@tanstack/svelte-hotkeys 0.19.1 → 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.
package/dist/HotkeysCtx.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeySequenceRecorderOptions } from '@tanstack/hotkeys';
|
|
1
|
+
import type { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeySequenceRecorderOptions } from '@tanstack/hotkeys';
|
|
2
2
|
import type { HotkeysProviderScopeProps } from '@tanstack/hotkeys/adapter';
|
|
3
3
|
import type { CreateHotkeyCommonOptions } from './createHotkey.svelte.js';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
export interface HotkeysProviderOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The user's platform, for labels from `getFormatForDisplay`, hotkeys, and
|
|
8
|
+
* recorders. On a server, set it from the request with
|
|
9
|
+
* `detectPlatform(userAgent)`.
|
|
10
|
+
*/
|
|
11
|
+
platform?: HotkeyPlatform;
|
|
6
12
|
/**
|
|
7
13
|
* Defaults for every hotkey registered by `createHotkey` and `createHotkeys`.
|
|
8
14
|
* `requireReset` applies to chords and `timeout` applies to sequences.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { formatForDisplay } from '@tanstack/hotkeys';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `formatForDisplay` with the provider's `platform` as the default,
|
|
4
|
+
* so labels match the user's platform. Call during component initialization,
|
|
5
|
+
* like `getContext`; the returned function works anywhere and reads the
|
|
6
|
+
* provider's current defaults. An explicit `platform` option wins.
|
|
7
|
+
*
|
|
8
|
+
* Server-rendered apps should set the provider's `defaultOptions.platform`
|
|
9
|
+
* from the request user agent with `detectPlatform(userAgent)`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <script lang="ts">
|
|
14
|
+
* const format = getFormatForDisplay()
|
|
15
|
+
* </script>
|
|
16
|
+
*
|
|
17
|
+
* <kbd>{format('Mod+S')}</kbd>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function getFormatForDisplay(): typeof formatForDisplay;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { formatForDisplay } from '@tanstack/hotkeys';
|
|
2
|
+
import { getHotkeysContext } from './HotkeysCtx.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns `formatForDisplay` with the provider's `platform` as the default,
|
|
5
|
+
* so labels match the user's platform. Call during component initialization,
|
|
6
|
+
* like `getContext`; the returned function works anywhere and reads the
|
|
7
|
+
* provider's current defaults. 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
|
+
* ```svelte
|
|
14
|
+
* <script lang="ts">
|
|
15
|
+
* const format = getFormatForDisplay()
|
|
16
|
+
* </script>
|
|
17
|
+
*
|
|
18
|
+
* <kbd>{format('Mod+S')}</kbd>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function getFormatForDisplay() {
|
|
22
|
+
const context = getHotkeysContext();
|
|
23
|
+
return ((hotkey, options) => formatForDisplay(hotkey, {
|
|
24
|
+
...options,
|
|
25
|
+
platform: options?.platform ?? context?.defaultOptions.platform,
|
|
26
|
+
}));
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export { default as HotkeysProvider } from './HotkeysProvider.svelte';
|
|
|
12
12
|
export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkeysContext, } from './HotkeysCtx.js';
|
|
13
13
|
export type { HotkeysContextOptions, HotkeysProviderOptions, HotkeysProviderProps, } from './HotkeysCtx.js';
|
|
14
14
|
export * from './getHotkeyHint.svelte.js';
|
|
15
|
+
export * from './getFormatForDisplay.js';
|
package/dist/index.js
CHANGED
|
@@ -12,3 +12,4 @@ export * from './getAppHotkeys.svelte.js';
|
|
|
12
12
|
export { default as HotkeysProvider } from './HotkeysProvider.svelte';
|
|
13
13
|
export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkeysContext, } from './HotkeysCtx.js';
|
|
14
14
|
export * from './getHotkeyHint.svelte.js';
|
|
15
|
+
export * from './getFormatForDisplay.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
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.
|
|
44
|
+
"@tanstack/hotkeys": "0.23.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@sveltejs/package": "^3.0.0",
|
|
@@ -65,6 +65,7 @@ Before starting, load the `@tanstack/hotkeys#hotkeys-core` skill (`npx @tanstack
|
|
|
65
65
|
| `setHotkeysContext(options)` | Set the same options from a component's script instead of rendering `HotkeysProvider`; they apply to that component too. |
|
|
66
66
|
| `getHotkeysContext()` | Read the nearest context's merged defaults and enabled state, or `null` outside one. |
|
|
67
67
|
| `getDefaultHotkeysOptions()` | Read the default options merged from every context above. |
|
|
68
|
+
| `getFormatForDisplay()` | Get `formatForDisplay` with the provider's `platform` filled in, for labels in server-rendered apps. Call it during component initialization. |
|
|
68
69
|
| `getAppHotkeys()` | Read `.current`, the declared app hotkeys with the user's custom hotkeys applied. |
|
|
69
70
|
| `getAppHotkeyList()` | Read `.current`, every app hotkey with its status, for a cheat sheet or settings screen. |
|
|
70
71
|
| `getCustomHotkeys()` | Read the user's custom hotkeys from `.current`, change or reset them, and check a new one for conflicts. |
|
|
@@ -88,6 +89,7 @@ No provider is required. Call these at the top level of a component's `<script>`
|
|
|
88
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.
|
|
89
90
|
- **The callback isn't tracked.** Read state and props inside it.
|
|
90
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.
|
|
91
93
|
|
|
92
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).
|
|
93
95
|
|