@sanity/ui 4.0.0-static.34 → 4.0.0-static.35

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.
package/dist/index.d.ts CHANGED
@@ -41,7 +41,7 @@ import type {Radius} from '@sanity/ui/theme'
41
41
  import {RadiusStyleProps} from '@sanity/ui/css'
42
42
  import {ReactElement} from 'react'
43
43
  import {ReactNode} from 'react'
44
- import type {ReactPortal} from 'react'
44
+ import {ReactPortal} from 'react'
45
45
  import {Ref} from 'react'
46
46
  import {RefAttributes} from 'react'
47
47
  import {ResponsiveProp} from '@sanity/ui/css'
@@ -359,10 +359,7 @@ export declare interface BaseAutocompleteOption {
359
359
  }
360
360
 
361
361
  /** @public */
362
- export declare interface BoundaryElementContextValue {
363
- version: 0.0
364
- element: HTMLElement | null
365
- }
362
+ export declare type BoundaryElementContextValue = HTMLElement | null
366
363
 
367
364
  /** @public */
368
365
  export declare function BoundaryElementProvider(
@@ -2364,7 +2361,10 @@ export declare interface TreeState {
2364
2361
  }
2365
2362
 
2366
2363
  /** @public */
2367
- export declare function useBoundaryElement(): BoundaryElementContextValue
2364
+ export declare function useBoundaryElement(): {
2365
+ version: 0.0
2366
+ element: BoundaryElementContextValue
2367
+ }
2368
2368
 
2369
2369
  /** @public */
2370
2370
  export declare function useCard(): CardContextValue
package/dist/index.js CHANGED
@@ -487,16 +487,7 @@ function createGlobalScopedContext(key2, defaultValue) {
487
487
  const symbolMap = globalScope;
488
488
  return symbolMap[symbol] = symbolMap[symbol] || createContext(defaultValue), symbolMap[symbol];
489
489
  }
490
- const BoundaryElementContext = createGlobalScopedContext("@sanity/ui/v4/boundaryElement", null), DEFAULT_VALUE = {
491
- version: 0,
492
- element: null
493
- };
494
- function useBoundaryElement() {
495
- const value = use(BoundaryElementContext);
496
- if (value && (!isRecord(value) || value.version !== 0))
497
- throw new Error("useBoundaryElement(): the context value is not compatible");
498
- return value || DEFAULT_VALUE;
499
- }
490
+ const BoundaryElementContext = createGlobalScopedContext("@sanity/ui/v4/boundaryElement", null);
500
491
  function getElementRef(element) {
501
492
  let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get, mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
502
493
  return mayWarn ? element.ref : (getter = Object.getOwnPropertyDescriptor(element, "ref")?.get, mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning, mayWarn ? element.props.ref : element.props.ref || element.ref);
@@ -520,9 +511,13 @@ function CardProvider(props) {
520
511
  }
521
512
  function useCard() {
522
513
  const card2 = use(CardContext);
514
+ return assertCardContext(card2), card2;
515
+ }
516
+ function assertCardContext(card2) {
523
517
  if (!card2)
524
- throw new Error("useCard(): missing context value");
525
- return card2;
518
+ throw new Error("useCard(): missing context value", {
519
+ cause: card2
520
+ });
526
521
  }
527
522
  const key = "@sanity/ui/v4/portal", elementKey = Symbol.for(`${key}/element`), elementMap = globalScope;
528
523
  elementMap[elementKey] = null;
@@ -535,19 +530,23 @@ const defaultContextValue = {
535
530
  }, PortalContext = createGlobalScopedContext(key, defaultContextValue);
536
531
  function usePortal() {
537
532
  const value = use(PortalContext);
533
+ return assertPortalContext(value), value;
534
+ }
535
+ function assertPortalContext(value) {
538
536
  if (!value)
539
537
  throw new Error("usePortal(): missing context value");
540
538
  if (!isRecord(value) || value.version !== 0)
541
539
  throw new Error("usePortal(): the context value is not compatible");
542
- return value;
543
540
  }
544
541
  function Portal(props) {
545
542
  const $ = c(6), {
546
543
  children,
547
544
  __unstable_name: name
548
- } = props, card2 = useCard(), portal = usePortal(), portalElement = (name ? portal.elements && portal.elements[name] : portal.element) || portal.elements?.default;
545
+ } = props, portal = usePortal(), portalElement = (name ? portal.elements && portal.elements[name] : portal.element) || portal.elements?.default;
549
546
  if (!portalElement)
550
547
  return null;
548
+ const card2 = use(CardContext);
549
+ assertCardContext(card2);
551
550
  let t0;
552
551
  $[0] !== card2.scheme || $[1] !== children ? (t0 = /* @__PURE__ */ jsx(CardProvider, { tone: "transparent", scheme: card2.scheme, children }), $[0] = card2.scheme, $[1] = children, $[2] = t0) : t0 = $[2];
553
552
  let t1;
@@ -1036,7 +1035,7 @@ function ViewportOverlay() {
1036
1035
  } }), $[0] = zIndex, $[1] = t0) : t0 = $[1], t0;
