@sanity/ui 2.1.2 → 2.1.3-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import {BaseTheme as BaseTheme_2} from '@sanity/ui/theme'
4
4
  import {Component} from 'react'
5
+ import {Context} from 'react'
5
6
  import {CSSObject} from '@sanity/ui/theme'
6
7
  import {DetailedHTMLProps} from 'react'
7
8
  import {ElementType} from 'react'
@@ -718,7 +719,7 @@ export declare const Dialog: ForwardRefExoticComponent<
718
719
  /**
719
720
  * @internal
720
721
  */
721
- export declare const DialogContext: React.Context<DialogContextValue>
722
+ export declare const DialogContext: Context<DialogContextValue>
722
723
 
723
724
  /**
724
725
  * This API might change. DO NOT USE IN PRODUCTION.
@@ -2465,7 +2466,7 @@ export declare const Tooltip: ForwardRefExoticComponent<
2465
2466
  /**
2466
2467
  * @beta
2467
2468
  */
2468
- export declare const TooltipDelayGroupContext: React.Context<TooltipDelayGroupContextValue | null>
2469
+ export declare const TooltipDelayGroupContext: Context<TooltipDelayGroupContextValue | null>
2469
2470
 
2470
2471
  /**
2471
2472
  * @beta
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import {BaseTheme as BaseTheme_2} from '@sanity/ui/theme'
4
4
  import {Component} from 'react'
5
+ import {Context} from 'react'
5
6
  import {CSSObject} from '@sanity/ui/theme'
6
7
  import {DetailedHTMLProps} from 'react'
7
8
  import {ElementType} from 'react'
@@ -718,7 +719,7 @@ export declare const Dialog: ForwardRefExoticComponent<
718
719
  /**
719
720
  * @internal
720
721
  */
721
- export declare const DialogContext: React.Context<DialogContextValue>
722
+ export declare const DialogContext: Context<DialogContextValue>
722
723
 
723
724
  /**
724
725
  * This API might change. DO NOT USE IN PRODUCTION.
@@ -2465,7 +2466,7 @@ export declare const Tooltip: ForwardRefExoticComponent<
2465
2466
  /**
2466
2467
  * @beta
2467
2468
  */
2468
- export declare const TooltipDelayGroupContext: React.Context<TooltipDelayGroupContextValue | null>
2469
+ export declare const TooltipDelayGroupContext: Context<TooltipDelayGroupContextValue | null>
2469
2470
 
2470
2471
  /**
2471
2472
  * @beta
package/dist/index.esm.js CHANGED
@@ -517,9 +517,11 @@ function getGlobalScope() {
517
517
  return global;
518
518
  throw new Error("@sanity/ui: could not locate global scope");
519
519
  }
520
- const globalScope = getGlobalScope(), key$8 = Symbol.for("@sanity/ui/context/theme");
521
- globalScope[key$8] = globalScope[key$8] || createContext(null);
522
- const ThemeContext = globalScope[key$8];
520
+ const globalScope = getGlobalScope();
521
+ function createGlobalScopedContext(key2, defaultValue) {
522
+ return typeof document > "u" ? createContext(defaultValue) : (globalScope[key2] = globalScope[key2] || createContext(defaultValue), globalScope[key2]);
523
+ }
524
+ const key$8 = Symbol.for("@sanity/ui/context/theme"), ThemeContext = createGlobalScopedContext(key$8, null);
523
525
  function ThemeProvider(props) {
524
526
  const parentTheme = useContext(ThemeContext), {
525
527
  children,
@@ -2819,9 +2821,10 @@ const Root$k = styled.div(
2819
2821
  /* @__PURE__ */ jsx(StrokePath, { d: strokePath, mask: "url(#stroke-mask)", strokeWidth: strokeWidth * 2 }),
2820
2822
  /* @__PURE__ */ jsx(ShapePath, { d: fillPath })
2821
2823
  ] }) });
