@chaibuilder/pages 0.1.0-beta.26 → 0.1.0-beta.27

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/index.cjs CHANGED
@@ -27,4 +27,4 @@ Check the top-level render call using <`+d+">.")}return l}}function ze(t,l){{if(
27
27
  <%s {...props} />
28
28
  React keys must be passed directly to JSX without using spread:
29
29
  let props = %s;
30
- <%s key={someKey} {...props} />`,Ne,K,Dt,K),We[K+Ne]=!0}}return t===n?Nt(F):St(F),F}}function kt(t,l,d){return Qe(t,l,d,!0)}function Et(t,l,d){return Qe(t,l,d,!1)}var Tt=Et,Pt=kt;ee.Fragment=n,ee.jsx=Tt,ee.jsxs=Pt}()),ee}process.env.NODE_ENV==="production"?ke.exports=_t():ke.exports=Ft();var e=ke.exports;const Ze=(a,s)=>{const n=A.useQueryClient().getQueryData(["builder_props"]);return c.get(n,a,s)},I=()=>Ze("apiUrl","/chai/api"),Ee=()=>{const a=A.useQueryClient(),{data:s}=A.useQuery({queryKey:["ai-context"],initialData:"",queryFn:()=>""});return{setAiContext:w.useCallback(n=>{a.setQueryData(["ai-context"],n)},[]),aiContext:s}},Rt=()=>{const a=I(),{aiContext:s}=Ee();return w.useCallback(async(o,n,i,h)=>{const f=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ASK_AI",data:{type:o,prompt:n,blocks:i,aiContext:s,lang:h}})})).json();return console.log("data",f),f.error?{error:new Error(f.error)}:f},[a,s])},Lt=()=>{const a=I(),{toast:s}=r.useToast();return{getUILibraryBlock:async(h,u)=>{const y=(await(await fetch(h.url+(u.path?"/blocks/"+u.path:"/"+u.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return J.getBlocksFromHTML(`${y}`)},getUILibraryBlocks:async h=>{try{return(await(await fetch(h.url+"/blocks.json")).json()).map(g=>({...g,preview:h.url.replace("chaiblocks","")+g.preview}))}catch(u){return console.error(u),[]}},onSave:async({page:h,blocks:u})=>{try{return(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:h,blocks:u}})})).ok?(s({title:"Success",description:"Page saved successfully",variant:"default"}),!0):new Error("Failed to save blocks")}catch(f){return f}}}};function ae(){const[a,s]=w.useState(new URLSearchParams(window.location.search));return w.useEffect(()=>{const o=()=>{s(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}},[]),[a,s]}const Te=()=>{const a=I();return A.useQuery({queryKey:["project-pages"],staleTime:1e3*60*5,queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_PAGES"})})).json()})},fe=()=>{const[a]=ae(),s=a.get("page"),{data:o,isFetching:n}=Te();return{data:w.useMemo(()=>c.find(o,{id:s})||{},[o,s]),isFetching:n}},It=()=>A.useQuery({queryKey:["uiLibraries"],initialData:[],queryFn:async()=>[{uuid:"meraki-ui",name:"Meraki UI",url:"https://chai-ui-blocks.vercel.app"},{uuid:"chaiblocks",name:"UI Blocks",url:"https://chaibuilder.com/chaiblocks"}]}),Bt=()=>{const[a]=ae(),s=a.get("page"),o=I(),{setAiContext:n}=Ee();return A.useQuery({queryKey:["page",s],initialData:[],queryFn:async()=>{const u=(await(await fetch(`${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:s,draft:!0}})})).json()).blocks??[],f=c.find(u,{_type:"@chai/ai-context"});return n(c.get(f,"_value","")||""),u},enabled:!!s})},Gt=a=>w.useMemo(()=>{if(!a||c.isEmpty(a))return{blocks:[],theme:{}};const s=c.find(a,{_type:"@chai/theme"}),o=c.get(s,"_value",{})||{},n=c.filter(a,i=>!c.includes(i==null?void 0:i._type,"@chai/"));return{theme:o,blocks:n}},[a]),et=()=>{const a=I();return A.useQuery({queryKey:["project-config"],initialData:{theme:{},fallbackLang:"",languages:[]},queryFn:async()=>{try{const o=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_WEBSITE_SETTINGS",draft:!0})})).json();if(o!=null&&o.error)throw"";return o}catch(s){return console.error(s),null}}})},Ut=()=>{const{data:a}=Te(),s=I();return{getGlobalBlocks:async()=>{const o={};for(const n of a??[])c.isEmpty(n==null?void 0:n.slug)&&(o[n.id]={name:c.startCase(n.name??n.slug),description:""});return o},getGlobalBlockBlocks:async o=>o?(await(await fetch(`${s}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:o,draft:!0}})})).json()).blocks:[]}},Mt=()=>({uploadFile:async s=>(console.log("uploadFile",s),{})}),Pe=()=>{const a=I(),[s]=ae(),o=s.get("page");return A.useQuery({queryKey:["language-pages",o],initialData:[],queryFn:async()=>{if(!o)return null;const i=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_LANGUAGE_PAGES",data:{id:o}})})).json();return c.reverse(c.sortBy(i,"primaryPage"))}})},te={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},tt=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>{var u;const h=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"CREATE_PAGE",data:n})})).json();if(h!=null&&h.error)throw new Error(((u=h==null?void 0:h.error)==null?void 0:u.message)||"Something went wrong.");return h},onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),o({title:`New ${i.global?"global block":"page"} added successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to add new ${i.global?"global block":"page"}.`,description:n.message})}})},De=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:n})})).json(),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),i!=null&&i.seo?o({title:"SEO Settings updated successfully."}):o({title:`${i.global?"Global block":"Page"} updated successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to update ${i.global?"global block":"page"}.`,description:n.message})}})},at=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"DELETE_PAGE",data:{id:n==null?void 0:n.id}})})).json(),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),o({title:`${i.global?"Global block":"Page"} deleted successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to delete ${i.global?"global block":"page"}.`,description:n.message})}})},qt=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>{const h=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"TAKE_OFFLINE",data:{id:n==null?void 0:n.id}})})).json();if(h!=null&&h.error)throw h==null?void 0:h.error;return h},onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),o({title:`${i.global?"Global block":"Page"} taken offline successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to take offline ${i.global?"global block":"page"}.`,description:n.message})}})},$t=()=>{const a=I(),{toast:s}=r.useToast(),o=A.useQueryClient();return A.useMutation({mutationFn:async({ids:n,theme:i})=>{const u=await(await fetch(`${a}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"PUBLISH_CHANGES",data:{ids:n,theme:i}})})).json();if(u!=null&&u.error)throw u==null?void 0:u.error;return u},onSuccess:()=>{s({title:"Pages published"}),o.invalidateQueries({queryKey:["get-page-changes"]}),o.invalidateQueries({queryKey:["project-pages"]})},onError:()=>{s({title:"Failed to publish pages.",variant:"destructive"})}})},Kt=()=>{const{selectedLang:a}=J.useLanguages(),{data:s,isFetching:o}=Pe();return{data:w.useMemo(()=>c.find(s,{lang:a||""})||{},[s,a]),isFetching:o}},nt=()=>{const{data:a,isFetching:s}=Kt(),o=a==null?void 0:a.seo,[n,i]=w.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o}),h=w.useRef({initial:n,updated:n}),{selectedLang:u,fallbackLang:f,languages:g}=J.useLanguages(),y=u.length?u:f,{mutate:j,isPending:P}=De(),v=P;w.useEffect(()=>{!s&&o&&i({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o})},[s,o]);const D=async()=>{j({id:a==null?void 0:a.id,seo:n}),h.current.initial=n,h.current.updated=n},k=()=>{i({...n,ogTitle:n.title,ogDescription:n.description})},p=()=>{i({...n,searchTitle:n.ogTitle,searchDescription:n.ogDescription})},b=m=>{const C={...n,[m.target.name]:m.target.name==="noIndex"||m.target.name==="noFollow"?m.target.checked:m.target.value};i(C),h.current.updated=C};return e.jsxs("div",{className:"relative pb-40",children:[e.jsxs("div",{className:"text-xs bg-gray-100 p-2 rounded-md text-left",children:["Slug: ",a==null?void 0:a.slug,"  ",g.length>0&&e.jsxs("span",{className:"text-blue-500 font-semibold",children:["(",c.get(te,y,y),")"]})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(r.Accordion,{type:"multiple",defaultValue:["page"],children:[e.jsxs(r.AccordionItem,{value:"page",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Seo Page"}),e.jsx(r.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"title",children:"SEO Title"}),e.jsx(r.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:b,disabled:v,placeholder:"Enter SEO title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The title should be between 10 and 60 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"description",children:"SEO Description"}),e.jsx(r.Textarea,{id:"description",name:"description",value:n.description,onChange:b,disabled:v,placeholder:"Enter SEO description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The description should be between 50 and 160 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"title",children:"Canonical URL"}),e.jsx(r.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:b,disabled:v,placeholder:"Enter Canonical URL"})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(r.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:b,disabled:v,className:"h-4 w-4"}),e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"noIndex",children:"No Index"})]}),e.jsx("p",{className:"mt-2 text-[10px] font-light text-gray-400",children:"Check this if you don't want search engines to index this page."})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(r.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:b,disabled:v,className:"h-4 w-4"}),e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"noIndex",children:"No Follow"})]}),e.jsx("p",{className:"mt-2 text-[10px] font-light text-gray-400",children:"Check this if you don't want search engines to follow links on this page."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"og",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"OG"}),e.jsx(r.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:k,children:"Copy from SEO Settings"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogTitle",children:"OG Title"}),e.jsx(r.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:b,disabled:v,placeholder:"Enter OG title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG title should be between 10 and 60 characters."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogDescription",children:"OG Description"}),e.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",value:n.ogDescription,onChange:b,disabled:v,placeholder:"Enter OG description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG description should be between 50 and 160 characters."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogImage",children:"OG Image URL"}),e.jsx(r.Input,{type:"text",id:"ogImage",name:"ogImage",value:n.ogImage,onChange:b,disabled:v,placeholder:"Enter OG image URL"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"Enter a valid URL for the OG image."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"search",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Search"}),e.jsx(r.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:p,children:"Copy from OG Settings"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchTitle",children:"Search Title"}),e.jsx(r.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:n.searchTitle,onChange:b,disabled:v,placeholder:"Enter search title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search title should be between 10 and 60 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchDescription",children:"Search Description"}),e.jsx(r.Textarea,{id:"searchDescription",name:"searchDescription",value:n.searchDescription,onChange:b,placeholder:"Enter search description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search description should be between 50 and 160 characters."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"jsonLD",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"JSON-LD"}),e.jsx(r.AccordionContent,{children:e.jsx("div",{className:"space-y-4",children:e.jsx("div",{children:e.jsx(r.Textarea,{id:"jsonLD",name:"jsonLD",rows:3,value:n.jsonLD,onChange:b,placeholder:"Enter JSON-LD"})})})})]})]})}),e.jsx("div",{className:"w-full flex items-center justify-end mt-4",children:e.jsx(r.Button,{size:"lg",variant:"default",onClick:D,disabled:c.isEqual(h.current.initial,n)||v,children:P?"Saving...":"Save"})})]})};nt.displayName="SeoPanel";const zt=({langProps:a,onClose:s,languages:o})=>{const{data:n}=fe(),[i,h]=w.useState(a.name||""),[u,f]=w.useState(a.edit?a.lang:""),[g,y]=w.useState(a.edit?a.slug:""),{mutate:j,isPending:P}=tt(),{mutate:v,isPending:D}=De(),k=!!(a!=null&&a.global),p=P||D,b=()=>{const m={name:i,lang:u,primaryPage:n==null?void 0:n.id,slug:g};m.global=k,a.edit&&(m.id=a==null?void 0:a.id),a.edit?v(m,{onSuccess:s}):j(m,{onSuccess:s})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:s,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:a.edit?"Edit language":"Add New language"}),e.jsx(r.DialogDescription,{children:"Enter the details for the language"})]}),e.jsxs("form",{children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"lang",className:"text-right",children:"Language"}),e.jsxs("select",{value:u,disabled:a.edit||c.isEmpty(o),onChange:m=>{const C=m.target.value;f(C),!k&&y(`/${C}`)},className:"flex h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 col-span-3",children:[e.jsx("option",{value:"",disabled:!0,selected:!0,children:a.edit?c.get(te,a.lang,a.lang):c.isEmpty(o)?"All available language page is created.":"Choose language"}),c.map(o,m=>e.jsx("option",{value:m,children:c.get(te,m,m)},m))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:"Page Name"}),e.jsx(r.Input,{id:"name",value:i,onChange:m=>h(m.target.value),className:"col-span-3",required:!0,placeholder:"Enter page name"})]}),!k&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(r.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",e.jsxs("small",{className:"font-light",children:["(Slug should start with /",u,")"]})]}),e.jsx(r.Input,{id:"slug",value:g,onChange:m=>{const C=m.target.value;c.startsWith(C,`/${u}`)&&y(c.toLower(c.trim(C)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:c.isEmpty(u),title:"Slug must start with /",placeholder:c.isEmpty(u)?"Choose language to add slug":"Enter page slug"})]})]}),e.jsx(r.DialogFooter,{children:e.jsx(r.Button,{onClick:b,type:"button",disabled:p||!u||!k&&!c.startsWith(g,`/${u}`),children:p?a.edit?"Updating...":"Adding...":a.edit?"Update":"Add new language"})})]})]})})},Vt=()=>{const[a,s]=w.useState(null),{selectedLang:o,fallbackLang:n,setSelectedLang:i}=J.useLanguages(),{data:h,isFetching:u}=Pe(),{mutate:f,isPending:g}=at(),{data:y}=fe(),{data:j}=et(),P=c.filter(c.get(j,"languages")||["en"],v=>!c.find(h,{lang:v})&&v!==c.get(j,"fallbackLang"));return e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsx("ul",{className:"space-y-2 mt-4",children:u?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):c.map(h,v=>{const D=v.lang,k=v.slug,p=!v.primaryPage,b=D===o;return p?null:e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`w-full p-2 rounded cursor-pointer flex items-center justify-between ${b?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>i(D),children:[e.jsxs("div",{className:" flex-1 gap-x-3",children:[e.jsx("div",{className:"text-[13px]",children:c.get(te,p?n:D,D)}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Slug:",e.jsxs("b",{children:[" ",k]})]}),e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Name:",e.jsxs("b",{children:[" ",v.name," "]})]})]})]}),p?e.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[e.jsx(R.StarIcon,{fill:"orange",className:"w-3 h-3"}),e.jsx("b",{children:" Default"})]}):e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx(R.PencilIcon,{onClick:m=>{m.stopPropagation(),s({...v,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),e.jsxs(r.Popover,{children:[e.jsx(r.PopoverTrigger,{children:e.jsx(R.TrashIcon,{className:"w-3 h-3 hover:text-red-500"})}),e.jsx(r.PopoverContent,{children:e.jsxs("div",{children:[e.jsxs("p",{className:"pb-2 text-sm",children:["Are you sure you want to remove"," ",e.jsx("b",{children:c.get(te,D,D)})," language?"]}),e.jsx("div",{className:"flex items-center justify-end w-full",children:e.jsx(r.Button,{size:"sm",variant:"destructive",disabled:g,onClick:()=>f(v),children:g?"Deleting...":"Delete"})})]})})]})]})]},v.id),e.jsx("div",{className:"h-1 w-full border-b"})]})})}),e.jsx("div",{className:"flex justify-center w-full",children:e.jsx(r.Button,{variant:"default",size:"sm",disabled:c.isEmpty(P),onClick:()=>{s({name:y==null?void 0:y.name,global:y==null?void 0:y.global,lang:"",slug:"",edit:!1})},children:"+ Add new language"})}),a&&e.jsx(zt,{languages:P,langProps:a,onClose:()=>s(null)})]})};function Wt({page:a,onClose:s,onDelete:o}){const{mutate:n,isPending:i}=at(),h=()=>{n(a,{onSuccess:()=>{o()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:s,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm Deletion"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to remove ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)})," ",a!=null&&a.global?"global block?":"page? This will also delete all associated language pages."]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:i,onClick:h,children:i?"Deleting...":"Delete"})]})]})})}const Qt=({page:a,onClose:s,onUnpublish:o})=>{const{mutate:n,isPending:i}=qt(),h=async()=>{n(a,{onSuccess:()=>{o()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:s,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm action"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to take offline"," ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)}),"?"]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:i,onClick:h,children:i?"Updating...":"Take offline"})]})]})})},Jt=({activePage:a,editPage:s,onShowUpsertPage:o})=>{const[n,i]=w.useState("pages"),{data:h,isFetching:u}=Te(),[f,g]=w.useState(null),[y,j]=w.useState(null),P=D=>{var b;if(n==="globalBlocks")return v(D.filter(m=>!m.slug));const k=c.groupBy(D.filter(m=>m.slug),"collection"),p=Object.entries(k).sort(([m],[C])=>m?!C||m.toLowerCase()==="page"?-1:C.toLowerCase()==="page"?1:m.localeCompare(C):1);return e.jsx(r.Accordion,{type:"single",collapsible:!0,className:"w-full",defaultValue:((b=p[0])==null?void 0:b[0])||"uncategorized",children:p.map(([m,C])=>e.jsxs(r.AccordionItem,{value:m||"uncategorized",children:[e.jsx(r.AccordionTrigger,{className:"px-2",children:c.startCase(m)||"Uncategorized"}),e.jsx(r.AccordionContent,{className:"bg-white",children:e.jsx("div",{className:"space-y-2",children:v(C)})})]},m))})},v=D=>c.orderBy(D,"online","desc").map(p=>e.jsxs(r.Button,{onClick:()=>s(p.id),variant:p.id===a?"default":"ghost",className:"flex justify-between items-center h-auto w-full space-x-2 py-1",children:[e.jsxs("div",{className:"flex items-start space-x-2 relative",children:[e.jsx("div",{className:"mt-1",children:p.global?e.jsx(R.GlobeIcon,{className:"h-4 w-4"}):e.jsx(R.File,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex flex-col items-start",children:[e.jsxs("span",{className:"flex items-center space-x-1",children:[p.name??p.slug,"  ",(p==null?void 0:p.online)&&e.jsx("div",{style:{backgroundColor:"lightgreen"},className:"rounded-full w-2 h-2 mr-2"})]}),(p==null?void 0:p.slug)&&e.jsx("span",{className:"text-xs font-light",children:p.slug})]})]}),e.jsx("div",{className:"flex items-center space-x-4",children:e.jsxs(r.DropdownMenu,{children:[e.jsx(r.DropdownMenuTrigger,{asChild:!0,onClick:b=>b.stopPropagation(),children:e.jsx(r.Button,{variant:"ghost",size:"sm",className:`h-8 w-8 p-0 hover:bg-transparent ${p.id===a?" hover:text-gray-200":"bg-transparent "}`,children:e.jsx(R.MoreVertical,{className:"h-4 w-4"})})}),e.jsxs(r.DropdownMenuContent,{align:"end",className:"text-sm",children:[e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),o({...p,global:n==="globalBlocks"})},children:[e.jsx(R.PencilIcon,{className:"size-3"}),"Edit"]}),e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),g(p)},children:[e.jsx(R.TrashIcon,{className:"size-3"}),"Delete"]}),(p==null?void 0:p.online)&&e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),j(p)},children:[e.jsx(R.Power,{className:"size-3"}),"Take offline"]})]})]})})]},p.id));return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs(r.Tabs,{value:n,className:"w-full",onValueChange:i,children:[e.jsxs(r.TabsList,{className:"w-full",children:[e.jsx(r.TabsTrigger,{value:"pages",className:"w-full",children:e.jsx("div",{className:"px-4",children:"Pages"})}),e.jsx(r.TabsTrigger,{value:"globalBlocks",className:"w-full",children:e.jsx("div",{className:"px-4",children:"Global Blocks"})})]}),u?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):e.jsxs("div",{className:"py-4 space-y-3",children:[e.jsx("div",{className:"w-full flex justify-start",children:e.jsxs(r.Button,{variant:"default",size:"sm",disabled:u,onClick:()=>o({slug:"",name:"",global:n==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[e.jsx(R.Plus,{className:"h-4 w-4 mr-2"}),u?"Loading...":`Add ${n==="pages"?"page":"Global Block"}`]})}),e.jsx("div",{className:"pt-0",children:e.jsx("div",{className:"space-y-2",children:u?e.jsx(Yt,{}):P(h)})})]})]}),e.jsx(Wt,{page:f,onClose:()=>g(null),onDelete:()=>{g(null)}}),e.jsx(Qt,{page:y,onClose:()=>j(null),onUnpublish:()=>{j(null)}})]})};function Yt(){return e.jsx("div",{className:"h-32 w-full flex justify-center items-center text-sm animate-pulse",children:"Loading..."})}const st=()=>{const a=I();return A.useQuery({queryKey:["project-collections"],initialData:[],queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_COLLECTIONS"})})).json()})},Ht=()=>{const a=I();return A.useMutation({mutationFn:async({collection:s,query:o})=>{try{return await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"SEARCH_PAGES",data:{collection:s,query:Array.isArray(o)&&o.length>0?o[0]:o}})})).json()||[]}catch{return[]}}})},Xt=({editPage:a,showUpsertPage:s,setShowUpsertPage:o})=>{const n=s.id,[i,h]=w.useState(n&&s.name||""),[u,f]=w.useState(n&&s.slug||""),[g,y]=w.useState(n?s.pageType||"":"page"),{data:j=[]}=st(),{mutate:P,isPending:v}=tt(),{mutate:D,isPending:k}=De(),p=v||k,b=()=>{n?D({name:i,slug:u,id:s.id,collection:s.global?"global":g},{onSuccess:()=>{o(void 0)}}):P({name:i,slug:u,collection:s.global?"global":g},{onSuccess:m=>{a(m.page.id)}})};return e.jsx(r.Dialog,{open:!!s,onOpenChange:()=>o(void 0),children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsxs(r.DialogTitle,{children:[n?"Edit":"Add New"," ",s.global?"Global Block":c.startCase(g)]}),e.jsxs(r.DialogDescription,{children:["Enter the details for the new"," ",s.global?"Global Block":`${c.startCase(g)}. Slug must start with /`]})]}),e.jsxs("form",{children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[!s.global&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"pageType",children:"Type"}),e.jsx("select",{value:g,onChange:m=>y(m.target.value),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:j.map(m=>e.jsx("option",{value:m.key,children:m.name},m.key))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"name",className:"text-right",children:"Name"}),e.jsx(r.Input,{id:"name",value:i,placeholder:`Enter ${s.global?"global block":"page"} name`,onChange:m=>h(m.target.value),className:"col-span-3",required:!0})]}),!s.global&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:s.global?"Identifier":"Slug"}),e.jsx(r.Input,{id:"slug",value:u,onChange:m=>{var C;return f((C=m.target.value)==null?void 0:C.trim().toLowerCase())},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})})]}),e.jsx(r.DialogFooter,{children:e.jsx(r.Button,{onClick:b,type:"button",disabled:p||!i||!s.global&&!u.startsWith("/")||c.isEqual(s.name,i)&&c.isEqual(s.slug,u)&&c.isEqual(s.pageType,g),children:p?n?"Updating...":"Adding...":s.global?`${n?"Update":"Add"} global block`:`${n?"Update":"Add"} Page`})})]})]})})};function Zt(a){const{activePage:s,canClose:o,open:n,close:i}=a,[,h]=ae(),[u,f]=w.useState(),g=y=>{window.history.pushState({},"",`?page=${y}`),h(new URLSearchParams({page:y})),window.dispatchEvent(new PopStateEvent("popstate")),f(void 0),i()};return e.jsx(r.Sheet,{open:n,onOpenChange:y=>{!y&&o&&i()},children:e.jsxs(r.SheetContent,{side:"left",className:`border-border w-full ${o?"":"sheet-hide-close-btn"}`,children:[e.jsx("div",{children:e.jsx(Jt,{onShowUpsertPage:y=>f(y),activePage:s,editPage:g})}),u&&e.jsx(Xt,{editPage:g,showUpsertPage:u,setShowUpsertPage:f})]})})}const ea=()=>{const{t:a}=J.useTranslation(),{data:s,isFetching:o}=fe(),n=Ze("getPreviewUrl",async u=>u),[i,h]=w.useState("");return w.useEffect(()=>{(async()=>{if(!n||!(s!=null&&s.slug)){h("");return}const u=await n((s==null?void 0:s.slug)||"");h(u)})()},[n,s==null?void 0:s.slug]),!i||s!=null&&s.global||o?null:e.jsxs(r.Button,{variant:"outline",size:"sm",className:"ml-2",children:[e.jsx(R.EyeIcon,{className:"h-4 w-4 mr-2"}),e.jsx("a",{href:i,target:"_blank",children:a("Preview")})]})},ta=()=>{const a=I();return A.useQuery({queryKey:["get-page-changes"],queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_CHANGES"})})).json()})},He=({pages:a,selectedPages:s,handleCheckboxChange:o,loading:n,type:i})=>{if(n)return e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"bg-gray-200 h-6 w-full rounded animate-pulse mt-2"}),e.jsx("div",{className:"bg-gray-200 h-6 w-full rounded animate-pulse"})]});if(c.isEmpty(a))return e.jsx("div",{className:"p-4 text-center text-gray-400 font-medium",children:"No changes available to publish"});const h=c.filter(a,{online:!0}),u=c.filter(a,{online:!1});return e.jsxs("div",{className:"space-y-2 px-1",children:[c.map(h,(f,g)=>e.jsxs("div",{className:`pt-2 flex justify-between ${g>0?"border-t":""}`,children:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx("input",{checked:c.includes(s,f.id),onChange:()=>o(f.id),type:"checkbox",className:"rounded focus:outline-none focus:ring-0 cursor-pointer"}),e.jsx("div",{className:"text-xs",children:e.jsxs("div",{className:"flex items-center gap-x-2 text-gray-400",children:[f.global?e.jsx(R.GlobeIcon,{className:"h-4 w-4"}):e.jsx(R.File,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-gray-800",children:f.name})," ",e.jsx("span",{children:f.slug&&!f.global&&e.jsx("span",{children:f.slug})})]})})]}),e.jsx("div",{className:" text-gray-500 text-xs font-medium",children:c.first(f==null?void 0:f.changes)})]},f.id)),!c.isEmpty(u)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative py-0 -ml-2 !mt-3",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-gray-200"})}),e.jsx("div",{className:"relative flex justify-left",children:e.jsxs("span",{className:"bg-white px-2 text-xs text-gray-500",children:["Offline ",i]})})]}),c.map(u,(f,g)=>e.jsxs("div",{className:`pt-2 flex justify-between ${g>0?"border-t":""}`,children:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx("input",{checked:c.includes(s,f.id),onChange:()=>o(f.id),type:"checkbox",className:"rounded focus:outline-none focus:ring-0 cursor-pointer"}),e.jsx("div",{className:"text-xs",children:e.jsxs("div",{className:"flex items-center gap-x-2 text-gray-400",children:[f.global?e.jsx(R.GlobeIcon,{className:"h-4 w-4"}):e.jsx(R.File,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-medium text-gray-800",children:[f.name," ",f.lang&&`(${f.lang})`]})," ",e.jsx("span",{children:f.slug&&!f.global&&e.jsx("span",{children:f.slug})})]})})]}),e.jsx("div",{className:" text-gray-500 text-xs font-medium",children:c.first(f==null?void 0:f.changes)})]},f.id))]})]})};function aa({onClose:a=()=>console.log("Cancelled")}){const[s,o]=w.useState([]),{data:n,isFetching:i}=ta(),h=w.useMemo(()=>[...c.filter(n,{global:!1,online:!0}),...c.filter(n,{global:!1,online:!1})],[n]),u=w.useMemo(()=>[...c.filter(n,{global:!0,online:!0}),...c.filter(n,{global:!0,online:!1})],[n]),{mutate:f,isPending:g}=$t();w.useEffect(()=>{o(c.map(c.filter(n,{online:!0}),"id"))},[n]);const{isAllPagesSelected:y,isAllGlobalBlocksSelected:j}=w.useMemo(()=>{const k=h.length>0&&h.every(b=>s.includes(b.id)),p=u.length>0&&u.every(b=>s.includes(b.id));return{isAllPagesSelected:k,isAllGlobalBlocksSelected:p}},[h,u,s]),P=k=>{o(p=>c.includes(p,k)?c.filter(p,b=>b!==k):c.concat(p,k))},v=k=>{o(k==="globalBlocks"?b=>j?c.filter(b,m=>!c.find(u,{id:m})):c.uniq(c.concat(b,c.map(u,"id"))):b=>y?c.filter(b,m=>!c.find(h,{id:m})):c.uniq(c.concat(b,c.map(h,"id"))))},D=()=>{f({ids:s,theme:!1},{onSuccess:()=>{a()}})};return e.jsx(r.Dialog,{open:!0,onOpenChange:g?()=>{}:a,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[525px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Publish changes"}),e.jsx(r.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),e.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:e.jsxs(r.Accordion,{type:"multiple",defaultValue:["pages","globalBlocks"],children:[e.jsxs(r.AccordionItem,{value:"pages",defaultChecked:!0,children:[e.jsx(r.AccordionTrigger,{className:"bg-gray-100 rounded px-4",children:e.jsxs("div",{className:"flex items-center gap-x-2 pl-2 -mx-1",children:[!c.isEmpty(h)&&e.jsx("input",{checked:y,onClick:k=>{k.stopPropagation(),v("pages")},type:"checkbox",className:"rounded focus:outline-none focus:ring-0 mt-1 cursor-pointer"}),"Pages"]})}),e.jsx(r.AccordionContent,{className:"px-4 pt-2",children:e.jsx(He,{type:"Pages",loading:i,pages:h,selectedPages:s,handleCheckboxChange:P})})]}),e.jsxs(r.AccordionItem,{value:"globalBlocks",children:[e.jsx(r.AccordionTrigger,{className:"bg-gray-100 rounded px-4",children:e.jsxs("div",{className:"flex items-center gap-x-2 pl-2 -mx-1",children:[!c.isEmpty(u)&&e.jsx("input",{checked:j,onClick:k=>{k.stopPropagation(),v("globalBlocks")},type:"checkbox",className:"rounded focus:outline-none focus:ring-0 mt-1 cursor-pointer"}),"Global Block"]})}),e.jsx(r.AccordionContent,{className:"px-4 pt-2",children:e.jsx(He,{type:"Global Blocks",loading:i,pages:u,selectedPages:s,handleCheckboxChange:P})})]})]})}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{disabled:g,variant:"outline",onClick:a,children:"Cancel"}),e.jsx(r.Button,{disabled:g||i||c.isEmpty(n),onClick:D,children:g?"Publishing...":"Publish"})]})]})})}Ot.loadWebBlocks();const na=a=>{const s=w.useRef([]),[o]=ae(),n=o.get("page"),{data:i,isFetching:h}=fe(),{data:u}=It(),{data:f,isFetching:g}=Bt(),{blocks:y}=Gt(f),{data:j}=et(),{data:P}=Pe(),{data:v}=st(),D=Rt(),{uploadFile:k}=Mt(),{getUILibraryBlock:p,getUILibraryBlocks:b,onSave:m}=Lt(),{getGlobalBlocks:C,getGlobalBlockBlocks:me}=Ut(),{aiContext:Y,setAiContext:ge}=Ee(),{mutateAsync:ne}=Ht();s.current=y;const[pe,se]=w.useState(!1),[re,ie]=w.useState(!1),[z,le]=w.useState("SAVED");w.useEffect(()=>{const O=M=>{z==="UNSAVED"&&(M.preventDefault(),M.returnValue=!1)};return z==="UNSAVED"&&window.addEventListener("beforeunload",O),()=>{window.removeEventListener("beforeunload",O)}},[z]);const G=w.useMemo(()=>{const O={};return j!=null&&j.theme&&(O.brandingOptions=j.theme),a.mediaManagerComponent&&(O.mediaManagerComponent=a.mediaManagerComponent,O.uploadMediaCallback=k),O},[j,a.mediaManagerComponent,k]),q=w.useMemo(()=>Array.isArray(a==null?void 0:a.uiLibraries)?[...u,...a==null?void 0:a.uiLibraries]:u,[u,a==null?void 0:a.uiLibraries]),$=w.useCallback(async(O,M)=>await ne({collection:O,query:M}),[ne]);return e.jsxs(e.Fragment,{children:[e.jsx(J.ChaiBuilderEditor,{loading:g,...a.fallbackLang&&{fallbackLang:a.fallbackLang||"en"},...a.languages&&{languages:c.map(P,"lang")||[]},translations:a.translations||{},locale:a.locale||"en",htmlDir:a.htmlDir||"ltr",autoSaveSupport:a.autoSaveSupport||!1,autoSaveInterval:a.autoSaveInterval||15,onError:a.onError||console.error,getGlobalBlockBlocks:me,getGlobalBlocks:C,blocks:y,getUILibraryBlock:p,getUILibraryBlocks:b,uiLibraries:q,collections:v,searchCollectionItems:$,saveAiContextCallback:async O=>{if(!n)return!0;const M=s.current,V={_type:"@chai/ai-context",_value:c.isString(O)?O:""},oe=[...M,V];return await m({page:n,blocks:oe}),ge(O),!0},onSaveStateChange:O=>le(O),aiContext:Y,askAiCallBack:D,onSave:async({blocks:O})=>{if(!n)return!0;s.current=O;const M={_type:"@chai/ai-context",_value:c.isString(Y)?Y:""},V=[...O,M];return await m({page:n,blocks:V}),s.current=O,!0},topBarComponents:{left:[()=>e.jsxs(r.Button,{variant:"default",className:"flex justify-start max-w-[250px] items-center w-full space-x-2 py-1",onClick:()=>se(!0),children:[c.includes(i.slug,"/")?e.jsx(R.File,{className:"h-4 w-4"}):e.jsx(R.GlobeIcon,{className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:(i==null?void 0:i.name)??""}),e.jsx(R.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[ea,()=>e.jsxs(r.Button,{disabled:z!=="SAVED",size:"sm",variant:"default",onClick:()=>ie(!0),children:[e.jsx(R.RocketIcon,{className:"h-4 w-4"}),"   Publish"]})]},sideBarComponents:{top:[...i!=null&&i.global?[]:[{label:"SEO Setting",component:nt,icon:e.jsx(e.Fragment,{children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 21 21",fill:"currentColor",width:"21",height:"21",children:[e.jsx("path",{d:"M9.931 6.818c-1.238 0-2.136.925-2.136 2.2 0 1.279.898 2.207 2.136 2.207.664 0 1.257-.246 1.67-.694a.15.15 0 0 0-.009-.213l-.311-.286a.15.15 0 0 0-.213.009c-.273.297-.677.46-1.137.46-.699 0-1.233-.444-1.375-1.12h3.295a.15.15 0 0 0 .151-.151v-.211c0-1.295-.852-2.2-2.072-2.2m0 .724c.697 0 1.188.422 1.315 1.113h-2.69c.142-.673.676-1.113 1.374-1.113m4.332-.724c-1.246 0-2.15.925-2.15 2.2 0 1.279.904 2.207 2.15 2.207.596 0 1.143-.223 1.538-.628s.612-.965.612-1.579c0-1.275-.904-2.2-2.15-2.2m0 3.683c-.826 0-1.426-.624-1.426-1.483 0-.855.6-1.475 1.426-1.475s1.426.621 1.426 1.476c0 .423-.144.804-.406 1.073-.258.264-.62.41-1.019.41M6.318 8.71c-.665-.206-.902-.335-.902-.645 0-.47.564-.521.806-.521.29 0 .552.07.801.215a.15.15 0 0 0 .206-.055l.212-.366a.15.15 0 0 0-.055-.206 2.27 2.27 0 0 0-1.165-.312c-.915 0-1.53.501-1.53 1.245 0 .899.816 1.152 1.411 1.336.655.203.812.307.804.53-.016.398-.567.429-.735.429-.386 0-.722-.129-.972-.374q-.043-.042-.107-.043a.15.15 0 0 0-.106.045l-.295.302a.15.15 0 0 0 .002.213c.383.374.908.58 1.478.58.859 0 1.432-.441 1.459-1.125.031-.833-.746-1.074-1.313-1.249"}),e.jsx("path",{d:"M20.396 2.049H.604A.604.604 0 0 0 0 2.653v12.7c0 .333.27.604.604.604h6.941c-.266 1.296-.881 1.966-.886 1.971a.604.604 0 0 0 .434 1.024h6.815a.604.604 0 0 0 .434-1.024c-.007-.007-.621-.675-.886-1.971h6.941c.333 0 .604-.27.604-.604V2.652a.604.604 0 0 0-.604-.604m-.604 12.701h-.985v-.17a.604.604 0 0 0-1.208 0v.17h-.63v-.17a.604.604 0 0 0-1.208 0v.17H1.207V3.256h18.585z"})]})})}],...(j==null?void 0:j.languages.length)>0?[{label:"Language Pages",component:Vt,icon:e.jsx(e.Fragment,{children:e.jsx("svg",{width:"21",height:"21",viewBox:"0 0 21 21",fill:"currentColor",children:e.jsxs("g",{fill:"none","fill-rule":"evenodd",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round",children:[e.jsx("path",{d:"M18.5 10.5v-6a2 2 0 0 0-2-2h-6a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2"}),e.jsx("path",{d:"M6.5 8.503h-2a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h.003l6-.01a2 2 0 0 0 1.997-2V14.5"}),e.jsx("path",{d:"M7.5 12.503h-3M9 14l-1 1q-.5.5-2.5 1.5"}),e.jsx("path",{d:"M5.5 12.503q.501 1.75 1.5 2.499c1 .749 1.5.999 2.5 1.498m4-12-3 6m3-6 3 6m-1-2h-4"})]})})})}]:[]]},...G}),e.jsx(Zt,{activePage:n||"",canClose:!!n&&!c.isEmpty(i),open:!n||!h&&c.isEmpty(i)||pe,close:()=>se(!1)}),re&&e.jsx(aa,{onClose:()=>ie(!1)})]})},Xe=new A.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),sa=a=>(Xe.setQueryData(["builder_props"],a),e.jsx(A.QueryClientProvider,{client:Xe,children:e.jsx(na,{...a})}));module.exports=sa;
30
+ <%s key={someKey} {...props} />`,Ne,K,Dt,K),We[K+Ne]=!0}}return t===n?Nt(F):St(F),F}}function kt(t,l,d){return Qe(t,l,d,!0)}function Et(t,l,d){return Qe(t,l,d,!1)}var Tt=Et,Pt=kt;ee.Fragment=n,ee.jsx=Tt,ee.jsxs=Pt}()),ee}process.env.NODE_ENV==="production"?ke.exports=_t():ke.exports=Ft();var e=ke.exports;const Ze=(a,s)=>{const n=A.useQueryClient().getQueryData(["builder_props"]);return c.get(n,a,s)},I=()=>Ze("apiUrl","/chai/api"),Ee=()=>{const a=A.useQueryClient(),{data:s}=A.useQuery({queryKey:["ai-context"],initialData:"",queryFn:()=>""});return{setAiContext:w.useCallback(n=>{a.setQueryData(["ai-context"],n)},[]),aiContext:s}},Rt=()=>{const a=I(),{aiContext:s}=Ee();return w.useCallback(async(o,n,i,h)=>{const f=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ASK_AI",data:{type:o,prompt:n,blocks:i,aiContext:s,lang:h}})})).json();return console.log("data",f),f.error?{error:new Error(f.error)}:f},[a,s])},Lt=()=>{const a=I(),{toast:s}=r.useToast();return{getUILibraryBlock:async(h,u)=>{const y=(await(await fetch(h.url+(u.path?"/blocks/"+u.path:"/"+u.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return J.getBlocksFromHTML(`${y}`)},getUILibraryBlocks:async h=>{try{return(await(await fetch(h.url+"/blocks.json")).json()).map(g=>({...g,preview:h.url.replace("chaiblocks","")+g.preview}))}catch(u){return console.error(u),[]}},onSave:async({page:h,blocks:u})=>{try{return(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:h,blocks:u}})})).ok?(s({title:"Success",description:"Page saved successfully",variant:"default"}),!0):new Error("Failed to save blocks")}catch(f){return f}}}};function ae(){const[a,s]=w.useState(new URLSearchParams(window.location.search));return w.useEffect(()=>{const o=()=>{s(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}},[]),[a,s]}const Te=()=>{const a=I();return A.useQuery({queryKey:["project-pages"],staleTime:1e3*60*5,queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_PAGES"})})).json()})},fe=()=>{const[a]=ae(),s=a.get("page"),{data:o,isFetching:n}=Te();return{data:w.useMemo(()=>c.find(o,{id:s})||{},[o,s]),isFetching:n}},It=()=>A.useQuery({queryKey:["uiLibraries"],initialData:[],queryFn:async()=>[{uuid:"meraki-ui",name:"Meraki UI",url:"https://chai-ui-blocks.vercel.app"},{uuid:"chaiblocks",name:"UI Blocks",url:"https://chaibuilder.com/chaiblocks"}]}),Bt=()=>{const[a]=ae(),s=a.get("page"),o=I(),{setAiContext:n}=Ee();return A.useQuery({queryKey:["page",s],initialData:[],queryFn:async()=>{const u=(await(await fetch(`${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:s,draft:!0}})})).json()).blocks??[],f=c.find(u,{_type:"@chai/ai-context"});return n(c.get(f,"_value","")||""),u},enabled:!!s})},Gt=a=>w.useMemo(()=>{if(!a||c.isEmpty(a))return{blocks:[],theme:{}};const s=c.find(a,{_type:"@chai/theme"}),o=c.get(s,"_value",{})||{},n=c.filter(a,i=>!c.includes(i==null?void 0:i._type,"@chai/"));return{theme:o,blocks:n}},[a]),et=()=>{const a=I();return A.useQuery({queryKey:["project-config"],initialData:{theme:{},fallbackLang:"",languages:[]},queryFn:async()=>{try{const o=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_WEBSITE_SETTINGS",draft:!0})})).json();if(o!=null&&o.error)throw"";return o}catch(s){return console.error(s),null}}})},Ut=()=>{const{data:a}=Te(),s=I();return{getGlobalBlocks:async()=>{const o={};for(const n of a??[])c.isEmpty(n==null?void 0:n.slug)&&(o[n.id]={name:c.startCase(n.name??n.slug),description:""});return o},getGlobalBlockBlocks:async o=>o?(await(await fetch(`${s}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:o,draft:!0}})})).json()).blocks:[]}},Mt=()=>({uploadFile:async s=>(console.log("uploadFile",s),{})}),Pe=()=>{const a=I(),[s]=ae(),o=s.get("page");return A.useQuery({queryKey:["language-pages",o],initialData:[],queryFn:async()=>{if(!o)return null;const i=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_LANGUAGE_PAGES",data:{id:o}})})).json();return c.reverse(c.sortBy(i,"primaryPage"))}})},te={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},tt=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>{var u;const h=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"CREATE_PAGE",data:n})})).json();if(h!=null&&h.error)throw new Error(((u=h==null?void 0:h.error)==null?void 0:u.message)||"Something went wrong.");return h},onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),o({title:`New ${i.global?"global block":"page"} added successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to add new ${i.global?"global block":"page"}.`,description:n.message})}})},De=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:n})})).json(),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),i!=null&&i.seo?o({title:"SEO Settings updated successfully."}):o({title:`${i.global?"Global block":"Page"} updated successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to update ${i.global?"global block":"page"}.`,description:n.message})}})},at=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"DELETE_PAGE",data:{id:n==null?void 0:n.id}})})).json(),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),o({title:`${i.global?"Global block":"Page"} deleted successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to delete ${i.global?"global block":"page"}.`,description:n.message})}})},qt=()=>{const a=I(),s=A.useQueryClient(),{toast:o}=r.useToast();return A.useMutation({mutationFn:async n=>{const h=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"TAKE_OFFLINE",data:{id:n==null?void 0:n.id}})})).json();if(h!=null&&h.error)throw h==null?void 0:h.error;return h},onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?s.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):s.invalidateQueries({queryKey:["project-pages"]}),o({title:`${i.global?"Global block":"Page"} taken offline successfully.`})},onError:(n,i)=>{o({variant:"destructive",title:`Failed to take offline ${i.global?"global block":"page"}.`,description:n.message})}})},$t=()=>{const a=I(),{toast:s}=r.useToast(),o=A.useQueryClient();return A.useMutation({mutationFn:async({ids:n,theme:i})=>{const u=await(await fetch(`${a}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"PUBLISH_CHANGES",data:{ids:n,theme:i}})})).json();if(u!=null&&u.error)throw u==null?void 0:u.error;return u},onSuccess:()=>{s({title:"Pages published"}),o.invalidateQueries({queryKey:["get-page-changes"]}),o.invalidateQueries({queryKey:["project-pages"]})},onError:()=>{s({title:"Failed to publish pages.",variant:"destructive"})}})},Kt=()=>{const{selectedLang:a}=J.useLanguages(),{data:s,isFetching:o}=Pe();return{data:w.useMemo(()=>c.find(s,{lang:a||""})||{},[s,a]),isFetching:o}},nt=()=>{const{data:a,isFetching:s}=Kt(),o=a==null?void 0:a.seo,[n,i]=w.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o}),h=w.useRef({initial:n,updated:n}),{selectedLang:u,fallbackLang:f,languages:g}=J.useLanguages(),y=u.length?u:f,{mutate:j,isPending:P}=De(),v=P;w.useEffect(()=>{!s&&o&&i({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o})},[s,o]);const D=async()=>{j({id:a==null?void 0:a.id,seo:n}),h.current.initial=n,h.current.updated=n},k=()=>{i({...n,ogTitle:n.title,ogDescription:n.description})},p=()=>{i({...n,searchTitle:n.ogTitle,searchDescription:n.ogDescription})},b=m=>{const C={...n,[m.target.name]:m.target.name==="noIndex"||m.target.name==="noFollow"?m.target.checked:m.target.value};i(C),h.current.updated=C};return e.jsxs("div",{className:"relative pb-40",children:[e.jsxs("div",{className:"text-xs bg-gray-100 p-2 rounded-md text-left",children:["Slug: ",a==null?void 0:a.slug,"  ",g.length>0&&e.jsxs("span",{className:"text-blue-500 font-semibold",children:["(",c.get(te,y,y),")"]})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(r.Accordion,{type:"multiple",defaultValue:["page"],children:[e.jsxs(r.AccordionItem,{value:"page",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Seo Page"}),e.jsx(r.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"title",children:"SEO Title"}),e.jsx(r.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:b,disabled:v,placeholder:"Enter SEO title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The title should be between 10 and 60 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"description",children:"SEO Description"}),e.jsx(r.Textarea,{id:"description",name:"description",value:n.description,onChange:b,disabled:v,placeholder:"Enter SEO description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The description should be between 50 and 160 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"title",children:"Canonical URL"}),e.jsx(r.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:b,disabled:v,placeholder:"Enter Canonical URL"})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(r.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:b,disabled:v,className:"h-4 w-4"}),e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"noIndex",children:"No Index"})]}),e.jsx("p",{className:"mt-2 text-[10px] font-light text-gray-400",children:"Check this if you don't want search engines to index this page."})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(r.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:b,disabled:v,className:"h-4 w-4"}),e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"noIndex",children:"No Follow"})]}),e.jsx("p",{className:"mt-2 text-[10px] font-light text-gray-400",children:"Check this if you don't want search engines to follow links on this page."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"og",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"OG"}),e.jsx(r.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:k,children:"Copy from SEO Settings"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogTitle",children:"OG Title"}),e.jsx(r.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:b,disabled:v,placeholder:"Enter OG title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG title should be between 10 and 60 characters."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogDescription",children:"OG Description"}),e.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",value:n.ogDescription,onChange:b,disabled:v,placeholder:"Enter OG description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG description should be between 50 and 160 characters."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogImage",children:"OG Image URL"}),e.jsx(r.Input,{type:"text",id:"ogImage",name:"ogImage",value:n.ogImage,onChange:b,disabled:v,placeholder:"Enter OG image URL"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"Enter a valid URL for the OG image."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"search",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Search"}),e.jsx(r.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:p,children:"Copy from OG Settings"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchTitle",children:"Search Title"}),e.jsx(r.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:n.searchTitle,onChange:b,disabled:v,placeholder:"Enter search title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search title should be between 10 and 60 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchDescription",children:"Search Description"}),e.jsx(r.Textarea,{id:"searchDescription",name:"searchDescription",value:n.searchDescription,onChange:b,placeholder:"Enter search description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search description should be between 50 and 160 characters."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"jsonLD",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"JSON-LD"}),e.jsx(r.AccordionContent,{children:e.jsx("div",{className:"space-y-4",children:e.jsx("div",{children:e.jsx(r.Textarea,{id:"jsonLD",name:"jsonLD",rows:3,value:n.jsonLD,onChange:b,placeholder:"Enter JSON-LD"})})})})]})]})}),e.jsx("div",{className:"w-full flex items-center justify-end mt-4",children:e.jsx(r.Button,{size:"lg",variant:"default",onClick:D,disabled:c.isEqual(h.current.initial,n)||v,children:P?"Saving...":"Save"})})]})};nt.displayName="SeoPanel";const zt=({langProps:a,onClose:s,languages:o})=>{const{data:n}=fe(),[i,h]=w.useState(a.name||""),[u,f]=w.useState(a.edit?a.lang:""),[g,y]=w.useState(a.edit?a.slug:""),{mutate:j,isPending:P}=tt(),{mutate:v,isPending:D}=De(),k=!!(a!=null&&a.global),p=P||D,b=()=>{const m={name:i,lang:u,primaryPage:n==null?void 0:n.id,slug:g};m.global=k,a.edit&&(m.id=a==null?void 0:a.id),a.edit?v(m,{onSuccess:s}):j(m,{onSuccess:s})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:s,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:a.edit?"Edit language":"Add New language"}),e.jsx(r.DialogDescription,{children:"Enter the details for the language"})]}),e.jsxs("form",{children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"lang",className:"text-right",children:"Language"}),e.jsxs("select",{value:u,disabled:a.edit||c.isEmpty(o),onChange:m=>{const C=m.target.value;f(C),!k&&y(`/${C}`)},className:"flex h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 col-span-3",children:[e.jsx("option",{value:"",disabled:!0,selected:!0,children:a.edit?c.get(te,a.lang,a.lang):c.isEmpty(o)?"All available language page is created.":"Choose language"}),c.map(o,m=>e.jsx("option",{value:m,children:c.get(te,m,m)},m))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:"Page Name"}),e.jsx(r.Input,{id:"name",value:i,onChange:m=>h(m.target.value),className:"col-span-3",required:!0,placeholder:"Enter page name"})]}),!k&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(r.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",e.jsxs("small",{className:"font-light",children:["(Slug should start with /",u,")"]})]}),e.jsx(r.Input,{id:"slug",value:g,onChange:m=>{const C=m.target.value;c.startsWith(C,`/${u}`)&&y(c.toLower(c.trim(C)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:c.isEmpty(u),title:"Slug must start with /",placeholder:c.isEmpty(u)?"Choose language to add slug":"Enter page slug"})]})]}),e.jsx(r.DialogFooter,{children:e.jsx(r.Button,{onClick:b,type:"button",disabled:p||!u||!k&&!c.startsWith(g,`/${u}`),children:p?a.edit?"Updating...":"Adding...":a.edit?"Update":"Add new language"})})]})]})})},Vt=()=>{const[a,s]=w.useState(null),{selectedLang:o,fallbackLang:n,setSelectedLang:i}=J.useLanguages(),{data:h,isFetching:u}=Pe(),{mutate:f,isPending:g}=at(),{data:y}=fe(),{data:j}=et(),P=c.filter(c.get(j,"languages")||["en"],v=>!c.find(h,{lang:v})&&v!==c.get(j,"fallbackLang"));return e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsx("ul",{className:"space-y-2 mt-4",children:u?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):c.map(h,v=>{const D=v.lang,k=v.slug,p=!v.primaryPage,b=D===o;return p?null:e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`w-full p-2 rounded cursor-pointer flex items-center justify-between ${b?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>i(D),children:[e.jsxs("div",{className:" flex-1 gap-x-3",children:[e.jsx("div",{className:"text-[13px]",children:c.get(te,p?n:D,D)}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Slug:",e.jsxs("b",{children:[" ",k]})]}),e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Name:",e.jsxs("b",{children:[" ",v.name," "]})]})]})]}),p?e.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[e.jsx(R.StarIcon,{fill:"orange",className:"w-3 h-3"}),e.jsx("b",{children:" Default"})]}):e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx(R.PencilIcon,{onClick:m=>{m.stopPropagation(),s({...v,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),e.jsxs(r.Popover,{children:[e.jsx(r.PopoverTrigger,{children:e.jsx(R.TrashIcon,{className:"w-3 h-3 hover:text-red-500"})}),e.jsx(r.PopoverContent,{children:e.jsxs("div",{children:[e.jsxs("p",{className:"pb-2 text-sm",children:["Are you sure you want to remove"," ",e.jsx("b",{children:c.get(te,D,D)})," language?"]}),e.jsx("div",{className:"flex items-center justify-end w-full",children:e.jsx(r.Button,{size:"sm",variant:"destructive",disabled:g,onClick:()=>f(v),children:g?"Deleting...":"Delete"})})]})})]})]})]},v.id),e.jsx("div",{className:"h-1 w-full border-b"})]})})}),e.jsx("div",{className:"flex justify-center w-full",children:e.jsx(r.Button,{variant:"default",size:"sm",disabled:c.isEmpty(P),onClick:()=>{s({name:y==null?void 0:y.name,global:y==null?void 0:y.global,lang:"",slug:"",edit:!1})},children:"+ Add new language"})}),a&&e.jsx(zt,{languages:P,langProps:a,onClose:()=>s(null)})]})};function Wt({page:a,onClose:s,onDelete:o}){const{mutate:n,isPending:i}=at(),h=()=>{n(a,{onSuccess:()=>{o()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:s,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm Deletion"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to remove ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)})," ",a!=null&&a.global?"global block?":"page? This will also delete all associated language pages."]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:i,onClick:h,children:i?"Deleting...":"Delete"})]})]})})}const Qt=({page:a,onClose:s,onUnpublish:o})=>{const{mutate:n,isPending:i}=qt(),h=async()=>{n(a,{onSuccess:()=>{o()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:s,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm action"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to take offline"," ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)}),"?"]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:i,onClick:h,children:i?"Updating...":"Take offline"})]})]})})},Jt=({activePage:a,editPage:s,onShowUpsertPage:o})=>{const[n,i]=w.useState("pages"),{data:h,isFetching:u}=Te(),[f,g]=w.useState(null),[y,j]=w.useState(null),P=D=>{var b;if(n==="globalBlocks")return v(D.filter(m=>!m.slug));const k=c.groupBy(D.filter(m=>m.slug),"collection"),p=Object.entries(k).sort(([m],[C])=>m?!C||m.toLowerCase()==="page"?-1:C.toLowerCase()==="page"?1:m.localeCompare(C):1);return e.jsx(r.Accordion,{type:"single",collapsible:!0,className:"w-full",defaultValue:((b=p[0])==null?void 0:b[0])||"uncategorized",children:p.map(([m,C])=>e.jsxs(r.AccordionItem,{value:m||"uncategorized",children:[e.jsx(r.AccordionTrigger,{className:"px-2",children:c.startCase(m)||"Uncategorized"}),e.jsx(r.AccordionContent,{className:"bg-white",children:e.jsx("div",{className:"space-y-2",children:v(C)})})]},m))})},v=D=>c.orderBy(D,"online","desc").map(p=>e.jsxs(r.Button,{onClick:()=>s(p.id),variant:p.id===a?"default":"ghost",className:"flex justify-between items-center h-auto w-full space-x-2 py-1",children:[e.jsxs("div",{className:"flex items-start space-x-2 relative",children:[e.jsx("div",{className:"mt-1",children:p.global?e.jsx(R.GlobeIcon,{className:"h-4 w-4"}):e.jsx(R.File,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex flex-col items-start",children:[e.jsxs("span",{className:"flex items-center space-x-1",children:[p.name??p.slug,"  ",(p==null?void 0:p.online)&&e.jsx("div",{style:{backgroundColor:"lightgreen"},className:"rounded-full w-2 h-2 mr-2"})]}),(p==null?void 0:p.slug)&&e.jsx("span",{className:"text-xs font-light",children:p.slug})]})]}),e.jsx("div",{className:"flex items-center space-x-4",children:e.jsxs(r.DropdownMenu,{children:[e.jsx(r.DropdownMenuTrigger,{asChild:!0,onClick:b=>b.stopPropagation(),children:e.jsx(r.Button,{variant:"ghost",size:"sm",className:`h-8 w-8 p-0 hover:bg-transparent ${p.id===a?" hover:text-gray-200":"bg-transparent "}`,children:e.jsx(R.MoreVertical,{className:"h-4 w-4"})})}),e.jsxs(r.DropdownMenuContent,{align:"end",className:"text-sm",children:[e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),o({...p,global:n==="globalBlocks"})},children:[e.jsx(R.PencilIcon,{className:"size-3"}),"Edit"]}),e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),g(p)},children:[e.jsx(R.TrashIcon,{className:"size-3"}),"Delete"]}),(p==null?void 0:p.online)&&e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:b=>{b.stopPropagation(),j(p)},children:[e.jsx(R.Power,{className:"size-3"}),"Take offline"]})]})]})})]},p.id));return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs(r.Tabs,{value:n,className:"w-full",onValueChange:i,children:[e.jsxs(r.TabsList,{className:"w-full",children:[e.jsx(r.TabsTrigger,{value:"pages",className:"w-full",children:e.jsx("div",{className:"px-4",children:"Pages"})}),e.jsx(r.TabsTrigger,{value:"globalBlocks",className:"w-full",children:e.jsx("div",{className:"px-4",children:"Global Blocks"})})]}),u?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),e.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):e.jsxs("div",{className:"py-4 space-y-3",children:[e.jsx("div",{className:"w-full flex justify-start",children:e.jsxs(r.Button,{variant:"default",size:"sm",disabled:u,onClick:()=>o({slug:"",name:"",global:n==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[e.jsx(R.Plus,{className:"h-4 w-4 mr-2"}),u?"Loading...":`Add ${n==="pages"?"page":"Global Block"}`]})}),e.jsx("div",{className:"pt-0",children:e.jsx("div",{className:"space-y-2",children:u?e.jsx(Yt,{}):P(h)})})]})]}),e.jsx(Wt,{page:f,onClose:()=>g(null),onDelete:()=>{g(null)}}),e.jsx(Qt,{page:y,onClose:()=>j(null),onUnpublish:()=>{j(null)}})]})};function Yt(){return e.jsx("div",{className:"h-32 w-full flex justify-center items-center text-sm animate-pulse",children:"Loading..."})}const st=()=>{const a=I();return A.useQuery({queryKey:["project-collections"],initialData:[],queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_COLLECTIONS"})})).json()})},Ht=()=>{const a=I();return A.useMutation({mutationFn:async({collection:s,query:o})=>{try{return await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"SEARCH_PAGES",data:{collection:s,query:Array.isArray(o)&&o.length>0?o[0]:o}})})).json()||[]}catch{return[]}}})},Xt=({editPage:a,showUpsertPage:s,setShowUpsertPage:o})=>{const n=s.id,[i,h]=w.useState(n&&s.name||""),[u,f]=w.useState(n&&s.slug||""),[g,y]=w.useState(n?s.pageType||"":"page"),{data:j=[]}=st(),{mutate:P,isPending:v}=tt(),{mutate:D,isPending:k}=De(),p=v||k,b=()=>{n?D({name:i,slug:u,id:s.id,collection:s.global?"global":g},{onSuccess:()=>{o(void 0)}}):P({name:i,slug:u,collection:s.global?"global":g},{onSuccess:m=>{a(m.page.id)}})};return e.jsx(r.Dialog,{open:!!s,onOpenChange:()=>o(void 0),children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsxs(r.DialogTitle,{children:[n?"Edit":"Add New"," ",s.global?"Global Block":c.startCase(g)]}),e.jsxs(r.DialogDescription,{children:["Enter the details for the new"," ",s.global?"Global Block":`${c.startCase(g)}. Slug must start with /`]})]}),e.jsxs("form",{children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[!s.global&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"pageType",children:"Type"}),e.jsx("select",{value:g,onChange:m=>y(m.target.value),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:j.map(m=>e.jsx("option",{value:m.key,children:m.name},m.key))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"name",className:"text-right",children:"Name"}),e.jsx(r.Input,{id:"name",value:i,placeholder:`Enter ${s.global?"global block":"page"} name`,onChange:m=>h(m.target.value),className:"col-span-3",required:!0})]}),!s.global&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:s.global?"Identifier":"Slug"}),e.jsx(r.Input,{id:"slug",value:u,onChange:m=>{var C;return f((C=m.target.value)==null?void 0:C.trim().toLowerCase())},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})})]}),e.jsx(r.DialogFooter,{children:e.jsx(r.Button,{onClick:b,type:"button",disabled:p||!i||!s.global&&!u.startsWith("/")||c.isEqual(s.name,i)&&c.isEqual(s.slug,u)&&c.isEqual(s.pageType,g),children:p?n?"Updating...":"Adding...":s.global?`${n?"Update":"Add"} global block`:`${n?"Update":"Add"} Page`})})]})]})})};function Zt(a){const{activePage:s,canClose:o,open:n,close:i}=a,[,h]=ae(),[u,f]=w.useState(),g=y=>{window.history.pushState({},"",`?page=${y}`),h(new URLSearchParams({page:y})),window.dispatchEvent(new PopStateEvent("popstate")),f(void 0),i()};return e.jsx(r.Sheet,{open:n,onOpenChange:y=>{!y&&o&&i()},children:e.jsxs(r.SheetContent,{side:"left",className:`border-border w-full ${o?"":"sheet-hide-close-btn"}`,children:[e.jsx("div",{children:e.jsx(Jt,{onShowUpsertPage:y=>f(y),activePage:s,editPage:g})}),u&&e.jsx(Xt,{editPage:g,showUpsertPage:u,setShowUpsertPage:f})]})})}const ea=()=>{const{t:a}=J.useTranslation(),{data:s,isFetching:o}=fe(),n=Ze("getPreviewUrl",async u=>u),[i,h]=w.useState("");return w.useEffect(()=>{(async()=>{if(!n||!(s!=null&&s.slug)){h("");return}const u=await n((s==null?void 0:s.slug)||"");h(u)})()},[n,s==null?void 0:s.slug]),!i||s!=null&&s.global||o?null:e.jsxs(r.Button,{variant:"outline",size:"sm",className:"ml-2",children:[e.jsx(R.EyeIcon,{className:"h-4 w-4 mr-2"}),e.jsx("a",{href:i,target:"_blank",children:a("Preview")})]})},ta=()=>{const a=I();return A.useQuery({queryKey:["get-page-changes"],queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_CHANGES"})})).json()})},He=({pages:a,selectedPages:s,handleCheckboxChange:o,loading:n,type:i})=>{if(n)return e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"bg-gray-200 h-6 w-full rounded animate-pulse mt-2"}),e.jsx("div",{className:"bg-gray-200 h-6 w-full rounded animate-pulse"})]});if(c.isEmpty(a))return e.jsx("div",{className:"p-4 text-center text-gray-400 font-medium",children:"No changes available to publish"});const h=c.filter(a,{online:!0}),u=c.filter(a,{online:!1});return e.jsxs("div",{className:"space-y-2 px-1",children:[c.map(h,(f,g)=>e.jsxs("div",{className:`pt-2 flex justify-between ${g>0?"border-t":""}`,children:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx("input",{checked:c.includes(s,f.id),onChange:()=>o(f.id),type:"checkbox",className:"rounded focus:outline-none focus:ring-0 cursor-pointer"}),e.jsx("div",{className:"text-xs",children:e.jsxs("div",{className:"flex items-center gap-x-2 text-gray-400",children:[f.global?e.jsx(R.GlobeIcon,{className:"h-4 w-4"}):e.jsx(R.File,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-gray-800",children:f.name})," ",e.jsx("span",{children:f.slug&&!f.global&&e.jsx("span",{children:f.slug})})]})})]}),e.jsx("div",{className:" text-gray-500 text-xs font-medium",children:c.first(f==null?void 0:f.changes)})]},f.id)),!c.isEmpty(u)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative py-0 -ml-2 !mt-3",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-gray-200"})}),e.jsx("div",{className:"relative flex justify-left",children:e.jsxs("span",{className:"bg-white px-2 text-xs text-gray-500",children:["Offline ",i]})})]}),c.map(u,(f,g)=>e.jsxs("div",{className:`pt-2 flex justify-between ${g>0?"border-t":""}`,children:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx("input",{checked:c.includes(s,f.id),onChange:()=>o(f.id),type:"checkbox",className:"rounded focus:outline-none focus:ring-0 cursor-pointer"}),e.jsx("div",{className:"text-xs",children:e.jsxs("div",{className:"flex items-center gap-x-2 text-gray-400",children:[f.global?e.jsx(R.GlobeIcon,{className:"h-4 w-4"}):e.jsx(R.File,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-medium text-gray-800",children:[f.name," ",f.lang&&`(${f.lang})`]})," ",e.jsx("span",{children:f.slug&&!f.global&&e.jsx("span",{children:f.slug})})]})})]}),e.jsx("div",{className:" text-gray-500 text-xs font-medium",children:c.first(f==null?void 0:f.changes)})]},f.id))]})]})};function aa({onClose:a=()=>console.log("Cancelled")}){const[s,o]=w.useState([]),{data:n,isFetching:i}=ta(),h=w.useMemo(()=>[...c.filter(n,{global:!1,online:!0}),...c.filter(n,{global:!1,online:!1})],[n]),u=w.useMemo(()=>[...c.filter(n,{global:!0,online:!0}),...c.filter(n,{global:!0,online:!1})],[n]),{mutate:f,isPending:g}=$t();w.useEffect(()=>{o(c.map(c.filter(n,{online:!0}),"id"))},[n]);const{isAllPagesSelected:y,isAllGlobalBlocksSelected:j}=w.useMemo(()=>{const k=h.length>0&&h.every(b=>s.includes(b.id)),p=u.length>0&&u.every(b=>s.includes(b.id));return{isAllPagesSelected:k,isAllGlobalBlocksSelected:p}},[h,u,s]),P=k=>{o(p=>c.includes(p,k)?c.filter(p,b=>b!==k):c.concat(p,k))},v=k=>{o(k==="globalBlocks"?b=>j?c.filter(b,m=>!c.find(u,{id:m})):c.uniq(c.concat(b,c.map(u,"id"))):b=>y?c.filter(b,m=>!c.find(h,{id:m})):c.uniq(c.concat(b,c.map(h,"id"))))},D=()=>{f({ids:s,theme:!1},{onSuccess:()=>{a()}})};return e.jsx(r.Dialog,{open:!0,onOpenChange:g?()=>{}:a,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[525px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Publish changes"}),e.jsx(r.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),e.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:e.jsxs(r.Accordion,{type:"multiple",defaultValue:["pages","globalBlocks"],children:[e.jsxs(r.AccordionItem,{value:"pages",defaultChecked:!0,children:[e.jsx(r.AccordionTrigger,{className:"bg-gray-100 rounded px-4",children:e.jsxs("div",{className:"flex items-center gap-x-2 pl-2 -mx-1",children:[!c.isEmpty(h)&&e.jsx("input",{checked:y,onClick:k=>{k.stopPropagation(),v("pages")},type:"checkbox",className:"rounded focus:outline-none focus:ring-0 mt-1 cursor-pointer"}),"Pages"]})}),e.jsx(r.AccordionContent,{className:"px-4 pt-2",children:e.jsx(He,{type:"Pages",loading:i,pages:h,selectedPages:s,handleCheckboxChange:P})})]}),e.jsxs(r.AccordionItem,{value:"globalBlocks",children:[e.jsx(r.AccordionTrigger,{className:"bg-gray-100 rounded px-4",children:e.jsxs("div",{className:"flex items-center gap-x-2 pl-2 -mx-1",children:[!c.isEmpty(u)&&e.jsx("input",{checked:j,onClick:k=>{k.stopPropagation(),v("globalBlocks")},type:"checkbox",className:"rounded focus:outline-none focus:ring-0 mt-1 cursor-pointer"}),"Global Block"]})}),e.jsx(r.AccordionContent,{className:"px-4 pt-2",children:e.jsx(He,{type:"Global Blocks",loading:i,pages:u,selectedPages:s,handleCheckboxChange:P})})]})]})}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{disabled:g,variant:"outline",onClick:a,children:"Cancel"}),e.jsx(r.Button,{disabled:g||i||c.isEmpty(n),onClick:D,children:g?"Publishing...":"Publish"})]})]})})}Ot.loadWebBlocks();const na=a=>{const s=w.useRef([]),[o]=ae(),n=o.get("page"),{data:i,isFetching:h}=fe(),{data:u}=It(),{data:f,isFetching:g}=Bt(),{blocks:y}=Gt(f),{data:j}=et(),{data:P}=Pe(),{data:v}=st(),D=Rt(),{uploadFile:k}=Mt(),{getUILibraryBlock:p,getUILibraryBlocks:b,onSave:m}=Lt(),{getGlobalBlocks:C,getGlobalBlockBlocks:me}=Ut(),{aiContext:Y,setAiContext:ge}=Ee(),{mutateAsync:ne}=Ht();s.current=y;const[pe,se]=w.useState(!1),[re,ie]=w.useState(!1),[z,le]=w.useState("SAVED");w.useEffect(()=>{const O=M=>{z==="UNSAVED"&&(M.preventDefault(),M.returnValue=!1)};return z==="UNSAVED"&&window.addEventListener("beforeunload",O),()=>{window.removeEventListener("beforeunload",O)}},[z]);const G=w.useMemo(()=>{const O={};return j!=null&&j.theme&&(O.brandingOptions=j.theme),a.mediaManagerComponent&&(O.mediaManagerComponent=a.mediaManagerComponent,O.uploadMediaCallback=k),O},[j,a.mediaManagerComponent,k]),q=w.useMemo(()=>Array.isArray(a==null?void 0:a.uiLibraries)?[...u,...a==null?void 0:a.uiLibraries]:u,[u,a==null?void 0:a.uiLibraries]),$=w.useCallback(async(O,M)=>await ne({collection:O,query:M}),[ne]);return e.jsxs(e.Fragment,{children:[e.jsx(J.ChaiBuilderEditor,{loading:g,...a.fallbackLang&&{fallbackLang:a.fallbackLang||"en"},...a.languages&&{languages:c.map(P,"lang")||[]},translations:a.translations||{},locale:a.locale||"en",htmlDir:a.htmlDir||"ltr",autoSaveSupport:a.autoSaveSupport||!1,autoSaveInterval:a.autoSaveInterval||15,onError:a.onError||console.error,getGlobalBlockBlocks:me,getGlobalBlocks:C,blocks:y,getUILibraryBlock:p,getUILibraryBlocks:b,uiLibraries:q,collections:v,searchCollectionItems:$,saveAiContextCallback:async O=>{if(!n)return!0;const M=s.current,V={_type:"@chai/ai-context",_value:c.isString(O)?O:""},oe=[...M,V];return await m({page:n,blocks:oe}),ge(O),!0},onSaveStateChange:O=>le(O),aiContext:Y,askAiCallBack:D,onSave:async({blocks:O})=>{if(!n)return!0;s.current=O;const M={_type:"@chai/ai-context",_value:c.isString(Y)?Y:""},V=[...O,M];return await m({page:n,blocks:V}),s.current=O,!0},topBarComponents:{left:[()=>e.jsxs(r.Button,{variant:"default",className:"flex justify-start max-w-[250px] items-center w-full space-x-2 py-1",onClick:()=>se(!0),children:[c.includes(i.slug,"/")?e.jsx(R.File,{className:"h-4 w-4"}):e.jsx(R.GlobeIcon,{className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:(i==null?void 0:i.name)??""}),e.jsx(R.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[ea,()=>e.jsxs(r.Button,{disabled:z!=="SAVED",size:"sm",variant:"default",onClick:()=>ie(!0),children:[e.jsx(R.RocketIcon,{className:"h-4 w-4"}),"   Publish"]})]},sideBarComponents:{top:[...(i==null?void 0:i.collection)!=="global"?[{label:"SEO Setting",component:nt,icon:e.jsx(e.Fragment,{children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 21 21",fill:"currentColor",width:"21",height:"21",children:[e.jsx("path",{d:"M9.931 6.818c-1.238 0-2.136.925-2.136 2.2 0 1.279.898 2.207 2.136 2.207.664 0 1.257-.246 1.67-.694a.15.15 0 0 0-.009-.213l-.311-.286a.15.15 0 0 0-.213.009c-.273.297-.677.46-1.137.46-.699 0-1.233-.444-1.375-1.12h3.295a.15.15 0 0 0 .151-.151v-.211c0-1.295-.852-2.2-2.072-2.2m0 .724c.697 0 1.188.422 1.315 1.113h-2.69c.142-.673.676-1.113 1.374-1.113m4.332-.724c-1.246 0-2.15.925-2.15 2.2 0 1.279.904 2.207 2.15 2.207.596 0 1.143-.223 1.538-.628s.612-.965.612-1.579c0-1.275-.904-2.2-2.15-2.2m0 3.683c-.826 0-1.426-.624-1.426-1.483 0-.855.6-1.475 1.426-1.475s1.426.621 1.426 1.476c0 .423-.144.804-.406 1.073-.258.264-.62.41-1.019.41M6.318 8.71c-.665-.206-.902-.335-.902-.645 0-.47.564-.521.806-.521.29 0 .552.07.801.215a.15.15 0 0 0 .206-.055l.212-.366a.15.15 0 0 0-.055-.206 2.27 2.27 0 0 0-1.165-.312c-.915 0-1.53.501-1.53 1.245 0 .899.816 1.152 1.411 1.336.655.203.812.307.804.53-.016.398-.567.429-.735.429-.386 0-.722-.129-.972-.374q-.043-.042-.107-.043a.15.15 0 0 0-.106.045l-.295.302a.15.15 0 0 0 .002.213c.383.374.908.58 1.478.58.859 0 1.432-.441 1.459-1.125.031-.833-.746-1.074-1.313-1.249"}),e.jsx("path",{d:"M20.396 2.049H.604A.604.604 0 0 0 0 2.653v12.7c0 .333.27.604.604.604h6.941c-.266 1.296-.881 1.966-.886 1.971a.604.604 0 0 0 .434 1.024h6.815a.604.604 0 0 0 .434-1.024c-.007-.007-.621-.675-.886-1.971h6.941c.333 0 .604-.27.604-.604V2.652a.604.604 0 0 0-.604-.604m-.604 12.701h-.985v-.17a.604.604 0 0 0-1.208 0v.17h-.63v-.17a.604.604 0 0 0-1.208 0v.17H1.207V3.256h18.585z"})]})})}]:[],...(j==null?void 0:j.languages.length)>0?[{label:"Language Pages",component:Vt,icon:e.jsx(e.Fragment,{children:e.jsx("svg",{width:"21",height:"21",viewBox:"0 0 21 21",fill:"currentColor",children:e.jsxs("g",{fill:"none","fill-rule":"evenodd",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round",children:[e.jsx("path",{d:"M18.5 10.5v-6a2 2 0 0 0-2-2h-6a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2"}),e.jsx("path",{d:"M6.5 8.503h-2a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h.003l6-.01a2 2 0 0 0 1.997-2V14.5"}),e.jsx("path",{d:"M7.5 12.503h-3M9 14l-1 1q-.5.5-2.5 1.5"}),e.jsx("path",{d:"M5.5 12.503q.501 1.75 1.5 2.499c1 .749 1.5.999 2.5 1.498m4-12-3 6m3-6 3 6m-1-2h-4"})]})})})}]:[]]},...G}),e.jsx(Zt,{activePage:n||"",canClose:!!n&&!c.isEmpty(i),open:!n||!h&&c.isEmpty(i)||pe,close:()=>se(!1)}),re&&e.jsx(aa,{onClose:()=>ie(!1)})]})},Xe=new A.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),sa=a=>(Xe.setQueryData(["builder_props"],a),e.jsx(A.QueryClientProvider,{client:Xe,children:e.jsx(na,{...a})}));module.exports=sa;
package/dist/index.js CHANGED
@@ -2419,7 +2419,7 @@ const xn = (a) => {
2419
2419
  },
