@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.js CHANGED
@@ -621,12 +621,9 @@ function getServerSnapshot() {
621
621
  function usePrefersReducedMotion() {
622
622
  return react.useSyncExternalStore(subscribe$1, getSnapshot, getServerSnapshot);
623
623
  }
624
- const useIsomorphicEffect = typeof window < "u" ? react.useLayoutEffect : react.useEffect;
625
624
  function useForwardedRef(ref) {
626
625
  const innerRef = react.useRef(null);
627
- return useIsomorphicEffect(() => {
628
- ref && (typeof ref == "function" ? ref(innerRef.current) : ref.current = innerRef.current);
629
- }), innerRef;
626
+ return react.useImperativeHandle(ref, () => innerRef.current), innerRef;
630
627
  }
631
628
  function useCustomValidity(ref, customValidity) {
632
629
  react.useEffect(() => {
@@ -2372,10 +2369,13 @@ const Root$r = styledComponents.styled.div(checkboxBaseStyles), Input$5 = styled
2372
2369
  readOnly,
2373
2370
  style,
2374
2371
  ...restProps
2375
- } = props, ref = useForwardedRef(forwardedRef);
2376
- return useCustomValidity(ref, customValidity), react.useEffect(() => {
2372
+ } = props, ref = react.useRef(null);
2373
+ return react.useImperativeHandle(
2374
+ forwardedRef,
2375
+ () => ref.current
2376
+ ), react.useEffect(() => {
2377
2377
  ref.current && (ref.current.indeterminate = indeterminate || !1);
2378
- }, [indeterminate, ref]), /* @__PURE__ */ jsxRuntime.jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2378
+ }, [indeterminate]), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$r, { className, "data-ui": "Checkbox", style, children: [
2379
2379
  /* @__PURE__ */ jsxRuntime.jsx(
2380
2380
  Input$5,
2381
2381
  {
@@ -2850,16 +2850,15 @@ function findMinBreakpoints(media, width) {
2850
2850
  media[i] <= width && ret.push(i);
2851
2851
  return ret;
2852
2852
  }
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(() => {
2853
+ const ElementQuery = react.forwardRef(function(props, forwardedRef) {
2854
+ 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
2855
  var _a;
2856
2856
  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
- );
2857
+ }, [elementSize]), max = react.useMemo(() => findMaxBreakpoints(media, width), [media, width]), min = react.useMemo(() => findMinBreakpoints(media, width), [media, width]);
2858
+ react.useImperativeHandle(forwardedRef, () => ref.current);
2859
+ const setRef = react.useCallback((el) => {
2860
+ ref.current = el, setElement(el);
2861
+ }, []);
2863
2862
  return /* @__PURE__ */ jsxRuntime.jsx(
2864
2863
  "div",
2865
2864
  {
@@ -3019,30 +3018,20 @@ function LayerProvider(props) {
3019
3018
  );
3020
3019
  return /* @__PURE__ */ jsxRuntime.jsx(LayerContext.Provider, { value, children });
3021
3020
  }
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(() => {
3021
+ const Root$j = styledComponents.styled.div({ position: "relative" }), LayerChildren = react.forwardRef(function(props, forwardedRef) {
3022
+ const { children, onActivate, onFocus, style = EMPTY_RECORD, ...restProps } = props, { zIndex, isTopLayer } = useLayer(), lastFocusedRef = react.useRef(null), ref = react.useRef(null), isTopLayerRef = react.useRef(isTopLayer);
3023
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useEffect(() => {
3025
3024
  isTopLayerRef.current !== isTopLayer && isTopLayer && (onActivate == null || onActivate({ activeElement: lastFocusedRef.current })), isTopLayerRef.current = isTopLayer;
3026
3025
  }, [isTopLayer, onActivate]);
3027
3026
  const handleFocus = react.useCallback(
3028
3027
  (event) => {
3029
3028
  onFocus == null || onFocus(event);
3030
- const rootElement = forwardedRef.current, target = document.activeElement;
3029
+ const rootElement = ref.current, target = document.activeElement;
3031
3030
  !isTopLayer || !rootElement || !target || isHTMLElement(target) && containsOrEqualsElement(rootElement, target) && (lastFocusedRef.current = target);
3032
3031
  },
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
- }
3032
+ [isTopLayer, onFocus]
3045
3033
  );
3034
+ return /* @__PURE__ */ jsxRuntime.jsx(Root$j, { ...restProps, "data-ui": "Layer", onFocus: handleFocus, ref, style: { ...style, zIndex }, children });
3046
3035
  }), Layer = react.forwardRef(function(props, ref) {
3047
3036
  const { children, zOffset = 1, ...restProps } = props;
3048
3037
  return /* @__PURE__ */ jsxRuntime.jsx(LayerProvider, { zOffset, children: /* @__PURE__ */ jsxRuntime.jsx(LayerChildren, { ...restProps, ref, children }) });
@@ -3108,15 +3097,15 @@ const emptySubscribe$1 = () => () => {
3108
3097
  position: absolute;
3109
3098
  left: 0;
3110
3099
  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(() => {
3100
+ `, VirtualList = react.forwardRef(function(props, forwardedRef) {
3101
+ 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);
3102
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useEffect(() => {
3114
3103
  if (!wrapperRef.current) return;
3115
3104
  const firstElement = wrapperRef.current.firstChild;
3116
3105
  firstElement instanceof HTMLElement && setItemHeight(firstElement.offsetHeight);
3117
3106
  }, [renderItem]), react.useEffect(() => {
3118
- if (!forwardedRef.current) return;
3119
- let _scrollEl = forwardedRef.current.parentNode;
3107
+ if (!ref.current) return;
3108
+ let _scrollEl = ref.current.parentNode;
3120
3109
  for (; _scrollEl && !_isScrollable(_scrollEl); )
3121
3110
  _scrollEl = _scrollEl.parentNode;
3122
3111
  if (_scrollEl) {
@@ -3141,7 +3130,7 @@ const emptySubscribe$1 = () => () => {
3141
3130
  return window.addEventListener("scroll", handleScroll, { passive: !0 }), window.addEventListener("resize", handleResize), setScrollHeight(window.innerHeight), handleScroll(), () => {
3142
3131
  window.removeEventListener("scroll", handleScroll), window.removeEventListener("resize", handleResize);
3143
3132
  };
3144
- }, [forwardedRef]);
3133
+ }, []);
3145
3134
  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
3135
  react.useEffect(() => {
3147
3136
  onChange && onChange({ fromIndex, gap: space[gap], itemHeight, scrollHeight, scrollTop, toIndex });
@@ -3150,7 +3139,7 @@ const emptySubscribe$1 = () => () => {
3150
3139
  const itemIndex = fromIndex + _itemIndex, node = renderItem(item), key2 = getItemKey ? getItemKey(item, itemIndex) : itemIndex;
3151
3140
  return /* @__PURE__ */ jsxRuntime.jsx(ItemWrapper, { style: { top: itemIndex * (itemHeight + space[gap]) }, children: node }, key2);
3152
3141
  }), [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 }) });
3142
+ return /* @__PURE__ */ jsxRuntime.jsx(Root$h, { as, "data-ui": "VirtualList", ...restProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: wrapperRef, style: wrapperStyle, children }) });
3154
3143
  }), 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
3144
  top: ["bottom", "left", "right"],
3156
3145
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -3296,7 +3285,7 @@ const MotionCard$1 = styledComponents.styled(framerMotion.motion(Card))`
3296
3285
  );
3297
3286
  PopoverCard.displayName = "PopoverCard";
3298
3287
  const Popover = react.memo(
3299
- react.forwardRef(function(props, ref) {
3288
+ react.forwardRef(function(props, forwardedRef) {
3300
3289
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3301
3290
  const { container, layer } = useTheme_v2(), boundaryElementContext = useBoundaryElement(), {
3302
3291
  __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
@@ -3328,7 +3317,12 @@ const Popover = react.memo(
3328
3317
  zOffset: zOffsetProp = layer.popover.zOffset,
3329
3318
  updateRef,
3330
3319
  ...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({
3320
+ } = 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";
3321
+ react.useImperativeHandle(
3322
+ forwardedRef,
3323
+ () => ref.current
3324
+ );
3325
+ const mediaIndex = useMediaIndex(), boundaryWidth = constrainSize || preventOverflow ? boundarySize == null ? void 0 : boundarySize.width : void 0, width = calcCurrentWidth({
3332
3326
  container,
3333
3327
  mediaIndex,
3334
3328
  width: widthArrayProp
@@ -3342,11 +3336,11 @@ const Popover = react.memo(
3342
3336
  }, [maxWidth]);
3343
3337
  const referenceWidthRef = react.useRef();
3344
3338
  react.useEffect(() => {
3345
- const floatingElement = forwardedRef.current;
3339
+ const floatingElement = ref.current;
3346
3340
  if (!open || !floatingElement) return;
3347
3341
  const referenceWidth = referenceWidthRef.current;
3348
3342
  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]);
3343
+ }, [width, matchReferenceWidth, maxWidth, open]);
3350
3344
  const middleware = react.useMemo(() => {
3351
3345
  const ret = [];
3352
3346
  return (constrainSize || preventOverflow) && ret.push(
@@ -3408,9 +3402,9 @@ const Popover = react.memo(
3408
3402
  arrowRef.current = arrowEl;
3409
3403
  }, []), setFloating = react.useCallback(
3410
3404
  (node) => {
3411
- forwardedRef.current = node, refs.setFloating(node);
3405
+ ref.current = node, refs.setFloating(node);
3412
3406
  },
3413
- [forwardedRef, refs]
3407
+ [refs]
3414
3408
  ), setReference = react.useCallback(
3415
3409
  (node) => {
3416
3410
  refs.setReference(node);
@@ -3583,8 +3577,11 @@ function inputElementStyle(props) {
3583
3577
  `;
3584
3578
  }
3585
3579
  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: [
3580
+ const { className, disabled, style, customValidity, readOnly, ...restProps } = props, ref = react.useRef(null);
3581
+ return react.useImperativeHandle(
3582
+ forwardedRef,
3583
+ () => ref.current
3584
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$g, { className, "data-ui": "Radio", style, children: [
3588
3585
  /* @__PURE__ */ jsxRuntime.jsx(
3589
3586
  Input$4,
3590
3587
  {
@@ -3745,8 +3742,11 @@ const selectStyle = {
3745
3742
  readOnly,
3746
3743
  space = 3,
3747
3744
  ...restProps
3748
- } = props, ref = useForwardedRef(forwardedRef);
3749
- return useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$f, { "data-ui": "Select", children: [
3745
+ } = props, ref = react.useRef(null);
3746
+ return react.useImperativeHandle(
3747
+ forwardedRef,
3748
+ () => ref.current
3749
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsxs(Root$f, { "data-ui": "Select", children: [
3750
3750
  /* @__PURE__ */ jsxRuntime.jsx(
3751
3751
  Input$3,
3752
3752
  {
@@ -3940,10 +3940,13 @@ function switchThumbStyles(props) {
3940
3940
  `;
3941
3941
  }
3942
3942
  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(() => {
3943
+ const { checked, className, disabled, indeterminate, readOnly, style, ...restProps } = props, ref = react.useRef(null);
3944
+ return react.useImperativeHandle(
3945
+ forwardedRef,
3946
+ () => ref.current
3947
+ ), react.useEffect(() => {
3945
3948
  ref.current && (ref.current.indeterminate = indeterminate || !1);
3946
- }, [indeterminate, ref]), /* @__PURE__ */ jsxRuntime.jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3949
+ }, [indeterminate]), /* @__PURE__ */ jsxRuntime.jsxs(Root$d, { className, "data-ui": "Switch", style, children: [
3947
3950
  /* @__PURE__ */ jsxRuntime.jsx(
3948
3951
  Input$2,
3949
3952
  {
@@ -3982,8 +3985,11 @@ const Root$d = styledComponents.styled.span(switchBaseStyles), Input$2 = styledC
3982
3985
  radius = 2,
3983
3986
  weight,
3984
3987
  ...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: [
3988
+ } = props, ref = react.useRef(null), rootTheme = useRootTheme();
3989
+ return react.useImperativeHandle(
3990
+ forwardedRef,
3991
+ () => ref.current
3992
+ ), useCustomValidity(ref, customValidity), /* @__PURE__ */ jsxRuntime.jsx(Root$c, { "data-ui": "TextArea", children: /* @__PURE__ */ jsxRuntime.jsxs(InputRoot$1, { children: [
3987
3993
  /* @__PURE__ */ jsxRuntime.jsx(
3988
3994
  Input$1,
3989
3995
  {
@@ -4078,8 +4084,11 @@ const Root$d = styledComponents.styled.span(switchBaseStyles), Input$2 = styledC
4078
4084
  type = "text",
4079
4085
  weight,
4080
4086
  ...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);
4087
+ } = 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;
4088
+ react.useImperativeHandle(
4089
+ forwardedRef,
4090
+ () => ref.current
4091
+ ), useCustomValidity(ref, customValidity);
4083
4092
  const handleClearMouseDown = react.useCallback((event) => {
4084
4093
  event.preventDefault(), event.stopPropagation();
4085
4094
  }, []), handleClearClick = react.useCallback(
@@ -4326,7 +4335,7 @@ function TooltipDelayGroupProvider(props) {
4326
4335
  const Root$a = styledComponents.styled(Layer)`
4327
4336
  pointer-events: none;
4328
4337
  max-width: ${({ $maxWidth }) => $maxWidth}px;
4329
- `, Tooltip = react.forwardRef(function(props, ref) {
4338
+ `, Tooltip = react.forwardRef(function(props, forwardedRef) {
4330
4339
  var _a, _b, _c, _d, _e, _f, _g;
4331
4340
  const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
4332
4341
  animate: _animate = !1,
@@ -4345,7 +4354,9 @@ const Root$a = styledComponents.styled(Layer)`
4345
4354
  zOffset = layer.tooltip.zOffset,
4346
4355
  delay,
4347
4356
  ...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(
4357
+ } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport";
4358
+ react.useImperativeHandle(forwardedRef, () => ref.current);
4359
+ const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = react.useSyncExternalStore(
4349
4360
  emptySubscribe,
4350
4361
  () => document.body.offsetWidth,
4351
4362
  // 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 +4466,9 @@ const Root$a = styledComponents.styled(Layer)`
4455
4466
  [update]
4456
4467
  ), setFloating = react.useCallback(
4457
4468
  (node) => {
4458
- forwardedRef.current = node, refs.setFloating(node);
4469
+ ref.current = node, refs.setFloating(node);
4459
4470
  },
4460
- [forwardedRef, refs]
4471
+ [refs]
4461
4472
  ), childRef = childProp == null ? void 0 : childProp.ref, setReference = react.useCallback(
4462
4473
  (node) => {
4463
4474
  typeof childRef == "function" ? childRef(node) : childRef && (childRef.current = node), setReferenceElement(node);
@@ -4591,7 +4602,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4591
4602
  "Meta",
4592
4603
  "Tab",
4593
4604
  "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) {
4605
+ ], 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
4606
  const {
4596
4607
  border: border2 = !0,
4597
4608
  customValidity,
@@ -4630,7 +4641,12 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4630
4641
  }), { activeValue, focused, listFocused, query, value } = state, defaultRenderOption = react.useCallback(
4631
4642
  ({ 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
4643
  [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(
4644
+ ), 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);
4645
+ react.useImperativeHandle(
4646
+ forwardedRef,
4647
+ () => inputElementRef.current
4648
+ );
4649
+ const listBoxId = `${id}-listbox`, options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY, padding = useArrayProp(paddingProp), currentOption = react.useMemo(
4634
4650
  () => value !== null ? options.find((o) => o.value === value) : void 0,
4635
4651
  [options, value]
4636
4652
  ), filteredOptions = react.useMemo(
@@ -4734,12 +4750,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4734
4750
  }
4735
4751
  }
4736
4752
  }, [activeValue, filteredOptions]);
4737
- const setRef = react.useCallback(
4738
- (el) => {
4739
- inputElementRef.current = el, forwardedRef.current = el;
4740
- },
4741
- [forwardedRef]
4742
- ), clearButton = react.useMemo(() => {
4753
+ const clearButton = react.useMemo(() => {
4743
4754
  if (!loading && !disabled && value)
4744
4755
  return {
4745
4756
  "aria-label": "Clear",
@@ -4814,7 +4825,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4814
4825
  prefix,
4815
4826
  radius,
4816
4827
  readOnly,
4817
- ref: setRef,
4828
+ ref: inputElementRef,
4818
4829
  role: "combobox",
4819
4830
  spellCheck: !1,
4820
4831
  suffix: suffix || openButtonNode,
@@ -5076,13 +5087,13 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5076
5087
  `, DialogFooter = styledComponents.styled(Box)`
5077
5088
  position: relative;
5078
5089
  z-index: 3;
5079
- `, DialogCard = react.forwardRef(function(props, ref) {
5090
+ `, DialogCard = react.forwardRef(function(props, forwardedRef) {
5080
5091
  var _a;
5081
5092
  const {
5082
5093
  __unstable_autoFocus: autoFocus,
5083
5094
  __unstable_hideCloseButton: hideCloseButton,
5084
5095
  children,
5085
- contentRef,
5096
+ contentRef: forwardedContentRef,
5086
5097
  footer,
5087
5098
  header,
5088
5099
  id,
@@ -5093,10 +5104,13 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5093
5104
  scheme,
5094
5105
  shadow: shadowProp,
5095
5106
  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(
5107
+ } = 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;
5108
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useImperativeHandle(
5109
+ forwardedContentRef,
5110
+ () => contentRef.current
5111
+ ), react.useEffect(() => {
5112
+ autoFocus && ref.current && focusFirstDescendant(ref.current);
5113
+ }, [autoFocus, ref]), useGlobalKeyDown(
5100
5114
  react.useCallback(
5101
5115
  (event) => {
5102
5116
  if (!isTopLayer || !onClose) return;
@@ -5116,17 +5130,9 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5116
5130
  ),
5117
5131
  [rootElement]
5118
5132
  );
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
- );
5133
+ const setRef = react.useCallback((el) => {
5134
+ setRootElement(el), ref.current = el;
5135
+ }, []);
5130
5136
  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
5137
  showHeader && /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(Flex, { align: "center", padding: 3, children: [
5132
5138
  /* @__PURE__ */ jsxRuntime.jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsxRuntime.jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
@@ -5142,7 +5148,7 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5142
5148
  }
5143
5149
  ) })
5144
5150
  ] }) }),
5145
- /* @__PURE__ */ jsxRuntime.jsx(DialogContent, { flex: 1, ref: setContentRef, tabIndex: -1, children }),
5151
+ /* @__PURE__ */ jsxRuntime.jsx(DialogContent, { flex: 1, ref: contentRef, tabIndex: -1, children }),
5146
5152
  footer && /* @__PURE__ */ jsxRuntime.jsx(DialogFooter, { children: footer })
5147
5153
  ] }) }) });
5148
5154
  }), Dialog = react.forwardRef(function(props, ref) {
@@ -5418,7 +5424,7 @@ function useMenuController(props) {
5418
5424
  const Root$5 = styledComponents.styled(Box)`
5419
5425
  outline: none;
5420
5426
  overflow: auto;
5421
- `, Menu = react.forwardRef(function(props, ref) {
5427
+ `, Menu = react.forwardRef(function(props, forwardedRef) {
5422
5428
  const {
5423
5429
  children,
5424
5430
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -5436,7 +5442,9 @@ const Root$5 = styledComponents.styled(Box)`
5436
5442
  shouldFocus = props.focusFirst && "first" || props.focusLast && "last" || null,
5437
5443
  space = 1,
5438
5444
  ...restProps
5439
- } = props, forwardedRef = useForwardedRef(ref), { isTopLayer } = useLayer(), {
5445
+ } = props, ref = react.useRef(null);
5446
+ react.useImperativeHandle(forwardedRef, () => ref.current);
5447
+ const { isTopLayer } = useLayer(), {
5440
5448
  activeElement,
5441
5449
  activeIndex,
5442
5450
  handleItemMouseEnter,
@@ -5447,9 +5455,9 @@ const Root$5 = styledComponents.styled(Box)`
5447
5455
  setRootElement
5448
5456
  } = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = react.useCallback(
5449
5457
  (el) => {
5450
- setRootElement(el), forwardedRef.current = el;
5458
+ setRootElement(el), ref.current = el;
5451
5459
  },
5452
- [forwardedRef, setRootElement]
5460
+ [setRootElement]
5453
5461
  );
5454
5462
  react.useEffect(() => {
5455
5463
  onItemSelect && onItemSelect(activeIndex);
@@ -5884,9 +5892,9 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
5884
5892
  onItemClick,
5885
5893
  onItemMouseEnter = menu.onMouseEnter,
5886
5894
  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(
5895
+ } = menu, [rootElement, setRootElement] = react.useState(null), active = !!activeElement && activeElement === rootElement, ref = react.useRef(null);
5896
+ react.useImperativeHandle(forwardedRef, () => ref.current), react.useEffect(() => mount(rootElement, selectedProp), [mount, rootElement, selectedProp]);
5897
+ const handleClick = react.useCallback(
5890
5898
  (event) => {
5891
5899
  disabled || (onClick && onClick(event), onItemClick && onItemClick());
5892
5900
  },
@@ -5902,12 +5910,9 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
5902
5910
  paddingLeft
5903
5911
  }),
5904
5912
  [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
- );
5913
+ ), hotkeysFontSize = useArrayProp(fontSize2).map((s) => s - 1), setRef = react.useCallback((el) => {
5914
+ ref.current = el, setRootElement(el);
5915
+ }, []);
5911
5916
  return /* @__PURE__ */ jsxRuntime.jsxs(
5912
5917
  Selectable,
5913
5918
  {
@@ -6046,16 +6051,21 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
6046
6051
  padding = 2,
6047
6052
  selected,
6048
6053
  ...restProps
6049
- } = props, elementRef = react.useRef(null), focusedRef = react.useRef(!1), handleBlur = react.useCallback(() => {
6054
+ } = props, ref = react.useRef(null), focusedRef = react.useRef(!1);
6055
+ react.useImperativeHandle(
6056
+ forwardedRef,
6057
+ () => ref.current
6058
+ );
6059
+ const handleBlur = react.useCallback(() => {
6050
6060
  focusedRef.current = !1;
6051
6061
  }, []), handleFocus = react.useCallback(
6052
6062
  (event) => {
6053
6063
  focusedRef.current = !0, onFocus && onFocus(event);
6054
6064
  },
6055
6065
  [onFocus]
6056
- ), ref = useForwardedRef(forwardedRef);
6066
+ );
6057
6067
  return react.useEffect(() => {
6058
- focused && !focusedRef.current && (elementRef.current && elementRef.current.focus(), focusedRef.current = !0);
6068
+ focused && !focusedRef.current && (ref.current && ref.current.focus(), focusedRef.current = !0);
6059
6069
  }, [focused]), /* @__PURE__ */ jsxRuntime.jsx(
6060
6070
  CustomButton,
6061
6071
  {
@@ -6070,9 +6080,7 @@ const MenuItem = react.forwardRef(function(props, forwardedRef) {
6070
6080
  onBlur: handleBlur,
6071
6081
  onFocus: handleFocus,
6072
6082
  padding,
6073
- ref: (el) => {
6074
- elementRef.current = el, ref.current = el;
6075
- },
6083
+ ref,
6076
6084
  role: "tab",
6077
6085
  selected,
6078
6086
  tabIndex: selected ? 0 : -1,
@@ -6355,9 +6363,12 @@ function _focusItemElement(el) {
6355
6363
  }
6356
6364
  }
6357
6365
  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(() => {
6366
+ react.forwardRef(function(props, forwardedRef) {
6367
+ 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);
6368
+ react.useImperativeHandle(
6369
+ forwardedRef,
6370
+ () => ref.current
6371
+ ), react.useEffect(() => {
6361
6372
  focusedElementRef.current = focusedElement;
6362
6373
  }, [focusedElement]), react.useEffect(() => {
6363
6374
  stateRef.current = state;
@@ -6451,12 +6462,12 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6451
6462
  [onFocus]
6452
6463
  );
6453
6464
  return react.useEffect(() => {
6454
- if (!forwardedRef.current) return;
6465
+ if (!ref.current) return;
6455
6466
  const _itemElements = Array.from(
6456
- forwardedRef.current.querySelectorAll('[data-ui="TreeItem"]')
6467
+ ref.current.querySelectorAll('[data-ui="TreeItem"]')
6457
6468
  );
6458
6469
  setItemElements(_itemElements);
6459
- }, [children, forwardedRef]), /* @__PURE__ */ jsxRuntime.jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
6470
+ }, [children, ref]), /* @__PURE__ */ jsxRuntime.jsx(TreeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
6460
6471
  Stack,
6461
6472
  {
6462
6473
  as: "ul",
@@ -6464,7 +6475,7 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6464
6475
  ...restProps,
6465
6476
  onFocus: handleFocus,
6466
6477
  onKeyDown: handleKeyDown,
6467
- ref: forwardedRef,
6478
+ ref,
6468
6479
  role: "tree",
6469
6480
  space,
6470
6481
  children