@tanstack/vue-hotkeys 0.9.1 → 0.11.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 +15 -1
- 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/useHeldKeyCodes.cjs +1 -1
- package/dist/useHeldKeyCodes.cjs.map +1 -1
- package/dist/useHeldKeyCodes.js +2 -2
- package/dist/useHeldKeyCodes.js.map +1 -1
- package/dist/useHeldKeys.cjs +2 -2
- package/dist/useHeldKeys.cjs.map +1 -1
- package/dist/useHeldKeys.d.cts +1 -1
- package/dist/useHeldKeys.d.ts +1 -1
- package/dist/useHeldKeys.js +3 -3
- package/dist/useHeldKeys.js.map +1 -1
- package/dist/useHotkeyHint.cjs +20 -0
- package/dist/useHotkeyHint.cjs.map +1 -0
- package/dist/useHotkeyHint.d.cts +15 -0
- package/dist/useHotkeyHint.d.ts +15 -0
- package/dist/useHotkeyHint.js +20 -0
- package/dist/useHotkeyHint.js.map +1 -0
- package/dist/useHotkeyRecorder.cjs +2 -2
- package/dist/useHotkeyRecorder.cjs.map +1 -1
- package/dist/useHotkeyRecorder.js +3 -3
- package/dist/useHotkeyRecorder.js.map +1 -1
- package/dist/useHotkeyRegistrations.cjs +2 -2
- package/dist/useHotkeyRegistrations.cjs.map +1 -1
- package/dist/useHotkeyRegistrations.js +3 -3
- package/dist/useHotkeyRegistrations.js.map +1 -1
- package/dist/useHotkeySequenceRecorder.cjs +3 -3
- package/dist/useHotkeySequenceRecorder.cjs.map +1 -1
- package/dist/useHotkeySequenceRecorder.js +4 -4
- package/dist/useHotkeySequenceRecorder.js.map +1 -1
- package/dist/useKeyHold.cjs +2 -2
- package/dist/useKeyHold.cjs.map +1 -1
- package/dist/useKeyHold.d.cts +1 -1
- package/dist/useKeyHold.d.ts +1 -1
- package/dist/useKeyHold.js +3 -3
- package/dist/useKeyHold.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/useHeldKeyCodes.ts +2 -2
- package/src/useHeldKeys.ts +3 -3
- package/src/useHotkeyHint.ts +25 -0
- package/src/useHotkeyRecorder.ts +4 -4
- package/src/useHotkeyRegistrations.ts +3 -3
- package/src/useHotkeySequenceRecorder.ts +4 -4
- package/src/useKeyHold.ts +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
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 />
|
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ const require_useHotkeySequences = require('./useHotkeySequences.cjs');
|
|
|
11
11
|
const require_useHotkeyRecorder = require('./useHotkeyRecorder.cjs');
|
|
12
12
|
const require_useHotkeyRegistrations = require('./useHotkeyRegistrations.cjs');
|
|
13
13
|
const require_useHotkeySequenceRecorder = require('./useHotkeySequenceRecorder.cjs');
|
|
14
|
+
const require_useHotkeyHint = require('./useHotkeyHint.cjs');
|
|
14
15
|
|
|
15
16
|
exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
|
|
16
17
|
exports.provideHotkeysContext = require_HotkeysProviderContext.provideHotkeysContext;
|
|
@@ -18,6 +19,7 @@ exports.useDefaultHotkeysOptions = require_HotkeysProviderContext.useDefaultHotk
|
|
|
18
19
|
exports.useHeldKeyCodes = require_useHeldKeyCodes.useHeldKeyCodes;
|
|
19
20
|
exports.useHeldKeys = require_useHeldKeys.useHeldKeys;
|
|
20
21
|
exports.useHotkey = require_useHotkey.useHotkey;
|
|
22
|
+
exports.useHotkeyHint = require_useHotkeyHint.useHotkeyHint;
|
|
21
23
|
exports.useHotkeyRecorder = require_useHotkeyRecorder.useHotkeyRecorder;
|
|
22
24
|
exports.useHotkeyRegistrations = require_useHotkeyRegistrations.useHotkeyRegistrations;
|
|
23
25
|
exports.useHotkeySequence = require_useHotkeySequence.useHotkeySequence;
|
package/dist/index.d.cts
CHANGED
|
@@ -10,5 +10,6 @@ import { UseHotkeySequenceDefinition, useHotkeySequences } from "./useHotkeySequ
|
|
|
10
10
|
import { VueHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.cjs";
|
|
11
11
|
import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.cjs";
|
|
12
12
|
import { VueHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.cjs";
|
|
13
|
+
import { useHotkeyHint } from "./useHotkeyHint.cjs";
|
|
13
14
|
export * from "@tanstack/hotkeys";
|
|
14
|
-
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, VueHotkeyRecorder, VueHotkeySequenceRecorder, provideHotkeysContext, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
|
15
|
+
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, VueHotkeyRecorder, VueHotkeySequenceRecorder, provideHotkeysContext, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ import { UseHotkeySequenceDefinition, useHotkeySequences } from "./useHotkeySequ
|
|
|
10
10
|
import { VueHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
11
11
|
import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
12
12
|
import { VueHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.js";
|
|
13
|
+
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
13
14
|
export * from "@tanstack/hotkeys";
|
|
14
|
-
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, VueHotkeyRecorder, VueHotkeySequenceRecorder, provideHotkeysContext, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
|
15
|
+
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, VueHotkeyRecorder, VueHotkeySequenceRecorder, provideHotkeysContext, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import { useHotkeySequences } from "./useHotkeySequences.js";
|
|
|
10
10
|
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
11
11
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
12
12
|
import { useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.js";
|
|
13
|
+
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
13
14
|
|
|
14
15
|
export * from "@tanstack/hotkeys"
|
|
15
16
|
|
|
16
|
-
export { HotkeysProvider, provideHotkeysContext, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
|
17
|
+
export { HotkeysProvider, provideHotkeysContext, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
package/dist/useHeldKeyCodes.cjs
CHANGED
|
@@ -29,7 +29,7 @@ let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
function useHeldKeyCodes() {
|
|
32
|
-
return (0, _tanstack_vue_store.
|
|
32
|
+
return (0, _tanstack_vue_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldCodes);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHeldKeyCodes.cjs","names":[],"sources":["../src/useHeldKeyCodes.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useHeldKeyCodes.cjs","names":[],"sources":["../src/useHeldKeyCodes.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { Ref } from 'vue'\n\n/**\n * Vue composable that returns a reactive ref mapping currently held key names to their physical `event.code` values.\n *\n * This is useful for debugging which physical key was pressed (e.g. distinguishing\n * left vs right Shift via \"ShiftLeft\" / \"ShiftRight\").\n *\n * @returns Reactive ref containing record mapping normalized key names to their `event.code` values\n *\n * @example\n * ```vue\n * <script setup>\n * import { useHeldKeys, useHeldKeyCodes } from '@tanstack/vue-hotkeys'\n *\n * const heldKeys = useHeldKeys()\n * const heldCodes = useHeldKeyCodes()\n * </script>\n *\n * <template>\n * <div>\n * <kbd v-for=\"key in heldKeys\" :key=\"key\">\n * {{ key }} <small>{{ heldCodes[key] }}</small>\n * </kbd>\n * </div>\n * </template>\n * ```\n */\nexport function useHeldKeyCodes(): Ref<Record<string, string>> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldCodes)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,kBAA+C;AAE7D,wFADoC,CACT,QAAQ,UAAU,MAAM,UAAU"}
|
package/dist/useHeldKeyCodes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from "@tanstack/vue-store";
|
|
3
3
|
|
|
4
4
|
//#region src/useHeldKeyCodes.ts
|
|
5
5
|
/**
|
|
@@ -29,7 +29,7 @@ import { useStore } from "@tanstack/vue-store";
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
function useHeldKeyCodes() {
|
|
32
|
-
return
|
|
32
|
+
return useSelector(getKeyStateTracker().store, (state) => state.heldCodes);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHeldKeyCodes.js","names":[],"sources":["../src/useHeldKeyCodes.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useHeldKeyCodes.js","names":[],"sources":["../src/useHeldKeyCodes.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { Ref } from 'vue'\n\n/**\n * Vue composable that returns a reactive ref mapping currently held key names to their physical `event.code` values.\n *\n * This is useful for debugging which physical key was pressed (e.g. distinguishing\n * left vs right Shift via \"ShiftLeft\" / \"ShiftRight\").\n *\n * @returns Reactive ref containing record mapping normalized key names to their `event.code` values\n *\n * @example\n * ```vue\n * <script setup>\n * import { useHeldKeys, useHeldKeyCodes } from '@tanstack/vue-hotkeys'\n *\n * const heldKeys = useHeldKeys()\n * const heldCodes = useHeldKeyCodes()\n * </script>\n *\n * <template>\n * <div>\n * <kbd v-for=\"key in heldKeys\" :key=\"key\">\n * {{ key }} <small>{{ heldCodes[key] }}</small>\n * </kbd>\n * </div>\n * </template>\n * ```\n */\nexport function useHeldKeyCodes(): Ref<Record<string, string>> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldCodes)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,kBAA+C;AAE7D,QAAO,YADS,oBAAoB,CACT,QAAQ,UAAU,MAAM,UAAU"}
|
package/dist/useHeldKeys.cjs
CHANGED
|
@@ -5,7 +5,7 @@ let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
|
5
5
|
/**
|
|
6
6
|
* Vue composable that returns a reactive ref of currently held keyboard keys.
|
|
7
7
|
*
|
|
8
|
-
* This composable uses `
|
|
8
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
9
9
|
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
10
|
* or released.
|
|
11
11
|
*
|
|
@@ -27,7 +27,7 @@ let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
function useHeldKeys() {
|
|
30
|
-
return (0, _tanstack_vue_store.
|
|
30
|
+
return (0, _tanstack_vue_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
//#endregion
|
package/dist/useHeldKeys.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHeldKeys.cjs","names":[],"sources":["../src/useHeldKeys.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useHeldKeys.cjs","names":[],"sources":["../src/useHeldKeys.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { Ref } from 'vue'\n\n/**\n * Vue composable that returns a reactive ref of currently held keyboard keys.\n *\n * This composable uses `useSelector` from `@tanstack/vue-store` to subscribe\n * to the global KeyStateTracker and updates whenever keys are pressed\n * or released.\n *\n * @returns Reactive ref containing array of currently held key names\n *\n * @example\n * ```vue\n * <script setup>\n * import { useHeldKeys } from '@tanstack/vue-hotkeys'\n *\n * const heldKeys = useHeldKeys()\n * </script>\n *\n * <template>\n * <div>\n * Currently pressed: {{ heldKeys.join(' + ') || 'None' }}\n * </div>\n * </template>\n * ```\n */\nexport function useHeldKeys(): Ref<Array<string>> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,cAAkC;AAEhD,wFADoC,CACT,QAAQ,UAAU,MAAM,SAAS"}
|
package/dist/useHeldKeys.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { Ref } from "vue";
|
|
|
4
4
|
/**
|
|
5
5
|
* Vue composable that returns a reactive ref of currently held keyboard keys.
|
|
6
6
|
*
|
|
7
|
-
* This composable uses `
|
|
7
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
8
8
|
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
9
9
|
* or released.
|
|
10
10
|
*
|
package/dist/useHeldKeys.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Ref } from "vue";
|
|
|
4
4
|
/**
|
|
5
5
|
* Vue composable that returns a reactive ref of currently held keyboard keys.
|
|
6
6
|
*
|
|
7
|
-
* This composable uses `
|
|
7
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
8
8
|
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
9
9
|
* or released.
|
|
10
10
|
*
|
package/dist/useHeldKeys.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from "@tanstack/vue-store";
|
|
3
3
|
|
|
4
4
|
//#region src/useHeldKeys.ts
|
|
5
5
|
/**
|
|
6
6
|
* Vue composable that returns a reactive ref of currently held keyboard keys.
|
|
7
7
|
*
|
|
8
|
-
* This composable uses `
|
|
8
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
9
9
|
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
10
|
* or released.
|
|
11
11
|
*
|
|
@@ -27,7 +27,7 @@ import { useStore } from "@tanstack/vue-store";
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
function useHeldKeys() {
|
|
30
|
-
return
|
|
30
|
+
return useSelector(getKeyStateTracker().store, (state) => state.heldKeys);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
//#endregion
|
package/dist/useHeldKeys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHeldKeys.js","names":[],"sources":["../src/useHeldKeys.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useHeldKeys.js","names":[],"sources":["../src/useHeldKeys.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { Ref } from 'vue'\n\n/**\n * Vue composable that returns a reactive ref of currently held keyboard keys.\n *\n * This composable uses `useSelector` from `@tanstack/vue-store` to subscribe\n * to the global KeyStateTracker and updates whenever keys are pressed\n * or released.\n *\n * @returns Reactive ref containing array of currently held key names\n *\n * @example\n * ```vue\n * <script setup>\n * import { useHeldKeys } from '@tanstack/vue-hotkeys'\n *\n * const heldKeys = useHeldKeys()\n * </script>\n *\n * <template>\n * <div>\n * Currently pressed: {{ heldKeys.join(' + ') || 'None' }}\n * </div>\n * </template>\n * ```\n */\nexport function useHeldKeys(): Ref<Array<string>> {\n const tracker = getKeyStateTracker()\n return useSelector(tracker.store, (state) => state.heldKeys)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,cAAkC;AAEhD,QAAO,YADS,oBAAoB,CACT,QAAQ,UAAU,MAAM,SAAS"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
+
let vue = require("vue");
|
|
3
|
+
let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
4
|
+
|
|
5
|
+
//#region src/useHotkeyHint.ts
|
|
6
|
+
/**
|
|
7
|
+
* Returns a computed ref indicating whether held modifiers reveal this shortcut.
|
|
8
|
+
* Pass refs or 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
|
+
function useHotkeyHint(hotkey, options = {}) {
|
|
14
|
+
const held = (0, _tanstack_vue_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
|
|
15
|
+
return (0, vue.computed)(() => (0, _tanstack_hotkeys.matchesHeldModifiers)((0, vue.toValue)(hotkey), held.value, (0, vue.toValue)(options)));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.useHotkeyHint = useHotkeyHint;
|
|
20
|
+
//# sourceMappingURL=useHotkeyHint.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHotkeyHint.cjs","names":[],"sources":["../src/useHotkeyHint.ts"],"sourcesContent":["import { computed, toValue } from 'vue'\nimport { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'\nimport type { ComputedRef, MaybeRefOrGetter } from 'vue'\nimport type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'\n\n/**\n * Returns a computed ref indicating whether held modifiers reveal this shortcut.\n * Pass refs or getters to track changing bindings and options.\n * Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires\n * every modifier. Combine with the action's enabled state before showing a badge.\n * This helper does not register a shortcut or check whether its target is focused.\n */\nexport function useHotkeyHint(\n hotkey: MaybeRefOrGetter<RegisterableHotkey>,\n options: MaybeRefOrGetter<HeldModifierOptions> = {},\n): ComputedRef<boolean> {\n const held = useSelector(\n getKeyStateTracker().store,\n (state) => state.heldKeys,\n )\n return computed(() =>\n matchesHeldModifiers(toValue(hotkey), held.value, toValue(options)),\n )\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,cACd,QACA,UAAiD,EAAE,EAC7B;CACtB,MAAM,uFACgB,CAAC,QACpB,UAAU,MAAM,SAClB;AACD,6FAC+B,OAAO,EAAE,KAAK,wBAAe,QAAQ,CAAC,CACpE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
+
import { ComputedRef, MaybeRefOrGetter } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/useHotkeyHint.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns a computed ref indicating whether held modifiers reveal this shortcut.
|
|
7
|
+
* Pass refs or getters to track changing bindings and options.
|
|
8
|
+
* Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
|
|
9
|
+
* every modifier. Combine with the action's enabled state before showing a badge.
|
|
10
|
+
* This helper does not register a shortcut or check whether its target is focused.
|
|
11
|
+
*/
|
|
12
|
+
declare function useHotkeyHint(hotkey: MaybeRefOrGetter<RegisterableHotkey>, options?: MaybeRefOrGetter<HeldModifierOptions>): ComputedRef<boolean>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { useHotkeyHint };
|
|
15
|
+
//# sourceMappingURL=useHotkeyHint.d.cts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
+
import { ComputedRef, MaybeRefOrGetter } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/useHotkeyHint.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns a computed ref indicating whether held modifiers reveal this shortcut.
|
|
7
|
+
* Pass refs or getters to track changing bindings and options.
|
|
8
|
+
* Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
|
|
9
|
+
* every modifier. Combine with the action's enabled state before showing a badge.
|
|
10
|
+
* This helper does not register a shortcut or check whether its target is focused.
|
|
11
|
+
*/
|
|
12
|
+
declare function useHotkeyHint(hotkey: MaybeRefOrGetter<RegisterableHotkey>, options?: MaybeRefOrGetter<HeldModifierOptions>): ComputedRef<boolean>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { useHotkeyHint };
|
|
15
|
+
//# sourceMappingURL=useHotkeyHint.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getKeyStateTracker, matchesHeldModifiers } from "@tanstack/hotkeys";
|
|
2
|
+
import { computed, toValue } from "vue";
|
|
3
|
+
import { useSelector } from "@tanstack/vue-store";
|
|
4
|
+
|
|
5
|
+
//#region src/useHotkeyHint.ts
|
|
6
|
+
/**
|
|
7
|
+
* Returns a computed ref indicating whether held modifiers reveal this shortcut.
|
|
8
|
+
* Pass refs or 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
|
+
function useHotkeyHint(hotkey, options = {}) {
|
|
14
|
+
const held = useSelector(getKeyStateTracker().store, (state) => state.heldKeys);
|
|
15
|
+
return computed(() => matchesHeldModifiers(toValue(hotkey), held.value, toValue(options)));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useHotkeyHint };
|
|
20
|
+
//# sourceMappingURL=useHotkeyHint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHotkeyHint.js","names":[],"sources":["../src/useHotkeyHint.ts"],"sourcesContent":["import { computed, toValue } from 'vue'\nimport { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'\nimport type { ComputedRef, MaybeRefOrGetter } from 'vue'\nimport type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'\n\n/**\n * Returns a computed ref indicating whether held modifiers reveal this shortcut.\n * Pass refs or getters to track changing bindings and options.\n * Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires\n * every modifier. Combine with the action's enabled state before showing a badge.\n * This helper does not register a shortcut or check whether its target is focused.\n */\nexport function useHotkeyHint(\n hotkey: MaybeRefOrGetter<RegisterableHotkey>,\n options: MaybeRefOrGetter<HeldModifierOptions> = {},\n): ComputedRef<boolean> {\n const held = useSelector(\n getKeyStateTracker().store,\n (state) => state.heldKeys,\n )\n return computed(() =>\n matchesHeldModifiers(toValue(hotkey), held.value, toValue(options)),\n )\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,cACd,QACA,UAAiD,EAAE,EAC7B;CACtB,MAAM,OAAO,YACX,oBAAoB,CAAC,QACpB,UAAU,MAAM,SAClB;AACD,QAAO,eACL,qBAAqB,QAAQ,OAAO,EAAE,KAAK,OAAO,QAAQ,QAAQ,CAAC,CACpE"}
|
|
@@ -48,8 +48,8 @@ let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
|
48
48
|
function useHotkeyRecorder(options) {
|
|
49
49
|
const defaultOptions = require_HotkeysProviderContext.useDefaultHotkeysOptions();
|
|
50
50
|
const recorder = new _tanstack_hotkeys.HotkeyRecorder(resolveRecorderOptions(options, defaultOptions));
|
|
51
|
-
const isRecording = (0, _tanstack_vue_store.
|
|
52
|
-
const recordedHotkey = (0, _tanstack_vue_store.
|
|
51
|
+
const isRecording = (0, _tanstack_vue_store.useSelector)(recorder.store, (state) => state.isRecording);
|
|
52
|
+
const recordedHotkey = (0, _tanstack_vue_store.useSelector)(recorder.store, (state) => state.recordedHotkey);
|
|
53
53
|
const stopWatcher = (0, vue.watch)(() => resolveRecorderOptions(options, defaultOptions), (resolvedOptions) => {
|
|
54
54
|
recorder.setOptions(resolvedOptions);
|
|
55
55
|
}, { immediate: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeyRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeyRecorder"],"sources":["../src/useHotkeyRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport {
|
|
1
|
+
{"version":3,"file":"useHotkeyRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeyRecorder"],"sources":["../src/useHotkeyRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport { useSelector } from '@tanstack/vue-store'\nimport { HotkeyRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProviderContext'\nimport type { MaybeRefOrGetter, Ref } from 'vue'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\nexport interface VueHotkeyRecorder {\n /** Whether recording is currently active */\n isRecording: Ref<boolean>\n /** The currently recorded hotkey (for live preview) */\n recordedHotkey: Ref<Hotkey | null>\n /** Start recording a new hotkey */\n startRecording: () => void\n /** Stop recording (same as cancel) */\n stopRecording: () => void\n /** Cancel recording without saving */\n cancelRecording: () => void\n}\n\n/**\n * Vue composable for recording keyboard shortcuts.\n *\n * This composable provides a thin wrapper around the framework-agnostic `HotkeyRecorder`\n * class, managing all the complexity of capturing keyboard events, converting them\n * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete\n * to clear.\n *\n * @param options - Configuration options for the recorder\n * @returns An object with recording state and control functions\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkeyRecorder } from '@tanstack/vue-hotkeys'\n *\n * const shortcut = ref<Hotkey>('Mod+S')\n *\n * const recorder = useHotkeyRecorder({\n * onRecord: (hotkey) => {\n * shortcut.value = hotkey\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n * </script>\n *\n * <template>\n * <div>\n * <button @click=\"recorder.startRecording()\">\n * {{ recorder.isRecording ? 'Recording...' : 'Edit Shortcut' }}\n * </button>\n * <div v-if=\"recorder.recordedHotkey\">\n * Recording: {{ recorder.recordedHotkey }}\n * </div>\n * </div>\n * </template>\n * ```\n */\nexport function useHotkeyRecorder(\n options: MaybeRefOrGetter<HotkeyRecorderOptions>,\n): VueHotkeyRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n const recorder = new HotkeyRecorder(\n resolveRecorderOptions(options, defaultOptions),\n )\n\n // Subscribe to recorder state using useSelector\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const recordedHotkey = useSelector(\n recorder.store,\n (state) => state.recordedHotkey,\n )\n\n const stopWatcher = watch(\n () => resolveRecorderOptions(options, defaultOptions),\n (resolvedOptions) => {\n recorder.setOptions(resolvedOptions)\n },\n { immediate: true },\n )\n\n // Cleanup on unmount\n onUnmounted(() => {\n stopWatcher()\n recorder.destroy()\n })\n\n return {\n isRecording: isRecording as Ref<boolean>,\n recordedHotkey: recordedHotkey as Ref<Hotkey | null>,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n }\n}\n\nfunction resolveRecorderOptions(\n options: MaybeRefOrGetter<HotkeyRecorderOptions>,\n defaultOptions: ReturnType<typeof useDefaultHotkeysOptions>,\n): HotkeyRecorderOptions {\n return {\n ...defaultOptions.hotkeyRecorder,\n ...resolveMaybeRefOrGetter(options),\n } as HotkeyRecorderOptions\n}\n\nfunction resolveMaybeRefOrGetter<T>(value: MaybeRefOrGetter<T>): T {\n return typeof value === 'function' ? (value as () => T)() : unref(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,kBACd,SACmB;CACnB,MAAM,iBAAiBA,yDAA0B;CACjD,MAAM,WAAW,IAAIC,iCACnB,uBAAuB,SAAS,eAAe,CAChD;CAGD,MAAM,mDAA0B,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,sDACJ,SAAS,QACR,UAAU,MAAM,eAClB;CAED,MAAM,mCACE,uBAAuB,SAAS,eAAe,GACpD,oBAAoB;AACnB,WAAS,WAAW,gBAAgB;IAEtC,EAAE,WAAW,MAAM,CACpB;AAGD,4BAAkB;AAChB,eAAa;AACb,WAAS,SAAS;GAClB;AAEF,QAAO;EACQ;EACG;EAChB,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACzC;;AAGH,SAAS,uBACP,SACA,gBACuB;AACvB,QAAO;EACL,GAAG,eAAe;EAClB,GAAG,wBAAwB,QAAQ;EACpC;;AAGH,SAAS,wBAA2B,OAA+B;AACjE,QAAO,OAAO,UAAU,aAAc,OAAmB,kBAAS,MAAM"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
|
|
2
2
|
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
3
3
|
import { onUnmounted, unref, watch } from "vue";
|
|
4
|
-
import {
|
|
4
|
+
import { useSelector } from "@tanstack/vue-store";
|
|
5
5
|
|
|
6
6
|
//#region src/useHotkeyRecorder.ts
|
|
7
7
|
/**
|
|
@@ -48,8 +48,8 @@ import { useStore } from "@tanstack/vue-store";
|
|
|
48
48
|
function useHotkeyRecorder(options) {
|
|
49
49
|
const defaultOptions = useDefaultHotkeysOptions();
|
|
50
50
|
const recorder = new HotkeyRecorder(resolveRecorderOptions(options, defaultOptions));
|
|
51
|
-
const isRecording =
|
|
52
|
-
const recordedHotkey =
|
|
51
|
+
const isRecording = useSelector(recorder.store, (state) => state.isRecording);
|
|
52
|
+
const recordedHotkey = useSelector(recorder.store, (state) => state.recordedHotkey);
|
|
53
53
|
const stopWatcher = watch(() => resolveRecorderOptions(options, defaultOptions), (resolvedOptions) => {
|
|
54
54
|
recorder.setOptions(resolvedOptions);
|
|
55
55
|
}, { immediate: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeyRecorder.js","names":[],"sources":["../src/useHotkeyRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport {
|
|
1
|
+
{"version":3,"file":"useHotkeyRecorder.js","names":[],"sources":["../src/useHotkeyRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport { useSelector } from '@tanstack/vue-store'\nimport { HotkeyRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProviderContext'\nimport type { MaybeRefOrGetter, Ref } from 'vue'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\nexport interface VueHotkeyRecorder {\n /** Whether recording is currently active */\n isRecording: Ref<boolean>\n /** The currently recorded hotkey (for live preview) */\n recordedHotkey: Ref<Hotkey | null>\n /** Start recording a new hotkey */\n startRecording: () => void\n /** Stop recording (same as cancel) */\n stopRecording: () => void\n /** Cancel recording without saving */\n cancelRecording: () => void\n}\n\n/**\n * Vue composable for recording keyboard shortcuts.\n *\n * This composable provides a thin wrapper around the framework-agnostic `HotkeyRecorder`\n * class, managing all the complexity of capturing keyboard events, converting them\n * to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete\n * to clear.\n *\n * @param options - Configuration options for the recorder\n * @returns An object with recording state and control functions\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkeyRecorder } from '@tanstack/vue-hotkeys'\n *\n * const shortcut = ref<Hotkey>('Mod+S')\n *\n * const recorder = useHotkeyRecorder({\n * onRecord: (hotkey) => {\n * shortcut.value = hotkey\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n * </script>\n *\n * <template>\n * <div>\n * <button @click=\"recorder.startRecording()\">\n * {{ recorder.isRecording ? 'Recording...' : 'Edit Shortcut' }}\n * </button>\n * <div v-if=\"recorder.recordedHotkey\">\n * Recording: {{ recorder.recordedHotkey }}\n * </div>\n * </div>\n * </template>\n * ```\n */\nexport function useHotkeyRecorder(\n options: MaybeRefOrGetter<HotkeyRecorderOptions>,\n): VueHotkeyRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n const recorder = new HotkeyRecorder(\n resolveRecorderOptions(options, defaultOptions),\n )\n\n // Subscribe to recorder state using useSelector\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const recordedHotkey = useSelector(\n recorder.store,\n (state) => state.recordedHotkey,\n )\n\n const stopWatcher = watch(\n () => resolveRecorderOptions(options, defaultOptions),\n (resolvedOptions) => {\n recorder.setOptions(resolvedOptions)\n },\n { immediate: true },\n )\n\n // Cleanup on unmount\n onUnmounted(() => {\n stopWatcher()\n recorder.destroy()\n })\n\n return {\n isRecording: isRecording as Ref<boolean>,\n recordedHotkey: recordedHotkey as Ref<Hotkey | null>,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n }\n}\n\nfunction resolveRecorderOptions(\n options: MaybeRefOrGetter<HotkeyRecorderOptions>,\n defaultOptions: ReturnType<typeof useDefaultHotkeysOptions>,\n): HotkeyRecorderOptions {\n return {\n ...defaultOptions.hotkeyRecorder,\n ...resolveMaybeRefOrGetter(options),\n } as HotkeyRecorderOptions\n}\n\nfunction resolveMaybeRefOrGetter<T>(value: MaybeRefOrGetter<T>): T {\n return typeof value === 'function' ? (value as () => T)() : unref(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,kBACd,SACmB;CACnB,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,WAAW,IAAI,eACnB,uBAAuB,SAAS,eAAe,CAChD;CAGD,MAAM,cAAc,YAAY,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,iBAAiB,YACrB,SAAS,QACR,UAAU,MAAM,eAClB;CAED,MAAM,cAAc,YACZ,uBAAuB,SAAS,eAAe,GACpD,oBAAoB;AACnB,WAAS,WAAW,gBAAgB;IAEtC,EAAE,WAAW,MAAM,CACpB;AAGD,mBAAkB;AAChB,eAAa;AACb,WAAS,SAAS;GAClB;AAEF,QAAO;EACQ;EACG;EAChB,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACzC;;AAGH,SAAS,uBACP,SACA,gBACuB;AACvB,QAAO;EACL,GAAG,eAAe;EAClB,GAAG,wBAAwB,QAAQ;EACpC;;AAGH,SAAS,wBAA2B,OAA+B;AACjE,QAAO,OAAO,UAAU,aAAc,OAAmB,GAAG,MAAM,MAAM"}
|
|
@@ -16,8 +16,8 @@ function useHotkeyRegistrations() {
|
|
|
16
16
|
const hotkeyManager = (0, _tanstack_hotkeys.getHotkeyManager)();
|
|
17
17
|
const sequenceManager = (0, _tanstack_hotkeys.getSequenceManager)();
|
|
18
18
|
return {
|
|
19
|
-
hotkeys: (0, _tanstack_vue_store.
|
|
20
|
-
sequences: (0, _tanstack_vue_store.
|
|
19
|
+
hotkeys: (0, _tanstack_vue_store.useSelector)(hotkeyManager.registrations, (state) => Array.from(state.values()).map(_tanstack_hotkeys.toHotkeyRegistrationView)),
|
|
20
|
+
sequences: (0, _tanstack_vue_store.useSelector)(sequenceManager.registrations, (state) => Array.from(state.values()))
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeyRegistrations.cjs","names":["toHotkeyRegistrationView"],"sources":["../src/useHotkeyRegistrations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useHotkeyRegistrations.cjs","names":["toHotkeyRegistrationView"],"sources":["../src/useHotkeyRegistrations.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\nimport type { Ref } from 'vue'\n\n/**\n * Return type for useHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** All registered hotkeys (public view, no callbacks) */\n hotkeys: Ref<Array<HotkeyRegistrationView>>\n /** All registered sequences */\n sequences: Ref<Array<SequenceRegistrationView>>\n}\n\n/**\n * Vue composable that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone composable that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * triggers reactivity when registrations change.\n *\n * @returns Object with `hotkeys` and `sequences` refs\n */\nexport function useHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = useSelector(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = useSelector(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,yBAAoD;CAClE,MAAM,yDAAkC;CACxC,MAAM,6DAAsC;AAU5C,QAAO;EAAE,8CARmB,cAAc,gBAAgB,UACxD,MAAM,KAAK,MAAM,QAAQ,CAAC,CAAC,IAAIA,2CAAyB,CACzD;EAMiB,gDAJY,gBAAgB,gBAAgB,UAC5D,MAAM,KAAK,MAAM,QAAQ,CAAC,CAC3B;EAE4B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from "@tanstack/vue-store";
|
|
3
3
|
|
|
4
4
|
//#region src/useHotkeyRegistrations.ts
|
|
5
5
|
/**
|
|
@@ -16,8 +16,8 @@ function useHotkeyRegistrations() {
|
|
|
16
16
|
const hotkeyManager = getHotkeyManager();
|
|
17
17
|
const sequenceManager = getSequenceManager();
|
|
18
18
|
return {
|
|
19
|
-
hotkeys:
|
|
20
|
-
sequences:
|
|
19
|
+
hotkeys: useSelector(hotkeyManager.registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView)),
|
|
20
|
+
sequences: useSelector(sequenceManager.registrations, (state) => Array.from(state.values()))
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeyRegistrations.js","names":[],"sources":["../src/useHotkeyRegistrations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useHotkeyRegistrations.js","names":[],"sources":["../src/useHotkeyRegistrations.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\nimport type { Ref } from 'vue'\n\n/**\n * Return type for useHotkeyRegistrations.\n */\nexport interface HotkeyRegistrationsResult {\n /** All registered hotkeys (public view, no callbacks) */\n hotkeys: Ref<Array<HotkeyRegistrationView>>\n /** All registered sequences */\n sequences: Ref<Array<SequenceRegistrationView>>\n}\n\n/**\n * Vue composable that reactively reads all hotkey and sequence registrations\n * from the singleton managers.\n *\n * This is a standalone composable that does NOT require the HotkeysProvider.\n * It subscribes to both HotkeyManager and SequenceManager stores and\n * triggers reactivity when registrations change.\n *\n * @returns Object with `hotkeys` and `sequences` refs\n */\nexport function useHotkeyRegistrations(): HotkeyRegistrationsResult {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeys = useSelector(hotkeyManager.registrations, (state) =>\n Array.from(state.values()).map(toHotkeyRegistrationView),\n )\n\n const sequences = useSelector(sequenceManager.registrations, (state) =>\n Array.from(state.values()),\n )\n\n return { hotkeys, sequences }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,yBAAoD;CAClE,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"}
|
|
@@ -10,9 +10,9 @@ let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
|
10
10
|
function useHotkeySequenceRecorder(options) {
|
|
11
11
|
const defaultOptions = require_HotkeysProviderContext.useDefaultHotkeysOptions();
|
|
12
12
|
const recorder = new _tanstack_hotkeys.HotkeySequenceRecorder(resolveHotkeySequenceRecorderOptions(options, defaultOptions));
|
|
13
|
-
const isRecording = (0, _tanstack_vue_store.
|
|
14
|
-
const steps = (0, _tanstack_vue_store.
|
|
15
|
-
const recordedSequence = (0, _tanstack_vue_store.
|
|
13
|
+
const isRecording = (0, _tanstack_vue_store.useSelector)(recorder.store, (state) => state.isRecording);
|
|
14
|
+
const steps = (0, _tanstack_vue_store.useSelector)(recorder.store, (state) => state.steps);
|
|
15
|
+
const recordedSequence = (0, _tanstack_vue_store.useSelector)(recorder.store, (state) => state.recordedSequence);
|
|
16
16
|
const stopWatcher = (0, vue.watch)(() => resolveHotkeySequenceRecorderOptions(options, defaultOptions), (resolvedOptions) => {
|
|
17
17
|
recorder.setOptions(resolvedOptions);
|
|
18
18
|
}, { immediate: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequenceRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeySequenceRecorder"],"sources":["../src/useHotkeySequenceRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport {
|
|
1
|
+
{"version":3,"file":"useHotkeySequenceRecorder.cjs","names":["useDefaultHotkeysOptions","HotkeySequenceRecorder"],"sources":["../src/useHotkeySequenceRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport { useSelector } from '@tanstack/vue-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProviderContext'\nimport type { MaybeRefOrGetter, Ref } from 'vue'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface VueHotkeySequenceRecorder {\n isRecording: Ref<boolean>\n steps: Ref<HotkeySequence>\n recordedSequence: Ref<HotkeySequence | null>\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * Vue composable for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function useHotkeySequenceRecorder(\n options: MaybeRefOrGetter<HotkeySequenceRecorderOptions>,\n): VueHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n const recorder = new HotkeySequenceRecorder(\n resolveHotkeySequenceRecorderOptions(options, defaultOptions),\n )\n\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const steps = useSelector(recorder.store, (state) => state.steps)\n const recordedSequence = useSelector(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n const stopWatcher = watch(\n () => resolveHotkeySequenceRecorderOptions(options, defaultOptions),\n (resolvedOptions) => {\n recorder.setOptions(resolvedOptions)\n },\n { immediate: true },\n )\n\n onUnmounted(() => {\n stopWatcher()\n recorder.destroy()\n })\n\n return {\n isRecording: isRecording as Ref<boolean>,\n steps: steps as Ref<HotkeySequence>,\n recordedSequence: recordedSequence as Ref<HotkeySequence | null>,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n\nfunction resolveHotkeySequenceRecorderOptions(\n options: MaybeRefOrGetter<HotkeySequenceRecorderOptions>,\n defaultOptions: ReturnType<typeof useDefaultHotkeysOptions>,\n): HotkeySequenceRecorderOptions {\n return {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolveMaybeRefOrGetter(options),\n } as HotkeySequenceRecorderOptions\n}\n\nfunction resolveMaybeRefOrGetter<T>(value: MaybeRefOrGetter<T>): T {\n return typeof value === 'function' ? (value as () => T)() : unref(value)\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAgB,0BACd,SAC2B;CAC3B,MAAM,iBAAiBA,yDAA0B;CACjD,MAAM,WAAW,IAAIC,yCACnB,qCAAqC,SAAS,eAAe,CAC9D;CAED,MAAM,mDAA0B,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,6CAAoB,SAAS,QAAQ,UAAU,MAAM,MAAM;CACjE,MAAM,wDACJ,SAAS,QACR,UAAU,MAAM,iBAClB;CAED,MAAM,mCACE,qCAAqC,SAAS,eAAe,GAClE,oBAAoB;AACnB,WAAS,WAAW,gBAAgB;IAEtC,EAAE,WAAW,MAAM,CACpB;AAED,4BAAkB;AAChB,eAAa;AACb,WAAS,SAAS;GAClB;AAEF,QAAO;EACQ;EACN;EACW;EAClB,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC;;AAGH,SAAS,qCACP,SACA,gBAC+B;AAC/B,QAAO;EACL,GAAG,eAAe;EAClB,GAAG,wBAAwB,QAAQ;EACpC;;AAGH,SAAS,wBAA2B,OAA+B;AACjE,QAAO,OAAO,UAAU,aAAc,OAAmB,kBAAS,MAAM"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptions } from "./HotkeysProviderContext.js";
|
|
2
2
|
import { HotkeySequenceRecorder } from "@tanstack/hotkeys";
|
|
3
3
|
import { onUnmounted, unref, watch } from "vue";
|
|
4
|
-
import {
|
|
4
|
+
import { useSelector } from "@tanstack/vue-store";
|
|
5
5
|
|
|
6
6
|
//#region src/useHotkeySequenceRecorder.ts
|
|
7
7
|
/**
|
|
@@ -10,9 +10,9 @@ import { useStore } from "@tanstack/vue-store";
|
|
|
10
10
|
function useHotkeySequenceRecorder(options) {
|
|
11
11
|
const defaultOptions = useDefaultHotkeysOptions();
|
|
12
12
|
const recorder = new HotkeySequenceRecorder(resolveHotkeySequenceRecorderOptions(options, defaultOptions));
|
|
13
|
-
const isRecording =
|
|
14
|
-
const steps =
|
|
15
|
-
const recordedSequence =
|
|
13
|
+
const isRecording = useSelector(recorder.store, (state) => state.isRecording);
|
|
14
|
+
const steps = useSelector(recorder.store, (state) => state.steps);
|
|
15
|
+
const recordedSequence = useSelector(recorder.store, (state) => state.recordedSequence);
|
|
16
16
|
const stopWatcher = watch(() => resolveHotkeySequenceRecorderOptions(options, defaultOptions), (resolvedOptions) => {
|
|
17
17
|
recorder.setOptions(resolvedOptions);
|
|
18
18
|
}, { immediate: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkeySequenceRecorder.js","names":[],"sources":["../src/useHotkeySequenceRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport {
|
|
1
|
+
{"version":3,"file":"useHotkeySequenceRecorder.js","names":[],"sources":["../src/useHotkeySequenceRecorder.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport { useSelector } from '@tanstack/vue-store'\nimport { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProviderContext'\nimport type { MaybeRefOrGetter, Ref } from 'vue'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\nexport interface VueHotkeySequenceRecorder {\n isRecording: Ref<boolean>\n steps: Ref<HotkeySequence>\n recordedSequence: Ref<HotkeySequence | null>\n startRecording: () => void\n stopRecording: () => void\n cancelRecording: () => void\n commitRecording: () => void\n}\n\n/**\n * Vue composable for recording multi-chord sequences (Vim-style shortcuts).\n */\nexport function useHotkeySequenceRecorder(\n options: MaybeRefOrGetter<HotkeySequenceRecorderOptions>,\n): VueHotkeySequenceRecorder {\n const defaultOptions = useDefaultHotkeysOptions()\n const recorder = new HotkeySequenceRecorder(\n resolveHotkeySequenceRecorderOptions(options, defaultOptions),\n )\n\n const isRecording = useSelector(recorder.store, (state) => state.isRecording)\n const steps = useSelector(recorder.store, (state) => state.steps)\n const recordedSequence = useSelector(\n recorder.store,\n (state) => state.recordedSequence,\n )\n\n const stopWatcher = watch(\n () => resolveHotkeySequenceRecorderOptions(options, defaultOptions),\n (resolvedOptions) => {\n recorder.setOptions(resolvedOptions)\n },\n { immediate: true },\n )\n\n onUnmounted(() => {\n stopWatcher()\n recorder.destroy()\n })\n\n return {\n isRecording: isRecording as Ref<boolean>,\n steps: steps as Ref<HotkeySequence>,\n recordedSequence: recordedSequence as Ref<HotkeySequence | null>,\n startRecording: () => recorder.start(),\n stopRecording: () => recorder.stop(),\n cancelRecording: () => recorder.cancel(),\n commitRecording: () => recorder.commit(),\n }\n}\n\nfunction resolveHotkeySequenceRecorderOptions(\n options: MaybeRefOrGetter<HotkeySequenceRecorderOptions>,\n defaultOptions: ReturnType<typeof useDefaultHotkeysOptions>,\n): HotkeySequenceRecorderOptions {\n return {\n ...defaultOptions.hotkeySequenceRecorder,\n ...resolveMaybeRefOrGetter(options),\n } as HotkeySequenceRecorderOptions\n}\n\nfunction resolveMaybeRefOrGetter<T>(value: MaybeRefOrGetter<T>): T {\n return typeof value === 'function' ? (value as () => T)() : unref(value)\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAgB,0BACd,SAC2B;CAC3B,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,WAAW,IAAI,uBACnB,qCAAqC,SAAS,eAAe,CAC9D;CAED,MAAM,cAAc,YAAY,SAAS,QAAQ,UAAU,MAAM,YAAY;CAC7E,MAAM,QAAQ,YAAY,SAAS,QAAQ,UAAU,MAAM,MAAM;CACjE,MAAM,mBAAmB,YACvB,SAAS,QACR,UAAU,MAAM,iBAClB;CAED,MAAM,cAAc,YACZ,qCAAqC,SAAS,eAAe,GAClE,oBAAoB;AACnB,WAAS,WAAW,gBAAgB;IAEtC,EAAE,WAAW,MAAM,CACpB;AAED,mBAAkB;AAChB,eAAa;AACb,WAAS,SAAS;GAClB;AAEF,QAAO;EACQ;EACN;EACW;EAClB,sBAAsB,SAAS,OAAO;EACtC,qBAAqB,SAAS,MAAM;EACpC,uBAAuB,SAAS,QAAQ;EACxC,uBAAuB,SAAS,QAAQ;EACzC;;AAGH,SAAS,qCACP,SACA,gBAC+B;AAC/B,QAAO;EACL,GAAG,eAAe;EAClB,GAAG,wBAAwB,QAAQ;EACpC;;AAGH,SAAS,wBAA2B,OAA+B;AACjE,QAAO,OAAO,UAAU,aAAc,OAAmB,GAAG,MAAM,MAAM"}
|
package/dist/useKeyHold.cjs
CHANGED
|
@@ -6,7 +6,7 @@ let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
|
6
6
|
/**
|
|
7
7
|
* Vue composable that returns a reactive ref indicating whether a specific key is currently being held.
|
|
8
8
|
*
|
|
9
|
-
* This composable uses `
|
|
9
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
10
10
|
* to the global KeyStateTracker and uses a selector to determine if
|
|
11
11
|
* the specified key is held.
|
|
12
12
|
*
|
|
@@ -48,7 +48,7 @@ let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
function useKeyHold(key) {
|
|
51
|
-
return (0, _tanstack_vue_store.
|
|
51
|
+
return (0, _tanstack_vue_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => {
|
|
52
52
|
const keyValue = (0, vue.unref)(key);
|
|
53
53
|
const normalizedKey = (typeof keyValue === "string" ? keyValue : String(keyValue)).toLowerCase();
|
|
54
54
|
return state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey);
|
package/dist/useKeyHold.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useKeyHold.cjs","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useKeyHold.cjs","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport { unref } from 'vue'\nimport type { MaybeRefOrGetter, Ref } from 'vue'\nimport type { IndividualKey } from '@tanstack/hotkeys'\n\n/**\n * Vue composable that returns a reactive ref indicating whether a specific key is currently being held.\n *\n * This composable uses `useSelector` from `@tanstack/vue-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if\n * the specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A')\n * @returns Reactive ref that is true if the key is currently held down\n *\n * @example\n * ```vue\n * <script setup>\n * import { useKeyHold } from '@tanstack/vue-hotkeys'\n *\n * const isShiftHeld = useKeyHold('Shift')\n * </script>\n *\n * <template>\n * <div :style=\"{ opacity: isShiftHeld ? 1 : 0.5 }\">\n * {{ isShiftHeld ? 'Shift is pressed!' : 'Press Shift' }}\n * </div>\n * </template>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { useKeyHold } from '@tanstack/vue-hotkeys'\n *\n * const ctrl = useKeyHold('Control')\n * const shift = useKeyHold('Shift')\n * const alt = useKeyHold('Alt')\n * </script>\n *\n * <template>\n * <div>\n * <span :style=\"{ opacity: ctrl ? 1 : 0.3 }\">Ctrl</span>\n * <span :style=\"{ opacity: shift ? 1 : 0.3 }\">Shift</span>\n * <span :style=\"{ opacity: alt ? 1 : 0.3 }\">Alt</span>\n * </div>\n * </template>\n * ```\n */\nexport function useKeyHold(key: MaybeRefOrGetter<IndividualKey>): Ref<boolean> {\n const tracker = getKeyStateTracker()\n\n const isHeld = useSelector(tracker.store, (state) => {\n const keyValue = unref(key)\n const normalizedKey = (\n typeof keyValue === 'string' ? keyValue : String(keyValue)\n ).toLowerCase()\n return state.heldKeys.some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n\n return isHeld as Ref<boolean>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,WAAW,KAAoD;AAa7E,wFAZoC,CAED,QAAQ,UAAU;EACnD,MAAM,0BAAiB,IAAI;EAC3B,MAAM,iBACJ,OAAO,aAAa,WAAW,WAAW,OAAO,SAAS,EAC1D,aAAa;AACf,SAAO,MAAM,SAAS,MACnB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
package/dist/useKeyHold.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ import { MaybeRefOrGetter, Ref } from "vue";
|
|
|
5
5
|
/**
|
|
6
6
|
* Vue composable that returns a reactive ref indicating whether a specific key is currently being held.
|
|
7
7
|
*
|
|
8
|
-
* This composable uses `
|
|
8
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
9
9
|
* to the global KeyStateTracker and uses a selector to determine if
|
|
10
10
|
* the specified key is held.
|
|
11
11
|
*
|
package/dist/useKeyHold.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { MaybeRefOrGetter, Ref } from "vue";
|
|
|
5
5
|
/**
|
|
6
6
|
* Vue composable that returns a reactive ref indicating whether a specific key is currently being held.
|
|
7
7
|
*
|
|
8
|
-
* This composable uses `
|
|
8
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
9
9
|
* to the global KeyStateTracker and uses a selector to determine if
|
|
10
10
|
* the specified key is held.
|
|
11
11
|
*
|
package/dist/useKeyHold.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
2
|
import { unref } from "vue";
|
|
3
|
-
import {
|
|
3
|
+
import { useSelector } from "@tanstack/vue-store";
|
|
4
4
|
|
|
5
5
|
//#region src/useKeyHold.ts
|
|
6
6
|
/**
|
|
7
7
|
* Vue composable that returns a reactive ref indicating whether a specific key is currently being held.
|
|
8
8
|
*
|
|
9
|
-
* This composable uses `
|
|
9
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
10
10
|
* to the global KeyStateTracker and uses a selector to determine if
|
|
11
11
|
* the specified key is held.
|
|
12
12
|
*
|
|
@@ -48,7 +48,7 @@ import { useStore } from "@tanstack/vue-store";
|
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
function useKeyHold(key) {
|
|
51
|
-
return
|
|
51
|
+
return useSelector(getKeyStateTracker().store, (state) => {
|
|
52
52
|
const keyValue = unref(key);
|
|
53
53
|
const normalizedKey = (typeof keyValue === "string" ? keyValue : String(keyValue)).toLowerCase();
|
|
54
54
|
return state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey);
|
package/dist/useKeyHold.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useKeyHold.js","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useKeyHold.js","names":[],"sources":["../src/useKeyHold.ts"],"sourcesContent":["import { useSelector } from '@tanstack/vue-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport { unref } from 'vue'\nimport type { MaybeRefOrGetter, Ref } from 'vue'\nimport type { IndividualKey } from '@tanstack/hotkeys'\n\n/**\n * Vue composable that returns a reactive ref indicating whether a specific key is currently being held.\n *\n * This composable uses `useSelector` from `@tanstack/vue-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if\n * the specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A')\n * @returns Reactive ref that is true if the key is currently held down\n *\n * @example\n * ```vue\n * <script setup>\n * import { useKeyHold } from '@tanstack/vue-hotkeys'\n *\n * const isShiftHeld = useKeyHold('Shift')\n * </script>\n *\n * <template>\n * <div :style=\"{ opacity: isShiftHeld ? 1 : 0.5 }\">\n * {{ isShiftHeld ? 'Shift is pressed!' : 'Press Shift' }}\n * </div>\n * </template>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { useKeyHold } from '@tanstack/vue-hotkeys'\n *\n * const ctrl = useKeyHold('Control')\n * const shift = useKeyHold('Shift')\n * const alt = useKeyHold('Alt')\n * </script>\n *\n * <template>\n * <div>\n * <span :style=\"{ opacity: ctrl ? 1 : 0.3 }\">Ctrl</span>\n * <span :style=\"{ opacity: shift ? 1 : 0.3 }\">Shift</span>\n * <span :style=\"{ opacity: alt ? 1 : 0.3 }\">Alt</span>\n * </div>\n * </template>\n * ```\n */\nexport function useKeyHold(key: MaybeRefOrGetter<IndividualKey>): Ref<boolean> {\n const tracker = getKeyStateTracker()\n\n const isHeld = useSelector(tracker.store, (state) => {\n const keyValue = unref(key)\n const normalizedKey = (\n typeof keyValue === 'string' ? keyValue : String(keyValue)\n ).toLowerCase()\n return state.heldKeys.some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n\n return isHeld as Ref<boolean>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,WAAW,KAAoD;AAa7E,QAVe,YAFC,oBAAoB,CAED,QAAQ,UAAU;EACnD,MAAM,WAAW,MAAM,IAAI;EAC3B,MAAM,iBACJ,OAAO,aAAa,WAAW,WAAW,OAAO,SAAS,EAC1D,aAAa;AACf,SAAO,MAAM,SAAS,MACnB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Vue adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"src"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@tanstack/vue-store": "^0.
|
|
46
|
-
"@tanstack/hotkeys": "0.
|
|
45
|
+
"@tanstack/vue-store": "^0.11.0",
|
|
46
|
+
"@tanstack/hotkeys": "0.9.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
50
|
-
"@vue/test-utils": "^2.4.
|
|
51
|
-
"vue": "^3.5.
|
|
49
|
+
"@vitejs/plugin-vue": "^6.0.6",
|
|
50
|
+
"@vue/test-utils": "^2.4.8",
|
|
51
|
+
"vue": "^3.5.33"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"vue": ">=3.0.0"
|
package/src/index.ts
CHANGED
package/src/useHeldKeyCodes.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSelector } from '@tanstack/vue-store'
|
|
2
2
|
import { getKeyStateTracker } from '@tanstack/hotkeys'
|
|
3
3
|
import type { Ref } from 'vue'
|
|
4
4
|
|
|
@@ -30,5 +30,5 @@ import type { Ref } from 'vue'
|
|
|
30
30
|
*/
|
|
31
31
|
export function useHeldKeyCodes(): Ref<Record<string, string>> {
|
|
32
32
|
const tracker = getKeyStateTracker()
|
|
33
|
-
return
|
|
33
|
+
return useSelector(tracker.store, (state) => state.heldCodes)
|
|
34
34
|
}
|
package/src/useHeldKeys.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSelector } from '@tanstack/vue-store'
|
|
2
2
|
import { getKeyStateTracker } from '@tanstack/hotkeys'
|
|
3
3
|
import type { Ref } from 'vue'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Vue composable that returns a reactive ref of currently held keyboard keys.
|
|
7
7
|
*
|
|
8
|
-
* This composable uses `
|
|
8
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
9
9
|
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
10
|
* or released.
|
|
11
11
|
*
|
|
@@ -28,5 +28,5 @@ import type { Ref } from 'vue'
|
|
|
28
28
|
*/
|
|
29
29
|
export function useHeldKeys(): Ref<Array<string>> {
|
|
30
30
|
const tracker = getKeyStateTracker()
|
|
31
|
-
return
|
|
31
|
+
return useSelector(tracker.store, (state) => state.heldKeys)
|
|
32
32
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { computed, toValue } from 'vue'
|
|
2
|
+
import { useSelector } from '@tanstack/vue-store'
|
|
3
|
+
import { getKeyStateTracker, matchesHeldModifiers } from '@tanstack/hotkeys'
|
|
4
|
+
import type { ComputedRef, MaybeRefOrGetter } from 'vue'
|
|
5
|
+
import type { HeldModifierOptions, RegisterableHotkey } from '@tanstack/hotkeys'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns a computed ref indicating whether held modifiers reveal this shortcut.
|
|
9
|
+
* Pass refs or getters to track changing bindings and options.
|
|
10
|
+
* Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
|
|
11
|
+
* every modifier. Combine with the action's enabled state before showing a badge.
|
|
12
|
+
* This helper does not register a shortcut or check whether its target is focused.
|
|
13
|
+
*/
|
|
14
|
+
export function useHotkeyHint(
|
|
15
|
+
hotkey: MaybeRefOrGetter<RegisterableHotkey>,
|
|
16
|
+
options: MaybeRefOrGetter<HeldModifierOptions> = {},
|
|
17
|
+
): ComputedRef<boolean> {
|
|
18
|
+
const held = useSelector(
|
|
19
|
+
getKeyStateTracker().store,
|
|
20
|
+
(state) => state.heldKeys,
|
|
21
|
+
)
|
|
22
|
+
return computed(() =>
|
|
23
|
+
matchesHeldModifiers(toValue(hotkey), held.value, toValue(options)),
|
|
24
|
+
)
|
|
25
|
+
}
|
package/src/useHotkeyRecorder.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { onUnmounted, unref, watch } from 'vue'
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from '@tanstack/vue-store'
|
|
3
3
|
import { HotkeyRecorder } from '@tanstack/hotkeys'
|
|
4
4
|
import { useDefaultHotkeysOptions } from './HotkeysProviderContext'
|
|
5
5
|
import type { MaybeRefOrGetter, Ref } from 'vue'
|
|
@@ -67,9 +67,9 @@ export function useHotkeyRecorder(
|
|
|
67
67
|
resolveRecorderOptions(options, defaultOptions),
|
|
68
68
|
)
|
|
69
69
|
|
|
70
|
-
// Subscribe to recorder state using
|
|
71
|
-
const isRecording =
|
|
72
|
-
const recordedHotkey =
|
|
70
|
+
// Subscribe to recorder state using useSelector
|
|
71
|
+
const isRecording = useSelector(recorder.store, (state) => state.isRecording)
|
|
72
|
+
const recordedHotkey = useSelector(
|
|
73
73
|
recorder.store,
|
|
74
74
|
(state) => state.recordedHotkey,
|
|
75
75
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSelector } from '@tanstack/vue-store'
|
|
2
2
|
import {
|
|
3
3
|
getHotkeyManager,
|
|
4
4
|
getSequenceManager,
|
|
@@ -34,11 +34,11 @@ export function useHotkeyRegistrations(): HotkeyRegistrationsResult {
|
|
|
34
34
|
const hotkeyManager = getHotkeyManager()
|
|
35
35
|
const sequenceManager = getSequenceManager()
|
|
36
36
|
|
|
37
|
-
const hotkeys =
|
|
37
|
+
const hotkeys = useSelector(hotkeyManager.registrations, (state) =>
|
|
38
38
|
Array.from(state.values()).map(toHotkeyRegistrationView),
|
|
39
39
|
)
|
|
40
40
|
|
|
41
|
-
const sequences =
|
|
41
|
+
const sequences = useSelector(sequenceManager.registrations, (state) =>
|
|
42
42
|
Array.from(state.values()),
|
|
43
43
|
)
|
|
44
44
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { onUnmounted, unref, watch } from 'vue'
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from '@tanstack/vue-store'
|
|
3
3
|
import { HotkeySequenceRecorder } from '@tanstack/hotkeys'
|
|
4
4
|
import { useDefaultHotkeysOptions } from './HotkeysProviderContext'
|
|
5
5
|
import type { MaybeRefOrGetter, Ref } from 'vue'
|
|
@@ -29,9 +29,9 @@ export function useHotkeySequenceRecorder(
|
|
|
29
29
|
resolveHotkeySequenceRecorderOptions(options, defaultOptions),
|
|
30
30
|
)
|
|
31
31
|
|
|
32
|
-
const isRecording =
|
|
33
|
-
const steps =
|
|
34
|
-
const recordedSequence =
|
|
32
|
+
const isRecording = useSelector(recorder.store, (state) => state.isRecording)
|
|
33
|
+
const steps = useSelector(recorder.store, (state) => state.steps)
|
|
34
|
+
const recordedSequence = useSelector(
|
|
35
35
|
recorder.store,
|
|
36
36
|
(state) => state.recordedSequence,
|
|
37
37
|
)
|
package/src/useKeyHold.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSelector } from '@tanstack/vue-store'
|
|
2
2
|
import { getKeyStateTracker } from '@tanstack/hotkeys'
|
|
3
3
|
import { unref } from 'vue'
|
|
4
4
|
import type { MaybeRefOrGetter, Ref } from 'vue'
|
|
@@ -7,7 +7,7 @@ import type { IndividualKey } from '@tanstack/hotkeys'
|
|
|
7
7
|
/**
|
|
8
8
|
* Vue composable that returns a reactive ref indicating whether a specific key is currently being held.
|
|
9
9
|
*
|
|
10
|
-
* This composable uses `
|
|
10
|
+
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
11
11
|
* to the global KeyStateTracker and uses a selector to determine if
|
|
12
12
|
* the specified key is held.
|
|
13
13
|
*
|
|
@@ -51,7 +51,7 @@ import type { IndividualKey } from '@tanstack/hotkeys'
|
|
|
51
51
|
export function useKeyHold(key: MaybeRefOrGetter<IndividualKey>): Ref<boolean> {
|
|
52
52
|
const tracker = getKeyStateTracker()
|
|
53
53
|
|
|
54
|
-
const isHeld =
|
|
54
|
+
const isHeld = useSelector(tracker.store, (state) => {
|
|
55
55
|
const keyValue = unref(key)
|
|
56
56
|
const normalizedKey = (
|
|
57
57
|
typeof keyValue === 'string' ? keyValue : String(keyValue)
|