@tanstack/vue-hotkeys 0.26.0 → 0.27.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
@@ -5,6 +5,7 @@ import { UseHotkeyDefinition, useHotkeys } from "./useHotkeys.js";
5
5
  import { useHeldKeys } from "./useHeldKeys.js";
6
6
  import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
7
7
  import { useKeyHold } from "./useKeyHold.js";
8
+ import { useKeyLockState } from "./useKeyLockState.js";
8
9
  import { VueHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
9
10
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
11
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
@@ -16,4 +17,4 @@ import { formatForAria } from "./formatForAria.js";
16
17
  import { useKeyboardLayout } from "./useKeyboardLayout.js";
17
18
  import { UseCustomHotkeysResult, useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
18
19
  export * from "@tanstack/hotkeys";
19
- export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, formatForAria, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
20
+ export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, formatForAria, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyLockState, useKeyboardLayout };
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { useHotkeys } from "./useHotkeys.js";
5
5
  import { useHeldKeys } from "./useHeldKeys.js";
6
6
  import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
7
7
  import { useKeyHold } from "./useKeyHold.js";
8
+ import { useKeyLockState } from "./useKeyLockState.js";
8
9
  import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
9
10
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
11
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
@@ -18,4 +19,4 @@ import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotke
18
19
 
19
20
  export * from "@tanstack/hotkeys"
20
21
 
21
- export { HotkeysProvider, formatForAria, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
22
+ export { HotkeysProvider, formatForAria, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyLockState, useKeyboardLayout };
@@ -0,0 +1,36 @@
1
+ import { LockKey } from "@tanstack/hotkeys";
2
+ import { ComputedRef, MaybeRefOrGetter } from "vue";
3
+ /**
4
+ * Vue composable that returns a reactive ref telling whether a lock key, such
5
+ * as Caps Lock, is on.
6
+ *
7
+ * Lock keys toggle instead of being held, so this reads the lock state that
8
+ * the browser reports on key and mouse events. It is `null` until the user
9
+ * presses a key, clicks, or moves the mouse, after the window loses focus or the page is hidden,
10
+ * and always for Num Lock and Scroll Lock on macOS and iOS. The key may be a
11
+ * ref or getter; the result follows it without waiting for an event.
12
+ * Pressing or releasing a key that doesn't change the lock state doesn't
13
+ * notify anything that reads the ref.
14
+ *
15
+ * @param key - `'CapsLock'`, `'NumLock'`, or `'ScrollLock'`
16
+ * @returns Read-only reactive ref that is `true` when the lock is on, `false`
17
+ * when it is off, or `null`
18
+ *
19
+ * @example
20
+ * ```vue
21
+ * <script setup>
22
+ * import { useKeyLockState } from '@tanstack/vue-hotkeys'
23
+ *
24
+ * const capsLock = useKeyLockState('CapsLock')
25
+ * </script>
26
+ *
27
+ * <template>
28
+ * <label>
29
+ * Password
30
+ * <input type="password" />
31
+ * <span v-if="capsLock" role="status">Caps Lock is on</span>
32
+ * </label>
33
+ * </template>
34
+ * ```
35
+ */
36
+ export declare function useKeyLockState(key: MaybeRefOrGetter<LockKey>): ComputedRef<boolean | null>;
@@ -0,0 +1,55 @@
1
+ import { getKeyStateTracker } from "@tanstack/hotkeys";
2
+ import { computed, onScopeDispose, shallowRef, toValue } from "vue";
3
+
4
+ // src/useKeyLockState.ts
5
+ /**
6
+ * Vue composable that returns a reactive ref telling whether a lock key, such
7
+ * as Caps Lock, is on.
8
+ *
9
+ * Lock keys toggle instead of being held, so this reads the lock state that
10
+ * the browser reports on key and mouse events. It is `null` until the user
11
+ * presses a key, clicks, or moves the mouse, after the window loses focus or the page is hidden,
12
+ * and always for Num Lock and Scroll Lock on macOS and iOS. The key may be a
13
+ * ref or getter; the result follows it without waiting for an event.
14
+ * Pressing or releasing a key that doesn't change the lock state doesn't
15
+ * notify anything that reads the ref.
16
+ *
17
+ * @param key - `'CapsLock'`, `'NumLock'`, or `'ScrollLock'`
18
+ * @returns Read-only reactive ref that is `true` when the lock is on, `false`
19
+ * when it is off, or `null`
20
+ *
21
+ * @example
22
+ * ```vue
23
+ * <script setup>
24
+ * import { useKeyLockState } from '@tanstack/vue-hotkeys'
25
+ *
26
+ * const capsLock = useKeyLockState('CapsLock')
27
+ * <\/script>
28
+ *
29
+ * <template>
30
+ * <label>
31
+ * Password
32
+ * <input type="password" />
33
+ * <span v-if="capsLock" role="status">Caps Lock is on</span>
34
+ * </label>
35
+ * </template>
36
+ * ```
37
+ */
38
+ function useKeyLockState(key) {
39
+ const tracker = getKeyStateTracker();
40
+ const read = () => tracker.store.state.locks[toValue(key)];
41
+ const changes = shallowRef(0);
42
+ let last = read();
43
+ if (typeof document !== "undefined") {
44
+ const { unsubscribe } = tracker.store.subscribe(() => {
45
+ if (read() !== last) changes.value++;
46
+ });
47
+ onScopeDispose(unsubscribe);
48
+ }
49
+ return computed(() => {
50
+ changes.value;
51
+ return last = read();
52
+ });
53
+ }
54
+
55
+ export { useKeyLockState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-hotkeys",
3
- "version": "0.26.0",
3
+ "version": "0.27.1",
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.37.0"
41
+ "@tanstack/hotkeys": "0.39.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@tanstack/hotkeys-test-utils": "0.0.0",
@@ -71,6 +71,7 @@ const formatForDisplay = useFormatForDisplay()
71
71
  | `useHotkeyScopesState()` | Get a ref of the active scopes and the exclusive scope that owns the keyboard. |
72
72
  | `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. |
73
73
  | `useKeyHold(key)` | Get a ref of whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
74
+ | `useKeyLockState(key)` | Get a read-only ref of whether `'CapsLock'`, `'NumLock'`, or `'ScrollLock'` is on: `true`, `false`, or `null` until a key press, click, or mouse move reports it. Accepts a ref or getter. Resets to `null` when the window loses focus. Num Lock and Scroll Lock are always `null` on macOS and iOS. Use it for lock state, not `useKeyHold`, which is true only while the key is down. |
74
75
  | `useHeldKeys()` | Get a ref of every key that's held right now. |
75
76
  | `useHeldKeyCodes()` | Get a ref mapping each held key to its physical `event.code`. |
76
77