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

Commit

Permalink
Used secureSourceElement() as a helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Jul 22, 2019
1 parent dad8e42 commit b9681ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ 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';
import secureSourceElement from '@ckeditor/ckeditor5-core/src/editor/utils/securesourceelement';

/**
* The {@glink builds/guides/overview#document-editor decoupled editor} implementation.
Expand Down Expand Up @@ -48,7 +48,6 @@ 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 @@ -70,7 +69,7 @@ export default class DecoupledEditor extends Editor {

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

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

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

function getInitialData( sourceElementOrData ) {
return isElement( sourceElementOrData ) ? getDataFromElement( sourceElementOrData ) : sourceElementOrData;
Expand Down
24 changes: 13 additions & 11 deletions tests/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ 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 @@ -49,10 +47,6 @@ 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 @@ -134,13 +128,21 @@ 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' );
let editor;

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/ );

.then( newEditor => {
editor = newEditor;

return new DecoupledEditor( sourceElement );
} )
.then( () => {
expect.fail( 'Decoupled editor should not initialize on an element already used by other instance.' );
} )
.catch( err => {
assertCKEditorError( err, /^editor-source-element-used-more-than-once/ );
} )
.finally( () => {
return editor.destroy();
} );
} );
Expand Down

0 comments on commit b9681ca

Please sign in to comment.