@sveltia/ui 0.65.3 → 0.65.4

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.
@@ -12,7 +12,7 @@
12
12
  <script>
13
13
  import { _ } from '@sveltia/i18n';
14
14
  import { onMount } from 'svelte';
15
- import { loadEmojiList, searchEmojis } from './emoji.js';
15
+ import { searchEmojis } from './emoji.js';
16
16
 
17
17
  /**
18
18
  * @import { EmojiAnchorRect, EmojiEntry, EmojiTrigger } from '../../typedefs';
@@ -84,12 +84,6 @@
84
84
  * @type {HTMLElement | undefined}
85
85
  */
86
86
  let listElement = $state();
87
- /**
88
- * Monotonically increasing counter used to discard the result of a search that has been
89
- * superseded while the emoji list was being loaded.
90
- * @type {number}
91
- */
92
- let searchGeneration = 0;
93
87
  /**
94
88
  * Identifier of the shortcode the user has dismissed with the Escape key, so the suggestions
95
89
  * don’t come back while they keep typing it.
@@ -167,14 +161,13 @@
167
161
  candidates = [];
168
162
  selectedIndex = 0;
169
163
  anchorRect = undefined;
170
- searchGeneration += 1;
171
164
  };
172
165
 
173
166
  /**
174
167
  * Feed the shortcode being typed into the list, or nothing to close it.
175
168
  * @param {EmojiTrigger} [newTrigger] Shortcode state.
176
169
  */
177
- export const update = async (newTrigger) => {
170
+ export const update = (newTrigger) => {
178
171
  if (!newTrigger) {
179
172
  if (trigger || dismissedShortcodeId) {
180
173
  close();
@@ -202,17 +195,6 @@
202
195
  }
203
196
 
204
197
  trigger = newTrigger;
205
- searchGeneration += 1;
206
-
207
- const generation = searchGeneration;
208
-
209
- await loadEmojiList();
210
-
211
- // Bail out if the user has kept typing in the meantime
212
- if (generation !== searchGeneration) {
213
- return;
214
- }
215
-
216
198
  candidates = searchEmojis(query);
217
199
  selectedIndex = 0;
218
200
  };
@@ -359,11 +341,6 @@
359
341
  });
360
342
 
