8
0
Просмотр исходного кода

Add command for marking parts of content as non restricted to editing.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
a8f253172b

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

@@ -8,6 +8,7 @@
  */
 
 import Plugin from './plugin';
+import RestrictedDocumentCommand from './restricteddocumentcommand';
 
 /**
  * @extends module:core/plugin~Plugin
@@ -35,5 +36,7 @@ export default class RestrictedDocument extends Plugin {
 				classes: 'ck-non-restricted'
 			}
 		} );
+
+		editor.commands.add( 'norRestricted', new RestrictedDocumentCommand( editor ) );
 	}
 }

+ 27 - 0
packages/ckeditor5-restricted-editing/src/restricteddocumentcommand.js

@@ -0,0 +1,27 @@
+/**
+ * @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/restricteddocumentcommand
+ */
+
+import Command from './command';
+
+/**
+ * @extends module:core/command~Command
+ */
+export default class RestrictedDocumentCommand extends Command {
+	/**
+	 * @inheritDoc
+	 */
+	refresh() {
+		const model = this.editor.model;
+		const doc = model.document;
+
+		this.value = doc.selection.getAttribute( 'nonRestricted' );
+
+		this.isEnabled = model.schema.checkAttributeInSelection( doc.selection, 'nonRestricted' );
+	}
+}

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

@@ -11,6 +11,7 @@ import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils
 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( 'RestrictedDocument', () => {
 	let editor, model;
@@ -49,6 +50,12 @@ describe( 'RestrictedDocument', () => {
 		expect( model.schema.checkAttribute( [ '$block' ], 'nonRestricted' ) ).to.be.false;
 	} );
 
+	it( 'should register command', () => {
+		const command = editor.commands.get( 'norRestricted' );
+
+		expect( command ).to.be.instanceof( RestrictedDocumentCommand );
+	} );
+
 	describe( 'conversion', () => {
 		describe( 'upcast', () => {
 			it( 'should convert <span class="ck-non-restricted"> to model attribute', () => {