@tanstack/svelte-hotkeys 0.8.4 → 0.9.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.
@@ -0,0 +1,26 @@
1
+ import type { HotkeyRegistrationView, SequenceRegistrationView } from '@tanstack/hotkeys';
2
+ export interface SvelteHotkeyRegistrations {
3
+ readonly hotkeys: Array<HotkeyRegistrationView>;
4
+ readonly sequences: Array<SequenceRegistrationView>;
5
+ }
6
+ /**
7
+ * Svelte function that returns reactive access to all hotkey and sequence
8
+ * registrations from the singleton managers.
9
+ *
10
+ * This is a standalone function that does NOT require the HotkeysProvider.
11
+ *
12
+ * @returns Object with reactive `hotkeys` and `sequences` properties
13
+ *
14
+ * @example
15
+ * ```svelte
16
+ * <script>
17
+ * import { getHotkeyRegistrations } from '@tanstack/svelte-hotkeys'
18
+ *
19
+ * const registrations = getHotkeyRegistrations()
20
+ * </script>
21
+ * {#each registrations.hotkeys as reg}
22
+ * <div>{reg.options.meta?.name} — {reg.triggerCount} triggers</div>
23
+ * {/each}
24
+ * ```
25
+ */
26
+ export declare function getHotkeyRegistrations(): SvelteHotkeyRegistrations;
@@ -0,0 +1,48 @@
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
+ import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView, } from '@tanstack/hotkeys';
8
+ import { createStoreSubscriber } from './internal.svelte';
9
+ 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
+ }
16
+ get hotkeys() {
17
+ __classPrivateFieldGet(this, _HotkeyRegistrationsState_subscribeHotkeys, "f").call(this);
18
+ return Array.from(__classPrivateFieldGet(this, _HotkeyRegistrationsState_hotkeyManager, "f").registrations.state.values()).map(toHotkeyRegistrationView);
19
+ }
20
+ get sequences() {
21
+ __classPrivateFieldGet(this, _HotkeyRegistrationsState_subscribeSequences, "f").call(this);
22
+ return Array.from(__classPrivateFieldGet(this, _HotkeyRegistrationsState_sequenceManager, "f").registrations.state.values());
23
+ }
24
+ }
25
+ _HotkeyRegistrationsState_hotkeyManager = new WeakMap(), _HotkeyRegistrationsState_sequenceManager = new WeakMap(), _HotkeyRegistrationsState_subscribeHotkeys = new WeakMap(), _HotkeyRegistrationsState_subscribeSequences = new WeakMap();
26
+ /**
27
+ * Svelte function that returns reactive access to all hotkey and sequence
28
+ * registrations from the singleton managers.
29
+ *
30
+ * This is a standalone function that does NOT require the HotkeysProvider.
31
+ *
32
+ * @returns Object with reactive `hotkeys` and `sequences` properties
33
+ *
34
+ * @example
35
+ * ```svelte
36
+ * <script>
37
+ * import { getHotkeyRegistrations } from '@tanstack/svelte-hotkeys'
38
+ *
39
+ * const registrations = getHotkeyRegistrations()
40
+ * </script>
41
+ * {#each registrations.hotkeys as reg}
42
+ * <div>{reg.options.meta?.name} — {reg.triggerCount} triggers</div>
43
+ * {/each}
44
+ * ```
45
+ */
46
+ export function getHotkeyRegistrations() {
47
+ return new HotkeyRegistrationsState();
48
+ }
@@ -1,4 +1,4 @@
1
- import type { HeldKey } from '@tanstack/hotkeys';
1
+ import type { IndividualKey } from '@tanstack/hotkeys';
2
2
  export interface SvelteHeldKeyState {
3
3
  readonly held: boolean;
4
4
  }
