@tanstack/octane-hotkeys 0.11.1 → 0.11.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.
|
@@ -3,9 +3,10 @@ import { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions,
|
|
|
3
3
|
import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
4
4
|
export interface DefaultHotkeysOptions {
|
|
5
5
|
/**
|
|
6
|
-
* The user's platform, for labels from `useFormatForDisplay`, hotkeys,
|
|
7
|
-
* recorders
|
|
8
|
-
* request with
|
|
6
|
+
* The user's platform, for labels from `useFormatForDisplay`, hotkeys,
|
|
7
|
+
* recorders, and app hotkey checks such as conflicts. Defaults to detection.
|
|
8
|
+
* When server rendering, set it from the request with
|
|
9
|
+
* `detectPlatform(userAgent)`.
|
|
9
10
|
*/
|
|
10
11
|
platform?: HotkeyPlatform;
|
|
11
12
|
/**
|
package/dist/HotkeysProvider.js
CHANGED
|
@@ -24,18 +24,27 @@ function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys,
|
|
|
24
24
|
const parent = useContext(HotkeysContext);
|
|
25
25
|
const callbackRef = useRef(onCustomHotkeysChange, subSlot(void 0, "provider-callback"));
|
|
26
26
|
callbackRef.current = onCustomHotkeysChange;
|
|
27
|
+
const platform = defaultOptions?.platform ?? parent?.defaultOptions.platform;
|
|
27
28
|
const storeRef = useRef(void 0, subSlot(void 0, "provider-store"));
|
|
28
29
|
storeRef.current ??= appHotkeys ? createAppHotkeysStore(appHotkeys, {
|
|
29
30
|
customHotkeys,
|
|
30
|
-
onCustomHotkeysChange: (custom) => callbackRef.current?.(custom)
|
|
31
|
+
onCustomHotkeysChange: (custom) => callbackRef.current?.(custom),
|
|
32
|
+
platform
|
|
31
33
|
}) : null;
|
|
32
34
|
const store = storeRef.current;
|
|
33
35
|
useLayoutEffect(() => {
|
|
34
36
|
if (appHotkeys) store?.setAppHotkeys(appHotkeys);
|
|
35
37
|
}, [store, appHotkeys], subSlot(void 0, "provider-declarations"));
|
|
36
38
|
useLayoutEffect(() => {
|
|
37
|
-
store?.setOptions({
|
|
38
|
-
|
|
39
|
+
store?.setOptions({
|
|
40
|
+
customHotkeys,
|
|
41
|
+
platform
|
|
42
|
+
});
|
|
43
|
+
}, [
|
|
44
|
+
store,
|
|
45
|
+
customHotkeys,
|
|
46
|
+
platform
|
|
47
|
+
], subSlot(void 0, "provider-custom-hotkeys"));
|
|
39
48
|
useLayoutEffect(() => store ? publishAppHotkeysStore(store) : void 0, [store], subSlot(void 0, "provider-publish"));
|
|
40
49
|
const active = (parent?.enabled ?? true) && enabled;
|
|
41
50
|
const scopeKey = getHotkeysProviderScopeKey({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/octane-hotkeys",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
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.25.
|
|
38
|
+
"@tanstack/hotkeys": "0.25.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@tsrx/oxc": "0.23.0",
|
|
@@ -78,7 +78,7 @@ No provider is required. Use Octane 0.12 or newer, with hooks in compiler-enable
|
|
|
78
78
|
- **Hooks are tracked by call site.** Use `useHotkeys(items.map(...))` for lists, not `useHotkey` in a loop.
|
|
79
79
|
- **Custom hooks in plain `.ts` and `.js` files need the compiler.** Calls from a `.ts` or `.js` file that the compiler skips share one slot per hook in each component, even across different custom hooks, so only the last `useHotkey` call works. The compiler handles a file that imports a value from `octane` or starts with `/** @jsxImportSource octane */`. A type-only import doesn't count. `.tsrx` and `.tsx` files are fine.
|
|
80
80
|
- **Call the hooks directly.** A `useShortcut(keys: string)` wrapper has to cast strings to hotkeys, which turns off type checking and drops sequences, options, and app hotkeys.
|
|
81
|
-
- **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 = useFormatForDisplay()` at the top of the component, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser
|
|
81
|
+
- **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 = useFormatForDisplay()` at the top of the component, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser, when no provider sets `platform`.
|
|
82
82
|
|
|
83
83
|
When declaring app hotkeys, building a cheat sheet, or letting users rebind shortcuts, load `@tanstack/hotkeys#app-hotkeys` and read [app hotkeys in Octane](references/app-hotkeys.md).
|
|
84
84
|
|