Ver código fonte

Merge branch 't/ckeditor5/1449' into t/ckeditor5/479

Aleksander Nowodzinski 7 anos atrás
pai
commit
aca7c0d709

+ 3 - 2
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';
 
 /**
@@ -80,7 +81,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;
 	}
 
 	/**
@@ -180,7 +182,6 @@ export default class InlineEditor extends Editor {
 				editor.initPlugins()
 					.then( () => {
 						editor.ui.init();
-						editor.fire( 'uiReady' );
 					} )
 					.then( () => {
 						const initialData = isElement( sourceElementOrData ) ?

+ 37 - 5
packages/ckeditor5-editor-inline/src/inlineeditorui.js

@@ -19,10 +19,21 @@ import { attachPlaceholder, getPlaceholderElement } from '@ckeditor/ckeditor5-en
  */
 export default class InlineEditorUI extends EditorUI {
 	/**
-	 * @inheritDoc
+	 * Creates an instance of the inline editor UI class.
+	 *
+	 * @param {module:core/editor/editor~Editor} editor The editor instance.
+	 * @param {module:ui/editorui/editoruiview~EditorUIView} view The view of the UI.
 	 */
 	constructor( editor, view ) {
-		super( editor, view );
+		super( editor );
+
+		/**
+		 * The main (top–most) view of the editor UI.
+		 *
+		 * @private
+		 * @member {module:ui/editorui/editoruiview~EditorUIView} #_view
+		 */
+		this._view = view;
 
 		/**
 		 * A normalized `config.toolbar` object.
@@ -33,6 +44,23 @@ export default class InlineEditorUI extends EditorUI {
 		this._toolbarConfig = normalizeToolbarConfig( editor.config.get( 'toolbar' ) );
 	}
 
+	/**
+	 * The main (top–most) view of the editor UI.
+	 *
+	 * @readonly
+	 * @member {module:ui/editorui/editoruiview~EditorUIView} #view
+	 */
+	get view() {
+		return this._view;
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	get element() {
+		return this.view.editable.element;
+	}
+
 	/**
 	 * Initializes the UI.
 	 */
@@ -47,7 +75,7 @@ export default class InlineEditorUI extends EditorUI {
 
 		view.render();
 
-		editingView.attachDomRoot( view.editableElement );
+		editingView.attachDomRoot( view.editable.editableElement );
 
 		const editingRoot = editingView.document.getRoot();
 
@@ -72,13 +100,15 @@ export default class InlineEditorUI extends EditorUI {
 			// showing up when there's no focus in the UI.
 			if ( view.panel.isVisible ) {
 				view.panel.pin( {
-					target: view.editableElement,
+					target: view.editable.editableElement,
 					positions: view.panelPositions
 				} );
 			}
 		} );
 
-		this.focusTracker.add( view.editableElement );
+		this.focusTracker.add( view.editable.editableElement );
+
+		this._editableElements.push( view.editable );
 
 		view.toolbar.fillFromConfig( this._toolbarConfig.items, this.componentFactory );
 
@@ -88,6 +118,8 @@ export default class InlineEditorUI extends EditorUI {
 			originKeystrokeHandler: editor.keystrokes,
 			toolbar: view.toolbar
 		} );
+
+		this.ready();
 	}
 
 	destroy() {

+ 13 - 2
packages/ckeditor5-editor-inline/src/inlineeditoruiview.js

@@ -12,6 +12,8 @@ import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/i
 import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpanelview';
 import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
 
+import log from '@ckeditor/ckeditor5-utils/src/log';
+
 /**
  * Inline editor UI view. Uses an nline editable and a floating toolbar.
  *
@@ -144,10 +146,19 @@ export default class InlineEditorUIView extends EditorUIView {
 	}
 
 	/**
-	 * @inheritDoc
+	 * **Deprecated** since `v12.0.0`. The {@link module:ui/editableui/editableuiview~EditableUIView#editableElement
+	 * `EditableUIView editableElement`} could be used instead.
+	 *
+	 * The element which is the main editable element (usually the one with `contentEditable="true"`).
+	 *
+	 * @deprecated v12.0.0 The {@link module:ui/editableui/editableuiview~EditableUIView#editableElement
+	 * `EditableUIView editableElement`} could be used instead.
+	 * @readonly
+	 * @member {HTMLElement} #editableElement
 	 */
 	get editableElement() {
-		return this.editable.element;
+		log.warn( 'deprecated-ui-view-editableElement: The InlineEditorUIView#editableElement property is deprecated.' );
+		return this.editable.editableElement;
 	}
 
 	/**

+ 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', () => {

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

@@ -93,7 +93,7 @@ describe( 'InlineEditorUI', () => {
 				editor.ui.fire( 'update' );
 				sinon.assert.calledOnce( spy );
 				sinon.assert.calledWithExactly( spy, {
-					target: view.editableElement,
+					target: view.editable.editableElement,
 					positions: sinon.match.array
 				} );
 			} );
@@ -198,6 +198,20 @@ describe( 'InlineEditorUI', () => {
 				} );
 		} );
 	} );
+
+	describe( 'getEditableElement()', () => {
+		it( 'returns editable element (default)', () => {
+			expect( ui.getEditableElement() ).to.equal( view.editable.element );
+		} );
+
+		it( 'returns editable element (root name passed)', () => {
+			expect( ui.getEditableElement( 'main' ) ).to.equal( view.editable.element );
+		} );
+
+		it( 'returns null if editable with the given name is absent', () => {
+			expect( ui.getEditableElement( 'absent' ) ).to.null;
+		} );
+	} );
 } );
 
 function viewCreator( name ) {
@@ -236,6 +250,7 @@ class VirtualInlineTestEditor extends VirtualTestEditor {
 				editor.initPlugins()
 					.then( () => {
 						editor.ui.init();
+						editor.ui.ready();
 						editor.fire( 'uiReady' );
 						editor.fire( 'dataReady' );
 						editor.fire( 'ready' );

+ 7 - 0
packages/ckeditor5-editor-inline/tests/inlineeditoruiview.js

@@ -9,9 +9,14 @@ import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpa
 import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
 import Locale from '@ckeditor/ckeditor5-utils/src/locale';
 
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import log from '@ckeditor/ckeditor5-utils/src/log';
+
 describe( 'InlineEditorUIView', () => {
 	let locale, view;
 
+	testUtils.createSinonSandbox();
+
 	beforeEach( () => {
 		locale = new Locale( 'en' );
 		view = new InlineEditorUIView( locale );
@@ -119,6 +124,8 @@ describe( 'InlineEditorUIView', () => {
 
 	describe( 'editableElement', () => {
 		it( 'returns editable\'s view element', () => {
+			testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
+
 			view.render();
 			expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
 			view.destroy();