@sanity/ui 1.8.3 → 1.9.1

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
@@ -6860,6 +6860,7 @@ function useDelayedState(initialState) {
6860
6860
  }, []);
6861
6861
  return [state, onStateChange];
6862
6862
  }
6863
+ const DEFAULT_TOOLTIP_PADDING = 4;
6863
6864
  const DEFAULT_FALLBACK_PLACEMENTS = {
6864
6865
  top: ["bottom", "left", "right"],
6865
6866
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -6943,7 +6944,7 @@ var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
6943
6944
  value: __freeze$e(raw || cooked.slice())
6944
6945
  }));
6945
6946
  var _a$e;
6946
- const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n"])));
6947
+ const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n // Note that 100vw doesn't exclude system scrollbars.\n // This should be sufficiently small enough to not trigger overflow-x scrollbars when portalled.\n max-width: calc(100vw - ", "px);\n"])), DEFAULT_TOOLTIP_PADDING * 10);
6947
6948
  const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6948
6949
  var _a2, _b, _c, _d, _e;
6949
6950
  const boundaryElementContext = useBoundaryElement();
@@ -6971,42 +6972,25 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6971
6972
  const middleware = react.useMemo(() => {
6972
6973
  const ret = [];
6973
6974
  ret.push(reactDom$1.flip({
6974
- boundary: boundaryElement || void 0,
6975
+ boundary: portal ? void 0 : boundaryElement || void 0,
6975
6976
  fallbackPlacements,
6976
- padding: 4,
6977
- rootBoundary,
6978
- mainAxis: false
6977
+ padding: DEFAULT_TOOLTIP_PADDING,
6978
+ rootBoundary
6979
6979
  }));
6980
6980
  ret.push(reactDom$1.offset({
6981
6981
  mainAxis: 3
6982
6982
  }));
6983
- ret.push(reactDom$1.size({
6984
- apply(_ref22) {
6985
- let {
6986
- availableWidth,
6987
- availableHeight,
6988
- elements
6989
- } = _ref22;
6990
- Object.assign(elements.floating.style, {
6991
- maxWidth: "".concat(availableWidth - 4 * 2, "px"),
6992
- // the padding is `4px`
6993
- maxHeight: "".concat(availableHeight - 4 * 2, "px")
6994
- // the padding is `4px`
6995
- });
6996
- }
6997
- }));
6998
-
6999
6983
  ret.push(reactDom$1.shift({
7000
- boundary: boundaryElement || void 0,
6984
+ boundary: portal ? void 0 : boundaryElement || void 0,
7001
6985
  rootBoundary,
7002
- padding: 4
6986
+ padding: DEFAULT_TOOLTIP_PADDING
7003
6987
  }));
7004
6988
  ret.push(reactDom$1.arrow({
7005
6989
  element: arrowRef,
7006
6990
  padding: 2
7007
6991
  }));
7008
6992
  return ret;
7009
- }, [boundaryElement, fallbackPlacements]);
6993
+ }, [boundaryElement, fallbackPlacements, portal]);
7010
6994
  const {
7011
6995
  floatingStyles,
7012
6996
  placement,
@@ -7040,19 +7024,21 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7040
7024
  const closeDelayProp = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.close) || 0;
7041
7025
  const openDelay = isInsideGroup ? delayGroupContext.openDelay : openDelayProp;
7042
7026
  const closeDelay = isInsideGroup ? delayGroupContext.closeDelay : closeDelayProp;
