@tanstack/alpine-hotkeys 0.16.0 → 0.17.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.
|
@@ -9,6 +9,7 @@ import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
|
9
9
|
import { createHotkeyScopesState } from "./createHotkeyScopesState.js";
|
|
10
10
|
import { createHotkeys } from "./createHotkeys.js";
|
|
11
11
|
import { createKeyHold } from "./createKeyHold.js";
|
|
12
|
+
import { createKeyLockState } from "./createKeyLockState.js";
|
|
12
13
|
import { createKeyboardLayout } from "./createKeyboardLayout.js";
|
|
13
14
|
import { createScope, ownerScopes } from "./scope.js";
|
|
14
15
|
|
|
@@ -26,6 +27,7 @@ function createHotkeysScope(defaultOptions = {}) {
|
|
|
26
27
|
createHeldKeys: (...args) => createHeldKeys(scope, ...args),
|
|
27
28
|
createHeldKeyCodes: (...args) => createHeldKeyCodes(scope, ...args),
|
|
28
29
|
createKeyHold: (...args) => createKeyHold(scope, ...args),
|
|
30
|
+
createKeyLockState: (...args) => createKeyLockState(scope, ...args),
|
|
29
31
|
createHotkeyHint: (...args) => createHotkeyHint(scope, ...args),
|
|
30
32
|
createHotkeyRegistrations: (...args) => createHotkeyRegistrations(scope, ...args),
|
|
31
33
|
createHotkeyScopesState: () => createHotkeyScopesState(scope),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
+
import { resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
|
+
|
|
4
|
+
// src/createKeyLockState.ts
|
|
5
|
+
function createKeyLockState(scope, key) {
|
|
6
|
+
const tracker = getKeyStateTracker();
|
|
7
|
+
return scope.select(tracker.store, (state) => state.locks[resolveMaybeGetter(key)]);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { createKeyLockState };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppHotkey, CustomHotkeyActions, CustomHotkeys, HeldModifierOptions, Hotkey, HotkeyCallback, HotkeyCallbackContextFor, HotkeyChord, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeyRecorderActions, HotkeyRecorderOptions, HotkeyRecorderState, HotkeyRegistrationsResult, HotkeyScopesState, HotkeySequenceRecorderOptions, IndividualKey, KeyboardLayoutMap, MaybeGetter, RegisterableHotkey, RegisteredAppHotkeyListItem, RegisteredAppHotkeys, Target, formatForAria, formatForDisplay } from "@tanstack/hotkeys";
|
|
1
|
+
import { AppHotkey, CustomHotkeyActions, CustomHotkeys, HeldModifierOptions, Hotkey, HotkeyCallback, HotkeyCallbackContextFor, HotkeyChord, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeyRecorderActions, HotkeyRecorderOptions, HotkeyRecorderState, HotkeyRegistrationsResult, HotkeyScopesState, HotkeySequenceRecorderOptions, IndividualKey, KeyboardLayoutMap, LockKey, MaybeGetter, RegisterableHotkey, RegisteredAppHotkeyListItem, RegisteredAppHotkeys, Target, formatForAria, formatForDisplay } from "@tanstack/hotkeys";
|
|
2
2
|
import { AdapterAppHotkeyOptions, AdapterCommonOptions, AdapterHotkeyDefinition, AdapterOptionsFor, HotkeyRecorderDefaults } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
/** A reactive value. Read `.value` where the framework tracks dependencies. */
|
|
4
4
|
export interface AlpineHotkeyState<T> {
|
|
@@ -53,6 +53,42 @@ export interface AlpineHotkeys {
|
|
|
53
53
|
createHeldKeyCodes: () => AlpineHotkeyState<Record<string, string>>;
|
|
54
54
|
/** Read whether a key is held through `.value`. */
|
|
55
55
|
createKeyHold: (key: MaybeGetter<IndividualKey>) => AlpineHotkeyState<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Read whether a lock key, such as Caps Lock, is on through `.value`: `true`
|
|
58
|
+
* when the lock is on, `false` when it is off, or `null`. Pass
|
|
59
|
+
* `'CapsLock'`, `'NumLock'`, or `'ScrollLock'`, or a getter.
|
|
60
|
+
*
|
|
61
|
+
* Lock keys toggle instead of being held, so this reads the lock state that
|
|
62
|
+
* the browser reports on key and mouse events. `.value` is `null` until the
|
|
63
|
+
* user presses a key, clicks, or moves the mouse, after the window loses
|
|
64
|
+
* focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* Alpine.data('passwordField', () => {
|
|
69
|
+
* const hotkeys = createHotkeysScope()
|
|
70
|
+
* const capsLock = hotkeys.createKeyLockState('CapsLock')
|
|
71
|
+
*
|
|
72
|
+
* return {
|
|
73
|
+
* get capsLockOn() {
|
|
74
|
+
* return capsLock.value === true
|
|
75
|
+
* },
|
|
76
|
+
* destroy() {
|
|
77
|
+
* hotkeys.destroy()
|
|
78
|
+
* },
|
|
79
|
+
* }
|
|
80
|
+
* })
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* ```html
|
|
84
|
+
* <label x-data="passwordField">
|
|
85
|
+
* Password
|
|
86
|
+
* <input type="password" />
|
|
87
|
+
* <span x-show="capsLockOn" role="status">Caps Lock is on</span>
|
|
88
|
+
* </label>
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
createKeyLockState: (key: MaybeGetter<LockKey>) => AlpineHotkeyState<boolean | null>;
|
|
56
92
|
/**
|
|
57
93
|
* Read whether held modifiers reveal a hotkey through `.value`. No hotkey
|
|
58
94
|
* (`undefined`, `null`, or `''`) is never visible.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/alpine-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "Alpine 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.
|
|
38
|
+
"@tanstack/hotkeys": "0.39.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@alpinejs/csp": "3.17.5",
|
|
@@ -91,6 +91,7 @@ Each owner has these methods. Read their state through `.value`, or `.hotkeys` f
|
|
|
91
91
|
| `createHotkeyScopesState()` | Get the active scopes and the exclusive scope that owns the keyboard. |
|
|
92
92
|
| `createHotkeyHint(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. |
|
|
93
93
|
| `createKeyHold(key)` | Get whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
|
|
94
|
+
| `createKeyLockState(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 `createKeyHold`, which is true only while the key is down. |
|
|
94
95
|
| `createHeldKeys()` | Get every key that's held right now. |
|
|
95
96
|
| `createHeldKeyCodes()` | Map each held key to its physical `event.code`. |
|
|
96
97
|
| `destroy()` | Release every hotkey, subscription, and recorder the owner created. |
|