@sanity/ui 2.6.4-canary.2 → 2.6.5

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 (37) hide show
  1. package/dist/index.d.mts +6 -42
  2. package/dist/index.d.ts +6 -42
  3. package/dist/index.esm.js +164 -97
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +162 -95
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +164 -97
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +34 -26
  10. package/src/core/components/breadcrumbs/breadcrumbs.tsx +6 -15
  11. package/src/core/components/dialog/dialog.tsx +21 -12
  12. package/src/core/components/menu/menu.tsx +18 -11
  13. package/src/core/components/menu/menuButton.tsx +1 -1
  14. package/src/core/components/menu/menuContext.ts +1 -1
  15. package/src/core/components/menu/useMenuController.ts +17 -11
  16. package/src/core/components/toast/styles.ts +1 -2
  17. package/src/core/components/toast/useToast.ts +0 -1
  18. package/src/core/components/tree/tree.tsx +0 -1
  19. package/src/core/components/tree/treeItem.tsx +0 -1
  20. package/src/core/helpers/focus.ts +0 -1
  21. package/src/core/helpers/scroll.ts +0 -1
  22. package/src/core/hooks/_internal/index.ts +1 -0
  23. package/src/core/hooks/_internal/useUnique.ts +34 -0
  24. package/src/core/hooks/index.ts +2 -3
  25. package/src/core/hooks/useClickOutside.ts +72 -38
  26. package/src/core/hooks/useElementSize.ts +0 -1
  27. package/src/core/hooks/useMediaIndex/useMediaIndex.ts +10 -2
  28. package/src/core/hooks/usePrefersDark.ts +55 -10
  29. package/src/core/hooks/usePrefersReducedMotion.ts +56 -10
  30. package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +7 -9
  31. package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +6 -8
  32. package/src/core/primitives/tooltip/tooltip.tsx +29 -31
  33. package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +0 -1
  34. package/src/core/utils/layer/layerProvider.tsx +0 -1
  35. package/src/core/utils/portal/__workshop__/named.tsx +8 -10
  36. package/src/core/utils/portal/portalProvider.tsx +3 -2
  37. package/src/core/hooks/useMatchMedia.ts +0 -46
package/dist/index.js CHANGED
@@ -126,26 +126,45 @@ function useArrayProp(val, defaultVal) {
126
126
  [__perf_hash__]
127
127
  );
128
128
  }
129
+ function _getElements(element, elementsArg) {
130
+ const ret = [element];
131
+ for (const el of elementsArg)
132
+ Array.isArray(el) ? ret.push(...el) : ret.push(el);
133
+ return ret.filter(Boolean);
134
+ }
129
135
  function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
130
- const eventHandler = useEffectEvent.useEffectEvent((evt) => {
131
- const target = evt.target;
132
- if (!(target instanceof Node) || boundaryElement && !boundaryElement.contains(target))
136
+ const [element, setElement] = react.useState(null), [elements, setElements] = react.useState(() => _getElements(element, elementsArg)), elementsRef = react.useRef(elements);
137
+ return react.useEffect(() => {
138
+ const prevElements = elementsRef.current, nextElements = _getElements(element, elementsArg);
139
+ if (prevElements.length !== nextElements.length) {
140
+ setElements(nextElements), elementsRef.current = nextElements;
133
141
  return;
134
- const elements = (Array.isArray(elementsArg) ? elementsArg : elementsArg()).flat();
135
- for (const el of elements)
136
- if (el && (target === el || el.contains(target)))
142
+ }
143
+ for (const el of prevElements)
144
+ if (!nextElements.includes(el)) {
145
+ setElements(nextElements), elementsRef.current = nextElements;
137
146
  return;
138
- listener(evt);
139
- });
140
- react.useEffect(() => (document.addEventListener("mousedown", eventHandler), document.addEventListener("touchstart", eventHandler), () => {
141
- document.removeEventListener("mousedown", eventHandler), document.removeEventListener("touchstart", eventHandler);
142
- }), [eventHandler]);
143
- }
144
- function useCustomValidity(ref, customValidity) {
145
- react.useEffect(() => {
146
- var _a;
147
- (_a = ref.current) == null || _a.setCustomValidity(customValidity || "");
148
- }, [customValidity, ref]);
147
+ }
148
+ for (const el of nextElements)
149
+ if (!prevElements.includes(el)) {
150
+ setElements(nextElements), elementsRef.current = nextElements;
151
+ return;
152
+ }
153
+ }, [element, elementsArg]), react.useEffect(() => {
154
+ if (!listener) return;
155
+ const handleWindowMouseDown = (evt) => {
156
+ const target = evt.target;
157
+ if (target instanceof Node && !(boundaryElement && !boundaryElement.contains(target))) {
158
+ for (const el of elements)
159
+ if (target === el || el.contains(target))
160
+ return;
161
+ listener(evt);
162
+ }
163
+ };
164
+ return window.addEventListener("mousedown", handleWindowMouseDown), () => {
165
+ window.removeEventListener("mousedown", handleWindowMouseDown);
166
+ };
167
+ }, [boundaryElement, listener, elements]), setElement;
149
168
  }
