@tanstack/hotkeys 0.8.0 → 0.10.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/{manager.utils.js → _event-target.js} +2 -41
- package/dist/_keyboard-event.js +75 -0
- package/dist/_match.js +48 -0
- package/dist/_named-keys.d.ts +6 -0
- package/dist/_named-keys.js +65 -0
- package/dist/_recorder-chord.js +42 -0
- package/dist/_recording-guard.js +55 -0
- package/dist/_registration.js +49 -0
- package/dist/conflicts.d.ts +36 -0
- package/dist/conflicts.js +54 -0
- package/dist/constants.d.ts +16 -144
- package/dist/constants.js +55 -172
- package/dist/display-labels.d.ts +90 -0
- package/dist/display-labels.js +112 -0
- package/dist/format.d.ts +48 -12
- package/dist/format.js +35 -39
- package/dist/hint.d.ts +20 -0
- package/dist/hint.js +23 -0
- package/dist/hotkey-manager.d.ts +14 -12
- package/dist/hotkey-manager.js +70 -21
- package/dist/hotkey-recorder.d.ts +8 -8
- package/dist/hotkey-recorder.js +74 -15
- package/dist/hotkey-sequence-recorder.d.ts +13 -9
- package/dist/hotkey-sequence-recorder.js +90 -28
- package/dist/{hotkey.d.ts → hotkey.types.d.ts} +58 -126
- package/dist/index.d.ts +14 -9
- package/dist/index.js +10 -6
- package/dist/key-state-tracker.d.ts +4 -7
- package/dist/key-state-tracker.js +30 -27
- package/dist/key.types.d.ts +79 -0
- package/dist/match.d.ts +24 -11
- package/dist/match.js +19 -30
- package/dist/parse.d.ts +18 -15
- package/dist/parse.js +39 -22
- package/dist/platform.d.ts +41 -0
- package/dist/platform.js +52 -0
- package/dist/recorder-options.d.ts +31 -0
- package/dist/sequence-manager.d.ts +27 -15
- package/dist/sequence-manager.js +61 -30
- package/dist/validate.d.ts +16 -8
- package/dist/validate.js +8 -13
- package/package.json +8 -13
- package/dist/constants.cjs +0 -535
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -290
- package/dist/constants.js.map +0 -1
- package/dist/format.cjs +0 -91
- package/dist/format.cjs.map +0 -1
- package/dist/format.d.cts +0 -60
- package/dist/format.js.map +0 -1
- package/dist/hotkey-manager.cjs +0 -383
- package/dist/hotkey-manager.cjs.map +0 -1
- package/dist/hotkey-manager.d.cts +0 -230
- package/dist/hotkey-manager.js.map +0 -1
- package/dist/hotkey-recorder.cjs +0 -179
- package/dist/hotkey-recorder.cjs.map +0 -1
- package/dist/hotkey-recorder.d.cts +0 -116
- package/dist/hotkey-recorder.js.map +0 -1
- package/dist/hotkey-sequence-recorder.cjs +0 -192
- package/dist/hotkey-sequence-recorder.cjs.map +0 -1
- package/dist/hotkey-sequence-recorder.d.cts +0 -79
- package/dist/hotkey-sequence-recorder.js.map +0 -1
- package/dist/hotkey.d.cts +0 -301
- package/dist/index.cjs +0 -63
- package/dist/index.d.cts +0 -13
- package/dist/key-state-tracker.cjs +0 -197
- package/dist/key-state-tracker.cjs.map +0 -1
- package/dist/key-state-tracker.d.cts +0 -107
- package/dist/key-state-tracker.js.map +0 -1
- package/dist/manager.utils.cjs +0 -115
- package/dist/manager.utils.cjs.map +0 -1
- package/dist/manager.utils.d.cts +0 -13
- package/dist/manager.utils.d.ts +0 -13
- package/dist/manager.utils.js.map +0 -1
- package/dist/match.cjs +0 -153
- package/dist/match.cjs.map +0 -1
- package/dist/match.d.cts +0 -85
- package/dist/match.js.map +0 -1
- package/dist/parse.cjs +0 -228
- package/dist/parse.cjs.map +0 -1
- package/dist/parse.d.cts +0 -128
- package/dist/parse.js.map +0 -1
- package/dist/recorder-chord.cjs +0 -18
- package/dist/recorder-chord.cjs.map +0 -1
- package/dist/recorder-chord.js +0 -18
- package/dist/recorder-chord.js.map +0 -1
- package/dist/sequence-manager.cjs +0 -415
- package/dist/sequence-manager.cjs.map +0 -1
- package/dist/sequence-manager.d.cts +0 -157
- package/dist/sequence-manager.js.map +0 -1
- package/dist/validate.cjs +0 -116
- package/dist/validate.cjs.map +0 -1
- package/dist/validate.d.cts +0 -56
- package/dist/validate.js.map +0 -1
- package/src/constants.ts +0 -603
- package/src/format.ts +0 -142
- package/src/hotkey-manager.ts +0 -759
- package/src/hotkey-recorder.ts +0 -272
- package/src/hotkey-sequence-recorder.ts +0 -328
- package/src/hotkey.ts +0 -436
- package/src/index.ts +0 -11
- package/src/key-state-tracker.ts +0 -249
- package/src/manager.utils.ts +0 -231
- package/src/match.ts +0 -259
- package/src/parse.ts +0 -328
- package/src/recorder-chord.ts +0 -25
- package/src/sequence-manager.ts +0 -734
- package/src/validate.ts +0 -171
package/src/format.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
KEY_DISPLAY_SYMBOLS,
|
|
3
|
-
LINUX_MODIFIER_LABELS,
|
|
4
|
-
MAC_MODIFIER_LABELS,
|
|
5
|
-
MAC_MODIFIER_SYMBOLS,
|
|
6
|
-
MODIFIER_ALIASES,
|
|
7
|
-
MODIFIER_ORDER,
|
|
8
|
-
PUNCTUATION_KEY_DISPLAY_LABELS,
|
|
9
|
-
WINDOWS_MODIFIER_LABELS,
|
|
10
|
-
detectPlatform,
|
|
11
|
-
} from './constants'
|
|
12
|
-
import {
|
|
13
|
-
isModifierKey,
|
|
14
|
-
normalizeHotkeyFromParsed,
|
|
15
|
-
normalizeRegisterableHotkey,
|
|
16
|
-
} from './parse'
|
|
17
|
-
import type {
|
|
18
|
-
CanonicalModifier,
|
|
19
|
-
FormatDisplayOptions,
|
|
20
|
-
Hotkey,
|
|
21
|
-
ParsedHotkey,
|
|
22
|
-
RegisterableHotkey,
|
|
23
|
-
} from './hotkey'
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Converts a hotkey sequence array to a display string.
|
|
27
|
-
*
|
|
28
|
-
* @param sequence - Array of hotkey strings that form the sequence
|
|
29
|
-
* @returns A space-separated string (e.g. ['G','G'] → 'G G')
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* formatHotkeySequence(['G', 'G']) // 'G G'
|
|
34
|
-
* formatHotkeySequence(['D', 'I', 'W']) // 'D I W'
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export function formatHotkeySequence(sequence: Array<Hotkey>): string {
|
|
38
|
-
return sequence.join(' ')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Converts a ParsedHotkey back to a hotkey string.
|
|
43
|
-
*
|
|
44
|
-
* @param parsed - The parsed hotkey object
|
|
45
|
-
* @returns A hotkey string in canonical form
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* formatHotkey({ key: 'S', ctrl: true, shift: true, alt: false, meta: false, modifiers: ['Control', 'Shift'] })
|
|
50
|
-
* // Returns: 'Control+Shift+S'
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export function formatHotkey(parsed: ParsedHotkey): string {
|
|
54
|
-
const parts: Array<string> = []
|
|
55
|
-
|
|
56
|
-
// Add modifiers in canonical order
|
|
57
|
-
for (const modifier of MODIFIER_ORDER) {
|
|
58
|
-
if (parsed.modifiers.includes(modifier)) {
|
|
59
|
-
parts.push(modifier)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Add the key
|
|
64
|
-
parts.push(parsed.key)
|
|
65
|
-
|
|
66
|
-
return parts.join('+')
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Formats a hotkey for display in a user interface.
|
|
71
|
-
*
|
|
72
|
-
* On macOS, uses symbols (⌘⇧S) in the same modifier order as {@link normalizeHotkeyFromParsed}.
|
|
73
|
-
* On Windows/Linux, uses text (Ctrl+Shift+S) with `+` separators.
|
|
74
|
-
* The separator can be customized with `separatorToken`.
|
|
75
|
-
*
|
|
76
|
-
* @param hotkey - The hotkey string or ParsedHotkey to format
|
|
77
|
-
* @param options - Formatting options
|
|
78
|
-
* @returns A formatted string suitable for display
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* formatForDisplay('Mod+Shift+S', { platform: 'mac' })
|
|
83
|
-
* // Returns: '⌘ ⇧ S' (symbols separated by spaces on macOS)
|
|
84
|
-
*
|
|
85
|
-
* formatForDisplay('Mod+Shift+S', { platform: 'windows' })
|
|
86
|
-
* // Returns: 'Ctrl+Shift+S'
|
|
87
|
-
*
|
|
88
|
-
* formatForDisplay('Escape')
|
|
89
|
-
* // Returns: 'Esc' (on all platforms)
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export function formatForDisplay(
|
|
93
|
-
hotkey: RegisterableHotkey | (string & {}),
|
|
94
|
-
options: FormatDisplayOptions = {},
|
|
95
|
-
): string {
|
|
96
|
-
const platform = options.platform ?? detectPlatform()
|
|
97
|
-
const useSymbols = options.useSymbols ?? true
|
|
98
|
-
const separatorToken =
|
|
99
|
-
options.separatorToken ?? (platform === 'mac' && useSymbols ? ' ' : '+')
|
|
100
|
-
const normalizedHotkey = normalizeRegisterableHotkey(
|
|
101
|
-
hotkey as RegisterableHotkey,
|
|
102
|
-
platform,
|
|
103
|
-
)
|
|
104
|
-
return normalizedHotkey
|
|
105
|
-
.split('+')
|
|
106
|
-
.map((segment) => {
|
|
107
|
-
if (isModifierKey(segment)) {
|
|
108
|
-
const modifierToken = (MODIFIER_ALIASES[segment] ??
|
|
109
|
-
MODIFIER_ALIASES[segment.toLowerCase()]) as CanonicalModifier | 'Mod'
|
|
110
|
-
return platform === 'mac'
|
|
111
|
-
? useSymbols
|
|
112
|
-
? MAC_MODIFIER_SYMBOLS[modifierToken]
|
|
113
|
-
: MAC_MODIFIER_LABELS[modifierToken]
|
|
114
|
-
: platform === 'windows'
|
|
115
|
-
? WINDOWS_MODIFIER_LABELS[modifierToken]
|
|
116
|
-
: LINUX_MODIFIER_LABELS[modifierToken]
|
|
117
|
-
} else {
|
|
118
|
-
const keyDisplaySymbol =
|
|
119
|
-
useSymbols &&
|
|
120
|
-
KEY_DISPLAY_SYMBOLS[segment as keyof typeof KEY_DISPLAY_SYMBOLS]
|
|
121
|
-
if (keyDisplaySymbol) return keyDisplaySymbol
|
|
122
|
-
|
|
123
|
-
const punctuationKeyDisplayLabel =
|
|
124
|
-
!useSymbols &&
|
|
125
|
-
PUNCTUATION_KEY_DISPLAY_LABELS[
|
|
126
|
-
segment as keyof typeof PUNCTUATION_KEY_DISPLAY_LABELS
|
|
127
|
-
]
|
|
128
|
-
return punctuationKeyDisplayLabel || segment
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
.join(separatorToken)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @deprecated Use {@link formatForDisplay} instead with `useSymbols: false` option.
|
|
136
|
-
*/
|
|
137
|
-
export function formatWithLabels(
|
|
138
|
-
hotkey: RegisterableHotkey,
|
|
139
|
-
options: Omit<FormatDisplayOptions, 'useSymbols'> = {},
|
|
140
|
-
): string {
|
|
141
|
-
return formatForDisplay(hotkey, { ...options, useSymbols: false })
|
|
142
|
-
}
|