Explorar el Código

Split restricted editing plugins.

Maciej Gołaszewski hace 6 años
padre
commit
ee092efb00

+ 5 - 18
packages/ckeditor5-restricted-editing/src/restricteddocument.js

@@ -8,7 +8,9 @@
  */
 
 import Plugin from './plugin';
-import RestrictedDocumentCommand from './restricteddocumentcommand';
+
+import RestrictedDocumentEditing from './restricteddocumentediting';
+import RestrictedDocumentUI from './restricteddocumentui';
 
 /**
  * @extends module:core/plugin~Plugin
@@ -21,22 +23,7 @@ export default class RestrictedDocument extends Plugin {
 		return 'RestrictedDocument';
 	}
 
-	/**
-	 * @inheritDoc
-	 */
-	init() {
-		const editor = this.editor;
-
-		editor.model.schema.extend( '$text', { allowAttributes: [ 'nonRestricted' ] } );
-
-		editor.conversion.attributeToElement( {
-			model: 'nonRestricted',
-			view: {
-				name: 'span',
-				classes: 'ck-non-restricted'
-			}
-		} );
-
-		editor.commands.add( 'nonRestricted', new RestrictedDocumentCommand( editor ) );
+	static get requires() {
+		return [ RestrictedDocumentEditing, RestrictedDocumentUI ];
 	}
 }

+ 42 - 0
packages/ckeditor5-restricted-editing/src/restricteddocumentediting.js

@@ -0,0 +1,42 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/**
+ * @module core/restricteddocumentediting
+ */
+
+import Plugin from './plugin';
+import RestrictedDocumentCommand from './restricteddocumentcommand';
+
+/**
+ * @extends module:core/plugin~Plugin
+ */
+export default class RestrictedDocumentEditing extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'RestrictedDocumentEditing';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const editor = this.editor;
+
+		editor.model.schema.extend( '$text', { allowAttributes: [ 'nonRestricted' ] } );
+
+		editor.conversion.attributeToElement( {
+			model: 'nonRestricted',
+			view: {
+				name: 'span',
+				classes: 'ck-non-restricted'
+			}
+		} );
+
+		editor.commands.add( 'nonRestricted', new RestrictedDocumentCommand( editor ) );
+	}
+}

+ 16 - 52
packages/ckeditor5-restricted-editing/tests/restricteddocument.js

@@ -3,31 +3,30 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+/* global document */
 
 import testUtils from './_utils/utils';
-import VirtualTestEditor from './_utils/virtualtesteditor';
-import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
-import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import ClassicTestEditor from './_utils/classictesteditor';
 
 import RestrictedDocument from './../src/restricteddocument';
