@tanstack/solid-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 -9
- package/dist/HotkeysProvider.js +1 -2
- package/dist/createHeldKeyCodes.d.ts +2 -4
- package/dist/createHeldKeyCodes.js +3 -3
- package/dist/createHeldKeys.d.ts +2 -4
- package/dist/createHeldKeys.js +3 -3
- package/dist/createHotkey.d.ts +3 -6
- package/dist/createHotkey.js +3 -3
- package/dist/createHotkeyHint.d.ts +2 -5
- package/dist/createHotkeyHint.js +1 -2
- package/dist/createHotkeyRecorder.d.ts +3 -6
- package/dist/createHotkeyRecorder.js +4 -4
- package/dist/createHotkeyRegistrations.d.ts +3 -6
- package/dist/createHotkeyRegistrations.js +1 -2
- package/dist/createHotkeySequence.d.ts +3 -6
- package/dist/createHotkeySequence.js +1 -2
- package/dist/createHotkeySequenceRecorder.d.ts +3 -6
- package/dist/createHotkeySequenceRecorder.js +4 -4
- package/dist/createHotkeySequences.d.ts +3 -6
- package/dist/createHotkeySequences.js +1 -2
- package/dist/createHotkeys.d.ts +3 -6
- package/dist/createHotkeys.js +1 -2
- package/dist/createKeyHold.d.ts +2 -5
- package/dist/createKeyHold.js +3 -3
- package/package.json +12 -17
- package/dist/HotkeysProvider.cjs +0 -27
- package/dist/HotkeysProvider.cjs.map +0 -1
- package/dist/HotkeysProvider.d.cts +0 -25
- package/dist/HotkeysProvider.js.map +0 -1
- package/dist/createHeldKeyCodes.cjs +0 -42
- package/dist/createHeldKeyCodes.cjs.map +0 -1
- package/dist/createHeldKeyCodes.d.cts +0 -36
- package/dist/createHeldKeyCodes.js.map +0 -1
- package/dist/createHeldKeys.cjs +0 -33
- package/dist/createHeldKeys.cjs.map +0 -1
- package/dist/createHeldKeys.d.cts +0 -27
- package/dist/createHeldKeys.js.map +0 -1
- package/dist/createHotkey.cjs +0 -120
- package/dist/createHotkey.cjs.map +0 -1
- package/dist/createHotkey.d.cts +0 -72
- package/dist/createHotkey.js.map +0 -1
- package/dist/createHotkeyHint.cjs +0 -20
- package/dist/createHotkeyHint.cjs.map +0 -1
- package/dist/createHotkeyHint.d.cts +0 -14
- package/dist/createHotkeyHint.js.map +0 -1
- package/dist/createHotkeyRecorder.cjs +0 -78
- package/dist/createHotkeyRecorder.cjs.map +0 -1
- package/dist/createHotkeyRecorder.d.cts +0 -60
- package/dist/createHotkeyRecorder.js.map +0 -1
- package/dist/createHotkeyRegistrations.cjs +0 -26
- package/dist/createHotkeyRegistrations.cjs.map +0 -1
- package/dist/createHotkeyRegistrations.d.cts +0 -26
- package/dist/createHotkeyRegistrations.js.map +0 -1
- package/dist/createHotkeySequence.cjs +0 -107
- package/dist/createHotkeySequence.cjs.map +0 -1
- package/dist/createHotkeySequence.d.cts +0 -56
- package/dist/createHotkeySequence.js.map +0 -1
- package/dist/createHotkeySequenceRecorder.cjs +0 -43
- package/dist/createHotkeySequenceRecorder.cjs.map +0 -1
- package/dist/createHotkeySequenceRecorder.d.cts +0 -19
- package/dist/createHotkeySequenceRecorder.js.map +0 -1
- package/dist/createHotkeySequences.cjs +0 -112
- package/dist/createHotkeySequences.cjs.map +0 -1
- package/dist/createHotkeySequences.d.cts +0 -57
- package/dist/createHotkeySequences.js.map +0 -1
- package/dist/createHotkeys.cjs +0 -112
- package/dist/createHotkeys.cjs.map +0 -1
- package/dist/createHotkeys.d.cts +0 -57
- package/dist/createHotkeys.js.map +0 -1
- package/dist/createKeyHold.cjs +0 -56
- package/dist/createKeyHold.cjs.map +0 -1
- package/dist/createKeyHold.d.cts +0 -47
- package/dist/createKeyHold.js.map +0 -1
- package/dist/index.cjs +0 -35
- package/dist/index.d.cts +0 -14
- package/src/HotkeysProvider.tsx +0 -51
- package/src/createHeldKeyCodes.ts +0 -38
- package/src/createHeldKeys.ts +0 -29
- package/src/createHotkey.ts +0 -172
- package/src/createHotkeyHint.ts +0 -28
- package/src/createHotkeyRecorder.ts +0 -103
- package/src/createHotkeyRegistrations.ts +0 -45
- package/src/createHotkeySequence.ts +0 -155
- package/src/createHotkeySequenceRecorder.ts +0 -66
- package/src/createHotkeySequences.ts +0 -181
- package/src/createHotkeys.ts +0 -187
- package/src/createKeyHold.ts +0 -59
- package/src/index.ts +0 -18
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let solid_js = require("solid-js");
|
|
4
|
-
|
|
5
|
-
//#region src/createHotkeySequence.ts
|
|
6
|
-
/**
|
|
7
|
-
* SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).
|
|
8
|
-
*
|
|
9
|
-
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
10
|
-
* that trigger when the full sequence is pressed within a timeout.
|
|
11
|
-
*
|
|
12
|
-
* Each step may include modifiers. You can chain the same modifier across
|
|
13
|
-
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
14
|
-
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
15
|
-
* advance the sequence or reset progress.
|
|
16
|
-
*
|
|
17
|
-
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
18
|
-
* @param callback - Function to call when the sequence is completed
|
|
19
|
-
* @param options - Options for the sequence behavior (or accessor function)
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* function VimEditor() {
|
|
24
|
-
* // 'g g' to go to top
|
|
25
|
-
* createHotkeySequence(['G', 'G'], () => {
|
|
26
|
-
* scrollToTop()
|
|
27
|
-
* })
|
|
28
|
-
*
|
|
29
|
-
* // 'd d' to delete line
|
|
30
|
-
* createHotkeySequence(['D', 'D'], () => {
|
|
31
|
-
* deleteLine()
|
|
32
|
-
* })
|
|
33
|
-
*
|
|
34
|
-
* // 'd i w' to delete inner word
|
|
35
|
-
* createHotkeySequence(['D', 'I', 'W'], () => {
|
|
36
|
-
* deleteInnerWord()
|
|
37
|
-
* }, { timeout: 500 })
|
|
38
|
-
*
|
|
39
|
-
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
40
|
-
* createHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
41
|
-
* nextAction()
|
|
42
|
-
* })
|
|
43
|
-
*
|
|
44
|
-
* return <div>...</div>
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
function createHotkeySequence(sequence, callback, options = {}) {
|
|
49
|
-
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
50
|
-
const manager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
51
|
-
let registration = null;
|
|
52
|
-
let lastSequenceKey = null;
|
|
53
|
-
let lastTarget = null;
|
|
54
|
-
(0, solid_js.onCleanup)(() => {
|
|
55
|
-
if (registration?.isActive) {
|
|
56
|
-
registration.unregister();
|
|
57
|
-
registration = null;
|
|
58
|
-
}
|
|
59
|
-
lastSequenceKey = null;
|
|
60
|
-
lastTarget = null;
|
|
61
|
-
});
|
|
62
|
-
(0, solid_js.createEffect)(() => {
|
|
63
|
-
const resolvedSequence = typeof sequence === "function" ? sequence() : sequence;
|
|
64
|
-
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
65
|
-
const mergedOptions = {
|
|
66
|
-
...defaultOptions.hotkeySequence,
|
|
67
|
-
...resolvedOptions
|
|
68
|
-
};
|
|
69
|
-
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
70
|
-
const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
|
|
71
|
-
if (resolvedSequence.length === 0 || !resolvedTarget) {
|
|
72
|
-
if (registration?.isActive) {
|
|
73
|
-
registration.unregister();
|
|
74
|
-
registration = null;
|
|
75
|
-
}
|
|
76
|
-
lastSequenceKey = null;
|
|
77
|
-
lastTarget = null;
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const sequenceKey = (0, _tanstack_hotkeys.formatHotkeySequence)(resolvedSequence);
|
|
81
|
-
(0, solid_js.untrack)(() => {
|
|
82
|
-
if (registration?.isActive && lastSequenceKey === sequenceKey && lastTarget === resolvedTarget) {
|
|
83
|
-
registration.callback = callback;
|
|
84
|
-
registration.setOptions(optionsWithoutTarget);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (registration?.isActive) {
|
|
88
|
-
registration.unregister();
|
|
89
|
-
registration = null;
|
|
90
|
-
}
|
|
91
|
-
registration = manager.register(resolvedSequence, callback, {
|
|
92
|
-
...mergedOptions,
|
|
93
|
-
target: resolvedTarget
|
|
94
|
-
});
|
|
95
|
-
if (registration.isActive) {
|
|
96
|
-
registration.callback = callback;
|
|
97
|
-
registration.setOptions(optionsWithoutTarget);
|
|
98
|
-
}
|
|
99
|
-
lastSequenceKey = sequenceKey;
|
|
100
|
-
lastTarget = resolvedTarget;
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
//#endregion
|
|
106
|
-
exports.createHotkeySequence = createHotkeySequence;
|
|
107
|
-
//# sourceMappingURL=createHotkeySequence.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeySequence.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkeySequence.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor, or null. Defaults to document.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).\n *\n * This primitive 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 (or accessor function)\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior (or accessor function)\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * createHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * createHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * createHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * // Same modifier on consecutive steps (bare Shift between chords is ignored)\n * createHotkeySequence(['Shift+R', 'Shift+T'], () => {\n * nextAction()\n * })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function createHotkeySequence(\n sequence: HotkeySequence | (() => HotkeySequence),\n callback: HotkeyCallback,\n options:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getSequenceManager()\n\n let registration: SequenceRegistrationHandle | null = null\n let lastSequenceKey: string | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n })\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedSequence =\n typeof sequence === 'function' ? sequence() : sequence\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedOptions,\n } as CreateHotkeySequenceOptions\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches createHotkey.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (resolvedSequence.length === 0 || !resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n return\n }\n\n const sequenceKey = formatHotkeySequence(resolvedSequence)\n\n // Untrack store mutations so that registering/updating the sequence doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n if (\n registration?.isActive &&\n lastSequenceKey === sequenceKey &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastSequenceKey = sequenceKey\n lastTarget = resolvedTarget\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,qDAA8B;CAEpC,IAAI,eAAkD;CACtD,IAAI,kBAAiC;CACrC,IAAI,aAAqD;AAEzD,+BAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,oBAAkB;AAClB,eAAa;GACb;AAEF,kCAAmB;EAEjB,MAAM,mBACJ,OAAO,aAAa,aAAa,UAAU,GAAG;EAChD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;EAIrD,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,iBAAiB,WAAW,KAAK,CAAC,gBAAgB;AACpD,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,qBAAkB;AAClB,gBAAa;AACb;;EAGF,MAAM,0DAAmC,iBAAiB;AAK1D,8BAAc;AACZ,OACE,cAAc,YACd,oBAAoB,eACpB,eAAe,gBACf;AACA,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;AAC7C;;AAGF,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAGjB,kBAAe,QAAQ,SAAS,kBAAkB,UAAU;IAC1D,GAAG;IACH,QAAQ;IACT,CAAC;AAEF,OAAI,aAAa,UAAU;AACzB,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;;AAG/C,qBAAkB;AAClB,gBAAa;IACb;GACF"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { HotkeyCallback, HotkeySequence, SequenceOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/createHotkeySequence.d.ts
|
|
4
|
-
interface CreateHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
5
|
-
/**
|
|
6
|
-
* The DOM element to attach the event listener to.
|
|
7
|
-
* Can be a direct DOM element, an accessor, or null. Defaults to document.
|
|
8
|
-
*/
|
|
9
|
-
target?: HTMLElement | Document | Window | null;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).
|
|
13
|
-
*
|
|
14
|
-
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
15
|
-
* that trigger when the full sequence is pressed within a timeout.
|
|
16
|
-
*
|
|
17
|
-
* Each step may include modifiers. You can chain the same modifier across
|
|
18
|
-
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
19
|
-
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
20
|
-
* advance the sequence or reset progress.
|
|
21
|
-
*
|
|
22
|
-
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
23
|
-
* @param callback - Function to call when the sequence is completed
|
|
24
|
-
* @param options - Options for the sequence behavior (or accessor function)
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```tsx
|
|
28
|
-
* function VimEditor() {
|
|
29
|
-
* // 'g g' to go to top
|
|
30
|
-
* createHotkeySequence(['G', 'G'], () => {
|
|
31
|
-
* scrollToTop()
|
|
32
|
-
* })
|
|
33
|
-
*
|
|
34
|
-
* // 'd d' to delete line
|
|
35
|
-
* createHotkeySequence(['D', 'D'], () => {
|
|
36
|
-
* deleteLine()
|
|
37
|
-
* })
|
|
38
|
-
*
|
|
39
|
-
* // 'd i w' to delete inner word
|
|
40
|
-
* createHotkeySequence(['D', 'I', 'W'], () => {
|
|
41
|
-
* deleteInnerWord()
|
|
42
|
-
* }, { timeout: 500 })
|
|
43
|
-
*
|
|
44
|
-
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
45
|
-
* createHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
46
|
-
* nextAction()
|
|
47
|
-
* })
|
|
48
|
-
*
|
|
49
|
-
* return <div>...</div>
|
|
50
|
-
* }
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
declare function createHotkeySequence(sequence: HotkeySequence | (() => HotkeySequence), callback: HotkeyCallback, options?: CreateHotkeySequenceOptions | (() => CreateHotkeySequenceOptions)): void;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { CreateHotkeySequenceOptions, createHotkeySequence };
|
|
56
|
-
//# sourceMappingURL=createHotkeySequence.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeySequence.js","names":[],"sources":["../src/createHotkeySequence.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor, or null. Defaults to document.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).\n *\n * This primitive 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 (or accessor function)\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior (or accessor function)\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * createHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * createHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * createHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * // Same modifier on consecutive steps (bare Shift between chords is ignored)\n * createHotkeySequence(['Shift+R', 'Shift+T'], () => {\n * nextAction()\n * })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function createHotkeySequence(\n sequence: HotkeySequence | (() => HotkeySequence),\n callback: HotkeyCallback,\n options:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getSequenceManager()\n\n let registration: SequenceRegistrationHandle | null = null\n let lastSequenceKey: string | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n })\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedSequence =\n typeof sequence === 'function' ? sequence() : sequence\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedOptions,\n } as CreateHotkeySequenceOptions\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches createHotkey.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (resolvedSequence.length === 0 || !resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n return\n }\n\n const sequenceKey = formatHotkeySequence(resolvedSequence)\n\n // Untrack store mutations so that registering/updating the sequence doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n if (\n registration?.isActive &&\n lastSequenceKey === sequenceKey &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastSequenceKey = sequenceKey\n lastTarget = resolvedTarget\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,oBAAoB;CAEpC,IAAI,eAAkD;CACtD,IAAI,kBAAiC;CACrC,IAAI,aAAqD;AAEzD,iBAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,oBAAkB;AAClB,eAAa;GACb;AAEF,oBAAmB;EAEjB,MAAM,mBACJ,OAAO,aAAa,aAAa,UAAU,GAAG;EAChD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;EAIrD,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,iBAAiB,WAAW,KAAK,CAAC,gBAAgB;AACpD,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,qBAAkB;AAClB,gBAAa;AACb;;EAGF,MAAM,cAAc,qBAAqB,iBAAiB;AAK1D,gBAAc;AACZ,OACE,cAAc,YACd,oBAAoB,eACpB,eAAe,gBACf;AACA,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;AAC7C;;AAGF,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAGjB,kBAAe,QAAQ,SAAS,kBAAkB,UAAU;IAC1D,GAAG;IACH,QAAQ;IACT,CAAC;AAEF,OAAI,aAAa,UAAU;AACzB,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;;AAG/C,qBAAkB;AAClB,gBAAa;IACb;GACF"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let solid_js = require("solid-js");
|
|
4
|
-
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
5
|
-
|
|
6
|
-
//#region src/createHotkeySequenceRecorder.ts
|
|
7
|
-
/**
|
|
8
|
-
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
9
|
-
*/
|
|
10
|
-
function createHotkeySequenceRecorder(options) {
|
|
11
|
-
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
12
|
-
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
13
|
-
const recorder = new _tanstack_hotkeys.HotkeySequenceRecorder({
|
|
14
|
-
...defaultOptions.hotkeySequenceRecorder,
|
|
15
|
-
...resolvedOptions
|
|
16
|
-
});
|
|
17
|
-
const isRecording = (0, _tanstack_solid_store.useSelector)(recorder.store, (state) => state.isRecording);
|
|
18
|
-
const steps = (0, _tanstack_solid_store.useSelector)(recorder.store, (state) => state.steps);
|
|
19
|
-
const recordedSequence = (0, _tanstack_solid_store.useSelector)(recorder.store, (state) => state.recordedSequence);
|
|
20
|
-
(0, solid_js.createEffect)(() => {
|
|
21
|
-
const resolved = typeof options === "function" ? options() : options;
|
|
22
|
-
recorder.setOptions({
|
|
23
|
-
...defaultOptions.hotkeySequenceRecorder,
|
|
24
|
-
...resolved
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
(0, solid_js.onCleanup)(() => {
|
|
28
|
-
recorder.destroy();
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
isRecording,
|
|
32
|
-
steps,
|
|
33
|
-
recordedSequence,
|
|
34
|
-
startRecording: () => recorder.start(),
|
|
35
|
-
stopRecording: () => recorder.stop(),
|
|
36
|
-
cancelRecording: () => recorder.cancel(),
|
|
37
|
-
commitRecording: () => recorder.commit()
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
exports.createHotkeySequenceRecorder = createHotkeySequenceRecorder;
|
|
43
|
-
//# sourceMappingURL=createHotkeySequenceRecorder.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeySequenceRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeySequenceRecorder"],"sources":["../src/createHotkeySequenceRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useSelector } from '@tanstack/solid-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface SolidHotkeySequenceRecorder {\n isRecording: () => boolean\n steps: () => HotkeySequence\n recordedSequence: () => HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function createHotkeySequenceRecorder(\n options:\n | HotkeySequenceRecorderOptions\n | (() => HotkeySequenceRecorderOptions),\n): SolidHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolvedOptions,\n } as HotkeySequenceRecorderOptions\n\n const recorder = new HotkeySequenceRecorder(mergedOptions)\n\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const steps = useSelector(recorder.store, (state) => state.steps)\n const recordedSequence = useSelector(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolved,\n } as HotkeySequenceRecorderOptions)\n })\n\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,6BACd,SAG6B;CAC7B,MAAM,iBAAiBA,kDAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAMpE,MAAM,WAAW,IAAIC,yCALC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAEyD;CAE1D,MAAM,qDAA0B,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,+CAAoB,SAAS,QAAQ,UAAU,MAAM,MAAM;CACjE,MAAM,0DACJ,SAAS,QACR,UAAU,MAAM,iBAClB;AAED,kCAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAAkC;GACnC;AAEF,+BAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/createHotkeySequenceRecorder.d.ts
|
|
4
|
-
interface SolidHotkeySequenceRecorder {
|
|
5
|
-
isRecording: () => boolean;
|
|
6
|
-
steps: () => HotkeySequence;
|
|
7
|
-
recordedSequence: () => HotkeySequence | null;
|
|
8
|
-
startRecording: () => void;
|
|
9
|
-
stopRecording: () => void;
|
|
10
|
-
cancelRecording: () => void;
|
|
11
|
-
commitRecording: () => void;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
15
|
-
*/
|
|
16
|
-
declare function createHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions | (() => HotkeySequenceRecorderOptions)): SolidHotkeySequenceRecorder;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder };
|
|
19
|
-
//# sourceMappingURL=createHotkeySequenceRecorder.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeySequenceRecorder.js","names":[],"sources":["../src/createHotkeySequenceRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useSelector } from '@tanstack/solid-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface SolidHotkeySequenceRecorder {\n isRecording: () => boolean\n steps: () => HotkeySequence\n recordedSequence: () => HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function createHotkeySequenceRecorder(\n options:\n | HotkeySequenceRecorderOptions\n | (() => HotkeySequenceRecorderOptions),\n): SolidHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolvedOptions,\n } as HotkeySequenceRecorderOptions\n\n const recorder = new HotkeySequenceRecorder(mergedOptions)\n\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const steps = useSelector(recorder.store, (state) => state.steps)\n const recordedSequence = useSelector(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolved,\n } as HotkeySequenceRecorderOptions)\n })\n\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,6BACd,SAG6B;CAC7B,MAAM,iBAAiB,0BAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAMpE,MAAM,WAAW,IAAI,uBALC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAEyD;CAE1D,MAAM,cAAc,YAAY,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,QAAQ,YAAY,SAAS,QAAQ,UAAU,MAAM,MAAM;CACjE,MAAM,mBAAmB,YACvB,SAAS,QACR,UAAU,MAAM,iBAClB;AAED,oBAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAAkC;GACnC;AAEF,iBAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC"}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let solid_js = require("solid-js");
|
|
4
|
-
|
|
5
|
-
//#region src/createHotkeySequences.ts
|
|
6
|
-
/**
|
|
7
|
-
* SolidJS primitive for registering multiple keyboard shortcut sequences at once (Vim-style).
|
|
8
|
-
*
|
|
9
|
-
* Uses the singleton SequenceManager. Accepts a dynamic array of definitions, or accessors,
|
|
10
|
-
* so you can react to variable-length lists.
|
|
11
|
-
*
|
|
12
|
-
* Options are merged in this order:
|
|
13
|
-
* HotkeysProvider defaults < commonOptions < per-definition options
|
|
14
|
-
*
|
|
15
|
-
* Definitions with an empty `sequence` are skipped (no registration).
|
|
16
|
-
*
|
|
17
|
-
* @param sequences - Array of sequence definitions, or accessor returning them
|
|
18
|
-
* @param commonOptions - Shared options for all sequences, or accessor
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```tsx
|
|
22
|
-
* function VimPalette() {
|
|
23
|
-
* createHotkeySequences([
|
|
24
|
-
* { sequence: ['G', 'G'], callback: () => scrollToTop() },
|
|
25
|
-
* { sequence: ['D', 'D'], callback: () => deleteLine() },
|
|
26
|
-
* ])
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* function Dynamic(props) {
|
|
33
|
-
* createHotkeySequences(
|
|
34
|
-
* () => props.items.map((item) => ({
|
|
35
|
-
* sequence: item.chords,
|
|
36
|
-
* callback: item.action,
|
|
37
|
-
* options: { enabled: item.enabled },
|
|
38
|
-
* })),
|
|
39
|
-
* { preventDefault: true },
|
|
40
|
-
* )
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
function createHotkeySequences(sequences, commonOptions = {}) {
|
|
45
|
-
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
46
|
-
const manager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
47
|
-
const registrations = /* @__PURE__ */ new Map();
|
|
48
|
-
(0, solid_js.onCleanup)(() => {
|
|
49
|
-
for (const { handle } of registrations.values()) if (handle.isActive) handle.unregister();
|
|
50
|
-
registrations.clear();
|
|
51
|
-
});
|
|
52
|
-
(0, solid_js.createEffect)(() => {
|
|
53
|
-
const resolved = typeof sequences === "function" ? sequences() : sequences;
|
|
54
|
-
const resolvedCommonOptions = typeof commonOptions === "function" ? commonOptions() : commonOptions;
|
|
55
|
-
const nextKeys = /* @__PURE__ */ new Set();
|
|
56
|
-
const prepared = [];
|
|
57
|
-
for (let i = 0; i < resolved.length; i++) {
|
|
58
|
-
const def = resolved[i];
|
|
59
|
-
const resolvedDefOptions = def.options ?? {};
|
|
60
|
-
const mergedOptions = {
|
|
61
|
-
...defaultOptions.hotkeySequence,
|
|
62
|
-
...resolvedCommonOptions,
|
|
63
|
-
...resolvedDefOptions
|
|
64
|
-
};
|
|
65
|
-
if (def.sequence.length === 0) continue;
|
|
66
|
-
const sequenceString = (0, _tanstack_hotkeys.formatHotkeySequence)(def.sequence);
|
|
67
|
-
const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
|
|
68
|
-
if (!resolvedTarget) continue;
|
|
69
|
-
const registrationKey = `${i}:${sequenceString}`;
|
|
70
|
-
nextKeys.add(registrationKey);
|
|
71
|
-
prepared.push({
|
|
72
|
-
registrationKey,
|
|
73
|
-
def,
|
|
74
|
-
mergedOptions,
|
|
75
|
-
sequenceString,
|
|
76
|
-
resolvedTarget
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
(0, solid_js.untrack)(() => {
|
|
80
|
-
for (const [key, record] of [...registrations.entries()]) if (!nextKeys.has(key)) {
|
|
81
|
-
if (record.handle.isActive) record.handle.unregister();
|
|
82
|
-
registrations.delete(key);
|
|
83
|
-
}
|
|
84
|
-
for (const p of prepared) {
|
|
85
|
-
const existing = registrations.get(p.registrationKey);
|
|
86
|
-
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
87
|
-
existing.handle.callback = p.def.callback;
|
|
88
|
-
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
89
|
-
existing.handle.setOptions(optionsWithoutTarget);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (existing) {
|
|
93
|
-
if (existing.handle.isActive) existing.handle.unregister();
|
|
94
|
-
registrations.delete(p.registrationKey);
|
|
95
|
-
}
|
|
96
|
-
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
97
|
-
const handle = manager.register(p.def.sequence, p.def.callback, {
|
|
98
|
-
...optionsWithoutTarget,
|
|
99
|
-
target: p.resolvedTarget
|
|
100
|
-
});
|
|
101
|
-
registrations.set(p.registrationKey, {
|
|
102
|
-
handle,
|
|
103
|
-
target: p.resolvedTarget
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
//#endregion
|
|
111
|
-
exports.createHotkeySequences = createHotkeySequences;
|
|
112
|
-
//# sourceMappingURL=createHotkeySequences.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeySequences.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkeySequences.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A single sequence definition for use with `createHotkeySequences`.\n */\nexport interface CreateHotkeySequenceDefinition {\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?: CreateHotkeySequenceOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard shortcut sequences at once (Vim-style).\n *\n * Uses the singleton SequenceManager. Accepts a dynamic array of definitions, or accessors,\n * so you can react to variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * Definitions with an empty `sequence` are skipped (no registration).\n *\n * @param sequences - Array of sequence definitions, or accessor returning them\n * @param commonOptions - Shared options for all sequences, or accessor\n *\n * @example\n * ```tsx\n * function VimPalette() {\n * createHotkeySequences([\n * { sequence: ['G', 'G'], callback: () => scrollToTop() },\n * { sequence: ['D', 'D'], callback: () => deleteLine() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Dynamic(props) {\n * createHotkeySequences(\n * () => props.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 createHotkeySequences(\n sequences:\n | Array<CreateHotkeySequenceDefinition>\n | (() => Array<CreateHotkeySequenceDefinition>),\n commonOptions:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: SequenceRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getSequenceManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolved = typeof sequences === 'function' ? sequences() : sequences\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeySequenceDefinition\n mergedOptions: CreateHotkeySequenceOptions\n sequenceString: string\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolved.length; i++) {\n const def = resolved[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeySequenceOptions\n\n if (def.sequence.length === 0) {\n continue\n }\n\n const sequenceString = formatHotkeySequence(def.sequence)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${sequenceString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n sequenceString,\n resolvedTarget,\n })\n }\n\n // Untrack store mutations so that registering/updating sequences doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n for (const [key, record] of [...registrations.entries()]) {\n if (!nextKeys.has(key)) {\n if (record.handle.isActive) {\n record.handle.unregister()\n }\n registrations.delete(key)\n }\n }\n\n for (const p of prepared) {\n const existing = registrations.get(p.registrationKey)\n if (existing?.handle.isActive && existing.target === p.resolvedTarget) {\n existing.handle.callback = p.def.callback\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\n continue\n }\n\n if (existing) {\n if (existing.handle.isActive) {\n existing.handle.unregister()\n }\n registrations.delete(p.registrationKey)\n }\n\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n const handle = manager.register(p.def.sequence, p.def.callback, {\n ...optionsWithoutTarget,\n target: p.resolvedTarget,\n })\n registrations.set(p.registrationKey, {\n handle,\n target: p.resolvedTarget,\n })\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,sBACd,WAGA,gBAE0C,EAAE,EACtC;CAMN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,qDAA8B;CAEpC,MAAM,gCAAgB,IAAI,KAAiC;AAE3D,+BAAgB;AACd,OAAK,MAAM,EAAE,YAAY,cAAc,QAAQ,CAC7C,KAAI,OAAO,SACT,QAAO,YAAY;AAGvB,gBAAc,OAAO;GACrB;AAEF,kCAAmB;EACjB,MAAM,WAAW,OAAO,cAAc,aAAa,WAAW,GAAG;EACjE,MAAM,wBACJ,OAAO,kBAAkB,aAAa,eAAe,GAAG;EAE1D,MAAM,2BAAW,IAAI,KAAa;EAClC,MAAM,WAMD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;GACxC,MAAM,MAAM,SAAS;GACrB,MAAM,qBAAqB,IAAI,WAAW,EAAE;GAE5C,MAAM,gBAAgB;IACpB,GAAG,eAAe;IAClB,GAAG;IACH,GAAG;IACJ;AAED,OAAI,IAAI,SAAS,WAAW,EAC1B;GAGF,MAAM,6DAAsC,IAAI,SAAS;GAEzD,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,OAAI,CAAC,eACH;GAGF,MAAM,kBAAkB,GAAG,EAAE,GAAG;AAChC,YAAS,IAAI,gBAAgB;AAC7B,YAAS,KAAK;IACZ;IACA;IACA;IACA;IACA;IACD,CAAC;;AAMJ,8BAAc;AACZ,QAAK,MAAM,CAAC,KAAK,WAAW,CAAC,GAAG,cAAc,SAAS,CAAC,CACtD,KAAI,CAAC,SAAS,IAAI,IAAI,EAAE;AACtB,QAAI,OAAO,OAAO,SAChB,QAAO,OAAO,YAAY;AAE5B,kBAAc,OAAO,IAAI;;AAI7B,QAAK,MAAM,KAAK,UAAU;IACxB,MAAM,WAAW,cAAc,IAAI,EAAE,gBAAgB;AACrD,QAAI,UAAU,OAAO,YAAY,SAAS,WAAW,EAAE,gBAAgB;AACrE,cAAS,OAAO,WAAW,EAAE,IAAI;KACjC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;AACvD,cAAS,OAAO,WAAW,qBAAqB;AAChD;;AAGF,QAAI,UAAU;AACZ,SAAI,SAAS,OAAO,SAClB,UAAS,OAAO,YAAY;AAE9B,mBAAc,OAAO,EAAE,gBAAgB;;IAGzC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;IACvD,MAAM,SAAS,QAAQ,SAAS,EAAE,IAAI,UAAU,EAAE,IAAI,UAAU;KAC9D,GAAG;KACH,QAAQ,EAAE;KACX,CAAC;AACF,kBAAc,IAAI,EAAE,iBAAiB;KACnC;KACA,QAAQ,EAAE;KACX,CAAC;;IAEJ;GACF"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { CreateHotkeySequenceOptions } from "./createHotkeySequence.cjs";
|
|
2
|
-
import { HotkeyCallback, HotkeySequence } from "@tanstack/hotkeys";
|
|
3
|
-
|
|
4
|
-
//#region src/createHotkeySequences.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* A single sequence definition for use with `createHotkeySequences`.
|
|
7
|
-
*/
|
|
8
|
-
interface CreateHotkeySequenceDefinition {
|
|
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?: CreateHotkeySequenceOptions;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* SolidJS primitive for registering multiple keyboard shortcut sequences at once (Vim-style).
|
|
18
|
-
*
|
|
19
|
-
* Uses the singleton SequenceManager. Accepts a dynamic array of definitions, or accessors,
|
|
20
|
-
* so you can react to variable-length lists.
|
|
21
|
-
*
|
|
22
|
-
* Options are merged in this order:
|
|
23
|
-
* HotkeysProvider defaults < commonOptions < per-definition options
|
|
24
|
-
*
|
|
25
|
-
* Definitions with an empty `sequence` are skipped (no registration).
|
|
26
|
-
*
|
|
27
|
-
* @param sequences - Array of sequence definitions, or accessor returning them
|
|
28
|
-
* @param commonOptions - Shared options for all sequences, or accessor
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* function VimPalette() {
|
|
33
|
-
* createHotkeySequences([
|
|
34
|
-
* { sequence: ['G', 'G'], callback: () => scrollToTop() },
|
|
35
|
-
* { sequence: ['D', 'D'], callback: () => deleteLine() },
|
|
36
|
-
* ])
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```tsx
|
|
42
|
-
* function Dynamic(props) {
|
|
43
|
-
* createHotkeySequences(
|
|
44
|
-
* () => props.items.map((item) => ({
|
|
45
|
-
* sequence: item.chords,
|
|
46
|
-
* callback: item.action,
|
|
47
|
-
* options: { enabled: item.enabled },
|
|
48
|
-
* })),
|
|
49
|
-
* { preventDefault: true },
|
|
50
|
-
* )
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
declare function createHotkeySequences(sequences: Array<CreateHotkeySequenceDefinition> | (() => Array<CreateHotkeySequenceDefinition>), commonOptions?: CreateHotkeySequenceOptions | (() => CreateHotkeySequenceOptions)): void;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { CreateHotkeySequenceDefinition, createHotkeySequences };
|
|
57
|
-
//# sourceMappingURL=createHotkeySequences.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeySequences.js","names":[],"sources":["../src/createHotkeySequences.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A single sequence definition for use with `createHotkeySequences`.\n */\nexport interface CreateHotkeySequenceDefinition {\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?: CreateHotkeySequenceOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard shortcut sequences at once (Vim-style).\n *\n * Uses the singleton SequenceManager. Accepts a dynamic array of definitions, or accessors,\n * so you can react to variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * Definitions with an empty `sequence` are skipped (no registration).\n *\n * @param sequences - Array of sequence definitions, or accessor returning them\n * @param commonOptions - Shared options for all sequences, or accessor\n *\n * @example\n * ```tsx\n * function VimPalette() {\n * createHotkeySequences([\n * { sequence: ['G', 'G'], callback: () => scrollToTop() },\n * { sequence: ['D', 'D'], callback: () => deleteLine() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Dynamic(props) {\n * createHotkeySequences(\n * () => props.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 createHotkeySequences(\n sequences:\n | Array<CreateHotkeySequenceDefinition>\n | (() => Array<CreateHotkeySequenceDefinition>),\n commonOptions:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: SequenceRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getSequenceManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolved = typeof sequences === 'function' ? sequences() : sequences\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeySequenceDefinition\n mergedOptions: CreateHotkeySequenceOptions\n sequenceString: string\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolved.length; i++) {\n const def = resolved[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeySequenceOptions\n\n if (def.sequence.length === 0) {\n continue\n }\n\n const sequenceString = formatHotkeySequence(def.sequence)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${sequenceString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n sequenceString,\n resolvedTarget,\n })\n }\n\n // Untrack store mutations so that registering/updating sequences doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n for (const [key, record] of [...registrations.entries()]) {\n if (!nextKeys.has(key)) {\n if (record.handle.isActive) {\n record.handle.unregister()\n }\n registrations.delete(key)\n }\n }\n\n for (const p of prepared) {\n const existing = registrations.get(p.registrationKey)\n if (existing?.handle.isActive && existing.target === p.resolvedTarget) {\n existing.handle.callback = p.def.callback\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\n continue\n }\n\n if (existing) {\n if (existing.handle.isActive) {\n existing.handle.unregister()\n }\n registrations.delete(p.registrationKey)\n }\n\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n const handle = manager.register(p.def.sequence, p.def.callback, {\n ...optionsWithoutTarget,\n target: p.resolvedTarget,\n })\n registrations.set(p.registrationKey, {\n handle,\n target: p.resolvedTarget,\n })\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,sBACd,WAGA,gBAE0C,EAAE,EACtC;CAMN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,oBAAoB;CAEpC,MAAM,gCAAgB,IAAI,KAAiC;AAE3D,iBAAgB;AACd,OAAK,MAAM,EAAE,YAAY,cAAc,QAAQ,CAC7C,KAAI,OAAO,SACT,QAAO,YAAY;AAGvB,gBAAc,OAAO;GACrB;AAEF,oBAAmB;EACjB,MAAM,WAAW,OAAO,cAAc,aAAa,WAAW,GAAG;EACjE,MAAM,wBACJ,OAAO,kBAAkB,aAAa,eAAe,GAAG;EAE1D,MAAM,2BAAW,IAAI,KAAa;EAClC,MAAM,WAMD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;GACxC,MAAM,MAAM,SAAS;GACrB,MAAM,qBAAqB,IAAI,WAAW,EAAE;GAE5C,MAAM,gBAAgB;IACpB,GAAG,eAAe;IAClB,GAAG;IACH,GAAG;IACJ;AAED,OAAI,IAAI,SAAS,WAAW,EAC1B;GAGF,MAAM,iBAAiB,qBAAqB,IAAI,SAAS;GAEzD,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,OAAI,CAAC,eACH;GAGF,MAAM,kBAAkB,GAAG,EAAE,GAAG;AAChC,YAAS,IAAI,gBAAgB;AAC7B,YAAS,KAAK;IACZ;IACA;IACA;IACA;IACA;IACD,CAAC;;AAMJ,gBAAc;AACZ,QAAK,MAAM,CAAC,KAAK,WAAW,CAAC,GAAG,cAAc,SAAS,CAAC,CACtD,KAAI,CAAC,SAAS,IAAI,IAAI,EAAE;AACtB,QAAI,OAAO,OAAO,SAChB,QAAO,OAAO,YAAY;AAE5B,kBAAc,OAAO,IAAI;;AAI7B,QAAK,MAAM,KAAK,UAAU;IACxB,MAAM,WAAW,cAAc,IAAI,EAAE,gBAAgB;AACrD,QAAI,UAAU,OAAO,YAAY,SAAS,WAAW,EAAE,gBAAgB;AACrE,cAAS,OAAO,WAAW,EAAE,IAAI;KACjC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;AACvD,cAAS,OAAO,WAAW,qBAAqB;AAChD;;AAGF,QAAI,UAAU;AACZ,SAAI,SAAS,OAAO,SAClB,UAAS,OAAO,YAAY;AAE9B,mBAAc,OAAO,EAAE,gBAAgB;;IAGzC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;IACvD,MAAM,SAAS,QAAQ,SAAS,EAAE,IAAI,UAAU,EAAE,IAAI,UAAU;KAC9D,GAAG;KACH,QAAQ,EAAE;KACX,CAAC;AACF,kBAAc,IAAI,EAAE,iBAAiB;KACnC;KACA,QAAQ,EAAE;KACX,CAAC;;IAEJ;GACF"}
|
package/dist/createHotkeys.cjs
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let solid_js = require("solid-js");
|
|
4
|
-
|
|
5
|
-
//#region src/createHotkeys.ts
|
|
6
|
-
/**
|
|
7
|
-
* SolidJS primitive for registering multiple keyboard hotkeys at once.
|
|
8
|
-
*
|
|
9
|
-
* Uses the singleton HotkeyManager for efficient event handling.
|
|
10
|
-
* Accepts a dynamic array of hotkey definitions, making it safe to use
|
|
11
|
-
* with variable-length lists.
|
|
12
|
-
*
|
|
13
|
-
* Options are merged in this order:
|
|
14
|
-
* HotkeysProvider defaults < commonOptions < per-definition options
|
|
15
|
-
*
|
|
16
|
-
* @param hotkeys - Array of hotkey definitions, or accessor returning them
|
|
17
|
-
* @param commonOptions - Shared options applied to all hotkeys, or accessor
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* function Editor() {
|
|
22
|
-
* createHotkeys([
|
|
23
|
-
* { hotkey: 'Mod+S', callback: () => save() },
|
|
24
|
-
* { hotkey: 'Mod+Z', callback: () => undo() },
|
|
25
|
-
* { hotkey: 'Escape', callback: () => close() },
|
|
26
|
-
* ])
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* function MenuShortcuts(props) {
|
|
33
|
-
* createHotkeys(
|
|
34
|
-
* () => props.items.map((item) => ({
|
|
35
|
-
* hotkey: item.shortcut,
|
|
36
|
-
* callback: item.action,
|
|
37
|
-
* options: { enabled: item.enabled },
|
|
38
|
-
* })),
|
|
39
|
-
* { preventDefault: true },
|
|
40
|
-
* )
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
function createHotkeys(hotkeys, commonOptions = {}) {
|
|
45
|
-
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
46
|
-
const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
|
|
47
|
-
const registrations = /* @__PURE__ */ new Map();
|
|
48
|
-
(0, solid_js.onCleanup)(() => {
|
|
49
|
-
for (const { handle } of registrations.values()) if (handle.isActive) handle.unregister();
|
|
50
|
-
registrations.clear();
|
|
51
|
-
});
|
|
52
|
-
(0, solid_js.createEffect)(() => {
|
|
53
|
-
const resolvedHotkeys = typeof hotkeys === "function" ? hotkeys() : hotkeys;
|
|
54
|
-
const resolvedCommonOptions = typeof commonOptions === "function" ? commonOptions() : commonOptions;
|
|
55
|
-
const nextKeys = /* @__PURE__ */ new Set();
|
|
56
|
-
const prepared = [];
|
|
57
|
-
for (let i = 0; i < resolvedHotkeys.length; i++) {
|
|
58
|
-
const def = resolvedHotkeys[i];
|
|
59
|
-
const resolvedDefOptions = def.options ?? {};
|
|
60
|
-
const mergedOptions = {
|
|
61
|
-
...defaultOptions.hotkey,
|
|
62
|
-
...resolvedCommonOptions,
|
|
63
|
-
...resolvedDefOptions
|
|
64
|
-
};
|
|
65
|
-
const platform = mergedOptions.platform ?? (0, _tanstack_hotkeys.detectPlatform)();
|
|
66
|
-
const hotkeyString = (0, _tanstack_hotkeys.normalizeRegisterableHotkey)(def.hotkey, platform);
|
|
67
|
-
const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
|
|
68
|
-
if (!resolvedTarget) continue;
|
|
69
|
-
const registrationKey = `${i}:${hotkeyString}`;
|
|
70
|
-
nextKeys.add(registrationKey);
|
|
71
|
-
prepared.push({
|
|
72
|
-
registrationKey,
|
|
73
|
-
def,
|
|
74
|
-
mergedOptions,
|
|
75
|
-
hotkeyString,
|
|
76
|
-
resolvedTarget
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
(0, solid_js.untrack)(() => {
|
|
80
|
-
for (const [key, record] of [...registrations.entries()]) if (!nextKeys.has(key)) {
|
|
81
|
-
if (record.handle.isActive) record.handle.unregister();
|
|
82
|
-
registrations.delete(key);
|
|
83
|
-
}
|
|
84
|
-
for (const p of prepared) {
|
|
85
|
-
const existing = registrations.get(p.registrationKey);
|
|
86
|
-
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
87
|
-
existing.handle.callback = p.def.callback;
|
|
88
|
-
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
89
|
-
existing.handle.setOptions(optionsWithoutTarget);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (existing) {
|
|
93
|
-
if (existing.handle.isActive) existing.handle.unregister();
|
|
94
|
-
registrations.delete(p.registrationKey);
|
|
95
|
-
}
|
|
96
|
-
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
97
|
-
const handle = manager.register(p.hotkeyString, p.def.callback, {
|
|
98
|
-
...optionsWithoutTarget,
|
|
99
|
-
target: p.resolvedTarget
|
|
100
|
-
});
|
|
101
|
-
registrations.set(p.registrationKey, {
|
|
102
|
-
handle,
|
|
103
|
-
target: p.resolvedTarget
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
//#endregion
|
|
111
|
-
exports.createHotkeys = createHotkeys;
|
|
112
|
-
//# sourceMappingURL=createHotkeys.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeys.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkeys.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A single hotkey definition for use with `createHotkeys`.\n */\nexport interface CreateHotkeyDefinition {\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?: CreateHotkeyOptions\n}\n\n/**\n * SolidJS primitive 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.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * @param hotkeys - Array of hotkey definitions, or accessor returning them\n * @param commonOptions - Shared options applied to all hotkeys, or accessor\n *\n * @example\n * ```tsx\n * function Editor() {\n * createHotkeys([\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(props) {\n * createHotkeys(\n * () => props.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 createHotkeys(\n hotkeys:\n | Array<CreateHotkeyDefinition>\n | (() => Array<CreateHotkeyDefinition>),\n commonOptions: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: HotkeyRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n // Clean up only when this component/scope disposes — not before every effect\n // re-run. An inner `onCleanup` inside `createEffect` runs whenever reactive\n // deps change (e.g. dynamic hotkey list), which unregistered every hotkey and\n // re-registered them, flooding the manager store and could freeze the tab.\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolvedHotkeys = typeof hotkeys === 'function' ? hotkeys() : hotkeys\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeyDefinition\n mergedOptions: CreateHotkeyOptions\n hotkeyString: Hotkey\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolvedHotkeys.length; i++) {\n const def = resolvedHotkeys[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeyOptions\n\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(def.hotkey, platform)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${hotkeyString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n hotkeyString,\n resolvedTarget,\n })\n }\n\n // Untrack store mutations so that registering/updating hotkeys doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n // Drop stale keys first so list index shifts don't briefly double-register\n // the same hotkey+target (conflictBehavior: 'warn' + devtools can loop).\n for (const [key, record] of [...registrations.entries()]) {\n if (!nextKeys.has(key)) {\n if (record.handle.isActive) {\n record.handle.unregister()\n }\n registrations.delete(key)\n }\n }\n\n for (const p of prepared) {\n const existing = registrations.get(p.registrationKey)\n if (existing?.handle.isActive && existing.target === p.resolvedTarget) {\n existing.handle.callback = p.def.callback\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\n continue\n }\n\n if (existing) {\n if (existing.handle.isActive) {\n existing.handle.unregister()\n }\n registrations.delete(p.registrationKey)\n }\n\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n const handle = manager.register(p.hotkeyString, p.def.callback, {\n ...optionsWithoutTarget,\n target: p.resolvedTarget,\n })\n registrations.set(p.registrationKey, {\n handle,\n target: p.resolvedTarget,\n })\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,cACd,SAGA,gBAAmE,EAAE,EAC/D;CAMN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,mDAA4B;CAElC,MAAM,gCAAgB,IAAI,KAAiC;AAM3D,+BAAgB;AACd,OAAK,MAAM,EAAE,YAAY,cAAc,QAAQ,CAC7C,KAAI,OAAO,SACT,QAAO,YAAY;AAGvB,gBAAc,OAAO;GACrB;AAEF,kCAAmB;EACjB,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EACpE,MAAM,wBACJ,OAAO,kBAAkB,aAAa,eAAe,GAAG;EAE1D,MAAM,2BAAW,IAAI,KAAa;EAClC,MAAM,WAMD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,gBAAgB,QAAQ,KAAK;GAC/C,MAAM,MAAM,gBAAgB;GAC5B,MAAM,qBAAqB,IAAI,WAAW,EAAE;GAE5C,MAAM,gBAAgB;IACpB,GAAG,eAAe;IAClB,GAAG;IACH,GAAG;IACJ;GAED,MAAM,WAAW,cAAc,mDAA4B;GAC3D,MAAM,kEAA2C,IAAI,QAAQ,SAAS;GAEtE,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,OAAI,CAAC,eACH;GAGF,MAAM,kBAAkB,GAAG,EAAE,GAAG;AAChC,YAAS,IAAI,gBAAgB;AAC7B,YAAS,KAAK;IACZ;IACA;IACA;IACA;IACA;IACD,CAAC;;AAMJ,8BAAc;AAGZ,QAAK,MAAM,CAAC,KAAK,WAAW,CAAC,GAAG,cAAc,SAAS,CAAC,CACtD,KAAI,CAAC,SAAS,IAAI,IAAI,EAAE;AACtB,QAAI,OAAO,OAAO,SAChB,QAAO,OAAO,YAAY;AAE5B,kBAAc,OAAO,IAAI;;AAI7B,QAAK,MAAM,KAAK,UAAU;IACxB,MAAM,WAAW,cAAc,IAAI,EAAE,gBAAgB;AACrD,QAAI,UAAU,OAAO,YAAY,SAAS,WAAW,EAAE,gBAAgB;AACrE,cAAS,OAAO,WAAW,EAAE,IAAI;KACjC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;AACvD,cAAS,OAAO,WAAW,qBAAqB;AAChD;;AAGF,QAAI,UAAU;AACZ,SAAI,SAAS,OAAO,SAClB,UAAS,OAAO,YAAY;AAE9B,mBAAc,OAAO,EAAE,gBAAgB;;IAGzC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;IACvD,MAAM,SAAS,QAAQ,SAAS,EAAE,cAAc,EAAE,IAAI,UAAU;KAC9D,GAAG;KACH,QAAQ,EAAE;KACX,CAAC;AACF,kBAAc,IAAI,EAAE,iBAAiB;KACnC;KACA,QAAQ,EAAE;KACX,CAAC;;IAEJ;GACF"}
|