1037
1036
  }
1038
1037
  function Popover(props) {
1039
- const $ = c(113), boundaryElementContext = useBoundaryElement(), t0 = props;
1038
+ const $ = c(113), t0 = props;
1040
1039
  let _fallbackPlacements, _floatingBoundary, _referenceBoundary, childProp, className, content2, disabled, forwardedRef, matchReferenceWidth, modal, open, padding, portal, referenceElement, rest, scheme, t1, t10, t11, t12, t13, t14, t2, t3, t4, t5, t6, t7, t8, t9, updateRef;
1041
1040
  if ($[0] !== t0) {
1042
1041
  const {
@@ -1058,7 +1057,7 @@ function Popover(props) {
1058
1057
  overflow: t292,
1059
1058
  padding: t302,
1060
1059
  placement: t312,
1061
- placementStrategy: t322,
1060
+ placementStrategy: t32,
1062
1061
  portal: t33,
1063
1062
  preventOverflow: t34,
1064
1063
  radius: t35,
@@ -1073,10 +1072,10 @@ function Popover(props) {
1073
1072
  updateRef: t44,
1074
1073
  ...t45
1075
1074
  } = t0;
1076
- t1 = t152, t2 = t162, t3 = t172, t4 = t182, childProp = t192, className = t202, t5 = t212, content2 = t222, disabled = t232, _fallbackPlacements = t242, matchReferenceWidth = t252, _floatingBoundary = t262, modal = t272, open = t282, t6 = t292, padding = t302, t7 = t312, t8 = t322, portal = t33, t9 = t34, t10 = t35, forwardedRef = t36, _referenceBoundary = t37, referenceElement = t38, scheme = t39, t11 = t40, t12 = t41, t13 = t42, t14 = t43, updateRef = t44, rest = t45, $[0] = t0, $[1] = _fallbackPlacements, $[2] = _floatingBoundary, $[3] = _referenceBoundary, $[4] = childProp, $[5] = className, $[6] = content2, $[7] = disabled, $[8] = forwardedRef, $[9] = matchReferenceWidth, $[10] = modal, $[11] = open, $[12] = padding, $[13] = portal, $[14] = referenceElement, $[15] = rest, $[16] = scheme, $[17] = t1, $[18] = t10, $[19] = t11, $[20] = t12, $[21] = t13, $[22] = t14, $[23] = t2, $[24] = t3, $[25] = t4, $[26] = t5, $[27] = t6, $[28] = t7, $[29] = t8, $[30] = t9, $[31] = updateRef;
1075
+ t1 = t152, t2 = t162, t3 = t172, t4 = t182, childProp = t192, className = t202, t5 = t212, content2 = t222, disabled = t232, _fallbackPlacements = t242, matchReferenceWidth = t252, _floatingBoundary = t262, modal = t272, open = t282, t6 = t292, padding = t302, t7 = t312, t8 = t32, portal = t33, t9 = t34, t10 = t35, forwardedRef = t36, _referenceBoundary = t37, referenceElement = t38, scheme = t39, t11 = t40, t12 = t41, t13 = t42, t14 = t43, updateRef = t44, rest = t45, $[0] = t0, $[1] = _fallbackPlacements, $[2] = _floatingBoundary, $[3] = _referenceBoundary, $[4] = childProp, $[5] = className, $[6] = content2, $[7] = disabled, $[8] = forwardedRef, $[9] = matchReferenceWidth, $[10] = modal, $[11] = open, $[12] = padding, $[13] = portal, $[14] = referenceElement, $[15] = rest, $[16] = scheme, $[17] = t1, $[18] = t10, $[19] = t11, $[20] = t12, $[21] = t13, $[22] = t14, $[23] = t2, $[24] = t3, $[25] = t4, $[26] = t5, $[27] = t6, $[28] = t7, $[29] = t8, $[30] = t9, $[31] = updateRef;
1077
1076
  } else
1078
1077
  _fallbackPlacements = $[1], _floatingBoundary = $[2], _referenceBoundary = $[3], childProp = $[4], className = $[5], content2 = $[6], disabled = $[7], forwardedRef = $[8], matchReferenceWidth = $[9], modal = $[10], open = $[11], padding = $[12], portal = $[13], referenceElement = $[14], rest = $[15], scheme = $[16], t1 = $[17], t10 = $[18], t11 = $[19], t12 = $[20], t13 = $[21], t14 = $[22], t2 = $[23], t3 = $[24], t4 = $[25], t5 = $[26], t6 = $[27], t7 = $[28], t8 = $[29], t9 = $[30], updateRef = $[31];
1079
- const margins = t1 === void 0 ? DEFAULT_POPOVER_MARGINS : t1, _animate = t2 === void 0 ? !1 : t2, arrowProp = t3 === void 0 ? !1 : t3, as = t4 === void 0 ? DEFAULT_POPOVER_ELEMENT : t4, constrainSize = t5 === void 0 ? !1 : t5, overflow = t6 === void 0 ? "hidden" : t6, placementProp = t7 === void 0 ? "bottom" : t7, placementStrategy = t8 === void 0 ? "flip" : t8, preventOverflow = t9 === void 0 ? !0 : t9, radius = t10 === void 0 ? 3 : t10, shadow = t11 === void 0 ? 3 : t11, tone = t12 === void 0 ? "inherit" : t12, widthProp = t13 === void 0 ? "auto" : t13, zOffsetProp = t14 === void 0 ? Z_OFFSETS.popover : t14, fallbackPlacements = _fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS$1[props.placement ?? "bottom"], floatingBoundary = _floatingBoundary ?? boundaryElementContext.element, referenceBoundary = _referenceBoundary ?? boundaryElementContext.element, card2 = useCard(), animate = usePrefersReducedMotion() ? !1 : _animate;
1078
+ const margins = t1 === void 0 ? DEFAULT_POPOVER_MARGINS : t1, _animate = t2 === void 0 ? !1 : t2, arrowProp = t3 === void 0 ? !1 : t3, as = t4 === void 0 ? DEFAULT_POPOVER_ELEMENT : t4, constrainSize = t5 === void 0 ? !1 : t5, overflow = t6 === void 0 ? "hidden" : t6, placementProp = t7 === void 0 ? "bottom" : t7, placementStrategy = t8 === void 0 ? "flip" : t8, preventOverflow = t9 === void 0 ? !0 : t9, radius = t10 === void 0 ? 3 : t10, shadow = t11 === void 0 ? 3 : t11, tone = t12 === void 0 ? "inherit" : t12, widthProp = t13 === void 0 ? "auto" : t13, zOffsetProp = t14 === void 0 ? Z_OFFSETS.popover : t14, fallbackPlacements = _fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS$1[props.placement ?? "bottom"], floatingBoundary = _floatingBoundary ?? use(BoundaryElementContext), referenceBoundary = _referenceBoundary ?? use(BoundaryElementContext), animate = usePrefersReducedMotion() ? !1 : _animate;
1080
1079
  let t15;
1081
1080
  $[32] !== zOffsetProp ? (t15 = _getResponsiveProp(zOffsetProp), $[32] = zOffsetProp, $[33] = t15) : t15 = $[33];
1082
1081
  const zOffset = t15, ref = useRef(null), arrowRef = useRef(null);
@@ -1165,16 +1164,26 @@ function Popover(props) {
1165
1164
  t28
1166
1165
  ] }), $[97] = t26, $[98] = t28, $[99] = t29) : t29 = $[99];