7043
- const handleIsOpenChange = react.useCallback(open => {
7027
+ const handleIsOpenChange = react.useCallback((open, immediate) => {
7044
7028
  if (isInsideGroup) {
7045
7029
  if (open) {
7046
- delayGroupContext.setIsGroupActive(open, openDelay);
7047
- delayGroupContext.setOpenTooltipId(tooltipId, openDelay);
7030
+ const groupedOpenDelay = immediate ? 0 : openDelay;
7031
+ delayGroupContext.setIsGroupActive(open, groupedOpenDelay);
7032
+ delayGroupContext.setOpenTooltipId(tooltipId, groupedOpenDelay);
7048
7033
  } else {
7049
7034
  const minimumGroupDeactivateDelay = 200;
7050
7035
  const groupDeactivateDelay = closeDelay > minimumGroupDeactivateDelay ? closeDelay : minimumGroupDeactivateDelay;
7051
7036
  delayGroupContext.setIsGroupActive(open, groupDeactivateDelay);
7052
- delayGroupContext.setOpenTooltipId(null, closeDelay);
7037
+ delayGroupContext.setOpenTooltipId(null, immediate ? 0 : closeDelay);
7053
7038
  }
7054
7039
  } else {
7055
- setIsOpen(open, open ? openDelay : closeDelay);
7040
+ const standaloneDelay = immediate ? 0 : open ? openDelay : closeDelay;
7041
+ setIsOpen(open, standaloneDelay);
7056
7042
  }
7057
7043
  }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
7058
7044
  const handleBlur = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
@@ -7081,6 +7067,18 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7081
7067
  if (!content) handleIsOpenChange(false);
7082
7068
  }, [content, handleIsOpenChange]);
7083
7069
  react.useEffect(() => refs.setReference(referenceElement), [referenceElement, refs]);
7070
+ react.useEffect(() => {
7071
+ if (!showTooltip) return;
7072
+ function handleWindowKeyDown(event) {
7073
+ if (event.key === "Escape") {
7074
+ handleIsOpenChange(false, true);
7075
+ }
7076
+ }
7077
+ window.addEventListener("keydown", handleWindowKeyDown);
7078
+ return () => {
7079
+ window.removeEventListener("keydown", handleWindowKeyDown);
7080
+ };
7081
+ }, [handleIsOpenChange, showTooltip]);
7084
7082
  const setArrow = react.useCallback(arrowEl => {
7085
7083
  arrowRef.current = arrowEl;
7086
7084
  update();
@@ -7292,10 +7290,10 @@ const InnerAutocomplete = react.forwardRef(function InnerAutocomplete2(props, re
7292
7290
  query,
7293
7291
  value
7294
7292
  } = state;
7295
- const defaultRenderOption = react.useCallback(_ref23 => {
7293
+ const defaultRenderOption = react.useCallback(_ref22 => {
7296
7294
  let {
7297
7295
  value: value2
7298
- } = _ref23;
7296
+ } = _ref22;
7299
7297
  return /* @__PURE__ */jsxRuntime.jsx(Card, {
7300
7298
  "data-as": "button",
7301
7299
  padding: paddingProp,
@@ -7748,10 +7746,10 @@ const Breadcrumbs = react.forwardRef(function Breadcrumbs2(props, ref) {
7748
7746
  }, itemIndex))
7749
7747
  });
7750
7748
  });
7751
- function dialogStyle(_ref24) {
7749
+ function dialogStyle(_ref23) {
7752
7750
  let {
7753
7751
  theme
7754
- } = _ref24;
7752
+ } = _ref23;
7755
7753
  const color = theme.sanity.color.base;
7756
7754
  return {
7757
7755
  "&:not([hidden])": {
@@ -8813,15 +8811,15 @@ var __template$6 = (cooked, raw) => __freeze$6(__defProp$6(cooked, "raw", {
8813
8811
  var _a$6, _b$3, _c$1, _d;
8814
8812
  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"])));
8815
8813
  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);
8816
- 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 => {
8814
+ 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 => {
8817
8815
  let {
8818
8816
  $visible
8819
- } = _ref25;
8817
+ } = _ref24;
8820
8818
  return $visible ? 1 : 0;
8821
- }, _ref26 => {
8819
+ }, _ref25 => {
8822
8820
  let {
8823
8821
  $animated
8824
- } = _ref26;
8822
+ } = _ref25;
8825
8823
  return $animated ? animation : styled.css(_c$1 || (_c$1 = __template$6(["\n background-color: var(--card-skeleton-color-from);\n "])));
8826
8824
  });
8827
8825
  const Root$4 = styled__default.default(Box)(responsiveRadiusStyle, skeletonStyle);
@@ -8852,12 +8850,12 @@ const Skeleton = react.forwardRef(function Skeleton2(props, ref) {
8852
8850
  ref
8853
8851
  });
8854
8852
  });
8855
- const Root$3 = styled__default.default(Skeleton)(_ref27 => {
8853
+ const Root$3 = styled__default.default(Skeleton)(_ref26 => {
8856
8854
  let {
8857
8855
  $size,
8858
8856
  $style,
8859
8857
  theme
8860
- } = _ref27;
8858
+ } = _ref26;
8861
8859
  const {
8862
8860
  media
8863
8861
  } = theme.sanity;
@@ -9204,12 +9202,12 @@ function ToastProvider(props) {
9204
9202
  paddingY,
9205
9203
  children: /* @__PURE__ */jsxRuntime.jsx(framerMotion.AnimatePresence, {
9206
9204
  initial: false,
9207
- children: state.map(_ref28 => {
9205
+ children: state.map(_ref27 => {
9208
9206
  let {
9209
9207
  dismiss,
9210
9208
  id,
9211
9209
  params
9212
- } = _ref28;
9210
+ } = _ref27;
9213
9211
  return /* @__PURE__ */jsxRuntime.jsx(framerMotion.motion.div, {
9214
9212
  animate: {
9215
9213
  opacity: 1,