This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from ckeditor/t/130
Feature: Introduced the `EditorUI#update` event. Closes #130. BREAKING CHANGE: The `EditorUI` is now a class (no longer an interface).
- Loading branch information
Showing
7 changed files
with
195 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module core/editor/editorui | ||
*/ | ||
|
||
import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory'; | ||
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker'; | ||
|
||
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin'; | ||
import mix from '@ckeditor/ckeditor5-utils/src/mix'; | ||
|
||
/** | ||
* A class providing the minimal interface that is required to successfully bootstrap any editor UI. | ||
* | ||
* @mixes module:utils/emittermixin~EmitterMixin | ||
*/ | ||
export default class 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. | ||
*/ | ||
constructor( editor, view ) { | ||
/** | ||
* The editor that the UI belongs to. | ||
* | ||
* @readonly | ||
* @member {module:core/editor/editor~Editor} #editor | ||
*/ | ||
this.editor = editor; | ||
|
||
/** | ||
* The main (top–most) view of the editor UI. | ||
* | ||
* @readonly | ||
* @member {module:ui/editorui/editoruiview~EditorUIView} #view | ||
*/ | ||
this.view = view; | ||
|
||
/** | ||
* An instance of the {@link module:ui/componentfactory~ComponentFactory}, a registry used by plugins | ||
* to register factories of specific UI components. | ||
* | ||
* @readonly | ||
* @member {module:ui/componentfactory~ComponentFactory} #componentFactory | ||
*/ | ||
this.componentFactory = new ComponentFactory( editor ); | ||
|
||
/** | ||
* Stores the information about the editor UI focus and propagates it so various plugins and components | ||
* are unified as a focus group. | ||
* | ||
* @readonly | ||
* @member {module:utils/focustracker~FocusTracker} #focusTracker | ||
*/ | ||
this.focusTracker = new FocusTracker(); | ||
|
||
// Informs UI components that should be refreshed after layout change. | ||
this.listenTo( editor.editing.view.document, 'layoutChanged', () => this.update() ); | ||
} | ||
|
||
/** | ||
* Fires the {@link module:core/editor/editorui~EditorUI#event:update} event. | ||
*/ | ||
update() { | ||
this.fire( 'update' ); | ||
} | ||
|
||
/** | ||
* Destroys the UI. | ||
*/ | ||
destroy() { | ||
this.stopListening(); | ||
this.view.destroy(); | ||
} | ||
|
||
/** | ||
* Fired whenever the UI (all related components) should be refreshed. | ||
* | ||
* **Note:**: The event is fired after each {@link module:engine/view/document~Document#event:layoutChanged}. | ||
* It can also be fired manually via the {@link module:core/editor/editorui~EditorUI#update} method. | ||
* | ||
* @event update | ||
*/ | ||
} | ||
|
||
mix( EditorUI, EmitterMixin ); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import EditorUI from '../../src/editor/editorui'; | ||
import Editor from '../../src/editor/editor'; | ||
|
||
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker'; | ||
import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory'; | ||
import View from '@ckeditor/ckeditor5-ui/src/view'; | ||
|
||
import testUtils from '../_utils/utils'; | ||
|
||
testUtils.createSinonSandbox(); | ||
|
||
describe( 'EditorUI', () => { | ||
let editor, view, ui; | ||
|
||
beforeEach( () => { | ||
editor = new Editor(); | ||
view = new View(); | ||
ui = new EditorUI( editor, view ); | ||
} ); | ||
|
||
afterEach( () => { | ||
return Promise.all( [ | ||
editor.destroy(), | ||
ui.destroy() | ||
] ); | ||
} ); | ||
|
||
describe( 'constructor()', () => { | ||
it( 'should set #editor', () => { | ||
expect( ui.editor ).to.equal( editor ); | ||
} ); | ||
|
||
it( 'should set #view', () => { | ||
expect( ui.view ).to.equal( view ); | ||
} ); | ||
|
||
it( 'should create #componentFactory factory', () => { | ||
expect( ui.componentFactory ).to.be.instanceOf( ComponentFactory ); | ||
} ); | ||
|
||
it( 'should create #focusTracker', () => { | ||
expect( ui.focusTracker ).to.be.instanceOf( FocusTracker ); | ||
} ); | ||
|
||
it( 'should fire update event after viewDocument#layoutChanged', () => { | ||
const spy = sinon.spy(); | ||
|
||
ui.on( 'update', spy ); | ||
|
||
editor.editing.view.document.fire( 'layoutChanged' ); | ||
|
||
sinon.assert.calledOnce( spy ); | ||
|
||
editor.editing.view.document.fire( 'layoutChanged' ); | ||
|
||
sinon.assert.calledTwice( spy ); | ||
} ); | ||
} ); | ||
|
||
describe( 'update()', () => { | ||
it( 'should fire update event', () => { | ||
const spy = sinon.spy(); | ||
|
||
ui.on( 'update', spy ); | ||
|
||
ui.update(); | ||
|
||
sinon.assert.calledOnce( spy ); | ||
|
||
ui.update(); | ||
|
||
sinon.assert.calledTwice( spy ); | ||
} ); | ||
} ); | ||
|
||
describe( 'destroy()', () => { | ||
it( 'should stop listening', () => { | ||
const spy = sinon.spy( ui, 'stopListening' ); | ||
|
||
ui.destroy(); | ||
|
||
sinon.assert.called( spy ); | ||
} ); | ||
|
||
it( 'should destroy the #view', () => { | ||
const spy = sinon.spy( view, 'destroy' ); | ||
|
||
ui.destroy(); | ||
|
||
sinon.assert.called( spy ); | ||
} ); | ||
} ); | ||
} ); |