1167
1166
  const node_0 = t29;
1167
+ let children = open ? node_0 : null;
1168
+ if (open && portal) {
1169
+ let resolvedTone = tone;
1170
+ if (tone === "inherit") {
1171
+ const card2 = use(CardContext);
1172
+ assertCardContext(card2), resolvedTone = card2.tone;
1173
+ }
1174
+ const t302 = typeof portal == "string" ? portal : void 0, t312 = scheme ?? "light";
1175
+ let t32;
1176
+ $[100] !== node_0 || $[101] !== resolvedTone || $[102] !== t312 ? (t32 = /* @__PURE__ */ jsx(CardProvider, { tone: resolvedTone, scheme: t312, children: node_0 }), $[100] = node_0, $[101] = resolvedTone, $[102] = t312, $[103] = t32) : t32 = $[103];
1177
+ let t33;
1178
+ $[104] !== t302 || $[105] !== t32 ? (t33 = /* @__PURE__ */ jsx(Portal, { __unstable_name: t302, children: t32 }), $[104] = t302, $[105] = t32, $[106] = t33) : t33 = $[106], children = t33;
1179
+ }
1168
1180
  let t30;
1169
- $[100] !== card2 || $[101] !== node_0 || $[102] !== open || $[103] !== portal || $[104] !== scheme || $[105] !== tone ? (t30 = open && (portal ? /* @__PURE__ */ jsx(Portal, { __unstable_name: typeof portal == "string" ? portal : void 0, children: /* @__PURE__ */ jsx(CardProvider, { tone: tone === "inherit" ? card2.tone : tone, scheme: scheme ?? "light", children: node_0 }) }) : node_0), $[100] = card2, $[101] = node_0, $[102] = open, $[103] = portal, $[104] = scheme, $[105] = tone, $[106] = t30) : t30 = $[106];
1170
- const children = t30;
1181
+ $[107] !== animate || $[108] !== children ? (t30 = animate ? /* @__PURE__ */ jsx(AnimatePresence, { children }) : children, $[107] = animate, $[108] = children, $[109] = t30) : t30 = $[109];
1171
1182
  let t31;
