@sanity/ui 1.7.11 → 1.8.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.
package/dist/index.js CHANGED
@@ -3074,9 +3074,9 @@ function getGlobalScope() {
3074
3074
  throw new Error("@sanity/ui: could not locate global scope");
3075
3075
  }
3076
3076
  const globalScope = getGlobalScope();
3077
- const key$7 = Symbol.for("@sanity/ui/context/theme");
3078
- globalScope[key$7] = globalScope[key$7] || react.createContext(null);
3079
- const ThemeContext = globalScope[key$7];
3077
+ const key$8 = Symbol.for("@sanity/ui/context/theme");
3078
+ globalScope[key$8] = globalScope[key$8] || react.createContext(null);
3079
+ const ThemeContext = globalScope[key$8];
3080
3080
  function ThemeProvider(props) {
3081
3081
  const parentTheme = react.useContext(ThemeContext);
3082
3082
  const {
@@ -5269,9 +5269,9 @@ const KBD = react.forwardRef(function KBD2(props, ref) {
5269
5269
  })
5270
5270
  });
5271
5271
  });
5272
- const key$6 = Symbol.for("@sanity/ui/context/boundaryElement");
5273
- globalScope[key$6] = globalScope[key$6] || react.createContext(null);
5274
- const BoundaryElementContext = globalScope[key$6];
5272
+ const key$7 = Symbol.for("@sanity/ui/context/boundaryElement");
5273
+ globalScope[key$7] = globalScope[key$7] || react.createContext(null);
5274
+ const BoundaryElementContext = globalScope[key$7];
5275
5275
  function BoundaryElementProvider(props) {
5276
5276
  const {
5277
5277
  children,
@@ -5400,9 +5400,9 @@ function getLayerContext(contextValue) {
5400
5400
  }
5401
5401
  throw new Error("could not get layer context");
5402
5402
  }
5403
- const key$5 = Symbol.for("@sanity/ui/context/layer");
5404
- globalScope[key$5] = globalScope[key$5] || react.createContext(null);
5405
- const LayerContext = globalScope[key$5];
5403
+ const key$6 = Symbol.for("@sanity/ui/context/layer");
5404
+ globalScope[key$6] = globalScope[key$6] || react.createContext(null);
5405
+ const LayerContext = globalScope[key$6];
5406
5406
  function useLayer() {
5407
5407
  const value = react.useContext(LayerContext);
5408
5408
  if (!value) {
@@ -5639,7 +5639,7 @@ const Layer = react.forwardRef(function Layer2(props, ref) {
5639
5639
  })
5640
5640
  });
5641
5641
  });
5642
- const key$4 = Symbol.for("@sanity/ui/context/portal");
5642
+ const key$5 = Symbol.for("@sanity/ui/context/portal");
5643
5643
  const elementKey = Symbol.for("@sanity/ui/context/portal/element");
5644
5644
  globalScope[elementKey] = null;
5645
5645
  const defaultContextValue = {
@@ -5658,8 +5658,8 @@ const defaultContextValue = {
5658
5658
  return globalScope[elementKey];
5659
5659
  }
5660
5660
  };
5661
- globalScope[key$4] = globalScope[key$4] || react.createContext(defaultContextValue);
5662
- const PortalContext = globalScope[key$4];
5661
+ globalScope[key$5] = globalScope[key$5] || react.createContext(defaultContextValue);
5662
+ const PortalContext = globalScope[key$5];
5663
5663
  function usePortal() {
5664
5664
  const value = react.useContext(PortalContext);
5665
5665
  if (!value) {
@@ -6825,6 +6825,22 @@ const TextInput = react.forwardRef(function TextInput2(props, forwardedRef) {
6825
6825
  }), suffixNode]
6826
6826
  });
6827
6827
  });
