@tanstack/solid-hotkeys 0.21.1 → 0.21.2

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.
@@ -5,8 +5,8 @@ import { JSX, ParentComponent } from "solid-js";
5
5
  export interface HotkeysProviderOptions {
6
6
  /**
7
7
  * The user's platform, for labels from `createFormatForDisplay`, hotkeys,
8
- * and recorders. On a server, set it from the request with
9
- * `detectPlatform(userAgent)`.
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
  /**
@@ -37,20 +37,25 @@ const HotkeysProvider = (props) => {
37
37
  const parent = useContext(HotkeysContext);
38
38
  const store = props.appHotkeys ? createAppHotkeysStore(props.appHotkeys, {
39
39
  customHotkeys: props.customHotkeys,
40
- onCustomHotkeysChange: (custom) => props.onCustomHotkeysChange?.(custom)
40
+ onCustomHotkeysChange: (custom) => props.onCustomHotkeysChange?.(custom),
41
+ platform: props.defaultOptions?.platform ?? parent?.defaultOptions.platform
41
42
  }) : null;
42
43
  createEffect(() => {
43
44
  if (props.appHotkeys) store?.setAppHotkeys(props.appHotkeys);
44
45
  });
45
- createEffect(() => {
46
- const customHotkeys = props.customHotkeys;
47
- store?.setOptions({ customHotkeys });
48
- });
49
46
  onMount(() => {
50
47
  if (store) onCleanup(publishAppHotkeysStore(store));
51
48
  });
52
49
  const active = () => (parent?.enabled ?? true) && props.enabled !== false;
53
50
  const defaultOptions = createMemo(() => mergeHotkeysProviderDefaults(parent?.defaultOptions, props.defaultOptions, props.scope));
51
+ if (store) createEffect(() => {
52
+ const customHotkeys = props.customHotkeys;
53
+ const platform = defaultOptions().platform;
54
+ store.setOptions({
55
+ customHotkeys,
56
+ platform
57
+ });
58
+ });
54
59
  const scopeKey = createMemo(() => getHotkeysProviderScopeKey({
55
60
  scope: props.scope,
56
61
  exclusive: props.exclusive,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-hotkeys",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
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.25.0"
41
+ "@tanstack/hotkeys": "0.25.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@solidjs/testing-library": "^0.8.10",
@@ -85,7 +85,7 @@ The state these return is accessors, including the recorder's fields. No provide
85
85
  - **The callback isn't tracked.** Read props inside it, as `() => props.onClose()`, rather than passing `props.onClose` itself.
86
86
  - **Register a dialog's hotkeys in a child of its provider.** A primitive uses the nearest `HotkeysProvider` above its component, so a dialog that renders `<HotkeysProvider scope={...} exclusive>` and creates `Escape` itself puts it in the suspended outer scope. Give each open dialog its own scope name, such as `` `dialog-${createUniqueId()}` ``.
87
87
  - **Call the primitives directly.** A `createShortcut(keys: string)` wrapper has to cast strings to hotkeys, which turns off type checking and drops sequences, accessor options, and app hotkeys.
88
- - **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 = createFormatForDisplay()` in the component, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser.
88
+ - **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 = createFormatForDisplay()` in the component, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser, when no provider sets `platform`.
89
89
 
90
90
  When declaring app hotkeys, building a cheat sheet, or letting users rebind shortcuts, load `@tanstack/hotkeys#app-hotkeys` and read [app hotkeys in Solid](references/app-hotkeys.md).
91
91