@tanstack/react-hotkeys 0.11.0 → 0.12.0
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/HotkeysProvider.d.ts +6 -12
- package/dist/HotkeysProvider.js +1 -2
- package/dist/useHeldKeyCodes.d.ts +2 -4
- package/dist/useHeldKeyCodes.js +3 -3
- package/dist/useHeldKeys.d.ts +2 -4
- package/dist/useHeldKeys.js +3 -3
- package/dist/useHotkey.d.ts +3 -6
- package/dist/useHotkey.js +3 -3
- package/dist/useHotkeyHint.d.ts +2 -5
- package/dist/useHotkeyHint.js +1 -2
- package/dist/useHotkeyRecorder.d.ts +3 -6
- package/dist/useHotkeyRecorder.js +1 -2
- package/dist/useHotkeyRegistrations.d.ts +3 -6
- package/dist/useHotkeyRegistrations.js +1 -2
- package/dist/useHotkeySequence.d.ts +3 -6
- package/dist/useHotkeySequence.js +1 -2
- package/dist/useHotkeySequenceRecorder.d.ts +3 -6
- package/dist/useHotkeySequenceRecorder.js +1 -2
- package/dist/useHotkeySequences.d.ts +3 -6
- package/dist/useHotkeySequences.js +1 -2
- package/dist/useHotkeys.d.ts +3 -6
- package/dist/useHotkeys.js +1 -2
- package/dist/useKeyHold.d.ts +2 -5
- package/dist/useKeyHold.js +1 -2
- package/dist/utils.js +1 -2
- package/package.json +14 -19
- package/dist/HotkeysProvider.cjs +0 -23
- package/dist/HotkeysProvider.cjs.map +0 -1
- package/dist/HotkeysProvider.d.cts +0 -28
- package/dist/HotkeysProvider.js.map +0 -1
- package/dist/_virtual/_rolldown/runtime.cjs +0 -29
- package/dist/index.cjs +0 -35
- package/dist/index.d.cts +0 -14
- package/dist/useHeldKeyCodes.cjs +0 -38
- package/dist/useHeldKeyCodes.cjs.map +0 -1
- package/dist/useHeldKeyCodes.d.cts +0 -31
- package/dist/useHeldKeyCodes.js.map +0 -1
- package/dist/useHeldKeys.cjs +0 -34
- package/dist/useHeldKeys.cjs.map +0 -1
- package/dist/useHeldKeys.d.cts +0 -27
- package/dist/useHeldKeys.js.map +0 -1
- package/dist/useHotkey.cjs +0 -126
- package/dist/useHotkey.cjs.map +0 -1
- package/dist/useHotkey.d.cts +0 -74
- package/dist/useHotkey.js.map +0 -1
- package/dist/useHotkeyHint.cjs +0 -19
- package/dist/useHotkeyHint.cjs.map +0 -1
- package/dist/useHotkeyHint.d.cts +0 -14
- package/dist/useHotkeyHint.js.map +0 -1
- package/dist/useHotkeyRecorder.cjs +0 -72
- package/dist/useHotkeyRecorder.cjs.map +0 -1
- package/dist/useHotkeyRecorder.d.cts +0 -57
- package/dist/useHotkeyRecorder.js.map +0 -1
- package/dist/useHotkeyRegistrations.cjs +0 -49
- package/dist/useHotkeyRegistrations.cjs.map +0 -1
- package/dist/useHotkeyRegistrations.d.cts +0 -48
- package/dist/useHotkeyRegistrations.js.map +0 -1
- package/dist/useHotkeySequence.cjs +0 -121
- package/dist/useHotkeySequence.cjs.map +0 -1
- package/dist/useHotkeySequence.d.cts +0 -58
- package/dist/useHotkeySequence.js.map +0 -1
- package/dist/useHotkeySequenceRecorder.cjs +0 -42
- package/dist/useHotkeySequenceRecorder.cjs.map +0 -1
- package/dist/useHotkeySequenceRecorder.d.cts +0 -25
- package/dist/useHotkeySequenceRecorder.js.map +0 -1
- package/dist/useHotkeySequences.cjs +0 -127
- package/dist/useHotkeySequences.cjs.map +0 -1
- package/dist/useHotkeySequences.d.cts +0 -63
- package/dist/useHotkeySequences.js.map +0 -1
- package/dist/useHotkeys.cjs +0 -125
- package/dist/useHotkeys.cjs.map +0 -1
- package/dist/useHotkeys.d.cts +0 -63
- package/dist/useHotkeys.js.map +0 -1
- package/dist/useKeyHold.cjs +0 -54
- package/dist/useKeyHold.cjs.map +0 -1
- package/dist/useKeyHold.d.cts +0 -47
- package/dist/useKeyHold.js.map +0 -1
- package/dist/utils.cjs +0 -12
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
- package/src/HotkeysProvider.tsx +0 -58
- package/src/index.ts +0 -18
- package/src/useHeldKeyCodes.ts +0 -33
- package/src/useHeldKeys.ts +0 -29
- package/src/useHotkey.ts +0 -190
- package/src/useHotkeyHint.ts +0 -19
- package/src/useHotkeyRecorder.ts +0 -101
- package/src/useHotkeyRegistrations.ts +0 -67
- package/src/useHotkeySequence.ts +0 -191
- package/src/useHotkeySequenceRecorder.ts +0 -70
- package/src/useHotkeySequences.ts +0 -192
- package/src/useHotkeys.ts +0 -193
- package/src/useKeyHold.ts +0 -52
- package/src/utils.ts +0 -10
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeyRegistrations.js","names":[],"sources":["../src/useHotkeyRegistrations.ts"],"sourcesContent":["import { useSelector } from '@tanstack/react-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\n\n/**\n * Return type for useHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** All registered hotkeys (public view, no callbacks) */\n hotkeys: Array<HotkeyRegistrationView>\n /** All registered sequences */\n sequences: Array<SequenceRegistrationView>\n}\n\n/**\n * React hook that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone hook that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * re-renders when registrations change.\n *\n * @returns Object with `hotkeys` and `sequences` arrays\n *\n * @example\n * ```tsx\n * function ShortcutPalette() {\n * const { hotkeys, sequences } = useHotkeyRegistrations()\n *\n * return (\n * <ul>\n * {hotkeys.map((reg) => (\n * <li key={reg.id}>\n * {reg.options.meta?.name ?? reg.hotkey}\n * </li>\n * ))}\n * {sequences.map((reg) => (\n * <li key={reg.id}>\n * {reg.options.meta?.name ?? reg.sequence.join(' ')}\n * </li>\n * ))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = useSelector(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = useSelector(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,yBAAoD;CAClE,MAAM,gBAAgB,kBAAkB;CACxC,MAAM,kBAAkB,oBAAoB;AAU5C,QAAO;EAAE,SARO,YAAY,cAAc,gBAAgB,UACxD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAI,yBAAyB,CACzD;EAMiB,WAJA,YAAY,gBAAgB,gBAAgB,UAC5D,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
|
|
@@ -1,121 +0,0 @@
|
|
|
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/useHotkeySequence.ts
|
|
8
|
-
/**
|
|
9
|
-
* React hook for registering a keyboard shortcut sequence (Vim-style).
|
|
10
|
-
*
|
|
11
|
-
* This hook allows you to register multi-key sequences like 'g g' or 'd d'
|
|
12
|
-
* that trigger when the full sequence is pressed within a timeout.
|
|
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
|
-
*
|
|
19
|
-
* @param sequence - Array of hotkey strings that form the sequence
|
|
20
|
-
* @param callback - Function to call when the sequence is completed
|
|
21
|
-
* @param options - Options for the sequence behavior. `enabled: false` keeps the registration (visible in devtools)
|
|
22
|
-
* and only suppresses firing; the hook updates the existing handle instead of unregistering.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* function VimEditor() {
|
|
27
|
-
* // 'g g' to go to top
|
|
28
|
-
* useHotkeySequence(['G', 'G'], () => {
|
|
29
|
-
* scrollToTop()
|
|
30
|
-
* })
|
|
31
|
-
*
|
|
32
|
-
* // 'd d' to delete line
|
|
33
|
-
* useHotkeySequence(['D', 'D'], () => {
|
|
34
|
-
* deleteLine()
|
|
35
|
-
* })
|
|
36
|
-
*
|
|
37
|
-
* // 'd i w' to delete inner word
|
|
38
|
-
* useHotkeySequence(['D', 'I', 'W'], () => {
|
|
39
|
-
* deleteInnerWord()
|
|
40
|
-
* }, { timeout: 500 })
|
|
41
|
-
*
|
|
42
|
-
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
43
|
-
* useHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
44
|
-
* nextAction()
|
|
45
|
-
* })
|
|
46
|
-
*
|
|
47
|
-
* return <div>...</div>
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
function useHotkeySequence(sequence, callback, options = {}) {
|
|
52
|
-
const mergedOptions = {
|
|
53
|
-
...require_HotkeysProvider.useDefaultHotkeysOptions().hotkeySequence,
|
|
54
|
-
...options
|
|
55
|
-
};
|
|
56
|
-
const manager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
57
|
-
const registrationRef = (0, react.useRef)(null);
|
|
58
|
-
const callbackRef = (0, react.useRef)(callback);
|
|
59
|
-
const optionsRef = (0, react.useRef)(mergedOptions);
|
|
60
|
-
const managerRef = (0, react.useRef)(manager);
|
|
61
|
-
const sequenceRef = (0, react.useRef)(sequence);
|
|
62
|
-
callbackRef.current = callback;
|
|
63
|
-
optionsRef.current = mergedOptions;
|
|
64
|
-
managerRef.current = manager;
|
|
65
|
-
sequenceRef.current = sequence;
|
|
66
|
-
const prevTargetRef = (0, react.useRef)(null);
|
|
67
|
-
const prevSequenceRef = (0, react.useRef)(null);
|
|
68
|
-
const hotkeySequenceString = (0, _tanstack_hotkeys.formatHotkeySequence)(sequence);
|
|
69
|
-
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
70
|
-
(0, react.useEffect)(() => {
|
|
71
|
-
if (sequenceRef.current.length === 0) {
|
|
72
|
-
if (registrationRef.current?.isActive) {
|
|
73
|
-
registrationRef.current.unregister();
|
|
74
|
-
registrationRef.current = null;
|
|
75
|
-
}
|
|
76
|
-
prevTargetRef.current = null;
|
|
77
|
-
prevSequenceRef.current = null;
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const resolvedTarget = require_utils.isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
|
|
81
|
-
if (!resolvedTarget) {
|
|
82
|
-
if (registrationRef.current?.isActive) {
|
|
83
|
-
registrationRef.current.unregister();
|
|
84
|
-
registrationRef.current = null;
|
|
85
|
-
}
|
|
86
|
-
prevTargetRef.current = null;
|
|
87
|
-
prevSequenceRef.current = null;
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const targetChanged = prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget;
|
|
91
|
-
const sequenceChanged = prevSequenceRef.current !== null && prevSequenceRef.current !== hotkeySequenceString;
|
|
92
|
-
if (registrationRef.current?.isActive && (targetChanged || sequenceChanged)) {
|
|
93
|
-
registrationRef.current.unregister();
|
|
94
|
-
registrationRef.current = null;
|
|
95
|
-
}
|
|
96
|
-
if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(sequenceRef.current, (event, context) => callbackRef.current(event, context), {
|
|
97
|
-
...optionsRef.current,
|
|
98
|
-
target: resolvedTarget
|
|
99
|
-
});
|
|
100
|
-
prevTargetRef.current = resolvedTarget;
|
|
101
|
-
prevSequenceRef.current = hotkeySequenceString;
|
|
102
|
-
});
|
|
103
|
-
(0, react.useEffect)(() => {
|
|
104
|
-
return () => {
|
|
105
|
-
if (registrationRef.current?.isActive) {
|
|
106
|
-
registrationRef.current.unregister();
|
|
107
|
-
registrationRef.current = null;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}, []);
|
|
111
|
-
(0, react.useEffect)(() => {
|
|
112
|
-
if (registrationRef.current?.isActive) {
|
|
113
|
-
registrationRef.current.callback = (event, context) => callbackRef.current(event, context);
|
|
114
|
-
registrationRef.current.setOptions(optionsWithoutTarget);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
exports.useHotkeySequence = useHotkeySequence;
|
|
121
|
-
//# sourceMappingURL=useHotkeySequence.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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. `enabled: false` keeps the registration (visible in devtools)\n * and only suppresses firing; the hook updates the existing handle instead of unregistering.\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 if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n prevTargetRef.current = null\n prevSequenceRef.current = null\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 if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n prevTargetRef.current = null\n prevSequenceRef.current = null\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\n useEffect(() => {\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [])\n\n // Publish option changes after commit, never during render.\n 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}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB,kBACd,UAC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AAY,YAAY,QAAQ,OAAO,QAAQ,EACvD;GACE,GAAG,WAAW;GACd,QAAQ;GACT,CACF;AAIH,gBAAc,UAAU;AACxB,kBAAgB,UAAU;GAC1B;AAEF,4BAAgB;AAEd,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,EAAE,CAAC;AAGN,4BAAgB;AACd,MAAI,gBAAgB,SAAS,UAAU;AACrC,mBAAgB,QAAQ,YACtB,OACA,YACG,YAAY,QAAQ,OAAO,QAAQ;AACxC,mBAAgB,QAAQ,WAAW,qBAAqB;;GAE1D"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { HotkeyCallback, HotkeySequence, SequenceOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/useHotkeySequence.d.ts
|
|
4
|
-
interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
5
|
-
/**
|
|
6
|
-
* The DOM element to attach the event listener to.
|
|
7
|
-
* Can be a React ref, direct DOM element, or null.
|
|
8
|
-
* Defaults to document.
|
|
9
|
-
*/
|
|
10
|
-
target?: React.RefObject<HTMLElement | null> | HTMLElement | Document | Window | null;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* React hook for registering a keyboard shortcut sequence (Vim-style).
|
|
14
|
-
*
|
|
15
|
-
* This hook allows you to register multi-key sequences like 'g g' or 'd d'
|
|
16
|
-
* that trigger when the full sequence is pressed within a timeout.
|
|
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
|
-
*
|
|
23
|
-
* @param sequence - Array of hotkey strings that form the sequence
|
|
24
|
-
* @param callback - Function to call when the sequence is completed
|
|
25
|
-
* @param options - Options for the sequence behavior. `enabled: false` keeps the registration (visible in devtools)
|
|
26
|
-
* and only suppresses firing; the hook updates the existing handle instead of unregistering.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* function VimEditor() {
|
|
31
|
-
* // 'g g' to go to top
|
|
32
|
-
* useHotkeySequence(['G', 'G'], () => {
|
|
33
|
-
* scrollToTop()
|
|
34
|
-
* })
|
|
35
|
-
*
|
|
36
|
-
* // 'd d' to delete line
|
|
37
|
-
* useHotkeySequence(['D', 'D'], () => {
|
|
38
|
-
* deleteLine()
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* // 'd i w' to delete inner word
|
|
42
|
-
* useHotkeySequence(['D', 'I', 'W'], () => {
|
|
43
|
-
* deleteInnerWord()
|
|
44
|
-
* }, { timeout: 500 })
|
|
45
|
-
*
|
|
46
|
-
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
47
|
-
* useHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
48
|
-
* nextAction()
|
|
49
|
-
* })
|
|
50
|
-
*
|
|
51
|
-
* return <div>...</div>
|
|
52
|
-
* }
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
declare function useHotkeySequence(sequence: HotkeySequence, callback: HotkeyCallback, options?: UseHotkeySequenceOptions): void;
|
|
56
|
-
//#endregion
|
|
57
|
-
export { UseHotkeySequenceOptions, useHotkeySequence };
|
|
58
|
-
//# sourceMappingURL=useHotkeySequence.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
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. `enabled: false` keeps the registration (visible in devtools)\n * and only suppresses firing; the hook updates the existing handle instead of unregistering.\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 if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n prevTargetRef.current = null\n prevSequenceRef.current = null\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 if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n prevTargetRef.current = null\n prevSequenceRef.current = null\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\n useEffect(() => {\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [])\n\n // Publish option changes after commit, never during render.\n 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}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,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,GAAG;AACpC,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;AAE5B,iBAAc,UAAU;AACxB,mBAAgB,UAAU;AAC1B;;EAIF,MAAM,iBAAiB,MAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,gBAAgB;AACnB,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;AAE5B,iBAAc,UAAU;AACxB,mBAAgB,UAAU;AAC1B;;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;GAC1B;AAEF,iBAAgB;AAEd,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,EAAE,CAAC;AAGN,iBAAgB;AACd,MAAI,gBAAgB,SAAS,UAAU;AACrC,mBAAgB,QAAQ,YACtB,OACA,YACG,YAAY,QAAQ,OAAO,QAAQ;AACxC,mBAAgB,QAAQ,WAAW,qBAAqB;;GAE1D"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
3
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
4
|
-
let react = require("react");
|
|
5
|
-
let _tanstack_react_store = require("@tanstack/react-store");
|
|
6
|
-
|
|
7
|
-
//#region src/useHotkeySequenceRecorder.ts
|
|
8
|
-
/**
|
|
9
|
-
* React hook for recording multi-chord sequences (Vim-style shortcuts).
|
|
10
|
-
*
|
|
11
|
-
* @param options - Configuration options for the hotkey sequence recorder
|
|
12
|
-
*/
|
|
13
|
-
function useHotkeySequenceRecorder(options) {
|
|
14
|
-
const mergedOptions = {
|
|
15
|
-
...require_HotkeysProvider.useDefaultHotkeysOptions().hotkeySequenceRecorder,
|
|
16
|
-
...options
|
|
17
|
-
};
|
|
18
|
-
const recorderRef = (0, react.useRef)(null);
|
|
19
|
-
if (!recorderRef.current) recorderRef.current = new _tanstack_hotkeys.HotkeySequenceRecorder(mergedOptions);
|
|
20
|
-
recorderRef.current.setOptions(mergedOptions);
|
|
21
|
-
const isRecording = (0, _tanstack_react_store.useSelector)(recorderRef.current.store, (state) => state.isRecording);
|
|
22
|
-
const steps = (0, _tanstack_react_store.useSelector)(recorderRef.current.store, (state) => state.steps);
|
|
23
|
-
const recordedSequence = (0, _tanstack_react_store.useSelector)(recorderRef.current.store, (state) => state.recordedSequence);
|
|
24
|
-
(0, react.useEffect)(() => {
|
|
25
|
-
return () => {
|
|
26
|
-
recorderRef.current?.destroy();
|
|
27
|
-
};
|
|
28
|
-
}, []);
|
|
29
|
-
return {
|
|
30
|
-
isRecording,
|
|
31
|
-
steps,
|
|
32
|
-
recordedSequence,
|
|
33
|
-
startRecording: () => recorderRef.current?.start(),
|
|
34
|
-
stopRecording: () => recorderRef.current?.stop(),
|
|
35
|
-
cancelRecording: () => recorderRef.current?.cancel(),
|
|
36
|
-
commitRecording: () => recorderRef.current?.commit()
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
exports.useHotkeySequenceRecorder = useHotkeySequenceRecorder;
|
|
42
|
-
//# sourceMappingURL=useHotkeySequenceRecorder.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequenceRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeySequenceRecorder"],"sources":["../src/useHotkeySequenceRecorder.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { useSelector } from '@tanstack/react-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface ReactHotkeySequenceRecorder {\n /** Whether recording is currently active */\n isRecording: boolean\n /** Chords captured in the current session */\n steps: HotkeySequence\n /** Last committed sequence */\n recordedSequence: HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n /** Commit current steps (no-op if empty) */\n commitRecording: () => void\n}\n\n/**\n * React hook for recording multi-chord sequences (Vim-style shortcuts).\n *\n * @param options - Configuration options for the hotkey sequence recorder\n */\nexport function useHotkeySequenceRecorder(\n options: HotkeySequenceRecorderOptions,\n): ReactHotkeySequenceRecorder {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeySequenceRecorder,\n ...options,\n } as HotkeySequenceRecorderOptions\n\n const recorderRef = useRef<HotkeySequenceRecorder | null>(null)\n\n if (!recorderRef.current) {\n recorderRef.current = new HotkeySequenceRecorder(mergedOptions)\n }\n\n recorderRef.current.setOptions(mergedOptions)\n\n const isRecording = useSelector(\n recorderRef.current.store,\n (state) => state.isRecording,\n )\n const steps = useSelector(recorderRef.current.store, (state) => state.steps)\n const recordedSequence = useSelector(\n recorderRef.current.store,\n (state) => state.recordedSequence,\n )\n\n useEffect(() => {\n return () => {\n recorderRef.current?.destroy()\n }\n }, [])\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorderRef.current?.start(),\n stopRecording: () => recorderRef.current?.stop(),\n cancelRecording: () => recorderRef.current?.cancel(),\n commitRecording: () => recorderRef.current?.commit(),\n }\n}\n"],"mappings":";;;;;;;;;;;;AA4BA,SAAgB,0BACd,SAC6B;CAC7B,MAAM,gBAAgB;EACpB,GAAGA,kDAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,gCAAoD,KAAK;AAE/D,KAAI,CAAC,YAAY,QACf,aAAY,UAAU,IAAIC,yCAAuB,cAAc;AAGjE,aAAY,QAAQ,WAAW,cAAc;CAE7C,MAAM,qDACJ,YAAY,QAAQ,QACnB,UAAU,MAAM,YAClB;CACD,MAAM,+CAAoB,YAAY,QAAQ,QAAQ,UAAU,MAAM,MAAM;CAC5E,MAAM,0DACJ,YAAY,QAAQ,QACnB,UAAU,MAAM,iBAClB;AAED,4BAAgB;AACd,eAAa;AACX,eAAY,SAAS,SAAS;;IAE/B,EAAE,CAAC;AAEN,QAAO;EACL;EACA;EACA;EACA,sBAAsB,YAAY,SAAS,OAAO;EAClD,qBAAqB,YAAY,SAAS,MAAM;EAChD,uBAAuB,YAAY,SAAS,QAAQ;EACpD,uBAAuB,YAAY,SAAS,QAAQ;EACrD"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/useHotkeySequenceRecorder.d.ts
|
|
4
|
-
interface ReactHotkeySequenceRecorder {
|
|
5
|
-
/** Whether recording is currently active */
|
|
6
|
-
isRecording: boolean;
|
|
7
|
-
/** Chords captured in the current session */
|
|
8
|
-
steps: HotkeySequence;
|
|
9
|
-
/** Last committed sequence */
|
|
10
|
-
recordedSequence: HotkeySequence | null;
|
|
11
|
-
startRecording: () => void;
|
|
12
|
-
stopRecording: () => void;
|
|
13
|
-
cancelRecording: () => void;
|
|
14
|
-
/** Commit current steps (no-op if empty) */
|
|
15
|
-
commitRecording: () => void;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* React hook for recording multi-chord sequences (Vim-style shortcuts).
|
|
19
|
-
*
|
|
20
|
-
* @param options - Configuration options for the hotkey sequence recorder
|
|
21
|
-
*/
|
|
22
|
-
declare function useHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions): ReactHotkeySequenceRecorder;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { ReactHotkeySequenceRecorder, useHotkeySequenceRecorder };
|
|
25
|
-
//# sourceMappingURL=useHotkeySequenceRecorder.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequenceRecorder.js","names":[],"sources":["../src/useHotkeySequenceRecorder.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { useSelector } from '@tanstack/react-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface ReactHotkeySequenceRecorder {\n /** Whether recording is currently active */\n isRecording: boolean\n /** Chords captured in the current session */\n steps: HotkeySequence\n /** Last committed sequence */\n recordedSequence: HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n /** Commit current steps (no-op if empty) */\n commitRecording: () => void\n}\n\n/**\n * React hook for recording multi-chord sequences (Vim-style shortcuts).\n *\n * @param options - Configuration options for the hotkey sequence recorder\n */\nexport function useHotkeySequenceRecorder(\n options: HotkeySequenceRecorderOptions,\n): ReactHotkeySequenceRecorder {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeySequenceRecorder,\n ...options,\n } as HotkeySequenceRecorderOptions\n\n const recorderRef = useRef<HotkeySequenceRecorder | null>(null)\n\n if (!recorderRef.current) {\n recorderRef.current = new HotkeySequenceRecorder(mergedOptions)\n }\n\n recorderRef.current.setOptions(mergedOptions)\n\n const isRecording = useSelector(\n recorderRef.current.store,\n (state) => state.isRecording,\n )\n const steps = useSelector(recorderRef.current.store, (state) => state.steps)\n const recordedSequence = useSelector(\n recorderRef.current.store,\n (state) => state.recordedSequence,\n )\n\n useEffect(() => {\n return () => {\n recorderRef.current?.destroy()\n }\n }, [])\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorderRef.current?.start(),\n stopRecording: () => recorderRef.current?.stop(),\n cancelRecording: () => recorderRef.current?.cancel(),\n commitRecording: () => recorderRef.current?.commit(),\n }\n}\n"],"mappings":";;;;;;;;;;;AA4BA,SAAgB,0BACd,SAC6B;CAC7B,MAAM,gBAAgB;EACpB,GAAG,0BAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,cAAc,OAAsC,KAAK;AAE/D,KAAI,CAAC,YAAY,QACf,aAAY,UAAU,IAAI,uBAAuB,cAAc;AAGjE,aAAY,QAAQ,WAAW,cAAc;CAE7C,MAAM,cAAc,YAClB,YAAY,QAAQ,QACnB,UAAU,MAAM,YAClB;CACD,MAAM,QAAQ,YAAY,YAAY,QAAQ,QAAQ,UAAU,MAAM,MAAM;CAC5E,MAAM,mBAAmB,YACvB,YAAY,QAAQ,QACnB,UAAU,MAAM,iBAClB;AAED,iBAAgB;AACd,eAAa;AACX,eAAY,SAAS,SAAS;;IAE/B,EAAE,CAAC;AAEN,QAAO;EACL;EACA;EACA;EACA,sBAAsB,YAAY,SAAS,OAAO;EAClD,qBAAqB,YAAY,SAAS,MAAM;EAChD,uBAAuB,YAAY,SAAS,QAAQ;EACpD,uBAAuB,YAAY,SAAS,QAAQ;EACrD"}
|
|
@@ -1,127 +0,0 @@
|
|
|
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/useHotkeySequences.ts
|
|
8
|
-
/**
|
|
9
|
-
* React hook for registering multiple keyboard shortcut sequences at once (Vim-style).
|
|
10
|
-
*
|
|
11
|
-
* Uses the singleton SequenceManager. Accepts a dynamic array of definitions so you can
|
|
12
|
-
* register variable-length lists without violating the rules of hooks.
|
|
13
|
-
*
|
|
14
|
-
* Options are merged in this order:
|
|
15
|
-
* HotkeysProvider defaults < commonOptions < per-definition options
|
|
16
|
-
*
|
|
17
|
-
* Callbacks and options are synced on every render to avoid stale closures.
|
|
18
|
-
*
|
|
19
|
-
* Definitions with an empty `sequence` are skipped (no registration).
|
|
20
|
-
*
|
|
21
|
-
* @param definitions - Array of sequence definitions to register
|
|
22
|
-
* @param commonOptions - Shared options applied to all sequences (overridden by per-definition options).
|
|
23
|
-
* Per-row `enabled: false` still registers that sequence: `SequenceManager` suppresses execution only (the row
|
|
24
|
-
* stays in the store and appears in TanStack Hotkeys devtools). Toggling `enabled` updates the existing handle
|
|
25
|
-
* via `setOptions` (no unregister/re-register churn).
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```tsx
|
|
29
|
-
* function VimPalette() {
|
|
30
|
-
* useHotkeySequences([
|
|
31
|
-
* { sequence: ['G', 'G'], callback: () => scrollToTop() },
|
|
32
|
-
* { sequence: ['D', 'D'], callback: () => deleteLine() },
|
|
33
|
-
* { sequence: ['C', 'I', 'W'], callback: () => changeInnerWord(), options: { timeout: 500 } },
|
|
34
|
-
* ])
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```tsx
|
|
40
|
-
* function DynamicSequences({ items }) {
|
|
41
|
-
* useHotkeySequences(
|
|
42
|
-
* items.map((item) => ({
|
|
43
|
-
* sequence: item.chords,
|
|
44
|
-
* callback: item.action,
|
|
45
|
-
* options: { enabled: item.enabled },
|
|
46
|
-
* })),
|
|
47
|
-
* { preventDefault: true },
|
|
48
|
-
* )
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
function useHotkeySequences(definitions, commonOptions = {}) {
|
|
53
|
-
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions().hotkeySequence;
|
|
54
|
-
const manager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
55
|
-
const registrationsRef = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
56
|
-
const definitionsRef = (0, react.useRef)(definitions);
|
|
57
|
-
const sequenceStringsRef = (0, react.useRef)([]);
|
|
58
|
-
const commonOptionsRef = (0, react.useRef)(commonOptions);
|
|
59
|
-
const defaultOptionsRef = (0, react.useRef)(defaultOptions);
|
|
60
|
-
const managerRef = (0, react.useRef)(manager);
|
|
61
|
-
const sequenceStrings = definitions.map((def) => (0, _tanstack_hotkeys.formatHotkeySequence)(def.sequence));
|
|
62
|
-
definitionsRef.current = definitions;
|
|
63
|
-
sequenceStringsRef.current = sequenceStrings;
|
|
64
|
-
commonOptionsRef.current = commonOptions;
|
|
65
|
-
defaultOptionsRef.current = defaultOptions;
|
|
66
|
-
managerRef.current = manager;
|
|
67
|
-
(0, react.useEffect)(() => {
|
|
68
|
-
const prevRegistrations = registrationsRef.current;
|
|
69
|
-
const nextRegistrations = /* @__PURE__ */ new Map();
|
|
70
|
-
const rows = [];
|
|
71
|
-
for (let i = 0; i < definitionsRef.current.length; i++) {
|
|
72
|
-
const def = definitionsRef.current[i];
|
|
73
|
-
const seqStr = sequenceStringsRef.current[i];
|
|
74
|
-
const seq = def.sequence;
|
|
75
|
-
if (seq.length === 0) continue;
|
|
76
|
-
const mergedOptions = {
|
|
77
|
-
...defaultOptionsRef.current,
|
|
78
|
-
...commonOptionsRef.current,
|
|
79
|
-
...def.options
|
|
80
|
-
};
|
|
81
|
-
const resolvedTarget = require_utils.isRef(mergedOptions.target) ? mergedOptions.target.current : mergedOptions.target ?? (typeof document !== "undefined" ? document : null);
|
|
82
|
-
if (!resolvedTarget) continue;
|
|
83
|
-
const registrationKey = `${i}:${seqStr}`;
|
|
84
|
-
rows.push({
|
|
85
|
-
registrationKey,
|
|
86
|
-
def,
|
|
87
|
-
seq,
|
|
88
|
-
seqStr,
|
|
89
|
-
mergedOptions,
|
|
90
|
-
resolvedTarget
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
const nextKeys = new Set(rows.map((r) => r.registrationKey));
|
|
94
|
-
for (const [key, record] of prevRegistrations) if (!nextKeys.has(key) && record.handle.isActive) record.handle.unregister();
|
|
95
|
-
for (const row of rows) {
|
|
96
|
-
const { registrationKey, def, seq, mergedOptions, resolvedTarget } = row;
|
|
97
|
-
const existing = prevRegistrations.get(registrationKey);
|
|
98
|
-
if (existing?.handle.isActive && existing.target === resolvedTarget) {
|
|
99
|
-
existing.handle.callback = def.callback;
|
|
100
|
-
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
101
|
-
existing.handle.setOptions(optionsWithoutTarget);
|
|
102
|
-
nextRegistrations.set(registrationKey, existing);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
if (existing?.handle.isActive) existing.handle.unregister();
|
|
106
|
-
const handle = managerRef.current.register(seq, def.callback, {
|
|
107
|
-
...mergedOptions,
|
|
108
|
-
target: resolvedTarget
|
|
109
|
-
});
|
|
110
|
-
nextRegistrations.set(registrationKey, {
|
|
111
|
-
handle,
|
|
112
|
-
target: resolvedTarget
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
registrationsRef.current = nextRegistrations;
|
|
116
|
-
});
|
|
117
|
-
(0, react.useEffect)(() => {
|
|
118
|
-
return () => {
|
|
119
|
-
for (const { handle } of registrationsRef.current.values()) if (handle.isActive) handle.unregister();
|
|
120
|
-
registrationsRef.current = /* @__PURE__ */ new Map();
|
|
121
|
-
};
|
|
122
|
-
}, []);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
//#endregion
|
|
126
|
-
exports.useHotkeySequences = useHotkeySequences;
|
|
127
|
-
//# sourceMappingURL=useHotkeySequences.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequences.cjs","names":["useDefaultHotkeysOptions","isRef"],"sources":["../src/useHotkeySequences.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type { UseHotkeySequenceOptions } from './useHotkeySequence'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A single sequence definition for use with `useHotkeySequences`.\n */\nexport interface UseHotkeySequenceDefinition {\n /** Array of hotkey strings that form the sequence */\n sequence: HotkeySequence\n /** The function to call when the sequence is completed */\n callback: HotkeyCallback\n /** Per-sequence options (merged on top of commonOptions) */\n options?: UseHotkeySequenceOptions\n}\n\n/**\n * React hook for registering multiple keyboard shortcut sequences at once (Vim-style).\n *\n * Uses the singleton SequenceManager. Accepts a dynamic array of definitions so you can\n * register 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 * Definitions with an empty `sequence` are skipped (no registration).\n *\n * @param definitions - Array of sequence definitions to register\n * @param commonOptions - Shared options applied to all sequences (overridden by per-definition options).\n * Per-row `enabled: false` still registers that sequence: `SequenceManager` suppresses execution only (the row\n * stays in the store and appears in TanStack Hotkeys devtools). Toggling `enabled` updates the existing handle\n * via `setOptions` (no unregister/re-register churn).\n *\n * @example\n * ```tsx\n * function VimPalette() {\n * useHotkeySequences([\n * { sequence: ['G', 'G'], callback: () => scrollToTop() },\n * { sequence: ['D', 'D'], callback: () => deleteLine() },\n * { sequence: ['C', 'I', 'W'], callback: () => changeInnerWord(), options: { timeout: 500 } },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function DynamicSequences({ items }) {\n * useHotkeySequences(\n * items.map((item) => ({\n * sequence: item.chords,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function useHotkeySequences(\n definitions: Array<UseHotkeySequenceDefinition>,\n commonOptions: UseHotkeySequenceOptions = {},\n): void {\n type RegistrationRecord = {\n handle: SequenceRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions().hotkeySequence\n const manager = getSequenceManager()\n\n const registrationsRef = useRef<Map<string, RegistrationRecord>>(new Map())\n const definitionsRef = useRef(definitions)\n const sequenceStringsRef = useRef<Array<string>>([])\n const commonOptionsRef = useRef(commonOptions)\n const defaultOptionsRef = useRef(defaultOptions)\n const managerRef = useRef(manager)\n\n const sequenceStrings = definitions.map((def) =>\n formatHotkeySequence(def.sequence),\n )\n\n definitionsRef.current = definitions\n sequenceStringsRef.current = sequenceStrings\n commonOptionsRef.current = commonOptions\n defaultOptionsRef.current = defaultOptions\n managerRef.current = manager\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 definitionsRef.current)[number]\n seq: HotkeySequence\n seqStr: string\n mergedOptions: UseHotkeySequenceOptions\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < definitionsRef.current.length; i++) {\n const def = definitionsRef.current[i]!\n const seqStr = sequenceStringsRef.current[i]!\n const seq = def.sequence\n if (seq.length === 0) {\n continue\n }\n\n const mergedOptions = {\n ...defaultOptionsRef.current,\n ...commonOptionsRef.current,\n ...def.options,\n } as UseHotkeySequenceOptions\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}:${seqStr}`\n rows.push({\n registrationKey,\n def,\n seq,\n seqStr,\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, seq, mergedOptions, resolvedTarget } = row\n\n const existing = prevRegistrations.get(registrationKey)\n if (existing?.handle.isActive && existing.target === resolvedTarget) {\n // Publish callback/options only after commit, never during render.\n existing.handle.callback = def.callback\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\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(seq, 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\n useEffect(() => {\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 }, [])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,SAAgB,mBACd,aACA,gBAA0C,EAAE,EACtC;CAMN,MAAM,iBAAiBA,kDAA0B,CAAC;CAClD,MAAM,qDAA8B;CAEpC,MAAM,qDAA2D,IAAI,KAAK,CAAC;CAC3E,MAAM,mCAAwB,YAAY;CAC1C,MAAM,uCAA2C,EAAE,CAAC;CACpD,MAAM,qCAA0B,cAAc;CAC9C,MAAM,sCAA2B,eAAe;CAChD,MAAM,+BAAoB,QAAQ;CAElC,MAAM,kBAAkB,YAAY,KAAK,oDAClB,IAAI,SAAS,CACnC;AAED,gBAAe,UAAU;AACzB,oBAAmB,UAAU;AAC7B,kBAAiB,UAAU;AAC3B,mBAAkB,UAAU;AAC5B,YAAW,UAAU;AAErB,4BAAgB;EACd,MAAM,oBAAoB,iBAAiB;EAC3C,MAAM,oCAAoB,IAAI,KAAiC;EAE/D,MAAM,OAOD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,eAAe,QAAQ,QAAQ,KAAK;GACtD,MAAM,MAAM,eAAe,QAAQ;GACnC,MAAM,SAAS,mBAAmB,QAAQ;GAC1C,MAAM,MAAM,IAAI;AAChB,OAAI,IAAI,WAAW,EACjB;GAGF,MAAM,gBAAgB;IACpB,GAAG,kBAAkB;IACrB,GAAG,iBAAiB;IACpB,GAAG,IAAI;IACR;G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back, HotkeySequence } from "@tanstack/hotkeys";
|
|
3
|
-
|
|
4
|
-
//#region src/useHotkeySequences.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* A single sequence definition for use with `useHotkeySequences`.
|
|
7
|
-
*/
|
|
8
|
-
interface UseHotkeySequenceDefinition {
|
|
9
|
-
/** Array of hotkey strings that form the sequence */
|
|
10
|
-
sequence: HotkeySequence;
|
|
11
|
-
/** The function to call when the sequence is completed */
|
|
12
|
-
callback: HotkeyCallback;
|
|
13
|
-
/** Per-sequence options (merged on top of commonOptions) */
|
|
14
|
-
options?: UseHotkeySequenceOptions;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* React hook for registering multiple keyboard shortcut sequences at once (Vim-style).
|
|
18
|
-
*
|
|
19
|
-
* Uses the singleton SequenceManager. Accepts a dynamic array of definitions so you can
|
|
20
|
-
* register variable-length lists without violating the rules of hooks.
|
|
21
|
-
*
|
|
22
|
-
* Options are merged in this order:
|
|
23
|
-
* HotkeysProvider defaults < commonOptions < per-definition options
|
|
24
|
-
*
|
|
25
|
-
* Callbacks and options are synced on every render to avoid stale closures.
|
|
26
|
-
*
|
|
27
|
-
* Definitions with an empty `sequence` are skipped (no registration).
|
|
28
|
-
*
|
|
29
|
-
* @param definitions - Array of sequence definitions to register
|
|
30
|
-
* @param commonOptions - Shared options applied to all sequences (overridden by per-definition options).
|
|
31
|
-
* Per-row `enabled: false` still registers that sequence: `SequenceManager` suppresses execution only (the row
|
|
32
|
-
* stays in the store and appears in TanStack Hotkeys devtools). Toggling `enabled` updates the existing handle
|
|
33
|
-
* via `setOptions` (no unregister/re-register churn).
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```tsx
|
|
37
|
-
* function VimPalette() {
|
|
38
|
-
* useHotkeySequences([
|
|
39
|
-
* { sequence: ['G', 'G'], callback: () => scrollToTop() },
|
|
40
|
-
* { sequence: ['D', 'D'], callback: () => deleteLine() },
|
|
41
|
-
* { sequence: ['C', 'I', 'W'], callback: () => changeInnerWord(), options: { timeout: 500 } },
|
|
42
|
-
* ])
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```tsx
|
|
48
|
-
* function DynamicSequences({ items }) {
|
|
49
|
-
* useHotkeySequences(
|
|
50
|
-
* items.map((item) => ({
|
|
51
|
-
* sequence: item.chords,
|
|
52
|
-
* callback: item.action,
|
|
53
|
-
* options: { enabled: item.enabled },
|
|
54
|
-
* })),
|
|
55
|
-
* { preventDefault: true },
|
|
56
|
-
* )
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
declare function useHotkeySequences(definitions: Array<UseHotkeySequenceDefinition>, commonOptions?: UseHotkeySequenceOptions): void;
|
|
61
|
-
//#endregion
|
|
62
|
-
export { UseHotkeySequenceDefinition, useHotkeySequences };
|
|
63
|
-
//# sourceMappingURL=useHotkeySequences.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequences.js","names":[],"sources":["../src/useHotkeySequences.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type { UseHotkeySequenceOptions } from './useHotkeySequence'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A single sequence definition for use with `useHotkeySequences`.\n */\nexport interface UseHotkeySequenceDefinition {\n /** Array of hotkey strings that form the sequence */\n sequence: HotkeySequence\n /** The function to call when the sequence is completed */\n callback: HotkeyCallback\n /** Per-sequence options (merged on top of commonOptions) */\n options?: UseHotkeySequenceOptions\n}\n\n/**\n * React hook for registering multiple keyboard shortcut sequences at once (Vim-style).\n *\n * Uses the singleton SequenceManager. Accepts a dynamic array of definitions so you can\n * register 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 * Definitions with an empty `sequence` are skipped (no registration).\n *\n * @param definitions - Array of sequence definitions to register\n * @param commonOptions - Shared options applied to all sequences (overridden by per-definition options).\n * Per-row `enabled: false` still registers that sequence: `SequenceManager` suppresses execution only (the row\n * stays in the store and appears in TanStack Hotkeys devtools). Toggling `enabled` updates the existing handle\n * via `setOptions` (no unregister/re-register churn).\n *\n * @example\n * ```tsx\n * function VimPalette() {\n * useHotkeySequences([\n * { sequence: ['G', 'G'], callback: () => scrollToTop() },\n * { sequence: ['D', 'D'], callback: () => deleteLine() },\n * { sequence: ['C', 'I', 'W'], callback: () => changeInnerWord(), options: { timeout: 500 } },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function DynamicSequences({ items }) {\n * useHotkeySequences(\n * items.map((item) => ({\n * sequence: item.chords,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function useHotkeySequences(\n definitions: Array<UseHotkeySequenceDefinition>,\n commonOptions: UseHotkeySequenceOptions = {},\n): void {\n type RegistrationRecord = {\n handle: SequenceRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions().hotkeySequence\n const manager = getSequenceManager()\n\n const registrationsRef = useRef<Map<string, RegistrationRecord>>(new Map())\n const definitionsRef = useRef(definitions)\n const sequenceStringsRef = useRef<Array<string>>([])\n const commonOptionsRef = useRef(commonOptions)\n const defaultOptionsRef = useRef(defaultOptions)\n const managerRef = useRef(manager)\n\n const sequenceStrings = definitions.map((def) =>\n formatHotkeySequence(def.sequence),\n )\n\n definitionsRef.current = definitions\n sequenceStringsRef.current = sequenceStrings\n commonOptionsRef.current = commonOptions\n defaultOptionsRef.current = defaultOptions\n managerRef.current = manager\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 definitionsRef.current)[number]\n seq: HotkeySequence\n seqStr: string\n mergedOptions: UseHotkeySequenceOptions\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < definitionsRef.current.length; i++) {\n const def = definitionsRef.current[i]!\n const seqStr = sequenceStringsRef.current[i]!\n const seq = def.sequence\n if (seq.length === 0) {\n continue\n }\n\n const mergedOptions = {\n ...defaultOptionsRef.current,\n ...commonOptionsRef.current,\n ...def.options,\n } as UseHotkeySequenceOptions\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}:${seqStr}`\n rows.push({\n registrationKey,\n def,\n seq,\n seqStr,\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, seq, mergedOptions, resolvedTarget } = row\n\n const existing = prevRegistrations.get(registrationKey)\n if (existing?.handle.isActive && existing.target === resolvedTarget) {\n // Publish callback/options only after commit, never during render.\n existing.handle.callback = def.callback\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\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(seq, 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\n useEffect(() => {\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 }, [])\n}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