@chaibuilder/pages 0.15.24 → 0.16.1
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-wLnL_T-W.cjs → 2AITGKQY-CD9A6oc6.cjs} +1 -1
- package/dist/{2AITGKQY-B6ojx8vV.js → 2AITGKQY-Z1XcJ6Q7.js} +2 -2
- package/dist/{NCMVHL6D-DGH2CRR6.cjs → NCMVHL6D-CkpM-3og.cjs} +1 -1
- package/dist/{NCMVHL6D-vsNnIwmV.js → NCMVHL6D-DoK0XoIo.js} +4 -4
- package/dist/{ZDWCUMSJ-3BnFdOH2.cjs → ZDWCUMSJ-D32swpGV.cjs} +1 -1
- package/dist/{ZDWCUMSJ-CoYx1TP5.js → ZDWCUMSJ-hGXNxbOK.js} +1 -1
- package/dist/{add-new-language-page-d0-cAxlt.js → add-new-language-page-BZPoqdX-.js} +2 -2
- package/dist/{add-new-language-page-VDZSKD95.cjs → add-new-language-page-D65TpIwK.cjs} +1 -1
- package/dist/{add-new-page-D4IkZL8h.cjs → add-new-page-CQ0aj4RJ.cjs} +1 -1
- package/dist/{add-new-page-Bcoxw6U5.js → add-new-page-DK25Y0zS.js} +1 -1
- package/dist/ai-panel-content-BSGJqnTM.cjs +1 -0
- package/dist/ai-panel-content-DYRZnMgV.js +52 -0
- package/dist/ai-panel-default-lang-BOZrL5Xe.cjs +1 -0
- package/dist/ai-panel-default-lang-DZUqC79y.js +173 -0
- package/dist/ai-panel-message-bubble-Bl-aUeU4.cjs +1 -0
- package/dist/ai-panel-message-bubble-DPAaAMAZ.js +38 -0
- package/dist/ai-panel-other-lang-CCyiE6ha.js +145 -0
- package/dist/ai-panel-other-lang-CNtlT5dM.cjs +1 -0
- package/dist/ai-panel-quick-prompts-DeS7L1f0.cjs +1 -0
- package/dist/ai-panel-quick-prompts-Ds0Ndz7g.js +46 -0
- package/dist/ai-prompt-input-Ch_PLEPN.js +133 -0
- package/dist/ai-prompt-input-Zg6lN1Lo.cjs +1 -0
- package/dist/ai-translation-prompt-BUFjo_om.cjs +1 -0
- package/dist/ai-translation-prompt-BiJ5B_an.js +28 -0
- package/dist/{delete-page-KS6p6b8f.js → delete-page-B95T2Prd.js} +1 -1
- package/dist/{delete-page-DeKAD4Ld.cjs → delete-page-BSop1jNg.cjs} +1 -1
- package/dist/{digital-asset-manager-Dfe9SS09.js → digital-asset-manager-BQNSwfKs.js} +1 -1
- package/dist/{digital-asset-manager-C9gYL2SF.cjs → digital-asset-manager-Bn58WzM6.cjs} +1 -1
- package/dist/{duplicate-page-CKr-HNs-.cjs → duplicate-page-BLxkSiug.cjs} +1 -1
- package/dist/{duplicate-page-vCgYnw4H.js → duplicate-page-CrzzObAj.js} +9 -9
- package/dist/{dynamic-page-selector-A4fqWqZZ.js → dynamic-page-selector-D6wQnNfH.js} +1 -1
- package/dist/{dynamic-page-selector-C7w3TOdK.cjs → dynamic-page-selector-D8UZ63LW.cjs} +1 -1
- package/dist/index-W0r4o5Ro.cjs +5 -0
- package/dist/{index-NSqs69Op.js → index-yhKyIbgs.js} +1035 -1031
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +7 -7
- package/dist/{json-diff-viewer-7TGemUrn.js → json-diff-viewer-ISJS7lHK.js} +1 -1
- package/dist/{json-diff-viewer-nLLX6kJK.cjs → json-diff-viewer-ZeJ3Rp2y.cjs} +1 -1
- package/dist/{lang-panel-C6KxjKn_.js → lang-panel-Bj11IL7k.js} +33 -33
- package/dist/{lang-panel-dc9uBMtE.cjs → lang-panel-DqN_J3vz.cjs} +1 -1
- package/dist/{mark-as-template-CJ9SiEBl.cjs → mark-as-template-CcwAAdrd.cjs} +1 -1
- package/dist/{mark-as-template-CRUOQ_FZ.js → mark-as-template-CmCCMaQg.js} +1 -1
- package/dist/{no-language-page-content--8a37nsW.cjs → no-language-page-content-BXm1k1Aa.cjs} +1 -1
- package/dist/{no-language-page-content-ByHFQjkV.js → no-language-page-content-Cme-zo4R.js} +1 -1
- package/dist/{page-creator-CzUQicdh.cjs → page-creator-ByhjXyHP.cjs} +1 -1
- package/dist/{page-creator-J_CNgdj5.js → page-creator-Zbv4d4H8.js} +2 -2
- package/dist/{page-lock-request-BE9-Oego.cjs → page-lock-request-Cln-EE6Z.cjs} +1 -1
- package/dist/{page-lock-request-CD93n5pq.js → page-lock-request-DDQJb8IA.js} +10 -10
- package/dist/{page-locked-by-dialog-1Lm9dcT6.cjs → page-locked-by-dialog-BIXYITEu.cjs} +1 -1
- package/dist/{page-locked-by-dialog-noDLCQWF.js → page-locked-by-dialog-Csn56a3n.js} +1 -1
- package/dist/{page-manager-new-BoTBCqZF.cjs → page-manager-new-BJaTBpih.cjs} +1 -1
- package/dist/{page-manager-new-D-U4B9y9.js → page-manager-new-BrRxZDfT.js} +67 -67
- package/dist/{page-manager-search-and-filter-BJmETYq-.cjs → page-manager-search-and-filter-Bk3PUjha.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-h-YzJVcH.js → page-manager-search-and-filter-_Hvk3bU3.js} +1 -1
- package/dist/{page-revisions-content-C7DXjFls.js → page-revisions-content-B6fRCBX_.js} +10 -10
- package/dist/{page-revisions-content-BNBb2qYh.cjs → page-revisions-content-C_Ha3tFu.cjs} +1 -1
- package/dist/prompt-helper-Csgu8Rfb.js +187 -0
- package/dist/prompt-helper-DgI1lgGV.cjs +51 -0
- package/dist/{publish-pages-content-DAKh_sSW.js → publish-pages-content-CFEIxKQD.js} +2 -2
- package/dist/{publish-pages-content-DsOVOiBD.cjs → publish-pages-content-DQDNxwHD.cjs} +1 -1
- package/dist/{save-to-lib-BR1Qhw3Q.cjs → save-to-lib-Bl22umTa.cjs} +1 -1
- package/dist/{save-to-lib-BPR_--qN.js → save-to-lib-YyYkF6c6.js} +1 -1
- package/dist/{seo-panel-C7XC-XRg.js → seo-panel-BZlMea1L.js} +1 -1
- package/dist/{seo-panel-CUqtdGoF.cjs → seo-panel-BhxikAkG.cjs} +1 -1
- package/dist/server.cjs +241 -1
- package/dist/server.d.ts +50 -6
- package/dist/server.js +10327 -290
- package/dist/{shared-json-ld-CDffP4G3.cjs → shared-json-ld-BfkH76U3.cjs} +1 -1
- package/dist/{shared-json-ld-0JD8sokD.js → shared-json-ld-E4Ckwlbr.js} +41 -41
- package/dist/{slug-input-BYH90lv1.cjs → slug-input--VmQG0S1.cjs} +1 -1
- package/dist/{slug-input-CvIDihGn.js → slug-input-CKKkqGj4.js} +1 -1
- package/dist/{theme-panel-footer-DPpLzCDu.js → theme-panel-footer-2ERfMsET.js} +1 -1
- package/dist/{theme-panel-footer-CUSfduTK.cjs → theme-panel-footer-CagxEZEO.cjs} +1 -1
- package/dist/{unmark-as-template-CjqRfFDL.js → unmark-as-template-BJ5CTNAe.js} +1 -1
- package/dist/{unmark-as-template-Bxw4t_Xi.cjs → unmark-as-template-CeWpo9wD.cjs} +1 -1
- package/dist/{unpublish-page-BjiB3d7l.cjs → unpublish-page-DmZSVxFj.cjs} +1 -1
- package/dist/{unpublish-page-CKKU1St1.js → unpublish-page-DvOWVBIf.js} +1 -1
- package/dist/{web-preview-D0OpieXz.js → web-preview-DTkIggV7.js} +1 -1
- package/dist/{web-preview-CNMYCWxW.cjs → web-preview-DlSKpPUZ.cjs} +1 -1
- package/package.json +3 -3
- package/dist/ai-panel-content-Cn3SA_Sr.cjs +0 -46
- package/dist/ai-panel-content-qmOJKjkE.js +0 -524
- package/dist/index-LfuCMBwI.cjs +0 -5
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-W0r4o5Ro.cjs"),s=require("@chaibuilder/sdk");exports.ChaiBuilderPagesRealtime=e.ChaiBuilderPagesRealtime;exports.ChaiJsonInput=e.SmartJsonInput;exports.ImagePicker=e.ImagePicker;exports.LanguageSwitcher=e.LanguageSwitcher;exports.NestedPathSelector=e.NestedPathSelector;exports.PermissionChecker=e.PermissionChecker;exports.default=e.ChaiBuilderPages;exports.useActivePage=e.useActivePage;exports.useApiUrl=e.useApiUrl;exports.useBuilderFetch=e.useBuilderFetch;exports.useBuilderPageData=e.useBuilderPageData;exports.useChaiAuth=e.useChaiAuth;exports.useChaiCurrentPage=e.useCurrentPage;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useClearAll=e.useClearAll;exports.useFallbackLang=e.useFallbackLang;exports.useFetch=e.useFetch;exports.useGotoPage=e.useGotoPage;exports.useLanguagePages=e.useLanguagePages;exports.usePageTypes=e.usePageTypes;exports.useReloadPage=e.useReloadPage;exports.useUpdateActivePageMetadata=e.useUpdateActivePageMetadata;exports.useUserPermissions=e.useUserRoleAndPermissions;exports.useWebsitePages=e.useWebsitePages;exports.useWebsiteSetting=e.useWebsiteSetting;Object.keys(s).forEach(a=>{a!=="default"&&!Object.prototype.hasOwnProperty.call(exports,a)&&Object.defineProperty(exports,a,{enumerable:!0,get:()=>s[a]})});
|
package/dist/index.d.ts
CHANGED
|
@@ -83,9 +83,10 @@ declare interface ImagePickerProps {
|
|
|
83
83
|
disabled?: boolean;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
export declare const LanguageSwitcher: ({ showAdd, variant, }: {
|
|
86
|
+
export declare const LanguageSwitcher: ({ showAdd, variant, goToDefaultLang, }: {
|
|
87
87
|
showAdd?: boolean;
|
|
88
88
|
variant?: "ghost" | "outline";
|
|
89
|
+
goToDefaultLang?: boolean;
|
|
89
90
|
}) => JSX.Element | null;
|
|
90
91
|
|
|
91
92
|
declare type LISTEN_EVENTS = "PAGE_LOCKED" | "USER_JOINED" | "TAKE_OVER_REQUESTED" | "UPDATE_ONLINE_USERS" | "TAKE_OVER_REQUEST_ACCEPTED" | "TAKE_OVER_REQUEST_REJECTED";
|
|
@@ -135,13 +136,14 @@ export declare const useActivePage: () => {
|
|
|
135
136
|
|
|
136
137
|
export declare const useApiUrl: () => string;
|
|
137
138
|
|
|
138
|
-
export declare const useBuilderFetch: () => ({ body, headers, url, }: {
|
|
139
|
+
export declare const useBuilderFetch: () => ({ body, headers, url, streamResponse, }: {
|
|
139
140
|
body: {
|
|
140
141
|
action: string;
|
|
141
142
|
data?: any;
|
|
142
143
|
};
|
|
143
144
|
headers?: Record<string, string>;
|
|
144
145
|
url?: string;
|
|
146
|
+
streamResponse?: boolean;
|
|
145
147
|
}) => Promise<any>;
|
|
146
148
|
|
|
147
149
|
export declare const useBuilderPageData: () => UseQueryResult<any, Error>;
|
|
@@ -171,7 +173,7 @@ export declare const useFallbackLang: () => string;
|
|
|
171
173
|
export declare const useFetch: () => (url: string | undefined, body: {
|
|
172
174
|
action: string;
|
|
173
175
|
data?: any;
|
|
174
|
-
}, headers?: Record<string, string
|
|
176
|
+
}, headers?: Record<string, string>, streamResponse?: boolean) => Promise<any>;
|
|
175
177
|
|
|
176
178
|
export declare const useGotoPage: () => ({ pageId }: {
|
|
177
179
|
pageId: string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aW as s,
|
|
1
|
+
import { aW as s, ay as u, aL as t, aj as i, aK as r, as as g, aO as P, aP as l, am as h, q as o, aH as n, aU as c, ar as d, ak as C, aQ as m, f as p, an as f, aR as A, g as U, h as b, aS as k, aT as L, aV as S, b as B, e as F } from "./index-yhKyIbgs.js";
|
|
2
2
|
export * from "@chaibuilder/sdk";
|
|
3
3
|
export {
|
|
4
4
|
s as ChaiBuilderPagesRealtime,
|
|
@@ -15,15 +15,15 @@ export {
|
|
|
15
15
|
c as useChaiAuth,
|
|
16
16
|
d as useChaiCurrentPage,
|
|
17
17
|
C as useChaiUserInfo,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
m as useClearAll,
|
|
19
|
+
p as useFallbackLang,
|
|
20
20
|
f as useFetch,
|
|
21
21
|
A as useGotoPage,
|
|
22
22
|
U as useLanguagePages,
|
|
23
23
|
b as usePageTypes,
|
|
24
24
|
k as useReloadPage,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
L as useUpdateActivePageMetadata,
|
|
26
|
+
S as useUserPermissions,
|
|
27
|
+
B as useWebsitePages,
|
|
28
|
+
F as useWebsiteSetting
|
|
29
29
|
};
|
|
@@ -5,7 +5,7 @@ import { startsWith as T, replace as W, isString as X, trim as Y, isArray as Z,
|
|
|
5
5
|
import { FileJson as F, Loader as ne, Check as B, Copy as H } from "lucide-react";
|
|
6
6
|
import { useState as D, useMemo as A } from "react";
|
|
7
7
|
import { parseDiff as se, Diff as le, Hunk as ae } from "react-diff-view";
|
|
8
|
-
import {
|
|
8
|
+
import { am as ie, an as oe, A as ce, ak as de } from "./index-yhKyIbgs.js";
|
|
9
9
|
import { useQuery as fe } from "@tanstack/react-query";
|
|
10
10
|
function me(t, n) {
|
|
11
11
|
const o = ie(), s = oe(), u = T(t.uid, "draft:") || T(n.uid, "live:");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk/ui"),z=require("date-fns"),p=require("lodash-es"),N=require("lucide-react"),b=require("react"),M=require("react-diff-view"),O=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk/ui"),z=require("date-fns"),p=require("lodash-es"),N=require("lucide-react"),b=require("react"),M=require("react-diff-view"),O=require("./index-W0r4o5Ro.cjs"),B=require("@tanstack/react-query");function H(t,r){const o=O.useApiUrl(),n=O.useFetch(),f=p.startsWith(t.uid,"draft:")||p.startsWith(r.uid,"live:");return B.useQuery({queryKey:["revision-comparison",t.uid,r.uid],queryFn:async()=>{if(!t.uid||!r.uid)throw new Error("Both revision IDs are required for comparison");const l=u=>u==="draft"||u==="live"?u:"revision",s=u=>p.replace(u.uid,`${u.label}:`,"");return await n(o,{action:O.ACTIONS.GET_COMPARE_DATA,data:{versions:{version1:{type:l(t.label),id:s(t)},version2:{type:l(r.label),id:s(r)}}}})},enabled:!!t.uid&&!!r.uid,staleTime:f?0:1/0})}const K=({version:t})=>{const r=t==null?void 0:t.item,{data:o}=O.useChaiUserInfo(r==null?void 0:r.currentEditor),n=t.label==="live",f=t.label==="draft";return e.jsxs("span",{className:`flex items-center gap-x-2 rounded border bg-white px-2 text-xs shadow-lg ${n?"border-green-500/30":f?"border-amber-500/30":"border-purple-500/30"}`,children:[e.jsx("div",{className:"h-full items-center rounded px-1.5 py-0.5 font-medium capitalize"+(n?" bg-green-500 text-green-50":f?" bg-amber-500 text-amber-50":" bg-purple-500 text-purple-50"),children:t.label}),e.jsxs("div",{className:"py-1 text-xs font-light leading-none text-gray-800",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-light opacity-90",children:f?"Currently editing":"Published by"}),!f&&e.jsx("span",{className:"pl-1 font-medium",children:(o==null?void 0:o.name)||"Unknown"})]}),e.jsx("div",{className:"text-[10px] leading-tight",children:z.formatDate(r.createdAt,"dd MMM yyyy, h:mm a")})]})]})},L=({version:t})=>e.jsx(K,{version:t});function V(t,r,o="data.json"){const n=JSON.stringify(t,null,2),f=JSON.stringify(r,null,2),l=n.split(`
|
|
2
2
|
`),s=f.split(`
|
|
3
3
|
`);let d=`--- a/${o}
|
|
4
4
|
`;d+=`+++ b/${o}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as e, jsxs as s, Fragment as M } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { ap as j, h as T, L as I, aq as F, g as H, ar as O, e as W, as as f, at as o } from "./index-yhKyIbgs.js";
|
|
3
3
|
import { useTranslation as G, useLanguages as q } from "@chaibuilder/sdk";
|
|
4
4
|
import { Dialog as B, DialogContent as R, DialogHeader as J, DialogTitle as K, DialogDescription as Q, Alert as V, Label as X, Input as Y, DialogFooter as Z, Button as A, DropdownMenu as ee, DropdownMenuTrigger as se, DropdownMenuContent as ne, DropdownMenuItem as w } from "@chaibuilder/sdk/ui";
|
|
5
|
-
import { find as z, startsWith as E, isEqual as
|
|
5
|
+
import { find as z, startsWith as E, isEqual as te, filter as ae, get as D, map as le, isEmpty as ie } from "lodash-es";
|
|
6
6
|
import { AlertCircle as re, StarIcon as ce, MoreHorizontal as oe, PencilIcon as de, Power as me, TrashIcon as ue } from "lucide-react";
|
|
7
7
|
import { useState as S, lazy as U, useMemo as he, Suspense as L } from "react";
|
|
8
8
|
import { toast as ge } from "sonner";
|
|
@@ -11,10 +11,10 @@ const fe = ({
|
|
|
11
11
|
page: n,
|
|
12
12
|
onClose: g
|
|
13
13
|
}) => {
|
|
14
|
-
const { t } = G(), [i, v] = S(n.slug || ""), { mutate: N, isPending: y } = j(), { data:
|
|
14
|
+
const { t: l } = G(), [i, v] = S(n.slug || ""), { mutate: N, isPending: y } = j(), { data: a } = T(), r = z(a, { key: n == null ? void 0 : n.pageType }), x = (m) => {
|
|
15
15
|
if (m.preventDefault(), !(n != null && n.primaryPage) && Object.keys(I).some((p) => i === `/${p}` || E(i, `/${p}/`))) {
|
|
16
|
-
ge.error(
|
|
17
|
-
description:
|
|
16
|
+
ge.error(l("Error"), {
|
|
17
|
+
description: l("Slugs cannot start with a language code for primary page")
|
|
18
18
|
});
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
@@ -22,10 +22,10 @@ const fe = ({
|
|
|
22
22
|
}, d = (n == null ? void 0 : n.lang) || "";
|
|
23
23
|
return /* @__PURE__ */ e(B, { open: !!n, onOpenChange: g, children: /* @__PURE__ */ s(R, { children: [
|
|
24
24
|
/* @__PURE__ */ s(J, { children: [
|
|
25
|
-
/* @__PURE__ */ e(K, { children:
|
|
25
|
+
/* @__PURE__ */ e(K, { children: l("Change Slug") }),
|
|
26
26
|
/* @__PURE__ */ e(Q, { className: "text-xs", children: /* @__PURE__ */ s(V, { variant: "destructive", className: "mt-2", children: [
|
|
27
27
|
/* @__PURE__ */ e(re, { className: "h-4 w-4" }),
|
|
28
|
-
|
|
28
|
+
l("Changing the slug may have impact on your SEO. Please proceed with caution.")
|
|
29
29
|
] }) })
|
|
30
30
|
] }),
|
|
31
31
|
/* @__PURE__ */ s("form", { onSubmit: x, children: [
|
|
@@ -33,7 +33,7 @@ const fe = ({
|
|
|
33
33
|
/* @__PURE__ */ s("div", { className: "space-y-1", children: [
|
|
34
34
|
/* @__PURE__ */ s("div", { children: [
|
|
35
35
|
/* @__PURE__ */ s("span", { children: [
|
|
36
|
-
|
|
36
|
+
l("Type"),
|
|
37
37
|
":"
|
|
38
38
|
] }),
|
|
39
39
|
/* @__PURE__ */ s("span", { className: "font-medium text-gray-600", children: [
|
|
@@ -43,7 +43,7 @@ const fe = ({
|
|
|
43
43
|
] }),
|
|
44
44
|
/* @__PURE__ */ s("div", { children: [
|
|
45
45
|
/* @__PURE__ */ s("span", { children: [
|
|
46
|
-
|
|
46
|
+
l("Name"),
|
|
47
47
|
":"
|
|
48
48
|
] }),
|
|
49
49
|
/* @__PURE__ */ s("span", { className: "font-medium text-gray-600", children: [
|
|
@@ -54,10 +54,10 @@ const fe = ({
|
|
|
54
54
|
] }),
|
|
55
55
|
/* @__PURE__ */ s("div", { className: "space-y-1", children: [
|
|
56
56
|
/* @__PURE__ */ s(X, { htmlFor: "slug", className: "text-right", children: [
|
|
57
|
-
|
|
57
|
+
l("Slug"),
|
|
58
58
|
" ",
|
|
59
59
|
/* @__PURE__ */ s("small", { className: "font-light text-gray-500", children: [
|
|
60
|
-
|
|
60
|
+
l("Slug should start with"),
|
|
61
61
|
" /",
|
|
62
62
|
d
|
|
63
63
|
] })
|
|
@@ -74,8 +74,8 @@ const fe = ({
|
|
|
74
74
|
className: "col-span-3",
|
|
75
75
|
required: !0,
|
|
76
76
|
pattern: "^/.*",
|
|
77
|
-
title:
|
|
78
|
-
placeholder:
|
|
77
|
+
title: l("Slug must start with /"),
|
|
78
|
+
placeholder: l("Enter page slug")
|
|
79
79
|
}
|
|
80
80
|
)
|
|
81
81
|
] })
|
|
@@ -84,37 +84,37 @@ const fe = ({
|
|
|
84
84
|
A,
|
|
85
85
|
{
|
|
86
86
|
type: "submit",
|
|
87
|
-
disabled: y || !E(i, `/${d}`) ||
|
|
88
|
-
children:
|
|
87
|
+
disabled: y || !E(i, `/${d}`) || te(n == null ? void 0 : n.slug, i),
|
|
88
|
+
children: l(y ? "Changing..." : "Change Slug")
|
|
89
89
|
}
|
|
90
90
|
) })
|
|
91
91
|
] })
|
|
92
92
|
] }) });
|
|
93
|
-
}, Ne = U(() => import("./delete-page-
|
|
94
|
-
const { t: n } = G(), [, g] = pe(F), { selectedLang:
|
|
95
|
-
const
|
|
96
|
-
return
|
|
97
|
-
}, [r,
|
|
93
|
+
}, Ne = U(() => import("./delete-page-B95T2Prd.js")), ye = U(() => import("./unpublish-page-DvOWVBIf.js")), Pe = () => {
|
|
94
|
+
const { t: n } = G(), [, g] = pe(F), { selectedLang: l, fallbackLang: i, setSelectedLang: v } = q(), { data: N, isFetching: y } = H(), { data: a } = O(), { data: r } = T(), x = he(() => {
|
|
95
|
+
const t = r == null ? void 0 : r.find((h) => h.key === (a == null ? void 0 : a.pageType));
|
|
96
|
+
return a != null && a.dynamic ? t == null ? void 0 : t.dynamicSlug : "";
|
|
97
|
+
}, [r, a == null ? void 0 : a.pageType, a == null ? void 0 : a.dynamic]), [d, m] = S(null), [u, C] = S(null), [p, _] = S(null), { data: P } = W(), $ = ae(
|
|
98
98
|
D(P, "languages") || ["en"],
|
|
99
|
-
(
|
|
99
|
+
(t) => !z(N, { lang: t }) && t !== D(P, "fallbackLang")
|
|
100
100
|
);
|
|
101
101
|
return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
|
|
102
102
|
/* @__PURE__ */ e("ul", { className: "space-y-2", children: y ? /* @__PURE__ */ s("div", { className: "w-full space-y-3 py-4", children: [
|
|
103
103
|
/* @__PURE__ */ e("div", { className: "h-8 w-full animate-pulse rounded bg-gray-300" }),
|
|
104
104
|
/* @__PURE__ */ e("div", { className: "h-8 w-full animate-pulse rounded bg-gray-300" }),
|
|
105
105
|
/* @__PURE__ */ e("div", { className: "h-8 w-full animate-pulse rounded bg-gray-300" })
|
|
106
|
-
] }) :
|
|
107
|
-
const h =
|
|
106
|
+
] }) : le(N, (t) => {
|
|
107
|
+
const h = t.lang, b = t.slug, k = !t.primaryPage;
|
|
108
108
|
return /* @__PURE__ */ s(M, { children: [
|
|
109
109
|
/* @__PURE__ */ s(
|
|
110
110
|
"li",
|
|
111
111
|
{
|
|
112
|
-
className: `flex w-full cursor-pointer items-center justify-between rounded p-2 text-slate-500 ${h ===
|
|
112
|
+
className: `flex w-full cursor-pointer items-center justify-between rounded p-2 text-slate-500 ${h === l ? "bg-gray-200" : "hover:bg-gray-100"}`,
|
|
113
113
|
onClick: () => v(h),
|
|
114
114
|
children: [
|
|
115
115
|
/* @__PURE__ */ s("div", { className: "flex-1 gap-x-3", children: [
|
|
116
116
|
/* @__PURE__ */ s("div", { className: "flex items-center gap-x-2 text-[13px] text-slate-800", children: [
|
|
117
|
-
/* @__PURE__ */ e("div", { className: `h-2.5 w-2.5 rounded-full ${
|
|
117
|
+
/* @__PURE__ */ e("div", { className: `h-2.5 w-2.5 rounded-full ${t.online ? "bg-green-300" : "bg-gray-300"}` }),
|
|
118
118
|
D(I, k ? i : h, h)
|
|
119
119
|
] }),
|
|
120
120
|
/* @__PURE__ */ s("div", { children: [
|
|
@@ -126,7 +126,7 @@ const fe = ({
|
|
|
126
126
|
"Name:",
|
|
127
127
|
/* @__PURE__ */ s("b", { className: "font-medium", children: [
|
|
128
128
|
" ",
|
|
129
|
-
|
|
129
|
+
t.name,
|
|
130
130
|
" "
|
|
131
131
|
] })
|
|
132
132
|
] })
|
|
@@ -153,8 +153,8 @@ const fe = ({
|
|
|
153
153
|
onClick: (c) => {
|
|
154
154
|
c.stopPropagation(), g({
|
|
155
155
|
edit: !0,
|
|
156
|
-
id:
|
|
157
|
-
primaryPage:
|
|
156
|
+
id: t.id,
|
|
157
|
+
primaryPage: t.primaryPage
|
|
158
158
|
});
|
|
159
159
|
},
|
|
160
160
|
children: [
|
|
@@ -163,12 +163,12 @@ const fe = ({
|
|
|
163
163
|
]
|
|
164
164
|
}
|
|
165
165
|
) }),
|
|
166
|
-
/* @__PURE__ */ e(f, { permissions: [o.UNPUBLISH_PAGE], children: (
|
|
166
|
+
/* @__PURE__ */ e(f, { permissions: [o.UNPUBLISH_PAGE], children: (t == null ? void 0 : t.online) && /* @__PURE__ */ s(
|
|
167
167
|
w,
|
|
168
168
|
{
|
|
169
169
|
className: "flex cursor-pointer items-center gap-2",
|
|
170
170
|
onClick: (c) => {
|
|
171
|
-
c.stopPropagation(), C(
|
|
171
|
+
c.stopPropagation(), C(t);
|
|
172
172
|
},
|
|
173
173
|
children: [
|
|
174
174
|
/* @__PURE__ */ e(me, { className: "size-3" }),
|
|
@@ -181,7 +181,7 @@ const fe = ({
|
|
|
181
181
|
{
|
|
182
182
|
className: "flex cursor-pointer items-center gap-2",
|
|
183
183
|
onClick: (c) => {
|
|
184
|
-
c.stopPropagation(), m(
|
|
184
|
+
c.stopPropagation(), m(t);
|
|
185
185
|
},
|
|
186
186
|
children: [
|
|
187
187
|
/* @__PURE__ */ e(ue, { className: "size-3" }),
|
|
@@ -195,7 +195,7 @@ const fe = ({
|
|
|
195
195
|
) })
|
|
196
196
|
]
|
|
197
197
|
},
|
|
198
|
-
|
|
198
|
+
t.id
|
|
199
199
|
),
|
|
200
200
|
/* @__PURE__ */ e("div", { className: "h-1 w-full border-b" })
|
|
201
201
|
] });
|
|
@@ -208,7 +208,7 @@ const fe = ({
|
|
|
208
208
|
disabled: ie($),
|
|
209
209
|
onClick: () => {
|
|
210
210
|
g({
|
|
211
|
-
primaryPage:
|
|
211
|
+
primaryPage: a == null ? void 0 : a.id,
|
|
212
212
|
edit: !1
|
|
213
213
|
});
|
|
214
214
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-W0r4o5Ro.cjs"),C=require("@chaibuilder/sdk"),i=require("@chaibuilder/sdk/ui"),r=require("lodash-es"),j=require("lucide-react"),c=require("react"),k=require("sonner"),G=require("jotai"),L=({page:s,onClose:S})=>{const{t:a}=C.useTranslation(),[o,E]=c.useState(s.slug||""),{mutate:N,isPending:y}=n.useChangeSlug(),{data:l}=n.usePageTypes(),d=r.find(l,{key:s==null?void 0:s.pageType}),f=h=>{if(h.preventDefault(),!(s!=null&&s.primaryPage)&&Object.keys(n.LANGUAGES).some(p=>o===`/${p}`||r.startsWith(o,`/${p}/`))){k.toast.error(a("Error"),{description:a("Slugs cannot start with a language code for primary page")});return}N({...s,slug:o},{onSuccess:S})},m=(s==null?void 0:s.lang)||"";return e.jsx(i.Dialog,{open:!!s,onOpenChange:S,children:e.jsxs(i.DialogContent,{children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:a("Change Slug")}),e.jsx(i.DialogDescription,{className:"text-xs",children:e.jsxs(i.Alert,{variant:"destructive",className:"mt-2",children:[e.jsx(j.AlertCircle,{className:"h-4 w-4"}),a("Changing the slug may have impact on your SEO. Please proceed with caution.")]})})]}),e.jsxs("form",{onSubmit:f,children:[e.jsxs("div",{className:"space-y-4 py-4 text-sm ",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{children:[e.jsxs("span",{children:[a("Type"),":"]}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",(d==null?void 0:d.name)||(s==null?void 0:s.pageType)]})]}),e.jsxs("div",{children:[e.jsxs("span",{children:[a("Name"),":"]}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",s.name]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(i.Label,{htmlFor:"slug",className:"text-right",children:[a("Slug")," ",e.jsxs("small",{className:"font-light text-gray-500",children:[a("Slug should start with")," /",m]})]}),e.jsx(i.Input,{id:"slug",value:o,onChange:h=>{const x=h.target.value;r.startsWith(x,`/${m}`)&&E(x)},className:"col-span-3",required:!0,pattern:"^/.*",title:a("Slug must start with /"),placeholder:a("Enter page slug")})]})]}),e.jsx(i.DialogFooter,{children:e.jsx(i.Button,{type:"submit",disabled:y||!r.startsWith(o,`/${m}`)||r.isEqual(s==null?void 0:s.slug,o),children:a(y?"Changing...":"Change Slug")})})]})]})})},M=c.lazy(()=>Promise.resolve().then(()=>require("./delete-page-BSop1jNg.cjs"))),T=c.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-DmZSVxFj.cjs"))),_=()=>{const{t:s}=C.useTranslation(),[,S]=G.useAtom(n.addNewLangAtom),{selectedLang:a,fallbackLang:o,setSelectedLang:E}=C.useLanguages(),{data:N,isFetching:y}=n.useLanguagePages(),{data:l}=n.useCurrentPage(),{data:d}=n.usePageTypes(),f=c.useMemo(()=>{const t=d==null?void 0:d.find(g=>g.key===(l==null?void 0:l.pageType));return l!=null&&l.dynamic?t==null?void 0:t.dynamicSlug:""},[d,l==null?void 0:l.pageType,l==null?void 0:l.dynamic]),[m,h]=c.useState(null),[x,P]=c.useState(null),[p,A]=c.useState(null),{data:b}=n.useWebsiteSetting(),I=r.filter(r.get(b,"languages")||["en"],t=>!r.find(N,{lang:t})&&t!==r.get(b,"fallbackLang"));return e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"space-y-2",children:y?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"})]}):r.map(N,t=>{const g=t.lang,v=t.slug,w=!t.primaryPage,D=g===a;return e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`flex w-full cursor-pointer items-center justify-between rounded p-2 text-slate-500 ${D?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>E(g),children:[e.jsxs("div",{className:"flex-1 gap-x-3",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-[13px] text-slate-800",children:[e.jsx("div",{className:`h-2.5 w-2.5 rounded-full ${t.online?"bg-green-300":"bg-gray-300"}`}),r.get(n.LANGUAGES,w?o:g,g)]}),e.jsxs("div",{children:[v&&e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Slug: ",e.jsx("b",{className:"font-mono font-medium",children:f?`${v}/${f}`:v})]}),e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Name:",e.jsxs("b",{className:"font-medium",children:[" ",t.name," "]})]})]})]}),w?e.jsxs("div",{className:"flex items-center gap-x-1 text-[11px] text-orange-500",children:[e.jsx(j.StarIcon,{fill:"orange",className:"h-3 w-3"}),e.jsx("b",{children:" Primary"})]}):e.jsx("div",{className:"flex items-center gap-x-3",children:e.jsx(n.PermissionChecker,{permissions:[n.PAGES_PERMISSIONS.EDIT_PAGE,n.PAGES_PERMISSIONS.DELETE_PAGE,n.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:e.jsxs(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,onClick:u=>u.stopPropagation(),children:e.jsx(i.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:e.jsx(j.MoreHorizontal,{className:"h-4 w-4"})})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"z-[9999] text-sm",children:[e.jsx(n.PermissionChecker,{permissions:[n.PAGES_PERMISSIONS.EDIT_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:u=>{u.stopPropagation(),S({edit:!0,id:t.id,primaryPage:t.primaryPage})},children:[e.jsx(j.PencilIcon,{className:"size-3"}),s("Edit")]})}),e.jsx(n.PermissionChecker,{permissions:[n.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:(t==null?void 0:t.online)&&e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:u=>{u.stopPropagation(),P(t)},children:[e.jsx(j.Power,{className:"size-3"}),s("Unpublish")]})}),e.jsx(n.PermissionChecker,{permissions:[n.PAGES_PERMISSIONS.DELETE_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:u=>{u.stopPropagation(),h(t)},children:[e.jsx(j.TrashIcon,{className:"size-3"}),s("Delete")]})})]})]})})})]},t.id),e.jsx("div",{className:"h-1 w-full border-b"})]})})}),e.jsx(n.PermissionChecker,{permissions:[n.PAGES_PERMISSIONS.ADD_PAGE],children:e.jsx("div",{className:"flex w-full justify-center",children:e.jsx(i.Button,{variant:"default",size:"sm",disabled:r.isEmpty(I),onClick:()=>{S({primaryPage:l==null?void 0:l.id,edit:!1})},children:s("Add new language page")})})}),m&&e.jsx(c.Suspense,{children:e.jsx(M,{page:m,onClose:()=>h(null)})}),x&&e.jsx(c.Suspense,{children:e.jsx(T,{page:x,onClose:()=>P(null)})}),p&&e.jsx(c.Suspense,{children:e.jsx(L,{page:p,onClose:()=>A(null)})})]})};exports.default=_;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("./index-W0r4o5Ro.cjs"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),y=require("lodash-es"),d=require("lucide-react"),l=require("react"),w=require("sonner"),q=1*1024*1024,A=({page:r,onClose:m})=>{const{t:s}=M.useTranslation(),[g,u]=l.useState(!1),[f,k]=l.useState(""),[c,j]=l.useState(""),[N,p]=l.useState(!1),i=l.useRef(null),T=b.useMarkAsTemplate(),{data:x}=b.usePageTypes(),h=x==null?void 0:x.find(t=>t.key===r.pageType),C=(h==null?void 0:h.name)||y.startCase(r.pageType),I=l.useCallback(t=>{var v;const o=(v=t.target.files)==null?void 0:v[0];if(o){if(o.size>q){w.toast.error(s("File too large"),{description:`${s("Maximum file size is 1MB. Selected file is")} ${(o.size/1024).toFixed(2)}KB.`}),i.current&&(i.current.value="");return}try{p(!0);const n=new FileReader;n.onloadend=()=>{j(n.result),p(!1)},n.readAsDataURL(o)}catch(n){console.error("Error reading file:",n),p(!1),w.toast.error(s("Failed to process image"),{description:n instanceof Error?n.message:s("Unknown error")})}}},[s]),D=()=>{j(""),i.current&&(i.current.value="")},F=()=>{var t;(t=i.current)==null||t.click()},S=()=>{u(!0),T.mutate({page:r,name:r.name,description:f.trim()||void 0,pageType:r.pageType,...c?{previewImage:c}:{}},{onSuccess:()=>{u(!1),m()},onError:()=>{u(!1)}})};return e.jsx(a.Dialog,{open:!0,onOpenChange:m,children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:s("Mark as template")}),e.jsxs(a.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:[s("Are you sure you want to mark this page as a template?"),e.jsx("br",{}),s("Templates can be used to create new pages with the same content.")]})]}),e.jsxs("div",{className:"mb-4 space-y-4 text-xs",children:[e.jsxs("div",{className:"space-y-3 rounded border bg-slate-50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d.Tag,{className:"h-4 w-4 text-slate-500"}),e.jsxs("span",{className:"font-medium text-slate-500",children:[s("Page Name"),":"]}),e.jsx("span",{className:"font-semibold",children:y.startCase(r.name)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d.File,{className:"h-4 w-4 text-slate-500"}),e.jsxs("span",{className:"font-medium text-slate-500",children:[s("Type"),":"]}),e.jsx("span",{className:"font-semibold",children:C})]})]}),e.jsxs("div",{children:[e.jsx(a.Label,{htmlFor:"description",className:"text-xs font-medium",children:s("Description (Optional)")}),e.jsx(a.Textarea,{id:"description",placeholder:s("Describe this template's purpose"),className:"mt-1 h-24 resize-none text-xs",value:f,onChange:t=>k(t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"previewImage",className:"text-xs font-medium",children:s("Preview Image (Optional)")}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Input,{type:"file",id:"previewImage",ref:i,onChange:I,accept:"image/*",className:"hidden"}),e.jsx(a.Button,{type:"button",variant:"outline",onClick:F,disabled:N,className:"w-full",children:N?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),s("Uploading...")]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(d.ImageIcon,{className:"h-4 w-4"}),s("Select image")]})}),c&&e.jsx(a.Button,{type:"button",variant:"outline",size:"icon",onClick:D,children:e.jsx(d.X,{className:"h-4 w-4"})})]}),c&&e.jsx("div",{className:"aspect-video overflow-hidden rounded-md border",children:e.jsx("img",{src:c,alt:s("Preview"),className:"h-full max-h-[200px] w-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("max 1mb")})]})]})]}),e.jsxs(a.DialogFooter,{className:g?"pointer-events-none opacity-75":"",children:[e.jsx(a.Button,{variant:"outline",onClick:t=>{t.stopPropagation(),m()},children:s("Cancel")}),e.jsx(a.Button,{variant:"default",disabled:g,onClick:S,children:s("Mark as template")})]})]})})};exports.default=A;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as t } from "react/jsx-runtime";
|
|
2
|
-
import { n as P, h as z } from "./index-
|
|
2
|
+
import { n as P, h as z } from "./index-yhKyIbgs.js";
|
|
3
3
|
import { useTranslation as E } from "@chaibuilder/sdk";
|
|
4
4
|
import { Dialog as L, DialogContent as S, DialogHeader as U, DialogTitle as B, DialogDescription as R, Label as w, Textarea as j, Input as O, Button as c, DialogFooter as X } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { startCase as y } from "lodash-es";
|
package/dist/{no-language-page-content--8a37nsW.cjs → no-language-page-content-BXm1k1Aa.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-W0r4o5Ro.cjs"),i=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),w=require("lodash-es"),x=require("lucide-react"),P=()=>{const{t:a}=i.useTranslation(),[l,g]=n.useSearchParams(),c=l.get("lang"),u=n.useIsLanguagePageCreated(c),{setSelectedLang:d}=i.useLanguages(),h=()=>{const r=new URLSearchParams(window.location.search);r.delete("lang");const o=r.toString(),m=`${window.location.pathname}${o?`?${o}`:""}`;window.history.pushState({},"",m),g(r),d(""),window.dispatchEvent(new PopStateEvent("popstate"))};if(u)return null;const s=w.get(n.LANGUAGES,c);return e.jsx(n.BlurContainer,{children:e.jsxs(t.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(t.CardHeader,{className:"space-y-1",children:e.jsxs(t.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[e.jsx(x.LockIcon,{className:"h-6 w-6 text-yellow-500"}),a("Page missing for"),' "',s,'" ',a("language"),"."]})}),e.jsx(t.CardContent,{className:"grid gap-4",children:e.jsxs("div",{children:[a("Page is not available in the"),' "',s,'" ',a("language. Either create the page in the"),' "',s,'"',a("language or switch to the base language.")]})}),e.jsx(t.CardFooter,{children:e.jsx(t.Button,{onClick:h,className:"w-full",variant:"destructive",children:a("Switch to default language")})})]})})};exports.default=P;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as s } from "react/jsx-runtime";
|
|
2
|
-
import { i as h, j as u, L as w, B as p } from "./index-
|
|
2
|
+
import { i as h, j as u, L as w, B as p } from "./index-yhKyIbgs.js";
|
|
3
3
|
import { useTranslation as f, useLanguages as P } from "@chaibuilder/sdk";
|
|
4
4
|
import { Card as C, CardHeader as S, CardTitle as L, CardContent as x, CardFooter as N, Button as v } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { get as B } from "lodash-es";
|
|
@@ -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-BYH90lv1.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-LfuCMBwI.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--VmQG0S1.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-W0r4o5Ro.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,11 +1,11 @@
|
|
|
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-CKKkqGj4.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 {
|
|
8
|
+
import { am as Re, an as Ue, A as oe, h as fs, ao as gs, b as ys, c as vs, d as Ns, at as bs, L as Ss } from "./index-yhKyIbgs.js";
|
|
9
9
|
import { useQuery as ze } from "@tanstack/react-query";
|
|
10
10
|
import { toast as E } from "sonner";
|
|
11
11
|
import { g as $e } from "./get-seo-defaults-9zHebckY.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("./index-W0r4o5Ro.cjs"),C=require("@chaibuilder/sdk"),i=require("@chaibuilder/sdk/ui"),n=require("lucide-react"),x=require("react"),N=({userId:d})=>{const{data:r}=l.useChaiUserInfo(d);return(r==null?void 0:r.name)||"Unknown"},f=({isChecking:d,lockingStatus:r,onContinue:j})=>{const{t:s}=C.useTranslation(),[u,h]=x.useState(!1),c=r==="page_is_active_in_other_tab",a=(r==null?void 0:r.length)>0,{pageLock:t,acceptTakeOver:o,rejectTakeOver:m}=l.usePageLockRequestTakeOver(),g=()=>{h(!0),a||c?j():o(),setTimeout(()=>{h(!1)},3e3)};return x.useEffect(()=>{(t==null?void 0:t.requestedBy)==="ANOTHER_TAB"&&o()},[t,o]),(t==null?void 0:t.requestedBy)==="ANOTHER_TAB"?null:d?e.jsx(l.BlurContainer,{children:e.jsx(n.Loader,{className:"h-5 w-5 animate-spin text-primary"})}):e.jsx(l.BlurContainer,{children:e.jsxs(i.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(i.CardHeader,{className:"space-y-1",children:e.jsxs(i.CardTitle,{className:"flex items-center gap-2 text-xl font-medium",children:[u?e.jsx(n.Loader,{className:"h-6 w-6 animate-spin text-gray-500"}):c?e.jsx(n.TableIcon,{className:"h-6 w-6 text-green-500"}):a?e.jsx(n.CheckCircle,{className:"h-6 w-6 text-green-500"}):e.jsx(n.Target,{className:"h-6 w-6 text-green-500"}),s(c?"Page is active in other tab":a?"You can edit the page now.":"Page take over request")]})}),e.jsx(i.CardContent,{className:"grid gap-4",children:e.jsx("div",{children:c?e.jsxs("p",{children:[s("You are already editing this page in another tab. To continue editing here, click on"),' "',s("Continue editing here"),'".']}):a?e.jsx("p",{children:s("This page is released by other user you can continue editing now.")}):e.jsxs("p",{children:[e.jsxs("b",{children:[" ",e.jsx(N,{userId:t==null?void 0:t.requestedBy})]})," ",s("has requested to take over this page."),e.jsx("br",{})," ",s("If you accept, your unsaved changes will be saved.")]})})}),e.jsxs(i.CardFooter,{className:"flex items-center justify-end gap-2",children:[e.jsx(i.Button,{disabled:u,onClick:g,className:a?"":"bg-green-500 hover:bg-green-600",children:c?e.jsxs(e.Fragment,{children:[e.jsx(n.Edit,{className:"h-5 w-5"})," ",s("Continue editing here")]}):a?e.jsxs(e.Fragment,{children:[e.jsx(n.Edit,{className:"h-5 w-5"})," ",s("Continue to edit")]}):e.jsxs(e.Fragment,{children:[e.jsx(n.Check,{className:"h-5 w-5"})," ",s("Accept")]})}),!a&&e.jsxs(i.Button,{variant:"outline",onClick:m,children:[e.jsx(n.X,{className:"h-5 w-5"})," ",s("Reject")]})]})]})})};exports.default=f;
|