@sanity/ui 2.14.4-canary.2 → 2.14.4

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.
@@ -4,41 +4,33 @@ function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
6
6
  var ReactIs__default = /* @__PURE__ */ _interopDefaultCompat(ReactIs);
7
- const createColorTheme = theme.createColorTheme, hexToRgb = theme.hexToRgb, hslToRgb = theme.hslToRgb, multiply = theme.multiply, parseColor = theme.parseColor, rgbToHex = theme.rgbToHex, rgbToHsl = theme.rgbToHsl, rgba = theme.rgba, screen = theme.screen, studioTheme = theme.buildTheme(), EMPTY_ARRAY = [], EMPTY_RECORD = {}, POPOVER_MOTION_PROPS = {
8
- outerVariants: {
9
- initial: {
10
- scale: 0.97,
11
- willChange: "transform"
12
- },
13
- hidden: {
14
- opacity: 0
15
- },
16
- visible: {
17
- opacity: 1,
18
- transition: {
19
- when: "beforeChildren",
20
- duration: 0.1
21
- }
22
- },
23
- scaleIn: {
24
- scale: 1
25
- },
26
- scaleOut: {
27
- scale: 0.97
28
- }
7
+ const createColorTheme = theme.createColorTheme, hexToRgb = theme.hexToRgb, hslToRgb = theme.hslToRgb, multiply = theme.multiply, parseColor = theme.parseColor, rgbToHex = theme.rgbToHex, rgbToHsl = theme.rgbToHsl, rgba = theme.rgba, screen = theme.screen, studioTheme = theme.buildTheme(), EMPTY_ARRAY = [], EMPTY_RECORD = {}, POPOVER_MOTION_CONTENT_OPACITY_PROPERTY = "--motion-content-opacity", POPOVER_MOTION_PROPS = {
8
+ /**
9
+ * These variants makes use of special timing, by using a negative opacity as a starting position,
10
+ * as well as double opacity as the end position.
11
+ * The purpose of this is to make the tooltip/popover container appear before the content, and when exiting
12
+ * we want the content to disappear faster than the container.
13
+ */
14
+ initial: {
15
+ opacity: 0.5,
16
+ // the nagative opacity here, as well as the double opacity further down, are to make the content appear after the backgdrop, and when exiting the content should disappear first.
17
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY]: -1,
18
+ scale: 0.97,
19
+ willChange: "transform"
29
20
  },
30
- innerVariants: {
31
- hidden: {
32
- opacity: 0
33
- },
34
- visible: {
35
- opacity: 1
36
- }
21
+ animate: {
22
+ opacity: 2,
23
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY]: 1,
24
+ scale: 1
25
+ },
26
+ exit: {
27
+ opacity: 0,
28
+ [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY]: -1,
29
+ scale: 0.97
37
30
  },
38
31
  transition: {
39
- type: "spring",
40
- visualDuration: 0.2,
41
- bounce: 0.25
32
+ duration: 0.4,
33
+ type: "spring"
42
34
  }
43
35
  };
44
36
  function _fillCSSObject(keys, value) {
@@ -3129,7 +3121,7 @@ const StyledLayer = /* @__PURE__ */ styledComponents.styled.div.withConfig({
3129
3121
  zIndex
3130
3122
  }, $[14] = style, $[15] = zIndex, $[16] = t5) : t5 = $[16];
3131
3123
  let t6;
3132
- return $[17] !== children || $[18] !== handleFocus || $[19] !== restProps || $[20] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(StyledLayer, { "data-ui": "Layer", ...restProps, onFocus: handleFocus, ref, style: t5, children }), $[17] = children, $[18] = handleFocus, $[19] = restProps, $[20] = t5, $[21] = t6) : t6 = $[21], t6;
3124
+ return $[17] !== children || $[18] !== handleFocus || $[19] !== restProps || $[20] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(StyledLayer, { ...restProps, "data-ui": "Layer", onFocus: handleFocus, ref, style: t5, children }), $[17] = children, $[18] = handleFocus, $[19] = restProps, $[20] = t5, $[21] = t6) : t6 = $[21], t6;
3133
3125
  }), Layer = react.forwardRef(function(props, ref) {
3134
3126
  const $ = reactCompilerRuntime.c(11);
3135
3127
  let children, restProps, t0;
@@ -3425,11 +3417,8 @@ function calcMaxWidth(params) {
3425
3417
  const MotionCard$1 = styledComponents.styled(framerMotion.motion.create(Card)).withConfig({
3426
3418
  displayName: "MotionCard",
3427
3419
  componentId: "sc-ihg31s-0"
3428
- })`&:not([hidden]){display:flex;}flex-direction:column;width:max-content;min-width:min-content;will-change:transform;`, MotionFlex = styledComponents.styled(framerMotion.motion.create(Flex)).withConfig({
3429
- displayName: "MotionFlex",
3430
- componentId: "sc-ihg31s-1"
3431
- })`will-change:opacity;`, PopoverCard = react.memo(react.forwardRef(function(props, ref) {
3432
- const $ = reactCompilerRuntime.c(66);
3420
+ })`&:not([hidden]){display:flex;}flex-direction:column;width:max-content;min-width:min-content;& > *{opacity:var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY},1);will-change:opacity;}`, PopoverCard = react.memo(react.forwardRef(function(props, ref) {
3421
+ const $ = reactCompilerRuntime.c(60);
3433
3422
  let animate, arrow, arrowRef, arrowX, arrowY, children, marginsProp, originX, originY, overflow, padding, placement, radius, restProps, scheme, shadow, strategy, style, tone, width, xProp, yProp;
3434
3423
  $[0] !== props ? ({
3435
3424
  __unstable_margins: marginsProp,
@@ -3487,22 +3476,18 @@ const MotionCard$1 = styledComponents.styled(framerMotion.motion.create(Card)).w
3487
3476
  }, $[33] = t5, $[34] = t6, $[35] = t7) : t7 = $[35], t4 = t7;
3488
3477
  const arrowStyle = t4, t8 = restProps;
3489
3478
  let t9;
3490
- $[36] !== animate ? (t9 = animate ? ["hidden", "initial"] : void 0, $[36] = animate, $[37] = t9) : t9 = $[37];
3479
+ $[36] !== animate ? (t9 = animate ? POPOVER_MOTION_PROPS : {}, $[36] = animate, $[37] = t9) : t9 = $[37];
3491
3480
  let t10;
3492
- $[38] !== animate ? (t10 = animate ? ["visible", "scaleIn"] : void 0, $[38] = animate, $[39] = t10) : t10 = $[39];
3481
+ $[38] !== children || $[39] !== padding ? (t10 = /* @__PURE__ */ jsxRuntime.jsx(Flex, { direction: "column", flex: 1, padding, children }), $[38] = children, $[39] = padding, $[40] = t10) : t10 = $[40];
3493
3482
  let t11;
3494
- $[40] !== animate ? (t11 = animate ? ["hidden", "scaleOut"] : void 0, $[40] = animate, $[41] = t11) : t11 = $[41];
3483
+ $[41] !== overflow || $[42] !== t10 ? (t11 = /* @__PURE__ */ jsxRuntime.jsx(Flex, { "data-ui": "Popover__wrapper", direction: "column", flex: 1, overflow, children: t10 }), $[41] = overflow, $[42] = t10, $[43] = t11) : t11 = $[43];
3495
3484
  let t12;
3496
- $[42] !== children || $[43] !== padding ? (t12 = /* @__PURE__ */ jsxRuntime.jsx(Flex, { direction: "column", flex: 1, padding, children }), $[42] = children, $[43] = padding, $[44] = t12) : t12 = $[44];
3485
+ $[44] !== arrow || $[45] !== arrowRef || $[46] !== arrowStyle ? (t12 = arrow && /* @__PURE__ */ jsxRuntime.jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_POPOVER_ARROW_WIDTH, height: DEFAULT_POPOVER_ARROW_HEIGHT, radius: DEFAULT_POPOVER_ARROW_RADIUS }), $[44] = arrow, $[45] = arrowRef, $[46] = arrowStyle, $[47] = t12) : t12 = $[47];
3497
3486
  let t13;
3498
- $[45] !== overflow || $[46] !== t12 ? (t13 = /* @__PURE__ */ jsxRuntime.jsx(MotionFlex, { "data-ui": "Popover__wrapper", direction: "column", flex: 1, overflow, variants: POPOVER_MOTION_PROPS.innerVariants, transition: POPOVER_MOTION_PROPS.transition, children: t12 }), $[45] = overflow, $[46] = t12, $[47] = t13) : t13 = $[47];
3499
- let t14;
3500
- $[48] !== arrow || $[49] !== arrowRef || $[50] !== arrowStyle ? (t14 = arrow && /* @__PURE__ */ jsxRuntime.jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_POPOVER_ARROW_WIDTH, height: DEFAULT_POPOVER_ARROW_HEIGHT, radius: DEFAULT_POPOVER_ARROW_RADIUS }), $[48] = arrow, $[49] = arrowRef, $[50] = arrowStyle, $[51] = t14) : t14 = $[51];
3501
- let t15;
3502
- return $[52] !== placement || $[53] !== radius || $[54] !== ref || $[55] !== rootStyle2 || $[56] !== scheme || $[57] !== shadow || $[58] !== t10 || $[59] !== t11 || $[60] !== t13 || $[61] !== t14 || $[62] !== t8 || $[63] !== t9 || $[64] !== tone ? (t15 = /* @__PURE__ */ jsxRuntime.jsxs(MotionCard$1, { "data-ui": "Popover", ...t8, "data-placement": placement, radius, ref, scheme, shadow, sizing: "border", style: rootStyle2, tone, variants: POPOVER_MOTION_PROPS.outerVariants, transition: POPOVER_MOTION_PROPS.transition, initial: t9, animate: t10, exit: t11, children: [
3503
- t13,
3504
- t14
3505
- ] }), $[52] = placement, $[53] = radius, $[54] = ref, $[55] = rootStyle2, $[56] = scheme, $[57] = shadow, $[58] = t10, $[59] = t11, $[60] = t13, $[61] = t14, $[62] = t8, $[63] = t9, $[64] = tone, $[65] = t15) : t15 = $[65], t15;
3487
+ return $[48] !== placement || $[49] !== radius || $[50] !== ref || $[51] !== rootStyle2 || $[52] !== scheme || $[53] !== shadow || $[54] !== t11 || $[55] !== t12 || $[56] !== t8 || $[57] !== t9 || $[58] !== tone ? (t13 = /* @__PURE__ */ jsxRuntime.jsxs(MotionCard$1, { "data-ui": "Popover", ...t8, "data-placement": placement, radius, ref, scheme, shadow, sizing: "border", style: rootStyle2, tone, ...t9, children: [
3488
+ t11,
3489
+ t12
3490
+ ] }), $[48] = placement, $[49] = radius, $[50] = ref, $[51] = rootStyle2, $[52] = scheme, $[53] = shadow, $[54] = t11, $[55] = t12, $[56] = t8, $[57] = t9, $[58] = tone, $[59] = t13) : t13 = $[59], t13;
3506
3491
  }));
