@tanstack/vue-hotkeys 0.12.0 → 0.13.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/README.md CHANGED
@@ -67,6 +67,9 @@ Type-safe keyboard shortcuts for the web. Template-string bindings, parsed objec
67
67
  > [!NOTE]
68
68
  > You may know **TanStack Hotkeys** by our adapter names, too!
69
69
  >
70
+ > - [**Alpine Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/alpine/quick-start)
71
+ > - [**Ember Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/ember/quick-start)
72
+ > - [**Octane Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/octane/quick-start)
70
73
  > - [**React Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/react/react-hotkeys)
71
74
  > - [**Preact Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/preact/preact-hotkeys)
72
75
  > - [**Solid Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/solid/reference)
@@ -21,7 +21,7 @@ const HotkeysProvider = defineComponent({
21
21
  default: void 0
22
22
  } },
23
23
  setup(props, { slots }) {
24
- provideHotkeysContext(props.defaultOptions);
24
+ provideHotkeysContext(() => props.defaultOptions ?? {});
25
25
  return () => slots.default?.();
26
26
  }
27
27
  });
@@ -1,6 +1,7 @@
1
1
  import { UseHotkeyOptions } from "./useHotkey.js";
2
2
  import { UseHotkeySequenceOptions } from "./useHotkeySequence.js";
3
3
  import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
4
+ import { MaybeRefOrGetter } from "vue";
4
5
  //#region src/HotkeysProviderContext.d.ts
