@sanity/ui 3.0.0-static.31 → 3.0.0-static.33

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.
Files changed (39) hide show
  1. package/dist/_chunks-cjs/_visual-editing.cjs +55 -50
  2. package/dist/_chunks-cjs/_visual-editing.cjs.map +1 -1
  3. package/dist/_chunks-es/_visual-editing.js +56 -51
  4. package/dist/_chunks-es/_visual-editing.js.map +1 -1
  5. package/dist/_visual-editing.d.cts +10 -0
  6. package/dist/_visual-editing.d.ts +10 -0
  7. package/dist/css/index.cjs +2 -4
  8. package/dist/css/index.cjs.map +1 -1
  9. package/dist/css/index.css +1 -1
  10. package/dist/css/index.d.cts +1 -1
  11. package/dist/css/index.d.ts +1 -1
  12. package/dist/css/index.js +2 -4
  13. package/dist/css/index.js.map +1 -1
  14. package/dist/index.cjs +80 -79
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +11 -1
  17. package/dist/index.d.ts +11 -1
  18. package/dist/index.js +82 -81
  19. package/dist/index.js.map +1 -1
  20. package/package.json +6 -6
  21. package/src/core/{primitives/root/Root.tsx → Root.tsx} +6 -4
  22. package/src/core/{primitives/root/RootProvider.tsx → RootProvider.tsx} +5 -5
  23. package/src/core/__workshop__/boundary.tsx +28 -0
  24. package/src/core/__workshop__/index.ts +14 -0
  25. package/src/core/index.ts +4 -2
  26. package/src/core/primitives/card/card.tsx +4 -3
  27. package/src/core/primitives/card/useCard.ts +8 -2
  28. package/src/core/primitives/grid/types.ts +1 -1
  29. package/src/core/primitives/popover/popover.tsx +31 -12
  30. package/src/core/primitives/tooltip/tooltip.tsx +1 -4
  31. package/src/core/utils/portal/portal.tsx +1 -5
  32. package/src/css/components/toast/toast.css.ts +2 -2
  33. package/src/css/primitives/root/root.css.ts +6 -2
  34. package/src/css/primitives/root/root.ts +2 -2
  35. package/src/css/props/gridColumnStart/types.ts +1 -1
  36. package/dist/css/layers.css +0 -4
  37. package/dist/css/primitives/popover/popover.css +0 -4
  38. package/src/core/primitives/root/__workshop__/boundary.tsx +0 -5
  39. package/src/core/primitives/root/__workshop__/index.ts +0 -8
@@ -540,7 +540,10 @@ function getElementRef(element) {
540
540
  return mayWarn ? element.ref : (getter = Object.getOwnPropertyDescriptor(element, "ref")?.get, mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning, mayWarn ? element.props.ref : element.props.ref || element.ref);
541
541
  }
542
542
  function useCard() {
543
- return react.useContext(CardContext);
543
+ const card = react.useContext(CardContext);
544
+ if (!card)
545
+ throw new Error("useCard(): missing context value");
546
+ return card;
544
547
  }
545
548
  const key = "@sanity/ui/context/portal", elementKey = Symbol.for(`${key}/element`), elementMap = globalScope;
546
549
  elementMap[elementKey] = null;
@@ -566,11 +569,10 @@ function Portal(props) {
566
569
  } = props, card = useCard(), portal = usePortal(), portalElement = (name ? portal.elements && portal.elements[name] : portal.element) || portal.elements?.default;
567
570
  if (!portalElement)
568
571
  return null;
569
- const t0 = card?.scheme || "light";
572
+ let t0;
573
+ $[0] !== card.scheme || $[1] !== children ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(CardProvider, { tone: "transparent", scheme: card.scheme, children }), $[0] = card.scheme, $[1] = children, $[2] = t0) : t0 = $[2];
570
574
  let t1;
571
- $[0] !== children || $[1] !== t0 ? (t1 = /* @__PURE__ */ jsxRuntime.jsx(CardProvider, { tone: "transparent", scheme: t0, children }), $[0] = children, $[1] = t0, $[2] = t1) : t1 = $[2];
572
- let t2;
573
- return $[3] !== portalElement || $[4] !== t1 ? (t2 = reactDom.createPortal(t1, portalElement), $[3] = portalElement, $[4] = t1, $[5] = t2) : t2 = $[5], t2;
575
+ return $[3] !== portalElement || $[4] !== t0 ? (t1 = reactDom.createPortal(t0, portalElement), $[3] = portalElement, $[4] = t0, $[5] = t1) : t1 = $[5], t1;
574
576
  }
