8
0
Просмотр исходного кода

Adjust to changes in `EditorUI`.

Krzysztof Krztoń 7 лет назад
Родитель
Сommit
650d6ff70c

+ 34 - 6
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -18,20 +18,41 @@ import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalize
  */
 export default class ClassicEditorUI extends EditorUI {
 	/**
-	 * @inheritDoc
+	 * Creates an instance of the classic 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.
 		 *
-		 * @type {Object}
 		 * @private
+		 * @member {Object}
 		 */
 		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
 	 */
@@ -39,6 +60,13 @@ export default class ClassicEditorUI extends EditorUI {
 		return this.view.element;
 	}
 
+	/**
+	 * @inheritDoc
+	 */
+	getEditableElement( rootName = 'main' ) {
+		return this.view.editable.name === rootName ? this.view.editable : null;
+	}
+
 	/**
 	 * Initializes the UI.
 	 */
@@ -62,15 +90,15 @@ export default class ClassicEditorUI extends EditorUI {
 		view.editable.bind( 'isFocused' ).to( editor.editing.view.document );
 		view.editable.name = editingRoot.rootName;
 
-		this.focusTracker.add( this.view.editable.editableElement );
+		this.focusTracker.add( view.editable.editableElement );
 
-		this.view.toolbar.fillFromConfig( this._toolbarConfig.items, this.componentFactory );
+		view.toolbar.fillFromConfig( this._toolbarConfig.items, this.componentFactory );
 
 		enableToolbarKeyboardFocus( {
 			origin: editor.editing.view,
 			originFocusTracker: this.focusTracker,
 			originKeystrokeHandler: editor.keystrokes,
-			toolbar: this.view.toolbar
+			toolbar: view.toolbar
 		} );
 	}
 }

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

@@ -178,6 +178,26 @@ describe( 'ClassicEditorUI', () => {
 				} );
 		} );
 	} );
+
+	describe( 'view()', () => {
+		it( 'returns view instance', () => {
+			expect( ui.view ).to.equal( view );
+		} );
+	} );
+
+	describe( 'getEditableElement()', () => {
+		it( 'returns editable element (default)', () => {
+			expect( ui.getEditableElement() ).to.equal( view.editable );
+		} );
+
+		it( 'returns editable element (root name passed)', () => {
+			expect( ui.getEditableElement( 'main' ) ).to.equal( view.editable );
+		} );
+
+		it( 'returns null if editable with the given name is absent', () => {
+			expect( ui.getEditableElement( 'absent' ) ).to.null;
+		} );
+	} );
 } );
 
 function viewCreator( name ) {