@chaibuilder/pages 0.15.3 → 0.15.5
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-o6FgGSqg.cjs → 2AITGKQY-D4uLyw6-.cjs} +1 -1
- package/dist/{2AITGKQY-DhC0sF1x.js → 2AITGKQY-DYwNjBFe.js} +2 -2
- package/dist/{NCMVHL6D-BPM6RHYa.cjs → NCMVHL6D-C-L7-X3f.cjs} +1 -1
- package/dist/{NCMVHL6D-D7HU3akD.js → NCMVHL6D-DVB60g_2.js} +2 -2
- package/dist/{ZDWCUMSJ-NVCxv9uE.cjs → ZDWCUMSJ-BORULBXb.cjs} +1 -1
- package/dist/{ZDWCUMSJ-Cr1v3giV.js → ZDWCUMSJ-Dp6ML_tn.js} +1 -1
- package/dist/{add-new-language-page-D3PSLiUv.cjs → add-new-language-page-D4VPifNs.cjs} +1 -1
- package/dist/{add-new-language-page-8q4Ku3eg.js → add-new-language-page-DENCjC_f.js} +2 -2
- package/dist/{add-new-page-YpzILOYq.cjs → add-new-page-BuK6We-q.cjs} +1 -1
- package/dist/{add-new-page-BpvpSM4X.js → add-new-page-CD-9ppdS.js} +1 -1
- package/dist/{delete-page-w64MO7db.cjs → delete-page-B-TP6nJ7.cjs} +1 -1
- package/dist/{delete-page-CXRJjJ4o.js → delete-page-CatRlDfx.js} +1 -1
- package/dist/digital-asset-manager-DL2nAqUC.cjs +1 -0
- package/dist/digital-asset-manager-KakxBkBC.js +917 -0
- package/dist/{duplicate-page-DB_c7V2t.cjs → duplicate-page-D4Oiy71Q.cjs} +1 -1
- package/dist/{duplicate-page-CSQs2MOp.js → duplicate-page-DEmh0df0.js} +2 -2
- package/dist/{dynamic-page-selector-DTk4oull.js → dynamic-page-selector-8g1-84iW.js} +1 -1
- package/dist/{dynamic-page-selector-CF9nb6i_.cjs → dynamic-page-selector-Cz6zWaKo.cjs} +1 -1
- package/dist/index-Blg1T7nL.cjs +5 -0
- package/dist/{index-BuXZJnGo.js → index-zaGKeGBW.js} +850 -765
- package/dist/index.cjs +1 -1
- package/dist/index.js +6 -6
- package/dist/{json-diff-viewer-oyxMD3Hc.js → json-diff-viewer-BF0qFBif.js} +1 -1
- package/dist/{json-diff-viewer-zBoPBSd3.cjs → json-diff-viewer-c3ft4c4A.cjs} +1 -1
- package/dist/{lang-panel-B_HcsPPo.js → lang-panel-D1FKTNui.js} +2 -2
- package/dist/{lang-panel-D2YUMeJZ.cjs → lang-panel-ExS97Zgk.cjs} +1 -1
- package/dist/{mark-as-template-C4wH4UKf.cjs → mark-as-template-CcnkROAU.cjs} +1 -1
- package/dist/{mark-as-template-CPEPYXg7.js → mark-as-template-v-I05xcZ.js} +1 -1
- package/dist/{no-language-page-content-CVyOpT9h.js → no-language-page-content-Bm5CcsUo.js} +1 -1
- package/dist/{no-language-page-content-ECt0SxFX.cjs → no-language-page-content-Ddz2hnYs.cjs} +1 -1
- package/dist/{page-creator-y6kl3nw5.js → page-creator-Crc5BzeB.js} +2 -2
- package/dist/{page-creator-BG2hc82u.cjs → page-creator-CsZpQ7Gy.cjs} +1 -1
- package/dist/{page-lock-request-fGZbOFTp.cjs → page-lock-request-Dx6OrOwM.cjs} +1 -1
- package/dist/{page-lock-request-DC62b588.js → page-lock-request-WKfG7Sd3.js} +1 -1
- package/dist/{page-locked-by-dialog-BIC-c0Jl.cjs → page-locked-by-dialog-BvdAXZPw.cjs} +1 -1
- package/dist/{page-locked-by-dialog-D-vXaoga.js → page-locked-by-dialog-jy3lYV3l.js} +1 -1
- package/dist/{page-manager-new-Cto2r7Va.js → page-manager-new-CNHlSwfe.js} +66 -66
- package/dist/page-manager-new-CUlpwqpH.cjs +1 -0
- package/dist/{page-manager-search-and-filter-sVnGlF46.js → page-manager-search-and-filter-CuAn82Db.js} +1 -1
- package/dist/{page-manager-search-and-filter-z2b4sgvb.cjs → page-manager-search-and-filter-eFsGtm5W.cjs} +1 -1
- package/dist/{page-revisions-content-BaTqBnko.js → page-revisions-content-PRgwV04S.js} +2 -2
- package/dist/{page-revisions-content-Tb3T6zvU.cjs → page-revisions-content-dSFvGFEO.cjs} +1 -1
- package/dist/{publish-pages-content-C9CgEWo0.js → publish-pages-content-C24iBibw.js} +2 -2
- package/dist/{publish-pages-content-BGkEZ3GK.cjs → publish-pages-content-akIgltlm.cjs} +1 -1
- package/dist/{save-to-lib-DNK4GPNw.cjs → save-to-lib-C3H1ZPb-.cjs} +1 -1
- package/dist/{save-to-lib-DGtyTG6H.js → save-to-lib-DSPvtFSd.js} +1 -1
- package/dist/{seo-panel-CrK7z4bR.cjs → seo-panel-Ce6aTIyt.cjs} +1 -1
- package/dist/{seo-panel-DESVAQM5.js → seo-panel-rZ8s88c0.js} +17 -17
- package/dist/server.cjs +1 -1
- package/dist/server.js +96 -96
- package/dist/shared-json-ld-DMYOwp6B.js +565 -0
- package/dist/shared-json-ld-hCiviuBf.cjs +1 -0
- package/dist/{slug-input-DMYhARDW.cjs → slug-input-BN8eQgxP.cjs} +1 -1
- package/dist/{slug-input-DfAsMPg8.js → slug-input-Dhzaobv6.js} +1 -1
- package/dist/{theme-panel-footer-Bj2yHtxO.cjs → theme-panel-footer-0GrdOHO_.cjs} +1 -1
- package/dist/{theme-panel-footer-RrxiDGoD.js → theme-panel-footer-BzEy5bsg.js} +1 -1
- package/dist/{unmark-as-template-C8hTjRVk.cjs → unmark-as-template-DXEs6foh.cjs} +1 -1
- package/dist/{unmark-as-template-BjetSrYF.js → unmark-as-template-Dsiyocm9.js} +1 -1
- package/dist/{unpublish-page-gtGfNOAq.cjs → unpublish-page-c1mqQEa_.cjs} +1 -1
- package/dist/{unpublish-page-BTPEVAkv.js → unpublish-page-yGyz2jiw.js} +1 -1
- package/dist/{web-preview-DNgPjdgZ.js → web-preview-BEyjKFDL.js} +1 -1
- package/dist/{web-preview-BcULgiw_.cjs → web-preview-TTKtpSUi.cjs} +1 -1
- package/package.json +2 -3
- package/dist/digital-asset-manager-B2m5T22s.js +0 -1001
- package/dist/digital-asset-manager-BGyKKd_6.cjs +0 -1
- package/dist/index-Cds1vIhw.cjs +0 -5
- package/dist/page-manager-new-CUfjlMed.cjs +0 -1
- package/dist/shared-json-ld-BMfQzOWc.js +0 -650
- package/dist/shared-json-ld-_ozYsSHn.cjs +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsxs as p, jsx as s, Fragment as D } from "react/jsx-runtime";
|
|
2
|
-
import { au as pe, f as oe, aj as be, T as
|
|
2
|
+
import { au as pe, f as oe, aj as be, T as H, aD as ye, L as ge, h as ke, b as Ne, i as we, ap as ve, aE as Se, aF as _ } from "./index-zaGKeGBW.js";
|
|
3
3
|
import { u as J } from "./use-page-expand-manager-D6T75I11.js";
|
|
4
|
-
import { compact as ie, filter as
|
|
4
|
+
import { compact as ie, filter as j, isEmpty as v, uniqBy as Ae, keyBy as ce, mapValues as Le, startCase as Te, toLower as C, includes as O, find as M, get as q, map as Ee } from "lodash-es";
|
|
5
5
|
import { useLanguages as re } from "@chaibuilder/sdk";
|
|
6
|
-
import { useAtom as
|
|
7
|
-
import { NotepadText as Ue, MoreHorizontal as $e, Lock as
|
|
8
|
-
import { useMemo as Q, lazy as U, useState as N, useCallback as ae, useEffect as
|
|
6
|
+
import { useAtom as Ce } from "jotai";
|
|
7
|
+
import { NotepadText as Ue, MoreHorizontal as $e, Lock as Fe, Edit as Me, Plus as je, ChevronRight as ze, StarsIcon as Be, Hash as Ie, File as de } from "lucide-react";
|
|
8
|
+
import { useMemo as Q, lazy as U, useState as N, useCallback as ae, useEffect as F, Suspense as E } from "react";
|
|
9
9
|
const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
10
|
-
|
|
11
|
-
const t =
|
|
12
|
-
return O(
|
|
10
|
+
j(e, (r) => {
|
|
11
|
+
const t = C(n);
|
|
12
|
+
return O(C((r == null ? void 0 : r.name) || ""), t) || O(C((r == null ? void 0 : r.slug) || ""), t);
|
|
13
13
|
})
|
|
14
14
|
), Ge = (e, n) => {
|
|
15
15
|
const r = /* @__PURE__ */ new Set(), t = ce(e, "id");
|
|
@@ -26,7 +26,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
26
26
|
children: t.children ? V(t.children, n, r) : []
|
|
27
27
|
};
|
|
28
28
|
const l = t.children && t.children.some(
|
|
29
|
-
(o) => O(
|
|
29
|
+
(o) => O(C(o.name || ""), C(n)) || O(C(o.slug || ""), C(n))
|
|
30
30
|
);
|
|
31
31
|
return {
|
|
32
32
|
...t,
|
|
@@ -51,27 +51,27 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
51
51
|
})), Oe = (e, n, r, t) => {
|
|
52
52
|
if (!e || !e.length) return [];
|
|
53
53
|
let l = e;
|
|
54
|
-
if (r !== "all" && (l = ie(
|
|
54
|
+
if (r !== "all" && (l = ie(j(e, { pageType: r }))), v(n))
|
|
55
55
|
l = le(l, n);
|
|
56
56
|
else {
|
|
57
57
|
const d = le(l, n), i = Ge(e, d);
|
|
58
58
|
l = Ae([...d, ...i], "id");
|
|
59
59
|
}
|
|
60
|
-
const o = ue(De(l)), b = V(o, n, t), f =
|
|
60
|
+
const o = ue(De(l)), b = V(o, n, t), f = j(b, (d) => t(d.pageType)).sort((d, i) => (d.name || "").localeCompare(i.name || "")), P = j(b, (d) => !t(d.pageType));
|
|
61
61
|
let m = [];
|
|
62
62
|
if (r === "all") {
|
|
63
|
-
const d = ce(
|
|
63
|
+
const d = ce(P, "pageType");
|
|
64
64
|
m = Object.values(
|
|
65
|
-
Le(d, (i,
|
|
65
|
+
Le(d, (i, x) => ({
|
|
66
66
|
...i,
|
|
67
|
-
id:
|
|
68
|
-
name: Te(
|
|
67
|
+
id: x,
|
|
68
|
+
name: Te(x),
|
|
69
69
|
isPartialGroup: !0,
|
|
70
|
-
children: b.filter((S) => S.pageType ===
|
|
70
|
+
children: b.filter((S) => S.pageType === x)
|
|
71
71
|
}))
|
|
72
72
|
);
|
|
73
73
|
} else
|
|
74
|
-
m =
|
|
74
|
+
m = P.sort((d, i) => (d.name || "").localeCompare(i.name || ""));
|
|
75
75
|
return [...f, ...m];
|
|
76
76
|
}, Re = ({ page: e }) => {
|
|
77
77
|
var t, l;
|
|
@@ -85,7 +85,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
85
85
|
disabled: !((t = e == null ? void 0 : e.children) != null && t.length),
|
|
86
86
|
className: `flex h-[calc(100%-2px)] w-5 items-center justify-center rounded text-gray-400 transition-colors hover:bg-gray-200 hover:px-1 hover:text-gray-500 ${(l = e == null ? void 0 : e.children) != null && l.length ? "hover:text-blue-400" : "opacity-0"}`,
|
|
87
87
|
children: /* @__PURE__ */ s(
|
|
88
|
-
|
|
88
|
+
ze,
|
|
89
89
|
{
|
|
90
90
|
size: 12,
|
|
91
91
|
className: `stroke-[4] transition-transform duration-200 ${n ? "rotate-90" : ""}`
|
|
@@ -99,7 +99,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
99
99
|
className: "flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",
|
|
100
100
|
dangerouslySetInnerHTML: { __html: n.icon }
|
|
101
101
|
}
|
|
102
|
-
) : n != null && n.hasSlug ? /* @__PURE__ */ s(de, { size: 12, className: "stroke-[1] text-slate-500" }) : /* @__PURE__ */ s(Ie, { size: 12, className: "stroke-[1] text-slate-500" }) }),
|
|
102
|
+
) : n != null && n.hasSlug ? /* @__PURE__ */ s(de, { size: 12, className: "stroke-[1] text-slate-500" }) : /* @__PURE__ */ s(Ie, { size: 12, className: "stroke-[1] text-slate-500" }) }), He = ({ isOnline: e }) => /* @__PURE__ */ s("div", { className: `h-2 w-2 rounded-full ${e ? "bg-green-300" : "bg-gray-300"}` }), _e = ({
|
|
103
103
|
page: e,
|
|
104
104
|
pageTypes: n,
|
|
105
105
|
currentPage: r,
|
|
@@ -108,12 +108,12 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
108
108
|
selectedLanguage: o,
|
|
109
109
|
showUntranslatedPages: b
|
|
110
110
|
}) => {
|
|
111
|
-
const [f] = pe(),
|
|
112
|
-
let u =
|
|
113
|
-
u =
|
|
114
|
-
const A = o ===
|
|
111
|
+
const [f] = pe(), P = oe(), m = r === e.id, d = !!e.isTemplate, i = Q(() => M(n, { key: e.pageType }), [n, e.pageType]), x = f == null ? void 0 : f[e.id], { data: S } = be(x), y = S ? S == null ? void 0 : S.name : null;
|
|
112
|
+
let u = q(l, e == null ? void 0 : e.id);
|
|
113
|
+
u = q(u, "lang") === o ? u : null;
|
|
114
|
+
const A = o === P || !!u, L = (u == null ? void 0 : u.name) || (e == null ? void 0 : e.name) || "No name";
|
|
115
115
|
let g = (u == null ? void 0 : u.slug) || (e == null ? void 0 : e.slug) || "";
|
|
116
|
-
const
|
|
116
|
+
const z = g + (e != null && e.dynamic ? `/${i == null ? void 0 : i.dynamicSlug}` : "") + (e != null && e.dynamicSlugCustom ? `${e.dynamicSlugCustom}` : "");
|
|
117
117
|
if (g.startsWith("/") && !b) {
|
|
118
118
|
const c = g.split("/").pop();
|
|
119
119
|
g = g.endsWith(c) && e.dynamic ? "" : `/${c}`;
|
|
@@ -130,10 +130,10 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
130
130
|
className: B,
|
|
131
131
|
children: [
|
|
132
132
|
/* @__PURE__ */ s(Re, { page: e }),
|
|
133
|
-
!e.isPartialGroup && /* @__PURE__ */ s(
|
|
134
|
-
/* @__PURE__ */ s(We, { page: e, pageType: i }),
|
|
135
|
-
/* @__PURE__ */ s(
|
|
136
|
-
(g || e.dynamic) && /* @__PURE__ */ s(
|
|
133
|
+
!e.isPartialGroup && /* @__PURE__ */ s(He, { isOnline: u ? u.online : e.online }),
|
|
134
|
+
!e.isPartialGroup && /* @__PURE__ */ s(We, { page: e, pageType: i }),
|
|
135
|
+
/* @__PURE__ */ s(H, { content: L, side: "top", showTooltip: L.length > 35, children: /* @__PURE__ */ s("span", { className: "max-w-[40%] truncate font-medium text-black", children: L }) }),
|
|
136
|
+
(g || e.dynamic) && /* @__PURE__ */ s(H, { content: z, side: "top", showTooltip: !0, children: /* @__PURE__ */ p("span", { className: "max-w-[40%] truncate font-mono text-xs text-muted-foreground", children: [
|
|
137
137
|
g,
|
|
138
138
|
e.dynamic && (i == null ? void 0 : i.dynamicSlug) && /* @__PURE__ */ p("span", { className: "text-xs text-gray-500", children: [
|
|
139
139
|
"/",
|
|
@@ -141,7 +141,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
141
141
|
e.dynamicSlugCustom
|
|
142
142
|
] })
|
|
143
143
|
] }) }),
|
|
144
|
-
d && /* @__PURE__ */ s(
|
|
144
|
+
d && /* @__PURE__ */ s(H, { content: "Template", side: "top", children: /* @__PURE__ */ s("span", { className: "text-blue-500", children: /* @__PURE__ */ s(Ue, { size: 16 }) }) }),
|
|
145
145
|
!e.isPartialGroup && A && !y ? /* @__PURE__ */ s("div", { className: "duration absolute right-0.5 top-[3px]", children: /* @__PURE__ */ s(
|
|
146
146
|
ye,
|
|
147
147
|
{
|
|
@@ -155,12 +155,12 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
155
155
|
setUnmarkAsTemplate: (c) => t("unmarkAsTemplate", c),
|
|
156
156
|
children: /* @__PURE__ */ s("div", { className: "m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white", children: /* @__PURE__ */ s($e, { className: "h-4 w-4", onClick: (c) => c.stopPropagation() }) })
|
|
157
157
|
}
|
|
158
|
-
) }) : y ? /* @__PURE__ */ s("span", { className: "duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500", children: /* @__PURE__ */ s(
|
|
158
|
+
) }) : y ? /* @__PURE__ */ s("span", { className: "duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500", children: /* @__PURE__ */ s(Fe, { className: "h-3.5 w-3.5 fill-red-200 text-red-500" }) }) : null
|
|
159
159
|
]
|
|
160
160
|
}
|
|
161
161
|
),
|
|
162
162
|
/* @__PURE__ */ s(D, { children: y && /* @__PURE__ */ p("button", { className: "absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100", children: [
|
|
163
|
-
/* @__PURE__ */ s(
|
|
163
|
+
/* @__PURE__ */ s(Me, { size: 12, className: "stroke-[3]" }),
|
|
164
164
|
" ",
|
|
165
165
|
/* @__PURE__ */ s("span", { className: "font-medium", children: y }),
|
|
166
166
|
" is editing this page"
|
|
@@ -173,11 +173,11 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
173
173
|
},
|
|
174
174
|
className: "absolute left-1/2 top-1 flex -translate-x-1/2 items-center gap-x-1 rounded bg-blue-500 px-2 py-0.5 text-xs text-white opacity-0 duration-200 hover:bg-blue-700 group-hover:opacity-100",
|
|
175
175
|
children: [
|
|
176
|
-
/* @__PURE__ */ s(
|
|
176
|
+
/* @__PURE__ */ s(je, { size: 12, className: "stroke-[3]" }),
|
|
177
177
|
" ",
|
|
178
178
|
/* @__PURE__ */ p("span", { className: "text-[10px]", children: [
|
|
179
179
|
"Add ",
|
|
180
|
-
|
|
180
|
+
q(ge, o),
|
|
181
181
|
" Page"
|
|
182
182
|
] })
|
|
183
183
|
]
|
|
@@ -194,10 +194,10 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
194
194
|
selectedLanguage: b,
|
|
195
195
|
showUntranslatedPages: f
|
|
196
196
|
}) => {
|
|
197
|
-
const { expandedPages:
|
|
197
|
+
const { expandedPages: P } = J();
|
|
198
198
|
return /* @__PURE__ */ s("div", { className: "space-y-0.5", style: { paddingLeft: `${n * 10}px` }, children: e.map((m) => /* @__PURE__ */ p(D, { children: [
|
|
199
199
|
/* @__PURE__ */ s(
|
|
200
|
-
|
|
200
|
+
_e,
|
|
201
201
|
{
|
|
202
202
|
page: m,
|
|
203
203
|
pageTypes: r,
|
|
@@ -208,7 +208,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
208
208
|
showUntranslatedPages: f
|
|
209
209
|
}
|
|
210
210
|
),
|
|
211
|
-
m.children && m.children.length > 0 && (
|
|
211
|
+
m.children && m.children.length > 0 && (P == null ? void 0 : P.includes(m.id)) && /* @__PURE__ */ s(
|
|
212
212
|
me,
|
|
213
213
|
{
|
|
214
214
|
pages: m.children,
|
|
@@ -222,38 +222,38 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
222
222
|
}
|
|
223
223
|
)
|
|
224
224
|
] }, m.id)) });
|
|
225
|
-
},
|
|
226
|
-
const { languages: n, setSelectedLang: r } = re(), { data: t } = ke(), { data: l, isFetching: o } = Ne(), [b, f] = we(), { updateForSelectedPage:
|
|
225
|
+
}, qe = U(() => import("./page-manager-search-and-filter-CuAn82Db.js")), Qe = U(() => import("./add-new-page-CD-9ppdS.js")), Ve = U(() => import("./delete-page-CatRlDfx.js")), Je = U(() => import("./duplicate-page-DEmh0df0.js")), Ke = U(() => import("./mark-as-template-v-I05xcZ.js")), Xe = U(() => import("./unmark-as-template-Dsiyocm9.js")), Ye = U(() => import("./unpublish-page-yGyz2jiw.js")), ot = ({ close: e }) => {
|
|
226
|
+
const { languages: n, setSelectedLang: r } = re(), { data: t } = ke(), { data: l, isFetching: o } = Ne(), [b, f] = we(), { updateForSelectedPage: P, expandPagesOnSearch: m } = J(null), d = oe(), i = b.get("page"), [x, S] = N(""), [y, u] = N(null), [A, L] = N(null), [g, z] = N(null), [B, c] = N(null), [T, R] = N(""), [K, X] = N(null), [Y, Z] = N(null), [k, he] = N(d), [fe, Pe] = N(!1), [, ee] = Ce(ve), I = fe && k !== d, { data: $, isFetching: xe } = Se(k), te = ae(
|
|
227
227
|
(h) => {
|
|
228
228
|
var a;
|
|
229
|
-
return (a =
|
|
229
|
+
return (a = M(t, { key: h })) == null ? void 0 : a.hasSlug;
|
|
230
230
|
},
|
|
231
231
|
[t]
|
|
232
|
-
), w = Q(() => l ? I ?
|
|
233
|
-
|
|
232
|
+
), w = Q(() => l ? I ? j(l, (h) => !($ != null && $[h.id])) : Oe(l, x, T, te) : [], [l, te, x, T, $, I]);
|
|
233
|
+
F(() => {
|
|
234
234
|
r(d);
|
|
235
|
-
}, [d, r]),
|
|
235
|
+
}, [d, r]), F(() => {
|
|
236
236
|
if (!v(T)) return;
|
|
237
237
|
const h = sessionStorage.getItem("pageTypeFilter") || "all";
|
|
238
|
-
!v(t) && h && (
|
|
239
|
-
}, [t, T]),
|
|
240
|
-
if (i && !o && !
|
|
241
|
-
const a =
|
|
238
|
+
!v(t) && h && (M(t, { key: h }) ? R(h) : R("all"));
|
|
239
|
+
}, [t, T]), F(() => {
|
|
240
|
+
if (i && !o && !M(l, { id: i })) {
|
|
241
|
+
const a = M(l, { slug: "/" });
|
|
242
242
|
if (a) {
|
|
243
243
|
const G = new URLSearchParams({ page: a.id });
|
|
244
|
-
|
|
244
|
+
_(G, f);
|
|
245
245
|
} else
|
|
246
|
-
|
|
246
|
+
_(new URLSearchParams({}), f, !0);
|
|
247
247
|
}
|
|
248
|
-
}, [l, i, o, f]),
|
|
249
|
-
i && !o && !v(w) &&
|
|
250
|
-
}, [i, o, w,
|
|
251
|
-
!v(
|
|
252
|
-
}, [
|
|
248
|
+
}, [l, i, o, f]), F(() => {
|
|
249
|
+
i && !o && !v(w) && P(w, i);
|
|
250
|
+
}, [i, o, w, P]), F(() => {
|
|
251
|
+
!v(x) && !v(w) && m(w);
|
|
252
|
+
}, [x, w, m]);
|
|
253
253
|
const { setSelectedLang: W } = re(), se = ae(
|
|
254
254
|
(h) => {
|
|
255
255
|
const a = new URLSearchParams({ page: h });
|
|
256
|
-
k !== d ? (a.set("lang", k), W(k)) : W(""),
|
|
256
|
+
k !== d ? (a.set("lang", k), W(k)) : W(""), _(a, f), e();
|
|
257
257
|
},
|
|
258
258
|
[e, f, W, k, d]
|
|
259
259
|
), ne = (h, a) => {
|
|
@@ -277,7 +277,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
277
277
|
u(a);
|
|
278
278
|
break;
|
|
279
279
|
case "unpublish":
|
|
280
|
-
|
|
280
|
+
z(a);
|
|
281
281
|
break;
|
|
282
282
|
case "markAsTemplate":
|
|
283
283
|
c(a);
|
|
@@ -299,11 +299,11 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
299
299
|
};
|
|
300
300
|
return /* @__PURE__ */ p(D, { children: [
|
|
301
301
|
/* @__PURE__ */ p("div", { className: "flex h-full flex-col justify-between", children: [
|
|
302
|
-
/* @__PURE__ */ s(
|
|
303
|
-
|
|
302
|
+
/* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(
|
|
303
|
+
qe,
|
|
304
304
|
{
|
|
305
305
|
pages: w,
|
|
306
|
-
search:
|
|
306
|
+
search: x,
|
|
307
307
|
setSearch: S,
|
|
308
308
|
languages: [d, ...n],
|
|
309
309
|
selectedLanguage: k,
|
|
@@ -312,10 +312,10 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
312
312
|
setSelectedPageType: R,
|
|
313
313
|
onAddPage: (h) => ne("add", h),
|
|
314
314
|
showUntranslatedPages: I,
|
|
315
|
-
setShowUntranslatedPages:
|
|
315
|
+
setShowUntranslatedPages: Pe
|
|
316
316
|
}
|
|
317
317
|
) }),
|
|
318
|
-
/* @__PURE__ */ s("div", { className: "flex-1 overflow-y-auto px-4 pb-6 pt-2", children: o ||
|
|
318
|
+
/* @__PURE__ */ s("div", { className: "flex-1 overflow-y-auto px-4 pb-6 pt-2", children: o || xe ? /* @__PURE__ */ s("div", { className: "space-y-2", children: Ee([...Array(15).keys()], (h) => /* @__PURE__ */ s("div", { className: "h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200" }, h)) }) : v(w) ? /* @__PURE__ */ p("div", { className: "flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500", children: [
|
|
319
319
|
/* @__PURE__ */ s(de, { className: "h-6 w-6 stroke-[1]" }),
|
|
320
320
|
"Empty List!",
|
|
321
321
|
/* @__PURE__ */ s("span", { className: "font-light", children: "Add new page to start" })
|
|
@@ -333,7 +333,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
333
333
|
}
|
|
334
334
|
) })
|
|
335
335
|
] }),
|
|
336
|
-
A && /* @__PURE__ */ s(
|
|
336
|
+
A && /* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(
|
|
337
337
|
Qe,
|
|
338
338
|
{
|
|
339
339
|
closePanel: e,
|
|
@@ -342,11 +342,11 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
342
342
|
setAddEditPage: L
|
|
343
343
|
}
|
|
344
344
|
) }),
|
|
345
|
-
y && /* @__PURE__ */ s(
|
|
346
|
-
g && /* @__PURE__ */ s(
|
|
347
|
-
B && /* @__PURE__ */ s(
|
|
348
|
-
Y && /* @__PURE__ */ s(
|
|
349
|
-
K && /* @__PURE__ */ s(
|
|
345
|
+
y && /* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(Ve, { page: y, onClose: () => u(null) }) }),
|
|
346
|
+
g && /* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(Ye, { page: g, onClose: () => z(null) }) }),
|
|
347
|
+
B && /* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(Ke, { page: B, onClose: () => c(null) }) }),
|
|
348
|
+
Y && /* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(Xe, { page: Y, onClose: () => Z(null) }) }),
|
|
349
|
+
K && /* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(Je, { page: K, onClose: () => X(null), closePanel: e }) })
|
|
350
350
|
] });
|
|
351
351
|
};
|
|
352
352
|
export {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("./index-Blg1T7nL.cjs"),B=require("./use-page-expand-manager-2KjeYfVS.cjs"),n=require("lodash-es"),Q=require("@chaibuilder/sdk"),se=require("jotai"),v=require("lucide-react"),l=require("react"),V=(e,r)=>!e||!Array.isArray(e)?[]:n.isEmpty(r)?e:n.compact(n.filter(e,a=>{const t=n.toLower(r);return n.includes(n.toLower((a==null?void 0:a.name)||""),t)||n.includes(n.toLower((a==null?void 0:a.slug)||""),t)})),te=(e,r)=>{const a=new Set,t=n.keyBy(e,"id");return r.forEach(o=>{let c=o;for(;c.parent&&t[c.parent];)a.add(c.parent),c=t[c.parent]}),Array.from(a).map(o=>t[o])},$=(e,r,a)=>n.isEmpty(r)?e:e.map(t=>{if(!a(t.pageType))return{...t,shouldExpandOnSearch:!0,children:t.children?$(t.children,r,a):[]};const o=t.children&&t.children.some(c=>n.includes(n.toLower(c.name||""),n.toLower(r))||n.includes(n.toLower(c.slug||""),n.toLower(r)));return{...t,shouldExpandOnSearch:o,children:t.children?$(t.children,r,a):[]}}),ne=e=>{if(!e||!e.length)return[];const r={};e.forEach(t=>{r[t.id]={...t,children:[]}});const a=[];return Object.values(r).forEach(t=>{t.parent&&r[t.parent]?r[t.parent].children.push(t):a.push(t)}),a},J=e=>!e||!e.length?[]:[...e].sort((a,t)=>(a.name||"").localeCompare(t.name||"")).map(a=>({...a,children:a.children?J(a.children):[]})),re=(e,r,a,t)=>{if(!e||!e.length)return[];let o=e;if(a!=="all"&&(o=n.compact(n.filter(e,{pageType:a}))),n.isEmpty(r))o=V(o,r);else{const m=V(o,r),d=te(e,m);o=n.uniqBy([...m,...d],"id")}const c=J(ne(o)),b=$(c,r,t),y=n.filter(b,m=>t(m.pageType)).sort((m,d)=>(m.name||"").localeCompare(d.name||"")),p=n.filter(b,m=>!t(m.pageType));let f=[];if(a==="all"){const m=n.keyBy(p,"pageType");f=Object.values(n.mapValues(m,(d,j)=>({...d,id:j,name:n.startCase(j),isPartialGroup:!0,children:b.filter(N=>N.pageType===j)})))}else f=p.sort((m,d)=>(m.name||"").localeCompare(d.name||""));return[...y,...f]},ae=({page:e})=>{var t,o;const{isExpanded:r,toggleExpanded:a}=B.usePageExpandManager(e==null?void 0:e.id);return s.jsx("button",{onClick:c=>{c.stopPropagation(),a()},disabled:!((t=e==null?void 0:e.children)!=null&&t.length),className:`flex h-[calc(100%-2px)] w-5 items-center justify-center rounded text-gray-400 transition-colors hover:bg-gray-200 hover:px-1 hover:text-gray-500 ${(o=e==null?void 0:e.children)!=null&&o.length?"hover:text-blue-400":"opacity-0"}`,children:s.jsx(v.ChevronRight,{size:12,className:`stroke-[4] transition-transform duration-200 ${r?"rotate-90":""}`})})},le=({page:e,pageType:r})=>s.jsx("div",{className:"flex h-full items-center justify-center gap-x-1",children:e.dynamic?s.jsx(v.StarsIcon,{size:12,className:"text-yellow-400"}):r!=null&&r.icon?s.jsx("div",{className:"flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",dangerouslySetInnerHTML:{__html:r.icon}}):r!=null&&r.hasSlug?s.jsx(v.File,{size:12,className:"stroke-[1] text-slate-500"}):s.jsx(v.Hash,{size:12,className:"stroke-[1] text-slate-500"})}),ie=({isOnline:e})=>s.jsx("div",{className:`h-2 w-2 rounded-full ${e?"bg-green-300":"bg-gray-300"}`}),oe=({page:e,pageTypes:r,currentPage:a,onClickAction:t,languagePages:o,selectedLanguage:c,showUntranslatedPages:b})=>{const[y]=x.usePageUserMapping(),p=x.useFallbackLang(),f=a===e.id,m=!!e.isTemplate,d=l.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]),j=y==null?void 0:y[e.id],{data:N}=x.useChaiUserInfo(j),g=N?N==null?void 0:N.name:null;let h=n.get(o,e==null?void 0:e.id);h=n.get(h,"lang")===c?h:null;const E=c===p||!!h,L=(h==null?void 0:h.name)||(e==null?void 0:e.name)||"No name";let S=(h==null?void 0:h.slug)||(e==null?void 0:e.slug)||"";const C=S+(e!=null&&e.dynamic?`/${d==null?void 0:d.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(S.startsWith("/")&&!b){const u=S.split("/").pop();S=S.endsWith(u)&&e.dynamic?"":`/${u}`}const q=l.useMemo(()=>{const u="flex h-7 min-w-0 flex-1 cursor-pointer select-none items-center gap-x-1.5 rounded px-px text-xs duration-300 border-[1px]",T=`${f?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${u} ${T} ${g?"opacity-60":""}`:`${u} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,f,g]);return s.jsxs("div",{className:"group relative",children:[s.jsxs("div",{onClick:()=>!e.isPartialGroup&&E&&t("select",e==null?void 0:e.id),className:q,children:[s.jsx(ae,{page:e}),!e.isPartialGroup&&s.jsx(ie,{isOnline:h?h.online:e.online}),!e.isPartialGroup&&s.jsx(le,{page:e,pageType:d}),s.jsx(x.Tooltip,{content:L,side:"top",showTooltip:L.length>35,children:s.jsx("span",{className:"max-w-[40%] truncate font-medium text-black",children:L})}),(S||e.dynamic)&&s.jsx(x.Tooltip,{content:C,side:"top",showTooltip:!0,children:s.jsxs("span",{className:"max-w-[40%] truncate font-mono text-xs text-muted-foreground",children:[S,e.dynamic&&(d==null?void 0:d.dynamicSlug)&&s.jsxs("span",{className:"text-xs text-gray-500",children:["/",d==null?void 0:d.dynamicSlug,e.dynamicSlugCustom]})]})}),m&&s.jsx(x.Tooltip,{content:"Template",side:"top",children:s.jsx("span",{className:"text-blue-500",children:s.jsx(v.NotepadText,{size:16})})}),!e.isPartialGroup&&E&&!g?s.jsx("div",{className:"duration absolute right-0.5 top-[3px]",children:s.jsx(x.PageActionsDropdown,{isLanguagePage:!!h,page:h||e,setDuplicatePage:u=>t("duplicate",u),setAddEditPage:u=>t("edit",h||u),setUnpublishPage:u=>t("unpublish",u),setDeletePage:u=>t("delete",h||u),setMarkAsTemplate:u=>t("markAsTemplate",u),setUnmarkAsTemplate:u=>t("unmarkAsTemplate",u),children:s.jsx("div",{className:"m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white",children:s.jsx(v.MoreHorizontal,{className:"h-4 w-4",onClick:u=>u.stopPropagation()})})})}):g?s.jsx("span",{className:"duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500",children:s.jsx(v.Lock,{className:"h-3.5 w-3.5 fill-red-200 text-red-500"})}):null]}),s.jsx(s.Fragment,{children:g&&s.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[s.jsx(v.Edit,{size:12,className:"stroke-[3]"})," ",s.jsx("span",{className:"font-medium",children:g})," is editing this page"]})}),s.jsx(s.Fragment,{children:!E&&!e.isPartialGroup&&!g&&s.jsxs("button",{onClick:u=>{u.stopPropagation(),t("addLanguagePage",{language:c,page:e})},className:"absolute left-1/2 top-1 flex -translate-x-1/2 items-center gap-x-1 rounded bg-blue-500 px-2 py-0.5 text-xs text-white opacity-0 duration-200 hover:bg-blue-700 group-hover:opacity-100",children:[s.jsx(v.Plus,{size:12,className:"stroke-[3]"})," ",s.jsxs("span",{className:"text-[10px]",children:["Add ",n.get(x.LANGUAGES,c)," Page"]})]})})]})},K=({pages:e,tier:r,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y})=>{const{expandedPages:p}=B.usePageExpandManager();return s.jsx("div",{className:"space-y-0.5",style:{paddingLeft:`${r*10}px`},children:e.map(f=>s.jsxs(s.Fragment,{children:[s.jsx(oe,{page:f,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y}),f.children&&f.children.length>0&&(p==null?void 0:p.includes(f.id))&&s.jsx(K,{pages:f.children,tier:r+1,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y})]},f.id))})},ce=l.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-eFsGtm5W.cjs"))),de=l.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-BuK6We-q.cjs"))),ue=l.lazy(()=>Promise.resolve().then(()=>require("./delete-page-B-TP6nJ7.cjs"))),me=l.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-D4Oiy71Q.cjs"))),he=l.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-CcnkROAU.cjs"))),xe=l.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-DXEs6foh.cjs"))),fe=l.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-c1mqQEa_.cjs"))),Pe=({close:e})=>{const{languages:r,setSelectedLang:a}=Q.useLanguages(),{data:t}=x.usePageTypes(),{data:o,isFetching:c}=x.useWebsitePages(),[b,y]=x.useSearchParams(),{updateForSelectedPage:p,expandPagesOnSearch:f}=B.usePageExpandManager(null),m=x.useFallbackLang(),d=b.get("page"),[j,N]=l.useState(""),[g,h]=l.useState(null),[E,L]=l.useState(null),[S,C]=l.useState(null),[q,u]=l.useState(null),[T,F]=l.useState(""),[I,G]=l.useState(null),[O,R]=l.useState(null),[k,X]=l.useState(m),[Y,Z]=l.useState(!1),[,D]=se.useAtom(x.addNewLangAtom),M=Y&&k!==m,{data:A,isFetching:ee}=x.useWebsiteLanguagePages(k),W=l.useCallback(P=>{var i;return(i=n.find(t,{key:P}))==null?void 0:i.hasSlug},[t]),w=l.useMemo(()=>o?M?n.filter(o,P=>!(A!=null&&A[P.id])):re(o,j,T,W):[],[o,W,j,T,A,M]);l.useEffect(()=>{a(m)},[m,a]),l.useEffect(()=>{if(!n.isEmpty(T))return;const P=sessionStorage.getItem("pageTypeFilter")||"all";!n.isEmpty(t)&&P&&(n.find(t,{key:P})?F(P):F("all"))},[t,T]),l.useEffect(()=>{if(d&&!c&&!n.find(o,{id:d})){const i=n.find(o,{slug:"/"});if(i){const z=new URLSearchParams({page:i.id});x.navigateToPage(z,y)}else x.navigateToPage(new URLSearchParams({}),y,!0)}},[o,d,c,y]),l.useEffect(()=>{d&&!c&&!n.isEmpty(w)&&p(w,d)},[d,c,w,p]),l.useEffect(()=>{!n.isEmpty(j)&&!n.isEmpty(w)&&f(w)},[j,w,f]);const{setSelectedLang:U}=Q.useLanguages(),H=l.useCallback(P=>{const i=new URLSearchParams({page:P});k!==m?(i.set("lang",k),U(k)):U(""),x.navigateToPage(i,y),e()},[e,y,U,k,m]),_=(P,i)=>{var z;if(i)switch(P){case"add":L(i);break;case"select":H(i);break;case"edit":k!==m?D({edit:!0,id:i==null?void 0:i.id,primaryPage:i==null?void 0:i.primaryPage}):L(i);break;case"delete":h(i);break;case"unpublish":C(i);break;case"markAsTemplate":u(i);break;case"unmarkAsTemplate":R(i);break;case"duplicate":G(i);break;case"addLanguagePage":D({edit:!1,primaryPage:((z=i==null?void 0:i.page)==null?void 0:z.id)||"",preselectedLang:(i==null?void 0:i.language)||k});break}};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex h-full flex-col justify-between",children:[s.jsx(l.Suspense,{children:s.jsx(ce,{pages:w,search:j,setSearch:N,languages:[m,...r],selectedLanguage:k,setSelectedLanguage:X,selectedPageType:T,setSelectedPageType:F,onAddPage:P=>_("add",P),showUntranslatedPages:M,setShowUntranslatedPages:Z})}),s.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-6 pt-2",children:c||ee?s.jsx("div",{className:"space-y-2",children:n.map([...Array(15).keys()],P=>s.jsx("div",{className:"h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200"},P))}):n.isEmpty(w)?s.jsxs("div",{className:"flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500",children:[s.jsx(v.File,{className:"h-6 w-6 stroke-[1]"}),"Empty List!",s.jsx("span",{className:"font-light",children:"Add new page to start"})]}):s.jsx(K,{tier:0,pages:w,pageTypes:t,currentPage:d||"",onClickAction:_,languagePages:A,selectedLanguage:k,showUntranslatedPages:M})})]}),E&&s.jsx(l.Suspense,{children:s.jsx(de,{closePanel:e,editPage:H,addEditPage:E,setAddEditPage:L})}),g&&s.jsx(l.Suspense,{children:s.jsx(ue,{page:g,onClose:()=>h(null)})}),S&&s.jsx(l.Suspense,{children:s.jsx(fe,{page:S,onClose:()=>C(null)})}),q&&s.jsx(l.Suspense,{children:s.jsx(he,{page:q,onClose:()=>u(null)})}),O&&s.jsx(l.Suspense,{children:s.jsx(xe,{page:O,onClose:()=>R(null)})}),I&&s.jsx(l.Suspense,{children:s.jsx(me,{page:I,onClose:()=>G(null),closePanel:e})})]})};exports.default=Pe;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as r, Fragment as w } from "react/jsx-runtime";
|
|
2
|
-
import { f as P, L, h as F, A as I } from "./index-
|
|
2
|
+
import { f as P, L, h as F, A as I } from "./index-zaGKeGBW.js";
|
|
3
3
|
import { u as z } from "./use-page-expand-manager-D6T75I11.js";
|
|
4
4
|
import { Button as m, Tooltip as f, TooltipTrigger as v, TooltipContent as g, Select as j, SelectTrigger as $, SelectContent as G, Input as S, SelectItem as b } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { useQueryClient as T } from "@tanstack/react-query";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),m=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),m=require("./index-Blg1T7nL.cjs"),y=require("./use-page-expand-manager-2KjeYfVS.cjs"),s=require("@chaibuilder/sdk/ui"),b=require("@tanstack/react-query"),r=require("lodash-es"),c=require("lucide-react"),N=require("react"),w=({selectedPageType:n,setSelectedPageType:a})=>{const[o,l]=N.useState(""),{data:i}=m.usePageTypes(),d=t=>{if(!o)return!0;const x=o.toLowerCase(),h=p=>String(r.get(t,p,"")).toLowerCase().includes(x);return h("name")||h("key")},u=i.find(t=>t.key===n);return e.jsxs(s.Select,{onValueChange:a,value:n,children:[e.jsx(s.SelectTrigger,{className:`${n==="all"?"bg-gray-100/30 hover:bg-gray-100":"gap-x-1 border bg-gray-100/30 hover:bg-gray-100"} h-9 w-max min-w-[150px] overflow-hidden whitespace-nowrap rounded p-0 px-2 py-1 text-xs text-gray-600 shadow-none ring-0 focus:ring-0 [&>svg]:hidden`,children:e.jsxs("div",{className:"flex w-full items-center justify-between gap-x-1.5",children:[e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate whitespace-nowrap font-medium leading-tight",children:(u==null?void 0:u.name)||"All"}),e.jsx(c.ListFilter,{className:`${n!=="all"?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground hover:bg-blue-300`})]})}),e.jsxs(s.SelectContent,{children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(c.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(s.Input,{placeholder:"Search page types...",className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:o,onChange:t=>l(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(s.SelectItem,{value:"all",children:"All"}),!r.isEmpty(r.filter(i,t=>t.hasSlug&&d(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:"Pages"}),r.map([...r.filter(i,t=>t.hasSlug&&d(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),!r.isEmpty(r.filter(i,t=>!t.hasSlug&&d(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:"Partials"}),r.map([...r.filter(i,t=>!t.hasSlug&&d(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),r.isEmpty(r.filter(i,d))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:"No matching page types found"})]})]})},C=({search:n,setSearch:a})=>e.jsxs("div",{className:"relative flex h-9 flex-1 items-center gap-2 rounded-md border px-2.5",children:[e.jsx("label",{htmlFor:"page-search-input",className:"sr-only",children:"Search Pages"}),e.jsx(c.Search,{className:`${n?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground`,"aria-hidden":"true"}),e.jsx(s.Input,{id:"page-search-input",placeholder:"Search pages",value:n,onChange:o=>a(o.target.value),className:"border-none px-1.5 shadow-none outline-none ring-0 transition-none focus:outline-none focus:ring-0 focus-visible:ring-0",autoComplete:"off"})]}),S=({pages:n})=>{const{expandAll:a,collapseAll:o,expandedPages:l}=y.usePageExpandManager(null);return e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"icon",onClick:()=>a(n),className:"rounded p-1 text-gray-500",children:e.jsx(c.ChevronsUpDown,{})})}),e.jsx(s.TooltipContent,{children:"Expand All"})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{disabled:l.length===0,variant:"outline",size:"icon",onClick:()=>o(),className:"rounded p-1 text-gray-500",children:e.jsx(c.ChevronsDownUp,{})})}),e.jsx(s.TooltipContent,{children:"Collapse All"})]})]})},f=({languages:n,selectedLanguage:a,setSelectedLanguage:o})=>{const l=m.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:n.map(i=>e.jsxs(s.Button,{variant:a===i?"default":"outline",size:"sm",className:`h-6 flex-shrink-0 whitespace-nowrap rounded px-3 text-xs font-normal ${a===i?"bg-black text-white hover:bg-black":"text-gray-500"}`,onClick:()=>o(i.toLowerCase()),children:[i===l&&e.jsx(c.Star,{size:4,className:`p-0.5 ${a===l?"fill-white":"fill-black"}`}),m.LANGUAGES[i]||""]},i))})},j=()=>{const n=b.useQueryClient();return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",onClick:()=>n.invalidateQueries({queryKey:[m.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(c.RefreshCw,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:"Refresh pages list"})]})},k=({pages:n,search:a,setSearch:o,languages:l,onAddPage:i,selectedLanguage:d,setSelectedLanguage:u,selectedPageType:t,setSelectedPageType:x,showUntranslatedPages:h,setShowUntranslatedPages:p})=>{const g=l.length>1;return e.jsxs("div",{className:"space-y-3 border-b border-b-gray-200 px-4 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(w,{selectedPageType:t,setSelectedPageType:x}),e.jsx(C,{search:a,setSearch:o}),e.jsx(S,{pages:n}),e.jsxs(s.Button,{variant:"default",onClick:i,className:"rounded px-3 font-normal",children:[e.jsx(c.Plus,{strokeWidth:2,className:"stroke-white stroke-[3]"}),e.jsx("span",{className:"font-normal text-white",children:"Add Page"})]}),!g&&e.jsx(j,{})]}),g?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(f,{languages:l,selectedLanguage:d,setSelectedLanguage:v=>{u(v),p(h&&(l==null?void 0:l[0])!==d)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(l==null?void 0:l[0])!==d&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",onClick:()=>p(!h),className:"h-6 rounded px-3 py-1 text-xs font-normal",children:h?e.jsx(c.FilterXIcon,{}):e.jsx(c.Filter,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:"Toggle Untranslated Pages"})]}),e.jsx(j,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=f;exports.default=k;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as n, Fragment as p, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { al as C, am as A, A as b, aq as j, at as le, aj as I, ar as R, as as w } from "./index-
|
|
2
|
+
import { al as C, am as A, A as b, aq as j, at as le, aj as I, ar as R, as as w } from "./index-zaGKeGBW.js";
|
|
3
3
|
import { useQuery as re, useQueryClient as O, useMutation as q } from "@tanstack/react-query";
|
|
4
4
|
import { useLanguages as ie, useSavePage as de } from "@chaibuilder/sdk";
|
|
5
5
|
import { SheetHeader as ce, SheetTitle as oe, ScrollArea as ue, Skeleton as y, Button as g, DropdownMenu as me, DropdownMenuTrigger as he, DropdownMenuContent as fe, DropdownMenuItem as U, DropdownMenuSeparator as pe, Dialog as G, DialogContent as L, DialogHeader as P, DialogTitle as $, DialogDescription as z, DialogFooter as H } from "@chaibuilder/sdk/ui";
|
|
@@ -46,7 +46,7 @@ const Ae = () => {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
}, Oe = Se(() => import("./json-diff-viewer-
|
|
49
|
+
}, Oe = Se(() => import("./json-diff-viewer-BF0qFBif.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ n("div", { className: "flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600", children: [
|
|
50
50
|
/* @__PURE__ */ n("span", { className: "relative flex h-2 w-2", children: [
|
|
51
51
|
/* @__PURE__ */ e("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75" }),
|
|
52
52
|
/* @__PURE__ */ e("span", { className: "relative inline-flex h-2 w-2 rounded-full bg-amber-500" })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-Cds1vIhw.cjs"),N=require("@tanstack/react-query"),O=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),y=require("date-fns"),L=require("lodash-es"),p=require("lucide-react"),b=require("react");function Q(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const l=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,l.get?l:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const v=Q(b);function z(s){const n=d.useApiUrl(),t=d.useFetch();return N.useQuery({queryKey:[d.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:d.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const B=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async l=>await n(s,{action:d.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async({revisionId:l,discardCurrent:r})=>await n(s,{action:d.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=b.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-zBoPBSd3.cjs"))),g=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(p.Rocket,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Published"})]}):s==="unsaved"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[e.jsx(p.Save,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Unsaved changes"})]}):e.jsx("span",{className:"rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600",children:s});function J({compare:s,setCompare:n}){const{data:t}=d.useCurrentPage(),{saveState:l}=O.useSavePage(),[r]=d.usePageEditInfo();if(!t)return null;const c=!!s.find(u=>{var i;return(i=u==null?void 0:u.uid)==null?void 0:i.startsWith("draft:")}),x=s.length>=2&&!c,m=l==="UNSAVED";return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium leading-none",children:[e.jsx(g,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!L.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",y.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(g,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:c,disabled:x,onChange:()=>{n(c?s.filter(u=>u.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(a.Skeleton,{className:"h-4 w-3/4"}),e.jsx(a.Skeleton,{className:"h-3 w-1/2"}),e.jsx(a.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(a.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:c,setCompare:x,pageId:m}){const{data:u}=d.useChaiUserInfo(s.currentEditor),i=(u==null?void 0:u.name)||"Unknown",f=!!c.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),S=c.length>=2&&!f;return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs leading-none",children:[e.jsx(g,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:i})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(g,{tag:"published"}):e.jsx(g,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:y.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(d.PermissionChecker,{permissions:[d.PAGES_PERMISSIONS.RESTORE_REVISION,d.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:S,onChange:()=>{x(f?c.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...c,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${r}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function W({compare:s,setCompare:n,pageId:t}){const[l,r]=b.useState(!1),[c,x]=s;if(s.length===0)return null;const m=({tab:u})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(g,{tag:u.label}),e.jsx("button",{className:"z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",style:{lineHeight:1},onClick:()=>n(s.filter(i=>i.uid!==u.uid)),"aria-label":"Remove selection 1",children:e.jsx(p.X,{className:"h-3 w-3"})})]});return e.jsxs("div",{className:"mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-xs",children:[e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"Compare"}),c&&e.jsx(m,{tab:c}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),x?e.jsx(m,{tab:x}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>r(!0),disabled:s.length<2,children:[e.jsx(p.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),l&&(s==null?void 0:s.length)>1&&t&&e.jsx(b.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open:l,onOpenChange:r,compare:s})})]})}function A({checked:s,disabled:n,onChange:t,label:l="Compare"}){return e.jsx("div",{className:"absolute bottom-2 right-2",children:e.jsxs("label",{className:`flex cursor-pointer items-center gap-x-1 text-[11px] ${n?"opacity-50":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",checked:s,disabled:n,onChange:t}),e.jsx("span",{className:"select-none leading-tight",children:l})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(a.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:l,isRestoring:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Restore Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>l(!1),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(a.Button,{variant:"default",className:"sm:flex-1",onClick:()=>l(!0),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:l,isDeleting:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",className:"sm:flex-1",onClick:l,disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var E,R;const[n,t]=v.useState([]),[l,r]=v.useState(null),[c,x]=v.useState(!1),[m,u]=v.useState(!1),{data:i}=d.useCurrentPage(),{data:f,isFetching:S,error:h,refetch:j}=z(i==null?void 0:i.id),{mutate:k,isPending:M}=B(),{mutate:T,isPending:F}=H(),_=N.useQueryClient(),{selectedLang:P,fallbackLang:q}=O.useLanguages(),U=P||q;b.useEffect(()=>t([]),[i==null?void 0:i.id]);const G=o=>{l&&T({revisionId:l.uid,discardCurrent:o},{onSuccess:()=>{x(!1),r(null),_.invalidateQueries({queryKey:[d.ACTIONS.GET_DRAFT_PAGE]})}})},D=o=>{r(o),x(!0)},C=o=>{r(o),u(!0)},V=()=>{l&&k(l.uid,{onSuccess:()=>{u(!1),r(null)}})};return b.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(a.SheetHeader,{children:[e.jsx(a.SheetTitle,{children:"Revision History"}),(i==null?void 0:i.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",y.format(new Date(i.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),S?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:i==null?void 0:i.id}),e.jsx(J,{compare:n,setCompare:t}),(E=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:E.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:!0,onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w,compare:n,setCompare:t},o.uid)),e.jsx(a.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(R=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:R.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:o.uid==="current",onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:c,onOpenChange:x,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:u,revision:l,onDelete:V,isDeleting:M})]})}exports.default=ee;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-Blg1T7nL.cjs"),N=require("@tanstack/react-query"),O=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),y=require("date-fns"),L=require("lodash-es"),p=require("lucide-react"),b=require("react");function Q(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const l=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,l.get?l:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const v=Q(b);function z(s){const n=d.useApiUrl(),t=d.useFetch();return N.useQuery({queryKey:[d.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:d.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const B=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async l=>await n(s,{action:d.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async({revisionId:l,discardCurrent:r})=>await n(s,{action:d.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=b.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-c3ft4c4A.cjs"))),g=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(p.Rocket,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Published"})]}):s==="unsaved"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[e.jsx(p.Save,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Unsaved changes"})]}):e.jsx("span",{className:"rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600",children:s});function J({compare:s,setCompare:n}){const{data:t}=d.useCurrentPage(),{saveState:l}=O.useSavePage(),[r]=d.usePageEditInfo();if(!t)return null;const c=!!s.find(u=>{var i;return(i=u==null?void 0:u.uid)==null?void 0:i.startsWith("draft:")}),x=s.length>=2&&!c,m=l==="UNSAVED";return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium leading-none",children:[e.jsx(g,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!L.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",y.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(g,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:c,disabled:x,onChange:()=>{n(c?s.filter(u=>u.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(a.Skeleton,{className:"h-4 w-3/4"}),e.jsx(a.Skeleton,{className:"h-3 w-1/2"}),e.jsx(a.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(a.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:c,setCompare:x,pageId:m}){const{data:u}=d.useChaiUserInfo(s.currentEditor),i=(u==null?void 0:u.name)||"Unknown",f=!!c.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),S=c.length>=2&&!f;return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs leading-none",children:[e.jsx(g,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:i})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(g,{tag:"published"}):e.jsx(g,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:y.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(d.PermissionChecker,{permissions:[d.PAGES_PERMISSIONS.RESTORE_REVISION,d.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:S,onChange:()=>{x(f?c.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...c,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${r}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function W({compare:s,setCompare:n,pageId:t}){const[l,r]=b.useState(!1),[c,x]=s;if(s.length===0)return null;const m=({tab:u})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(g,{tag:u.label}),e.jsx("button",{className:"z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",style:{lineHeight:1},onClick:()=>n(s.filter(i=>i.uid!==u.uid)),"aria-label":"Remove selection 1",children:e.jsx(p.X,{className:"h-3 w-3"})})]});return e.jsxs("div",{className:"mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-xs",children:[e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"Compare"}),c&&e.jsx(m,{tab:c}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),x?e.jsx(m,{tab:x}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>r(!0),disabled:s.length<2,children:[e.jsx(p.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),l&&(s==null?void 0:s.length)>1&&t&&e.jsx(b.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open:l,onOpenChange:r,compare:s})})]})}function A({checked:s,disabled:n,onChange:t,label:l="Compare"}){return e.jsx("div",{className:"absolute bottom-2 right-2",children:e.jsxs("label",{className:`flex cursor-pointer items-center gap-x-1 text-[11px] ${n?"opacity-50":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",checked:s,disabled:n,onChange:t}),e.jsx("span",{className:"select-none leading-tight",children:l})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(a.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:l,isRestoring:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Restore Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>l(!1),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(a.Button,{variant:"default",className:"sm:flex-1",onClick:()=>l(!0),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:l,isDeleting:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",className:"sm:flex-1",onClick:l,disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var E,R;const[n,t]=v.useState([]),[l,r]=v.useState(null),[c,x]=v.useState(!1),[m,u]=v.useState(!1),{data:i}=d.useCurrentPage(),{data:f,isFetching:S,error:h,refetch:j}=z(i==null?void 0:i.id),{mutate:k,isPending:M}=B(),{mutate:T,isPending:F}=H(),_=N.useQueryClient(),{selectedLang:P,fallbackLang:q}=O.useLanguages(),U=P||q;b.useEffect(()=>t([]),[i==null?void 0:i.id]);const G=o=>{l&&T({revisionId:l.uid,discardCurrent:o},{onSuccess:()=>{x(!1),r(null),_.invalidateQueries({queryKey:[d.ACTIONS.GET_DRAFT_PAGE]})}})},D=o=>{r(o),x(!0)},C=o=>{r(o),u(!0)},V=()=>{l&&k(l.uid,{onSuccess:()=>{u(!1),r(null)}})};return b.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(a.SheetHeader,{children:[e.jsx(a.SheetTitle,{children:"Revision History"}),(i==null?void 0:i.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",y.format(new Date(i.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),S?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:i==null?void 0:i.id}),e.jsx(J,{compare:n,setCompare:t}),(E=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:E.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:!0,onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w,compare:n,setCompare:t},o.uid)),e.jsx(a.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(R=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:R.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:o.uid==="current",onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:c,onOpenChange:x,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:u,revision:l,onDelete:V,isDeleting:M})]})}exports.default=ee;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as n, jsx as t, Fragment as H } from "react/jsx-runtime";
|
|
2
|
-
import { LanguageSelector as z } from "./page-manager-search-and-filter-
|
|
3
|
-
import { al as R, am as _, A as L, au as $, f as K, h as Q, aj as J, T as A, t as V } from "./index-
|
|
2
|
+
import { LanguageSelector as z } from "./page-manager-search-and-filter-CuAn82Db.js";
|
|
3
|
+
import { al as R, am as _, A as L, au as $, f as K, h as Q, aj as J, T as A, t as V } from "./index-zaGKeGBW.js";
|
|
4
4
|
import { useQuery as W } from "@tanstack/react-query";
|
|
5
5
|
import { DialogContent as X, DialogHeader as Y, DialogTitle as Z, DialogDescription as ee, DialogFooter as te, Button as F } from "@chaibuilder/sdk/ui";
|
|
6
6
|
import { find as G, filter as a, map as y, includes as P, orderBy as b, isEmpty as se, first as le, uniq as U, concat as ne } from "lodash-es";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),B=require("./page-manager-search-and-filter-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),B=require("./page-manager-search-and-filter-eFsGtm5W.cjs"),r=require("./index-Blg1T7nL.cjs"),L=require("@tanstack/react-query"),h=require("@chaibuilder/sdk/ui"),t=require("lodash-es"),j=require("lucide-react"),i=require("react"),F=()=>{const l=r.useApiUrl(),u=r.useFetch();return L.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>u(l,{action:r.ACTIONS.GET_CHANGES})})},O=({page:l,selectedPages:u,handleCheckboxChange:b,getPageType:m,hasSlug:o,currentOwnerId:x})=>{const{data:d}=r.useChaiUserInfo(x),a=d==null?void 0:d.name;return e.jsxs("tr",{className:"group relative border-b last:border-b-0 hover:bg-gray-50",children:[e.jsxs("td",{scope:"row",className:`flex items-center gap-x-1 whitespace-nowrap px-6 py-2 text-gray-900 dark:text-white ${a?"opacity-50":""}`,children:[a?e.jsx(j.Lock,{className:"h-4 w-4 fill-red-200 text-red-500"}):e.jsx("input",{checked:t.includes(u,l==null?void 0:l.id),onClick:p=>{p.stopPropagation(),b(l==null?void 0:l.id)},type:"checkbox",className:"cursor-pointer rounded focus:outline-none focus:ring-0"})," ",o(l.pageType)?e.jsx(j.File,{className:"h-4 w-4"}):e.jsx(j.GlobeIcon,{className:"h-4 w-4"}),e.jsx(r.Tooltip,{content:l.name,side:"top",showTooltip:l.name.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-medium text-black",children:l.name})}),l.slug&&e.jsx(r.Tooltip,{content:l.slug,side:"top",showTooltip:l.slug.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs text-muted-foreground",children:l.slug})})]}),e.jsx("td",{className:"px-2",children:m(l==null?void 0:l.pageType)}),e.jsx("td",{className:"px-4 text-right",children:t.first(l.changes)||""}),e.jsx(e.Fragment,{children:a&&e.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[e.jsx(j.Edit,{size:12,className:"stroke-[3]"})," ",e.jsx("span",{className:"font-medium",children:a})," is editing this page"]})})]},l==null?void 0:l.id)},G=({onClose:l=()=>{},isPending:u,publishPage:b})=>{const[m]=r.usePageUserMapping(),[o,x]=i.useState([]),d=r.useFallbackLang(),[a,p]=i.useState(d),{data:N,isFetching:T}=F(),{data:g}=r.usePageTypes(),k=i.useCallback(s=>{var n;return(n=t.find(g,{key:s}))==null?void 0:n.hasSlug},[g]),y=i.useMemo(()=>t.filter(g,s=>!k(s.key)).map(s=>s.key),[k,g]),P=t.uniq(t.map(N,"lang")).filter(Boolean),c=i.useMemo(()=>t.filter(N,s=>s.pageType==="theme"?!1:a===d?s.lang===a||s.lang==="":s.lang===a),[N,a,d]),w=i.useMemo(()=>t.filter(c,s=>!y.includes(s.pageType)),[c,y]),S=i.useMemo(()=>t.filter(c,s=>y.includes(s.pageType)),[c,y]);i.useEffect(()=>{const s=t.map(t.filter(c,{online:!0}),"id");x(s)},[c]),i.useEffect(()=>{const s=Object.keys(m);x(n=>t.filter(n,f=>!t.includes(s,f)))},[m]);const C=o.length===(c==null?void 0:c.length),v=s=>{x(n=>t.includes(n,s)?t.filter(n,f=>f!==s):t.concat(n,s))},E=()=>{x(C?[]:t.map(c,"id"))},q=()=>{b({ids:t.uniq(o)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(d)}})},M=s=>{if(s==="theme")return"Theme";const n=t.find(g,{key:s});return n?n==null?void 0:n.name:s},A=i.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(f=>f.pageType!=="theme"),n=[{label:"Offline",top:"pt-6"},...t.orderBy(t.filter(w,{online:!1}),"pageType"),...t.orderBy(t.filter(S,{online:!1}),"pageType")];return[...s,...n]},[w,S]);return e.jsxs(h.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(h.DialogHeader,{children:[e.jsx(h.DialogTitle,{children:"Publish changes"}),e.jsx(h.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),P.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(B.LanguageSelector,{languages:[d,...P],selectedLanguage:a,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:T?e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"mt-2 h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):e.jsxs("table",{className:"w-full text-left text-xs text-gray-500 dark:text-gray-400 rtl:text-right",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-gray-50 text-gray-700 dark:bg-gray-700 dark:text-gray-400",children:e.jsxs("tr",{children:[e.jsxs("th",{scope:"col",className:"w-[1 50px] flex items-center gap-x-2 px-6 py-3",children:[e.jsx("input",{checked:C,onClick:s=>{s.stopPropagation(),E()},type:"checkbox",className:"mt-1 cursor-pointer rounded focus:outline-none focus:ring-0"}),"Name"]}),e.jsx("th",{scope:"col",className:"w-[150px] px-2 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"w-[150px] px-4 py-3 text-right",children:"Status"})]})}),e.jsx("tbody",{children:t.map(A,s=>s.label?e.jsx("tr",{children:e.jsxs("td",{colSpan:3,className:`relative px-6 py-2 text-xs font-medium text-gray-800 ${s.top}`,children:[e.jsx("div",{className:"absolute inset-0 left-6 flex items-center",children:e.jsx("div",{className:"order-gray-300 w-full"})}),e.jsx("div",{className:"relative flex justify-start",children:e.jsx("span",{className:"bg-gray-50 pr-2",children:s.label})})]})},"separator"):e.jsx(O,{page:s,selectedPages:o,handleCheckboxChange:v,getPageType:M,hasSlug:k,currentOwnerId:m[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id)]}))})]})}),e.jsxs(h.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[o.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[o.length," Page",o.length!==1?"s":""," Selected"]}),e.jsx(h.Button,{disabled:u,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(h.Button,{disabled:u||T||t.isEmpty(o),onClick:q,children:u?"Publishing...":"Publish Selected"})]})]})};exports.default=G;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("@tanstack/react-query"),k=require("sonner"),x=require("./index-Cds1vIhw.cjs"),E=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{n(t)},onError:t=>{console.error("Error saving block:",t),k.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,n],enabled:!!n,queryFn:async()=>{if(!n)return null;try{return await l(s,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:n}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{n()},onError:t=>{console.error("Error deleting block:",t),k.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:n,libBlockId:s,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[u,o]=i.useState(!1),d=E.useUpdateBlocksPropsRealtime(),b=ee(()=>{d([n],{_libBlockId:void 0}),k.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),b.mutate(s)},g=e.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:u,children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return e.jsxs(c.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(c.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},se=({blockId:n,libBlockId:s,blockName:l,size:t="sm",className:m="",close:f})=>{const[u,o]=i.useState(!1);return e.jsx(te,{blockId:n,libBlockId:s,isOpen:u,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(c.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},re=()=>{const n=x.useApiUrl(),s=x.useFetch(),l=I.useQueryClient(),{data:t=[],isLoading:m,error:f}=I.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await s(n,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=I.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return s(n,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),k.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),k.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:u,isCreating:o}},ne=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),u=i.useRef(null),{groups:o}=re(),[d,b]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...d.filter(r=>!o.some(j=>j.id===r.id))],[o,d]),g=()=>{const r=m.trim();if(!r)return;const j={id:r,name:r};b(w=>[...w,j]),s(j.id),f(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const h=r=>{r.key==="Enter"&&(r.preventDefault(),g())};return i.useEffect(()=>{n&&!p.some(r=>r.id===n)&&s("")},[n,p,s]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Input,{ref:u,placeholder:"Enter new group name",value:m,onChange:r=>f(r.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(c.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:n,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(r=>e.jsx("option",{value:r.id,children:r.name},`lib-${r.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(r=>!o.some(j=>j.id===r.id)).map(r=>e.jsx("option",{value:r.id,children:r.name},`local-${r.id}`))})]}),e.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(C.Plus,{className:"h-4 w-4"})})]})},ae=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async d=>{var p;const b=(p=d.target.files)==null?void 0:p[0];if(b)try{t(!0);let g=b;b.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(b));const h=new FileReader;h.onloadend=()=>{s(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),k.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[s]),u=()=>{s(""),m.current&&(m.current.value="")},o=()=>{var d;(d=m.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(C.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),n&&e.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(C.X,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:n,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=n=>{const{blocks:s,close:l,blockId:t}=n,{getPartailBlocks:m}=E.usePartailBlocksStore(),f=s.find(a=>a._id===t),u=f==null?void 0:f._libBlockId,o=!!u,d=i.useMemo(()=>s.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[s]),b=i.useMemo(()=>{let a=[];for(const y of s)if(y._type==="PartialBlock"||y._type==="GlobalBlock"){let v=m(y.partialBlockId);y._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",y._parent),T))),a=[...a,...v]}else a.push(y);return a},[s,m]),[p,g]=i.useState(""),[h,r]=i.useState(""),[j,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=E.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=E.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),k.toast.success("Block delinked from library"),l()},{data:B,isLoading:P,isError:G}=Z(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{B&&!P&&(g(B.name||""),r(B.group||""),w(B.description||""),_(B.preview||""),F(!1))},[B,P]),i.useEffect(()=>{const a=p.trim().length>=2,y=h.trim()!=="";M(a&&y)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=E.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),k.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const y=b.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));U.mutate({name:p.trim(),group:h,blocks:y,description:j.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(c.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(C.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:r}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:j,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:u,blockName:p,className:"mr-auto",close:l}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(c.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("@tanstack/react-query"),k=require("sonner"),x=require("./index-Blg1T7nL.cjs"),E=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{n(t)},onError:t=>{console.error("Error saving block:",t),k.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,n],enabled:!!n,queryFn:async()=>{if(!n)return null;try{return await l(s,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:n}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{n()},onError:t=>{console.error("Error deleting block:",t),k.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:n,libBlockId:s,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[u,o]=i.useState(!1),d=E.useUpdateBlocksPropsRealtime(),b=ee(()=>{d([n],{_libBlockId:void 0}),k.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),b.mutate(s)},g=e.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:u,children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return e.jsxs(c.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(c.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},se=({blockId:n,libBlockId:s,blockName:l,size:t="sm",className:m="",close:f})=>{const[u,o]=i.useState(!1);return e.jsx(te,{blockId:n,libBlockId:s,isOpen:u,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(c.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},re=()=>{const n=x.useApiUrl(),s=x.useFetch(),l=I.useQueryClient(),{data:t=[],isLoading:m,error:f}=I.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await s(n,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=I.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return s(n,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),k.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),k.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:u,isCreating:o}},ne=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),u=i.useRef(null),{groups:o}=re(),[d,b]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...d.filter(r=>!o.some(j=>j.id===r.id))],[o,d]),g=()=>{const r=m.trim();if(!r)return;const j={id:r,name:r};b(w=>[...w,j]),s(j.id),f(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const h=r=>{r.key==="Enter"&&(r.preventDefault(),g())};return i.useEffect(()=>{n&&!p.some(r=>r.id===n)&&s("")},[n,p,s]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Input,{ref:u,placeholder:"Enter new group name",value:m,onChange:r=>f(r.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(c.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:n,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(r=>e.jsx("option",{value:r.id,children:r.name},`lib-${r.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(r=>!o.some(j=>j.id===r.id)).map(r=>e.jsx("option",{value:r.id,children:r.name},`local-${r.id}`))})]}),e.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(C.Plus,{className:"h-4 w-4"})})]})},ae=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async d=>{var p;const b=(p=d.target.files)==null?void 0:p[0];if(b)try{t(!0);let g=b;b.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(b));const h=new FileReader;h.onloadend=()=>{s(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),k.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[s]),u=()=>{s(""),m.current&&(m.current.value="")},o=()=>{var d;(d=m.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(C.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),n&&e.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(C.X,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:n,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=n=>{const{blocks:s,close:l,blockId:t}=n,{getPartailBlocks:m}=E.usePartailBlocksStore(),f=s.find(a=>a._id===t),u=f==null?void 0:f._libBlockId,o=!!u,d=i.useMemo(()=>s.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[s]),b=i.useMemo(()=>{let a=[];for(const y of s)if(y._type==="PartialBlock"||y._type==="GlobalBlock"){let v=m(y.partialBlockId);y._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",y._parent),T))),a=[...a,...v]}else a.push(y);return a},[s,m]),[p,g]=i.useState(""),[h,r]=i.useState(""),[j,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=E.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=E.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),k.toast.success("Block delinked from library"),l()},{data:B,isLoading:P,isError:G}=Z(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{B&&!P&&(g(B.name||""),r(B.group||""),w(B.description||""),_(B.preview||""),F(!1))},[B,P]),i.useEffect(()=>{const a=p.trim().length>=2,y=h.trim()!=="";M(a&&y)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=E.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),k.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const y=b.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));U.mutate({name:p.trim(),group:h,blocks:y,description:j.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(c.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(C.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:r}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:j,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:u,blockName:p,className:"mr-auto",close:l}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(c.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
|