1172
- $[107] !== animate || $[108] !== children ? (t31 = animate ? /* @__PURE__ */ jsx(AnimatePresence, { children }) : children, $[107] = animate, $[108] = children, $[109] = t31) : t31 = $[109];
1173
- let t32;
1174
- return $[110] !== child || $[111] !== t31 ? (t32 = /* @__PURE__ */ jsxs(Fragment, { children: [
1175
- t31,
1183
+ return $[110] !== child || $[111] !== t30 ? (t31 = /* @__PURE__ */ jsxs(Fragment, { children: [
1184
+ t30,
1176
1185
  child
1177
- ] }), $[110] = child, $[111] = t31, $[112] = t32) : t32 = $[112], t32;
1186
+ ] }), $[110] = child, $[111] = t30, $[112] = t31) : t31 = $[112], t31;
1178
1187
  }
1179
1188
  function useMiddleware$1(t0) {
1180
1189
  const $ = c(36), {
@@ -2029,9 +2038,9 @@ function DialogCard(props) {
2029
2038
  ref: forwardedRef,
2030
2039
  ...rest
2031
2040
  } = t0, $[0] = t0, $[1] = autoFocus, $[2] = children, $[3] = footer, $[4] = forwardedContentRef, $[5] = forwardedRef, $[6] = header, $[7] = hideCloseButton, $[8] = id, $[9] = onClickOutside, $[10] = onClose, $[11] = portalProp, $[12] = rest, $[13] = t1) : (autoFocus = $[1], children = $[2], footer = $[3], forwardedContentRef = $[4], forwardedRef = $[5], header = $[6], hideCloseButton = $[7], id = $[8], onClickOutside = $[9], onClose = $[10], portalProp = $[11], rest = $[12], t1 = $[13]);
2032
- const as = t1 === void 0 ? DEFAULT_DIALOG_CARD_ELEMENT : t1, portal = usePortal(), portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element, boundaryElement = useBoundaryElement().element, ref = useRef(null), contentRef = useRef(null), layer = useLayer(), {
2041
+ const as = t1 === void 0 ? DEFAULT_DIALOG_CARD_ELEMENT : t1, portal = usePortal(), portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element, boundaryElement = use(BoundaryElementContext), ref = useRef(null), contentRef = useRef(null), {
2033
2042
  isTopLayer
2034
- } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton, [scrollTop, setScrollTop] = useState(0), [scrollHeight, setScrollHeight] = useState(0), scrollBottom = scrollHeight - scrollTop;
2043
+ } = useLayer(), labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton, [scrollTop, setScrollTop] = useState(0), [scrollHeight, setScrollHeight] = useState(0), scrollBottom = scrollHeight - scrollTop;
2035
2044
  let t2;
2036
2045
  $[14] === Symbol.for("react.memo_cache_sentinel") ? (t2 = () => ref.current, $[14] = t2) : t2 = $[14], useImperativeHandle(forwardedRef, t2);
2037
2046
  let t3;
@@ -2139,7 +2148,7 @@ function Dialog(props) {
2139
2148
  tone,
2140
2149
  ...rest
2141
2150
  } = t0, $[0] = t0, $[1] = _positionProp, $[2] = _zOffsetProp, $[3] = children, $[4] = className, $[5] = contentRef, $[6] = footer, $[7] = header, $[8] = id, $[9] = onActivate, $[10] = onClickOutside, $[11] = onClose, $[12] = onFocus, $[13] = portalProp, $[14] = rest, $[15] = scheme, $[16] = t1, $[17] = t2, $[18] = t3, $[19] = t4, $[20] = t5, $[21] = t6, $[22] = t7, $[23] = tone) : (_positionProp = $[1], _zOffsetProp = $[2], children = $[3], className = $[4], contentRef = $[5], footer = $[6], header = $[7], id = $[8], onActivate = $[9], onClickOutside = $[10], onClose = $[11], onFocus = $[12], portalProp = $[13], rest = $[14], scheme = $[15], t1 = $[16], t2 = $[17], t3 = $[18], t4 = $[19], t5 = $[20], t6 = $[21], t7 = $[22], tone = $[23]);
