Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit dd43e7a

Browse files
author
Piotr Jasiun
authored
Merge pull request #24 from ckeditor/t/ckeditor5/1449
Other: Editor UI classes API refactoring. BREAKING CHANGE: Removed `BalloonEditor#element` property. The `BalloonEditorUI#element` property should be used instead. BREAKING CHANGE: Removed `BalloonEditorUIView#editableElement`. Instead `BalloonEditorUI#getEditableElement()` method should be used.
2 parents c959daf + 23912ea commit dd43e7a

File tree

6 files changed

+84
-40
lines changed

6 files changed

+84
-40
lines changed

src/ballooneditor.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ export default class BalloonEditor extends Editor {
8282
attachToForm( this );
8383
}
8484

85-
/**
86-
* @inheritDoc
87-
*/
88-
get element() {
89-
return this.ui.view.editable.element;
90-
}
91-
9285
/**
9386
* Destroys the editor instance, releasing all resources used by it.
9487
*
@@ -189,7 +182,6 @@ export default class BalloonEditor extends Editor {
189182
editor.initPlugins()
190183
.then( () => {
191184
editor.ui.init();
192-
editor.fire( 'uiReady' );
193185
} )
194186
.then( () => {
195187
const initialData = isElement( sourceElementOrData ) ?

src/ballooneditorui.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,41 @@ import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabl
1616
* @extends module:core/editor/editorui~EditorUI
1717
*/
1818
export default class BalloonEditorUI extends EditorUI {
19+
/**
20+
* Creates an instance of the balloon editor UI class.
21+
*
22+
* @param {module:core/editor/editor~Editor} editor The editor instance.
23+
* @param {module:ui/editorui/editoruiview~EditorUIView} view The view of the UI.
24+
*/
25+
constructor( editor, view ) {
26+
super( editor );
27+
28+
/**
29+
* The main (top–most) view of the editor UI.
30+
*
31+
* @private
32+
* @member {module:ui/editorui/editoruiview~EditorUIView} #_view
33+
*/
34+
this._view = view;
35+
}
36+
37+
/**
38+
* The main (top–most) view of the editor UI.
39+
*
40+
* @readonly
41+
* @member {module:ui/editorui/editoruiview~EditorUIView} #view
42+
*/
43+
get view() {
44+
return this._view;
45+
}
46+
47+
/**
48+
* @inheritDoc
49+
*/
50+
get element() {
51+
return this.view.editable.element;
52+
}
53+
1954
/**
2055
* Initializes the UI.
2156
*/
@@ -33,10 +68,12 @@ export default class BalloonEditorUI extends EditorUI {
3368
// Bind to focusTracker instead of editor.editing.view because otherwise
3469
// focused editable styles disappear when view#toolbar is focused.
3570
view.editable.bind( 'isFocused' ).to( this.focusTracker );
36-
editor.editing.view.attachDomRoot( view.editableElement );
71+
editor.editing.view.attachDomRoot( view.editable.element );
3772
view.editable.name = editingRoot.rootName;
3873

39-
this.focusTracker.add( view.editableElement );
74+
this._editableElements.set( view.editable.name, view.editable.element );
75+
76+
this.focusTracker.add( view.editable.element );
4077

4178
enableToolbarKeyboardFocus( {
4279
origin: editor.editing.view,
@@ -50,5 +87,16 @@ export default class BalloonEditorUI extends EditorUI {
5087
balloonToolbar.hide();
5188
}
5289
} );
90+
91+
this.fire( 'ready' );
92+
}
93+
94+
/**
95+
* @inheritDoc
96+
*/
97+
destroy() {
98+
this._view.destroy();
99+
100+
super.destroy();
53101
}
54102
}

src/ballooneditoruiview.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,4 @@ export default class BalloonEditorUIView extends EditorUIView {
4343

4444
this.registerChild( this.editable );
4545
}
46-
47-
/**
48-
* @inheritDoc
49-
*/
50-
get editableElement() {
51-
return this.editable.element;
52-
}
5346
}

tests/ballooneditor.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import ElementApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/elementap
2020
import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';
2121

2222
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
23+
import log from '@ckeditor/ckeditor5-utils/src/log';
24+
2325
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
2426
import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory';
2527

@@ -33,6 +35,8 @@ describe( 'BalloonEditor', () => {
3335
editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
3436

3537
document.body.appendChild( editorElement );
38+
39+
testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
3640
} );
3741

3842
afterEach( () => {
@@ -121,14 +125,6 @@ describe( 'BalloonEditor', () => {
121125
return newEditor.destroy();
122126
} );
123127
} );
124-
125-
it( 'editor.element should contain the whole editor (with UI) element', () => {
126-
return BalloonEditor.create( '<p>Hello world!</p>', {
127-
plugins: [ Paragraph ]
128-
} ).then( editor => {
129-
expect( editor.editing.view.getDomRoot() ).to.equal( editor.element );
130-
} );
131-
} );
132128
} );
133129

