@tanstack/hotkeys 0.9.0 → 0.10.1

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.
Files changed (148) hide show
  1. package/dist/_event-target.js +1 -2
  2. package/dist/_keyboard-event.js +1 -2
  3. package/dist/_match.js +1 -2
  4. package/dist/_named-keys.d.ts +3 -5
  5. package/dist/_named-keys.js +1 -2
  6. package/dist/_recorder-chord.js +1 -2
  7. package/dist/_recording-guard.js +1 -2
  8. package/dist/_registration.js +1 -2
  9. package/dist/conflicts.d.ts +4 -7
  10. package/dist/conflicts.js +1 -2
  11. package/dist/constants.d.ts +14 -17
  12. package/dist/constants.js +8 -9
  13. package/dist/display-labels.d.ts +7 -10
  14. package/dist/display-labels.js +1 -2
  15. package/dist/format.d.ts +12 -14
  16. package/dist/format.js +17 -7
  17. package/dist/hint.d.ts +3 -6
  18. package/dist/hint.js +1 -2
  19. package/dist/hotkey-manager.d.ts +8 -10
  20. package/dist/hotkey-manager.js +21 -3
  21. package/dist/hotkey-recorder.d.ts +4 -7
  22. package/dist/hotkey-recorder.js +9 -6
  23. package/dist/hotkey-sequence-recorder.d.ts +5 -8
  24. package/dist/hotkey-sequence-recorder.js +6 -7
  25. package/dist/hotkey.types.d.ts +15 -18
  26. package/dist/key-state-tracker.d.ts +4 -7
  27. package/dist/key-state-tracker.js +6 -3
  28. package/dist/key.types.d.ts +17 -20
  29. package/dist/match.d.ts +8 -11
  30. package/dist/match.js +1 -2
  31. package/dist/parse.d.ts +11 -14
  32. package/dist/parse.js +5 -4
  33. package/dist/platform.d.ts +3 -6
  34. package/dist/platform.js +1 -2
  35. package/dist/recorder-options.d.ts +6 -9
  36. package/dist/sequence-manager.d.ts +11 -14
  37. package/dist/sequence-manager.js +12 -7
  38. package/dist/validate.d.ts +5 -8
  39. package/dist/validate.js +1 -2
  40. package/package.json +8 -13
  41. package/dist/_event-target.cjs +0 -73
  42. package/dist/_event-target.cjs.map +0 -1
  43. package/dist/_event-target.js.map +0 -1
  44. package/dist/_keyboard-event.cjs +0 -83
  45. package/dist/_keyboard-event.cjs.map +0 -1
  46. package/dist/_keyboard-event.js.map +0 -1
  47. package/dist/_match.cjs +0 -49
  48. package/dist/_match.cjs.map +0 -1
  49. package/dist/_match.js.map +0 -1
  50. package/dist/_named-keys.cjs +0 -68
  51. package/dist/_named-keys.cjs.map +0 -1
  52. package/dist/_named-keys.d.cts +0 -8
  53. package/dist/_named-keys.js.map +0 -1
  54. package/dist/_recorder-chord.cjs +0 -44
  55. package/dist/_recorder-chord.cjs.map +0 -1
  56. package/dist/_recorder-chord.js.map +0 -1
  57. package/dist/_recording-guard.cjs +0 -59
  58. package/dist/_recording-guard.cjs.map +0 -1
  59. package/dist/_recording-guard.js.map +0 -1
  60. package/dist/_registration.cjs +0 -54
  61. package/dist/_registration.cjs.map +0 -1
  62. package/dist/_registration.js.map +0 -1
  63. package/dist/conflicts.cjs +0 -55
  64. package/dist/conflicts.cjs.map +0 -1
  65. package/dist/conflicts.d.cts +0 -39
  66. package/dist/conflicts.js.map +0 -1
  67. package/dist/constants.cjs +0 -410
  68. package/dist/constants.cjs.map +0 -1
  69. package/dist/constants.d.cts +0 -165
  70. package/dist/constants.js.map +0 -1
  71. package/dist/display-labels.cjs +0 -119
  72. package/dist/display-labels.cjs.map +0 -1
  73. package/dist/display-labels.d.cts +0 -93
  74. package/dist/display-labels.js.map +0 -1
  75. package/dist/format.cjs +0 -85
  76. package/dist/format.cjs.map +0 -1
  77. package/dist/format.d.cts +0 -99
  78. package/dist/format.js.map +0 -1
  79. package/dist/hint.cjs +0 -24
  80. package/dist/hint.cjs.map +0 -1
  81. package/dist/hint.d.cts +0 -23
  82. package/dist/hint.js.map +0 -1
  83. package/dist/hotkey-manager.cjs +0 -414
  84. package/dist/hotkey-manager.cjs.map +0 -1
  85. package/dist/hotkey-manager.d.cts +0 -234
  86. package/dist/hotkey-manager.js.map +0 -1
  87. package/dist/hotkey-recorder.cjs +0 -235
  88. package/dist/hotkey-recorder.cjs.map +0 -1
  89. package/dist/hotkey-recorder.d.cts +0 -119
  90. package/dist/hotkey-recorder.js.map +0 -1
  91. package/dist/hotkey-sequence-recorder.cjs +0 -255
  92. package/dist/hotkey-sequence-recorder.cjs.map +0 -1
  93. package/dist/hotkey-sequence-recorder.d.cts +0 -86
  94. package/dist/hotkey-sequence-recorder.js.map +0 -1
  95. package/dist/hotkey.types.d.cts +0 -236
  96. package/dist/index.cjs +0 -71
  97. package/dist/index.d.cts +0 -18
  98. package/dist/key-state-tracker.cjs +0 -197
  99. package/dist/key-state-tracker.cjs.map +0 -1
  100. package/dist/key-state-tracker.d.cts +0 -107
  101. package/dist/key-state-tracker.js.map +0 -1
  102. package/dist/key.types.d.cts +0 -82
  103. package/dist/match.cjs +0 -144
  104. package/dist/match.cjs.map +0 -1
  105. package/dist/match.d.cts +0 -101
  106. package/dist/match.js.map +0 -1
  107. package/dist/parse.cjs +0 -245
  108. package/dist/parse.cjs.map +0 -1
  109. package/dist/parse.d.cts +0 -134
  110. package/dist/parse.js.map +0 -1
  111. package/dist/platform.cjs +0 -55
  112. package/dist/platform.cjs.map +0 -1
  113. package/dist/platform.d.cts +0 -44
  114. package/dist/platform.js.map +0 -1
  115. package/dist/recorder-options.d.cts +0 -34
  116. package/dist/sequence-manager.cjs +0 -441
  117. package/dist/sequence-manager.cjs.map +0 -1
  118. package/dist/sequence-manager.d.cts +0 -172
  119. package/dist/sequence-manager.js.map +0 -1
  120. package/dist/validate.cjs +0 -112
  121. package/dist/validate.cjs.map +0 -1
  122. package/dist/validate.d.cts +0 -67
  123. package/dist/validate.js.map +0 -1
  124. package/src/_event-target.ts +0 -157
  125. package/src/_keyboard-event.ts +0 -101
  126. package/src/_match.ts +0 -96
  127. package/src/_named-keys.ts +0 -62
  128. package/src/_recorder-chord.ts +0 -76
  129. package/src/_recording-guard.ts +0 -63
  130. package/src/_registration.ts +0 -79
  131. package/src/conflicts.ts +0 -125
  132. package/src/constants.ts +0 -455
  133. package/src/display-labels.ts +0 -123
  134. package/src/format.ts +0 -201
  135. package/src/hint.ts +0 -42
  136. package/src/hotkey-manager.ts +0 -814
  137. package/src/hotkey-recorder.ts +0 -348
  138. package/src/hotkey-sequence-recorder.ts +0 -410
  139. package/src/hotkey.types.ts +0 -269
  140. package/src/index.ts +0 -17
  141. package/src/key-state-tracker.ts +0 -261
  142. package/src/key.types.ts +0 -268
  143. package/src/match.ts +0 -210
  144. package/src/parse.ts +0 -369
  145. package/src/platform.ts +0 -66
  146. package/src/recorder-options.ts +0 -34
  147. package/src/sequence-manager.ts +0 -769
  148. package/src/validate.ts +0 -179
