This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ckeditor/i/1110
Feature: Introduced the special characters plugin. See ckeditor/ckeditor5#1110.
- Loading branch information
Showing
29 changed files
with
2,601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @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 } ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* @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/specialcharacters | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import SpecialCharactersUI from './specialcharactersui'; | ||
import SpecialCharactersEditing from './specialcharactersediting'; | ||
|
||
import '../theme/specialcharacters.css'; | ||
|
||
/** | ||
* The special characters feature. | ||
* | ||
* @extends module:core/plugin~Plugin | ||
*/ | ||
export default class SpecialCharacters extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
constructor( editor ) { | ||
super( editor ); | ||
|
||
/** | ||
* Registered characters. A pair of a character name and its symbol. | ||
* | ||
* @private | ||
* @member {Map.<String, String>} #_characters | ||
*/ | ||
this._characters = new Map(); | ||
|
||
/** | ||
* Registered groups. Each group contains a collection with symbol names. | ||
* | ||
* @private | ||
* @member {Map.<String, Set.<String>>} #_groups | ||
*/ | ||
this._groups = new Map(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
static get requires() { | ||
return [ SpecialCharactersEditing, SpecialCharactersUI ]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
static get pluginName() { | ||
return 'SpecialCharacters'; | ||
} | ||
|
||
/** | ||
* Adds a collection of special characters to specified group. A title of a special character must be unique. | ||
* | ||
* @param {String} groupName | ||
* @param {Array.<module:special-characters/specialcharacters~SpecialCharacterDefinition>} items | ||
*/ | ||
addItems( groupName, items ) { | ||
const group = this._getGroup( groupName ); | ||
|
||
for ( const item of items ) { | ||
group.add( item.title ); | ||
this._characters.set( item.title, item.character ); | ||
} | ||
} | ||
|
||
/** | ||
* Returns iterator of special characters groups. | ||
* | ||
* @returns {Iterable.<String>} | ||
*/ | ||
getGroups() { | ||
return this._groups.keys(); | ||
} | ||
|
||
/** | ||
* Returns a collection of symbol names (titles). | ||
* | ||
* @param {String} groupName | ||
* @returns {Set.<String>|undefined} | ||
*/ | ||
getCharactersForGroup( groupName ) { | ||
return this._groups.get( groupName ); | ||
} | ||
|
||
/** | ||
* Returns a symbol of the special character for specified name. If the special character couldn't be found, `undefined` is returned. | ||
* | ||
* @param {String} title A title of the special character. | ||
* @returns {String|undefined} | ||
*/ | ||
getCharacter( title ) { | ||
return this._characters.get( title ); | ||
} | ||
|
||
/** | ||
* Returns a group of special characters. If the group with the specified name does not exist, it will be created. | ||
* | ||
* @private | ||
* @param {String} groupName A name of group to create. | ||
*/ | ||
_getGroup( groupName ) { | ||
if ( !this._groups.has( groupName ) ) { | ||
this._groups.set( groupName, new Set() ); | ||
} | ||
|
||
return this._groups.get( groupName ); | ||
} | ||
} | ||
|
||
/** | ||
* @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. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
*/ | ||
|
||
/** | ||
* @module special-characters/specialcharacters | ||
*/ | ||
|
||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import SpecialCharacters from './specialcharacters'; | ||
|
||
export default class SpecialCharactersArrows extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
static get requires() { | ||
return [ | ||
SpecialCharacters | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
init() { | ||
this.editor.plugins.get( 'SpecialCharacters' ).addItems( 'Arrows', [ | ||
{ title: 'leftwards double arrow', character: '⇐' }, | ||
{ title: 'rightwards double arrow', character: '⇒' }, | ||
{ title: 'upwards double arrow', character: '⇑' }, | ||
{ title: 'downwards double arrow', character: '⇓' }, | ||
{ title: 'leftwards dashed arrow', character: '⇠' }, | ||
{ title: 'rightwards dashed arrow', character: '⇢' }, | ||
{ title: 'upwards dashed arrow', character: '⇡' }, | ||
{ title: 'downwards dashed arrow', character: '⇣' }, | ||
{ title: 'leftwards arrow to bar', character: '⇤' }, | ||
{ title: 'rightwards arrow to bar', character: '⇥' }, | ||
{ title: 'upwards arrow to bar', character: '⤒' }, | ||
{ title: 'downwards arrow to bar', character: '⤓' }, | ||
{ title: 'up down arrow with base', character: '↨' }, | ||
{ title: 'back with leftwards arrow above', character: '🔙' }, | ||
{ title: 'end with leftwards arrow above', character: '🔚' }, | ||
{ title: 'on with exclamation mark with left right arrow above', character: '🔛' }, | ||
{ title: 'soon with rightwards arrow above', character: '🔜' }, | ||
{ title: 'top with upwards arrow above', character: '🔝' } | ||
] ); | ||
} | ||
} |
Oops, something went wrong.