@chaibuilder/pages 0.1.0-beta.4 → 0.1.0-beta.6
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 +1 -1
- package/dist/index.js +47 -47
- package/dist/server.cjs +1 -1
- package/dist/server.js +30 -27
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -27,4 +27,4 @@ Check the top-level render call using <`+c+">.")}return n}}function $e(e,n){{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} />`,je,$,Nt,$),Ve[$+je]=!0}}return e===a?St(P):wt(P),P}}function Et(e,n,c){return We(e,n,c,!0)}function Ct(e,n,c){return We(e,n,c,!1)}var Tt=Ct,kt=Et;X.Fragment=a,X.jsx=Tt,X.jsxs=kt}()),X}process.env.NODE_ENV==="production"?we.exports=Ot():we.exports=Rt();var t=we.exports;const Dt=(s,o)=>{const a=_.useQueryClient().getQueryData(["builder_props"]);return g.get(a,s,o)},I=()=>Dt("apiUrl","/chai/api");function z(){const[s,o]=k.useState(new URLSearchParams(window.location.search));return k.useEffect(()=>{const l=()=>{o(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",l),()=>{window.removeEventListener("popstate",l)}},[]),[s,o]}const Ye=()=>{const[s]=z(),o=s.get("page"),l=I();return _.useQuery({queryKey:["page",o],initialData:[],queryFn:async()=>(await(await fetch(`${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:o,draft:!0}})})).json()).blocks??[],enabled:!!o})},He=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast(),{data:a}=Ye(),[i]=z(),E=i.get("page"),u=g.get(g.find(a,{_type:"@chai/ai-context"}),"_value",""),{mutateAsync:p}=_.useMutation({mutationFn:async({page:d,aiContext:m})=>{const v={_type:"@chai/ai-context",_value:g.isString(m)?m:""},x=g.filter(a,C=>(C==null?void 0:C._type)!==v._type);return x.push(v),await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:d,blocks:x}})})},onSuccess:(d,{aiContext:m})=>{o.setQueryData(["page",E],()=>{const v={_type:"@chai/ai-context",_value:g.isString(m)?m:""},x=g.filter(a,f=>(f==null?void 0:f._type)!==v._type);return x.push(v),x}),l({title:"AI context updated successfully."})},onError:d=>{l({variant:"destructive",title:"Failed to update AI context",description:d.message})}});return{aiContext:u,updateAiContext:p}},At=()=>{const s=I(),{aiContext:o}=He();return k.useCallback(async(l,a,i,E)=>{const p=await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ASK_AI",data:{type:l,prompt:a,blocks:i,aiContext:o,lang:E}})})).json();return console.log("data",p),p.error?{error:new Error(p.error)}:p},[s,o])},Ft=()=>{const s=I(),{toast:o}=r.useToast(),l=_.useQueryClient();return{getUILibraryBlock:async(u,p)=>{const v=(await(await fetch(u.url+(p.path?"/blocks/"+p.path:"/"+p.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return Z.getBlocksFromHTML(`${v}`)},getUILibraryBlocks:async u=>{try{return(await(await fetch(u.url+"/blocks.json")).json()).map(m=>({...m,preview:u.url.replace("chaiblocks","")+m.preview}))}catch(p){return console.error(p),[]}},onSave:async({page:u,blocks:p})=>{try{return(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:u,blocks:p}})})).ok?(l.setQueryData(["page",u],p),o({title:"Success",description:"Page saved successfully",variant:"default"}),!0):new Error("Failed to save blocks")}catch(d){return d}}}},Se=()=>{const s=I();return _.useQuery({queryKey:["project-pages"],initialData:[],queryFn:async()=>await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_PAGES"})})).json()})},Xe=()=>{const[s]=z(),o=s.get("page"),{data:l,isFetching:a}=Se();return{data:k.useMemo(()=>g.find(l,{id:o})||{},[l,o]),isFetching:a}},Lt=()=>_.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"}]}),It=s=>k.useMemo(()=>{if(!s||g.isEmpty(s))return{blocks:[],theme:{}};const o=g.find(s,{_type:"@chai/theme"}),l=g.get(o,"_value",{})||{},a=g.filter(s,i=>!g.includes(i==null?void 0:i._type,"@chai/"));return{theme:l,blocks:a}},[s]),Ze=()=>{const s=I();return _.useQuery({queryKey:["project-config"],initialData:{theme:{}},queryFn:async()=>await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_CONFIG"})})).json()})},Bt=()=>{const{data:s}=Se(),o=I();return{getGlobalBlocks:async()=>{const l={};for(const a of s)g.isEmpty(a==null?void 0:a.slug)&&(l[a.id]={name:g.startCase(a.name??a.slug),description:""});return l},getGlobalBlockBlocks:async l=>l?(await(await fetch(`${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:l,draft:!0}})})).json()).blocks:[]}},Ut=()=>{const s=I();return{uploadFile:async l=>{const a=new FormData;return a.append("action","UPLOAD_FILE"),a.append("file",l),(await fetch(s,{method:"POST",body:a})).json()}}},Gt=()=>{const s=I(),{toast:o}=r.useToast();return _.useMutation({mutationFn:async l=>(await fetch(`${s}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"PUBLISH_PAGE",data:{id:l}})})).json(),onSuccess:()=>{o({title:"Pages published",description:"Your page has been published"})}})},Ee=()=>{const s=I(),[o]=z(),l=o.get("page");return _.useQuery({queryKey:["language-pages",l],initialData:[],queryFn:async()=>{if(!l)return null;const i=await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_LANGUAGE_PAGES",data:{id:l}})})).json();return g.reverse(g.sortBy(i,"primaryPage"))}})},ce={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"},et=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast();return _.useMutation({mutationFn:async a=>await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"CREATE_PAGE",data:a})})).json(),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage)?o.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`New ${i.global?"global block":"page"} added successfully.`})},onError:(a,i)=>{l({variant:"destructive",title:`Failed to add new ${i.global?"global block":"page"}.`,description:a.message})}})},Ce=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast();return _.useMutation({mutationFn:async a=>(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:a})})).json(),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?o.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),i!=null&&i.seo?l({title:"SEO Settings updated successfully."}):l({title:`${i.global?"Global block":"Page"} updated successfully.`})},onError:(a,i)=>{l({variant:"destructive",title:`Failed to update ${i.global?"global block":"page"}.`,description:a.message})}})},tt=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast();return _.useMutation({mutationFn:async a=>(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"DELETE_PAGE",data:{id:a==null?void 0:a.id}})})).json(),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage)?o.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`${i.global?"Global block":"Page"} deleted successfully.`})},onError:(a,i)=>{l({variant:"destructive",title:`Failed to delete ${i.global?"global block":"page"}.`,description:a.message})}})},qt=()=>{const{selectedLang:s}=Z.useLanguages(),{data:o,isFetching:l}=Ee();return{data:k.useMemo(()=>g.find(o,{lang:s||""})||{},[o,s]),isFetching:l}},at=()=>{const{data:s,isFetching:o}=qt(),l=s==null?void 0:s.seo,[a,i]=k.useState({seoTitle:"",seoDescription:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l}),E=k.useRef({initial:a,updated:a}),{selectedLang:u,fallbackLang:p}=Z.useLanguages(),d=u.length?u:p,{mutate:m,isPending:v}=Ce(),x=v;k.useEffect(()=>{!o&&l&&i({seoTitle:"",seoDescription:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l})},[o,l]);const f=async()=>{m({id:s==null?void 0:s.id,seo:a}),E.current.initial=a,E.current.updated=a},C=()=>{i({...a,ogTitle:a.seoTitle,ogDescription:a.seoDescription})},O=()=>{i({...a,searchTitle:a.ogTitle,searchDescription:a.ogDescription})},T=B=>{const L={...a,[B.target.name]:B.target.name==="noIndex"?B.target.checked:B.target.value};i(L),E.current.updated=L};return t.jsxs("div",{className:"relative pb-40",children:[t.jsxs("div",{className:"text-xs bg-gray-100 p-2 rounded-md text-center",children:["Current language:"," ",t.jsx("span",{className:"text-blue-500 font-semibold",children:g.get(ce,d,d)})]}),t.jsx("form",{className:"space-y-8",children:t.jsxs(r.Accordion,{type:"multiple",defaultValue:["page"],children:[t.jsxs(r.AccordionItem,{value:"page",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Seo Page"}),t.jsx(r.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoTitle",children:"SEO Title"}),t.jsx(r.Input,{type:"text",id:"seoTitle",name:"seoTitle",value:a.seoTitle,onChange:T,disabled:x,placeholder:"Enter SEO title"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The title should be between 10 and 60 characters."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoDescription",children:"SEO Description"}),t.jsx(r.Textarea,{id:"seoDescription",name:"seoDescription",value:a.seoDescription,onChange:T,disabled:x,placeholder:"Enter SEO description"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The description should be between 50 and 160 characters."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoTitle",children:"Canonical URL"}),t.jsx(r.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:a.canonicalUrl,onChange:T,disabled:x,placeholder:"Enter Canonical URL"})]}),t.jsxs("div",{className:"",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx(r.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:a.noIndex,onChange:T,disabled:x,className:"h-4 w-4"}),t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"noIndex",children:"No Index"})]}),t.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."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoTitle",children:"No Follow"}),t.jsx(r.Input,{type:"text",id:"noFollow",name:"noFollow",value:a.noFollow,onChange:T,disabled:x,placeholder:"Enter No follow"})]})]})})]}),t.jsxs(r.AccordionItem,{value:"og",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"OG"}),t.jsx(r.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:C,children:"Copy from SEO Settings"})}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogTitle",children:"OG Title"}),t.jsx(r.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:a.ogTitle,onChange:T,disabled:x,placeholder:"Enter OG title"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG title should be between 10 and 60 characters."})]}),t.jsxs("div",{className:"mt-4",children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogDescription",children:"OG Description"}),t.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",value:a.ogDescription,onChange:T,disabled:x,placeholder:"Enter OG description"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG description should be between 50 and 160 characters."})]}),t.jsxs("div",{className:"mt-4",children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogImage",children:"OG Image URL"}),t.jsx(r.Input,{type:"text",id:"ogImage",name:"ogImage",value:a.ogImage,onChange:T,disabled:x,placeholder:"Enter OG image URL"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"Enter a valid URL for the OG image."})]})]})})]}),t.jsxs(r.AccordionItem,{value:"search",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Search"}),t.jsx(r.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:O,children:"Copy from OG Settings"})}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchTitle",children:"Search Title"}),t.jsx(r.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:a.searchTitle,onChange:T,disabled:x,placeholder:"Enter search title"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search title should be between 10 and 60 characters."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchDescription",children:"Search Description"}),t.jsx(r.Textarea,{id:"searchDescription",name:"searchDescription",value:a.searchDescription,onChange:T,placeholder:"Enter search description"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search description should be between 50 and 160 characters."})]})]})})]}),t.jsxs(r.AccordionItem,{value:"jsonLD",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"JSON-LD"}),t.jsx(r.AccordionContent,{children:t.jsx("div",{className:"space-y-4",children:t.jsx("div",{children:t.jsx(r.Textarea,{id:"jsonLD",name:"jsonLD",rows:3,value:a.jsonLD,onChange:T,placeholder:"Enter JSON-LD"})})})})]})]})}),t.jsx("div",{className:"w-full flex items-center justify-end mt-4",children:t.jsx(r.Button,{size:"lg",variant:"default",onClick:f,disabled:g.isEqual(E.current.initial,a)||x,children:v?"Saving...":"Save"})})]})};at.displayName="SeoPanel";const Mt=({langProps:s,onClose:o,languagePages:l})=>{const{data:a}=Xe(),[i,E]=k.useState(s.edit?s.name:""),[u,p]=k.useState(s.edit?s.lang:""),[d,m]=k.useState(s.edit?s.slug:""),{mutate:v,isPending:x}=et(),{mutate:f,isPending:C}=Ce(),O=x||C,{data:T}=Ze(),B=g.filter(g.get(T,"languages")||["en"],j=>!g.find(l,{lang:j})&&j!==g.get(T,"fallbackLang")),L=()=>{s.edit?f({name:i,slug:d,lang:u,id:s==null?void 0:s.id,primaryPage:s==null?void 0:s.primaryPage},{onSuccess:o}):v({name:i,slug:d,lang:u,primaryPage:a==null?void 0:a.id},{onSuccess:o})};return t.jsx(r.Dialog,{open:!!s,onOpenChange:o,children:t.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[t.jsxs(r.DialogHeader,{children:[t.jsx(r.DialogTitle,{children:s.edit?"Edit language":"Add New language"}),t.jsx(r.DialogDescription,{children:"Enter the details for the language"})]}),t.jsxs("form",{children:[t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"lang",className:"text-right",children:"Language"}),t.jsxs("select",{value:u,disabled:s.edit||g.isEmpty(B),onChange:j=>p(j.target.value),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:[t.jsx("option",{value:"",disabled:!0,selected:!0,children:g.isEmpty(B)?"All available language page is created.":"Choose language"}),g.map(B,j=>t.jsx("option",{value:j,children:g.get(ce,j,j)},j))]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:"Page Name"}),t.jsx(r.Input,{id:"name",value:i,onChange:j=>E(j.target.value),className:"col-span-3",required:!0,placeholder:"Enter page name"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs(r.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",t.jsx("small",{className:"font-light",children:"(Slug should start with /)"})]}),t.jsx(r.Input,{id:"slug",value:d,onChange:j=>m(g.toLower(g.trim(j.target.value))),className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),t.jsx(r.DialogFooter,{children:t.jsx(r.Button,{onClick:L,type:"button",disabled:O||!u||!d||!d.startsWith("/"),children:O?s.edit?"Updating...":"Adding...":s.edit?"Update":"Add new language"})})]})]})})},$t=()=>{const[s,o]=k.useState(null),{selectedLang:l,fallbackLang:a,setSelectedLang:i,languages:E}=Z.useLanguages(),{data:u,isFetching:p}=Ee(),{mutate:d,isPending:m}=tt();return t.jsxs("div",{className:"space-y-4 pt-2",children:[t.jsxs("ul",{className:"space-y-2 mt-4",children:[p&&t.jsxs("div",{className:"w-full space-y-3 py-4",children:[t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}),g.map(u,v=>{const x=v.lang,f=v.slug,C=!v.primaryPage,O=x===l;return C?null:t.jsxs(t.Fragment,{children:[t.jsxs("li",{className:`w-full p-2 rounded cursor-pointer flex items-center justify-between ${O?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>i(x),children:[t.jsxs("div",{className:" flex-1 gap-x-3",children:[t.jsx("div",{className:"text-[13px]",children:g.get(ce,C?a:x,x)}),t.jsxs("div",{children:[t.jsxs("div",{className:"text-[11px] text-gray-500",children:["Slug:",t.jsxs("b",{children:[" ",f]})]}),t.jsxs("div",{className:"text-[11px] text-gray-500",children:["Name:",t.jsxs("b",{children:[" ",v.name," "]})]})]})]}),C?t.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[t.jsx(G.StarIcon,{fill:"orange",className:"w-3 h-3"}),t.jsx("b",{children:" Default"})]}):t.jsxs("div",{className:"flex items-center gap-x-3",children:[t.jsx(G.PencilIcon,{onClick:T=>{T.stopPropagation(),o({...v,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),t.jsxs(r.Popover,{children:[t.jsx(r.PopoverTrigger,{children:t.jsx(G.TrashIcon,{className:"w-3 h-3 hover:text-red-500"})}),t.jsx(r.PopoverContent,{children:t.jsxs("div",{children:[t.jsxs("p",{className:"pb-2 text-sm",children:["Are you sure you want to remove"," ",t.jsx("b",{children:g.get(ce,x,x)})," language?"]}),t.jsx("div",{className:"flex items-center justify-end w-full",children:t.jsx(r.Button,{size:"sm",variant:"destructive",disabled:m,onClick:()=>d(v),children:m?"Deleting...":"Delete"})})]})})]})]})]},v.id),t.jsx("div",{className:"h-1 w-full border-b"})]})})]}),t.jsx("div",{className:"flex justify-center w-full",children:((u==null?void 0:u.length)||0)>=E.length&&t.jsx(r.Button,{variant:"default",size:"sm",onClick:()=>o({name:"",lang:"",slug:"",edit:!1}),children:"+ Add new language"})}),s&&t.jsx(Mt,{langProps:s,languagePages:u,onClose:()=>o(null)})]})},Kt=({activePage:s,editPage:o,onShowUpsertPage:l})=>{const[a,i]=k.useState("pages"),{data:E,isFetching:u}=Se(),{mutate:p,isPending:d}=tt(),m=v=>g.orderBy(g.filter(v,f=>a==="pages"?f.slug:!f.slug),"name","asc").map(f=>t.jsxs(r.Button,{onClick:()=>o(f.id),variant:f.id===s?"default":"ghost",className:"flex justify-between items-center w-full space-x-2 py-1",children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[f.global?t.jsx(G.GlobeIcon,{className:"h-4 w-4"}):t.jsx(G.File,{className:"h-4 w-4"}),t.jsx("span",{children:f.name??f.slug}),(f==null?void 0:f.slug)&&t.jsxs("span",{className:"text-xs font-light",children:["( ",f.slug," )"]})]}),t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsx(G.PencilIcon,{className:"h-3 w-3 hover:text-blue-500",onClick:C=>{C.stopPropagation(),l({...f,global:a==="globalBlocks"})}}),t.jsxs(r.Popover,{children:[t.jsx(r.PopoverTrigger,{onClick:C=>C.stopPropagation(),children:t.jsx(G.TrashIcon,{className:"w-3 h-3 hover:text-red-500"})}),t.jsx(r.PopoverContent,{children:t.jsxs("div",{children:[t.jsxs("p",{className:"pb-2 text-sm",children:["Are you sure you want to remove"," ",t.jsx("b",{children:f.name??(f==null?void 0:f.slug)})," ",f.global?"global block?":"page? This will also delete all associated language pages."]}),t.jsx("div",{className:"flex items-center justify-end w-full",children:t.jsx(r.Button,{size:"sm",variant:"destructive",disabled:d,onClick:C=>{C.stopPropagation(),p(f)},children:d?"Deleting...":"Delete"})})]})})]})]})]},f.id));return t.jsxs(t.Fragment,{children:[t.jsx("br",{}),t.jsxs(r.Tabs,{value:a,className:"w-full",onValueChange:i,children:[t.jsxs(r.TabsList,{className:"w-full",children:[t.jsx(r.TabsTrigger,{value:"pages",className:"w-full",children:t.jsx("div",{className:"px-4",children:"Pages"})}),t.jsx(r.TabsTrigger,{value:"globalBlocks",className:"w-full",children:t.jsx("div",{className:"px-4",children:"Global Blocks"})})]}),u?t.jsxs("div",{className:"w-full space-y-3 py-4",children:[t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):t.jsxs("div",{className:"py-4 space-y-3",children:[t.jsx(r.SheetHeader,{children:t.jsxs(r.SheetDescription,{className:"text-xs text-muted-foreground text-center text-light",children:["Manage your ",a==="pages"?"pages":"global blocks"]})}),t.jsx("div",{className:"w-full flex justify-center",children:t.jsxs(r.Button,{variant:"default",size:"sm",disabled:u,onClick:()=>l({slug:"",name:"",global:a==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[t.jsx(G.Plus,{className:"h-4 w-4 mr-2"}),u?"Loading...":`Add new ${a==="pages"?"page":"global block"}`]})}),t.jsx("div",{className:"pt-4",children:t.jsx("div",{className:"space-y-2",children:u?t.jsx("div",{className:"h-32 w-full flex justify-center items-center text-sm animate-pulse",children:"Loading..."}):m(E)})})]})]})]})},Vt=({editPage:s,showUpsertPage:o,setShowUpsertPage:l})=>{const a=o.id,[i,E]=k.useState(a&&o.name||""),[u,p]=k.useState(a&&o.slug||""),{mutate:d,isPending:m}=et(),{mutate:v,isPending:x}=Ce(),f=m||x,C=()=>{a?v({name:i,slug:u,id:o.id,global:!!o.global},{onSuccess:()=>{l(void 0)}}):d({name:i,slug:u,global:!!o.global},{onSuccess:O=>{s(O.id)}})};return t.jsx(r.Dialog,{open:!!o,onOpenChange:()=>l(void 0),children:t.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[t.jsxs(r.DialogHeader,{children:[t.jsxs(r.DialogTitle,{children:[a?"Edit":"Add New"," ",o.global?"Global Block":"Page"]}),t.jsxs(r.DialogDescription,{children:["Enter the details for the new"," ",o.global?"global block. Identifier should be unique.":"page. Slug must start with /"]})]}),t.jsxs("form",{children:[t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"name",className:"text-right",children:"Name"}),t.jsx(r.Input,{id:"name",value:i,placeholder:`Enter ${o.global?"global block":"page"} name`,onChange:O=>E(O.target.value),className:"col-span-3",required:!0})]}),!o.global&&t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:o.global?"Identifier":"Slug"}),t.jsx(r.Input,{id:"slug",value:u,onChange:O=>{var T;return p((T=O.target.value)==null?void 0:T.trim().toLowerCase())},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),t.jsx(r.DialogFooter,{children:t.jsx(r.Button,{onClick:C,type:"button",disabled:f||!i||!o.global&&!u.startsWith("/")||g.isEqual(o.name,i)&&g.isEqual(o.slug,u),children:f?a?"Updating...":"Adding...":o.global?`${a?"Update":"Add"} global block`:`${a?"Update":"Add"} Page`})})]})]})})};function Wt(s){const{activePage:o,canClose:l,open:a,close:i}=s,[,E]=z(),[u,p]=k.useState(),d=m=>{window.history.pushState({},"",`?page=${m}`),E(new URLSearchParams({page:m})),window.dispatchEvent(new PopStateEvent("popstate")),p(void 0),i()};return t.jsx(r.Sheet,{open:a,onOpenChange:m=>{!m&&l&&i()},children:t.jsxs(r.SheetContent,{side:"left",className:`border-border w-full ${l?"":"sheet-hide-close-btn"}`,children:[t.jsx("div",{children:t.jsx(Kt,{onShowUpsertPage:m=>p(m),activePage:o,editPage:d})}),u&&t.jsx(Vt,{editPage:d,showUpsertPage:u,setShowUpsertPage:p})]})})}_t.loadWebBlocks();const zt=s=>{var ne;const[o]=z(),l=o.get("page"),{data:a,isFetching:i}=Xe(),{data:E}=Lt(),{data:u}=Ye(),{blocks:p,theme:d}=It(u),{data:m}=Ze(),{data:v}=Ee(),x=At(),{uploadFile:f}=Ut(),{getUILibraryBlock:C,getUILibraryBlocks:O,onSave:T}=Ft(),{getGlobalBlocks:B,getGlobalBlockBlocks:L}=Bt(),{mutate:j,isPending:ee}=Gt(),{aiContext:J,updateAiContext:ue}=He(),[de,te]=k.useState(!1),[K,ae]=k.useState("SAVED");k.useEffect(()=>{const A=R=>{K==="UNSAVED"&&(R.preventDefault(),R.returnValue=!1)};return K==="UNSAVED"&&window.addEventListener("beforeunload",A),()=>{window.removeEventListener("beforeunload",A)}},[K]);const he=k.useMemo(()=>{const A={};return m!=null&&m.theme&&(A.brandingOptions=m.theme),A},[m]);return t.jsxs(t.Fragment,{children:[t.jsx(Z.ChaiBuilderEditor,{fallbackLang:s.fallbackLang||"en",languages:g.map(v,"lang")||[],translations:s.translations||{},locale:s.locale||"en",htmlDir:s.htmlDir||"ltr",autoSaveSupport:s.autoSaveSupport||!1,autoSaveInterval:s.autoSaveInterval||15,uploadMediaCallback:f,onError:s.onError||console.error,getGlobalBlockBlocks:L,getGlobalBlocks:B,blocks:p,getUILibraryBlock:C,getUILibraryBlocks:O,brandingOptions:d,uiLibraries:E,saveAiContextCallback:async A=>(await ue({page:l,aiContext:A}),!0),onSaveStateChange:A=>ae(A),aiContext:J,askAiCallBack:x,onSave:async({blocks:A,themeConfiguration:R})=>{if(!l)return!0;const q={_type:"@chai/theme",_value:R},M={_type:"@chai/ai-context",_value:g.isString(J)?J:""},se=[...A,q,M];return await T({page:l,blocks:se}),!0},topBarComponents:{left:[()=>t.jsxs(r.Button,{variant:"default",className:"flex justify-start max-w-[250px] items-center w-full space-x-2 py-1",onClick:()=>te(!0),children:[g.includes(a.slug,"/")?t.jsx(G.File,{className:"h-4 w-4"}):t.jsx(G.GlobeIcon,{className:"h-4 w-4"}),t.jsx("span",{className:"truncate",children:(a==null?void 0:a.name)??""}),t.jsx(G.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[()=>t.jsxs(r.Button,{disabled:ee||K!=="SAVED",size:"sm",variant:"default",onClick:()=>j(l),children:[t.jsx(G.RocketIcon,{className:"h-4 w-4"})," "," ",ee?"Publishing...":"Publish"]})]},sideBarComponents:{top:[...g.includes(a.slug,"/")?[{label:"SEO Setting",component:at,icon:t.jsx(t.Fragment,{children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 21 21",fill:"currentColor",width:"21",height:"21",children:[t.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"}),t.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"})]})})}]:[],...(ne=s.languages)!=null&&ne.length&&g.includes(a.slug,"/")?[{label:"Language Pages",component:$t,icon:t.jsx(t.Fragment,{children:t.jsx("svg",{width:"21",height:"21",viewBox:"0 0 21 21",fill:"currentColor",children:t.jsxs("g",{fill:"none","fill-rule":"evenodd",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round",children:[t.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"}),t.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"}),t.jsx("path",{d:"M7.5 12.503h-3M9 14l-1 1q-.5.5-2.5 1.5"}),t.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"})]})})})}]:[]]},...he}),t.jsx(Wt,{activePage:l||"",canClose:!!l&&!g.isEmpty(a),open:!l||!i&&g.isEmpty(a)||de,close:()=>te(!1)})]})},Qe=new _.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),Jt=s=>(Qe.setQueryData(["builder_props"],s),t.jsx(_.QueryClientProvider,{client:Qe,children:t.jsx(zt,{...s})}));module.exports=Jt;
|
|
30
|
+
<%s key={someKey} {...props} />`,je,$,Nt,$),Ve[$+je]=!0}}return e===a?St(P):wt(P),P}}function Et(e,n,c){return We(e,n,c,!0)}function Ct(e,n,c){return We(e,n,c,!1)}var Tt=Ct,kt=Et;X.Fragment=a,X.jsx=Tt,X.jsxs=kt}()),X}process.env.NODE_ENV==="production"?we.exports=Ot():we.exports=Rt();var t=we.exports;const Dt=(s,o)=>{const a=_.useQueryClient().getQueryData(["builder_props"]);return g.get(a,s,o)},I=()=>Dt("apiUrl","/chai/api");function z(){const[s,o]=k.useState(new URLSearchParams(window.location.search));return k.useEffect(()=>{const l=()=>{o(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",l),()=>{window.removeEventListener("popstate",l)}},[]),[s,o]}const Ye=()=>{const[s]=z(),o=s.get("page"),l=I();return _.useQuery({queryKey:["page",o],initialData:[],queryFn:async()=>(await(await fetch(`${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:o,draft:!0}})})).json()).blocks??[],enabled:!!o})},He=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast(),{data:a}=Ye(),[i]=z(),E=i.get("page"),u=g.get(g.find(a,{_type:"@chai/ai-context"}),"_value",""),{mutateAsync:p}=_.useMutation({mutationFn:async({page:d,aiContext:m})=>{const v={_type:"@chai/ai-context",_value:g.isString(m)?m:""},x=g.filter(a,C=>(C==null?void 0:C._type)!==v._type);return x.push(v),await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:d,blocks:x}})})},onSuccess:(d,{aiContext:m})=>{o.setQueryData(["page",E],()=>{const v={_type:"@chai/ai-context",_value:g.isString(m)?m:""},x=g.filter(a,f=>(f==null?void 0:f._type)!==v._type);return x.push(v),x}),l({title:"AI context updated successfully."})},onError:d=>{l({variant:"destructive",title:"Failed to update AI context",description:d.message})}});return{aiContext:u,updateAiContext:p}},At=()=>{const s=I(),{aiContext:o}=He();return k.useCallback(async(l,a,i,E)=>{const p=await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ASK_AI",data:{type:l,prompt:a,blocks:i,aiContext:o,lang:E}})})).json();return console.log("data",p),p.error?{error:new Error(p.error)}:p},[s,o])},Ft=()=>{const s=I(),{toast:o}=r.useToast(),l=_.useQueryClient();return{getUILibraryBlock:async(u,p)=>{const v=(await(await fetch(u.url+(p.path?"/blocks/"+p.path:"/"+p.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return Z.getBlocksFromHTML(`${v}`)},getUILibraryBlocks:async u=>{try{return(await(await fetch(u.url+"/blocks.json")).json()).map(m=>({...m,preview:u.url.replace("chaiblocks","")+m.preview}))}catch(p){return console.error(p),[]}},onSave:async({page:u,blocks:p})=>{try{return(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:u,blocks:p}})})).ok?(l.setQueryData(["page",u],p),o({title:"Success",description:"Page saved successfully",variant:"default"}),!0):new Error("Failed to save blocks")}catch(d){return d}}}},Se=()=>{const s=I();return _.useQuery({queryKey:["project-pages"],staleTime:1e3*60*5,queryFn:async()=>await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_PAGES"})})).json()})},Xe=()=>{const[s]=z(),o=s.get("page"),{data:l,isFetching:a}=Se();return{data:k.useMemo(()=>g.find(l,{id:o})||{},[l,o]),isFetching:a}},Lt=()=>_.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"}]}),It=s=>k.useMemo(()=>{if(!s||g.isEmpty(s))return{blocks:[],theme:{}};const o=g.find(s,{_type:"@chai/theme"}),l=g.get(o,"_value",{})||{},a=g.filter(s,i=>!g.includes(i==null?void 0:i._type,"@chai/"));return{theme:l,blocks:a}},[s]),Ze=()=>{const s=I();return _.useQuery({queryKey:["project-config"],initialData:{theme:{}},queryFn:async()=>await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_CONFIG"})})).json()})},Bt=()=>{const{data:s}=Se(),o=I();return{getGlobalBlocks:async()=>{const l={};for(const a of s??[])g.isEmpty(a==null?void 0:a.slug)&&(l[a.id]={name:g.startCase(a.name??a.slug),description:""});return l},getGlobalBlockBlocks:async l=>l?(await(await fetch(`${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:l,draft:!0}})})).json()).blocks:[]}},Ut=()=>{const s=I();return{uploadFile:async l=>{const a=new FormData;return a.append("action","UPLOAD_FILE"),a.append("file",l),(await fetch(s,{method:"POST",body:a})).json()}}},Gt=()=>{const s=I(),{toast:o}=r.useToast();return _.useMutation({mutationFn:async l=>(await fetch(`${s}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"PUBLISH_PAGE",data:{id:l}})})).json(),onSuccess:()=>{o({title:"Pages published",description:"Your page has been published"})}})},Ee=()=>{const s=I(),[o]=z(),l=o.get("page");return _.useQuery({queryKey:["language-pages",l],initialData:[],queryFn:async()=>{if(!l)return null;const i=await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_LANGUAGE_PAGES",data:{id:l}})})).json();return g.reverse(g.sortBy(i,"primaryPage"))}})},ce={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"},et=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast();return _.useMutation({mutationFn:async a=>await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"CREATE_PAGE",data:a})})).json(),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage)?o.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`New ${i.global?"global block":"page"} added successfully.`})},onError:(a,i)=>{l({variant:"destructive",title:`Failed to add new ${i.global?"global block":"page"}.`,description:a.message})}})},Ce=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast();return _.useMutation({mutationFn:async a=>(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:a})})).json(),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?o.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),i!=null&&i.seo?l({title:"SEO Settings updated successfully."}):l({title:`${i.global?"Global block":"Page"} updated successfully.`})},onError:(a,i)=>{l({variant:"destructive",title:`Failed to update ${i.global?"global block":"page"}.`,description:a.message})}})},tt=()=>{const s=I(),o=_.useQueryClient(),{toast:l}=r.useToast();return _.useMutation({mutationFn:async a=>(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"DELETE_PAGE",data:{id:a==null?void 0:a.id}})})).json(),onSuccess:(a,i)=>{i&&(i!=null&&i.primaryPage)?o.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`${i.global?"Global block":"Page"} deleted successfully.`})},onError:(a,i)=>{l({variant:"destructive",title:`Failed to delete ${i.global?"global block":"page"}.`,description:a.message})}})},qt=()=>{const{selectedLang:s}=Z.useLanguages(),{data:o,isFetching:l}=Ee();return{data:k.useMemo(()=>g.find(o,{lang:s||""})||{},[o,s]),isFetching:l}},at=()=>{const{data:s,isFetching:o}=qt(),l=s==null?void 0:s.seo,[a,i]=k.useState({seoTitle:"",seoDescription:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l}),E=k.useRef({initial:a,updated:a}),{selectedLang:u,fallbackLang:p}=Z.useLanguages(),d=u.length?u:p,{mutate:m,isPending:v}=Ce(),x=v;k.useEffect(()=>{!o&&l&&i({seoTitle:"",seoDescription:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l})},[o,l]);const f=async()=>{m({id:s==null?void 0:s.id,seo:a}),E.current.initial=a,E.current.updated=a},C=()=>{i({...a,ogTitle:a.seoTitle,ogDescription:a.seoDescription})},O=()=>{i({...a,searchTitle:a.ogTitle,searchDescription:a.ogDescription})},T=B=>{const L={...a,[B.target.name]:B.target.name==="noIndex"?B.target.checked:B.target.value};i(L),E.current.updated=L};return t.jsxs("div",{className:"relative pb-40",children:[t.jsxs("div",{className:"text-xs bg-gray-100 p-2 rounded-md text-center",children:["Current language:"," ",t.jsx("span",{className:"text-blue-500 font-semibold",children:g.get(ce,d,d)})]}),t.jsx("form",{className:"space-y-8",children:t.jsxs(r.Accordion,{type:"multiple",defaultValue:["page"],children:[t.jsxs(r.AccordionItem,{value:"page",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Seo Page"}),t.jsx(r.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoTitle",children:"SEO Title"}),t.jsx(r.Input,{type:"text",id:"seoTitle",name:"seoTitle",value:a.seoTitle,onChange:T,disabled:x,placeholder:"Enter SEO title"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The title should be between 10 and 60 characters."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoDescription",children:"SEO Description"}),t.jsx(r.Textarea,{id:"seoDescription",name:"seoDescription",value:a.seoDescription,onChange:T,disabled:x,placeholder:"Enter SEO description"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The description should be between 50 and 160 characters."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoTitle",children:"Canonical URL"}),t.jsx(r.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:a.canonicalUrl,onChange:T,disabled:x,placeholder:"Enter Canonical URL"})]}),t.jsxs("div",{className:"",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx(r.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:a.noIndex,onChange:T,disabled:x,className:"h-4 w-4"}),t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"noIndex",children:"No Index"})]}),t.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."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"seoTitle",children:"No Follow"}),t.jsx(r.Input,{type:"text",id:"noFollow",name:"noFollow",value:a.noFollow,onChange:T,disabled:x,placeholder:"Enter No follow"})]})]})})]}),t.jsxs(r.AccordionItem,{value:"og",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"OG"}),t.jsx(r.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:C,children:"Copy from SEO Settings"})}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogTitle",children:"OG Title"}),t.jsx(r.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:a.ogTitle,onChange:T,disabled:x,placeholder:"Enter OG title"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG title should be between 10 and 60 characters."})]}),t.jsxs("div",{className:"mt-4",children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogDescription",children:"OG Description"}),t.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",value:a.ogDescription,onChange:T,disabled:x,placeholder:"Enter OG description"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG description should be between 50 and 160 characters."})]}),t.jsxs("div",{className:"mt-4",children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogImage",children:"OG Image URL"}),t.jsx(r.Input,{type:"text",id:"ogImage",name:"ogImage",value:a.ogImage,onChange:T,disabled:x,placeholder:"Enter OG image URL"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"Enter a valid URL for the OG image."})]})]})})]}),t.jsxs(r.AccordionItem,{value:"search",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Search"}),t.jsx(r.AccordionContent,{children:t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:O,children:"Copy from OG Settings"})}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchTitle",children:"Search Title"}),t.jsx(r.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:a.searchTitle,onChange:T,disabled:x,placeholder:"Enter search title"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search title should be between 10 and 60 characters."})]}),t.jsxs("div",{children:[t.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchDescription",children:"Search Description"}),t.jsx(r.Textarea,{id:"searchDescription",name:"searchDescription",value:a.searchDescription,onChange:T,placeholder:"Enter search description"}),t.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search description should be between 50 and 160 characters."})]})]})})]}),t.jsxs(r.AccordionItem,{value:"jsonLD",children:[t.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"JSON-LD"}),t.jsx(r.AccordionContent,{children:t.jsx("div",{className:"space-y-4",children:t.jsx("div",{children:t.jsx(r.Textarea,{id:"jsonLD",name:"jsonLD",rows:3,value:a.jsonLD,onChange:T,placeholder:"Enter JSON-LD"})})})})]})]})}),t.jsx("div",{className:"w-full flex items-center justify-end mt-4",children:t.jsx(r.Button,{size:"lg",variant:"default",onClick:f,disabled:g.isEqual(E.current.initial,a)||x,children:v?"Saving...":"Save"})})]})};at.displayName="SeoPanel";const Mt=({langProps:s,onClose:o,languagePages:l})=>{const{data:a}=Xe(),[i,E]=k.useState(s.edit?s.name:""),[u,p]=k.useState(s.edit?s.lang:""),[d,m]=k.useState(s.edit?s.slug:""),{mutate:v,isPending:x}=et(),{mutate:f,isPending:C}=Ce(),O=x||C,{data:T}=Ze(),B=g.filter(g.get(T,"languages")||["en"],j=>!g.find(l,{lang:j})&&j!==g.get(T,"fallbackLang")),L=()=>{s.edit?f({name:i,slug:d,lang:u,id:s==null?void 0:s.id,primaryPage:s==null?void 0:s.primaryPage},{onSuccess:o}):v({name:i,slug:d,lang:u,primaryPage:a==null?void 0:a.id},{onSuccess:o})};return t.jsx(r.Dialog,{open:!!s,onOpenChange:o,children:t.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[t.jsxs(r.DialogHeader,{children:[t.jsx(r.DialogTitle,{children:s.edit?"Edit language":"Add New language"}),t.jsx(r.DialogDescription,{children:"Enter the details for the language"})]}),t.jsxs("form",{children:[t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"lang",className:"text-right",children:"Language"}),t.jsxs("select",{value:u,disabled:s.edit||g.isEmpty(B),onChange:j=>p(j.target.value),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:[t.jsx("option",{value:"",disabled:!0,selected:!0,children:g.isEmpty(B)?"All available language page is created.":"Choose language"}),g.map(B,j=>t.jsx("option",{value:j,children:g.get(ce,j,j)},j))]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:"Page Name"}),t.jsx(r.Input,{id:"name",value:i,onChange:j=>E(j.target.value),className:"col-span-3",required:!0,placeholder:"Enter page name"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs(r.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",t.jsx("small",{className:"font-light",children:"(Slug should start with /)"})]}),t.jsx(r.Input,{id:"slug",value:d,onChange:j=>m(g.toLower(g.trim(j.target.value))),className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),t.jsx(r.DialogFooter,{children:t.jsx(r.Button,{onClick:L,type:"button",disabled:O||!u||!d||!d.startsWith("/"),children:O?s.edit?"Updating...":"Adding...":s.edit?"Update":"Add new language"})})]})]})})},$t=()=>{const[s,o]=k.useState(null),{selectedLang:l,fallbackLang:a,setSelectedLang:i,languages:E}=Z.useLanguages(),{data:u,isFetching:p}=Ee(),{mutate:d,isPending:m}=tt();return t.jsxs("div",{className:"space-y-4 pt-2",children:[t.jsxs("ul",{className:"space-y-2 mt-4",children:[p&&t.jsxs("div",{className:"w-full space-y-3 py-4",children:[t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}),g.map(u,v=>{const x=v.lang,f=v.slug,C=!v.primaryPage,O=x===l;return C?null:t.jsxs(t.Fragment,{children:[t.jsxs("li",{className:`w-full p-2 rounded cursor-pointer flex items-center justify-between ${O?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>i(x),children:[t.jsxs("div",{className:" flex-1 gap-x-3",children:[t.jsx("div",{className:"text-[13px]",children:g.get(ce,C?a:x,x)}),t.jsxs("div",{children:[t.jsxs("div",{className:"text-[11px] text-gray-500",children:["Slug:",t.jsxs("b",{children:[" ",f]})]}),t.jsxs("div",{className:"text-[11px] text-gray-500",children:["Name:",t.jsxs("b",{children:[" ",v.name," "]})]})]})]}),C?t.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[t.jsx(G.StarIcon,{fill:"orange",className:"w-3 h-3"}),t.jsx("b",{children:" Default"})]}):t.jsxs("div",{className:"flex items-center gap-x-3",children:[t.jsx(G.PencilIcon,{onClick:T=>{T.stopPropagation(),o({...v,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),t.jsxs(r.Popover,{children:[t.jsx(r.PopoverTrigger,{children:t.jsx(G.TrashIcon,{className:"w-3 h-3 hover:text-red-500"})}),t.jsx(r.PopoverContent,{children:t.jsxs("div",{children:[t.jsxs("p",{className:"pb-2 text-sm",children:["Are you sure you want to remove"," ",t.jsx("b",{children:g.get(ce,x,x)})," language?"]}),t.jsx("div",{className:"flex items-center justify-end w-full",children:t.jsx(r.Button,{size:"sm",variant:"destructive",disabled:m,onClick:()=>d(v),children:m?"Deleting...":"Delete"})})]})})]})]})]},v.id),t.jsx("div",{className:"h-1 w-full border-b"})]})})]}),t.jsx("div",{className:"flex justify-center w-full",children:((u==null?void 0:u.length)||0)>=E.length&&t.jsx(r.Button,{variant:"default",size:"sm",onClick:()=>o({name:"",lang:"",slug:"",edit:!1}),children:"+ Add new language"})}),s&&t.jsx(Mt,{langProps:s,languagePages:u,onClose:()=>o(null)})]})},Kt=({activePage:s,editPage:o,onShowUpsertPage:l})=>{const[a,i]=k.useState("pages"),{data:E,isFetching:u}=Se(),{mutate:p,isPending:d}=tt(),m=v=>g.orderBy(g.filter(v,f=>a==="pages"?f.slug:!f.slug),"name","asc").map(f=>t.jsxs(r.Button,{onClick:()=>o(f.id),variant:f.id===s?"default":"ghost",className:"flex justify-between items-center w-full space-x-2 py-1",children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[f.global?t.jsx(G.GlobeIcon,{className:"h-4 w-4"}):t.jsx(G.File,{className:"h-4 w-4"}),t.jsx("span",{children:f.name??f.slug}),(f==null?void 0:f.slug)&&t.jsxs("span",{className:"text-xs font-light",children:["( ",f.slug," )"]})]}),t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsx(G.PencilIcon,{className:"h-3 w-3 hover:text-blue-500",onClick:C=>{C.stopPropagation(),l({...f,global:a==="globalBlocks"})}}),t.jsxs(r.Popover,{children:[t.jsx(r.PopoverTrigger,{onClick:C=>C.stopPropagation(),children:t.jsx(G.TrashIcon,{className:"w-3 h-3 hover:text-red-500"})}),t.jsx(r.PopoverContent,{children:t.jsxs("div",{children:[t.jsxs("p",{className:"pb-2 text-sm",children:["Are you sure you want to remove"," ",t.jsx("b",{children:f.name??(f==null?void 0:f.slug)})," ",f.global?"global block?":"page? This will also delete all associated language pages."]}),t.jsx("div",{className:"flex items-center justify-end w-full",children:t.jsx(r.Button,{size:"sm",variant:"destructive",disabled:d,onClick:C=>{C.stopPropagation(),p(f)},children:d?"Deleting...":"Delete"})})]})})]})]})]},f.id));return t.jsxs(t.Fragment,{children:[t.jsx("br",{}),t.jsxs(r.Tabs,{value:a,className:"w-full",onValueChange:i,children:[t.jsxs(r.TabsList,{className:"w-full",children:[t.jsx(r.TabsTrigger,{value:"pages",className:"w-full",children:t.jsx("div",{className:"px-4",children:"Pages"})}),t.jsx(r.TabsTrigger,{value:"globalBlocks",className:"w-full",children:t.jsx("div",{className:"px-4",children:"Global Blocks"})})]}),u?t.jsxs("div",{className:"w-full space-y-3 py-4",children:[t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"}),t.jsx("div",{className:"w-full h-8 rounded bg-gray-300 animate-pulse"})]}):t.jsxs("div",{className:"py-4 space-y-3",children:[t.jsx(r.SheetHeader,{children:t.jsxs(r.SheetDescription,{className:"text-xs text-muted-foreground text-center text-light",children:["Manage your ",a==="pages"?"pages":"global blocks"]})}),t.jsx("div",{className:"w-full flex justify-center",children:t.jsxs(r.Button,{variant:"default",size:"sm",disabled:u,onClick:()=>l({slug:"",name:"",global:a==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[t.jsx(G.Plus,{className:"h-4 w-4 mr-2"}),u?"Loading...":`Add new ${a==="pages"?"page":"global block"}`]})}),t.jsx("div",{className:"pt-4",children:t.jsx("div",{className:"space-y-2",children:u?t.jsx("div",{className:"h-32 w-full flex justify-center items-center text-sm animate-pulse",children:"Loading..."}):m(E)})})]})]})]})},Vt=({editPage:s,showUpsertPage:o,setShowUpsertPage:l})=>{const a=o.id,[i,E]=k.useState(a&&o.name||""),[u,p]=k.useState(a&&o.slug||""),{mutate:d,isPending:m}=et(),{mutate:v,isPending:x}=Ce(),f=m||x,C=()=>{a?v({name:i,slug:u,id:o.id,global:!!o.global},{onSuccess:()=>{l(void 0)}}):d({name:i,slug:u,global:!!o.global},{onSuccess:O=>{s(O.id)}})};return t.jsx(r.Dialog,{open:!!o,onOpenChange:()=>l(void 0),children:t.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[t.jsxs(r.DialogHeader,{children:[t.jsxs(r.DialogTitle,{children:[a?"Edit":"Add New"," ",o.global?"Global Block":"Page"]}),t.jsxs(r.DialogDescription,{children:["Enter the details for the new"," ",o.global?"global block. Identifier should be unique.":"page. Slug must start with /"]})]}),t.jsxs("form",{children:[t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"name",className:"text-right",children:"Name"}),t.jsx(r.Input,{id:"name",value:i,placeholder:`Enter ${o.global?"global block":"page"} name`,onChange:O=>E(O.target.value),className:"col-span-3",required:!0})]}),!o.global&&t.jsxs("div",{className:"space-y-1",children:[t.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:o.global?"Identifier":"Slug"}),t.jsx(r.Input,{id:"slug",value:u,onChange:O=>{var T;return p((T=O.target.value)==null?void 0:T.trim().toLowerCase())},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),t.jsx(r.DialogFooter,{children:t.jsx(r.Button,{onClick:C,type:"button",disabled:f||!i||!o.global&&!u.startsWith("/")||g.isEqual(o.name,i)&&g.isEqual(o.slug,u),children:f?a?"Updating...":"Adding...":o.global?`${a?"Update":"Add"} global block`:`${a?"Update":"Add"} Page`})})]})]})})};function Wt(s){const{activePage:o,canClose:l,open:a,close:i}=s,[,E]=z(),[u,p]=k.useState(),d=m=>{window.history.pushState({},"",`?page=${m}`),E(new URLSearchParams({page:m})),window.dispatchEvent(new PopStateEvent("popstate")),p(void 0),i()};return t.jsx(r.Sheet,{open:a,onOpenChange:m=>{!m&&l&&i()},children:t.jsxs(r.SheetContent,{side:"left",className:`border-border w-full ${l?"":"sheet-hide-close-btn"}`,children:[t.jsx("div",{children:t.jsx(Kt,{onShowUpsertPage:m=>p(m),activePage:o,editPage:d})}),u&&t.jsx(Vt,{editPage:d,showUpsertPage:u,setShowUpsertPage:p})]})})}_t.loadWebBlocks();const zt=s=>{var ne;const[o]=z(),l=o.get("page"),{data:a,isFetching:i}=Xe(),{data:E}=Lt(),{data:u}=Ye(),{blocks:p,theme:d}=It(u),{data:m}=Ze(),{data:v}=Ee(),x=At(),{uploadFile:f}=Ut(),{getUILibraryBlock:C,getUILibraryBlocks:O,onSave:T}=Ft(),{getGlobalBlocks:B,getGlobalBlockBlocks:L}=Bt(),{mutate:j,isPending:ee}=Gt(),{aiContext:J,updateAiContext:ue}=He(),[de,te]=k.useState(!1),[K,ae]=k.useState("SAVED");k.useEffect(()=>{const A=R=>{K==="UNSAVED"&&(R.preventDefault(),R.returnValue=!1)};return K==="UNSAVED"&&window.addEventListener("beforeunload",A),()=>{window.removeEventListener("beforeunload",A)}},[K]);const he=k.useMemo(()=>{const A={};return m!=null&&m.theme&&(A.brandingOptions=m.theme),A},[m]);return t.jsxs(t.Fragment,{children:[t.jsx(Z.ChaiBuilderEditor,{fallbackLang:s.fallbackLang||"en",languages:g.map(v,"lang")||[],translations:s.translations||{},locale:s.locale||"en",htmlDir:s.htmlDir||"ltr",autoSaveSupport:s.autoSaveSupport||!1,autoSaveInterval:s.autoSaveInterval||15,uploadMediaCallback:f,onError:s.onError||console.error,getGlobalBlockBlocks:L,getGlobalBlocks:B,blocks:p,getUILibraryBlock:C,getUILibraryBlocks:O,brandingOptions:d,uiLibraries:E,saveAiContextCallback:async A=>(await ue({page:l,aiContext:A}),!0),onSaveStateChange:A=>ae(A),aiContext:J,askAiCallBack:x,onSave:async({blocks:A,themeConfiguration:R})=>{if(!l)return!0;const q={_type:"@chai/theme",_value:R},M={_type:"@chai/ai-context",_value:g.isString(J)?J:""},se=[...A,q,M];return await T({page:l,blocks:se}),!0},topBarComponents:{left:[()=>t.jsxs(r.Button,{variant:"default",className:"flex justify-start max-w-[250px] items-center w-full space-x-2 py-1",onClick:()=>te(!0),children:[g.includes(a.slug,"/")?t.jsx(G.File,{className:"h-4 w-4"}):t.jsx(G.GlobeIcon,{className:"h-4 w-4"}),t.jsx("span",{className:"truncate",children:(a==null?void 0:a.name)??""}),t.jsx(G.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[()=>t.jsxs(r.Button,{disabled:ee||K!=="SAVED",size:"sm",variant:"default",onClick:()=>j(l),children:[t.jsx(G.RocketIcon,{className:"h-4 w-4"})," "," ",ee?"Publishing...":"Publish"]})]},sideBarComponents:{top:[...g.includes(a.slug,"/")?[{label:"SEO Setting",component:at,icon:t.jsx(t.Fragment,{children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 21 21",fill:"currentColor",width:"21",height:"21",children:[t.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"}),t.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"})]})})}]:[],...(ne=s.languages)!=null&&ne.length&&g.includes(a.slug,"/")?[{label:"Language Pages",component:$t,icon:t.jsx(t.Fragment,{children:t.jsx("svg",{width:"21",height:"21",viewBox:"0 0 21 21",fill:"currentColor",children:t.jsxs("g",{fill:"none","fill-rule":"evenodd",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round",children:[t.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"}),t.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"}),t.jsx("path",{d:"M7.5 12.503h-3M9 14l-1 1q-.5.5-2.5 1.5"}),t.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"})]})})})}]:[]]},...he}),t.jsx(Wt,{activePage:l||"",canClose:!!l&&!g.isEmpty(a),open:!l||!i&&g.isEmpty(a)||de,close:()=>te(!1)})]})},Qe=new _.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),Jt=s=>(Qe.setQueryData(["builder_props"],s),t.jsx(_.QueryClientProvider,{client:Qe,children:t.jsx(zt,{...s})}));module.exports=Jt;
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { loadWebBlocks as ua } from "@chaibuilder/sdk/web-blocks";
|
|
|
3
3
|
import { getBlocksFromHTML as da, useLanguages as Be, ChaiBuilderEditor as ha } from "@chaibuilder/sdk";
|
|
4
4
|
import { useQueryClient as J, useQuery as ne, useMutation as re, QueryClient as fa, QueryClientProvider as pa } from "@tanstack/react-query";
|
|
5
5
|
import { useToast as Y, Accordion as ga, AccordionItem as ge, AccordionTrigger as me, AccordionContent as ve, Label as _, Input as U, Textarea as xe, Button as B, Popover as gt, PopoverTrigger as mt, PopoverContent as vt, Dialog as xt, DialogContent as bt, DialogHeader as yt, DialogTitle as jt, DialogDescription as wt, DialogFooter as St, Tabs as ma, TabsList as va, TabsTrigger as ut, SheetHeader as xa, SheetDescription as ba, Sheet as ya, SheetContent as ja } from "@chaibuilder/sdk/ui";
|
|
6
|
-
import { StarIcon as wa, PencilIcon as Et, TrashIcon as Ct, Plus as Sa, GlobeIcon as Nt, File as
|
|
7
|
-
import { get as q, find as se, isString as Ae, filter as ae, isEmpty as z, includes as be, startCase as Na, reverse as
|
|
6
|
+
import { StarIcon as wa, PencilIcon as Et, TrashIcon as Ct, Plus as Sa, GlobeIcon as Nt, File as Tt, ArrowLeftRightIcon as Ea, RocketIcon as Ca } from "lucide-react";
|
|
7
|
+
import { get as q, find as se, isString as Ae, filter as ae, isEmpty as z, includes as be, startCase as Na, reverse as Ta, sortBy as ka, isEqual as Fe, map as Ue, toLower as Pa, trim as _a, orderBy as Oa } from "lodash-es";
|
|
8
8
|
var Le = { exports: {} }, ee = {};
|
|
9
9
|
/**
|
|
10
10
|
* @license React
|
|
@@ -42,11 +42,11 @@ var te = {};
|
|
|
42
42
|
var ht;
|
|
43
43
|
function Da() {
|
|
44
44
|
return ht || (ht = 1, process.env.NODE_ENV !== "production" && function() {
|
|
45
|
-
var r = pt, i = Symbol.for("react.element"), o = Symbol.for("react.portal"), a = Symbol.for("react.fragment"), s = Symbol.for("react.strict_mode"), w = Symbol.for("react.profiler"), c = Symbol.for("react.provider"), f = Symbol.for("react.context"), u = Symbol.for("react.forward_ref"), p = Symbol.for("react.suspense"), g = Symbol.for("react.suspense_list"), m = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), S = Symbol.for("react.offscreen"),
|
|
45
|
+
var r = pt, i = Symbol.for("react.element"), o = Symbol.for("react.portal"), a = Symbol.for("react.fragment"), s = Symbol.for("react.strict_mode"), w = Symbol.for("react.profiler"), c = Symbol.for("react.provider"), f = Symbol.for("react.context"), u = Symbol.for("react.forward_ref"), p = Symbol.for("react.suspense"), g = Symbol.for("react.suspense_list"), m = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), S = Symbol.for("react.offscreen"), T = Symbol.iterator, E = "@@iterator";
|
|
46
46
|
function F(e) {
|
|
47
47
|
if (e === null || typeof e != "object")
|
|
48
48
|
return null;
|
|
49
|
-
var n =
|
|
49
|
+
var n = T && e[T] || e[E];
|
|
50
50
|
return typeof n == "function" ? n : null;
|
|
51
51
|
}
|
|
52
52
|
var D = r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
@@ -86,7 +86,7 @@ function Da() {
|
|
|
86
86
|
function O(e) {
|
|
87
87
|
return e.displayName || "Context";
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function k(e) {
|
|
90
90
|
if (e == null)
|
|
91
91
|
return null;
|
|
92
92
|
if (typeof e.tag == "number" && b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
|
|
@@ -119,11 +119,11 @@ function Da() {
|
|
|
119
119
|
return ce(e, e.render, "ForwardRef");
|
|
120
120
|
case m:
|
|
121
121
|
var d = e.displayName || null;
|
|
122
|
-
return d !== null ? d :
|
|
122
|
+
return d !== null ? d : k(e.type) || "Memo";
|
|
123
123
|
case h: {
|
|
124
124
|
var y = e, j = y._payload, x = y._init;
|
|
125
125
|
try {
|
|
126
|
-
return
|
|
126
|
+
return k(x(j));
|
|
127
127
|
} catch {
|
|
128
128
|
return null;
|
|
129
129
|
}
|
|
@@ -207,13 +207,13 @@ function Da() {
|
|
|
207
207
|
` + Ne + e;
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
var
|
|
210
|
+
var Te = !1, he;
|
|
211
211
|
{
|
|
212
212
|
var It = typeof WeakMap == "function" ? WeakMap : Map;
|
|
213
213
|
he = new It();
|
|
214
214
|
}
|
|
215
215
|
function He(e, n) {
|
|
216
|
-
if (!e ||
|
|
216
|
+
if (!e || Te)
|
|
217
217
|
return "";
|
|
218
218
|
{
|
|
219
219
|
var l = he.get(e);
|
|
@@ -221,7 +221,7 @@ function Da() {
|
|
|
221
221
|
return l;
|
|
222
222
|
}
|
|
223
223
|
var d;
|
|
224
|
-
|
|
224
|
+
Te = !0;
|
|
225
225
|
var y = Error.prepareStackTrace;
|
|
226
226
|
Error.prepareStackTrace = void 0;
|
|
227
227
|
var j;
|
|
@@ -278,7 +278,7 @@ function Da() {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
} finally {
|
|
281
|
-
|
|
281
|
+
Te = !1, Ce.current = j, Lt(), Error.prepareStackTrace = y;
|
|
282
282
|
}
|
|
283
283
|
var W = e ? e.displayName || e.name : "", $ = W ? de(W) : "";
|
|
284
284
|
return typeof e == "function" && he.set(e, $), $;
|
|
@@ -347,7 +347,7 @@ function Da() {
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
var qt = Array.isArray;
|
|
350
|
-
function
|
|
350
|
+
function ke(e) {
|
|
351
351
|
return qt(e);
|
|
352
352
|
}
|
|
353
353
|
function Mt(e) {
|
|
@@ -395,8 +395,8 @@ function Da() {
|
|
|
395
395
|
}
|
|
396
396
|
function zt(e, n) {
|
|
397
397
|
if (typeof e.ref == "string" && Z.current && n && Z.current.stateNode !== n) {
|
|
398
|
-
var l =
|
|
399
|
-
Pe[l] || (b('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',
|
|
398
|
+
var l = k(Z.current.type);
|
|
399
|
+
Pe[l] || (b('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', k(Z.current.type), e.ref), Pe[l] = !0);
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
function Jt(e, n) {
|
|
@@ -484,7 +484,7 @@ function Da() {
|
|
|
484
484
|
function rt() {
|
|
485
485
|
{
|
|
486
486
|
if (_e.current) {
|
|
487
|
-
var e =
|
|
487
|
+
var e = k(_e.current.type);
|
|
488
488
|
if (e)
|
|
489
489
|
return `
|
|
490
490
|
|
|
@@ -519,14 +519,14 @@ Check the top-level render call using <` + l + ">.");
|
|
|
519
519
|
return;
|
|
520
520
|
st[l] = !0;
|
|
521
521
|
var d = "";
|
|
522
|
-
e && e._owner && e._owner !== _e.current && (d = " It was passed a child from " +
|
|
522
|
+
e && e._owner && e._owner !== _e.current && (d = " It was passed a child from " + k(e._owner.type) + "."), V(e), b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', l, d), V(null);
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
function ot(e, n) {
|
|
526
526
|
{
|
|
527
527
|
if (typeof e != "object")
|
|
528
528
|
return;
|
|
529
|
-
if (
|
|
529
|
+
if (ke(e))
|
|
530
530
|
for (var l = 0; l < e.length; l++) {
|
|
531
531
|
var d = e[l];
|
|
532
532
|
Re(d) && it(d, n);
|
|
@@ -556,11 +556,11 @@ Check the top-level render call using <` + l + ">.");
|
|
|
556
556
|
else
|
|
557
557
|
return;
|
|
558
558
|
if (l) {
|
|
559
|
-
var d =
|
|
559
|
+
var d = k(n);
|
|
560
560
|
Gt(l, e.props, "prop", d, e);
|
|
561
561
|
} else if (n.PropTypes !== void 0 && !Oe) {
|
|
562
562
|
Oe = !0;
|
|
563
|
-
var y =
|
|
563
|
+
var y = k(n);
|
|
564
564
|
b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", y || "Unknown");
|
|
565
565
|
}
|
|
566
566
|
typeof n.getDefaultProps == "function" && !n.getDefaultProps.isReactClassApproved && b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
|
|
@@ -588,7 +588,7 @@ Check the top-level render call using <` + l + ">.");
|
|
|
588
588
|
var P = Xt();
|
|
589
589
|
P ? v += P : v += rt();
|
|
590
590
|
var C;
|
|
591
|
-
e === null ? C = "null" :
|
|
591
|
+
e === null ? C = "null" : ke(e) ? C = "array" : e !== void 0 && e.$$typeof === i ? (C = "<" + (k(e.type) || "Unknown") + " />", v = " Did you accidentally export a JSX literal instead of a component?") : C = typeof e, b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", C, v);
|
|
592
592
|
}
|
|
593
593
|
var N = Qt(e, n, l, y, j);
|
|
594
594
|
if (N == null)
|
|
@@ -597,7 +597,7 @@ Check the top-level render call using <` + l + ">.");
|
|
|
597
597
|
var L = n.children;
|
|
598
598
|
if (L !== void 0)
|
|
599
599
|
if (d)
|
|
600
|
-
if (
|
|
600
|
+
if (ke(L)) {
|
|
601
601
|
for (var W = 0; W < L.length; W++)
|
|
602
602
|
ot(L[W], e);
|
|
603
603
|
Object.freeze && Object.freeze(L);
|
|
@@ -607,7 +607,7 @@ Check the top-level render call using <` + l + ">.");
|
|
|
607
607
|
ot(L, e);
|
|
608
608
|
}
|
|
609
609
|
if (X.call(n, "key")) {
|
|
610
|
-
var $ =
|
|
610
|
+
var $ = k(e), R = Object.keys(n).filter(function(oa) {
|
|
611
611
|
return oa !== "key";
|
|
612
612
|
}), De = R.length > 0 ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
613
613
|
if (!lt[$ + De]) {
|
|
@@ -652,7 +652,7 @@ function H() {
|
|
|
652
652
|
};
|
|
653
653
|
}, []), [r, i];
|
|
654
654
|
}
|
|
655
|
-
const
|
|
655
|
+
const kt = () => {
|
|
656
656
|
const [r] = H(), i = r.get("page"), o = A();
|
|
657
657
|
return ne({
|
|
658
658
|
queryKey: ["page", i],
|
|
@@ -668,7 +668,7 @@ const Tt = () => {
|
|
|
668
668
|
enabled: !!i
|
|
669
669
|
});
|
|
670
670
|
}, Pt = () => {
|
|
671
|
-
const r = A(), i = J(), { toast: o } = Y(), { data: a } =
|
|
671
|
+
const r = A(), i = J(), { toast: o } = Y(), { data: a } = kt(), [s] = H(), w = s.get("page"), c = q(
|
|
672
672
|
se(a, { _type: "@chai/ai-context" }),
|
|
673
673
|
"_value",
|
|
674
674
|
""
|
|
@@ -770,7 +770,7 @@ const Tt = () => {
|
|
|
770
770
|
const r = A();
|
|
771
771
|
return ne({
|
|
772
772
|
queryKey: ["project-pages"],
|
|
773
|
-
|
|
773
|
+
staleTime: 1e3 * 60 * 5,
|
|
774
774
|
queryFn: async () => await (await fetch(r, {
|
|
775
775
|
method: "POST",
|
|
776
776
|
headers: {
|
|
@@ -831,7 +831,7 @@ const Tt = () => {
|
|
|
831
831
|
return {
|
|
832
832
|
getGlobalBlocks: async () => {
|
|
833
833
|
const o = {};
|
|
834
|
-
for (const a of r)
|
|
834
|
+
for (const a of r ?? [])
|
|
835
835
|
z(a == null ? void 0 : a.slug) && (o[a.id] = {
|
|
836
836
|
name: Na(a.name ?? a.slug),
|
|
837
837
|
description: ""
|
|
@@ -889,7 +889,7 @@ const Tt = () => {
|
|
|
889
889
|
data: { id: o }
|
|
890
890
|
})
|
|
891
891
|
})).json();
|
|
892
|
-
return ka(
|
|
892
|
+
return Ta(ka(s, "primaryPage"));
|
|
893
893
|
}
|
|
894
894
|
});
|
|
895
895
|
}, ye = {
|
|
@@ -1208,7 +1208,7 @@ const Tt = () => {
|
|
|
1208
1208
|
ogTitle: a.seoTitle,
|
|
1209
1209
|
ogDescription: a.seoDescription
|
|
1210
1210
|
});
|
|
1211
|
-
},
|
|
1211
|
+
}, T = () => {
|
|
1212
1212
|
s({
|
|
1213
1213
|
...a,
|
|
1214
1214
|
searchTitle: a.ogTitle,
|
|
@@ -1383,7 +1383,7 @@ const Tt = () => {
|
|
|
1383
1383
|
type: "button",
|
|
1384
1384
|
variant: "outline",
|
|
1385
1385
|
size: "sm",
|
|
1386
|
-
onClick:
|
|
1386
|
+
onClick: T,
|
|
1387
1387
|
children: "Copy from OG Settings"
|
|
1388
1388
|
}
|
|
1389
1389
|
) }),
|
|
@@ -1452,7 +1452,7 @@ const $a = ({
|
|
|
1452
1452
|
onClose: i,
|
|
1453
1453
|
languagePages: o
|
|
1454
1454
|
}) => {
|
|
1455
|
-
const { data: a } = _t(), [s, w] = I(r.edit ? r.name : ""), [c, f] = I(r.edit ? r.lang : ""), [u, p] = I(r.edit ? r.slug : ""), { mutate: g, isPending: m } = Rt(), { mutate: h, isPending: S } = Me(),
|
|
1455
|
+
const { data: a } = _t(), [s, w] = I(r.edit ? r.name : ""), [c, f] = I(r.edit ? r.lang : ""), [u, p] = I(r.edit ? r.slug : ""), { mutate: g, isPending: m } = Rt(), { mutate: h, isPending: S } = Me(), T = m || S, { data: E } = Ot(), F = ae(
|
|
1456
1456
|
q(E, "languages") || ["en"],
|
|
1457
1457
|
(b) => !se(o, { lang: b }) && b !== q(E, "fallbackLang")
|
|
1458
1458
|
), D = () => {
|
|
@@ -1538,8 +1538,8 @@ const $a = ({
|
|
|
1538
1538
|
{
|
|
1539
1539
|
onClick: D,
|
|
1540
1540
|
type: "button",
|
|
1541
|
-
disabled:
|
|
1542
|
-
children:
|
|
1541
|
+
disabled: T || !c || !u || !u.startsWith("/"),
|
|
1542
|
+
children: T ? r.edit ? "Updating..." : "Adding..." : r.edit ? "Update" : "Add new language"
|
|
1543
1543
|
}
|
|
1544
1544
|
) })
|
|
1545
1545
|
] })
|
|
@@ -1554,12 +1554,12 @@ const $a = ({
|
|
|
1554
1554
|
/* @__PURE__ */ t.jsx("div", { className: "w-full h-8 rounded bg-gray-300 animate-pulse" })
|
|
1555
1555
|
] }),
|
|
1556
1556
|
Ue(c, (g) => {
|
|
1557
|
-
const m = g.lang, h = g.slug, S = !g.primaryPage,
|
|
1557
|
+
const m = g.lang, h = g.slug, S = !g.primaryPage, T = m === o;
|
|
1558
1558
|
return S ? null : /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
|
|
1559
1559
|
/* @__PURE__ */ t.jsxs(
|
|
1560
1560
|
"li",
|
|
1561
1561
|
{
|
|
1562
|
-
className: `w-full p-2 rounded cursor-pointer flex items-center justify-between ${
|
|
1562
|
+
className: `w-full p-2 rounded cursor-pointer flex items-center justify-between ${T ? "bg-gray-200" : "hover:bg-gray-100"}`,
|
|
1563
1563
|
onClick: () => s(m),
|
|
1564
1564
|
children: [
|
|
1565
1565
|
/* @__PURE__ */ t.jsxs("div", { className: " flex-1 gap-x-3", children: [
|
|
@@ -1660,7 +1660,7 @@ const $a = ({
|
|
|
1660
1660
|
className: "flex justify-between items-center w-full space-x-2 py-1",
|
|
1661
1661
|
children: [
|
|
1662
1662
|
/* @__PURE__ */ t.jsxs("div", { className: "flex items-center space-x-2", children: [
|
|
1663
|
-
h.global ? /* @__PURE__ */ t.jsx(Nt, { className: "h-4 w-4" }) : /* @__PURE__ */ t.jsx(
|
|
1663
|
+
h.global ? /* @__PURE__ */ t.jsx(Nt, { className: "h-4 w-4" }) : /* @__PURE__ */ t.jsx(Tt, { className: "h-4 w-4" }),
|
|
1664
1664
|
/* @__PURE__ */ t.jsx("span", { children: h.name ?? h.slug }),
|
|
1665
1665
|
(h == null ? void 0 : h.slug) && /* @__PURE__ */ t.jsxs("span", { className: "text-xs font-light", children: [
|
|
1666
1666
|
"( ",
|
|
@@ -1770,8 +1770,8 @@ const $a = ({
|
|
|
1770
1770
|
global: !!i.global
|
|
1771
1771
|
},
|
|
1772
1772
|
{
|
|
1773
|
-
onSuccess: (
|
|
1774
|
-
r(
|
|
1773
|
+
onSuccess: (T) => {
|
|
1774
|
+
r(T.id);
|
|
1775
1775
|
}
|
|
1776
1776
|
}
|
|
1777
1777
|
);
|
|
@@ -1804,7 +1804,7 @@ const $a = ({
|
|
|
1804
1804
|
id: "name",
|
|
1805
1805
|
value: s,
|
|
1806
1806
|
placeholder: `Enter ${i.global ? "global block" : "page"} name`,
|
|
1807
|
-
onChange: (
|
|
1807
|
+
onChange: (T) => w(T.target.value),
|
|
1808
1808
|
className: "col-span-3",
|
|
1809
1809
|
required: !0
|
|
1810
1810
|
}
|
|
@@ -1817,9 +1817,9 @@ const $a = ({
|
|
|
1817
1817
|
{
|
|
1818
1818
|
id: "slug",
|
|
1819
1819
|
value: c,
|
|
1820
|
-
onChange: (
|
|
1820
|
+
onChange: (T) => {
|
|
1821
1821
|
var E;
|
|
1822
|
-
return f((E =
|
|
1822
|
+
return f((E = T.target.value) == null ? void 0 : E.trim().toLowerCase());
|
|
1823
1823
|
},
|
|
1824
1824
|
className: "col-span-3",
|
|
1825
1825
|
required: !0,
|
|
@@ -1886,10 +1886,10 @@ function za(r) {
|
|
|
1886
1886
|
ua();
|
|
1887
1887
|
const Ja = (r) => {
|
|
1888
1888
|
var ce;
|
|
1889
|
-
const [i] = H(), o = i.get("page"), { data: a, isFetching: s } = _t(), { data: w } = Ia(), { data: c } =
|
|
1889
|
+
const [i] = H(), o = i.get("page"), { data: a, isFetching: s } = _t(), { data: w } = Ia(), { data: c } = kt(), { blocks: f, theme: u } = Ba(c), { data: p } = Ot(), { data: g } = qe(), m = Fa(), { uploadFile: h } = Ga(), { getUILibraryBlock: S, getUILibraryBlocks: T, onSave: E } = La(), { getGlobalBlocks: F, getGlobalBlockBlocks: D } = Ua(), { mutate: b, isPending: ie } = qa(), { aiContext: Q, updateAiContext: we } = Pt(), [Se, oe] = I(!1), [K, le] = I("SAVED");
|
|
1890
1890
|
Ie(() => {
|
|
1891
|
-
const O = (
|
|
1892
|
-
K === "UNSAVED" && (
|
|
1891
|
+
const O = (k) => {
|
|
1892
|
+
K === "UNSAVED" && (k.preventDefault(), k.returnValue = !1);
|
|
1893
1893
|
};
|
|
1894
1894
|
return K === "UNSAVED" && window.addEventListener("beforeunload", O), () => {
|
|
1895
1895
|
window.removeEventListener("beforeunload", O);
|
|
@@ -1916,18 +1916,18 @@ const Ja = (r) => {
|
|
|
1916
1916
|
getGlobalBlocks: F,
|
|
1917
1917
|
blocks: f,
|
|
1918
1918
|
getUILibraryBlock: S,
|
|
1919
|
-
getUILibraryBlocks:
|
|
1919
|
+
getUILibraryBlocks: T,
|
|
1920
1920
|
brandingOptions: u,
|
|
1921
1921
|
uiLibraries: w,
|
|
1922
1922
|
saveAiContextCallback: async (O) => (await we({ page: o, aiContext: O }), !0),
|
|
1923
1923
|
onSaveStateChange: (O) => le(O),
|
|
1924
1924
|
aiContext: Q,
|
|
1925
1925
|
askAiCallBack: m,
|
|
1926
|
-
onSave: async ({ blocks: O, themeConfiguration:
|
|
1926
|
+
onSave: async ({ blocks: O, themeConfiguration: k }) => {
|
|
1927
1927
|
if (!o) return !0;
|
|
1928
1928
|
const G = {
|
|
1929
1929
|
_type: "@chai/theme",
|
|
1930
|
-
_value:
|
|
1930
|
+
_value: k
|
|
1931
1931
|
}, M = {
|
|
1932
1932
|
_type: "@chai/ai-context",
|
|
1933
1933
|
_value: Ae(Q) ? Q : ""
|
|
@@ -1943,7 +1943,7 @@ const Ja = (r) => {
|
|
|
1943
1943
|
className: "flex justify-start max-w-[250px] items-center w-full space-x-2 py-1",
|
|
1944
1944
|
onClick: () => oe(!0),
|
|
1945
1945
|
children: [
|
|
1946
|
-
be(a.slug, "/") ? /* @__PURE__ */ t.jsx(
|
|
1946
|
+
be(a.slug, "/") ? /* @__PURE__ */ t.jsx(Tt, { className: "h-4 w-4" }) : /* @__PURE__ */ t.jsx(Nt, { className: "h-4 w-4" }),
|
|
1947
1947
|
/* @__PURE__ */ t.jsx("span", { className: "truncate", children: (a == null ? void 0 : a.name) ?? "" }),
|
|
1948
1948
|
/* @__PURE__ */ t.jsx(Ea, { className: "h-4 w-4" })
|
|
1949
1949
|
]
|
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n="https://api.chaibuilder.com",o=async(s,e)=>{try{const a=new Headers;a.append("x-chai-api-key",e);const r={headers:a,method:"POST",body:JSON.stringify(s)},t=await fetch(n+"/v1/api/chai",r);if(t.ok)return{data:await t.json()};throw new Error("Failed to handle request: "+t.statusText)}catch(a){return{error:a}}},i="https://api.chaibuilder.com";class c{constructor(e){this.apiKey=e}async handle(e){return await o(e,this.apiKey)}async getPageId(e){return(await fetch(`${i}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE_ID",data:{slug:e,published:!0}}),headers:{"x-chai-api-key":this.apiKey}})).json()}async getPage(e){return(await fetch(`${i}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE",data:{id:e,published:!0,mergeGlobal:!0}}),headers:{"x-chai-api-key":this.apiKey}})).json()}}exports.ChaiBuilderPages=c;
|
package/dist/server.js
CHANGED
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
const
|
|
1
|
+
const n = "https://api.chaibuilder.com", o = async (s, e) => {
|
|
2
2
|
try {
|
|
3
3
|
const a = new Headers();
|
|
4
|
-
a.append("x-chai-api-key",
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
p + "/v1/api/chai",
|
|
4
|
+
a.append("x-chai-api-key", e);
|
|
5
|
+
const r = {
|
|
6
|
+
headers: a,
|
|
7
|
+
method: "POST",
|
|
8
|
+
body: JSON.stringify(s)
|
|
9
|
+
}, t = await fetch(
|
|
10
|
+
n + "/v1/api/chai",
|
|
12
11
|
r
|
|
13
12
|
);
|
|
14
|
-
if (
|
|
15
|
-
return { data: await
|
|
16
|
-
throw new Error("Failed to handle request: " +
|
|
13
|
+
if (t.ok)
|
|
14
|
+
return { data: await t.json() };
|
|
15
|
+
throw new Error("Failed to handle request: " + t.statusText);
|
|
17
16
|
} catch (a) {
|
|
18
17
|
return { error: a };
|
|
19
18
|
}
|
|
20
|
-
},
|
|
21
|
-
class
|
|
22
|
-
constructor(
|
|
23
|
-
this.apiKey =
|
|
19
|
+
}, i = "https://api.chaibuilder.com";
|
|
20
|
+
class h {
|
|
21
|
+
constructor(e) {
|
|
22
|
+
this.apiKey = e;
|
|
24
23
|
}
|
|
25
|
-
async handle(
|
|
26
|
-
return await
|
|
24
|
+
async handle(e) {
|
|
25
|
+
return await o(e, this.apiKey);
|
|
27
26
|
}
|
|
28
|
-
async getPageId(
|
|
29
|
-
|
|
30
|
-
return a.append("action", "GET_PAGE_ID"), a.append("data", JSON.stringify({ slug: t, published: !0 })), (await fetch(`${o}/v1/api/chai`, {
|
|
27
|
+
async getPageId(e) {
|
|
28
|
+
return (await fetch(`${i}/v1/api/chai`, {
|
|
31
29
|
method: "POST",
|
|
32
|
-
body:
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
action: "GET_PAGE_ID",
|
|
32
|
+
data: { slug: e, published: !0 }
|
|
33
|
+
}),
|
|
33
34
|
headers: { "x-chai-api-key": this.apiKey }
|
|
34
35
|
})).json();
|
|
35
36
|
}
|
|
36
|
-
async getPage(
|
|
37
|
-
|
|
38
|
-
return a.append("action", "GET_PAGE"), a.append("data", JSON.stringify({ id: t, published: !0 })), (await fetch(`${o}/v1/api/chai`, {
|
|
37
|
+
async getPage(e) {
|
|
38
|
+
return (await fetch(`${i}/v1/api/chai`, {
|
|
39
39
|
method: "POST",
|
|
40
|
-
body:
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
action: "GET_PAGE",
|
|
42
|
+
data: { id: e, published: !0, mergeGlobal: !0 }
|
|
43
|
+
}),
|
|
41
44
|
headers: { "x-chai-api-key": this.apiKey }
|
|
42
45
|
})).json();
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
export {
|
|
46
|
-
|
|
49
|
+
h as ChaiBuilderPages
|
|
47
50
|
};
|