package/src/validate.ts DELETED
@@ -1,179 +0,0 @@
1
- import { ALL_KEYS, MODIFIER_ALIASES, normalizeKeyName } from './constants'
2
- import { splitHotkeyParts } from './_keyboard-event'
3
- import type { Hotkey } from './hotkey.types'
4
-
5
- /**
6
- * Validates a hotkey string and returns any warnings or errors.
7
- *
8
- * Checks for:
9
- * - Valid syntax (modifier+...+key format)
10
- * - Known modifiers
11
- * - Known keys
12
- *
13
- * @param hotkey - The hotkey string to validate
14
- * @returns A ValidationResult with validity status, warnings, and errors
15
- *
16
- * @example
17
- * ```ts
18
- * validateHotkey('Mod+S')
19
- * // { valid: true, warnings: [], errors: [] }
20
- *
21
- * validateHotkey('')
22
- * // { valid: false, warnings: [], errors: ['Hotkey cannot be empty'] }
23
- * ```
24
- */
25
- export function validateHotkey(
26
- hotkey: Hotkey | (string & {}),
27
- ): ValidationResult {
28
- const warnings: Array<string> = []
29
- const errors: Array<string> = []
30
-
31
- // Check for empty string
32
- if (!hotkey || hotkey.trim() === '') {
33
- return {
34
- valid: false,
35
- warnings: [],
36
- errors: ['Hotkey cannot be empty'],
37
- }
38
- }
39
-
40
- const parts = splitHotkeyParts(hotkey).map((p) => p.trim())
41
-
42
- // Must have at least one part (the key)
43
- if (parts.length === 0 || parts.some((p) => p === '')) {
44
- return {
45
- valid: false,
46
- warnings: [],
47
- errors: ['Invalid hotkey format: empty parts detected'],
48
- }
49
- }
50
-
51
- // Validate modifiers (all parts except the last)
52
- const modifierParts = parts.slice(0, -1)
53
- const keyPart = parts[parts.length - 1]!
54
-
55
- // Check for unknown modifiers
56
- for (const modifier of modifierParts) {
57
- const normalized =
58
- MODIFIER_ALIASES[modifier] ?? MODIFIER_ALIASES[modifier.toLowerCase()]
59
- if (!normalized) {
60
- errors.push(`Unknown modifier: '${modifier}'`)
61
- }
62
- }
63
-
64
- if (
65
- keyPart.length > 1 &&
66
- (keyPart.startsWith('[') || keyPart.endsWith(']')) &&
67
- !/^\[[A-Za-z][A-Za-z0-9]*\]$/.test(keyPart)
68
- ) {
69
- errors.push(
70
- 'Invalid physical key: use a bracketed KeyboardEvent.code, such as [KeyS]',
71
- )
72
- }
73
-
74
- // Check if key is known
75
- const normalizedKey = normalizeKeyName(keyPart)
76
- if (!isKnownKey(normalizedKey) && !isKnownKey(keyPart)) {
77
- warnings.push(
78
- `Unknown key: '${keyPart}'. This may still work but won't have type-safe autocomplete.`,
79
- )
80
- }
81
-
82
- return {
83
- valid: errors.length === 0,
84
- warnings,
85
- errors,
86
- }
87
- }
88
-
89
- /**
90
- * Checks if a key is in the known keys set.
91
- */
92
- function isKnownKey(key: string): boolean {
93
- if (/^\[[A-Za-z][A-Za-z0-9]*\]$/.test(key)) return true
94
- if (Array.from(key).length === 1) return true
95
- // Check direct match
96
- if (ALL_KEYS.has(key as any)) {
97
- return true
98
- }
99
-
100
- // Check uppercase version for letters
101
- if (key.length === 1 && ALL_KEYS.has(key.toUpperCase() as any)) {
102
- return true
103
- }
104
-
105
- // Check common aliases
106
- const aliases: Record<string, boolean> = {
107
- Esc: true,
108
- Return: true,
109
- Space: true,
110
- ' ': true,
111
- Del: true,
112
- Up: true,
113
- Down: true,
114
- Left: true,
115
- Right: true,
116
- }
117
-
118
- return key in aliases
119
- }
120
-
121
- /**
122
- * Validates a hotkey and throws an error if invalid.
123
- * Useful for development-time validation.
124
- *
125
- * @param hotkey - The hotkey string to validate
126
- * @throws Error if the hotkey is invalid
127
- *
128
- * @example
129
- * ```ts
130
- * assertValidHotkey('Mod+S') // OK
131
- * assertValidHotkey('') // Throws Error: Invalid hotkey: Hotkey cannot be empty
132
- * ```
133
- */
134
- export function assertValidHotkey(hotkey: Hotkey | (string & {})): void {
135
- const result = validateHotkey(hotkey)
136
- if (!result.valid) {
137
- throw new Error(`Invalid hotkey '${hotkey}': ${result.errors.join(', ')}`)
138
- }
139
- }
140
-
141
- /**
142
- * Validates a hotkey and logs warnings to the console.
143
- * Useful for development-time feedback.
144
- *
145
- * @param hotkey - The hotkey string to validate
146
- * @returns True if the hotkey is valid (may still have warnings)
147
- *
148
- * @example
149
- * ```ts
150
- * checkHotkey('Alt+C')
151
- * // Console: Warning: Alt+C may not work reliably on macOS...
152
- * // Returns: true
153
- * ```
154
- */
155
- export function checkHotkey(hotkey: Hotkey | (string & {})): boolean {
156
- const result = validateHotkey(hotkey)
157
-
158
- if (result.errors.length > 0) {
159
- console.error(`Hotkey '${hotkey}' errors:`, result.errors.join('; '))
160
- }
161
-
162
- if (result.warnings.length > 0) {
163
- console.warn(`Hotkey '${hotkey}' warnings:`, result.warnings.join('; '))
164
- }
165
-
166
- return result.valid
167
- }
168
-
169
- /**
170
- * Result of validating a hotkey string.
171
- */
172
- export interface ValidationResult {
173
- /** Whether the hotkey is valid (can still have warnings) */
174
- valid: boolean
175
- /** Warning messages about potential issues */
176
- warnings: Array<string>
177
- /** Error messages about invalid syntax */
178
- errors: Array<string>
179
- }