@tanstack/vue-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.
package/dist/index.d.ts CHANGED
@@ -7,7 +7,8 @@ import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
7
7
  import { useKeyHold } from "./useKeyHold.js";
8
8
  import { VueHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
9
9
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
+ import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
10
11
  import { useHotkeyHint } from "./useHotkeyHint.js";
11
12
  import { UseCustomHotkeysResult, useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
12
13
  export * from "@tanstack/hotkeys";
13
- export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeys, useHotkeysContext, useKeyHold };
14
+ export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold };
package/dist/index.js CHANGED
@@ -7,9 +7,10 @@ import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
7
7
  import { useKeyHold } from "./useKeyHold.js";
8
8
  import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
9
9
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
+ import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
10
11
  import { useHotkeyHint } from "./useHotkeyHint.js";
11
12
  import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
12
13
 
13
14
  export * from "@tanstack/hotkeys"
14
15
 
15
- export { HotkeysProvider, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeys, useHotkeysContext, useKeyHold };
16
+ export { HotkeysProvider, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold };
@@ -3,10 +3,11 @@ import { ComputedRef, MaybeRefOrGetter } from "vue";
3
3
  //#region src/useHotkeyHint.d.ts
4
4
  /**
5
5
  * Returns a computed ref indicating whether held modifiers reveal this shortcut.
6
- * Pass refs or getters to track changing hotkeys and options. A sequence
7
- * reveals its hint from its first step, and an app hotkey uses its effective
8
- * hotkey (false while unbound). This helper does not register a shortcut or
9
- * check whether its target is focused.
6
+ * The hint shows only while the hotkey can fire: some registration of it is
7
+ * enabled and in an active scope. Pass refs or getters to track changing
8
+ * hotkeys and options. A sequence reveals its hint from its first step, and
9
+ * an app hotkey matches its registrations by id and uses its effective hotkey
10
+ * (false while unbound). This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
10
11
  */
11
12
  export declare function useHotkeyHint(hotkey: MaybeRefOrGetter<RegisterableHotkey | AppHotkey>, options?: MaybeRefOrGetter<HeldModifierOptions>): ComputedRef<boolean>;
12
13
  //#endregion
@@ -1,24 +1,27 @@
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 { computed, toValue } from "vue";
4
4
  import { useSelector } from "@tanstack/vue-store";
5
5
 
6
6
  //#region src/useHotkeyHint.ts
7
7
  /**
8
8
  * Returns a computed ref indicating whether held modifiers reveal this shortcut.
9
- * Pass refs or getters to track changing hotkeys and options. A sequence
10
- * reveals its hint from its first step, and an app hotkey uses its effective
11
- * hotkey (false while unbound). This helper does not register a shortcut or
12
- * 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. Pass refs or getters to track changing
11
+ * hotkeys and options. A sequence reveals its hint from its first step, and
12
+ * an app hotkey matches its registrations by id and uses its effective hotkey
13
+ * (false while unbound). This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
13
14
  */
14
15
  function useHotkeyHint(hotkey, options = {}) {
15
16
  const appHotkeys = useAppHotkeysStoreSource();
17
+ const manager = getHotkeyManager();
18
+ const registrations = useSelector(manager.registrations, (state) => state);
16
19
  const held = useSelector(getKeyStateTracker().store, (state) => state.heldKeys);
17
20
  return computed(() => {
18
21
  appHotkeys.state.value;
19
22
  const value = toValue(hotkey);
20
23
  const resolved = isAppHotkey(value) ? resolveAppHotkey(value, appHotkeys.store).hotkey : value;
21
- return resolved !== null && matchesHeldModifiers(resolved, held.value, toValue(options));
24
+ return resolved !== null && matchesHeldModifiers(resolved, held.value, toValue(options)) && registrations.value.size > 0 && manager.hasActiveRegistration(value);
22
25
  });
23
26
  }
24
27
 
