@tanstack/vue-hotkeys 0.21.2 → 0.21.3

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.
@@ -4,9 +4,9 @@ import { MaybeRefOrGetter } from "vue";
4
4
  import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
5
5
  export interface HotkeysProviderOptions {
6
6
  /**
7
- * The user's platform, for labels from `useFormatForDisplay`, hotkeys, and
8
- * recorders. On a server, set it from the request with
9
- * `detectPlatform(userAgent)`.
7
+ * The user's platform, for labels from `useFormatForDisplay`, hotkeys,
8
+ * recorders, and app hotkey checks such as conflicts. On a server, set it
9
+ * from the request with `detectPlatform(userAgent)`.
10
10
  */
11
11
  platform?: HotkeyPlatform;
12
12
  /**
@@ -31,18 +31,22 @@ function provideHotkeysContext(options = {}) {
31
31
  const appHotkeys = toValue(options.appHotkeys);
32
32
  const store = appHotkeys ? createAppHotkeysStore(appHotkeys, {
33
33
  customHotkeys: toValue(options.customHotkeys),
34
- onCustomHotkeysChange: (custom) => options.onCustomHotkeysChange?.(custom)
34
+ onCustomHotkeysChange: (custom) => options.onCustomHotkeysChange?.(custom),
35
+ platform: toValue(options.defaultOptions)?.platform ?? parent?.defaultOptions.platform
35
36
  }) : null;
36
37
  if (store) {
37
38
  watch(() => toValue(options.appHotkeys), (next) => {
38
39
  if (next) store.setAppHotkeys(next);
39
40
  });
40
- watch(() => toValue(options.customHotkeys), (customHotkeys) => store.setOptions({ customHotkeys }), { deep: true });
41
41
  if (typeof document !== "undefined") onScopeDispose(publishAppHotkeysStore(store));
42
42
  }
43
43
  const live = useLive();
44
44
  const active = computed(() => live.value && (parent?.enabled ?? true) && toValue(options.enabled) !== false);
45
45
  const defaultOptions = computed(() => mergeHotkeysProviderDefaults(parent?.defaultOptions, toValue(options.defaultOptions), toValue(options.scope)));
46
+ if (store) watch([() => toValue(options.customHotkeys), () => defaultOptions.value.platform], ([customHotkeys, platform]) => store.setOptions({
47
+ customHotkeys,
48
+ platform
49
+ }), { deep: true });
46
50
  const scopeKey = computed(() => getHotkeysProviderScopeKey({
47
51
  scope: toValue(options.scope),
48
52
  exclusive: toValue(options.exclusive),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-hotkeys",
3
- "version": "0.21.2",
3
+ "version": "0.21.3",
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.25.0"
41
+ "@tanstack/hotkeys": "0.25.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@vitejs/plugin-vue": "^6.0.10",
@@ -83,7 +83,7 @@ No provider is required. Call the composables synchronously in setup.
83
83
  - **Destructure the recorder.** Templates unwrap only top-level refs, so `v-if="recorder.isRecording"` is always true. Use `const { isRecording, startRecording } = useHotkeyRecorder(...)`.
84
84
  - **The callback isn't tracked.** Read refs and props inside it.
85
85
  - **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.
86
- - **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.
86
+ - **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`.
87
87
 
88
88
  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).
89
89