@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.js CHANGED
@@ -514,9 +514,11 @@ function getGlobalScope() {
514
514
  return global;
515
515
  throw new Error("@sanity/ui: could not locate global scope");
516
516
  }
517
- const globalScope = getGlobalScope(), key$8 = Symbol.for("@sanity/ui/context/theme");
518
- globalScope[key$8] = globalScope[key$8] || react.createContext(null);
519
- const ThemeContext = globalScope[key$8];
517
+ const globalScope = getGlobalScope();
518
+ function createGlobalScopedContext(key2, defaultValue) {
519
+ return typeof document > "u" ? react.createContext(defaultValue) : (globalScope[key2] = globalScope[key2] || react.createContext(defaultValue), globalScope[key2]);
520
+ }
521
+ const key$8 = Symbol.for("@sanity/ui/context/theme"), ThemeContext = createGlobalScopedContext(key$8, null);
520
522
  function ThemeProvider(props) {
521
523
  const parentTheme = react.useContext(ThemeContext), {
522
524
  children,
@@ -2816,9 +2818,10 @@ const Root$k = styledComponents.styled.div(
2816
2818
  /* @__PURE__ */ jsxRuntime.jsx(StrokePath, { d: strokePath, mask: "url(#stroke-mask)", strokeWidth: strokeWidth * 2 }),
2817
2819
  /* @__PURE__ */ jsxRuntime.jsx(ShapePath, { d: fillPath })
2818
2820
  ] }) });
2819
- }), key$7 = Symbol.for("@sanity/ui/context/boundaryElement");
2820
- globalScope[key$7] = globalScope[key$7] || react.createContext(null);
2821
- const BoundaryElementContext = globalScope[key$7];
2821
+ }), key$7 = Symbol.for("@sanity/ui/context/boundaryElement"), BoundaryElementContext = createGlobalScopedContext(
2822
+ key$7,
2823
+ null
2824
+ );
2822
2825
  function BoundaryElementProvider(props) {
2823
2826
  const { children, element } = props, value = react.useMemo(() => ({ version: 0, element }), [element]);
2824
2827
  return /* @__PURE__ */ jsxRuntime.jsx(BoundaryElementContext.Provider, { value, children });
@@ -2906,9 +2909,7 @@ function getLayerContext(contextValue) {
2906
2909
  return contextValue;
2907
2910
  throw new Error("could not get layer context");
2908
2911
  }
2909
- const key$6 = Symbol.for("@sanity/ui/context/layer");
2910
- globalScope[key$6] = globalScope[key$6] || react.createContext(null);
2911
- const LayerContext = globalScope[key$6];
2912
+ const key$6 = Symbol.for("@sanity/ui/context/layer"), LayerContext = createGlobalScopedContext(key$6, null);
2912
2913
  function useLayer() {
2913
2914
  const value = react.useContext(LayerContext);
2914
2915
  if (!value)
@@ -3062,9 +3063,7 @@ const defaultContextValue = {
3062
3063
  get element() {
3063
3064
  return typeof document > "u" ? null : (globalScope[elementKey] || (globalScope[elementKey] = document.createElement("div"), globalScope[elementKey].setAttribute("data-portal", ""), document.body.appendChild(globalScope[elementKey])), globalScope[elementKey]);
3064
3065
  }
3065
- };
3066
- globalScope[key$5] = globalScope[key$5] || react.createContext(defaultContextValue);
3067
- const PortalContext = globalScope[key$5];
3066
+ }, PortalContext = createGlobalScopedContext(key$5, defaultContextValue);
3068
3067
  function usePortal() {
3069
3068
  const value = react.useContext(PortalContext);
3070
3069
  if (!value)
@@ -3088,17 +3087,21 @@ function _isEqual(objA, objB) {
3088
3087
  const keysA = Object.keys(objA), keysB = Object.keys(objB);
3089
3088
  return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
3090
3089
  }
3091
- const __BROWSER__ = typeof document < "u";
3092
3090
  function PortalProvider(props) {
3093
- const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), value = react.useMemo(() => ({
3091
+ const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = react.useSyncExternalStore(
3092
+ emptySubscribe$1,
3093
+ () => document.body,
3094
+ () => null
3095
+ ), value = react.useMemo(() => ({
3094
3096
  version: 0,
3095
3097
  boundaryElement: boundaryElement || null,
3096
- element: element || __BROWSER__ && document.body || null,
3098
+ element: element || fallbackElement,
3097
3099
  elements
3098
- }), [boundaryElement, element, elements]);
3100
+ }), [boundaryElement, element, elements, fallbackElement]);
3099
3101
  return /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children });
