react-hotkeys-hook 4.0.4-1 → 4.0.4-2

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.
@@ -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): JSX.Element;
14
- export {};
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): 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
- 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) => JSX.Element;
16
- export {};
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) => JSX.Element;
16
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import useHotkeys from './useHotkeys';
2
- import type { Options } from './types';
3
- import { HotkeysProvider, useHotkeysContext } from './HotkeysProvider';
4
- import { isHotkeyPressed } from './isHotkeyPressed';
5
- export { useHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, Options, };
1
+ import useHotkeys from './useHotkeys';
2
+ import type { Options } from './types';
3
+ import { HotkeysProvider, useHotkeysContext } from './HotkeysProvider';
4
+ import { isHotkeyPressed } from './isHotkeyPressed';
5
+ export { useHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, Options, };
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
+ }
@@ -1,3 +1,3 @@
1
- export declare function isHotkeyPressed(key: string | string[], splitKey?: string): boolean;
2
- export declare function pushToCurrentlyPressedKeys(key: string | string[]): void;
3
- export declare function removeFromCurrentlyPressedKeys(key: string | string[]): void;
1
+ export declare function isHotkeyPressed(key: string | string[], splitKey?: string): boolean;
2
+ export declare function pushToCurrentlyPressedKeys(key: string | string[]): void;
3
+ export declare function removeFromCurrentlyPressedKeys(key: string | string[]): void;
@@ -1,3 +1,3 @@
1
- import { Hotkey, Keys } from './types';
2
- export declare function parseKeysHookInput(keys: Keys, splitKey?: string): string[];
3
- export declare function parseHotkey(hotkey: string, combinationKey?: string): Hotkey;
1
+ import { Hotkey, Keys } from './types';
2
+ export declare function parseKeysHookInput(keys: Keys, splitKey?: string): string[];
3
+ export declare function parseHotkey(hotkey: string, combinationKey?: string): Hotkey;
@@ -0,0 +1,427 @@
1
+ 'use strict';
2
+
3
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
+
5
+ var react = require('react');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var isEqual = _interopDefault(require('lodash/isEqual'));
8
+
9
+ function _extends() {
10
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
11
+ for (var i = 1; i < arguments.length; i++) {
12
+ var source = arguments[i];
13
+ for (var key in source) {
14
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
15
+ target[key] = source[key];
16
+ }
17
+ }
18
+ }
19
+ return target;
20
+ };
21
+ return _extends.apply(this, arguments);
22
+ }
23
+ function _unsupportedIterableToArray(o, minLen) {
24
+ if (!o) return;
25
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
26
+ var n = Object.prototype.toString.call(o).slice(8, -1);
27
+ if (n === "Object" && o.constructor) n = o.constructor.name;
28
+ if (n === "Map" || n === "Set") return Array.from(o);
29
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
30
+ }
31
+ function _arrayLikeToArray(arr, len) {
32
+ if (len == null || len > arr.length) len = arr.length;
33
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
34
+ return arr2;
35
+ }
36
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
37
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
38
+ if (it) return (it = it.call(o)).next.bind(it);
39
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
40
+ if (it) o = it;
41
+ var i = 0;
42
+ return function () {
43
+ if (i >= o.length) return {
44
+ done: true
45
+ };
46
+ return {
47
+ done: false,
48
+ value: o[i++]
49
+ };
50
+ };
51
+ }
52
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ }
54
+
55
+ var reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod'];
56
+ var mappedKeys = {
57
+ esc: 'escape',
58
+ "return": 'enter',
59
+ left: 'arrowleft',
60
+ up: 'arrowup',
61
+ right: 'arrowright',
62
+ down: 'arrowdown'
63
+ };
64
+ function parseKeysHookInput(keys, splitKey) {
65
+ if (splitKey === void 0) {
66
+ splitKey = ',';
67
+ }
68
+ if (typeof keys === 'string') {
69
+ return keys.split(splitKey);
70
+ }
71
+ return keys;
72
+ }
73
+ function parseHotkey(hotkey, combinationKey) {
74
+ if (combinationKey === void 0) {
75
+ combinationKey = '+';
76
+ }
77
+ var keys = hotkey.toLocaleLowerCase().split(combinationKey).map(function (k) {
78
+ return k.trim();
79
+ }).map(function (k) {
80
+ return mappedKeys[k] || k;
81
+ });
82
+ var modifiers = {
83
+ alt: keys.includes('alt'),
84
+ ctrl: keys.includes('ctrl'),
85
+ shift: keys.includes('shift'),
86
+ meta: keys.includes('meta'),
87
+ mod: keys.includes('mod')
88
+ };
89
+ var singleCharKeys = keys.filter(function (k) {
90
+ return !reservedModifierKeywords.includes(k);
91
+ });
92
+ return _extends({}, modifiers, {
93
+ keys: singleCharKeys
94
+ });
95
+ }
96
+
97
+ function maybePreventDefault(e, hotkey, preventDefault) {
98
+ if (typeof preventDefault === 'function' && preventDefault(e, hotkey) || preventDefault === true) {
99
+ e.preventDefault();
100
+ }
101
+ }
102
+ function isHotkeyEnabled(e, hotkey, enabled) {
103
+ if (typeof enabled === 'function') {
104
+ return enabled(e, hotkey);
105
+ }
106
+ return enabled === true || enabled === undefined;
107
+ }
108
+ function isKeyboardEventTriggeredByInput(ev) {
109
+ return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select']);
110
+ }
111
+ function isHotkeyEnabledOnTag(_ref, enabledOnTags) {
112
+ var target = _ref.target;
113
+ if (enabledOnTags === void 0) {
114
+ enabledOnTags = false;
115
+ }
116
+ var targetTagName = target && target.tagName;
117
+ if (enabledOnTags instanceof Array) {
118
+ return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(function (tag) {
119
+ return tag.toLowerCase() === targetTagName.toLowerCase();
120
+ }));
121
+ }
122
+ return Boolean(targetTagName && enabledOnTags && enabledOnTags === true);
123
+ }
124
+ function isScopeActive(activeScopes, scopes) {
125
+ if (activeScopes.length === 0 && scopes) {
126
+ 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>');
127
+ return true;
128
+ }
129
+ if (!scopes) {
130
+ return true;
131
+ }
132
+ return activeScopes.some(function (scope) {
133
+ return scopes.includes(scope);
134
+ }) || activeScopes.includes('*');
135
+ }
136
+ var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) {
137
+ var alt = hotkey.alt,
138
+ ctrl = hotkey.ctrl,
139
+ meta = hotkey.meta,
140
+ mod = hotkey.mod,
141
+ shift = hotkey.shift,
142
+ keys = hotkey.keys;
143
+ var altKey = e.altKey,
144
+ ctrlKey = e.ctrlKey,
145
+ metaKey = e.metaKey,
146
+ shiftKey = e.shiftKey,
147
+ pressedKeyUppercase = e.key,
148
+ code = e.code;
149
+ var keyCode = code.toLowerCase().replace('key', '');
150
+ var pressedKey = pressedKeyUppercase.toLowerCase();
151
+ if (altKey !== alt && pressedKey !== 'alt') {
152
+ return false;
153
+ }
154
+ if (shiftKey !== shift && pressedKey !== 'shift') {
155
+ return false;
156
+ }
157
+ // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
158
+ if (mod) {
159
+ if (!metaKey && !ctrlKey) {
160
+ return false;
161
+ }
162
+ } else {
163
+ if (metaKey !== meta && keyCode !== 'meta') {
164
+ return false;
165
+ }
166
+ if (ctrlKey !== ctrl && keyCode !== 'ctrl') {
167
+ return false;
168
+ }
169
+ }
170
+ // All modifiers are correct, now check the key
171
+ // If the key is set we check for the key
172
+ if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {
173
+ return true;
174
+ } else if (keys) {
175
+ // Check if all keys are present in pressedDownKeys set
176
+ return keys.every(function (key) {
177
+ return pressedDownKeys.has(key);
178
+ });
179
+ } else if (!keys) {
180
+ // If the key is not set, we only listen for modifiers, that check went alright, so we return true
181
+ return true;
182
+ }
183
+ // There is nothing that matches.
184
+ return false;
185
+ };
186
+
187
+ var BoundHotkeysProxyProvider = /*#__PURE__*/react.createContext(undefined);
188
+ var useBoundHotkeysProxy = function useBoundHotkeysProxy() {
189
+ return react.useContext(BoundHotkeysProxyProvider);
190
+ };
191
+ function BoundHotkeysProxyProviderProvider(_ref) {
192
+ var addHotkey = _ref.addHotkey,
193
+ removeHotkey = _ref.removeHotkey,
194
+ children = _ref.children;
195
+ return /*#__PURE__*/jsxRuntime.jsx(BoundHotkeysProxyProvider.Provider, {
196
+ value: {
197
+ addHotkey: addHotkey,
198
+ removeHotkey: removeHotkey
199
+ },
200
+ children: children
201
+ });
202
+ }
203
+
204
+ var HotkeysContext = /*#__PURE__*/react.createContext({
205
+ hotkeys: [],
206
+ enabledScopes: [],
207
+ toggleScope: function toggleScope() {},
208
+ enableScope: function enableScope() {},
209
+ disableScope: function disableScope() {}
210
+ });
211
+ var useHotkeysContext = function useHotkeysContext() {
212
+ return react.useContext(HotkeysContext);
213
+ };
214
+ var HotkeysProvider = function HotkeysProvider(_ref) {
215
+ var _ref$initiallyActiveS = _ref.initiallyActiveScopes,
216
+ initiallyActiveScopes = _ref$initiallyActiveS === void 0 ? ['*'] : _ref$initiallyActiveS,
217
+ children = _ref.children;
218
+ var _useState = react.useState((initiallyActiveScopes == null ? void 0 : initiallyActiveScopes.length) > 0 ? initiallyActiveScopes : ['*']),
219
+ internalActiveScopes = _useState[0],
220
+ setInternalActiveScopes = _useState[1];
221
+ var _useState2 = react.useState([]),
222
+ boundHotkeys = _useState2[0],
223
+ setBoundHotkeys = _useState2[1];
224
+ var isAllActive = react.useMemo(function () {
225
+ return internalActiveScopes.includes('*');
226
+ }, [internalActiveScopes]);
227
+ var enableScope = function enableScope(scope) {
228
+ if (isAllActive) {
229
+ setInternalActiveScopes([scope]);
230
+ } else {
231
+ setInternalActiveScopes(Array.from(new Set([].concat(internalActiveScopes, [scope]))));
232
+ }
233
+ };
234
+ var disableScope = function disableScope(scope) {
235
+ var scopes = internalActiveScopes.filter(function (s) {
236
+ return s !== scope;
237
+ });
238
+ if (scopes.length === 0) {
239
+ setInternalActiveScopes(['*']);
240
+ } else {
241
+ setInternalActiveScopes(scopes);
242
+ }
243
+ };
244
+ var toggleScope = function toggleScope(scope) {
245
+ if (internalActiveScopes.includes(scope)) {
246
+ disableScope(scope);
247
+ } else {
248
+ enableScope(scope);
249
+ }
250
+ };
251
+ var addBoundHotkey = function addBoundHotkey(hotkey) {
252
+ setBoundHotkeys([].concat(boundHotkeys, [hotkey]));
253
+ };
254
+ var removeBoundHotkey = function removeBoundHotkey(hotkey) {
255
+ setBoundHotkeys(boundHotkeys.filter(function (h) {
256
+ return h.keys !== hotkey.keys;
257
+ }));
258
+ };
259
+ return /*#__PURE__*/jsxRuntime.jsx(HotkeysContext.Provider, {
260
+ value: {
261
+ enabledScopes: internalActiveScopes,
262
+ hotkeys: boundHotkeys,
263
+ enableScope: enableScope,
264
+ disableScope: disableScope,
265
+ toggleScope: toggleScope
266
+ },
267
+ children: /*#__PURE__*/jsxRuntime.jsx(BoundHotkeysProxyProviderProvider, {
268
+ addHotkey: addBoundHotkey,
269
+ removeHotkey: removeBoundHotkey,
270
+ children: children
271
+ })
272
+ });
273
+ };
274
+
275
+ function useDeepEqualMemo(value) {
276
+ var ref = react.useRef(undefined);
277
+ if (!isEqual(ref.current, value)) {
278
+ ref.current = value;
279
+ }
280
+ return ref.current;
281
+ }
282
+
283
+ var stopPropagation = function stopPropagation(e) {
284
+ e.stopPropagation();
285
+ e.preventDefault();
286
+ e.stopImmediatePropagation();
287
+ };
288
+ var useSafeLayoutEffect = typeof window !== 'undefined' ? react.useLayoutEffect : react.useEffect;
289
+ function useHotkeys(keys, callback, options, dependencies) {
290
+ var ref = react.useRef(null);
291
+ var _useRef = react.useRef(new Set()),
292
+ pressedDownKeys = _useRef.current;
293
+ var _options = !(options instanceof Array) ? options : !(dependencies instanceof Array) ? dependencies : undefined;
294
+ var _deps = options instanceof Array ? options : dependencies instanceof Array ? dependencies : [];
295
+ var cb = react.useCallback(callback, [].concat(_deps));
296
+ var memoisedOptions = useDeepEqualMemo(_options);
297
+ var _useHotkeysContext = useHotkeysContext(),
298
+ enabledScopes = _useHotkeysContext.enabledScopes;
299
+ var proxy = useBoundHotkeysProxy();
300
+ useSafeLayoutEffect(function () {
301
+ if ((memoisedOptions == null ? void 0 : memoisedOptions.enabled) === false || !isScopeActive(enabledScopes, memoisedOptions == null ? void 0 : memoisedOptions.scopes)) {
302
+ return;
303
+ }
304
+ var listener = function listener(e) {
305
+ var _e$target;
306
+ if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions == null ? void 0 : memoisedOptions.enableOnFormTags)) {
307
+ return;
308
+ }
309
+ // 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
310
+ // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.
311
+ if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {
312
+ stopPropagation(e);
313
+ return;
314
+ }
315
+ if ((_e$target = e.target) != null && _e$target.isContentEditable && !(memoisedOptions != null && memoisedOptions.enableOnContentEditable)) {
316
+ return;
317
+ }
318
+ parseKeysHookInput(keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
319
+ var _hotkey$keys;
320
+ var hotkey = parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey);
321
+ if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) {
322
+ maybePreventDefault(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.preventDefault);
323
+ if (!isHotkeyEnabled(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.enabled)) {
324
+ stopPropagation(e);
325
+ return;
326
+ }
327
+ cb(e, hotkey);
328
+ }
329
+ });
330
+ };
331
+ var handleKeyDown = function handleKeyDown(event) {
332
+ pressedDownKeys.add(event.key.toLowerCase());
333
+ if ((memoisedOptions == null ? void 0 : memoisedOptions.keydown) === undefined && (memoisedOptions == null ? void 0 : memoisedOptions.keyup) !== true || memoisedOptions != null && memoisedOptions.keydown) {
334
+ listener(event);
335
+ }
336
+ };
337
+ var handleKeyUp = function handleKeyUp(event) {
338
+ if (event.key.toLowerCase() !== 'meta') {
339
+ pressedDownKeys["delete"](event.key.toLowerCase());
340
+ } else {
341
+ // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.
342
+ pressedDownKeys.clear();
343
+ }
344
+ if (memoisedOptions != null && memoisedOptions.keyup) {
345
+ listener(event);
346
+ }
347
+ };
348
+ // @ts-ignore
349
+ (ref.current || document).addEventListener('keyup', handleKeyUp);
350
+ // @ts-ignore
351
+ (ref.current || document).addEventListener('keydown', handleKeyDown);
352
+ if (proxy) {
353
+ parseKeysHookInput(keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
354
+ return proxy.addHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey));
355
+ });
356
+ }
357
+ return function () {
358
+ // @ts-ignore
359
+ (ref.current || document).removeEventListener('keyup', handleKeyUp);
360
+ // @ts-ignore
361
+ (ref.current || document).removeEventListener('keydown', handleKeyDown);
362
+ if (proxy) {
363
+ parseKeysHookInput(keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
364
+ return proxy.removeHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey));
365
+ });
366
+ }
367
+ };
368
+ }, [keys, cb, memoisedOptions, enabledScopes]);
369
+ return ref;
370
+ }
371
+
372
+ var currentlyPressedKeys = /*#__PURE__*/new Set();
373
+ function isHotkeyPressed(key, splitKey) {
374
+ if (splitKey === void 0) {
375
+ splitKey = ',';
376
+ }
377
+ var hotkeyArray = Array.isArray(key) ? key : key.split(splitKey);
378
+ return hotkeyArray.every(function (hotkey) {
379
+ var parsedHotkey = parseHotkey(hotkey);
380
+ for (var _iterator = _createForOfIteratorHelperLoose(currentlyPressedKeys), _step; !(_step = _iterator()).done;) {
381
+ var pressedHotkey = _step.value;
382
+ if (isEqual(parsedHotkey, pressedHotkey)) {
383
+ return true;
384
+ }
385
+ }
386
+ });
387
+ }
388
+ function pushToCurrentlyPressedKeys(key) {
389
+ var hotkeyArray = Array.isArray(key) ? key : [key];
390
+ hotkeyArray.forEach(function (hotkey) {
391
+ return currentlyPressedKeys.add(parseHotkey(hotkey));
392
+ });
393
+ }
394
+ function removeFromCurrentlyPressedKeys(key) {
395
+ var hotkeyArray = Array.isArray(key) ? key : [key];
396
+ hotkeyArray.forEach(function (hotkey) {
397
+ var parsedHotkey = parseHotkey(hotkey);
398
+ for (var _iterator2 = _createForOfIteratorHelperLoose(currentlyPressedKeys), _step2; !(_step2 = _iterator2()).done;) {
399
+ var _pressedHotkey$keys;
400
+ var pressedHotkey = _step2.value;
401
+ if ((_pressedHotkey$keys = pressedHotkey.keys) != null && _pressedHotkey$keys.every(function (key) {
402
+ var _parsedHotkey$keys;
403
+ return (_parsedHotkey$keys = parsedHotkey.keys) == null ? void 0 : _parsedHotkey$keys.includes(key);
404
+ })) {
405
+ currentlyPressedKeys["delete"](pressedHotkey);
406
+ }
407
+ }
408
+ });
409
+ }
410
+ (function () {
411
+ if (typeof window !== 'undefined') {
412
+ window.addEventListener('DOMContentLoaded', function () {
413
+ document.addEventListener('keydown', function (e) {
414
+ pushToCurrentlyPressedKeys(e.key);
415
+ });
416
+ document.addEventListener('keyup', function (e) {
417
+ removeFromCurrentlyPressedKeys(e.key);
418
+ });
419
+ });
420
+ }
421
+ })();
422
+
423
+ exports.HotkeysProvider = HotkeysProvider;
424
+ exports.isHotkeyPressed = isHotkeyPressed;
425
+ exports.useHotkeys = useHotkeys;
426
+ exports.useHotkeysContext = useHotkeysContext;
427
+ //# sourceMappingURL=react-hotkeys-hook.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-hotkeys-hook.cjs.development.js","sources":["../src/parseHotkeys.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/HotkeysProvider.tsx","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/isHotkeyPressed.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n left: 'arrowleft',\n up: 'arrowup',\n right: 'arrowright',\n down: 'arrowdown',\n}\n\nexport function parseKeysHookInput(keys: Keys, splitKey: string = ','): string[] {\n if (typeof keys === 'string') {\n return keys.split(splitKey)\n }\n\n return keys\n}\n\nexport function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotkey {\n const keys = hotkey\n .toLocaleLowerCase()\n .split(combinationKey)\n .map(k => k.trim())\n .map(k => mappedKeys[k] || k)\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n shift: keys.includes('shift'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n }\n\n const singleCharKeys = keys.filter((k) => !reservedModifierKeywords.includes(k))\n\n return {\n ...modifiers,\n keys: singleCharKeys,\n }\n}\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\n\nexport function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void {\n if ((typeof preventDefault === 'function' && preventDefault(e, hotkey)) || preventDefault === true) {\n e.preventDefault()\n }\n}\n\nexport function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean {\n if (typeof enabled === 'function') {\n return enabled(e, hotkey)\n }\n\n return enabled === true || enabled === undefined\n}\n\nexport function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean {\n return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select'])\n}\n\nexport function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: FormTags[] | boolean = false): boolean {\n const targetTagName = target && (target as HTMLElement).tagName\n\n if (enabledOnTags instanceof Array) {\n return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(tag => tag.toLowerCase() === targetTagName.toLowerCase()))\n }\n\n return Boolean(targetTagName && enabledOnTags && enabledOnTags === true)\n}\n\nexport function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {\n if (activeScopes.length === 0 && scopes) {\n console.warn(\n '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>'\n )\n\n return true\n }\n\n if (!scopes) {\n return true\n }\n\n return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')\n}\n\nexport const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {\n const { alt, ctrl, meta, mod, shift, keys } = hotkey\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e\n\n const keyCode = code.toLowerCase().replace('key', '')\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (altKey !== alt && pressedKey !== 'alt') {\n return false\n }\n\n if (shiftKey !== shift && pressedKey !== 'shift') {\n return false\n }\n\n // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms\n if (mod) {\n if (!metaKey && !ctrlKey) {\n return false\n }\n } else {\n if (metaKey !== meta && keyCode !== 'meta') {\n return false\n }\n\n if (ctrlKey !== ctrl && keyCode !== 'ctrl') {\n return false\n }\n }\n\n // All modifiers are correct, now check the key\n // If the key is set we check for the key\n if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {\n return true\n } else if (keys) {\n // Check if all keys are present in pressedDownKeys set\n return keys.every(key => pressedDownKeys.has(key))\n }\n else if (!keys) {\n // If the key is not set, we only listen for modifiers, that check went alright, so we return true\n return true\n }\n\n // There is nothing that matches.\n return false\n}\n","import { createContext, ReactNode, useContext } from 'react'\nimport { Hotkey } from './types'\n\ntype BoundHotkeysProxyProviderType = {\n addHotkey: (hotkey: Hotkey) => void,\n removeHotkey: (hotkey: Hotkey) => void,\n}\n\nconst BoundHotkeysProxyProvider = createContext<BoundHotkeysProxyProviderType | undefined>(undefined)\n\nexport const useBoundHotkeysProxy = () => {\n return useContext(BoundHotkeysProxyProvider)\n}\n\ninterface Props {\n children: ReactNode\n addHotkey: (hotkey: Hotkey) => void\n removeHotkey: (hotkey: Hotkey) => void\n}\n\nexport default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props) {\n return <BoundHotkeysProxyProvider.Provider value={{addHotkey, removeHotkey}}>{children}</BoundHotkeysProxyProvider.Provider>\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useMemo, useState, useContext } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\n\nexport type HotkeysContextType = {\n hotkeys: ReadonlyArray<Hotkey>\n enabledScopes: string[]\n toggleScope: (scope: string) => void\n enableScope: (scope: string) => void\n disableScope: (scope: string) => void\n}\n\n// The context is only needed for special features like global scoping, so we use a graceful default fallback\nconst HotkeysContext = createContext<HotkeysContextType>({\n hotkeys: [],\n enabledScopes: [], // This array has to be empty instead of containing '*' as default, to check if the provider is set or not\n toggleScope: () => {},\n enableScope: () => {},\n disableScope: () => {},\n})\n\nexport const useHotkeysContext = () => {\n return useContext(HotkeysContext)\n}\n\ninterface Props {\n initiallyActiveScopes?: string[]\n children: ReactNode\n}\n\nexport const HotkeysProvider = ({initiallyActiveScopes = ['*'], children}: Props) => {\n const [internalActiveScopes, setInternalActiveScopes] = useState(initiallyActiveScopes?.length > 0 ? initiallyActiveScopes : ['*'])\n const [boundHotkeys, setBoundHotkeys] = useState<Hotkey[]>([]);\n\n const isAllActive = useMemo(() => internalActiveScopes.includes('*'), [internalActiveScopes])\n\n const enableScope = (scope: string) => {\n if (isAllActive) {\n setInternalActiveScopes([scope])\n } else {\n setInternalActiveScopes(Array.from(new Set([...internalActiveScopes, scope])))\n }\n }\n\n const disableScope = (scope: string) => {\n const scopes = internalActiveScopes.filter(s => s !== scope)\n\n if (scopes.length === 0) {\n setInternalActiveScopes(['*'])\n } else {\n setInternalActiveScopes(scopes)\n }\n }\n\n const toggleScope = (scope: string) => {\n if (internalActiveScopes.includes(scope)) {\n disableScope(scope)\n } else {\n enableScope(scope)\n }\n }\n\n const addBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys([...boundHotkeys, hotkey])\n }\n\n const removeBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys(boundHotkeys.filter(h => h.keys !== hotkey.keys))\n }\n\n return (\n <HotkeysContext.Provider value={{enabledScopes: internalActiveScopes, hotkeys: boundHotkeys, enableScope, disableScope, toggleScope}}>\n <BoundHotkeysProxyProviderProvider addHotkey={addBoundHotkey} removeHotkey={removeBoundHotkey}>\n {children}\n </BoundHotkeysProxyProviderProvider>\n </HotkeysContext.Provider>\n )\n}\n","import { useRef } from 'react'\nimport isEqual from 'lodash/isEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!isEqual(ref.current, value)) {\n ref.current = value\n }\n\n return ref.current\n}\n","import { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'\nimport { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { parseHotkey, parseKeysHookInput } from './parseHotkeys'\nimport {\n isHotkeyEnabled,\n isHotkeyEnabledOnTag,\n isHotkeyMatchingKeyboardEvent,\n isKeyboardEventTriggeredByInput,\n isScopeActive,\n maybePreventDefault,\n} from './validators'\nimport { useHotkeysContext } from './HotkeysProvider'\nimport { useBoundHotkeysProxy } from './BoundHotkeysProxyProvider'\nimport useDeepEqualMemo from './useDeepEqualMemo'\n\nconst stopPropagation = (e: KeyboardEvent): void => {\n e.stopPropagation()\n e.preventDefault()\n e.stopImmediatePropagation()\n}\n\nconst useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nexport default function useHotkeys<T extends HTMLElement>(\n keys: Keys,\n callback: HotkeyCallback,\n options?: OptionsOrDependencyArray,\n dependencies?: OptionsOrDependencyArray,\n) {\n const ref = useRef<RefType<T>>(null)\n const { current: pressedDownKeys } = useRef<Set<string>>(new Set())\n\n const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined\n const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []\n\n const cb = useCallback(callback, [..._deps])\n const memoisedOptions = useDeepEqualMemo(_options)\n\n const { enabledScopes } = useHotkeysContext()\n const proxy = useBoundHotkeysProxy()\n\n useSafeLayoutEffect(() => {\n if (memoisedOptions?.enabled === false || !isScopeActive(enabledScopes, memoisedOptions?.scopes)) {\n return\n }\n\n const listener = (e: KeyboardEvent) => {\n if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions?.enableOnFormTags)) {\n return\n }\n\n // 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\n // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.\n\n if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {\n stopPropagation(e)\n\n return\n }\n\n if (((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable)) {\n return\n }\n\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {\n const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)\n\n if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || hotkey.keys?.includes('*')) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n cb(e, hotkey)\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n pressedDownKeys.add(event.key.toLowerCase())\n\n if ((memoisedOptions?.keydown === undefined && memoisedOptions?.keyup !== true) || memoisedOptions?.keydown) {\n listener(event)\n }\n }\n\n const handleKeyUp = (event: KeyboardEvent) => {\n if (event.key.toLowerCase() !== 'meta') {\n pressedDownKeys.delete(event.key.toLowerCase())\n } else {\n // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.\n pressedDownKeys.clear()\n }\n\n if (memoisedOptions?.keyup) {\n listener(event)\n }\n }\n\n // @ts-ignore\n (ref.current || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).addEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n\n return () => {\n // @ts-ignore\n (ref.current || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).removeEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n }\n }, [keys, cb, memoisedOptions, enabledScopes])\n\n return ref\n}\n","import { Hotkey } from './types'\nimport { parseHotkey } from './parseHotkeys'\nimport isEqual from 'lodash/isEqual'\n\nconst currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()\n\nexport function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean {\n const hotkeyArray = Array.isArray(key) ? key : key.split(splitKey)\n\n return hotkeyArray.every((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (isEqual(parsedHotkey, pressedHotkey)) {\n return true\n }\n }\n })\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(parseHotkey(hotkey)))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (pressedHotkey.keys?.every((key) => parsedHotkey.keys?.includes(key))) {\n currentlyPressedKeys.delete(pressedHotkey)\n }\n }\n })\n}\n\n(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n document.addEventListener('keydown', e => {\n pushToCurrentlyPressedKeys(e.key)\n })\n\n document.addEventListener('keyup', e => {\n removeFromCurrentlyPressedKeys(e.key)\n })\n })\n }\n})()\n"],"names":["reservedModifierKeywords","mappedKeys","esc","left","up","right","down","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","trim","modifiers","alt","includes","ctrl","shift","meta","mod","singleCharKeys","filter","maybePreventDefault","e","preventDefault","isHotkeyEnabled","enabled","undefined","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Array","Boolean","some","tag","toLowerCase","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","pressedDownKeys","altKey","ctrlKey","metaKey","shiftKey","pressedKeyUppercase","key","code","keyCode","replace","pressedKey","every","has","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","isAllActive","useMemo","from","Set","s","addBoundHotkey","removeBoundHotkey","h","useDeepEqualMemo","value","ref","useRef","isEqual","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","window","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","_options","_deps","cb","useCallback","memoisedOptions","proxy","listener","enableOnFormTags","document","activeElement","contains","isContentEditable","enableOnContentEditable","forEach","handleKeyDown","event","add","keydown","keyup","handleKeyUp","clear","addEventListener","removeEventListener","currentlyPressedKeys","isHotkeyPressed","hotkeyArray","isArray","parsedHotkey","pressedHotkey","pushToCurrentlyPressedKeys","removeFromCurrentlyPressedKeys"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;AAExE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACfC,IAAI,EAAE,WAAW;EACjBC,EAAE,EAAE,SAAS;EACbC,KAAK,EAAE,YAAY;EACnBC,IAAI,EAAE;CACP;SAEeC,kBAAkB,CAACC,IAAU,EAAEC;MAAAA;IAAAA,WAAmB,GAAG;;EACnE,IAAI,OAAOD,IAAI,KAAK,QAAQ,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AA1G,CAAC;QACpCkH,0BAA0B,CAAClH,CAAC,CAAC+B,GAAG,CAAC;OAClC,CAAC;MAEF8D,QAAQ,CAACa,gBAAgB,CAAC,OAAO,EAAE,UAAA1G,CAAC;QAClCmH,8BAA8B,CAACnH,CAAC,CAAC+B,GAAG,CAAC;OACtC,CAAC;KACH,CAAC;;AAEN,CAAC,GAAG;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e,n=require("react"),t=require("react/jsx-runtime"),r=(e=require("lodash/isEqual"))&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function i(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function u(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return i(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=["ctrl","shift","alt","meta","mod"],c={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown"};function l(e,n){return void 0===n&&(n=","),"string"==typeof e?e.split(n):e}function s(e,n){void 0===n&&(n="+");var t=e.toLocaleLowerCase().split(n).map((function(e){return e.trim()})).map((function(e){return c[e]||e}));return o({},{alt:t.includes("alt"),ctrl:t.includes("ctrl"),shift:t.includes("shift"),meta:t.includes("meta"),mod:t.includes("mod")},{keys:t.filter((function(e){return!a.includes(e)}))})}function d(e,n){var t=e.target;void 0===n&&(n=!1);var r=t&&t.tagName;return n instanceof Array?Boolean(r&&n&&n.some((function(e){return e.toLowerCase()===r.toLowerCase()}))):Boolean(r&&n&&!0===n)}var f=n.createContext(void 0);function y(e){return t.jsx(f.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}var v=n.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),p=function(){return n.useContext(v)},m=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},h="undefined"!=typeof window?n.useLayoutEffect:n.useEffect,k=new Set;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(function(){document.addEventListener("keydown",(function(e){var n;n=e.key,(Array.isArray(n)?n:[n]).forEach((function(e){return k.add(s(e))}))})),document.addEventListener("keyup",(function(e){var n;n=e.key,(Array.isArray(n)?n:[n]).forEach((function(e){for(var n,t=s(e),r=u(k);!(n=r()).done;){var o,i=n.value;null!=(o=i.keys)&&o.every((function(e){var n;return null==(n=t.keys)?void 0:n.includes(e)}))&&k.delete(i)}}))}))})),exports.HotkeysProvider=function(e){var r=e.initiallyActiveScopes,o=void 0===r?["*"]:r,i=e.children,u=n.useState((null==o?void 0:o.length)>0?o:["*"]),a=u[0],c=u[1],l=n.useState([]),s=l[0],d=l[1],f=n.useMemo((function(){return a.includes("*")}),[a]),p=function(e){c(f?[e]:Array.from(new Set([].concat(a,[e]))))},m=function(e){var n=a.filter((function(n){return n!==e}));c(0===n.length?["*"]:n)};return t.jsx(v.Provider,{value:{enabledScopes:a,hotkeys:s,enableScope:p,disableScope:m,toggleScope:function(e){a.includes(e)?m(e):p(e)}},children:t.jsx(y,{addHotkey:function(e){d([].concat(s,[e]))},removeHotkey:function(e){d(s.filter((function(n){return n.keys!==e.keys})))},children:i})})},exports.isHotkeyPressed=function(e,n){return void 0===n&&(n=","),(Array.isArray(e)?e:e.split(n)).every((function(e){for(var n,t=s(e),o=u(k);!(n=o()).done;)if(r(t,n.value))return!0}))},exports.useHotkeys=function(e,t,o,i){var u=n.useRef(null),a=n.useRef(new Set).current,c=o instanceof Array?i instanceof Array?void 0:i:o,y=n.useCallback(t,[].concat(o instanceof Array?o:i instanceof Array?i:[])),v=function(e){var t=n.useRef(void 0);return r(t.current,e)||(t.current=e),t.current}(c),k=p().enabledScopes,w=n.useContext(f);return h((function(){if(!1!==(null==v?void 0:v.enabled)&&(t=null==v?void 0:v.scopes,0===(n=k).length&&t?(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>'),1):!t||n.some((function(e){return t.includes(e)}))||n.includes("*"))){var n,t,r=function(n){var t;d(n,["input","textarea","select"])&&!d(n,null==v?void 0:v.enableOnFormTags)||(null===u.current||document.activeElement===u.current||u.current.contains(document.activeElement)?(null==(t=n.target)||!t.isContentEditable||null!=v&&v.enableOnContentEditable)&&l(e,null==v?void 0:v.splitKey).forEach((function(e){var t,r=s(e,null==v?void 0:v.combinationKey);if(function(e,n,t){var r=n.alt,o=n.ctrl,i=n.meta,u=n.mod,a=n.shift,c=n.keys,l=e.altKey,s=e.ctrlKey,d=e.metaKey,f=e.shiftKey,y=e.key,v=e.code.toLowerCase().replace("key",""),p=y.toLowerCase();if(l!==r&&"alt"!==p)return!1;if(f!==a&&"shift"!==p)return!1;if(u){if(!d&&!s)return!1}else{if(d!==i&&"meta"!==v)return!1;if(s!==o&&"ctrl"!==v)return!1}return!(!c||1!==c.length||!c.includes(p)&&!c.includes(v))||(c?c.every((function(e){return t.has(e)})):!c)}(n,r,a)||null!=(t=r.keys)&&t.includes("*")){if(function(e,n,t){("function"==typeof t&&t(e,n)||!0===t)&&e.preventDefault()}(n,r,null==v?void 0:v.preventDefault),!function(e,n,t){return"function"==typeof t?t(e,n):!0===t||void 0===t}(n,r,null==v?void 0:v.enabled))return void m(n);y(n,r)}})):m(n))},o=function(e){a.add(e.key.toLowerCase()),(void 0===(null==v?void 0:v.keydown)&&!0!==(null==v?void 0:v.keyup)||null!=v&&v.keydown)&&r(e)},i=function(e){"meta"!==e.key.toLowerCase()?a.delete(e.key.toLowerCase()):a.clear(),null!=v&&v.keyup&&r(e)};return(u.current||document).addEventListener("keyup",i),(u.current||document).addEventListener("keydown",o),w&&l(e,null==v?void 0:v.splitKey).forEach((function(e){return w.addHotkey(s(e,null==v?void 0:v.combinationKey))})),function(){(u.current||document).removeEventListener("keyup",i),(u.current||document).removeEventListener("keydown",o),w&&l(e,null==v?void 0:v.splitKey).forEach((function(e){return w.removeHotkey(s(e,null==v?void 0:v.combinationKey))}))}}}),[e,y,v,k]),u},exports.useHotkeysContext=p;
2
+ //# sourceMappingURL=react-hotkeys-hook.cjs.production.min.js.map