@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,78 @@
|
|
|
1
|
+
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
|
+
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
3
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
4
|
+
import { useStore } from "@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 = useDefaultHotkeysOptions();
|
|
50
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
51
|
+
const recorder = new HotkeyRecorder({
|
|
52
|
+
...defaultOptions.hotkeyRecorder,
|
|
53
|
+
...resolvedOptions
|
|
54
|
+
});
|
|
55
|
+
const isRecording = useStore(recorder.store, (state) => state.isRecording);
|
|
56
|
+
const recordedHotkey = useStore(recorder.store, (state) => state.recordedHotkey);
|
|
57
|
+
createEffect(() => {
|
|
58
|
+
const resolved = typeof options === "function" ? options() : options;
|
|
59
|
+
recorder.setOptions({
|
|
60
|
+
...defaultOptions.hotkeyRecorder,
|
|
61
|
+
...resolved
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
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
|
+
export { createHotkeyRecorder };
|
|
78
|
+
//# sourceMappingURL=createHotkeyRecorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeyRecorder.js","names":[],"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,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,SAAS,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC1E,MAAM,iBAAiB,SACrB,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"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
2
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
+
let solid_js = require("solid-js");
|
|
4
|
+
|
|
5
|
+
//#region src/createHotkeySequence.ts
|
|
6
|
+
/**
|
|
7
|
+
* SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).
|
|
8
|
+
*
|
|
9
|
+
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
10
|
+
* that trigger when the full sequence is pressed within a timeout.
|
|
11
|
+
*
|
|
12
|
+
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
13
|
+
* @param callback - Function to call when the sequence is completed
|
|
14
|
+
* @param options - Options for the sequence behavior (or accessor function)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function VimEditor() {
|
|
19
|
+
* // 'g g' to go to top
|
|
20
|
+
* createHotkeySequence(['G', 'G'], () => {
|
|
21
|
+
* scrollToTop()
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // 'd d' to delete line
|
|
25
|
+
* createHotkeySequence(['D', 'D'], () => {
|
|
26
|
+
* deleteLine()
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* // 'd i w' to delete inner word
|
|
30
|
+
* createHotkeySequence(['D', 'I', 'W'], () => {
|
|
31
|
+
* deleteInnerWord()
|
|
32
|
+
* }, { timeout: 500 })
|
|
33
|
+
*
|
|
34
|
+
* return <div>...</div>
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function createHotkeySequence(sequence, callback, options = {}) {
|
|
39
|
+
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
40
|
+
(0, solid_js.createEffect)(() => {
|
|
41
|
+
const resolvedSequence = typeof sequence === "function" ? sequence() : sequence;
|
|
42
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
43
|
+
const { enabled = true, ...sequenceOptions } = {
|
|
44
|
+
...defaultOptions.hotkeySequence,
|
|
45
|
+
...resolvedOptions
|
|
46
|
+
};
|
|
47
|
+
if (!enabled || resolvedSequence.length === 0) return;
|
|
48
|
+
const manager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
49
|
+
const registerOptions = { enabled: true };
|
|
50
|
+
if (sequenceOptions.timeout !== void 0) registerOptions.timeout = sequenceOptions.timeout;
|
|
51
|
+
if (sequenceOptions.platform !== void 0) registerOptions.platform = sequenceOptions.platform;
|
|
52
|
+
(0, solid_js.onCleanup)(manager.register(resolvedSequence, callback, registerOptions));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.createHotkeySequence = createHotkeySequence;
|
|
58
|
+
//# sourceMappingURL=createHotkeySequence.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeySequence.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkeySequence.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceOptions,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'enabled'\n> {\n /** Whether the sequence is enabled. Defaults to true. */\n enabled?: boolean\n}\n\n/**\n * SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).\n *\n * This primitive allows you to register multi-key sequences like 'g g' or 'd d'\n * that trigger when the full sequence is pressed within a timeout.\n *\n * @param sequence - Array of hotkey strings that form the sequence (or accessor function)\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior (or accessor function)\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * createHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * createHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * createHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function createHotkeySequence(\n sequence: HotkeySequence | (() => HotkeySequence),\n callback: HotkeyCallback,\n options:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedSequence =\n typeof sequence === 'function' ? sequence() : sequence\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedOptions,\n } as CreateHotkeySequenceOptions\n\n const { enabled = true, ...sequenceOptions } = mergedOptions\n\n if (!enabled || resolvedSequence.length === 0) {\n return\n }\n\n const manager = getSequenceManager()\n\n // Build options object conditionally to avoid overwriting manager defaults with undefined\n const registerOptions: SequenceOptions = { enabled: true }\n if (sequenceOptions.timeout !== undefined)\n registerOptions.timeout = sequenceOptions.timeout\n if (sequenceOptions.platform !== undefined)\n registerOptions.platform = sequenceOptions.platform\n\n const unregister = manager.register(\n resolvedSequence,\n callback,\n registerOptions,\n )\n\n onCleanup(unregister)\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiBA,kDAA0B;AAEjD,kCAAmB;EAEjB,MAAM,mBACJ,OAAO,aAAa,aAAa,UAAU,GAAG;EAChD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAOpE,MAAM,EAAE,UAAU,MAAM,GAAG,oBALL;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;AAID,MAAI,CAAC,WAAW,iBAAiB,WAAW,EAC1C;EAGF,MAAM,qDAA8B;EAGpC,MAAM,kBAAmC,EAAE,SAAS,MAAM;AAC1D,MAAI,gBAAgB,YAAY,OAC9B,iBAAgB,UAAU,gBAAgB;AAC5C,MAAI,gBAAgB,aAAa,OAC/B,iBAAgB,WAAW,gBAAgB;AAQ7C,0BANmB,QAAQ,SACzB,kBACA,UACA,gBACD,CAEoB;GACrB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { HotkeyCallback, HotkeySequence, SequenceOptions } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createHotkeySequence.d.ts
|
|
4
|
+
interface CreateHotkeySequenceOptions extends Omit<SequenceOptions, 'enabled'> {
|
|
5
|
+
/** Whether the sequence is enabled. Defaults to true. */
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).
|
|
10
|
+
*
|
|
11
|
+
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
12
|
+
* that trigger when the full sequence is pressed within a timeout.
|
|
13
|
+
*
|
|
14
|
+
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
15
|
+
* @param callback - Function to call when the sequence is completed
|
|
16
|
+
* @param options - Options for the sequence behavior (or accessor function)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* function VimEditor() {
|
|
21
|
+
* // 'g g' to go to top
|
|
22
|
+
* createHotkeySequence(['G', 'G'], () => {
|
|
23
|
+
* scrollToTop()
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // 'd d' to delete line
|
|
27
|
+
* createHotkeySequence(['D', 'D'], () => {
|
|
28
|
+
* deleteLine()
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* // 'd i w' to delete inner word
|
|
32
|
+
* createHotkeySequence(['D', 'I', 'W'], () => {
|
|
33
|
+
* deleteInnerWord()
|
|
34
|
+
* }, { timeout: 500 })
|
|
35
|
+
*
|
|
36
|
+
* return <div>...</div>
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createHotkeySequence(sequence: HotkeySequence | (() => HotkeySequence), callback: HotkeyCallback, options?: CreateHotkeySequenceOptions | (() => CreateHotkeySequenceOptions)): void;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { CreateHotkeySequenceOptions, createHotkeySequence };
|
|
43
|
+
//# sourceMappingURL=createHotkeySequence.d.cts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { HotkeyCallback, HotkeySequence, SequenceOptions } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createHotkeySequence.d.ts
|
|
4
|
+
interface CreateHotkeySequenceOptions extends Omit<SequenceOptions, 'enabled'> {
|
|
5
|
+
/** Whether the sequence is enabled. Defaults to true. */
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).
|
|
10
|
+
*
|
|
11
|
+
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
12
|
+
* that trigger when the full sequence is pressed within a timeout.
|
|
13
|
+
*
|
|
14
|
+
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
15
|
+
* @param callback - Function to call when the sequence is completed
|
|
16
|
+
* @param options - Options for the sequence behavior (or accessor function)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* function VimEditor() {
|
|
21
|
+
* // 'g g' to go to top
|
|
22
|
+
* createHotkeySequence(['G', 'G'], () => {
|
|
23
|
+
* scrollToTop()
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // 'd d' to delete line
|
|
27
|
+
* createHotkeySequence(['D', 'D'], () => {
|
|
28
|
+
* deleteLine()
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* // 'd i w' to delete inner word
|
|
32
|
+
* createHotkeySequence(['D', 'I', 'W'], () => {
|
|
33
|
+
* deleteInnerWord()
|
|
34
|
+
* }, { timeout: 500 })
|
|
35
|
+
*
|
|
36
|
+
* return <div>...</div>
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createHotkeySequence(sequence: HotkeySequence | (() => HotkeySequence), callback: HotkeyCallback, options?: CreateHotkeySequenceOptions | (() => CreateHotkeySequenceOptions)): void;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { CreateHotkeySequenceOptions, createHotkeySequence };
|
|
43
|
+
//# sourceMappingURL=createHotkeySequence.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
|
+
import { getSequenceManager } from "@tanstack/hotkeys";
|
|
3
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
4
|
+
|
|
5
|
+
//#region src/createHotkeySequence.ts
|
|
6
|
+
/**
|
|
7
|
+
* SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).
|
|
8
|
+
*
|
|
9
|
+
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
10
|
+
* that trigger when the full sequence is pressed within a timeout.
|
|
11
|
+
*
|
|
12
|
+
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
13
|
+
* @param callback - Function to call when the sequence is completed
|
|
14
|
+
* @param options - Options for the sequence behavior (or accessor function)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function VimEditor() {
|
|
19
|
+
* // 'g g' to go to top
|
|
20
|
+
* createHotkeySequence(['G', 'G'], () => {
|
|
21
|
+
* scrollToTop()
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // 'd d' to delete line
|
|
25
|
+
* createHotkeySequence(['D', 'D'], () => {
|
|
26
|
+
* deleteLine()
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* // 'd i w' to delete inner word
|
|
30
|
+
* createHotkeySequence(['D', 'I', 'W'], () => {
|
|
31
|
+
* deleteInnerWord()
|
|
32
|
+
* }, { timeout: 500 })
|
|
33
|
+
*
|
|
34
|
+
* return <div>...</div>
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function createHotkeySequence(sequence, callback, options = {}) {
|
|
39
|
+
const defaultOptions = useDefaultHotkeysOptions();
|
|
40
|
+
createEffect(() => {
|
|
41
|
+
const resolvedSequence = typeof sequence === "function" ? sequence() : sequence;
|
|
42
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
43
|
+
const { enabled = true, ...sequenceOptions } = {
|
|
44
|
+
...defaultOptions.hotkeySequence,
|
|
45
|
+
...resolvedOptions
|
|
46
|
+
};
|
|
47
|
+
if (!enabled || resolvedSequence.length === 0) return;
|
|
48
|
+
const manager = getSequenceManager();
|
|
49
|
+
const registerOptions = { enabled: true };
|
|
50
|
+
if (sequenceOptions.timeout !== void 0) registerOptions.timeout = sequenceOptions.timeout;
|
|
51
|
+
if (sequenceOptions.platform !== void 0) registerOptions.platform = sequenceOptions.platform;
|
|
52
|
+
onCleanup(manager.register(resolvedSequence, callback, registerOptions));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { createHotkeySequence };
|
|
58
|
+
//# sourceMappingURL=createHotkeySequence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeySequence.js","names":[],"sources":["../src/createHotkeySequence.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceOptions,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'enabled'\n> {\n /** Whether the sequence is enabled. Defaults to true. */\n enabled?: boolean\n}\n\n/**\n * SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).\n *\n * This primitive allows you to register multi-key sequences like 'g g' or 'd d'\n * that trigger when the full sequence is pressed within a timeout.\n *\n * @param sequence - Array of hotkey strings that form the sequence (or accessor function)\n * @param callback - Function to call when the sequence is completed\n * @param options - Options for the sequence behavior (or accessor function)\n *\n * @example\n * ```tsx\n * function VimEditor() {\n * // 'g g' to go to top\n * createHotkeySequence(['G', 'G'], () => {\n * scrollToTop()\n * })\n *\n * // 'd d' to delete line\n * createHotkeySequence(['D', 'D'], () => {\n * deleteLine()\n * })\n *\n * // 'd i w' to delete inner word\n * createHotkeySequence(['D', 'I', 'W'], () => {\n * deleteInnerWord()\n * }, { timeout: 500 })\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function createHotkeySequence(\n sequence: HotkeySequence | (() => HotkeySequence),\n callback: HotkeyCallback,\n options:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedSequence =\n typeof sequence === 'function' ? sequence() : sequence\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedOptions,\n } as CreateHotkeySequenceOptions\n\n const { enabled = true, ...sequenceOptions } = mergedOptions\n\n if (!enabled || resolvedSequence.length === 0) {\n return\n }\n\n const manager = getSequenceManager()\n\n // Build options object conditionally to avoid overwriting manager defaults with undefined\n const registerOptions: SequenceOptions = { enabled: true }\n if (sequenceOptions.timeout !== undefined)\n registerOptions.timeout = sequenceOptions.timeout\n if (sequenceOptions.platform !== undefined)\n registerOptions.platform = sequenceOptions.platform\n\n const unregister = manager.register(\n resolvedSequence,\n callback,\n registerOptions,\n )\n\n onCleanup(unregister)\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiB,0BAA0B;AAEjD,oBAAmB;EAEjB,MAAM,mBACJ,OAAO,aAAa,aAAa,UAAU,GAAG;EAChD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAOpE,MAAM,EAAE,UAAU,MAAM,GAAG,oBALL;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;AAID,MAAI,CAAC,WAAW,iBAAiB,WAAW,EAC1C;EAGF,MAAM,UAAU,oBAAoB;EAGpC,MAAM,kBAAmC,EAAE,SAAS,MAAM;AAC1D,MAAI,gBAAgB,YAAY,OAC9B,iBAAgB,UAAU,gBAAgB;AAC5C,MAAI,gBAAgB,aAAa,OAC/B,iBAAgB,WAAW,gBAAgB;AAQ7C,YANmB,QAAQ,SACzB,kBACA,UACA,gBACD,CAEoB;GACrB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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/createKeyHold.ts
|
|
6
|
+
/**
|
|
7
|
+
* SolidJS primitive that returns whether a specific key is currently being held.
|
|
8
|
+
*
|
|
9
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
10
|
+
* to the global KeyStateTracker and uses a selector to determine if the
|
|
11
|
+
* specified key is held.
|
|
12
|
+
*
|
|
13
|
+
* @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function
|
|
14
|
+
* @returns Signal accessor that returns true if the key is currently held down
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function ShiftIndicator() {
|
|
19
|
+
* const isShiftHeld = createKeyHold('Shift')
|
|
20
|
+
*
|
|
21
|
+
* return (
|
|
22
|
+
* <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>
|
|
23
|
+
* {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}
|
|
24
|
+
* </div>
|
|
25
|
+
* )
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* function ModifierIndicators() {
|
|
32
|
+
* const ctrl = createKeyHold('Control')
|
|
33
|
+
* const shift = createKeyHold('Shift')
|
|
34
|
+
* const alt = createKeyHold('Alt')
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>
|
|
39
|
+
* <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>
|
|
40
|
+
* <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>
|
|
41
|
+
* </div>
|
|
42
|
+
* )
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function createKeyHold(key) {
|
|
47
|
+
const heldKeysSelector = (0, _tanstack_solid_store.useStore)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
|
|
48
|
+
return (0, solid_js.createMemo)(() => {
|
|
49
|
+
const normalizedKey = (typeof key === "function" ? key() : key).toLowerCase();
|
|
50
|
+
return heldKeysSelector().some((heldKey) => heldKey.toLowerCase() === normalizedKey);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
exports.createKeyHold = createKeyHold;
|
|
56
|
+
//# sourceMappingURL=createKeyHold.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createKeyHold.cjs","names":[],"sources":["../src/createKeyHold.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { HeldKey } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns whether a specific key is currently being held.\n *\n * This primitive uses `useStore` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if the\n * specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function\n * @returns Signal accessor that returns true if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = createKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>\n * {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = createKeyHold('Control')\n * const shift = createKeyHold('Shift')\n * const alt = createKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function createKeyHold(key: HeldKey | (() => HeldKey)): () => boolean {\n const tracker = getKeyStateTracker()\n const heldKeysSelector = useStore(tracker.store, (state) => state.heldKeys)\n\n return createMemo(() => {\n const resolvedKey = typeof key === 'function' ? key() : key\n const normalizedKey = resolvedKey.toLowerCase()\n return heldKeysSelector().some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,cAAc,KAA+C;CAE3E,MAAM,kGAD8B,CACM,QAAQ,UAAU,MAAM,SAAS;AAE3E,uCAAwB;EAEtB,MAAM,iBADc,OAAO,QAAQ,aAAa,KAAK,GAAG,KACtB,aAAa;AAC/C,SAAO,kBAAkB,CAAC,MACvB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { HeldKey } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createKeyHold.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* SolidJS primitive that returns whether a specific key is currently being held.
|
|
6
|
+
*
|
|
7
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
8
|
+
* to the global KeyStateTracker and uses a selector to determine if the
|
|
9
|
+
* specified key is held.
|
|
10
|
+
*
|
|
11
|
+
* @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function
|
|
12
|
+
* @returns Signal accessor that returns true if the key is currently held down
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function ShiftIndicator() {
|
|
17
|
+
* const isShiftHeld = createKeyHold('Shift')
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>
|
|
21
|
+
* {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}
|
|
22
|
+
* </div>
|
|
23
|
+
* )
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* function ModifierIndicators() {
|
|
30
|
+
* const ctrl = createKeyHold('Control')
|
|
31
|
+
* const shift = createKeyHold('Shift')
|
|
32
|
+
* const alt = createKeyHold('Alt')
|
|
33
|
+
*
|
|
34
|
+
* return (
|
|
35
|
+
* <div>
|
|
36
|
+
* <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>
|
|
37
|
+
* <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>
|
|
38
|
+
* <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>
|
|
39
|
+
* </div>
|
|
40
|
+
* )
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function createKeyHold(key: HeldKey | (() => HeldKey)): () => boolean;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { createKeyHold };
|
|
47
|
+
//# sourceMappingURL=createKeyHold.d.cts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { HeldKey } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createKeyHold.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* SolidJS primitive that returns whether a specific key is currently being held.
|
|
6
|
+
*
|
|
7
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
8
|
+
* to the global KeyStateTracker and uses a selector to determine if the
|
|
9
|
+
* specified key is held.
|
|
10
|
+
*
|
|
11
|
+
* @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function
|
|
12
|
+
* @returns Signal accessor that returns true if the key is currently held down
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function ShiftIndicator() {
|
|
17
|
+
* const isShiftHeld = createKeyHold('Shift')
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>
|
|
21
|
+
* {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}
|
|
22
|
+
* </div>
|
|
23
|
+
* )
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* function ModifierIndicators() {
|
|
30
|
+
* const ctrl = createKeyHold('Control')
|
|
31
|
+
* const shift = createKeyHold('Shift')
|
|
32
|
+
* const alt = createKeyHold('Alt')
|
|
33
|
+
*
|
|
34
|
+
* return (
|
|
35
|
+
* <div>
|
|
36
|
+
* <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>
|
|
37
|
+
* <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>
|
|
38
|
+
* <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>
|
|
39
|
+
* </div>
|
|
40
|
+
* )
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function createKeyHold(key: HeldKey | (() => HeldKey)): () => boolean;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { createKeyHold };
|
|
47
|
+
//# sourceMappingURL=createKeyHold.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
+
import { createMemo } from "solid-js";
|
|
3
|
+
import { useStore } from "@tanstack/solid-store";
|
|
4
|
+
|
|
5
|
+
//#region src/createKeyHold.ts
|
|
6
|
+
/**
|
|
7
|
+
* SolidJS primitive that returns whether a specific key is currently being held.
|
|
8
|
+
*
|
|
9
|
+
* This primitive uses `useStore` from `@tanstack/solid-store` to subscribe
|
|
10
|
+
* to the global KeyStateTracker and uses a selector to determine if the
|
|
11
|
+
* specified key is held.
|
|
12
|
+
*
|
|
13
|
+
* @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function
|
|
14
|
+
* @returns Signal accessor that returns true if the key is currently held down
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function ShiftIndicator() {
|
|
19
|
+
* const isShiftHeld = createKeyHold('Shift')
|
|
20
|
+
*
|
|
21
|
+
* return (
|
|
22
|
+
* <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>
|
|
23
|
+
* {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}
|
|
24
|
+
* </div>
|
|
25
|
+
* )
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* function ModifierIndicators() {
|
|
32
|
+
* const ctrl = createKeyHold('Control')
|
|
33
|
+
* const shift = createKeyHold('Shift')
|
|
34
|
+
* const alt = createKeyHold('Alt')
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>
|
|
39
|
+
* <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>
|
|
40
|
+
* <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>
|
|
41
|
+
* </div>
|
|
42
|
+
* )
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function createKeyHold(key) {
|
|
47
|
+
const heldKeysSelector = useStore(getKeyStateTracker().store, (state) => state.heldKeys);
|
|
48
|
+
return createMemo(() => {
|
|
49
|
+
const normalizedKey = (typeof key === "function" ? key() : key).toLowerCase();
|
|
50
|
+
return heldKeysSelector().some((heldKey) => heldKey.toLowerCase() === normalizedKey);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { createKeyHold };
|
|
56
|
+
//# sourceMappingURL=createKeyHold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createKeyHold.js","names":[],"sources":["../src/createKeyHold.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { HeldKey } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns whether a specific key is currently being held.\n *\n * This primitive uses `useStore` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if the\n * specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function\n * @returns Signal accessor that returns true if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = createKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>\n * {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = createKeyHold('Control')\n * const shift = createKeyHold('Shift')\n * const alt = createKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function createKeyHold(key: HeldKey | (() => HeldKey)): () => boolean {\n const tracker = getKeyStateTracker()\n const heldKeysSelector = useStore(tracker.store, (state) => state.heldKeys)\n\n return createMemo(() => {\n const resolvedKey = typeof key === 'function' ? key() : key\n const normalizedKey = resolvedKey.toLowerCase()\n return heldKeysSelector().some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,cAAc,KAA+C;CAE3E,MAAM,mBAAmB,SADT,oBAAoB,CACM,QAAQ,UAAU,MAAM,SAAS;AAE3E,QAAO,iBAAiB;EAEtB,MAAM,iBADc,OAAO,QAAQ,aAAa,KAAK,GAAG,KACtB,aAAa;AAC/C,SAAO,kBAAkB,CAAC,MACvB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
3
|
+
const require_createHotkey = require('./createHotkey.cjs');
|
|
4
|
+
const require_createHeldKeys = require('./createHeldKeys.cjs');
|
|
5
|
+
const require_createHeldKeyCodes = require('./createHeldKeyCodes.cjs');
|
|
6
|
+
const require_createKeyHold = require('./createKeyHold.cjs');
|
|
7
|
+
const require_createHotkeySequence = require('./createHotkeySequence.cjs');
|
|
8
|
+
const require_createHotkeyRecorder = require('./createHotkeyRecorder.cjs');
|
|
9
|
+
|
|
10
|
+
exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
|
|
11
|
+
exports.createHeldKeyCodes = require_createHeldKeyCodes.createHeldKeyCodes;
|
|
12
|
+
exports.createHeldKeys = require_createHeldKeys.createHeldKeys;
|
|
13
|
+
exports.createHotkey = require_createHotkey.createHotkey;
|
|
14
|
+
exports.createHotkeyRecorder = require_createHotkeyRecorder.createHotkeyRecorder;
|
|
15
|
+
exports.createHotkeySequence = require_createHotkeySequence.createHotkeySequence;
|
|
16
|
+
exports.createKeyHold = require_createKeyHold.createKeyHold;
|
|
17
|
+
exports.useDefaultHotkeysOptions = require_HotkeysProvider.useDefaultHotkeysOptions;
|
|
18
|
+
exports.useHotkeysContext = require_HotkeysProvider.useHotkeysContext;
|
|
19
|
+
var _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
20
|
+
Object.keys(_tanstack_hotkeys).forEach(function (k) {
|
|
21
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return _tanstack_hotkeys[k]; }
|
|
24
|
+
});
|
|
25
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CreateHotkeyOptions, createHotkey } from "./createHotkey.cjs";
|
|
2
|
+
import { CreateHotkeySequenceOptions, createHotkeySequence } from "./createHotkeySequence.cjs";
|
|
3
|
+
import { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.cjs";
|
|
4
|
+
import { createHeldKeys } from "./createHeldKeys.cjs";
|
|
5
|
+
import { createHeldKeyCodes } from "./createHeldKeyCodes.cjs";
|
|
6
|
+
import { createKeyHold } from "./createKeyHold.cjs";
|
|
7
|
+
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.cjs";
|
|
8
|
+
export * from "@tanstack/hotkeys";
|
|
9
|
+
export { CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CreateHotkeyOptions, createHotkey } from "./createHotkey.js";
|
|
2
|
+
import { CreateHotkeySequenceOptions, createHotkeySequence } from "./createHotkeySequence.js";
|
|
3
|
+
import { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.js";
|
|
4
|
+
import { createHeldKeys } from "./createHeldKeys.js";
|
|
5
|
+
import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
6
|
+
import { createKeyHold } from "./createKeyHold.js";
|
|
7
|
+
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
8
|
+
export * from "@tanstack/hotkeys";
|
|
9
|
+
export { CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HotkeysProvider, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
|
+
import { createHotkey } from "./createHotkey.js";
|
|
3
|
+
import { createHeldKeys } from "./createHeldKeys.js";
|
|
4
|
+
import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
5
|
+
import { createKeyHold } from "./createKeyHold.js";
|
|
6
|
+
import { createHotkeySequence } from "./createHotkeySequence.js";
|
|
7
|
+
import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
8
|
+
|
|
9
|
+
export * from "@tanstack/hotkeys"
|
|
10
|
+
|
|
11
|
+
export { HotkeysProvider, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|