@sustaina/shared-ui 1.28.0 → 1.29.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.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React$1 from 'react';
3
- import React__default, { CSSProperties, ReactNode, SVGProps } from 'react';
3
+ import React__default, { CSSProperties, ReactNode, SVGProps, ComponentProps } from 'react';
4
4
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
5
5
  import { ClassValue } from 'clsx';
6
6
  import * as class_variance_authority_dist_types from 'class-variance-authority/dist/types';
@@ -507,6 +507,7 @@ declare const getDialogAlertControls: () => {
507
507
  openDialogAlert: (payload?: {
508
508
  template?: TemplateKeys;
509
509
  props?: OpenDialogAlert;
510
+ isExclusive?: boolean;
510
511
  }) => void;
511
512
  closeDialogAlert: () => void;
512
513
  openErrorDialogAlert: (error: unknown) => void;
@@ -1282,8 +1283,10 @@ type TruncatedProps = {
1282
1283
  children: ReactNode;
1283
1284
  as?: keyof React__default.JSX.IntrinsicElements;
1284
1285
  style?: CSSProperties;
1286
+ tooltipProps?: Omit<ComponentProps<typeof Tooltip$1>, "open" | "onOpenChange">;
1287
+ tooltipContentProps?: Omit<ComponentProps<typeof TooltipContent$1>, "children">;
1285
1288
  };
1286
- declare const Truncated: ({ children, className, ellipsis, as, style }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1289
+ declare const Truncated: ({ children, className, ellipsis, as, style, tooltipProps, tooltipContentProps }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1287
1290
 
1288
1291
  type InputPrimitiveProps = React$1.InputHTMLAttributes<HTMLInputElement>;
1289
1292
  declare const inputVariants: (props?: ({
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React$1 from 'react';
3
- import React__default, { CSSProperties, ReactNode, SVGProps } from 'react';
3
+ import React__default, { CSSProperties, ReactNode, SVGProps, ComponentProps } from 'react';
4
4
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
5
5
  import { ClassValue } from 'clsx';
6
6
  import * as class_variance_authority_dist_types from 'class-variance-authority/dist/types';
@@ -507,6 +507,7 @@ declare const getDialogAlertControls: () => {
507
507
  openDialogAlert: (payload?: {
508
508
  template?: TemplateKeys;
509
509
  props?: OpenDialogAlert;
510
+ isExclusive?: boolean;
510
511
  }) => void;
511
512
  closeDialogAlert: () => void;
512
513
  openErrorDialogAlert: (error: unknown) => void;
@@ -1282,8 +1283,10 @@ type TruncatedProps = {
1282
1283
  children: ReactNode;
1283
1284
  as?: keyof React__default.JSX.IntrinsicElements;
1284
1285
  style?: CSSProperties;
1286
+ tooltipProps?: Omit<ComponentProps<typeof Tooltip$1>, "open" | "onOpenChange">;
1287
+ tooltipContentProps?: Omit<ComponentProps<typeof TooltipContent$1>, "children">;
1285
1288
  };
1286
- declare const Truncated: ({ children, className, ellipsis, as, style }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1289
+ declare const Truncated: ({ children, className, ellipsis, as, style, tooltipProps, tooltipContentProps }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1287
1290
 
1288
1291
  type InputPrimitiveProps = React$1.InputHTMLAttributes<HTMLInputElement>;
1289
1292
  declare const inputVariants: (props?: ({
package/dist/index.js CHANGED
@@ -5313,7 +5313,8 @@ var getDialogTemplates = ({ setOpen = () => {
5313
5313
  title: "error.session_expired.title",
5314
5314
  description: "error.session_expired.description",
5315
5315
  confirmText: "error.session_expired.confirm_text",
5316
- showCancel: false
5316
+ showCancel: false,
5317
+ persistent: true
5317
5318
  },
5318
5319
  "error.user_not_found": {
5319
5320
  variant: "error",
@@ -5440,9 +5441,17 @@ var getDialogTemplates = ({ setOpen = () => {
5440
5441
  var useDialogAlertStore = zustand.create((set, get) => ({
5441
5442
  open: false,
5442
5443
  dialogProps: {},
5443
- setOpen: (data) => set({ open: data }),
5444
+ setOpen: (open) => {
5445
+ if (!open && get().isExclusive) {
5446
+ get().setIsExclusive(false);
5447
+ }
5448
+ set({ open });
5449
+ },
5444
5450
  setDialogProps: (data) => set({ dialogProps: data }),
5445
5451
  openDialogAlert: (payload) => {
5452
+ if (get().isExclusive) {
5453
+ return;
5454
+ }
5446
5455
  let templateVal;
5447
5456
  if (payload?.template) {
5448
5457
  templateVal = getDialogTemplates({ setOpen: get().setOpen })[payload.template];
@@ -5453,10 +5462,13 @@ var useDialogAlertStore = zustand.create((set, get) => ({
5453
5462
  }
5454
5463
  get().setDialogProps({ ...templateVal, ...payload?.props });
5455
5464
  get().setOpen(true);
5465
+ get().setIsExclusive(payload?.isExclusive ?? false);
5456
5466
  },
5457
5467
  closeDialogAlert: () => {
5458
5468
  set({ open: false });
5459
- }
5469
+ },
5470
+ isExclusive: false,
5471
+ setIsExclusive: (isExclusive) => set({ isExclusive })
5460
5472
  }));
5461
5473
  var DialogAlertProvider = ({ children, i18nResource, i18nLang }) => {
5462
5474
  const open = useDialogAlertStore((state) => state.open);
@@ -5486,16 +5498,16 @@ var DialogAlertProvider = ({ children, i18nResource, i18nLang }) => {
5486
5498
  var openDialogAlert = useDialogAlertStore.getState().openDialogAlert;
5487
5499
  var closeDialogAlert = useDialogAlertStore.getState().closeDialogAlert;
5488
5500
  var openErrorDialogAlert = (error) => {
5489
- if (error instanceof Error) {
5490
- openDialogAlert({ template: "error.something_went_wrong", props: { description: error.message } });
5491
- } else if (error.isAxiosError) {
5501
+ if (error.isAxiosError) {
5492
5502
  let template = "error.something_went_wrong";
5503
+ let props = void 0;
5493
5504
  switch (error.response?.status) {
5494
5505
  case 400:
5495
5506
  template = "error.invalid_incomplete_data";
5496
5507
  break;
5497
5508
  case 401:
5498
5509
  template = "error.session_expired";
5510
+ props = { confirmText: void 0 };
5499
5511
  break;
5500
5512
  case 403:
5501
5513
  template = "error.permission_denied";
@@ -5510,7 +5522,9 @@ var openErrorDialogAlert = (error) => {
5510
5522
  template = "error.api_db_error";
5511
5523
  break;
5512
5524
  }
5513
- openDialogAlert({ template });
5525
+ openDialogAlert({ template, props });
5526
+ } else if (error instanceof Error) {
5527
+ openDialogAlert({ template: "error.something_went_wrong", props: { description: error.message } });
5514
5528
  } else {
5515
5529
  openDialogAlert({ template: "error.something_went_wrong" });
5516
5530
  }
@@ -9810,27 +9824,51 @@ var CropperModal = ({
9810
9824
  }
9811
9825
  );
9812
9826
  };
9813
- var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9827
+ var Truncated = ({
9828
+ children,
9829
+ className,
9830
+ ellipsis = true,
9831
+ as = "p",
9832
+ style,
9833
+ tooltipProps,
9834
+ tooltipContentProps
9835
+ }) => {
9814
9836
  const elementRef = React4.useRef(null);
9815
9837
  const [open, setOpen] = React4.useState(false);
9816
9838
  const [isTruncated, setIsTruncated] = React4.useState(false);
9817
9839
  const Comp = as;
9818
9840
  const normalizedChildren = typeof children === "string" ? children.replace(/>/g, ">\u200B") : children;
9841
+ const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis?.lineClamp ?? 3 : null;
9819
9842
  React4.useEffect(() => {
9820
9843
  const el = elementRef.current;
9821
9844
  if (!el) return;
9822
- const checkTruncate = debounce(() => {
9823
- const overflowX = el.scrollWidth > el.clientWidth;
9824
- const overflowY = el.scrollHeight > el.clientHeight;
9825
- setIsTruncated(overflowX || overflowY);
9826
- }, 300);
9827
- const resizeObserver = new ResizeObserver(checkTruncate);
9845
+ const measure = () => {
9846
+ if (!ellipsis) {
9847
+ setIsTruncated(false);
9848
+ return;
9849
+ }
9850
+ const rect = el.getBoundingClientRect();
9851
+ const width = el.clientWidth || el.offsetWidth || rect.width;
9852
+ const height = el.clientHeight || el.offsetHeight || rect.height;
9853
+ if (!width || !height) {
9854
+ setIsTruncated(false);
9855
+ return;
9856
+ }
9857
+ const epsilon = 1;
9858
+ const overflowWidth = el.scrollWidth - width > epsilon;
9859
+ const overflowHeight = el.scrollHeight - height > epsilon;
9860
+ setIsTruncated(overflowWidth || overflowHeight);
9861
+ };
9862
+ const resizeObserver = new ResizeObserver(() => requestAnimationFrame(measure));
9828
9863
  resizeObserver.observe(el);
9864
+ const mutationObserver = new MutationObserver(() => measure());
9865
+ mutationObserver.observe(el, { childList: true, subtree: true, characterData: true });
9866
+ requestAnimationFrame(measure);
9829
9867
  return () => {
9830
9868
  resizeObserver.disconnect();
9869
+ mutationObserver.disconnect();
9831
9870
  };
9832
- }, []);
9833
- const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis.lineClamp ?? 3 : null;
9871
+ }, [children, ellipsis, lineClampLines]);
9834
9872
  const truncationClass = React4.useMemo(() => {
9835
9873
  if (!ellipsis) return "";
9836
9874
  if (typeof ellipsis === "number") return `line-clamp-${ellipsis}`;
@@ -9849,14 +9887,20 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9849
9887
  }, [lineClampLines, style]);
9850
9888
  const baseContent = /* @__PURE__ */ jsxRuntime.jsx(Comp, { ref: elementRef, className: cn(truncationClass, className), style: clampedStyle, children: normalizedChildren });
9851
9889
  let tooltipContent = normalizedChildren;
9852
- let tooltipSide = "top";
9853
9890
  if (typeof ellipsis === "object") {
9854
9891
  tooltipContent = ellipsis?.content ?? normalizedChildren;
9855
- tooltipSide = ellipsis?.side ?? "top";
9856
9892
  }
9893
+ const {
9894
+ className: tooltipContentClassName,
9895
+ arrowClassName: tooltipArrowClassName,
9896
+ side: tooltipContentSide,
9897
+ ...tooltipContentRest
9898
+ } = tooltipContentProps ?? {};
9899
+ const tooltipSide = (typeof ellipsis === "object" ? ellipsis?.side : void 0) ?? tooltipContentSide ?? "top";
9857
9900
  return /* @__PURE__ */ jsxRuntime.jsxs(
9858
9901
  Tooltip2,
9859
9902
  {
9903
+ ...tooltipProps,
9860
9904
  open,
9861
9905
  onOpenChange: (open2) => {
9862
9906
  setOpen(isTruncated && open2);
@@ -9867,8 +9911,12 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9867
9911
  TooltipContent2,
9868
9912
  {
9869
9913
  side: tooltipSide,
9870
- className: cn("text-white bg-[#8B8B8B] max-w-md wrap-break-word shadow-lg"),
9871
- arrowClassName: "bg-[#8B8B8B] fill-[#8B8B8B]",
9914
+ className: cn(
9915
+ "text-white bg-[#8B8B8B] max-w-xs sm:max-w-md wrap-break-word shadow-lg",
9916
+ tooltipContentClassName
9917
+ ),
9918
+ arrowClassName: cn("bg-[#8B8B8B] fill-[#8B8B8B]", tooltipArrowClassName),
9919
+ ...tooltipContentRest,
9872
9920
  children: tooltipContent
9873
9921
  }
9874
9922
  )