@servicetitan/anvil2 1.27.2 → 1.29.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 (108) hide show
  1. package/CHANGELOG.md +76 -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-DCrEfyl2.js} +2209 -228
  6. package/dist/Combobox-DCrEfyl2.js.map +1 -0
  7. package/dist/Combobox.css +443 -69
  8. package/dist/Combobox.js +1 -1
  9. package/dist/DateField-4jR9NvbC.js +1109 -0
  10. package/dist/DateField-4jR9NvbC.js.map +1 -0
  11. package/dist/DateField.js +1 -1
  12. package/dist/{Dialog-DQ9QXB5D.js → Dialog-CL3bfZuB.js} +2 -2
  13. package/dist/{Dialog-DQ9QXB5D.js.map → Dialog-CL3bfZuB.js.map} +1 -1
  14. package/dist/{Dialog-Kh2tcVWz-DqcNnouf.js → Dialog-CYBt_JdP-CmF0MUHL.js} +80 -51
  15. package/dist/Dialog-CYBt_JdP-CmF0MUHL.js.map +1 -0
  16. package/dist/Dialog.js +1 -1
  17. package/dist/Drawer-8nHrKktU.js +66 -0
  18. package/dist/Drawer-8nHrKktU.js.map +1 -0
  19. package/dist/{Drawer-C6fpnRDX.js → Drawer-UQlX-LQG-BSCnMRad.js} +97 -130
  20. package/dist/Drawer-UQlX-LQG-BSCnMRad.js.map +1 -0
  21. package/dist/{Drawer.css → Drawer-UQlX-LQG.css} +26 -25
  22. package/dist/Drawer.js +1 -1
  23. package/dist/{AnvilProvider-DNJk1Ait.js → HammerProvider-DuxhW0gv-C2voN5ro.js} +26 -15
  24. package/dist/HammerProvider-DuxhW0gv-C2voN5ro.js.map +1 -0
  25. package/dist/InputMask-B8N8PP1W-DlUKpMR4.js +323 -0
  26. package/dist/InputMask-B8N8PP1W-DlUKpMR4.js.map +1 -0
  27. package/dist/{InputMask-Ceh574pv.js → InputMask-jsL7rSOk.js} +2 -2
  28. package/dist/{InputMask-Ceh574pv.js.map → InputMask-jsL7rSOk.js.map} +1 -1
  29. package/dist/InputMask.js +1 -1
  30. package/dist/{Label-DWF2pXeG-1BhzVgZG.js → Label-CUVr-jvI-BXhER5eQ.js} +3 -3
  31. package/dist/{Label-DWF2pXeG-1BhzVgZG.js.map → Label-CUVr-jvI-BXhER5eQ.js.map} +1 -1
  32. package/dist/Menu-CsfX8-_z.js +1091 -0
  33. package/dist/Menu-CsfX8-_z.js.map +1 -0
  34. package/dist/Menu.css +116 -1
  35. package/dist/Menu.js +1 -1
  36. package/dist/{Page-BGkLs3bR.js → Page-vKi5JkDS.js} +70 -54
  37. package/dist/Page-vKi5JkDS.js.map +1 -0
  38. package/dist/Page.css +103 -70
  39. package/dist/Page.js +1 -1
  40. package/dist/{Popover-DzEc_Muv.js → Popover-OFlyW8gN.js} +2 -2
  41. package/dist/{Popover-DzEc_Muv.js.map → Popover-OFlyW8gN.js.map} +1 -1
  42. package/dist/{Popover-QKZtjN4_-CETYlWwq.js → Popover-tu_N1aS6-CSLR1Xzc.js} +351 -12
  43. package/dist/Popover-tu_N1aS6-CSLR1Xzc.js.map +1 -0
  44. package/dist/{Popover-QKZtjN4_.css → Popover-tu_N1aS6.css} +53 -1
  45. package/dist/Popover.js +1 -1
  46. package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js → ProgressBar-DQ1lsFk2-Ci4eqzM0.js} +3 -3
  47. package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js.map → ProgressBar-DQ1lsFk2-Ci4eqzM0.js.map} +1 -1
  48. package/dist/{ProgressBar-IItIByYc.js → ProgressBar-gVRLaKPz.js} +2 -2
  49. package/dist/{ProgressBar-IItIByYc.js.map → ProgressBar-gVRLaKPz.js.map} +1 -1
  50. package/dist/ProgressBar.js +1 -1
  51. package/dist/{SearchField-CWb0kaV8.js → SearchField-C-4icPUa.js} +2 -2
  52. package/dist/{SearchField-CWb0kaV8.js.map → SearchField-C-4icPUa.js.map} +1 -1
  53. package/dist/SearchField.js +1 -1
  54. package/dist/{TextField-D53XNiCi-C6_A5VRq.js → TextField-B8LHWOoC-DSV9zY-z.js} +2 -2
  55. package/dist/{TextField-D53XNiCi-C6_A5VRq.js.map → TextField-B8LHWOoC-DSV9zY-z.js.map} +1 -1
  56. package/dist/{TextField-s92xHzb3.js → TextField-DgxJO1a7.js} +2 -2
  57. package/dist/{TextField-s92xHzb3.js.map → TextField-DgxJO1a7.js.map} +1 -1
  58. package/dist/TextField.js +1 -1
  59. package/dist/{Textarea-B61wNIFr.js → Textarea-B-Dv2RXs.js} +2 -2
  60. package/dist/{Textarea-B61wNIFr.js.map → Textarea-B-Dv2RXs.js.map} +1 -1
  61. package/dist/Textarea.js +1 -1
  62. package/dist/Toast.js +1 -1
  63. package/dist/{Toolbar-Cge6Nznj.js → Toolbar-7BeCY61H.js} +2 -2
  64. package/dist/{Toolbar-Cge6Nznj.js.map → Toolbar-7BeCY61H.js.map} +1 -1
  65. package/dist/Toolbar.js +1 -1
  66. package/dist/{Tooltip-89FIvMG0.js → Tooltip-BVBq-KxK.js} +2 -2
  67. package/dist/{Tooltip-89FIvMG0.js.map → Tooltip-BVBq-KxK.js.map} +1 -1
  68. package/dist/{Tooltip-DgM8NSPm-CRIQbuTm.js → Tooltip-C8sCGmKM-CLrDofvy.js} +222 -22
  69. package/dist/Tooltip-C8sCGmKM-CLrDofvy.js.map +1 -0
  70. package/dist/{Tooltip-DgM8NSPm.css → Tooltip-C8sCGmKM.css} +43 -1
  71. package/dist/Tooltip.js +1 -1
  72. package/dist/components/Dialog/Dialog.d.ts +1 -0
  73. package/dist/components/Drawer/Drawer.d.ts +1 -0
  74. package/dist/components/Page/Page.d.ts +4 -1
  75. package/dist/floating-ui.react-4AwURJA3.js +5989 -0
  76. package/dist/floating-ui.react-4AwURJA3.js.map +1 -0
  77. package/dist/{useKeyboardFocusables-CwVMAe5C-CIHqixNA.js → index.esm-CunAFnrh.js} +11 -59
  78. package/dist/index.esm-CunAFnrh.js.map +1 -0
  79. package/dist/index.js +16 -16
  80. package/dist/supportsPopover-8aJR37cf-8aJR37cf.js +6 -0
  81. package/dist/supportsPopover-8aJR37cf-8aJR37cf.js.map +1 -0
  82. package/dist/{toast-CHld8RKY.js → toast-CbokOkfo.js} +6 -2
  83. package/dist/toast-CbokOkfo.js.map +1 -0
  84. package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js +61 -0
  85. package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js.map +1 -0
  86. package/package.json +3 -3
  87. package/dist/AnvilProvider-DNJk1Ait.js.map +0 -1
  88. package/dist/Combobox-DnTI2I3L.js.map +0 -1
  89. package/dist/DateField-DocC46Mw.js +0 -565
  90. package/dist/DateField-DocC46Mw.js.map +0 -1
  91. package/dist/Dialog-Kh2tcVWz-DqcNnouf.js.map +0 -1
  92. package/dist/Drawer-C6fpnRDX.js.map +0 -1
  93. package/dist/InputMask-DQXw5qvG-BH4P-Woc.js +0 -195
  94. package/dist/InputMask-DQXw5qvG-BH4P-Woc.js.map +0 -1
  95. package/dist/Menu-D8SDm9s9.js +0 -706
  96. package/dist/Menu-D8SDm9s9.js.map +0 -1
  97. package/dist/Page-BGkLs3bR.js.map +0 -1
  98. package/dist/Popover-QKZtjN4_-CETYlWwq.js.map +0 -1
  99. package/dist/Tooltip-DgM8NSPm-CRIQbuTm.js.map +0 -1
  100. package/dist/floating-ui.react-P5949bpO.js +0 -28
  101. package/dist/floating-ui.react-P5949bpO.js.map +0 -1
  102. package/dist/floating-ui.react-dom-D912oS4K.js +0 -1841
  103. package/dist/floating-ui.react-dom-D912oS4K.js.map +0 -1
  104. package/dist/toast-CHld8RKY.js.map +0 -1
  105. package/dist/useKeyboardFocusables-CwVMAe5C-CIHqixNA.js.map +0 -1
  106. /package/dist/{Dialog-Kh2tcVWz.css → Dialog-CYBt_JdP.css} +0 -0
  107. /package/dist/{Label-DWF2pXeG.css → Label-CUVr-jvI.css} +0 -0
  108. /package/dist/{ProgressBar-cKtBso7j.css → ProgressBar-DQ1lsFk2.css} +0 -0
