@versini/ui-menu 7.6.6 → 7.6.8

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 (2) hide show
  1. package/dist/index.js +289 -631
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- @versini/ui-menu v7.6.6
2
+ @versini/ui-menu v7.6.8
3
3
  © 2026 gizmette.com
4
4
  */
5
5
 
@@ -8,62 +8,15 @@ import { useUniqueId } from "@versini/ui-hooks/use-unique-id";
8
8
  import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
9
9
  import clsx_0, { clsx } from "clsx";
10
10
  import { IconNext } from "@versini/ui-icons";
11
-
12
11
  import * as __rspack_external_react from "react";
13
-
14
-
15
-
16
-
17
-
18
- /**
19
- * Returning focus to the trigger without asking for a focus ring.
20
- *
21
- * Closing a menu hands focus back to its trigger. Whether such a script-moved
22
- * focus should be RINGED is a heuristic the spec leaves to the UA, and the
23
- * engines disagree: measured in Safari 27 / WebKit 605.1.15, `button.focus()`
24
- * matches `:focus-visible` even from a cold start with nothing focused
25
- * beforehand, while Chromium declines to. So in WebKit, dismissing a menu with
26
- * a tap painted a keyboard focus ring on the trigger.
27
- *
28
- * SCOPED TO THE TRIGGER on purpose. A menu focuses items constantly -- on
29
- * hover, on open, on arrow keys -- and none of those needs this: every item
30
- * carries `outline-hidden` from `getMenuItemClasses`, an author declaration
31
- * that outranks the UA's `:focus-visible` outline, so an item cannot ring
32
- * however it is focused. The trigger is the exception because it is supplied by
33
- * the consumer, typically a `ui-button` carrying `focus-visible:outline-*`.
34
- *
35
- * ONLY `false` IS EVER PASSED, and that asymmetry is the design. A
36
- * pointer-driven dismissal knows the ring is wrong and says so. A
37
- * keyboard-driven one says NOTHING and calls `focus()` bare, leaving the
38
- * decision to the UA, because that is the case the heuristic already gets right
39
- * -- passing `focusVisible: true` would override it rather than agree with it.
40
- *
41
- */ /**
42
- * Focus `element`, suppressing the ring when we know a pointer caused it.
43
- *
44
- * `element` is optional so call sites can pass a ref's `current` straight in
45
- * without repeating the null check at seven sites.
46
- *
47
- */ const restoreFocus = (element, { viaPointer } = {})=>{
12
+ const restoreFocus = (element, { viaPointer } = {})=>{
48
13
  element?.focus(viaPointer ? {
49
14
  focusVisible: false
50
- } : undefined);
15
+ } : void 0);
51
16
  };
52
- /**
53
- * Whether a click came from a pointer rather than from a keypress.
54
- *
55
- * `useMenuKeyboard` activates Enter and Space by calling `element.click()`, so
56
- * a keyboard activation and a real tap arrive at the SAME handler and the call
57
- * site alone cannot tell them apart. `detail` can: a synthetic click reports 0
58
- * and a pointer click reports 1 or more. Measured in WebKit rather than
59
- * assumed.
60
- *
61
- */ const isPointerClick = (event)=>event.detail > 0;
62
-
63
-
64
-
17
+ const isPointerClick = (event)=>event.detail > 0;
65
18
  const MenuGroupContext = createContext(false);
