react-hotkeys-hook 4.4.2 → 4.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +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 {};
@@ -0,0 +1,16 @@
1
+ import { Hotkey } from './types';
2
+ import { ReactNode } from 'react';
3
+ export declare type HotkeysContextType = {
4
+ hotkeys: ReadonlyArray<Hotkey>;
5
+ enabledScopes: 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 {};
@@ -0,0 +1 @@
1
+ export default function deepEqual(x: any, y: any): boolean;
@@ -0,0 +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, };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,4 @@
1
+ export declare function isReadonlyArray(value: unknown): value is readonly unknown[];
2
+ export declare function isHotkeyPressed(key: string | readonly string[], splitKey?: string): boolean;
3
+ export declare function pushToCurrentlyPressedKeys(key: string | string[]): void;
4
+ export declare function removeFromCurrentlyPressedKeys(key: string | string[]): void;
@@ -0,0 +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, splitKey?: string): string[];
5
+ export declare function parseHotkey(hotkey: string, combinationKey?: string, description?: string): Hotkey;
@@ -0,0 +1,529 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ function _extends() {
7
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
8
+ for (var i = 1; i < arguments.length; i++) {
9
+ var source = arguments[i];
10
+ for (var key in source) {
11
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
12
+ target[key] = source[key];
13
+ }
14
+ }
15
+ }
16
+ return target;
17
+ };
18
+ return _extends.apply(this, arguments);
19
+ }
20
+
21
+ var reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl'];
22
+ var mappedKeys = {
23
+ esc: 'escape',
24
+ "return": 'enter',
25
+ '.': 'period',
26
+ ',': 'comma',
27
+ '-': 'slash',
28
+ ' ': 'space',
29
+ '`': 'backquote',
30
+ '#': 'backslash',
31
+ '+': 'bracketright',
32
+ ShiftLeft: 'shift',
33
+ ShiftRight: 'shift',
34
+ AltLeft: 'alt',
35
+ AltRight: 'alt',
36
+ MetaLeft: 'meta',
37
+ MetaRight: 'meta',
38
+ OSLeft: 'meta',
39
+ OSRight: 'meta',
40
+ ControlLeft: 'ctrl',
41
+ ControlRight: 'ctrl'
42
+ };
43
+ function mapKey(key) {
44
+ return (mappedKeys[key] || key).trim().toLowerCase().replace(/key|digit|numpad|arrow/, '');
45
+ }
46
+ function isHotkeyModifier(key) {
47
+ return reservedModifierKeywords.includes(key);
48
+ }
49
+ function parseKeysHookInput(keys, splitKey) {
50
+ if (splitKey === void 0) {
51
+ splitKey = ',';
52
+ }
53
+ return keys.split(splitKey);
54
+ }
55
+ function parseHotkey(hotkey, combinationKey, description) {
56
+ if (combinationKey === void 0) {
57
+ combinationKey = '+';
58
+ }
59
+ var keys = hotkey.toLocaleLowerCase().split(combinationKey).map(function (k) {
60
+ return mapKey(k);
61
+ });
62
+ var modifiers = {
63
+ alt: keys.includes('alt'),
64
+ ctrl: keys.includes('ctrl') || keys.includes('control'),
65
+ shift: keys.includes('shift'),
66
+ meta: keys.includes('meta'),
67
+ mod: keys.includes('mod')
68
+ };
69
+ var singleCharKeys = keys.filter(function (k) {
70
+ return !reservedModifierKeywords.includes(k);
71
+ });
72
+ return _extends({}, modifiers, {
73
+ keys: singleCharKeys,
74
+ description: description
75
+ });
76
+ }
77
+
78
+ (function () {
79
+ if (typeof document !== 'undefined') {
80
+ document.addEventListener('keydown', function (e) {
81
+ if (e.key === undefined) {
82
+ // Synthetic event (e.g., Chrome autofill). Ignore.
83
+ return;
84
+ }
85
+ pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)]);
86
+ });
87
+ document.addEventListener('keyup', function (e) {
88
+ if (e.key === undefined) {
89
+ // Synthetic event (e.g., Chrome autofill). Ignore.
90
+ return;
91
+ }
92
+ removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)]);
93
+ });
94
+ }
95
+ if (typeof window !== 'undefined') {
96
+ window.addEventListener('blur', function () {
97
+ currentlyPressedKeys.clear();
98
+ });
99
+ }
100
+ })();
101
+ var currentlyPressedKeys = /*#__PURE__*/new Set();
102
+ // https://github.com/microsoft/TypeScript/issues/17002
103
+ function isReadonlyArray(value) {
104
+ return Array.isArray(value);
105
+ }
106
+ function isHotkeyPressed(key, splitKey) {
107
+ if (splitKey === void 0) {
108
+ splitKey = ',';
109
+ }
110
+ var hotkeyArray = isReadonlyArray(key) ? key : key.split(splitKey);
111
+ return hotkeyArray.every(function (hotkey) {
112
+ return currentlyPressedKeys.has(hotkey.trim().toLowerCase());
113
+ });
114
+ }
115
+ function pushToCurrentlyPressedKeys(key) {
116
+ var hotkeyArray = Array.isArray(key) ? key : [key];
117
+ /*
118
+ Due to a weird behavior on macOS we need to clear the set if the user pressed down the meta key and presses another key.
119
+ https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser
120
+ Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.
121
+ */
122
+ if (currentlyPressedKeys.has('meta')) {
123
+ currentlyPressedKeys.forEach(function (key) {
124
+ return !isHotkeyModifier(key) && currentlyPressedKeys["delete"](key.toLowerCase());
125
+ });
126
+ }
127
+ hotkeyArray.forEach(function (hotkey) {
128
+ return currentlyPressedKeys.add(hotkey.toLowerCase());
129
+ });
130
+ }
131
+ function removeFromCurrentlyPressedKeys(key) {
132
+ var hotkeyArray = Array.isArray(key) ? key : [key];
133
+ /*
134
+ Due to a weird behavior on macOS we need to clear the set if the user pressed down the meta key and presses another key.
135
+ https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser
136
+ Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.
137
+ */
138
+ if (key === 'meta') {
139
+ currentlyPressedKeys.clear();
140
+ } else {
141
+ hotkeyArray.forEach(function (hotkey) {
142
+ return currentlyPressedKeys["delete"](hotkey.toLowerCase());
143
+ });
144
+ }
145
+ }
146
+
147
+ function maybePreventDefault(e, hotkey, preventDefault) {
148
+ if (typeof preventDefault === 'function' && preventDefault(e, hotkey) || preventDefault === true) {
149
+ e.preventDefault();
150
+ }
151
+ }
152
+ function isHotkeyEnabled(e, hotkey, enabled) {
153
+ if (typeof enabled === 'function') {
154
+ return enabled(e, hotkey);
155
+ }
156
+ return enabled === true || enabled === undefined;
157
+ }
158
+ function isKeyboardEventTriggeredByInput(ev) {
159
+ return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select']);
160
+ }
161
+ function isHotkeyEnabledOnTag(_ref, enabledOnTags) {
162
+ var target = _ref.target;
163
+ if (enabledOnTags === void 0) {
164
+ enabledOnTags = false;
165
+ }
166
+ var targetTagName = target && target.tagName;
167
+ if (isReadonlyArray(enabledOnTags)) {
168
+ return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(function (tag) {
169
+ return tag.toLowerCase() === targetTagName.toLowerCase();
170
+ }));
171
+ }
172
+ return Boolean(targetTagName && enabledOnTags && enabledOnTags === true);
173
+ }
174
+ function isScopeActive(activeScopes, scopes) {
175
+ if (activeScopes.length === 0 && scopes) {
176
+ console.warn('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>');
177
+ return true;
178
+ }
179
+ if (!scopes) {
180
+ return true;
181
+ }
182
+ return activeScopes.some(function (scope) {
183
+ return scopes.includes(scope);
184
+ }) || activeScopes.includes('*');
185
+ }
186
+ var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey, ignoreModifiers) {
187
+ if (ignoreModifiers === void 0) {
188
+ ignoreModifiers = false;
189
+ }
190
+ var alt = hotkey.alt,
191
+ meta = hotkey.meta,
192
+ mod = hotkey.mod,
193
+ shift = hotkey.shift,
194
+ ctrl = hotkey.ctrl,
195
+ keys = hotkey.keys;
196
+ var pressedKeyUppercase = e.key,
197
+ code = e.code,
198
+ ctrlKey = e.ctrlKey,
199
+ metaKey = e.metaKey,
200
+ shiftKey = e.shiftKey,
201
+ altKey = e.altKey;
202
+ var keyCode = mapKey(code);
203
+ var pressedKey = pressedKeyUppercase.toLowerCase();
204
+ if (!(keys != null && keys.includes(keyCode)) && !['ctrl', 'control', 'unknown', 'meta', 'alt', 'shift', 'os'].includes(keyCode)) {
205
+ return false;
206
+ }
207
+ if (!ignoreModifiers) {
208
+ // We check the pressed keys for compatibility with the keyup event. In keyup events the modifier flags are not set.
209
+ if (alt === !altKey && pressedKey !== 'alt') {
210
+ return false;
211
+ }
212
+ if (shift === !shiftKey && pressedKey !== 'shift') {
213
+ return false;
214
+ }
215
+ // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
216
+ if (mod) {
217
+ if (!metaKey && !ctrlKey) {
218
+ return false;
219
+ }
220
+ } else {
221
+ if (meta === !metaKey && pressedKey !== 'meta' && pressedKey !== 'os') {
222
+ return false;
223
+ }
224
+ if (ctrl === !ctrlKey && pressedKey !== 'ctrl' && pressedKey !== 'control') {
225
+ return false;
226
+ }
227
+ }
228
+ }
229
+ // All modifiers are correct, now check the key
230
+ // If the key is set, we check for the key
231
+ if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {
232
+ return true;
233
+ } else if (keys) {
234
+ // Check if all keys are present in pressedDownKeys set
235
+ return isHotkeyPressed(keys);
236
+ } else if (!keys) {
237
+ // If the key is not set, we only listen for modifiers, that check went alright, so we return true
238
+ return true;
239
+ }
240
+ // There is nothing that matches.
241
+ return false;
242
+ };
243
+
244
+ var BoundHotkeysProxyProvider = /*#__PURE__*/react.createContext(undefined);
245
+ var useBoundHotkeysProxy = function useBoundHotkeysProxy() {
246
+ return react.useContext(BoundHotkeysProxyProvider);
247
+ };
248
+ function BoundHotkeysProxyProviderProvider(_ref) {
249
+ var addHotkey = _ref.addHotkey,
250
+ removeHotkey = _ref.removeHotkey,
251
+ children = _ref.children;
252
+ return /*#__PURE__*/jsxRuntime.jsx(BoundHotkeysProxyProvider.Provider, {
253
+ value: {
254
+ addHotkey: addHotkey,
255
+ removeHotkey: removeHotkey
256
+ },
257
+ children: children
258
+ });
259
+ }
260
+
261
+ function deepEqual(x, y) {
262
+ //@ts-ignore
263
+ return x && y && typeof x === 'object' && typeof y === 'object' ? Object.keys(x).length === Object.keys(y).length &&
264
+ //@ts-ignore
265
+ Object.keys(x).reduce(function (isEqual, key) {
266
+ return isEqual && deepEqual(x[key], y[key]);
267
+ }, true) : x === y;
268
+ }
269
+
270
+ var HotkeysContext = /*#__PURE__*/react.createContext({
271
+ hotkeys: [],
272
+ enabledScopes: [],
273
+ toggleScope: function toggleScope() {},
274
+ enableScope: function enableScope() {},
275
+ disableScope: function disableScope() {}
276
+ });
277
+ var useHotkeysContext = function useHotkeysContext() {
278
+ return react.useContext(HotkeysContext);
279
+ };
280
+ var HotkeysProvider = function HotkeysProvider(_ref) {
281
+ var _ref$initiallyActiveS = _ref.initiallyActiveScopes,
282
+ initiallyActiveScopes = _ref$initiallyActiveS === void 0 ? ['*'] : _ref$initiallyActiveS,
283
+ children = _ref.children;
284
+ var _useState = react.useState((initiallyActiveScopes == null ? void 0 : initiallyActiveScopes.length) > 0 ? initiallyActiveScopes : ['*']),
285
+ internalActiveScopes = _useState[0],
286
+ setInternalActiveScopes = _useState[1];
287
+ var _useState2 = react.useState([]),
288
+ boundHotkeys = _useState2[0],
289
+ setBoundHotkeys = _useState2[1];
290
+ var enableScope = react.useCallback(function (scope) {
291
+ setInternalActiveScopes(function (prev) {
292
+ if (prev.includes('*')) {
293
+ return [scope];
294
+ }
295
+ return Array.from(new Set([].concat(prev, [scope])));
296
+ });
297
+ }, []);
298
+ var disableScope = react.useCallback(function (scope) {
299
+ setInternalActiveScopes(function (prev) {
300
+ if (prev.filter(function (s) {
301
+ return s !== scope;
302
+ }).length === 0) {
303
+ return ['*'];
304
+ } else {
305
+ return prev.filter(function (s) {
306
+ return s !== scope;
307
+ });
308
+ }
309
+ });
310
+ }, []);
311
+ var toggleScope = react.useCallback(function (scope) {
312
+ setInternalActiveScopes(function (prev) {
313
+ if (prev.includes(scope)) {
314
+ if (prev.filter(function (s) {
315
+ return s !== scope;
316
+ }).length === 0) {
317
+ return ['*'];
318
+ } else {
319
+ return prev.filter(function (s) {
320
+ return s !== scope;
321
+ });
322
+ }
323
+ } else {
324
+ if (prev.includes('*')) {
325
+ return [scope];
326
+ }
327
+ return Array.from(new Set([].concat(prev, [scope])));
328
+ }
329
+ });
330
+ }, []);
331
+ var addBoundHotkey = react.useCallback(function (hotkey) {
332
+ setBoundHotkeys(function (prev) {
333
+ return [].concat(prev, [hotkey]);
334
+ });
335
+ }, []);
336
+ var removeBoundHotkey = react.useCallback(function (hotkey) {
337
+ setBoundHotkeys(function (prev) {
338
+ return prev.filter(function (h) {
339
+ return !deepEqual(h, hotkey);
340
+ });
341
+ });
342
+ }, []);
343
+ return /*#__PURE__*/jsxRuntime.jsx(HotkeysContext.Provider, {
344
+ value: {
345
+ enabledScopes: internalActiveScopes,
346
+ hotkeys: boundHotkeys,
347
+ enableScope: enableScope,
348
+ disableScope: disableScope,
349
+ toggleScope: toggleScope
350
+ },
351
+ children: /*#__PURE__*/jsxRuntime.jsx(BoundHotkeysProxyProviderProvider, {
352
+ addHotkey: addBoundHotkey,
353
+ removeHotkey: removeBoundHotkey,
354
+ children: children
355
+ })
356
+ });
357
+ };
358
+
359
+ function useDeepEqualMemo(value) {
360
+ var ref = react.useRef(undefined);
361
+ if (!deepEqual(ref.current, value)) {
362
+ ref.current = value;
363
+ }
364
+ return ref.current;
365
+ }
366
+
367
+ var stopPropagation = function stopPropagation(e) {
368
+ e.stopPropagation();
369
+ e.preventDefault();
370
+ e.stopImmediatePropagation();
371
+ };
372
+ var useSafeLayoutEffect = typeof window !== 'undefined' ? react.useLayoutEffect : react.useEffect;
373
+ function useHotkeys(keys, callback, options, dependencies) {
374
+ var ref = react.useRef(null);
375
+ var hasTriggeredRef = react.useRef(false);
376
+ var _options = !(options instanceof Array) ? options : !(dependencies instanceof Array) ? dependencies : undefined;
377
+ var _keys = isReadonlyArray(keys) ? keys.join(_options == null ? void 0 : _options.splitKey) : keys;
378
+ var _deps = options instanceof Array ? options : dependencies instanceof Array ? dependencies : undefined;
379
+ var memoisedCB = react.useCallback(callback, _deps != null ? _deps : []);
380
+ var cbRef = react.useRef(memoisedCB);
381
+ if (_deps) {
382
+ cbRef.current = memoisedCB;
383
+ } else {
384
+ cbRef.current = callback;
385
+ }
386
+ var memoisedOptions = useDeepEqualMemo(_options);
387
+ var _useHotkeysContext = useHotkeysContext(),
388
+ enabledScopes = _useHotkeysContext.enabledScopes;
389
+ var proxy = useBoundHotkeysProxy();
390
+ useSafeLayoutEffect(function () {
391
+ if ((memoisedOptions == null ? void 0 : memoisedOptions.enabled) === false || !isScopeActive(enabledScopes, memoisedOptions == null ? void 0 : memoisedOptions.scopes)) {
392
+ return;
393
+ }
394
+ var listener = function listener(e, isKeyUp) {
395
+ var _e$target;
396
+ if (isKeyUp === void 0) {
397
+ isKeyUp = false;
398
+ }
399
+ if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions == null ? void 0 : memoisedOptions.enableOnFormTags)) {
400
+ return;
401
+ }
402
+ // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE
403
+ // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WON'T TRIGGER THE HOTKEY.
404
+ if (ref.current !== null) {
405
+ var rootNode = ref.current.getRootNode();
406
+ if ((rootNode instanceof Document || rootNode instanceof ShadowRoot) && rootNode.activeElement !== ref.current && !ref.current.contains(rootNode.activeElement)) {
407
+ stopPropagation(e);
408
+ return;
409
+ }
410
+ }
411
+ if ((_e$target = e.target) != null && _e$target.isContentEditable && !(memoisedOptions != null && memoisedOptions.enableOnContentEditable)) {
412
+ return;
413
+ }
414
+ parseKeysHookInput(_keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
415
+ var _hotkey$keys;
416
+ var hotkey = parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey);
417
+ if (isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.ignoreModifiers) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) {
418
+ if (memoisedOptions != null && memoisedOptions.ignoreEventWhen != null && memoisedOptions.ignoreEventWhen(e)) {
419
+ return;
420
+ }
421
+ if (isKeyUp && hasTriggeredRef.current) {
422
+ return;
423
+ }
424
+ maybePreventDefault(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.preventDefault);
425
+ if (!isHotkeyEnabled(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.enabled)) {
426
+ stopPropagation(e);
427
+ return;
428
+ }
429
+ // Execute the user callback for that hotkey
430
+ cbRef.current(e, hotkey);
431
+ if (!isKeyUp) {
432
+ hasTriggeredRef.current = true;
433
+ }
434
+ }
435
+ });
436
+ };
437
+ var handleKeyDown = function handleKeyDown(event) {
438
+ if (event.key === undefined) {
439
+ // Synthetic event (e.g., Chrome autofill). Ignore.
440
+ return;
441
+ }
442
+ pushToCurrentlyPressedKeys(mapKey(event.code));
443
+ if ((memoisedOptions == null ? void 0 : memoisedOptions.keydown) === undefined && (memoisedOptions == null ? void 0 : memoisedOptions.keyup) !== true || memoisedOptions != null && memoisedOptions.keydown) {
444
+ listener(event);
445
+ }
446
+ };
447
+ var handleKeyUp = function handleKeyUp(event) {
448
+ if (event.key === undefined) {
449
+ // Synthetic event (e.g., Chrome autofill). Ignore.
450
+ return;
451
+ }
452
+ removeFromCurrentlyPressedKeys(mapKey(event.code));
453
+ hasTriggeredRef.current = false;
454
+ if (memoisedOptions != null && memoisedOptions.keyup) {
455
+ listener(event, true);
456
+ }
457
+ };
458
+ var domNode = ref.current || (_options == null ? void 0 : _options.document) || document;
459
+ // @ts-ignore
460
+ domNode.addEventListener('keyup', handleKeyUp);
461
+ // @ts-ignore
462
+ domNode.addEventListener('keydown', handleKeyDown);
463
+ if (proxy) {
464
+ parseKeysHookInput(_keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
465
+ return proxy.addHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey, memoisedOptions == null ? void 0 : memoisedOptions.description));
466
+ });
467
+ }
468
+ return function () {
469
+ // @ts-ignore
470
+ domNode.removeEventListener('keyup', handleKeyUp);
471
+ // @ts-ignore
472
+ domNode.removeEventListener('keydown', handleKeyDown);
473
+ if (proxy) {
474
+ parseKeysHookInput(_keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
475
+ return proxy.removeHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey, memoisedOptions == null ? void 0 : memoisedOptions.description));
476
+ });
477
+ }
478
+ };
479
+ }, [_keys, memoisedOptions, enabledScopes]);
480
+ return ref;
481
+ }
482
+
483
+ function useRecordHotkeys() {
484
+ var _useState = react.useState(new Set()),
485
+ keys = _useState[0],
486
+ setKeys = _useState[1];
487
+ var _useState2 = react.useState(false),
488
+ isRecording = _useState2[0],
489
+ setIsRecording = _useState2[1];
490
+ var handler = react.useCallback(function (event) {
491
+ if (event.key === undefined) {
492
+ // Synthetic event (e.g., Chrome autofill). Ignore.
493
+ return;
494
+ }
495
+ event.preventDefault();
496
+ event.stopPropagation();
497
+ setKeys(function (prev) {
498
+ var newKeys = new Set(prev);
499
+ newKeys.add(mapKey(event.code));
500
+ return newKeys;
501
+ });
502
+ }, []);
503
+ var stop = react.useCallback(function () {
504
+ if (typeof document !== 'undefined') {
505
+ document.removeEventListener('keydown', handler);
506
+ setIsRecording(false);
507
+ }
508
+ }, [handler]);
509
+ var start = react.useCallback(function () {
510
+ setKeys(new Set());
511
+ if (typeof document !== 'undefined') {
512
+ stop();
513
+ document.addEventListener('keydown', handler);
514
+ setIsRecording(true);
515
+ }
516
+ }, [handler, stop]);
517
+ return [keys, {
518
+ start: start,
519
+ stop: stop,
520
+ isRecording: isRecording
521
+ }];
522
+ }
523
+
524
+ exports.HotkeysProvider = HotkeysProvider;
525
+ exports.isHotkeyPressed = isHotkeyPressed;
526
+ exports.useHotkeys = useHotkeys;
527
+ exports.useHotkeysContext = useHotkeysContext;
528
+ exports.useRecordHotkeys = useRecordHotkeys;
529
+ //# sourceMappingURL=react-hotkeys-hook.cjs.development.js.map