@chaibuilder/pages 0.15.0 → 0.15.2
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-CpxlNmec.cjs → 2AITGKQY-C2afI3G9.cjs} +1 -1
- package/dist/{2AITGKQY-gEvxLMa5.js → 2AITGKQY-CpTgZa1B.js} +2 -2
- package/dist/{NCMVHL6D-sV6MElOb.cjs → NCMVHL6D-BdBKMEGN.cjs} +1 -1
- package/dist/{NCMVHL6D-DpycZ17L.js → NCMVHL6D-fVqsZOVq.js} +2 -2
- package/dist/{ZDWCUMSJ-BbzwbqTE.js → ZDWCUMSJ-CTb4F48A.js} +1 -1
- package/dist/{ZDWCUMSJ-BPT9OZay.cjs → ZDWCUMSJ-DHGlUoWR.cjs} +1 -1
- package/dist/{add-new-language-page-B4_z4O8a.cjs → add-new-language-page-CY2hL7A-.cjs} +1 -1
- package/dist/{add-new-language-page-C8LIaHl6.js → add-new-language-page-DY0789ha.js} +2 -2
- package/dist/{add-new-page-JY6dRnC4.js → add-new-page-C6fGkJF9.js} +1 -1
- package/dist/{add-new-page-CQRr6Z8g.cjs → add-new-page-DnVeU4g6.cjs} +1 -1
- package/dist/{delete-page-z88W-Ikh.cjs → delete-page-DZi2DCAb.cjs} +1 -1
- package/dist/{delete-page-Dfa2vyQB.js → delete-page-hLDHKzbl.js} +1 -1
- package/dist/digital-asset-manager-Cj5r9niq.cjs +1 -0
- package/dist/digital-asset-manager-CpoNKOFK.js +1001 -0
- package/dist/{duplicate-page-Welcro7Y.cjs → duplicate-page-CTH0REkv.cjs} +1 -1
- package/dist/{duplicate-page-B0urG1pP.js → duplicate-page-sdO4hRfo.js} +14 -14
- package/dist/{dynamic-page-selector-CyhZ0SRO.js → dynamic-page-selector-EfxbLRp-.js} +1 -1
- package/dist/{dynamic-page-selector-Dn_j_r-h.cjs → dynamic-page-selector-Ki3lEtRJ.cjs} +1 -1
- package/dist/image-editor-CRJ0cNde.cjs +1 -0
- package/dist/image-editor-DR1FYokM.js +111 -0
- package/dist/{index-BSEA_u0X.js → index-CdUDr4JM.js} +1446 -1368
- package/dist/index-vjYir4bk.cjs +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -10
- package/dist/{json-diff-viewer-DVlb4YWD.js → json-diff-viewer-BQSgrzoZ.js} +1 -1
- package/dist/{json-diff-viewer-BIJ4iNWb.cjs → json-diff-viewer-DthVeQzc.cjs} +1 -1
- package/dist/{lang-panel-D0IN38gF.js → lang-panel-DJGvZmRK.js} +29 -29
- package/dist/{lang-panel-l6Teik-4.cjs → lang-panel-DTDqVZGv.cjs} +1 -1
- package/dist/{mark-as-template-DBPJ1gIK.cjs → mark-as-template-BNbkAkrD.cjs} +1 -1
- package/dist/{mark-as-template-B22EANHN.js → mark-as-template-C3669ENB.js} +1 -1
- package/dist/{no-language-page-content-DNNu8wd0.js → no-language-page-content-DMdFjwWT.js} +1 -1
- package/dist/{no-language-page-content-BUHXqSKG.cjs → no-language-page-content-DY-A9YbI.cjs} +1 -1
- package/dist/{page-creator-BPgx7zdJ.js → page-creator-B_X6PI1J.js} +2 -2
- package/dist/{page-creator-DbN3Nvq6.cjs → page-creator-BcoyQ5mT.cjs} +1 -1
- package/dist/{page-lock-request-BFkpw5VN.cjs → page-lock-request-Cl0GyiJp.cjs} +1 -1
- package/dist/{page-lock-request-Br9S1AsA.js → page-lock-request-DJVlDGsX.js} +10 -10
- package/dist/{page-locked-by-dialog-2h8cv1tO.cjs → page-locked-by-dialog-CZvpeWVu.cjs} +1 -1
- package/dist/{page-locked-by-dialog-DyLcMu33.js → page-locked-by-dialog-DY_jVajL.js} +1 -1
- package/dist/{page-manager-new-B2oBm4pU.js → page-manager-new-BKr1R3Yu.js} +37 -37
- package/dist/{page-manager-new-CAj6WV-C.cjs → page-manager-new-v2nHss3Q.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-CWMXLTqE.cjs → page-manager-search-and-filter-CibEmd6Z.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-WQYVXUAt.js → page-manager-search-and-filter-DLrJ5bRM.js} +1 -1
- package/dist/{page-revisions-content-AMH8AxBU.cjs → page-revisions-content-Bv1b1HsS.cjs} +1 -1
- package/dist/{page-revisions-content-DM-ngq3R.js → page-revisions-content-C4hAdUVX.js} +17 -17
- package/dist/{publish-pages-content-Dast4sG6.js → publish-pages-content-B-8X8FzF.js} +2 -2
- package/dist/{publish-pages-content-Dkv0Lok8.cjs → publish-pages-content-Krawy2bg.cjs} +1 -1
- package/dist/{save-to-lib-B5k0MVbW.js → save-to-lib-BV_uNHn3.js} +12 -12
- package/dist/{save-to-lib-DWtmtrUj.cjs → save-to-lib-CiX1h4Po.cjs} +1 -1
- package/dist/{seo-panel-D75jQH_j.js → seo-panel-BHqhAOiz.js} +34 -34
- package/dist/{seo-panel-dBvEEfi9.cjs → seo-panel-CpjeH5Yl.cjs} +1 -1
- package/dist/shared-json-ld-BfkvfAZY.js +650 -0
- package/dist/shared-json-ld-C-fV8erH.cjs +1 -0
- package/dist/{slug-input-BEegJ8bv.js → slug-input-Dz9A1ksl.js} +1 -1
- package/dist/{slug-input-BITq28nI.cjs → slug-input-ssMiXYTG.cjs} +1 -1
- package/dist/{theme-panel-footer-zLXS6SHh.js → theme-panel-footer-DZSU9bNX.js} +1 -1
- package/dist/{theme-panel-footer-DcASH9l1.cjs → theme-panel-footer-Rmw520a9.cjs} +1 -1
- package/dist/{unmark-as-template-DXFRY_pc.js → unmark-as-template-D8o31xMH.js} +1 -1
- package/dist/{unmark-as-template-ChmjL4-w.cjs → unmark-as-template-D_Td5Aeb.cjs} +1 -1
- package/dist/{unpublish-page-BxN0deJK.cjs → unpublish-page-Bca-dVic.cjs} +1 -1
- package/dist/{unpublish-page-DMteaCpR.js → unpublish-page-D9XisIu8.js} +1 -1
- package/dist/{web-preview-DM11qhOe.cjs → web-preview-BddtAY2w.cjs} +1 -1
- package/dist/{web-preview-BDTdFQ2h.js → web-preview-Dn1aCs5v.js} +1 -1
- package/package.json +1 -1
- package/dist/digital-asset-manager-Zh-mlMF5.cjs +0 -1
- package/dist/digital-asset-manager-hqMwBWhb.js +0 -976
- package/dist/image-editor-BWLJT1mr.cjs +0 -1
- package/dist/image-editor-CzFST20j.js +0 -104
- package/dist/index-MlpQJHWW.cjs +0 -5
- package/dist/shared-json-ld-BvWyXBz_.cjs +0 -1
- package/dist/shared-json-ld-ZtwsYt9H.js +0 -337
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("./index-vjYir4bk.cjs"),s=require("@chaibuilder/sdk/ui"),b=require("lodash-es"),o=require("lucide-react"),i=require("react"),y=require("sonner"),S=1*1024*1024,M=({page:n,onClose:d})=>{const[h,m]=i.useState(!1),[g,w]=i.useState(""),[l,f]=i.useState(""),[j,u]=i.useState(!1),r=i.useRef(null),k=v.useMarkAsTemplate(),{data:p}=v.usePageTypes(),x=p==null?void 0:p.find(a=>a.key===n.pageType),C=(x==null?void 0:x.name)||b.startCase(n.pageType),I=i.useCallback(a=>{var N;const c=(N=a.target.files)==null?void 0:N[0];if(c){if(c.size>S){y.toast.error("File too large",{description:`Maximum file size is 1MB. Selected file is ${(c.size/1024).toFixed(2)}KB.`}),r.current&&(r.current.value="");return}try{u(!0);const t=new FileReader;t.onloadend=()=>{f(t.result),u(!1)},t.readAsDataURL(c)}catch(t){console.error("Error reading file:",t),u(!1),y.toast.error("Failed to process image",{description:t instanceof Error?t.message:"Unknown error"})}}},[]),T=()=>{f(""),r.current&&(r.current.value="")},D=()=>{var a;(a=r.current)==null||a.click()},F=()=>{m(!0),k.mutate({page:n,name:n.name,description:g.trim()||void 0,pageType:n.pageType,...l?{previewImage:l}:{}},{onSuccess:()=>{m(!1),d()},onError:()=>{m(!1)}})};return e.jsx(s.Dialog,{open:!0,onOpenChange:d,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Mark as template"}),e.jsxs(s.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:["Are you sure you want to mark this page as a template?",e.jsx("br",{}),"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(o.Tag,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Page Name:"}),e.jsx("span",{className:"font-semibold",children:b.startCase(n.name)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.File,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Type:"}),e.jsx("span",{className:"font-semibold",children:C})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"description",className:"text-xs font-medium",children:"Description (Optional)"}),e.jsx(s.Textarea,{id:"description",placeholder:"Describe this template's purpose",className:"mt-1 h-24 resize-none text-xs",value:g,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"previewImage",className:"text-xs font-medium",children:"Preview Image (Optional)"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input,{type:"file",id:"previewImage",ref:r,onChange:I,accept:"image/*",className:"hidden"}),e.jsx(s.Button,{type:"button",variant:"outline",onClick:D,disabled:j,className:"w-full",children:j?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"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(o.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),l&&e.jsx(s.Button,{type:"button",variant:"outline",size:"icon",onClick:T,children:e.jsx(o.X,{className:"h-4 w-4"})})]}),l&&e.jsx("div",{className:"aspect-video overflow-hidden rounded-md border",children:e.jsx("img",{src:l,alt:"Preview",className:"h-full max-h-[200px] w-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"max 1mb"})]})]})]}),e.jsxs(s.DialogFooter,{className:h?"pointer-events-none opacity-75":"",children:[e.jsx(s.Button,{variant:"outline",onClick:a=>{a.stopPropagation(),d()},children:"Cancel"}),e.jsx(s.Button,{variant:"default",disabled:h,onClick:F,children:"Mark as template"})]})]})})};exports.default=M;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as a } from "react/jsx-runtime";
|
|
2
|
-
import { n as A, h as P } from "./index-
|
|
2
|
+
import { n as A, h as P } from "./index-CdUDr4JM.js";
|
|
3
3
|
import { Dialog as z, DialogContent as E, DialogHeader as L, DialogTitle as S, DialogDescription as U, Label as b, Textarea as B, Input as R, Button as o, DialogFooter as j } from "@chaibuilder/sdk/ui";
|
|
4
4
|
import { startCase as w } from "lodash-es";
|
|
5
5
|
import { Tag as O, File as X, ImageIcon as _, X as H } from "lucide-react";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as a, jsxs as n } from "react/jsx-runtime";
|
|
2
|
-
import { i as m, j as h, L as u, B as w } from "./index-
|
|
2
|
+
import { i as m, j as h, L as u, B as w } from "./index-CdUDr4JM.js";
|
|
3
3
|
import { useLanguages as p } from "@chaibuilder/sdk";
|
|
4
4
|
import { Card as f, CardHeader as P, CardTitle as C, CardContent as S, CardFooter as L, Button as x } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { get as N } from "lodash-es";
|
package/dist/{no-language-page-content-BUHXqSKG.cjs → no-language-page-content-DY-A9YbI.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-vjYir4bk.cjs"),h=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),m=require("lodash-es"),w=require("lucide-react"),x=()=>{const[o,i]=t.useSearchParams(),r=o.get("lang"),l=t.useIsLanguagePageCreated(r),{setSelectedLang:g}=h.useLanguages(),u=()=>{const s=new URLSearchParams(window.location.search);s.delete("lang");const c=s.toString(),d=`${window.location.pathname}${c?`?${c}`:""}`;window.history.pushState({},"",d),i(s),g(""),window.dispatchEvent(new PopStateEvent("popstate"))};if(l)return null;const n=m.get(t.LANGUAGES,r);return e.jsx(t.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[e.jsx(w.LockIcon,{className:"h-6 w-6 text-yellow-500"}),'Page missing for "',n,'" language.']})}),e.jsx(a.CardContent,{className:"grid gap-4",children:e.jsxs("div",{children:['Page is not available in the "',n,'" language. Either create the page in the "',n,'" language or switch to the base language.']})}),e.jsx(a.CardFooter,{children:e.jsx(a.Button,{onClick:u,className:"w-full",variant:"destructive",children:"Switch to default language"})})]})})};exports.default=x;
|
|
@@ -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-Dz9A1ksl.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 { al as Re, am as Ue, A as oe, h as fs, an as gs, b as ys, c as vs, d as Ns, as as bs, L as Ss } from "./index-CdUDr4JM.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"),n=require("@chaibuilder/sdk/ui"),i=require("react"),$=require("./slug-input-BITq28nI.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-MlpQJHWW.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-ssMiXYTG.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-vjYir4bk.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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./index-vjYir4bk.cjs"),a=require("@chaibuilder/sdk/ui"),t=require("lucide-react"),h=require("react"),g=({userId:l})=>{const{data:n}=c.useChaiUserInfo(l);return(n==null?void 0:n.name)||"Unknown"},C=({isChecking:l,lockingStatus:n,onContinue:x})=>{const[o,u]=h.useState(!1),i=n==="page_is_active_in_other_tab",r=(n==null?void 0:n.length)>0,{pageLock:s,acceptTakeOver:d,rejectTakeOver:j}=c.usePageLockRequestTakeOver(),m=()=>{u(!0),r||i?x():d(),setTimeout(()=>{u(!1)},3e3)};return h.useEffect(()=>{(s==null?void 0:s.requestedBy)==="ANOTHER_TAB"&&d()},[s,d]),(s==null?void 0:s.requestedBy)==="ANOTHER_TAB"?null:l?e.jsx(c.BlurContainer,{children:e.jsx(t.Loader,{className:"h-5 w-5 animate-spin text-primary"})}):e.jsx(c.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-xl font-medium",children:[o?e.jsx(t.Loader,{className:"h-6 w-6 animate-spin text-gray-500"}):i?e.jsx(t.TableIcon,{className:"h-6 w-6 text-green-500"}):r?e.jsx(t.CheckCircle,{className:"h-6 w-6 text-green-500"}):e.jsx(t.Target,{className:"h-6 w-6 text-green-500"}),i?"Page is active in other tab":r?"You can edit the page now.":"Page take over request"]})}),e.jsx(a.CardContent,{className:"grid gap-4",children:e.jsx("div",{children:i?e.jsx("p",{children:'You are already editing this page in another tab. To continue editing here, click on "Continue editing here".'}):r?e.jsx("p",{children:"This page is released by other user you can continue editing now."}):e.jsxs("p",{children:[e.jsxs("b",{children:[" ",e.jsx(g,{userId:s==null?void 0:s.requestedBy})]})," ","has requested to take over this page.",e.jsx("br",{})," If you accept, your unsaved changes will be saved."]})})}),e.jsxs(a.CardFooter,{className:"flex items-center justify-end gap-2",children:[e.jsx(a.Button,{disabled:o,onClick:m,className:r?"":"bg-green-500 hover:bg-green-600",children:i?e.jsxs(e.Fragment,{children:[e.jsx(t.Edit,{className:"h-5 w-5"})," Continue editing here"]}):r?e.jsxs(e.Fragment,{children:[e.jsx(t.Edit,{className:"h-5 w-5"})," Continue to edit"]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Check,{className:"h-5 w-5"})," Accept"]})}),!r&&e.jsxs(a.Button,{variant:"outline",onClick:j,children:[e.jsx(t.X,{className:"h-5 w-5"})," Reject"]})]})]})})};exports.default=C;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as e, jsxs as a, Fragment as l } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { aj as N, ak as w, B as h } from "./index-CdUDr4JM.js";
|
|
3
3
|
import { Card as x, CardHeader as T, CardTitle as b, CardContent as v, CardFooter as y, Button as m } from "@chaibuilder/sdk/ui";
|
|
4
|
-
import { Loader as u, TableIcon as
|
|
5
|
-
import { useState as
|
|
6
|
-
const
|
|
4
|
+
import { Loader as u, TableIcon as B, CheckCircle as q, Target as _, Edit as f, Check as j, X as A } from "lucide-react";
|
|
5
|
+
import { useState as I, useEffect as O } from "react";
|
|
6
|
+
const k = ({ userId: i }) => {
|
|
7
7
|
const { data: r } = N(i);
|
|
8
8
|
return (r == null ? void 0 : r.name) || "Unknown";
|
|
9
9
|
}, F = ({
|
|
@@ -11,22 +11,22 @@ const E = ({ userId: i }) => {
|
|
|
11
11
|
lockingStatus: r,
|
|
12
12
|
onContinue: g
|
|
13
13
|
}) => {
|
|
14
|
-
const [d, o] =
|
|
14
|
+
const [d, o] = I(!1), s = r === "page_is_active_in_other_tab", n = (r == null ? void 0 : r.length) > 0, { pageLock: t, acceptTakeOver: c, rejectTakeOver: p } = w(), C = () => {
|
|
15
15
|
o(!0), n || s ? g() : c(), setTimeout(() => {
|
|
16
16
|
o(!1);
|
|
17
17
|
}, 3e3);
|
|
18
18
|
};
|
|
19
|
-
return
|
|
19
|
+
return O(() => {
|
|
20
20
|
(t == null ? void 0 : t.requestedBy) === "ANOTHER_TAB" && c();
|
|
21
21
|
}, [t, c]), (t == null ? void 0 : t.requestedBy) === "ANOTHER_TAB" ? null : i ? /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(u, { className: "h-5 w-5 animate-spin text-primary" }) }) : /* @__PURE__ */ e(h, { children: /* @__PURE__ */ a(x, { className: "mx-auto w-full max-w-md", children: [
|
|
22
22
|
/* @__PURE__ */ e(T, { className: "space-y-1", children: /* @__PURE__ */ a(b, { className: "flex items-center gap-2 text-xl font-medium", children: [
|
|
23
|
-
d ? /* @__PURE__ */ e(u, { className: "h-6 w-6 animate-spin text-gray-500" }) : s ? /* @__PURE__ */ e(
|
|
23
|
+
d ? /* @__PURE__ */ e(u, { className: "h-6 w-6 animate-spin text-gray-500" }) : s ? /* @__PURE__ */ e(B, { className: "h-6 w-6 text-green-500" }) : n ? /* @__PURE__ */ e(q, { className: "h-6 w-6 text-green-500" }) : /* @__PURE__ */ e(_, { className: "h-6 w-6 text-green-500" }),
|
|
24
24
|
s ? "Page is active in other tab" : n ? "You can edit the page now." : "Page take over request"
|
|
25
25
|
] }) }),
|
|
26
26
|
/* @__PURE__ */ e(v, { className: "grid gap-4", children: /* @__PURE__ */ e("div", { children: s ? /* @__PURE__ */ e("p", { children: 'You are already editing this page in another tab. To continue editing here, click on "Continue editing here".' }) : n ? /* @__PURE__ */ e("p", { children: "This page is released by other user you can continue editing now." }) : /* @__PURE__ */ a("p", { children: [
|
|
27
27
|
/* @__PURE__ */ a("b", { children: [
|
|
28
28
|
" ",
|
|
29
|
-
/* @__PURE__ */ e(
|
|
29
|
+
/* @__PURE__ */ e(k, { userId: t == null ? void 0 : t.requestedBy })
|
|
30
30
|
] }),
|
|
31
31
|
" ",
|
|
32
32
|
"has requested to take over this page.",
|
|
@@ -47,13 +47,13 @@ const E = ({ userId: i }) => {
|
|
|
47
47
|
/* @__PURE__ */ e(f, { className: "h-5 w-5" }),
|
|
48
48
|
" Continue to edit"
|
|
49
49
|
] }) : /* @__PURE__ */ a(l, { children: [
|
|
50
|
-
/* @__PURE__ */ e(
|
|
50
|
+
/* @__PURE__ */ e(j, { className: "h-5 w-5" }),
|
|
51
51
|
" Accept"
|
|
52
52
|
] })
|
|
53
53
|
}
|
|
54
54
|
),
|
|
55
55
|
!n && /* @__PURE__ */ a(m, { variant: "outline", onClick: p, children: [
|
|
56
|
-
/* @__PURE__ */ e(
|
|
56
|
+
/* @__PURE__ */ e(A, { className: "h-5 w-5" }),
|
|
57
57
|
" Reject"
|
|
58
58
|
] })
|
|
59
59
|
] })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("@chaibuilder/sdk/ui"),m=require("date-fns"),r=require("lucide-react"),h=require("react"),j=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("@chaibuilder/sdk/ui"),m=require("date-fns"),r=require("lucide-react"),h=require("react"),j=require("./index-vjYir4bk.cjs");function p({avatar:d,name:a,email:l,lastSaved:n,onTakeOver:u,isRequestRejected:c,isFetchingUserInfo:t}){const[i,o]=h.useState(!1),x=()=>{o(!0),setTimeout(()=>{o(!1)},15e3),u()};return e.jsx(j.BlurContainer,{children:e.jsxs(s.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(s.CardHeader,{className:"space-y-1",children:e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(r.LockKeyhole,{className:"h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500"}),"Page is locked for editing"]})}),e.jsx(s.CardContent,{className:"w-md grid w-full pt-2",children:e.jsxs("div",{children:[e.jsxs("div",{className:"relative mx-auto flex w-96 items-center space-x-4 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:"Locked By"}),d&&!t?e.jsx("img",{src:d,alt:a,className:"h-14 w-14 rounded-full border border-gray-300"}):e.jsx(r.UserIcon,{className:"h-14 w-14 flex-shrink-0 rounded-full bg-gradient-to-br from-purple-400 to-pink-500 p-2 text-white"}),e.jsxs("div",{className:t?"space-y-1.5":"space-y-0",children:[t?e.jsx(s.Skeleton,{className:"h-4 w-40 rounded"}):e.jsx("span",{className:"truncate font-medium text-black",children:a}),l&&!t?e.jsx("p",{className:"truncate text-sm text-muted-foreground",children:l}):e.jsx(s.Skeleton,{className:"h-4 w-60 rounded"}),n&&!t?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Last saved:"," ",m.formatDistanceToNow(new Date(n),{addSuffix:!0})]}):e.jsx(s.Skeleton,{className:"h-4 w-40 rounded"})]})]}),e.jsx("div",{className:"mt-4 text-sm",children:e.jsxs("p",{className:"py-4 text-center text-gray-600",children:["This page is currently being edited by ",e.jsx("span",{className:"font-bold",children:a}),".",e.jsx("br",{}),e.jsx("br",{})," You can either wait until they finish editing or request to take over the page."]})}),c&&e.jsxs("div",{className:"mt-4 flex w-full items-center justify-center gap-x-2 rounded border border-red-500 bg-red-50 p-2 text-center font-medium text-red-500",children:[e.jsx(r.Info,{className:"h-5 w-5"})," Page take over request is rejected"]})]})}),e.jsx(s.CardFooter,{children:e.jsxs(s.Button,{disabled:i,onClick:x,className:"w-full",variant:"destructive",children:[e.jsx(r.KeyIcon,{className:"h-5 w-5"}),i?"Page take is requested.":c?"Request take over again":"Request take over"]})})]})})}exports.default=p;
|
|
@@ -3,7 +3,7 @@ import { Card as p, CardHeader as x, CardTitle as f, CardContent as h, Skeleton
|
|
|
3
3
|
import { formatDistanceToNow as b } from "date-fns";
|
|
4
4
|
import { LockKeyhole as w, UserIcon as k, Info as y, KeyIcon as v } from "lucide-react";
|
|
5
5
|
import { useState as C } from "react";
|
|
6
|
-
import { B } from "./index-
|
|
6
|
+
import { B } from "./index-CdUDr4JM.js";
|
|
7
7
|
function K({
|
|
8
8
|
avatar: s,
|
|
9
9
|
name: a,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { jsxs as p, jsx as s, Fragment as
|
|
2
|
-
import {
|
|
1
|
+
import { jsxs as p, jsx as s, Fragment as D } from "react/jsx-runtime";
|
|
2
|
+
import { au as pe, f as oe, aj as be, T as _, aC as ye, L as ge, h as ke, b as Ne, i as we, ap as ve, aD as Se, aE as q } from "./index-CdUDr4JM.js";
|
|
3
3
|
import { u as J } from "./use-page-expand-manager-D6T75I11.js";
|
|
4
|
-
import { compact as ie, filter as
|
|
4
|
+
import { compact as ie, filter as z, isEmpty as v, uniqBy as Ae, keyBy as ce, mapValues as Le, startCase as Te, toLower as E, includes as O, find as j, get as H, map as Ce } from "lodash-es";
|
|
5
5
|
import { useLanguages as re } from "@chaibuilder/sdk";
|
|
6
6
|
import { useAtom as Ee } from "jotai";
|
|
7
|
-
import { NotepadText as Ue, MoreHorizontal as $e, Lock as
|
|
8
|
-
import { useMemo as Q, lazy as U, useState as N, useCallback as ae, useEffect as
|
|
7
|
+
import { NotepadText as Ue, MoreHorizontal as $e, Lock as Me, Edit as je, Plus as ze, ChevronRight as Fe, StarsIcon as Be, Globe as Ie, File as de } from "lucide-react";
|
|
8
|
+
import { useMemo as Q, lazy as U, useState as N, useCallback as ae, useEffect as M, Suspense as C } from "react";
|
|
9
9
|
const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
10
|
-
|
|
10
|
+
z(e, (r) => {
|
|
11
11
|
const t = E(n);
|
|
12
|
-
return
|
|
12
|
+
return O(E((r == null ? void 0 : r.name) || ""), t) || O(E((r == null ? void 0 : r.slug) || ""), t);
|
|
13
13
|
})
|
|
14
14
|
), Ge = (e, n) => {
|
|
15
15
|
const r = /* @__PURE__ */ new Set(), t = ce(e, "id");
|
|
@@ -26,14 +26,14 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
26
26
|
children: t.children ? V(t.children, n, r) : []
|
|
27
27
|
};
|
|
28
28
|
const l = t.children && t.children.some(
|
|
29
|
-
(o) =>
|
|
29
|
+
(o) => O(E(o.name || ""), E(n)) || O(E(o.slug || ""), E(n))
|
|
30
30
|
);
|
|
31
31
|
return {
|
|
32
32
|
...t,
|
|
33
33
|
shouldExpandOnSearch: l,
|
|
34
34
|
children: t.children ? V(t.children, n, r) : []
|
|
35
35
|
};
|
|
36
|
-
}),
|
|
36
|
+
}), De = (e) => {
|
|
37
37
|
if (!e || !e.length) return [];
|
|
38
38
|
const n = {};
|
|
39
39
|
e.forEach((t) => {
|
|
@@ -48,16 +48,16 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
48
48
|
).map((r) => ({
|
|
49
49
|
...r,
|
|
50
50
|
children: r.children ? ue(r.children) : []
|
|
51
|
-
})),
|
|
51
|
+
})), Oe = (e, n, r, t) => {
|
|
52
52
|
if (!e || !e.length) return [];
|
|
53
53
|
let l = e;
|
|
54
|
-
if (r !== "all" && (l = ie(
|
|
54
|
+
if (r !== "all" && (l = ie(z(e, { pageType: r }))), v(n))
|
|
55
55
|
l = le(l, n);
|
|
56
56
|
else {
|
|
57
57
|
const d = le(l, n), i = Ge(e, d);
|
|
58
58
|
l = Ae([...d, ...i], "id");
|
|
59
59
|
}
|
|
60
|
-
const o = ue(
|
|
60
|
+
const o = ue(De(l)), b = V(o, n, t), f = z(b, (d) => t(d.pageType)).sort((d, i) => (d.name || "").localeCompare(i.name || "")), x = z(b, (d) => !t(d.pageType));
|
|
61
61
|
let m = [];
|
|
62
62
|
if (r === "all") {
|
|
63
63
|
const d = ce(x, "pageType");
|
|
@@ -85,7 +85,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
85
85
|
disabled: !((t = e == null ? void 0 : e.children) != null && t.length),
|
|
86
86
|
className: `flex h-[calc(100%-2px)] w-5 items-center justify-center rounded text-gray-400 transition-colors hover:bg-gray-200 hover:px-1 hover:text-gray-500 ${(l = e == null ? void 0 : e.children) != null && l.length ? "hover:text-blue-400" : "opacity-0"}`,
|
|
87
87
|
children: /* @__PURE__ */ s(
|
|
88
|
-
|
|
88
|
+
Fe,
|
|
89
89
|
{
|
|
90
90
|
size: 12,
|
|
91
91
|
className: `stroke-[4] transition-transform duration-200 ${n ? "rotate-90" : ""}`
|
|
@@ -108,12 +108,12 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
108
108
|
selectedLanguage: o,
|
|
109
109
|
showUntranslatedPages: b
|
|
110
110
|
}) => {
|
|
111
|
-
const [f] = pe(), x = oe(), m = r === e.id, d = !!e.isTemplate, i = Q(() =>
|
|
111
|
+
const [f] = pe(), x = oe(), m = r === e.id, d = !!e.isTemplate, i = Q(() => j(n, { key: e.pageType }), [n, e.pageType]), P = f == null ? void 0 : f[e.id], { data: S } = be(P), y = S ? S == null ? void 0 : S.name : null;
|
|
112
112
|
let u = H(l, e == null ? void 0 : e.id);
|
|
113
113
|
u = H(u, "lang") === o ? u : null;
|
|
114
114
|
const A = o === x || !!u, L = (u == null ? void 0 : u.name) || (e == null ? void 0 : e.name) || "No name";
|
|
115
115
|
let g = (u == null ? void 0 : u.slug) || (e == null ? void 0 : e.slug) || "";
|
|
116
|
-
const
|
|
116
|
+
const F = g + (e != null && e.dynamic ? `/${i == null ? void 0 : i.dynamicSlug}` : "") + (e != null && e.dynamicSlugCustom ? `${e.dynamicSlugCustom}` : "");
|
|
117
117
|
if (g.startsWith("/") && !b) {
|
|
118
118
|
const c = g.split("/").pop();
|
|
119
119
|
g = g.endsWith(c) && e.dynamic ? "" : `/${c}`;
|
|
@@ -133,7 +133,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
133
133
|
!e.isPartialGroup && /* @__PURE__ */ s(_e, { isOnline: u ? u.online : e.online }),
|
|
134
134
|
/* @__PURE__ */ s(We, { page: e, pageType: i }),
|
|
135
135
|
/* @__PURE__ */ s(_, { content: L, side: "top", showTooltip: L.length > 35, children: /* @__PURE__ */ s("span", { className: "max-w-[40%] truncate font-medium text-black", children: L }) }),
|
|
136
|
-
(g || e.dynamic) && /* @__PURE__ */ s(_, { content:
|
|
136
|
+
(g || e.dynamic) && /* @__PURE__ */ s(_, { content: F, side: "top", showTooltip: !0, children: /* @__PURE__ */ p("span", { className: "max-w-[40%] truncate font-mono text-xs text-muted-foreground", children: [
|
|
137
137
|
g,
|
|
138
138
|
e.dynamic && (i == null ? void 0 : i.dynamicSlug) && /* @__PURE__ */ p("span", { className: "text-xs text-gray-500", children: [
|
|
139
139
|
"/",
|
|
@@ -155,17 +155,17 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
155
155
|
setUnmarkAsTemplate: (c) => t("unmarkAsTemplate", c),
|
|
156
156
|
children: /* @__PURE__ */ s("div", { className: "m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white", children: /* @__PURE__ */ s($e, { className: "h-4 w-4", onClick: (c) => c.stopPropagation() }) })
|
|
157
157
|
}
|
|
158
|
-
) }) : y ? /* @__PURE__ */ s("span", { className: "duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500", children: /* @__PURE__ */ s(
|
|
158
|
+
) }) : y ? /* @__PURE__ */ s("span", { className: "duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500", children: /* @__PURE__ */ s(Me, { className: "h-3.5 w-3.5 fill-red-200 text-red-500" }) }) : null
|
|
159
159
|
]
|
|
160
160
|
}
|
|
161
161
|
),
|
|
162
|
-
/* @__PURE__ */ s(
|
|
163
|
-
/* @__PURE__ */ s(
|
|
162
|
+
/* @__PURE__ */ s(D, { children: y && /* @__PURE__ */ p("button", { className: "absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100", children: [
|
|
163
|
+
/* @__PURE__ */ s(je, { size: 12, className: "stroke-[3]" }),
|
|
164
164
|
" ",
|
|
165
165
|
/* @__PURE__ */ s("span", { className: "font-medium", children: y }),
|
|
166
166
|
" is editing this page"
|
|
167
167
|
] }) }),
|
|
168
|
-
/* @__PURE__ */ s(
|
|
168
|
+
/* @__PURE__ */ s(D, { children: !A && !e.isPartialGroup && !y && /* @__PURE__ */ p(
|
|
169
169
|
"button",
|
|
170
170
|
{
|
|
171
171
|
onClick: (c) => {
|
|
@@ -173,7 +173,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
173
173
|
},
|
|
174
174
|
className: "absolute left-1/2 top-1 flex -translate-x-1/2 items-center gap-x-1 rounded bg-blue-500 px-2 py-0.5 text-xs text-white opacity-0 duration-200 hover:bg-blue-700 group-hover:opacity-100",
|
|
175
175
|
children: [
|
|
176
|
-
/* @__PURE__ */ s(
|
|
176
|
+
/* @__PURE__ */ s(ze, { size: 12, className: "stroke-[3]" }),
|
|
177
177
|
" ",
|
|
178
178
|
/* @__PURE__ */ p("span", { className: "text-[10px]", children: [
|
|
179
179
|
"Add ",
|
|
@@ -195,7 +195,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
195
195
|
showUntranslatedPages: f
|
|
196
196
|
}) => {
|
|
197
197
|
const { expandedPages: x } = J();
|
|
198
|
-
return /* @__PURE__ */ s("div", { className: "space-y-0.5", style: { paddingLeft: `${n * 10}px` }, children: e.map((m) => /* @__PURE__ */ p(
|
|
198
|
+
return /* @__PURE__ */ s("div", { className: "space-y-0.5", style: { paddingLeft: `${n * 10}px` }, children: e.map((m) => /* @__PURE__ */ p(D, { children: [
|
|
199
199
|
/* @__PURE__ */ s(
|
|
200
200
|
qe,
|
|
201
201
|
{
|
|
@@ -222,32 +222,32 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
222
222
|
}
|
|
223
223
|
)
|
|
224
224
|
] }, m.id)) });
|
|
225
|
-
}, He = U(() => import("./page-manager-search-and-filter-
|
|
226
|
-
const { languages: n, setSelectedLang: r } = re(), { data: t } = ke(), { data: l, isFetching: o } = Ne(), [b, f] = we(), { updateForSelectedPage: x, expandPagesOnSearch: m } = J(null), d = oe(), i = b.get("page"), [P, S] = N(""), [y, u] = N(null), [A, L] = N(null), [g,
|
|
225
|
+
}, He = U(() => import("./page-manager-search-and-filter-DLrJ5bRM.js")), Qe = U(() => import("./add-new-page-C6fGkJF9.js")), Ve = U(() => import("./delete-page-hLDHKzbl.js")), Je = U(() => import("./duplicate-page-sdO4hRfo.js")), Ke = U(() => import("./mark-as-template-C3669ENB.js")), Xe = U(() => import("./unmark-as-template-D8o31xMH.js")), Ye = U(() => import("./unpublish-page-D9XisIu8.js")), ot = ({ close: e }) => {
|
|
226
|
+
const { languages: n, setSelectedLang: r } = re(), { data: t } = ke(), { data: l, isFetching: o } = Ne(), [b, f] = we(), { updateForSelectedPage: x, expandPagesOnSearch: m } = J(null), d = oe(), i = b.get("page"), [P, S] = N(""), [y, u] = N(null), [A, L] = N(null), [g, F] = N(null), [B, c] = N(null), [T, R] = N(""), [K, X] = N(null), [Y, Z] = N(null), [k, he] = N(d), [fe, xe] = N(!1), [, ee] = Ee(ve), I = fe && k !== d, { data: $, isFetching: Pe } = Se(k), te = ae(
|
|
227
227
|
(h) => {
|
|
228
228
|
var a;
|
|
229
|
-
return (a =
|
|
229
|
+
return (a = j(t, { key: h })) == null ? void 0 : a.hasSlug;
|
|
230
230
|
},
|
|
231
231
|
[t]
|
|
232
|
-
), w = Q(() => l ? I ?
|
|
233
|
-
|
|
232
|
+
), w = Q(() => l ? I ? z(l, (h) => !($ != null && $[h.id])) : Oe(l, P, T, te) : [], [l, te, P, T, $, I]);
|
|
233
|
+
M(() => {
|
|
234
234
|
r(d);
|
|
235
|
-
}, [d, r]),
|
|
235
|
+
}, [d, r]), M(() => {
|
|
236
236
|
if (!v(T)) return;
|
|
237
237
|
const h = sessionStorage.getItem("pageTypeFilter") || "all";
|
|
238
|
-
!v(t) && h && (
|
|
239
|
-
}, [t, T]),
|
|
240
|
-
if (i && !o && !
|
|
241
|
-
const a =
|
|
238
|
+
!v(t) && h && (j(t, { key: h }) ? R(h) : R("all"));
|
|
239
|
+
}, [t, T]), M(() => {
|
|
240
|
+
if (i && !o && !j(l, { id: i })) {
|
|
241
|
+
const a = j(l, { slug: "/" });
|
|
242
242
|
if (a) {
|
|
243
243
|
const G = new URLSearchParams({ page: a.id });
|
|
244
244
|
q(G, f);
|
|
245
245
|
} else
|
|
246
246
|
q(new URLSearchParams({}), f, !0);
|
|
247
247
|
}
|
|
248
|
-
}, [l, i, o, f]),
|
|
248
|
+
}, [l, i, o, f]), M(() => {
|
|
249
249
|
i && !o && !v(w) && x(w, i);
|
|
250
|
-
}, [i, o, w, x]),
|
|
250
|
+
}, [i, o, w, x]), M(() => {
|
|
251
251
|
!v(P) && !v(w) && m(w);
|
|
252
252
|
}, [P, w, m]);
|
|
253
253
|
const { setSelectedLang: W } = re(), se = ae(
|
|
@@ -277,7 +277,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
277
277
|
u(a);
|
|
278
278
|
break;
|
|
279
279
|
case "unpublish":
|
|
280
|
-
|
|
280
|
+
F(a);
|
|
281
281
|
break;
|
|
282
282
|
case "markAsTemplate":
|
|
283
283
|
c(a);
|
|
@@ -297,7 +297,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
297
297
|
break;
|
|
298
298
|
}
|
|
299
299
|
};
|
|
300
|
-
return /* @__PURE__ */ p(
|
|
300
|
+
return /* @__PURE__ */ p(D, { children: [
|
|
301
301
|
/* @__PURE__ */ p("div", { className: "flex h-full flex-col justify-between", children: [
|
|
302
302
|
/* @__PURE__ */ s(C, { children: /* @__PURE__ */ s(
|
|
303
303
|
He,
|
|
@@ -343,7 +343,7 @@ const le = (e, n) => !e || !Array.isArray(e) ? [] : v(n) ? e : ie(
|
|
|
343
343
|
}
|
|
344
344
|
) }),
|
|
345
345
|
y && /* @__PURE__ */ s(C, { children: /* @__PURE__ */ s(Ve, { page: y, onClose: () => u(null) }) }),
|
|
346
|
-
g && /* @__PURE__ */ s(C, { children: /* @__PURE__ */ s(Ye, { page: g, onClose: () =>
|
|
346
|
+
g && /* @__PURE__ */ s(C, { children: /* @__PURE__ */ s(Ye, { page: g, onClose: () => F(null) }) }),
|
|
347
347
|
B && /* @__PURE__ */ s(C, { children: /* @__PURE__ */ s(Ke, { page: B, onClose: () => c(null) }) }),
|
|
348
348
|
Y && /* @__PURE__ */ s(C, { children: /* @__PURE__ */ s(Xe, { page: Y, onClose: () => Z(null) }) }),
|
|
349
349
|
K && /* @__PURE__ */ s(C, { children: /* @__PURE__ */ s(Je, { page: K, onClose: () => X(null), closePanel: e }) })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("./index-MlpQJHWW.cjs"),B=require("./use-page-expand-manager-2KjeYfVS.cjs"),n=require("lodash-es"),Q=require("@chaibuilder/sdk"),se=require("jotai"),v=require("lucide-react"),l=require("react"),V=(e,r)=>!e||!Array.isArray(e)?[]:n.isEmpty(r)?e:n.compact(n.filter(e,a=>{const t=n.toLower(r);return n.includes(n.toLower((a==null?void 0:a.name)||""),t)||n.includes(n.toLower((a==null?void 0:a.slug)||""),t)})),te=(e,r)=>{const a=new Set,t=n.keyBy(e,"id");return r.forEach(o=>{let c=o;for(;c.parent&&t[c.parent];)a.add(c.parent),c=t[c.parent]}),Array.from(a).map(o=>t[o])},$=(e,r,a)=>n.isEmpty(r)?e:e.map(t=>{if(!a(t.pageType))return{...t,shouldExpandOnSearch:!0,children:t.children?$(t.children,r,a):[]};const o=t.children&&t.children.some(c=>n.includes(n.toLower(c.name||""),n.toLower(r))||n.includes(n.toLower(c.slug||""),n.toLower(r)));return{...t,shouldExpandOnSearch:o,children:t.children?$(t.children,r,a):[]}}),ne=e=>{if(!e||!e.length)return[];const r={};e.forEach(t=>{r[t.id]={...t,children:[]}});const a=[];return Object.values(r).forEach(t=>{t.parent&&r[t.parent]?r[t.parent].children.push(t):a.push(t)}),a},J=e=>!e||!e.length?[]:[...e].sort((a,t)=>(a.name||"").localeCompare(t.name||"")).map(a=>({...a,children:a.children?J(a.children):[]})),re=(e,r,a,t)=>{if(!e||!e.length)return[];let o=e;if(a!=="all"&&(o=n.compact(n.filter(e,{pageType:a}))),n.isEmpty(r))o=V(o,r);else{const m=V(o,r),d=te(e,m);o=n.uniqBy([...m,...d],"id")}const c=J(ne(o)),b=$(c,r,t),y=n.filter(b,m=>t(m.pageType)).sort((m,d)=>(m.name||"").localeCompare(d.name||"")),p=n.filter(b,m=>!t(m.pageType));let f=[];if(a==="all"){const m=n.keyBy(p,"pageType");f=Object.values(n.mapValues(m,(d,j)=>({...d,id:j,name:n.startCase(j),isPartialGroup:!0,children:b.filter(N=>N.pageType===j)})))}else f=p.sort((m,d)=>(m.name||"").localeCompare(d.name||""));return[...y,...f]},ae=({page:e})=>{var t,o;const{isExpanded:r,toggleExpanded:a}=B.usePageExpandManager(e==null?void 0:e.id);return s.jsx("button",{onClick:c=>{c.stopPropagation(),a()},disabled:!((t=e==null?void 0:e.children)!=null&&t.length),className:`flex h-[calc(100%-2px)] w-5 items-center justify-center rounded text-gray-400 transition-colors hover:bg-gray-200 hover:px-1 hover:text-gray-500 ${(o=e==null?void 0:e.children)!=null&&o.length?"hover:text-blue-400":"opacity-0"}`,children:s.jsx(v.ChevronRight,{size:12,className:`stroke-[4] transition-transform duration-200 ${r?"rotate-90":""}`})})},le=({page:e,pageType:r})=>s.jsx("div",{className:"flex h-full items-center justify-center gap-x-1",children:e.dynamic?s.jsx(v.StarsIcon,{size:12,className:"text-yellow-400"}):r!=null&&r.icon?s.jsx("div",{className:"flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",dangerouslySetInnerHTML:{__html:r.icon}}):r!=null&&r.hasSlug?s.jsx(v.File,{size:12,className:"stroke-[1] text-slate-500"}):s.jsx(v.Globe,{size:12,className:"stroke-[1] text-slate-500"})}),ie=({isOnline:e})=>s.jsx("div",{className:`h-2 w-2 rounded-full ${e?"bg-green-300":"bg-gray-300"}`}),oe=({page:e,pageTypes:r,currentPage:a,onClickAction:t,languagePages:o,selectedLanguage:c,showUntranslatedPages:b})=>{const[y]=x.usePageUserMapping(),p=x.useFallbackLang(),f=a===e.id,m=!!e.isTemplate,d=l.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]),j=y==null?void 0:y[e.id],{data:N}=x.useChaiUserInfo(j),g=N?N==null?void 0:N.name:null;let h=n.get(o,e==null?void 0:e.id);h=n.get(h,"lang")===c?h:null;const E=c===p||!!h,L=(h==null?void 0:h.name)||(e==null?void 0:e.name)||"No name";let S=(h==null?void 0:h.slug)||(e==null?void 0:e.slug)||"";const C=S+(e!=null&&e.dynamic?`/${d==null?void 0:d.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(S.startsWith("/")&&!b){const u=S.split("/").pop();S=S.endsWith(u)&&e.dynamic?"":`/${u}`}const q=l.useMemo(()=>{const u="flex h-7 min-w-0 flex-1 cursor-pointer select-none items-center gap-x-1.5 rounded px-px text-xs duration-300 border-[1px]",T=`${f?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${u} ${T} ${g?"opacity-60":""}`:`${u} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,f,g]);return s.jsxs("div",{className:"group relative",children:[s.jsxs("div",{onClick:()=>!e.isPartialGroup&&E&&t("select",e==null?void 0:e.id),className:q,children:[s.jsx(ae,{page:e}),!e.isPartialGroup&&s.jsx(ie,{isOnline:h?h.online:e.online}),s.jsx(le,{page:e,pageType:d}),s.jsx(x.Tooltip,{content:L,side:"top",showTooltip:L.length>35,children:s.jsx("span",{className:"max-w-[40%] truncate font-medium text-black",children:L})}),(S||e.dynamic)&&s.jsx(x.Tooltip,{content:C,side:"top",showTooltip:!0,children:s.jsxs("span",{className:"max-w-[40%] truncate font-mono text-xs text-muted-foreground",children:[S,e.dynamic&&(d==null?void 0:d.dynamicSlug)&&s.jsxs("span",{className:"text-xs text-gray-500",children:["/",d==null?void 0:d.dynamicSlug,e.dynamicSlugCustom]})]})}),m&&s.jsx(x.Tooltip,{content:"Template",side:"top",children:s.jsx("span",{className:"text-blue-500",children:s.jsx(v.NotepadText,{size:16})})}),!e.isPartialGroup&&E&&!g?s.jsx("div",{className:"duration absolute right-0.5 top-[3px]",children:s.jsx(x.PageActionsDropdown,{isLanguagePage:!!h,page:h||e,setDuplicatePage:u=>t("duplicate",u),setAddEditPage:u=>t("edit",h||u),setUnpublishPage:u=>t("unpublish",u),setDeletePage:u=>t("delete",h||u),setMarkAsTemplate:u=>t("markAsTemplate",u),setUnmarkAsTemplate:u=>t("unmarkAsTemplate",u),children:s.jsx("div",{className:"m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white",children:s.jsx(v.MoreHorizontal,{className:"h-4 w-4",onClick:u=>u.stopPropagation()})})})}):g?s.jsx("span",{className:"duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500",children:s.jsx(v.Lock,{className:"h-3.5 w-3.5 fill-red-200 text-red-500"})}):null]}),s.jsx(s.Fragment,{children:g&&s.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[s.jsx(v.Edit,{size:12,className:"stroke-[3]"})," ",s.jsx("span",{className:"font-medium",children:g})," is editing this page"]})}),s.jsx(s.Fragment,{children:!E&&!e.isPartialGroup&&!g&&s.jsxs("button",{onClick:u=>{u.stopPropagation(),t("addLanguagePage",{language:c,page:e})},className:"absolute left-1/2 top-1 flex -translate-x-1/2 items-center gap-x-1 rounded bg-blue-500 px-2 py-0.5 text-xs text-white opacity-0 duration-200 hover:bg-blue-700 group-hover:opacity-100",children:[s.jsx(v.Plus,{size:12,className:"stroke-[3]"})," ",s.jsxs("span",{className:"text-[10px]",children:["Add ",n.get(x.LANGUAGES,c)," Page"]})]})})]})},K=({pages:e,tier:r,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y})=>{const{expandedPages:p}=B.usePageExpandManager();return s.jsx("div",{className:"space-y-0.5",style:{paddingLeft:`${r*10}px`},children:e.map(f=>s.jsxs(s.Fragment,{children:[s.jsx(oe,{page:f,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y}),f.children&&f.children.length>0&&(p==null?void 0:p.includes(f.id))&&s.jsx(K,{pages:f.children,tier:r+1,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y})]},f.id))})},ce=l.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-CWMXLTqE.cjs"))),de=l.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-CQRr6Z8g.cjs"))),ue=l.lazy(()=>Promise.resolve().then(()=>require("./delete-page-z88W-Ikh.cjs"))),me=l.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-Welcro7Y.cjs"))),he=l.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-DBPJ1gIK.cjs"))),xe=l.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-ChmjL4-w.cjs"))),fe=l.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-BxN0deJK.cjs"))),Pe=({close:e})=>{const{languages:r,setSelectedLang:a}=Q.useLanguages(),{data:t}=x.usePageTypes(),{data:o,isFetching:c}=x.useWebsitePages(),[b,y]=x.useSearchParams(),{updateForSelectedPage:p,expandPagesOnSearch:f}=B.usePageExpandManager(null),m=x.useFallbackLang(),d=b.get("page"),[j,N]=l.useState(""),[g,h]=l.useState(null),[E,L]=l.useState(null),[S,C]=l.useState(null),[q,u]=l.useState(null),[T,F]=l.useState(""),[I,G]=l.useState(null),[O,R]=l.useState(null),[k,X]=l.useState(m),[Y,Z]=l.useState(!1),[,D]=se.useAtom(x.addNewLangAtom),M=Y&&k!==m,{data:A,isFetching:ee}=x.useWebsiteLanguagePages(k),W=l.useCallback(P=>{var i;return(i=n.find(t,{key:P}))==null?void 0:i.hasSlug},[t]),w=l.useMemo(()=>o?M?n.filter(o,P=>!(A!=null&&A[P.id])):re(o,j,T,W):[],[o,W,j,T,A,M]);l.useEffect(()=>{a(m)},[m,a]),l.useEffect(()=>{if(!n.isEmpty(T))return;const P=sessionStorage.getItem("pageTypeFilter")||"all";!n.isEmpty(t)&&P&&(n.find(t,{key:P})?F(P):F("all"))},[t,T]),l.useEffect(()=>{if(d&&!c&&!n.find(o,{id:d})){const i=n.find(o,{slug:"/"});if(i){const z=new URLSearchParams({page:i.id});x.navigateToPage(z,y)}else x.navigateToPage(new URLSearchParams({}),y,!0)}},[o,d,c,y]),l.useEffect(()=>{d&&!c&&!n.isEmpty(w)&&p(w,d)},[d,c,w,p]),l.useEffect(()=>{!n.isEmpty(j)&&!n.isEmpty(w)&&f(w)},[j,w,f]);const{setSelectedLang:U}=Q.useLanguages(),_=l.useCallback(P=>{const i=new URLSearchParams({page:P});k!==m?(i.set("lang",k),U(k)):U(""),x.navigateToPage(i,y),e()},[e,y,U,k,m]),H=(P,i)=>{var z;if(i)switch(P){case"add":L(i);break;case"select":_(i);break;case"edit":k!==m?D({edit:!0,id:i==null?void 0:i.id,primaryPage:i==null?void 0:i.primaryPage}):L(i);break;case"delete":h(i);break;case"unpublish":C(i);break;case"markAsTemplate":u(i);break;case"unmarkAsTemplate":R(i);break;case"duplicate":G(i);break;case"addLanguagePage":D({edit:!1,primaryPage:((z=i==null?void 0:i.page)==null?void 0:z.id)||"",preselectedLang:(i==null?void 0:i.language)||k});break}};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex h-full flex-col justify-between",children:[s.jsx(l.Suspense,{children:s.jsx(ce,{pages:w,search:j,setSearch:N,languages:[m,...r],selectedLanguage:k,setSelectedLanguage:X,selectedPageType:T,setSelectedPageType:F,onAddPage:P=>H("add",P),showUntranslatedPages:M,setShowUntranslatedPages:Z})}),s.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-6 pt-2",children:c||ee?s.jsx("div",{className:"space-y-2",children:n.map([...Array(15).keys()],P=>s.jsx("div",{className:"h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200"},P))}):n.isEmpty(w)?s.jsxs("div",{className:"flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500",children:[s.jsx(v.File,{className:"h-6 w-6 stroke-[1]"}),"Empty List!",s.jsx("span",{className:"font-light",children:"Add new page to start"})]}):s.jsx(K,{tier:0,pages:w,pageTypes:t,currentPage:d||"",onClickAction:H,languagePages:A,selectedLanguage:k,showUntranslatedPages:M})})]}),E&&s.jsx(l.Suspense,{children:s.jsx(de,{closePanel:e,editPage:_,addEditPage:E,setAddEditPage:L})}),g&&s.jsx(l.Suspense,{children:s.jsx(ue,{page:g,onClose:()=>h(null)})}),S&&s.jsx(l.Suspense,{children:s.jsx(fe,{page:S,onClose:()=>C(null)})}),q&&s.jsx(l.Suspense,{children:s.jsx(he,{page:q,onClose:()=>u(null)})}),O&&s.jsx(l.Suspense,{children:s.jsx(xe,{page:O,onClose:()=>R(null)})}),I&&s.jsx(l.Suspense,{children:s.jsx(me,{page:I,onClose:()=>G(null),closePanel:e})})]})};exports.default=Pe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("./index-vjYir4bk.cjs"),B=require("./use-page-expand-manager-2KjeYfVS.cjs"),n=require("lodash-es"),Q=require("@chaibuilder/sdk"),se=require("jotai"),v=require("lucide-react"),l=require("react"),V=(e,r)=>!e||!Array.isArray(e)?[]:n.isEmpty(r)?e:n.compact(n.filter(e,a=>{const t=n.toLower(r);return n.includes(n.toLower((a==null?void 0:a.name)||""),t)||n.includes(n.toLower((a==null?void 0:a.slug)||""),t)})),te=(e,r)=>{const a=new Set,t=n.keyBy(e,"id");return r.forEach(o=>{let c=o;for(;c.parent&&t[c.parent];)a.add(c.parent),c=t[c.parent]}),Array.from(a).map(o=>t[o])},$=(e,r,a)=>n.isEmpty(r)?e:e.map(t=>{if(!a(t.pageType))return{...t,shouldExpandOnSearch:!0,children:t.children?$(t.children,r,a):[]};const o=t.children&&t.children.some(c=>n.includes(n.toLower(c.name||""),n.toLower(r))||n.includes(n.toLower(c.slug||""),n.toLower(r)));return{...t,shouldExpandOnSearch:o,children:t.children?$(t.children,r,a):[]}}),ne=e=>{if(!e||!e.length)return[];const r={};e.forEach(t=>{r[t.id]={...t,children:[]}});const a=[];return Object.values(r).forEach(t=>{t.parent&&r[t.parent]?r[t.parent].children.push(t):a.push(t)}),a},J=e=>!e||!e.length?[]:[...e].sort((a,t)=>(a.name||"").localeCompare(t.name||"")).map(a=>({...a,children:a.children?J(a.children):[]})),re=(e,r,a,t)=>{if(!e||!e.length)return[];let o=e;if(a!=="all"&&(o=n.compact(n.filter(e,{pageType:a}))),n.isEmpty(r))o=V(o,r);else{const m=V(o,r),d=te(e,m);o=n.uniqBy([...m,...d],"id")}const c=J(ne(o)),b=$(c,r,t),y=n.filter(b,m=>t(m.pageType)).sort((m,d)=>(m.name||"").localeCompare(d.name||"")),p=n.filter(b,m=>!t(m.pageType));let f=[];if(a==="all"){const m=n.keyBy(p,"pageType");f=Object.values(n.mapValues(m,(d,j)=>({...d,id:j,name:n.startCase(j),isPartialGroup:!0,children:b.filter(N=>N.pageType===j)})))}else f=p.sort((m,d)=>(m.name||"").localeCompare(d.name||""));return[...y,...f]},ae=({page:e})=>{var t,o;const{isExpanded:r,toggleExpanded:a}=B.usePageExpandManager(e==null?void 0:e.id);return s.jsx("button",{onClick:c=>{c.stopPropagation(),a()},disabled:!((t=e==null?void 0:e.children)!=null&&t.length),className:`flex h-[calc(100%-2px)] w-5 items-center justify-center rounded text-gray-400 transition-colors hover:bg-gray-200 hover:px-1 hover:text-gray-500 ${(o=e==null?void 0:e.children)!=null&&o.length?"hover:text-blue-400":"opacity-0"}`,children:s.jsx(v.ChevronRight,{size:12,className:`stroke-[4] transition-transform duration-200 ${r?"rotate-90":""}`})})},le=({page:e,pageType:r})=>s.jsx("div",{className:"flex h-full items-center justify-center gap-x-1",children:e.dynamic?s.jsx(v.StarsIcon,{size:12,className:"text-yellow-400"}):r!=null&&r.icon?s.jsx("div",{className:"flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",dangerouslySetInnerHTML:{__html:r.icon}}):r!=null&&r.hasSlug?s.jsx(v.File,{size:12,className:"stroke-[1] text-slate-500"}):s.jsx(v.Globe,{size:12,className:"stroke-[1] text-slate-500"})}),ie=({isOnline:e})=>s.jsx("div",{className:`h-2 w-2 rounded-full ${e?"bg-green-300":"bg-gray-300"}`}),oe=({page:e,pageTypes:r,currentPage:a,onClickAction:t,languagePages:o,selectedLanguage:c,showUntranslatedPages:b})=>{const[y]=x.usePageUserMapping(),p=x.useFallbackLang(),f=a===e.id,m=!!e.isTemplate,d=l.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]),j=y==null?void 0:y[e.id],{data:N}=x.useChaiUserInfo(j),g=N?N==null?void 0:N.name:null;let h=n.get(o,e==null?void 0:e.id);h=n.get(h,"lang")===c?h:null;const E=c===p||!!h,L=(h==null?void 0:h.name)||(e==null?void 0:e.name)||"No name";let S=(h==null?void 0:h.slug)||(e==null?void 0:e.slug)||"";const C=S+(e!=null&&e.dynamic?`/${d==null?void 0:d.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(S.startsWith("/")&&!b){const u=S.split("/").pop();S=S.endsWith(u)&&e.dynamic?"":`/${u}`}const q=l.useMemo(()=>{const u="flex h-7 min-w-0 flex-1 cursor-pointer select-none items-center gap-x-1.5 rounded px-px text-xs duration-300 border-[1px]",T=`${f?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${u} ${T} ${g?"opacity-60":""}`:`${u} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,f,g]);return s.jsxs("div",{className:"group relative",children:[s.jsxs("div",{onClick:()=>!e.isPartialGroup&&E&&t("select",e==null?void 0:e.id),className:q,children:[s.jsx(ae,{page:e}),!e.isPartialGroup&&s.jsx(ie,{isOnline:h?h.online:e.online}),s.jsx(le,{page:e,pageType:d}),s.jsx(x.Tooltip,{content:L,side:"top",showTooltip:L.length>35,children:s.jsx("span",{className:"max-w-[40%] truncate font-medium text-black",children:L})}),(S||e.dynamic)&&s.jsx(x.Tooltip,{content:C,side:"top",showTooltip:!0,children:s.jsxs("span",{className:"max-w-[40%] truncate font-mono text-xs text-muted-foreground",children:[S,e.dynamic&&(d==null?void 0:d.dynamicSlug)&&s.jsxs("span",{className:"text-xs text-gray-500",children:["/",d==null?void 0:d.dynamicSlug,e.dynamicSlugCustom]})]})}),m&&s.jsx(x.Tooltip,{content:"Template",side:"top",children:s.jsx("span",{className:"text-blue-500",children:s.jsx(v.NotepadText,{size:16})})}),!e.isPartialGroup&&E&&!g?s.jsx("div",{className:"duration absolute right-0.5 top-[3px]",children:s.jsx(x.PageActionsDropdown,{isLanguagePage:!!h,page:h||e,setDuplicatePage:u=>t("duplicate",u),setAddEditPage:u=>t("edit",h||u),setUnpublishPage:u=>t("unpublish",u),setDeletePage:u=>t("delete",h||u),setMarkAsTemplate:u=>t("markAsTemplate",u),setUnmarkAsTemplate:u=>t("unmarkAsTemplate",u),children:s.jsx("div",{className:"m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white",children:s.jsx(v.MoreHorizontal,{className:"h-4 w-4",onClick:u=>u.stopPropagation()})})})}):g?s.jsx("span",{className:"duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500",children:s.jsx(v.Lock,{className:"h-3.5 w-3.5 fill-red-200 text-red-500"})}):null]}),s.jsx(s.Fragment,{children:g&&s.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[s.jsx(v.Edit,{size:12,className:"stroke-[3]"})," ",s.jsx("span",{className:"font-medium",children:g})," is editing this page"]})}),s.jsx(s.Fragment,{children:!E&&!e.isPartialGroup&&!g&&s.jsxs("button",{onClick:u=>{u.stopPropagation(),t("addLanguagePage",{language:c,page:e})},className:"absolute left-1/2 top-1 flex -translate-x-1/2 items-center gap-x-1 rounded bg-blue-500 px-2 py-0.5 text-xs text-white opacity-0 duration-200 hover:bg-blue-700 group-hover:opacity-100",children:[s.jsx(v.Plus,{size:12,className:"stroke-[3]"})," ",s.jsxs("span",{className:"text-[10px]",children:["Add ",n.get(x.LANGUAGES,c)," Page"]})]})})]})},K=({pages:e,tier:r,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y})=>{const{expandedPages:p}=B.usePageExpandManager();return s.jsx("div",{className:"space-y-0.5",style:{paddingLeft:`${r*10}px`},children:e.map(f=>s.jsxs(s.Fragment,{children:[s.jsx(oe,{page:f,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y}),f.children&&f.children.length>0&&(p==null?void 0:p.includes(f.id))&&s.jsx(K,{pages:f.children,tier:r+1,pageTypes:a,currentPage:t,onClickAction:o,languagePages:c,selectedLanguage:b,showUntranslatedPages:y})]},f.id))})},ce=l.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-CibEmd6Z.cjs"))),de=l.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-DnVeU4g6.cjs"))),ue=l.lazy(()=>Promise.resolve().then(()=>require("./delete-page-DZi2DCAb.cjs"))),me=l.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-CTH0REkv.cjs"))),he=l.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-BNbkAkrD.cjs"))),xe=l.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-D_Td5Aeb.cjs"))),fe=l.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-Bca-dVic.cjs"))),Pe=({close:e})=>{const{languages:r,setSelectedLang:a}=Q.useLanguages(),{data:t}=x.usePageTypes(),{data:o,isFetching:c}=x.useWebsitePages(),[b,y]=x.useSearchParams(),{updateForSelectedPage:p,expandPagesOnSearch:f}=B.usePageExpandManager(null),m=x.useFallbackLang(),d=b.get("page"),[j,N]=l.useState(""),[g,h]=l.useState(null),[E,L]=l.useState(null),[S,C]=l.useState(null),[q,u]=l.useState(null),[T,F]=l.useState(""),[I,G]=l.useState(null),[O,R]=l.useState(null),[k,X]=l.useState(m),[Y,Z]=l.useState(!1),[,D]=se.useAtom(x.addNewLangAtom),M=Y&&k!==m,{data:A,isFetching:ee}=x.useWebsiteLanguagePages(k),W=l.useCallback(P=>{var i;return(i=n.find(t,{key:P}))==null?void 0:i.hasSlug},[t]),w=l.useMemo(()=>o?M?n.filter(o,P=>!(A!=null&&A[P.id])):re(o,j,T,W):[],[o,W,j,T,A,M]);l.useEffect(()=>{a(m)},[m,a]),l.useEffect(()=>{if(!n.isEmpty(T))return;const P=sessionStorage.getItem("pageTypeFilter")||"all";!n.isEmpty(t)&&P&&(n.find(t,{key:P})?F(P):F("all"))},[t,T]),l.useEffect(()=>{if(d&&!c&&!n.find(o,{id:d})){const i=n.find(o,{slug:"/"});if(i){const z=new URLSearchParams({page:i.id});x.navigateToPage(z,y)}else x.navigateToPage(new URLSearchParams({}),y,!0)}},[o,d,c,y]),l.useEffect(()=>{d&&!c&&!n.isEmpty(w)&&p(w,d)},[d,c,w,p]),l.useEffect(()=>{!n.isEmpty(j)&&!n.isEmpty(w)&&f(w)},[j,w,f]);const{setSelectedLang:U}=Q.useLanguages(),_=l.useCallback(P=>{const i=new URLSearchParams({page:P});k!==m?(i.set("lang",k),U(k)):U(""),x.navigateToPage(i,y),e()},[e,y,U,k,m]),H=(P,i)=>{var z;if(i)switch(P){case"add":L(i);break;case"select":_(i);break;case"edit":k!==m?D({edit:!0,id:i==null?void 0:i.id,primaryPage:i==null?void 0:i.primaryPage}):L(i);break;case"delete":h(i);break;case"unpublish":C(i);break;case"markAsTemplate":u(i);break;case"unmarkAsTemplate":R(i);break;case"duplicate":G(i);break;case"addLanguagePage":D({edit:!1,primaryPage:((z=i==null?void 0:i.page)==null?void 0:z.id)||"",preselectedLang:(i==null?void 0:i.language)||k});break}};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex h-full flex-col justify-between",children:[s.jsx(l.Suspense,{children:s.jsx(ce,{pages:w,search:j,setSearch:N,languages:[m,...r],selectedLanguage:k,setSelectedLanguage:X,selectedPageType:T,setSelectedPageType:F,onAddPage:P=>H("add",P),showUntranslatedPages:M,setShowUntranslatedPages:Z})}),s.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-6 pt-2",children:c||ee?s.jsx("div",{className:"space-y-2",children:n.map([...Array(15).keys()],P=>s.jsx("div",{className:"h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200"},P))}):n.isEmpty(w)?s.jsxs("div",{className:"flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500",children:[s.jsx(v.File,{className:"h-6 w-6 stroke-[1]"}),"Empty List!",s.jsx("span",{className:"font-light",children:"Add new page to start"})]}):s.jsx(K,{tier:0,pages:w,pageTypes:t,currentPage:d||"",onClickAction:H,languagePages:A,selectedLanguage:k,showUntranslatedPages:M})})]}),E&&s.jsx(l.Suspense,{children:s.jsx(de,{closePanel:e,editPage:_,addEditPage:E,setAddEditPage:L})}),g&&s.jsx(l.Suspense,{children:s.jsx(ue,{page:g,onClose:()=>h(null)})}),S&&s.jsx(l.Suspense,{children:s.jsx(fe,{page:S,onClose:()=>C(null)})}),q&&s.jsx(l.Suspense,{children:s.jsx(he,{page:q,onClose:()=>u(null)})}),O&&s.jsx(l.Suspense,{children:s.jsx(xe,{page:O,onClose:()=>R(null)})}),I&&s.jsx(l.Suspense,{children:s.jsx(me,{page:I,onClose:()=>G(null),closePanel:e})})]})};exports.default=Pe;
|