@ckeditor/ckeditor5-special-characters 36.0.1 → 37.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,68 +2,64 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module special-characters/specialcharacterstext
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  /**
13
10
  * A plugin that provides special characters for the "Text" category.
14
11
  *
15
- * ClassicEditor
16
- * .create( {
17
- * plugins: [ ..., SpecialCharacters, SpecialCharactersText ],
18
- * } )
19
- * .then( ... )
20
- * .catch( ... );
21
- *
22
- * @extends module:core/plugin~Plugin
12
+ * ```ts
13
+ * ClassicEditor
14
+ * .create( {
15
+ * plugins: [ ..., SpecialCharacters, SpecialCharactersText ],
16
+ * } )
17
+ * .then( ... )
18
+ * .catch( ... );
19
+ * ```
23
20
  */
24
21
  export default class SpecialCharactersText extends Plugin {
25
- /**
26
- * @inheritDoc
27
- */
28
- static get pluginName() {
29
- return 'SpecialCharactersText';
30
- }
31
-
32
- /**
33
- * @inheritDoc
34
- */
35
- init() {
36
- const editor = this.editor;
37
- const t = editor.t;
38
-
39
- editor.plugins.get( 'SpecialCharacters' ).addItems( 'Text', [
40
- { character: '', title: t( 'Single left-pointing angle quotation mark' ) },
41
- { character: '', title: t( 'Single right-pointing angle quotation mark' ) },
42
- { character: '«', title: t( 'Left-pointing double angle quotation mark' ) },
43
- { character: '»', title: t( 'Right-pointing double angle quotation mark' ) },
44
- { character: '', title: t( 'Left single quotation mark' ) },
45
- { character: '', title: t( 'Right single quotation mark' ) },
46
- { character: '', title: t( 'Left double quotation mark' ) },
47
- { character: '', title: t( 'Right double quotation mark' ) },
48
- { character: '', title: t( 'Single low-9 quotation mark' ) },
49
- { character: '', title: t( 'Double low-9 quotation mark' ) },
50
- { character: '¡', title: t( 'Inverted exclamation mark' ) },
51
- { character: '¿', title: t( 'Inverted question mark' ) },
52
- { character: '', title: t( 'Two dot leader' ) },
53
- { character: '', title: t( 'Horizontal ellipsis' ) },
54
- { character: '', title: t( 'Double dagger' ) },
55
- { character: '', title: t( 'Per mille sign' ) },
56
- { character: '', title: t( 'Per ten thousand sign' ) },
57
- { character: '', title: t( 'Double exclamation mark' ) },
58
- { character: '', title: t( 'Question exclamation mark' ) },
59
- { character: '', title: t( 'Exclamation question mark' ) },
60
- { character: '', title: t( 'Double question mark' ) },
61
- { character: '©', title: t( 'Copyright sign' ) },
62
- { character: '®', title: t( 'Registered sign' ) },
63
- { character: '', title: t( 'Trade mark sign' ) },
64
- { character: '§', title: t( 'Section sign' ) },
65
- { character: '', title: t( 'Paragraph sign' ) },
66
- { character: '⁋', title: t( 'Reversed paragraph sign' ) }
67
- ], { label: t( 'Text' ) } );
68
- }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName() {
26
+ return 'SpecialCharactersText';
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ init() {
32
+ const editor = this.editor;
33
+ const t = editor.t;
34
+ const plugin = editor.plugins.get('SpecialCharacters');
35
+ plugin.addItems('Text', [
36
+ { character: '', title: t('Single left-pointing angle quotation mark') },
37
+ { character: '', title: t('Single right-pointing angle quotation mark') },
38
+ { character: '«', title: t('Left-pointing double angle quotation mark') },
39
+ { character: '»', title: t('Right-pointing double angle quotation mark') },
40
+ { character: '', title: t('Left single quotation mark') },
41
+ { character: '', title: t('Right single quotation mark') },
42
+ { character: '', title: t('Left double quotation mark') },
43
+ { character: '', title: t('Right double quotation mark') },
44
+ { character: '', title: t('Single low-9 quotation mark') },
45
+ { character: '', title: t('Double low-9 quotation mark') },
46
+ { character: '¡', title: t('Inverted exclamation mark') },
47
+ { character: '¿', title: t('Inverted question mark') },
48
+ { character: '', title: t('Two dot leader') },
49
+ { character: '', title: t('Horizontal ellipsis') },
50
+ { character: '', title: t('Double dagger') },
51
+ { character: '', title: t('Per mille sign') },
52
+ { character: '', title: t('Per ten thousand sign') },
53
+ { character: '', title: t('Double exclamation mark') },
54
+ { character: '', title: t('Question exclamation mark') },
55
+ { character: '', title: t('Exclamation question mark') },
56
+ { character: '', title: t('Double question mark') },
57
+ { character: '©', title: t('Copyright sign') },
58
+ { character: '®', title: t('Registered sign') },
59
+ { character: '', title: t('Trade mark sign') },
60
+ { character: '§', title: t('Section sign') },
61
+ { character: '', title: t('Paragraph sign') },
62
+ { character: '', title: t('Reversed paragraph sign') }
63
+ ], { label: t('Text') });
64
+ }
69
65
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module special-characters/ui/charactergridview
7
+ */
8
+ import { View, ButtonView, type ViewCollection } from 'ckeditor5/src/ui';
9
+ import { KeystrokeHandler, FocusTracker, type Locale } from 'ckeditor5/src/utils';
10
+ import '../../theme/charactergrid.css';
11
+ /**
12
+ * A grid of character tiles. It allows browsing special characters and selecting the character to
13
+ * be inserted into the content.
14
+ */
15
+ export default class CharacterGridView extends View<HTMLDivElement> {
16
+ /**
17
+ * A collection of the child tile views. Each tile represents a particular character.
18
+ */
19
+ readonly tiles: ViewCollection<ButtonView>;
20
+ /**
21
+ * Tracks information about the DOM focus in the grid.
22
+ */
23
+ readonly focusTracker: FocusTracker;
24
+ /**
25
+ * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
26
+ */
27
+ readonly keystrokes: KeystrokeHandler;
28
+ /**
29
+ * Creates an instance of a character grid containing tiles representing special characters.
30
+ *
31
+ * @param locale The localization services instance.
32
+ */
33
+ constructor(locale: Locale);
34
+ /**
35
+ * Creates a new tile for the grid.
36
+ *
37
+ * @param character A human-readable character displayed as the label (e.g. "ε").
38
+ * @param name The name of the character (e.g. "greek small letter epsilon").
39
+ */
40
+ createTile(character: string, name: string): ButtonView;
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ render(): void;
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ destroy(): void;
49
+ /**
50
+ * Focuses the first focusable in {@link #tiles}.
51
+ */
52
+ focus(): void;
53
+ }
@@ -2,201 +2,153 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module special-characters/ui/charactergridview
8
7
  */
9
-
10
8
  import { View, ButtonView, addKeyboardHandlingForGrid } from 'ckeditor5/src/ui';
11
-
12
9
  import { KeystrokeHandler, FocusTracker, global } from 'ckeditor5/src/utils';
13
-
14
10
  import '../../theme/charactergrid.css';
15
-
16
11
  /**
17
12
  * A grid of character tiles. It allows browsing special characters and selecting the character to
18
13
  * be inserted into the content.
19
- *
20
- * @extends module:ui/view~View
21
14
  */
22
15
  export default class CharacterGridView extends View {
23
- /**
24
- * Creates an instance of a character grid containing tiles representing special characters.
25
- *
26
- * @param {module:utils/locale~Locale} locale The localization services instance.
27
- */
28
- constructor( locale ) {
29
- super( locale );
30
-
31
- /**
32
- * A collection of the child tile views. Each tile represents a particular character.
33
- *
34
- * @readonly
35
- * @member {module:ui/viewcollection~ViewCollection}
36
- */
37
- this.tiles = this.createCollection();
38
-
39
- this.setTemplate( {
40
- tag: 'div',
41
- children: [
42
- {
43
- tag: 'div',
44
- attributes: {
45
- class: [
46
- 'ck',
47
- 'ck-character-grid__tiles'
48
- ]
49
- },
50
- children: this.tiles
51
- }
52
- ],
53
- attributes: {
54
- class: [
55
- 'ck',
56
- 'ck-character-grid'
57
- ]
58
- }
59
- } );
60
-
61
- /**
62
- * Tracks information about the DOM focus in the grid.
63
- *
64
- * @readonly
65
- * @member {module:utils/focustracker~FocusTracker}
66
- */
67
- this.focusTracker = new FocusTracker();
68
-
69
- /**
70
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
71
- *
72
- * @readonly
73
- * @member {module:utils/keystrokehandler~KeystrokeHandler}
74
- */
75
- this.keystrokes = new KeystrokeHandler();
76
-
77
- addKeyboardHandlingForGrid( {
78
- keystrokeHandler: this.keystrokes,
79
- focusTracker: this.focusTracker,
80
- gridItems: this.tiles,
81
- numberOfColumns: () => global.window
82
- .getComputedStyle( this.element.firstChild ) // Responsive .ck-character-grid__tiles
83
- .getPropertyValue( 'grid-template-columns' )
84
- .split( ' ' )
85
- .length,
86
- uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
87
- } );
88
-
89
- /**
90
- * Fired when any of {@link #tiles grid tiles} is clicked.
91
- *
92
- * @event execute
93
- * @param {Object} data Additional information about the event.
94
- * @param {String} data.name The name of the tile that caused the event (e.g. "greek small letter epsilon").
95
- * @param {String} data.character A human-readable character displayed as the label (e.g. "ε").
96
- */
97
-
98
- /**
99
- * Fired when a mouse or another pointing device caused the cursor to move onto any {@link #tiles grid tile}
100
- * (similar to the native `mouseover` DOM event).
101
- *
102
- * @event tileHover
103
- * @param {Object} data Additional information about the event.
104
- * @param {String} data.name The name of the tile that caused the event (e.g. "greek small letter epsilon").
105
- * @param {String} data.character A human-readable character displayed as the label (e.g. "ε").
106
- */
107
-
108
- /**
109
- * Fired when {@link #tiles grid tile} is focused (e.g. by navigating with arrow keys).
110
- *
111
- * @event tileFocus
112
- * @param {Object} data Additional information about the event.
113
- * @param {String} data.name The name of the tile that caused the event (e.g. "greek small letter epsilon").
114
- * @param {String} data.character A human-readable character displayed as the label (e.g. "ε").
115
- */
116
- }
117
-
118
- /**
119
- * Creates a new tile for the grid.
120
- *
121
- * @param {String} character A human-readable character displayed as the label (e.g. "ε").
122
- * @param {String} name The name of the character (e.g. "greek small letter epsilon").
123
- * @returns {module:ui/button/buttonview~ButtonView}
124
- */
125
- createTile( character, name ) {
126
- const tile = new ButtonView( this.locale );
127
-
128
- tile.set( {
129
- label: character,
130
- withText: true,
131
- class: 'ck-character-grid__tile'
132
- } );
133
-
134
- // Labels are vital for the users to understand what character they're looking at.
135
- // For now we're using native title attribute for that, see #5817.
136
- tile.extendTemplate( {
137
- attributes: {
138
- title: name
139
- },
140
- on: {
141
- mouseover: tile.bindTemplate.to( 'mouseover' ),
142
- focus: tile.bindTemplate.to( 'focus' )
143
- }
144
- } );
145
-
146
- tile.on( 'mouseover', () => {
147
- this.fire( 'tileHover', { name, character } );
148
- } );
149
-
150
- tile.on( 'focus', () => {
151
- this.fire( 'tileFocus', { name, character } );
152
- } );
153
-
154
- tile.on( 'execute', () => {
155
- this.fire( 'execute', { name, character } );
156
- } );
157
-
158
- return tile;
159
- }
160
-
161
- /**
162
- * @inheritDoc
163
- */
164
- render() {
165
- super.render();
166
-
167
- for ( const item of this.tiles ) {
168
- this.focusTracker.add( item.element );
169
- }
170
-
171
- this.tiles.on( 'change', ( eventInfo, { added, removed } ) => {
172
- if ( added.length > 0 ) {
173
- for ( const item of added ) {
174
- this.focusTracker.add( item.element );
175
- }
176
- }
177
- if ( removed.length > 0 ) {
178
- for ( const item of removed ) {
179
- this.focusTracker.remove( item.element );
180
- }
181
- }
182
- } );
183
-
184
- this.keystrokes.listenTo( this.element );
185
- }
186
-
187
- /**
188
- * @inheritDoc
189
- */
190
- destroy() {
191
- super.destroy();
192
-
193
- this.keystrokes.destroy();
194
- }
195
-
196
- /**
197
- * Focuses the first focusable in {@link #tiles}.
198
- */
199
- focus() {
200
- this.tiles.get( 0 ).focus();
201
- }
16
+ /**
17
+ * Creates an instance of a character grid containing tiles representing special characters.
18
+ *
19
+ * @param locale The localization services instance.
20
+ */
21
+ constructor(locale) {
22
+ super(locale);
23
+ this.tiles = this.createCollection();
24
+ this.setTemplate({
25
+ tag: 'div',
26
+ children: [
27
+ {
28
+ tag: 'div',
29
+ attributes: {
30
+ class: [
31
+ 'ck',
32
+ 'ck-character-grid__tiles'
33
+ ]
34
+ },
35
+ children: this.tiles
36
+ }
37
+ ],
38
+ attributes: {
39
+ class: [
40
+ 'ck',
41
+ 'ck-character-grid'
42
+ ]
43
+ }
44
+ });
45
+ this.focusTracker = new FocusTracker();
46
+ this.keystrokes = new KeystrokeHandler();
47
+ addKeyboardHandlingForGrid({
48
+ keystrokeHandler: this.keystrokes,
49
+ focusTracker: this.focusTracker,
50
+ gridItems: this.tiles,
51
+ numberOfColumns: () => global.window
52
+ .getComputedStyle(this.element.firstChild) // Responsive .ck-character-grid__tiles
53
+ .getPropertyValue('grid-template-columns')
54
+ .split(' ')
55
+ .length,
56
+ uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
57
+ });
58
+ /**
59
+ * Fired when any of {@link #tiles grid tiles} is clicked.
60
+ *
61
+ * @event execute
62
+ * @param {Object} data Additional information about the event.
63
+ * @param {String} data.name The name of the tile that caused the event (e.g. "greek small letter epsilon").
64
+ * @param {String} data.character A human-readable character displayed as the label (e.g. "ε").
65
+ */
66
+ /**
67
+ * Fired when a mouse or another pointing device caused the cursor to move onto any {@link #tiles grid tile}
68
+ * (similar to the native `mouseover` DOM event).
69
+ *
70
+ * @event tileHover
71
+ * @param {Object} data Additional information about the event.
72
+ * @param {String} data.name The name of the tile that caused the event (e.g. "greek small letter epsilon").
73
+ * @param {String} data.character A human-readable character displayed as the label (e.g. "ε").
74
+ */
75
+ /**
76
+ * Fired when {@link #tiles grid tile} is focused (e.g. by navigating with arrow keys).
77
+ *
78
+ * @event tileFocus
79
+ * @param {Object} data Additional information about the event.
80
+ * @param {String} data.name The name of the tile that caused the event (e.g. "greek small letter epsilon").
81
+ * @param {String} data.character A human-readable character displayed as the label (e.g. "ε").
82
+ */
83
+ }
84
+ /**
85
+ * Creates a new tile for the grid.
86
+ *
87
+ * @param character A human-readable character displayed as the label (e.g. "ε").
88
+ * @param name The name of the character (e.g. "greek small letter epsilon").
89
+ */
90
+ createTile(character, name) {
91
+ const tile = new ButtonView(this.locale);
92
+ tile.set({
93
+ label: character,
94
+ withText: true,
95
+ class: 'ck-character-grid__tile'
96
+ });
97
+ // Labels are vital for the users to understand what character they're looking at.
98
+ // For now we're using native title attribute for that, see #5817.
99
+ tile.extendTemplate({
100
+ attributes: {
101
+ title: name
102
+ },
103
+ on: {
104
+ mouseover: tile.bindTemplate.to('mouseover'),
105
+ focus: tile.bindTemplate.to('focus')
106
+ }
107
+ });
108
+ tile.on('mouseover', () => {
109
+ this.fire('tileHover', { name, character });
110
+ });
111
+ tile.on('focus', () => {
112
+ this.fire('tileFocus', { name, character });
113
+ });
114
+ tile.on('execute', () => {
115
+ this.fire('execute', { name, character });
116
+ });
117
+ return tile;
118
+ }
119
+ /**
120
+ * @inheritDoc
121
+ */
122
+ render() {
123
+ super.render();
124
+ for (const item of this.tiles) {
125
+ this.focusTracker.add(item.element);
126
+ }
127
+ this.tiles.on('change', (eventInfo, { added, removed }) => {
128
+ if (added.length > 0) {
129
+ for (const item of added) {
130
+ this.focusTracker.add(item.element);
131
+ }
132
+ }
133
+ if (removed.length > 0) {
134
+ for (const item of removed) {
135
+ this.focusTracker.remove(item.element);
136
+ }
137
+ }
138
+ });
139
+ this.keystrokes.listenTo(this.element);
140
+ }
141
+ /**
142
+ * @inheritDoc
143
+ */
144
+ destroy() {
145
+ super.destroy();
146
+ this.keystrokes.destroy();
147
+ }
148
+ /**
149
+ * Focuses the first focusable in {@link #tiles}.
150
+ */
151
+ focus() {
152
+ this.tiles.first.focus();
153
+ }
202
154
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module special-characters/ui/characterinfoview
7
+ */
8
+ import type { Locale } from 'ckeditor5/src/utils';
9
+ import { View } from 'ckeditor5/src/ui';
10
+ import '../../theme/characterinfo.css';
11
+ /**
12
+ * The view displaying detailed information about a special character glyph, e.g. upon
13
+ * hovering it with a mouse.
14
+ */
15
+ export default class CharacterInfoView extends View<HTMLDivElement> {
16
+ /**
17
+ * The character whose information is displayed by the view. For instance, "∑" or "¿".
18
+ *
19
+ * @observable
20
+ */
21
+ character: string | null;
22
+ /**
23
+ * The name of the {@link #character}. For instance, "N-ary summation" or "Inverted question mark".
24
+ *
25
+ * @observable
26
+ */
27
+ name: string | null;
28
+ /**
29
+ * The "Unicode string" of the {@link #character}. For instance "U+0061".
30
+ *
31
+ * @observable
32
+ */
33
+ readonly code: string;
34
+ constructor(locale: Locale);
35
+ }