@tanstack/hotkeys 0.9.0 → 0.10.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.
Files changed (148) hide show
  1. package/dist/_event-target.js +1 -2
  2. package/dist/_keyboard-event.js +1 -2
  3. package/dist/_match.js +1 -2
  4. package/dist/_named-keys.d.ts +3 -5
  5. package/dist/_named-keys.js +1 -2
  6. package/dist/_recorder-chord.js +1 -2
  7. package/dist/_recording-guard.js +1 -2
  8. package/dist/_registration.js +1 -2
  9. package/dist/conflicts.d.ts +4 -7
  10. package/dist/conflicts.js +1 -2
  11. package/dist/constants.d.ts +14 -17
  12. package/dist/constants.js +8 -9
  13. package/dist/display-labels.d.ts +7 -10
  14. package/dist/display-labels.js +1 -2
  15. package/dist/format.d.ts +9 -12
  16. package/dist/format.js +9 -7
  17. package/dist/hint.d.ts +3 -6
  18. package/dist/hint.js +1 -2
  19. package/dist/hotkey-manager.d.ts +8 -10
  20. package/dist/hotkey-manager.js +21 -3
  21. package/dist/hotkey-recorder.d.ts +4 -7
  22. package/dist/hotkey-recorder.js +9 -6
  23. package/dist/hotkey-sequence-recorder.d.ts +5 -8
  24. package/dist/hotkey-sequence-recorder.js +6 -7
  25. package/dist/hotkey.types.d.ts +15 -18
  26. package/dist/key-state-tracker.d.ts +4 -7
  27. package/dist/key-state-tracker.js +6 -3
  28. package/dist/key.types.d.ts +17 -20
  29. package/dist/match.d.ts +8 -11
  30. package/dist/match.js +1 -2
  31. package/dist/parse.d.ts +11 -14
  32. package/dist/parse.js +5 -4
  33. package/dist/platform.d.ts +3 -6
  34. package/dist/platform.js +1 -2
  35. package/dist/recorder-options.d.ts +6 -9
  36. package/dist/sequence-manager.d.ts +11 -14
  37. package/dist/sequence-manager.js +12 -7
  38. package/dist/validate.d.ts +5 -8
  39. package/dist/validate.js +1 -2
  40. package/package.json +8 -13
  41. package/dist/_event-target.cjs +0 -73
  42. package/dist/_event-target.cjs.map +0 -1
  43. package/dist/_event-target.js.map +0 -1
  44. package/dist/_keyboard-event.cjs +0 -83
  45. package/dist/_keyboard-event.cjs.map +0 -1
  46. package/dist/_keyboard-event.js.map +0 -1
  47. package/dist/_match.cjs +0 -49
  48. package/dist/_match.cjs.map +0 -1
  49. package/dist/_match.js.map +0 -1
  50. package/dist/_named-keys.cjs +0 -68
  51. package/dist/_named-keys.cjs.map +0 -1
  52. package/dist/_named-keys.d.cts +0 -8
  53. package/dist/_named-keys.js.map +0 -1
  54. package/dist/_recorder-chord.cjs +0 -44
  55. package/dist/_recorder-chord.cjs.map +0 -1
  56. package/dist/_recorder-chord.js.map +0 -1
  57. package/dist/_recording-guard.cjs +0 -59
  58. package/dist/_recording-guard.cjs.map +0 -1
  59. package/dist/_recording-guard.js.map +0 -1
  60. package/dist/_registration.cjs +0 -54
  61. package/dist/_registration.cjs.map +0 -1
  62. package/dist/_registration.js.map +0 -1
  63. package/dist/conflicts.cjs +0 -55
  64. package/dist/conflicts.cjs.map +0 -1
  65. package/dist/conflicts.d.cts +0 -39
  66. package/dist/conflicts.js.map +0 -1
  67. package/dist/constants.cjs +0 -410
  68. package/dist/constants.cjs.map +0 -1
  69. package/dist/constants.d.cts +0 -165
  70. package/dist/constants.js.map +0 -1
  71. package/dist/display-labels.cjs +0 -119
  72. package/dist/display-labels.cjs.map +0 -1
  73. package/dist/display-labels.d.cts +0 -93
  74. package/dist/display-labels.js.map +0 -1
  75. package/dist/format.cjs +0 -85
  76. package/dist/format.cjs.map +0 -1
  77. package/dist/format.d.cts +0 -99
  78. package/dist/format.js.map +0 -1
  79. package/dist/hint.cjs +0 -24
  80. package/dist/hint.cjs.map +0 -1
  81. package/dist/hint.d.cts +0 -23
  82. package/dist/hint.js.map +0 -1
  83. package/dist/hotkey-manager.cjs +0 -414
  84. package/dist/hotkey-manager.cjs.map +0 -1
  85. package/dist/hotkey-manager.d.cts +0 -234
  86. package/dist/hotkey-manager.js.map +0 -1
  87. package/dist/hotkey-recorder.cjs +0 -235
  88. package/dist/hotkey-recorder.cjs.map +0 -1
  89. package/dist/hotkey-recorder.d.cts +0 -119
  90. package/dist/hotkey-recorder.js.map +0 -1
  91. package/dist/hotkey-sequence-recorder.cjs +0 -255
  92. package/dist/hotkey-sequence-recorder.cjs.map +0 -1
  93. package/dist/hotkey-sequence-recorder.d.cts +0 -86
  94. package/dist/hotkey-sequence-recorder.js.map +0 -1
  95. package/dist/hotkey.types.d.cts +0 -236
  96. package/dist/index.cjs +0 -71
  97. package/dist/index.d.cts +0 -18
  98. package/dist/key-state-tracker.cjs +0 -197
  99. package/dist/key-state-tracker.cjs.map +0 -1
  100. package/dist/key-state-tracker.d.cts +0 -107
  101. package/dist/key-state-tracker.js.map +0 -1
  102. package/dist/key.types.d.cts +0 -82
  103. package/dist/match.cjs +0 -144
  104. package/dist/match.cjs.map +0 -1
  105. package/dist/match.d.cts +0 -101
  106. package/dist/match.js.map +0 -1
  107. package/dist/parse.cjs +0 -245
  108. package/dist/parse.cjs.map +0 -1
  109. package/dist/parse.d.cts +0 -134
  110. package/dist/parse.js.map +0 -1
  111. package/dist/platform.cjs +0 -55
  112. package/dist/platform.cjs.map +0 -1
  113. package/dist/platform.d.cts +0 -44
  114. package/dist/platform.js.map +0 -1
  115. package/dist/recorder-options.d.cts +0 -34
  116. package/dist/sequence-manager.cjs +0 -441
  117. package/dist/sequence-manager.cjs.map +0 -1
  118. package/dist/sequence-manager.d.cts +0 -172
  119. package/dist/sequence-manager.js.map +0 -1
  120. package/dist/validate.cjs +0 -112
  121. package/dist/validate.cjs.map +0 -1
  122. package/dist/validate.d.cts +0 -67
  123. package/dist/validate.js.map +0 -1
  124. package/src/_event-target.ts +0 -157
  125. package/src/_keyboard-event.ts +0 -101
  126. package/src/_match.ts +0 -96
  127. package/src/_named-keys.ts +0 -62
  128. package/src/_recorder-chord.ts +0 -76
  129. package/src/_recording-guard.ts +0 -63
  130. package/src/_registration.ts +0 -79
  131. package/src/conflicts.ts +0 -125
  132. package/src/constants.ts +0 -455
  133. package/src/display-labels.ts +0 -123
  134. package/src/format.ts +0 -201
  135. package/src/hint.ts +0 -42
  136. package/src/hotkey-manager.ts +0 -814
  137. package/src/hotkey-recorder.ts +0 -348
  138. package/src/hotkey-sequence-recorder.ts +0 -410
  139. package/src/hotkey.types.ts +0 -269
  140. package/src/index.ts +0 -17
  141. package/src/key-state-tracker.ts +0 -261
  142. package/src/key.types.ts +0 -268
  143. package/src/match.ts +0 -210
  144. package/src/parse.ts +0 -369
  145. package/src/platform.ts +0 -66
  146. package/src/recorder-options.ts +0 -34
  147. package/src/sequence-manager.ts +0 -769
  148. package/src/validate.ts +0 -179
