@tanstack/hotkeys 0.4.3 → 0.6.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/README.md +1 -1
- package/dist/constants.cjs +70 -10
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +57 -4
- package/dist/constants.d.ts +57 -4
- package/dist/constants.js +67 -10
- package/dist/constants.js.map +1 -1
- package/dist/format.cjs +20 -125
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +8 -72
- package/dist/format.d.ts +8 -72
- package/dist/format.js +23 -127
- package/dist/format.js.map +1 -1
- package/dist/hotkey-manager.cjs.map +1 -1
- package/dist/hotkey-manager.d.cts +5 -1
- package/dist/hotkey-manager.d.ts +5 -1
- package/dist/hotkey-manager.js.map +1 -1
- package/dist/{recorder.cjs → hotkey-recorder.cjs} +14 -16
- package/dist/hotkey-recorder.cjs.map +1 -0
- package/dist/{recorder.d.cts → hotkey-recorder.d.cts} +2 -2
- package/dist/{recorder.d.ts → hotkey-recorder.d.ts} +2 -2
- package/dist/{recorder.js → hotkey-recorder.js} +14 -16
- package/dist/hotkey-recorder.js.map +1 -0
- package/dist/hotkey-sequence-recorder.cjs +188 -0
- package/dist/hotkey-sequence-recorder.cjs.map +1 -0
- package/dist/hotkey-sequence-recorder.d.cts +71 -0
- package/dist/hotkey-sequence-recorder.d.ts +71 -0
- package/dist/hotkey-sequence-recorder.js +188 -0
- package/dist/hotkey-sequence-recorder.js.map +1 -0
- package/dist/hotkey.d.cts +2 -0
- package/dist/hotkey.d.ts +2 -0
- package/dist/index.cjs +12 -7
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +7 -6
- package/dist/parse.cjs +53 -91
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +31 -72
- package/dist/parse.d.ts +31 -72
- package/dist/parse.js +51 -89
- package/dist/parse.js.map +1 -1
- package/dist/recorder-chord.cjs +18 -0
- package/dist/recorder-chord.cjs.map +1 -0
- package/dist/recorder-chord.js +18 -0
- package/dist/recorder-chord.js.map +1 -0
- package/dist/sequence-manager.cjs +24 -8
- package/dist/sequence-manager.cjs.map +1 -1
- package/dist/sequence-manager.d.cts +11 -2
- package/dist/sequence-manager.d.ts +11 -2
- package/dist/sequence-manager.js +25 -10
- package/dist/sequence-manager.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +75 -21
- package/src/format.ts +58 -196
- package/src/hotkey-manager.ts +5 -1
- package/src/{recorder.ts → hotkey-recorder.ts} +18 -32
- package/src/hotkey-sequence-recorder.ts +308 -0
- package/src/hotkey.ts +2 -0
- package/src/index.ts +2 -1
- package/src/parse.ts +91 -131
- package/src/recorder-chord.ts +25 -0
- package/src/sequence-manager.ts +30 -9
- package/dist/recorder.cjs.map +0 -1
- package/dist/recorder.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hotkey } from "./hotkey.js";
|
|
2
2
|
import { Store } from "@tanstack/store";
|
|
3
3
|
|
|
4
|
-
//#region src/recorder.d.ts
|
|
4
|
+
//#region src/hotkey-recorder.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* State interface for the HotkeyRecorder.
|
|
7
7
|
*/
|
|
@@ -105,4 +105,4 @@ declare class HotkeyRecorder {
|
|
|
105
105
|
}
|
|
106
106
|
//#endregion
|
|
107
107
|
export { HotkeyRecorder, HotkeyRecorderOptions, HotkeyRecorderState };
|
|
108
|
-
//# sourceMappingURL=recorder.d.ts.map
|
|
108
|
+
//# sourceMappingURL=hotkey-recorder.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { detectPlatform } from "./constants.js";
|
|
2
|
-
import {
|
|
2
|
+
import { hotkeyChordFromKeydown } from "./recorder-chord.js";
|
|
3
3
|
import { Store } from "@tanstack/store";
|
|
4
4
|
|
|
5
|
-
//#region src/recorder.ts
|
|
5
|
+
//#region src/hotkey-recorder.ts
|
|
6
6
|
/**
|
|
7
7
|
* Framework-agnostic class for recording keyboard shortcuts.
|
|
8
8
|
*
|
|
@@ -93,20 +93,18 @@ var HotkeyRecorder = class {
|
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.#keydownHandler = null;
|
|
103
|
-
}
|
|
104
|
-
this.store.setState(() => ({
|
|
105
|
-
isRecording: false,
|
|
106
|
-
recordedHotkey: finalHotkey
|
|
107
|
-
}));
|
|
108
|
-
this.#options.onRecord(finalHotkey);
|
|
96
|
+
const finalHotkey = hotkeyChordFromKeydown(event, this.#platform);
|
|
97
|
+
if (finalHotkey === null) return;
|
|
98
|
+
const handlerToRemove = this.#keydownHandler;
|
|
99
|
+
if (handlerToRemove) {
|
|
100
|
+
this.#removeListener(handlerToRemove);
|
|
101
|
+
this.#keydownHandler = null;
|
|
109
102
|
}
|
|
103
|
+
this.store.setState(() => ({
|
|
104
|
+
isRecording: false,
|
|
105
|
+
recordedHotkey: finalHotkey
|
|
106
|
+
}));
|
|
107
|
+
this.#options.onRecord(finalHotkey);
|
|
110
108
|
};
|
|
111
109
|
this.#keydownHandler = handler;
|
|
112
110
|
this.#addListener(handler);
|
|
@@ -174,4 +172,4 @@ var HotkeyRecorder = class {
|
|
|
174
172
|
|
|
175
173
|
//#endregion
|
|
176
174
|
export { HotkeyRecorder };
|
|
177
|
-
//# sourceMappingURL=recorder.js.map
|
|
175
|
+
//# sourceMappingURL=hotkey-recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkey-recorder.js","names":["#options","#platform","#keydownHandler","#removeListener","#addListener"],"sources":["../src/hotkey-recorder.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { detectPlatform } from './constants'\nimport { hotkeyChordFromKeydown } from './recorder-chord'\nimport type { Hotkey } from './hotkey'\n\n/**\n * State interface for the HotkeyRecorder.\n */\nexport interface HotkeyRecorderState {\n /** Whether recording is currently active */\n isRecording: boolean\n /** The currently recorded hotkey (for live preview) */\n recordedHotkey: Hotkey | null\n}\n\n/**\n * Options for configuring a HotkeyRecorder instance.\n */\nexport interface HotkeyRecorderOptions {\n /** Callback when a hotkey is successfully recorded */\n onRecord: (hotkey: Hotkey) => void\n /** Optional callback when recording is cancelled (Escape pressed) */\n onCancel?: () => void\n /** Optional callback when shortcut is cleared (Backspace/Delete pressed) */\n onClear?: () => void\n}\n\n/**\n * Framework-agnostic class for recording keyboard shortcuts.\n *\n * This class handles all the complexity of capturing keyboard events,\n * converting them to hotkey strings, and handling edge cases like\n * Escape to cancel or Backspace/Delete to clear.\n *\n * State Management:\n * - Uses TanStack Store for reactive state management\n * - State can be accessed via `recorder.store.state` when using the class directly\n * - When using framework adapters (React), use `useStore` hooks for reactive state\n *\n * @example\n * ```ts\n * const recorder = new HotkeyRecorder({\n * onRecord: (hotkey) => {\n * console.log('Recorded:', hotkey)\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * // Start recording\n * recorder.start()\n *\n * // Access state directly\n * console.log(recorder.store.state.isRecording) // true\n *\n * // Subscribe to changes with TanStack Store\n * const unsubscribe = recorder.store.subscribe(() => {\n * console.log('Recording:', recorder.store.state.isRecording)\n * })\n *\n * // Cleanup\n * recorder.destroy()\n * unsubscribe()\n * ```\n */\nexport class HotkeyRecorder {\n /**\n * The TanStack Store instance containing the recorder state.\n * Use this to subscribe to state changes or access current state.\n */\n readonly store: Store<HotkeyRecorderState> = new Store<HotkeyRecorderState>({\n isRecording: false,\n recordedHotkey: null,\n })\n\n #keydownHandler: ((event: KeyboardEvent) => void) | null = null\n #options: HotkeyRecorderOptions\n #platform: 'mac' | 'windows' | 'linux'\n\n constructor(options: HotkeyRecorderOptions) {\n this.#options = options\n this.#platform = detectPlatform()\n }\n\n /**\n * Updates the recorder options, including callbacks.\n * This allows framework adapters to sync callback changes without recreating the recorder.\n */\n setOptions(options: Partial<HotkeyRecorderOptions>): void {\n this.#options = {\n ...this.#options,\n ...options,\n }\n }\n\n /**\n * Start recording a new hotkey.\n *\n * Sets up a keydown event listener that captures keyboard events\n * and converts them to hotkey strings. Recording continues until\n * a valid hotkey is recorded, Escape is pressed, or stop/cancel is called.\n */\n start(): void {\n // Prevent starting recording if already recording\n if (this.#keydownHandler) {\n return\n }\n\n // Update store state\n this.store.setState(() => ({\n isRecording: true,\n recordedHotkey: null,\n }))\n\n // Create keydown handler\n const handler = (event: KeyboardEvent) => {\n // Check if we're still recording (handler might be called after stop/cancel)\n if (!this.#keydownHandler) {\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n // Handle Escape to cancel\n if (event.key === 'Escape') {\n this.cancel()\n return\n }\n\n // Handle Backspace/Delete to clear shortcut\n if (event.key === 'Backspace' || event.key === 'Delete') {\n if (\n !event.ctrlKey &&\n !event.shiftKey &&\n !event.altKey &&\n !event.metaKey\n ) {\n this.#options.onClear?.()\n this.#options.onRecord('' as Hotkey)\n this.stop()\n return\n }\n }\n\n const finalHotkey = hotkeyChordFromKeydown(event, this.#platform)\n if (finalHotkey === null) {\n return\n }\n\n // Remove listener FIRST to prevent any additional events\n const handlerToRemove = this.#keydownHandler as\n | ((event: KeyboardEvent) => void)\n | null\n if (handlerToRemove) {\n this.#removeListener(handlerToRemove)\n this.#keydownHandler = null\n }\n\n // Update store state immediately\n this.store.setState(() => ({\n isRecording: false,\n recordedHotkey: finalHotkey,\n }))\n\n // Call callback AFTER listener is removed and state is set\n this.#options.onRecord(finalHotkey)\n }\n\n this.#keydownHandler = handler\n this.#addListener(handler)\n }\n\n /**\n * Stop recording (same as cancel, but doesn't call onCancel).\n *\n * Removes the event listener and resets the recording state.\n */\n stop(): void {\n // Remove event listener immediately\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n\n // Update store state\n this.store.setState(() => ({\n isRecording: false,\n recordedHotkey: null,\n }))\n }\n\n /**\n * Cancel recording without saving.\n *\n * Removes the event listener, resets the recording state, and calls\n * the onCancel callback if provided.\n */\n cancel(): void {\n // Remove event listener immediately\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n\n // Update store state\n this.store.setState(() => ({\n isRecording: false,\n recordedHotkey: null,\n }))\n\n // Call cancel callback\n this.#options.onCancel?.()\n }\n\n /**\n * Adds the keydown event listener to the document.\n */\n #addListener(handler: (event: KeyboardEvent) => void): void {\n if (typeof document === 'undefined') {\n return // SSR safety\n }\n\n document.addEventListener('keydown', handler, true)\n }\n\n /**\n * Removes the keydown event listener from the document.\n */\n #removeListener(handler: (event: KeyboardEvent) => void): void {\n if (typeof document === 'undefined') {\n return\n }\n\n document.removeEventListener('keydown', handler, true)\n }\n\n /**\n * Clean up event listeners and reset state.\n *\n * Call this when you're done with the recorder to ensure\n * all event listeners are properly removed.\n */\n destroy(): void {\n this.stop()\n this.store.setState(() => ({\n isRecording: false,\n recordedHotkey: null,\n }))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAa,iBAAb,MAA4B;CAU1B,kBAA2D;CAC3D;CACA;CAEA,YAAY,SAAgC;eATC,IAAI,MAA2B;GAC1E,aAAa;GACb,gBAAgB;GACjB,CAAC;AAOA,QAAKA,UAAW;AAChB,QAAKC,WAAY,gBAAgB;;;;;;CAOnC,WAAW,SAA+C;AACxD,QAAKD,UAAW;GACd,GAAG,MAAKA;GACR,GAAG;GACJ;;;;;;;;;CAUH,QAAc;AAEZ,MAAI,MAAKE,eACP;AAIF,OAAK,MAAM,gBAAgB;GACzB,aAAa;GACb,gBAAgB;GACjB,EAAE;EAGH,MAAM,WAAW,UAAyB;AAExC,OAAI,CAAC,MAAKA,eACR;AAGF,SAAM,gBAAgB;AACtB,SAAM,iBAAiB;AAGvB,OAAI,MAAM,QAAQ,UAAU;AAC1B,SAAK,QAAQ;AACb;;AAIF,OAAI,MAAM,QAA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
2
|
+
const require_recorder_chord = require('./recorder-chord.cjs');
|
|
3
|
+
let _tanstack_store = require("@tanstack/store");
|
|
4
|
+
|
|
5
|
+
//#region src/hotkey-sequence-recorder.ts
|
|
6
|
+
const defaultHotkeySequenceRecorderOptions = {
|
|
7
|
+
commitOnEnter: true,
|
|
8
|
+
commitKeys: "enter"
|
|
9
|
+
};
|
|
10
|
+
function resolvedCommitOnEnter(options) {
|
|
11
|
+
if (options.commitKeys === "none") return false;
|
|
12
|
+
return options.commitOnEnter !== false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Framework-agnostic class for recording multi-chord sequences (Vim-style shortcuts).
|
|
16
|
+
*
|
|
17
|
+
* Each step is captured like a single hotkey chord. Press **Enter** (no modifiers) to commit
|
|
18
|
+
* when {@link HotkeySequenceRecorderOptions.commitKeys} is `'enter'` (default), **Escape** to cancel,
|
|
19
|
+
* **Backspace/Delete** to remove the last step or clear when empty.
|
|
20
|
+
*/
|
|
21
|
+
var HotkeySequenceRecorder = class {
|
|
22
|
+
#keydownHandler = null;
|
|
23
|
+
#options;
|
|
24
|
+
#platform;
|
|
25
|
+
#idleTimer = null;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.store = new _tanstack_store.Store({
|
|
28
|
+
isRecording: false,
|
|
29
|
+
steps: [],
|
|
30
|
+
recordedSequence: null
|
|
31
|
+
});
|
|
32
|
+
this.#options = {
|
|
33
|
+
...defaultHotkeySequenceRecorderOptions,
|
|
34
|
+
...options
|
|
35
|
+
};
|
|
36
|
+
this.#platform = require_constants.detectPlatform();
|
|
37
|
+
}
|
|
38
|
+
setOptions(options) {
|
|
39
|
+
this.#options = {
|
|
40
|
+
...defaultHotkeySequenceRecorderOptions,
|
|
41
|
+
...this.#options,
|
|
42
|
+
...options
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
#clearIdleTimer() {
|
|
46
|
+
if (this.#idleTimer !== null) {
|
|
47
|
+
clearTimeout(this.#idleTimer);
|
|
48
|
+
this.#idleTimer = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
#scheduleIdleTimer() {
|
|
52
|
+
this.#clearIdleTimer();
|
|
53
|
+
const ms = this.#options.idleTimeoutMs;
|
|
54
|
+
if (ms === void 0 || ms <= 0) return;
|
|
55
|
+
if (this.store.state.steps.length === 0) return;
|
|
56
|
+
this.#idleTimer = setTimeout(() => {
|
|
57
|
+
this.#idleTimer = null;
|
|
58
|
+
if (!this.#keydownHandler) return;
|
|
59
|
+
if (this.store.state.steps.length >= 1) this.commit();
|
|
60
|
+
}, ms);
|
|
61
|
+
}
|
|
62
|
+
#patchSteps(updater) {
|
|
63
|
+
this.store.setState((s) => ({
|
|
64
|
+
...s,
|
|
65
|
+
steps: updater(s.steps)
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
start() {
|
|
69
|
+
if (this.#keydownHandler) return;
|
|
70
|
+
this.#clearIdleTimer();
|
|
71
|
+
this.store.setState(() => ({
|
|
72
|
+
isRecording: true,
|
|
73
|
+
steps: [],
|
|
74
|
+
recordedSequence: null
|
|
75
|
+
}));
|
|
76
|
+
const handler = (event) => {
|
|
77
|
+
if (!this.#keydownHandler) return;
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
event.stopPropagation();
|
|
80
|
+
if (event.key === "Escape") {
|
|
81
|
+
this.cancel();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
85
|
+
if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
86
|
+
if (this.store.state.steps.length === 0) {
|
|
87
|
+
this.#options.onClear?.();
|
|
88
|
+
this.#options.onRecord([]);
|
|
89
|
+
this.#finishWithoutCommitCallback();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.#patchSteps((prev) => prev.slice(0, -1));
|
|
93
|
+
if (this.store.state.steps.length === 0) this.#clearIdleTimer();
|
|
94
|
+
else this.#scheduleIdleTimer();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const enterCommits = resolvedCommitOnEnter(this.#options) && event.key === "Enter" && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey;
|
|
99
|
+
if (enterCommits && this.store.state.steps.length >= 1) {
|
|
100
|
+
this.commit();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (enterCommits && this.store.state.steps.length === 0) return;
|
|
104
|
+
const finalHotkey = require_recorder_chord.hotkeyChordFromKeydown(event, this.#platform);
|
|
105
|
+
if (finalHotkey === null) return;
|
|
106
|
+
this.#patchSteps((prev) => [...prev, finalHotkey]);
|
|
107
|
+
this.#scheduleIdleTimer();
|
|
108
|
+
};
|
|
109
|
+
this.#keydownHandler = handler;
|
|
110
|
+
this.#addListener(handler);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Commit the current steps as a sequence. No-op if fewer than one step.
|
|
114
|
+
*/
|
|
115
|
+
commit() {
|
|
116
|
+
const steps = this.store.state.steps;
|
|
117
|
+
if (steps.length < 1) return;
|
|
118
|
+
const sequence = [...steps];
|
|
119
|
+
if (this.#keydownHandler) {
|
|
120
|
+
this.#removeListener(this.#keydownHandler);
|
|
121
|
+
this.#keydownHandler = null;
|
|
122
|
+
}
|
|
123
|
+
this.#clearIdleTimer();
|
|
124
|
+
this.store.setState(() => ({
|
|
125
|
+
isRecording: false,
|
|
126
|
+
steps: [],
|
|
127
|
+
recordedSequence: sequence
|
|
128
|
+
}));
|
|
129
|
+
this.#options.onRecord(sequence);
|
|
130
|
+
}
|
|
131
|
+
#finishWithoutCommitCallback() {
|
|
132
|
+
if (this.#keydownHandler) {
|
|
133
|
+
this.#removeListener(this.#keydownHandler);
|
|
134
|
+
this.#keydownHandler = null;
|
|
135
|
+
}
|
|
136
|
+
this.#clearIdleTimer();
|
|
137
|
+
this.store.setState(() => ({
|
|
138
|
+
isRecording: false,
|
|
139
|
+
steps: [],
|
|
140
|
+
recordedSequence: null
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
stop() {
|
|
144
|
+
if (this.#keydownHandler) {
|
|
145
|
+
this.#removeListener(this.#keydownHandler);
|
|
146
|
+
this.#keydownHandler = null;
|
|
147
|
+
}
|
|
148
|
+
this.#clearIdleTimer();
|
|
149
|
+
this.store.setState(() => ({
|
|
150
|
+
isRecording: false,
|
|
151
|
+
steps: [],
|
|
152
|
+
recordedSequence: null
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
cancel() {
|
|
156
|
+
if (this.#keydownHandler) {
|
|
157
|
+
this.#removeListener(this.#keydownHandler);
|
|
158
|
+
this.#keydownHandler = null;
|
|
159
|
+
}
|
|
160
|
+
this.#clearIdleTimer();
|
|
161
|
+
this.store.setState(() => ({
|
|
162
|
+
isRecording: false,
|
|
163
|
+
steps: [],
|
|
164
|
+
recordedSequence: null
|
|
165
|
+
}));
|
|
166
|
+
this.#options.onCancel?.();
|
|
167
|
+
}
|
|
168
|
+
#addListener(handler) {
|
|
169
|
+
if (typeof document === "undefined") return;
|
|
170
|
+
document.addEventListener("keydown", handler, true);
|
|
171
|
+
}
|
|
172
|
+
#removeListener(handler) {
|
|
173
|
+
if (typeof document === "undefined") return;
|
|
174
|
+
document.removeEventListener("keydown", handler, true);
|
|
175
|
+
}
|
|
176
|
+
destroy() {
|
|
177
|
+
this.stop();
|
|
178
|
+
this.store.setState(() => ({
|
|
179
|
+
isRecording: false,
|
|
180
|
+
steps: [],
|
|
181
|
+
recordedSequence: null
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
exports.HotkeySequenceRecorder = HotkeySequenceRecorder;
|
|
188
|
+
//# sourceMappingURL=hotkey-sequence-recorder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkey-sequence-recorder.cjs","names":["Store","#options","#platform","detectPlatform","#idleTimer","#clearIdleTimer","#keydownHandler","#finishWithoutCommitCallback","#patchSteps","#scheduleIdleTimer","hotkeyChordFromKeydown","#addListener","#removeListener"],"sources":["../src/hotkey-sequence-recorder.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { detectPlatform } from './constants'\nimport { hotkeyChordFromKeydown } from './recorder-chord'\nimport type { HotkeySequence } from './sequence-manager'\n\n/**\n * How the user can commit a recorded sequence from the keyboard.\n * - `'enter'`: plain Enter (no modifiers) commits when at least one step exists.\n * - `'none'`: only {@link HotkeySequenceRecorder.commit} finishes recording (or idle timeout if set).\n */\nexport type HotkeySequenceRecorderCommitKeys = 'enter' | 'none'\n\n/**\n * State interface for the HotkeySequenceRecorder.\n */\nexport interface HotkeySequenceRecorderState {\n /** Whether recording is currently active */\n isRecording: boolean\n /** Chords captured so far in the current recording session */\n steps: HotkeySequence\n /** The last successfully committed sequence, or null if none / after starting a new session */\n recordedSequence: HotkeySequence | null\n}\n\n/**\n * Options for configuring a HotkeySequenceRecorder instance.\n */\nexport interface HotkeySequenceRecorderOptions {\n /** Callback when a sequence is successfully recorded (including empty array when cleared) */\n onRecord: (sequence: HotkeySequence) => void\n /** Optional callback when recording is cancelled (Escape pressed) */\n onCancel?: () => void\n /** Optional callback when the sequence is cleared (Backspace/Delete with no steps) */\n onClear?: () => void\n /**\n * Whether plain Enter commits the current steps. Ignored when {@link commitKeys} is `'none'`.\n * @default true\n */\n commitOnEnter?: boolean\n /**\n * Keyboard commit mode. When `'none'`, use {@link HotkeySequenceRecorder.commit} (and optional idle timeout).\n * @default 'enter'\n */\n commitKeys?: HotkeySequenceRecorderCommitKeys\n /**\n * Milliseconds of inactivity after the **last completed chord** before auto-committing.\n * The timer does not run while waiting for the first chord (`steps.length === 0`).\n */\n idleTimeoutMs?: number\n}\n\nconst defaultHotkeySequenceRecorderOptions: Pick<\n HotkeySequenceRecorderOptions,\n 'commitOnEnter' | 'commitKeys'\n> = {\n commitOnEnter: true,\n commitKeys: 'enter',\n}\n\nfunction resolvedCommitOnEnter(\n options: HotkeySequenceRecorderOptions,\n): boolean {\n if (options.commitKeys === 'none') {\n return false\n }\n return options.commitOnEnter !== false\n}\n\n/**\n * Framework-agnostic class for recording multi-chord sequences (Vim-style shortcuts).\n *\n * Each step is captured like a single hotkey chord. Press **Enter** (no modifiers) to commit\n * when {@link HotkeySequenceRecorderOptions.commitKeys} is `'enter'` (default), **Escape** to cancel,\n * **Backspace/Delete** to remove the last step or clear when empty.\n */\nexport class HotkeySequenceRecorder {\n readonly store: Store<HotkeySequenceRecorderState> =\n new Store<HotkeySequenceRecorderState>({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n })\n\n #keydownHandler: ((event: KeyboardEvent) => void) | null = null\n #options: HotkeySequenceRecorderOptions\n #platform: 'mac' | 'windows' | 'linux'\n #idleTimer: ReturnType<typeof setTimeout> | null = null\n\n constructor(options: HotkeySequenceRecorderOptions) {\n this.#options = {\n ...defaultHotkeySequenceRecorderOptions,\n ...options,\n }\n this.#platform = detectPlatform()\n }\n\n setOptions(options: Partial<HotkeySequenceRecorderOptions>): void {\n this.#options = {\n ...defaultHotkeySequenceRecorderOptions,\n ...this.#options,\n ...options,\n }\n }\n\n #clearIdleTimer(): void {\n if (this.#idleTimer !== null) {\n clearTimeout(this.#idleTimer)\n this.#idleTimer = null\n }\n }\n\n #scheduleIdleTimer(): void {\n this.#clearIdleTimer()\n const ms = this.#options.idleTimeoutMs\n if (ms === undefined || ms <= 0) {\n return\n }\n const steps = this.store.state.steps\n if (steps.length === 0) {\n return\n }\n this.#idleTimer = setTimeout(() => {\n this.#idleTimer = null\n if (!this.#keydownHandler) {\n return\n }\n if (this.store.state.steps.length >= 1) {\n this.commit()\n }\n }, ms)\n }\n\n #patchSteps(updater: (prev: HotkeySequence) => HotkeySequence): void {\n this.store.setState((s) => ({\n ...s,\n steps: updater(s.steps),\n }))\n }\n\n start(): void {\n if (this.#keydownHandler) {\n return\n }\n\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: true,\n steps: [],\n recordedSequence: null,\n }))\n\n const handler = (event: KeyboardEvent) => {\n if (!this.#keydownHandler) {\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n if (event.key === 'Escape') {\n this.cancel()\n return\n }\n\n if (event.key === 'Backspace' || event.key === 'Delete') {\n if (\n !event.ctrlKey &&\n !event.shiftKey &&\n !event.altKey &&\n !event.metaKey\n ) {\n const steps = this.store.state.steps\n if (steps.length === 0) {\n this.#options.onClear?.()\n this.#options.onRecord([])\n this.#finishWithoutCommitCallback()\n return\n }\n this.#patchSteps((prev) => prev.slice(0, -1))\n const next = this.store.state.steps\n if (next.length === 0) {\n this.#clearIdleTimer()\n } else {\n this.#scheduleIdleTimer()\n }\n return\n }\n }\n\n const enterCommits =\n resolvedCommitOnEnter(this.#options) &&\n event.key === 'Enter' &&\n !event.ctrlKey &&\n !event.shiftKey &&\n !event.altKey &&\n !event.metaKey\n\n if (enterCommits && this.store.state.steps.length >= 1) {\n this.commit()\n return\n }\n\n if (enterCommits && this.store.state.steps.length === 0) {\n return\n }\n\n const finalHotkey = hotkeyChordFromKeydown(event, this.#platform)\n if (finalHotkey === null) {\n return\n }\n\n this.#patchSteps((prev) => [...prev, finalHotkey])\n this.#scheduleIdleTimer()\n }\n\n this.#keydownHandler = handler\n this.#addListener(handler)\n }\n\n /**\n * Commit the current steps as a sequence. No-op if fewer than one step.\n */\n commit(): void {\n const steps = this.store.state.steps\n if (steps.length < 1) {\n return\n }\n\n const sequence = [...steps]\n\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: sequence,\n }))\n\n this.#options.onRecord(sequence)\n }\n\n #finishWithoutCommitCallback(): void {\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n }\n\n stop(): void {\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n }\n\n cancel(): void {\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n this.#options.onCancel?.()\n }\n\n #addListener(handler: (event: KeyboardEvent) => void): void {\n if (typeof document === 'undefined') {\n return\n }\n document.addEventListener('keydown', handler, true)\n }\n\n #removeListener(handler: (event: KeyboardEvent) => void): void {\n if (typeof document === 'undefined') {\n return\n }\n document.removeEventListener('keydown', handler, true)\n }\n\n destroy(): void {\n this.stop()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n }\n}\n"],"mappings":";;;;;AAmDA,MAAM,uCAGF;CACF,eAAe;CACf,YAAY;CACb;AAED,SAAS,sBACP,SACS;AACT,KAAI,QAAQ,eAAe,OACzB,QAAO;AAET,QAAO,QAAQ,kBAAkB;;;;;;;;;AAUnC,IAAa,yBAAb,MAAoC;CAQlC,kBAA2D;CAC3D;CACA;CACA,aAAmD;CAEnD,YAAY,SAAwC;eAXlD,IAAIA,sBAAmC;GACrC,aAAa;GACb,OAAO,EAAE;GACT,kBAAkB;GACnB,CAAC;AAQF,QAAKC,UAAW;GACd,GAAG;GACH,GAAG;GACJ;AACD,QAAKC,WAAYC,kCAAgB;;CAGnC,WAAW,SAAuD;AAChE,QAAKF,UAAW;GACd,GAAG;GACH,GAAG,MAAKA;GACR,GAAG;GACJ;;CAGH,kBAAwB;AACtB,MAAI,MAAKG,cAAe,MAAM;AAC5B,gBAAa,MAAKA,UAAW;AAC7B,SAAKA,YAAa;;;CAItB,qBAA2B;AACzB,QAAKC,gBAAiB;EACtB,MAAM,KAAK,MAAKJ,QAA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GACnB,EAAE;AACH,QAAKJ,QAAS,YAAY;;CAG5B,aAAa,SAA+C;AAC1D,MAAI,OAAO,aAAa,YACtB;AAEF,WAAS,iBAAiB,WAAW,SAAS,KAAK;;CAGrD,gBAAgB,SAA+C;AAC7D,MAAI,OAAO,aAAa,YACtB;AAEF,WAAS,oBAAoB,WAAW,SAAS,KAAK;;CAGxD,UAAgB;AACd,OAAK,MAAM;AACX,OAAK,MAAM,gBAAgB;GACzB,aAAa;GACb,OAAO,EAAE;GACT,kBAAkB;GACnB,EAAE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { HotkeySequence } from "./sequence-manager.cjs";
|
|
2
|
+
import { Store } from "@tanstack/store";
|
|
3
|
+
|
|
4
|
+
//#region src/hotkey-sequence-recorder.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* How the user can commit a recorded sequence from the keyboard.
|
|
7
|
+
* - `'enter'`: plain Enter (no modifiers) commits when at least one step exists.
|
|
8
|
+
* - `'none'`: only {@link HotkeySequenceRecorder.commit} finishes recording (or idle timeout if set).
|
|
9
|
+
*/
|
|
10
|
+
type HotkeySequenceRecorderCommitKeys = 'enter' | 'none';
|
|
11
|
+
/**
|
|
12
|
+
* State interface for the HotkeySequenceRecorder.
|
|
13
|
+
*/
|
|
14
|
+
interface HotkeySequenceRecorderState {
|
|
15
|
+
/** Whether recording is currently active */
|
|
16
|
+
isRecording: boolean;
|
|
17
|
+
/** Chords captured so far in the current recording session */
|
|
18
|
+
steps: HotkeySequence;
|
|
19
|
+
/** The last successfully committed sequence, or null if none / after starting a new session */
|
|
20
|
+
recordedSequence: HotkeySequence | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for configuring a HotkeySequenceRecorder instance.
|
|
24
|
+
*/
|
|
25
|
+
interface HotkeySequenceRecorderOptions {
|
|
26
|
+
/** Callback when a sequence is successfully recorded (including empty array when cleared) */
|
|
27
|
+
onRecord: (sequence: HotkeySequence) => void;
|
|
28
|
+
/** Optional callback when recording is cancelled (Escape pressed) */
|
|
29
|
+
onCancel?: () => void;
|
|
30
|
+
/** Optional callback when the sequence is cleared (Backspace/Delete with no steps) */
|
|
31
|
+
onClear?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Whether plain Enter commits the current steps. Ignored when {@link commitKeys} is `'none'`.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
commitOnEnter?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Keyboard commit mode. When `'none'`, use {@link HotkeySequenceRecorder.commit} (and optional idle timeout).
|
|
39
|
+
* @default 'enter'
|
|
40
|
+
*/
|
|
41
|
+
commitKeys?: HotkeySequenceRecorderCommitKeys;
|
|
42
|
+
/**
|
|
43
|
+
* Milliseconds of inactivity after the **last completed chord** before auto-committing.
|
|
44
|
+
* The timer does not run while waiting for the first chord (`steps.length === 0`).
|
|
45
|
+
*/
|
|
46
|
+
idleTimeoutMs?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Framework-agnostic class for recording multi-chord sequences (Vim-style shortcuts).
|
|
50
|
+
*
|
|
51
|
+
* Each step is captured like a single hotkey chord. Press **Enter** (no modifiers) to commit
|
|
52
|
+
* when {@link HotkeySequenceRecorderOptions.commitKeys} is `'enter'` (default), **Escape** to cancel,
|
|
53
|
+
* **Backspace/Delete** to remove the last step or clear when empty.
|
|
54
|
+
*/
|
|
55
|
+
declare class HotkeySequenceRecorder {
|
|
56
|
+
#private;
|
|
57
|
+
readonly store: Store<HotkeySequenceRecorderState>;
|
|
58
|
+
constructor(options: HotkeySequenceRecorderOptions);
|
|
59
|
+
setOptions(options: Partial<HotkeySequenceRecorderOptions>): void;
|
|
60
|
+
start(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Commit the current steps as a sequence. No-op if fewer than one step.
|
|
63
|
+
*/
|
|
64
|
+
commit(): void;
|
|
65
|
+
stop(): void;
|
|
66
|
+
cancel(): void;
|
|
67
|
+
destroy(): void;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { HotkeySequenceRecorder, HotkeySequenceRecorderCommitKeys, HotkeySequenceRecorderOptions, HotkeySequenceRecorderState };
|
|
71
|
+
//# sourceMappingURL=hotkey-sequence-recorder.d.cts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { HotkeySequence } from "./sequence-manager.js";
|
|
2
|
+
import { Store } from "@tanstack/store";
|
|
3
|
+
|
|
4
|
+
//#region src/hotkey-sequence-recorder.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* How the user can commit a recorded sequence from the keyboard.
|
|
7
|
+
* - `'enter'`: plain Enter (no modifiers) commits when at least one step exists.
|
|
8
|
+
* - `'none'`: only {@link HotkeySequenceRecorder.commit} finishes recording (or idle timeout if set).
|
|
9
|
+
*/
|
|
10
|
+
type HotkeySequenceRecorderCommitKeys = 'enter' | 'none';
|
|
11
|
+
/**
|
|
12
|
+
* State interface for the HotkeySequenceRecorder.
|
|
13
|
+
*/
|
|
14
|
+
interface HotkeySequenceRecorderState {
|
|
15
|
+
/** Whether recording is currently active */
|
|
16
|
+
isRecording: boolean;
|
|
17
|
+
/** Chords captured so far in the current recording session */
|
|
18
|
+
steps: HotkeySequence;
|
|
19
|
+
/** The last successfully committed sequence, or null if none / after starting a new session */
|
|
20
|
+
recordedSequence: HotkeySequence | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for configuring a HotkeySequenceRecorder instance.
|
|
24
|
+
*/
|
|
25
|
+
interface HotkeySequenceRecorderOptions {
|
|
26
|
+
/** Callback when a sequence is successfully recorded (including empty array when cleared) */
|
|
27
|
+
onRecord: (sequence: HotkeySequence) => void;
|
|
28
|
+
/** Optional callback when recording is cancelled (Escape pressed) */
|
|
29
|
+
onCancel?: () => void;
|
|
30
|
+
/** Optional callback when the sequence is cleared (Backspace/Delete with no steps) */
|
|
31
|
+
onClear?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Whether plain Enter commits the current steps. Ignored when {@link commitKeys} is `'none'`.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
commitOnEnter?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Keyboard commit mode. When `'none'`, use {@link HotkeySequenceRecorder.commit} (and optional idle timeout).
|
|
39
|
+
* @default 'enter'
|
|
40
|
+
*/
|
|
41
|
+
commitKeys?: HotkeySequenceRecorderCommitKeys;
|
|
42
|
+
/**
|
|
43
|
+
* Milliseconds of inactivity after the **last completed chord** before auto-committing.
|
|
44
|
+
* The timer does not run while waiting for the first chord (`steps.length === 0`).
|
|
45
|
+
*/
|
|
46
|
+
idleTimeoutMs?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Framework-agnostic class for recording multi-chord sequences (Vim-style shortcuts).
|
|
50
|
+
*
|
|
51
|
+
* Each step is captured like a single hotkey chord. Press **Enter** (no modifiers) to commit
|
|
52
|
+
* when {@link HotkeySequenceRecorderOptions.commitKeys} is `'enter'` (default), **Escape** to cancel,
|
|
53
|
+
* **Backspace/Delete** to remove the last step or clear when empty.
|
|
54
|
+
*/
|
|
55
|
+
declare class HotkeySequenceRecorder {
|
|
56
|
+
#private;
|
|
57
|
+
readonly store: Store<HotkeySequenceRecorderState>;
|
|
58
|
+
constructor(options: HotkeySequenceRecorderOptions);
|
|
59
|
+
setOptions(options: Partial<HotkeySequenceRecorderOptions>): void;
|
|
60
|
+
start(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Commit the current steps as a sequence. No-op if fewer than one step.
|
|
63
|
+
*/
|
|
64
|
+
commit(): void;
|
|
65
|
+
stop(): void;
|
|
66
|
+
cancel(): void;
|
|
67
|
+
destroy(): void;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { HotkeySequenceRecorder, HotkeySequenceRecorderCommitKeys, HotkeySequenceRecorderOptions, HotkeySequenceRecorderState };
|
|
71
|
+
//# sourceMappingURL=hotkey-sequence-recorder.d.ts.map
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { detectPlatform } from "./constants.js";
|
|
2
|
+
import { hotkeyChordFromKeydown } from "./recorder-chord.js";
|
|
3
|
+
import { Store } from "@tanstack/store";
|
|
4
|
+
|
|
5
|
+
//#region src/hotkey-sequence-recorder.ts
|
|
6
|
+
const defaultHotkeySequenceRecorderOptions = {
|
|
7
|
+
commitOnEnter: true,
|
|
8
|
+
commitKeys: "enter"
|
|
9
|
+
};
|
|
10
|
+
function resolvedCommitOnEnter(options) {
|
|
11
|
+
if (options.commitKeys === "none") return false;
|
|
12
|
+
return options.commitOnEnter !== false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Framework-agnostic class for recording multi-chord sequences (Vim-style shortcuts).
|
|
16
|
+
*
|
|
17
|
+
* Each step is captured like a single hotkey chord. Press **Enter** (no modifiers) to commit
|
|
18
|
+
* when {@link HotkeySequenceRecorderOptions.commitKeys} is `'enter'` (default), **Escape** to cancel,
|
|
19
|
+
* **Backspace/Delete** to remove the last step or clear when empty.
|
|
20
|
+
*/
|
|
21
|
+
var HotkeySequenceRecorder = class {
|
|
22
|
+
#keydownHandler = null;
|
|
23
|
+
#options;
|
|
24
|
+
#platform;
|
|
25
|
+
#idleTimer = null;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.store = new Store({
|
|
28
|
+
isRecording: false,
|
|
29
|
+
steps: [],
|
|
30
|
+
recordedSequence: null
|
|
31
|
+
});
|
|
32
|
+
this.#options = {
|
|
33
|
+
...defaultHotkeySequenceRecorderOptions,
|
|
34
|
+
...options
|
|
35
|
+
};
|
|
36
|
+
this.#platform = detectPlatform();
|
|
37
|
+
}
|
|
38
|
+
setOptions(options) {
|
|
39
|
+
this.#options = {
|
|
40
|
+
...defaultHotkeySequenceRecorderOptions,
|
|
41
|
+
...this.#options,
|
|
42
|
+
...options
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
#clearIdleTimer() {
|
|
46
|
+
if (this.#idleTimer !== null) {
|
|
47
|
+
clearTimeout(this.#idleTimer);
|
|
48
|
+
this.#idleTimer = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
#scheduleIdleTimer() {
|
|
52
|
+
this.#clearIdleTimer();
|
|
53
|
+
const ms = this.#options.idleTimeoutMs;
|
|
54
|
+
if (ms === void 0 || ms <= 0) return;
|
|
55
|
+
if (this.store.state.steps.length === 0) return;
|
|
56
|
+
this.#idleTimer = setTimeout(() => {
|
|
57
|
+
this.#idleTimer = null;
|
|
58
|
+
if (!this.#keydownHandler) return;
|
|
59
|
+
if (this.store.state.steps.length >= 1) this.commit();
|
|
60
|
+
}, ms);
|
|
61
|
+
}
|
|
62
|
+
#patchSteps(updater) {
|
|
63
|
+
this.store.setState((s) => ({
|
|
64
|
+
...s,
|
|
65
|
+
steps: updater(s.steps)
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
start() {
|
|
69
|
+
if (this.#keydownHandler) return;
|
|
70
|
+
this.#clearIdleTimer();
|
|
71
|
+
this.store.setState(() => ({
|
|
72
|
+
isRecording: true,
|
|
73
|
+
steps: [],
|
|
74
|
+
recordedSequence: null
|
|
75
|
+
}));
|
|
76
|
+
const handler = (event) => {
|
|
77
|
+
if (!this.#keydownHandler) return;
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
event.stopPropagation();
|
|
80
|
+
if (event.key === "Escape") {
|
|
81
|
+
this.cancel();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
85
|
+
if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
86
|
+
if (this.store.state.steps.length === 0) {
|
|
87
|
+
this.#options.onClear?.();
|
|
88
|
+
this.#options.onRecord([]);
|
|
89
|
+
this.#finishWithoutCommitCallback();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.#patchSteps((prev) => prev.slice(0, -1));
|
|
93
|
+
if (this.store.state.steps.length === 0) this.#clearIdleTimer();
|
|
94
|
+
else this.#scheduleIdleTimer();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const enterCommits = resolvedCommitOnEnter(this.#options) && event.key === "Enter" && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey;
|
|
99
|
+
if (enterCommits && this.store.state.steps.length >= 1) {
|
|
100
|
+
this.commit();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (enterCommits && this.store.state.steps.length === 0) return;
|
|
104
|
+
const finalHotkey = hotkeyChordFromKeydown(event, this.#platform);
|
|
105
|
+
if (finalHotkey === null) return;
|
|
106
|
+
this.#patchSteps((prev) => [...prev, finalHotkey]);
|
|
107
|
+
this.#scheduleIdleTimer();
|
|
108
|
+
};
|
|
109
|
+
this.#keydownHandler = handler;
|
|
110
|
+
this.#addListener(handler);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Commit the current steps as a sequence. No-op if fewer than one step.
|
|
114
|
+
*/
|
|
115
|
+
commit() {
|
|
116
|
+
const steps = this.store.state.steps;
|
|
117
|
+
if (steps.length < 1) return;
|
|
118
|
+
const sequence = [...steps];
|
|
119
|
+
if (this.#keydownHandler) {
|
|
120
|
+
this.#removeListener(this.#keydownHandler);
|
|
121
|
+
this.#keydownHandler = null;
|
|
122
|
+
}
|
|
123
|
+
this.#clearIdleTimer();
|
|
124
|
+
this.store.setState(() => ({
|
|
125
|
+
isRecording: false,
|
|
126
|
+
steps: [],
|
|
127
|
+
recordedSequence: sequence
|
|
128
|
+
}));
|
|
129
|
+
this.#options.onRecord(sequence);
|
|
130
|
+
}
|
|
131
|
+
#finishWithoutCommitCallback() {
|
|
132
|
+
if (this.#keydownHandler) {
|
|
133
|
+
this.#removeListener(this.#keydownHandler);
|
|
134
|
+
this.#keydownHandler = null;
|
|
135
|
+
}
|
|
136
|
+
this.#clearIdleTimer();
|
|
137
|
+
this.store.setState(() => ({
|
|
138
|
+
isRecording: false,
|
|
139
|
+
steps: [],
|
|
140
|
+
recordedSequence: null
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
stop() {
|
|
144
|
+
if (this.#keydownHandler) {
|
|
145
|
+
this.#removeListener(this.#keydownHandler);
|
|
146
|
+
this.#keydownHandler = null;
|
|
147
|
+
}
|
|
148
|
+
this.#clearIdleTimer();
|
|
149
|
+
this.store.setState(() => ({
|
|
150
|
+
isRecording: false,
|
|
151
|
+
steps: [],
|
|
152
|
+
recordedSequence: null
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
cancel() {
|
|
156
|
+
if (this.#keydownHandler) {
|
|
157
|
+
this.#removeListener(this.#keydownHandler);
|
|
158
|
+
this.#keydownHandler = null;
|
|
159
|
+
}
|
|
160
|
+
this.#clearIdleTimer();
|
|
161
|
+
this.store.setState(() => ({
|
|
162
|
+
isRecording: false,
|
|
163
|
+
steps: [],
|
|
164
|
+
recordedSequence: null
|
|
165
|
+
}));
|
|
166
|
+
this.#options.onCancel?.();
|
|
167
|
+
}
|
|
168
|
+
#addListener(handler) {
|
|
169
|
+
if (typeof document === "undefined") return;
|
|
170
|
+
document.addEventListener("keydown", handler, true);
|
|
171
|
+
}
|
|
172
|
+
#removeListener(handler) {
|
|
173
|
+
if (typeof document === "undefined") return;
|
|
174
|
+
document.removeEventListener("keydown", handler, true);
|
|
175
|
+
}
|
|
176
|
+
destroy() {
|
|
177
|
+
this.stop();
|
|
178
|
+
this.store.setState(() => ({
|
|
179
|
+
isRecording: false,
|
|
180
|
+
steps: [],
|
|
181
|
+
recordedSequence: null
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
export { HotkeySequenceRecorder };
|
|
188
|
+
//# sourceMappingURL=hotkey-sequence-recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkey-sequence-recorder.js","names":["#options","#platform","#idleTimer","#clearIdleTimer","#keydownHandler","#finishWithoutCommitCallback","#patchSteps","#scheduleIdleTimer","#addListener","#removeListener"],"sources":["../src/hotkey-sequence-recorder.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { detectPlatform } from './constants'\nimport { hotkeyChordFromKeydown } from './recorder-chord'\nimport type { HotkeySequence } from './sequence-manager'\n\n/**\n * How the user can commit a recorded sequence from the keyboard.\n * - `'enter'`: plain Enter (no modifiers) commits when at least one step exists.\n * - `'none'`: only {@link HotkeySequenceRecorder.commit} finishes recording (or idle timeout if set).\n */\nexport type HotkeySequenceRecorderCommitKeys = 'enter' | 'none'\n\n/**\n * State interface for the HotkeySequenceRecorder.\n */\nexport interface HotkeySequenceRecorderState {\n /** Whether recording is currently active */\n isRecording: boolean\n /** Chords captured so far in the current recording session */\n steps: HotkeySequence\n /** The last successfully committed sequence, or null if none / after starting a new session */\n recordedSequence: HotkeySequence | null\n}\n\n/**\n * Options for configuring a HotkeySequenceRecorder instance.\n */\nexport interface HotkeySequenceRecorderOptions {\n /** Callback when a sequence is successfully recorded (including empty array when cleared) */\n onRecord: (sequence: HotkeySequence) => void\n /** Optional callback when recording is cancelled (Escape pressed) */\n onCancel?: () => void\n /** Optional callback when the sequence is cleared (Backspace/Delete with no steps) */\n onClear?: () => void\n /**\n * Whether plain Enter commits the current steps. Ignored when {@link commitKeys} is `'none'`.\n * @default true\n */\n commitOnEnter?: boolean\n /**\n * Keyboard commit mode. When `'none'`, use {@link HotkeySequenceRecorder.commit} (and optional idle timeout).\n * @default 'enter'\n */\n commitKeys?: HotkeySequenceRecorderCommitKeys\n /**\n * Milliseconds of inactivity after the **last completed chord** before auto-committing.\n * The timer does not run while waiting for the first chord (`steps.length === 0`).\n */\n idleTimeoutMs?: number\n}\n\nconst defaultHotkeySequenceRecorderOptions: Pick<\n HotkeySequenceRecorderOptions,\n 'commitOnEnter' | 'commitKeys'\n> = {\n commitOnEnter: true,\n commitKeys: 'enter',\n}\n\nfunction resolvedCommitOnEnter(\n options: HotkeySequenceRecorderOptions,\n): boolean {\n if (options.commitKeys === 'none') {\n return false\n }\n return options.commitOnEnter !== false\n}\n\n/**\n * Framework-agnostic class for recording multi-chord sequences (Vim-style shortcuts).\n *\n * Each step is captured like a single hotkey chord. Press **Enter** (no modifiers) to commit\n * when {@link HotkeySequenceRecorderOptions.commitKeys} is `'enter'` (default), **Escape** to cancel,\n * **Backspace/Delete** to remove the last step or clear when empty.\n */\nexport class HotkeySequenceRecorder {\n readonly store: Store<HotkeySequenceRecorderState> =\n new Store<HotkeySequenceRecorderState>({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n })\n\n #keydownHandler: ((event: KeyboardEvent) => void) | null = null\n #options: HotkeySequenceRecorderOptions\n #platform: 'mac' | 'windows' | 'linux'\n #idleTimer: ReturnType<typeof setTimeout> | null = null\n\n constructor(options: HotkeySequenceRecorderOptions) {\n this.#options = {\n ...defaultHotkeySequenceRecorderOptions,\n ...options,\n }\n this.#platform = detectPlatform()\n }\n\n setOptions(options: Partial<HotkeySequenceRecorderOptions>): void {\n this.#options = {\n ...defaultHotkeySequenceRecorderOptions,\n ...this.#options,\n ...options,\n }\n }\n\n #clearIdleTimer(): void {\n if (this.#idleTimer !== null) {\n clearTimeout(this.#idleTimer)\n this.#idleTimer = null\n }\n }\n\n #scheduleIdleTimer(): void {\n this.#clearIdleTimer()\n const ms = this.#options.idleTimeoutMs\n if (ms === undefined || ms <= 0) {\n return\n }\n const steps = this.store.state.steps\n if (steps.length === 0) {\n return\n }\n this.#idleTimer = setTimeout(() => {\n this.#idleTimer = null\n if (!this.#keydownHandler) {\n return\n }\n if (this.store.state.steps.length >= 1) {\n this.commit()\n }\n }, ms)\n }\n\n #patchSteps(updater: (prev: HotkeySequence) => HotkeySequence): void {\n this.store.setState((s) => ({\n ...s,\n steps: updater(s.steps),\n }))\n }\n\n start(): void {\n if (this.#keydownHandler) {\n return\n }\n\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: true,\n steps: [],\n recordedSequence: null,\n }))\n\n const handler = (event: KeyboardEvent) => {\n if (!this.#keydownHandler) {\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n if (event.key === 'Escape') {\n this.cancel()\n return\n }\n\n if (event.key === 'Backspace' || event.key === 'Delete') {\n if (\n !event.ctrlKey &&\n !event.shiftKey &&\n !event.altKey &&\n !event.metaKey\n ) {\n const steps = this.store.state.steps\n if (steps.length === 0) {\n this.#options.onClear?.()\n this.#options.onRecord([])\n this.#finishWithoutCommitCallback()\n return\n }\n this.#patchSteps((prev) => prev.slice(0, -1))\n const next = this.store.state.steps\n if (next.length === 0) {\n this.#clearIdleTimer()\n } else {\n this.#scheduleIdleTimer()\n }\n return\n }\n }\n\n const enterCommits =\n resolvedCommitOnEnter(this.#options) &&\n event.key === 'Enter' &&\n !event.ctrlKey &&\n !event.shiftKey &&\n !event.altKey &&\n !event.metaKey\n\n if (enterCommits && this.store.state.steps.length >= 1) {\n this.commit()\n return\n }\n\n if (enterCommits && this.store.state.steps.length === 0) {\n return\n }\n\n const finalHotkey = hotkeyChordFromKeydown(event, this.#platform)\n if (finalHotkey === null) {\n return\n }\n\n this.#patchSteps((prev) => [...prev, finalHotkey])\n this.#scheduleIdleTimer()\n }\n\n this.#keydownHandler = handler\n this.#addListener(handler)\n }\n\n /**\n * Commit the current steps as a sequence. No-op if fewer than one step.\n */\n commit(): void {\n const steps = this.store.state.steps\n if (steps.length < 1) {\n return\n }\n\n const sequence = [...steps]\n\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: sequence,\n }))\n\n this.#options.onRecord(sequence)\n }\n\n #finishWithoutCommitCallback(): void {\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n }\n\n stop(): void {\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n }\n\n cancel(): void {\n if (this.#keydownHandler) {\n this.#removeListener(this.#keydownHandler)\n this.#keydownHandler = null\n }\n this.#clearIdleTimer()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n this.#options.onCancel?.()\n }\n\n #addListener(handler: (event: KeyboardEvent) => void): void {\n if (typeof document === 'undefined') {\n return\n }\n document.addEventListener('keydown', handler, true)\n }\n\n #removeListener(handler: (event: KeyboardEvent) => void): void {\n if (typeof document === 'undefined') {\n return\n }\n document.removeEventListener('keydown', handler, true)\n }\n\n destroy(): void {\n this.stop()\n this.store.setState(() => ({\n isRecording: false,\n steps: [],\n recordedSequence: null,\n }))\n }\n}\n"],"mappings":";;;;;AAmDA,MAAM,uCAGF;CACF,eAAe;CACf,YAAY;CACb;AAED,SAAS,sBACP,SACS;AACT,KAAI,QAAQ,eAAe,OACzB,QAAO;AAET,QAAO,QAAQ,kBAAkB;;;;;;;;;AAUnC,IAAa,yBAAb,MAAoC;CAQlC,kBAA2D;CAC3D;CACA;CACA,aAAmD;CAEnD,YAAY,SAAwC;eAXlD,IAAI,MAAmC;GACrC,aAAa;GACb,OAAO,EAAE;GACT,kBAAkB;GACnB,CAAC;AAQF,QAAKA,UAAW;GACd,GAAG;GACH,GAAG;GACJ;AACD,QAAKC,WAAY,gBAAgB;;CAGnC,WAAW,SAAuD;AAChE,QAAKD,UAAW;GACd,GAAG;GACH,GAAG,MAAKA;GACR,GAAG;GACJ;;CAGH,kBAAwB;AACtB,MAAI,MAAKE,cAAe,MAAM;AAC5B,gBAAa,MAAKA,UAAW;AAC7B,SAAKA,YAAa;;;CAItB,qBAA2B;AACzB,QAAKC,gBAAiB;EACtB,MAAM,KAAK,MAAKH,QAAS;AACzB,MAAI,OAAO,UAAa,MAA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YAAY;;CAG5B,aAAa,SAA+C;AAC1D,MAAI,OAAO,aAAa,YACtB;AAEF,WAAS,iBAAiB,WAAW,SAAS,KAAK;;CAGrD,gBAAgB,SAA+C;AAC7D,MAAI,OAAO,aAAa,YACtB;AAEF,WAAS,oBAAoB,WAAW,SAAS,KAAK;;CAGxD,UAAgB;AACd,OAAK,MAAM;AACX,OAAK,MAAM,gBAAgB;GACzB,aAAa;GACb,OAAO,EAAE;GACT,kBAAkB;GACnB,EAAE"}
|
package/dist/hotkey.d.cts
CHANGED
|
@@ -237,6 +237,8 @@ type RegisterableHotkey = Hotkey | RawHotkey;
|
|
|
237
237
|
interface FormatDisplayOptions {
|
|
238
238
|
/** The target platform. Defaults to auto-detection. */
|
|
239
239
|
platform?: 'mac' | 'windows' | 'linux';
|
|
240
|
+
/** Whether to use symbols for the display. Defaults to true. */
|
|
241
|
+
useSymbols?: boolean;
|
|
240
242
|
}
|
|
241
243
|
/**
|
|
242
244
|
* Result of validating a hotkey string.
|