@@ -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' ) ;
0 commit comments