@tanstack/preact-hotkeys 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,6 +58,7 @@ Type-safe keyboard shortcuts for the web. Template-string bindings, parsed objec
58
58
  > - [**Solid Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/solid/reference)
59
59
  > - [**Angular Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/angular/reference)
60
60
  > - [**Vue Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/vue/reference)
61
+ > - [**Lit Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/lit/reference)
61
62
  > - [**Svelte Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/svelte/reference)
62
63
 
63
64
  ## Get Involved
@@ -1,7 +1,7 @@
1
1
  import { UseHotkeyOptions } from "./useHotkey.cjs";
2
2
  import { UseHotkeySequenceOptions } from "./useHotkeySequence.cjs";
3
3
  import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
4
- import * as preact from "preact";
4
+ import * as _$preact from "preact";
5
5
  import { ComponentChildren } from "preact";
6
6
 
7
7
  //#region src/HotkeysProvider.d.ts
@@ -21,7 +21,7 @@ interface HotkeysProviderProps {
21
21
  declare function HotkeysProvider({
22
22
  children,
23
23
  defaultOptions
24
- }: HotkeysProviderProps): preact.JSX.Element;
24
+ }: HotkeysProviderProps): _$preact.JSX.Element;
25
25
  declare function useHotkeysContext(): HotkeysContextValue | null;
26
26
  declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
27
27
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { UseHotkeyOptions } from "./useHotkey.js";
2
2
  import { UseHotkeySequenceOptions } from "./useHotkeySequence.js";
3
3
  import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
4
- import * as preact from "preact";
4
+ import * as _$preact from "preact";
5
5
  import { ComponentChildren } from "preact";
6
6
 
7
7
  //#region src/HotkeysProvider.d.ts
@@ -21,7 +21,7 @@ interface HotkeysProviderProps {
21
21
  declare function HotkeysProvider({
22
22
  children,
23
23
  defaultOptions
24
- }: HotkeysProviderProps): preact.JSX.Element;
24
+ }: HotkeysProviderProps): _$preact.JSX.Element;
25
25
  declare function useHotkeysContext(): HotkeysContextValue | null;
26
26
  declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
27
27
  //#endregion
package/dist/index.cjs CHANGED
@@ -8,6 +8,7 @@ const require_useKeyHold = require('./useKeyHold.cjs');
8
8
  const require_useHotkeySequence = require('./useHotkeySequence.cjs');
9
9
  const require_useHotkeySequences = require('./useHotkeySequences.cjs');
10
10
  const require_useHotkeyRecorder = require('./useHotkeyRecorder.cjs');
11
+ const require_useHotkeyRegistrations = require('./useHotkeyRegistrations.cjs');
11
12
  const require_useHotkeySequenceRecorder = require('./useHotkeySequenceRecorder.cjs');
12
13
 
13
14
  exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
@@ -16,6 +17,7 @@ exports.useHeldKeyCodes = require_useHeldKeyCodes.useHeldKeyCodes;
16
17
  exports.useHeldKeys = require_useHeldKeys.useHeldKeys;
17
18
  exports.useHotkey = require_useHotkey.useHotkey;
18
19
  exports.useHotkeyRecorder = require_useHotkeyRecorder.useHotkeyRecorder;
20
+ exports.useHotkeyRegistrations = require_useHotkeyRegistrations.useHotkeyRegistrations;
19
21
  exports.useHotkeySequence = require_useHotkeySequence.useHotkeySequence;
20
22
  exports.useHotkeySequenceRecorder = require_useHotkeySequenceRecorder.useHotkeySequenceRecorder;
21
23
  exports.useHotkeySequences = require_useHotkeySequences.useHotkeySequences;
package/dist/index.d.cts CHANGED
@@ -7,6 +7,7 @@ import { useHeldKeyCodes } from "./useHeldKeyCodes.cjs";
7
7
  import { useKeyHold } from "./useKeyHold.cjs";