361
343
  onMount(() => {
362
- // Warm the data up front, so the first shortcode the user types shows suggestions straight away
363
- // rather than waiting on the network. The loader memoizes, so this costs one request per page
364
- // however many fields are on it, and nothing at all once it’s cached.
365
- loadEmojiList();
366
-
367
344
  /**
368
345
  * Follow the caret when the page or an ancestor is scrolled or the window is resized.
369
346
  */
@@ -5,7 +5,7 @@ type EmojiSuggestions = {
5
5
  } & {
6
6
  isOpen: () => boolean;
7
7
  close: (dismissed?: boolean | undefined) => void;
8
- update: (newTrigger?: EmojiTrigger | undefined) => Promise<void>;
8
+ update: (newTrigger?: EmojiTrigger | undefined) => void;
9
9
  moveSelection: (delta: number) => void;
10
10
  selectHighlighted: () => void;
11
11
  handleKeyDown: (event: KeyboardEvent) => boolean;
@@ -39,7 +39,7 @@ declare const EmojiSuggestions: import("svelte").Component<{
39
39
  }, {
40
40
  isOpen: () => boolean;
41
41
  close: (dismissed?: boolean | undefined) => void;
42
- update: (newTrigger?: EmojiTrigger | undefined) => Promise<void>;
42
+ update: (newTrigger?: EmojiTrigger | undefined) => void;
43
43
  moveSelection: (delta: number) => void;
44
44
  selectHighlighted: () => void;
45
45
  handleKeyDown: (event: KeyboardEvent) => boolean;
@@ -16,7 +16,6 @@ export const EMOJI_TRIGGER_REGEX: RegExp;
16
16
  */
17
17
  export const MAX_EMOJI_SUGGESTIONS: 50;
18
18
  export function parseEmojiData(data: string): EmojiEntry[];
19
- export function loadEmojiList(): Promise<EmojiEntry[]>;
20
19
  /**
21
20
  * Rank given when there is no match at all. Higher than any real rank, so an unmatched emoji sorts
22
21
  * last and the ranks can still be compared arithmetically.
@@ -1,3 +1,5 @@
1
+ import { EMOJI_DATA } from './generated.js';
2
+
1
3
  /**
2
4
  * @import { EmojiEntry } from '../../typedefs';
3
5
  */
@@ -24,15 +26,11 @@ export const MAX_EMOJI_SUGGESTIONS = 50;
24
26
  */
25
27
  const WORD_SEPARATOR_REGEX = /[-_]/;
26
28
  /**
27
- * Cached emoji list. This is `undefined` until {@link loadEmojiList} resolves for the first time.
29
+ * Emoji list, parsed out of the data the first time it’s searched. This is `undefined` until then,
30
+ * so a page that never sees a shortcode never pays for it.
28
31
  * @type {EmojiEntry[] | undefined}
29
32
  */
30
33
  let emojiList;
31
- /**
32
- * In-flight or completed loader for {@link emojiList}, so the data is only parsed once.
33
- * @type {Promise<EmojiEntry[]> | undefined}
34
- */
35
- let loader;
36
34
 
37
35
  /**
38
36
  * Convert the generated emoji data into a searchable list.
@@ -54,34 +52,6 @@ export const parseEmojiData = (data) =>
54
52
  };
55
53
  });
56
54
 
57
- /**
58
- * Load the emoji list.
59
- *
60
- * The data is imported on demand rather than up front, so a bundler that can split it out keeps it
61
- * out of the initial payload — most sessions never type a shortcode. A failure here is not worth
62
- * surfacing: no suggestions are ever shown, and the shortcode the user typed stays as plain text.
63
- * @returns {Promise<EmojiEntry[]>} Emoji list, or an empty list if the data can’t be obtained.
64
- */
65
- export const loadEmojiList = async () => {
66
- loader ??= (async () => {
67
- try {
68
- const { EMOJI_DATA } = await import('./generated.js');
69
-
70
- emojiList = parseEmojiData(EMOJI_DATA);
71
- } catch (ex) {
72
- // Allow a later attempt to retry, so a transient chunk load failure isn’t permanent
73
- loader = undefined;
74
- emojiList = [];
75
- // eslint-disable-next-line no-console
76
- console.error(ex);
77
- }
78
-
79
- return /** @type {EmojiEntry[]} */ (emojiList);
80
- })();
81
-
82
- return loader;
83
- };
84
-
85
55
  /**
86
56
  * Rank given when there is no match at all. Higher than any real rank, so an unmatched emoji sorts
87
57
  * last and the ranks can still be compared arithmetically.
@@ -194,8 +164,7 @@ const getMatchCentrality = ({ name, aliases }, query) => {
194
164
  };
195
165
 
196
166
  /**
197
- * Search the loaded emoji list for the given query. This returns an empty list unless
198
- * {@link loadEmojiList} has been resolved beforehand.
167
+ * Search the emoji list for the given query.
199
168
  * @param {string} query Search query without the leading colon, e.g. `smi`.
200
169
  * @returns {EmojiEntry[]} Matching emojis, best match first, capped at
201
170
  * {@link MAX_EMOJI_SUGGESTIONS}.
@@ -203,10 +172,12 @@ const getMatchCentrality = ({ name, aliases }, query) => {
203
172
  export const searchEmojis = (query) => {
204
173
  const normalizedQuery = query.toLowerCase();
205
174
 
206
- if (!emojiList || !normalizedQuery) {
175
+ if (!normalizedQuery) {
207
176
  return [];
208
177
  }
209
178
 
179
+ emojiList ??= parseEmojiData(EMOJI_DATA);
180
+
210
181
  return (
211
182
  emojiList
212
183
  .map((entry) => {
@@ -7,7 +7,7 @@ export const SHIKI_VERSION: "4.4.3";
7
7
  /**
8
8
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
9
9
  */
10
- export const UI_VERSION: "0.65.3";
10
+ export const UI_VERSION: "0.65.4";
11
11
  /**
12
12
  * Available syntax highlighting languages, sorted by display name.
13
13
  * @type {{ id: string, name: string, aliases?: string[] }[]}
@@ -10,7 +10,7 @@ export const SHIKI_VERSION = "4.4.3";
10
10
  /**
11
11
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
12
12
  */
13
- export const UI_VERSION = "0.65.3";
13
+ export const UI_VERSION = "0.65.4";
14
14
 
15
15
  /**
16
16
  * Available syntax highlighting languages, sorted by display name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.65.3",
3
+ "version": "0.65.4",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",