@tanstack/vue-hotkeys 0.25.6 → 0.26.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 -0
- package/dist/HotkeysProvider.js +6 -0
- package/dist/HotkeysProviderContext.d.ts +2 -0
- package/dist/HotkeysProviderContext.js +4 -1
- package/dist/formatForAria.d.ts +12 -0
- package/dist/formatForAria.js +15 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/useFormatForAria.d.ts +32 -0
- package/dist/useFormatForAria.js +45 -0
- package/package.json +2 -2
- package/skills/vue-hotkeys/SKILL.md +21 -20
|
@@ -30,6 +30,11 @@ declare const providerProps: {
|
|
|
30
30
|
type: BooleanConstructor;
|
|
31
31
|
default: boolean;
|
|
32
32
|
};
|
|
33
|
+
/** See `HotkeysProviderScopeProps['suspendCharacterKeys']`. */
|
|
34
|
+
suspendCharacterKeys: {
|
|
35
|
+
type: BooleanConstructor;
|
|
36
|
+
default: boolean;
|
|
37
|
+
};
|
|
33
38
|
};
|
|
34
39
|
declare const providerEmits: {
|
|
35
40
|
customHotkeysChange: (_customHotkeys: CustomHotkeys) => true;
|
package/dist/HotkeysProvider.js
CHANGED
|
@@ -31,6 +31,11 @@ const component = defineComponent({
|
|
|
31
31
|
enabled: {
|
|
32
32
|
type: Boolean,
|
|
33
33
|
default: true
|
|
34
|
+
},
|
|
35
|
+
/** See `HotkeysProviderScopeProps['suspendCharacterKeys']`. */
|
|
36
|
+
suspendCharacterKeys: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
emits: { customHotkeysChange: (_customHotkeys) => true },
|
|
@@ -42,6 +47,7 @@ const component = defineComponent({
|
|
|
42
47
|
scope: () => props.scope,
|
|
43
48
|
exclusive: () => props.exclusive,
|
|
44
49
|
enabled: () => props.enabled,
|
|
50
|
+
suspendCharacterKeys: () => props.suspendCharacterKeys,
|
|
45
51
|
onCustomHotkeysChange: (custom) => emit("customHotkeysChange", custom)
|
|
46
52
|
});
|
|
47
53
|
return () => slots.default?.();
|
|
@@ -36,6 +36,8 @@ export interface ProvideHotkeysContextOptions {
|
|
|
36
36
|
exclusive?: MaybeRefOrGetter<HotkeysProviderScopeProps['exclusive']>;
|
|
37
37
|
/** See `HotkeysProviderScopeProps['enabled']`. */
|
|
38
38
|
enabled?: MaybeRefOrGetter<HotkeysProviderScopeProps['enabled']>;
|
|
39
|
+
/** See `HotkeysProviderScopeProps['suspendCharacterKeys']`. */
|
|
40
|
+
suspendCharacterKeys?: MaybeRefOrGetter<HotkeysProviderScopeProps['suspendCharacterKeys']>;
|
|
39
41
|
/**
|
|
40
42
|
* Every app hotkey, from `defineAppHotkeys`. It can start as `undefined` and
|
|
41
43
|
* arrive later, such as from a lazy import. Later changes update the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useLive } from "./_useLive.js";
|
|
2
|
-
import { publishAppHotkeysStore } from "@tanstack/hotkeys";
|
|
2
|
+
import { getHotkeyManager, publishAppHotkeysStore } from "@tanstack/hotkeys";
|
|
3
3
|
import { computed, hasInjectionContext, inject, onMounted, provide, shallowRef, toValue, watch } from "vue";
|
|
4
4
|
import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
5
5
|
|
|
@@ -63,6 +63,9 @@ function provideHotkeysContext(options = {}) {
|
|
|
63
63
|
watch(scopeKey, (key, _, onCleanup) => {
|
|
64
64
|
if (key) onCleanup(activateHotkeysProviderScope(key));
|
|
65
65
|
}, { immediate: true });
|
|
66
|
+
watch(() => !!toValue(options.suspendCharacterKeys), (suspend, _, onCleanup) => {
|
|
67
|
+
if (suspend) onCleanup(getHotkeyManager().suspendCharacterKeys());
|
|
68
|
+
}, { immediate: true });
|
|
66
69
|
});
|
|
67
70
|
provide(HotkeysContext, {
|
|
68
71
|
get appHotkeysStore() {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
2
|
+
/**
|
|
3
|
+
* Formats a hotkey for `aria-keyshortcuts`, without the provider's platform or
|
|
4
|
+
* the user's keyboard layout.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Use `useFormatForAria()` in components. It returns this
|
|
7
|
+
* function with the provider's platform and the user's keyboard layout filled
|
|
8
|
+
* in. Outside a component, keep calling this function and pass `platform`
|
|
9
|
+
* yourself.
|
|
10
|
+
*/
|
|
11
|
+
declare const formatForAria$1: typeof formatForAria;
|
|
12
|
+
export { formatForAria$1 as formatForAria };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
// src/formatForAria.ts
|
|
4
|
+
/**
|
|
5
|
+
* Formats a hotkey for `aria-keyshortcuts`, without the provider's platform or
|
|
6
|
+
* the user's keyboard layout.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Use `useFormatForAria()` in components. It returns this
|
|
9
|
+
* function with the provider's platform and the user's keyboard layout filled
|
|
10
|
+
* in. Outside a component, keep calling this function and pass `platform`
|
|
11
|
+
* yourself.
|
|
12
|
+
*/
|
|
13
|
+
const formatForAria$1 = formatForAria;
|
|
14
|
+
|
|
15
|
+
export { formatForAria$1 as formatForAria };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
|
10
10
|
import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
|
|
11
11
|
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
12
12
|
import { useFormatForDisplay } from "./useFormatForDisplay.js";
|
|
13
|
+
import { useFormatForAria } from "./useFormatForAria.js";
|
|
13
14
|
import { formatForDisplay } from "./formatForDisplay.js";
|
|
15
|
+
import { formatForAria } from "./formatForAria.js";
|
|
14
16
|
import { useKeyboardLayout } from "./useKeyboardLayout.js";
|
|
15
17
|
import { UseCustomHotkeysResult, useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
|
|
16
18
|
export * from "@tanstack/hotkeys";
|
|
17
|
-
export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
|
|
19
|
+
export { HotkeysProvider, HotkeysProviderOptions, ProvideHotkeysContextOptions, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, VueHotkeyRecorder, formatForAria, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,12 @@ import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
|
10
10
|
import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
|
|
11
11
|
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
12
12
|
import { useFormatForDisplay } from "./useFormatForDisplay.js";
|
|
13
|
+
import { useFormatForAria } from "./useFormatForAria.js";
|
|
13
14
|
import { formatForDisplay } from "./formatForDisplay.js";
|
|
15
|
+
import { formatForAria } from "./formatForAria.js";
|
|
14
16
|
import { useKeyboardLayout } from "./useKeyboardLayout.js";
|
|
15
17
|
import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
|
|
16
18
|
|
|
17
19
|
export * from "@tanstack/hotkeys"
|
|
18
20
|
|
|
19
|
-
export { HotkeysProvider, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
|
|
21
|
+
export { HotkeysProvider, formatForAria, formatForDisplay, provideHotkeysContext, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
2
|
+
/**
|
|
3
|
+
* Returns `formatForAria` with the provider's `platform` as the default. Use
|
|
4
|
+
* its value for `aria-keyshortcuts`, so screen readers announce the shortcut.
|
|
5
|
+
* It returns `undefined` for a multi-step sequence, no hotkey, or a hotkey
|
|
6
|
+
* that can't fire right now (one that is disabled, in a suspended scope, a
|
|
7
|
+
* suspended character key, or not registered), so Vue omits the attribute.
|
|
8
|
+
* Call in `setup`; the returned function works anywhere, and templates update
|
|
9
|
+
* when the provider's platform changes. An explicit `platform` option wins.
|
|
10
|
+
*
|
|
11
|
+
* Physical bindings such as `[KeyQ]` name the key the user presses in
|
|
12
|
+
* Chromium browsers, once the keyboard layout has loaded. See
|
|
13
|
+
* `useKeyboardLayout`. A `layoutMap` passed to the returned function wins.
|
|
14
|
+
*
|
|
15
|
+
* Server-rendered apps should set the provider's `defaultOptions.platform`
|
|
16
|
+
* from the request user agent with `detectPlatform(userAgent)`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```vue
|
|
20
|
+
* <script setup lang="ts">
|
|
21
|
+
* const appHotkeys = useAppHotkeys()
|
|
22
|
+
* const formatForAria = useFormatForAria()
|
|
23
|
+
* </script>
|
|
24
|
+
*
|
|
25
|
+
* <template>
|
|
26
|
+
* <button :aria-keyshortcuts="formatForAria(appHotkeys['search.open'].hotkey)">
|
|
27
|
+
* Search
|
|
28
|
+
* </button>
|
|
29
|
+
* </template>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function useFormatForAria(): typeof formatForAria;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
|
|
2
|
+
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
3
|
+
import { useKeyboardLayout } from "./useKeyboardLayout.js";
|
|
4
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
5
|
+
import { announceLiveHotkeys, createFormatter } from "@tanstack/hotkeys/adapter";
|
|
6
|
+
|
|
7
|
+
// src/useFormatForAria.ts
|
|
8
|
+
/**
|
|
9
|
+
* Returns `formatForAria` with the provider's `platform` as the default. Use
|
|
10
|
+
* its value for `aria-keyshortcuts`, so screen readers announce the shortcut.
|
|
11
|
+
* It returns `undefined` for a multi-step sequence, no hotkey, or a hotkey
|
|
12
|
+
* that can't fire right now (one that is disabled, in a suspended scope, a
|
|
13
|
+
* suspended character key, or not registered), so Vue omits the attribute.
|
|
14
|
+
* Call in `setup`; the returned function works anywhere, and templates update
|
|
15
|
+
* when the provider's platform changes. An explicit `platform` option wins.
|
|
16
|
+
*
|
|
17
|
+
* Physical bindings such as `[KeyQ]` name the key the user presses in
|
|
18
|
+
* Chromium browsers, once the keyboard layout has loaded. See
|
|
19
|
+
* `useKeyboardLayout`. A `layoutMap` passed to the returned function wins.
|
|
20
|
+
*
|
|
21
|
+
* Server-rendered apps should set the provider's `defaultOptions.platform`
|
|
22
|
+
* from the request user agent with `detectPlatform(userAgent)`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```vue
|
|
26
|
+
* <script setup lang="ts">
|
|
27
|
+
* const appHotkeys = useAppHotkeys()
|
|
28
|
+
* const formatForAria = useFormatForAria()
|
|
29
|
+
* <\/script>
|
|
30
|
+
*
|
|
31
|
+
* <template>
|
|
32
|
+
* <button :aria-keyshortcuts="formatForAria(appHotkeys['search.open'].hotkey)">
|
|
33
|
+
* Search
|
|
34
|
+
* </button>
|
|
35
|
+
* </template>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function useFormatForAria() {
|
|
39
|
+
const defaultOptions = useDefaultHotkeysOptionsSource();
|
|
40
|
+
const layoutMap = useKeyboardLayout();
|
|
41
|
+
const registrations = useHotkeyRegistrations();
|
|
42
|
+
return announceLiveHotkeys(createFormatter(formatForAria, () => defaultOptions().platform, () => layoutMap.value), () => registrations.value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { useFormatForAria };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Vue adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"skills"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@tanstack/hotkeys": "0.
|
|
41
|
+
"@tanstack/hotkeys": "0.37.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@tanstack/hotkeys-test-utils": "0.0.0",
|
|
@@ -53,27 +53,28 @@ const formatForDisplay = useFormatForDisplay()
|
|
|
53
53
|
|
|
54
54
|
## API
|
|
55
55
|
|
|
56
|
-
| API | What it's for
|
|
57
|
-
| ----------------------------------------- |
|
|
58
|
-
| `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted; the hotkey and options can be refs or getters.
|
|
59
|
-
| `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a ref or getter of a list built from data, in one call.
|
|
60
|
-
| `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for its children, and emit `custom-hotkeys-change`.
|
|
61
|
-
| `provideHotkeysContext(options)` | Provide the same options from a component's setup instead of rendering `HotkeysProvider`; they apply to its children.
|
|
62
|
-
| `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider.
|
|
63
|
-
| `useDefaultHotkeysOptions()` | Read the default options merged from every provider above.
|
|
64
|
-
| `useFormatForDisplay()` | Get the function that formats a hotkey as a label, with the provider's `platform` and the user's keyboard layout filled in. Only Chromium browsers report a layout, so physical keys keep their US labels in Firefox and Safari. Use it for every label in a component: `const formatForDisplay = useFormatForDisplay()` in `setup`, then `formatForDisplay(hotkey)`.
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
56
|
+
| API | What it's for |
|
|
57
|
+
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
58
|
+
| `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted; the hotkey and options can be refs or getters. |
|
|
59
|
+
| `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a ref or getter of a list built from data, in one call. |
|
|
60
|
+
| `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, `suspendCharacterKeys` (set from a user setting that turns off single-key shortcuts; it applies app-wide while the provider is mounted), and app hotkeys for its children, and emit `custom-hotkeys-change`. |
|
|
61
|
+
| `provideHotkeysContext(options)` | Provide the same options from a component's setup instead of rendering `HotkeysProvider`; they apply to its children. |
|
|
62
|
+
| `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
|
|
63
|
+
| `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
|
|
64
|
+
| `useFormatForDisplay()` | Get the function that formats a hotkey as a label, with the provider's `platform` and the user's keyboard layout filled in. Only Chromium browsers report a layout, so physical keys keep their US labels in Firefox and Safari. Use it for every label in a component: `const formatForDisplay = useFormatForDisplay()` in `setup`, then `formatForDisplay(hotkey)`. |
|
|
65
|
+
| `useFormatForAria()` | Get the function that formats a hotkey for `aria-keyshortcuts`, with the provider's `platform` and the user's keyboard layout filled in. Returns `undefined` for a multi-step sequence, no hotkey, or a hotkey that can't fire right now, such as a disabled or suspended one, so the attribute is omitted. Set `aria-keyshortcuts` on every control that has a shortcut, next to the visible label. |
|
|
66
|
+
| `useAppHotkeys()` | Get a computed ref of the declared app hotkeys with the user's custom hotkeys applied. |
|
|
67
|
+
| `useAppHotkeyList()` | Get a computed ref listing every app hotkey with its status, for a cheat sheet or settings screen. |
|
|
68
|
+
| `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
|
|
69
|
+
| `useHotkeyRecorder(options)` | Record a chord or sequence the user presses; destructure the refs it returns. |
|
|
70
|
+
| `useHotkeyRegistrations()` | Get a ref listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
|
|
71
|
+
| `useHotkeyScopesState()` | Get a ref of the active scopes and the exclusive scope that owns the keyboard. |
|
|
72
|
+
| `useHotkeyHint(hotkey, options?)` | Get a computed ref of whether held modifiers should reveal a shortcut's hint. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
|
|
73
|
+
| `useKeyHold(key)` | Get a ref of whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
|
|
74
|
+
| `useHeldKeys()` | Get a ref of every key that's held right now. |
|
|
75
|
+
| `useHeldKeyCodes()` | Get a ref mapping each held key to its physical `event.code`. |
|
|
75
76
|
|
|
76
|
-
The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`.
|
|
77
|
+
The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`. The plain `formatForAria` export is deprecated the same way, in favor of `useFormatForAria()`.
|
|
77
78
|
|
|
78
79
|
No provider is required. Call the composables synchronously in setup.
|
|
79
80
|
|