@tanstack/angular-hotkeys 0.8.3 → 0.9.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 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/injectHotkeyRegistrations.cjs +28 -0
- package/dist/injectHotkeyRegistrations.cjs.map +1 -0
- package/dist/injectHotkeyRegistrations.d.cts +29 -0
- package/dist/injectHotkeyRegistrations.d.ts +29 -0
- package/dist/injectHotkeyRegistrations.js +28 -0
- package/dist/injectHotkeyRegistrations.js.map +1 -0
- package/dist/injectKeyHold.cjs.map +1 -1
- package/dist/injectKeyHold.d.cts +2 -2
- package/dist/injectKeyHold.d.ts +2 -2
- package/dist/injectKeyHold.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/injectHotkeyRegistrations.ts +48 -0
- package/src/injectKeyHold.ts +4 -2
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ Type-safe keyboard shortcuts for the web. Template-string bindings, parsed objec
|
|
|
58
58
|
> - [**Solid Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/solid/reference)
|
|
59
59
|
> - [**Angular Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/angular/reference)
|
|
60
60
|
> - [**Vue Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/vue/reference)
|
|
61
|
+
> - [**Lit Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/lit/reference)
|
|
61
62
|
> - [**Svelte Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/svelte/reference)
|
|
62
63
|
|
|
63
64
|
## Get Involved
|
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const require_injectHeldKeys = require('./injectHeldKeys.cjs');
|
|
|
8
8
|
const require_injectHeldKeyCodes = require('./injectHeldKeyCodes.cjs');
|
|
9
9
|
const require_injectKeyHold = require('./injectKeyHold.cjs');
|
|
10
10
|
const require_injectHotkeyRecorder = require('./injectHotkeyRecorder.cjs');
|
|
11
|
+
const require_injectHotkeyRegistrations = require('./injectHotkeyRegistrations.cjs');
|
|
11
12
|
const require_injectHotkeySequenceRecorder = require('./injectHotkeySequenceRecorder.cjs');
|
|
12
13
|
|
|
13
14
|
exports.HOTKEYS_INJECTION_TOKEN = require_hotkeys_provider.HOTKEYS_INJECTION_TOKEN;
|
|
@@ -16,6 +17,7 @@ exports.injectHeldKeyCodes = require_injectHeldKeyCodes.injectHeldKeyCodes;
|
|
|
16
17
|
exports.injectHeldKeys = require_injectHeldKeys.injectHeldKeys;
|
|
17
18
|
exports.injectHotkey = require_injectHotkey.injectHotkey;
|
|
18
19
|
exports.injectHotkeyRecorder = require_injectHotkeyRecorder.injectHotkeyRecorder;
|
|
20
|
+
exports.injectHotkeyRegistrations = require_injectHotkeyRegistrations.injectHotkeyRegistrations;
|
|
19
21
|
exports.injectHotkeySequence = require_injectHotkeySequence.injectHotkeySequence;
|
|
20
22
|
exports.injectHotkeySequenceRecorder = require_injectHotkeySequenceRecorder.injectHotkeySequenceRecorder;
|
|
21
23
|
exports.injectHotkeySequences = require_injectHotkeySequences.injectHotkeySequences;
|
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,7 @@ import { injectHeldKeys } from "./injectHeldKeys.cjs";
|
|
|
7
7
|
import { injectHeldKeyCodes } from "./injectHeldKeyCodes.cjs";
|
|
8
8
|
import { injectKeyHold } from "./injectKeyHold.cjs";
|
|
9
9
|
import { AngularHotkeyRecorder, injectHotkeyRecorder } from "./injectHotkeyRecorder.cjs";
|
|
10
|
+
import { HotkeyRegistrationsResult, injectHotkeyRegistrations } from "./injectHotkeyRegistrations.cjs";
|
|
10
11
|
import { AngularHotkeySequenceRecorder, injectHotkeySequenceRecorder } from "./injectHotkeySequenceRecorder.cjs";
|
|
11
12
|
export * from "@tanstack/hotkeys";
|
|
12
|
-
export { AngularHotkeyRecorder, AngularHotkeySequenceRecorder, HOTKEYS_INJECTION_TOKEN, HotkeysContextValue, HotkeysProviderOptions, InjectHotkeyDefinition, InjectHotkeyOptions, InjectHotkeySequenceDefinition, InjectHotkeySequenceOptions, injectDefaultHotkeysOptions, injectHeldKeyCodes, injectHeldKeys, injectHotkey, injectHotkeyRecorder, injectHotkeySequence, injectHotkeySequenceRecorder, injectHotkeySequences, injectHotkeys, injectHotkeysContext, injectKeyHold, provideHotkeys };
|
|
13
|
+
export { AngularHotkeyRecorder, AngularHotkeySequenceRecorder, HOTKEYS_INJECTION_TOKEN, HotkeyRegistrationsResult, HotkeysContextValue, HotkeysProviderOptions, InjectHotkeyDefinition, InjectHotkeyOptions, InjectHotkeySequenceDefinition, InjectHotkeySequenceOptions, injectDefaultHotkeysOptions, injectHeldKeyCodes, injectHeldKeys, injectHotkey, injectHotkeyRecorder, injectHotkeyRegistrations, injectHotkeySequence, injectHotkeySequenceRecorder, injectHotkeySequences, injectHotkeys, injectHotkeysContext, injectKeyHold, provideHotkeys };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { injectHeldKeys } from "./injectHeldKeys.js";
|
|
|
7
7
|
import { injectHeldKeyCodes } from "./injectHeldKeyCodes.js";
|
|
8
8
|
import { injectKeyHold } from "./injectKeyHold.js";
|
|
9
9
|
import { AngularHotkeyRecorder, injectHotkeyRecorder } from "./injectHotkeyRecorder.js";
|
|
10
|
+
import { HotkeyRegistrationsResult, injectHotkeyRegistrations } from "./injectHotkeyRegistrations.js";
|
|
10
11
|
import { AngularHotkeySequenceRecorder, injectHotkeySequenceRecorder } from "./injectHotkeySequenceRecorder.js";
|
|
11
12
|
export * from "@tanstack/hotkeys";
|
|
12
|
-
export { AngularHotkeyRecorder, AngularHotkeySequenceRecorder, HOTKEYS_INJECTION_TOKEN, HotkeysContextValue, HotkeysProviderOptions, InjectHotkeyDefinition, InjectHotkeyOptions, InjectHotkeySequenceDefinition, InjectHotkeySequenceOptions, injectDefaultHotkeysOptions, injectHeldKeyCodes, injectHeldKeys, injectHotkey, injectHotkeyRecorder, injectHotkeySequence, injectHotkeySequenceRecorder, injectHotkeySequences, injectHotkeys, injectHotkeysContext, injectKeyHold, provideHotkeys };
|
|
13
|
+
export { AngularHotkeyRecorder, AngularHotkeySequenceRecorder, HOTKEYS_INJECTION_TOKEN, HotkeyRegistrationsResult, HotkeysContextValue, HotkeysProviderOptions, InjectHotkeyDefinition, InjectHotkeyOptions, InjectHotkeySequenceDefinition, InjectHotkeySequenceOptions, injectDefaultHotkeysOptions, injectHeldKeyCodes, injectHeldKeys, injectHotkey, injectHotkeyRecorder, injectHotkeyRegistrations, injectHotkeySequence, injectHotkeySequenceRecorder, injectHotkeySequences, injectHotkeys, injectHotkeysContext, injectKeyHold, provideHotkeys };
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,9 @@ import { injectHeldKeys } from "./injectHeldKeys.js";
|
|
|
7
7
|
import { injectHeldKeyCodes } from "./injectHeldKeyCodes.js";
|
|
8
8
|
import { injectKeyHold } from "./injectKeyHold.js";
|
|
9
9
|
import { injectHotkeyRecorder } from "./injectHotkeyRecorder.js";
|
|
10
|
+
import { injectHotkeyRegistrations } from "./injectHotkeyRegistrations.js";
|
|
10
11
|
import { injectHotkeySequenceRecorder } from "./injectHotkeySequenceRecorder.js";
|
|
11
12
|
|
|
12
13
|
export * from "@tanstack/hotkeys"
|
|
13
14
|
|
|
14
|
-
export { HOTKEYS_INJECTION_TOKEN, injectDefaultHotkeysOptions, injectHeldKeyCodes, injectHeldKeys, injectHotkey, injectHotkeyRecorder, injectHotkeySequence, injectHotkeySequenceRecorder, injectHotkeySequences, injectHotkeys, injectHotkeysContext, injectKeyHold, provideHotkeys };
|
|
15
|
+
export { HOTKEYS_INJECTION_TOKEN, injectDefaultHotkeysOptions, injectHeldKeyCodes, injectHeldKeys, injectHotkey, injectHotkeyRecorder, injectHotkeyRegistrations, injectHotkeySequence, injectHotkeySequenceRecorder, injectHotkeySequences, injectHotkeys, injectHotkeysContext, injectKeyHold, provideHotkeys };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
+
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
3
|
+
|
|
4
|
+
//#region src/injectHotkeyRegistrations.ts
|
|
5
|
+
/**
|
|
6
|
+
* Angular injectable that reactively reads all hotkey and sequence registrations
|
|
7
|
+
* from the singleton managers.
|
|
8
|
+
*
|
|
9
|
+
* This is a standalone injectable that does NOT require the HotkeysProvider.
|
|
10
|
+
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
11
|
+
* triggers change detection when registrations change.
|
|
12
|
+
*
|
|
13
|
+
* Must be called in an injection context (constructor, factory, or `inject()`).
|
|
14
|
+
*
|
|
15
|
+
* @returns Object with `hotkeys` and `sequences` signals
|
|
16
|
+
*/
|
|
17
|
+
function injectHotkeyRegistrations() {
|
|
18
|
+
const hotkeyManager = (0, _tanstack_hotkeys.getHotkeyManager)();
|
|
19
|
+
const sequenceManager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
20
|
+
return {
|
|
21
|
+
hotkeys: (0, _tanstack_angular_store.injectStore)(hotkeyManager.registrations, (state) => Array.from(state.values()).map(_tanstack_hotkeys.toHotkeyRegistrationView)),
|
|
22
|
+
sequences: (0, _tanstack_angular_store.injectStore)(sequenceManager.registrations, (state) => Array.from(state.values()))
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.injectHotkeyRegistrations = injectHotkeyRegistrations;
|
|
28
|
+
//# sourceMappingURL=injectHotkeyRegistrations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectHotkeyRegistrations.cjs","names":["toHotkeyRegistrationView"],"sources":["../src/injectHotkeyRegistrations.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\nimport type { Signal } from '@angular/core'\n\n/**\n * Return type for injectHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** Signal for all registered hotkeys (public view, no callbacks) */\n hotkeys: Signal<Array<HotkeyRegistrationView>>\n /** Signal for all registered sequences */\n sequences: Signal<Array<SequenceRegistrationView>>\n}\n\n/**\n * Angular injectable that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone injectable that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * triggers change detection when registrations change.\n *\n * Must be called in an injection context (constructor, factory, or `inject()`).\n *\n * @returns Object with `hotkeys` and `sequences` signals\n */\nexport function injectHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = injectStore(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = injectStore(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,4BAAuD;CACrE,MAAM,yDAAkC;CACxC,MAAM,6DAAsC;AAU5C,QAAO;EAAE,kDARmB,cAAc,gBAAgB,UACxD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAIA,2CAAyB,CACzD;EAMiB,oDAJY,gBAAgB,gBAAgB,UAC5D,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
+
import { Signal } from "@angular/core";
|
|
3
|
+
|
|
4
|
+
//#region src/injectHotkeyRegistrations.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Return type for injectHotkeyRegistrations.
|
|
7
|
+
*/
|
|
8
|
+
interface HotkeyRegistrationsResult {
|
|
9
|
+
/** Signal for all registered hotkeys (public view, no callbacks) */
|
|
10
|
+
hotkeys: Signal<Array<HotkeyRegistrationView>>;
|
|
11
|
+
/** Signal for all registered sequences */
|
|
12
|
+
sequences: Signal<Array<SequenceRegistrationView>>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Angular injectable that reactively reads all hotkey and sequence registrations
|
|
16
|
+
* from the singleton managers.
|
|
17
|
+
*
|
|
18
|
+
* This is a standalone injectable that does NOT require the HotkeysProvider.
|
|
19
|
+
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
20
|
+
* triggers change detection when registrations change.
|
|
21
|
+
*
|
|
22
|
+
* Must be called in an injection context (constructor, factory, or `inject()`).
|
|
23
|
+
*
|
|
24
|
+
* @returns Object with `hotkeys` and `sequences` signals
|
|
25
|
+
*/
|
|
26
|
+
declare function injectHotkeyRegistrations(): HotkeyRegistrationsResult;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { HotkeyRegistrationsResult, injectHotkeyRegistrations };
|
|
29
|
+
//# sourceMappingURL=injectHotkeyRegistrations.d.cts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
+
import { Signal } from "@angular/core";
|
|
3
|
+
|
|
4
|
+
//#region src/injectHotkeyRegistrations.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Return type for injectHotkeyRegistrations.
|
|
7
|
+
*/
|
|
8
|
+
interface HotkeyRegistrationsResult {
|
|
9
|
+
/** Signal for all registered hotkeys (public view, no callbacks) */
|
|
10
|
+
hotkeys: Signal<Array<HotkeyRegistrationView>>;
|
|
11
|
+
/** Signal for all registered sequences */
|
|
12
|
+
sequences: Signal<Array<SequenceRegistrationView>>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Angular injectable that reactively reads all hotkey and sequence registrations
|
|
16
|
+
* from the singleton managers.
|
|
17
|
+
*
|
|
18
|
+
* This is a standalone injectable that does NOT require the HotkeysProvider.
|
|
19
|
+
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
20
|
+
* triggers change detection when registrations change.
|
|
21
|
+
*
|
|
22
|
+
* Must be called in an injection context (constructor, factory, or `inject()`).
|
|
23
|
+
*
|
|
24
|
+
* @returns Object with `hotkeys` and `sequences` signals
|
|
25
|
+
*/
|
|
26
|
+
declare function injectHotkeyRegistrations(): HotkeyRegistrationsResult;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { HotkeyRegistrationsResult, injectHotkeyRegistrations };
|
|
29
|
+
//# sourceMappingURL=injectHotkeyRegistrations.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
+
import { injectStore } from "@tanstack/angular-store";
|
|
3
|
+
|
|
4
|
+
//#region src/injectHotkeyRegistrations.ts
|
|
5
|
+
/**
|
|
6
|
+
* Angular injectable that reactively reads all hotkey and sequence registrations
|
|
7
|
+
* from the singleton managers.
|
|
8
|
+
*
|
|
9
|
+
* This is a standalone injectable that does NOT require the HotkeysProvider.
|
|
10
|
+
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
11
|
+
* triggers change detection when registrations change.
|
|
12
|
+
*
|
|
13
|
+
* Must be called in an injection context (constructor, factory, or `inject()`).
|
|
14
|
+
*
|
|
15
|
+
* @returns Object with `hotkeys` and `sequences` signals
|
|
16
|
+
*/
|
|
17
|
+
function injectHotkeyRegistrations() {
|
|
18
|
+
const hotkeyManager = getHotkeyManager();
|
|
19
|
+
const sequenceManager = getSequenceManager();
|
|
20
|
+
return {
|
|
21
|
+
hotkeys: injectStore(hotkeyManager.registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView)),
|
|
22
|
+
sequences: injectStore(sequenceManager.registrations, (state) => Array.from(state.values()))
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { injectHotkeyRegistrations };
|
|
28
|
+
//# sourceMappingURL=injectHotkeyRegistrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectHotkeyRegistrations.js","names":[],"sources":["../src/injectHotkeyRegistrations.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\nimport type { Signal } from '@angular/core'\n\n/**\n * Return type for injectHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** Signal for all registered hotkeys (public view, no callbacks) */\n hotkeys: Signal<Array<HotkeyRegistrationView>>\n /** Signal for all registered sequences */\n sequences: Signal<Array<SequenceRegistrationView>>\n}\n\n/**\n * Angular injectable that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone injectable that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * triggers change detection when registrations change.\n *\n * Must be called in an injection context (constructor, factory, or `inject()`).\n *\n * @returns Object with `hotkeys` and `sequences` signals\n */\nexport function injectHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = injectStore(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = injectStore(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,4BAAuD;CACrE,MAAM,gBAAgB,kBAAkB;CACxC,MAAM,kBAAkB,oBAAoB;AAU5C,QAAO;EAAE,SARO,YAAY,cAAc,gBAAgB,UACxD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAI,yBAAyB,CACzD;EAMiB,WAJA,YAAY,gBAAgB,gBAAgB,UAC5D,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectKeyHold.cjs","names":[],"sources":["../src/injectKeyHold.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type {
|
|
1
|
+
{"version":3,"file":"injectKeyHold.cjs","names":[],"sources":["../src/injectKeyHold.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { IndividualKey } from '@tanstack/hotkeys'\nimport type { Signal } from '@angular/core'\n\n/**\n * Angular inject-based API that returns a signal that is true when the given key is held.\n *\n * Subscribes to the global KeyStateTracker and uses a computed to determine\n * if the specified key is held.\n *\n * @param key - The key to check (e.g. 'Shift', 'Control', 'Space') - can be a getter function\n * @returns Signal that returns true if the key is currently held down\n *\n * @example\n * ```ts\n * @Component({\n * template: `{{ isShiftHeld() ? 'Shift is pressed!' : 'Press Shift' }}`,\n * })\n * export class ShiftIndicatorComponent {\n * isShiftHeld = injectKeyHold('Shift')\n * }\n * ```\n *\n * @example\n * ```ts\n * @Component({\n * template: `\n * <span [style.opacity]=\"ctrl() ? 1 : 0.3\">Ctrl</span>\n * <span [style.opacity]=\"shift() ? 1 : 0.3\">Shift</span>\n * `,\n * })\n * export class ModifierIndicatorsComponent {\n * ctrl = injectKeyHold('Control')\n * shift = injectKeyHold('Shift')\n * }\n * ```\n */\nexport function injectKeyHold(\n key: IndividualKey | (() => IndividualKey),\n): Signal<boolean> {\n const tracker = getKeyStateTracker()\n const heldKeysSelector = injectStore(tracker.store, (state) => state.heldKeys)\n\n return computed(() => {\n const resolvedKey = typeof key === 'function' ? key() : key\n const normalizedKey = resolvedKey.toLowerCase()\n\n return heldKeysSelector().some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,cACd,KACiB;CAEjB,MAAM,uGAD8B,CACS,QAAQ,UAAU,MAAM,SAAS;AAE9E,0CAAsB;EAEpB,MAAM,iBADc,OAAO,QAAQ,aAAa,KAAK,GAAG,KACtB,aAAa;AAE/C,SAAO,kBAAkB,CAAC,MACvB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
package/dist/injectKeyHold.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IndividualKey } from "@tanstack/hotkeys";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
3
|
|
|
4
4
|
//#region src/injectKeyHold.d.ts
|
|
@@ -35,7 +35,7 @@ import { Signal } from "@angular/core";
|
|
|
35
35
|
* }
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
declare function injectKeyHold(key:
|
|
38
|
+
declare function injectKeyHold(key: IndividualKey | (() => IndividualKey)): Signal<boolean>;
|
|
39
39
|
//#endregion
|
|
40
40
|
export { injectKeyHold };
|
|
41
41
|
//# sourceMappingURL=injectKeyHold.d.cts.map
|
package/dist/injectKeyHold.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IndividualKey } from "@tanstack/hotkeys";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
3
|
|
|
4
4
|
//#region src/injectKeyHold.d.ts
|
|
@@ -35,7 +35,7 @@ import { Signal } from "@angular/core";
|
|
|
35
35
|
* }
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
declare function injectKeyHold(key:
|
|
38
|
+
declare function injectKeyHold(key: IndividualKey | (() => IndividualKey)): Signal<boolean>;
|
|
39
39
|
//#endregion
|
|
40
40
|
export { injectKeyHold };
|
|
41
41
|
//# sourceMappingURL=injectKeyHold.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectKeyHold.js","names":[],"sources":["../src/injectKeyHold.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type {
|
|
1
|
+
{"version":3,"file":"injectKeyHold.js","names":[],"sources":["../src/injectKeyHold.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectStore } from '@tanstack/angular-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { IndividualKey } from '@tanstack/hotkeys'\nimport type { Signal } from '@angular/core'\n\n/**\n * Angular inject-based API that returns a signal that is true when the given key is held.\n *\n * Subscribes to the global KeyStateTracker and uses a computed to determine\n * if the specified key is held.\n *\n * @param key - The key to check (e.g. 'Shift', 'Control', 'Space') - can be a getter function\n * @returns Signal that returns true if the key is currently held down\n *\n * @example\n * ```ts\n * @Component({\n * template: `{{ isShiftHeld() ? 'Shift is pressed!' : 'Press Shift' }}`,\n * })\n * export class ShiftIndicatorComponent {\n * isShiftHeld = injectKeyHold('Shift')\n * }\n * ```\n *\n * @example\n * ```ts\n * @Component({\n * template: `\n * <span [style.opacity]=\"ctrl() ? 1 : 0.3\">Ctrl</span>\n * <span [style.opacity]=\"shift() ? 1 : 0.3\">Shift</span>\n * `,\n * })\n * export class ModifierIndicatorsComponent {\n * ctrl = injectKeyHold('Control')\n * shift = injectKeyHold('Shift')\n * }\n * ```\n */\nexport function injectKeyHold(\n key: IndividualKey | (() => IndividualKey),\n): Signal<boolean> {\n const tracker = getKeyStateTracker()\n const heldKeysSelector = injectStore(tracker.store, (state) => state.heldKeys)\n\n return computed(() => {\n const resolvedKey = typeof key === 'function' ? key() : key\n const normalizedKey = resolvedKey.toLowerCase()\n\n return heldKeysSelector().some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,cACd,KACiB;CAEjB,MAAM,mBAAmB,YADT,oBAAoB,CACS,QAAQ,UAAU,MAAM,SAAS;AAE9E,QAAO,eAAe;EAEpB,MAAM,iBADc,OAAO,QAAQ,aAAa,KAAK,GAAG,KACtB,aAAa;AAE/C,SAAO,kBAAkB,CAAC,MACvB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Angular adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,17 +42,17 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@tanstack/angular-store": "^0.9.3",
|
|
45
|
-
"@tanstack/hotkeys": "0.
|
|
45
|
+
"@tanstack/hotkeys": "0.7.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@angular/common": ">=19.0.0",
|
|
49
49
|
"@angular/core": ">=19.0.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@angular/common": "^21.2.
|
|
53
|
-
"@angular/core": "^21.2.
|
|
54
|
-
"@angular/platform-browser-dynamic": "^21.2.
|
|
55
|
-
"typescript": "
|
|
52
|
+
"@angular/common": "^21.2.6",
|
|
53
|
+
"@angular/core": "^21.2.6",
|
|
54
|
+
"@angular/platform-browser-dynamic": "^21.2.6",
|
|
55
|
+
"typescript": "6.0.2"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"clean": "premove ./build ./dist",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { injectStore } from '@tanstack/angular-store'
|
|
2
|
+
import {
|
|
3
|
+
getHotkeyManager,
|
|
4
|
+
getSequenceManager,
|
|
5
|
+
toHotkeyRegistrationView,
|
|
6
|
+
} from '@tanstack/hotkeys'
|
|
7
|
+
import type {
|
|
8
|
+
HotkeyRegistrationView,
|
|
9
|
+
SequenceRegistrationView,
|
|
10
|
+
} from '@tanstack/hotkeys'
|
|
11
|
+
import type { Signal } from '@angular/core'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Return type for injectHotkeyRegistrations.
|
|
15
|
+
*/
|
|
16
|
+
export interface HotkeyRegistrationsResult {
|
|
17
|
+
/** Signal for all registered hotkeys (public view, no callbacks) */
|
|
18
|
+
hotkeys: Signal<Array<HotkeyRegistrationView>>
|
|
19
|
+
/** Signal for all registered sequences */
|
|
20
|
+
sequences: Signal<Array<SequenceRegistrationView>>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Angular injectable that reactively reads all hotkey and sequence registrations
|
|
25
|
+
* from the singleton managers.
|
|
26
|
+
*
|
|
27
|
+
* This is a standalone injectable that does NOT require the HotkeysProvider.
|
|
28
|
+
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
29
|
+
* triggers change detection when registrations change.
|
|
30
|
+
*
|
|
31
|
+
* Must be called in an injection context (constructor, factory, or `inject()`).
|
|
32
|
+
*
|
|
33
|
+
* @returns Object with `hotkeys` and `sequences` signals
|
|
34
|
+
*/
|
|
35
|
+
export function injectHotkeyRegistrations(): HotkeyRegistrationsResult {
|
|
36
|
+
const hotkeyManager = getHotkeyManager()
|
|
37
|
+
const sequenceManager = getSequenceManager()
|
|
38
|
+
|
|
39
|
+
const hotkeys = injectStore(hotkeyManager.registrations, (state) =>
|
|
40
|
+
Array.from(state.values()).map(toHotkeyRegistrationView),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const sequences = injectStore(sequenceManager.registrations, (state) =>
|
|
44
|
+
Array.from(state.values()),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return { hotkeys, sequences }
|
|
48
|
+
}
|
package/src/injectKeyHold.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computed } from '@angular/core'
|
|
2
2
|
import { injectStore } from '@tanstack/angular-store'
|
|
3
3
|
import { getKeyStateTracker } from '@tanstack/hotkeys'
|
|
4
|
-
import type {
|
|
4
|
+
import type { IndividualKey } from '@tanstack/hotkeys'
|
|
5
5
|
import type { Signal } from '@angular/core'
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -37,7 +37,9 @@ import type { Signal } from '@angular/core'
|
|
|
37
37
|
* }
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export function injectKeyHold(
|
|
40
|
+
export function injectKeyHold(
|
|
41
|
+
key: IndividualKey | (() => IndividualKey),
|
|
42
|
+
): Signal<boolean> {
|
|
41
43
|
const tracker = getKeyStateTracker()
|
|
42
44
|
const heldKeysSelector = injectStore(tracker.store, (state) => state.heldKeys)
|
|
43
45
|
|