6828
+ function useDelayedState(initialState) {
6829
+ const [state, setState] = react.useState(initialState);
6830
+ const delayedAction = react.useRef();
6831
+ const onStateChange = react.useCallback((nextState, delay) => {
6832
+ const action = () => {
6833
+ setState(nextState);
6834
+ };
6835
+ if (delayedAction.current) {
6836
+ clearTimeout(delayedAction.current);
6837
+ delayedAction.current = void 0;
6838
+ }
6839
+ if (!delay) return action();
6840
+ delayedAction.current = setTimeout(action, delay);
6841
+ }, []);
6842
+ return [state, onStateChange];
6843
+ }
6828
6844
  var __freeze$f = Object.freeze;
6829
6845
  var __defProp$f = Object.defineProperty;
6830
6846
  var __template$f = (cooked, raw) => __freeze$f(__defProp$f(cooked, "raw", {
@@ -6854,6 +6870,40 @@ const TooltipArrow = react.forwardRef(function TooltipArrow2(props, ref) {
6854
6870
  })
6855
6871
  });
6856
6872
  });
6873
+ const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup");
6874
+ globalScope[key$4] = globalScope[key$4] || react.createContext(null);
6875
+ const TooltipDelayGroupContext = globalScope[key$4];
6876
+ function useTooltipDelayGroup() {
6877
+ const value = react.useContext(TooltipDelayGroupContext);
6878
+ return value;
6879
+ }
6880
+ function TooltipDelayGroupProvider(props) {
6881
+ const {
6882
+ children,
6883
+ delay
6884
+ } = props;
6885
+ const [isGroupActive, setIsGroupActive] = useDelayedState(false);
6886
+ const [openTooltipId, setOpenTooltipId] = useDelayedState(null);
6887
+ const isInsideContext = useTooltipDelayGroup();
6888
+ if (isInsideContext) {
6889
+ throw new Error("TooltipDelayGroupProvider cannot be nested inside another TooltipDelayGroupProvider");
6890
+ }
6891
+ const openDelay = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.open) || 0;
6892
+ const closeDelay = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.close) || 0;
6893
+ const value = react.useMemo(() => ({
6894
+ isGroupActive,
6895
+ setIsGroupActive,
6896
+ openTooltipId,
6897
+ setOpenTooltipId,
6898
+ // When the group is active, we want the next tooltip to open immediately.
6899
+ openDelay: isGroupActive ? 1 : openDelay,
6900
+ closeDelay
6901
+ }), [closeDelay, isGroupActive, openDelay, openTooltipId, setIsGroupActive, setOpenTooltipId]);
6902
+ return /* @__PURE__ */jsxRuntime.jsx(TooltipDelayGroupContext.Provider, {
6903
+ value,
6904
+ children
6905
+ });
6906
+ }
6857
6907
  var __freeze$e = Object.freeze;
6858
6908
  var __defProp$e = Object.defineProperty;
6859
6909
  var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
@@ -6877,6 +6927,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6877
6927
  scheme,
6878
6928
  shadow = 2,
6879
6929
  zOffset = (_a2 = theme.sanity.layer) == null ? void 0 : _a2.tooltip.zOffset,
6930
+ delay,
6880
6931
  ...restProps
6881
6932
  } = props;
6882
6933
  const fallbackPlacements = useArrayProp(fallbackPlacementsProp);
@@ -6890,11 +6941,28 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6890
6941
  boundary: boundaryElement || void 0,
6891
6942
  fallbackPlacements,
6892
6943
  padding: 4,
6893
- rootBoundary
6944
+ rootBoundary,
6945
+ mainAxis: false
6894
6946
  }));
6895
6947
  ret.push(reactDom$1.offset({
6896
6948
  mainAxis: 3
6897
6949
  }));
