@tanstack/solid-hotkeys 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +305 -0
- package/dist/HotkeysProvider.cjs +27 -0
- package/dist/HotkeysProvider.cjs.map +1 -0
- package/dist/HotkeysProvider.d.cts +24 -0
- package/dist/HotkeysProvider.d.ts +24 -0
- package/dist/HotkeysProvider.js +25 -0
- package/dist/HotkeysProvider.js.map +1 -0
- package/dist/createHeldKeyCodes.cjs +42 -0
- package/dist/createHeldKeyCodes.cjs.map +1 -0
- package/dist/createHeldKeyCodes.d.cts +36 -0
- package/dist/createHeldKeyCodes.d.ts +36 -0
- package/dist/createHeldKeyCodes.js +42 -0
- package/dist/createHeldKeyCodes.js.map +1 -0
- package/dist/createHeldKeys.cjs +33 -0
- package/dist/createHeldKeys.cjs.map +1 -0
- package/dist/createHeldKeys.d.cts +27 -0
- package/dist/createHeldKeys.d.ts +27 -0
- package/dist/createHeldKeys.js +33 -0
- package/dist/createHeldKeys.js.map +1 -0
- package/dist/createHotkey.cjs +100 -0
- package/dist/createHotkey.cjs.map +1 -0
- package/dist/createHotkey.d.cts +72 -0
- package/dist/createHotkey.d.ts +72 -0
- package/dist/createHotkey.js +100 -0
- package/dist/createHotkey.js.map +1 -0
- package/dist/createHotkeyRecorder.cjs +78 -0
- package/dist/createHotkeyRecorder.cjs.map +1 -0
- package/dist/createHotkeyRecorder.d.cts +60 -0
- package/dist/createHotkeyRecorder.d.ts +60 -0
- package/dist/createHotkeyRecorder.js +78 -0
- package/dist/createHotkeyRecorder.js.map +1 -0
- package/dist/createHotkeySequence.cjs +58 -0
- package/dist/createHotkeySequence.cjs.map +1 -0
- package/dist/createHotkeySequence.d.cts +43 -0
- package/dist/createHotkeySequence.d.ts +43 -0
- package/dist/createHotkeySequence.js +58 -0
- package/dist/createHotkeySequence.js.map +1 -0
- package/dist/createKeyHold.cjs +56 -0
- package/dist/createKeyHold.cjs.map +1 -0
- package/dist/createKeyHold.d.cts +47 -0
- package/dist/createKeyHold.d.ts +47 -0
- package/dist/createKeyHold.js +56 -0
- package/dist/createKeyHold.js.map +1 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +11 -0
- package/package.json +67 -0
- package/src/HotkeysProvider.tsx +47 -0
- package/src/createHeldKeyCodes.ts +38 -0
- package/src/createHeldKeys.ts +29 -0
- package/src/createHotkey.ts +154 -0
- package/src/createHotkeyRecorder.ts +103 -0
- package/src/createHotkeySequence.ts +93 -0
- package/src/createKeyHold.ts +57 -0
- package/src/index.ts +13 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/createHeldKeys.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SolidJS primitive that returns a signal of currently held keyboard keys.
|
|
4
|
+
*
|
|
5
|
+
* This primitive uses `useStore` 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.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
+
import { useStore } from "@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 `useStore` 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 useStore(getKeyStateTracker().store, (state) => state.heldKeys);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createHeldKeys };
|
|
33
|
+
//# sourceMappingURL=createHeldKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHeldKeys.js","names":[],"sources":["../src/createHeldKeys.ts"],"sourcesContent":["import { useStore } 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 `useStore` 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 useStore(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,iBAAsC;AAEpD,QAAO,SADS,oBAAoB,CACZ,QAAQ,UAAU,MAAM,SAAS"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
(0, solid_js.createEffect)(() => {
|
|
66
|
+
const resolvedHotkey = typeof hotkey === "function" ? hotkey() : hotkey;
|
|
67
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
68
|
+
const mergedOptions = {
|
|
69
|
+
...defaultOptions.hotkey,
|
|
70
|
+
...resolvedOptions
|
|
71
|
+
};
|
|
72
|
+
const platform = mergedOptions.platform ?? (0, _tanstack_hotkeys.detectPlatform)();
|
|
73
|
+
const hotkeyString = typeof resolvedHotkey === "string" ? resolvedHotkey : (0, _tanstack_hotkeys.formatHotkey)((0, _tanstack_hotkeys.rawHotkeyToParsedHotkey)(resolvedHotkey, platform));
|
|
74
|
+
const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
|
|
75
|
+
if (!resolvedTarget) return;
|
|
76
|
+
if (registration?.isActive) {
|
|
77
|
+
registration.unregister();
|
|
78
|
+
registration = null;
|
|
79
|
+
}
|
|
80
|
+
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
81
|
+
registration = manager.register(hotkeyString, callback, {
|
|
82
|
+
...optionsWithoutTarget,
|
|
83
|
+
target: resolvedTarget
|
|
84
|
+
});
|
|
85
|
+
if (registration.isActive) {
|
|
86
|
+
registration.callback = callback;
|
|
87
|
+
registration.setOptions(optionsWithoutTarget);
|
|
88
|
+
}
|
|
89
|
+
(0, solid_js.onCleanup)(() => {
|
|
90
|
+
if (registration?.isActive) {
|
|
91
|
+
registration.unregister();
|
|
92
|
+
registration = null;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
exports.createHotkey = createHotkey;
|
|
100
|
+
//# sourceMappingURL=createHotkey.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkey.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\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\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: Hotkey =\n typeof resolvedHotkey === 'string'\n ? resolvedHotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(resolvedHotkey, platform),\n ) as Hotkey)\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 return\n }\n\n // Unregister previous registration if it exists\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Register the hotkey\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n // Update callback and options on every effect run\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n // Cleanup on disposal\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,mDAA4B;CAElC,IAAI,eAAgD;AAEpD,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;EAGD,MAAM,WAAW,cAAc,mDAA4B;EAC3D,MAAM,eACJ,OAAO,mBAAmB,WACtB,oGAE0B,gBAAgB,SAAS,CAClD;EAIP,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,eACH;AAIF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;EAIjB,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAGrD,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAGF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAI/C,gCAAgB;AACd,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;IAEjB;GACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
|
@@ -0,0 +1,72 @@
|
|
|
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.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
|
+
import { detectPlatform, formatHotkey, getHotkeyManager, rawHotkeyToParsedHotkey } from "@tanstack/hotkeys";
|
|
3
|
+
import { createEffect, onCleanup } from "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 = useDefaultHotkeysOptions();
|
|
63
|
+
const manager = getHotkeyManager();
|
|
64
|
+
let registration = null;
|
|
65
|
+
createEffect(() => {
|
|
66
|
+
const resolvedHotkey = typeof hotkey === "function" ? hotkey() : hotkey;
|
|
67
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
68
|
+
const mergedOptions = {
|
|
69
|
+
...defaultOptions.hotkey,
|
|
70
|
+
...resolvedOptions
|
|
71
|
+
};
|
|
72
|
+
const platform = mergedOptions.platform ?? detectPlatform();
|
|
73
|
+
const hotkeyString = typeof resolvedHotkey === "string" ? resolvedHotkey : formatHotkey(rawHotkeyToParsedHotkey(resolvedHotkey, platform));
|
|
74
|
+
const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
|
|
75
|
+
if (!resolvedTarget) return;
|
|
76
|
+
if (registration?.isActive) {
|
|
77
|
+
registration.unregister();
|
|
78
|
+
registration = null;
|
|
79
|
+
}
|
|
80
|
+
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
81
|
+
registration = manager.register(hotkeyString, callback, {
|
|
82
|
+
...optionsWithoutTarget,
|
|
83
|
+
target: resolvedTarget
|
|
84
|
+
});
|
|
85
|
+
if (registration.isActive) {
|
|
86
|
+
registration.callback = callback;
|
|
87
|
+
registration.setOptions(optionsWithoutTarget);
|
|
88
|
+
}
|
|
89
|
+
onCleanup(() => {
|
|
90
|
+
if (registration?.isActive) {
|
|
91
|
+
registration.unregister();
|
|
92
|
+
registration = null;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { createHotkey };
|
|
100
|
+
//# sourceMappingURL=createHotkey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkey.js","names":[],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\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\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: Hotkey =\n typeof resolvedHotkey === 'string'\n ? resolvedHotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(resolvedHotkey, platform),\n ) as Hotkey)\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 return\n }\n\n // Unregister previous registration if it exists\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Register the hotkey\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n // Update callback and options on every effect run\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n // Cleanup on disposal\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,kBAAkB;CAElC,IAAI,eAAgD;AAEpD,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;EAGD,MAAM,WAAW,cAAc,YAAY,gBAAgB;EAC3D,MAAM,eACJ,OAAO,mBAAmB,WACtB,iBACC,aACC,wBAAwB,gBAAgB,SAAS,CAClD;EAIP,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,eACH;AAIF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;EAIjB,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAGrD,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAGF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAI/C,kBAAgB;AACd,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;IAEjB;GACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 `useStore` 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.useStore)(recorder.store, (state) => state.isRecording);
|
|
56
|
+
const recordedHotkey = (0, _tanstack_solid_store.useStore)(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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeyRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeyRecorder"],"sources":["../src/createHotkeyRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useStore } 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 `useStore` 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 useStore (same pattern as useHotkeyRecorder)\n const isRecording = useStore(recorder.store, (state) => state.isRecording)\n const recordedHotkey = useStore(\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,kDAAuB,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC1E,MAAM,qDACJ,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"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 `useStore` 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
|
|
@@ -0,0 +1,60 @@
|
|
|
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 `useStore` 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.ts.map
|