react-hotkeys-hook 4.0.4-4 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export default function deepEqual(x: any, y: any): boolean;
@@ -1,10 +1,7 @@
1
1
  'use strict';
2
2
 
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
3
  var react = require('react');
6
4
  var jsxRuntime = require('react/jsx-runtime');
7
- var isEqual = _interopDefault(require('lodash.isEqual'));
8
5
 
9
6
  function _extends() {
10
7
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -272,9 +269,18 @@ var HotkeysProvider = function HotkeysProvider(_ref) {
272
269
  });
273
270
  };
274
271
 
272
+ function deepEqual(x, y) {
273
+ //@ts-ignore
274
+ return x && y && typeof x === 'object' && typeof y === 'object'
275
+ //@ts-ignore
276
+ ? Object.keys(x).length === Object.keys(y).length && Object.keys(x).reduce(function (isEqual, key) {
277
+ return isEqual && deepEqual(x[key], y[key]);
278
+ }, true) : x === y;
279
+ }
280
+
275
281
  function useDeepEqualMemo(value) {
276
282
  var ref = react.useRef(undefined);
277
- if (!isEqual(ref.current, value)) {
283
+ if (!deepEqual(ref.current, value)) {
278
284
  ref.current = value;
279
285
  }
280
286
  return ref.current;
@@ -379,7 +385,7 @@ function isHotkeyPressed(key, splitKey) {
379
385
  var parsedHotkey = parseHotkey(hotkey);
380
386
  for (var _iterator = _createForOfIteratorHelperLoose(currentlyPressedKeys), _step; !(_step = _iterator()).done;) {
381
387
  var pressedHotkey = _step.value;
382
- if (isEqual(parsedHotkey, pressedHotkey)) {
388
+ if (deepEqual(parsedHotkey, pressedHotkey)) {
383
389
  return true;
384
390
  }
385
391
  }
@@ -1 +1 @@
1
- {"version":3,"file":"react-hotkeys-hook.cjs.development.js","sources":["../src/parseHotkeys.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/HotkeysProvider.tsx","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/isHotkeyPressed.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n left: 'arrowleft',\n up: 'arrowup',\n right: 'arrowright',\n down: 'arrowdown',\n}\n\nexport function parseKeysHookInput(keys: Keys, splitKey: string = ','): string[] {\n if (typeof keys === 'string') {\n return keys.split(splitKey)\n }\n\n return keys\n}\n\nexport function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotkey {\n const keys = hotkey\n .toLocaleLowerCase()\n .split(combinationKey)\n .map(k => k.trim())\n .map(k => mappedKeys[k] || k)\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n shift: keys.includes('shift'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n }\n\n const singleCharKeys = keys.filter((k) => !reservedModifierKeywords.includes(k))\n\n return {\n ...modifiers,\n keys: singleCharKeys,\n }\n}\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\n\nexport function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void {\n if ((typeof preventDefault === 'function' && preventDefault(e, hotkey)) || preventDefault === true) {\n e.preventDefault()\n }\n}\n\nexport function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean {\n if (typeof enabled === 'function') {\n return enabled(e, hotkey)\n }\n\n return enabled === true || enabled === undefined\n}\n\nexport function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean {\n return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select'])\n}\n\nexport function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: FormTags[] | boolean = false): boolean {\n const targetTagName = target && (target as HTMLElement).tagName\n\n if (enabledOnTags instanceof Array) {\n return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(tag => tag.toLowerCase() === targetTagName.toLowerCase()))\n }\n\n return Boolean(targetTagName && enabledOnTags && enabledOnTags === true)\n}\n\nexport function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {\n if (activeScopes.length === 0 && scopes) {\n console.warn(\n 'A hotkey has the \"scopes\" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'\n )\n\n return true\n }\n\n if (!scopes) {\n return true\n }\n\n return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')\n}\n\nexport const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {\n const { alt, ctrl, meta, mod, shift, keys } = hotkey\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e\n\n const keyCode = code.toLowerCase().replace('key', '')\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (altKey !== alt && pressedKey !== 'alt') {\n return false\n }\n\n if (shiftKey !== shift && pressedKey !== 'shift') {\n return false\n }\n\n // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms\n if (mod) {\n if (!metaKey && !ctrlKey) {\n return false\n }\n } else {\n if (metaKey !== meta && keyCode !== 'meta') {\n return false\n }\n\n if (ctrlKey !== ctrl && keyCode !== 'ctrl') {\n return false\n }\n }\n\n // All modifiers are correct, now check the key\n // If the key is set we check for the key\n if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {\n return true\n } else if (keys) {\n // Check if all keys are present in pressedDownKeys set\n return keys.every(key => pressedDownKeys.has(key))\n }\n else if (!keys) {\n // If the key is not set, we only listen for modifiers, that check went alright, so we return true\n return true\n }\n\n // There is nothing that matches.\n return false\n}\n","import { createContext, ReactNode, useContext } from 'react'\nimport { Hotkey } from './types'\n\ntype BoundHotkeysProxyProviderType = {\n addHotkey: (hotkey: Hotkey) => void,\n removeHotkey: (hotkey: Hotkey) => void,\n}\n\nconst BoundHotkeysProxyProvider = createContext<BoundHotkeysProxyProviderType | undefined>(undefined)\n\nexport const useBoundHotkeysProxy = () => {\n return useContext(BoundHotkeysProxyProvider)\n}\n\ninterface Props {\n children: ReactNode\n addHotkey: (hotkey: Hotkey) => void\n removeHotkey: (hotkey: Hotkey) => void\n}\n\nexport default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props) {\n return <BoundHotkeysProxyProvider.Provider value={{addHotkey, removeHotkey}}>{children}</BoundHotkeysProxyProvider.Provider>\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useMemo, useState, useContext } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\n\nexport type HotkeysContextType = {\n hotkeys: ReadonlyArray<Hotkey>\n enabledScopes: string[]\n toggleScope: (scope: string) => void\n enableScope: (scope: string) => void\n disableScope: (scope: string) => void\n}\n\n// The context is only needed for special features like global scoping, so we use a graceful default fallback\nconst HotkeysContext = createContext<HotkeysContextType>({\n hotkeys: [],\n enabledScopes: [], // This array has to be empty instead of containing '*' as default, to check if the provider is set or not\n toggleScope: () => {},\n enableScope: () => {},\n disableScope: () => {},\n})\n\nexport const useHotkeysContext = () => {\n return useContext(HotkeysContext)\n}\n\ninterface Props {\n initiallyActiveScopes?: string[]\n children: ReactNode\n}\n\nexport const HotkeysProvider = ({initiallyActiveScopes = ['*'], children}: Props) => {\n const [internalActiveScopes, setInternalActiveScopes] = useState(initiallyActiveScopes?.length > 0 ? initiallyActiveScopes : ['*'])\n const [boundHotkeys, setBoundHotkeys] = useState<Hotkey[]>([]);\n\n const isAllActive = useMemo(() => internalActiveScopes.includes('*'), [internalActiveScopes])\n\n const enableScope = (scope: string) => {\n if (isAllActive) {\n setInternalActiveScopes([scope])\n } else {\n setInternalActiveScopes(Array.from(new Set([...internalActiveScopes, scope])))\n }\n }\n\n const disableScope = (scope: string) => {\n const scopes = internalActiveScopes.filter(s => s !== scope)\n\n if (scopes.length === 0) {\n setInternalActiveScopes(['*'])\n } else {\n setInternalActiveScopes(scopes)\n }\n }\n\n const toggleScope = (scope: string) => {\n if (internalActiveScopes.includes(scope)) {\n disableScope(scope)\n } else {\n enableScope(scope)\n }\n }\n\n const addBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys([...boundHotkeys, hotkey])\n }\n\n const removeBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys(boundHotkeys.filter(h => h.keys !== hotkey.keys))\n }\n\n return (\n <HotkeysContext.Provider value={{enabledScopes: internalActiveScopes, hotkeys: boundHotkeys, enableScope, disableScope, toggleScope}}>\n <BoundHotkeysProxyProviderProvider addHotkey={addBoundHotkey} removeHotkey={removeBoundHotkey}>\n {children}\n </BoundHotkeysProxyProviderProvider>\n </HotkeysContext.Provider>\n )\n}\n","import { useRef } from 'react'\nimport isEqual from 'lodash.isEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!isEqual(ref.current, value)) {\n ref.current = value\n }\n\n return ref.current\n}\n","import { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'\nimport { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { parseHotkey, parseKeysHookInput } from './parseHotkeys'\nimport {\n isHotkeyEnabled,\n isHotkeyEnabledOnTag,\n isHotkeyMatchingKeyboardEvent,\n isKeyboardEventTriggeredByInput,\n isScopeActive,\n maybePreventDefault,\n} from './validators'\nimport { useHotkeysContext } from './HotkeysProvider'\nimport { useBoundHotkeysProxy } from './BoundHotkeysProxyProvider'\nimport useDeepEqualMemo from './useDeepEqualMemo'\n\nconst stopPropagation = (e: KeyboardEvent): void => {\n e.stopPropagation()\n e.preventDefault()\n e.stopImmediatePropagation()\n}\n\nconst useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nexport default function useHotkeys<T extends HTMLElement>(\n keys: Keys,\n callback: HotkeyCallback,\n options?: OptionsOrDependencyArray,\n dependencies?: OptionsOrDependencyArray,\n) {\n const ref = useRef<RefType<T>>(null)\n const { current: pressedDownKeys } = useRef<Set<string>>(new Set())\n\n const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined\n const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []\n\n const cb = useCallback(callback, [..._deps])\n const memoisedOptions = useDeepEqualMemo(_options)\n\n const { enabledScopes } = useHotkeysContext()\n const proxy = useBoundHotkeysProxy()\n\n useSafeLayoutEffect(() => {\n if (memoisedOptions?.enabled === false || !isScopeActive(enabledScopes, memoisedOptions?.scopes)) {\n return\n }\n\n const listener = (e: KeyboardEvent) => {\n if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions?.enableOnFormTags)) {\n return\n }\n\n // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE\n // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.\n\n if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {\n stopPropagation(e)\n\n return\n }\n\n if (((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable)) {\n return\n }\n\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {\n const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)\n\n if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || hotkey.keys?.includes('*')) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n cb(e, hotkey)\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n pressedDownKeys.add(event.key.toLowerCase())\n\n if ((memoisedOptions?.keydown === undefined && memoisedOptions?.keyup !== true) || memoisedOptions?.keydown) {\n listener(event)\n }\n }\n\n const handleKeyUp = (event: KeyboardEvent) => {\n if (event.key.toLowerCase() !== 'meta') {\n pressedDownKeys.delete(event.key.toLowerCase())\n } else {\n // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.\n pressedDownKeys.clear()\n }\n\n if (memoisedOptions?.keyup) {\n listener(event)\n }\n }\n\n // @ts-ignore\n (ref.current || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).addEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n\n return () => {\n // @ts-ignore\n (ref.current || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).removeEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n }\n }, [keys, cb, memoisedOptions, enabledScopes])\n\n return ref\n}\n","import { Hotkey } from './types'\nimport { parseHotkey } from './parseHotkeys'\nimport isEqual from 'lodash.isEqual'\n\nconst currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()\n\nexport function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean {\n const hotkeyArray = Array.isArray(key) ? key : key.split(splitKey)\n\n return hotkeyArray.every((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (isEqual(parsedHotkey, pressedHotkey)) {\n return true\n }\n }\n })\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(parseHotkey(hotkey)))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (pressedHotkey.keys?.every((key) => parsedHotkey.keys?.includes(key))) {\n currentlyPressedKeys.delete(pressedHotkey)\n }\n }\n })\n}\n\n(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n document.addEventListener('keydown', e => {\n pushToCurrentlyPressedKeys(e.key)\n })\n\n document.addEventListener('keyup', e => {\n removeFromCurrentlyPressedKeys(e.key)\n })\n })\n }\n})()\n"],"names":["reservedModifierKeywords","mappedKeys","esc","left","up","right","down","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","trim","modifiers","alt","includes","ctrl","shift","meta","mod","singleCharKeys","filter","maybePreventDefault","e","preventDefault","isHotkeyEnabled","enabled","undefined","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Array","Boolean","some","tag","toLowerCase","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","pressedDownKeys","altKey","ctrlKey","metaKey","shiftKey","pressedKeyUppercase","key","code","keyCode","replace","pressedKey","every","has","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","isAllActive","useMemo","from","Set","s","addBoundHotkey","removeBoundHotkey","h","useDeepEqualMemo","value","ref","useRef","isEqual","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","window","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","_options","_deps","cb","useCallback","memoisedOptions","proxy","listener","enableOnFormTags","document","activeElement","contains","isContentEditable","enableOnContentEditable","forEach","handleKeyDown","event","add","keydown","keyup","handleKeyUp","clear","addEventListener","removeEventListener","currentlyPressedKeys","isHotkeyPressed","hotkeyArray","isArray","parsedHotkey","pressedHotkey","pushToCurrentlyPressedKeys","removeFromCurrentlyPressedKeys"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;AAExE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACfC,IAAI,EAAE,WAAW;EACjBC,EAAE,EAAE,SAAS;EACbC,KAAK,EAAE,YAAY;EACnBC,IAAI,EAAE;CACP;SAEeC,kBAAkB,CAACC,IAAU,EAAEC;MAAAA;IAAAA,WAAmB,GAAG;;EACnE,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI,CAACE,KAAK,CAACD,QAAQ,CAAC;;EAG7B,OAAOD,IAAI;AACb;SAEgBG,WAAW,CAACC,MAAc,EAAEC;MAAAA;IAAAA,iBAAyB,GAAG;;EACtE,IAAML,IAAI,GAAGI,MAAM,CAChBE,iBAAiB,EAAE,CACnBJ,KAAK,CAACG,cAAc,CAAC,CACrBE,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIA,CAAC,CAACC,IAAI,EAAE;IAAC,CAClBF,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIf,UAAU,CAACe,CAAC,CAAC,IAAIA,CAAC;IAAC;EAE/B,IAAME,SAAS,GAAsB;IACnCC,GAAG,EAAEX,IAAI,CAACY,QAAQ,CAAC,KAAK,CAAC;IACzBC,IAAI,EAAEb,IAAI,CAACY,QAAQ,CAAC,MAAM,CAAC;IAC3BE,KAAK,EAAEd,IAAI,CAACY,QAAQ,CAAC,OAAO,CAAC;IAC7B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AK,CAACmG,OAAO,CAAChF,GAAG,CAAC,GAAGA,GAAG,GAAG,CAACA,GAAG,CAAC;EAEpD+E,WAAW,CAACZ,OAAO,CAAC,UAAClH,MAAM;IACzB,IAAMgI,YAAY,GAAGjI,WAAW,CAACC,MAAM,CAAC;IAExC,sDAA4B4H,oBAAoB,2CAAE;MAAA;MAAA,IAAvCK,aAAa;MACtB,2BAAIA,aAAa,CAACrI,IAAI,aAAlB,oBAAoBwD,KAAK,CAAC,UAACL,GAAG;QAAA;QAAA,6BAAKiF,YAAY,CAACpI,IAAI,qBAAjB,mBAAmBY,QAAQ,CAACuC,GAAG,CAAC;QAAC,EAAE;QACxE6E,oBAAoB,UAAO,CAACK,aAAa,CAAC;;;GAG/C,CAAC;AACJ;AAEA,CAAC;EACC,IAAI,OAAOnC,MAAM,KAAK,WAAW,EAAE;IACjCA,MAAM,CAAC4B,gBAAgB,CAAC,kBAAkB,EAAE;MAC1Cb,QAAQ,CAACa,gBAAgB,CAAC,SAAS,EAAE,UAAA1G,CAAC;QACpCkH,0BAA0B,CAAClH,CAAC,CAAC+B,GAAG,CAAC;OAClC,CAAC;MAEF8D,QAAQ,CAACa,gBAAgB,CAAC,OAAO,EAAE,UAAA1G,CAAC;QAClCmH,8BAA8B,CAACnH,CAAC,CAAC+B,GAAG,CAAC;OACtC,CAAC;KACH,CAAC;;AAEN,CAAC,GAAG;;;;;;;"}
1
+ {"version":3,"file":"react-hotkeys-hook.cjs.development.js","sources":["../src/parseHotkeys.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/HotkeysProvider.tsx","../src/deepEqual.ts","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/isHotkeyPressed.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n left: 'arrowleft',\n up: 'arrowup',\n right: 'arrowright',\n down: 'arrowdown',\n}\n\nexport function parseKeysHookInput(keys: Keys, splitKey: string = ','): string[] {\n if (typeof keys === 'string') {\n return keys.split(splitKey)\n }\n\n return keys\n}\n\nexport function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotkey {\n const keys = hotkey\n .toLocaleLowerCase()\n .split(combinationKey)\n .map(k => k.trim())\n .map(k => mappedKeys[k] || k)\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n shift: keys.includes('shift'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n }\n\n const singleCharKeys = keys.filter((k) => !reservedModifierKeywords.includes(k))\n\n return {\n ...modifiers,\n keys: singleCharKeys,\n }\n}\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\n\nexport function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void {\n if ((typeof preventDefault === 'function' && preventDefault(e, hotkey)) || preventDefault === true) {\n e.preventDefault()\n }\n}\n\nexport function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean {\n if (typeof enabled === 'function') {\n return enabled(e, hotkey)\n }\n\n return enabled === true || enabled === undefined\n}\n\nexport function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean {\n return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select'])\n}\n\nexport function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: FormTags[] | boolean = false): boolean {\n const targetTagName = target && (target as HTMLElement).tagName\n\n if (enabledOnTags instanceof Array) {\n return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(tag => tag.toLowerCase() === targetTagName.toLowerCase()))\n }\n\n return Boolean(targetTagName && enabledOnTags && enabledOnTags === true)\n}\n\nexport function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {\n if (activeScopes.length === 0 && scopes) {\n console.warn(\n 'A hotkey has the \"scopes\" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'\n )\n\n return true\n }\n\n if (!scopes) {\n return true\n }\n\n return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')\n}\n\nexport const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {\n const { alt, ctrl, meta, mod, shift, keys } = hotkey\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e\n\n const keyCode = code.toLowerCase().replace('key', '')\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (altKey !== alt && pressedKey !== 'alt') {\n return false\n }\n\n if (shiftKey !== shift && pressedKey !== 'shift') {\n return false\n }\n\n // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms\n if (mod) {\n if (!metaKey && !ctrlKey) {\n return false\n }\n } else {\n if (metaKey !== meta && keyCode !== 'meta') {\n return false\n }\n\n if (ctrlKey !== ctrl && keyCode !== 'ctrl') {\n return false\n }\n }\n\n // All modifiers are correct, now check the key\n // If the key is set we check for the key\n if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {\n return true\n } else if (keys) {\n // Check if all keys are present in pressedDownKeys set\n return keys.every(key => pressedDownKeys.has(key))\n }\n else if (!keys) {\n // If the key is not set, we only listen for modifiers, that check went alright, so we return true\n return true\n }\n\n // There is nothing that matches.\n return false\n}\n","import { createContext, ReactNode, useContext } from 'react'\nimport { Hotkey } from './types'\n\ntype BoundHotkeysProxyProviderType = {\n addHotkey: (hotkey: Hotkey) => void,\n removeHotkey: (hotkey: Hotkey) => void,\n}\n\nconst BoundHotkeysProxyProvider = createContext<BoundHotkeysProxyProviderType | undefined>(undefined)\n\nexport const useBoundHotkeysProxy = () => {\n return useContext(BoundHotkeysProxyProvider)\n}\n\ninterface Props {\n children: ReactNode\n addHotkey: (hotkey: Hotkey) => void\n removeHotkey: (hotkey: Hotkey) => void\n}\n\nexport default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props) {\n return <BoundHotkeysProxyProvider.Provider value={{addHotkey, removeHotkey}}>{children}</BoundHotkeysProxyProvider.Provider>\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useMemo, useState, useContext } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\n\nexport type HotkeysContextType = {\n hotkeys: ReadonlyArray<Hotkey>\n enabledScopes: string[]\n toggleScope: (scope: string) => void\n enableScope: (scope: string) => void\n disableScope: (scope: string) => void\n}\n\n// The context is only needed for special features like global scoping, so we use a graceful default fallback\nconst HotkeysContext = createContext<HotkeysContextType>({\n hotkeys: [],\n enabledScopes: [], // This array has to be empty instead of containing '*' as default, to check if the provider is set or not\n toggleScope: () => {},\n enableScope: () => {},\n disableScope: () => {},\n})\n\nexport const useHotkeysContext = () => {\n return useContext(HotkeysContext)\n}\n\ninterface Props {\n initiallyActiveScopes?: string[]\n children: ReactNode\n}\n\nexport const HotkeysProvider = ({initiallyActiveScopes = ['*'], children}: Props) => {\n const [internalActiveScopes, setInternalActiveScopes] = useState(initiallyActiveScopes?.length > 0 ? initiallyActiveScopes : ['*'])\n const [boundHotkeys, setBoundHotkeys] = useState<Hotkey[]>([]);\n\n const isAllActive = useMemo(() => internalActiveScopes.includes('*'), [internalActiveScopes])\n\n const enableScope = (scope: string) => {\n if (isAllActive) {\n setInternalActiveScopes([scope])\n } else {\n setInternalActiveScopes(Array.from(new Set([...internalActiveScopes, scope])))\n }\n }\n\n const disableScope = (scope: string) => {\n const scopes = internalActiveScopes.filter(s => s !== scope)\n\n if (scopes.length === 0) {\n setInternalActiveScopes(['*'])\n } else {\n setInternalActiveScopes(scopes)\n }\n }\n\n const toggleScope = (scope: string) => {\n if (internalActiveScopes.includes(scope)) {\n disableScope(scope)\n } else {\n enableScope(scope)\n }\n }\n\n const addBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys([...boundHotkeys, hotkey])\n }\n\n const removeBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys(boundHotkeys.filter(h => h.keys !== hotkey.keys))\n }\n\n return (\n <HotkeysContext.Provider value={{enabledScopes: internalActiveScopes, hotkeys: boundHotkeys, enableScope, disableScope, toggleScope}}>\n <BoundHotkeysProxyProviderProvider addHotkey={addBoundHotkey} removeHotkey={removeBoundHotkey}>\n {children}\n </BoundHotkeysProxyProviderProvider>\n </HotkeysContext.Provider>\n )\n}\n","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 { 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 { parseHotkey, parseKeysHookInput } from './parseHotkeys'\nimport {\n isHotkeyEnabled,\n isHotkeyEnabledOnTag,\n isHotkeyMatchingKeyboardEvent,\n isKeyboardEventTriggeredByInput,\n isScopeActive,\n maybePreventDefault,\n} from './validators'\nimport { useHotkeysContext } from './HotkeysProvider'\nimport { useBoundHotkeysProxy } from './BoundHotkeysProxyProvider'\nimport useDeepEqualMemo from './useDeepEqualMemo'\n\nconst stopPropagation = (e: KeyboardEvent): void => {\n e.stopPropagation()\n e.preventDefault()\n e.stopImmediatePropagation()\n}\n\nconst useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nexport default function useHotkeys<T extends HTMLElement>(\n keys: Keys,\n callback: HotkeyCallback,\n options?: OptionsOrDependencyArray,\n dependencies?: OptionsOrDependencyArray,\n) {\n const ref = useRef<RefType<T>>(null)\n const { current: pressedDownKeys } = useRef<Set<string>>(new Set())\n\n const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined\n const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []\n\n const cb = useCallback(callback, [..._deps])\n const memoisedOptions = useDeepEqualMemo(_options)\n\n const { enabledScopes } = useHotkeysContext()\n const proxy = useBoundHotkeysProxy()\n\n useSafeLayoutEffect(() => {\n if (memoisedOptions?.enabled === false || !isScopeActive(enabledScopes, memoisedOptions?.scopes)) {\n return\n }\n\n const listener = (e: KeyboardEvent) => {\n if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions?.enableOnFormTags)) {\n return\n }\n\n // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE\n // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.\n\n if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {\n stopPropagation(e)\n\n return\n }\n\n if (((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable)) {\n return\n }\n\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {\n const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)\n\n if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || hotkey.keys?.includes('*')) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n cb(e, hotkey)\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n pressedDownKeys.add(event.key.toLowerCase())\n\n if ((memoisedOptions?.keydown === undefined && memoisedOptions?.keyup !== true) || memoisedOptions?.keydown) {\n listener(event)\n }\n }\n\n const handleKeyUp = (event: KeyboardEvent) => {\n if (event.key.toLowerCase() !== 'meta') {\n pressedDownKeys.delete(event.key.toLowerCase())\n } else {\n // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.\n pressedDownKeys.clear()\n }\n\n if (memoisedOptions?.keyup) {\n listener(event)\n }\n }\n\n // @ts-ignore\n (ref.current || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).addEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n\n return () => {\n // @ts-ignore\n (ref.current || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).removeEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n }\n }, [keys, cb, memoisedOptions, enabledScopes])\n\n return ref\n}\n","import { Hotkey } from './types'\nimport { parseHotkey } from './parseHotkeys'\nimport deepEqual from './deepEqual'\n\nconst currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()\n\nexport function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean {\n const hotkeyArray = Array.isArray(key) ? key : key.split(splitKey)\n\n return hotkeyArray.every((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (deepEqual(parsedHotkey, pressedHotkey)) {\n return true\n }\n }\n })\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(parseHotkey(hotkey)))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (pressedHotkey.keys?.every((key) => parsedHotkey.keys?.includes(key))) {\n currentlyPressedKeys.delete(pressedHotkey)\n }\n }\n })\n}\n\n(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n document.addEventListener('keydown', e => {\n pushToCurrentlyPressedKeys(e.key)\n })\n\n document.addEventListener('keyup', e => {\n removeFromCurrentlyPressedKeys(e.key)\n })\n })\n }\n})()\n"],"names":["reservedModifierKeywords","mappedKeys","esc","left","up","right","down","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","trim","modifiers","alt","includes","ctrl","shift","meta","mod","singleCharKeys","filter","maybePreventDefault","e","preventDefault","isHotkeyEnabled","enabled","undefined","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Array","Boolean","some","tag","toLowerCase","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","pressedDownKeys","altKey","ctrlKey","metaKey","shiftKey","pressedKeyUppercase","key","code","keyCode","replace","pressedKey","every","has","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","isAllActive","useMemo","from","Set","s","addBoundHotkey","removeBoundHotkey","h","deepEqual","x","y","Object","reduce","isEqual","useDeepEqualMemo","value","ref","useRef","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","window","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","_options","_deps","cb","useCallback","memoisedOptions","proxy","listener","enableOnFormTags","document","activeElement","contains","isContentEditable","enableOnContentEditable","forEach","handleKeyDown","event","add","keydown","keyup","handleKeyUp","clear","addEventListener","removeEventListener","currentlyPressedKeys","isHotkeyPressed","hotkeyArray","isArray","parsedHotkey","pressedHotkey","pushToCurrentlyPressedKeys","removeFromCurrentlyPressedKeys"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;AAExE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACfC,IAAI,EAAE,WAAW;EACjBC,EAAE,EAAE,SAAS;EACbC,KAAK,EAAE,YAAY;EACnBC,IAAI,EAAE;CACP;SAEeC,kBAAkB,CAACC,IAAU,EAAEC;MAAAA;IAAAA,WAAmB,GAAG;;EACnE,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI,CAACE,KAAK,CAACD,QAAQ,CAAC;;EAG7B,OAAOD,IAAI;AACb;SAEgBG,WAAW,CAACC,MAAc,EAAEC;MAAAA;IAAAA,iBAAyB,GAAG;;EACtE,IAAML,IAAI,GAAGI,MAAM,CAChBE,iBAAiB,EAAE,CACnBJ,KAAK,CAACG,cAAc,CAAC,CACrBE,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIA,CAAC,CAACC,IAAI,EAAE;IAAC,CAClBF,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIf,UAAU,CAACe,CAAC,CAAC,IAAIA,CAAC;IAAC;EAE/B,IAAME,SAAS,GAAsB;IACnCC,GAAG,EAAEX,IAAI,CAACY,QAAQ,CAAC,KAAK,CAAC;IACzBC,IAAI,EAAEb,IAAI,CAACY,QAAQ,CAAC,MAAM,CAAC;IAC3BE,KAAK,EAAEd,IAAI,CAACY,QAAQ,CAAC,OAAO,CAAC;IAC7BG,IAAI,EAAEf,IAAI,CAACY,QAAQ,CA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UAAA/G,CAAC;QAClCwH,8BAA8B,CAACxH,CAAC,CAAC+B,GAAG,CAAC;OACtC,CAAC;KACH,CAAC;;AAEN,CAAC,GAAG;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";var e,n=require("react"),t=require("react/jsx-runtime"),r=(e=require("lodash.isEqual"))&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function i(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function u(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return i(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=["ctrl","shift","alt","meta","mod"],c={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown"};function l(e,n){return void 0===n&&(n=","),"string"==typeof e?e.split(n):e}function s(e,n){void 0===n&&(n="+");var t=e.toLocaleLowerCase().split(n).map((function(e){return e.trim()})).map((function(e){return c[e]||e}));return o({},{alt:t.includes("alt"),ctrl:t.includes("ctrl"),shift:t.includes("shift"),meta:t.includes("meta"),mod:t.includes("mod")},{keys:t.filter((function(e){return!a.includes(e)}))})}function d(e,n){var t=e.target;void 0===n&&(n=!1);var r=t&&t.tagName;return n instanceof Array?Boolean(r&&n&&n.some((function(e){return e.toLowerCase()===r.toLowerCase()}))):Boolean(r&&n&&!0===n)}var f=n.createContext(void 0);function y(e){return t.jsx(f.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}var v=n.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),p=function(){return n.useContext(v)},m=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},h="undefined"!=typeof window?n.useLayoutEffect:n.useEffect,k=new Set;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(function(){document.addEventListener("keydown",(function(e){var n;n=e.key,(Array.isArray(n)?n:[n]).forEach((function(e){return k.add(s(e))}))})),document.addEventListener("keyup",(function(e){var n;n=e.key,(Array.isArray(n)?n:[n]).forEach((function(e){for(var n,t=s(e),r=u(k);!(n=r()).done;){var o,i=n.value;null!=(o=i.keys)&&o.every((function(e){var n;return null==(n=t.keys)?void 0:n.includes(e)}))&&k.delete(i)}}))}))})),exports.HotkeysProvider=function(e){var r=e.initiallyActiveScopes,o=void 0===r?["*"]:r,i=e.children,u=n.useState((null==o?void 0:o.length)>0?o:["*"]),a=u[0],c=u[1],l=n.useState([]),s=l[0],d=l[1],f=n.useMemo((function(){return a.includes("*")}),[a]),p=function(e){c(f?[e]:Array.from(new Set([].concat(a,[e]))))},m=function(e){var n=a.filter((function(n){return n!==e}));c(0===n.length?["*"]:n)};return t.jsx(v.Provider,{value:{enabledScopes:a,hotkeys:s,enableScope:p,disableScope:m,toggleScope:function(e){a.includes(e)?m(e):p(e)}},children:t.jsx(y,{addHotkey:function(e){d([].concat(s,[e]))},removeHotkey:function(e){d(s.filter((function(n){return n.keys!==e.keys})))},children:i})})},exports.isHotkeyPressed=function(e,n){return void 0===n&&(n=","),(Array.isArray(e)?e:e.split(n)).every((function(e){for(var n,t=s(e),o=u(k);!(n=o()).done;)if(r(t,n.value))return!0}))},exports.useHotkeys=function(e,t,o,i){var u=n.useRef(null),a=n.useRef(new Set).current,c=o instanceof Array?i instanceof Array?void 0:i:o,y=n.useCallback(t,[].concat(o instanceof Array?o:i instanceof Array?i:[])),v=function(e){var t=n.useRef(void 0);return r(t.current,e)||(t.current=e),t.current}(c),k=p().enabledScopes,w=n.useContext(f);return h((function(){if(!1!==(null==v?void 0:v.enabled)&&(t=null==v?void 0:v.scopes,0===(n=k).length&&t?(console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'),1):!t||n.some((function(e){return t.includes(e)}))||n.includes("*"))){var n,t,r=function(n){var t;d(n,["input","textarea","select"])&&!d(n,null==v?void 0:v.enableOnFormTags)||(null===u.current||document.activeElement===u.current||u.current.contains(document.activeElement)?(null==(t=n.target)||!t.isContentEditable||null!=v&&v.enableOnContentEditable)&&l(e,null==v?void 0:v.splitKey).forEach((function(e){var t,r=s(e,null==v?void 0:v.combinationKey);if(function(e,n,t){var r=n.alt,o=n.ctrl,i=n.meta,u=n.mod,a=n.shift,c=n.keys,l=e.altKey,s=e.ctrlKey,d=e.metaKey,f=e.shiftKey,y=e.key,v=e.code.toLowerCase().replace("key",""),p=y.toLowerCase();if(l!==r&&"alt"!==p)return!1;if(f!==a&&"shift"!==p)return!1;if(u){if(!d&&!s)return!1}else{if(d!==i&&"meta"!==v)return!1;if(s!==o&&"ctrl"!==v)return!1}return!(!c||1!==c.length||!c.includes(p)&&!c.includes(v))||(c?c.every((function(e){return t.has(e)})):!c)}(n,r,a)||null!=(t=r.keys)&&t.includes("*")){if(function(e,n,t){("function"==typeof t&&t(e,n)||!0===t)&&e.preventDefault()}(n,r,null==v?void 0:v.preventDefault),!function(e,n,t){return"function"==typeof t?t(e,n):!0===t||void 0===t}(n,r,null==v?void 0:v.enabled))return void m(n);y(n,r)}})):m(n))},o=function(e){a.add(e.key.toLowerCase()),(void 0===(null==v?void 0:v.keydown)&&!0!==(null==v?void 0:v.keyup)||null!=v&&v.keydown)&&r(e)},i=function(e){"meta"!==e.key.toLowerCase()?a.delete(e.key.toLowerCase()):a.clear(),null!=v&&v.keyup&&r(e)};return(u.current||document).addEventListener("keyup",i),(u.current||document).addEventListener("keydown",o),w&&l(e,null==v?void 0:v.splitKey).forEach((function(e){return w.addHotkey(s(e,null==v?void 0:v.combinationKey))})),function(){(u.current||document).removeEventListener("keyup",i),(u.current||document).removeEventListener("keydown",o),w&&l(e,null==v?void 0:v.splitKey).forEach((function(e){return w.removeHotkey(s(e,null==v?void 0:v.combinationKey))}))}}}),[e,y,v,k]),u},exports.useHotkeysContext=p;
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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=["ctrl","shift","alt","meta","mod"],u={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown"};function a(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 e.trim()})).map((function(e){return u[e]||e}));return n({},{alt:r.includes("alt"),ctrl:r.includes("ctrl"),shift:r.includes("shift"),meta:r.includes("meta"),mod:r.includes("mod")},{keys:r.filter((function(e){return!i.includes(e)}))})}function l(e,t){var n=e.target;void 0===t&&(t=!1);var r=n&&n.tagName;return t instanceof Array?Boolean(r&&t&&t.some((function(e){return e.toLowerCase()===r.toLowerCase()}))):Boolean(r&&t&&!0===t)}var s=e.createContext(void 0);function d(e){return t.jsx(s.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}var f=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),y=function(){return e.useContext(f)};function v(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,r){return n&&v(e[r],t[r])}),!0):e===t}var p=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},m="undefined"!=typeof window?e.useLayoutEffect:e.useEffect,k=new Set;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(function(){document.addEventListener("keydown",(function(e){var t;t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){return k.add(c(e))}))})),document.addEventListener("keyup",(function(e){var t;t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){for(var t,n=c(e),r=o(k);!(t=r()).done;){var i,u=t.value;null!=(i=u.keys)&&i.every((function(e){var t;return null==(t=n.keys)?void 0:t.includes(e)}))&&k.delete(u)}}))}))})),exports.HotkeysProvider=function(n){var r=n.initiallyActiveScopes,o=void 0===r?["*"]:r,i=n.children,u=e.useState((null==o?void 0:o.length)>0?o:["*"]),a=u[0],c=u[1],l=e.useState([]),s=l[0],y=l[1],v=e.useMemo((function(){return a.includes("*")}),[a]),p=function(e){c(v?[e]:Array.from(new Set([].concat(a,[e]))))},m=function(e){var t=a.filter((function(t){return t!==e}));c(0===t.length?["*"]:t)};return t.jsx(f.Provider,{value:{enabledScopes:a,hotkeys:s,enableScope:p,disableScope:m,toggleScope:function(e){a.includes(e)?m(e):p(e)}},children:t.jsx(d,{addHotkey:function(e){y([].concat(s,[e]))},removeHotkey:function(e){y(s.filter((function(t){return t.keys!==e.keys})))},children:i})})},exports.isHotkeyPressed=function(e,t){return void 0===t&&(t=","),(Array.isArray(e)?e:e.split(t)).every((function(e){for(var t,n=c(e),r=o(k);!(t=r()).done;)if(v(n,t.value))return!0}))},exports.useHotkeys=function(t,n,r,o){var i=e.useRef(null),u=e.useRef(new Set).current,d=r instanceof Array?o instanceof Array?void 0:o:r,f=e.useCallback(n,[].concat(r instanceof Array?r:o instanceof Array?o:[])),k=function(t){var n=e.useRef(void 0);return v(n.current,t)||(n.current=t),n.current}(d),h=y().enabledScopes,b=e.useContext(s);return m((function(){if(!1!==(null==k?void 0:k.enabled)&&(n=null==k?void 0:k.scopes,0===(e=h).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,r=function(e){var n;l(e,["input","textarea","select"])&&!l(e,null==k?void 0:k.enableOnFormTags)||(null===i.current||document.activeElement===i.current||i.current.contains(document.activeElement)?(null==(n=e.target)||!n.isContentEditable||null!=k&&k.enableOnContentEditable)&&a(t,null==k?void 0:k.splitKey).forEach((function(t){var n,r=c(t,null==k?void 0:k.combinationKey);if(function(e,t,n){var r=t.alt,o=t.ctrl,i=t.meta,u=t.mod,a=t.shift,c=t.keys,l=e.altKey,s=e.ctrlKey,d=e.metaKey,f=e.shiftKey,y=e.key,v=e.code.toLowerCase().replace("key",""),p=y.toLowerCase();if(l!==r&&"alt"!==p)return!1;if(f!==a&&"shift"!==p)return!1;if(u){if(!d&&!s)return!1}else{if(d!==i&&"meta"!==v)return!1;if(s!==o&&"ctrl"!==v)return!1}return!(!c||1!==c.length||!c.includes(p)&&!c.includes(v))||(c?c.every((function(e){return n.has(e)})):!c)}(e,r,u)||null!=(n=r.keys)&&n.includes("*")){if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==k?void 0:k.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==k?void 0:k.enabled))return void p(e);f(e,r)}})):p(e))},o=function(e){u.add(e.key.toLowerCase()),(void 0===(null==k?void 0:k.keydown)&&!0!==(null==k?void 0:k.keyup)||null!=k&&k.keydown)&&r(e)},s=function(e){"meta"!==e.key.toLowerCase()?u.delete(e.key.toLowerCase()):u.clear(),null!=k&&k.keyup&&r(e)};return(i.current||document).addEventListener("keyup",s),(i.current||document).addEventListener("keydown",o),b&&a(t,null==k?void 0:k.splitKey).forEach((function(e){return b.addHotkey(c(e,null==k?void 0:k.combinationKey))})),function(){(i.current||document).removeEventListener("keyup",s),(i.current||document).removeEventListener("keydown",o),b&&a(t,null==k?void 0:k.splitKey).forEach((function(e){return b.removeHotkey(c(e,null==k?void 0:k.combinationKey))}))}}}),[t,f,k,h]),i},exports.useHotkeysContext=y;
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/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/HotkeysProvider.tsx","../src/useHotkeys.ts","../src/isHotkeyPressed.ts","../src/useDeepEqualMemo.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n left: 'arrowleft',\n up: 'arrowup',\n right: 'arrowright',\n down: 'arrowdown',\n}\n\nexport function parseKeysHookInput(keys: Keys, splitKey: string = ','): string[] {\n if (typeof keys === 'string') {\n return keys.split(splitKey)\n }\n\n return keys\n}\n\nexport function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotkey {\n const keys = hotkey\n .toLocaleLowerCase()\n .split(combinationKey)\n .map(k => k.trim())\n .map(k => mappedKeys[k] || k)\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n shift: keys.includes('shift'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n }\n\n const singleCharKeys = keys.filter((k) => !reservedModifierKeywords.includes(k))\n\n return {\n ...modifiers,\n keys: singleCharKeys,\n }\n}\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\n\nexport function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void {\n if ((typeof preventDefault === 'function' && preventDefault(e, hotkey)) || preventDefault === true) {\n e.preventDefault()\n }\n}\n\nexport function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean {\n if (typeof enabled === 'function') {\n return enabled(e, hotkey)\n }\n\n return enabled === true || enabled === undefined\n}\n\nexport function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean {\n return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select'])\n}\n\nexport function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: FormTags[] | boolean = false): boolean {\n const targetTagName = target && (target as HTMLElement).tagName\n\n if (enabledOnTags instanceof Array) {\n return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(tag => tag.toLowerCase() === targetTagName.toLowerCase()))\n }\n\n return Boolean(targetTagName && enabledOnTags && enabledOnTags === true)\n}\n\nexport function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {\n if (activeScopes.length === 0 && scopes) {\n console.warn(\n 'A hotkey has the \"scopes\" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'\n )\n\n return true\n }\n\n if (!scopes) {\n return true\n }\n\n return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')\n}\n\nexport const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {\n const { alt, ctrl, meta, mod, shift, keys } = hotkey\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e\n\n const keyCode = code.toLowerCase().replace('key', '')\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (altKey !== alt && pressedKey !== 'alt') {\n return false\n }\n\n if (shiftKey !== shift && pressedKey !== 'shift') {\n return false\n }\n\n // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms\n if (mod) {\n if (!metaKey && !ctrlKey) {\n return false\n }\n } else {\n if (metaKey !== meta && keyCode !== 'meta') {\n return false\n }\n\n if (ctrlKey !== ctrl && keyCode !== 'ctrl') {\n return false\n }\n }\n\n // All modifiers are correct, now check the key\n // If the key is set we check for the key\n if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {\n return true\n } else if (keys) {\n // Check if all keys are present in pressedDownKeys set\n return keys.every(key => pressedDownKeys.has(key))\n }\n else if (!keys) {\n // If the key is not set, we only listen for modifiers, that check went alright, so we return true\n return true\n }\n\n // There is nothing that matches.\n return false\n}\n","import { createContext, ReactNode, useContext } from 'react'\nimport { Hotkey } from './types'\n\ntype BoundHotkeysProxyProviderType = {\n addHotkey: (hotkey: Hotkey) => void,\n removeHotkey: (hotkey: Hotkey) => void,\n}\n\nconst BoundHotkeysProxyProvider = createContext<BoundHotkeysProxyProviderType | undefined>(undefined)\n\nexport const useBoundHotkeysProxy = () => {\n return useContext(BoundHotkeysProxyProvider)\n}\n\ninterface Props {\n children: ReactNode\n addHotkey: (hotkey: Hotkey) => void\n removeHotkey: (hotkey: Hotkey) => void\n}\n\nexport default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props) {\n return <BoundHotkeysProxyProvider.Provider value={{addHotkey, removeHotkey}}>{children}</BoundHotkeysProxyProvider.Provider>\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useMemo, useState, useContext } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\n\nexport type HotkeysContextType = {\n hotkeys: ReadonlyArray<Hotkey>\n enabledScopes: string[]\n toggleScope: (scope: string) => void\n enableScope: (scope: string) => void\n disableScope: (scope: string) => void\n}\n\n// The context is only needed for special features like global scoping, so we use a graceful default fallback\nconst HotkeysContext = createContext<HotkeysContextType>({\n hotkeys: [],\n enabledScopes: [], // This array has to be empty instead of containing '*' as default, to check if the provider is set or not\n toggleScope: () => {},\n enableScope: () => {},\n disableScope: () => {},\n})\n\nexport const useHotkeysContext = () => {\n return useContext(HotkeysContext)\n}\n\ninterface Props {\n initiallyActiveScopes?: string[]\n children: ReactNode\n}\n\nexport const HotkeysProvider = ({initiallyActiveScopes = ['*'], children}: Props) => {\n const [internalActiveScopes, setInternalActiveScopes] = useState(initiallyActiveScopes?.length > 0 ? initiallyActiveScopes : ['*'])\n const [boundHotkeys, setBoundHotkeys] = useState<Hotkey[]>([]);\n\n const isAllActive = useMemo(() => internalActiveScopes.includes('*'), [internalActiveScopes])\n\n const enableScope = (scope: string) => {\n if (isAllActive) {\n setInternalActiveScopes([scope])\n } else {\n setInternalActiveScopes(Array.from(new Set([...internalActiveScopes, scope])))\n }\n }\n\n const disableScope = (scope: string) => {\n const scopes = internalActiveScopes.filter(s => s !== scope)\n\n if (scopes.length === 0) {\n setInternalActiveScopes(['*'])\n } else {\n setInternalActiveScopes(scopes)\n }\n }\n\n const toggleScope = (scope: string) => {\n if (internalActiveScopes.includes(scope)) {\n disableScope(scope)\n } else {\n enableScope(scope)\n }\n }\n\n const addBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys([...boundHotkeys, hotkey])\n }\n\n const removeBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys(boundHotkeys.filter(h => h.keys !== hotkey.keys))\n }\n\n return (\n <HotkeysContext.Provider value={{enabledScopes: internalActiveScopes, hotkeys: boundHotkeys, enableScope, disableScope, toggleScope}}>\n <BoundHotkeysProxyProviderProvider addHotkey={addBoundHotkey} removeHotkey={removeBoundHotkey}>\n {children}\n </BoundHotkeysProxyProviderProvider>\n </HotkeysContext.Provider>\n )\n}\n","import { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'\nimport { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { parseHotkey, parseKeysHookInput } from './parseHotkeys'\nimport {\n isHotkeyEnabled,\n isHotkeyEnabledOnTag,\n isHotkeyMatchingKeyboardEvent,\n isKeyboardEventTriggeredByInput,\n isScopeActive,\n maybePreventDefault,\n} from './validators'\nimport { useHotkeysContext } from './HotkeysProvider'\nimport { useBoundHotkeysProxy } from './BoundHotkeysProxyProvider'\nimport useDeepEqualMemo from './useDeepEqualMemo'\n\nconst stopPropagation = (e: KeyboardEvent): void => {\n e.stopPropagation()\n e.preventDefault()\n e.stopImmediatePropagation()\n}\n\nconst useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nexport default function useHotkeys<T extends HTMLElement>(\n keys: Keys,\n callback: HotkeyCallback,\n options?: OptionsOrDependencyArray,\n dependencies?: OptionsOrDependencyArray,\n) {\n const ref = useRef<RefType<T>>(null)\n const { current: pressedDownKeys } = useRef<Set<string>>(new Set())\n\n const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined\n const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []\n\n const cb = useCallback(callback, [..._deps])\n const memoisedOptions = useDeepEqualMemo(_options)\n\n const { enabledScopes } = useHotkeysContext()\n const proxy = useBoundHotkeysProxy()\n\n useSafeLayoutEffect(() => {\n if (memoisedOptions?.enabled === false || !isScopeActive(enabledScopes, memoisedOptions?.scopes)) {\n return\n }\n\n const listener = (e: KeyboardEvent) => {\n if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions?.enableOnFormTags)) {\n return\n }\n\n // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE\n // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.\n\n if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {\n stopPropagation(e)\n\n return\n }\n\n if (((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable)) {\n return\n }\n\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {\n const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)\n\n if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || hotkey.keys?.includes('*')) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n cb(e, hotkey)\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n pressedDownKeys.add(event.key.toLowerCase())\n\n if ((memoisedOptions?.keydown === undefined && memoisedOptions?.keyup !== true) || memoisedOptions?.keydown) {\n listener(event)\n }\n }\n\n const handleKeyUp = (event: KeyboardEvent) => {\n if (event.key.toLowerCase() !== 'meta') {\n pressedDownKeys.delete(event.key.toLowerCase())\n } else {\n // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.\n pressedDownKeys.clear()\n }\n\n if (memoisedOptions?.keyup) {\n listener(event)\n }\n }\n\n // @ts-ignore\n (ref.current || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).addEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n\n return () => {\n // @ts-ignore\n (ref.current || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).removeEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n }\n }, [keys, cb, memoisedOptions, enabledScopes])\n\n return ref\n}\n","import { Hotkey } from './types'\nimport { parseHotkey } from './parseHotkeys'\nimport isEqual from 'lodash.isEqual'\n\nconst currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()\n\nexport function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean {\n const hotkeyArray = Array.isArray(key) ? key : key.split(splitKey)\n\n return hotkeyArray.every((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (isEqual(parsedHotkey, pressedHotkey)) {\n return true\n }\n }\n })\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(parseHotkey(hotkey)))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (pressedHotkey.keys?.every((key) => parsedHotkey.keys?.includes(key))) {\n currentlyPressedKeys.delete(pressedHotkey)\n }\n }\n })\n}\n\n(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n document.addEventListener('keydown', e => {\n pushToCurrentlyPressedKeys(e.key)\n })\n\n document.addEventListener('keyup', e => {\n removeFromCurrentlyPressedKeys(e.key)\n })\n })\n }\n})()\n","import { useRef } from 'react'\nimport isEqual from 'lodash.isEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!isEqual(ref.current, value)) {\n ref.current = value\n }\n\n return ref.current\n}\n"],"names":["reservedModifierKeywords","mappedKeys","esc","return","left","up","right","down","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","trim","alt","includes","ctrl","shift","meta","mod","filter","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Array","Boolean","some","tag","toLowerCase","BoundHotkeysProxyProvider","createContext","undefined","BoundHotkeysProxyProviderProvider","_jsx","Provider","value","addHotkey","removeHotkey","children","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","useContext","stopPropagation","e","preventDefault","stopImmediatePropagation","useSafeLayoutEffect","window","useLayoutEffect","useEffect","currentlyPressedKeys","Set","addEventListener","document","key","isArray","forEach","add","parsedHotkey","pressedHotkey","_pressedHotkey$keys","every","_parsedHotkey$keys","initiallyActiveScopes","useState","length","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","isAllActive","useMemo","scope","from","scopes","s","h","isEqual","callback","options","dependencies","ref","useRef","pressedDownKeys","current","_options","cb","useCallback","memoisedOptions","useDeepEqualMemo","proxy","enabled","activeScopes","console","warn","listener","enableOnFormTags","activeElement","contains","_e$target","isContentEditable","enableOnContentEditable","altKey","ctrlKey","metaKey","shiftKey","pressedKeyUppercase","keyCode","code","replace","pressedKey","has","isHotkeyMatchingKeyboardEvent","_hotkey$keys","maybePreventDefault","isHotkeyEnabled","handleKeyDown","event","keydown","keyup","handleKeyUp","clear","removeEventListener"],"mappings":"urCAEA,IAAMA,EAA2B,CAAC,OAAQ,QAAS,MAAO,OAAQ,OAE5DC,EAAqC,CACzCC,IAAK,SACLC,OAAQ,QACRC,KAAM,YACNC,GAAI,UACJC,MAAO,aACPC,KAAM,sBAGQC,EAAmBC,EAAYC,GAC7C,gBAD6CA,IAAAA,EAAmB,KAC5C,iBAATD,EACFA,EAAKE,MAAMD,GAGbD,WAGOG,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,SAAAA,EAAiBG,SAG/C,YAFAjD,EAAgBC,GAKlB2C,EAAG3C,EAAG1C,OArBRyC,EAAgBC,KA0BdyE,EAAgB,SAACC,GACrBlC,EAAgB1B,IAAI4D,EAAM/D,IAAI/B,qBAEIG,WAA7B8D,SAAAA,EAAiB8B,WAAoD,WAA3B9B,SAAAA,EAAiB+B,cAAmB/B,GAAAA,EAAiB8B,UAClGvB,EAASsB,IAIPG,EAAc,SAACH,GACa,SAA5BA,EAAM/D,IAAI/B,cACZ4D,SAAuBkC,EAAM/D,IAAI/B,eAGjC4D,EAAgBsC,cAGdjC,GAAAA,EAAiB+B,OACnBxB,EAASsB,IAab,OARCpC,EAAIG,SAAW/B,UAAUD,iBAAiB,QAASoE,IAEnDvC,EAAIG,SAAW/B,UAAUD,iBAAiB,UAAWgE,GAElD1B,GACF9F,EAAmBC,QAAM2F,SAAAA,EAAiB1F,UAAU0D,SAAQ,SAACF,GAAG,OAAKoC,EAAM3D,UAAU/B,EAAYsD,QAAKkC,SAAAA,EAAiBtF,oBAGlH,YAEJ+E,EAAIG,SAAW/B,UAAUqE,oBAAoB,QAASF,IAEtDvC,EAAIG,SAAW/B,UAAUqE,oBAAoB,UAAWN,GAErD1B,GACF9F,EAAmBC,QAAM2F,SAAAA,EAAiB1F,UAAU0D,SAAQ,SAACF,GAAG,OAAKoC,EAAM1D,aAAahC,EAAYsD,QAAKkC,SAAAA,EAAiBtF,wBAG7H,CAACL,EAAMyF,EAAIE,EAAiBpD,IAExB6C"}
1
+ {"version":3,"file":"react-hotkeys-hook.cjs.production.min.js","sources":["../src/parseHotkeys.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/HotkeysProvider.tsx","../src/deepEqual.ts","../src/useHotkeys.ts","../src/isHotkeyPressed.ts","../src/useDeepEqualMemo.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n left: 'arrowleft',\n up: 'arrowup',\n right: 'arrowright',\n down: 'arrowdown',\n}\n\nexport function parseKeysHookInput(keys: Keys, splitKey: string = ','): string[] {\n if (typeof keys === 'string') {\n return keys.split(splitKey)\n }\n\n return keys\n}\n\nexport function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotkey {\n const keys = hotkey\n .toLocaleLowerCase()\n .split(combinationKey)\n .map(k => k.trim())\n .map(k => mappedKeys[k] || k)\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n shift: keys.includes('shift'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n }\n\n const singleCharKeys = keys.filter((k) => !reservedModifierKeywords.includes(k))\n\n return {\n ...modifiers,\n keys: singleCharKeys,\n }\n}\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\n\nexport function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void {\n if ((typeof preventDefault === 'function' && preventDefault(e, hotkey)) || preventDefault === true) {\n e.preventDefault()\n }\n}\n\nexport function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean {\n if (typeof enabled === 'function') {\n return enabled(e, hotkey)\n }\n\n return enabled === true || enabled === undefined\n}\n\nexport function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean {\n return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select'])\n}\n\nexport function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: FormTags[] | boolean = false): boolean {\n const targetTagName = target && (target as HTMLElement).tagName\n\n if (enabledOnTags instanceof Array) {\n return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(tag => tag.toLowerCase() === targetTagName.toLowerCase()))\n }\n\n return Boolean(targetTagName && enabledOnTags && enabledOnTags === true)\n}\n\nexport function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {\n if (activeScopes.length === 0 && scopes) {\n console.warn(\n 'A hotkey has the \"scopes\" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'\n )\n\n return true\n }\n\n if (!scopes) {\n return true\n }\n\n return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')\n}\n\nexport const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {\n const { alt, ctrl, meta, mod, shift, keys } = hotkey\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e\n\n const keyCode = code.toLowerCase().replace('key', '')\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (altKey !== alt && pressedKey !== 'alt') {\n return false\n }\n\n if (shiftKey !== shift && pressedKey !== 'shift') {\n return false\n }\n\n // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms\n if (mod) {\n if (!metaKey && !ctrlKey) {\n return false\n }\n } else {\n if (metaKey !== meta && keyCode !== 'meta') {\n return false\n }\n\n if (ctrlKey !== ctrl && keyCode !== 'ctrl') {\n return false\n }\n }\n\n // All modifiers are correct, now check the key\n // If the key is set we check for the key\n if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {\n return true\n } else if (keys) {\n // Check if all keys are present in pressedDownKeys set\n return keys.every(key => pressedDownKeys.has(key))\n }\n else if (!keys) {\n // If the key is not set, we only listen for modifiers, that check went alright, so we return true\n return true\n }\n\n // There is nothing that matches.\n return false\n}\n","import { createContext, ReactNode, useContext } from 'react'\nimport { Hotkey } from './types'\n\ntype BoundHotkeysProxyProviderType = {\n addHotkey: (hotkey: Hotkey) => void,\n removeHotkey: (hotkey: Hotkey) => void,\n}\n\nconst BoundHotkeysProxyProvider = createContext<BoundHotkeysProxyProviderType | undefined>(undefined)\n\nexport const useBoundHotkeysProxy = () => {\n return useContext(BoundHotkeysProxyProvider)\n}\n\ninterface Props {\n children: ReactNode\n addHotkey: (hotkey: Hotkey) => void\n removeHotkey: (hotkey: Hotkey) => void\n}\n\nexport default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props) {\n return <BoundHotkeysProxyProvider.Provider value={{addHotkey, removeHotkey}}>{children}</BoundHotkeysProxyProvider.Provider>\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useMemo, useState, useContext } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\n\nexport type HotkeysContextType = {\n hotkeys: ReadonlyArray<Hotkey>\n enabledScopes: string[]\n toggleScope: (scope: string) => void\n enableScope: (scope: string) => void\n disableScope: (scope: string) => void\n}\n\n// The context is only needed for special features like global scoping, so we use a graceful default fallback\nconst HotkeysContext = createContext<HotkeysContextType>({\n hotkeys: [],\n enabledScopes: [], // This array has to be empty instead of containing '*' as default, to check if the provider is set or not\n toggleScope: () => {},\n enableScope: () => {},\n disableScope: () => {},\n})\n\nexport const useHotkeysContext = () => {\n return useContext(HotkeysContext)\n}\n\ninterface Props {\n initiallyActiveScopes?: string[]\n children: ReactNode\n}\n\nexport const HotkeysProvider = ({initiallyActiveScopes = ['*'], children}: Props) => {\n const [internalActiveScopes, setInternalActiveScopes] = useState(initiallyActiveScopes?.length > 0 ? initiallyActiveScopes : ['*'])\n const [boundHotkeys, setBoundHotkeys] = useState<Hotkey[]>([]);\n\n const isAllActive = useMemo(() => internalActiveScopes.includes('*'), [internalActiveScopes])\n\n const enableScope = (scope: string) => {\n if (isAllActive) {\n setInternalActiveScopes([scope])\n } else {\n setInternalActiveScopes(Array.from(new Set([...internalActiveScopes, scope])))\n }\n }\n\n const disableScope = (scope: string) => {\n const scopes = internalActiveScopes.filter(s => s !== scope)\n\n if (scopes.length === 0) {\n setInternalActiveScopes(['*'])\n } else {\n setInternalActiveScopes(scopes)\n }\n }\n\n const toggleScope = (scope: string) => {\n if (internalActiveScopes.includes(scope)) {\n disableScope(scope)\n } else {\n enableScope(scope)\n }\n }\n\n const addBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys([...boundHotkeys, hotkey])\n }\n\n const removeBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys(boundHotkeys.filter(h => h.keys !== hotkey.keys))\n }\n\n return (\n <HotkeysContext.Provider value={{enabledScopes: internalActiveScopes, hotkeys: boundHotkeys, enableScope, disableScope, toggleScope}}>\n <BoundHotkeysProxyProviderProvider addHotkey={addBoundHotkey} removeHotkey={removeBoundHotkey}>\n {children}\n </BoundHotkeysProxyProviderProvider>\n </HotkeysContext.Provider>\n )\n}\n","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 { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'\nimport { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { parseHotkey, parseKeysHookInput } from './parseHotkeys'\nimport {\n isHotkeyEnabled,\n isHotkeyEnabledOnTag,\n isHotkeyMatchingKeyboardEvent,\n isKeyboardEventTriggeredByInput,\n isScopeActive,\n maybePreventDefault,\n} from './validators'\nimport { useHotkeysContext } from './HotkeysProvider'\nimport { useBoundHotkeysProxy } from './BoundHotkeysProxyProvider'\nimport useDeepEqualMemo from './useDeepEqualMemo'\n\nconst stopPropagation = (e: KeyboardEvent): void => {\n e.stopPropagation()\n e.preventDefault()\n e.stopImmediatePropagation()\n}\n\nconst useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nexport default function useHotkeys<T extends HTMLElement>(\n keys: Keys,\n callback: HotkeyCallback,\n options?: OptionsOrDependencyArray,\n dependencies?: OptionsOrDependencyArray,\n) {\n const ref = useRef<RefType<T>>(null)\n const { current: pressedDownKeys } = useRef<Set<string>>(new Set())\n\n const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined\n const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []\n\n const cb = useCallback(callback, [..._deps])\n const memoisedOptions = useDeepEqualMemo(_options)\n\n const { enabledScopes } = useHotkeysContext()\n const proxy = useBoundHotkeysProxy()\n\n useSafeLayoutEffect(() => {\n if (memoisedOptions?.enabled === false || !isScopeActive(enabledScopes, memoisedOptions?.scopes)) {\n return\n }\n\n const listener = (e: KeyboardEvent) => {\n if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions?.enableOnFormTags)) {\n return\n }\n\n // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE\n // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.\n\n if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {\n stopPropagation(e)\n\n return\n }\n\n if (((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable)) {\n return\n }\n\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {\n const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)\n\n if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || hotkey.keys?.includes('*')) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n cb(e, hotkey)\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n pressedDownKeys.add(event.key.toLowerCase())\n\n if ((memoisedOptions?.keydown === undefined && memoisedOptions?.keyup !== true) || memoisedOptions?.keydown) {\n listener(event)\n }\n }\n\n const handleKeyUp = (event: KeyboardEvent) => {\n if (event.key.toLowerCase() !== 'meta') {\n pressedDownKeys.delete(event.key.toLowerCase())\n } else {\n // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.\n pressedDownKeys.clear()\n }\n\n if (memoisedOptions?.keyup) {\n listener(event)\n }\n }\n\n // @ts-ignore\n (ref.current || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).addEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n\n return () => {\n // @ts-ignore\n (ref.current || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).removeEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n }\n }, [keys, cb, memoisedOptions, enabledScopes])\n\n return ref\n}\n","import { Hotkey } from './types'\nimport { parseHotkey } from './parseHotkeys'\nimport deepEqual from './deepEqual'\n\nconst currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()\n\nexport function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean {\n const hotkeyArray = Array.isArray(key) ? key : key.split(splitKey)\n\n return hotkeyArray.every((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (deepEqual(parsedHotkey, pressedHotkey)) {\n return true\n }\n }\n })\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(parseHotkey(hotkey)))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (pressedHotkey.keys?.every((key) => parsedHotkey.keys?.includes(key))) {\n currentlyPressedKeys.delete(pressedHotkey)\n }\n }\n })\n}\n\n(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n document.addEventListener('keydown', e => {\n pushToCurrentlyPressedKeys(e.key)\n })\n\n document.addEventListener('keyup', e => {\n removeFromCurrentlyPressedKeys(e.key)\n })\n })\n }\n})()\n","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"],"names":["reservedModifierKeywords","mappedKeys","esc","return","left","up","right","down","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","trim","alt","includes","ctrl","shift","meta","mod","filter","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Array","Boolean","some","tag","toLowerCase","BoundHotkeysProxyProvider","createContext","undefined","BoundHotkeysProxyProviderProvider","_jsx","Provider","value","addHotkey","removeHotkey","children","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","useContext","deepEqual","x","y","Object","length","reduce","isEqual","key","stopPropagation","e","preventDefault","stopImmediatePropagation","useSafeLayoutEffect","window","useLayoutEffect","useEffect","currentlyPressedKeys","Set","addEventListener","document","isArray","forEach","add","parsedHotkey","pressedHotkey","_pressedHotkey$keys","every","_parsedHotkey$keys","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","isAllActive","useMemo","scope","from","scopes","s","h","callback","options","dependencies","ref","useRef","pressedDownKeys","current","_options","cb","useCallback","memoisedOptions","useDeepEqualMemo","proxy","enabled","activeScopes","console","warn","listener","enableOnFormTags","activeElement","contains","_e$target","isContentEditable","enableOnContentEditable","altKey","ctrlKey","metaKey","shiftKey","pressedKeyUppercase","keyCode","code","replace","pressedKey","has","isHotkeyMatchingKeyboardEvent","_hotkey$keys","maybePreventDefault","isHotkeyEnabled","handleKeyDown","event","keydown","keyup","handleKeyUp","clear","removeEventListener"],"mappings":"smCAEA,IAAMA,EAA2B,CAAC,OAAQ,QAAS,MAAO,OAAQ,OAE5DC,EAAqC,CACzCC,IAAK,SACLC,OAAQ,QACRC,KAAM,YACNC,GAAI,UACJC,MAAO,aACPC,KAAM,sBAGQC,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,OAAIA,EAAEC,UACXF,KAAI,SAAAC,GAAC,OAAIhB,EAAWgB,IAAMA,KAY7B,YAVqC,CACnCE,IAAKV,EAAKW,SAAS,OACnBC,KAAMZ,EAAKW,SAAS,QACpBE,MAAOb,EAAKW,SAAS,SACrBG,KAAMd,EAAKW,SAAS,QACpBI,IAAKf,EAAKW,SAAS,SAOnBX,KAJqBA,EAAKgB,QAAO,SAACR,GAAC,OAAMjB,EAAyBoB,SAASH,iBChB/DS,IAAgDC,OAAzBC,IAAAA,gBAAyBD,IAAAA,GAAsC,GACpG,IAAME,EAAgBD,GAAWA,EAAuBE,QAExD,OAAIH,aAAyBI,MACpBC,QAAQH,GAAiBF,GAAiBA,EAAcM,MAAK,SAAAC,GAAG,OAAIA,EAAIC,gBAAkBN,EAAcM,kBAG1GH,QAAQH,GAAiBF,IAAmC,IAAlBA,GAmBnD,ICtCMS,EAA4BC,qBAAyDC,YAYnEC,KACtB,OAAOC,MAACJ,EAA0BK,UAASC,MAAO,CAACC,YADOA,UACIC,eADOA,cACOC,WADOA,WCPrF,IAAMC,EAAiBT,gBAAkC,CACvDU,QAAS,GACTC,cAAe,GACfC,YAAa,aACbC,YAAa,aACbC,aAAc,eAGHC,EAAoB,WAC/B,O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EAAYiD,QAAK4C,SAAAA,EAAiB3F,oBAGlH,YAEJoF,EAAIG,SAAW5B,UAAUkE,oBAAoB,QAASF,IAEtDvC,EAAIG,SAAW5B,UAAUkE,oBAAoB,UAAWN,GAErD1B,GACFnG,EAAmBC,QAAMgG,SAAAA,EAAiB/F,UAAUiE,SAAQ,SAACd,GAAG,OAAK8C,EAAM/D,aAAahC,EAAYiD,QAAK4C,SAAAA,EAAiB3F,wBAG7H,CAACL,EAAM8F,EAAIE,EAAiBzD,IAExBkD"}
@@ -1,6 +1,5 @@
1
1
  import { useContext, createContext, useState, useMemo, useRef, useCallback, useLayoutEffect, useEffect } from 'react';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import isEqual from 'lodash.isEqual';
4
3
 
5
4
  function _extends() {
6
5
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -268,9 +267,18 @@ var HotkeysProvider = function HotkeysProvider(_ref) {
268
267
  });
269
268
  };
270
269
 
270
+ function deepEqual(x, y) {
271
+ //@ts-ignore
272
+ return x && y && typeof x === 'object' && typeof y === 'object'
273
+ //@ts-ignore
274
+ ? Object.keys(x).length === Object.keys(y).length && Object.keys(x).reduce(function (isEqual, key) {
275
+ return isEqual && deepEqual(x[key], y[key]);
276
+ }, true) : x === y;
277
+ }
278
+
271
279
  function useDeepEqualMemo(value) {
272
280
  var ref = useRef(undefined);
273
- if (!isEqual(ref.current, value)) {
281
+ if (!deepEqual(ref.current, value)) {
274
282
  ref.current = value;
275
283
  }
276
284
  return ref.current;
@@ -375,7 +383,7 @@ function isHotkeyPressed(key, splitKey) {
375
383
  var parsedHotkey = parseHotkey(hotkey);
376
384
  for (var _iterator = _createForOfIteratorHelperLoose(currentlyPressedKeys), _step; !(_step = _iterator()).done;) {
377
385
  var pressedHotkey = _step.value;
378
- if (isEqual(parsedHotkey, pressedHotkey)) {
386
+ if (deepEqual(parsedHotkey, pressedHotkey)) {
379
387
  return true;
380
388
  }
381
389
  }
@@ -1 +1 @@
1
- {"version":3,"file":"react-hotkeys-hook.esm.js","sources":["../src/parseHotkeys.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/HotkeysProvider.tsx","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/isHotkeyPressed.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n left: 'arrowleft',\n up: 'arrowup',\n right: 'arrowright',\n down: 'arrowdown',\n}\n\nexport function parseKeysHookInput(keys: Keys, splitKey: string = ','): string[] {\n if (typeof keys === 'string') {\n return keys.split(splitKey)\n }\n\n return keys\n}\n\nexport function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotkey {\n const keys = hotkey\n .toLocaleLowerCase()\n .split(combinationKey)\n .map(k => k.trim())\n .map(k => mappedKeys[k] || k)\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n shift: keys.includes('shift'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n }\n\n const singleCharKeys = keys.filter((k) => !reservedModifierKeywords.includes(k))\n\n return {\n ...modifiers,\n keys: singleCharKeys,\n }\n}\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\n\nexport function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void {\n if ((typeof preventDefault === 'function' && preventDefault(e, hotkey)) || preventDefault === true) {\n e.preventDefault()\n }\n}\n\nexport function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean {\n if (typeof enabled === 'function') {\n return enabled(e, hotkey)\n }\n\n return enabled === true || enabled === undefined\n}\n\nexport function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean {\n return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select'])\n}\n\nexport function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: FormTags[] | boolean = false): boolean {\n const targetTagName = target && (target as HTMLElement).tagName\n\n if (enabledOnTags instanceof Array) {\n return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(tag => tag.toLowerCase() === targetTagName.toLowerCase()))\n }\n\n return Boolean(targetTagName && enabledOnTags && enabledOnTags === true)\n}\n\nexport function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {\n if (activeScopes.length === 0 && scopes) {\n console.warn(\n 'A hotkey has the \"scopes\" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'\n )\n\n return true\n }\n\n if (!scopes) {\n return true\n }\n\n return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')\n}\n\nexport const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {\n const { alt, ctrl, meta, mod, shift, keys } = hotkey\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e\n\n const keyCode = code.toLowerCase().replace('key', '')\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (altKey !== alt && pressedKey !== 'alt') {\n return false\n }\n\n if (shiftKey !== shift && pressedKey !== 'shift') {\n return false\n }\n\n // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms\n if (mod) {\n if (!metaKey && !ctrlKey) {\n return false\n }\n } else {\n if (metaKey !== meta && keyCode !== 'meta') {\n return false\n }\n\n if (ctrlKey !== ctrl && keyCode !== 'ctrl') {\n return false\n }\n }\n\n // All modifiers are correct, now check the key\n // If the key is set we check for the key\n if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {\n return true\n } else if (keys) {\n // Check if all keys are present in pressedDownKeys set\n return keys.every(key => pressedDownKeys.has(key))\n }\n else if (!keys) {\n // If the key is not set, we only listen for modifiers, that check went alright, so we return true\n return true\n }\n\n // There is nothing that matches.\n return false\n}\n","import { createContext, ReactNode, useContext } from 'react'\nimport { Hotkey } from './types'\n\ntype BoundHotkeysProxyProviderType = {\n addHotkey: (hotkey: Hotkey) => void,\n removeHotkey: (hotkey: Hotkey) => void,\n}\n\nconst BoundHotkeysProxyProvider = createContext<BoundHotkeysProxyProviderType | undefined>(undefined)\n\nexport const useBoundHotkeysProxy = () => {\n return useContext(BoundHotkeysProxyProvider)\n}\n\ninterface Props {\n children: ReactNode\n addHotkey: (hotkey: Hotkey) => void\n removeHotkey: (hotkey: Hotkey) => void\n}\n\nexport default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props) {\n return <BoundHotkeysProxyProvider.Provider value={{addHotkey, removeHotkey}}>{children}</BoundHotkeysProxyProvider.Provider>\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useMemo, useState, useContext } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\n\nexport type HotkeysContextType = {\n hotkeys: ReadonlyArray<Hotkey>\n enabledScopes: string[]\n toggleScope: (scope: string) => void\n enableScope: (scope: string) => void\n disableScope: (scope: string) => void\n}\n\n// The context is only needed for special features like global scoping, so we use a graceful default fallback\nconst HotkeysContext = createContext<HotkeysContextType>({\n hotkeys: [],\n enabledScopes: [], // This array has to be empty instead of containing '*' as default, to check if the provider is set or not\n toggleScope: () => {},\n enableScope: () => {},\n disableScope: () => {},\n})\n\nexport const useHotkeysContext = () => {\n return useContext(HotkeysContext)\n}\n\ninterface Props {\n initiallyActiveScopes?: string[]\n children: ReactNode\n}\n\nexport const HotkeysProvider = ({initiallyActiveScopes = ['*'], children}: Props) => {\n const [internalActiveScopes, setInternalActiveScopes] = useState(initiallyActiveScopes?.length > 0 ? initiallyActiveScopes : ['*'])\n const [boundHotkeys, setBoundHotkeys] = useState<Hotkey[]>([]);\n\n const isAllActive = useMemo(() => internalActiveScopes.includes('*'), [internalActiveScopes])\n\n const enableScope = (scope: string) => {\n if (isAllActive) {\n setInternalActiveScopes([scope])\n } else {\n setInternalActiveScopes(Array.from(new Set([...internalActiveScopes, scope])))\n }\n }\n\n const disableScope = (scope: string) => {\n const scopes = internalActiveScopes.filter(s => s !== scope)\n\n if (scopes.length === 0) {\n setInternalActiveScopes(['*'])\n } else {\n setInternalActiveScopes(scopes)\n }\n }\n\n const toggleScope = (scope: string) => {\n if (internalActiveScopes.includes(scope)) {\n disableScope(scope)\n } else {\n enableScope(scope)\n }\n }\n\n const addBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys([...boundHotkeys, hotkey])\n }\n\n const removeBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys(boundHotkeys.filter(h => h.keys !== hotkey.keys))\n }\n\n return (\n <HotkeysContext.Provider value={{enabledScopes: internalActiveScopes, hotkeys: boundHotkeys, enableScope, disableScope, toggleScope}}>\n <BoundHotkeysProxyProviderProvider addHotkey={addBoundHotkey} removeHotkey={removeBoundHotkey}>\n {children}\n </BoundHotkeysProxyProviderProvider>\n </HotkeysContext.Provider>\n )\n}\n","import { useRef } from 'react'\nimport isEqual from 'lodash.isEqual'\n\nexport default function useDeepEqualMemo<T>(value: T) {\n const ref = useRef<T | undefined>(undefined)\n\n if (!isEqual(ref.current, value)) {\n ref.current = value\n }\n\n return ref.current\n}\n","import { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'\nimport { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'\nimport { parseHotkey, parseKeysHookInput } from './parseHotkeys'\nimport {\n isHotkeyEnabled,\n isHotkeyEnabledOnTag,\n isHotkeyMatchingKeyboardEvent,\n isKeyboardEventTriggeredByInput,\n isScopeActive,\n maybePreventDefault,\n} from './validators'\nimport { useHotkeysContext } from './HotkeysProvider'\nimport { useBoundHotkeysProxy } from './BoundHotkeysProxyProvider'\nimport useDeepEqualMemo from './useDeepEqualMemo'\n\nconst stopPropagation = (e: KeyboardEvent): void => {\n e.stopPropagation()\n e.preventDefault()\n e.stopImmediatePropagation()\n}\n\nconst useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nexport default function useHotkeys<T extends HTMLElement>(\n keys: Keys,\n callback: HotkeyCallback,\n options?: OptionsOrDependencyArray,\n dependencies?: OptionsOrDependencyArray,\n) {\n const ref = useRef<RefType<T>>(null)\n const { current: pressedDownKeys } = useRef<Set<string>>(new Set())\n\n const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined\n const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []\n\n const cb = useCallback(callback, [..._deps])\n const memoisedOptions = useDeepEqualMemo(_options)\n\n const { enabledScopes } = useHotkeysContext()\n const proxy = useBoundHotkeysProxy()\n\n useSafeLayoutEffect(() => {\n if (memoisedOptions?.enabled === false || !isScopeActive(enabledScopes, memoisedOptions?.scopes)) {\n return\n }\n\n const listener = (e: KeyboardEvent) => {\n if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions?.enableOnFormTags)) {\n return\n }\n\n // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE\n // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.\n\n if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {\n stopPropagation(e)\n\n return\n }\n\n if (((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable)) {\n return\n }\n\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {\n const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)\n\n if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || hotkey.keys?.includes('*')) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n cb(e, hotkey)\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n pressedDownKeys.add(event.key.toLowerCase())\n\n if ((memoisedOptions?.keydown === undefined && memoisedOptions?.keyup !== true) || memoisedOptions?.keydown) {\n listener(event)\n }\n }\n\n const handleKeyUp = (event: KeyboardEvent) => {\n if (event.key.toLowerCase() !== 'meta') {\n pressedDownKeys.delete(event.key.toLowerCase())\n } else {\n // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.\n pressedDownKeys.clear()\n }\n\n if (memoisedOptions?.keyup) {\n listener(event)\n }\n }\n\n // @ts-ignore\n (ref.current || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).addEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n\n return () => {\n // @ts-ignore\n (ref.current || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).removeEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n }\n }, [keys, cb, memoisedOptions, enabledScopes])\n\n return ref\n}\n","import { Hotkey } from './types'\nimport { parseHotkey } from './parseHotkeys'\nimport isEqual from 'lodash.isEqual'\n\nconst currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()\n\nexport function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean {\n const hotkeyArray = Array.isArray(key) ? key : key.split(splitKey)\n\n return hotkeyArray.every((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (isEqual(parsedHotkey, pressedHotkey)) {\n return true\n }\n }\n })\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(parseHotkey(hotkey)))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (pressedHotkey.keys?.every((key) => parsedHotkey.keys?.includes(key))) {\n currentlyPressedKeys.delete(pressedHotkey)\n }\n }\n })\n}\n\n(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n document.addEventListener('keydown', e => {\n pushToCurrentlyPressedKeys(e.key)\n })\n\n document.addEventListener('keyup', e => {\n removeFromCurrentlyPressedKeys(e.key)\n })\n })\n }\n})()\n"],"names":["reservedModifierKeywords","mappedKeys","esc","left","up","right","down","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","trim","modifiers","alt","includes","ctrl","shift","meta","mod","singleCharKeys","filter","maybePreventDefault","e","preventDefault","isHotkeyEnabled","enabled","undefined","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Array","Boolean","some","tag","toLowerCase","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","pressedDownKeys","altKey","ctrlKey","metaKey","shiftKey","pressedKeyUppercase","key","code","keyCode","replace","pressedKey","every","has","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","isAllActive","useMemo","from","Set","s","addBoundHotkey","removeBoundHotkey","h","useDeepEqualMemo","value","ref","useRef","isEqual","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","window","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","_options","_deps","cb","useCallback","memoisedOptions","proxy","listener","enableOnFormTags","document","activeElement","contains","isContentEditable","enableOnContentEditable","forEach","handleKeyDown","event","add","keydown","keyup","handleKeyUp","clear","addEventListener","removeEventListener","currentlyPressedKeys","isHotkeyPressed","hotkeyArray","isArray","parsedHotkey","pressedHotkey","pushToCurrentlyPressedKeys","removeFromCurrentlyPressedKeys"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;AAExE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACfC,IAAI,EAAE,WAAW;EACjBC,EAAE,EAAE,SAAS;EACbC,KAAK,EAAE,YAAY;EACnBC,IAAI,EAAE;CACP;SAEeC,kBAAkB,CAACC,IAAU,EAAEC;MAAAA;IAAAA,WAAmB,GAAG;;EACnE,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI,CAACE,KAAK,CAACD,QAAQ,CAAC;;EAG7B,OAAOD,IAAI;AACb;SAEgBG,WAAW,CAACC,MAAc,EAAEC;MAAAA;IAAAA,iBAAyB,GAAG;;EACtE,IAAML,IAAI,GAAGI,MAAM,CAChBE,iBAAiB,EAAE,CACnBJ,KAAK,CAACG,cAAc,CAAC,CACrBE,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIA,CAAC,CAACC,IAAI,EAAE;IAAC,CAClBF,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIf,UAAU,CAACe,CAAC,CAAC,IAAIA,CAAC;IAAC;EAE/B,IAAME,SAAS,GAAsB;IACnCC,GAAG,EAAEX,IAAI,CAACY,QAAQ,CAAC,KAAK,CAAC;IACzBC,IAAI,EAAEb,IAAI,CA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AC;IAAC;AAC9E;AAEA,SAAgBmI,8BAA8B,CAACpF,GAAsB;EACnE,IAAM+E,WAAW,GAAGlG,KAAK,CAACmG,OAAO,CAAChF,GAAG,CAAC,GAAGA,GAAG,GAAG,CAACA,GAAG,CAAC;EAEpD+E,WAAW,CAACZ,OAAO,CAAC,UAAClH,MAAM;IACzB,IAAMgI,YAAY,GAAGjI,WAAW,CAACC,MAAM,CAAC;IAExC,sDAA4B4H,oBAAoB,2CAAE;MAAA;MAAA,IAAvCK,aAAa;MACtB,2BAAIA,aAAa,CAACrI,IAAI,aAAlB,oBAAoBwD,KAAK,CAAC,UAACL,GAAG;QAAA;QAAA,6BAAKiF,YAAY,CAACpI,IAAI,qBAAjB,mBAAmBY,QAAQ,CAACuC,GAAG,CAAC;QAAC,EAAE;QACxE6E,oBAAoB,UAAO,CAACK,aAAa,CAAC;;;GAG/C,CAAC;AACJ;AAEA,CAAC;EACC,IAAI,OAAOnC,MAAM,KAAK,WAAW,EAAE;IACjCA,MAAM,CAAC4B,gBAAgB,CAAC,kBAAkB,EAAE;MAC1Cb,QAAQ,CAACa,gBAAgB,CAAC,SAAS,EAAE,UAAA1G,CAAC;QACpCkH,0BAA0B,CAAClH,CAAC,CAAC+B,GAAG,CAAC;OAClC,CAAC;MAEF8D,QAAQ,CAACa,gBAAgB,CAAC,OAAO,EAAE,UAAA1G,CAAC;QAClCmH,8BAA8B,CAACnH,CAAC,CAAC+B,GAAG,CAAC;OACtC,CAAC;KACH,CAAC;;AAEN,CAAC,GAAG;;;;"}
1
+ {"version":3,"file":"react-hotkeys-hook.esm.js","sources":["../src/parseHotkeys.ts","../src/validators.ts","../src/BoundHotkeysProxyProvider.tsx","../src/HotkeysProvider.tsx","../src/deepEqual.ts","../src/useDeepEqualMemo.ts","../src/useHotkeys.ts","../src/isHotkeyPressed.ts"],"sourcesContent":["import { Hotkey, KeyboardModifiers, Keys } from './types'\n\nconst reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']\n\nconst mappedKeys: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n left: 'arrowleft',\n up: 'arrowup',\n right: 'arrowright',\n down: 'arrowdown',\n}\n\nexport function parseKeysHookInput(keys: Keys, splitKey: string = ','): string[] {\n if (typeof keys === 'string') {\n return keys.split(splitKey)\n }\n\n return keys\n}\n\nexport function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotkey {\n const keys = hotkey\n .toLocaleLowerCase()\n .split(combinationKey)\n .map(k => k.trim())\n .map(k => mappedKeys[k] || k)\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n shift: keys.includes('shift'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n }\n\n const singleCharKeys = keys.filter((k) => !reservedModifierKeywords.includes(k))\n\n return {\n ...modifiers,\n keys: singleCharKeys,\n }\n}\n","import { FormTags, Hotkey, Scopes, Trigger } from './types'\n\nexport function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void {\n if ((typeof preventDefault === 'function' && preventDefault(e, hotkey)) || preventDefault === true) {\n e.preventDefault()\n }\n}\n\nexport function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean {\n if (typeof enabled === 'function') {\n return enabled(e, hotkey)\n }\n\n return enabled === true || enabled === undefined\n}\n\nexport function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean {\n return isHotkeyEnabledOnTag(ev, ['input', 'textarea', 'select'])\n}\n\nexport function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags: FormTags[] | boolean = false): boolean {\n const targetTagName = target && (target as HTMLElement).tagName\n\n if (enabledOnTags instanceof Array) {\n return Boolean(targetTagName && enabledOnTags && enabledOnTags.some(tag => tag.toLowerCase() === targetTagName.toLowerCase()))\n }\n\n return Boolean(targetTagName && enabledOnTags && enabledOnTags === true)\n}\n\nexport function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean {\n if (activeScopes.length === 0 && scopes) {\n console.warn(\n 'A hotkey has the \"scopes\" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'\n )\n\n return true\n }\n\n if (!scopes) {\n return true\n }\n\n return activeScopes.some(scope => scopes.includes(scope)) || activeScopes.includes('*')\n}\n\nexport const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {\n const { alt, ctrl, meta, mod, shift, keys } = hotkey\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e\n\n const keyCode = code.toLowerCase().replace('key', '')\n const pressedKey = pressedKeyUppercase.toLowerCase()\n\n if (altKey !== alt && pressedKey !== 'alt') {\n return false\n }\n\n if (shiftKey !== shift && pressedKey !== 'shift') {\n return false\n }\n\n // Mod is a special key name that is checking for meta on macOS and ctrl on other platforms\n if (mod) {\n if (!metaKey && !ctrlKey) {\n return false\n }\n } else {\n if (metaKey !== meta && keyCode !== 'meta') {\n return false\n }\n\n if (ctrlKey !== ctrl && keyCode !== 'ctrl') {\n return false\n }\n }\n\n // All modifiers are correct, now check the key\n // If the key is set we check for the key\n if (keys && keys.length === 1 && (keys.includes(pressedKey) || keys.includes(keyCode))) {\n return true\n } else if (keys) {\n // Check if all keys are present in pressedDownKeys set\n return keys.every(key => pressedDownKeys.has(key))\n }\n else if (!keys) {\n // If the key is not set, we only listen for modifiers, that check went alright, so we return true\n return true\n }\n\n // There is nothing that matches.\n return false\n}\n","import { createContext, ReactNode, useContext } from 'react'\nimport { Hotkey } from './types'\n\ntype BoundHotkeysProxyProviderType = {\n addHotkey: (hotkey: Hotkey) => void,\n removeHotkey: (hotkey: Hotkey) => void,\n}\n\nconst BoundHotkeysProxyProvider = createContext<BoundHotkeysProxyProviderType | undefined>(undefined)\n\nexport const useBoundHotkeysProxy = () => {\n return useContext(BoundHotkeysProxyProvider)\n}\n\ninterface Props {\n children: ReactNode\n addHotkey: (hotkey: Hotkey) => void\n removeHotkey: (hotkey: Hotkey) => void\n}\n\nexport default function BoundHotkeysProxyProviderProvider({ addHotkey, removeHotkey, children }: Props) {\n return <BoundHotkeysProxyProvider.Provider value={{addHotkey, removeHotkey}}>{children}</BoundHotkeysProxyProvider.Provider>\n}\n","import { Hotkey } from './types'\nimport { createContext, ReactNode, useMemo, useState, useContext } from 'react'\nimport BoundHotkeysProxyProviderProvider from './BoundHotkeysProxyProvider'\n\nexport type HotkeysContextType = {\n hotkeys: ReadonlyArray<Hotkey>\n enabledScopes: string[]\n toggleScope: (scope: string) => void\n enableScope: (scope: string) => void\n disableScope: (scope: string) => void\n}\n\n// The context is only needed for special features like global scoping, so we use a graceful default fallback\nconst HotkeysContext = createContext<HotkeysContextType>({\n hotkeys: [],\n enabledScopes: [], // This array has to be empty instead of containing '*' as default, to check if the provider is set or not\n toggleScope: () => {},\n enableScope: () => {},\n disableScope: () => {},\n})\n\nexport const useHotkeysContext = () => {\n return useContext(HotkeysContext)\n}\n\ninterface Props {\n initiallyActiveScopes?: string[]\n children: ReactNode\n}\n\nexport const HotkeysProvider = ({initiallyActiveScopes = ['*'], children}: Props) => {\n const [internalActiveScopes, setInternalActiveScopes] = useState(initiallyActiveScopes?.length > 0 ? initiallyActiveScopes : ['*'])\n const [boundHotkeys, setBoundHotkeys] = useState<Hotkey[]>([]);\n\n const isAllActive = useMemo(() => internalActiveScopes.includes('*'), [internalActiveScopes])\n\n const enableScope = (scope: string) => {\n if (isAllActive) {\n setInternalActiveScopes([scope])\n } else {\n setInternalActiveScopes(Array.from(new Set([...internalActiveScopes, scope])))\n }\n }\n\n const disableScope = (scope: string) => {\n const scopes = internalActiveScopes.filter(s => s !== scope)\n\n if (scopes.length === 0) {\n setInternalActiveScopes(['*'])\n } else {\n setInternalActiveScopes(scopes)\n }\n }\n\n const toggleScope = (scope: string) => {\n if (internalActiveScopes.includes(scope)) {\n disableScope(scope)\n } else {\n enableScope(scope)\n }\n }\n\n const addBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys([...boundHotkeys, hotkey])\n }\n\n const removeBoundHotkey = (hotkey: Hotkey) => {\n setBoundHotkeys(boundHotkeys.filter(h => h.keys !== hotkey.keys))\n }\n\n return (\n <HotkeysContext.Provider value={{enabledScopes: internalActiveScopes, hotkeys: boundHotkeys, enableScope, disableScope, toggleScope}}>\n <BoundHotkeysProxyProviderProvider addHotkey={addBoundHotkey} removeHotkey={removeBoundHotkey}>\n {children}\n </BoundHotkeysProxyProviderProvider>\n </HotkeysContext.Provider>\n )\n}\n","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 { 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 { parseHotkey, parseKeysHookInput } from './parseHotkeys'\nimport {\n isHotkeyEnabled,\n isHotkeyEnabledOnTag,\n isHotkeyMatchingKeyboardEvent,\n isKeyboardEventTriggeredByInput,\n isScopeActive,\n maybePreventDefault,\n} from './validators'\nimport { useHotkeysContext } from './HotkeysProvider'\nimport { useBoundHotkeysProxy } from './BoundHotkeysProxyProvider'\nimport useDeepEqualMemo from './useDeepEqualMemo'\n\nconst stopPropagation = (e: KeyboardEvent): void => {\n e.stopPropagation()\n e.preventDefault()\n e.stopImmediatePropagation()\n}\n\nconst useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n\nexport default function useHotkeys<T extends HTMLElement>(\n keys: Keys,\n callback: HotkeyCallback,\n options?: OptionsOrDependencyArray,\n dependencies?: OptionsOrDependencyArray,\n) {\n const ref = useRef<RefType<T>>(null)\n const { current: pressedDownKeys } = useRef<Set<string>>(new Set())\n\n const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined\n const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []\n\n const cb = useCallback(callback, [..._deps])\n const memoisedOptions = useDeepEqualMemo(_options)\n\n const { enabledScopes } = useHotkeysContext()\n const proxy = useBoundHotkeysProxy()\n\n useSafeLayoutEffect(() => {\n if (memoisedOptions?.enabled === false || !isScopeActive(enabledScopes, memoisedOptions?.scopes)) {\n return\n }\n\n const listener = (e: KeyboardEvent) => {\n if (isKeyboardEventTriggeredByInput(e) && !isHotkeyEnabledOnTag(e, memoisedOptions?.enableOnFormTags)) {\n return\n }\n\n // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE\n // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.\n\n if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {\n stopPropagation(e)\n\n return\n }\n\n if (((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable)) {\n return\n }\n\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => {\n const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)\n\n if (isHotkeyMatchingKeyboardEvent(e, hotkey, pressedDownKeys) || hotkey.keys?.includes('*')) {\n maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)\n\n if (!isHotkeyEnabled(e, hotkey, memoisedOptions?.enabled)) {\n stopPropagation(e)\n\n return\n }\n\n cb(e, hotkey)\n }\n })\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n pressedDownKeys.add(event.key.toLowerCase())\n\n if ((memoisedOptions?.keydown === undefined && memoisedOptions?.keyup !== true) || memoisedOptions?.keydown) {\n listener(event)\n }\n }\n\n const handleKeyUp = (event: KeyboardEvent) => {\n if (event.key.toLowerCase() !== 'meta') {\n pressedDownKeys.delete(event.key.toLowerCase())\n } else {\n // On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.\n pressedDownKeys.clear()\n }\n\n if (memoisedOptions?.keyup) {\n listener(event)\n }\n }\n\n // @ts-ignore\n (ref.current || document).addEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).addEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n\n return () => {\n // @ts-ignore\n (ref.current || document).removeEventListener('keyup', handleKeyUp);\n // @ts-ignore\n (ref.current || document).removeEventListener('keydown', handleKeyDown)\n\n if (proxy) {\n parseKeysHookInput(keys, memoisedOptions?.splitKey).forEach((key) => proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey)))\n }\n }\n }, [keys, cb, memoisedOptions, enabledScopes])\n\n return ref\n}\n","import { Hotkey } from './types'\nimport { parseHotkey } from './parseHotkeys'\nimport deepEqual from './deepEqual'\n\nconst currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()\n\nexport function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean {\n const hotkeyArray = Array.isArray(key) ? key : key.split(splitKey)\n\n return hotkeyArray.every((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (deepEqual(parsedHotkey, pressedHotkey)) {\n return true\n }\n }\n })\n}\n\nexport function pushToCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach(hotkey => currentlyPressedKeys.add(parseHotkey(hotkey)))\n}\n\nexport function removeFromCurrentlyPressedKeys(key: string | string[]): void {\n const hotkeyArray = Array.isArray(key) ? key : [key]\n\n hotkeyArray.forEach((hotkey) => {\n const parsedHotkey = parseHotkey(hotkey)\n\n for (const pressedHotkey of currentlyPressedKeys) {\n if (pressedHotkey.keys?.every((key) => parsedHotkey.keys?.includes(key))) {\n currentlyPressedKeys.delete(pressedHotkey)\n }\n }\n })\n}\n\n(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n document.addEventListener('keydown', e => {\n pushToCurrentlyPressedKeys(e.key)\n })\n\n document.addEventListener('keyup', e => {\n removeFromCurrentlyPressedKeys(e.key)\n })\n })\n }\n})()\n"],"names":["reservedModifierKeywords","mappedKeys","esc","left","up","right","down","parseKeysHookInput","keys","splitKey","split","parseHotkey","hotkey","combinationKey","toLocaleLowerCase","map","k","trim","modifiers","alt","includes","ctrl","shift","meta","mod","singleCharKeys","filter","maybePreventDefault","e","preventDefault","isHotkeyEnabled","enabled","undefined","isKeyboardEventTriggeredByInput","ev","isHotkeyEnabledOnTag","enabledOnTags","target","targetTagName","tagName","Array","Boolean","some","tag","toLowerCase","isScopeActive","activeScopes","scopes","length","console","warn","scope","isHotkeyMatchingKeyboardEvent","pressedDownKeys","altKey","ctrlKey","metaKey","shiftKey","pressedKeyUppercase","key","code","keyCode","replace","pressedKey","every","has","BoundHotkeysProxyProvider","createContext","useBoundHotkeysProxy","useContext","BoundHotkeysProxyProviderProvider","addHotkey","removeHotkey","children","_jsx","HotkeysContext","hotkeys","enabledScopes","toggleScope","enableScope","disableScope","useHotkeysContext","HotkeysProvider","initiallyActiveScopes","useState","internalActiveScopes","setInternalActiveScopes","boundHotkeys","setBoundHotkeys","isAllActive","useMemo","from","Set","s","addBoundHotkey","removeBoundHotkey","h","deepEqual","x","y","Object","reduce","isEqual","useDeepEqualMemo","value","ref","useRef","current","stopPropagation","stopImmediatePropagation","useSafeLayoutEffect","window","useLayoutEffect","useEffect","useHotkeys","callback","options","dependencies","_options","_deps","cb","useCallback","memoisedOptions","proxy","listener","enableOnFormTags","document","activeElement","contains","isContentEditable","enableOnContentEditable","forEach","handleKeyDown","event","add","keydown","keyup","handleKeyUp","clear","addEventListener","removeEventListener","currentlyPressedKeys","isHotkeyPressed","hotkeyArray","isArray","parsedHotkey","pressedHotkey","pushToCurrentlyPressedKeys","removeFromCurrentlyPressedKeys"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,wBAAwB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;AAExE,IAAMC,UAAU,GAA2B;EACzCC,GAAG,EAAE,QAAQ;EACb,UAAQ,OAAO;EACfC,IAAI,EAAE,WAAW;EACjBC,EAAE,EAAE,SAAS;EACbC,KAAK,EAAE,YAAY;EACnBC,IAAI,EAAE;CACP;SAEeC,kBAAkB,CAACC,IAAU,EAAEC;MAAAA;IAAAA,WAAmB,GAAG;;EACnE,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI,CAACE,KAAK,CAACD,QAAQ,CAAC;;EAG7B,OAAOD,IAAI;AACb;SAEgBG,WAAW,CAACC,MAAc,EAAEC;MAAAA;IAAAA,iBAAyB,GAAG;;EACtE,IAAML,IAAI,GAAGI,MAAM,CAChBE,iBAAiB,EAAE,CACnBJ,KAAK,CAACG,cAAc,CAAC,CACrBE,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIA,CAAC,CAACC,IAAI,EAAE;IAAC,CAClBF,GAAG,CAAC,UAAAC,CAAC;IAAA,OAAIf,UAAU,CAACe,CAAC,CAAC,IAAIA,CAAC;IAAC;EAE/B,IAAME,SAAS,GAAsB;IACnCC,GAAG,EAAEX,IAAI,CAACY,QAAQ,CAAC,KAAK,CAAC;IACzBC,IAAI,EAAEb,IAAI,CAACY,QAAQ,CAAC,MAAM,CAAC;IAC3BE,KAAK,EAAEd,IAA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AG,CAAC;OAClC,CAAC;MAEFmE,QAAQ,CAACa,gBAAgB,CAAC,OAAO,EAAE,UAAA/G,CAAC;QAClCwH,8BAA8B,CAACxH,CAAC,CAAC+B,GAAG,CAAC;OACtC,CAAC;KACH,CAAC;;AAEN,CAAC,GAAG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hotkeys-hook",
3
- "version": "4.0.4-4",
3
+ "version": "4.0.4",
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",
@@ -54,7 +54,6 @@
54
54
  "@testing-library/react-hooks": "8.0.1",
55
55
  "@testing-library/user-event": "14.4.3",
56
56
  "@types/jest": "29.2.2",
57
- "@types/lodash.isequal": "4.5.6",
58
57
  "@types/react": "18.0.15",
59
58
  "@types/react-dom": "18.0.6",
60
59
  "eslint-plugin-prettier": "4.2.1",
@@ -68,9 +67,6 @@
68
67
  "tslib": "2.4.0",
69
68
  "typescript": "4.7.4"
70
69
  },
71
- "dependencies": {
72
- "lodash.isequal": "4.5.0"
73
- },
74
70
  "peerDependencies": {
75
71
  "react": ">=16.8.1",
76
72
  "react-dom": ">=16.8.1"
@@ -0,0 +1,9 @@
1
+ export default function deepEqual(x: any, y: any): boolean {
2
+ //@ts-ignore
3
+ return (x && y && typeof x === 'object' && typeof y === 'object')
4
+ //@ts-ignore
5
+ ? (Object.keys(x).length === Object.keys(y).length) && Object.keys(x).reduce(function(isEqual, key) {
6
+ return isEqual && deepEqual(x[key], y[key])
7
+ }, true)
8
+ : (x === y)
9
+ }
@@ -1,6 +1,6 @@
1
1
  import { Hotkey } from './types'
2
2
  import { parseHotkey } from './parseHotkeys'
3
- import isEqual from 'lodash.isEqual'
3
+ import deepEqual from './deepEqual'
4
4
 
5
5
  const currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>()
6
6
 
@@ -11,7 +11,7 @@ export function isHotkeyPressed(key: string | string[], splitKey: string = ','):
11
11
  const parsedHotkey = parseHotkey(hotkey)
12
12
 
13
13
  for (const pressedHotkey of currentlyPressedKeys) {
14
- if (isEqual(parsedHotkey, pressedHotkey)) {
14
+ if (deepEqual(parsedHotkey, pressedHotkey)) {
15
15
  return true
16
16
  }
17
17
  }
@@ -1,10 +1,10 @@
1
1
  import { useRef } from 'react'
2
- import isEqual from 'lodash.isEqual'
2
+ import deepEqual from './deepEqual'
3
3
 
4
4
  export default function useDeepEqualMemo<T>(value: T) {
5
5
  const ref = useRef<T | undefined>(undefined)
6
6
 
7
- if (!isEqual(ref.current, value)) {
7
+ if (!deepEqual(ref.current, value)) {
8
8
  ref.current = value
9
9
  }
10
10