@tanstack/preact-hotkeys 0.3.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 (56) hide show
  1. package/README.md +122 -0
  2. package/dist/HotkeysProvider.cjs +26 -0
  3. package/dist/HotkeysProvider.cjs.map +1 -0
  4. package/dist/HotkeysProvider.d.cts +28 -0
  5. package/dist/HotkeysProvider.d.ts +28 -0
  6. package/dist/HotkeysProvider.js +24 -0
  7. package/dist/HotkeysProvider.js.map +1 -0
  8. package/dist/index.cjs +25 -0
  9. package/dist/index.d.cts +9 -0
  10. package/dist/index.d.ts +9 -0
  11. package/dist/index.js +11 -0
  12. package/dist/useHeldKeyCodes.cjs +37 -0
  13. package/dist/useHeldKeyCodes.cjs.map +1 -0
  14. package/dist/useHeldKeyCodes.d.cts +31 -0
  15. package/dist/useHeldKeyCodes.d.ts +31 -0
  16. package/dist/useHeldKeyCodes.js +37 -0
  17. package/dist/useHeldKeyCodes.js.map +1 -0
  18. package/dist/useHeldKeys.cjs +33 -0
  19. package/dist/useHeldKeys.cjs.map +1 -0
  20. package/dist/useHeldKeys.d.cts +27 -0
  21. package/dist/useHeldKeys.d.ts +27 -0
  22. package/dist/useHeldKeys.js +33 -0
  23. package/dist/useHeldKeys.js.map +1 -0
  24. package/dist/useHotkey.cjs +118 -0
  25. package/dist/useHotkey.cjs.map +1 -0
  26. package/dist/useHotkey.d.cts +74 -0
  27. package/dist/useHotkey.d.ts +74 -0
  28. package/dist/useHotkey.js +118 -0
  29. package/dist/useHotkey.js.map +1 -0
  30. package/dist/useHotkeyRecorder.cjs +71 -0
  31. package/dist/useHotkeyRecorder.cjs.map +1 -0
  32. package/dist/useHotkeyRecorder.d.cts +57 -0
  33. package/dist/useHotkeyRecorder.d.ts +57 -0
  34. package/dist/useHotkeyRecorder.js +71 -0
  35. package/dist/useHotkeyRecorder.js.map +1 -0
  36. package/dist/useHotkeySequence.cjs +96 -0
  37. package/dist/useHotkeySequence.cjs.map +1 -0
  38. package/dist/useHotkeySequence.d.cts +48 -0
  39. package/dist/useHotkeySequence.d.ts +48 -0
  40. package/dist/useHotkeySequence.js +96 -0
  41. package/dist/useHotkeySequence.js.map +1 -0
  42. package/dist/useKeyHold.cjs +53 -0
  43. package/dist/useKeyHold.cjs.map +1 -0
  44. package/dist/useKeyHold.d.cts +47 -0
  45. package/dist/useKeyHold.d.ts +47 -0
  46. package/dist/useKeyHold.js +53 -0
  47. package/dist/useKeyHold.js.map +1 -0
  48. package/package.json +63 -0
  49. package/src/HotkeysProvider.tsx +52 -0
  50. package/src/index.ts +13 -0
  51. package/src/useHeldKeyCodes.ts +33 -0
  52. package/src/useHeldKeys.ts +29 -0
  53. package/src/useHotkey.ts +192 -0
  54. package/src/useHotkeyRecorder.ts +101 -0
  55. package/src/useHotkeySequence.ts +169 -0
  56. package/src/useKeyHold.ts +52 -0