2142
- const autoFocus = t1 === void 0 ? !0 : t1, hideCloseButton = t2 === void 0 ? !1 : t2, _animate = t3 === void 0 ? !1 : t3, cardRadiusProp = t4 === void 0 ? 4 : t4, padding = t5 === void 0 ? 3 : t5, cardShadow = t6 === void 0 ? 4 : t6, width = t7 === void 0 ? 0 : t7, positionProp = _positionProp ?? context.position ?? "fixed", zOffsetProp = _zOffsetProp ?? context.zOffset ?? Z_OFFSETS.dialog, animate = usePrefersReducedMotion() ? !1 : _animate, portal = usePortal(), portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element, boundaryElement = useBoundaryElement().element;
2151
+ const autoFocus = t1 === void 0 ? !0 : t1, hideCloseButton = t2 === void 0 ? !1 : t2, _animate = t3 === void 0 ? !1 : t3, cardRadiusProp = t4 === void 0 ? 4 : t4, padding = t5 === void 0 ? 3 : t5, cardShadow = t6 === void 0 ? 4 : t6, width = t7 === void 0 ? 0 : t7, positionProp = _positionProp ?? context.position ?? "fixed", zOffsetProp = _zOffsetProp ?? context.zOffset ?? Z_OFFSETS.dialog, animate = usePrefersReducedMotion() ? !1 : _animate, portal = usePortal(), portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element, boundaryElement = use(BoundaryElementContext);
2143
2152
  let t8;
2144
2153
  $[24] !== cardRadiusProp ? (t8 = _getResponsiveProp(cardRadiusProp), $[24] = cardRadiusProp, $[25] = t8) : t8 = $[25];
2145
2154
  const cardRadius = t8;
@@ -4436,9 +4445,6 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
4436
4445
  "right-start": ["right", "right-end", "left-start", "top-start", "bottom-start"],
4437
4446
  "right-end": ["right", "right-start", "left-end", "top-end", "bottom-end"]
4438
4447
  }, TooltipDelayGroupContext = createGlobalScopedContext("@sanity/ui/v4/tooltipDelayGroup", null);
