@tanstack/octane-hotkeys 0.11.2 → 0.12.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,7 +1,12 @@
|
|
|
1
1
|
import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey, Target } from "@tanstack/hotkeys";
|
|
2
2
|
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A ref object, element, document, or window to listen on. A `null` or
|
|
5
|
+
* `undefined` target, or a ref that is still unset, waits for the element.
|
|
6
|
+
*/
|
|
7
|
+
export type UseHotkeyTarget = {
|
|
8
|
+
current: HTMLElement | null | undefined;
|
|
9
|
+
} | Target | null;
|
|
5
10
|
/** Options shared by chords and sequences. */
|
|
6
11
|
export type UseHotkeyOptions = AdapterHotkeyOptions<UseHotkeyTarget>;
|
|
7
12
|
/** Options for a chord such as `'Mod+S'`. */
|
package/dist/useHotkeys.js
CHANGED
|
@@ -17,7 +17,7 @@ function useHotkeys(definitions, ...rest) {
|
|
|
17
17
|
appHotkeysStore,
|
|
18
18
|
defaults: context?.defaultOptions.hotkey,
|
|
19
19
|
commonOptions,
|
|
20
|
-
resolveTarget: (target) => target
|
|
20
|
+
resolveTarget: (target) => target && "current" in target ? target.current : target
|
|
21
21
|
}));
|
|
22
22
|
}, null, subSlot(slot, "update"));
|
|
23
23
|
useLayoutEffect(() => () => bindings.destroy(), [], subSlot(slot, "cleanup"));
|
package/dist/useKeyHold.js
CHANGED
|
@@ -3,7 +3,8 @@ import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
|
3
3
|
|
|
4
4
|
// src/useKeyHold.ts
|
|
5
5
|
function useKeyHold(key, slot) {
|
|
6
|
-
|
|
6
|
+
const tracker = getKeyStateTracker();
|
|
7
|
+
return select(tracker.store, () => tracker.isKeyHeld(key), subSlot(slot, "key-hold"));
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export { useKeyHold };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/octane-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Octane adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,9 +35,10 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
38
|
+
"@tanstack/hotkeys": "0.27.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
+
"@tanstack/hotkeys-test-utils": "0.0.0",
|
|
41
42
|
"@tsrx/oxc": "0.23.0",
|
|
42
43
|
"@tsrx/typescript-plugin": "^0.6.3",
|
|
43
44
|
"octane": "0.16.7",
|
|
@@ -63,7 +63,7 @@ export function Panel({ onSave }: { onSave: () => void }) @{
|
|
|
63
63
|
| `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. |
|
|
64
64
|
| `useHotkeyScopesState()` | Get the active scopes and the exclusive scope that owns the keyboard. |
|
|
65
65
|
| `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. |
|
|
66
|
-
| `useKeyHold(key)` | Get whether one key is held, such as Shift for a range-select mode.
|
|
66
|
+
| `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. |
|
|
67
67
|
| `useHeldKeys()` | Get every key that's held right now. |
|
|
68
68
|
| `useHeldKeyCodes()` | Map each held key to its physical `event.code`. |
|
|
69
69
|
|
|
@@ -73,7 +73,7 @@ No provider is required. Use Octane 0.12 or newer, with hooks in compiler-enable
|
|
|
73
73
|
|
|
74
74
|
## Pitfalls
|
|
75
75
|
|
|
76
|
-
- **
|
|
76
|
+
- **Keep elements that mount later in state.** A ref object such as `useRef<HTMLDivElement | null>(null)` works as `target`, but the hook reads `ref.current` only after its component renders, so it misses an element that mounts later, such as one a child shows from its own state. Keep such an element in state with a callback ref, as above. A `null` or `undefined` target, or an unset ref, waits for the element.
|
|
77
77
|
- **Register a dialog's hotkeys in a child of its provider.** A hook uses the nearest `HotkeysProvider` above its component, so a dialog that renders `<HotkeysProvider scope={...} exclusive>` and registers `Escape` itself puts it in the suspended outer scope. Give each open dialog its own scope name, such as `` `dialog-${useId()}` ``.
|
|
78
78
|
- **Hooks are tracked by call site.** Use `useHotkeys(items.map(...))` for lists, not `useHotkey` in a loop.
|
|
79
79
|
- **Custom hooks in plain `.ts` and `.js` files need the compiler.** Calls from a `.ts` or `.js` file that the compiler skips share one slot per hook in each component, even across different custom hooks, so only the last `useHotkey` call works. The compiler handles a file that imports a value from `octane` or starts with `/** @jsxImportSource octane */`. A type-only import doesn't count. `.tsrx` and `.tsx` files are fine.
|