@ckeditor/ckeditor5-emoji 0.0.0-nightly-next-20250217.0 → 0.0.1

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.
Files changed (43) hide show
  1. package/LICENSE.md +5 -15
  2. package/README.md +3 -30
  3. package/package.json +5 -59
  4. package/CHANGELOG.md +0 -4
  5. package/build/emoji.js +0 -4
  6. package/ckeditor5-metadata.json +0 -32
  7. package/dist/index-content.css +0 -4
  8. package/dist/index-editor.css +0 -111
  9. package/dist/index.css +0 -143
  10. package/dist/index.css.map +0 -1
  11. package/dist/index.js +0 -1478
  12. package/dist/index.js.map +0 -1
  13. package/lang/contexts.json +0 -24
  14. package/src/augmentation.d.ts +0 -24
  15. package/src/augmentation.js +0 -5
  16. package/src/emoji.d.ts +0 -32
  17. package/src/emoji.js +0 -38
  18. package/src/emojicommand.d.ts +0 -24
  19. package/src/emojicommand.js +0 -33
  20. package/src/emojiconfig.d.ts +0 -80
  21. package/src/emojiconfig.js +0 -5
  22. package/src/emojimention.d.ts +0 -68
  23. package/src/emojimention.js +0 -203
  24. package/src/emojipicker.d.ts +0 -97
  25. package/src/emojipicker.js +0 -256
  26. package/src/emojirepository.d.ts +0 -139
  27. package/src/emojirepository.js +0 -280
  28. package/src/index.d.ts +0 -14
  29. package/src/index.js +0 -13
  30. package/src/ui/emojicategoriesview.d.ts +0 -68
  31. package/src/ui/emojicategoriesview.js +0 -147
  32. package/src/ui/emojigridview.d.ts +0 -140
  33. package/src/ui/emojigridview.js +0 -209
  34. package/src/ui/emojipickerview.d.ts +0 -91
  35. package/src/ui/emojipickerview.js +0 -208
  36. package/src/ui/emojisearchview.d.ts +0 -51
  37. package/src/ui/emojisearchview.js +0 -97
  38. package/src/ui/emojitoneview.d.ts +0 -46
  39. package/src/ui/emojitoneview.js +0 -97
  40. package/theme/emojicategories.css +0 -29
  41. package/theme/emojigrid.css +0 -55
  42. package/theme/emojipicker.css +0 -32
  43. package/theme/emojitone.css +0 -21