4439
- function useTooltipDelayGroup() {
4440
- return use(TooltipDelayGroupContext);
4441
- }
4442
4448
  function TooltipLayer(props) {
4443
4449
  const $ = c(50);
4444
4450
  let animate, arrow2, arrowRef, arrowX, arrowY, children, originX, originY, padding, placement, radius, rest, scheme, shadow, style, t0;
@@ -4493,7 +4499,7 @@ function TooltipLayer(props) {
4493
4499
  }
4494
4500
  const DEFAULT_TOOLTIP_ELEMENT = "div";
4495
4501
  function Tooltip(props) {
4496
- const $ = c(143), boundaryElementContext = useBoundaryElement(), t0 = props;
4502
+ const $ = c(143), t0 = props;
4497
4503
  let _boundaryElement, _fallbackPlacements, childProp, className, content2, delay, disabled, forwardedRef, portalProp, rest, scheme, t1, t2, t3, t4, t5, t6, t7, t8, t9;
4498
4504
  $[0] !== t0 ? ({
4499
4505
  animate: t1,
@@ -4517,10 +4523,14 @@ function Tooltip(props) {
4517
4523
  tone: t9,
4518
4524
  ...rest
4519
4525
  } = t0, $[0] = t0, $[1] = _boundaryElement, $[2] = _fallbackPlacements, $[3] = childProp, $[4] = className, $[5] = content2, $[6] = delay, $[7] = disabled, $[8] = forwardedRef, $[9] = portalProp, $[10] = rest, $[11] = scheme, $[12] = t1, $[13] = t2, $[14] = t3, $[15] = t4, $[16] = t5, $[17] = t6, $[18] = t7, $[19] = t8, $[20] = t9) : (_boundaryElement = $[1], _fallbackPlacements = $[2], childProp = $[3], className = $[4], content2 = $[5], delay = $[6], disabled = $[7], forwardedRef = $[8], portalProp = $[9], rest = $[10], scheme = $[11], t1 = $[12], t2 = $[13], t3 = $[14], t4 = $[15], t5 = $[16], t6 = $[17], t7 = $[18], t8 = $[19], t9 = $[20]);
4520
- const _animate = t1 === void 0 ? !1 : t1, arrowProp = t2 === void 0 ? !1 : t2, as = t3 === void 0 ? DEFAULT_TOOLTIP_ELEMENT : t3, padding = t4 === void 0 ? 2 : t4, placementProp = t5 === void 0 ? "bottom" : t5, radius = t6 === void 0 ? 3 : t6, shadow = t7 === void 0 ? 2 : t7, zOffset = t8 === void 0 ? Z_OFFSETS.tooltip : t8, tone = t9 === void 0 ? "inherit" : t9, boundaryElement = _boundaryElement ?? boundaryElementContext?.element, fallbackPlacements = _fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? "bottom"], card2 = useCard(), animate = usePrefersReducedMotion() ? !1 : _animate, ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), [tooltipMaxWidth, setTooltipMaxWidth] = useState(0);
4526
+ const _animate = t1 === void 0 ? !1 : t1, arrowProp = t2 === void 0 ? !1 : t2, as = t3 === void 0 ? DEFAULT_TOOLTIP_ELEMENT : t3, padding = t4 === void 0 ? 2 : t4, placementProp = t5 === void 0 ? "bottom" : t5, radius = t6 === void 0 ? 3 : t6, shadow = t7 === void 0 ? 2 : t7, zOffset = t8 === void 0 ? Z_OFFSETS.tooltip : t8, tone = t9 === void 0 ? "inherit" : t9, boundaryElement = _boundaryElement ?? use(BoundaryElementContext), fallbackPlacements = _fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? "bottom"], animate = usePrefersReducedMotion() ? !1 : _animate, ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), [tooltipMaxWidth, setTooltipMaxWidth] = useState(0);
4521
4527
  let t10;
4522
4528
  $[21] === Symbol.for("react.memo_cache_sentinel") ? (t10 = () => ref.current, $[21] = t10) : t10 = $[21], useImperativeHandle(forwardedRef, t10);
4523
- const portal = usePortal(), portalElement = typeof portalProp == "string" ? portal.elements?.[portalProp] || null : portal.element;
4529
+ let portalElement = null;
4530
+ if (portalProp) {
4531
+ const portal = use(PortalContext);
4532
+ assertPortalContext(portal), portalElement = typeof portalProp == "string" ? portal.elements?.[portalProp] || null : portal.element;
4533
+ }
4524
4534
  let t11;
