react-hotkeys-hook 4.0.4-1 → 4.0.4-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BoundHotkeysProxyProvider.d.ts +14 -14
- package/dist/HotkeysProvider.d.ts +16 -16
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -0
- package/dist/isHotkeyPressed.d.ts +3 -3
- package/dist/parseHotkeys.d.ts +3 -3
- package/dist/react-hotkeys-hook.cjs.development.js +427 -0
- package/dist/react-hotkeys-hook.cjs.development.js.map +1 -0
- package/dist/react-hotkeys-hook.cjs.production.min.js +2 -0
- package/dist/react-hotkeys-hook.cjs.production.min.js.map +1 -0
- package/dist/react-hotkeys-hook.esm.js +420 -0
- package/dist/react-hotkeys-hook.esm.js.map +1 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/types.d.ts +32 -32
- package/dist/useDeepEqualMemo.d.ts +1 -1
- package/dist/useHotkeys.d.ts +3 -2
- package/dist/validators.d.ts +7 -7
- package/package.json +5 -5
- package/src/useHotkeys.ts +4 -4
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -7
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hotkeys-hook",
|
|
3
|
-
"version": "4.0.4-
|
|
3
|
+
"version": "4.0.4-2",
|
|
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",
|
|
7
|
-
"main": "dist/index.
|
|
8
|
-
"module": "dist/
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/react-hotkeys-hook.esm.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "
|
|
28
|
+
"build": "tsdx build",
|
|
29
29
|
"test": "jest",
|
|
30
30
|
"publish": "np"
|
|
31
31
|
},
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"@types/lodash": "^4.14.182",
|
|
58
58
|
"@types/react": "18.0.15",
|
|
59
59
|
"@types/react-dom": "18.0.6",
|
|
60
|
-
"esbuild": "0.15.13",
|
|
61
60
|
"eslint-plugin-prettier": "4.2.1",
|
|
62
61
|
"jest": "29.2.2",
|
|
63
62
|
"jest-environment-jsdom": "29.2.2",
|
|
@@ -65,6 +64,7 @@
|
|
|
65
64
|
"react": "18.2.0",
|
|
66
65
|
"react-dom": "18.2.0",
|
|
67
66
|
"react-test-renderer": "18.2.0",
|
|
67
|
+
"tsdx": "0.14.1",
|
|
68
68
|
"tslib": "2.4.0",
|
|
69
69
|
"typescript": "4.7.4"
|
|
70
70
|
},
|
package/src/useHotkeys.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HotkeyCallback, Keys, OptionsOrDependencyArray, RefType } from './types'
|
|
2
|
-
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'
|
|
1
|
+
import { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'
|
|
2
|
+
import { DependencyList, useCallback, useEffect, useLayoutEffect, useRef } from 'react'
|
|
3
3
|
import { parseHotkey, parseKeysHookInput } from './parseHotkeys'
|
|
4
4
|
import {
|
|
5
5
|
isHotkeyEnabled,
|
|
@@ -30,8 +30,8 @@ export default function useHotkeys<T extends HTMLElement>(
|
|
|
30
30
|
const ref = useRef<RefType<T>>(null)
|
|
31
31
|
const { current: pressedDownKeys } = useRef<Set<string>>(new Set())
|
|
32
32
|
|
|
33
|
-
const _options = !(options instanceof Array) ? options : !(dependencies instanceof Array) ? dependencies : undefined
|
|
34
|
-
const _deps = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []
|
|
33
|
+
const _options: Options | undefined = !(options instanceof Array) ? (options as Options) : !(dependencies instanceof Array) ? (dependencies as Options) : undefined
|
|
34
|
+
const _deps: DependencyList = options instanceof Array ? options : dependencies instanceof Array ? dependencies : []
|
|
35
35
|
|
|
36
36
|
const cb = useCallback(callback, [..._deps])
|
|
37
37
|
const memoisedOptions = useDeepEqualMemo(_options)
|
package/dist/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var J=Object.create;var h=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var Y=(e,o)=>{for(var t in o)h(e,t,{get:o[t],enumerable:!0})},L=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of V(o))!X.call(e,r)&&r!==t&&h(e,r,{get:()=>o[r],enumerable:!(s=Q(o,r))||s.enumerable});return e};var T=(e,o,t)=>(t=e!=null?J(W(e)):{},L(o||!e||!e.__esModule?h(t,"default",{value:e,enumerable:!0}):t,e)),Z=e=>L(h({},"__esModule",{value:!0}),e);var ne={};Y(ne,{HotkeysProvider:()=>F,isHotkeyPressed:()=>G,useHotkeys:()=>S,useHotkeysContext:()=>K});module.exports=Z(ne);var p=require("react");var $=["ctrl","shift","alt","meta","mod"],ee={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown"};function E(e,o=","){return typeof e=="string"?e.split(o):e}function l(e,o="+"){let t=e.toLocaleLowerCase().split(o).map(y=>y.trim()).map(y=>ee[y]||y),s={alt:t.includes("alt"),ctrl:t.includes("ctrl"),shift:t.includes("shift"),meta:t.includes("meta"),mod:t.includes("mod")},r=t.filter(y=>!$.includes(y));return{...s,keys:r}}function B(e,o,t){(typeof t=="function"&&t(e,o)||t===!0)&&e.preventDefault()}function M(e,o,t){return typeof t=="function"?t(e,o):t===!0||t===void 0}function D(e){return w(e,["input","textarea","select"])}function w({target:e},o=!1){let t=e&&e.tagName;return o instanceof Array?Boolean(t&&o&&o.some(s=>s.toLowerCase()===t.toLowerCase())):Boolean(t&&o&&o===!0)}function O(e,o){return e.length===0&&o?(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>'),!0):o?e.some(t=>o.includes(t))||e.includes("*"):!0}var R=(e,o,t)=>{let{alt:s,ctrl:r,meta:y,mod:g,shift:H,keys:d}=o,{altKey:i,ctrlKey:m,metaKey:c,shiftKey:a,key:u,code:v}=e,n=v.toLowerCase().replace("key",""),b=u.toLowerCase();if(i!==s&&b!=="alt"||a!==H&&b!=="shift")return!1;if(g){if(!c&&!m)return!1}else if(c!==y&&n!=="meta"||m!==r&&n!=="ctrl")return!1;return d&&d.length===1&&(d.includes(b)||d.includes(n))?!0:d?d.every(k=>t.has(k)):!d};var f=require("react");var x=require("react"),I=(0,x.createContext)(void 0),N=()=>(0,x.useContext)(I);function A({addHotkey:e,removeHotkey:o,children:t}){return<I.Provider value={{addHotkey:e,removeHotkey:o}}>{t}</I.Provider>}var q=(0,f.createContext)({hotkeys:[],enabledScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),K=()=>(0,f.useContext)(q),F=({initiallyActiveScopes:e=["*"],children:o})=>{let[t,s]=(0,f.useState)(e?.length>0?e:["*"]),[r,y]=(0,f.useState)([]),g=(0,f.useMemo)(()=>t.includes("*"),[t]),H=a=>{s(g?[a]:Array.from(new Set([...t,a])))},d=a=>{let u=t.filter(v=>v!==a);u.length===0?s(["*"]):s(u)},i=a=>{t.includes(a)?d(a):H(a)},m=a=>{y([...r,a])},c=a=>{y(r.filter(u=>u.keys!==a.keys))};return<q.Provider value={{enabledScopes:t,hotkeys:r,enableScope:H,disableScope:d,toggleScope:i}}><A addHotkey={m}removeHotkey={c}>{o}</A></q.Provider>};var U=require("react"),_=T(require("lodash/isEqual"));function C(e){let o=(0,U.useRef)(void 0);return(0,_.default)(o.current,e)||(o.current=e),o.current}var j=e=>{e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},te=typeof window<"u"?p.useLayoutEffect:p.useEffect;function S(e,o,t,s){let r=(0,p.useRef)(null),{current:y}=(0,p.useRef)(new Set),g=t instanceof Array?s instanceof Array?void 0:s:t,H=t instanceof Array?t:s instanceof Array?s:[],d=(0,p.useCallback)(o,[...H]),i=C(g),{enabledScopes:m}=K(),c=N();return te(()=>{if(i?.enabled===!1||!O(m,i?.scopes))return;let a=n=>{if(!(D(n)&&!w(n,i?.enableOnFormTags))){if(r.current!==null&&document.activeElement!==r.current&&!r.current.contains(document.activeElement)){j(n);return}n.target?.isContentEditable&&!i?.enableOnContentEditable||E(e,i?.splitKey).forEach(b=>{let k=l(b,i?.combinationKey);if(R(n,k,y)||k.keys?.includes("*")){if(B(n,k,i?.preventDefault),!M(n,k,i?.enabled)){j(n);return}d(n,k)}})}},u=n=>{y.add(n.key.toLowerCase()),(i?.keydown===void 0&&i?.keyup!==!0||i?.keydown)&&a(n)},v=n=>{n.key.toLowerCase()!=="meta"?y.delete(n.key.toLowerCase()):y.clear(),i?.keyup&&a(n)};return(r.current||document).addEventListener("keyup",v),(r.current||document).addEventListener("keydown",u),c&&E(e,i?.splitKey).forEach(n=>c.addHotkey(l(n,i?.combinationKey))),()=>{(r.current||document).removeEventListener("keyup",v),(r.current||document).removeEventListener("keydown",u),c&&E(e,i?.splitKey).forEach(n=>c.removeHotkey(l(n,i?.combinationKey)))}},[e,d,i,m]),r}var z=T(require("lodash/isEqual")),P=new Set;function G(e,o=","){return(Array.isArray(e)?e:e.split(o)).every(s=>{let r=l(s);for(let y of P)if((0,z.default)(r,y))return!0})}function oe(e){(Array.isArray(e)?e:[e]).forEach(t=>P.add(l(t)))}function re(e){(Array.isArray(e)?e:[e]).forEach(t=>{let s=l(t);for(let r of P)r.keys?.every(y=>s.keys?.includes(y))&&P.delete(r)})}typeof window<"u"&&window.addEventListener("DOMContentLoaded",()=>{document.addEventListener("keydown",e=>{oe(e.key)}),document.addEventListener("keyup",e=>{re(e.key)})});
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../src/useHotkeys.ts", "../src/parseHotkeys.ts", "../src/validators.ts", "../src/HotkeysProvider.tsx", "../src/BoundHotkeysProxyProvider.tsx", "../src/useDeepEqualMemo.ts", "../src/isHotkeyPressed.ts"],
|
|
4
|
-
"sourcesContent": ["import useHotkeys from './useHotkeys'\nimport type { Options } from './types'\nimport { HotkeysProvider, useHotkeysContext } from './HotkeysProvider'\nimport { isHotkeyPressed } from './isHotkeyPressed'\n\nexport {\n useHotkeys,\n useHotkeysContext,\n isHotkeyPressed,\n HotkeysProvider,\n Options,\n}\n", "import { HotkeyCallback, Keys, OptionsOrDependencyArray, RefType } from './types'\nimport { 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 instanceof Array) ? options : !(dependencies instanceof Array) ? dependencies : undefined\n const _deps = 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, 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 { 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 { 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 { 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 { 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"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,qBAAAE,EAAA,oBAAAC,EAAA,eAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAN,ICCA,IAAAO,EAAgE,iBCChE,IAAMC,EAA2B,CAAC,OAAQ,QAAS,MAAO,OAAQ,KAAK,EAEjEC,GAAqC,CACzC,IAAK,SACL,OAAQ,QACR,KAAM,YACN,GAAI,UACJ,MAAO,aACP,KAAM,WACR,EAEO,SAASC,EAAmBC,EAAYC,EAAmB,IAAe,CAC/E,OAAI,OAAOD,GAAS,SACX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,EAAcE,CAAa,EACrC,MAAO,EAGb,CAAC,CACH,CAEO,SAASE,GAA2BP,EAA8B,EACnD,MAAM,QAAQA,CAAG,EAAIA,EAAM,CAACA,CAAG,GAEvC,QAAQE,GAAUJ,EAAqB,IAAIM,EAAYF,CAAM,CAAC,CAAC,CAC7E,CAEO,SAASM,GAA+BR,EAA8B,EACvD,MAAM,QAAQA,CAAG,EAAIA,EAAM,CAACA,CAAG,GAEvC,QAASE,GAAW,CAC9B,IAAMC,EAAeC,EAAYF,CAAM,EAEvC,QAAWG,KAAiBP,EACtBO,EAAc,MAAM,MAAOL,GAAQG,EAAa,MAAM,SAASH,CAAG,CAAC,GACrEF,EAAqB,OAAOO,CAAa,CAG/C,CAAC,CACH,CAGM,OAAO,OAAW,KACpB,OAAO,iBAAiB,mBAAoB,IAAM,CAChD,SAAS,iBAAiB,UAAW,GAAK,CACxCE,GAA2B,EAAE,GAAG,CAClC,CAAC,EAED,SAAS,iBAAiB,QAAS,GAAK,CACtCC,GAA+B,EAAE,GAAG,CACtC,CAAC,CACH,CAAC",
|
|
6
|
-
"names": ["src_exports", "__export", "HotkeysProvider", "isHotkeyPressed", "useHotkeys", "useHotkeysContext", "__toCommonJS", "import_react", "reservedModifierKeywords", "mappedKeys", "parseKeysHookInput", "keys", "splitKey", "parseHotkey", "hotkey", "combinationKey", "k", "modifiers", "singleCharKeys", "maybePreventDefault", "hotkey", "preventDefault", "isHotkeyEnabled", "enabled", "isKeyboardEventTriggeredByInput", "ev", "isHotkeyEnabledOnTag", "target", "enabledOnTags", "targetTagName", "tag", "isScopeActive", "activeScopes", "scopes", "scope", "isHotkeyMatchingKeyboardEvent", "pressedDownKeys", "alt", "ctrl", "meta", "mod", "shift", "keys", "altKey", "ctrlKey", "metaKey", "shiftKey", "pressedKeyUppercase", "code", "keyCode", "pressedKey", "key", "import_react", "import_react", "BoundHotkeysProxyProvider", "useBoundHotkeysProxy", "BoundHotkeysProxyProviderProvider", "addHotkey", "removeHotkey", "children", "HotkeysContext", "useHotkeysContext", "HotkeysProvider", "initiallyActiveScopes", "children", "internalActiveScopes", "setInternalActiveScopes", "boundHotkeys", "setBoundHotkeys", "isAllActive", "enableScope", "scope", "disableScope", "scopes", "s", "toggleScope", "addBoundHotkey", "hotkey", "removeBoundHotkey", "h", "BoundHotkeysProxyProviderProvider", "import_react", "import_isEqual", "useDeepEqualMemo", "value", "ref", "isEqual", "stopPropagation", "useSafeLayoutEffect", "useHotkeys", "keys", "callback", "options", "dependencies", "ref", "pressedDownKeys", "_options", "_deps", "cb", "memoisedOptions", "useDeepEqualMemo", "enabledScopes", "useHotkeysContext", "proxy", "useBoundHotkeysProxy", "isScopeActive", "listener", "e", "isKeyboardEventTriggeredByInput", "isHotkeyEnabledOnTag", "parseKeysHookInput", "key", "hotkey", "parseHotkey", "isHotkeyMatchingKeyboardEvent", "maybePreventDefault", "isHotkeyEnabled", "handleKeyDown", "event", "handleKeyUp", "import_isEqual", "currentlyPressedKeys", "isHotkeyPressed", "key", "splitKey", "hotkey", "parsedHotkey", "parseHotkey", "pressedHotkey", "isEqual", "pushToCurrentlyPressedKeys", "removeFromCurrentlyPressedKeys"]
|
|
7
|
-
}
|
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{useCallback as Q,useEffect as V,useLayoutEffect as W,useRef as D}from"react";var I=["ctrl","shift","alt","meta","mod"],N={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown"};function g(e,o=","){return typeof e=="string"?e.split(o):e}function f(e,o="+"){let t=e.toLocaleLowerCase().split(o).map(i=>i.trim()).map(i=>N[i]||i),y={alt:t.includes("alt"),ctrl:t.includes("ctrl"),shift:t.includes("shift"),meta:t.includes("meta"),mod:t.includes("mod")},n=t.filter(i=>!I.includes(i));return{...y,keys:n}}function P(e,o,t){(typeof t=="function"&&t(e,o)||t===!0)&&e.preventDefault()}function w(e,o,t){return typeof t=="function"?t(e,o):t===!0||t===void 0}function A(e){return h(e,["input","textarea","select"])}function h({target:e},o=!1){let t=e&&e.tagName;return o instanceof Array?Boolean(t&&o&&o.some(y=>y.toLowerCase()===t.toLowerCase())):Boolean(t&&o&&o===!0)}function C(e,o){return e.length===0&&o?(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>'),!0):o?e.some(t=>o.includes(t))||e.includes("*"):!0}var S=(e,o,t)=>{let{alt:y,ctrl:n,meta:i,mod:H,shift:m,keys:d}=o,{altKey:s,ctrlKey:p,metaKey:c,shiftKey:a,key:u,code:k}=e,r=k.toLowerCase().replace("key",""),v=u.toLowerCase();if(s!==y&&v!=="alt"||a!==m&&v!=="shift")return!1;if(H){if(!c&&!p)return!1}else if(c!==i&&r!=="meta"||p!==n&&r!=="ctrl")return!1;return d&&d.length===1&&(d.includes(v)||d.includes(r))?!0:d?d.every(l=>t.has(l)):!d};import{createContext as U,useMemo as _,useState as B,useContext as j}from"react";import{createContext as q,useContext as F}from"react";var L=q(void 0),T=()=>F(L);function E({addHotkey:e,removeHotkey:o,children:t}){return<L.Provider value={{addHotkey:e,removeHotkey:o}}>{t}</L.Provider>}var M=U({hotkeys:[],enabledScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),x=()=>j(M),z=({initiallyActiveScopes:e=["*"],children:o})=>{let[t,y]=B(e?.length>0?e:["*"]),[n,i]=B([]),H=_(()=>t.includes("*"),[t]),m=a=>{y(H?[a]:Array.from(new Set([...t,a])))},d=a=>{let u=t.filter(k=>k!==a);u.length===0?y(["*"]):y(u)},s=a=>{t.includes(a)?d(a):m(a)},p=a=>{i([...n,a])},c=a=>{i(n.filter(u=>u.keys!==a.keys))};return<M.Provider value={{enabledScopes:t,hotkeys:n,enableScope:m,disableScope:d,toggleScope:s}}><E addHotkey={p}removeHotkey={c}>{o}</E></M.Provider>};import{useRef as G}from"react";import J from"lodash/isEqual";function K(e){let o=G(void 0);return J(o.current,e)||(o.current=e),o.current}var O=e=>{e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},X=typeof window<"u"?W:V;function R(e,o,t,y){let n=D(null),{current:i}=D(new Set),H=t instanceof Array?y instanceof Array?void 0:y:t,m=t instanceof Array?t:y instanceof Array?y:[],d=Q(o,[...m]),s=K(H),{enabledScopes:p}=x(),c=T();return X(()=>{if(s?.enabled===!1||!C(p,s?.scopes))return;let a=r=>{if(!(A(r)&&!h(r,s?.enableOnFormTags))){if(n.current!==null&&document.activeElement!==n.current&&!n.current.contains(document.activeElement)){O(r);return}r.target?.isContentEditable&&!s?.enableOnContentEditable||g(e,s?.splitKey).forEach(v=>{let l=f(v,s?.combinationKey);if(S(r,l,i)||l.keys?.includes("*")){if(P(r,l,s?.preventDefault),!w(r,l,s?.enabled)){O(r);return}d(r,l)}})}},u=r=>{i.add(r.key.toLowerCase()),(s?.keydown===void 0&&s?.keyup!==!0||s?.keydown)&&a(r)},k=r=>{r.key.toLowerCase()!=="meta"?i.delete(r.key.toLowerCase()):i.clear(),s?.keyup&&a(r)};return(n.current||document).addEventListener("keyup",k),(n.current||document).addEventListener("keydown",u),c&&g(e,s?.splitKey).forEach(r=>c.addHotkey(f(r,s?.combinationKey))),()=>{(n.current||document).removeEventListener("keyup",k),(n.current||document).removeEventListener("keydown",u),c&&g(e,s?.splitKey).forEach(r=>c.removeHotkey(f(r,s?.combinationKey)))}},[e,d,s,p]),n}import Y from"lodash/isEqual";var b=new Set;function Z(e,o=","){return(Array.isArray(e)?e:e.split(o)).every(y=>{let n=f(y);for(let i of b)if(Y(n,i))return!0})}function $(e){(Array.isArray(e)?e:[e]).forEach(t=>b.add(f(t)))}function ee(e){(Array.isArray(e)?e:[e]).forEach(t=>{let y=f(t);for(let n of b)n.keys?.every(i=>y.keys?.includes(i))&&b.delete(n)})}typeof window<"u"&&window.addEventListener("DOMContentLoaded",()=>{document.addEventListener("keydown",e=>{$(e.key)}),document.addEventListener("keyup",e=>{ee(e.key)})});export{z as HotkeysProvider,Z as isHotkeyPressed,R as useHotkeys,x as useHotkeysContext};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/useHotkeys.ts", "../src/parseHotkeys.ts", "../src/validators.ts", "../src/HotkeysProvider.tsx", "../src/BoundHotkeysProxyProvider.tsx", "../src/useDeepEqualMemo.ts", "../src/isHotkeyPressed.ts"],
|
|
4
|
-
"sourcesContent": ["import { HotkeyCallback, Keys, OptionsOrDependencyArray, RefType } from './types'\nimport { 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 instanceof Array) ? options : !(dependencies instanceof Array) ? dependencies : undefined\n const _deps = 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, 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 { 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 { 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 { 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 { 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"],
|
|
5
|
-
"mappings": "AACA,OAAS,eAAAA,EAAa,aAAAC,EAAW,mBAAAC,EAAiB,UAAAC,MAAc,QCChE,IAAMC,EAA2B,CAAC,OAAQ,QAAS,MAAO,OAAQ,KAAK,EAEjEC,EAAqC,CACzC,IAAK,SACL,OAAQ,QACR,KAAM,YACN,GAAI,UACJ,MAAO,aACP,KAAM,WACR,EAEO,SAASC,EAAmBC,EAAYC,EAAmB,IAAe,CAC/E,OAAI,OAAOD,GAAS,SACXA,EAAK,MAAMC,CAAQ,EAGrBD,CACT,CAEO,SAASE,EAAYC,EAAgBC,EAAyB,IAAa,CAChF,IAAMJ,EAAOG,EACV,kBAAkB,EAClB,MAAMC,CAAc,EACpB,IAAIC,GAAKA,EAAE,KAAK,CAAC,EACjB,IAAIA,GAAKP,EAAWO,IAAMA,CAAC,EAExBC,EAA+B,CACnC,IAAKN,EAAK,SAAS,KAAK,EACxB,KAAMA,EAAK,SAAS,MAAM,EAC1B,M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BP,EAA8B,EACvD,MAAM,QAAQA,CAAG,EAAIA,EAAM,CAACA,CAAG,GAEvC,QAASE,GAAW,CAC9B,IAAMC,EAAeC,EAAYF,CAAM,EAEvC,QAAWG,KAAiBP,EACtBO,EAAc,MAAM,MAAOL,GAAQG,EAAa,MAAM,SAASH,CAAG,CAAC,GACrEF,EAAqB,OAAOO,CAAa,CAG/C,CAAC,CACH,CAGM,OAAO,OAAW,KACpB,OAAO,iBAAiB,mBAAoB,IAAM,CAChD,SAAS,iBAAiB,UAAW,GAAK,CACxCC,EAA2B,EAAE,GAAG,CAClC,CAAC,EAED,SAAS,iBAAiB,QAAS,GAAK,CACtCC,GAA+B,EAAE,GAAG,CACtC,CAAC,CACH,CAAC",
|
|
6
|
-
"names": ["useCallback", "useEffect", "useLayoutEffect", "useRef", "reservedModifierKeywords", "mappedKeys", "parseKeysHookInput", "keys", "splitKey", "parseHotkey", "hotkey", "combinationKey", "k", "modifiers", "singleCharKeys", "maybePreventDefault", "hotkey", "preventDefault", "isHotkeyEnabled", "enabled", "isKeyboardEventTriggeredByInput", "ev", "isHotkeyEnabledOnTag", "target", "enabledOnTags", "targetTagName", "tag", "isScopeActive", "activeScopes", "scopes", "scope", "isHotkeyMatchingKeyboardEvent", "pressedDownKeys", "alt", "ctrl", "meta", "mod", "shift", "keys", "altKey", "ctrlKey", "metaKey", "shiftKey", "pressedKeyUppercase", "code", "keyCode", "pressedKey", "key", "createContext", "useMemo", "useState", "useContext", "createContext", "useContext", "BoundHotkeysProxyProvider", "useBoundHotkeysProxy", "BoundHotkeysProxyProviderProvider", "addHotkey", "removeHotkey", "children", "HotkeysContext", "createContext", "useHotkeysContext", "useContext", "HotkeysProvider", "initiallyActiveScopes", "children", "internalActiveScopes", "setInternalActiveScopes", "useState", "boundHotkeys", "setBoundHotkeys", "isAllActive", "useMemo", "enableScope", "scope", "disableScope", "scopes", "s", "toggleScope", "addBoundHotkey", "hotkey", "removeBoundHotkey", "h", "BoundHotkeysProxyProviderProvider", "useRef", "isEqual", "useDeepEqualMemo", "value", "ref", "stopPropagation", "useSafeLayoutEffect", "useLayoutEffect", "useEffect", "useHotkeys", "keys", "callback", "options", "dependencies", "ref", "useRef", "pressedDownKeys", "_options", "_deps", "cb", "useCallback", "memoisedOptions", "useDeepEqualMemo", "enabledScopes", "useHotkeysContext", "proxy", "useBoundHotkeysProxy", "isScopeActive", "listener", "e", "isKeyboardEventTriggeredByInput", "isHotkeyEnabledOnTag", "parseKeysHookInput", "key", "hotkey", "parseHotkey", "isHotkeyMatchingKeyboardEvent", "maybePreventDefault", "isHotkeyEnabled", "handleKeyDown", "event", "handleKeyUp", "isEqual", "currentlyPressedKeys", "isHotkeyPressed", "key", "splitKey", "hotkey", "parsedHotkey", "parseHotkey", "pressedHotkey", "pushToCurrentlyPressedKeys", "removeFromCurrentlyPressedKeys"]
|
|
7
|
-
}
|