@tanstack/vue-hotkeys 0.22.1 → 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.
@@ -1,7 +1,39 @@
1
1
  import { HotkeysProviderOptions } from "./HotkeysProviderContext.js";
2
2
  import { AppHotkeys, CustomHotkeys } from "@tanstack/hotkeys";
3
- import { PropType } from "vue";
3
+ import { ComponentOptionsMixin, DefineComponent, PropType, VNode } from "vue";
4
4
  import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
5
+ declare const providerProps: {
6
+ defaultOptions: {
7
+ type: PropType<HotkeysProviderOptions>;
8
+ default: undefined;
9
+ };
10
+ appHotkeys: {
11
+ type: PropType<AppHotkeys>;
12
+ default: undefined;
13
+ };
14
+ customHotkeys: {
15
+ type: PropType<CustomHotkeys | null>;
16
+ default: undefined;
17
+ };
18
+ /** See `HotkeysProviderScopeProps['scope']`. */
19
+ scope: {
20
+ type: StringConstructor;
21
+ default: undefined;
22
+ };
23
+ /** See `HotkeysProviderScopeProps['exclusive']`. */
24
+ exclusive: {
25
+ type: PropType<HotkeysProviderScopeProps["exclusive"]>;
26
+ default: boolean;
27
+ };
28
+ /** See `HotkeysProviderScopeProps['enabled']`. */
29
+ enabled: {
30
+ type: BooleanConstructor;
31
+ default: boolean;
32
+ };
33
+ };
34
+ declare const providerEmits: {
35
+ customHotkeysChange: (_customHotkeys: CustomHotkeys) => true;
36
+ };
5
37
  /**
6
38
  * Vue component that provides default options, app hotkeys, and the user's
7
39
  * custom hotkeys. A new `customHotkeys` value replaces the current custom
@@ -13,6 +45,10 @@ import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
13
45
  * while it is mounted, enabled, and not hidden by `<KeepAlive>`; with
14
46
  * `exclusive`, only its hotkeys fire.
15
47
  *
48
+ * Props: `defaultOptions` (a `HotkeysProviderOptions`), `appHotkeys`,
49
+ * `customHotkeys`, and the `scope`, `exclusive`, and `enabled` props of
50
+ * `HotkeysProviderScopeProps`. Event: `custom-hotkeys-change`.
51
+ *
16
52
  * @example
17
53
  * ```vue
18
54
  * <template>
@@ -33,75 +69,5 @@ import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
33
69
  * </HotkeysProvider>
34
70
  * ```
35
71
  */
