@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
@@ -7,7 +7,7 @@ import { box, text, textOverflow, animatedSpinnerIcon, spinner, button, buttonLo
7
7
  import { useEffectEvent } from "use-effect-event";
8
8
  import { SpinnerIcon, CloseIcon, ChevronRightIcon } from "@sanity/icons";
9
9
  import { isValidElementType } from "react-is";
10
- import { detectOverflow, flip, offset, shift, arrow, hide, useFloating, autoUpdate } from "@floating-ui/react-dom";
10
+ import { detectOverflow, autoPlacement, flip, offset, shift, arrow, hide, useFloating, autoUpdate } from "@floating-ui/react-dom";
11
11
  import { motion, AnimatePresence } from "framer-motion";
12
12
  import { createPortal } from "react-dom";
13
13
  import { assignInlineVars } from "@vanilla-extract/dynamic";
@@ -551,7 +551,10 @@ function getElementRef(element) {
551
551
  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);
552
552
  }
553
553
  function useCard() {
554
- return useContext(CardContext);
554
+ const card2 = useContext(CardContext);
555
+ if (!card2)
556
+ throw new Error("useCard(): missing context value");
557
+ return card2;
555
558
  }
556
559
  const key = "@sanity/ui/context/portal", elementKey = Symbol.for(`${key}/element`), elementMap = globalScope;
557
560
  elementMap[elementKey] = null;
@@ -577,11 +580,10 @@ function Portal(props) {
577
580
  } = props, card2 = useCard(), portal = usePortal(), portalElement = (name ? portal.elements && portal.elements[name] : portal.element) || portal.elements?.default;
578
581
  if (!portalElement)
579
582
  return null;
580
- const t0 = card2?.scheme || "light";
583
+ let t0;
584
+ $[0] !== card2.scheme || $[1] !== children ? (t0 = /* @__PURE__ */ jsx(CardProvider, { tone: "transparent", scheme: card2.scheme, children }), $[0] = card2.scheme, $[1] = children, $[2] = t0) : t0 = $[2];
581
585
  let t1;
582
- $[0] !== children || $[1] !== t0 ? (t1 = /* @__PURE__ */ jsx(CardProvider, { tone: "transparent", scheme: t0, children }), $[0] = children, $[1] = t0, $[2] = t1) : t1 = $[2];
583
- let t2;
584
- return $[3] !== portalElement || $[4] !== t1 ? (t2 = createPortal(t1, portalElement), $[3] = portalElement, $[4] = t1, $[5] = t2) : t2 = $[5], t2;
586
+ return $[3] !== portalElement || $[4] !== t0 ? (t1 = createPortal(t0, portalElement), $[3] = portalElement, $[4] = t0, $[5] = t1) : t1 = $[5], t1;
585
587
  }
586
588
  function getLayerContext(contextValue) {
587
589
  if (!isRecord(contextValue) || contextValue.version !== 0)
@@ -801,7 +803,7 @@ function Card(props) {
801
803
  tone: t5,
802
804
  ...rest
803
805
  } = 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]);
804
- 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;
806
+ 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 = useContext(CardContext), tone = toneProp === "inherit" ? parent?.tone : toneProp, scheme = schemeProp === void 0 ? parent?.scheme : schemeProp, t6 = scheme === parent?.scheme ? void 0 : scheme;
805
807
  let t7;
