Преглед изворни кода

Adjust to changes in `core/EditorWithUI`.

Krzysztof Krztoń пре 7 година
родитељ
комит
2102b6e014

+ 4 - 0
packages/ckeditor5-editor-decoupled/src/decouplededitor.js

@@ -15,6 +15,7 @@ import DecoupledEditorUIView from './decouplededitoruiview';
 import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromelement';
 import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 import { isElement } from 'lodash-es';
 
 /**
@@ -80,6 +81,7 @@ export default class DecoupledEditor extends Editor {
 	 * @inheritDoc
 	 */
 	get element() {
+		log.warn( 'deprecated-editor-element: The editor#element is deprecated.' );
 		// This editor has no single "main UI element". Its editable and toolbar are exposed separately and need
 		// to be added to the DOM manually by the consumer.
 		return null;
@@ -198,6 +200,8 @@ export default class DecoupledEditor extends Editor {
 				editor.initPlugins()
 					.then( () => {
 						editor.ui.init();
+						editor.ui.ready();
+
 						editor.fire( 'uiReady' );
 					} )
 					.then( () => {

+ 29 - 1
packages/ckeditor5-editor-decoupled/tests/decouplededitor.js

@@ -18,6 +18,7 @@ import DataApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/dataapimixin
 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';
 
 const editorData = '<p><strong>foo</strong> bar</p>';
 
@@ -26,6 +27,10 @@ describe( 'DecoupledEditor', () => {
 
 	testUtils.createSinonSandbox();
 
+	beforeEach( () => {
+		testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
+	} );
+
 	describe( 'constructor()', () => {
 		beforeEach( () => {
 			editor = new DecoupledEditor();
@@ -189,6 +194,7 @@ describe( 'DecoupledEditor', () => {
 					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 );
@@ -200,7 +206,7 @@ describe( 'DecoupledEditor', () => {
 							plugins: [ EventWatcher ]
 						} )
 						.then( newEditor => {
-							expect( fired ).to.deep.equal( [ 'pluginsReady', 'uiReady', 'dataReady', 'ready' ] );
+							expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'uiReady', 'dataReady', 'ready' ] );
 
 							return newEditor.destroy();
 						} );
@@ -249,6 +255,28 @@ describe( 'DecoupledEditor', () => {
 							return newEditor.destroy();
 						} );
 				} );
+
+				it( 'fires ready once UI is rendered', () => {
+					let isReady;
+
+					class EventWatcher extends Plugin {
+						init() {
+							this.editor.ui.on( 'ready', () => {
+								isReady = this.editor.ui.view.isRendered;
+							} );
+						}
+					}
+
+					return DecoupledEditor
+						.create( getElementOrData(), {
+							plugins: [ EventWatcher ]
+						} )
+						.then( newEditor => {
+							expect( isReady ).to.be.true;
+
+							return newEditor.destroy();
+						} );
+				} );
 			} );
 		}
 	} );

+ 1 - 0
packages/ckeditor5-editor-decoupled/tests/decouplededitorui.js

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