@tanstack/ember-hotkeys 0.15.0 → 0.16.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
@@ -3,6 +3,7 @@ import { UseHotkeys } from "./useHotkeys.js";
3
3
  import { useHeldKeys } from "./useHeldKeys.js";
4
4
  import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
5
5
  import { useKeyHold } from "./useKeyHold.js";
6
+ import { useKeyLockState } from "./useKeyLockState.js";
6
7
  import { useHotkeyHint } from "./useHotkeyHint.js";
7
8
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
8
9
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
@@ -18,4 +19,4 @@ import { EmberHotkeysScope, createHotkeysScope } from "./createHotkeysScope.js";
18
19
  import { OnHotkey } from "./onHotkey.js";
19
20
  import { ElementHotkeyOptions, OnHotkeys } from "./onHotkeys.js";
20
21
  export * from "@tanstack/hotkeys";
21
- export { DefaultHotkeysOptions, type ElementHotkeyOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, EmberHotkeysScope, createHotkeysScope, formatForAria, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyboardLayout };
22
+ export { DefaultHotkeysOptions, type ElementHotkeyOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, EmberHotkeysScope, createHotkeysScope, formatForAria, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyLockState, useKeyboardLayout };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { UseHotkeys } from "./useHotkeys.js";
3
3
  import { useHeldKeys } from "./useHeldKeys.js";
4
4
  import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
5
5
  import { useKeyHold } from "./useKeyHold.js";
6
+ import { useKeyLockState } from "./useKeyLockState.js";
6
7
  import { useHotkeyHint } from "./useHotkeyHint.js";
7
8
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
8
9
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
@@ -19,4 +20,4 @@ import { OnHotkeys } from "./onHotkeys.js";
19
20
 
20
21
  export * from "@tanstack/hotkeys"
21
22
 
22
- export { createHotkeysScope, formatForAria, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyboardLayout };
23
+ export { createHotkeysScope, formatForAria, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyLockState, useKeyboardLayout };
@@ -0,0 +1,35 @@
1
+ import { EmberHotkeyState } from "./types.js";
2
+ import { LockKey, MaybeGetter } from "@tanstack/hotkeys";
3
+ /**
4
+ * Returns whether a lock key, such as Caps Lock, is on. Pass the containing
5
+ * component as owner to release the subscription on destruction. Getter
6
+ * arguments can read changing tracked component properties.
7
+ *
8
+ * Lock keys toggle instead of being held, so this reads the lock state that
9
+ * the browser reports on key and mouse events. Its value is `null` until the
10
+ * user presses a key, clicks, or moves the mouse, after the window loses
11
+ * focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS.
12
+ *
13
+ * @param owner - The component that owns the subscription
14
+ * @param key - `'CapsLock'`, `'NumLock'`, or `'ScrollLock'`
15
+ * @returns A state whose `value` is `true` when the lock is on, `false` when
16
+ * it is off, or `null`
17
+ *
18
+ * @example
19
+ * ```gts
20
+ * class PasswordField extends Component {
21
+ * capsLock = useKeyLockState(this, 'CapsLock')
22
+ *
23
+ * <template>
24
+ * <label>
25
+ * Password
26
+ * <input type="password" />
27
+ * {{#if this.capsLock.value}}
28
+ * <span role="status">Caps Lock is on</span>
29
+ * {{/if}}
30
+ * </label>
31
+ * </template>
32
+ * }
33
+ * ```
34
+ */
35
+ export declare function useKeyLockState(owner: object, key: MaybeGetter<LockKey>): EmberHotkeyState<boolean | null>;
@@ -0,0 +1,42 @@
1
+ import { select } from "./utils.js";
2
+ import { getKeyStateTracker } from "@tanstack/hotkeys";
3
+ import { resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
4
+
5
+ // src/useKeyLockState.ts
6
+ /**
7
+ * Returns whether a lock key, such as Caps Lock, is on. Pass the containing
8
+ * component as owner to release the subscription on destruction. Getter
9
+ * arguments can read changing tracked component properties.
10
+ *
11
+ * Lock keys toggle instead of being held, so this reads the lock state that
12
+ * the browser reports on key and mouse events. Its value is `null` until the
13
+ * user presses a key, clicks, or moves the mouse, after the window loses
14
+ * focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS.
15
+ *
16
+ * @param owner - The component that owns the subscription
17
+ * @param key - `'CapsLock'`, `'NumLock'`, or `'ScrollLock'`
18
+ * @returns A state whose `value` is `true` when the lock is on, `false` when
19
+ * it is off, or `null`
20
+ *
21
+ * @example
22
+ * ```gts
23
+ * class PasswordField extends Component {
24
+ * capsLock = useKeyLockState(this, 'CapsLock')
25
+ *
26
+ * <template>
27
+ * <label>
28
+ * Password
29
+ * <input type="password" />
30
+ * {{#if this.capsLock.value}}
31
+ * <span role="status">Caps Lock is on</span>
32
+ * {{/if}}
33
+ * </label>
34
+ * </template>
35
+ * }
36
+ * ```
37
+ */
38
+ function useKeyLockState(owner, key) {
39
+ return select(owner, getKeyStateTracker().store, (state) => state.locks[resolveMaybeGetter(key)]);
40
+ }
41
+
42
+ export { useKeyLockState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ember-hotkeys",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Ember adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@embroider/addon-shim": "^1.11.0",
43
- "@tanstack/hotkeys": "0.37.0",
43
+ "@tanstack/hotkeys": "0.38.0",
44
44
  "ember-modifier": "^4.2.2"
45
45
  },
46
46
  "devDependencies": {
@@ -74,6 +74,7 @@ export default class Editor extends Component {
74
74
  | `useHotkeyScopesState(this)` | Get the active scopes and the exclusive scope that owns the keyboard. |
75
75
  | `useHotkeyHint(this, hotkey, options?)` | Get 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. |
76
76
  | `useKeyHold(this, key)` | Get whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
77
+ | `useKeyLockState(this, key)` | Read `.value`, whether `'CapsLock'`, `'NumLock'`, or `'ScrollLock'` is on: `true`, `false`, or `null` until a key press, click, or mouse move reports it. 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. |
77
78
  | `useHeldKeys(this)` | Get every key that's held right now. |
78
79
  | `useHeldKeyCodes(this)` | Map each held key to its physical `event.code`. |
79
80