806
808
  $[13] !== className || $[14] !== t6 || $[15] !== tone ? (t7 = card({
807
809
  className,
@@ -817,7 +819,7 @@ function Card(props) {
817
819
  const t14 = scheme ?? "light", t15 = tone ?? "default", t16 = parent?.unstable_CompatProvider;
818
820
  let t17;
819
821
  if ($[28] !== node || $[29] !== t14 || $[30] !== t15 || $[31] !== t16 ? (t17 = /* @__PURE__ */ 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) {
820
- const CompatProvider = parent.unstable_CompatProvider, t18 = scheme ?? "light", t19 = tone ?? parent?.tone ?? "default";
822
+ const CompatProvider = parent.unstable_CompatProvider, t18 = scheme ?? "light", t19 = tone ?? parent.tone;
821
823
  let t20;
822
824
  return $[33] !== CompatProvider || $[34] !== node || $[35] !== t18 || $[36] !== t19 ? (t20 = /* @__PURE__ */ jsx(CompatProvider, { scheme: t18, tone: t19, children: node }), $[33] = CompatProvider, $[34] = node, $[35] = t18, $[36] = t19, $[37] = t20) : t20 = $[37], t20;
823
825
  }
@@ -1098,6 +1100,7 @@ function Popover(props) {
1098
1100
  overflow = "hidden",
1099
1101
  padding,
1100
1102
  placement: placementProp = "bottom",
1103
+ placementStrategy = "flip",
1101
1104
  portal,
1102
1105
  preventOverflow = !0,
1103
1106
  radius = 3,
@@ -1115,12 +1118,14 @@ function Popover(props) {
1115
1118
  useImperativeHandle(forwardedRef, () => ref.current);
1116
1119
  const referenceWidthRef = useRef(void 0), middleware = useMemo(() => {
1117
1120
  const ret = [];
1118
- return (constrainSize || preventOverflow) && ret.push(flip({
1121
+ return (constrainSize || preventOverflow) && (placementStrategy === "autoPlacement" ? ret.push(autoPlacement({
1122
+ allowedPlacements: [placementProp].concat(fallbackPlacements)
1123
+ })) : ret.push(flip({
1119
1124
  boundary: floatingBoundary || void 0,
1120
1125
  fallbackPlacements,
1121
1126
  padding: DEFAULT_POPOVER_PADDING,
1122
1127
  rootBoundary
1123
- })), ret.push(offset({
1128
+ }))), ret.push(offset({
1124
1129
  mainAxis: DEFAULT_POPOVER_DISTANCE
1125
1130
  })), (constrainSize || matchReferenceWidth) && ret.push(size({
1126
1131
  apply({
@@ -1146,7 +1151,7 @@ function Popover(props) {
1146
1151
  padding: DEFAULT_POPOVER_PADDING,
1147
1152
  strategy: "referenceHidden"
1148
1153
  })), ret;
1149
- }, [animate, arrowProp, constrainSize, fallbackPlacements, floatingBoundary, margins, matchReferenceWidth, preventOverflow, referenceBoundary]), {
1154
+ }, [animate, arrowProp, constrainSize, fallbackPlacements, floatingBoundary, placementProp, placementStrategy, margins, matchReferenceWidth, preventOverflow, referenceBoundary]), {
1150
1155
  x,
1151
1156
  y,
1152
1157
  middlewareData,
@@ -1181,7 +1186,7 @@ function Popover(props) {
1181
1186
  /* @__PURE__ */ jsx(PopoverLayer, { ...rest, __unstable_margins: margins, animate, arrow: arrowProp, arrowRef: setArrow, arrowX, arrowY, as, className: popover({
1182
1187
  className
1183
1188
  }), hidden: referenceHidden, maxWidth: widthProp, overflow, padding, placement, radius, ref: setFloating, scheme, shadow, originX, originY, strategy, x, y, zOffset, children: content })
1184
- ] }), children = open && (portal ? /* @__PURE__ */ jsx(Portal, { __unstable_name: typeof portal == "string" ? portal : void 0, children: /* @__PURE__ */ jsx(CardProvider, { tone: tone === "inherit" ? card2?.tone ?? "default" : tone, scheme: scheme ?? "light", children: node_1 }) }) : node_1);
1189
+ ] }), children = open && (portal ? /* @__PURE__ */ jsx(Portal, { __unstable_name: typeof portal == "string" ? portal : void 0, children: /* @__PURE__ */ jsx(CardProvider, { tone: tone === "inherit" ? card2.tone : tone, scheme: scheme ?? "light", children: node_1 }) }) : node_1);
1185
1190
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1186
1191
  animate ? /* @__PURE__ */ jsx(AnimatePresence, { children }) : children,
1187
1192
  child
@@ -2000,44 +2005,6 @@ function usePrefersDark(t0) {
2000
2005
  function _temp$1() {
2001
2006
  return !1;
2002
2007
  }
2003
- function PortalProvider(props) {
2004
- const $ = c(7), {
2005
- boundaryElement,
2006
- children,
2007
- element,
2008
- __unstable_elements: elementsProp
2009
- } = props, elements = useUnique(elementsProp), fallbackElement = useSyncExternalStore(emptySubscribe, _temp, _temp2);
2010
- let t0;
2011
- const t1 = boundaryElement || null, t2 = element || fallbackElement;
2012
- let t3;
2013
- $[0] !== elements || $[1] !== t1 || $[2] !== t2 ? (t3 = {
2014
- version: 0,
2015
- boundaryElement: t1,
2016
- element: t2,
2017
- elements
2018
- }, $[0] = elements, $[1] = t1, $[2] = t2, $[3] = t3) : t3 = $[3], t0 = t3;
2019
- const value = t0;
2020
- let t4;
2021
- return $[4] !== children || $[5] !== value ? (t4 = /* @__PURE__ */ jsx(PortalContext.Provider, { value, children }), $[4] = children, $[5] = value, $[6] = t4) : t4 = $[6], t4;
2022
- }
2023
- function _temp2() {
2024
- return null;
2025
- }
2026
- function _temp() {
2027
- return document.body;
2028
- }
2029
- const emptySubscribe = () => () => {
2030
- };
2031
- function useUnique(value) {
2032
- const valueRef = useRef(value);
2033
- return _isEqual(valueRef.current, value) || (valueRef.current = value), valueRef.current;
2034
- }
2035
- function _isEqual(objA, objB) {
2036
- if (!objA || !objB)
2037
- return objA === objB;
2038
- const keysA = Object.keys(objA), keysB = Object.keys(objB);
2039
- return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
2040
- }
2041
2008
  function useDelayedState(initialState) {
2042
2009
  const $ = c(3), [state, setState] = useState(initialState), delayedAction = useRef(void 0);
2043
2010
  let t0;
@@ -2250,7 +2217,7 @@ function Tooltip(props) {
2250
2217
  }), originX, originY, padding, placement, radius, ref: setFloating, scheme, shadow, style: {
2251
2218
  ...floatingStyles,
2252
2219
  maxWidth: tooltipMaxWidth > 0 ? `${tooltipMaxWidth}px` : void 0
2253
- }, tone, zOffset, children: content }), children = showTooltip && (portalProp ? /* @__PURE__ */ jsx(Portal, { __unstable_name: typeof portalProp == "string" ? portalProp : void 0, children: /* @__PURE__ */ jsx(CardProvider, { tone: tone === "inherit" ? card2?.tone ?? "default" : tone, scheme: scheme ?? "light", children: node_0 }) }) : node_0);
2220
+ }, tone, zOffset, children: content }), children = showTooltip && (portalProp ? /* @__PURE__ */ jsx(Portal, { __unstable_name: typeof portalProp == "string" ? portalProp : void 0, children: /* @__PURE__ */ jsx(CardProvider, { tone: tone === "inherit" ? card2.tone : tone, scheme: scheme ?? "light", children: node_0 }) }) : node_0);
2254
2221
  return /* @__PURE__ */ jsxs(Fragment, { children: [
2255
2222
  animate ? /* @__PURE__ */ jsx(AnimatePresence, { children }) : children,
2256
2223
  child
@@ -2280,6 +2247,44 @@ function useCloseOnMouseLeave(t0) {
2280
2247
  let t3;
2281
2248
  $[7] !== isInsideGroup || $[8] !== showTooltip ? (t3 = [isInsideGroup, showTooltip], $[7] = isInsideGroup, $[8] = showTooltip, $[9] = t3) : t3 = $[9], useEffect(t2, t3);
2282
2249
  }
2250
+ function PortalProvider(props) {
2251
+ const $ = c(7), {
2252
+ boundaryElement,
2253
+ children,
2254
+ element,
2255
+ __unstable_elements: elementsProp
2256
+ } = props, elements = useUnique(elementsProp), fallbackElement = useSyncExternalStore(emptySubscribe, _temp, _temp2);
2257
+ let t0;
2258
+ const t1 = boundaryElement || null, t2 = element || fallbackElement;
2259
+ let t3;
2260
+ $[0] !== elements || $[1] !== t1 || $[2] !== t2 ? (t3 = {
2261
+ version: 0,
2262
+ boundaryElement: t1,
2263
+ element: t2,
2264
+ elements
2265
+ }, $[0] = elements, $[1] = t1, $[2] = t2, $[3] = t3) : t3 = $[3], t0 = t3;
2266
+ const value = t0;
2267
+ let t4;
2268
+ return $[4] !== children || $[5] !== value ? (t4 = /* @__PURE__ */ jsx(PortalContext.Provider, { value, children }), $[4] = children, $[5] = value, $[6] = t4) : t4 = $[6], t4;
2269
+ }
2270
+ function _temp2() {
2271
+ return null;
2272
+ }
2273
+ function _temp() {
2274
+ return document.body;
2275
+ }
2276
+ const emptySubscribe = () => () => {
2277
+ };
2278
+ function useUnique(value) {
2279
+ const valueRef = useRef(value);
2280
+ return _isEqual(valueRef.current, value) || (valueRef.current = value), valueRef.current;
2281
+ }
2282
+ function _isEqual(objA, objB) {
2283
+ if (!objA || !objB)
2284
+ return objA === objB;
2285
+ const keysA = Object.keys(objA), keysB = Object.keys(objB);
2286
+ return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
2287
+ }
2283
2288
  export {
2284
2289
  AnimatedSpinnerIcon,
2285
2290
  Arrow,