@@ -0,0 +1,118 @@
1
+ const require_HotkeysProvider = require('./HotkeysProvider.cjs');
2
+ let _tanstack_hotkeys = require("@tanstack/hotkeys");
3
+ let preact_hooks = require("preact/hooks");
4
+
5
+ //#region src/useHotkey.ts
6
+ /**
7
+ * Preact hook for registering a keyboard hotkey.
8
+ *
9
+ * Uses the singleton HotkeyManager for efficient event handling.
10
+ * The callback receives both the keyboard event and a context object
11
+ * containing the hotkey string and parsed hotkey.
12
+ *
13
+ * This hook syncs the callback and options on every render to avoid
14
+ * stale closures. This means
15
+ * callbacks that reference Preact state will always have access to
16
+ * the latest values.
17
+ *
18
+ * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
19
+ * @param callback - The function to call when the hotkey is pressed
20
+ * @param options - Options for the hotkey behavior
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * function SaveButton() {
25
+ * const [count, setCount] = useState(0)
26
+ *
27
+ * // Callback always has access to latest count value
28
+ * useHotkey('Mod+S', (event, { hotkey }) => {
29
+ * console.log(`Save triggered, count is ${count}`)
30
+ * handleSave()
31
+ * })
32
+ *
33
+ * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
34
+ * }
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * function Modal({ isOpen, onClose }) {
40
+ * // enabled option is synced on every render
41
+ * useHotkey('Escape', () => {
42
+ * onClose()
43
+ * }, { enabled: isOpen })
44
+ *
45
+ * if (!isOpen) return null
46
+ * return <div className="modal">...</div>
47
+ * }
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * function Editor() {
53
+ * const editorRef = useRef<HTMLDivElement>(null)
54
+ *
55
+ * // Scoped to a specific element
56
+ * useHotkey('Mod+S', () => {
57
+ * save()
58
+ * }, { target: editorRef })
59
+ *
60
+ * return <div ref={editorRef}>...</div>
61
+ * }
62
+ * ```
63
+ */
64
+ function useHotkey(hotkey, callback, options = {}) {
65
+ const mergedOptions = {
66
+ ...require_HotkeysProvider.useDefaultHotkeysOptions().hotkey,
67
+ ...options
68
+ };
69
+ const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
70
+ const registrationRef = (0, preact_hooks.useRef)(null);
71
+ const callbackRef = (0, preact_hooks.useRef)(callback);
72
+ const optionsRef = (0, preact_hooks.useRef)(mergedOptions);
73
+ const managerRef = (0, preact_hooks.useRef)(manager);
74
+ callbackRef.current = callback;
75
+ optionsRef.current = mergedOptions;
76
+ managerRef.current = manager;
77
+ const prevTargetRef = (0, preact_hooks.useRef)(null);
78
+ const prevHotkeyRef = (0, preact_hooks.useRef)(null);
79
+ const platform = mergedOptions.platform ?? (0, _tanstack_hotkeys.detectPlatform)();
80
+ const hotkeyString = typeof hotkey === "string" ? hotkey : (0, _tanstack_hotkeys.formatHotkey)((0, _tanstack_hotkeys.rawHotkeyToParsedHotkey)(hotkey, platform));
81
+ const { target: _target, ...optionsWithoutTarget } = mergedOptions;
82
+ (0, preact_hooks.useEffect)(() => {
83
+ const resolvedTarget = isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
84
+ if (!resolvedTarget) return;
85
+ const targetChanged = prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget;
86
+ const hotkeyChanged = prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString;
87
+ if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {
88
+ registrationRef.current.unregister();
89
+ registrationRef.current = null;
90
+ }
91
+ if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(hotkeyString, callbackRef.current, {
92
+ ...optionsRef.current,
93
+ target: resolvedTarget
94
+ });
95
+ prevTargetRef.current = resolvedTarget;
96
+ prevHotkeyRef.current = hotkeyString;
97
+ return () => {
98
+ if (registrationRef.current?.isActive) {
99
+ registrationRef.current.unregister();
100
+ registrationRef.current = null;
101
+ }
102
+ };
103
+ }, [hotkeyString, options.enabled]);
104
+ if (registrationRef.current?.isActive) {
105
+ registrationRef.current.callback = callback;
106
+ registrationRef.current.setOptions(optionsWithoutTarget);
107
+ }
108
+ }
109
+ /**
110
+ * Type guard to check if a value is a Preact ref-like object.
111
+ */
112
+ function isRef(value) {
113
+ return value !== null && typeof value === "object" && "current" in value;
114
+ }
115
+
116
+ //#endregion
117
+ exports.useHotkey = useHotkey;
118
+ //# sourceMappingURL=useHotkey.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHotkey.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'preact/hooks'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { RefObject } from 'preact'\nimport type {\n Hotkey,\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\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: Hotkey =\n typeof hotkey === 'string'\n ? hotkey\n : (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)\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 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, options.enabled])\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\n/**\n * Type guard to check if a value is a Preact ref-like object.\n */\nfunction isRef(value: unknown): value is RefObject<HTMLElement | null> {\n return value !== null && typeof value === 'object' && 'current' in value\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;CAGjD,MAAM,WAAW,cAAc,mDAA4B;CAC3D,MAAM,eACJ,OAAO,WAAW,WACd,4FACsC,QAAQ,SAAS,CAAC;CAG9D,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB;AAErD,mCAAgB;EAEd,MAAM,iBAAiB,MAAM,WAAW,QAAQ,OAAO,GACnD,WAAW,QAAQ,OAAO,UACzB,WAAW,QAAQ,WACnB,OAAO,aAAa,cAAc,WAAW;AAGlD,MAAI,CAAC,eACH;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,cAAc,QAAQ,QAAQ,CAAC;AAInC,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,WAAW;AACnC,kBAAgB,QAAQ,WAAW,qBAAqB;;;;;;AAO5D,SAAS,MAAM,OAAwD;AACrE,QAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa"}
@@ -0,0 +1,74 @@
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
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * function SaveButton() {
32
+ * const [count, setCount] = useState(0)
33
+ *
34
+ * // Callback always has access to latest count value
35
+ * useHotkey('Mod+S', (event, { hotkey }) => {
36
+ * console.log(`Save triggered, count is ${count}`)
37
+ * handleSave()
38
+ * })
39
+ *
40
+ * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
41
+ * }
42
+ * ```
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * function Modal({ isOpen, onClose }) {
47
+ * // enabled option is synced on every render
48
+ * useHotkey('Escape', () => {
49
+ * onClose()
50
+ * }, { enabled: isOpen })
51
+ *
52
+ * if (!isOpen) return null
53
+ * return <div className="modal">...</div>
54
+ * }
55
+ * ```
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * function Editor() {
60
+ * const editorRef = useRef<HTMLDivElement>(null)
61
+ *
62
+ * // Scoped to a specific element
63
+ * useHotkey('Mod+S', () => {
64
+ * save()
65
+ * }, { target: editorRef })
66
+ *
67
+ * return <div ref={editorRef}>...</div>
68
+ * }
69
+ * ```
70
+ */
71
+ declare function useHotkey(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: UseHotkeyOptions): void;
72
+ //#endregion
73
+ export { UseHotkeyOptions, useHotkey };
74
+ //# sourceMappingURL=useHotkey.d.cts.map
@@ -0,0 +1,74 @@
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
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * function SaveButton() {
32
+ * const [count, setCount] = useState(0)
33
+ *
34
+ * // Callback always has access to latest count value
35
+ * useHotkey('Mod+S', (event, { hotkey }) => {
36
+ * console.log(`Save triggered, count is ${count}`)
37
+ * handleSave()
38
+ * })
39
+ *
40
+ * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
41
+ * }
42
+ * ```
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * function Modal({ isOpen, onClose }) {
47
+ * // enabled option is synced on every render
48
+ * useHotkey('Escape', () => {
49
+ * onClose()
50
+ * }, { enabled: isOpen })
51
+ *
52
+ * if (!isOpen) return null
53
+ * return <div className="modal">...</div>
54
+ * }
55
+ * ```
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * function Editor() {
60
+ * const editorRef = useRef<HTMLDivElement>(null)
61
+ *
62
+ * // Scoped to a specific element
63
+ * useHotkey('Mod+S', () => {
64
+ * save()
65
+ * }, { target: editorRef })
66
+ *
67
+ * return <div ref={editorRef}>...</div>
68
+ * }
69
+ * ```
70
+ */
71
+ declare function useHotkey(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: UseHotkeyOptions): void;
72
+ //#endregion
73
+ export { UseHotkeyOptions, useHotkey };
74
+ //# sourceMappingURL=useHotkey.d.ts.map
@@ -0,0 +1,118 @@
1
+ import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
2
+ import { detectPlatform, formatHotkey, getHotkeyManager, rawHotkeyToParsedHotkey } from "@tanstack/hotkeys";
3
+ import { useEffect, useRef } from "preact/hooks";
4
+
5
+ //#region src/useHotkey.ts
6
+ /**
7
+ * Preact hook for registering a keyboard hotkey.
8
+ *
9
+ * Uses the singleton HotkeyManager for efficient event handling.
10
+ * The callback receives both the keyboard event and a context object
11
+ * containing the hotkey string and parsed hotkey.
12
+ *
13
+ * This hook syncs the callback and options on every render to avoid
14
+ * stale closures. This means
15
+ * callbacks that reference Preact state will always have access to
16
+ * the latest values.
17
+ *
18
+ * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
19
+ * @param callback - The function to call when the hotkey is pressed
20
+ * @param options - Options for the hotkey behavior
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * function SaveButton() {
25
+ * const [count, setCount] = useState(0)
26
+ *
27
+ * // Callback always has access to latest count value
28
+ * useHotkey('Mod+S', (event, { hotkey }) => {
29
+ * console.log(`Save triggered, count is ${count}`)
30
+ * handleSave()
31
+ * })
32
+ *
33
+ * return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
34
+ * }
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * function Modal({ isOpen, onClose }) {
40
+ * // enabled option is synced on every render
41
+ * useHotkey('Escape', () => {
42
+ * onClose()
43
+ * }, { enabled: isOpen })
44
+ *
45
+ * if (!isOpen) return null
46
+ * return <div className="modal">...</div>
47
+ * }
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * function Editor() {
53
+ * const editorRef = useRef<HTMLDivElement>(null)
54
+ *
55
+ * // Scoped to a specific element
56
+ * useHotkey('Mod+S', () => {
57
+ * save()
58
+ * }, { target: editorRef })
59
+ *
60
+ * return <div ref={editorRef}>...</div>
61
+ * }
62
+ * ```
63
+ */
64
+ function useHotkey(hotkey, callback, options = {}) {
65
+ const mergedOptions = {
66
+ ...useDefaultHotkeysOptions().hotkey,
67
+ ...options
68
+ };
69
+ const manager = getHotkeyManager();
70
+ const registrationRef = useRef(null);
71
+ const callbackRef = useRef(callback);
72
+ const optionsRef = useRef(mergedOptions);
73
+ const managerRef = useRef(manager);
74
+ callbackRef.current = callback;
75
+ optionsRef.current = mergedOptions;
76
+ managerRef.current = manager;
77
+ const prevTargetRef = useRef(null);
78
+ const prevHotkeyRef = useRef(null);
79
+ const platform = mergedOptions.platform ?? detectPlatform();
80
+ const hotkeyString = typeof hotkey === "string" ? hotkey : formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform));
81
+ const { target: _target, ...optionsWithoutTarget } = mergedOptions;
82
+ useEffect(() => {
83
+ const resolvedTarget = isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
84
+ if (!resolvedTarget) return;
85
+ const targetChanged = prevTargetRef.current !== null && prevTargetRef.current !== resolvedTarget;
86
+ const hotkeyChanged = prevHotkeyRef.current !== null && prevHotkeyRef.current !== hotkeyString;
87
+ if (registrationRef.current?.isActive && (targetChanged || hotkeyChanged)) {
88
+ registrationRef.current.unregister();
89
+ registrationRef.current = null;
90
+ }
91
+ if (!registrationRef.current || !registrationRef.current.isActive) registrationRef.current = managerRef.current.register(hotkeyString, callbackRef.current, {
92
+ ...optionsRef.current,
93
+ target: resolvedTarget
94
+ });
95
+ prevTargetRef.current = resolvedTarget;
96
+ prevHotkeyRef.current = hotkeyString;
97
+ return () => {
98
+ if (registrationRef.current?.isActive) {
99
+ registrationRef.current.unregister();
100
+ registrationRef.current = null;
101
+ }
102
+ };
103
+ }, [hotkeyString, options.enabled]);
104
+ if (registrationRef.current?.isActive) {
105
+ registrationRef.current.callback = callback;
106
+ registrationRef.current.setOptions(optionsWithoutTarget);
107
+ }
108
+ }
109
+ /**
110
+ * Type guard to check if a value is a Preact ref-like object.
111
+ */
112
+ function isRef(value) {
113
+ return value !== null && typeof value === "object" && "current" in value;
114
+ }
115
+
116
+ //#endregion
117
+ export { useHotkey };
118
+ //# sourceMappingURL=useHotkey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHotkey.js","names":[],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { useEffect, useRef } from 'preact/hooks'\nimport {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { RefObject } from 'preact'\nimport type {\n Hotkey,\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\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: Hotkey =\n typeof hotkey === 'string'\n ? hotkey\n : (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)\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 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, options.enabled])\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\n/**\n * Type guard to check if a value is a Preact ref-like object.\n */\nfunction isRef(value: unknown): value is RefObject<HTMLElement | null> {\n return value !== null && typeof value === 'object' && 'current' in value\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;CAGjD,MAAM,WAAW,cAAc,YAAY,gBAAgB;CAC3D,MAAM,eACJ,OAAO,WAAW,WACd,SACC,aAAa,wBAAwB,QAAQ,SAAS,CAAC;CAG9D,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,eACH;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,cAAc,QAAQ,QAAQ,CAAC;AAInC,KAAI,gBAAgB,SAAS,UAAU;AACrC,kBAAgB,QAAQ,WAAW;AACnC,kBAAgB,QAAQ,WAAW,qBAAqB;;;;;;AAO5D,SAAS,MAAM,OAAwD;AACrE,QAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa"}
@@ -0,0 +1,71 @@
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.useStore)(recorderRef.current.store, (state) => state.isRecording);
54
+ const recordedHotkey = (0, _tanstack_preact_store.useStore)(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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHotkeyRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeyRecorder"],"sources":["../src/useHotkeyRecorder.ts"],"sourcesContent":["import { useEffect, useRef } from 'preact/hooks'\nimport { useStore } 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 useStore (same pattern as useHeldKeys)\n const isRecording = useStore(\n recorderRef.current.store,\n (state) => state.isRecording,\n )\n const recordedHotkey = useStore(\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,mDACJ,YAAY,QAAQ,QACnB,UAAU,MAAM,YAClB;CACD,MAAM,sDACJ,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"}
@@ -0,0 +1,57 @@
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
@@ -0,0 +1,57 @@
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.ts.map