@tanstack/preact-hotkeys 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +15 -1
  2. package/dist/HotkeysProvider.d.ts +6 -13
  3. package/dist/HotkeysProvider.js +1 -2
  4. package/dist/index.d.ts +2 -1
  5. package/dist/index.js +2 -1
  6. package/dist/useHeldKeyCodes.d.ts +2 -4
  7. package/dist/useHeldKeyCodes.js +3 -3
  8. package/dist/useHeldKeys.d.ts +2 -4
  9. package/dist/useHeldKeys.js +3 -3
  10. package/dist/useHotkey.d.ts +3 -6
  11. package/dist/useHotkey.js +12 -8
  12. package/dist/useHotkeyHint.d.ts +11 -0
  13. package/dist/useHotkeyHint.js +17 -0
  14. package/dist/useHotkeyRecorder.d.ts +3 -6
  15. package/dist/useHotkeyRecorder.js +1 -2
  16. package/dist/useHotkeyRegistrations.d.ts +3 -6
  17. package/dist/useHotkeyRegistrations.js +6 -4
  18. package/dist/useHotkeySequence.d.ts +3 -6
  19. package/dist/useHotkeySequence.js +10 -7
  20. package/dist/useHotkeySequenceRecorder.d.ts +3 -6
  21. package/dist/useHotkeySequenceRecorder.js +1 -2
  22. package/dist/useHotkeySequences.d.ts +3 -6
  23. package/dist/useHotkeySequences.js +4 -17
  24. package/dist/useHotkeys.d.ts +3 -6
  25. package/dist/useHotkeys.js +4 -17
  26. package/dist/useKeyHold.d.ts +2 -5
  27. package/dist/useKeyHold.js +1 -2
  28. package/dist/utils.js +1 -2
  29. package/package.json +11 -16
  30. package/dist/HotkeysProvider.cjs +0 -26
  31. package/dist/HotkeysProvider.cjs.map +0 -1
  32. package/dist/HotkeysProvider.d.cts +0 -29
  33. package/dist/HotkeysProvider.js.map +0 -1
  34. package/dist/index.cjs +0 -33
  35. package/dist/index.d.cts +0 -13
  36. package/dist/useHeldKeyCodes.cjs +0 -37
  37. package/dist/useHeldKeyCodes.cjs.map +0 -1
  38. package/dist/useHeldKeyCodes.d.cts +0 -31
  39. package/dist/useHeldKeyCodes.js.map +0 -1
  40. package/dist/useHeldKeys.cjs +0 -33
  41. package/dist/useHeldKeys.cjs.map +0 -1
  42. package/dist/useHeldKeys.d.cts +0 -27
  43. package/dist/useHeldKeys.js.map +0 -1
  44. package/dist/useHotkey.cjs +0 -121
  45. package/dist/useHotkey.cjs.map +0 -1
  46. package/dist/useHotkey.d.cts +0 -75
  47. package/dist/useHotkey.js.map +0 -1
  48. package/dist/useHotkeyRecorder.cjs +0 -71
  49. package/dist/useHotkeyRecorder.cjs.map +0 -1
  50. package/dist/useHotkeyRecorder.d.cts +0 -57
  51. package/dist/useHotkeyRecorder.js.map +0 -1
  52. package/dist/useHotkeyRegistrations.cjs +0 -26
  53. package/dist/useHotkeyRegistrations.cjs.map +0 -1
  54. package/dist/useHotkeyRegistrations.d.cts +0 -26
  55. package/dist/useHotkeyRegistrations.js.map +0 -1
  56. package/dist/useHotkeySequence.cjs +0 -116
  57. package/dist/useHotkeySequence.cjs.map +0 -1
  58. package/dist/useHotkeySequence.d.cts +0 -59
  59. package/dist/useHotkeySequence.js.map +0 -1
  60. package/dist/useHotkeySequenceRecorder.cjs +0 -39
  61. package/dist/useHotkeySequenceRecorder.cjs.map +0 -1
  62. package/dist/useHotkeySequenceRecorder.d.cts +0 -19
  63. package/dist/useHotkeySequenceRecorder.js.map +0 -1
  64. package/dist/useHotkeySequences.cjs +0 -138
  65. package/dist/useHotkeySequences.cjs.map +0 -1
  66. package/dist/useHotkeySequences.d.cts +0 -63
  67. package/dist/useHotkeySequences.js.map +0 -1
  68. package/dist/useHotkeys.cjs +0 -136
  69. package/dist/useHotkeys.cjs.map +0 -1
  70. package/dist/useHotkeys.d.cts +0 -63
  71. package/dist/useHotkeys.js.map +0 -1
  72. package/dist/useKeyHold.cjs +0 -53
  73. package/dist/useKeyHold.cjs.map +0 -1
  74. package/dist/useKeyHold.d.cts +0 -47
  75. package/dist/useKeyHold.js.map +0 -1
  76. package/dist/utils.cjs +0 -12
  77. package/dist/utils.cjs.map +0 -1
  78. package/dist/utils.js.map +0 -1
  79. package/src/HotkeysProvider.tsx +0 -56
  80. package/src/index.ts +0 -17
  81. package/src/useHeldKeyCodes.ts +0 -33
  82. package/src/useHeldKeys.ts +0 -29
  83. package/src/useHotkey.ts +0 -188
  84. package/src/useHotkeyRecorder.ts +0 -101
  85. package/src/useHotkeyRegistrations.ts +0 -45
  86. package/src/useHotkeySequence.ts +0 -188
  87. package/src/useHotkeySequenceRecorder.ts +0 -64
  88. package/src/useHotkeySequences.ts +0 -206
  89. package/src/useHotkeys.ts +0 -207
  90. package/src/useKeyHold.ts +0 -52
  91. package/src/utils.ts +0 -8
