@tanstack/lit-hotkeys 0.11.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 />
@@ -0,0 +1,47 @@
1
+ let _tanstack_hotkeys = require("@tanstack/hotkeys");
2
+
3
+ //#region src/controllers/hotkey-hint.ts
4
+ /** Modifier hint controller. Getter arguments can read reactive host properties. */
5
+ var HotkeyHintController = class {
6
+ /** Attaches to the host; getter arguments can read changing reactive properties. */
7
+ constructor(host, hotkey, options = {}) {
8
+ this.host = host;
9
+ this.hotkey = hotkey;
10
+ this.options = options;
11
+ this.visible = false;
12
+ host.addController(this);
13
+ }
14
+ /** Current visibility; combine with the action’s enabled state when rendering. */
15
+ get value() {
16
+ return this.visible;
17
+ }
18
+ /** Subscribes on connection and requests renders only when hint visibility changes. */
19
+ hostConnected() {
20
+ this.update();
21
+ const subscription = (0, _tanstack_hotkeys.getKeyStateTracker)().store.subscribe(() => {
22
+ if (this.update()) this.host.requestUpdate();
23
+ });
24
+ this.unsubscribe = () => subscription.unsubscribe();
25
+ }
26
+ /** Re-evaluates getter arguments when host properties trigger an update. */
27
+ hostUpdate() {
28
+ this.update();
29
+ }
30
+ /** Releases the subscription and clears cached visibility while disconnected. */
31
+ hostDisconnected() {
32
+ this.unsubscribe?.();
33
+ this.unsubscribe = void 0;
34
+ this.visible = false;
35
+ }
36
+ /** Recomputes visibility and reports whether the host needs another render. */
37
+ update() {
38
+ const next = (0, _tanstack_hotkeys.matchesHeldModifiers)(typeof this.hotkey === "function" ? this.hotkey() : this.hotkey, (0, _tanstack_hotkeys.getKeyStateTracker)().store.state.heldKeys, typeof this.options === "function" ? this.options() : this.options);
39
+ const changed = next !== this.visible;
40
+ this.visible = next;
41
+ return changed;
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ exports.HotkeyHintController = HotkeyHintController;
47
+ //# sourceMappingURL=hotkey-hint.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hotkey-hint.cjs","names":[],"sources":["../../src/controllers/hotkey-hint.ts"],"sourcesContent":["import { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'\n\n/** Modifier hint controller. Getter arguments can read reactive host properties. */\nexport class HotkeyHintController implements ReactiveController {\n private unsubscribe?: () => void\n private visible = false\n\n /** Attaches to the host; getter arguments can read changing reactive properties. */\n constructor(\n private host: ReactiveControllerHost,\n private hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n private options: HeldModifierOptions | (() => HeldModifierOptions) = {},\n ) {\n host.addController(this)\n }\n\n /** Current visibility; combine with the action’s enabled state when rendering. */\n get value(): boolean {\n return this.visible\n }\n\n /** Subscribes on connection and requests renders only when hint visibility changes. */\n hostConnected(): void {\n this.update()\n const subscription = getKeyStateTracker().store.subscribe(() => {\n if (this.update()) this.host.requestUpdate()\n })\n this.unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Re-evaluates getter arguments when host properties trigger an update. */\n hostUpdate(): void {\n this.update()\n }\n\n /** Releases the subscription and clears cached visibility while disconnected. */\n hostDisconnected(): void {\n this.unsubscribe?.()\n this.unsubscribe = undefined\n this.visible = false\n }\n\n /** Recomputes visibility and reports whether the host needs another render. */\n private update(): boolean {\n const next = matchesHeldModifiers(\n typeof this.hotkey === 'function' ? this.hotkey() : this.hotkey,\n getKeyStateTracker().store.state.heldKeys,\n typeof this.options === 'function' ? this.options() : this.options,\n )\n const changed = next !== this.visible\n this.visible = next\n return changed\n }\n}\n"],"mappings":";;;;AAKA,IAAa,uBAAb,MAAgE;;CAK9D,YACE,AAAQ,MACR,AAAQ,QACR,AAAQ,UAA6D,EAAE,EACvE;EAHQ;EACA;EACA;iBANQ;AAQhB,OAAK,cAAc,KAAK;;;CAI1B,IAAI,QAAiB;AACnB,SAAO,KAAK;;;CAId,gBAAsB;AACpB,OAAK,QAAQ;EACb,MAAM,0DAAmC,CAAC,MAAM,gBAAgB;AAC9D,OAAI,KAAK,QAAQ,CAAE,MAAK,KAAK,eAAe;IAC5C;AACF,OAAK,oBAAoB,aAAa,aAAa;;;CAIrD,aAAmB;AACjB,OAAK,QAAQ;;;CAIf,mBAAyB;AACvB,OAAK,eAAe;AACpB,OAAK,cAAc;AACnB,OAAK,UAAU;;;CAIjB,AAAQ,SAAkB;EACxB,MAAM,mDACJ,OAAO,KAAK,WAAW,aAAa,KAAK,QAAQ,GAAG,KAAK,mDACrC,CAAC,MAAM,MAAM,UACjC,OAAO,KAAK,YAAY,aAAa,KAAK,SAAS,GAAG,KAAK,QAC5D;EACD,MAAM,UAAU,SAAS,KAAK;AAC9B,OAAK,UAAU;AACf,SAAO"}
@@ -0,0 +1,27 @@
1
+ import { HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
2
+ import { ReactiveController, ReactiveControllerHost } from "lit";
3
+
4
+ //#region src/controllers/hotkey-hint.d.ts
5
+ /** Modifier hint controller. Getter arguments can read reactive host properties. */
6
+ declare class HotkeyHintController implements ReactiveController {
7
+ private host;
8
+ private hotkey;
9
+ private options;
10
+ private unsubscribe?;
11
+ private visible;
12
+ /** Attaches to the host; getter arguments can read changing reactive properties. */
13
+ constructor(host: ReactiveControllerHost, hotkey: RegisterableHotkey | (() => RegisterableHotkey), options?: HeldModifierOptions | (() => HeldModifierOptions));
14
+ /** Current visibility; combine with the action’s enabled state when rendering. */
15
+ get value(): boolean;
16
+ /** Subscribes on connection and requests renders only when hint visibility changes. */
17
+ hostConnected(): void;
18
+ /** Re-evaluates getter arguments when host properties trigger an update. */
19
+ hostUpdate(): void;
20
+ /** Releases the subscription and clears cached visibility while disconnected. */
21
+ hostDisconnected(): void;
22
+ /** Recomputes visibility and reports whether the host needs another render. */
23
+ private update;
24
+ }
25
+ //#endregion
26
+ export { HotkeyHintController };
27
+ //# sourceMappingURL=hotkey-hint.d.cts.map
@@ -0,0 +1,27 @@
1
+ import { HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
2
+ import { ReactiveController, ReactiveControllerHost } from "lit";
3
+
4
+ //#region src/controllers/hotkey-hint.d.ts
5
+ /** Modifier hint controller. Getter arguments can read reactive host properties. */
6
+ declare class HotkeyHintController implements ReactiveController {
7
+ private host;
8
+ private hotkey;
9
+ private options;
10
+ private unsubscribe?;
11
+ private visible;
12
+ /** Attaches to the host; getter arguments can read changing reactive properties. */
13
+ constructor(host: ReactiveControllerHost, hotkey: RegisterableHotkey | (() => RegisterableHotkey), options?: HeldModifierOptions | (() => HeldModifierOptions));
14
+ /** Current visibility; combine with the action’s enabled state when rendering. */
15
+ get value(): boolean;
16
+ /** Subscribes on connection and requests renders only when hint visibility changes. */
17
+ hostConnected(): void;
18
+ /** Re-evaluates getter arguments when host properties trigger an update. */
19
+ hostUpdate(): void;
20
+ /** Releases the subscription and clears cached visibility while disconnected. */
21
+ hostDisconnected(): void;
22
+ /** Recomputes visibility and reports whether the host needs another render. */
23
+ private update;
24
+ }
25
+ //#endregion
26
+ export { HotkeyHintController };
27
+ //# sourceMappingURL=hotkey-hint.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { getKeyStateTracker, matchesHeldModifiers } from "@tanstack/hotkeys";
2
+
3
+ //#region src/controllers/hotkey-hint.ts
4
+ /** Modifier hint controller. Getter arguments can read reactive host properties. */
5
+ var HotkeyHintController = class {
6
+ /** Attaches to the host; getter arguments can read changing reactive properties. */
7
+ constructor(host, hotkey, options = {}) {
8
+ this.host = host;
9
+ this.hotkey = hotkey;
10
+ this.options = options;
11
+ this.visible = false;
12
+ host.addController(this);
13
+ }
14
+ /** Current visibility; combine with the action’s enabled state when rendering. */
15
+ get value() {
16
+ return this.visible;
17
+ }
18
+ /** Subscribes on connection and requests renders only when hint visibility changes. */
19
+ hostConnected() {
20
+ this.update();
21
+ const subscription = getKeyStateTracker().store.subscribe(() => {
22
+ if (this.update()) this.host.requestUpdate();
23
+ });
24
+ this.unsubscribe = () => subscription.unsubscribe();
25
+ }
26
+ /** Re-evaluates getter arguments when host properties trigger an update. */
27
+ hostUpdate() {
28
+ this.update();
29
+ }
30
+ /** Releases the subscription and clears cached visibility while disconnected. */
31
+ hostDisconnected() {
32
+ this.unsubscribe?.();
33
+ this.unsubscribe = void 0;
34
+ this.visible = false;
35
+ }
36
+ /** Recomputes visibility and reports whether the host needs another render. */
37
+ update() {
38
+ const next = matchesHeldModifiers(typeof this.hotkey === "function" ? this.hotkey() : this.hotkey, getKeyStateTracker().store.state.heldKeys, typeof this.options === "function" ? this.options() : this.options);
39
+ const changed = next !== this.visible;
40
+ this.visible = next;
41
+ return changed;
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ export { HotkeyHintController };
47
+ //# sourceMappingURL=hotkey-hint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hotkey-hint.js","names":[],"sources":["../../src/controllers/hotkey-hint.ts"],"sourcesContent":["import { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'\n\n/** Modifier hint controller. Getter arguments can read reactive host properties. */\nexport class HotkeyHintController implements ReactiveController {\n private unsubscribe?: () => void\n private visible = false\n\n /** Attaches to the host; getter arguments can read changing reactive properties. */\n constructor(\n private host: ReactiveControllerHost,\n private hotkey: RegisterableHotkey | (() => RegisterableHotkey),\n private options: HeldModifierOptions | (() => HeldModifierOptions) = {},\n ) {\n host.addController(this)\n }\n\n /** Current visibility; combine with the action’s enabled state when rendering. */\n get value(): boolean {\n return this.visible\n }\n\n /** Subscribes on connection and requests renders only when hint visibility changes. */\n hostConnected(): void {\n this.update()\n const subscription = getKeyStateTracker().store.subscribe(() => {\n if (this.update()) this.host.requestUpdate()\n })\n this.unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Re-evaluates getter arguments when host properties trigger an update. */\n hostUpdate(): void {\n this.update()\n }\n\n /** Releases the subscription and clears cached visibility while disconnected. */\n hostDisconnected(): void {\n this.unsubscribe?.()\n this.unsubscribe = undefined\n this.visible = false\n }\n\n /** Recomputes visibility and reports whether the host needs another render. */\n private update(): boolean {\n const next = matchesHeldModifiers(\n typeof this.hotkey === 'function' ? this.hotkey() : this.hotkey,\n getKeyStateTracker().store.state.heldKeys,\n typeof this.options === 'function' ? this.options() : this.options,\n )\n const changed = next !== this.visible\n this.visible = next\n return changed\n }\n}\n"],"mappings":";;;;AAKA,IAAa,uBAAb,MAAgE;;CAK9D,YACE,AAAQ,MACR,AAAQ,QACR,AAAQ,UAA6D,EAAE,EACvE;EAHQ;EACA;EACA;iBANQ;AAQhB,OAAK,cAAc,KAAK;;;CAI1B,IAAI,QAAiB;AACnB,SAAO,KAAK;;;CAId,gBAAsB;AACpB,OAAK,QAAQ;EACb,MAAM,eAAe,oBAAoB,CAAC,MAAM,gBAAgB;AAC9D,OAAI,KAAK,QAAQ,CAAE,MAAK,KAAK,eAAe;IAC5C;AACF,OAAK,oBAAoB,aAAa,aAAa;;;CAIrD,aAAmB;AACjB,OAAK,QAAQ;;;CAIf,mBAAyB;AACvB,OAAK,eAAe;AACpB,OAAK,cAAc;AACnB,OAAK,UAAU;;;CAIjB,AAAQ,SAAkB;EACxB,MAAM,OAAO,qBACX,OAAO,KAAK,WAAW,aAAa,KAAK,QAAQ,GAAG,KAAK,QACzD,oBAAoB,CAAC,MAAM,MAAM,UACjC,OAAO,KAAK,YAAY,aAAa,KAAK,SAAS,GAAG,KAAK,QAC5D;EACD,MAAM,UAAU,SAAS,KAAK;AAC9B,OAAK,UAAU;AACf,SAAO"}
@@ -5,4 +5,5 @@ import { HotkeyRecorderController } from "./hotkey-recorder.cjs";
5
5
  import { HotkeyRegistrationsController } from "./hotkey-registrations.cjs";
6
6
  import { HotkeySequenceController } from "./hotkey-sequence.cjs";
7
7
  import { HotkeySequenceRecorderController } from "./hotkey-sequence-recorder.cjs";
8
- import { KeyHoldController } from "./key-hold.cjs";
8
+ import { KeyHoldController } from "./key-hold.cjs";
9
+ import { HotkeyHintController } from "./hotkey-hint.cjs";
@@ -5,4 +5,5 @@ import { HotkeyRecorderController } from "./hotkey-recorder.js";
5
5
  import { HotkeyRegistrationsController } from "./hotkey-registrations.js";
6
6
  import { HotkeySequenceController } from "./hotkey-sequence.js";
7
7
  import { HotkeySequenceRecorderController } from "./hotkey-sequence-recorder.js";
8
- import { KeyHoldController } from "./key-hold.js";
8
+ import { KeyHoldController } from "./key-hold.js";
9
+ import { HotkeyHintController } from "./hotkey-hint.js";
package/dist/index.cjs CHANGED
@@ -9,10 +9,12 @@ const require_hotkey_recorder = require('./controllers/hotkey-recorder.cjs');
9
9
  const require_hotkey_registrations = require('./controllers/hotkey-registrations.cjs');
10
10
  const require_hotkey_sequence_recorder = require('./controllers/hotkey-sequence-recorder.cjs');
11
11
  const require_key_hold = require('./controllers/key-hold.cjs');
12
+ const require_hotkey_hint = require('./controllers/hotkey-hint.cjs');
12
13
 
13
14
  exports.HeldKeyCodesController = require_held_key_codes.HeldKeyCodesController;
14
15
  exports.HeldKeysController = require_held_keys.HeldKeysController;
15
16
  exports.HotkeyController = require_hotkey.HotkeyController;
17
+ exports.HotkeyHintController = require_hotkey_hint.HotkeyHintController;
16
18
  exports.HotkeyRecorderController = require_hotkey_recorder.HotkeyRecorderController;
17
19
  exports.HotkeyRegistrationsController = require_hotkey_registrations.HotkeyRegistrationsController;
18
20
  exports.HotkeySequenceController = require_hotkey_sequence.HotkeySequenceController;
package/dist/index.d.cts CHANGED
@@ -8,5 +8,6 @@ import { HotkeyRegistrationsController } from "./controllers/hotkey-registration
8
8
  import { HotkeySequenceController } from "./controllers/hotkey-sequence.cjs";
9
9
  import { HotkeySequenceRecorderController } from "./controllers/hotkey-sequence-recorder.cjs";
10
10
  import { KeyHoldController } from "./controllers/key-hold.cjs";
11
+ import { HotkeyHintController } from "./controllers/hotkey-hint.cjs";
11
12
  export * from "@tanstack/hotkeys";
12
- export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
13
+ export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyHintController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
package/dist/index.d.ts CHANGED
@@ -8,5 +8,6 @@ import { HotkeyRegistrationsController } from "./controllers/hotkey-registration
8
8
  import { HotkeySequenceController } from "./controllers/hotkey-sequence.js";
9
9
  import { HotkeySequenceRecorderController } from "./controllers/hotkey-sequence-recorder.js";
10
10
  import { KeyHoldController } from "./controllers/key-hold.js";
11
+ import { HotkeyHintController } from "./controllers/hotkey-hint.js";
11
12
  export * from "@tanstack/hotkeys";
12
- export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
13
+ export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyHintController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
package/dist/index.js CHANGED
@@ -8,7 +8,8 @@ import { HotkeyRecorderController } from "./controllers/hotkey-recorder.js";
8
8
  import { HotkeyRegistrationsController } from "./controllers/hotkey-registrations.js";
9
9
  import { HotkeySequenceRecorderController } from "./controllers/hotkey-sequence-recorder.js";
10
10
  import { KeyHoldController } from "./controllers/key-hold.js";
11
+ import { HotkeyHintController } from "./controllers/hotkey-hint.js";
11
12
 
12
13
  export * from "@tanstack/hotkeys"
13
14
 
14
- export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
15
+ export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyHintController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/lit-hotkeys",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Lit adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "src"
40
40
  ],
41
41
  "dependencies": {
42
- "@tanstack/hotkeys": "0.8.0"
42
+ "@tanstack/hotkeys": "0.9.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "lit": "^3.3.2"
@@ -0,0 +1,56 @@
1
+ import { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'
2
+ import type { ReactiveController, ReactiveControllerHost } from 'lit'
3
+ import type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'
4
+
5
+ /** Modifier hint controller. Getter arguments can read reactive host properties. */
6
+ export class HotkeyHintController implements ReactiveController {
7
+ private unsubscribe?: () => void
8
+ private visible = false
9
+
10
+ /** Attaches to the host; getter arguments can read changing reactive properties. */
11
+ constructor(
12
+ private host: ReactiveControllerHost,
13
+ private hotkey: RegisterableHotkey | (() => RegisterableHotkey),
14
+ private options: HeldModifierOptions | (() => HeldModifierOptions) = {},
15
+ ) {
16
+ host.addController(this)
17
+ }
18
+
19
+ /** Current visibility; combine with the action’s enabled state when rendering. */
20
+ get value(): boolean {
21
+ return this.visible
22
+ }
23
+
24
+ /** Subscribes on connection and requests renders only when hint visibility changes. */
25
+ hostConnected(): void {
26
+ this.update()
27
+ const subscription = getKeyStateTracker().store.subscribe(() => {
28
+ if (this.update()) this.host.requestUpdate()
29
+ })
30
+ this.unsubscribe = () => subscription.unsubscribe()
31
+ }
32
+
33
+ /** Re-evaluates getter arguments when host properties trigger an update. */
34
+ hostUpdate(): void {
35
+ this.update()
36
+ }
37
+
38
+ /** Releases the subscription and clears cached visibility while disconnected. */
39
+ hostDisconnected(): void {
40
+ this.unsubscribe?.()
41
+ this.unsubscribe = undefined
42
+ this.visible = false
43
+ }
44
+
45
+ /** Recomputes visibility and reports whether the host needs another render. */
46
+ private update(): boolean {
47
+ const next = matchesHeldModifiers(
48
+ typeof this.hotkey === 'function' ? this.hotkey() : this.hotkey,
49
+ getKeyStateTracker().store.state.heldKeys,
50
+ typeof this.options === 'function' ? this.options() : this.options,
51
+ )
52
+ const changed = next !== this.visible
53
+ this.visible = next
54
+ return changed
55
+ }
56
+ }
@@ -6,3 +6,4 @@ export * from './hotkey-registrations'
6
6
  export * from './hotkey-sequence'
7
7
  export * from './hotkey-sequence-recorder'
8
8
  export * from './key-hold'
9
+ export * from './hotkey-hint'