36
- export declare const HotkeysProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
37
- defaultOptions: {
38
- type: PropType<HotkeysProviderOptions>;
39
- default: undefined;
40
- };
41
- appHotkeys: {
42
- type: PropType<AppHotkeys>;
43
- default: undefined;
44
- };
45
- customHotkeys: {
46
- type: PropType<CustomHotkeys | null>;
47
- default: undefined;
48
- };
49
- /** See `HotkeysProviderScopeProps['scope']`. */
50
- scope: {
51
- type: StringConstructor;
52
- default: undefined;
53
- };
54
- /** See `HotkeysProviderScopeProps['exclusive']`. */
55
- exclusive: {
56
- type: PropType<HotkeysProviderScopeProps["exclusive"]>;
57
- default: boolean;
58
- };
59
- /** See `HotkeysProviderScopeProps['enabled']`. */
60
- enabled: {
61
- type: BooleanConstructor;
62
- default: boolean;
63
- };
64
- }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
65
- [key: string]: any;
66
- }>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
67
- customHotkeysChange: (_customHotkeys: CustomHotkeys) => true;
68
- }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
69
- defaultOptions: {
70
- type: PropType<HotkeysProviderOptions>;
71
- default: undefined;
72
- };
73
- appHotkeys: {
74
- type: PropType<AppHotkeys>;
75
- default: undefined;
76
- };
77
- customHotkeys: {
78
- type: PropType<CustomHotkeys | null>;
79
- default: undefined;
80
- };
81
- /** See `HotkeysProviderScopeProps['scope']`. */
82
- scope: {
83
- type: StringConstructor;
84
- default: undefined;
85
- };
86
- /** See `HotkeysProviderScopeProps['exclusive']`. */
87
- exclusive: {
88
- type: PropType<HotkeysProviderScopeProps["exclusive"]>;
89
- default: boolean;
90
- };
91
- /** See `HotkeysProviderScopeProps['enabled']`. */
92
- enabled: {
93
- type: BooleanConstructor;
94
- default: boolean;
95
- };
96
- }>> & Readonly<{
97
- onCustomHotkeysChange?: ((_customHotkeys: CustomHotkeys<Readonly<Record<string, import("@tanstack/hotkeys").AppHotkey<string, import("@tanstack/hotkeys").HotkeyChord | import("@tanstack/hotkeys").HotkeySequence | null>>>>) => any) | undefined;
98
- }>, {
99
- exclusive: boolean | {
100
- allow: ReadonlyArray<string>;
101
- } | undefined;
102
- defaultOptions: HotkeysProviderOptions;
103
- appHotkeys: Readonly<Record<string, import("@tanstack/hotkeys").AppHotkey<string, import("@tanstack/hotkeys").HotkeyChord | import("@tanstack/hotkeys").HotkeySequence | null>>>;
104
- customHotkeys: CustomHotkeys<Readonly<Record<string, import("@tanstack/hotkeys").AppHotkey<string, import("@tanstack/hotkeys").HotkeyChord | import("@tanstack/hotkeys").HotkeySequence | null>>>> | null;
105
- scope: string;
106
- enabled: boolean;
107
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
72
+ export declare const HotkeysProvider: DefineComponent<typeof providerProps, () => Array<VNode> | undefined, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, typeof providerEmits>;
73
+ export {};
@@ -2,38 +2,7 @@ import { provideHotkeysContext } from "./HotkeysProviderContext.js";
2
2
  import { defineComponent } from "vue";
3
3
 
4
4
  // src/HotkeysProvider.tsx
5
- /**
6
- * Vue component that provides default options, app hotkeys, and the user's
7
- * custom hotkeys. A new `customHotkeys` value replaces the current custom
8
- * hotkeys, `undefined` leaves them unchanged, and `null` clears them. Listen
9
- * to `custom-hotkeys-change` to save changes.
10
- *
11
- * Nest providers to create hotkey scopes. A nested provider inherits app
12
- * hotkeys and merges default options. With `scope`, its hotkeys fire only
13
- * while it is mounted, enabled, and not hidden by `<KeepAlive>`; with
14
- * `exclusive`, only its hotkeys fire.
15
- *
16
- * @example
17
- * ```vue
18
- * <template>
19
- * <HotkeysProvider
20
- * :app-hotkeys="appHotkeys"
21
- * :custom-hotkeys="saved"
22
- * @custom-hotkeys-change="save"
23
- * >
24
- * <App />
25
- * </HotkeysProvider>
26
- * </template>
27
- * ```
28
- *
29
- * @example
30
- * ```vue
31
- * <HotkeysProvider scope="edit-dialog" :exclusive="{ allow: ['global'] }">
32
- * <DialogBody />
33
- * </HotkeysProvider>
34
- * ```
35
- */
36
- const HotkeysProvider = defineComponent({
5
+ const component = defineComponent({
37
6
  name: "HotkeysProvider",
38
7
  props: {
39
8
  defaultOptions: {
@@ -78,5 +47,41 @@ const HotkeysProvider = defineComponent({
78
47
  return () => slots.default?.();
79
48
  }
80
49
  });
50
+ /**
51
+ * Vue component that provides default options, app hotkeys, and the user's
52
+ * custom hotkeys. A new `customHotkeys` value replaces the current custom
53
+ * hotkeys, `undefined` leaves them unchanged, and `null` clears them. Listen
54
+ * to `custom-hotkeys-change` to save changes.
55
+ *
56
+ * Nest providers to create hotkey scopes. A nested provider inherits app
57
+ * hotkeys and merges default options. With `scope`, its hotkeys fire only
58
+ * while it is mounted, enabled, and not hidden by `<KeepAlive>`; with
59
+ * `exclusive`, only its hotkeys fire.
60
+ *
61
+ * Props: `defaultOptions` (a `HotkeysProviderOptions`), `appHotkeys`,
62
+ * `customHotkeys`, and the `scope`, `exclusive`, and `enabled` props of
63
+ * `HotkeysProviderScopeProps`. Event: `custom-hotkeys-change`.
64
+ *
65
+ * @example
66
+ * ```vue
67
+ * <template>
68
+ * <HotkeysProvider
69
+ * :app-hotkeys="appHotkeys"
70
+ * :custom-hotkeys="saved"
71
+ * @custom-hotkeys-change="save"
72
+ * >
73
+ * <App />
74
+ * </HotkeysProvider>
75
+ * </template>
76
+ * ```
77
+ *
78
+ * @example
79
+ * ```vue
80
+ * <HotkeysProvider scope="edit-dialog" :exclusive="{ allow: ['global'] }">
81
+ * <DialogBody />
82
+ * </HotkeysProvider>
83
+ * ```
84
+ */
85
+ const HotkeysProvider = component;
81
86
 
82
87
  export { HotkeysProvider };
@@ -1,7 +1,7 @@
1
1
  import { UseHotkeyCommonOptions } from "./useHotkey.js";
2
- import { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
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,
@@ -9,21 +9,23 @@ export interface HotkeysProviderOptions {
9
9
  * from the request with `detectPlatform(userAgent)`.
10
10
  */
11
11
  platform?: HotkeyPlatform;
12
+ /**
13
+ * Whether labels from `useFormatForDisplay` follow the user's keyboard
14
+ * layout, so `[KeyQ]` reads `A` on a French AZERTY keyboard. The layout
15
+ * loads from the browser when the first label mounts. Only Chromium
16
+ * browsers report one. Set `false` to never ask the browser for it.
17
+ * Default: `true`.
18
+ */
19
+ keyboardLayout?: boolean;
12
20
  /**
13
21
  * Defaults for every hotkey registered by `useHotkey` and `useHotkeys`.
14
22
  * `requireReset` applies to chords and `timeout` applies to sequences.
15
23
  */
16
24
  hotkey?: UseHotkeyCommonOptions;
17
25
  /** Defaults for every `useHotkeyRecorder`. */
18
- hotkeyRecorder?: Partial<Omit<HotkeyChordRecorderOptions & HotkeySequenceRecorderOptions, 'maxSteps' | 'onRecord' | 'validate'>>;
19
- }
20
- interface HotkeysContextValue {
21
- readonly appHotkeysStore: AppHotkeysStore | null;
22
- /** Merged with every ancestor's defaults, including `hotkey.scope`. */
23
- readonly defaultOptions: HotkeysProviderOptions;
24
- /** Whether this context and every ancestor are enabled. */
25
- readonly enabled: boolean;
26
+ hotkeyRecorder?: HotkeyRecorderDefaults;
26
27
  }
28
+ type VueHotkeysContextValue = HotkeysContextValue<HotkeysProviderOptions>;
27
29
  /** Options for `provideHotkeysContext`. */
28
30
  export interface ProvideHotkeysContextOptions {
29
31
  /** Merged with the parent context's defaults. */
@@ -76,6 +78,6 @@ export declare function provideHotkeysContext(options?: ProvideHotkeysContextOpt
76
78
  * `effectScope`, there is no context to read, so this skips `inject` and its
77
79
  * warning.
78
80
  */
79
- export declare function useHotkeysContext(): HotkeysContextValue | null;
81
+ export declare function useHotkeysContext(): VueHotkeysContextValue | null;
80
82
  export declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
81
83
  export {};
@@ -0,0 +1,12 @@
1
+ import { formatForDisplay } from "@tanstack/hotkeys";
2
+ /**
3
+ * Formats a hotkey as a label, without the provider's platform or the user's
4
+ * keyboard layout.
5
+ *
6
+ * @deprecated Use `useFormatForDisplay()` in components. It returns this
7
+ * function with the provider's platform and the user's keyboard layout filled
8
+ * in. Outside a component, keep calling this function and pass `platform`
9
+ * yourself.
10
+ */
11
+ declare const formatForDisplay$1: typeof formatForDisplay;
12
+ export { formatForDisplay$1 as formatForDisplay };
@@ -0,0 +1,15 @@
1
+ import { formatForDisplay } from "@tanstack/hotkeys";
2
+
3
+ // src/formatForDisplay.ts
4
+ /**
5
+ * Formats a hotkey as a label, without the provider's platform or the user's
6
+ * keyboard layout.
7
+ *
8
+ * @deprecated Use `useFormatForDisplay()` in components. It returns this
9
+ * function with the provider's platform and the user's keyboard layout filled
10
+ * in. Outside a component, keep calling this function and pass `platform`
11
+ * yourself.
12
+ */
13
+ const formatForDisplay$1 = formatForDisplay;
14
+
15
+ export { formatForDisplay$1 as formatForDisplay };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
10
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
11
11
  import { useHotkeyHint } from "./useHotkeyHint.js";
12
12
  import { useFormatForDisplay } from "./useFormatForDisplay.js";
13
+ import { formatForDisplay } from "./formatForDisplay.js";
14
+ import { useKeyboardLayout } from "./useKeyboardLayout.js";
13
15
  import { UseCustomHotkeysResult, useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
14
16
  export * from "@tanstack/hotkeys";
15
- export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold };
17
+ export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
package/dist/index.js CHANGED
@@ -10,8 +10,10 @@ import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
10
10
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
11
11
  import { useHotkeyHint } from "./useHotkeyHint.js";
12
12
  import { useFormatForDisplay } from "./useFormatForDisplay.js";
13
+ import { formatForDisplay } from "./formatForDisplay.js";
14
+ import { useKeyboardLayout } from "./useKeyboardLayout.js";
13
15
  import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
14
16
 
15
17
  export * from "@tanstack/hotkeys"
16
18
 
17
- export { HotkeysProvider, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold };
19
+ export { HotkeysProvider, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
@@ -1,4 +1,4 @@
1
- import { AppHotkey, AppHotkeyListItem, CustomHotkeys, Hotkey, RegisteredAppHotkeys } from "@tanstack/hotkeys";
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,22 +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<AppHotkeyListItem<RegisteredAppHotkeys[keyof RegisteredAppHotkeys]>>>;
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.
27
- */
28
- setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null) => Array<AppHotkey>;
29
- /** Restores the default hotkey for an app hotkey. */
30
- resetCustomHotkey: (id: keyof RegisteredAppHotkeys & string) => void;
31
- /** Restores every default hotkey. */
32
- resetCustomHotkeys: () => void;
33
- /** Other app hotkeys that would collide if `id` used `hotkey`. */
34
- findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey) => Array<AppHotkey>;
35
24
  }
36
25
  /**
37
26
  * Reads and changes the user's custom hotkeys. Changes apply to every
@@ -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 initial = source.store;
9
- if (!initial) throw new Error(`[hotkeys] ${name} requires a HotkeysProvider with app hotkeys`);
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
- setCustomHotkey: (id, hotkey) => store().setCustomHotkey(id, hotkey),
58
- resetCustomHotkey: (id) => store().resetCustomHotkey(id),
59
- resetCustomHotkeys: () => store().resetCustomHotkeys(),
60
- findConflicts: (id, hotkey) => store().findConflicts(id, hotkey)
58
+ ...bindCustomHotkeyActions(store)
61
59
  };
62
60
  }
63
61
 
@@ -5,17 +5,23 @@ import { formatForDisplay } from "@tanstack/hotkeys";
5
5
  * works anywhere, and templates update when the provider's platform changes.
6
6
  * An explicit `platform` option wins.
7
7
  *
8
+ * Physical bindings such as `[KeyQ]` are labeled with the character the key
9
+ * types for this user in Chromium browsers, once the keyboard layout has
10
+ * loaded, and templates update when it arrives. See `useKeyboardLayout`. A
11
+ * `layoutMap` passed to the returned function wins. Firefox and Safari report
12
+ * no layout, so labels there keep the key's US character.
13
+ *
8
14
  * Server-rendered apps should set the provider's `defaultOptions.platform`
9
15
  * from the request user agent with `detectPlatform(userAgent)`.
10
16
  *
11
17
  * @example
12
18
  * ```vue
13
19
  * <script setup lang="ts">
14
- * const format = useFormatForDisplay()
20
+ * const formatForDisplay = useFormatForDisplay()
15
21
  * </script>
16
22
  *
17
23
  * <template>
18
- * <kbd>{{ format('Mod+S') }}</kbd>
24
+ * <kbd>{{ formatForDisplay('Mod+S') }}</kbd>
19
25
  * </template>
20
26
  * ```
21
27
  */
@@ -1,5 +1,6 @@
1
1
  import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
- import { formatForDisplay } from "@tanstack/hotkeys";
2
+ import { useKeyboardLayout } from "./useKeyboardLayout.js";
3
+ import { createFormatForDisplay } from "@tanstack/hotkeys/adapter";
3
4
 
4
5
  // src/useFormatForDisplay.ts
5
6
  /**
@@ -8,26 +9,30 @@ import { formatForDisplay } from "@tanstack/hotkeys";
8
9
  * works anywhere, and templates update when the provider's platform changes.
9
10
  * An explicit `platform` option wins.
10
11
  *
12
+ * Physical bindings such as `[KeyQ]` are labeled with the character the key
13
+ * types for this user in Chromium browsers, once the keyboard layout has
14
+ * loaded, and templates update when it arrives. See `useKeyboardLayout`. A
15
+ * `layoutMap` passed to the returned function wins. Firefox and Safari report
16
+ * no layout, so labels there keep the key's US character.
17
+ *
11
18
  * Server-rendered apps should set the provider's `defaultOptions.platform`
12
19
  * from the request user agent with `detectPlatform(userAgent)`.
13
20
  *
14
21
  * @example
15
22
  * ```vue
16
23
  * <script setup lang="ts">
17
- * const format = useFormatForDisplay()
24
+ * const formatForDisplay = useFormatForDisplay()
18
25
  * <\/script>
19
26
  *
20
27
  * <template>
21
- * <kbd>{{ format('Mod+S') }}</kbd>
28
+ * <kbd>{{ formatForDisplay('Mod+S') }}</kbd>
22
29
  * </template>
23
30
  * ```
24
31
  */
25
32
  function useFormatForDisplay() {
26
33
  const defaultOptions = useDefaultHotkeysOptionsSource();
27
- return ((hotkey, options) => formatForDisplay(hotkey, {
28
- ...options,
29
- platform: options?.platform ?? defaultOptions().platform
30
- }));
34
+ const layoutMap = useKeyboardLayout();
35
+ return createFormatForDisplay(() => defaultOptions().platform, () => layoutMap.value);
31
36
  }
32
37
 
33
38
  export { useFormatForDisplay };
@@ -25,4 +25,4 @@ import { Ref } from "vue";
25
25
  * </template>
26
26
  * ```
27
27
  */
28
- export declare function useHeldKeyCodes(): Ref<Record<string, string>>;
28
+ export declare function useHeldKeyCodes(): Readonly<Ref<Record<string, string>>>;
@@ -5,7 +5,7 @@ import { Ref } from "vue";
5
5
  * This composable subscribes to the global KeyStateTracker and updates whenever keys are pressed
6
6
  * or released.
7
7
  *
8
- * @returns Reactive ref containing array of currently held key names
8
+ * @returns Read-only reactive ref containing array of currently held key names
9
9
  *
10
10
  * @example
11
11
  * ```vue
@@ -22,4 +22,4 @@ import { Ref } from "vue";
22
22
  * </template>
23
23
  * ```
24
24
  */
25
- export declare function useHeldKeys(): Ref<Array<string>>;
25
+ export declare function useHeldKeys(): Readonly<Ref<Array<string>>>;
@@ -8,7 +8,7 @@ import { getKeyStateTracker } from "@tanstack/hotkeys";
8
8
  * This composable subscribes to the global KeyStateTracker and updates whenever keys are pressed
9
9
  * or released.
10
10
  *
11
- * @returns Reactive ref containing array of currently held key names
11
+ * @returns Read-only reactive ref containing array of currently held key names
12
12
  *
13
13
  * @example
14
14
  * ```vue
@@ -44,6 +44,6 @@ export type UseAppHotkeyOptions<T extends AppHotkey = AppHotkey> = WithReactiveE
44
44
  * useHotkey('Escape', () => close(), { enabled: isOpen })
45
45
  * ```
46
46
  */
47
- export declare function useHotkey<T extends AppHotkey>(hotkey: MaybeRefOrGetter<T | null | undefined>, callback: HotkeyCallback, options?: MaybeRefOrGetter<UseAppHotkeyOptions<T>>): void;
48
47
  export declare function useHotkey<const T extends RegisterableHotkey>(hotkey: MaybeRefOrGetter<T | null | undefined>, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: MaybeRefOrGetter<UseHotkeyOptionsFor<T>>): void;
48
+ export declare function useHotkey<T extends AppHotkey>(hotkey: MaybeRefOrGetter<T | null | undefined>, callback: HotkeyCallback, options?: MaybeRefOrGetter<UseAppHotkeyOptions<T>>): void;
49
49
  export {};
@@ -1,7 +1,8 @@
1
1
  import { useAppHotkeysStoreSource } from "./defaultOptions.js";
2
2
  import { useStoreSelector } from "./useStoreSelector.js";
3
- import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
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 manager = getHotkeyManager();
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
- const value = toValue(hotkey);
24
- const resolved = isAppHotkey(value) ? resolveAppHotkey(value, appHotkeys.store).hotkey : value;
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, HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
1
+ import { Hotkey, HotkeyChord, HotkeyChordRecorderOptions, HotkeyRecorderActions, HotkeyRecorderOptions, HotkeyRecorderState, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
2
2
  import { Ref } from "vue";
3
- export interface VueHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
4
- /** Whether recording is currently active */
5
- isRecording: Readonly<Ref<boolean>>;
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 {};
@@ -12,6 +12,7 @@ import { Ref } from "vue";
12
12
  * ```vue
13
13
  * <script setup>
14
14
  * const registrations = useHotkeyRegistrations()
15
+ * const formatForDisplay = useFormatForDisplay()
15
16
  * </script>
16
17
  * <template>
17
18
  * <li v-for="reg in registrations" :key="reg.id">
@@ -1,5 +1,6 @@
1
1
  import { useStoreSelector } from "./useStoreSelector.js";
2
- import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
2
+ import { getHotkeyManager } from "@tanstack/hotkeys";
3
+ import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
3
4
 
4
5
  // src/useHotkeyRegistrations.ts
5
6
  /**
@@ -14,6 +15,7 @@ import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
14
15
  * ```vue
15
16
  * <script setup>
16
17
  * const registrations = useHotkeyRegistrations()
18
+ * const formatForDisplay = useFormatForDisplay()
17
19
  * <\/script>
18
20
  * <template>
19
21
  * <li v-for="reg in registrations" :key="reg.id">
@@ -23,7 +25,7 @@ import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
23
25
  * ```
24
26
  */
25
27
  function useHotkeyRegistrations() {
26
- return useStoreSelector(getHotkeyManager().registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView));
28
+ return useStoreSelector(getHotkeyManager().registrations, getHotkeyRegistrationViews);
27
29
  }
28
30
 
29
31
  export { useHotkeyRegistrations };
@@ -20,4 +20,4 @@ import { Ref } from "vue";
20
20
  * </template>
21
21
  * ```
22
22
  */
23
- export declare function useHotkeyScopesState(): Ref<HotkeyScopesState>;
23
+ export declare function useHotkeyScopesState(): Readonly<Ref<HotkeyScopesState>>;
@@ -1,13 +1,14 @@
1
1
  import { IndividualKey } from "@tanstack/hotkeys";
2
- import { MaybeRefOrGetter, Ref } from "vue";
2
+ import { ComputedRef, MaybeRefOrGetter } from "vue";
3
3
  /**
4
4
  * Vue composable that returns a reactive ref indicating whether a specific key is currently being held.
5
5
  *
6
6
  * Reads the held keys from the global KeyStateTracker. The key may be a ref
7
- * or getter; the result follows it without waiting for a key event.
7
+ * or getter; the result follows it without waiting for a key event. Pressing
8
+ * or releasing another key doesn't notify anything that reads the ref.
8
9
  *
9
10
  * @param key - The key to check (e.g., 'Shift', 'Control', 'A')
10
- * @returns Reactive ref that is true if the key is currently held down
11
+ * @returns Read-only reactive ref that is true if the key is currently held down
11
12
  *
12
13
  * @example
13
14
  * ```vue
@@ -43,4 +44,4 @@ import { MaybeRefOrGetter, Ref } from "vue";
43
44
  * </template>
44
45
  * ```
45
46
  */
46
- export declare function useKeyHold(key: MaybeRefOrGetter<IndividualKey>): Ref<boolean>;
47
+ export declare function useKeyHold(key: MaybeRefOrGetter<IndividualKey>): ComputedRef<boolean>;
@@ -1,16 +1,16 @@
1
- import { useHeldKeys } from "./useHeldKeys.js";
2
1
  import { getKeyStateTracker } from "@tanstack/hotkeys";
3
- import { computed, toValue } from "vue";
2
+ import { computed, onScopeDispose, shallowRef, toValue } from "vue";
4
3
 
5
4
  // src/useKeyHold.ts
6
5
  /**
7
6
  * Vue composable that returns a reactive ref indicating whether a specific key is currently being held.
8
7
  *
9
8
  * Reads the held keys from the global KeyStateTracker. The key may be a ref
10
- * or getter; the result follows it without waiting for a key event.
9
+ * or getter; the result follows it without waiting for a key event. Pressing
10
+ * or releasing another key doesn't notify anything that reads the ref.
11
11
  *
12
12
  * @param key - The key to check (e.g., 'Shift', 'Control', 'A')
13
- * @returns Reactive ref that is true if the key is currently held down
13
+ * @returns Read-only reactive ref that is true if the key is currently held down
14
14
  *
15
15
  * @example
16
16
  * ```vue
@@ -47,10 +47,19 @@ import { computed, toValue } from "vue";
47
47
  * ```
48
48
  */
49
49
  function useKeyHold(key) {
50
- const heldKeys = useHeldKeys();
50
+ const tracker = getKeyStateTracker();
51
+ const isHeld = () => tracker.isKeyHeld(toValue(key));
52
+ const changes = shallowRef(0);
53
+ let last = isHeld();
54
+ if (typeof document !== "undefined") {
55
+ const { unsubscribe } = tracker.store.subscribe(() => {
56
+ if (isHeld() !== last) changes.value++;
57
+ });
58
+ onScopeDispose(unsubscribe);
59
+ }
51
60
  return computed(() => {
52
- heldKeys.value;
53
- return getKeyStateTracker().isKeyHeld(toValue(key));
61
+ changes.value;
62
+ return last = isHeld();
54
63
  });
55
64
  }
56
65
 
@@ -0,0 +1,33 @@
1
+ import { KeyboardLayoutMap } from "@tanstack/hotkeys";
2
+ import { Ref } from "vue";
3
+ /**
4
+ * Vue composable that returns a ref of the browser's keyboard layout, or
5
+ * `null` until it loads and in browsers that don't report one. The layout maps
6
+ * each physical code to the character it types, such as `KeyQ` to `a` on a
7
+ * French AZERTY keyboard. Only Chromium browsers report one.
8
+ *
9
+ * The layout loads after the first component that uses this composable
10
+ * mounts, so server-rendered output hydrates unchanged. `useFormatForDisplay`
11
+ * uses this composable, so you only need it for labels you draw yourself.
12
+ *
13
+ * To never ask the browser for the layout, set `keyboardLayout: false` in
14
+ * `HotkeysProvider`'s `defaultOptions`. The ref then holds `null`.
15
+ *
16
+ * @returns Read-only reactive ref of the keyboard layout, or `null`
17
+ *
18
+ * @example
19
+ * ```vue
20
+ * <script setup lang="ts">
21
+ * import { useKeyboardLayout } from '@tanstack/vue-hotkeys'
22
+ *
23
+ * const layoutMap = useKeyboardLayout()
24
+ * const label = (code: string) =>
25
+ * (layoutMap.value?.get(code) ?? code).toUpperCase()
26
+ * </script>
27
+ *
28
+ * <template>
29
+ * <kbd>{{ label('KeyW') }}</kbd>
30
+ * </template>
31
+ * ```
32
+ */
33
+ export declare function useKeyboardLayout(): Readonly<Ref<KeyboardLayoutMap | null>>;
@@ -0,0 +1,61 @@
1
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
+ import { getKeyboardLayoutStore } from "@tanstack/hotkeys";
3
+ import { getCurrentInstance, onMounted, shallowReadonly, shallowRef, watch } from "vue";
4
+ import { followKeyboardLayout } from "@tanstack/hotkeys/adapter";
5
+
6
+ // src/useKeyboardLayout.ts
7
+ /**
8
+ * Vue composable that returns a ref of the browser's keyboard layout, or
9
+ * `null` until it loads and in browsers that don't report one. The layout maps
10
+ * each physical code to the character it types, such as `KeyQ` to `a` on a
11
+ * French AZERTY keyboard. Only Chromium browsers report one.
12
+ *
13
+ * The layout loads after the first component that uses this composable
14
+ * mounts, so server-rendered output hydrates unchanged. `useFormatForDisplay`
15
+ * uses this composable, so you only need it for labels you draw yourself.
16
+ *
17
+ * To never ask the browser for the layout, set `keyboardLayout: false` in
18
+ * `HotkeysProvider`'s `defaultOptions`. The ref then holds `null`.
19
+ *
20
+ * @returns Read-only reactive ref of the keyboard layout, or `null`
21
+ *
22
+ * @example
23
+ * ```vue
24
+ * <script setup lang="ts">
25
+ * import { useKeyboardLayout } from '@tanstack/vue-hotkeys'
26
+ *
27
+ * const layoutMap = useKeyboardLayout()
28
+ * const label = (code: string) =>
29
+ * (layoutMap.value?.get(code) ?? code).toUpperCase()
30
+ * <\/script>
31
+ *
32
+ * <template>
33
+ * <kbd>{{ label('KeyW') }}</kbd>
34
+ * </template>
35
+ * ```
36
+ */
37
+ function useKeyboardLayout() {
38
+ const layout = shallowRef(null);
39
+ if (typeof document === "undefined") return shallowReadonly(layout);
40
+ const defaultOptions = useDefaultHotkeysOptionsSource();
41
+ const enabled = () => defaultOptions().keyboardLayout !== false;
42
+ const store = getKeyboardLayoutStore();
43
+ const follow = () => {
44
+ watch(enabled, (on, _, onCleanup) => {
45
+ layout.value = on ? store.get() : null;
46
+ if (!on) return;
47
+ onCleanup(followKeyboardLayout((next) => {
48
+ layout.value = next;
49
+ }));
50
+ }, { immediate: true });
51
+ };
52
+ const instance = getCurrentInstance();
53
+ if (!instance || instance.isMounted) {
54
+ follow();
55
+ return shallowReadonly(layout);
56
+ }
57
+ onMounted(follow);
58
+ return shallowReadonly(layout);
59
+ }
60
+
61
+ export { useKeyboardLayout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-hotkeys",
3
- "version": "0.22.1",
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.27.1"
41
+ "@tanstack/hotkeys": "0.30.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@tanstack/hotkeys-test-utils": "0.0.0",
@@ -33,7 +33,7 @@ Before starting, load the `@tanstack/hotkeys#hotkeys-core` skill (`npx @tanstack
33
33
 
34
34
  ```vue
35
35
  <script setup lang="ts">
36
- import { formatForDisplay, useHotkey } from '@tanstack/vue-hotkeys'
36
+ import { useFormatForDisplay, useHotkey } from '@tanstack/vue-hotkeys'
37
37
  import { ref } from 'vue'
38
38
 
39
39
  const isDirty = ref(false)
@@ -41,6 +41,7 @@ const panel = ref<HTMLDivElement | null>(null)
41
41
 
42
42
  useHotkey('Mod+S', () => save(), { enabled: isDirty })
43
43
  useHotkey('Escape', () => closePanel(), { target: panel })
44
+ const formatForDisplay = useFormatForDisplay()
44
45
  </script>
45
46
 
46
47
  <template>
@@ -52,27 +53,27 @@ useHotkey('Escape', () => closePanel(), { target: panel })
52
53
 
53
54
  ## API
54
55
 
55
- | API | What it's for |
56
- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
57
- | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted; the hotkey and options can be refs or getters. |
58
- | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a ref or getter of a list built from data, in one call. |
59
- | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for its children, and emit `custom-hotkeys-change`. |
60
- | `provideHotkeysContext(options)` | Provide the same options from a component's setup instead of rendering `HotkeysProvider`; they apply to its children. |
61
- | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
62
- | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
63
- | `useFormatForDisplay()` | Get `formatForDisplay` with the provider's `platform` filled in, for labels in server-rendered apps. Call it in `setup`. |
64
- | `useAppHotkeys()` | Get a computed ref of the declared app hotkeys with the user's custom hotkeys applied. |
65
- | `useAppHotkeyList()` | Get a computed ref listing every app hotkey with its status, for a cheat sheet or settings screen. |
66
- | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
67
- | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses; destructure the refs it returns. |
68
- | `useHotkeyRegistrations()` | Get a ref listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
69
- | `useHotkeyScopesState()` | Get a ref of the active scopes and the exclusive scope that owns the keyboard. |
70
- | `useHotkeyHint(hotkey, options?)` | Get a computed ref of 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. |
71
- | `useKeyHold(key)` | Get a ref of whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
72
- | `useHeldKeys()` | Get a ref of every key that's held right now. |
73
- | `useHeldKeyCodes()` | Get a ref mapping each held key to its physical `event.code`. |
56
+ | API | What it's for |
57
+ | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
58
+ | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted; the hotkey and options can be refs or getters. |
59
+ | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a ref or getter of a list built from data, in one call. |
60
+ | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for its children, and emit `custom-hotkeys-change`. |
61
+ | `provideHotkeysContext(options)` | Provide the same options from a component's setup instead of rendering `HotkeysProvider`; they apply to its children. |
62
+ | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
63
+ | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
64
+ | `useFormatForDisplay()` | Get the function that formats a hotkey as a label, with the provider's `platform` and the user's keyboard layout filled in. Only Chromium browsers report a layout, so physical keys keep their US labels in Firefox and Safari. Use it for every label in a component: `const formatForDisplay = useFormatForDisplay()` in `setup`, then `formatForDisplay(hotkey)`. |
65
+ | `useAppHotkeys()` | Get a computed ref of the declared app hotkeys with the user's custom hotkeys applied. |
66
+ | `useAppHotkeyList()` | Get a computed ref listing every app hotkey with its status, for a cheat sheet or settings screen. |
67
+ | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
68
+ | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses; destructure the refs it returns. |
69
+ | `useHotkeyRegistrations()` | Get a ref listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
70
+ | `useHotkeyScopesState()` | Get a ref of the active scopes and the exclusive scope that owns the keyboard. |
71
+ | `useHotkeyHint(hotkey, options?)` | Get a computed ref of 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. |
72
+ | `useKeyHold(key)` | Get a ref of whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
73
+ | `useHeldKeys()` | Get a ref of every key that's held right now. |
74
+ | `useHeldKeyCodes()` | Get a ref mapping each held key to its physical `event.code`. |
74
75
 
75
- The package also re-exports `@tanstack/hotkeys`, such as `formatForDisplay`, `matchesKeyboardEvent`, and `defineAppHotkeys`.
76
+ The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`.
76
77
 
77
78
  No provider is required. Call the composables synchronously in setup.
78
79
 
@@ -84,7 +85,7 @@ No provider is required. Call the composables synchronously in setup.
84
85
  - **Destructure the recorder.** Templates unwrap only top-level refs, so `v-if="recorder.isRecording"` is always true. Use `const { isRecording, startRecording } = useHotkeyRecorder(...)`.
85
86
  - **The callback isn't tracked.** Read refs and props inside it.
86
87
  - **Call the composables directly.** A `useShortcut(keys: string)` wrapper has to cast strings to hotkeys, which turns off type checking and drops sequences, reactive options, and app hotkeys.
87
- - **Server-rendered labels need the user's platform.** On the server, `formatForDisplay` can't see the user's OS, so it renders Linux labels that differ after hydration for Mac and Windows users. Set the provider's `defaultOptions.platform` to `detectPlatform(userAgent)` from the request's `User-Agent` header, and format labels with `const format = useFormatForDisplay()` in `setup`, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser, when no provider sets `platform`.
88
+ - **Server-rendered labels need the user's platform.** The server can't see the user's OS, so without a platform it renders Linux labels that differ after hydration for Mac and Windows users. Set the provider's `defaultOptions.platform` to `detectPlatform(userAgent)` from the request's `User-Agent` header. `useFormatForDisplay()` reads it.
88
89
 
89
90
  When declaring app hotkeys, building a cheat sheet, or letting users rebind shortcuts, load `@tanstack/hotkeys#app-hotkeys` and read [app hotkeys in Vue](references/app-hotkeys.md).
90
91
 
@@ -49,26 +49,27 @@ A settings row records with `useHotkeyRecorder` and saves through `useCustomHotk
49
49
  ```vue
50
50
  <script setup lang="ts">
51
51
  import {
52
- formatForDisplay,
53
52
  useAppHotkeys,
54
53
  useCustomHotkeys,
54
+ useFormatForDisplay,
55
55
  useHotkeyRecorder,
56
56
  } from '@tanstack/vue-hotkeys'
57
57
  import { computed } from 'vue'
58
58
  import type { AppHotkeyId } from '@tanstack/vue-hotkeys'
59
59
 
60
60
  const props = defineProps<{ id: AppHotkeyId }>()
61
+ const formatForDisplay = useFormatForDisplay()
61
62
  const appHotkeys = useAppHotkeys()
62
63
  const appHotkey = computed(() => appHotkeys.value[props.id])
63
64
  const { findConflicts, setCustomHotkey, resetCustomHotkey } = useCustomHotkeys()
64
65
 
65
66
  const { startRecording } = useHotkeyRecorder({
66
67
  maxSteps: Infinity,
67
- validate: (hotkey) => {
68
- const [conflict] = findConflicts(props.id, hotkey)
68
+ validate: (hotkey, context) => {
69
+ const [conflict] = findConflicts(props.id, hotkey, context)
69
70
  return conflict ? `Used by ${conflict.meta?.name ?? conflict.id}` : true
70
71
  },
71
- onRecord: (hotkey) => setCustomHotkey(props.id, hotkey),
72
+ onRecord: (hotkey, context) => setCustomHotkey(props.id, hotkey, context),
72
73
  onClear: () => setCustomHotkey(props.id, null),
73
74
  })
74
75
  </script>