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

Commit f8195da

Browse files
author
Piotr Jasiun
authored
Merge pull request #43 from ckeditor/t/ckeditor5/1449
Other: Editor UI classes API refactoring. BREAKING CHANGE: Removed `InlineEditor#element` property. The `InlineEditorUI#element` property should be used instead. BREAKING CHANGE: Removed `InlineEditorUIView#editableElement`. Instead `InlineEditorUI#getEditableElement()` method should be used.
2 parents dd2bb90 + 00089d3 commit f8195da

File tree

6 files changed

+85
-39
lines changed

6 files changed

+85
-39
lines changed

src/inlineeditor.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ export default class InlineEditor extends Editor {
7575
attachToForm( this );
7676
}
7777

78-
/**
79-
* @inheritDoc
80-
*/
81-
get element() {
82-
return this.ui.view.editable.element;
83-
}
84-
8578
/**
8679
* Destroys the editor instance, releasing all resources used by it.
8780
*
@@ -179,7 +172,6 @@ export default class InlineEditor extends Editor {
179172
editor.initPlugins()
180173
.then( () => {
181174
editor.ui.init();
182-
editor.fire( 'uiReady' );
183175
} )
184176
.then( () => {
185177
const initialData = isElement( sourceElementOrData ) ?

src/inlineeditorui.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalize
1818
*/
1919
export default class InlineEditorUI extends EditorUI {
2020
/**
21-
* @inheritDoc
21+
* Creates an instance of the inline editor UI class.
22+
*
23+
* @param {module:core/editor/editor~Editor} editor The editor instance.
24+
* @param {module:ui/editorui/editoruiview~EditorUIView} view The view of the UI.
2225
*/
2326
constructor( editor, view ) {
24-
super( editor, view );
27+
super( editor );
28+
29+
/**
30+
* The main (top–most) view of the editor UI.
31+
*
32+
* @private
33+
* @member {module:ui/editorui/editoruiview~EditorUIView} #_view
34+
*/
35+
this._view = view;
2536

2637
/**
2738
* A normalized `config.toolbar` object.
@@ -32,6 +43,23 @@ export default class InlineEditorUI extends EditorUI {
3243
this._toolbarConfig = normalizeToolbarConfig( editor.config.get( 'toolbar' ) );
3344
}
3445

46+
/**
47+
* The main (top–most) view of the editor UI.
48+
*
49+
* @readonly
50+
* @member {module:ui/editorui/editoruiview~EditorUIView} #view
51+
*/
52+
get view() {
53+
return this._view;
54+
}
55+
56+
/**
57+
* @inheritDoc
58+
*/
59+
get element() {
60+
return this.view.editable.element;
61+
}
62+
3563
/**
3664
* Initializes the UI.
3765
*/
@@ -54,7 +82,7 @@ export default class InlineEditorUI extends EditorUI {
5482
// showing up when there's no focus in the UI.
5583
if ( view.panel.isVisible ) {
5684
view.panel.pin( {
57-
target: view.editableElement,
85+
target: view.editable.element,
5886
positions: view.panelPositions
5987
} );
6088
}
@@ -67,10 +95,12 @@ export default class InlineEditorUI extends EditorUI {
6795
// Bind to focusTracker instead of editor.editing.view because otherwise
6896
// focused editable styles disappear when view#toolbar is focused.
6997
view.editable.bind( 'isFocused' ).to( this.focusTracker );
70-
editor.editing.view.attachDomRoot( view.editableElement );
98+
editor.editing.view.attachDomRoot( view.editable.element );
7199
view.editable.name = editingRoot.rootName;
72100

73-
this.focusTracker.add( view.editableElement );
101+
this._editableElements.set( view.editable.name, view.editable.element );
102+
103+
this.focusTracker.add( view.editable.element );
74104

75105
view.toolbar.fillFromConfig( this._toolbarConfig.items, this.componentFactory );
76106

@@ -80,5 +110,16 @@ export default class InlineEditorUI extends EditorUI {
80110
originKeystrokeHandler: editor.keystrokes,
81111
toolbar: view.toolbar
82112
} );
113+
114+
this.fire( 'ready' );
115+
}
116+
117+
/**
118+
* @inheritDoc
119+
*/
120+
destroy() {
121+
this._view.destroy();
122+
123+
super.destroy();
83124
}
84125
}

src/inlineeditoruiview.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default class InlineEditorUIView extends EditorUIView {
7272

7373
/**
7474
* A set of positioning functions used by the {@link #panel} to float around
75-
* {@link #editableElement}.
75+
* {@link #element editableElement}.
7676
*
7777
* The positioning functions are as follows:
7878
*
@@ -143,18 +143,11 @@ export default class InlineEditorUIView extends EditorUIView {
143143
this.panel.content.add( this.toolbar );
144144
}
145145

146-
/**
147-
* @inheritDoc
148-
*/
149-
get editableElement() {
150-
return this.editable.element;
151-
}
152-
153146
/**
154147
* Determines the panel top position of the {@link #panel} in {@link #panelPositions}.
155148
*
156149
* @private
157-
* @param {module:utils/dom/rect~Rect} editableRect Rect of the {@link #editableElement}.
150+
* @param {module:utils/dom/rect~Rect} editableRect Rect of the {@link #element}.
158151
* @param {module:utils/dom/rect~Rect} panelRect Rect of the {@link #panel}.
159152
*/
160153
_getPanelPositionTop( editableRect, panelRect ) {

tests/inlineeditor.js

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

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

@@ -32,6 +34,8 @@ describe( 'InlineEditor', () => {
3234
editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
3335

3436
document.body.appendChild( editorElement );
37+
38+
testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
3539
} );
3640

3741
afterEach( () => {
@@ -111,11 +115,11 @@ describe( 'InlineEditor', () => {
111115
} );
112116
} );
113117

114-
it( 'editor.element should contain the whole editor (with UI) element', () => {
118+
it( 'editor.ui.element should contain the whole editor (with UI) element', () => {
115119
return InlineEditor.create( '<p>Hello world!</p>', {
116120
plugins: [ Paragraph ]
117121
} ).then( editor => {
118-
expect( editor.editing.view.getDomRoot() ).to.equal( editor.element );
122+
expect( editor.editing.view.getDomRoot() ).to.equal( editor.ui.element );
119123
} );
120124
} );
121125
} );
@@ -194,7 +198,7 @@ describe( 'InlineEditor', () => {
194198
class EventWatcher extends Plugin {
195199
init() {
196200
this.editor.on( 'pluginsReady', spy );
197-
this.editor.on( 'uiReady', spy );
201+
this.editor.ui.on( 'ready', spy );
198202
this.editor.on( 'dataReady', spy );
199203
this.editor.on( 'ready', spy );
200204
}
@@ -205,7 +209,7 @@ describe( 'InlineEditor', () => {
205209
plugins: [ EventWatcher ]
206210
} )
207211
.then( newEditor => {
208-
expect( fired ).to.deep.equal( [ 'pluginsReady', 'uiReady', 'dataReady', 'ready' ] );
212+
expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'dataReady', 'ready' ] );
209213

210214
editor = newEditor;
211215
} );
@@ -233,12 +237,12 @@ describe( 'InlineEditor', () => {
233237
} );
234238
} );
235239

236-
it( 'fires uiReady once UI is ready', () => {
240+
it( 'fires ready once UI is ready', () => {
237241
let isReady;
238242

239243
class EventWatcher extends Plugin {
240244
init() {
241-
this.editor.on( 'uiReady', () => {
245+
this.editor.ui.on( 'ready', () => {
242246
isReady = this.editor.ui.view.isRendered;
243247
} );
244248
}

tests/inlineeditorui.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
1717
import utils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
1818

1919
describe( 'InlineEditorUI', () => {
20-
let editor, view, ui;
20+
let editor, view, ui, viewElement;
2121

2222
testUtils.createSinonSandbox();
2323

@@ -31,6 +31,7 @@ describe( 'InlineEditorUI', () => {
3131

3232
ui = editor.ui;
3333
view = ui.view;
34+
viewElement = view.editable.element;
3435
} );
3536
} );
3637

@@ -93,7 +94,7 @@ describe( 'InlineEditorUI', () => {
9394
editor.ui.fire( 'update' );
9495
sinon.assert.calledOnce( spy );
9596
sinon.assert.calledWithExactly( spy, {
96-
target: view.editableElement,
97+
target: view.editable.element,
9798
positions: sinon.match.array
9899
} );
99100
} );
@@ -198,6 +199,26 @@ describe( 'InlineEditorUI', () => {
198199
} );
199200
} );
200201
} );
202+
203+
describe( 'element()', () => {
204+
it( 'returns correct element instance', () => {
205+
expect( ui.element ).to.equal( viewElement );
206+
} );
207+
} );
208+
209+
describe( 'getEditableElement()', () => {
210+
it( 'returns editable element (default)', () => {
211+
expect( ui.getEditableElement() ).to.equal( view.editable.element );
212+
} );
213+
214+
it( 'returns editable element (root name passed)', () => {
215+
expect( ui.getEditableElement( 'main' ) ).to.equal( view.editable.element );
216+
} );
217+
218+
it( 'returns undefined if editable with the given name is absent', () => {
219+
expect( ui.getEditableElement( 'absent' ) ).to.be.undefined;
220+
} );
221+
} );
201222
} );
202223

203224
function viewCreator( name ) {
@@ -236,7 +257,6 @@ class VirtualInlineTestEditor extends VirtualTestEditor {
236257
editor.initPlugins()
237258
.then( () => {
238259
editor.ui.init();
239-
editor.fire( 'uiReady' );
240260
editor.fire( 'dataReady' );
241261
editor.fire( 'ready' );
242262
} )

tests/inlineeditoruiview.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpa
99
import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
1010
import Locale from '@ckeditor/ckeditor5-utils/src/locale';
1111

12+
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
13+
1214
describe( 'InlineEditorUIView', () => {
1315
let locale, view;
1416

17+
testUtils.createSinonSandbox();
18+
1519
beforeEach( () => {
1620
locale = new Locale( 'en' );
1721
view = new InlineEditorUIView( locale );
@@ -117,14 +121,6 @@ describe( 'InlineEditorUIView', () => {
117121
} );
118122
} );
119123

120-
describe( 'editableElement', () => {
121-
it( 'returns editable\'s view element', () => {
122-
view.render();
123-
expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
124-
view.destroy();
125-
} );
126-
} );
127-
128124
describe( 'panelPositions', () => {
129125
it( 'returns the positions in the right order', () => {
130126
const positions = view.panelPositions;

0 commit comments

Comments
 (0)