@sanity/ui 2.1.14 → 2.1.15-canary.1

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.js CHANGED
@@ -196,7 +196,16 @@ var freeze = function(obj) {
196
196
  }
197
197
  return DOMRectReadOnly2.prototype.toJSON = function() {
198
198
  var _a = this, x = _a.x, y = _a.y, top = _a.top, right = _a.right, bottom = _a.bottom, left = _a.left, width = _a.width, height = _a.height;
199
- return { x, y, top, right, bottom, left, width, height };
199
+ return {
200
+ x,
201
+ y,
202
+ top,
203
+ right,
204
+ bottom,
205
+ left,
206
+ width,
207
+ height
208
+ };
200
209
  }, DOMRectReadOnly2.fromRect = function(rectangle) {
201
210
  return new DOMRectReadOnly2(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
202
211
  }, DOMRectReadOnly2;
@@ -308,7 +317,9 @@ var freeze = function(obj) {
308
317
  });
309
318
  }, queueMicroTask = function(callback) {
310
319
  if (!trigger) {
311
- var toggle_1 = 0, el_1 = document.createTextNode(""), config = { characterData: !0 };
320
+ var toggle_1 = 0, el_1 = document.createTextNode(""), config = {
321
+ characterData: !0
322
+ };
312
323
  new MutationObserver(function() {
313
324
  return notify();
314
325
  }).observe(el_1, config), trigger = function() {
@@ -322,22 +333,12 @@ var freeze = function(obj) {
322
333
  });
323
334
  }, watching = 0, isWatching = function() {
324
335
  return !!watching;
325
- }, CATCH_PERIOD = 250, observerConfig = { attributes: !0, characterData: !0, childList: !0, subtree: !0 }, events = [
326
- "resize",
327
- "load",
328
- "transitionend",
329
- "animationend",
330
- "animationstart",
331
- "animationiteration",
332
- "keyup",
333
- "keydown",
334
- "mouseup",
335
- "mousedown",
336
- "mouseover",
337
- "mouseout",
338
- "blur",
339
- "focus"
340
- ], time = function(timeout) {
336
+ }, CATCH_PERIOD = 250, observerConfig = {
337
+ attributes: !0,
338
+ characterData: !0,
339
+ childList: !0,
340
+ subtree: !0
341
+ }, events = ["resize", "load", "transitionend", "animationend", "animationstart", "animationiteration", "keyup", "keydown", "mouseup", "mousedown", "mouseover", "mouseout", "blur", "focus"], time = function(timeout) {
341
342
  return timeout === void 0 && (timeout = 0), Date.now() + timeout;
342
343
  }, scheduled = !1, Scheduler = function() {
343
344
  function Scheduler2() {
@@ -621,12 +622,9 @@ function getServerSnapshot() {
621
622
  function usePrefersReducedMotion() {
622
623
  return react.useSyncExternalStore(subscribe$1, getSnapshot, getServerSnapshot);
623
624
  }
624
- const useIsomorphicEffect = typeof window < "u" ? react.useLayoutEffect : react.useEffect;
625
625
  function useForwardedRef(ref) {
626
626
  const innerRef = react.useRef(null);
627
- return useIsomorphicEffect(() => {
628
- ref && (typeof ref == "function" ? ref(innerRef.current) : ref.current = innerRef.current);
629
- }), innerRef;
627
+ return react.useImperativeHandle(ref, () => innerRef.current), innerRef;
630
628
  }
631
629
  function useCustomValidity(ref, customValidity) {
632
630
  react.useEffect(() => {
@@ -2372,10 +2370,13 @@ const Root$r = styledComponents.styled.div(checkboxBaseStyles), Input$5 = styled
2372
2370
  readOnly,
2373
2371
  style,
2374
2372
  ...restProps
2375
- } = props, ref = useForwardedRef(forwardedRef);
2376
- return useCustomValidity(ref, customValidity), react.useEffect(() => {
2373
+ } = props, ref = react.useRef(null);
2374
+ return react.useImperativeHandle(
2375
+ forwardedRef,
2376
+ () => ref.current
2377
+ ), react.useEffect(() => {
2377
2378
  ref.current && (ref.current.indeterminate = indeterminate || !1);
2378
- }, [indeterminate, ref]), /* @__PURE__ */ jsxRuntime.jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2379
+ }, [indeterminate]), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2379
2380
  /* @__PURE__ */ jsxRuntime.jsx(
2380
2381
  Input$5,
2381
2382
  {
@@ -2850,16 +2851,15 @@ function findMinBreakpoints(media, width) {
2850
2851
  media[i] <= width && ret.push(i);
2851
2852
  return ret;
2852
2853
  }
2853
- const ElementQuery = react.forwardRef(function(props, ref) {
2854
- const theme2 = useTheme_v2(), { children, media = theme2.media, ...restProps } = props, forwardedRef = useForwardedRef(ref), [element, setElement] = react.useState(null), elementSize = useElementSize(element), width = react.useMemo(() => {
2854
+ const ElementQuery = react.forwardRef(function(props, forwardedRef) {
2855
+ const theme2 = useTheme_v2(), { children, media = theme2.media, ...restProps } = props, ref = react.useRef(null), [element, setElement] = react.useState(null), elementSize = useElementSize(element), width = react.useMemo(() => {
2855
2856
  var _a;
2856
2857
  return (_a = elementSize == null ? void 0 : elementSize.border.width) != null ? _a : window.innerWidth;
2857
- }, [elementSize]), max = react.useMemo(() => findMaxBreakpoints(media, width), [media, width]), min = react.useMemo(() => findMinBreakpoints(media, width), [media, width]), setRef = react.useCallback(
2858
- (el) => {
2859
- forwardedRef.current = el, setElement(el);
2860
- },
2861
- [forwardedRef]
2862
- );
2858
+ }, [elementSize]), max = react.useMemo(() => findMaxBreakpoints(media, width), [media, width]), min = react.useMemo(() => findMinBreakpoints(media, width), [media, width]);
2859
+ react.useImperativeHandle(forwardedRef, () => ref.current);
2860
+ const setRef = react.useCallback((el) => {
2861
+ ref.current = el, setElement(el);
2862
+ }, []);
2863
2863
  return /* @__PURE__ */ jsxRuntime.jsx(
2864
2864
  "div",
2865
2865
  {
@@ -3019,30 +3019,20 @@ function LayerProvider(props) {
3019
3019
  );
3020
3020
  return /* @__PURE__ */ jsxRuntime.jsx(LayerContext.Provider, { value, children });
3021
3021
  }
3022
- const Root$j = styledComponents.styled.div({ position: "relative" }), LayerChildren = react.forwardRef(function(props, ref) {
3023
- const { children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps } = props, { zIndex, isTopLayer } = useLayer(), lastFocusedRef = react.useRef(null), forwardedRef = useForwardedRef(ref), isTopLayerRef = react.useRef(isTopLayer);
3024
- react.useEffect(() => {
3022
+ const Root$j = styledComponents.styled.div({ position: "relative" }), LayerChildren = react.forwardRef(function(props, forwardedRef) {
3023
+ const { children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps } = props, { zIndex, isTopLayer } = useLayer(), lastFocusedRef = react.useRef(null), ref = react.useRef(null), isTopLayerRef = react.useRef(isTopLayer);
3024
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useEffect(() => {
3025
3025
  isTopLayerRef.current !== isTopLayer && isTopLayer && (onActivate == null || onActivate({ activeElement: lastFocusedRef.current })), isTopLayerRef.current = isTopLayer;
3026
3026
  }, [isTopLayer, onActivate]);
3027
3027
  const handleFocus = react.useCallback(
3028
3028
  (event) => {
3029
3029
  onFocus == null || onFocus(event);
3030
- const rootElement = forwardedRef.current, target = document.activeElement;
3030
+ const rootElement = ref.current, target = document.activeElement;
3031
3031
  !isTopLayer || !rootElement || !target || isHTMLElement(target) && containsOrEqualsElement(rootElement, target) && (lastFocusedRef.current = target);
3032
3032
  },
3033
- [forwardedRef, isTopLayer, onFocus]
3034
- );
3035
- return /* @__PURE__ */ jsxRuntime.jsx(
3036
- Root$j,
3037
- {
3038
- ...restProps,
3039
- "data-ui": "Layer",
3040
- onFocus: handleFocus,
3041
- ref: forwardedRef,
3042
- style: { ...style, zIndex },
3043
- children
3044
- }
3033
+ [isTopLayer, onFocus]
3045
3034
  );
3035
+ return /* @__PURE__ */ jsxRuntime.jsx(Root$j, { ...restProps, "data-ui": "Layer", onFocus: handleFocus, ref, style: { ...style, zIndex }, children });
3046
3036
  }), Layer = react.forwardRef(function(props, ref) {
3047
3037
  const { children, zOffset = 1, ...restProps } = props;
3048
3038
  return /* @__PURE__ */ jsxRuntime.jsx(LayerProvider, { zOffset, children: /* @__PURE__ */ jsxRuntime.jsx(LayerChildren, { ...restProps, ref, children }) });
@@ -3108,15 +3098,15 @@ const emptySubscribe$1 = () => () => {
3108
3098
  position: absolute;
3109
3099
  left: 0;
3110
3100
  right: 0;
3111
- `, VirtualList = react.forwardRef(function(props, ref) {
3112
- const { as = "div", gap = 0, getItemKey, items = [], onChange, renderItem, ...restProps } = props, { space } = useTheme_v2(), forwardedRef = useForwardedRef(ref), wrapperRef = react.useRef(null), [scrollTop, setScrollTop] = react.useState(0), [scrollHeight, setScrollHeight] = react.useState(0), [itemHeight, setItemHeight] = react.useState(-1);
3113
- react.useEffect(() => {
3101
+ `, VirtualList = react.forwardRef(function(props, forwardedRef) {
3102
+ const { as = "div", gap = 0, getItemKey, items = [], onChange, renderItem, ...restProps } = props, { space } = useTheme_v2(), ref = react.useRef(null), wrapperRef = react.useRef(null), [scrollTop, setScrollTop] = react.useState(0), [scrollHeight, setScrollHeight] = react.useState(0), [itemHeight, setItemHeight] = react.useState(-1);
3103
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useEffect(() => {
3114
3104
  if (!wrapperRef.current) return;
3115
3105
  const firstElement = wrapperRef.current.firstChild;
3116
3106
  firstElement instanceof HTMLElement && setItemHeight(firstElement.offsetHeight);
3117
3107
  }, [renderItem]), react.useEffect(() => {
3118
- if (!forwardedRef.current) return;
3119
- let _scrollEl = forwardedRef.current.parentNode;
3108
+ if (!ref.current) return;
3109
+ let _scrollEl = ref.current.parentNode;
3120
3110
  for (; _scrollEl && !_isScrollable(_scrollEl); )
3121
3111
  _scrollEl = _scrollEl.parentNode;
3122
3112
  if (_scrollEl) {
@@ -3141,7 +3131,7 @@ const emptySubscribe$1 = () => () => {
3141
3131
  return window.addEventListener("scroll", handleScroll, { passive: !0 }), window.addEventListener("resize", handleResize), setScrollHeight(window.innerHeight), handleScroll(), () => {
3142
3132
  window.removeEventListener("scroll", handleScroll), window.removeEventListener("resize", handleResize);
3143
3133
  };
3144
- }, [forwardedRef]);
3134
+ }, []);
3145
3135
  const len = items.length, height = itemHeight ? len * (itemHeight + space[gap]) - space[gap] : 0, fromIndex = height ? Math.max(Math.floor(scrollTop / height * len) - 2, 0) : 0, toIndex = height ? Math.ceil((scrollTop + scrollHeight) / height * len) + 1 : 0;
3146
3136
  react.useEffect(() => {
3147
3137
  onChange && onChange({ fromIndex, gap: space[gap], itemHeight, scrollHeight, scrollTop, toIndex });
@@ -3150,7 +3140,7 @@ const emptySubscribe$1 = () => () => {
3150
3140
  const itemIndex = fromIndex + _itemIndex, node = renderItem(item), key2 = getItemKey ? getItemKey(item, itemIndex) : itemIndex;
3151
3141
  return /* @__PURE__ */ jsxRuntime.jsx(ItemWrapper, { style: { top: itemIndex * (itemHeight + space[gap]) }, children: node }, key2);
3152
3142
  }), [fromIndex, gap, getItemKey, itemHeight, items, renderItem, space, toIndex]), wrapperStyle = react.useMemo(() => ({ height }), [height]);
3153
- return /* @__PURE__ */ jsxRuntime.jsx(Root$h, { as, "data-ui": "VirtualList", ...restProps, ref: forwardedRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: wrapperRef, style: wrapperStyle, children }) });
3143
+ return /* @__PURE__ */ jsxRuntime.jsx(Root$h, { as, "data-ui": "VirtualList", ...restProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: wrapperRef, style: wrapperStyle, children }) });
3154
3144
  }), DEFAULT_POPOVER_DISTANCE = 4, DEFAULT_POPOVER_PADDING = 4, DEFAULT_POPOVER_ARROW_WIDTH = 19, DEFAULT_POPOVER_ARROW_HEIGHT = 8, DEFAULT_POPOVER_ARROW_RADIUS = 2, DEFAULT_POPOVER_MARGINS = [0, 0, 0, 0], DEFAULT_FALLBACK_PLACEMENTS$1 = {
3155
3145
  top: ["bottom", "left", "right"],
3156
3146
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -3296,7 +3286,7 @@ const MotionCard$1 = styledComponents.styled(framerMotion.motion(Card))`
3296
3286
  );
3297
3287
  PopoverCard.displayName = "PopoverCard";
3298
3288
  const Popover = react.memo(
3299
- react.forwardRef(function(props, ref) {
3289
+ react.forwardRef(function(props, forwardedRef) {
3300
3290
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3301
3291
  const { container, layer } = useTheme_v2(), boundaryElementContext = useBoundaryElement(), {
3302
3292
  __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
@@ -3328,7 +3318,12 @@ const Popover = react.memo(
3328
3318
  zOffset: zOffsetProp = layer.popover.zOffset,
3329
3319
  updateRef,
3330
3320
  ...restProps
3331
- } = props, animate = usePrefersReducedMotion() ? !1 : _animate, boundarySize = (_e = useElementSize(boundaryElement)) == null ? void 0 : _e.border, padding = useArrayProp(paddingProp), radius = useArrayProp(radiusProp), shadow = useArrayProp(shadowProp), widthArrayProp = useArrayProp(widthProp), zOffset = useArrayProp(zOffsetProp), forwardedRef = useForwardedRef(ref), arrowRef = react.useRef(null), rootBoundary = "viewport", mediaIndex = useMediaIndex(), boundaryWidth = constrainSize || preventOverflow ? boundarySize == null ? void 0 : boundarySize.width : void 0, width = calcCurrentWidth({
3321
+ } = props, animate = usePrefersReducedMotion() ? !1 : _animate, boundarySize = (_e = useElementSize(boundaryElement)) == null ? void 0 : _e.border, padding = useArrayProp(paddingProp), radius = useArrayProp(radiusProp), shadow = useArrayProp(shadowProp), widthArrayProp = useArrayProp(widthProp), zOffset = useArrayProp(zOffsetProp), ref = react.useRef(null), arrowRef = react.useRef(null), rootBoundary = "viewport";
3322
+ react.useImperativeHandle(
3323
+ forwardedRef,
3324
+ () => ref.current
3325
+ );
3326
+ const mediaIndex = useMediaIndex(), boundaryWidth = constrainSize || preventOverflow ? boundarySize == null ? void 0 : boundarySize.width : void 0, width = calcCurrentWidth({
3332
3327
  container,
3333
3328
  mediaIndex,
3334
3329
  width: widthArrayProp
@@ -3342,11 +3337,11 @@ const Popover = react.memo(
3342
3337
  }, [maxWidth]);
3343
3338
  const referenceWidthRef = react.useRef();
3344
3339
  react.useEffect(() => {
3345
- const floatingElement = forwardedRef.current;
3340
+ const floatingElement = ref.current;
3346
3341
  if (!open || !floatingElement) return;
3347
3342
  const referenceWidth = referenceWidthRef.current;
3348
3343
  matchReferenceWidth ? referenceWidth !== void 0 && (floatingElement.style.width = `${referenceWidth}px`) : width !== void 0 && (floatingElement.style.width = `${width}px`), typeof maxWidth == "number" && (floatingElement.style.maxWidth = `${maxWidth}px`);
3349
- }, [width, forwardedRef, matchReferenceWidth, maxWidth, open]);
3344
+ }, [width, matchReferenceWidth, maxWidth, open]);
3350
3345
  const middleware = react.useMemo(() => {
3351
3346
  const ret = [];
3352
3347
  return (constrainSize || preventOverflow) && ret.push(
@@ -3408,9 +3403,9 @@ const Popover = react.memo(
3408
3403
  arrowRef.current = arrowEl;
3409
3404
  }, []), setFloating = react.useCallback(
3410
3405
  (node) => {
3411
- forwardedRef.current = node, refs.setFloating(node);
3406
+ ref.current = node, refs.setFloating(node);
3412
3407
  },
3413
- [forwardedRef, refs]
3408
+ [refs]
3414
3409
  ), setReference = react.useCallback(
3415
3410
  (node) => {
3416
3411
  refs.setReference(node);
@@ -3583,8 +3578,11 @@ function inputElementStyle(props) {
3583
3578
  `;
3584
3579
  }
3585
3580
  const Root$g = styledComponents.styled.div(radioBaseStyle), Input$4 = styledComponents.styled.input(inputElementStyle), Radio = react.forwardRef(function(props, forwardedRef) {
3586
- const { className, disabled, style, customValidity, readOnly, ...restProps } = props, ref = useForwardedRef(forwardedRef);
3587
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$g, { className, "data-ui": "Radio", style, children: [
3581
+ const { className, disabled, style, customValidity, readOnly, ...restProps } = props, ref = react.useRef(null);
3582
+ return react.useImperativeHandle(
3583
+ forwardedRef,
3584
+ () => ref.current
3585
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$g, { className, "data-ui": "Radio", style, children: [
3588
3586
  /* @__PURE__ */ jsxRuntime.jsx(
3589
3587
  Input$4,
3590
3588
  {
@@ -3745,8 +3743,11 @@ const selectStyle = {
3745
3743
  readOnly,
3746
3744
  space = 3,
3747
3745
  ...restProps
3748
- } = props, ref = useForwardedRef(forwardedRef);
3749
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$f, { "data-ui": "Select", children: [
3746
+ } = props, ref = react.useRef(null);
3747
+ return react.useImperativeHandle(
3748
+ forwardedRef,
3749
+ () => ref.current
3750
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$f, { "data-ui": "Select", children: [
3750
3751
  /* @__PURE__ */ jsxRuntime.jsx(
3751
3752
  Input$3,
3752
3753
  {
@@ -3940,10 +3941,13 @@ function switchThumbStyles(props) {
3940
3941
  `;
3941
3942
  }
3942
3943
  const Root$d = styledComponents.styled.span(switchBaseStyles), Input$2 = styledComponents.styled.input(switchInputStyles), Representation = styledComponents.styled.span(switchRepresentationStyles), Track = styledComponents.styled.span(switchTrackStyles), Thumb = styledComponents.styled.span(switchThumbStyles), Switch = react.forwardRef(function(props, forwardedRef) {
3943
- const { checked, className, disabled, indeterminate, readOnly, style, ...restProps } = props, ref = useForwardedRef(forwardedRef);
3944
- return react.useEffect(() => {
3944
+ const { checked, className, disabled, indeterminate, readOnly, style, ...restProps } = props, ref = react.useRef(null);
3945
+ return react.useImperativeHandle(
3946
+ forwardedRef,
3947
+ () => ref.current
3948
+ ), react.useEffect(() => {
3945
3949
  ref.current && (ref.current.indeterminate = indeterminate || !1);
3946
- }, [indeterminate, ref]), /* @__PURE__ */ jsxRuntime.jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3950
+ }, [indeterminate]), /* @__PURE__ */ jsxRuntime.jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3947
3951
  /* @__PURE__ */ jsxRuntime.jsx(
3948
3952
  Input$2,
3949
3953
  {
@@ -3982,8 +3986,11 @@ const Root$d = styledComponents.styled.span(switchBaseStyles), Input$2 = styledC
3982
3986
  radius = 2,
3983
3987
  weight,
3984
3988
  ...restProps
3985
- } = props, ref = useForwardedRef(forwardedRef), rootTheme = useRootTheme();
3986
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsx(Root$c, { "data-ui": "TextArea", children: /* @__PURE__ */ jsxRuntime.jsxs(InputRoot$1, { children: [
3989
+ } = props, ref = react.useRef(null), rootTheme = useRootTheme();
3990
+ return react.useImperativeHandle(
3991
+ forwardedRef,
3992
+ () => ref.current
3993
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsx(Root$c, { "data-ui": "TextArea", children: /* @__PURE__ */ jsxRuntime.jsxs(InputRoot$1, { children: [
3987
3994
  /* @__PURE__ */ jsxRuntime.jsx(
3988
3995
  Input$1,
3989
3996
  {
@@ -4078,8 +4085,11 @@ const Root$d = styledComponents.styled.span(switchBaseStyles), Input$2 = styledC
4078
4085
  type = "text",
4079
4086
  weight,
4080
4087
  ...restProps
4081
- } = props, ref = useForwardedRef(forwardedRef), rootTheme = useRootTheme(), fontSize2 = useArrayProp(fontSizeProp), padding = useArrayProp(paddingProp), radius = useArrayProp(radiusProp), space = useArrayProp(spaceProp), $hasClearButton = !!clearButton, $hasIcon = !!icon, $hasIconRight = !!iconRight, $hasSuffix = !!suffix, $hasPrefix = !!prefix;
4082
- useCustomValidity(ref, customValidity);
4088
+ } = props, ref = react.useRef(null), rootTheme = useRootTheme(), fontSize2 = useArrayProp(fontSizeProp), padding = useArrayProp(paddingProp), radius = useArrayProp(radiusProp), space = useArrayProp(spaceProp), $hasClearButton = !!clearButton, $hasIcon = !!icon, $hasIconRight = !!iconRight, $hasSuffix = !!suffix, $hasPrefix = !!prefix;
4089
+ react.useImperativeHandle(
4090
+ forwardedRef,
4091
+ () => ref.current
4092
+ ), useCustomValidity(ref, customValidity);
4083
4093
  const handleClearMouseDown = react.useCallback((event) => {
4084
4094
  event.preventDefault(), event.stopPropagation();
4085
4095
  }, []), handleClearClick = react.useCallback(
@@ -4326,7 +4336,7 @@ function TooltipDelayGroupProvider(props) {
4326
4336
  const Root$a = styledComponents.styled(Layer)`
4327
4337
  pointer-events: none;
4328
4338
  max-width: ${({ $maxWidth }) => $maxWidth}px;
4329
- `, Tooltip = react.forwardRef(function(props, ref) {
4339
+ `, Tooltip = react.forwardRef(function(props, forwardedRef) {
4330
4340
  var _a, _b, _c, _d, _e, _f, _g;
4331
4341
  const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
4332
4342
  animate: _animate = !1,
@@ -4345,7 +4355,9 @@ const Root$a = styledComponents.styled(Layer)`
4345
4355
  zOffset = layer.tooltip.zOffset,
4346
4356
  delay,
4347
4357
  ...restProps
4348
- } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), forwardedRef = useForwardedRef(ref), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport", portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = react.useSyncExternalStore(
4358
+ } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport";
4359
+ react.useImperativeHandle(forwardedRef, () => ref.current);
4360
+ const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = react.useSyncExternalStore(
4349
4361
  emptySubscribe,
4350
4362
  () => document.body.offsetWidth,
4351
4363
  // We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
@@ -4455,9 +4467,9 @@ const Root$a = styledComponents.styled(Layer)`
4455
4467
  [update]
4456
4468
  ), setFloating = react.useCallback(
4457
4469
  (node) => {
4458
- forwardedRef.current = node, refs.setFloating(node);
4470
+ ref.current = node, refs.setFloating(node);
4459
4471
  },
4460
- [forwardedRef, refs]
4472
+ [refs]
4461
4473
  ), childRef = childProp == null ? void 0 : childProp.ref, setReference = react.useCallback(
4462
4474
  (node) => {
4463
4475
  typeof childRef == "function" ? childRef(node) : childRef && (childRef.current = node), setReferenceElement(node);
@@ -4591,7 +4603,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4591
4603
  "Meta",
4592
4604
  "Tab",
4593
4605
  "CapsLock"
4594
- ], AUTOCOMPLETE_POPOVER_PLACEMENT = "bottom-start", AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS = ["bottom-start", "top-start"], DEFAULT_RENDER_VALUE = (value, option) => option ? option.value : value, DEFAULT_FILTER_OPTION = (query, option) => option.value.toLowerCase().indexOf(query.toLowerCase()) > -1, InnerAutocomplete = react.forwardRef(function(props, ref) {
4606
+ ], AUTOCOMPLETE_POPOVER_PLACEMENT = "bottom-start", AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS = ["bottom-start", "top-start"], DEFAULT_RENDER_VALUE = (value, option) => option ? option.value : value, DEFAULT_FILTER_OPTION = (query, option) => option.value.toLowerCase().indexOf(query.toLowerCase()) > -1, InnerAutocomplete = react.forwardRef(function(props, forwardedRef) {
4595
4607
  const {
4596
4608
  border: border2 = !0,
4597
4609
  customValidity,
@@ -4630,7 +4642,12 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4630
4642
  }), { activeValue, focused, listFocused, query, value } = state, defaultRenderOption = react.useCallback(
4631
4643
  ({ value: value2 }) => /* @__PURE__ */ jsxRuntime.jsx(Card, { "data-as": "button", padding: paddingProp, radius: 2, tone: "inherit", children: /* @__PURE__ */ jsxRuntime.jsx(Text, { size: fontSize2, textOverflow: "ellipsis", children: value2 }) }),
4632
4644
  [fontSize2, paddingProp]
4633
- ), renderOption = typeof renderOptionProp == "function" ? renderOptionProp : defaultRenderOption, filterOption = typeof filterOptionProp == "function" ? filterOptionProp : DEFAULT_FILTER_OPTION, rootElementRef = react.useRef(null), resultsPopoverElementRef = react.useRef(null), inputElementRef = react.useRef(null), listBoxElementRef = react.useRef(null), listFocusedRef = react.useRef(!1), valueRef = react.useRef(value), valuePropRef = react.useRef(valueProp), popoverMouseWithinRef = react.useRef(!1), forwardedRef = useForwardedRef(ref), listBoxId = `${id}-listbox`, options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY, padding = useArrayProp(paddingProp), currentOption = react.useMemo(
4645
+ ), renderOption = typeof renderOptionProp == "function" ? renderOptionProp : defaultRenderOption, filterOption = typeof filterOptionProp == "function" ? filterOptionProp : DEFAULT_FILTER_OPTION, rootElementRef = react.useRef(null), resultsPopoverElementRef = react.useRef(null), inputElementRef = react.useRef(null), listBoxElementRef = react.useRef(null), listFocusedRef = react.useRef(!1), valueRef = react.useRef(value), valuePropRef = react.useRef(valueProp), popoverMouseWithinRef = react.useRef(!1);
4646
+ react.useImperativeHandle(
4647
+ forwardedRef,
4648
+ () => inputElementRef.current
4649
+ );
4650
+ const listBoxId = `${id}-listbox`, options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY, padding = useArrayProp(paddingProp), currentOption = react.useMemo(
4634
4651
  () => value !== null ? options.find((o) => o.value === value) : void 0,
4635
4652
  [options, value]
4636
4653
  ), filteredOptions = react.useMemo(
@@ -4734,12 +4751,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4734
4751
  }
4735
4752
  }
4736
4753
  }, [activeValue, filteredOptions]);
4737
- const setRef = react.useCallback(
4738
- (el) => {
4739
- inputElementRef.current = el, forwardedRef.current = el;
4740
- },
4741
- [forwardedRef]
4742
- ), clearButton = react.useMemo(() => {
4754
+ const clearButton = react.useMemo(() => {
4743
4755
  if (!loading && !disabled && value)
4744
4756
  return {
4745
4757
  "aria-label": "Clear",
@@ -4814,7 +4826,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4814
4826
  prefix,
4815
4827
  radius,
4816
4828
  readOnly,
4817
- ref: setRef,
4829
+ ref: inputElementRef,
4818
4830
  role: "combobox",
4819
4831
  spellCheck: !1,
4820
4832
  suffix: suffix || openButtonNode,
@@ -5076,13 +5088,13 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5076
5088
  `, DialogFooter = styledComponents.styled(Box)`
5077
5089
  position: relative;
5078
5090
  z-index: 3;
5079
- `, DialogCard = react.forwardRef(function(props, ref) {
5091
+ `, DialogCard = react.forwardRef(function(props, forwardedRef) {
5080
5092
  var _a;
5081
5093
  const {
5082
5094
  __unstable_autoFocus: autoFocus,
5083
5095
  __unstable_hideCloseButton: hideCloseButton,
5084
5096
  children,
5085
- contentRef,
5097
+ contentRef: forwardedContentRef,
5086
5098
  footer,
5087
5099
  header,
5088
5100
  id,
@@ -5093,10 +5105,13 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5093
5105
  scheme,
5094
5106
  shadow: shadowProp,
5095
5107
  width: widthProp
5096
- } = 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), forwardedRef = useForwardedRef(ref), [rootElement, setRootElement] = react.useState(null), localContentRef = react.useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
5097
- react.useEffect(() => {
5098
- autoFocus && forwardedRef.current && focusFirstDescendant(forwardedRef.current);
5099
- }, [autoFocus, forwardedRef]), useGlobalKeyDown(
5108
+ } = 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;
5109
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useImperativeHandle(
5110
+ forwardedContentRef,
5111
+ () => contentRef.current
5112
+ ), react.useEffect(() => {
5113
+ autoFocus && ref.current && focusFirstDescendant(ref.current);
5114
+ }, [autoFocus, ref]), useGlobalKeyDown(
5100
5115
  react.useCallback(
5101
5116
  (event) => {
5102
5117
  if (!isTopLayer || !onClose) return;
@@ -5116,17 +5131,9 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5116
5131
  ),
5117
5132
  [rootElement]
5118
5133
  );
5119
- const setRef = react.useCallback(
5120
- (el) => {
5121
- setRootElement(el), forwardedRef.current = el;
5122
- },
5123
- [forwardedRef]
5124
- ), setContentRef = react.useCallback(
5125
- (el) => {
5126
- localContentRef.current = el, typeof contentRef == "function" ? contentRef(el) : contentRef && (contentRef.current = el);
5127
- },
5128
- [contentRef]
5129
- );
5134
+ const setRef = react.useCallback((el) => {
5135
+ setRootElement(el), ref.current = el;
5136
+ }, []);
5130
5137
  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: [
5131
5138
  showHeader && /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(Flex, { align: "center", padding: 3, children: [
5132
5139
  /* @__PURE__ */ jsxRuntime.jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsxRuntime.jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
@@ -5142,7 +5149,7 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5142
5149
  }
5143
5150
  ) })
5144
5151
  ] }) }),
5145
- /* @__PURE__ */ jsxRuntime.jsx(DialogContent, { flex: 1, ref: setContentRef, tabIndex: -1, children }),
5152
+ /* @__PURE__ */ jsxRuntime.jsx(DialogContent, { flex: 1, ref: contentRef, tabIndex: -1, children }),
5146
5153
  footer && /* @__PURE__ */ jsxRuntime.jsx(DialogFooter, { children: footer })
5147
5154
  ] }) }) });
5148
5155
  }), Dialog = react.forwardRef(function(props, ref) {
@@ -5418,7 +5425,7 @@ function useMenuController(props) {
5418
5425
  const Root$5 = styledComponents.styled(Box)`
5419
5426
  outline: none;
5420
5427
  overflow: auto;
5421
- `, Menu = react.forwardRef(function(props, ref) {
5428
+ `, Menu = react.forwardRef(function(props, forwardedRef) {
5422
5429
  const {
5423
5430
  children,
5424
5431
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -5436,7 +5443,9 @@ const Root$5 = styledComponents.styled(Box)`
5436
5443
  shouldFocus = props.focusFirst && "first" || props.focusLast && "last" || null,
5437
5444
  space = 1,
5438
5445
  ...restProps
5439
- } = props, forwardedRef = useForwardedRef(ref), { isTopLayer } = useLayer(), {
5446
+ } = props, ref = react.useRef(null);
5447
+ react.useImperativeHandle(forwardedRef, () => ref.current);
5448
+ const { isTopLayer } = useLayer(), {
5440
5449
  activeElement,
5441
5450
  activeIndex,
5442
5451
  handleItemMouseEnter,
@@ -5447,9 +5456,9 @@ const Root$5 = styledComponents.styled(Box)`
5447
5456
  setRootElement
5448
5457
  } = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = react.useCallback(
5449
5458
  (el) => {
5450
- setRootElement(el), forwardedRef.current = el;
5459
+ setRootElement(el), ref.current = el;
5451
5460
  },
5452
- [forwardedRef, setRootElement]
5461
+ [setRootElement]
5453
5462
  );
5454
5463
  react.useEffect(() => {
5455
5464
  onItemSelect && onItemSelect(activeIndex);
@@ -5884,9 +5893,9 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
5884
5893
  onItemClick,
5885
5894
  onItemMouseEnter = menu.onMouseEnter,
5886
5895
  onItemMouseLeave = menu.onMouseLeave
5887
- } = menu, [rootElement, setRootElement] = react.useState(null), active = !!activeElement && activeElement === rootElement;
5888
- react.useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp]);
5889
- const ref = useForwardedRef(forwardedRef), handleClick = react.useCallback(
5896
+ } = menu, [rootElement, setRootElement] = react.useState(null), active = !!activeElement && activeElement === rootElement, ref = react.useRef(null);
5897
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp]);
5898
+ const handleClick = react.useCallback(
5890
5899
  (event) => {
5891
5900
  disabled || (onClick && onClick(event), onItemClick && onItemClick());
5892
5901
  },
@@ -5902,12 +5911,9 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
5902
5911
  paddingLeft
5903
5912
  }),
5904
5913
  [padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft]
5905
- ), hotkeysFontSize = useArrayProp(fontSize2).map((s) => s - 1), setRef = react.useCallback(
5906
- (el) => {
5907
- ref.current = el, setRootElement(el);
5908
- },
5909
- [ref]
5910
- );
5914
+ ), hotkeysFontSize = useArrayProp(fontSize2).map((s) => s - 1), setRef = react.useCallback((el) => {
5915
+ ref.current = el, setRootElement(el);
5916
+ }, []);
5911
5917
  return /* @__PURE__ */ jsxRuntime.jsxs(
5912
5918
  Selectable,
5913
5919
  {
@@ -6046,16 +6052,21 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
6046
6052
  padding = 2,
6047
6053
  selected,
6048
6054
  ...restProps
6049
- } = props, elementRef = react.useRef(null), focusedRef = react.useRef(!1), handleBlur = react.useCallback(() => {
6055
+ } = props, ref = react.useRef(null), focusedRef = react.useRef(!1);
6056
+ react.useImperativeHandle(
6057
+ forwardedRef,
6058
+ () => ref.current
6059
+ );
6060
+ const handleBlur = react.useCallback(() => {
6050
6061
  focusedRef.current = !1;
6051
6062
  }, []), handleFocus = react.useCallback(
6052
6063
  (event) => {
6053
6064
  focusedRef.current = !0, onFocus && onFocus(event);
6054
6065
  },
6055
6066
  [onFocus]
6056
- ), ref = useForwardedRef(forwardedRef);
6067
+ );
6057
6068
  return react.useEffect(() => {
6058
- focused && !focusedRef.current && (elementRef.current && elementRef.current.focus(), focusedRef.current = !0);
6069
+ focused && !focusedRef.current && (ref.current && ref.current.focus(), focusedRef.current = !0);
6059
6070
  }, [focused]), /* @__PURE__ */ jsxRuntime.jsx(
6060
6071
  CustomButton,
6061
6072
  {
@@ -6070,9 +6081,7 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
6070
6081
  onBlur: handleBlur,
6071
6082
  onFocus: handleFocus,
6072
6083
  padding,
6073
- ref: (el) => {
6074
- elementRef.current = el, ref.current = el;
6075
- },
6084
+ ref,
6076
6085
  role: "tab",
6077
6086
  selected,
6078
6087
  tabIndex: selected ? 0 : -1,
@@ -6355,9 +6364,12 @@ function _focusItemElement(el) {
6355
6364
  }
6356
6365
  }
6357
6366
  const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalScopedContext(key, null), Tree = react.memo(
6358
- react.forwardRef(function(props, ref) {
6359
- const { children, space = 1, onFocus, ...restProps } = props, forwardedRef = useForwardedRef(ref), [focusedElement, setFocusedElement] = react.useState(null), focusedElementRef = react.useRef(focusedElement), path = react.useMemo(() => [], []), [itemElements, setItemElements] = react.useState([]), [state, setState] = react.useState({}), stateRef = react.useRef(state);
6360
- react.useEffect(() => {
6367
+ react.forwardRef(function(props, forwardedRef) {
6368
+ const { children, space = 1, onFocus, ...restProps } = props, ref = react.useRef(null), [focusedElement, setFocusedElement] = react.useState(null), focusedElementRef = react.useRef(focusedElement), path = react.useMemo(() => [], []), [itemElements, setItemElements] = react.useState([]), [state, setState] = react.useState({}), stateRef = react.useRef(state);
6369
+ react.useImperativeHandle(
6370
+ forwardedRef,
6371
+ () => ref.current
6372
+ ), react.useEffect(() => {
6361
6373
  focusedElementRef.current = focusedElement;
6362
6374
  }, [focusedElement]), react.useEffect(() => {
6363
6375
  stateRef.current = state;
@@ -6451,12 +6463,12 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6451
6463
  [onFocus]
6452
6464
  );
6453
6465
  return react.useEffect(() => {
6454
- if (!forwardedRef.current) return;
6466
+ if (!ref.current) return;
6455
6467
  const _itemElements = Array.from(
6456
- forwardedRef.current.querySelectorAll('[data-ui="TreeItem"]')
6468
+ ref.current.querySelectorAll('[data-ui="TreeItem"]')
6457
6469
  );
6458
6470
  setItemElements(_itemElements);
6459
- }, [children, forwardedRef]), /* @__PURE__ */ jsxRuntime.jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
6471
+ }, [children, ref]), /* @__PURE__ */ jsxRuntime.jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
6460
6472
  Stack,
6461
6473
  {
6462
6474
  as: "ul",
@@ -6464,7 +6476,7 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6464
6476
  ...restProps,
6465
6477
  onFocus: handleFocus,
6466
6478
  onKeyDown: handleKeyDown,
6467
- ref: forwardedRef,
6479
+ ref,
6468
6480
  role: "tree",
6469
6481
  space,
6470
6482
  children