@tanstack/solid-hotkeys 0.16.0 → 0.17.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.
@@ -2,9 +2,10 @@ import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/ho
2
2
  //#region src/createHotkeyHint.d.ts
3
3
  /**
4
4
  * Returns an accessor indicating whether held modifiers reveal this shortcut.
5
- * A sequence reveals its hint from its first step, and an app hotkey uses its
6
- * effective hotkey (false while unbound). This helper does not register a
7
- * shortcut or check whether its target is focused.
5
+ * The hint shows only while the hotkey can fire: some registration of it is
6
+ * enabled and in an active scope. A sequence reveals its hint from its first
7
+ * step, and an app hotkey matches its registrations by id and uses its
8
+ * effective hotkey (false while unbound). This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
8
9
  */
9
10
  export declare function createHotkeyHint(hotkey: RegisterableHotkey | AppHotkey | (() => RegisterableHotkey | AppHotkey), options?: HeldModifierOptions | (() => HeldModifierOptions)): () => boolean;
10
11
  //#endregion
@@ -1,23 +1,26 @@
1
1
  import { useAppHotkeysStoreSource } from "./defaultOptions.js";
2
- import { getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
2
+ import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
3
3
  import { createMemo } from "solid-js";
4
4
  import { useSelector } from "@tanstack/solid-store";
5
5
 
6
6
  //#region src/createHotkeyHint.ts
7
7
  /**
8
8
  * Returns an accessor indicating whether held modifiers reveal this shortcut.
9
- * A sequence reveals its hint from its first step, and an app hotkey uses its
10
- * effective hotkey (false while unbound). This helper does not register a
11
- * shortcut or check whether its target is focused.
9
+ * The hint shows only while the hotkey can fire: some registration of it is
10
+ * enabled and in an active scope. A sequence reveals its hint from its first
11
+ * step, and an app hotkey matches its registrations by id and uses its
12
+ * effective hotkey (false while unbound). This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
12
13
  */
13
14
  function createHotkeyHint(hotkey, options = {}) {
14
15
  const appHotkeys = useAppHotkeysStoreSource();
16
+ const manager = getHotkeyManager();
17
+ const registrations = useSelector(manager.registrations, (state) => state);
15
18
  const held = useSelector(getKeyStateTracker().store, (state) => state.heldKeys);
16
19
  return createMemo(() => {
17
20
  appHotkeys.state();
18
21
  const value = typeof hotkey === "function" ? hotkey() : hotkey;
19
22
  const resolved = isAppHotkey(value) ? resolveAppHotkey(value, appHotkeys.store).hotkey : value;
20
- return resolved !== null && matchesHeldModifiers(resolved, held(), typeof options === "function" ? options() : options);
23
+ return resolved !== null && matchesHeldModifiers(resolved, held(), typeof options === "function" ? options() : options) && registrations().size > 0 && manager.hasActiveRegistration(value);
21
24
  });
22
25
  }
23
26
 
@@ -0,0 +1,24 @@
1
+ import { HotkeyScopesState } from "@tanstack/hotkeys";
2
+ //#region src/createHotkeyScopesState.d.ts
3
+ /**
4
+ * SolidJS primitive that returns a signal of the hotkey manager's scope state:
5
+ * the active scopes, the exclusive scope that owns the keyboard, and the
6
+ * scopes it allows or suspends. Updates when scopes activate or release.
7
+ *
8
+ * @returns Signal accessor for the current scope state
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * function KeyboardOwner() {
13
+ * const scopes = createHotkeyScopesState()
14
+ *
15
+ * return (
16
+ * <Show when={scopes().exclusive}>
17
+ * {(exclusive) => <p>Shortcuts belong to {exclusive()}</p>}
18
+ * </Show>
19
+ * )
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function createHotkeyScopesState(): () => HotkeyScopesState;
24
+ //#endregion
@@ -0,0 +1,30 @@
1
+ import { getHotkeyManager } from "@tanstack/hotkeys";
2
+ import { useSelector } from "@tanstack/solid-store";
3
+
4
+ //#region src/createHotkeyScopesState.ts
5
+ /**
6
+ * SolidJS primitive that returns a signal of the hotkey manager's scope state:
7
+ * the active scopes, the exclusive scope that owns the keyboard, and the
8
+ * scopes it allows or suspends. Updates when scopes activate or release.
9
+ *
10
+ * @returns Signal accessor for the current scope state
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * function KeyboardOwner() {
15
+ * const scopes = createHotkeyScopesState()
16
+ *
17
+ * return (
18
+ * <Show when={scopes().exclusive}>
19
+ * {(exclusive) => <p>Shortcuts belong to {exclusive()}</p>}
20
+ * </Show>
21
+ * )
22
+ * }
23
+ * ```
24
+ */
25
+ function createHotkeyScopesState() {
26
+ return useSelector(getHotkeyManager().scopes, (state) => state);
27
+ }
28
+
29
+ //#endregion
30
+ export { createHotkeyScopesState };
package/dist/index.d.ts CHANGED
@@ -3,10 +3,11 @@ import { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefau
3
3
  import { CreateHotkeyDefinition, createHotkeys } from "./createHotkeys.js";
4
4
  import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.js";
5
5
  import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
6
+ import { createHotkeyScopesState } from "./createHotkeyScopesState.js";
6
7
  import { createHotkeyHint } from "./createHotkeyHint.js";
7
8
  import { UseCustomHotkeysResult, createAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./appHotkeys.js";
8
9
  import { createHeldKeys } from "./createHeldKeys.js";
9
10
  import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
10
11
  import { createKeyHold } from "./createKeyHold.js";
11
12
  export * from "@tanstack/hotkeys";
12
- export { CreateAppHotkeyOptions, CreateHotkeyChordOptions, CreateHotkeyCommonOptions, CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeyOptionsFor, CreateHotkeySequenceOptions, CreateHotkeyTarget, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, UseCustomHotkeysResult, createAppHotkeyList, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
13
+ export { CreateAppHotkeyOptions, CreateHotkeyChordOptions, CreateHotkeyCommonOptions, CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeyOptionsFor, CreateHotkeySequenceOptions, CreateHotkeyTarget, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, UseCustomHotkeysResult, createAppHotkeyList, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { createHotkeys } from "./createHotkeys.js";
3
3
  import { createHotkey } from "./createHotkey.js";
4
4
  import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
5
5
  import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
6
+ import { createHotkeyScopesState } from "./createHotkeyScopesState.js";
6
7
  import { createHotkeyHint } from "./createHotkeyHint.js";
7
8
  import { createAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./appHotkeys.js";
8
9
  import { createHeldKeys } from "./createHeldKeys.js";
@@ -11,4 +12,4 @@ import { createKeyHold } from "./createKeyHold.js";
11
12
 
12
13
  export * from "@tanstack/hotkeys"
13
14
 
14
- export { HotkeysProvider, createAppHotkeyList, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
15
+ export { HotkeysProvider, createAppHotkeyList, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-hotkeys",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "SolidJS adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "skills"
39
39
  ],
40
40
  "dependencies": {
41
- "@tanstack/hotkeys": "0.17.0",
41
+ "@tanstack/hotkeys": "0.18.0",
42
42
  "@tanstack/solid-store": "^0.11.2"
43
43
  },
44
44
  "devDependencies": {
@@ -54,22 +54,23 @@ export function Editor() {
54
54
 
55
55
  ## API
56
56
 
57
- | API | What it's for |
58
- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
59
- | `createHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey for the owning component's lifetime; the hotkey and options can be accessors. |
60
- | `createHotkeys(definitions, commonOptions?)` | Register several hotkeys, or an accessor of a list built from data, in one call. |
61
- | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
62
- | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
63
- | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
64
- | `useAppHotkeys()` | Get an accessor of the declared app hotkeys with the user's custom hotkeys applied. |
65
- | `createAppHotkeyList()` | Get an accessor listing every app hotkey with its status, for a cheat sheet or settings screen. |
66
- | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
67
- | `createHotkeyRecorder(options)` | Record a chord or sequence the user presses; its state fields are accessors. |
68
- | `createHotkeyRegistrations()` | Get an accessor listing every registered hotkey with its options and `meta`. |
69
- | `createHotkeyHint(hotkey, options?)` | Get an accessor of whether held modifiers should reveal a shortcut's hint. |
70
- | `createKeyHold(key)` | Get an accessor of whether one key is held. |
71
- | `createHeldKeys()` | Get an accessor of every key that's held right now. |
72
- | `createHeldKeyCodes()` | Get an accessor mapping each held key to its physical `event.code`. |
57
+ | API | What it's for |
58
+ | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
59
+ | `createHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey for the owning component's lifetime; the hotkey and options can be accessors. |
60
+ | `createHotkeys(definitions, commonOptions?)` | Register several hotkeys, or an accessor of a list built from data, in one call. |
61
+ | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
62
+ | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
63
+ | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
64
+ | `useAppHotkeys()` | Get an accessor of the declared app hotkeys with the user's custom hotkeys applied. |
65
+ | `createAppHotkeyList()` | Get an accessor listing every app hotkey with its status, for a cheat sheet or settings screen. |
66
+ | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
67
+ | `createHotkeyRecorder(options)` | Record a chord or sequence the user presses; its state fields are accessors. |
68
+ | `createHotkeyRegistrations()` | Get an accessor listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
69
+ | `createHotkeyScopesState()` | Get an accessor of the active scopes and the exclusive scope that owns the keyboard. |
70
+ | `createHotkeyHint(hotkey, options?)` | Get an accessor of whether held modifiers should reveal a shortcut's hint. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
71
+ | `createKeyHold(key)` | Get an accessor of whether one key is held. |
72
+ | `createHeldKeys()` | Get an accessor of every key that's held right now. |
73
+ | `createHeldKeyCodes()` | Get an accessor mapping each held key to its physical `event.code`. |
73
74
 
74
75
  The package also re-exports `@tanstack/hotkeys`, such as `formatForDisplay`, `matchesKeyboardEvent`, and `defineAppHotkeys`.
75
76