6950
+ ret.push(reactDom$1.size({
6951
+ apply(_ref22) {
6952
+ let {
6953
+ availableWidth,
6954
+ availableHeight,
6955
+ elements
6956
+ } = _ref22;
6957
+ Object.assign(elements.floating.style, {
6958
+ maxWidth: "".concat(availableWidth - 4 * 2, "px"),
6959
+ // the padding is `4px`
6960
+ maxHeight: "".concat(availableHeight - 4 * 2, "px")
6961
+ // the padding is `4px`
6962
+ });
6963
+ }
6964
+ }));
6965
+
6898
6966
  ret.push(reactDom$1.shift({
6899
6967
  boundary: boundaryElement || void 0,
6900
6968
  rootBoundary,
@@ -6907,23 +6975,16 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6907
6975
  return ret;
6908
6976
  }, [boundaryElement, fallbackPlacements]);
6909
6977
  const {
6910
- x,
6911
- y,
6978
+ floatingStyles,
6912
6979
  placement,
6913
6980
  middlewareData,
6914
6981
  refs,
6915
- update,
6916
- strategy
6982
+ update
6917
6983
  } = reactDom$1.useFloating({
6918
6984
  middleware,
6919
6985
  placement: placementProp,
6920
6986
  whileElementsMounted: reactDom$1.autoUpdate
6921
6987
  });
6922
- const rootStyle = react.useMemo(() => ({
6923
- position: strategy,
6924
- top: y != null ? y : 0,
6925
- left: x != null ? x : 0
6926
- }), [strategy, x, y]);
6927
6988
  const staticSide = placement && FLOATING_STATIC_SIDES[placement.split("-")[0]];
6928
6989
  const arrowX = (_b = middlewareData.arrow) == null ? void 0 : _b.x;
6929
6990
  const arrowY = (_c = middlewareData.arrow) == null ? void 0 : _c.y;
@@ -6937,18 +6998,41 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6937
6998
  if (staticSide) style[staticSide] = -15;
6938
6999
  return style;
6939
7000
  }, [arrowX, arrowY, staticSide]);
6940
- const [isOpen, setIsOpen] = react.useState(false);
6941
- const handleBlur = react.useCallback(() => setIsOpen(false), []);
6942
- const handleFocus = react.useCallback(() => setIsOpen(true), []);
6943
- const handleMouseEnter = react.useCallback(() => setIsOpen(true), []);
6944
- const handleMouseLeave = react.useCallback(() => setIsOpen(false), []);
7001
+ const tooltipId = react.useId();
7002
+ const [isOpen, setIsOpen] = useDelayedState(false);
7003
+ const delayGroupContext = useTooltipDelayGroup();
7004
+ const showTooltip = isOpen || (delayGroupContext == null ? void 0 : delayGroupContext.openTooltipId) === tooltipId;
7005
+ const isInsideGroup = delayGroupContext !== null;
7006
+ const openDelayProp = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.open) || 0;
7007
+ const closeDelayProp = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.close) || 0;
7008
+ const openDelay = isInsideGroup ? delayGroupContext.openDelay : openDelayProp;
7009
+ const closeDelay = isInsideGroup ? delayGroupContext.closeDelay : closeDelayProp;
7010
+ const handleIsOpenChange = react.useCallback(open => {
7011
+ if (isInsideGroup) {
7012
+ if (open) {
7013
+ delayGroupContext.setIsGroupActive(open, openDelay);
7014
+ delayGroupContext.setOpenTooltipId(tooltipId, openDelay);
7015
+ } else {
7016
+ const minimumGroupDeactivateDelay = 200;
7017
+ const groupDeactivateDelay = closeDelay > minimumGroupDeactivateDelay ? closeDelay : minimumGroupDeactivateDelay;
7018
+ delayGroupContext.setIsGroupActive(open, groupDeactivateDelay);
7019
+ delayGroupContext.setOpenTooltipId(null, closeDelay);
7020
+ }
7021
+ } else {
7022
+ setIsOpen(open, open ? openDelay : closeDelay);
7023
+ }
7024
+ }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
7025
+ const handleBlur = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
7026
+ const handleFocus = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
7027
+ const handleMouseEnter = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
7028
+ const handleMouseLeave = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
6945
7029
  react.useEffect(() => {
6946
7030
  if (!isOpen) return;
6947
7031
  function handleWindowMouseMove(event) {
6948
7032
  if (!referenceElement) return;
6949
7033
  const isHoveringReference = referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target);
6950
7034
  if (!isHoveringReference) {
6951
- setIsOpen(false);
7035
+ handleIsOpenChange(false);
6952
7036
  window.removeEventListener("mousemove", handleWindowMouseMove);
6953
7037
  }
6954
7038
  }
@@ -6956,13 +7040,13 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6956
7040
  return () => {
6957
7041
  window.removeEventListener("mousemove", handleWindowMouseMove);
6958
7042
  };
6959
- }, [isOpen, referenceElement]);
7043
+ }, [isOpen, referenceElement, handleIsOpenChange]);
6960
7044
  react.useEffect(() => {
6961
- if (disabled) setIsOpen(false);
6962
- }, [disabled]);
7045
+ if (disabled) handleIsOpenChange(false);
7046
+ }, [disabled, handleIsOpenChange]);
6963
7047
  react.useEffect(() => {
6964
- if (!content) setIsOpen(false);
6965
- }, [content]);
7048
+ if (!content) handleIsOpenChange(false);
7049
+ }, [content, handleIsOpenChange]);
6966
7050
  react.useEffect(() => refs.setReference(referenceElement), [referenceElement, refs]);
