@tanstack/solid-hotkeys 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/HotkeysProvider.cjs.map +1 -1
  2. package/dist/HotkeysProvider.d.cts +2 -1
  3. package/dist/HotkeysProvider.d.ts +2 -1
  4. package/dist/HotkeysProvider.js.map +1 -1
  5. package/dist/createHotkey.cjs +27 -8
  6. package/dist/createHotkey.cjs.map +1 -1
  7. package/dist/createHotkey.js +27 -8
  8. package/dist/createHotkey.js.map +1 -1
  9. package/dist/createHotkeySequence.cjs +27 -8
  10. package/dist/createHotkeySequence.cjs.map +1 -1
  11. package/dist/createHotkeySequence.js +28 -9
  12. package/dist/createHotkeySequence.js.map +1 -1
  13. package/dist/createHotkeySequenceRecorder.cjs +43 -0
  14. package/dist/createHotkeySequenceRecorder.cjs.map +1 -0
  15. package/dist/createHotkeySequenceRecorder.d.cts +19 -0
  16. package/dist/createHotkeySequenceRecorder.d.ts +19 -0
  17. package/dist/createHotkeySequenceRecorder.js +43 -0
  18. package/dist/createHotkeySequenceRecorder.js.map +1 -0
  19. package/dist/createHotkeySequences.cjs +110 -0
  20. package/dist/createHotkeySequences.cjs.map +1 -0
  21. package/dist/createHotkeySequences.d.cts +57 -0
  22. package/dist/createHotkeySequences.d.ts +57 -0
  23. package/dist/createHotkeySequences.js +110 -0
  24. package/dist/createHotkeySequences.js.map +1 -0
  25. package/dist/index.cjs +4 -0
  26. package/dist/index.d.cts +3 -1
  27. package/dist/index.d.ts +3 -1
  28. package/dist/index.js +3 -1
  29. package/package.json +2 -2
  30. package/src/HotkeysProvider.tsx +5 -1
  31. package/src/createHotkey.ts +32 -13
  32. package/src/createHotkeySequence.ts +33 -16
  33. package/src/createHotkeySequenceRecorder.ts +66 -0
  34. package/src/createHotkeySequences.ts +176 -0
  35. package/src/index.ts +2 -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 { HotkeyRecorderOptions } 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 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":";;;;AAgBA,MAAMc,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
