@ckeditor/ckeditor5-emoji 0.0.0-nightly-20250129.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +28 -0
  3. package/README.md +31 -0
  4. package/build/emoji.js +4 -0
  5. package/ckeditor5-metadata.json +32 -0
  6. package/dist/index-content.css +4 -0
  7. package/dist/index-editor.css +111 -0
  8. package/dist/index.css +143 -0
  9. package/dist/index.css.map +1 -0
  10. package/dist/index.js +1477 -0
  11. package/dist/index.js.map +1 -0
  12. package/lang/contexts.json +24 -0
  13. package/package.json +67 -0
  14. package/src/augmentation.d.ts +24 -0
  15. package/src/augmentation.js +5 -0
  16. package/src/emoji.d.ts +32 -0
  17. package/src/emoji.js +38 -0
  18. package/src/emojicommand.d.ts +24 -0
  19. package/src/emojicommand.js +33 -0
  20. package/src/emojiconfig.d.ts +80 -0
  21. package/src/emojiconfig.js +5 -0
  22. package/src/emojimention.d.ts +68 -0
  23. package/src/emojimention.js +193 -0
  24. package/src/emojipicker.d.ts +97 -0
  25. package/src/emojipicker.js +255 -0
  26. package/src/emojirepository.d.ts +139 -0
  27. package/src/emojirepository.js +267 -0
  28. package/src/index.d.ts +14 -0
  29. package/src/index.js +13 -0
  30. package/src/ui/emojicategoriesview.d.ts +68 -0
  31. package/src/ui/emojicategoriesview.js +131 -0
  32. package/src/ui/emojigridview.d.ts +140 -0
  33. package/src/ui/emojigridview.js +183 -0
  34. package/src/ui/emojipickerview.d.ts +91 -0
  35. package/src/ui/emojipickerview.js +172 -0
  36. package/src/ui/emojisearchview.d.ts +51 -0
  37. package/src/ui/emojisearchview.js +89 -0
  38. package/src/ui/emojitoneview.d.ts +46 -0
  39. package/src/ui/emojitoneview.js +89 -0
  40. package/theme/emojicategories.css +29 -0
  41. package/theme/emojigrid.css +55 -0
  42. package/theme/emojipicker.css +32 -0
  43. package/theme/emojitone.css +21 -0