5
6
  export interface HotkeysProviderOptions {
6
7
  hotkey?: Partial<UseHotkeyOptions>;
@@ -11,7 +12,7 @@ export interface HotkeysProviderOptions {
11
12
  interface HotkeysContextValue {
12
13
  defaultOptions: HotkeysProviderOptions;
13
14
  }
14
- export declare function provideHotkeysContext(defaultOptions?: HotkeysProviderOptions): void;
15
+ export declare function provideHotkeysContext(defaultOptions?: MaybeRefOrGetter<HotkeysProviderOptions>): void;
15
16
  export declare function useHotkeysContext(): HotkeysContextValue | null;
16
17
  export declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
17
18
  //#endregion
@@ -1,10 +1,12 @@
1
- import { inject, provide } from "vue";
1
+ import { inject, provide, toValue } from "vue";
2
2
 
3
3
  //#region src/HotkeysProviderContext.ts
4
4
  const HotkeysContext = Symbol("HotkeysContext");
5
5
  const DEFAULT_OPTIONS = {};
6
6
  function provideHotkeysContext(defaultOptions) {
7
- provide(HotkeysContext, { defaultOptions: defaultOptions ?? DEFAULT_OPTIONS });
7
+ provide(HotkeysContext, { get defaultOptions() {
8
+ return toValue(defaultOptions) ?? DEFAULT_OPTIONS;
9
+ } });
8
10
  }
9
11
  function useHotkeysContext() {
10
12
  return inject(HotkeysContext, null);
@@ -0,0 +1,11 @@
1
+ import { useHotkeysContext } from "./HotkeysProviderContext.js";
2
+
3
+ //#region src/defaultOptions.ts
4
+ /** Captures the context once and reads current defaults inside reactive computations. */
5
+ function useDefaultHotkeysOptionsSource() {
6
+ const context = useHotkeysContext();
7
+ return () => context?.defaultOptions ?? {};
8
+ }
9
+
10
+ //#endregion
11
+ export { useDefaultHotkeysOptionsSource };
package/dist/useHotkey.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
1
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
2
  import { detectPlatform, getHotkeyManager, normalizeRegisterableHotkey } from "@tanstack/hotkeys";
3
3
  import { onUnmounted, unref, watch } from "vue";
4
4
 
@@ -68,7 +68,7 @@ import { onUnmounted, unref, watch } from "vue";
68
68
  * ```
69
69
  */
70
70
  function useHotkey(hotkey, callback, options = {}) {
71
- const defaultOptions = useDefaultHotkeysOptions();
71
+ const defaultOptions = useDefaultHotkeysOptionsSource();
72
72
  const manager = getHotkeyManager();
73
73
  let registration = null;
74
74
  let lastHotkeyString = null;
@@ -77,7 +77,7 @@ function useHotkey(hotkey, callback, options = {}) {
77
77
  const resolvedHotkey = resolveMaybeRefOrGetter(hotkey);
78
78
  const resolvedOptions = resolveMaybeRefOrGetter(options);
79
79
  const mergedOptions = {
80
- ...defaultOptions.hotkey,
80
+ ...defaultOptions().hotkey,
81
81
  ...resolvedOptions
82
82
  };
83
83
  return {
@@ -1,4 +1,4 @@
1
- import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
1
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
2
  import { HotkeyRecorder } from "@tanstack/hotkeys";
3
3
  import { onUnmounted, unref, watch } from "vue";
4
4
  import { useSelector } from "@tanstack/vue-store";
@@ -46,7 +46,7 @@ import { useSelector } from "@tanstack/vue-store";
46
46
  * ```
47
47
  */
48
48
  function useHotkeyRecorder(options) {
49
- const defaultOptions = useDefaultHotkeysOptions();
49
+ const defaultOptions = useDefaultHotkeysOptionsSource();
50
50
  const recorder = new HotkeyRecorder(resolveRecorderOptions(options, defaultOptions));
51
51
  const isRecording = useSelector(recorder.store, (state) => state.isRecording);
52
52
  const recordedHotkey = useSelector(recorder.store, (state) => state.recordedHotkey);
@@ -67,7 +67,7 @@ function useHotkeyRecorder(options) {
67
67
  }
68
68
  function resolveRecorderOptions(options, defaultOptions) {
69
69
  return {
70
- ...defaultOptions.hotkeyRecorder,
70
+ ...defaultOptions().hotkeyRecorder,
71
71
  ...resolveMaybeRefOrGetter(options)
72
72
  };
73
73
  }
@@ -1,4 +1,4 @@
1
- import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
1
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
2
  import { formatHotkeySequence, getSequenceManager } from "@tanstack/hotkeys";
3
3
  import { onUnmounted, unref, watch } from "vue";
4
4
 
@@ -50,7 +50,7 @@ import { onUnmounted, unref, watch } from "vue";
50
50
  * ```
51
51
  */
52
52
  function useHotkeySequence(sequence, callback, options = {}) {
53
- const defaultOptions = useDefaultHotkeysOptions();
53
+ const defaultOptions = useDefaultHotkeysOptionsSource();
54
54
  const manager = getSequenceManager();
55
55
  let registration = null;
56
56
  let lastSequenceKey = null;
@@ -59,7 +59,7 @@ function useHotkeySequence(sequence, callback, options = {}) {
59
59
  const resolvedSequence = resolveMaybeRefOrGetter(sequence);
60
60
  const resolvedOptions = resolveMaybeRefOrGetter(options);
61
61
  const mergedOptions = {
62
- ...defaultOptions.hotkeySequence,
62
+ ...defaultOptions().hotkeySequence,
63
63
  ...resolvedOptions
64
64
  };
65
65
  return {
@@ -1,4 +1,4 @@
1
- import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
1
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
2
  import { HotkeySequenceRecorder } from "@tanstack/hotkeys";
3
3
  import { onUnmounted, unref, watch } from "vue";
4
4
  import { useSelector } from "@tanstack/vue-store";
@@ -8,7 +8,7 @@ import { useSelector } from "@tanstack/vue-store";
8
8
  * Vue composable for recording multi-chord sequences (Vim-style shortcuts).
9
9
  */
10
10
  function useHotkeySequenceRecorder(options) {
11
- const defaultOptions = useDefaultHotkeysOptions();
11
+ const defaultOptions = useDefaultHotkeysOptionsSource();
12
12
  const recorder = new HotkeySequenceRecorder(resolveHotkeySequenceRecorderOptions(options, defaultOptions));
13
13
  const isRecording = useSelector(recorder.store, (state) => state.isRecording);
14
14
  const steps = useSelector(recorder.store, (state) => state.steps);
@@ -32,7 +32,7 @@ function useHotkeySequenceRecorder(options) {
32
32
  }
33
33
  function resolveHotkeySequenceRecorderOptions(options, defaultOptions) {
34
34
  return {
35
- ...defaultOptions.hotkeySequenceRecorder,
35
+ ...defaultOptions().hotkeySequenceRecorder,
36
36
  ...resolveMaybeRefOrGetter(options)
37
37
  };
38
38
  }
@@ -1,4 +1,4 @@
1
- import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
1
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
2
  import { formatHotkeySequence, getSequenceManager } from "@tanstack/hotkeys";
3
3
  import { onUnmounted, unref, watch } from "vue";
4
4
 
@@ -48,7 +48,7 @@ import { onUnmounted, unref, watch } from "vue";
48
48
  * ```
49
49
  */
50
50
  function useHotkeySequences(definitions, commonOptions = {}) {
51
- const defaultOptions = useDefaultHotkeysOptions();
51
+ const defaultOptions = useDefaultHotkeysOptionsSource();
52
52
  const manager = getSequenceManager();
53
53
  const registrations = /* @__PURE__ */ new Map();
54
54
  const stopWatcher = watch(() => {
@@ -58,7 +58,7 @@ function useHotkeySequences(definitions, commonOptions = {}) {
58
58
  const resolvedSequence = resolveMaybeRefOrGetter(def.sequence);
59
59
  const resolvedDefOptions = def.options ? resolveMaybeRefOrGetter(def.options) : {};
60
60
  const mergedOptions = {
61
- ...defaultOptions.hotkeySequence,
61
+ ...defaultOptions().hotkeySequence,
62
62
  ...resolvedCommonOptions,
63
63
  ...resolvedDefOptions
64
64
  };
@@ -1,4 +1,4 @@
1
- import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
1
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
2
  import { detectPlatform, getHotkeyManager, normalizeRegisterableHotkey } from "@tanstack/hotkeys";
3
3
  import { onUnmounted, unref, watch } from "vue";
4
4
 
@@ -49,7 +49,7 @@ import { onUnmounted, unref, watch } from "vue";
49
49
  * ```
50
50
  */
51
51
  function useHotkeys(hotkeys, commonOptions = {}) {
52
- const defaultOptions = useDefaultHotkeysOptions();
52
+ const defaultOptions = useDefaultHotkeysOptionsSource();
53
53
  const manager = getHotkeyManager();
54
54
  const registrations = /* @__PURE__ */ new Map();
55
55
  const stopWatcher = watch(() => {
@@ -59,7 +59,7 @@ function useHotkeys(hotkeys, commonOptions = {}) {
59
59
  const resolvedHotkey = resolveMaybeRefOrGetter(def.hotkey);
60
60
  const resolvedDefOptions = def.options ? resolveMaybeRefOrGetter(def.options) : {};
61
61
  const mergedOptions = {
62
- ...defaultOptions.hotkey,
62
+ ...defaultOptions().hotkey,
63
63
  ...resolvedCommonOptions,
64
64
  ...resolvedDefOptions
65
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-hotkeys",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Vue adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -36,8 +36,8 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@tanstack/hotkeys": "0.10.0",
40
- "@tanstack/vue-store": "^0.11.1"
39
+ "@tanstack/hotkeys": "0.11.0",
40
+ "@tanstack/vue-store": "^0.11.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@vitejs/plugin-vue": "^6.0.9",