@tanstack/solid-hotkeys 0.21.1 → 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.
|
@@ -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
|
|
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
|
/**
|
package/dist/HotkeysProvider.js
CHANGED
|
@@ -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/dist/createHotkey.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey, Target } from "@tanstack/hotkeys";
|
|
2
2
|
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
/**
|
|
4
|
-
* The element to listen on. A `null` target skips
|
|
5
|
-
* accessor such as `() => ({ target: element() })`
|
|
6
|
-
* after mount.
|
|
4
|
+
* The element to listen on. A `null` or `undefined` target skips
|
|
5
|
+
* registration, so pass an accessor such as `() => ({ target: element() })`
|
|
6
|
+
* for elements that attach after mount. Omit `target` for the document.
|
|
7
7
|
*/
|
|
8
8
|
export type CreateHotkeyTarget = Target | null;
|
|
9
9
|
/** Options shared by chords and sequences. */
|
package/dist/createHotkeys.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type CreateHotkeyDefinition = AdapterHotkeyDefinition<CreateHotkeyTarget>
|
|
|
13
13
|
* commonOptions, per-hotkey options. Each option applies only to the kinds
|
|
14
14
|
* that support it. Unbound app hotkeys, empty sequences, and `undefined`,
|
|
15
15
|
* `null`, or `''` hotkeys register nothing.
|
|
16
|
-
* A `null` target skips registration until it is set.
|
|
16
|
+
* A `null` or `undefined` target skips registration until it is set.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```tsx
|
package/dist/createHotkeys.js
CHANGED
|
@@ -12,7 +12,7 @@ import { createEffect, onCleanup, untrack } from "solid-js";
|
|
|
12
12
|
* commonOptions, per-hotkey options. Each option applies only to the kinds
|
|
13
13
|
* that support it. Unbound app hotkeys, empty sequences, and `undefined`,
|
|
14
14
|
* `null`, or `''` hotkeys register nothing.
|
|
15
|
-
* A `null` target skips registration until it is set.
|
|
15
|
+
* A `null` or `undefined` target skips registration until it is set.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-hotkeys",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.3",
|
|
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.
|
|
41
|
+
"@tanstack/hotkeys": "0.26.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@solidjs/testing-library": "^0.8.10",
|
|
@@ -80,12 +80,12 @@ The state these return is accessors, including the recorder's fields. No provide
|
|
|
80
80
|
## Pitfalls
|
|
81
81
|
|
|
82
82
|
- **Pass options as an accessor.** `{ enabled: isDirty() }` is read once, during setup, so the hotkey never follows the signal. Use `() => ({ enabled: isDirty() })`. The hotkey and `createHotkeys`' definitions also accept accessors.
|
|
83
|
-
- **Keep element targets in a signal.** A `let el` variable is still `undefined` when the options are read, and
|
|
83
|
+
- **Keep element targets in a signal.** A `let el` variable is still `undefined` when the options are read, and nothing tracks it, so the hotkey waits and never registers. Use `ref={setEl}` and `() => ({ target: el() })`; a `null` or `undefined` target waits for the element.
|
|
84
84
|
- **Register hotkeys for removable elements in their `ref`.** Solid never calls a `ref` with `null`, so a signal keeps an element that `<Show>` or `<For>` removed, and the hotkey stays registered on it. Use `ref={(el) => createHotkey('K', cb, { target: el })}`; the hotkey unregisters when the element is removed.
|
|
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
|
|