8
8
  import { UseHotkeySequenceDefinition, useHotkeySequences } from "./useHotkeySequences.cjs";
9
9
  import { PreactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.cjs";
10
+ import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.cjs";
10
11
  import { PreactHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.cjs";
11
12
  export * from "@tanstack/hotkeys";
12
- export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, PreactHotkeyRecorder, PreactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
13
+ export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, PreactHotkeyRecorder, PreactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
7
7
  import { useKeyHold } from "./useKeyHold.js";
8
8
  import { UseHotkeySequenceDefinition, useHotkeySequences } from "./useHotkeySequences.js";
9
9
  import { PreactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
10
+ import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
11
  import { PreactHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.js";
11
12
  export * from "@tanstack/hotkeys";
12
- export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, PreactHotkeyRecorder, PreactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
13
+ export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, PreactHotkeyRecorder, PreactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
package/dist/index.js CHANGED
@@ -7,8 +7,9 @@ import { useKeyHold } from "./useKeyHold.js";
7
7
  import { useHotkeySequence } from "./useHotkeySequence.js";
8
8
  import { useHotkeySequences } from "./useHotkeySequences.js";
9
9
  import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
10
+ import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
11
  import { useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.js";
11
12
 
12
13
  export * from "@tanstack/hotkeys"
13
14
 
14
- export { HotkeysProvider, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
15
+ export { HotkeysProvider, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
@@ -0,0 +1,26 @@
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.useStore)(hotkeyManager.registrations, (state) => Array.from(state.values()).map(_tanstack_hotkeys.toHotkeyRegistrationView)),
20
+ sequences: (0, _tanstack_preact_store.useStore)(sequenceManager.registrations, (state) => Array.from(state.values()))
21
+ };
22
+ }
23
+
24
+ //#endregion
25
+ exports.useHotkeyRegistrations = useHotkeyRegistrations;
26
+ //# sourceMappingURL=useHotkeyRegistrations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHotkeyRegistrations.cjs","names":["toHotkeyRegistrationView"],"sources":["../src/useHotkeyRegistrations.ts"],"sourcesContent":["import { useStore } from '@tanstack/preact-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\n\n/**\n * Return type for useHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** All registered hotkeys (public view, no callbacks) */\n hotkeys: Array<HotkeyRegistrationView>\n /** All registered sequences */\n sequences: Array<SequenceRegistrationView>\n}\n\n/**\n * Preact hook that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone hook that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * re-renders when registrations change.\n *\n * @returns Object with `hotkeys` and `sequences` arrays\n */\nexport function useHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = useStore(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = useStore(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,yBAAoD;CAClE,MAAM,yDAAkC;CACxC,MAAM,6DAAsC;AAU5C,QAAO;EAAE,8CARgB,cAAc,gBAAgB,UACrD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAIA,2CAAyB,CACzD;EAMiB,gDAJS,gBAAgB,gBAAgB,UACzD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
@@ -0,0 +1,26 @@
1
+ import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
2
+
3
+ //#region src/useHotkeyRegistrations.d.ts
4
+ /**
5
+ * Return type for useHotkeyRegistrations.
6
+ */
7
+ interface HotkeyRegistrationsResult {
8
+ /** All registered hotkeys (public view, no callbacks) */
9
+ hotkeys: Array<HotkeyRegistrationView>;
10
+ /** All registered sequences */
11
+ sequences: Array<SequenceRegistrationView>;
12
+ }
13
+ /**
14
+ * Preact hook that reactively reads all hotkey and sequence registrations
15
+ * from the singleton managers.
16
+ *
17
+ * This is a standalone hook that does NOT require the HotkeysProvider.
18
+ * It subscribes to both HotkeyManager and SequenceManager stores and
19
+ * re-renders when registrations change.
20
+ *
21
+ * @returns Object with `hotkeys` and `sequences` arrays
22
+ */
23
+ declare function useHotkeyRegistrations(): HotkeyRegistrationsResult;
24
+ //#endregion
25
+ export { HotkeyRegistrationsResult, useHotkeyRegistrations };
26
+ //# sourceMappingURL=useHotkeyRegistrations.d.cts.map
@@ -0,0 +1,26 @@
1
+ import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
2
+
3
+ //#region src/useHotkeyRegistrations.d.ts
4
+ /**
5
+ * Return type for useHotkeyRegistrations.
6
+ */
7
+ interface HotkeyRegistrationsResult {
8
+ /** All registered hotkeys (public view, no callbacks) */
9
+ hotkeys: Array<HotkeyRegistrationView>;
10
+ /** All registered sequences */
11
+ sequences: Array<SequenceRegistrationView>;
12
+ }
13
+ /**
14
+ * Preact hook that reactively reads all hotkey and sequence registrations
15
+ * from the singleton managers.
16
+ *
17
+ * This is a standalone hook that does NOT require the HotkeysProvider.
18
+ * It subscribes to both HotkeyManager and SequenceManager stores and
19
+ * re-renders when registrations change.
20
+ *
21
+ * @returns Object with `hotkeys` and `sequences` arrays
22
+ */
23
+ declare function useHotkeyRegistrations(): HotkeyRegistrationsResult;
24
+ //#endregion
25
+ export { HotkeyRegistrationsResult, useHotkeyRegistrations };
26
+ //# sourceMappingURL=useHotkeyRegistrations.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
2
+ import { useStore } from "@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 = getHotkeyManager();
17
+ const sequenceManager = getSequenceManager();
18
+ return {
19
+ hotkeys: useStore(hotkeyManager.registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView)),
20
+ sequences: useStore(sequenceManager.registrations, (state) => Array.from(state.values()))
21
+ };
22
+ }
23
+
24
+ //#endregion
25
+ export { useHotkeyRegistrations };
26
+ //# sourceMappingURL=useHotkeyRegistrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHotkeyRegistrations.js","names":[],"sources":["../src/useHotkeyRegistrations.ts"],"sourcesContent":["import { useStore } from '@tanstack/preact-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\n\n/**\n * Return type for useHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** All registered hotkeys (public view, no callbacks) */\n hotkeys: Array<HotkeyRegistrationView>\n /** All registered sequences */\n sequences: Array<SequenceRegistrationView>\n}\n\n/**\n * Preact hook that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone hook that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * re-renders when registrations change.\n *\n * @returns Object with `hotkeys` and `sequences` arrays\n */\nexport function useHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = useStore(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = useStore(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,yBAAoD;CAClE,MAAM,gBAAgB,kBAAkB;CACxC,MAAM,kBAAkB,oBAAoB;AAU5C,QAAO;EAAE,SARO,SAAS,cAAc,gBAAgB,UACrD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAI,yBAAyB,CACzD;EAMiB,WAJA,SAAS,gBAAgB,gBAAgB,UACzD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyHold.cjs","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import { useStore } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { HeldKey } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns whether a specific key is currently being held.\n *\n * This hook uses `useStore` from `@tanstack/preact-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if\n * the specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A')\n * @returns True if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = useKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld ? 1 : 0.5 }}>\n * {isShiftHeld ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = useKeyHold('Control')\n * const shift = useKeyHold('Shift')\n * const alt = useKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function useKeyHold(key: HeldKey): boolean {\n const tracker = getKeyStateTracker()\n const normalizedKey = key.toLowerCase()\n\n return useStore(tracker.store, (state) =>\n state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,WAAW,KAAuB;CAChD,MAAM,qDAA8B;CACpC,MAAM,gBAAgB,IAAI,aAAa;AAEvC,6CAAgB,QAAQ,QAAQ,UAC9B,MAAM,SAAS,MAAM,YAAY,QAAQ,aAAa,KAAK,cAAc,CAC1E"}
1
+ {"version":3,"file":"useKeyHold.cjs","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import { useStore } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { IndividualKey } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns whether a specific key is currently being held.\n *\n * This hook uses `useStore` from `@tanstack/preact-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if\n * the specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A')\n * @returns True if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = useKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld ? 1 : 0.5 }}>\n * {isShiftHeld ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = useKeyHold('Control')\n * const shift = useKeyHold('Shift')\n * const alt = useKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function useKeyHold(key: IndividualKey): boolean {\n const tracker = getKeyStateTracker()\n const normalizedKey = key.toLowerCase()\n\n return useStore(tracker.store, (state) =>\n state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,WAAW,KAA6B;CACtD,MAAM,qDAA8B;CACpC,MAAM,gBAAgB,IAAI,aAAa;AAEvC,6CAAgB,QAAQ,QAAQ,UAC9B,MAAM,SAAS,MAAM,YAAY,QAAQ,aAAa,KAAK,cAAc,CAC1E"}
@@ -1,4 +1,4 @@
1
- import { HeldKey } from "@tanstack/hotkeys";
1
+ import { IndividualKey } from "@tanstack/hotkeys";
2
2
 
3
3
  //#region src/useKeyHold.d.ts
4
4
  /**
@@ -41,7 +41,7 @@ import { HeldKey } from "@tanstack/hotkeys";
41
41
  * }
42
42
  * ```
43
43
  */
44
- declare function useKeyHold(key: HeldKey): boolean;
44
+ declare function useKeyHold(key: IndividualKey): boolean;
45
45
  //#endregion
46
46
  export { useKeyHold };
47
47
  //# sourceMappingURL=useKeyHold.d.cts.map
@@ -1,4 +1,4 @@
1
- import { HeldKey } from "@tanstack/hotkeys";
1
+ import { IndividualKey } from "@tanstack/hotkeys";
2
2
 
3
3
  //#region src/useKeyHold.d.ts
4
4
  /**
@@ -41,7 +41,7 @@ import { HeldKey } from "@tanstack/hotkeys";
41
41
  * }
42
42
  * ```
43
43
  */
44
- declare function useKeyHold(key: HeldKey): boolean;
44
+ declare function useKeyHold(key: IndividualKey): boolean;
45
45
  //#endregion
46
46
  export { useKeyHold };
47
47
  //# sourceMappingURL=useKeyHold.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyHold.js","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import { useStore } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { HeldKey } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns whether a specific key is currently being held.\n *\n * This hook uses `useStore` from `@tanstack/preact-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if\n * the specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A')\n * @returns True if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = useKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld ? 1 : 0.5 }}>\n * {isShiftHeld ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = useKeyHold('Control')\n * const shift = useKeyHold('Shift')\n * const alt = useKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function useKeyHold(key: HeldKey): boolean {\n const tracker = getKeyStateTracker()\n const normalizedKey = key.toLowerCase()\n\n return useStore(tracker.store, (state) =>\n state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,WAAW,KAAuB;CAChD,MAAM,UAAU,oBAAoB;CACpC,MAAM,gBAAgB,IAAI,aAAa;AAEvC,QAAO,SAAS,QAAQ,QAAQ,UAC9B,MAAM,SAAS,MAAM,YAAY,QAAQ,aAAa,KAAK,cAAc,CAC1E"}
1
+ {"version":3,"file":"useKeyHold.js","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import { useStore } from '@tanstack/preact-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { IndividualKey } from '@tanstack/hotkeys'\n\n/**\n * Preact hook that returns whether a specific key is currently being held.\n *\n * This hook uses `useStore` from `@tanstack/preact-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if\n * the specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A')\n * @returns True if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = useKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld ? 1 : 0.5 }}>\n * {isShiftHeld ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = useKeyHold('Control')\n * const shift = useKeyHold('Shift')\n * const alt = useKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function useKeyHold(key: IndividualKey): boolean {\n const tracker = getKeyStateTracker()\n const normalizedKey = key.toLowerCase()\n\n return useStore(tracker.store, (state) =>\n state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,WAAW,KAA6B;CACtD,MAAM,UAAU,oBAAoB;CACpC,MAAM,gBAAgB,IAAI,aAAa;AAEvC,QAAO,SAAS,QAAQ,QAAQ,UAC9B,MAAM,SAAS,MAAM,YAAY,QAAQ,aAAa,KAAK,cAAc,CAC1E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/preact-hotkeys",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "description": "Preact adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@tanstack/preact-store": "^0.11.3",
43
- "@tanstack/hotkeys": "0.6.3"
43
+ "@tanstack/hotkeys": "0.7.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@preact/preset-vite": "^2.10.5",
package/src/index.ts CHANGED
@@ -13,4 +13,5 @@ export * from './useKeyHold'
13
13
  export * from './useHotkeySequence'
14
14
  export * from './useHotkeySequences'
15
15
  export * from './useHotkeyRecorder'
16
+ export * from './useHotkeyRegistrations'
16
17
  export * from './useHotkeySequenceRecorder'
@@ -0,0 +1,45 @@
1
+ import { useStore } from '@tanstack/preact-store'
2
+ import {
3
+ getHotkeyManager,
4
+ getSequenceManager,
5
+ toHotkeyRegistrationView,
6
+ } from '@tanstack/hotkeys'
7
+ import type {
8
+ HotkeyRegistrationView,
9
+ SequenceRegistrationView,
10
+ } from '@tanstack/hotkeys'
11
+
12
+ /**
13
+ * Return type for useHotkeyRegistrations.
14
+ */
15
+ export interface HotkeyRegistrationsResult {
16
+ /** All registered hotkeys (public view, no callbacks) */
17
+ hotkeys: Array<HotkeyRegistrationView>
18
+ /** All registered sequences */
19
+ sequences: Array<SequenceRegistrationView>
20
+ }
21
+
22
+ /**
23
+ * Preact hook that reactively reads all hotkey and sequence registrations
24
+ * from the singleton managers.
25
+ *
26
+ * This is a standalone hook that does NOT require the HotkeysProvider.
27
+ * It subscribes to both HotkeyManager and SequenceManager stores and
28
+ * re-renders when registrations change.
29
+ *
30
+ * @returns Object with `hotkeys` and `sequences` arrays
31
+ */
32
+ export function useHotkeyRegistrations(): HotkeyRegistrationsResult {
33
+ const hotkeyManager = getHotkeyManager()
34
+ const sequenceManager = getSequenceManager()
35
+
36
+ const hotkeys = useStore(hotkeyManager.registrations, (state) =>
37
+ Array.from(state.values()).map(toHotkeyRegistrationView),
38
+ )
39
+
40
+ const sequences = useStore(sequenceManager.registrations, (state) =>
41
+ Array.from(state.values()),
42
+ )
43
+
44
+ return { hotkeys, sequences }
45
+ }
package/src/useKeyHold.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useStore } from '@tanstack/preact-store'
2
2
  import { getKeyStateTracker } from '@tanstack/hotkeys'
3
- import type { HeldKey } from '@tanstack/hotkeys'
3
+ import type { IndividualKey } from '@tanstack/hotkeys'
4
4
 
5
5
  /**
6
6
  * Preact hook that returns whether a specific key is currently being held.
@@ -42,7 +42,7 @@ import type { HeldKey } from '@tanstack/hotkeys'
42
42
  * }
43
43
  * ```
44
44
  */
45
- export function useKeyHold(key: HeldKey): boolean {
45
+ export function useKeyHold(key: IndividualKey): boolean {
46
46
  const tracker = getKeyStateTracker()
47
47
  const normalizedKey = key.toLowerCase()
48
48