Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 8c7414b

Browse files
authored
Merge pull request #18 from ckeditor/t/ckeditor5-core/64
Other: Aligned `DecoupledEditor` to changes in the `EditorWithUI` and `ElementApi` interfaces. BREAKING CHANGE: `DecoupledEditor#element` was renamed to `DecoupledEditor#sourceElement`. See ckeditor/ckeditor5-core#64.
2 parents 6a79fcf + d0da654 commit 8c7414b

File tree

3 files changed

+41
-27
lines changed

3 files changed

+41
-27
lines changed

src/decouplededitor.js

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,32 @@ export default class DecoupledEditor extends Editor {
5757
* {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`} method instead.
5858
*
5959
* @protected
60-
* @param {HTMLElement|String} elementOrData The DOM element that serves as an editable.
61-
* The data will be loaded from it and loaded back to it once the editor is destroyed.
62-
* Alternatively, a data string to be loaded into the editor.
60+
* @param {HTMLElement|String} sourceElementOrData The DOM element that will be the source for the created editor
61+
* (on which the editor will be initialized) or initial data for the editor. For more information see
62+
* {@link module:editor-balloon/ballooneditor~BalloonEditor.create `BalloonEditor.create()`}.
6363
* @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
6464
*/
65-
constructor( elementOrData, config ) {
65+
constructor( sourceElementOrData, config ) {
6666
super( config );
6767

68-
if ( isElement( elementOrData ) ) {
69-
/**
70-
* The element used as an editable. The data will be loaded from it and loaded back to
71-
* it once the editor is destroyed.
72-
*
73-
* **Note:** The property is available only when such element has been passed
74-
* to the {@link #constructor}.
75-
*
76-
* @readonly
77-
* @member {HTMLElement}
78-
*/
79-
this.element = elementOrData;
68+
if ( isElement( sourceElementOrData ) ) {
69+
this.sourceElement = sourceElementOrData;
8070
}
8171

8272
this.data.processor = new HtmlDataProcessor();
8373

8474
this.model.document.createRoot();
8575

86-
this.ui = new DecoupledEditorUI( this, new DecoupledEditorUIView( this.locale, this.element ) );
76+
this.ui = new DecoupledEditorUI( this, new DecoupledEditorUIView( this.locale, this.sourceElement ) );
77+
}
78+
79+
/**
80+
* @inheritDoc
81+
*/
82+
get element() {
83+
// This editor has no single "main UI element". Its editable and toolbar are exposed separately and need
84+
// to be added to the DOM manually by the consumer.
85+
return null;
8786
}
8887

8988
/**
@@ -114,8 +113,8 @@ export default class DecoupledEditor extends Editor {
114113

115114
return super.destroy()
116115
.then( () => {
117-
if ( this.element ) {
118-
setDataInElement( this.element, data );
116+
if ( this.sourceElement ) {
117+
setDataInElement( this.sourceElement, data );
119118
}
120119
} );
121120
}
@@ -178,16 +177,22 @@ export default class DecoupledEditor extends Editor {
178177
* console.error( err.stack );
179178
* } );
180179
*
181-
* @param {HTMLElement|String} elementOrData The DOM element that serves as an editable.
182-
* The data will be loaded from it and loaded back to it once the editor is destroyed.
183-
* Alternatively, a data string to be loaded into the editor.
180+
* @param {HTMLElement|String} sourceElementOrData The DOM element that will be the source for the created editor
181+
* (on which the editor will be initialized) or initial data for the editor.
182+
*
183+
* If a source element is passed, then its contents will be automatically
184+
* {@link module:editor-decoupled/decouplededitor~DecoupledEditor#setData loaded} to the editor on startup and the element
185+
* itself will be used as the editor's editable element.
186+
*
187+
* If data is provided, then `editor.ui.view.editable.element` will be created automatically and needs to be added
188+
* to the DOM manually.
184189
* @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
185190
* @returns {Promise} A promise resolved once the editor is ready.
186191
* The promise returns the created {@link module:editor-decoupled/decouplededitor~DecoupledEditor} instance.
187192
*/
188-
static create( elementOrData, config ) {
193+
static create( sourceElementOrData, config ) {
189194
return new Promise( resolve => {
190-
const editor = new this( elementOrData, config );
195+
const editor = new this( sourceElementOrData, config );
191196

192197
resolve(
193198
editor.initPlugins()
@@ -196,7 +201,11 @@ export default class DecoupledEditor extends Editor {
196201
editor.fire( 'uiReady' );
197202
} )
198203
.then( () => {
199-
return editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
204+
const initialData = isElement( sourceElementOrData ) ?
205+
getDataFromElement( sourceElementOrData ) :
206+
sourceElementOrData;
207+
208+
return editor.data.init( initialData );
200209
} )
201210
.then( () => {
202211
editor.fire( 'dataReady' );

src/decouplededitoruiview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export default class DecoupledEditorUIView extends EditorUIView {
2828
* Creates an instance of the decoupled editor UI view.
2929
*
3030
* @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
31-
* @param {HTMLElement} [editableElement] The DOM element to be used as editable.
31+
* @param {HTMLElement} [editableElement] The editable element. If not specified, it will be automatically created by
32+
* {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
3233
*/
3334
constructor( locale, editableElement ) {
3435
super( locale );

tests/decouplededitor.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ describe( 'DecoupledEditor', () => {
3636
} );
3737

3838
it( 'has a Data Interface', () => {
39-
testUtils.isMixed( DecoupledEditor, DataApiMixin );
39+
expect( testUtils.isMixed( DecoupledEditor, DataApiMixin ) ).to.be.true;
40+
} );
41+
42+
it( 'implements the EditorWithUI interface', () => {
43+
expect( editor.element ).to.be.null;
4044
} );
4145

4246
it( 'creates main root element', () => {

0 commit comments

Comments
 (0)