134130
describe( 'create()', () => {
@@ -157,7 +153,6 @@ describe( 'BalloonEditor', () => {
157153
it( 'attaches editable UI as view\'s DOM root', () => {
158154
const domRoot = editor.editing.view.getDomRoot();
159155

160-
expect( domRoot ).to.equal( editor.element );
161156
expect( domRoot ).to.equal( editor.ui.view.editable.element );
162157
} );
163158

@@ -213,7 +208,7 @@ describe( 'BalloonEditor', () => {
213208
class EventWatcher extends Plugin {
214209
init() {
215210
this.editor.on( 'pluginsReady', spy );
216-
this.editor.on( 'uiReady', spy );
211+
this.editor.ui.on( 'ready', spy );
217212
this.editor.on( 'dataReady', spy );
218213
this.editor.on( 'ready', spy );
219214
}
@@ -224,7 +219,7 @@ describe( 'BalloonEditor', () => {
224219
plugins: [ EventWatcher ]
225220
} )
226221
.then( newEditor => {
227-
expect( fired ).to.deep.equal( [ 'pluginsReady', 'uiReady', 'dataReady', 'ready' ] );
222+
expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'dataReady', 'ready' ] );
228223

229224
editor = newEditor;
230225
} );
@@ -252,12 +247,12 @@ describe( 'BalloonEditor', () => {
252247
} );
253248
} );
254249

255-
it( 'fires uiReady once UI is ready', () => {
250+
it( 'fires ready once UI is ready', () => {
256251
let isRendered;
257252

258253
class EventWatcher extends Plugin {
259254
init() {
260-
this.editor.on( 'uiReady', () => {
255+
this.editor.ui.on( 'ready', () => {
261256
isRendered = this.editor.ui.view.isRendered;
262257
} );
263258
}

tests/ballooneditorui.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import utils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
1616
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
1717

1818
describe( 'BalloonEditorUI', () => {
19-
let editor, view, ui;
19+
let editor, view, ui, viewElement;
2020

2121
testUtils.createSinonSandbox();
2222

@@ -29,6 +29,7 @@ describe( 'BalloonEditorUI', () => {
2929
editor = newEditor;
3030
ui = editor.ui;
3131
view = ui.view;
32+
viewElement = view.editable.element;
3233
} );
3334
} );
3435

@@ -123,6 +124,26 @@ describe( 'BalloonEditorUI', () => {
123124
} );
124125
} );
125126
} );
127+
128+
describe( 'element()', () => {
129+
it( 'returns correct element instance', () => {
130+
expect( ui.element ).to.equal( viewElement );
131+
} );
132+
} );
133+
134+
describe( 'getEditableElement()', () => {
135+
it( 'returns editable element (default)', () => {
136+
expect( ui.getEditableElement() ).to.equal( view.editable.element );
137+
} );
138+
139+
it( 'returns editable element (root name passed)', () => {
140+
expect( ui.getEditableElement( 'main' ) ).to.equal( view.editable.element );
141+
} );
142+
143+
it( 'returns undefined if editable with the given name is absent', () => {
144+
expect( ui.getEditableElement( 'absent' ) ).to.be.undefined;
145+
} );
146+
} );
126147
} );
127148

128149
class VirtualBalloonTestEditor extends VirtualTestEditor {
@@ -147,7 +168,6 @@ class VirtualBalloonTestEditor extends VirtualTestEditor {
147168
editor.initPlugins()
148169
.then( () => {
149170
editor.ui.init();
150-
editor.fire( 'uiReady' );
151171
editor.fire( 'dataReady' );
152172
editor.fire( 'ready' );
153173
} )

tests/ballooneditoruiview.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import BalloonEditorUIView from '../src/ballooneditoruiview';
77
import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
88
import Locale from '@ckeditor/ckeditor5-utils/src/locale';
99

10+
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
11+
1012
describe( 'BalloonEditorUIView', () => {
1113
let locale, view;
1214

15+
testUtils.createSinonSandbox();
16+
1317
beforeEach( () => {
1418
locale = new Locale( 'en' );
1519
view = new BalloonEditorUIView( locale );
@@ -40,12 +44,4 @@ describe( 'BalloonEditorUIView', () => {
4044
sinon.assert.calledOnce( spy );
4145
} );
4246
} );
43-
44-
describe( 'editableElement', () => {
45-
it( 'returns editable\'s view element', () => {
46-
view.render();
47-
expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
48-
view.destroy();
49-
} );
50-
} );
5147
} );

0 commit comments

Comments
 (0)