@sanity/ui 2.1.13 → 2.1.15-canary.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
@@ -2684,6 +2684,13 @@ export declare function useElementSize(element: HTMLElement | null): ElementSize
2684
2684
 
2685
2685
  /**
2686
2686
  * @beta
2687
+ * @deprecated use `useImperativeHandle` instead
2688
+ * @example
2689
+ * ```diff
2690
+ * -const ref = useForwardedRef(forwardedRef)
2691
+ * +const ref = useRef(null)
2692
+ * +useImperativeHandle(forwardedRef, () => ref.current)
2693
+ * ```
2687
2694
  */
2688
2695
  export declare function useForwardedRef<T>(
2689
2696
  ref: React.ForwardedRef<T>,
package/dist/index.d.ts CHANGED
@@ -2684,6 +2684,13 @@ export declare function useElementSize(element: HTMLElement | null): ElementSize
2684
2684
 
2685
2685
  /**
2686
2686
  * @beta
2687
+ * @deprecated use `useImperativeHandle` instead
2688
+ * @example
2689
+ * ```diff
2690
+ * -const ref = useForwardedRef(forwardedRef)
2691
+ * +const ref = useRef(null)
2692
+ * +useImperativeHandle(forwardedRef, () => ref.current)
2693
+ * ```
2687
2694
  */
2688
2695
  export declare function useForwardedRef<T>(
2689
2696
  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(() => {
@@ -2375,10 +2372,13 @@ const Root$r = styled.div(checkboxBaseStyles), Input$5 = styled.input(inputEleme
2375
2372
  readOnly,
2376
2373
  style,
2377
2374
  ...restProps
2378
- } = props, ref = useForwardedRef(forwardedRef);
2379
- return useCustomValidity(ref, customValidity), useEffect(() => {
2375
+ } = props, ref = useRef(null);
2376
+ return useImperativeHandle(
2377
+ forwardedRef,
2378
+ () => ref.current
2379
+ ), useEffect(() => {
2380
2380
  ref.current && (ref.current.indeterminate = indeterminate || !1);
2381
- }, [indeterminate, ref]), /* @__PURE__ */ jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2381
+ }, [indeterminate]), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2382
2382
  /* @__PURE__ */ jsx(
2383
2383
  Input$5,
2384
2384
  {
@@ -2853,16 +2853,15 @@ function findMinBreakpoints(media, width) {
2853
2853
  media[i] <= width && ret.push(i);
2854
2854
  return ret;
2855
2855
  }
2856
- const ElementQuery = forwardRef(function(props, ref) {
2857
- const theme = useTheme_v2(), { children, media = theme.media, ...restProps } = props, forwardedRef = useForwardedRef(ref), [element, setElement] = useState(null), elementSize = useElementSize(element), width = useMemo(() => {
2856
+ const ElementQuery = forwardRef(function(props, forwardedRef) {
2857
+ const theme = useTheme_v2(), { children, media = theme.media, ...restProps } = props, ref = useRef(null), [element, setElement] = useState(null), elementSize = useElementSize(element), width = useMemo(() => {
2858
2858
  var _a;
2859
2859
  return (_a = elementSize == null ? void 0 : elementSize.border.width) != null ? _a : window.innerWidth;
2860
- }, [elementSize]), max = useMemo(() => findMaxBreakpoints(media, width), [media, width]), min = useMemo(() => findMinBreakpoints(media, width), [media, width]), setRef = useCallback(
2861
- (el) => {
2862
- forwardedRef.current = el, setElement(el);
2863
- },
2864
- [forwardedRef]
2865
- );
2860
+ }, [elementSize]), max = useMemo(() => findMaxBreakpoints(media, width), [media, width]), min = useMemo(() => findMinBreakpoints(media, width), [media, width]);
2861
+ useImperativeHandle(forwardedRef, () => ref.current);
2862
+ const setRef = useCallback((el) => {
2863
+ ref.current = el, setElement(el);
2864
+ }, []);
2866
2865
  return /* @__PURE__ */ jsx(
2867
2866
  "div",
2868
2867
  {
@@ -3022,30 +3021,20 @@ function LayerProvider(props) {
3022
3021
  );
3023
3022
  return /* @__PURE__ */ jsx(LayerContext.Provider, { value, children });
3024
3023
  }
3025
- const Root$j = styled.div({ position: "relative" }), LayerChildren = forwardRef(function(props, ref) {
3026
- const { children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps } = props, { zIndex, isTopLayer } = useLayer(), lastFocusedRef = useRef(null), forwardedRef = useForwardedRef(ref), isTopLayerRef = useRef(isTopLayer);
3027
- useEffect(() => {
3024
+ const Root$j = styled.div({ position: "relative" }), LayerChildren = forwardRef(function(props, forwardedRef) {
3025
+ const { children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps } = props, { zIndex, isTopLayer } = useLayer(), lastFocusedRef = useRef(null), ref = useRef(null), isTopLayerRef = useRef(isTopLayer);
3026
+ useImperativeHandle(forwardedRef, () => ref.current), useEffect(() => {
3028
3027
  isTopLayerRef.current !== isTopLayer && isTopLayer && (onActivate == null || onActivate({ activeElement: lastFocusedRef.current })), isTopLayerRef.current = isTopLayer;
3029
3028
  }, [isTopLayer, onActivate]);
3030
3029
  const handleFocus = useCallback(
3031
3030
  (event) => {
3032
3031
  onFocus == null || onFocus(event);
3033
- const rootElement = forwardedRef.current, target = document.activeElement;
3032
+ const rootElement = ref.current, target = document.activeElement;
3034
3033
  !isTopLayer || !rootElement || !target || isHTMLElement(target) && containsOrEqualsElement(rootElement, target) && (lastFocusedRef.current = target);
3035
3034
  },
3036
- [forwardedRef, isTopLayer, onFocus]
3037
- );
3038
- return /* @__PURE__ */ jsx(
3039
- Root$j,
3040
- {
3041
- ...restProps,
3042
- "data-ui": "Layer",
3043
- onFocus: handleFocus,
3044
- ref: forwardedRef,
3045
- style: { ...style, zIndex },
3046
- children
3047
- }
3035
+ [isTopLayer, onFocus]
3048
3036
  );
3037
+ return /* @__PURE__ */ jsx(Root$j, { ...restProps, "data-ui": "Layer", onFocus: handleFocus, ref, style: { ...style, zIndex }, children });
3049
3038
  }), Layer = forwardRef(function(props, ref) {
3050
3039
  const { children, zOffset = 1, ...restProps } = props;
3051
3040
  return /* @__PURE__ */ jsx(LayerProvider, { zOffset, children: /* @__PURE__ */ jsx(LayerChildren, { ...restProps, ref, children }) });
@@ -3111,15 +3100,15 @@ const emptySubscribe$1 = () => () => {
3111
3100
  position: absolute;
3112
3101
  left: 0;
3113
3102
  right: 0;
3114
- `, VirtualList = forwardRef(function(props, ref) {
3115
- 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);
3116
- useEffect(() => {
3103
+ `, VirtualList = forwardRef(function(props, forwardedRef) {
3104
+ 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);
3105
+ useImperativeHandle(forwardedRef, () => ref.current), useEffect(() => {
3117
3106
  if (!wrapperRef.current) return;
3118
3107
  const firstElement = wrapperRef.current.firstChild;
3119
3108
  firstElement instanceof HTMLElement && setItemHeight(firstElement.offsetHeight);
3120
3109
  }, [renderItem]), useEffect(() => {
3121
- if (!forwardedRef.current) return;
3122
- let _scrollEl = forwardedRef.current.parentNode;
3110
+ if (!ref.current) return;
3111
+ let _scrollEl = ref.current.parentNode;
3123
3112
  for (; _scrollEl && !_isScrollable(_scrollEl); )
3124
3113
  _scrollEl = _scrollEl.parentNode;
3125
3114
  if (_scrollEl) {
@@ -3144,7 +3133,7 @@ const emptySubscribe$1 = () => () => {
3144
3133
  return window.addEventListener("scroll", handleScroll, { passive: !0 }), window.addEventListener("resize", handleResize), setScrollHeight(window.innerHeight), handleScroll(), () => {
3145
3134
  window.removeEventListener("scroll", handleScroll), window.removeEventListener("resize", handleResize);
3146
3135
  };
3147
- }, [forwardedRef]);
3136
+ }, []);
3148
3137
  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;
3149
3138
  useEffect(() => {
3150
3139
  onChange && onChange({ fromIndex, gap: space[gap], itemHeight, scrollHeight, scrollTop, toIndex });
@@ -3153,7 +3142,7 @@ const emptySubscribe$1 = () => () => {
3153
3142
  const itemIndex = fromIndex + _itemIndex, node = renderItem(item), key2 = getItemKey ? getItemKey(item, itemIndex) : itemIndex;
3154
3143
  return /* @__PURE__ */ jsx(ItemWrapper, { style: { top: itemIndex * (itemHeight + space[gap]) }, children: node }, key2);
3155
3144
  }), [fromIndex, gap, getItemKey, itemHeight, items, renderItem, space, toIndex]), wrapperStyle = useMemo(() => ({ height }), [height]);
3156
- return /* @__PURE__ */ jsx(Root$h, { as, "data-ui": "VirtualList", ...restProps, ref: forwardedRef, children: /* @__PURE__ */ jsx("div", { ref: wrapperRef, style: wrapperStyle, children }) });
3145
+ return /* @__PURE__ */ jsx(Root$h, { as, "data-ui": "VirtualList", ...restProps, ref, children: /* @__PURE__ */ jsx("div", { ref: wrapperRef, style: wrapperStyle, children }) });
3157
3146
  }), 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 = {
3158
3147
  top: ["bottom", "left", "right"],
3159
3148
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -3299,7 +3288,7 @@ const MotionCard$1 = styled(motion(Card))`
3299
3288
  );
3300
3289
  PopoverCard.displayName = "PopoverCard";
3301
3290
  const Popover = memo(
3302
- forwardRef(function(props, ref) {
3291
+ forwardRef(function(props, forwardedRef) {
3303
3292
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3304
3293
  const { container, layer } = useTheme_v2(), boundaryElementContext = useBoundaryElement(), {
3305
3294
  __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
@@ -3331,7 +3320,12 @@ const Popover = memo(
3331
3320
  zOffset: zOffsetProp = layer.popover.zOffset,
3332
3321
  updateRef,
3333
3322
  ...restProps
3334
- } = 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({
3323
+ } = 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";
3324
+ useImperativeHandle(
3325
+ forwardedRef,
3326
+ () => ref.current
3327
+ );
3328
+ const mediaIndex = useMediaIndex(), boundaryWidth = constrainSize || preventOverflow ? boundarySize == null ? void 0 : boundarySize.width : void 0, width = calcCurrentWidth({
3335
3329
  container,
3336
3330
  mediaIndex,
3337
3331
  width: widthArrayProp
@@ -3345,11 +3339,11 @@ const Popover = memo(
3345
3339
  }, [maxWidth]);
3346
3340
  const referenceWidthRef = useRef();
3347
3341
  useEffect(() => {
3348
- const floatingElement = forwardedRef.current;
3342
+ const floatingElement = ref.current;
3349
3343
  if (!open || !floatingElement) return;
3350
3344
  const referenceWidth = referenceWidthRef.current;
3351
3345
  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`);
3352
- }, [width, forwardedRef, matchReferenceWidth, maxWidth, open]);
3346
+ }, [width, matchReferenceWidth, maxWidth, open]);
3353
3347
  const middleware = useMemo(() => {
3354
3348
  const ret = [];
3355
3349
  return (constrainSize || preventOverflow) && ret.push(
@@ -3411,9 +3405,9 @@ const Popover = memo(
3411
3405
  arrowRef.current = arrowEl;
3412
3406
  }, []), setFloating = useCallback(
3413
3407
  (node) => {
3414
- forwardedRef.current = node, refs.setFloating(node);
3408
+ ref.current = node, refs.setFloating(node);
3415
3409
  },
3416
- [forwardedRef, refs]
3410
+ [refs]
3417
3411
  ), setReference = useCallback(
3418
3412
  (node) => {
3419
3413
  refs.setReference(node);
@@ -3586,8 +3580,11 @@ function inputElementStyle(props) {
3586
3580
  `;
3587
3581
  }
3588
3582
  const Root$g = styled.div(radioBaseStyle), Input$4 = styled.input(inputElementStyle), Radio = forwardRef(function(props, forwardedRef) {
3589
- const { className, disabled, style, customValidity, readOnly, ...restProps } = props, ref = useForwardedRef(forwardedRef);
3590
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$g, { className, "data-ui": "Radio", style, children: [
3583
+ const { className, disabled, style, customValidity, readOnly, ...restProps } = props, ref = useRef(null);
3584
+ return useImperativeHandle(
3585
+ forwardedRef,
3586
+ () => ref.current
3587
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$g, { className, "data-ui": "Radio", style, children: [
3591
3588
  /* @__PURE__ */ jsx(
3592
3589
  Input$4,
3593
3590
  {
@@ -3748,8 +3745,11 @@ const selectStyle = {
3748
3745
  readOnly,
3749
3746
  space = 3,
3750
3747
  ...restProps
3751
- } = props, ref = useForwardedRef(forwardedRef);
3752
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$f, { "data-ui": "Select", children: [
3748
+ } = props, ref = useRef(null);
3749
+ return useImperativeHandle(
3750
+ forwardedRef,
3751
+ () => ref.current
3752
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxs(Root$f, { "data-ui": "Select", children: [
3753
3753
  /* @__PURE__ */ jsx(
3754
3754
  Input$3,
3755
3755
  {
@@ -3943,10 +3943,13 @@ function switchThumbStyles(props) {
3943
3943
  `;
3944
3944
  }
3945
3945
  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) {
3946
- const { checked, className, disabled, indeterminate, readOnly, style, ...restProps } = props, ref = useForwardedRef(forwardedRef);
3947
- return useEffect(() => {
3946
+ const { checked, className, disabled, indeterminate, readOnly, style, ...restProps } = props, ref = useRef(null);
3947
+ return useImperativeHandle(
3948
+ forwardedRef,
3949
+ () => ref.current
3950
+ ), useEffect(() => {
3948
3951
  ref.current && (ref.current.indeterminate = indeterminate || !1);
3949
- }, [indeterminate, ref]), /* @__PURE__ */ jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3952
+ }, [indeterminate]), /* @__PURE__ */ jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3950
3953
  /* @__PURE__ */ jsx(
3951
3954
  Input$2,
3952
3955
  {
@@ -3985,8 +3988,11 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
3985
3988
  radius = 2,
3986
3989
  weight,
3987
3990
  ...restProps
3988
- } = props, ref = useForwardedRef(forwardedRef), rootTheme = useRootTheme();
3989
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsx(Root$c, { "data-ui": "TextArea", children: /* @__PURE__ */ jsxs(InputRoot$1, { children: [
3991
+ } = props, ref = useRef(null), rootTheme = useRootTheme();
3992
+ return useImperativeHandle(
3993
+ forwardedRef,
3994
+ () => ref.current
3995
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsx(Root$c, { "data-ui": "TextArea", children: /* @__PURE__ */ jsxs(InputRoot$1, { children: [
3990
3996
  /* @__PURE__ */ jsx(
3991
3997
  Input$1,
3992
3998
  {
@@ -4081,8 +4087,11 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
4081
4087
  type = "text",
4082
4088
  weight,
4083
4089
  ...restProps
4084
- } = 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;
4085
- useCustomValidity(ref, customValidity);
4090
+ } = 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;
4091
+ useImperativeHandle(
4092
+ forwardedRef,
4093
+ () => ref.current
4094
+ ), useCustomValidity(ref, customValidity);
4086
4095
  const handleClearMouseDown = useCallback((event) => {
4087
4096
  event.preventDefault(), event.stopPropagation();
4088
4097
  }, []), handleClearClick = useCallback(
@@ -4329,7 +4338,7 @@ function TooltipDelayGroupProvider(props) {
4329
4338
  const Root$a = styled(Layer)`
4330
4339
  pointer-events: none;
4331
4340
  max-width: ${({ $maxWidth }) => $maxWidth}px;
4332
- `, Tooltip = forwardRef(function(props, ref) {
4341
+ `, Tooltip = forwardRef(function(props, forwardedRef) {
4333
4342
  var _a, _b, _c, _d, _e, _f, _g;
4334
4343
  const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
4335
4344
  animate: _animate = !1,
@@ -4348,7 +4357,9 @@ const Root$a = styled(Layer)`
4348
4357
  zOffset = layer.tooltip.zOffset,
4349
4358
  delay,
4350
4359
  ...restProps
4351
- } = 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(
4360
+ } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport";
4361
+ useImperativeHandle(forwardedRef, () => ref.current);
4362
+ const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = useSyncExternalStore(
4352
4363
  emptySubscribe,
4353
4364
  () => document.body.offsetWidth,
4354
4365
  // We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
@@ -4458,9 +4469,9 @@ const Root$a = styled(Layer)`
4458
4469
  [update]
4459
4470
  ), setFloating = useCallback(
4460
4471
  (node) => {
4461
- forwardedRef.current = node, refs.setFloating(node);
4472
+ ref.current = node, refs.setFloating(node);
4462
4473
  },
4463
- [forwardedRef, refs]
4474
+ [refs]
4464
4475
  ), childRef = childProp == null ? void 0 : childProp.ref, setReference = useCallback(
4465
4476
  (node) => {
4466
4477
  typeof childRef == "function" ? childRef(node) : childRef && (childRef.current = node), setReferenceElement(node);
@@ -4594,7 +4605,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4594
4605
  "Meta",
4595
4606
  "Tab",
4596
4607
  "CapsLock"
4597
- ], 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) {
4608
+ ], 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) {
4598
4609
  const {
4599
4610
  border: border2 = !0,
4600
4611
  customValidity,
@@ -4633,7 +4644,12 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4633
4644
  }), { activeValue, focused, listFocused, query, value } = state, defaultRenderOption = useCallback(
4634
4645
  ({ value: value2 }) => /* @__PURE__ */ jsx(Card, { "data-as": "button", padding: paddingProp, radius: 2, tone: "inherit", children: /* @__PURE__ */ jsx(Text, { size: fontSize2, textOverflow: "ellipsis", children: value2 }) }),
4635
4646
  [fontSize2, paddingProp]
4636
- ), 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(
4647
+ ), 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);
4648
+ useImperativeHandle(
4649
+ forwardedRef,
4650
+ () => inputElementRef.current
4651
+ );
4652
+ const listBoxId = `${id}-listbox`, options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY, padding = useArrayProp(paddingProp), currentOption = useMemo(
4637
4653
  () => value !== null ? options.find((o) => o.value === value) : void 0,
4638
4654
  [options, value]
4639
4655
  ), filteredOptions = useMemo(
@@ -4737,12 +4753,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4737
4753
  }
4738
4754
  }
4739
4755
  }, [activeValue, filteredOptions]);
4740
- const setRef = useCallback(
4741
- (el) => {
4742
- inputElementRef.current = el, forwardedRef.current = el;
4743
- },
4744
- [forwardedRef]
4745
- ), clearButton = useMemo(() => {
4756
+ const clearButton = useMemo(() => {
4746
4757
  if (!loading && !disabled && value)
4747
4758
  return {
4748
4759
  "aria-label": "Clear",
@@ -4817,7 +4828,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4817
4828
  prefix,
4818
4829
  radius,
4819
4830
  readOnly,
4820
- ref: setRef,
4831
+ ref: inputElementRef,
4821
4832
  role: "combobox",
4822
4833
  spellCheck: !1,
4823
4834
  suffix: suffix || openButtonNode,
@@ -5079,13 +5090,13 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5079
5090
  `, DialogFooter = styled(Box)`
5080
5091
  position: relative;
5081
5092
  z-index: 3;
5082
- `, DialogCard = forwardRef(function(props, ref) {
5093
+ `, DialogCard = forwardRef(function(props, forwardedRef) {
5083
5094
  var _a;
5084
5095
  const {
5085
5096
  __unstable_autoFocus: autoFocus,
5086
5097
  __unstable_hideCloseButton: hideCloseButton,
5087
5098
  children,
5088
- contentRef,
5099
+ contentRef: forwardedContentRef,
5089
5100
  footer,
5090
5101
  header,
5091
5102
  id,
@@ -5096,10 +5107,13 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5096
5107
  scheme,
5097
5108
  shadow: shadowProp,
5098
5109
  width: widthProp
5099
- } = 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;
5100
- useEffect(() => {
5101
- autoFocus && forwardedRef.current && focusFirstDescendant(forwardedRef.current);
5102
- }, [autoFocus, forwardedRef]), useGlobalKeyDown(
5110
+ } = 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;
5111
+ useImperativeHandle(forwardedRef, () => ref.current), useImperativeHandle(
5112
+ forwardedContentRef,
5113
+ () => contentRef.current
5114
+ ), useEffect(() => {
5115
+ autoFocus && ref.current && focusFirstDescendant(ref.current);
5116
+ }, [autoFocus, ref]), useGlobalKeyDown(
5103
5117
  useCallback(
5104
5118
  (event) => {
5105
5119
  if (!isTopLayer || !onClose) return;
@@ -5119,17 +5133,9 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5119
5133
  ),
5120
5134
  [rootElement]
5121
5135
  );
5122
- const setRef = useCallback(
5123
- (el) => {
5124
- setRootElement(el), forwardedRef.current = el;
5125
- },
5126
- [forwardedRef]
5127
- ), setContentRef = useCallback(
5128
- (el) => {
5129
- localContentRef.current = el, typeof contentRef == "function" ? contentRef(el) : contentRef && (contentRef.current = el);
5130
- },
5131
- [contentRef]
5132
- );
5136
+ const setRef = useCallback((el) => {
5137
+ setRootElement(el), ref.current = el;
5138
+ }, []);
5133
5139
  return /* @__PURE__ */ jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsx(DialogCardRoot, { radius, ref: setRef, scheme, shadow, children: /* @__PURE__ */ jsxs(DialogLayout, { direction: "column", children: [
5134
5140
  showHeader && /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsxs(Flex, { align: "center", padding: 3, children: [
5135
5141
  /* @__PURE__ */ jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
@@ -5145,7 +5151,7 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
5145
5151
  }
5146
5152
  ) })
5147
5153
  ] }) }),
5148
- /* @__PURE__ */ jsx(DialogContent, { flex: 1, ref: setContentRef, tabIndex: -1, children }),
5154
+ /* @__PURE__ */ jsx(DialogContent, { flex: 1, ref: contentRef, tabIndex: -1, children }),
5149
5155
  footer && /* @__PURE__ */ jsx(DialogFooter, { children: footer })
5150
5156
  ] }) }) });
5151
5157
  }), Dialog = forwardRef(function(props, ref) {
@@ -5421,7 +5427,7 @@ function useMenuController(props) {
5421
5427
  const Root$5 = styled(Box)`
5422
5428
  outline: none;
5423
5429
  overflow: auto;
5424
- `, Menu = forwardRef(function(props, ref) {
5430
+ `, Menu = forwardRef(function(props, forwardedRef) {
5425
5431
  const {
5426
5432
  children,
5427
5433
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -5439,7 +5445,9 @@ const Root$5 = styled(Box)`
5439
5445
  shouldFocus = props.focusFirst && "first" || props.focusLast && "last" || null,
5440
5446
  space = 1,
5441
5447
  ...restProps
5442
- } = props, forwardedRef = useForwardedRef(ref), { isTopLayer } = useLayer(), {
5448
+ } = props, ref = useRef(null);
5449
+ useImperativeHandle(forwardedRef, () => ref.current);
5450
+ const { isTopLayer } = useLayer(), {
5443
5451
  activeElement,
5444
5452
  activeIndex,
5445
5453
  handleItemMouseEnter,
@@ -5450,9 +5458,9 @@ const Root$5 = styled(Box)`
5450
5458
  setRootElement
5451
5459
  } = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = useCallback(
5452
5460
  (el) => {
5453
- setRootElement(el), forwardedRef.current = el;
5461
+ setRootElement(el), ref.current = el;
5454
5462
  },
5455
- [forwardedRef, setRootElement]
5463
+ [setRootElement]
5456
5464
  );
5457
5465
  useEffect(() => {
5458
5466
  onItemSelect && onItemSelect(activeIndex);
@@ -5887,9 +5895,9 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
5887
5895
  onItemClick,
5888
5896
  onItemMouseEnter = menu.onMouseEnter,
5889
5897
  onItemMouseLeave = menu.onMouseLeave
5890
- } = menu, [rootElement, setRootElement] = useState(null), active = !!activeElement && activeElement === rootElement;
5891
- useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp]);
5892
- const ref = useForwardedRef(forwardedRef), handleClick = useCallback(
5898
+ } = menu, [rootElement, setRootElement] = useState(null), active = !!activeElement && activeElement === rootElement, ref = useRef(null);
5899
+ useImperativeHandle(forwardedRef, () => ref.current), useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp]);
5900
+ const handleClick = useCallback(
5893
5901
  (event) => {
5894
5902
  disabled || (onClick && onClick(event), onItemClick && onItemClick());
5895
5903
  },
@@ -5905,12 +5913,9 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
5905
5913
  paddingLeft
5906
5914
  }),
5907
5915
  [padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft]
5908
- ), hotkeysFontSize = useArrayProp(fontSize2).map((s) => s - 1), setRef = useCallback(
5909
- (el) => {
5910
- ref.current = el, setRootElement(el);
5911
- },
5912
- [ref]
5913
- );
5916
+ ), hotkeysFontSize = useArrayProp(fontSize2).map((s) => s - 1), setRef = useCallback((el) => {
5917
+ ref.current = el, setRootElement(el);
5918
+ }, []);
5914
5919
  return /* @__PURE__ */ jsxs(
5915
5920
  Selectable,
5916
5921
  {
@@ -6049,16 +6054,21 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
6049
6054
  padding = 2,
6050
6055
  selected,
6051
6056
  ...restProps
6052
- } = props, elementRef = useRef(null), focusedRef = useRef(!1), handleBlur = useCallback(() => {
6057
+ } = props, ref = useRef(null), focusedRef = useRef(!1);
6058
+ useImperativeHandle(
6059
+ forwardedRef,
6060
+ () => ref.current
6061
+ );
6062
+ const handleBlur = useCallback(() => {
6053
6063
  focusedRef.current = !1;
6054
6064
  }, []), handleFocus = useCallback(
6055
6065
  (event) => {
6056
6066
  focusedRef.current = !0, onFocus && onFocus(event);
6057
6067
  },
6058
6068
  [onFocus]
6059
- ), ref = useForwardedRef(forwardedRef);
6069
+ );
6060
6070
  return useEffect(() => {
6061
- focused && !focusedRef.current && (elementRef.current && elementRef.current.focus(), focusedRef.current = !0);
6071
+ focused && !focusedRef.current && (ref.current && ref.current.focus(), focusedRef.current = !0);
6062
6072
  }, [focused]), /* @__PURE__ */ jsx(
6063
6073
  CustomButton,
6064
6074
  {
@@ -6073,9 +6083,7 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
6073
6083
  onBlur: handleBlur,
6074
6084
  onFocus: handleFocus,
6075
6085
  padding,
6076
- ref: (el) => {
6077
- elementRef.current = el, ref.current = el;
6078
- },
6086
+ ref,
6079
6087
  role: "tab",
6080
6088
  selected,
6081
6089
  tabIndex: selected ? 0 : -1,
@@ -6358,9 +6366,12 @@ function _focusItemElement(el) {
6358
6366
  }
6359
6367
  }
6360
6368
  const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalScopedContext(key, null), Tree = memo(
6361
- forwardRef(function(props, ref) {
6362
- 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);
6363
- useEffect(() => {
6369
+ forwardRef(function(props, forwardedRef) {
6370
+ 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);
6371
+ useImperativeHandle(
6372
+ forwardedRef,
6373
+ () => ref.current
6374
+ ), useEffect(() => {
6364
6375
  focusedElementRef.current = focusedElement;
6365
6376
  }, [focusedElement]), useEffect(() => {
6366
6377
  stateRef.current = state;
@@ -6454,12 +6465,12 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6454
6465
  [onFocus]
6455
6466
  );
6456
6467
  return useEffect(() => {
6457
- if (!forwardedRef.current) return;
6468
+ if (!ref.current) return;
6458
6469
  const _itemElements = Array.from(
6459
- forwardedRef.current.querySelectorAll('[data-ui="TreeItem"]')
6470
+ ref.current.querySelectorAll('[data-ui="TreeItem"]')
6460
6471
  );
6461
6472
  setItemElements(_itemElements);
6462
- }, [children, forwardedRef]), /* @__PURE__ */ jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
6473
+ }, [children, ref]), /* @__PURE__ */ jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
6463
6474
  Stack,
6464
6475
  {
6465
6476
  as: "ul",
@@ -6467,7 +6478,7 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6467
6478
  ...restProps,
6468
6479
  onFocus: handleFocus,
6469
6480
  onKeyDown: handleKeyDown,
6470
- ref: forwardedRef,
6481
+ ref,
6471
6482
  role: "tree",
6472
6483
  space,
6473
6484
  children