@tanstack/octane-hotkeys 0.8.0 → 0.9.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.
@@ -29,8 +29,10 @@ export interface HotkeysProviderProps extends HotkeysProviderScopeProps {
29
29
  */
30
30
  appHotkeys?: AppHotkeys;
31
31
  /**
32
- * Starting custom hotkeys, such as saved data. Read once; the provider owns
33
- * the state afterwards. Invalid entries are ignored with a warning.
32
+ * The user's saved custom hotkeys. When the value changes, such as after
33
+ * saved data loads or the user signs in, it replaces the current custom
34
+ * hotkeys. `undefined` leaves them unchanged; `null` clears them. Invalid
35
+ * entries are ignored with a warning.
34
36
  */
35
37
  customHotkeys?: CustomHotkeys | null;
36
38
  /** Called with the custom hotkeys after every change, ready to save. */
@@ -33,6 +33,9 @@ function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys,
33
33
  useLayoutEffect(() => {
34
34
  if (appHotkeys) store?.setAppHotkeys(appHotkeys);
35
35
  }, [store, appHotkeys], subSlot(void 0, "provider-declarations"));
36
+ useLayoutEffect(() => {
37
+ store?.setOptions({ customHotkeys });
38
+ }, [store, customHotkeys], subSlot(void 0, "provider-custom-hotkeys"));
36
39
  useLayoutEffect(() => store ? publishAppHotkeysStore(store) : void 0, [store], subSlot(void 0, "provider-publish"));
37
40
  const active = (parent?.enabled ?? true) && enabled;
38
41
  const scopeKey = getHotkeysProviderScopeKey({
@@ -18,8 +18,9 @@ export type UseAppHotkeyOptions<T extends AppHotkey = AppHotkey> = AdapterAppHot
18
18
  /**
19
19
  * Registers one hotkey: a chord such as `'Mod+S'`, a sequence such as
20
20
  * `['G', 'G']`, or an app hotkey from `defineAppHotkeys`. The callback and
21
- * options are refreshed after every commit.
21
+ * options are refreshed after every commit. `undefined`, `null`, or `''`
22
+ * registers nothing, for an optional shortcut.
22
23
  */
23
- export declare function useHotkey<T extends AppHotkey>(hotkey: T, callback: HotkeyCallback, options?: UseAppHotkeyOptions<T>): void;
24
- export declare function useHotkey<const T extends RegisterableHotkey>(hotkey: T, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: UseHotkeyOptionsFor<T>): void;
24
+ export declare function useHotkey<T extends AppHotkey>(hotkey: T | null | undefined, callback: HotkeyCallback, options?: UseAppHotkeyOptions<T>): void;
25
+ export declare function useHotkey<const T extends RegisterableHotkey>(hotkey: T | null | undefined, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: UseHotkeyOptionsFor<T>): void;
25
26
  //#endregion
@@ -5,7 +5,8 @@ import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/ho
5
5
  * while the hotkey can fire: some registration of it is enabled and in an
6
6
  * active scope. A sequence reveals its hint from its first step, and an app
7
7
  * hotkey matches its registrations by id and uses its effective hotkey (false
8
- * while unbound). A hotkey on an element counts only while focus is inside it.
8
+ * while unbound). No hotkey (`undefined`, `null`, or `''`) returns false. A
9
+ * hotkey on an element counts only while focus is inside it.
9
10
  */
10
- export declare function useHotkeyHint(hotkey: RegisterableHotkey | AppHotkey, options?: HeldModifierOptions): boolean;
11
+ export declare function useHotkeyHint(hotkey: RegisterableHotkey | AppHotkey | null | undefined, options?: HeldModifierOptions): boolean;
11
12
  //#endregion
@@ -2,13 +2,12 @@ import { select, subSlot } from "./internal.js";
2
2
  import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
3
3
  import { HotkeyRecorder } from "@tanstack/hotkeys";
4
4
  import { useLayoutEffect, useRef } from "octane";
5
+ import { withDefaults } from "@tanstack/hotkeys/adapter";
5
6
 
6
7
  //#region src/useHotkeyRecorder.ts
7
8
  function useHotkeyRecorder(options, slot) {
8
- const merged = {
9
- ...useDefaultHotkeysOptions().hotkeyRecorder,
10
- ...options
11
- };
9
+ const defaults = useDefaultHotkeysOptions();
10
+ const merged = withDefaults(defaults.hotkeyRecorder, options);
12
11
  const ref = useRef(null, subSlot(slot, "recorder"));
13
12
  ref.current ??= new HotkeyRecorder(merged);
14
13
  const recorder = ref.current;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/octane-hotkeys",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Octane adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "skills"
36
36
  ],
37
37
  "dependencies": {
38
- "@tanstack/hotkeys": "0.20.0"
38
+ "@tanstack/hotkeys": "0.21.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@tsrx/oxc": "0.20.0",