@ckeditor/ckeditor5-emoji 49.1.0-alpha.1 → 49.1.0-alpha.2

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 (90) hide show
  1. package/dist/emojiconfig.d.ts +31 -0
  2. package/dist/emojirepository.d.ts +37 -4
  3. package/dist/emojiutils.d.ts +5 -5
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +81 -19
  6. package/dist/index.js.map +1 -1
  7. package/dist/translations/ar.js +1 -1
  8. package/dist/translations/ar.umd.js +1 -1
  9. package/dist/translations/bg.js +1 -1
  10. package/dist/translations/bg.umd.js +1 -1
  11. package/dist/translations/bn.js +1 -1
  12. package/dist/translations/bn.umd.js +1 -1
  13. package/dist/translations/ca.js +1 -1
  14. package/dist/translations/ca.umd.js +1 -1
  15. package/dist/translations/cs.js +1 -1
  16. package/dist/translations/cs.umd.js +1 -1
  17. package/dist/translations/da.js +1 -1
  18. package/dist/translations/da.umd.js +1 -1
  19. package/dist/translations/de.js +1 -1
  20. package/dist/translations/de.umd.js +1 -1
  21. package/dist/translations/el.js +1 -1
  22. package/dist/translations/el.umd.js +1 -1
  23. package/dist/translations/en-au.js +1 -1
  24. package/dist/translations/en-au.umd.js +1 -1
  25. package/dist/translations/en-gb.js +1 -1
  26. package/dist/translations/en-gb.umd.js +1 -1
  27. package/dist/translations/en.js +1 -1
  28. package/dist/translations/en.umd.js +1 -1
  29. package/dist/translations/es.js +1 -1
  30. package/dist/translations/es.umd.js +1 -1
  31. package/dist/translations/et.js +1 -1
  32. package/dist/translations/et.umd.js +1 -1
  33. package/dist/translations/fi.js +1 -1
  34. package/dist/translations/fi.umd.js +1 -1
  35. package/dist/translations/fr.js +1 -1
  36. package/dist/translations/fr.umd.js +1 -1
  37. package/dist/translations/he.js +1 -1
  38. package/dist/translations/he.umd.js +1 -1
  39. package/dist/translations/hi.js +1 -1
  40. package/dist/translations/hi.umd.js +1 -1
  41. package/dist/translations/hu.js +1 -1
  42. package/dist/translations/hu.umd.js +1 -1
  43. package/dist/translations/id.js +1 -1
  44. package/dist/translations/id.umd.js +1 -1
  45. package/dist/translations/it.js +1 -1
  46. package/dist/translations/it.umd.js +1 -1
  47. package/dist/translations/ja.js +1 -1
  48. package/dist/translations/ja.umd.js +1 -1
  49. package/dist/translations/ko.js +1 -1
  50. package/dist/translations/ko.umd.js +1 -1
  51. package/dist/translations/lt.js +1 -1
  52. package/dist/translations/lt.umd.js +1 -1
  53. package/dist/translations/lv.js +1 -1
  54. package/dist/translations/lv.umd.js +1 -1
  55. package/dist/translations/ms.js +1 -1
  56. package/dist/translations/ms.umd.js +1 -1
  57. package/dist/translations/nl.js +1 -1
  58. package/dist/translations/nl.umd.js +1 -1
  59. package/dist/translations/no.js +1 -1
  60. package/dist/translations/no.umd.js +1 -1
  61. package/dist/translations/pl.js +1 -1
  62. package/dist/translations/pl.umd.js +1 -1
  63. package/dist/translations/pt-br.js +1 -1
  64. package/dist/translations/pt-br.umd.js +1 -1
  65. package/dist/translations/pt.js +1 -1
  66. package/dist/translations/pt.umd.js +1 -1
  67. package/dist/translations/ro.js +1 -1
  68. package/dist/translations/ro.umd.js +1 -1
  69. package/dist/translations/ru.js +1 -1
  70. package/dist/translations/ru.umd.js +1 -1
  71. package/dist/translations/sk.js +1 -1
  72. package/dist/translations/sk.umd.js +1 -1
  73. package/dist/translations/sr.js +1 -1
  74. package/dist/translations/sr.umd.js +1 -1
  75. package/dist/translations/sv.js +1 -1
  76. package/dist/translations/sv.umd.js +1 -1
  77. package/dist/translations/th.js +1 -1
  78. package/dist/translations/th.umd.js +1 -1
  79. package/dist/translations/tr.js +1 -1
  80. package/dist/translations/tr.umd.js +1 -1
  81. package/dist/translations/uk.js +1 -1
  82. package/dist/translations/uk.umd.js +1 -1
  83. package/dist/translations/vi.js +1 -1
  84. package/dist/translations/vi.umd.js +1 -1
  85. package/dist/translations/zh-cn.js +1 -1
  86. package/dist/translations/zh-cn.umd.js +1 -1
  87. package/dist/translations/zh.js +1 -1
  88. package/dist/translations/zh.umd.js +1 -1
  89. package/dist/utils/emojirepositorycache.d.ts +2 -2
  90. package/package.json +7 -7
