react-hotkeys-hook 5.0.1 → 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.0.1",
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 I, useContext as q, useState as A, useCallback as w, useRef as S, useLayoutEffect as Q, useEffect as U } from "react";
2
- import { jsx as R } from "react/jsx-runtime";
3
- const F = ["shift", "alt", "meta", "mod", "ctrl", "control"], V = {
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,99 +18,108 @@ const F = ["shift", "alt", "meta", "mod", "ctrl", "control"], V = {
18
18
  ControlLeft: "ctrl",
19
19
  ControlRight: "ctrl"
20
20
  };
21
- function g(t) {
22
- return (V[t.trim()] || t.trim()).toLowerCase().replace(/key|digit|numpad/, "");
23
- }
24
- function X(t) {
25
- return F.includes(t);
26
- }
27
- function P(t, r = ",") {
28
- return t.toLowerCase().split(r);
29
- }
30
- function b(t, r = "+", n = !1, a) {
31
- const c = t.toLocaleLowerCase().split(r).map((i) => g(i)), l = {
32
- alt: c.includes("alt"),
33
- ctrl: c.includes("ctrl") || c.includes("control"),
34
- shift: c.includes("shift"),
35
- meta: c.includes("meta"),
36
- mod: c.includes("mod"),
37
- useKey: n
38
- }, o = c.filter((i) => !F.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));
39
41
  return {
40
- ...l,
41
- keys: o,
42
- description: a
42
+ ...y,
43
+ keys: d,
44
+ description: u,
45
+ isSequence: c,
46
+ hotkey: e
43
47
  };
44
48
  }
45
- typeof document < "u" && (document.addEventListener("keydown", (t) => {
46
- t.code !== void 0 && T([g(t.code)]);
47
- }), document.addEventListener("keyup", (t) => {
48
- t.code !== void 0 && W([g(t.code)]);
49
- })), typeof window < "u" && window.addEventListener("blur", () => {
50
- v.clear();
51
- });
52
- const v = /* @__PURE__ */ new Set();
53
- function B(t) {
54
- return Array.isArray(t);
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)]);
53
+ })), typeof window < "u" && (window.addEventListener("blur", () => {
54
+ L.clear();
55
+ }), window.addEventListener("contextmenu", () => {
56
+ setTimeout(() => {
57
+ L.clear();
58
+ }, 0);
59
+ }));
60
+ const L = /* @__PURE__ */ new Set();
61
+ function R(e) {
62
+ return Array.isArray(e);
55
63
  }
56
- function Y(t, r = ",") {
57
- return (B(t) ? t : t.split(r)).every((a) => v.has(a.trim().toLowerCase()));
64
+ function U(e, r = ",") {
65
+ return (R(e) ? e : e.split(r)).every((i) => L.has(i.trim().toLowerCase()));
58
66
  }
59
- function T(t) {
60
- const r = Array.isArray(t) ? t : [t];
61
- v.has("meta") && v.forEach((n) => !X(n) && v.delete(n.toLowerCase())), r.forEach((n) => v.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()));
62
70
  }
63
- function W(t) {
64
- const r = Array.isArray(t) ? t : [t];
65
- t === "meta" ? v.clear() : r.forEach((n) => v.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()));
66
74
  }