575
577
  function getLayerContext(contextValue) {
576
578
  if (!isRecord(contextValue) || contextValue.version !== 0)
@@ -790,7 +792,7 @@ function Card(props) {
790
792
  tone: t5,
791
793
  ...rest
792
794
  } = t0, $[0] = t0, $[1] = className, $[2] = disabled, $[3] = pressed, $[4] = rest, $[5] = schemeProp, $[6] = selected, $[7] = style, $[8] = t1, $[9] = t2, $[10] = t3, $[11] = t4, $[12] = t5) : (className = $[1], disabled = $[2], pressed = $[3], rest = $[4], schemeProp = $[5], selected = $[6], style = $[7], t1 = $[8], t2 = $[9], t3 = $[10], t4 = $[11], t5 = $[12]);
793
- const checkered = t1 === void 0 ? !1 : t1, focusRing = t2 === void 0 ? !1 : t2, as = t3 === void 0 ? DEFAULT_CARD_ELEMENT : t3, radius = t4 === void 0 ? 0 : t4, toneProp = t5 === void 0 ? "default" : t5, parent = useCard(), tone = toneProp === "inherit" ? parent?.tone : toneProp, scheme = schemeProp === void 0 ? parent?.scheme : schemeProp, t6 = scheme === parent?.scheme ? void 0 : scheme;
795
+ const checkered = t1 === void 0 ? !1 : t1, focusRing = t2 === void 0 ? !1 : t2, as = t3 === void 0 ? DEFAULT_CARD_ELEMENT : t3, radius = t4 === void 0 ? 0 : t4, toneProp = t5 === void 0 ? "default" : t5, parent = react.useContext(CardContext), tone = toneProp === "inherit" ? parent?.tone : toneProp, scheme = schemeProp === void 0 ? parent?.scheme : schemeProp, t6 = scheme === parent?.scheme ? void 0 : scheme;
794
796
  let t7;
