@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 +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +68 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5273,7 +5273,8 @@ var getDialogTemplates = ({ setOpen = () => {
|
|
|
5273
5273
|
title: "error.session_expired.title",
|
|
5274
5274
|
description: "error.session_expired.description",
|
|
5275
5275
|
confirmText: "error.session_expired.confirm_text",
|
|
5276
|
-
showCancel: false
|
|
5276
|
+
showCancel: false,
|
|
5277
|
+
persistent: true
|
|
5277
5278
|
},
|
|
5278
5279
|
"error.user_not_found": {
|
|
5279
5280
|
variant: "error",
|
|
@@ -5400,9 +5401,17 @@ var getDialogTemplates = ({ setOpen = () => {
|
|
|
5400
5401
|
var useDialogAlertStore = create((set, get) => ({
|
|
5401
5402
|
open: false,
|
|
5402
5403
|
dialogProps: {},
|
|
5403
|
-
setOpen: (
|
|
5404
|
+
setOpen: (open) => {
|
|
5405
|
+
if (!open && get().isExclusive) {
|
|
5406
|
+
get().setIsExclusive(false);
|
|
5407
|
+
}
|
|
5408
|
+
set({ open });
|
|
5409
|
+
},
|
|
5404
5410
|
setDialogProps: (data) => set({ dialogProps: data }),
|
|
5405
5411
|
openDialogAlert: (payload) => {
|
|
5412
|
+
if (get().isExclusive) {
|
|
5413
|
+
return;
|
|
5414
|
+
}
|
|
5406
5415
|
let templateVal;
|
|
5407
5416
|
if (payload?.template) {
|
|
5408
5417
|
templateVal = getDialogTemplates({ setOpen: get().setOpen })[payload.template];
|
|
@@ -5413,10 +5422,13 @@ var useDialogAlertStore = create((set, get) => ({
|
|
|
5413
5422
|
}
|
|
5414
5423
|
get().setDialogProps({ ...templateVal, ...payload?.props });
|
|
5415
5424
|
get().setOpen(true);
|
|
5425
|
+
get().setIsExclusive(payload?.isExclusive ?? false);
|
|
5416
5426
|
},
|
|
5417
5427
|
closeDialogAlert: () => {
|
|
5418
5428
|
set({ open: false });
|
|
5419
|
-
}
|
|
5429
|
+
},
|
|
5430
|
+
isExclusive: false,
|
|
5431
|
+
setIsExclusive: (isExclusive) => set({ isExclusive })
|
|
5420
5432
|
}));
|
|
5421
5433
|
var DialogAlertProvider = ({ children, i18nResource, i18nLang }) => {
|
|
5422
5434
|
const open = useDialogAlertStore((state) => state.open);
|
|
@@ -5446,16 +5458,16 @@ var DialogAlertProvider = ({ children, i18nResource, i18nLang }) => {
|
|
|
5446
5458
|
var openDialogAlert = useDialogAlertStore.getState().openDialogAlert;
|
|
5447
5459
|
var closeDialogAlert = useDialogAlertStore.getState().closeDialogAlert;
|
|
5448
5460
|
var openErrorDialogAlert = (error) => {
|
|
5449
|
-
if (error
|
|
5450
|
-
openDialogAlert({ template: "error.something_went_wrong", props: { description: error.message } });
|
|
5451
|
-
} else if (error.isAxiosError) {
|
|
5461
|
+
if (error.isAxiosError) {
|
|
5452
5462
|
let template = "error.something_went_wrong";
|
|
5463
|
+
let props = void 0;
|
|
5453
5464
|
switch (error.response?.status) {
|
|
5454
5465
|
case 400:
|
|
5455
5466
|
template = "error.invalid_incomplete_data";
|
|
5456
5467
|
break;
|
|
5457
5468
|
case 401:
|
|
5458
5469
|
template = "error.session_expired";
|
|
5470
|
+
props = { confirmText: void 0 };
|
|
5459
5471
|
break;
|
|
5460
5472
|
case 403:
|
|
5461
5473
|
template = "error.permission_denied";
|
|
@@ -5470,7 +5482,9 @@ var openErrorDialogAlert = (error) => {
|
|
|
5470
5482
|
template = "error.api_db_error";
|
|
5471
5483
|
break;
|
|
5472
5484
|
}
|
|
5473
|
-
openDialogAlert({ template });
|
|
5485
|
+
openDialogAlert({ template, props });
|
|
5486
|
+
} else if (error instanceof Error) {
|
|
5487
|
+
openDialogAlert({ template: "error.something_went_wrong", props: { description: error.message } });
|
|
5474
5488
|
} else {
|
|
5475
5489
|
openDialogAlert({ template: "error.something_went_wrong" });
|
|
5476
5490
|
}
|
|
@@ -9770,27 +9784,51 @@ var CropperModal = ({
|
|
|
9770
9784
|
}
|
|
9771
9785
|
);
|
|
9772
9786
|
};
|
|
9773
|
-
var Truncated = ({
|
|
9787
|
+
var Truncated = ({
|
|
9788
|
+
children,
|
|
9789
|
+
className,
|
|
9790
|
+
ellipsis = true,
|
|
9791
|
+
as = "p",
|
|
9792
|
+
style,
|
|
9793
|
+
tooltipProps,
|
|
9794
|
+
tooltipContentProps
|
|
9795
|
+
}) => {
|
|
9774
9796
|
const elementRef = useRef(null);
|
|
9775
9797
|
const [open, setOpen] = useState(false);
|
|
9776
9798
|
const [isTruncated, setIsTruncated] = useState(false);
|
|
9777
9799
|
const Comp = as;
|
|
9778
9800
|
const normalizedChildren = typeof children === "string" ? children.replace(/>/g, ">\u200B") : children;
|
|
9801
|
+
const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis?.lineClamp ?? 3 : null;
|
|
9779
9802
|
useEffect(() => {
|
|
9780
9803
|
const el = elementRef.current;
|
|
9781
9804
|
if (!el) return;
|
|
9782
|
-
const
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9805
|
+
const measure = () => {
|
|
9806
|
+
if (!ellipsis) {
|
|
9807
|
+
setIsTruncated(false);
|
|
9808
|
+
return;
|
|
9809
|
+
}
|
|
9810
|
+
const rect = el.getBoundingClientRect();
|
|
9811
|
+
const width = el.clientWidth || el.offsetWidth || rect.width;
|
|
9812
|
+
const height = el.clientHeight || el.offsetHeight || rect.height;
|
|
9813
|
+
if (!width || !height) {
|
|
9814
|
+
setIsTruncated(false);
|
|
9815
|
+
return;
|
|
9816
|
+
}
|
|
9817
|
+
const epsilon = 1;
|
|
9818
|
+
const overflowWidth = el.scrollWidth - width > epsilon;
|
|
9819
|
+
const overflowHeight = el.scrollHeight - height > epsilon;
|
|
9820
|
+
setIsTruncated(overflowWidth || overflowHeight);
|
|
9821
|
+
};
|
|
9822
|
+
const resizeObserver = new ResizeObserver(() => requestAnimationFrame(measure));
|
|
9788
9823
|
resizeObserver.observe(el);
|
|
9824
|
+
const mutationObserver = new MutationObserver(() => measure());
|
|
9825
|
+
mutationObserver.observe(el, { childList: true, subtree: true, characterData: true });
|
|
9826
|
+
requestAnimationFrame(measure);
|
|
9789
9827
|
return () => {
|
|
9790
9828
|
resizeObserver.disconnect();
|
|
9829
|
+
mutationObserver.disconnect();
|
|
9791
9830
|
};
|
|
9792
|
-
}, []);
|
|
9793
|
-
const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis.lineClamp ?? 3 : null;
|
|
9831
|
+
}, [children, ellipsis, lineClampLines]);
|
|
9794
9832
|
const truncationClass = useMemo(() => {
|
|
9795
9833
|
if (!ellipsis) return "";
|
|
9796
9834
|
if (typeof ellipsis === "number") return `line-clamp-${ellipsis}`;
|
|
@@ -9809,14 +9847,20 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
|
|
|
9809
9847
|
}, [lineClampLines, style]);
|
|
9810
9848
|
const baseContent = /* @__PURE__ */ jsx(Comp, { ref: elementRef, className: cn(truncationClass, className), style: clampedStyle, children: normalizedChildren });
|
|
9811
9849
|
let tooltipContent = normalizedChildren;
|
|
9812
|
-
let tooltipSide = "top";
|
|
9813
9850
|
if (typeof ellipsis === "object") {
|
|
9814
9851
|
tooltipContent = ellipsis?.content ?? normalizedChildren;
|
|
9815
|
-
tooltipSide = ellipsis?.side ?? "top";
|
|
9816
9852
|
}
|
|
9853
|
+
const {
|
|
9854
|
+
className: tooltipContentClassName,
|
|
9855
|
+
arrowClassName: tooltipArrowClassName,
|
|
9856
|
+
side: tooltipContentSide,
|
|
9857
|
+
...tooltipContentRest
|
|
9858
|
+
} = tooltipContentProps ?? {};
|
|
9859
|
+
const tooltipSide = (typeof ellipsis === "object" ? ellipsis?.side : void 0) ?? tooltipContentSide ?? "top";
|
|
9817
9860
|
return /* @__PURE__ */ jsxs(
|
|
9818
9861
|
Tooltip2,
|
|
9819
9862
|
{
|
|
9863
|
+
...tooltipProps,
|
|
9820
9864
|
open,
|
|
9821
9865
|
onOpenChange: (open2) => {
|
|
9822
9866
|
setOpen(isTruncated && open2);
|
|
@@ -9827,8 +9871,12 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
|
|
|
9827
9871
|
TooltipContent2,
|
|
9828
9872
|
{
|
|
9829
9873
|
side: tooltipSide,
|
|
9830
|
-
className: cn(
|
|
9831
|
-
|
|
9874
|
+
className: cn(
|
|
9875
|
+
"text-white bg-[#8B8B8B] max-w-xs sm:max-w-md wrap-break-word shadow-lg",
|
|
9876
|
+
tooltipContentClassName
|
|
9877
|
+
),
|
|
9878
|
+
arrowClassName: cn("bg-[#8B8B8B] fill-[#8B8B8B]", tooltipArrowClassName),
|
|
9879
|
+
...tooltipContentRest,
|
|
9832
9880
|
children: tooltipContent
|
|
9833
9881
|
}
|
|
9834
9882
|
)
|