3507
3492
  PopoverCard.displayName = "Memo(ForwardRef(PopoverCard))";
3508
3493
  const ViewportOverlay = () => {
@@ -4431,8 +4416,8 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
4431
4416
  }, MotionCard = styledComponents.styled(framerMotion.motion.create(Card)).withConfig({
4432
4417
  displayName: "MotionCard",
4433
4418
  componentId: "sc-1xn138w-0"
4434
- })`will-change:transform;`, TooltipCard = react.memo(react.forwardRef(function(props, ref) {
4435
- const $ = reactCompilerRuntime.c(48);
4419
+ })`& > *{opacity:var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY},1);will-change:opacity;}`, TooltipCard = react.memo(react.forwardRef(function(props, ref) {
4420
+ const $ = reactCompilerRuntime.c(42);
4436
4421
  let animate, arrow, arrowRef, arrowX, arrowY, children, originX, originY, padding, placement, radius, restProps, scheme, shadow, style;
4437
4422
  $[0] !== props ? ({
4438
4423
  animate,
@@ -4472,18 +4457,14 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
4472
4457
  }, $[21] = t4, $[22] = t5, $[23] = t6) : t6 = $[23], t3 = t6;
4473
4458
  const arrowStyle = t3, t7 = restProps;
4474
4459
  let t8;
4475
- $[24] !== animate ? (t8 = animate ? ["hidden", "initial"] : void 0, $[24] = animate, $[25] = t8) : t8 = $[25];
4460
+ $[24] !== animate ? (t8 = animate ? POPOVER_MOTION_PROPS : {}, $[24] = animate, $[25] = t8) : t8 = $[25];
4476
4461
  let t9;
4477
- $[26] !== animate ? (t9 = animate ? ["visible", "scaleIn"] : void 0, $[26] = animate, $[27] = t9) : t9 = $[27];
4462
+ $[26] !== arrow || $[27] !== arrowRef || $[28] !== arrowStyle ? (t9 = arrow && /* @__PURE__ */ jsxRuntime.jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_TOOLTIP_ARROW_WIDTH, height: DEFAULT_TOOLTIP_ARROW_HEIGHT, radius: DEFAULT_TOOLTIP_ARROW_RADIUS }), $[26] = arrow, $[27] = arrowRef, $[28] = arrowStyle, $[29] = t9) : t9 = $[29];
4478
4463
  let t10;
4479
- $[28] !== animate ? (t10 = animate ? ["hidden", "scaleOut"] : void 0, $[28] = animate, $[29] = t10) : t10 = $[29];
4480
- let t11;
4481
- $[30] !== arrow || $[31] !== arrowRef || $[32] !== arrowStyle ? (t11 = arrow && /* @__PURE__ */ jsxRuntime.jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_TOOLTIP_ARROW_WIDTH, height: DEFAULT_TOOLTIP_ARROW_HEIGHT, radius: DEFAULT_TOOLTIP_ARROW_RADIUS }), $[30] = arrow, $[31] = arrowRef, $[32] = arrowStyle, $[33] = t11) : t11 = $[33];
4482
- let t12;
4483
- return $[34] !== children || $[35] !== padding || $[36] !== placement || $[37] !== radius || $[38] !== ref || $[39] !== rootStyle2 || $[40] !== scheme || $[41] !== shadow || $[42] !== t10 || $[43] !== t11 || $[44] !== t7 || $[45] !== t8 || $[46] !== t9 ? (t12 = /* @__PURE__ */ jsxRuntime.jsxs(MotionCard, { "data-ui": "Tooltip__card", ...t7, "data-placement": placement, padding, radius, ref, scheme, shadow, style: rootStyle2, variants: POPOVER_MOTION_PROPS.outerVariants, transition: POPOVER_MOTION_PROPS.transition, initial: t8, animate: t9, exit: t10, children: [
4464
+ return $[30] !== children || $[31] !== padding || $[32] !== placement || $[33] !== radius || $[34] !== ref || $[35] !== rootStyle2 || $[36] !== scheme || $[37] !== shadow || $[38] !== t7 || $[39] !== t8 || $[40] !== t9 ? (t10 = /* @__PURE__ */ jsxRuntime.jsxs(MotionCard, { "data-ui": "Tooltip__card", ...t7, "data-placement": placement, padding, radius, ref, scheme, shadow, style: rootStyle2, ...t8, children: [
4484
4465
  children,
4485
- t11
4486
- ] }), $[34] = children, $[35] = padding, $[36] = placement, $[37] = radius, $[38] = ref, $[39] = rootStyle2, $[40] = scheme, $[41] = shadow, $[42] = t10, $[43] = t11, $[44] = t7, $[45] = t8, $[46] = t9, $[47] = t12) : t12 = $[47], t12;
4466
+ t9
4467
+ ] }), $[30] = children, $[31] = padding, $[32] = placement, $[33] = radius, $[34] = ref, $[35] = rootStyle2, $[36] = scheme, $[37] = shadow, $[38] = t7, $[39] = t8, $[40] = t9, $[41] = t10) : t10 = $[41], t10;
4487
4468
  }));