150
169
  var resizeObservers = [], hasActiveObservations = function() {
151
170
  return resizeObservers.some(function(ro) {
@@ -480,27 +499,9 @@ function useElementRect(element) {
480
499
  const elementSize = useElementSize(element);
481
500
  return (elementSize == null ? void 0 : elementSize._contentRect) || null;
482
501
  }
483
- function useForwardedRef(ref) {
484
- const innerRef = react.useRef(null);
485
- return react.useImperativeHandle(ref, () => innerRef.current), innerRef;
486
- }
487
502
  function useGlobalKeyDown(onKeyDown) {
488
503
  return react.useEffect(() => (addEventListener("keydown", onKeyDown), () => removeEventListener("keydown", onKeyDown)), [onKeyDown]);
489
504
  }
490
- function useMatchMedia(mediaQueryString, getServerSnapshot2) {
491
- const { subscribe: subscribe2, getSnapshot } = react.useMemo(() => {
492
- let MEDIA_QUERY_CACHE;
493
- const getMatchMedia = () => (MEDIA_QUERY_CACHE || (MEDIA_QUERY_CACHE = window.matchMedia(mediaQueryString)), MEDIA_QUERY_CACHE);
494
- return {
495
- subscribe: (onStoreChange) => {
496
- const matchMedia = getMatchMedia();
497
- return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
498
- },
499
- getSnapshot: () => getMatchMedia().matches
500
- };
501
- }, [mediaQueryString]);
502
- return react.useDebugValue(mediaQueryString), react.useSyncExternalStore(subscribe2, getSnapshot, getServerSnapshot2);
503
- }
504
505
  function getGlobalScope() {
505
506
  if (typeof globalThis < "u") return globalThis;
506
507
  if (typeof window < "u") return window;
@@ -543,6 +544,7 @@ function useTheme() {
543
544
  function useTheme_v2() {
544
545
  return theme.getTheme_v2(styledComponents.useTheme());
545
546
  }
547
+ const MEDIA_STORE_CACHE = /* @__PURE__ */ new WeakMap();
546
548
  function _getMediaQuery(media, index) {
547
549
  return index === 0 ? `screen and (max-width: ${media[index] - 1}px)` : index === media.length ? `screen and (min-width: ${media[index - 1]}px)` : `screen and (min-width: ${media[index - 1]}px) and (max-width: ${media[index] - 1}px)`;
548
550
  }
@@ -577,18 +579,57 @@ function _createMediaStore(media) {
577
579
  };
578
580
  } };
579
581
  }
580
- function getServerSnapshot() {
582
+ function getServerSnapshot$2() {
581
583
  return 0;
582
584
  }
583
585
  function useMediaIndex() {
584
- const { media } = useTheme_v2(), store = react.useMemo(() => _createMediaStore(media), [media]);
585
- return react.useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
586
+ const { media } = useTheme_v2();
587
+ let store = MEDIA_STORE_CACHE.get(media);
588
+ return store || (store = _createMediaStore(media), MEDIA_STORE_CACHE.set(media, store)), react.useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot$2);
589
+ }
590
+ let MEDIA_QUERY_CACHE$1;
591
+ function getMatchMedia$1() {
592
+ return MEDIA_QUERY_CACHE$1 || (MEDIA_QUERY_CACHE$1 = window.matchMedia("(prefers-color-scheme: dark)")), MEDIA_QUERY_CACHE$1;
593
+ }
594
+ function subscribe$2(onStoreChange) {
595
+ const matchMedia = getMatchMedia$1();
596
+ return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
597
+ }
598
+ function getSnapshot$1() {
599
+ return getMatchMedia$1().matches;
600
+ }
601
+ function getServerSnapshot$1() {
602
+ return !1;
603
+ }
604
+ function usePrefersDark() {
605
+ return react.useSyncExternalStore(subscribe$2, getSnapshot$1, getServerSnapshot$1);
606
+ }
607
+ let MEDIA_QUERY_CACHE;
608
+ function getMatchMedia() {
609
+ return MEDIA_QUERY_CACHE || (MEDIA_QUERY_CACHE = window.matchMedia("(prefers-reduced-motion: reduce)")), MEDIA_QUERY_CACHE;
610
+ }
611
+ function subscribe$1(onStoreChange) {
612
+ const matchMedia = getMatchMedia();
613
+ return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
614
+ }
615
+ function getSnapshot() {
616
+ return getMatchMedia().matches;
617
+ }
618
+ function getServerSnapshot() {
619
+ return !1;
620
+ }
621
+ function usePrefersReducedMotion() {
622
+ return react.useSyncExternalStore(subscribe$1, getSnapshot, getServerSnapshot);
586
623
  }
587
- function usePrefersDark(getServerSnapshot2 = () => !1) {
588
- return useMatchMedia("(prefers-color-scheme: dark)", getServerSnapshot2);
624
+ function useForwardedRef(ref) {
625
+ const innerRef = react.useRef(null);
626
+ return react.useImperativeHandle(ref, () => innerRef.current), innerRef;
589
627
  }
590
- function usePrefersReducedMotion(getServerSnapshot2 = () => !1) {
591
- return useMatchMedia("(prefers-reduced-motion: reduce)", getServerSnapshot2);
628
+ function useCustomValidity(ref, customValidity) {
629
+ react.useEffect(() => {
630
+ var _a;
631
+ (_a = ref.current) == null || _a.setCustomValidity(customValidity || "");
632
+ }, [customValidity, ref]);
592
633
  }
593
634
  function responsiveBorderStyle() {
594
635
  return [border, borderTop, borderRight, borderBottom, borderLeft];
@@ -3014,6 +3055,16 @@ function Portal(props) {
3014
3055
  const { children, __unstable_name: name } = props, portal = usePortal(), portalElement = (name ? portal.elements && portal.elements[name] : portal.element) || ((_a = portal.elements) == null ? void 0 : _a.default);
3015
3056
  return portalElement ? reactDom.createPortal(children, portalElement) : null;
3016
3057
  }
3058
+ function useUnique(value) {
3059
+ const valueRef = react.useRef(value);
3060
+ return _isEqual(valueRef.current, value) || (valueRef.current = value), valueRef.current;
3061
+ }
3062
+ function _isEqual(objA, objB) {
3063
+ if (!objA || !objB)
3064
+ return objA === objB;
3065
+ const keysA = Object.keys(objA), keysB = Object.keys(objB);
3066
+ return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
3067
+ }
3017
3068
  function useMounted() {
3018
3069
  return react.useSyncExternalStore(
3019
3070
  subscribe,
@@ -3024,7 +3075,7 @@ function useMounted() {
3024
3075
  const subscribe = () => () => {
3025
3076
  };
3026
3077
  function PortalProvider(props) {
3027
- const { boundaryElement, children, element, __unstable_elements: elements } = props, mounted = useMounted(), value = react.useMemo(() => ({
3078
+ const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), mounted = useMounted(), value = react.useMemo(() => ({
3028
3079
  version: 0,
3029
3080
  boundaryElement: boundaryElement || null,
3030
3081
  element: element || mounted ? document.body : null,
@@ -4306,23 +4357,11 @@ const Root$a = styledComponents.styled(Layer)`
4306
4357
  zOffset = layer.tooltip.zOffset,
4307
4358
  delay,
4308
4359
  ...restProps
4309
- } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport";
4360
+ } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport", [tooltipMaxWidth, setTooltipMaxWidth] = react.useState(0);
4310
4361
  react.useImperativeHandle(forwardedRef, () => ref.current);
4311
4362
  const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, middleware = react.useMemo(() => {
4312
4363
  const ret = [];
4313
4364
  return ret.push(
4314
- reactDom$1.size({
4315
- apply({ elements }) {
4316
- const availableWidths = [
4317
- ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4318
- (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
4319
- ], tooltipWidth = Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
4320
- Object.assign(elements.floating.style, {
4321
- maxWidth: tooltipWidth > 0 ? `${tooltipWidth}px` : void 0
4322
- });
4323
- }
4324
- })
4325
- ), ret.push(
4326
4365
  reactDom$1.flip({
4327
4366
  boundary: boundaryElement || void 0,
4328
4367
  fallbackPlacements,
@@ -4336,7 +4375,7 @@ const Root$a = styledComponents.styled(Layer)`
4336
4375
  padding: DEFAULT_TOOLTIP_PADDING
4337
4376
  })
4338
4377
  ), arrowProp && ret.push(reactDom$1.arrow({ element: arrowRef, padding: DEFAULT_TOOLTIP_PADDING })), animate && ret.push(origin), ret;
4339
- }, [animate, arrowProp, boundaryElement, fallbackPlacements, portalElement]), { floatingStyles, placement, middlewareData, refs, update } = reactDom$1.useFloating({
4378
+ }, [animate, arrowProp, boundaryElement, fallbackPlacements]), { floatingStyles, placement, middlewareData, refs, update } = reactDom$1.useFloating({
4340
4379
  middleware,
4341
4380
  placement: placementProp,
4342
4381
  whileElementsMounted: reactDom$1.autoUpdate
@@ -4403,7 +4442,13 @@ const Root$a = styledComponents.styled(Layer)`
4403
4442
  return window.addEventListener("keydown", handleWindowKeyDown), () => {
4404
4443
  window.removeEventListener("keydown", handleWindowKeyDown);
4405
4444
  };
4406
- }, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip });
4445
+ }, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip }), react.useLayoutEffect(() => {
4446
+ const availableWidths = [
4447
+ ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4448
+ (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
4449
+ ];
4450
+ setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
4451
+ }, [boundaryElement, portalElement]);
4407
4452
  const setArrow = react.useCallback(
4408
4453
  (arrowEl) => {
4409
4454
  arrowRef.current = arrowEl, update();
@@ -4444,7 +4489,10 @@ const Root$a = styledComponents.styled(Layer)`
4444
4489
  "data-ui": "Tooltip",
4445
4490
  ...restProps,
4446
4491
  ref: setFloating,
4447
- style: floatingStyles,
4492
+ style: {
4493
+ ...floatingStyles,
4494
+ maxWidth: tooltipMaxWidth > 0 ? `${tooltipMaxWidth}px` : void 0
4495
+ },
4448
4496
  zOffset,
4449
4497
  children: /* @__PURE__ */ jsxRuntime.jsx(
4450
4498
  TooltipCard,
@@ -4492,13 +4540,16 @@ function useCloseOnMouseLeave({
4492
4540
  referenceElement,
4493
4541
  showTooltip
4494
4542
  }) {
4495
- const handleWindowMouseMove = useEffectEvent.useEffectEvent((event) => {
4496
- referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || handleIsOpenChange(!1));
4543
+ const onMouseMove = useEffectEvent.useEffectEvent((target) => {
4544
+ referenceElement && (referenceElement === target || target instanceof Node && referenceElement.contains(target) || handleIsOpenChange(!1));
4497
4545
  });
4498
4546
  react.useEffect(() => {
4499
- if (showTooltip)
4500
- return window.addEventListener("mousemove", handleWindowMouseMove), () => window.removeEventListener("mousemove", handleWindowMouseMove);
4501
- }, [handleWindowMouseMove, showTooltip]);
4547
+ if (!showTooltip) return;
4548
+ const handleMouseMove = (event) => {
4549
+ onMouseMove(event.target);
4550
+ };
4551
+ return window.addEventListener("mousemove", handleMouseMove), () => window.removeEventListener("mousemove", handleMouseMove);
4552
+ }, [onMouseMove, showTooltip]);
4502
4553
  }
4503
4554
  const Root$9 = styledComponents.styled.div`
4504
4555
  line-height: 0;
@@ -4911,8 +4962,8 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4911
4962
  appearance: none;
4912
4963
  margin: -4px;
4913
4964
  `, Breadcrumbs = react.forwardRef(function(props, ref) {
4914
- const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = react.useState(!1), expandElementRef = react.useRef(null), popoverElementRef = react.useRef(null), collapse = react.useCallback(() => setOpen(!1), []), expand = react.useCallback(() => setOpen(!0), []);
4915
- useClickOutside(collapse, () => [expandElementRef.current, popoverElementRef.current]);
4965
+ const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = react.useState(!1), [expandElement, setExpandElement] = react.useState(null), [popoverElement, setPopoverElement] = react.useState(null), collapse = react.useCallback(() => setOpen(!1), []), expand = react.useCallback(() => setOpen(!0), []);
4966
+ useClickOutside(collapse, [expandElement, popoverElement]);
4916
4967
  const rawItems = react.useMemo(() => react.Children.toArray(children).filter(react.isValidElement), [children]), items = react.useMemo(() => {
4917
4968
  const len = rawItems.length;
4918
4969
  if (maxLength && len > maxLength) {
@@ -4927,7 +4978,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4927
4978
  open,
4928
4979
  placement: "top",
4929
4980
  portal: !0,
4930
- ref: popoverElementRef,
4981
+ ref: setPopoverElement,
4931
4982
  children: /* @__PURE__ */ jsxRuntime.jsx(
4932
4983
  ExpandButton,
4933
4984
  {
@@ -4935,7 +4986,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4935
4986
  mode: "bleed",
4936
4987
  onClick: open ? collapse : expand,
4937
4988
  padding: 1,
4938
- ref: expandElementRef,
4989
+ ref: setExpandElement,
4939
4990
  selected: open,
4940
4991
  text: "\u2026"
4941
4992
  }
@@ -5060,8 +5111,8 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5060
5111
  scheme,
5061
5112
  shadow: shadowProp,
5062
5113
  width: widthProp
5063
- } = props, portal = usePortal(), portalElement = portalProp ? ((_a = portal.elements) == null ? void 0 : _a[portalProp]) || null : portal.element, boundaryElement = useBoundaryElement().element, radius = useArrayProp(radiusProp), shadow = useArrayProp(shadowProp), width = useArrayProp(widthProp), ref = react.useRef(null), contentRef = react.useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
5064
- return react.useImperativeHandle(forwardedRef, () => ref.current), react.useImperativeHandle(
5114
+ } = props, portal = usePortal(), portalElement = portalProp ? ((_a = portal.elements) == null ? void 0 : _a[portalProp]) || null : portal.element, boundaryElement = useBoundaryElement().element, radius = useArrayProp(radiusProp), shadow = useArrayProp(shadowProp), width = useArrayProp(widthProp), ref = react.useRef(null), [rootElement, setRootElement] = react.useState(null), contentRef = react.useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
5115
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useImperativeHandle(
5065
5116
  forwardedContentRef,
5066
5117
  () => contentRef.current
5067
5118
  ), react.useEffect(() => {
@@ -5076,13 +5127,20 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5076
5127
  [boundaryElement, isTopLayer, onClose, portalElement]
5077
5128
  )
5078
5129
  ), useClickOutside(
5079
- (event) => {
5080
- if (!isTopLayer || !onClickOutside) return;
5081
- const target = event.target;
5082
- target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
5083
- },
5084
- () => [ref.current]
5085
- ), /* @__PURE__ */ jsxRuntime.jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsxRuntime.jsx(DialogCardRoot, { radius, ref, scheme, shadow, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogLayout, { direction: "column", children: [
5130
+ react.useCallback(
5131
+ (event) => {
5132
+ if (!isTopLayer || !onClickOutside) return;
5133
+ const target = event.target;
5134
+ target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
5135
+ },
5136
+ [boundaryElement, isTopLayer, onClickOutside, portalElement]
5137
+ ),
5138
+ [rootElement]
5139
+ );
5140
+ const setRef = react.useCallback((el) => {
5141
+ setRootElement(el), ref.current = el;
5142
+ }, []);
5143
+ return /* @__PURE__ */ jsxRuntime.jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsxRuntime.jsx(DialogCardRoot, { radius, ref: setRef, scheme, shadow, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogLayout, { direction: "column", children: [
5086
5144
  showHeader && /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(Flex, { align: "center", padding: 3, children: [
5087
5145
  /* @__PURE__ */ jsxRuntime.jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsxRuntime.jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
5088
5146
  showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -5260,13 +5318,13 @@ function _sortElements(rootElement, elements) {
5260
5318
  elements.sort(_sort);
5261
5319
  }
5262
5320
  function useMenuController(props) {
5263
- const { onKeyDown, originElement, shouldFocus, rootElementRef } = props, elementsRef = react.useRef([]), [activeIndex, _setActiveIndex] = react.useState(-1), activeIndexRef = react.useRef(activeIndex), activeElement = react.useMemo(() => elementsRef.current[activeIndex] || null, [activeIndex]), mounted = !!rootElementRef.current, setActiveIndex = react.useCallback((nextActiveIndex) => {
5321
+ const { onKeyDown, originElement, shouldFocus } = props, elementsRef = react.useRef([]), [rootElement, setRootElement] = react.useState(null), [activeIndex, _setActiveIndex] = react.useState(-1), activeIndexRef = react.useRef(activeIndex), activeElement = elementsRef.current[activeIndex] || null, mounted = !!rootElement, setActiveIndex = react.useCallback((nextActiveIndex) => {
5264
5322
  _setActiveIndex(nextActiveIndex), activeIndexRef.current = nextActiveIndex;
5265
5323
  }, []), mount = react.useCallback(
5266
5324
  (element, selected) => {
5267
5325
  if (!element) return () => {
5268
5326
  };
5269
- if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(rootElementRef.current, elementsRef.current)), selected) {
5327
+ if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(rootElement, elementsRef.current)), selected) {
5270
5328
  const selectedIndex = elementsRef.current.indexOf(element);
5271
5329
  setActiveIndex(selectedIndex);
5272
5330
  }
@@ -5275,7 +5333,7 @@ function useMenuController(props) {
5275
5333
  idx > -1 && elementsRef.current.splice(idx, 1);
5276
5334
  };
5277
5335
  },
5278
- [rootElementRef, setActiveIndex]
5336
+ [rootElement, setActiveIndex]
5279
5337
  ), handleKeyDown = react.useCallback(
5280
5338
  (event) => {
5281
5339
  if (event.key === "Tab") {
@@ -5330,13 +5388,13 @@ function useMenuController(props) {
5330
5388
  },
5331
5389
  [setActiveIndex]
5332
5390
  ), handleItemMouseLeave = react.useCallback(() => {
5333
- var _a;
5334
- setActiveIndex(-2), (_a = rootElementRef.current) == null || _a.focus();
5335
- }, [rootElementRef, setActiveIndex]);
5391
+ setActiveIndex(-2), rootElement == null || rootElement.focus();
5392
+ }, [setActiveIndex, rootElement]);
5336
5393
  return react.useEffect(() => {
5337
5394
  if (!mounted) return;
5338
5395
  const rafId = window.requestAnimationFrame(() => {
5339
- if (activeIndex === -1) {
5396
+ const _activeIndex = activeIndexRef.current;
5397
+ if (_activeIndex === -1) {
5340
5398
  if (shouldFocus === "first") {
5341
5399
  const el = _getFocusableElements(elementsRef.current)[0];
5342
5400
  if (el) {
@@ -5353,7 +5411,7 @@ function useMenuController(props) {
5353
5411
  }
5354
5412
  return;
5355
5413
  }
5356
- const element = elementsRef.current[activeIndex] || null;
5414
+ const element = elementsRef.current[_activeIndex] || null;
5357
5415
  element == null || element.focus();
5358
5416
  });
5359
5417
  return () => {
@@ -5365,7 +5423,9 @@ function useMenuController(props) {
5365
5423
  handleItemMouseEnter,
5366
5424
  handleItemMouseLeave,
5367
5425
  handleKeyDown,
5368
- mount
5426
+ mount,
5427
+ rootElement,
5428
+ setRootElement
5369
5429
  };
5370
5430
  }
5371
5431
  const Root$5 = styledComponents.styled(Box)`
@@ -5397,18 +5457,23 @@ const Root$5 = styledComponents.styled(Box)`
5397
5457
  handleItemMouseEnter,
5398
5458
  handleItemMouseLeave,
5399
5459
  handleKeyDown,
5400
- mount
5401
- } = useMenuController({ onKeyDown, originElement, shouldFocus, rootElementRef: ref }), handleRefChange = react.useCallback(
5460
+ mount,
5461
+ rootElement,
5462
+ setRootElement
5463
+ } = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = react.useCallback(
5402
5464
  (el) => {
5403
- ref.current = el, ref.current && registerElement && registerElement(ref.current);
5465
+ setRootElement(el), ref.current = el;
5404
5466
  },
5405
- [registerElement]
5467
+ [setRootElement]
5406
5468
  );
5407
5469
  react.useEffect(() => {
5408
5470
  onItemSelect && onItemSelect(activeIndex);
5409
5471
  }, [activeIndex, onItemSelect]), useClickOutside(
5410
- (event) => isTopLayer && onClickOutside && onClickOutside(event),
5411
- () => [ref.current]
5472
+ react.useCallback(
5473
+ (event) => isTopLayer && onClickOutside && onClickOutside(event),
5474
+ [isTopLayer, onClickOutside]
5475
+ ),
5476
+ [rootElement]
5412
5477
  ), useGlobalKeyDown(
5413
5478
  react.useCallback(
5414
5479
  (event) => {
@@ -5416,7 +5481,10 @@ const Root$5 = styledComponents.styled(Box)`
5416
5481
  },
5417
5482
  [isTopLayer, onEscape]
5418
5483
  )
5419
- );
5484
+ ), react.useEffect(() => {
5485
+ if (!(!rootElement || !registerElement))
5486
+ return registerElement(rootElement);
5487
+ }, [registerElement, rootElement]);
5420
5488
  const value = react.useMemo(
5421
5489
  () => ({
5422
5490
  version: 0,
@@ -6092,7 +6160,7 @@ const CustomInline = styledComponents.styled(Inline)`
6092
6160
  }
6093
6161
  100% {
6094
6162
  width: 100%;
6095
- }
6163
+ }
6096
6164
  `, LOADING_BAR_HEIGHT = 2;
6097
6165
  function rootStyles(props) {
6098
6166
  const { color } = getTheme_v2.getTheme_v2(props.theme), loadingBarColor = color.button.default[props.tone].enabled.bg;
@@ -6789,7 +6857,6 @@ exports.useElementSize = useElementSize;
6789
6857
  exports.useForwardedRef = useForwardedRef;
6790
6858
  exports.useGlobalKeyDown = useGlobalKeyDown;
6791
6859
  exports.useLayer = useLayer;
6792
- exports.useMatchMedia = useMatchMedia;
6793
6860
  exports.useMediaIndex = useMediaIndex;
6794
6861
  exports.usePortal = usePortal;
6795
6862
  exports.usePrefersDark = usePrefersDark;