Browse Source

Adjust to changes in `core/EditorWithUI`.

Krzysztof Krztoń 7 years ago
parent
commit
afda55df5c

+ 6 - 2
packages/ckeditor5-editor-classic/src/classiceditor.js

@@ -17,6 +17,7 @@ import ClassicEditorUIView from './classiceditoruiview';
 import ElementReplacer from '@ckeditor/ckeditor5-utils/src/elementreplacer';
 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';
 
 /**
@@ -87,7 +88,8 @@ export default class ClassicEditor extends Editor {
 	 * @inheritDoc
 	 */
 	get element() {
-		return this.ui.view.element;
+		log.warn( 'deprecated-editor-element: The editor#element is deprecated.' );
+		return this.ui.element;
 	}
 
 	/**
@@ -192,9 +194,11 @@ export default class ClassicEditor extends Editor {
 					.then( () => editor.ui.init() )
 					.then( () => {
 						if ( isElement( sourceElementOrData ) ) {
-							editor._elementReplacer.replace( sourceElementOrData, editor.element );
+							editor._elementReplacer.replace( sourceElementOrData, editor.ui.element );
 						}
 
+						editor.ui.ready();
+
 						editor.fire( 'uiReady' );
 					} )
 					.then( () => editor.editing.view.attachDomRoot( editor.ui.view.editableElement ) )

+ 7 - 0
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -32,6 +32,13 @@ export default class ClassicEditorUI extends EditorUI {
 		this._toolbarConfig = normalizeToolbarConfig( editor.config.get( 'toolbar' ) );
 	}
 
+	/**
+	 * @inheritDoc
+	 */
+	get element() {
+		return this.view.element;
+	}
+
 	/**
 	 * Initializes the UI.
 	 */

+ 27 - 1
packages/ckeditor5-editor-classic/tests/classiceditor.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( 'ClassicEditor', () => {
 	let editor, editorElement;
@@ -30,6 +31,8 @@ describe( 'ClassicEditor', () => {
 		editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
 
 		document.body.appendChild( editorElement );
+
+		testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
 	} );
 
 	afterEach( () => {
@@ -201,6 +204,7 @@ describe( 'ClassicEditor', () => {
 			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 );
@@ -212,7 +216,7 @@ describe( 'ClassicEditor', () => {
 					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;
 				} );
@@ -261,6 +265,28 @@ describe( 'ClassicEditor', () => {
 					editor = newEditor;
 				} );
 		} );
+
+		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 ClassicEditor
+				.create( editorElement, {
+					plugins: [ EventWatcher ]
+				} )
+				.then( newEditor => {
+					expect( isReady ).to.be.true;
+
+					editor = newEditor;
+				} );
+		} );
 	} );
 
 	describe( 'destroy', () => {

+ 1 - 0
packages/ckeditor5-editor-classic/tests/classiceditorui.js

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