react-hotkeys-hook 5.1.0 → 5.2.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/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,7 @@
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.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/JohannesKlauss/react-keymap-hook.git"
@@ -30,9 +30,10 @@
30
30
  "scripts": {
31
31
  "build": "npm run -w packages/react-hotkeys-hook build",
32
32
  "build:documentation": "npm run -w packages/documentation build",
33
- "lint": "npm run -w packages/react-hotkeys-hook lint",
34
33
  "test": "npm run -w packages/react-hotkeys-hook test",
35
- "prepublishOnly": "npm run test && npm run lint && npm run build"
34
+ "prepublishOnly": "npm run test && npm run lint && npm run build",
35
+ "format": "npx @biomejs/biome format --write packages",
36
+ "lint": "npx @biomejs/biome lint --write packages"
36
37
  },
37
38
  "workspaces": [
38
39
  "packages/*"
@@ -40,5 +41,8 @@
40
41
  "peerDependencies": {
41
42
  "react": ">=16.8.0",
42
43
  "react-dom": ">=16.8.0"
44
+ },
45
+ "devDependencies": {
46
+ "@biomejs/biome": "2.0.6"
43
47
  }
44
48
  }
@@ -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,108 @@ 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 = ["input", "textarea", "select", "searchbox", "slider", "spinbutton", "menuitem", "menuitemcheckbox", "menuitemradio", "option", "radio", "textbox"];
82
+ function Z(e) {
83
+ return F(e, Y);
82
84
  }
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);
85
+ function F(e, r = !1) {
86
+ const { target: o, composed: i } = e;
87
+ let u, n;
88
+ 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
89
  }
88
- function ce(t) {
89
- return !!t.tagName && !t.tagName.startsWith("-") && t.tagName.includes("-");
90
+ function ee(e) {
91
+ return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
90
92
  }
91
- function ue(t, r) {
92
- return t.length === 0 && r ? (console.warn(
93
+ function te(e, r) {
94
+ return e.length === 0 && r ? (console.warn(
93
95
  '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;
96
+ ), !0) : r ? e.some((o) => r.includes(o)) || e.includes("*") : !0;
95
97
  }
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))
98
+ const re = (e, r, o = !1) => {
99
+ 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);
100
+ if (f && d?.length === 1 && d.includes(t))
99
101
  return !0;
100
- if (!(a != null && a.includes(h)) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(h))
102
+ if (!d?.includes(m) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(m))
101
103
  return !1;
102
- if (!n) {
103
- if (f !== K && h !== "alt" || c !== k && h !== "shift")
104
+ if (!o) {
105
+ if (i !== k && m !== "alt" || c !== g && m !== "shift")
104
106
  return !1;
105
- if (u) {
106
- if (!y && !s)
107
+ if (n) {
108
+ if (!l && !a)
107
109
  return !1;
108
- } else if (l !== y && h !== "meta" && h !== "os" || d !== s && h !== "ctrl" && h !== "control")
110
+ } else if (u !== l && m !== "meta" && m !== "os" || y !== a && m !== "ctrl" && m !== "control")
109
111
  return !1;
110
112
  }
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 });
113
+ return d && d.length === 1 && d.includes(m) ? !0 : d ? U(d) : !d;
114
+ }, $ = T(void 0), oe = () => M($);
115
+ function ne({ addHotkey: e, removeHotkey: r, children: o }) {
116
+ return /* @__PURE__ */ b($.Provider, { value: { addHotkey: e, removeHotkey: r }, children: o });
115
117
  }
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;
118
+ function x(e, r) {
119
+ return e && r && typeof e == "object" && typeof r == "object" ? Object.keys(e).length === Object.keys(r).length && // @ts-expect-error TS7053
120
+ Object.keys(e).reduce((o, i) => o && x(e[i], r[i]), !0) : e === r;
119
121
  }
