Преглед на файлове

Merge pull request #40 from ckeditor/t/ckeditor5-core/130

Other: Used the `EditorUI` as a parent class for the `InlineEditorUI` (see ckeditor/ckeditor5-core#130).
Aleksander Nowodzinski преди 7 години
родител
ревизия
a280fe93d8
променени са 2 файла, в които са добавени 12 реда и са изтрити 66 реда
  1. 6 35
      packages/ckeditor5-editor-inline/src/inlineeditorui.js
  2. 6 31
      packages/ckeditor5-editor-inline/tests/inlineeditorui.js

+ 6 - 35
packages/ckeditor5-editor-inline/src/inlineeditorui.js

@@ -7,43 +7,21 @@
  * @module editor-inline/inlineeditorui
  */
 
-import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
-import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
+import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
 import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabletoolbarkeyboardfocus';
 import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalizetoolbarconfig';
 
 /**
  * The inline editor UI class.
  *
- * @implements module:core/editor/editorui~EditorUI
+ * @extends module:core/editor/editorui~EditorUI
  */
-export default class InlineEditorUI {
+export default class InlineEditorUI extends EditorUI {
 	/**
-	 * Creates an instance of the 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.
+	 * @inheritDoc
 	 */
 	constructor( editor, view ) {
-		/**
-		 * @inheritDoc
-		 */
-		this.editor = editor;
-
-		/**
-		 * @inheritDoc
-		 */
-		this.view = view;
-
-		/**
-		 * @inheritDoc
-		 */
-		this.componentFactory = new ComponentFactory( editor );
-
-		/**
-		 * @inheritDoc
-		 */
-		this.focusTracker = new FocusTracker();
+		super( editor, view );
 
 		/**
 		 * A normalized `config.toolbar` object.
@@ -71,7 +49,7 @@ export default class InlineEditorUI {
 		}
 
 		// https://github.com/ckeditor/ckeditor5-editor-inline/issues/4
-		view.listenTo( editor.editing.view, 'render', () => {
+		view.listenTo( editor.ui, 'update', () => {
 			// Don't pin if the panel is not already visible. It prevents the panel
 			// showing up when there's no focus in the UI.
 			if ( view.panel.isVisible ) {
@@ -103,11 +81,4 @@ export default class InlineEditorUI {
 			toolbar: view.toolbar
 		} );
 	}
-
-	/**
-	 * Destroys the UI.
-	 */
-	destroy() {
-		this.view.destroy();
-	}
 }

+ 6 - 31
packages/ckeditor5-editor-inline/tests/inlineeditorui.js

@@ -5,15 +5,13 @@
 
 /* globals document, Event */
 
-import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
 import View from '@ckeditor/ckeditor5-ui/src/view';
 
 import InlineEditorUI from '../src/inlineeditorui';
+import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
 import InlineEditorUIView from '../src/inlineeditoruiview';
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 
-import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
-
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import utils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
@@ -41,20 +39,8 @@ describe( 'InlineEditorUI', () => {
 	} );
 
 	describe( 'constructor()', () => {
-		it( 'sets #editor', () => {
-			expect( ui.editor ).to.equal( editor );
-		} );
-
-		it( 'sets #view', () => {
-			expect( ui.view ).to.equal( view );
-		} );
-
-		it( 'creates #componentFactory factory', () => {
-			expect( ui.componentFactory ).to.be.instanceOf( ComponentFactory );
-		} );
-
-		it( 'creates #focusTracker', () => {
-			expect( ui.focusTracker ).to.be.instanceOf( FocusTracker );
+		it( 'extends EditorUI', () => {
+			expect( ui ).to.instanceof( EditorUI );
 		} );
 	} );
 
@@ -94,17 +80,17 @@ describe( 'InlineEditorUI', () => {
 			} );
 
 			// https://github.com/ckeditor/ckeditor5-editor-inline/issues/4
-			it( 'pin() is called on editor.editable.view#render', () => {
+			it( 'pin() is called on editor.ui#update', () => {
 				const spy = sinon.stub( view.panel, 'pin' );
 
 				view.panel.hide();
 
-				editor.editing.view.render();
+				editor.ui.fire( 'update' );
 				sinon.assert.notCalled( spy );
 
 				view.panel.show();
 
-				editor.editing.view.render();
+				editor.ui.fire( 'update' );
 				sinon.assert.calledOnce( spy );
 				sinon.assert.calledWithExactly( spy, {
 					target: view.editableElement,
@@ -212,17 +198,6 @@ describe( 'InlineEditorUI', () => {
 				} );
 		} );
 	} );
-
-	describe( 'destroy()', () => {
-		it( 'destroys the #view', () => {
-			const spy = sinon.spy( view, 'destroy' );
-
-			return editor.destroy()
-				.then( () => {
-					sinon.assert.calledOnce( spy );
-				} );
-		} );
-	} );
 } );
 
 function viewCreator( name ) {