@tanstack/vue-hotkeys 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/HotkeysProvider.d.ts +5 -9
- package/dist/HotkeysProvider.js +1 -2
- package/dist/HotkeysProviderContext.d.ts +5 -8
- package/dist/HotkeysProviderContext.js +1 -2
- package/dist/useHeldKeyCodes.d.ts +2 -5
- package/dist/useHeldKeyCodes.js +3 -3
- package/dist/useHeldKeys.d.ts +2 -5
- package/dist/useHeldKeys.js +3 -3
- package/dist/useHotkey.d.ts +3 -6
- package/dist/useHotkey.js +3 -3
- package/dist/useHotkeyHint.d.ts +2 -5
- package/dist/useHotkeyHint.js +1 -2
- package/dist/useHotkeyRecorder.d.ts +3 -6
- package/dist/useHotkeyRecorder.js +1 -2
- package/dist/useHotkeyRegistrations.d.ts +3 -6
- package/dist/useHotkeyRegistrations.js +1 -2
- package/dist/useHotkeySequence.d.ts +3 -6
- package/dist/useHotkeySequence.js +1 -2
- package/dist/useHotkeySequenceRecorder.d.ts +3 -6
- package/dist/useHotkeySequenceRecorder.js +1 -2
- package/dist/useHotkeySequences.d.ts +3 -6
- package/dist/useHotkeySequences.js +1 -2
- package/dist/useHotkeys.d.ts +3 -6
- package/dist/useHotkeys.js +3 -3
- package/dist/useKeyHold.d.ts +2 -5
- package/dist/useKeyHold.js +3 -3
- package/package.json +12 -17
- package/dist/HotkeysProvider.cjs +0 -31
- package/dist/HotkeysProvider.cjs.map +0 -1
- package/dist/HotkeysProvider.d.cts +0 -34
- package/dist/HotkeysProvider.js.map +0 -1
- package/dist/HotkeysProviderContext.cjs +0 -20
- package/dist/HotkeysProviderContext.cjs.map +0 -1
- package/dist/HotkeysProviderContext.d.cts +0 -20
- package/dist/HotkeysProviderContext.js.map +0 -1
- package/dist/index.cjs +0 -37
- package/dist/index.d.cts +0 -15
- package/dist/useHeldKeyCodes.cjs +0 -37
- package/dist/useHeldKeyCodes.cjs.map +0 -1
- package/dist/useHeldKeyCodes.d.cts +0 -33
- package/dist/useHeldKeyCodes.js.map +0 -1
- package/dist/useHeldKeys.cjs +0 -35
- package/dist/useHeldKeys.cjs.map +0 -1
- package/dist/useHeldKeys.d.cts +0 -31
- package/dist/useHeldKeys.js.map +0 -1
- package/dist/useHotkey.cjs +0 -140
- package/dist/useHotkey.cjs.map +0 -1
- package/dist/useHotkey.d.cts +0 -86
- package/dist/useHotkey.js.map +0 -1
- package/dist/useHotkeyHint.cjs +0 -20
- package/dist/useHotkeyHint.cjs.map +0 -1
- package/dist/useHotkeyHint.d.cts +0 -15
- package/dist/useHotkeyHint.js.map +0 -1
- package/dist/useHotkeyRecorder.cjs +0 -80
- package/dist/useHotkeyRecorder.cjs.map +0 -1
- package/dist/useHotkeyRecorder.d.cts +0 -61
- package/dist/useHotkeyRecorder.js.map +0 -1
- package/dist/useHotkeyRegistrations.cjs +0 -26
- package/dist/useHotkeyRegistrations.cjs.map +0 -1
- package/dist/useHotkeyRegistrations.d.cts +0 -27
- package/dist/useHotkeyRegistrations.js.map +0 -1
- package/dist/useHotkeySequence.cjs +0 -122
- package/dist/useHotkeySequence.cjs.map +0 -1
- package/dist/useHotkeySequence.d.cts +0 -68
- package/dist/useHotkeySequence.js.map +0 -1
- package/dist/useHotkeySequenceRecorder.cjs +0 -45
- package/dist/useHotkeySequenceRecorder.cjs.map +0 -1
- package/dist/useHotkeySequenceRecorder.d.cts +0 -20
- package/dist/useHotkeySequenceRecorder.js.map +0 -1
- package/dist/useHotkeySequences.cjs +0 -140
- package/dist/useHotkeySequences.cjs.map +0 -1
- package/dist/useHotkeySequences.d.cts +0 -64
- package/dist/useHotkeySequences.js.map +0 -1
- package/dist/useHotkeys.cjs +0 -139
- package/dist/useHotkeys.cjs.map +0 -1
- package/dist/useHotkeys.d.cts +0 -65
- package/dist/useHotkeys.js.map +0 -1
- package/dist/useKeyHold.cjs +0 -60
- package/dist/useKeyHold.cjs.map +0 -1
- package/dist/useKeyHold.d.cts +0 -52
- package/dist/useKeyHold.js.map +0 -1
- package/src/HotkeysProvider.tsx +0 -29
- package/src/HotkeysProviderContext.ts +0 -41
- package/src/index.ts +0 -19
- package/src/useHeldKeyCodes.ts +0 -34
- package/src/useHeldKeys.ts +0 -32
- package/src/useHotkey.ts +0 -213
- package/src/useHotkeyHint.ts +0 -25
- package/src/useHotkeyRecorder.ts +0 -112
- package/src/useHotkeyRegistrations.ts +0 -46
- package/src/useHotkeySequence.ts +0 -187
- package/src/useHotkeySequenceRecorder.ts +0 -75
- package/src/useHotkeySequences.ts +0 -221
- package/src/useHotkeys.ts +0 -221
- package/src/useKeyHold.ts +0 -65
- package/src/vue.d.ts +0 -6
package/dist/index.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_HotkeysProviderContext = require('./HotkeysProviderContext.cjs');
|
|
3
|
-
const require_HotkeysProvider = require('./HotkeysProvider.cjs');
|
|
4
|
-
const require_useHotkey = require('./useHotkey.cjs');
|
|
5
|
-
const require_useHotkeys = require('./useHotkeys.cjs');
|
|
6
|
-
const require_useHeldKeys = require('./useHeldKeys.cjs');
|
|
7
|
-
const require_useHeldKeyCodes = require('./useHeldKeyCodes.cjs');
|
|
8
|
-
const require_useKeyHold = require('./useKeyHold.cjs');
|
|
9
|
-
const require_useHotkeySequence = require('./useHotkeySequence.cjs');
|
|
10
|
-
const require_useHotkeySequences = require('./useHotkeySequences.cjs');
|
|
11
|
-
const require_useHotkeyRecorder = require('./useHotkeyRecorder.cjs');
|
|
12
|
-
const require_useHotkeyRegistrations = require('./useHotkeyRegistrations.cjs');
|
|
13
|
-
const require_useHotkeySequenceRecorder = require('./useHotkeySequenceRecorder.cjs');
|
|
14
|
-
const require_useHotkeyHint = require('./useHotkeyHint.cjs');
|
|
15
|
-
|
|
16
|
-
exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
|
|
17
|
-
exports.provideHotkeysContext = require_HotkeysProviderContext.provideHotkeysContext;
|
|
18
|
-
exports.useDefaultHotkeysOptions = require_HotkeysProviderContext.useDefaultHotkeysOptions;
|
|
19
|
-
exports.useHeldKeyCodes = require_useHeldKeyCodes.useHeldKeyCodes;
|
|
20
|
-
exports.useHeldKeys = require_useHeldKeys.useHeldKeys;
|
|
21
|
-
exports.useHotkey = require_useHotkey.useHotkey;
|
|
22
|
-
exports.useHotkeyHint = require_useHotkeyHint.useHotkeyHint;
|
|
23
|
-
exports.useHotkeyRecorder = require_useHotkeyRecorder.useHotkeyRecorder;
|
|
24
|
-
exports.useHotkeyRegistrations = require_useHotkeyRegistrations.useHotkeyRegistrations;
|
|
25
|
-
exports.useHotkeySequence = require_useHotkeySequence.useHotkeySequence;
|
|
26
|
-
exports.useHotkeySequenceRecorder = require_useHotkeySequenceRecorder.useHotkeySequenceRecorder;
|
|
27
|
-
exports.useHotkeySequences = require_useHotkeySequences.useHotkeySequences;
|
|
28
|
-
exports.useHotkeys = require_useHotkeys.useHotkeys;
|
|
29
|
-
exports.useHotkeysContext = require_HotkeysProviderContext.useHotkeysContext;
|
|
30
|
-
exports.useKeyHold = require_useKeyHold.useKeyHold;
|
|
31
|
-
var _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
32
|
-
Object.keys(_tanstack_hotkeys).forEach(function (k) {
|
|
33
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () { return _tanstack_hotkeys[k]; }
|
|
36
|
-
});
|
|
37
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { UseHotkeyOptions, useHotkey } from "./useHotkey.cjs";
|
|
2
|
-
import { UseHotkeySequenceOptions, useHotkeySequence } from "./useHotkeySequence.cjs";
|
|
3
|
-
import { HotkeysProviderOptions, provideHotkeysContext, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProviderContext.cjs";
|
|
4
|
-
import { HotkeysProvider } from "./HotkeysProvider.cjs";
|
|
5
|
-
import { UseHotkeyDefinition, useHotkeys } from "./useHotkeys.cjs";
|
|
6
|
-
import { useHeldKeys } from "./useHeldKeys.cjs";
|
|
7
|
-
import { useHeldKeyCodes } from "./useHeldKeyCodes.cjs";
|
|
8
|
-
import { useKeyHold } from "./useKeyHold.cjs";
|
|
9
|
-
import { UseHotkeySequenceDefinition, useHotkeySequences } from "./useHotkeySequences.cjs";
|
|
10
|
-
import { VueHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.cjs";
|
|
11
|
-
import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.cjs";
|
|
12
|
-
import { VueHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.cjs";
|
|
13
|
-
import { useHotkeyHint } from "./useHotkeyHint.cjs";
|
|
14
|
-
export * from "@tanstack/hotkeys";
|
|
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/useHeldKeyCodes.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
-
let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
3
|
-
|
|
4
|
-
//#region src/useHeldKeyCodes.ts
|
|
5
|
-
/**
|
|
6
|
-
* Vue composable that returns a reactive ref mapping currently held key names to their physical `event.code` values.
|
|
7
|
-
*
|
|
8
|
-
* This is useful for debugging which physical key was pressed (e.g. distinguishing
|
|
9
|
-
* left vs right Shift via "ShiftLeft" / "ShiftRight").
|
|
10
|
-
*
|
|
11
|
-
* @returns Reactive ref containing record mapping normalized key names to their `event.code` values
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```vue
|
|
15
|
-
* <script setup>
|
|
16
|
-
* import { useHeldKeys, useHeldKeyCodes } from '@tanstack/vue-hotkeys'
|
|
17
|
-
*
|
|
18
|
-
* const heldKeys = useHeldKeys()
|
|
19
|
-
* const heldCodes = useHeldKeyCodes()
|
|
20
|
-
* <\/script>
|
|
21
|
-
*
|
|
22
|
-
* <template>
|
|
23
|
-
* <div>
|
|
24
|
-
* <kbd v-for="key in heldKeys" :key="key">
|
|
25
|
-
* {{ key }} <small>{{ heldCodes[key] }}</small>
|
|
26
|
-
* </kbd>
|
|
27
|
-
* </div>
|
|
28
|
-
* </template>
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
function useHeldKeyCodes() {
|
|
32
|
-
return (0, _tanstack_vue_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldCodes);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
exports.useHeldKeyCodes = useHeldKeyCodes;
|
|
37
|
-
//# sourceMappingURL=useHeldKeyCodes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Ref } from "vue";
|
|
2
|
-
|
|
3
|
-
//#region src/useHeldKeyCodes.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Vue composable that returns a reactive ref mapping currently held key names to their physical `event.code` values.
|
|
6
|
-
*
|
|
7
|
-
* This is useful for debugging which physical key was pressed (e.g. distinguishing
|
|
8
|
-
* left vs right Shift via "ShiftLeft" / "ShiftRight").
|
|
9
|
-
*
|
|
10
|
-
* @returns Reactive ref containing record mapping normalized key names to their `event.code` values
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```vue
|
|
14
|
-
* <script setup>
|
|
15
|
-
* import { useHeldKeys, useHeldKeyCodes } from '@tanstack/vue-hotkeys'
|
|
16
|
-
*
|
|
17
|
-
* const heldKeys = useHeldKeys()
|
|
18
|
-
* const heldCodes = useHeldKeyCodes()
|
|
19
|
-
* </script>
|
|
20
|
-
*
|
|
21
|
-
* <template>
|
|
22
|
-
* <div>
|
|
23
|
-
* <kbd v-for="key in heldKeys" :key="key">
|
|
24
|
-
* {{ key }} <small>{{ heldCodes[key] }}</small>
|
|
25
|
-
* </kbd>
|
|
26
|
-
* </div>
|
|
27
|
-
* </template>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare function useHeldKeyCodes(): Ref<Record<string, string>>;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { useHeldKeyCodes };
|
|
33
|
-
//# sourceMappingURL=useHeldKeyCodes.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
-
let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
3
|
-
|
|
4
|
-
//#region src/useHeldKeys.ts
|
|
5
|
-
/**
|
|
6
|
-
* Vue composable that returns a reactive ref of currently held keyboard keys.
|
|
7
|
-
*
|
|
8
|
-
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
9
|
-
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
10
|
-
* or released.
|
|
11
|
-
*
|
|
12
|
-
* @returns Reactive ref containing array of currently held key names
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```vue
|
|
16
|
-
* <script setup>
|
|
17
|
-
* import { useHeldKeys } from '@tanstack/vue-hotkeys'
|
|
18
|
-
*
|
|
19
|
-
* const heldKeys = useHeldKeys()
|
|
20
|
-
* <\/script>
|
|
21
|
-
*
|
|
22
|
-
* <template>
|
|
23
|
-
* <div>
|
|
24
|
-
* Currently pressed: {{ heldKeys.join(' + ') || 'None' }}
|
|
25
|
-
* </div>
|
|
26
|
-
* </template>
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
function useHeldKeys() {
|
|
30
|
-
return (0, _tanstack_vue_store.useSelector)((0, _tanstack_hotkeys.getKeyStateTracker)().store, (state) => state.heldKeys);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
exports.useHeldKeys = useHeldKeys;
|
|
35
|
-
//# sourceMappingURL=useHeldKeys.cjs.map
|
package/dist/useHeldKeys.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Ref } from "vue";
|
|
2
|
-
|
|
3
|
-
//#region src/useHeldKeys.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Vue composable that returns a reactive ref of currently held keyboard keys.
|
|
6
|
-
*
|
|
7
|
-
* This composable uses `useSelector` from `@tanstack/vue-store` to subscribe
|
|
8
|
-
* to the global KeyStateTracker and updates whenever keys are pressed
|
|
9
|
-
* or released.
|
|
10
|
-
*
|
|
11
|
-
* @returns Reactive ref containing array of currently held key names
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```vue
|
|
15
|
-
* <script setup>
|
|
16
|
-
* import { useHeldKeys } from '@tanstack/vue-hotkeys'
|
|
17
|
-
*
|
|
18
|
-
* const heldKeys = useHeldKeys()
|
|
19
|
-
* </script>
|
|
20
|
-
*
|
|
21
|
-
* <template>
|
|
22
|
-
* <div>
|
|
23
|
-
* Currently pressed: {{ heldKeys.join(' + ') || 'None' }}
|
|
24
|
-
* </div>
|
|
25
|
-
* </template>
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare function useHeldKeys(): Ref<Array<string>>;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { useHeldKeys };
|
|
31
|
-
//# sourceMappingURL=useHeldKeys.d.cts.map
|
package/dist/useHeldKeys.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/useHotkey.cjs
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProviderContext = require('./HotkeysProviderContext.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let vue = require("vue");
|
|
4
|
-
|
|
5
|
-
//#region src/useHotkey.ts
|
|
6
|
-
/**
|
|
7
|
-
* Vue composable for registering a keyboard hotkey.
|
|
8
|
-
*
|
|
9
|
-
* Uses the singleton HotkeyManager for efficient event handling.
|
|
10
|
-
* The callback receives both the keyboard event and a context object
|
|
11
|
-
* containing the hotkey string and parsed hotkey.
|
|
12
|
-
*
|
|
13
|
-
* This composable automatically tracks reactive dependencies and updates
|
|
14
|
-
* the registration when options or the callback change.
|
|
15
|
-
*
|
|
16
|
-
* @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
|
|
17
|
-
* @param callback - The function to call when the hotkey is pressed
|
|
18
|
-
* @param options - Options for the hotkey behavior
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```vue
|
|
22
|
-
* <script setup>
|
|
23
|
-
* import { ref } from 'vue'
|
|
24
|
-
* import { useHotkey } from '@tanstack/vue-hotkeys'
|
|
25
|
-
*
|
|
26
|
-
* const count = ref(0)
|
|
27
|
-
*
|
|
28
|
-
* // Callback always has access to latest count value
|
|
29
|
-
* useHotkey('Mod+S', (event, { hotkey }) => {
|
|
30
|
-
* console.log(`Save triggered, count is ${count.value}`)
|
|
31
|
-
* handleSave()
|
|
32
|
-
* })
|
|
33
|
-
* <\/script>
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```vue
|
|
38
|
-
* <script setup>
|
|
39
|
-
* import { ref } from 'vue'
|
|
40
|
-
* import { useHotkey } from '@tanstack/vue-hotkeys'
|
|
41
|
-
*
|
|
42
|
-
* const isOpen = ref(false)
|
|
43
|
-
*
|
|
44
|
-
* // enabled option is reactive
|
|
45
|
-
* useHotkey('Escape', () => {
|
|
46
|
-
* isOpen.value = false
|
|
47
|
-
* }, { enabled: isOpen })
|
|
48
|
-
* <\/script>
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```vue
|
|
53
|
-
* <script setup>
|
|
54
|
-
* import { ref } from 'vue'
|
|
55
|
-
* import { useHotkey } from '@tanstack/vue-hotkeys'
|
|
56
|
-
*
|
|
57
|
-
* const editorRef = ref<HTMLDivElement | null>(null)
|
|
58
|
-
*
|
|
59
|
-
* // Scoped to a specific element
|
|
60
|
-
* useHotkey('Mod+S', () => {
|
|
61
|
-
* save()
|
|
62
|
-
* }, { target: editorRef })
|
|
63
|
-
* <\/script>
|
|
64
|
-
*
|
|
65
|
-
* <template>
|
|
66
|
-
* <div ref="editorRef">...</div>
|
|
67
|
-
* </template>
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
function useHotkey(hotkey, callback, options = {}) {
|
|
71
|
-
const defaultOptions = require_HotkeysProviderContext.useDefaultHotkeysOptions();
|
|
72
|
-
const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
|
|
73
|
-
let registration = null;
|
|
74
|
-
let lastHotkeyString = null;
|
|
75
|
-
let lastTarget = null;
|
|
76
|
-
const stopWatcher = (0, vue.watch)(() => {
|
|
77
|
-
const resolvedHotkey = resolveMaybeRefOrGetter(hotkey);
|
|
78
|
-
const resolvedOptions = resolveMaybeRefOrGetter(options);
|
|
79
|
-
const mergedOptions = {
|
|
80
|
-
...defaultOptions.hotkey,
|
|
81
|
-
...resolvedOptions
|
|
82
|
-
};
|
|
83
|
-
return {
|
|
84
|
-
resolvedHotkey,
|
|
85
|
-
mergedOptions,
|
|
86
|
-
resolvedEnabled: mergedOptions.enabled === void 0 ? void 0 : resolveMaybeRefOrGetter(mergedOptions.enabled),
|
|
87
|
-
resolvedTarget: mergedOptions.target === void 0 ? void 0 : resolveMaybeRefOrGetter(mergedOptions.target)
|
|
88
|
-
};
|
|
89
|
-
}, ({ resolvedHotkey, mergedOptions, resolvedEnabled, resolvedTarget }) => {
|
|
90
|
-
const hotkeyString = (0, _tanstack_hotkeys.normalizeRegisterableHotkey)(resolvedHotkey, mergedOptions.platform ?? (0, _tanstack_hotkeys.detectPlatform)());
|
|
91
|
-
const finalTarget = resolvedTarget === void 0 ? typeof document !== "undefined" ? document : null : resolvedTarget;
|
|
92
|
-
if (!finalTarget) {
|
|
93
|
-
if (registration?.isActive) {
|
|
94
|
-
registration.unregister();
|
|
95
|
-
registration = null;
|
|
96
|
-
}
|
|
97
|
-
lastHotkeyString = null;
|
|
98
|
-
lastTarget = null;
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const { target: _target, enabled: _enabled, ...restOptions } = mergedOptions;
|
|
102
|
-
const optionsWithoutTarget = {
|
|
103
|
-
...restOptions,
|
|
104
|
-
...resolvedEnabled === void 0 ? {} : { enabled: resolvedEnabled }
|
|
105
|
-
};
|
|
106
|
-
if (registration?.isActive && lastHotkeyString === hotkeyString && lastTarget === finalTarget) {
|
|
107
|
-
registration.callback = callback;
|
|
108
|
-
registration.setOptions(optionsWithoutTarget);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (registration?.isActive) {
|
|
112
|
-
registration.unregister();
|
|
113
|
-
registration = null;
|
|
114
|
-
}
|
|
115
|
-
registration = manager.register(hotkeyString, callback, {
|
|
116
|
-
...optionsWithoutTarget,
|
|
117
|
-
target: finalTarget
|
|
118
|
-
});
|
|
119
|
-
if (registration.isActive) {
|
|
120
|
-
registration.callback = callback;
|
|
121
|
-
registration.setOptions(optionsWithoutTarget);
|
|
122
|
-
}
|
|
123
|
-
lastHotkeyString = hotkeyString;
|
|
124
|
-
lastTarget = finalTarget;
|
|
125
|
-
}, { immediate: true });
|
|
126
|
-
(0, vue.onUnmounted)(() => {
|
|
127
|
-
stopWatcher();
|
|
128
|
-
if (registration?.isActive) {
|
|
129
|
-
registration.unregister();
|
|
130
|
-
registration = null;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
function resolveMaybeRefOrGetter(value) {
|
|
135
|
-
return typeof value === "function" ? value() : (0, vue.unref)(value);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//#endregion
|
|
139
|
-
exports.useHotkey = useHotkey;
|
|
140
|
-
//# sourceMappingURL=useHotkey.cjs.map
|
package/dist/useHotkey.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkey.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProviderContext'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport type { MaybeRefOrGetter } from 'vue'\n\nexport interface UseHotkeyOptions extends Omit<\n HotkeyOptions,\n 'enabled' | 'target'\n> {\n /**\n * Whether the hotkey is active.\n * Can be a Ref, a getter function, or a boolean value.\n * Defaults to true.\n */\n enabled?: MaybeRefOrGetter<boolean>\n /**\n * The DOM element to attach the event listener to.\n * Can be a Ref, a getter function, direct DOM element, or null.\n * Defaults to document.\n */\n target?: MaybeRefOrGetter<HTMLElement | Document | Window | null>\n}\n\n/**\n * Vue composable for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This composable automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkey } from '@tanstack/vue-hotkeys'\n *\n * const count = ref(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count.value}`)\n * handleSave()\n * })\n * </script>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkey } from '@tanstack/vue-hotkeys'\n *\n * const isOpen = ref(false)\n *\n * // enabled option is reactive\n * useHotkey('Escape', () => {\n * isOpen.value = false\n * }, { enabled: isOpen })\n * </script>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkey } from '@tanstack/vue-hotkeys'\n *\n * const editorRef = ref<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n * </script>\n *\n * <template>\n * <div ref=\"editorRef\">...</div>\n * </template>\n * ```\n */\nexport function useHotkey(\n hotkey: MaybeRefOrGetter<RegisterableHotkey>,\n callback: HotkeyCallback,\n options: MaybeRefOrGetter<UseHotkeyOptions> = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n let lastHotkeyString: Hotkey | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n // Watch for changes to reactive dependencies\n const stopWatcher = watch(\n () => {\n const resolvedHotkey = resolveMaybeRefOrGetter(hotkey)\n const resolvedOptions = resolveMaybeRefOrGetter(options)\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as UseHotkeyOptions\n const resolvedEnabled =\n mergedOptions.enabled === undefined\n ? undefined\n : resolveMaybeRefOrGetter(mergedOptions.enabled)\n const resolvedTarget =\n mergedOptions.target === undefined\n ? undefined\n : resolveMaybeRefOrGetter(mergedOptions.target)\n\n return {\n resolvedHotkey,\n mergedOptions,\n resolvedEnabled,\n resolvedTarget,\n }\n },\n ({ resolvedHotkey, mergedOptions, resolvedEnabled, resolvedTarget }) => {\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(resolvedHotkey, platform)\n\n // Resolve target\n const finalTarget =\n resolvedTarget === undefined\n ? typeof document !== 'undefined'\n ? document\n : null\n : resolvedTarget\n\n if (!finalTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n return\n }\n\n // Extract options without target (target is handled separately)\n const {\n target: _target,\n enabled: _enabled,\n ...restOptions\n } = mergedOptions\n const optionsWithoutTarget = {\n ...restOptions,\n ...(resolvedEnabled === undefined ? {} : { enabled: resolvedEnabled }),\n }\n\n if (\n registration?.isActive &&\n lastHotkeyString === hotkeyString &&\n lastTarget === finalTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: finalTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastHotkeyString = hotkeyString\n lastTarget = finalTarget\n },\n { immediate: true },\n )\n\n // Cleanup on unmount\n onUnmounted(() => {\n stopWatcher()\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n })\n}\n\nfunction resolveMaybeRefOrGetter<T>(value: MaybeRefOrGetter<T>): T {\n return typeof value === 'function' ? (value as () => T)() : unref(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,UACd,QACA,UACA,UAA8C,EAAE,EAC1C;CACN,MAAM,iBAAiBA,yDAA0B;CACjD,MAAM,mDAA4B;CAElC,IAAI,eAAgD;CACpD,IAAI,mBAAkC;CACtC,IAAI,aAAqD;CAGzD,MAAM,mCACE;EACJ,MAAM,iBAAiB,wBAAwB,OAAO;EACtD,MAAM,kBAAkB,wBAAwB,QAAQ;EACxD,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;AAUD,SAAO;GACL;GACA;GACA,iBAXA,cAAc,YAAY,SACtB,SACA,wBAAwB,cAAc,QAAQ;GAUlD,gBARA,cAAc,WAAW,SACrB,SACA,wBAAwB,cAAc,OAAO;GAOlD;KAEF,EAAE,gBAAgB,eAAe,iBAAiB,qBAAqB;EAGtE,MAAM,kEAA2C,gBADhC,cAAc,mDAA4B,CACe;EAG1E,MAAM,cACJ,mBAAmB,SACf,OAAO,aAAa,cAClB,WACA,OACF;AAEN,MAAI,CAAC,aAAa;AAChB,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,sBAAmB;AACnB,gBAAa;AACb;;EAIF,MAAM,EACJ,QAAQ,SACR,SAAS,UACT,GAAG,gBACD;EACJ,MAAM,uBAAuB;GAC3B,GAAG;GACH,GAAI,oBAAoB,SAAY,EAAE,GAAG,EAAE,SAAS,iBAAiB;GACtE;AAED,MACE,cAAc,YACd,qBAAqB,gBACrB,eAAe,aACf;AACA,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;AAC7C;;AAGF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAGjB,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAEF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAG/C,qBAAmB;AACnB,eAAa;IAEf,EAAE,WAAW,MAAM,CACpB;AAGD,4BAAkB;AAChB,eAAa;AACb,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;GAEjB;;AAGJ,SAAS,wBAA2B,OAA+B;AACjE,QAAO,OAAO,UAAU,aAAc,OAAmB,kBAAS,MAAM"}
|
package/dist/useHotkey.d.cts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { HotkeyCallback, HotkeyOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
-
import { MaybeRefOrGetter } from "vue";
|
|
3
|
-
|
|
4
|
-
//#region src/useHotkey.d.ts
|
|
5
|
-
interface UseHotkeyOptions extends Omit<HotkeyOptions, 'enabled' | 'target'> {
|
|
6
|
-
/**
|
|
7
|
-
* Whether the hotkey is active.
|
|
8
|
-
* Can be a Ref, a getter function, or a boolean value.
|
|
9
|
-
* Defaults to true.
|
|
10
|
-
*/
|
|
11
|
-
enabled?: MaybeRefOrGetter<boolean>;
|
|
12
|
-
/**
|
|
13
|
-
* The DOM element to attach the event listener to.
|
|
14
|
-
* Can be a Ref, a getter function, direct DOM element, or null.
|
|
15
|
-
* Defaults to document.
|
|
16
|
-
*/
|
|
17
|
-
target?: MaybeRefOrGetter<HTMLElement | Document | Window | null>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Vue composable for registering a keyboard hotkey.
|
|
21
|
-
*
|
|
22
|
-
* Uses the singleton HotkeyManager for efficient event handling.
|
|
23
|
-
* The callback receives both the keyboard event and a context object
|
|
24
|
-
* containing the hotkey string and parsed hotkey.
|
|
25
|
-
*
|
|
26
|
-
* This composable automatically tracks reactive dependencies and updates
|
|
27
|
-
* the registration when options or the callback change.
|
|
28
|
-
*
|
|
29
|
-
* @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)
|
|
30
|
-
* @param callback - The function to call when the hotkey is pressed
|
|
31
|
-
* @param options - Options for the hotkey behavior
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```vue
|
|
35
|
-
* <script setup>
|
|
36
|
-
* import { ref } from 'vue'
|
|
37
|
-
* import { useHotkey } from '@tanstack/vue-hotkeys'
|
|
38
|
-
*
|
|
39
|
-
* const count = ref(0)
|
|
40
|
-
*
|
|
41
|
-
* // Callback always has access to latest count value
|
|
42
|
-
* useHotkey('Mod+S', (event, { hotkey }) => {
|
|
43
|
-
* console.log(`Save triggered, count is ${count.value}`)
|
|
44
|
-
* handleSave()
|
|
45
|
-
* })
|
|
46
|
-
* </script>
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```vue
|
|
51
|
-
* <script setup>
|
|
52
|
-
* import { ref } from 'vue'
|
|
53
|
-
* import { useHotkey } from '@tanstack/vue-hotkeys'
|
|
54
|
-
*
|
|
55
|
-
* const isOpen = ref(false)
|
|
56
|
-
*
|
|
57
|
-
* // enabled option is reactive
|
|
58
|
-
* useHotkey('Escape', () => {
|
|
59
|
-
* isOpen.value = false
|
|
60
|
-
* }, { enabled: isOpen })
|
|
61
|
-
* </script>
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```vue
|
|
66
|
-
* <script setup>
|
|
67
|
-
* import { ref } from 'vue'
|
|
68
|
-
* import { useHotkey } from '@tanstack/vue-hotkeys'
|
|
69
|
-
*
|
|
70
|
-
* const editorRef = ref<HTMLDivElement | null>(null)
|
|
71
|
-
*
|
|
72
|
-
* // Scoped to a specific element
|
|
73
|
-
* useHotkey('Mod+S', () => {
|
|
74
|
-
* save()
|
|
75
|
-
* }, { target: editorRef })
|
|
76
|
-
* </script>
|
|
77
|
-
*
|
|
78
|
-
* <template>
|
|
79
|
-
* <div ref="editorRef">...</div>
|
|
80
|
-
* </template>
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
declare function useHotkey(hotkey: MaybeRefOrGetter<RegisterableHotkey>, callback: HotkeyCallback, options?: MaybeRefOrGetter<UseHotkeyOptions>): void;
|
|
84
|
-
//#endregion
|
|
85
|
-
export { UseHotkeyOptions, useHotkey };
|
|
86
|
-
//# sourceMappingURL=useHotkey.d.cts.map
|
package/dist/useHotkey.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHotkey.js","names":[],"sources":["../src/useHotkey.ts"],"sourcesContent":["import { onUnmounted, unref, watch } from 'vue'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProviderContext'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport type { MaybeRefOrGetter } from 'vue'\n\nexport interface UseHotkeyOptions extends Omit<\n HotkeyOptions,\n 'enabled' | 'target'\n> {\n /**\n * Whether the hotkey is active.\n * Can be a Ref, a getter function, or a boolean value.\n * Defaults to true.\n */\n enabled?: MaybeRefOrGetter<boolean>\n /**\n * The DOM element to attach the event listener to.\n * Can be a Ref, a getter function, direct DOM element, or null.\n * Defaults to document.\n */\n target?: MaybeRefOrGetter<HTMLElement | Document | Window | null>\n}\n\n/**\n * Vue composable for registering a keyboard hotkey.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * The callback receives both the keyboard event and a context object\n * containing the hotkey string and parsed hotkey.\n *\n * This composable automatically tracks reactive dependencies and updates\n * the registration when options or the callback change.\n *\n * @param hotkey - The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object (supports `mod` for cross-platform)\n * @param callback - The function to call when the hotkey is pressed\n * @param options - Options for the hotkey behavior\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkey } from '@tanstack/vue-hotkeys'\n *\n * const count = ref(0)\n *\n * // Callback always has access to latest count value\n * useHotkey('Mod+S', (event, { hotkey }) => {\n * console.log(`Save triggered, count is ${count.value}`)\n * handleSave()\n * })\n * </script>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkey } from '@tanstack/vue-hotkeys'\n *\n * const isOpen = ref(false)\n *\n * // enabled option is reactive\n * useHotkey('Escape', () => {\n * isOpen.value = false\n * }, { enabled: isOpen })\n * </script>\n * ```\n *\n * @example\n * ```vue\n * <script setup>\n * import { ref } from 'vue'\n * import { useHotkey } from '@tanstack/vue-hotkeys'\n *\n * const editorRef = ref<HTMLDivElement | null>(null)\n *\n * // Scoped to a specific element\n * useHotkey('Mod+S', () => {\n * save()\n * }, { target: editorRef })\n * </script>\n *\n * <template>\n * <div ref=\"editorRef\">...</div>\n * </template>\n * ```\n */\nexport function useHotkey(\n hotkey: MaybeRefOrGetter<RegisterableHotkey>,\n callback: HotkeyCallback,\n options: MaybeRefOrGetter<UseHotkeyOptions> = {},\n): void {\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n let registration: HotkeyRegistrationHandle | null = null\n let lastHotkeyString: Hotkey | null = null\n let lastTarget: HTMLElement | Document | Window | null = null\n\n // Watch for changes to reactive dependencies\n const stopWatcher = watch(\n () => {\n const resolvedHotkey = resolveMaybeRefOrGetter(hotkey)\n const resolvedOptions = resolveMaybeRefOrGetter(options)\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedOptions,\n } as UseHotkeyOptions\n const resolvedEnabled =\n mergedOptions.enabled === undefined\n ? undefined\n : resolveMaybeRefOrGetter(mergedOptions.enabled)\n const resolvedTarget =\n mergedOptions.target === undefined\n ? undefined\n : resolveMaybeRefOrGetter(mergedOptions.target)\n\n return {\n resolvedHotkey,\n mergedOptions,\n resolvedEnabled,\n resolvedTarget,\n }\n },\n ({ resolvedHotkey, mergedOptions, resolvedEnabled, resolvedTarget }) => {\n // Normalize to hotkey string\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(resolvedHotkey, platform)\n\n // Resolve target\n const finalTarget =\n resolvedTarget === undefined\n ? typeof document !== 'undefined'\n ? document\n : null\n : resolvedTarget\n\n if (!finalTarget) {\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n lastHotkeyString = null\n lastTarget = null\n return\n }\n\n // Extract options without target (target is handled separately)\n const {\n target: _target,\n enabled: _enabled,\n ...restOptions\n } = mergedOptions\n const optionsWithoutTarget = {\n ...restOptions,\n ...(resolvedEnabled === undefined ? {} : { enabled: resolvedEnabled }),\n }\n\n if (\n registration?.isActive &&\n lastHotkeyString === hotkeyString &&\n lastTarget === finalTarget\n ) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n return\n }\n\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n\n registration = manager.register(hotkeyString, callback, {\n ...optionsWithoutTarget,\n target: finalTarget,\n })\n\n if (registration.isActive) {\n registration.callback = callback\n registration.setOptions(optionsWithoutTarget)\n }\n\n lastHotkeyString = hotkeyString\n lastTarget = finalTarget\n },\n { immediate: true },\n )\n\n // Cleanup on unmount\n onUnmounted(() => {\n stopWatcher()\n if (registration?.isActive) {\n registration.unregister()\n registration = null\n }\n })\n}\n\nfunction resolveMaybeRefOrGetter<T>(value: MaybeRefOrGetter<T>): T {\n return typeof value === 'function' ? (value as () => T)() : unref(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,UACd,QACA,UACA,UAA8C,EAAE,EAC1C;CACN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,kBAAkB;CAElC,IAAI,eAAgD;CACpD,IAAI,mBAAkC;CACtC,IAAI,aAAqD;CAGzD,MAAM,cAAc,YACZ;EACJ,MAAM,iBAAiB,wBAAwB,OAAO;EACtD,MAAM,kBAAkB,wBAAwB,QAAQ;EACxD,MAAM,gBAAgB;GACpB,GAAG,eAAe;GAClB,GAAG;GACJ;AAUD,SAAO;GACL;GACA;GACA,iBAXA,cAAc,YAAY,SACtB,SACA,wBAAwB,cAAc,QAAQ;GAUlD,gBARA,cAAc,WAAW,SACrB,SACA,wBAAwB,cAAc,OAAO;GAOlD;KAEF,EAAE,gBAAgB,eAAe,iBAAiB,qBAAqB;EAGtE,MAAM,eAAe,4BAA4B,gBADhC,cAAc,YAAY,gBAAgB,CACe;EAG1E,MAAM,cACJ,mBAAmB,SACf,OAAO,aAAa,cAClB,WACA,OACF;AAEN,MAAI,CAAC,aAAa;AAChB,OAAI,cAAc,UAAU;AAC1B,iBAAa,YAAY;AACzB,mBAAe;;AAEjB,sBAAmB;AACnB,gBAAa;AACb;;EAIF,MAAM,EACJ,QAAQ,SACR,SAAS,UACT,GAAG,gBACD;EACJ,MAAM,uBAAuB;GAC3B,GAAG;GACH,GAAI,oBAAoB,SAAY,EAAE,GAAG,EAAE,SAAS,iBAAiB;GACtE;AAED,MACE,cAAc,YACd,qBAAqB,gBACrB,eAAe,aACf;AACA,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;AAC7C;;AAGF,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;AAGjB,iBAAe,QAAQ,SAAS,cAAc,UAAU;GACtD,GAAG;GACH,QAAQ;GACT,CAAC;AAEF,MAAI,aAAa,UAAU;AACzB,gBAAa,WAAW;AACxB,gBAAa,WAAW,qBAAqB;;AAG/C,qBAAmB;AACnB,eAAa;IAEf,EAAE,WAAW,MAAM,CACpB;AAGD,mBAAkB;AAChB,eAAa;AACb,MAAI,cAAc,UAAU;AAC1B,gBAAa,YAAY;AACzB,kBAAe;;GAEjB;;AAGJ,SAAS,wBAA2B,OAA+B;AACjE,QAAO,OAAO,UAAU,aAAc,OAAmB,GAAG,MAAM,MAAM"}
|
package/dist/useHotkeyHint.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/useHotkeyHint.d.cts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
const require_HotkeysProviderContext = require('./HotkeysProviderContext.cjs');
|
|
2
|
-
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
3
|
-
let vue = require("vue");
|
|
4
|
-
let _tanstack_vue_store = require("@tanstack/vue-store");
|
|
5
|
-
|
|
6
|
-
//#region src/useHotkeyRecorder.ts
|
|
7
|
-
/**
|
|
8
|
-
* Vue composable for recording keyboard shortcuts.
|
|
9
|
-
*
|
|
10
|
-
* This composable provides a thin wrapper around the framework-agnostic `HotkeyRecorder`
|
|
11
|
-
* class, managing all the complexity of capturing keyboard events, converting them
|
|
12
|
-
* to hotkey strings, and handling edge cases like Escape to cancel or Backspace/Delete
|
|
13
|
-
* to clear.
|
|
14
|
-
*
|
|
15
|
-
* @param options - Configuration options for the recorder
|
|
16
|
-
* @returns An object with recording state and control functions
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```vue
|
|
20
|
-
* <script setup>
|
|
21
|
-
* import { ref } from 'vue'
|
|
22
|
-
* import { useHotkeyRecorder } from '@tanstack/vue-hotkeys'
|
|
23
|
-
*
|
|
24
|
-
* const shortcut = ref<Hotkey>('Mod+S')
|
|
25
|
-
*
|
|
26
|
-
* const recorder = useHotkeyRecorder({
|
|
27
|
-
* onRecord: (hotkey) => {
|
|
28
|
-
* shortcut.value = hotkey
|
|
29
|
-
* },
|
|
30
|
-
* onCancel: () => {
|
|
31
|
-
* console.log('Recording cancelled')
|
|
32
|
-
* },
|
|
33
|
-
* })
|
|
34
|
-
* <\/script>
|
|
35
|
-
*
|
|
36
|
-
* <template>
|
|
37
|
-
* <div>
|
|
38
|
-
* <button @click="recorder.startRecording()">
|
|
39
|
-
* {{ recorder.isRecording ? 'Recording...' : 'Edit Shortcut' }}
|
|
40
|
-
* </button>
|
|
41
|
-
* <div v-if="recorder.recordedHotkey">
|
|
42
|
-
* Recording: {{ recorder.recordedHotkey }}
|
|
43
|
-
* </div>
|
|
44
|
-
* </div>
|
|
45
|
-
* </template>
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
function useHotkeyRecorder(options) {
|
|
49
|
-
const defaultOptions = require_HotkeysProviderContext.useDefaultHotkeysOptions();
|
|
50
|
-
const recorder = new _tanstack_hotkeys.HotkeyRecorder(resolveRecorderOptions(options, defaultOptions));
|
|
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
|
-
const stopWatcher = (0, vue.watch)(() => resolveRecorderOptions(options, defaultOptions), (resolvedOptions) => {
|
|
54
|
-
recorder.setOptions(resolvedOptions);
|
|
55
|
-
}, { immediate: true });
|
|
56
|
-
(0, vue.onUnmounted)(() => {
|
|
57
|
-
stopWatcher();
|
|
58
|
-
recorder.destroy();
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
isRecording,
|
|
62
|
-
recordedHotkey,
|
|
63
|
-
startRecording: () => recorder.start(),
|
|
64
|
-
stopRecording: () => recorder.stop(),
|
|
65
|
-
cancelRecording: () => recorder.cancel()
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function resolveRecorderOptions(options, defaultOptions) {
|
|
69
|
-
return {
|
|
70
|
-
...defaultOptions.hotkeyRecorder,
|
|
71
|
-
...resolveMaybeRefOrGetter(options)
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function resolveMaybeRefOrGetter(value) {
|
|
75
|
-
return typeof value === "function" ? value() : (0, vue.unref)(value);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
//#endregion
|
|
79
|
-
exports.useHotkeyRecorder = useHotkeyRecorder;
|
|
80
|
-
//# sourceMappingURL=useHotkeyRecorder.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|