120
- const Y = W({
122
+ const W = T({
121
123
  hotkeys: [],
122
124
  activeScopes: [],
123
125
  // This array has to be empty instead of containing '*' as default, to check if the provider is set or not
@@ -127,120 +129,141 @@ const Y = W({
127
129
  },
128
130
  disableScope: () => {
129
131
  }
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)));
132
+ }), se = () => M(W), de = ({ initiallyActiveScopes: e = ["*"], children: r }) => {
133
+ const [o, i] = A(e), [u, n] = A([]), c = w((t) => {
134
+ i((a) => a.includes("*") ? [t] : Array.from(/* @__PURE__ */ new Set([...a, t])));
135
+ }, []), y = w((t) => {
136
+ i((a) => a.filter((l) => l !== t));
137
+ }, []), d = w((t) => {
138
+ i((a) => a.includes(t) ? a.filter((l) => l !== t) : a.includes("*") ? [t] : Array.from(/* @__PURE__ */ new Set([...a, t])));
139
+ }, []), f = w((t) => {
140
+ n((a) => [...a, t]);
141
+ }, []), p = w((t) => {
142
+ n((a) => a.filter((l) => !x(l, t)));
141
143
  }, []);
142
- return /* @__PURE__ */ q(
143
- Y.Provider,
144
+ return /* @__PURE__ */ b(
145
+ W.Provider,
144
146
  {
145
- value: { activeScopes: n, hotkeys: l, enableScope: c, disableScope: d, toggleScope: a },
146
- children: /* @__PURE__ */ q(fe, { addHotkey: i, removeHotkey: w, children: r })
147
+ value: { activeScopes: o, hotkeys: u, enableScope: c, disableScope: y, toggleScope: d },
148
+ children: /* @__PURE__ */ b(ne, { addHotkey: f, removeHotkey: p, children: r })
147
149
  }
148
150
  );
149
151
  };
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))
152
+ function ie(e) {
153
+ const r = S(void 0);
154
+ return x(r.current, e) || (r.current = e), r.current;
155
+ }
156
+ const N = (e) => {
157
+ e.stopPropagation(), e.preventDefault(), e.stopImmediatePropagation();
158
+ }, ue = typeof window < "u" ? z : J;
159
+ function fe(e, r, o, i) {
160
+ 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);
161
+ d ? p.current = f : p.current = r;
162
+ const t = ie(c), { activeScopes: a } = se(), l = oe();
163
+ return ue(() => {
164
+ if (t?.enabled === !1 || !te(a, t?.scopes))
163
165
  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);
166
+ let g = [], k;
167
+ const m = (s, B = !1) => {
168
+ if (!(Z(s) && !F(s, t?.enableOnFormTags))) {
169
+ if (u.current !== null) {
170
+ const v = u.current.getRootNode();
171
+ if ((v instanceof Document || v instanceof ShadowRoot) && v.activeElement !== u.current && !u.current.contains(v.activeElement)) {
172
+ N(s);
172
173
  return;
173
174
  }
174
175
  }
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.`);
176
+ s.target?.isContentEditable && !t?.enableOnContentEditable || H(y, t?.delimiter).forEach((v) => {
177
+ if (v.includes(t?.splitKey ?? "+") && v.includes(t?.sequenceSplitKey ?? ">")) {
178
+ console.warn(
179
+ `Hotkey ${v} contains both ${t?.splitKey ?? "+"} and ${t?.sequenceSplitKey ?? ">"} which is not supported.`
180
+ );
179
181
  return;
180
182
  }
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()))
183
+ const h = P(
184
+ v,
185
+ t?.splitKey,
186
+ t?.sequenceSplitKey,
187
+ t?.useKey,
188
+ t?.description
189
+ );
190
+ if (h.isSequence) {
191
+ k = setTimeout(() => {
192
+ g = [];
193
+ }, t?.sequenceTimeoutMs ?? 1e3);
194
+ const C = h.useKey ? s.key : K(s.code);
195
+ if (D(C.toLowerCase()))
188
196
  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);
197
+ g.push(C);
198
+ const G = h.keys?.[g.length - 1];
199
+ if (C !== G) {
200
+ g = [], k && clearTimeout(k);
193
201
  return;
194
202
  }
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)
203
+ g.length === h.keys?.length && (p.current(s, h), k && clearTimeout(k), g = []);
204
+ } else if (re(s, h, t?.ignoreModifiers) || h.keys?.includes("*")) {
205
+ if (t?.ignoreEventWhen?.(s) || B && n.current)
198
206
  return;
199
- if (te(o, g, e == null ? void 0 : e.preventDefault), !re(o, g, e == null ? void 0 : e.enabled)) {
200
- F(o);
207
+ if (V(s, h, t?.preventDefault), !X(s, h, t?.enabled)) {
208
+ N(s);
201
209
  return;
202
210
  }
203
- w.current(o, g), M || (u.current = !0);
211
+ p.current(s, h), B || (n.current = !0);
204
212
  }
205
213
  });
206
214
  }
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)
215
+ }, O = (s) => {
216
+ s.code !== void 0 && (I(K(s.code)), (t?.keydown === void 0 && t?.keyup !== !0 || t?.keydown) && m(s));
217
+ }, q = (s) => {
218
+ s.code !== void 0 && (_(K(s.code)), n.current = !1, t?.keyup && m(s, !0));
219
+ }, E = u.current || c?.document || document;
220
+ return E.addEventListener("keyup", q, c?.eventListenerOptions), E.addEventListener("keydown", O, c?.eventListenerOptions), l && H(y, t?.delimiter).forEach(
221
+ (s) => l.addHotkey(
222
+ P(
223
+ s,
224
+ t?.splitKey,
225
+ t?.sequenceSplitKey,
226
+ t?.useKey,
227
+ t?.description
228
+ )
215
229
  )
216
230
  ), () => {
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)
231
+ E.removeEventListener("keyup", q, c?.eventListenerOptions), E.removeEventListener("keydown", O, c?.eventListenerOptions), l && H(y, t?.delimiter).forEach(
232
+ (s) => l.removeHotkey(
233
+ P(
234
+ s,
235
+ t?.splitKey,
236
+ t?.sequenceSplitKey,
237
+ t?.useKey,
238
+ t?.description
239
+ )
220
240
  )
221
- ), k = [], K && clearTimeout(K);
241
+ ), g = [], k && clearTimeout(k);
222
242
  };
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());
243
+ }, [y, t, a]), u;
244
+ }
245
+ function le(e = !1) {
246
+ const [r, o] = A(/* @__PURE__ */ new Set()), [i, u] = A(!1), n = w(
247
+ (f) => {
248
+ f.code !== void 0 && (f.preventDefault(), f.stopPropagation(), o((p) => {
249
+ const t = new Set(p);
250
+ return t.add(K(e ? f.key : f.code)), t;
251
+ }));
252
+ },
253
+ [e]
254
+ ), c = w(() => {
255
+ typeof document < "u" && (document.removeEventListener("keydown", n), u(!1));
256
+ }, [n]), y = w(() => {
257
+ o(/* @__PURE__ */ new Set()), typeof document < "u" && (c(), document.addEventListener("keydown", n), u(!0));
258
+ }, [n, c]), d = w(() => {
259
+ o(/* @__PURE__ */ new Set());
237
260
  }, []);
238
- return [r, { start: d, stop: c, resetKeys: a, isRecording: f }];
261
+ return [r, { start: y, stop: c, resetKeys: d, isRecording: i }];
239
262
  }
240
263
  export {
241
- he as HotkeysProvider,
242
- ee as isHotkeyPressed,
243
- we as useHotkeys,
244
- le as useHotkeysContext,
245
- ge as useRecordHotkeys
264
+ de as HotkeysProvider,
265
+ U as isHotkeyPressed,
266
+ fe as useHotkeys,
267
+ se as useHotkeysContext,
268
+ le as useRecordHotkeys
246
269
  };
@@ -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;