@tanstack/solid-hotkeys 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/HotkeysProvider.cjs.map +1 -1
- package/dist/HotkeysProvider.d.cts +2 -1
- package/dist/HotkeysProvider.d.ts +2 -1
- package/dist/HotkeysProvider.js.map +1 -1
- package/dist/createHotkeySequence.cjs +10 -0
- package/dist/createHotkeySequence.cjs.map +1 -1
- package/dist/createHotkeySequence.d.cts +10 -0
- package/dist/createHotkeySequence.d.ts +10 -0
- package/dist/createHotkeySequence.js +10 -0
- package/dist/createHotkeySequence.js.map +1 -1
- package/dist/createHotkeySequenceRecorder.cjs +43 -0
- package/dist/createHotkeySequenceRecorder.cjs.map +1 -0
- package/dist/createHotkeySequenceRecorder.d.cts +19 -0
- package/dist/createHotkeySequenceRecorder.d.ts +19 -0
- package/dist/createHotkeySequenceRecorder.js +43 -0
- package/dist/createHotkeySequenceRecorder.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +2 -2
- package/src/HotkeysProvider.tsx +5 -1
- package/src/createHotkeySequence.ts +10 -0
- package/src/createHotkeySequenceRecorder.ts +66 -0
- package/src/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HotkeysProvider.cjs","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"HotkeysProvider.cjs","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","HotkeySequenceRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequenceRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {\n HotkeyRecorderOptions,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<CreateHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>\n hotkeySequence?: Partial<CreateHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: JSX.Element\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport const HotkeysProvider: ParentComponent<HotkeysProviderProps> = (\n props,\n) => {\n const contextValue: HotkeysContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <HotkeysContext.Provider value={contextValue}>\n {props.children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAoBA,MAAMgB,6CAA2D,KAAK;AAOtE,MAAMI,kBAA0C,EAAE;AAElD,MAAaC,mBACXC,UACG;CACH,MAAMC,eAAoC,EACxCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;AAED,0CACGJ,eAAeS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;AAAA,UACzCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,oBAAoB;AAClC,iCAAkBX,eAAe;;AAGnC,SAAgBY,2BAA2B;AAEzC,iCAD2BZ,eAAe,EAC1BD,kBAAkB,EAAE"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CreateHotkeyOptions } from "./createHotkey.cjs";
|
|
2
2
|
import { CreateHotkeySequenceOptions } from "./createHotkeySequence.cjs";
|
|
3
|
-
import { HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
3
|
+
import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
4
4
|
import { JSX, ParentComponent } from "solid-js";
|
|
5
5
|
|
|
6
6
|
//#region src/HotkeysProvider.d.ts
|
|
7
7
|
interface HotkeysProviderOptions {
|
|
8
8
|
hotkey?: Partial<CreateHotkeyOptions>;
|
|
9
9
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
|
+
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
|
|
10
11
|
hotkeySequence?: Partial<CreateHotkeySequenceOptions>;
|
|
11
12
|
}
|
|
12
13
|
interface HotkeysContextValue {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CreateHotkeyOptions } from "./createHotkey.js";
|
|
2
2
|
import { CreateHotkeySequenceOptions } from "./createHotkeySequence.js";
|
|
3
|
-
import { HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
3
|
+
import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
4
4
|
import { JSX, ParentComponent } from "solid-js";
|
|
5
5
|
|
|
6
6
|
//#region src/HotkeysProvider.d.ts
|
|
7
7
|
interface HotkeysProviderOptions {
|
|
8
8
|
hotkey?: Partial<CreateHotkeyOptions>;
|
|
9
9
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
|
+
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
|
|
10
11
|
hotkeySequence?: Partial<CreateHotkeySequenceOptions>;
|
|
11
12
|
}
|
|
12
13
|
interface HotkeysContextValue {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HotkeysProvider.js","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"HotkeysProvider.js","names":["createContext","useContext","JSX","ParentComponent","HotkeyRecorderOptions","HotkeySequenceRecorderOptions","CreateHotkeyOptions","CreateHotkeySequenceOptions","HotkeysProviderOptions","hotkey","Partial","hotkeyRecorder","hotkeySequenceRecorder","hotkeySequence","HotkeysContextValue","defaultOptions","HotkeysContext","HotkeysProviderProps","children","Element","DEFAULT_OPTIONS","HotkeysProvider","props","contextValue","_$createComponent","Provider","value","useHotkeysContext","useDefaultHotkeysOptions","context"],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentComponent } from 'solid-js'\nimport type {\n HotkeyRecorderOptions,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<CreateHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>\n hotkeySequence?: Partial<CreateHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: JSX.Element\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport const HotkeysProvider: ParentComponent<HotkeysProviderProps> = (\n props,\n) => {\n const contextValue: HotkeysContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <HotkeysContext.Provider value={contextValue}>\n {props.children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAoBA,MAAMgB,iBAAiBhB,cAA0C,KAAK;AAOtE,MAAMoB,kBAA0C,EAAE;AAElD,MAAaC,mBACXC,UACG;CACH,MAAMC,eAAoC,EACxCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;AAED,QAAAI,gBACGR,eAAeS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;AAAA,UACzCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,oBAAoB;AAClC,QAAO1B,WAAWe,eAAe;;AAGnC,SAAgBY,2BAA2B;AAEzC,QADgB3B,WAAWe,eAAe,EAC1BD,kBAAkB,EAAE"}
|
|
@@ -9,6 +9,11 @@ let solid_js = require("solid-js");
|
|
|
9
9
|
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
10
10
|
* that trigger when the full sequence is pressed within a timeout.
|
|
11
11
|
*
|
|
12
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
13
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
14
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
15
|
+
* advance the sequence or reset progress.
|
|
16
|
+
*
|
|
12
17
|
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
13
18
|
* @param callback - Function to call when the sequence is completed
|
|
14
19
|
* @param options - Options for the sequence behavior (or accessor function)
|
|
@@ -31,6 +36,11 @@ let solid_js = require("solid-js");
|
|
|
31
36
|
* deleteInnerWord()
|
|
32
37
|
* }, { timeout: 500 })
|
|
33
38
|
*
|
|
39
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
40
|
+
* createHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
41
|
+
* nextAction()
|
|
42
|
+
* })
|
|
43
|
+
*
|
|
34
44
|
* return <div>...</div>
|
|
35
45
|
* }
|
|
36
46
|
* ```
|
|
@@ -1 +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 SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor, or null. Defaults to document.\n */\n target?: HTMLElement | Document | Window | null\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 const manager = getSequenceManager()\n\n let registration: SequenceRegistrationHandle | null = null\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 // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n if (resolvedSequence.length === 0) {\n return\n }\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches createHotkey.\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 // Register the sequence\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n // Sync 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":"
|
|
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 SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor, or null. Defaults to document.\n */\n target?: HTMLElement | Document | Window | null\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 * Each step may include modifiers. You can chain the same modifier across\n * steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,\n * Control, Alt, or Meta pressed alone) are ignored while matching—they do not\n * advance the sequence or reset progress.\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 * // Same modifier on consecutive steps (bare Shift between chords is ignored)\n * createHotkeySequence(['Shift+R', 'Shift+T'], () => {\n * nextAction()\n * })\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 const manager = getSequenceManager()\n\n let registration: SequenceRegistrationHandle | null = null\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 // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n if (resolvedSequence.length === 0) {\n return\n }\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches createHotkey.\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 // Register the sequence\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n // Sync 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,qDAA8B;CAEpC,IAAI,eAAkD;AAEtD,kCAAmB;EAEjB,MAAM,mBACJ,OAAO,aAAa,aAAa,UAAU,GAAG;EAChD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,MAAI,iBAAiB,WAAW,EAC9B;EAKF,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,eACH;AAIF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAIjB,iBAAe,QAAQ,SAAS,kBAAkB,UAAU;GAC1D,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"}
|
|
@@ -14,6 +14,11 @@ interface CreateHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
14
14
|
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
15
15
|
* that trigger when the full sequence is pressed within a timeout.
|
|
16
16
|
*
|
|
17
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
18
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
19
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
20
|
+
* advance the sequence or reset progress.
|
|
21
|
+
*
|
|
17
22
|
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
18
23
|
* @param callback - Function to call when the sequence is completed
|
|
19
24
|
* @param options - Options for the sequence behavior (or accessor function)
|
|
@@ -36,6 +41,11 @@ interface CreateHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
36
41
|
* deleteInnerWord()
|
|
37
42
|
* }, { timeout: 500 })
|
|
38
43
|
*
|
|
44
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
45
|
+
* createHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
46
|
+
* nextAction()
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
39
49
|
* return <div>...</div>
|
|
40
50
|
* }
|
|
41
51
|
* ```
|
|
@@ -14,6 +14,11 @@ interface CreateHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
14
14
|
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
15
15
|
* that trigger when the full sequence is pressed within a timeout.
|
|
16
16
|
*
|
|
17
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
18
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
19
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
20
|
+
* advance the sequence or reset progress.
|
|
21
|
+
*
|
|
17
22
|
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
18
23
|
* @param callback - Function to call when the sequence is completed
|
|
19
24
|
* @param options - Options for the sequence behavior (or accessor function)
|
|
@@ -36,6 +41,11 @@ interface CreateHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
36
41
|
* deleteInnerWord()
|
|
37
42
|
* }, { timeout: 500 })
|
|
38
43
|
*
|
|
44
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
45
|
+
* createHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
46
|
+
* nextAction()
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
39
49
|
* return <div>...</div>
|
|
40
50
|
* }
|
|
41
51
|
* ```
|
|
@@ -9,6 +9,11 @@ import { createEffect, onCleanup } from "solid-js";
|
|
|
9
9
|
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
10
10
|
* that trigger when the full sequence is pressed within a timeout.
|
|
11
11
|
*
|
|
12
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
13
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
14
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
15
|
+
* advance the sequence or reset progress.
|
|
16
|
+
*
|
|
12
17
|
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
13
18
|
* @param callback - Function to call when the sequence is completed
|
|
14
19
|
* @param options - Options for the sequence behavior (or accessor function)
|
|
@@ -31,6 +36,11 @@ import { createEffect, onCleanup } from "solid-js";
|
|
|
31
36
|
* deleteInnerWord()
|
|
32
37
|
* }, { timeout: 500 })
|
|
33
38
|
*
|
|
39
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
40
|
+
* createHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
41
|
+
* nextAction()
|
|
42
|
+
* })
|
|
43
|
+
*
|
|
34
44
|
* return <div>...</div>
|
|
35
45
|
* }
|
|
36
46
|
* ```
|
|
@@ -1 +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 SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor, or null. Defaults to document.\n */\n target?: HTMLElement | Document | Window | null\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 const manager = getSequenceManager()\n\n let registration: SequenceRegistrationHandle | null = null\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 // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n if (resolvedSequence.length === 0) {\n return\n }\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches createHotkey.\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 // Register the sequence\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n // Sync 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":"
|
|
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 SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeySequenceOptions extends Omit<\n SequenceOptions,\n 'target'\n> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor, or null. Defaults to document.\n */\n target?: HTMLElement | Document | Window | null\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 * Each step may include modifiers. You can chain the same modifier across\n * steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,\n * Control, Alt, or Meta pressed alone) are ignored while matching—they do not\n * advance the sequence or reset progress.\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 * // Same modifier on consecutive steps (bare Shift between chords is ignored)\n * createHotkeySequence(['Shift+R', 'Shift+T'], () => {\n * nextAction()\n * })\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 const manager = getSequenceManager()\n\n let registration: SequenceRegistrationHandle | null = null\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 // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n if (resolvedSequence.length === 0) {\n return\n }\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches createHotkey.\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 // Register the sequence\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n // Sync 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,oBAAoB;CAEpC,IAAI,eAAkD;AAEtD,oBAAmB;EAEjB,MAAM,mBACJ,OAAO,aAAa,aAAa,UAAU,GAAG;EAChD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,MAAI,iBAAiB,WAAW,EAC9B;EAKF,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,eACH;AAIF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAIjB,iBAAe,QAAQ,SAAS,kBAAkB,UAAU;GAC1D,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,43 @@
|
|
|
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/createHotkeySequenceRecorder.ts
|
|
7
|
+
/**
|
|
8
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
9
|
+
*/
|
|
10
|
+
function createHotkeySequenceRecorder(options) {
|
|
11
|
+
const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
|
|
12
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
13
|
+
const recorder = new _tanstack_hotkeys.HotkeySequenceRecorder({
|
|
14
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
15
|
+
...resolvedOptions
|
|
16
|
+
});
|
|
17
|
+
const isRecording = (0, _tanstack_solid_store.useStore)(recorder.store, (state) => state.isRecording);
|
|
18
|
+
const steps = (0, _tanstack_solid_store.useStore)(recorder.store, (state) => state.steps);
|
|
19
|
+
const recordedSequence = (0, _tanstack_solid_store.useStore)(recorder.store, (state) => state.recordedSequence);
|
|
20
|
+
(0, solid_js.createEffect)(() => {
|
|
21
|
+
const resolved = typeof options === "function" ? options() : options;
|
|
22
|
+
recorder.setOptions({
|
|
23
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
24
|
+
...resolved
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
(0, solid_js.onCleanup)(() => {
|
|
28
|
+
recorder.destroy();
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
isRecording,
|
|
32
|
+
steps,
|
|
33
|
+
recordedSequence,
|
|
34
|
+
startRecording: () => recorder.start(),
|
|
35
|
+
stopRecording: () => recorder.stop(),
|
|
36
|
+
cancelRecording: () => recorder.cancel(),
|
|
37
|
+
commitRecording: () => recorder.commit()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.createHotkeySequenceRecorder = createHotkeySequenceRecorder;
|
|
43
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeySequenceRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeySequenceRecorder"],"sources":["../src/createHotkeySequenceRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface SolidHotkeySequenceRecorder {\n isRecording: () => boolean\n steps: () => HotkeySequence\n recordedSequence: () => HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function createHotkeySequenceRecorder(\n options:\n | HotkeySequenceRecorderOptions\n | (() => HotkeySequenceRecorderOptions),\n): SolidHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolvedOptions,\n } as HotkeySequenceRecorderOptions\n\n const recorder = new HotkeySequenceRecorder(mergedOptions)\n\n const isRecording = useStore(recorder.store, (state) => state.isRecording)\n const steps = useStore(recorder.store, (state) => state.steps)\n const recordedSequence = useStore(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolved,\n } as HotkeySequenceRecorderOptions)\n })\n\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,6BACd,SAG6B;CAC7B,MAAM,iBAAiBA,kDAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAMpE,MAAM,WAAW,IAAIC,yCALC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAEyD;CAE1D,MAAM,kDAAuB,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC1E,MAAM,4CAAiB,SAAS,QAAQ,UAAU,MAAM,MAAM;CAC9D,MAAM,uDACJ,SAAS,QACR,UAAU,MAAM,iBAClB;AAED,kCAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAAkC;GACnC;AAEF,+BAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createHotkeySequenceRecorder.d.ts
|
|
4
|
+
interface SolidHotkeySequenceRecorder {
|
|
5
|
+
isRecording: () => boolean;
|
|
6
|
+
steps: () => HotkeySequence;
|
|
7
|
+
recordedSequence: () => HotkeySequence | null;
|
|
8
|
+
startRecording: () => void;
|
|
9
|
+
stopRecording: () => void;
|
|
10
|
+
cancelRecording: () => void;
|
|
11
|
+
commitRecording: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
15
|
+
*/
|
|
16
|
+
declare function createHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions | (() => HotkeySequenceRecorderOptions)): SolidHotkeySequenceRecorder;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder };
|
|
19
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.d.cts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/createHotkeySequenceRecorder.d.ts
|
|
4
|
+
interface SolidHotkeySequenceRecorder {
|
|
5
|
+
isRecording: () => boolean;
|
|
6
|
+
steps: () => HotkeySequence;
|
|
7
|
+
recordedSequence: () => HotkeySequence | null;
|
|
8
|
+
startRecording: () => void;
|
|
9
|
+
stopRecording: () => void;
|
|
10
|
+
cancelRecording: () => void;
|
|
11
|
+
commitRecording: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
15
|
+
*/
|
|
16
|
+
declare function createHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions | (() => HotkeySequenceRecorderOptions)): SolidHotkeySequenceRecorder;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder };
|
|
19
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
|
+
import { HotkeySequenceRecorder } from "@tanstack/hotkeys";
|
|
3
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
4
|
+
import { useStore } from "@tanstack/solid-store";
|
|
5
|
+
|
|
6
|
+
//#region src/createHotkeySequenceRecorder.ts
|
|
7
|
+
/**
|
|
8
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
9
|
+
*/
|
|
10
|
+
function createHotkeySequenceRecorder(options) {
|
|
11
|
+
const defaultOptions = useDefaultHotkeysOptions();
|
|
12
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
13
|
+
const recorder = new HotkeySequenceRecorder({
|
|
14
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
15
|
+
...resolvedOptions
|
|
16
|
+
});
|
|
17
|
+
const isRecording = useStore(recorder.store, (state) => state.isRecording);
|
|
18
|
+
const steps = useStore(recorder.store, (state) => state.steps);
|
|
19
|
+
const recordedSequence = useStore(recorder.store, (state) => state.recordedSequence);
|
|
20
|
+
createEffect(() => {
|
|
21
|
+
const resolved = typeof options === "function" ? options() : options;
|
|
22
|
+
recorder.setOptions({
|
|
23
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
24
|
+
...resolved
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
onCleanup(() => {
|
|
28
|
+
recorder.destroy();
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
isRecording,
|
|
32
|
+
steps,
|
|
33
|
+
recordedSequence,
|
|
34
|
+
startRecording: () => recorder.start(),
|
|
35
|
+
stopRecording: () => recorder.stop(),
|
|
36
|
+
cancelRecording: () => recorder.cancel(),
|
|
37
|
+
commitRecording: () => recorder.commit()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createHotkeySequenceRecorder };
|
|
43
|
+
//# sourceMappingURL=createHotkeySequenceRecorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHotkeySequenceRecorder.js","names":[],"sources":["../src/createHotkeySequenceRecorder.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface SolidHotkeySequenceRecorder {\n isRecording: () => boolean\n steps: () => HotkeySequence\n recordedSequence: () => HotkeySequence | null\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function createHotkeySequenceRecorder(\n options:\n | HotkeySequenceRecorderOptions\n | (() => HotkeySequenceRecorderOptions),\n): SolidHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n\n const resolvedOptions = typeof options === 'function' ? options() : options\n const mergedOptions = {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolvedOptions,\n } as HotkeySequenceRecorderOptions\n\n const recorder = new HotkeySequenceRecorder(mergedOptions)\n\n const isRecording = useStore(recorder.store, (state) => state.isRecording)\n const steps = useStore(recorder.store, (state) => state.steps)\n const recordedSequence = useStore(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n createEffect(() => {\n const resolved = typeof options === 'function' ? options() : options\n recorder.setOptions({\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolved,\n } as HotkeySequenceRecorderOptions)\n })\n\n onCleanup(() => {\n recorder.destroy()\n })\n\n return {\n isRecording,\n steps,\n recordedSequence,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,6BACd,SAG6B;CAC7B,MAAM,iBAAiB,0BAA0B;CAEjD,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;CAMpE,MAAM,WAAW,IAAI,uBALC;EACpB,GAAG,eAAe;EAClB,GAAG;EACJ,CAEyD;CAE1D,MAAM,cAAc,SAAS,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC1E,MAAM,QAAQ,SAAS,SAAS,QAAQ,UAAU,MAAM,MAAM;CAC9D,MAAM,mBAAmB,SACvB,SAAS,QACR,UAAU,MAAM,iBAClB;AAED,oBAAmB;EACjB,MAAM,WAAW,OAAO,YAAY,aAAa,SAAS,GAAG;AAC7D,WAAS,WAAW;GAClB,GAAG,eAAe;GAClB,GAAG;GACJ,CAAkC;GACnC;AAEF,iBAAgB;AACd,WAAS,SAAS;GAClB;AAEF,QAAO;EACL;EACA;EACA;EACA,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC"}
|
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ const require_createHeldKeyCodes = require('./createHeldKeyCodes.cjs');
|
|
|
7
7
|
const require_createKeyHold = require('./createKeyHold.cjs');
|
|
8
8
|
const require_createHotkeySequence = require('./createHotkeySequence.cjs');
|
|
9
9
|
const require_createHotkeyRecorder = require('./createHotkeyRecorder.cjs');
|
|
10
|
+
const require_createHotkeySequenceRecorder = require('./createHotkeySequenceRecorder.cjs');
|
|
10
11
|
|
|
11
12
|
exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
|
|
12
13
|
exports.createHeldKeyCodes = require_createHeldKeyCodes.createHeldKeyCodes;
|
|
@@ -14,6 +15,7 @@ exports.createHeldKeys = require_createHeldKeys.createHeldKeys;
|
|
|
14
15
|
exports.createHotkey = require_createHotkey.createHotkey;
|
|
15
16
|
exports.createHotkeyRecorder = require_createHotkeyRecorder.createHotkeyRecorder;
|
|
16
17
|
exports.createHotkeySequence = require_createHotkeySequence.createHotkeySequence;
|
|
18
|
+
exports.createHotkeySequenceRecorder = require_createHotkeySequenceRecorder.createHotkeySequenceRecorder;
|
|
17
19
|
exports.createHotkeys = require_createHotkeys.createHotkeys;
|
|
18
20
|
exports.createKeyHold = require_createKeyHold.createKeyHold;
|
|
19
21
|
exports.useDefaultHotkeysOptions = require_HotkeysProvider.useDefaultHotkeysOptions;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,5 +6,6 @@ import { createHeldKeys } from "./createHeldKeys.cjs";
|
|
|
6
6
|
import { createHeldKeyCodes } from "./createHeldKeyCodes.cjs";
|
|
7
7
|
import { createKeyHold } from "./createKeyHold.cjs";
|
|
8
8
|
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.cjs";
|
|
9
|
+
import { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.cjs";
|
|
9
10
|
export * from "@tanstack/hotkeys";
|
|
10
|
-
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
11
|
+
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ import { createHeldKeys } from "./createHeldKeys.js";
|
|
|
6
6
|
import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
7
7
|
import { createKeyHold } from "./createKeyHold.js";
|
|
8
8
|
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
9
|
+
import { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.js";
|
|
9
10
|
export * from "@tanstack/hotkeys";
|
|
10
|
-
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
11
|
+
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,8 @@ import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
|
6
6
|
import { createKeyHold } from "./createKeyHold.js";
|
|
7
7
|
import { createHotkeySequence } from "./createHotkeySequence.js";
|
|
8
8
|
import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
9
|
+
import { createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.js";
|
|
9
10
|
|
|
10
11
|
export * from "@tanstack/hotkeys"
|
|
11
12
|
|
|
12
|
-
export { HotkeysProvider, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
13
|
+
export { HotkeysProvider, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "SolidJS adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@tanstack/solid-store": "^0.9.2",
|
|
46
|
-
"@tanstack/hotkeys": "0.
|
|
46
|
+
"@tanstack/hotkeys": "0.5.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@solidjs/testing-library": "^0.8.10",
|
package/src/HotkeysProvider.tsx
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { createContext, useContext } from 'solid-js'
|
|
2
2
|
import type { JSX, ParentComponent } from 'solid-js'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
HotkeyRecorderOptions,
|
|
5
|
+
HotkeySequenceRecorderOptions,
|
|
6
|
+
} from '@tanstack/hotkeys'
|
|
4
7
|
import type { CreateHotkeyOptions } from './createHotkey'
|
|
5
8
|
import type { CreateHotkeySequenceOptions } from './createHotkeySequence'
|
|
6
9
|
|
|
7
10
|
export interface HotkeysProviderOptions {
|
|
8
11
|
hotkey?: Partial<CreateHotkeyOptions>
|
|
9
12
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>
|
|
13
|
+
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>
|
|
10
14
|
hotkeySequence?: Partial<CreateHotkeySequenceOptions>
|
|
11
15
|
}
|
|
12
16
|
|
|
@@ -25,6 +25,11 @@ export interface CreateHotkeySequenceOptions extends Omit<
|
|
|
25
25
|
* This primitive allows you to register multi-key sequences like 'g g' or 'd d'
|
|
26
26
|
* that trigger when the full sequence is pressed within a timeout.
|
|
27
27
|
*
|
|
28
|
+
* Each step may include modifiers. You can chain the same modifier across
|
|
29
|
+
* steps (e.g. `Shift+R` then `Shift+T`). Modifier-only keydown events (Shift,
|
|
30
|
+
* Control, Alt, or Meta pressed alone) are ignored while matching—they do not
|
|
31
|
+
* advance the sequence or reset progress.
|
|
32
|
+
*
|
|
28
33
|
* @param sequence - Array of hotkey strings that form the sequence (or accessor function)
|
|
29
34
|
* @param callback - Function to call when the sequence is completed
|
|
30
35
|
* @param options - Options for the sequence behavior (or accessor function)
|
|
@@ -47,6 +52,11 @@ export interface CreateHotkeySequenceOptions extends Omit<
|
|
|
47
52
|
* deleteInnerWord()
|
|
48
53
|
* }, { timeout: 500 })
|
|
49
54
|
*
|
|
55
|
+
* // Same modifier on consecutive steps (bare Shift between chords is ignored)
|
|
56
|
+
* createHotkeySequence(['Shift+R', 'Shift+T'], () => {
|
|
57
|
+
* nextAction()
|
|
58
|
+
* })
|
|
59
|
+
*
|
|
50
60
|
* return <div>...</div>
|
|
51
61
|
* }
|
|
52
62
|
* ```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createEffect, onCleanup } from 'solid-js'
|
|
2
|
+
import { useStore } from '@tanstack/solid-store'
|
|
3
|
+
import { HotkeySequenceRecorder } from '@tanstack/hotkeys'
|
|
4
|
+
import { useDefaultHotkeysOptions } from './HotkeysProvider'
|
|
5
|
+
import type {
|
|
6
|
+
HotkeySequence,
|
|
7
|
+
HotkeySequenceRecorderOptions,
|
|
8
|
+
} from '@tanstack/hotkeys'
|
|
9
|
+
|
|
10
|
+
export interface SolidHotkeySequenceRecorder {
|
|
11
|
+
isRecording: () => boolean
|
|
12
|
+
steps: () => HotkeySequence
|
|
13
|
+
recordedSequence: () => HotkeySequence | null
|
|
14
|
+
startRecording: () => void
|
|
15
|
+
stopRecording: () => void
|
|
16
|
+
cancelRecording: () => void
|
|
17
|
+
commitRecording: () => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* SolidJS primitive for recording multi-chord sequences (Vim-style shortcuts).
|
|
22
|
+
*/
|
|
23
|
+
export function createHotkeySequenceRecorder(
|
|
24
|
+
options:
|
|
25
|
+
| HotkeySequenceRecorderOptions
|
|
26
|
+
| (() => HotkeySequenceRecorderOptions),
|
|
27
|
+
): SolidHotkeySequenceRecorder {
|
|
28
|
+
const defaultOptions = useDefaultHotkeysOptions()
|
|
29
|
+
|
|
30
|
+
const resolvedOptions = typeof options === 'function' ? options() : options
|
|
31
|
+
const mergedOptions = {
|
|
32
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
33
|
+
...resolvedOptions,
|
|
34
|
+
} as HotkeySequenceRecorderOptions
|
|
35
|
+
|
|
36
|
+
const recorder = new HotkeySequenceRecorder(mergedOptions)
|
|
37
|
+
|
|
38
|
+
const isRecording = useStore(recorder.store, (state) => state.isRecording)
|
|
39
|
+
const steps = useStore(recorder.store, (state) => state.steps)
|
|
40
|
+
const recordedSequence = useStore(
|
|
41
|
+
recorder.store,
|
|
42
|
+
(state) => state.recordedSequence,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
createEffect(() => {
|
|
46
|
+
const resolved = typeof options === 'function' ? options() : options
|
|
47
|
+
recorder.setOptions({
|
|
48
|
+
...defaultOptions.hotkeySequenceRecorder,
|
|
49
|
+
...resolved,
|
|
50
|
+
} as HotkeySequenceRecorderOptions)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
onCleanup(() => {
|
|
54
|
+
recorder.destroy()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
isRecording,
|
|
59
|
+
steps,
|
|
60
|
+
recordedSequence,
|
|
61
|
+
startRecording: () => recorder.start(),
|
|
62
|
+
stopRecording: () => recorder.stop(),
|
|
63
|
+
cancelRecording: () => recorder.cancel(),
|
|
64
|
+
commitRecording: () => recorder.commit(),
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/index.ts
CHANGED