Browse Source

Used secureSourceElement() as a helper.

Aleksander Nowodzinski 6 years ago
parent
commit
9a69bb78a0

+ 2 - 4
packages/ckeditor5-editor-decoupled/src/decouplededitor.js

@@ -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.
@@ -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
  */
@@ -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();
@@ -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;

+ 13 - 11
packages/ckeditor5-editor-decoupled/tests/decouplededitor.js

@@ -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>';
@@ -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 );
 		} );
@@ -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();
 				} );
 		} );