66
- /* v8 ignore start - default context values are fallbacks, never used directly */ const MenuRootContext = createContext({
19
+ const MenuRootContext = createContext({
67
20
  closeAll: ()=>{}
68
21
  });
69
22
  const MenuContentContext = createContext({
@@ -76,111 +29,69 @@ const MenuContentContext = createContext({
76
29
  setOpenSubMenuId: ()=>{},
77
30
  close: ()=>{},
78
31
  isSubMenu: false
79
- }); /* v8 ignore stop */
80
-
81
-
82
-
32
+ });
83
33
  function getNextEnabledIndex(items, currentIndex, direction) {
84
34
  const count = items.length;
85
- /* v8 ignore start - empty items edge case */ if (count === 0) {
86
- return -1;
87
- }
88
- /* v8 ignore stop */ let index = currentIndex;
35
+ if (0 === count) return -1;
36
+ let index = currentIndex;
89
37
  for(let i = 0; i < count; i++){
90
38
  index = (index + direction + count) % count;
91
- if (!items[index].disabled) {
92
- return index;
93
- }
39
+ if (!items[index].disabled) return index;
94
40
  }
95
- /* v8 ignore start - all items disabled edge case */ return currentIndex;
96
- /* v8 ignore stop */ }
41
+ return currentIndex;
42
+ }
97
43
  const TYPEAHEAD_TIMEOUT_MS = 500;
98
44
  function getTypeaheadMatchIndex(items, searchString, startIndex) {
99
45
  const count = items.length;
100
46
  const normalized = searchString.toLowerCase();
101
- /**
102
- * When the same single character is repeated (e.g. "aaa"), cycle through items
103
- * starting with that character instead of trying to match the full repeated
104
- * string.
105
- */ const isRepeatedChar = normalized.length > 1 && [
47
+ const isRepeatedChar = normalized.length > 1 && [
106
48
  ...normalized
107
49
  ].every((c)=>c === normalized[0]);
108
50
  const matchStr = isRepeatedChar ? normalized[0] : normalized;
109
- /**
110
- * For a single character (including repeated single-char), start searching
111
- * from the item *after* the current one so we always advance to the next
112
- * match. For multi-character strings, start from the current item so the user
113
- * can refine the match in-place.
114
- */ const offset = normalized.length === 1 || isRepeatedChar ? 1 : 0;
51
+ const offset = 1 === normalized.length || isRepeatedChar ? 1 : 0;
115
52
  for(let i = 0; i < count; i++){
116
53
  const index = (startIndex + offset + i) % count;
117
- if (items[index].disabled) {
118
- continue;
119
- }
120
- /* v8 ignore start -- textContent is always a string in DOM */ const text = (items[index].element.textContent ?? "").trim().toLowerCase();
121
- /* v8 ignore stop */ if (text.startsWith(matchStr)) {
122
- return index;
123
- }
54
+ if (items[index].disabled) continue;
55
+ const text = (items[index].element.textContent ?? "").trim().toLowerCase();
56
+ if (text.startsWith(matchStr)) return index;
124
57
  }
125
58
  return -1;
126
59
  }
127
- /* v8 ignore start - Home/End handlers with disabled item edge cases */ function getFirstEnabledIndex(items) {
128
- for(let i = 0; i < items.length; i++){
129
- if (!items[i].disabled) {
130
- return i;
131
- }
132
- }
60
+ function getFirstEnabledIndex(items) {
61
+ for(let i = 0; i < items.length; i++)if (!items[i].disabled) return i;
133
62
  return -1;
134
63
  }
135
64
  function getLastEnabledIndex(items) {
136
- for(let i = items.length - 1; i >= 0; i--){
137
- if (!items[i].disabled) {
138
- return i;
139
- }
140
- }
65
+ for(let i = items.length - 1; i >= 0; i--)if (!items[i].disabled) return i;
141
66
  return -1;
142
67
  }
143
- /* v8 ignore stop */ function useMenuKeyboard({ menuRef, isOpen, activeIndex, setActiveIndex, getItems, onClose, isSubMenu = false, onOpenSubMenu, onCloseToParent }) {
68
+ function useMenuKeyboard({ menuRef, isOpen, activeIndex, setActiveIndex, getItems, onClose, isSubMenu = false, onOpenSubMenu, onCloseToParent }) {
144
69
  const searchBufferRef = useRef("");
145
- const searchTimeoutRef = useRef(undefined);
146
- // Clear the typeahead buffer when the menu closes.
70
+ const searchTimeoutRef = useRef(void 0);
147
71
  useEffect(()=>{
148
72
  if (!isOpen) {
149
73
  searchBufferRef.current = "";
150
- if (searchTimeoutRef.current) {
151
- clearTimeout(searchTimeoutRef.current);
152
- }
74
+ if (searchTimeoutRef.current) clearTimeout(searchTimeoutRef.current);
153
75
  }
154
76
  }, [
155
77
  isOpen
156
78
  ]);
157
- // Clean up timeout on unmount.
158
- useEffect(()=>{
159
- return ()=>{
160
- if (searchTimeoutRef.current) {
161
- clearTimeout(searchTimeoutRef.current);
162
- }
163
- };
164
- }, []);
165
- /* v8 ignore start - focusItem bounds guard */ const focusItem = useCallback((index)=>{
79
+ useEffect(()=>()=>{
80
+ if (searchTimeoutRef.current) clearTimeout(searchTimeoutRef.current);
81
+ }, []);
82
+ const focusItem = useCallback((index)=>{
166
83
  const items = getItems();
167
- if (index >= 0 && index < items.length) {
168
- items[index].element.focus();
169
- }
84
+ if (index >= 0 && index < items.length) items[index].element.focus();
170
85
  }, [
171
86
  getItems
172
87
  ]);
173
- /* v8 ignore stop */ useEffect(()=>{
174
- if (!isOpen || !menuRef.current) {
175
- return;
176
- }
88
+ useEffect(()=>{
89
+ if (!isOpen || !menuRef.current) return;
177
90
  const handleKeyDown = (event)=>{
178
91
  const items = getItems();
179
- /* v8 ignore start - items always exist when menu is open */ if (items.length === 0) {
180
- return;
181
- }
182
- /* v8 ignore stop */ /* v8 ignore start - switch internal branch */ switch(event.key){
183
- /* v8 ignore stop */ case "ArrowDown":
92
+ if (0 === items.length) return;
93
+ switch(event.key){
94
+ case "ArrowDown":
184
95
  {
185
96
  event.preventDefault();
186
97
  event.stopPropagation();
@@ -218,73 +129,53 @@ function getLastEnabledIndex(items) {
218
129
  }
219
130
  case "Enter":
220
131
  case " ":
221
- {
222
- event.preventDefault();
223
- event.stopPropagation();
224
- /* v8 ignore start - activeIndex bounds and disabled guard */ if (activeIndex >= 0 && activeIndex < items.length && !items[activeIndex].disabled) {
225
- items[activeIndex].element.click();
226
- }
227
- break;
228
- }
132
+ event.preventDefault();
133
+ event.stopPropagation();
134
+ if (activeIndex >= 0 && activeIndex < items.length && !items[activeIndex].disabled) items[activeIndex].element.click();
135
+ break;
229
136
  case "Escape":
230
- {
231
- event.preventDefault();
232
- event.stopPropagation();
233
- onClose();
234
- break;
235
- }
236
- /* v8 ignore start - sub-menu keyboard nav requires full browser env */ case "ArrowRight":
237
- {
238
- if (activeIndex >= 0 && activeIndex < items.length && onOpenSubMenu) {
239
- const item = items[activeIndex].element;
240
- if (item.getAttribute("aria-haspopup") === "menu") {
241
- event.preventDefault();
242
- event.stopPropagation();
243
- onOpenSubMenu(item);
244
- }
245
- }
246
- break;
247
- }
248
- case "ArrowLeft":
249
- {
250
- if (isSubMenu && onCloseToParent) {
137
+ event.preventDefault();
138
+ event.stopPropagation();
139
+ onClose();
140
+ break;
141
+ case "ArrowRight":
142
+ if (activeIndex >= 0 && activeIndex < items.length && onOpenSubMenu) {
143
+ const item = items[activeIndex].element;
144
+ if ("menu" === item.getAttribute("aria-haspopup")) {
251
145
  event.preventDefault();
252
146
  event.stopPropagation();
253
- onCloseToParent();
147
+ onOpenSubMenu(item);
254
148
  }
255
- break;
256
149
  }
257
- case "Tab":
258
- {
150
+ break;
151
+ case "ArrowLeft":
152
+ if (isSubMenu && onCloseToParent) {
259
153
  event.preventDefault();
260
154
  event.stopPropagation();
261
- onClose();
262
- break;
155
+ onCloseToParent();
263
156
  }
264
- /* v8 ignore stop */ default:
265
- {
266
- /**
267
- * Typeahead: printable single characters (ignore modifier-only or
268
- * functional keys such as Shift, Control, Alt, Meta, etc.).
269
- */ if (event.key.length === 1 && !event.ctrlKey && !event.metaKey) {
270
- event.preventDefault();
271
- event.stopPropagation();
272
- // Reset the debounce timer.
273
- if (searchTimeoutRef.current) {
274
- clearTimeout(searchTimeoutRef.current);
275
- }
276
- searchBufferRef.current += event.key;
277
- const matchIndex = getTypeaheadMatchIndex(items, searchBufferRef.current, /* v8 ignore next */ activeIndex >= 0 ? activeIndex : 0);
278
- if (matchIndex >= 0) {
279
- setActiveIndex(matchIndex);
280
- focusItem(matchIndex);
281
- }
282
- searchTimeoutRef.current = setTimeout(()=>{
283
- searchBufferRef.current = "";
284
- }, TYPEAHEAD_TIMEOUT_MS);
157
+ break;
158
+ case "Tab":
159
+ event.preventDefault();
160
+ event.stopPropagation();
161
+ onClose();
162
+ break;
163
+ default:
164
+ if (1 === event.key.length && !event.ctrlKey && !event.metaKey) {
165
+ event.preventDefault();
166
+ event.stopPropagation();
167
+ if (searchTimeoutRef.current) clearTimeout(searchTimeoutRef.current);
168
+ searchBufferRef.current += event.key;
169
+ const matchIndex = getTypeaheadMatchIndex(items, searchBufferRef.current, activeIndex >= 0 ? activeIndex : 0);
170
+ if (matchIndex >= 0) {
171
+ setActiveIndex(matchIndex);
172
+ focusItem(matchIndex);
285
173
  }
286
- break;
174
+ searchTimeoutRef.current = setTimeout(()=>{
175
+ searchBufferRef.current = "";
176
+ }, TYPEAHEAD_TIMEOUT_MS);
287
177
  }
178
+ break;
288
179
  }
289
180
  };
290
181
  const menuElement = menuRef.current;
@@ -308,67 +199,35 @@ function getLastEnabledIndex(items) {
308
199
  focusItem
309
200
  };
310
201
  }
311
-
312
-
313
-
314
-
315
-
316
-
317
- /**
318
- * Shared classes for the small green "selected" dot, reused by MenuItem (inner
319
- * dot) and MenuSub (nested-selection indicator) so the success token lives in
320
- * one place.
321
- */ const SELECTED_DOT_CLASS = "size-1.5 rounded-full bg-copy-success-light";
202
+ const SELECTED_DOT_CLASS = "size-1.5 rounded-full bg-copy-success-light";
322
203
  const getDisplayName = (element)=>{
323
- if (typeof element === "string") {
324
- return element;
325
- }
326
- if (typeof element === "function") {
327
- return element.displayName || element.name || "Component";
328
- }
329
- if (typeof element === "object" && element !== null && "type" in element) {
204
+ if ("string" == typeof element) return element;
205
+ if ("function" == typeof element) return element.displayName || element.name || "Component";
206
+ if ("object" == typeof element && null !== element && "type" in element) {
330
207
  const type = element.type;
331
- if (typeof type === "function" || typeof type === "object") {
332
- /* v8 ignore start */ return type.displayName || type.name || "Component";
333
- /* v8 ignore stop */ }
208
+ if ("function" == typeof type || "object" == typeof type) return type.displayName || type.name || "Component";
334
209
  }
335
210
  return "Element";
336
211
  };
337
- /**
338
- * Recursively walks a React children tree looking for a selected menu entry.
339
- * Only `MenuItem`/`MenuSub` elements with `selected === true` count, so an
340
- * unrelated `selected` prop on other nested content (e.g. a native `<option
341
- * selected>`) does not produce a false indicator. Traversal still descends
342
- * through any container (MenuGroup, fragments) to reach those entries.
343
- *
344
- * Used by MenuSub to surface a nested selection on its trigger row even while
345
- * the sub-menu is closed (sub-menu children are conditionally mounted, so they
346
- * cannot report selection upward via context).
347
- *
348
- */ const hasSelectedDescendant = (node)=>{
212
+ const hasSelectedDescendant = (node)=>{
349
213
  let found = false;
350
214
  __rspack_external_react.Children.forEach(node, (child)=>{
351
- if (found || !__rspack_external_react.isValidElement(child)) {
352
- return;
353
- }
215
+ if (found || !__rspack_external_react.isValidElement(child)) return;
354
216
  const childProps = child.props;
355
217
  const name = getDisplayName(child);
356
- if ((name === "MenuItem" || name === "MenuSub") && childProps.selected === true) {
218
+ if (("MenuItem" === name || "MenuSub" === name) && true === childProps.selected) {
357
219
  found = true;
358
220
  return;
359
221
  }
360
- if (childProps.children) {
361
- found = hasSelectedDescendant(childProps.children);
362
- }
222
+ if (childProps.children) found = hasSelectedDescendant(childProps.children);
363
223
  });
364
224
  return found;
365
225
  };
366
226
  const calculatePosition = (triggerRect, menuRect, placement, sideOffset, viewportWidth, viewportHeight)=>{
367
- /* v8 ignore start - split always returns non-empty for valid placements */ const side = placement.split("-")[0] || "bottom";
368
- /* v8 ignore stop */ const alignment = placement.includes("-") ? placement.split("-")[1] : "center";
227
+ const side = placement.split("-")[0] || "bottom";
228
+ const alignment = placement.includes("-") ? placement.split("-")[1] : "center";
369
229
  let top = 0;
370
230
  let left = 0;
371
- // Calculate base position based on side.
372
231
  switch(side){
373
232
  case "bottom":
374
233
  top = triggerRect.bottom + sideOffset;
@@ -383,55 +242,41 @@ const calculatePosition = (triggerRect, menuRect, placement, sideOffset, viewpor
383
242
  left = triggerRect.left - menuRect.width - sideOffset;
384
243
  break;
385
244
  }
386
- // Calculate alignment.
387
- if (side === "bottom" || side === "top") {
388
- switch(alignment){
389
- case "start":
390
- left = triggerRect.left;
391
- break;
392
- case "end":
393
- left = triggerRect.right - menuRect.width;
394
- break;
395
- default:
396
- left = triggerRect.left + (triggerRect.width - menuRect.width) / 2;
397
- break;
398
- }
399
- } else {
400
- switch(alignment){
401
- case "start":
402
- top = triggerRect.top;
403
- break;
404
- case "end":
405
- top = triggerRect.bottom - menuRect.height;
406
- break;
407
- default:
408
- top = triggerRect.top + (triggerRect.height - menuRect.height) / 2;
409
- break;
410
- }
245
+ if ("bottom" === side || "top" === side) switch(alignment){
246
+ case "start":
247
+ left = triggerRect.left;
248
+ break;
249
+ case "end":
250
+ left = triggerRect.right - menuRect.width;
251
+ break;
252
+ default:
253
+ left = triggerRect.left + (triggerRect.width - menuRect.width) / 2;
254
+ break;
411
255
  }
412
- // Auto-flip if overflowing viewport.
413
- /* v8 ignore start - auto-flip with fallback when flipped position also overflows */ if (side === "bottom" && top + menuRect.height > viewportHeight) {
256
+ else switch(alignment){
257
+ case "start":
258
+ top = triggerRect.top;
259
+ break;
260
+ case "end":
261
+ top = triggerRect.bottom - menuRect.height;
262
+ break;
263
+ default:
264
+ top = triggerRect.top + (triggerRect.height - menuRect.height) / 2;
265
+ break;
266
+ }
267
+ if ("bottom" === side && top + menuRect.height > viewportHeight) {
414
268
  const flippedTop = triggerRect.top - menuRect.height - sideOffset;
415
- if (flippedTop >= 0) {
416
- top = flippedTop;
417
- }
418
- } else if (side === "top" && top < 0) {
269
+ if (flippedTop >= 0) top = flippedTop;
270
+ } else if ("top" === side && top < 0) {
419
271
  const flippedTop = triggerRect.bottom + sideOffset;
420
- if (flippedTop + menuRect.height <= viewportHeight) {
421
- top = flippedTop;
422
- }
423
- } else if (side === "right" && left + menuRect.width > viewportWidth) {
272
+ if (flippedTop + menuRect.height <= viewportHeight) top = flippedTop;
273
+ } else if ("right" === side && left + menuRect.width > viewportWidth) {
424
274
  const flippedLeft = triggerRect.left - menuRect.width - sideOffset;
425
- if (flippedLeft >= 0) {
426
- left = flippedLeft;
427
- }
428
- } else if (side === "left" && left < 0) {
275
+ if (flippedLeft >= 0) left = flippedLeft;
276
+ } else if ("left" === side && left < 0) {
429
277
  const flippedLeft = triggerRect.right + sideOffset;
430
- if (flippedLeft + menuRect.width <= viewportWidth) {
431
- left = flippedLeft;
432
- }
278
+ if (flippedLeft + menuRect.width <= viewportWidth) left = flippedLeft;
433
279
  }
434
- /* v8 ignore stop */ // Clamp to viewport bounds.
435
280
  left = Math.max(0, Math.min(left, viewportWidth - menuRect.width));
436
281
  top = Math.max(0, Math.min(top, viewportHeight - menuRect.height));
437
282
  return {
@@ -439,31 +284,22 @@ const calculatePosition = (triggerRect, menuRect, placement, sideOffset, viewpor
439
284
  left
440
285
  };
441
286
  };
442
- const getMenuItemClasses = ({ isSub })=>{
443
- return clsx("flex flex-row items-center", "w-full", "m-0 first:mt-0 mt-2 sm:mt-1 px-2 py-1", "rounded-md border border-transparent", "text-left text-base select-none cursor-pointer", "outline-hidden", "disabled:cursor-not-allowed disabled:text-copy-medium", "text-copy-dark", "data-highlighted:bg-surface-darker", "data-highlighted:text-copy-light", "in-data-menu-group:text-copy-light", "in-data-menu-group:data-highlighted:bg-surface-darker", "in-data-menu-group:data-highlighted:border-border-medium", {
287
+ const getMenuItemClasses = ({ isSub })=>clsx("flex flex-row items-center", "w-full", "m-0 first:mt-0 mt-2 sm:mt-1 px-2 py-1", "rounded-md border border-transparent", "text-left text-base select-none cursor-pointer", "outline-hidden", "disabled:cursor-not-allowed disabled:text-copy-medium", "text-copy-dark", "data-highlighted:bg-surface-darker", "data-highlighted:text-copy-light", "in-data-menu-group:text-copy-light", "in-data-menu-group:data-highlighted:bg-surface-darker", "in-data-menu-group:data-highlighted:border-border-medium", {
444
288
  "data-[state=open]:bg-surface-darker data-[state=open]:text-copy-light justify-between": isSub,
445
289
  "data-disabled:cursor-not-allowed data-disabled:text-copy-medium": !isSub
446
290
  });
447
- };
448
- const getMenuClasses = ({ isSub, noBackdrop = false })=>{
449
- return clsx("bg-surface-light", "rounded-md", "outline-hidden", "p-1", {
291
+ const getMenuClasses = ({ isSub, noBackdrop = false })=>clsx("bg-surface-light", "rounded-md", "outline-hidden", "p-1", {
450
292
  "z-100 plume plume-dark": !isSub,
451
293
  "z-60 mx-3": isSub,
452
294
  "av-backdrop-animate": !noBackdrop && !isSub
453
295
  });
454
- };
455
-
456
-
457
-
458
296
  function useMenuPosition({ triggerRef, menuRef, placement, sideOffset, isOpen }) {
459
297
  const positionRef = useRef({
460
298
  top: 0,
461
299
  left: 0
462
300
  });
463
301
  const updatePosition = useCallback(()=>{
464
- /* v8 ignore start - positioning requires real DOM layout */ if (!triggerRef.current || !menuRef.current) {
465
- return;
466
- }
302
+ if (!triggerRef.current || !menuRef.current) return;
467
303
  const triggerRect = triggerRef.current.getBoundingClientRect();
468
304
  const menuRect = menuRef.current.getBoundingClientRect();
469
305
  const viewportWidth = window.innerWidth;
@@ -474,18 +310,16 @@ function useMenuPosition({ triggerRef, menuRef, placement, sideOffset, isOpen })
474
310
  menuRef.current.style.top = `${position.top}px`;
475
311
  menuRef.current.style.left = `${position.left}px`;
476
312
  menuRef.current.style.margin = "0";
477
- /* v8 ignore stop */ }, [
313
+ }, [
478
314
  triggerRef,
479
315
  menuRef,
480
316
  placement,
481
317
  sideOffset
482
318
  ]);
483
319
  useEffect(()=>{
484
- if (isOpen) {
485
- requestAnimationFrame(()=>{
486
- updatePosition();
487
- });
488
- }
320
+ if (isOpen) requestAnimationFrame(()=>{
321
+ updatePosition();
322
+ });
489
323
  }, [
490
324
  isOpen,
491
325
  updatePosition
@@ -495,79 +329,49 @@ function useMenuPosition({ triggerRef, menuRef, placement, sideOffset, isOpen })
495
329
  positionRef
496
330
  };
497
331
  }
498
-
499
-
500
-
501
-
502
-
503
-
504
-
505
-
506
-
507
-
508
332
  const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bottom-start", onOpenChange, mode = "system", sideOffset = 10, noBackdrop = false })=>{
509
333
  const contentClass = getMenuClasses({
510
334
  isSub: false,
511
335
  noBackdrop
512
336
  });
513
- const [isOpen, setIsOpen] = (0,__rspack_external_react.useState)(false);
514
- const [activeIndex, setActiveIndex] = (0,__rspack_external_react.useState)(-1);
515
- const [openSubMenuId, setOpenSubMenuId] = (0,__rspack_external_react.useState)(null);
337
+ const [isOpen, setIsOpen] = (0, __rspack_external_react.useState)(false);
338
+ const [activeIndex, setActiveIndex] = (0, __rspack_external_react.useState)(-1);
339
+ const [openSubMenuId, setOpenSubMenuId] = (0, __rspack_external_react.useState)(null);
516
340
  const menuId = useUniqueId("av-menu-");
517
- const triggerRef = (0,__rspack_external_react.useRef)(null);
518
- const menuRef = (0,__rspack_external_react.useRef)(null);
519
- const itemsRef = (0,__rspack_external_react.useRef)([]);
520
- const isTogglingRef = (0,__rspack_external_react.useRef)(false);
341
+ const triggerRef = (0, __rspack_external_react.useRef)(null);
342
+ const menuRef = (0, __rspack_external_react.useRef)(null);
343
+ const itemsRef = (0, __rspack_external_react.useRef)([]);
344
+ const isTogglingRef = (0, __rspack_external_react.useRef)(false);
521
345
  useMenuPosition({
522
346
  triggerRef,
523
347
  menuRef,
524
- /* v8 ignore start - defaultPlacement always has a default value */ placement: defaultPlacement || "bottom-start",
525
- /* v8 ignore stop */ sideOffset,
348
+ placement: defaultPlacement || "bottom-start",
349
+ sideOffset,
526
350
  isOpen
527
351
  });
528
- // Show/hide popover after the menu element is mounted/unmounted.
529
- /* v8 ignore start - popover API may not be available in test env */ (0,__rspack_external_react.useEffect)(()=>{
530
- if (isOpen && menuRef.current && typeof menuRef.current.showPopover === "function") {
531
- try {
532
- menuRef.current.showPopover();
533
- } catch {
534
- // Popover might already be shown.
535
- }
536
- }
352
+ (0, __rspack_external_react.useEffect)(()=>{
353
+ if (isOpen && menuRef.current && "function" == typeof menuRef.current.showPopover) try {
354
+ menuRef.current.showPopover();
355
+ } catch {}
537
356
  }, [
538
357
  isOpen
539
358
  ]);
540
- /* v8 ignore stop */ /**
541
- * `options` carries whether a POINTER closed the menu, because focus returns
542
- * to the trigger here and the three ways in disagree: `useMenuKeyboard`
543
- * reaches this on Escape and Tab, `handleToggle` on a click of the trigger
544
- * itself, and `MenuItem` on an activation that may be either. Each passes what
545
- * it knows; see `focusRestore.ts` for why only the pointer case speaks up.
546
- */ const handleClose = (0,__rspack_external_react.useCallback)((options)=>{
547
- /* v8 ignore start - guard against double-close */ if (!isOpen) {
548
- return;
549
- }
550
- /* v8 ignore stop */ setIsOpen(false);
359
+ const handleClose = (0, __rspack_external_react.useCallback)((options)=>{
360
+ if (!isOpen) return;
361
+ setIsOpen(false);
551
362
  setActiveIndex(-1);
552
363
  setOpenSubMenuId(null);
553
364
  onOpenChange?.(false);
554
- /* v8 ignore start - popover API may not be available in test env */ if (menuRef.current && typeof menuRef.current.hidePopover === "function") {
555
- try {
556
- menuRef.current.hidePopover();
557
- } catch {
558
- // Popover might already be hidden.
559
- }
560
- }
561
- /* v8 ignore stop */ restoreFocus(triggerRef.current, options);
365
+ if (menuRef.current && "function" == typeof menuRef.current.hidePopover) try {
366
+ menuRef.current.hidePopover();
367
+ } catch {}
368
+ restoreFocus(triggerRef.current, options);
562
369
  }, [
563
370
  isOpen,
564
371
  onOpenChange
565
372
  ]);
566
- // Click-outside detection: only active when menu is open.
567
- /* v8 ignore start - click-outside detection requires full browser env */ (0,__rspack_external_react.useEffect)(()=>{
568
- if (!isOpen) {
569
- return;
570
- }
373
+ (0, __rspack_external_react.useEffect)(()=>{
374
+ if (!isOpen) return;
571
375
  const handleClickOutside = (event)=>{
572
376
  const target = event.target;
573
377
  if (menuRef.current && !menuRef.current.contains(target) && triggerRef.current && !triggerRef.current.contains(target)) {
@@ -575,13 +379,11 @@ const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bott
575
379
  setActiveIndex(-1);
576
380
  setOpenSubMenuId(null);
577
381
  onOpenChange?.(false);
578
- // A mousedown outside is unambiguously a pointer.
579
382
  restoreFocus(triggerRef.current, {
580
383
  viaPointer: true
581
384
  });
582
385
  }
583
386
  };
584
- // Use a timeout to avoid catching the opening click itself.
585
387
  const timeoutId = setTimeout(()=>{
586
388
  document.addEventListener("mousedown", handleClickOutside);
587
389
  }, 0);
@@ -593,33 +395,28 @@ const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bott
593
395
  isOpen,
594
396
  onOpenChange
595
397
  ]);
596
- /* v8 ignore stop */ const getItems = (0,__rspack_external_react.useCallback)(()=>itemsRef.current, []);
597
- const registerItem = (0,__rspack_external_react.useCallback)((element, disabled)=>{
598
- // Maintain DOM order by using compareDocumentPosition.
398
+ const getItems = (0, __rspack_external_react.useCallback)(()=>itemsRef.current, []);
399
+ const registerItem = (0, __rspack_external_react.useCallback)((element, disabled)=>{
599
400
  const existing = itemsRef.current.findIndex((item)=>item.element === element);
600
- /* v8 ignore start - re-registration on re-render */ if (existing >= 0) {
401
+ if (existing >= 0) {
601
402
  itemsRef.current[existing].disabled = disabled;
602
403
  return;
603
404
  }
604
- /* v8 ignore stop */ const newItem = {
405
+ const newItem = {
605
406
  element,
606
407
  disabled
607
408
  };
608
- // Insert in DOM order.
609
409
  const insertIndex = itemsRef.current.findIndex((item)=>item.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING);
610
- /* v8 ignore start */ if (insertIndex === -1) {
611
- itemsRef.current.push(newItem);
612
- } else {
613
- itemsRef.current.splice(insertIndex, 0, newItem);
614
- }
615
- /* v8 ignore stop */ }, []);
616
- const unregisterItem = (0,__rspack_external_react.useCallback)((element)=>{
410
+ if (-1 === insertIndex) itemsRef.current.push(newItem);
411
+ else itemsRef.current.splice(insertIndex, 0, newItem);
412
+ }, []);
413
+ const unregisterItem = (0, __rspack_external_react.useCallback)((element)=>{
617
414
  itemsRef.current = itemsRef.current.filter((item)=>item.element !== element);
618
415
  }, []);
619
- /* v8 ignore start - sub-menu keyboard nav requires full browser env */ const handleOpenSubMenu = (0,__rspack_external_react.useCallback)((element)=>{
416
+ const handleOpenSubMenu = (0, __rspack_external_react.useCallback)((element)=>{
620
417
  element.click();
621
418
  }, []);
622
- /* v8 ignore stop */ const { focusItem } = useMenuKeyboard({
419
+ const { focusItem } = useMenuKeyboard({
623
420
  menuRef,
624
421
  isOpen,
625
422
  activeIndex,
@@ -628,60 +425,32 @@ const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bott
628
425
  onClose: handleClose,
629
426
  onOpenSubMenu: handleOpenSubMenu
630
427
  });
631
- const handleOpen = (0,__rspack_external_react.useCallback)(()=>{
428
+ const handleOpen = (0, __rspack_external_react.useCallback)(()=>{
632
429
  setIsOpen(true);
633
430
  onOpenChange?.(true);
634
- // Focus first enabled item after menu renders.
635
- /* v8 ignore start - rAF does not execute in test env */ requestAnimationFrame(()=>{
431
+ requestAnimationFrame(()=>{
636
432
  const items = getItems();
637
- for(let i = 0; i < items.length; i++){
638
- if (!items[i].disabled) {
639
- setActiveIndex(i);
640
- focusItem(i);
641
- break;
642
- }
433
+ for(let i = 0; i < items.length; i++)if (!items[i].disabled) {
434
+ setActiveIndex(i);
435
+ focusItem(i);
436
+ break;
643
437
  }
644
438
  });
645
- /* v8 ignore stop */ }, [
439
+ }, [
646
440
  onOpenChange,
647
441
  getItems,
648
442
  focusItem
649
443
  ]);
650
- /**
651
- * Only the CLOSE branch classifies. Closing hands focus back to the trigger,
652
- * which is the one element around a menu that can show a ring; opening focuses
653
- * a menu item, and items carry `outline-hidden`, so nothing there rings
654
- * whatever it is focused with.
655
- *
656
- * `isPointerClick` answers "pointer" every time TODAY, and that is not an
657
- * oversight. `handleTriggerKeyDown` below intercepts Enter, Space and
658
- * ArrowDown, calls `preventDefault` so no click is synthesized, and opens the
659
- * menu itself -- so keyboard activation never arrives here at all. Measured,
660
- * not read: forcing this to classify every toggle as a pointer leaves the
661
- * keyboard tests green, which is only possible if the keyboard never reaches
662
- * this code.
663
- *
664
- * Kept as a classifier rather than hardcoded to `true` because it stays
665
- * correct if that interception is ever removed or narrowed, where a hardcoded
666
- * value would silently start lying about a keyboard press.
667
- *
668
- */ const handleToggle = (0,__rspack_external_react.useCallback)((event)=>{
669
- /* v8 ignore start - re-entrant guard for synthetic click dispatch */ if (isTogglingRef.current) {
670
- return;
671
- }
672
- /* v8 ignore stop */ isTogglingRef.current = true;
673
- /* v8 ignore start - toggle close when clicking trigger while menu is open */ const viaPointer = isPointerClick(event);
674
- if (isOpen) {
675
- handleClose({
676
- viaPointer
677
- });
678
- } else {
679
- /* v8 ignore stop */ handleOpen();
680
- /**
681
- * Dispatch a click event to parent elements. This ensures that parent
682
- * components like Tooltip can detect the interaction and respond
683
- * appropriately (e.g., disable tooltip display).
684
- */ /* v8 ignore start */ if (triggerRef.current) {
444
+ const handleToggle = (0, __rspack_external_react.useCallback)((event)=>{
445
+ if (isTogglingRef.current) return;
446
+ isTogglingRef.current = true;
447
+ const viaPointer = isPointerClick(event);
448
+ if (isOpen) handleClose({
449
+ viaPointer
450
+ });
451
+ else {
452
+ handleOpen();
453
+ if (triggerRef.current) {
685
454
  const clickEvent = new MouseEvent("click", {
686
455
  bubbles: true,
687
456
  cancelable: true,
@@ -689,31 +458,28 @@ const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bott
689
458
  });
690
459
  triggerRef.current.dispatchEvent(clickEvent);
691
460
  }
692
- /* v8 ignore stop */ }
461
+ }
693
462
  isTogglingRef.current = false;
694
463
  }, [
695
464
  isOpen,
696
465
  handleClose,
697
466
  handleOpen
698
467
  ]);
699
- /* v8 ignore start - trigger keyboard handler tested via integration */ const handleTriggerKeyDown = (0,__rspack_external_react.useCallback)((event)=>{
700
- if (event.key === "Enter" || event.key === " " || event.key === "ArrowDown") {
468
+ const handleTriggerKeyDown = (0, __rspack_external_react.useCallback)((event)=>{
469
+ if ("Enter" === event.key || " " === event.key || "ArrowDown" === event.key) {
701
470
  event.preventDefault();
702
- if (!isOpen) {
703
- handleOpen();
704
- }
471
+ if (!isOpen) handleOpen();
705
472
  }
706
473
  }, [
707
474
  isOpen,
708
475
  handleOpen
709
476
  ]);
710
- /* v8 ignore stop */ // Build trigger element with props.
711
- const noInternalClick = getDisplayName(trigger) === "Button" || getDisplayName(trigger) === "ButtonIcon";
477
+ const noInternalClick = "Button" === getDisplayName(trigger) || "ButtonIcon" === getDisplayName(trigger);
712
478
  const uiButtonsExtraProps = noInternalClick ? {
713
479
  noInternalClick,
714
480
  mode
715
481
  } : {};
716
- /* v8 ignore start - trigger is required in practice */ const triggerElement = /*#__PURE__*/ __rspack_external_react.isValidElement(trigger) ? /*#__PURE__*/ __rspack_external_react.cloneElement(trigger, {
482
+ const triggerElement = __rspack_external_react.isValidElement(trigger) ? __rspack_external_react.cloneElement(trigger, {
717
483
  ...uiButtonsExtraProps,
718
484
  "aria-label": label,
719
485
  "aria-haspopup": "menu",
@@ -724,7 +490,7 @@ const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bott
724
490
  onClick: handleToggle,
725
491
  onKeyDown: handleTriggerKeyDown
726
492
  }) : null;
727
- /* v8 ignore stop */ const contentContextValue = {
493
+ const contentContextValue = {
728
494
  registerItem,
729
495
  unregisterItem,
730
496
  getItems,
@@ -735,15 +501,15 @@ const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bott
735
501
  close: handleClose,
736
502
  isSubMenu: false
737
503
  };
738
- return /*#__PURE__*/ jsx(MenuRootContext.Provider, {
504
+ return jsx(MenuRootContext.Provider, {
739
505
  value: {
740
506
  closeAll: handleClose
741
507
  },
742
- children: /*#__PURE__*/ jsxs(MenuContentContext.Provider, {
508
+ children: jsxs(MenuContentContext.Provider, {
743
509
  value: contentContextValue,
744
510
  children: [
745
511
  triggerElement,
746
- isOpen && /*#__PURE__*/ jsx("div", {
512
+ isOpen && jsx("div", {
747
513
  ref: menuRef,
748
514
  id: menuId,
749
515
  popover: "manual",
@@ -756,26 +522,20 @@ const Menu = ({ trigger, children, label = "Open menu", defaultPlacement = "bott
756
522
  });
757
523
  };
758
524
  Menu.displayName = "Menu";
759
-
760
-
761
-
762
-
763
-
764
-
765
525
  const MenuGroup = ({ children, label, className, icon })=>{
766
526
  const groupClass = clsx_0("rounded-md", "p-2", "first:mt-0 mt-1", "bg-surface-dark", "text-copy-light", className);
767
527
  const labelContainerClass = clsx_0("pt-2 pb-2", "px-3 sm:px-2", "-mx-1 -mt-1", "flex items-center justify-between", "text-xs text-copy-medium uppercase font-bold", "rounded-t-md");
768
- return /*#__PURE__*/ jsx(MenuGroupContext.Provider, {
528
+ return jsx(MenuGroupContext.Provider, {
769
529
  value: true,
770
- children: /*#__PURE__*/ jsxs("div", {
771
- role: label ? "group" : undefined,
530
+ children: jsxs("div", {
531
+ role: label ? "group" : void 0,
772
532
  className: groupClass,
773
533
  "data-menu-group": true,
774
- "aria-label": label || undefined,
534
+ "aria-label": label || void 0,
775
535
  children: [
776
- label && /*#__PURE__*/ jsx("div", {
536
+ label && jsx("div", {
777
537
  className: labelContainerClass,
778
- children: /*#__PURE__*/ jsxs("span", {
538
+ children: jsxs("span", {
779
539
  className: "flex items-center gap-1",
780
540
  children: [
781
541
  icon,
@@ -789,16 +549,6 @@ const MenuGroup = ({ children, label, className, icon })=>{
789
549
  });
790
550
  };
791
551
  MenuGroup.displayName = "MenuGroup";
792
-
793
-
794
-
795
-
796
-
797
-
798
-
799
-
800
-
801
-
802
552
  const ITEM_CLASS = getMenuItemClasses({
803
553
  isSub: false
804
554
  });
@@ -809,20 +559,18 @@ const MenuItem = ({ label, disabled, icon, raw = false, children, ignoreClick =
809
559
  const { registerItem, unregisterItem, getItems, activeIndex, setActiveIndex, setOpenSubMenuId } = useContext(MenuContentContext);
810
560
  useEffect(()=>{
811
561
  const element = itemRef.current;
812
- /* v8 ignore start - ref is always set after mount */ if (element) {
562
+ if (element) {
813
563
  registerItem(element, !!disabled);
814
564
  return ()=>{
815
565
  unregisterItem(element);
816
566
  };
817
567
  }
818
- /* v8 ignore stop */ }, [
568
+ }, [
819
569
  disabled,
820
570
  registerItem,
821
571
  unregisterItem
822
572
  ]);
823
- if (!isInsideMenuGroup) {
824
- throw new Error("MenuItem must be used within a MenuGroup.");
825
- }
573
+ if (!isInsideMenuGroup) throw new Error("MenuItem must be used within a MenuGroup.");
826
574
  const getMyIndex = ()=>{
827
575
  const items = getItems();
828
576
  return items.findIndex((item)=>item.element === itemRef.current);
@@ -830,101 +578,82 @@ const MenuItem = ({ label, disabled, icon, raw = false, children, ignoreClick =
830
578
  const myIndex = getMyIndex();
831
579
  const isHighlighted = myIndex >= 0 && activeIndex === myIndex;
832
580
  const handleSelect = (event)=>{
833
- /* v8 ignore start - disabled items are not clickable in practice */ if (disabled) {
834
- return;
835
- }
836
- /* v8 ignore stop */ const syntheticEvent = new Event("select", {
581
+ if (disabled) return;
582
+ const syntheticEvent = new Event("select", {
837
583
  bubbles: true,
838
584
  cancelable: true
839
585
  });
840
- if (ignoreClick) {
841
- syntheticEvent.preventDefault();
842
- }
586
+ if (ignoreClick) syntheticEvent.preventDefault();
843
587
  onSelect?.(syntheticEvent);
844
- /* v8 ignore start - optional onClick may not be provided */ onClick?.(event);
845
- /* v8 ignore stop */ if (!ignoreClick) {
846
- closeAll({
847
- viaPointer: isPointerClick(event)
848
- });
849
- }
588
+ onClick?.(event);
589
+ if (!ignoreClick) closeAll({
590
+ viaPointer: isPointerClick(event)
591
+ });
850
592
  };
851
593
  const handleMouseEnter = (event)=>{
852
- /* v8 ignore start - disabled items do not receive hover highlight */ if (disabled) {
853
- return;
854
- }
855
- /* v8 ignore stop */ const myIndex = getMyIndex();
856
- /* v8 ignore start - item is always registered when mouse enters */ if (myIndex >= 0) {
594
+ if (disabled) return;
595
+ const myIndex = getMyIndex();
596
+ if (myIndex >= 0) {
857
597
  setActiveIndex(myIndex);
858
598
  itemRef.current?.focus();
859
599
  }
860
- /* v8 ignore stop */ // Close any open sub-menu when hovering a regular item.
861
600
  setOpenSubMenuId(null);
862
601
  onMouseEnter?.(event);
863
602
  };
864
- /* v8 ignore start - raw items with disabled attribute */ if (raw && children) {
865
- return /*#__PURE__*/ jsx("div", {
866
- ref: itemRef,
867
- role: "menuitem",
868
- tabIndex: isHighlighted ? 0 : -1,
869
- className: "outline-hidden",
870
- "data-highlighted": isHighlighted ? "" : undefined,
871
- "data-disabled": disabled ? "" : undefined,
872
- "aria-disabled": disabled || undefined,
873
- onClick: (event)=>{
874
- /* v8 ignore start - disabled items are not clickable in practice */ if (disabled) {
875
- return;
876
- }
877
- /* v8 ignore stop */ const syntheticEvent = new Event("select", {
878
- bubbles: true,
879
- cancelable: true
880
- });
881
- if (ignoreClick) {
882
- syntheticEvent.preventDefault();
883
- }
884
- onSelect?.(syntheticEvent);
885
- /* v8 ignore start - optional onClick may not be provided */ onClick?.(event);
886
- /* v8 ignore stop */ if (!ignoreClick) {
887
- closeAll({
888
- viaPointer: isPointerClick(event)
889
- });
890
- }
891
- },
892
- onMouseEnter: handleMouseEnter,
893
- ...props,
894
- children: children
895
- });
896
- }
897
- /* v8 ignore stop */ let buttonSpanClass = "";
898
- if (icon) {
899
- buttonSpanClass = "pl-2";
900
- }
603
+ if (raw && children) return jsx("div", {
604
+ ref: itemRef,
605
+ role: "menuitem",
606
+ tabIndex: isHighlighted ? 0 : -1,
607
+ className: "outline-hidden",
608
+ "data-highlighted": isHighlighted ? "" : void 0,
609
+ "data-disabled": disabled ? "" : void 0,
610
+ "aria-disabled": disabled || void 0,
611
+ onClick: (event)=>{
612
+ if (disabled) return;
613
+ const syntheticEvent = new Event("select", {
614
+ bubbles: true,
615
+ cancelable: true
616
+ });
617
+ if (ignoreClick) syntheticEvent.preventDefault();
618
+ onSelect?.(syntheticEvent);
619
+ onClick?.(event);
620
+ if (!ignoreClick) closeAll({
621
+ viaPointer: isPointerClick(event)
622
+ });
623
+ },
624
+ onMouseEnter: handleMouseEnter,
625
+ ...props,
626
+ children: children
627
+ });
628
+ let buttonSpanClass = "";
629
+ if (icon) buttonSpanClass = "pl-2";
901
630
  const itemClass = clsx_0(ITEM_CLASS, {
902
631
  "bg-none": !disabled && !selected
903
632
  });
904
- return /*#__PURE__*/ jsxs("div", {
633
+ return jsxs("div", {
905
634
  ref: itemRef,
906
635
  role: "menuitem",
907
636
  tabIndex: isHighlighted ? 0 : -1,
908
637
  className: itemClass,
909
- "data-highlighted": isHighlighted ? "" : undefined,
910
- "data-disabled": disabled ? "" : undefined,
911
- "aria-disabled": disabled || undefined,
638
+ "data-highlighted": isHighlighted ? "" : void 0,
639
+ "data-disabled": disabled ? "" : void 0,
640
+ "aria-disabled": disabled || void 0,
912
641
  onClick: handleSelect,
913
642
  onFocus: onFocus,
914
643
  onMouseEnter: handleMouseEnter,
915
644
  ...props,
916
645
  children: [
917
- selected === true && /*#__PURE__*/ jsx("span", {
646
+ true === selected && jsx("span", {
918
647
  className: "mr-2 flex size-4 shrink-0 items-center justify-center rounded-full border border-copy-medium",
919
- children: /*#__PURE__*/ jsx("span", {
648
+ children: jsx("span", {
920
649
  className: SELECTED_DOT_CLASS
921
650
  })
922
651
  }),
923
- selected === false && /*#__PURE__*/ jsx("span", {
652
+ false === selected && jsx("span", {
924
653
  className: clsx_0("mr-2 size-4 shrink-0", "rounded-full border border-copy-medium")
925
654
  }),
926
655
  icon,
927
- label && /*#__PURE__*/ jsx("span", {
656
+ label && jsx("span", {
928
657
  className: buttonSpanClass,
929
658
  children: label
930
659
  })
@@ -932,22 +661,17 @@ const MenuItem = ({ label, disabled, icon, raw = false, children, ignoreClick =
932
661
  });
933
662
  };
934
663
  MenuItem.displayName = "MenuItem";
935
-
936
-
937
-
938
-
939
-
940
664
  const MenuLabel = ({ className, icon, children, ...props })=>{
941
665
  const groupLabelClass = clsx_0(className, "pt-1 pb-2", "text-xs text-copy-medium uppercase font-bold", "border-b border-border-medium", {
942
666
  "flex items-center": icon
943
667
  });
944
668
  const labelSpanClass = icon ? "px-2" : "";
945
- return /*#__PURE__*/ jsxs("div", {
669
+ return jsxs("div", {
946
670
  className: groupLabelClass,
947
671
  ...props,
948
672
  children: [
949
673
  icon,
950
- /*#__PURE__*/ jsx("span", {
674
+ jsx("span", {
951
675
  className: labelSpanClass,
952
676
  children: children
953
677
  })
@@ -955,33 +679,15 @@ const MenuLabel = ({ className, icon, children, ...props })=>{
955
679
  });
956
680
  };
957
681
  MenuLabel.displayName = "MenuLabel";
958
-
959
-
960
-
961
-
962
-
963
682
  const MenuSeparator = ({ className, ...props })=>{
964
683
  const separatorClass = clsx_0(className, "my-1 border-t border-border-medium");
965
- return /*#__PURE__*/ jsx("div", {
684
+ return jsx("div", {
966
685
  role: "separator",
967
686
  className: separatorClass,
968
687
  ...props
969
688
  });
970
689
  };
971
690
  MenuSeparator.displayName = "MenuSeparator";
972
-
973
-
974
-
975
-
976
-
977
-
978
-
979
-
980
-
981
-
982
-
983
-
984
-
985
691
  const SUB_CONTENT_CLASS = getMenuClasses({
986
692
  isSub: true
987
693
  });
@@ -998,35 +704,27 @@ const MenuSub = ({ label, icon, children, disabled = false, sideOffset = 20, sel
998
704
  const subItemsRef = useRef([]);
999
705
  const parentContext = useContext(MenuContentContext);
1000
706
  const rootContext = useContext(MenuRootContext);
1001
- // Register as an item in the parent menu.
1002
707
  useEffect(()=>{
1003
708
  const element = triggerItemRef.current;
1004
- /* v8 ignore start - ref is always set after mount */ if (element) {
709
+ if (element) {
1005
710
  parentContext.registerItem(element, !!disabled);
1006
711
  return ()=>{
1007
712
  parentContext.unregisterItem(element);
1008
713
  };
1009
714
  }
1010
- /* v8 ignore stop */ }, [
715
+ }, [
1011
716
  disabled,
1012
717
  parentContext.registerItem,
1013
718
  parentContext.unregisterItem
1014
719
  ]);
1015
- /**
1016
- * Close if a sibling sub-menu opens or parent signals close (openSubMenuId set
1017
- * to null).
1018
- */ useEffect(()=>{
720
+ useEffect(()=>{
1019
721
  if (isSubOpen && parentContext.openSubMenuId !== subMenuId) {
1020
722
  setIsSubOpen(false);
1021
723
  setSubActiveIndex(-1);
1022
- /* v8 ignore start */ if (subMenuRef.current && typeof subMenuRef.current.hidePopover === "function") {
1023
- try {
1024
- subMenuRef.current.hidePopover();
1025
- } catch {
1026
- // Already hidden.
1027
- }
1028
- }
1029
- /* v8 ignore stop */ }
724
+ if (subMenuRef.current && "function" == typeof subMenuRef.current.hidePopover) try {
725
+ subMenuRef.current.hidePopover();
726
+ } catch {}
727
+ }
1030
728
  }, [
1031
729
  parentContext.openSubMenuId,
1032
730
  subMenuId,
@@ -1039,124 +737,92 @@ const MenuSub = ({ label, icon, children, disabled = false, sideOffset = 20, sel
1039
737
  sideOffset,
1040
738
  isOpen: isSubOpen
1041
739
  });
1042
- // Show popover after the sub-menu element is mounted.
1043
- /* v8 ignore start - popover API may not be available in test env */ useEffect(()=>{
1044
- if (isSubOpen && subMenuRef.current && typeof subMenuRef.current.showPopover === "function") {
1045
- try {
1046
- subMenuRef.current.showPopover();
1047
- } catch {
1048
- // Popover might already be shown.
1049
- }
1050
- }
740
+ useEffect(()=>{
741
+ if (isSubOpen && subMenuRef.current && "function" == typeof subMenuRef.current.showPopover) try {
742
+ subMenuRef.current.showPopover();
743
+ } catch {}
1051
744
  }, [
1052
745
  isSubOpen
1053
746
  ]);
1054
- /* v8 ignore stop */ const getSubItems = useCallback(()=>subItemsRef.current, []);
747
+ const getSubItems = useCallback(()=>subItemsRef.current, []);
1055
748
  const registerSubItem = useCallback((element, itemDisabled)=>{
1056
749
  const existing = subItemsRef.current.findIndex((item)=>item.element === element);
1057
- /* v8 ignore start - re-registration on re-render */ if (existing >= 0) {
750
+ if (existing >= 0) {
1058
751
  subItemsRef.current[existing].disabled = itemDisabled;
1059
752
  return;
1060
753
  }
1061
- /* v8 ignore stop */ const newItem = {
754
+ const newItem = {
1062
755
  element,
1063
756
  disabled: itemDisabled
1064
757
  };
1065
758
  const insertIndex = subItemsRef.current.findIndex((item)=>item.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING);
1066
- /* v8 ignore start */ if (insertIndex === -1) {
1067
- subItemsRef.current.push(newItem);
1068
- } else {
1069
- subItemsRef.current.splice(insertIndex, 0, newItem);
1070
- }
1071
- /* v8 ignore stop */ }, []);
759
+ if (-1 === insertIndex) subItemsRef.current.push(newItem);
760
+ else subItemsRef.current.splice(insertIndex, 0, newItem);
761
+ }, []);
1072
762
  const unregisterSubItem = useCallback((element)=>{
1073
763
  subItemsRef.current = subItemsRef.current.filter((item)=>item.element !== element);
1074
764
  }, []);
1075
- /* v8 ignore start - closeSubMenu requires full browser env */ const closeSubMenu = useCallback(()=>{
765
+ const closeSubMenu = useCallback(()=>{
1076
766
  setIsSubOpen(false);
1077
767
  setSubActiveIndex(-1);
1078
768
  setSubOpenSubMenuId(null);
1079
- if (subMenuRef.current && typeof subMenuRef.current.hidePopover === "function") {
1080
- try {
1081
- subMenuRef.current.hidePopover();
1082
- } catch {
1083
- // Already hidden.
1084
- }
1085
- }
769
+ if (subMenuRef.current && "function" == typeof subMenuRef.current.hidePopover) try {
770
+ subMenuRef.current.hidePopover();
771
+ } catch {}
1086
772
  triggerItemRef.current?.focus();
1087
773
  }, []);
1088
- /* v8 ignore stop */ const openSubMenu = useCallback(()=>{
1089
- /* v8 ignore start - disabled sub-triggers cannot be opened */ if (disabled) {
1090
- return;
1091
- }
1092
- /* v8 ignore stop */ setIsSubOpen(true);
774
+ const openSubMenu = useCallback(()=>{
775
+ if (disabled) return;
776
+ setIsSubOpen(true);
1093
777
  parentContext.setOpenSubMenuId(subMenuId);
1094
- // Focus first enabled item after render.
1095
- /* v8 ignore start - rAF does not execute in test env */ requestAnimationFrame(()=>{
778
+ requestAnimationFrame(()=>{
1096
779
  const items = getSubItems();
1097
- for(let i = 0; i < items.length; i++){
1098
- if (!items[i].disabled) {
1099
- setSubActiveIndex(i);
1100
- items[i].element.focus();
1101
- break;
1102
- }
780
+ for(let i = 0; i < items.length; i++)if (!items[i].disabled) {
781
+ setSubActiveIndex(i);
782
+ items[i].element.focus();
783
+ break;
1103
784
  }
1104
785
  });
1105
- /* v8 ignore stop */ }, [
786
+ }, [
1106
787
  disabled,
1107
788
  parentContext,
1108
789
  subMenuId,
1109
790
  getSubItems
1110
791
  ]);
1111
- /* v8 ignore start - sub-menu keyboard nav requires full browser env */ const handleSubOpenSubMenu = useCallback((element)=>{
792
+ const handleSubOpenSubMenu = useCallback((element)=>{
1112
793
  element.click();
1113
794
  }, []);
1114
- /* v8 ignore stop */ useMenuKeyboard({
795
+ useMenuKeyboard({
1115
796
  menuRef: subMenuRef,
1116
797
  isOpen: isSubOpen,
1117
798
  activeIndex: subActiveIndex,
1118
799
  setActiveIndex: setSubActiveIndex,
1119
800
  getItems: getSubItems,
1120
- /* v8 ignore start - sub-menu escape close */ onClose: ()=>{
801
+ onClose: ()=>{
1121
802
  rootContext.closeAll();
1122
803
  },
1123
- /* v8 ignore stop */ isSubMenu: true,
804
+ isSubMenu: true,
1124
805
  onOpenSubMenu: handleSubOpenSubMenu,
1125
806
  onCloseToParent: closeSubMenu
1126
807
  });
1127
808
  const handleTriggerClick = ()=>{
1128
- /* v8 ignore start - disabled sub-triggers are not clickable in practice */ if (disabled) {
1129
- return;
1130
- }
1131
- /* v8 ignore stop */ /* v8 ignore start - click always follows mouseenter which already opens */ if (!isSubOpen) {
1132
- openSubMenu();
1133
- }
1134
- /* v8 ignore stop */ };
1135
- /* v8 ignore start - mouse enter always finds registered item */ const handleTriggerMouseEnter = ()=>{
809
+ if (disabled) return;
810
+ if (!isSubOpen) openSubMenu();
811
+ };
812
+ const handleTriggerMouseEnter = ()=>{
1136
813
  const items = parentContext.getItems();
1137
814
  const myIndex = items.findIndex((item)=>item.element === triggerItemRef.current);
1138
815
  if (myIndex >= 0) {
1139
816
  parentContext.setActiveIndex(myIndex);
1140
817
  triggerItemRef.current?.focus();
1141
818
  }
1142
- /**
1143
- * Open sub-menu on hover (WAI-ARIA: hover opens sub-menus when parent menu is
1144
- * already open).
1145
- */ if (!isSubOpen && !disabled) {
1146
- openSubMenu();
1147
- }
819
+ if (!isSubOpen && !disabled) openSubMenu();
1148
820
  };
1149
- /* v8 ignore stop */ const myIndex = parentContext.getItems().findIndex((item)=>item.element === triggerItemRef.current);
821
+ const myIndex = parentContext.getItems().findIndex((item)=>item.element === triggerItemRef.current);
1150
822
  const isHighlighted = myIndex >= 0 && parentContext.activeIndex === myIndex;
1151
823
  const labelSpanClass = icon ? "pl-2" : "";
1152
- /**
1153
- * Surface a nested selection on the trigger row. An explicit `selected` prop
1154
- * wins; otherwise auto-detect from the descendant children tree.
1155
- */ const showSelectedIndicator = selected ?? hasSelectedDescendant(children);
1156
- /**
1157
- * Screen-reader description id. Kept OUTSIDE the menuitem's text content so it
1158
- * never pollutes typeahead navigation (which reads element.textContent).
1159
- */ const selectionDescriptionId = `${subMenuId}-selection`;
824
+ const showSelectedIndicator = selected ?? hasSelectedDescendant(children);
825
+ const selectionDescriptionId = `${subMenuId}-selection`;
1160
826
  const subContentContextValue = {
1161
827
  registerItem: registerSubItem,
1162
828
  unregisterItem: unregisterSubItem,
@@ -1168,59 +834,59 @@ const MenuSub = ({ label, icon, children, disabled = false, sideOffset = 20, sel
1168
834
  close: closeSubMenu,
1169
835
  isSubMenu: true
1170
836
  };
1171
- return /*#__PURE__*/ jsxs(Fragment, {
837
+ return jsxs(Fragment, {
1172
838
  children: [
1173
- /*#__PURE__*/ jsxs("div", {
839
+ jsxs("div", {
1174
840
  ref: triggerItemRef,
1175
841
  role: "menuitem",
1176
842
  "aria-haspopup": "menu",
1177
843
  "aria-expanded": isSubOpen,
1178
844
  "aria-controls": subMenuId,
1179
- "aria-describedby": showSelectedIndicator ? selectionDescriptionId : undefined,
845
+ "aria-describedby": showSelectedIndicator ? selectionDescriptionId : void 0,
1180
846
  tabIndex: isHighlighted ? 0 : -1,
1181
847
  className: SUB_TRIGGER_CLASS,
1182
848
  "data-state": isSubOpen ? "open" : "closed",
1183
- "data-highlighted": isHighlighted ? "" : undefined,
1184
- /* v8 ignore start - disabled sub-trigger not tested */ "data-disabled": disabled ? "" : undefined,
1185
- "aria-disabled": disabled || undefined,
1186
- /* v8 ignore stop */ onClick: handleTriggerClick,
849
+ "data-highlighted": isHighlighted ? "" : void 0,
850
+ "data-disabled": disabled ? "" : void 0,
851
+ "aria-disabled": disabled || void 0,
852
+ onClick: handleTriggerClick,
1187
853
  onMouseEnter: handleTriggerMouseEnter,
1188
854
  children: [
1189
- /*#__PURE__*/ jsxs("span", {
855
+ jsxs("span", {
1190
856
  className: "flex items-center",
1191
857
  children: [
1192
- showSelectedIndicator && /*#__PURE__*/ jsx("span", {
858
+ showSelectedIndicator && jsx("span", {
1193
859
  className: `mr-2 shrink-0 ${SELECTED_DOT_CLASS}`,
1194
860
  "aria-hidden": "true"
1195
861
  }),
1196
862
  icon,
1197
- /*#__PURE__*/ jsx("span", {
863
+ jsx("span", {
1198
864
  className: labelSpanClass,
1199
865
  children: label
1200
866
  })
1201
867
  ]
1202
868
  }),
1203
- /*#__PURE__*/ jsx(IconNext, {
869
+ jsx(IconNext, {
1204
870
  className: "ml-2",
1205
871
  size: "size-3",
1206
872
  monotone: true
1207
873
  })
1208
874
  ]
1209
875
  }),
1210
- showSelectedIndicator && /*#__PURE__*/ jsx("span", {
876
+ showSelectedIndicator && jsx("span", {
1211
877
  id: selectionDescriptionId,
1212
878
  className: "sr-only",
1213
879
  children: "(contains a selection)"
1214
880
  }),
1215
- isSubOpen && /*#__PURE__*/ jsx("div", {
881
+ isSubOpen && jsx("div", {
1216
882
  ref: subMenuRef,
1217
883
  id: subMenuId,
1218
884
  popover: "manual",
1219
885
  role: "menu",
1220
886
  className: SUB_CONTENT_CLASS,
1221
- children: /*#__PURE__*/ jsx(MenuGroupContext.Provider, {
887
+ children: jsx(MenuGroupContext.Provider, {
1222
888
  value: false,
1223
- children: /*#__PURE__*/ jsx(MenuContentContext.Provider, {
889
+ children: jsx(MenuContentContext.Provider, {
1224
890
  value: subContentContextValue,
1225
891
  children: children
1226
892
  })
@@ -1230,12 +896,4 @@ const MenuSub = ({ label, icon, children, disabled = false, sideOffset = 20, sel
1230
896
  });
1231
897
  };
1232
898
  MenuSub.displayName = "MenuSub";
1233
-
1234
-
1235
-
1236
-
1237
-
1238
-
1239
-
1240
-
1241
899
  export { Menu, MenuGroup, MenuItem, MenuLabel, MenuSeparator, MenuSub };