@chaibuilder/pages 0.16.14 → 0.16.16
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-B9AnRLq_.cjs → 2AITGKQY-BV6JxIio.cjs} +1 -1
- package/dist/{2AITGKQY-B7xwscsX.js → 2AITGKQY-DmJ7FEya.js} +5 -5
- package/dist/{NCMVHL6D-CRMC-wXy.cjs → NCMVHL6D-B_AZmaGG.cjs} +1 -1
- package/dist/{NCMVHL6D-B1mwht0Q.js → NCMVHL6D-DsqUQxZK.js} +4 -4
- package/dist/{ZDWCUMSJ-BqqPEOij.cjs → ZDWCUMSJ-CQXWzREv.cjs} +1 -1
- package/dist/{ZDWCUMSJ-CxKNtXtp.js → ZDWCUMSJ-DusX6DXb.js} +1 -1
- package/dist/active-in-another-tab-CSNxota6.js +34 -0
- package/dist/active-in-another-tab-rGDvhc3f.cjs +1 -0
- package/dist/{add-new-language-page-DD0qvJJs.js → add-new-language-page-C1ekdWwV.js} +20 -20
- package/dist/{add-new-language-page-D2a6GK-7.cjs → add-new-language-page-DmQ_eB85.cjs} +1 -1
- package/dist/{add-new-page-01GDCaa4.cjs → add-new-page-BImvK_fV.cjs} +1 -1
- package/dist/{add-new-page-CYtuChN1.js → add-new-page-C6gW1_B-.js} +1 -1
- package/dist/{ai-panel-content-Ouz6pu_0.cjs → ai-panel-content-BGMRcgkl.cjs} +1 -1
- package/dist/{ai-panel-content-DfdnvlS8.js → ai-panel-content-BJoNy1Yk.js} +2 -2
- package/dist/{ai-panel-default-lang-Bi2fH1so.js → ai-panel-default-lang-BLE3cVLR.js} +3 -3
- package/dist/{ai-panel-default-lang-N1pb8rzQ.cjs → ai-panel-default-lang-CNTq97FU.cjs} +2 -2
- package/dist/{ai-panel-other-lang-2JPRSyO1.js → ai-panel-other-lang-DBBxinT6.js} +3 -3
- package/dist/{ai-panel-other-lang-BysU1464.cjs → ai-panel-other-lang-VRmIp9Qm.cjs} +1 -1
- package/dist/{ai-prompt-input-JeIqWZco.cjs → ai-prompt-input-5aMuJDep.cjs} +1 -1
- package/dist/{ai-prompt-input-DadL_cng.js → ai-prompt-input-BivmKxNH.js} +2 -2
- package/dist/{ai-translation-prompt-B0si-R0R.js → ai-translation-prompt-CkvGj9Zu.js} +1 -1
- package/dist/{ai-translation-prompt-CQb1L7NM.cjs → ai-translation-prompt-hp5Ey1Eq.cjs} +1 -1
- package/dist/continue-editing-in-this-client-BdjGzFLm.cjs +1 -0
- package/dist/continue-editing-in-this-client-Bdm_5BEM.js +24 -0
- package/dist/delete-page-BHu4rVNA.js +70 -0
- package/dist/delete-page-OGCRZzrG.cjs +1 -0
- package/dist/{digital-asset-manager-jfnmWRJj.js → digital-asset-manager-C7JEgxdI.js} +1 -1
- package/dist/{digital-asset-manager-B5FQGtGY.cjs → digital-asset-manager-CaF6tRHd.cjs} +1 -1
- package/dist/{duplicate-page-BNjfZ7Wd.cjs → duplicate-page-Co3QgE3M.cjs} +1 -1
- package/dist/{duplicate-page-CERjaPIW.js → duplicate-page-DZW5jpE3.js} +13 -13
- package/dist/{dynamic-page-selector-XEWV4iCf.js → dynamic-page-selector-C2vVfVwL.js} +1 -1
- package/dist/{dynamic-page-selector-Bpz_bvRu.cjs → dynamic-page-selector-CL-sCDkO.cjs} +1 -1
- package/dist/index-DOH-lluK.js +4820 -0
- package/dist/index-MzR4MaVE.cjs +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -34
- package/dist/index.js +21 -22
- package/dist/{json-diff-viewer-H-2DkGza.cjs → json-diff-viewer-C69tubC8.cjs} +1 -1
- package/dist/{json-diff-viewer-DyvKomxd.js → json-diff-viewer-DVB2glQZ.js} +6 -6
- package/dist/{lang-panel-BWP5A-FD.js → lang-panel-BDNMrT8U.js} +24 -24
- package/dist/{lang-panel-DcZ7u4em.cjs → lang-panel-DWj5wlfo.cjs} +1 -1
- package/dist/{mark-as-template-B_FyVRRO.cjs → mark-as-template-Br9qxjbc.cjs} +1 -1
- package/dist/{mark-as-template-1oVraE1x.js → mark-as-template-wKn7aI8D.js} +7 -7
- package/dist/{no-language-page-content-CEci_4j7.js → no-language-page-content-C7oVsIYu.js} +1 -1
- package/dist/{no-language-page-content-JO4YYUx7.cjs → no-language-page-content-CFVzHv_Y.cjs} +1 -1
- package/dist/no-language-page-dialog-5-cAE2F2.js +10 -0
- package/dist/no-language-page-dialog-BqrxzBfj.cjs +1 -0
- package/dist/{page-creator-DJJFl7px.js → page-creator-89jgn0Ao.js} +52 -52
- package/dist/{page-creator-BGgoOA92.cjs → page-creator-itnGYmd4.cjs} +1 -1
- package/dist/page-lock-BGnEhXCW.cjs +1 -0
- package/dist/page-lock-T6QScRbl.js +30 -0
- package/dist/page-locked-dialog-B39IqdJ9.cjs +1 -0
- package/dist/page-locked-dialog-Bo2JuCSN.js +133 -0
- package/dist/page-manager-new-CElobhjD.js +354 -0
- package/dist/page-manager-new-D44_zdpQ.cjs +1 -0
- package/dist/{page-manager-search-and-filter-Dgh8iyGp.cjs → page-manager-search-and-filter-DmXFyylC.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-DbUoW8Di.js → page-manager-search-and-filter-VgVbeup1.js} +1 -1
- package/dist/{page-revisions-content-CxEJGxLY.js → page-revisions-content-C3GLr_sM.js} +19 -19
- package/dist/{page-revisions-content-CwoXXE53.cjs → page-revisions-content-CsxGDRzT.cjs} +1 -1
- package/dist/pages.css +1 -1
- package/dist/publish-pages-content-CdwZOxtG.cjs +1 -0
- package/dist/{publish-pages-content-CfAlmivf.js → publish-pages-content-Cj6sTZ-B.js} +88 -88
- package/dist/{save-to-lib-DpyJA0y1.cjs → save-to-lib-BjfzVByH.cjs} +1 -1
- package/dist/{save-to-lib-BCaBfh0I.js → save-to-lib-DtdHpuWg.js} +1 -1
- package/dist/{selected-block-display-CqnwyGRp.cjs → selected-block-display-B0yeKnWl.cjs} +1 -1
- package/dist/{selected-block-display-BmNhvYKu.js → selected-block-display-DVzQ888o.js} +1 -1
- package/dist/{seo-panel-D-nKfsRJ.cjs → seo-panel-CaXQTicZ.cjs} +1 -1
- package/dist/{seo-panel-BH8fcGqr.js → seo-panel-h6FQkwhv.js} +61 -61
- package/dist/{shared-json-ld-zTDoJzUv.js → shared-json-ld-B1HhFgk0.js} +39 -39
- package/dist/{shared-json-ld-m_OsVv8h.cjs → shared-json-ld-DcYfd7Sl.cjs} +1 -1
- package/dist/{slug-input-CumDDlCk.js → slug-input-Bq48cfWr.js} +1 -1
- package/dist/{slug-input-vzNtu37S.cjs → slug-input-DDDMhrBe.cjs} +1 -1
- package/dist/take-over-request-BC2Rh5wd.js +63 -0
- package/dist/take-over-request-Cpa9ooTw.cjs +1 -0
- package/dist/{theme-panel-footer-CdUmjB-e.js → theme-panel-footer-B4D33YEO.js} +4 -4
- package/dist/{theme-panel-footer-CKccBcd9.cjs → theme-panel-footer-DoFYuPy1.cjs} +1 -1
- package/dist/{unmark-as-template-BNFOsxIg.cjs → unmark-as-template-4A6kxi6r.cjs} +1 -1
- package/dist/{unmark-as-template-6ew-7bf8.js → unmark-as-template-fkt1rehy.js} +1 -1
- package/dist/{unpublish-page-BomE76Wg.js → unpublish-page-IQ4WTVMd.js} +9 -9
- package/dist/{unpublish-page-BZQpTpU3.cjs → unpublish-page-uIYo5nwG.cjs} +1 -1
- package/dist/{web-preview-C5QTX7bS.cjs → web-preview-BvfhE4ij.cjs} +1 -1
- package/dist/{web-preview-jo8lnpEx.js → web-preview-DYbA7jro.js} +1 -1
- package/package.json +3 -3
- package/dist/delete-page-C8Nt7IYF.cjs +0 -1
- package/dist/delete-page-_96Di9yN.js +0 -40
- package/dist/index-Pdb5tSRL.cjs +0 -5
- package/dist/index-e9WlBH0R.js +0 -4960
- package/dist/page-lock-request-BoYzkcyt.cjs +0 -1
- package/dist/page-lock-request-WzpcD2ZN.js +0 -75
- package/dist/page-locked-by-dialog-Djvjp2Hx.js +0 -68
- package/dist/page-locked-by-dialog-bvI27OZ6.cjs +0 -1
- package/dist/page-manager-new-CMfGorRQ.cjs +0 -1
- package/dist/page-manager-new-DmVX0qLk.js +0 -354
- package/dist/publish-pages-content-BRu7qwAo.cjs +0 -1
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { jsxs as b, jsx as t, Fragment as D } from "react/jsx-runtime";
|
|
2
|
+
import { aA as be, aB as ye, ao as ge, k as ie, T as q, aK as ke, L as Ne, m as ve, g as we, c as Se, av as Ae, aL as Le, aM as K } from "./index-DOH-lluK.js";
|
|
3
|
+
import { u as J } from "./use-page-expand-manager-D6T75I11.js";
|
|
4
|
+
import { compact as ce, filter as z, isEmpty as w, uniqBy as Te, keyBy as de, mapValues as Ce, startCase as Ee, toLower as E, includes as R, get as O, find as $, map as Ue } from "lodash-es";
|
|
5
|
+
import { useTranslation as Ie, useLanguages as ae } from "@chaibuilder/sdk";
|
|
6
|
+
import { useAtom as Me } from "jotai";
|
|
7
|
+
import { NotepadText as $e, MoreHorizontal as ze, Lock as Be, Edit as Fe, Plus as je, ChevronRight as Ge, StarsIcon as Oe, Hash as De, File as ue } from "lucide-react";
|
|
8
|
+
import { useMemo as Q, lazy as U, useState as N, useCallback as le, useEffect as M, Suspense as C } from "react";
|
|
9
|
+
const oe = (e, n) => !e || !Array.isArray(e) ? [] : w(n) ? e : ce(
|
|
10
|
+
z(e, (r) => {
|
|
11
|
+
const s = E(n);
|
|
12
|
+
return R(E((r == null ? void 0 : r.name) || ""), s) || R(E((r == null ? void 0 : r.slug) || ""), s);
|
|
13
|
+
})
|
|
14
|
+
), Re = (e, n) => {
|
|
15
|
+
const r = /* @__PURE__ */ new Set(), s = de(e, "id");
|
|
16
|
+
return n.forEach((o) => {
|
|
17
|
+
let l = o;
|
|
18
|
+
for (; l.parent && s[l.parent]; )
|
|
19
|
+
r.add(l.parent), l = s[l.parent];
|
|
20
|
+
}), Array.from(r).map((o) => s[o]);
|
|
21
|
+
}, V = (e, n, r) => w(n) ? e : e.map((s) => {
|
|
22
|
+
if (!r(s.pageType))
|
|
23
|
+
return {
|
|
24
|
+
...s,
|
|
25
|
+
shouldExpandOnSearch: !0,
|
|
26
|
+
children: s.children ? V(s.children, n, r) : []
|
|
27
|
+
};
|
|
28
|
+
const o = s.children && s.children.some(
|
|
29
|
+
(l) => R(E(l.name || ""), E(n)) || R(E(l.slug || ""), E(n))
|
|
30
|
+
);
|
|
31
|
+
return {
|
|
32
|
+
...s,
|
|
33
|
+
shouldExpandOnSearch: o,
|
|
34
|
+
children: s.children ? V(s.children, n, r) : []
|
|
35
|
+
};
|
|
36
|
+
}), We = (e) => {
|
|
37
|
+
if (!e || !e.length) return [];
|
|
38
|
+
const n = {};
|
|
39
|
+
e.forEach((s) => {
|
|
40
|
+
n[s.id] = { ...s, children: [] };
|
|
41
|
+
});
|
|
42
|
+
const r = [];
|
|
43
|
+
return Object.values(n).forEach((s) => {
|
|
44
|
+
s.parent && n[s.parent] ? n[s.parent].children.push(s) : r.push(s);
|
|
45
|
+
}), r;
|
|
46
|
+
}, me = (e) => !e || !e.length ? [] : [...e].sort(
|
|
47
|
+
(r, s) => (r.name || "").localeCompare(s.name || "")
|
|
48
|
+
).map((r) => ({
|
|
49
|
+
...r,
|
|
50
|
+
children: r.children ? me(r.children) : []
|
|
51
|
+
})), He = (e, n, r, s) => {
|
|
52
|
+
if (!e || !e.length) return [];
|
|
53
|
+
let o = e;
|
|
54
|
+
if (r !== "all" && (o = ce(z(e, { pageType: r }))), w(n))
|
|
55
|
+
o = oe(o, n);
|
|
56
|
+
else {
|
|
57
|
+
const d = oe(o, n), i = Re(e, d);
|
|
58
|
+
o = Te([...d, ...i], "id");
|
|
59
|
+
}
|
|
60
|
+
const l = me(We(o)), f = V(l, n, s), S = z(f, (d) => s(d.pageType)).sort((d, i) => (d.name || "").localeCompare(i.name || "")), x = z(f, (d) => !s(d.pageType));
|
|
61
|
+
let m = [];
|
|
62
|
+
if (r === "all") {
|
|
63
|
+
const d = de(x, "pageType");
|
|
64
|
+
m = Object.values(
|
|
65
|
+
Ce(d, (i, P) => ({
|
|
66
|
+
...i,
|
|
67
|
+
id: P,
|
|
68
|
+
name: Ee(P),
|
|
69
|
+
isPartialGroup: !0,
|
|
70
|
+
children: f.filter((y) => y.pageType === P)
|
|
71
|
+
}))
|
|
72
|
+
);
|
|
73
|
+
} else
|
|
74
|
+
m = x.sort((d, i) => (d.name || "").localeCompare(i.name || ""));
|
|
75
|
+
return [...S, ...m];
|
|
76
|
+
}, _e = ({ page: e }) => {
|
|
77
|
+
var s, o;
|
|
78
|
+
const { isExpanded: n, toggleExpanded: r } = J(e == null ? void 0 : e.id);
|
|
79
|
+
return /* @__PURE__ */ t(
|
|
80
|
+
"button",
|
|
81
|
+
{
|
|
82
|
+
onClick: (l) => {
|
|
83
|
+
l.stopPropagation(), r();
|
|
84
|
+
},
|
|
85
|
+
disabled: !((s = e == null ? void 0 : e.children) != null && s.length),
|
|
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 ${(o = e == null ? void 0 : e.children) != null && o.length ? "hover:text-blue-400" : "opacity-0"}`,
|
|
87
|
+
children: /* @__PURE__ */ t(
|
|
88
|
+
Ge,
|
|
89
|
+
{
|
|
90
|
+
size: 12,
|
|
91
|
+
className: `stroke-[4] transition-transform duration-200 ${n ? "rotate-90" : ""}`
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}, qe = ({ page: e, pageType: n }) => /* @__PURE__ */ t("div", { className: "flex h-full items-center justify-center gap-x-1", children: e.dynamic ? /* @__PURE__ */ t(Oe, { size: 12, className: "text-yellow-400" }) : n != null && n.icon ? /* @__PURE__ */ t(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
className: "flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",
|
|
100
|
+
dangerouslySetInnerHTML: { __html: n.icon }
|
|
101
|
+
}
|
|
102
|
+
) : n != null && n.hasSlug ? /* @__PURE__ */ t(ue, { size: 12, className: "stroke-[1] text-slate-500" }) : /* @__PURE__ */ t(De, { size: 12, className: "stroke-[1] text-slate-500" }) }), Ke = ({ isOnline: e }) => /* @__PURE__ */ t("div", { className: `h-2 w-2 rounded-full ${e ? "bg-green-300" : "bg-gray-300"}` }), Qe = ({
|
|
103
|
+
page: e,
|
|
104
|
+
pageTypes: n,
|
|
105
|
+
currentPage: r,
|
|
106
|
+
onClickAction: s,
|
|
107
|
+
languagePages: o,
|
|
108
|
+
selectedLanguage: l,
|
|
109
|
+
showUntranslatedPages: f
|
|
110
|
+
}) => {
|
|
111
|
+
const S = be(), { pageToUser: x } = ye(), m = O(x, [e == null ? void 0 : e.id, "userId"]), { data: d } = ge(m), i = d && S !== m ? d == null ? void 0 : d.name : null, P = ie(), y = r === e.id, W = !!e.isTemplate, p = Q(() => $(n, { key: e.pageType }), [n, e.pageType]);
|
|
112
|
+
let u = O(o, e == null ? void 0 : e.id);
|
|
113
|
+
u = O(u, "lang") === l ? u : null;
|
|
114
|
+
const A = l === P || !!u, L = (u == null ? void 0 : u.name) || (e == null ? void 0 : e.name) || "No name";
|
|
115
|
+
let g = (u == null ? void 0 : u.slug) || (e == null ? void 0 : e.slug) || "";
|
|
116
|
+
const B = g + (e != null && e.dynamic ? `/${p == null ? void 0 : p.dynamicSlug}` : "") + (e != null && e.dynamicSlugCustom ? `${e.dynamicSlugCustom}` : "");
|
|
117
|
+
if (g.startsWith("/") && !f) {
|
|
118
|
+
const c = g.split("/").pop();
|
|
119
|
+
g = g.endsWith(c) && e.dynamic ? "" : `/${c}`;
|
|
120
|
+
}
|
|
121
|
+
const F = Q(() => {
|
|
122
|
+
const c = "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 = `${y ? "border-primary/30 bg-primary/5" : "border-transparent hover:border-gray-200 hover:bg-gray-100"}`;
|
|
123
|
+
return A ? `${c} ${T} ${i ? "opacity-60" : ""}` : `${c} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`;
|
|
124
|
+
}, [A, y, i]);
|
|
125
|
+
return /* @__PURE__ */ b("div", { className: "group relative", children: [
|
|
126
|
+
/* @__PURE__ */ b(
|
|
127
|
+
"div",
|
|
128
|
+
{
|
|
129
|
+
onClick: () => !e.isPartialGroup && A && s("select", e == null ? void 0 : e.id),
|
|
130
|
+
className: F,
|
|
131
|
+
children: [
|
|
132
|
+
/* @__PURE__ */ t(_e, { page: e }),
|
|
133
|
+
!e.isPartialGroup && /* @__PURE__ */ t(Ke, { isOnline: u ? u.online : e.online }),
|
|
134
|
+
!e.isPartialGroup && /* @__PURE__ */ t(qe, { page: e, pageType: p }),
|
|
135
|
+
/* @__PURE__ */ t(q, { content: L, side: "top", showTooltip: L.length > 35, children: /* @__PURE__ */ t("span", { className: "max-w-[40%] truncate font-medium text-black", children: L }) }),
|
|
136
|
+
(g || e.dynamic) && /* @__PURE__ */ t(q, { content: B, side: "top", showTooltip: !0, children: /* @__PURE__ */ b("span", { className: "max-w-[40%] truncate font-mono text-xs text-muted-foreground", children: [
|
|
137
|
+
g,
|
|
138
|
+
e.dynamic && (p == null ? void 0 : p.dynamicSlug) && /* @__PURE__ */ b("span", { className: "text-xs text-gray-500", children: [
|
|
139
|
+
"/",
|
|
140
|
+
p == null ? void 0 : p.dynamicSlug,
|
|
141
|
+
e.dynamicSlugCustom
|
|
142
|
+
] })
|
|
143
|
+
] }) }),
|
|
144
|
+
W && /* @__PURE__ */ t(q, { content: "Template", side: "top", children: /* @__PURE__ */ t("span", { className: "text-blue-500", children: /* @__PURE__ */ t($e, { size: 16 }) }) }),
|
|
145
|
+
!e.isPartialGroup && A && !i ? /* @__PURE__ */ t("div", { className: "duration absolute right-0.5 top-[3px]", children: /* @__PURE__ */ t(
|
|
146
|
+
ke,
|
|
147
|
+
{
|
|
148
|
+
isLanguagePage: !!u,
|
|
149
|
+
page: u || e,
|
|
150
|
+
setDuplicatePage: (c) => s("duplicate", c),
|
|
151
|
+
setAddEditPage: (c) => s("edit", u || c),
|
|
152
|
+
setUnpublishPage: (c) => s("unpublish", c),
|
|
153
|
+
setDeletePage: (c) => s("delete", u || c),
|
|
154
|
+
setMarkAsTemplate: (c) => s("markAsTemplate", c),
|
|
155
|
+
setUnmarkAsTemplate: (c) => s("unmarkAsTemplate", c),
|
|
156
|
+
children: /* @__PURE__ */ t("div", { className: "m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white", children: /* @__PURE__ */ t(ze, { className: "h-4 w-4", onClick: (c) => c.stopPropagation() }) })
|
|
157
|
+
}
|
|
158
|
+
) }) : i ? /* @__PURE__ */ t("span", { className: "duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500", children: /* @__PURE__ */ t(Be, { className: "h-3.5 w-3.5 fill-red-200 text-red-500" }) }) : null
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
/* @__PURE__ */ t(D, { children: i && /* @__PURE__ */ b("button", { className: "absolute right-px top-1/2 flex h-6 -translate-y-1/2 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__ */ t(Fe, { size: 12, className: "stroke-[3]" }),
|
|
164
|
+
" ",
|
|
165
|
+
/* @__PURE__ */ t("span", { className: "font-medium", children: i }),
|
|
166
|
+
" is editing this page"
|
|
167
|
+
] }) }),
|
|
168
|
+
/* @__PURE__ */ t(D, { children: !A && !e.isPartialGroup && !i && /* @__PURE__ */ b(
|
|
169
|
+
"button",
|
|
170
|
+
{
|
|
171
|
+
onClick: (c) => {
|
|
172
|
+
c.stopPropagation(), s("addLanguagePage", { language: l, page: e });
|
|
173
|
+
},
|
|
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
|
+
children: [
|
|
176
|
+
/* @__PURE__ */ t(je, { size: 12, className: "stroke-[3]" }),
|
|
177
|
+
" ",
|
|
178
|
+
/* @__PURE__ */ b("span", { className: "text-[10px]", children: [
|
|
179
|
+
"Add ",
|
|
180
|
+
O(Ne, l),
|
|
181
|
+
" Page"
|
|
182
|
+
] })
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
) })
|
|
186
|
+
] });
|
|
187
|
+
}, he = ({
|
|
188
|
+
pages: e,
|
|
189
|
+
tier: n,
|
|
190
|
+
pageTypes: r,
|
|
191
|
+
currentPage: s,
|
|
192
|
+
onClickAction: o,
|
|
193
|
+
languagePages: l,
|
|
194
|
+
selectedLanguage: f,
|
|
195
|
+
showUntranslatedPages: S
|
|
196
|
+
}) => {
|
|
197
|
+
const { expandedPages: x } = J();
|
|
198
|
+
return /* @__PURE__ */ t("div", { className: "space-y-0.5", style: { paddingLeft: `${n * 10}px` }, children: e.map((m) => /* @__PURE__ */ b(D, { children: [
|
|
199
|
+
/* @__PURE__ */ t(
|
|
200
|
+
Qe,
|
|
201
|
+
{
|
|
202
|
+
page: m,
|
|
203
|
+
pageTypes: r,
|
|
204
|
+
currentPage: s,
|
|
205
|
+
onClickAction: o,
|
|
206
|
+
languagePages: l,
|
|
207
|
+
selectedLanguage: f,
|
|
208
|
+
showUntranslatedPages: S
|
|
209
|
+
}
|
|
210
|
+
),
|
|
211
|
+
m.children && m.children.length > 0 && (x == null ? void 0 : x.includes(m.id)) && /* @__PURE__ */ t(
|
|
212
|
+
he,
|
|
213
|
+
{
|
|
214
|
+
pages: m.children,
|
|
215
|
+
tier: n + 1,
|
|
216
|
+
pageTypes: r,
|
|
217
|
+
currentPage: s,
|
|
218
|
+
onClickAction: o,
|
|
219
|
+
languagePages: l,
|
|
220
|
+
selectedLanguage: f,
|
|
221
|
+
showUntranslatedPages: S
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
] }, m.id)) });
|
|
225
|
+
}, Ve = U(() => import("./page-manager-search-and-filter-VgVbeup1.js")), Je = U(() => import("./add-new-page-C6gW1_B-.js")), Xe = U(() => import("./delete-page-BHu4rVNA.js")), Ye = U(() => import("./duplicate-page-DZW5jpE3.js")), Ze = U(() => import("./mark-as-template-wKn7aI8D.js")), et = U(() => import("./unmark-as-template-fkt1rehy.js")), tt = U(() => import("./unpublish-page-IQ4WTVMd.js")), dt = ({ close: e }) => {
|
|
226
|
+
const { t: n } = Ie(), { languages: r, setSelectedLang: s } = ae(), { data: o } = ve(), { data: l, isFetching: f } = we(), [S, x] = Se(), { updateForSelectedPage: m, expandPagesOnSearch: d } = J(null), i = ie(), P = S.get("page"), [y, W] = N(""), [p, u] = N(null), [A, L] = N(null), [g, B] = N(null), [F, c] = N(null), [T, H] = N(""), [X, Y] = N(null), [Z, ee] = N(null), [k, fe] = N(i), [xe, Pe] = N(!1), [, te] = Me(Ae), j = xe && k !== i, { data: I, isFetching: pe } = Le(k), se = le(
|
|
227
|
+
(h) => {
|
|
228
|
+
var a;
|
|
229
|
+
return (a = $(o, { key: h })) == null ? void 0 : a.hasSlug;
|
|
230
|
+
},
|
|
231
|
+
[o]
|
|
232
|
+
), v = Q(() => l ? j ? z(l, (h) => !(I != null && I[h.id])) : He(l, y, T, se) : [], [l, se, y, T, I, j]);
|
|
233
|
+
M(() => {
|
|
234
|
+
s(i);
|
|
235
|
+
}, [i, s]), M(() => {
|
|
236
|
+
if (!w(T)) return;
|
|
237
|
+
const h = sessionStorage.getItem("pageTypeFilter") || "all";
|
|
238
|
+
!w(o) && h && ($(o, { key: h }) ? H(h) : H("all"));
|
|
239
|
+
}, [o, T]), M(() => {
|
|
240
|
+
if (P && !f && !$(l, { id: P })) {
|
|
241
|
+
const a = $(l, { slug: "/" });
|
|
242
|
+
if (a) {
|
|
243
|
+
const G = new URLSearchParams({ page: a.id });
|
|
244
|
+
K(G, x);
|
|
245
|
+
} else
|
|
246
|
+
K(new URLSearchParams({}), x, !0);
|
|
247
|
+
}
|
|
248
|
+
}, [l, P, f, x]), M(() => {
|
|
249
|
+
P && !f && !w(v) && m(v, P);
|
|
250
|
+
}, [P, f, v, m]), M(() => {
|
|
251
|
+
!w(y) && !w(v) && d(v);
|
|
252
|
+
}, [y, v, d]);
|
|
253
|
+
const { setSelectedLang: _ } = ae(), ne = le(
|
|
254
|
+
(h) => {
|
|
255
|
+
const a = new URLSearchParams({ page: h });
|
|
256
|
+
k !== i ? (a.set("lang", k), _(k)) : _(""), K(a, x), e();
|
|
257
|
+
},
|
|
258
|
+
[e, x, _, k, i]
|
|
259
|
+
), re = (h, a) => {
|
|
260
|
+
var G;
|
|
261
|
+
if (a)
|
|
262
|
+
switch (h) {
|
|
263
|
+
case "add":
|
|
264
|
+
L(a);
|
|
265
|
+
break;
|
|
266
|
+
case "select":
|
|
267
|
+
ne(a);
|
|
268
|
+
break;
|
|
269
|
+
case "edit":
|
|
270
|
+
k !== i ? te({
|
|
271
|
+
edit: !0,
|
|
272
|
+
id: a == null ? void 0 : a.id,
|
|
273
|
+
primaryPage: a == null ? void 0 : a.primaryPage
|
|
274
|
+
}) : L(a);
|
|
275
|
+
break;
|
|
276
|
+
case "delete":
|
|
277
|
+
u(a);
|
|
278
|
+
break;
|
|
279
|
+
case "unpublish":
|
|
280
|
+
B(a);
|
|
281
|
+
break;
|
|
282
|
+
case "markAsTemplate":
|
|
283
|
+
c(a);
|
|
284
|
+
break;
|
|
285
|
+
case "unmarkAsTemplate":
|
|
286
|
+
ee(a);
|
|
287
|
+
break;
|
|
288
|
+
case "duplicate":
|
|
289
|
+
Y(a);
|
|
290
|
+
break;
|
|
291
|
+
case "addLanguagePage":
|
|
292
|
+
te({
|
|
293
|
+
edit: !1,
|
|
294
|
+
primaryPage: ((G = a == null ? void 0 : a.page) == null ? void 0 : G.id) || "",
|
|
295
|
+
preselectedLang: (a == null ? void 0 : a.language) || k
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
return /* @__PURE__ */ b(D, { children: [
|
|
301
|
+
/* @__PURE__ */ b("div", { className: "flex h-full flex-col justify-between", children: [
|
|
302
|
+
/* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(
|
|
303
|
+
Ve,
|
|
304
|
+
{
|
|
305
|
+
pages: v,
|
|
306
|
+
search: y,
|
|
307
|
+
setSearch: W,
|
|
308
|
+
languages: [i, ...r],
|
|
309
|
+
selectedLanguage: k,
|
|
310
|
+
setSelectedLanguage: fe,
|
|
311
|
+
selectedPageType: T,
|
|
312
|
+
setSelectedPageType: H,
|
|
313
|
+
onAddPage: (h) => re("add", h),
|
|
314
|
+
showUntranslatedPages: j,
|
|
315
|
+
setShowUntranslatedPages: Pe
|
|
316
|
+
}
|
|
317
|
+
) }),
|
|
318
|
+
/* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto px-4 pb-6 pt-2", children: f || pe ? /* @__PURE__ */ t("div", { className: "space-y-2", children: Ue([...Array(15).keys()], (h) => /* @__PURE__ */ t("div", { className: "h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200" }, h)) }) : w(v) ? /* @__PURE__ */ b("div", { className: "flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500", children: [
|
|
319
|
+
/* @__PURE__ */ t(ue, { className: "h-6 w-6 stroke-[1]" }),
|
|
320
|
+
n("Empty List!"),
|
|
321
|
+
/* @__PURE__ */ t("span", { className: "font-light", children: n("Add new page to start") })
|
|
322
|
+
] }) : /* @__PURE__ */ t(
|
|
323
|
+
he,
|
|
324
|
+
{
|
|
325
|
+
tier: 0,
|
|
326
|
+
pages: v,
|
|
327
|
+
pageTypes: o,
|
|
328
|
+
currentPage: P || "",
|
|
329
|
+
onClickAction: re,
|
|
330
|
+
languagePages: I,
|
|
331
|
+
selectedLanguage: k,
|
|
332
|
+
showUntranslatedPages: j
|
|
333
|
+
}
|
|
334
|
+
) })
|
|
335
|
+
] }),
|
|
336
|
+
A && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(
|
|
337
|
+
Je,
|
|
338
|
+
{
|
|
339
|
+
closePanel: e,
|
|
340
|
+
editPage: ne,
|
|
341
|
+
addEditPage: A,
|
|
342
|
+
setAddEditPage: L
|
|
343
|
+
}
|
|
344
|
+
) }),
|
|
345
|
+
p && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(Xe, { page: p, onClose: () => u(null) }) }),
|
|
346
|
+
g && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(tt, { page: g, onClose: () => B(null) }) }),
|
|
347
|
+
F && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(Ze, { page: F, onClose: () => c(null) }) }),
|
|
348
|
+
Z && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(et, { page: Z, onClose: () => ee(null) }) }),
|
|
349
|
+
X && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(Ye, { page: X, onClose: () => Y(null), closePanel: e }) })
|
|
350
|
+
] });
|
|
351
|
+
};
|
|
352
|
+
export {
|
|
353
|
+
dt as default
|
|
354
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("./index-MzR4MaVE.cjs"),G=require("./use-page-expand-manager-2KjeYfVS.cjs"),n=require("lodash-es"),$=require("@chaibuilder/sdk"),te=require("jotai"),v=require("lucide-react"),l=require("react"),J=(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)})),ne=(e,r)=>{const a=new Set,t=n.keyBy(e,"id");return r.forEach(c=>{let o=c;for(;o.parent&&t[o.parent];)a.add(o.parent),o=t[o.parent]}),Array.from(a).map(c=>t[c])},B=(e,r,a)=>n.isEmpty(r)?e:e.map(t=>{if(!a(t.pageType))return{...t,shouldExpandOnSearch:!0,children:t.children?B(t.children,r,a):[]};const c=t.children&&t.children.some(o=>n.includes(n.toLower(o.name||""),n.toLower(r))||n.includes(n.toLower(o.slug||""),n.toLower(r)));return{...t,shouldExpandOnSearch:c,children:t.children?B(t.children,r,a):[]}}),re=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},K=e=>!e||!e.length?[]:[...e].sort((a,t)=>(a.name||"").localeCompare(t.name||"")).map(a=>({...a,children:a.children?K(a.children):[]})),ae=(e,r,a,t)=>{if(!e||!e.length)return[];let c=e;if(a!=="all"&&(c=n.compact(n.filter(e,{pageType:a}))),n.isEmpty(r))c=J(c,r);else{const m=J(c,r),d=ne(e,m);c=n.uniqBy([...m,...d],"id")}const o=K(re(c)),y=B(o,r,t),N=n.filter(y,m=>t(m.pageType)).sort((m,d)=>(m.name||"").localeCompare(d.name||"")),p=n.filter(y,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:y.filter(g=>g.pageType===j)})))}else f=p.sort((m,d)=>(m.name||"").localeCompare(d.name||""));return[...N,...f]},le=({page:e})=>{var t,c;const{isExpanded:r,toggleExpanded:a}=G.usePageExpandManager(e==null?void 0:e.id);return s.jsx("button",{onClick:o=>{o.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 ${(c=e==null?void 0:e.children)!=null&&c.length?"hover:text-blue-400":"opacity-0"}`,children:s.jsx(v.ChevronRight,{size:12,className:`stroke-[4] transition-transform duration-200 ${r?"rotate-90":""}`})})},ie=({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"})}),oe=({isOnline:e})=>s.jsx("div",{className:`h-2 w-2 rounded-full ${e?"bg-green-300":"bg-gray-300"}`}),ce=({page:e,pageTypes:r,currentPage:a,onClickAction:t,languagePages:c,selectedLanguage:o,showUntranslatedPages:y})=>{const N=x.useUserId(),{pageToUser:p}=x.usePageToUser(),f=n.get(p,[e==null?void 0:e.id,"userId"]),{data:m}=x.useChaiUserInfo(f),d=m&&N!==f?m==null?void 0:m.name:null,j=x.useFallbackLang(),g=a===e.id,U=!!e.isTemplate,b=l.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]);let h=n.get(c,e==null?void 0:e.id);h=n.get(h,"lang")===o?h:null;const E=o===j||!!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?`/${b==null?void 0:b.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(S.startsWith("/")&&!y){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=`${g?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${u} ${T} ${d?"opacity-60":""}`:`${u} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,g,d]);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(le,{page:e}),!e.isPartialGroup&&s.jsx(oe,{isOnline:h?h.online:e.online}),!e.isPartialGroup&&s.jsx(ie,{page:e,pageType:b}),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&&(b==null?void 0:b.dynamicSlug)&&s.jsxs("span",{className:"text-xs text-gray-500",children:["/",b==null?void 0:b.dynamicSlug,e.dynamicSlugCustom]})]})}),U&&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&&!d?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()})})})}):d?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:d&&s.jsxs("button",{className:"absolute right-px top-1/2 flex h-6 -translate-y-1/2 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:d})," is editing this page"]})}),s.jsx(s.Fragment,{children:!E&&!e.isPartialGroup&&!d&&s.jsxs("button",{onClick:u=>{u.stopPropagation(),t("addLanguagePage",{language:o,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,o)," Page"]})]})})]})},X=({pages:e,tier:r,pageTypes:a,currentPage:t,onClickAction:c,languagePages:o,selectedLanguage:y,showUntranslatedPages:N})=>{const{expandedPages:p}=G.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(ce,{page:f,pageTypes:a,currentPage:t,onClickAction:c,languagePages:o,selectedLanguage:y,showUntranslatedPages:N}),f.children&&f.children.length>0&&(p==null?void 0:p.includes(f.id))&&s.jsx(X,{pages:f.children,tier:r+1,pageTypes:a,currentPage:t,onClickAction:c,languagePages:o,selectedLanguage:y,showUntranslatedPages:N})]},f.id))})},de=l.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-DmXFyylC.cjs"))),ue=l.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-BImvK_fV.cjs"))),me=l.lazy(()=>Promise.resolve().then(()=>require("./delete-page-OGCRZzrG.cjs"))),he=l.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-Co3QgE3M.cjs"))),xe=l.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-Br9qxjbc.cjs"))),fe=l.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-4A6kxi6r.cjs"))),Pe=l.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-uIYo5nwG.cjs"))),ye=({close:e})=>{const{t:r}=$.useTranslation(),{languages:a,setSelectedLang:t}=$.useLanguages(),{data:c}=x.usePageTypes(),{data:o,isFetching:y}=x.useWebsitePages(),[N,p]=x.useSearchParams(),{updateForSelectedPage:f,expandPagesOnSearch:m}=G.usePageExpandManager(null),d=x.useFallbackLang(),j=N.get("page"),[g,U]=l.useState(""),[b,h]=l.useState(null),[E,L]=l.useState(null),[S,C]=l.useState(null),[q,u]=l.useState(null),[T,F]=l.useState(""),[O,R]=l.useState(null),[D,W]=l.useState(null),[k,Y]=l.useState(d),[Z,ee]=l.useState(!1),[,H]=te.useAtom(x.addNewLangAtom),M=Z&&k!==d,{data:A,isFetching:se}=x.useWebsiteLanguagePages(k),_=l.useCallback(P=>{var i;return(i=n.find(c,{key:P}))==null?void 0:i.hasSlug},[c]),w=l.useMemo(()=>o?M?n.filter(o,P=>!(A!=null&&A[P.id])):ae(o,g,T,_):[],[o,_,g,T,A,M]);l.useEffect(()=>{t(d)},[d,t]),l.useEffect(()=>{if(!n.isEmpty(T))return;const P=sessionStorage.getItem("pageTypeFilter")||"all";!n.isEmpty(c)&&P&&(n.find(c,{key:P})?F(P):F("all"))},[c,T]),l.useEffect(()=>{if(j&&!y&&!n.find(o,{id:j})){const i=n.find(o,{slug:"/"});if(i){const z=new URLSearchParams({page:i.id});x.navigateToPage(z,p)}else x.navigateToPage(new URLSearchParams({}),p,!0)}},[o,j,y,p]),l.useEffect(()=>{j&&!y&&!n.isEmpty(w)&&f(w,j)},[j,y,w,f]),l.useEffect(()=>{!n.isEmpty(g)&&!n.isEmpty(w)&&m(w)},[g,w,m]);const{setSelectedLang:I}=$.useLanguages(),Q=l.useCallback(P=>{const i=new URLSearchParams({page:P});k!==d?(i.set("lang",k),I(k)):I(""),x.navigateToPage(i,p),e()},[e,p,I,k,d]),V=(P,i)=>{var z;if(i)switch(P){case"add":L(i);break;case"select":Q(i);break;case"edit":k!==d?H({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":W(i);break;case"duplicate":R(i);break;case"addLanguagePage":H({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(de,{pages:w,search:g,setSearch:U,languages:[d,...a],selectedLanguage:k,setSelectedLanguage:Y,selectedPageType:T,setSelectedPageType:F,onAddPage:P=>V("add",P),showUntranslatedPages:M,setShowUntranslatedPages:ee})}),s.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-6 pt-2",children:y||se?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]"}),r("Empty List!"),s.jsx("span",{className:"font-light",children:r("Add new page to start")})]}):s.jsx(X,{tier:0,pages:w,pageTypes:c,currentPage:j||"",onClickAction:V,languagePages:A,selectedLanguage:k,showUntranslatedPages:M})})]}),E&&s.jsx(l.Suspense,{children:s.jsx(ue,{closePanel:e,editPage:Q,addEditPage:E,setAddEditPage:L})}),b&&s.jsx(l.Suspense,{children:s.jsx(me,{page:b,onClose:()=>h(null)})}),S&&s.jsx(l.Suspense,{children:s.jsx(Pe,{page:S,onClose:()=>C(null)})}),q&&s.jsx(l.Suspense,{children:s.jsx(xe,{page:q,onClose:()=>u(null)})}),D&&s.jsx(l.Suspense,{children:s.jsx(fe,{page:D,onClose:()=>W(null)})}),O&&s.jsx(l.Suspense,{children:s.jsx(he,{page:O,onClose:()=>R(null),closePanel:e})})]})};exports.default=ye;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-MzR4MaVE.cjs"),N=require("./use-page-expand-manager-2KjeYfVS.cjs"),m=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),w=require("@tanstack/react-query"),r=require("lodash-es"),d=require("lucide-react"),C=require("react"),S=({selectedPageType:l,setSelectedPageType:i})=>{const{t:a}=m.useTranslation(),[n,o]=C.useState(""),{data:c}=j.usePageTypes(),h=t=>{if(!n)return!0;const x=n.toLowerCase(),p=g=>String(r.get(t,g,"")).toLowerCase().includes(x);return p("name")||p("key")},u=c.find(t=>t.key===l);return e.jsxs(s.Select,{onValueChange:i,value:l,children:[e.jsx(s.SelectTrigger,{className:`${l==="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)||a("All")}),e.jsx(d.ListFilter,{className:`${l!=="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(d.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(s.Input,{placeholder:a("Search page types..."),className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:n,onChange:t=>o(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(s.SelectItem,{value:"all",children:a("All")}),!r.isEmpty(r.filter(c,t=>t.hasSlug&&h(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:a("Pages")}),r.map([...r.filter(c,t=>t.hasSlug&&h(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(c,t=>!t.hasSlug&&h(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:a("Partials")}),r.map([...r.filter(c,t=>!t.hasSlug&&h(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(c,h))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:a("No matching page types found")})]})]})},k=({search:l,setSearch:i})=>{const{t:a}=m.useTranslation();return 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:a("Search Pages")}),e.jsx(d.Search,{className:`${l?"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:a("Search pages"),value:l,onChange:n=>i(n.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"})]})},T=({pages:l})=>{const{t:i}=m.useTranslation(),{expandAll:a,collapseAll:n,expandedPages:o}=N.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(l),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsUpDown,{})})}),e.jsx(s.TooltipContent,{children:i("Expand All")})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{disabled:o.length===0,variant:"outline",size:"icon",onClick:()=>n(),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsDownUp,{})})}),e.jsx(s.TooltipContent,{children:i("Collapse All")})]})]})},y=({languages:l,selectedLanguage:i,setSelectedLanguage:a})=>{const n=j.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:l.map(o=>e.jsxs(s.Button,{variant:i===o?"default":"outline",size:"sm",className:`h-6 flex-shrink-0 whitespace-nowrap rounded px-3 text-xs font-normal ${i===o?"bg-black text-white hover:bg-black":"text-gray-500"}`,onClick:()=>a(o.toLowerCase()),children:[o===n&&e.jsx(d.Star,{size:4,className:`p-0.5 ${i===n?"fill-white":"fill-black"}`}),j.LANGUAGES[o]||""]},o))})},v=()=>{const{t:l}=m.useTranslation(),i=w.useQueryClient();return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",onClick:()=>i.invalidateQueries({queryKey:[j.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(d.RefreshCw,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:l("Refresh pages list")})]})},E=({pages:l,search:i,setSearch:a,languages:n,onAddPage:o,selectedLanguage:c,setSelectedLanguage:h,selectedPageType:u,setSelectedPageType:t,showUntranslatedPages:x,setShowUntranslatedPages:p})=>{const{t:g}=m.useTranslation(),f=n.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(S,{selectedPageType:u,setSelectedPageType:t}),e.jsx(k,{search:i,setSearch:a}),e.jsx(T,{pages:l}),e.jsxs(s.Button,{variant:"default",onClick:o,className:"rounded px-3 font-normal",children:[e.jsx(d.Plus,{strokeWidth:2,className:"stroke-white stroke-[3]"}),e.jsx("span",{className:"font-normal text-white",children:g("Add Page")})]}),!f&&e.jsx(v,{})]}),f?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(y,{languages:n,selectedLanguage:c,setSelectedLanguage:b=>{h(b),p(x&&(n==null?void 0:n[0])!==c)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(n==null?void 0:n[0])!==c&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",onClick:()=>p(!x),className:"h-6 rounded px-3 py-1 text-xs font-normal",children:x?e.jsx(d.FilterXIcon,{}):e.jsx(d.Filter,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:g("Toggle Untranslated Pages")})]}),e.jsx(v,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=y;exports.default=E;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as n, Fragment as k } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { k as F, L as I, m as z, A as j } from "./index-DOH-lluK.js";
|
|
3
3
|
import { u as T } from "./use-page-expand-manager-D6T75I11.js";
|
|
4
4
|
import { useTranslation as f } from "@chaibuilder/sdk";
|
|
5
5
|
import { Button as m, Tooltip as g, TooltipTrigger as b, TooltipContent as y, Select as $, SelectTrigger as G, SelectContent as D, Input as E, SelectItem as N } from "@chaibuilder/sdk/ui";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs as n, Fragment as p, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useQuery as re, useQueryClient as
|
|
2
|
+
import { aq as C, ar as A, A as b, aw as q, az as le, ao as I, ax as R, ay as w } from "./index-DOH-lluK.js";
|
|
3
|
+
import { useQuery as re, useQueryClient as O, useMutation as G } from "@tanstack/react-query";
|
|
4
4
|
import { useLanguages as ie, useSavePage as de } from "@chaibuilder/sdk";
|
|
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 j, DialogContent as L, DialogHeader as
|
|
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 j, DialogContent as L, DialogHeader as z, DialogTitle as P, DialogDescription as $, DialogFooter as H } from "@chaibuilder/sdk/ui";
|
|
6
6
|
import { format as D, formatDistanceToNow as xe } from "date-fns";
|
|
7
7
|
import { isEmpty as ge } from "lodash-es";
|
|
8
8
|
import { FileJson as Ne, MoreHorizontal as be, Undo2 as J, Trash as Q, CloudOff as ye, Rocket as ve, Save as we, X as De } from "lucide-react";
|
|
@@ -21,7 +21,7 @@ function Ce(t) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
const Ae = () => {
|
|
24
|
-
const t = C(), s = A(), a =
|
|
24
|
+
const t = C(), s = A(), a = O();
|
|
25
25
|
return G({
|
|
26
26
|
mutationFn: async (i) => await s(t, {
|
|
27
27
|
action: b.DELETE_PAGE_REVISION,
|
|
@@ -34,7 +34,7 @@ const Ae = () => {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
}, Ie = () => {
|
|
37
|
-
const t = C(), s = A(), a =
|
|
37
|
+
const t = C(), s = A(), a = O();
|
|
38
38
|
return G({
|
|
39
39
|
mutationFn: async ({ revisionId: i, discardCurrent: l }) => await s(t, {
|
|
40
40
|
action: b.RESTORE_PAGE_REVISION,
|
|
@@ -46,7 +46,7 @@ const Ae = () => {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
},
|
|
49
|
+
}, Oe = Se(() => import("./json-diff-viewer-DVB2glQZ.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" })
|
|
@@ -65,7 +65,7 @@ const Ae = () => {
|
|
|
65
65
|
/* @__PURE__ */ e(we, { className: "h-3 w-3" }),
|
|
66
66
|
/* @__PURE__ */ e("span", { className: "text-[11px] leading-tight", children: "Unsaved changes" })
|
|
67
67
|
] }) : /* @__PURE__ */ e("span", { className: "rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600", children: t });
|
|
68
|
-
function
|
|
68
|
+
function ke({ compare: t, setCompare: s }) {
|
|
69
69
|
const { data: a } = q(), { saveState: i } = de(), [l] = le();
|
|
70
70
|
if (!a) return null;
|
|
71
71
|
const d = !!t.find((o) => {
|
|
@@ -214,7 +214,7 @@ function Te({ compare: t, setCompare: s, pageId: a }) {
|
|
|
214
214
|
Re,
|
|
215
215
|
{
|
|
216
216
|
fallback: /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-4", children: /* @__PURE__ */ e("span", { className: "text-sm", children: "Loading diff viewer..." }) }),
|
|
217
|
-
children: /* @__PURE__ */ e(
|
|
217
|
+
children: /* @__PURE__ */ e(Oe, { open: i, onOpenChange: l, compare: t })
|
|
218
218
|
}
|
|
219
219
|
)
|
|
220
220
|
] });
|
|
@@ -271,9 +271,9 @@ function Ue({
|
|
|
271
271
|
l || s(m);
|
|
272
272
|
},
|
|
273
273
|
children: /* @__PURE__ */ n(L, { className: "sm:max-w-md", children: [
|
|
274
|
-
/* @__PURE__ */ n(
|
|
275
|
-
/* @__PURE__ */ e(
|
|
276
|
-
/* @__PURE__ */ n(
|
|
274
|
+
/* @__PURE__ */ n(z, { children: [
|
|
275
|
+
/* @__PURE__ */ e(P, { children: "Restore Revision" }),
|
|
276
|
+
/* @__PURE__ */ n($, { children: [
|
|
277
277
|
"You are about to restore to revision ",
|
|
278
278
|
a.uid.substring(0, 8),
|
|
279
279
|
" from",
|
|
@@ -320,9 +320,9 @@ function Fe({
|
|
|
320
320
|
l || s(m);
|
|
321
321
|
},
|
|
322
322
|
children: /* @__PURE__ */ n(L, { className: "sm:max-w-md", children: [
|
|
323
|
-
/* @__PURE__ */ n(
|
|
324
|
-
/* @__PURE__ */ e(
|
|
325
|
-
/* @__PURE__ */ n(
|
|
323
|
+
/* @__PURE__ */ n(z, { children: [
|
|
324
|
+
/* @__PURE__ */ e(P, { children: "Delete Revision" }),
|
|
325
|
+
/* @__PURE__ */ n($, { children: [
|
|
326
326
|
"You are about to delete revision ",
|
|
327
327
|
a.uid.substring(0, 8),
|
|
328
328
|
" from",
|
|
@@ -349,7 +349,7 @@ function Fe({
|
|
|
349
349
|
}
|
|
350
350
|
function Je({ isOpen: t }) {
|
|
351
351
|
var T, _;
|
|
352
|
-
const [s, a] = v.useState([]), [i, l] = v.useState(null), [d, u] = v.useState(!1), [m, o] = v.useState(!1), { data: r } = q(), { data: f, isFetching: S, error: h, refetch: x } = Ce(r == null ? void 0 : r.id), { mutate: W, isPending: Y } = Ae(), { mutate: B, isPending: X } = Ie(), Z =
|
|
352
|
+
const [s, a] = v.useState([]), [i, l] = v.useState(null), [d, u] = v.useState(!1), [m, o] = v.useState(!1), { data: r } = q(), { data: f, isFetching: S, error: h, refetch: x } = Ce(r == null ? void 0 : r.id), { mutate: W, isPending: Y } = Ae(), { mutate: B, isPending: X } = Ie(), Z = O(), { selectedLang: ee, fallbackLang: te } = ie(), ne = ee || te;
|
|
353
353
|
F(() => a([]), [r == null ? void 0 : r.id]);
|
|
354
354
|
const ae = (c) => {
|
|
355
355
|
i && B(
|
|
@@ -362,7 +362,7 @@ function Je({ isOpen: t }) {
|
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
);
|
|
365
|
-
},
|
|
365
|
+
}, k = (c) => {
|
|
366
366
|
l(c), u(!0);
|
|
367
367
|
}, M = (c) => {
|
|
368
368
|
l(c), o(!0);
|
|
@@ -389,14 +389,14 @@ function Je({ isOpen: t }) {
|
|
|
389
389
|
] }),
|
|
390
390
|
S ? /* @__PURE__ */ e(Me, {}) : h ? /* @__PURE__ */ e("div", { className: "p-4 text-center text-sm text-muted-foreground", children: "Failed to load revisions. Please try again." }) : /* @__PURE__ */ n("div", { className: "mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2", children: [
|
|
391
391
|
/* @__PURE__ */ e(Te, { lang: ne, compare: s, setCompare: a, pageId: r == null ? void 0 : r.id }),
|
|
392
|
-
/* @__PURE__ */ e(
|
|
392
|
+
/* @__PURE__ */ e(ke, { compare: s, setCompare: a }),
|
|
393
393
|
(T = f == null ? void 0 : f.filter((c) => c.uid === "current")) == null ? void 0 : T.map((c, E) => /* @__PURE__ */ e(
|
|
394
394
|
V,
|
|
395
395
|
{
|
|
396
396
|
pageId: r == null ? void 0 : r.id,
|
|
397
397
|
revision: c,
|
|
398
398
|
isLatest: !0,
|
|
399
|
-
onRestore: () =>
|
|
399
|
+
onRestore: () => k(c),
|
|
400
400
|
onDelete: () => M(c),
|
|
401
401
|
revisionNumber: E,
|
|
402
402
|
compare: s,
|
|
@@ -410,7 +410,7 @@ function Je({ isOpen: t }) {
|
|
|
410
410
|
pageId: r == null ? void 0 : r.id,
|
|
411
411
|
revision: c,
|
|
412
412
|
isLatest: c.uid === "current",
|
|
413
|
-
onRestore: () =>
|
|
413
|
+
onRestore: () => k(c),
|
|
414
414
|
onDelete: () => M(c),
|
|
415
415
|
revisionNumber: E + 1,
|
|
416
416
|
compare: s,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-Pdb5tSRL.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-H-2DkGza.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-MzR4MaVE.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-C69tubC8.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;
|