@@ -0,0 +1,25 @@
1
+ import { HotkeyScopesState } from "@tanstack/hotkeys";
2
+ import { Ref } from "vue";
3
+ //#region src/useHotkeyScopesState.d.ts
4
+ /**
5
+ * Vue composable that returns a ref of the hotkey manager's scope state: the
6
+ * active scopes, the exclusive scope that owns the keyboard, and the scopes
7
+ * it allows or suspends. Updates when scopes activate or release.
8
+ *
9
+ * @returns Reactive ref of the current scope state
10
+ *
11
+ * @example
12
+ * ```vue
13
+ * <script setup>
14
+ * import { useHotkeyScopesState } from '@tanstack/vue-hotkeys'
15
+ *
16
+ * const scopes = useHotkeyScopesState()
17
+ * </script>
18
+ *
19
+ * <template>
20
+ * <p v-if="scopes.exclusive">Shortcuts belong to {{ scopes.exclusive }}</p>
21
+ * </template>
22
+ * ```
23
+ */
24
+ export declare function useHotkeyScopesState(): Ref<HotkeyScopesState>;
25
+ //#endregion
@@ -0,0 +1,30 @@
1
+ import { getHotkeyManager } from "@tanstack/hotkeys";
2
+ import { useSelector } from "@tanstack/vue-store";
3
+
4
+ //#region src/useHotkeyScopesState.ts
5
+ /**
6
+ * Vue composable that returns a ref of the hotkey manager's scope state: the
7
+ * active scopes, the exclusive scope that owns the keyboard, and the scopes
8
+ * it allows or suspends. Updates when scopes activate or release.
9
+ *
10
+ * @returns Reactive ref of the current scope state
11
+ *
12
+ * @example
13
+ * ```vue
14
+ * <script setup>
15
+ * import { useHotkeyScopesState } from '@tanstack/vue-hotkeys'
16
+ *
17
+ * const scopes = useHotkeyScopesState()
18
+ * <\/script>
19
+ *
20
+ * <template>
21
+ * <p v-if="scopes.exclusive">Shortcuts belong to {{ scopes.exclusive }}</p>
22
+ * </template>
23
+ * ```
24
+ */
25
+ function useHotkeyScopesState() {
26
+ return useSelector(getHotkeyManager().scopes, (state) => state);
27
+ }
28
+
29
+ //#endregion
30
+ export { useHotkeyScopesState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-hotkeys",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Vue 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/vue-store": "^0.11.2"
43
43
  },
44
44
  "devDependencies": {
@@ -52,23 +52,24 @@ useHotkey('Escape', () => closePanel(), { target: panel })
52
52
 
53
53
  ## API
54
54
 
55
- | API | What it's for |
56
- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
57
- | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted; the hotkey and options can be refs or getters. |
58
- | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a ref or getter of a list built from data, in one call. |
59
- | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for its children, and emit `custom-hotkeys-change`. |
60
- | `provideHotkeysContext(options)` | Provide the same options from a component's setup instead of rendering `HotkeysProvider`; they apply to its children. |
61
- | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
62
- | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
63
- | `useAppHotkeys()` | Get a computed ref of the declared app hotkeys with the user's custom hotkeys applied. |
64
- | `useAppHotkeyList()` | Get a computed ref listing every app hotkey with its status, for a cheat sheet or settings screen. |
65
- | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
66
- | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses; destructure the refs it returns. |
67
- | `useHotkeyRegistrations()` | Get a ref listing every registered hotkey with its options and `meta`. |
68
- | `useHotkeyHint(hotkey, options?)` | Get a computed ref of whether held modifiers should reveal a shortcut's hint. |
69
- | `useKeyHold(key)` | Get a ref of whether one key is held. |
70
- | `useHeldKeys()` | Get a ref of every key that's held right now. |
71
- | `useHeldKeyCodes()` | Get a ref mapping each held key to its physical `event.code`. |
55
+ | API | What it's for |
56
+ | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
57
+ | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted; the hotkey and options can be refs or getters. |
58
+ | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a ref or getter of a list built from data, in one call. |
59
+ | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for its children, and emit `custom-hotkeys-change`. |
60
+ | `provideHotkeysContext(options)` | Provide the same options from a component's setup instead of rendering `HotkeysProvider`; they apply to its children. |
61
+ | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
62
+ | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
63
+ | `useAppHotkeys()` | Get a computed ref of the declared app hotkeys with the user's custom hotkeys applied. |
64
+ | `useAppHotkeyList()` | Get a computed ref listing every app hotkey with its status, for a cheat sheet or settings screen. |
65
+ | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
66
+ | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses; destructure the refs it returns. |
67
+ | `useHotkeyRegistrations()` | Get a ref listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
68
+ | `useHotkeyScopesState()` | Get a ref of the active scopes and the exclusive scope that owns the keyboard. |
69
+ | `useHotkeyHint(hotkey, options?)` | Get a computed ref 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. |
70
+ | `useKeyHold(key)` | Get a ref of whether one key is held. |
71
+ | `useHeldKeys()` | Get a ref of every key that's held right now. |
72
+ | `useHeldKeyCodes()` | Get a ref mapping each held key to its physical `event.code`. |
72
73
 
73
74
  The package also re-exports `@tanstack/hotkeys`, such as `formatForDisplay`, `matchesKeyboardEvent`, and `defineAppHotkeys`.
74
75