6967
7051
  const setArrow = react.useCallback(arrowEl => {
6968
7052
  arrowRef.current = arrowEl;
@@ -6997,7 +7081,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6997
7081
  "data-ui": "Tooltip",
6998
7082
  ...restProps,
6999
7083
  ref: setFloating,
7000
- style: rootStyle,
7084
+ style: floatingStyles,
7001
7085
  zOffset,
7002
7086
  children: /* @__PURE__ */jsxRuntime.jsxs(Card, {
7003
7087
  "data-ui": "Tooltip__card",
@@ -7013,7 +7097,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7013
7097
  })
7014
7098
  });
7015
7099
  return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
7016
- children: [child, isOpen && /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
7100
+ children: [child, showTooltip && /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
7017
7101
  children: portal ? /* @__PURE__ */jsxRuntime.jsx(Portal, {
7018
7102
  __unstable_name: typeof portal === "string" ? portal : void 0,
7019
7103
  children: root
@@ -7175,10 +7259,10 @@ const InnerAutocomplete = react.forwardRef(function InnerAutocomplete2(props, re
7175
7259
  query,
7176
7260
  value
7177
7261
  } = state;
7178
- const defaultRenderOption = react.useCallback(_ref22 => {
7262
+ const defaultRenderOption = react.useCallback(_ref23 => {
7179
7263
  let {
7180
7264
  value: value2
7181
- } = _ref22;
7265
+ } = _ref23;
7182
7266
  return /* @__PURE__ */jsxRuntime.jsx(Card, {
7183
7267
  "data-as": "button",
7184
7268
  padding: paddingProp,
@@ -7631,10 +7715,10 @@ const Breadcrumbs = react.forwardRef(function Breadcrumbs2(props, ref) {
7631
7715
  }, itemIndex))
7632
7716
  });
7633
7717
  });
7634
- function dialogStyle(_ref23) {
7718
+ function dialogStyle(_ref24) {
7635
7719
  let {
7636
7720
  theme
7637
- } = _ref23;
7721
+ } = _ref24;
7638
7722
  const color = theme.sanity.color.base;
7639
7723
  return {
7640
7724
  "&:not([hidden])": {
@@ -8696,15 +8780,15 @@ var __template$6 = (cooked, raw) => __freeze$6(__defProp$6(cooked, "raw", {
8696
8780
  var _a$6, _b$3, _c$1, _d;
8697
8781
  const keyframe = styled.keyframes(_a$6 || (_a$6 = __template$6(["\n 0% {\n background-position: 100%;\n }\n 100% {\n background-position: -100%;\n }\n"])));
8698
8782
  const animation = styled.css(_b$3 || (_b$3 = __template$6(["\n background-image: linear-gradient(\n to right,\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-to),\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-from)\n );\n background-position: 100%;\n background-size: 200% 100%;\n background-attachment: fixed;\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n animation-iteration-count: infinite;\n animation-duration: 2000ms;\n"])), keyframe);
8699
- const skeletonStyle = styled.css(_d || (_d = __template$6(["\n opacity: ", ";\n transition: opacity 200ms ease-in;\n\n @media screen and (prefers-reduced-motion: no-preference) {\n ", "\n }\n\n @media screen and (prefers-reduced-motion: reduce) {\n background-color: var(--card-skeleton-color-from);\n }\n"])), _ref24 => {
8783
+ const skeletonStyle = styled.css(_d || (_d = __template$6(["\n opacity: ", ";\n transition: opacity 200ms ease-in;\n\n @media screen and (prefers-reduced-motion: no-preference) {\n ", "\n }\n\n @media screen and (prefers-reduced-motion: reduce) {\n background-color: var(--card-skeleton-color-from);\n }\n"])), _ref25 => {
8700
8784
  let {
8701
8785
  $visible
8702
- } = _ref24;
8786
+ } = _ref25;
8703
8787
  return $visible ? 1 : 0;
8704
- }, _ref25 => {
8788
+ }, _ref26 => {
8705
8789
  let {
8706
8790
  $animated
8707
- } = _ref25;
8791
+ } = _ref26;
8708
8792
  return $animated ? animation : styled.css(_c$1 || (_c$1 = __template$6(["\n background-color: var(--card-skeleton-color-from);\n "])));
8709
8793
  });
8710
8794
  const Root$4 = styled__default.default(Box)(responsiveRadiusStyle, skeletonStyle);
@@ -8735,12 +8819,12 @@ const Skeleton = react.forwardRef(function Skeleton2(props, ref) {
8735
8819
  ref
8736
8820
  });
8737
8821
  });
8738
- const Root$3 = styled__default.default(Skeleton)(_ref26 => {
8822
+ const Root$3 = styled__default.default(Skeleton)(_ref27 => {
8739
8823
  let {
8740
8824
  $size,
8741
8825
  $style,
8742
8826
  theme
8743
- } = _ref26;
8827
+ } = _ref27;
8744
8828
  const {
8745
8829
  media
8746
8830
  } = theme.sanity;
@@ -9087,12 +9171,12 @@ function ToastProvider(props) {
9087
9171
  paddingY,
9088
9172
  children: /* @__PURE__ */jsxRuntime.jsx(framerMotion.AnimatePresence, {
9089
9173
  initial: false,
9090
- children: state.map(_ref27 => {
9174
+ children: state.map(_ref28 => {
9091
9175
  let {
9092
9176
  dismiss,
9093
9177
  id,
9094
9178
  params
9095
- } = _ref27;
9179
+ } = _ref28;
9096
9180
  return /* @__PURE__ */jsxRuntime.jsx(framerMotion.motion.div, {
9097
9181
  animate: {
9098
9182
  opacity: 1,
@@ -9649,6 +9733,8 @@ exports.ThemeProvider = ThemeProvider;
9649
9733
  exports.Toast = Toast;
9650
9734
  exports.ToastProvider = ToastProvider;
9651
9735
  exports.Tooltip = Tooltip;
9736
+ exports.TooltipDelayGroupContext = TooltipDelayGroupContext;
9737
+ exports.TooltipDelayGroupProvider = TooltipDelayGroupProvider;
9652
9738
  exports.Tree = Tree;
9653
9739
  exports.TreeItem = TreeItem;
9654
9740
  exports.VirtualList = VirtualList;
@@ -9707,5 +9793,6 @@ exports.usePrefersReducedMotion = usePrefersReducedMotion;
9707
9793
  exports.useRootTheme = useRootTheme;
9708
9794
  exports.useTheme = useTheme;
9709
9795
  exports.useToast = useToast;
9796
+ exports.useTooltipDelayGroup = useTooltipDelayGroup;
9710
9797
  exports.useTree = useTree;
9711
9798
  //# sourceMappingURL=index.js.map