@tanstack/preact-hotkeys 0.20.3 → 0.21.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/useHotkey.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
2
|
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
import { RefObject } from "preact";
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A Preact ref, element, document, or window to listen on. A `null` or
|
|
6
|
+
* `undefined` target, or a ref that is still unset, waits for the element.
|
|
7
|
+
*/
|
|
8
|
+
export type UseHotkeyTarget = RefObject<HTMLElement | null | undefined> | HTMLElement | Document | Window | null;
|
|
6
9
|
/** Options shared by chords and sequences. */
|
|
7
10
|
export type UseHotkeyOptions = AdapterHotkeyOptions<UseHotkeyTarget>;
|
|
8
11
|
/** Options for a chord such as `'Mod+S'`. */
|
|
@@ -24,8 +24,9 @@ export interface PreactHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
|
|
|
24
24
|
* `commitKeys: 'none'`), after `idleTimeoutMs`, or when it reaches `maxSteps`,
|
|
25
25
|
* and `onRecord` receives a chord (one step) or a sequence.
|
|
26
26
|
*
|
|
27
|
-
* Escape cancels
|
|
28
|
-
* when nothing is
|
|
27
|
+
* Escape cancels, and so do Tab and Shift+Tab unless `recordTab` is set.
|
|
28
|
+
* Backspace/Delete removes the last step, or calls `onClear` when nothing is
|
|
29
|
+
* recorded.
|
|
29
30
|
*
|
|
30
31
|
* @param options - Configuration options for the recorder
|
|
31
32
|
* @returns The recorder state and controls
|
package/dist/useKeyHold.js
CHANGED
|
@@ -43,8 +43,7 @@ import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
|
43
43
|
*/
|
|
44
44
|
function useKeyHold(key) {
|
|
45
45
|
const tracker = getKeyStateTracker();
|
|
46
|
-
|
|
47
|
-
return useSelector(tracker.store, (state) => state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey));
|
|
46
|
+
return useSelector(tracker.store, () => tracker.isKeyHeld(key));
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
export { useKeyHold };
|
package/dist/utils.js
CHANGED
|
@@ -6,7 +6,7 @@ function isRef(value) {
|
|
|
6
6
|
return value !== null && typeof value === "object" && "current" in value;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Resolves a hook target. A null target, or a ref that is still
|
|
9
|
+
* Resolves a hook target. A null target, or a ref that is still unset, skips
|
|
10
10
|
* registration. Omit the target to listen on the document.
|
|
11
11
|
*/
|
|
12
12
|
function resolveTarget(target) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Preact adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,10 +35,11 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
38
|
+
"@tanstack/hotkeys": "0.27.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@preact/preset-vite": "^2.10.6",
|
|
42
|
+
"@tanstack/hotkeys-test-utils": "0.0.0",
|
|
42
43
|
"@testing-library/preact": "^3.2.6",
|
|
43
44
|
"preact": "^11.2.0"
|
|
44
45
|
},
|
|
@@ -50,8 +51,9 @@
|
|
|
50
51
|
"lint": "oxlint ./src",
|
|
51
52
|
"lint:fix": "oxlint ./src --fix",
|
|
52
53
|
"test:oxlint": "oxlint ./src",
|
|
53
|
-
"test:lib": "vitest
|
|
54
|
+
"test:lib": "vitest",
|
|
54
55
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
56
|
+
"test:coverage": "vitest --coverage",
|
|
55
57
|
"test:types": "tsc",
|
|
56
58
|
"build": "tsdown",
|
|
57
59
|
"test:build": "publint --strict && node ../../scripts/verify-package.ts"
|
|
@@ -60,7 +60,7 @@ export function SaveButton({ onSave }: { onSave: () => void }) {
|
|
|
60
60
|
| `useHotkeyRegistrations()` | List every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope), for a cheat sheet of what's mounted. |
|
|
61
61
|
| `useHotkeyScopesState()` | Get the active scopes and the exclusive scope that owns the keyboard. |
|
|
62
62
|
| `useHotkeyHint(hotkey, options?)` | Get whether held modifiers should reveal a shortcut's hint, such as labels that appear while Mod is held. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
|
|
63
|
-
| `useKeyHold(key)` | Get whether one key is held, such as Shift for a range-select mode.
|
|
63
|
+
| `useKeyHold(key)` | Get whether one key is held, such as Shift for a range-select mode. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
|
|
64
64
|
| `useHeldKeys()` | Get every key that's held right now. |
|
|
65
65
|
| `useHeldKeyCodes()` | Map each held key to its physical `event.code`. |
|
|
66
66
|
|