2420
2420
  sideBarComponents: {
2421
2421
  top: [
2422
- ...r != null && r.global ? [] : [
2422
+ ...(r == null ? void 0 : r.collection) !== "global" ? [
2423
2423
  {
2424
2424
  label: "SEO Setting",
2425
2425
  component: Mt,
@@ -2438,7 +2438,7 @@ const xn = (a) => {
2438
2438
  }
2439
2439
  ) })
2440
2440
  }
2441
- ],
2441
+ ] : [],
2442
2442
  ...(b == null ? void 0 : b.languages.length) > 0 ? [
2443
2443
  {
2444
2444
  label: "Language Pages",
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Suraj Air",
4
4
  "license": "Private",
5
5
  "homepage": "https://chaibuilder.com",
6
- "version": "0.1.0-beta.26",
6
+ "version": "0.1.0-beta.27",
7
7
  "type": "module",
8
8
  "files": [
9
9
  "dist"
@@ -61,7 +61,7 @@
61
61
  "@ai-sdk/openai": "^0.0.66",
62
62
  "@chaibuilder/ai": "^0.1.2",
63
63
  "@chaibuilder/runtime": "0.2.12",
64
- "@chaibuilder/sdk": "^2.0.0-beta.3",
64
+ "@chaibuilder/sdk": "^2.0.0-beta.4",
65
65
  "@mhsdesign/jit-browser-tailwindcss": "^0.4.1",
66
66
  "@supabase/supabase-js": "^2.45.6",
67
67
  "@tailwindcss/aspect-ratio": "^0.4.2",