@tanstack/svelte-hotkeys 0.7.0 → 0.8.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/README.md +1 -1
- package/dist/createHotkey.svelte.js +4 -10
- package/dist/createHotkeys.svelte.js +3 -9
- package/package.json +2 -2
- package/src/createHotkey.svelte.ts +13 -16
- package/src/createHotkeys.svelte.ts +9 -14
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
# TanStack Hotkeys
|
|
38
38
|
|
|
39
39
|
> [!NOTE]
|
|
40
|
-
> TanStack Hotkeys is
|
|
40
|
+
> TanStack Hotkeys is alpha. We are actively developing the library and are open to feedback and contributions.
|
|
41
41
|
|
|
42
42
|
Type-safe keyboard shortcuts for the web. Template-string bindings, parsed objects, a cross-platform `Mod` key, a singleton Hotkey Manager, and utilities for cheatsheet UIs—built to stay SSR-friendly.
|
|
43
43
|
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { detectPlatform,
|
|
1
|
+
import { detectPlatform, getHotkeyManager, normalizeRegisterableHotkey, } from '@tanstack/hotkeys';
|
|
2
2
|
import { onDestroy } from 'svelte';
|
|
3
3
|
import { getDefaultHotkeysOptions } from './HotkeysCtx';
|
|
4
4
|
import { resolveMaybeGetter } from './internal.svelte';
|
|
5
|
-
function normalizeHotkey(hotkey, options) {
|
|
6
|
-
const platform = options.platform ?? detectPlatform();
|
|
7
|
-
return typeof hotkey === 'string'
|
|
8
|
-
? hotkey
|
|
9
|
-
: formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform));
|
|
10
|
-
}
|
|
11
5
|
function registerHotkey(target, hotkey, callback, mergedOptions) {
|
|
12
|
-
return getHotkeyManager().register(
|
|
6
|
+
return getHotkeyManager().register(normalizeRegisterableHotkey(hotkey, mergedOptions.platform ?? detectPlatform()), callback, {
|
|
13
7
|
...mergedOptions,
|
|
14
8
|
target,
|
|
15
9
|
});
|
|
@@ -41,7 +35,7 @@ export function createHotkey(hotkey, callback, options = {}) {
|
|
|
41
35
|
...getDefaultHotkeysOptions().hotkey,
|
|
42
36
|
...resolvedOptions,
|
|
43
37
|
};
|
|
44
|
-
const hotkeyStr =
|
|
38
|
+
const hotkeyStr = normalizeRegisterableHotkey(resolvedHotkey, mergedOptions.platform ?? detectPlatform());
|
|
45
39
|
const { target: _t, ...optionsWithoutTarget } = mergedOptions;
|
|
46
40
|
if (registration?.isActive && lastHotkeyStr === hotkeyStr) {
|
|
47
41
|
registration.callback = callback;
|
|
@@ -93,7 +87,7 @@ export function createHotkeyAttachment(hotkey, callback, options = {}) {
|
|
|
93
87
|
...getDefaultHotkeysOptions().hotkey,
|
|
94
88
|
...resolvedOptions,
|
|
95
89
|
};
|
|
96
|
-
const hotkeyStr =
|
|
90
|
+
const hotkeyStr = normalizeRegisterableHotkey(resolvedHotkey, mergedOptions.platform ?? detectPlatform());
|
|
97
91
|
const { target: _t, ...optionsWithoutTarget } = mergedOptions;
|
|
98
92
|
if (registration?.isActive && lastHotkeyStr === hotkeyStr) {
|
|
99
93
|
registration.callback = callback;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { detectPlatform,
|
|
1
|
+
import { detectPlatform, getHotkeyManager, normalizeRegisterableHotkey, } from '@tanstack/hotkeys';
|
|
2
2
|
import { onDestroy } from 'svelte';
|
|
3
3
|
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
|
4
4
|
import { getDefaultHotkeysOptions } from './HotkeysCtx';
|
|
5
5
|
import { resolveMaybeGetter } from './internal.svelte';
|
|
6
|
-
function normalizeHotkey(hotkey, options) {
|
|
7
|
-
const platform = options.platform ?? detectPlatform();
|
|
8
|
-
return typeof hotkey === 'string'
|
|
9
|
-
? hotkey
|
|
10
|
-
: formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform));
|
|
11
|
-
}
|
|
12
6
|
function cleanupRegistrations(registrations) {
|
|
13
7
|
for (const { handle } of registrations.values()) {
|
|
14
8
|
if (handle.isActive) {
|
|
@@ -62,7 +56,7 @@ export function createHotkeys(hotkeys, commonOptions = {}) {
|
|
|
62
56
|
if (!resolvedTarget) {
|
|
63
57
|
continue;
|
|
64
58
|
}
|
|
65
|
-
const hotkeyString =
|
|
59
|
+
const hotkeyString = normalizeRegisterableHotkey(resolvedHotkey, mergedOptions.platform ?? detectPlatform());
|
|
66
60
|
const registrationKey = `${i}:${hotkeyString}`;
|
|
67
61
|
nextKeys.add(registrationKey);
|
|
68
62
|
prepared.push({
|
|
@@ -144,7 +138,7 @@ export function createHotkeysAttachment(hotkeys, commonOptions = {}) {
|
|
|
144
138
|
...resolvedCommonOptions,
|
|
145
139
|
...resolvedDefOptions,
|
|
146
140
|
};
|
|
147
|
-
const hotkeyString =
|
|
141
|
+
const hotkeyString = normalizeRegisterableHotkey(resolvedHotkey, mergedOptions.platform ?? detectPlatform());
|
|
148
142
|
const registrationKey = `${i}:${hotkeyString}`;
|
|
149
143
|
nextKeys.add(registrationKey);
|
|
150
144
|
prepared.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Svelte adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Kunal Rao",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"src"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tanstack/hotkeys": "0.
|
|
43
|
+
"@tanstack/hotkeys": "0.6.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@sveltejs/package": "^2.5.7",
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
detectPlatform,
|
|
3
|
-
formatHotkey,
|
|
4
3
|
getHotkeyManager,
|
|
5
|
-
|
|
4
|
+
normalizeRegisterableHotkey,
|
|
6
5
|
} from '@tanstack/hotkeys'
|
|
7
6
|
import { onDestroy } from 'svelte'
|
|
8
7
|
import { getDefaultHotkeysOptions } from './HotkeysCtx'
|
|
@@ -21,17 +20,6 @@ export interface CreateHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
|
21
20
|
target?: Document | Window // not html elements, use attachment instead
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
function normalizeHotkey(
|
|
25
|
-
hotkey: RegisterableHotkey,
|
|
26
|
-
options: CreateHotkeyOptions,
|
|
27
|
-
): Hotkey {
|
|
28
|
-
const platform = options.platform ?? detectPlatform()
|
|
29
|
-
|
|
30
|
-
return typeof hotkey === 'string'
|
|
31
|
-
? hotkey
|
|
32
|
-
: (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
23
|
function registerHotkey(
|
|
36
24
|
target: HTMLElement | Document | Window,
|
|
37
25
|
hotkey: RegisterableHotkey,
|
|
@@ -39,7 +27,10 @@ function registerHotkey(
|
|
|
39
27
|
mergedOptions: CreateHotkeyOptions,
|
|
40
28
|
) {
|
|
41
29
|
return getHotkeyManager().register(
|
|
42
|
-
|
|
30
|
+
normalizeRegisterableHotkey(
|
|
31
|
+
hotkey,
|
|
32
|
+
mergedOptions.platform ?? detectPlatform(),
|
|
33
|
+
),
|
|
43
34
|
callback,
|
|
44
35
|
{
|
|
45
36
|
...mergedOptions,
|
|
@@ -82,7 +73,10 @@ export function createHotkey(
|
|
|
82
73
|
...resolvedOptions,
|
|
83
74
|
} as CreateHotkeyOptions
|
|
84
75
|
|
|
85
|
-
const hotkeyStr =
|
|
76
|
+
const hotkeyStr = normalizeRegisterableHotkey(
|
|
77
|
+
resolvedHotkey,
|
|
78
|
+
mergedOptions.platform ?? detectPlatform(),
|
|
79
|
+
)
|
|
86
80
|
const { target: _t, ...optionsWithoutTarget } = mergedOptions
|
|
87
81
|
|
|
88
82
|
if (registration?.isActive && lastHotkeyStr === hotkeyStr) {
|
|
@@ -150,7 +144,10 @@ export function createHotkeyAttachment(
|
|
|
150
144
|
...resolvedOptions,
|
|
151
145
|
} as CreateHotkeyOptions
|
|
152
146
|
|
|
153
|
-
const hotkeyStr =
|
|
147
|
+
const hotkeyStr = normalizeRegisterableHotkey(
|
|
148
|
+
resolvedHotkey,
|
|
149
|
+
mergedOptions.platform ?? detectPlatform(),
|
|
150
|
+
)
|
|
154
151
|
const { target: _t, ...optionsWithoutTarget } = mergedOptions
|
|
155
152
|
|
|
156
153
|
if (registration?.isActive && lastHotkeyStr === hotkeyStr) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
detectPlatform,
|
|
3
|
-
formatHotkey,
|
|
4
3
|
getHotkeyManager,
|
|
5
|
-
|
|
4
|
+
normalizeRegisterableHotkey,
|
|
6
5
|
} from '@tanstack/hotkeys'
|
|
7
6
|
import { onDestroy } from 'svelte'
|
|
8
7
|
import { SvelteMap, SvelteSet } from 'svelte/reactivity'
|
|
@@ -30,16 +29,6 @@ export interface CreateHotkeyDefinition {
|
|
|
30
29
|
options?: MaybeGetter<CreateHotkeyOptions>
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
function normalizeHotkey(
|
|
34
|
-
hotkey: RegisterableHotkey,
|
|
35
|
-
options: CreateHotkeyOptions,
|
|
36
|
-
): Hotkey {
|
|
37
|
-
const platform = options.platform ?? detectPlatform()
|
|
38
|
-
return typeof hotkey === 'string'
|
|
39
|
-
? hotkey
|
|
40
|
-
: (formatHotkey(rawHotkeyToParsedHotkey(hotkey, platform)) as Hotkey)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
32
|
type RegistrationRecord = {
|
|
44
33
|
handle: HotkeyRegistrationHandle
|
|
45
34
|
target: Document | HTMLElement | Window
|
|
@@ -121,7 +110,10 @@ export function createHotkeys(
|
|
|
121
110
|
continue
|
|
122
111
|
}
|
|
123
112
|
|
|
124
|
-
const hotkeyString =
|
|
113
|
+
const hotkeyString = normalizeRegisterableHotkey(
|
|
114
|
+
resolvedHotkey,
|
|
115
|
+
mergedOptions.platform ?? detectPlatform(),
|
|
116
|
+
)
|
|
125
117
|
const registrationKey = `${i}:${hotkeyString}`
|
|
126
118
|
nextKeys.add(registrationKey)
|
|
127
119
|
prepared.push({
|
|
@@ -225,7 +217,10 @@ export function createHotkeysAttachment(
|
|
|
225
217
|
...resolvedDefOptions,
|
|
226
218
|
} as CreateHotkeyOptions
|
|
227
219
|
|
|
228
|
-
const hotkeyString =
|
|
220
|
+
const hotkeyString = normalizeRegisterableHotkey(
|
|
221
|
+
resolvedHotkey,
|
|
222
|
+
mergedOptions.platform ?? detectPlatform(),
|
|
223
|
+
)
|
|
229
224
|
const registrationKey = `${i}:${hotkeyString}`
|
|
230
225
|
nextKeys.add(registrationKey)
|
|
231
226
|
prepared.push({
|