-import RestrictedDocumentCommand from '../src/restricteddocumentcommand';
+import RestrictedDocumentUI from './../src/restricteddocumentui';
+import RestrictedDocumentEditing from './../src/restricteddocumentediting';
 
 describe( 'RestrictedDocument', () => {
-	let editor, model;
+	let editor, element;
 
 	testUtils.createSinonSandbox();
 
-	beforeEach( () => {
-		return VirtualTestEditor
-			.create( { plugins: [ Paragraph, RestrictedDocument ] } )
-			.then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-			} );
+	beforeEach( async () => {
+		element = document.createElement( 'div' );
+		document.body.appendChild( element );
+
+		editor = await ClassicTestEditor.create( element, { plugins: [ RestrictedDocument ] } );
 	} );
 
 	afterEach( () => {
+		element.remove();
+
 		if ( editor ) {
 			return editor.destroy();
 		}
@@ -37,46 +36,11 @@ describe( 'RestrictedDocument', () => {
 		expect( RestrictedDocument.pluginName ).to.equal( 'RestrictedDocument' );
 	} );
 
-	it( 'should be loaded', () => {
-		expect( editor.plugins.get( 'RestrictedDocument' ) ).to.be.instanceOf( RestrictedDocument );
+	it( 'should load the RestrictedDocumentEditing plugin', () => {
+		expect( editor.plugins.get( RestrictedDocumentEditing ) ).to.be.instanceOf( RestrictedDocumentEditing );
 	} );
 
-	it( 'should set proper schema rules', () => {
-		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'nonRestricted' ) ).to.be.true;
-
-		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'nonRestricted' ) ).to.be.true;
-		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'nonRestricted' ) ).to.be.true;
-
-		expect( model.schema.checkAttribute( [ '$block' ], 'nonRestricted' ) ).to.be.false;
-	} );
-
-	it( 'should register command', () => {
-		const command = editor.commands.get( 'nonRestricted' );
-
-		expect( command ).to.be.instanceof( RestrictedDocumentCommand );
-	} );
-
-	describe( 'conversion', () => {
-		describe( 'upcast', () => {
-			it( 'should convert <span class="ck-non-restricted"> to model attribute', () => {
-				editor.setData( '<p>foo <span class="ck-non-restricted">bar</span> baz</p>' );
-
-				expect( getModelData( model, { withoutSelection: true } ) )
-					.to.equal( '<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>' );
-			} );
-		} );
-
-		describe( 'downcast', () => {
-			it( 'should convert model attribute to <span>', () => {
-				const expectedView = '<p>foo <span class="ck-non-restricted">bar</span> baz</p>';
-
-				setModelData( editor.model,
-					'<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>'
-				);
-
-				expect( editor.getData() ).to.equal( expectedView );
-				expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
-			} );
-		} );
+	it( 'should load the RestrictedDocumentUI plugin', () => {
+		expect( editor.plugins.get( RestrictedDocumentUI ) ).to.be.instanceOf( RestrictedDocumentUI );
 	} );
 } );

+ 82 - 0
packages/ckeditor5-restricted-editing/tests/restricteddocumentediting.js

@@ -0,0 +1,82 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
+import testUtils from './_utils/utils';
+import VirtualTestEditor from './_utils/virtualtesteditor';
+import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+import RestrictedDocument from './../src/restricteddocument';
+import RestrictedDocumentCommand from '../src/restricteddocumentcommand';
+
+describe( 'RestrictedDocumentEditing', () => {
+	let editor, model;
+
+	testUtils.createSinonSandbox();
+
+	beforeEach( () => {
+		return VirtualTestEditor
+			.create( { plugins: [ Paragraph, RestrictedDocument ] } )
+			.then( newEditor => {
+				editor = newEditor;
+				model = editor.model;
+			} );
+	} );
+
+	afterEach( () => {
+		if ( editor ) {
+			return editor.destroy();
+		}
+	} );
+
+	it( 'should be named', () => {
+		expect( RestrictedDocument.pluginName ).to.equal( 'RestrictedDocument' );
+	} );
+
+	it( 'should be loaded', () => {
+		expect( editor.plugins.get( 'RestrictedDocument' ) ).to.be.instanceOf( RestrictedDocument );
+	} );
+
+	it( 'should set proper schema rules', () => {
+		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'nonRestricted' ) ).to.be.true;
+
+		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'nonRestricted' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'nonRestricted' ) ).to.be.true;
+
+		expect( model.schema.checkAttribute( [ '$block' ], 'nonRestricted' ) ).to.be.false;
+	} );
+
+	it( 'should register command', () => {
+		const command = editor.commands.get( 'nonRestricted' );
+
+		expect( command ).to.be.instanceof( RestrictedDocumentCommand );
+	} );
+
+	describe( 'conversion', () => {
+		describe( 'upcast', () => {
+			it( 'should convert <span class="ck-non-restricted"> to model attribute', () => {
+				editor.setData( '<p>foo <span class="ck-non-restricted">bar</span> baz</p>' );
+
+				expect( getModelData( model, { withoutSelection: true } ) )
+					.to.equal( '<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>' );
+			} );
+		} );
+
+		describe( 'downcast', () => {
+			it( 'should convert model attribute to <span>', () => {
+				const expectedView = '<p>foo <span class="ck-non-restricted">bar</span> baz</p>';
+
+				setModelData( editor.model,
+					'<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>'
+				);
+
+				expect( editor.getData() ).to.equal( expectedView );
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
+			} );
+		} );
+	} );
+} );