@@ -0,0 +1,97 @@
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
+ /**
6
+ * @module emoji/emojipicker
7
+ */
8
+ import { ContextualBalloon, Dialog } from 'ckeditor5/src/ui.js';
9
+ import { Plugin } from 'ckeditor5/src/core.js';
10
+ import { Typing } from 'ckeditor5/src/typing.js';
11
+ import EmojiRepository from './emojirepository.js';
12
+ import EmojiPickerView from './ui/emojipickerview.js';
13
+ import type { SkinToneId } from './emojiconfig.js';
14
+ import '../theme/emojipicker.css';
15
+ /**
16
+ * The emoji picker plugin.
17
+ *
18
+ * Introduces the `'emoji'` dropdown.
19
+ */
20
+ export default class EmojiPicker extends Plugin {
21
+ /**
22
+ * The actions view displayed inside the balloon.
23
+ */
24
+ emojiPickerView: EmojiPickerView | undefined;
25
+ /**
26
+ * The contextual balloon plugin instance.
27
+ */
28
+ _balloonPlugin: ContextualBalloon;
29
+ /**
30
+ * An instance of the {@link module:emoji/emojirepository~EmojiRepository} plugin.
31
+ */
32
+ private _emojiRepositoryPlugin;
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ static get requires(): readonly [typeof EmojiRepository, typeof ContextualBalloon, typeof Dialog, typeof Typing];
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ static get pluginName(): "EmojiPicker";
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ static get isOfficialPlugin(): true;
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ init(): Promise<void>;
49
+ /**
50
+ * @inheritDoc
51
+ */
52
+ destroy(): void;
53
+ /**
54
+ * Represents an active skin tone. Its value depends on the emoji UI plugin.
55
+ *
56
+ * Before opening the UI for the first time, the returned value is read from the editor configuration.
57
+ * Otherwise, it reflects the user's intention.
58
+ */
59
+ get skinTone(): SkinToneId;
60
+ /**
61
+ * Displays the balloon with the emoji picker.
62
+ *
63
+ * @param [searchValue=''] A default query used to filer the grid when opening the UI.
64
+ */
65
+ showUI(searchValue?: string): void;
66
+ /**
67
+ * Creates a button for toolbar and menu bar that will show the emoji dialog.
68
+ */
69
+ private _createButton;
70
+ /**
71
+ * Creates an instance of the `EmojiPickerView` class that represents an emoji balloon.
72
+ */
73
+ private _createEmojiPickerView;
74
+ /**
75
+ * Hides the balloon with the emoji picker.
76
+ */
77
+ private _hideUI;
78
+ /**
79
+ * Registers converters.
80
+ */
81
+ private _setupConversion;
82
+ /**
83
+ * Returns positioning options for the {@link #_balloonPlugin}. They control the way the balloon is attached
84
+ * to the target element or selection.
85
+ */
86
+ private _getBalloonPositionData;
87
+ /**
88
+ * Displays a fake visual selection when the contextual balloon is displayed.
89
+ *
90
+ * This adds an 'emoji-picker' marker into the document that is rendered as a highlight on selected text fragment.
91
+ */
92
+ private _showFakeVisualSelection;
93
+ /**
94
+ * Hides the fake visual selection.
95
+ */
96
+ private _hideFakeVisualSelection;
97
+ }
@@ -0,0 +1,255 @@
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
+ /**
6
+ * @module emoji/emojipicker
7
+ */
8
+ import { ButtonView, clickOutsideHandler, ContextualBalloon, Dialog, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
9
+ import { icons, Plugin } from 'ckeditor5/src/core.js';
10
+ import { Typing } from 'ckeditor5/src/typing.js';
11
+ import EmojiCommand from './emojicommand.js';
12
+ import EmojiRepository from './emojirepository.js';
13
+ import EmojiPickerView from './ui/emojipickerview.js';
14
+ import '../theme/emojipicker.css';
15
+ const VISUAL_SELECTION_MARKER_NAME = 'emoji-picker';
16
+ /**
17
+ * The emoji picker plugin.
18
+ *
19
+ * Introduces the `'emoji'` dropdown.
20
+ */
21
+ export default class EmojiPicker extends Plugin {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get requires() {
26
+ return [EmojiRepository, ContextualBalloon, Dialog, Typing];
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get pluginName() {
32
+ return 'EmojiPicker';
33
+ }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ static get isOfficialPlugin() {
38
+ return true;
39
+ }
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ async init() {
44
+ const editor = this.editor;
45
+ this._balloonPlugin = editor.plugins.get('ContextualBalloon');
46
+ this._emojiRepositoryPlugin = editor.plugins.get('EmojiRepository');
47
+ // Skip registering a button in the toolbar and list item in the menu bar if the emoji repository is not ready.
48
+ if (!await this._emojiRepositoryPlugin.isReady()) {
49
+ return;
50
+ }
51
+ const command = new EmojiCommand(editor);
52
+ editor.commands.add('emoji', command);
53
+ editor.ui.componentFactory.add('emoji', () => {
54
+ const button = this._createButton(ButtonView, command);
55
+ button.set({
56
+ tooltip: true
57
+ });
58
+ return button;
59
+ });
60
+ editor.ui.componentFactory.add('menuBar:emoji', () => {
61
+ return this._createButton(MenuBarMenuListItemButtonView, command);
62
+ });
63
+ this._setupConversion();
64
+ }
65
+ /**
66
+ * @inheritDoc
67
+ */
68
+ destroy() {
69
+ super.destroy();
70
+ if (this.emojiPickerView) {
71
+ this.emojiPickerView.destroy();
72
+ }
73
+ }
74
+ /**
75
+ * Represents an active skin tone. Its value depends on the emoji UI plugin.
76
+ *
77
+ * Before opening the UI for the first time, the returned value is read from the editor configuration.
78
+ * Otherwise, it reflects the user's intention.
79
+ */
80
+ get skinTone() {
81
+ if (!this.emojiPickerView) {
82
+ return this.editor.config.get('emoji.skinTone');
83
+ }
84
+ return this.emojiPickerView.gridView.skinTone;
85
+ }
86
+ /**
87
+ * Displays the balloon with the emoji picker.
88
+ *
89
+ * @param [searchValue=''] A default query used to filer the grid when opening the UI.
90
+ */
91
+ showUI(searchValue = '') {
92
+ // Show visual selection on a text when the contextual balloon is displayed.
93
+ // See #17654.
94
+ this._showFakeVisualSelection();
95
+ if (!this.emojiPickerView) {
96
+ this.emojiPickerView = this._createEmojiPickerView();
97
+ }
98
+ if (searchValue) {
99
+ this.emojiPickerView.searchView.setInputValue(searchValue);
100
+ }
101
+ this.emojiPickerView.searchView.search(searchValue);
102
+ if (!this._balloonPlugin.hasView(this.emojiPickerView)) {
103
+ this._balloonPlugin.add({
104
+ view: this.emojiPickerView,
105
+ position: this._getBalloonPositionData()
106
+ });
107
+ }
108
+ this.emojiPickerView.focus();
109
+ }
110
+ /**
111
+ * Creates a button for toolbar and menu bar that will show the emoji dialog.
112
+ */
113
+ _createButton(ViewClass, command) {
114
+ const buttonView = new ViewClass(this.editor.locale);
115
+ const t = this.editor.locale.t;
116
+ buttonView.bind('isEnabled').to(command, 'isEnabled');
117
+ buttonView.set({
118
+ label: t('Emoji'),
119
+ icon: icons.emoji,
120
+ isToggleable: true
121
+ });
122
+ buttonView.on('execute', () => {
123
+ this.showUI();
124
+ });
125
+ return buttonView;
126
+ }
127
+ /**
128
+ * Creates an instance of the `EmojiPickerView` class that represents an emoji balloon.
129
+ */
130
+ _createEmojiPickerView() {
131
+ const emojiPickerView = new EmojiPickerView(this.editor.locale, {
132
+ emojiCategories: this._emojiRepositoryPlugin.getEmojiCategories(),
133
+ skinTone: this.editor.config.get('emoji.skinTone'),
134
+ skinTones: this._emojiRepositoryPlugin.getSkinTones(),
135
+ getEmojiByQuery: (query) => {
136
+ return this._emojiRepositoryPlugin.getEmojiByQuery(query);
137
+ }
138
+ });
139
+ // Insert an emoji on a tile click.
140
+ this.listenTo(emojiPickerView.gridView, 'execute', (evt, data) => {
141
+ const editor = this.editor;
142
+ const textToInsert = data.emoji;
143
+ this._hideUI();
144
+ editor.execute('insertText', { text: textToInsert });
145
+ });
146
+ // Update the balloon position when layout is changed.
147
+ this.listenTo(emojiPickerView, 'update', () => {
148
+ if (this._balloonPlugin.visibleView === emojiPickerView) {
149
+ this._balloonPlugin.updatePosition();
150
+ }
151
+ });
152
+ // Close the panel on `Esc` key press when the **actions have focus**.
153
+ emojiPickerView.keystrokes.set('Esc', (data, cancel) => {
154
+ this._hideUI();
155
+ cancel();
156
+ });
157
+ // Close the dialog when clicking outside of it.
158
+ clickOutsideHandler({
159
+ emitter: emojiPickerView,
160
+ contextElements: [this._balloonPlugin.view.element],
161
+ callback: () => this._hideUI(),
162
+ activator: () => this._balloonPlugin.visibleView === emojiPickerView
163
+ });
164
+ return emojiPickerView;
165
+ }
166
+ /**
167
+ * Hides the balloon with the emoji picker.
168
+ */
169
+ _hideUI() {
170
+ this._balloonPlugin.remove(this.emojiPickerView);
171
+ this.emojiPickerView.searchView.setInputValue('');
172
+ this.editor.editing.view.focus();
173
+ this._hideFakeVisualSelection();
174
+ }
175
+ /**
176
+ * Registers converters.
177
+ */
178
+ _setupConversion() {
179
+ const editor = this.editor;
180
+ // Renders a fake visual selection marker on an expanded selection.
181
+ editor.conversion.for('editingDowncast').markerToHighlight({
182
+ model: VISUAL_SELECTION_MARKER_NAME,
183
+ view: {
184
+ classes: ['ck-fake-emoji-selection']
185
+ }
186
+ });
187
+ // Renders a fake visual selection marker on a collapsed selection.
188
+ editor.conversion.for('editingDowncast').markerToElement({
189
+ model: VISUAL_SELECTION_MARKER_NAME,
190
+ view: (data, { writer }) => {
191
+ if (!data.markerRange.isCollapsed) {
192
+ return null;
193
+ }
194
+ const markerElement = writer.createUIElement('span');
195
+ writer.addClass(['ck-fake-emoji-selection', 'ck-fake-emoji-selection_collapsed'], markerElement);
196
+ return markerElement;
197
+ }
198
+ });
199
+ }
200
+ /**
201
+ * Returns positioning options for the {@link #_balloonPlugin}. They control the way the balloon is attached
202
+ * to the target element or selection.
203
+ */
204
+ _getBalloonPositionData() {
205
+ const view = this.editor.editing.view;
206
+ const viewDocument = view.document;
207
+ // Set a target position by converting view selection range to DOM.
208
+ const target = () => view.domConverter.viewRangeToDom(viewDocument.selection.getFirstRange());
209
+ return {
210
+ target
211
+ };
212
+ }
213
+ /**
214
+ * Displays a fake visual selection when the contextual balloon is displayed.
215
+ *
216
+ * This adds an 'emoji-picker' marker into the document that is rendered as a highlight on selected text fragment.
217
+ */
218
+ _showFakeVisualSelection() {
219
+ const model = this.editor.model;
220
+ model.change(writer => {
221
+ const range = model.document.selection.getFirstRange();
222
+ if (model.markers.has(VISUAL_SELECTION_MARKER_NAME)) {
223
+ writer.updateMarker(VISUAL_SELECTION_MARKER_NAME, { range });
224
+ }
225
+ else {
226
+ if (range.start.isAtEnd) {
227
+ const startPosition = range.start.getLastMatchingPosition(({ item }) => !model.schema.isContent(item), { boundaries: range });
228
+ writer.addMarker(VISUAL_SELECTION_MARKER_NAME, {
229
+ usingOperation: false,
230
+ affectsData: false,
231
+ range: writer.createRange(startPosition, range.end)
232
+ });
233
+ }
234
+ else {
235
+ writer.addMarker(VISUAL_SELECTION_MARKER_NAME, {
236
+ usingOperation: false,
237
+ affectsData: false,
238
+ range
239
+ });
240
+ }
241
+ }
242
+ });
243
+ }
244
+ /**
245
+ * Hides the fake visual selection.
246
+ */
247
+ _hideFakeVisualSelection() {
248
+ const model = this.editor.model;
249
+ if (model.markers.has(VISUAL_SELECTION_MARKER_NAME)) {
250
+ model.change(writer => {
251
+ writer.removeMarker(VISUAL_SELECTION_MARKER_NAME);
252
+ });
253
+ }
254
+ }
255
+ }
@@ -0,0 +1,139 @@
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, type Editor } from 'ckeditor5/src/core.js';
6
+ import type { SkinToneId } from './emojiconfig.js';
7
+ /**
8
+ * The emoji repository plugin.
9
+ *
10
+ * Loads the emoji database from URL during plugin initialization and provides utility methods to search it.
11
+ */
12
+ export default class EmojiRepository extends Plugin {
13
+ /**
14
+ * Emoji database.
15
+ */
16
+ private _database;
17
+ /**
18
+ * A promise resolved after downloading the emoji database.
19
+ * The promise resolves with `true` when the database is successfully downloaded or `false` otherwise.
20
+ */
21
+ private _databasePromise;
22
+ /**
23
+ * A callback to resolve the {@link #_databasePromise} to control the return value of this promise.
24
+ */
25
+ private _databasePromiseResolveCallback;
26
+ /**
27
+ * An instance of the [Fuse.js](https://www.fusejs.io/) library.
28
+ */
29
+ private _fuseSearch;
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get pluginName(): "EmojiRepository";
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ static get isOfficialPlugin(): true;
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ constructor(editor: Editor);
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ init(): Promise<void>;
46
+ /**
47
+ * Returns an array of emoji entries that match the search query.
48
+ * If the emoji database is not loaded, the [Fuse.js](https://www.fusejs.io/) instance is not created,
49
+ * hence this method returns an empty array.
50
+ *
51
+ * @param searchQuery A search query to match emoji.
52
+ * @returns An array of emoji entries that match the search query.
53
+ */
54
+ getEmojiByQuery(searchQuery: string): Array<EmojiEntry>;
55
+ /**
56
+ * Groups all emojis by categories.
57
+ * If the emoji database is not loaded, it returns an empty array.
58
+ *
59
+ * @returns An array of emoji entries grouped by categories.
60
+ */
61
+ getEmojiCategories(): Array<EmojiCategory>;
62
+ /**
63
+ * Returns an array of available skin tones.
64
+ */
65
+ getSkinTones(): Array<SkinTone>;
66
+ /**
67
+ * Indicates whether the emoji database has been successfully downloaded and the plugin is operational.
68
+ */
69
+ isReady(): Promise<boolean>;
70
+ /**
71
+ * A function used to check if the given emoji is supported in the operating system.
72
+ *
73
+ * Referenced for unit testing purposes.
74
+ */
75
+ private static _isEmojiSupported;
76
+ }
77
+ /**
78
+ * Represents a single group of the emoji category, e.g., "Smileys & Expressions".
79
+ */
80
+ export type EmojiCategory = {
81
+ /**
82
+ * A name of the category.
83
+ */
84
+ title: string;
85
+ /**
86
+ * An example emoji representing items belonging to the category.
87
+ */
88
+ icon: string;
89
+ /**
90
+ * Group id used to assign {@link #items}.
91
+ */
92
+ groupId: number;
93
+ /**
94
+ * An array of emojis.
95
+ */
96
+ items: Array<EmojiEntry>;
97
+ };
98
+ /**
99
+ * Represents a single item fetched from the CDN.
100
+ */
101
+ export type EmojiCdnResource = {
102
+ annotation: string;
103
+ emoji: string;
104
+ group: number;
105
+ order: number;
106
+ version: number;
107
+ emoticon?: string;
108
+ shortcodes?: Array<string>;
109
+ skins?: Array<{
110
+ emoji: string;
111
+ tone: number;
112
+ version: number;
113
+ }>;
114
+ tags?: Array<string>;
115
+ };
116
+ /**
117
+ * Represents a single emoji item used by the emoji feature.
118
+ */
119
+ export type EmojiEntry = Omit<EmojiCdnResource, 'skins'> & {
120
+ skins: EmojiMap;
121
+ };
122
+ /**
123
+ * Represents mapping between a skin tone and its corresponding emoji.
124
+ *
125
+ * The `default` key is always present. Additional values are assigned only if an emoji supports skin tones.
126
+ */
127
+ export type EmojiMap = {
128
+ [K in Exclude<SkinToneId, 'default'>]?: string;
129
+ } & {
130
+ default: string;
131
+ };
132
+ /**
133
+ * Represents an emoji skin tone variant.
134
+ */
135
+ export type SkinTone = {
136
+ id: SkinToneId;
137
+ icon: string;
138
+ tooltip: string;
139
+ };