67
- function Z(t, r, n) {
68
- (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();
69
77
  }
70
- function $(t, r, n) {
71
- 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;
72
80
  }
73
- function _(t) {
74
- return z(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);
75
84
  }
76
- function z(t, r = !1) {
77
- const { target: n, composed: a } = t;
78
- let c;
79
- return m(n) && a ? c = t.composedPath()[0] && t.composedPath()[0].tagName : c = n && n.tagName, B(r) ? !!(c && r && r.some((l) => l.toLowerCase() === c.toLowerCase())) : !!(c && 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);
80
89
  }
81
- function m(t) {
82
- return !!t.tagName && !t.tagName.startsWith("-") && t.tagName.includes("-");
90
+ function ee(e) {
91
+ return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
83
92
  }
84
- function O(t, r) {
85
- return t.length === 0 && r ? (console.warn(
93
+ function te(e, r) {
94
+ return e.length === 0 && r ? (console.warn(
86
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>'
87
- ), !0) : r ? t.some((n) => r.includes(n)) || t.includes("*") : !0;
96
+ ), !0) : r ? e.some((o) => r.includes(o)) || e.includes("*") : !0;
88
97
  }
89
- const ee = (t, r, n = !1) => {
90
- const { alt: a, meta: c, mod: l, shift: o, ctrl: i, keys: f, useKey: y } = r, { code: k, key: e, ctrlKey: s, metaKey: d, shiftKey: C, altKey: H } = t, h = g(k);
91
- if (y && (f == null ? void 0 : f.length) === 1 && f.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))
92
101
  return !0;
93
- if (!(f != null && f.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))
94
103
  return !1;
95
- if (!n) {
96
- if (a !== H && h !== "alt" || o !== C && h !== "shift")
104
+ if (!o) {
105
+ if (i !== k && m !== "alt" || c !== g && m !== "shift")
97
106
  return !1;
98
- if (l) {
99
- if (!d && !s)
107
+ if (n) {
108
+ if (!l && !a)
100
109
  return !1;
101
- } else if (c !== d && h !== "meta" && h !== "os" || i !== s && h !== "ctrl" && h !== "control")
110
+ } else if (u !== l && m !== "meta" && m !== "os" || y !== a && m !== "ctrl" && m !== "control")
102
111
  return !1;
103
112
  }
104
- return f && f.length === 1 && f.includes(h) ? !0 : f ? Y(f) : !f;
105
- }, G = I(void 0), te = () => q(G);
106
- function re({ addHotkey: t, removeHotkey: r, children: n }) {
107
- return /* @__PURE__ */ R(G.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 });
108
117
  }
109
- function N(t, r) {
110
- return t && r && typeof t == "object" && typeof r == "object" ? Object.keys(t).length === Object.keys(r).length && // @ts-expect-error TS7053
111
- Object.keys(t).reduce((n, a) => n && N(t[a], r[a]), !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;
112
121
  }
113
- const J = I({
122
+ const W = T({
114
123
  hotkeys: [],
115
124
  activeScopes: [],
116
125
  // This array has to be empty instead of containing '*' as default, to check if the provider is set or not
@@ -120,101 +129,141 @@ const J = I({
120
129
  },
121
130
  disableScope: () => {
122
131
  }
123
- }), ne = () => q(J), fe = ({ initiallyActiveScopes: t = ["*"], children: r }) => {
124
- const [n, a] = A(t), [c, l] = A([]), o = w((e) => {
125
- a((s) => s.includes("*") ? [e] : Array.from(/* @__PURE__ */ new Set([...s, e])));
126
- }, []), i = w((e) => {
127
- a((s) => s.filter((d) => d !== e));
128
- }, []), f = w((e) => {
129
- a((s) => s.includes(e) ? s.filter((d) => d !== e) : s.includes("*") ? [e] : Array.from(/* @__PURE__ */ new Set([...s, e])));
130
- }, []), y = w((e) => {
131
- l((s) => [...s, e]);
132
- }, []), k = w((e) => {
133
- l((s) => s.filter((d) => !N(d, 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)));
134
143
  }, []);
135
- return /* @__PURE__ */ R(
136
- J.Provider,
144
+ return /* @__PURE__ */ b(
145
+ W.Provider,
137
146
  {
138
- value: { activeScopes: n, hotkeys: c, enableScope: o, disableScope: i, toggleScope: f },
139
- children: /* @__PURE__ */ R(re, { addHotkey: y, removeHotkey: k, 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 })
140
149
  }
141
150
  );
142
151
  };
143
- function oe(t) {
152
+ function ie(e) {
144
153
  const r = S(void 0);
145
- return N(r.current, t) || (r.current = t), r.current;
146
- }
147
- const D = (t) => {
148
- t.stopPropagation(), t.preventDefault(), t.stopImmediatePropagation();
149
- }, ce = typeof window < "u" ? Q : U;
150
- function se(t, r, n, a) {
151
- const c = S(null), l = S(!1), o = n instanceof Array ? a instanceof Array ? void 0 : a : n, i = B(t) ? t.join(o == null ? void 0 : o.delimiter) : t, f = n instanceof Array ? n : a instanceof Array ? a : void 0, y = w(r, f ?? []), k = S(y);
152
- f ? k.current = y : k.current = r;
153
- const e = oe(o), { activeScopes: s } = ne(), d = te();
154
- return ce(() => {
155
- if ((e == null ? void 0 : e.enabled) === !1 || !O(s, e == null ? void 0 : e.scopes))
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))
156
165
  return;
157
- const C = (u, p = !1) => {
158
- var j;
159
- if (!(_(u) && !z(u, e == null ? void 0 : e.enableOnFormTags))) {
160
- if (c.current !== null) {
161
- const E = c.current.getRootNode();
162
- if ((E instanceof Document || E instanceof ShadowRoot) && E.activeElement !== c.current && !c.current.contains(E.activeElement)) {
163
- D(u);
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);
164
173
  return;
165
174
  }
166
175
  }
167
- (j = u.target) != null && j.isContentEditable && !(e != null && e.enableOnContentEditable) || P(i, e == null ? void 0 : e.delimiter).forEach((E) => {
168
- var M, x;
169
- const L = b(E, e == null ? void 0 : e.splitKey, e == null ? void 0 : e.useKey, e == null ? void 0 : e.description);
170
- if (ee(u, L, e == null ? void 0 : e.ignoreModifiers) || (M = L.keys) != null && M.includes("*")) {
171
- if ((x = e == null ? void 0 : e.ignoreEventWhen) != null && x.call(e, u) || p && l.current)
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
+ );
181
+ return;
182
+ }
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()))
172
196
  return;
173
- if (Z(u, L, e == null ? void 0 : e.preventDefault), !$(u, L, e == null ? void 0 : e.enabled)) {
174
- D(u);
197
+ g.push(C);
198
+ const G = h.keys?.[g.length - 1];
199
+ if (C !== G) {
200
+ g = [], k && clearTimeout(k);
175
201
  return;
176
202
  }
177
- k.current(u, L), p || (l.current = !0);
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)
206
+ return;
207
+ if (V(s, h, t?.preventDefault), !X(s, h, t?.enabled)) {
208
+ N(s);
209
+ return;
210
+ }
211
+ p.current(s, h), B || (n.current = !0);
178
212
  }
179
213
  });
180
214
  }
181
- }, H = (u) => {
182
- u.code !== void 0 && (T(g(u.code)), ((e == null ? void 0 : e.keydown) === void 0 && (e == null ? void 0 : e.keyup) !== !0 || e != null && e.keydown) && C(u));
183
- }, h = (u) => {
184
- u.code !== void 0 && (W(g(u.code)), l.current = !1, e != null && e.keyup && C(u, !0));
185
- }, K = c.current || (o == null ? void 0 : o.document) || document;
186
- return K.addEventListener("keyup", h, o == null ? void 0 : o.eventListenerOptions), K.addEventListener("keydown", H, o == null ? void 0 : o.eventListenerOptions), d && P(i, e == null ? void 0 : e.delimiter).forEach(
187
- (u) => d.addHotkey(
188
- b(u, e == null ? void 0 : e.splitKey, 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
+ )
189
229
  )
190
230
  ), () => {
191
- K.removeEventListener("keyup", h, o == null ? void 0 : o.eventListenerOptions), K.removeEventListener("keydown", H, o == null ? void 0 : o.eventListenerOptions), d && P(i, e == null ? void 0 : e.delimiter).forEach(
192
- (u) => d.removeHotkey(
193
- b(u, e == null ? void 0 : e.splitKey, 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
+ )
194
240
  )
195
- );
241
+ ), g = [], k && clearTimeout(k);
196
242
  };
197
- }, [i, e, s]), c;
198
- }
199
- function le(t = !1) {
200
- const [r, n] = A(/* @__PURE__ */ new Set()), [a, c] = A(!1), l = w((y) => {
201
- y.code !== void 0 && (y.preventDefault(), y.stopPropagation(), n((k) => {
202
- const e = new Set(k);
203
- return e.add(g(t ? y.key : y.code)), e;
204
- }));
205
- }, [t]), o = w(() => {
206
- typeof document < "u" && (document.removeEventListener("keydown", l), c(!1));
207
- }, [l]), i = w(() => {
208
- n(/* @__PURE__ */ new Set()), typeof document < "u" && (o(), document.addEventListener("keydown", l), c(!0));
209
- }, [l, o]), f = w(() => {
210
- 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());
211
260
  }, []);
