@tanstack/svelte-hotkeys 0.18.0 → 0.19.1
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 +4 -2
- package/dist/HotkeysProvider.svelte +6 -0
- package/dist/createHotkey.svelte.d.ts +7 -5
- package/dist/createHotkeyRecorder.svelte.js +2 -4
- package/dist/createHotkeys.svelte.d.ts +7 -3
- package/dist/createHotkeys.svelte.js +2 -1
- package/dist/getHotkeyHint.svelte.d.ts +3 -2
- package/dist/getHotkeyHint.svelte.js +2 -1
- package/package.json +2 -2
package/dist/HotkeysCtx.d.ts
CHANGED
|
@@ -21,8 +21,10 @@ export interface HotkeysContextOptions extends HotkeysProviderScopeProps {
|
|
|
21
21
|
*/
|
|
22
22
|
appHotkeys?: AppHotkeys;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* the
|
|
24
|
+
* The user's saved custom hotkeys. When the value changes, such as after
|
|
25
|
+
* saved data loads or the user signs in, it replaces the current custom
|
|
26
|
+
* hotkeys. `undefined` leaves them unchanged; `null` clears them. Invalid
|
|
27
|
+
* entries are ignored with a warning.
|
|
26
28
|
*/
|
|
27
29
|
customHotkeys?: CustomHotkeys | null;
|
|
28
30
|
/** Called with the custom hotkeys after every change, ready to save. */
|
|
@@ -28,6 +28,12 @@
|
|
|
28
28
|
$effect(() => {
|
|
29
29
|
if (appHotkeys) context.appHotkeysStore?.setAppHotkeys(appHotkeys)
|
|
30
30
|
})
|
|
31
|
+
|
|
32
|
+
// Apply saved custom hotkeys whose value changes, such as data that loads
|
|
33
|
+
// after the first render. Only a provider with appHotkeys owns a store.
|
|
34
|
+
$effect(() => {
|
|
35
|
+
if (appHotkeys) context.appHotkeysStore?.setOptions({ customHotkeys })
|
|
36
|
+
})
|
|
31
37
|
</script>
|
|
32
38
|
|
|
33
39
|
{@render children()}
|
|
@@ -26,6 +26,7 @@ export type CreateAppHotkeyOptions<T extends AppHotkey = AppHotkey> = AdapterApp
|
|
|
26
26
|
* sequence registers as its chord. An app hotkey uses its effective hotkey
|
|
27
27
|
* from `HotkeysProvider` (including the user's custom hotkey) and its
|
|
28
28
|
* declared meta and options, and registers nothing while unbound.
|
|
29
|
+
* `undefined`, `null`, or `''` registers nothing, for an optional shortcut.
|
|
29
30
|
*
|
|
30
31
|
* @example
|
|
31
32
|
* ```svelte
|
|
@@ -36,11 +37,12 @@ export type CreateAppHotkeyOptions<T extends AppHotkey = AppHotkey> = AdapterApp
|
|
|
36
37
|
* </script>
|
|
37
38
|
* ```
|
|
38
39
|
*/
|
|
39
|
-
export declare function createHotkey<T extends AppHotkey>(hotkey: MaybeGetter<T>, callback: HotkeyCallback, options?: MaybeGetter<CreateAppHotkeyOptions<T>>): void;
|
|
40
|
-
export declare function createHotkey<const T extends RegisterableHotkey>(hotkey: MaybeGetter<T>, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: MaybeGetter<CreateHotkeyOptionsFor<T>>): void;
|
|
40
|
+
export declare function createHotkey<T extends AppHotkey>(hotkey: MaybeGetter<T | null | undefined>, callback: HotkeyCallback, options?: MaybeGetter<CreateAppHotkeyOptions<T>>): void;
|
|
41
|
+
export declare function createHotkey<const T extends RegisterableHotkey>(hotkey: MaybeGetter<T | null | undefined>, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: MaybeGetter<CreateHotkeyOptionsFor<T>>): void;
|
|
41
42
|
/**
|
|
42
43
|
* Create an attachment for an element-scoped hotkey: a chord, a sequence, or
|
|
43
|
-
* an app hotkey that listens on the attached element.
|
|
44
|
+
* an app hotkey that listens on the attached element. `undefined`, `null`,
|
|
45
|
+
* or `''` registers nothing, for an optional shortcut.
|
|
44
46
|
*
|
|
45
47
|
* @example
|
|
46
48
|
* ```svelte
|
|
@@ -51,5 +53,5 @@ export declare function createHotkey<const T extends RegisterableHotkey>(hotkey:
|
|
|
51
53
|
* <div tabindex="0" {@attach saveKey}>Editor content</div>
|
|
52
54
|
* ```
|
|
53
55
|
*/
|
|
54
|
-
export declare function createHotkeyAttachment<T extends AppHotkey>(hotkey: MaybeGetter<T>, callback: HotkeyCallback, options?: MaybeGetter<CreateAppHotkeyOptions<T>>): Attachment<HTMLElement>;
|
|
55
|
-
export declare function createHotkeyAttachment<const T extends RegisterableHotkey>(hotkey: MaybeGetter<T>, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: MaybeGetter<CreateHotkeyOptionsFor<T>>): Attachment<HTMLElement>;
|
|
56
|
+
export declare function createHotkeyAttachment<T extends AppHotkey>(hotkey: MaybeGetter<T | null | undefined>, callback: HotkeyCallback, options?: MaybeGetter<CreateAppHotkeyOptions<T>>): Attachment<HTMLElement>;
|
|
57
|
+
export declare function createHotkeyAttachment<const T extends RegisterableHotkey>(hotkey: MaybeGetter<T | null | undefined>, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: MaybeGetter<CreateHotkeyOptionsFor<T>>): Attachment<HTMLElement>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HotkeyRecorder } from '@tanstack/hotkeys';
|
|
2
|
+
import { withDefaults } from '@tanstack/hotkeys/adapter';
|
|
2
3
|
import { getDefaultHotkeysOptions } from './HotkeysCtx.js';
|
|
3
4
|
import { createStoreSubscriber, resolveMaybeGetter } from './internal.svelte.js';
|
|
4
5
|
class SvelteHotkeyRecorderState {
|
|
@@ -41,10 +42,7 @@ class SvelteHotkeyRecorderState {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
export function createHotkeyRecorder(options) {
|
|
44
|
-
const resolve = () => (
|
|
45
|
-
...getDefaultHotkeysOptions().hotkeyRecorder,
|
|
46
|
-
...resolveMaybeGetter(options),
|
|
47
|
-
});
|
|
45
|
+
const resolve = () => withDefaults(getDefaultHotkeysOptions().hotkeyRecorder, resolveMaybeGetter(options));
|
|
48
46
|
// Overloads already checked the options; either shape is valid here.
|
|
49
47
|
const recorder = new SvelteHotkeyRecorderState(resolve());
|
|
50
48
|
$effect(() => {
|
|
@@ -25,8 +25,11 @@ export type CreateHotkeyDefinition = {
|
|
|
25
25
|
callback: HotkeyCallback;
|
|
26
26
|
options?: MaybeGetter<CreateAppHotkeyOptions>;
|
|
27
27
|
} | {
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* A hotkey whose kind is not known statically. Accepts only shared
|
|
30
|
+
* options. `undefined`, `null`, or `''` registers nothing.
|
|
31
|
+
*/
|
|
32
|
+
hotkey: MaybeGetter<RegisterableHotkey | null | undefined>;
|
|
30
33
|
callback: HotkeyCallback;
|
|
31
34
|
options?: MaybeGetter<CreateHotkeyOptions>;
|
|
32
35
|
};
|
|
@@ -37,7 +40,8 @@ export type CreateHotkeyDefinition = {
|
|
|
37
40
|
*
|
|
38
41
|
* Options merge in this order: provider defaults, app hotkey declaration,
|
|
39
42
|
* commonOptions, per-hotkey options. Each option applies only to the kinds
|
|
40
|
-
* that support it. Unbound app hotkeys
|
|
43
|
+
* that support it. Unbound app hotkeys, empty sequences, and `undefined`,
|
|
44
|
+
* `null`, or `''` hotkeys register nothing.
|
|
41
45
|
*
|
|
42
46
|
* @example
|
|
43
47
|
* ```svelte
|
|
@@ -40,7 +40,8 @@ function bindHotkeys(hotkeys, commonOptions, element) {
|
|
|
40
40
|
*
|
|
41
41
|
* Options merge in this order: provider defaults, app hotkey declaration,
|
|
42
42
|
* commonOptions, per-hotkey options. Each option applies only to the kinds
|
|
43
|
-
* that support it. Unbound app hotkeys
|
|
43
|
+
* that support it. Unbound app hotkeys, empty sequences, and `undefined`,
|
|
44
|
+
* `null`, or `''` hotkeys register nothing.
|
|
44
45
|
*
|
|
45
46
|
* @example
|
|
46
47
|
* ```svelte
|
|
@@ -9,6 +9,7 @@ export interface SvelteHotkeyHint {
|
|
|
9
9
|
* fire: some registration of it is enabled and in an active scope. Pass
|
|
10
10
|
* getters to track changing hotkeys and options. A sequence reveals its hint
|
|
11
11
|
* from its first step, and an app hotkey matches its registrations by id and
|
|
12
|
-
* uses its effective hotkey (false while unbound).
|
|
12
|
+
* uses its effective hotkey (false while unbound). No hotkey (`undefined`,
|
|
13
|
+
* `null`, or `''`) returns false. This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
|
|
13
14
|
*/
|
|
14
|
-
export declare function getHotkeyHint(hotkey: MaybeGetter<RegisterableHotkey | AppHotkey>, options?: MaybeGetter<HeldModifierOptions>): SvelteHotkeyHint;
|
|
15
|
+
export declare function getHotkeyHint(hotkey: MaybeGetter<RegisterableHotkey | AppHotkey | null | undefined>, options?: MaybeGetter<HeldModifierOptions>): SvelteHotkeyHint;
|
|
@@ -8,7 +8,8 @@ import { resolveMaybeGetter } from './internal.svelte.js';
|
|
|
8
8
|
* fire: some registration of it is enabled and in an active scope. Pass
|
|
9
9
|
* getters to track changing hotkeys and options. A sequence reveals its hint
|
|
10
10
|
* from its first step, and an app hotkey matches its registrations by id and
|
|
11
|
-
* uses its effective hotkey (false while unbound).
|
|
11
|
+
* uses its effective hotkey (false while unbound). No hotkey (`undefined`,
|
|
12
|
+
* `null`, or `''`) returns false. This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
|
|
12
13
|
*/
|
|
13
14
|
export function getHotkeyHint(hotkey, options = {}) {
|
|
14
15
|
const tracker = getKeyStateTracker();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
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.22.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@sveltejs/package": "^3.0.0",
|