react-hotkeys-hook 4.3.1 → 4.3.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.
- package/dist/react-hotkeys-hook.cjs.development.js +34 -19
- package/dist/react-hotkeys-hook.cjs.development.js.map +1 -1
- package/dist/react-hotkeys-hook.cjs.production.min.js +1 -1
- package/dist/react-hotkeys-hook.cjs.production.min.js.map +1 -1
- package/dist/react-hotkeys-hook.esm.js +34 -19
- package/dist/react-hotkeys-hook.esm.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/validators.d.ts +1 -1
- package/package.json +10 -10
- package/src/parseHotkeys.ts +3 -1
- package/src/types.ts +2 -0
- package/src/useHotkeys.ts +5 -1
- package/src/validators.ts +25 -24
|
@@ -18,7 +18,7 @@ function _extends() {
|
|
|
18
18
|
return _extends.apply(this, arguments);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
var reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod'];
|
|
21
|
+
var reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl'];
|
|
22
22
|
var mappedKeys = {
|
|
23
23
|
esc: 'escape',
|
|
24
24
|
"return": 'enter',
|
|
@@ -26,6 +26,7 @@ var mappedKeys = {
|
|
|
26
26
|
',': 'comma',
|
|
27
27
|
'-': 'slash',
|
|
28
28
|
' ': 'space',
|
|
29
|
+
'`': 'backquote',
|
|
29
30
|
'#': 'backslash',
|
|
30
31
|
'+': 'bracketright',
|
|
31
32
|
'ShiftLeft': 'shift',
|
|
@@ -61,6 +62,7 @@ function parseHotkey(hotkey, combinationKey) {
|
|
|
61
62
|
});
|
|
62
63
|
var modifiers = {
|
|
63
64
|
alt: keys.includes('alt'),
|
|
65
|
+
ctrl: keys.includes('ctrl') || keys.includes('control'),
|
|
64
66
|
shift: keys.includes('shift'),
|
|
65
67
|
meta: keys.includes('meta'),
|
|
66
68
|
mod: keys.includes('mod')
|
|
@@ -177,35 +179,45 @@ function isScopeActive(activeScopes, scopes) {
|
|
|
177
179
|
return scopes.includes(scope);
|
|
178
180
|
}) || activeScopes.includes('*');
|
|
179
181
|
}
|
|
180
|
-
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey) {
|
|
182
|
+
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey, ignoreModifiers) {
|
|
183
|
+
if (ignoreModifiers === void 0) {
|
|
184
|
+
ignoreModifiers = false;
|
|
185
|
+
}
|
|
181
186
|
var alt = hotkey.alt,
|
|
182
187
|
meta = hotkey.meta,
|
|
183
188
|
mod = hotkey.mod,
|
|
184
189
|
shift = hotkey.shift,
|
|
190
|
+
ctrl = hotkey.ctrl,
|
|
185
191
|
keys = hotkey.keys;
|
|
186
192
|
var pressedKeyUppercase = e.key,
|
|
187
|
-
code = e.code
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
code = e.code,
|
|
194
|
+
ctrlKey = e.ctrlKey,
|
|
195
|
+
metaKey = e.metaKey,
|
|
196
|
+
shiftKey = e.shiftKey,
|
|
197
|
+
altKey = e.altKey;
|
|
192
198
|
var keyCode = mapKey(code);
|
|
193
199
|
var pressedKey = pressedKeyUppercase.toLowerCase();
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (shiftKey !== shift && pressedKey !== 'shift') {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
|
|
201
|
-
if (mod) {
|
|
202
|
-
if (!metaKey && !ctrlKey) {
|
|
200
|
+
if (!ignoreModifiers) {
|
|
201
|
+
// We check the pressed keys for compatibility with the keyup event. In keyup events the modifier flags are not set.
|
|
202
|
+
if (alt === !altKey && alt && pressedKey !== 'alt') {
|
|
203
203
|
return false;
|
|
204
204
|
}
|
|
205
|
-
|
|
206
|
-
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
|
|
205
|
+
if (shift === !shiftKey && shift && pressedKey !== 'shift') {
|
|
207
206
|
return false;
|
|
208
207
|
}
|
|
208
|
+
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
|
|
209
|
+
if (mod) {
|
|
210
|
+
if (!metaKey && !ctrlKey) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
if (meta === !metaKey && meta && pressedKey !== 'meta') {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (ctrl === !ctrlKey && ctrl && pressedKey !== 'ctrl') {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
209
221
|
}
|
|
210
222
|
// All modifiers are correct, now check the key
|
|
211
223
|
// If the key is set, we check for the key
|
|
@@ -385,7 +397,10 @@ function useHotkeys(keys, callback, options, dependencies) {
|
|
|
385
397
|
parseKeysHookInput(keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
|
|
386
398
|
var _hotkey$keys;
|
|
387
399
|
var hotkey = parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey);
|
|
388
|
-
if (
|
|
400
|
+
if (isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.ignoreModifiers) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) {
|
|
401
|
+
if (isKeyUp && hasTriggeredRef.current) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
389
404
|
maybePreventDefault(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.preventDefault);
|
|
390
405
|
if (!isHotkeyEnabled(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.enabled)) {
|
|
391
406
|
stopPropagation(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-hotkeys-hook.cjs.development.js","sources":["../src/parseHotkeys.ts","../src/isHotkeyPressed.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/deepEqual.ts","../src/HotkeysProvider.tsx","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/useRecordHotkeys.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n '.': 'period',\n ',': 'comma',\n '-': 'slash',\n ' ': 'space',\n '#': 'backslash',\n '+': 'bracketright',\n 'ShiftLeft': 'shift',\n 'ShiftRight': 'shift',\n 'AltLeft': 'alt',\n 'AltRight': 'alt',\n 'MetaLeft': 'meta',\n 'MetaRight': 'meta',\n 'ControlLeft': 'ctrl',\n 'ControlRight': 'ctrl',\n}\n\nexport function mapKey(key: string): string {\n return (mappedKeys[key] || key)\n .trim()\n .toLowerCase()\n .replace('key', '')\n .replace('digit', '')\n .replace('numpad', '')\n .replace('arrow', '')\n}\n\nexport function isHotkeyModifier(key: string) {\n return reservedModifierKeywords.includes(key)\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 => mapKey(k))\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\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 { isHotkeyModifier, mapKey } from './parseHotkeys'\n\nconst currentlyPressedKeys: Set<string> = new Set<string>()\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) => currentlyPressedKeys.has(hotkey.trim().toLowerCase()))\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (currentlyPressedKeys.has('meta')) {\n currentlyPressedKeys.forEach(key => !isHotkeyModifier(key) && currentlyPressedKeys.delete(key.toLowerCase()))\n }\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(hotkey.toLowerCase()))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (key === 'meta') {\n currentlyPressedKeys.clear()\n } else {\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.delete(hotkey.toLowerCase()))\n }\n}\n\n(() => {\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n\n document.addEventListener('keyup', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('blur', () => {\n currentlyPressedKeys.clear()\n })\n }\n})()\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\nimport { isHotkeyPressed } from './isHotkeyPressed'\nimport { mapKey } from './parseHotkeys'\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): boolean => {\n const { alt, meta, mod, shift, keys } = hotkey\n const { key: pressedKeyUppercase, code } = e\n\n const altKey = isHotkeyPressed('alt')\n const shiftKey = isHotkeyPressed('shift')\n const metaKey = isHotkeyPressed('meta')\n const ctrlKey = isHotkeyPressed('ctrl')\n\n const keyCode = mapKey(code)\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 && ctrlKey !== meta && keyCode !== 'meta' && 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 isHotkeyPressed(keys)\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","export default function deepEqual(x: any, y: any): boolean {\n //@ts-ignore\n return (x && y && typeof x === 'object' && typeof y === 'object')\n //@ts-ignore\n ? (Object.keys(x).length === Object.keys(y).length) && Object.keys(x).reduce(function(isEqual, key) {\n return isEqual && deepEqual(x[key], y[key])\n }, true)\n : (x === y)\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useState, useContext, useCallback } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\nimport deepEqual from './deepEqual'\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 enableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n })\n }, [])\n\n const disableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n })\n }, [])\n\n const toggleScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes(scope)) {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n } else {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n }\n })\n }, [])\n\n const addBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => [...prev, hotkey])\n }, [])\n\n const removeBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => prev.filter(h => !deepEqual(h, hotkey)))\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 deepEqual from './deepEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!deepEqual(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 { mapKey, 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'\nimport { pushToCurrentlyPressedKeys, removeFromCurrentlyPressedKeys } from './isHotkeyPressed'\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 hasTriggeredRef = useRef(false)\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, isKeyUp: boolean = false) => {\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 WON'T TRIGGER THE HOTKEY.\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) || hotkey.keys?.includes('*')) && !hasTriggeredRef.current) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n // Execute the user callback for that hotkey\n cb(e, hotkey)\n\n if (!isKeyUp) {\n hasTriggeredRef.current = true\n }\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys(mapKey(event.code))\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 === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys(mapKey(event.code))\n\n hasTriggeredRef.current = false\n\n if (memoisedOptions?.keyup) {\n listener(event, true)\n }\n }\n\n // @ts-ignore\n (ref.current || _options?.document || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 || _options?.document || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 { useCallback, useState } from 'react'\nimport { mapKey } from './parseHotkeys'\n\nexport default function useRecordHotkeys() {\n const [keys, setKeys] = useState(new Set<string>())\n const [isRecording, setIsRecording] = useState(false);\n\n const handler = useCallback((event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n setKeys(prev => {\n const newKeys = new Set(prev)\n\n newKeys.add(mapKey(event.code))\n\n return newKeys\n })\n }, [])\n\n const stop = useCallback(() => {\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handler)\n\n setIsRecording(false)\n }\n }, [handler])\n\n const start = useCallback(() => {\n setKeys(new Set<string>())\n\n if (typeof document !== 'undefined') {\n stop()\n\n document.addEventListener('keydown', handler)\n\n setIsRecording(true)\n }\n }, [handler, stop])\n\n return [keys, { start, stop, isRecording }] as const\n}\n"],"names":["reservedModifierKeywords","mappedKeys","esc","mapKey","key","trim","toLowerCase","replace","isHotkeyModifier","includes","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","modifiers","alt","shift","meta","mod","singleCharKeys","filter","currentlyPressedKeys","Set","isHotkeyPressed","hotkeyArray","Array","isArray","every","has","pushToCurrentlyPressedKeys","forEach","add","removeFromCurrentlyPressedKeys","clear","document","addEventListener","e","undefined","code","window","maybePreventDefault","preventDefault","isHotkeyEnabled","enabled","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Boolean","some","tag","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","pressedKeyUppercase","altKey","shiftKey","metaKey","ctrlKey","keyCode","pressedKey","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","deepEqual","x","y","Object","reduce","isEqual","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","useCallback","prev","from","s","addBoundHotkey","removeBoundHotkey","h","useDeepEqualMemo","value","ref","useRef","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","hasTriggeredRef","_options","_deps","cb","memoisedOptions","proxy","listener","isKeyUp","enableOnFormTags","activeElement","contains","isContentEditable","enableOnContentEditable","handleKeyDown","event","keydown","keyup","handleKeyUp","removeEventListener","useRecordHotkeys","setKeys","isRecording","setIsRecording","handler","newKeys","stop","start"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;AAEhE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACf,GAAG,EAAE,QAAQ;EACb,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,WAAW;EAChB,G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W;IAAEC,cAAc;EAElC,IAAMC,OAAO,GAAG5C,iBAAW,CAAC,UAACmC,KAAoB;IAC/C,IAAIA,KAAK,CAACvI,GAAG,KAAKuC,SAAS,EAAE;;MAE3B;;IAGFgG,KAAK,CAAC5F,cAAc,EAAE;IACtB4F,KAAK,CAACvB,eAAe,EAAE;IAEvB6B,OAAO,CAAC,UAAAxC,IAAI;MACV,IAAM4C,OAAO,GAAG,IAAIzH,GAAG,CAAC6E,IAAI,CAAC;MAE7B4C,OAAO,CAAChH,GAAG,CAAClC,MAAM,CAACwI,KAAK,CAAC/F,IAAI,CAAC,CAAC;MAE/B,OAAOyG,OAAO;KACf,CAAC;GACH,EAAE,EAAE,CAAC;EAEN,IAAMC,IAAI,GAAG9C,iBAAW,CAAC;IACvB,IAAI,OAAOhE,QAAQ,KAAK,WAAW,EAAE;MACnCA,QAAQ,CAACuG,mBAAmB,CAAC,SAAS,EAAEK,OAAO,CAAC;MAEhDD,cAAc,CAAC,KAAK,CAAC;;GAExB,EAAE,CAACC,OAAO,CAAC,CAAC;EAEb,IAAMG,KAAK,GAAG/C,iBAAW,CAAC;IACxByC,OAAO,CAAC,IAAIrH,GAAG,EAAU,CAAC;IAE1B,IAAI,OAAOY,QAAQ,KAAK,WAAW,EAAE;MACnC8G,IAAI,EAAE;MAEN9G,QAAQ,CAACC,gBAAgB,CAAC,SAAS,EAAE2G,OAAO,CAAC;MAE7CD,cAAc,CAAC,IAAI,CAAC;;GAEvB,EAAE,CAACC,OAAO,EAAEE,IAAI,CAAC,CAAC;EAEnB,OAAO,CAAC3I,IAAI,EAAE;IAAE4I,KAAK,EAALA,KAAK;IAAED,IAAI,EAAJA,IAAI;IAAEJ,WAAW,EAAXA;GAAa,CAAU;AACtD;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"react-hotkeys-hook.cjs.development.js","sources":["../src/parseHotkeys.ts","../src/isHotkeyPressed.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/deepEqual.ts","../src/HotkeysProvider.tsx","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/useRecordHotkeys.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n '.': 'period',\n ',': 'comma',\n '-': 'slash',\n ' ': 'space',\n '`': 'backquote',\n '#': 'backslash',\n '+': 'bracketright',\n 'ShiftLeft': 'shift',\n 'ShiftRight': 'shift',\n 'AltLeft': 'alt',\n 'AltRight': 'alt',\n 'MetaLeft': 'meta',\n 'MetaRight': 'meta',\n 'ControlLeft': 'ctrl',\n 'ControlRight': 'ctrl',\n}\n\nexport function mapKey(key: string): string {\n return (mappedKeys[key] || key)\n .trim()\n .toLowerCase()\n .replace('key', '')\n .replace('digit', '')\n .replace('numpad', '')\n .replace('arrow', '')\n}\n\nexport function isHotkeyModifier(key: string) {\n return reservedModifierKeywords.includes(key)\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 => mapKey(k))\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl') || keys.includes('control'),\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 { isHotkeyModifier, mapKey } from './parseHotkeys'\n\nconst currentlyPressedKeys: Set<string> = new Set<string>()\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) => currentlyPressedKeys.has(hotkey.trim().toLowerCase()))\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (currentlyPressedKeys.has('meta')) {\n currentlyPressedKeys.forEach(key => !isHotkeyModifier(key) && currentlyPressedKeys.delete(key.toLowerCase()))\n }\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(hotkey.toLowerCase()))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (key === 'meta') {\n currentlyPressedKeys.clear()\n } else {\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.delete(hotkey.toLowerCase()))\n }\n}\n\n(() => {\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n\n document.addEventListener('keyup', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('blur', () => {\n currentlyPressedKeys.clear()\n })\n }\n})()\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\nimport { isHotkeyPressed } from './isHotkeyPressed'\nimport { mapKey } from './parseHotkeys'\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, ignoreModifiers: boolean = false): boolean => {\n const { alt, meta, mod, shift, ctrl, keys } = hotkey\n const { key: pressedKeyUppercase, code, ctrlKey, metaKey, shiftKey, altKey } = e\n\n const keyCode = mapKey(code)\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (!ignoreModifiers) {\n // We check the pressed keys for compatibility with the keyup event. In keyup events the modifier flags are not set.\n if (alt === !altKey && (alt && pressedKey !== 'alt')) {\n return false\n }\n\n if (shift === !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 (meta === !metaKey && (meta && pressedKey !== 'meta')) {\n return false\n }\n\n if (ctrl === !ctrlKey && (ctrl && pressedKey !== 'ctrl')) {\n return false\n }\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 isHotkeyPressed(keys)\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","export default function deepEqual(x: any, y: any): boolean {\n //@ts-ignore\n return (x && y && typeof x === 'object' && typeof y === 'object')\n //@ts-ignore\n ? (Object.keys(x).length === Object.keys(y).length) && Object.keys(x).reduce(function(isEqual, key) {\n return isEqual && deepEqual(x[key], y[key])\n }, true)\n : (x === y)\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useState, useContext, useCallback } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\nimport deepEqual from './deepEqual'\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 enableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n })\n }, [])\n\n const disableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n })\n }, [])\n\n const toggleScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes(scope)) {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n } else {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n }\n })\n }, [])\n\n const addBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => [...prev, hotkey])\n }, [])\n\n const removeBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => prev.filter(h => !deepEqual(h, hotkey)))\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 deepEqual from './deepEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!deepEqual(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 { mapKey, 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'\nimport { pushToCurrentlyPressedKeys, removeFromCurrentlyPressedKeys } from './isHotkeyPressed'\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 hasTriggeredRef = useRef(false)\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, isKeyUp: boolean = false) => {\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 WON'T TRIGGER THE HOTKEY.\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, memoisedOptions?.ignoreModifiers) || hotkey.keys?.includes('*')) {\n if (isKeyUp && hasTriggeredRef.current) {\n return\n }\n\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n // Execute the user callback for that hotkey\n cb(e, hotkey)\n\n if (!isKeyUp) {\n hasTriggeredRef.current = true\n }\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys(mapKey(event.code))\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 === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys(mapKey(event.code))\n\n hasTriggeredRef.current = false\n\n if (memoisedOptions?.keyup) {\n listener(event, true)\n }\n }\n\n // @ts-ignore\n (ref.current || _options?.document || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 || _options?.document || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 { useCallback, useState } from 'react'\nimport { mapKey } from './parseHotkeys'\n\nexport default function useRecordHotkeys() {\n const [keys, setKeys] = useState(new Set<string>())\n const [isRecording, setIsRecording] = useState(false);\n\n const handler = useCallback((event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n setKeys(prev => {\n const newKeys = new Set(prev)\n\n newKeys.add(mapKey(event.code))\n\n return newKeys\n })\n }, [])\n\n const stop = useCallback(() => {\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handler)\n\n setIsRecording(false)\n }\n }, [handler])\n\n const start = useCallback(() => {\n setKeys(new Set<string>())\n\n if (typeof document !== 'undefined') {\n stop()\n\n document.addEventListener('keydown', handler)\n\n setIsRecording(true)\n }\n }, [handler, stop])\n\n return [keys, { start, stop, isRecording }] as const\n}\n"],"names":["reservedModifierKeywords","mappedKeys","esc","mapKey","key","trim","toLowerCase","replace","isHotkeyModifier","includes","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","modifiers","alt","ctrl","shift","meta","mod","singleCharKeys","filter","currentlyPressedKeys","Set","isHotkeyPressed","hotkeyArray","Array","isArray","every","has","pushToCurrentlyPressedKeys","forEach","add","removeFromCurrentlyPressedKeys","clear","document","addEventListener","e","undefined","code","window","maybePreventDefault","preventDefault","isHotkeyEnabled","enabled","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Boolean","some","tag","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","ignoreModifiers","pressedKeyUppercase","ctrlKey","metaKey","shiftKey","altKey","keyCode","pressedKey","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","deepEqual","x","y","Object","reduce","isEqual","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","useCallback","prev","from","s","addBoundHotkey","removeBoundHotkey","h","useDeepEqualMemo","value","ref","useRef","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","hasTriggeredRef","_options","_deps","cb","memoisedOptions","proxy","listener","isKeyUp","enableOnFormTags","activeElement","contains","isContentEditable","enableOnContentEditable","handleKeyDown","event","keydown","keyup","handleKeyUp","removeEventListener","useRecordHotkeys","setKeys","isRecording","setIsRecording","handler","newKeys","stop","start"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;AAExE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAA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OAAO,CAAC,IAAItH,GAAG,EAAU,CAAC;IAE1B,IAAI,OAAOY,QAAQ,KAAK,WAAW,EAAE;MACnC+G,IAAI,EAAE;MAEN/G,QAAQ,CAACC,gBAAgB,CAAC,SAAS,EAAE4G,OAAO,CAAC;MAE7CD,cAAc,CAAC,IAAI,CAAC;;GAEvB,EAAE,CAACC,OAAO,EAAEE,IAAI,CAAC,CAAC;EAEnB,OAAO,CAAC7I,IAAI,EAAE;IAAE8I,KAAK,EAALA,KAAK;IAAED,IAAI,EAAJA,IAAI;IAAEJ,WAAW,EAAXA;GAAa,CAAU;AACtD;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=require("react/jsx-runtime");function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var o=["shift","alt","meta","mod"],r={esc:"escape",return:"enter",".":"period",",":"comma","-":"slash"," ":"space","#":"backslash","+":"bracketright",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function u(e){return(r[e]||e).trim().toLowerCase().replace("key","").replace("digit","").replace("numpad","").replace("arrow","")}function i(e,t){return void 0===t&&(t=","),"string"==typeof e?e.split(t):e}function c(e,t){void 0===t&&(t="+");var r=e.toLocaleLowerCase().split(t).map((function(e){return u(e)}));return n({},{alt:r.includes("alt"),shift:r.includes("shift"),meta:r.includes("meta"),mod:r.includes("mod")},{keys:r.filter((function(e){return!o.includes(e)}))})}var a=new Set;function l(e,t){return void 0===t&&(t=","),(Array.isArray(e)?e:e.split(t)).every((function(e){return a.has(e.trim().toLowerCase())}))}function d(e){var t=Array.isArray(e)?e:[e];a.has("meta")&&a.forEach((function(e){return!function(e){return o.includes(e)}(e)&&a.delete(e.toLowerCase())})),t.forEach((function(e){return a.add(e.toLowerCase())}))}function s(e){var t=Array.isArray(e)?e:[e];"meta"===e?a.clear():t.forEach((function(e){return a.delete(e.toLowerCase())}))}function f(e,t){var n=e.target;void 0===t&&(t=!1);var o=n&&n.tagName;return t instanceof Array?Boolean(o&&t&&t.some((function(e){return e.toLowerCase()===o.toLowerCase()}))):Boolean(o&&t&&!0===t)}"undefined"!=typeof document&&(document.addEventListener("keydown",(function(e){void 0!==e.key&&d([u(e.key),u(e.code)])})),document.addEventListener("keyup",(function(e){void 0!==e.key&&s([u(e.key),u(e.code)])}))),"undefined"!=typeof window&&window.addEventListener("blur",(function(){a.clear()}));var v=e.createContext(void 0);function y(e){return t.jsx(v.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}function p(e,t){return e&&t&&"object"==typeof e&&"object"==typeof t?Object.keys(e).length===Object.keys(t).length&&Object.keys(e).reduce((function(n,o){return n&&p(e[o],t[o])}),!0):e===t}var m=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),k=function(){return e.useContext(m)},h=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},b="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;exports.HotkeysProvider=function(n){var o=n.initiallyActiveScopes,r=void 0===o?["*"]:o,u=n.children,i=e.useState((null==r?void 0:r.length)>0?r:["*"]),c=i[0],a=i[1],l=e.useState([]),d=l[0],s=l[1],f=e.useCallback((function(e){a((function(t){return t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),v=e.useCallback((function(e){a((function(t){return 0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e}))}))}),[]),k=e.useCallback((function(e){a((function(t){return t.includes(e)?0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e})):t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),h=e.useCallback((function(e){s((function(t){return[].concat(t,[e])}))}),[]),b=e.useCallback((function(e){s((function(t){return t.filter((function(t){return!p(t,e)}))}))}),[]);return t.jsx(m.Provider,{value:{enabledScopes:c,hotkeys:d,enableScope:f,disableScope:v,toggleScope:k},children:t.jsx(y,{addHotkey:h,removeHotkey:b,children:u})})},exports.isHotkeyPressed=l,exports.useHotkeys=function(t,n,o,r){var a=e.useRef(null),y=e.useRef(!1),m=o instanceof Array?r instanceof Array?void 0:r:o,w=e.useCallback(n,[].concat(o instanceof Array?o:r instanceof Array?r:[])),g=function(t){var n=e.useRef(void 0);return p(n.current,t)||(n.current=t),n.current}(m),C=k().enabledScopes,L=e.useContext(v);return b((function(){if(!1!==(null==g?void 0:g.enabled)&&(n=null==g?void 0:g.scopes,0===(e=C).length&&n?(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):!n||e.some((function(e){return n.includes(e)}))||e.includes("*"))){var e,n,o=function(e,n){var o;void 0===n&&(n=!1),(!f(e,["input","textarea","select"])||f(e,null==g?void 0:g.enableOnFormTags))&&(null===a.current||document.activeElement===a.current||a.current.contains(document.activeElement)?(null==(o=e.target)||!o.isContentEditable||null!=g&&g.enableOnContentEditable)&&i(t,null==g?void 0:g.splitKey).forEach((function(t){var o,r=c(t,null==g?void 0:g.combinationKey);if(
|
|
1
|
+
"use strict";var e=require("react"),t=require("react/jsx-runtime");function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var o=["shift","alt","meta","mod","ctrl"],r={esc:"escape",return:"enter",".":"period",",":"comma","-":"slash"," ":"space","`":"backquote","#":"backslash","+":"bracketright",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function u(e){return(r[e]||e).trim().toLowerCase().replace("key","").replace("digit","").replace("numpad","").replace("arrow","")}function i(e,t){return void 0===t&&(t=","),"string"==typeof e?e.split(t):e}function c(e,t){void 0===t&&(t="+");var r=e.toLocaleLowerCase().split(t).map((function(e){return u(e)}));return n({},{alt:r.includes("alt"),ctrl:r.includes("ctrl")||r.includes("control"),shift:r.includes("shift"),meta:r.includes("meta"),mod:r.includes("mod")},{keys:r.filter((function(e){return!o.includes(e)}))})}var a=new Set;function l(e,t){return void 0===t&&(t=","),(Array.isArray(e)?e:e.split(t)).every((function(e){return a.has(e.trim().toLowerCase())}))}function d(e){var t=Array.isArray(e)?e:[e];a.has("meta")&&a.forEach((function(e){return!function(e){return o.includes(e)}(e)&&a.delete(e.toLowerCase())})),t.forEach((function(e){return a.add(e.toLowerCase())}))}function s(e){var t=Array.isArray(e)?e:[e];"meta"===e?a.clear():t.forEach((function(e){return a.delete(e.toLowerCase())}))}function f(e,t){var n=e.target;void 0===t&&(t=!1);var o=n&&n.tagName;return t instanceof Array?Boolean(o&&t&&t.some((function(e){return e.toLowerCase()===o.toLowerCase()}))):Boolean(o&&t&&!0===t)}"undefined"!=typeof document&&(document.addEventListener("keydown",(function(e){void 0!==e.key&&d([u(e.key),u(e.code)])})),document.addEventListener("keyup",(function(e){void 0!==e.key&&s([u(e.key),u(e.code)])}))),"undefined"!=typeof window&&window.addEventListener("blur",(function(){a.clear()}));var v=e.createContext(void 0);function y(e){return t.jsx(v.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}function p(e,t){return e&&t&&"object"==typeof e&&"object"==typeof t?Object.keys(e).length===Object.keys(t).length&&Object.keys(e).reduce((function(n,o){return n&&p(e[o],t[o])}),!0):e===t}var m=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),k=function(){return e.useContext(m)},h=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},b="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;exports.HotkeysProvider=function(n){var o=n.initiallyActiveScopes,r=void 0===o?["*"]:o,u=n.children,i=e.useState((null==r?void 0:r.length)>0?r:["*"]),c=i[0],a=i[1],l=e.useState([]),d=l[0],s=l[1],f=e.useCallback((function(e){a((function(t){return t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),v=e.useCallback((function(e){a((function(t){return 0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e}))}))}),[]),k=e.useCallback((function(e){a((function(t){return t.includes(e)?0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e})):t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),h=e.useCallback((function(e){s((function(t){return[].concat(t,[e])}))}),[]),b=e.useCallback((function(e){s((function(t){return t.filter((function(t){return!p(t,e)}))}))}),[]);return t.jsx(m.Provider,{value:{enabledScopes:c,hotkeys:d,enableScope:f,disableScope:v,toggleScope:k},children:t.jsx(y,{addHotkey:h,removeHotkey:b,children:u})})},exports.isHotkeyPressed=l,exports.useHotkeys=function(t,n,o,r){var a=e.useRef(null),y=e.useRef(!1),m=o instanceof Array?r instanceof Array?void 0:r:o,w=e.useCallback(n,[].concat(o instanceof Array?o:r instanceof Array?r:[])),g=function(t){var n=e.useRef(void 0);return p(n.current,t)||(n.current=t),n.current}(m),C=k().enabledScopes,L=e.useContext(v);return b((function(){if(!1!==(null==g?void 0:g.enabled)&&(n=null==g?void 0:g.scopes,0===(e=C).length&&n?(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):!n||e.some((function(e){return n.includes(e)}))||e.includes("*"))){var e,n,o=function(e,n){var o;void 0===n&&(n=!1),(!f(e,["input","textarea","select"])||f(e,null==g?void 0:g.enableOnFormTags))&&(null===a.current||document.activeElement===a.current||a.current.contains(document.activeElement)?(null==(o=e.target)||!o.isContentEditable||null!=g&&g.enableOnContentEditable)&&i(t,null==g?void 0:g.splitKey).forEach((function(t){var o,r=c(t,null==g?void 0:g.combinationKey);if(function(e,t,n){void 0===n&&(n=!1);var o=t.alt,r=t.meta,i=t.mod,c=t.shift,a=t.ctrl,d=t.keys,s=e.key,f=e.ctrlKey,v=e.metaKey,y=e.shiftKey,p=e.altKey,m=u(e.code),k=s.toLowerCase();if(!n){if(o===!p&&o&&"alt"!==k)return!1;if(c===!y&&c&&"shift"!==k)return!1;if(i){if(!v&&!f)return!1}else{if(r===!v&&r&&"meta"!==k)return!1;if(a===!f&&a&&"ctrl"!==k)return!1}}return!(!d||1!==d.length||!d.includes(k)&&!d.includes(m))||(d?l(d):!d)}(e,r,null==g?void 0:g.ignoreModifiers)||null!=(o=r.keys)&&o.includes("*")){if(n&&y.current)return;if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==g?void 0:g.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==g?void 0:g.enabled))return void h(e);w(e,r),n||(y.current=!0)}})):h(e))},r=function(e){void 0!==e.key&&(d(u(e.code)),(void 0===(null==g?void 0:g.keydown)&&!0!==(null==g?void 0:g.keyup)||null!=g&&g.keydown)&&o(e))},v=function(e){void 0!==e.key&&(s(u(e.code)),y.current=!1,null!=g&&g.keyup&&o(e,!0))};return(a.current||(null==m?void 0:m.document)||document).addEventListener("keyup",v),(a.current||(null==m?void 0:m.document)||document).addEventListener("keydown",r),L&&i(t,null==g?void 0:g.splitKey).forEach((function(e){return L.addHotkey(c(e,null==g?void 0:g.combinationKey))})),function(){(a.current||(null==m?void 0:m.document)||document).removeEventListener("keyup",v),(a.current||(null==m?void 0:m.document)||document).removeEventListener("keydown",r),L&&i(t,null==g?void 0:g.splitKey).forEach((function(e){return L.removeHotkey(c(e,null==g?void 0:g.combinationKey))}))}}}),[t,w,g,C]),a},exports.useHotkeysContext=k,exports.useRecordHotkeys=function(){var t=e.useState(new Set),n=t[0],o=t[1],r=e.useState(!1),i=r[0],c=r[1],a=e.useCallback((function(e){void 0!==e.key&&(e.preventDefault(),e.stopPropagation(),o((function(t){var n=new Set(t);return n.add(u(e.code)),n})))}),[]),l=e.useCallback((function(){"undefined"!=typeof document&&(document.removeEventListener("keydown",a),c(!1))}),[a]);return[n,{start:e.useCallback((function(){o(new Set),"undefined"!=typeof document&&(l(),document.addEventListener("keydown",a),c(!0))}),[a,l]),stop:l,isRecording:i}]};
|
|
2
2
|
//# sourceMappingURL=react-hotkeys-hook.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-hotkeys-hook.cjs.production.min.js","sources":["../src/parseHotkeys.ts","../src/isHotkeyPressed.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/deepEqual.ts","../src/HotkeysProvider.tsx","../src/useHotkeys.ts","../src/useDeepEqualMemo.ts","../src/useRecordHotkeys.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n '.': 'period',\n ',': 'comma',\n '-': 'slash',\n ' ': 'space',\n '#': 'backslash',\n '+': 'bracketright',\n 'ShiftLeft': 'shift',\n 'ShiftRight': 'shift',\n 'AltLeft': 'alt',\n 'AltRight': 'alt',\n 'MetaLeft': 'meta',\n 'MetaRight': 'meta',\n 'ControlLeft': 'ctrl',\n 'ControlRight': 'ctrl',\n}\n\nexport function mapKey(key: string): string {\n return (mappedKeys[key] || key)\n .trim()\n .toLowerCase()\n .replace('key', '')\n .replace('digit', '')\n .replace('numpad', '')\n .replace('arrow', '')\n}\n\nexport function isHotkeyModifier(key: string) {\n return reservedModifierKeywords.includes(key)\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 => mapKey(k))\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\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 { isHotkeyModifier, mapKey } from './parseHotkeys'\n\nconst currentlyPressedKeys: Set<string> = new Set<string>()\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) => currentlyPressedKeys.has(hotkey.trim().toLowerCase()))\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (currentlyPressedKeys.has('meta')) {\n currentlyPressedKeys.forEach(key => !isHotkeyModifier(key) && currentlyPressedKeys.delete(key.toLowerCase()))\n }\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(hotkey.toLowerCase()))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (key === 'meta') {\n currentlyPressedKeys.clear()\n } else {\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.delete(hotkey.toLowerCase()))\n }\n}\n\n(() => {\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n\n document.addEventListener('keyup', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('blur', () => {\n currentlyPressedKeys.clear()\n })\n }\n})()\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\nimport { isHotkeyPressed } from './isHotkeyPressed'\nimport { mapKey } from './parseHotkeys'\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): boolean => {\n const { alt, meta, mod, shift, keys } = hotkey\n const { key: pressedKeyUppercase, code } = e\n\n const altKey = isHotkeyPressed('alt')\n const shiftKey = isHotkeyPressed('shift')\n const metaKey = isHotkeyPressed('meta')\n const ctrlKey = isHotkeyPressed('ctrl')\n\n const keyCode = mapKey(code)\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 && ctrlKey !== meta && keyCode !== 'meta' && 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 isHotkeyPressed(keys)\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","export default function deepEqual(x: any, y: any): boolean {\n //@ts-ignore\n return (x && y && typeof x === 'object' && typeof y === 'object')\n //@ts-ignore\n ? (Object.keys(x).length === Object.keys(y).length) && Object.keys(x).reduce(function(isEqual, key) {\n return isEqual && deepEqual(x[key], y[key])\n }, true)\n : (x === y)\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useState, useContext, useCallback } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\nimport deepEqual from './deepEqual'\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 enableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n })\n }, [])\n\n const disableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n })\n }, [])\n\n const toggleScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes(scope)) {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n } else {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n }\n })\n }, [])\n\n const addBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => [...prev, hotkey])\n }, [])\n\n const removeBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => prev.filter(h => !deepEqual(h, hotkey)))\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 { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'\nimport { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { mapKey, 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'\nimport { pushToCurrentlyPressedKeys, removeFromCurrentlyPressedKeys } from './isHotkeyPressed'\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 hasTriggeredRef = useRef(false)\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, isKeyUp: boolean = false) => {\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 WON'T TRIGGER THE HOTKEY.\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) || hotkey.keys?.includes('*')) && !hasTriggeredRef.current) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n // Execute the user callback for that hotkey\n cb(e, hotkey)\n\n if (!isKeyUp) {\n hasTriggeredRef.current = true\n }\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys(mapKey(event.code))\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 === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys(mapKey(event.code))\n\n hasTriggeredRef.current = false\n\n if (memoisedOptions?.keyup) {\n listener(event, true)\n }\n }\n\n // @ts-ignore\n (ref.current || _options?.document || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 || _options?.document || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 { useRef } from 'react'\nimport deepEqual from './deepEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!deepEqual(ref.current, value)) {\n ref.current = value\n }\n\n return ref.current\n}\n","import { useCallback, useState } from 'react'\nimport { mapKey } from './parseHotkeys'\n\nexport default function useRecordHotkeys() {\n const [keys, setKeys] = useState(new Set<string>())\n const [isRecording, setIsRecording] = useState(false);\n\n const handler = useCallback((event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n setKeys(prev => {\n const newKeys = new Set(prev)\n\n newKeys.add(mapKey(event.code))\n\n return newKeys\n })\n }, [])\n\n const stop = useCallback(() => {\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handler)\n\n setIsRecording(false)\n }\n }, [handler])\n\n const start = useCallback(() => {\n setKeys(new Set<string>())\n\n if (typeof document !== 'undefined') {\n stop()\n\n document.addEventListener('keydown', handler)\n\n setIsRecording(true)\n }\n }, [handler, stop])\n\n return [keys, { start, stop, isRecording }] as const\n}\n"],"names":["reservedModifierKeywords","mappedKeys","esc","return",".",",","-"," ","#","+","ShiftLeft","ShiftRight","AltLeft","AltRight","MetaLeft","MetaRight","ControlLeft","ControlRight","mapKey","key","trim","toLowerCase","replace","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","alt","includes","shift","meta","mod","filter","currentlyPressedKeys","Set","isHotkeyPressed","Array","isArray","every","has","pushToCurrentlyPressedKeys","hotkeyArray","forEach","isHotkeyModifier","add","removeFromCurrentlyPressedKeys","clear","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Boolean","some","tag","document","addEventListener","e","undefined","code","window","BoundHotkeysProxyProvider","createContext","BoundHotkeysProxyProviderProvider","_jsx","Provider","value","addHotkey","removeHotkey","children","deepEqual","x","y","Object","length","reduce","isEqual","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","useContext","stopPropagation","preventDefault","stopImmediatePropagation","useSafeLayoutEffect","useLayoutEffect","useEffect","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","useCallback","scope","prev","from","s","addBoundHotkey","removeBoundHotkey","h","callback","options","dependencies","ref","useRef","hasTriggeredRef","_options","cb","memoisedOptions","current","useDeepEqualMemo","proxy","enabled","scopes","activeScopes","console","warn","listener","isKeyUp","enableOnFormTags","activeElement","contains","_e$target","isContentEditable","enableOnContentEditable","pressedKeyUppercase","altKey","shiftKey","metaKey","ctrlKey","keyCode","pressedKey","isHotkeyMatchingKeyboardEvent","_hotkey$keys","maybePreventDefault","isHotkeyEnabled","handleKeyDown","event","keydown","keyup","handleKeyUp","removeEventListener","setKeys","isRecording","setIsRecording","handler","newKeys","stop","start"],"mappings":"sSAEA,IAAMA,EAA2B,CAAC,QAAS,MAAO,OAAQ,OAEpDC,EAAqC,CACzCC,IAAK,SACLC,OAAQ,QACRC,IAAK,SACLC,IAAK,QACLC,IAAK,QACLC,IAAK,QACLC,IAAK,YACLC,IAAK,eACLC,UAAa,QACbC,WAAc,QACdC,QAAW,MACXC,SAAY,MACZC,SAAY,OACZC,UAAa,OACbC,YAAe,OACfC,aAAgB,iBAGFC,EAAOC,GACrB,OAAQlB,EAAWkB,IAAQA,GACxBC,OACAC,cACAC,QAAQ,MAAO,IACfA,QAAQ,QAAS,IACjBA,QAAQ,SAAU,IAClBA,QAAQ,QAAS,aAONC,EAAmBC,EAAYC,GAC7C,gBAD6CA,IAAAA,EAAmB,KAC5C,iBAATD,EACFA,EAAKE,MAAMD,GAGbD,WAGOG,EAAYC,EAAgBC,YAAAA,IAAAA,EAAyB,KACnE,IAAML,EAAOI,EACVE,oBACAJ,MAAMG,GACNE,KAAI,SAAAC,GAAC,OAAId,EAAOc,MAWnB,YATqC,CACnCC,IAAKT,EAAKU,SAAS,OACnBC,MAAOX,EAAKU,SAAS,SACrBE,KAAMZ,EAAKU,SAAS,QACpBG,IAAKb,EAAKU,SAAS,SAOnBV,KAJqBA,EAAKc,QAAO,SAACN,GAAC,OAAMhC,EAAyBkC,SAASF,QCxD/E,IAAMO,EAAoC,IAAIC,aAE9BC,EAAgBtB,EAAwBM,GAGtD,gBAHsDA,IAAAA,EAAmB,MACrDiB,MAAMC,QAAQxB,GAAOA,EAAMA,EAAIO,MAAMD,IAEtCmB,OAAM,SAAChB,GAAM,OAAKW,EAAqBM,IAAIjB,EAAOR,OAAOC,2BAG9DyB,EAA2B3B,GACzC,IAAM4B,EAAcL,MAAMC,QAAQxB,GAAOA,EAAM,CAACA,GAO5CoB,EAA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,EAAUrD,eAAY,SAAC6C,QACTpF,IAAdoF,EAAMjI,MAKViI,EAAMxD,iBACNwD,EAAMzD,kBAEN8D,GAAQ,SAAAhD,GACN,IAAMoD,EAAU,IAAIrH,IAAIiE,GAIxB,OAFAoD,EAAQ3G,IAAIhC,EAAOkI,EAAMnF,OAElB4F,QAER,IAEGC,EAAOvD,eAAY,WACC,oBAAb1C,WACTA,SAAS2F,oBAAoB,UAAWI,GAExCD,GAAe,MAEhB,CAACC,IAcJ,MAAO,CAACpI,EAAM,CAAEuI,MAZFxD,eAAY,WACxBkD,EAAQ,IAAIjH,KAEY,oBAAbqB,WACTiG,IAEAjG,SAASC,iBAAiB,UAAW8F,GAErCD,GAAe,MAEhB,CAACC,EAASE,IAEUA,KAAAA,EAAMJ,YAAAA"}
|
|
1
|
+
{"version":3,"file":"react-hotkeys-hook.cjs.production.min.js","sources":["../src/parseHotkeys.ts","../src/isHotkeyPressed.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/deepEqual.ts","../src/HotkeysProvider.tsx","../src/useHotkeys.ts","../src/useDeepEqualMemo.ts","../src/useRecordHotkeys.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n '.': 'period',\n ',': 'comma',\n '-': 'slash',\n ' ': 'space',\n '`': 'backquote',\n '#': 'backslash',\n '+': 'bracketright',\n 'ShiftLeft': 'shift',\n 'ShiftRight': 'shift',\n 'AltLeft': 'alt',\n 'AltRight': 'alt',\n 'MetaLeft': 'meta',\n 'MetaRight': 'meta',\n 'ControlLeft': 'ctrl',\n 'ControlRight': 'ctrl',\n}\n\nexport function mapKey(key: string): string {\n return (mappedKeys[key] || key)\n .trim()\n .toLowerCase()\n .replace('key', '')\n .replace('digit', '')\n .replace('numpad', '')\n .replace('arrow', '')\n}\n\nexport function isHotkeyModifier(key: string) {\n return reservedModifierKeywords.includes(key)\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 => mapKey(k))\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl') || keys.includes('control'),\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 { isHotkeyModifier, mapKey } from './parseHotkeys'\n\nconst currentlyPressedKeys: Set<string> = new Set<string>()\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) => currentlyPressedKeys.has(hotkey.trim().toLowerCase()))\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (currentlyPressedKeys.has('meta')) {\n currentlyPressedKeys.forEach(key => !isHotkeyModifier(key) && currentlyPressedKeys.delete(key.toLowerCase()))\n }\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(hotkey.toLowerCase()))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (key === 'meta') {\n currentlyPressedKeys.clear()\n } else {\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.delete(hotkey.toLowerCase()))\n }\n}\n\n(() => {\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n\n document.addEventListener('keyup', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('blur', () => {\n currentlyPressedKeys.clear()\n })\n }\n})()\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\nimport { isHotkeyPressed } from './isHotkeyPressed'\nimport { mapKey } from './parseHotkeys'\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, ignoreModifiers: boolean = false): boolean => {\n const { alt, meta, mod, shift, ctrl, keys } = hotkey\n const { key: pressedKeyUppercase, code, ctrlKey, metaKey, shiftKey, altKey } = e\n\n const keyCode = mapKey(code)\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (!ignoreModifiers) {\n // We check the pressed keys for compatibility with the keyup event. In keyup events the modifier flags are not set.\n if (alt === !altKey && (alt && pressedKey !== 'alt')) {\n return false\n }\n\n if (shift === !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 (meta === !metaKey && (meta && pressedKey !== 'meta')) {\n return false\n }\n\n if (ctrl === !ctrlKey && (ctrl && pressedKey !== 'ctrl')) {\n return false\n }\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 isHotkeyPressed(keys)\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","export default function deepEqual(x: any, y: any): boolean {\n //@ts-ignore\n return (x && y && typeof x === 'object' && typeof y === 'object')\n //@ts-ignore\n ? (Object.keys(x).length === Object.keys(y).length) && Object.keys(x).reduce(function(isEqual, key) {\n return isEqual && deepEqual(x[key], y[key])\n }, true)\n : (x === y)\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useState, useContext, useCallback } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\nimport deepEqual from './deepEqual'\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 enableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n })\n }, [])\n\n const disableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n })\n }, [])\n\n const toggleScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes(scope)) {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n } else {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n }\n })\n }, [])\n\n const addBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => [...prev, hotkey])\n }, [])\n\n const removeBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => prev.filter(h => !deepEqual(h, hotkey)))\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 { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'\nimport { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { mapKey, 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'\nimport { pushToCurrentlyPressedKeys, removeFromCurrentlyPressedKeys } from './isHotkeyPressed'\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 hasTriggeredRef = useRef(false)\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, isKeyUp: boolean = false) => {\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 WON'T TRIGGER THE HOTKEY.\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, memoisedOptions?.ignoreModifiers) || hotkey.keys?.includes('*')) {\n if (isKeyUp && hasTriggeredRef.current) {\n return\n }\n\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n // Execute the user callback for that hotkey\n cb(e, hotkey)\n\n if (!isKeyUp) {\n hasTriggeredRef.current = true\n }\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys(mapKey(event.code))\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 === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys(mapKey(event.code))\n\n hasTriggeredRef.current = false\n\n if (memoisedOptions?.keyup) {\n listener(event, true)\n }\n }\n\n // @ts-ignore\n (ref.current || _options?.document || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 || _options?.document || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 { useRef } from 'react'\nimport deepEqual from './deepEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!deepEqual(ref.current, value)) {\n ref.current = value\n }\n\n return ref.current\n}\n","import { useCallback, useState } from 'react'\nimport { mapKey } from './parseHotkeys'\n\nexport default function useRecordHotkeys() {\n const [keys, setKeys] = useState(new Set<string>())\n const [isRecording, setIsRecording] = useState(false);\n\n const handler = useCallback((event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n setKeys(prev => {\n const newKeys = new Set(prev)\n\n newKeys.add(mapKey(event.code))\n\n return newKeys\n })\n }, [])\n\n const stop = useCallback(() => {\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handler)\n\n setIsRecording(false)\n }\n }, [handler])\n\n const start = useCallback(() => {\n setKeys(new Set<string>())\n\n if (typeof document !== 'undefined') {\n stop()\n\n document.addEventListener('keydown', handler)\n\n setIsRecording(true)\n }\n }, [handler, stop])\n\n return [keys, { start, stop, isRecording }] as const\n}\n"],"names":["reservedModifierKeywords","mappedKeys","esc","return",".",",","-"," ","`","#","+","ShiftLeft","ShiftRight","AltLeft","AltRight","MetaLeft","MetaRight","ControlLeft","ControlRight","mapKey","key","trim","toLowerCase","replace","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","alt","includes","ctrl","shift","meta","mod","filter","currentlyPressedKeys","Set","isHotkeyPressed","Array","isArray","every","has","pushToCurrentlyPressedKeys","hotkeyArray","forEach","isHotkeyModifier","add","removeFromCurrentlyPressedKeys","clear","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Boolean","some","tag","document","addEventListener","e","undefined","code","window","BoundHotkeysProxyProvider","createContext","BoundHotkeysProxyProviderProvider","_jsx","Provider","value","addHotkey","removeHotkey","children","deepEqual","x","y","Object","length","reduce","isEqual","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","useContext","stopPropagation","preventDefault","stopImmediatePropagation","useSafeLayoutEffect","useLayoutEffect","useEffect","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","useCallback","scope","prev","from","s","addBoundHotkey","removeBoundHotkey","h","callback","options","dependencies","ref","useRef","hasTriggeredRef","_options","cb","memoisedOptions","current","useDeepEqualMemo","proxy","enabled","scopes","activeScopes","console","warn","listener","isKeyUp","enableOnFormTags","activeElement","contains","_e$target","isContentEditable","enableOnContentEditable","ignoreModifiers","pressedKeyUppercase","ctrlKey","metaKey","shiftKey","altKey","keyCode","pressedKey","isHotkeyMatchingKeyboardEvent","_hotkey$keys","maybePreventDefault","isHotkeyEnabled","handleKeyDown","event","keydown","keyup","handleKeyUp","removeEventListener","setKeys","isRecording","setIsRecording","handler","newKeys","stop","start"],"mappings":"sSAEA,IAAMA,EAA2B,CAAC,QAAS,MAAO,OAAQ,MAAO,QAE3DC,EAAqC,CACzCC,IAAK,SACLC,OAAQ,QACRC,IAAK,SACLC,IAAK,QACLC,IAAK,QACLC,IAAK,QACLC,IAAK,YACLC,IAAK,YACLC,IAAK,eACLC,UAAa,QACbC,WAAc,QACdC,QAAW,MACXC,SAAY,MACZC,SAAY,OACZC,UAAa,OACbC,YAAe,OACfC,aAAgB,iBAGFC,EAAOC,GACrB,OAAQnB,EAAWmB,IAAQA,GACxBC,OACAC,cACAC,QAAQ,MAAO,IACfA,QAAQ,QAAS,IACjBA,QAAQ,SAAU,IAClBA,QAAQ,QAAS,aAONC,EAAmBC,EAAYC,GAC7C,gBAD6CA,IAAAA,EAAmB,KAC5C,iBAATD,EACFA,EAAKE,MAAMD,GAGbD,WAGOG,EAAYC,EAAgBC,YAAAA,IAAAA,EAAyB,KACnE,IAAML,EAAOI,EACVE,oBACAJ,MAAMG,GACNE,KAAI,SAAAC,GAAC,OAAId,EAAOc,MAYnB,YAVqC,CACnCC,IAAKT,EAAKU,SAAS,OACnBC,KAAMX,EAAKU,SAAS,SAAWV,EAAKU,SAAS,WAC7CE,MAAOZ,EAAKU,SAAS,SACrBG,KAAMb,EA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
var reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl'];
|
|
20
20
|
var mappedKeys = {
|
|
21
21
|
esc: 'escape',
|
|
22
22
|
"return": 'enter',
|
|
@@ -24,6 +24,7 @@ var mappedKeys = {
|
|
|
24
24
|
',': 'comma',
|
|
25
25
|
'-': 'slash',
|
|
26
26
|
' ': 'space',
|
|
27
|
+
'`': 'backquote',
|
|
27
28
|
'#': 'backslash',
|
|
28
29
|
'+': 'bracketright',
|
|
29
30
|
'ShiftLeft': 'shift',
|
|
@@ -59,6 +60,7 @@ function parseHotkey(hotkey, combinationKey) {
|
|
|
59
60
|
});
|
|
60
61
|
var modifiers = {
|
|
61
62
|
alt: keys.includes('alt'),
|
|
63
|
+
ctrl: keys.includes('ctrl') || keys.includes('control'),
|
|
62
64
|
shift: keys.includes('shift'),
|
|
63
65
|
meta: keys.includes('meta'),
|
|
64
66
|
mod: keys.includes('mod')
|
|
@@ -175,35 +177,45 @@ function isScopeActive(activeScopes, scopes) {
|
|
|
175
177
|
return scopes.includes(scope);
|
|
176
178
|
}) || activeScopes.includes('*');
|
|
177
179
|
}
|
|
178
|
-
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey) {
|
|
180
|
+
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey, ignoreModifiers) {
|
|
181
|
+
if (ignoreModifiers === void 0) {
|
|
182
|
+
ignoreModifiers = false;
|
|
183
|
+
}
|
|
179
184
|
var alt = hotkey.alt,
|
|
180
185
|
meta = hotkey.meta,
|
|
181
186
|
mod = hotkey.mod,
|
|
182
187
|
shift = hotkey.shift,
|
|
188
|
+
ctrl = hotkey.ctrl,
|
|
183
189
|
keys = hotkey.keys;
|
|
184
190
|
var pressedKeyUppercase = e.key,
|
|
185
|
-
code = e.code
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
code = e.code,
|
|
192
|
+
ctrlKey = e.ctrlKey,
|
|
193
|
+
metaKey = e.metaKey,
|
|
194
|
+
shiftKey = e.shiftKey,
|
|
195
|
+
altKey = e.altKey;
|
|
190
196
|
var keyCode = mapKey(code);
|
|
191
197
|
var pressedKey = pressedKeyUppercase.toLowerCase();
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (shiftKey !== shift && pressedKey !== 'shift') {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
|
|
199
|
-
if (mod) {
|
|
200
|
-
if (!metaKey && !ctrlKey) {
|
|
198
|
+
if (!ignoreModifiers) {
|
|
199
|
+
// We check the pressed keys for compatibility with the keyup event. In keyup events the modifier flags are not set.
|
|
200
|
+
if (alt === !altKey && alt && pressedKey !== 'alt') {
|
|
201
201
|
return false;
|
|
202
202
|
}
|
|
203
|
-
|
|
204
|
-
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
|
|
203
|
+
if (shift === !shiftKey && shift && pressedKey !== 'shift') {
|
|
205
204
|
return false;
|
|
206
205
|
}
|
|
206
|
+
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
|
|
207
|
+
if (mod) {
|
|
208
|
+
if (!metaKey && !ctrlKey) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
if (meta === !metaKey && meta && pressedKey !== 'meta') {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
if (ctrl === !ctrlKey && ctrl && pressedKey !== 'ctrl') {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
207
219
|
}
|
|
208
220
|
// All modifiers are correct, now check the key
|
|
209
221
|
// If the key is set, we check for the key
|
|
@@ -383,7 +395,10 @@ function useHotkeys(keys, callback, options, dependencies) {
|
|
|
383
395
|
parseKeysHookInput(keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
|
|
384
396
|
var _hotkey$keys;
|
|
385
397
|
var hotkey = parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey);
|
|
386
|
-
if (
|
|
398
|
+
if (isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.ignoreModifiers) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) {
|
|
399
|
+
if (isKeyUp && hasTriggeredRef.current) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
387
402
|
maybePreventDefault(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.preventDefault);
|
|
388
403
|
if (!isHotkeyEnabled(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.enabled)) {
|
|
389
404
|
stopPropagation(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-hotkeys-hook.esm.js","sources":["../src/parseHotkeys.ts","../src/isHotkeyPressed.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/deepEqual.ts","../src/HotkeysProvider.tsx","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/useRecordHotkeys.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n '.': 'period',\n ',': 'comma',\n '-': 'slash',\n ' ': 'space',\n '#': 'backslash',\n '+': 'bracketright',\n 'ShiftLeft': 'shift',\n 'ShiftRight': 'shift',\n 'AltLeft': 'alt',\n 'AltRight': 'alt',\n 'MetaLeft': 'meta',\n 'MetaRight': 'meta',\n 'ControlLeft': 'ctrl',\n 'ControlRight': 'ctrl',\n}\n\nexport function mapKey(key: string): string {\n return (mappedKeys[key] || key)\n .trim()\n .toLowerCase()\n .replace('key', '')\n .replace('digit', '')\n .replace('numpad', '')\n .replace('arrow', '')\n}\n\nexport function isHotkeyModifier(key: string) {\n return reservedModifierKeywords.includes(key)\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 => mapKey(k))\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\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 { isHotkeyModifier, mapKey } from './parseHotkeys'\n\nconst currentlyPressedKeys: Set<string> = new Set<string>()\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) => currentlyPressedKeys.has(hotkey.trim().toLowerCase()))\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (currentlyPressedKeys.has('meta')) {\n currentlyPressedKeys.forEach(key => !isHotkeyModifier(key) && currentlyPressedKeys.delete(key.toLowerCase()))\n }\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(hotkey.toLowerCase()))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (key === 'meta') {\n currentlyPressedKeys.clear()\n } else {\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.delete(hotkey.toLowerCase()))\n }\n}\n\n(() => {\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n\n document.addEventListener('keyup', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('blur', () => {\n currentlyPressedKeys.clear()\n })\n }\n})()\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\nimport { isHotkeyPressed } from './isHotkeyPressed'\nimport { mapKey } from './parseHotkeys'\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): boolean => {\n const { alt, meta, mod, shift, keys } = hotkey\n const { key: pressedKeyUppercase, code } = e\n\n const altKey = isHotkeyPressed('alt')\n const shiftKey = isHotkeyPressed('shift')\n const metaKey = isHotkeyPressed('meta')\n const ctrlKey = isHotkeyPressed('ctrl')\n\n const keyCode = mapKey(code)\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 && ctrlKey !== meta && keyCode !== 'meta' && 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 isHotkeyPressed(keys)\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","export default function deepEqual(x: any, y: any): boolean {\n //@ts-ignore\n return (x && y && typeof x === 'object' && typeof y === 'object')\n //@ts-ignore\n ? (Object.keys(x).length === Object.keys(y).length) && Object.keys(x).reduce(function(isEqual, key) {\n return isEqual && deepEqual(x[key], y[key])\n }, true)\n : (x === y)\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useState, useContext, useCallback } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\nimport deepEqual from './deepEqual'\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 enableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n })\n }, [])\n\n const disableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n })\n }, [])\n\n const toggleScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes(scope)) {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n } else {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n }\n })\n }, [])\n\n const addBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => [...prev, hotkey])\n }, [])\n\n const removeBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => prev.filter(h => !deepEqual(h, hotkey)))\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 deepEqual from './deepEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!deepEqual(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 { mapKey, 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'\nimport { pushToCurrentlyPressedKeys, removeFromCurrentlyPressedKeys } from './isHotkeyPressed'\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 hasTriggeredRef = useRef(false)\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, isKeyUp: boolean = false) => {\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 WON'T TRIGGER THE HOTKEY.\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) || hotkey.keys?.includes('*')) && !hasTriggeredRef.current) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n // Execute the user callback for that hotkey\n cb(e, hotkey)\n\n if (!isKeyUp) {\n hasTriggeredRef.current = true\n }\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys(mapKey(event.code))\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 === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys(mapKey(event.code))\n\n hasTriggeredRef.current = false\n\n if (memoisedOptions?.keyup) {\n listener(event, true)\n }\n }\n\n // @ts-ignore\n (ref.current || _options?.document || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 || _options?.document || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 { useCallback, useState } from 'react'\nimport { mapKey } from './parseHotkeys'\n\nexport default function useRecordHotkeys() {\n const [keys, setKeys] = useState(new Set<string>())\n const [isRecording, setIsRecording] = useState(false);\n\n const handler = useCallback((event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n setKeys(prev => {\n const newKeys = new Set(prev)\n\n newKeys.add(mapKey(event.code))\n\n return newKeys\n })\n }, [])\n\n const stop = useCallback(() => {\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handler)\n\n setIsRecording(false)\n }\n }, [handler])\n\n const start = useCallback(() => {\n setKeys(new Set<string>())\n\n if (typeof document !== 'undefined') {\n stop()\n\n document.addEventListener('keydown', handler)\n\n setIsRecording(true)\n }\n }, [handler, stop])\n\n return [keys, { start, stop, isRecording }] as const\n}\n"],"names":["reservedModifierKeywords","mappedKeys","esc","mapKey","key","trim","toLowerCase","replace","isHotkeyModifier","includes","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","modifiers","alt","shift","meta","mod","singleCharKeys","filter","currentlyPressedKeys","Set","isHotkeyPressed","hotkeyArray","Array","isArray","every","has","pushToCurrentlyPressedKeys","forEach","add","removeFromCurrentlyPressedKeys","clear","document","addEventListener","e","undefined","code","window","maybePreventDefault","preventDefault","isHotkeyEnabled","enabled","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Boolean","some","tag","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","pressedKeyUppercase","altKey","shiftKey","metaKey","ctrlKey","keyCode","pressedKey","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","deepEqual","x","y","Object","reduce","isEqual","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","useCallback","prev","from","s","addBoundHotkey","removeBoundHotkey","h","useDeepEqualMemo","value","ref","useRef","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","hasTriggeredRef","_options","_deps","cb","memoisedOptions","proxy","listener","isKeyUp","enableOnFormTags","activeElement","contains","isContentEditable","enableOnContentEditable","handleKeyDown","event","keydown","keyup","handleKeyUp","removeEventListener","useRecordHotkeys","setKeys","isRecording","setIsRecording","handler","newKeys","stop","start"],"mappings":";;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;AAEhE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACf,GAAG,EAAE,QAAQ;EACb,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,WAAW;EAChB,GAAG,EAAE,cAAc;EACnB,WAAW,EAAE,OAAO;EACpB,YAAY,EAAE,OAAO;EACrB,SAAS,EAAE,KAAK;EAChB,UAAU,EAAE,KAAK;EACjB,UAAU,EAAE,MAAM;EAClB,WAAW,EAAE,MAAM;EACnB,aAAa,EAAE,MAAM;EACrB,cAAc,EAAE;CACjB;SAEeC,MAAM,CAACC,GAAW;EAChC,OAAO,CAACH,UAAU,CAACG,GAAG,CAAC,IAAIA,GAAG,EAC3BC,IAAI,EAAE,CACNC,WAAW,EAAE,CACbC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAClBA,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CACpBA,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CACrBA,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;AACzB;SAEgBC,gBAAgB,CAACJ,GAAW;EAC1C,OAAOJ,wBAAwB,CAACS,QAAQ,CAACL,GAAG,CAAC;AAC/C;SAEgBM,kBAAkB,CAACC,IAAU,EAAEC;MA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EAEb,IAAMG,KAAK,GAAG/C,WAAW,CAAC;IACxByC,OAAO,CAAC,IAAIrH,GAAG,EAAU,CAAC;IAE1B,IAAI,OAAOY,QAAQ,KAAK,WAAW,EAAE;MACnC8G,IAAI,EAAE;MAEN9G,QAAQ,CAACC,gBAAgB,CAAC,SAAS,EAAE2G,OAAO,CAAC;MAE7CD,cAAc,CAAC,IAAI,CAAC;;GAEvB,EAAE,CAACC,OAAO,EAAEE,IAAI,CAAC,CAAC;EAEnB,OAAO,CAAC3I,IAAI,EAAE;IAAE4I,KAAK,EAALA,KAAK;IAAED,IAAI,EAAJA,IAAI;IAAEJ,WAAW,EAAXA;GAAa,CAAU;AACtD;;;;"}
|
|
1
|
+
{"version":3,"file":"react-hotkeys-hook.esm.js","sources":["../src/parseHotkeys.ts","../src/isHotkeyPressed.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/deepEqual.ts","../src/HotkeysProvider.tsx","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/useRecordHotkeys.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n '.': 'period',\n ',': 'comma',\n '-': 'slash',\n ' ': 'space',\n '`': 'backquote',\n '#': 'backslash',\n '+': 'bracketright',\n 'ShiftLeft': 'shift',\n 'ShiftRight': 'shift',\n 'AltLeft': 'alt',\n 'AltRight': 'alt',\n 'MetaLeft': 'meta',\n 'MetaRight': 'meta',\n 'ControlLeft': 'ctrl',\n 'ControlRight': 'ctrl',\n}\n\nexport function mapKey(key: string): string {\n return (mappedKeys[key] || key)\n .trim()\n .toLowerCase()\n .replace('key', '')\n .replace('digit', '')\n .replace('numpad', '')\n .replace('arrow', '')\n}\n\nexport function isHotkeyModifier(key: string) {\n return reservedModifierKeywords.includes(key)\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 => mapKey(k))\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl') || keys.includes('control'),\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 { isHotkeyModifier, mapKey } from './parseHotkeys'\n\nconst currentlyPressedKeys: Set<string> = new Set<string>()\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) => currentlyPressedKeys.has(hotkey.trim().toLowerCase()))\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (currentlyPressedKeys.has('meta')) {\n currentlyPressedKeys.forEach(key => !isHotkeyModifier(key) && currentlyPressedKeys.delete(key.toLowerCase()))\n }\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(hotkey.toLowerCase()))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n /*\n 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.\n https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser\n Otherwise the set will hold all ever pressed keys while the meta key is down which leads to wrong results.\n */\n if (key === 'meta') {\n currentlyPressedKeys.clear()\n } else {\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.delete(hotkey.toLowerCase()))\n }\n}\n\n(() => {\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n\n document.addEventListener('keyup', e => {\n if (e.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys([mapKey(e.key), mapKey(e.code)])\n })\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('blur', () => {\n currentlyPressedKeys.clear()\n })\n }\n})()\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\nimport { isHotkeyPressed } from './isHotkeyPressed'\nimport { mapKey } from './parseHotkeys'\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, ignoreModifiers: boolean = false): boolean => {\n const { alt, meta, mod, shift, ctrl, keys } = hotkey\n const { key: pressedKeyUppercase, code, ctrlKey, metaKey, shiftKey, altKey } = e\n\n const keyCode = mapKey(code)\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (!ignoreModifiers) {\n // We check the pressed keys for compatibility with the keyup event. In keyup events the modifier flags are not set.\n if (alt === !altKey && (alt && pressedKey !== 'alt')) {\n return false\n }\n\n if (shift === !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 (meta === !metaKey && (meta && pressedKey !== 'meta')) {\n return false\n }\n\n if (ctrl === !ctrlKey && (ctrl && pressedKey !== 'ctrl')) {\n return false\n }\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 isHotkeyPressed(keys)\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","export default function deepEqual(x: any, y: any): boolean {\n //@ts-ignore\n return (x && y && typeof x === 'object' && typeof y === 'object')\n //@ts-ignore\n ? (Object.keys(x).length === Object.keys(y).length) && Object.keys(x).reduce(function(isEqual, key) {\n return isEqual && deepEqual(x[key], y[key])\n }, true)\n : (x === y)\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useState, useContext, useCallback } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\nimport deepEqual from './deepEqual'\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 enableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n })\n }, [])\n\n const disableScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n })\n }, [])\n\n const toggleScope = useCallback((scope: string) => {\n setInternalActiveScopes((prev) => {\n if (prev.includes(scope)) {\n if (prev.filter(s => s !== scope).length === 0) {\n return ['*']\n } else {\n return prev.filter(s => s !== scope)\n }\n } else {\n if (prev.includes('*')) {\n return [scope]\n }\n\n return Array.from(new Set([...prev, scope]))\n }\n })\n }, [])\n\n const addBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => [...prev, hotkey])\n }, [])\n\n const removeBoundHotkey = useCallback((hotkey: Hotkey) => {\n setBoundHotkeys((prev) => prev.filter(h => !deepEqual(h, hotkey)))\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 deepEqual from './deepEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!deepEqual(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 { mapKey, 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'\nimport { pushToCurrentlyPressedKeys, removeFromCurrentlyPressedKeys } from './isHotkeyPressed'\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 hasTriggeredRef = useRef(false)\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, isKeyUp: boolean = false) => {\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 WON'T TRIGGER THE HOTKEY.\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, memoisedOptions?.ignoreModifiers) || hotkey.keys?.includes('*')) {\n if (isKeyUp && hasTriggeredRef.current) {\n return\n }\n\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n // Execute the user callback for that hotkey\n cb(e, hotkey)\n\n if (!isKeyUp) {\n hasTriggeredRef.current = true\n }\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n pushToCurrentlyPressedKeys(mapKey(event.code))\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 === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n removeFromCurrentlyPressedKeys(mapKey(event.code))\n\n hasTriggeredRef.current = false\n\n if (memoisedOptions?.keyup) {\n listener(event, true)\n }\n }\n\n // @ts-ignore\n (ref.current || _options?.document || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 || _options?.document || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || _options?.document || 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 { useCallback, useState } from 'react'\nimport { mapKey } from './parseHotkeys'\n\nexport default function useRecordHotkeys() {\n const [keys, setKeys] = useState(new Set<string>())\n const [isRecording, setIsRecording] = useState(false);\n\n const handler = useCallback((event: KeyboardEvent) => {\n if (event.key === undefined) {\n // Synthetic event (e.g., Chrome autofill). Ignore.\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n setKeys(prev => {\n const newKeys = new Set(prev)\n\n newKeys.add(mapKey(event.code))\n\n return newKeys\n })\n }, [])\n\n const stop = useCallback(() => {\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handler)\n\n setIsRecording(false)\n }\n }, [handler])\n\n const start = useCallback(() => {\n setKeys(new Set<string>())\n\n if (typeof document !== 'undefined') {\n stop()\n\n document.addEventListener('keydown', handler)\n\n setIsRecording(true)\n }\n }, [handler, stop])\n\n return [keys, { start, stop, isRecording }] as const\n}\n"],"names":["reservedModifierKeywords","mappedKeys","esc","mapKey","key","trim","toLowerCase","replace","isHotkeyModifier","includes","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","modifiers","alt","ctrl","shift","meta","mod","singleCharKeys","filter","currentlyPressedKeys","Set","isHotkeyPressed","hotkeyArray","Array","isArray","every","has","pushToCurrentlyPressedKeys","forEach","add","removeFromCurrentlyPressedKeys","clear","document","addEventListener","e","undefined","code","window","maybePreventDefault","preventDefault","isHotkeyEnabled","enabled","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Boolean","some","tag","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","ignoreModifiers","pressedKeyUppercase","ctrlKey","metaKey","shiftKey","altKey","keyCode","pressedKey","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","deepEqual","x","y","Object","reduce","isEqual","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","useCallback","prev","from","s","addBoundHotkey","removeBoundHotkey","h","useDeepEqualMemo","value","ref","useRef","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","hasTriggeredRef","_options","_deps","cb","memoisedOptions","proxy","listener","isKeyUp","enableOnFormTags","activeElement","contains","isContentEditable","enableOnContentEditable","handleKeyDown","event","keydown","keyup","handleKeyUp","removeEventListener","useRecordHotkeys","setKeys","isRecording","setIsRecording","handler","newKeys","stop","start"],"mappings":";;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;AAExE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACf,GAAG,EAAE,QAAQ;EACb,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,WAAW;EAChB,GAAG,EAAE,WAAW;EAChB,GAAG,EAAE,cAAc;EACnB,WAAW,EAAE,OAAO;EACpB,YAAY,EAAE,OAAO;EACrB,SAAS,EAAE,KAAK;EAChB,UAAU,EAAE,KAAK;EACjB,UAAU,EAAE,MAAM;EAClB,WAAW,EAAE,MAAM;EACnB,aAAa,EAAE,MAAM;EACrB,cAAc,EAAE;CACjB;SAEeC,MAAM,CAACC,GAAW;EAChC,OAAO,CAACH,UAAU,CAACG,GAAG,CAAC,IAAIA,GAAG,EAC3BC,IAAI,EAAE,CACNC,WAAW,EAAE,CACbC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAClBA,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CACpBA,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CACrBA,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;AACzB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AC7F,cAAc,EAAE;IACtB6F,KAAK,CAACvB,eAAe,EAAE;IAEvB6B,OAAO,CAAC,UAAAxC,IAAI;MACV,IAAM4C,OAAO,GAAG,IAAI1H,GAAG,CAAC8E,IAAI,CAAC;MAE7B4C,OAAO,CAACjH,GAAG,CAACnC,MAAM,CAAC0I,KAAK,CAAChG,IAAI,CAAC,CAAC;MAE/B,OAAO0G,OAAO;KACf,CAAC;GACH,EAAE,EAAE,CAAC;EAEN,IAAMC,IAAI,GAAG9C,WAAW,CAAC;IACvB,IAAI,OAAOjE,QAAQ,KAAK,WAAW,EAAE;MACnCA,QAAQ,CAACwG,mBAAmB,CAAC,SAAS,EAAEK,OAAO,CAAC;MAEhDD,cAAc,CAAC,KAAK,CAAC;;GAExB,EAAE,CAACC,OAAO,CAAC,CAAC;EAEb,IAAMG,KAAK,GAAG/C,WAAW,CAAC;IACxByC,OAAO,CAAC,IAAItH,GAAG,EAAU,CAAC;IAE1B,IAAI,OAAOY,QAAQ,KAAK,WAAW,EAAE;MACnC+G,IAAI,EAAE;MAEN/G,QAAQ,CAACC,gBAAgB,CAAC,SAAS,EAAE4G,OAAO,CAAC;MAE7CD,cAAc,CAAC,IAAI,CAAC;;GAEvB,EAAE,CAACC,OAAO,EAAEE,IAAI,CAAC,CAAC;EAEnB,OAAO,CAAC7I,IAAI,EAAE;IAAE8I,KAAK,EAALA,KAAK;IAAED,IAAI,EAAJA,IAAI;IAAEJ,WAAW,EAAXA;GAAa,CAAU;AACtD;;;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare type Scopes = string | string[];
|
|
|
5
5
|
export declare type RefType<T> = T | null;
|
|
6
6
|
export declare type KeyboardModifiers = {
|
|
7
7
|
alt?: boolean;
|
|
8
|
+
ctrl?: boolean;
|
|
8
9
|
meta?: boolean;
|
|
9
10
|
shift?: boolean;
|
|
10
11
|
mod?: boolean;
|
|
@@ -28,5 +29,6 @@ export declare type Options = {
|
|
|
28
29
|
preventDefault?: Trigger;
|
|
29
30
|
description?: string;
|
|
30
31
|
document?: Document;
|
|
32
|
+
ignoreModifiers?: boolean;
|
|
31
33
|
};
|
|
32
34
|
export declare type OptionsOrDependencyArray = Options | DependencyList;
|
package/dist/validators.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export declare function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enable
|
|
|
4
4
|
export declare function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean;
|
|
5
5
|
export declare function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags?: FormTags[] | boolean): boolean;
|
|
6
6
|
export declare function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean;
|
|
7
|
-
export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey) => boolean;
|
|
7
|
+
export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers?: boolean) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hotkeys-hook",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3",
|
|
4
4
|
"repository": "https://JohannesKlauss@github.com/JohannesKlauss/react-keymap-hook.git",
|
|
5
5
|
"homepage": "https://johannesklauss.github.io/react-hotkeys-hook/",
|
|
6
6
|
"author": "Johannes Klauss",
|
|
@@ -43,28 +43,28 @@
|
|
|
43
43
|
"trailingComma": "es5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/core": "7.20.
|
|
46
|
+
"@babel/core": "7.20.12",
|
|
47
47
|
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
48
|
-
"@babel/plugin-transform-react-jsx": "7.20.
|
|
48
|
+
"@babel/plugin-transform-react-jsx": "7.20.13",
|
|
49
49
|
"@babel/preset-env": "7.20.2",
|
|
50
50
|
"@babel/preset-react": "7.18.6",
|
|
51
51
|
"@babel/preset-typescript": "7.18.6",
|
|
52
52
|
"@testing-library/jest-dom": "5.16.5",
|
|
53
|
-
"@testing-library/react": "13.
|
|
53
|
+
"@testing-library/react": "13.4.0",
|
|
54
54
|
"@testing-library/react-hooks": "8.0.1",
|
|
55
55
|
"@testing-library/user-event": "14.4.3",
|
|
56
|
-
"@types/jest": "29.
|
|
57
|
-
"@types/react": "18.0.
|
|
56
|
+
"@types/jest": "29.4.0",
|
|
57
|
+
"@types/react": "18.0.27",
|
|
58
58
|
"@types/react-dom": "18.0.10",
|
|
59
59
|
"eslint-plugin-prettier": "4.2.1",
|
|
60
|
-
"jest": "29.
|
|
61
|
-
"jest-environment-jsdom": "29.
|
|
62
|
-
"prettier": "2.8.
|
|
60
|
+
"jest": "29.4.1",
|
|
61
|
+
"jest-environment-jsdom": "29.4.1",
|
|
62
|
+
"prettier": "2.8.3",
|
|
63
63
|
"react": "18.2.0",
|
|
64
64
|
"react-dom": "18.2.0",
|
|
65
65
|
"react-test-renderer": "18.2.0",
|
|
66
66
|
"tsdx": "0.14.1",
|
|
67
|
-
"tslib": "2.
|
|
67
|
+
"tslib": "2.5.0",
|
|
68
68
|
"typescript": "4.9.4"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
package/src/parseHotkeys.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hotkey, KeyboardModifiers, Keys } from './types'
|
|
2
2
|
|
|
3
|
-
const reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod']
|
|
3
|
+
const reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl']
|
|
4
4
|
|
|
5
5
|
const mappedKeys: Record<string, string> = {
|
|
6
6
|
esc: 'escape',
|
|
@@ -9,6 +9,7 @@ const mappedKeys: Record<string, string> = {
|
|
|
9
9
|
',': 'comma',
|
|
10
10
|
'-': 'slash',
|
|
11
11
|
' ': 'space',
|
|
12
|
+
'`': 'backquote',
|
|
12
13
|
'#': 'backslash',
|
|
13
14
|
'+': 'bracketright',
|
|
14
15
|
'ShiftLeft': 'shift',
|
|
@@ -51,6 +52,7 @@ export function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotke
|
|
|
51
52
|
|
|
52
53
|
const modifiers: KeyboardModifiers = {
|
|
53
54
|
alt: keys.includes('alt'),
|
|
55
|
+
ctrl: keys.includes('ctrl') || keys.includes('control'),
|
|
54
56
|
shift: keys.includes('shift'),
|
|
55
57
|
meta: keys.includes('meta'),
|
|
56
58
|
mod: keys.includes('mod'),
|
package/src/types.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type RefType<T> = T | null
|
|
|
8
8
|
|
|
9
9
|
export type KeyboardModifiers = {
|
|
10
10
|
alt?: boolean
|
|
11
|
+
ctrl?: boolean
|
|
11
12
|
meta?: boolean
|
|
12
13
|
shift?: boolean
|
|
13
14
|
mod?: boolean
|
|
@@ -36,6 +37,7 @@ export type Options = {
|
|
|
36
37
|
preventDefault?: Trigger // Prevent default browser behavior? (Default: false)
|
|
37
38
|
description?: string // Use this option to describe what the hotkey does. (Default: undefined)
|
|
38
39
|
document?: Document // Listen to events on the document instead of the window. (Default: false)
|
|
40
|
+
ignoreModifiers?: boolean // Ignore modifiers when matching hotkeys. (Default: false)
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export type OptionsOrDependencyArray = Options | DependencyList
|
package/src/useHotkeys.ts
CHANGED
|
@@ -65,7 +65,11 @@ export default function useHotkeys<T extends HTMLElement>(
|
|
|
65
65
|
parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {
|
|
66
66
|
const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)
|
|
67
67
|
|
|
68
|
-
if (
|
|
68
|
+
if (isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions?.ignoreModifiers) || hotkey.keys?.includes('*')) {
|
|
69
|
+
if (isKeyUp && hasTriggeredRef.current) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)
|
|
70
74
|
|
|
71
75
|
if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {
|
package/src/validators.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: F
|
|
|
33
33
|
export function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {
|
|
34
34
|
if (activeScopes.length === 0 && scopes) {
|
|
35
35
|
console.warn(
|
|
36
|
-
'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>'
|
|
36
|
+
'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>',
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
return true
|
|
@@ -46,35 +46,37 @@ export function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean
|
|
|
46
46
|
return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey): boolean => {
|
|
50
|
-
const { alt, meta, mod, shift, keys } = hotkey
|
|
51
|
-
const { key: pressedKeyUppercase, code } = e
|
|
52
|
-
|
|
53
|
-
const altKey = isHotkeyPressed('alt')
|
|
54
|
-
const shiftKey = isHotkeyPressed('shift')
|
|
55
|
-
const metaKey = isHotkeyPressed('meta')
|
|
56
|
-
const ctrlKey = isHotkeyPressed('ctrl')
|
|
49
|
+
export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers: boolean = false): boolean => {
|
|
50
|
+
const { alt, meta, mod, shift, ctrl, keys } = hotkey
|
|
51
|
+
const { key: pressedKeyUppercase, code, ctrlKey, metaKey, shiftKey, altKey } = e
|
|
57
52
|
|
|
58
53
|
const keyCode = mapKey(code)
|
|
59
54
|
const pressedKey = pressedKeyUppercase.toLowerCase()
|
|
60
55
|
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (shiftKey !== shift && pressedKey !== 'shift') {
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
|
|
70
|
-
if (mod) {
|
|
71
|
-
if (!metaKey && !ctrlKey) {
|
|
56
|
+
if (!ignoreModifiers) {
|
|
57
|
+
// We check the pressed keys for compatibility with the keyup event. In keyup events the modifier flags are not set.
|
|
58
|
+
if (alt === !altKey && (alt && pressedKey !== 'alt')) {
|
|
72
59
|
return false
|
|
73
60
|
}
|
|
74
|
-
|
|
75
|
-
if (
|
|
61
|
+
|
|
62
|
+
if (shift === !shiftKey && (shift && pressedKey !== 'shift')) {
|
|
76
63
|
return false
|
|
77
64
|
}
|
|
65
|
+
|
|
66
|
+
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
|
|
67
|
+
if (mod) {
|
|
68
|
+
if (!metaKey && !ctrlKey) {
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (meta === !metaKey && (meta && pressedKey !== 'meta')) {
|
|
73
|
+
return false
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (ctrl === !ctrlKey && (ctrl && pressedKey !== 'ctrl')) {
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
// All modifiers are correct, now check the key
|
|
@@ -84,8 +86,7 @@ export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey):
|
|
|
84
86
|
} else if (keys) {
|
|
85
87
|
// Check if all keys are present in pressedDownKeys set
|
|
86
88
|
return isHotkeyPressed(keys)
|
|
87
|
-
}
|
|
88
|
-
else if (!keys) {
|
|
89
|
+
} else if (!keys) {
|
|
89
90
|
// If the key is not set, we only listen for modifiers, that check went alright, so we return true
|
|
90
91
|
return true
|
|
91
92
|
}
|