4488
4469
  TooltipCard.displayName = "Memo(ForwardRef(TooltipCard))";
4489
4470
  const TooltipDelayGroupContext = createGlobalScopedContext("@sanity/ui/context/tooltipDelayGroup", null);
@@ -4577,7 +4558,19 @@ const StyledTooltip = styledComponents.styled(Layer).withConfig({
4577
4558
  }
4578
4559
  else
4579
4560
  setIsOpen(open, immediate ? 0 : open ? openDelay : closeDelay);
4580
- }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
4561
+ }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]), handleBlur = react.useCallback((e) => {
4562
+ handleIsOpenChange(!1), childProp?.props?.onBlur?.(e);
4563
+ }, [childProp?.props, handleIsOpenChange]), handleClick = react.useCallback((e_0) => {
4564
+ handleIsOpenChange(!1, !0), childProp?.props.onClick?.(e_0);
4565
+ }, [childProp?.props, handleIsOpenChange]), handleContextMenu = react.useCallback((e_1) => {
4566
+ handleIsOpenChange(!1, !0), childProp?.props.onContextMenu?.(e_1);
4567
+ }, [childProp?.props, handleIsOpenChange]), handleFocus = react.useCallback((e_2) => {
4568
+ handleIsOpenChange(!0), childProp?.props?.onFocus?.(e_2);
4569
+ }, [childProp?.props, handleIsOpenChange]), handleMouseEnter = react.useCallback((e_3) => {
4570
+ handleIsOpenChange(!0), childProp?.props?.onMouseEnter?.(e_3);
4571
+ }, [childProp?.props, handleIsOpenChange]), handleMouseLeave = react.useCallback((e_4) => {
4572
+ handleIsOpenChange(!1), childProp?.props?.onMouseLeave?.(e_4);
4573
+ }, [childProp?.props, handleIsOpenChange]);
4581
4574
  useCloseOnMouseLeave({
4582
4575
  handleIsOpenChange,
4583
4576
  referenceElement,
@@ -4594,27 +4587,7 @@ const StyledTooltip = styledComponents.styled(Layer).withConfig({
4594
4587
  return window.addEventListener("keydown", handleWindowKeyDown), () => {
4595
4588
  window.removeEventListener("keydown", handleWindowKeyDown);
4596
4589
  };
4597
- }, [handleIsOpenChange, showTooltip]);
4598
- const handleChildEvent = useEffectEvent.useEffectEvent((open_0, immediate_0) => handleIsOpenChange(open_0, immediate_0));
4599
- react.useEffect(() => {
4600
- if (!referenceElement) return;
4601
- const controller = new AbortController(), {
4602
- signal
4603
- } = controller;
4604
- return referenceElement.addEventListener("blur", () => handleChildEvent(!1), {
4605
- signal
4606
- }), referenceElement.addEventListener("focus", () => handleChildEvent(!0), {
4607
- signal
4608
- }), referenceElement.addEventListener("mouseenter", () => handleChildEvent(!0), {
4609
- signal
4610
- }), referenceElement.addEventListener("mouseleave", () => handleChildEvent(!1), {
4611
- signal
4612
- }), referenceElement.addEventListener("click", () => handleChildEvent(!1, !0), {
4613
- signal
4614
- }), referenceElement.addEventListener("contextmenu", () => handleChildEvent(!1, !0), {
4615
- signal
4616
- }), () => controller.abort();
4617
- }, [referenceElement]), react.useLayoutEffect(() => {
4590
+ }, [handleIsOpenChange, showTooltip]), react.useLayoutEffect(() => {
4618
4591
  const availableWidths = [...boundaryElement ? [boundaryElement.offsetWidth] : [], portalElement?.offsetWidth || document.body.offsetWidth];
4619
4592
  setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
4620
4593
  }, [boundaryElement, portalElement]);
@@ -4623,8 +4596,14 @@ const StyledTooltip = styledComponents.styled(Layer).withConfig({
4623
4596
  }, [update]), setFloating = react.useCallback((node) => {
4624
4597
  ref.current = node, refs.setFloating(node);
4625
4598
  }, [refs]), child = react.useMemo(() => childProp ? react.cloneElement(childProp, {
4599
+ onBlur: handleBlur,
4600
+ onFocus: handleFocus,
4601
+ onMouseEnter: handleMouseEnter,
4602
+ onMouseLeave: handleMouseLeave,
4603
+ onClick: handleClick,
4604
+ onContextMenu: handleContextMenu,
4626
4605
  ref: setReferenceElement
4627
- }) : null, [childProp]);
4606
+ }) : null, [childProp, handleBlur, handleClick, handleContextMenu, handleFocus, handleMouseEnter, handleMouseLeave]);
4628
4607
  if (react.useImperativeHandle(childProp ? getElementRef(childProp) : null, () => referenceElement, [referenceElement]), !child) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
4629
4608
  if (disabled) return child;
4630
4609
  const tooltip = /* @__PURE__ */ jsxRuntime.jsx(StyledTooltip, { "data-ui": "Tooltip", ...restProps, ref: setFloating, style: {
@@ -5335,6 +5314,7 @@ exports.Menu = Menu;
5335
5314
  exports.MenuDivider = MenuDivider;
5336
5315
  exports.MenuGroup = MenuGroup;
5337
5316
  exports.MenuItem = MenuItem;
5317
+ exports.POPOVER_MOTION_CONTENT_OPACITY_PROPERTY = POPOVER_MOTION_CONTENT_OPACITY_PROPERTY;
5338
5318
  exports.Popover = Popover;
5339
5319
  exports.Portal = Portal;
5340
5320
  exports.PortalProvider = PortalProvider;