795
797
  $[13] !== className || $[14] !== t6 || $[15] !== tone ? (t7 = css.card({
796
798
  className,
@@ -806,7 +808,7 @@ function Card(props) {
806
808
  const t14 = scheme ?? "light", t15 = tone ?? "default", t16 = parent?.unstable_CompatProvider;
807
809
  let t17;
808
810
  if ($[28] !== node || $[29] !== t14 || $[30] !== t15 || $[31] !== t16 ? (t17 = /* @__PURE__ */ jsxRuntime.jsx(CardProvider, { scheme: t14, tone: t15, unstable_CompatProvider: t16, children: node }), $[28] = node, $[29] = t14, $[30] = t15, $[31] = t16, $[32] = t17) : t17 = $[32], node = t17, parent?.unstable_CompatProvider) {
809
- const CompatProvider = parent.unstable_CompatProvider, t18 = scheme ?? "light", t19 = tone ?? parent?.tone ?? "default";
811
+ const CompatProvider = parent.unstable_CompatProvider, t18 = scheme ?? "light", t19 = tone ?? parent.tone;
810
812
  let t20;
811
813
  return $[33] !== CompatProvider || $[34] !== node || $[35] !== t18 || $[36] !== t19 ? (t20 = /* @__PURE__ */ jsxRuntime.jsx(CompatProvider, { scheme: t18, tone: t19, children: node }), $[33] = CompatProvider, $[34] = node, $[35] = t18, $[36] = t19, $[37] = t20) : t20 = $[37], t20;
812
814
  }
@@ -1087,6 +1089,7 @@ function Popover(props) {
1087
1089
  overflow = "hidden",
1088
1090
  padding,
1089
1091
  placement: placementProp = "bottom",
1092
+ placementStrategy = "flip",
1090
1093
  portal,
1091
1094
  preventOverflow = !0,
1092
1095
  radius = 3,
@@ -1104,12 +1107,14 @@ function Popover(props) {
1104
1107
  react.useImperativeHandle(forwardedRef, () => ref.current);
1105
1108
  const referenceWidthRef = react.useRef(void 0), middleware = react.useMemo(() => {
1106
1109
  const ret = [];
1107
- return (constrainSize || preventOverflow) && ret.push(reactDom$1.flip({
1110
+ return (constrainSize || preventOverflow) && (placementStrategy === "autoPlacement" ? ret.push(reactDom$1.autoPlacement({
1111
+ allowedPlacements: [placementProp].concat(fallbackPlacements)
1112
+ })) : ret.push(reactDom$1.flip({
1108
1113
  boundary: floatingBoundary || void 0,
1109
1114
  fallbackPlacements,
1110
1115
  padding: DEFAULT_POPOVER_PADDING,
1111
1116
  rootBoundary
1112
- })), ret.push(reactDom$1.offset({
1117
+ }))), ret.push(reactDom$1.offset({
1113
1118
  mainAxis: DEFAULT_POPOVER_DISTANCE
1114
1119
  })), (constrainSize || matchReferenceWidth) && ret.push(size({
1115
1120
  apply({
@@ -1135,7 +1140,7 @@ function Popover(props) {
1135
1140
  padding: DEFAULT_POPOVER_PADDING,
1136
1141
  strategy: "referenceHidden"
1137
1142
  })), ret;
1138
- }, [animate, arrowProp, constrainSize, fallbackPlacements, floatingBoundary, margins, matchReferenceWidth, preventOverflow, referenceBoundary]), {
1143
+ }, [animate, arrowProp, constrainSize, fallbackPlacements, floatingBoundary, placementProp, placementStrategy, margins, matchReferenceWidth, preventOverflow, referenceBoundary]), {
1139
1144
  x,
1140
1145
  y,
1141
1146
  middlewareData,
@@ -1170,7 +1175,7 @@ function Popover(props) {
1170
1175
  /* @__PURE__ */ jsxRuntime.jsx(PopoverLayer, { ...rest, __unstable_margins: margins, animate, arrow: arrowProp, arrowRef: setArrow, arrowX, arrowY, as, className: css.popover({
1171
1176
  className
1172
1177
  }), hidden: referenceHidden, maxWidth: widthProp, overflow, padding, placement, radius, ref: setFloating, scheme, shadow, originX, originY, strategy, x, y, zOffset, children: content })
1173
- ] }), children = open && (portal ? /* @__PURE__ */ jsxRuntime.jsx(Portal, { __unstable_name: typeof portal == "string" ? portal : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(CardProvider, { tone: tone === "inherit" ? card?.tone ?? "default" : tone, scheme: scheme ?? "light", children: node_1 }) }) : node_1);
1178
+ ] }), children = open && (portal ? /* @__PURE__ */ jsxRuntime.jsx(Portal, { __unstable_name: typeof portal == "string" ? portal : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(CardProvider, { tone: tone === "inherit" ? card.tone : tone, scheme: scheme ?? "light", children: node_1 }) }) : node_1);
1174
1179
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1175
1180
  animate ? /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children }) : children,
1176
1181
  child
@@ -1989,44 +1994,6 @@ function usePrefersDark(t0) {
1989
1994
  function _temp$1() {
1990
1995
  return !1;
1991
1996
  }
1992
- function PortalProvider(props) {
1993
- const $ = compilerRuntime.c(7), {
1994
- boundaryElement,
1995
- children,
1996
- element,
1997
- __unstable_elements: elementsProp
1998
- } = props, elements = useUnique(elementsProp), fallbackElement = react.useSyncExternalStore(emptySubscribe, _temp, _temp2);
1999
- let t0;
2000
- const t1 = boundaryElement || null, t2 = element || fallbackElement;
2001
- let t3;
2002
- $[0] !== elements || $[1] !== t1 || $[2] !== t2 ? (t3 = {
2003
- version: 0,
2004
- boundaryElement: t1,
2005
- element: t2,
2006
- elements
2007
- }, $[0] = elements, $[1] = t1, $[2] = t2, $[3] = t3) : t3 = $[3], t0 = t3;
2008
- const value = t0;
2009
- let t4;
2010
- return $[4] !== children || $[5] !== value ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children }), $[4] = children, $[5] = value, $[6] = t4) : t4 = $[6], t4;
2011
- }
2012
- function _temp2() {
2013
- return null;
2014
- }
2015
- function _temp() {
2016
- return document.body;
2017
- }
2018
- const emptySubscribe = () => () => {
2019
- };
2020
- function useUnique(value) {
2021
- const valueRef = react.useRef(value);
2022
- return _isEqual(valueRef.current, value) || (valueRef.current = value), valueRef.current;
2023
- }
2024
- function _isEqual(objA, objB) {
2025
- if (!objA || !objB)
2026
- return objA === objB;
2027
- const keysA = Object.keys(objA), keysB = Object.keys(objB);
2028
- return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
2029
- }
2030
1997
  function useDelayedState(initialState) {
2031
1998
  const $ = compilerRuntime.c(3), [state, setState] = react.useState(initialState), delayedAction = react.useRef(void 0);
2032
1999
  let t0;
@@ -2239,7 +2206,7 @@ function Tooltip(props) {
2239
2206
  }), originX, originY, padding, placement, radius, ref: setFloating, scheme, shadow, style: {
2240
2207
  ...floatingStyles,
2241
2208
  maxWidth: tooltipMaxWidth > 0 ? `${tooltipMaxWidth}px` : void 0
2242
- }, tone, zOffset, children: content }), children = showTooltip && (portalProp ? /* @__PURE__ */ jsxRuntime.jsx(Portal, { __unstable_name: typeof portalProp == "string" ? portalProp : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(CardProvider, { tone: tone === "inherit" ? card?.tone ?? "default" : tone, scheme: scheme ?? "light", children: node_0 }) }) : node_0);
2209
+ }, tone, zOffset, children: content }), children = showTooltip && (portalProp ? /* @__PURE__ */ jsxRuntime.jsx(Portal, { __unstable_name: typeof portalProp == "string" ? portalProp : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(CardProvider, { tone: tone === "inherit" ? card.tone : tone, scheme: scheme ?? "light", children: node_0 }) }) : node_0);
2243
2210
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2244
2211
  animate ? /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children }) : children,
