@chaibuilder/sdk 4.0.0-beta.35 → 4.0.0-beta.36
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/{2SSKDMRQ-CZ0Vy6ir.cjs → 2SSKDMRQ-C3eivR9y.cjs} +1 -1
- package/dist/{2SSKDMRQ-Ce8xH_EE.js → 2SSKDMRQ-rk5vFzuv.js} +5 -5
- package/dist/{AP7HFJJL-C_GhxNzR.cjs → AP7HFJJL-2qWLZyWT.cjs} +1 -1
- package/dist/{AP7HFJJL-DxRUcy8z.js → AP7HFJJL-BMK2jPSi.js} +1 -1
- package/dist/{WDYDFRGG-JMA9G17v.js → WDYDFRGG-1zoPbvu7.js} +6 -6
- package/dist/{WDYDFRGG-DPPgf9Va.cjs → WDYDFRGG-Bfra_-3l.cjs} +1 -1
- package/dist/{actions-registery-CKEzH855.js → actions-registery-CMKfEXxX.js} +235 -301
- package/dist/{actions-registery-Byid-s6S.cjs → actions-registery-CqhNZFV3.cjs} +13 -13
- package/dist/actions.cjs +1 -1
- package/dist/actions.js +2 -2
- package/dist/{active-in-another-tab-CcCrhl7z.cjs → active-in-another-tab-DkOOxZwb.cjs} +1 -1
- package/dist/{active-in-another-tab-C-E0cjyu.js → active-in-another-tab-Zrq6x3L9.js} +1 -1
- package/dist/{add-new-language-page-DIAFT7Au.cjs → add-new-language-page-Dsze4PNK.cjs} +1 -1
- package/dist/{add-new-language-page-D93yJKtJ.js → add-new-language-page-alqCh26P.js} +1 -1
- package/dist/{add-new-page-D2IBnynJ.cjs → add-new-page-DtQYPRYM.cjs} +1 -1
- package/dist/{add-new-page-DaBpJeHK.js → add-new-page-HoFoI257.js} +1 -1
- package/dist/{ai-panel-content-DAXG0iZN.js → ai-panel-content-DZmolAf1.js} +2 -2
- package/dist/{ai-panel-content-CZO5fG_R.cjs → ai-panel-content-DcM2BBcL.cjs} +1 -1
- package/dist/{ai-panel-default-lang-CwnsdDO8.cjs → ai-panel-default-lang-BmVJcDnH.cjs} +1 -1
- package/dist/{ai-panel-default-lang-KI9kwEt7.js → ai-panel-default-lang-Bv8Fms5X.js} +1 -1
- package/dist/{ai-panel-other-lang-BpGRrcQQ.cjs → ai-panel-other-lang-BGyP45jz.cjs} +1 -1
- package/dist/{ai-panel-other-lang-DgyCpBVD.js → ai-panel-other-lang-CCGz4Tql.js} +2 -2
- package/dist/{ai-translation-prompt-BQ0OW9F_.cjs → ai-translation-prompt-DWj1gmKg.cjs} +1 -1
- package/dist/{ai-translation-prompt-Cs39rmRE.js → ai-translation-prompt-DXhM0OnM.js} +1 -1
- package/dist/{change-password-modal-CdrJct2d.cjs → change-password-modal-BcJsR8sq.cjs} +1 -1
- package/dist/{change-password-modal-CfZ3KoDT.js → change-password-modal-D4wVoj8S.js} +1 -1
- package/dist/{continue-editing-in-this-client-BkHlxvfG.cjs → continue-editing-in-this-client-BHbRZL8A.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-BqgTDohA.js → continue-editing-in-this-client-CoZnDfgk.js} +1 -1
- package/dist/{delete-page-Vn6P6hEV.cjs → delete-page-DKBN4nL1.cjs} +1 -1
- package/dist/{delete-page-BIP7fPy_.js → delete-page-T2VWcbyP.js} +1 -1
- package/dist/{digital-asset-manager-aSXb6slG.js → digital-asset-manager-B1KUqVJc.js} +1 -1
- package/dist/{digital-asset-manager-BoNm3Q2W.cjs → digital-asset-manager-DYMrQhJ7.cjs} +1 -1
- package/dist/{duplicate-page-C46afThg.js → duplicate-page-Bt36erFD.js} +14 -14
- package/dist/{duplicate-page-CwFCJNwW.cjs → duplicate-page-Cop50Nuj.cjs} +1 -1
- package/dist/{dynamic-page-selector-txjqS5jX.cjs → dynamic-page-selector-DxJ80Cpv.cjs} +1 -1
- package/dist/{dynamic-page-selector-IT9LZDro.js → dynamic-page-selector-jMUcjGtc.js} +1 -1
- package/dist/index-DvOWqGdC.cjs +5 -0
- package/dist/{index-Bh0hrlXu.js → index-K4yKMKbY.js} +700 -681
- package/dist/{json-diff-viewer-CTsxzkiu.cjs → json-diff-viewer-BisiaC_I.cjs} +1 -1
- package/dist/{json-diff-viewer-D1Y_t-v4.js → json-diff-viewer-CivVPp1k.js} +33 -33
- package/dist/{lang-panel-irJl_yAH.js → lang-panel-DejZsTqE.js} +22 -22
- package/dist/{lang-panel-BUXBHMCZ.cjs → lang-panel-DoPGR_AP.cjs} +1 -1
- package/dist/{mark-as-template-DqIqHM7P.js → mark-as-template-NPUbCfae.js} +1 -1
- package/dist/{mark-as-template-Dr-qn1H7.cjs → mark-as-template-OqwiT2Zm.cjs} +1 -1
- package/dist/{no-language-page-content-Cb8CviKU.cjs → no-language-page-content-BGlAr__k.cjs} +1 -1
- package/dist/{no-language-page-content-DQK5hRDH.js → no-language-page-content-DfdMEUqE.js} +1 -1
- package/dist/{no-language-page-dialog-Bw_oSBFM.js → no-language-page-dialog-3obqd_9-.js} +2 -2
- package/dist/{no-language-page-dialog-J36heFUY.cjs → no-language-page-dialog-d1oHBURV.cjs} +1 -1
- package/dist/{page-creator-C5g7z8W6.js → page-creator-4ElxexYm.js} +51 -51
- package/dist/{page-creator-CMJ9ZDbx.cjs → page-creator-Il_h2vl4.cjs} +1 -1
- package/dist/{page-lock-C4R_Or95.js → page-lock-CT54xDQL.js} +2 -2
- package/dist/{page-lock-BWomVpCL.cjs → page-lock-s-pfopxQ.cjs} +1 -1
- package/dist/{page-locked-dialog-DMZLhad3.cjs → page-locked-dialog-BORNeoXe.cjs} +1 -1
- package/dist/{page-locked-dialog-urg4T_WZ.js → page-locked-dialog-CBL04Nga.js} +2 -2
- package/dist/{page-manager-new-myexG-Df.cjs → page-manager-new-Bp5QkZD4.cjs} +1 -1
- package/dist/{page-manager-new-D_Lwwz4w.js → page-manager-new-DqCkZnWY.js} +91 -91
- package/dist/{page-manager-search-and-filter-qv_E2tzW.cjs → page-manager-search-and-filter-BMPaoTAI.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-D56yGDSe.js → page-manager-search-and-filter-CUEUB4bN.js} +1 -1
- package/dist/{page-revisions-content-BOaT_9og.cjs → page-revisions-content-1kklUJZV.cjs} +1 -1
- package/dist/{page-revisions-content-Dyi6EY_V.js → page-revisions-content-mU05KA_O.js} +7 -7
- package/dist/pages.cjs +1 -1
- package/dist/pages.d.ts +1 -0
- package/dist/pages.js +15 -15
- package/dist/{publish-pages-content-C0vWbTxI.js → publish-pages-content-CcV-xLsk.js} +80 -73
- package/dist/publish-pages-content-CpdTUAds.cjs +1 -0
- package/dist/{save-to-lib-BN2EgYkx.js → save-to-lib-CXhaKw5V.js} +57 -57
- package/dist/{save-to-lib-Bw6DefI8.cjs → save-to-lib-Uw9LqY5V.cjs} +1 -1
- package/dist/{selected-block-display-DQ_eRZxQ.cjs → selected-block-display-DZz78Kuo.cjs} +1 -1
- package/dist/{selected-block-display-BE83jvES.js → selected-block-display-_r5ZoSSD.js} +1 -1
- package/dist/{seo-panel-Bd5Yt35N.js → seo-panel-CMIMJh2W.js} +12 -12
- package/dist/{seo-panel-BZJ-bpPv.cjs → seo-panel-Cj8ky_W6.cjs} +1 -1
- package/dist/{shared-json-ld-_tOID7Vv.cjs → shared-json-ld-C28DLkns.cjs} +1 -1
- package/dist/{shared-json-ld-FApiYd-N.js → shared-json-ld-LWZfxt-V.js} +1 -1
- package/dist/supabase-actions.cjs +1 -1
- package/dist/supabase-actions.js +1 -1
- package/dist/{take-over-request-BfJbko6g.js → take-over-request-eNwLOB2Q.js} +9 -9
- package/dist/{take-over-request-CjcBgl4k.cjs → take-over-request-x9nLTelf.cjs} +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/{unmark-as-template-DCoIaBeJ.cjs → unmark-as-template-GdqfA8lm.cjs} +1 -1
- package/dist/{unmark-as-template-vdqK9CiS.js → unmark-as-template-YGONVpmY.js} +1 -1
- package/dist/{unpublish-page-CKeoMtlZ.cjs → unpublish-page-CmwSkit5.cjs} +1 -1
- package/dist/{unpublish-page-5a9yi96y.js → unpublish-page-D-A9A9db.js} +1 -1
- package/dist/{web-preview-IfmBWYnZ.js → web-preview-CZVcFxwF.js} +1 -1
- package/dist/{web-preview-DbcvvsU-.cjs → web-preview-D4_3nlN-.cjs} +1 -1
- package/package.json +1 -1
- package/dist/index-D76nE1DU.cjs +0 -5
- package/dist/publish-pages-content-CqiZED9d.cjs +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as s, jsxs as a, Fragment as Fe } from "react/jsx-runtime";
|
|
2
2
|
import { z as M, h as ye, B as F } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import { j as os, p as
|
|
4
|
-
import { useState as y, useRef as ms, useEffect as
|
|
5
|
-
import { r as te, S as hs, c as
|
|
3
|
+
import { j as os, p as z, W as ee, X as se, P as le, C as ae, k as ne, l as G, m as I, ax as cs, d as us } from "./index-DZheQdw-.js";
|
|
4
|
+
import { useState as y, useRef as ms, useEffect as ze, useMemo as B, startTransition as Oe } from "react";
|
|
5
|
+
import { r as te, S as hs, c as Be } from "./slug-input-BCs8-IRf.js";
|
|
6
6
|
import { isEmpty as Ie, startCase as de, filter as ps, find as ge, groupBy as ds, pick as fs, set as P } from "lodash-es";
|
|
7
7
|
import { ChevronDown as re, Search as ie, Check as R } from "lucide-react";
|
|
8
|
-
import {
|
|
9
|
-
import { useQuery as
|
|
8
|
+
import { ao as Re, ap as Ue, A as oe, k as gs, aq as ys, e as vs, f as Ns, g as Ss, av as bs, L as ws } from "./index-K4yKMKbY.js";
|
|
9
|
+
import { useQuery as qe } from "@tanstack/react-query";
|
|
10
10
|
import { toast as E } from "sonner";
|
|
11
|
-
import { g as
|
|
11
|
+
import { g as $e } from "./get-seo-defaults-9zHebckY.js";
|
|
12
12
|
function xs({
|
|
13
13
|
value: l,
|
|
14
14
|
onChange: o,
|
|
@@ -17,7 +17,7 @@ function xs({
|
|
|
17
17
|
onValidationChange: i
|
|
18
18
|
}) {
|
|
19
19
|
const [g, u] = y(null), m = ms(null), [f, C] = y(p + l);
|
|
20
|
-
|
|
20
|
+
ze(() => {
|
|
21
21
|
C(p + l);
|
|
22
22
|
}, [l, p]);
|
|
23
23
|
const A = (S) => {
|
|
@@ -39,7 +39,7 @@ function xs({
|
|
|
39
39
|
S.setSelectionRange(b, b);
|
|
40
40
|
}, 0);
|
|
41
41
|
}
|
|
42
|
-
},
|
|
42
|
+
}, $ = (S) => {
|
|
43
43
|
const b = S.currentTarget;
|
|
44
44
|
(b.selectionStart || 0) <= p.length && setTimeout(() => {
|
|
45
45
|
const t = p.length;
|
|
@@ -58,7 +58,7 @@ function xs({
|
|
|
58
58
|
value: f,
|
|
59
59
|
onChange: A,
|
|
60
60
|
onFocus: w,
|
|
61
|
-
onClick:
|
|
61
|
+
onClick: $,
|
|
62
62
|
placeholder: v,
|
|
63
63
|
className: g ? "border-red-500" : ""
|
|
64
64
|
}
|
|
@@ -86,7 +86,7 @@ function Cs({
|
|
|
86
86
|
}) {
|
|
87
87
|
const [u, m] = y(!1), [f, C] = y(""), A = ye("enable-add-page-dropdown");
|
|
88
88
|
A || (p = "w-full rounded-md border border-gray-300 px-3 py-2");
|
|
89
|
-
const w =
|
|
89
|
+
const w = B(() => !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
90
|
if (!f.trim()) return w;
|
|
91
91
|
const n = f.toLowerCase();
|
|
92
92
|
return w.filter(
|
|
@@ -106,7 +106,7 @@ function Cs({
|
|
|
106
106
|
return n ? `${n.name} (${h(n.slug)})` : "None";
|
|
107
107
|
};
|
|
108
108
|
return /* @__PURE__ */ a("div", { className: "space-y-0.5", children: [
|
|
109
|
-
/* @__PURE__ */ s(
|
|
109
|
+
/* @__PURE__ */ s(z, { htmlFor: i, className: "text-sm", children: "Parent" }),
|
|
110
110
|
A ? /* @__PURE__ */ a(ee, { open: u, onOpenChange: m, children: [
|
|
111
111
|
/* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ a(
|
|
112
112
|
F,
|
|
@@ -152,7 +152,7 @@ function Cs({
|
|
|
152
152
|
]
|
|
153
153
|
}
|
|
154
154
|
),
|
|
155
|
-
|
|
155
|
+
$.map((n) => {
|
|
156
156
|
const d = b(S(n.slug)), N = h(n.slug), O = /* @__PURE__ */ a("span", { className: "flex items-center text-sm", children: [
|
|
157
157
|
d,
|
|
158
158
|
n.name,
|
|
@@ -221,7 +221,7 @@ const ks = (...l) => l.filter(Boolean).join(" "), Ls = ({
|
|
|
221
221
|
isLoading: p = !1
|
|
222
222
|
}) => {
|
|
223
223
|
const [i, g] = y(""), [u, m] = y(!1), [f, C] = y(""), A = ye("enable-add-page-dropdown");
|
|
224
|
-
if (
|
|
224
|
+
if (ze(() => {
|
|
225
225
|
if (o) {
|
|
226
226
|
const h = l.find((t) => t.id === o);
|
|
227
227
|
Oe(() => g((h == null ? void 0 : h.preview) || ""));
|
|
@@ -236,7 +236,7 @@ const ks = (...l) => l.filter(Boolean).join(" "), Ls = ({
|
|
|
236
236
|
const t = h.libraryName;
|
|
237
237
|
w[t] || (w[t] = []), w[t].push(h);
|
|
238
238
|
});
|
|
239
|
-
const
|
|
239
|
+
const $ = Object.entries(w).reduce(
|
|
240
240
|
(h, [t, n]) => {
|
|
241
241
|
const d = n.filter(
|
|
242
242
|
(N) => N.name.toLowerCase().includes(f.toLowerCase()) || t.toLowerCase().includes(f.toLowerCase())
|
|
@@ -266,7 +266,7 @@ const ks = (...l) => l.filter(Boolean).join(" "), Ls = ({
|
|
|
266
266
|
] }) }),
|
|
267
267
|
/* @__PURE__ */ a(ce, { className: "max-h-[300px] overflow-y-auto", children: [
|
|
268
268
|
/* @__PURE__ */ s(ne, { children: "No templates found." }),
|
|
269
|
-
Object.entries(
|
|
269
|
+
Object.entries($).map(([h, t]) => /* @__PURE__ */ s(G, { heading: h, children: t.map((n) => /* @__PURE__ */ a(
|
|
270
270
|
I,
|
|
271
271
|
{
|
|
272
272
|
value: n.id,
|
|
@@ -310,14 +310,14 @@ const ks = (...l) => l.filter(Boolean).join(" "), Ls = ({
|
|
|
310
310
|
] });
|
|
311
311
|
}, Ts = () => {
|
|
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
|
}, js = (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,
|
|
@@ -330,33 +330,33 @@ const ks = (...l) => l.filter(Boolean).join(" "), Ls = ({
|
|
|
330
330
|
}
|
|
331
331
|
});
|
|
332
332
|
}, Ds = (l) => {
|
|
333
|
-
const { data: o = [], isLoading: v } = js(l), { data: p = [], isLoading: i } = Ts(), g =
|
|
333
|
+
const { data: o = [], isLoading: v } = js(l), { data: p = [], isLoading: i } = Ts(), g = B(() => v || i ? [] : o.map((m) => {
|
|
334
334
|
const f = ge(p, { id: m.library });
|
|
335
335
|
return {
|
|
336
336
|
...m,
|
|
337
337
|
libraryName: (f == null ? void 0 : f.type) !== "shared" ? "Site Library" : (f == null ? void 0 : f.name) + " Library",
|
|
338
338
|
libraryType: f == null ? void 0 : f.type
|
|
339
339
|
};
|
|
340
|
-
}), [o, p, v, i]), u =
|
|
340
|
+
}), [o, p, v, i]), u = B(() => ds(g, "libraryName"), [g]);
|
|
341
341
|
return {
|
|
342
342
|
data: g,
|
|
343
343
|
groupedData: u,
|
|
344
344
|
isLoading: v || i
|
|
345
345
|
};
|
|
346
346
|
}, V = (...l) => l.filter(Boolean).join(" ");
|
|
347
|
-
function
|
|
347
|
+
function _s({ addEditPage: l, close: o, closePanel: v }) {
|
|
348
348
|
var We, Ae;
|
|
349
|
-
const { data: p } = gs(), i =
|
|
349
|
+
const { data: p } = gs(), i = B(() => p ?? [], [p]), g = ys(), u = !!(l != null && l.id), { data: m } = vs(), { mutate: f, isPending: C } = Ns(), { mutate: A, isPending: w } = Ss(), [$, S] = y(null), [b, h] = y(!0), [t, n] = y((l == null ? void 0 : l.pageType) ?? "page"), { hasPermission: d } = cs(), N = d(bs.CHANGE_PAGE_TYPE), [O, U] = y(!1), [_e, Ve] = y(""), { selectedLang: Ge, fallbackLang: Me } = us(), ve = Ge || Me, [Y, X] = y(""), [Ne, H] = y(!1), Se = B(() => {
|
|
350
350
|
const e = i.find((c) => c.key === t);
|
|
351
351
|
return (e == null ? void 0 : e.hasSlug) === !1;
|
|
352
|
-
}, [t, i]), [k, Ye] = y((l == null ? void 0 : l.parent) ?? ""), [
|
|
352
|
+
}, [t, i]), [k, Ye] = y((l == null ? void 0 : l.parent) ?? ""), [q, 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, Qe] = y(!0), [He, ue] = y(!1), [me, Ke] = y(""), { data: Le, isLoading: Xe } = Ds(t), Q = C || w, Te = ye("enable-add-page-dropdown"), he = B(() => !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 = B(() => !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
|
Ve(e), U(!0), X(""), H(!1);
|
|
355
355
|
return;
|
|
356
356
|
}
|
|
357
357
|
n(e), X(""), H(!1);
|
|
358
358
|
}, je = () => {
|
|
359
|
-
n(
|
|
359
|
+
n(_e), U(!1), we(!1);
|
|
360
360
|
}, Pe = (e) => {
|
|
361
361
|
we(e), e ? K("") : Ce("");
|
|
362
362
|
}, Ee = (e) => {
|
|
@@ -371,15 +371,15 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
371
371
|
K(j ? `${j}` : "");
|
|
372
372
|
}, es = (e) => {
|
|
373
373
|
Ke(e);
|
|
374
|
-
}, ss = () =>
|
|
374
|
+
}, ss = () => q.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), ls = () => {
|
|
375
375
|
const e = {
|
|
376
376
|
pageType: r == null ? void 0 : r.key,
|
|
377
|
-
name:
|
|
377
|
+
name: q,
|
|
378
378
|
slug: "",
|
|
379
379
|
hasSlug: !1
|
|
380
380
|
};
|
|
381
381
|
u ? A(
|
|
382
|
-
{ id: l == null ? void 0 : l.id, name:
|
|
382
|
+
{ id: l == null ? void 0 : l.id, name: q },
|
|
383
383
|
{
|
|
384
384
|
onSuccess: () => {
|
|
385
385
|
E.success((r == null ? void 0 : r.name) + " updated successfully"), o();
|
|
@@ -393,12 +393,12 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
393
393
|
}, as = (e, c) => {
|
|
394
394
|
if (!e.trim() && !T)
|
|
395
395
|
return S("Child page slug is required"), !1;
|
|
396
|
-
const D = te(c), x =
|
|
396
|
+
const D = te(c), x = Be(D, e);
|
|
397
397
|
return Object.keys(ws).some((J) => x === `/${J}` || (x == null ? void 0 : x.startsWith(`/${J}/`))) ? (S("Slugs cannot start with a language code for primary page"), !1) : !0;
|
|
398
398
|
}, ns = (e, c) => {
|
|
399
|
-
const D = te(c), x =
|
|
399
|
+
const D = te(c), x = Be(D, e), L = {
|
|
400
400
|
pageType: t,
|
|
401
|
-
name:
|
|
401
|
+
name: q,
|
|
402
402
|
slug: x.replace(/\/$/, ""),
|
|
403
403
|
// remove trailing slashes
|
|
404
404
|
parent: k,
|
|
@@ -422,7 +422,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
422
422
|
} else {
|
|
423
423
|
const W = ge(i, { key: t });
|
|
424
424
|
W != null && W.trackingDefault && (L.tracking = W.trackingDefault);
|
|
425
|
-
const { seo: J, jsonLD: rs } =
|
|
425
|
+
const { seo: J, jsonLD: rs } = $e(W, ve);
|
|
426
426
|
P(L, "seo", J), P(L, "jsonLD", rs), f(L, {
|
|
427
427
|
onSuccess: (is) => {
|
|
428
428
|
o(), g(is.page.id, v);
|
|
@@ -432,7 +432,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
432
432
|
}, ts = () => {
|
|
433
433
|
const e = {
|
|
434
434
|
pageType: t,
|
|
435
|
-
name:
|
|
435
|
+
name: q,
|
|
436
436
|
slug: j === "" ? "/" : `/${j.replace(/\/$/, "")}`,
|
|
437
437
|
template: me || void 0,
|
|
438
438
|
parent: null,
|
|
@@ -450,7 +450,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
450
450
|
else {
|
|
451
451
|
const c = ge(i, { key: t });
|
|
452
452
|
c != null && c.trackingDefault && (e.tracking = c.trackingDefault);
|
|
453
|
-
const { seo: D, jsonLD: x } =
|
|
453
|
+
const { seo: D, jsonLD: x } = $e(c, ve);
|
|
454
454
|
P(e, "seo", D), P(e, "jsonLD", x), f(e, {
|
|
455
455
|
onSuccess: (L) => {
|
|
456
456
|
var W;
|
|
@@ -472,7 +472,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
472
472
|
} else
|
|
473
473
|
ts();
|
|
474
474
|
}
|
|
475
|
-
}, { pagesType: pe, partialsType: Z } =
|
|
475
|
+
}, { pagesType: pe, partialsType: Z } = B(() => {
|
|
476
476
|
const e = (c) => Y ? c.name.toLowerCase().includes(Y.toLowerCase()) || c.key.toLowerCase().includes(Y.toLowerCase()) : !0;
|
|
477
477
|
return {
|
|
478
478
|
pagesType: i.filter((c) => c.hasSlug !== !1 && e(c)),
|
|
@@ -481,7 +481,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
481
481
|
}, [i, Y]);
|
|
482
482
|
return r != null && r.hasSlug ? /* @__PURE__ */ a("form", { onSubmit: De, className: "mx-auto w-full max-w-md space-y-4", children: [
|
|
483
483
|
/* @__PURE__ */ a("div", { className: "space-y-0.5", children: [
|
|
484
|
-
/* @__PURE__ */ s(
|
|
484
|
+
/* @__PURE__ */ s(z, { htmlFor: "pageType", className: "text-sm", children: "Type" }),
|
|
485
485
|
Te ? /* @__PURE__ */ a(ee, { open: Ne, onOpenChange: H, children: [
|
|
486
486
|
/* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ a(
|
|
487
487
|
F,
|
|
@@ -518,7 +518,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
518
518
|
I,
|
|
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 qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
535
535
|
I,
|
|
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 qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
553
553
|
I,
|
|
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 qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
571
571
|
I,
|
|
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,7 +594,7 @@ function qs({ 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
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__ */ a(Fe, { 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)) }),
|
|
@@ -611,7 +611,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
611
611
|
] })
|
|
612
612
|
] }),
|
|
613
613
|
!u && (r == null ? void 0 : r.hasSlug) && Le.length > 0 && /* @__PURE__ */ a("div", { className: "space-y-1", children: [
|
|
614
|
-
/* @__PURE__ */ s(
|
|
614
|
+
/* @__PURE__ */ s(z, { className: "mb-1 block text-sm", children: "Template" }),
|
|
615
615
|
/* @__PURE__ */ s(
|
|
616
616
|
Ls,
|
|
617
617
|
{
|
|
@@ -632,12 +632,12 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
632
632
|
}
|
|
633
633
|
),
|
|
634
634
|
/* @__PURE__ */ a("div", { className: "space-y-0.5", children: [
|
|
635
|
-
/* @__PURE__ */ s(
|
|
635
|
+
/* @__PURE__ */ s(z, { htmlFor: "name", className: "text-sm", children: "Name" }),
|
|
636
636
|
/* @__PURE__ */ s(
|
|
637
637
|
M,
|
|
638
638
|
{
|
|
639
639
|
id: "name",
|
|
640
|
-
value:
|
|
640
|
+
value: q,
|
|
641
641
|
onChange: (e) => be(e.target.value),
|
|
642
642
|
required: !0,
|
|
643
643
|
"aria-required": "true",
|
|
@@ -657,7 +657,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
657
657
|
className: "rounded border-gray-300"
|
|
658
658
|
}
|
|
659
659
|
),
|
|
660
|
-
/* @__PURE__ */ s(
|
|
660
|
+
/* @__PURE__ */ s(z, { htmlFor: "useDynamicSlug", className: "text-sm", children: "Use Dynamic Slug" })
|
|
661
661
|
] }),
|
|
662
662
|
T && /* @__PURE__ */ s("div", { className: "space-y-2", children: /* @__PURE__ */ s("div", { className: "space-y-0.5", children: /* @__PURE__ */ s(
|
|
663
663
|
xs,
|
|
@@ -671,7 +671,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
671
671
|
) }) })
|
|
672
672
|
] }),
|
|
673
673
|
(!(r != null && r.dynamicSegments) || !T) && /* @__PURE__ */ a("div", { className: "space-y-0.5", children: [
|
|
674
|
-
/* @__PURE__ */ s(
|
|
674
|
+
/* @__PURE__ */ s(z, { htmlFor: "slug", className: "text-sm", children: "Slug" }),
|
|
675
675
|
/* @__PURE__ */ s(
|
|
676
676
|
hs,
|
|
677
677
|
{
|
|
@@ -685,7 +685,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
685
685
|
onValidationChange: h
|
|
686
686
|
}
|
|
687
687
|
),
|
|
688
|
-
|
|
688
|
+
$ && /* @__PURE__ */ s("p", { className: "text-xs text-red-500", children: $ }),
|
|
689
689
|
He && /* @__PURE__ */ s("div", { className: "mt-4 rounded-md border border-amber-200 bg-amber-50 p-3", children: /* @__PURE__ */ a("div", { className: "flex items-start space-x-2", children: [
|
|
690
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
691
|
"path",
|
|
@@ -714,7 +714,7 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
714
714
|
)
|
|
715
715
|
] }) : /* @__PURE__ */ a("form", { onSubmit: De, className: "mx-auto w-full max-w-md space-y-4", children: [
|
|
716
716
|
/* @__PURE__ */ a("div", { className: "space-y-0.5", children: [
|
|
717
|
-
/* @__PURE__ */ s(
|
|
717
|
+
/* @__PURE__ */ s(z, { htmlFor: "pageType", className: "text-sm", children: "Type" }),
|
|
718
718
|
Te ? /* @__PURE__ */ a(ee, { open: Ne, onOpenChange: H, children: [
|
|
719
719
|
/* @__PURE__ */ s(se, { asChild: !0, children: /* @__PURE__ */ a(
|
|
720
720
|
F,
|
|
@@ -752,7 +752,7 @@ function qs({ 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 qs({ 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
|
}
|
|
@@ -785,12 +785,12 @@ function qs({ addEditPage: l, close: o, closePanel: v }) {
|
|
|
785
785
|
/* @__PURE__ */ s("p", { className: "text-xs text-gray-500", children: (We = i.find((e) => e.key === t)) == null ? void 0 : We.helpText })
|
|
786
786
|
] }),
|
|
787
787
|
/* @__PURE__ */ a("div", { className: "space-y-0.5", children: [
|
|
788
|
-
/* @__PURE__ */ s(
|
|
789
|
-
/* @__PURE__ */ s(M, { id: "name", value:
|
|
788
|
+
/* @__PURE__ */ s(z, { htmlFor: "name", className: "text-sm", children: "Name" }),
|
|
789
|
+
/* @__PURE__ */ s(M, { id: "name", value: q, onChange: (e) => be(e.target.value), required: !0, "aria-required": "true" })
|
|
790
790
|
] }),
|
|
791
791
|
/* @__PURE__ */ s(F, { 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
|
+
_s as default
|
|
796
796
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("./register-chai-top-bar-DyW9GPzV.cjs"),a=require("./index-W4Ur56bi.cjs"),o=require("react"),_=require("./slug-input-CQu9-5GT.cjs"),w=require("lodash-es"),N=require("lucide-react"),k=require("./index-D76nE1DU.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:i}){const[f,m]=o.useState(null),h=o.useRef(null),[g,T]=o.useState(p+t);o.useEffect(()=>{T(p+t)},[t,p]);const O=S=>{const C=S.target.value;if(!C.startsWith(p)){const W=C.replace(p,""),G=p+W;T(G),c(W);return}const l=C.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),n=(l.match(/\./g)||[]).length,x=n<=1;n>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),i&&i(x);const y=p+l;T(y),c(l)},b=()=>{if(h.current){const S=h.current;setTimeout(()=>{const C=p.length;S.setSelectionRange(C,C)},0)}},R=S=>{const C=S.currentTarget;(C.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;C.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"mb-2 text-xs text-gray-500",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(v.Input,{ref:h,value:g,onChange:O,onFocus:b,onClick:R,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"mt-1 text-xs text-red-500",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=i=>{try{i.preventDefault();const f=i.currentTarget;f.scrollTop+=i.deltaY}catch{i.preventDefault()}c&&c(i)};return e.jsx(a.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function ze({pages:t,selectedParentId:c,onChange:j,className:p,id:i="parentPage",currentPage:f}){const[m,h]=o.useState(!1),[g,T]=o.useState(""),O=v.useChaiFeatureFlag("enable-add-page-dropdown");O||(p="w-full rounded-md border border-gray-300 px-3 py-2");const b=o.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!w.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),R=o.useMemo(()=>{if(!g.trim())return b;const n=g.toLowerCase();return b.filter(x=>x.name.toLowerCase().includes(n)||x.slug.toLowerCase().includes(n))},[b,g]),S=n=>Math.max(0,(n.match(/\//g)||[]).length-1),C=n=>" ".repeat(n),d=n=>{if(n==="/")return"/";const x=n.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 n=b.find(x=>x.id===c);return n?`${n.name} (${d(n.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:i,className:"text-sm",children:"Parent"}),O?e.jsxs(a.Popover,{open:m,onOpenChange:h,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{id:i,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:n=>T(n.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No pages found."}),e.jsxs(a.CommandGroup,{children:[e.jsxs(a.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),T("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(N.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),R.map(n=>{const x=C(S(n.slug)),y=d(n.slug),W=e.jsxs("span",{className:"flex items-center text-sm",children:[x,n.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(a.CommandItem,{value:n.id,onSelect:()=>{j(n.id),h(!1),T("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:W}),e.jsx(N.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===n.id?"opacity-100":"opacity-0")})]},n.id)})]})]})]})})]}):e.jsxs("select",{id:i,value:c||"none",onChange:n=>j(n.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),b.map(n=>{const x=S(n.slug),y=x>0?C(x):"",W=d(n.slug);return(f==null?void 0:f.id)===n.id||n.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:n.id,children:[y,n.name," (",W,")"]},n.id)})]})]})}const _e=(...t)=>t.filter(Boolean).join(" "),Ve=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[i,f]=o.useState(""),[m,h]=o.useState(!1),[g,T]=o.useState(""),O=v.useChaiFeatureFlag("enable-add-page-dropdown");if(o.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);o.startTransition(()=>f((d==null?void 0:d.preview)||""))}else o.startTransition(()=>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 b={};t.forEach(d=>{const l=d.libraryName;b[l]||(b[l]=[]),b[l].push(d)});const R=Object.entries(b).reduce((d,[l,n])=>{const x=n.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),S=t.find(d=>d.id===c),C=S?w.startCase(S.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[O?e.jsxs(a.Popover,{open:m,onOpenChange:h,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[C,e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>T(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No templates found."}),Object.entries(R).map(([d,l])=>e.jsx(a.CommandGroup,{heading:d,children:l.map(n=>e.jsxs(a.CommandItem,{value:n.id,onSelect:()=>{j(n.id),h(!1),T("")},className:"flex cursor-pointer items-center justify-between",children:[w.startCase(n.name),e.jsx(N.Check,{className:_e("mr-2 h-4 w-4",c===n.id?"opacity-100":"opacity-0")})]},n.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(b).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(n=>e.jsx("option",{value:n.id,children:w.startCase(n.name)},n.id))},d))]}),i&&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:i,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"})]})]})},$e=()=>{const t=k.useApiUrl(),c=k.useFetch();return je.useQuery({queryKey:[k.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:k.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=k.useApiUrl(),j=k.useFetch();return je.useQuery({queryKey:[k.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:k.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?w.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:i}=$e(),f=o.useMemo(()=>j||i?[]:c.map(h=>{const g=w.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,i]),m=o.useMemo(()=>w.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||i}},z=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=k.usePageTypes(),i=o.useMemo(()=>p??[],[p]),f=k.useChangePage(),m=!!(t!=null&&t.id),{data:h}=k.useWebsitePrimaryPages(),{mutate:g,isPending:T}=k.useCreatePage(),{mutate:O,isPending:b}=k.useUpdatePage(),[R,S]=o.useState(null),[C,d]=o.useState(!0),[l,n]=o.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=a.usePermissions(),y=x(k.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[W,G]=o.useState(!1),[ye,ve]=o.useState(""),{selectedLang:Se,fallbackLang:Ce}=a.useLanguages(),ne=Se||Ce,[V,H]=o.useState(""),[ae,Q]=o.useState(!1),le=o.useMemo(()=>{const s=i.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,i]),[D,Ne]=o.useState((t==null?void 0:t.parent)??""),[M,re]=o.useState((t==null?void 0:t.name)??""),[F,oe]=o.useState((t==null?void 0:t.dynamic)??!1),[B,Y]=o.useState(F?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=o.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=o.useState(!0),[we,P]=o.useState(!1),[E,ke]=o.useState(""),{data:me,isLoading:Le}=Ye(l),$=T||b,he=v.useChaiFeatureFlag("enable-add-page-dropdown"),ee=o.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=o.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=i.find(s=>s.key===l),U=s=>{if(m&&l!==s){ve(s),G(!0),H(""),Q(!1);return}n(s),H(""),Q(!1)},pe=()=>{n(ye),G(!1),oe(!1)},Ie=s=>{oe(s),s?Y(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(L=>L.id===s),q=(u==null?void 0:u.slug)||"";if(B.startsWith(q)){const L=B.slice(q.length).replace(/^\/+/,"");Y(L)}else Y(B.replace(/^\/+/,""))}else Y(B?`${B}`:"")},Be=s=>{ke(s)},qe=()=>M.trim()?F&&!w.isEmpty(B)?(S("Slug must be empty when using dynamic slug"),!1):F&&!ue?(S("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Ae=()=>{const s={pageType:r==null?void 0:r.key,name:M,slug:"",hasSlug:!1};m?O({id:t==null?void 0:t.id,name:M},{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()&&!F)return S("Child page slug is required"),!1;const q=_.removeSlugExtension(u),L=_.combineParentChildSlugs(q,s);return Object.keys(k.LANGUAGES).some(Z=>L===`/${Z}`||(L==null?void 0:L.startsWith(`/${Z}/`)))?(S("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=_.removeSlugExtension(u),L=_.combineParentChildSlugs(q,s),I={pageType:l,name:M,slug:L.replace(/\/$/,""),parent:D,dynamic:F,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(F&&(I.dynamicSlugCustom=ie),m){const A=w.pick(I,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);O({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=w.find(i,{key:l});A!=null&&A.trackingDefault&&(I.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);w.set(I,"seo",Z),w.set(I,"jsonLD",Ge),g(I,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:M,slug:B===""?"/":`/${B.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)O({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=w.find(i,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:L}=fe.getSeoDefaults(u,ne);w.set(s,"seo",q),w.set(s,"jsonLD",L),g(s,{onSuccess:I=>{var A;(A=I==null?void 0:I.page)!=null&&A.id&&f(I.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),S(null),!!qe()){if(!(r!=null&&r.hasSlug)){Ae();return}if(D&&D!=="none"){const u=h==null?void 0:h.find(L=>L.id===D),q=(u==null?void 0:u.slug)||"";if(!Oe(B,q))return;We(B,q)}else Re()}},{pagesType:se,partialsType:K}=o.useMemo(()=>{const s=u=>V?u.name.toLowerCase().includes(V.toLowerCase())||u.key.toLowerCase().includes(V.toLowerCase()):!0;return{pagesType:i.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:i.filter(u=>u.hasSlug===!1&&s(u))}},[i,V]);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(a.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(a.Popover,{open:ae,onOpenChange:Q,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:z("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:V,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(a.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("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(a.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("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=>U(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:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:i.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:i.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),W&&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(v.Button,{variant:"outline",size:"sm",onClick:()=>G(!1),children:"Cancel"}),e.jsx(v.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(a.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(Ve,{templates:me,selectedTemplateId:E,onSelectTemplate:Be,isLoading:Le})]}),e.jsx(ze,{pages:h,selectedParentId:D,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(v.Input,{id:"name",value:M,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&D&&D!=="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:F,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(a.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),F&&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)||!F)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx(_.SlugInput,{value:B,onChange:s=>{var u;Y(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:D&&D!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:D&&D!=="none"?(ge=h==null?void 0:h.find(s=>s.id===D))==null?void 0:ge.slug:void 0,onValidationChange:d}),R&&e.jsx("p",{className:"text-xs text-red-500",children:R}),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(v.Button,{disabled:$||!C&&(!(r!=null&&r.dynamicSegments)||!F)||F&&!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(a.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(a.Popover,{open:ae,onOpenChange:Q,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:z("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:V,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No page type found."}),e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>{U(s.key),Q(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("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=>U(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:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),W&&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(v.Button,{variant:"outline",size:"sm",onClick:()=>G(!1),children:"Cancel"}),e.jsx(v.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=i.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(v.Input,{id:"name",value:M,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(v.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"),v=require("./register-chai-top-bar-DyW9GPzV.cjs"),a=require("./index-W4Ur56bi.cjs"),o=require("react"),_=require("./slug-input-CQu9-5GT.cjs"),w=require("lodash-es"),N=require("lucide-react"),k=require("./index-DvOWqGdC.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:i}){const[f,m]=o.useState(null),h=o.useRef(null),[g,T]=o.useState(p+t);o.useEffect(()=>{T(p+t)},[t,p]);const O=S=>{const C=S.target.value;if(!C.startsWith(p)){const W=C.replace(p,""),G=p+W;T(G),c(W);return}const l=C.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),n=(l.match(/\./g)||[]).length,x=n<=1;n>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),i&&i(x);const y=p+l;T(y),c(l)},b=()=>{if(h.current){const S=h.current;setTimeout(()=>{const C=p.length;S.setSelectionRange(C,C)},0)}},R=S=>{const C=S.currentTarget;(C.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;C.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"mb-2 text-xs text-gray-500",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(v.Input,{ref:h,value:g,onChange:O,onFocus:b,onClick:R,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"mt-1 text-xs text-red-500",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=i=>{try{i.preventDefault();const f=i.currentTarget;f.scrollTop+=i.deltaY}catch{i.preventDefault()}c&&c(i)};return e.jsx(a.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function ze({pages:t,selectedParentId:c,onChange:j,className:p,id:i="parentPage",currentPage:f}){const[m,h]=o.useState(!1),[g,T]=o.useState(""),O=v.useChaiFeatureFlag("enable-add-page-dropdown");O||(p="w-full rounded-md border border-gray-300 px-3 py-2");const b=o.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!w.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),R=o.useMemo(()=>{if(!g.trim())return b;const n=g.toLowerCase();return b.filter(x=>x.name.toLowerCase().includes(n)||x.slug.toLowerCase().includes(n))},[b,g]),S=n=>Math.max(0,(n.match(/\//g)||[]).length-1),C=n=>" ".repeat(n),d=n=>{if(n==="/")return"/";const x=n.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 n=b.find(x=>x.id===c);return n?`${n.name} (${d(n.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:i,className:"text-sm",children:"Parent"}),O?e.jsxs(a.Popover,{open:m,onOpenChange:h,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{id:i,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:n=>T(n.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No pages found."}),e.jsxs(a.CommandGroup,{children:[e.jsxs(a.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),T("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(N.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),R.map(n=>{const x=C(S(n.slug)),y=d(n.slug),W=e.jsxs("span",{className:"flex items-center text-sm",children:[x,n.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(a.CommandItem,{value:n.id,onSelect:()=>{j(n.id),h(!1),T("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:W}),e.jsx(N.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===n.id?"opacity-100":"opacity-0")})]},n.id)})]})]})]})})]}):e.jsxs("select",{id:i,value:c||"none",onChange:n=>j(n.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),b.map(n=>{const x=S(n.slug),y=x>0?C(x):"",W=d(n.slug);return(f==null?void 0:f.id)===n.id||n.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:n.id,children:[y,n.name," (",W,")"]},n.id)})]})]})}const _e=(...t)=>t.filter(Boolean).join(" "),Ve=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[i,f]=o.useState(""),[m,h]=o.useState(!1),[g,T]=o.useState(""),O=v.useChaiFeatureFlag("enable-add-page-dropdown");if(o.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);o.startTransition(()=>f((d==null?void 0:d.preview)||""))}else o.startTransition(()=>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 b={};t.forEach(d=>{const l=d.libraryName;b[l]||(b[l]=[]),b[l].push(d)});const R=Object.entries(b).reduce((d,[l,n])=>{const x=n.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),S=t.find(d=>d.id===c),C=S?w.startCase(S.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[O?e.jsxs(a.Popover,{open:m,onOpenChange:h,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[C,e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>T(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No templates found."}),Object.entries(R).map(([d,l])=>e.jsx(a.CommandGroup,{heading:d,children:l.map(n=>e.jsxs(a.CommandItem,{value:n.id,onSelect:()=>{j(n.id),h(!1),T("")},className:"flex cursor-pointer items-center justify-between",children:[w.startCase(n.name),e.jsx(N.Check,{className:_e("mr-2 h-4 w-4",c===n.id?"opacity-100":"opacity-0")})]},n.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(b).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(n=>e.jsx("option",{value:n.id,children:w.startCase(n.name)},n.id))},d))]}),i&&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:i,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"})]})]})},$e=()=>{const t=k.useApiUrl(),c=k.useFetch();return je.useQuery({queryKey:[k.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:k.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=k.useApiUrl(),j=k.useFetch();return je.useQuery({queryKey:[k.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:k.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?w.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:i}=$e(),f=o.useMemo(()=>j||i?[]:c.map(h=>{const g=w.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,i]),m=o.useMemo(()=>w.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||i}},z=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=k.usePageTypes(),i=o.useMemo(()=>p??[],[p]),f=k.useChangePage(),m=!!(t!=null&&t.id),{data:h}=k.useWebsitePrimaryPages(),{mutate:g,isPending:T}=k.useCreatePage(),{mutate:O,isPending:b}=k.useUpdatePage(),[R,S]=o.useState(null),[C,d]=o.useState(!0),[l,n]=o.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=a.usePermissions(),y=x(k.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[W,G]=o.useState(!1),[ye,ve]=o.useState(""),{selectedLang:Se,fallbackLang:Ce}=a.useLanguages(),ne=Se||Ce,[V,H]=o.useState(""),[ae,Q]=o.useState(!1),le=o.useMemo(()=>{const s=i.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,i]),[D,Ne]=o.useState((t==null?void 0:t.parent)??""),[M,re]=o.useState((t==null?void 0:t.name)??""),[F,oe]=o.useState((t==null?void 0:t.dynamic)??!1),[B,Y]=o.useState(F?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=o.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=o.useState(!0),[we,P]=o.useState(!1),[E,ke]=o.useState(""),{data:me,isLoading:Le}=Ye(l),$=T||b,he=v.useChaiFeatureFlag("enable-add-page-dropdown"),ee=o.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=o.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=i.find(s=>s.key===l),U=s=>{if(m&&l!==s){ve(s),G(!0),H(""),Q(!1);return}n(s),H(""),Q(!1)},pe=()=>{n(ye),G(!1),oe(!1)},Ie=s=>{oe(s),s?Y(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(L=>L.id===s),q=(u==null?void 0:u.slug)||"";if(B.startsWith(q)){const L=B.slice(q.length).replace(/^\/+/,"");Y(L)}else Y(B.replace(/^\/+/,""))}else Y(B?`${B}`:"")},Be=s=>{ke(s)},qe=()=>M.trim()?F&&!w.isEmpty(B)?(S("Slug must be empty when using dynamic slug"),!1):F&&!ue?(S("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Ae=()=>{const s={pageType:r==null?void 0:r.key,name:M,slug:"",hasSlug:!1};m?O({id:t==null?void 0:t.id,name:M},{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()&&!F)return S("Child page slug is required"),!1;const q=_.removeSlugExtension(u),L=_.combineParentChildSlugs(q,s);return Object.keys(k.LANGUAGES).some(Z=>L===`/${Z}`||(L==null?void 0:L.startsWith(`/${Z}/`)))?(S("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=_.removeSlugExtension(u),L=_.combineParentChildSlugs(q,s),I={pageType:l,name:M,slug:L.replace(/\/$/,""),parent:D,dynamic:F,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(F&&(I.dynamicSlugCustom=ie),m){const A=w.pick(I,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);O({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=w.find(i,{key:l});A!=null&&A.trackingDefault&&(I.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);w.set(I,"seo",Z),w.set(I,"jsonLD",Ge),g(I,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:M,slug:B===""?"/":`/${B.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)O({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=w.find(i,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:L}=fe.getSeoDefaults(u,ne);w.set(s,"seo",q),w.set(s,"jsonLD",L),g(s,{onSuccess:I=>{var A;(A=I==null?void 0:I.page)!=null&&A.id&&f(I.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),S(null),!!qe()){if(!(r!=null&&r.hasSlug)){Ae();return}if(D&&D!=="none"){const u=h==null?void 0:h.find(L=>L.id===D),q=(u==null?void 0:u.slug)||"";if(!Oe(B,q))return;We(B,q)}else Re()}},{pagesType:se,partialsType:K}=o.useMemo(()=>{const s=u=>V?u.name.toLowerCase().includes(V.toLowerCase())||u.key.toLowerCase().includes(V.toLowerCase()):!0;return{pagesType:i.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:i.filter(u=>u.hasSlug===!1&&s(u))}},[i,V]);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(a.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(a.Popover,{open:ae,onOpenChange:Q,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:z("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:V,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(a.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("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(a.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("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=>U(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:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:i.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:i.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),W&&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(v.Button,{variant:"outline",size:"sm",onClick:()=>G(!1),children:"Cancel"}),e.jsx(v.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(a.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(Ve,{templates:me,selectedTemplateId:E,onSelectTemplate:Be,isLoading:Le})]}),e.jsx(ze,{pages:h,selectedParentId:D,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(v.Input,{id:"name",value:M,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&D&&D!=="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:F,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(a.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),F&&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)||!F)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx(_.SlugInput,{value:B,onChange:s=>{var u;Y(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:D&&D!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:D&&D!=="none"?(ge=h==null?void 0:h.find(s=>s.id===D))==null?void 0:ge.slug:void 0,onValidationChange:d}),R&&e.jsx("p",{className:"text-xs text-red-500",children:R}),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(v.Button,{disabled:$||!C&&(!(r!=null&&r.dynamicSegments)||!F)||F&&!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(a.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(a.Popover,{open:ae,onOpenChange:Q,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:z("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.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(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:V,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No page type found."}),e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>{U(s.key),Q(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("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=>U(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:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),W&&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(v.Button,{variant:"outline",size:"sm",onClick:()=>G(!1),children:"Cancel"}),e.jsx(v.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=i.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(v.Input,{id:"name",value:M,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(v.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,8 +1,8 @@
|
|
|
1
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-
|
|
2
|
+
import { u as E, a as c, b as T, P as e, A as l, B as I, E as _ } from "./index-K4yKMKbY.js";
|
|
3
3
|
import { useQueryClient as C } from "@tanstack/react-query";
|
|
4
4
|
import { useRef as p, useEffect as N, Suspense as A, lazy as s } from "react";
|
|
5
|
-
const m = s(() => import("./take-over-request-
|
|
5
|
+
const m = s(() => import("./take-over-request-eNwLOB2Q.js")), f = s(() => import("./page-locked-dialog-CBL04Nga.js")), O = s(() => import("./active-in-another-tab-Zrq6x3L9.js")), S = s(() => import("./continue-editing-in-this-client-CoZnDfgk.js")), r = (a) => /* @__PURE__ */ n(A, { children: /* @__PURE__ */ n(a, {}) }), L = ({ isFetchingPageData: a }) => {
|
|
6
6
|
E();
|
|
7
7
|
const { pageStatus: t } = c(), { pageLockMeta: o } = T(), u = C(), i = p(t);
|
|
8
8
|
if (N(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("./index-DvOWqGdC.cjs"),E=require("@tanstack/react-query"),r=require("react"),c=r.lazy(()=>Promise.resolve().then(()=>require("./take-over-request-x9nLTelf.cjs"))),o=r.lazy(()=>Promise.resolve().then(()=>require("./page-locked-dialog-BORNeoXe.cjs"))),l=r.lazy(()=>Promise.resolve().then(()=>require("./active-in-another-tab-DkOOxZwb.cjs"))),S=r.lazy(()=>Promise.resolve().then(()=>require("./continue-editing-in-this-client-BHbRZL8A.cjs"))),s=n=>u.jsx(r.Suspense,{children:u.jsx(n,{})}),A=({isFetchingPageData:n})=>{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]),n)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?s(S):null;case e.PAGE_STATUS.LOCKED:return s(o);case e.PAGE_STATUS.TAKE_OVER_REQUESTED:return s(c);case e.PAGE_STATUS.ACTIVE_IN_ANOTHER_TAB:return s(l);case e.PAGE_STATUS.CONNECTION_LOST:return u.jsx(e.BlurContainer,{children:null});default:return null}};exports.default=A;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-W4Ur56bi.cjs"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-W4Ur56bi.cjs"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-DvOWqGdC.cjs"),c=require("lucide-react"),d=require("react"),O=require("react-i18next"),_=()=>{const m=t.useCurrentPageOwner(),f=t.useSendRealtimeEvent(),{setPageStatus:j}=t.usePageLockStatus(),{data:s,isFetching:v}=t.useChaiUserInfo((m==null?void 0:m.userId)||""),{pageLockMeta:o,setPageLockMeta:g}=t.usePageLockMeta(),{t:r}=O.useTranslation(),[u,i]=d.useState(""),[a,N]=d.useState({}),[T,k]=d.useState(!1),l=d.useRef(null);d.useEffect(()=>{o!=null&&o.type&&(l.current&&clearTimeout(l.current),d.startTransition(()=>{N(o),g({}),i("")}))},[o,g]);const b=()=>{u!==t.EVENT.TAKE_OVER_REQUEST&&(i(t.EVENT.TAKE_OVER_REQUEST),f(t.EVENT.TAKE_OVER_REQUEST),l.current=setTimeout(()=>i(""),2e4))},R=()=>{u!==t.EVENT.FORCE_TAKE_OVER_REQUEST&&(i(t.EVENT.FORCE_TAKE_OVER_REQUEST),f(t.EVENT.FORCE_TAKE_OVER_REQUEST),j(t.PAGE_STATUS.CHECKING),l.current=setTimeout(()=>i(""),2e4))},y=()=>{N({}),l.current&&clearTimeout(l.current),i("")},x=v?"Loading...":(s==null?void 0:s.name)||"Current editor",h=u===t.EVENT.TAKE_OVER_REQUEST,E=u===t.EVENT.FORCE_TAKE_OVER_REQUEST;return e.jsx(t.BlurContainer,{children:e.jsxs(n.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(n.CardHeader,{className:"space-y-1 border-b pb-3",children:e.jsxs(n.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(c.LockKeyhole,{className:"h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500"}),e.jsx("span",{children:r("Page Locked for Editing")})]})}),e.jsxs(n.CardContent,{className:"space-y-4 p-4",children:[e.jsxs("div",{className:"relative rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("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"}),e.jsxs("div",{className:"flex items-center space-x-4 p-1",children:[s!=null&&s.avatar?e.jsx("img",{src:s.avatar,alt:s.name,className:"h-12 w-12 flex-shrink-0 rounded-full bg-black text-white"}):e.jsx(c.UserIcon,{className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}),e.jsxs("div",{className:"flex-1 space-y-0",children:[e.jsx("div",{className:"truncate font-medium leading-tight text-black",children:x}),(s==null?void 0:s.email)&&e.jsx("p",{className:"truncate text-sm leading-tight text-muted-foreground",children:s.email})]})]})]}),((a==null?void 0:a.type)===t.EVENT.TAKE_OVER_REJECTED||(a==null?void 0:a.type)===t.EVENT.FORCE_TAKE_OVER_REQUEST)&&e.jsx("section",{className:"space-y-2",children:e.jsxs("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:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx(c.AlertCircleIcon,{className:"mt-px flex h-4 w-4 shrink-0"}),e.jsxs("div",{className:"font-light leading-tight",children:[e.jsx("span",{className:"font-medium",children:(s==null?void 0:s.name)||"The current editor"}),(a==null?void 0:a.type)===t.EVENT.TAKE_OVER_REJECTED?" rejected your take over request.":" forcefully took over this page."]})]}),e.jsx(p.Button,{size:"icon",variant:"ghost",onClick:y,className:"flex-shrink-0",children:e.jsx(c.X,{className:"h-4 w-4"})})]})})]}),e.jsx(n.CardFooter,{className:"flex flex-col gap-3 border-t pt-3",children:e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("Take Over Options")}),e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("p",{className:"text-sm font-medium",children:r("Take Over Request:")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r("Send a request to {{currentEditorName}} asking them to release the page. They can accept or decline your request.",{currentEditorName:x})})]}),e.jsxs(p.Button,{disabled:h,variant:"default",onClick:b,className:"mt-3 w-full gap-2",children:[e.jsx(c.Edit,{className:"h-4 w-4"}),h?"Take over request sent":"Send Take Over Request"]}),h&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("Request sent. If no response, try again or use force take over.")})]}),e.jsx(n.Accordion,{type:"single",collapsible:!0,className:"w-full",children:e.jsxs(n.AccordionItem,{value:"force-takeover",className:"rounded-md border border-destructive/40 bg-destructive/5",children:[e.jsx(n.AccordionTrigger,{className:"px-3 py-2 hover:no-underline",children:e.jsx("div",{className:"flex items-center gap-2 text-left",children:e.jsxs("div",{children:[e.jsxs("p",{className:"flex items-center gap-x-2 text-sm font-medium text-destructive",children:[e.jsx(c.ShieldAlert,{className:"h-4 w-4 text-destructive"}),r("Force Take Over")]}),e.jsx("p",{className:"pl-6 text-xs font-normal leading-tight text-muted-foreground",children:r("Immediately take control (use with caution)")})]})})}),e.jsx(n.AccordionContent,{className:"px-3 pb-3",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-background p-2",children:[e.jsx("input",{type:"checkbox",id:"force-takeover",checked:T,onChange:C=>k(C.target.checked),className:"mt-0.5 h-4 w-4 rounded border-gray-300"}),e.jsx("label",{htmlFor:"force-takeover",className:"flex-1 text-xs text-muted-foreground",children:r("I understand this will immediately close the editor for {{currentEditorName}}. I am using this option with caution.",{currentEditorName:x})})]}),e.jsxs(p.Button,{disabled:!T||E,variant:"destructive",onClick:R,className:"w-full gap-2",children:[e.jsx(c.ShieldAlert,{className:"h-4 w-4"}),r(E?"Take over page...":"Force Take Over")]}),E&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r("Attempting to forcefully take over this page. Please wait while we update the editing session.")})]})})]})})]})})]})})};exports.default=_;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as e, jsxs as t } from "react/jsx-runtime";
|
|
2
2
|
import { F as _, G as w, H as A, I as S, J as F, K, M as I, O as U, Q as V } from "./index-DZheQdw-.js";
|
|
3
3
|
import { B as f } from "./register-chai-top-bar-D6GjnauV.js";
|
|
4
|
-
import {
|
|
4
|
+
import { an as Q, al as q, a as P, am as j, b as B, B as D, E as a, P as G } from "./index-K4yKMKbY.js";
|
|
5
5
|
import { LockKeyhole as H, UserIcon as J, AlertCircleIcon as L, X as z, Edit as X, ShieldAlert as v } from "lucide-react";
|
|
6
6
|
import { useState as p, useRef as W, useEffect as Y, startTransition as Z } from "react";
|
|
7
7
|
import { useTranslation as $ } from "react-i18next";
|
|
8
8
|
const ie = () => {
|
|
9
|
-
const o =
|
|
9
|
+
const o = Q(), x = q(), { setPageStatus: T } = P(), { data: r, isFetching: k } = j((o == null ? void 0 : o.userId) || ""), { pageLockMeta: l, setPageLockMeta: E } = B(), { t: s } = $(), [d, i] = p(""), [n, g] = p({}), [N, b] = p(!1), c = W(null);
|
|
10
10
|
Y(() => {
|
|
11
11
|
l != null && l.type && (c.current && clearTimeout(c.current), Z(() => {
|
|
12
12
|
g(l), E({}), i("");
|