@ckeditor/ckeditor5-emoji 44.2.0 → 44.2.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-emoji",
3
- "version": "44.2.0",
3
+ "version": "44.2.1-alpha.0",
4
4
  "description": "Emoji feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "@ckeditor/ckeditor5-core": "44.2.0",
17
- "@ckeditor/ckeditor5-mention": "44.2.0",
18
- "@ckeditor/ckeditor5-typing": "44.2.0",
19
- "@ckeditor/ckeditor5-ui": "44.2.0",
20
- "@ckeditor/ckeditor5-utils": "44.2.0",
21
- "ckeditor5": "44.2.0",
22
- "fuse.js": "7.0.0",
16
+ "@ckeditor/ckeditor5-core": "44.2.1-alpha.0",
17
+ "@ckeditor/ckeditor5-mention": "44.2.1-alpha.0",
18
+ "@ckeditor/ckeditor5-typing": "44.2.1-alpha.0",
19
+ "@ckeditor/ckeditor5-ui": "44.2.1-alpha.0",
20
+ "@ckeditor/ckeditor5-utils": "44.2.1-alpha.0",
21
+ "ckeditor5": "44.2.1-alpha.0",
22
+ "fuzzysort": "3.1.0",
23
23
  "lodash-es": "4.17.21"
24
24
  },
25
25
  "author": "CKSource (http://cksource.com/)",
@@ -41,6 +41,11 @@
41
41
  "ckeditor5-metadata.json",
42
42
  "CHANGELOG.md"
43
43
  ],
44
+ "sideEffects": [
45
+ "*.css",
46
+ "build/**/*.js",
47
+ "dist/translations/*.umd.js"
48
+ ],
44
49
  "types": "src/index.d.ts",
45
50
  "exports": {
46
51
  ".": {
@@ -16,9 +16,9 @@ export default class EmojiRepository extends Plugin {
16
16
  */
17
17
  private _repositoryPromiseResolveCallback;
18
18
  /**
19
- * An instance of the [Fuse.js](https://www.fusejs.io/) library.
19
+ * Emoji repository in a configured version.
20
20
  */
21
- private _fuseSearch;
21
+ private _items;
22
22
  /**
23
23
  * The resolved URL from which the emoji repository is downloaded.
24
24
  */
@@ -50,8 +50,7 @@ export default class EmojiRepository extends Plugin {
50
50
  init(): Promise<void>;
51
51
  /**
52
52
  * Returns an array of emoji entries that match the search query.
53
- * If the emoji repository is not loaded, the [Fuse.js](https://www.fusejs.io/) instance is not created,
54
- * hence this method returns an empty array.
53
+ * If the emoji repository is not loaded this method returns an empty array.
55
54
  *
56
55
  * @param searchQuery A search query to match emoji.
57
56
  * @returns An array of emoji entries that match the search query.
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * @module emoji/emojirepository
7
7
  */
8
- import Fuse from 'fuse.js';
8
+ import fuzzysort from 'fuzzysort';
9
9
  import { groupBy } from 'lodash-es';
10
10
  import { Plugin } from 'ckeditor5/src/core.js';
11
11
  import { logWarning, version as editorVersion } from 'ckeditor5/src/utils.js';
@@ -52,7 +52,7 @@ class EmojiRepository extends Plugin {
52
52
  this._repositoryPromise = new Promise(resolve => {
53
53
  this._repositoryPromiseResolveCallback = resolve;
54
54
  });
55
- this._fuseSearch = null;
55
+ this._items = null;
56
56
  }
57
57
  /**
58
58
  * @inheritDoc
@@ -60,35 +60,21 @@ class EmojiRepository extends Plugin {
60
60
  async init() {
61
61
  this._warnAboutCdnUse();
62
62
  await this._loadAndCacheEmoji();
63
- const items = this._getItems();
64
- // Skip plugin initialization if the emoji repository is not available.
65
- // The initialization of other dependent plugins, such as `EmojiMention` and `EmojiPicker`, is prevented as well.
66
- if (!items) {
63
+ this._items = this._getItems();
64
+ if (!this._items) {
67
65
  return this._repositoryPromiseResolveCallback(false);
68
66
  }
69
- // Create instance of the Fuse.js library with configured weighted search keys and disabled fuzzy search.
70
- this._fuseSearch = new Fuse(items, {
71
- keys: [
72
- { name: 'emoticon', weight: 5 },
73
- { name: 'annotation', weight: 3 },
74
- { name: 'tags', weight: 1 }
75
- ],
76
- minMatchCharLength: 2,
77
- threshold: 0,
78
- ignoreLocation: true
79
- });
80
67
  return this._repositoryPromiseResolveCallback(true);
81
68
  }
82
69
  /**
83
70
  * Returns an array of emoji entries that match the search query.
84
- * If the emoji repository is not loaded, the [Fuse.js](https://www.fusejs.io/) instance is not created,
85
- * hence this method returns an empty array.
71
+ * If the emoji repository is not loaded this method returns an empty array.
86
72
  *
87
73
  * @param searchQuery A search query to match emoji.
88
74
  * @returns An array of emoji entries that match the search query.
89
75
  */
90
76
  getEmojiByQuery(searchQuery) {
91
- if (!this._fuseSearch) {
77
+ if (!this._items) {
92
78
  return [];
93
79
  }
94
80
  const searchQueryTokens = searchQuery.split(/\s/).filter(Boolean);
@@ -97,21 +83,25 @@ class EmojiRepository extends Plugin {
97
83
  if (!shouldSearch) {
98
84
  return [];
99
85
  }
100
- return this._fuseSearch
101
- .search({
102
- '$or': [
103
- {
104
- emoticon: searchQuery
105
- },
106
- {
107
- '$and': searchQueryTokens.map(token => ({ annotation: token }))
108
- },
109
- {
110
- '$and': searchQueryTokens.map(token => ({ tags: token }))
86
+ return fuzzysort
87
+ .go(searchQuery, this._items, {
88
+ threshold: 0.6,
89
+ keys: [
90
+ 'emoticon',
91
+ 'annotation',
92
+ (emojiEntry) => {
93
+ // Instead of searching over all tags, let's use only those that matches the query.
94
+ // It enables searching in tags with the space character in names.
95
+ const searchQueryTokens = searchQuery.split(/\s/).filter(Boolean);
96
+ const matchedTags = searchQueryTokens.flatMap(tok => {
97
+ var _a;
98
+ return (_a = emojiEntry.tags) === null || _a === void 0 ? void 0 : _a.filter(t => t.startsWith(tok));
99
+ });
100
+ return matchedTags.join();
111
101
  }
112
102
  ]
113
103
  })
114
- .map(result => result.item);
104
+ .map(result => result.obj);
115
105
  }
116
106
  /**
117
107
  * Groups all emojis by categories.