@@ -41,4 +41,4 @@ export interface SvelteHeldKeyState {
41
41
  * </div>
42
42
  * ```
43
43
  */
44
- export declare function getIsKeyHeld(key: HeldKey): SvelteHeldKeyState;
44
+ export declare function getIsKeyHeld(key: IndividualKey): SvelteHeldKeyState;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './createHotkeySequences.svelte';
6
6
  export * from './createHotkeyRecorder.svelte';
7
7
  export * from './createHotkeySequenceRecorder.svelte';
8
8
  export * from './getHeldKeys.svelte';
9
+ export * from './getHotkeyRegistrations.svelte';
9
10
  export * from './getHeldKeyCodesMap.svelte';
10
11
  export * from './getIsKeyHeld.svelte';
11
12
  export { default as HotkeysProvider } from './HotkeysProvider.svelte';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './createHotkeySequences.svelte';
7
7
  export * from './createHotkeyRecorder.svelte';
8
8
  export * from './createHotkeySequenceRecorder.svelte';
9
9
  export * from './getHeldKeys.svelte';
10
+ export * from './getHotkeyRegistrations.svelte';
10
11
  export * from './getHeldKeyCodesMap.svelte';
11
12
  export * from './getIsKeyHeld.svelte';
12
13
  export { default as HotkeysProvider } from './HotkeysProvider.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-hotkeys",
3
- "version": "0.8.4",
3
+ "version": "0.9.1",
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.6.4"
43
+ "@tanstack/hotkeys": "0.7.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@sveltejs/package": "^2.5.7",
@@ -0,0 +1,60 @@
1
+ import {
2
+ getHotkeyManager,
3
+ getSequenceManager,
4
+ toHotkeyRegistrationView,
5
+ } from '@tanstack/hotkeys'
6
+ import { createStoreSubscriber } from './internal.svelte'
7
+ import type {
8
+ HotkeyRegistrationView,
9
+ SequenceRegistrationView,
10
+ } from '@tanstack/hotkeys'
11
+
12
+ export interface SvelteHotkeyRegistrations {
13
+ readonly hotkeys: Array<HotkeyRegistrationView>
14
+ readonly sequences: Array<SequenceRegistrationView>
15
+ }
16
+
17
+ class HotkeyRegistrationsState implements SvelteHotkeyRegistrations {
18
+ #hotkeyManager = getHotkeyManager()
19
+ #sequenceManager = getSequenceManager()
20
+ #subscribeHotkeys = createStoreSubscriber(this.#hotkeyManager.registrations)
21
+ #subscribeSequences = createStoreSubscriber(
22
+ this.#sequenceManager.registrations,
23
+ )
24
+
25
+ get hotkeys(): Array<HotkeyRegistrationView> {
26
+ this.#subscribeHotkeys()
27
+ return Array.from(this.#hotkeyManager.registrations.state.values()).map(
28
+ toHotkeyRegistrationView,
29
+ )
30
+ }
31
+
32
+ get sequences(): Array<SequenceRegistrationView> {
33
+ this.#subscribeSequences()
34
+ return Array.from(this.#sequenceManager.registrations.state.values())
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Svelte function that returns reactive access to all hotkey and sequence
40
+ * registrations from the singleton managers.
41
+ *
42
+ * This is a standalone function that does NOT require the HotkeysProvider.
43
+ *
44
+ * @returns Object with reactive `hotkeys` and `sequences` properties
45
+ *
46
+ * @example
47
+ * ```svelte
48
+ * <script>
49
+ * import { getHotkeyRegistrations } from '@tanstack/svelte-hotkeys'
50
+ *
51
+ * const registrations = getHotkeyRegistrations()
52
+ * </script>
53
+ * {#each registrations.hotkeys as reg}
54
+ * <div>{reg.options.meta?.name} — {reg.triggerCount} triggers</div>
55
+ * {/each}
56
+ * ```
57
+ */
58
+ export function getHotkeyRegistrations(): SvelteHotkeyRegistrations {
59
+ return new HotkeyRegistrationsState()
60
+ }
@@ -1,6 +1,6 @@
1
1
  import { getKeyStateTracker } from '@tanstack/hotkeys'
2
2
  import { createStoreSubscriber } from './internal.svelte'
3
- import type { HeldKey } from '@tanstack/hotkeys'
3
+ import type { IndividualKey } from '@tanstack/hotkeys'
4
4
 
5
5
  export interface SvelteHeldKeyState {
6
6
  readonly held: boolean
@@ -11,7 +11,7 @@ class HeldKeyState implements SvelteHeldKeyState {
11
11
  #normalizedKey: string
12
12
  #subscribe = createStoreSubscriber(this.#tracker.store)
13
13
 
14
- constructor(key: HeldKey) {
14
+ constructor(key: IndividualKey) {
15
15
  this.#normalizedKey = key.toLowerCase()
16
16
  }
17
17
 
@@ -63,6 +63,6 @@ class HeldKeyState implements SvelteHeldKeyState {
63
63
  * ```
64
64
  */
65
65
 
66
- export function getIsKeyHeld(key: HeldKey): SvelteHeldKeyState {
66
+ export function getIsKeyHeld(key: IndividualKey): SvelteHeldKeyState {
67
67
  return new HeldKeyState(key)
68
68
  }
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from './createHotkeySequences.svelte'
8
8
  export * from './createHotkeyRecorder.svelte'
9
9
  export * from './createHotkeySequenceRecorder.svelte'
10
10
  export * from './getHeldKeys.svelte'
11
+ export * from './getHotkeyRegistrations.svelte'
11
12
  export * from './getHeldKeyCodesMap.svelte'
12
13
  export * from './getIsKeyHeld.svelte'
13
14
  export { default as HotkeysProvider } from './HotkeysProvider.svelte'