@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
@@ -1,706 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import * as React from 'react';
3
- import { forwardRef, useContext, useId, useRef, useState, createContext, useCallback, useLayoutEffect, useEffect, useMemo } 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-Kh2tcVWz-DqcNnouf.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 { u as useMergeRefs } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
12
- import { c as computePosition, o as offset, f as flip, s as shift, l as limitShift, d as size, a as autoUpdate } from './floating-ui.react-dom-D912oS4K.js';
13
-
14
- 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" }));
15
-
16
- 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" }));
17
-
18
- const item = "_item_hid8p_3";
19
- const content = "_content_hid8p_16";
20
- const scroller = "_scroller_hid8p_46";
21
- const disabled = "_disabled_hid8p_124";
22
- const styles = {
23
- item: item,
24
- content: content,
25
- scroller: scroller,
26
- "arrow-down": "_arrow-down_hid8p_62",
27
- "arrow-up": "_arrow-up_hid8p_63",
28
- "arrow-icon": "_arrow-icon_hid8p_75",
29
- "no-padding": "_no-padding_hid8p_117",
30
- disabled: disabled
31
- };
32
-
33
- const MenuItem$1 = forwardRef(
34
- ({
35
- label,
36
- disabled,
37
- icon,
38
- className,
39
- onClick,
40
- onMouseEnter,
41
- id: idProp,
42
- ...props
43
- }, ref) => {
44
- const menuContext = useContext(MenuContext);
45
- const uid = useId();
46
- const buttonRef = useRef(null);
47
- const combinedRef = useMergeRefs([buttonRef, ref]);
48
- const [tabIndex, setTabIndex] = useState(-1);
49
- const itemCx = cx([styles["item"]], className);
50
- const onClickHandler = (e) => {
51
- if (disabled) {
52
- e.preventDefault();
53
- e.stopPropagation();
54
- return;
55
- }
56
- onClick?.(e);
57
- menuContext?.closeRootMenu();
58
- };
59
- const onMouseEnterHandler = (e) => {
60
- onMouseEnter?.(e);
61
- buttonRef.current?.focus();
62
- };
63
- const onFocusHandler = () => {
64
- setTabIndex(0);
65
- };
66
- const onBlurHandler = () => {
67
- setTabIndex(-1);
68
- };
69
- return /* @__PURE__ */ jsxs(
70
- "button",
71
- {
72
- ...props,
73
- ref: combinedRef,
74
- type: "button",
75
- role: "menuitem",
76
- "data-anv": "menu-item",
77
- id: idProp ?? `menuitem-${uid.replace(/:/g, "")}`,
78
- className: itemCx,
79
- tabIndex,
80
- "aria-disabled": disabled,
81
- onClick: onClickHandler,
82
- onMouseEnter: onMouseEnterHandler,
83
- onFocus: onFocusHandler,
84
- onBlur: onBlurHandler,
85
- children: [
86
- icon ? /* @__PURE__ */ jsx(Icon, { inherit: true, "aria-hidden": true, svg: icon }) : null,
87
- label
88
- ]
89
- }
90
- );
91
- }
92
- );
93
- MenuItem$1.displayName = "MenuItem";
94
-
95
- const MenuNested = (props) => {
96
- const { children, open, defaultOpen = false, label, className, icon } = props;
97
- const uid = useId();
98
- const [tabIndex, setTabIndex] = useState(-1);
99
- const [openState, setOpenState] = useState(open ?? defaultOpen);
100
- const [scrollTop, setScrollTop] = useState(0);
101
- const [menuHeight, setMenuHeight] = useState(null);
102
- const [arrowStart, setArrowStart] = useState(false);
103
- const [arrowEnd, setArrowEnd] = useState(false);
104
- const invokerRef = useRef(null);
105
- const menuRef = useRef(null);
106
- const childrenRef = useRef(null);
107
- const containerRef = useRef(null);
108
- const [focusItems, setFocusItems] = useState();
109
- const menuContext = useContext(MenuContext);
110
- const fallbackArr = useCallback(() => {
111
- return menuContext?.disableAutoHeight ? ["right-start"] : ["right-start", "right-end", "left-start", "left-end"];
112
- }, [menuContext?.disableAutoHeight]);
113
- const updatePosition = useCallback(() => {
114
- if (!invokerRef.current || !menuRef.current) return;
115
- computePosition(invokerRef.current, menuRef.current, {
116
- placement: "right-start",
117
- middleware: [
118
- offset({
119
- mainAxis: 0,
120
- alignmentAxis: -4
121
- }),
122
- flip({
123
- fallbackStrategy: "bestFit",
124
- fallbackPlacements: fallbackArr()
125
- }),
126
- shift({
127
- mainAxis: !menuContext?.disableAutoHeight,
128
- crossAxis: false,
129
- limiter: limitShift({
130
- mainAxis: !menuContext?.disableAutoHeight
131
- })
132
- }),
133
- size({
134
- padding: 8,
135
- apply({ availableWidth, availableHeight, elements }) {
136
- if (menuContext?.disableAutoHeight) return;
137
- setMenuHeight(availableHeight);
138
- Object.assign(elements.floating.style, {
139
- maxWidth: `${availableWidth - 16}px`,
140
- maxHeight: `${availableHeight - 16}px`
141
- });
142
- }
143
- })
144
- ]
145
- }).then(({ x, y }) => {
146
- if (!menuRef.current) return;
147
- Object.assign(menuRef.current.style, {
148
- left: `${x}px`,
149
- top: `${y + 8}px`
150
- });
151
- });
152
- }, [fallbackArr, menuContext?.disableAutoHeight]);
153
- const menuReference = useRef(null);
154
- useLayoutEffect(() => {
155
- if (!openState) {
156
- setMenuHeight(null);
157
- setScrollTop(0);
158
- return;
159
- }
160
- if (!menuRef.current) return;
161
- menuReference.current = menuRef.current;
162
- const observer = new ResizeObserver((entries) => {
163
- /* istanbul ignore next -- @preserve */
164
- setTimeout(() => {
165
- if (!childrenRef.current || !menuReference.current) return;
166
- setMenuHeight(menuReference.current.clientHeight);
167
- const isOverflow = childrenRef.current.scrollHeight > menuReference.current.clientHeight;
168
- if (!isOverflow) return;
169
- const showTop = childrenRef.current.scrollTop > 0;
170
- const showBottom = childrenRef.current.scrollHeight - menuReference.current.clientHeight - scrollTop - 16 > 0;
171
- setArrowStart(showTop);
172
- setArrowEnd(showBottom);
173
- }, 100);
174
- });
175
- if (menuReference.current) {
176
- observer.observe(menuReference.current);
177
- }
178
- return () => {
179
- if (menuReference.current) {
180
- observer.unobserve(menuReference.current);
181
- }
182
- observer.disconnect();
183
- };
184
- }, [openState, scrollTop]);
185
- useLayoutEffect(() => {
186
- if (!menuRef.current || !invokerRef.current) return;
187
- const cleanup = autoUpdate(invokerRef.current, menuRef.current, () => {
188
- updatePosition();
189
- });
190
- return () => {
191
- cleanup();
192
- };
193
- }, [updatePosition]);
194
- const popoverHoverTriggered = useRef();
195
- const openMenu = useCallback(async () => {
196
- popoverHoverTriggered.current = true;
197
- await new Promise((resolve) => setTimeout(resolve, 100));
198
- if (!popoverHoverTriggered.current || !menuRef.current || !childrenRef.current)
199
- return;
200
- menuRef.current.showPopover();
201
- setOpenState(true);
202
- const focusables = Array.from(
203
- childrenRef.current.querySelectorAll(
204
- `#scroller-${uid.replace(/:/g, "")} > button, #scroller-${uid.replace(/:/g, "")} > div[data-nested="true"] > button, #scroller-${uid.replace(/:/g, "")} > a[href]`
205
- )
206
- );
207
- setFocusItems(focusables);
208
- }, [uid]);
209
- const closeMenu = useCallback(async (fn) => {
210
- popoverHoverTriggered.current = false;
211
- await new Promise((resolve) => setTimeout(resolve, 100));
212
- if (popoverHoverTriggered.current || !menuRef.current) return;
213
- fn?.();
214
- menuRef.current.hidePopover();
215
- setOpenState(false);
216
- }, []);
217
- const isControlled = typeof open !== "undefined";
218
- const initialRender = useRef(true);
219
- useEffect(() => {
220
- if (!isControlled) return;
221
- if (initialRender.current === true) {
222
- open && menuRef.current && openMenu();
223
- initialRender.current = false;
224
- return;
225
- }
226
- setOpenState(open);
227
- open ? openMenu() : closeMenu();
228
- }, [closeMenu, isControlled, open, openMenu]);
229
- useEffect(() => {
230
- if (!containerRef.current) return;
231
- const nestedContainer = containerRef.current;
232
- nestedContainer.addEventListener("focusin", (e) => {
233
- openMenu();
234
- });
235
- nestedContainer.addEventListener("focusout", () => closeMenu());
236
- return () => {
237
- nestedContainer.removeEventListener("focusin", () => openMenu());
238
- nestedContainer.removeEventListener("focusout", () => closeMenu());
239
- };
240
- }, [closeMenu, openMenu]);
241
- const onKeyDownHandler = (e) => {
242
- if (!openState || !childrenRef.current) return;
243
- const currentActiveIndex = focusItems?.findIndex(
244
- (item) => item.id === document.activeElement?.id
245
- );
246
- const firstItem = focusItems?.[0];
247
- const lastItem = focusItems?.[focusItems.length - 1];
248
- if (e.code === "Escape") {
249
- menuContext?.closeRootMenu();
250
- }
251
- if (e.code === "ArrowLeft") {
252
- e.stopPropagation();
253
- e.preventDefault();
254
- invokerRef.current?.focus();
255
- closeMenu();
256
- }
257
- if (e.code === "ArrowDown") {
258
- e.stopPropagation();
259
- if (currentActiveIndex === (focusItems?.length ?? 0) - 1) {
260
- firstItem.focus();
261
- return;
262
- }
263
- const nextItem = focusItems?.[(currentActiveIndex ?? 0) + 1];
264
- nextItem.focus();
265
- return;
266
- }
267
- if (e.code === "ArrowUp") {
268
- e.stopPropagation();
269
- e.preventDefault();
270
- if (currentActiveIndex === 0) {
271
- lastItem.focus();
272
- return;
273
- }
274
- const prevItem = focusItems?.[(currentActiveIndex ?? 0) - 1];
275
- prevItem.focus();
276
- return;
277
- }
278
- };
279
- const onFocusHandler = () => {
280
- setTabIndex(0);
281
- };
282
- const onBlurHandler = () => {
283
- setTabIndex(-1);
284
- };
285
- const MenuButtonOnKeyDownHandler = (e) => {
286
- if (e.code === "ArrowRight") {
287
- e.stopPropagation();
288
- e.preventDefault();
289
- openMenu();
290
- const firstItem = menuRef.current?.querySelectorAll(
291
- `#scroller-${uid.replace(/:/g, "")} > button, #scroller-${uid.replace(/:/g, "")} > a[href]`
292
- )[0];
293
- firstItem.focus();
294
- }
295
- };
296
- const MenuButtonOnClick = () => {
297
- if (isControlled) return;
298
- openMenu();
299
- };
300
- const itemCx = cx([styles["item"]], className);
301
- return /* @__PURE__ */ jsxs("div", { ref: containerRef, "data-nested": "true", children: [
302
- /* @__PURE__ */ jsxs(
303
- "button",
304
- {
305
- role: "menuitem",
306
- "data-anv": "menu-item",
307
- "data-state": openState ? "open" : "close",
308
- ref: invokerRef,
309
- id: `menuitem-${uid.replace(/:/g, "")}`,
310
- "aria-expanded": openState,
311
- onMouseEnter: (e) => {
312
- e.currentTarget.focus();
313
- },
314
- onKeyDown: MenuButtonOnKeyDownHandler,
315
- onFocus: onFocusHandler,
316
- onBlur: onBlurHandler,
317
- onClick: MenuButtonOnClick,
318
- "aria-haspopup": true,
319
- "aria-controls": `menu-${uid.replace(/:/g, "")}`,
320
- className: itemCx,
321
- tabIndex,
322
- children: [
323
- icon ? /* @__PURE__ */ jsx(Icon, { inherit: true, "aria-hidden": true, svg: icon }) : null,
324
- label,
325
- /* @__PURE__ */ jsx("div", { style: { flexGrow: 1 } }),
326
- /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, svg: SvgNavigateNext })
327
- ]
328
- }
329
- ),
330
- /* @__PURE__ */ jsxs(
331
- "div",
332
- {
333
- popover: "auto",
334
- id: `menu-${uid.replace(/:/g, "")}`,
335
- "data-anv": "menu-content",
336
- className: styles.content,
337
- ref: menuRef,
338
- role: "presentation",
339
- onKeyDown: onKeyDownHandler,
340
- children: [
341
- arrowStart && /* @__PURE__ */ jsx("div", { className: styles["arrow-up"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropUp, size: "xlarge", className: styles["arrow-icon"] }) }),
342
- /* @__PURE__ */ jsx(
343
- "div",
344
- {
345
- className: styles.scroller,
346
- tabIndex: -1,
347
- ref: childrenRef,
348
- style: {
349
- position: "relative",
350
- maxHeight: menuHeight ?? "inherit"
351
- },
352
- onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
353
- role: "menu",
354
- id: `scroller-${uid.replace(/:/g, "")}`,
355
- children
356
- }
357
- ),
358
- arrowEnd && /* @__PURE__ */ jsx("div", { className: styles["arrow-down"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropDown, size: "xlarge", className: styles["arrow-icon"] }) })
359
- ]
360
- }
361
- )
362
- ] });
363
- };
364
-
365
- const MenuContext = createContext(null);
366
- const MenuElement$1 = (props) => {
367
- const {
368
- children,
369
- placement = "bottom-start",
370
- open,
371
- defaultOpen = false,
372
- disableAutoHeight,
373
- label,
374
- onOutsidePress,
375
- trigger,
376
- ...rest
377
- } = props;
378
- const uid = useId();
379
- const [openState, setOpenState] = useState(open ?? defaultOpen);
380
- const [scrollTop, setScrollTop] = useState(0);
381
- const [menuHeight, setMenuHeight] = useState(null);
382
- const [arrowStart, setArrowStart] = useState(false);
383
- const [arrowEnd, setArrowEnd] = useState(false);
384
- const invokerRef = useRef(null);
385
- const menuRef = useRef(null);
386
- const childrenRef = useRef(null);
387
- const [focusItems, setFocusItems] = useState();
388
- const dialogContext = useContext(DialogContext);
389
- const menuContext = useContext(MenuContext);
390
- const fallbackArr = useCallback(() => {
391
- if (placement.startsWith("top")) {
392
- return disableAutoHeight ? placement : ["top-start", "top-end", "bottom-start", "bottom-end"];
393
- }
394
- return disableAutoHeight ? placement : ["bottom-start", "bottom-end", "top-start", "top-end"];
395
- }, [disableAutoHeight, placement]);
396
- const updatePosition = useCallback(() => {
397
- if (!invokerRef.current || !menuRef.current) return;
398
- computePosition(invokerRef.current, menuRef.current, {
399
- placement,
400
- middleware: [
401
- offset({
402
- mainAxis: 5,
403
- alignmentAxis: 0
404
- }),
405
- flip({
406
- fallbackStrategy: "bestFit",
407
- fallbackPlacements: fallbackArr()
408
- }),
409
- shift({
410
- mainAxis: !menuContext?.disableAutoHeight,
411
- crossAxis: false,
412
- limiter: limitShift({
413
- mainAxis: !menuContext?.disableAutoHeight
414
- })
415
- }),
416
- size({
417
- padding: 8,
418
- apply({ availableWidth, availableHeight, elements }) {
419
- if (disableAutoHeight ?? menuContext?.disableAutoHeight) return;
420
- setMenuHeight(availableHeight);
421
- Object.assign(elements.floating.style, {
422
- maxWidth: `${availableWidth - 16}px`,
423
- maxHeight: `${availableHeight - 16}px`
424
- });
425
- }
426
- })
427
- ]
428
- }).then(({ x, y }) => {
429
- if (!menuRef.current) return;
430
- Object.assign(menuRef.current.style, {
431
- left: `${x}px`,
432
- top: `${y}px`
433
- });
434
- });
435
- }, [
436
- placement,
437
- fallbackArr,
438
- menuContext?.disableAutoHeight,
439
- disableAutoHeight
440
- ]);
441
- const menuReference = useRef(null);
442
- useLayoutEffect(() => {
443
- if (!openState) {
444
- setMenuHeight(null);
445
- setScrollTop(0);
446
- return;
447
- }
448
- if (!menuRef.current) return;
449
- menuReference.current = menuRef.current;
450
- /* istanbul ignore next -- @preserve */
451
- const observer = new ResizeObserver((entries) => {
452
- if (!childrenRef.current || !menuReference.current) return;
453
- setMenuHeight(menuReference.current.clientHeight);
454
- const isOverflow = childrenRef.current.scrollHeight > menuReference.current.clientHeight;
455
- if (!isOverflow) return;
456
- const showTop = childrenRef.current.scrollTop > 0;
457
- const showBottom = childrenRef.current.scrollHeight - menuReference.current.clientHeight - scrollTop - 16 > 0;
458
- setArrowStart(showTop);
459
- setArrowEnd(showBottom);
460
- });
461
- observer.observe(menuReference.current);
462
- return () => {
463
- if (menuReference.current) {
464
- observer.unobserve(menuReference.current);
465
- }
466
- observer.disconnect();
467
- };
468
- }, [openState, scrollTop]);
469
- useLayoutEffect(() => {
470
- if (!menuRef.current || !invokerRef.current) return;
471
- const cleanup = autoUpdate(invokerRef.current, menuRef.current, () => {
472
- updatePosition();
473
- });
474
- return () => {
475
- cleanup();
476
- };
477
- }, [updatePosition]);
478
- const openMenu = useCallback(async () => {
479
- if (!menuRef.current || !childrenRef.current) return;
480
- menuRef.current.showPopover();
481
- const focusables = Array.from(
482
- childrenRef.current.querySelectorAll(
483
- `#scroller-${uid.replace(/:/g, "")} > button, #scroller-${uid.replace(/:/g, "")} > div[data-nested="true"] > button, #scroller-${uid.replace(/:/g, "")} > a[href]`
484
- )
485
- );
486
- setOpenState(true);
487
- setFocusItems(focusables);
488
- dialogContext?.setHasOpenPopover?.(true);
489
- }, [dialogContext, uid]);
490
- const closeMenu = useCallback(
491
- async (fn) => {
492
- if (!menuRef.current || !openState) return;
493
- fn?.();
494
- setOpenState(false);
495
- menuRef.current.hidePopover();
496
- dialogContext?.setHasOpenPopover?.(false);
497
- invokerRef.current?.focus();
498
- },
499
- [openState, dialogContext]
500
- );
501
- const isControlled = typeof open !== "undefined";
502
- const initialRender = useRef(true);
503
- useEffect(() => {
504
- if (!isControlled) return;
505
- if (initialRender.current === true) {
506
- open && menuRef.current && openMenu();
507
- initialRender.current = false;
508
- return;
509
- }
510
- if (open) {
511
- openMenu();
512
- } else {
513
- closeMenu();
514
- }
515
- }, [closeMenu, isControlled, open, openMenu, dialogContext]);
516
- useEffect(() => {
517
- if (typeof document === "undefined") return;
518
- let isClosable = false;
519
- const onMouseDownHandler = (e) => {
520
- if (!invokerRef.current || !menuRef.current) return;
521
- const isInvoker = e.composedPath().includes(invokerRef.current);
522
- const isPopover = e.composedPath().includes(menuRef.current);
523
- if (!isInvoker && !isPopover && openState) {
524
- onOutsidePress?.(e);
525
- isClosable = true;
526
- }
527
- };
528
- const onMouseUpHandler = (e) => {
529
- if (!invokerRef.current || !menuRef.current) return;
530
- const isInvoker = e.composedPath().includes(invokerRef.current);
531
- const isPopover = e.composedPath().includes(menuRef.current);
532
- if (!isInvoker && !isPopover && openState) {
533
- if (isControlled || !isClosable || !openState) return;
534
- closeMenu();
535
- }
536
- };
537
- document.addEventListener("mousedown", onMouseDownHandler);
538
- document.addEventListener("mouseup", onMouseUpHandler);
539
- return () => {
540
- document.removeEventListener("mousedown", onMouseDownHandler);
541
- document.removeEventListener("mouseup", onMouseUpHandler);
542
- };
543
- }, [isControlled, openState, onOutsidePress, closeMenu]);
544
- const closeRootMenu = useCallback(() => {
545
- closeMenu();
546
- }, [closeMenu]);
547
- const onKeyDownHandler = (e) => {
548
- if (!openState || !childrenRef.current || menuContext) return;
549
- if (e.code === "Escape") {
550
- e.stopPropagation();
551
- e.preventDefault();
552
- closeMenu();
553
- }
554
- const currentActiveIndex = focusItems?.findIndex(
555
- (item) => item.id === document.activeElement?.id
556
- );
557
- const firstItem = focusItems?.[0];
558
- const lastItem = focusItems?.[focusItems.length - 1];
559
- if (e.code === "ArrowDown") {
560
- e.stopPropagation();
561
- e.preventDefault();
562
- if (currentActiveIndex === (focusItems?.length ?? 0) - 1) {
563
- firstItem.focus();
564
- return;
565
- }
566
- const nextItem = focusItems?.[(currentActiveIndex ?? 0) + 1];
567
- nextItem.focus();
568
- return;
569
- }
570
- if (e.code === "ArrowUp") {
571
- e.stopPropagation();
572
- e.preventDefault();
573
- if (currentActiveIndex === 0) {
574
- lastItem.focus();
575
- return;
576
- }
577
- const prevItem = focusItems?.[(currentActiveIndex ?? 0) - 1];
578
- prevItem.focus();
579
- return;
580
- }
581
- };
582
- const value = useMemo(() => {
583
- return {
584
- disableAutoHeight,
585
- closeRootMenu
586
- };
587
- }, [disableAutoHeight, closeRootMenu]);
588
- const MenuButtonOnKeyDownHandler = (e) => {
589
- if (e.code === "ArrowDown") {
590
- focusItems?.[0].focus();
591
- e.stopPropagation();
592
- e.preventDefault();
593
- }
594
- };
595
- const MenuButtonOnClick = () => {
596
- if (isControlled) return;
597
- if (openState) {
598
- closeMenu();
599
- return;
600
- }
601
- openMenu();
602
- };
603
- if (menuContext) {
604
- return /* @__PURE__ */ jsx(MenuContext.Provider, { value, children: /* @__PURE__ */ jsx(
605
- MenuNested,
606
- {
607
- open,
608
- defaultOpen,
609
- className: props.className,
610
- icon: props.icon,
611
- label,
612
- children
613
- }
614
- ) });
615
- }
616
- return /* @__PURE__ */ jsxs(MenuContext.Provider, { value, children: [
617
- trigger ? trigger({
618
- ref: invokerRef,
619
- onClick: () => MenuButtonOnClick(),
620
- "aria-haspopup": true,
621
- "aria-controls": `menu-${uid.replace(/:/g, "")}`,
622
- "aria-expanded": openState,
623
- "data-state": openState ? "open" : "close"
624
- }) : /* @__PURE__ */ jsx(
625
- Button,
626
- {
627
- ref: invokerRef,
628
- onClick: MenuButtonOnClick,
629
- onKeyDown: MenuButtonOnKeyDownHandler,
630
- "aria-haspopup": true,
631
- "aria-controls": `menu-${uid.replace(/:/g, "")}`,
632
- "data-state": openState ? "open" : "close",
633
- "aria-expanded": openState,
634
- ...rest,
635
- children: label
636
- }
637
- ),
638
- /* @__PURE__ */ jsxs(
639
- "div",
640
- {
641
- popover: "manual",
642
- id: `menu-${uid.replace(/:/g, "")}`,
643
- "data-anv": "menu-content",
644
- className: styles.content,
645
- onKeyDown: onKeyDownHandler,
646
- ref: menuRef,
647
- role: "presentation",
648
- children: [
649
- arrowStart && /* @__PURE__ */ jsx("div", { className: styles["arrow-up"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropUp, size: "xlarge", className: styles["arrow-icon"] }) }),
650
- /* @__PURE__ */ jsx(
651
- "div",
652
- {
653
- className: styles.scroller,
654
- tabIndex: -1,
655
- ref: childrenRef,
656
- style: {
657
- position: "relative",
658
- maxHeight: menuHeight ?? "inherit"
659
- },
660
- onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
661
- role: "menu",
662
- id: `scroller-${uid.replace(/:/g, "")}`,
663
- children
664
- }
665
- ),
666
- arrowEnd && /* @__PURE__ */ jsx("div", { className: styles["arrow-down"], "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { svg: SvgArrowDropDown, size: "xlarge", className: styles["arrow-icon"] }) })
667
- ]
668
- }
669
- )
670
- ] });
671
- };
672
- const Menu$1 = Object.assign(MenuElement$1, {
673
- Item: MenuItem$1
674
- });
675
-
676
- const MenuElement = (props) => {
677
- const data = {
678
- value: props.value,
679
- ariaLabel: props["aria-label"]
680
- };
681
- const trackingId = useTrackingId({
682
- name: "Menu",
683
- data,
684
- hasOverride: !!props["data-tracking-id"]
685
- });
686
- return /* @__PURE__ */ jsx(Menu$1, { "data-tracking-id": trackingId, ...props });
687
- };
688
- const MenuItem = forwardRef(
689
- (props, ref) => {
690
- const data = {
691
- label: childrenToString(props.label)
692
- };
693
- const trackingId = useTrackingId({
694
- name: "MenuItem",
695
- data,
696
- hasOverride: !!props["data-tracking-id"]
697
- });
698
- return /* @__PURE__ */ jsx(MenuItem$1, { ref, "data-tracking-id": trackingId, ...props });
699
- }
700
- );
701
- const Menu = Object.assign(MenuElement, {
702
- Item: MenuItem
703
- });
704
-
705
- export { Menu as M, MenuItem as a };
706
- //# sourceMappingURL=Menu-D8SDm9s9.js.map