3100
3102
  }
3101
- const Root$i = styledComponents.styled.div`
3103
+ const emptySubscribe$1 = () => () => {
3104
+ }, Root$i = styledComponents.styled.div`
3102
3105
  display: block;
3103
3106
  width: 0;
3104
3107
  height: 0;
@@ -4315,9 +4318,7 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
4315
4318
  })
4316
4319
  );
4317
4320
  TooltipCard.displayName = "TooltipCard";
4318
- const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup");
4319
- globalScope[key$4] = globalScope[key$4] || react.createContext(null);
4320
- const TooltipDelayGroupContext = globalScope[key$4];
4321
+ const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup"), TooltipDelayGroupContext = createGlobalScopedContext(key$4, null);
4321
4322
  function useTooltipDelayGroup() {
4322
4323
  return react.useContext(TooltipDelayGroupContext);
4323
4324
  }
@@ -5054,9 +5055,9 @@ function animationDialogStyle(props) {
5054
5055
  }
5055
5056
  ` : styledComponents.css``;
5056
5057
  }
5057
- const key$3 = Symbol.for("@sanity/ui/context/dialog");
5058
- globalScope[key$3] = globalScope[key$3] || react.createContext({ version: 0 });
5059
- const DialogContext = globalScope[key$3];
5058
+ const key$3 = Symbol.for("@sanity/ui/context/dialog"), DialogContext = createGlobalScopedContext(key$3, {
5059
+ version: 0
5060
+ });
5060
5061
  function useDialog() {
5061
5062
  return react.useContext(DialogContext);
5062
5063
  }
@@ -5289,9 +5290,7 @@ const Root$6 = styledComponents.styled.kbd`
5289
5290
  `, Hotkeys = react.forwardRef(function(props, ref) {
5290
5291
  const { fontSize: fontSize2, keys, padding, radius, space: spaceProp = 0.5, ...restProps } = props, space = useArrayProp(spaceProp);
5291
5292
  return !keys || keys.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}) : /* @__PURE__ */ jsxRuntime.jsx(Root$6, { "data-ui": "Hotkeys", ...restProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx(Inline, { as: "span", space, children: keys.map((key2, i) => /* @__PURE__ */ jsxRuntime.jsx(Key, { fontSize: fontSize2, padding, radius, children: key2 }, i)) }) });
5292
- }), key$2 = Symbol.for("@sanity/ui/context/menu");
5293
- globalScope[key$2] = globalScope[key$2] || react.createContext(null);
5294
- const MenuContext = globalScope[key$2];
5293
+ }), key$2 = Symbol.for("@sanity/ui/context/menu"), MenuContext = createGlobalScopedContext(key$2, null);
5295
5294
  function _isFocusable(element) {
5296
5295
  return isHTMLAnchorElement(element) && element.getAttribute("data-disabled") !== "true" || isHTMLButtonElement(element) && !element.disabled;
5297
5296
  }
@@ -6228,9 +6227,7 @@ function useMounted() {
6228
6227
  );
6229
6228
  }
6230
6229
  const subscribe = () => () => {
6231
- }, key$1 = Symbol.for("@sanity/ui/context/toast");
6232
- globalScope[key$1] = globalScope[key$1] || react.createContext(null);
6233
- const ToastContext = globalScope[key$1], Root$1 = styledComponents.styled(Layer)`
6230
+ }, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styledComponents.styled(Layer)`
6234
6231
  position: fixed;
6235
6232
  top: 0;
6236
6233
  left: 0;
@@ -6388,9 +6385,7 @@ function _focusItemElement(el) {
6388
6385
  firstChild && firstChild instanceof HTMLElement && firstChild.focus();
6389
6386
  }
6390
6387
  }
6391
- const key = Symbol.for("@sanity/ui/context/tree");
6392
- globalScope[key] = globalScope[key] || react.createContext(null);
6393
- const TreeContext = globalScope[key], Tree = react.memo(
6388
+ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalScopedContext(key, null), Tree = react.memo(
6394
6389
  react.forwardRef(function(props, ref) {
6395
6390
  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);
6396
6391
  react.useEffect(() => {