@sanity/ui 2.14.3 → 2.14.4-canary.0

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.
@@ -10,33 +10,41 @@ import { motion, AnimatePresence } from "framer-motion";
10
10
  import { ResizeObserver } from "@juggle/resize-observer";
11
11
  import { createPortal } from "react-dom";
12
12
  import { useEffectEvent } from "use-effect-event";
13
- const createColorTheme = createColorTheme$1, hexToRgb = hexToRgb$1, hslToRgb = hslToRgb$1, multiply = multiply$1, parseColor = parseColor$1, rgbToHex = rgbToHex$1, rgbToHsl = rgbToHsl$1, rgba = rgba$1, screen = screen$1, studioTheme = buildTheme(), EMPTY_ARRAY = [], EMPTY_RECORD = {}, POPOVER_MOTION_CONTENT_OPACITY_PROPERTY = "--motion-content-opacity", POPOVER_MOTION_PROPS = {
14
- /**
15
- * These variants makes use of special timing, by using a negative opacity as a starting position,
16
- * as well as double opacity as the end position.
17
- * The purpose of this is to make the tooltip/popover container appear before the content, and when exiting
18
- * we want the content to disappear faster than the container.
19
- */
20
- initial: {
21
- opacity: 0.5,
22
- // 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.
23
- [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY]: -1,
24
- scale: 0.97,
25
- willChange: "transform"
26
- },
27
- animate: {
28
- opacity: 2,
29
- [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY]: 1,
30
- scale: 1
13
+ const createColorTheme = createColorTheme$1, hexToRgb = hexToRgb$1, hslToRgb = hslToRgb$1, multiply = multiply$1, parseColor = parseColor$1, rgbToHex = rgbToHex$1, rgbToHsl = rgbToHsl$1, rgba = rgba$1, screen = screen$1, studioTheme = buildTheme(), EMPTY_ARRAY = [], EMPTY_RECORD = {}, POPOVER_MOTION_PROPS = {
14
+ outerVariants: {
15
+ initial: {
16
+ scale: 0.97,
17
+ willChange: "transform"
18
+ },
19
+ hidden: {
20
+ opacity: 0
21
+ },
22
+ visible: {
23
+ opacity: 1,
24
+ transition: {
25
+ when: "beforeChildren",
26
+ duration: 0.09999999999999999
27
+ }
28
+ },
29
+ scaleIn: {
30
+ scale: 1
31
+ },
32
+ scaleOut: {
33
+ scale: 0.97
34
+ }
31
35
  },
32
- exit: {
33
- opacity: 0,
34
- [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY]: -1,
35
- scale: 0.97
36
+ innerVariants: {
37
+ hidden: {
38
+ opacity: 0
39
+ },
40
+ visible: {
41
+ opacity: 1
42
+ }
36
43
  },
37
44
  transition: {
38
- duration: 0.4,
39
- type: "spring"
45
+ type: "spring",
46
+ visualDuration: 0.3,
47
+ bounce: 0.25
40
48
  }
41
49
  };
42
50
  function _fillCSSObject(keys, value) {
@@ -3125,7 +3133,7 @@ const StyledLayer = /* @__PURE__ */ styled.div.withConfig({
3125
3133
  zIndex
3126
3134
  }, $[14] = style, $[15] = zIndex, $[16] = t5) : t5 = $[16];
3127
3135
  let t6;
3128
- return $[17] !== children || $[18] !== handleFocus || $[19] !== restProps || $[20] !== t5 ? (t6 = /* @__PURE__ */ 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;
3136
+ return $[17] !== children || $[18] !== handleFocus || $[19] !== restProps || $[20] !== t5 ? (t6 = /* @__PURE__ */ 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;
3129
3137
  }), Layer = forwardRef(function(props, ref) {
3130
3138
  const $ = c(11);
3131
3139
  let children, restProps, t0;
@@ -3421,8 +3429,11 @@ function calcMaxWidth(params) {
3421
3429
  const MotionCard$1 = styled(motion.create(Card)).withConfig({
3422
3430
  displayName: "MotionCard",
3423
3431
  componentId: "sc-ihg31s-0"
3424
- })`&: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 = memo(forwardRef(function(props, ref) {
3425
- const $ = c(60);
3432
+ })`&:not([hidden]){display:flex;}flex-direction:column;width:max-content;min-width:min-content;will-change:transform;`, MotionFlex = styled(motion.create(Flex)).withConfig({
3433
+ displayName: "MotionFlex",
3434
+ componentId: "sc-ihg31s-1"
3435
+ })`will-change:opacity;`, PopoverCard = memo(forwardRef(function(props, ref) {
3436
+ const $ = c(66);
3426
3437
  let animate, arrow2, arrowRef, arrowX, arrowY, children, marginsProp, originX, originY, overflow, padding, placement, radius, restProps, scheme, shadow, strategy, style, tone, width, xProp, yProp;
3427
3438
  $[0] !== props ? ({
3428
3439
  __unstable_margins: marginsProp,
@@ -3480,18 +3491,22 @@ const MotionCard$1 = styled(motion.create(Card)).withConfig({
3480
3491
  }, $[33] = t5, $[34] = t6, $[35] = t7) : t7 = $[35], t4 = t7;
3481
3492
  const arrowStyle = t4, t8 = restProps;
3482
3493
  let t9;
3483
- $[36] !== animate ? (t9 = animate ? POPOVER_MOTION_PROPS : {}, $[36] = animate, $[37] = t9) : t9 = $[37];
3494
+ $[36] !== animate ? (t9 = animate ? ["hidden", "initial"] : void 0, $[36] = animate, $[37] = t9) : t9 = $[37];
3484
3495
  let t10;
3485
- $[38] !== children || $[39] !== padding ? (t10 = /* @__PURE__ */ jsx(Flex, { direction: "column", flex: 1, padding, children }), $[38] = children, $[39] = padding, $[40] = t10) : t10 = $[40];
3496
+ $[38] !== animate ? (t10 = animate ? ["visible", "scaleIn"] : void 0, $[38] = animate, $[39] = t10) : t10 = $[39];
3486
3497
  let t11;
3487
- $[41] !== overflow || $[42] !== t10 ? (t11 = /* @__PURE__ */ jsx(Flex, { "data-ui": "Popover__wrapper", direction: "column", flex: 1, overflow, children: t10 }), $[41] = overflow, $[42] = t10, $[43] = t11) : t11 = $[43];
3498
+ $[40] !== animate ? (t11 = animate ? ["hidden", "scaleOut"] : void 0, $[40] = animate, $[41] = t11) : t11 = $[41];
3488
3499
  let t12;
3489
- $[44] !== arrow2 || $[45] !== arrowRef || $[46] !== arrowStyle ? (t12 = arrow2 && /* @__PURE__ */ jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_POPOVER_ARROW_WIDTH, height: DEFAULT_POPOVER_ARROW_HEIGHT, radius: DEFAULT_POPOVER_ARROW_RADIUS }), $[44] = arrow2, $[45] = arrowRef, $[46] = arrowStyle, $[47] = t12) : t12 = $[47];
3500
+ $[42] !== children || $[43] !== padding ? (t12 = /* @__PURE__ */ jsx(Flex, { direction: "column", flex: 1, padding, children }), $[42] = children, $[43] = padding, $[44] = t12) : t12 = $[44];
3490
3501
  let t13;
3491
- 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__ */ jsxs(MotionCard$1, { "data-ui": "Popover", ...t8, "data-placement": placement, radius, ref, scheme, shadow, sizing: "border", style: rootStyle2, tone, ...t9, children: [
3492
- t11,
3493
- t12
3494
- ] }), $[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;
3502
+ $[45] !== overflow || $[46] !== t12 ? (t13 = /* @__PURE__ */ 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];
3503
+ let t14;
3504
+ $[48] !== arrow2 || $[49] !== arrowRef || $[50] !== arrowStyle ? (t14 = arrow2 && /* @__PURE__ */ jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_POPOVER_ARROW_WIDTH, height: DEFAULT_POPOVER_ARROW_HEIGHT, radius: DEFAULT_POPOVER_ARROW_RADIUS }), $[48] = arrow2, $[49] = arrowRef, $[50] = arrowStyle, $[51] = t14) : t14 = $[51];
3505
+ let t15;
3506
+ 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__ */ 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: [
3507
+ t13,
3508
+ t14
3509
+ ] }), $[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;
3495
3510
  }));
3496
3511
  PopoverCard.displayName = "Memo(ForwardRef(PopoverCard))";
3497
3512
  const ViewportOverlay = () => {
@@ -4396,9 +4411,9 @@ function useDelayedState(initialState) {
4396
4411
  const action = () => {
4397
4412
  setState(nextState);
4398
4413
  };
4399
- if (delayedAction.current && (clearTimeout(delayedAction.current), delayedAction.current = void 0), !delay)
4414
+ if (!delay)
4400
4415
  return action();
4401
- delayedAction.current = setTimeout(action, delay);
4416
+ delayedAction.current && (clearTimeout(delayedAction.current), delayedAction.current = void 0), delayedAction.current = setTimeout(action, delay);
4402
4417
  }, $[0] = t0) : t0 = $[0];
4403
4418
  const onStateChange = t0;
4404
4419
  let t1;
@@ -4420,8 +4435,8 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
4420
4435
  }, MotionCard = styled(motion.create(Card)).withConfig({
4421
4436
  displayName: "MotionCard",
4422
4437
  componentId: "sc-1xn138w-0"
4423
- })`& > *{opacity:var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY},1);will-change:opacity;}`, TooltipCard = memo(forwardRef(function(props, ref) {
4424
- const $ = c(42);
4438
+ })`will-change:transform;`, TooltipCard = memo(forwardRef(function(props, ref) {
4439
+ const $ = c(48);
4425
4440
  let animate, arrow2, arrowRef, arrowX, arrowY, children, originX, originY, padding, placement, radius, restProps, scheme, shadow, style;
4426
4441
  $[0] !== props ? ({
4427
4442
  animate,
@@ -4461,14 +4476,18 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
4461
4476
  }, $[21] = t4, $[22] = t5, $[23] = t6) : t6 = $[23], t3 = t6;
4462
4477
  const arrowStyle = t3, t7 = restProps;
4463
4478
  let t8;
4464
- $[24] !== animate ? (t8 = animate ? POPOVER_MOTION_PROPS : {}, $[24] = animate, $[25] = t8) : t8 = $[25];
4479
+ $[24] !== animate ? (t8 = animate ? ["hidden", "initial"] : void 0, $[24] = animate, $[25] = t8) : t8 = $[25];
4465
4480
  let t9;
4466
- $[26] !== arrow2 || $[27] !== arrowRef || $[28] !== arrowStyle ? (t9 = arrow2 && /* @__PURE__ */ jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_TOOLTIP_ARROW_WIDTH, height: DEFAULT_TOOLTIP_ARROW_HEIGHT, radius: DEFAULT_TOOLTIP_ARROW_RADIUS }), $[26] = arrow2, $[27] = arrowRef, $[28] = arrowStyle, $[29] = t9) : t9 = $[29];
4481
+ $[26] !== animate ? (t9 = animate ? ["visible", "scaleIn"] : void 0, $[26] = animate, $[27] = t9) : t9 = $[27];
4467
4482
  let t10;
4468
- 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__ */ jsxs(MotionCard, { "data-ui": "Tooltip__card", ...t7, "data-placement": placement, padding, radius, ref, scheme, shadow, style: rootStyle2, ...t8, children: [
4483
+ $[28] !== animate ? (t10 = animate ? ["hidden", "scaleOut"] : void 0, $[28] = animate, $[29] = t10) : t10 = $[29];
4484
+ let t11;
4485
+ $[30] !== arrow2 || $[31] !== arrowRef || $[32] !== arrowStyle ? (t11 = arrow2 && /* @__PURE__ */ jsx(Arrow, { ref: arrowRef, style: arrowStyle, width: DEFAULT_TOOLTIP_ARROW_WIDTH, height: DEFAULT_TOOLTIP_ARROW_HEIGHT, radius: DEFAULT_TOOLTIP_ARROW_RADIUS }), $[30] = arrow2, $[31] = arrowRef, $[32] = arrowStyle, $[33] = t11) : t11 = $[33];
4486
+ let t12;
4487
+ 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__ */ 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: [
4469
4488
  children,
4470
- t9
4471
- ] }), $[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;
4489
+ t11
4490
+ ] }), $[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;
4472
4491
  }));
4473
4492
  TooltipCard.displayName = "Memo(ForwardRef(TooltipCard))";
4474
4493
  const TooltipDelayGroupContext = createGlobalScopedContext("@sanity/ui/context/tooltipDelayGroup", null);
@@ -4562,19 +4581,7 @@ const StyledTooltip = styled(Layer).withConfig({
4562
4581
  }
4563
4582
  else
4564
4583
  setIsOpen(open, immediate ? 0 : open ? openDelay : closeDelay);
4565
- }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]), handleBlur = useCallback((e) => {
4566
- handleIsOpenChange(!1), childProp?.props?.onBlur?.(e);
4567
- }, [childProp?.props, handleIsOpenChange]), handleClick = useCallback((e_0) => {
4568
- handleIsOpenChange(!1, !0), childProp?.props.onClick?.(e_0);
4569
- }, [childProp?.props, handleIsOpenChange]), handleContextMenu = useCallback((e_1) => {
4570
- handleIsOpenChange(!1, !0), childProp?.props.onContextMenu?.(e_1);
4571
- }, [childProp?.props, handleIsOpenChange]), handleFocus = useCallback((e_2) => {
4572
- handleIsOpenChange(!0), childProp?.props?.onFocus?.(e_2);
4573
- }, [childProp?.props, handleIsOpenChange]), handleMouseEnter = useCallback((e_3) => {
4574
- handleIsOpenChange(!0), childProp?.props?.onMouseEnter?.(e_3);
4575
- }, [childProp?.props, handleIsOpenChange]), handleMouseLeave = useCallback((e_4) => {
4576
- handleIsOpenChange(!1), childProp?.props?.onMouseLeave?.(e_4);
4577
- }, [childProp?.props, handleIsOpenChange]);
4584
+ }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
4578
4585
  useCloseOnMouseLeave({
4579
4586
  handleIsOpenChange,
4580
4587
  referenceElement,
@@ -4591,7 +4598,27 @@ const StyledTooltip = styled(Layer).withConfig({
4591
4598
  return window.addEventListener("keydown", handleWindowKeyDown), () => {
4592
4599
  window.removeEventListener("keydown", handleWindowKeyDown);
4593
4600
  };
4594
- }, [handleIsOpenChange, showTooltip]), useLayoutEffect(() => {
4601
+ }, [handleIsOpenChange, showTooltip]);
4602
+ const handleChildEvent = useEffectEvent((open_0, immediate_0) => handleIsOpenChange(open_0, immediate_0));
4603
+ useEffect(() => {
4604
+ if (!referenceElement) return;
4605
+ const controller = new AbortController(), {
4606
+ signal
4607
+ } = controller;
4608
+ return referenceElement.addEventListener("blur", () => handleChildEvent(!1), {
4609
+ signal
4610
+ }), referenceElement.addEventListener("focus", () => handleChildEvent(!0), {
4611
+ signal
4612
+ }), referenceElement.addEventListener("mouseenter", () => handleChildEvent(!0), {
4613
+ signal
4614
+ }), referenceElement.addEventListener("mouseleave", () => handleChildEvent(!1), {
4615
+ signal
4616
+ }), referenceElement.addEventListener("click", () => handleChildEvent(!1, !0), {
4617
+ signal
4618
+ }), referenceElement.addEventListener("contextmenu", () => handleChildEvent(!1, !0), {
4619
+ signal
4620
+ }), () => controller.abort();
4621
+ }, [referenceElement]), useLayoutEffect(() => {
4595
4622
  const availableWidths = [...boundaryElement ? [boundaryElement.offsetWidth] : [], portalElement?.offsetWidth || document.body.offsetWidth];
4596
4623
  setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
4597
4624
  }, [boundaryElement, portalElement]);
@@ -4600,14 +4627,8 @@ const StyledTooltip = styled(Layer).withConfig({
4600
4627
  }, [update]), setFloating = useCallback((node) => {
4601
4628
  ref.current = node, refs.setFloating(node);
4602
4629
  }, [refs]), child = useMemo(() => childProp ? cloneElement(childProp, {
4603
- onBlur: handleBlur,
4604
- onFocus: handleFocus,
4605
- onMouseEnter: handleMouseEnter,
4606
- onMouseLeave: handleMouseLeave,
4607
- onClick: handleClick,
4608
- onContextMenu: handleContextMenu,
4609
4630
  ref: setReferenceElement
4610
- }) : null, [childProp, handleBlur, handleClick, handleContextMenu, handleFocus, handleMouseEnter, handleMouseLeave]);
4631
+ }) : null, [childProp]);
4611
4632
  if (useImperativeHandle(childProp ? getElementRef(childProp) : null, () => referenceElement, [referenceElement]), !child) return /* @__PURE__ */ jsx(Fragment, {});
4612
4633
  if (disabled) return child;
4613
4634
  const tooltip = /* @__PURE__ */ jsx(StyledTooltip, { "data-ui": "Tooltip", ...restProps, ref: setFloating, style: {
@@ -5319,7 +5340,6 @@ export {
5319
5340
  MenuDivider,
5320
5341
  MenuGroup,
5321
5342
  MenuItem,
5322
- POPOVER_MOTION_CONTENT_OPACITY_PROPERTY,
5323
5343
  Popover,
5324
5344
  Portal,
5325
5345
  PortalProvider,