@redis-ui/components 47.4.0 → 47.5.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 (32) hide show
  1. package/dist/MultiSelect/components/Content/components/SelectAll/SelectAll.cjs +11 -7
  2. package/dist/MultiSelect/components/Content/components/SelectAll/SelectAll.js +12 -8
  3. package/dist/node_modules/@tanstack/hotkeys/dist/constants.cjs +389 -0
  4. package/dist/node_modules/@tanstack/hotkeys/dist/constants.js +383 -0
  5. package/dist/node_modules/@tanstack/hotkeys/dist/format.cjs +22 -0
  6. package/dist/node_modules/@tanstack/hotkeys/dist/format.js +22 -0
  7. package/dist/node_modules/@tanstack/hotkeys/dist/hotkey-manager.cjs +363 -0
  8. package/dist/node_modules/@tanstack/hotkeys/dist/hotkey-manager.js +363 -0
  9. package/dist/node_modules/@tanstack/hotkeys/dist/manager.utils.cjs +111 -0
  10. package/dist/node_modules/@tanstack/hotkeys/dist/manager.utils.js +107 -0
  11. package/dist/node_modules/@tanstack/hotkeys/dist/match.cjs +59 -0
  12. package/dist/node_modules/@tanstack/hotkeys/dist/match.js +59 -0
  13. package/dist/node_modules/@tanstack/hotkeys/dist/parse.cjs +143 -0
  14. package/dist/node_modules/@tanstack/hotkeys/dist/parse.js +141 -0
  15. package/dist/node_modules/@tanstack/react-hotkeys/dist/HotkeysProvider.cjs +10 -0
  16. package/dist/node_modules/@tanstack/react-hotkeys/dist/HotkeysProvider.js +8 -0
  17. package/dist/node_modules/@tanstack/react-hotkeys/dist/useHotkey.cjs +121 -0
  18. package/dist/node_modules/@tanstack/react-hotkeys/dist/useHotkey.js +120 -0
  19. package/dist/node_modules/@tanstack/react-hotkeys/dist/utils.cjs +9 -0
  20. package/dist/node_modules/@tanstack/react-hotkeys/dist/utils.js +9 -0
  21. package/dist/node_modules/@tanstack/store/dist/alien.cjs +183 -0
  22. package/dist/node_modules/@tanstack/store/dist/alien.js +182 -0
  23. package/dist/node_modules/@tanstack/store/dist/atom.cjs +161 -0
  24. package/dist/node_modules/@tanstack/store/dist/atom.js +160 -0
  25. package/dist/node_modules/@tanstack/store/dist/store.cjs +25 -0
  26. package/dist/node_modules/@tanstack/store/dist/store.js +25 -0
  27. package/package.json +3 -3
  28. package/skills/redis-ui-components/SKILL.md +1 -1
  29. package/skills/redis-ui-components/references/Icons.md +3 -3
  30. package/skills/redis-ui-components/references/SideBar.md +8 -8
  31. package/dist/node_modules/react-hotkeys-hook/dist/react-hotkeys-hook.esm.cjs +0 -289
  32. package/dist/node_modules/react-hotkeys-hook/dist/react-hotkeys-hook.esm.js +0 -288
