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

Commit

Permalink
Merge dad8e42 into 24bee4c
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Jul 19, 2019
2 parents 24bee4c + dad8e42 commit 1d55599
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/decouplededitor.js
Expand Up @@ -14,6 +14,7 @@ import DecoupledEditorUI from './decouplededitorui';
import DecoupledEditorUIView from './decouplededitoruiview';
import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromelement';
import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
import ElementApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/elementapimixin';
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import { isElement } from 'lodash-es';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
Expand Down Expand Up @@ -47,6 +48,7 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
* {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}.
*
* @mixes module:core/editor/utils/dataapimixin~DataApiMixin
* @mixes module:core/editor/utils/elementapimixin~ElementApiMixin
* @implements module:core/editor/editorwithui~EditorWithUI
* @extends module:core/editor/editor~Editor
*/
Expand All @@ -68,6 +70,7 @@ export default class DecoupledEditor extends Editor {

if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
this.secureSourceElement();
}

this.data.processor = new HtmlDataProcessor();
Expand Down Expand Up @@ -252,6 +255,7 @@ export default class DecoupledEditor extends Editor {
}

mix( DecoupledEditor, DataApiMixin );
mix( DecoupledEditor, ElementApiMixin );

function getInitialData( sourceElementOrData ) {
return isElement( sourceElementOrData ) ? getDataFromElement( sourceElementOrData ) : sourceElementOrData;
Expand Down
20 changes: 20 additions & 0 deletions tests/decouplededitor.js
Expand Up @@ -15,12 +15,14 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import DataApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/dataapimixin';
import ElementApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/elementapimixin';
import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';

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

import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

const editorData = '<p><strong>foo</strong> bar</p>';
Expand All @@ -47,6 +49,10 @@ describe( 'DecoupledEditor', () => {
expect( testUtils.isMixed( DecoupledEditor, DataApiMixin ) ).to.be.true;
} );

it( 'has an Element Interface', () => {
testUtils.isMixed( DecoupledEditor, ElementApiMixin );
} );

it( 'creates main root element', () => {
expect( editor.model.document.getRoot( 'main' ) ).to.instanceof( RootElement );
} );
Expand Down Expand Up @@ -125,6 +131,20 @@ describe( 'DecoupledEditor', () => {
} );
} );

// See: https://github.com/ckeditor/ckeditor5/issues/746
it( 'should throw when trying to create the editor using the same source element more than once', () => {
const sourceElement = document.createElement( 'div' );

return DecoupledEditor.create( sourceElement )
.then( editor => {
expect( () => {
new DecoupledEditor( sourceElement ); // eslint-disable-line no-new
} ).to.throw( CKEditorError, /^editor-source-element-used-more-than-once/ );

return editor.destroy();
} );
} );

it( 'throws if initial data is passed in Editor#create and config.initialData is also used', done => {
DecoupledEditor.create( '<p>Hello world!</p>', {
initialData: '<p>I am evil!</p>',
Expand Down

0 comments on commit 1d55599

Please sign in to comment.