+ {"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 { HotkeyRecorderOptions } 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 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":";;;;AAgBA,MAAMc,iBAAiBd,cAA0C,KAAK;AAOtE,MAAMkB,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,QAAOxB,WAAWa,eAAe;;AAGnC,SAAgBY,2BAA2B;AAEzC,QADgBzB,WAAWa,eAAe,EAC1BD,kBAAkB,EAAE"}
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"}
@@ -62,6 +62,16 @@ function createHotkey(hotkey, callback, options = {}) {
62
62
  const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
63
63
  const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
64
64
  let registration = null;
65
+ let lastHotkeyString = null;
66
+ let lastTarget = null;
67
+ (0, solid_js.onCleanup)(() => {
68
+ if (registration?.isActive) {
69
+ registration.unregister();
70
+ registration = null;
71
+ }
72
+ lastHotkeyString = null;
73
+ lastTarget = null;
74
+ });
65
75
  (0, solid_js.createEffect)(() => {
66
76
  const resolvedHotkey = typeof hotkey === "function" ? hotkey() : hotkey;
67
77
  const resolvedOptions = typeof options === "function" ? options() : options;
@@ -72,12 +82,25 @@ function createHotkey(hotkey, callback, options = {}) {
72
82
  const platform = mergedOptions.platform ?? (0, _tanstack_hotkeys.detectPlatform)();
73
83
  const hotkeyString = typeof resolvedHotkey === "string" ? resolvedHotkey : (0, _tanstack_hotkeys.formatHotkey)((0, _tanstack_hotkeys.rawHotkeyToParsedHotkey)(resolvedHotkey, platform));
74
84
  const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
75
- if (!resolvedTarget) return;
85
+ if (!resolvedTarget) {
86
+ if (registration?.isActive) {
87
+ registration.unregister();
88
+ registration = null;
89
+ }
90
+ lastHotkeyString = null;
91
+ lastTarget = null;
92
+ return;
93
+ }
94
+ const { target: _target, ...optionsWithoutTarget } = mergedOptions;
95
+ if (registration?.isActive && lastHotkeyString === hotkeyString && lastTarget === resolvedTarget) {
96
+ registration.callback = callback;
97
+ registration.setOptions(optionsWithoutTarget);
98
+ return;
99
+ }
76
100
  if (registration?.isActive) {
77
101
  registration.unregister();
78
102
  registration = null;
79
103
  }
80
- const { target: _target, ...optionsWithoutTarget } = mergedOptions;
81
104
  registration = manager.register(hotkeyString, callback, {
82
105
  ...optionsWithoutTarget,
83
106
  target: resolvedTarget
@@ -86,12 +109,8 @@ function createHotkey(hotkey, callback, options = {}) {
86
109
  registration.callback = callback;
87
110
  registration.setOptions(optionsWithoutTarget);
88
111
  }
89
- (0, solid_js.onCleanup)(() => {
90
- if (registration?.isActive) {
91
- registration.unregister();
92
- registration = null;
93
- }
94
- });
112
+ lastHotkeyString = hotkeyString;
113
+ lastTarget = resolvedTarget;
95
114
  });
96
115
  }
97
116
 
@@ -1 +1 @@
1
- {"version":3,"file":"createHotkey.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor (for reactive targets that become\n * available after mount), or null. Defaults to document.\n * When using scoped targets, pass an accessor: () => ({ target: elementSignal() })\n * so the hotkey waits for the element to be attached before registering.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This primitive automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = createSignal(0)\n *\n * // Callback always has access to latest count value\n * createHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count()}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal(props) {\n * // enabled option is reactive\n * createHotkey('Escape', () => {\n * props.onClose()\n * }, () => ({ enabled: props.isOpen }))\n *\n * return <Show when={props.isOpen}>\n * <div class=\"modal\">...</div>\n * </Show>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element - use accessor so hotkey waits for ref\n * createHotkey('Mod+S', save, () => ({ target: editorRef() }))\n *\n * return <div ref={setEditorRef}>...</div>\n * }\n * ```\n */\nexport function createHotkey(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n callback: HotkeyCallback,\n options: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedHotkey = typeof hotkey === 'function' ? hotkey() : hotkey\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as CreateHotkeyOptions\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof resolvedHotkey === 'string'\n ? resolvedHotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(resolvedHotkey, platform),\n ) as Hotkey)\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches React's ref handling.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n return\n }\n\n // Unregister previous registration if it exists\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Register the hotkey\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n // Update callback and options on every effect run\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n // Cleanup on disposal\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,mDAA4B;CAElC,IAAI,eAAgD;AAEpD,kCAAmB;EAEjB,MAAM,iBAAiB,OAAO,WAAW,aAAa,QAAQ,GAAG;EACjE,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,WAAW,cAAc,mDAA4B;EAC3D,MAAM,eACJ,OAAO,mBAAmB,WACtB,oGAE0B,gBAAgB,SAAS,CAClD;EAIP,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,eACH;AAIF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;EAIjB,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAGrD,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAGF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAI/C,gCAAgB;AACd,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;IAEjB;GACF"}
1
+ {"version":3,"file":"createHotkey.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor (for reactive targets that become\n * available after mount), or null. Defaults to document.\n * When using scoped targets, pass an accessor: () => ({ target: elementSignal() })\n * so the hotkey waits for the element to be attached before registering.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This primitive automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = createSignal(0)\n *\n * // Callback always has access to latest count value\n * createHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count()}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal(props) {\n * // enabled option is reactive\n * createHotkey('Escape', () => {\n * props.onClose()\n * }, () => ({ enabled: props.isOpen }))\n *\n * return <Show when={props.isOpen}>\n * <div class=\"modal\">...</div>\n * </Show>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element - use accessor so hotkey waits for ref\n * createHotkey('Mod+S', save, () => ({ target: editorRef() }))\n *\n * return <div ref={setEditorRef}>...</div>\n * }\n * ```\n */\nexport function createHotkey(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n callback: HotkeyCallback,\n options: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n let lastHotkeyString: Hotkey | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n })\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedHotkey = typeof hotkey === 'function' ? hotkey() : hotkey\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as CreateHotkeyOptions\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof resolvedHotkey === 'string'\n ? resolvedHotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(resolvedHotkey, platform),\n ) as Hotkey)\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches React's ref handling.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n return\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n if (\n registration?.isActive &&\n lastHotkeyString === hotkeyString &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastHotkeyString = hotkeyString\n lastTarget = resolvedTarget\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,mDAA4B;CAElC,IAAI,eAAgD;CACpD,IAAI,mBAAkC;CACtC,IAAI,aAAqD;AAEzD,+BAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,qBAAmB;AACnB,eAAa;GACb;AAEF,kCAAmB;EAEjB,MAAM,iBAAiB,OAAO,WAAW,aAAa,QAAQ,GAAG;EACjE,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,WAAW,cAAc,mDAA4B;EAC3D,MAAM,eACJ,OAAO,mBAAmB,WACtB,oGAE0B,gBAAgB,SAAS,CAClD;EAIP,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,gBAAgB;AACnB,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,sBAAmB;AACnB,gBAAa;AACb;;EAIF,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,MACE,cAAc,YACd,qBAAqB,gBACrB,eAAe,gBACf;AACA,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;AAC7C;;AAGF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAGjB,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAEF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAG/C,qBAAmB;AACnB,eAAa;GACb"}
@@ -62,6 +62,16 @@ function createHotkey(hotkey, callback, options = {}) {
62
62
  const defaultOptions = useDefaultHotkeysOptions();
63
63
  const manager = getHotkeyManager();
64
64
  let registration = null;
65
+ let lastHotkeyString = null;
66
+ let lastTarget = null;
67
+ onCleanup(() => {
68
+ if (registration?.isActive) {
69
+ registration.unregister();
70
+ registration = null;
71
+ }
72
+ lastHotkeyString = null;
73
+ lastTarget = null;
74
+ });
65
75
  createEffect(() => {
66
76
  const resolvedHotkey = typeof hotkey === "function" ? hotkey() : hotkey;
67
77
  const resolvedOptions = typeof options === "function" ? options() : options;
@@ -72,12 +82,25 @@ function createHotkey(hotkey, callback, options = {}) {
72
82
  const platform = mergedOptions.platform ?? detectPlatform();
73
83
  const hotkeyString = typeof resolvedHotkey === "string" ? resolvedHotkey : formatHotkey(rawHotkeyToParsedHotkey(resolvedHotkey, platform));
74
84
  const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
75
- if (!resolvedTarget) return;
85
+ if (!resolvedTarget) {
86
+ if (registration?.isActive) {
87
+ registration.unregister();
88
+ registration = null;
89
+ }
90
+ lastHotkeyString = null;
91
+ lastTarget = null;
92
+ return;
93
+ }
94
+ const { target: _target, ...optionsWithoutTarget } = mergedOptions;
95
+ if (registration?.isActive && lastHotkeyString === hotkeyString && lastTarget === resolvedTarget) {
96
+ registration.callback = callback;
97
+ registration.setOptions(optionsWithoutTarget);
98
+ return;
99
+ }
76
100
  if (registration?.isActive) {
77
101
  registration.unregister();
78
102
  registration = null;
79
103
  }
80
- const { target: _target, ...optionsWithoutTarget } = mergedOptions;
81
104
  registration = manager.register(hotkeyString, callback, {
82
105
  ...optionsWithoutTarget,
83
106
  target: resolvedTarget
@@ -86,12 +109,8 @@ function createHotkey(hotkey, callback, options = {}) {
86
109
  registration.callback = callback;
87
110
  registration.setOptions(optionsWithoutTarget);
88
111
  }
89
- onCleanup(() => {
90
- if (registration?.isActive) {
91
- registration.unregister();
92
- registration = null;
93
- }
94
- });
112
+ lastHotkeyString = hotkeyString;
113
+ lastTarget = resolvedTarget;
95
114
  });
96
115
  }
97
116
 
@@ -1 +1 @@
1
- {"version":3,"file":"createHotkey.js","names":[],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor (for reactive targets that become\n * available after mount), or null. Defaults to document.\n * When using scoped targets, pass an accessor: () => ({ target: elementSignal() })\n * so the hotkey waits for the element to be attached before registering.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This primitive automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = createSignal(0)\n *\n * // Callback always has access to latest count value\n * createHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count()}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal(props) {\n * // enabled option is reactive\n * createHotkey('Escape', () => {\n * props.onClose()\n * }, () => ({ enabled: props.isOpen }))\n *\n * return <Show when={props.isOpen}>\n * <div class=\"modal\">...</div>\n * </Show>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element - use accessor so hotkey waits for ref\n * createHotkey('Mod+S', save, () => ({ target: editorRef() }))\n *\n * return <div ref={setEditorRef}>...</div>\n * }\n * ```\n */\nexport function createHotkey(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n callback: HotkeyCallback,\n options: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedHotkey = typeof hotkey === 'function' ? hotkey() : hotkey\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as CreateHotkeyOptions\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof resolvedHotkey === 'string'\n ? resolvedHotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(resolvedHotkey, platform),\n ) as Hotkey)\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches React's ref handling.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n return\n }\n\n // Unregister previous registration if it exists\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n // Register the hotkey\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n // Update callback and options on every effect run\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n // Cleanup on disposal\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,kBAAkB;CAElC,IAAI,eAAgD;AAEpD,oBAAmB;EAEjB,MAAM,iBAAiB,OAAO,WAAW,aAAa,QAAQ,GAAG;EACjE,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,WAAW,cAAc,YAAY,gBAAgB;EAC3D,MAAM,eACJ,OAAO,mBAAmB,WACtB,iBACC,aACC,wBAAwB,gBAAgB,SAAS,CAClD;EAIP,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,eACH;AAIF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;EAIjB,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAGrD,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAGF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAI/C,kBAAgB;AACd,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;IAEjB;GACF"}
1
+ {"version":3,"file":"createHotkey.js","names":[],"sources":["../src/createHotkey.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a direct DOM element, an accessor (for reactive targets that become\n * available after mount), or null. Defaults to document.\n * When using scoped targets, pass an accessor: () => ({ target: elementSignal() })\n * so the hotkey waits for the element to be attached before registering.\n */\n target?: HTMLElement | Document | Window | null\n}\n\n/**\n * SolidJS primitive for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This primitive automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = createSignal(0)\n *\n * // Callback always has access to latest count value\n * createHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count()}`)\n * handleSave()\n * })\n *\n * return <button onClick={() => setCount(c => c + 1)}>Count: {count()}</button>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Modal(props) {\n * // enabled option is reactive\n * createHotkey('Escape', () => {\n * props.onClose()\n * }, () => ({ enabled: props.isOpen }))\n *\n * return <Show when={props.isOpen}>\n * <div class=\"modal\">...</div>\n * </Show>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const [editorRef, setEditorRef] = createSignal<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element - use accessor so hotkey waits for ref\n * createHotkey('Mod+S', save, () => ({ target: editorRef() }))\n *\n * return <div ref={setEditorRef}>...</div>\n * }\n * ```\n */\nexport function createHotkey(\n hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n callback: HotkeyCallback,\n options: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n let lastHotkeyString: Hotkey | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n })\n\n createEffect(() => {\n // Resolve reactive values\n const resolvedHotkey = typeof hotkey === 'function' ? hotkey() : hotkey\n const resolvedOptions = typeof options === 'function' ? options() : options\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as CreateHotkeyOptions\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof resolvedHotkey === 'string'\n ? resolvedHotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(resolvedHotkey, platform),\n ) as Hotkey)\n\n // Resolve target: when explicitly provided (even as null), use it and skip if null.\n // When not provided, default to document. Matches React's ref handling.\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n return\n }\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n if (\n registration?.isActive &&\n lastHotkeyString === hotkeyString &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastHotkeyString = hotkeyString\n lastTarget = resolvedTarget\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,aACd,QACA,UACA,UAA6D,EAAE,EACzD;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,kBAAkB;CAElC,IAAI,eAAgD;CACpD,IAAI,mBAAkC;CACtC,IAAI,aAAqD;AAEzD,iBAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,qBAAmB;AACnB,eAAa;GACb;AAEF,oBAAmB;EAEjB,MAAM,iBAAiB,OAAO,WAAW,aAAa,QAAQ,GAAG;EACjE,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EAEpE,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;EAGD,MAAM,WAAW,cAAc,YAAY,gBAAgB;EAC3D,MAAM,eACJ,OAAO,mBAAmB,WACtB,iBACC,aACC,wBAAwB,gBAAgB,SAAS,CAClD;EAIP,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,CAAC,gBAAgB;AACnB,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,sBAAmB;AACnB,gBAAa;AACb;;EAIF,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,MACE,cAAc,YACd,qBAAqB,gBACrB,eAAe,gBACf;AACA,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;AAC7C;;AAGF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAGjB,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAEF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAG/C,qBAAmB;AACnB,eAAa;GACb"}
@@ -49,6 +49,16 @@ function createHotkeySequence(sequence, callback, options = {}) {
49
49
  const defaultOptions = require_HotkeysProvider.useDefaultHotkeysOptions();
50
50
  const manager = (0, _tanstack_hotkeys.getSequenceManager)();
51
51
  let registration = null;
52
+ let lastSequenceKey = null;
53
+ let lastTarget = null;
54
+ (0, solid_js.onCleanup)(() => {
55
+ if (registration?.isActive) {
56
+ registration.unregister();
57
+ registration = null;
58
+ }
59
+ lastSequenceKey = null;
60
+ lastTarget = null;
61
+ });
52
62
  (0, solid_js.createEffect)(() => {
53
63
  const resolvedSequence = typeof sequence === "function" ? sequence() : sequence;
54
64
  const resolvedOptions = typeof options === "function" ? options() : options;
@@ -57,9 +67,22 @@ function createHotkeySequence(sequence, callback, options = {}) {
57
67
  ...resolvedOptions
58
68
  };
59
69
  const { target: _target, ...optionsWithoutTarget } = mergedOptions;
60
- if (resolvedSequence.length === 0) return;
61
70
  const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
62
- if (!resolvedTarget) return;
71
+ if (resolvedSequence.length === 0 || !resolvedTarget) {
72
+ if (registration?.isActive) {
73
+ registration.unregister();
74
+ registration = null;
75
+ }
76
+ lastSequenceKey = null;
77
+ lastTarget = null;
78
+ return;
79
+ }
80
+ const sequenceKey = (0, _tanstack_hotkeys.formatHotkeySequence)(resolvedSequence);
81
+ if (registration?.isActive && lastSequenceKey === sequenceKey && lastTarget === resolvedTarget) {
82
+ registration.callback = callback;
83
+ registration.setOptions(optionsWithoutTarget);
84
+ return;
85
+ }
63
86
  if (registration?.isActive) {
64
87
  registration.unregister();
65
88
  registration = null;
@@ -72,12 +95,8 @@ function createHotkeySequence(sequence, callback, options = {}) {
72
95
  registration.callback = callback;
73
96
  registration.setOptions(optionsWithoutTarget);
74
97
  }
75
- (0, solid_js.onCleanup)(() => {
76
- if (registration?.isActive) {
77
- registration.unregister();
78
- registration = null;
79
- }
80
- });
98
+ lastSequenceKey = sequenceKey;
99
+ lastTarget = resolvedTarget;
81
100
  });
82
101
  }
83
102
 
@@ -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 * 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"}
1
+ {"version":3,"file":"createHotkeySequence.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkeySequence.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { formatHotkeySequence, 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 let lastSequenceKey: string | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n })\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 // 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 (resolvedSequence.length === 0 || !resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n return\n }\n\n const sequenceKey = formatHotkeySequence(resolvedSequence)\n\n if (\n registration?.isActive &&\n lastSequenceKey === sequenceKey &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastSequenceKey = sequenceKey\n lastTarget = resolvedTarget\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,qDAA8B;CAEpC,IAAI,eAAkD;CACtD,IAAI,kBAAiC;CACrC,IAAI,aAAqD;AAEzD,+BAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,oBAAkB;AAClB,eAAa;GACb;AAEF,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;EAIrD,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,iBAAiB,WAAW,KAAK,CAAC,gBAAgB;AACpD,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,qBAAkB;AAClB,gBAAa;AACb;;EAGF,MAAM,0DAAmC,iBAAiB;AAE1D,MACE,cAAc,YACd,oBAAoB,eACpB,eAAe,gBACf;AACA,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;AAC7C;;AAGF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAGjB,iBAAe,QAAQ,SAAS,kBAAkB,UAAU;GAC1D,GAAG;GACH,QAAQ;GACT,CAAC;AAEF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAG/C,oBAAkB;AAClB,eAAa;GACb"}
@@ -1,5 +1,5 @@
1
1
  import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
2
- import { getSequenceManager } from "@tanstack/hotkeys";
2
+ import { formatHotkeySequence, getSequenceManager } from "@tanstack/hotkeys";
3
3
  import { createEffect, onCleanup } from "solid-js";
4
4
 
5
5
  //#region src/createHotkeySequence.ts
@@ -49,6 +49,16 @@ function createHotkeySequence(sequence, callback, options = {}) {
49
49
  const defaultOptions = useDefaultHotkeysOptions();
50
50
  const manager = getSequenceManager();
51
51
  let registration = null;
52
+ let lastSequenceKey = null;
53
+ let lastTarget = null;
54
+ onCleanup(() => {
55
+ if (registration?.isActive) {
56
+ registration.unregister();
57
+ registration = null;
58
+ }
59
+ lastSequenceKey = null;
60
+ lastTarget = null;
61
+ });
52
62
  createEffect(() => {
53
63
  const resolvedSequence = typeof sequence === "function" ? sequence() : sequence;
54
64
  const resolvedOptions = typeof options === "function" ? options() : options;
@@ -57,9 +67,22 @@ function createHotkeySequence(sequence, callback, options = {}) {
57
67
  ...resolvedOptions
58
68
  };
59
69
  const { target: _target, ...optionsWithoutTarget } = mergedOptions;
60
- if (resolvedSequence.length === 0) return;
61
70
  const resolvedTarget = "target" in mergedOptions ? mergedOptions.target ?? null : typeof document !== "undefined" ? document : null;
62
- if (!resolvedTarget) return;
71
+ if (resolvedSequence.length === 0 || !resolvedTarget) {
72
+ if (registration?.isActive) {
73
+ registration.unregister();
74
+ registration = null;
75
+ }
76
+ lastSequenceKey = null;
77
+ lastTarget = null;
78
+ return;
79
+ }
80
+ const sequenceKey = formatHotkeySequence(resolvedSequence);
81
+ if (registration?.isActive && lastSequenceKey === sequenceKey && lastTarget === resolvedTarget) {
82
+ registration.callback = callback;
83
+ registration.setOptions(optionsWithoutTarget);
84
+ return;
85
+ }
63
86
  if (registration?.isActive) {
64
87
  registration.unregister();
65
88
  registration = null;
@@ -72,12 +95,8 @@ function createHotkeySequence(sequence, callback, options = {}) {
72
95
  registration.callback = callback;
73
96
  registration.setOptions(optionsWithoutTarget);
74
97
  }
75
- onCleanup(() => {
76
- if (registration?.isActive) {
77
- registration.unregister();
78
- registration = null;
79
- }
80
- });
98
+ lastSequenceKey = sequenceKey;
99
+ lastTarget = resolvedTarget;
81
100
  });
82
101
  }
83
102
 
@@ -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 * 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"}
1
+ {"version":3,"file":"createHotkeySequence.js","names":[],"sources":["../src/createHotkeySequence.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { formatHotkeySequence, 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 let lastSequenceKey: string | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n onCleanup(() => {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n })\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 // 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 (resolvedSequence.length === 0 || !resolvedTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastSequenceKey = null\n lastTarget = null\n return\n }\n\n const sequenceKey = formatHotkeySequence(resolvedSequence)\n\n if (\n registration?.isActive &&\n lastSequenceKey === sequenceKey &&\n lastTarget === resolvedTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(resolvedSequence, callback, {\n ...mergedOptions,\n target: resolvedTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastSequenceKey = sequenceKey\n lastTarget = resolvedTarget\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,qBACd,UACA,UACA,UAE0C,EAAE,EACtC;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,oBAAoB;CAEpC,IAAI,eAAkD;CACtD,IAAI,kBAAiC;CACrC,IAAI,aAAqD;AAEzD,iBAAgB;AACd,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAEjB,oBAAkB;AAClB,eAAa;GACb;AAEF,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;EAIrD,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,MAAI,iBAAiB,WAAW,KAAK,CAAC,gBAAgB;AACpD,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,qBAAkB;AAClB,gBAAa;AACb;;EAGF,MAAM,cAAc,qBAAqB,iBAAiB;AAE1D,MACE,cAAc,YACd,oBAAoB,eACpB,eAAe,gBACf;AACA,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;AAC7C;;AAGF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAGjB,iBAAe,QAAQ,SAAS,kBAAkB,UAAU;GAC1D,GAAG;GACH,QAAQ;GACT,CAAC;AAEF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAG/C,oBAAkB;AAClB,eAAa;GACb"}
@@ -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"}