ソースを参照

Adjust to changes in `core/EditorWithUI`.

Krzysztof Krztoń 7 年 前
コミット
88420396ea

+ 5 - 1
packages/ckeditor5-editor-inline/src/inlineeditor.js

@@ -17,6 +17,7 @@ import InlineEditorUIView from './inlineeditoruiview';
 import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
 import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromelement';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 import { isElement } from 'lodash-es';
 
 /**
@@ -79,7 +80,8 @@ export default class InlineEditor extends Editor {
 	 * @inheritDoc
 	 */
 	get element() {
-		return this.ui.view.editable.element;
+		log.warn( 'deprecated-editor-element: The editor#element is deprecated.' );
+		return this.ui.element;
 	}
 
 	/**
@@ -179,6 +181,8 @@ export default class InlineEditor extends Editor {
 				editor.initPlugins()
 					.then( () => {
 						editor.ui.init();
+						editor.ui.ready();
+
 						editor.fire( 'uiReady' );
 					} )
 					.then( () => {

+ 7 - 0
packages/ckeditor5-editor-inline/src/inlineeditorui.js

@@ -33,6 +33,13 @@ export default class InlineEditorUI extends EditorUI {
 	}
 
 	/**
+	 * @inheritDoc
+	 */
+	get element() {
+		return this.view.editable.element;
+	}
+
+	/**
 	 * Initializes the UI.
 	 */
 	init() {

+ 35 - 1
packages/ckeditor5-editor-inline/tests/inlineeditor.js

@@ -19,6 +19,7 @@ import ElementApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/elementap
 import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';
 
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 
 describe( 'InlineEditor', () => {
 	let editor, editorElement;
@@ -30,6 +31,8 @@ describe( 'InlineEditor', () => {
 		editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
 
 		document.body.appendChild( editorElement );
+
+		testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
 	} );
 
 	afterEach( () => {
@@ -116,6 +119,14 @@ describe( 'InlineEditor', () => {
 				expect( editor.editing.view.getDomRoot() ).to.equal( editor.element );
 			} );
 		} );
+
+		it( 'editor.ui.element should contain the whole editor (with UI) element', () => {
+			return InlineEditor.create( '<p>Hello world!</p>', {
+				plugins: [ Paragraph ]
+			} ).then( editor => {
+				expect( editor.editing.view.getDomRoot() ).to.equal( editor.ui.element );
+			} );
+		} );
 	} );
 
 	describe( 'create()', () => {
@@ -192,6 +203,7 @@ describe( 'InlineEditor', () => {
 			class EventWatcher extends Plugin {
 				init() {
 					this.editor.on( 'pluginsReady', spy );
+					this.editor.ui.on( 'ready', spy );
 					this.editor.on( 'uiReady', spy );
 					this.editor.on( 'dataReady', spy );
 					this.editor.on( 'ready', spy );
@@ -203,7 +215,7 @@ describe( 'InlineEditor', () => {
 					plugins: [ EventWatcher ]
 				} )
 				.then( newEditor => {
-					expect( fired ).to.deep.equal( [ 'pluginsReady', 'uiReady', 'dataReady', 'ready' ] );
+					expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'uiReady', 'dataReady', 'ready' ] );
 
 					editor = newEditor;
 				} );
@@ -252,6 +264,28 @@ describe( 'InlineEditor', () => {
 					editor = newEditor;
 				} );
 		} );
+
+		it( 'fires ready once UI is ready', () => {
+			let isReady;
+
+			class EventWatcher extends Plugin {
+				init() {
+					this.editor.ui.on( 'ready', () => {
+						isReady = this.editor.ui.view.isRendered;
+					} );
+				}
+			}
+
+			return InlineEditor
+				.create( editorElement, {
+					plugins: [ EventWatcher ]
+				} )
+				.then( newEditor => {
+					expect( isReady ).to.be.true;
+
+					editor = newEditor;
+				} );
+		} );
 	} );
 
 	describe( 'destroy', () => {

+ 1 - 0
packages/ckeditor5-editor-inline/tests/inlineeditorui.js

@@ -236,6 +236,7 @@ class VirtualInlineTestEditor extends VirtualTestEditor {
 				editor.initPlugins()
 					.then( () => {
 						editor.ui.init();
+						editor.ui.ready();
 						editor.fire( 'uiReady' );
 						editor.fire( 'dataReady' );
 						editor.fire( 'ready' );