@sanity/ui 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2686,6 +2686,13 @@ export declare function useElementSize(element: HTMLElement | null): ElementSize
2686
2686
 
2687
2687
  /**
2688
2688
  * @beta
2689
+ * @deprecated use `useImperativeHandle` instead
2690
+ * @example
2691
+ * ```diff
2692
+ * -const ref = useForwardedRef(forwardedRef)
2693
+ * +const ref = useRef(null)
2694
+ * +useImperativeHandle(forwardedRef, () => ref.current)
2695
+ * ```
2689
2696
  */
2690
2697
  export declare function useForwardedRef<T>(
2691
2698
  ref: React.ForwardedRef<T>,
package/dist/index.d.ts CHANGED
@@ -2686,6 +2686,13 @@ export declare function useElementSize(element: HTMLElement | null): ElementSize
2686
2686
 
2687
2687
  /**
2688
2688
  * @beta
2689
+ * @deprecated use `useImperativeHandle` instead
2690
+ * @example
2691
+ * ```diff
2692
+ * -const ref = useForwardedRef(forwardedRef)
2693
+ * +const ref = useRef(null)
2694
+ * +useImperativeHandle(forwardedRef, () => ref.current)
2695
+ * ```
2689
2696
  */
2690
2697
  export declare function useForwardedRef<T>(
2691
2698
  ref: React.ForwardedRef<T>,
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { buildTheme, createColorTheme as createColorTheme$1, hexToRgb as hexToRgb$1, hslToRgb as hslToRgb$1, multiply as multiply$1, parseColor as parseColor$1, rgbToHex as rgbToHex$1, rgbToHsl as rgbToHsl$1, rgba as rgba$1, screen as screen$1, getTheme_v2, getScopedTheme } from "@sanity/ui/theme";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useLayoutEffect, forwardRef, useId, useCallback, cloneElement, isValidElement, createElement, Component, memo, useReducer, Children, Fragment as Fragment$1, startTransition } from "react";
3
+ import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useImperativeHandle, forwardRef, useId, useCallback, cloneElement, isValidElement, createElement, Component, memo, useReducer, Children, Fragment as Fragment$1, startTransition } from "react";
4
4
  import ReactIs, { isElement as isElement$1, isFragment, isValidElementType } from "react-is";
5
5
  import { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css, styled, keyframes } from "styled-components";
6
6
  import { SpinnerIcon, CheckmarkIcon, RemoveIcon, ChevronDownIcon, CloseIcon, ChevronRightIcon, ToggleArrowRightIcon } from "@sanity/icons";
