@tanstack/vue-hotkeys 0.21.3 → 0.21.4
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 +7 -4
- package/dist/useHotkeys.d.ts +2 -1
- package/dist/useHotkeys.js +8 -2
- package/package.json +2 -2
- package/skills/vue-hotkeys/SKILL.md +1 -0
package/dist/useHotkey.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey, Target } from "@tanstack/hotkeys";
|
|
2
|
-
import { MaybeRefOrGetter } from "vue";
|
|
2
|
+
import { ComponentPublicInstance, MaybeRefOrGetter } from "vue";
|
|
3
3
|
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
|
|
4
4
|
/**
|
|
5
|
-
* The element to listen on: a ref, getter, element, or
|
|
6
|
-
*
|
|
5
|
+
* The element to listen on: a ref, getter, element, or component instance,
|
|
6
|
+
* such as a template ref on a component, which listens on its root element.
|
|
7
|
+
* A target that resolves to `null` or `undefined`, or a component without a
|
|
8
|
+
* single root element, skips registration until it is set. Omit it for the
|
|
9
|
+
* document.
|
|
7
10
|
*/
|
|
8
|
-
export type UseHotkeyTarget = MaybeRefOrGetter<Target | null>;
|
|
11
|
+
export type UseHotkeyTarget = MaybeRefOrGetter<Target | ComponentPublicInstance | null | undefined>;
|
|
9
12
|
/** Lets `enabled` be a ref or getter. */
|
|
10
13
|
type WithReactiveEnabled<TOptions> = Omit<TOptions, 'enabled'> & {
|
|
11
14
|
/** Whether the hotkey is active. Can be a ref, getter, or boolean. Defaults to true. */
|
package/dist/useHotkeys.d.ts
CHANGED
|
@@ -40,7 +40,8 @@ export type UseHotkeyDefinition = {
|
|
|
40
40
|
* commonOptions, per-hotkey options. Each option applies only to the kinds
|
|
41
41
|
* that support it. Unbound app hotkeys, empty sequences, and `undefined`,
|
|
42
42
|
* `null`, or `''` hotkeys register nothing.
|
|
43
|
-
* A target that resolves to `null` skips registration until it
|
|
43
|
+
* A target that resolves to `null` or `undefined` skips registration until it
|
|
44
|
+
* is set. A component target listens on its root element.
|
|
44
45
|
*
|
|
45
46
|
* @example
|
|
46
47
|
* ```ts
|
package/dist/useHotkeys.js
CHANGED
|
@@ -21,7 +21,8 @@ function resolveEnabled(options) {
|
|
|
21
21
|
* commonOptions, per-hotkey options. Each option applies only to the kinds
|
|
22
22
|
* that support it. Unbound app hotkeys, empty sequences, and `undefined`,
|
|
23
23
|
* `null`, or `''` hotkeys register nothing.
|
|
24
|
-
* A target that resolves to `null` skips registration until it
|
|
24
|
+
* A target that resolves to `null` or `undefined` skips registration until it
|
|
25
|
+
* is set. A component target listens on its root element.
|
|
25
26
|
*
|
|
26
27
|
* @example
|
|
27
28
|
* ```ts
|
|
@@ -48,7 +49,12 @@ function useHotkeys(hotkeys, commonOptions = {}) {
|
|
|
48
49
|
appHotkeysStore: appHotkeys.store,
|
|
49
50
|
defaults: resolveEnabled(defaultOptions().hotkey),
|
|
50
51
|
commonOptions: resolveEnabled(toValue(commonOptions)),
|
|
51
|
-
resolveTarget: (target) =>
|
|
52
|
+
resolveTarget: (target) => {
|
|
53
|
+
const value = toValue(target);
|
|
54
|
+
if (!value || !("$el" in value)) return value;
|
|
55
|
+
const element = value.$el;
|
|
56
|
+
return element?.nodeType === 1 ? element : null;
|
|
57
|
+
}
|
|
52
58
|
});
|
|
53
59
|
}, (definitions) => bindings.update(definitions), { immediate: true });
|
|
54
60
|
onScopeDispose(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-hotkeys",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.4",
|
|
4
4
|
"description": "Vue adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"skills"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@tanstack/hotkeys": "0.
|
|
41
|
+
"@tanstack/hotkeys": "0.26.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@vitejs/plugin-vue": "^6.0.10",
|
|
@@ -79,6 +79,7 @@ No provider is required. Call the composables synchronously in setup.
|
|
|
79
79
|
## Pitfalls
|
|
80
80
|
|
|
81
81
|
- **Pass the ref, not `.value`.** `{ enabled: isDirty.value }` is read once, so the hotkey never turns on, and `{ target: panel.value }` is `null` in setup, so the hotkey never registers. Pass `isDirty` and `panel`. `enabled` and `target` accept refs and getters; for other options that depend on state, pass a getter for the whole options object.
|
|
82
|
+
- **A component ref listens on the component's root element.** `useTemplateRef<InstanceType<typeof Panel>>('panel')` works as `target`. The root element is read when the ref is set: a component with more than one root node or a text root registers nothing, and a root the component adds or swaps later (`v-if` on the root) isn't followed. Put the ref on an element instead.
|
|
82
83
|
- **Put the provider around the dialog component.** A `HotkeysProvider` in a component's own template, or `provideHotkeysContext` in its own setup, applies only to its children. Register the dialog's hotkeys in a child component, and give each open dialog its own scope name, such as `` `dialog-${useId()}` ``.
|
|
83
84
|
- **Destructure the recorder.** Templates unwrap only top-level refs, so `v-if="recorder.isRecording"` is always true. Use `const { isRecording, startRecording } = useHotkeyRecorder(...)`.
|
|
84
85
|
- **The callback isn't tracked.** Read refs and props inside it.
|