@chaibuilder/pages 0.13.3 → 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.
Files changed (76) hide show
  1. package/dist/{2AITGKQY-DpAgk_u8.cjs → 2AITGKQY-BLi5HVHf.cjs} +1 -1
  2. package/dist/{2AITGKQY-Dx_Cte-P.js → 2AITGKQY-iyhQ7kgG.js} +5 -5
  3. package/dist/{NCMVHL6D-B6lv7Umq.cjs → NCMVHL6D-CKYg8-AM.cjs} +1 -1
  4. package/dist/{NCMVHL6D-CT2qHOTS.js → NCMVHL6D-PLvSyK5P.js} +2 -2
  5. package/dist/{ZDWCUMSJ-C1vrgsti.cjs → ZDWCUMSJ-BJZ_Yi-4.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-W9xywtZH.js → ZDWCUMSJ-CuLkdxY-.js} +1 -1
  7. package/dist/add-new-language-page--ah9yzN3.cjs +1 -0
  8. package/dist/add-new-language-page-WM_Ve2vH.js +390 -0
  9. package/dist/add-new-page-Bs_NXM9x.js +30 -0
  10. package/dist/add-new-page-CnUo6xzd.cjs +1 -0
  11. package/dist/confetti.module-BuUnQuWk.cjs +2 -0
  12. package/dist/confetti.module-DCmCkDyV.js +409 -0
  13. package/dist/delete-page-Cf88UkqJ.cjs +1 -0
  14. package/dist/delete-page-D8xhYESu.js +38 -0
  15. package/dist/digital-asset-manager-BAFTqxsM.js +976 -0
  16. package/dist/digital-asset-manager-D_lcprwY.cjs +1 -0
  17. package/dist/duplicate-page-BX1gOez-.cjs +1 -0
  18. package/dist/duplicate-page-CqXTGmWt.js +120 -0
  19. package/dist/dynamic-page-selector-0TiUnfUg.js +86 -0
  20. package/dist/dynamic-page-selector-9JIQrcq5.cjs +1 -0
  21. package/dist/get-seo-defaults-9zHebckY.js +65 -0
  22. package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
  23. package/dist/image-compression-DZ9WMmyn.cjs +1 -0
  24. package/dist/image-compression-DsZ1oqpb.js +37 -0
  25. package/dist/index-D7kegQ3M.js +5153 -0
  26. package/dist/index-LU0FTfeN.cjs +5 -0
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.ts +4 -22
  29. package/dist/index.js +20 -21
  30. package/dist/json-diff-viewer-Be-PVOZN.cjs +8 -0
  31. package/dist/json-diff-viewer-C2GK_BDh.js +258 -0
  32. package/dist/lang-panel-CPFS1ssC.js +218 -0
  33. package/dist/lang-panel-CePltxo2.cjs +1 -0
  34. package/dist/mark-as-template-DeB23sWR.cjs +1 -0
  35. package/dist/mark-as-template-jdwcgRIB.js +146 -0
  36. package/dist/nested-path-selector-content-D_iF9Sm3.cjs +1 -0
  37. package/dist/nested-path-selector-content-DvIL_EoN.js +87 -0
  38. package/dist/no-language-page-content-DUM4KxWu.js +35 -0
  39. package/dist/no-language-page-content-Dsm2H3pc.cjs +1 -0
  40. package/dist/page-creator-BjuYmKfc.js +796 -0
  41. package/dist/page-creator-DG0LwvL1.cjs +1 -0
  42. package/dist/page-lock-request-B9WPmFcd.cjs +1 -0
  43. package/dist/page-lock-request-BceB1S-X.js +64 -0
  44. package/dist/page-locked-by-dialog-2MULM3jh.cjs +1 -0
  45. package/dist/page-locked-by-dialog-BEWfFLSc.js +63 -0
  46. package/dist/page-manager-new-BONZN4c5.cjs +1 -0
  47. package/dist/page-manager-new-DV6A9WFv.js +354 -0
  48. package/dist/page-manager-search-and-filter-3h4URMP_.cjs +1 -0
  49. package/dist/page-manager-search-and-filter-DIiowi9F.js +197 -0
  50. package/dist/page-revisions-content-BIxeZeND.js +446 -0
  51. package/dist/page-revisions-content-CQbt25XX.cjs +1 -0
  52. package/dist/publish-pages-content-CdKHrfys.js +178 -0
  53. package/dist/publish-pages-content-im9dPOBM.cjs +1 -0
  54. package/dist/save-to-lib-DGII9CEP.js +476 -0
  55. package/dist/save-to-lib-DOh-850u.cjs +1 -0
  56. package/dist/seo-panel-2VdpoGSg.cjs +1 -0
  57. package/dist/seo-panel-Bxo4f-a_.js +667 -0
  58. package/dist/shared-json-ld-C1OewNgp.cjs +1 -0
  59. package/dist/shared-json-ld-gbnBFljN.js +337 -0
  60. package/dist/slug-input-BmcGmc_i.js +87 -0
  61. package/dist/slug-input-CfuQV97Z.cjs +1 -0
  62. package/dist/theme-panel-footer-D3SwHqGR.js +25 -0
  63. package/dist/theme-panel-footer-FrY4U8zn.cjs +1 -0
  64. package/dist/translation-warning-modal-DalBhNQy.js +26 -0
  65. package/dist/translation-warning-modal-Kctu12rQ.cjs +1 -0
  66. package/dist/unmark-as-template-CihtTMOb.cjs +1 -0
  67. package/dist/unmark-as-template-UwmCCn0u.js +38 -0
  68. package/dist/unpublish-page-CNwIU6AS.js +26 -0
  69. package/dist/unpublish-page-DzLtZcNw.cjs +1 -0
  70. package/dist/use-page-expand-manager-B7JtHdg5.cjs +1 -0
  71. package/dist/use-page-expand-manager-BCFQnVkT.js +85 -0
  72. package/package.json +3 -3
  73. package/dist/index-C4j31Yhz.js +0 -11471
  74. package/dist/index-DnjETHks.cjs +0 -6
  75. package/dist/page-revisions-content-Gx-Qf_91.cjs +0 -8
  76. package/dist/page-revisions-content-_-Nd4U11.js +0 -712