@@ -5,6 +5,7 @@
5
5
  /**
6
6
  * @module emoji/emojiconfig
7
7
  */
8
+ import type { EmojiDefinition } from "./emojirepository.js";
8
9
  /**
9
10
  * The configuration of the Emoji feature.
10
11
  *
@@ -72,9 +73,38 @@ export interface EmojiConfig {
72
73
  * .then( ... )
73
74
  * .catch( ... );
74
75
  * ```
76
+ *
77
+ * If the {@link module:emoji/emojiconfig~EmojiConfig#definitions `emoji.definitions`}
78
+ * option is provided, `definitionsUrl` is ignored as the passed definitions take precedence over the URL.
75
79
  */
76
80
  definitionsUrl?: string;
77
81
  /**
82
+ * The emoji definitions to use instead of downloading them from URL.
83
+ *
84
+ * Use this option to bundle the emoji database with your application, for example, when the
85
+ * {@glink getting-started/setup/csp Content Security Policy} of the page does not allow
86
+ * downloading it. The definitions must have the same structure as the database hosted on the CKEditor 5 CDN.
87
+ *
88
+ * ```ts
89
+ * import definitions from './emoji/en.json';
90
+ *
91
+ * ClassicEditor
92
+ * .create( {
93
+ * plugins: [ Emoji, ... ],
94
+ * emoji: {
95
+ * definitions
96
+ * }
97
+ * } )
98
+ * .then( ... )
99
+ * .catch( ... );
100
+ * ```
101
+ *
102
+ * If this option is provided, it takes precedence over the
103
+ * {@link module:emoji/emojiconfig~EmojiConfig#definitionsUrl `emoji.definitionsUrl`} and
104
+ * {@link module:emoji/emojiconfig~EmojiConfig#version `emoji.version`} options, which are ignored.
105
+ */
106
+ definitions?: Array<EmojiDefinition>;
107
+ /**
78
108
  * The emoji database version.
79
109
  *
80
110
  * ```ts
@@ -91,6 +121,7 @@ export interface EmojiConfig {
91
121
  *
92
122
  * If the {@link module:emoji/emojiconfig~EmojiConfig#definitionsUrl `emoji.definitionsUrl`}
93
123
  * option is provided, `version` is ignored as the defined URL takes precedence over the `version`.
124
+ * The same applies to the {@link module:emoji/emojiconfig~EmojiConfig#definitions `emoji.definitions`} option.
94
125
  */
95
126
  version?: EmojiVersion;
96
127
  /**
@@ -8,7 +8,9 @@ import type { EmojiSkinToneId } from "./emojiconfig.js";
8
8
  /**
9
9
  * The emoji repository plugin.
10
10
  *
11
- * Loads the emoji repository from URL during plugin initialization and provides utility methods to search it.
11
+ * Loads the emoji repository during plugin initialization and provides utility methods to search it.
12
+ * The repository comes from the {@link module:emoji/emojiconfig~EmojiConfig#definitions `emoji.definitions`}
13
+ * configuration option, if provided. Otherwise, it is downloaded from URL.
12
14
  */