@@ -0,0 +1,363 @@
1
+ import { detectPlatform, normalizeKeyName } from "./constants.js";
2
+ import { parseHotkey, rawHotkeyToParsedHotkey } from "./parse.js";
3
+ import { formatHotkey } from "./format.js";
4
+ import { matchesKeyboardEvent } from "./match.js";
5
+ import { defaultHotkeyOptions, getDefaultIgnoreInputs, handleConflict, isEventForTarget, shouldIgnoreInputEvent } from "./manager.utils.js";
6
+ import { Store } from "../../store/dist/store.js";
7
+ //#region ../../node_modules/@tanstack/hotkeys/dist/hotkey-manager.js
8
+ var registrationIdCounter = 0;
9
+ /**
10
+ * Generates a unique ID for hotkey registrations.
11
+ */
12
+ function generateId() {
13
+ return `hotkey_${++registrationIdCounter}`;
14
+ }
15
+ /**
16
+ * Singleton manager for hotkey registrations.
17
+ *
18
+ * This class provides a centralized way to register and manage keyboard hotkeys.
19
+ * It uses a single event listener for efficiency, regardless of how many hotkeys
20
+ * are registered.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const manager = HotkeyManager.getInstance()
25
+ *
26
+ * const unregister = manager.register('Mod+S', (event, context) => {
27
+ * console.log('Save triggered!')
28
+ * })
29
+ *
30
+ * // Later, to unregister:
31
+ * unregister()
32
+ * ```
33
+ */
34
+ var HotkeyManager = class HotkeyManager {
35
+ static #instance = null;
36
+ #platform;
37
+ #targetListeners = /* @__PURE__ */ new Map();
38
+ #targetRegistrations = /* @__PURE__ */ new Map();
39
+ constructor() {
40
+ this.registrations = new Store(/* @__PURE__ */ new Map());
41
+ this.#platform = detectPlatform();
42
+ }
43
+ /**
44
+ * Gets the singleton instance of HotkeyManager.
45
+ */
46
+ static getInstance() {
47
+ if (!HotkeyManager.#instance) HotkeyManager.#instance = new HotkeyManager();
48
+ return HotkeyManager.#instance;
49
+ }
50
+ /**
51
+ * Resets the singleton instance. Useful for testing.
52
+ */
53
+ static resetInstance() {
54
+ if (HotkeyManager.#instance) {
55
+ HotkeyManager.#instance.destroy();
56
+ HotkeyManager.#instance = null;
57
+ }
58
+ }
59
+ /**
60
+ * Registers a hotkey handler and returns a handle for updating the registration.
61
+ *
62
+ * The returned handle allows updating the callback and options without
63
+ * re-registering, which is useful for avoiding stale closures in React.
64
+ *
65
+ * @param hotkey - The hotkey string (e.g., 'Mod+S') or RawHotkey object
66
+ * @param callback - The function to call when the hotkey is pressed
67
+ * @param options - Options for the hotkey behavior
68
+ * @returns A handle for managing the registration
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const handle = manager.register('Mod+S', callback)
73
+ *
74
+ * // Update callback without re-registering (avoids stale closures)
75
+ * handle.callback = newCallback
76
+ *
77
+ * // Update options
78
+ * handle.setOptions({ enabled: false })
79
+ *
80
+ * // Unregister when done
81
+ * handle.unregister()
82
+ * ```
83
+ */
84
+ register(hotkey, callback, options = {}) {
85
+ if (typeof document === "undefined" && !options.target) {
86
+ let currentCallback = callback;
87
+ return {
88
+ id: generateId(),
89
+ unregister: () => {},
90
+ get callback() {
91
+ return currentCallback;
92
+ },
93
+ set callback(newCallback) {
94
+ currentCallback = newCallback;
95
+ },
96
+ setOptions: () => {},
97
+ get isActive() {
98
+ return false;
99
+ }
100
+ };
101
+ }
102
+ const id = generateId();
103
+ const platform = options.platform ?? this.#platform;
104
+ const parsedHotkey = typeof hotkey === "string" ? parseHotkey(hotkey, platform) : rawHotkeyToParsedHotkey(hotkey, platform);
105
+ const hotkeyStr = typeof hotkey === "string" ? hotkey : formatHotkey(parsedHotkey);
106
+ const target = options.target ?? document;
107
+ const conflictBehavior = options.conflictBehavior ?? "warn";
108
+ const conflictingRegistration = this.#findConflictingRegistration(hotkeyStr, target);
109
+ if (conflictingRegistration) handleConflict(conflictingRegistration.id, hotkeyStr, conflictBehavior, (id) => this.#unregister(id));
110
+ const resolvedIgnoreInputs = options.ignoreInputs ?? getDefaultIgnoreInputs(parsedHotkey);
111
+ const registration = {
112
+ id,
113
+ hotkey: hotkeyStr,
114
+ parsedHotkey,
115
+ callback,
116
+ options: {
117
+ ...defaultHotkeyOptions,
118
+ requireReset: false,
119
+ ...options,
120
+ platform,
121
+ ignoreInputs: resolvedIgnoreInputs
122
+ },
123
+ hasFired: false,
124
+ triggerCount: 0,
125
+ target
126
+ };
127
+ this.registrations.setState((prev) => new Map(prev).set(id, registration));
128
+ if (!this.#targetRegistrations.has(target)) this.#targetRegistrations.set(target, /* @__PURE__ */ new Set());
129
+ this.#targetRegistrations.get(target).add(id);
130
+ this.#ensureListenersForTarget(target);
131
+ const manager = this;
132
+ return {
133
+ get id() {
134
+ return id;
135
+ },
136
+ unregister: () => {
137
+ manager.#unregister(id);
138
+ },
139
+ get callback() {
140
+ return manager.registrations.state.get(id)?.callback ?? callback;
141
+ },
142
+ set callback(newCallback) {
143
+ const reg = manager.registrations.state.get(id);
144
+ if (reg) reg.callback = newCallback;
145
+ },
146
+ setOptions: (newOptions) => {
147
+ manager.registrations.setState((prev) => {
148
+ const reg = prev.get(id);
149
+ if (reg) {
150
+ const next = new Map(prev);
151
+ next.set(id, {
152
+ ...reg,
153
+ options: {
154
+ ...reg.options,
155
+ ...newOptions
156
+ }
157
+ });
158
+ return next;
159
+ }
160
+ return prev;
161
+ });
162
+ },
163
+ get isActive() {
164
+ return manager.registrations.state.has(id);
165
+ }
166
+ };
167
+ }
168
+ /**
169
+ * Unregisters a hotkey by its registration ID.
170
+ */
171
+ #unregister(id) {
172
+ const registration = this.registrations.state.get(id);
173
+ if (!registration) return;
174
+ const target = registration.target;
175
+ this.registrations.setState((prev) => {
176
+ const next = new Map(prev);
177
+ next.delete(id);
178
+ return next;
179
+ });
180
+ const targetRegs = this.#targetRegistrations.get(target);
181
+ if (targetRegs) {
182
+ targetRegs.delete(id);
183
+ if (targetRegs.size === 0) this.#removeListenersForTarget(target);
184
+ }
185
+ }
186
+ /**
187
+ * Ensures event listeners are attached for a specific target.
188
+ */
189
+ #ensureListenersForTarget(target) {
190
+ if (typeof document === "undefined") return;
191
+ if (this.#targetListeners.has(target)) return;
192
+ const keydownHandler = this.#createTargetKeyDownHandler(target);
193
+ const keyupHandler = this.#createTargetKeyUpHandler(target);
194
+ target.addEventListener("keydown", keydownHandler);
195
+ target.addEventListener("keyup", keyupHandler);
196
+ this.#targetListeners.set(target, {
197
+ keydown: keydownHandler,
198
+ keyup: keyupHandler
199
+ });
200
+ }
201
+ /**
202
+ * Removes event listeners for a specific target.
203
+ */
204
+ #removeListenersForTarget(target) {
205
+ if (typeof document === "undefined") return;
206
+ const listeners = this.#targetListeners.get(target);
207
+ if (!listeners) return;
208
+ target.removeEventListener("keydown", listeners.keydown);
209
+ target.removeEventListener("keyup", listeners.keyup);
210
+ this.#targetListeners.delete(target);
211
+ this.#targetRegistrations.delete(target);
212
+ }
213
+ /**
214
+ * Processes keyboard events for a specific target and event type.
215
+ */
216
+ #processTargetEvent(event, target, eventType) {
217
+ const targetRegs = this.#targetRegistrations.get(target);
218
+ if (!targetRegs) return;
219
+ for (const id of targetRegs) {
220
+ const registration = this.registrations.state.get(id);
221
+ if (!registration) continue;
222
+ if (!isEventForTarget(event, target)) continue;
223
+ if (!registration.options.enabled) continue;
224
+ if (registration.options.ignoreInputs !== false) {
225
+ if (shouldIgnoreInputEvent(event, target, registration.target)) continue;
226
+ }
227
+ if (eventType === "keydown") {
228
+ if (registration.options.eventType !== "keydown") continue;
229
+ if (matchesKeyboardEvent(event, registration.parsedHotkey, registration.options.platform)) {
230
+ if (registration.options.preventDefault) event.preventDefault();
231
+ if (registration.options.stopPropagation) event.stopPropagation();
232
+ if (!registration.options.requireReset || !registration.hasFired) {
233
+ this.#executeHotkeyCallback(registration, event);
234
+ if (registration.options.requireReset) registration.hasFired = true;
235
+ }
236
+ }
237
+ } else {
238
+ if (registration.options.eventType === "keyup") {
239
+ if (matchesKeyboardEvent(event, registration.parsedHotkey, registration.options.platform)) this.#executeHotkeyCallback(registration, event);
240
+ }
241
+ if (registration.options.requireReset && registration.hasFired) {
242
+ if (this.#shouldResetRegistration(registration, event)) registration.hasFired = false;
243
+ }
244
+ }
245
+ }
246
+ }
247
+ /**
248
+ * Executes a hotkey callback with proper event handling.
249
+ */
250
+ #executeHotkeyCallback(registration, event) {
251
+ if (registration.options.preventDefault) event.preventDefault();
252
+ if (registration.options.stopPropagation) event.stopPropagation();
253
+ registration.triggerCount++;
254
+ this.registrations.setState((prev) => new Map(prev));
255
+ const context = {
256
+ hotkey: registration.hotkey,
257
+ parsedHotkey: registration.parsedHotkey
258
+ };
259
+ registration.callback(event, context);
260
+ }
261
+ /**
262
+ * Creates a keydown handler for a specific target.
263
+ */
264
+ #createTargetKeyDownHandler(target) {
265
+ return (event) => {
266
+ this.#processTargetEvent(event, target, "keydown");
267
+ };
268
+ }
269
+ /**
270
+ * Creates a keyup handler for a specific target.
271
+ */
272
+ #createTargetKeyUpHandler(target) {
273
+ return (event) => {
274
+ this.#processTargetEvent(event, target, "keyup");
275
+ };
276
+ }
277
+ /**
278
+ * Finds an existing registration with the same hotkey and target.
279
+ */
280
+ #findConflictingRegistration(hotkey, target) {
281
+ for (const registration of this.registrations.state.values()) if (registration.hotkey === hotkey && registration.target === target) return registration;
282
+ return null;
283
+ }
284
+ /**
285
+ * Determines if a registration should be reset based on the keyup event.
286
+ */
287
+ #shouldResetRegistration(registration, event) {
288
+ const parsed = registration.parsedHotkey;
289
+ const releasedKey = normalizeKeyName(event.key);
290
+ const parsedKeyNormalized = parsed.key.length === 1 ? parsed.key.toUpperCase() : parsed.key;
291
+ if ((releasedKey.length === 1 ? releasedKey.toUpperCase() : releasedKey) === parsedKeyNormalized) return true;
292
+ if (parsed.ctrl && releasedKey === "Control") return true;
293
+ if (parsed.shift && releasedKey === "Shift") return true;
294
+ if (parsed.alt && releasedKey === "Alt") return true;
295
+ if (parsed.meta && releasedKey === "Meta") return true;
296
+ return false;
297
+ }
298
+ /**
299
+ * Triggers a registration's callback programmatically from devtools.
300
+ * Creates a synthetic KeyboardEvent and invokes the callback.
301
+ *
302
+ * @param id - The registration ID to trigger
303
+ * @returns True if the registration was found and triggered
304
+ */
305
+ triggerRegistration(id) {
306
+ const registration = this.registrations.state.get(id);
307
+ if (!registration) return false;
308
+ const parsed = registration.parsedHotkey;
309
+ const syntheticEvent = new KeyboardEvent(registration.options.eventType ?? "keydown", {
310
+ key: parsed.key,
311
+ ctrlKey: parsed.ctrl,
312
+ shiftKey: parsed.shift,
313
+ altKey: parsed.alt,
314
+ metaKey: parsed.meta,
315
+ bubbles: true,
316
+ cancelable: true
317
+ });
318
+ registration.triggerCount++;
319
+ this.registrations.setState((prev) => new Map(prev));
320
+ registration.callback(syntheticEvent, {
321
+ hotkey: registration.hotkey,
322
+ parsedHotkey: registration.parsedHotkey
323
+ });
324
+ return true;
325
+ }
326
+ /**
327
+ * Gets the number of registered hotkeys.
328
+ */
329
+ getRegistrationCount() {
330
+ return this.registrations.state.size;
331
+ }
332
+ /**
333
+ * Checks if a specific hotkey is registered.
334
+ *
335
+ * @param hotkey - The hotkey string to check
336
+ * @param target - Optional target element to match (if provided, both hotkey and target must match)
337
+ * @returns True if a matching registration exists
338
+ */
339
+ isRegistered(hotkey, target) {
340
+ for (const registration of this.registrations.state.values()) if (registration.hotkey === hotkey) {
341
+ if (target === void 0 || registration.target === target) return true;
342
+ }
343
+ return false;
344
+ }
345
+ /**
346
+ * Destroys the manager and removes all listeners.
347
+ */
348
+ destroy() {
349
+ for (const target of this.#targetListeners.keys()) this.#removeListenersForTarget(target);
350
+ this.registrations.setState(() => /* @__PURE__ */ new Map());
351
+ this.#targetListeners.clear();
352
+ this.#targetRegistrations.clear();
353
+ }
354
+ };
355
+ /**
356
+ * Gets the singleton HotkeyManager instance.
357
+ * Convenience function for accessing the manager.
358
+ */
359
+ function getHotkeyManager() {
360
+ return HotkeyManager.getInstance();
361
+ }
362
+ //#endregion
363
+ export { getHotkeyManager };
@@ -0,0 +1,111 @@
1
+ //#region ../../node_modules/@tanstack/hotkeys/dist/manager.utils.js
2
+ /**
3
+ * Default options for hotkey/sequence registration.
4
+ * Omitted: platform, target (resolved at registration), requireReset (HotkeyManager only).
5
+ */
6
+ var defaultHotkeyOptions = {
7
+ preventDefault: true,
8
+ stopPropagation: true,
9
+ eventType: "keydown",
10
+ enabled: true,
11
+ ignoreInputs: true,
12
+ conflictBehavior: "warn"
13
+ };
14
+ /**
15
+ * Computes the default ignoreInputs value based on the hotkey.
16
+ * Ctrl/Meta shortcuts and Escape fire in inputs; single keys and Shift/Alt combos are ignored.
17
+ */
18
+ function getDefaultIgnoreInputs(parsedHotkey) {
19
+ if (parsedHotkey.ctrl || parsedHotkey.meta) return false;
20
+ if (parsedHotkey.key === "Escape") return false;
21
+ return true;
22
+ }
23
+ /**
24
+ * Checks if an element is an input-like element that should be ignored for hotkeys.
25
+ *
26
+ * This includes:
27
+ * - HTMLInputElement (all input types except button, submit, reset)
28
+ * - HTMLTextAreaElement
29
+ * - HTMLSelectElement
30
+ * - Elements with contentEditable enabled
31
+ *
32
+ * Button-type inputs (button, submit, reset) are excluded so hotkeys like
33
+ * Mod+S and Escape fire when the user has tabbed to a form button.
34
+ */
35
+ function isInputElement(element) {
36
+ if (!element) return false;
37
+ if (element instanceof HTMLInputElement) {
38
+ const type = element.type.toLowerCase();
39
+ if (type === "button" || type === "submit" || type === "reset") return false;
40
+ return true;
41
+ }
42
+ if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) return true;
43
+ if (element instanceof HTMLElement && element.isContentEditable) return true;
44
+ return false;
45
+ }
46
+ /**
47
+ * Returns the focused element for the document associated with where hotkey
48
+ * listeners are attached (listener root). Use this instead of the global
49
+ * `document.activeElement` so registrations scoped to an iframe (or another
50
+ * document) read focus from the correct tree.
51
+ */
52
+ function getActiveElementForListenerTarget(target) {
53
+ if (typeof document === "undefined") return null;
54
+ if (typeof Document !== "undefined" && target instanceof Document || typeof Node !== "undefined" && target.nodeType === Node.DOCUMENT_NODE) return target.activeElement;
55
+ if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) return target.ownerDocument.activeElement ?? null;
56
+ return target.document.activeElement ?? null;
57
+ }
58
+ /**
59
+ * Returns whether an event should be ignored because it originated from an
60
+ * input-like element other than the registration target.
61
+ *
62
+ * This checks:
63
+ * - the currently focused element for the listener target
64
+ * - the event's composed path (for shadow DOM)
65
+ * - the event target as a final fallback
66
+ */
67
+ function shouldIgnoreInputEvent(event, listenerTarget, registrationTarget) {
68
+ const focused = getActiveElementForListenerTarget(listenerTarget);
69
+ if (focused && isInputElement(focused) && focused !== registrationTarget) return true;
70
+ if (event.composedPath().some((element) => isInputElement(element) && element !== registrationTarget)) return true;
71
+ return isInputElement(event.target) && event.target !== registrationTarget;
72
+ }
73
+ /**
74
+ * Checks if an event is for the given target (originated from or bubbled to it).
75
+ *
76
+ * For document/window targets, also accepts document.documentElement as currentTarget
77
+ * to handle Brave and other browsers where currentTarget may be documentElement
78
+ * instead of document when listeners are attached to document.
79
+ */
80
+ function isEventForTarget(event, target) {
81
+ if (target === document || target === window) return event.currentTarget === target || event.currentTarget === document.documentElement;
82
+ if (target === window) return event.currentTarget === window || event.currentTarget === document || event.currentTarget === document.documentElement;
83
+ if (target instanceof HTMLElement) {
84
+ if (event.currentTarget === target) return true;
85
+ if (event.target instanceof Node && target.contains(event.target)) return true;
86
+ }
87
+ return false;
88
+ }
89
+ /**
90
+ * Handles conflicts between registrations based on conflict behavior.
91
+ *
92
+ * @param conflictingId - The ID of the conflicting registration
93
+ * @param keyDisplay - Display string for the conflicting key/sequence (for error messages)
94
+ * @param conflictBehavior - How to handle the conflict
95
+ * @param unregister - Function to unregister by ID
96
+ */
97
+ function handleConflict(conflictingId, keyDisplay, conflictBehavior, unregister) {
98
+ if (conflictBehavior === "allow") return;
99
+ if (conflictBehavior === "warn") {
100
+ console.warn(`'${keyDisplay}' is already registered. Multiple handlers will be triggered. Use conflictBehavior: 'replace' to replace the existing handler, or conflictBehavior: 'allow' to suppress this warning.`);
101
+ return;
102
+ }
103
+ if (conflictBehavior === "error") throw new Error(`'${keyDisplay}' is already registered. Use conflictBehavior: 'replace' to replace the existing handler, or conflictBehavior: 'allow' to allow multiple registrations.`);
104
+ unregister(conflictingId);
105
+ }
106
+ //#endregion
107
+ exports.defaultHotkeyOptions = defaultHotkeyOptions;
108
+ exports.getDefaultIgnoreInputs = getDefaultIgnoreInputs;
109
+ exports.handleConflict = handleConflict;
110
+ exports.isEventForTarget = isEventForTarget;
111
+ exports.shouldIgnoreInputEvent = shouldIgnoreInputEvent;
@@ -0,0 +1,107 @@
1
+ //#region ../../node_modules/@tanstack/hotkeys/dist/manager.utils.js
2
+ /**
3
+ * Default options for hotkey/sequence registration.
4
+ * Omitted: platform, target (resolved at registration), requireReset (HotkeyManager only).
5
+ */
6
+ var defaultHotkeyOptions = {
7
+ preventDefault: true,
8
+ stopPropagation: true,
9
+ eventType: "keydown",
10
+ enabled: true,
11
+ ignoreInputs: true,
12
+ conflictBehavior: "warn"
13
+ };
14
+ /**
15
+ * Computes the default ignoreInputs value based on the hotkey.
16
+ * Ctrl/Meta shortcuts and Escape fire in inputs; single keys and Shift/Alt combos are ignored.
17
+ */
18
+ function getDefaultIgnoreInputs(parsedHotkey) {
19
+ if (parsedHotkey.ctrl || parsedHotkey.meta) return false;
20
+ if (parsedHotkey.key === "Escape") return false;
21
+ return true;
22
+ }
23
+ /**
24
+ * Checks if an element is an input-like element that should be ignored for hotkeys.
25
+ *
26
+ * This includes:
27
+ * - HTMLInputElement (all input types except button, submit, reset)
28
+ * - HTMLTextAreaElement
29
+ * - HTMLSelectElement
30
+ * - Elements with contentEditable enabled
31
+ *
32
+ * Button-type inputs (button, submit, reset) are excluded so hotkeys like
33
+ * Mod+S and Escape fire when the user has tabbed to a form button.
34
+ */
35
+ function isInputElement(element) {
36
+ if (!element) return false;
37
+ if (element instanceof HTMLInputElement) {
38
+ const type = element.type.toLowerCase();
39
+ if (type === "button" || type === "submit" || type === "reset") return false;
40
+ return true;
41
+ }
42
+ if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) return true;
43
+ if (element instanceof HTMLElement && element.isContentEditable) return true;
44
+ return false;
45
+ }
46
+ /**
47
+ * Returns the focused element for the document associated with where hotkey
48
+ * listeners are attached (listener root). Use this instead of the global
49
+ * `document.activeElement` so registrations scoped to an iframe (or another
50
+ * document) read focus from the correct tree.
51
+ */
52
+ function getActiveElementForListenerTarget(target) {
53
+ if (typeof document === "undefined") return null;
54
+ if (typeof Document !== "undefined" && target instanceof Document || typeof Node !== "undefined" && target.nodeType === Node.DOCUMENT_NODE) return target.activeElement;
55
+ if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) return target.ownerDocument.activeElement ?? null;
56
+ return target.document.activeElement ?? null;
57
+ }
58
+ /**
59
+ * Returns whether an event should be ignored because it originated from an
60
+ * input-like element other than the registration target.
61
+ *
62
+ * This checks:
63
+ * - the currently focused element for the listener target
64
+ * - the event's composed path (for shadow DOM)
65
+ * - the event target as a final fallback
66
+ */
67
+ function shouldIgnoreInputEvent(event, listenerTarget, registrationTarget) {
68
+ const focused = getActiveElementForListenerTarget(listenerTarget);
69
+ if (focused && isInputElement(focused) && focused !== registrationTarget) return true;
70
+ if (event.composedPath().some((element) => isInputElement(element) && element !== registrationTarget)) return true;
71
+ return isInputElement(event.target) && event.target !== registrationTarget;
72
+ }
73
+ /**
74
+ * Checks if an event is for the given target (originated from or bubbled to it).
75
+ *
76
+ * For document/window targets, also accepts document.documentElement as currentTarget
77
+ * to handle Brave and other browsers where currentTarget may be documentElement
78
+ * instead of document when listeners are attached to document.
79
+ */
80
+ function isEventForTarget(event, target) {
81
+ if (target === document || target === window) return event.currentTarget === target || event.currentTarget === document.documentElement;
82
+ if (target === window) return event.currentTarget === window || event.currentTarget === document || event.currentTarget === document.documentElement;
83
+ if (target instanceof HTMLElement) {
84
+ if (event.currentTarget === target) return true;
85
+ if (event.target instanceof Node && target.contains(event.target)) return true;
86
+ }
87
+ return false;
88
+ }
89
+ /**
90
+ * Handles conflicts between registrations based on conflict behavior.
91
+ *
92
+ * @param conflictingId - The ID of the conflicting registration
93
+ * @param keyDisplay - Display string for the conflicting key/sequence (for error messages)
94
+ * @param conflictBehavior - How to handle the conflict
95
+ * @param unregister - Function to unregister by ID
96
+ */
97
+ function handleConflict(conflictingId, keyDisplay, conflictBehavior, unregister) {
98
+ if (conflictBehavior === "allow") return;
99
+ if (conflictBehavior === "warn") {
100
+ console.warn(`'${keyDisplay}' is already registered. Multiple handlers will be triggered. Use conflictBehavior: 'replace' to replace the existing handler, or conflictBehavior: 'allow' to suppress this warning.`);
101
+ return;
102
+ }
103
+ if (conflictBehavior === "error") throw new Error(`'${keyDisplay}' is already registered. Use conflictBehavior: 'replace' to replace the existing handler, or conflictBehavior: 'allow' to allow multiple registrations.`);
104
+ unregister(conflictingId);
105
+ }
106
+ //#endregion
107
+ export { defaultHotkeyOptions, getDefaultIgnoreInputs, handleConflict, isEventForTarget, shouldIgnoreInputEvent };
@@ -0,0 +1,59 @@
1
+ const require_constants = require("./constants.cjs");
2
+ const require_parse = require("./parse.cjs");
3
+ //#region ../../node_modules/@tanstack/hotkeys/dist/match.js
4
+ /**
5
+ * Checks if a KeyboardEvent matches a hotkey.
6
+ *
7
+ * Uses the `key` property from KeyboardEvent for matching, with a fallback to `code`
8
+ * for letter keys, digit keys (0-9), and punctuation keys when `key` produces special
9
+ * characters (e.g., macOS Option+letter, Shift+number, or Option+punctuation).
10
+ * Letter keys are matched case-insensitively.
11
+ *
12
+ * Also handles "dead key" events where `event.key` is `'Dead'` instead of the expected
13
+ * character. This commonly occurs on macOS with Option+letter combinations (e.g., Option+E,
14
+ * Option+I, Option+U, Option+N) and on Windows/Linux with international keyboard layouts.
15
+ * In these cases, `event.code` is used to determine the physical key.
16
+ *
17
+ * @param event - The KeyboardEvent to check
18
+ * @param hotkey - The hotkey string or ParsedHotkey to match against
19
+ * @param platform - The target platform for resolving 'Mod' (defaults to auto-detection)
20
+ * @returns True if the event matches the hotkey
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * document.addEventListener('keydown', (event) => {
25
+ * if (matchesKeyboardEvent(event, 'Mod+S')) {
26
+ * event.preventDefault()
27
+ * handleSave()
28
+ * }
29
+ * })
30
+ * ```
31
+ */
32
+ function matchesKeyboardEvent(event, hotkey, platform = require_constants.detectPlatform()) {
33
+ const parsed = typeof hotkey === "string" ? require_parse.parseHotkey(hotkey, platform) : hotkey;
34
+ if (event.ctrlKey !== parsed.ctrl) return false;
35
+ if (event.shiftKey !== parsed.shift) return false;
36
+ if (event.altKey !== parsed.alt) return false;
37
+ if (event.metaKey !== parsed.meta) return false;
38
+ const eventKey = require_constants.normalizeKeyName(event.key);
39
+ const hotkeyKey = parsed.key;
40
+ if (eventKey !== "Dead" && eventKey.length === 1 && hotkeyKey.length === 1) {
41
+ if (eventKey.toUpperCase() === hotkeyKey.toUpperCase()) return true;
42
+ if (require_constants.isSingleLetterKey(eventKey) && (/^[A-Za-z]$/.test(eventKey) || !event.altKey)) return false;
43
+ }
44
+ if (event.code && (eventKey === "Dead" || eventKey.length === 1 && hotkeyKey.length === 1)) {
45
+ if (event.code.startsWith("Key")) {
46
+ const codeLetter = event.code.slice(3);
47
+ if (codeLetter.length === 1 && /^[A-Za-z]$/.test(codeLetter)) return codeLetter.toUpperCase() === hotkeyKey.toUpperCase();
48
+ }
49
+ if (event.code.startsWith("Digit")) {
50
+ const codeDigit = event.code.slice(5);
51
+ if (codeDigit.length === 1 && /^[0-9]$/.test(codeDigit)) return codeDigit === hotkeyKey;
52
+ }
53
+ if (event.code in require_constants.PUNCTUATION_CODE_MAP) return require_constants.PUNCTUATION_CODE_MAP[event.code] === hotkeyKey;
54
+ return false;
55
+ }
56
+ return eventKey === hotkeyKey;
57
+ }
58
+ //#endregion
59
+ exports.matchesKeyboardEvent = matchesKeyboardEvent;