Procházet zdrojové kódy

Define text attribute marking non-restricted parts of content.

Maciej Gołaszewski před 6 roky
rodič
revize
95679da202

+ 29 - 0
packages/ckeditor5-restricted-editing/src/restricteddocument.js

@@ -0,0 +1,29 @@
+/**
+ * @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/restricteddocument
+ */
+
+import Plugin from './plugin';
+
+/**
+ * @extends module:core/plugin~Plugin
+ */
+export default class RestrictedDocument extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'RestrictedDocument';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		this.editor.model.schema.extend( '$text', { allowAttributes: [ 'nonRestricted' ] } );
+	}
+}

+ 48 - 0
packages/ckeditor5-restricted-editing/tests/restricteddocument.js

@@ -0,0 +1,48 @@
+/**
+ * @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 testUtils from './_utils/utils';
+import VirtualTestEditor from './_utils/virtualtesteditor';
+
+import RestrictedDocument from './../src/restricteddocument';
+
+describe( 'RestrictedDocument', () => {
+	let editor;
+
+	testUtils.createSinonSandbox();
+
+	beforeEach( () => {
+		return VirtualTestEditor
+			.create( { plugins: [ RestrictedDocument ] } )
+			.then( newEditor => {
+				editor = newEditor;
+			} );
+	} );
+
+	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', () => {
+		const model = editor.model;
+
+		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;
+	} );
+} );