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

Commit

Permalink
Merge 76aeef3 into 6a79fcf
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Jul 3, 2018
2 parents 6a79fcf + 76aeef3 commit bcee8f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
33 changes: 22 additions & 11 deletions src/decouplededitor.js
Expand Up @@ -57,15 +57,15 @@ export default class DecoupledEditor extends Editor {
* {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`} method instead.
*
* @protected
* @param {HTMLElement|String} elementOrData The DOM element that serves as an editable.
* @param {HTMLElement|String} sourceElementOrData The DOM element that serves as an editable.
* The data will be loaded from it and loaded back to it once the editor is destroyed.
* Alternatively, a data string to be loaded into the editor.
* @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
*/
constructor( elementOrData, config ) {
constructor( sourceElementOrData, config ) {
super( config );

if ( isElement( elementOrData ) ) {
if ( isElement( sourceElementOrData ) ) {
/**
* The element used as an editable. The data will be loaded from it and loaded back to
* it once the editor is destroyed.
Expand All @@ -76,14 +76,21 @@ export default class DecoupledEditor extends Editor {
* @readonly
* @member {HTMLElement}
*/
this.element = elementOrData;
this.sourceElement = sourceElementOrData;
}

this.data.processor = new HtmlDataProcessor();

this.model.document.createRoot();

this.ui = new DecoupledEditorUI( this, new DecoupledEditorUIView( this.locale, this.element ) );
this.ui = new DecoupledEditorUI( this, new DecoupledEditorUIView( this.locale, this.sourceElement ) );
}

/**
* @inheritDoc
*/
get element() {
return null;
}

/**
Expand Down Expand Up @@ -114,8 +121,8 @@ export default class DecoupledEditor extends Editor {

return super.destroy()
.then( () => {
if ( this.element ) {
setDataInElement( this.element, data );
if ( this.sourceElement ) {
setDataInElement( this.sourceElement, data );
}
} );
}
Expand Down Expand Up @@ -178,16 +185,16 @@ export default class DecoupledEditor extends Editor {
* console.error( err.stack );
* } );
*
* @param {HTMLElement|String} elementOrData The DOM element that serves as an editable.
* @param {HTMLElement|String} sourceElementOrData The DOM element that serves as an editable.
* The data will be loaded from it and loaded back to it once the editor is destroyed.
* Alternatively, a data string to be loaded into the editor.
* @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
* @returns {Promise} A promise resolved once the editor is ready.
* The promise returns the created {@link module:editor-decoupled/decouplededitor~DecoupledEditor} instance.
*/
static create( elementOrData, config ) {
static create( sourceElementOrData, config ) {
return new Promise( resolve => {
const editor = new this( elementOrData, config );
const editor = new this( sourceElementOrData, config );

resolve(
editor.initPlugins()
Expand All @@ -196,7 +203,11 @@ export default class DecoupledEditor extends Editor {
editor.fire( 'uiReady' );
} )
.then( () => {
return editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
const initialData = isElement( sourceElementOrData ) ?
getDataFromElement( sourceElementOrData ) :
sourceElementOrData;

return editor.data.init( initialData );
} )
.then( () => {
editor.fire( 'dataReady' );
Expand Down
6 changes: 5 additions & 1 deletion tests/decouplededitor.js
Expand Up @@ -36,7 +36,11 @@ describe( 'DecoupledEditor', () => {
} );

it( 'has a Data Interface', () => {
testUtils.isMixed( DecoupledEditor, DataApiMixin );
expect( testUtils.isMixed( DecoupledEditor, DataApiMixin ) ).to.be.true;
} );

it( 'implements the EditorWithUI interface', () => {
expect( editor.element ).to.be.null;
} );

it( 'creates main root element', () => {
Expand Down

0 comments on commit bcee8f6

Please sign in to comment.