@tanstack/octane-hotkeys 0.6.0 → 0.7.1

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/dist/index.d.ts CHANGED
@@ -7,7 +7,8 @@ import { useKeyHold } from "./useKeyHold.js";
7
7
  import { useHotkeyHint } from "./useHotkeyHint.js";
8
8
  import { HotkeyRegistrationsResult, OctaneHotkeyRecorder, UseCustomHotkeysResult } from "./types.js";
9
9
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
+ import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
10
11
  import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
11
12
  import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
12
13
  export * from "@tanstack/hotkeys";
13
- export { type DefaultHotkeysOptions, HotkeyRegistrationsResult, HotkeysProvider, type HotkeysProviderOptions, type HotkeysProviderProps, OctaneHotkeyRecorder, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeys, useHotkeysContext, useKeyHold };
14
+ export { type DefaultHotkeysOptions, HotkeyRegistrationsResult, HotkeysProvider, type HotkeysProviderOptions, type HotkeysProviderProps, OctaneHotkeyRecorder, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold };
package/dist/index.js CHANGED
@@ -6,9 +6,10 @@ import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
6
6
  import { useKeyHold } from "./useKeyHold.js";
7
7
  import { useHotkeyHint } from "./useHotkeyHint.js";
8
8
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
9
+ import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
9
10
  import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
10
11
  import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
11
12
 
12
13
  export * from "@tanstack/hotkeys"
13
14
 
14
- export { HotkeysProvider, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeys, useHotkeysContext, useKeyHold };
15
+ export { HotkeysProvider, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold };
@@ -1,9 +1,11 @@
1
1
  import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
2
2
  //#region src/useHotkeyHint.d.ts
3
3
  /**
4
- * Reports whether held modifiers reveal a shortcut hint. A sequence reveals
5
- * its hint from its first step, and an app hotkey uses its effective hotkey
6
- * (false while unbound).
4
+ * Reports whether held modifiers reveal a shortcut hint. The hint shows only
5
+ * while the hotkey can fire: some registration of it is enabled and in an
6
+ * active scope. A sequence reveals its hint from its first step, and an app
7
+ * hotkey matches its registrations by id and uses its effective hotkey (false
8
+ * while unbound). A hotkey on an element counts only while focus is inside it.
7
9
  */
8
10
  export declare function useHotkeyHint(hotkey: RegisterableHotkey | AppHotkey, options?: HeldModifierOptions): boolean;
9
11
  //#endregion
@@ -1,13 +1,16 @@
1
1
  import { select, splitSlot, subSlot, useAppHotkeysStore } from "./internal.js";
2
2
  import { useHotkeysContext } from "./HotkeysProvider.js";
3
- import { getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
3
+ import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
4
4
 
5
5
  //#region src/useHotkeyHint.ts
6
6
  function useHotkeyHint(hotkey, ...rest) {
7
7
  const [args, slot] = splitSlot(rest);
8
8
  const store = useAppHotkeysStore(useHotkeysContext()?.appHotkeysStore ?? null, subSlot(slot, "app-hotkeys"));
9
9
  const resolved = isAppHotkey(hotkey) ? resolveAppHotkey(hotkey, store).hotkey : hotkey;
10
- return select(getKeyStateTracker().store, (state) => resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, args[0]), void 0, subSlot(slot, "hint"));
10
+ const manager = getHotkeyManager();
11
+ const active = select(manager.registrations, () => resolved !== null && manager.hasActiveRegistration(hotkey), void 0, subSlot(slot, "hint-active"));
12
+ const held = select(getKeyStateTracker().store, (state) => resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, args[0]), void 0, subSlot(slot, "hint"));
13
+ return active && held;
11
14
  }
12
15
 
13
16
  //#endregion
@@ -0,0 +1,8 @@
1
+ import { HotkeyScopesState } from "@tanstack/hotkeys";
2
+ //#region src/useHotkeyScopesState.d.ts
3
+ /**
4
+ * Reads the hotkey manager's scope state: the active scopes, the exclusive
5
+ * scope that owns the keyboard, and the scopes it allows or suspends.
6
+ */
7
+ export declare function useHotkeyScopesState(): HotkeyScopesState;
8
+ //#endregion
@@ -0,0 +1,10 @@
1
+ import { select, subSlot } from "./internal.js";
2
+ import { getHotkeyManager } from "@tanstack/hotkeys";
3
+
4
+ //#region src/useHotkeyScopesState.ts
5
+ function useHotkeyScopesState(slot) {
6
+ return select(getHotkeyManager().scopes, (state) => state, void 0, subSlot(slot, "hotkey-scopes-state"));
7
+ }
8
+
9
+ //#endregion
10
+ export { useHotkeyScopesState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/octane-hotkeys",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Octane adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "skills"
36
36
  ],
37
37
  "dependencies": {
38
- "@tanstack/hotkeys": "0.17.0",
38
+ "@tanstack/hotkeys": "0.19.0",
39
39
  "@tanstack/octane-store": "^0.13.0"
40
40
  },
41
41
  "devDependencies": {
@@ -48,22 +48,23 @@ export function Panel({ onSave }: { onSave: () => void }) @{
48
48
 
49
49
  ## API
50
50
 
51
- | API | What it's for |
52
- | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
53
- | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted. |
54
- | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a list built from data, in one call. |
55
- | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
56
- | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
57
- | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
58
- | `useAppHotkeys()` | Get the declared app hotkeys with the user's custom hotkeys applied, to pass to the register API. |
59
- | `useAppHotkeyList()` | List every app hotkey with its status, including ones whose components aren't mounted, for a cheat sheet or settings screen. |
60
- | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
61
- | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses, for a settings screen. |
62
- | `useHotkeyRegistrations()` | List every registered hotkey with its options and `meta`, for a cheat sheet of what's mounted. |
63
- | `useHotkeyHint(hotkey, options?)` | Get whether held modifiers should reveal a shortcut's hint, such as labels that appear while Mod is held. |
64
- | `useKeyHold(key)` | Get whether one key is held, such as Shift for a range-select mode. |
65
- | `useHeldKeys()` | Get every key that's held right now. |
66
- | `useHeldKeyCodes()` | Map each held key to its physical `event.code`. |
51
+ | API | What it's for |
52
+ | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
53
+ | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted. |
54
+ | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a list built from data, in one call. |
55
+ | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
56
+ | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
57
+ | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
58
+ | `useAppHotkeys()` | Get the declared app hotkeys with the user's custom hotkeys applied, to pass to the register API. |
59
+ | `useAppHotkeyList()` | List every app hotkey with its status, including ones whose components aren't mounted, for a cheat sheet or settings screen. |
60
+ | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
61
+ | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses, for a settings screen. |
62
+ | `useHotkeyRegistrations()` | List every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope), for a cheat sheet of what's mounted. |
63
+ | `useHotkeyScopesState()` | Get the active scopes and the exclusive scope that owns the keyboard. |
64
+ | `useHotkeyHint(hotkey, options?)` | Get whether held modifiers should reveal a shortcut's hint, such as labels that appear while Mod is held. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
65
+ | `useKeyHold(key)` | Get whether one key is held, such as Shift for a range-select mode. |
66
+ | `useHeldKeys()` | Get every key that's held right now. |
67
+ | `useHeldKeyCodes()` | Map each held key to its physical `event.code`. |
67
68
 
68
69
  The package also re-exports `@tanstack/hotkeys`, such as `formatForDisplay`, `matchesKeyboardEvent`, and `defineAppHotkeys`.
69
70