@tanstack/solid-hotkeys 0.18.0 → 0.19.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.
@@ -27,8 +27,10 @@ export interface HotkeysProviderProps extends HotkeysProviderScopeProps {
27
27
  */
28
28
  appHotkeys?: AppHotkeys;
29
29
  /**
30
- * Starting custom hotkeys, such as saved data. Read once; the provider owns
31
- * the state afterwards. Invalid entries are ignored with a warning.
30
+ * The user's saved custom hotkeys. When the value changes, such as after
31
+ * saved data loads or the user signs in, it replaces the current custom
32
+ * hotkeys. `undefined` leaves them unchanged; `null` clears them. Invalid
33
+ * entries are ignored with a warning.
32
34
  */
33
35
  customHotkeys?: CustomHotkeys | null;
34
36
  /** Called with the custom hotkeys after every change, ready to save. */
@@ -42,6 +42,10 @@ const HotkeysProvider = (props) => {
42
42
  createEffect(() => {
43
43
  if (props.appHotkeys) store?.setAppHotkeys(props.appHotkeys);
44
44
  });
45
+ createEffect(() => {
46
+ const customHotkeys = props.customHotkeys;
47
+ store?.setOptions({ customHotkeys });
48
+ });
45
49
  onMount(() => {
46
50
  if (store) onCleanup(publishAppHotkeysStore(store));
47
51
  });
@@ -29,6 +29,7 @@ type MaybeAccessor<T> = T | (() => T);
29
29
  * sequence registers as its chord. An app hotkey uses its effective hotkey
30
30
  * from `HotkeysProvider` (including the user's custom hotkey) and its
31
31
  * declared meta and options, and registers nothing while unbound.
32
+ * `undefined`, `null`, or `''` registers nothing, for an optional shortcut.
32
33
  *
33
34
  * @example
34
35
  * ```tsx
@@ -37,6 +38,6 @@ type MaybeAccessor<T> = T | (() => T);
37
38
  * createHotkey('Escape', () => close(), () => ({ enabled: isOpen() }))
38
39
  * ```
39
40
  */
40
- export declare function createHotkey<T extends AppHotkey>(hotkey: MaybeAccessor<T>, callback: HotkeyCallback, options?: MaybeAccessor<CreateAppHotkeyOptions<T>>): void;
41
- export declare function createHotkey<const T extends RegisterableHotkey>(hotkey: MaybeAccessor<T>, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: MaybeAccessor<CreateHotkeyOptionsFor<T>>): void;
41
+ export declare function createHotkey<T extends AppHotkey>(hotkey: MaybeAccessor<T | null | undefined>, callback: HotkeyCallback, options?: MaybeAccessor<CreateAppHotkeyOptions<T>>): void;
42
+ export declare function createHotkey<const T extends RegisterableHotkey>(hotkey: MaybeAccessor<T | null | undefined>, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: MaybeAccessor<CreateHotkeyOptionsFor<T>>): void;
42
43
  //#endregion
@@ -5,7 +5,8 @@ import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/ho
5
5
  * The hint shows only while the hotkey can fire: some registration of it is
6
6
  * enabled and in an active scope. A sequence reveals its hint from its first
7
7
  * step, and an app hotkey matches its registrations by id and uses its
8
- * effective hotkey (false while unbound). This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
8
+ * effective hotkey (false while unbound). No hotkey (`undefined`, `null`, or
9
+ * `''`) returns false. This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
9
10
  */
10
- export declare function createHotkeyHint(hotkey: RegisterableHotkey | AppHotkey | (() => RegisterableHotkey | AppHotkey), options?: HeldModifierOptions | (() => HeldModifierOptions)): () => boolean;
11
+ export declare function createHotkeyHint(hotkey: RegisterableHotkey | AppHotkey | null | undefined | (() => RegisterableHotkey | AppHotkey | null | undefined), options?: HeldModifierOptions | (() => HeldModifierOptions)): () => boolean;
11
12
  //#endregion
@@ -9,7 +9,8 @@ import { createMemo } from "solid-js";
9
9
  * The hint shows only while the hotkey can fire: some registration of it is
10
10
  * enabled and in an active scope. A sequence reveals its hint from its first
11
11
  * step, and an app hotkey matches its registrations by id and uses its
12
- * effective hotkey (false while unbound). This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
12
+ * effective hotkey (false while unbound). No hotkey (`undefined`, `null`, or
13
+ * `''`) returns false. This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
13
14
  */
14
15
  function createHotkeyHint(hotkey, options = {}) {
15
16
  const appHotkeys = useAppHotkeysStoreSource();
@@ -2,14 +2,12 @@ import { useSelector } from "./_useSelector.js";
2
2
  import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
3
3
  import { HotkeyRecorder } from "@tanstack/hotkeys";
4
4
  import { createEffect, onCleanup } from "solid-js";
5
+ import { withDefaults } from "@tanstack/hotkeys/adapter";
5
6
 
6
7
  //#region src/createHotkeyRecorder.ts
7
8
  function createHotkeyRecorder(options) {
8
9
  const defaultOptions = useDefaultHotkeysOptionsSource();
9
- const resolve = () => ({
10
- ...defaultOptions().hotkeyRecorder,
11
- ...typeof options === "function" ? options() : options
12
- });
10
+ const resolve = () => withDefaults(defaultOptions().hotkeyRecorder, typeof options === "function" ? options() : options);
13
11
  const recorder = new HotkeyRecorder(resolve());
14
12
  const isRecording = useSelector(recorder.store, (state) => state.isRecording);
15
13
  const steps = useSelector(recorder.store, (state) => state.steps);
@@ -12,7 +12,8 @@ export type CreateHotkeyDefinition = AdapterHotkeyDefinition<CreateHotkeyTarget>
12
12
  *
13
13
  * Options merge in this order: provider defaults, app hotkey declaration,
14
14
  * commonOptions, per-hotkey options. Each option applies only to the kinds
15
- * that support it. Unbound app hotkeys and empty sequences register nothing.
15
+ * that support it. Unbound app hotkeys, empty sequences, and `undefined`,
16
+ * `null`, or `''` hotkeys register nothing.
16
17
  * A `null` target skips registration until it is set.
17
18
  *
18
19
  * @example
@@ -9,7 +9,8 @@ import { createHotkeyBindings, prepareHotkeyDefinitions } from "@tanstack/hotkey
9
9
  *
10
10
  * Options merge in this order: provider defaults, app hotkey declaration,
11
11
  * commonOptions, per-hotkey options. Each option applies only to the kinds
12
- * that support it. Unbound app hotkeys and empty sequences register nothing.
12
+ * that support it. Unbound app hotkeys, empty sequences, and `undefined`,
13
+ * `null`, or `''` hotkeys register nothing.
13
14
  * A `null` target skips registration until it is set.
14
15
  *
15
16
  * @example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-hotkeys",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "SolidJS 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.20.0"
41
+ "@tanstack/hotkeys": "0.21.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@solidjs/testing-library": "^0.8.10",