Sfoglia il codice sorgente

Removed the command and editing part of the feature.

Kamil Piechaczek 6 anni fa
parent
commit
6f8f662a8c

+ 0 - 45
packages/ckeditor5-special-characters/src/insertspecialcharactercommand.js

@@ -1,45 +0,0 @@
-/**
- * @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 special-characters/insertspecialcharactercommand
- */
-
-import Command from '@ckeditor/ckeditor5-core/src/command';
-
-/**
- * @extends module:core/command~Command
- */
-export default class InsertSpecialCharacterCommand extends Command {
-	/**
-	 * Creates an instance of the command.
-	 *
-	 * @param {module:core/editor/editor~Editor} editor
-	 */
-	constructor( editor ) {
-		super( editor );
-
-		/**
-		 * @readonly
-		 * @private
-		 * @member {module:typing/inputcommand~InputCommand} #_inputCommand
-		 */
-		this._inputCommand = editor.commands.get( 'input' );
-
-		// Use the state of `Input` command to determine whether the special characters could be inserted.
-		this.bind( 'isEnabled' ).to( this._inputCommand, 'isEnabled' );
-	}
-
-	/**
-	 * @param {Object} options
-	 * @param {String} options.item An id of the special character that should be added to the editor.
-	 */
-	execute( options ) {
-		const editor = this.editor;
-		const character = editor.plugins.get( 'SpecialCharacters' ).getCharacter( options.item );
-
-		this._inputCommand.execute( { text: character } );
-	}
-}

+ 3 - 4
packages/ckeditor5-special-characters/src/specialcharacters.js

@@ -9,7 +9,6 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import SpecialCharactersUI from './specialcharactersui';
-import SpecialCharactersEditing from './specialcharactersediting';
 
 import '../theme/specialcharacters.css';
 