@@ -0,0 +1,1091 @@
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-CYBt_JdP-CmF0MUHL.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-UQlX-LQG-BSCnMRad.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
+ root,
757
+ ...rest
758
+ } = props;
759
+ const uid = useId();
760
+ const [openState, setOpenState] = useState(open ?? defaultOpen);
761
+ const [scrollTop, setScrollTop] = useState(0);
762
+ const [menuHeight, setMenuHeight] = useState(null);
763
+ const [arrowStart, setArrowStart] = useState(false);
764
+ const [arrowEnd, setArrowEnd] = useState(false);
765
+ const invokerRef = useRef(null);
766
+ const menuRef = useRef(null);
767
+ const childrenRef = useRef(null);
768
+ const [focusItems, setFocusItems] = useState();
769
+ const dialogContext = useContext(DialogContext);
770
+ const menuContext = useContext(MenuContext);
771
+ const fallbackArr = useCallback(() => {
772
+ if (placement.startsWith("top")) {
773
+ return disableAutoHeight ? placement : ["top-start", "top-end", "bottom-start", "bottom-end"];
774
+ }
775
+ return disableAutoHeight ? placement : ["bottom-start", "bottom-end", "top-start", "top-end"];
776
+ }, [disableAutoHeight, placement]);
777
+ const updatePosition = useCallback(() => {
778
+ if (!invokerRef.current || !menuRef.current) return;
779
+ computePosition(invokerRef.current, menuRef.current, {
780
+ placement,
781
+ middleware: [
782
+ offset({
783
+ mainAxis: 5,
784
+ alignmentAxis: 0
785
+ }),
786
+ flip({
787
+ fallbackStrategy: "bestFit",
788
+ fallbackPlacements: fallbackArr()
789
+ }),
790
+ shift({
791
+ mainAxis: !menuContext?.disableAutoHeight,
792
+ crossAxis: false,
793
+ limiter: limitShift({
794
+ mainAxis: !menuContext?.disableAutoHeight
795
+ })
796
+ }),
797
+ size({
798
+ padding: 8,
799
+ apply({ availableWidth, availableHeight, elements }) {
800
+ if (disableAutoHeight ?? menuContext?.disableAutoHeight) return;
801
+ setMenuHeight(availableHeight);
802
+ Object.assign(elements.floating.style, {
803
+ maxWidth: `${availableWidth - 16}px`,
804
+ maxHeight: `${availableHeight - 16}px`
805
+ });
806
+ }
807
+ })
808
+ ]
809
+ }).then(({ x, y }) => {
810
+ if (!menuRef.current) return;
811
+ Object.assign(menuRef.current.style, {
812
+ left: `${x}px`,
813
+ top: `${y}px`
814
+ });
815
+ });
816
+ }, [
817
+ placement,
818
+ fallbackArr,
819
+ menuContext?.disableAutoHeight,
820
+ disableAutoHeight
821
+ ]);
822
+ const menuReference = useRef(null);
823
+ useLayoutEffect(() => {
824
+ if (!openState) {
825
+ setMenuHeight(null);
826
+ setScrollTop(0);
827
+ return;
828
+ }
829
+ if (!menuRef.current) return;
830
+ menuReference.current = menuRef.current;
831
+ /* istanbul ignore next -- @preserve */
832
+ const observer = new ResizeObserver((entries) => {
833
+ if (!childrenRef.current || !menuReference.current) return;
834
+ setMenuHeight(menuReference.current.clientHeight);
835
+ const isOverflow = childrenRef.current.scrollHeight > menuReference.current.clientHeight;
836
+ if (!isOverflow) return;
837
+ const showTop = childrenRef.current.scrollTop > 0;
838
+ const showBottom = childrenRef.current.scrollHeight - menuReference.current.clientHeight - scrollTop - 16 > 0;
839
+ setArrowStart(showTop);
840
+ setArrowEnd(showBottom);
841
+ });
842
+ observer.observe(menuReference.current);
843
+ return () => {
844
+ if (menuReference.current) {
845
+ observer.unobserve(menuReference.current);
846
+ }
847
+ observer.disconnect();
848
+ };
849
+ }, [openState, scrollTop]);
850
+ useLayoutEffect(() => {
851
+ if (!menuRef.current || !invokerRef.current) return;
852
+ const cleanup = autoUpdate(invokerRef.current, menuRef.current, () => {
853
+ updatePosition();
854
+ });
855
+ return () => {
856
+ cleanup();
857
+ };
858
+ }, [updatePosition]);
859
+ const openMenu = useCallback(async () => {
860
+ if (!menuRef.current || !childrenRef.current) return;
861
+ menuRef.current.showPopover();
862
+ const focusables = Array.from(
863
+ childrenRef.current.querySelectorAll(
864
+ `#scroller-${uid.replace(/:/g, "")} > button, #scroller-${uid.replace(/:/g, "")} > div[data-nested="true"] > button, #scroller-${uid.replace(/:/g, "")} > a[href]`
865
+ )
866
+ );
867
+ setOpenState(true);
868
+ setFocusItems(focusables);
869
+ dialogContext?.setHasOpenPopover?.(true);
870
+ }, [dialogContext, uid]);
871
+ const closeMenu = useCallback(
872
+ async (fn) => {
873
+ if (!menuRef.current || !openState) return;
874
+ fn?.();
875
+ setOpenState(false);
876
+ menuRef.current.hidePopover();
877
+ dialogContext?.setHasOpenPopover?.(false);
878
+ invokerRef.current?.focus();
879
+ },
880
+ [openState, dialogContext]
881
+ );
882
+ const isControlled = typeof open !== "undefined";
883
+ const initialRender = useRef(true);
884
+ useEffect(() => {
885
+ if (!isControlled) return;
886
+ if (initialRender.current === true) {
887
+ open && menuRef.current && openMenu();
888
+ initialRender.current = false;
889
+ return;
890
+ }
891
+ if (open) {
892
+ openMenu();
893
+ } else {
894
+ closeMenu();
895
+ }
896
+ }, [closeMenu, isControlled, open, openMenu, dialogContext]);
897
+ useEffect(() => {
898
+ if (typeof document === "undefined") return;
899
+ let isClosable = false;
900
+ const onMouseDownHandler = (e) => {
901
+ if (!invokerRef.current || !menuRef.current) return;
902
+ const isInvoker = e.composedPath().includes(invokerRef.current);
903
+ const isPopover = e.composedPath().includes(menuRef.current);
904
+ if (!isInvoker && !isPopover && openState) {
905
+ onOutsidePress?.(e);
906
+ isClosable = true;
907
+ }
908
+ };
909
+ const onMouseUpHandler = (e) => {
910
+ if (!invokerRef.current || !menuRef.current) return;
911
+ const isInvoker = e.composedPath().includes(invokerRef.current);
912
+ const isPopover = e.composedPath().includes(menuRef.current);
913
+ if (!isInvoker && !isPopover && openState) {
914
+ if (isControlled || !isClosable || !openState) return;
915
+ closeMenu();
916
+ }
917
+ };
918
+ document.addEventListener("mousedown", onMouseDownHandler);
919
+ document.addEventListener("mouseup", onMouseUpHandler);
920
+ return () => {
921
+ document.removeEventListener("mousedown", onMouseDownHandler);
922
+ document.removeEventListener("mouseup", onMouseUpHandler);
923
+ };
924
+ }, [isControlled, openState, onOutsidePress, closeMenu]);
925
+ const closeRootMenu = useCallback(() => {
926
+ closeMenu();
927
+ }, [closeMenu]);
928
+ const onKeyDownHandler = (e) => {
929
+ if (!openState || !childrenRef.current || menuContext) return;
930
+ if (e.code === "Escape") {
931
+ e.stopPropagation();
932
+ e.preventDefault();
933
+ closeMenu();
934
+ }
935
+ const currentActiveIndex = focusItems?.findIndex(
936
+ (item) => item.id === document.activeElement?.id
937
+ );
938
+ const firstItem = focusItems?.[0];
939
+ const lastItem = focusItems?.[focusItems.length - 1];
940
+ if (e.code === "ArrowDown") {
941
+ e.stopPropagation();
942
+ e.preventDefault();
943
+ if (currentActiveIndex === (focusItems?.length ?? 0) - 1) {
944
+ firstItem.focus();
945
+ return;
946
+ }
947
+ const nextItem = focusItems?.[(currentActiveIndex ?? 0) + 1];
948
+ nextItem.focus();
949
+ return;
950
+ }
951
+ if (e.code === "ArrowUp") {
952
+ e.stopPropagation();
953
+ e.preventDefault();
954
+ if (currentActiveIndex === 0) {
955
+ lastItem.focus();
956
+ return;
957
+ }
958
+ const prevItem = focusItems?.[(currentActiveIndex ?? 0) - 1];
959
+ prevItem.focus();
960
+ return;
961
+ }
962
+ };
963
+ const value = useMemo(() => {
964
+ return {
965
+ disableAutoHeight,
966
+ closeRootMenu
967
+ };
968
+ }, [disableAutoHeight, closeRootMenu]);
969
+ const MenuButtonOnKeyDownHandler = (e) => {
970
+ if (e.code === "ArrowDown") {
971
+ focusItems?.[0].focus();
972
+ e.stopPropagation();
973
+ e.preventDefault();
974
+ }
975
+ };
976
+ const MenuButtonOnClick = () => {
977
+ if (isControlled) return;
978
+ if (openState) {
979
+ closeMenu();
980
+ return;
981
+ }
982
+ openMenu();
983
+ };
984
+ if (!supportsPopover())
985
+ return /* @__PURE__ */ jsx(MenuLegacyComponent, { ...props, ref });
986
+ if (menuContext) {
987
+ return /* @__PURE__ */ jsx(MenuContext.Provider, { value, children: /* @__PURE__ */ jsx(
988
+ MenuNested,
989
+ {
990
+ open,
991
+ defaultOpen,
992
+ className: props.className,
993
+ icon: props.icon,
994
+ label,
995
+ children
996
+ }
997
+ ) });
998
+ }
999
+ return /* @__PURE__ */ jsxs(MenuContext.Provider, { value, children: [
1000
+ trigger ? trigger({
1001
+ ref: invokerRef,
1002
+ onClick: () => MenuButtonOnClick(),
1003
+ "aria-haspopup": true,
1004
+ "aria-controls": `menu-${uid.replace(/:/g, "")}`,
1005
+ "aria-expanded": openState,
1006
+ "data-state": openState ? "open" : "close"
1007
+ }) : /* @__PURE__ */ jsx(
1008
+ Button,
1009
+ {
1010
+ ref: invokerRef,
1011
+ onClick: MenuButtonOnClick,
1012
+ onKeyDown: MenuButtonOnKeyDownHandler,
1013
+ "aria-haspopup": true,
1014
+ "aria-controls": `menu-${uid.replace(/:/g, "")}`,
1015
+ "data-state": openState ? "open" : "close",
1016
+ "aria-expanded": openState,
1017
+ ...rest,
1018
+ children: label
1019
+ }
1020
+ ),
1021
+ /* @__PURE__ */ jsxs(
1022
+ "div",
1023
+ {
1024
+ popover: "manual",
1025
+ id: `menu-${uid.replace(/:/g, "")}`,
1026
+ "data-anv": "menu-content",
1027
+ className: styles.content,
1028
+ onKeyDown: onKeyDownHandler,
1029
+ ref: menuRef,
1030
+ role: "presentation",
1031
+ children: [
1032
+ arrowStart && /* @__PURE__ */ jsx("div", { className: styles["arrow-up"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropUp, size: "xlarge", className: styles["arrow-icon"] }) }),
1033
+ /* @__PURE__ */ jsx(
1034
+ "div",
1035
+ {
1036
+ className: styles.scroller,
1037
+ tabIndex: -1,
1038
+ ref: childrenRef,
1039
+ style: {
1040
+ position: "relative",
1041
+ maxHeight: menuHeight ?? "inherit"
1042
+ },
1043
+ onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
1044
+ role: "menu",
1045
+ id: `scroller-${uid.replace(/:/g, "")}`,
1046
+ children
1047
+ }
1048
+ ),
1049
+ arrowEnd && /* @__PURE__ */ jsx("div", { className: styles["arrow-down"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropDown, size: "xlarge", className: styles["arrow-icon"] }) })
1050
+ ]
1051
+ }
1052
+ )
1053
+ ] });
1054
+ }
1055
+ );
1056
+ MenuElement$1.displayName = "Menu";
1057
+ const Menu$1 = Object.assign(MenuElement$1, {
1058
+ Item: MenuItem$1
1059
+ });
1060
+
1061
+ const MenuElement = (props) => {
1062
+ const data = {
1063
+ value: props.value,
1064
+ ariaLabel: props["aria-label"]
1065
+ };
1066
+ const trackingId = useTrackingId({
1067
+ name: "Menu",
1068
+ data,
1069
+ hasOverride: !!props["data-tracking-id"]
1070
+ });
1071
+ return /* @__PURE__ */ jsx(Menu$1, { "data-tracking-id": trackingId, ...props });
1072
+ };
1073
+ const MenuItem = forwardRef(
1074
+ (props, ref) => {
1075
+ const data = {
1076
+ label: childrenToString(props.label)
1077
+ };
1078
+ const trackingId = useTrackingId({
1079
+ name: "MenuItem",
1080
+ data,
1081
+ hasOverride: !!props["data-tracking-id"]
1082
+ });
1083
+ return /* @__PURE__ */ jsx(MenuItem$1, { ref, "data-tracking-id": trackingId, ...props });
1084
+ }
1085
+ );
1086
+ const Menu = Object.assign(MenuElement, {
1087
+ Item: MenuItem
1088
+ });
1089
+
1090
+ export { Menu as M, MenuItem as a };
1091
+ //# sourceMappingURL=Menu-CsfX8-_z.js.map