@tanstack/svelte-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.
package/dist/HotkeysCtx.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { Snippet } from 'svelte';
|
|
|
4
4
|
import type { CreateHotkeyCommonOptions } from './createHotkey.svelte.js';
|
|
5
5
|
export interface HotkeysProviderOptions {
|
|
6
6
|
/**
|
|
7
|
-
* The user's platform, for labels from `getFormatForDisplay`, hotkeys,
|
|
8
|
-
* recorders. On a server, set it
|
|
9
|
-
* `detectPlatform(userAgent)`.
|
|
7
|
+
* The user's platform, for labels from `getFormatForDisplay`, hotkeys,
|
|
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/HotkeysCtx.js
CHANGED
|
@@ -31,10 +31,12 @@ export function setHotkeysContext(options = {}) {
|
|
|
31
31
|
/** Sets the context from a getter, so default options stay reactive. */
|
|
32
32
|
export function setHotkeysContextSource(source) {
|
|
33
33
|
const parent = getHotkeysContext();
|
|
34
|
-
const { appHotkeys, customHotkeys } = source();
|
|
34
|
+
const { appHotkeys, customHotkeys, defaultOptions } = source();
|
|
35
35
|
const store = appHotkeys
|
|
36
36
|
? createAppHotkeysStore(appHotkeys, {
|
|
37
37
|
customHotkeys,
|
|
38
|
+
// App hotkeys compare hotkeys, such as for conflicts, on this platform.
|
|
39
|
+
platform: defaultOptions?.platform ?? parent?.defaultOptions.platform,
|
|
38
40
|
onCustomHotkeysChange: (custom) => source().onCustomHotkeysChange?.(custom),
|
|
39
41
|
})
|
|
40
42
|
: null;
|
|
@@ -28,10 +28,14 @@
|
|
|
28
28
|
if (appHotkeys) context.appHotkeysStore?.setAppHotkeys(appHotkeys)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
// Apply saved custom hotkeys whose value changes, such as
|
|
32
|
-
// after the first render. Only a provider with appHotkeys
|
|
31
|
+
// Apply the platform and saved custom hotkeys whose value changes, such as
|
|
32
|
+
// data that loads after the first render. Only a provider with appHotkeys
|
|
33
|
+
// owns a store.
|
|
33
34
|
$effect(() => {
|
|
34
|
-
|
|
35
|
+
const platform = context.defaultOptions.platform
|
|
36
|
+
if (appHotkeys) {
|
|
37
|
+
context.appHotkeysStore?.setOptions({ customHotkeys, platform })
|
|
38
|
+
}
|
|
35
39
|
})
|
|
36
40
|
</script>
|
|
37
41
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-hotkeys",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.2",
|
|
4
4
|
"description": "Svelte adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Kunal Rao",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"skills"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@tanstack/hotkeys": "0.25.
|
|
44
|
+
"@tanstack/hotkeys": "0.25.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@sveltejs/package": "^3.0.2",
|
|
@@ -89,7 +89,7 @@ No provider is required. Call these at the top level of a component's `<script>`
|
|
|
89
89
|
- **Call `setHotkeysContext` before creating the component's hotkeys.** It applies to the component itself, so a hotkey created first lands in the outer scope, which an exclusive context then suspends. It reads its options once; for `enabled` or `exclusive` that change, wrap the component in `<HotkeysProvider>`. Give each open dialog its own scope name.
|
|
90
90
|
- **The callback isn't tracked.** Read state and props inside it.
|
|
91
91
|
- **Call the functions directly.** A `createShortcut(keys: string)` wrapper has to cast strings to hotkeys, which turns off type checking and drops sequences, getter options, and app hotkeys.
|
|
92
|
-
- **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 = getFormatForDisplay()` during component initialization, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser
|
|
92
|
+
- **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 = getFormatForDisplay()` during component initialization, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser, when no provider sets `platform`.
|
|
93
93
|
|
|
94
94
|
When declaring app hotkeys, building a cheat sheet, or letting users rebind shortcuts, load `@tanstack/hotkeys#app-hotkeys` and read [app hotkeys in Svelte](references/app-hotkeys.md).
|
|
95
95
|
|