react-hotkeys-hook 5.1.0 → 5.2.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.
package/README.md CHANGED
@@ -26,7 +26,9 @@
26
26
  </a>
27
27
  </p>
28
28
 
29
- <pre align="center">npm i react-hotkeys-hook</pre>
29
+ ```
30
+ npm i react-hotkeys-hook
31
+ ```
30
32
 
31
33
  <p align="center">
32
34
  A React hook for using keyboard shortcuts in components in a declarative way.
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "react-hotkeys-hook",
3
3
  "description": "React hook for handling keyboard shortcuts",
4
- "version": "5.1.0",
4
+ "version": "5.2.1",
5
+ "sideEffects": false,
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/JohannesKlauss/react-keymap-hook.git"
@@ -30,9 +31,10 @@
30
31
  "scripts": {
31
32
  "build": "npm run -w packages/react-hotkeys-hook build",
32
33
  "build:documentation": "npm run -w packages/documentation build",
33
- "lint": "npm run -w packages/react-hotkeys-hook lint",
34
34
  "test": "npm run -w packages/react-hotkeys-hook test",
35
- "prepublishOnly": "npm run test && npm run lint && npm run build"
35
+ "prepublishOnly": "npm run test && npm run lint && npm run build",
36
+ "format": "npx @biomejs/biome format --write packages",
37
+ "lint": "npx @biomejs/biome lint --write packages"
36
38
  },
37
39
  "workspaces": [
38
40
  "packages/*"
@@ -40,5 +42,8 @@
40
42
  "peerDependencies": {
41
43
  "react": ">=16.8.0",
42
44
  "react-dom": ">=16.8.0"
45
+ },
46
+ "devDependencies": {
47
+ "@biomejs/biome": "2.0.6"
43
48
  }
44
49
  }
@@ -3,4 +3,4 @@ import { Options, Keys, HotkeyCallback } from './types';
3
3
  import { HotkeysProvider, useHotkeysContext } from './HotkeysProvider';
4
4
  import { isHotkeyPressed } from './isHotkeyPressed';
5
5
  import { default as useRecordHotkeys } from './useRecordHotkeys';
