@servicetitan/anvil2 1.27.2 → 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/AnvilProvider-C7Li86-d.js +16 -0
  3. package/dist/AnvilProvider-C7Li86-d.js.map +1 -0
  4. package/dist/AnvilProvider.js +1 -1
  5. package/dist/{Combobox-DnTI2I3L.js → Combobox-JAm3x-tw.js} +1986 -116
  6. package/dist/Combobox-JAm3x-tw.js.map +1 -0
  7. package/dist/Combobox.css +343 -1
  8. package/dist/Combobox.js +1 -1
  9. package/dist/{DateField-DocC46Mw.js → DateField-5mNXaJ7q.js} +548 -11
  10. package/dist/DateField-5mNXaJ7q.js.map +1 -0
  11. package/dist/DateField.js +1 -1
  12. package/dist/{Dialog-DQ9QXB5D.js → Dialog-B4M0DXxG.js} +2 -2
  13. package/dist/{Dialog-DQ9QXB5D.js.map → Dialog-B4M0DXxG.js.map} +1 -1
  14. package/dist/{Dialog-Kh2tcVWz-DqcNnouf.js → Dialog-CUK5YvVY-Dv5edacC.js} +5 -5
  15. package/dist/Dialog-CUK5YvVY-Dv5edacC.js.map +1 -0
  16. package/dist/Dialog.js +1 -1
  17. package/dist/Drawer-BqqZB3Sn.js +66 -0
  18. package/dist/Drawer-BqqZB3Sn.js.map +1 -0
  19. package/dist/{Drawer-C6fpnRDX.js → Drawer-CrXiK2w0-BMzKuNFt.js} +15 -75
  20. package/dist/Drawer-CrXiK2w0-BMzKuNFt.js.map +1 -0
  21. package/dist/Drawer.js +1 -1
  22. package/dist/{AnvilProvider-DNJk1Ait.js → HammerProvider-DuxhW0gv-C2voN5ro.js} +26 -15
  23. package/dist/HammerProvider-DuxhW0gv-C2voN5ro.js.map +1 -0
  24. package/dist/{InputMask-Ceh574pv.js → InputMask-BmXj5mob.js} +2 -2
  25. package/dist/{InputMask-Ceh574pv.js.map → InputMask-BmXj5mob.js.map} +1 -1
  26. package/dist/{InputMask-DQXw5qvG-BH4P-Woc.js → InputMask-CQzrMoEy-CLNvXsm7.js} +3 -3
  27. package/dist/{InputMask-DQXw5qvG-BH4P-Woc.js.map → InputMask-CQzrMoEy-CLNvXsm7.js.map} +1 -1
  28. package/dist/InputMask.js +1 -1
  29. package/dist/{Label-DWF2pXeG-1BhzVgZG.js → Label-CbYy5kwu-BCTOKxOk.js} +3 -3
  30. package/dist/{Label-DWF2pXeG-1BhzVgZG.js.map → Label-CbYy5kwu-BCTOKxOk.js.map} +1 -1
  31. package/dist/Menu-IEBrkdoN.js +1090 -0
  32. package/dist/Menu-IEBrkdoN.js.map +1 -0
  33. package/dist/Menu.css +116 -1
  34. package/dist/Menu.js +1 -1
  35. package/dist/{Page-BGkLs3bR.js → Page-qlpHVAMH.js} +70 -54
  36. package/dist/Page-qlpHVAMH.js.map +1 -0
  37. package/dist/Page.css +103 -70
  38. package/dist/Page.js +1 -1
  39. package/dist/{Popover-DzEc_Muv.js → Popover-B7K3o_l4.js} +2 -2
  40. package/dist/{Popover-DzEc_Muv.js.map → Popover-B7K3o_l4.js.map} +1 -1
  41. package/dist/{Popover-QKZtjN4_-CETYlWwq.js → Popover-C1B3UJXp-B5obSIvA.js} +351 -12
  42. package/dist/Popover-C1B3UJXp-B5obSIvA.js.map +1 -0
  43. package/dist/{Popover-QKZtjN4_.css → Popover-C1B3UJXp.css} +53 -1
  44. package/dist/Popover.js +1 -1
  45. package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js → ProgressBar-BLg29adn-CMz5eu5f.js} +3 -3
  46. package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js.map → ProgressBar-BLg29adn-CMz5eu5f.js.map} +1 -1
  47. package/dist/{ProgressBar-IItIByYc.js → ProgressBar-_DyYSgfx.js} +2 -2
  48. package/dist/{ProgressBar-IItIByYc.js.map → ProgressBar-_DyYSgfx.js.map} +1 -1
  49. package/dist/ProgressBar.js +1 -1
  50. package/dist/{SearchField-CWb0kaV8.js → SearchField-C-4icPUa.js} +2 -2
  51. package/dist/{SearchField-CWb0kaV8.js.map → SearchField-C-4icPUa.js.map} +1 -1
  52. package/dist/SearchField.js +1 -1
  53. package/dist/{TextField-D53XNiCi-C6_A5VRq.js → TextField-Lwe9XAou-tH8gcQTq.js} +2 -2
  54. package/dist/{TextField-D53XNiCi-C6_A5VRq.js.map → TextField-Lwe9XAou-tH8gcQTq.js.map} +1 -1
  55. package/dist/{TextField-s92xHzb3.js → TextField-tF-ERwA8.js} +2 -2
  56. package/dist/{TextField-s92xHzb3.js.map → TextField-tF-ERwA8.js.map} +1 -1
  57. package/dist/TextField.js +1 -1
  58. package/dist/{Textarea-B61wNIFr.js → Textarea-BrzxOEx3.js} +2 -2
  59. package/dist/Textarea-BrzxOEx3.js.map +1 -0
  60. package/dist/Textarea.js +1 -1
  61. package/dist/Toast.js +1 -1
  62. package/dist/{Toolbar-Cge6Nznj.js → Toolbar-D9fMSiGU.js} +2 -2
  63. package/dist/{Toolbar-Cge6Nznj.js.map → Toolbar-D9fMSiGU.js.map} +1 -1
  64. package/dist/Toolbar.js +1 -1
  65. package/dist/{Tooltip-DgM8NSPm-CRIQbuTm.js → Tooltip-36nMbVT3-DMkvo60s.js} +222 -22
  66. package/dist/Tooltip-36nMbVT3-DMkvo60s.js.map +1 -0
  67. package/dist/{Tooltip-DgM8NSPm.css → Tooltip-36nMbVT3.css} +43 -1
  68. package/dist/{Tooltip-89FIvMG0.js → Tooltip-BEo0IRDf.js} +2 -2
  69. package/dist/{Tooltip-89FIvMG0.js.map → Tooltip-BEo0IRDf.js.map} +1 -1
  70. package/dist/Tooltip.js +1 -1
  71. package/dist/components/Page/Page.d.ts +4 -1
  72. package/dist/floating-ui.react-4AwURJA3.js +5989 -0
  73. package/dist/floating-ui.react-4AwURJA3.js.map +1 -0
  74. package/dist/{useKeyboardFocusables-CwVMAe5C-CIHqixNA.js → index.esm-CunAFnrh.js} +11 -59
  75. package/dist/index.esm-CunAFnrh.js.map +1 -0
  76. package/dist/index.js +16 -16
  77. package/dist/supportsPopover-8aJR37cf-8aJR37cf.js +6 -0
  78. package/dist/supportsPopover-8aJR37cf-8aJR37cf.js.map +1 -0
  79. package/dist/{toast-CHld8RKY.js → toast-DkO9HWpH.js} +2 -2
  80. package/dist/{toast-CHld8RKY.js.map → toast-DkO9HWpH.js.map} +1 -1
  81. package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js +61 -0
  82. package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js.map +1 -0
  83. package/package.json +2 -2
  84. package/dist/AnvilProvider-DNJk1Ait.js.map +0 -1
  85. package/dist/Combobox-DnTI2I3L.js.map +0 -1
  86. package/dist/DateField-DocC46Mw.js.map +0 -1
  87. package/dist/Dialog-Kh2tcVWz-DqcNnouf.js.map +0 -1
  88. package/dist/Drawer-C6fpnRDX.js.map +0 -1
  89. package/dist/Menu-D8SDm9s9.js +0 -706
  90. package/dist/Menu-D8SDm9s9.js.map +0 -1
  91. package/dist/Page-BGkLs3bR.js.map +0 -1
  92. package/dist/Popover-QKZtjN4_-CETYlWwq.js.map +0 -1
  93. package/dist/Textarea-B61wNIFr.js.map +0 -1
  94. package/dist/Tooltip-DgM8NSPm-CRIQbuTm.js.map +0 -1
  95. package/dist/floating-ui.react-P5949bpO.js +0 -28
  96. package/dist/floating-ui.react-P5949bpO.js.map +0 -1
  97. package/dist/floating-ui.react-dom-D912oS4K.js +0 -1841
  98. package/dist/floating-ui.react-dom-D912oS4K.js.map +0 -1
  99. package/dist/useKeyboardFocusables-CwVMAe5C-CIHqixNA.js.map +0 -1
  100. /package/dist/{Dialog-Kh2tcVWz.css → Dialog-CUK5YvVY.css} +0 -0
  101. /package/dist/{Drawer.css → Drawer-CrXiK2w0.css} +0 -0
  102. /package/dist/{Label-DWF2pXeG.css → Label-CbYy5kwu.css} +0 -0
  103. /package/dist/{ProgressBar-cKtBso7j.css → ProgressBar-BLg29adn.css} +0 -0
