@tanstack/svelte-hotkeys 0.21.0 → 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 +6 -6
- package/dist/HotkeysCtx.js +4 -2
- package/dist/HotkeysProvider.svelte +7 -4
- package/dist/createHotkey.svelte.d.ts +1 -1
- package/dist/createHotkeys.svelte.d.ts +2 -2
- package/dist/getAppHotkeys.svelte.js +2 -2
- package/dist/getHotkeyHint.svelte.js +1 -1
- package/dist/internal.svelte.js +1 -1
- package/package.json +8 -6
- package/skills/svelte-hotkeys/SKILL.md +1 -1
package/dist/HotkeysCtx.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeySequenceRecorderOptions } from '@tanstack/hotkeys';
|
|
2
2
|
import type { HotkeysProviderScopeProps } from '@tanstack/hotkeys/adapter';
|
|
3
|
-
import type { CreateHotkeyCommonOptions } from './createHotkey.svelte.js';
|
|
4
3
|
import type { Snippet } from 'svelte';
|
|
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
|
/**
|
|
@@ -29,8 +29,8 @@ export interface HotkeysContextOptions extends HotkeysProviderScopeProps {
|
|
|
29
29
|
/**
|
|
30
30
|
* The user's saved custom hotkeys. When the value changes, such as after
|
|
31
31
|
* saved data loads or the user signs in, it replaces the current custom
|
|
32
|
-
* hotkeys. `undefined` leaves them unchanged; `null` clears them.
|
|
33
|
-
* entries are ignored
|
|
32
|
+
* hotkeys. `undefined` leaves them unchanged; `null` clears them. Unknown
|
|
33
|
+
* ids and invalid entries are ignored.
|
|
34
34
|
*/
|
|
35
35
|
customHotkeys?: CustomHotkeys | null;
|
|
36
36
|
/** Called with the custom hotkeys after every change, ready to save. */
|
package/dist/HotkeysCtx.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createContext, onMount } from 'svelte';
|
|
2
1
|
import { publishAppHotkeysStore } from '@tanstack/hotkeys';
|
|
3
2
|
import { createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults, } from '@tanstack/hotkeys/adapter';
|
|
3
|
+
import { createContext, onMount } from 'svelte';
|
|
4
4
|
import { activateScopeWhileMounted } from './internal.svelte.js';
|
|
5
5
|
export const DEFAULT_OPTIONS = {};
|
|
6
6
|
const [useHotkeysContext, setHotkeysContextValue] = createContext();
|
|
@@ -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;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { setHotkeysContextSource } from './HotkeysCtx.js'
|
|
3
|
-
|
|
4
3
|
import type { HotkeysProviderProps } from './HotkeysCtx.js'
|
|
5
4
|
|
|
6
5
|
let {
|
|
@@ -29,10 +28,14 @@
|
|
|
29
28
|
if (appHotkeys) context.appHotkeysStore?.setAppHotkeys(appHotkeys)
|
|
30
29
|
})
|
|
31
30
|
|
|
32
|
-
// Apply saved custom hotkeys whose value changes, such as
|
|
33
|
-
// 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.
|
|
34
34
|
$effect(() => {
|
|
35
|
-
|
|
35
|
+
const platform = context.defaultOptions.platform
|
|
36
|
+
if (appHotkeys) {
|
|
37
|
+
context.appHotkeysStore?.setOptions({ customHotkeys, platform })
|
|
38
|
+
}
|
|
36
39
|
})
|
|
37
40
|
</script>
|
|
38
41
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Attachment } from 'svelte/attachments';
|
|
2
1
|
import type { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey } from '@tanstack/hotkeys';
|
|
3
2
|
import type { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from '@tanstack/hotkeys/adapter';
|
|
3
|
+
import type { Attachment } from 'svelte/attachments';
|
|
4
4
|
import type { MaybeGetter } from './internal.svelte.js';
|
|
5
5
|
/** The document or window to listen on. Use an attachment for elements. */
|
|
6
6
|
export type CreateHotkeyTarget = Document | Window;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Attachment } from 'svelte/attachments';
|
|
2
1
|
import type { AppHotkey, HotkeyCallback, RegisterableHotkey, RegisterableHotkeyChord, RegisterableHotkeySequence } from '@tanstack/hotkeys';
|
|
3
|
-
import type {
|
|
2
|
+
import type { Attachment } from 'svelte/attachments';
|
|
4
3
|
import type { CreateAppHotkeyOptions, CreateHotkeyChordOptions, CreateHotkeyCommonOptions, CreateHotkeyOptions, CreateHotkeySequenceOptions } from './createHotkey.svelte.js';
|
|
4
|
+
import type { MaybeGetter } from './internal.svelte.js';
|
|
5
5
|
/**
|
|
6
6
|
* One hotkey for `createHotkeys`. The hotkey and options may be getters.
|
|
7
7
|
* Chords accept `requireReset`; sequences accept `timeout`; hotkeys of unknown
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getHotkeysContext } from './HotkeysCtx.js';
|
|
2
|
-
import { createStoreSubscriber } from './internal.svelte.js';
|
|
3
2
|
import { getHotkeyRegistrations } from './getHotkeyRegistrations.svelte.js';
|
|
3
|
+
import { createStoreSubscriber } from './internal.svelte.js';
|
|
4
4
|
function requireStore(name) {
|
|
5
5
|
const store = getHotkeysContext()?.appHotkeysStore;
|
|
6
6
|
if (!store) {
|
|
7
|
-
throw new Error(
|
|
7
|
+
throw new Error(`[hotkeys] ${name} requires a HotkeysProvider with appHotkeys`);
|
|
8
8
|
}
|
|
9
9
|
return {
|
|
10
10
|
store: store,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createSubscriber } from 'svelte/reactivity';
|
|
2
1
|
import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey, } from '@tanstack/hotkeys';
|
|
2
|
+
import { createSubscriber } from 'svelte/reactivity';
|
|
3
3
|
import { getHotkeysContext } from './HotkeysCtx.js';
|
|
4
4
|
import { resolveMaybeGetter } from './internal.svelte.js';
|
|
5
5
|
/**
|
package/dist/internal.svelte.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createSubscriber } from 'svelte/reactivity';
|
|
2
1
|
import { activateHotkeysProviderScope } from '@tanstack/hotkeys/adapter';
|
|
2
|
+
import { createSubscriber } from 'svelte/reactivity';
|
|
3
3
|
export function resolveMaybeGetter(value) {
|
|
4
4
|
return typeof value === 'function' ? value() : value;
|
|
5
5
|
}
|
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,14 +41,15 @@
|
|
|
41
41
|
"skills"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@tanstack/hotkeys": "0.
|
|
44
|
+
"@tanstack/hotkeys": "0.25.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@sveltejs/package": "^3.0.
|
|
47
|
+
"@sveltejs/package": "^3.0.2",
|
|
48
48
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
49
|
-
"@typescript-eslint/parser": "^8.
|
|
50
|
-
"eslint
|
|
51
|
-
"svelte": "^
|
|
49
|
+
"@typescript-eslint/parser": "^8.72.1",
|
|
50
|
+
"eslint": "^10.14.0",
|
|
51
|
+
"eslint-plugin-svelte": "^3.24.0",
|
|
52
|
+
"svelte": "^5.57.3"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
55
|
"svelte": "^5.40.0"
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
61
|
"clean": "premove ./dist ./coverage",
|
|
62
|
+
"test:oxlint": "oxlint ./src",
|
|
61
63
|
"test:eslint": "eslint ./src",
|
|
62
64
|
"test:lib": "vitest --passWithNoTests",
|
|
63
65
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
@@ -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
|
|