@@ -1,29 +0,0 @@
1
- import { UseHotkeyOptions } from "./useHotkey.cjs";
2
- import { UseHotkeySequenceOptions } from "./useHotkeySequence.cjs";
3
- import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
4
- import * as _$preact from "preact";
5
- import { ComponentChildren } from "preact";
6
-
7
- //#region src/HotkeysProvider.d.ts
8
- interface HotkeysProviderOptions {
9
- hotkey?: Partial<UseHotkeyOptions>;
10
- hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
11
- hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
12
- hotkeySequence?: Partial<UseHotkeySequenceOptions>;
13
- }
14
- interface HotkeysContextValue {
15
- defaultOptions: HotkeysProviderOptions;
16
- }
17
- interface HotkeysProviderProps {
18
- children: ComponentChildren;
19
- defaultOptions?: HotkeysProviderOptions;
20
- }
21
- declare function HotkeysProvider({
22
- children,
23
- defaultOptions
24
- }: HotkeysProviderProps): _$preact.JSX.Element;
25
- declare function useHotkeysContext(): HotkeysContextValue | null;
26
- declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
27
- //#endregion
28
- export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext };
29
- //# sourceMappingURL=HotkeysProvider.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HotkeysProvider.js","names":[],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport { useContext, useMemo } from 'preact/hooks'\nimport type { ComponentChildren } from 'preact'\nimport type {\n HotkeyRecorderOptions,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\nimport type { UseHotkeyOptions } from './useHotkey'\nimport type { UseHotkeySequenceOptions } from './useHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<UseHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>\n hotkeySequence?: Partial<UseHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: ComponentChildren\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport function HotkeysProvider({\n children,\n defaultOptions = DEFAULT_OPTIONS,\n}: HotkeysProviderProps) {\n const contextValue: HotkeysContextValue = useMemo(\n () => ({\n defaultOptions,\n }),\n [defaultOptions],\n )\n\n return (\n <HotkeysContext.Provider value={contextValue}>\n {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":";;;;;AAqBA,MAAM,iBAAiB,cAA0C,KAAK;AAOtE,MAAM,kBAA0C,EAAE;AAElD,SAAgB,gBAAgB,EAC9B,UACA,iBAAiB,mBACM;CACvB,MAAM,eAAoC,eACjC,EACL,gBACD,GACD,CAAC,eAAe,CACjB;AAED,QACE,oBAAC,eAAe,UAAhB;EAAyB,OAAO;EAC7B;EACuB;;AAI9B,SAAgB,oBAAoB;AAClC,QAAO,WAAW,eAAe;;AAGnC,SAAgB,2BAA2B;AAEzC,QADgB,WAAW,eAAe,EAC1B,kBAAkB,EAAE"}
package/dist/index.cjs DELETED
@@ -1,33 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_HotkeysProvider = require('./HotkeysProvider.cjs');
3
- const require_useHotkey = require('./useHotkey.cjs');
4
- const require_useHotkeys = require('./useHotkeys.cjs');
5
- const require_useHeldKeys = require('./useHeldKeys.cjs');
6
- const require_useHeldKeyCodes = require('./useHeldKeyCodes.cjs');
7
- const require_useKeyHold = require('./useKeyHold.cjs');
8
- const require_useHotkeySequence = require('./useHotkeySequence.cjs');
9
- const require_useHotkeySequences = require('./useHotkeySequences.cjs');
10
- const require_useHotkeyRecorder = require('./useHotkeyRecorder.cjs');
11
- const require_useHotkeyRegistrations = require('./useHotkeyRegistrations.cjs');
12
- const require_useHotkeySequenceRecorder = require('./useHotkeySequenceRecorder.cjs');
13
-
14
- exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
15
- exports.useDefaultHotkeysOptions = require_HotkeysProvider.useDefaultHotkeysOptions;
16
- exports.useHeldKeyCodes = require_useHeldKeyCodes.useHeldKeyCodes;
17
- exports.useHeldKeys = require_useHeldKeys.useHeldKeys;
18
- exports.useHotkey = require_useHotkey.useHotkey;
19
- exports.useHotkeyRecorder = require_useHotkeyRecorder.useHotkeyRecorder;
20
- exports.useHotkeyRegistrations = require_useHotkeyRegistrations.useHotkeyRegistrations;
21
- exports.useHotkeySequence = require_useHotkeySequence.useHotkeySequence;
22
- exports.useHotkeySequenceRecorder = require_useHotkeySequenceRecorder.useHotkeySequenceRecorder;
23
- exports.useHotkeySequences = require_useHotkeySequences.useHotkeySequences;
24
- exports.useHotkeys = require_useHotkeys.useHotkeys;
25
- exports.useHotkeysContext = require_HotkeysProvider.useHotkeysContext;
26
- exports.useKeyHold = require_useKeyHold.useKeyHold;
27
- var _tanstack_hotkeys = require("@tanstack/hotkeys");
28
- Object.keys(_tanstack_hotkeys).forEach(function (k) {
29
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
30
- enumerable: true,
31
- get: function () { return _tanstack_hotkeys[k]; }
32
- });
33
- });
package/dist/index.d.cts DELETED
@@ -1,13 +0,0 @@
1
- import { UseHotkeyOptions, useHotkey } from "./useHotkey.cjs";
2
- import { UseHotkeySequenceOptions, useHotkeySequence } from "./useHotkeySequence.cjs";
3
- import { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.cjs";
4
- import { UseHotkeyDefinition, useHotkeys } from "./useHotkeys.cjs";
5
- import { useHeldKeys } from "./useHeldKeys.cjs";
6
- import { useHeldKeyCodes } from "./useHeldKeyCodes.cjs";
7
- import { useKeyHold } from "./useKeyHold.cjs";
8
- import { UseHotkeySequenceDefinition, useHotkeySequences } from "./useHotkeySequences.cjs";
9
- import { PreactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.cjs";
10
- import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.cjs";
11
- import { PreactHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.cjs";
12
- export * from "@tanstack/hotkeys";
13
- export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, PreactHotkeyRecorder, PreactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
@@ -1,37 +0,0 @@
1
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
2
- let _tanstack_preact_store = require("@tanstack/preact-store");
3
-
4
- //#region src/useHeldKeyCodes.ts
5
- /**
6
- * Preact hook that returns a map of currently held key names to their physical `event.code` values.
7
- *
8
- * This is useful for debugging which physical key was pressed (e.g. distinguishing
9
- * left vs right Shift via "ShiftLeft" / "ShiftRight").
10
- *
11
- * @returns Record mapping normalized key names to their `event.code` values
12
- *
13
- * @example
14
- * ```tsx
15
- * function KeyDebugDisplay() {
16
- * const heldKeys = useHeldKeys()
17
- * const heldCodes = useHeldKeyCodes()
18
- *
19
- * return (
20
- * <div>
21
- * {heldKeys.map((key) => (
22
- * <kbd key={key}>
23
- * {key} <small>{heldCodes[key]}</small>
24
- * </kbd>
25
- * ))}
26
- * </div>
27
- * )
28
- * }
29
- * ```
30
- */
31
- function useHeldKeyCodes() {
32
- return (0, _tanstack_preact_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldCodes);
33
- }
34
-
35
- //#endregion
36
- exports.useHeldKeyCodes = useHeldKeyCodes;
37
- //# sourceMappingURL=useHeldKeyCodes.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHeldKeyCodes.cjs","names":[],"sources":["../src/useHeldKeyCodes.ts"],"sourcesContent":["import { useSelector } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns a map of currently held key names to their physical `event.code` values.\n *\n * This is useful for debugging which physical key was pressed (e.g. distinguishing\n * left vs right Shift via \"ShiftLeft\" / \"ShiftRight\").\n *\n * @returns Record mapping normalized key names to their `event.code` values\n *\n * @example\n * ```tsx\n * function KeyDebugDisplay() {\n * const heldKeys = useHeldKeys()\n * const heldCodes = useHeldKeyCodes()\n *\n * return (\n * <div>\n * {heldKeys.map((key) => (\n * <kbd key={key}>\n * {key} <small>{heldCodes[key]}</small>\n * </kbd>\n * ))}\n * </div>\n * )\n * }\n * ```\n */\nexport function useHeldKeyCodes(): Record<string, string> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldCodes)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,kBAA0C;AAExD,2FADoC,CACT,QAAQ,UAAU,MAAM,UAAU"}
@@ -1,31 +0,0 @@
1
- //#region src/useHeldKeyCodes.d.ts
2
- /**
3
- * Preact hook that returns a map of currently held key names to their physical `event.code` values.
4
- *
5
- * This is useful for debugging which physical key was pressed (e.g. distinguishing
6
- * left vs right Shift via "ShiftLeft" / "ShiftRight").
7
- *
8
- * @returns Record mapping normalized key names to their `event.code` values
9
- *
10
- * @example
11
- * ```tsx
12
- * function KeyDebugDisplay() {
13
- * const heldKeys = useHeldKeys()
14
- * const heldCodes = useHeldKeyCodes()
15
- *
16
- * return (
17
- * <div>
18
- * {heldKeys.map((key) => (
19
- * <kbd key={key}>
20
- * {key} <small>{heldCodes[key]}</small>
21
- * </kbd>
22
- * ))}
23
- * </div>
24
- * )
25
- * }
26
- * ```
27
- */
28
- declare function useHeldKeyCodes(): Record<string, string>;
29
- //#endregion
30
- export { useHeldKeyCodes };
31
- //# sourceMappingURL=useHeldKeyCodes.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHeldKeyCodes.js","names":[],"sources":["../src/useHeldKeyCodes.ts"],"sourcesContent":["import { useSelector } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns a map of currently held key names to their physical `event.code` values.\n *\n * This is useful for debugging which physical key was pressed (e.g. distinguishing\n * left vs right Shift via \"ShiftLeft\" / \"ShiftRight\").\n *\n * @returns Record mapping normalized key names to their `event.code` values\n *\n * @example\n * ```tsx\n * function KeyDebugDisplay() {\n * const heldKeys = useHeldKeys()\n * const heldCodes = useHeldKeyCodes()\n *\n * return (\n * <div>\n * {heldKeys.map((key) => (\n * <kbd key={key}>\n * {key} <small>{heldCodes[key]}</small>\n * </kbd>\n * ))}\n * </div>\n * )\n * }\n * ```\n */\nexport function useHeldKeyCodes(): Record<string, string> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldCodes)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,kBAA0C;AAExD,QAAO,YADS,oBAAoB,CACT,QAAQ,UAAU,MAAM,UAAU"}
@@ -1,33 +0,0 @@
1
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
2
- let _tanstack_preact_store = require("@tanstack/preact-store");
3
-
4
- //#region src/useHeldKeys.ts
5
- /**
6
- * Preact hook that returns an array of currently held keyboard keys.
7
- *
8
- * This hook uses `useSelector` from `@tanstack/preact-store` to subscribe
9
- * to the global KeyStateTracker and updates whenever keys are pressed
10
- * or released.
11
- *
12
- * @returns Array of currently held key names
13
- *
14
- * @example
15
- * ```tsx
16
- * function KeyDisplay() {
17
- * const heldKeys = useHeldKeys()
18
- *
19
- * return (
20
- * <div>
21
- * Currently pressed: {heldKeys.join(' + ') || 'None'}
22
- * </div>
23
- * )
24
- * }
25
- * ```
26
- */
27
- function useHeldKeys() {
28
- return (0, _tanstack_preact_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
29
- }
30
-
31
- //#endregion
32
- exports.useHeldKeys = useHeldKeys;
33
- //# sourceMappingURL=useHeldKeys.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHeldKeys.cjs","names":[],"sources":["../src/useHeldKeys.ts"],"sourcesContent":["import { useSelector } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns an array of currently held keyboard keys.\n *\n * This hook uses `useSelector` from `@tanstack/preact-store` to subscribe\n * to the global KeyStateTracker and updates whenever keys are pressed\n * or released.\n *\n * @returns Array of currently held key names\n *\n * @example\n * ```tsx\n * function KeyDisplay() {\n * const heldKeys = useHeldKeys()\n *\n * return (\n * <div>\n * Currently pressed: {heldKeys.join(' + ') || 'None'}\n * </div>\n * )\n * }\n * ```\n */\nexport function useHeldKeys(): Array<string> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,cAA6B;AAE3C,2FADoC,CACT,QAAQ,UAAU,MAAM,SAAS"}
@@ -1,27 +0,0 @@
1
- //#region src/useHeldKeys.d.ts
2
- /**
3
- * Preact hook that returns an array of currently held keyboard keys.
4
- *
5
- * This hook uses `useSelector` from `@tanstack/preact-store` to subscribe
6
- * to the global KeyStateTracker and updates whenever keys are pressed
7
- * or released.
8
- *
9
- * @returns Array of currently held key names
10
- *
11
- * @example
12
- * ```tsx
13
- * function KeyDisplay() {
14
- * const heldKeys = useHeldKeys()
15
- *
16
- * return (
17
- * <div>
18
- * Currently pressed: {heldKeys.join(' + ') || 'None'}
19
- * </div>
20
- * )
21
- * }
22
- * ```
23
- */
24
- declare function useHeldKeys(): Array<string>;
25
- //#endregion
26
- export { useHeldKeys };
27
- //# sourceMappingURL=useHeldKeys.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHeldKeys.js","names":[],"sources":["../src/useHeldKeys.ts"],"sourcesContent":["import { useSelector } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns an array of currently held keyboard keys.\n *\n * This hook uses `useSelector` from `@tanstack/preact-store` to subscribe\n * to the global KeyStateTracker and updates whenever keys are pressed\n * or released.\n *\n * @returns Array of currently held key names\n *\n * @example\n * ```tsx\n * function KeyDisplay() {\n * const heldKeys = useHeldKeys()\n *\n * return (\n * <div>\n * Currently pressed: {heldKeys.join(' + ') || 'None'}\n * </div>\n * )\n * }\n * ```\n */\nexport function useHeldKeys(): Array<string> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,cAA6B;AAE3C,QAAO,YADS,oBAAoB,CACT,QAAQ,UAAU,MAAM,SAAS"}
@@ -1,121 +0,0 @@
1
- const require_HotkeysProvider = require('./HotkeysProvider.cjs');
2
- const require_utils = require('./utils.cjs');
3
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
4
- let preact_hooks = require("preact/hooks");
5
-
6
- //#region src/useHotkey.ts
7
- /**
8
- * Preact hook for registering a keyboard hotkey.
9
- *
10
- * Uses the singleton HotkeyManager for efficient event handling.
11
- * The callback receives both the keyboard event and a context object
12
- * containing the hotkey string and parsed hotkey.
13
- *
14
- * This hook syncs the callback and options on every render to avoid
15
- * stale closures. This means
16
- * callbacks that reference Preact state will always have access to
17
- * the latest values.
18
- *
19
- * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
20
- * @param callback - The function to call when the hotkey is pressed
21
- * @param options - Options for the hotkey behavior. `enabled: false` keeps the registration (visible in devtools)
22
- * and only suppresses firing; the hook updates the existing handle instead of unregistering.
23
- *
24
- * @example
25
- * ```tsx
26
- * function SaveButton() {
27
- * const [count, setCount] = useState(0)
28
- *
29
- * // Callback always has access to latest count value
30
- * useHotkey('Mod+S', (event, { hotkey }) => {
31
- * console.log(`Save triggered, count is ${count}`)
32
- * handleSave()
33
- * })
34
- *
35
- * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
36
- * }
37
- * ```
38
- *
39
- * @example
40
- * ```tsx
41
- * function Modal({ isOpen, onClose }) {
42
- * // enabled option is synced on every render
43
- * useHotkey('Escape', () => {
44
- * onClose()
45
- * }, { enabled: isOpen })
46
- *
47
- * if (!isOpen) return null
48
- * return <div className="modal">...</div>
49
- * }
50
- * ```
51
- *
52
- * @example
53
- * ```tsx
54
- * function Editor() {
55
- * const editorRef = useRef<HTMLDivElement>(null)
56
- *
57
- * // Scoped to a specific element
58
- * useHotkey('Mod+S', () => {
59
- * save()
60
- * }, { target: editorRef })
61
- *
62
- * return <div ref={editorRef}>...</div>
63
- * }
64
- * ```
65
- */
66
- function useHotkey(hotkey, callback, options = {}) {
67
- const mergedOptions = {
68
- ...require_HotkeysProvider.useDefaultHotkeysOptions().hotkey,
69
- ...options
70
- };
71
- const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
72
- const registrationRef = (0, preact_hooks.useRef)(null);
73
- const callbackRef = (0, preact_hooks.useRef)(callback);
74
- const optionsRef = (0, preact_hooks.useRef)(mergedOptions);
75
- const managerRef = (0, preact_hooks.useRef)(manager);
76
- callbackRef.current = callback;
77
- optionsRef.current = mergedOptions;
78
- managerRef.current = manager;
79
- const prevTargetRef = (0, preact_hooks.useRef)(null);
80
- const prevHotkeyRef = (0, preact_hooks.useRef)(null);
81
- const hotkeyString = (0, _tanstack_hotkeys.normalizeRegisterableHotkey)(hotkey, mergedOptions.platform ?? (0, _tanstack_hotkeys.detectPlatform)());
82
- const { target: _target, ...optionsWithoutTarget } = mergedOptions;
83
- (0, preact_hooks.useEffect)(() => {
84
- const resolvedTarget = require_utils.isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
85
- if (!resolvedTarget) {
86
- if (registrationRef.current?.isActive) {
87
- registrationRef.current.unregister();
88
- registrationRef.current = null;
89
- }
90
- prevTargetRef.current = null;
91
- prevHotkeyRef.current = null;
92
- return;
93
- }
94
- const targetChanged = prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget;
95
- const hotkeyChanged = prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString;
96
- if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {
97
- registrationRef.current.unregister();
98
- registrationRef.current = null;
99
- }
100
- if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(hotkeyString, callbackRef.current, {
101
- ...optionsRef.current,
102
- target: resolvedTarget
103
- });
104
- prevTargetRef.current = resolvedTarget;
105
- prevHotkeyRef.current = hotkeyString;
106
- return () => {
107
- if (registrationRef.current?.isActive) {
108
- registrationRef.current.unregister();
109
- registrationRef.current = null;
110
- }
111
- };
112
- }, [hotkeyString]);
113
- if (registrationRef.current?.isActive) {
114
- registrationRef.current.callback = callback;
115
- registrationRef.current.setOptions(optionsWithoutTarget);
116
- }
117
- }
118
-
119
- //#endregion
120
- exports.useHotkey = useHotkey;
121
- //# sourceMappingURL=useHotkey.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHotkey.cjs","names":["useDefaultHotkeysOptions","isRef"],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'preact/hooks'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type { RefObject } from 'preact'\nimport type {\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a Preact ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * Preact hook 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 hook syncs the callback and options on every render to avoid\n * stale closures. This means\n * callbacks that reference Preact state will always have access to\n * the latest values.\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. `enabled: false` keeps the registration (visible in devtools)\n * and only suppresses firing; the hook updates the existing handle instead of unregistering.\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = useState(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('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({ isOpen, onClose }) {\n * // enabled option is synced on every render\n * useHotkey('Escape', () => {\n * onClose()\n * }, { enabled: isOpen })\n *\n * if (!isOpen) return null\n * return <div className=\"modal\">...</div>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const editorRef = useRef<HTMLDivElement>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n *\n * return <div ref={editorRef}>...</div>\n * }\n * ```\n */\nexport function useHotkey(\n hotkey: RegisterableHotkey,\n callback: HotkeyCallback,\n options: UseHotkeyOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkey,\n ...options,\n } as UseHotkeyOptions\n\n const manager = getHotkeyManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<HotkeyRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and hotkey to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevHotkeyRef = useRef<string | null>(null)\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(hotkey, platform)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n prevTargetRef.current = null\n prevHotkeyRef.current = null\n return\n }\n\n // Check if we need to re-register (target or hotkey changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const hotkeyChanged =\n prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString\n\n // If we have an active registration and target/hotkey changed, unregister first\n if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n // Use refs to access current values without adding them to dependencies\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n hotkeyString,\n callbackRef.current,\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevHotkeyRef.current = hotkeyString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeyString])\n\n // Sync callback and options on EVERY render (outside useEffect)\n // This avoids stale closures - the callback always has access to latest state\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = callback\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,UACd,QACA,UACA,UAA4B,EAAE,EACxB;CACN,MAAM,gBAAgB;EACpB,GAAGA,kDAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,mDAA4B;CAGlC,MAAM,2CAA0D,KAAK;CAGrE,MAAM,uCAAqB,SAAS;CACpC,MAAM,sCAAoB,cAAc;CACxC,MAAM,sCAAoB,QAAQ;AAGlC,aAAY,UAAU;AACtB,YAAW,UAAU;AACrB,YAAW,UAAU;CAGrB,MAAM,yCAA+D,KAAK;CAC1E,MAAM,yCAAsC,KAAK;CAIjD,MAAM,kEAA2C,QADhC,cAAc,mDAA4B,CACO;CAGlE,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,mCAAgB;EAEd,MAAM,iBAAiBC,oBAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,gBAAgB;AACnB,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;AAE5B,iBAAc,UAAU;AACxB,iBAAc,UAAU;AACxB;;EAIF,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;EAC9D,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;AAG9D,MAAI,gBAAgB,SAAS,aAAa,iBAAiB,gBAAgB;AACzE,mBAAgB,QAAQ,YAAY;AACpC,mBAAgB,UAAU;;AAK5B,MAAI,CAAC,gBAAgB,WAAW,CAAC,gBAAgB,QAAQ,SACvD,iBAAgB,UAAU,WAAW,QAAQ,SAC3C,cACA,YAAY,SACZ;GACE,GAAG,WAAW;GACd,QAAQ;GACT,CACF;AAIH,gBAAc,UAAU;AACxB,gBAAc,UAAU;AAGxB,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,CAAC,aAAa,CAAC;AAIlB,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,WAAW;AACnC,kBAAgB,QAAQ,WAAW,qBAAqB"}
@@ -1,75 +0,0 @@
1
- import { HotkeyCallback, HotkeyOptions, RegisterableHotkey } from "@tanstack/hotkeys";
2
- import { RefObject } from "preact";
3
-
4
- //#region src/useHotkey.d.ts
5
- interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
6
- /**
7
- * The DOM element to attach the event listener to.
8
- * Can be a Preact ref, direct DOM element, or null.
9
- * Defaults to document.
10
- */
11
- target?: RefObject<HTMLElement | null> | HTMLElement | Document | Window | null;
12
- }
13
- /**
14
- * Preact hook for registering a keyboard hotkey.
15
- *
16
- * Uses the singleton HotkeyManager for efficient event handling.
17
- * The callback receives both the keyboard event and a context object
18
- * containing the hotkey string and parsed hotkey.
19
- *
20
- * This hook syncs the callback and options on every render to avoid
21
- * stale closures. This means
22
- * callbacks that reference Preact state will always have access to
23
- * the latest values.
24
- *
25
- * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
26
- * @param callback - The function to call when the hotkey is pressed
27
- * @param options - Options for the hotkey behavior. `enabled: false` keeps the registration (visible in devtools)
28
- * and only suppresses firing; the hook updates the existing handle instead of unregistering.
29
- *
30
- * @example
31
- * ```tsx
32
- * function SaveButton() {
33
- * const [count, setCount] = useState(0)
34
- *
35
- * // Callback always has access to latest count value
36
- * useHotkey('Mod+S', (event, { hotkey }) => {
37
- * console.log(`Save triggered, count is ${count}`)
38
- * handleSave()
39
- * })
40
- *
41
- * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
42
- * }
43
- * ```
44
- *
45
- * @example
46
- * ```tsx
47
- * function Modal({ isOpen, onClose }) {
48
- * // enabled option is synced on every render
49
- * useHotkey('Escape', () => {
50
- * onClose()
51
- * }, { enabled: isOpen })
52
- *
53
- * if (!isOpen) return null
54
- * return <div className="modal">...</div>
55
- * }
56
- * ```
57
- *
58
- * @example
59
- * ```tsx
60
- * function Editor() {
61
- * const editorRef = useRef<HTMLDivElement>(null)
62
- *
63
- * // Scoped to a specific element
64
- * useHotkey('Mod+S', () => {
65
- * save()
66
- * }, { target: editorRef })
67
- *
68
- * return <div ref={editorRef}>...</div>
69
- * }
70
- * ```
71
- */
72
- declare function useHotkey(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: UseHotkeyOptions): void;
73
- //#endregion
74
- export { UseHotkeyOptions, useHotkey };
75
- //# sourceMappingURL=useHotkey.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHotkey.js","names":[],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'preact/hooks'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport { isRef } from './utils'\nimport type { RefObject } from 'preact'\nimport type {\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\nexport interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {\n /**\n * The DOM element to attach the event listener to.\n * Can be a Preact ref, direct DOM element, or null.\n * Defaults to document.\n */\n target?:\n | RefObject<HTMLElement | null>\n | HTMLElement\n | Document\n | Window\n | null\n}\n\n/**\n * Preact hook 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 hook syncs the callback and options on every render to avoid\n * stale closures. This means\n * callbacks that reference Preact state will always have access to\n * the latest values.\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. `enabled: false` keeps the registration (visible in devtools)\n * and only suppresses firing; the hook updates the existing handle instead of unregistering.\n *\n * @example\n * ```tsx\n * function SaveButton() {\n * const [count, setCount] = useState(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('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({ isOpen, onClose }) {\n * // enabled option is synced on every render\n * useHotkey('Escape', () => {\n * onClose()\n * }, { enabled: isOpen })\n *\n * if (!isOpen) return null\n * return <div className=\"modal\">...</div>\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Editor() {\n * const editorRef = useRef<HTMLDivElement>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n *\n * return <div ref={editorRef}>...</div>\n * }\n * ```\n */\nexport function useHotkey(\n hotkey: RegisterableHotkey,\n callback: HotkeyCallback,\n options: UseHotkeyOptions = {},\n): void {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkey,\n ...options,\n } as UseHotkeyOptions\n\n const manager = getHotkeyManager()\n\n // Stable ref for registration handle\n const registrationRef = useRef<HotkeyRegistrationHandle | null>(null)\n\n // Refs to capture current values for use in effect without adding dependencies\n const callbackRef = useRef(callback)\n const optionsRef = useRef(mergedOptions)\n const managerRef = useRef(manager)\n\n // Update refs on every render\n callbackRef.current = callback\n optionsRef.current = mergedOptions\n managerRef.current = manager\n\n // Track previous target and hotkey to detect changes requiring re-registration\n const prevTargetRef = useRef<HTMLElement | Document | Window | null>(null)\n const prevHotkeyRef = useRef<string | null>(null)\n\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(hotkey, platform)\n\n // Extract options without target (target is handled separately)\n const { target: _target, ...optionsWithoutTarget } = mergedOptions\n\n useEffect(() => {\n // Resolve target inside the effect so refs are already attached after mount\n const resolvedTarget = isRef(optionsRef.current.target)\n ? optionsRef.current.target.current\n : (optionsRef.current.target ??\n (typeof document !== 'undefined' ? document : null))\n\n // Skip if no valid target (SSR or ref still null)\n if (!resolvedTarget) {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n prevTargetRef.current = null\n prevHotkeyRef.current = null\n return\n }\n\n // Check if we need to re-register (target or hotkey changed)\n const targetChanged =\n prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget\n const hotkeyChanged =\n prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString\n\n // If we have an active registration and target/hotkey changed, unregister first\n if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n\n // Register if needed (no active registration)\n // Use refs to access current values without adding them to dependencies\n if (!registrationRef.current || !registrationRef.current.isActive) {\n registrationRef.current = managerRef.current.register(\n hotkeyString,\n callbackRef.current,\n {\n ...optionsRef.current,\n target: resolvedTarget,\n },\n )\n }\n\n // Update tracking refs\n prevTargetRef.current = resolvedTarget\n prevHotkeyRef.current = hotkeyString\n\n // Cleanup on unmount\n return () => {\n if (registrationRef.current?.isActive) {\n registrationRef.current.unregister()\n registrationRef.current = null\n }\n }\n }, [hotkeyString])\n\n // Sync callback and options on EVERY render (outside useEffect)\n // This avoids stale closures - the callback always has access to latest state\n if (registrationRef.current?.isActive) {\n registrationRef.current.callback = callback\n registrationRef.current.setOptions(optionsWithoutTarget)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,UACd,QACA,UACA,UAA4B,EAAE,EACxB;CACN,MAAM,gBAAgB;EACpB,GAAG,0BAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,UAAU,kBAAkB;CAGlC,MAAM,kBAAkB,OAAwC,KAAK;CAGrE,MAAM,cAAc,OAAO,SAAS;CACpC,MAAM,aAAa,OAAO,cAAc;CACxC,MAAM,aAAa,OAAO,QAAQ;AAGlC,aAAY,UAAU;AACtB,YAAW,UAAU;AACrB,YAAW,UAAU;CAGrB,MAAM,gBAAgB,OAA+C,KAAK;CAC1E,MAAM,gBAAgB,OAAsB,KAAK;CAIjD,MAAM,eAAe,4BAA4B,QADhC,cAAc,YAAY,gBAAgB,CACO;CAGlE,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,iBAAgB;EAEd,MAAM,iBAAiB,MAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,gBAAgB;AACnB,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;AAE5B,iBAAc,UAAU;AACxB,iBAAc,UAAU;AACxB;;EAIF,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;EAC9D,MAAM,gBACJ,cAAc,YAAY,QAAQ,cAAc,YAAY;AAG9D,MAAI,gBAAgB,SAAS,aAAa,iBAAiB,gBAAgB;AACzE,mBAAgB,QAAQ,YAAY;AACpC,mBAAgB,UAAU;;AAK5B,MAAI,CAAC,gBAAgB,WAAW,CAAC,gBAAgB,QAAQ,SACvD,iBAAgB,UAAU,WAAW,QAAQ,SAC3C,cACA,YAAY,SACZ;GACE,GAAG,WAAW;GACd,QAAQ;GACT,CACF;AAIH,gBAAc,UAAU;AACxB,gBAAc,UAAU;AAGxB,eAAa;AACX,OAAI,gBAAgB,SAAS,UAAU;AACrC,oBAAgB,QAAQ,YAAY;AACpC,oBAAgB,UAAU;;;IAG7B,CAAC,aAAa,CAAC;AAIlB,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,WAAW;AACnC,kBAAgB,QAAQ,WAAW,qBAAqB"}
@@ -1,71 +0,0 @@
1
- const require_HotkeysProvider = require('./HotkeysProvider.cjs');
2
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
3
- let preact_hooks = require("preact/hooks");
4
- let _tanstack_preact_store = require("@tanstack/preact-store");
5
-
6
- //#region src/useHotkeyRecorder.ts
7
- /**
8
- * Preact hook for recording keyboard shortcuts.
9
- *
10
- * This hook provides a thin wrapper around the framework-agnostic `HotkeyRecorder`
11
- * class, managing all the complexity of capturing keyboard events, converting them
12
- * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete
13
- * to clear.
14
- *
15
- * @param options - Configuration options for the recorder
16
- * @returns An object with recording state and control functions
17
- *
18
- * @example
19
- * ```tsx
20
- * function ShortcutSettings() {
21
- * const [shortcut, setShortcut] = useState<Hotkey>('Mod+S')
22
- *
23
- * const recorder = useHotkeyRecorder({
24
- * onRecord: (hotkey) => {
25
- * setShortcut(hotkey)
26
- * },
27
- * onCancel: () => {
28
- * console.log('Recording cancelled')
29
- * },
30
- * })
31
- *
32
- * return (
33
- * <div>
34
- * <button onClick={recorder.startRecording}>
35
- * {recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
36
- * </button>
37
- * {recorder.recordedHotkey && (
38
- * <div>Recording: {recorder.recordedHotkey}</div>
39
- * )}
40
- * </div>
41
- * )
42
- * }
43
- * ```
44
- */
45
- function useHotkeyRecorder(options) {
46
- const mergedOptions = {
47
- ...require_HotkeysProvider.useDefaultHotkeysOptions().hotkeyRecorder,
48
- ...options
49
- };
50
- const recorderRef = (0, preact_hooks.useRef)(null);
51
- if (!recorderRef.current) recorderRef.current = new _tanstack_hotkeys.HotkeyRecorder(mergedOptions);
52
- recorderRef.current.setOptions(mergedOptions);
53
- const isRecording = (0, _tanstack_preact_store.useSelector)(recorderRef.current.store, (state) => state.isRecording);
54
- const recordedHotkey = (0, _tanstack_preact_store.useSelector)(recorderRef.current.store, (state) => state.recordedHotkey);
55
- (0, preact_hooks.useEffect)(() => {
56
- return () => {
57
- recorderRef.current?.destroy();
58
- };
59
- }, []);
60
- return {
61
- isRecording,
62
- recordedHotkey,
63
- startRecording: () => recorderRef.current?.start(),
64
- stopRecording: () => recorderRef.current?.stop(),
65
- cancelRecording: () => recorderRef.current?.cancel()
66
- };
67
- }
68
-
69
- //#endregion
70
- exports.useHotkeyRecorder = useHotkeyRecorder;
71
- //# sourceMappingURL=useHotkeyRecorder.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHotkeyRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeyRecorder"],"sources":["../src/useHotkeyRecorder.ts"],"sourcesContent":["import { useEffect, useRef } from 'preact/hooks'\nimport { useSelector } from '@tanstack/preact-store'\nimport { HotkeyRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\nexport interface PreactHotkeyRecorder {\n /** Whether recording is currently active */\n isRecording: boolean\n /** The currently recorded hotkey (for live preview) */\n recordedHotkey: Hotkey | null\n /** Start recording a new hotkey */\n startRecording: () => void\n /** Stop recording (same as cancel) */\n stopRecording: () => void\n /** Cancel recording without saving */\n cancelRecording: () => void\n}\n\n/**\n * Preact hook for recording keyboard shortcuts.\n *\n * This hook provides a thin wrapper around the framework-agnostic `HotkeyRecorder`\n * class, managing all the complexity of capturing keyboard events, converting them\n * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete\n * to clear.\n *\n * @param options - Configuration options for the recorder\n * @returns An object with recording state and control functions\n *\n * @example\n * ```tsx\n * function ShortcutSettings() {\n * const [shortcut, setShortcut] = useState<Hotkey>('Mod+S')\n *\n * const recorder = useHotkeyRecorder({\n * onRecord: (hotkey) => {\n * setShortcut(hotkey)\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * return (\n * <div>\n * <button onClick={recorder.startRecording}>\n * {recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}\n * </button>\n * {recorder.recordedHotkey && (\n * <div>Recording: {recorder.recordedHotkey}</div>\n * )}\n * </div>\n * )\n * }\n * ```\n */\nexport function useHotkeyRecorder(\n options: HotkeyRecorderOptions,\n): PreactHotkeyRecorder {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeyRecorder,\n ...options,\n } as HotkeyRecorderOptions\n\n const recorderRef = useRef<HotkeyRecorder | null>(null)\n\n // Create recorder instance once\n if (!recorderRef.current) {\n recorderRef.current = new HotkeyRecorder(mergedOptions)\n }\n\n // Sync options on every render (same pattern as useHotkey)\n // This ensures callbacks always have access to latest values\n recorderRef.current.setOptions(mergedOptions)\n\n // Subscribe to recorder state using useSelector (same pattern as useHeldKeys)\n const isRecording = useSelector(\n recorderRef.current.store,\n (state) => state.isRecording,\n )\n const recordedHotkey = useSelector(\n recorderRef.current.store,\n (state) => state.recordedHotkey,\n )\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n recorderRef.current?.destroy()\n }\n }, [])\n\n return {\n isRecording,\n recordedHotkey,\n startRecording: () => recorderRef.current?.start(),\n stopRecording: () => recorderRef.current?.stop(),\n cancelRecording: () => recorderRef.current?.cancel(),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,kBACd,SACsB;CACtB,MAAM,gBAAgB;EACpB,GAAGA,kDAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,uCAA4C,KAAK;AAGvD,KAAI,CAAC,YAAY,QACf,aAAY,UAAU,IAAIC,iCAAe,cAAc;AAKzD,aAAY,QAAQ,WAAW,cAAc;CAG7C,MAAM,sDACJ,YAAY,QAAQ,QACnB,UAAU,MAAM,YAClB;CACD,MAAM,yDACJ,YAAY,QAAQ,QACnB,UAAU,MAAM,eAClB;AAGD,mCAAgB;AACd,eAAa;AACX,eAAY,SAAS,SAAS;;IAE/B,EAAE,CAAC;AAEN,QAAO;EACL;EACA;EACA,sBAAsB,YAAY,SAAS,OAAO;EAClD,qBAAqB,YAAY,SAAS,MAAM;EAChD,uBAAuB,YAAY,SAAS,QAAQ;EACrD"}
@@ -1,57 +0,0 @@
1
- import { Hotkey, HotkeyRecorderOptions } from "@tanstack/hotkeys";
2
-
3
- //#region src/useHotkeyRecorder.d.ts
4
- interface PreactHotkeyRecorder {
5
- /** Whether recording is currently active */
6
- isRecording: boolean;
7
- /** The currently recorded hotkey (for live preview) */
8
- recordedHotkey: Hotkey | null;
9
- /** Start recording a new hotkey */
10
- startRecording: () => void;
11
- /** Stop recording (same as cancel) */
12
- stopRecording: () => void;
13
- /** Cancel recording without saving */
14
- cancelRecording: () => void;
15
- }
16
- /**
17
- * Preact hook for recording keyboard shortcuts.
18
- *
19
- * This hook provides a thin wrapper around the framework-agnostic `HotkeyRecorder`
20
- * class, managing all the complexity of capturing keyboard events, converting them
21
- * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete
22
- * to clear.
23
- *
24
- * @param options - Configuration options for the recorder
25
- * @returns An object with recording state and control functions
26
- *
27
- * @example
28
- * ```tsx
29
- * function ShortcutSettings() {
30
- * const [shortcut, setShortcut] = useState<Hotkey>('Mod+S')
31
- *
32
- * const recorder = useHotkeyRecorder({
33
- * onRecord: (hotkey) => {
34
- * setShortcut(hotkey)
35
- * },
36
- * onCancel: () => {
37
- * console.log('Recording cancelled')
38
- * },
39
- * })
40
- *
41
- * return (
42
- * <div>
43
- * <button onClick={recorder.startRecording}>
44
- * {recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
45
- * </button>
46
- * {recorder.recordedHotkey && (
47
- * <div>Recording: {recorder.recordedHotkey}</div>
48
- * )}
49
- * </div>
50
- * )
51
- * }
52
- * ```
53
- */
54
- declare function useHotkeyRecorder(options: HotkeyRecorderOptions): PreactHotkeyRecorder;
55
- //#endregion
56
- export { PreactHotkeyRecorder, useHotkeyRecorder };
57
- //# sourceMappingURL=useHotkeyRecorder.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHotkeyRecorder.js","names":[],"sources":["../src/useHotkeyRecorder.ts"],"sourcesContent":["import { useEffect, useRef } from 'preact/hooks'\nimport { useSelector } from '@tanstack/preact-store'\nimport { HotkeyRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\nexport interface PreactHotkeyRecorder {\n /** Whether recording is currently active */\n isRecording: boolean\n /** The currently recorded hotkey (for live preview) */\n recordedHotkey: Hotkey | null\n /** Start recording a new hotkey */\n startRecording: () => void\n /** Stop recording (same as cancel) */\n stopRecording: () => void\n /** Cancel recording without saving */\n cancelRecording: () => void\n}\n\n/**\n * Preact hook for recording keyboard shortcuts.\n *\n * This hook provides a thin wrapper around the framework-agnostic `HotkeyRecorder`\n * class, managing all the complexity of capturing keyboard events, converting them\n * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete\n * to clear.\n *\n * @param options - Configuration options for the recorder\n * @returns An object with recording state and control functions\n *\n * @example\n * ```tsx\n * function ShortcutSettings() {\n * const [shortcut, setShortcut] = useState<Hotkey>('Mod+S')\n *\n * const recorder = useHotkeyRecorder({\n * onRecord: (hotkey) => {\n * setShortcut(hotkey)\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * return (\n * <div>\n * <button onClick={recorder.startRecording}>\n * {recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}\n * </button>\n * {recorder.recordedHotkey && (\n * <div>Recording: {recorder.recordedHotkey}</div>\n * )}\n * </div>\n * )\n * }\n * ```\n */\nexport function useHotkeyRecorder(\n options: HotkeyRecorderOptions,\n): PreactHotkeyRecorder {\n const mergedOptions = {\n ...useDefaultHotkeysOptions().hotkeyRecorder,\n ...options,\n } as HotkeyRecorderOptions\n\n const recorderRef = useRef<HotkeyRecorder | null>(null)\n\n // Create recorder instance once\n if (!recorderRef.current) {\n recorderRef.current = new HotkeyRecorder(mergedOptions)\n }\n\n // Sync options on every render (same pattern as useHotkey)\n // This ensures callbacks always have access to latest values\n recorderRef.current.setOptions(mergedOptions)\n\n // Subscribe to recorder state using useSelector (same pattern as useHeldKeys)\n const isRecording = useSelector(\n recorderRef.current.store,\n (state) => state.isRecording,\n )\n const recordedHotkey = useSelector(\n recorderRef.current.store,\n (state) => state.recordedHotkey,\n )\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n recorderRef.current?.destroy()\n }\n }, [])\n\n return {\n isRecording,\n recordedHotkey,\n startRecording: () => recorderRef.current?.start(),\n stopRecording: () => recorderRef.current?.stop(),\n cancelRecording: () => recorderRef.current?.cancel(),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,kBACd,SACsB;CACtB,MAAM,gBAAgB;EACpB,GAAG,0BAA0B,CAAC;EAC9B,GAAG;EACJ;CAED,MAAM,cAAc,OAA8B,KAAK;AAGvD,KAAI,CAAC,YAAY,QACf,aAAY,UAAU,IAAI,eAAe,cAAc;AAKzD,aAAY,QAAQ,WAAW,cAAc;CAG7C,MAAM,cAAc,YAClB,YAAY,QAAQ,QACnB,UAAU,MAAM,YAClB;CACD,MAAM,iBAAiB,YACrB,YAAY,QAAQ,QACnB,UAAU,MAAM,eAClB;AAGD,iBAAgB;AACd,eAAa;AACX,eAAY,SAAS,SAAS;;IAE/B,EAAE,CAAC;AAEN,QAAO;EACL;EACA;EACA,sBAAsB,YAAY,SAAS,OAAO;EAClD,qBAAqB,YAAY,SAAS,MAAM;EAChD,uBAAuB,YAAY,SAAS,QAAQ;EACrD"}
@@ -1,26 +0,0 @@
1
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
2
- let _tanstack_preact_store = require("@tanstack/preact-store");
3
-
4
- //#region src/useHotkeyRegistrations.ts
5
- /**
6
- * Preact hook that reactively reads all hotkey and sequence registrations
7
- * from the singleton managers.
8
- *
9
- * This is a standalone hook that does NOT require the HotkeysProvider.
10
- * It subscribes to both HotkeyManager and SequenceManager stores and
11
- * re-renders when registrations change.
12
- *
13
- * @returns Object with `hotkeys` and `sequences` arrays
14
- */
15
- function useHotkeyRegistrations() {
16
- const hotkeyManager = (0, _tanstack_hotkeys.getHotkeyManager)();
17
- const sequenceManager = (0, _tanstack_hotkeys.getSequenceManager)();
18
- return {
19
- hotkeys: (0, _tanstack_preact_store.useSelector)(hotkeyManager.registrations, (state) => Array.from(state.values()).map(_tanstack_hotkeys.toHotkeyRegistrationView)),
20
- sequences: (0, _tanstack_preact_store.useSelector)(sequenceManager.registrations, (state) => Array.from(state.values()))
21
- };
22
- }
23
-
24
- //#endregion
25
- exports.useHotkeyRegistrations = useHotkeyRegistrations;
26
- //# sourceMappingURL=useHotkeyRegistrations.cjs.map