@chaibuilder/pages 0.13.4 → 0.14.0
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-DpAgk_u8.cjs → 2AITGKQY-BLi5HVHf.cjs} +1 -1
- package/dist/{2AITGKQY-Dx_Cte-P.js → 2AITGKQY-iyhQ7kgG.js} +5 -5
- package/dist/{NCMVHL6D-B6lv7Umq.cjs → NCMVHL6D-CKYg8-AM.cjs} +1 -1
- package/dist/{NCMVHL6D-CT2qHOTS.js → NCMVHL6D-PLvSyK5P.js} +2 -2
- package/dist/{ZDWCUMSJ-C1vrgsti.cjs → ZDWCUMSJ-BJZ_Yi-4.cjs} +1 -1
- package/dist/{ZDWCUMSJ-W9xywtZH.js → ZDWCUMSJ-CuLkdxY-.js} +1 -1
- package/dist/add-new-language-page--ah9yzN3.cjs +1 -0
- package/dist/add-new-language-page-WM_Ve2vH.js +390 -0
- package/dist/add-new-page-Bs_NXM9x.js +30 -0
- package/dist/add-new-page-CnUo6xzd.cjs +1 -0
- package/dist/confetti.module-BuUnQuWk.cjs +2 -0
- package/dist/confetti.module-DCmCkDyV.js +409 -0
- package/dist/delete-page-Cf88UkqJ.cjs +1 -0
- package/dist/delete-page-D8xhYESu.js +38 -0
- package/dist/digital-asset-manager-BAFTqxsM.js +976 -0
- package/dist/digital-asset-manager-D_lcprwY.cjs +1 -0
- package/dist/duplicate-page-BX1gOez-.cjs +1 -0
- package/dist/duplicate-page-CqXTGmWt.js +120 -0
- package/dist/dynamic-page-selector-0TiUnfUg.js +86 -0
- package/dist/dynamic-page-selector-9JIQrcq5.cjs +1 -0
- package/dist/get-seo-defaults-9zHebckY.js +65 -0
- package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
- package/dist/image-compression-DZ9WMmyn.cjs +1 -0
- package/dist/image-compression-DsZ1oqpb.js +37 -0
- package/dist/index-D7kegQ3M.js +5153 -0
- package/dist/index-LU0FTfeN.cjs +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -22
- package/dist/index.js +20 -21
- package/dist/json-diff-viewer-Be-PVOZN.cjs +8 -0
- package/dist/json-diff-viewer-C2GK_BDh.js +258 -0
- package/dist/lang-panel-CPFS1ssC.js +218 -0
- package/dist/lang-panel-CePltxo2.cjs +1 -0
- package/dist/mark-as-template-DeB23sWR.cjs +1 -0
- package/dist/mark-as-template-jdwcgRIB.js +146 -0
- package/dist/nested-path-selector-content-D_iF9Sm3.cjs +1 -0
- package/dist/nested-path-selector-content-DvIL_EoN.js +87 -0
- package/dist/no-language-page-content-DUM4KxWu.js +35 -0
- package/dist/no-language-page-content-Dsm2H3pc.cjs +1 -0
- package/dist/page-creator-BjuYmKfc.js +796 -0
- package/dist/page-creator-DG0LwvL1.cjs +1 -0
- package/dist/page-lock-request-B9WPmFcd.cjs +1 -0
- package/dist/page-lock-request-BceB1S-X.js +64 -0
- package/dist/page-locked-by-dialog-2MULM3jh.cjs +1 -0
- package/dist/page-locked-by-dialog-BEWfFLSc.js +63 -0
- package/dist/page-manager-new-BONZN4c5.cjs +1 -0
- package/dist/page-manager-new-DV6A9WFv.js +354 -0
- package/dist/page-manager-search-and-filter-3h4URMP_.cjs +1 -0
- package/dist/page-manager-search-and-filter-DIiowi9F.js +197 -0
- package/dist/page-revisions-content-BIxeZeND.js +446 -0
- package/dist/page-revisions-content-CQbt25XX.cjs +1 -0
- package/dist/publish-pages-content-CdKHrfys.js +178 -0
- package/dist/publish-pages-content-im9dPOBM.cjs +1 -0
- package/dist/save-to-lib-DGII9CEP.js +476 -0
- package/dist/save-to-lib-DOh-850u.cjs +1 -0
- package/dist/seo-panel-2VdpoGSg.cjs +1 -0
- package/dist/seo-panel-Bxo4f-a_.js +667 -0
- package/dist/shared-json-ld-C1OewNgp.cjs +1 -0
- package/dist/shared-json-ld-gbnBFljN.js +337 -0
- package/dist/slug-input-BmcGmc_i.js +87 -0
- package/dist/slug-input-CfuQV97Z.cjs +1 -0
- package/dist/theme-panel-footer-D3SwHqGR.js +25 -0
- package/dist/theme-panel-footer-FrY4U8zn.cjs +1 -0
- package/dist/translation-warning-modal-DalBhNQy.js +26 -0
- package/dist/translation-warning-modal-Kctu12rQ.cjs +1 -0
- package/dist/unmark-as-template-CihtTMOb.cjs +1 -0
- package/dist/unmark-as-template-UwmCCn0u.js +38 -0
- package/dist/unpublish-page-CNwIU6AS.js +26 -0
- package/dist/unpublish-page-DzLtZcNw.cjs +1 -0
- package/dist/use-page-expand-manager-B7JtHdg5.cjs +1 -0
- package/dist/use-page-expand-manager-BCFQnVkT.js +85 -0
- package/package.json +1 -1
- package/dist/index-C4j31Yhz.js +0 -11471
- package/dist/index-DnjETHks.cjs +0 -6
- package/dist/page-revisions-content-Gx-Qf_91.cjs +0 -8
- package/dist/page-revisions-content-_-Nd4U11.js +0 -712
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { jsx as e, jsxs as h } from "react/jsx-runtime";
|
|
2
|
+
import { Dialog as V, DialogContent as _, DialogHeader as q, DialogTitle as G, Switch as $, ScrollArea as I, Button as z, Badge as P } from "@chaibuilder/sdk/ui";
|
|
3
|
+
import { formatDate as Q } from "date-fns";
|
|
4
|
+
import { startsWith as T, replace as W, isString as X, trim as Y, isArray as Z, map as ee, isPlainObject as te, mapValues as re } from "lodash-es";
|
|
5
|
+
import { FileJson as F, Loader as ne, Check as B, Copy as H } from "lucide-react";
|
|
6
|
+
import { useState as D, useMemo as A } from "react";
|
|
7
|
+
import { parseDiff as se, Diff as le, Hunk as ae } from "react-diff-view";
|
|
8
|
+
import { ai as ie, aj as oe, A as ce, ao as de } from "./index-D7kegQ3M.js";
|
|
9
|
+
import { useQuery as fe } from "@tanstack/react-query";
|
|
10
|
+
function me(t, n) {
|
|
11
|
+
const o = ie(), s = oe(), u = T(t.uid, "draft:") || T(n.uid, "live:");
|
|
12
|
+
return fe({
|
|
13
|
+
queryKey: ["revision-comparison", t.uid, n.uid],
|
|
14
|
+
queryFn: async () => {
|
|
15
|
+
if (!t.uid || !n.uid)
|
|
16
|
+
throw new Error("Both revision IDs are required for comparison");
|
|
17
|
+
const l = (f) => f === "draft" || f === "live" ? f : "revision", r = (f) => W(f.uid, `${f.label}:`, "");
|
|
18
|
+
return await s(o, {
|
|
19
|
+
action: ce.GET_COMPARE_DATA,
|
|
20
|
+
data: {
|
|
21
|
+
versions: {
|
|
22
|
+
version1: { type: l(t.label), id: r(t) },
|
|
23
|
+
version2: { type: l(n.label), id: r(n) }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
enabled: !!t.uid && !!n.uid,
|
|
29
|
+
staleTime: u ? 0 : 1 / 0
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const he = ({ version: t }) => {
|
|
33
|
+
const n = t == null ? void 0 : t.item, { data: o } = de(n == null ? void 0 : n.currentEditor), s = t.label === "live", u = t.label === "draft";
|
|
34
|
+
return /* @__PURE__ */ h(
|
|
35
|
+
"span",
|
|
36
|
+
{
|
|
37
|
+
className: `flex items-center gap-x-2 rounded border bg-white px-2 text-xs shadow-lg ${s ? "border-green-500/30" : u ? "border-amber-500/30" : "border-purple-500/30"}`,
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ e(
|
|
40
|
+
"div",
|
|
41
|
+
{
|
|
42
|
+
className: "h-full items-center rounded px-1.5 py-0.5 font-medium capitalize" + (s ? " bg-green-500 text-green-50" : u ? " bg-amber-500 text-amber-50" : " bg-purple-500 text-purple-50"),
|
|
43
|
+
children: t.label
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
/* @__PURE__ */ h("div", { className: "py-1 text-xs font-light leading-none text-gray-800", children: [
|
|
47
|
+
/* @__PURE__ */ h("div", { children: [
|
|
48
|
+
/* @__PURE__ */ e("span", { className: "font-light opacity-90", children: u ? "Currently editing" : "Published by" }),
|
|
49
|
+
!u && /* @__PURE__ */ e("span", { className: "pl-1 font-medium", children: (o == null ? void 0 : o.name) || "Unknown" })
|
|
50
|
+
] }),
|
|
51
|
+
/* @__PURE__ */ e("div", { className: "text-[10px] leading-tight", children: Q(n.createdAt, "dd MMM yyyy, h:mm a") })
|
|
52
|
+
] })
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}, K = ({ version: t }) => /* @__PURE__ */ e(he, { version: t });
|
|
57
|
+
function ue(t, n, o = "data.json") {
|
|
58
|
+
const s = JSON.stringify(t, null, 2), u = JSON.stringify(n, null, 2), l = s.split(`
|
|
59
|
+
`), r = u.split(`
|
|
60
|
+
`);
|
|
61
|
+
let d = `--- a/${o}
|
|
62
|
+
`;
|
|
63
|
+
d += `+++ b/${o}
|
|
64
|
+
`;
|
|
65
|
+
const f = [];
|
|
66
|
+
let c = 0, p = 0;
|
|
67
|
+
for (; c < l.length || p < r.length; ) {
|
|
68
|
+
const g = l[c] || "", N = r[p] || "";
|
|
69
|
+
if (g === N)
|
|
70
|
+
f.push(` ${g}`), c++, p++;
|
|
71
|
+
else {
|
|
72
|
+
let m = -1, x = -1;
|
|
73
|
+
for (let a = c + 1; a < l.length; a++)
|
|
74
|
+
if (r[p] === l[a]) {
|
|
75
|
+
m = a;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
for (let a = p + 1; a < r.length; a++)
|
|
79
|
+
if (l[c] === r[a]) {
|
|
80
|
+
x = a;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (m !== -1 && (x === -1 || m - c <= x - p)) {
|
|
84
|
+
for (let a = c; a < m; a++)
|
|
85
|
+
f.push(`-${l[a]}`);
|
|
86
|
+
c = m;
|
|
87
|
+
} else if (x !== -1) {
|
|
88
|
+
for (let a = p; a < x; a++)
|
|
89
|
+
f.push(`+${r[a]}`);
|
|
90
|
+
p = x;
|
|
91
|
+
} else
|
|
92
|
+
g && f.push(`-${g}`), N && f.push(`+${N}`), c++, p++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const y = l.length, j = r.length;
|
|
96
|
+
return d += `@@ -1,${y} +1,${j} @@
|
|
97
|
+
`, d += f.join(`
|
|
98
|
+
`) + `
|
|
99
|
+
`, d;
|
|
100
|
+
}
|
|
101
|
+
function S(t, n = !0, o = !1) {
|
|
102
|
+
if (X(t)) {
|
|
103
|
+
const s = Y(t);
|
|
104
|
+
if (T(s, "{") || T(s, "[") || n && (s === "true" || s === "false" || s === "null" || /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(s)))
|
|
105
|
+
try {
|
|
106
|
+
const l = JSON.parse(s);
|
|
107
|
+
return S(l, n, o);
|
|
108
|
+
} catch {
|
|
109
|
+
if (o)
|
|
110
|
+
throw new Error(`Invalid JSON string: ${s}`);
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
return t;
|
|
114
|
+
}
|
|
115
|
+
return Z(t) ? ee(t, (s) => S(s, n, o)) : te(t) ? re(t, (s) => S(s, n, o)) : t;
|
|
116
|
+
}
|
|
117
|
+
const pe = (t) => {
|
|
118
|
+
switch (t) {
|
|
119
|
+
case "blocks":
|
|
120
|
+
return "Blocks";
|
|
121
|
+
case "seo":
|
|
122
|
+
return "SEO";
|
|
123
|
+
case "tracking":
|
|
124
|
+
return "Tracking";
|
|
125
|
+
default:
|
|
126
|
+
return t;
|
|
127
|
+
}
|
|
128
|
+
}, ge = (t, n) => {
|
|
129
|
+
if (!t || !n) return [{ key: "blocks", label: "Blocks" }];
|
|
130
|
+
const o = Object.keys(t), s = Object.keys(n);
|
|
131
|
+
return o.filter((r) => s.includes(r)).map((r) => ({ key: r, label: pe(r) })).filter((r) => r.key.length > 0);
|
|
132
|
+
}, xe = (t, n = 3) => {
|
|
133
|
+
const o = /* @__PURE__ */ new Set();
|
|
134
|
+
t.map((r, d) => ({ change: r, index: d })).filter(({ change: r }) => r.type !== "normal").map(({ index: r }) => r).forEach((r) => {
|
|
135
|
+
const d = Math.max(0, r - n), f = Math.min(t.length - 1, r + n);
|
|
136
|
+
for (let c = d; c <= f; c++)
|
|
137
|
+
o.add(c);
|
|
138
|
+
});
|
|
139
|
+
const u = [];
|
|
140
|
+
let l = -1;
|
|
141
|
+
return t.forEach((r, d) => {
|
|
142
|
+
if (o.has(d)) {
|
|
143
|
+
if (l !== -1 && d - l > 1) {
|
|
144
|
+
const f = t[l].lineNumber != null ? t[l].lineNumber + 1 : l + 2, c = t[d].lineNumber != null ? t[d].lineNumber - 1 : d;
|
|
145
|
+
u.push({
|
|
146
|
+
content: /* @__PURE__ */ e(P, { className: "pointer-events-none w-60 -translate-x-1/2 cursor-default border-none bg-transparent py-1 shadow-none", children: /* @__PURE__ */ h("span", { className: "rounded border border-border bg-muted px-3 py-1 text-xs font-light leading-none text-muted-foreground", children: [
|
|
147
|
+
"No changes from ",
|
|
148
|
+
f,
|
|
149
|
+
" to ",
|
|
150
|
+
c,
|
|
151
|
+
" line"
|
|
152
|
+
] }) })
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
u.push(r), l = d;
|
|
156
|
+
}
|
|
157
|
+
}), u;
|
|
158
|
+
};
|
|
159
|
+
function Te({ open: t, compare: n, onOpenChange: o }) {
|
|
160
|
+
const s = n[0], u = n[1], [l, r] = D(null), [d, f] = D("split"), [c, p] = D(!1), [y, j] = D(!0), [g, N] = D("blocks"), { data: m, isLoading: x } = me(s, u), { leftData: a, rightData: w, options: U } = A(() => {
|
|
161
|
+
var b, R;
|
|
162
|
+
const i = (b = m == null ? void 0 : m.version1) == null ? void 0 : b[g], v = (R = m == null ? void 0 : m.version2) == null ? void 0 : R[g], k = S(i), C = S(v), J = ge(m == null ? void 0 : m.version1, m == null ? void 0 : m.version2);
|
|
163
|
+
return { leftData: k, rightData: C, options: J };
|
|
164
|
+
}, [m, g]), O = A(() => !a || !w ? "" : ue(a, w), [a, w]), E = A(() => {
|
|
165
|
+
if (!O) return [];
|
|
166
|
+
try {
|
|
167
|
+
return se(O);
|
|
168
|
+
} catch (i) {
|
|
169
|
+
return console.error("Failed to parse diff:", i), [];
|
|
170
|
+
}
|
|
171
|
+
}, [O]), L = async (i, v) => {
|
|
172
|
+
try {
|
|
173
|
+
await navigator.clipboard.writeText(JSON.stringify(i, null, 2)), r(v), setTimeout(() => r(null), 2e3);
|
|
174
|
+
} catch (k) {
|
|
175
|
+
console.error("Failed to copy:", k);
|
|
176
|
+
}
|
|
177
|
+
}, M = (i) => JSON.stringify(i, null, 2);
|
|
178
|
+
return /* @__PURE__ */ e(V, { open: t, onOpenChange: o, children: /* @__PURE__ */ h(_, { className: "flex h-[90vh] w-[95vw] max-w-[1900px] flex-col p-6", children: [
|
|
179
|
+
/* @__PURE__ */ e(q, { className: "pb-4 pt-0", children: /* @__PURE__ */ h(G, { className: "flex items-center justify-between gap-2 leading-none", children: [
|
|
180
|
+
/* @__PURE__ */ h("div", { className: "flex items-center gap-2", children: [
|
|
181
|
+
/* @__PURE__ */ e(F, { className: "h-5 w-5" }),
|
|
182
|
+
"Compare",
|
|
183
|
+
"",
|
|
184
|
+
U.map((i) => /* @__PURE__ */ e(
|
|
185
|
+
"div",
|
|
186
|
+
{
|
|
187
|
+
className: `cursor-pointer rounded-full border px-2.5 py-1 text-xs leading-none ${g === i.key ? "border-blue-500 bg-blue-500 text-white" : "border-gray-600 text-gray-600 hover:bg-gray-200"}`,
|
|
188
|
+
onClick: () => N(i.key),
|
|
189
|
+
children: i.label
|
|
190
|
+
},
|
|
191
|
+
i.key
|
|
192
|
+
))
|
|
193
|
+
] }),
|
|
194
|
+
/* @__PURE__ */ e("div", { className: "flex flex-1 items-center justify-end pr-8", children: /* @__PURE__ */ h("div", { className: "flex w-max items-center justify-end gap-2 rounded-md border px-1.5 py-1", children: [
|
|
195
|
+
/* @__PURE__ */ h("div", { className: "flex items-center gap-2 px-2 py-1", children: [
|
|
196
|
+
/* @__PURE__ */ e(
|
|
197
|
+
$,
|
|
198
|
+
{
|
|
199
|
+
disabled: c,
|
|
200
|
+
checked: c ? !0 : d === "split",
|
|
201
|
+
onCheckedChange: (i) => f(i ? "split" : "unified")
|
|
202
|
+
}
|
|
203
|
+
),
|
|
204
|
+
/* @__PURE__ */ e("label", { className: "text-sm", children: "Split View" })
|
|
205
|
+
] }),
|
|
206
|
+
/* @__PURE__ */ h("div", { className: "flex items-center gap-2 px-2 py-1", children: [
|
|
207
|
+
/* @__PURE__ */ e($, { checked: c, onCheckedChange: (i) => p(i) }),
|
|
208
|
+
/* @__PURE__ */ e("label", { className: "text-sm", children: "Show Raw Data" })
|
|
209
|
+
] }),
|
|
210
|
+
/* @__PURE__ */ h("div", { className: "flex items-center gap-2 px-2 py-1", children: [
|
|
211
|
+
/* @__PURE__ */ e($, { checked: y, onCheckedChange: (i) => j(i) }),
|
|
212
|
+
/* @__PURE__ */ e("label", { className: "text-sm", children: "Hide Common Data" })
|
|
213
|
+
] })
|
|
214
|
+
] }) })
|
|
215
|
+
] }) }),
|
|
216
|
+
x ? /* @__PURE__ */ e("div", { className: "flex h-full w-full items-center justify-center", children: /* @__PURE__ */ e(ne, { className: "h-6 w-6 animate-spin text-primary" }) }) : /* @__PURE__ */ e("div", { className: "flex min-h-0 flex-1 flex-col", children: /* @__PURE__ */ h("div", { className: "relative min-h-0 flex-1", children: [
|
|
217
|
+
/* @__PURE__ */ h("div", { className: "absolute -top-5 z-50 mt-0.5 flex w-full items-center justify-between gap-2", children: [
|
|
218
|
+
/* @__PURE__ */ e("div", { className: "flex w-1/2 items-center justify-center gap-2", children: /* @__PURE__ */ e(K, { version: s }) }),
|
|
219
|
+
/* @__PURE__ */ e("div", { className: "flex w-1/2 items-center justify-center gap-2", children: /* @__PURE__ */ e(K, { version: u }) })
|
|
220
|
+
] }),
|
|
221
|
+
c ? /* @__PURE__ */ h("div", { className: "grid h-full grid-cols-2 gap-3 rounded-lg border", children: [
|
|
222
|
+
/* @__PURE__ */ h("div", { className: "relative flex min-h-0 flex-col border-r", children: [
|
|
223
|
+
/* @__PURE__ */ e("div", { className: "absolute -top-4 right-4 z-50", children: /* @__PURE__ */ h(z, { variant: "outline", size: "sm", onClick: () => L(a, "left"), children: [
|
|
224
|
+
l === "left" ? /* @__PURE__ */ e(B, { className: "text-green-500" }) : /* @__PURE__ */ e(H, {}),
|
|
225
|
+
"Copy"
|
|
226
|
+
] }) }),
|
|
227
|
+
/* @__PURE__ */ e(I, { className: "flex-1 rounded-lg bg-slate-50 p-3 dark:bg-slate-900", children: /* @__PURE__ */ e("pre", { className: "whitespace-pre-wrap font-mono text-xs", children: M(a) }) })
|
|
228
|
+
] }),
|
|
229
|
+
/* @__PURE__ */ h("div", { className: "relative flex min-h-0 flex-col", children: [
|
|
230
|
+
/* @__PURE__ */ e("div", { className: "absolute -top-4 right-4 z-50", children: /* @__PURE__ */ h(z, { variant: "outline", size: "sm", onClick: () => L(w, "right"), children: [
|
|
231
|
+
l === "right" ? /* @__PURE__ */ e(B, { className: "text-green-500" }) : /* @__PURE__ */ e(H, {}),
|
|
232
|
+
"Copy"
|
|
233
|
+
] }) }),
|
|
234
|
+
/* @__PURE__ */ e(I, { className: "flex-1 rounded-lg bg-slate-50 p-3 dark:bg-slate-900", children: /* @__PURE__ */ e("pre", { className: "whitespace-pre-wrap font-mono text-xs", children: M(w) }) })
|
|
235
|
+
] })
|
|
236
|
+
] }) : /* @__PURE__ */ e(I, { className: "h-full overflow-y-auto rounded-lg border bg-slate-50 text-xs dark:bg-slate-900", children: E.length === 0 ? /* @__PURE__ */ e("div", { className: "flex h-full items-center justify-center p-6", children: /* @__PURE__ */ h("div", { className: "text-center text-muted-foreground", children: [
|
|
237
|
+
/* @__PURE__ */ e(F, { className: "mx-auto mb-2 h-8 w-8 opacity-50" }),
|
|
238
|
+
/* @__PURE__ */ e("p", { children: "No differences found or unable to parse diff" })
|
|
239
|
+
] }) }) : /* @__PURE__ */ e("div", { children: E.map((i, v) => /* @__PURE__ */ e("div", { className: "relative mb-4", children: /* @__PURE__ */ e(
|
|
240
|
+
le,
|
|
241
|
+
{
|
|
242
|
+
viewType: d,
|
|
243
|
+
diffType: i.type,
|
|
244
|
+
hunks: i.hunks,
|
|
245
|
+
className: "rounded-lg text-xs",
|
|
246
|
+
children: (k) => k.map((C, J) => {
|
|
247
|
+
const b = y ? xe(C.changes) : C.changes;
|
|
248
|
+
return (b == null ? void 0 : b.length) === 0 ? /* @__PURE__ */ e("div", { className: "absolute h-full w-full border-l pt-64 text-center font-sans text-sm", children: /* @__PURE__ */ e("span", { children: "No difference found" }) }) : /* @__PURE__ */ e(ae, { hunk: { ...C, changes: b } }, J);
|
|
249
|
+
})
|
|
250
|
+
},
|
|
251
|
+
y ? "hide-common-data" : "show-common-data"
|
|
252
|
+
) }, v)) }) })
|
|
253
|
+
] }) })
|
|
254
|
+
] }) });
|
|
255
|
+
}
|
|
256
|
+
export {
|
|
257
|
+
Te as default
|
|
258
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { jsx as e, jsxs as s, Fragment as $ } from "react/jsx-runtime";
|
|
2
|
+
import { ar as M, h as k, L as I, as as j, g as F, ak as H, e as O, at as g, au as c, C as x } from "./index-D7kegQ3M.js";
|
|
3
|
+
import { Dialog as W, DialogContent as B, DialogHeader as q, DialogTitle as R, DialogDescription as J, Alert as K, Label as Q, Input as V, DialogFooter as X, Button as A, DropdownMenu as Y, DropdownMenuTrigger as Z, DropdownMenuContent as ee, DropdownMenuItem as b } from "@chaibuilder/sdk/ui";
|
|
4
|
+
import { find as G, startsWith as w, isEqual as se, filter as ae, get as D, map as le, isEmpty as ne } from "lodash-es";
|
|
5
|
+
import { AlertCircle as te, StarIcon as ie, MoreHorizontal as re, PencilIcon as ce, Power as oe, TrashIcon as de } from "lucide-react";
|
|
6
|
+
import { useState as S, lazy as U, useMemo as me, Suspense as L } from "react";
|
|
7
|
+
import { toast as ue } from "sonner";
|
|
8
|
+
import { useLanguages as he } from "@chaibuilder/sdk";
|
|
9
|
+
import { useAtom as ge } from "jotai";
|
|
10
|
+
const pe = ({
|
|
11
|
+
page: a,
|
|
12
|
+
onClose: p
|
|
13
|
+
}) => {
|
|
14
|
+
const [t, v] = S(a.slug || ""), { mutate: N, isPending: f } = M(), { data: n } = k(), i = G(n, { key: a == null ? void 0 : a.pageType }), y = (d) => {
|
|
15
|
+
if (d.preventDefault(), !(a != null && a.primaryPage) && Object.keys(I).some((h) => t === `/${h}` || w(t, `/${h}/`))) {
|
|
16
|
+
ue.error("Error", {
|
|
17
|
+
description: "Slugs cannot start with a language code for primary page"
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
N({ ...a, slug: t }, { onSuccess: p });
|
|
22
|
+
}, o = (a == null ? void 0 : a.lang) || "";
|
|
23
|
+
return /* @__PURE__ */ e(W, { open: !!a, onOpenChange: p, children: /* @__PURE__ */ s(B, { children: [
|
|
24
|
+
/* @__PURE__ */ s(q, { children: [
|
|
25
|
+
/* @__PURE__ */ e(R, { children: "Change Slug" }),
|
|
26
|
+
/* @__PURE__ */ e(J, { className: "text-xs", children: /* @__PURE__ */ s(K, { variant: "destructive", className: "mt-2", children: [
|
|
27
|
+
/* @__PURE__ */ e(te, { className: "h-4 w-4" }),
|
|
28
|
+
"Changing the slug may have impact on your SEO. Please proceed with caution."
|
|
29
|
+
] }) })
|
|
30
|
+
] }),
|
|
31
|
+
/* @__PURE__ */ s("form", { onSubmit: y, children: [
|
|
32
|
+
/* @__PURE__ */ s("div", { className: "space-y-4 py-4 text-sm ", children: [
|
|
33
|
+
/* @__PURE__ */ s("div", { className: "space-y-1", children: [
|
|
34
|
+
/* @__PURE__ */ s("div", { children: [
|
|
35
|
+
/* @__PURE__ */ e("span", { children: "Type:" }),
|
|
36
|
+
/* @__PURE__ */ s("span", { className: "font-medium text-gray-600", children: [
|
|
37
|
+
" ",
|
|
38
|
+
(i == null ? void 0 : i.name) || (a == null ? void 0 : a.pageType)
|
|
39
|
+
] })
|
|
40
|
+
] }),
|
|
41
|
+
/* @__PURE__ */ s("div", { children: [
|
|
42
|
+
/* @__PURE__ */ e("span", { children: "Name:" }),
|
|
43
|
+
/* @__PURE__ */ s("span", { className: "font-medium text-gray-600", children: [
|
|
44
|
+
" ",
|
|
45
|
+
a.name
|
|
46
|
+
] })
|
|
47
|
+
] })
|
|
48
|
+
] }),
|
|
49
|
+
/* @__PURE__ */ s("div", { className: "space-y-1", children: [
|
|
50
|
+
/* @__PURE__ */ s(Q, { htmlFor: "slug", className: "text-right", children: [
|
|
51
|
+
"Slug",
|
|
52
|
+
" ",
|
|
53
|
+
/* @__PURE__ */ s("small", { className: "font-light text-gray-500", children: [
|
|
54
|
+
"Slug should start with /",
|
|
55
|
+
o
|
|
56
|
+
] })
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ e(
|
|
59
|
+
V,
|
|
60
|
+
{
|
|
61
|
+
id: "slug",
|
|
62
|
+
value: t,
|
|
63
|
+
onChange: (d) => {
|
|
64
|
+
const m = d.target.value;
|
|
65
|
+
w(m, `/${o}`) && v(m);
|
|
66
|
+
},
|
|
67
|
+
className: "col-span-3",
|
|
68
|
+
required: !0,
|
|
69
|
+
pattern: "^/.*",
|
|
70
|
+
title: "Slug must start with /",
|
|
71
|
+
placeholder: "Enter page slug"
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
] })
|
|
75
|
+
] }),
|
|
76
|
+
/* @__PURE__ */ e(X, { children: /* @__PURE__ */ e(
|
|
77
|
+
A,
|
|
78
|
+
{
|
|
79
|
+
type: "submit",
|
|
80
|
+
disabled: f || !w(t, `/${o}`) || se(a == null ? void 0 : a.slug, t),
|
|
81
|
+
children: f ? "Changing..." : "Change Slug"
|
|
82
|
+
}
|
|
83
|
+
) })
|
|
84
|
+
] })
|
|
85
|
+
] }) });
|
|
86
|
+
}, Ne = U(() => import("./delete-page-D8xhYESu.js")), fe = U(() => import("./unpublish-page-CNwIU6AS.js")), Ae = () => {
|
|
87
|
+
const [, a] = ge(j), { selectedLang: p, fallbackLang: t, setSelectedLang: v } = he(), { data: N, isFetching: f } = F(), { data: n } = H(), { data: i } = k(), y = me(() => {
|
|
88
|
+
const l = i == null ? void 0 : i.find((u) => u.key === (n == null ? void 0 : n.pageType));
|
|
89
|
+
return n != null && n.dynamic ? l == null ? void 0 : l.dynamicSlug : "";
|
|
90
|
+
}, [i, n == null ? void 0 : n.pageType, n == null ? void 0 : n.dynamic]), [o, d] = S(null), [m, C] = S(null), [h, _] = S(null), { data: P } = O(), z = ae(
|
|
91
|
+
D(P, "languages") || ["en"],
|
|
92
|
+
(l) => !G(N, { lang: l }) && l !== D(P, "fallbackLang")
|
|
93
|
+
);
|
|
94
|
+
return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
|
|
95
|
+
/* @__PURE__ */ e("ul", { className: "space-y-2", children: f ? /* @__PURE__ */ s("div", { className: "w-full space-y-3 py-4", children: [
|
|
96
|
+
/* @__PURE__ */ e("div", { className: "h-8 w-full animate-pulse rounded bg-gray-300" }),
|
|
97
|
+
/* @__PURE__ */ e("div", { className: "h-8 w-full animate-pulse rounded bg-gray-300" }),
|
|
98
|
+
/* @__PURE__ */ e("div", { className: "h-8 w-full animate-pulse rounded bg-gray-300" })
|
|
99
|
+
] }) : le(N, (l) => {
|
|
100
|
+
const u = l.lang, E = l.slug, T = !l.primaryPage;
|
|
101
|
+
return /* @__PURE__ */ s($, { children: [
|
|
102
|
+
/* @__PURE__ */ s(
|
|
103
|
+
"li",
|
|
104
|
+
{
|
|
105
|
+
className: `flex w-full cursor-pointer items-center justify-between rounded p-2 text-slate-500 ${u === p ? "bg-gray-200" : "hover:bg-gray-100"}`,
|
|
106
|
+
onClick: () => v(u),
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ s("div", { className: "flex-1 gap-x-3", children: [
|
|
109
|
+
/* @__PURE__ */ s("div", { className: "flex items-center gap-x-2 text-[13px] text-slate-800", children: [
|
|
110
|
+
/* @__PURE__ */ e("div", { className: `h-2.5 w-2.5 rounded-full ${l.online ? "bg-green-300" : "bg-gray-300"}` }),
|
|
111
|
+
D(I, T ? t : u, u)
|
|
112
|
+
] }),
|
|
113
|
+
/* @__PURE__ */ s("div", { children: [
|
|
114
|
+
E && /* @__PURE__ */ s("div", { className: "text-[11px] font-light text-slate-600", children: [
|
|
115
|
+
"Slug: ",
|
|
116
|
+
/* @__PURE__ */ e("b", { className: "font-mono font-medium", children: y ? `${E}/${y}` : E })
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ s("div", { className: "text-[11px] font-light text-slate-600", children: [
|
|
119
|
+
"Name:",
|
|
120
|
+
/* @__PURE__ */ s("b", { className: "font-medium", children: [
|
|
121
|
+
" ",
|
|
122
|
+
l.name,
|
|
123
|
+
" "
|
|
124
|
+
] })
|
|
125
|
+
] })
|
|
126
|
+
] })
|
|
127
|
+
] }),
|
|
128
|
+
T ? /* @__PURE__ */ s("div", { className: "flex items-center gap-x-1 text-[11px] text-orange-500", children: [
|
|
129
|
+
/* @__PURE__ */ e(ie, { fill: "orange", className: "h-3 w-3" }),
|
|
130
|
+
/* @__PURE__ */ e("b", { children: " Primary" })
|
|
131
|
+
] }) : /* @__PURE__ */ e("div", { className: "flex items-center gap-x-3", children: /* @__PURE__ */ e(
|
|
132
|
+
g,
|
|
133
|
+
{
|
|
134
|
+
permissions: [
|
|
135
|
+
c.EDIT_PAGE,
|
|
136
|
+
c.DELETE_PAGE,
|
|
137
|
+
c.UNPUBLISH_PAGE
|
|
138
|
+
],
|
|
139
|
+
children: /* @__PURE__ */ s(Y, { children: [
|
|
140
|
+
/* @__PURE__ */ e(Z, { asChild: !0, onClick: (r) => r.stopPropagation(), children: /* @__PURE__ */ e(A, { variant: "ghost", size: "sm", className: "h-8 w-8 p-0", children: /* @__PURE__ */ e(re, { className: "h-4 w-4" }) }) }),
|
|
141
|
+
/* @__PURE__ */ s(ee, { align: "end", className: "z-[9999] text-sm", children: [
|
|
142
|
+
/* @__PURE__ */ e(g, { permissions: [c.EDIT_PAGE], children: /* @__PURE__ */ s(
|
|
143
|
+
b,
|
|
144
|
+
{
|
|
145
|
+
className: "flex cursor-pointer items-center gap-2",
|
|
146
|
+
onClick: (r) => {
|
|
147
|
+
r.stopPropagation(), a({
|
|
148
|
+
edit: !0,
|
|
149
|
+
id: l.id,
|
|
150
|
+
primaryPage: l.primaryPage
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
children: [
|
|
154
|
+
/* @__PURE__ */ e(ce, { className: "size-3" }),
|
|
155
|
+
x.EDIT
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
) }),
|
|
159
|
+
/* @__PURE__ */ e(g, { permissions: [c.UNPUBLISH_PAGE], children: (l == null ? void 0 : l.online) && /* @__PURE__ */ s(
|
|
160
|
+
b,
|
|
161
|
+
{
|
|
162
|
+
className: "flex cursor-pointer items-center gap-2",
|
|
163
|
+
onClick: (r) => {
|
|
164
|
+
r.stopPropagation(), C(l);
|
|
165
|
+
},
|
|
166
|
+
children: [
|
|
167
|
+
/* @__PURE__ */ e(oe, { className: "size-3" }),
|
|
168
|
+
x.UNPUBLISH
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
) }),
|
|
172
|
+
/* @__PURE__ */ e(g, { permissions: [c.DELETE_PAGE], children: /* @__PURE__ */ s(
|
|
173
|
+
b,
|
|
174
|
+
{
|
|
175
|
+
className: "flex cursor-pointer items-center gap-2",
|
|
176
|
+
onClick: (r) => {
|
|
177
|
+
r.stopPropagation(), d(l);
|
|
178
|
+
},
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ e(de, { className: "size-3" }),
|
|
181
|
+
x.DELETE
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
) })
|
|
185
|
+
] })
|
|
186
|
+
] })
|
|
187
|
+
}
|
|
188
|
+
) })
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
l.id
|
|
192
|
+
),
|
|
193
|
+
/* @__PURE__ */ e("div", { className: "h-1 w-full border-b" })
|
|
194
|
+
] });
|
|
195
|
+
}) }),
|
|
196
|
+
/* @__PURE__ */ e(g, { permissions: [c.ADD_PAGE], children: /* @__PURE__ */ e("div", { className: "flex w-full justify-center", children: /* @__PURE__ */ e(
|
|
197
|
+
A,
|
|
198
|
+
{
|
|
199
|
+
variant: "default",
|
|
200
|
+
size: "sm",
|
|
201
|
+
disabled: ne(z),
|
|
202
|
+
onClick: () => {
|
|
203
|
+
a({
|
|
204
|
+
primaryPage: n == null ? void 0 : n.id,
|
|
205
|
+
edit: !1
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
children: x.ADD_NEW_LANGUAGE
|
|
209
|
+
}
|
|
210
|
+
) }) }),
|
|
211
|
+
o && /* @__PURE__ */ e(L, { children: /* @__PURE__ */ e(Ne, { page: o, onClose: () => d(null) }) }),
|
|
212
|
+
m && /* @__PURE__ */ e(L, { children: /* @__PURE__ */ e(fe, { page: m, onClose: () => C(null) }) }),
|
|
213
|
+
h && /* @__PURE__ */ e(L, { children: /* @__PURE__ */ e(pe, { page: h, onClose: () => _(null) }) })
|
|
214
|
+
] });
|
|
215
|
+
};
|
|
216
|
+
export {
|
|
217
|
+
Ae as default
|
|
218
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-LU0FTfeN.cjs"),i=require("@chaibuilder/sdk/ui"),a=require("lodash-es"),g=require("lucide-react"),r=require("react"),w=require("sonner"),D=require("@chaibuilder/sdk"),T=require("jotai"),L=({page:n,onClose:S})=>{const[c,y]=r.useState(n.slug||""),{mutate:N,isPending:p}=s.useChangeSlug(),{data:l}=s.usePageTypes(),o=a.find(l,{key:n==null?void 0:n.pageType}),E=m=>{if(m.preventDefault(),!(n!=null&&n.primaryPage)&&Object.keys(s.LANGUAGES).some(j=>c===`/${j}`||a.startsWith(c,`/${j}/`))){w.toast.error("Error",{description:"Slugs cannot start with a language code for primary page"});return}N({...n,slug:c},{onSuccess:S})},u=(n==null?void 0:n.lang)||"";return e.jsx(i.Dialog,{open:!!n,onOpenChange:S,children:e.jsxs(i.DialogContent,{children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Change Slug"}),e.jsx(i.DialogDescription,{className:"text-xs",children:e.jsxs(i.Alert,{variant:"destructive",className:"mt-2",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),"Changing the slug may have impact on your SEO. Please proceed with caution."]})})]}),e.jsxs("form",{onSubmit:E,children:[e.jsxs("div",{className:"space-y-4 py-4 text-sm ",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Type:"}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",(o==null?void 0:o.name)||(n==null?void 0:n.pageType)]})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Name:"}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",n.name]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(i.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",e.jsxs("small",{className:"font-light text-gray-500",children:["Slug should start with /",u]})]}),e.jsx(i.Input,{id:"slug",value:c,onChange:m=>{const h=m.target.value;a.startsWith(h,`/${u}`)&&y(h)},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),e.jsx(i.DialogFooter,{children:e.jsx(i.Button,{type:"submit",disabled:p||!a.startsWith(c,`/${u}`)||a.isEqual(n==null?void 0:n.slug,c),children:p?"Changing...":"Change Slug"})})]})]})})},G=r.lazy(()=>Promise.resolve().then(()=>require("./delete-page-Cf88UkqJ.cjs"))),k=r.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-DzLtZcNw.cjs"))),M=()=>{const[,n]=T.useAtom(s.addNewLangAtom),{selectedLang:S,fallbackLang:c,setSelectedLang:y}=D.useLanguages(),{data:N,isFetching:p}=s.useLanguagePages(),{data:l}=s.useCurrentPage(),{data:o}=s.usePageTypes(),E=r.useMemo(()=>{const t=o==null?void 0:o.find(x=>x.key===(l==null?void 0:l.pageType));return l!=null&&l.dynamic?t==null?void 0:t.dynamicSlug:""},[o,l==null?void 0:l.pageType,l==null?void 0:l.dynamic]),[u,m]=r.useState(null),[h,f]=r.useState(null),[j,b]=r.useState(null),{data:C}=s.useWebsiteSetting(),A=a.filter(a.get(C,"languages")||["en"],t=>!a.find(N,{lang:t})&&t!==a.get(C,"fallbackLang"));return e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"space-y-2",children:p?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"})]}):a.map(N,t=>{const x=t.lang,P=t.slug,v=!t.primaryPage,I=x===S;return e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`flex w-full cursor-pointer items-center justify-between rounded p-2 text-slate-500 ${I?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>y(x),children:[e.jsxs("div",{className:"flex-1 gap-x-3",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-[13px] text-slate-800",children:[e.jsx("div",{className:`h-2.5 w-2.5 rounded-full ${t.online?"bg-green-300":"bg-gray-300"}`}),a.get(s.LANGUAGES,v?c:x,x)]}),e.jsxs("div",{children:[P&&e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Slug: ",e.jsx("b",{className:"font-mono font-medium",children:E?`${P}/${E}`:P})]}),e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Name:",e.jsxs("b",{className:"font-medium",children:[" ",t.name," "]})]})]})]}),v?e.jsxs("div",{className:"flex items-center gap-x-1 text-[11px] text-orange-500",children:[e.jsx(g.StarIcon,{fill:"orange",className:"h-3 w-3"}),e.jsx("b",{children:" Primary"})]}):e.jsx("div",{className:"flex items-center gap-x-3",children:e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.EDIT_PAGE,s.PAGES_PERMISSIONS.DELETE_PAGE,s.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:e.jsxs(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,onClick:d=>d.stopPropagation(),children:e.jsx(i.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:e.jsx(g.MoreHorizontal,{className:"h-4 w-4"})})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"z-[9999] text-sm",children:[e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.EDIT_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),n({edit:!0,id:t.id,primaryPage:t.primaryPage})},children:[e.jsx(g.PencilIcon,{className:"size-3"}),s.CONTENT.EDIT]})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:(t==null?void 0:t.online)&&e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),f(t)},children:[e.jsx(g.Power,{className:"size-3"}),s.CONTENT.UNPUBLISH]})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.DELETE_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),m(t)},children:[e.jsx(g.TrashIcon,{className:"size-3"}),s.CONTENT.DELETE]})})]})]})})})]},t.id),e.jsx("div",{className:"h-1 w-full border-b"})]})})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.ADD_PAGE],children:e.jsx("div",{className:"flex w-full justify-center",children:e.jsx(i.Button,{variant:"default",size:"sm",disabled:a.isEmpty(A),onClick:()=>{n({primaryPage:l==null?void 0:l.id,edit:!1})},children:s.CONTENT.ADD_NEW_LANGUAGE})})}),u&&e.jsx(r.Suspense,{children:e.jsx(G,{page:u,onClose:()=>m(null)})}),h&&e.jsx(r.Suspense,{children:e.jsx(k,{page:h,onClose:()=>f(null)})}),j&&e.jsx(r.Suspense,{children:e.jsx(L,{page:j,onClose:()=>b(null)})})]})};exports.default=M;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("./index-LU0FTfeN.cjs"),s=require("@chaibuilder/sdk/ui"),b=require("lodash-es"),o=require("lucide-react"),i=require("react"),y=require("sonner"),S=1*1024*1024,M=({page:n,onClose:d})=>{const[h,m]=i.useState(!1),[g,w]=i.useState(""),[l,f]=i.useState(""),[j,u]=i.useState(!1),r=i.useRef(null),k=v.useMarkAsTemplate(),{data:p}=v.usePageTypes(),x=p==null?void 0:p.find(a=>a.key===n.pageType),C=(x==null?void 0:x.name)||b.startCase(n.pageType),I=i.useCallback(a=>{var N;const c=(N=a.target.files)==null?void 0:N[0];if(c){if(c.size>S){y.toast.error("File too large",{description:`Maximum file size is 1MB. Selected file is ${(c.size/1024).toFixed(2)}KB.`}),r.current&&(r.current.value="");return}try{u(!0);const t=new FileReader;t.onloadend=()=>{f(t.result),u(!1)},t.readAsDataURL(c)}catch(t){console.error("Error reading file:",t),u(!1),y.toast.error("Failed to process image",{description:t instanceof Error?t.message:"Unknown error"})}}},[]),T=()=>{f(""),r.current&&(r.current.value="")},D=()=>{var a;(a=r.current)==null||a.click()},F=()=>{m(!0),k.mutate({page:n,name:n.name,description:g.trim()||void 0,pageType:n.pageType,...l?{previewImage:l}:{}},{onSuccess:()=>{m(!1),d()},onError:()=>{m(!1)}})};return e.jsx(s.Dialog,{open:!0,onOpenChange:d,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Mark as template"}),e.jsxs(s.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:["Are you sure you want to mark this page as a template?",e.jsx("br",{}),"Templates can be used to create new pages with the same content."]})]}),e.jsxs("div",{className:"mb-4 space-y-4 text-xs",children:[e.jsxs("div",{className:"space-y-3 rounded border bg-slate-50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.Tag,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Page Name:"}),e.jsx("span",{className:"font-semibold",children:b.startCase(n.name)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.File,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Type:"}),e.jsx("span",{className:"font-semibold",children:C})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"description",className:"text-xs font-medium",children:"Description (Optional)"}),e.jsx(s.Textarea,{id:"description",placeholder:"Describe this template's purpose",className:"mt-1 h-24 resize-none text-xs",value:g,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"previewImage",className:"text-xs font-medium",children:"Preview Image (Optional)"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input,{type:"file",id:"previewImage",ref:r,onChange:I,accept:"image/*",className:"hidden"}),e.jsx(s.Button,{type:"button",variant:"outline",onClick:D,disabled:j,className:"w-full",children:j?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(o.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),l&&e.jsx(s.Button,{type:"button",variant:"outline",size:"icon",onClick:T,children:e.jsx(o.X,{className:"h-4 w-4"})})]}),l&&e.jsx("div",{className:"aspect-video overflow-hidden rounded-md border",children:e.jsx("img",{src:l,alt:"Preview",className:"h-full max-h-[200px] w-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"max 1mb"})]})]})]}),e.jsxs(s.DialogFooter,{className:h?"pointer-events-none opacity-75":"",children:[e.jsx(s.Button,{variant:"outline",onClick:a=>{a.stopPropagation(),d()},children:"Cancel"}),e.jsx(s.Button,{variant:"default",disabled:h,onClick:F,children:"Mark as template"})]})]})})};exports.default=M;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { jsx as e, jsxs as a } from "react/jsx-runtime";
|
|
2
|
+
import { n as A, h as P } from "./index-D7kegQ3M.js";
|
|
3
|
+
import { Dialog as z, DialogContent as E, DialogHeader as L, DialogTitle as S, DialogDescription as U, Label as b, Textarea as B, Input as R, Button as o, DialogFooter as j } from "@chaibuilder/sdk/ui";
|
|
4
|
+
import { startCase as w } from "lodash-es";
|
|
5
|
+
import { Tag as O, File as X, ImageIcon as _, X as H } from "lucide-react";
|
|
6
|
+
import { useState as c, useRef as K, useCallback as Z } from "react";
|
|
7
|
+
import { toast as y } from "sonner";
|
|
8
|
+
const $ = 1 * 1024 * 1024, ee = ({ page: r, onClose: d }) => {
|
|
9
|
+
const [f, m] = c(!1), [g, k] = c(""), [i, x] = c(""), [N, p] = c(!1), n = K(null), I = A(), { data: u } = P(), h = u == null ? void 0 : u.find((t) => t.key === r.pageType), C = (h == null ? void 0 : h.name) || w(r.pageType), T = Z((t) => {
|
|
10
|
+
var v;
|
|
11
|
+
const l = (v = t.target.files) == null ? void 0 : v[0];
|
|
12
|
+
if (l) {
|
|
13
|
+
if (l.size > $) {
|
|
14
|
+
y.error("File too large", {
|
|
15
|
+
description: `Maximum file size is 1MB. Selected file is ${(l.size / 1024).toFixed(2)}KB.`
|
|
16
|
+
}), n.current && (n.current.value = "");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
p(!0);
|
|
21
|
+
const s = new FileReader();
|
|
22
|
+
s.onloadend = () => {
|
|
23
|
+
x(s.result), p(!1);
|
|
24
|
+
}, s.readAsDataURL(l);
|
|
25
|
+
} catch (s) {
|
|
26
|
+
console.error("Error reading file:", s), p(!1), y.error("Failed to process image", {
|
|
27
|
+
description: s instanceof Error ? s.message : "Unknown error"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}, []), D = () => {
|
|
32
|
+
x(""), n.current && (n.current.value = "");
|
|
33
|
+
}, F = () => {
|
|
34
|
+
var t;
|
|
35
|
+
(t = n.current) == null || t.click();
|
|
36
|
+
}, M = () => {
|
|
37
|
+
m(!0), I.mutate(
|
|
38
|
+
{
|
|
39
|
+
page: r,
|
|
40
|
+
name: r.name,
|
|
41
|
+
description: g.trim() || void 0,
|
|
42
|
+
pageType: r.pageType,
|
|
43
|
+
...i ? { previewImage: i } : {}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
onSuccess: () => {
|
|
47
|
+
m(!1), d();
|
|
48
|
+
},
|
|
49
|
+
onError: () => {
|
|
50
|
+
m(!1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
return /* @__PURE__ */ e(z, { open: !0, onOpenChange: d, children: /* @__PURE__ */ a(E, { children: [
|
|
56
|
+
/* @__PURE__ */ a(L, { children: [
|
|
57
|
+
/* @__PURE__ */ e(S, { children: "Mark as template" }),
|
|
58
|
+
/* @__PURE__ */ a(U, { className: "space-y-1 py-4 text-xs text-slate-500", children: [
|
|
59
|
+
"Are you sure you want to mark this page as a template?",
|
|
60
|
+
/* @__PURE__ */ e("br", {}),
|
|
61
|
+
"Templates can be used to create new pages with the same content."
|
|
62
|
+
] })
|
|
63
|
+
] }),
|
|
64
|
+
/* @__PURE__ */ a("div", { className: "mb-4 space-y-4 text-xs", children: [
|
|
65
|
+
/* @__PURE__ */ a("div", { className: "space-y-3 rounded border bg-slate-50 p-4", children: [
|
|
66
|
+
/* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
|
|
67
|
+
/* @__PURE__ */ e(O, { className: "h-4 w-4 text-slate-500" }),
|
|
68
|
+
/* @__PURE__ */ e("span", { className: "font-medium text-slate-500", children: "Page Name:" }),
|
|
69
|
+
/* @__PURE__ */ e("span", { className: "font-semibold", children: w(r.name) })
|
|
70
|
+
] }),
|
|
71
|
+
/* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
|
|
72
|
+
/* @__PURE__ */ e(X, { className: "h-4 w-4 text-slate-500" }),
|
|
73
|
+
/* @__PURE__ */ e("span", { className: "font-medium text-slate-500", children: "Type:" }),
|
|
74
|
+
/* @__PURE__ */ e("span", { className: "font-semibold", children: C })
|
|
75
|
+
] })
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ a("div", { children: [
|
|
78
|
+
/* @__PURE__ */ e(b, { htmlFor: "description", className: "text-xs font-medium", children: "Description (Optional)" }),
|
|
79
|
+
/* @__PURE__ */ e(
|
|
80
|
+
B,
|
|
81
|
+
{
|
|
82
|
+
id: "description",
|
|
83
|
+
placeholder: "Describe this template's purpose",
|
|
84
|
+
className: "mt-1 h-24 resize-none text-xs",
|
|
85
|
+
value: g,
|
|
86
|
+
onChange: (t) => k(t.target.value)
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
] }),
|
|
90
|
+
/* @__PURE__ */ a("div", { className: "space-y-2", children: [
|
|
91
|
+
/* @__PURE__ */ e(b, { htmlFor: "previewImage", className: "text-xs font-medium", children: "Preview Image (Optional)" }),
|
|
92
|
+
/* @__PURE__ */ a("div", { className: "space-y-2", children: [
|
|
93
|
+
/* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
|
|
94
|
+
/* @__PURE__ */ e(
|
|
95
|
+
R,
|
|
96
|
+
{
|
|
97
|
+
type: "file",
|
|
98
|
+
id: "previewImage",
|
|
99
|
+
ref: n,
|
|
100
|
+
onChange: T,
|
|
101
|
+
accept: "image/*",
|
|
102
|
+
className: "hidden"
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
/* @__PURE__ */ e(
|
|
106
|
+
o,
|
|
107
|
+
{
|
|
108
|
+
type: "button",
|
|
109
|
+
variant: "outline",
|
|
110
|
+
onClick: F,
|
|
111
|
+
disabled: N,
|
|
112
|
+
className: "w-full",
|
|
113
|
+
children: N ? /* @__PURE__ */ a("span", { className: "flex items-center gap-2", children: [
|
|
114
|
+
/* @__PURE__ */ e("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }),
|
|
115
|
+
"Uploading..."
|
|
116
|
+
] }) : /* @__PURE__ */ a("span", { className: "flex items-center gap-2", children: [
|
|
117
|
+
/* @__PURE__ */ e(_, { className: "h-4 w-4" }),
|
|
118
|
+
"Select image"
|
|
119
|
+
] })
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
i && /* @__PURE__ */ e(o, { type: "button", variant: "outline", size: "icon", onClick: D, children: /* @__PURE__ */ e(H, { className: "h-4 w-4" }) })
|
|
123
|
+
] }),
|
|
124
|
+
i && /* @__PURE__ */ e("div", { className: "aspect-video overflow-hidden rounded-md border", children: /* @__PURE__ */ e("img", { src: i, alt: "Preview", className: "h-full max-h-[200px] w-full object-contain" }) }),
|
|
125
|
+
/* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: "max 1mb" })
|
|
126
|
+
] })
|
|
127
|
+
] })
|
|
128
|
+
] }),
|
|
129
|
+
/* @__PURE__ */ a(j, { className: f ? "pointer-events-none opacity-75" : "", children: [
|
|
130
|
+
/* @__PURE__ */ e(
|
|
131
|
+
o,
|
|
132
|
+
{
|
|
133
|
+
variant: "outline",
|
|
134
|
+
onClick: (t) => {
|
|
135
|
+
t.stopPropagation(), d();
|
|
136
|
+
},
|
|
137
|
+
children: "Cancel"
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ e(o, { variant: "default", disabled: f, onClick: M, children: "Mark as template" })
|
|
141
|
+
] })
|
|
142
|
+
] }) });
|
|
143
|
+
};
|
|
144
|
+
export {
|
|
145
|
+
ee as default
|
|
146
|
+
};
|