4525
4535
  $[22] !== animate || $[23] !== arrowProp || $[24] !== boundaryElement || $[25] !== fallbackPlacements ? (t11 = {
4526
4536
  animate,
@@ -4549,7 +4559,7 @@ function Tooltip(props) {
4549
4559
  middlewareData,
4550
4560
  refs,
4551
4561
  update
4552
- } = useFloating(t13), arrowX = middlewareData.arrow?.x, arrowY = middlewareData.arrow?.y, originX = middlewareData["@sanity/ui/origin"]?.originX, originY = middlewareData["@sanity/ui/origin"]?.originY, tooltipId = useId(), [isOpen, setIsOpen] = useDelayedState(!1), delayGroupContext = useTooltipDelayGroup();
4562
+ } = useFloating(t13), arrowX = middlewareData.arrow?.x, arrowY = middlewareData.arrow?.y, originX = middlewareData["@sanity/ui/origin"]?.originX, originY = middlewareData["@sanity/ui/origin"]?.originY, tooltipId = useId(), [isOpen, setIsOpen] = useDelayedState(!1), delayGroupContext = use(TooltipDelayGroupContext);
4553
4563
  let t14;
4554
4564
  $[33] !== delayGroupContext ? (t14 = delayGroupContext || {}, $[33] = delayGroupContext, $[34] = t14) : t14 = $[34];
4555
4565
  const {
@@ -4627,10 +4637,10 @@ function Tooltip(props) {
4627
4637
  };
4628
4638
  }, t28 = [handleIsOpenChange, showTooltip], $[76] = handleIsOpenChange, $[77] = showTooltip, $[78] = t27, $[79] = t28) : (t27 = $[78], t28 = $[79]), useEffect(t27, t28);
4629
4639
  let t29;
4630
- $[80] !== boundaryElement || $[81] !== portalElement?.offsetWidth ? (t29 = () => {
4640
+ $[80] !== boundaryElement || $[81] !== portalElement ? (t29 = () => {
4631
4641
  const availableWidths = [...boundaryElement ? [boundaryElement.offsetWidth] : [], portalElement?.offsetWidth || document.body.offsetWidth];
4632
4642
  setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
4633
- }, $[80] = boundaryElement, $[81] = portalElement?.offsetWidth, $[82] = t29) : t29 = $[82];
4643
+ }, $[80] = boundaryElement, $[81] = portalElement, $[82] = t29) : t29 = $[82];
4634
4644
  let t30;
4635
4645
  $[83] !== boundaryElement || $[84] !== portalElement ? (t30 = [boundaryElement, portalElement], $[83] = boundaryElement, $[84] = portalElement, $[85] = t30) : t30 = $[85], useLayoutEffect(t29, t30);
4636
4646
  let t31;