2822
- }), key$7 = Symbol.for("@sanity/ui/context/boundaryElement");
2823
- globalScope[key$7] = globalScope[key$7] || createContext(null);
2824
- const BoundaryElementContext = globalScope[key$7];
2824
+ }), key$7 = Symbol.for("@sanity/ui/context/boundaryElement"), BoundaryElementContext = createGlobalScopedContext(
2825
+ key$7,
2826
+ null
2827
+ );
2825
2828
  function BoundaryElementProvider(props) {
2826
2829
  const { children, element } = props, value = useMemo(() => ({ version: 0, element }), [element]);
2827
2830
  return /* @__PURE__ */ jsx(BoundaryElementContext.Provider, { value, children });
@@ -2909,9 +2912,7 @@ function getLayerContext(contextValue) {
2909
2912
  return contextValue;
2910
2913
  throw new Error("could not get layer context");
2911
2914
  }
2912
- const key$6 = Symbol.for("@sanity/ui/context/layer");
2913
- globalScope[key$6] = globalScope[key$6] || createContext(null);
2914
- const LayerContext = globalScope[key$6];
2915
+ const key$6 = Symbol.for("@sanity/ui/context/layer"), LayerContext = createGlobalScopedContext(key$6, null);
2915
2916
  function useLayer() {
2916
2917
  const value = useContext(LayerContext);
2917
2918
  if (!value)
@@ -3065,9 +3066,7 @@ const defaultContextValue = {
3065
3066
  get element() {
3066
3067
  return typeof document > "u" ? null : (globalScope[elementKey] || (globalScope[elementKey] = document.createElement("div"), globalScope[elementKey].setAttribute("data-portal", ""), document.body.appendChild(globalScope[elementKey])), globalScope[elementKey]);
3067
3068
  }
3068
- };
3069
- globalScope[key$5] = globalScope[key$5] || createContext(defaultContextValue);
3070
- const PortalContext = globalScope[key$5];
3069
+ }, PortalContext = createGlobalScopedContext(key$5, defaultContextValue);
3071
3070
  function usePortal() {
3072
3071
  const value = useContext(PortalContext);
3073
3072
  if (!value)
@@ -3091,17 +3090,21 @@ function _isEqual(objA, objB) {
3091
3090
  const keysA = Object.keys(objA), keysB = Object.keys(objB);
3092
3091
  return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
3093
3092
  }
3094
- const __BROWSER__ = typeof document < "u";
3095
3093
  function PortalProvider(props) {
3096
- const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), value = useMemo(() => ({
3094
+ const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = useSyncExternalStore(
3095
+ emptySubscribe$1,
3096
+ () => document.body,
3097
+ () => null
3098
+ ), value = useMemo(() => ({
3097
3099
  version: 0,
3098
3100
  boundaryElement: boundaryElement || null,
3099
- element: element || __BROWSER__ && document.body || null,
3101
+ element: element || fallbackElement,
3100
3102
  elements
3101
- }), [boundaryElement, element, elements]);
3103
+ }), [boundaryElement, element, elements, fallbackElement]);
3102
3104
  return /* @__PURE__ */ jsx(PortalContext.Provider, { value, children });
3103
3105
  }
3104
- const Root$i = styled.div`
3106
+ const emptySubscribe$1 = () => () => {
3107
+ }, Root$i = styled.div`
3105
3108
  display: block;
3106
3109
  width: 0;
3107
3110
  height: 0;
@@ -4318,9 +4321,7 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
4318
4321
  })
4319
4322
  );
4320
4323
  TooltipCard.displayName = "TooltipCard";
4321
- const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup");
4322
- globalScope[key$4] = globalScope[key$4] || createContext(null);
4323
- const TooltipDelayGroupContext = globalScope[key$4];
4324
+ const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup"), TooltipDelayGroupContext = createGlobalScopedContext(key$4, null);
4324
4325
  function useTooltipDelayGroup() {
4325
4326
  return useContext(TooltipDelayGroupContext);
4326
4327
  }
@@ -5057,9 +5058,9 @@ function animationDialogStyle(props) {
5057
5058
  }
5058
5059
  ` : css``;
5059
5060
  }
5060
- const key$3 = Symbol.for("@sanity/ui/context/dialog");
5061
- globalScope[key$3] = globalScope[key$3] || createContext({ version: 0 });
5062
- const DialogContext = globalScope[key$3];
5061
+ const key$3 = Symbol.for("@sanity/ui/context/dialog"), DialogContext = createGlobalScopedContext(key$3, {
5062
+ version: 0
5063
+ });
5063
5064
  function useDialog() {
5064
5065
  return useContext(DialogContext);
5065
5066
  }
@@ -5292,9 +5293,7 @@ const Root$6 = styled.kbd`
5292
5293
  `, Hotkeys = forwardRef(function(props, ref) {
5293
5294
  const { fontSize: fontSize2, keys, padding, radius, space: spaceProp = 0.5, ...restProps } = props, space = useArrayProp(spaceProp);
5294
5295
  return !keys || keys.length === 0 ? /* @__PURE__ */ jsx(Fragment, {}) : /* @__PURE__ */ jsx(Root$6, { "data-ui": "Hotkeys", ...restProps, ref, children: /* @__PURE__ */ jsx(Inline, { as: "span", space, children: keys.map((key2, i) => /* @__PURE__ */ jsx(Key, { fontSize: fontSize2, padding, radius, children: key2 }, i)) }) });
5295
- }), key$2 = Symbol.for("@sanity/ui/context/menu");
5296
- globalScope[key$2] = globalScope[key$2] || createContext(null);
5297
- const MenuContext = globalScope[key$2];
5296
+ }), key$2 = Symbol.for("@sanity/ui/context/menu"), MenuContext = createGlobalScopedContext(key$2, null);
5298
5297
  function _isFocusable(element) {
5299
5298
  return isHTMLAnchorElement(element) && element.getAttribute("data-disabled") !== "true" || isHTMLButtonElement(element) && !element.disabled;
5300
5299
  }
@@ -6231,9 +6230,7 @@ function useMounted() {
6231
6230
  );
6232
6231
  }
6233
6232
  const subscribe = () => () => {
6234
- }, key$1 = Symbol.for("@sanity/ui/context/toast");
6235
- globalScope[key$1] = globalScope[key$1] || createContext(null);
6236
- const ToastContext = globalScope[key$1], Root$1 = styled(Layer)`
6233
+ }, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styled(Layer)`
6237
6234
  position: fixed;
6238
6235
  top: 0;
6239
6236
  left: 0;
@@ -6391,9 +6388,7 @@ function _focusItemElement(el) {
6391
6388
  firstChild && firstChild instanceof HTMLElement && firstChild.focus();
6392
6389
  }
6393
6390
  }
6394
- const key = Symbol.for("@sanity/ui/context/tree");
6395
- globalScope[key] = globalScope[key] || createContext(null);
6396
- const TreeContext = globalScope[key], Tree = memo(
6391
+ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalScopedContext(key, null), Tree = memo(
6397
6392
  forwardRef(function(props, ref) {
6398
6393
  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);
6399
6394
  useEffect(() => {