@chaibuilder/pages 0.16.13 → 0.16.15
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-D1mM4eEh.js → 2AITGKQY-2rt9M99C.js} +5 -5
- package/dist/{2AITGKQY-AK2WgbeT.cjs → 2AITGKQY-Cs6RBSPQ.cjs} +1 -1
- package/dist/{NCMVHL6D-DItDf9IY.cjs → NCMVHL6D-CsC6nsSQ.cjs} +1 -1
- package/dist/{NCMVHL6D-BeRsWdGV.js → NCMVHL6D-vUfYKc6i.js} +2 -2
- package/dist/{ZDWCUMSJ-COSBY-at.cjs → ZDWCUMSJ-B2OZjsr6.cjs} +1 -1
- package/dist/{ZDWCUMSJ-D6caRaY7.js → ZDWCUMSJ-CzEWKlEU.js} +1 -1
- package/dist/active-in-another-tab-B0N5S-Bh.js +34 -0
- package/dist/active-in-another-tab-BK3cZf-x.cjs +1 -0
- package/dist/{add-new-language-page-CQcFi0Tp.cjs → add-new-language-page-Dt1j-8Zg.cjs} +1 -1
- package/dist/{add-new-language-page-nnaUe-qk.js → add-new-language-page-YlqcCdlK.js} +20 -20
- package/dist/{add-new-page-DxObnvo_.cjs → add-new-page-DqhQUQBz.cjs} +1 -1
- package/dist/{add-new-page-Ba1fq6LH.js → add-new-page-aYomeid4.js} +1 -1
- package/dist/ai-panel-content-C6cH9rrC.js +123 -0
- package/dist/ai-panel-content-MOZmNIKP.cjs +1 -0
- package/dist/ai-panel-default-lang-BZHkFsox.js +317 -0
- package/dist/ai-panel-default-lang-DOk_Q0IO.cjs +3 -0
- package/dist/{ai-panel-other-lang-B4euTuod.js → ai-panel-other-lang-D2A46FTg.js} +10 -9
- package/dist/ai-panel-other-lang-qHrdvAMa.cjs +1 -0
- package/dist/ai-prompt-input-BZSjjNJd.cjs +1 -0
- package/dist/ai-prompt-input-C6gDvvLQ.js +1071 -0
- package/dist/{ai-translation-prompt-Ip7w2_Ey.cjs → ai-translation-prompt-BqXo2CLp.cjs} +1 -1
- package/dist/{ai-translation-prompt-CVuPbgXw.js → ai-translation-prompt-DTR0wbGt.js} +1 -1
- package/dist/continue-editing-in-this-client-C3T6Jzhi.cjs +1 -0
- package/dist/continue-editing-in-this-client-D2S1yCOM.js +24 -0
- package/dist/delete-page-BF1k60U2.js +70 -0
- package/dist/delete-page-x0DWKzsR.cjs +1 -0
- package/dist/{digital-asset-manager-CIMo79Di.cjs → digital-asset-manager-BmlFt2T_.cjs} +1 -1
- package/dist/{digital-asset-manager-SAFNO_mx.js → digital-asset-manager-C8udwDBW.js} +1 -1
- package/dist/{duplicate-page-CXK2HcxD.cjs → duplicate-page-Dt_QZkTk.cjs} +1 -1
- package/dist/{duplicate-page-5SwLvmkX.js → duplicate-page-u_6vUVo1.js} +7 -7
- package/dist/{dynamic-page-selector-Crd3y4Hk.cjs → dynamic-page-selector-Cgs_Y_Kl.cjs} +1 -1
- package/dist/{dynamic-page-selector-DfcuTqRN.js → dynamic-page-selector-DxBHmglP.js} +1 -1
- package/dist/index-BeWL6Sj6.cjs +5 -0
- package/dist/index-DI2Rwk5v.js +4820 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -34
- package/dist/index.js +21 -22
- package/dist/{json-diff-viewer-D34kDA_c.cjs → json-diff-viewer-D2g0Yab2.cjs} +1 -1
- package/dist/{json-diff-viewer-CDwpbuag.js → json-diff-viewer-QdUwk7yF.js} +6 -6
- package/dist/{lang-panel-CUIeO5bb.js → lang-panel-B8OD0GiA.js} +24 -24
- package/dist/{lang-panel-CaFrYllL.cjs → lang-panel-M2Zb01lF.cjs} +1 -1
- package/dist/{mark-as-template-D0dLQaIB.js → mark-as-template-CJ1mlxYT.js} +7 -7
- package/dist/{mark-as-template-v182tmN6.cjs → mark-as-template-DONU52b1.cjs} +1 -1
- package/dist/{no-language-page-content-Bk4fEx_p.cjs → no-language-page-content-DD9Ok2Ku.cjs} +1 -1
- package/dist/{no-language-page-content-ByRFD_qA.js → no-language-page-content-Dtm37LTJ.js} +1 -1
- package/dist/no-language-page-dialog-D3dvenZ7.cjs +1 -0
- package/dist/no-language-page-dialog-Dj_z2_hF.js +10 -0
- package/dist/{page-creator-Bh0IUGR3.js → page-creator-DIMFISo4.js} +52 -52
- package/dist/{page-creator-BnvaGZVI.cjs → page-creator-DTC66ujU.cjs} +1 -1
- package/dist/page-lock-CI6BYvF_.cjs +1 -0
- package/dist/page-lock-DUlNr3os.js +30 -0
- package/dist/page-locked-dialog-BKwULMV7.js +133 -0
- package/dist/page-locked-dialog-DorIbva0.cjs +1 -0
- package/dist/page-manager-new-lNVrLOJp.cjs +1 -0
- package/dist/page-manager-new-znvqI9_L.js +354 -0
- package/dist/{page-manager-search-and-filter-BETHSa3y.js → page-manager-search-and-filter-C-_w7N27.js} +1 -1
- package/dist/{page-manager-search-and-filter-hyUIHOD_.cjs → page-manager-search-and-filter-pe0q0qnZ.cjs} +1 -1
- package/dist/{page-revisions-content-BCMjvZRZ.cjs → page-revisions-content-Caaj5TEI.cjs} +1 -1
- package/dist/{page-revisions-content-VWthKL7O.js → page-revisions-content-CyLjyxNU.js} +16 -16
- package/dist/pages.css +1 -1
- package/dist/publish-pages-content-Bih1W9C4.js +178 -0
- package/dist/publish-pages-content-D5beVcQI.cjs +1 -0
- package/dist/{save-to-lib-YYBxY7MV.js → save-to-lib-BwpkJcT2.js} +1 -1
- package/dist/{save-to-lib-CtGpDkC6.cjs → save-to-lib-DPAERsi4.cjs} +1 -1
- package/dist/{selected-block-display-DdW-DWF1.js → selected-block-display-GXSf3y2s.js} +1 -1
- package/dist/{selected-block-display-BEbuJn0l.cjs → selected-block-display-s99Y91qI.cjs} +1 -1
- package/dist/{seo-panel-CqJDhbj-.js → seo-panel-BurZA566.js} +61 -61
- package/dist/{seo-panel-B9P7fXjo.cjs → seo-panel-BxUfalVy.cjs} +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +39 -39
- package/dist/{shared-json-ld-CyxmC9y5.cjs → shared-json-ld-BYAdrPeC.cjs} +1 -1
- package/dist/{shared-json-ld-DxEPILj_.js → shared-json-ld-DHWdJvQd.js} +39 -39
- package/dist/{slug-input-RNiSrU3p.cjs → slug-input-CR2B1kDJ.cjs} +1 -1
- package/dist/{slug-input-j5z5ZQn9.js → slug-input-Z_ny7bgX.js} +1 -1
- package/dist/take-over-request-CnEpToCM.cjs +1 -0
- package/dist/take-over-request-DF2JsIes.js +63 -0
- package/dist/{theme-panel-footer-DD2yalfG.js → theme-panel-footer-5mxFeEua.js} +4 -4
- package/dist/{theme-panel-footer-CCsiDIVl.cjs → theme-panel-footer-C2CjHoBu.cjs} +1 -1
- package/dist/{unmark-as-template-DXjLbqOM.cjs → unmark-as-template-Dn90g1eh.cjs} +1 -1
- package/dist/{unmark-as-template-B2hKhAHn.js → unmark-as-template-JRRUYTOY.js} +1 -1
- package/dist/{unpublish-page-BdJScWMX.cjs → unpublish-page-C3C_rTRd.cjs} +1 -1
- package/dist/{unpublish-page-BvB1PGSz.js → unpublish-page-FZ8rbi7u.js} +9 -9
- package/dist/{web-preview-CwVpkcwU.js → web-preview-CGBKG162.js} +1 -1
- package/dist/{web-preview-BI4jd0O7.cjs → web-preview-NdxC92Fk.cjs} +1 -1
- package/package.json +3 -3
- package/dist/ai-panel-content-B2AgBWqo.cjs +0 -1
- package/dist/ai-panel-content-M1UnzG_f.js +0 -54
- package/dist/ai-panel-default-lang-CHOFEwmV.js +0 -313
- package/dist/ai-panel-default-lang-sy6vkQJh.cjs +0 -3
- package/dist/ai-panel-other-lang-BwjSDD3L.cjs +0 -1
- package/dist/ai-prompt-input-B_NRADBT.js +0 -988
- package/dist/ai-prompt-input-DcyVXcLG.cjs +0 -1
- package/dist/delete-page-CbY8q5M3.cjs +0 -1
- package/dist/delete-page-SX9X35nA.js +0 -40
- package/dist/index-Bz7smSC0.cjs +0 -5
- package/dist/index-EnM7J19_.js +0 -4960
- package/dist/page-lock-request-C2b1kqyA.cjs +0 -1
- package/dist/page-lock-request-CaNqxfD6.js +0 -75
- package/dist/page-locked-by-dialog--WLDdkw9.js +0 -68
- package/dist/page-locked-by-dialog-90ElC8aG.cjs +0 -1
- package/dist/page-manager-new-Bo4-zwfW.js +0 -354
- package/dist/page-manager-new-SNRQn7Az.cjs +0 -1
- package/dist/publish-pages-content-6N7aEcM1.js +0 -178
- package/dist/publish-pages-content-CaBwfekc.cjs +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as s, jsxs as n, Fragment as We } from "react/jsx-runtime";
|
|
2
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
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-
|
|
4
|
+
import { r as te, S as cs, c as Oe } from "./slug-input-Z_ny7bgX.js";
|
|
5
5
|
import { useChaiFeatureFlag as ye, usePermissions as us, useLanguages as ms } from "@chaibuilder/sdk";
|
|
6
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
7
|
import { ChevronDown as re, Search as ie, Check as U } from "lucide-react";
|
|
8
|
-
import {
|
|
9
|
-
import { useQuery as
|
|
8
|
+
import { aq as Re, ar as Ue, A as oe, m as fs, as as gs, g as ys, h as vs, i as Ns, ay as Ss, L as bs } from "./index-DI2Rwk5v.js";
|
|
9
|
+
import { useQuery as qe } from "@tanstack/react-query";
|
|
10
10
|
import { toast as E } from "sonner";
|
|
11
11
|
import { g as $e } from "./get-seo-defaults-9zHebckY.js";
|
|
12
12
|
function ws({
|
|
@@ -20,30 +20,30 @@ function ws({
|
|
|
20
20
|
Be(() => {
|
|
21
21
|
C(p + l);
|
|
22
22
|
}, [l, p]);
|
|
23
|
-
const F = (
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
26
|
-
const O =
|
|
27
|
-
C(
|
|
23
|
+
const F = (S) => {
|
|
24
|
+
const b = S.target.value;
|
|
25
|
+
if (!b.startsWith(p)) {
|
|
26
|
+
const O = b.replace(p, ""), q = p + O;
|
|
27
|
+
C(q), o(O);
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
const t =
|
|
30
|
+
const t = b.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
31
|
a > 1 ? u("Invalid slug. Only one dot (.) is allowed in the slug") : u(null), i && i(d);
|
|
32
32
|
const N = p + t;
|
|
33
33
|
C(N), o(t);
|
|
34
34
|
}, w = () => {
|
|
35
35
|
if (m.current) {
|
|
36
|
-
const
|
|
36
|
+
const S = m.current;
|
|
37
37
|
setTimeout(() => {
|
|
38
|
-
const
|
|
39
|
-
|
|
38
|
+
const b = p.length;
|
|
39
|
+
S.setSelectionRange(b, b);
|
|
40
40
|
}, 0);
|
|
41
41
|
}
|
|
42
|
-
}, B = (
|
|
43
|
-
const
|
|
44
|
-
(
|
|
42
|
+
}, B = (S) => {
|
|
43
|
+
const b = S.currentTarget;
|
|
44
|
+
(b.selectionStart || 0) <= p.length && setTimeout(() => {
|
|
45
45
|
const t = p.length;
|
|
46
|
-
|
|
46
|
+
b.setSelectionRange(t, t);
|
|
47
47
|
}, 0);
|
|
48
48
|
};
|
|
49
49
|
return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ n("div", { className: "relative", children: [
|
|
@@ -92,7 +92,7 @@ function xs({
|
|
|
92
92
|
return w.filter(
|
|
93
93
|
(d) => d.name.toLowerCase().includes(a) || d.slug.toLowerCase().includes(a)
|
|
94
94
|
);
|
|
95
|
-
}, [w, f]),
|
|
95
|
+
}, [w, f]), S = (a) => Math.max(0, (a.match(/\//g) || []).length - 1), b = (a) => " ".repeat(a), h = (a) => {
|
|
96
96
|
if (a === "/") return "/";
|
|
97
97
|
const d = a.split("/").filter(Boolean);
|
|
98
98
|
if (d.length <= 1) {
|
|
@@ -153,7 +153,7 @@ function xs({
|
|
|
153
153
|
}
|
|
154
154
|
),
|
|
155
155
|
B.map((a) => {
|
|
156
|
-
const d = S(
|
|
156
|
+
const d = b(S(a.slug)), N = h(a.slug), O = /* @__PURE__ */ n("span", { className: "flex items-center text-sm", children: [
|
|
157
157
|
d,
|
|
158
158
|
a.name,
|
|
159
159
|
/* @__PURE__ */ n("span", { className: "text-xs text-gray-500", children: [
|
|
@@ -200,7 +200,7 @@ function xs({
|
|
|
200
200
|
children: [
|
|
201
201
|
/* @__PURE__ */ s("option", { value: "none", children: "None" }),
|
|
202
202
|
w.map((a) => {
|
|
203
|
-
const d =
|
|
203
|
+
const d = S(a.slug), N = d > 0 ? b(d) : "", O = h(a.slug);
|
|
204
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
205
|
N,
|
|
206
206
|
a.name,
|
|
@@ -244,11 +244,11 @@ const Cs = (...l) => l.filter(Boolean).join(" "), ks = ({
|
|
|
244
244
|
return d.length > 0 && (h[t] = d), h;
|
|
245
245
|
},
|
|
246
246
|
{}
|
|
247
|
-
),
|
|
247
|
+
), S = l.find((h) => h.id === o), b = S ? de(S.name) : "No Template";
|
|
248
248
|
return /* @__PURE__ */ n("div", { className: "space-y-4", children: [
|
|
249
249
|
F ? /* @__PURE__ */ n(ee, { open: u, onOpenChange: m, children: [
|
|
250
250
|
/* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ n(W, { variant: "outline", role: "combobox", className: "w-full justify-between", children: [
|
|
251
|
-
|
|
251
|
+
b,
|
|
252
252
|
/* @__PURE__ */ s(re, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
|
|
253
253
|
] }) }),
|
|
254
254
|
/* @__PURE__ */ s(le, { className: "w-[var(--radix-popover-trigger-width)] p-0", align: "start", children: /* @__PURE__ */ n(ne, { shouldFilter: !1, children: [
|
|
@@ -310,14 +310,14 @@ const Cs = (...l) => l.filter(Boolean).join(" "), ks = ({
|
|
|
310
310
|
] });
|
|
311
311
|
}, Ls = () => {
|
|
312
312
|
const l = Re(), o = Ue();
|
|
313
|
-
return
|
|
313
|
+
return qe({
|
|
314
314
|
queryKey: [oe.GET_LIBRARIES],
|
|
315
315
|
staleTime: "static",
|
|
316
316
|
queryFn: async () => await o(l, { action: oe.GET_LIBRARIES }) || []
|
|
317
317
|
});
|
|
318
318
|
}, Ts = (l) => {
|
|
319
319
|
const o = Re(), v = Ue();
|
|
320
|
-
return
|
|
320
|
+
return qe({
|
|
321
321
|
queryKey: [oe.GET_TEMPLATES_BY_TYPE, l],
|
|
322
322
|
staleTime: "static",
|
|
323
323
|
enabled: !!l,
|
|
@@ -344,19 +344,19 @@ const Cs = (...l) => l.filter(Boolean).join(" "), ks = ({
|
|
|
344
344
|
isLoading: v || i
|
|
345
345
|
};
|
|
346
346
|
}, V = (...l) => l.filter(Boolean).join(" ");
|
|
347
|
-
function
|
|
347
|
+
function zs({ addEditPage: l, close: o, closePanel: v }) {
|
|
348
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,
|
|
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, S] = y(null), [b, h] = y(!0), [t, a] = y((l == null ? void 0 : l.pageType) ?? "page"), { hasPermission: d } = us(), N = d(Ss.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), Se = $(() => {
|
|
350
350
|
const e = i.find((c) => c.key === t);
|
|
351
351
|
return (e == null ? void 0 : e.hasSlug) === !1;
|
|
352
|
-
}, [t, i]), [k, Me] = y((l == null ? void 0 : l.parent) ?? ""), [
|
|
352
|
+
}, [t, i]), [k, Me] = y((l == null ? void 0 : l.parent) ?? ""), [z, be] = 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
353
|
if (u && t !== e) {
|
|
354
|
-
|
|
354
|
+
_e(e), q(!0), Z(""), H(!1);
|
|
355
355
|
return;
|
|
356
356
|
}
|
|
357
357
|
a(e), Z(""), H(!1);
|
|
358
358
|
}, je = () => {
|
|
359
|
-
a(
|
|
359
|
+
a(ze), q(!1), we(!1);
|
|
360
360
|
}, Xe = (e) => {
|
|
361
361
|
we(e), e ? K("") : Ce("");
|
|
362
362
|
}, Pe = (e) => {
|
|
@@ -371,15 +371,15 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
371
371
|
K(j ? `${j}` : "");
|
|
372
372
|
}, Ee = (e) => {
|
|
373
373
|
He(e);
|
|
374
|
-
}, es = () =>
|
|
374
|
+
}, es = () => z.trim() ? T && !Ie(j) ? (S("Slug must be empty when using dynamic slug"), !1) : T && !ke ? (S("Dynamic slug is invalid"), !1) : !0 : (E.error("Name is required"), !1), ss = () => {
|
|
375
375
|
const e = {
|
|
376
376
|
pageType: r == null ? void 0 : r.key,
|
|
377
|
-
name:
|
|
377
|
+
name: z,
|
|
378
378
|
slug: "",
|
|
379
379
|
hasSlug: !1
|
|
380
380
|
};
|
|
381
381
|
u ? F(
|
|
382
|
-
{ id: l == null ? void 0 : l.id, name:
|
|
382
|
+
{ id: l == null ? void 0 : l.id, name: z },
|
|
383
383
|
{
|
|
384
384
|
onSuccess: () => {
|
|
385
385
|
E.success((r == null ? void 0 : r.name) + " updated successfully"), o();
|
|
@@ -392,13 +392,13 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
392
392
|
});
|
|
393
393
|
}, ls = (e, c) => {
|
|
394
394
|
if (!e.trim() && !T)
|
|
395
|
-
return
|
|
395
|
+
return S("Child page slug is required"), !1;
|
|
396
396
|
const D = te(c), x = Oe(D, e);
|
|
397
|
-
return Object.keys(
|
|
397
|
+
return Object.keys(bs).some((X) => x === `/${X}` || (x == null ? void 0 : x.startsWith(`/${X}/`))) ? (S("Slugs cannot start with a language code for primary page"), !1) : !0;
|
|
398
398
|
}, ns = (e, c) => {
|
|
399
399
|
const D = te(c), x = Oe(D, e), L = {
|
|
400
400
|
pageType: t,
|
|
401
|
-
name:
|
|
401
|
+
name: z,
|
|
402
402
|
slug: x.replace(/\/$/, ""),
|
|
403
403
|
// remove trailing slashes
|
|
404
404
|
parent: k,
|
|
@@ -432,7 +432,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
432
432
|
}, as = () => {
|
|
433
433
|
const e = {
|
|
434
434
|
pageType: t,
|
|
435
|
-
name:
|
|
435
|
+
name: z,
|
|
436
436
|
slug: j === "" ? "/" : `/${j.replace(/\/$/, "")}`,
|
|
437
437
|
template: me || void 0,
|
|
438
438
|
parent: null,
|
|
@@ -459,7 +459,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
459
459
|
});
|
|
460
460
|
}
|
|
461
461
|
}, De = (e) => {
|
|
462
|
-
if (e.preventDefault(),
|
|
462
|
+
if (e.preventDefault(), S(null), !!es()) {
|
|
463
463
|
if (!(r != null && r.hasSlug)) {
|
|
464
464
|
ss();
|
|
465
465
|
return;
|
|
@@ -514,11 +514,11 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
514
514
|
] }) }),
|
|
515
515
|
/* @__PURE__ */ n(ce, { className: "overflow-y-auto", children: [
|
|
516
516
|
/* @__PURE__ */ s(ae, { children: "No page type found." }),
|
|
517
|
-
u ?
|
|
517
|
+
u ? Se ? /* @__PURE__ */ s(G, { heading: "Partials", children: J.map((e) => /* @__PURE__ */ n(
|
|
518
518
|
R,
|
|
519
519
|
{
|
|
520
520
|
value: e.key,
|
|
521
|
-
onSelect: () =>
|
|
521
|
+
onSelect: () => _(e.key),
|
|
522
522
|
className: "flex cursor-pointer items-center justify-between",
|
|
523
523
|
children: [
|
|
524
524
|
e.name,
|
|
@@ -535,7 +535,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
535
535
|
R,
|
|
536
536
|
{
|
|
537
537
|
value: e.key,
|
|
538
|
-
onSelect: () =>
|
|
538
|
+
onSelect: () => _(e.key),
|
|
539
539
|
className: "flex cursor-pointer items-center justify-between",
|
|
540
540
|
children: [
|
|
541
541
|
e.name,
|
|
@@ -553,7 +553,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
553
553
|
R,
|
|
554
554
|
{
|
|
555
555
|
value: e.key,
|
|
556
|
-
onSelect: () =>
|
|
556
|
+
onSelect: () => _(e.key),
|
|
557
557
|
className: "flex cursor-pointer items-center justify-between",
|
|
558
558
|
children: [
|
|
559
559
|
e.name,
|
|
@@ -571,7 +571,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
571
571
|
R,
|
|
572
572
|
{
|
|
573
573
|
value: e.key,
|
|
574
|
-
onSelect: () =>
|
|
574
|
+
onSelect: () => _(e.key),
|
|
575
575
|
className: "flex cursor-pointer items-center justify-between",
|
|
576
576
|
children: [
|
|
577
577
|
e.name,
|
|
@@ -594,9 +594,9 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
594
594
|
id: "pageType",
|
|
595
595
|
value: t,
|
|
596
596
|
disabled: u && !N,
|
|
597
|
-
onChange: (e) =>
|
|
597
|
+
onChange: (e) => _(e.target.value),
|
|
598
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 ?
|
|
599
|
+
children: u ? Se ? /* @__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
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
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
602
|
] })
|
|
@@ -605,7 +605,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
605
605
|
O && /* @__PURE__ */ n("div", { className: "mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3", children: [
|
|
606
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
607
|
/* @__PURE__ */ n("div", { className: "mt-2 flex gap-2", children: [
|
|
608
|
-
/* @__PURE__ */ s(W, { variant: "outline", size: "sm", onClick: () =>
|
|
608
|
+
/* @__PURE__ */ s(W, { variant: "outline", size: "sm", onClick: () => q(!1), children: "Cancel" }),
|
|
609
609
|
/* @__PURE__ */ s(W, { variant: "default", size: "sm", onClick: je, children: "Confirm" })
|
|
610
610
|
] })
|
|
611
611
|
] })
|
|
@@ -637,8 +637,8 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
637
637
|
M,
|
|
638
638
|
{
|
|
639
639
|
id: "name",
|
|
640
|
-
value:
|
|
641
|
-
onChange: (e) =>
|
|
640
|
+
value: z,
|
|
641
|
+
onChange: (e) => be(e.target.value),
|
|
642
642
|
required: !0,
|
|
643
643
|
"aria-required": "true",
|
|
644
644
|
placeholder: "Enter page name"
|
|
@@ -705,7 +705,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
705
705
|
W,
|
|
706
706
|
{
|
|
707
707
|
disabled: Q || // Disable if regular slug is invalid and we're not using dynamic slug
|
|
708
|
-
!
|
|
708
|
+
!b && (!(r != null && r.dynamicSegments) || !T) || // Disable if dynamic slug is invalid and we are using dynamic slug
|
|
709
709
|
T && !ke,
|
|
710
710
|
type: "submit",
|
|
711
711
|
className: "w-full",
|
|
@@ -752,7 +752,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
752
752
|
{
|
|
753
753
|
value: e.key,
|
|
754
754
|
onSelect: () => {
|
|
755
|
-
|
|
755
|
+
_(e.key), H(!1);
|
|
756
756
|
},
|
|
757
757
|
className: "flex cursor-pointer items-center justify-between",
|
|
758
758
|
children: [
|
|
@@ -770,7 +770,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
770
770
|
id: "pageType",
|
|
771
771
|
value: t,
|
|
772
772
|
disabled: u && !N,
|
|
773
|
-
onChange: (e) =>
|
|
773
|
+
onChange: (e) => _(e.target.value),
|
|
774
774
|
className: `w-full rounded-md border border-gray-300 px-3 py-2 ${u && !N ? "cursor-not-allowed text-gray-500" : ""}`,
|
|
775
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
776
|
}
|
|
@@ -778,7 +778,7 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
778
778
|
O && /* @__PURE__ */ n("div", { className: "mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3", children: [
|
|
779
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
780
|
/* @__PURE__ */ n("div", { className: "mt-2 flex gap-2", children: [
|
|
781
|
-
/* @__PURE__ */ s(W, { variant: "outline", size: "sm", onClick: () =>
|
|
781
|
+
/* @__PURE__ */ s(W, { variant: "outline", size: "sm", onClick: () => q(!1), children: "Cancel" }),
|
|
782
782
|
/* @__PURE__ */ s(W, { variant: "default", size: "sm", onClick: je, children: "Confirm" })
|
|
783
783
|
] })
|
|
784
784
|
] }),
|
|
@@ -786,11 +786,11 @@ function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
786
786
|
] }),
|
|
787
787
|
/* @__PURE__ */ n("div", { className: "space-y-0.5", children: [
|
|
788
788
|
/* @__PURE__ */ s(I, { htmlFor: "name", className: "text-sm", children: "Name" }),
|
|
789
|
-
/* @__PURE__ */ s(M, { id: "name", value:
|
|
789
|
+
/* @__PURE__ */ s(M, { id: "name", value: z, onChange: (e) => be(e.target.value), required: !0, "aria-required": "true" })
|
|
790
790
|
] }),
|
|
791
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
792
|
] });
|
|
793
793
|
}
|
|
794
794
|
export {
|
|
795
|
-
|
|
795
|
+
zs as default
|
|
796
796
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),i=require("react"),$=require("./slug-input-RNiSrU3p.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-Bz7smSC0.cjs"),je=require("@tanstack/react-query"),J=require("sonner"),fe=require("./get-seo-defaults-Cw7vFt-B.cjs");function Ue({value:t,onChange:c,placeholder:j="Enter custom slug part",dynamicPattern:p,onValidationChange:o}){const[f,m]=i.useState(null),h=i.useRef(null),[g,L]=i.useState(p+t);i.useEffect(()=>{L(p+t)},[t,p]);const B=v=>{const S=v.target.value;if(!S.startsWith(p)){const O=S.replace(p,""),R=p+O;L(R),c(O);return}const l=S.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),a=(l.match(/\./g)||[]).length,x=a<=1;a>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),o&&o(x);const y=p+l;L(y),c(l)},N=()=>{if(h.current){const v=h.current;setTimeout(()=>{const S=p.length;v.setSelectionRange(S,S)},0)}},W=v=>{const S=v.currentTarget;(S.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;S.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"text-gray-500 text-xs mb-2",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(n.Input,{ref:h,value:g,onChange:B,onFocus:N,onClick:W,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"text-red-500 text-xs mt-1",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=o=>{try{o.preventDefault();const f=o.currentTarget;f.scrollTop+=o.deltaY}catch{o.preventDefault()}c&&c(o)};return e.jsx(n.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function $e({pages:t,selectedParentId:c,onChange:j,className:p,id:o="parentPage",currentPage:f}){const[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");B||(p="w-full rounded-md border border-gray-300 px-3 py-2");const N=i.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!b.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),W=i.useMemo(()=>{if(!g.trim())return N;const a=g.toLowerCase();return N.filter(x=>x.name.toLowerCase().includes(a)||x.slug.toLowerCase().includes(a))},[N,g]),v=a=>Math.max(0,(a.match(/\//g)||[]).length-1),S=a=>" ".repeat(a),d=a=>{if(a==="/")return"/";const x=a.split("/").filter(Boolean);if(x.length<=1){const y=x[0]||"";return`/${$.removeSlugExtension(y)}`}return`/${$.removeSlugExtension(x[x.length-1])}`},l=()=>{if(!c||c==="none")return"None";const a=N.find(x=>x.id===c);return a?`${a.name} (${d(a.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:o,className:"text-sm",children:"Parent"}),B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{id:o,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"relative border-none py-2",children:e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:a=>L(a.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No pages found."}),e.jsxs(n.CommandGroup,{children:[e.jsxs(n.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),W.map(a=>{const x=S(v(a.slug)),y=d(a.slug),O=e.jsxs("span",{className:"flex items-center text-sm",children:[x,a.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:O}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===a.id?"opacity-100":"opacity-0")})]},a.id)})]})]})]})})]}):e.jsxs("select",{id:o,value:c||"none",onChange:a=>j(a.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),N.map(a=>{const x=v(a.slug),y=x>0?S(x):"",O=d(a.slug);return(f==null?void 0:f.id)===a.id||a.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:a.id,children:[y,a.name," (",O,")"]},a.id)})]})]})}const ze=(...t)=>t.filter(Boolean).join(" "),_e=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[o,f]=i.useState(""),[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");if(i.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);f((d==null?void 0:d.preview)||"")}else f("")},[c,t]),p)return e.jsx("div",{className:"flex h-fit items-center justify-center text-sm text-gray-500",children:"Loading templates..."});if(t.length===0)return null;const N={};t.forEach(d=>{const l=d.libraryName;N[l]||(N[l]=[]),N[l].push(d)});const W=Object.entries(N).reduce((d,[l,a])=>{const x=a.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),v=t.find(d=>d.id===c),S=v?b.startCase(v.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[S,e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>L(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No templates found."}),Object.entries(W).map(([d,l])=>e.jsx(n.CommandGroup,{heading:d,children:l.map(a=>e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[b.startCase(a.name),e.jsx(C.Check,{className:ze("mr-2 h-4 w-4",c===a.id?"opacity-100":"opacity-0")})]},a.id))},d))]})]})})]}):e.jsxs("select",{className:"w-full rounded-md border border-gray-300 px-3 py-2",value:c,onChange:d=>j(d.target.value),children:[e.jsx("option",{value:"",children:"No Template"}),Object.entries(N).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(a=>e.jsx("option",{value:a.id,children:b.startCase(a.name)},a.id))},d))]}),o&&e.jsxs("div",{className:"mt-3 overflow-hidden rounded border",children:[e.jsx("div",{className:"max-h-[200px] overflow-auto",children:e.jsx("img",{src:o,alt:"Template Preview",className:"w-full object-contain"})}),e.jsx("div",{className:"border-t bg-gray-50 p-2 text-xs text-gray-500",children:"Template preview"})]})]})},Ve=()=>{const t=w.useApiUrl(),c=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:w.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=w.useApiUrl(),j=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:w.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?b.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:o}=Ve(),f=i.useMemo(()=>j||o?[]:c.map(h=>{const g=b.find(p,{id:h.library});return{...h,libraryName:(g==null?void 0:g.type)!=="shared"?"Site Library":(g==null?void 0:g.name)+" Library",libraryType:g==null?void 0:g.type}}),[c,p,j,o]),m=i.useMemo(()=>b.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||o}},U=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=w.usePageTypes(),o=i.useMemo(()=>p??[],[p]),f=w.useChangePage(),m=!!(t!=null&&t.id),{data:h}=w.useWebsitePages(),{mutate:g,isPending:L}=w.useCreatePage(),{mutate:B,isPending:N}=w.useUpdatePage(),[W,v]=i.useState(null),[S,d]=i.useState(!0),[l,a]=i.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=Y.usePermissions(),y=x(w.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[O,R]=i.useState(!1),[ye,ve]=i.useState(""),{selectedLang:Se,fallbackLang:Ce}=Y.useLanguages(),ne=Se||Ce,[z,H]=i.useState(""),[ae,V]=i.useState(!1),le=i.useMemo(()=>{const s=o.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,o]),[T,Ne]=i.useState((t==null?void 0:t.parent)??""),[G,re]=i.useState((t==null?void 0:t.name)??""),[I,oe]=i.useState((t==null?void 0:t.dynamic)??!1),[F,Q]=i.useState(I?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=i.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=i.useState(!0),[we,P]=i.useState(!1),[E,ke]=i.useState(""),{data:me,isLoading:Le}=Ye(l),_=L||N,he=Y.useChaiFeatureFlag("enable-add-page-dropdown"),ee=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?null:h.find(s=>s.id===t.id),[m,t==null?void 0:t.id,h]),Te=(ee==null?void 0:ee.online)||!1,De=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=o.find(s=>s.key===l),M=s=>{if(m&&l!==s){ve(s),R(!0),H(""),V(!1);return}a(s),H(""),V(!1)},pe=()=>{a(ye),R(!1),oe(!1)},Ie=s=>{oe(s),s?Q(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(k=>k.id===s),q=(u==null?void 0:u.slug)||"";if(F.startsWith(q)){const k=F.slice(q.length).replace(/^\/+/,"");Q(k)}else Q(F.replace(/^\/+/,""))}else Q(F?`${F}`:"")},qe=s=>{ke(s)},Ae=()=>G.trim()?I&&!b.isEmpty(F)?(v("Slug must be empty when using dynamic slug"),!1):I&&!ue?(v("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Be=()=>{const s={pageType:r==null?void 0:r.key,name:G,slug:"",hasSlug:!1};m?B({id:t==null?void 0:t.id,name:G},{onSuccess:()=>{J.toast.success((r==null?void 0:r.name)+" updated successfully"),c()}}):g(s,{onSuccess:u=>{c(),f(u.page.id,j)}})},Oe=(s,u)=>{if(!s.trim()&&!I)return v("Child page slug is required"),!1;const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s);return Object.keys(w.LANGUAGES).some(Z=>k===`/${Z}`||(k==null?void 0:k.startsWith(`/${Z}/`)))?(v("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s),D={pageType:l,name:G,slug:k.replace(/\/$/,""),parent:T,dynamic:I,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(I&&(D.dynamicSlugCustom=ie),m){const A=b.pick(D,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);B({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=b.find(o,{key:l});A!=null&&A.trackingDefault&&(D.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);b.set(D,"seo",Z),b.set(D,"jsonLD",Ge),g(D,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:G,slug:F===""?"/":`/${F.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)B({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=b.find(o,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:k}=fe.getSeoDefaults(u,ne);b.set(s,"seo",q),b.set(s,"jsonLD",k),g(s,{onSuccess:D=>{var A;(A=D==null?void 0:D.page)!=null&&A.id&&f(D.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),v(null),!!Ae()){if(!(r!=null&&r.hasSlug)){Be();return}if(T&&T!=="none"){const u=h==null?void 0:h.find(k=>k.id===T),q=(u==null?void 0:u.slug)||"";if(!Oe(F,q))return;We(F,q)}else Re()}},{pagesType:se,partialsType:K}=i.useMemo(()=>{const s=u=>z?u.name.toLowerCase().includes(z.toLowerCase())||u.key.toLowerCase().includes(z.toLowerCase()):!0;return{pagesType:o.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:o.filter(u=>u.hasSlug===!1&&s(u))}},[o,z]);return r!=null&&r.hasSlug?e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsxs(e.Fragment,{children:[se.length>0&&e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:m?le?e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]})]}),!m&&(r==null?void 0:r.hasSlug)&&me.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(n.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(_e,{templates:me,selectedTemplateId:E,onSelectTemplate:qe,isLoading:Le})]}),e.jsx($e,{pages:h,selectedParentId:T,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&T&&T!=="none"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:I,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(n.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),I&&e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"space-y-0.5",children:e.jsx(Ue,{value:ie,onChange:ce,dynamicPattern:(r==null?void 0:r.dynamicSlug)||"{{id}}",placeholder:"Enter custom slug part (optional)",onValidationChange:be})})})]}),(!(r!=null&&r.dynamicSegments)||!I)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx($.SlugInput,{value:F,onChange:s=>{var u;Q(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:T&&T!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:T&&T!=="none"?(ge=h==null?void 0:h.find(s=>s.id===T))==null?void 0:ge.slug:void 0,onValidationChange:d}),W&&e.jsx("p",{className:"text-xs text-red-500",children:W}),we&&e.jsx("div",{className:"mt-4 rounded-md border border-amber-200 bg-amber-50 p-3",children:e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-amber-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",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",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-amber-800",children:"Slug Change Warning"}),e.jsx("div",{className:"mt-1 text-sm text-amber-700",children:e.jsx("p",{children:"The previous URL and any child pages will become inaccessible. You may want to set up a redirect to avoid broken links."})})]})]})})]}),e.jsx(n.Button,{disabled:_||!S&&(!(r!=null&&r.dynamicSegments)||!I)||I&&!ue,type:"submit",className:"w-full",children:m?_?"Updating...":"Update page":_?"Creating...":"Create Page"})]}):e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>{M(s.key),V(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=o.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(n.Button,{disabled:_,type:"submit",className:"w-full",children:m?_?"Updating...":"Update "+(r==null?void 0:r.name):_?"Creating...":"Create "+(r==null?void 0:r.name)})]})}exports.default=He;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),i=require("react"),$=require("./slug-input-CR2B1kDJ.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-BeWL6Sj6.cjs"),je=require("@tanstack/react-query"),J=require("sonner"),fe=require("./get-seo-defaults-Cw7vFt-B.cjs");function Ue({value:t,onChange:c,placeholder:j="Enter custom slug part",dynamicPattern:p,onValidationChange:o}){const[f,m]=i.useState(null),h=i.useRef(null),[g,L]=i.useState(p+t);i.useEffect(()=>{L(p+t)},[t,p]);const B=v=>{const S=v.target.value;if(!S.startsWith(p)){const O=S.replace(p,""),R=p+O;L(R),c(O);return}const l=S.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),a=(l.match(/\./g)||[]).length,x=a<=1;a>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),o&&o(x);const y=p+l;L(y),c(l)},N=()=>{if(h.current){const v=h.current;setTimeout(()=>{const S=p.length;v.setSelectionRange(S,S)},0)}},W=v=>{const S=v.currentTarget;(S.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;S.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"text-gray-500 text-xs mb-2",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(n.Input,{ref:h,value:g,onChange:B,onFocus:N,onClick:W,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"text-red-500 text-xs mt-1",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=o=>{try{o.preventDefault();const f=o.currentTarget;f.scrollTop+=o.deltaY}catch{o.preventDefault()}c&&c(o)};return e.jsx(n.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function $e({pages:t,selectedParentId:c,onChange:j,className:p,id:o="parentPage",currentPage:f}){const[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");B||(p="w-full rounded-md border border-gray-300 px-3 py-2");const N=i.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!b.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),W=i.useMemo(()=>{if(!g.trim())return N;const a=g.toLowerCase();return N.filter(x=>x.name.toLowerCase().includes(a)||x.slug.toLowerCase().includes(a))},[N,g]),v=a=>Math.max(0,(a.match(/\//g)||[]).length-1),S=a=>" ".repeat(a),d=a=>{if(a==="/")return"/";const x=a.split("/").filter(Boolean);if(x.length<=1){const y=x[0]||"";return`/${$.removeSlugExtension(y)}`}return`/${$.removeSlugExtension(x[x.length-1])}`},l=()=>{if(!c||c==="none")return"None";const a=N.find(x=>x.id===c);return a?`${a.name} (${d(a.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:o,className:"text-sm",children:"Parent"}),B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{id:o,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"relative border-none py-2",children:e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:a=>L(a.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No pages found."}),e.jsxs(n.CommandGroup,{children:[e.jsxs(n.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),W.map(a=>{const x=S(v(a.slug)),y=d(a.slug),O=e.jsxs("span",{className:"flex items-center text-sm",children:[x,a.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:O}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===a.id?"opacity-100":"opacity-0")})]},a.id)})]})]})]})})]}):e.jsxs("select",{id:o,value:c||"none",onChange:a=>j(a.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),N.map(a=>{const x=v(a.slug),y=x>0?S(x):"",O=d(a.slug);return(f==null?void 0:f.id)===a.id||a.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:a.id,children:[y,a.name," (",O,")"]},a.id)})]})]})}const ze=(...t)=>t.filter(Boolean).join(" "),_e=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[o,f]=i.useState(""),[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");if(i.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);f((d==null?void 0:d.preview)||"")}else f("")},[c,t]),p)return e.jsx("div",{className:"flex h-fit items-center justify-center text-sm text-gray-500",children:"Loading templates..."});if(t.length===0)return null;const N={};t.forEach(d=>{const l=d.libraryName;N[l]||(N[l]=[]),N[l].push(d)});const W=Object.entries(N).reduce((d,[l,a])=>{const x=a.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),v=t.find(d=>d.id===c),S=v?b.startCase(v.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[S,e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>L(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No templates found."}),Object.entries(W).map(([d,l])=>e.jsx(n.CommandGroup,{heading:d,children:l.map(a=>e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[b.startCase(a.name),e.jsx(C.Check,{className:ze("mr-2 h-4 w-4",c===a.id?"opacity-100":"opacity-0")})]},a.id))},d))]})]})})]}):e.jsxs("select",{className:"w-full rounded-md border border-gray-300 px-3 py-2",value:c,onChange:d=>j(d.target.value),children:[e.jsx("option",{value:"",children:"No Template"}),Object.entries(N).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(a=>e.jsx("option",{value:a.id,children:b.startCase(a.name)},a.id))},d))]}),o&&e.jsxs("div",{className:"mt-3 overflow-hidden rounded border",children:[e.jsx("div",{className:"max-h-[200px] overflow-auto",children:e.jsx("img",{src:o,alt:"Template Preview",className:"w-full object-contain"})}),e.jsx("div",{className:"border-t bg-gray-50 p-2 text-xs text-gray-500",children:"Template preview"})]})]})},Ve=()=>{const t=w.useApiUrl(),c=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:w.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=w.useApiUrl(),j=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:w.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?b.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:o}=Ve(),f=i.useMemo(()=>j||o?[]:c.map(h=>{const g=b.find(p,{id:h.library});return{...h,libraryName:(g==null?void 0:g.type)!=="shared"?"Site Library":(g==null?void 0:g.name)+" Library",libraryType:g==null?void 0:g.type}}),[c,p,j,o]),m=i.useMemo(()=>b.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||o}},U=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=w.usePageTypes(),o=i.useMemo(()=>p??[],[p]),f=w.useChangePage(),m=!!(t!=null&&t.id),{data:h}=w.useWebsitePages(),{mutate:g,isPending:L}=w.useCreatePage(),{mutate:B,isPending:N}=w.useUpdatePage(),[W,v]=i.useState(null),[S,d]=i.useState(!0),[l,a]=i.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=Y.usePermissions(),y=x(w.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[O,R]=i.useState(!1),[ye,ve]=i.useState(""),{selectedLang:Se,fallbackLang:Ce}=Y.useLanguages(),ne=Se||Ce,[z,H]=i.useState(""),[ae,V]=i.useState(!1),le=i.useMemo(()=>{const s=o.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,o]),[T,Ne]=i.useState((t==null?void 0:t.parent)??""),[G,re]=i.useState((t==null?void 0:t.name)??""),[I,oe]=i.useState((t==null?void 0:t.dynamic)??!1),[F,Q]=i.useState(I?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=i.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=i.useState(!0),[we,P]=i.useState(!1),[E,ke]=i.useState(""),{data:me,isLoading:Le}=Ye(l),_=L||N,he=Y.useChaiFeatureFlag("enable-add-page-dropdown"),ee=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?null:h.find(s=>s.id===t.id),[m,t==null?void 0:t.id,h]),Te=(ee==null?void 0:ee.online)||!1,De=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=o.find(s=>s.key===l),M=s=>{if(m&&l!==s){ve(s),R(!0),H(""),V(!1);return}a(s),H(""),V(!1)},pe=()=>{a(ye),R(!1),oe(!1)},Ie=s=>{oe(s),s?Q(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(k=>k.id===s),q=(u==null?void 0:u.slug)||"";if(F.startsWith(q)){const k=F.slice(q.length).replace(/^\/+/,"");Q(k)}else Q(F.replace(/^\/+/,""))}else Q(F?`${F}`:"")},qe=s=>{ke(s)},Ae=()=>G.trim()?I&&!b.isEmpty(F)?(v("Slug must be empty when using dynamic slug"),!1):I&&!ue?(v("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Be=()=>{const s={pageType:r==null?void 0:r.key,name:G,slug:"",hasSlug:!1};m?B({id:t==null?void 0:t.id,name:G},{onSuccess:()=>{J.toast.success((r==null?void 0:r.name)+" updated successfully"),c()}}):g(s,{onSuccess:u=>{c(),f(u.page.id,j)}})},Oe=(s,u)=>{if(!s.trim()&&!I)return v("Child page slug is required"),!1;const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s);return Object.keys(w.LANGUAGES).some(Z=>k===`/${Z}`||(k==null?void 0:k.startsWith(`/${Z}/`)))?(v("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s),D={pageType:l,name:G,slug:k.replace(/\/$/,""),parent:T,dynamic:I,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(I&&(D.dynamicSlugCustom=ie),m){const A=b.pick(D,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);B({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=b.find(o,{key:l});A!=null&&A.trackingDefault&&(D.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);b.set(D,"seo",Z),b.set(D,"jsonLD",Ge),g(D,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:G,slug:F===""?"/":`/${F.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)B({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=b.find(o,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:k}=fe.getSeoDefaults(u,ne);b.set(s,"seo",q),b.set(s,"jsonLD",k),g(s,{onSuccess:D=>{var A;(A=D==null?void 0:D.page)!=null&&A.id&&f(D.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),v(null),!!Ae()){if(!(r!=null&&r.hasSlug)){Be();return}if(T&&T!=="none"){const u=h==null?void 0:h.find(k=>k.id===T),q=(u==null?void 0:u.slug)||"";if(!Oe(F,q))return;We(F,q)}else Re()}},{pagesType:se,partialsType:K}=i.useMemo(()=>{const s=u=>z?u.name.toLowerCase().includes(z.toLowerCase())||u.key.toLowerCase().includes(z.toLowerCase()):!0;return{pagesType:o.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:o.filter(u=>u.hasSlug===!1&&s(u))}},[o,z]);return r!=null&&r.hasSlug?e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsxs(e.Fragment,{children:[se.length>0&&e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:m?le?e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]})]}),!m&&(r==null?void 0:r.hasSlug)&&me.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(n.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(_e,{templates:me,selectedTemplateId:E,onSelectTemplate:qe,isLoading:Le})]}),e.jsx($e,{pages:h,selectedParentId:T,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&T&&T!=="none"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:I,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(n.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),I&&e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"space-y-0.5",children:e.jsx(Ue,{value:ie,onChange:ce,dynamicPattern:(r==null?void 0:r.dynamicSlug)||"{{id}}",placeholder:"Enter custom slug part (optional)",onValidationChange:be})})})]}),(!(r!=null&&r.dynamicSegments)||!I)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx($.SlugInput,{value:F,onChange:s=>{var u;Q(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:T&&T!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:T&&T!=="none"?(ge=h==null?void 0:h.find(s=>s.id===T))==null?void 0:ge.slug:void 0,onValidationChange:d}),W&&e.jsx("p",{className:"text-xs text-red-500",children:W}),we&&e.jsx("div",{className:"mt-4 rounded-md border border-amber-200 bg-amber-50 p-3",children:e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-amber-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",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",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-amber-800",children:"Slug Change Warning"}),e.jsx("div",{className:"mt-1 text-sm text-amber-700",children:e.jsx("p",{children:"The previous URL and any child pages will become inaccessible. You may want to set up a redirect to avoid broken links."})})]})]})})]}),e.jsx(n.Button,{disabled:_||!S&&(!(r!=null&&r.dynamicSegments)||!I)||I&&!ue,type:"submit",className:"w-full",children:m?_?"Updating...":"Update page":_?"Creating...":"Create Page"})]}):e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>{M(s.key),V(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=o.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(n.Button,{disabled:_,type:"submit",className:"w-full",children:m?_?"Updating...":"Update "+(r==null?void 0:r.name):_?"Creating...":"Create "+(r==null?void 0:r.name)})]})}exports.default=He;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("./index-BeWL6Sj6.cjs"),E=require("@tanstack/react-query"),r=require("react"),c=r.lazy(()=>Promise.resolve().then(()=>require("./take-over-request-CnEpToCM.cjs"))),o=r.lazy(()=>Promise.resolve().then(()=>require("./page-locked-dialog-DorIbva0.cjs"))),l=r.lazy(()=>Promise.resolve().then(()=>require("./active-in-another-tab-BK3cZf-x.cjs"))),S=r.lazy(()=>Promise.resolve().then(()=>require("./continue-editing-in-this-client-C3T6Jzhi.cjs"))),n=s=>u.jsx(r.Suspense,{children:u.jsx(s,{})}),A=({isFetchingPageData:s})=>{e.useChaibuilderRealtime();const{pageStatus:t}=e.usePageLockStatus(),{pageLockMeta:a}=e.usePageLockMeta(),T=E.useQueryClient(),i=r.useRef(t);if(r.useEffect(()=>{t===e.PAGE_STATUS.EDITING&&i.current!==e.PAGE_STATUS.TAKE_OVER_REQUESTED&&T.invalidateQueries({queryKey:[e.ACTIONS.GET_DRAFT_PAGE]}),i.current=t},[t,T]),s)return null;switch(t){case e.PAGE_STATUS.EDITING:case e.PAGE_STATUS.CHECKING:case e.PAGE_STATUS.FORCE_TAKE_OVER:return a.type===e.EVENT.CONTINUE_EDITING_IN_THIS_CLIENT?n(S):null;case e.PAGE_STATUS.LOCKED:return n(o);case e.PAGE_STATUS.TAKE_OVER_REQUESTED:return n(c);case e.PAGE_STATUS.ACTIVE_IN_ANOTHER_TAB:return n(l);case e.PAGE_STATUS.CONNECTION_LOST:return u.jsx(e.BlurContainer,{children:null});default:return null}};exports.default=A;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { u as E, a as c, b as T, P as e, A as l, B as I, E as _ } from "./index-DI2Rwk5v.js";
|
|
3
|
+
import { useQueryClient as C } from "@tanstack/react-query";
|
|
4
|
+
import { lazy as s, useRef as p, useEffect as N, Suspense as A } from "react";
|
|
5
|
+
const m = s(() => import("./take-over-request-DF2JsIes.js")), f = s(() => import("./page-locked-dialog-BKwULMV7.js")), O = s(() => import("./active-in-another-tab-B0N5S-Bh.js")), S = s(() => import("./continue-editing-in-this-client-D2S1yCOM.js")), r = (a) => /* @__PURE__ */ n(A, { children: /* @__PURE__ */ n(a, {}) }), L = ({ isFetchingPageData: a }) => {
|
|
6
|
+
E();
|
|
7
|
+
const { pageStatus: t } = c(), { pageLockMeta: o } = T(), u = C(), i = p(t);
|
|
8
|
+
if (N(() => {
|
|
9
|
+
t === e.EDITING && i.current !== e.TAKE_OVER_REQUESTED && u.invalidateQueries({ queryKey: [l.GET_DRAFT_PAGE] }), i.current = t;
|
|
10
|
+
}, [t, u]), a) return null;
|
|
11
|
+
switch (t) {
|
|
12
|
+
case e.EDITING:
|
|
13
|
+
case e.CHECKING:
|
|
14
|
+
case e.FORCE_TAKE_OVER:
|
|
15
|
+
return o.type === _.CONTINUE_EDITING_IN_THIS_CLIENT ? r(S) : null;
|
|
16
|
+
case e.LOCKED:
|
|
17
|
+
return r(f);
|
|
18
|
+
case e.TAKE_OVER_REQUESTED:
|
|
19
|
+
return r(m);
|
|
20
|
+
case e.ACTIVE_IN_ANOTHER_TAB:
|
|
21
|
+
return r(O);
|
|
22
|
+
case e.CONNECTION_LOST:
|
|
23
|
+
return /* @__PURE__ */ n(I, { children: null });
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
L as default
|
|
30
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { jsx as e, jsxs as t } from "react/jsx-runtime";
|
|
2
|
+
import { ap as _, an as w, a as A, ao as S, b as F, B as K, E as a, P as I } from "./index-DI2Rwk5v.js";
|
|
3
|
+
import { useTranslation as U } from "@chaibuilder/sdk";
|
|
4
|
+
import { Card as V, CardHeader as q, CardTitle as Q, CardContent as P, Button as p, CardFooter as j, Accordion as B, AccordionItem as D, AccordionTrigger as L, AccordionContent as G } from "@chaibuilder/sdk/ui";
|
|
5
|
+
import { LockKeyhole as H, UserIcon as J, AlertCircleIcon as z, X, Edit as W, ShieldAlert as v } from "lucide-react";
|
|
6
|
+
import { useState as f, useRef as Y, useEffect as Z } from "react";
|
|
7
|
+
const ae = () => {
|
|
8
|
+
const o = _(), x = w(), { setPageStatus: T } = A(), { data: r, isFetching: k } = S((o == null ? void 0 : o.userId) || ""), { pageLockMeta: l, setPageLockMeta: E } = F(), { t: s } = U(), [d, c] = f(""), [n, g] = f({}), [N, b] = f(!1), i = Y(null);
|
|
9
|
+
Z(() => {
|
|
10
|
+
l != null && l.type && (i.current && clearTimeout(i.current), g(l), E({}), c(""));
|
|
11
|
+
}, [l, E]);
|
|
12
|
+
const R = () => {
|
|
13
|
+
d !== a.TAKE_OVER_REQUEST && (c(a.TAKE_OVER_REQUEST), x(a.TAKE_OVER_REQUEST), i.current = setTimeout(() => c(""), 2e4));
|
|
14
|
+
}, C = () => {
|
|
15
|
+
d !== a.FORCE_TAKE_OVER_REQUEST && (c(a.FORCE_TAKE_OVER_REQUEST), x(a.FORCE_TAKE_OVER_REQUEST), T(I.CHECKING), i.current = setTimeout(() => c(""), 2e4));
|
|
16
|
+
}, y = () => {
|
|
17
|
+
g({}), i.current && clearTimeout(i.current), c("");
|
|
18
|
+
}, m = k ? "Loading..." : (r == null ? void 0 : r.name) || "Current editor", u = d === a.TAKE_OVER_REQUEST, h = d === a.FORCE_TAKE_OVER_REQUEST;
|
|
19
|
+
return /* @__PURE__ */ e(K, { children: /* @__PURE__ */ t(V, { className: "mx-auto w-full max-w-md", children: [
|
|
20
|
+
/* @__PURE__ */ e(q, { className: "space-y-1 border-b pb-3", children: /* @__PURE__ */ t(Q, { className: "flex items-center gap-2 text-xl", children: [
|
|
21
|
+
/* @__PURE__ */ e(H, { className: "h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500" }),
|
|
22
|
+
/* @__PURE__ */ e("span", { children: s("Page Locked for Editing") })
|
|
23
|
+
] }) }),
|
|
24
|
+
/* @__PURE__ */ t(P, { className: "space-y-4 p-4", children: [
|
|
25
|
+
/* @__PURE__ */ t("div", { className: "relative rounded-md border border-green-500 px-2 pb-2 pt-4", children: [
|
|
26
|
+
/* @__PURE__ */ e("div", { className: "absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white", children: "Current Editor" }),
|
|
27
|
+
/* @__PURE__ */ t("div", { className: "flex items-center space-x-4 p-1", children: [
|
|
28
|
+
r != null && r.avatar ? /* @__PURE__ */ e(
|
|
29
|
+
"img",
|
|
30
|
+
{
|
|
31
|
+
src: r.avatar,
|
|
32
|
+
alt: r.name,
|
|
33
|
+
className: "h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"
|
|
34
|
+
}
|
|
35
|
+
) : /* @__PURE__ */ e(J, { className: "h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white" }),
|
|
36
|
+
/* @__PURE__ */ t("div", { className: "flex-1 space-y-0", children: [
|
|
37
|
+
/* @__PURE__ */ e("div", { className: "truncate font-medium leading-tight text-black", children: m }),
|
|
38
|
+
(r == null ? void 0 : r.email) && /* @__PURE__ */ e("p", { className: "truncate text-sm leading-tight text-muted-foreground", children: r.email })
|
|
39
|
+
] })
|
|
40
|
+
] })
|
|
41
|
+
] }),
|
|
42
|
+
((n == null ? void 0 : n.type) === a.TAKE_OVER_REJECTED || (n == null ? void 0 : n.type) === a.FORCE_TAKE_OVER_REQUEST) && /* @__PURE__ */ e("section", { className: "space-y-2", children: /* @__PURE__ */ t("div", { className: "flex items-center justify-between gap-x-2 rounded border border-red-500 bg-red-500/10 py-2 pl-3 pr-2 text-sm font-medium text-red-500", children: [
|
|
43
|
+
/* @__PURE__ */ t("div", { className: "flex items-start gap-x-2", children: [
|
|
44
|
+
/* @__PURE__ */ e(z, { className: "mt-px flex h-4 w-4 shrink-0" }),
|
|
45
|
+
/* @__PURE__ */ t("div", { className: "font-light leading-tight", children: [
|
|
46
|
+
/* @__PURE__ */ e("span", { className: "font-medium", children: (r == null ? void 0 : r.name) || "The current editor" }),
|
|
47
|
+
(n == null ? void 0 : n.type) === a.TAKE_OVER_REJECTED ? " rejected your take over request." : " forcefully took over this page."
|
|
48
|
+
] })
|
|
49
|
+
] }),
|
|
50
|
+
/* @__PURE__ */ e(p, { size: "icon", variant: "ghost", onClick: y, className: "flex-shrink-0", children: /* @__PURE__ */ e(X, { className: "h-4 w-4" }) })
|
|
51
|
+
] }) })
|
|
52
|
+
] }),
|
|
53
|
+
/* @__PURE__ */ e(j, { className: "flex flex-col gap-3 border-t pt-3", children: /* @__PURE__ */ t("section", { className: "space-y-2", children: [
|
|
54
|
+
/* @__PURE__ */ e("h3", { className: "text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: s("Take Over Options") }),
|
|
55
|
+
/* @__PURE__ */ t("div", { className: "rounded-md border bg-muted/40 p-3", children: [
|
|
56
|
+
/* @__PURE__ */ t("div", { className: "mb-2", children: [
|
|
57
|
+
/* @__PURE__ */ e("p", { className: "text-sm font-medium", children: s("Take Over Request:") }),
|
|
58
|
+
/* @__PURE__ */ e("p", { className: "mt-1 text-xs text-muted-foreground", children: s(
|
|
59
|
+
"Send a request to {{currentEditorName}} asking them to release the page. They can accept or decline your request.",
|
|
60
|
+
{ currentEditorName: m }
|
|
61
|
+
) })
|
|
62
|
+
] }),
|
|
63
|
+
/* @__PURE__ */ t(
|
|
64
|
+
p,
|
|
65
|
+
{
|
|
66
|
+
disabled: u,
|
|
67
|
+
variant: "default",
|
|
68
|
+
onClick: R,
|
|
69
|
+
className: "mt-3 w-full gap-2",
|
|
70
|
+
children: [
|
|
71
|
+
/* @__PURE__ */ e(W, { className: "h-4 w-4" }),
|
|
72
|
+
u ? "Take over request sent" : "Send Take Over Request"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
),
|
|
76
|
+
u && /* @__PURE__ */ e("p", { className: "mt-2 text-xs text-muted-foreground", children: s("Request sent. If no response, try again or use force take over.") })
|
|
77
|
+
] }),
|
|
78
|
+
/* @__PURE__ */ e(B, { type: "single", collapsible: !0, className: "w-full", children: /* @__PURE__ */ t(
|
|
79
|
+
D,
|
|
80
|
+
{
|
|
81
|
+
value: "force-takeover",
|
|
82
|
+
className: "rounded-md border border-destructive/40 bg-destructive/5",
|
|
83
|
+
children: [
|
|
84
|
+
/* @__PURE__ */ e(L, { className: "px-3 py-2 hover:no-underline", children: /* @__PURE__ */ e("div", { className: "flex items-center gap-2 text-left", children: /* @__PURE__ */ t("div", { children: [
|
|
85
|
+
/* @__PURE__ */ t("p", { className: "flex items-center gap-x-2 text-sm font-medium text-destructive", children: [
|
|
86
|
+
/* @__PURE__ */ e(v, { className: "h-4 w-4 text-destructive" }),
|
|
87
|
+
s("Force Take Over")
|
|
88
|
+
] }),
|
|
89
|
+
/* @__PURE__ */ e("p", { className: "pl-6 text-xs font-normal leading-tight text-muted-foreground", children: s("Immediately take control (use with caution)") })
|
|
90
|
+
] }) }) }),
|
|
91
|
+
/* @__PURE__ */ e(G, { className: "px-3 pb-3", children: /* @__PURE__ */ t("div", { className: "space-y-3", children: [
|
|
92
|
+
/* @__PURE__ */ t("div", { className: "flex items-start gap-2 rounded-md border border-destructive/40 bg-background p-2", children: [
|
|
93
|
+
/* @__PURE__ */ e(
|
|
94
|
+
"input",
|
|
95
|
+
{
|
|
96
|
+
type: "checkbox",
|
|
97
|
+
id: "force-takeover",
|
|
98
|
+
checked: N,
|
|
99
|
+
onChange: (O) => b(O.target.checked),
|
|
100
|
+
className: "mt-0.5 h-4 w-4 rounded border-gray-300"
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
/* @__PURE__ */ e("label", { htmlFor: "force-takeover", className: "flex-1 text-xs text-muted-foreground", children: s(
|
|
104
|
+
"I understand this will immediately close the editor for {{currentEditorName}}. I am using this option with caution.",
|
|
105
|
+
{ currentEditorName: m }
|
|
106
|
+
) })
|
|
107
|
+
] }),
|
|
108
|
+
/* @__PURE__ */ t(
|
|
109
|
+
p,
|
|
110
|
+
{
|
|
111
|
+
disabled: !N || h,
|
|
112
|
+
variant: "destructive",
|
|
113
|
+
onClick: C,
|
|
114
|
+
className: "w-full gap-2",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ e(v, { className: "h-4 w-4" }),
|
|
117
|
+
s(h ? "Take over page..." : "Force Take Over")
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
),
|
|
121
|
+
h && /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: s(
|
|
122
|
+
"Attempting to forcefully take over this page. Please wait while we update the editing session."
|
|
123
|
+
) })
|
|
124
|
+
] }) })
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
) })
|
|
128
|
+
] }) })
|
|
129
|
+
] }) });
|
|
130
|
+
};
|
|
131
|
+
export {
|
|
132
|
+
ae as default
|
|
133
|
+
};
|