@ckeditor/ckeditor5-emoji 44.2.0-alpha.14 → 44.2.0-alpha.16
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.
- package/build/emoji.js +1 -1
- package/dist/index.js +79 -20
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/emojiconfig.d.ts +18 -1
- package/src/emojirepository.d.ts +16 -4
- package/src/emojirepository.js +82 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-emoji",
|
|
3
|
-
"version": "44.2.0-alpha.
|
|
3
|
+
"version": "44.2.0-alpha.16",
|
|
4
4
|
"description": "Emoji feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ckeditor/ckeditor5-core": "44.2.0-alpha.
|
|
17
|
-
"@ckeditor/ckeditor5-mention": "44.2.0-alpha.
|
|
18
|
-
"@ckeditor/ckeditor5-typing": "44.2.0-alpha.
|
|
19
|
-
"@ckeditor/ckeditor5-ui": "44.2.0-alpha.
|
|
20
|
-
"@ckeditor/ckeditor5-utils": "44.2.0-alpha.
|
|
21
|
-
"ckeditor5": "44.2.0-alpha.
|
|
16
|
+
"@ckeditor/ckeditor5-core": "44.2.0-alpha.16",
|
|
17
|
+
"@ckeditor/ckeditor5-mention": "44.2.0-alpha.16",
|
|
18
|
+
"@ckeditor/ckeditor5-typing": "44.2.0-alpha.16",
|
|
19
|
+
"@ckeditor/ckeditor5-ui": "44.2.0-alpha.16",
|
|
20
|
+
"@ckeditor/ckeditor5-utils": "44.2.0-alpha.16",
|
|
21
|
+
"ckeditor5": "44.2.0-alpha.16",
|
|
22
22
|
"fuse.js": "7.0.0",
|
|
23
23
|
"lodash-es": "4.17.21"
|
|
24
24
|
},
|
package/src/emojiconfig.d.ts
CHANGED
|
@@ -58,6 +58,22 @@ export interface EmojiConfig {
|
|
|
58
58
|
* @default 'default'
|
|
59
59
|
*/
|
|
60
60
|
skinTone?: SkinToneId;
|
|
61
|
+
/**
|
|
62
|
+
* The URL from which the emoji definitions should be loaded.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* ClassicEditor
|
|
66
|
+
* .create( editorElement, {
|
|
67
|
+
* plugins: [ Emoji, ... ],
|
|
68
|
+
* emoji: {
|
|
69
|
+
* definitionsUrl: ''
|
|
70
|
+
* }
|
|
71
|
+
* } )
|
|
72
|
+
* .then( ... )
|
|
73
|
+
* .catch( ... );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
definitionsUrl?: string;
|
|
61
77
|
/**
|
|
62
78
|
* The emoji database version.
|
|
63
79
|
*
|
|
@@ -73,7 +89,8 @@ export interface EmojiConfig {
|
|
|
73
89
|
* .catch( ... );
|
|
74
90
|
* ```
|
|
75
91
|
*
|
|
76
|
-
* @
|
|
92
|
+
* If the {@link module:emoji/emojiconfig~EmojiConfig#definitionsUrl `emoji.definitionsUrl`}
|
|
93
|
+
* option is provided, `version` is ignored as the defined URL takes precedence over the `version`.
|
|
77
94
|
*/
|
|
78
95
|
version?: EmojiVersion;
|
|
79
96
|
}
|
package/src/emojirepository.d.ts
CHANGED
|
@@ -20,9 +20,9 @@ export default class EmojiRepository extends Plugin {
|
|
|
20
20
|
*/
|
|
21
21
|
private _fuseSearch;
|
|
22
22
|
/**
|
|
23
|
-
* The
|
|
23
|
+
* The resolved URL from which the emoji repository is downloaded.
|
|
24
24
|
*/
|
|
25
|
-
private readonly
|
|
25
|
+
private readonly _url;
|
|
26
26
|
/**
|
|
27
27
|
* A promise resolved after downloading the emoji collection.
|
|
28
28
|
* The promise resolves with `true` when the repository is successfully downloaded or `false` otherwise.
|
|
@@ -72,14 +72,26 @@ export default class EmojiRepository extends Plugin {
|
|
|
72
72
|
* Indicates whether the emoji repository has been successfully downloaded and the plugin is operational.
|
|
73
73
|
*/
|
|
74
74
|
isReady(): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the URL from which the emoji repository is downloaded. If the URL is not provided
|
|
77
|
+
* in the configuration, the default URL is used with the version from the configuration.
|
|
78
|
+
*
|
|
79
|
+
* If both the URL and version are provided, a warning is logged.
|
|
80
|
+
*/
|
|
81
|
+
private _getUrl;
|
|
82
|
+
/**
|
|
83
|
+
* Warn users on self-hosted installations that this plugin uses a CDN to fetch the emoji repository.
|
|
84
|
+
*/
|
|
85
|
+
private _warnAboutCdnUse;
|
|
75
86
|
/**
|
|
76
87
|
* Returns the emoji repository in a configured version if it is a non-empty array. Returns `null` otherwise.
|
|
77
88
|
*/
|
|
78
89
|
private _getItems;
|
|
79
90
|
/**
|
|
80
|
-
*
|
|
91
|
+
* Loads the emoji repository. If the repository is already loaded, it returns the cached result.
|
|
92
|
+
* Otherwise, it fetches the repository from the URL and adds it to the cache.
|
|
81
93
|
*/
|
|
82
|
-
private
|
|
94
|
+
private _loadAndCacheEmoji;
|
|
83
95
|
/**
|
|
84
96
|
* Normalizes the raw data fetched from CDN. By normalization, we meant:
|
|
85
97
|
*
|
package/src/emojirepository.js
CHANGED
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
import Fuse from 'fuse.js';
|
|
9
9
|
import { groupBy } from 'lodash-es';
|
|
10
10
|
import { Plugin } from 'ckeditor5/src/core.js';
|
|
11
|
-
import { logWarning, version } from 'ckeditor5/src/utils.js';
|
|
11
|
+
import { logWarning, version as editorVersion } from 'ckeditor5/src/utils.js';
|
|
12
12
|
import EmojiUtils from './emojiutils.js';
|
|
13
13
|
// An endpoint from which the emoji data will be downloaded during plugin initialization.
|
|
14
14
|
// The `{version}` placeholder is replaced with the value from editor config.
|
|
15
|
-
const
|
|
15
|
+
const DEFAULT_EMOJI_DATABASE_URL = 'https://cdn.ckeditor.com/ckeditor5/data/emoji/{version}/en.json';
|
|
16
|
+
const DEFAULT_EMOJI_VERSION = 16;
|
|
16
17
|
/**
|
|
17
18
|
* The emoji repository plugin.
|
|
18
19
|
*
|
|
@@ -43,10 +44,11 @@ class EmojiRepository extends Plugin {
|
|
|
43
44
|
constructor(editor) {
|
|
44
45
|
super(editor);
|
|
45
46
|
editor.config.define('emoji', {
|
|
46
|
-
version:
|
|
47
|
-
skinTone: 'default'
|
|
47
|
+
version: undefined,
|
|
48
|
+
skinTone: 'default',
|
|
49
|
+
definitionsUrl: undefined
|
|
48
50
|
});
|
|
49
|
-
this.
|
|
51
|
+
this._url = this._getUrl();
|
|
50
52
|
this._repositoryPromise = new Promise(resolve => {
|
|
51
53
|
this._repositoryPromiseResolveCallback = resolve;
|
|
52
54
|
});
|
|
@@ -56,10 +58,8 @@ class EmojiRepository extends Plugin {
|
|
|
56
58
|
* @inheritDoc
|
|
57
59
|
*/
|
|
58
60
|
async init() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
EmojiRepository._results[this._version] = this._normalizeEmoji(cdnResult);
|
|
62
|
-
}
|
|
61
|
+
this._warnAboutCdnUse();
|
|
62
|
+
await this._loadAndCacheEmoji();
|
|
63
63
|
const items = this._getItems();
|
|
64
64
|
// Skip plugin initialization if the emoji repository is not available.
|
|
65
65
|
// The initialization of other dependent plugins, such as `EmojiMention` and `EmojiPicker`, is prevented as well.
|
|
@@ -164,20 +164,83 @@ class EmojiRepository extends Plugin {
|
|
|
164
164
|
isReady() {
|
|
165
165
|
return this._repositoryPromise;
|
|
166
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns the URL from which the emoji repository is downloaded. If the URL is not provided
|
|
169
|
+
* in the configuration, the default URL is used with the version from the configuration.
|
|
170
|
+
*
|
|
171
|
+
* If both the URL and version are provided, a warning is logged.
|
|
172
|
+
*/
|
|
173
|
+
_getUrl() {
|
|
174
|
+
const { definitionsUrl, version } = this.editor.config.get('emoji');
|
|
175
|
+
if (!definitionsUrl || definitionsUrl === 'cdn') {
|
|
176
|
+
// URL was not provided or is set to 'cdn', so we use the default CDN URL.
|
|
177
|
+
const urlVersion = version || DEFAULT_EMOJI_VERSION;
|
|
178
|
+
const url = new URL(DEFAULT_EMOJI_DATABASE_URL.replace('{version}', urlVersion.toString()));
|
|
179
|
+
url.searchParams.set('editorVersion', editorVersion);
|
|
180
|
+
return url;
|
|
181
|
+
}
|
|
182
|
+
if (version) {
|
|
183
|
+
/**
|
|
184
|
+
* Both {@link module:emoji/emojiconfig~EmojiConfig#definitionsUrl `emoji.definitionsUrl`} and
|
|
185
|
+
* {@link module:emoji/emojiconfig~EmojiConfig#version `emoji.version`} configuration options
|
|
186
|
+
* are set. Only the `emoji.definitionsUrl` option will be used.
|
|
187
|
+
*
|
|
188
|
+
* The `emoji.version` option will be ignored and should be removed from the configuration.
|
|
189
|
+
*
|
|
190
|
+
* @error emoji-repository-redundant-version
|
|
191
|
+
*/
|
|
192
|
+
logWarning('emoji-repository-redundant-version');
|
|
193
|
+
}
|
|
194
|
+
return new URL(definitionsUrl);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Warn users on self-hosted installations that this plugin uses a CDN to fetch the emoji repository.
|
|
198
|
+
*/
|
|
199
|
+
_warnAboutCdnUse() {
|
|
200
|
+
const editor = this.editor;
|
|
201
|
+
const config = editor.config.get('emoji');
|
|
202
|
+
const licenseKey = editor.config.get('licenseKey');
|
|
203
|
+
const distributionChannel = window[Symbol.for('cke distribution')];
|
|
204
|
+
if (licenseKey === 'GPL') {
|
|
205
|
+
// Don't warn GPL users.
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (distributionChannel === 'cloud') {
|
|
209
|
+
// Don't warn cloud users, because they already use our CDN.
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (config && config.definitionsUrl) {
|
|
213
|
+
// Don't warn users who have configured their own definitions URL.
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* By default, the Emoji plugin fetches the emoji repository from CKEditor 5 CDN. To avoid this,
|
|
218
|
+
* you can use the {@link module:emoji/emojiconfig~EmojiConfig#definitionsUrl `emoji.definitionsUrl`}
|
|
219
|
+
* configuration option to provide a URL to your own emoji repository.
|
|
220
|
+
*
|
|
221
|
+
* If you only want to suppress this warning, set this configuration option to `cdn`.
|
|
222
|
+
*
|
|
223
|
+
* @error emoji-repository-cdn-use
|
|
224
|
+
*/
|
|
225
|
+
logWarning('emoji-repository-cdn-use');
|
|
226
|
+
}
|
|
167
227
|
/**
|
|
168
228
|
* Returns the emoji repository in a configured version if it is a non-empty array. Returns `null` otherwise.
|
|
169
229
|
*/
|
|
170
230
|
_getItems() {
|
|
171
|
-
const repository = EmojiRepository._results[this.
|
|
231
|
+
const repository = EmojiRepository._results[this._url.href];
|
|
172
232
|
return repository && repository.length ? repository : null;
|
|
173
233
|
}
|
|
174
234
|
/**
|
|
175
|
-
*
|
|
235
|
+
* Loads the emoji repository. If the repository is already loaded, it returns the cached result.
|
|
236
|
+
* Otherwise, it fetches the repository from the URL and adds it to the cache.
|
|
176
237
|
*/
|
|
177
|
-
async
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
238
|
+
async _loadAndCacheEmoji() {
|
|
239
|
+
if (EmojiRepository._results[this._url.href]) {
|
|
240
|
+
// The repository has already been downloaded.
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const result = await fetch(this._url, { cache: 'force-cache' })
|
|
181
244
|
.then(response => {
|
|
182
245
|
if (!response.ok) {
|
|
183
246
|
return [];
|
|
@@ -189,17 +252,17 @@ class EmojiRepository extends Plugin {
|
|
|
189
252
|
});
|
|
190
253
|
if (!result.length) {
|
|
191
254
|
/**
|
|
192
|
-
* Unable to load the emoji repository from
|
|
255
|
+
* Unable to load the emoji repository from the URL.
|
|
193
256
|
*
|
|
194
|
-
* If the
|
|
257
|
+
* If the URL works properly and there is no disruption of communication, please check your
|
|
195
258
|
* {@glink getting-started/setup/csp Content Security Policy (CSP)} setting and make sure
|
|
196
|
-
* the
|
|
259
|
+
* the URL connection is allowed by the editor.
|
|
197
260
|
*
|
|
198
261
|
* @error emoji-repository-load-failed
|
|
199
262
|
*/
|
|
200
263
|
logWarning('emoji-repository-load-failed');
|
|
201
264
|
}
|
|
202
|
-
|
|
265
|
+
EmojiRepository._results[this._url.href] = this._normalizeEmoji(result);
|
|
203
266
|
}
|
|
204
267
|
/**
|
|
205
268
|
* Normalizes the raw data fetched from CDN. By normalization, we meant:
|