@@ -1,234 +0,0 @@
1
- import { ConflictBehavior, Hotkey, HotkeyCallback, HotkeyMeta, ParsedHotkey, RegisterableHotkey } from "./hotkey.types.cjs";
2
- import { Store } from "@tanstack/store";
3
-
4
- //#region src/hotkey-manager.d.ts
5
- /**
6
- * Options for registering a hotkey.
7
- */
8
- interface HotkeyOptions {
9
- /** Behavior when this hotkey conflicts with an existing registration on the same target. Defaults to 'warn' */
10
- conflictBehavior?: ConflictBehavior;
11
- /**
12
- * Soft-disable: when `false`, the callback does not run but the registration
13
- * stays in `HotkeyManager` (and in devtools). Toggling this should update the
14
- * existing handle via `setOptions` rather than unregistering. Defaults to `true`.
15
- */
16
- enabled?: boolean;
17
- /** The event type to listen for. Defaults to 'keydown' */
18
- eventType?: 'keydown' | 'keyup';
19
- /** Whether to ignore hotkeys when keyboard events originate from input-like elements (text inputs, textarea, select, contenteditable — button-type inputs like type=button/submit/reset are not ignored). Defaults based on hotkey: true for single keys and Shift/Alt combos; false for Ctrl/Meta shortcuts and Escape */
20
- ignoreInputs?: boolean;
21
- /** The target platform for resolving 'Mod' */
22
- platform?: 'mac' | 'windows' | 'linux';
23
- /** Prevent the default browser action when the hotkey matches. Defaults to true */
24
- preventDefault?: boolean;
25
- /** If true, only trigger once until all keys are released. Default: false */
26
- requireReset?: boolean;
27
- /** Stop event propagation when the hotkey matches. Defaults to true */
28
- stopPropagation?: boolean;
29
- /** The DOM element to attach the event listener to. Defaults to document. */
30
- target?: HTMLElement | Document | Window | null;
31
- /** Optional metadata (name, description, custom fields via declaration merging) */
32
- meta?: HotkeyMeta;
33
- }
34
- /**
35
- * A registered hotkey handler in the HotkeyManager.
36
- */
37
- interface HotkeyRegistration {
38
- /** The callback to invoke */
39
- callback: HotkeyCallback;
40
- /** Whether this registration has fired and needs reset (for requireReset) */
41
- hasFired: boolean;
42
- /** The concrete key/code that activated a requireReset registration. */
43
- activeMatch?: {
44
- key: string;
45
- code: string;
46
- };
47
- /** The original hotkey string */
48
- hotkey: Hotkey;
49
- /** Unique identifier for this registration */
50
- id: string;
51
- /** Options for this registration */
52
- options: HotkeyOptions;
53
- /** The parsed hotkey */
54
- parsedHotkey: ParsedHotkey;
55
- /** The resolved target element for this registration */
56
- target: HTMLElement | Document | Window;
57
- /** How many times this registration's callback has been triggered */
58
- triggerCount: number;
59
- }
60
- /**
61
- * Public view of a hotkey registration for display and introspection.
62
- * Omits the callback function which is an internal implementation detail.
63
- */
64
- interface HotkeyRegistrationView {
65
- /** The original hotkey string */
66
- hotkey: Hotkey;
67
- /** Unique identifier for this registration */
68
- id: string;
69
- /** Options for this registration */
70
- options: HotkeyOptions;
71
- /** The parsed hotkey */
72
- parsedHotkey: ParsedHotkey;
73
- /** The resolved target element for this registration */
74
- target: HTMLElement | Document | Window;
75
- /** How many times this registration's callback has been triggered */
76
- triggerCount: number;
77
- /** Whether this registration has fired and needs reset (for requireReset) */
78
- hasFired: boolean;
79
- }
80
- /**
81
- * Creates a public view from an internal registration,
82
- * stripping the callback function.
83
- */
84
- declare function toHotkeyRegistrationView(reg: HotkeyRegistration): HotkeyRegistrationView;
85
- /**
86
- * A handle returned from HotkeyManager.register() that allows updating
87
- * the callback and options without re-registering the hotkey.
88
- *
89
- * @example
90
- * ```ts
91
- * const handle = manager.register('Mod+S', callback, options)
92
- *
93
- * // Update callback without re-registering (avoids stale closures)
94
- * handle.callback = newCallback
95
- *
96
- * // Update options without re-registering
97
- * handle.setOptions({ enabled: false })
98
- *
99
- * // Check if still active
100
- * if (handle.isActive) {
101
- * // ...
102
- * }
103
- *
104
- * // Unregister when done
105
- * handle.unregister()
106
- * ```
107
- */
108
- interface HotkeyRegistrationHandle {
109
- /**
110
- * The callback function. Can be set directly to update without re-registering.
111
- * This avoids stale closures when the callback references React state.
112
- */
113
- callback: HotkeyCallback;
114
- /** Unique identifier for this registration */
115
- readonly id: string;
116
- /** Check if this registration is still active (not unregistered) */
117
- readonly isActive: boolean;
118
- /**
119
- * Update options (merged with existing options).
120
- * Useful for updating `enabled`, `preventDefault`, etc. without re-registering.
121
- */
122
- setOptions: (options: Partial<HotkeyOptions>) => void;
123
- /** Unregister this hotkey */
124
- unregister: () => void;
125
- }
126
- /**
127
- * Singleton manager for hotkey registrations.
128
- *
129
- * This class provides a centralized way to register and manage keyboard hotkeys.
130
- * It uses a single event listener for efficiency, regardless of how many hotkeys
131
- * are registered.
132
- *
133
- * @example
134
- * ```ts
135
- * const manager = HotkeyManager.getInstance()
136
- *
137
- * const unregister = manager.register('Mod+S', (event, context) => {
138
- * console.log('Save triggered!')
139
- * })
140
- *
141
- * // Later, to unregister:
142
- * unregister()
143
- * ```
144
- */
145
- declare class HotkeyManager {
146
- #private;
147
- /**
148
- * The TanStack Store containing all hotkey registrations.
149
- * Use this to subscribe to registration changes or access current registrations.
150
- *
151
- * @example
152
- * ```ts
153
- * const manager = HotkeyManager.getInstance()
154
- *
155
- * // Subscribe to registration changes
156
- * const unsubscribe = manager.registrations.subscribe(() => {
157
- * console.log('Registrations changed:', manager.registrations.state.size)
158
- * })
159
- *
160
- * // Access current registrations
161
- * for (const [id, reg] of manager.registrations.state) {
162
- * console.log(reg.hotkey, reg.options.enabled)
163
- * }
164
- * ```
165
- */
166
- readonly registrations: Store<Map<string, HotkeyRegistration>>;
167
- private constructor();
168
- /**
169
- * Gets the singleton instance of HotkeyManager.
170
- */
171
- static getInstance(): HotkeyManager;
172
- /**
173
- * Resets the singleton instance. Useful for testing.
174
- */
175
- static resetInstance(): void;
176
- /**
177
- * Registers a hotkey handler and returns a handle for updating the registration.
178
- *
179
- * The returned handle allows updating the callback and options without
180
- * re-registering, which is useful for avoiding stale closures in React.
181
- *
182
- * @param hotkey - The hotkey string (e.g., 'Mod+S') or RawHotkey object
183
- * @param callback - The function to call when the hotkey is pressed
184
- * @param options - Options for the hotkey behavior
185
- * @returns A handle for managing the registration
186
- *
187
- * @example
188
- * ```ts
189
- * const handle = manager.register('Mod+S', callback)
190
- *
191
- * // Update callback without re-registering (avoids stale closures)
192
- * handle.callback = newCallback
193
- *
194
- * // Update options
195
- * handle.setOptions({ enabled: false })
196
- *
197
- * // Unregister when done
198
- * handle.unregister()
199
- * ```
200
- */
201
- register(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: HotkeyOptions): HotkeyRegistrationHandle;
202
- /**
203
- * Triggers a registration's callback programmatically from devtools.
204
- * Creates a synthetic KeyboardEvent and invokes the callback.
205
- *
206
- * @param id - The registration ID to trigger
207
- * @returns True if the registration was found and triggered
208
- */
209
- triggerRegistration(id: string): boolean;
210
- /**
211
- * Gets the number of registered hotkeys.
212
- */
213
- getRegistrationCount(): number;
214
- /**
215
- * Checks if a specific hotkey is registered.
216
- *
217
- * @param hotkey - The hotkey string to check
218
- * @param target - Optional target element to match (if provided, both hotkey and target must match)
219
- * @returns True if a matching registration exists
220
- */
221
- isRegistered(hotkey: Hotkey, target?: HTMLElement | Document | Window): boolean;
222
- /**
223
- * Destroys the manager and removes all listeners.
224
- */
225
- destroy(): void;
226
- }
227
- /**
228
- * Gets the singleton HotkeyManager instance.
229
- * Convenience function for accessing the manager.
230
- */
231
- declare function getHotkeyManager(): HotkeyManager;
232
- //#endregion
233
- export { HotkeyManager, HotkeyOptions, HotkeyRegistration, HotkeyRegistrationHandle, HotkeyRegistrationView, getHotkeyManager, toHotkeyRegistrationView };
234
- //# sourceMappingURL=hotkey-manager.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey-manager.js","names":["#instance","#platform","#findConflictingRegistration","#unregister","#targetRegistrations","#ensureListenersForTarget","#removeListenersForTarget","#targetListeners","#createTargetKeyDownHandler","#createTargetKeyUpHandler","#shouldResetRegistration","#executeHotkeyCallback","#processTargetEvent"],"sources":["../src/hotkey-manager.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { isRecordingEvent } from './_recording-guard'\nimport { areHotkeysEqual } from './match'\nimport { detectPlatform } from './platform'\nimport { normalizeKeyName } from './constants'\nimport { formatHotkey } from './format'\nimport { parseHotkey, rawHotkeyToParsedHotkey } from './parse'\nimport { matchKeyboardEvent } from './_match'\nimport {\n defaultHotkeyOptions,\n getDefaultIgnoreInputs,\n handleConflict,\n optionsEqual,\n} from './_registration'\nimport { isEventForTarget, shouldIgnoreInputEvent } from './_event-target'\nimport type {\n ConflictBehavior,\n Hotkey,\n HotkeyCallback,\n HotkeyCallbackContext,\n HotkeyMeta,\n ParsedHotkey,\n RegisterableHotkey,\n} from './hotkey.types'\n\nexport type { ConflictBehavior }\n\n/**\n * Options for registering a hotkey.\n */\nexport interface HotkeyOptions {\n /** Behavior when this hotkey conflicts with an existing registration on the same target. Defaults to 'warn' */\n conflictBehavior?: ConflictBehavior\n /**\n * Soft-disable: when `false`, the callback does not run but the registration\n * stays in `HotkeyManager` (and in devtools). Toggling this should update the\n * existing handle via `setOptions` rather than unregistering. Defaults to `true`.\n */\n enabled?: boolean\n /** The event type to listen for. Defaults to 'keydown' */\n eventType?: 'keydown' | 'keyup'\n /** Whether to ignore hotkeys when keyboard events originate from input-like elements (text inputs, textarea, select, contenteditable — button-type inputs like type=button/submit/reset are not ignored). Defaults based on hotkey: true for single keys and Shift/Alt combos; false for Ctrl/Meta shortcuts and Escape */\n ignoreInputs?: boolean\n /** The target platform for resolving 'Mod' */\n platform?: 'mac' | 'windows' | 'linux'\n /** Prevent the default browser action when the hotkey matches. Defaults to true */\n preventDefault?: boolean\n /** If true, only trigger once until all keys are released. Default: false */\n requireReset?: boolean\n /** Stop event propagation when the hotkey matches. Defaults to true */\n stopPropagation?: boolean\n /** The DOM element to attach the event listener to. Defaults to document. */\n target?: HTMLElement | Document | Window | null\n /** Optional metadata (name, description, custom fields via declaration merging) */\n meta?: HotkeyMeta\n}\n\n/**\n * A registered hotkey handler in the HotkeyManager.\n */\nexport interface HotkeyRegistration {\n /** The callback to invoke */\n callback: HotkeyCallback\n /** Whether this registration has fired and needs reset (for requireReset) */\n hasFired: boolean\n /** The concrete key/code that activated a requireReset registration. */\n activeMatch?: { key: string; code: string }\n /** The original hotkey string */\n hotkey: Hotkey\n /** Unique identifier for this registration */\n id: string\n /** Options for this registration */\n options: HotkeyOptions\n /** The parsed hotkey */\n parsedHotkey: ParsedHotkey\n /** The resolved target element for this registration */\n target: HTMLElement | Document | Window\n /** How many times this registration's callback has been triggered */\n triggerCount: number\n}\n\n/**\n * Public view of a hotkey registration for display and introspection.\n * Omits the callback function which is an internal implementation detail.\n */\nexport interface HotkeyRegistrationView {\n /** The original hotkey string */\n hotkey: Hotkey\n /** Unique identifier for this registration */\n id: string\n /** Options for this registration */\n options: HotkeyOptions\n /** The parsed hotkey */\n parsedHotkey: ParsedHotkey\n /** The resolved target element for this registration */\n target: HTMLElement | Document | Window\n /** How many times this registration's callback has been triggered */\n triggerCount: number\n /** Whether this registration has fired and needs reset (for requireReset) */\n hasFired: boolean\n}\n\n/**\n * Creates a public view from an internal registration,\n * stripping the callback function.\n */\nexport function toHotkeyRegistrationView(\n reg: HotkeyRegistration,\n): HotkeyRegistrationView {\n return {\n hotkey: reg.hotkey,\n id: reg.id,\n options: reg.options,\n parsedHotkey: reg.parsedHotkey,\n target: reg.target,\n triggerCount: reg.triggerCount,\n hasFired: reg.hasFired,\n }\n}\n\n/**\n * A handle returned from HotkeyManager.register() that allows updating\n * the callback and options without re-registering the hotkey.\n *\n * @example\n * ```ts\n * const handle = manager.register('Mod+S', callback, options)\n *\n * // Update callback without re-registering (avoids stale closures)\n * handle.callback = newCallback\n *\n * // Update options without re-registering\n * handle.setOptions({ enabled: false })\n *\n * // Check if still active\n * if (handle.isActive) {\n * // ...\n * }\n *\n * // Unregister when done\n * handle.unregister()\n * ```\n */\nexport interface HotkeyRegistrationHandle {\n /**\n * The callback function. Can be set directly to update without re-registering.\n * This avoids stale closures when the callback references React state.\n */\n callback: HotkeyCallback\n /** Unique identifier for this registration */\n readonly id: string\n /** Check if this registration is still active (not unregistered) */\n readonly isActive: boolean\n /**\n * Update options (merged with existing options).\n * Useful for updating `enabled`, `preventDefault`, etc. without re-registering.\n */\n setOptions: (options: Partial<HotkeyOptions>) => void\n /** Unregister this hotkey */\n unregister: () => void\n}\n\nlet registrationIdCounter = 0\n\n/**\n * Generates a unique ID for hotkey registrations.\n */\nfunction generateId(): string {\n return `hotkey_${++registrationIdCounter}`\n}\n\n/**\n * Singleton manager for hotkey registrations.\n *\n * This class provides a centralized way to register and manage keyboard hotkeys.\n * It uses a single event listener for efficiency, regardless of how many hotkeys\n * are registered.\n *\n * @example\n * ```ts\n * const manager = HotkeyManager.getInstance()\n *\n * const unregister = manager.register('Mod+S', (event, context) => {\n * console.log('Save triggered!')\n * })\n *\n * // Later, to unregister:\n * unregister()\n * ```\n */\nexport class HotkeyManager {\n static #instance: HotkeyManager | null = null\n\n /**\n * The TanStack Store containing all hotkey registrations.\n * Use this to subscribe to registration changes or access current registrations.\n *\n * @example\n * ```ts\n * const manager = HotkeyManager.getInstance()\n *\n * // Subscribe to registration changes\n * const unsubscribe = manager.registrations.subscribe(() => {\n * console.log('Registrations changed:', manager.registrations.state.size)\n * })\n *\n * // Access current registrations\n * for (const [id, reg] of manager.registrations.state) {\n * console.log(reg.hotkey, reg.options.enabled)\n * }\n * ```\n */\n readonly registrations: Store<Map<string, HotkeyRegistration>> = new Store(\n new Map(),\n )\n #platform: 'mac' | 'windows' | 'linux'\n #targetListeners: Map<\n HTMLElement | Document | Window,\n {\n keydown: (event: KeyboardEvent) => void\n keyup: (event: KeyboardEvent) => void\n }\n > = new Map()\n #targetRegistrations: Map<HTMLElement | Document | Window, Set<string>> =\n new Map()\n\n private constructor() {\n this.#platform = detectPlatform()\n }\n\n /**\n * Gets the singleton instance of HotkeyManager.\n */\n static getInstance(): HotkeyManager {\n if (!HotkeyManager.#instance) {\n HotkeyManager.#instance = new HotkeyManager()\n }\n return HotkeyManager.#instance\n }\n\n /**\n * Resets the singleton instance. Useful for testing.\n */\n static resetInstance(): void {\n if (HotkeyManager.#instance) {\n HotkeyManager.#instance.destroy()\n HotkeyManager.#instance = null\n }\n }\n\n /**\n * Registers a hotkey handler and returns a handle for updating the registration.\n *\n * The returned handle allows updating the callback and options without\n * re-registering, which is useful for avoiding stale closures in React.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S') or RawHotkey object\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n * @returns A handle for managing the registration\n *\n * @example\n * ```ts\n * const handle = manager.register('Mod+S', callback)\n *\n * // Update callback without re-registering (avoids stale closures)\n * handle.callback = newCallback\n *\n * // Update options\n * handle.setOptions({ enabled: false })\n *\n * // Unregister when done\n * handle.unregister()\n * ```\n */\n register(\n hotkey: RegisterableHotkey,\n callback: HotkeyCallback,\n options: HotkeyOptions = {},\n ): HotkeyRegistrationHandle {\n // In SSR environments, return a no-op handle since there's no DOM to attach listeners to\n if (typeof document === 'undefined' && !options.target) {\n let currentCallback = callback\n return {\n id: generateId(),\n unregister: () => {},\n get callback() {\n return currentCallback\n },\n set callback(newCallback: HotkeyCallback) {\n currentCallback = newCallback\n },\n setOptions: () => {},\n get isActive() {\n return false\n },\n }\n }\n\n const id = generateId()\n const platform = options.platform ?? this.#platform\n const parsedHotkey =\n typeof hotkey === 'string'\n ? parseHotkey(hotkey, platform)\n : rawHotkeyToParsedHotkey(hotkey, platform)\n const hotkeyStr = (\n typeof hotkey === 'string' ? hotkey : formatHotkey(parsedHotkey)\n ) as Hotkey\n\n // Resolve target: default to document if not provided\n // Note: SSR case without explicit target is handled above\n const target = options.target ?? document\n\n // Resolve conflict behavior\n const conflictBehavior = options.conflictBehavior ?? 'warn'\n\n // Check for existing registrations with the same hotkey and target\n const conflictingRegistration = this.#findConflictingRegistration(\n hotkeyStr,\n target,\n )\n\n if (conflictingRegistration) {\n handleConflict(\n conflictingRegistration.id,\n hotkeyStr,\n conflictBehavior,\n (id) => this.#unregister(id),\n )\n }\n\n const resolvedIgnoreInputs =\n options.ignoreInputs ?? getDefaultIgnoreInputs(parsedHotkey)\n\n const baseOptions = {\n ...defaultHotkeyOptions,\n requireReset: false,\n ...options,\n platform,\n }\n\n const registration: HotkeyRegistration = {\n id,\n hotkey: hotkeyStr,\n parsedHotkey,\n callback,\n options: { ...baseOptions, ignoreInputs: resolvedIgnoreInputs },\n hasFired: false,\n triggerCount: 0,\n target,\n }\n\n this.registrations.setState((prev) => new Map(prev).set(id, registration))\n\n // Track registration for this target\n if (!this.#targetRegistrations.has(target)) {\n this.#targetRegistrations.set(target, new Set())\n }\n this.#targetRegistrations.get(target)!.add(id)\n\n // Ensure listeners are attached for this target\n this.#ensureListenersForTarget(target)\n\n // Create and return the handle\n const manager = this\n const handle: HotkeyRegistrationHandle = {\n get id() {\n return id\n },\n unregister: () => {\n manager.#unregister(id)\n },\n get callback() {\n const reg = manager.registrations.state.get(id)\n return reg?.callback ?? callback\n },\n set callback(newCallback: HotkeyCallback) {\n const reg = manager.registrations.state.get(id)\n if (reg) {\n reg.callback = newCallback\n }\n },\n setOptions: (newOptions: Partial<HotkeyOptions>) => {\n manager.registrations.setState((prev) => {\n const reg = prev.get(id)\n if (\n reg &&\n !optionsEqual(reg.options, { ...reg.options, ...newOptions })\n ) {\n const next = new Map(prev)\n next.set(id, { ...reg, options: { ...reg.options, ...newOptions } })\n return next\n }\n return prev\n })\n },\n get isActive() {\n return manager.registrations.state.has(id)\n },\n }\n\n return handle\n }\n\n /**\n * Unregisters a hotkey by its registration ID.\n */\n #unregister(id: string): void {\n const registration = this.registrations.state.get(id)\n if (!registration) {\n return\n }\n\n const target = registration.target\n\n // Remove registration\n this.registrations.setState((prev) => {\n const next = new Map(prev)\n next.delete(id)\n return next\n })\n\n // Remove from target registrations tracking\n const targetRegs = this.#targetRegistrations.get(target)\n if (targetRegs) {\n targetRegs.delete(id)\n // If no more registrations for this target, remove listeners\n if (targetRegs.size === 0) {\n this.#removeListenersForTarget(target)\n }\n }\n }\n\n /**\n * Ensures event listeners are attached for a specific target.\n */\n #ensureListenersForTarget(target: HTMLElement | Document | Window): void {\n if (typeof document === 'undefined') {\n return // SSR safety\n }\n\n // Skip if listeners already exist for this target\n if (this.#targetListeners.has(target)) {\n return\n }\n\n const keydownHandler = this.#createTargetKeyDownHandler(target)\n const keyupHandler = this.#createTargetKeyUpHandler(target)\n\n target.addEventListener('keydown', keydownHandler as EventListener)\n target.addEventListener('keyup', keyupHandler as EventListener)\n\n this.#targetListeners.set(target, {\n keydown: keydownHandler,\n keyup: keyupHandler,\n })\n }\n\n /**\n * Removes event listeners for a specific target.\n */\n #removeListenersForTarget(target: HTMLElement | Document | Window): void {\n if (typeof document === 'undefined') {\n return\n }\n\n const listeners = this.#targetListeners.get(target)\n if (!listeners) {\n return\n }\n\n target.removeEventListener('keydown', listeners.keydown as EventListener)\n target.removeEventListener('keyup', listeners.keyup as EventListener)\n\n this.#targetListeners.delete(target)\n this.#targetRegistrations.delete(target)\n }\n\n /**\n * Processes keyboard events for a specific target and event type.\n */\n #processTargetEvent(\n event: KeyboardEvent,\n target: HTMLElement | Document | Window,\n eventType: 'keydown' | 'keyup',\n ): void {\n // Releases clear latches even when focus or enabled state now prevents callbacks.\n if (eventType === 'keyup') {\n for (const id of this.#targetRegistrations.get(target) ?? []) {\n const registration = this.registrations.state.get(id)\n if (\n registration?.hasFired &&\n this.#shouldResetRegistration(registration, event)\n ) {\n registration.hasFired = false\n registration.activeMatch = undefined\n }\n }\n }\n if (isRecordingEvent(event)) return\n const targetRegs = this.#targetRegistrations.get(target)\n if (!targetRegs) {\n return\n }\n\n const matches = new Map<string, ReturnType<typeof matchKeyboardEvent>>()\n let bestScore = 0\n\n // Exact logical/explicit-code matches outrank compatibility fallbacks.\n for (const id of targetRegs) {\n const registration = this.registrations.state.get(id)\n if (\n !registration ||\n !registration.options.enabled ||\n registration.options.eventType !== eventType ||\n !isEventForTarget(event, target) ||\n (registration.options.ignoreInputs !== false &&\n shouldIgnoreInputEvent(event, target, registration.target))\n ) {\n continue\n }\n const result = matchKeyboardEvent(\n event,\n registration.parsedHotkey,\n registration.options.platform,\n )\n if (result.matched) {\n matches.set(id, result)\n bestScore = Math.max(bestScore, result.score)\n }\n }\n\n for (const id of targetRegs) {\n const registration = this.registrations.state.get(id)\n if (!registration) {\n continue\n }\n\n // Check if event originated from or bubbled to this target\n if (!isEventForTarget(event, target)) {\n continue\n }\n\n if (!registration.options.enabled) {\n continue\n }\n\n // Check if we should ignore input elements (defaults to true)\n if (registration.options.ignoreInputs !== false) {\n if (shouldIgnoreInputEvent(event, target, registration.target)) {\n continue\n }\n }\n\n // Handle keydown events\n if (eventType === 'keydown') {\n if (registration.options.eventType !== 'keydown') {\n continue\n }\n\n const match = matches.get(id)\n\n if (match?.matched && match.score === bestScore) {\n // Always apply preventDefault/stopPropagation if the hotkey matches,\n // even when requireReset is active and has already fired\n if (registration.options.preventDefault) {\n event.preventDefault()\n }\n if (registration.options.stopPropagation) {\n event.stopPropagation()\n }\n\n // Only execute callback if requireReset is not active or hasn't fired yet\n if (!registration.options.requireReset || !registration.hasFired) {\n this.#executeHotkeyCallback(registration, event)\n\n // Mark as fired if requireReset is enabled\n if (registration.options.requireReset) {\n registration.hasFired = true\n registration.activeMatch = match.identity\n }\n }\n }\n }\n // Handle keyup events\n else {\n if (registration.options.eventType === 'keyup') {\n const match = matches.get(id)\n if (match?.matched && match.score === bestScore) {\n this.#executeHotkeyCallback(registration, event)\n }\n }\n }\n }\n }\n\n /**\n * Executes a hotkey callback with proper event handling.\n */\n #executeHotkeyCallback(\n registration: HotkeyRegistration,\n event: KeyboardEvent,\n ): void {\n if (registration.options.preventDefault) {\n event.preventDefault()\n }\n if (registration.options.stopPropagation) {\n event.stopPropagation()\n }\n\n registration.triggerCount++\n\n // Notify the store so subscribers (e.g. devtools) see the updated count.\n // We create a new Map but keep the same registration reference to preserve\n // identity for mutation-based fields like hasFired.\n this.registrations.setState((prev) => new Map(prev))\n\n const context: HotkeyCallbackContext = {\n hotkey: registration.hotkey,\n parsedHotkey: registration.parsedHotkey,\n }\n\n registration.callback(event, context)\n }\n\n /**\n * Creates a keydown handler for a specific target.\n */\n #createTargetKeyDownHandler(\n target: HTMLElement | Document | Window,\n ): (event: KeyboardEvent) => void {\n return (event: KeyboardEvent) => {\n this.#processTargetEvent(event, target, 'keydown')\n }\n }\n\n /**\n * Creates a keyup handler for a specific target.\n */\n #createTargetKeyUpHandler(\n target: HTMLElement | Document | Window,\n ): (event: KeyboardEvent) => void {\n return (event: KeyboardEvent) => {\n this.#processTargetEvent(event, target, 'keyup')\n }\n }\n\n /**\n * Finds an existing registration with the same hotkey and target.\n */\n #findConflictingRegistration(\n hotkey: Hotkey,\n target: HTMLElement | Document | Window,\n ): HotkeyRegistration | null {\n for (const registration of this.registrations.state.values()) {\n if (\n areHotkeysEqual(\n registration.hotkey,\n hotkey,\n registration.options.platform,\n ) &&\n registration.target === target\n ) {\n return registration\n }\n }\n return null\n }\n\n /**\n * Determines if a registration should be reset based on the keyup event.\n */\n #shouldResetRegistration(\n registration: HotkeyRegistration,\n event: KeyboardEvent,\n ): boolean {\n const parsed = registration.parsedHotkey\n const releasedKey = normalizeKeyName(event.key)\n\n if (\n registration.activeMatch?.code &&\n event.code === registration.activeMatch.code\n ) {\n return true\n }\n\n // Compare the release against the identity this binding actually stores.\n if (parsed.code !== undefined) {\n if (event.code === parsed.code) return true\n } else {\n const parsedKeyNormalized =\n parsed.key.length === 1 ? parsed.key.toUpperCase() : parsed.key\n const releasedKeyNormalized =\n releasedKey.length === 1 ? releasedKey.toUpperCase() : releasedKey\n if (releasedKeyNormalized === parsedKeyNormalized) return true\n }\n\n // Reset if any required modifier is released\n // Use normalized key names and check against canonical modifier names\n if (parsed.ctrl && releasedKey === 'Control') {\n return true\n }\n if (parsed.shift && releasedKey === 'Shift') {\n return true\n }\n if (parsed.alt && releasedKey === 'Alt') {\n return true\n }\n if (parsed.meta && releasedKey === 'Meta') {\n return true\n }\n\n return false\n }\n\n /**\n * Triggers a registration's callback programmatically from devtools.\n * Creates a synthetic KeyboardEvent and invokes the callback.\n *\n * @param id - The registration ID to trigger\n * @returns True if the registration was found and triggered\n */\n triggerRegistration(id: string): boolean {\n const registration = this.registrations.state.get(id)\n if (!registration) {\n return false\n }\n\n const parsed = registration.parsedHotkey\n const syntheticEvent = new KeyboardEvent(\n registration.options.eventType ?? 'keydown',\n {\n ...(parsed.code !== undefined\n ? { code: parsed.code }\n : { key: parsed.key }),\n ctrlKey: parsed.ctrl,\n shiftKey: parsed.shift,\n altKey: parsed.alt,\n metaKey: parsed.meta,\n bubbles: true,\n cancelable: true,\n },\n )\n\n registration.triggerCount++\n\n // Notify the store so subscribers (e.g. devtools) see the updated count\n this.registrations.setState((prev) => new Map(prev))\n\n registration.callback(syntheticEvent, {\n hotkey: registration.hotkey,\n parsedHotkey: registration.parsedHotkey,\n })\n\n return true\n }\n\n /**\n * Gets the number of registered hotkeys.\n */\n getRegistrationCount(): number {\n return this.registrations.state.size\n }\n\n /**\n * Checks if a specific hotkey is registered.\n *\n * @param hotkey - The hotkey string to check\n * @param target - Optional target element to match (if provided, both hotkey and target must match)\n * @returns True if a matching registration exists\n */\n isRegistered(\n hotkey: Hotkey,\n target?: HTMLElement | Document | Window,\n ): boolean {\n for (const registration of this.registrations.state.values()) {\n if (\n areHotkeysEqual(\n registration.hotkey,\n hotkey,\n registration.options.platform,\n )\n ) {\n // If target is specified, both must match\n if (target === undefined || registration.target === target) {\n return true\n }\n }\n }\n return false\n }\n\n /**\n * Destroys the manager and removes all listeners.\n */\n destroy(): void {\n // Remove all target listeners\n for (const target of this.#targetListeners.keys()) {\n this.#removeListenersForTarget(target)\n }\n\n this.registrations.setState(() => new Map())\n this.#targetListeners.clear()\n this.#targetRegistrations.clear()\n }\n}\n\n/**\n * Gets the singleton HotkeyManager instance.\n * Convenience function for accessing the manager.\n */\nexport function getHotkeyManager(): HotkeyManager {\n return HotkeyManager.getInstance()\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0GA,SAAgB,yBACd,KACwB;AACxB,QAAO;EACL,QAAQ,IAAI;EACZ,IAAI,IAAI;EACR,SAAS,IAAI;EACb,cAAc,IAAI;EAClB,QAAQ,IAAI;EACZ,cAAc,IAAI;EAClB,UAAU,IAAI;EACf;;AA6CH,IAAI,wBAAwB;;;;AAK5B,SAAS,aAAqB;AAC5B,QAAO,UAAU,EAAE;;;;;;;;;;;;;;;;;;;;;AAsBrB,IAAa,gBAAb,MAAa,cAAc;CACzB,QAAOA,WAAkC;CAwBzC;CACA,mCAMI,IAAI,KAAK;CACb,uCACE,IAAI,KAAK;CAEX,AAAQ,cAAc;uBAd2C,IAAI,sBACnE,IAAI,KAAK,CACV;AAaC,QAAKC,WAAY,gBAAgB;;;;;CAMnC,OAAO,cAA6B;AAClC,MAAI,CAAC,eAAcD,SACjB,gBAAcA,WAAY,IAAI,eAAe;AAE/C,SAAO,eAAcA;;;;;CAMvB,OAAO,gBAAsB;AAC3B,MAAI,eAAcA,UAAW;AAC3B,kBAAcA,SAAU,SAAS;AACjC,kBAAcA,WAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B9B,SACE,QACA,UACA,UAAyB,EAAE,EACD;AAE1B,MAAI,OAAO,aAAa,eAAe,CAAC,QAAQ,QAAQ;GACtD,IAAI,kBAAkB;AACtB,UAAO;IACL,IAAI,YAAY;IAChB,kBAAkB;IAClB,IAAI,WAAW;AACb,YAAO;;IAET,IAAI,SAAS,aAA6B;AACxC,uBAAkB;;IAEpB,kBAAkB;IAClB,IAAI,WAAW;A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ClD,QAAO;;AAIb,SAAO;;;;;CAMT,UAAgB;AAEd,OAAK,MAAM,UAAU,MAAKL,gBAAiB,MAAM,CAC/C,OAAKD,yBAA0B,OAAO;AAGxC,OAAK,cAAc,+BAAe,IAAI,KAAK,CAAC;AAC5C,QAAKC,gBAAiB,OAAO;AAC7B,QAAKH,oBAAqB,OAAO;;;;;;;AAQrC,SAAgB,mBAAkC;AAChD,QAAO,cAAc,aAAa"}
@@ -1,235 +0,0 @@
1
- const require_platform = require('./platform.cjs');
2
- const require__keyboard_event = require('./_keyboard-event.cjs');
3
- const require_parse = require('./parse.cjs');
4
- const require_validate = require('./validate.cjs');
5
- const require__recording_guard = require('./_recording-guard.cjs');
6
- const require__event_target = require('./_event-target.cjs');
7
- const require_conflicts = require('./conflicts.cjs');
8
- const require__recorder_chord = require('./_recorder-chord.cjs');
9
- let _tanstack_store = require("@tanstack/store");
10
-
11
- //#region src/hotkey-recorder.ts
12
- /**
13
- * Framework-agnostic class for recording keyboard shortcuts.
14
- *
15
- * This class handles all the complexity of capturing keyboard events,
16
- * converting them to hotkey strings, and handling edge cases like
17
- * Escape to cancel or Backspace/Delete to clear.
18
- *
19
- * State Management:
20
- * - Uses TanStack Store for reactive state management
21
- * - State can be accessed via `recorder.store.state` when using the class directly
22
- * - When using framework adapters (React), use `useSelector` hooks for reactive state
23
- *
24
- * @example
25
- * ```ts
26
- * const recorder = new HotkeyRecorder({
27
- * onRecord: (hotkey) => {
28
- * console.log('Recorded:', hotkey)
29
- * },
30
- * onCancel: () => {
31
- * console.log('Recording cancelled')
32
- * },
33
- * })
34
- *
35
- * // Start recording
36
- * recorder.start()
37
- *
38
- * // Access state directly
39
- * console.log(recorder.store.state.isRecording) // true
40
- *
41
- * // Subscribe to changes with TanStack Store
42
- * const unsubscribe = recorder.store.subscribe(() => {
43
- * console.log('Recording:', recorder.store.state.isRecording)
44
- * })
45
- *
46
- * // Cleanup
47
- * recorder.destroy()
48
- * unsubscribe()
49
- * ```
50
- */
51
- var HotkeyRecorder = class {
52
- #keydownHandler = null;
53
- #options;
54
- #platform;
55
- constructor(options) {
56
- this.store = new _tanstack_store.Store({
57
- isRecording: false,
58
- recordedHotkey: null
59
- });
60
- this.#options = options;
61
- this.#platform = require_platform.detectPlatform();
62
- }
63
- /**
64
- * Updates the recorder options, including callbacks.
65
- * This allows framework adapters to sync callback changes without recreating the recorder.
66
- */
67
- setOptions(options) {
68
- this.#options = {
69
- ...this.#options,
70
- ...options
71
- };
72
- }
73
- /**
74
- * Start recording a new hotkey.
75
- *
76
- * Sets up a keydown event listener that captures keyboard events
77
- * and converts them to hotkey strings. Recording continues until
78
- * a valid hotkey is recorded, Escape is pressed, or stop/cancel is called.
79
- */
80
- start() {
81
- if (this.#keydownHandler) return;
82
- require__recording_guard.beginRecording(this);
83
- this.store.setState(() => ({
84
- isRecording: true,
85
- recordedHotkey: null
86
- }));
87
- const handler = (event) => {
88
- if (!this.#keydownHandler) return;
89
- if (this.#options.ignoreInputs !== false && event.key !== "Escape" && require__event_target.shouldIgnoreInputEvent(event, document, document)) return;
90
- const platform = this.#options.platform ?? this.#platform;
91
- if (require__keyboard_event.normalizeKeyboardEvent(event, platform).isComposing) return;
92
- require__recording_guard.captureRecordingEvent(event);
93
- event.preventDefault();
94
- event.stopPropagation();
95
- if (event.repeat) return;
96
- if (event.key === "Escape") {
97
- this.cancel();
98
- return;
99
- }
100
- if (event.key === "Backspace" || event.key === "Delete") {
101
- if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
102
- this.stop();
103
- this.#options.onClear?.();
104
- return;
105
- }
106
- }
107
- if (require_parse.isModifierKey(event.key) || event.key === "AltGraph") return;
108
- const rejection = require__recorder_chord.chordRejection(event, {
109
- ...this.#options,
110
- platform
111
- });
112
- if (rejection) {
113
- this.#options.onReject?.(rejection);
114
- return;
115
- }
116
- const finalHotkey = require__recorder_chord.hotkeyChordFromKeydown(event, platform, this.#options.recordBy);
117
- if (finalHotkey === null) return;
118
- const validation = require_validate.validateHotkey(finalHotkey);
119
- if (!validation.valid) {
120
- this.#options.onReject?.({
121
- reason: "invalid",
122
- message: validation.errors.join("; "),
123
- hotkey: finalHotkey
124
- });
125
- return;
126
- }
127
- const accepted = this.#options.validate?.(finalHotkey, {
128
- event,
129
- parsedHotkey: require_parse.parseHotkey(finalHotkey, platform)
130
- });
131
- if (accepted !== void 0 && accepted !== true) {
132
- this.#options.onReject?.({
133
- reason: "validation",
134
- message: typeof accepted === "string" ? accepted : "This shortcut is not allowed.",
135
- hotkey: finalHotkey
136
- });
137
- return;
138
- }
139
- if (this.#options.detectConflicts) {
140
- const conflicts = require_conflicts.findHotkeyConflicts(finalHotkey, {
141
- ...typeof this.#options.detectConflicts === "object" ? this.#options.detectConflicts : {},
142
- platform,
143
- events: [event]
144
- });
145
- if (conflicts.length) {
146
- this.#options.onReject?.({
147
- reason: "conflict",
148
- message: "This shortcut conflicts with a registered binding.",
149
- hotkey: finalHotkey,
150
- conflicts
151
- });
152
- return;
153
- }
154
- }
155
- require__recording_guard.endRecording(this);
156
- const handlerToRemove = this.#keydownHandler;
157
- if (handlerToRemove) {
158
- this.#removeListener(handlerToRemove);
159
- this.#keydownHandler = null;
160
- }
161
- this.store.setState(() => ({
162
- isRecording: false,
163
- recordedHotkey: finalHotkey
164
- }));
165
- this.#options.onRecord(finalHotkey);
166
- };
167
- this.#keydownHandler = handler;
168
- this.#addListener(handler);
169
- }
170
- /**
171
- * Stop recording (same as cancel, but doesn't call onCancel).
172
- *
173
- * Removes the event listener and resets the recording state.
174
- */
175
- stop() {
176
- require__recording_guard.endRecording(this);
177
- if (this.#keydownHandler) {
178
- this.#removeListener(this.#keydownHandler);
179
- this.#keydownHandler = null;
180
- }
181
- this.store.setState(() => ({
182
- isRecording: false,
183
- recordedHotkey: null
184
- }));
185
- }
186
- /**
187
- * Cancel recording without saving.
188
- *
189
- * Removes the event listener, resets the recording state, and calls
190
- * the onCancel callback if provided.
191
- */
192
- cancel() {
193
- require__recording_guard.endRecording(this);
194
- if (this.#keydownHandler) {
195
- this.#removeListener(this.#keydownHandler);
196
- this.#keydownHandler = null;
197
- }
198
- this.store.setState(() => ({
199
- isRecording: false,
200
- recordedHotkey: null
201
- }));
202
- this.#options.onCancel?.();
203
- }
204
- /**
205
- * Adds the keydown event listener to the document.
206
- */
207
- #addListener(handler) {
208
- if (typeof document === "undefined") return;
209
- document.addEventListener("keydown", handler, true);
210
- }
211
- /**
212
- * Removes the keydown event listener from the document.
213
- */
214
- #removeListener(handler) {
215
- if (typeof document === "undefined") return;
216
- document.removeEventListener("keydown", handler, true);
217
- }
218
- /**
219
- * Clean up event listeners and reset state.
220
- *
221
- * Call this when you're done with the recorder to ensure
222
- * all event listeners are properly removed.
223
- */
224
- destroy() {
225
- this.stop();
226
- this.store.setState(() => ({
227
- isRecording: false,
228
- recordedHotkey: null
229
- }));
230
- }
231
- };
232
-
233
- //#endregion
234
- exports.HotkeyRecorder = HotkeyRecorder;
235
- //# sourceMappingURL=hotkey-recorder.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey-recorder.cjs","names":["Store","#options","#platform","detectPlatform","#keydownHandler","shouldIgnoreInputEvent","normalizeKeyboardEvent","isModifierKey","chordRejection","hotkeyChordFromKeydown","validateHotkey","parseHotkey","findHotkeyConflicts","#removeListener","#addListener"],"sources":["../src/hotkey-recorder.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { findHotkeyConflicts } from './conflicts'\nimport {\n beginRecording,\n captureRecordingEvent,\n endRecording,\n} from './_recording-guard'\nimport { chordRejection, hotkeyChordFromKeydown } from './_recorder-chord'\nimport { normalizeKeyboardEvent } from './_keyboard-event'\nimport { isModifierKey, parseHotkey } from './parse'\nimport { validateHotkey } from './validate'\nimport { detectPlatform } from './platform'\nimport { shouldIgnoreInputEvent } from './_event-target'\nimport type {\n HotkeyRecorderValidationContext,\n RecorderOptions,\n} from './recorder-options'\nimport type { Hotkey } from './hotkey.types'\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 extends RecorderOptions {\n /** Return true to accept, or false/a message to reject while staying in recording mode. */\n validate?: (\n hotkey: Hotkey,\n context: HotkeyRecorderValidationContext,\n ) => boolean | string\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 * Whether to ignore keyboard events from input-like elements (text inputs,\n * textarea, select, contenteditable). When true, typing in inputs passes\n * through normally instead of being captured as a hotkey recording.\n * Escape always works regardless of this setting.\n * @default true\n */\n ignoreInputs?: boolean\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 `useSelector` 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 beginRecording(this)\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 // If ignoreInputs is enabled (default) and focus is in an input element,\n // let the event pass through so the user can type normally.\n // Escape is the exception — it should always cancel recording.\n if (\n this.#options.ignoreInputs !== false &&\n event.key !== 'Escape' &&\n shouldIgnoreInputEvent(event, document, document)\n )\n return\n\n const platform = this.#options.platform ?? this.#platform\n if (normalizeKeyboardEvent(event, platform).isComposing) return\n captureRecordingEvent(event)\n event.preventDefault()\n event.stopPropagation()\n if (event.repeat) return\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.stop()\n this.#options.onClear?.()\n return\n }\n }\n\n if (isModifierKey(event.key) || event.key === 'AltGraph') return\n const rejection = chordRejection(event, { ...this.#options, platform })\n if (rejection) {\n this.#options.onReject?.(rejection)\n return\n }\n const finalHotkey = hotkeyChordFromKeydown(\n event,\n platform,\n this.#options.recordBy,\n )\n if (finalHotkey === null) {\n return\n }\n\n const validation = validateHotkey(finalHotkey)\n if (!validation.valid) {\n this.#options.onReject?.({\n reason: 'invalid',\n message: validation.errors.join('; '),\n hotkey: finalHotkey,\n })\n return\n }\n const accepted = this.#options.validate?.(finalHotkey, {\n event,\n parsedHotkey: parseHotkey(finalHotkey, platform),\n })\n if (accepted !== undefined && accepted !== true) {\n this.#options.onReject?.({\n reason: 'validation',\n message:\n typeof accepted === 'string'\n ? accepted\n : 'This shortcut is not allowed.',\n hotkey: finalHotkey,\n })\n return\n }\n if (this.#options.detectConflicts) {\n const conflicts = findHotkeyConflicts(finalHotkey, {\n ...(typeof this.#options.detectConflicts === 'object'\n ? this.#options.detectConflicts\n : {}),\n platform,\n events: [event],\n })\n if (conflicts.length) {\n this.#options.onReject?.({\n reason: 'conflict',\n message: 'This shortcut conflicts with a registered binding.',\n hotkey: finalHotkey,\n conflicts,\n })\n return\n }\n }\n endRecording(this)\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 endRecording(this)\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 endRecording(this)\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,IAAa,iBAAb,MAA4B;CAU1B,kBAA2D;CAC3D;CACA;CAEA,YAAY,SAAgC;eATC,IAAIA,sBAA2B;GAC1E,aAAa;GACb,gBAAgB;GACjB,CAAC;AAOA,QAAKC,UAAW;AAChB,QAAKC,WAAYC,iCAAgB;;;;;;CAOnC,WAAW,SAA+C;AACxD,QAAKF,UAAW;GACd,GAAG,MAAKA;GACR,GAAG;GACJ;;;;;;;;;CAUH,QAAc;AAEZ,MAAI,MAAKG,eACP;AAGF,0CAAe,KAAK;AAEpB,OAAK,MAAM,gBAAgB;GACzB,aAAa;GACb,gBAAgB;GACjB,EAAE;EAGH,MAAM,WAAW,UAAyB;AAExC,OAAI,CAAC,MAAKA,eACR;AAMF,OACE,MAAKH,QAAS,iBAAiB,SAC/B,MAAM,QAAQ,YACdI,6CAAuB,OAAO,UAAU,SAAS,CAEjD;GAEF,MAAM,WAAW,MAAK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