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

Commit

Permalink
Merge 918e170 into ead6e41
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames authored Jan 15, 2019
2 parents ead6e41 + 918e170 commit 9facfe4
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/inlineeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import InlineEditorUIView from './inlineeditoruiview';
import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromelement';
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import log from '@ckeditor/ckeditor5-utils/src/log';
import { isElement } from 'lodash-es';

/**
Expand Down Expand Up @@ -79,7 +80,8 @@ export default class InlineEditor extends Editor {
* @inheritDoc
*/
get element() {
return this.ui.view.editable.element;
log.warn( 'deprecated-editor-element: The editor#element is deprecated.' );
return this.ui.element;
}

/**
Expand Down Expand Up @@ -179,6 +181,8 @@ export default class InlineEditor extends Editor {
editor.initPlugins()
.then( () => {
editor.ui.init();
editor.ui.ready();

editor.fire( 'uiReady' );
} )
.then( () => {
Expand Down
45 changes: 40 additions & 5 deletions src/inlineeditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalize
*/
export default class InlineEditorUI extends EditorUI {
/**
* @inheritDoc
* Creates an instance of the inline 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.
Expand All @@ -32,6 +43,30 @@ export default class InlineEditorUI extends EditorUI {
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
*/
get element() {
return this.view.editable.element;
}

/**
* @inheritDoc
*/
getEditableElement( rootName = 'main' ) {
return this.view.editable.name === rootName ? this.view.editable : null;
}

/**
* Initializes the UI.
*/
Expand All @@ -54,7 +89,7 @@ export default class InlineEditorUI extends EditorUI {
// showing up when there's no focus in the UI.
if ( view.panel.isVisible ) {
view.panel.pin( {
target: view.editableElement,
target: view.editable.editableElement,
positions: view.panelPositions
} );
}
Expand All @@ -67,10 +102,10 @@ export default class InlineEditorUI extends EditorUI {
// Bind to focusTracker instead of editor.editing.view because otherwise
// focused editable styles disappear when view#toolbar is focused.
view.editable.bind( 'isFocused' ).to( this.focusTracker );
editor.editing.view.attachDomRoot( view.editableElement );
editor.editing.view.attachDomRoot( view.editable.editableElement );
view.editable.name = editingRoot.rootName;

this.focusTracker.add( view.editableElement );
this.focusTracker.add( view.editable.editableElement );

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

Expand Down
15 changes: 13 additions & 2 deletions src/inlineeditoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/i
import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpanelview';
import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';

import log from '@ckeditor/ckeditor5-utils/src/log';

/**
* Inline editor UI view. Uses an nline editable and a floating toolbar.
*
Expand Down Expand Up @@ -144,10 +146,19 @@ export default class InlineEditorUIView extends EditorUIView {
}

/**
* @inheritDoc
* **Deprecated** since `v12.0.0`. The {@link module:ui/editableui/editableuiview~EditableUIView#editableElement
* `EditableUIView editableElement`} could be used instead.
*
* The element which is the main editable element (usually the one with `contentEditable="true"`).
*
* @deprecated v12.0.0 The {@link module:ui/editableui/editableuiview~EditableUIView#editableElement
* `EditableUIView editableElement`} could be used instead.
* @readonly
* @member {HTMLElement} #editableElement
*/
get editableElement() {
return this.editable.element;
log.warn( 'deprecated-ui-view-editableElement: The InlineEditorUIView#editableElement property is deprecated.' );
return this.editable.editableElement;
}

/**
Expand Down
36 changes: 35 additions & 1 deletion tests/inlineeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ElementApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/elementap
import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';

import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import log from '@ckeditor/ckeditor5-utils/src/log';

describe( 'InlineEditor', () => {
let editor, editorElement;
Expand All @@ -30,6 +31,8 @@ describe( 'InlineEditor', () => {
editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';

document.body.appendChild( editorElement );

testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
} );

afterEach( () => {
Expand Down Expand Up @@ -116,6 +119,14 @@ describe( 'InlineEditor', () => {
expect( editor.editing.view.getDomRoot() ).to.equal( editor.element );
} );
} );

it( 'editor.ui.element should contain the whole editor (with UI) element', () => {
return InlineEditor.create( '<p>Hello world!</p>', {
plugins: [ Paragraph ]
} ).then( editor => {
expect( editor.editing.view.getDomRoot() ).to.equal( editor.ui.element );
} );
} );
} );

describe( 'create()', () => {
Expand Down Expand Up @@ -192,6 +203,7 @@ describe( 'InlineEditor', () => {
class EventWatcher extends Plugin {
init() {
this.editor.on( 'pluginsReady', spy );
this.editor.ui.on( 'ready', spy );
this.editor.on( 'uiReady', spy );
this.editor.on( 'dataReady', spy );
this.editor.on( 'ready', spy );
Expand All @@ -203,7 +215,7 @@ describe( 'InlineEditor', () => {
plugins: [ EventWatcher ]
} )
.then( newEditor => {
expect( fired ).to.deep.equal( [ 'pluginsReady', 'uiReady', 'dataReady', 'ready' ] );
expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'uiReady', 'dataReady', 'ready' ] );

editor = newEditor;
} );
Expand Down Expand Up @@ -252,6 +264,28 @@ describe( 'InlineEditor', () => {
editor = newEditor;
} );
} );

it( 'fires ready once UI is ready', () => {
let isReady;

class EventWatcher extends Plugin {
init() {
this.editor.ui.on( 'ready', () => {
isReady = this.editor.ui.view.isRendered;
} );
}
}

return InlineEditor
.create( editorElement, {
plugins: [ EventWatcher ]
} )
.then( newEditor => {
expect( isReady ).to.be.true;

editor = newEditor;
} );
} );
} );

describe( 'destroy', () => {
Expand Down
17 changes: 16 additions & 1 deletion tests/inlineeditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe( 'InlineEditorUI', () => {
editor.ui.fire( 'update' );
sinon.assert.calledOnce( spy );
sinon.assert.calledWithExactly( spy, {
target: view.editableElement,
target: view.editable.editableElement,
positions: sinon.match.array
} );
} );
Expand Down Expand Up @@ -198,6 +198,20 @@ describe( 'InlineEditorUI', () => {
} );
} );
} );

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 ) {
Expand Down Expand Up @@ -236,6 +250,7 @@ class VirtualInlineTestEditor extends VirtualTestEditor {
editor.initPlugins()
.then( () => {
editor.ui.init();
editor.ui.ready();
editor.fire( 'uiReady' );
editor.fire( 'dataReady' );
editor.fire( 'ready' );
Expand Down
7 changes: 7 additions & 0 deletions tests/inlineeditoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpa
import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
import Locale from '@ckeditor/ckeditor5-utils/src/locale';

import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import log from '@ckeditor/ckeditor5-utils/src/log';

describe( 'InlineEditorUIView', () => {
let locale, view;

testUtils.createSinonSandbox();

beforeEach( () => {
locale = new Locale( 'en' );
view = new InlineEditorUIView( locale );
Expand Down Expand Up @@ -119,6 +124,8 @@ describe( 'InlineEditorUIView', () => {

describe( 'editableElement', () => {
it( 'returns editable\'s view element', () => {
testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );

view.render();
expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
view.destroy();
Expand Down

0 comments on commit 9facfe4

Please sign in to comment.