212
- return [r, { start: i, stop: o, resetKeys: f, isRecording: a }];
261
+ return [r, { start: y, stop: c, resetKeys: d, isRecording: i }];
213
262
  }
214
263
  export {
215
- fe as HotkeysProvider,
216
- Y as isHotkeyPressed,
217
- se as useHotkeys,
218
- ne as useHotkeysContext,
264
+ de as HotkeysProvider,
265
+ U as isHotkeyPressed,
266
+ fe as useHotkeys,
267
+ se as useHotkeysContext,
219
268
  le as useRecordHotkeys
220
269
  };
@@ -2,4 +2,4 @@ import { Hotkey } from './types';
2
2
  export declare function mapCode(key: string): string;
3
3
  export declare function isHotkeyModifier(key: string): boolean;
4
4
  export declare function parseKeysHookInput(keys: string, delimiter?: string): string[];
5
- export declare function parseHotkey(hotkey: string, splitKey?: string, useKey?: boolean, description?: string): Hotkey;
5
+ export declare function parseHotkey(hotkey: string, splitKey?: string, sequenceSplitKey?: string, useKey?: boolean, description?: string): Hotkey;
@@ -1,8 +1,7 @@
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
- export type RefType<T> = T | null;
6
5
  export type EventListenerOptions = {
7
6
  capture?: boolean;
8
7
  once?: boolean;
@@ -21,6 +20,8 @@ export type Hotkey = KeyboardModifiers & {
21
20
  keys?: readonly string[];
22
21
  scopes?: Scopes;
23
22
  description?: string;
23
+ isSequence?: boolean;
24
+ hotkey: string;
24
25
  };
25
26
  export type HotkeysEvent = Hotkey;
26
27
  export type HotkeyCallback = (keyboardEvent: KeyboardEvent, hotkeysEvent: HotkeysEvent) => void;
@@ -41,5 +42,7 @@ export type Options = {
41
42
  ignoreModifiers?: boolean;
42
43
  eventListenerOptions?: EventListenerOptions;
43
44
  useKey?: boolean;
45
+ sequenceTimeoutMs?: number;
46
+ sequenceSplitKey?: string;
44
47
  };
45
48
  export type OptionsOrDependencyArray = Options | DependencyList;
@@ -1,2 +1,2 @@
1
- import { HotkeyCallback, Keys, OptionsOrDependencyArray, RefType } from './types';
2
- export default function useHotkeys<T extends HTMLElement>(keys: Keys, callback: HotkeyCallback, options?: OptionsOrDependencyArray, dependencies?: OptionsOrDependencyArray): import('react').RefObject<RefType<T>>;
1
+ import { HotkeyCallback, Keys, OptionsOrDependencyArray } from './types';
2
+ export default function useHotkeys<T extends HTMLElement>(keys: Keys, callback: HotkeyCallback, options?: OptionsOrDependencyArray, dependencies?: OptionsOrDependencyArray): import('react').RefObject<T | null>;