react-hotkeys-hook 5.0.0-1 → 5.0.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.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/package.json +15 -83
  3. package/{dist → packages/react-hotkeys-hook/dist}/BoundHotkeysProxyProvider.d.ts +14 -14
  4. package/{dist → packages/react-hotkeys-hook/dist}/HotkeysProvider.d.ts +16 -16
  5. package/packages/react-hotkeys-hook/dist/deepEqual.d.ts +1 -0
  6. package/{dist → packages/react-hotkeys-hook/dist}/index.d.ts +6 -6
  7. package/packages/react-hotkeys-hook/dist/index.js +220 -0
  8. package/{dist → packages/react-hotkeys-hook/dist}/isHotkeyPressed.d.ts +4 -4
  9. package/{dist → packages/react-hotkeys-hook/dist}/parseHotkeys.d.ts +5 -5
  10. package/packages/react-hotkeys-hook/dist/types.d.ts +45 -0
  11. package/{dist → packages/react-hotkeys-hook/dist}/useDeepEqualMemo.d.ts +1 -1
  12. package/{dist → packages/react-hotkeys-hook/dist}/useHotkeys.d.ts +2 -3
  13. package/{dist → packages/react-hotkeys-hook/dist}/useRecordHotkeys.d.ts +6 -6
  14. package/{dist → packages/react-hotkeys-hook/dist}/validators.d.ts +8 -7
  15. package/dist/deepEqual.d.ts +0 -1
  16. package/dist/index.js +0 -8
  17. package/dist/react-hotkeys-hook.cjs.development.js +0 -525
  18. package/dist/react-hotkeys-hook.cjs.development.js.map +0 -1
  19. package/dist/react-hotkeys-hook.cjs.production.min.js +0 -2
  20. package/dist/react-hotkeys-hook.cjs.production.min.js.map +0 -1
  21. package/dist/react-hotkeys-hook.esm.js +0 -519
  22. package/dist/react-hotkeys-hook.esm.js.map +0 -1
  23. package/dist/setupTests.d.ts +0 -1
  24. package/dist/types.d.ts +0 -38
  25. package/src/BoundHotkeysProxyProvider.tsx +0 -27
  26. package/src/HotkeysProvider.tsx +0 -81
  27. package/src/deepEqual.ts +0 -8
  28. package/src/index.ts +0 -16
  29. package/src/isHotkeyPressed.ts +0 -71
  30. package/src/parseHotkeys.ts +0 -58
  31. package/src/types.ts +0 -61
  32. package/src/useDeepEqualMemo.ts +0 -12
  33. package/src/useHotkeys.ts +0 -176
  34. package/src/useRecordHotkeys.ts +0 -51
  35. package/src/validators.ts +0 -111