@@ -0,0 +1,1090 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { forwardRef, useContext, createContext, useState, useRef, useEffect, useMemo, useId, useCallback, useLayoutEffect } from 'react';
4
+ import { useTrackingId } from './useTrackingId.js';
5
+ import { c as childrenToString } from './childrenToString-Bz9MqbHb-Bz9MqbHb.js';
6
+ import { c as cx } from './index-tZvMCc77.js';
7
+ import { e as DialogContext } from './Dialog-CUK5YvVY-Dv5edacC.js';
8
+ import { B as Button } from './Button-Ce--YZ9L-Csh0Zzuf.js';
9
+ import { S as SvgArrowDropDown } from './arrow_drop_down-ChAdBDux.js';
10
+ import { I as Icon } from './Icon-DbHA5GV1-DwO2aGkj.js';
11
+ import { s as supportsPopover } from './supportsPopover-8aJR37cf-8aJR37cf.js';
12
+ import { v as useListItem, w as useFloatingTree, x as useFloatingNodeId, y as useFloatingParentNodeId, d as useFloating, o as offset, f as flip, s as shift, l as limitShift, r as size, e as autoUpdate, h as useHover, i as safePolygon, t as useClick, m as useRole, k as useDismiss, z as useListNavigation, A as useTypeahead, n as useInteractions, B as FloatingNode, C as FloatingList, F as FloatingPortal, q as FloatingFocusManager, D as FloatingTree, p as computePosition } from './floating-ui.react-4AwURJA3.js';
13
+ import { a as PortalProviderContext } from './PortalProvider-9lXkQ0xY-BKoGegS1.js';
14
+ import { e as DrawerContext } from './Drawer-CrXiK2w0-BMzKuNFt.js';
15
+ import { a as ThemeProviderContext, T as ThemeProvider } from './ThemeProvider-CioBp3gk-B6HyDICa.js';
16
+ import { u as useMergeRefs } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
17
+
18
+ import './Menu.css';const SvgArrowDropUp = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("path", { d: "M8.71 12.29 11.3 9.7a.996.996 0 0 1 1.41 0l2.59 2.59c.63.63.18 1.71-.71 1.71H9.41c-.89 0-1.33-1.08-.7-1.71z" }));
19
+
20
+ const SvgNavigateNext = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("path", { d: "M9.31 6.71a.996.996 0 0 0 0 1.41L13.19 12l-3.88 3.88a.996.996 0 1 0 1.41 1.41l4.59-4.59a.996.996 0 0 0 0-1.41L10.72 6.7c-.38-.38-1.02-.38-1.41.01z" }));
21
+
22
+ const item$1 = "_item_1q43b_5";
23
+ const menu = "_menu_1q43b_49";
24
+ const scroll = "_scroll_1q43b_60";
25
+ const disabled$1 = "_disabled_1q43b_108";
26
+ const styles$1 = {
27
+ "nested-menu": "_nested-menu_1q43b_4",
28
+ item: item$1,
29
+ menu: menu,
30
+ scroll: scroll,
31
+ "arrow-down": "_arrow-down_1q43b_70",
32
+ "arrow-up": "_arrow-up_1q43b_71",
33
+ "arrow-icon": "_arrow-icon_1q43b_83",
34
+ disabled: disabled$1
35
+ };
36
+
37
+ const MenuLegacyItem = forwardRef(({ label, disabled, icon, className, ...props }, forwardedRef) => {
38
+ const MenuLegacy = useContext(MenuLegacyContext);
39
+ const item = useListItem({
40
+ label: disabled ? null : childrenToString(label)
41
+ });
42
+ const tree = useFloatingTree();
43
+ const isActive = item.index === MenuLegacy.activeIndex;
44
+ const itemCx = cx([styles$1["item"]], className);
45
+ return /* @__PURE__ */ jsxs(
46
+ "button",
47
+ {
48
+ ...props,
49
+ ref: useMergeRefs([item.ref, forwardedRef]),
50
+ type: "button",
51
+ role: "menuitem",
52
+ "data-anv": "menu-item",
53
+ className: itemCx,
54
+ tabIndex: isActive ? 0 : -1,
55
+ disabled,
56
+ ...MenuLegacy.getItemProps({
57
+ onClick(event) {
58
+ props.onClick?.(event);
59
+ tree?.events.emit("click");
60
+ },
61
+ onFocus(event) {
62
+ props.onFocus?.(event);
63
+ MenuLegacy.setHasFocusInside?.(true);
64
+ }
65
+ }),
66
+ children: [
67
+ icon ? /* @__PURE__ */ jsx(Icon, { inherit: true, "aria-hidden": true, svg: icon }) : null,
68
+ label
69
+ ]
70
+ }
71
+ );
72
+ });
73
+ MenuLegacyItem.displayName = "MenuLegacyItem";
74
+
75
+ const MenuLegacyContext = createContext({
76
+ getItemProps: () => ({}),
77
+ activeIndex: null,
78
+ isOpen: false
79
+ });
80
+ const MenuLegacyComponent = forwardRef(
81
+ ({
82
+ children,
83
+ disableAutoHeight,
84
+ open,
85
+ icon,
86
+ root,
87
+ placement = "bottom-start",
88
+ ...props
89
+ }, forwardedRef) => {
90
+ const [isOpen, setIsOpen] = useState(!!open || false);
91
+ const [hasFocusInside, setHasFocusInside] = useState(false);
92
+ const [activeIndex, setActiveIndex] = useState(null);
93
+ const scrollRef = useRef(null);
94
+ const [scrollTop, setScrollTop] = useState(0);
95
+ const [menuHeight, setMenuLegacyHeight] = useState(null);
96
+ const [arrowStart, setArrowStart] = useState(false);
97
+ const [arrowEnd, setArrowEnd] = useState(false);
98
+ const elementsRef = useRef([]);
99
+ const labelsRef = useRef([]);
100
+ const parent = useContext(MenuLegacyContext);
101
+ const { root: portalRoot } = useContext(PortalProviderContext);
102
+ const tree = useFloatingTree();
103
+ const nodeId = useFloatingNodeId();
104
+ const parentId = useFloatingParentNodeId();
105
+ const item = useListItem();
106
+ const isNested = parentId != null;
107
+ const { theme, mode = "light" } = useContext(ThemeProviderContext);
108
+ const dialogContext = useContext(DialogContext);
109
+ const drawerContext = useContext(DrawerContext);
110
+ const fallbackArr = () => {
111
+ if (!isNested) {
112
+ if (placement.startsWith("top")) {
113
+ return disableAutoHeight ? placement : ["top-start", "top-end", "bottom-start", "bottom-end"];
114
+ }
115
+ return disableAutoHeight ? placement : ["bottom-start", "bottom-end", "top-start", "top-end"];
116
+ }
117
+ return parent.disableAutoHeight ? ["right-start"] : ["right-start", "right-end", "left-start", "left-end"];
118
+ };
119
+ const handleIsOpenChange = (internalOpen) => {
120
+ if (typeof open === "boolean") {
121
+ setIsOpen(open);
122
+ return;
123
+ }
124
+ setIsOpen(internalOpen);
125
+ };
126
+ const { floatingStyles, refs, context } = useFloating({
127
+ nodeId,
128
+ open: isOpen,
129
+ onOpenChange: handleIsOpenChange,
130
+ placement: isNested ? "right-start" : placement,
131
+ middleware: [
132
+ offset({
133
+ mainAxis: isNested ? 0 : 4,
134
+ alignmentAxis: isNested ? -4 : 0
135
+ }),
136
+ flip({
137
+ fallbackStrategy: "bestFit",
138
+ fallbackPlacements: fallbackArr()
139
+ }),
140
+ shift({
141
+ mainAxis: !parent.disableAutoHeight,
142
+ crossAxis: false,
143
+ limiter: limitShift({
144
+ mainAxis: !parent.disableAutoHeight
145
+ })
146
+ }),
147
+ size({
148
+ padding: 8,
149
+ apply({ availableWidth, availableHeight, elements }) {
150
+ if (disableAutoHeight ?? parent.disableAutoHeight) return;
151
+ setMenuLegacyHeight(availableHeight);
152
+ Object.assign(elements.floating.style, {
153
+ maxWidth: `${availableWidth}px`,
154
+ maxHeight: `${availableHeight}px`
155
+ });
156
+ }
157
+ })
158
+ ],
159
+ whileElementsMounted: autoUpdate
160
+ });
161
+ const [hoverEnabled, setHoverEnabled] = useState(false);
162
+ const hover = useHover(context, {
163
+ enabled: hoverEnabled,
164
+ delay: { open: 75 },
165
+ handleClose: safePolygon({ blockPointerEvents: true })
166
+ });
167
+ const click = useClick(context, {
168
+ event: "mousedown",
169
+ toggle: !isNested,
170
+ ignoreMouse: isNested
171
+ });
172
+ const role = useRole(context, { role: "menu" });
173
+ const dismiss = useDismiss(context, { bubbles: true });
174
+ const listNavigation = useListNavigation(context, {
175
+ listRef: elementsRef,
176
+ activeIndex,
177
+ nested: isNested,
178
+ onNavigate: setActiveIndex
179
+ });
180
+ const typeahead = useTypeahead(context, {
181
+ listRef: labelsRef,
182
+ onMatch: isOpen ? setActiveIndex : undefined,
183
+ activeIndex
184
+ });
185
+ const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([hover, click, role, dismiss, listNavigation, typeahead]);
186
+ useEffect(() => {
187
+ if (!tree) return;
188
+ function handleTreeClick() {
189
+ setIsOpen(!!open || false);
190
+ }
191
+ function onSubMenuLegacyOpen(event) {
192
+ if (event.nodeId === nodeId || event.parentId !== parentId) {
193
+ return;
194
+ }
195
+ setIsOpen(!!open || false);
196
+ }
197
+ tree.events.on("click", handleTreeClick);
198
+ tree.events.on("menuopen", onSubMenuLegacyOpen);
199
+ return () => {
200
+ tree.events.off("click", handleTreeClick);
201
+ tree.events.off("menuopen", onSubMenuLegacyOpen);
202
+ };
203
+ }, [tree, nodeId, parentId]);
204
+ useEffect(() => {
205
+ if (disableAutoHeight ?? parent.disableAutoHeight) return;
206
+ if (!isOpen) {
207
+ setMenuLegacyHeight(null);
208
+ return;
209
+ }
210
+ setTimeout(() => {
211
+ if (!scrollRef.current || !refs.floating.current) return;
212
+ setMenuLegacyHeight(refs.floating.current.clientHeight);
213
+ const isOverflow = scrollRef.current.scrollHeight > refs.floating.current.clientHeight;
214
+ if (!isOverflow) return;
215
+ const showTop = scrollRef.current.scrollTop > 0;
216
+ const showBottom = scrollRef.current.scrollHeight - refs.floating.current.clientHeight - scrollTop - 16 > 0;
217
+ setArrowStart(showTop);
218
+ setArrowEnd(showBottom);
219
+ }, 0);
220
+ }, [
221
+ disableAutoHeight,
222
+ isOpen,
223
+ parent.disableAutoHeight,
224
+ refs.floating,
225
+ scrollTop
226
+ ]);
227
+ useEffect(() => {
228
+ if (!isOpen || !tree) return;
229
+ tree.events.emit("menuopen", { parentId, nodeId });
230
+ }, [tree, isOpen, nodeId, parentId]);
231
+ const menuComponentCX = cx({
232
+ [styles$1["nested-menu"]]: isNested,
233
+ [styles$1["item"]]: !isNested
234
+ });
235
+ const menuRefs = useMergeRefs([refs.setReference, item.ref, forwardedRef]);
236
+ const triggerProps = {
237
+ "data-open": isOpen,
238
+ "data-focus-inside": hasFocusInside,
239
+ ref: menuRefs,
240
+ ...getReferenceProps(
241
+ parent.getItemProps({
242
+ ...props,
243
+ // This is to allow any type of element to be used as a custom trigger element
244
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
245
+ onFocus(event) {
246
+ props.onFocus?.(event);
247
+ setHasFocusInside(false);
248
+ parent.setHasFocusInside?.(true);
249
+ }
250
+ // This is to allow any type of element to be used as a custom trigger element
251
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
252
+ })
253
+ )
254
+ };
255
+ const value = useMemo(
256
+ () => ({
257
+ activeIndex,
258
+ setActiveIndex,
259
+ getItemProps,
260
+ setHasFocusInside,
261
+ isOpen,
262
+ disableAutoHeight: disableAutoHeight ?? parent.disableAutoHeight
263
+ }),
264
+ [
265
+ activeIndex,
266
+ disableAutoHeight,
267
+ getItemProps,
268
+ isOpen,
269
+ parent.disableAutoHeight
270
+ ]
271
+ );
272
+ return /* @__PURE__ */ jsxs(FloatingNode, { id: nodeId, children: [
273
+ isNested ? /* @__PURE__ */ jsxs(
274
+ "button",
275
+ {
276
+ ref: menuRefs,
277
+ tabIndex: parent.activeIndex === item.index ? 0 : -1,
278
+ role: "menuitem",
279
+ "data-anv": "menu-item",
280
+ "data-open": isOpen ? "" : undefined,
281
+ "data-nested": "",
282
+ "data-focus-inside": hasFocusInside ? "" : undefined,
283
+ className: menuComponentCX,
284
+ ...getReferenceProps(
285
+ parent.getItemProps({
286
+ ...props,
287
+ onFocus(event) {
288
+ props.onFocus?.(event);
289
+ setHasFocusInside(false);
290
+ parent.setHasFocusInside?.(true);
291
+ },
292
+ onMouseEnter: () => setHoverEnabled(true)
293
+ })
294
+ ),
295
+ children: [
296
+ icon ? /* @__PURE__ */ jsx(Icon, { inherit: true, "aria-hidden": true, svg: icon }) : null,
297
+ "label" in props && props.label,
298
+ /* @__PURE__ */ jsx("div", { style: { flexGrow: 1 } }),
299
+ /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, svg: SvgNavigateNext })
300
+ ]
301
+ }
302
+ ) : "trigger" in props ? props.trigger?.(triggerProps) : /* @__PURE__ */ jsx(
303
+ Button,
304
+ {
305
+ ...props,
306
+ ...triggerProps,
307
+ ...getReferenceProps({
308
+ onFocus: (event) => props.onFocus?.(event)
309
+ }),
310
+ icon,
311
+ "data-anv": "menu",
312
+ children: "label" in props && props.label
313
+ }
314
+ ),
315
+ /* @__PURE__ */ jsx(MenuLegacyContext.Provider, { value, children: /* @__PURE__ */ jsx(FloatingList, { elementsRef, labelsRef, children: isOpen && (dialogContext == null || dialogContext?.ref?.current != null) && /* @__PURE__ */ jsx(
316
+ FloatingPortal,
317
+ {
318
+ root: root ?? dialogContext?.ref?.current ?? drawerContext?.ref?.current ?? portalRoot,
319
+ children: /* @__PURE__ */ jsx(
320
+ FloatingFocusManager,
321
+ {
322
+ context,
323
+ modal: false,
324
+ initialFocus: isNested ? -1 : 0,
325
+ returnFocus: !isNested,
326
+ children: /* @__PURE__ */ jsx(ThemeProvider, { theme, mode, children: /* @__PURE__ */ jsxs(
327
+ "div",
328
+ {
329
+ ref: refs.setFloating,
330
+ className: styles$1["menu"],
331
+ style: floatingStyles,
332
+ ...getFloatingProps({
333
+ onMouseEnter: () => {
334
+ setHoverEnabled(false);
335
+ },
336
+ onKeyDown: (e) => {
337
+ if (e.code === "ArrowLeft" || e.code === "ArrowRight") {
338
+ e.stopPropagation();
339
+ }
340
+ }
341
+ }),
342
+ children: [
343
+ arrowStart && /* @__PURE__ */ jsx("div", { className: styles$1["arrow-up"], "aria-hidden": true, children: /* @__PURE__ */ jsx(
344
+ Icon,
345
+ {
346
+ svg: SvgArrowDropUp,
347
+ size: "xlarge",
348
+ className: styles$1["arrow-icon"]
349
+ }
350
+ ) }),
351
+ /* @__PURE__ */ jsx(
352
+ "div",
353
+ {
354
+ ref: scrollRef,
355
+ className: styles$1["scroll"],
356
+ style: {
357
+ position: "relative",
358
+ maxHeight: menuHeight ?? "inherit"
359
+ },
360
+ onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
361
+ children
362
+ }
363
+ ),
364
+ arrowEnd && /* @__PURE__ */ jsx("div", { className: styles$1["arrow-down"], "aria-hidden": true, children: /* @__PURE__ */ jsx(
365
+ Icon,
366
+ {
367
+ svg: SvgArrowDropDown,
368
+ size: "xlarge",
369
+ className: styles$1["arrow-icon"]
370
+ }
371
+ ) })
372
+ ]
373
+ }
374
+ ) })
375
+ }
376
+ )
377
+ }
378
+ ) }) })
379
+ ] });
380
+ }
381
+ );
382
+ MenuLegacyComponent.displayName = "MenuLegacyComponent";
383
+ const MenuLegacyElement = forwardRef(
384
+ (props, ref) => {
385
+ const parentId = useFloatingParentNodeId();
386
+ if (parentId === null) {
387
+ return /* @__PURE__ */ jsx(FloatingTree, { children: /* @__PURE__ */ jsx(MenuLegacyComponent, { ...props, ref }) });
388
+ }
389
+ return /* @__PURE__ */ jsx(MenuLegacyComponent, { ...props, ref });
390
+ }
391
+ );
392
+ MenuLegacyElement.displayName = "MenuLegacy";
393
+ Object.assign(MenuLegacyElement, {
394
+ Item: MenuLegacyItem
395
+ });
396
+
397
+ const item = "_item_hid8p_3";
398
+ const content = "_content_hid8p_16";
399
+ const scroller = "_scroller_hid8p_46";
400
+ const disabled = "_disabled_hid8p_124";
401
+ const styles = {
402
+ item: item,
403
+ content: content,
404
+ scroller: scroller,
405
+ "arrow-down": "_arrow-down_hid8p_62",
406
+ "arrow-up": "_arrow-up_hid8p_63",
407
+ "arrow-icon": "_arrow-icon_hid8p_75",
408
+ "no-padding": "_no-padding_hid8p_117",
409
+ disabled: disabled
410
+ };
411
+
412
+ const MenuItem$1 = forwardRef((props, ref) => {
413
+ const {
414
+ label,
415
+ disabled,
416
+ icon,
417
+ className,
418
+ onClick,
419
+ onMouseEnter,
420
+ id: idProp,
421
+ ...rest
422
+ } = props;
423
+ const menuContext = useContext(MenuContext);
424
+ const uid = useId();
425
+ const buttonRef = useRef(null);
426
+ const combinedRef = useMergeRefs([buttonRef, ref]);
427
+ const [tabIndex, setTabIndex] = useState(-1);
428
+ const itemCx = cx([styles["item"]], className);
429
+ const onClickHandler = (e) => {
430
+ if (disabled) {
431
+ e.preventDefault();
432
+ e.stopPropagation();
433
+ return;
434
+ }
435
+ onClick?.(e);
436
+ menuContext?.closeRootMenu();
437
+ };
438
+ const onMouseEnterHandler = (e) => {
439
+ onMouseEnter?.(e);
440
+ buttonRef.current?.focus();
441
+ };
442
+ const onFocusHandler = () => {
443
+ setTabIndex(0);
444
+ };
445
+ const onBlurHandler = () => {
446
+ setTabIndex(-1);
447
+ };
448
+ if (!supportsPopover()) return /* @__PURE__ */ jsx(MenuLegacyItem, { ...props, ref });
449
+ return /* @__PURE__ */ jsxs(
450
+ "button",
451
+ {
452
+ ...rest,
453
+ ref: combinedRef,
454
+ type: "button",
455
+ role: "menuitem",
456
+ "data-anv": "menu-item",
457
+ id: idProp ?? `menuitem-${uid.replace(/:/g, "")}`,
458
+ className: itemCx,
459
+ tabIndex,
460
+ "aria-disabled": disabled,
461
+ onClick: onClickHandler,
462
+ onMouseEnter: onMouseEnterHandler,
463
+ onFocus: onFocusHandler,
464
+ onBlur: onBlurHandler,
465
+ children: [
466
+ icon ? /* @__PURE__ */ jsx(Icon, { inherit: true, "aria-hidden": true, svg: icon }) : null,
467
+ label
468
+ ]
469
+ }
470
+ );
471
+ });
472
+ MenuItem$1.displayName = "MenuItem";
473
+
474
+ const MenuNested = (props) => {
475
+ const { children, open, defaultOpen = false, label, className, icon } = props;
476
+ const uid = useId();
477
+ const [tabIndex, setTabIndex] = useState(-1);
478
+ const [openState, setOpenState] = useState(open ?? defaultOpen);
479
+ const [scrollTop, setScrollTop] = useState(0);
480
+ const [menuHeight, setMenuHeight] = useState(null);
481
+ const [arrowStart, setArrowStart] = useState(false);
482
+ const [arrowEnd, setArrowEnd] = useState(false);
483
+ const invokerRef = useRef(null);
484
+ const menuRef = useRef(null);
485
+ const childrenRef = useRef(null);
486
+ const containerRef = useRef(null);
487
+ const [focusItems, setFocusItems] = useState();
488
+ const menuContext = useContext(MenuContext);
489
+ const fallbackArr = useCallback(() => {
490
+ return menuContext?.disableAutoHeight ? ["right-start"] : ["right-start", "right-end", "left-start", "left-end"];
491
+ }, [menuContext?.disableAutoHeight]);
492
+ const updatePosition = useCallback(() => {
493
+ if (!invokerRef.current || !menuRef.current) return;
494
+ computePosition(invokerRef.current, menuRef.current, {
495
+ placement: "right-start",
496
+ middleware: [
497
+ offset({
498
+ mainAxis: 0,
499
+ alignmentAxis: -4
500
+ }),
501
+ flip({
502
+ fallbackStrategy: "bestFit",
503
+ fallbackPlacements: fallbackArr()
504
+ }),
505
+ shift({
506
+ mainAxis: !menuContext?.disableAutoHeight,
507
+ crossAxis: false,
508
+ limiter: limitShift({
509
+ mainAxis: !menuContext?.disableAutoHeight
510
+ })
511
+ }),
512
+ size({
513
+ padding: 8,
514
+ apply({ availableWidth, availableHeight, elements }) {
515
+ if (menuContext?.disableAutoHeight) return;
516
+ setMenuHeight(availableHeight);
517
+ Object.assign(elements.floating.style, {
518
+ maxWidth: `${availableWidth - 16}px`,
519
+ maxHeight: `${availableHeight - 16}px`
520
+ });
521
+ }
522
+ })
523
+ ]
524
+ }).then(({ x, y }) => {
525
+ if (!menuRef.current) return;
526
+ Object.assign(menuRef.current.style, {
527
+ left: `${x}px`,
528
+ top: `${y + 8}px`
529
+ });
530
+ });
531
+ }, [fallbackArr, menuContext?.disableAutoHeight]);
532
+ const menuReference = useRef(null);
533
+ useLayoutEffect(() => {
534
+ if (!openState) {
535
+ setMenuHeight(null);
536
+ setScrollTop(0);
537
+ return;
538
+ }
539
+ if (!menuRef.current) return;
540
+ menuReference.current = menuRef.current;
541
+ const observer = new ResizeObserver((entries) => {
542
+ /* istanbul ignore next -- @preserve */
543
+ setTimeout(() => {
544
+ if (!childrenRef.current || !menuReference.current) return;
545
+ setMenuHeight(menuReference.current.clientHeight);
546
+ const isOverflow = childrenRef.current.scrollHeight > menuReference.current.clientHeight;
547
+ if (!isOverflow) return;
548
+ const showTop = childrenRef.current.scrollTop > 0;
549
+ const showBottom = childrenRef.current.scrollHeight - menuReference.current.clientHeight - scrollTop - 16 > 0;
550
+ setArrowStart(showTop);
551
+ setArrowEnd(showBottom);
552
+ }, 100);
553
+ });
554
+ if (menuReference.current) {
555
+ observer.observe(menuReference.current);
556
+ }
557
+ return () => {
558
+ if (menuReference.current) {
559
+ observer.unobserve(menuReference.current);
560
+ }
561
+ observer.disconnect();
562
+ };
563
+ }, [openState, scrollTop]);
564
+ useLayoutEffect(() => {
565
+ if (!menuRef.current || !invokerRef.current) return;
566
+ const cleanup = autoUpdate(invokerRef.current, menuRef.current, () => {
567
+ updatePosition();
568
+ });
569
+ return () => {
570
+ cleanup();
571
+ };
572
+ }, [updatePosition]);
573
+ const popoverHoverTriggered = useRef();
574
+ const openMenu = useCallback(async () => {
575
+ popoverHoverTriggered.current = true;
576
+ await new Promise((resolve) => setTimeout(resolve, 100));
577
+ if (!popoverHoverTriggered.current || !menuRef.current || !childrenRef.current)
578
+ return;
579
+ menuRef.current.showPopover();
580
+ setOpenState(true);
581
+ const focusables = Array.from(
582
+ childrenRef.current.querySelectorAll(
583
+ `#scroller-${uid.replace(/:/g, "")} > button, #scroller-${uid.replace(/:/g, "")} > div[data-nested="true"] > button, #scroller-${uid.replace(/:/g, "")} > a[href]`
584
+ )
585
+ );
586
+ setFocusItems(focusables);
587
+ }, [uid]);
588
+ const closeMenu = useCallback(async (fn) => {
589
+ popoverHoverTriggered.current = false;
590
+ await new Promise((resolve) => setTimeout(resolve, 100));
591
+ if (popoverHoverTriggered.current || !menuRef.current) return;
592
+ fn?.();
593
+ menuRef.current.hidePopover();
594
+ setOpenState(false);
595
+ }, []);
596
+ const isControlled = typeof open !== "undefined";
597
+ const initialRender = useRef(true);
598
+ useEffect(() => {
599
+ if (!isControlled) return;
600
+ if (initialRender.current === true) {
601
+ open && menuRef.current && openMenu();
602
+ initialRender.current = false;
603
+ return;
604
+ }
605
+ setOpenState(open);
606
+ open ? openMenu() : closeMenu();
607
+ }, [closeMenu, isControlled, open, openMenu]);
608
+ useEffect(() => {
609
+ if (!containerRef.current) return;
610
+ const nestedContainer = containerRef.current;
611
+ nestedContainer.addEventListener("focusin", (e) => {
612
+ openMenu();
613
+ });
614
+ nestedContainer.addEventListener("focusout", () => closeMenu());
615
+ return () => {
616
+ nestedContainer.removeEventListener("focusin", () => openMenu());
617
+ nestedContainer.removeEventListener("focusout", () => closeMenu());
618
+ };
619
+ }, [closeMenu, openMenu]);
620
+ const onKeyDownHandler = (e) => {
621
+ if (!openState || !childrenRef.current) return;
622
+ const currentActiveIndex = focusItems?.findIndex(
623
+ (item) => item.id === document.activeElement?.id
624
+ );
625
+ const firstItem = focusItems?.[0];
626
+ const lastItem = focusItems?.[focusItems.length - 1];
627
+ if (e.code === "Escape") {
628
+ menuContext?.closeRootMenu();
629
+ }
630
+ if (e.code === "ArrowLeft") {
631
+ e.stopPropagation();
632
+ e.preventDefault();
633
+ invokerRef.current?.focus();
634
+ closeMenu();
635
+ }
636
+ if (e.code === "ArrowDown") {
637
+ e.stopPropagation();
638
+ if (currentActiveIndex === (focusItems?.length ?? 0) - 1) {
639
+ firstItem.focus();
640
+ return;
641
+ }
642
+ const nextItem = focusItems?.[(currentActiveIndex ?? 0) + 1];
643
+ nextItem.focus();
644
+ return;
645
+ }
646
+ if (e.code === "ArrowUp") {
647
+ e.stopPropagation();
648
+ e.preventDefault();
649
+ if (currentActiveIndex === 0) {
650
+ lastItem.focus();
651
+ return;
652
+ }
653
+ const prevItem = focusItems?.[(currentActiveIndex ?? 0) - 1];
654
+ prevItem.focus();
655
+ return;
656
+ }
657
+ };
658
+ const onFocusHandler = () => {
659
+ setTabIndex(0);
660
+ };
661
+ const onBlurHandler = () => {
662
+ setTabIndex(-1);
663
+ };
664
+ const MenuButtonOnKeyDownHandler = (e) => {
665
+ if (e.code === "ArrowRight") {
666
+ e.stopPropagation();
667
+ e.preventDefault();
668
+ openMenu();
669
+ const firstItem = menuRef.current?.querySelectorAll(
670
+ `#scroller-${uid.replace(/:/g, "")} > button, #scroller-${uid.replace(/:/g, "")} > a[href]`
671
+ )[0];
672
+ firstItem.focus();
673
+ }
674
+ };
675
+ const MenuButtonOnClick = () => {
676
+ if (isControlled) return;
677
+ openMenu();
678
+ };
679
+ const itemCx = cx([styles["item"]], className);
680
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, "data-nested": "true", children: [
681
+ /* @__PURE__ */ jsxs(
682
+ "button",
683
+ {
684
+ role: "menuitem",
685
+ "data-anv": "menu-item",
686
+ "data-state": openState ? "open" : "close",
687
+ ref: invokerRef,
688
+ id: `menuitem-${uid.replace(/:/g, "")}`,
689
+ "aria-expanded": openState,
690
+ onMouseEnter: (e) => {
691
+ e.currentTarget.focus();
692
+ },
693
+ onKeyDown: MenuButtonOnKeyDownHandler,
694
+ onFocus: onFocusHandler,
695
+ onBlur: onBlurHandler,
696
+ onClick: MenuButtonOnClick,
697
+ "aria-haspopup": true,
698
+ "aria-controls": `menu-${uid.replace(/:/g, "")}`,
699
+ className: itemCx,
700
+ tabIndex,
701
+ children: [
702
+ icon ? /* @__PURE__ */ jsx(Icon, { inherit: true, "aria-hidden": true, svg: icon }) : null,
703
+ label,
704
+ /* @__PURE__ */ jsx("div", { style: { flexGrow: 1 } }),
705
+ /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, svg: SvgNavigateNext })
706
+ ]
707
+ }
708
+ ),
709
+ /* @__PURE__ */ jsxs(
710
+ "div",
711
+ {
712
+ popover: "auto",
713
+ id: `menu-${uid.replace(/:/g, "")}`,
714
+ "data-anv": "menu-content",
715
+ className: styles.content,
716
+ ref: menuRef,
717
+ role: "presentation",
718
+ onKeyDown: onKeyDownHandler,
719
+ children: [
720
+ arrowStart && /* @__PURE__ */ jsx("div", { className: styles["arrow-up"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropUp, size: "xlarge", className: styles["arrow-icon"] }) }),
721
+ /* @__PURE__ */ jsx(
722
+ "div",
723
+ {
724
+ className: styles.scroller,
725
+ tabIndex: -1,
726
+ ref: childrenRef,
727
+ style: {
728
+ position: "relative",
729
+ maxHeight: menuHeight ?? "inherit"
730
+ },
731
+ onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
732
+ role: "menu",
733
+ id: `scroller-${uid.replace(/:/g, "")}`,
734
+ children
735
+ }
736
+ ),
737
+ arrowEnd && /* @__PURE__ */ jsx("div", { className: styles["arrow-down"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropDown, size: "xlarge", className: styles["arrow-icon"] }) })
738
+ ]
739
+ }
740
+ )
741
+ ] });
742
+ };
743
+
744
+ const MenuContext = createContext(null);
745
+ const MenuElement$1 = forwardRef(
746
+ (props, ref) => {
747
+ const {
748
+ children,
749
+ placement = "bottom-start",
750
+ open,
751
+ defaultOpen = false,
752
+ disableAutoHeight,
753
+ label,
754
+ onOutsidePress,
755
+ trigger,
756
+ ...rest
757
+ } = props;
758
+ const uid = useId();
759
+ const [openState, setOpenState] = useState(open ?? defaultOpen);
760
+ const [scrollTop, setScrollTop] = useState(0);
761
+ const [menuHeight, setMenuHeight] = useState(null);
762
+ const [arrowStart, setArrowStart] = useState(false);
763
+ const [arrowEnd, setArrowEnd] = useState(false);
764
+ const invokerRef = useRef(null);
765
+ const menuRef = useRef(null);
766
+ const childrenRef = useRef(null);
767
+ const [focusItems, setFocusItems] = useState();
768
+ const dialogContext = useContext(DialogContext);
769
+ const menuContext = useContext(MenuContext);
770
+ const fallbackArr = useCallback(() => {
771
+ if (placement.startsWith("top")) {
772
+ return disableAutoHeight ? placement : ["top-start", "top-end", "bottom-start", "bottom-end"];
773
+ }
774
+ return disableAutoHeight ? placement : ["bottom-start", "bottom-end", "top-start", "top-end"];
775
+ }, [disableAutoHeight, placement]);
776
+ const updatePosition = useCallback(() => {
777
+ if (!invokerRef.current || !menuRef.current) return;
778
+ computePosition(invokerRef.current, menuRef.current, {
779
+ placement,
780
+ middleware: [
781
+ offset({
782
+ mainAxis: 5,
783
+ alignmentAxis: 0
784
+ }),
785
+ flip({
786
+ fallbackStrategy: "bestFit",
787
+ fallbackPlacements: fallbackArr()
788
+ }),
789
+ shift({
790
+ mainAxis: !menuContext?.disableAutoHeight,
791
+ crossAxis: false,
792
+ limiter: limitShift({
793
+ mainAxis: !menuContext?.disableAutoHeight
794
+ })
795
+ }),
796
+ size({
797
+ padding: 8,
798
+ apply({ availableWidth, availableHeight, elements }) {
799
+ if (disableAutoHeight ?? menuContext?.disableAutoHeight) return;
800
+ setMenuHeight(availableHeight);
801
+ Object.assign(elements.floating.style, {
802
+ maxWidth: `${availableWidth - 16}px`,
803
+ maxHeight: `${availableHeight - 16}px`
804
+ });
805
+ }
806
+ })
807
+ ]
808
+ }).then(({ x, y }) => {
809
+ if (!menuRef.current) return;
810
+ Object.assign(menuRef.current.style, {
811
+ left: `${x}px`,
812
+ top: `${y}px`
813
+ });
814
+ });
815
+ }, [
816
+ placement,
817
+ fallbackArr,
818
+ menuContext?.disableAutoHeight,
819
+ disableAutoHeight
820
+ ]);
821
+ const menuReference = useRef(null);
822
+ useLayoutEffect(() => {
823
+ if (!openState) {
824
+ setMenuHeight(null);
825
+ setScrollTop(0);
826
+ return;
827
+ }
828
+ if (!menuRef.current) return;
829
+ menuReference.current = menuRef.current;
830
+ /* istanbul ignore next -- @preserve */
831
+ const observer = new ResizeObserver((entries) => {
832
+ if (!childrenRef.current || !menuReference.current) return;
833
+ setMenuHeight(menuReference.current.clientHeight);
834
+ const isOverflow = childrenRef.current.scrollHeight > menuReference.current.clientHeight;
835
+ if (!isOverflow) return;
836
+ const showTop = childrenRef.current.scrollTop > 0;
837
+ const showBottom = childrenRef.current.scrollHeight - menuReference.current.clientHeight - scrollTop - 16 > 0;
838
+ setArrowStart(showTop);
839
+ setArrowEnd(showBottom);
840
+ });
841
+ observer.observe(menuReference.current);
842
+ return () => {
843
+ if (menuReference.current) {
844
+ observer.unobserve(menuReference.current);
845
+ }
846
+ observer.disconnect();
847
+ };
848
+ }, [openState, scrollTop]);
849
+ useLayoutEffect(() => {
850
+ if (!menuRef.current || !invokerRef.current) return;
851
+ const cleanup = autoUpdate(invokerRef.current, menuRef.current, () => {
852
+ updatePosition();
853
+ });
854
+ return () => {
855
+ cleanup();
856
+ };
857
+ }, [updatePosition]);
858
+ const openMenu = useCallback(async () => {
859
+ if (!menuRef.current || !childrenRef.current) return;
860
+ menuRef.current.showPopover();
861
+ const focusables = Array.from(
862
+ childrenRef.current.querySelectorAll(
863
+ `#scroller-${uid.replace(/:/g, "")} > button, #scroller-${uid.replace(/:/g, "")} > div[data-nested="true"] > button, #scroller-${uid.replace(/:/g, "")} > a[href]`
864
+ )
865
+ );
866
+ setOpenState(true);
867
+ setFocusItems(focusables);
868
+ dialogContext?.setHasOpenPopover?.(true);
869
+ }, [dialogContext, uid]);
870
+ const closeMenu = useCallback(
871
+ async (fn) => {
872
+ if (!menuRef.current || !openState) return;
873
+ fn?.();
874
+ setOpenState(false);
875
+ menuRef.current.hidePopover();
876
+ dialogContext?.setHasOpenPopover?.(false);
877
+ invokerRef.current?.focus();
878
+ },
879
+ [openState, dialogContext]
880
+ );
881
+ const isControlled = typeof open !== "undefined";
882
+ const initialRender = useRef(true);
883
+ useEffect(() => {
884
+ if (!isControlled) return;
885
+ if (initialRender.current === true) {
886
+ open && menuRef.current && openMenu();
887
+ initialRender.current = false;
888
+ return;
889
+ }
890
+ if (open) {
891
+ openMenu();
892
+ } else {
893
+ closeMenu();
894
+ }
895
+ }, [closeMenu, isControlled, open, openMenu, dialogContext]);
896
+ useEffect(() => {
897
+ if (typeof document === "undefined") return;
898
+ let isClosable = false;
899
+ const onMouseDownHandler = (e) => {
900
+ if (!invokerRef.current || !menuRef.current) return;
901
+ const isInvoker = e.composedPath().includes(invokerRef.current);
902
+ const isPopover = e.composedPath().includes(menuRef.current);
903
+ if (!isInvoker && !isPopover && openState) {
904
+ onOutsidePress?.(e);
905
+ isClosable = true;
906
+ }
907
+ };
908
+ const onMouseUpHandler = (e) => {
909
+ if (!invokerRef.current || !menuRef.current) return;
910
+ const isInvoker = e.composedPath().includes(invokerRef.current);
911
+ const isPopover = e.composedPath().includes(menuRef.current);
912
+ if (!isInvoker && !isPopover && openState) {
913
+ if (isControlled || !isClosable || !openState) return;
914
+ closeMenu();
915
+ }
916
+ };
917
+ document.addEventListener("mousedown", onMouseDownHandler);
918
+ document.addEventListener("mouseup", onMouseUpHandler);
919
+ return () => {
920
+ document.removeEventListener("mousedown", onMouseDownHandler);
921
+ document.removeEventListener("mouseup", onMouseUpHandler);
922
+ };
923
+ }, [isControlled, openState, onOutsidePress, closeMenu]);
924
+ const closeRootMenu = useCallback(() => {
925
+ closeMenu();
926
+ }, [closeMenu]);
927
+ const onKeyDownHandler = (e) => {
928
+ if (!openState || !childrenRef.current || menuContext) return;
929
+ if (e.code === "Escape") {
930
+ e.stopPropagation();
931
+ e.preventDefault();
932
+ closeMenu();
933
+ }
934
+ const currentActiveIndex = focusItems?.findIndex(
935
+ (item) => item.id === document.activeElement?.id
936
+ );
937
+ const firstItem = focusItems?.[0];
938
+ const lastItem = focusItems?.[focusItems.length - 1];
939
+ if (e.code === "ArrowDown") {
940
+ e.stopPropagation();
941
+ e.preventDefault();
942
+ if (currentActiveIndex === (focusItems?.length ?? 0) - 1) {
943
+ firstItem.focus();
944
+ return;
945
+ }
946
+ const nextItem = focusItems?.[(currentActiveIndex ?? 0) + 1];
947
+ nextItem.focus();
948
+ return;
949
+ }
950
+ if (e.code === "ArrowUp") {
951
+ e.stopPropagation();
952
+ e.preventDefault();
953
+ if (currentActiveIndex === 0) {
954
+ lastItem.focus();
955
+ return;
956
+ }
957
+ const prevItem = focusItems?.[(currentActiveIndex ?? 0) - 1];
958
+ prevItem.focus();
959
+ return;
960
+ }
961
+ };
962
+ const value = useMemo(() => {
963
+ return {
964
+ disableAutoHeight,
965
+ closeRootMenu
966
+ };
967
+ }, [disableAutoHeight, closeRootMenu]);
968
+ const MenuButtonOnKeyDownHandler = (e) => {
969
+ if (e.code === "ArrowDown") {
970
+ focusItems?.[0].focus();
971
+ e.stopPropagation();
972
+ e.preventDefault();
973
+ }
974
+ };
975
+ const MenuButtonOnClick = () => {
976
+ if (isControlled) return;
977
+ if (openState) {
978
+ closeMenu();
979
+ return;
980
+ }
981
+ openMenu();
982
+ };
983
+ if (!supportsPopover())
984
+ return /* @__PURE__ */ jsx(MenuLegacyComponent, { ...props, ref });
985
+ if (menuContext) {
986
+ return /* @__PURE__ */ jsx(MenuContext.Provider, { value, children: /* @__PURE__ */ jsx(
987
+ MenuNested,
988
+ {
989
+ open,
990
+ defaultOpen,
991
+ className: props.className,
992
+ icon: props.icon,
993
+ label,
994
+ children
995
+ }
996
+ ) });
997
+ }
998
+ return /* @__PURE__ */ jsxs(MenuContext.Provider, { value, children: [
999
+ trigger ? trigger({
1000
+ ref: invokerRef,
1001
+ onClick: () => MenuButtonOnClick(),
1002
+ "aria-haspopup": true,
1003
+ "aria-controls": `menu-${uid.replace(/:/g, "")}`,
1004
+ "aria-expanded": openState,
1005
+ "data-state": openState ? "open" : "close"
1006
+ }) : /* @__PURE__ */ jsx(
1007
+ Button,
1008
+ {
1009
+ ref: invokerRef,
1010
+ onClick: MenuButtonOnClick,
1011
+ onKeyDown: MenuButtonOnKeyDownHandler,
1012
+ "aria-haspopup": true,
1013
+ "aria-controls": `menu-${uid.replace(/:/g, "")}`,
1014
+ "data-state": openState ? "open" : "close",
1015
+ "aria-expanded": openState,
1016
+ ...rest,
1017
+ children: label
1018
+ }
1019
+ ),
1020
+ /* @__PURE__ */ jsxs(
1021
+ "div",
1022
+ {
1023
+ popover: "manual",
1024
+ id: `menu-${uid.replace(/:/g, "")}`,
1025
+ "data-anv": "menu-content",
1026
+ className: styles.content,
1027
+ onKeyDown: onKeyDownHandler,
1028
+ ref: menuRef,
1029
+ role: "presentation",
1030
+ children: [
1031
+ arrowStart && /* @__PURE__ */ jsx("div", { className: styles["arrow-up"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropUp, size: "xlarge", className: styles["arrow-icon"] }) }),
1032
+ /* @__PURE__ */ jsx(
1033
+ "div",
1034
+ {
1035
+ className: styles.scroller,
1036
+ tabIndex: -1,
1037
+ ref: childrenRef,
1038
+ style: {
1039
+ position: "relative",
1040
+ maxHeight: menuHeight ?? "inherit"
1041
+ },
1042
+ onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
1043
+ role: "menu",
1044
+ id: `scroller-${uid.replace(/:/g, "")}`,
1045
+ children
1046
+ }
1047
+ ),
1048
+ arrowEnd && /* @__PURE__ */ jsx("div", { className: styles["arrow-down"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropDown, size: "xlarge", className: styles["arrow-icon"] }) })
1049
+ ]
1050
+ }
1051
+ )
1052
+ ] });
1053
+ }
1054
+ );
1055
+ MenuElement$1.displayName = "Menu";
1056
+ const Menu$1 = Object.assign(MenuElement$1, {
1057
+ Item: MenuItem$1
1058
+ });
1059
+
1060
+ const MenuElement = (props) => {
1061
+ const data = {
1062
+ value: props.value,
1063
+ ariaLabel: props["aria-label"]
1064
+ };
1065
+ const trackingId = useTrackingId({
1066
+ name: "Menu",
1067
+ data,
1068
+ hasOverride: !!props["data-tracking-id"]
1069
+ });
1070
+ return /* @__PURE__ */ jsx(Menu$1, { "data-tracking-id": trackingId, ...props });
1071
+ };
1072
+ const MenuItem = forwardRef(
1073
+ (props, ref) => {
1074
+ const data = {
1075
+ label: childrenToString(props.label)
1076
+ };
1077
+ const trackingId = useTrackingId({
1078
+ name: "MenuItem",
1079
+ data,
1080
+ hasOverride: !!props["data-tracking-id"]
1081
+ });
1082
+ return /* @__PURE__ */ jsx(MenuItem$1, { ref, "data-tracking-id": trackingId, ...props });
1083
+ }
1084
+ );
1085
+ const Menu = Object.assign(MenuElement, {
1086
+ Item: MenuItem
1087
+ });
1088
+
1089
+ export { Menu as M, MenuItem as a };
1090
+ //# sourceMappingURL=Menu-IEBrkdoN.js.map