@tanstack/vue-hotkeys 0.24.0 → 0.24.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.
- package/dist/HotkeysProviderContext.d.ts +5 -11
- package/dist/useAppHotkeys.d.ts +3 -19
- package/dist/useAppHotkeys.js +5 -7
- package/dist/useFormatForDisplay.js +2 -7
- package/dist/useHotkeyHint.js +5 -6
- package/dist/useHotkeyRecorder.d.ts +6 -18
- package/dist/useHotkeyRegistrations.js +3 -2
- package/dist/useKeyboardLayout.js +4 -8
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UseHotkeyCommonOptions } from "./useHotkey.js";
|
|
2
|
-
import { AppHotkeys,
|
|
2
|
+
import { AppHotkeys, CustomHotkeys, HotkeyPlatform } from "@tanstack/hotkeys";
|
|
3
3
|
import { MaybeRefOrGetter } from "vue";
|
|
4
|
-
import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
4
|
+
import { HotkeyRecorderDefaults, HotkeysContextValue, HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
5
5
|
export interface HotkeysProviderOptions {
|
|
6
6
|
/**
|
|
7
7
|
* The user's platform, for labels from `useFormatForDisplay`, hotkeys,
|
|
@@ -23,15 +23,9 @@ export interface HotkeysProviderOptions {
|
|
|
23
23
|
*/
|
|
24
24
|
hotkey?: UseHotkeyCommonOptions;
|
|
25
25
|
/** Defaults for every `useHotkeyRecorder`. */
|
|
26
|
-
hotkeyRecorder?:
|
|
27
|
-
}
|
|
28
|
-
interface HotkeysContextValue {
|
|
29
|
-
readonly appHotkeysStore: AppHotkeysStore | null;
|
|
30
|
-
/** Merged with every ancestor's defaults, including `hotkey.scope`. */
|
|
31
|
-
readonly defaultOptions: HotkeysProviderOptions;
|
|
32
|
-
/** Whether this context and every ancestor are enabled. */
|
|
33
|
-
readonly enabled: boolean;
|
|
26
|
+
hotkeyRecorder?: HotkeyRecorderDefaults;
|
|
34
27
|
}
|
|
28
|
+
type VueHotkeysContextValue = HotkeysContextValue<HotkeysProviderOptions>;
|
|
35
29
|
/** Options for `provideHotkeysContext`. */
|
|
36
30
|
export interface ProvideHotkeysContextOptions {
|
|
37
31
|
/** Merged with the parent context's defaults. */
|
|
@@ -84,6 +78,6 @@ export declare function provideHotkeysContext(options?: ProvideHotkeysContextOpt
|
|
|
84
78
|
* `effectScope`, there is no context to read, so this skips `inject` and its
|
|
85
79
|
* warning.
|
|
86
80
|
*/
|
|
87
|
-
export declare function useHotkeysContext():
|
|
81
|
+
export declare function useHotkeysContext(): VueHotkeysContextValue | null;
|
|
88
82
|
export declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
89
83
|
export {};
|
package/dist/useAppHotkeys.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CustomHotkeyActions, CustomHotkeys, RegisteredAppHotkeyListItem, RegisteredAppHotkeys } from "@tanstack/hotkeys";
|
|
2
2
|
import { ComputedRef } from "vue";
|
|
3
3
|
/**
|
|
4
4
|
* Returns a computed ref of the effective app hotkeys from `HotkeysProvider`,
|
|
@@ -16,27 +16,11 @@ export declare function useAppHotkeys(): ComputedRef<RegisteredAppHotkeys>;
|
|
|
16
16
|
* cheat sheets and settings screens. App hotkeys whose components have not
|
|
17
17
|
* mounted are `'inactive'`; those without a hotkey are `'unbound'`.
|
|
18
18
|
*/
|
|
19
|
-
export declare function useAppHotkeyList(): ComputedRef<Array<
|
|
19
|
+
export declare function useAppHotkeyList(): ComputedRef<Array<RegisteredAppHotkeyListItem>>;
|
|
20
20
|
/** Custom hotkey state and actions returned by `useCustomHotkeys`. */
|
|
21
|
-
export interface UseCustomHotkeysResult {
|
|
21
|
+
export interface UseCustomHotkeysResult extends CustomHotkeyActions {
|
|
22
22
|
/** The user's hotkeys that differ from the defaults. */
|
|
23
23
|
customHotkeys: ComputedRef<CustomHotkeys>;
|
|
24
|
-
/**
|
|
25
|
-
* Sets the user's hotkey for an app hotkey. `null` unbinds it.
|
|
26
|
-
* Returns conflicting app hotkeys; when any exist, nothing changes. Pass
|
|
27
|
-
* the recorder's `context` for a recorded hotkey, as for `findConflicts`.
|
|
28
|
-
*/
|
|
29
|
-
setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
|
|
30
|
-
/** Restores the default hotkey for an app hotkey. */
|
|
31
|
-
resetCustomHotkey: (id: keyof RegisteredAppHotkeys & string) => void;
|
|
32
|
-
/** Restores every default hotkey. */
|
|
33
|
-
resetCustomHotkeys: () => void;
|
|
34
|
-
/**
|
|
35
|
-
* Other app hotkeys that would collide if `id` used `hotkey`. Pass the
|
|
36
|
-
* recorder's `context` for a recorded hotkey: it has the key press, which
|
|
37
|
-
* also finds a hotkey written differently that the same press fires.
|
|
38
|
-
*/
|
|
39
|
-
findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
|
|
40
24
|
}
|
|
41
25
|
/**
|
|
42
26
|
* Reads and changes the user's custom hotkeys. Changes apply to every
|
package/dist/useAppHotkeys.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { useAppHotkeysStoreSource } from "./defaultOptions.js";
|
|
2
2
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
3
3
|
import { computed } from "vue";
|
|
4
|
+
import { bindCustomHotkeyActions, requireAppHotkeysStore } from "@tanstack/hotkeys/adapter";
|
|
4
5
|
|
|
5
6
|
// src/useAppHotkeys.ts
|
|
6
7
|
function useRequiredStore(name) {
|
|
7
8
|
const source = useAppHotkeysStoreSource();
|
|
8
|
-
const
|
|
9
|
-
|
|
9
|
+
const message = `${name} requires a HotkeysProvider with app hotkeys`;
|
|
10
|
+
const initial = requireAppHotkeysStore(source.store, message);
|
|
10
11
|
return {
|
|
11
|
-
store: () => source.store ?? initial,
|
|
12
|
+
store: () => requireAppHotkeysStore(source.store ?? initial, message),
|
|
12
13
|
state: source.state
|
|
13
14
|
};
|
|
14
15
|
}
|
|
@@ -54,10 +55,7 @@ function useCustomHotkeys() {
|
|
|
54
55
|
state.value;
|
|
55
56
|
return store().customHotkeys;
|
|
56
57
|
}),
|
|
57
|
-
|
|
58
|
-
resetCustomHotkey: (id) => store().resetCustomHotkey(id),
|
|
59
|
-
resetCustomHotkeys: () => store().resetCustomHotkeys(),
|
|
60
|
-
findConflicts: (id, hotkey, recordedWith) => store().findConflicts(id, hotkey, recordedWith)
|
|
58
|
+
...bindCustomHotkeyActions(store)
|
|
61
59
|
};
|
|
62
60
|
}
|
|
63
61
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
|
|
2
2
|
import { useKeyboardLayout } from "./useKeyboardLayout.js";
|
|
3
|
-
import {
|
|
4
|
-
import { namesPhysicalKey } from "@tanstack/hotkeys/adapter";
|
|
3
|
+
import { createFormatForDisplay } from "@tanstack/hotkeys/adapter";
|
|
5
4
|
|
|
6
5
|
// src/useFormatForDisplay.ts
|
|
7
6
|
/**
|
|
@@ -33,11 +32,7 @@ import { namesPhysicalKey } from "@tanstack/hotkeys/adapter";
|
|
|
33
32
|
function useFormatForDisplay() {
|
|
34
33
|
const defaultOptions = useDefaultHotkeysOptionsSource();
|
|
35
34
|
const layoutMap = useKeyboardLayout();
|
|
36
|
-
return ((
|
|
37
|
-
...options,
|
|
38
|
-
platform: options?.platform ?? defaultOptions().platform,
|
|
39
|
-
layoutMap: options?.layoutMap ?? (namesPhysicalKey(hotkey) ? layoutMap.value ?? void 0 : void 0)
|
|
40
|
-
}));
|
|
35
|
+
return createFormatForDisplay(() => defaultOptions().platform, () => layoutMap.value);
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
export { useFormatForDisplay };
|
package/dist/useHotkeyHint.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useAppHotkeysStoreSource } from "./defaultOptions.js";
|
|
2
2
|
import { useStoreSelector } from "./useStoreSelector.js";
|
|
3
|
-
import { getHotkeyManager, getKeyStateTracker
|
|
3
|
+
import { getHotkeyManager, getKeyStateTracker } from "@tanstack/hotkeys";
|
|
4
4
|
import { computed, toValue } from "vue";
|
|
5
|
+
import { isHotkeyHintVisible } from "@tanstack/hotkeys/adapter";
|
|
5
6
|
|
|
6
7
|
// src/useHotkeyHint.ts
|
|
7
8
|
/**
|
|
@@ -15,14 +16,12 @@ import { computed, toValue } from "vue";
|
|
|
15
16
|
*/
|
|
16
17
|
function useHotkeyHint(hotkey, options = {}) {
|
|
17
18
|
const appHotkeys = useAppHotkeysStoreSource();
|
|
18
|
-
const
|
|
19
|
-
const registrations = useStoreSelector(manager.registrations, (state) => state);
|
|
19
|
+
const registrations = useStoreSelector(getHotkeyManager().registrations, (state) => state);
|
|
20
20
|
const held = useStoreSelector(getKeyStateTracker().store, (state) => state.heldKeys);
|
|
21
21
|
return computed(() => {
|
|
22
22
|
appHotkeys.state.value;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return resolved !== null && matchesHeldModifiers(resolved, held.value, toValue(options)) && registrations.value.size > 0 && manager.hasActiveRegistration(value);
|
|
23
|
+
registrations.value;
|
|
24
|
+
return isHotkeyHintVisible(toValue(hotkey), held.value, toValue(options), appHotkeys.store);
|
|
26
25
|
});
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
import { Hotkey, HotkeyChord, HotkeyChordRecorderOptions, HotkeyRecorderOptions,
|
|
1
|
+
import { Hotkey, HotkeyChord, HotkeyChordRecorderOptions, HotkeyRecorderActions, HotkeyRecorderOptions, HotkeyRecorderState, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
2
|
import { Ref } from "vue";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** Chords recorded so far in a multi-step recording (for live preview) */
|
|
7
|
-
steps: Readonly<Ref<HotkeySequence>>;
|
|
8
|
-
/** The last committed hotkey */
|
|
9
|
-
recordedHotkey: Readonly<Ref<THotkey | null>>;
|
|
10
|
-
/** Start recording a new hotkey */
|
|
11
|
-
startRecording: () => void;
|
|
12
|
-
/** Stop recording without calling onCancel */
|
|
13
|
-
stopRecording: () => void;
|
|
14
|
-
/** Cancel recording and call onCancel */
|
|
15
|
-
cancelRecording: () => void;
|
|
16
|
-
/** Commit the recorded steps now (multi-step recordings) */
|
|
17
|
-
commitRecording: () => void;
|
|
18
|
-
}
|
|
3
|
+
/** The recorder state, each field as a read-only ref. */
|
|
4
|
+
type VueHotkeyRecorderState<THotkey extends Hotkey> = { [K in keyof HotkeyRecorderState<THotkey>]: Readonly<Ref<HotkeyRecorderState<THotkey>[K]>>; };
|
|
5
|
+
export interface VueHotkeyRecorder<THotkey extends Hotkey = Hotkey> extends VueHotkeyRecorderState<THotkey>, HotkeyRecorderActions {}
|
|
19
6
|
/**
|
|
20
7
|
* Vue composable for recording keyboard shortcuts. Options may be a ref or getter.
|
|
21
8
|
*
|
|
@@ -34,4 +21,5 @@ export declare function useHotkeyRecorder(options: HotkeyChordRecorderOptions):
|
|
|
34
21
|
export declare function useHotkeyRecorder(options: HotkeySequenceRecorderOptions): VueHotkeyRecorder;
|
|
35
22
|
export declare function useHotkeyRecorder(options: () => HotkeySequenceRecorderOptions): VueHotkeyRecorder;
|
|
36
23
|
export declare function useHotkeyRecorder(options: () => HotkeyChordRecorderOptions): VueHotkeyRecorder<HotkeyChord>;
|
|
37
|
-
export declare function useHotkeyRecorder(options: Ref<HotkeyRecorderOptions>): VueHotkeyRecorder;
|
|
24
|
+
export declare function useHotkeyRecorder(options: Ref<HotkeyRecorderOptions>): VueHotkeyRecorder;
|
|
25
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useStoreSelector } from "./useStoreSelector.js";
|
|
2
|
-
import { getHotkeyManager
|
|
2
|
+
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
3
|
+
import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
|
|
3
4
|
|
|
4
5
|
// src/useHotkeyRegistrations.ts
|
|
5
6
|
/**
|
|
@@ -24,7 +25,7 @@ import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
function useHotkeyRegistrations() {
|
|
27
|
-
return useStoreSelector(getHotkeyManager().registrations,
|
|
28
|
+
return useStoreSelector(getHotkeyManager().registrations, getHotkeyRegistrationViews);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export { useHotkeyRegistrations };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
|
|
2
|
-
import { getKeyboardLayoutStore
|
|
2
|
+
import { getKeyboardLayoutStore } from "@tanstack/hotkeys";
|
|
3
3
|
import { getCurrentInstance, onMounted, shallowReadonly, shallowRef, watch } from "vue";
|
|
4
|
+
import { followKeyboardLayout } from "@tanstack/hotkeys/adapter";
|
|
4
5
|
|
|
5
6
|
// src/useKeyboardLayout.ts
|
|
6
7
|
/**
|
|
@@ -43,14 +44,9 @@ function useKeyboardLayout() {
|
|
|
43
44
|
watch(enabled, (on, _, onCleanup) => {
|
|
44
45
|
layout.value = on ? store.get() : null;
|
|
45
46
|
if (!on) return;
|
|
46
|
-
|
|
47
|
-
const { unsubscribe } = store.subscribe((next) => {
|
|
47
|
+
onCleanup(followKeyboardLayout((next) => {
|
|
48
48
|
layout.value = next;
|
|
49
|
-
});
|
|
50
|
-
onCleanup(() => {
|
|
51
|
-
unsubscribe();
|
|
52
|
-
stop();
|
|
53
|
-
});
|
|
49
|
+
}));
|
|
54
50
|
}, { immediate: true });
|
|
55
51
|
};
|
|
56
52
|
const instance = getCurrentInstance();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-hotkeys",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.1",
|
|
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.30.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@tanstack/hotkeys-test-utils": "0.0.0",
|