@@ -624,12 +624,9 @@ function getServerSnapshot() {
624
624
  function usePrefersReducedMotion() {
625
625
  return useSyncExternalStore(subscribe$1, getSnapshot, getServerSnapshot);
626
626
  }
627
- const useIsomorphicEffect = typeof window < "u" ? useLayoutEffect : useEffect;
628
627
  function useForwardedRef(ref) {
629
628
  const innerRef = useRef(null);
630
- return useIsomorphicEffect(() => {
631
- ref && (typeof ref == "function" ? ref(innerRef.current) : ref.current = innerRef.current);
632
- }), innerRef;
629
+ return useImperativeHandle(ref, () => innerRef.current), innerRef;
633
630
  }
634
631
  function useCustomValidity(ref, customValidity) {
635
632
  useEffect(() => {
@@ -2377,10 +2374,13 @@ const Root$r = styled.div(checkboxBaseStyles), Input$5 = styled.input(inputEleme
2377
2374
  readOnly,
2378
2375
  style,
2379
2376
  ...restProps
2380
- } = props, ref = useForwardedRef(forwardedRef);
2381
- return useCustomValidity(ref, customValidity), useEffect(() => {
2377
+ } = props, ref = useRef(null);
2378
+ return useImperativeHandle(
2379
+ forwardedRef,
2380
+ () => ref.current
2381
+ ), useEffect(() => {
2382
2382
  ref.current && (ref.current.indeterminate = indeterminate || !1);
2383
- }, [indeterminate, ref]), /* @__PURE__ */ jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2383
+ }, [indeterminate]), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2384
2384
  /* @__PURE__ */ jsx(
2385
2385
  Input$5,
2386
2386
  {
@@ -2855,16 +2855,15 @@ function findMinBreakpoints(media, width) {
2855
2855
  media[i] <= width && ret.push(i);
2856
2856
  return ret;
2857
2857
  }
2858
- const ElementQuery = forwardRef(function(props, ref) {
2859
- const theme = useTheme_v2(), { children, media = theme.media, ...restProps } = props, forwardedRef = useForwardedRef(ref), [element, setElement] = useState(null), elementSize = useElementSize(element), width = useMemo(() => {
2858
+ const ElementQuery = forwardRef(function(props, forwardedRef) {
2859
+ const theme = useTheme_v2(), { children, media = theme.media, ...restProps } = props, ref = useRef(null), [element, setElement] = useState(null), elementSize = useElementSize(element), width = useMemo(() => {
2860
2860
  var _a;
2861
2861
  return (_a = elementSize == null ? void 0 : elementSize.border.width) != null ? _a : window.innerWidth;
2862
- }, [elementSize]), max = useMemo(() => findMaxBreakpoints(media, width), [media, width]), min = useMemo(() => findMinBreakpoints(media, width), [media, width]), setRef = useCallback(
2863
- (el) => {
2864
- forwardedRef.current = el, setElement(el);
2865
- },
2866
- [forwardedRef]
2867
- );
2862
+ }, [elementSize]), max = useMemo(() => findMaxBreakpoints(media, width), [media, width]), min = useMemo(() => findMinBreakpoints(media, width), [media, width]);
2863
+ useImperativeHandle(forwardedRef, () => ref.current);
2864
+ const setRef = useCallback((el) => {
2865
+ ref.current = el, setElement(el);
2866
+ }, []);
2868
2867
  return /* @__PURE__ */ jsx(
2869
2868
  "div",
2870
2869
  {
@@ -3024,30 +3023,20 @@ function LayerProvider(props) {
3024
3023
  );
3025
3024
  return /* @__PURE__ */ jsx(LayerContext.Provider, { value, children });
3026
3025
  }
3027
- const Root$j = styled.div({ position: "relative" }), LayerChildren = forwardRef(function(props, ref) {
3028
- const { children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps } = props, { zIndex, isTopLayer } = useLayer(), lastFocusedRef = useRef(null), forwardedRef = useForwardedRef(ref), isTopLayerRef = useRef(isTopLayer);
3029
- useEffect(() => {
3026
+ const Root$j = styled.div({ position: "relative" }), LayerChildren = forwardRef(function(props, forwardedRef) {
3027
+ const { children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps } = props, { zIndex, isTopLayer } = useLayer(), lastFocusedRef = useRef(null), ref = useRef(null), isTopLayerRef = useRef(isTopLayer);
3028
+ useImperativeHandle(forwardedRef, () => ref.current), useEffect(() => {
3030
3029
  isTopLayerRef.current !== isTopLayer && isTopLayer && (onActivate == null || onActivate({ activeElement: lastFocusedRef.current })), isTopLayerRef.current = isTopLayer;
3031
3030
  }, [isTopLayer, onActivate]);
3032
3031
  const handleFocus = useCallback(
3033
3032
  (event) => {
3034
3033
  onFocus == null || onFocus(event);
3035
- const rootElement = forwardedRef.current, target = document.activeElement;
3034
+ const rootElement = ref.current, target = document.activeElement;
3036
3035
  !isTopLayer || !rootElement || !target || isHTMLElement(target) && containsOrEqualsElement(rootElement, target) && (lastFocusedRef.current = target);
3037
3036
  },
3038
- [forwardedRef, isTopLayer, onFocus]
3039
- );
3040
- return /* @__PURE__ */ jsx(
3041
- Root$j,
3042
- {
3043
- ...restProps,
3044
- "data-ui": "Layer",
3045
- onFocus: handleFocus,
3046
- ref: forwardedRef,
3047
- style: { ...style, zIndex },
3048
- children
3049
- }
3037
+ [isTopLayer, onFocus]
3050
3038
  );
3039
+ return /* @__PURE__ */ jsx(Root$j, { ...restProps, "data-ui": "Layer", onFocus: handleFocus, ref, style: { ...style, zIndex }, children });
3051
3040
  }), Layer = forwardRef(function(props, ref) {
3052
3041
  const { children, zOffset = 1, ...restProps } = props;
3053
3042
  return /* @__PURE__ */ jsx(LayerProvider, { zOffset, children: /* @__PURE__ */ jsx(LayerChildren, { ...restProps, ref, children }) });
@@ -3113,15 +3102,15 @@ const emptySubscribe$1 = () => () => {
3113
3102
  position: absolute;
3114
3103
  left: 0;
3115
3104
  right: 0;
3116
- `, VirtualList = forwardRef(function(props, ref) {
3117
- const { as = "div", gap = 0, getItemKey, items = [], onChange, renderItem, ...restProps } = props, { space } = useTheme_v2(), forwardedRef = useForwardedRef(ref), wrapperRef = useRef(null), [scrollTop, setScrollTop] = useState(0), [scrollHeight, setScrollHeight] = useState(0), [itemHeight, setItemHeight] = useState(-1);
3118
- useEffect(() => {
3105
+ `, VirtualList = forwardRef(function(props, forwardedRef) {
3106
+ const { as = "div", gap = 0, getItemKey, items = [], onChange, renderItem, ...restProps } = props, { space } = useTheme_v2(), ref = useRef(null), wrapperRef = useRef(null), [scrollTop, setScrollTop] = useState(0), [scrollHeight, setScrollHeight] = useState(0), [itemHeight, setItemHeight] = useState(-1);
3107
+ useImperativeHandle(forwardedRef, () => ref.current), useEffect(() => {
3119
3108
  if (!wrapperRef.current) return;
3120
3109
  const firstElement = wrapperRef.current.firstChild;
3121
3110
  firstElement instanceof HTMLElement && setItemHeight(firstElement.offsetHeight);
3122
3111
  }, [renderItem]), useEffect(() => {
3123
- if (!forwardedRef.current) return;
3124
- let _scrollEl = forwardedRef.current.parentNode;
3112
+ if (!ref.current) return;
3113
+ let _scrollEl = ref.current.parentNode;
3125
3114
  for (; _scrollEl && !_isScrollable(_scrollEl); )
3126
3115
  _scrollEl = _scrollEl.parentNode;
3127
3116
  if (_scrollEl) {
@@ -3146,7 +3135,7 @@ const emptySubscribe$1 = () => () => {
3146
3135
  return window.addEventListener("scroll", handleScroll, { passive: !0 }), window.addEventListener("resize", handleResize), setScrollHeight(window.innerHeight), handleScroll(), () => {
3147
3136
  window.removeEventListener("scroll", handleScroll), window.removeEventListener("resize", handleResize);
3148
3137
  };
3149
- }, [forwardedRef]);
3138
+ }, []);
3150
3139
  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;
3151
3140
  useEffect(() => {
3152
3141
  onChange && onChange({ fromIndex, gap: space[gap], itemHeight, scrollHeight, scrollTop, toIndex });
@@ -3155,7 +3144,7 @@ const emptySubscribe$1 = () => () => {
3155
3144
  const itemIndex = fromIndex + _itemIndex, node = renderItem(item), key2 = getItemKey ? getItemKey(item, itemIndex) : itemIndex;
3156
3145
  return /* @__PURE__ */ jsx(ItemWrapper, { style: { top: itemIndex * (itemHeight + space[gap]) }, children: node }, key2);
3157
3146
  }), [fromIndex, gap, getItemKey, itemHeight, items, renderItem, space, toIndex]), wrapperStyle = useMemo(() => ({ height }), [height]);
3158
- return /* @__PURE__ */ jsx(Root$h, { as, "data-ui": "VirtualList", ...restProps, ref: forwardedRef, children: /* @__PURE__ */ jsx("div", { ref: wrapperRef, style: wrapperStyle, children }) });
3147
+ return /* @__PURE__ */ jsx(Root$h, { as, "data-ui": "VirtualList", ...restProps, ref, children: /* @__PURE__ */ jsx("div", { ref: wrapperRef, style: wrapperStyle, children }) });
3159
3148
  }), 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 = {
3160
3149
  top: ["bottom", "left", "right"],
3161
3150
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -3301,7 +3290,7 @@ const MotionCard$1 = styled(motion(Card))`
3301
3290
  );
3302
3291
  PopoverCard.displayName = "PopoverCard";
3303
3292
  const Popover = memo(
3304
- forwardRef(function(props, ref) {
3293
+ forwardRef(function(props, forwardedRef) {
3305
3294
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3306
3295
  const { container, layer } = useTheme_v2(), boundaryElementContext = useBoundaryElement(), {
3307
3296
  __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
@@ -3333,7 +3322,12 @@ const Popover = memo(
3333
3322
  zOffset: zOffsetProp = layer.popover.zOffset,
3334
3323
  updateRef,
3335
3324
  ...restProps
3336
- } = 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 = useRef(null), rootBoundary = "viewport", mediaIndex = useMediaIndex(), boundaryWidth = constrainSize || preventOverflow ? boundarySize == null ? void 0 : boundarySize.width : void 0, width = calcCurrentWidth({
3325
+ } = 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 = useRef(null), arrowRef = useRef(null), rootBoundary = "viewport";
3326
+ useImperativeHandle(
3327
+ forwardedRef,
3328
+ () => ref.current
3329
+ );
3330
+ const mediaIndex = useMediaIndex(), boundaryWidth = constrainSize || preventOverflow ? boundarySize == null ? void 0 : boundarySize.width : void 0, width = calcCurrentWidth({
3337
3331
  container,
3338
3332
  mediaIndex,
3339
3333
  width: widthArrayProp
@@ -3347,11 +3341,11 @@ const Popover = memo(
3347
3341
  }, [maxWidth]);
3348
3342
  const referenceWidthRef = useRef();
3349
3343
  useEffect(() => {
3350
- const floatingElement = forwardedRef.current;
3344
+ const floatingElement = ref.current;
3351
3345
  if (!open || !floatingElement) return;
3352
3346
  const referenceWidth = referenceWidthRef.current;
3353
3347
  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`);
3354
- }, [width, forwardedRef, matchReferenceWidth, maxWidth, open]);
3348
+ }, [width, matchReferenceWidth, maxWidth, open]);
3355
3349
  const middleware = useMemo(() => {
3356
3350
  const ret = [];
3357
3351
  return (constrainSize || preventOverflow) && ret.push(
@@ -3413,9 +3407,9 @@ const Popover = memo(
3413
3407
  arrowRef.current = arrowEl;
3414
3408
  }, []), setFloating = useCallback(
3415
3409
  (node) => {
3416
- forwardedRef.current = node, refs.setFloating(node);
3410
+ ref.current = node, refs.setFloating(node);
3417
3411
  },
3418
- [forwardedRef, refs]
3412
+ [refs]
3419
3413
  ), setReference = useCallback(
3420
3414
  (node) => {
3421
3415
  refs.setReference(node);
@@ -3588,8 +3582,11 @@ function inputElementStyle(props) {
3588
3582
  `;
3589
3583
  }
3590
3584
  const Root$g = styled.div(radioBaseStyle), Input$4 = styled.input(inputElementStyle), Radio = forwardRef(function(props, forwardedRef) {
3591
- const { className, disabled, style, customValidity, readOnly, ...restProps } = props, ref = useForwardedRef(forwardedRef);
3592
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$g, { className, "data-ui": "Radio", style, children: [
3585
+ const { className, disabled, style, customValidity, readOnly, ...restProps } = props, ref = useRef(null);
3586
+ return useImperativeHandle(
3587
+ forwardedRef,
3588
+ () => ref.current
3589
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$g, { className, "data-ui": "Radio", style, children: [
3593
3590
  /* @__PURE__ */ jsx(
3594
3591
  Input$4,
3595
3592
  {
@@ -3750,8 +3747,11 @@ const selectStyle = {
3750
3747
  readOnly,
3751
3748
  space = 3,
3752
3749
  ...restProps
3753
- } = props, ref = useForwardedRef(forwardedRef);
3754
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$f, { "data-ui": "Select", children: [
3750
+ } = props, ref = useRef(null);
3751
+ return useImperativeHandle(
3752
+ forwardedRef,
3753
+ () => ref.current
3754
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$f, { "data-ui": "Select", children: [
3755
3755
  /* @__PURE__ */ jsx(
3756
3756
  Input$3,
3757
3757
  {
@@ -3945,10 +3945,13 @@ function switchThumbStyles(props) {
3945
3945
  `;
3946
3946
  }
3947
3947
  const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInputStyles), Representation = styled.span(switchRepresentationStyles), Track = styled.span(switchTrackStyles), Thumb = styled.span(switchThumbStyles), Switch = forwardRef(function(props, forwardedRef) {
3948
- const { checked, className, disabled, indeterminate, readOnly, style, ...restProps } = props, ref = useForwardedRef(forwardedRef);
3949
- return useEffect(() => {
3948
+ const { checked, className, disabled, indeterminate, readOnly, style, ...restProps } = props, ref = useRef(null);
3949
+ return useImperativeHandle(
3950
+ forwardedRef,
3951
+ () => ref.current
3952
+ ), useEffect(() => {
3950
3953
  ref.current && (ref.current.indeterminate = indeterminate || !1);
3951
- }, [indeterminate, ref]), /* @__PURE__ */ jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3954
+ }, [indeterminate]), /* @__PURE__ */ jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3952
3955
  /* @__PURE__ */ jsx(
3953
3956
  Input$2,
3954
3957
  {
@@ -3987,8 +3990,11 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
3987
3990
  radius = 2,
3988
3991
  weight,
3989
3992
  ...restProps
3990
- } = props, ref = useForwardedRef(forwardedRef), rootTheme = useRootTheme();
3991
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsx(Root$c, { "data-ui": "TextArea", children: /* @__PURE__ */ jsxs(InputRoot$1, { children: [
3993
+ } = props, ref = useRef(null), rootTheme = useRootTheme();
3994
+ return useImperativeHandle(
3995
+ forwardedRef,
3996
+ () => ref.current
3997
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsx(Root$c, { "data-ui": "TextArea", children: /* @__PURE__ */ jsxs(InputRoot$1, { children: [
3992
3998
  /* @__PURE__ */ jsx(
3993
3999
  Input$1,
3994
4000
  {
@@ -4083,8 +4089,11 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
4083
4089
  type = "text",
4084
4090
  weight,
4085
4091
  ...restProps
4086
- } = 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;
4087
- useCustomValidity(ref, customValidity);
4092
+ } = props, ref = 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;
4093
+ useImperativeHandle(
4094
+ forwardedRef,
4095
+ () => ref.current
4096
+ ), useCustomValidity(ref, customValidity);
4088
4097
  const handleClearMouseDown = useCallback((event) => {
4089
4098
  event.preventDefault(), event.stopPropagation();
4090
4099
  }, []), handleClearClick = useCallback(
@@ -4331,7 +4340,7 @@ function TooltipDelayGroupProvider(props) {
4331
4340
  const Root$a = styled(Layer)`
4332
4341
  pointer-events: none;
4333
4342
  max-width: ${({ $maxWidth }) => $maxWidth}px;
4334
- `, Tooltip = forwardRef(function(props, ref) {
4343
+ `, Tooltip = forwardRef(function(props, forwardedRef) {
4335
4344
  var _a, _b, _c, _d, _e, _f, _g;
4336
4345
  const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
4337
4346
  animate: _animate = !1,
@@ -4350,7 +4359,9 @@ const Root$a = styled(Layer)`
4350
4359
  zOffset = layer.tooltip.zOffset,
4351
4360
  delay,
4352
4361
  ...restProps
4353
- } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), forwardedRef = useForwardedRef(ref), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport", portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = useSyncExternalStore(
4362
+ } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport";
4363
+ useImperativeHandle(forwardedRef, () => ref.current);
4364
+ const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = useSyncExternalStore(
4354
4365
  emptySubscribe,
4355
4366
  () => document.body.offsetWidth,
4356
4367
  // We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
@@ -4460,9 +4471,9 @@ const Root$a = styled(Layer)`
4460
4471
  [update]
4461
4472
  ), setFloating = useCallback(
4462
4473
  (node) => {
4463
- forwardedRef.current = node, refs.setFloating(node);
4474
+ ref.current = node, refs.setFloating(node);
4464
4475
  },
4465
- [forwardedRef, refs]
4476
+ [refs]
4466
4477
  ), childRef = childProp == null ? void 0 : childProp.ref, setReference = useCallback(
4467
4478
  (node) => {
4468
4479
  typeof childRef == "function" ? childRef(node) : childRef && (childRef.current = node), setReferenceElement(node);
@@ -4596,7 +4607,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4596
4607
  "Meta",
4597
4608
  "Tab",
4598
4609
  "CapsLock"
4599
- ], 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 = forwardRef(function(props, ref) {
4610
+ ], 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 = forwardRef(function(props, forwardedRef) {
4600
4611
  const {
4601
4612
  border: border2 = !0,
4602
4613
  customValidity,
@@ -4635,7 +4646,12 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4635
4646
  }), { activeValue, focused, listFocused, query, value } = state, defaultRenderOption = useCallback(
4636
4647
  ({ value: value2 }) => /* @__PURE__ */ jsx(Card, { "data-as": "button", padding: paddingProp, radius: 2, tone: "inherit", children: /* @__PURE__ */ jsx(Text, { size: fontSize2, textOverflow: "ellipsis", children: value2 }) }),
4637
4648
  [fontSize2, paddingProp]
4638
- ), renderOption = typeof renderOptionProp == "function" ? renderOptionProp : defaultRenderOption, filterOption = typeof filterOptionProp == "function" ? filterOptionProp : DEFAULT_FILTER_OPTION, rootElementRef = useRef(null), resultsPopoverElementRef = useRef(null), inputElementRef = useRef(null), listBoxElementRef = useRef(null), listFocusedRef = useRef(!1), valueRef = useRef(value), valuePropRef = useRef(valueProp), popoverMouseWithinRef = useRef(!1), forwardedRef = useForwardedRef(ref), listBoxId = `${id}-listbox`, options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY, padding = useArrayProp(paddingProp), currentOption = useMemo(
4649
+ ), renderOption = typeof renderOptionProp == "function" ? renderOptionProp : defaultRenderOption, filterOption = typeof filterOptionProp == "function" ? filterOptionProp : DEFAULT_FILTER_OPTION, rootElementRef = useRef(null), resultsPopoverElementRef = useRef(null), inputElementRef = useRef(null), listBoxElementRef = useRef(null), listFocusedRef = useRef(!1), valueRef = useRef(value), valuePropRef = useRef(valueProp), popoverMouseWithinRef = useRef(!1);
4650
+ useImperativeHandle(
4651
+ forwardedRef,
4652
+ () => inputElementRef.current
4653
+ );
4654
+ const listBoxId = `${id}-listbox`, options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY, padding = useArrayProp(paddingProp), currentOption = useMemo(
4639
4655
  () => value !== null ? options.find((o) => o.value === value) : void 0,
4640
4656
  [options, value]
4641
4657
  ), filteredOptions = useMemo(
@@ -4739,12 +4755,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4739
4755
  }
4740
4756
  }
4741
4757
  }, [activeValue, filteredOptions]);
4742
- const setRef = useCallback(
4743
- (el) => {
4744
- inputElementRef.current = el, forwardedRef.current = el;
4745
- },
4746
- [forwardedRef]
4747
- ), clearButton = useMemo(() => {
4758
+ const clearButton = useMemo(() => {
4748
4759
  if (!loading && !disabled && value)
4749
4760
  return {
4750
4761
  "aria-label": "Clear",
@@ -4819,7 +4830,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4819
4830
  prefix,
4820
4831
  radius,
4821
4832
  readOnly,
4822
- ref: setRef,
4833
+ ref: inputElementRef,
4823
4834
  role: "combobox",
4824
4835
  spellCheck: !1,
4825
4836
  suffix: suffix || openButtonNode,
@@ -5081,13 +5092,13 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5081
5092
  `, DialogFooter = styled(Box)`
5082
5093
  position: relative;
5083
5094
  z-index: 3;
5084
- `, DialogCard = forwardRef(function(props, ref) {
5095
+ `, DialogCard = forwardRef(function(props, forwardedRef) {
5085
5096
  var _a;
5086
5097
  const {
5087
5098
  __unstable_autoFocus: autoFocus,
5088
5099
  __unstable_hideCloseButton: hideCloseButton,
5089
5100
  children,
5090
- contentRef,
5101
+ contentRef: forwardedContentRef,
5091
5102
  footer,
5092
5103
  header,
5093
5104
  id,
@@ -5098,10 +5109,13 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5098
5109
  scheme,
5099
5110
  shadow: shadowProp,
5100
5111
  width: widthProp
5101
- } = 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] = useState(null), localContentRef = useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
5102
- useEffect(() => {
5103
- autoFocus && forwardedRef.current && focusFirstDescendant(forwardedRef.current);
5104
- }, [autoFocus, forwardedRef]), useGlobalKeyDown(
5112
+ } = 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 = useRef(null), [rootElement, setRootElement] = useState(null), contentRef = useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
5113
+ useImperativeHandle(forwardedRef, () => ref.current), useImperativeHandle(
5114
+ forwardedContentRef,
5115
+ () => contentRef.current
5116
+ ), useEffect(() => {
5117
+ autoFocus && ref.current && focusFirstDescendant(ref.current);
5118
+ }, [autoFocus, ref]), useGlobalKeyDown(
5105
5119
  useCallback(
5106
5120
  (event) => {
5107
5121
  if (!isTopLayer || !onClose) return;
@@ -5121,17 +5135,9 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5121
5135
  ),
5122
5136
  [rootElement]
5123
5137
  );
5124
- const setRef = useCallback(
5125
- (el) => {
5126
- setRootElement(el), forwardedRef.current = el;
5127
- },
5128
- [forwardedRef]
5129
- ), setContentRef = useCallback(
5130
- (el) => {
5131
- localContentRef.current = el, typeof contentRef == "function" ? contentRef(el) : contentRef && (contentRef.current = el);
5132
- },
5133
- [contentRef]
5134
- );
5138
+ const setRef = useCallback((el) => {
5139
+ setRootElement(el), ref.current = el;
5140
+ }, []);
5135
5141
  return /* @__PURE__ */ jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsx(DialogCardRoot, { radius, ref: setRef, scheme, shadow, children: /* @__PURE__ */ jsxs(DialogLayout, { direction: "column", children: [
5136
5142
  showHeader && /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsxs(Flex, { align: "center", padding: 3, children: [
5137
5143
  /* @__PURE__ */ jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
@@ -5147,7 +5153,7 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5147
5153
  }
5148
5154
  ) })
5149
5155
  ] }) }),
5150
- /* @__PURE__ */ jsx(DialogContent, { flex: 1, ref: setContentRef, tabIndex: -1, children }),
5156
+ /* @__PURE__ */ jsx(DialogContent, { flex: 1, ref: contentRef, tabIndex: -1, children }),
5151
5157
  footer && /* @__PURE__ */ jsx(DialogFooter, { children: footer })
5152
5158
  ] }) }) });
5153
5159
  }), Dialog = forwardRef(function(props, ref) {
@@ -5423,7 +5429,7 @@ function useMenuController(props) {
5423
5429
  const Root$5 = styled(Box)`
5424
5430
  outline: none;
5425
5431
  overflow: auto;
5426
- `, Menu = forwardRef(function(props, ref) {
5432
+ `, Menu = forwardRef(function(props, forwardedRef) {
5427
5433
  const {
5428
5434
  children,
5429
5435
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -5441,7 +5447,9 @@ const Root$5 = styled(Box)`
5441
5447
  shouldFocus = props.focusFirst && "first" || props.focusLast && "last" || null,
5442
5448
  space = 1,
5443
5449
  ...restProps
5444
- } = props, forwardedRef = useForwardedRef(ref), { isTopLayer } = useLayer(), {
5450
+ } = props, ref = useRef(null);
5451
+ useImperativeHandle(forwardedRef, () => ref.current);
5452
+ const { isTopLayer } = useLayer(), {
5445
5453
  activeElement,
5446
5454
  activeIndex,
5447
5455
  handleItemMouseEnter,
@@ -5452,9 +5460,9 @@ const Root$5 = styled(Box)`
5452
5460
  setRootElement
5453
5461
  } = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = useCallback(
5454
5462
  (el) => {
5455
- setRootElement(el), forwardedRef.current = el;
5463
+ setRootElement(el), ref.current = el;
5456
5464
  },
5457
- [forwardedRef, setRootElement]
5465
+ [setRootElement]
5458
5466
  );
5459
5467
  useEffect(() => {
5460
5468
  onItemSelect && onItemSelect(activeIndex);
@@ -5889,9 +5897,9 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
5889
5897
  onItemClick,
5890
5898
  onItemMouseEnter = menu.onMouseEnter,
5891
5899
  onItemMouseLeave = menu.onMouseLeave
5892
- } = menu, [rootElement, setRootElement] = useState(null), active = !!activeElement && activeElement === rootElement;
5893
- useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp]);
5894
- const ref = useForwardedRef(forwardedRef), handleClick = useCallback(
5900
+ } = menu, [rootElement, setRootElement] = useState(null), active = !!activeElement && activeElement === rootElement, ref = useRef(null);
5901
+ useImperativeHandle(forwardedRef, () => ref.current), useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp]);
5902
+ const handleClick = useCallback(
5895
5903
  (event) => {
5896
5904
  disabled || (onClick && onClick(event), onItemClick && onItemClick());
5897
5905
  },
@@ -5907,12 +5915,9 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
5907
5915
  paddingLeft
5908
5916
  }),
5909
5917
  [padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft]
5910
- ), hotkeysFontSize = useArrayProp(fontSize2).map((s) => s - 1), setRef = useCallback(
5911
- (el) => {
5912
- ref.current = el, setRootElement(el);
5913
- },
5914
- [ref]
5915
- );
5918
+ ), hotkeysFontSize = useArrayProp(fontSize2).map((s) => s - 1), setRef = useCallback((el) => {
5919
+ ref.current = el, setRootElement(el);
5920
+ }, []);
5916
5921
  return /* @__PURE__ */ jsxs(
5917
5922
  Selectable,
5918
5923
  {
@@ -6051,16 +6056,21 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
6051
6056
  padding = 2,
6052
6057
  selected,
6053
6058
  ...restProps
6054
- } = props, elementRef = useRef(null), focusedRef = useRef(!1), handleBlur = useCallback(() => {
6059
+ } = props, ref = useRef(null), focusedRef = useRef(!1);
6060
+ useImperativeHandle(
6061
+ forwardedRef,
6062
+ () => ref.current
6063
+ );
6064
+ const handleBlur = useCallback(() => {
6055
6065
  focusedRef.current = !1;
6056
6066
  }, []), handleFocus = useCallback(
6057
6067
  (event) => {
6058
6068
  focusedRef.current = !0, onFocus && onFocus(event);
6059
6069
  },
6060
6070
  [onFocus]
6061
- ), ref = useForwardedRef(forwardedRef);
6071
+ );
6062
6072
  return useEffect(() => {
6063
- focused && !focusedRef.current && (elementRef.current && elementRef.current.focus(), focusedRef.current = !0);
6073
+ focused && !focusedRef.current && (ref.current && ref.current.focus(), focusedRef.current = !0);
6064
6074
  }, [focused]), /* @__PURE__ */ jsx(
6065
6075
  CustomButton,
6066
6076
  {
@@ -6075,9 +6085,7 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
6075
6085
  onBlur: handleBlur,
6076
6086
  onFocus: handleFocus,
6077
6087
  padding,
6078
- ref: (el) => {
6079
- elementRef.current = el, ref.current = el;
6080
- },
6088
+ ref,
6081
6089
  role: "tab",
6082
6090
  selected,
6083
6091
  tabIndex: selected ? 0 : -1,
@@ -6360,9 +6368,12 @@ function _focusItemElement(el) {
6360
6368
  }
6361
6369
  }
6362
6370
  const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalScopedContext(key, null), Tree = memo(
6363
- forwardRef(function(props, ref) {
6364
- const { children, space = 1, onFocus, ...restProps } = props, forwardedRef = useForwardedRef(ref), [focusedElement, setFocusedElement] = useState(null), focusedElementRef = useRef(focusedElement), path = useMemo(() => [], []), [itemElements, setItemElements] = useState([]), [state, setState] = useState({}), stateRef = useRef(state);
6365
- useEffect(() => {
6371
+ forwardRef(function(props, forwardedRef) {
6372
+ const { children, space = 1, onFocus, ...restProps } = props, ref = useRef(null), [focusedElement, setFocusedElement] = useState(null), focusedElementRef = useRef(focusedElement), path = useMemo(() => [], []), [itemElements, setItemElements] = useState([]), [state, setState] = useState({}), stateRef = useRef(state);
6373
+ useImperativeHandle(
6374
+ forwardedRef,
6375
+ () => ref.current
6376
+ ), useEffect(() => {
6366
6377
  focusedElementRef.current = focusedElement;
6367
6378
  }, [focusedElement]), useEffect(() => {
6368
6379
  stateRef.current = state;
@@ -6456,12 +6467,12 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6456
6467
  [onFocus]
6457
6468
  );
6458
6469
  return useEffect(() => {
6459
- if (!forwardedRef.current) return;
6470
+ if (!ref.current) return;
6460
6471
  const _itemElements = Array.from(
6461
- forwardedRef.current.querySelectorAll('[data-ui="TreeItem"]')
6472
+ ref.current.querySelectorAll('[data-ui="TreeItem"]')
6462
6473
  );
6463
6474
  setItemElements(_itemElements);
6464
- }, [children, forwardedRef]), /* @__PURE__ */ jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
6475
+ }, [children, ref]), /* @__PURE__ */ jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
6465
6476
  Stack,
6466
6477
  {
6467
6478
  as: "ul",
@@ -6469,7 +6480,7 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6469
6480
  ...restProps,
6470
6481
  onFocus: handleFocus,
6471
6482
  onKeyDown: handleKeyDown,
6472
- ref: forwardedRef,
6483
+ ref,
6473
6484
  role: "tree",
6474
6485
  space,
6475
6486
  children