@@ -46,7 +45,7 @@ export default class SpecialCharacters extends Plugin {
 	 * @inheritDoc
 	 */
 	static get requires() {
-		return [ SpecialCharactersEditing, SpecialCharactersUI ];
+		return [ SpecialCharactersUI ];
 	}
 
 	/**
@@ -118,6 +117,6 @@ export default class SpecialCharacters extends Plugin {
 /**
  * @typedef {Object} module:special-characters/specialcharacters~SpecialCharacterDefinition
  *
- * @property {String} title A unique title of the character.
- * @property {String} character A symbol that should be inserted to the editor.
+ * @property {String} title A unique name of the character (e.g. "greek small letter epsilon").
+ * @property {String} character A human-readable character displayed as label (e.g. "ε").
  */

+ 0 - 45
packages/ckeditor5-special-characters/src/specialcharactersediting.js

@@ -1,45 +0,0 @@
-/**
- * @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 special-characters/specialcharactersediting
- */
-
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import Typing from '@ckeditor/ckeditor5-typing/src/typing';
-import InsertSpecialCharacterCommand from './insertspecialcharactercommand';
-
-/**
- * Special characters editing plugin.
- *
- * It registers the {@link module:special-characters/insertspecialcharactercommand~InsertSpecialCharacterCommand Special Character} command.
- *
- * @extends module:core/plugin~Plugin
- */
-export default class SpecialCharactersEditing extends Plugin {
-	/**
-	 * @inheritDoc
-	 */
-	static get pluginName() {
-		return 'SpecialCharactersEditing';
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	static get requires() {
-		return [ Typing ];
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	init() {
-		const editor = this.editor;
-
-		const command = new InsertSpecialCharacterCommand( editor );
-		editor.commands.add( 'insertSpecialCharacter', command );
-	}
-}

+ 12 - 3
packages/ckeditor5-special-characters/src/specialcharactersui.js

@@ -12,6 +12,7 @@ import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
 import specialCharactersIcon from '../theme/icons/specialcharacters.svg';
 import CharacterGridView from './ui/charactergridview';
 import SpecialCharactersNavigationView from './ui/specialcharactersnavigationview';
+import Typing from '@ckeditor/ckeditor5-typing/src/typing';
 
 /**
  * The special characters UI plugin.
@@ -28,12 +29,21 @@ export default class SpecialCharactersUI extends Plugin {
 		return 'SpecialCharactersUI';
 	}
 
+	/**
+	 * @inheritDoc
+	 */
+	static get requires() {
+		return [ Typing ];
+	}
+
 	/**
 	 * @inheritDoc
 	 */
 	init() {
 		const editor = this.editor;
 		const t = editor.t;
+
+		const inputCommand = editor.commands.get( 'input' );
 		const specialCharsPlugin = editor.plugins.get( 'SpecialCharacters' );
 
 		// Add the `specialCharacters` dropdown button to feature components.
@@ -43,7 +53,6 @@ export default class SpecialCharactersUI extends Plugin {
 			const gridView = new CharacterGridView( this.locale, {
 				columns: 10
 			} );
-			const command = editor.commands.get( 'insertSpecialCharacter' );
 
 			gridView.delegate( 'execute' ).to( dropdownView );
 
@@ -61,11 +70,11 @@ export default class SpecialCharactersUI extends Plugin {
 				tooltip: true
 			} );
 
-			dropdownView.bind( 'isEnabled' ).to( command );
+			dropdownView.bind( 'isEnabled' ).to( inputCommand );
 
 			// Insert a special character when a tile was clicked.
 			dropdownView.on( 'execute', ( evt, data ) => {
-				editor.execute( 'insertSpecialCharacter', { item: data.name } );
+				editor.execute( 'input', { text: data.character } );
 				editor.editing.view.focus();
 			} );
 

+ 3 - 2
packages/ckeditor5-special-characters/src/ui/charactergridview.js

@@ -62,7 +62,8 @@ export default class CharacterGridView extends View {
 		 *
 		 * @event execute
 		 * @param {Object} data Additional information about the event.
-		 * @param {String} data.name Name of the tile that caused the event (e.g. "greek small letter epsilon").
+		 * @param {String} data.name A name of the tile that caused the event (e.g. "greek small letter epsilon").
+		 * @param {String} data.character A human-readable character displayed as label (e.g. "ε").
 		 */
 	}
 
@@ -91,7 +92,7 @@ export default class CharacterGridView extends View {
 		} );
 
 		tile.on( 'execute', () => {
-			this.fire( 'execute', { name } );
+			this.fire( 'execute', { name, character } );
 		} );
 
 		return tile;

+ 0 - 109
packages/ckeditor5-special-characters/tests/insertspecialcharactercommand.js

@@ -1,109 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
-
-/* globals document */
-
-import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
-import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
-import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
-import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import SpecialCharacters from '../src/specialcharacters';
-
-describe( 'InsertSpecialCharacterCommand', () => {
-	let editor, model, editorElement, command;
-
-	testUtils.createSinonSandbox();
-
-	beforeEach( () => {
-		editorElement = document.createElement( 'div' );
-		document.body.appendChild( editorElement );
-
-		return ClassicTestEditor
-			.create( editorElement, {
-				plugins: [ Paragraph, SpecialCharacters ]
-			} )
-			.then( newEditor => {
-				editor = newEditor;
-				model = editor.model;
-				command = editor.commands.get( 'insertSpecialCharacter' );
-
-				editor.plugins.get( 'SpecialCharacters' ).addItems( 'Arrows', [
-					{ title: 'arrow left', character: '←' },
-					{ title: 'arrow right', character: '→' }
-				] );
-			} );
-	} );
-
-	afterEach( () => {
-		return editor.destroy()
-			.then( () => {
-				editorElement.remove();
-			} );
-	} );
-
-	describe( 'isEnabled', () => {
-		it( 'should be bound to InputCommand#isEnables', () => {
-			const inputCommand = editor.commands.get( 'input' );
-
-			inputCommand.isEnabled = true;
-			expect( command.isEnabled ).to.equal( true );
-
-			inputCommand.isEnabled = false;
-			expect( command.isEnabled ).to.equal( false );
-		} );
-	} );
-
-	describe( 'execute()', () => {
-		it( 'should create a single batch', () => {
-			setModelData( model, '<paragraph>foo[]</paragraph>' );
-
-			const spy = sinon.spy();
-
-			model.document.on( 'change', spy );
-
-			command.execute( { item: 'arrow left' } );
-
-			sinon.assert.calledOnce( spy );
-		} );
-
-		it( 'executes InputCommand#execute()', () => {
-			const inputCommand = editor.commands.get( 'input' );
-
-			setModelData( model, '<paragraph>foo[]</paragraph>' );
-
-			const spy = sinon.stub( inputCommand, 'execute' );
-
-			command.execute( { item: 'arrow left' } );
-
-			sinon.assert.calledWithExactly( spy, { text: '←' } );
-
-			spy.restore();
-		} );
-
-		it( 'does nothing if specified object is invalid', () => {
-			setModelData( model, '<paragraph>foo[]</paragraph>' );
-
-			const spy = sinon.spy();
-
-			model.document.on( 'change', spy );
-
-			command.execute( { foo: 'arrow left' } );
-
-			sinon.assert.notCalled( spy );
-		} );
-
-		it( 'does nothing if specified item name does not exist', () => {
-			setModelData( model, '<paragraph>foo[]</paragraph>' );
-
-			const spy = sinon.spy();
-
-			model.document.on( 'change', spy );
-
-			command.execute( { item: 'arrow up' } );
-
-			sinon.assert.notCalled( spy );
-		} );
-	} );
-} );

+ 1 - 2
packages/ckeditor5-special-characters/tests/specialcharacters.js

@@ -5,7 +5,6 @@
 
 import SpecialCharacters from '../src/specialcharacters';
 import SpecialCharactersUI from '../src/specialcharactersui';
-import SpecialCharactersEditing from '../src/specialcharactersediting';
 
 describe( 'SpecialCharacters', () => {
 	let plugin;
@@ -15,7 +14,7 @@ describe( 'SpecialCharacters', () => {
 	} );
 
 	it( 'should require proper plugins', () => {
-		expect( SpecialCharacters.requires ).to.deep.equal( [ SpecialCharactersEditing, SpecialCharactersUI ] );
+		expect( SpecialCharacters.requires ).to.deep.equal( [ SpecialCharactersUI ] );
 	} );
 
 	it( 'should be named', () => {

+ 0 - 35
packages/ckeditor5-special-characters/tests/specialcharactersediting.js

@@ -1,35 +0,0 @@
-/**
- * @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 SpecialCharactersEditing from '../src/specialcharactersediting';
-import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
-import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
-import InsertSpecialCharacterCommand from '../src/insertspecialcharactercommand';
-
-describe( 'SpecialCharactersEditing', () => {
-	let editor;
-
-	beforeEach( () => {
-		return VirtualTestEditor
-			.create( {
-				plugins: [ SpecialCharactersEditing, Paragraph ]
-			} )
-			.then( newEditor => {
-				editor = newEditor;
-			} );
-	} );
-
-	afterEach( () => {
-		return editor.destroy();
-	} );
-
-	it( 'should have proper pluginName', () => {
-		expect( SpecialCharactersEditing.pluginName ).to.equal( 'SpecialCharactersEditing' );
-	} );
-
-	it( 'adds a command', () => {
-		expect( editor.commands.get( 'insertSpecialCharacter' ) ).to.be.instanceOf( InsertSpecialCharacterCommand );
-	} );
-} );

+ 3 - 3
packages/ckeditor5-special-characters/tests/specialcharactersui.js

@@ -33,7 +33,7 @@ describe( 'SpecialCharactersUI', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-				command = editor.commands.get( 'insertSpecialCharacter' );
+				command = editor.commands.get( 'input' );
 			} );
 	} );
 
@@ -91,8 +91,8 @@ describe( 'SpecialCharactersUI', () => {
 
 			sinon.assert.calledOnce( executeSpy );
 			sinon.assert.calledOnce( focusSpy );
-			sinon.assert.calledWithExactly( executeSpy.firstCall, 'insertSpecialCharacter', {
-				item: 'Less-than or equal to'
+			sinon.assert.calledWithExactly( executeSpy.firstCall, 'input', {
+				text: '≤'
 			} );
 		} );
 

+ 1 - 1
packages/ckeditor5-special-characters/tests/ui/charactergridview.js

@@ -61,7 +61,7 @@ describe( 'CharacterGridView', () => {
 			tile.fire( 'execute' );
 
 			sinon.assert.calledOnce( spy );
-			sinon.assert.calledWithExactly( spy, sinon.match.any, { name: 'foo bar baz' } );
+			sinon.assert.calledWithExactly( spy, sinon.match.any, { name: 'foo bar baz', character: 'ε' } );
 		} );
 	} );
 } );