@@ -4683,16 +4693,26 @@ function Tooltip(props) {
4683
4693
  let t40;
4684
4694
  $[109] !== animate || $[110] !== arrowProp || $[111] !== arrowX || $[112] !== arrowY || $[113] !== as || $[114] !== content2 || $[115] !== originX || $[116] !== originY || $[117] !== padding || $[118] !== placement || $[119] !== radius || $[120] !== rest || $[121] !== scheme || $[122] !== setArrow || $[123] !== setFloating || $[124] !== shadow || $[125] !== t37 || $[126] !== t39 || $[127] !== tone || $[128] !== zOffset ? (t40 = /* @__PURE__ */ jsx(TooltipLayer, { "data-ui": "Tooltip", ...rest, animate, arrow: arrowProp, arrowRef: setArrow, arrowX, arrowY, as, className: t37, originX, originY, padding, placement, radius, ref: setFloating, scheme, shadow, style: t39, tone, zOffset, children: content2 }), $[109] = animate, $[110] = arrowProp, $[111] = arrowX, $[112] = arrowY, $[113] = as, $[114] = content2, $[115] = originX, $[116] = originY, $[117] = padding, $[118] = placement, $[119] = radius, $[120] = rest, $[121] = scheme, $[122] = setArrow, $[123] = setFloating, $[124] = shadow, $[125] = t37, $[126] = t39, $[127] = tone, $[128] = zOffset, $[129] = t40) : t40 = $[129];
4685
4695
  const node_0 = t40;
4696
+ let children = showTooltip ? node_0 : null;
4697
+ if (showTooltip && portalProp) {
4698
+ let resolvedTone = tone;
4699
+ if (tone === "inherit") {
4700
+ const card2 = use(CardContext);
4701
+ assertCardContext(card2), resolvedTone = card2.tone;
4702
+ }
4703
+ const t412 = typeof portalProp == "string" ? portalProp : void 0, t422 = scheme ?? "light";
4704
+ let t43;
4705
+ $[130] !== node_0 || $[131] !== resolvedTone || $[132] !== t422 ? (t43 = /* @__PURE__ */ jsx(CardProvider, { tone: resolvedTone, scheme: t422, children: node_0 }), $[130] = node_0, $[131] = resolvedTone, $[132] = t422, $[133] = t43) : t43 = $[133];
4706
+ let t44;
4707
+ $[134] !== t412 || $[135] !== t43 ? (t44 = /* @__PURE__ */ jsx(Portal, { __unstable_name: t412, children: t43 }), $[134] = t412, $[135] = t43, $[136] = t44) : t44 = $[136], children = t44;
4708
+ }
4686
4709
  let t41;
4687
- $[130] !== card2 || $[131] !== node_0 || $[132] !== portalProp || $[133] !== scheme || $[134] !== showTooltip || $[135] !== tone ? (t41 = showTooltip && (portalProp ? /* @__PURE__ */ jsx(Portal, { __unstable_name: typeof portalProp == "string" ? portalProp : void 0, children: /* @__PURE__ */ jsx(CardProvider, { tone: tone === "inherit" ? card2.tone : tone, scheme: scheme ?? "light", children: node_0 }) }) : node_0), $[130] = card2, $[131] = node_0, $[132] = portalProp, $[133] = scheme, $[134] = showTooltip, $[135] = tone, $[136] = t41) : t41 = $[136];
4688
- const children = t41;
4710
+ $[137] !== animate || $[138] !== children ? (t41 = animate ? /* @__PURE__ */ jsx(AnimatePresence, { children }) : children, $[137] = animate, $[138] = children, $[139] = t41) : t41 = $[139];
4689
4711
  let t42;
4690
- $[137] !== animate || $[138] !== children ? (t42 = animate ? /* @__PURE__ */ jsx(AnimatePresence, { children }) : children, $[137] = animate, $[138] = children, $[139] = t42) : t42 = $[139];
4691
- let t43;
4692
- return $[140] !== child || $[141] !== t42 ? (t43 = /* @__PURE__ */ jsxs(Fragment, { children: [
4693
- t42,
4712
+ return $[140] !== child || $[141] !== t41 ? (t42 = /* @__PURE__ */ jsxs(Fragment, { children: [
4713
+ t41,
4694
4714
  child
4695
- ] }), $[140] = child, $[141] = t42, $[142] = t43) : t43 = $[142], t43;
4715
+ ] }), $[140] = child, $[141] = t41, $[142] = t42) : t42 = $[142], t42;
4696
4716
  }
4697
4717
  function useMiddleware(t0) {
4698
4718
  const $ = c(17), {
@@ -4777,19 +4797,24 @@ function TooltipDelayGroupProvider(props) {
4777
4797
  let t2;
4778
4798
  return $[6] !== children || $[7] !== value ? (t2 = /* @__PURE__ */ jsx(TooltipDelayGroupContext, { value, children }), $[6] = children, $[7] = value, $[8] = t2) : t2 = $[8], t2;
4779
4799
  }
4800
+ function useTooltipDelayGroup() {
4801
+ return use(TooltipDelayGroupContext);
4802
+ }
4780
4803
  function BoundaryElementProvider(props) {
4781
- const $ = c(5), {
4804
+ const $ = c(3), {
4782
4805
  children,
4783
4806
  element
4784
4807
  } = props;
4785
4808
  let t0;
4786
- $[0] !== element ? (t0 = {
4809
+ return $[0] !== children || $[1] !== element ? (t0 = /* @__PURE__ */ jsx(BoundaryElementContext, { value: element, children }), $[0] = children, $[1] = element, $[2] = t0) : t0 = $[2], t0;
4810
+ }
4811
+ function useBoundaryElement() {
4812
+ const $ = c(2), element = use(BoundaryElementContext);
4813
+ let t0;
4814
+ return $[0] !== element ? (t0 = {
4787
4815
  version: 0,
4788
4816
  element
4789
- }, $[0] = element, $[1] = t0) : t0 = $[1];
4790
- const value = t0;
4791
- let t1;
4792
- return $[2] !== children || $[3] !== value ? (t1 = /* @__PURE__ */ jsx(BoundaryElementContext, { value, children }), $[2] = children, $[3] = value, $[4] = t1) : t1 = $[4], t1;
4817
+ }, $[0] = element, $[1] = t0) : t0 = $[1], t0;
4793
4818
  }
4794
4819
  function findMaxBreakpoints(media2, width) {
4795
4820
  const ret = [];