6
- export { useHotkeys, useRecordHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, Options, Keys, HotkeyCallback, };
6
+ export { useHotkeys, useRecordHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, type Options, type Keys, type HotkeyCallback, };
@@ -1,6 +1,6 @@
1
- import { createContext as W, useContext as z, useState as A, useCallback as v, useRef as H, useLayoutEffect as _, useEffect as m } from "react";
2
- import { jsx as q } from "react/jsx-runtime";
3
- const G = ["shift", "alt", "meta", "mod", "ctrl", "control"], O = {
1
+ import { createContext as T, useContext as M, useState as A, useCallback as w, useRef as S, useLayoutEffect as z, useEffect as J } from "react";
2
+ import { jsx as b } from "react/jsx-runtime";
3
+ const j = ["shift", "alt", "meta", "mod", "ctrl", "control"], Q = {
4
4
  esc: "escape",
5
5
  return: "enter",
6
6
  left: "arrowleft",
@@ -18,106 +18,121 @@ const G = ["shift", "alt", "meta", "mod", "ctrl", "control"], O = {
18
18
  ControlLeft: "ctrl",
19
19
  ControlRight: "ctrl"
20
20
  };
21
- function S(t) {
22
- return (O[t.trim()] || t.trim()).toLowerCase().replace(/key|digit|numpad/, "");
23
- }
24
- function J(t) {
25
- return G.includes(t);
26
- }
27
- function b(t, r = ",") {
28
- return t.toLowerCase().split(r);
29
- }
30
- function R(t, r = "+", n = ">", f = !1, l) {
31
- let u = [], c = !1;
32
- t.includes(n) ? (c = !0, u = t.toLocaleLowerCase().split(n).map((i) => S(i))) : u = t.toLocaleLowerCase().split(r).map((i) => S(i));
33
- const d = {
34
- alt: u.includes("alt"),
35
- ctrl: u.includes("ctrl") || u.includes("control"),
36
- shift: u.includes("shift"),
37
- meta: u.includes("meta"),
38
- mod: u.includes("mod"),
39
- useKey: f
40
- }, a = u.filter((i) => !G.includes(i));
21
+ function K(e) {
22
+ return (Q[e.trim()] || e.trim()).toLowerCase().replace(/key|digit|numpad/, "");
23
+ }
24
+ function D(e) {
25
+ return j.includes(e);
26
+ }
27
+ function H(e, r = ",") {
28
+ return e.toLowerCase().split(r);
29
+ }
30
+ function P(e, r = "+", o = ">", i = !1, u) {
31
+ let n = [], c = !1;
32
+ e = e.trim(), e.includes(o) ? (c = !0, n = e.toLocaleLowerCase().split(o).map((f) => K(f))) : n = e.toLocaleLowerCase().split(r).map((f) => K(f));
33
+ const y = {
34
+ alt: n.includes("alt"),
35
+ ctrl: n.includes("ctrl") || n.includes("control"),
36
+ shift: n.includes("shift"),
37
+ meta: n.includes("meta"),
38
+ mod: n.includes("mod"),
39
+ useKey: i
40
+ }, d = n.filter((f) => !j.includes(f));
41
41
  return {
42
- ...d,
43
- keys: a,
44
- description: l,
45
- isSequence: c
42
+ ...y,
43
+ keys: d,
44
+ description: u,
45
+ isSequence: c,
46
+ hotkey: e
46
47
  };
47
48
  }
48
- typeof document < "u" && (document.addEventListener("keydown", (t) => {
49
- t.code !== void 0 && Q([S(t.code)]);
50
- }), document.addEventListener("keyup", (t) => {
51
- t.code !== void 0 && U([S(t.code)]);
49
+ typeof document < "u" && (document.addEventListener("keydown", (e) => {
50
+ e.code !== void 0 && I([K(e.code)]);
51
+ }), document.addEventListener("keyup", (e) => {
52
+ e.code !== void 0 && _([K(e.code)]);
52
53
  })), typeof window < "u" && (window.addEventListener("blur", () => {
53
- E.clear();
54
+ L.clear();
54
55
  }), window.addEventListener("contextmenu", () => {
55
56
  setTimeout(() => {
56
- E.clear();
57
+ L.clear();
57
58
  }, 0);
58
59
  }));
59
- const E = /* @__PURE__ */ new Set();
60
- function B(t) {
61
- return Array.isArray(t);
60
+ const L = /* @__PURE__ */ new Set();
61
+ function R(e) {
62
+ return Array.isArray(e);
62
63
  }
63
- function ee(t, r = ",") {
64
- return (B(t) ? t : t.split(r)).every((f) => E.has(f.trim().toLowerCase()));
64
+ function U(e, r = ",") {
65
+ return (R(e) ? e : e.split(r)).every((i) => L.has(i.trim().toLowerCase()));
65
66
  }
66
- function Q(t) {
67
- const r = Array.isArray(t) ? t : [t];
68
- E.has("meta") && E.forEach((n) => !J(n) && E.delete(n.toLowerCase())), r.forEach((n) => E.add(n.toLowerCase()));
67
+ function I(e) {
68
+ const r = Array.isArray(e) ? e : [e];
69
+ L.has("meta") && L.forEach((o) => !D(o) && L.delete(o.toLowerCase())), r.forEach((o) => L.add(o.toLowerCase()));
69
70
  }
70
- function U(t) {
71
- const r = Array.isArray(t) ? t : [t];
72
- t === "meta" ? E.clear() : r.forEach((n) => E.delete(n.toLowerCase()));
71
+ function _(e) {
72
+ const r = Array.isArray(e) ? e : [e];
73
+ e === "meta" ? L.clear() : r.forEach((o) => L.delete(o.toLowerCase()));
73
74
  }
74
- function te(t, r, n) {
75
- (typeof n == "function" && n(t, r) || n === !0) && t.preventDefault();
75
+ function V(e, r, o) {
76
+ (typeof o == "function" && o(e, r) || o === !0) && e.preventDefault();
76
77
  }
77
- function re(t, r, n) {
78
- return typeof n == "function" ? n(t, r) : n === !0 || n === void 0;
78
+ function X(e, r, o) {
79
+ return typeof o == "function" ? o(e, r) : o === !0 || o === void 0;
79
80
  }
80
- function ne(t) {
81
- return V(t, ["input", "textarea", "select"]);
81
+ const Y = [
82
+ "input",
83
+ "textarea",
84
+ "select",
85
+ "searchbox",
86
+ "slider",
87
+ "spinbutton",
88
+ "menuitem",
89
+ "menuitemcheckbox",
90
+ "menuitemradio",
91
+ "option",
92
+ "radio",
93
+ "textbox"
94
+ ];
95
+ function Z(e) {
96
+ return F(e, Y);
82
97
  }
83
- function V(t, r = !1) {
84
- const { target: n, composed: f } = t;
85
- let l;
86
- return ce(n) && f ? l = t.composedPath()[0] && t.composedPath()[0].tagName : l = n && n.tagName, B(r) ? !!(l && r && r.some((u) => u.toLowerCase() === l.toLowerCase())) : !!(l && r && r);
98
+ function F(e, r = !1) {
99
+ const { target: o, composed: i } = e;
100
+ let u, n;
101
+ return ee(o) && i ? (u = e.composedPath()[0] && e.composedPath()[0].tagName, n = e.composedPath()[0] && e.composedPath()[0].role) : (u = o && o.tagName, n = o && o.role), R(r) ? !!(u && r && r.some((c) => c.toLowerCase() === u.toLowerCase() || c === n)) : !!(u && r && r);
87
102
  }
88
- function ce(t) {
89
- return !!t.tagName && !t.tagName.startsWith("-") && t.tagName.includes("-");
103
+ function ee(e) {
104
+ return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
90
105
  }
91
- function ue(t, r) {
92
- return t.length === 0 && r ? (console.warn(
106
+ function te(e, r) {
107
+ return e.length === 0 && r ? (console.warn(
93
108
  'A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'
94
- ), !0) : r ? t.some((n) => r.includes(n)) || t.includes("*") : !0;
109
+ ), !0) : r ? e.some((o) => r.includes(o)) || e.includes("*") : !0;
95
110
  }
96
- const oe = (t, r, n = !1) => {
97
- const { alt: f, meta: l, mod: u, shift: c, ctrl: d, keys: a, useKey: i } = r, { code: w, key: e, ctrlKey: s, metaKey: y, shiftKey: k, altKey: K } = t, h = S(w);
98
- if (i && (a == null ? void 0 : a.length) === 1 && a.includes(e))
111
+ const re = (e, r, o = !1) => {
112
+ const { alt: i, meta: u, mod: n, shift: c, ctrl: y, keys: d, useKey: f } = r, { code: p, key: t, ctrlKey: a, metaKey: l, shiftKey: g, altKey: k } = e, m = K(p);
113
+ if (f && d?.length === 1 && d.includes(t))
99
114
  return !0;
100
- if (!(a != null && a.includes(h)) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(h))
115
+ if (!d?.includes(m) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(m))
101
116
  return !1;
102
- if (!n) {
103
- if (f !== K && h !== "alt" || c !== k && h !== "shift")
117
+ if (!o) {
118
+ if (i !== k && m !== "alt" || c !== g && m !== "shift")
104
119
  return !1;
105
- if (u) {
106
- if (!y && !s)
120
+ if (n) {
121
+ if (!l && !a)
107
122
  return !1;
108
- } else if (l !== y && h !== "meta" && h !== "os" || d !== s && h !== "ctrl" && h !== "control")
123
+ } else if (u !== l && m !== "meta" && m !== "os" || y !== a && m !== "ctrl" && m !== "control")
109
124
  return !1;
110
125
  }
111
- return a && a.length === 1 && a.includes(h) ? !0 : a ? ee(a) : !a;
112
- }, X = W(void 0), ae = () => z(X);
113
- function fe({ addHotkey: t, removeHotkey: r, children: n }) {
114
- return /* @__PURE__ */ q(X.Provider, { value: { addHotkey: t, removeHotkey: r }, children: n });
126
+ return d && d.length === 1 && d.includes(m) ? !0 : d ? U(d) : !d;
127
+ }, $ = T(void 0), oe = () => M($);
128
+ function ne({ addHotkey: e, removeHotkey: r, children: o }) {
129
+ return /* @__PURE__ */ b($.Provider, { value: { addHotkey: e, removeHotkey: r }, children: o });
115
130
  }
116
- function N(t, r) {
117
- return t && r && typeof t == "object" && typeof r == "object" ? Object.keys(t).length === Object.keys(r).length && // @ts-expect-error TS7053
118
- Object.keys(t).reduce((n, f) => n && N(t[f], r[f]), !0) : t === r;
131
+ function x(e, r) {
132
+ return e && r && typeof e == "object" && typeof r == "object" ? Object.keys(e).length === Object.keys(r).length && // @ts-expect-error TS7053
133
+ Object.keys(e).reduce((o, i) => o && x(e[i], r[i]), !0) : e === r;
119
134
  }
120
- const Y = W({
135
+ const W = T({
121
136
  hotkeys: [],
122
137
  activeScopes: [],
123
138
  // This array has to be empty instead of containing '*' as default, to check if the provider is set or not
@@ -127,120 +142,141 @@ const Y = W({
127
142
  },
128
143
  disableScope: () => {
129
144
  }
130
- }), le = () => z(Y), he = ({ initiallyActiveScopes: t = ["*"], children: r }) => {
131
- const [n, f] = A(t), [l, u] = A([]), c = v((e) => {
132
- f((s) => s.includes("*") ? [e] : Array.from(/* @__PURE__ */ new Set([...s, e])));
133
- }, []), d = v((e) => {
134
- f((s) => s.filter((y) => y !== e));
135
- }, []), a = v((e) => {
136
- f((s) => s.includes(e) ? s.filter((y) => y !== e) : s.includes("*") ? [e] : Array.from(/* @__PURE__ */ new Set([...s, e])));
137
- }, []), i = v((e) => {
138
- u((s) => [...s, e]);
139
- }, []), w = v((e) => {
140
- u((s) => s.filter((y) => !N(y, e)));
145
+ }), se = () => M(W), de = ({ initiallyActiveScopes: e = ["*"], children: r }) => {
146
+ const [o, i] = A(e), [u, n] = A([]), c = w((t) => {
147
+ i((a) => a.includes("*") ? [t] : Array.from(/* @__PURE__ */ new Set([...a, t])));
148
+ }, []), y = w((t) => {
149
+ i((a) => a.filter((l) => l !== t));
150
+ }, []), d = w((t) => {
151
+ i((a) => a.includes(t) ? a.filter((l) => l !== t) : a.includes("*") ? [t] : Array.from(/* @__PURE__ */ new Set([...a, t])));
152
+ }, []), f = w((t) => {
153
+ n((a) => [...a, t]);
154
+ }, []), p = w((t) => {
155
+ n((a) => a.filter((l) => !x(l, t)));
141
156
  }, []);
142
- return /* @__PURE__ */ q(
143
- Y.Provider,
157
+ return /* @__PURE__ */ b(
158
+ W.Provider,
144
159
  {
145
- value: { activeScopes: n, hotkeys: l, enableScope: c, disableScope: d, toggleScope: a },
146
- children: /* @__PURE__ */ q(fe, { addHotkey: i, removeHotkey: w, children: r })
160
+ value: { activeScopes: o, hotkeys: u, enableScope: c, disableScope: y, toggleScope: d },
161
+ children: /* @__PURE__ */ b(ne, { addHotkey: f, removeHotkey: p, children: r })
147
162
  }
148
163
  );
149
164
  };
150
- function se(t) {
151
- const r = H(void 0);
152
- return N(r.current, t) || (r.current = t), r.current;
153
- }
154
- const F = (t) => {
155
- t.stopPropagation(), t.preventDefault(), t.stopImmediatePropagation();
156
- }, ie = typeof window < "u" ? _ : m;
157
- function we(t, r, n, f) {
158
- const l = H(null), u = H(!1), c = n instanceof Array ? f instanceof Array ? void 0 : f : n, d = B(t) ? t.join(c == null ? void 0 : c.delimiter) : t, a = n instanceof Array ? n : f instanceof Array ? f : void 0, i = v(r, a ?? []), w = H(i);
159
- a ? w.current = i : w.current = r;
160
- const e = se(c), { activeScopes: s } = le(), y = ae();
161
- return ie(() => {
162
- if ((e == null ? void 0 : e.enabled) === !1 || !ue(s, e == null ? void 0 : e.scopes))
165
+ function ie(e) {
166
+ const r = S(void 0);
167
+ return x(r.current, e) || (r.current = e), r.current;
168
+ }
169
+ const N = (e) => {
170
+ e.stopPropagation(), e.preventDefault(), e.stopImmediatePropagation();
171
+ }, ue = typeof window < "u" ? z : J;
172
+ function fe(e, r, o, i) {
173
+ const u = S(null), n = S(!1), c = Array.isArray(o) ? Array.isArray(i) ? void 0 : i : o, y = R(e) ? e.join(c?.delimiter) : e, d = Array.isArray(o) ? o : Array.isArray(i) ? i : void 0, f = w(r, d ?? []), p = S(f);
174
+ d ? p.current = f : p.current = r;
175
+ const t = ie(c), { activeScopes: a } = se(), l = oe();
176
+ return ue(() => {
177
+ if (t?.enabled === !1 || !te(a, t?.scopes))
163
178
  return;
164
- let k = [], K;
165
- const h = (o, M = !1) => {
166
- var j;
167
- if (!(ne(o) && !V(o, e == null ? void 0 : e.enableOnFormTags))) {
168
- if (l.current !== null) {
169
- const L = l.current.getRootNode();
170
- if ((L instanceof Document || L instanceof ShadowRoot) && L.activeElement !== l.current && !l.current.contains(L.activeElement)) {
171
- F(o);
179
+ let g = [], k;
180
+ const m = (s, B = !1) => {
181
+ if (!(Z(s) && !F(s, t?.enableOnFormTags))) {
182
+ if (u.current !== null) {
183
+ const v = u.current.getRootNode();
184
+ if ((v instanceof Document || v instanceof ShadowRoot) && v.activeElement !== u.current && !u.current.contains(v.activeElement)) {
185
+ N(s);
172
186
  return;
173
187
  }
174
188
  }
175
- (j = o.target) != null && j.isContentEditable && !(e != null && e.enableOnContentEditable) || b(d, e == null ? void 0 : e.delimiter).forEach((L) => {
176
- var D, I, p, $;
177
- if (L.includes((e == null ? void 0 : e.splitKey) ?? "+") && L.includes((e == null ? void 0 : e.sequenceSplitKey) ?? ">")) {
178
- console.warn(`Hotkey ${L} contains both ${(e == null ? void 0 : e.splitKey) ?? "+"} and ${(e == null ? void 0 : e.sequenceSplitKey) ?? ">"} which is not supported.`);
189
+ s.target?.isContentEditable && !t?.enableOnContentEditable || H(y, t?.delimiter).forEach((v) => {
190
+ if (v.includes(t?.splitKey ?? "+") && v.includes(t?.sequenceSplitKey ?? ">")) {
191
+ console.warn(
192
+ `Hotkey ${v} contains both ${t?.splitKey ?? "+"} and ${t?.sequenceSplitKey ?? ">"} which is not supported.`
193
+ );
179
194
  return;
180
195
  }
181
- const g = R(L, e == null ? void 0 : e.splitKey, e == null ? void 0 : e.sequenceSplitKey, e == null ? void 0 : e.useKey, e == null ? void 0 : e.description);
182
- if (g.isSequence) {
183
- K = setTimeout(() => {
184
- k = [];
185
- }, (e == null ? void 0 : e.sequenceTimeoutMs) ?? 1e3);
186
- const P = g.useKey ? o.key : S(o.code);
187
- if (J(P.toLowerCase()))
196
+ const h = P(
197
+ v,
198
+ t?.splitKey,
199
+ t?.sequenceSplitKey,
200
+ t?.useKey,
201
+ t?.description
202
+ );
203
+ if (h.isSequence) {
204
+ k = setTimeout(() => {
205
+ g = [];
206
+ }, t?.sequenceTimeoutMs ?? 1e3);
207
+ const C = h.useKey ? s.key : K(s.code);
208
+ if (D(C.toLowerCase()))
188
209
  return;
189
- k.push(P);
190
- const Z = (D = g.keys) == null ? void 0 : D[k.length - 1];
191
- if (P !== Z) {
192
- k = [], K && clearTimeout(K);
210
+ g.push(C);
211
+ const G = h.keys?.[g.length - 1];
212
+ if (C !== G) {
213
+ g = [], k && clearTimeout(k);
193
214
  return;
194
215
  }
195
- k.length === ((I = g.keys) == null ? void 0 : I.length) && (w.current(o, g), K && clearTimeout(K), k = []);
196
- } else if (oe(o, g, e == null ? void 0 : e.ignoreModifiers) || (p = g.keys) != null && p.includes("*")) {
197
- if (($ = e == null ? void 0 : e.ignoreEventWhen) != null && $.call(e, o) || M && u.current)
216
+ g.length === h.keys?.length && (p.current(s, h), k && clearTimeout(k), g = []);
217
+ } else if (re(s, h, t?.ignoreModifiers) || h.keys?.includes("*")) {
218
+ if (t?.ignoreEventWhen?.(s) || B && n.current)
198
219
  return;
199
- if (te(o, g, e == null ? void 0 : e.preventDefault), !re(o, g, e == null ? void 0 : e.enabled)) {
200
- F(o);
220
+ if (V(s, h, t?.preventDefault), !X(s, h, t?.enabled)) {
221
+ N(s);
201
222
  return;
202
223
  }
203
- w.current(o, g), M || (u.current = !0);
224
+ p.current(s, h), B || (n.current = !0);
204
225
  }
205
226
  });
206
227
  }
207
- }, T = (o) => {
208
- o.code !== void 0 && (Q(S(o.code)), ((e == null ? void 0 : e.keydown) === void 0 && (e == null ? void 0 : e.keyup) !== !0 || e != null && e.keydown) && h(o));
209
- }, x = (o) => {
210
- o.code !== void 0 && (U(S(o.code)), u.current = !1, e != null && e.keyup && h(o, !0));
211
- }, C = l.current || (c == null ? void 0 : c.document) || document;
212
- return C.addEventListener("keyup", x, c == null ? void 0 : c.eventListenerOptions), C.addEventListener("keydown", T, c == null ? void 0 : c.eventListenerOptions), y && b(d, e == null ? void 0 : e.delimiter).forEach(
213
- (o) => y.addHotkey(
214
- R(o, e == null ? void 0 : e.splitKey, e == null ? void 0 : e.sequenceSplitKey, e == null ? void 0 : e.useKey, e == null ? void 0 : e.description)
228
+ }, O = (s) => {
229
+ s.code !== void 0 && (I(K(s.code)), (t?.keydown === void 0 && t?.keyup !== !0 || t?.keydown) && m(s));
230
+ }, q = (s) => {
231
+ s.code !== void 0 && (_(K(s.code)), n.current = !1, t?.keyup && m(s, !0));
232
+ }, E = u.current || c?.document || document;
233
+ return E.addEventListener("keyup", q, c?.eventListenerOptions), E.addEventListener("keydown", O, c?.eventListenerOptions), l && H(y, t?.delimiter).forEach(
234
+ (s) => l.addHotkey(
235
+ P(
236
+ s,
237
+ t?.splitKey,
238
+ t?.sequenceSplitKey,
239
+ t?.useKey,
240
+ t?.description
241
+ )
215
242
  )
216
243
  ), () => {
217
- C.removeEventListener("keyup", x, c == null ? void 0 : c.eventListenerOptions), C.removeEventListener("keydown", T, c == null ? void 0 : c.eventListenerOptions), y && b(d, e == null ? void 0 : e.delimiter).forEach(
218
- (o) => y.removeHotkey(
219
- R(o, e == null ? void 0 : e.splitKey, e == null ? void 0 : e.sequenceSplitKey, e == null ? void 0 : e.useKey, e == null ? void 0 : e.description)
244
+ E.removeEventListener("keyup", q, c?.eventListenerOptions), E.removeEventListener("keydown", O, c?.eventListenerOptions), l && H(y, t?.delimiter).forEach(
245
+ (s) => l.removeHotkey(
246
+ P(
247
+ s,
248
+ t?.splitKey,
249
+ t?.sequenceSplitKey,
250
+ t?.useKey,
251
+ t?.description
252
+ )
220
253
  )
221
- ), k = [], K && clearTimeout(K);
254
+ ), g = [], k && clearTimeout(k);
222
255
  };
223
- }, [d, e, s]), l;
224
- }
225
- function ge(t = !1) {
226
- const [r, n] = A(/* @__PURE__ */ new Set()), [f, l] = A(!1), u = v((i) => {
227
- i.code !== void 0 && (i.preventDefault(), i.stopPropagation(), n((w) => {
228
- const e = new Set(w);
229
- return e.add(S(t ? i.key : i.code)), e;
230
- }));
231
- }, [t]), c = v(() => {
232
- typeof document < "u" && (document.removeEventListener("keydown", u), l(!1));
233
- }, [u]), d = v(() => {
234
- n(/* @__PURE__ */ new Set()), typeof document < "u" && (c(), document.addEventListener("keydown", u), l(!0));
235
- }, [u, c]), a = v(() => {
236
- n(/* @__PURE__ */ new Set());
256
+ }, [y, t, a]), u;
257
+ }
258
+ function le(e = !1) {
259
+ const [r, o] = A(/* @__PURE__ */ new Set()), [i, u] = A(!1), n = w(
260
+ (f) => {
261
+ f.code !== void 0 && (f.preventDefault(), f.stopPropagation(), o((p) => {
262
+ const t = new Set(p);
263
+ return t.add(K(e ? f.key : f.code)), t;
264
+ }));
265
+ },
266
+ [e]
267
+ ), c = w(() => {
268
+ typeof document < "u" && (document.removeEventListener("keydown", n), u(!1));
269
+ }, [n]), y = w(() => {
270
+ o(/* @__PURE__ */ new Set()), typeof document < "u" && (c(), document.addEventListener("keydown", n), u(!0));
271
+ }, [n, c]), d = w(() => {
272
+ o(/* @__PURE__ */ new Set());
237
273
  }, []);
238
- return [r, { start: d, stop: c, resetKeys: a, isRecording: f }];
274
+ return [r, { start: y, stop: c, resetKeys: d, isRecording: i }];
239
275
  }
240
276
  export {
241
- he as HotkeysProvider,
242
- ee as isHotkeyPressed,
243
- we as useHotkeys,
244
- le as useHotkeysContext,
245
- ge as useRecordHotkeys
277
+ de as HotkeysProvider,
278
+ U as isHotkeyPressed,
279
+ fe as useHotkeys,
280
+ se as useHotkeysContext,
281
+ le as useRecordHotkeys
246
282
  };
@@ -1,5 +1,5 @@
1
1
  import { DependencyList } from 'react';
2
- export type FormTags = 'input' | 'textarea' | 'select' | 'INPUT' | 'TEXTAREA' | 'SELECT';
2
+ export type FormTags = 'input' | 'textarea' | 'select' | 'INPUT' | 'TEXTAREA' | 'SELECT' | 'searchbox' | 'slider' | 'spinbutton' | 'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'option' | 'radio' | 'textbox';
3
3
  export type Keys = string | readonly string[];
4
4
  export type Scopes = string | readonly string[];
5
5
  export type EventListenerOptions = {
@@ -21,6 +21,7 @@ export type Hotkey = KeyboardModifiers & {
21
21
  scopes?: Scopes;
22
22
  description?: string;
23
23
  isSequence?: boolean;
24
+ hotkey: string;
24
25
  };
25
26
  export type HotkeysEvent = Hotkey;
26
27
  export type HotkeyCallback = (keyboardEvent: KeyboardEvent, hotkeysEvent: HotkeysEvent) => void;