13
15
  export declare class EmojiRepository extends Plugin {
14
16
  /**
@@ -21,9 +23,24 @@ export declare class EmojiRepository extends Plugin {
21
23
  isRepositoryReady: boolean | null;
22
24
  /**
23
25
  * The resolved URL from which the emoji repository is downloaded.
26
+ *
27
+ * It is `null` when the emoji definitions are passed in the configuration.
24
28
  */
25
29
  private readonly _url;
26
30
  /**
31
+ * The emoji definitions passed in the configuration.
32
+ *
33
+ * It is `null` when the emoji definitions are downloaded from URL.
34
+ */
35
+ private readonly _definitions;
36
+ /**
37
+ * The normalized emoji definitions passed in the configuration.
38
+ *
39
+ * They are stored per editor instance instead of the process-global cache, because each editor
40
+ * can be configured with its own set of definitions.
41
+ */
42
+ private _definitionsItems;
43
+ /**
27
44
  * @inheritDoc
28
45
  */
29
46
  static get requires(): PluginDependenciesOf<[EmojiUtils]>;
@@ -94,6 +111,14 @@ export declare class EmojiRepository extends Plugin {
94
111
  */
95
112
  private _getItems;
96
113
  /**
114
+ * Updates the {@link #isRepositoryReady} flag once the repository finishes loading.
115
+ */
116
+ private _onRepositoryLoaded;
117
+ /**
118
+ * Warns about the options that are ignored because the emoji definitions are passed in the configuration.
119
+ */
120
+ private _warnAboutRedundantOptions;
121
+ /**
97
122
  * Normalizes the raw data fetched from CDN. By normalization, we meant:
98
123
  *
99
124
  * * Filter out unsupported emoji (these that will not render correctly),
@@ -131,9 +156,11 @@ export type EmojiCategory = {
131
156
  items: Array<EmojiEntry>;
132
157
  };
133
158
  /**
134
- * Represents a single item fetched from the CDN.
159
+ * Represents a single emoji definition, as stored in the emoji database. The database is either downloaded
160
+ * from {@link module:emoji/emojiconfig~EmojiConfig#definitionsUrl `emoji.definitionsUrl`} or passed directly
161
+ * in {@link module:emoji/emojiconfig~EmojiConfig#definitions `emoji.definitions`}.
135
162
  */
136
- export type EmojiCdnResource = {
163
+ export type EmojiDefinition = {
137
164
  annotation: string;
138
165
  emoji: string;
139
166
  group: number;
@@ -149,9 +176,15 @@ export type EmojiCdnResource = {
149
176
  tags?: Array<string>;
150
177
  };
151
178
  /**
179
+ * Represents a single item fetched from the CDN.
180
+ *
181
+ * @deprecated Use {@link module:emoji/emojirepository~EmojiDefinition `EmojiDefinition`} instead.
182
+ */
183
+ export type EmojiCdnResource = EmojiDefinition;
184
+ /**
152
185
  * Represents a single emoji item used by the Emoji feature.
153
186
  */
154
- export type EmojiEntry = Omit<EmojiCdnResource, "skins"> & {
187
+ export type EmojiEntry = Omit<EmojiDefinition, "skins"> & {
155
188
  skins: EmojiMap;
156
189
  };
157
190
  /**
@@ -6,7 +6,7 @@
6
6
  * @module emoji/emojiutils
7
7
  */
8
8
  import { Plugin } from "@ckeditor/ckeditor5-core";
9
- import type { EmojiCdnResource, EmojiEntry } from "./emojirepository.js";
9
+ import type { EmojiDefinition, EmojiEntry } from "./emojirepository.js";
10
10
  /**
11
11
  * The Emoji utilities plugin.
12
12
  */
@@ -31,7 +31,7 @@ export declare class EmojiUtils extends Plugin {
31
31
  * Checks if the emoji is supported by verifying the emoji version supported by the system first.
32
32
  * Then checks if emoji contains a zero width joiner (ZWJ), and if yes, then checks if it is supported by the system.
33
33
  */
34
- isEmojiSupported(item: EmojiCdnResource, emojiSupportedVersionByOs: number, container: HTMLDivElement): boolean;
34
+ isEmojiSupported(item: EmojiDefinition, emojiSupportedVersionByOs: number, container: HTMLDivElement): boolean;
35
35
  /**
36
36
  * Checks the supported emoji version by the OS, by sampling some representatives from different emoji releases.
37
37
  */
@@ -43,7 +43,7 @@ export declare class EmojiUtils extends Plugin {
43
43
  /**
44
44
  * Checks whether the emoji is supported in the operating system.
45
45
  */
46
- isEmojiZwjSupported(item: EmojiCdnResource, container: HTMLDivElement): boolean;
46
+ isEmojiZwjSupported(item: EmojiDefinition, container: HTMLDivElement): boolean;
47
47
  /**
48
48
  * Returns the width of the provided node.
49
49
  */
@@ -61,11 +61,11 @@ export declare class EmojiUtils extends Plugin {
61
61
  /**
62
62
  * Adds default skin tone property to each emoji. If emoji defines other skin tones, they are added as well.
63
63
  */
64
- normalizeEmojiSkinTone(item: EmojiCdnResource): EmojiEntry;
64
+ normalizeEmojiSkinTone(item: EmojiDefinition): EmojiEntry;
65
65
  /**
66
66
  * Checks whether the emoji belongs to a group that is allowed.
67
67
  */
68
- isEmojiCategoryAllowed(item: EmojiCdnResource): boolean;
68
+ isEmojiCategoryAllowed(item: EmojiDefinition): boolean;
69
69
  /**
70
70
  * A function used to determine if emoji is supported by detecting pixels.
71
71
  *
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  export { Emoji } from "./emoji.js";
9
9
  export { EmojiMention } from "./emojimention.js";
10
10
  export { EmojiPicker } from "./emojipicker.js";
11
- export { EmojiRepository, type EmojiCategory, type EmojiCdnResource, type EmojiEntry, type EmojiMap, type EmojiSkinTone } from "./emojirepository.js";
11
+ export { EmojiRepository, type EmojiCategory, type EmojiCdnResource, type EmojiDefinition, type EmojiEntry, type EmojiMap, type EmojiSkinTone } from "./emojirepository.js";
12
12
  export { EmojiUtils } from "./emojiutils.js";
13
13
  export { EmojiCommand } from "./emojicommand.js";
14
14
  export type { EmojiConfig, EmojiSkinToneId, EmojiVersion } from "./emojiconfig.js";
package/dist/index.js CHANGED
@@ -308,14 +308,31 @@ const DEFAULT_EMOJI_VERSION = 16;
308
308
  /**
309
309
  * The emoji repository plugin.
310
310
  *
311
- * Loads the emoji repository from URL during plugin initialization and provides utility methods to search it.
311
+ * Loads the emoji repository during plugin initialization and provides utility methods to search it.
312
+ * The repository comes from the {@link module:emoji/emojiconfig~EmojiConfig#definitions `emoji.definitions`}
313
+ * configuration option, if provided. Otherwise, it is downloaded from URL.
312
314
  */
313
315
  var EmojiRepository = class EmojiRepository extends Plugin {
314
316
  /**
315
317
  * The resolved URL from which the emoji repository is downloaded.
318
+ *
319
+ * It is `null` when the emoji definitions are passed in the configuration.
316
320
  */
317
321
  _url;
318
322
  /**
323
+ * The emoji definitions passed in the configuration.
324
+ *
325
+ * It is `null` when the emoji definitions are downloaded from URL.
326
+ */
327
+ _definitions;
328
+ /**
329
+ * The normalized emoji definitions passed in the configuration.
330
+ *
331
+ * They are stored per editor instance instead of the process-global cache, because each editor
332
+ * can be configured with its own set of definitions.
333
+ */
334
+ _definitionsItems = null;
335
+ /**
319
336
  * @inheritDoc
320
337
  */
321
338
  static get requires() {
@@ -342,35 +359,38 @@ var EmojiRepository = class EmojiRepository extends Plugin {
342
359
  version: void 0,
343
360
  skinTone: "default",
344
361
  definitionsUrl: void 0,
362
+ definitions: void 0,
345
363
  useCustomFont: false
346
364
  });
347
365
  this.set("isRepositoryReady", null);
348
- this._url = this._getUrl();
366
+ const definitions = editor.config.get("emoji.definitions");
367
+ if (definitions) {
368
+ this._definitions = definitions;
369
+ this._url = null;
370
+ this._warnAboutRedundantOptions();
371
+ } else {
372
+ this._definitions = null;
373
+ this._url = this._getUrl();
374
+ }
349
375
  }
350
376
  /**
351
377
  * @inheritDoc
352
378
  */
353
379
  init() {
380
+ if (this._definitions) {
381
+ const definitions = this._definitions;
382
+ Promise.resolve().then(() => this._normalizeEmoji(definitions)).catch(() => []).then((items) => {
383
+ this._definitionsItems = items;
384
+ this._onRepositoryLoaded();
385
+ });
386
+ return;
387
+ }
354
388
  this._warnAboutCdnUse();
355
389
  EmojiRepository._cache.fetch({
356
390
  url: this._url.toString(),
357
391
  cacheKeys: this._cacheKeys,
358
392
  transform: (raw) => this._normalizeEmoji(raw)
359
- }).then(() => {
360
- if (this.editor.state === "destroyed") return;
361
- const ready = !!this._getItems();
362
- if (!ready)
363
- /**
364
- * Unable to identify the available emoji to display.
365
- *
366
- * See the {@glink features/emoji#troubleshooting troubleshooting} section in
367
- * the {@glink features/emoji Emoji feature} guide for more details.
368
- *
369
- * @error emoji-repository-empty
370
- */
371
- logWarning("emoji-repository-empty");
372
- this.isRepositoryReady = ready;
373
- });
393
+ }).then(() => this._onRepositoryLoaded());
374
394
  }
375
395
  /**
376
396
  * Calls `callback` once the repository finishes loading, passing the result as the argument.
@@ -474,7 +494,7 @@ var EmojiRepository = class EmojiRepository extends Plugin {
474
494
  return categories.map((category) => {
475
495
  return {
476
496
  ...category,
477
- items: groups[category.groupId]
497
+ items: groups[category.groupId] || []
478
498
  };
479
499
  });
480
500
  }
@@ -588,13 +608,50 @@ var EmojiRepository = class EmojiRepository extends Plugin {
588
608
  * a non-empty array, or `null` otherwise.
589
609
  */
590
610
  _getItems() {
591
- const repository = EmojiRepository._cache.getSync({
611
+ const repository = this._definitions ? this._definitionsItems : EmojiRepository._cache.getSync({
592
612
  url: this._url.toString(),
593
613
  cacheKeys: this._cacheKeys
594
614
  });
595
615
  return repository && repository.length ? repository : null;
596
616
  }
597
617
  /**
618
+ * Updates the {@link #isRepositoryReady} flag once the repository finishes loading.
619
+ */
620
+ _onRepositoryLoaded() {
621
+ if (this.editor.state === "destroyed") return;
622
+ const ready = !!this._getItems();
623
+ if (!ready)
624
+ /**
625
+ * Unable to identify the available emoji to display.
626
+ *
627
+ * See the {@glink features/emoji#troubleshooting troubleshooting} section in
628
+ * the {@glink features/emoji Emoji feature} guide for more details.
629
+ *
630
+ * @error emoji-repository-empty
631
+ */
632
+ logWarning("emoji-repository-empty");
633
+ this.isRepositoryReady = ready;
634
+ }
635
+ /**
636
+ * Warns about the options that are ignored because the emoji definitions are passed in the configuration.
637
+ */
638
+ _warnAboutRedundantOptions() {
639
+ const definitionsUrl = this.editor.config.get("emoji.definitionsUrl");
640
+ const version = this.editor.config.get("emoji.version");
641
+ if (definitionsUrl && definitionsUrl !== "cdn" || version)
642
+ /**
643
+ * The {@link module:emoji/emojiconfig~EmojiConfig#definitions `emoji.definitions`} configuration option is set
644
+ * together with other options that point to the emoji database: {@link module:emoji/emojiconfig~EmojiConfig#definitionsUrl
645
+ * `emoji.definitionsUrl`} or {@link module:emoji/emojiconfig~EmojiConfig#version `emoji.version`}.
646
+ * Only the `emoji.definitions` option will be used.
647
+ *
648
+ * The other options will be ignored and should be removed from the configuration.
649
+ *
650
+ * @error emoji-repository-redundant-options
651
+ */
652
+ logWarning("emoji-repository-redundant-options");
653
+ }
654
+ /**
598
655
  * Normalizes the raw data fetched from CDN. By normalization, we meant:
599
656
  *
600
657
  * * Filter out unsupported emoji (these that will not render correctly),
@@ -1533,6 +1590,11 @@ var EmojiPickerView = class extends View {
1533
1590
  secondaryText: t("The query must contain at least two characters."),
1534
1591
  isVisible: true
1535
1592
  });
1593
+ else if (!data.query && !data.resultsCount) this.infoView.set({
1594
+ primaryText: t("There are no emojis in this category."),
1595
+ secondaryText: "",
1596
+ isVisible: true
1597
+ });
1536
1598
  else if (!data.resultsCount) this.infoView.set({
1537
1599
  primaryText: t("No emojis were found matching \"%0\".", data.query),
1538
1600
  secondaryText: t("Please try a different phrase or check the spelling."),