@tanstack/solid-hotkeys 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/HotkeysProvider.d.ts +6 -9
- package/dist/HotkeysProvider.js +1 -2
- package/dist/createHeldKeyCodes.d.ts +2 -4
- package/dist/createHeldKeyCodes.js +3 -3
- package/dist/createHeldKeys.d.ts +2 -4
- package/dist/createHeldKeys.js +3 -3
- package/dist/createHotkey.d.ts +3 -6
- package/dist/createHotkey.js +3 -3
- package/dist/createHotkeyHint.d.ts +2 -5
- package/dist/createHotkeyHint.js +1 -2
- package/dist/createHotkeyRecorder.d.ts +3 -6
- package/dist/createHotkeyRecorder.js +4 -4
- package/dist/createHotkeyRegistrations.d.ts +3 -6
- package/dist/createHotkeyRegistrations.js +1 -2
- package/dist/createHotkeySequence.d.ts +3 -6
- package/dist/createHotkeySequence.js +1 -2
- package/dist/createHotkeySequenceRecorder.d.ts +3 -6
- package/dist/createHotkeySequenceRecorder.js +4 -4
- package/dist/createHotkeySequences.d.ts +3 -6
- package/dist/createHotkeySequences.js +1 -2
- package/dist/createHotkeys.d.ts +3 -6
- package/dist/createHotkeys.js +1 -2
- package/dist/createKeyHold.d.ts +2 -5
- package/dist/createKeyHold.js +3 -3
- package/package.json +12 -17
- package/dist/HotkeysProvider.cjs +0 -27
- package/dist/HotkeysProvider.cjs.map +0 -1
- package/dist/HotkeysProvider.d.cts +0 -25
- package/dist/HotkeysProvider.js.map +0 -1
- package/dist/createHeldKeyCodes.cjs +0 -42
- package/dist/createHeldKeyCodes.cjs.map +0 -1
- package/dist/createHeldKeyCodes.d.cts +0 -36
- package/dist/createHeldKeyCodes.js.map +0 -1
- package/dist/createHeldKeys.cjs +0 -33
- package/dist/createHeldKeys.cjs.map +0 -1
- package/dist/createHeldKeys.d.cts +0 -27
- package/dist/createHeldKeys.js.map +0 -1
- package/dist/createHotkey.cjs +0 -120
- package/dist/createHotkey.cjs.map +0 -1
- package/dist/createHotkey.d.cts +0 -72
- package/dist/createHotkey.js.map +0 -1
- package/dist/createHotkeyHint.cjs +0 -20
- package/dist/createHotkeyHint.cjs.map +0 -1
- package/dist/createHotkeyHint.d.cts +0 -14
- package/dist/createHotkeyHint.js.map +0 -1
- package/dist/createHotkeyRecorder.cjs +0 -78
- package/dist/createHotkeyRecorder.cjs.map +0 -1
- package/dist/createHotkeyRecorder.d.cts +0 -60
- package/dist/createHotkeyRecorder.js.map +0 -1
- package/dist/createHotkeyRegistrations.cjs +0 -26
- package/dist/createHotkeyRegistrations.cjs.map +0 -1
- package/dist/createHotkeyRegistrations.d.cts +0 -26
- package/dist/createHotkeyRegistrations.js.map +0 -1
- package/dist/createHotkeySequence.cjs +0 -107
- package/dist/createHotkeySequence.cjs.map +0 -1
- package/dist/createHotkeySequence.d.cts +0 -56
- package/dist/createHotkeySequence.js.map +0 -1
- package/dist/createHotkeySequenceRecorder.cjs +0 -43
- package/dist/createHotkeySequenceRecorder.cjs.map +0 -1
- package/dist/createHotkeySequenceRecorder.d.cts +0 -19
- package/dist/createHotkeySequenceRecorder.js.map +0 -1
- package/dist/createHotkeySequences.cjs +0 -112
- package/dist/createHotkeySequences.cjs.map +0 -1
- package/dist/createHotkeySequences.d.cts +0 -57
- package/dist/createHotkeySequences.js.map +0 -1
- package/dist/createHotkeys.cjs +0 -112
- package/dist/createHotkeys.cjs.map +0 -1
- package/dist/createHotkeys.d.cts +0 -57
- package/dist/createHotkeys.js.map +0 -1
- package/dist/createKeyHold.cjs +0 -56
- package/dist/createKeyHold.cjs.map +0 -1
- package/dist/createKeyHold.d.cts +0 -47
- package/dist/createKeyHold.js.map +0 -1
- package/dist/index.cjs +0 -35
- package/dist/index.d.cts +0 -14
- package/src/HotkeysProvider.tsx +0 -51
- package/src/createHeldKeyCodes.ts +0 -38
- package/src/createHeldKeys.ts +0 -29
- package/src/createHotkey.ts +0 -172
- package/src/createHotkeyHint.ts +0 -28
- package/src/createHotkeyRecorder.ts +0 -103
- package/src/createHotkeyRegistrations.ts +0 -45
- package/src/createHotkeySequence.ts +0 -155
- package/src/createHotkeySequenceRecorder.ts +0 -66
- package/src/createHotkeySequences.ts +0 -181
- package/src/createHotkeys.ts +0 -187
- package/src/createKeyHold.ts +0 -59
- package/src/index.ts +0 -18
package/dist/createHeldKeys.cjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
-
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
-
|
|
4
|
-
//#region src/createHeldKeys.ts
|
|
5
|
-
/**
|
|
6
|
-
* SolidJS primitive that returns a signal of currently held keyboard keys.
|
|
7
|
-
*
|
|
8
|
-
* This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe
|
|
9
|
-
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
|
-
* or released.
|
|
11
|
-
*
|
|
12
|
-
* @returns Signal accessor for array of currently held key names
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* function KeyDisplay() {
|
|
17
|
-
* const heldKeys = createHeldKeys()
|
|
18
|
-
*
|
|
19
|
-
* return (
|
|
20
|
-
* <div>
|
|
21
|
-
* Currently pressed: {heldKeys().join(' + ') || 'None'}
|
|
22
|
-
* </div>
|
|
23
|
-
* )
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
function createHeldKeys() {
|
|
28
|
-
return (0, _tanstack_solid_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
exports.createHeldKeys = createHeldKeys;
|
|
33
|
-
//# sourceMappingURL=createHeldKeys.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHeldKeys.cjs","names":[],"sources":["../src/createHeldKeys.ts"],"sourcesContent":["import { useSelector } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns a signal of currently held keyboard keys.\n *\n * This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker and updates whenever keys are pressed\n * or released.\n *\n * @returns Signal accessor for array of currently held key names\n *\n * @example\n * ```tsx\n * function KeyDisplay() {\n * const heldKeys = createHeldKeys()\n *\n * return (\n * <div>\n * Currently pressed: {heldKeys().join(' + ') || 'None'}\n * </div>\n * )\n * }\n * ```\n */\nexport function createHeldKeys(): () => Array<string> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,iBAAsC;AAEpD,0FADoC,CACT,QAAQ,UAAU,MAAM,SAAS"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
//#region src/createHeldKeys.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* SolidJS primitive that returns a signal of currently held keyboard keys.
|
|
4
|
-
*
|
|
5
|
-
* This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe
|
|
6
|
-
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
7
|
-
* or released.
|
|
8
|
-
*
|
|
9
|
-
* @returns Signal accessor for array of currently held key names
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* function KeyDisplay() {
|
|
14
|
-
* const heldKeys = createHeldKeys()
|
|
15
|
-
*
|
|
16
|
-
* return (
|
|
17
|
-
* <div>
|
|
18
|
-
* Currently pressed: {heldKeys().join(' + ') || 'None'}
|
|
19
|
-
* </div>
|
|
20
|
-
* )
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare function createHeldKeys(): () => Array<string>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { createHeldKeys };
|
|
27
|
-
//# sourceMappingURL=createHeldKeys.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHeldKeys.js","names":[],"sources":["../src/createHeldKeys.ts"],"sourcesContent":["import { useSelector } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns a signal of currently held keyboard keys.\n *\n * This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker and updates whenever keys are pressed\n * or released.\n *\n * @returns Signal accessor for array of currently held key names\n *\n * @example\n * ```tsx\n * function KeyDisplay() {\n * const heldKeys = createHeldKeys()\n *\n * return (\n * <div>\n * Currently pressed: {heldKeys().join(' + ') || 'None'}\n * </div>\n * )\n * }\n * ```\n */\nexport function createHeldKeys(): () => Array<string> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,iBAAsC;AAEpD,QAAO,YADS,oBAAoB,CACT,QAAQ,UAAU,MAAM,SAAS"}
|
package/dist/createHotkey.cjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let solid_js = require("solid-js");
|
|
4
|
-
|
|
5
|
-
//#region src/createHotkey.ts
|
|
6
|
-
/**
|
|
7
|
-
* SolidJS primitive for registering a keyboard hotkey.
|
|
8
|
-
*
|
|
9
|
-
* Uses the singleton HotkeyManager for efficient event handling.
|
|
10
|
-
* The callback receives both the keyboard event and a context object
|
|
11
|
-
* containing the hotkey string and parsed hotkey.
|
|
12
|
-
*
|
|
13
|
-
* This primitive automatically tracks reactive dependencies and updates
|
|
14
|
-
* the registration when options or the callback change.
|
|
15
|
-
*
|
|
16
|
-
* @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
|
|
17
|
-
* @param callback - The function to call when the hotkey is pressed
|
|
18
|
-
* @param options - Options for the hotkey behavior
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```tsx
|
|
22
|
-
* function SaveButton() {
|
|
23
|
-
* const [count, setCount] = createSignal(0)
|
|
24
|
-
*
|
|
25
|
-
* // Callback always has access to latest count value
|
|
26
|
-
* createHotkey('Mod+S', (event, { hotkey }) => {
|
|
27
|
-
* console.log(`Save triggered, count is ${count()}`)
|
|
28
|
-
* handleSave()
|
|
29
|
-
* })
|
|
30
|
-
*
|
|
31
|
-
* return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```tsx
|
|
37
|
-
* function Modal(props) {
|
|
38
|
-
* // enabled option is reactive
|
|
39
|
-
* createHotkey('Escape', () => {
|
|
40
|
-
* props.onClose()
|
|
41
|
-
* }, () => ({ enabled: props.isOpen }))
|
|
42
|
-
*
|
|
43
|
-
* return <Show when={props.isOpen}>
|
|
44
|
-
* <div class="modal">...</div>
|
|
45
|
-
* </Show>
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* function Editor() {
|
|
52
|
-
* const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)
|
|
53
|
-
*
|
|
54
|
-
* // Scoped to a specific element - use accessor so hotkey waits for ref
|
|
55
|
-
* createHotkey('Mod+S', save, () => ({ target: editorRef() }))
|
|
56
|
-
*
|
|
57
|
-
* return <div ref={setEditorRef}>...</div>
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
function createHotkey(hotkey, callback, options = {}) {
|
|
62
|
-
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
63
|
-
const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
|
|
64
|
-
let registration = null;
|
|
65
|
-
let lastHotkeyString = null;
|
|
66
|
-
let lastTarget = null;
|
|
67
|
-
(0, solid_js.onCleanup)(() => {
|
|
68
|
-
if (registration?.isActive) {
|
|
69
|
-
registration.unregister();
|
|
70
|
-
registration = null;
|
|
71
|
-
}
|
|
72
|
-
lastHotkeyString = null;
|
|
73
|
-
lastTarget = null;
|
|
74
|
-
});
|
|
75
|
-
(0, solid_js.createEffect)(() => {
|
|
76
|
-
const resolvedHotkey = typeof hotkey === "function" ? hotkey() : hotkey;
|
|
77
|
-
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
78
|
-
const mergedOptions = {
|
|
79
|
-
...defaultOptions.hotkey,
|
|
80
|
-
...resolvedOptions
|
|
81
|
-
};
|
|
82
|
-
const hotkeyString = (0, _tanstack_hotkeys.normalizeRegisterableHotkey)(resolvedHotkey, mergedOptions.platform ?? (0, _tanstack_hotkeys.detectPlatform)());
|
|
83
|
-
const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
|
|
84
|
-
if (!resolvedTarget) {
|
|
85
|
-
if (registration?.isActive) {
|
|
86
|
-
registration.unregister();
|
|
87
|
-
registration = null;
|
|
88
|
-
}
|
|
89
|
-
lastHotkeyString = null;
|
|
90
|
-
lastTarget = null;
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
94
|
-
(0, solid_js.untrack)(() => {
|
|
95
|
-
if (registration?.isActive && lastHotkeyString === hotkeyString && lastTarget === resolvedTarget) {
|
|
96
|
-
registration.callback = callback;
|
|
97
|
-
registration.setOptions(optionsWithoutTarget);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (registration?.isActive) {
|
|
101
|
-
registration.unregister();
|
|
102
|
-
registration = null;
|
|
103
|
-
}
|
|
104
|
-
registration = manager.register(hotkeyString, callback, {
|
|
105
|
-
...optionsWithoutTarget,
|
|
106
|
-
target: resolvedTarget
|
|
107
|
-
});
|
|
108
|
-
if (registration.isActive) {
|
|
109
|
-
registration.callback = callback;
|
|
110
|
-
registration.setOptions(optionsWithoutTarget);
|
|
111
|
-
}
|
|
112
|
-
lastHotkeyString = hotkeyString;
|
|
113
|
-
lastTarget = resolvedTarget;
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
exports.createHotkey = createHotkey;
|
|
120
|
-
//# sourceMappingURL=createHotkey.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkey.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor (for reactive targets that become\n * available after mount), or null. Defaults to document.\n * When using scoped targets, pass an accessor: () => ({ target: elementSignal() })\n * so the hotkey waits for the element to be attached before registering.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This primitive automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = createSignal(0)\n *\n * // Callback always has access to latest count value\n * createHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count()}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal(props) {\n * // enabled option is reactive\n * createHotkey('Escape', () => {\n * props.onClose()\n * }, () => ({ enabled: props.isOpen }))\n *\n * return <Show when={props.isOpen}>\n * <div class=\"modal\">...</div>\n * </Show>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element - use accessor so hotkey waits for ref\n * createHotkey('Mod+S', save, () => ({ target: editorRef() }))\n *\n * return <div ref={setEditorRef}>...</div>\n * }\n * ```\n */\nexport function createHotkey(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n callback: HotkeyCallback,\n options: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n let lastHotkeyString: Hotkey | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n })\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedHotkey = typeof hotkey === 'function' ? hotkey() : hotkey\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as CreateHotkeyOptions\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(resolvedHotkey, platform)\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches React's ref handling.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n return\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Untrack store mutations so that registering/updating the hotkey doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n if (\n registration?.isActive &&\n lastHotkeyString === hotkeyString &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastHotkeyString = hotkeyString\n lastTarget = resolvedTarget\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,mDAA4B;CAElC,IAAI,eAAgD;CACpD,IAAI,mBAAkC;CACtC,IAAI,aAAqD;AAEzD,+BAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,qBAAmB;AACnB,eAAa;GACb;AAEF,kCAAmB;EAEjB,MAAM,iBAAiB,OAAO,WAAW,aAAa,QAAQ,GAAG;EACjE,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAID,MAAM,kEAA2C,gBADhC,cAAc,mDAA4B,CACe;EAI1E,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,gBAAgB;AACnB,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,sBAAmB;AACnB,gBAAa;AACb;;EAIF,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAKrD,8BAAc;AACZ,OACE,cAAc,YACd,qBAAqB,gBACrB,eAAe,gBACf;AACA,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;AAC7C;;AAGF,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAGjB,kBAAe,QAAQ,SAAS,cAAc,UAAU;IACtD,GAAG;IACH,QAAQ;IACT,CAAC;AAEF,OAAI,aAAa,UAAU;AACzB,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;;AAG/C,sBAAmB;AACnB,gBAAa;IACb;GACF"}
|
package/dist/createHotkey.d.cts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { HotkeyCallback, HotkeyOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/createHotkey.d.ts
|
|
4
|
-
interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
5
|
-
/**
|
|
6
|
-
* The DOM element to attach the event listener to.
|
|
7
|
-
* Can be a direct DOM element, an accessor (for reactive targets that become
|
|
8
|
-
* available after mount), or null. Defaults to document.
|
|
9
|
-
* When using scoped targets, pass an accessor: () => ({ target: elementSignal() })
|
|
10
|
-
* so the hotkey waits for the element to be attached before registering.
|
|
11
|
-
*/
|
|
12
|
-
target?: HTMLElement | Document | Window | null;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* SolidJS primitive for registering a keyboard hotkey.
|
|
16
|
-
*
|
|
17
|
-
* Uses the singleton HotkeyManager for efficient event handling.
|
|
18
|
-
* The callback receives both the keyboard event and a context object
|
|
19
|
-
* containing the hotkey string and parsed hotkey.
|
|
20
|
-
*
|
|
21
|
-
* This primitive automatically tracks reactive dependencies and updates
|
|
22
|
-
* the registration when options or the callback change.
|
|
23
|
-
*
|
|
24
|
-
* @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
|
|
25
|
-
* @param callback - The function to call when the hotkey is pressed
|
|
26
|
-
* @param options - Options for the hotkey behavior
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* function SaveButton() {
|
|
31
|
-
* const [count, setCount] = createSignal(0)
|
|
32
|
-
*
|
|
33
|
-
* // Callback always has access to latest count value
|
|
34
|
-
* createHotkey('Mod+S', (event, { hotkey }) => {
|
|
35
|
-
* console.log(`Save triggered, count is ${count()}`)
|
|
36
|
-
* handleSave()
|
|
37
|
-
* })
|
|
38
|
-
*
|
|
39
|
-
* return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```tsx
|
|
45
|
-
* function Modal(props) {
|
|
46
|
-
* // enabled option is reactive
|
|
47
|
-
* createHotkey('Escape', () => {
|
|
48
|
-
* props.onClose()
|
|
49
|
-
* }, () => ({ enabled: props.isOpen }))
|
|
50
|
-
*
|
|
51
|
-
* return <Show when={props.isOpen}>
|
|
52
|
-
* <div class="modal">...</div>
|
|
53
|
-
* </Show>
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```tsx
|
|
59
|
-
* function Editor() {
|
|
60
|
-
* const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)
|
|
61
|
-
*
|
|
62
|
-
* // Scoped to a specific element - use accessor so hotkey waits for ref
|
|
63
|
-
* createHotkey('Mod+S', save, () => ({ target: editorRef() }))
|
|
64
|
-
*
|
|
65
|
-
* return <div ref={setEditorRef}>...</div>
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
declare function createHotkey(hotkey: RegisterableHotkey | (() => RegisterableHotkey), callback: HotkeyCallback, options?: CreateHotkeyOptions | (() => CreateHotkeyOptions)): void;
|
|
70
|
-
//#endregion
|
|
71
|
-
export { CreateHotkeyOptions, createHotkey };
|
|
72
|
-
//# sourceMappingURL=createHotkey.d.cts.map
|
package/dist/createHotkey.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkey.js","names":[],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor (for reactive targets that become\n * available after mount), or null. Defaults to document.\n * When using scoped targets, pass an accessor: () => ({ target: elementSignal() })\n * so the hotkey waits for the element to be attached before registering.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This primitive automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = createSignal(0)\n *\n * // Callback always has access to latest count value\n * createHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count()}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal(props) {\n * // enabled option is reactive\n * createHotkey('Escape', () => {\n * props.onClose()\n * }, () => ({ enabled: props.isOpen }))\n *\n * return <Show when={props.isOpen}>\n * <div class=\"modal\">...</div>\n * </Show>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element - use accessor so hotkey waits for ref\n * createHotkey('Mod+S', save, () => ({ target: editorRef() }))\n *\n * return <div ref={setEditorRef}>...</div>\n * }\n * ```\n */\nexport function createHotkey(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n callback: HotkeyCallback,\n options: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n let lastHotkeyString: Hotkey | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n })\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedHotkey = typeof hotkey === 'function' ? hotkey() : hotkey\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as CreateHotkeyOptions\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(resolvedHotkey, platform)\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches React's ref handling.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n return\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Untrack store mutations so that registering/updating the hotkey doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n if (\n registration?.isActive &&\n lastHotkeyString === hotkeyString &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastHotkeyString = hotkeyString\n lastTarget = resolvedTarget\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,kBAAkB;CAElC,IAAI,eAAgD;CACpD,IAAI,mBAAkC;CACtC,IAAI,aAAqD;AAEzD,iBAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,qBAAmB;AACnB,eAAa;GACb;AAEF,oBAAmB;EAEjB,MAAM,iBAAiB,OAAO,WAAW,aAAa,QAAQ,GAAG;EACjE,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAID,MAAM,eAAe,4BAA4B,gBADhC,cAAc,YAAY,gBAAgB,CACe;EAI1E,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,gBAAgB;AACnB,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,sBAAmB;AACnB,gBAAa;AACb;;EAIF,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAKrD,gBAAc;AACZ,OACE,cAAc,YACd,qBAAqB,gBACrB,eAAe,gBACf;AACA,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;AAC7C;;AAGF,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAGjB,kBAAe,QAAQ,SAAS,cAAc,UAAU;IACtD,GAAG;IACH,QAAQ;IACT,CAAC;AAEF,OAAI,aAAa,UAAU;AACzB,iBAAa,WAAW;AACxB,iBAAa,WAAW,qBAAqB;;AAG/C,sBAAmB;AACnB,gBAAa;IACb;GACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
-
let solid_js = require("solid-js");
|
|
3
|
-
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
4
|
-
|
|
5
|
-
//#region src/createHotkeyHint.ts
|
|
6
|
-
/**
|
|
7
|
-
* Returns a boolean accessor indicating whether held modifiers reveal this shortcut.
|
|
8
|
-
* Pass accessors to track changing bindings and options.
|
|
9
|
-
* Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
|
|
10
|
-
* every modifier. Combine with the action's enabled state before showing a badge.
|
|
11
|
-
* This helper does not register a shortcut or check whether its target is focused.
|
|
12
|
-
*/
|
|
13
|
-
function createHotkeyHint(hotkey, options = {}) {
|
|
14
|
-
const held = (0, _tanstack_solid_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
|
|
15
|
-
return (0, solid_js.createMemo)(() => (0, _tanstack_hotkeys.matchesHeldModifiers)(typeof hotkey === "function" ? hotkey() : hotkey, held(), typeof options === "function" ? options() : options));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.createHotkeyHint = createHotkeyHint;
|
|
20
|
-
//# sourceMappingURL=createHotkeyHint.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeyHint.cjs","names":[],"sources":["../src/createHotkeyHint.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useSelector } from '@tanstack/solid-store'\nimport { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'\nimport type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'\n\n/**\n * Returns a boolean accessor indicating whether held modifiers reveal this shortcut.\n * Pass accessors to track changing bindings and options.\n * Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires\n * every modifier. Combine with the action's enabled state before showing a badge.\n * This helper does not register a shortcut or check whether its target is focused.\n */\nexport function createHotkeyHint(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n options: HeldModifierOptions | (() => HeldModifierOptions) = {},\n): () => boolean {\n const held = useSelector(\n getKeyStateTracker().store,\n (state) => state.heldKeys,\n )\n return createMemo(() =>\n matchesHeldModifiers(\n typeof hotkey === 'function' ? hotkey() : hotkey,\n held(),\n typeof options === 'function' ? options() : options,\n ),\n )\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACd,QACA,UAA6D,EAAE,EAChD;CACf,MAAM,yFACgB,CAAC,QACpB,UAAU,MAAM,SAClB;AACD,mFAEI,OAAO,WAAW,aAAa,QAAQ,GAAG,QAC1C,MAAM,EACN,OAAO,YAAY,aAAa,SAAS,GAAG,QAC7C,CACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/createHotkeyHint.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Returns a boolean accessor indicating whether held modifiers reveal this shortcut.
|
|
6
|
-
* Pass accessors to track changing bindings and options.
|
|
7
|
-
* Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
|
|
8
|
-
* every modifier. Combine with the action's enabled state before showing a badge.
|
|
9
|
-
* This helper does not register a shortcut or check whether its target is focused.
|
|
10
|
-
*/
|
|
11
|
-
declare function createHotkeyHint(hotkey: RegisterableHotkey | (() => RegisterableHotkey), options?: HeldModifierOptions | (() => HeldModifierOptions)): () => boolean;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { createHotkeyHint };
|
|
14
|
-
//# sourceMappingURL=createHotkeyHint.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeyHint.js","names":[],"sources":["../src/createHotkeyHint.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useSelector } from '@tanstack/solid-store'\nimport { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'\nimport type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'\n\n/**\n * Returns a boolean accessor indicating whether held modifiers reveal this shortcut.\n * Pass accessors to track changing bindings and options.\n * Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires\n * every modifier. Combine with the action's enabled state before showing a badge.\n * This helper does not register a shortcut or check whether its target is focused.\n */\nexport function createHotkeyHint(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n options: HeldModifierOptions | (() => HeldModifierOptions) = {},\n): () => boolean {\n const held = useSelector(\n getKeyStateTracker().store,\n (state) => state.heldKeys,\n )\n return createMemo(() =>\n matchesHeldModifiers(\n typeof hotkey === 'function' ? hotkey() : hotkey,\n held(),\n typeof options === 'function' ? options() : options,\n ),\n )\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBACd,QACA,UAA6D,EAAE,EAChD;CACf,MAAM,OAAO,YACX,oBAAoB,CAAC,QACpB,UAAU,MAAM,SAClB;AACD,QAAO,iBACL,qBACE,OAAO,WAAW,aAAa,QAAQ,GAAG,QAC1C,MAAM,EACN,OAAO,YAAY,aAAa,SAAS,GAAG,QAC7C,CACF"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let solid_js = require("solid-js");
|
|
4
|
-
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
5
|
-
|
|
6
|
-
//#region src/createHotkeyRecorder.ts
|
|
7
|
-
/**
|
|
8
|
-
* SolidJS primitive for recording keyboard shortcuts.
|
|
9
|
-
*
|
|
10
|
-
* This primitive provides a thin wrapper around the framework-agnostic `HotkeyRecorder`
|
|
11
|
-
* class, managing all the complexity of capturing keyboard events, converting them
|
|
12
|
-
* to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete
|
|
13
|
-
* to clear.
|
|
14
|
-
*
|
|
15
|
-
* This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe
|
|
16
|
-
* to the recorder's store state (same pattern as useHotkeyRecorder in React).
|
|
17
|
-
*
|
|
18
|
-
* @param options - Configuration options for the recorder (or accessor function)
|
|
19
|
-
* @returns An object with recording state signals and control functions
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* function ShortcutSettings() {
|
|
24
|
-
* const [shortcut, setShortcut] = createSignal<Hotkey>('Mod+S')
|
|
25
|
-
*
|
|
26
|
-
* const recorder = createHotkeyRecorder({
|
|
27
|
-
* onRecord: (hotkey) => {
|
|
28
|
-
* setShortcut(hotkey)
|
|
29
|
-
* },
|
|
30
|
-
* onCancel: () => {
|
|
31
|
-
* console.log('Recording cancelled')
|
|
32
|
-
* },
|
|
33
|
-
* })
|
|
34
|
-
*
|
|
35
|
-
* return (
|
|
36
|
-
* <div>
|
|
37
|
-
* <button onClick={recorder.startRecording}>
|
|
38
|
-
* {recorder.isRecording() ? 'Recording...' : 'Edit Shortcut'}
|
|
39
|
-
* </button>
|
|
40
|
-
* <Show when={recorder.recordedHotkey()}>
|
|
41
|
-
* <div>Recording: {recorder.recordedHotkey()}</div>
|
|
42
|
-
* </Show>
|
|
43
|
-
* </div>
|
|
44
|
-
* )
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
function createHotkeyRecorder(options) {
|
|
49
|
-
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
50
|
-
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
51
|
-
const recorder = new _tanstack_hotkeys.HotkeyRecorder({
|
|
52
|
-
...defaultOptions.hotkeyRecorder,
|
|
53
|
-
...resolvedOptions
|
|
54
|
-
});
|
|
55
|
-
const isRecording = (0, _tanstack_solid_store.useSelector)(recorder.store, (state) => state.isRecording);
|
|
56
|
-
const recordedHotkey = (0, _tanstack_solid_store.useSelector)(recorder.store, (state) => state.recordedHotkey);
|
|
57
|
-
(0, solid_js.createEffect)(() => {
|
|
58
|
-
const resolved = typeof options === "function" ? options() : options;
|
|
59
|
-
recorder.setOptions({
|
|
60
|
-
...defaultOptions.hotkeyRecorder,
|
|
61
|
-
...resolved
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
(0, solid_js.onCleanup)(() => {
|
|
65
|
-
recorder.destroy();
|
|
66
|
-
});
|
|
67
|
-
return {
|
|
68
|
-
isRecording,
|
|
69
|
-
recordedHotkey,
|
|
70
|
-
startRecording: () => recorder.start(),
|
|
71
|
-
stopRecording: () => recorder.stop(),
|
|
72
|
-
cancelRecording: () => recorder.cancel()
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
exports.createHotkeyRecorder = createHotkeyRecorder;
|
|
78
|
-
//# sourceMappingURL=createHotkeyRecorder.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeyRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeyRecorder"],"sources":["../src/createHotkeyRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useSelector } from '@tanstack/solid-store'\nimport { HotkeyRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\nexport interface SolidHotkeyRecorder {\n /** Whether recording is currently active */\n isRecording: () => boolean\n /** The currently recorded hotkey (for live preview) */\n recordedHotkey: () => Hotkey | null\n /** Start recording a new hotkey */\n startRecording: () => void\n /** Stop recording (same as cancel) */\n stopRecording: () => void\n /** Cancel recording without saving */\n cancelRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording keyboard shortcuts.\n *\n * This primitive provides a thin wrapper around the framework-agnostic `HotkeyRecorder`\n * class, managing all the complexity of capturing keyboard events, converting them\n * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete\n * to clear.\n *\n * This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe\n * to the recorder's store state (same pattern as useHotkeyRecorder in React).\n *\n * @param options - Configuration options for the recorder (or accessor function)\n * @returns An object with recording state signals and control functions\n *\n * @example\n * ```tsx\n * function ShortcutSettings() {\n * const [shortcut, setShortcut] = createSignal<Hotkey>('Mod+S')\n *\n * const recorder = createHotkeyRecorder({\n * onRecord: (hotkey) => {\n * setShortcut(hotkey)\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * return (\n * <div>\n * <button onClick={recorder.startRecording}>\n * {recorder.isRecording() ? 'Recording...' : 'Edit Shortcut'}\n * </button>\n * <Show when={recorder.recordedHotkey()}>\n * <div>Recording: {recorder.recordedHotkey()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport function createHotkeyRecorder(\n options: HotkeyRecorderOptions | (() => HotkeyRecorderOptions),\n): SolidHotkeyRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeyRecorder,\n ...resolvedOptions,\n } as HotkeyRecorderOptions\n\n // Create recorder once synchronously (matches React's useRef pattern)\n const recorder = new HotkeyRecorder(mergedOptions)\n\n // Subscribe to recorder state using useSelector (same pattern as useHotkeyRecorder)\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const recordedHotkey = useSelector(\n recorder.store,\n (state) => state.recordedHotkey,\n )\n\n // Sync options on every effect run (matches React's sync on render)\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeyRecorder,\n ...resolved,\n } as HotkeyRecorderOptions)\n })\n\n // Cleanup on unmount\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n recordedHotkey,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,qBACd,SACqB;CACrB,MAAM,iBAAiBA,kDAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAOpE,MAAM,WAAW,IAAIC,iCANC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAGiD;CAGlD,MAAM,qDAA0B,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,wDACJ,SAAS,QACR,UAAU,MAAM,eAClB;AAGD,kCAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAA0B;GAC3B;AAGF,+BAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACzC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Hotkey, HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/createHotkeyRecorder.d.ts
|
|
4
|
-
interface SolidHotkeyRecorder {
|
|
5
|
-
/** Whether recording is currently active */
|
|
6
|
-
isRecording: () => boolean;
|
|
7
|
-
/** The currently recorded hotkey (for live preview) */
|
|
8
|
-
recordedHotkey: () => Hotkey | null;
|
|
9
|
-
/** Start recording a new hotkey */
|
|
10
|
-
startRecording: () => void;
|
|
11
|
-
/** Stop recording (same as cancel) */
|
|
12
|
-
stopRecording: () => void;
|
|
13
|
-
/** Cancel recording without saving */
|
|
14
|
-
cancelRecording: () => void;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* SolidJS primitive for recording keyboard shortcuts.
|
|
18
|
-
*
|
|
19
|
-
* This primitive provides a thin wrapper around the framework-agnostic `HotkeyRecorder`
|
|
20
|
-
* class, managing all the complexity of capturing keyboard events, converting them
|
|
21
|
-
* to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete
|
|
22
|
-
* to clear.
|
|
23
|
-
*
|
|
24
|
-
* This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe
|
|
25
|
-
* to the recorder's store state (same pattern as useHotkeyRecorder in React).
|
|
26
|
-
*
|
|
27
|
-
* @param options - Configuration options for the recorder (or accessor function)
|
|
28
|
-
* @returns An object with recording state signals and control functions
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* function ShortcutSettings() {
|
|
33
|
-
* const [shortcut, setShortcut] = createSignal<Hotkey>('Mod+S')
|
|
34
|
-
*
|
|
35
|
-
* const recorder = createHotkeyRecorder({
|
|
36
|
-
* onRecord: (hotkey) => {
|
|
37
|
-
* setShortcut(hotkey)
|
|
38
|
-
* },
|
|
39
|
-
* onCancel: () => {
|
|
40
|
-
* console.log('Recording cancelled')
|
|
41
|
-
* },
|
|
42
|
-
* })
|
|
43
|
-
*
|
|
44
|
-
* return (
|
|
45
|
-
* <div>
|
|
46
|
-
* <button onClick={recorder.startRecording}>
|
|
47
|
-
* {recorder.isRecording() ? 'Recording...' : 'Edit Shortcut'}
|
|
48
|
-
* </button>
|
|
49
|
-
* <Show when={recorder.recordedHotkey()}>
|
|
50
|
-
* <div>Recording: {recorder.recordedHotkey()}</div>
|
|
51
|
-
* </Show>
|
|
52
|
-
* </div>
|
|
53
|
-
* )
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
declare function createHotkeyRecorder(options: HotkeyRecorderOptions | (() => HotkeyRecorderOptions)): SolidHotkeyRecorder;
|
|
58
|
-
//#endregion
|
|
59
|
-
export { SolidHotkeyRecorder, createHotkeyRecorder };
|
|
60
|
-
//# sourceMappingURL=createHotkeyRecorder.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeyRecorder.js","names":[],"sources":["../src/createHotkeyRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useSelector } from '@tanstack/solid-store'\nimport { HotkeyRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\nexport interface SolidHotkeyRecorder {\n /** Whether recording is currently active */\n isRecording: () => boolean\n /** The currently recorded hotkey (for live preview) */\n recordedHotkey: () => Hotkey | null\n /** Start recording a new hotkey */\n startRecording: () => void\n /** Stop recording (same as cancel) */\n stopRecording: () => void\n /** Cancel recording without saving */\n cancelRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording keyboard shortcuts.\n *\n * This primitive provides a thin wrapper around the framework-agnostic `HotkeyRecorder`\n * class, managing all the complexity of capturing keyboard events, converting them\n * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete\n * to clear.\n *\n * This primitive uses `useSelector` from `@tanstack/solid-store` to subscribe\n * to the recorder's store state (same pattern as useHotkeyRecorder in React).\n *\n * @param options - Configuration options for the recorder (or accessor function)\n * @returns An object with recording state signals and control functions\n *\n * @example\n * ```tsx\n * function ShortcutSettings() {\n * const [shortcut, setShortcut] = createSignal<Hotkey>('Mod+S')\n *\n * const recorder = createHotkeyRecorder({\n * onRecord: (hotkey) => {\n * setShortcut(hotkey)\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * return (\n * <div>\n * <button onClick={recorder.startRecording}>\n * {recorder.isRecording() ? 'Recording...' : 'Edit Shortcut'}\n * </button>\n * <Show when={recorder.recordedHotkey()}>\n * <div>Recording: {recorder.recordedHotkey()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport function createHotkeyRecorder(\n options: HotkeyRecorderOptions | (() => HotkeyRecorderOptions),\n): SolidHotkeyRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeyRecorder,\n ...resolvedOptions,\n } as HotkeyRecorderOptions\n\n // Create recorder once synchronously (matches React's useRef pattern)\n const recorder = new HotkeyRecorder(mergedOptions)\n\n // Subscribe to recorder state using useSelector (same pattern as useHotkeyRecorder)\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const recordedHotkey = useSelector(\n recorder.store,\n (state) => state.recordedHotkey,\n )\n\n // Sync options on every effect run (matches React's sync on render)\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeyRecorder,\n ...resolved,\n } as HotkeyRecorderOptions)\n })\n\n // Cleanup on unmount\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n recordedHotkey,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,qBACd,SACqB;CACrB,MAAM,iBAAiB,0BAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAOpE,MAAM,WAAW,IAAI,eANC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAGiD;CAGlD,MAAM,cAAc,YAAY,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,iBAAiB,YACrB,SAAS,QACR,UAAU,MAAM,eAClB;AAGD,oBAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAA0B;GAC3B;AAGF,iBAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACzC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
-
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
-
|
|
4
|
-
//#region src/createHotkeyRegistrations.ts
|
|
5
|
-
/**
|
|
6
|
-
* Solid primitive that reactively reads all hotkey and sequence registrations
|
|
7
|
-
* from the singleton managers.
|
|
8
|
-
*
|
|
9
|
-
* This is a standalone primitive that does NOT require the HotkeysProvider.
|
|
10
|
-
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
11
|
-
* triggers reactivity when registrations change.
|
|
12
|
-
*
|
|
13
|
-
* @returns Object with `hotkeys` and `sequences` signal accessors
|
|
14
|
-
*/
|
|
15
|
-
function createHotkeyRegistrations() {
|
|
16
|
-
const hotkeyManager = (0, _tanstack_hotkeys.getHotkeyManager)();
|
|
17
|
-
const sequenceManager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
18
|
-
return {
|
|
19
|
-
hotkeys: (0, _tanstack_solid_store.useSelector)(hotkeyManager.registrations, (state) => Array.from(state.values()).map(_tanstack_hotkeys.toHotkeyRegistrationView)),
|
|
20
|
-
sequences: (0, _tanstack_solid_store.useSelector)(sequenceManager.registrations, (state) => Array.from(state.values()))
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
exports.createHotkeyRegistrations = createHotkeyRegistrations;
|
|
26
|
-
//# sourceMappingURL=createHotkeyRegistrations.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeyRegistrations.cjs","names":["toHotkeyRegistrationView"],"sources":["../src/createHotkeyRegistrations.ts"],"sourcesContent":["import { useSelector } from '@tanstack/solid-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\n\n/**\n * Return type for createHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** Accessor for all registered hotkeys (public view, no callbacks) */\n hotkeys: () => Array<HotkeyRegistrationView>\n /** Accessor for all registered sequences */\n sequences: () => Array<SequenceRegistrationView>\n}\n\n/**\n * Solid primitive that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone primitive that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * triggers reactivity when registrations change.\n *\n * @returns Object with `hotkeys` and `sequences` signal accessors\n */\nexport function createHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = useSelector(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = useSelector(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,4BAAuD;CACrE,MAAM,yDAAkC;CACxC,MAAM,6DAAsC;AAU5C,QAAO;EAAE,gDARmB,cAAc,gBAAgB,UACxD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAIA,2CAAyB,CACzD;EAMiB,kDAJY,gBAAgB,gBAAgB,UAC5D,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
|
-
//#region src/createHotkeyRegistrations.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Return type for createHotkeyRegistrations.
|
|
6
|
-
*/
|
|
7
|
-
interface HotkeyRegistrationsResult {
|
|
8
|
-
/** Accessor for all registered hotkeys (public view, no callbacks) */
|
|
9
|
-
hotkeys: () => Array<HotkeyRegistrationView>;
|
|
10
|
-
/** Accessor for all registered sequences */
|
|
11
|
-
sequences: () => Array<SequenceRegistrationView>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Solid primitive that reactively reads all hotkey and sequence registrations
|
|
15
|
-
* from the singleton managers.
|
|
16
|
-
*
|
|
17
|
-
* This is a standalone primitive that does NOT require the HotkeysProvider.
|
|
18
|
-
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
19
|
-
* triggers reactivity when registrations change.
|
|
20
|
-
*
|
|
21
|
-
* @returns Object with `hotkeys` and `sequences` signal accessors
|
|
22
|
-
*/
|
|
23
|
-
declare function createHotkeyRegistrations(): HotkeyRegistrationsResult;
|
|
24
|
-
//#endregion
|
|
25
|
-
export { HotkeyRegistrationsResult, createHotkeyRegistrations };
|
|
26
|
-
//# sourceMappingURL=createHotkeyRegistrations.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeyRegistrations.js","names":[],"sources":["../src/createHotkeyRegistrations.ts"],"sourcesContent":["import { useSelector } from '@tanstack/solid-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\n\n/**\n * Return type for createHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** Accessor for all registered hotkeys (public view, no callbacks) */\n hotkeys: () => Array<HotkeyRegistrationView>\n /** Accessor for all registered sequences */\n sequences: () => Array<SequenceRegistrationView>\n}\n\n/**\n * Solid primitive that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone primitive that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * triggers reactivity when registrations change.\n *\n * @returns Object with `hotkeys` and `sequences` signal accessors\n */\nexport function createHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = useSelector(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = useSelector(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,4BAAuD;CACrE,MAAM,gBAAgB,kBAAkB;CACxC,MAAM,kBAAkB,oBAAoB;AAU5C,QAAO;EAAE,SARO,YAAY,cAAc,gBAAgB,UACxD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAI,yBAAyB,CACzD;EAMiB,WAJA,YAAY,gBAAgB,gBAAgB,UAC5D,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
|