react-hotkeys-hook 5.3.2 → 5.3.3
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hotkeys-hook",
|
|
3
3
|
"description": "React hook for handling keyboard shortcuts",
|
|
4
|
-
"version": "5.3.
|
|
4
|
+
"version": "5.3.3",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"react-dom": ">=16.8.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@biomejs/biome": "2.
|
|
47
|
+
"@biomejs/biome": "2.5.0"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -1,313 +1,318 @@
|
|
|
1
|
-
import { createContext as
|
|
2
|
-
import { jsx as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createContext as e, useCallback as t, useContext as n, useEffect as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
2
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
3
|
+
//#region src/lib/parseHotkeys.ts
|
|
4
|
+
var l = [
|
|
5
|
+
"shift",
|
|
6
|
+
"alt",
|
|
7
|
+
"meta",
|
|
8
|
+
"mod",
|
|
9
|
+
"ctrl",
|
|
10
|
+
"control"
|
|
11
|
+
];
|
|
12
|
+
function u() {
|
|
13
|
+
return typeof navigator > "u" ? !1 : /mac/i.test(navigator.userAgent) && !/iphone|ipad|ipod/i.test(navigator.userAgent);
|
|
6
14
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
var d = {
|
|
16
|
+
esc: "escape",
|
|
17
|
+
return: "enter",
|
|
18
|
+
left: "arrowleft",
|
|
19
|
+
right: "arrowright",
|
|
20
|
+
up: "arrowup",
|
|
21
|
+
down: "arrowdown",
|
|
22
|
+
ShiftLeft: "shift",
|
|
23
|
+
ShiftRight: "shift",
|
|
24
|
+
AltLeft: "alt",
|
|
25
|
+
AltRight: "alt",
|
|
26
|
+
MetaLeft: "meta",
|
|
27
|
+
MetaRight: "meta",
|
|
28
|
+
OSLeft: "meta",
|
|
29
|
+
OSRight: "meta",
|
|
30
|
+
ControlLeft: "ctrl",
|
|
31
|
+
ControlRight: "ctrl"
|
|
24
32
|
};
|
|
25
|
-
function
|
|
26
|
-
|
|
33
|
+
function f(e) {
|
|
34
|
+
return (d[e.trim()] || e.trim()).toLowerCase().replace(/key|digit|numpad/, "");
|
|
27
35
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
36
|
+
function p(e) {
|
|
37
|
+
return l.includes(e);
|
|
30
38
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
39
|
+
function m(e, t = ",") {
|
|
40
|
+
return e.toLowerCase().split(t);
|
|
33
41
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
function h(e, t = "+", n = ">", r = !1, i, a) {
|
|
43
|
+
let o = [], s = !1;
|
|
44
|
+
e = e.trim(), e.includes(n) ? (s = !0, o = e.toLocaleLowerCase().split(n).map((e) => f(e))) : o = e.toLocaleLowerCase().split(t).map((e) => f(e));
|
|
45
|
+
let c = {
|
|
46
|
+
alt: o.includes("alt"),
|
|
47
|
+
ctrl: o.includes("ctrl") || o.includes("control"),
|
|
48
|
+
shift: o.includes("shift"),
|
|
49
|
+
meta: o.includes("meta"),
|
|
50
|
+
mod: o.includes("mod"),
|
|
51
|
+
useKey: r
|
|
52
|
+
}, u = o.filter((e) => !l.includes(e));
|
|
53
|
+
return {
|
|
54
|
+
...c,
|
|
55
|
+
keys: u,
|
|
56
|
+
description: i,
|
|
57
|
+
isSequence: s,
|
|
58
|
+
hotkey: e,
|
|
59
|
+
metadata: a
|
|
60
|
+
};
|
|
53
61
|
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/lib/isHotkeyPressed.ts
|
|
54
64
|
typeof document < "u" && (document.addEventListener("keydown", (e) => {
|
|
55
|
-
|
|
65
|
+
e.code !== void 0 && y([f(e.code)]);
|
|
56
66
|
}), document.addEventListener("keyup", (e) => {
|
|
57
|
-
|
|
67
|
+
e.code !== void 0 && b([f(e.code)]);
|
|
58
68
|
})), typeof window < "u" && (window.addEventListener("blur", () => {
|
|
59
|
-
|
|
69
|
+
g.clear();
|
|
60
70
|
}), window.addEventListener("focus", () => {
|
|
61
|
-
|
|
71
|
+
g.clear();
|
|
62
72
|
}), window.addEventListener("contextmenu", () => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
g.clear();
|
|
75
|
+
}, 0);
|
|
66
76
|
})), typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
67
|
-
|
|
77
|
+
g.clear();
|
|
68
78
|
});
|
|
69
|
-
|
|
70
|
-
function
|
|
71
|
-
|
|
79
|
+
var g = /* @__PURE__ */ new Set();
|
|
80
|
+
function _(e) {
|
|
81
|
+
return Array.isArray(e);
|
|
72
82
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
83
|
+
function v(e, t = ",") {
|
|
84
|
+
return (_(e) ? e : e.split(t)).every((e) => g.has(e.trim().toLowerCase()));
|
|
75
85
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
function y(e) {
|
|
87
|
+
let t = Array.isArray(e) ? e : [e];
|
|
88
|
+
g.has("meta") && g.forEach((e) => {
|
|
89
|
+
p(e) || g.delete(e.toLowerCase());
|
|
90
|
+
}), t.forEach((e) => {
|
|
91
|
+
g.add(e.toLowerCase());
|
|
92
|
+
});
|
|
83
93
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
94
|
+
function b(e) {
|
|
95
|
+
e === "meta" ? g.clear() : (Array.isArray(e) ? e : [e]).forEach((e) => {
|
|
96
|
+
g.delete(e.toLowerCase());
|
|
97
|
+
});
|
|
89
98
|
}
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/lib/validators.ts
|
|
101
|
+
function x(e, t, n) {
|
|
102
|
+
(typeof n == "function" && n(e, t) || n === !0) && e.preventDefault();
|
|
92
103
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
104
|
+
function S(e, t, n) {
|
|
105
|
+
return typeof n == "function" ? n(e, t) : n === !0 || n === void 0;
|
|
95
106
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
var C = [
|
|
108
|
+
"input",
|
|
109
|
+
"textarea",
|
|
110
|
+
"select",
|
|
111
|
+
"searchbox",
|
|
112
|
+
"slider",
|
|
113
|
+
"spinbutton",
|
|
114
|
+
"menuitem",
|
|
115
|
+
"menuitemcheckbox",
|
|
116
|
+
"menuitemradio",
|
|
117
|
+
"option",
|
|
118
|
+
"radio",
|
|
119
|
+
"textbox"
|
|
109
120
|
];
|
|
110
|
-
function
|
|
111
|
-
|
|
121
|
+
function w(e) {
|
|
122
|
+
return T(e, C);
|
|
112
123
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return se(r) && u ? (s = e.composedPath()[0] && e.composedPath()[0].tagName, f = e.composedPath()[0] && e.composedPath()[0].role) : (s = r && r.tagName, f = r && r.role), D(t) ? !!(s && t?.some((d) => d.toLowerCase() === s.toLowerCase() || d === f)) : !!(s && t && t);
|
|
124
|
+
function T(e, t = !1) {
|
|
125
|
+
let { target: n, composed: r } = e, i, a;
|
|
126
|
+
return E(n) && r ? (i = e.composedPath()[0] && e.composedPath()[0].tagName, a = e.composedPath()[0] && e.composedPath()[0].role) : (i = n && n.tagName, a = n && n.role), _(t) ? !!(i && t?.some((e) => e.toLowerCase() === i.toLowerCase() || e === a)) : !!(i && t && t);
|
|
117
127
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
128
|
+
function E(e) {
|
|
129
|
+
return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
|
|
120
130
|
}
|
|
121
|
-
function
|
|
122
|
-
|
|
131
|
+
function D(e, t) {
|
|
132
|
+
return e.length === 0 && t ? !1 : t ? e.some((e) => t.includes(e)) || e.includes("*") : !0;
|
|
123
133
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
var O = (e, t, n = !1) => {
|
|
135
|
+
let { alt: r, meta: i, mod: a, shift: o, ctrl: s, keys: c, useKey: l } = t, { code: d, key: p, ctrlKey: m, metaKey: h, shiftKey: g, altKey: _ } = e, y = f(d), b = typeof e.getModifierState == "function" && e.getModifierState("AltGraph");
|
|
136
|
+
if (!l && !c?.includes(y) && ![
|
|
137
|
+
"ctrl",
|
|
138
|
+
"control",
|
|
139
|
+
"unknown",
|
|
140
|
+
"meta",
|
|
141
|
+
"alt",
|
|
142
|
+
"shift",
|
|
143
|
+
"os"
|
|
144
|
+
].includes(y)) return !1;
|
|
145
|
+
if (!n) {
|
|
146
|
+
if (r !== _ && y !== "alt" || o !== g && y !== "shift") return !1;
|
|
147
|
+
if (a) {
|
|
148
|
+
if (u() ? !h : !m) return !1;
|
|
149
|
+
} else if (i !== h && y !== "meta" && y !== "os" || s !== m && y !== "ctrl" && y !== "control") return !1;
|
|
150
|
+
if (b && !r && !s && !a && ![
|
|
151
|
+
"alt",
|
|
152
|
+
"ctrl",
|
|
153
|
+
"control"
|
|
154
|
+
].includes(y)) return !1;
|
|
155
|
+
}
|
|
156
|
+
return l && c?.length === 1 && c.includes(p.toLowerCase()) || c && c.length === 1 && c.includes(y) ? !0 : c && c.length > 0 ? c.includes(y) ? v(c) : !1 : !c || c.length === 0;
|
|
157
|
+
}, k = e(void 0), A = () => n(k);
|
|
158
|
+
function j({ addHotkey: e, removeHotkey: t, children: n }) {
|
|
159
|
+
return /* @__PURE__ */ c(k.Provider, {
|
|
160
|
+
value: {
|
|
161
|
+
addHotkey: e,
|
|
162
|
+
removeHotkey: t
|
|
163
|
+
},
|
|
164
|
+
children: n
|
|
165
|
+
});
|
|
143
166
|
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/lib/deepEqual.ts
|
|
144
169
|
function M(e, t) {
|
|
145
|
-
|
|
146
|
-
Object.keys(e).reduce((r, u) => r && M(e[u], t[u]), !0) : e === t;
|
|
170
|
+
return e && t && typeof e == "object" && typeof t == "object" ? Object.keys(e).length === Object.keys(t).length && Object.keys(e).reduce((n, r) => n && M(e[r], t[r]), !0) : e === t;
|
|
147
171
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/lib/HotkeysProvider.tsx
|
|
174
|
+
var N = e({
|
|
175
|
+
hotkeys: [],
|
|
176
|
+
activeScopes: [],
|
|
177
|
+
toggleScope: () => {},
|
|
178
|
+
enableScope: () => {},
|
|
179
|
+
disableScope: () => {}
|
|
180
|
+
}), P = () => n(N), F = ({ initiallyActiveScopes: e = ["*"], children: n }) => {
|
|
181
|
+
let [r, i] = s(e), [a, o] = s([]), l = t((e) => {
|
|
182
|
+
i((t) => t.includes("*") ? [e] : Array.from(new Set([...t, e])));
|
|
183
|
+
}, []), u = t((e) => {
|
|
184
|
+
i((t) => t.filter((t) => t !== e));
|
|
185
|
+
}, []), d = t((e) => {
|
|
186
|
+
i((t) => t.includes(e) ? t.filter((t) => t !== e) : t.includes("*") ? [e] : Array.from(new Set([...t, e])));
|
|
187
|
+
}, []), f = t((e) => {
|
|
188
|
+
o((t) => [...t, e]);
|
|
189
|
+
}, []), p = t((e) => {
|
|
190
|
+
o((t) => t.filter((t) => !M(t, e)));
|
|
191
|
+
}, []);
|
|
192
|
+
return /* @__PURE__ */ c(N.Provider, {
|
|
193
|
+
value: {
|
|
194
|
+
activeScopes: r,
|
|
195
|
+
hotkeys: a,
|
|
196
|
+
enableScope: l,
|
|
197
|
+
disableScope: u,
|
|
198
|
+
toggleScope: d
|
|
199
|
+
},
|
|
200
|
+
children: /* @__PURE__ */ c(j, {
|
|
201
|
+
addHotkey: f,
|
|
202
|
+
removeHotkey: p,
|
|
203
|
+
children: n
|
|
204
|
+
})
|
|
205
|
+
});
|
|
177
206
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/lib/useDeepEqualMemo.ts
|
|
209
|
+
function I(e) {
|
|
210
|
+
let t = o(void 0);
|
|
211
|
+
return M(t.current, e) || (t.current = e), t.current;
|
|
181
212
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/lib/useHotkeys.ts
|
|
215
|
+
var L = (e) => {
|
|
216
|
+
e.stopPropagation(), e.preventDefault(), e.stopImmediatePropagation();
|
|
217
|
+
}, R = typeof window < "u" ? i : r;
|
|
218
|
+
function z(e) {
|
|
219
|
+
if (!e) return;
|
|
220
|
+
let { enabled: t, preventDefault: n, ignoreEventWhen: r, ...i } = e;
|
|
221
|
+
return typeof t == "function" ? i : {
|
|
222
|
+
...i,
|
|
223
|
+
enabled: t
|
|
224
|
+
};
|
|
189
225
|
}
|
|
190
|
-
function
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
a.code !== void 0 && (G(L(a.code)), l.current = !1, n?.keyup && q(a, !0));
|
|
253
|
-
}, H = s || o?.document || document;
|
|
254
|
-
return H.addEventListener("keyup", N, o?.eventListenerOptions), H.addEventListener("keydown", B, o?.eventListenerOptions), b && R(p, n?.delimiter).forEach((a) => {
|
|
255
|
-
b.addHotkey(
|
|
256
|
-
O(
|
|
257
|
-
a,
|
|
258
|
-
n?.splitKey,
|
|
259
|
-
n?.sequenceSplitKey,
|
|
260
|
-
n?.useKey,
|
|
261
|
-
n?.description,
|
|
262
|
-
n?.metadata
|
|
263
|
-
)
|
|
264
|
-
);
|
|
265
|
-
}), () => {
|
|
266
|
-
H.removeEventListener("keyup", N, o?.eventListenerOptions), H.removeEventListener("keydown", B, o?.eventListenerOptions), b && R(p, n?.delimiter).forEach((a) => {
|
|
267
|
-
b.removeHotkey(
|
|
268
|
-
O(
|
|
269
|
-
a,
|
|
270
|
-
n?.splitKey,
|
|
271
|
-
n?.sequenceSplitKey,
|
|
272
|
-
n?.useKey,
|
|
273
|
-
n?.description,
|
|
274
|
-
n?.metadata
|
|
275
|
-
)
|
|
276
|
-
);
|
|
277
|
-
}), w = [], S && clearTimeout(S);
|
|
278
|
-
};
|
|
279
|
-
}, [s, n, T, p]), d;
|
|
226
|
+
function B(e, n, r, i) {
|
|
227
|
+
let [a, c] = s(null), l = t((e) => (c(e), () => c(null)), []), u = o(!1), d = Array.isArray(r) ? Array.isArray(i) ? void 0 : i : r, g = _(e) ? e.join(d?.delimiter) : e, v = Array.isArray(r) ? r : Array.isArray(i) ? i : void 0, C = t(n, v ?? []), E = o(C);
|
|
228
|
+
v ? E.current = C : E.current = n;
|
|
229
|
+
let k = I(z(d)), j = o(d?.enabled);
|
|
230
|
+
j.current = d?.enabled;
|
|
231
|
+
let M = o(d?.preventDefault);
|
|
232
|
+
M.current = d?.preventDefault;
|
|
233
|
+
let N = o(d?.ignoreEventWhen);
|
|
234
|
+
N.current = d?.ignoreEventWhen;
|
|
235
|
+
let { activeScopes: F } = P(), B = A();
|
|
236
|
+
return R(() => {
|
|
237
|
+
if (j.current === !1 || !D(F, k?.scopes)) return;
|
|
238
|
+
let e = [], t, n = (n, r = !1) => {
|
|
239
|
+
if (!(w(n) && !T(n, k?.enableOnFormTags))) {
|
|
240
|
+
if (a !== null) {
|
|
241
|
+
let e = a.getRootNode();
|
|
242
|
+
if ((e instanceof Document || e instanceof ShadowRoot) && e.activeElement !== a && !a.contains(e.activeElement)) {
|
|
243
|
+
L(n);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
n.target?.isContentEditable && !k?.enableOnContentEditable || m(g, k?.delimiter).forEach((i) => {
|
|
248
|
+
if (i.includes(k?.splitKey ?? "+") && i.includes(k?.sequenceSplitKey ?? ">")) {
|
|
249
|
+
console.warn(`Hotkey ${i} contains both ${k?.splitKey ?? "+"} and ${k?.sequenceSplitKey ?? ">"} which is not supported.`);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
let a = h(i, k?.splitKey, k?.sequenceSplitKey, k?.useKey, k?.description, k?.metadata);
|
|
253
|
+
if (a.isSequence) {
|
|
254
|
+
t = setTimeout(() => {
|
|
255
|
+
e = [];
|
|
256
|
+
}, k?.sequenceTimeoutMs ?? 1e3);
|
|
257
|
+
let r = a.useKey ? n.key : f(n.code);
|
|
258
|
+
if (p(r.toLowerCase())) return;
|
|
259
|
+
if (e.push(r), r !== a.keys?.[e.length - 1]) {
|
|
260
|
+
e = [], t && clearTimeout(t);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
e.length === a.keys?.length && (E.current(n, a), t && clearTimeout(t), e = []);
|
|
264
|
+
} else if (O(n, a, k?.ignoreModifiers) || a.keys?.includes("*")) {
|
|
265
|
+
if (N.current?.(n) || r && u.current || (x(n, a, M.current), !S(n, a, j.current))) return;
|
|
266
|
+
E.current(n, a), r || (u.current = !0);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}, r = (e) => {
|
|
271
|
+
e.code !== void 0 && (y(f(e.code)), (k?.keydown === void 0 && k?.keyup !== !0 || k?.keydown) && n(e));
|
|
272
|
+
}, i = (e) => {
|
|
273
|
+
e.code !== void 0 && (b(f(e.code)), u.current = !1, k?.keyup && n(e, !0));
|
|
274
|
+
}, o = a || d?.document || document;
|
|
275
|
+
return o.addEventListener("keyup", i, d?.eventListenerOptions), o.addEventListener("keydown", r, d?.eventListenerOptions), B && m(g, k?.delimiter).forEach((e) => {
|
|
276
|
+
B.addHotkey(h(e, k?.splitKey, k?.sequenceSplitKey, k?.useKey, k?.description, k?.metadata));
|
|
277
|
+
}), () => {
|
|
278
|
+
o.removeEventListener("keyup", i, d?.eventListenerOptions), o.removeEventListener("keydown", r, d?.eventListenerOptions), B && m(g, k?.delimiter).forEach((e) => {
|
|
279
|
+
B.removeHotkey(h(e, k?.splitKey, k?.sequenceSplitKey, k?.useKey, k?.description, k?.metadata));
|
|
280
|
+
}), e = [], t && clearTimeout(t);
|
|
281
|
+
};
|
|
282
|
+
}, [
|
|
283
|
+
a,
|
|
284
|
+
k,
|
|
285
|
+
F,
|
|
286
|
+
g
|
|
287
|
+
]), l;
|
|
280
288
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/lib/useRecordHotkeys.ts
|
|
291
|
+
function V(e = !1, n = []) {
|
|
292
|
+
let [i, o] = s(/* @__PURE__ */ new Set()), [c, l] = s(!1), u = a(() => new Set(n.map((e) => e.toLowerCase())), [n]), d = t((t) => {
|
|
293
|
+
if (t.code === void 0) return;
|
|
294
|
+
let n = f(e ? t.key : t.code).toLowerCase();
|
|
295
|
+
u.has(n) || (t.preventDefault(), t.stopPropagation(), o((e) => {
|
|
296
|
+
let t = new Set(e);
|
|
297
|
+
return t.add(n), t;
|
|
298
|
+
}));
|
|
299
|
+
}, [e, u]), p = t(() => {
|
|
300
|
+
l(!1);
|
|
301
|
+
}, []), m = t(() => {
|
|
302
|
+
o(/* @__PURE__ */ new Set()), l(!0);
|
|
303
|
+
}, []), h = t(() => {
|
|
304
|
+
o(/* @__PURE__ */ new Set());
|
|
305
|
+
}, []);
|
|
306
|
+
return r(() => {
|
|
307
|
+
if (typeof document < "u" && c) return document.addEventListener("keydown", d), () => {
|
|
308
|
+
document.removeEventListener("keydown", d);
|
|
309
|
+
};
|
|
310
|
+
}, [c, d]), [i, {
|
|
311
|
+
start: m,
|
|
312
|
+
stop: p,
|
|
313
|
+
resetKeys: h,
|
|
314
|
+
isRecording: c
|
|
315
|
+
}];
|
|
306
316
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
te as isHotkeyPressed,
|
|
310
|
-
we as useHotkeys,
|
|
311
|
-
fe as useHotkeysContext,
|
|
312
|
-
ke as useRecordHotkeys
|
|
313
|
-
};
|
|
317
|
+
//#endregion
|
|
318
|
+
export { F as HotkeysProvider, v as isHotkeyPressed, B as useHotkeys, P as useHotkeysContext, V as useRecordHotkeys };
|