@chaibuilder/pages 0.13.2 → 0.13.4

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.
@@ -0,0 +1,712 @@
1
+ import { jsx as e, jsxs as n, Fragment as k } from "react/jsx-runtime";
2
+ import { Dialog as X, DialogContent as Z, DialogHeader as ee, DialogTitle as te, Switch as B, ScrollArea as V, Button as v, Badge as Ne, SheetHeader as be, SheetTitle as ye, Skeleton as L, DropdownMenu as ve, DropdownMenuTrigger as we, DropdownMenuContent as Ce, DropdownMenuItem as ae, DropdownMenuSeparator as De, DialogDescription as oe, DialogFooter as ue } from "@chaibuilder/sdk/ui";
3
+ import { formatDate as Se, format as q, formatDistanceToNow as ke } from "date-fns";
4
+ import { replace as Ee, isString as Re, trim as Te, startsWith as se, isArray as Oe, map as Ie, isPlainObject as Me, mapValues as Ae, isEmpty as $e } from "lodash-es";
5
+ import { FileJson as W, Loader as je, Check as le, Copy as re, Eye as _e, MoreHorizontal as Fe, Undo2 as me, Trash as he, CloudOff as Je, Rocket as Le, Save as Ue, X as Ve } from "lucide-react";
6
+ import * as U from "react";
7
+ import { useState as A, useMemo as Q, useEffect as ie } from "react";
8
+ import { parseDiff as ze, Diff as qe, Hunk as Ge } from "react-diff-view";
9
+ import { X as G, Y as H, Z as j, _ as K, a0 as fe, a1 as He, a2 as Ke, a3 as Y, a4 as z } from "./index-C4j31Yhz.js";
10
+ import { useQuery as pe, useQueryClient as ne, useMutation as ge } from "@tanstack/react-query";
11
+ import { useChaiFeatureFlag as Pe, useLanguages as Be, useSavePage as Qe } from "@chaibuilder/sdk";
12
+ function We(t, a) {
13
+ const l = G(), s = H();
14
+ return pe({
15
+ queryKey: ["revision-comparison", t.uid, a.uid],
16
+ queryFn: async () => {
17
+ if (!t.uid || !a.uid)
18
+ throw new Error("Both revision IDs are required for comparison");
19
+ const c = (o) => o === "draft" || o === "live" ? o : "revision", d = (o) => Ee(o.uid, `${o.label}:`, "");
20
+ return await s(l, {
21
+ action: j.GET_COMPARE_DATA,
22
+ data: {
23
+ versions: {
24
+ version1: { type: c(t.label), id: d(t) },
25
+ version2: { type: c(a.label), id: d(a) }
26
+ }
27
+ }
28
+ });
29
+ },
30
+ enabled: !!t.uid && !!a.uid,
31
+ gcTime: 0,
32
+ staleTime: 0
33
+ });
34
+ }
35
+ const Ye = ({ version: t }) => {
36
+ const a = t == null ? void 0 : t.item, { data: l } = K(a == null ? void 0 : a.currentEditor), s = t.label === "live", c = t.label === "draft";
37
+ return /* @__PURE__ */ n(
38
+ "span",
39
+ {
40
+ className: `flex items-center gap-x-2 rounded border bg-white px-2 text-xs shadow-lg ${s ? "border-green-500/30" : c ? "border-amber-500/30" : "border-purple-500/30"}`,
41
+ children: [
42
+ /* @__PURE__ */ e(
43
+ "div",
44
+ {
45
+ className: "h-full items-center rounded px-1.5 py-0.5 font-medium capitalize" + (s ? " bg-green-500 text-green-50" : c ? " bg-amber-500 text-amber-50" : " bg-purple-500 text-purple-50"),
46
+ children: t.label
47
+ }
48
+ ),
49
+ /* @__PURE__ */ n("div", { className: "py-1 text-xs font-light leading-none text-gray-800", children: [
50
+ /* @__PURE__ */ n("div", { children: [
51
+ /* @__PURE__ */ e("span", { className: "font-light opacity-90", children: c ? "Currently editing" : "Published by" }),
52
+ !c && /* @__PURE__ */ e("span", { className: "pl-1 font-medium", children: (l == null ? void 0 : l.name) || "Unknown" })
53
+ ] }),
54
+ /* @__PURE__ */ e("div", { className: "text-[10px] leading-tight", children: Se(a.createdAt, "dd MMM yyyy, h:mm a") })
55
+ ] })
56
+ ]
57
+ }
58
+ );
59
+ }, ce = ({ version: t }) => /* @__PURE__ */ e(Ye, { version: t });
60
+ function Xe(t, a, l = "data.json") {
61
+ const s = JSON.stringify(t, null, 2), c = JSON.stringify(a, null, 2), d = s.split(`
62
+ `), i = c.split(`
63
+ `);
64
+ let o = `--- a/${l}
65
+ `;
66
+ o += `+++ b/${l}
67
+ `;
68
+ const h = [];
69
+ let r = 0, f = 0;
70
+ for (; r < d.length || f < i.length; ) {
71
+ const x = d[r] || "", w = i[f] || "";
72
+ if (x === w)
73
+ h.push(` ${x}`), r++, f++;
74
+ else {
75
+ let u = -1, N = -1;
76
+ for (let m = r + 1; m < d.length; m++)
77
+ if (i[f] === d[m]) {
78
+ u = m;
79
+ break;
80
+ }
81
+ for (let m = f + 1; m < i.length; m++)
82
+ if (d[r] === i[m]) {
83
+ N = m;
84
+ break;
85
+ }
86
+ if (u !== -1 && (N === -1 || u - r <= N - f)) {
87
+ for (let m = r; m < u; m++)
88
+ h.push(`-${d[m]}`);
89
+ r = u;
90
+ } else if (N !== -1) {
91
+ for (let m = f; m < N; m++)
92
+ h.push(`+${i[m]}`);
93
+ f = N;
94
+ } else
95
+ x && h.push(`-${x}`), w && h.push(`+${w}`), r++, f++;
96
+ }
97
+ }
98
+ const b = d.length, E = i.length;
99
+ return o += `@@ -1,${b} +1,${E} @@
100
+ `, o += h.join(`
101
+ `) + `
102
+ `, o;
103
+ }
104
+ function $(t, a = !0, l = !1) {
105
+ if (Re(t)) {
106
+ const s = Te(t);
107
+ if (se(s, "{") || se(s, "[") || a && (s === "true" || s === "false" || s === "null" || /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(s)))
108
+ try {
109
+ const d = JSON.parse(s);
110
+ return $(d, a, l);
111
+ } catch {
112
+ if (l)
113
+ throw new Error(`Invalid JSON string: ${s}`);
114
+ return {};
115
+ }
116
+ return t;
117
+ }
118
+ return Oe(t) ? Ie(t, (s) => $(s, a, l)) : Me(t) ? Ae(t, (s) => $(s, a, l)) : t;
119
+ }
120
+ const Ze = (t) => {
121
+ switch (t) {
122
+ case "blocks":
123
+ return "Blocks";
124
+ case "seo":
125
+ return "SEO";
126
+ case "tracking":
127
+ return "Tracking";
128
+ default:
129
+ return t;
130
+ }
131
+ }, et = (t, a) => {
132
+ if (!t || !a) return [{ key: "blocks", label: "Blocks" }];
133
+ const l = Object.keys(t), s = Object.keys(a);
134
+ return l.filter((i) => s.includes(i)).map((i) => ({ key: i, label: Ze(i) })).filter((i) => i.key.length > 0);
135
+ }, tt = (t, a = 3) => {
136
+ const l = /* @__PURE__ */ new Set();
137
+ t.map((i, o) => ({ change: i, index: o })).filter(({ change: i }) => i.type !== "normal").map(({ index: i }) => i).forEach((i) => {
138
+ const o = Math.max(0, i - a), h = Math.min(t.length - 1, i + a);
139
+ for (let r = o; r <= h; r++)
140
+ l.add(r);
141
+ });
142
+ const c = [];
143
+ let d = -1;
144
+ return t.forEach((i, o) => {
145
+ if (l.has(o)) {
146
+ if (d !== -1 && o - d > 1) {
147
+ const h = t[d].lineNumber != null ? t[d].lineNumber + 1 : d + 2, r = t[o].lineNumber != null ? t[o].lineNumber - 1 : o;
148
+ c.push({
149
+ content: /* @__PURE__ */ e(Ne, { className: "pointer-events-none w-60 -translate-x-1/2 cursor-default border-none bg-transparent py-1 shadow-none", children: /* @__PURE__ */ n("span", { className: "rounded border border-border bg-muted px-3 py-1 text-xs font-light leading-none text-muted-foreground", children: [
150
+ "No changes from ",
151
+ h,
152
+ " to ",
153
+ r,
154
+ " line"
155
+ ] }) })
156
+ });
157
+ }
158
+ c.push(i), d = o;
159
+ }
160
+ }), c;
161
+ };
162
+ function nt({ open: t, compare: a, onOpenChange: l }) {
163
+ const s = a[0], c = a[1], [d, i] = A(null), [o, h] = A("split"), [r, f] = A(!1), [b, E] = A(!1), [x, w] = A("blocks"), { data: u, isLoading: N } = We(s, c), { leftData: m, rightData: R, options: _ } = Q(() => {
164
+ var y, g;
165
+ const p = (y = u == null ? void 0 : u.version1) == null ? void 0 : y[x], D = (g = u == null ? void 0 : u.version2) == null ? void 0 : g[x], S = $(p), T = $(D), M = et(u == null ? void 0 : u.version1, u == null ? void 0 : u.version2);
166
+ return { leftData: S, rightData: T, options: M };
167
+ }, [u, x]), C = Q(() => !m || !R ? "" : Xe(m, R), [m, R]), F = Q(() => {
168
+ if (!C) return [];
169
+ try {
170
+ return ze(C);
171
+ } catch (p) {
172
+ return console.error("Failed to parse diff:", p), [];
173
+ }
174
+ }, [C]), J = async (p, D) => {
175
+ try {
176
+ await navigator.clipboard.writeText(JSON.stringify(p, null, 2)), i(D), setTimeout(() => i(null), 2e3);
177
+ } catch (S) {
178
+ console.error("Failed to copy:", S);
179
+ }
180
+ }, I = (p) => JSON.stringify(p, null, 2);
181
+ return /* @__PURE__ */ e(X, { open: t, onOpenChange: l, children: /* @__PURE__ */ n(Z, { className: "flex h-[90vh] w-[95vw] max-w-[1900px] flex-col p-6", children: [
182
+ /* @__PURE__ */ e(ee, { className: "pb-4 pt-0", children: /* @__PURE__ */ n(te, { className: "flex items-center justify-between gap-2 leading-none", children: [
183
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
184
+ /* @__PURE__ */ e(W, { className: "h-5 w-5" }),
185
+ "Compare",
186
+ "",
187
+ _.map((p) => /* @__PURE__ */ e(
188
+ "div",
189
+ {
190
+ className: `cursor-pointer rounded-full border px-2.5 py-1 text-xs leading-none ${x === p.key ? "border-blue-500 bg-blue-500 text-white" : "border-gray-600 text-gray-600 hover:bg-gray-200"}`,
191
+ onClick: () => w(p.key),
192
+ children: p.label
193
+ },
194
+ p.key
195
+ ))
196
+ ] }),
197
+ /* @__PURE__ */ e("div", { className: "flex flex-1 items-center justify-end pr-8", children: /* @__PURE__ */ n("div", { className: "flex w-max items-center justify-end gap-2 rounded-md border px-1.5 py-1", children: [
198
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-2 px-2 py-1", children: [
199
+ /* @__PURE__ */ e(
200
+ B,
201
+ {
202
+ disabled: r,
203
+ checked: r ? !0 : o === "split",
204
+ onCheckedChange: (p) => h(p ? "split" : "unified")
205
+ }
206
+ ),
207
+ /* @__PURE__ */ e("label", { className: "text-sm", children: "Split View" })
208
+ ] }),
209
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-2 px-2 py-1", children: [
210
+ /* @__PURE__ */ e(B, { checked: r, onCheckedChange: (p) => f(p) }),
211
+ /* @__PURE__ */ e("label", { className: "text-sm", children: "Show Raw Data" })
212
+ ] }),
213
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-2 px-2 py-1", children: [
214
+ /* @__PURE__ */ e(B, { checked: b, onCheckedChange: (p) => E(p) }),
215
+ /* @__PURE__ */ e("label", { className: "text-sm", children: "Hide Common Data" })
216
+ ] })
217
+ ] }) })
218
+ ] }) }),
219
+ N ? /* @__PURE__ */ e("div", { className: "flex h-full w-full items-center justify-center", children: /* @__PURE__ */ e(je, { className: "h-6 w-6 animate-spin text-primary" }) }) : /* @__PURE__ */ e("div", { className: "flex min-h-0 flex-1 flex-col", children: /* @__PURE__ */ n("div", { className: "relative min-h-0 flex-1", children: [
220
+ /* @__PURE__ */ n("div", { className: "absolute -top-5 z-50 mt-0.5 flex w-full items-center justify-between gap-2", children: [
221
+ /* @__PURE__ */ e("div", { className: "flex w-1/2 items-center justify-center gap-2", children: /* @__PURE__ */ e(ce, { version: s }) }),
222
+ /* @__PURE__ */ e("div", { className: "flex w-1/2 items-center justify-center gap-2", children: /* @__PURE__ */ e(ce, { version: c }) })
223
+ ] }),
224
+ r ? /* @__PURE__ */ n("div", { className: "grid h-full grid-cols-2 gap-3 rounded-lg border", children: [
225
+ /* @__PURE__ */ n("div", { className: "relative flex min-h-0 flex-col border-r", children: [
226
+ /* @__PURE__ */ e("div", { className: "absolute -top-4 right-4 z-50", children: /* @__PURE__ */ n(v, { variant: "outline", size: "sm", onClick: () => J(m, "left"), children: [
227
+ d === "left" ? /* @__PURE__ */ e(le, { className: "text-green-500" }) : /* @__PURE__ */ e(re, {}),
228
+ "Copy"
229
+ ] }) }),
230
+ /* @__PURE__ */ e(V, { 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: I(m) }) })
231
+ ] }),
232
+ /* @__PURE__ */ n("div", { className: "relative flex min-h-0 flex-col", children: [
233
+ /* @__PURE__ */ e("div", { className: "absolute -top-4 right-4 z-50", children: /* @__PURE__ */ n(v, { variant: "outline", size: "sm", onClick: () => J(R, "right"), children: [
234
+ d === "right" ? /* @__PURE__ */ e(le, { className: "text-green-500" }) : /* @__PURE__ */ e(re, {}),
235
+ "Copy"
236
+ ] }) }),
237
+ /* @__PURE__ */ e(V, { 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: I(R) }) })
238
+ ] })
239
+ ] }) : /* @__PURE__ */ e(V, { className: "h-full overflow-y-auto rounded-lg border bg-slate-50 text-xs dark:bg-slate-900", children: F.length === 0 ? /* @__PURE__ */ e("div", { className: "flex h-full items-center justify-center p-6", children: /* @__PURE__ */ n("div", { className: "text-center text-muted-foreground", children: [
240
+ /* @__PURE__ */ e(W, { className: "mx-auto mb-2 h-8 w-8 opacity-50" }),
241
+ /* @__PURE__ */ e("p", { children: "No differences found or unable to parse diff" })
242
+ ] }) }) : /* @__PURE__ */ e("div", { children: F.map((p, D) => /* @__PURE__ */ e("div", { className: "relative mb-4", children: /* @__PURE__ */ e(
243
+ qe,
244
+ {
245
+ viewType: o,
246
+ diffType: p.type,
247
+ hunks: p.hunks,
248
+ className: "rounded-lg text-xs",
249
+ children: (S) => S.map((T, M) => {
250
+ const y = b ? tt(T.changes) : T.changes;
251
+ return (y == null ? void 0 : y.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(Ge, { hunk: { ...T, changes: y } }, M);
252
+ })
253
+ },
254
+ b ? "hide-common-data" : "show-common-data"
255
+ ) }, D)) }) })
256
+ ] }) })
257
+ ] }) });
258
+ }
259
+ function at(t) {
260
+ const a = G(), l = H();
261
+ return pe({
262
+ queryKey: ["revisions", t],
263
+ queryFn: async () => await l(a, {
264
+ action: j.GET_PAGE_REVISIONS,
265
+ data: { pageId: t }
266
+ }),
267
+ enabled: !!t,
268
+ gcTime: 0,
269
+ refetchOnMount: !0
270
+ });
271
+ }
272
+ const st = () => {
273
+ const t = G(), a = H(), l = ne();
274
+ return ge({
275
+ mutationFn: async (s) => await a(t, {
276
+ action: j.DELETE_PAGE_REVISION,
277
+ data: { revisionId: s }
278
+ }),
279
+ onSuccess: () => {
280
+ l.invalidateQueries({
281
+ queryKey: ["revisions"]
282
+ });
283
+ }
284
+ });
285
+ }, lt = () => {
286
+ const t = G(), a = H(), l = ne();
287
+ return ge({
288
+ mutationFn: async ({ revisionId: s, discardCurrent: c }) => await a(t, {
289
+ action: j.RESTORE_PAGE_REVISION,
290
+ data: { revisionId: s, discardCurrent: c }
291
+ }),
292
+ onSuccess: () => {
293
+ l.invalidateQueries({
294
+ queryKey: ["revisions"]
295
+ });
296
+ }
297
+ });
298
+ }, O = ({ 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: [
299
+ /* @__PURE__ */ n("span", { className: "relative flex h-2 w-2", children: [
300
+ /* @__PURE__ */ e("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75" }),
301
+ /* @__PURE__ */ e("span", { className: "relative inline-flex h-2 w-2 rounded-full bg-amber-500" })
302
+ ] }),
303
+ /* @__PURE__ */ e("span", { className: "text-[11px] leading-tight", children: "Draft" })
304
+ ] }) : t === "live" ? /* @__PURE__ */ n("span", { className: "flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary", children: [
305
+ /* @__PURE__ */ n("span", { className: "relative flex h-2 w-2", children: [
306
+ /* @__PURE__ */ e("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75" }),
307
+ /* @__PURE__ */ e("span", { className: "relative inline-flex h-2 w-2 rounded-full bg-green-500" })
308
+ ] }),
309
+ /* @__PURE__ */ e("span", { className: "text-[11px] leading-tight", children: "Live" })
310
+ ] }) : t === "published" ? /* @__PURE__ */ n("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: [
311
+ /* @__PURE__ */ e(Le, { className: "h-3 w-3" }),
312
+ /* @__PURE__ */ e("span", { className: "text-[11px] leading-tight", children: "Published" })
313
+ ] }) : t === "unsaved" ? /* @__PURE__ */ n("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: [
314
+ /* @__PURE__ */ e(Ue, { className: "h-3 w-3" }),
315
+ /* @__PURE__ */ e("span", { className: "text-[11px] leading-tight", children: "Unsaved changes" })
316
+ ] }) : /* @__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 });
317
+ function rt({ compare: t, setCompare: a, isComparisonEnabled: l }) {
318
+ const { data: s } = fe(), { saveState: c } = Qe(), [d] = Ke();
319
+ if (!s) return null;
320
+ const i = !!t.find((r) => {
321
+ var f;
322
+ return (f = r == null ? void 0 : r.uid) == null ? void 0 : f.startsWith("draft:");
323
+ }), o = t.length >= 2 && !i, h = c === "UNSAVED";
324
+ return /* @__PURE__ */ n("div", { className: "relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50", children: [
325
+ /* @__PURE__ */ n("div", { className: "flex-1 space-y-1", children: [
326
+ /* @__PURE__ */ e("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ n("div", { className: "flex items-center gap-1 text-sm font-medium leading-none", children: [
327
+ /* @__PURE__ */ e(O, { tag: "draft" }),
328
+ /* @__PURE__ */ e("span", { className: "text-xs font-bold", children: "Currently editing" })
329
+ ] }) }),
330
+ /* @__PURE__ */ e("div", { className: "flex items-center pl-2 text-[11px] text-muted-foreground", children: !$e(d.lastSaved) && /* @__PURE__ */ n("span", { children: [
331
+ "Last updated",
332
+ " ",
333
+ ke(new Date(d.lastSaved), {
334
+ addSuffix: !0
335
+ })
336
+ ] }) }),
337
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2 pt-0.5", children: h ? /* @__PURE__ */ e(O, { tag: "unsaved" }) : null })
338
+ ] }),
339
+ l && /* @__PURE__ */ e(
340
+ xe,
341
+ {
342
+ checked: i,
343
+ disabled: o,
344
+ onChange: () => {
345
+ a(i ? t.filter((r) => r.uid !== `draft:${s == null ? void 0 : s.id}`) : [
346
+ ...t,
347
+ { uid: `draft:${s == null ? void 0 : s.id}`, label: "draft", item: { createdAt: Date.now() } }
348
+ ]);
349
+ }
350
+ }
351
+ )
352
+ ] });
353
+ }
354
+ function it() {
355
+ return /* @__PURE__ */ e("div", { className: "mt-2 space-y-2", children: Array.from({ length: 5 }).map((t, a) => /* @__PURE__ */ n("div", { className: "flex items-start gap-3 rounded-md border p-2", children: [
356
+ /* @__PURE__ */ n("div", { className: "flex-1 space-y-1", children: [
357
+ /* @__PURE__ */ e(L, { className: "h-4 w-3/4" }),
358
+ /* @__PURE__ */ e(L, { className: "h-3 w-1/2" }),
359
+ /* @__PURE__ */ e(L, { className: "mt-1 h-5 w-20" })
360
+ ] }),
361
+ /* @__PURE__ */ e(L, { className: "h-8 w-8 rounded-full" })
362
+ ] }, a)) });
363
+ }
364
+ function de({
365
+ revision: t,
366
+ isLatest: a,
367
+ onRestore: l,
368
+ onDelete: s,
369
+ revisionNumber: c,
370
+ compare: d,
371
+ setCompare: i,
372
+ pageId: o,
373
+ pageLiveFullSlug: h,
374
+ isComparisonEnabled: r,
375
+ lang: f
376
+ }) {
377
+ const { data: b } = K(t.currentEditor), E = (b == null ? void 0 : b.name) || "Unknown", x = !!d.find((u) => {
378
+ var N;
379
+ return a ? (N = u == null ? void 0 : u.uid) == null ? void 0 : N.startsWith("live") : (u == null ? void 0 : u.uid) === t.uid;
380
+ }), w = d.length >= 2 && !x;
381
+ return /* @__PURE__ */ n("div", { className: "relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50", children: [
382
+ /* @__PURE__ */ n("div", { className: "flex-1 space-y-3", children: [
383
+ /* @__PURE__ */ e("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ n("p", { className: "flex items-center gap-1 text-xs leading-none", children: [
384
+ r && /* @__PURE__ */ e(O, { tag: a ? "live" : `#${c}` }),
385
+ t.type === "published" ? "Published" : "Draft",
386
+ " by ",
387
+ /* @__PURE__ */ e("span", { className: "text-xs font-bold", children: E }),
388
+ !r && a && /* @__PURE__ */ e(O, { tag: "live" })
389
+ ] }) }),
390
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-x-3", children: [
391
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: t.type === "published" ? /* @__PURE__ */ e(O, { tag: "published" }) : /* @__PURE__ */ e(O, { tag: "draft" }) }),
392
+ /* @__PURE__ */ e("div", { className: "flex items-center text-[10px] text-muted-foreground", children: /* @__PURE__ */ e("span", { className: "leading-tight", children: q(t.createdAt, "MMM d, h:mm a") }) })
393
+ ] })
394
+ ] }),
395
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
396
+ t.type !== "draft" && r && /* @__PURE__ */ e(
397
+ "a",
398
+ {
399
+ target: "_blank",
400
+ href: a ? h : `/revision/revision:${t.uid}:${c}?lang=${f}`,
401
+ children: /* @__PURE__ */ n(v, { variant: "ghost", size: "icon", className: "h-4 w-4 hover:text-blue-500", children: [
402
+ /* @__PURE__ */ e(_e, { className: "h-3 w-3" }),
403
+ /* @__PURE__ */ e("span", { className: "sr-only", children: "View this version" })
404
+ ] })
405
+ }
406
+ ),
407
+ /* @__PURE__ */ e(Y, { permissions: [z.RESTORE_REVISION, z.DELETE_REVISION], children: /* @__PURE__ */ e(dt, { revision: t, onRestore: l, onDelete: s }) })
408
+ ] }),
409
+ r && /* @__PURE__ */ e(
410
+ xe,
411
+ {
412
+ checked: x,
413
+ disabled: w,
414
+ onChange: () => {
415
+ i(
416
+ x ? d.filter((u) => a ? u.uid !== `live:${o}` : u.uid !== t.uid) : [
417
+ ...d,
418
+ {
419
+ uid: a ? `live:${o}` : t.uid,
420
+ label: a ? "live" : `#${c}`,
421
+ item: t
422
+ }
423
+ ].sort((u, N) => new Date(u.item.createdAt).getTime() - new Date(N.item.createdAt).getTime())
424
+ );
425
+ }
426
+ }
427
+ )
428
+ ] });
429
+ }
430
+ function ct({ compare: t, setCompare: a, pageId: l }) {
431
+ const [s, c] = A(!1), [d, i] = t;
432
+ if (t.length === 0) return null;
433
+ const o = ({ tab: h }) => /* @__PURE__ */ n("span", { className: "flex items-center justify-between rounded border border-blue-100 p-1 font-medium", children: [
434
+ /* @__PURE__ */ e(O, { tag: h.label }),
435
+ /* @__PURE__ */ e(
436
+ "button",
437
+ {
438
+ className: "z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",
439
+ style: { lineHeight: 1 },
440
+ onClick: () => a(t.filter((r) => r.uid !== h.uid)),
441
+ "aria-label": "Remove selection 1",
442
+ children: /* @__PURE__ */ e(Ve, { className: "h-3 w-3" })
443
+ }
444
+ )
445
+ ] });
446
+ return /* @__PURE__ */ n("div", { className: "mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm", children: [
447
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-x-2 text-xs", children: [
448
+ /* @__PURE__ */ e("span", { className: "font-medium leading-tight text-gray-600", children: "Compare" }),
449
+ d && /* @__PURE__ */ e(o, { tab: d }),
450
+ /* @__PURE__ */ e("span", { className: "font-medium leading-tight text-gray-600", children: "with" }),
451
+ i ? /* @__PURE__ */ e(o, { tab: i }) : /* @__PURE__ */ e("span", { className: "rounded border px-1 text-xs text-muted-foreground", children: "Choose another" })
452
+ ] }),
453
+ /* @__PURE__ */ n("div", { className: "flex items-center justify-end gap-2 pb-0.5 pt-2", children: [
454
+ /* @__PURE__ */ e(
455
+ v,
456
+ {
457
+ size: "sm",
458
+ className: "h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",
459
+ variant: "outline",
460
+ onClick: () => a([]),
461
+ children: /* @__PURE__ */ e("span", { children: " Clear" })
462
+ }
463
+ ),
464
+ /* @__PURE__ */ n(
465
+ v,
466
+ {
467
+ size: "sm",
468
+ className: "h-6 gap-1 rounded px-2 text-xs leading-none",
469
+ variant: "default",
470
+ onClick: () => c(!0),
471
+ disabled: t.length < 2,
472
+ children: [
473
+ /* @__PURE__ */ e(W, { className: "h-2.5 w-2.5" }),
474
+ /* @__PURE__ */ e("span", { className: "pt-0.5", children: "Show JSON Diff" })
475
+ ]
476
+ }
477
+ )
478
+ ] }),
479
+ s && (t == null ? void 0 : t.length) > 1 && l && /* @__PURE__ */ e(nt, { open: s, onOpenChange: c, compare: t })
480
+ ] });
481
+ }
482
+ function xe({ checked: t, disabled: a, onChange: l, label: s = "Compare" }) {
483
+ return /* @__PURE__ */ e("div", { className: "absolute bottom-2 right-2", children: /* @__PURE__ */ n("label", { className: `flex cursor-pointer items-center gap-x-1 text-[11px] ${a ? "opacity-50" : ""}`, children: [
484
+ /* @__PURE__ */ e(
485
+ "input",
486
+ {
487
+ type: "checkbox",
488
+ className: "h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",
489
+ checked: t,
490
+ disabled: a,
491
+ onChange: l
492
+ }
493
+ ),
494
+ /* @__PURE__ */ e("span", { className: "select-none leading-tight", children: s })
495
+ ] }) });
496
+ }
497
+ function dt({ revision: t, onRestore: a, onDelete: l }) {
498
+ return /* @__PURE__ */ n(ve, { children: [
499
+ /* @__PURE__ */ e(we, { asChild: !0, children: /* @__PURE__ */ n(v, { variant: "ghost", size: "icon", className: "h-5 w-5", children: [
500
+ /* @__PURE__ */ e(Fe, { className: "h-4 w-4" }),
501
+ /* @__PURE__ */ e("span", { className: "sr-only", children: "More options" })
502
+ ] }) }),
503
+ /* @__PURE__ */ n(Ce, { align: "end", className: "text-xs", children: [
504
+ /* @__PURE__ */ e(Y, { permission: z.RESTORE_REVISION, children: /* @__PURE__ */ n(ae, { onClick: a, className: "cursor-pointer text-sm", children: [
505
+ /* @__PURE__ */ e(me, { className: "mr-2 h-4 w-4" }),
506
+ /* @__PURE__ */ e("span", { children: "Restore this version" })
507
+ ] }) }),
508
+ /* @__PURE__ */ e(Y, { permission: z.DELETE_REVISION, children: t.uid !== "current" && /* @__PURE__ */ n(k, { children: [
509
+ /* @__PURE__ */ e(De, {}),
510
+ /* @__PURE__ */ n(ae, { onClick: l, className: "cursor-pointer text-destructive", children: [
511
+ /* @__PURE__ */ e(he, { className: "mr-2 h-4 w-4" }),
512
+ /* @__PURE__ */ e("span", { children: "Delete this version" })
513
+ ] })
514
+ ] }) })
515
+ ] })
516
+ ] });
517
+ }
518
+ function ot({
519
+ open: t,
520
+ onOpenChange: a,
521
+ revision: l,
522
+ onRestore: s,
523
+ isRestoring: c
524
+ }) {
525
+ const { data: d } = K((l == null ? void 0 : l.currentEditor) || ""), i = (d == null ? void 0 : d.name) || "Unknown";
526
+ return l ? /* @__PURE__ */ e(
527
+ X,
528
+ {
529
+ open: t,
530
+ onOpenChange: (o) => {
531
+ c || a(o);
532
+ },
533
+ children: /* @__PURE__ */ n(Z, { className: "sm:max-w-md", children: [
534
+ /* @__PURE__ */ n(ee, { children: [
535
+ /* @__PURE__ */ e(te, { children: "Restore Revision" }),
536
+ /* @__PURE__ */ n(oe, { children: [
537
+ "You are about to restore to revision ",
538
+ l.uid.substring(0, 8),
539
+ " from",
540
+ " ",
541
+ q(l.createdAt, "MMM d, yyyy 'at' h:mm a"),
542
+ " by ",
543
+ i
544
+ ] })
545
+ ] }),
546
+ /* @__PURE__ */ e("div", { className: "py-2", children: /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "How would you like to handle your current edits?" }) }),
547
+ /* @__PURE__ */ n(ue, { className: "flex flex-col gap-2 sm:flex-row", children: [
548
+ /* @__PURE__ */ e(v, { variant: "outline", className: "sm:flex-1", onClick: () => s(!1), disabled: c, children: c ? /* @__PURE__ */ n(k, { children: [
549
+ /* @__PURE__ */ e("span", { className: "mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }),
550
+ "Saving as draft..."
551
+ ] }) : /* @__PURE__ */ n(k, { children: [
552
+ /* @__PURE__ */ e(Je, { className: "mr-2 h-4 w-4" }),
553
+ "Save as draft"
554
+ ] }) }),
555
+ /* @__PURE__ */ e(v, { variant: "default", className: "sm:flex-1", onClick: () => s(!0), disabled: c, children: c ? /* @__PURE__ */ n(k, { children: [
556
+ /* @__PURE__ */ e("span", { className: "mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }),
557
+ "Discarding current..."
558
+ ] }) : /* @__PURE__ */ n(k, { children: [
559
+ /* @__PURE__ */ e(me, { className: "mr-2 h-4 w-4" }),
560
+ "Discard current"
561
+ ] }) })
562
+ ] })
563
+ ] })
564
+ }
565
+ ) : null;
566
+ }
567
+ function ut({
568
+ open: t,
569
+ onOpenChange: a,
570
+ revision: l,
571
+ onDelete: s,
572
+ isDeleting: c
573
+ }) {
574
+ const { data: d } = K((l == null ? void 0 : l.currentEditor) || ""), i = (d == null ? void 0 : d.name) || "Unknown";
575
+ return l ? /* @__PURE__ */ e(
576
+ X,
577
+ {
578
+ open: t,
579
+ onOpenChange: (o) => {
580
+ c || a(o);
581
+ },
582
+ children: /* @__PURE__ */ n(Z, { className: "sm:max-w-md", children: [
583
+ /* @__PURE__ */ n(ee, { children: [
584
+ /* @__PURE__ */ e(te, { children: "Delete Revision" }),
585
+ /* @__PURE__ */ n(oe, { children: [
586
+ "You are about to delete revision ",
587
+ l.uid.substring(0, 8),
588
+ " from",
589
+ " ",
590
+ q(l.createdAt, "MMM d, yyyy 'at' h:mm a"),
591
+ " by ",
592
+ i
593
+ ] })
594
+ ] }),
595
+ /* @__PURE__ */ e("div", { className: "py-2", children: /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "This action cannot be undone. Are you sure you want to proceed?" }) }),
596
+ /* @__PURE__ */ n(ue, { className: "flex flex-col gap-2 sm:flex-row", children: [
597
+ /* @__PURE__ */ e(v, { variant: "outline", className: "sm:flex-1", onClick: () => a(!1), disabled: c, children: "Cancel" }),
598
+ /* @__PURE__ */ e(v, { variant: "destructive", className: "sm:flex-1", onClick: s, disabled: c, children: c ? /* @__PURE__ */ n(k, { children: [
599
+ /* @__PURE__ */ e("span", { className: "mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }),
600
+ "Deleting..."
601
+ ] }) : /* @__PURE__ */ n(k, { children: [
602
+ /* @__PURE__ */ e(he, { className: "mr-2 h-4 w-4" }),
603
+ "Delete Revision"
604
+ ] }) })
605
+ ] })
606
+ ] })
607
+ }
608
+ ) : null;
609
+ }
610
+ function wt({ isOpen: t }) {
611
+ var M, y;
612
+ const [a, l] = U.useState([]), [s, c] = U.useState(null), [d, i] = U.useState(!1), [o, h] = U.useState(!1), { data: r } = fe(), { data: f, isFetching: b, error: E, refetch: x } = at(r == null ? void 0 : r.id), { mutate: w, isPending: u } = st(), { mutate: N, isPending: m } = lt(), R = ne(), _ = He(), C = Pe("enable-page-revisions-compare"), { selectedLang: F, fallbackLang: J } = Be(), I = F || J;
613
+ ie(() => l([]), [r == null ? void 0 : r.id]);
614
+ const p = (g) => {
615
+ s && N(
616
+ { revisionId: s.uid, discardCurrent: g },
617
+ {
618
+ onSuccess: () => {
619
+ i(!1), c(null), R.invalidateQueries({
620
+ queryKey: [j.GET_DRAFT_PAGE]
621
+ });
622
+ }
623
+ }
624
+ );
625
+ }, D = (g) => {
626
+ c(g), i(!0);
627
+ }, S = (g) => {
628
+ c(g), h(!0);
629
+ }, T = () => {
630
+ s && w(s.uid, {
631
+ /**
632
+ * Callback for when deletion of a revision is successful. Closes the
633
+ * delete dialog and resets the selected revision to null.
634
+ */
635
+ onSuccess: () => {
636
+ h(!1), c(null);
637
+ }
638
+ });
639
+ };
640
+ return ie(() => {
641
+ t && x();
642
+ }, [t, x]), /* @__PURE__ */ n(k, { children: [
643
+ /* @__PURE__ */ n(be, { children: [
644
+ /* @__PURE__ */ e(ye, { children: "Revision History" }),
645
+ (r == null ? void 0 : r.createdAt) && /* @__PURE__ */ n("p", { className: "mt-1 text-xs text-muted-foreground", children: [
646
+ "Page created on ",
647
+ q(new Date(r.createdAt), "MMM d, yyyy 'at' h:mm a")
648
+ ] })
649
+ ] }),
650
+ b ? /* @__PURE__ */ e(it, {}) : E ? /* @__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: [
651
+ C && /* @__PURE__ */ e(ct, { lang: I, compare: a, setCompare: l, pageId: r == null ? void 0 : r.id }),
652
+ /* @__PURE__ */ e(rt, { compare: a, setCompare: l, isComparisonEnabled: C }),
653
+ (M = f == null ? void 0 : f.filter((g) => g.uid === "current")) == null ? void 0 : M.map((g, P) => /* @__PURE__ */ e(
654
+ de,
655
+ {
656
+ lang: I,
657
+ pageId: r == null ? void 0 : r.id,
658
+ revision: g,
659
+ isLatest: !0,
660
+ onRestore: () => D(g),
661
+ onDelete: () => S(g),
662
+ revisionNumber: P,
663
+ compare: a,
664
+ setCompare: l,
665
+ pageLiveFullSlug: _,
666
+ isComparisonEnabled: C
667
+ },
668
+ g.uid
669
+ )),
670
+ /* @__PURE__ */ e(V, { className: "min-h-0 flex-1", children: /* @__PURE__ */ e("div", { className: "space-y-2", children: (y = f == null ? void 0 : f.filter((g) => g.uid !== "current")) == null ? void 0 : y.map((g, P) => /* @__PURE__ */ e(
671
+ de,
672
+ {
673
+ lang: I,
674
+ pageId: r == null ? void 0 : r.id,
675
+ revision: g,
676
+ isLatest: g.uid === "current",
677
+ onRestore: () => D(g),
678
+ onDelete: () => S(g),
679
+ revisionNumber: P + 1,
680
+ compare: a,
681
+ setCompare: l,
682
+ pageLiveFullSlug: _,
683
+ isComparisonEnabled: C
684
+ },
685
+ g.uid
686
+ )) }) })
687
+ ] }),
688
+ /* @__PURE__ */ e(
689
+ ot,
690
+ {
691
+ open: d,
692
+ onOpenChange: i,
693
+ revision: s,
694
+ onRestore: p,
695
+ isRestoring: m
696
+ }
697
+ ),
698
+ /* @__PURE__ */ e(
699
+ ut,
700
+ {
701
+ open: o,
702
+ onOpenChange: h,
703
+ revision: s,
704
+ onDelete: T,
705
+ isDeleting: u
706
+ }
707
+ )
708
+ ] });
709
+ }
710
+ export {
711
+ wt as default
712
+ };