2245
2212
  child
@@ -2269,6 +2236,44 @@ function useCloseOnMouseLeave(t0) {
2269
2236
  let t3;
2270
2237
  $[7] !== isInsideGroup || $[8] !== showTooltip ? (t3 = [isInsideGroup, showTooltip], $[7] = isInsideGroup, $[8] = showTooltip, $[9] = t3) : t3 = $[9], react.useEffect(t2, t3);
2271
2238
  }
2239
+ function PortalProvider(props) {
2240
+ const $ = compilerRuntime.c(7), {
2241
+ boundaryElement,
2242
+ children,
2243
+ element,
2244
+ __unstable_elements: elementsProp
2245
+ } = props, elements = useUnique(elementsProp), fallbackElement = react.useSyncExternalStore(emptySubscribe, _temp, _temp2);
2246
+ let t0;
2247
+ const t1 = boundaryElement || null, t2 = element || fallbackElement;
2248
+ let t3;
2249
+ $[0] !== elements || $[1] !== t1 || $[2] !== t2 ? (t3 = {
2250
+ version: 0,
2251
+ boundaryElement: t1,
2252
+ element: t2,
2253
+ elements
2254
+ }, $[0] = elements, $[1] = t1, $[2] = t2, $[3] = t3) : t3 = $[3], t0 = t3;
2255
+ const value = t0;
2256
+ let t4;
2257
+ return $[4] !== children || $[5] !== value ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children }), $[4] = children, $[5] = value, $[6] = t4) : t4 = $[6], t4;
2258
+ }
2259
+ function _temp2() {
2260
+ return null;
2261
+ }
2262
+ function _temp() {
2263
+ return document.body;
2264
+ }
2265
+ const emptySubscribe = () => () => {
2266
+ };
2267
+ function useUnique(value) {
2268
+ const valueRef = react.useRef(value);
2269
+ return _isEqual(valueRef.current, value) || (valueRef.current = value), valueRef.current;
2270
+ }
2271
+ function _isEqual(objA, objB) {
2272
+ if (!objA || !objB)
2273
+ return objA === objB;
2274
+ const keysA = Object.keys(objA), keysB = Object.keys(objB);
2275
+ return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
2276
+ }
2272
2277
  exports.AnimatedSpinnerIcon = AnimatedSpinnerIcon;
2273
2278
  exports.Arrow = Arrow;
2274
2279
  exports.BoundaryElementContext = BoundaryElementContext;