@tanstack/react-hotkeys 0.4.2 → 0.5.1
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/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/useHotkey.cjs +2 -7
- package/dist/useHotkey.cjs.map +1 -1
- package/dist/useHotkey.js +1 -6
- package/dist/useHotkey.js.map +1 -1
- package/dist/useHotkeySequence.cjs +17 -14
- package/dist/useHotkeySequence.cjs.map +1 -1
- package/dist/useHotkeySequence.d.cts +10 -0
- package/dist/useHotkeySequence.d.ts +10 -0
- package/dist/useHotkeySequence.js +16 -13
- package/dist/useHotkeySequence.js.map +1 -1
- package/dist/useHotkeys.cjs +138 -0
- package/dist/useHotkeys.cjs.map +1 -0
- package/dist/useHotkeys.d.cts +60 -0
- package/dist/useHotkeys.d.ts +60 -0
- package/dist/useHotkeys.js +137 -0
- package/dist/useHotkeys.js.map +1 -0
- package/dist/utils.cjs +12 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.js +11 -0
- package/dist/utils.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/useHotkey.ts +1 -7
- package/src/useHotkeySequence.ts +16 -10
- package/src/useHotkeys.ts +219 -0
- package/src/utils.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
3
3
|
const require_useHotkey = require('./useHotkey.cjs');
|
|
4
|
+
const require_useHotkeys = require('./useHotkeys.cjs');
|
|
4
5
|
const require_useHeldKeys = require('./useHeldKeys.cjs');
|
|
5
6
|
const require_useHeldKeyCodes = require('./useHeldKeyCodes.cjs');
|
|
6
7
|
const require_useKeyHold = require('./useKeyHold.cjs');
|
|
@@ -14,6 +15,7 @@ exports.useHeldKeys = require_useHeldKeys.useHeldKeys;
|
|
|
14
15
|
exports.useHotkey = require_useHotkey.useHotkey;
|
|
15
16
|
exports.useHotkeyRecorder = require_useHotkeyRecorder.useHotkeyRecorder;
|
|
16
17
|
exports.useHotkeySequence = require_useHotkeySequence.useHotkeySequence;
|
|
18
|
+
exports.useHotkeys = require_useHotkeys.useHotkeys;
|
|
17
19
|
exports.useHotkeysContext = require_HotkeysProvider.useHotkeysContext;
|
|
18
20
|
exports.useKeyHold = require_useKeyHold.useKeyHold;
|
|
19
21
|
var _tanstack_hotkeys = require("@tanstack/hotkeys");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { UseHotkeyOptions, useHotkey } from "./useHotkey.cjs";
|
|
2
2
|
import { UseHotkeySequenceOptions, useHotkeySequence } from "./useHotkeySequence.cjs";
|
|
3
3
|
import { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.cjs";
|
|
4
|
+
import { UseHotkeyDefinition, useHotkeys } from "./useHotkeys.cjs";
|
|
4
5
|
import { useHeldKeys } from "./useHeldKeys.cjs";
|
|
5
6
|
import { useHeldKeyCodes } from "./useHeldKeyCodes.cjs";
|
|
6
7
|
import { useKeyHold } from "./useKeyHold.cjs";
|
|
7
8
|
import { ReactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.cjs";
|
|
8
9
|
export * from "@tanstack/hotkeys";
|
|
9
|
-
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, ReactHotkeyRecorder, UseHotkeyOptions, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeysContext, useKeyHold };
|
|
10
|
+
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, ReactHotkeyRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeys, useHotkeysContext, useKeyHold };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { UseHotkeyOptions, useHotkey } from "./useHotkey.js";
|
|
2
2
|
import { UseHotkeySequenceOptions, useHotkeySequence } from "./useHotkeySequence.js";
|
|
3
3
|
import { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.js";
|
|
4
|
+
import { UseHotkeyDefinition, useHotkeys } from "./useHotkeys.js";
|
|
4
5
|
import { useHeldKeys } from "./useHeldKeys.js";
|
|
5
6
|
import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
|
|
6
7
|
import { useKeyHold } from "./useKeyHold.js";
|
|
7
8
|
import { ReactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
8
9
|
export * from "@tanstack/hotkeys";
|
|
9
|
-
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, ReactHotkeyRecorder, UseHotkeyOptions, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeysContext, useKeyHold };
|
|
10
|
+
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, ReactHotkeyRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeys, useHotkeysContext, useKeyHold };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HotkeysProvider, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
2
|
import { useHotkey } from "./useHotkey.js";
|
|
3
|
+
import { useHotkeys } from "./useHotkeys.js";
|
|
3
4
|
import { useHeldKeys } from "./useHeldKeys.js";
|
|
4
5
|
import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
|
|
5
6
|
import { useKeyHold } from "./useKeyHold.js";
|
|
@@ -8,4 +9,4 @@ import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
|
8
9
|
|
|
9
10
|
export * from "@tanstack/hotkeys"
|
|
10
11
|
|
|
11
|
-
export { HotkeysProvider, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeysContext, useKeyHold };
|
|
12
|
+
export { HotkeysProvider, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeys, useHotkeysContext, useKeyHold };
|
package/dist/useHotkey.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
3
|
+
const require_utils = require('./utils.cjs');
|
|
3
4
|
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
4
5
|
let react = require("react");
|
|
5
6
|
|
|
@@ -81,7 +82,7 @@ function useHotkey(hotkey, callback, options = {}) {
|
|
|
81
82
|
const hotkeyString = typeof hotkey === "string" ? hotkey : (0, _tanstack_hotkeys.formatHotkey)((0, _tanstack_hotkeys.rawHotkeyToParsedHotkey)(hotkey, platform));
|
|
82
83
|
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
83
84
|
(0, react.useEffect)(() => {
|
|
84
|
-
const resolvedTarget = isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
|
|
85
|
+
const resolvedTarget = require_utils.isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
|
|
85
86
|
if (!resolvedTarget) return;
|
|
86
87
|
const targetChanged = prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget;
|
|
87
88
|
const hotkeyChanged = prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString;
|
|
@@ -107,12 +108,6 @@ function useHotkey(hotkey, callback, options = {}) {
|
|
|
107
108
|
registrationRef.current.setOptions(optionsWithoutTarget);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Type guard to check if a value is a React ref-like object.
|
|
112
|
-
*/
|
|
113
|
-
function isRef(value) {
|
|
114
|
-
return value !== null && typeof value === "object" && "current" in value;
|
|
115
|
-
}
|
|
116
111
|
|
|
117
112
|
//#endregion
|
|
118
113
|
exports.useHotkey = useHotkey;
|
package/dist/useHotkey.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkey.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This hook syncs the callback and options on every render to avoid\n * stale closures. This means\n * callbacks that reference React state will always have access to\n * the latest values.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = useState(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal({ isOpen, onClose }) {\n * // enabled option is synced on every render\n * useHotkey('Escape', () => {\n * onClose()\n * }, { enabled: isOpen })\n *\n * if (!isOpen) return null\n * return <div className=\"modal\">...</div>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const editorRef = useRef<HTMLDivElement>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n *\n * return <div ref={editorRef}>...</div>\n * }\n * ```\n */\nexport function useHotkey(\n hotkey: RegisterableHotkey,\n callback: HotkeyCallback,\n options: UseHotkeyOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkey,\n ...options,\n } as UseHotkeyOptions\n\n const manager = getHotkeyManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<HotkeyRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and hotkey to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevHotkeyRef = useRef<string | null>(null)\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof hotkey === 'string'\n ? hotkey\n : (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n return\n }\n\n // Check if we need to re-register (target or hotkey changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const hotkeyChanged =\n prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString\n\n // If we have an active registration and target/hotkey changed, unregister first\n if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n // Use refs to access current values without adding them to dependencies\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n hotkeyString,\n callbackRef.current,\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevHotkeyRef.current = hotkeyString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeyString, options.enabled])\n\n // Sync callback and options on EVERY render (outside useEffect)\n // This avoids stale closures - the callback always has access to latest state\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = callback\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n
|
|
1
|
+
{"version":3,"file":"useHotkey.cjs","names":["useDefaultHotkeysOptions","isRef"],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This hook syncs the callback and options on every render to avoid\n * stale closures. This means\n * callbacks that reference React state will always have access to\n * the latest values.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = useState(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal({ isOpen, onClose }) {\n * // enabled option is synced on every render\n * useHotkey('Escape', () => {\n * onClose()\n * }, { enabled: isOpen })\n *\n * if (!isOpen) return null\n * return <div className=\"modal\">...</div>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const editorRef = useRef<HTMLDivElement>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n *\n * return <div ref={editorRef}>...</div>\n * }\n * ```\n */\nexport function useHotkey(\n hotkey: RegisterableHotkey,\n callback: HotkeyCallback,\n options: UseHotkeyOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkey,\n ...options,\n } as UseHotkeyOptions\n\n const manager = getHotkeyManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<HotkeyRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and hotkey to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevHotkeyRef = useRef<string | null>(null)\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof hotkey === 'string'\n ? hotkey\n : (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n return\n }\n\n // Check if we need to re-register (target or hotkey changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const hotkeyChanged =\n prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString\n\n // If we have an active registration and target/hotkey changed, unregister first\n if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n // Use refs to access current values without adding them to dependencies\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n hotkeyString,\n callbackRef.current,\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevHotkeyRef.current = hotkeyString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeyString, options.enabled])\n\n // Sync callback and options on EVERY render (outside useEffect)\n // This avoids stale closures - the callback always has access to latest state\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = callback\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,UACd,QACA,UACA,UAA4B,EAAE,EACxB;CACN,MAAM,gBAAgB;EACpB,GAAGA,kDAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,mDAA4B;CAGlC,MAAM,oCAA0D,KAAK;CAGrE,MAAM,gCAAqB,SAAS;CACpC,MAAM,+BAAoB,cAAc;CACxC,MAAM,+BAAoB,QAAQ;AAGlC,aAAY,UAAU;AACtB,YAAW,UAAU;AACrB,YAAW,UAAU;CAGrB,MAAM,kCAA+D,KAAK;CAC1E,MAAM,kCAAsC,KAAK;CAGjD,MAAM,WAAW,cAAc,mDAA4B;CAC3D,MAAM,eACJ,OAAO,WAAW,WACd,4FACsC,QAAQ,SAAS,CAAC;CAG9D,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,4BAAgB;EAEd,MAAM,iBAAiBC,oBAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,eACH;EAIF,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;EAC9D,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;AAG9D,MAAI,gBAAgB,SAAS,aAAa,iBAAiB,gBAAgB;AACzE,mBAAgB,QAAQ,YAAY;AACpC,mBAAgB,UAAU;;AAK5B,MAAI,CAAC,gBAAgB,WAAW,CAAC,gBAAgB,QAAQ,SACvD,iBAAgB,UAAU,WAAW,QAAQ,SAC3C,cACA,YAAY,SACZ;GACE,GAAG,WAAW;GACd,QAAQ;GACT,CACF;AAIH,gBAAc,UAAU;AACxB,gBAAc,UAAU;AAGxB,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,CAAC,cAAc,QAAQ,QAAQ,CAAC;AAInC,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,WAAW;AACnC,kBAAgB,QAAQ,WAAW,qBAAqB"}
|
package/dist/useHotkey.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
|
+
import { isRef } from "./utils.js";
|
|
2
3
|
import { detectPlatform, formatHotkey, getHotkeyManager, rawHotkeyToParsedHotkey } from "@tanstack/hotkeys";
|
|
3
4
|
import { useEffect, useRef } from "react";
|
|
4
5
|
|
|
@@ -106,12 +107,6 @@ function useHotkey(hotkey, callback, options = {}) {
|
|
|
106
107
|
registrationRef.current.setOptions(optionsWithoutTarget);
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Type guard to check if a value is a React ref-like object.
|
|
111
|
-
*/
|
|
112
|
-
function isRef(value) {
|
|
113
|
-
return value !== null && typeof value === "object" && "current" in value;
|
|
114
|
-
}
|
|
115
110
|
|
|
116
111
|
//#endregion
|
|
117
112
|
export { useHotkey };
|
package/dist/useHotkey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkey.js","names":[],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This hook syncs the callback and options on every render to avoid\n * stale closures. This means\n * callbacks that reference React state will always have access to\n * the latest values.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = useState(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal({ isOpen, onClose }) {\n * // enabled option is synced on every render\n * useHotkey('Escape', () => {\n * onClose()\n * }, { enabled: isOpen })\n *\n * if (!isOpen) return null\n * return <div className=\"modal\">...</div>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const editorRef = useRef<HTMLDivElement>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n *\n * return <div ref={editorRef}>...</div>\n * }\n * ```\n */\nexport function useHotkey(\n hotkey: RegisterableHotkey,\n callback: HotkeyCallback,\n options: UseHotkeyOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkey,\n ...options,\n } as UseHotkeyOptions\n\n const manager = getHotkeyManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<HotkeyRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and hotkey to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevHotkeyRef = useRef<string | null>(null)\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof hotkey === 'string'\n ? hotkey\n : (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n return\n }\n\n // Check if we need to re-register (target or hotkey changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const hotkeyChanged =\n prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString\n\n // If we have an active registration and target/hotkey changed, unregister first\n if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n // Use refs to access current values without adding them to dependencies\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n hotkeyString,\n callbackRef.current,\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevHotkeyRef.current = hotkeyString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeyString, options.enabled])\n\n // Sync callback and options on EVERY render (outside useEffect)\n // This avoids stale closures - the callback always has access to latest state\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = callback\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n
|
|
1
|
+
{"version":3,"file":"useHotkey.js","names":[],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This hook syncs the callback and options on every render to avoid\n * stale closures. This means\n * callbacks that reference React state will always have access to\n * the latest values.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = useState(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal({ isOpen, onClose }) {\n * // enabled option is synced on every render\n * useHotkey('Escape', () => {\n * onClose()\n * }, { enabled: isOpen })\n *\n * if (!isOpen) return null\n * return <div className=\"modal\">...</div>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const editorRef = useRef<HTMLDivElement>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n *\n * return <div ref={editorRef}>...</div>\n * }\n * ```\n */\nexport function useHotkey(\n hotkey: RegisterableHotkey,\n callback: HotkeyCallback,\n options: UseHotkeyOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkey,\n ...options,\n } as UseHotkeyOptions\n\n const manager = getHotkeyManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<HotkeyRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and hotkey to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevHotkeyRef = useRef<string | null>(null)\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof hotkey === 'string'\n ? hotkey\n : (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n return\n }\n\n // Check if we need to re-register (target or hotkey changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const hotkeyChanged =\n prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString\n\n // If we have an active registration and target/hotkey changed, unregister first\n if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n // Use refs to access current values without adding them to dependencies\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n hotkeyString,\n callbackRef.current,\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevHotkeyRef.current = hotkeyString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeyString, options.enabled])\n\n // Sync callback and options on EVERY render (outside useEffect)\n // This avoids stale closures - the callback always has access to latest state\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = callback\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,UACd,QACA,UACA,UAA4B,EAAE,EACxB;CACN,MAAM,gBAAgB;EACpB,GAAG,0BAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,UAAU,kBAAkB;CAGlC,MAAM,kBAAkB,OAAwC,KAAK;CAGrE,MAAM,cAAc,OAAO,SAAS;CACpC,MAAM,aAAa,OAAO,cAAc;CACxC,MAAM,aAAa,OAAO,QAAQ;AAGlC,aAAY,UAAU;AACtB,YAAW,UAAU;AACrB,YAAW,UAAU;CAGrB,MAAM,gBAAgB,OAA+C,KAAK;CAC1E,MAAM,gBAAgB,OAAsB,KAAK;CAGjD,MAAM,WAAW,cAAc,YAAY,gBAAgB;CAC3D,MAAM,eACJ,OAAO,WAAW,WACd,SACC,aAAa,wBAAwB,QAAQ,SAAS,CAAC;CAG9D,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,iBAAgB;EAEd,MAAM,iBAAiB,MAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,eACH;EAIF,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;EAC9D,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;AAG9D,MAAI,gBAAgB,SAAS,aAAa,iBAAiB,gBAAgB;AACzE,mBAAgB,QAAQ,YAAY;AACpC,mBAAgB,UAAU;;AAK5B,MAAI,CAAC,gBAAgB,WAAW,CAAC,gBAAgB,QAAQ,SACvD,iBAAgB,UAAU,WAAW,QAAQ,SAC3C,cACA,YAAY,SACZ;GACE,GAAG,WAAW;GACd,QAAQ;GACT,CACF;AAIH,gBAAc,UAAU;AACxB,gBAAc,UAAU;AAGxB,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,CAAC,cAAc,QAAQ,QAAQ,CAAC;AAInC,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,WAAW;AACnC,kBAAgB,QAAQ,WAAW,qBAAqB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
3
|
+
const require_utils = require('./utils.cjs');
|
|
3
4
|
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
4
5
|
let react = require("react");
|
|
5
6
|
|
|
@@ -10,6 +11,11 @@ let react = require("react");
|
|
|
10
11
|
* This hook allows you to register multi-key sequences like 'g g' or 'd d'
|
|
11
12
|
* that trigger when the full sequence is pressed within a timeout.
|
|
12
13
|
*
|
|
14
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
15
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
16
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
17
|
+
* advance the sequence or reset progress.
|
|
18
|
+
*
|
|
13
19
|
* @param sequence - Array of hotkey strings that form the sequence
|
|
14
20
|
* @param callback - Function to call when the sequence is completed
|
|
15
21
|
* @param options - Options for the sequence behavior
|
|
@@ -32,6 +38,11 @@ let react = require("react");
|
|
|
32
38
|
* deleteInnerWord()
|
|
33
39
|
* }, { timeout: 500 })
|
|
34
40
|
*
|
|
41
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
42
|
+
* useHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
43
|
+
* nextAction()
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
35
46
|
* return <div>...</div>
|
|
36
47
|
* }
|
|
37
48
|
* ```
|
|
@@ -46,16 +57,18 @@ function useHotkeySequence(sequence, callback, options = {}) {
|
|
|
46
57
|
const callbackRef = (0, react.useRef)(callback);
|
|
47
58
|
const optionsRef = (0, react.useRef)(mergedOptions);
|
|
48
59
|
const managerRef = (0, react.useRef)(manager);
|
|
60
|
+
const sequenceRef = (0, react.useRef)(sequence);
|
|
49
61
|
callbackRef.current = callback;
|
|
50
62
|
optionsRef.current = mergedOptions;
|
|
51
63
|
managerRef.current = manager;
|
|
64
|
+
sequenceRef.current = sequence;
|
|
52
65
|
const prevTargetRef = (0, react.useRef)(null);
|
|
53
66
|
const prevSequenceRef = (0, react.useRef)(null);
|
|
54
67
|
const hotkeySequenceString = (0, _tanstack_hotkeys.formatHotkeySequence)(sequence);
|
|
55
68
|
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
56
69
|
(0, react.useEffect)(() => {
|
|
57
|
-
if (
|
|
58
|
-
const resolvedTarget = isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
|
|
70
|
+
if (sequenceRef.current.length === 0) return;
|
|
71
|
+
const resolvedTarget = require_utils.isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
|
|
59
72
|
if (!resolvedTarget) return;
|
|
60
73
|
const targetChanged = prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget;
|
|
61
74
|
const sequenceChanged = prevSequenceRef.current !== null && prevSequenceRef.current !== hotkeySequenceString;
|
|
@@ -63,7 +76,7 @@ function useHotkeySequence(sequence, callback, options = {}) {
|
|
|
63
76
|
registrationRef.current.unregister();
|
|
64
77
|
registrationRef.current = null;
|
|
65
78
|
}
|
|
66
|
-
if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(
|
|
79
|
+
if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(sequenceRef.current, (event, context) => callbackRef.current(event, context), {
|
|
67
80
|
...optionsRef.current,
|
|
68
81
|
target: resolvedTarget
|
|
69
82
|
});
|
|
@@ -75,22 +88,12 @@ function useHotkeySequence(sequence, callback, options = {}) {
|
|
|
75
88
|
registrationRef.current = null;
|
|
76
89
|
}
|
|
77
90
|
};
|
|
78
|
-
}, [
|
|
79
|
-
hotkeySequenceString,
|
|
80
|
-
mergedOptions.enabled,
|
|
81
|
-
sequence
|
|
82
|
-
]);
|
|
91
|
+
}, [hotkeySequenceString, mergedOptions.enabled]);
|
|
83
92
|
if (registrationRef.current?.isActive) {
|
|
84
93
|
registrationRef.current.callback = (event, context) => callbackRef.current(event, context);
|
|
85
94
|
registrationRef.current.setOptions(optionsWithoutTarget);
|
|
86
95
|
}
|
|
87
96
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Type guard to check if a value is a React ref-like object.
|
|
90
|
-
*/
|
|
91
|
-
function isRef(value) {
|
|
92
|
-
return value !== null && typeof value === "object" && "current" in value;
|
|
93
|
-
}
|
|
94
97
|
|
|
95
98
|
//#endregion
|
|
96
99
|
exports.useHotkeySequence = useHotkeySequence;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequence.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/useHotkeySequence.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeyCallback,\n HotkeyCallbackContext,\n HotkeySequence,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard shortcut sequence (Vim-style).\n *\n * This hook allows you to register multi-key sequences like 'g g' or 'd d'\n * that trigger when the full sequence is pressed within a timeout.\n *\n * @param sequence - Array of hotkey strings that form the sequence\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * useHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * useHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * useHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function useHotkeySequence(\n sequence: HotkeySequence,\n callback: HotkeyCallback,\n options: UseHotkeySequenceOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeySequence,\n ...options,\n } as UseHotkeySequenceOptions\n\n const manager = getSequenceManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<SequenceRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and sequence to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevSequenceRef = useRef<string | null>(null)\n\n // Normalize to hotkey sequence string (join with spaces)\n const hotkeySequenceString = formatHotkeySequence(sequence)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n if (
|
|
1
|
+
{"version":3,"file":"useHotkeySequence.cjs","names":["useDefaultHotkeysOptions","isRef"],"sources":["../src/useHotkeySequence.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type {\n HotkeyCallback,\n HotkeyCallbackContext,\n HotkeySequence,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard shortcut sequence (Vim-style).\n *\n * This hook allows you to register multi-key sequences like 'g g' or 'd d'\n * that trigger when the full sequence is pressed within a timeout.\n *\n * Each step may include modifiers. You can chain the same modifier across\n * steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,\n * Control, Alt, or Meta pressed alone) are ignored while matching—they do not\n * advance the sequence or reset progress.\n *\n * @param sequence - Array of hotkey strings that form the sequence\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * useHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * useHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * useHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * // Same modifier on consecutive steps (bare Shift between chords is ignored)\n * useHotkeySequence(['Shift+R', 'Shift+T'], () => {\n * nextAction()\n * })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function useHotkeySequence(\n sequence: HotkeySequence,\n callback: HotkeyCallback,\n options: UseHotkeySequenceOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeySequence,\n ...options,\n } as UseHotkeySequenceOptions\n\n const manager = getSequenceManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<SequenceRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n const sequenceRef = useRef(sequence)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n sequenceRef.current = sequence\n\n // Track previous target and sequence to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevSequenceRef = useRef<string | null>(null)\n\n // Normalize to hotkey sequence string (join with spaces)\n const hotkeySequenceString = formatHotkeySequence(sequence)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n if (sequenceRef.current.length === 0) {\n return\n }\n\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n return\n }\n\n // Check if we need to re-register (target or sequence changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const sequenceChanged =\n prevSequenceRef.current !== null &&\n prevSequenceRef.current !== hotkeySequenceString\n\n // If we have an active registration and target/sequence changed, unregister first\n if (\n registrationRef.current?.isActive &&\n (targetChanged || sequenceChanged)\n ) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n sequenceRef.current,\n (event, context) => callbackRef.current(event, context),\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevSequenceRef.current = hotkeySequenceString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeySequenceString, mergedOptions.enabled])\n\n // Sync callback and options on EVERY render (outside useEffect)\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = (\n event: KeyboardEvent,\n context: HotkeyCallbackContext,\n ) => callbackRef.current(event, context)\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,kBACd,UACA,UACA,UAAoC,EAAE,EAChC;CACN,MAAM,gBAAgB;EACpB,GAAGA,kDAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,qDAA8B;CAGpC,MAAM,oCAA4D,KAAK;CAGvE,MAAM,gCAAqB,SAAS;CACpC,MAAM,+BAAoB,cAAc;CACxC,MAAM,+BAAoB,QAAQ;CAClC,MAAM,gCAAqB,SAAS;AAGpC,aAAY,UAAU;AACtB,YAAW,UAAU;AACrB,YAAW,UAAU;AACrB,aAAY,UAAU;CAGtB,MAAM,kCAA+D,KAAK;CAC1E,MAAM,oCAAwC,KAAK;CAGnD,MAAM,mEAA4C,SAAS;CAG3D,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,4BAAgB;AACd,MAAI,YAAY,QAAQ,WAAW,EACjC;EAIF,MAAM,iBAAiBC,oBAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,eACH;EAIF,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;EAC9D,MAAM,kBACJ,gBAAgB,YAAY,QAC5B,gBAAgB,YAAY;AAG9B,MACE,gBAAgB,SAAS,aACxB,iBAAiB,kBAClB;AACA,mBAAgB,QAAQ,YAAY;AACpC,mBAAgB,UAAU;;AAI5B,MAAI,CAAC,gBAAgB,WAAW,CAAC,gBAAgB,QAAQ,SACvD,iBAAgB,UAAU,WAAW,QAAQ,SAC3C,YAAY,UACX,OAAO,YAAY,YAAY,QAAQ,OAAO,QAAQ,EACvD;GACE,GAAG,WAAW;GACd,QAAQ;GACT,CACF;AAIH,gBAAc,UAAU;AACxB,kBAAgB,UAAU;AAG1B,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,CAAC,sBAAsB,cAAc,QAAQ,CAAC;AAGjD,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,YACtB,OACA,YACG,YAAY,QAAQ,OAAO,QAAQ;AACxC,kBAAgB,QAAQ,WAAW,qBAAqB"}
|
|
@@ -15,6 +15,11 @@ interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
15
15
|
* This hook allows you to register multi-key sequences like 'g g' or 'd d'
|
|
16
16
|
* that trigger when the full sequence is pressed within a timeout.
|
|
17
17
|
*
|
|
18
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
19
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
20
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
21
|
+
* advance the sequence or reset progress.
|
|
22
|
+
*
|
|
18
23
|
* @param sequence - Array of hotkey strings that form the sequence
|
|
19
24
|
* @param callback - Function to call when the sequence is completed
|
|
20
25
|
* @param options - Options for the sequence behavior
|
|
@@ -37,6 +42,11 @@ interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
37
42
|
* deleteInnerWord()
|
|
38
43
|
* }, { timeout: 500 })
|
|
39
44
|
*
|
|
45
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
46
|
+
* useHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
47
|
+
* nextAction()
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
40
50
|
* return <div>...</div>
|
|
41
51
|
* }
|
|
42
52
|
* ```
|
|
@@ -15,6 +15,11 @@ interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
15
15
|
* This hook allows you to register multi-key sequences like 'g g' or 'd d'
|
|
16
16
|
* that trigger when the full sequence is pressed within a timeout.
|
|
17
17
|
*
|
|
18
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
19
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
20
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
21
|
+
* advance the sequence or reset progress.
|
|
22
|
+
*
|
|
18
23
|
* @param sequence - Array of hotkey strings that form the sequence
|
|
19
24
|
* @param callback - Function to call when the sequence is completed
|
|
20
25
|
* @param options - Options for the sequence behavior
|
|
@@ -37,6 +42,11 @@ interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
37
42
|
* deleteInnerWord()
|
|
38
43
|
* }, { timeout: 500 })
|
|
39
44
|
*
|
|
45
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
46
|
+
* useHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
47
|
+
* nextAction()
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
40
50
|
* return <div>...</div>
|
|
41
51
|
* }
|
|
42
52
|
* ```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
|
+
import { isRef } from "./utils.js";
|
|
2
3
|
import { formatHotkeySequence, getSequenceManager } from "@tanstack/hotkeys";
|
|
3
4
|
import { useEffect, useRef } from "react";
|
|
4
5
|
|
|
@@ -9,6 +10,11 @@ import { useEffect, useRef } from "react";
|
|
|
9
10
|
* This hook allows you to register multi-key sequences like 'g g' or 'd d'
|
|
10
11
|
* that trigger when the full sequence is pressed within a timeout.
|
|
11
12
|
*
|
|
13
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
14
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
15
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
16
|
+
* advance the sequence or reset progress.
|
|
17
|
+
*
|
|
12
18
|
* @param sequence - Array of hotkey strings that form the sequence
|
|
13
19
|
* @param callback - Function to call when the sequence is completed
|
|
14
20
|
* @param options - Options for the sequence behavior
|
|
@@ -31,6 +37,11 @@ import { useEffect, useRef } from "react";
|
|
|
31
37
|
* deleteInnerWord()
|
|
32
38
|
* }, { timeout: 500 })
|
|
33
39
|
*
|
|
40
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
41
|
+
* useHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
42
|
+
* nextAction()
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
34
45
|
* return <div>...</div>
|
|
35
46
|
* }
|
|
36
47
|
* ```
|
|
@@ -45,15 +56,17 @@ function useHotkeySequence(sequence, callback, options = {}) {
|
|
|
45
56
|
const callbackRef = useRef(callback);
|
|
46
57
|
const optionsRef = useRef(mergedOptions);
|
|
47
58
|
const managerRef = useRef(manager);
|
|
59
|
+
const sequenceRef = useRef(sequence);
|
|
48
60
|
callbackRef.current = callback;
|
|
49
61
|
optionsRef.current = mergedOptions;
|
|
50
62
|
managerRef.current = manager;
|
|
63
|
+
sequenceRef.current = sequence;
|
|
51
64
|
const prevTargetRef = useRef(null);
|
|
52
65
|
const prevSequenceRef = useRef(null);
|
|
53
66
|
const hotkeySequenceString = formatHotkeySequence(sequence);
|
|
54
67
|
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
55
68
|
useEffect(() => {
|
|
56
|
-
if (
|
|
69
|
+
if (sequenceRef.current.length === 0) return;
|
|
57
70
|
const resolvedTarget = isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
|
|
58
71
|
if (!resolvedTarget) return;
|
|
59
72
|
const targetChanged = prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget;
|
|
@@ -62,7 +75,7 @@ function useHotkeySequence(sequence, callback, options = {}) {
|
|
|
62
75
|
registrationRef.current.unregister();
|
|
63
76
|
registrationRef.current = null;
|
|
64
77
|
}
|
|
65
|
-
if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(
|
|
78
|
+
if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(sequenceRef.current, (event, context) => callbackRef.current(event, context), {
|
|
66
79
|
...optionsRef.current,
|
|
67
80
|
target: resolvedTarget
|
|
68
81
|
});
|
|
@@ -74,22 +87,12 @@ function useHotkeySequence(sequence, callback, options = {}) {
|
|
|
74
87
|
registrationRef.current = null;
|
|
75
88
|
}
|
|
76
89
|
};
|
|
77
|
-
}, [
|
|
78
|
-
hotkeySequenceString,
|
|
79
|
-
mergedOptions.enabled,
|
|
80
|
-
sequence
|
|
81
|
-
]);
|
|
90
|
+
}, [hotkeySequenceString, mergedOptions.enabled]);
|
|
82
91
|
if (registrationRef.current?.isActive) {
|
|
83
92
|
registrationRef.current.callback = (event, context) => callbackRef.current(event, context);
|
|
84
93
|
registrationRef.current.setOptions(optionsWithoutTarget);
|
|
85
94
|
}
|
|
86
95
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Type guard to check if a value is a React ref-like object.
|
|
89
|
-
*/
|
|
90
|
-
function isRef(value) {
|
|
91
|
-
return value !== null && typeof value === "object" && "current" in value;
|
|
92
|
-
}
|
|
93
96
|
|
|
94
97
|
//#endregion
|
|
95
98
|
export { useHotkeySequence };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequence.js","names":[],"sources":["../src/useHotkeySequence.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeyCallback,\n HotkeyCallbackContext,\n HotkeySequence,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard shortcut sequence (Vim-style).\n *\n * This hook allows you to register multi-key sequences like 'g g' or 'd d'\n * that trigger when the full sequence is pressed within a timeout.\n *\n * @param sequence - Array of hotkey strings that form the sequence\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * useHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * useHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * useHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function useHotkeySequence(\n sequence: HotkeySequence,\n callback: HotkeyCallback,\n options: UseHotkeySequenceOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeySequence,\n ...options,\n } as UseHotkeySequenceOptions\n\n const manager = getSequenceManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<SequenceRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and sequence to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevSequenceRef = useRef<string | null>(null)\n\n // Normalize to hotkey sequence string (join with spaces)\n const hotkeySequenceString = formatHotkeySequence(sequence)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n if (
|
|
1
|
+
{"version":3,"file":"useHotkeySequence.js","names":[],"sources":["../src/useHotkeySequence.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type {\n HotkeyCallback,\n HotkeyCallbackContext,\n HotkeySequence,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a React ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | React.RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * React hook for registering a keyboard shortcut sequence (Vim-style).\n *\n * This hook allows you to register multi-key sequences like 'g g' or 'd d'\n * that trigger when the full sequence is pressed within a timeout.\n *\n * Each step may include modifiers. You can chain the same modifier across\n * steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,\n * Control, Alt, or Meta pressed alone) are ignored while matching—they do not\n * advance the sequence or reset progress.\n *\n * @param sequence - Array of hotkey strings that form the sequence\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * useHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * useHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * useHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * // Same modifier on consecutive steps (bare Shift between chords is ignored)\n * useHotkeySequence(['Shift+R', 'Shift+T'], () => {\n * nextAction()\n * })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function useHotkeySequence(\n sequence: HotkeySequence,\n callback: HotkeyCallback,\n options: UseHotkeySequenceOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeySequence,\n ...options,\n } as UseHotkeySequenceOptions\n\n const manager = getSequenceManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<SequenceRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n const sequenceRef = useRef(sequence)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n sequenceRef.current = sequence\n\n // Track previous target and sequence to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevSequenceRef = useRef<string | null>(null)\n\n // Normalize to hotkey sequence string (join with spaces)\n const hotkeySequenceString = formatHotkeySequence(sequence)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n if (sequenceRef.current.length === 0) {\n return\n }\n\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n return\n }\n\n // Check if we need to re-register (target or sequence changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const sequenceChanged =\n prevSequenceRef.current !== null &&\n prevSequenceRef.current !== hotkeySequenceString\n\n // If we have an active registration and target/sequence changed, unregister first\n if (\n registrationRef.current?.isActive &&\n (targetChanged || sequenceChanged)\n ) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n sequenceRef.current,\n (event, context) => callbackRef.current(event, context),\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevSequenceRef.current = hotkeySequenceString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeySequenceString, mergedOptions.enabled])\n\n // Sync callback and options on EVERY render (outside useEffect)\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = (\n event: KeyboardEvent,\n context: HotkeyCallbackContext,\n ) => callbackRef.current(event, context)\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,kBACd,UACA,UACA,UAAoC,EAAE,EAChC;CACN,MAAM,gBAAgB;EACpB,GAAG,0BAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,UAAU,oBAAoB;CAGpC,MAAM,kBAAkB,OAA0C,KAAK;CAGvE,MAAM,cAAc,OAAO,SAAS;CACpC,MAAM,aAAa,OAAO,cAAc;CACxC,MAAM,aAAa,OAAO,QAAQ;CAClC,MAAM,cAAc,OAAO,SAAS;AAGpC,aAAY,UAAU;AACtB,YAAW,UAAU;AACrB,YAAW,UAAU;AACrB,aAAY,UAAU;CAGtB,MAAM,gBAAgB,OAA+C,KAAK;CAC1E,MAAM,kBAAkB,OAAsB,KAAK;CAGnD,MAAM,uBAAuB,qBAAqB,SAAS;CAG3D,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,iBAAgB;AACd,MAAI,YAAY,QAAQ,WAAW,EACjC;EAIF,MAAM,iBAAiB,MAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,eACH;EAIF,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;EAC9D,MAAM,kBACJ,gBAAgB,YAAY,QAC5B,gBAAgB,YAAY;AAG9B,MACE,gBAAgB,SAAS,aACxB,iBAAiB,kBAClB;AACA,mBAAgB,QAAQ,YAAY;AACpC,mBAAgB,UAAU;;AAI5B,MAAI,CAAC,gBAAgB,WAAW,CAAC,gBAAgB,QAAQ,SACvD,iBAAgB,UAAU,WAAW,QAAQ,SAC3C,YAAY,UACX,OAAO,YAAY,YAAY,QAAQ,OAAO,QAAQ,EACvD;GACE,GAAG,WAAW;GACd,QAAQ;GACT,CACF;AAIH,gBAAc,UAAU;AACxB,kBAAgB,UAAU;AAG1B,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,CAAC,sBAAsB,cAAc,QAAQ,CAAC;AAGjD,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,YACtB,OACA,YACG,YAAY,QAAQ,OAAO,QAAQ;AACxC,kBAAgB,QAAQ,WAAW,qBAAqB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
3
|
+
const require_utils = require('./utils.cjs');
|
|
4
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/useHotkeys.ts
|
|
8
|
+
/**
|
|
9
|
+
* React hook for registering multiple keyboard hotkeys at once.
|
|
10
|
+
*
|
|
11
|
+
* Uses the singleton HotkeyManager for efficient event handling.
|
|
12
|
+
* Accepts a dynamic array of hotkey definitions, making it safe to use
|
|
13
|
+
* with variable-length lists without violating the rules of hooks.
|
|
14
|
+
*
|
|
15
|
+
* Options are merged in this order:
|
|
16
|
+
* HotkeysProvider defaults < commonOptions < per-definition options
|
|
17
|
+
*
|
|
18
|
+
* Callbacks and options are synced on every render to avoid stale closures.
|
|
19
|
+
*
|
|
20
|
+
* @param hotkeys - Array of hotkey definitions to register
|
|
21
|
+
* @param commonOptions - Shared options applied to all hotkeys (overridden by per-definition options)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* function Editor() {
|
|
26
|
+
* useHotkeys([
|
|
27
|
+
* { hotkey: 'Mod+S', callback: () => save() },
|
|
28
|
+
* { hotkey: 'Mod+Z', callback: () => undo() },
|
|
29
|
+
* { hotkey: 'Escape', callback: () => close() },
|
|
30
|
+
* ])
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* function MenuShortcuts({ items }) {
|
|
37
|
+
* // Dynamic hotkeys from data -- safe because it's a single hook call
|
|
38
|
+
* useHotkeys(
|
|
39
|
+
* items.map((item) => ({
|
|
40
|
+
* hotkey: item.shortcut,
|
|
41
|
+
* callback: item.action,
|
|
42
|
+
* options: { enabled: item.enabled },
|
|
43
|
+
* })),
|
|
44
|
+
* { preventDefault: true },
|
|
45
|
+
* )
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function useHotkeys(hotkeys, commonOptions = {}) {
|
|
50
|
+
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions().hotkey;
|
|
51
|
+
const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
|
|
52
|
+
const platform = commonOptions.platform ?? defaultOptions?.platform ?? (0, _tanstack_hotkeys.detectPlatform)();
|
|
53
|
+
const registrationsRef = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
54
|
+
const hotkeysRef = (0, react.useRef)(hotkeys);
|
|
55
|
+
const hotkeyStringsRef = (0, react.useRef)([]);
|
|
56
|
+
const commonOptionsRef = (0, react.useRef)(commonOptions);
|
|
57
|
+
const defaultOptionsRef = (0, react.useRef)(defaultOptions);
|
|
58
|
+
const managerRef = (0, react.useRef)(manager);
|
|
59
|
+
const hotkeyStrings = hotkeys.map((def) => typeof def.hotkey === "string" ? def.hotkey : (0, _tanstack_hotkeys.formatHotkey)((0, _tanstack_hotkeys.rawHotkeyToParsedHotkey)(def.hotkey, platform)));
|
|
60
|
+
hotkeysRef.current = hotkeys;
|
|
61
|
+
hotkeyStringsRef.current = hotkeyStrings;
|
|
62
|
+
commonOptionsRef.current = commonOptions;
|
|
63
|
+
defaultOptionsRef.current = defaultOptions;
|
|
64
|
+
managerRef.current = manager;
|
|
65
|
+
(0, react.useEffect)(() => {
|
|
66
|
+
const prevRegistrations = registrationsRef.current;
|
|
67
|
+
const nextRegistrations = /* @__PURE__ */ new Map();
|
|
68
|
+
const rows = [];
|
|
69
|
+
for (let i = 0; i < hotkeysRef.current.length; i++) {
|
|
70
|
+
const def = hotkeysRef.current[i];
|
|
71
|
+
const hotkeyStr = hotkeyStringsRef.current[i];
|
|
72
|
+
const mergedOptions = {
|
|
73
|
+
...defaultOptionsRef.current,
|
|
74
|
+
...commonOptionsRef.current,
|
|
75
|
+
...def.options
|
|
76
|
+
};
|
|
77
|
+
const resolvedTarget = require_utils.isRef(mergedOptions.target) ? mergedOptions.target.current : mergedOptions.target ?? (typeof document !== "undefined" ? document : null);
|
|
78
|
+
if (!resolvedTarget) continue;
|
|
79
|
+
const registrationKey = `${i}:${hotkeyStr}`;
|
|
80
|
+
rows.push({
|
|
81
|
+
registrationKey,
|
|
82
|
+
def,
|
|
83
|
+
hotkeyStr,
|
|
84
|
+
mergedOptions,
|
|
85
|
+
resolvedTarget
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const nextKeys = new Set(rows.map((r) => r.registrationKey));
|
|
89
|
+
for (const [key, record] of prevRegistrations) if (!nextKeys.has(key) && record.handle.isActive) record.handle.unregister();
|
|
90
|
+
for (const row of rows) {
|
|
91
|
+
const { registrationKey, def, hotkeyStr, mergedOptions, resolvedTarget } = row;
|
|
92
|
+
const existing = prevRegistrations.get(registrationKey);
|
|
93
|
+
if (existing?.handle.isActive && existing.target === resolvedTarget) {
|
|
94
|
+
nextRegistrations.set(registrationKey, existing);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (existing?.handle.isActive) existing.handle.unregister();
|
|
98
|
+
const handle = managerRef.current.register(hotkeyStr, def.callback, {
|
|
99
|
+
...mergedOptions,
|
|
100
|
+
target: resolvedTarget
|
|
101
|
+
});
|
|
102
|
+
nextRegistrations.set(registrationKey, {
|
|
103
|
+
handle,
|
|
104
|
+
target: resolvedTarget
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
registrationsRef.current = nextRegistrations;
|
|
108
|
+
return () => {
|
|
109
|
+
for (const { handle } of registrationsRef.current.values()) if (handle.isActive) handle.unregister();
|
|
110
|
+
registrationsRef.current = /* @__PURE__ */ new Map();
|
|
111
|
+
};
|
|
112
|
+
}, [hotkeyStrings.join("\0"), hotkeys.map((def) => {
|
|
113
|
+
return {
|
|
114
|
+
...defaultOptions,
|
|
115
|
+
...commonOptions,
|
|
116
|
+
...def.options
|
|
117
|
+
}.enabled ?? true;
|
|
118
|
+
}).join("\0")]);
|
|
119
|
+
for (let i = 0; i < hotkeys.length; i++) {
|
|
120
|
+
const def = hotkeys[i];
|
|
121
|
+
const hotkeyStr = hotkeyStrings[i];
|
|
122
|
+
const registrationKey = `${i}:${hotkeyStr}`;
|
|
123
|
+
const handle = registrationsRef.current.get(registrationKey)?.handle;
|
|
124
|
+
if (handle?.isActive) {
|
|
125
|
+
handle.callback = def.callback;
|
|
126
|
+
const { target: _target, ...optionsWithoutTarget } = {
|
|
127
|
+
...defaultOptions,
|
|
128
|
+
...commonOptions,
|
|
129
|
+
...def.options
|
|
130
|
+
};
|
|
131
|
+
handle.setOptions(optionsWithoutTarget);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
exports.useHotkeys = useHotkeys;
|
|
138
|
+
//# sourceMappingURL=useHotkeys.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHotkeys.cjs","names":["useDefaultHotkeysOptions","isRef"],"sources":["../src/useHotkeys.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type { UseHotkeyOptions } from './useHotkey'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A single hotkey definition for use with `useHotkeys`.\n */\nexport interface UseHotkeyDefinition {\n /** The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object */\n hotkey: RegisterableHotkey\n /** The function to call when the hotkey is pressed */\n callback: HotkeyCallback\n /** Per-hotkey options (merged on top of commonOptions) */\n options?: UseHotkeyOptions\n}\n\n/**\n * React hook for registering multiple keyboard hotkeys at once.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * Accepts a dynamic array of hotkey definitions, making it safe to use\n * with variable-length lists without violating the rules of hooks.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * Callbacks and options are synced on every render to avoid stale closures.\n *\n * @param hotkeys - Array of hotkey definitions to register\n * @param commonOptions - Shared options applied to all hotkeys (overridden by per-definition options)\n *\n * @example\n * ```tsx\n * function Editor() {\n * useHotkeys([\n * { hotkey: 'Mod+S', callback: () => save() },\n * { hotkey: 'Mod+Z', callback: () => undo() },\n * { hotkey: 'Escape', callback: () => close() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function MenuShortcuts({ items }) {\n * // Dynamic hotkeys from data -- safe because it's a single hook call\n * useHotkeys(\n * items.map((item) => ({\n * hotkey: item.shortcut,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function useHotkeys(\n hotkeys: Array<UseHotkeyDefinition>,\n commonOptions: UseHotkeyOptions = {},\n): void {\n type RegistrationRecord = {\n handle: HotkeyRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions().hotkey\n const manager = getHotkeyManager()\n const platform =\n commonOptions.platform ?? defaultOptions?.platform ?? detectPlatform()\n\n const registrationsRef = useRef<Map<string, RegistrationRecord>>(new Map())\n const hotkeysRef = useRef(hotkeys)\n const hotkeyStringsRef = useRef<Array<Hotkey>>([])\n const commonOptionsRef = useRef(commonOptions)\n const defaultOptionsRef = useRef(defaultOptions)\n const managerRef = useRef(manager)\n\n const hotkeyStrings = hotkeys.map((def) =>\n typeof def.hotkey === 'string'\n ? def.hotkey\n : (formatHotkey(rawHotkeyToParsedHotkey(def.hotkey, platform)) as Hotkey),\n )\n\n hotkeysRef.current = hotkeys\n hotkeyStringsRef.current = hotkeyStrings\n commonOptionsRef.current = commonOptions\n defaultOptionsRef.current = defaultOptions\n managerRef.current = manager\n\n // Stable serialized keys for effect dependencies\n const hotkeyKey = hotkeyStrings.join('\\0')\n const enabledKey = hotkeys\n .map((def) => {\n const merged = {\n ...defaultOptions,\n ...commonOptions,\n ...def.options,\n }\n return merged.enabled ?? true\n })\n .join('\\0')\n\n useEffect(() => {\n const prevRegistrations = registrationsRef.current\n const nextRegistrations = new Map<string, RegistrationRecord>()\n\n const rows: Array<{\n registrationKey: string\n def: (typeof hotkeysRef.current)[number]\n hotkeyStr: Hotkey\n mergedOptions: UseHotkeyOptions\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < hotkeysRef.current.length; i++) {\n const def = hotkeysRef.current[i]!\n const hotkeyStr = hotkeyStringsRef.current[i]!\n const mergedOptions = {\n ...defaultOptionsRef.current,\n ...commonOptionsRef.current,\n ...def.options,\n } as UseHotkeyOptions\n\n const resolvedTarget = isRef(mergedOptions.target)\n ? mergedOptions.target.current\n : (mergedOptions.target ??\n (typeof document !== 'undefined' ? document : null))\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${hotkeyStr}`\n rows.push({\n registrationKey,\n def,\n hotkeyStr,\n mergedOptions,\n resolvedTarget,\n })\n }\n\n const nextKeys = new Set(rows.map((r) => r.registrationKey))\n\n for (const [key, record] of prevRegistrations) {\n if (!nextKeys.has(key) && record.handle.isActive) {\n record.handle.unregister()\n }\n }\n\n for (const row of rows) {\n const { registrationKey, def, hotkeyStr, mergedOptions, resolvedTarget } =\n row\n\n const existing = prevRegistrations.get(registrationKey)\n if (existing?.handle.isActive && existing.target === resolvedTarget) {\n nextRegistrations.set(registrationKey, existing)\n continue\n }\n\n if (existing?.handle.isActive) {\n existing.handle.unregister()\n }\n\n const handle = managerRef.current.register(hotkeyStr, def.callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n nextRegistrations.set(registrationKey, {\n handle,\n target: resolvedTarget,\n })\n }\n\n registrationsRef.current = nextRegistrations\n\n return () => {\n for (const { handle } of registrationsRef.current.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrationsRef.current = new Map()\n }\n }, [hotkeyKey, enabledKey])\n\n // Sync callbacks and options on EVERY render (outside useEffect)\n for (let i = 0; i < hotkeys.length; i++) {\n const def = hotkeys[i]!\n const hotkeyStr = hotkeyStrings[i]!\n const registrationKey = `${i}:${hotkeyStr}`\n const handle = registrationsRef.current.get(registrationKey)?.handle\n\n if (handle?.isActive) {\n handle.callback = def.callback\n const mergedOptions = {\n ...defaultOptions,\n ...commonOptions,\n ...def.options,\n } as UseHotkeyOptions\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n handle.setOptions(optionsWithoutTarget)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,WACd,SACA,gBAAkC,EAAE,EAC9B;CAMN,MAAM,iBAAiBA,kDAA0B,CAAC;CAClD,MAAM,mDAA4B;CAClC,MAAM,WACJ,cAAc,YAAY,gBAAgB,mDAA4B;CAExE,MAAM,qDAA2D,IAAI,KAAK,CAAC;CAC3E,MAAM,+BAAoB,QAAQ;CAClC,MAAM,qCAAyC,EAAE,CAAC;CAClD,MAAM,qCAA0B,cAAc;CAC9C,MAAM,sCAA2B,eAAe;CAChD,MAAM,+BAAoB,QAAQ;CAElC,MAAM,gBAAgB,QAAQ,KAAK,QACjC,OAAO,IAAI,WAAW,WAClB,IAAI,4FACkC,IAAI,QAAQ,SAAS,CAAC,CACjE;AAED,YAAW,UAAU;AACrB,kBAAiB,UAAU;AAC3B,kBAAiB,UAAU;AAC3B,mBAAkB,UAAU;AAC5B,YAAW,UAAU;AAerB,4BAAgB;EACd,MAAM,oBAAoB,iBAAiB;EAC3C,MAAM,oCAAoB,IAAI,KAAiC;EAE/D,MAAM,OAMD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,QAAQ,KAAK;GAClD,MAAM,MAAM,WAAW,QAAQ;GAC/B,MAAM,YAAY,iBAAiB,QAAQ;GAC3C,MAAM,gBAAgB;IACpB,GAAG,kBAAkB;IACrB,GAAG,iBAAiB;IACpB,GAAG,IAAI;IACR;GAED,MAAM,iBAAiBC,oBAAM,cAAc,OAAO,GAC9C,cAAc,OAAO,UACpB,cAAc,WACd,OAAO,aAAa,cAAc,WAAW;AAElD,OAAI,CAAC,eACH;GAGF,MAAM,kBAAkB,GAAG,EAAE,GAAG;AAChC,QAAK,KAAK;IACR;IACA;IACA;IACA;IACA;IACD,CAAC;;EAGJ,MAAM,WAAW,IAAI,IAAI,KAAK,KAAK,MAAM,EAAE,gBAAgB,CAAC;AAE5D,OAAK,MAAM,CAAC,KAAK,WAAW,kBAC1B,KAAI,CAAC,SAAS,IAAI,IAAI,IAAI,OAAO,OAAO,SACtC,QAAO,OAAO,YAAY;AAI9B,OAAK,MAAM,OAAO,MAAM;GACtB,MAAM,EAAE,iBAAiB,KAAK,WAAW,eAAe,mBACtD;GAEF,MAAM,WAAW,kBAAkB,IAAI,gBAAgB;AACvD,OAAI,UAAU,OAAO,YAAY,SAAS,WAAW,gBAAgB;AACnE,sBAAkB,IAAI,iBAAiB,SAAS;AAChD;;AAGF,OAAI,UAAU,OAAO,SACnB,UAAS,OAAO,YAAY;GAG9B,MAAM,SAAS,WAAW,QAAQ,SAAS,WAAW,IAAI,UAAU;IAClE,GAAG;IACH,QAAQ;IACT,CAAC;AACF,qBAAkB,IAAI,iBAAiB;IACrC;IACA,QAAQ;IACT,CAAC;;AAGJ,mBAAiB,UAAU;AAE3B,eAAa;AACX,QAAK,MAAM,EAAE,YAAY,iBAAiB,QAAQ,QAAQ,CACxD,KAAI,OAAO,SACT,QAAO,YAAY;AAGvB,oBAAiB,0BAAU,IAAI,KAAK;;IAErC,CA9Fe,cAAc,KAAK,KAAK,EACvB,QAChB,KAAK,QAAQ;AAMZ,SALe;GACb,GAAG;GACH,GAAG;GACH,GAAG,IAAI;GACR,CACa,WAAW;GACzB,CACD,KAAK,KAAK,CAoFa,CAAC;AAG3B,MAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,MAAM,QAAQ;EACpB,MAAM,YAAY,cAAc;EAChC,MAAM,kBAAkB,GAAG,EAAE,GAAG;EAChC,MAAM,SAAS,iBAAiB,QAAQ,IAAI,gBAAgB,EAAE;AAE9D,MAAI,QAAQ,UAAU;AACpB,UAAO,WAAW,IAAI;GAMtB,MAAM,EAAE,QAAQ,SAAS,GAAG,yBALN;IACpB,GAAG;IACH,GAAG;IACH,GAAG,IAAI;IACR;AAED,UAAO,WAAW,qBAAqB"}
|