@tanstack/svelte-hotkeys 0.26.0 → 0.27.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.
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LockKey } from '@tanstack/hotkeys';
|
|
2
|
+
export interface SvelteKeyLockState {
|
|
3
|
+
readonly value: boolean | null;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Svelte function that returns reactive access to whether a lock key, such as
|
|
7
|
+
* 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. Its `value` is `null` until the
|
|
11
|
+
* user presses a key, clicks, or moves the mouse, after the window loses
|
|
12
|
+
* focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS.
|
|
13
|
+
*
|
|
14
|
+
* @param key - `'CapsLock'`, `'NumLock'`, or `'ScrollLock'`
|
|
15
|
+
* @returns Object with a reactive `value` property: `true` when the lock is
|
|
16
|
+
* on, `false` when it is off, or `null`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```svelte
|
|
20
|
+
* <script>
|
|
21
|
+
* import { getKeyLockState } from '@tanstack/svelte-hotkeys'
|
|
22
|
+
*
|
|
23
|
+
* const capsLock = getKeyLockState('CapsLock')
|
|
24
|
+
* </script>
|
|
25
|
+
*
|
|
26
|
+
* <label>
|
|
27
|
+
* Password
|
|
28
|
+
* <input type="password" />
|
|
29
|
+
* {#if capsLock.value}
|
|
30
|
+
* <span role="status">Caps Lock is on</span>
|
|
31
|
+
* {/if}
|
|
32
|
+
* </label>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function getKeyLockState(key: LockKey): SvelteKeyLockState;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getKeyStateTracker } from '@tanstack/hotkeys';
|
|
2
|
+
import { createStoreSubscriber } from './internal.svelte.js';
|
|
3
|
+
class KeyLockState {
|
|
4
|
+
#tracker = getKeyStateTracker();
|
|
5
|
+
#key;
|
|
6
|
+
#subscribe = createStoreSubscriber(this.#tracker.store);
|
|
7
|
+
constructor(key) {
|
|
8
|
+
this.#key = key;
|
|
9
|
+
}
|
|
10
|
+
get value() {
|
|
11
|
+
this.#subscribe();
|
|
12
|
+
return this.#tracker.store.state.locks[this.#key];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Svelte function that returns reactive access to whether a lock key, such as
|
|
17
|
+
* Caps Lock, is on.
|
|
18
|
+
*
|
|
19
|
+
* Lock keys toggle instead of being held, so this reads the lock state that
|
|
20
|
+
* the browser reports on key and mouse events. Its `value` is `null` until the
|
|
21
|
+
* user presses a key, clicks, or moves the mouse, after the window loses
|
|
22
|
+
* focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS.
|
|
23
|
+
*
|
|
24
|
+
* @param key - `'CapsLock'`, `'NumLock'`, or `'ScrollLock'`
|
|
25
|
+
* @returns Object with a reactive `value` property: `true` when the lock is
|
|
26
|
+
* on, `false` when it is off, or `null`
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```svelte
|
|
30
|
+
* <script>
|
|
31
|
+
* import { getKeyLockState } from '@tanstack/svelte-hotkeys'
|
|
32
|
+
*
|
|
33
|
+
* const capsLock = getKeyLockState('CapsLock')
|
|
34
|
+
* </script>
|
|
35
|
+
*
|
|
36
|
+
* <label>
|
|
37
|
+
* Password
|
|
38
|
+
* <input type="password" />
|
|
39
|
+
* {#if capsLock.value}
|
|
40
|
+
* <span role="status">Caps Lock is on</span>
|
|
41
|
+
* {/if}
|
|
42
|
+
* </label>
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function getKeyLockState(key) {
|
|
46
|
+
return new KeyLockState(key);
|
|
47
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './getHotkeyRegistrations.svelte.js';
|
|
|
7
7
|
export * from './getHotkeyScopesState.svelte.js';
|
|
8
8
|
export * from './getHeldKeyCodesMap.svelte.js';
|
|
9
9
|
export * from './getIsKeyHeld.svelte.js';
|
|
10
|
+
export * from './getKeyLockState.svelte.js';
|
|
10
11
|
export * from './getAppHotkeys.svelte.js';
|
|
11
12
|
export { default as HotkeysProvider } from './HotkeysProvider.svelte';
|
|
12
13
|
export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkeysContext, } from './HotkeysCtx.js';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './getHotkeyRegistrations.svelte.js';
|
|
|
8
8
|
export * from './getHotkeyScopesState.svelte.js';
|
|
9
9
|
export * from './getHeldKeyCodesMap.svelte.js';
|
|
10
10
|
export * from './getIsKeyHeld.svelte.js';
|
|
11
|
+
export * from './getKeyLockState.svelte.js';
|
|
11
12
|
export * from './getAppHotkeys.svelte.js';
|
|
12
13
|
export { default as HotkeysProvider } from './HotkeysProvider.svelte';
|
|
13
14
|
export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkeysContext, } from './HotkeysCtx.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Svelte adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Kunal Rao",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"skills"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@tanstack/hotkeys": "0.
|
|
44
|
+
"@tanstack/hotkeys": "0.38.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@sveltejs/package": "^3.0.2",
|
|
@@ -75,6 +75,7 @@ Before starting, load the `@tanstack/hotkeys#hotkeys-core` skill (`npx @tanstack
|
|
|
75
75
|
| `getHotkeyScopesState()` | Read `.state`, the active scopes and the exclusive scope that owns the keyboard. |
|
|
76
76
|
| `getHotkeyHint(hotkey, options?)` | Read `.visible`, 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. |
|
|
77
77
|
| `getIsKeyHeld(key)` | Read `.held`, whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
|
|
78
|
+
| `getKeyLockState(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 `getIsKeyHeld`, which is true only while the key is down. |
|
|
78
79
|
| `getHeldKeys()` | Read `.keys`, every key that's held right now. |
|
|
79
80
|
| `getHeldKeyCodesMap()` | Read `.codes`, which maps each held key to its physical `event.code`. |
|
|
80
81
|
|