package/dist/index.js DELETED
@@ -1,1478 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { Plugin, Command } from '@ckeditor/ckeditor5-core/dist/index.js';
6
- import { logWarning, FocusTracker, KeystrokeHandler, global, Collection } from '@ckeditor/ckeditor5-utils/dist/index.js';
7
- import { Typing } from '@ckeditor/ckeditor5-typing/dist/index.js';
8
- import Fuse from 'fuse.js';
9
- import { groupBy, escapeRegExp } from 'es-toolkit/compat';
10
- import { View, addKeyboardHandlingForGrid, ButtonView, FocusCycler, SearchTextView, createLabeledInputText, createDropdown, ViewModel, addListToDropdown, SearchInfoView, ContextualBalloon, Dialog, MenuBarMenuListItemButtonView, clickOutsideHandler } from '@ckeditor/ckeditor5-ui/dist/index.js';
11
- import { IconEmoji } from '@ckeditor/ckeditor5-icons/dist/index.js';
12
-
13
- // An endpoint from which the emoji database will be downloaded during plugin initialization.
14
- // The `{version}` placeholder is replaced with the value from editor config.
15
- const EMOJI_DATABASE_URL = 'https://cdn.ckeditor.com/ckeditor5/data/emoji/{version}/en.json';
16
- const SKIN_TONE_MAP = {
17
- 0: 'default',
18
- 1: 'light',
19
- 2: 'medium-light',
20
- 3: 'medium',
21
- 4: 'medium-dark',
22
- 5: 'dark'
23
- };
24
- const BASELINE_EMOJI_WIDTH = 24;
25
- /**
26
- * The emoji repository plugin.
27
- *
28
- * Loads the emoji database from URL during plugin initialization and provides utility methods to search it.
29
- */ class EmojiRepository extends Plugin {
30
- /**
31
- * Emoji database.
32
- */ _database;
33
- /**
34
- * A promise resolved after downloading the emoji database.
35
- * The promise resolves with `true` when the database is successfully downloaded or `false` otherwise.
36
- */ _databasePromise;
37
- /**
38
- * An instance of the [Fuse.js](https://www.fusejs.io/) library.
39
- */ _fuseSearch;
40
- /**
41
- * @inheritDoc
42
- */ static get pluginName() {
43
- return 'EmojiRepository';
44
- }
45
- /**
46
- * @inheritDoc
47
- */ static get isOfficialPlugin() {
48
- return true;
49
- }
50
- /**
51
- * @inheritDoc
52
- */ constructor(editor){
53
- super(editor);
54
- this.editor.config.define('emoji', {
55
- version: 16,
56
- skinTone: 'default'
57
- });
58
- this._database = [];
59
- this._databasePromise = new Promise((resolve)=>{
60
- this._databasePromiseResolveCallback = resolve;
61
- });
62
- this._fuseSearch = null;
63
- }
64
- /**
65
- * @inheritDoc
66
- */ async init() {
67
- const emojiVersion = this.editor.config.get('emoji.version');
68
- const emojiDatabaseUrl = EMOJI_DATABASE_URL.replace('{version}', `${emojiVersion}`);
69
- const emojiDatabase = await loadEmojiDatabase(emojiDatabaseUrl);
70
- // Skip the initialization if the emoji database download has failed.
71
- // An empty database prevents the initialization of other dependent plugins, such as `EmojiMention` and `EmojiPicker`.
72
- if (!emojiDatabase.length) {
73
- return this._databasePromiseResolveCallback(false);
74
- }
75
- const container = createEmojiWidthTestingContainer();
76
- // Store the emoji database after normalizing the raw data.
77
- this._database = emojiDatabase.filter((item)=>isEmojiCategoryAllowed(item)).filter((item)=>EmojiRepository._isEmojiSupported(item, container)).map((item)=>normalizeEmojiSkinTone(item));
78
- container.remove();
79
- // Create instance of the Fuse.js library with configured weighted search keys and disabled fuzzy search.
80
- this._fuseSearch = new Fuse(this._database, {
81
- keys: [
82
- {
83
- name: 'emoticon',
84
- weight: 5
85
- },
86
- {
87
- name: 'annotation',
88
- weight: 3
89
- },
90
- {
91
- name: 'tags',
92
- weight: 1
93
- }
94
- ],
95
- minMatchCharLength: 2,
96
- threshold: 0,
97
- ignoreLocation: true
98
- });
99
- return this._databasePromiseResolveCallback(true);
100
- }
101
- /**
102
- * Returns an array of emoji entries that match the search query.
103
- * If the emoji database is not loaded, the [Fuse.js](https://www.fusejs.io/) instance is not created,
104
- * hence this method returns an empty array.
105
- *
106
- * @param searchQuery A search query to match emoji.
107
- * @returns An array of emoji entries that match the search query.
108
- */ getEmojiByQuery(searchQuery) {
109
- if (!this._fuseSearch) {
110
- return [];
111
- }
112
- const searchQueryTokens = searchQuery.split(/\s/).filter(Boolean);
113
- // Perform the search only if there is at least two non-white characters next to each other.
114
- const shouldSearch = searchQueryTokens.some((token)=>token.length >= 2);
115
- if (!shouldSearch) {
116
- return [];
117
- }
118
- return this._fuseSearch.search({
119
- '$or': [
120
- {
121
- emoticon: searchQuery
122
- },
123
- {
124
- '$and': searchQueryTokens.map((token)=>({
125
- annotation: token
126
- }))
127
- },
128
- {
129
- '$and': searchQueryTokens.map((token)=>({
130
- tags: token
131
- }))
132
- }
133
- ]
134
- }).map((result)=>result.item);
135
- }
136
- /**
137
- * Groups all emojis by categories.
138
- * If the emoji database is not loaded, it returns an empty array.
139
- *
140
- * @returns An array of emoji entries grouped by categories.
141
- */ getEmojiCategories() {
142
- if (!this._database.length) {
143
- return [];
144
- }
145
- const { t } = this.editor.locale;
146
- const categories = [
147
- {
148
- title: t('Smileys & Expressions'),
149
- icon: '😀',
150
- groupId: 0
151
- },
152
- {
153
- title: t('Gestures & People'),
154
- icon: '👋',
155
- groupId: 1
156
- },
157
- {
158
- title: t('Animals & Nature'),
159
- icon: '🐻',
160
- groupId: 3
161
- },
162
- {
163
- title: t('Food & Drinks'),
164
- icon: '🍎',
165
- groupId: 4
166
- },
167
- {
168
- title: t('Travel & Places'),
169
- icon: '🚘',
170
- groupId: 5
171
- },
172
- {
173
- title: t('Activities'),
174
- icon: '🏀',
175
- groupId: 6
176
- },
177
- {
178
- title: t('Objects'),
179
- icon: '💡',
180
- groupId: 7
181
- },
182
- {
183
- title: t('Symbols'),
184
- icon: '🟢',
185
- groupId: 8
186
- },
187
- {
188
- title: t('Flags'),
189
- icon: '🏁',
190
- groupId: 9
191
- }
192
- ];
193
- const groups = groupBy(this._database, (item)=>item.group);
194
- return categories.map((category)=>{
195
- return {
196
- ...category,
197
- items: groups[category.groupId]
198
- };
199
- });
200
- }
201
- /**
202
- * Returns an array of available skin tones.
203
- */ getSkinTones() {
204
- const { t } = this.editor.locale;
205
- return [
206
- {
207
- id: 'default',
208
- icon: '👋',
209
- tooltip: t('Default skin tone')
210
- },
211
- {
212
- id: 'light',
213
- icon: '👋🏻',
214
- tooltip: t('Light skin tone')
215
- },
216
- {
217
- id: 'medium-light',
218
- icon: '👋🏼',
219
- tooltip: t('Medium Light skin tone')
220
- },
221
- {
222
- id: 'medium',
223
- icon: '👋🏽',
224
- tooltip: t('Medium skin tone')
225
- },
226
- {
227
- id: 'medium-dark',
228
- icon: '👋🏾',
229
- tooltip: t('Medium Dark skin tone')
230
- },
231
- {
232
- id: 'dark',
233
- icon: '👋🏿',
234
- tooltip: t('Dark skin tone')
235
- }
236
- ];
237
- }
238
- /**
239
- * Indicates whether the emoji database has been successfully downloaded and the plugin is operational.
240
- */ isReady() {
241
- return this._databasePromise;
242
- }
243
- /**
244
- * A function used to check if the given emoji is supported in the operating system.
245
- *
246
- * Referenced for unit testing purposes.
247
- */ static _isEmojiSupported = isEmojiSupported;
248
- }
249
- /**
250
- * Makes the HTTP request to download the emoji database.
251
- */ async function loadEmojiDatabase(emojiDatabaseUrl) {
252
- const result = await fetch(emojiDatabaseUrl).then((response)=>{
253
- if (!response.ok) {
254
- return [];
255
- }
256
- return response.json();
257
- }).catch(()=>{
258
- return [];
259
- });
260
- if (!result.length) {
261
- /**
262
- * Unable to load the emoji database from CDN.
263
- *
264
- * TODO: It could be a problem of CKEditor 5 CDN, but also, Content Security Policy that disallow the request.
265
- * It would be good to explain what to do in such a case.
266
- *
267
- * @error emoji-database-load-failed
268
- */ logWarning('emoji-database-load-failed');
269
- }
270
- return result;
271
- }
272
- /**
273
- * Creates a div for emoji width testing purposes.
274
- */ function createEmojiWidthTestingContainer() {
275
- const container = document.createElement('div');
276
- container.setAttribute('aria-hidden', 'true');
277
- container.style.position = 'absolute';
278
- container.style.left = '-9999px';
279
- container.style.whiteSpace = 'nowrap';
280
- container.style.fontSize = BASELINE_EMOJI_WIDTH + 'px';
281
- document.body.appendChild(container);
282
- return container;
283
- }
284
- /**
285
- * Returns the width of the provided node.
286
- */ function getNodeWidth(container, node) {
287
- const span = document.createElement('span');
288
- span.textContent = node;
289
- container.appendChild(span);
290
- const nodeWidth = span.offsetWidth;
291
- container.removeChild(span);
292
- return nodeWidth;
293
- }
294
- /**
295
- * Checks whether the emoji is supported in the operating system.
296
- */ function isEmojiSupported(item, container) {
297
- const emojiWidth = getNodeWidth(container, item.emoji);
298
- // On Windows, some supported emoji are ~50% bigger than the baseline emoji, but what we really want to guard
299
- // against are the ones that are 2x the size, because those are truly broken (person with red hair = person with
300
- // floating red wig, black cat = cat with black square, polar bear = bear with snowflake, etc.)
301
- // So here we set the threshold at 1.8 times the size of the baseline emoji.
302
- return emojiWidth / 1.8 < BASELINE_EMOJI_WIDTH && emojiWidth >= BASELINE_EMOJI_WIDTH;
303
- }
304
- /**
305
- * Adds default skin tone property to each emoji. If emoji defines other skin tones, they are added as well.
306
- */ function normalizeEmojiSkinTone(item) {
307
- const entry = {
308
- ...item,
309
- skins: {
310
- default: item.emoji
311
- }
312
- };
313
- if (item.skins) {
314
- item.skins.forEach((skin)=>{
315
- const skinTone = SKIN_TONE_MAP[skin.tone];
316
- entry.skins[skinTone] = skin.emoji;
317
- });
318
- }
319
- return entry;
320
- }
321
- /**
322
- * Checks whether the emoji belongs to a group that is allowed.
323
- */ function isEmojiCategoryAllowed(item) {
324
- // Category group=2 contains skin tones only, which we do not want to render.
325
- return item.group !== 2;
326
- }
327
-
328
- const EMOJI_MENTION_MARKER = ':';
329
- const EMOJI_SHOW_ALL_OPTION_ID = ':__EMOJI_SHOW_ALL:';
330
- const EMOJI_HINT_OPTION_ID = ':__EMOJI_HINT:';
331
- /**
332
- * The emoji mention plugin.
333
- *
334
- * Introduces the autocomplete of emojis while typing.
335
- */ class EmojiMention extends Plugin {
336
- /**
337
- * Defines a number of displayed items in the auto complete dropdown.
338
- *
339
- * It includes the "Show all emoji..." option if the `EmojiPicker` plugin is loaded.
340
- */ _emojiDropdownLimit;
341
- /**
342
- * Defines a skin tone that is set in the emoji config.
343
- */ _skinTone;
344
- /**
345
- * @inheritDoc
346
- */ static get requires() {
347
- return [
348
- EmojiRepository,
349
- Typing,
350
- 'Mention'
351
- ];
352
- }
353
- /**
354
- * @inheritDoc
355
- */ static get pluginName() {
356
- return 'EmojiMention';
357
- }
358
- /**
359
- * @inheritDoc
360
- */ static get isOfficialPlugin() {
361
- return true;
362
- }
363
- /**
364
- * @inheritDoc
365
- */ constructor(editor){
366
- super(editor);
367
- this.editor.config.define('emoji', {
368
- dropdownLimit: 6
369
- });
370
- this._emojiDropdownLimit = editor.config.get('emoji.dropdownLimit');
371
- this._skinTone = editor.config.get('emoji.skinTone');
372
- const mentionFeedsConfigs = editor.config.get('mention.feeds');
373
- const mergeFieldsPrefix = editor.config.get('mergeFields.prefix');
374
- const markerAlreadyUsed = mentionFeedsConfigs.some((config)=>config.marker === EMOJI_MENTION_MARKER);
375
- const isMarkerUsedByMergeFields = mergeFieldsPrefix ? mergeFieldsPrefix[0] === EMOJI_MENTION_MARKER : false;
376
- if (markerAlreadyUsed || isMarkerUsedByMergeFields) {
377
- /**
378
- * The `marker` in the `emoji` config is already used by other plugin configuration.
379
- *
380
- * @error emoji-config-marker-already-used
381
- * @param {string} marker Used marker.
382
- */ logWarning('emoji-config-marker-already-used', {
383
- marker: EMOJI_MENTION_MARKER
384
- });
385
- return;
386
- }
387
- this._setupMentionConfiguration(mentionFeedsConfigs);
388
- }
389
- /**
390
- * @inheritDoc
391
- */ async init() {
392
- const editor = this.editor;
393
- this._emojiPickerPlugin = editor.plugins.has('EmojiPicker') ? editor.plugins.get('EmojiPicker') : null;
394
- this._emojiRepositoryPlugin = editor.plugins.get('EmojiRepository');
395
- // Skip overriding the `mention` command listener if the emoji repository is not ready.
396
- if (!await this._emojiRepositoryPlugin.isReady()) {
397
- return;
398
- }
399
- editor.once('ready', this._overrideMentionExecuteListener.bind(this));
400
- }
401
- /**
402
- * Initializes the configuration for emojis in the mention feature.
403
- */ _setupMentionConfiguration(mentionFeedsConfigs) {
404
- const emojiMentionFeedConfig = {
405
- marker: EMOJI_MENTION_MARKER,
406
- dropdownLimit: this._emojiDropdownLimit,
407
- itemRenderer: this._customItemRendererFactory(this.editor.t),
408
- feed: this._queryEmojiCallbackFactory()
409
- };
410
- this.editor.config.set('mention.feeds', [
411
- ...mentionFeedsConfigs,
412
- emojiMentionFeedConfig
413
- ]);
414
- }
415
- /**
416
- * Returns the `itemRenderer()` callback for mention config.
417
- */ _customItemRendererFactory(t) {
418
- return (item)=>{
419
- const itemElement = document.createElement('button');
420
- itemElement.classList.add('ck');
421
- itemElement.classList.add('ck-button');
422
- itemElement.classList.add('ck-button_with-text');
423
- itemElement.id = `mention-list-item-id${item.id.slice(0, -1)}`;
424
- itemElement.type = 'button';
425
- itemElement.tabIndex = -1;
426
- const labelElement = document.createElement('span');
427
- labelElement.classList.add('ck');
428
- labelElement.classList.add('ck-button__label');
429
- itemElement.appendChild(labelElement);
430
- if (item.id === EMOJI_HINT_OPTION_ID) {
431
- itemElement.classList.add('ck-list-item-button');
432
- itemElement.classList.add('ck-disabled');
433
- labelElement.textContent = t('Keep on typing to see the emoji.');
434
- } else if (item.id === EMOJI_SHOW_ALL_OPTION_ID) {
435
- labelElement.textContent = t('Show all emoji...');
436
- } else {
437
- labelElement.textContent = `${item.text} ${item.id}`;
438
- }
439
- return itemElement;
440
- };
441
- }
442
- /**
443
- * Overrides the default mention execute listener to insert an emoji as plain text instead.
444
- */ _overrideMentionExecuteListener() {
445
- const editor = this.editor;
446
- editor.commands.get('mention').on('execute', (event, data)=>{
447
- const eventData = data[0];
448
- // Ignore non-emoji auto-complete actions.
449
- if (eventData.marker !== EMOJI_MENTION_MARKER) {
450
- return;
451
- }
452
- // Do not propagate the event.
453
- event.stop();
454
- // Do nothing when executing after selecting a hint message.
455
- if (eventData.mention.id === EMOJI_HINT_OPTION_ID) {
456
- return;
457
- }
458
- // Trigger the picker UI.
459
- if (eventData.mention.id === EMOJI_SHOW_ALL_OPTION_ID) {
460
- const text = [
461
- ...eventData.range.getItems()
462
- ].filter((item)=>item.is('$textProxy')).map((item)=>item.data).reduce((result, text)=>result + text, '');
463
- editor.model.change((writer)=>{
464
- editor.model.deleteContent(writer.createSelection(eventData.range));
465
- });
466
- const emojiPickerPlugin = this._emojiPickerPlugin;
467
- emojiPickerPlugin.showUI(text.slice(1));
468
- setTimeout(()=>{
469
- emojiPickerPlugin.emojiPickerView.focus();
470
- });
471
- } else {
472
- editor.execute('insertText', {
473
- text: eventData.mention.text,
474
- range: eventData.range
475
- });
476
- }
477
- }, {
478
- priority: 'high'
479
- });
480
- }
481
- /**
482
- * Returns the `feed()` callback for mention config.
483
- */ _queryEmojiCallbackFactory() {
484
- return (searchQuery)=>{
485
- // Do not show anything when a query starts with a space.
486
- if (searchQuery.startsWith(' ')) {
487
- return [];
488
- }
489
- const emojis = this._emojiRepositoryPlugin.getEmojiByQuery(searchQuery).map((emoji)=>{
490
- let text = emoji.skins[this._skinTone] || emoji.skins.default;
491
- if (this._emojiPickerPlugin) {
492
- text = emoji.skins[this._emojiPickerPlugin.skinTone] || emoji.skins.default;
493
- }
494
- return {
495
- id: `:${emoji.annotation}:`,
496
- text
497
- };
498
- });
499
- if (!this._emojiPickerPlugin) {
500
- return emojis.slice(0, this._emojiDropdownLimit);
501
- }
502
- const actionItem = {
503
- id: searchQuery.length > 1 ? EMOJI_SHOW_ALL_OPTION_ID : EMOJI_HINT_OPTION_ID
504
- };
505
- return [
506
- ...emojis.slice(0, this._emojiDropdownLimit - 1),
507
- actionItem
508
- ];
509
- };
510
- }
511
- }
512
-
513
- /**
514
- * Command that shows the emoji user interface.
515
- */ class EmojiCommand extends Command {
516
- /**
517
- * Updates the command's {@link #isEnabled} based on the current selection.
518
- */ refresh() {
519
- const editor = this.editor;
520
- const model = editor.model;
521
- const schema = model.schema;
522
- const selection = model.document.selection;
523
- this.isEnabled = schema.checkChild(selection.getFirstPosition(), '$text');
524
- }
525
- /**
526
- * Opens emoji user interface for the current document selection.
527
- *
528
- * @fires execute
529
- * @param [searchValue=''] A default query used to filer the grid when opening the UI.
530
- */ execute(searchValue = '') {
531
- const emojiPickerPlugin = this.editor.plugins.get('EmojiPicker');
532
- emojiPickerPlugin.showUI(searchValue);
533
- }
534
- }
535
-
536
- /**
537
- * A grid of emoji tiles. It allows browsing emojis and selecting them to be inserted into the content.
538
- */ class EmojiGridView extends View {
539
- /**
540
- * A collection of the child tile views. Each tile represents a particular emoji.
541
- */ tiles;
542
- /**
543
- * Tracks information about the DOM focus in the grid.
544
- */ focusTracker;
545
- /**
546
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
547
- */ keystrokes;
548
- /**
549
- * An array containing all emojis grouped by their categories.
550
- */ emojiCategories;
551
- /**
552
- * A collection of all already created tile views. Each tile represents a particular emoji.
553
- * The cached tiles collection is used for efficiency purposes to avoid re-creating a particular
554
- * tile again when the grid view has changed.
555
- */ cachedTiles;
556
- /**
557
- * A callback used to filter grid items by a specified query.
558
- */ _getEmojiByQuery;
559
- /**
560
- * @inheritDoc
561
- */ constructor(locale, { categoryName, emojiCategories, getEmojiByQuery, skinTone }){
562
- super(locale);
563
- this.set('isEmpty', true);
564
- this.set('categoryName', categoryName);
565
- this.set('skinTone', skinTone);
566
- this.tiles = this.createCollection();
567
- this.cachedTiles = this.createCollection();
568
- this.focusTracker = new FocusTracker();
569
- this.keystrokes = new KeystrokeHandler();
570
- this._getEmojiByQuery = getEmojiByQuery;
571
- this.emojiCategories = emojiCategories;
572
- const bind = this.bindTemplate;
573
- this.setTemplate({
574
- tag: 'div',
575
- children: [
576
- {
577
- tag: 'div',
578
- attributes: {
579
- role: 'grid',
580
- class: [
581
- 'ck',
582
- 'ck-emoji__grid'
583
- ]
584
- },
585
- children: this.tiles
586
- }
587
- ],
588
- attributes: {
589
- role: 'tabpanel',
590
- class: [
591
- 'ck',
592
- 'ck-emoji__tiles',
593
- // To avoid issues with focus cycling, ignore a grid when it's empty.
594
- bind.if('isEmpty', 'ck-hidden', (value)=>value)
595
- ]
596
- }
597
- });
598
- addKeyboardHandlingForGrid({
599
- keystrokeHandler: this.keystrokes,
600
- focusTracker: this.focusTracker,
601
- gridItems: this.tiles,
602
- numberOfColumns: ()=>global.window.getComputedStyle(this.element.firstChild) // Responsive `.ck-emoji-grid__tiles`.
603
- .getPropertyValue('grid-template-columns').split(' ').length,
604
- uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
605
- });
606
- }
607
- /**
608
- * @inheritDoc
609
- */ render() {
610
- super.render();
611
- this.keystrokes.listenTo(this.element);
612
- }
613
- /**
614
- * @inheritDoc
615
- */ destroy() {
616
- super.destroy();
617
- this.keystrokes.destroy();
618
- this.focusTracker.destroy();
619
- }
620
- /**
621
- * Focuses the first focusable in {@link ~EmojiGridView#tiles} if available.
622
- */ focus() {
623
- const firstTile = this.tiles.first;
624
- if (firstTile) {
625
- firstTile.focus();
626
- }
627
- }
628
- /**
629
- * Filters the grid view by the given regular expression.
630
- *
631
- * It filters either by the pattern or an emoji category, but never both.
632
- *
633
- * @param pattern Expression to search or `null` when filter by category name.
634
- */ filter(pattern) {
635
- const { matchingItems, allItems } = pattern ? this._getItemsByQuery(pattern.source) : this._getItemsByCategory();
636
- this._updateGrid(matchingItems);
637
- this.set('isEmpty', matchingItems.length === 0);
638
- return {
639
- resultsCount: matchingItems.length,
640
- totalItemsCount: allItems.length
641
- };
642
- }
643
- /**
644
- * Filters emojis to show based on the specified query phrase.
645
- *
646
- * @param query A query used to filter the grid.
647
- */ _getItemsByQuery(query) {
648
- return {
649
- matchingItems: this._getEmojiByQuery(query),
650
- allItems: this.emojiCategories.flatMap((group)=>group.items)
651
- };
652
- }
653
- /**
654
- * Returns emojis that belong to the specified category.
655
- */ _getItemsByCategory() {
656
- const emojiCategory = this.emojiCategories.find((item)=>item.title === this.categoryName);
657
- const { items } = emojiCategory;
658
- return {
659
- matchingItems: items,
660
- allItems: items
661
- };
662
- }
663
- /**
664
- * Updates the grid by removing the existing items and insert the new ones.
665
- *
666
- * @param items An array of items to insert.
667
- */ _updateGrid(items) {
668
- // Clean-up.
669
- [
670
- ...this.tiles
671
- ].forEach((item)=>{
672
- this.focusTracker.remove(item);
673
- this.tiles.remove(item);
674
- });
675
- items// Create tiles from matching results.
676
- .map((item)=>{
677
- const emoji = item.skins[this.skinTone] || item.skins.default;
678
- return this.cachedTiles.get(emoji) || this._createTile(emoji, item.annotation);
679
- })// Insert new elements.
680
- .forEach((item)=>{
681
- this.tiles.add(item);
682
- this.focusTracker.add(item);
683
- });
684
- }
685
- /**
686
- * Creates a new tile for the grid. Created tile is added to the {@link #cachedTiles} collection for further usage, if needed.
687
- *
688
- * @param emoji The emoji itself.
689
- * @param name The name of the emoji (e.g. "Smiling Face with Smiling Eyes").
690
- */ _createTile(emoji, name) {
691
- const tile = new ButtonView(this.locale);
692
- tile.viewUid = emoji;
693
- tile.extendTemplate({
694
- attributes: {
695
- class: [
696
- 'ck-emoji__tile'
697
- ]
698
- }
699
- });
700
- tile.set({
701
- label: emoji,
702
- tooltip: name,
703
- withText: true,
704
- ariaLabel: name,
705
- // To improve accessibility, disconnect a button and its label connection so that screen
706
- // readers can read the `[aria-label]` attribute directly from the more descriptive button.
707
- ariaLabelledBy: undefined
708
- });
709
- tile.on('execute', ()=>{
710
- this.fire('execute', {
711
- name,
712
- emoji
713
- });
714
- });
715
- this.cachedTiles.add(tile);
716
- return tile;
717
- }
718
- }
719
-
720
- /**
721
- * A class representing the navigation part of the emoji UI.
722
- * It is responsible allowing the user to select a particular emoji category.
723
- */ class EmojiCategoriesView extends View {
724
- /**
725
- * Tracks information about the DOM focus in the grid.
726
- */ focusTracker;
727
- /**
728
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
729
- */ keystrokes;
730
- /**
731
- * Helps cycling over focusable children in the input view.
732
- */ focusCycler;
733
- /**
734
- * A collection of the categories buttons.
735
- */ buttonViews;
736
- /**
737
- * @inheritDoc
738
- */ constructor(locale, { emojiCategories, categoryName }){
739
- super(locale);
740
- this.buttonViews = this.createCollection(emojiCategories.map((emojiCategory)=>this._createCategoryButton(emojiCategory)));
741
- this.focusTracker = new FocusTracker();
742
- this.keystrokes = new KeystrokeHandler();
743
- this.focusCycler = new FocusCycler({
744
- focusables: this.buttonViews,
745
- focusTracker: this.focusTracker,
746
- keystrokeHandler: this.keystrokes,
747
- actions: {
748
- focusPrevious: 'arrowleft',
749
- focusNext: 'arrowright'
750
- }
751
- });
752
- this.setTemplate({
753
- tag: 'div',
754
- attributes: {
755
- class: [
756
- 'ck',
757
- 'ck-emoji__categories-list'
758
- ],
759
- role: 'tablist'
760
- },
761
- children: this.buttonViews
762
- });
763
- this.on('change:categoryName', (event, name, newValue, oldValue)=>{
764
- const oldCategoryButton = this.buttonViews.find((button)=>button.tooltip === oldValue);
765
- if (oldCategoryButton) {
766
- oldCategoryButton.isOn = false;
767
- }
768
- const newCategoryButton = this.buttonViews.find((button)=>button.tooltip === newValue);
769
- newCategoryButton.isOn = true;
770
- });
771
- this.set('categoryName', categoryName);
772
- }
773
- /**
774
- * @inheritDoc
775
- */ render() {
776
- super.render();
777
- this.buttonViews.forEach((buttonView)=>{
778
- this.focusTracker.add(buttonView);
779
- });
780
- this.keystrokes.listenTo(this.element);
781
- }
782
- /**
783
- * @inheritDoc
784
- */ destroy() {
785
- super.destroy();
786
- this.focusTracker.destroy();
787
- this.keystrokes.destroy();
788
- this.buttonViews.destroy();
789
- }
790
- /**
791
- * @inheritDoc
792
- */ focus() {
793
- this.buttonViews.first.focus();
794
- }
795
- /**
796
- * Marks all categories buttons as enabled (clickable).
797
- */ enableCategories() {
798
- this.buttonViews.forEach((buttonView)=>{
799
- buttonView.isEnabled = true;
800
- });
801
- }
802
- /**
803
- * Marks all categories buttons as disabled (non-clickable).
804
- */ disableCategories() {
805
- this.buttonViews.forEach((buttonView)=>{
806
- buttonView.set({
807
- class: '',
808
- isEnabled: false,
809
- isOn: false
810
- });
811
- });
812
- }
813
- /**
814
- * Creates a button representing a category item.
815
- */ _createCategoryButton(emojiCategory) {
816
- const buttonView = new ButtonView();
817
- const bind = buttonView.bindTemplate;
818
- // A `[role="tab"]` element requires also the `[aria-selected]` attribute with its state.
819
- buttonView.extendTemplate({
820
- attributes: {
821
- 'aria-selected': bind.to('isOn', (value)=>value.toString()),
822
- class: [
823
- 'ck-emoji__category-item'
824
- ]
825
- }
826
- });
827
- buttonView.set({
828
- ariaLabel: emojiCategory.title,
829
- label: emojiCategory.icon,
830
- role: 'tab',
831
- tooltip: emojiCategory.title,
832
- withText: true,
833
- // To improve accessibility, disconnect a button and its label connection so that screen
834
- // readers can read the `[aria-label]` attribute directly from the more descriptive button.
835
- ariaLabelledBy: undefined
836
- });
837
- buttonView.on('execute', ()=>{
838
- this.categoryName = emojiCategory.title;
839
- });
840
- buttonView.on('change:isEnabled', ()=>{
841
- if (buttonView.isEnabled && buttonView.tooltip === this.categoryName) {
842
- buttonView.isOn = true;
843
- }
844
- });
845
- return buttonView;
846
- }
847
- }
848
-
849
- /**
850
- * A view responsible for providing an input element that allows filtering emoji by the provided query.
851
- */ class EmojiSearchView extends View {
852
- /**
853
- * The find in text input view that stores the searched string.
854
- */ inputView;
855
- /**
856
- * An instance of the `EmojiGridView`.
857
- */ gridView;
858
- /**
859
- * @inheritDoc
860
- */ constructor(locale, { gridView, resultsView }){
861
- super(locale);
862
- this.gridView = gridView;
863
- const t = locale.t;
864
- this.inputView = new SearchTextView(this.locale, {
865
- queryView: {
866
- label: t('Find an emoji (min. 2 characters)'),
867
- creator: createLabeledInputText
868
- },
869
- filteredView: this.gridView,
870
- infoView: {
871
- instance: resultsView
872
- }
873
- });
874
- this.setTemplate({
875
- tag: 'div',
876
- attributes: {
877
- class: [
878
- 'ck',
879
- 'ck-search'
880
- ],
881
- tabindex: '-1'
882
- },
883
- children: [
884
- this.inputView.queryView
885
- ]
886
- });
887
- // Pass through the `search` event to handle it by a parent view.
888
- this.inputView.delegate('search').to(this);
889
- }
890
- /**
891
- * @inheritDoc
892
- */ destroy() {
893
- super.destroy();
894
- this.inputView.destroy();
895
- }
896
- /**
897
- * Searches the {@link #gridView} for the given query.
898
- *
899
- * @param query The search query string.
900
- */ search(query) {
901
- const regExp = query ? new RegExp(escapeRegExp(query), 'ig') : null;
902
- const filteringResults = this.gridView.filter(regExp);
903
- this.inputView.fire('search', {
904
- query,
905
- ...filteringResults
906
- });
907
- }
908
- /**
909
- * Allows defining the default value in the search text field.
910
- *
911
- * @param value The new value.
912
- */ setInputValue(value) {
913
- if (!value) {
914
- this.inputView.queryView.fieldView.reset();
915
- } else {
916
- this.inputView.queryView.fieldView.value = value;
917
- }
918
- }
919
- /**
920
- * Returns an input provided by a user in the search text field.
921
- */ getInputValue() {
922
- return this.inputView.queryView.fieldView.element.value;
923
- }
924
- /**
925
- * @inheritDoc
926
- */ focus() {
927
- this.inputView.focus();
928
- }
929
- }
930
-
931
- /**
932
- * A view responsible for selecting a skin tone for an emoji.
933
- */ class EmojiToneView extends View {
934
- /**
935
- * A dropdown element for selecting an active skin tone.
936
- */ dropdownView;
937
- /**
938
- * An array of available skin tones.
939
- */ _skinTones;
940
- /**
941
- * @inheritDoc
942
- */ constructor(locale, { skinTone, skinTones }){
943
- super(locale);
944
- this.set('skinTone', skinTone);
945
- this._skinTones = skinTones;
946
- const t = locale.t;
947
- const accessibleLabel = t('Select skin tone');
948
- const dropdownView = createDropdown(locale);
949
- const itemDefinitions = new Collection();
950
- for (const { id, icon, tooltip } of this._skinTones){
951
- const def = {
952
- type: 'button',
953
- model: new ViewModel({
954
- value: id,
955
- label: icon,
956
- ariaLabel: tooltip,
957
- tooltip,
958
- tooltipPosition: 'e',
959
- role: 'menuitemradio',
960
- withText: true,
961
- // To improve accessibility, disconnect a button and its label connection so that screen
962
- // readers can read the `[aria-label]` attribute directly from the more descriptive button.
963
- ariaLabelledBy: undefined
964
- })
965
- };
966
- def.model.bind('isOn').to(this, 'skinTone', (value)=>value === id);
967
- itemDefinitions.add(def);
968
- }
969
- addListToDropdown(dropdownView, itemDefinitions, {
970
- ariaLabel: accessibleLabel,
971
- role: 'menu'
972
- });
973
- dropdownView.buttonView.set({
974
- label: this._getSkinTone().icon,
975
- ariaLabel: accessibleLabel,
976
- ariaLabelledBy: undefined,
977
- isOn: false,
978
- withText: true,
979
- tooltip: accessibleLabel
980
- });
981
- this.dropdownView = dropdownView;
982
- // Execute command when an item from the dropdown is selected.
983
- this.listenTo(dropdownView, 'execute', (evt)=>{
984
- this.skinTone = evt.source.value;
985
- });
986
- dropdownView.buttonView.bind('label').to(this, 'skinTone', ()=>{
987
- return this._getSkinTone().icon;
988
- });
989
- dropdownView.buttonView.bind('ariaLabel').to(this, 'skinTone', ()=>{
990
- // Render a current state, but also what the dropdown does.
991
- return `${this._getSkinTone().tooltip}, ${accessibleLabel}`;
992
- });
993
- this.setTemplate({
994
- tag: 'div',
995
- attributes: {
996
- class: [
997
- 'ck',
998
- 'ck-emoji__skin-tone'
999
- ]
1000
- },
1001
- children: [
1002
- dropdownView
1003
- ]
1004
- });
1005
- }
1006
- /**
1007
- * @inheritDoc
1008
- */ focus() {
1009
- this.dropdownView.buttonView.focus();
1010
- }
1011
- /**
1012
- * Helper method for receiving an object describing the active skin tone.
1013
- */ _getSkinTone() {
1014
- return this._skinTones.find((tone)=>tone.id === this.skinTone);
1015
- }
1016
- }
1017
-
1018
- /**
1019
- * A view that glues pieces of the emoji panel together.
1020
- */ class EmojiPickerView extends View {
1021
- /**
1022
- * A collection of the focusable children of the view.
1023
- */ items;
1024
- /**
1025
- * Tracks information about the DOM focus in the view.
1026
- */ focusTracker;
1027
- /**
1028
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
1029
- */ keystrokes;
1030
- /**
1031
- * Helps cycling over focusable {@link #items} in the view.
1032
- */ focusCycler;
1033
- /**
1034
- * An instance of the `EmojiSearchView`.
1035
- */ searchView;
1036
- /**
1037
- * An instance of the `EmojiToneView`.
1038
- */ toneView;
1039
- /**
1040
- * An instance of the `EmojiCategoriesView`.
1041
- */ categoriesView;
1042
- /**
1043
- * An instance of the `EmojiGridView`.
1044
- */ gridView;
1045
- /**
1046
- * An instance of the `EmojiGridView`.
1047
- */ infoView;
1048
- /**
1049
- * @inheritDoc
1050
- */ constructor(locale, { emojiCategories, getEmojiByQuery, skinTone, skinTones }){
1051
- super(locale);
1052
- const categoryName = emojiCategories[0].title;
1053
- this.gridView = new EmojiGridView(locale, {
1054
- categoryName,
1055
- emojiCategories,
1056
- getEmojiByQuery,
1057
- skinTone
1058
- });
1059
- this.infoView = new SearchInfoView();
1060
- this.searchView = new EmojiSearchView(locale, {
1061
- gridView: this.gridView,
1062
- resultsView: this.infoView
1063
- });
1064
- this.categoriesView = new EmojiCategoriesView(locale, {
1065
- emojiCategories,
1066
- categoryName
1067
- });
1068
- this.toneView = new EmojiToneView(locale, {
1069
- skinTone,
1070
- skinTones
1071
- });
1072
- this.items = this.createCollection([
1073
- this.searchView,
1074
- this.toneView,
1075
- this.categoriesView,
1076
- this.gridView,
1077
- this.infoView
1078
- ]);
1079
- this.focusTracker = new FocusTracker();
1080
- this.keystrokes = new KeystrokeHandler();
1081
- this.focusCycler = new FocusCycler({
1082
- focusables: this.items,
1083
- focusTracker: this.focusTracker,
1084
- keystrokeHandler: this.keystrokes,
1085
- actions: {
1086
- focusPrevious: 'shift + tab',
1087
- focusNext: 'tab'
1088
- }
1089
- });
1090
- this.setTemplate({
1091
- tag: 'div',
1092
- children: [
1093
- {
1094
- tag: 'div',
1095
- children: [
1096
- this.searchView,
1097
- this.toneView
1098
- ],
1099
- attributes: {
1100
- class: [
1101
- 'ck',
1102
- 'ck-emoji__search'
1103
- ]
1104
- }
1105
- },
1106
- this.categoriesView,
1107
- this.gridView,
1108
- {
1109
- tag: 'div',
1110
- children: [
1111
- this.infoView
1112
- ],
1113
- attributes: {
1114
- class: [
1115
- 'ck',
1116
- 'ck-search__results'
1117
- ]
1118
- }
1119
- }
1120
- ],
1121
- attributes: {
1122
- tabindex: '-1',
1123
- class: [
1124
- 'ck',
1125
- 'ck-emoji',
1126
- 'ck-search'
1127
- ]
1128
- }
1129
- });
1130
- this._setupEventListeners();
1131
- }
1132
- /**
1133
- * @inheritDoc
1134
- */ render() {
1135
- super.render();
1136
- this.focusTracker.add(this.searchView.element);
1137
- this.focusTracker.add(this.toneView.element);
1138
- this.focusTracker.add(this.categoriesView.element);
1139
- this.focusTracker.add(this.gridView.element);
1140
- this.focusTracker.add(this.infoView.element);
1141
- // Start listening for the keystrokes coming from #element.
1142
- this.keystrokes.listenTo(this.element);
1143
- }
1144
- /**
1145
- * @inheritDoc
1146
- */ destroy() {
1147
- super.destroy();
1148
- this.focusTracker.destroy();
1149
- this.keystrokes.destroy();
1150
- }
1151
- /**
1152
- * Focuses the search input.
1153
- */ focus() {
1154
- this.searchView.focus();
1155
- }
1156
- /**
1157
- * Initializes interactions between sub-views.
1158
- */ _setupEventListeners() {
1159
- const t = this.locale.t;
1160
- // Disable the category switcher when filtering by a query.
1161
- this.searchView.on('search', (evt, data)=>{
1162
- if (data.query) {
1163
- this.categoriesView.disableCategories();
1164
- } else {
1165
- this.categoriesView.enableCategories();
1166
- }
1167
- });
1168
- // Show a user-friendly message depending on the search query.
1169
- this.searchView.on('search', (evt, data)=>{
1170
- if (data.query.length === 1) {
1171
- this.infoView.set({
1172
- primaryText: t('Keep on typing to see the emoji.'),
1173
- secondaryText: t('The query must contain at least two characters.'),
1174
- isVisible: true
1175
- });
1176
- } else if (!data.resultsCount) {
1177
- this.infoView.set({
1178
- primaryText: t('No emojis were found matching "%0".', data.query),
1179
- secondaryText: t('Please try a different phrase or check the spelling.'),
1180
- isVisible: true
1181
- });
1182
- } else {
1183
- this.infoView.set({
1184
- isVisible: false
1185
- });
1186
- }
1187
- });
1188
- // Emit an update event to react to balloon dimensions changes.
1189
- this.searchView.on('search', ()=>{
1190
- this.fire('update');
1191
- });
1192
- // Update the grid of emojis when the selected category is changed.
1193
- this.categoriesView.on('change:categoryName', (ev, args, categoryName)=>{
1194
- this.gridView.categoryName = categoryName;
1195
- this.searchView.search('');
1196
- });
1197
- // Update the grid of emojis when the selected skin tone is changed.
1198
- // In such a case, the displayed emoji should use an updated skin tone value.
1199
- this.toneView.on('change:skinTone', (evt, propertyName, newValue)=>{
1200
- this.gridView.skinTone = newValue;
1201
- this.searchView.search(this.searchView.getInputValue());
1202
- });
1203
- }
1204
- }
1205
-
1206
- const VISUAL_SELECTION_MARKER_NAME = 'emoji-picker';
1207
- /**
1208
- * The emoji picker plugin.
1209
- *
1210
- * Introduces the `'emoji'` dropdown.
1211
- */ class EmojiPicker extends Plugin {
1212
- /**
1213
- * @inheritDoc
1214
- */ static get requires() {
1215
- return [
1216
- EmojiRepository,
1217
- ContextualBalloon,
1218
- Dialog,
1219
- Typing
1220
- ];
1221
- }
1222
- /**
1223
- * @inheritDoc
1224
- */ static get pluginName() {
1225
- return 'EmojiPicker';
1226
- }
1227
- /**
1228
- * @inheritDoc
1229
- */ static get isOfficialPlugin() {
1230
- return true;
1231
- }
1232
- /**
1233
- * @inheritDoc
1234
- */ async init() {
1235
- const editor = this.editor;
1236
- this._balloonPlugin = editor.plugins.get('ContextualBalloon');
1237
- this._emojiRepositoryPlugin = editor.plugins.get('EmojiRepository');
1238
- // Skip registering a button in the toolbar and list item in the menu bar if the emoji repository is not ready.
1239
- if (!await this._emojiRepositoryPlugin.isReady()) {
1240
- return;
1241
- }
1242
- const command = new EmojiCommand(editor);
1243
- editor.commands.add('emoji', command);
1244
- editor.ui.componentFactory.add('emoji', ()=>{
1245
- const button = this._createButton(ButtonView, command);
1246
- button.set({
1247
- tooltip: true
1248
- });
1249
- return button;
1250
- });
1251
- editor.ui.componentFactory.add('menuBar:emoji', ()=>{
1252
- return this._createButton(MenuBarMenuListItemButtonView, command);
1253
- });
1254
- this._setupConversion();
1255
- }
1256
- /**
1257
- * @inheritDoc
1258
- */ destroy() {
1259
- super.destroy();
1260
- if (this.emojiPickerView) {
1261
- this.emojiPickerView.destroy();
1262
- }
1263
- }
1264
- /**
1265
- * Represents an active skin tone. Its value depends on the emoji UI plugin.
1266
- *
1267
- * Before opening the UI for the first time, the returned value is read from the editor configuration.
1268
- * Otherwise, it reflects the user's intention.
1269
- */ get skinTone() {
1270
- if (!this.emojiPickerView) {
1271
- return this.editor.config.get('emoji.skinTone');
1272
- }
1273
- return this.emojiPickerView.gridView.skinTone;
1274
- }
1275
- /**
1276
- * Displays the balloon with the emoji picker.
1277
- *
1278
- * @param [searchValue=''] A default query used to filer the grid when opening the UI.
1279
- */ showUI(searchValue = '') {
1280
- // Show visual selection on a text when the contextual balloon is displayed.
1281
- // See #17654.
1282
- this._showFakeVisualSelection();
1283
- if (!this.emojiPickerView) {
1284
- this.emojiPickerView = this._createEmojiPickerView();
1285
- }
1286
- if (searchValue) {
1287
- this.emojiPickerView.searchView.setInputValue(searchValue);
1288
- }
1289
- this.emojiPickerView.searchView.search(searchValue);
1290
- if (!this._balloonPlugin.hasView(this.emojiPickerView)) {
1291
- this._balloonPlugin.add({
1292
- view: this.emojiPickerView,
1293
- position: this._getBalloonPositionData()
1294
- });
1295
- }
1296
- this.emojiPickerView.focus();
1297
- }
1298
- /**
1299
- * Creates a button for toolbar and menu bar that will show the emoji dialog.
1300
- */ _createButton(ViewClass, command) {
1301
- const buttonView = new ViewClass(this.editor.locale);
1302
- const t = this.editor.locale.t;
1303
- buttonView.bind('isEnabled').to(command, 'isEnabled');
1304
- buttonView.set({
1305
- label: t('Emoji'),
1306
- icon: IconEmoji,
1307
- isToggleable: true
1308
- });
1309
- buttonView.on('execute', ()=>{
1310
- this.showUI();
1311
- });
1312
- return buttonView;
1313
- }
1314
- /**
1315
- * Creates an instance of the `EmojiPickerView` class that represents an emoji balloon.
1316
- */ _createEmojiPickerView() {
1317
- const emojiPickerView = new EmojiPickerView(this.editor.locale, {
1318
- emojiCategories: this._emojiRepositoryPlugin.getEmojiCategories(),
1319
- skinTone: this.editor.config.get('emoji.skinTone'),
1320
- skinTones: this._emojiRepositoryPlugin.getSkinTones(),
1321
- getEmojiByQuery: (query)=>{
1322
- return this._emojiRepositoryPlugin.getEmojiByQuery(query);
1323
- }
1324
- });
1325
- // Insert an emoji on a tile click.
1326
- this.listenTo(emojiPickerView.gridView, 'execute', (evt, data)=>{
1327
- const editor = this.editor;
1328
- const textToInsert = data.emoji;
1329
- this._hideUI();
1330
- editor.execute('insertText', {
1331
- text: textToInsert
1332
- });
1333
- });
1334
- // Update the balloon position when layout is changed.
1335
- this.listenTo(emojiPickerView, 'update', ()=>{
1336
- if (this._balloonPlugin.visibleView === emojiPickerView) {
1337
- this._balloonPlugin.updatePosition();
1338
- }
1339
- });
1340
- // Close the panel on `Esc` key press when the **actions have focus**.
1341
- emojiPickerView.keystrokes.set('Esc', (data, cancel)=>{
1342
- this._hideUI();
1343
- cancel();
1344
- });
1345
- // Close the dialog when clicking outside of it.
1346
- clickOutsideHandler({
1347
- emitter: emojiPickerView,
1348
- contextElements: [
1349
- this._balloonPlugin.view.element
1350
- ],
1351
- callback: ()=>this._hideUI(),
1352
- activator: ()=>this._balloonPlugin.visibleView === emojiPickerView
1353
- });
1354
- return emojiPickerView;
1355
- }
1356
- /**
1357
- * Hides the balloon with the emoji picker.
1358
- */ _hideUI() {
1359
- this._balloonPlugin.remove(this.emojiPickerView);
1360
- this.emojiPickerView.searchView.setInputValue('');
1361
- this.editor.editing.view.focus();
1362
- this._hideFakeVisualSelection();
1363
- }
1364
- /**
1365
- * Registers converters.
1366
- */ _setupConversion() {
1367
- const editor = this.editor;
1368
- // Renders a fake visual selection marker on an expanded selection.
1369
- editor.conversion.for('editingDowncast').markerToHighlight({
1370
- model: VISUAL_SELECTION_MARKER_NAME,
1371
- view: {
1372
- classes: [
1373
- 'ck-fake-emoji-selection'
1374
- ]
1375
- }
1376
- });
1377
- // Renders a fake visual selection marker on a collapsed selection.
1378
- editor.conversion.for('editingDowncast').markerToElement({
1379
- model: VISUAL_SELECTION_MARKER_NAME,
1380
- view: (data, { writer })=>{
1381
- if (!data.markerRange.isCollapsed) {
1382
- return null;
1383
- }
1384
- const markerElement = writer.createUIElement('span');
1385
- writer.addClass([
1386
- 'ck-fake-emoji-selection',
1387
- 'ck-fake-emoji-selection_collapsed'
1388
- ], markerElement);
1389
- return markerElement;
1390
- }
1391
- });
1392
- }
1393
- /**
1394
- * Returns positioning options for the {@link #_balloonPlugin}. They control the way the balloon is attached
1395
- * to the target element or selection.
1396
- */ _getBalloonPositionData() {
1397
- const view = this.editor.editing.view;
1398
- const viewDocument = view.document;
1399
- // Set a target position by converting view selection range to DOM.
1400
- const target = ()=>view.domConverter.viewRangeToDom(viewDocument.selection.getFirstRange());
1401
- return {
1402
- target
1403
- };
1404
- }
1405
- /**
1406
- * Displays a fake visual selection when the contextual balloon is displayed.
1407
- *
1408
- * This adds an 'emoji-picker' marker into the document that is rendered as a highlight on selected text fragment.
1409
- */ _showFakeVisualSelection() {
1410
- const model = this.editor.model;
1411
- model.change((writer)=>{
1412
- const range = model.document.selection.getFirstRange();
1413
- if (model.markers.has(VISUAL_SELECTION_MARKER_NAME)) {
1414
- writer.updateMarker(VISUAL_SELECTION_MARKER_NAME, {
1415
- range
1416
- });
1417
- } else {
1418
- if (range.start.isAtEnd) {
1419
- const startPosition = range.start.getLastMatchingPosition(({ item })=>!model.schema.isContent(item), {
1420
- boundaries: range
1421
- });
1422
- writer.addMarker(VISUAL_SELECTION_MARKER_NAME, {
1423
- usingOperation: false,
1424
- affectsData: false,
1425
- range: writer.createRange(startPosition, range.end)
1426
- });
1427
- } else {
1428
- writer.addMarker(VISUAL_SELECTION_MARKER_NAME, {
1429
- usingOperation: false,
1430
- affectsData: false,
1431
- range
1432
- });
1433
- }
1434
- }
1435
- });
1436
- }
1437
- /**
1438
- * Hides the fake visual selection.
1439
- */ _hideFakeVisualSelection() {
1440
- const model = this.editor.model;
1441
- if (model.markers.has(VISUAL_SELECTION_MARKER_NAME)) {
1442
- model.change((writer)=>{
1443
- writer.removeMarker(VISUAL_SELECTION_MARKER_NAME);
1444
- });
1445
- }
1446
- }
1447
- }
1448
-
1449
- /**
1450
- * The emoji plugin.
1451
- *
1452
- * This is a "glue" plugin which loads the following plugins:
1453
- *
1454
- * * {@link module:emoji/emojimention~EmojiMention},
1455
- * * {@link module:emoji/emojipicker~EmojiPicker},
1456
- */ class Emoji extends Plugin {
1457
- /**
1458
- * @inheritDoc
1459
- */ static get requires() {
1460
- return [
1461
- EmojiMention,
1462
- EmojiPicker
1463
- ];
1464
- }
1465
- /**
1466
- * @inheritDoc
1467
- */ static get pluginName() {
1468
- return 'Emoji';
1469
- }
1470
- /**
1471
- * @inheritDoc
1472
- */ static get isOfficialPlugin() {
1473
- return true;
1474
- }
1475
- }
1476
-
1477
- export { Emoji, EmojiCommand, EmojiMention, EmojiPicker, EmojiRepository };
1478
- //# sourceMappingURL=index.js.map