@chaibuilder/pages 0.16.14 → 0.16.15
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/{2AITGKQY-B7xwscsX.js → 2AITGKQY-2rt9M99C.js} +5 -5
- package/dist/{2AITGKQY-B9AnRLq_.cjs → 2AITGKQY-Cs6RBSPQ.cjs} +1 -1
- package/dist/{NCMVHL6D-CRMC-wXy.cjs → NCMVHL6D-CsC6nsSQ.cjs} +1 -1
- package/dist/{NCMVHL6D-B1mwht0Q.js → NCMVHL6D-vUfYKc6i.js} +4 -4
- package/dist/{ZDWCUMSJ-BqqPEOij.cjs → ZDWCUMSJ-B2OZjsr6.cjs} +1 -1
- package/dist/{ZDWCUMSJ-CxKNtXtp.js → ZDWCUMSJ-CzEWKlEU.js} +1 -1
- package/dist/active-in-another-tab-B0N5S-Bh.js +34 -0
- package/dist/active-in-another-tab-BK3cZf-x.cjs +1 -0
- package/dist/{add-new-language-page-D2a6GK-7.cjs → add-new-language-page-Dt1j-8Zg.cjs} +1 -1
- package/dist/{add-new-language-page-DD0qvJJs.js → add-new-language-page-YlqcCdlK.js} +20 -20
- package/dist/{add-new-page-01GDCaa4.cjs → add-new-page-DqhQUQBz.cjs} +1 -1
- package/dist/{add-new-page-CYtuChN1.js → add-new-page-aYomeid4.js} +1 -1
- package/dist/{ai-panel-content-DfdnvlS8.js → ai-panel-content-C6cH9rrC.js} +2 -2
- package/dist/{ai-panel-content-Ouz6pu_0.cjs → ai-panel-content-MOZmNIKP.cjs} +1 -1
- package/dist/{ai-panel-default-lang-Bi2fH1so.js → ai-panel-default-lang-BZHkFsox.js} +3 -3
- package/dist/{ai-panel-default-lang-N1pb8rzQ.cjs → ai-panel-default-lang-DOk_Q0IO.cjs} +2 -2
- package/dist/{ai-panel-other-lang-2JPRSyO1.js → ai-panel-other-lang-D2A46FTg.js} +3 -3
- package/dist/{ai-panel-other-lang-BysU1464.cjs → ai-panel-other-lang-qHrdvAMa.cjs} +1 -1
- package/dist/{ai-prompt-input-JeIqWZco.cjs → ai-prompt-input-BZSjjNJd.cjs} +1 -1
- package/dist/{ai-prompt-input-DadL_cng.js → ai-prompt-input-C6gDvvLQ.js} +2 -2
- package/dist/{ai-translation-prompt-CQb1L7NM.cjs → ai-translation-prompt-BqXo2CLp.cjs} +1 -1
- package/dist/{ai-translation-prompt-B0si-R0R.js → ai-translation-prompt-DTR0wbGt.js} +1 -1
- package/dist/continue-editing-in-this-client-C3T6Jzhi.cjs +1 -0
- package/dist/continue-editing-in-this-client-D2S1yCOM.js +24 -0
- package/dist/delete-page-BF1k60U2.js +70 -0
- package/dist/delete-page-x0DWKzsR.cjs +1 -0
- package/dist/{digital-asset-manager-B5FQGtGY.cjs → digital-asset-manager-BmlFt2T_.cjs} +1 -1
- package/dist/{digital-asset-manager-jfnmWRJj.js → digital-asset-manager-C8udwDBW.js} +1 -1
- package/dist/{duplicate-page-BNjfZ7Wd.cjs → duplicate-page-Dt_QZkTk.cjs} +1 -1
- package/dist/{duplicate-page-CERjaPIW.js → duplicate-page-u_6vUVo1.js} +13 -13
- package/dist/{dynamic-page-selector-Bpz_bvRu.cjs → dynamic-page-selector-Cgs_Y_Kl.cjs} +1 -1
- package/dist/{dynamic-page-selector-XEWV4iCf.js → dynamic-page-selector-DxBHmglP.js} +1 -1
- package/dist/index-BeWL6Sj6.cjs +5 -0
- package/dist/index-DI2Rwk5v.js +4820 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -34
- package/dist/index.js +21 -22
- package/dist/{json-diff-viewer-H-2DkGza.cjs → json-diff-viewer-D2g0Yab2.cjs} +1 -1
- package/dist/{json-diff-viewer-DyvKomxd.js → json-diff-viewer-QdUwk7yF.js} +6 -6
- package/dist/{lang-panel-BWP5A-FD.js → lang-panel-B8OD0GiA.js} +24 -24
- package/dist/{lang-panel-DcZ7u4em.cjs → lang-panel-M2Zb01lF.cjs} +1 -1
- package/dist/{mark-as-template-1oVraE1x.js → mark-as-template-CJ1mlxYT.js} +7 -7
- package/dist/{mark-as-template-B_FyVRRO.cjs → mark-as-template-DONU52b1.cjs} +1 -1
- package/dist/{no-language-page-content-JO4YYUx7.cjs → no-language-page-content-DD9Ok2Ku.cjs} +1 -1
- package/dist/{no-language-page-content-CEci_4j7.js → no-language-page-content-Dtm37LTJ.js} +1 -1
- package/dist/no-language-page-dialog-D3dvenZ7.cjs +1 -0
- package/dist/no-language-page-dialog-Dj_z2_hF.js +10 -0
- package/dist/{page-creator-DJJFl7px.js → page-creator-DIMFISo4.js} +52 -52
- package/dist/{page-creator-BGgoOA92.cjs → page-creator-DTC66ujU.cjs} +1 -1
- package/dist/page-lock-CI6BYvF_.cjs +1 -0
- package/dist/page-lock-DUlNr3os.js +30 -0
- package/dist/page-locked-dialog-BKwULMV7.js +133 -0
- package/dist/page-locked-dialog-DorIbva0.cjs +1 -0
- package/dist/page-manager-new-lNVrLOJp.cjs +1 -0
- package/dist/page-manager-new-znvqI9_L.js +354 -0
- package/dist/{page-manager-search-and-filter-DbUoW8Di.js → page-manager-search-and-filter-C-_w7N27.js} +1 -1
- package/dist/{page-manager-search-and-filter-Dgh8iyGp.cjs → page-manager-search-and-filter-pe0q0qnZ.cjs} +1 -1
- package/dist/{page-revisions-content-CwoXXE53.cjs → page-revisions-content-Caaj5TEI.cjs} +1 -1
- package/dist/{page-revisions-content-CxEJGxLY.js → page-revisions-content-CyLjyxNU.js} +19 -19
- package/dist/pages.css +1 -1
- package/dist/{publish-pages-content-CfAlmivf.js → publish-pages-content-Bih1W9C4.js} +88 -88
- package/dist/publish-pages-content-D5beVcQI.cjs +1 -0
- package/dist/{save-to-lib-BCaBfh0I.js → save-to-lib-BwpkJcT2.js} +1 -1
- package/dist/{save-to-lib-DpyJA0y1.cjs → save-to-lib-DPAERsi4.cjs} +1 -1
- package/dist/{selected-block-display-BmNhvYKu.js → selected-block-display-GXSf3y2s.js} +1 -1
- package/dist/{selected-block-display-CqnwyGRp.cjs → selected-block-display-s99Y91qI.cjs} +1 -1
- package/dist/{seo-panel-BH8fcGqr.js → seo-panel-BurZA566.js} +61 -61
- package/dist/{seo-panel-D-nKfsRJ.cjs → seo-panel-BxUfalVy.cjs} +1 -1
- package/dist/{shared-json-ld-m_OsVv8h.cjs → shared-json-ld-BYAdrPeC.cjs} +1 -1
- package/dist/{shared-json-ld-zTDoJzUv.js → shared-json-ld-DHWdJvQd.js} +39 -39
- package/dist/{slug-input-vzNtu37S.cjs → slug-input-CR2B1kDJ.cjs} +1 -1
- package/dist/{slug-input-CumDDlCk.js → slug-input-Z_ny7bgX.js} +1 -1
- package/dist/take-over-request-CnEpToCM.cjs +1 -0
- package/dist/take-over-request-DF2JsIes.js +63 -0
- package/dist/{theme-panel-footer-CdUmjB-e.js → theme-panel-footer-5mxFeEua.js} +4 -4
- package/dist/{theme-panel-footer-CKccBcd9.cjs → theme-panel-footer-C2CjHoBu.cjs} +1 -1
- package/dist/{unmark-as-template-BNFOsxIg.cjs → unmark-as-template-Dn90g1eh.cjs} +1 -1
- package/dist/{unmark-as-template-6ew-7bf8.js → unmark-as-template-JRRUYTOY.js} +1 -1
- package/dist/{unpublish-page-BZQpTpU3.cjs → unpublish-page-C3C_rTRd.cjs} +1 -1
- package/dist/{unpublish-page-BomE76Wg.js → unpublish-page-FZ8rbi7u.js} +9 -9
- package/dist/{web-preview-jo8lnpEx.js → web-preview-CGBKG162.js} +1 -1
- package/dist/{web-preview-C5QTX7bS.cjs → web-preview-NdxC92Fk.cjs} +1 -1
- package/package.json +3 -3
- package/dist/delete-page-C8Nt7IYF.cjs +0 -1
- package/dist/delete-page-_96Di9yN.js +0 -40
- package/dist/index-Pdb5tSRL.cjs +0 -5
- package/dist/index-e9WlBH0R.js +0 -4960
- package/dist/page-lock-request-BoYzkcyt.cjs +0 -1
- package/dist/page-lock-request-WzpcD2ZN.js +0 -75
- package/dist/page-locked-by-dialog-Djvjp2Hx.js +0 -68
- package/dist/page-locked-by-dialog-bvI27OZ6.cjs +0 -1
- package/dist/page-manager-new-CMfGorRQ.cjs +0 -1
- package/dist/page-manager-new-DmVX0qLk.js +0 -354
- package/dist/publish-pages-content-BRu7qwAo.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),a=require("lucide-react"),n=require("./index-BeWL6Sj6.cjs"),l=()=>{const{setPageLockMeta:c}=n.usePageLockMeta(),{t}=i.useTranslation(),r=async()=>{c({})};return e.jsx(n.BlurContainer,{children:e.jsxs(s.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(s.CardHeader,{className:"space-y-1",children:e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(a.CheckCircle,{className:"h-6 w-6 text-green-500"}),t("You can edit the page now")]})}),e.jsx(s.CardContent,{className:"space-y-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:t("This page is released by other user you can continue editing now")})}),e.jsx(s.CardFooter,{className:"flex gap-2",children:e.jsxs(s.Button,{variant:"default",onClick:r,className:"flex-1 gap-2",children:[e.jsx(a.Check,{className:"h-4 w-4"}),t("Continue Editing")]})})]})})};exports.default=l;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as e, jsxs as t } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation as r } from "@chaibuilder/sdk";
|
|
3
|
+
import { Card as c, CardHeader as o, CardTitle as i, CardContent as l, CardFooter as d, Button as m } from "@chaibuilder/sdk/ui";
|
|
4
|
+
import { CheckCircle as h, Check as u } from "lucide-react";
|
|
5
|
+
import { b as p, B as C } from "./index-DI2Rwk5v.js";
|
|
6
|
+
const k = () => {
|
|
7
|
+
const { setPageLockMeta: n } = p(), { t: a } = r(), s = async () => {
|
|
8
|
+
n({});
|
|
9
|
+
};
|
|
10
|
+
return /* @__PURE__ */ e(C, { children: /* @__PURE__ */ t(c, { className: "mx-auto w-full max-w-md", children: [
|
|
11
|
+
/* @__PURE__ */ e(o, { className: "space-y-1", children: /* @__PURE__ */ t(i, { className: "flex items-center gap-2 text-xl", children: [
|
|
12
|
+
/* @__PURE__ */ e(h, { className: "h-6 w-6 text-green-500" }),
|
|
13
|
+
a("You can edit the page now")
|
|
14
|
+
] }) }),
|
|
15
|
+
/* @__PURE__ */ e(l, { className: "space-y-4", children: /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a("This page is released by other user you can continue editing now") }) }),
|
|
16
|
+
/* @__PURE__ */ e(d, { className: "flex gap-2", children: /* @__PURE__ */ t(m, { variant: "default", onClick: s, className: "flex-1 gap-2", children: [
|
|
17
|
+
/* @__PURE__ */ e(u, { className: "h-4 w-4" }),
|
|
18
|
+
a("Continue Editing")
|
|
19
|
+
] }) })
|
|
20
|
+
] }) });
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
k as default
|
|
24
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as i, jsxs as n } from "react/jsx-runtime";
|
|
2
|
+
import { c as N, q as A, m as E, g as b, l as k, L as U } from "./index-DI2Rwk5v.js";
|
|
3
|
+
import { useTranslation as G, useLanguages as R, useSidebarActivePanel as W } from "@chaibuilder/sdk";
|
|
4
|
+
import { Dialog as q, DialogContent as B, DialogHeader as F, DialogTitle as H, DialogDescription as M, DialogFooter as Q, Button as v } from "@chaibuilder/sdk/ui";
|
|
5
|
+
import { get as $ } from "lodash-es";
|
|
6
|
+
import { useMemo as w } from "react";
|
|
7
|
+
const P = (e, l) => {
|
|
8
|
+
const t = l.filter((c) => c.parent === e);
|
|
9
|
+
if (t.length === 0) return 0;
|
|
10
|
+
let a = t.length;
|
|
11
|
+
return t.forEach((c) => {
|
|
12
|
+
a += P(c.id, l);
|
|
13
|
+
}), a;
|
|
14
|
+
};
|
|
15
|
+
function X({ page: e, onClose: l }) {
|
|
16
|
+
const { t } = G(), [, a] = N(), { mutate: c, isPending: h } = A(), { data: f } = E(), { data: m = [] } = b(), { setSelectedLang: S, fallbackLang: x } = R(), [, L] = W(), s = !(e != null && e.primaryPage), { data: r = [] } = k(s ? e == null ? void 0 : e.id : void 0), D = w(() => !s || !r ? 0 : r.filter((o) => o.id !== (e == null ? void 0 : e.id)).length, [s, r, e == null ? void 0 : e.id]), u = w(() => {
|
|
17
|
+
if (!(e != null && e.id) || !m.length) return 0;
|
|
18
|
+
let o = P(e.id, m);
|
|
19
|
+
return s && r && r.length > 0 && r.forEach((y) => {
|
|
20
|
+
y.id !== e.id && (o += P(y.id, m));
|
|
21
|
+
}), o;
|
|
22
|
+
}, [e == null ? void 0 : e.id, m, s, r]), C = () => {
|
|
23
|
+
h || c(e, {
|
|
24
|
+
onSuccess: () => {
|
|
25
|
+
e != null && e.primaryPage ? (window.history.replaceState({}, "", `/?page=${e.primaryPage}`), a(new URLSearchParams({ page: e.primaryPage }))) : (window.history.replaceState({}, "", "/"), a(new URLSearchParams())), window.dispatchEvent(new PopStateEvent("popstate")), S(x), L("outline"), l();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}, d = f == null ? void 0 : f.find((o) => o.key === (e == null ? void 0 : e.pageType));
|
|
29
|
+
return /* @__PURE__ */ i(q, { open: !!e, onOpenChange: l, children: /* @__PURE__ */ n(B, { children: [
|
|
30
|
+
/* @__PURE__ */ n(F, { children: [
|
|
31
|
+
/* @__PURE__ */ i(H, { children: t("Confirm Deletion") }),
|
|
32
|
+
/* @__PURE__ */ n(M, { className: "py-4 text-slate-500", children: [
|
|
33
|
+
/* @__PURE__ */ n("div", { children: [
|
|
34
|
+
t("Are you sure you want to remove"),
|
|
35
|
+
" ",
|
|
36
|
+
/* @__PURE__ */ i("b", { children: (e == null ? void 0 : e.name) ?? (e == null ? void 0 : e.slug) }),
|
|
37
|
+
" ",
|
|
38
|
+
d != null && d.hasSlug ? (d == null ? void 0 : d.name) + "?" : t("page?")
|
|
39
|
+
] }),
|
|
40
|
+
s && (D > 0 || u > 0) && /* @__PURE__ */ n("div", { className: "mt-3 rounded-md bg-red-50 p-3 text-sm", children: [
|
|
41
|
+
/* @__PURE__ */ n("div", { className: "font-semibold text-red-800", children: [
|
|
42
|
+
t("Warning: Deleting this primary page will also delete"),
|
|
43
|
+
":"
|
|
44
|
+
] }),
|
|
45
|
+
/* @__PURE__ */ n("ul", { className: "mt-2 list-inside list-disc space-y-1 text-red-700", children: [
|
|
46
|
+
u > 0 && /* @__PURE__ */ n("li", { children: [
|
|
47
|
+
/* @__PURE__ */ i("span", { className: "font-medium", children: u }),
|
|
48
|
+
" ",
|
|
49
|
+
t(u === 1 ? "nested child page" : "nested child pages")
|
|
50
|
+
] }),
|
|
51
|
+
D > 0 && /* @__PURE__ */ i("li", { children: t("All associated language pages") })
|
|
52
|
+
] })
|
|
53
|
+
] }),
|
|
54
|
+
e.lang && /* @__PURE__ */ n("div", { className: "py-2 text-sm", children: [
|
|
55
|
+
t("Language"),
|
|
56
|
+
":",
|
|
57
|
+
" ",
|
|
58
|
+
/* @__PURE__ */ i("span", { className: "font-medium text-gray-500", children: $(U, e.lang, e.lang) })
|
|
59
|
+
] })
|
|
60
|
+
] })
|
|
61
|
+
] }),
|
|
62
|
+
/* @__PURE__ */ n(Q, { children: [
|
|
63
|
+
/* @__PURE__ */ i(v, { variant: "outline", onClick: l, children: t("Cancel") }),
|
|
64
|
+
/* @__PURE__ */ i(v, { variant: "destructive", disabled: h, onClick: C, children: t(h ? "Deleting..." : "Delete") })
|
|
65
|
+
] })
|
|
66
|
+
] }) });
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
X as default
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),o=require("./index-BeWL6Sj6.cjs"),f=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),N=require("lodash-es"),v=require("react"),j=(e,r)=>{const n=r.filter(u=>u.parent===e);if(n.length===0)return 0;let a=n.length;return n.forEach(u=>{a+=j(u.id,r)}),a};function A({page:e,onClose:r}){const{t:n}=f.useTranslation(),[,a]=o.useSearchParams(),{mutate:u,isPending:x}=o.useDeletePage(),{data:P}=o.usePageTypes(),{data:h=[]}=o.useWebsitePages(),{setSelectedLang:S,fallbackLang:w}=f.useLanguages(),[,C]=f.useSidebarActivePanel(),l=!(e!=null&&e.primaryPage),{data:i=[]}=o.useLanguagePages(l?e==null?void 0:e.id:void 0),y=v.useMemo(()=>!l||!i?0:i.filter(c=>c.id!==(e==null?void 0:e.id)).length,[l,i,e==null?void 0:e.id]),m=v.useMemo(()=>{if(!(e!=null&&e.id)||!h.length)return 0;let c=j(e.id,h);return l&&i&&i.length>0&&i.forEach(D=>{D.id!==e.id&&(c+=j(D.id,h))}),c},[e==null?void 0:e.id,h,l,i]),L=()=>{x||u(e,{onSuccess:()=>{e!=null&&e.primaryPage?(window.history.replaceState({},"",`/?page=${e.primaryPage}`),a(new URLSearchParams({page:e.primaryPage}))):(window.history.replaceState({},"","/"),a(new URLSearchParams)),window.dispatchEvent(new PopStateEvent("popstate")),S(w),C("outline"),r()}})},d=P==null?void 0:P.find(c=>c.key===(e==null?void 0:e.pageType));return t.jsx(s.Dialog,{open:!!e,onOpenChange:r,children:t.jsxs(s.DialogContent,{children:[t.jsxs(s.DialogHeader,{children:[t.jsx(s.DialogTitle,{children:n("Confirm Deletion")}),t.jsxs(s.DialogDescription,{className:"py-4 text-slate-500",children:[t.jsxs("div",{children:[n("Are you sure you want to remove")," ",t.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",d!=null&&d.hasSlug?(d==null?void 0:d.name)+"?":n("page?")]}),l&&(y>0||m>0)&&t.jsxs("div",{className:"mt-3 rounded-md bg-red-50 p-3 text-sm",children:[t.jsxs("div",{className:"font-semibold text-red-800",children:[n("Warning: Deleting this primary page will also delete"),":"]}),t.jsxs("ul",{className:"mt-2 list-inside list-disc space-y-1 text-red-700",children:[m>0&&t.jsxs("li",{children:[t.jsx("span",{className:"font-medium",children:m})," ",n(m===1?"nested child page":"nested child pages")]}),y>0&&t.jsx("li",{children:n("All associated language pages")})]})]}),e.lang&&t.jsxs("div",{className:"py-2 text-sm",children:[n("Language"),":"," ",t.jsx("span",{className:"font-medium text-gray-500",children:N.get(o.LANGUAGES,e.lang,e.lang)})]})]})]}),t.jsxs(s.DialogFooter,{children:[t.jsx(s.Button,{variant:"outline",onClick:r,children:n("Cancel")}),t.jsx(s.Button,{variant:"destructive",disabled:x,onClick:L,children:n(x?"Deleting...":"Delete")})]})]})})}exports.default=A;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-Pdb5tSRL.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-BeWL6Sj6.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
@@ -5,7 +5,7 @@ import { find as Ge, merge as Oe, pick as Y, first as Be, isEmpty as Ke } from "
|
|
|
5
5
|
import { ChevronLeft as he, ChevronRight as Qe, Loader as B, AlertCircle as Re, Copy as fe, Pencil as We, Link as Ve, Search as He, RefreshCwIcon as Xe, Archive as Ze, Film as Je, ImageIcon as Ye, Edit as et, Trash2 as tt, Check as it, Upload as lt, AlertTriangle as at } from "lucide-react";
|
|
6
6
|
import pe, { useState as y, useMemo as ge, useEffect as O, useCallback as M, Suspense as rt } from "react";
|
|
7
7
|
import { useDropzone as nt } from "react-dropzone";
|
|
8
|
-
import {
|
|
8
|
+
import { aT as K, ar as Q, A as b, aU as st } from "./index-DI2Rwk5v.js";
|
|
9
9
|
import { toast as A } from "sonner";
|
|
10
10
|
import { f as ct, c as ot } from "./image-compression-DsZ1oqpb.js";
|
|
11
11
|
import { useQueryClient as te, useMutation as ie, useQuery as xe } from "@tanstack/react-query";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-BeWL6Sj6.cjs"),N=require("@tanstack/react-query"),v=require("sonner"),E=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),P=require("lodash-es"),C=require("lucide-react"),g=require("react"),A=require("./slug-input-CR2B1kDJ.cjs"),T=()=>{const t=p.useApiUrl(),u=N.useQueryClient(),h=p.useFetch();return N.useMutation({mutationFn:async({pageId:s,name:x,slug:r})=>{const o={pageId:s,name:x};return r&&(o.slug=r),await h(t,{action:"DUPLICATE_PAGE",data:o})},onSuccess:()=>{u.invalidateQueries({queryKey:[p.ACTIONS.GET_WEBSITE_PAGES]}),v.toast.success("Page duplicated successfully")},onError:s=>{v.toast.error("Failed to duplicate page",{description:s.message||"An error occurred while duplicating the page"})}})},w=({page:t,onClose:u,closePanel:h=()=>{}})=>{const{t:s}=E.useTranslation(),{mutate:x,isPending:r}=T(),[o,i]=g.useState(null),[d,D]=g.useState(`${t.name} (Copy)`),b=p.useChangePage(),n=P.isEmpty(t.slug),[m,I]=g.useState(n?"":`${t.slug.split("/").pop()}-copy`),f=n?"":P.initial(t.slug.split("/")).join("/"),[y,j]=g.useState(!1),q=l=>{if(l.preventDefault(),!d.trim()){i(s("Name is required"));return}if(!n&&!m.trim()){i(s("Slug is required"));return}i(null),j(!0);const S={pageId:t.id,name:d};n||(S.slug=`${f}/${m}`),x(S,{onSuccess:c=>{j(!1),u(),b(c.id,h)},onError:c=>{j(!1),c.code==="SLUG_EXISTS"?i(s("A page with this slug already exists. Please choose a different slug.")):c.code==="INVALID_SLUG"?i(s("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens.")):c.code==="PERMISSION_DENIED"?i(s("You don't have permission to duplicate this page.")):i(c.message||s("Failed to duplicate page. Please try again later."))}})};return e.jsx(a.Dialog,{open:!!t,onOpenChange:u,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:s("Duplicate Page")}),e.jsx(a.DialogDescription,{children:s("Create a copy of the page with a new name and slug")})]}),e.jsxs("div",{className:"mb-4 rounded-md bg-gray-50 p-3",children:[e.jsxs("h3",{className:"mb-1 text-sm font-medium",children:[s("Duplicating:"),":"]}),e.jsxs("div",{className:"flex flex-col gap-1 text-sm text-gray-700",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Name"),":"]})," ",t.name]}),!n&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Slug"),":"]})," ",t.slug]}),e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Type"),":"]})," ",t.pageType]})]})]}),e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:s("Name")}),e.jsx(a.Input,{id:"name",value:d,onChange:l=>D(l.target.value),required:!0})]}),!n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:s("Slug")}),e.jsx(A.SlugInput,{value:m,onChange:l=>I(l),parentSlug:f,onValidationChange:l=>{i(l?null:s("Invalid slug"))}})]}),o&&e.jsxs(a.Alert,{variant:"destructive",className:"py-2",children:[e.jsx(C.AlertCircle,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a.Button,{type:"button",variant:"outline",onClick:u,disabled:r,children:s("Cancel")}),e.jsx(a.Button,{type:"submit",disabled:!d.trim()||!n&&!m.trim()||r||y,children:s(r||y?"Duplicating...":"Duplicate")})]})]})]})})};exports.default=w;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jsx as t, jsxs as a } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useQueryClient as
|
|
2
|
+
import { aq as C, ar as A, A as T, as as w } from "./index-DI2Rwk5v.js";
|
|
3
|
+
import { useQueryClient as q, useMutation as F } from "@tanstack/react-query";
|
|
4
4
|
import { toast as v } from "sonner";
|
|
5
|
-
import { useTranslation as
|
|
6
|
-
import { Dialog as G, DialogContent as L, DialogHeader as U, DialogTitle as j, DialogDescription as $, Label as D, Input as O, Alert as
|
|
7
|
-
import { isEmpty as
|
|
8
|
-
import { AlertCircle as
|
|
5
|
+
import { useTranslation as _ } from "@chaibuilder/sdk";
|
|
6
|
+
import { Dialog as G, DialogContent as L, DialogHeader as U, DialogTitle as j, DialogDescription as $, Label as D, Input as O, Alert as B, Button as P } from "@chaibuilder/sdk/ui";
|
|
7
|
+
import { isEmpty as M, initial as Q } from "lodash-es";
|
|
8
|
+
import { AlertCircle as V } from "lucide-react";
|
|
9
9
|
import { useState as p } from "react";
|
|
10
|
-
import { S as
|
|
10
|
+
import { S as k } from "./slug-input-Z_ny7bgX.js";
|
|
11
11
|
const H = () => {
|
|
12
|
-
const s = C(), o =
|
|
13
|
-
return
|
|
12
|
+
const s = C(), o = q(), g = A();
|
|
13
|
+
return F({
|
|
14
14
|
mutationFn: async ({ pageId: e, name: h, slug: r }) => {
|
|
15
15
|
const u = {
|
|
16
16
|
pageId: e,
|
|
@@ -38,7 +38,7 @@ const H = () => {
|
|
|
38
38
|
closePanel: g = () => {
|
|
39
39
|
}
|
|
40
40
|
}) => {
|
|
41
|
-
const { t: e } =
|
|
41
|
+
const { t: e } = _(), { mutate: h, isPending: r } = H(), [u, i] = p(null), [m, x] = p(`${s.name} (Copy)`), I = w(), l = M(s.slug), [d, E] = p(l ? "" : `${s.slug.split("/").pop()}-copy`), y = l ? "" : Q(s.slug.split("/")).join("/"), [N, f] = p(!1), b = (n) => {
|
|
42
42
|
if (n.preventDefault(), !m.trim()) {
|
|
43
43
|
i(e("Name is required"));
|
|
44
44
|
return;
|
|
@@ -106,7 +106,7 @@ const H = () => {
|
|
|
106
106
|
!l && /* @__PURE__ */ a("div", { className: "space-y-2", children: [
|
|
107
107
|
/* @__PURE__ */ t(D, { htmlFor: "slug", className: "text-sm", children: e("Slug") }),
|
|
108
108
|
/* @__PURE__ */ t(
|
|
109
|
-
|
|
109
|
+
k,
|
|
110
110
|
{
|
|
111
111
|
value: d,
|
|
112
112
|
onChange: (n) => E(n),
|
|
@@ -117,8 +117,8 @@ const H = () => {
|
|
|
117
117
|
}
|
|
118
118
|
)
|
|
119
119
|
] }),
|
|
120
|
-
u && /* @__PURE__ */ a(
|
|
121
|
-
/* @__PURE__ */ t(
|
|
120
|
+
u && /* @__PURE__ */ a(B, { variant: "destructive", className: "py-2", children: [
|
|
121
|
+
/* @__PURE__ */ t(V, { className: "h-4 w-4" }),
|
|
122
122
|
/* @__PURE__ */ t("span", { className: "text-sm", children: u })
|
|
123
123
|
] }),
|
|
124
124
|
/* @__PURE__ */ a("div", { className: "flex justify-end gap-2", children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-BeWL6Sj6.cjs"),f=({isDefaultLang:r,searchQuery:l,setSearchQuery:c})=>e.jsx(a.Input,{type:"text",autoFocus:!0,value:r?l:"",onChange:t=>c(t.target.value),placeholder:r?"Search pages...":"To search select default language",disabled:!r,onKeyDown:t=>t.stopPropagation()}),m=({dynamicPage:r,setDynamicPage:l,searchQuery:c,setSearchQuery:t,dynamicPages:n})=>{const{selectedLang:o,fallbackLang:i}=x.useLanguages(),u=(o==null?void 0:o.length)===0;return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",className:"w-max focus:outline-none focus:ring-0 border-[0px] rounded-md py-1 text-sm h-max border border-gray-200 hover:bg-gray-100 pl-4",children:[r?h.get(r,"name"):"Select Page",e.jsx(p.ChevronDown,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(a.DropdownMenuContent,{className:"w-96 divide-y shadow-xl p-0 max-h-[75vh]",children:[e.jsx("div",{className:"p-1.5 bg-gray-50/30",children:e.jsx(f,{isDefaultLang:u,searchQuery:c,setSearchQuery:t})}),(n==null?void 0:n.length)===0?e.jsx("div",{className:"h-24 text-xs flex items-center justify-center",children:"No pages found"}):n==null?void 0:n.map(s=>e.jsx(a.DropdownMenuItem,{onClick:()=>l(s),disabled:u?i!==s.lang:o!==s.lang,className:`flex flex-col justify-start cursor-pointer overflow-x-auto whitespace-nowrap no-scrollbar ${s.id===(r==null?void 0:r.id)?"bg-blue-50":"hover:bg-gray-50"}`,children:e.jsx("div",{className:"w-full text-xs whitespace-nowrap px-2 py-[2px]",children:e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"font-mono font-medium text-gray-500 text-xs rounded-full px-2 py-[1px] border border-gray-300 truncate",children:s.slug})]})})},s.id))]})]})},j=()=>{const{dynamicPage:r,dynamicPages:l,allLangPages:c,selectedLang:t,searchQuery:n,updateDynamicPage:o,updateSearchQuery:i,onChangeLanguage:u}=g.useDynamicPageSelector(),s=d.useRef(void 0);return d.useEffect(()=>{s.current!==t&&r&&(u(),s.current=t)},[t,l]),e.jsx("div",{className:"relative",children:e.jsx(m,{dynamicPage:r,setDynamicPage:o,searchQuery:n,setSearchQuery:i,dynamicPages:c})})};exports.default=j;
|
|
@@ -4,7 +4,7 @@ import { DropdownMenu as h, DropdownMenuTrigger as p, Button as m, DropdownMenuC
|
|
|
4
4
|
import { get as v } from "lodash-es";
|
|
5
5
|
import { ChevronDown as w } from "lucide-react";
|
|
6
6
|
import { useRef as b, useEffect as N } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { n as y } from "./index-DI2Rwk5v.js";
|
|
8
8
|
const D = ({
|
|
9
9
|
isDefaultLang: e,
|
|
10
10
|
searchQuery: l,
|