package/README.md CHANGED
@@ -136,7 +136,7 @@ useHotkeys(keys: string | string[], callback: (event: KeyboardEvent, handler: Ho
136
136
 
137
137
  | Parameter | Type | Required? | Default value | Description |
138
138
  |---------------|---------------------------------------------------------|-----------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
139
- | `keys` | `string` or `string[]` | required | - | set the hotkeys you want the hook to listen to. You can use single or multiple keys, modifier combinations, etc. This will either be a string or an array of strings. To separate multiple keys, use a colon. This split key value can be overridden with the `splitKey` option. |
139
+ | `keys` | `string` or `string[]` | required | - | set the hotkeys you want the hook to listen to. You can use single or multiple keys, modifier combinations, etc. This will either be a string or an array of strings. To separate multiple keys, use a comma. This split key value can be overridden with the `splitKey` option. |
140
140
  | `callback` | `(event: KeyboardEvent, handler: HotkeysEvent) => void` | required | - | This is the callback function that will be called when the hotkey is pressed. The callback will receive the browsers native `KeyboardEvent` and the libraries `HotkeysEvent`. |
141
141
  | `options` | `Options` | optional | `{}` | Object to modify the behavior of the hook. Default options are given below. |
142
142
  | `dependencies` | `DependencyList` | optional | `[]` | The given callback will always be memoised inside the hook. So if you reference any outside variables, you need to set them here for the callback to get updated (Much like `useCallback` works in React). |
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "react-hotkeys-hook",
3
3
  "description": "React hook for handling keyboard shortcuts",
4
- "version": "5.0.0-1",
4
+ "version": "5.0.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/JohannesKlauss/react-keymap-hook.git"
8
8
  },
9
9
  "homepage": "https://johannesklauss.github.io/react-hotkeys-hook/",
10
10
  "author": "Johannes Klauss",
11
- "main": "dist/index.js",
12
- "module": "dist/react-hotkeys-hook.esm.js",
13
- "types": "dist/index.d.ts",
11
+ "type": "module",
12
+ "main": "packages/react-hotkeys-hook/dist/index.js",
13
+ "types": "packages/react-hotkeys-hook/dist/index.d.ts",
14
14
  "files": [
15
- "dist",
16
- "src"
15
+ "packages/react-hotkeys-hook/dist"
17
16
  ],
18
17
  "keywords": [
19
18
  "react",
@@ -29,84 +28,17 @@
29
28
  ],
30
29
  "license": "MIT",
31
30
  "scripts": {
32
- "build": "tsdx build",
33
- "test": "jest",
34
- "publish": "np",
35
- "format": "prettier ./src/**/*.{ts,tsx} --write",
36
- "lint": "eslint ./src/**/*.{ts,tsx} --fix && prettier ./src/**/*.{ts,tsx} --check"
37
- },
38
- "babel": {
39
- "presets": [
40
- "@babel/preset-env",
41
- "@babel/preset-typescript",
42
- "@babel/preset-react"
43
- ]
44
- },
45
- "prettier": {
46
- "printWidth": 120,
47
- "semi": false,
48
- "singleQuote": true,
49
- "trailingComma": "es5"
50
- },
51
- "eslintConfig": {
52
- "env": {
53
- "browser": true,
54
- "es2021": true
55
- },
56
- "extends": [
57
- "eslint:recommended",
58
- "plugin:react/recommended",
59
- "plugin:@typescript-eslint/recommended"
60
- ],
61
- "parser": "@typescript-eslint/parser",
62
- "parserOptions": {
63
- "ecmaFeatures": {
64
- "jsx": true
65
- },
66
- "ecmaVersion": "latest",
67
- "sourceType": "module"
68
- },
69
- "plugins": [
70
- "react",
71
- "@typescript-eslint"
72
- ],
73
- "rules": {
74
- "react/react-in-jsx-scope": "off",
75
- "@typescript-eslint/no-empty-function": "off",
76
- "@typescript-eslint/no-explicit-any": "off",
77
- "@typescript-eslint/ban-ts-comment": "off"
78
- }
79
- },
80
- "devDependencies": {
81
- "@babel/core": "7.23.7",
82
- "@babel/plugin-proposal-class-properties": "7.18.6",
83
- "@babel/plugin-transform-react-jsx": "7.23.4",
84
- "@babel/preset-env": "7.23.7",
85
- "@babel/preset-react": "7.23.3",
86
- "@babel/preset-typescript": "7.23.3",
87
- "@testing-library/jest-dom": "5.17.0",
88
- "@testing-library/react": "14.1.2",
89
- "@testing-library/user-event": "14.5.2",
90
- "@types/jest": "29.5.11",
91
- "@types/react": "18.2.47",
92
- "@types/react-dom": "18.2.18",
93
- "@typescript-eslint/eslint-plugin": "5.60.0",
94
- "@typescript-eslint/parser": "5.60.0",
95
- "eslint": "8.56.0",
96
- "eslint-plugin-prettier": "4.2.1",
97
- "eslint-plugin-react": "7.33.2",
98
- "jest": "29.7.0",
99
- "jest-environment-jsdom": "29.7.0",
100
- "prettier": "2.8.8",
101
- "react": "18.2.0",
102
- "react-dom": "18.2.0",
103
- "react-test-renderer": "18.2.0",
104
- "tsdx": "0.14.1",
105
- "tslib": "2.6.2",
106
- "typescript": "5.3.3"
31
+ "build": "npm run -w packages/react-hotkeys-hook build",
32
+ "build:documentation": "npm run -w packages/documentation build",
33
+ "lint": "npm run -w packages/react-hotkeys-hook lint",
34
+ "test": "npm run -w packages/react-hotkeys-hook test",
35
+ "prepublishOnly": "npm run test && npm run lint && npm run build"
107
36
  },
37
+ "workspaces": [
38
+ "packages/*"
39
+ ],
108
40
  "peerDependencies": {
109
- "react": ">=16.8.1",
110
- "react-dom": ">=16.8.1"
41
+ "react": ">=16.8.0",
42
+ "react-dom": ">=16.8.0"
111
43
  }
112
44
  }
