@tanstack/svelte-hotkeys 0.10.0 → 0.12.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  <div align="center">
2
- <img src="./media/header_hotkeys.png" alt="TanStack Hotkeys" />
2
+ <picture>
3
+ <source
4
+ media="(prefers-color-scheme: dark)"
5
+ srcset="https://tanstack.com/api/readme/hotkeys.png?theme=dark"
6
+ />
7
+ <source
8
+ media="(prefers-color-scheme: light)"
9
+ srcset="https://tanstack.com/api/readme/hotkeys.png"
10
+ />
11
+ <img
12
+ src="https://tanstack.com/api/readme/hotkeys.png"
13
+ alt="TanStack Hotkeys"
14
+ width="900"
15
+ />
16
+ </picture>
3
17
  </div>
4
18
 
5
19
  <br />
@@ -1,15 +1,3 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _SvelteHotkeyRecorderState_recorder, _SvelteHotkeyRecorderState_subscribe;
13
1
  import { HotkeyRecorder } from '@tanstack/hotkeys';
14
2
  import { onDestroy } from 'svelte';
15
3
  import { getDefaultHotkeysOptions } from './HotkeysCtx';
@@ -51,37 +39,39 @@ import { createStoreSubscriber, resolveMaybeGetter } from './internal.svelte';
51
39
  * ```
52
40
  */
53
41
  class SvelteHotkeyRecorderState {
42
+ #recorder;
43
+ #subscribe;
54
44
  constructor(options) {
55
- _SvelteHotkeyRecorderState_recorder.set(this, void 0);
56
- _SvelteHotkeyRecorderState_subscribe.set(this, void 0);
57
- __classPrivateFieldSet(this, _SvelteHotkeyRecorderState_recorder, new HotkeyRecorder(options), "f");
58
- __classPrivateFieldSet(this, _SvelteHotkeyRecorderState_subscribe, createStoreSubscriber(__classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").store), "f");
45
+ this.#recorder = new HotkeyRecorder(options);
46
+ this.#subscribe = createStoreSubscriber(this.#recorder.store);
59
47
  }
60
48
  get isRecording() {
61
- __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_subscribe, "f").call(this);
62
- return __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").store.state.isRecording;
49
+ this.#subscribe();
50
+ return this.#recorder.store.state.isRecording;
63
51
  }
64
52
  get recordedHotkey() {
65
- __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_subscribe, "f").call(this);
66
- return __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").store.state.recordedHotkey;
53
+ this.#subscribe();
54
+ return this.#recorder.store.state.recordedHotkey;
67
55
  }
68
56
  setOptions(options) {
69
- __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").setOptions(options);
70
- }
71
- startRecording() {
72
- __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").start();
73
- }
74
- stopRecording() {
75
- __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").stop();
76
- }
77
- cancelRecording() {
78
- __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").cancel();
57
+ this.#recorder.setOptions(options);
79
58
  }
59
+ // Keep the recorder receiver when used directly as an event handler.
60
+ startRecording = () => {
61
+ this.#recorder.start();
62
+ };
63
+ // Keep the recorder receiver when used directly as an event handler.
64
+ stopRecording = () => {
65
+ this.#recorder.stop();
66
+ };
67
+ // Keep the recorder receiver when used directly as an event handler.
68
+ cancelRecording = () => {
69
+ this.#recorder.cancel();
70
+ };
80
71
  destroy() {
81
- __classPrivateFieldGet(this, _SvelteHotkeyRecorderState_recorder, "f").destroy();
72
+ this.#recorder.destroy();
82
73
  }
83
74
  }
84
- _SvelteHotkeyRecorderState_recorder = new WeakMap(), _SvelteHotkeyRecorderState_subscribe = new WeakMap();
85
75
  export function createHotkeyRecorder(options) {
86
76
  const recorder = new SvelteHotkeyRecorderState({
87
77
  ...getDefaultHotkeysOptions().hotkeyRecorder,
@@ -1,58 +1,49 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _SvelteHotkeySequenceRecorderState_recorder, _SvelteHotkeySequenceRecorderState_subscribe;
13
1
  import { HotkeySequenceRecorder } from '@tanstack/hotkeys';
14
2
  import { onDestroy } from 'svelte';
15
3
  import { getDefaultHotkeysOptions } from './HotkeysCtx';
16
4
  import { createStoreSubscriber, resolveMaybeGetter } from './internal.svelte';
17
5
  class SvelteHotkeySequenceRecorderState {
6
+ #recorder;
7
+ #subscribe;
18
8
  constructor(options) {
19
- _SvelteHotkeySequenceRecorderState_recorder.set(this, void 0);
20
- _SvelteHotkeySequenceRecorderState_subscribe.set(this, void 0);
21
- __classPrivateFieldSet(this, _SvelteHotkeySequenceRecorderState_recorder, new HotkeySequenceRecorder(options), "f");
22
- __classPrivateFieldSet(this, _SvelteHotkeySequenceRecorderState_subscribe, createStoreSubscriber(__classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").store), "f");
9
+ this.#recorder = new HotkeySequenceRecorder(options);
10
+ this.#subscribe = createStoreSubscriber(this.#recorder.store);
23
11
  }
24
12
  get isRecording() {
25
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_subscribe, "f").call(this);
26
- return __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").store.state.isRecording;
13
+ this.#subscribe();
14
+ return this.#recorder.store.state.isRecording;
27
15
  }
28
16
  get steps() {
29
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_subscribe, "f").call(this);
30
- return __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").store.state.steps;
17
+ this.#subscribe();
18
+ return this.#recorder.store.state.steps;
31
19
  }
32
20
  get recordedSequence() {
33
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_subscribe, "f").call(this);
34
- return __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").store.state.recordedSequence;
21
+ this.#subscribe();
22
+ return this.#recorder.store.state.recordedSequence;
35
23
  }
36
24
  setOptions(options) {
37
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").setOptions(options);
38
- }
39
- startRecording() {
40
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").start();
41
- }
42
- stopRecording() {
43
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").stop();
44
- }
45
- cancelRecording() {
46
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").cancel();
47
- }
48
- commitRecording() {
49
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").commit();
25
+ this.#recorder.setOptions(options);
50
26
  }
27
+ // Keep the recorder receiver when used directly as an event handler.
28
+ startRecording = () => {
29
+ this.#recorder.start();
30
+ };
31
+ // Keep the recorder receiver when used directly as an event handler.
32
+ stopRecording = () => {
33
+ this.#recorder.stop();
34
+ };
35
+ // Keep the recorder receiver when used directly as an event handler.
36
+ cancelRecording = () => {
37
+ this.#recorder.cancel();
38
+ };
39
+ // Keep the recorder receiver when used directly as an event handler.
40
+ commitRecording = () => {
41
+ this.#recorder.commit();
42
+ };
51
43
  destroy() {
52
- __classPrivateFieldGet(this, _SvelteHotkeySequenceRecorderState_recorder, "f").destroy();
44
+ this.#recorder.destroy();
53
45
  }
54
46
  }
55
- _SvelteHotkeySequenceRecorderState_recorder = new WeakMap(), _SvelteHotkeySequenceRecorderState_subscribe = new WeakMap();
56
47
  /**
57
48
  * Svelte helper for recording multi-chord sequences (Vim-style shortcuts).
58
49
  */
@@ -1,22 +1,13 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _HeldKeyCodesMapState_tracker, _HeldKeyCodesMapState_subscribe;
7
1
  import { getKeyStateTracker } from '@tanstack/hotkeys';
8
2
  import { createStoreSubscriber } from './internal.svelte';
9
3
  class HeldKeyCodesMapState {
10
- constructor() {
11
- _HeldKeyCodesMapState_tracker.set(this, getKeyStateTracker());
12
- _HeldKeyCodesMapState_subscribe.set(this, createStoreSubscriber(__classPrivateFieldGet(this, _HeldKeyCodesMapState_tracker, "f").store));
13
- }
4
+ #tracker = getKeyStateTracker();
5
+ #subscribe = createStoreSubscriber(this.#tracker.store);
14
6
  get codes() {
15
- __classPrivateFieldGet(this, _HeldKeyCodesMapState_subscribe, "f").call(this);
16
- return __classPrivateFieldGet(this, _HeldKeyCodesMapState_tracker, "f").store.state.heldCodes;
7
+ this.#subscribe();
8
+ return this.#tracker.store.state.heldCodes;
17
9
  }
18
10
  }
19
- _HeldKeyCodesMapState_tracker = new WeakMap(), _HeldKeyCodesMapState_subscribe = new WeakMap();
20
11
  /**
21
12
  * Svelte function that returns reactive access to the map of currently held key names
22
13
  * to their physical `event.code` values.
@@ -1,22 +1,13 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _HeldKeysState_tracker, _HeldKeysState_subscribe;
7
1
  import { getKeyStateTracker } from '@tanstack/hotkeys';
8
2
  import { createStoreSubscriber } from './internal.svelte';
9
3
  class HeldKeysState {
10
- constructor() {
11
- _HeldKeysState_tracker.set(this, getKeyStateTracker());
12
- _HeldKeysState_subscribe.set(this, createStoreSubscriber(__classPrivateFieldGet(this, _HeldKeysState_tracker, "f").store));
13
- }
4
+ #tracker = getKeyStateTracker();
5
+ #subscribe = createStoreSubscriber(this.#tracker.store);
14
6
  get keys() {
15
- __classPrivateFieldGet(this, _HeldKeysState_subscribe, "f").call(this);
16
- return __classPrivateFieldGet(this, _HeldKeysState_tracker, "f").store.state.heldKeys;
7
+ this.#subscribe();
8
+ return this.#tracker.store.state.heldKeys;
17
9
  }
18
10
  }
19
- _HeldKeysState_tracker = new WeakMap(), _HeldKeysState_subscribe = new WeakMap();
20
11
  /**
21
12
  * Svelte function that returns reactive access to currently held keyboard keys.
22
13
  *
@@ -0,0 +1,13 @@
1
+ import type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys';
2
+ import type { MaybeGetter } from './internal.svelte';
3
+ export interface SvelteHotkeyHint {
4
+ readonly visible: boolean;
5
+ }
6
+ /**
7
+ * Returns an object with a reactive `visible` getter indicating whether held modifiers reveal this shortcut.
8
+ * Pass getters to track changing bindings and options.
9
+ * Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
10
+ * every modifier. Combine with the action's enabled state before showing a badge.
11
+ * This helper does not register a shortcut or check whether its target is focused.
12
+ */
13
+ export declare function getHotkeyHint(hotkey: MaybeGetter<RegisterableHotkey>, options?: MaybeGetter<HeldModifierOptions>): SvelteHotkeyHint;
@@ -0,0 +1,36 @@
1
+ import { createSubscriber } from 'svelte/reactivity';
2
+ import { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys';
3
+ import { resolveMaybeGetter } from './internal.svelte';
4
+ /**
5
+ * Returns an object with a reactive `visible` getter indicating whether held modifiers reveal this shortcut.
6
+ * Pass getters to track changing bindings and options.
7
+ * Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
8
+ * every modifier. Combine with the action's enabled state before showing a badge.
9
+ * This helper does not register a shortcut or check whether its target is focused.
10
+ */
11
+ export function getHotkeyHint(hotkey, options = {}) {
12
+ const tracker = getKeyStateTracker();
13
+ // Resolve current reactive arguments without caching a stale binding.
14
+ const read = () => matchesHeldModifiers(resolveMaybeGetter(hotkey), tracker.store.state.heldKeys, resolveMaybeGetter(options));
15
+ let previous = false;
16
+ // Notify Svelte only when visibility changes, not for every unrelated held key.
17
+ const subscribe = createSubscriber((update) => {
18
+ previous = read();
19
+ const subscription = tracker.store.subscribe(() => {
20
+ const next = read();
21
+ if (next !== previous) {
22
+ previous = next;
23
+ update();
24
+ }
25
+ });
26
+ return () => subscription.unsubscribe();
27
+ });
28
+ return {
29
+ /** Reads visibility and subscribes the current reactive consumer when needed. */
30
+ get visible() {
31
+ subscribe();
32
+ previous = read();
33
+ return previous;
34
+ },
35
+ };
36
+ }
@@ -1,28 +1,19 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _HotkeyRegistrationsState_hotkeyManager, _HotkeyRegistrationsState_sequenceManager, _HotkeyRegistrationsState_subscribeHotkeys, _HotkeyRegistrationsState_subscribeSequences;
7
1
  import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView, } from '@tanstack/hotkeys';
8
2
  import { createStoreSubscriber } from './internal.svelte';
9
3
  class HotkeyRegistrationsState {
10
- constructor() {
11
- _HotkeyRegistrationsState_hotkeyManager.set(this, getHotkeyManager());
12
- _HotkeyRegistrationsState_sequenceManager.set(this, getSequenceManager());
13
- _HotkeyRegistrationsState_subscribeHotkeys.set(this, createStoreSubscriber(__classPrivateFieldGet(this, _HotkeyRegistrationsState_hotkeyManager, "f").registrations));
14
- _HotkeyRegistrationsState_subscribeSequences.set(this, createStoreSubscriber(__classPrivateFieldGet(this, _HotkeyRegistrationsState_sequenceManager, "f").registrations));
15
- }
4
+ #hotkeyManager = getHotkeyManager();
5
+ #sequenceManager = getSequenceManager();
6
+ #subscribeHotkeys = createStoreSubscriber(this.#hotkeyManager.registrations);
7
+ #subscribeSequences = createStoreSubscriber(this.#sequenceManager.registrations);
16
8
  get hotkeys() {
17
- __classPrivateFieldGet(this, _HotkeyRegistrationsState_subscribeHotkeys, "f").call(this);
18
- return Array.from(__classPrivateFieldGet(this, _HotkeyRegistrationsState_hotkeyManager, "f").registrations.state.values()).map(toHotkeyRegistrationView);
9
+ this.#subscribeHotkeys();
10
+ return Array.from(this.#hotkeyManager.registrations.state.values()).map(toHotkeyRegistrationView);
19
11
  }
20
12
  get sequences() {
21
- __classPrivateFieldGet(this, _HotkeyRegistrationsState_subscribeSequences, "f").call(this);
22
- return Array.from(__classPrivateFieldGet(this, _HotkeyRegistrationsState_sequenceManager, "f").registrations.state.values());
13
+ this.#subscribeSequences();
14
+ return Array.from(this.#sequenceManager.registrations.state.values());
23
15
  }
24
16
  }
25
- _HotkeyRegistrationsState_hotkeyManager = new WeakMap(), _HotkeyRegistrationsState_sequenceManager = new WeakMap(), _HotkeyRegistrationsState_subscribeHotkeys = new WeakMap(), _HotkeyRegistrationsState_subscribeSequences = new WeakMap();
26
17
  /**
27
18
  * Svelte function that returns reactive access to all hotkey and sequence
28
19
  * registrations from the singleton managers.
@@ -1,30 +1,17 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _HeldKeyState_tracker, _HeldKeyState_normalizedKey, _HeldKeyState_subscribe;
13
1
  import { getKeyStateTracker } from '@tanstack/hotkeys';
14
2
  import { createStoreSubscriber } from './internal.svelte';
15
3
  class HeldKeyState {
4
+ #tracker = getKeyStateTracker();
5
+ #normalizedKey;
6
+ #subscribe = createStoreSubscriber(this.#tracker.store);
16
7
  constructor(key) {
17
- _HeldKeyState_tracker.set(this, getKeyStateTracker());
18
- _HeldKeyState_normalizedKey.set(this, void 0);
19
- _HeldKeyState_subscribe.set(this, createStoreSubscriber(__classPrivateFieldGet(this, _HeldKeyState_tracker, "f").store));
20
- __classPrivateFieldSet(this, _HeldKeyState_normalizedKey, key.toLowerCase(), "f");
8
+ this.#normalizedKey = key.toLowerCase();
21
9
  }
22
10
  get held() {
23
- __classPrivateFieldGet(this, _HeldKeyState_subscribe, "f").call(this);
24
- return __classPrivateFieldGet(this, _HeldKeyState_tracker, "f").store.state.heldKeys.some((heldKey) => heldKey.toLowerCase() === __classPrivateFieldGet(this, _HeldKeyState_normalizedKey, "f"));
11
+ this.#subscribe();
12
+ return this.#tracker.store.state.heldKeys.some((heldKey) => heldKey.toLowerCase() === this.#normalizedKey);
25
13
  }
26
14
  }
27
- _HeldKeyState_tracker = new WeakMap(), _HeldKeyState_normalizedKey = new WeakMap(), _HeldKeyState_subscribe = new WeakMap();
28
15
  /**
29
16
  * Svelte function that returns reactive access to whether a specific key is currently being held.
30
17
  *
package/dist/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export * from './getIsKeyHeld.svelte';
12
12
  export { default as HotkeysProvider } from './HotkeysProvider.svelte';
13
13
  export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkeysContext, } from './HotkeysCtx';
14
14
  export type { HotkeysProviderOptions, HotkeysProviderProps } from './HotkeysCtx';
15
+ export * from './getHotkeyHint.svelte';
package/dist/index.js CHANGED
@@ -12,3 +12,4 @@ export * from './getHeldKeyCodesMap.svelte';
12
12
  export * from './getIsKeyHeld.svelte';
13
13
  export { default as HotkeysProvider } from './HotkeysProvider.svelte';
14
14
  export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkeysContext, } from './HotkeysCtx';
15
+ export * from './getHotkeyHint.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-hotkeys",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Svelte adapter for TanStack Hotkeys",
5
5
  "author": "Kunal Rao",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "shortcuts"
24
24
  ],
25
25
  "type": "module",
26
- "types": "dist/index.d.ts",
26
+ "types": "./dist/index.d.ts",
27
27
  "module": "dist/index.js",
28
28
  "svelte": "./dist/index.js",
29
29
  "exports": {
@@ -36,29 +36,31 @@
36
36
  },
37
37
  "sideEffects": false,
38
38
  "files": [
39
- "dist",
40
- "src"
39
+ "dist"
41
40
  ],
42
41
  "dependencies": {
43
- "@tanstack/hotkeys": "0.8.0"
42
+ "@tanstack/hotkeys": "0.10.0"
44
43
  },
45
44
  "devDependencies": {
46
- "@sveltejs/package": "^2.5.7",
45
+ "@sveltejs/package": "^2.5.8",
47
46
  "@sveltejs/vite-plugin-svelte": "^7.0.0",
48
- "@typescript-eslint/parser": "^8.59.0",
49
- "eslint-plugin-svelte": "^3.17.1",
50
- "svelte": "^5.55.4"
47
+ "@typescript-eslint/parser": "^8.70.1",
48
+ "eslint-plugin-svelte": "^3.23.0",
49
+ "svelte": "^5.57.1"
51
50
  },
52
51
  "peerDependencies": {
53
52
  "svelte": "^5.25.0"
54
53
  },
54
+ "engines": {
55
+ "node": ">=20"
56
+ },
55
57
  "scripts": {
56
58
  "clean": "premove ./dist ./coverage",
57
59
  "test:eslint": "eslint ./src",
58
60
  "test:lib": "vitest --passWithNoTests",
59
61
  "test:lib:dev": "pnpm test:lib --watch",
60
62
  "test:types": "tsc",
61
- "test:build": "publint --strict",
63
+ "test:build": "publint --strict && node ../../scripts/verify-package.ts",
62
64
  "build": "svelte-package --input ./src --output ./dist"
63
65
  }
64
66
  }
package/src/HotkeysCtx.ts DELETED
@@ -1,61 +0,0 @@
1
- import { createContext } from 'svelte'
2
- import type {
3
- HotkeyRecorderOptions,
4
- HotkeySequenceRecorderOptions,
5
- } from '@tanstack/hotkeys'
6
- import type { CreateHotkeyOptions } from './createHotkey.svelte'
7
- import type { Snippet } from 'svelte'
8
- import type { CreateHotkeySequenceOptions } from './createHotkeySequence.svelte'
9
-
10
- export interface HotkeysProviderOptions {
11
- hotkey?: Partial<CreateHotkeyOptions>
12
- hotkeyRecorder?: Partial<HotkeyRecorderOptions>
13
- hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>
14
- hotkeySequence?: Partial<CreateHotkeySequenceOptions>
15
- }
16
-
17
- export interface HotkeysProviderProps {
18
- children: Snippet
19
- defaultOptions?: HotkeysProviderOptions
20
- }
21
-
22
- export const DEFAULT_OPTIONS: HotkeysProviderOptions = {}
23
-
24
- interface HotkeysContextValue {
25
- defaultOptions: HotkeysProviderOptions
26
- }
27
-
28
- const [useHotkeysContext, setHotkeysContextValue] =
29
- createContext<HotkeysContextValue | null>()
30
-
31
- export function setHotkeysContext(
32
- defaultOptions: HotkeysProviderOptions = DEFAULT_OPTIONS,
33
- ): HotkeysContextValue {
34
- return setHotkeysContextValue({
35
- get defaultOptions() {
36
- return defaultOptions
37
- },
38
- })!
39
- }
40
-
41
- export function setHotkeysContextSource(
42
- defaultOptions: () => HotkeysProviderOptions,
43
- ): HotkeysContextValue {
44
- return setHotkeysContextValue({
45
- get defaultOptions() {
46
- return defaultOptions()
47
- },
48
- })!
49
- }
50
-
51
- export function getHotkeysContext(): HotkeysContextValue | null {
52
- try {
53
- return useHotkeysContext()
54
- } catch {
55
- return null
56
- }
57
- }
58
-
59
- export function getDefaultHotkeysOptions(): HotkeysProviderOptions {
60
- return getHotkeysContext()?.defaultOptions ?? DEFAULT_OPTIONS
61
- }
@@ -1,12 +0,0 @@
1
- <script lang="ts">
2
- import { DEFAULT_OPTIONS, setHotkeysContextSource } from './HotkeysCtx'
3
-
4
- import type { HotkeysProviderProps } from './HotkeysCtx'
5
-
6
- let { children, defaultOptions = DEFAULT_OPTIONS }: HotkeysProviderProps =
7
- $props()
8
-
9
- setHotkeysContextSource(() => defaultOptions)
10
- </script>
11
-
12
- {@render children()}