emoji-picker-react 5.1.0 → 5.1.1

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.
@@ -0,0 +1,113 @@
1
+ // src/hooks/searchHighlight.ts
2
+ var HIGHLIGHTED = "data-epr-highlighted", ACTIVE_DESCENDANT = "aria-activedescendant", unmountWatchers = /* @__PURE__ */ new WeakMap, ARROWS = [ "ArrowDown", "ArrowUp", "ArrowRight", "ArrowLeft" ], OPPOSITE = {
3
+ ArrowDown: "ArrowUp",
4
+ ArrowUp: "ArrowDown",
5
+ ArrowRight: "ArrowLeft",
6
+ ArrowLeft: "ArrowRight"
7
+ };
8
+
9
+ function createSearchHighlight(...[main, body, input, registry, setActiveEmoji, allUnifiedFromEmojiElement, caretAtEdge, firstVisibleEmoji, focusAdjacentEmoji, getRegionInDirection, idRef, focusFirstEmoji]) {
10
+ const wanted = () => !!input.current?.hasAttribute(ACTIVE_DESCENDANT), highlighted = () => highlightedEmoji(body.current), highlight = emoji => {
11
+ if (void 0 === emoji) {
12
+ const generation = registry.currentGeneration();
13
+ return wanted() && (focusFirstEmoji(body.current, {
14
+ moveTo: highlight,
15
+ shouldFocus: () => registry.isCurrent(generation) && wanted()
16
+ }) || highlight(null));
17
+ }
18
+ return setActiveEmoji(emoji && allUnifiedFromEmojiElement(emoji)), highlightEmoji(emoji);
19
+ }, highlightEmoji = emoji => {
20
+ const before = wanted();
21
+ return highlighted()?.removeAttribute(HIGHLIGHTED), emoji?.setAttribute(HIGHLIGHTED, ""),
22
+ emoji?.scrollIntoView?.({
23
+ block: "nearest"
24
+ }), idRef(input.current, ACTIVE_DESCENDANT, emoji), watchUnmount(body.current, input.current, emoji),
25
+ before;
26
+ }, arrowTowardGrid = () => ARROWS.find((key => "grid" === getRegionInDirection(registry, main.current, "search", {
27
+ key,
28
+ prefer: "grid"
29
+ })?.kind)) ?? "ArrowDown";
30
+ return {
31
+ highlight,
32
+ highlighted,
33
+ // Arrows move the highlight instead of focus, so the caret stays in
34
+ // the input. The arrow toward the grid starts it (ArrowUp when the
35
+ // grid is above the input; Left or Right beside it, with the caret at
36
+ // that edge of the text); otherwise Left/Right edit text until a cell
37
+ // is highlighted. `key` is the logical arrow, `direction` its non-zero
38
+ // step. Returns whether the key was taken.
39
+ move(event, key, direction, searching) {
40
+ const current = highlighted(), towardGrid = arrowTowardGrid(), row = "ArrowDown" === key || "ArrowUp" === key;
41
+ if (!wanted() && (event.key !== towardGrid || !row && !caretAtEdge(input.current, "ArrowRight" === key))) return !1;
42
+ if (event.preventDefault(), !current) return input.current?.setAttribute(ACTIVE_DESCENDANT, ""),
43
+ highlight(searching ? void 0 : firstVisibleEmoji(body.current)), !0;
44
+ const generation = registry.currentGeneration();
45
+ return focusAdjacentEmoji(current, direction, row, {
46
+ // Escape or blur ended the highlight, or new results replaced the
47
+ // grid, before the move landed.
48
+ shouldFocus: () => registry.isCurrent(generation) && wanted()
49
+ // Past the grid edge that faces the input, the highlight ends.
50
+ ,
51
+ exit: event.key === OPPOSITE[towardGrid] ? () => highlight(null) : void 0,
52
+ moveTo: highlight
53
+ }), !0;
54
+ },
55
+ // Leaving the search input ends the highlight.
56
+ blur(event) {
57
+ event.target === input.current && wanted() && highlight(null);
58
+ }
59
+ };
60
+ }
61
+
62
+ function highlightedEmoji(body) {
63
+ return body?.querySelector(`[${HIGHLIGHTED}]`) ?? null;
64
+ }
65
+
66
+ function watchUnmount(body, input, emoji) {
67
+ if (!input) return;
68
+ if (unmountWatchers.get(input)?.disconnect(), !body || !emoji || "undefined" == typeof MutationObserver) return;
69
+ const watcher = new MutationObserver((() => {
70
+ emoji.isConnected || (watcher.disconnect(), input.getAttribute(ACTIVE_DESCENDANT) === emoji.id && input.setAttribute(ACTIVE_DESCENDANT, ""));
71
+ }));
72
+ watcher.observe(body, {
73
+ childList: !0,
74
+ subtree: !0
75
+ }), unmountWatchers.set(input, watcher);
76
+ }
77
+
78
+ // src/data-core/normalizeLoaderResult.ts
79
+ function isRecord(value) {
80
+ return !!value && "object" == typeof value && !Array.isArray(value);
81
+ }
82
+
83
+ function isStringArray(value) {
84
+ return Array.isArray(value) && value.every((item => "string" == typeof item));
85
+ }
86
+
87
+ function isUnified(value) {
88
+ return value.split("-").every((hex => /^[\da-f]{1,6}$/i.test(hex) && parseInt(hex, 16) <= 1114111));
89
+ }
90
+
91
+ function hasValidEncoding(value) {
92
+ return void 0 !== value.imgUrl ? "string" == typeof value.imgUrl : "string" == typeof value.u && isUnified(value.u) && (void 0 === value.v || isStringArray(value.v) && value.v.every(isUnified));
93
+ }
94
+
95
+ function isEmoji(value) {
96
+ return isRecord(value) && "string" == typeof value.u && !!value.u && isStringArray(value.n) && value.n.length > 0 && "string" == typeof value.a && hasValidEncoding(value);
97
+ }
98
+
99
+ function isEmojiGroup(value) {
100
+ return Array.isArray(value) && value.every(isEmoji);
101
+ }
102
+
103
+ function isCategory(value) {
104
+ return isRecord(value) && "string" == typeof value.category && "string" == typeof value.name;
105
+ }
106
+
107
+ function normalizeLoaderResult(result) {
108
+ const data = isRecord(result) && "default" in result ? result.default : result;
109
+ if (!(isRecord(data) && isRecord(data.categories) && isRecord(data.emojis) && Object.values(data.emojis).every(isEmojiGroup) && Object.values(data.categories).every(isCategory))) throw new Error("[emoji-picker-react] emojiData loader must resolve a dataset or { default: dataset }.");
110
+ return data;
111
+ }
112
+
113
+ export { createSearchHighlight, normalizeLoaderResult };
@@ -1,6 +1,3 @@
1
- import {
2
- emojis_default
3
- } from "./chunk-ZOAKI5M6.mjs";
4
- export {
5
- emojis_default as default
6
- };
1
+ import { emojis_default } from "./chunk-ZOAKI5M6.mjs";
2
+
3
+ export { emojis_default as default };
package/dist/esm/data.mjs CHANGED
@@ -1,10 +1,7 @@
1
- import "./chunks/chunk-3NQHPTFV.mjs";
2
- import {
3
- getEmojiByUnified,
4
- searchEmojis
5
- } from "./chunks/chunk-FJVAS6PR.mjs";
1
+ import "./chunks/chunk-G75AG4FD.mjs";
2
+
3
+ import { getEmojiByUnified, searchEmojis } from "./chunks/chunk-6LOWV5AK.mjs";
4
+
6
5
  import "./chunks/chunk-ZOAKI5M6.mjs";
7
- export {
8
- getEmojiByUnified,
9
- searchEmojis
10
- };
6
+
7
+ export { getEmojiByUnified, searchEmojis };