@@ -0,0 +1,796 @@
1
+ import { jsx as s, jsxs as n, Fragment as We } from "react/jsx-runtime";
2
+ import { Input as M, CommandList as is, Label as I, Popover as ee, PopoverTrigger as se, Button as W, PopoverContent as le, Command as ne, CommandEmpty as ae, CommandGroup as G, CommandItem as R } from "@chaibuilder/sdk/ui";
3
+ import { useState as y, useRef as os, useEffect as Be, useMemo as $ } from "react";
4
+ import { r as te, S as cs, c as Oe } from "./slug-input-BmcGmc_i.js";
5
+ import { useChaiFeatureFlag as ye, usePermissions as us, useLanguages as ms } from "@chaibuilder/sdk";
6
+ import { isEmpty as Ie, startCase as de, filter as hs, find as ge, groupBy as ps, pick as ds, set as P } from "lodash-es";
7
+ import { ChevronDown as re, Search as ie, Check as U } from "lucide-react";
8
+ import { ai as Re, aj as Ue, A as oe, h as fs, aq as gs, b as ys, c as vs, d as Ns, au as bs, L as Ss } from "./index-D7kegQ3M.js";
9
+ import { useQuery as qe } from "@tanstack/react-query";
10
+ import { toast as E } from "sonner";
11
+ import { g as $e } from "./get-seo-defaults-9zHebckY.js";
12
+ function ws({
13
+ value: l,
14
+ onChange: o,
15
+ placeholder: v = "Enter custom slug part",
16
+ dynamicPattern: p,
17
+ onValidationChange: i
18
+ }) {
19
+ const [g, u] = y(null), m = os(null), [f, C] = y(p + l);
20
+ Be(() => {
21
+ C(p + l);
22
+ }, [l, p]);
23
+ const F = (b) => {
24
+ const S = b.target.value;
25
+ if (!S.startsWith(p)) {
26
+ const O = S.replace(p, ""), q = p + O;
27
+ C(q), o(O);
28
+ return;
29
+ }
30
+ const t = S.substring(p.length).replace(/\//g, "").replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-_.]/g, "-").replace(/-+/g, "-").replace(/^-+/, "").toLowerCase(), a = (t.match(/\./g) || []).length, d = a <= 1;
31
+ a > 1 ? u("Invalid slug. Only one dot (.) is allowed in the slug") : u(null), i && i(d);
32
+ const N = p + t;
33
+ C(N), o(t);
34
+ }, w = () => {
35
+ if (m.current) {
36
+ const b = m.current;
37
+ setTimeout(() => {
38
+ const S = p.length;
39
+ b.setSelectionRange(S, S);
40
+ }, 0);
41
+ }
42
+ }, B = (b) => {
43
+ const S = b.currentTarget;
44
+ (S.selectionStart || 0) <= p.length && setTimeout(() => {
45
+ const t = p.length;
46
+ S.setSelectionRange(t, t);
47
+ }, 0);
48
+ };
49
+ return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ n("div", { className: "relative", children: [
50
+ /* @__PURE__ */ n("p", { className: "text-gray-500 text-xs mb-2", children: [
51
+ `${p}`,
52
+ " is a dynamic segment of slug"
53
+ ] }),
54
+ /* @__PURE__ */ s(
55
+ M,
56
+ {
57
+ ref: m,
58
+ value: f,
59
+ onChange: F,
60
+ onFocus: w,
61
+ onClick: B,
62
+ placeholder: v,
63
+ className: g ? "border-red-500" : ""
64
+ }
65
+ ),
66
+ g && /* @__PURE__ */ s("div", { className: "text-red-500 text-xs mt-1", children: g })
67
+ ] }) });
68
+ }
69
+ const ce = ({ children: l, onWheel: o, ...v }) => /* @__PURE__ */ s(is, { ...v, onWheel: (i) => {
70
+ try {
71
+ i.preventDefault();
72
+ const g = i.currentTarget;
73
+ g.scrollTop += i.deltaY;
74
+ } catch {
75
+ i.preventDefault();
76
+ }
77
+ o && o(i);
78
+ }, children: l }), fe = (...l) => l.filter(Boolean).join(" ");
79
+ function xs({
80
+ pages: l,
81
+ selectedParentId: o,
82
+ onChange: v,
83
+ className: p,
84
+ id: i = "parentPage",
85
+ currentPage: g
86
+ }) {
87
+ const [u, m] = y(!1), [f, C] = y(""), F = ye("enable-add-page-dropdown");
88
+ F || (p = "w-full rounded-md border border-gray-300 px-3 py-2");
89
+ const w = $(() => !l || l.length === 0 ? [] : l.filter((d) => !Ie(d.slug)).filter((d) => d.slug !== "/").sort((d, N) => d.slug.localeCompare(N.slug)), [l]), B = $(() => {
90
+ if (!f.trim()) return w;
91
+ const a = f.toLowerCase();
92
+ return w.filter(
93
+ (d) => d.name.toLowerCase().includes(a) || d.slug.toLowerCase().includes(a)
94
+ );
95
+ }, [w, f]), b = (a) => Math.max(0, (a.match(/\//g) || []).length - 1), S = (a) => "    ".repeat(a), h = (a) => {
96
+ if (a === "/") return "/";
97
+ const d = a.split("/").filter(Boolean);
98
+ if (d.length <= 1) {
99
+ const N = d[0] || "";
100
+ return `/${te(N)}`;
101
+ }
102
+ return `/${te(d[d.length - 1])}`;
103
+ }, t = () => {
104
+ if (!o || o === "none") return "None";
105
+ const a = w.find((d) => d.id === o);
106
+ return a ? `${a.name} (${h(a.slug)})` : "None";
107
+ };
108
+ return /* @__PURE__ */ n("div", { className: "space-y-0.5", children: [
109
+ /* @__PURE__ */ s(I, { htmlFor: i, className: "text-sm", children: "Parent" }),
110
+ F ? /* @__PURE__ */ n(ee, { open: u, onOpenChange: m, children: [
111
+ /* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ n(
112
+ W,
113
+ {
114
+ id: i,
115
+ variant: "outline",
116
+ role: "combobox",
117
+ className: fe("w-full justify-between", p),
118
+ "data-testid": "parent-page-selector",
119
+ children: [
120
+ t(),
121
+ /* @__PURE__ */ s(re, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
122
+ ]
123
+ }
124
+ ) }),
125
+ /* @__PURE__ */ s(le, { className: "w-[var(--radix-popover-trigger-width)] p-0", align: "start", children: /* @__PURE__ */ n(ne, { shouldFilter: !1, children: [
126
+ /* @__PURE__ */ s("div", { className: "relative border-none py-2", children: /* @__PURE__ */ s("div", { className: "sticky top-0 z-10 bg-white px-3 py-2", children: /* @__PURE__ */ n("div", { className: "relative", children: [
127
+ /* @__PURE__ */ s(ie, { strokeWidth: 2, className: "absolute left-2 top-2 h-4 w-4 text-gray-400" }),
128
+ /* @__PURE__ */ s(
129
+ M,
130
+ {
131
+ placeholder: "Search pages...",
132
+ className: "h-8 pl-8 text-xs",
133
+ value: f,
134
+ onChange: (a) => C(a.target.value)
135
+ }
136
+ )
137
+ ] }) }) }),
138
+ /* @__PURE__ */ n(ce, { className: "max-h-[300px] overflow-y-auto", children: [
139
+ /* @__PURE__ */ s(ae, { children: "No pages found." }),
140
+ /* @__PURE__ */ n(G, { children: [
141
+ /* @__PURE__ */ n(
142
+ R,
143
+ {
144
+ value: "none",
145
+ onSelect: () => {
146
+ v(""), m(!1), C("");
147
+ },
148
+ className: "flex cursor-pointer items-center justify-between",
149
+ children: [
150
+ /* @__PURE__ */ s("span", { children: "None" }),
151
+ /* @__PURE__ */ s(U, { className: fe("mr-2 h-4 w-4", o ? "opacity-0" : "opacity-100") })
152
+ ]
153
+ }
154
+ ),
155
+ B.map((a) => {
156
+ const d = S(b(a.slug)), N = h(a.slug), O = /* @__PURE__ */ n("span", { className: "flex items-center text-sm", children: [
157
+ d,
158
+ a.name,
159
+ /* @__PURE__ */ n("span", { className: "text-xs text-gray-500", children: [
160
+ " (",
161
+ N,
162
+ ")"
163
+ ] })
164
+ ] });
165
+ return /* @__PURE__ */ n(
166
+ R,
167
+ {
168
+ value: a.id,
169
+ onSelect: () => {
170
+ v(a.id), m(!1), C("");
171
+ },
172
+ className: "flex cursor-pointer items-center justify-between whitespace-pre-wrap",
173
+ children: [
174
+ /* @__PURE__ */ s("span", { children: O }),
175
+ /* @__PURE__ */ s(
176
+ U,
177
+ {
178
+ className: fe(
179
+ "mr-2 h-4 w-4 shrink-0",
180
+ o === a.id ? "opacity-100" : "opacity-0"
181
+ )
182
+ }
183
+ )
184
+ ]
185
+ },
186
+ a.id
187
+ );
188
+ })
189
+ ] })
190
+ ] })
191
+ ] }) })
192
+ ] }) : /* @__PURE__ */ n(
193
+ "select",
194
+ {
195
+ id: i,
196
+ value: o || "none",
197
+ onChange: (a) => v(a.target.value),
198
+ className: p,
199
+ "data-testid": "parent-page-selector",
200
+ children: [
201
+ /* @__PURE__ */ s("option", { value: "none", children: "None" }),
202
+ w.map((a) => {
203
+ const d = b(a.slug), N = d > 0 ? S(d) : "", O = h(a.slug);
204
+ return (g == null ? void 0 : g.id) === a.id || a.slug.startsWith(g == null ? void 0 : g.slug) ? null : /* @__PURE__ */ n("option", { value: a.id, children: [
205
+ N,
206
+ a.name,
207
+ " (",
208
+ O,
209
+ ")"
210
+ ] }, a.id);
211
+ })
212
+ ]
213
+ }
214
+ )
215
+ ] });
216
+ }
217
+ const Cs = (...l) => l.filter(Boolean).join(" "), ks = ({
218
+ templates: l,
219
+ selectedTemplateId: o,
220
+ onSelectTemplate: v,
221
+ isLoading: p = !1
222
+ }) => {
223
+ const [i, g] = y(""), [u, m] = y(!1), [f, C] = y(""), F = ye("enable-add-page-dropdown");
224
+ if (Be(() => {
225
+ if (o) {
226
+ const h = l.find((t) => t.id === o);
227
+ g((h == null ? void 0 : h.preview) || "");
228
+ } else
229
+ g("");
230
+ }, [o, l]), p)
231
+ return /* @__PURE__ */ s("div", { className: "flex h-fit items-center justify-center text-sm text-gray-500", children: "Loading templates..." });
232
+ if (l.length === 0)
233
+ return null;
234
+ const w = {};
235
+ l.forEach((h) => {
236
+ const t = h.libraryName;
237
+ w[t] || (w[t] = []), w[t].push(h);
238
+ });
239
+ const B = Object.entries(w).reduce(
240
+ (h, [t, a]) => {
241
+ const d = a.filter(
242
+ (N) => N.name.toLowerCase().includes(f.toLowerCase()) || t.toLowerCase().includes(f.toLowerCase())
243
+ );
244
+ return d.length > 0 && (h[t] = d), h;
245
+ },
246
+ {}
247
+ ), b = l.find((h) => h.id === o), S = b ? de(b.name) : "No Template";
248
+ return /* @__PURE__ */ n("div", { className: "space-y-4", children: [
249
+ F ? /* @__PURE__ */ n(ee, { open: u, onOpenChange: m, children: [
250
+ /* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ n(W, { variant: "outline", role: "combobox", className: "w-full justify-between", children: [
251
+ S,
252
+ /* @__PURE__ */ s(re, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
253
+ ] }) }),
254
+ /* @__PURE__ */ s(le, { className: "w-[var(--radix-popover-trigger-width)] p-0", align: "start", children: /* @__PURE__ */ n(ne, { shouldFilter: !1, children: [
255
+ /* @__PURE__ */ s("div", { className: "sticky top-0 z-10 bg-white px-3 py-2", children: /* @__PURE__ */ n("div", { className: "relative", children: [
256
+ /* @__PURE__ */ s(ie, { strokeWidth: 2, className: "absolute left-2 top-2 h-4 w-4 text-gray-400" }),
257
+ /* @__PURE__ */ s(
258
+ M,
259
+ {
260
+ placeholder: "Search templates...",
261
+ className: "h-8 pl-8 text-xs",
262
+ value: f,
263
+ onChange: (h) => C(h.target.value)
264
+ }
265
+ )
266
+ ] }) }),
267
+ /* @__PURE__ */ n(ce, { className: "max-h-[300px] overflow-y-auto", children: [
268
+ /* @__PURE__ */ s(ae, { children: "No templates found." }),
269
+ Object.entries(B).map(([h, t]) => /* @__PURE__ */ s(G, { heading: h, children: t.map((a) => /* @__PURE__ */ n(
270
+ R,
271
+ {
272
+ value: a.id,
273
+ onSelect: () => {
274
+ v(a.id), m(!1), C("");
275
+ },
276
+ className: "flex cursor-pointer items-center justify-between",
277
+ children: [
278
+ de(a.name),
279
+ /* @__PURE__ */ s(
280
+ U,
281
+ {
282
+ className: Cs(
283
+ "mr-2 h-4 w-4",
284
+ o === a.id ? "opacity-100" : "opacity-0"
285
+ )
286
+ }
287
+ )
288
+ ]
289
+ },
290
+ a.id
291
+ )) }, h))
292
+ ] })
293
+ ] }) })
294
+ ] }) : /* @__PURE__ */ n(
295
+ "select",
296
+ {
297
+ className: "w-full rounded-md border border-gray-300 px-3 py-2",
298
+ value: o,
299
+ onChange: (h) => v(h.target.value),
300
+ children: [
301
+ /* @__PURE__ */ s("option", { value: "", children: "No Template" }),
302
+ Object.entries(w).map(([h, t]) => /* @__PURE__ */ s("optgroup", { label: h, children: t.map((a) => /* @__PURE__ */ s("option", { value: a.id, children: de(a.name) }, a.id)) }, h))
303
+ ]
304
+ }
305
+ ),
306
+ i && /* @__PURE__ */ n("div", { className: "mt-3 overflow-hidden rounded border", children: [
307
+ /* @__PURE__ */ s("div", { className: "max-h-[200px] overflow-auto", children: /* @__PURE__ */ s("img", { src: i, alt: "Template Preview", className: "w-full object-contain" }) }),
308
+ /* @__PURE__ */ s("div", { className: "border-t bg-gray-50 p-2 text-xs text-gray-500", children: "Template preview" })
309
+ ] })
310
+ ] });
311
+ }, Ls = () => {
312
+ const l = Re(), o = Ue();
313
+ return qe({
314
+ queryKey: [oe.GET_LIBRARIES],
315
+ staleTime: "static",
316
+ queryFn: async () => await o(l, { action: oe.GET_LIBRARIES }) || []
317
+ });
318
+ }, Ts = (l) => {
319
+ const o = Re(), v = Ue();
320
+ return qe({
321
+ queryKey: [oe.GET_TEMPLATES_BY_TYPE, l],
322
+ staleTime: "static",
323
+ enabled: !!l,
324
+ queryFn: async () => {
325
+ const p = await v(o, {
326
+ action: oe.GET_TEMPLATES_BY_TYPE,
327
+ data: { pageType: l }
328
+ });
329
+ return (l ? hs(p, { pageType: l }) : p) || [];
330
+ }
331
+ });
332
+ }, js = (l) => {
333
+ const { data: o = [], isLoading: v } = Ts(l), { data: p = [], isLoading: i } = Ls(), g = $(() => v || i ? [] : o.map((m) => {
334
+ const f = ge(p, { id: m.library });
335
+ return {
336
+ ...m,
337
+ libraryName: (f == null ? void 0 : f.type) !== "shared" ? "Site Library" : (f == null ? void 0 : f.name) + " Library",
338
+ libraryType: f == null ? void 0 : f.type
339
+ };
340
+ }), [o, p, v, i]), u = $(() => ps(g, "libraryName"), [g]);
341
+ return {
342
+ data: g,
343
+ groupedData: u,
344
+ isLoading: v || i
345
+ };
346
+ }, V = (...l) => l.filter(Boolean).join(" ");
347
+ function zs({ addEditPage: l, close: o, closePanel: v }) {
348
+ var Ae, Fe;
349
+ const { data: p } = fs(), i = $(() => p ?? [], [p]), g = gs(), u = !!(l != null && l.id), { data: m } = ys(), { mutate: f, isPending: C } = vs(), { mutate: F, isPending: w } = Ns(), [B, b] = y(null), [S, h] = y(!0), [t, a] = y((l == null ? void 0 : l.pageType) ?? "page"), { hasPermission: d } = us(), N = d(bs.CHANGE_PAGE_TYPE), [O, q] = y(!1), [ze, _e] = y(""), { selectedLang: Ve, fallbackLang: Ge } = ms(), ve = Ve || Ge, [Y, Z] = y(""), [Ne, H] = y(!1), be = $(() => {
350
+ const e = i.find((c) => c.key === t);
351
+ return (e == null ? void 0 : e.hasSlug) === !1;
352
+ }, [t, i]), [k, Me] = y((l == null ? void 0 : l.parent) ?? ""), [z, Se] = y((l == null ? void 0 : l.name) ?? ""), [T, we] = y((l == null ? void 0 : l.dynamic) ?? !1), [j, K] = y(T ? "" : ((l == null ? void 0 : l.slug) ?? "").split("/").pop() || ""), [xe, Ce] = y((l == null ? void 0 : l.dynamicSlugCustom) ?? ""), [ke, Ye] = y(!0), [Qe, ue] = y(!1), [me, He] = y(""), { data: Le, isLoading: Ke } = js(t), Q = C || w, Te = ye("enable-add-page-dropdown"), he = $(() => !u || !(l != null && l.id) || !m ? null : m.find((e) => e.id === l.id), [u, l == null ? void 0 : l.id, m]), Ze = (he == null ? void 0 : he.online) || !1, Je = $(() => !u || !(l != null && l.id) || !m ? !1 : m.some((e) => e.parent === l.id), [u, l == null ? void 0 : l.id, m]), r = i.find((e) => e.key === t), _ = (e) => {
353
+ if (u && t !== e) {
354
+ _e(e), q(!0), Z(""), H(!1);
355
+ return;
356
+ }
357
+ a(e), Z(""), H(!1);
358
+ }, je = () => {
359
+ a(ze), q(!1), we(!1);
360
+ }, Xe = (e) => {
361
+ we(e), e ? K("") : Ce("");
362
+ }, Pe = (e) => {
363
+ if (Me(e), e && e !== "none") {
364
+ const c = m == null ? void 0 : m.find((x) => x.id === e), D = (c == null ? void 0 : c.slug) || "";
365
+ if (j.startsWith(D)) {
366
+ const x = j.slice(D.length).replace(/^\/+/, "");
367
+ K(x);
368
+ } else
369
+ K(j.replace(/^\/+/, ""));
370
+ } else
371
+ K(j ? `${j}` : "");
372
+ }, Ee = (e) => {
373
+ He(e);
374
+ }, es = () => z.trim() ? T && !Ie(j) ? (b("Slug must be empty when using dynamic slug"), !1) : T && !ke ? (b("Dynamic slug is invalid"), !1) : !0 : (E.error("Name is required"), !1), ss = () => {
375
+ const e = {
376
+ pageType: r == null ? void 0 : r.key,
377
+ name: z,
378
+ slug: "",
379
+ hasSlug: !1
380
+ };
381
+ u ? F(
382
+ { id: l == null ? void 0 : l.id, name: z },
383
+ {
384
+ onSuccess: () => {
385
+ E.success((r == null ? void 0 : r.name) + " updated successfully"), o();
386
+ }
387
+ }
388
+ ) : f(e, {
389
+ onSuccess: (c) => {
390
+ o(), g(c.page.id, v);
391
+ }
392
+ });
393
+ }, ls = (e, c) => {
394
+ if (!e.trim() && !T)
395
+ return b("Child page slug is required"), !1;
396
+ const D = te(c), x = Oe(D, e);
397
+ return Object.keys(Ss).some((X) => x === `/${X}` || (x == null ? void 0 : x.startsWith(`/${X}/`))) ? (b("Slugs cannot start with a language code for primary page"), !1) : !0;
398
+ }, ns = (e, c) => {
399
+ const D = te(c), x = Oe(D, e), L = {
400
+ pageType: t,
401
+ name: z,
402
+ slug: x.replace(/\/$/, ""),
403
+ // remove trailing slashes
404
+ parent: k,
405
+ dynamic: T,
406
+ hasSlug: !0,
407
+ template: me || void 0,
408
+ tracking: {},
409
+ seo: {},
410
+ jsonLD: {}
411
+ };
412
+ if (T && (L.dynamicSlugCustom = xe), u) {
413
+ const A = ds(L, ["pageType", "parent", "name", "slug", "dynamic", "dynamicSlugCustom"]);
414
+ F(
415
+ { id: l == null ? void 0 : l.id, ...A },
416
+ {
417
+ onSuccess: () => {
418
+ E.success("Page updated successfully"), o();
419
+ }
420
+ }
421
+ );
422
+ } else {
423
+ const A = ge(i, { key: t });
424
+ A != null && A.trackingDefault && (L.tracking = A.trackingDefault);
425
+ const { seo: X, jsonLD: ts } = $e(A, ve);
426
+ P(L, "seo", X), P(L, "jsonLD", ts), f(L, {
427
+ onSuccess: (rs) => {
428
+ o(), g(rs.page.id, v);
429
+ }
430
+ });
431
+ }
432
+ }, as = () => {
433
+ const e = {
434
+ pageType: t,
435
+ name: z,
436
+ slug: j === "" ? "/" : `/${j.replace(/\/$/, "")}`,
437
+ template: me || void 0,
438
+ parent: null,
439
+ tracking: {}
440
+ };
441
+ if (u)
442
+ F(
443
+ { id: l == null ? void 0 : l.id, ...e },
444
+ {
445
+ onSuccess: () => {
446
+ E.success("Page updated successfully"), o();
447
+ }
448
+ }
449
+ );
450
+ else {
451
+ const c = ge(i, { key: t });
452
+ c != null && c.trackingDefault && (e.tracking = c.trackingDefault);
453
+ const { seo: D, jsonLD: x } = $e(c, ve);
454
+ P(e, "seo", D), P(e, "jsonLD", x), f(e, {
455
+ onSuccess: (L) => {
456
+ var A;
457
+ (A = L == null ? void 0 : L.page) != null && A.id && g(L.page.id, v), o();
458
+ }
459
+ });
460
+ }
461
+ }, De = (e) => {
462
+ if (e.preventDefault(), b(null), !!es()) {
463
+ if (!(r != null && r.hasSlug)) {
464
+ ss();
465
+ return;
466
+ }
467
+ if (k && k !== "none") {
468
+ const c = m == null ? void 0 : m.find((x) => x.id === k), D = (c == null ? void 0 : c.slug) || "";
469
+ if (!ls(j, D))
470
+ return;
471
+ ns(j, D);
472
+ } else
473
+ as();
474
+ }
475
+ }, { pagesType: pe, partialsType: J } = $(() => {
476
+ const e = (c) => Y ? c.name.toLowerCase().includes(Y.toLowerCase()) || c.key.toLowerCase().includes(Y.toLowerCase()) : !0;
477
+ return {
478
+ pagesType: i.filter((c) => c.hasSlug !== !1 && e(c)),
479
+ partialsType: i.filter((c) => c.hasSlug === !1 && e(c))
480
+ };
481
+ }, [i, Y]);
482
+ return r != null && r.hasSlug ? /* @__PURE__ */ n("form", { onSubmit: De, className: "mx-auto w-full max-w-md space-y-4", children: [
483
+ /* @__PURE__ */ n("div", { className: "space-y-0.5", children: [
484
+ /* @__PURE__ */ s(I, { htmlFor: "pageType", className: "text-sm", children: "Type" }),
485
+ Te ? /* @__PURE__ */ n(ee, { open: Ne, onOpenChange: H, children: [
486
+ /* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ n(
487
+ W,
488
+ {
489
+ variant: "outline",
490
+ role: "combobox",
491
+ disabled: u && !N,
492
+ className: V(
493
+ "w-full justify-between",
494
+ u && !N ? "cursor-not-allowed text-gray-500" : ""
495
+ ),
496
+ children: [
497
+ (r == null ? void 0 : r.name) || "Select page type",
498
+ /* @__PURE__ */ s(re, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
499
+ ]
500
+ }
501
+ ) }),
502
+ /* @__PURE__ */ s(le, { className: "w-[var(--radix-popover-trigger-width)] p-0", align: "start", children: /* @__PURE__ */ n(ne, { shouldFilter: !1, children: [
503
+ /* @__PURE__ */ s("div", { className: "sticky top-0 z-10 bg-white px-3 py-2", children: /* @__PURE__ */ n("div", { className: "relative", children: [
504
+ /* @__PURE__ */ s(ie, { strokeWidth: 2, className: "absolute left-2 top-2 h-4 w-4 text-gray-400" }),
505
+ /* @__PURE__ */ s(
506
+ M,
507
+ {
508
+ placeholder: "Search page types...",
509
+ className: "h-8 pl-8 text-xs",
510
+ value: Y,
511
+ onChange: (e) => Z(e.target.value)
512
+ }
513
+ )
514
+ ] }) }),
515
+ /* @__PURE__ */ n(ce, { className: "overflow-y-auto", children: [
516
+ /* @__PURE__ */ s(ae, { children: "No page type found." }),
517
+ u ? be ? /* @__PURE__ */ s(G, { heading: "Partials", children: J.map((e) => /* @__PURE__ */ n(
518
+ R,
519
+ {
520
+ value: e.key,
521
+ onSelect: () => _(e.key),
522
+ className: "flex cursor-pointer items-center justify-between",
523
+ children: [
524
+ e.name,
525
+ /* @__PURE__ */ s(
526
+ U,
527
+ {
528
+ className: V("mr-2 h-4 w-4", t === e.key ? "opacity-100" : "opacity-0")
529
+ }
530
+ )
531
+ ]
532
+ },
533
+ e.key
534
+ )) }) : /* @__PURE__ */ s(G, { heading: "Pages", children: pe.map((e) => /* @__PURE__ */ n(
535
+ R,
536
+ {
537
+ value: e.key,
538
+ onSelect: () => _(e.key),
539
+ className: "flex cursor-pointer items-center justify-between",
540
+ children: [
541
+ e.name,
542
+ /* @__PURE__ */ s(
543
+ U,
544
+ {
545
+ className: V("mr-2 h-4 w-4", t === e.key ? "opacity-100" : "opacity-0")
546
+ }
547
+ )
548
+ ]
549
+ },
550
+ e.key
551
+ )) }) : /* @__PURE__ */ n(We, { children: [
552
+ pe.length > 0 && /* @__PURE__ */ s(G, { heading: "Pages", children: pe.map((e) => /* @__PURE__ */ n(
553
+ R,
554
+ {
555
+ value: e.key,
556
+ onSelect: () => _(e.key),
557
+ className: "flex cursor-pointer items-center justify-between",
558
+ children: [
559
+ e.name,
560
+ /* @__PURE__ */ s(
561
+ U,
562
+ {
563
+ className: V("mr-2 h-4 w-4", t === e.key ? "opacity-100" : "opacity-0")
564
+ }
565
+ )
566
+ ]
567
+ },
568
+ e.key
569
+ )) }),
570
+ J.length > 0 && /* @__PURE__ */ s(G, { heading: "Partials", children: J.map((e) => /* @__PURE__ */ n(
571
+ R,
572
+ {
573
+ value: e.key,
574
+ onSelect: () => _(e.key),
575
+ className: "flex cursor-pointer items-center justify-between",
576
+ children: [
577
+ e.name,
578
+ /* @__PURE__ */ s(
579
+ U,
580
+ {
581
+ className: V("mr-2 h-4 w-4", t === e.key ? "opacity-100" : "opacity-0")
582
+ }
583
+ )
584
+ ]
585
+ },
586
+ e.key
587
+ )) })
588
+ ] })
589
+ ] })
590
+ ] }) })
591
+ ] }) : /* @__PURE__ */ s(
592
+ "select",
593
+ {
594
+ id: "pageType",
595
+ value: t,
596
+ disabled: u && !N,
597
+ onChange: (e) => _(e.target.value),
598
+ className: `w-full rounded-md border border-gray-300 px-3 py-2 ${u && !N ? "cursor-not-allowed text-gray-500" : ""}`,
599
+ children: u ? be ? /* @__PURE__ */ s("optgroup", { label: "Partials", children: i.filter((e) => e.hasSlug === !1).map((e) => /* @__PURE__ */ s("option", { value: e.key, children: e.name }, e.key)) }) : /* @__PURE__ */ s("optgroup", { label: "Pages", children: i.filter((e) => e.hasSlug !== !1).map((e) => /* @__PURE__ */ s("option", { value: e.key, children: e.name }, e.key)) }) : /* @__PURE__ */ n(We, { children: [
600
+ /* @__PURE__ */ s("optgroup", { label: "Pages", children: i.filter((e) => e.hasSlug !== !1).map((e) => /* @__PURE__ */ s("option", { value: e.key, children: e.name }, e.key)) }),
601
+ /* @__PURE__ */ s("optgroup", { label: "Partials", children: i.filter((e) => e.hasSlug === !1).map((e) => /* @__PURE__ */ s("option", { value: e.key, children: e.name }, e.key)) })
602
+ ] })
603
+ }
604
+ ),
605
+ O && /* @__PURE__ */ n("div", { className: "mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3", children: [
606
+ /* @__PURE__ */ s("p", { className: "text-sm text-yellow-800", children: "Changing the page type may impact the page data. Are you sure you want to proceed?" }),
607
+ /* @__PURE__ */ n("div", { className: "mt-2 flex gap-2", children: [
608
+ /* @__PURE__ */ s(W, { variant: "outline", size: "sm", onClick: () => q(!1), children: "Cancel" }),
609
+ /* @__PURE__ */ s(W, { variant: "default", size: "sm", onClick: je, children: "Confirm" })
610
+ ] })
611
+ ] })
612
+ ] }),
613
+ !u && (r == null ? void 0 : r.hasSlug) && Le.length > 0 && /* @__PURE__ */ n("div", { className: "space-y-1", children: [
614
+ /* @__PURE__ */ s(I, { className: "mb-1 block text-sm", children: "Template" }),
615
+ /* @__PURE__ */ s(
616
+ ks,
617
+ {
618
+ templates: Le,
619
+ selectedTemplateId: me,
620
+ onSelectTemplate: Ee,
621
+ isLoading: Ke
622
+ }
623
+ )
624
+ ] }),
625
+ /* @__PURE__ */ s(
626
+ xs,
627
+ {
628
+ pages: m,
629
+ selectedParentId: k,
630
+ onChange: Pe,
631
+ currentPage: l
632
+ }
633
+ ),
634
+ /* @__PURE__ */ n("div", { className: "space-y-0.5", children: [
635
+ /* @__PURE__ */ s(I, { htmlFor: "name", className: "text-sm", children: "Name" }),
636
+ /* @__PURE__ */ s(
637
+ M,
638
+ {
639
+ id: "name",
640
+ value: z,
641
+ onChange: (e) => Se(e.target.value),
642
+ required: !0,
643
+ "aria-required": "true",
644
+ placeholder: "Enter page name"
645
+ }
646
+ )
647
+ ] }),
648
+ (r == null ? void 0 : r.dynamicSegments) && k && k !== "none" && /* @__PURE__ */ n("div", { className: "space-y-2", children: [
649
+ /* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
650
+ /* @__PURE__ */ s(
651
+ "input",
652
+ {
653
+ type: "checkbox",
654
+ id: "useDynamicSlug",
655
+ checked: T,
656
+ onChange: (e) => Xe(e.target.checked),
657
+ className: "rounded border-gray-300"
658
+ }
659
+ ),
660
+ /* @__PURE__ */ s(I, { htmlFor: "useDynamicSlug", className: "text-sm", children: "Use Dynamic Slug" })
661
+ ] }),
662
+ T && /* @__PURE__ */ s("div", { className: "space-y-2", children: /* @__PURE__ */ s("div", { className: "space-y-0.5", children: /* @__PURE__ */ s(
663
+ ws,
664
+ {
665
+ value: xe,
666
+ onChange: Ce,
667
+ dynamicPattern: (r == null ? void 0 : r.dynamicSlug) || "{{id}}",
668
+ placeholder: "Enter custom slug part (optional)",
669
+ onValidationChange: Ye
670
+ }
671
+ ) }) })
672
+ ] }),
673
+ (!(r != null && r.dynamicSegments) || !T) && /* @__PURE__ */ n("div", { className: "space-y-0.5", children: [
674
+ /* @__PURE__ */ s(I, { htmlFor: "slug", className: "text-sm", children: "Slug" }),
675
+ /* @__PURE__ */ s(
676
+ cs,
677
+ {
678
+ value: j,
679
+ onChange: (e) => {
680
+ var c;
681
+ K(e), u && e !== (((c = l == null ? void 0 : l.slug) == null ? void 0 : c.split("/").pop()) || "") ? ue(!!(Ze || Je)) : ue(!1);
682
+ },
683
+ placeholder: k && k !== "none" ? "Enter page slug" : t === "page" ? "Leave empty for home page" : "Required - e.g. your-slug",
684
+ parentSlug: k && k !== "none" ? (Fe = m == null ? void 0 : m.find((e) => e.id === k)) == null ? void 0 : Fe.slug : void 0,
685
+ onValidationChange: h
686
+ }
687
+ ),
688
+ B && /* @__PURE__ */ s("p", { className: "text-xs text-red-500", children: B }),
689
+ Qe && /* @__PURE__ */ s("div", { className: "mt-4 rounded-md border border-amber-200 bg-amber-50 p-3", children: /* @__PURE__ */ n("div", { className: "flex items-start space-x-2", children: [
690
+ /* @__PURE__ */ s("div", { className: "flex-shrink-0", children: /* @__PURE__ */ s("svg", { className: "h-5 w-5 text-amber-400", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ s(
691
+ "path",
692
+ {
693
+ fillRule: "evenodd",
694
+ d: "M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",
695
+ clipRule: "evenodd"
696
+ }
697
+ ) }) }),
698
+ /* @__PURE__ */ n("div", { className: "flex-1", children: [
699
+ /* @__PURE__ */ s("h3", { className: "text-sm font-medium text-amber-800", children: "Slug Change Warning" }),
700
+ /* @__PURE__ */ s("div", { className: "mt-1 text-sm text-amber-700", children: /* @__PURE__ */ s("p", { children: "The previous URL and any child pages will become inaccessible. You may want to set up a redirect to avoid broken links." }) })
701
+ ] })
702
+ ] }) })
703
+ ] }),
704
+ /* @__PURE__ */ s(
705
+ W,
706
+ {
707
+ disabled: Q || // Disable if regular slug is invalid and we're not using dynamic slug
708
+ !S && (!(r != null && r.dynamicSegments) || !T) || // Disable if dynamic slug is invalid and we are using dynamic slug
709
+ T && !ke,
710
+ type: "submit",
711
+ className: "w-full",
712
+ children: u ? Q ? "Updating..." : "Update page" : Q ? "Creating..." : "Create Page"
713
+ }
714
+ )
715
+ ] }) : /* @__PURE__ */ n("form", { onSubmit: De, className: "mx-auto w-full max-w-md space-y-4", children: [
716
+ /* @__PURE__ */ n("div", { className: "space-y-0.5", children: [
717
+ /* @__PURE__ */ s(I, { htmlFor: "pageType", className: "text-sm", children: "Type" }),
718
+ Te ? /* @__PURE__ */ n(ee, { open: Ne, onOpenChange: H, children: [
719
+ /* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ n(
720
+ W,
721
+ {
722
+ variant: "outline",
723
+ role: "combobox",
724
+ disabled: u && !N,
725
+ className: V(
726
+ "w-full justify-between",
727
+ u && !N ? "cursor-not-allowed text-gray-500" : ""
728
+ ),
729
+ children: [
730
+ (r == null ? void 0 : r.name) || "Select page type",
731
+ /* @__PURE__ */ s(re, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
732
+ ]
733
+ }
734
+ ) }),
735
+ /* @__PURE__ */ s(le, { className: "w-[var(--radix-popover-trigger-width)] p-0", align: "start", children: /* @__PURE__ */ n(ne, { shouldFilter: !1, children: [
736
+ /* @__PURE__ */ s("div", { className: "sticky top-0 z-10 bg-white px-3 py-2", children: /* @__PURE__ */ n("div", { className: "relative", children: [
737
+ /* @__PURE__ */ s(ie, { strokeWidth: 2, className: "absolute left-2 top-2 h-4 w-4 text-gray-400" }),
738
+ /* @__PURE__ */ s(
739
+ M,
740
+ {
741
+ placeholder: "Search page types...",
742
+ className: "h-8 pl-8 text-xs",
743
+ value: Y,
744
+ onChange: (e) => Z(e.target.value)
745
+ }
746
+ )
747
+ ] }) }),
748
+ /* @__PURE__ */ n(ce, { className: "max-h-[200px] overflow-y-auto", children: [
749
+ /* @__PURE__ */ s(ae, { children: "No page type found." }),
750
+ /* @__PURE__ */ s(G, { heading: "Partials", children: J.map((e) => /* @__PURE__ */ n(
751
+ R,
752
+ {
753
+ value: e.key,
754
+ onSelect: () => {
755
+ _(e.key), H(!1);
756
+ },
757
+ className: "flex cursor-pointer items-center justify-between",
758
+ children: [
759
+ e.name,
760
+ /* @__PURE__ */ s(U, { className: V("mr-2 h-4 w-4", t === e.key ? "opacity-100" : "opacity-0") })
761
+ ]
762
+ },
763
+ e.key
764
+ )) })
765
+ ] })
766
+ ] }) })
767
+ ] }) : /* @__PURE__ */ s(
768
+ "select",
769
+ {
770
+ id: "pageType",
771
+ value: t,
772
+ disabled: u && !N,
773
+ onChange: (e) => _(e.target.value),
774
+ className: `w-full rounded-md border border-gray-300 px-3 py-2 ${u && !N ? "cursor-not-allowed text-gray-500" : ""}`,
775
+ children: /* @__PURE__ */ s("optgroup", { label: "Partials", children: i.filter((e) => e.hasSlug === !1).map((e) => /* @__PURE__ */ s("option", { value: e.key, children: e.name }, e.key)) })
776
+ }
777
+ ),
778
+ O && /* @__PURE__ */ n("div", { className: "mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3", children: [
779
+ /* @__PURE__ */ s("p", { className: "text-sm text-yellow-800", children: "Changing the page type may impact the page data. Are you sure you want to proceed?" }),
780
+ /* @__PURE__ */ n("div", { className: "mt-2 flex gap-2", children: [
781
+ /* @__PURE__ */ s(W, { variant: "outline", size: "sm", onClick: () => q(!1), children: "Cancel" }),
782
+ /* @__PURE__ */ s(W, { variant: "default", size: "sm", onClick: je, children: "Confirm" })
783
+ ] })
784
+ ] }),
785
+ /* @__PURE__ */ s("p", { className: "text-xs text-gray-500", children: (Ae = i.find((e) => e.key === t)) == null ? void 0 : Ae.helpText })
786
+ ] }),
787
+ /* @__PURE__ */ n("div", { className: "space-y-0.5", children: [
788
+ /* @__PURE__ */ s(I, { htmlFor: "name", className: "text-sm", children: "Name" }),
789
+ /* @__PURE__ */ s(M, { id: "name", value: z, onChange: (e) => Se(e.target.value), required: !0, "aria-required": "true" })
790
+ ] }),
791
+ /* @__PURE__ */ s(W, { disabled: Q, type: "submit", className: "w-full", children: u ? Q ? "Updating..." : "Update " + (r == null ? void 0 : r.name) : Q ? "Creating..." : "Create " + (r == null ? void 0 : r.name) })
792
+ ] });
793
+ }
794
+ export {
795
+ zs as default
796
+ };