@sustaina/shared-ui 1.29.0 → 1.30.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.mjs CHANGED
@@ -2686,6 +2686,16 @@ var LookupSelect = ({
2686
2686
  }
2687
2687
  };
2688
2688
  }, [inputValue, fetchSuggestions, suggestionDebounce, upsertOptionLabels]);
2689
+ useEffect(() => {
2690
+ if (!fetchSuggestions) return;
2691
+ if (value.length === 0) return;
2692
+ const unresolvedValues = value.filter((v) => !optionLabels[v]);
2693
+ if (unresolvedValues.length === 0) return;
2694
+ fetchSuggestions("").then((options) => {
2695
+ upsertOptionLabels(options);
2696
+ }).catch(() => {
2697
+ });
2698
+ }, [value, fetchSuggestions, optionLabels, upsertOptionLabels]);
2689
2699
  useEffect(() => {
2690
2700
  const handleDocumentClick = (event) => {
2691
2701
  const target = event.target;
@@ -9784,27 +9794,51 @@ var CropperModal = ({
9784
9794
  }
9785
9795
  );
9786
9796
  };
9787
- var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9797
+ var Truncated = ({
9798
+ children,
9799
+ className,
9800
+ ellipsis = true,
9801
+ as = "p",
9802
+ style,
9803
+ tooltipProps,
9804
+ tooltipContentProps
9805
+ }) => {
9788
9806
  const elementRef = useRef(null);
9789
9807
  const [open, setOpen] = useState(false);
9790
9808
  const [isTruncated, setIsTruncated] = useState(false);
9791
9809
  const Comp = as;
9792
9810
  const normalizedChildren = typeof children === "string" ? children.replace(/>/g, ">\u200B") : children;
9811
+ const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis?.lineClamp ?? 3 : null;
9793
9812
  useEffect(() => {
9794
9813
  const el = elementRef.current;
9795
9814
  if (!el) return;
9796
- const checkTruncate = debounce(() => {
9797
- const overflowX = el.scrollWidth > el.clientWidth;
9798
- const overflowY = el.scrollHeight > el.clientHeight;
9799
- setIsTruncated(overflowX || overflowY);
9800
- }, 300);
9801
- const resizeObserver = new ResizeObserver(checkTruncate);
9815
+ const measure = () => {
9816
+ if (!ellipsis) {
9817
+ setIsTruncated(false);
9818
+ return;
9819
+ }
9820
+ const rect = el.getBoundingClientRect();
9821
+ const width = el.clientWidth || el.offsetWidth || rect.width;
9822
+ const height = el.clientHeight || el.offsetHeight || rect.height;
9823
+ if (!width || !height) {
9824
+ setIsTruncated(false);
9825
+ return;
9826
+ }
9827
+ const epsilon = 1;
9828
+ const overflowWidth = el.scrollWidth - width > epsilon;
9829
+ const overflowHeight = el.scrollHeight - height > epsilon;
9830
+ setIsTruncated(overflowWidth || overflowHeight);
9831
+ };
9832
+ const resizeObserver = new ResizeObserver(() => requestAnimationFrame(measure));
9802
9833
  resizeObserver.observe(el);
9834
+ const mutationObserver = new MutationObserver(() => measure());
9835
+ mutationObserver.observe(el, { childList: true, subtree: true, characterData: true });
9836
+ requestAnimationFrame(measure);
9803
9837
  return () => {
9804
9838
  resizeObserver.disconnect();
9839
+ mutationObserver.disconnect();
9805
9840
  };
9806
- }, []);
9807
- const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis.lineClamp ?? 3 : null;
9841
+ }, [children, ellipsis, lineClampLines]);
9808
9842
  const truncationClass = useMemo(() => {
9809
9843
  if (!ellipsis) return "";
9810
9844
  if (typeof ellipsis === "number") return `line-clamp-${ellipsis}`;
@@ -9823,14 +9857,20 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9823
9857
  }, [lineClampLines, style]);
9824
9858
  const baseContent = /* @__PURE__ */ jsx(Comp, { ref: elementRef, className: cn(truncationClass, className), style: clampedStyle, children: normalizedChildren });
9825
9859
  let tooltipContent = normalizedChildren;
9826
- let tooltipSide = "top";
9827
9860
  if (typeof ellipsis === "object") {
9828
9861
  tooltipContent = ellipsis?.content ?? normalizedChildren;
9829
- tooltipSide = ellipsis?.side ?? "top";
9830
9862
  }
9863
+ const {
9864
+ className: tooltipContentClassName,
9865
+ arrowClassName: tooltipArrowClassName,
9866
+ side: tooltipContentSide,
9867
+ ...tooltipContentRest
9868
+ } = tooltipContentProps ?? {};
9869
+ const tooltipSide = (typeof ellipsis === "object" ? ellipsis?.side : void 0) ?? tooltipContentSide ?? "top";
9831
9870
  return /* @__PURE__ */ jsxs(
9832
9871
  Tooltip2,
9833
9872
  {
9873
+ ...tooltipProps,
9834
9874
  open,
9835
9875
  onOpenChange: (open2) => {
9836
9876
  setOpen(isTruncated && open2);
@@ -9841,8 +9881,12 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9841
9881
  TooltipContent2,
9842
9882
  {
9843
9883
  side: tooltipSide,
9844
- className: cn("text-white bg-[#8B8B8B] max-w-md wrap-break-word shadow-lg"),
9845
- arrowClassName: "bg-[#8B8B8B] fill-[#8B8B8B]",
9884
+ className: cn(
9885
+ "text-white bg-[#8B8B8B] max-w-xs sm:max-w-md wrap-break-word shadow-lg",
9886
+ tooltipContentClassName
9887
+ ),
9888
+ arrowClassName: cn("bg-[#8B8B8B] fill-[#8B8B8B]", tooltipArrowClassName),
9889
+ ...tooltipContentRest,
9846
9890
  children: tooltipContent
9847
9891
  }
9848
9892
  )