@tanstack/solid-hotkeys 0.19.2 → 0.20.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.
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { CreateHotkeyCommonOptions } from "./createHotkey.js";
|
|
2
|
-
import { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
+
import { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
3
3
|
import { JSX, ParentComponent } from "solid-js";
|
|
4
4
|
import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
5
5
|
//#region src/HotkeysProvider.d.ts
|
|
6
6
|
export interface HotkeysProviderOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The user's platform, for labels from `createFormatForDisplay`, hotkeys,
|
|
9
|
+
* and recorders. On a server, set it from the request with
|
|
10
|
+
* `detectPlatform(userAgent)`.
|
|
11
|
+
*/
|
|
12
|
+
platform?: HotkeyPlatform;
|
|
7
13
|
/**
|
|
8
14
|
* Defaults for every hotkey registered by `createHotkey` and `createHotkeys`.
|
|
9
15
|
* `requireReset` applies to chords and `timeout` applies to sequences.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
2
|
+
//#region src/createFormatForDisplay.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns `formatForDisplay` with the provider's `platform` as the default,
|
|
5
|
+
* so labels match the user's platform. Call in a component; the returned
|
|
6
|
+
* function works anywhere, and JSX updates when the provider's platform
|
|
7
|
+
* changes. An explicit `platform` option wins.
|
|
8
|
+
*
|
|
9
|
+
* Server-rendered apps should set the provider's `defaultOptions.platform`
|
|
10
|
+
* from the request user agent with `detectPlatform(userAgent)`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function SaveButton() {
|
|
15
|
+
* const format = createFormatForDisplay()
|
|
16
|
+
* return <kbd>{format('Mod+S')}</kbd>
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function createFormatForDisplay(): typeof formatForDisplay;
|
|
21
|
+
//#endregion
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
|
|
2
|
+
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
3
|
+
|
|
4
|
+
//#region src/createFormatForDisplay.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns `formatForDisplay` with the provider's `platform` as the default,
|
|
7
|
+
* so labels match the user's platform. Call in a component; the returned
|
|
8
|
+
* function works anywhere, and JSX updates when the provider's platform
|
|
9
|
+
* changes. An explicit `platform` option wins.
|
|
10
|
+
*
|
|
11
|
+
* Server-rendered apps should set the provider's `defaultOptions.platform`
|
|
12
|
+
* from the request user agent with `detectPlatform(userAgent)`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function SaveButton() {
|
|
17
|
+
* const format = createFormatForDisplay()
|
|
18
|
+
* return <kbd>{format('Mod+S')}</kbd>
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function createFormatForDisplay() {
|
|
23
|
+
const defaultOptions = useDefaultHotkeysOptionsSource();
|
|
24
|
+
return ((hotkey, options) => formatForDisplay(hotkey, {
|
|
25
|
+
...options,
|
|
26
|
+
platform: options?.platform ?? defaultOptions().platform
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createFormatForDisplay };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorde
|
|
|
5
5
|
import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
6
6
|
import { createHotkeyScopesState } from "./createHotkeyScopesState.js";
|
|
7
7
|
import { createHotkeyHint } from "./createHotkeyHint.js";
|
|
8
|
+
import { createFormatForDisplay } from "./createFormatForDisplay.js";
|
|
8
9
|
import { UseCustomHotkeysResult, createAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./appHotkeys.js";
|
|
9
10
|
import { createHeldKeys } from "./createHeldKeys.js";
|
|
10
11
|
import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
11
12
|
import { createKeyHold } from "./createKeyHold.js";
|
|
12
13
|
export * from "@tanstack/hotkeys";
|
|
13
|
-
export { CreateAppHotkeyOptions, CreateHotkeyChordOptions, CreateHotkeyCommonOptions, CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeyOptionsFor, CreateHotkeySequenceOptions, CreateHotkeyTarget, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, UseCustomHotkeysResult, createAppHotkeyList, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
|
|
14
|
+
export { CreateAppHotkeyOptions, CreateHotkeyChordOptions, CreateHotkeyCommonOptions, CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeyOptionsFor, CreateHotkeySequenceOptions, CreateHotkeyTarget, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, UseCustomHotkeysResult, createAppHotkeyList, createFormatForDisplay, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
|
5
5
|
import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
6
6
|
import { createHotkeyScopesState } from "./createHotkeyScopesState.js";
|
|
7
7
|
import { createHotkeyHint } from "./createHotkeyHint.js";
|
|
8
|
+
import { createFormatForDisplay } from "./createFormatForDisplay.js";
|
|
8
9
|
import { createAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./appHotkeys.js";
|
|
9
10
|
import { createHeldKeys } from "./createHeldKeys.js";
|
|
10
11
|
import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
@@ -12,4 +13,4 @@ import { createKeyHold } from "./createKeyHold.js";
|
|
|
12
13
|
|
|
13
14
|
export * from "@tanstack/hotkeys"
|
|
14
15
|
|
|
15
|
-
export { HotkeysProvider, createAppHotkeyList, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
|
|
16
|
+
export { HotkeysProvider, createAppHotkeyList, createFormatForDisplay, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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.
|
|
41
|
+
"@tanstack/hotkeys": "0.23.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@solidjs/testing-library": "^0.8.10",
|
|
@@ -61,6 +61,7 @@ export function Editor() {
|
|
|
61
61
|
| `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
|
|
62
62
|
| `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
|
|
63
63
|
| `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
|
|
64
|
+
| `createFormatForDisplay()` | Get `formatForDisplay` with the provider's `platform` filled in, for labels in server-rendered apps. |
|
|
64
65
|
| `useAppHotkeys()` | Get an accessor of the declared app hotkeys with the user's custom hotkeys applied. |
|
|
65
66
|
| `createAppHotkeyList()` | Get an accessor listing every app hotkey with its status, for a cheat sheet or settings screen. |
|
|
66
67
|
| `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
|
|
@@ -84,6 +85,7 @@ The state these return is accessors, including the recorder's fields. No provide
|
|
|
84
85
|
- **The callback isn't tracked.** Read props inside it, as `() => props.onClose()`, rather than passing `props.onClose` itself.
|
|
85
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()}` ``.
|
|
86
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.
|
|
87
89
|
|
|
88
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).
|
|
89
91
|
|