@@ -1,14 +1,14 @@
1
- import { ReactNode } from 'react';
2
- import { Hotkey } from './types';
3
- declare type BoundHotkeysProxyProviderType = {
4
- addHotkey: (hotkey: Hotkey) => void;
5
- removeHotkey: (hotkey: Hotkey) => void;
6
- };
7
- export declare const useBoundHotkeysProxy: () => BoundHotkeysProxyProviderType | undefined;
8
- interface Props {
9
- children: ReactNode;
10
- addHotkey: (hotkey: Hotkey) => void;
11
- removeHotkey: (hotkey: Hotkey) => void;
12
- }
13
- export default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props): import("react").JSX.Element;
14
- export {};
1
+ import { ReactNode } from 'react';
2
+ import { Hotkey } from './types';
3
+ type BoundHotkeysProxyProviderType = {
4
+ addHotkey: (hotkey: Hotkey) => void;
5
+ removeHotkey: (hotkey: Hotkey) => void;
6
+ };
7
+ export declare const useBoundHotkeysProxy: () => BoundHotkeysProxyProviderType | undefined;
8
+ interface Props {
9
+ children: ReactNode;
10
+ addHotkey: (hotkey: Hotkey) => void;
11
+ removeHotkey: (hotkey: Hotkey) => void;
12
+ }
13
+ export default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props): import("react/jsx-runtime").JSX.Element;
14
+ export {};
@@ -1,16 +1,16 @@
1
- import { Hotkey } from './types';
2
- import { ReactNode } from 'react';
3
- export declare type HotkeysContextType = {
4
- hotkeys: ReadonlyArray<Hotkey>;
5
- activeScopes: string[];
6
- toggleScope: (scope: string) => void;
7
- enableScope: (scope: string) => void;
8
- disableScope: (scope: string) => void;
9
- };
10
- export declare const useHotkeysContext: () => HotkeysContextType;
11
- interface Props {
12
- initiallyActiveScopes?: string[];
13
- children: ReactNode;
14
- }
15
- export declare const HotkeysProvider: ({ initiallyActiveScopes, children }: Props) => import("react").JSX.Element;
16
- export {};
1
+ import { Hotkey } from './types';
2
+ import { ReactNode } from 'react';
3
+ export type HotkeysContextType = {
4
+ hotkeys: ReadonlyArray<Hotkey>;
5
+ activeScopes: string[];
6
+ toggleScope: (scope: string) => void;
7
+ enableScope: (scope: string) => void;
8
+ disableScope: (scope: string) => void;
9
+ };
10
+ export declare const useHotkeysContext: () => HotkeysContextType;
11
+ interface Props {
12
+ initiallyActiveScopes?: string[];
13
+ children: ReactNode;
14
+ }
15
+ export declare const HotkeysProvider: ({ initiallyActiveScopes, children }: Props) => import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1 @@
1
+ export default function deepEqual(x?: unknown, y?: unknown): boolean;
@@ -1,6 +1,6 @@
1
- import useHotkeys from './useHotkeys';
2
- import type { Options, Keys, HotkeyCallback } from './types';
3
- import { HotkeysProvider, useHotkeysContext } from './HotkeysProvider';
4
- import { isHotkeyPressed } from './isHotkeyPressed';
5
- import useRecordHotkeys from './useRecordHotkeys';
6
- export { useHotkeys, useRecordHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, Options, Keys, HotkeyCallback, };
1
+ import { default as useHotkeys } from './useHotkeys';
2
+ import { Options, Keys, HotkeyCallback } from './types';
3
+ import { HotkeysProvider, useHotkeysContext } from './HotkeysProvider';
4
+ import { isHotkeyPressed } from './isHotkeyPressed';
5
+ import { default as useRecordHotkeys } from './useRecordHotkeys';
6
+ export { useHotkeys, useRecordHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, Options, Keys, HotkeyCallback, };
@@ -0,0 +1,220 @@
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 = {
4
+ esc: "escape",
5
+ return: "enter",
6
+ left: "arrowleft",
7
+ right: "arrowright",
8
+ up: "arrowup",
9
+ down: "arrowdown",
10
+ ShiftLeft: "shift",
11
+ ShiftRight: "shift",
12
+ AltLeft: "alt",
13
+ AltRight: "alt",
14
+ MetaLeft: "meta",
15
+ MetaRight: "meta",
16
+ OSLeft: "meta",
17
+ OSRight: "meta",
18
+ ControlLeft: "ctrl",
19
+ ControlRight: "ctrl"
20
+ };
21
+ function k(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 o = t.toLocaleLowerCase().split(r).map((i) => k(i)), l = {
32
+ alt: o.includes("alt"),
33
+ ctrl: o.includes("ctrl") || o.includes("control"),
34
+ shift: o.includes("shift"),
35
+ meta: o.includes("meta"),
36
+ mod: o.includes("mod"),
37
+ useKey: n
38
+ }, c = o.filter((i) => !F.includes(i));
39
+ return {
40
+ ...l,
41
+ keys: c,
42
+ description: a
43
+ };
44
+ }
45
+ typeof document < "u" && (document.addEventListener("keydown", (t) => {
46
+ t.code !== void 0 && T([k(t.code)]);
47
+ }), document.addEventListener("keyup", (t) => {
48
+ t.code !== void 0 && W([k(t.code)]);
49
+ })), typeof window < "u" && window.addEventListener("blur", () => {
50
+ g.clear();
51
+ });
52
+ const g = /* @__PURE__ */ new Set();
53
+ function B(t) {
54
+ return Array.isArray(t);
55
+ }
56
+ function Y(t, r = ",") {
57
+ return (B(t) ? t : t.split(r)).every((a) => g.has(a.trim().toLowerCase()));
58
+ }
59
+ function T(t) {
60
+ const r = Array.isArray(t) ? t : [t];
61
+ g.has("meta") && g.forEach((n) => !X(n) && g.delete(n.toLowerCase())), r.forEach((n) => g.add(n.toLowerCase()));
62
+ }
63
+ function W(t) {
64
+ const r = Array.isArray(t) ? t : [t];
65
+ t === "meta" ? g.clear() : r.forEach((n) => g.delete(n.toLowerCase()));
66
+ }
67
+ function Z(t, r, n) {
68
+ (typeof n == "function" && n(t, r) || n === !0) && t.preventDefault();
69
+ }
70
+ function $(t, r, n) {
71
+ return typeof n == "function" ? n(t, r) : n === !0 || n === void 0;
72
+ }
73
+ function _(t) {
74
+ return z(t, ["input", "textarea", "select"]);
75
+ }
76
+ function z(t, r = !1) {
77
+ const { target: n, composed: a } = t;
78
+ let o;
79
+ return m(n) && a ? o = t.composedPath()[0] && t.composedPath()[0].tagName : o = n && n.tagName, B(r) ? !!(o && r && r.some((l) => l.toLowerCase() === o.toLowerCase())) : !!(o && r && r);
80
+ }
81
+ function m(t) {
82
+ return !!t.tagName && !t.tagName.startsWith("-") && t.tagName.includes("-");
83
+ }
84
+ function O(t, r) {
85
+ return t.length === 0 && r ? (console.warn(
86
+ '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;
88
+ }
89
+ const ee = (t, r, n = !1) => {
90
+ const { alt: a, meta: o, mod: l, shift: c, ctrl: i, keys: u, useKey: v } = r, { code: h, key: e, ctrlKey: s, metaKey: d, shiftKey: C, altKey: K } = t, y = k(h);
91
+ if (v && (u == null ? void 0 : u.length) === 1 && u.includes(e))
92
+ return !0;
93
+ if (!(u != null && u.includes(y)) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(y))
94
+ return !1;
95
+ if (!n) {
96
+ if (a !== K && y !== "alt" || c !== C && y !== "shift")
97
+ return !1;
98
+ if (l) {
99
+ if (!d && !s)
100
+ return !1;
101
+ } else if (o !== d && y !== "meta" && y !== "os" || i !== s && y !== "ctrl" && y !== "control")
102
+ return !1;
103
+ }
104
+ return u && u.length === 1 && u.includes(y) ? !0 : u ? Y(u) : !u;
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 });
108
+ }
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;
112
+ }
113
+ const J = I({
114
+ hotkeys: [],
115
+ activeScopes: [],
116
+ // This array has to be empty instead of containing '*' as default, to check if the provider is set or not
117
+ toggleScope: () => {
118
+ },
119
+ enableScope: () => {
120
+ },
121
+ disableScope: () => {
122
+ }
123
+ }), ne = () => q(J), fe = ({ initiallyActiveScopes: t = ["*"], children: r }) => {
124
+ const [n, a] = A(t), [o, l] = A([]), c = 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
+ }, []), u = w((e) => {
129
+ a((s) => s.includes(e) ? s.filter((d) => d !== e) : s.includes("*") ? [e] : Array.from(/* @__PURE__ */ new Set([...s, e])));
130
+ }, []), v = w((e) => {
131
+ l((s) => [...s, e]);
132
+ }, []), h = w((e) => {
133
+ l((s) => s.filter((d) => !N(d, e)));
134
+ }, []);
135
+ return /* @__PURE__ */ R(
136
+ J.Provider,
137
+ {
138
+ value: { activeScopes: n, hotkeys: o, enableScope: c, disableScope: i, toggleScope: u },
139
+ children: /* @__PURE__ */ R(re, { addHotkey: v, removeHotkey: h, children: r })
140
+ }
141
+ );
142
+ };
143
+ function oe(t) {
144
+ 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 o = S(null), l = S(!1), c = n instanceof Array ? a instanceof Array ? void 0 : a : n, i = B(t) ? t.join(c == null ? void 0 : c.delimiter) : t, u = n instanceof Array ? n : a instanceof Array ? a : void 0, v = w(r, u ?? []), h = S(v);
152
+ u ? h.current = v : h.current = r;
153
+ const e = oe(c), { 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))
156
+ return;
157
+ const C = (f, p = !1) => {
158
+ var j;
159
+ if (!(_(f) && !z(f, e == null ? void 0 : e.enableOnFormTags))) {
160
+ if (o.current !== null) {
161
+ const E = o.current.getRootNode();
162
+ if ((E instanceof Document || E instanceof ShadowRoot) && E.activeElement !== o.current && !o.current.contains(E.activeElement)) {
163
+ D(f);
164
+ return;
165
+ }
166
+ }
167
+ (j = f.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(f, 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, f) || p && l.current)
172
+ return;
173
+ if (Z(f, L, e == null ? void 0 : e.preventDefault), !$(f, L, e == null ? void 0 : e.enabled)) {
174
+ D(f);
175
+ return;
176
+ }
177
+ h.current(f, L), p || (l.current = !0);
178
+ }
179
+ });
180
+ }
181
+ }, K = (f) => {
182
+ f.code !== void 0 && (T(k(f.code)), ((e == null ? void 0 : e.keydown) === void 0 && (e == null ? void 0 : e.keyup) !== !0 || e != null && e.keydown) && C(f));
183
+ }, y = (f) => {
184
+ f.code !== void 0 && (W(k(f.code)), l.current = !1, e != null && e.keyup && C(f, !0));
185
+ }, H = o.current || (c == null ? void 0 : c.document) || document;
186
+ return H.addEventListener("keyup", y, c == null ? void 0 : c.eventListenerOptions), H.addEventListener("keydown", K, c == null ? void 0 : c.eventListenerOptions), d && P(i, e == null ? void 0 : e.delimiter).forEach(
187
+ (f) => d.addHotkey(
188
+ b(f, e == null ? void 0 : e.splitKey, e == null ? void 0 : e.useKey, e == null ? void 0 : e.description)
189
+ )
190
+ ), () => {
191
+ H.removeEventListener("keyup", y, c == null ? void 0 : c.eventListenerOptions), H.removeEventListener("keydown", K, c == null ? void 0 : c.eventListenerOptions), d && P(i, e == null ? void 0 : e.delimiter).forEach(
192
+ (f) => d.removeHotkey(
193
+ b(f, e == null ? void 0 : e.splitKey, e == null ? void 0 : e.useKey, e == null ? void 0 : e.description)
194
+ )
195
+ );
196
+ };
197
+ }, [i, e, s]), o;
198
+ }
199
+ function le() {
200
+ const [t, r] = A(/* @__PURE__ */ new Set()), [n, a] = A(!1), o = w((u) => {
201
+ u.code !== void 0 && (u.preventDefault(), u.stopPropagation(), r((v) => {
202
+ const h = new Set(v);
203
+ return h.add(k(u.code)), h;
204
+ }));
205
+ }, []), l = w(() => {
206
+ typeof document < "u" && (document.removeEventListener("keydown", o), a(!1));
207
+ }, [o]), c = w(() => {
208
+ r(/* @__PURE__ */ new Set()), typeof document < "u" && (l(), document.addEventListener("keydown", o), a(!0));
209
+ }, [o, l]), i = w(() => {
210
+ r(/* @__PURE__ */ new Set());
211
+ }, []);
212
+ return [t, { start: c, stop: l, resetKeys: i, isRecording: n }];
213
+ }
214
+ export {
215
+ fe as HotkeysProvider,
216
+ Y as isHotkeyPressed,
217
+ se as useHotkeys,
218
+ ne as useHotkeysContext,
219
+ le as useRecordHotkeys
220
+ };
@@ -1,4 +1,4 @@
1
- export declare function isReadonlyArray(value: unknown): value is readonly unknown[];
2
- export declare function isHotkeyPressed(key: string | readonly string[], delimiter?: string): boolean;
3
- export declare function pushToCurrentlyPressedKeys(key: string | string[]): void;
4
- export declare function removeFromCurrentlyPressedKeys(key: string | string[]): void;
1
+ export declare function isReadonlyArray(value: unknown): value is readonly unknown[];
2
+ export declare function isHotkeyPressed(key: string | readonly string[], delimiter?: string): boolean;
3
+ export declare function pushToCurrentlyPressedKeys(key: string | string[]): void;
4
+ export declare function removeFromCurrentlyPressedKeys(key: string | string[]): void;
@@ -1,5 +1,5 @@
1
- import { Hotkey } from './types';
2
- export declare function mapKey(key: string): string;
3
- export declare function isHotkeyModifier(key: string): boolean;
4
- export declare function parseKeysHookInput(keys: string, delimiter?: string): string[];
5
- export declare function parseHotkey(hotkey: string, splitKey?: string, useKey?: boolean, description?: string): Hotkey;
1
+ import { Hotkey } from './types';
2
+ export declare function mapCode(key: string): string;
3
+ export declare function isHotkeyModifier(key: string): boolean;
4
+ export declare function parseKeysHookInput(keys: string, delimiter?: string): string[];
5
+ export declare function parseHotkey(hotkey: string, splitKey?: string, useKey?: boolean, description?: string): Hotkey;
@@ -0,0 +1,45 @@
1
+ import { DependencyList } from 'react';
2
+ export type FormTags = 'input' | 'textarea' | 'select' | 'INPUT' | 'TEXTAREA' | 'SELECT';
3
+ export type Keys = string | readonly string[];
4
+ export type Scopes = string | readonly string[];
5
+ export type RefType<T> = T | null;
6
+ export type EventListenerOptions = {
7
+ capture?: boolean;
8
+ once?: boolean;
9
+ passive?: boolean;
10
+ signal?: AbortSignal;
11
+ } | boolean;
12
+ export type KeyboardModifiers = {
13
+ alt?: boolean;
14
+ ctrl?: boolean;
15
+ meta?: boolean;
16
+ shift?: boolean;
17
+ mod?: boolean;
18
+ useKey?: boolean;
19
+ };
20
+ export type Hotkey = KeyboardModifiers & {
21
+ keys?: readonly string[];
22
+ scopes?: Scopes;
23
+ description?: string;
24
+ };
25
+ export type HotkeysEvent = Hotkey;
26
+ export type HotkeyCallback = (keyboardEvent: KeyboardEvent, hotkeysEvent: HotkeysEvent) => void;
27
+ export type Trigger = boolean | ((keyboardEvent: KeyboardEvent, hotkeysEvent: HotkeysEvent) => boolean);
28
+ export type Options = {
29
+ enabled?: Trigger;
30
+ enableOnFormTags?: readonly FormTags[] | boolean;
31
+ enableOnContentEditable?: boolean;
32
+ ignoreEventWhen?: (e: KeyboardEvent) => boolean;
33
+ splitKey?: string;
34
+ delimiter?: string;
35
+ scopes?: Scopes;
36
+ keyup?: boolean;
37
+ keydown?: boolean;
38
+ preventDefault?: Trigger;
39
+ description?: string;
40
+ document?: Document;
41
+ ignoreModifiers?: boolean;
42
+ eventListenerOptions?: EventListenerOptions;
43
+ useKey?: boolean;
44
+ };
45
+ export type OptionsOrDependencyArray = Options | DependencyList;
@@ -1 +1 @@
1
- export default function useDeepEqualMemo<T>(value: T): T | undefined;
1
+ export default function useDeepEqualMemo<T>(value: T): T | undefined;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
- import { HotkeyCallback, Keys, OptionsOrDependencyArray, RefType } from './types';
3
- export default function useHotkeys<T extends HTMLElement>(keys: Keys, callback: HotkeyCallback, options?: OptionsOrDependencyArray, dependencies?: OptionsOrDependencyArray): import("react").MutableRefObject<RefType<T>>;
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,6 +1,6 @@
1
- export default function useRecordHotkeys(): readonly [Set<string>, {
2
- readonly start: () => void;
3
- readonly stop: () => void;
4
- readonly resetKeys: () => void;
5
- readonly isRecording: boolean;
6
- }];
1
+ export default function useRecordHotkeys(): readonly [Set<string>, {
2
+ readonly start: () => void;
3
+ readonly stop: () => void;
4
+ readonly resetKeys: () => void;
5
+ readonly isRecording: boolean;
6
+ }];
@@ -1,7 +1,8 @@
1
- import { FormTags, Hotkey, Scopes, Trigger } from './types';
2
- export declare function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void;
3
- export declare function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean;
4
- export declare function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean;
5
- export declare function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags?: readonly FormTags[] | boolean): boolean;
6
- export declare function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean;
7
- export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers?: boolean) => boolean;
1
+ import { FormTags, Hotkey, Scopes, Trigger } from './types';
2
+ export declare function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void;
3
+ export declare function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean;
4
+ export declare function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean;
5
+ export declare function isHotkeyEnabledOnTag(event: KeyboardEvent, enabledOnTags?: readonly FormTags[] | boolean): boolean;
6
+ export declare function isCustomElement(element: HTMLElement): boolean;
7
+ export declare function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean;
8
+ export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers?: boolean) => boolean;
@@ -1 +0,0 @@
1
- export default function deepEqual(x: any, y: any): boolean;
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./react-hotkeys-hook.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./react-hotkeys-hook.cjs.development.js')
8
- }