@chaibuilder/pages 0.1.0-beta.32 → 0.1.0-beta.33
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 +10 -10
- package/dist/index.js +843 -946
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +46 -47
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const j=require("react"),
|
|
1
|
+
"use strict";const j=require("react"),Rt=require("@chaibuilder/sdk/web-blocks"),Y=require("@chaibuilder/sdk"),_=require("@tanstack/react-query"),s=require("@chaibuilder/sdk/ui"),L=require("lucide-react"),c=require("lodash-es");var Ee={exports:{}},te={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Ye;function Ft(){if(Ye)return te;Ye=1;var a=j,r=Symbol.for("react.element"),o=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,g={key:!0,ref:!0,__self:!0,__source:!0};function d(f,m,N){var y,D={},b=null,T=null;N!==void 0&&(b=""+N),m.key!==void 0&&(b=""+m.key),m.ref!==void 0&&(T=m.ref);for(y in m)n.call(m,y)&&!g.hasOwnProperty(y)&&(D[y]=m[y]);if(f&&f.defaultProps)for(y in m=f.defaultProps,m)D[y]===void 0&&(D[y]=m[y]);return{$$typeof:r,type:f,key:b,ref:T,props:D,_owner:i.current}}return te.Fragment=o,te.jsx=d,te.jsxs=d,te}var ae={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var He;function Lt(){return He||(He=1,process.env.NODE_ENV!=="production"&&function(){var a=j,r=Symbol.for("react.element"),o=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),d=Symbol.for("react.provider"),f=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),y=Symbol.for("react.suspense_list"),D=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),T=Symbol.for("react.offscreen"),w=Symbol.iterator,x="@@iterator";function v(t){if(t===null||typeof t!="object")return null;var l=w&&t[w]||t[x];return typeof l=="function"?l:null}var h=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function C(t){{for(var l=arguments.length,u=new Array(l>1?l-1:0),p=1;p<l;p++)u[p-1]=arguments[p];J("error",t,u)}}function J(t,l,u){{var p=h.ReactDebugCurrentFrame,S=p.getStackAddendum();S!==""&&(l+="%s",u=u.concat([S]));var P=u.map(function(E){return String(E)});P.unshift("Warning: "+l),Function.prototype.apply.call(console[t],console,P)}}var fe=!1,se=!1,me=!1,re=!1,ge=!1,X;X=Symbol.for("react.module.reference");function z(t){return!!(typeof t=="string"||typeof t=="function"||t===n||t===g||ge||t===i||t===N||t===y||re||t===T||fe||se||me||typeof t=="object"&&t!==null&&(t.$$typeof===b||t.$$typeof===D||t.$$typeof===d||t.$$typeof===f||t.$$typeof===m||t.$$typeof===X||t.getModuleId!==void 0))}function xe(t,l,u){var p=t.displayName;if(p)return p;var S=l.displayName||l.name||"";return S!==""?u+"("+S+")":u}function ie(t){return t.displayName||"Context"}function U(t){if(t==null)return null;if(typeof t.tag=="number"&&C("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case n:return"Fragment";case o:return"Portal";case g:return"Profiler";case i:return"StrictMode";case N:return"Suspense";case y:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case f:var l=t;return ie(l)+".Consumer";case d:var u=t;return ie(u._context)+".Provider";case m:return xe(t,t.render,"ForwardRef");case D:var p=t.displayName||null;return p!==null?p:U(t.type)||"Memo";case b:{var S=t,P=S._payload,E=S._init;try{return U(E(P))}catch{return null}}}return null}var $=Object.assign,A=0,q,V,le,De,Ae,_e,Re;function Fe(){}Fe.__reactDisabledLog=!0;function it(){{if(A===0){q=console.log,V=console.info,le=console.warn,De=console.error,Ae=console.group,_e=console.groupCollapsed,Re=console.groupEnd;var t={configurable:!0,enumerable:!0,value:Fe,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}A++}}function lt(){{if(A--,A===0){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:$({},t,{value:q}),info:$({},t,{value:V}),warn:$({},t,{value:le}),error:$({},t,{value:De}),group:$({},t,{value:Ae}),groupCollapsed:$({},t,{value:_e}),groupEnd:$({},t,{value:Re})})}A<0&&C("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var pe=h.ReactCurrentDispatcher,ve;function oe(t,l,u){{if(ve===void 0)try{throw Error()}catch(S){var p=S.stack.trim().match(/\n( *(at )?)/);ve=p&&p[1]||""}return`
|
|
18
|
+
`+ve+t}}var be=!1,ce;{var ot=typeof WeakMap=="function"?WeakMap:Map;ce=new ot}function Le(t,l){if(!t||be)return"";{var u=ce.get(t);if(u!==void 0)return u}var p;be=!0;var S=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var P;P=pe.current,pe.current=null,it();try{if(l){var E=function(){throw Error()};if(Object.defineProperty(E.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(E,[])}catch(G){p=G}Reflect.construct(t,[],E)}else{try{E.call()}catch(G){p=G}t.call(E.prototype)}}else{try{throw Error()}catch(G){p=G}t()}}catch(G){if(G&&p&&typeof G.stack=="string"){for(var k=G.stack.split(`
|
|
19
|
+
`),O=p.stack.split(`
|
|
20
|
+
`),R=k.length-1,F=O.length-1;R>=1&&F>=0&&k[R]!==O[F];)F--;for(;R>=1&&F>=0;R--,F--)if(k[R]!==O[F]){if(R!==1||F!==1)do if(R--,F--,F<0||k[R]!==O[F]){var M=`
|
|
21
|
+
`+k[R].replace(" at new "," at ");return t.displayName&&M.includes("<anonymous>")&&(M=M.replace("<anonymous>",t.displayName)),typeof t=="function"&&ce.set(t,M),M}while(R>=1&&F>=0);break}}}finally{be=!1,pe.current=P,lt(),Error.prepareStackTrace=S}var Q=t?t.displayName||t.name:"",K=Q?oe(Q):"";return typeof t=="function"&&ce.set(t,K),K}function ct(t,l,u){return Le(t,!1)}function ut(t){var l=t.prototype;return!!(l&&l.isReactComponent)}function ue(t,l,u){if(t==null)return"";if(typeof t=="function")return Le(t,ut(t));if(typeof t=="string")return oe(t);switch(t){case N:return oe("Suspense");case y:return oe("SuspenseList")}if(typeof t=="object")switch(t.$$typeof){case m:return ct(t.render);case D:return ue(t.type,l,u);case b:{var p=t,S=p._payload,P=p._init;try{return ue(P(S),l,u)}catch{}}}return""}var Z=Object.prototype.hasOwnProperty,Oe={},Ie=h.ReactDebugCurrentFrame;function de(t){if(t){var l=t._owner,u=ue(t.type,t._source,l?l.type:null);Ie.setExtraStackFrame(u)}else Ie.setExtraStackFrame(null)}function dt(t,l,u,p,S){{var P=Function.call.bind(Z);for(var E in t)if(P(t,E)){var k=void 0;try{if(typeof t[E]!="function"){var O=Error((p||"React class")+": "+u+" type `"+E+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[E]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw O.name="Invariant Violation",O}k=t[E](l,E,p,u,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(R){k=R}k&&!(k instanceof Error)&&(de(S),C("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",p||"React class",u,E,typeof k),de(null)),k instanceof Error&&!(k.message in Oe)&&(Oe[k.message]=!0,de(S),C("Failed %s type: %s",u,k.message),de(null))}}}var ht=Array.isArray;function ye(t){return ht(t)}function ft(t){{var l=typeof Symbol=="function"&&Symbol.toStringTag,u=l&&t[Symbol.toStringTag]||t.constructor.name||"Object";return u}}function mt(t){try{return Be(t),!1}catch{return!0}}function Be(t){return""+t}function Ge(t){if(mt(t))return C("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ft(t)),Be(t)}var ee=h.ReactCurrentOwner,gt={key:!0,ref:!0,__self:!0,__source:!0},Ue,Me,je;je={};function xt(t){if(Z.call(t,"ref")){var l=Object.getOwnPropertyDescriptor(t,"ref").get;if(l&&l.isReactWarning)return!1}return t.ref!==void 0}function pt(t){if(Z.call(t,"key")){var l=Object.getOwnPropertyDescriptor(t,"key").get;if(l&&l.isReactWarning)return!1}return t.key!==void 0}function vt(t,l){if(typeof t.ref=="string"&&ee.current&&l&&ee.current.stateNode!==l){var u=U(ee.current.type);je[u]||(C('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',U(ee.current.type),t.ref),je[u]=!0)}}function bt(t,l){{var u=function(){Ue||(Ue=!0,C("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",l))};u.isReactWarning=!0,Object.defineProperty(t,"key",{get:u,configurable:!0})}}function yt(t,l){{var u=function(){Me||(Me=!0,C("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",l))};u.isReactWarning=!0,Object.defineProperty(t,"ref",{get:u,configurable:!0})}}var jt=function(t,l,u,p,S,P,E){var k={$$typeof:r,type:t,key:l,ref:u,props:E,_owner:P};return k._store={},Object.defineProperty(k._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(k,"_self",{configurable:!1,enumerable:!1,writable:!1,value:p}),Object.defineProperty(k,"_source",{configurable:!1,enumerable:!1,writable:!1,value:S}),Object.freeze&&(Object.freeze(k.props),Object.freeze(k)),k};function wt(t,l,u,p,S){{var P,E={},k=null,O=null;u!==void 0&&(Ge(u),k=""+u),pt(l)&&(Ge(l.key),k=""+l.key),xt(l)&&(O=l.ref,vt(l,S));for(P in l)Z.call(l,P)&&!gt.hasOwnProperty(P)&&(E[P]=l[P]);if(t&&t.defaultProps){var R=t.defaultProps;for(P in R)E[P]===void 0&&(E[P]=R[P])}if(k||O){var F=typeof t=="function"?t.displayName||t.name||"Unknown":t;k&&bt(E,F),O&&yt(E,F)}return jt(t,k,O,S,p,ee.current,E)}}var we=h.ReactCurrentOwner,qe=h.ReactDebugCurrentFrame;function W(t){if(t){var l=t._owner,u=ue(t.type,t._source,l?l.type:null);qe.setExtraStackFrame(u)}else qe.setExtraStackFrame(null)}var Ce;Ce=!1;function ke(t){return typeof t=="object"&&t!==null&&t.$$typeof===r}function $e(){{if(we.current){var t=U(we.current.type);if(t)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+t+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+t+"`."}return""}}function Ct(t){return""}var Ke={};function kt(t){{var l=$e();if(!l){var u=typeof t=="string"?t:t.displayName||t.name;u&&(l=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+u+">.")}return l}}function ze(t,l){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var u=kt(l);if(Ke[u])return;Ke[u]=!0;var p="";t&&t._owner&&t._owner!==we.current&&(p=" It was passed a child from "+U(t._owner.type)+"."),W(t),C('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',u,p),W(null)}}function Ve(t,l){{if(typeof t!="object")return;if(ye(t))for(var u=0;u<t.length;u++){var p=t[u];ke(p)&&ze(p,l)}else if(ke(t))t._store&&(t._store.validated=!0);else if(t){var S=v(t);if(typeof S=="function"&&S!==t.entries)for(var P=S.call(t),E;!(E=P.next()).done;)ke(E.value)&&ze(E.value,l)}}}function Nt(t){{var l=t.type;if(l==null||typeof l=="string")return;var u;if(typeof l=="function")u=l.propTypes;else if(typeof l=="object"&&(l.$$typeof===m||l.$$typeof===D))u=l.propTypes;else return;if(u){var p=U(l);dt(u,t.props,"prop",p,t)}else if(l.PropTypes!==void 0&&!Ce){Ce=!0;var S=U(l);C("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",S||"Unknown")}typeof l.getDefaultProps=="function"&&!l.getDefaultProps.isReactClassApproved&&C("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Et(t){{for(var l=Object.keys(t.props),u=0;u<l.length;u++){var p=l[u];if(p!=="children"&&p!=="key"){W(t),C("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",p),W(null);break}}t.ref!==null&&(W(t),C("Invalid attribute `ref` supplied to `React.Fragment`."),W(null))}}var We={};function Qe(t,l,u,p,S,P){{var E=z(t);if(!E){var k="";(t===void 0||typeof t=="object"&&t!==null&&Object.keys(t).length===0)&&(k+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var O=Ct();O?k+=O:k+=$e();var R;t===null?R="null":ye(t)?R="array":t!==void 0&&t.$$typeof===r?(R="<"+(U(t.type)||"Unknown")+" />",k=" Did you accidentally export a JSX literal instead of a component?"):R=typeof t,C("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",R,k)}var F=wt(t,l,u,S,P);if(F==null)return F;if(E){var M=l.children;if(M!==void 0)if(p)if(ye(M)){for(var Q=0;Q<M.length;Q++)Ve(M[Q],t);Object.freeze&&Object.freeze(M)}else C("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ve(M,t)}if(Z.call(l,"key")){var K=U(t),G=Object.keys(l).filter(function(_t){return _t!=="key"}),Ne=G.length>0?"{key: someKey, "+G.join(": ..., ")+": ...}":"{key: someKey}";if(!We[K+Ne]){var At=G.length>0?"{"+G.join(": ..., ")+": ...}":"{}";C(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
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} />`,Se,$,Dt,$),Ve[$+Se]=!0}}return t===a?Nt(R):St(R),R}}function kt(t,l,h){return We(t,l,h,!0)}function Et(t,l,h){return We(t,l,h,!1)}var Tt=Et,Pt=kt;te.Fragment=a,te.jsx=Tt,te.jsxs=Pt}()),te}process.env.NODE_ENV==="production"?Ne.exports=_t():Ne.exports=Rt();var e=Ne.exports;const Xe=(n,s)=>{const a=O.useQueryClient().getQueryData(["builder_props"]);return c.get(a,n,s)},I=()=>Xe("apiUrl","/chai/api"),ke=()=>{const n=O.useQueryClient(),{data:s}=O.useQuery({queryKey:["ai-context"],initialData:"",queryFn:()=>""});return{setAiContext:j.useCallback(a=>{n.setQueryData(["ai-context"],a)},[]),aiContext:s}},Ft=()=>{const n=I(),{aiContext:s}=ke();return j.useCallback(async(o,a,i,d)=>{const f=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ASK_AI",data:{type:o,prompt:a,blocks:i,context:s,lang:d}})})).json();return console.log("data",f),f.error?{error:new Error(f.error)}:f},[n,s])},Lt=()=>{const n=I(),{toast:s}=r.useToast();return{getUILibraryBlock:async(d,u)=>{const N=(await(await fetch(d.url+(u.path?"/blocks/"+u.path:"/"+u.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return Q.getBlocksFromHTML(`${N}`)},getUILibraryBlocks:async d=>{try{return(await(await fetch(d.url+"/blocks.json")).json()).map(g=>({...g,preview:d.url.replace("chaiblocks","")+g.preview}))}catch(u){return console.error(u),[]}},onSave:async({page:d,blocks:u})=>{try{return(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:d,blocks:u}})})).ok?(s({title:"Success",description:"Page saved successfully",variant:"default"}),!0):new Error("Failed to save blocks")}catch(f){return f}}}};function J(){const[n,s]=j.useState(new URLSearchParams(window.location.search));return j.useEffect(()=>{const o=()=>{s(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}},[]),[n,s]}const Ee=()=>{const n=I();return O.useQuery({queryKey:["project-pages"],staleTime:1e3*60*5,queryFn:async()=>await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_PAGES"})})).json()})},de=()=>{const[n]=J(),s=n.get("page"),{data:o,isFetching:a}=Ee();return{data:j.useMemo(()=>c.find(o,{id:s})||{},[o,s]),isFetching:a}},It=()=>O.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[n]=J(),s=n.get("page"),o=I(),{setAiContext:a}=ke();return O.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 a(c.get(f,"_value","")||""),u},enabled:!!s})},Gt=n=>j.useMemo(()=>{if(!n||c.isEmpty(n))return{blocks:[],theme:{}};const s=c.find(n,{_type:"@chai/theme"}),o=c.get(s,"_value",{})||{},a=c.filter(n,i=>!c.includes(i==null?void 0:i._type,"@chai/"));return{theme:o,blocks:a}},[n]),Ze=()=>{const n=I();return O.useQuery({queryKey:["website-settings"],initialData:{theme:{},fallbackLang:"",languages:[]},queryFn:async()=>{const o=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_WEBSITE_SETTINGS"})})).json();if(o!=null&&o.error)throw new Error(o.error);return o}})},Ut=()=>{const{data:n}=Ee(),s=I();return{getGlobalBlocks:async()=>{const o={};for(const a of n??[])c.isEmpty(a==null?void 0:a.slug)&&(o[a.id]={name:c.startCase(a.name??a.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),{})}),ne={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 n=I(),s=O.useQueryClient(),{toast:o}=r.useToast();return O.useMutation({mutationFn:async a=>{var u;const d=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"CREATE_PAGE",data:a})})).json();if(d!=null&&d.error)throw new Error(((u=d==null?void 0:d.error)==null?void 0:u.message)||"Something went wrong.");return d},onSuccess:(a,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:(a,i)=>{o({variant:"destructive",title:`Failed to add new ${i.global?"global block":"page"}.`,description:a.message})}})},Te=()=>{const n=I(),s=O.useQueryClient(),{toast:o}=r.useToast();return O.useMutation({mutationFn:async a=>(await fetch(n,{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)?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:(a,i)=>{o({variant:"destructive",title:`Failed to update ${i.global?"global block":"page"}.`,description:a.message})}})},tt=()=>{const n=I(),s=O.useQueryClient(),{toast:o}=r.useToast();return O.useMutation({mutationFn:async a=>{const d=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"DELETE_PAGE",data:{id:a==null?void 0:a.id}})})).json();if(d!=null&&d.error)throw d==null?void 0:d.error;return d},onSuccess:(a,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:(a,i)=>{o({variant:"destructive",title:`Failed to delete ${i.global?"global block":"page"}.`,description:a.message})}})},qt=()=>{const n=I(),s=O.useQueryClient(),{toast:o}=r.useToast();return O.useMutation({mutationFn:async a=>{const d=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"TAKE_OFFLINE",data:{id:a==null?void 0:a.id}})})).json();if(d!=null&&d.error)throw d==null?void 0:d.error;return d},onSuccess:(a,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:(a,i)=>{o({variant:"destructive",title:`Failed to take offline ${i.global?"global block":"page"}.`,description:a.message})}})},$t=()=>{const n=I(),{toast:s}=r.useToast(),o=O.useQueryClient();return O.useMutation({mutationFn:async({ids:a,theme:i})=>{const u=await(await fetch(`${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"PUBLISH_CHANGES",data:{ids:a,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"})}})},nt=()=>{const n=I(),[s]=J(),o=s.get("page");return O.useQuery({queryKey:["language-pages",o],initialData:[],queryFn:async()=>{if(!o)return null;const i=await(await fetch(n,{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"))}})},Kt=()=>{const{selectedLang:n}=Q.useLanguages(),{data:s,isFetching:o}=nt();return{data:j.useMemo(()=>c.find(s,{lang:n||""})||{},[s,n]),isFetching:o}},at=()=>{const{data:n,isFetching:s}=Kt(),o=n==null?void 0:n.seo,[a,i]=j.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o}),d=j.useRef({initial:a,updated:a}),{selectedLang:u,fallbackLang:f,languages:g}=Q.useLanguages(),N=u.length?u:f,{mutate:y,isPending:D}=Te(),b=D;j.useEffect(()=>{!s&&o&&i({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o})},[s,o]);const T=async()=>{y({id:n==null?void 0:n.id,seo:a}),d.current.initial=a,d.current.updated=a},w=()=>{i({...a,ogTitle:a.title,ogDescription:a.description})},p=()=>{i({...a,searchTitle:a.ogTitle,searchDescription:a.ogDescription})},v=m=>{const C={...a,[m.target.name]:m.target.name==="noIndex"||m.target.name==="noFollow"?m.target.checked:m.target.value};i(C),d.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: ",n==null?void 0:n.slug," ",g.length>0&&e.jsxs("span",{className:"text-blue-500 font-semibold",children:["(",c.get(ne,N,N),")"]})]}),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:a.title,onChange:v,disabled:b,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:a.description,onChange:v,disabled:b,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:a.canonicalUrl,onChange:v,disabled:b,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:a.noIndex,onChange:v,disabled:b,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:a.noFollow,onChange:v,disabled:b,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:w,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:a.ogTitle,onChange:v,disabled:b,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:a.ogDescription,onChange:v,disabled:b,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:a.ogImage,onChange:v,disabled:b,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:a.searchTitle,onChange:v,disabled:b,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:a.searchDescription,onChange:v,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:a.jsonLD,onChange:v,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:T,disabled:c.isEqual(d.current.initial,a)||b,children:D?"Saving...":"Save"})})]})};at.displayName="SeoPanel";const zt=({langProps:n,onClose:s,languages:o})=>{const{data:a}=de(),[i,d]=j.useState(n.name||""),[u,f]=j.useState(n.edit?n.lang:""),[g,N]=j.useState(n.edit?n.slug:""),{mutate:y,isPending:D}=et(),{mutate:b,isPending:T}=Te(),w=!!(n!=null&&n.global),p=D||T,v=()=>{const m={name:i,lang:u,primaryPage:a==null?void 0:a.id,slug:g,collection:a==null?void 0:a.collection};m.global=w,n.edit&&(m.id=n==null?void 0:n.id),n.edit?b(m,{onSuccess:s}):y(m,{onSuccess:s})};return e.jsx(r.Dialog,{open:!!n,onOpenChange:s,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:n.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:n.edit||c.isEmpty(o),onChange:m=>{const C=m.target.value;f(C),!w&&N(`/${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:n.edit?c.get(ne,n.lang,n.lang):c.isEmpty(o)?"All available language page is created.":"Choose language"}),c.map(o,m=>e.jsx("option",{value:m,children:c.get(ne,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=>d(m.target.value),className:"col-span-3",required:!0,placeholder:"Enter page name"})]}),!w&&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}`)&&N(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:v,type:"button",disabled:p||!u||!w&&!c.startsWith(g,`/${u}`),children:p?n.edit?"Updating...":"Adding...":n.edit?"Update":"Add new language"})})]})]})})},Vt=()=>{const[n,s]=j.useState(null),{selectedLang:o,fallbackLang:a,setSelectedLang:i}=Q.useLanguages(),{data:d,isFetching:u}=nt(),{mutate:f,isPending:g}=tt(),{data:N}=de(),{data:y}=Ze(),D=c.filter(c.get(y,"languages")||["en"],b=>!c.find(d,{lang:b})&&b!==c.get(y,"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(d,b=>{const T=b.lang,w=b.slug,p=!b.primaryPage,v=T===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 ${v?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>i(T),children:[e.jsxs("div",{className:" flex-1 gap-x-3",children:[e.jsx("div",{className:"text-[13px]",children:c.get(ne,p?a:T,T)}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Slug:",e.jsxs("b",{children:[" ",w]})]}),e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Name:",e.jsxs("b",{children:[" ",b.name," "]})]})]})]}),p?e.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[e.jsx(F.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(F.PencilIcon,{onClick:m=>{m.stopPropagation(),s({...b,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),e.jsxs(r.Popover,{children:[e.jsx(r.PopoverTrigger,{children:e.jsx(F.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(ne,T,T)})," 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(b),children:g?"Deleting...":"Delete"})})]})})]})]})]},b.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(D),onClick:()=>{s({name:N==null?void 0:N.name,lang:"",slug:"",edit:!1})},children:"+ Add new language"})}),n&&e.jsx(zt,{languages:D,langProps:n,onClose:()=>s(null)})]})};function Wt({page:n,onClose:s,onDelete:o}){const[,a]=J(),{mutate:i,isPending:d}=tt(),u=()=>{i(n,{onSuccess:()=>{window.history.replaceState(null,"","/"),a(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate")),o()}})};return e.jsx(r.Dialog,{open:!!n,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:(n==null?void 0:n.name)??(n==null?void 0:n.slug)})," ",n!=null&&n.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:d,onClick:u,children:d?"Deleting...":"Delete"})]})]})})}const Qt=({page:n,onClose:s,onUnpublish:o})=>{const{mutate:a,isPending:i}=qt(),d=async()=>{a(n,{onSuccess:()=>{o()}})};return e.jsx(r.Dialog,{open:!!n,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:(n==null?void 0:n.name)??(n==null?void 0:n.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:d,children:i?"Updating...":"Take offline"})]})]})})},Jt=({activePage:n,editPage:s,onShowUpsertPage:o})=>{const[a,i]=j.useState("pages"),{data:d,isFetching:u}=Ee(),[f,g]=j.useState(null),[N,y]=j.useState(null),D=T=>{var v;if(a==="globalBlocks")return b(c.filter(T,m=>!m.slug));const w=c.groupBy(c.filter(T,m=>m.slug),"collection"),p=Object.entries(w).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:((v=p[0])==null?void 0:v[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:b(C)})})]},m))})},b=T=>c.orderBy(T,"online","desc").map(p=>e.jsxs(r.Button,{onClick:()=>s(p.id),variant:p.id===n?"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(F.GlobeIcon,{className:"h-4 w-4"}):e.jsx(F.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:v=>v.stopPropagation(),children:e.jsx(r.Button,{variant:"ghost",size:"sm",className:`h-8 w-8 p-0 hover:bg-transparent ${p.id===n?" hover:text-gray-200":"bg-transparent "}`,children:e.jsx(F.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:v=>{v.stopPropagation(),o({...p,global:a==="globalBlocks"})},children:[e.jsx(F.PencilIcon,{className:"size-3"}),"Edit"]}),e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:v=>{v.stopPropagation(),g(p)},children:[e.jsx(F.TrashIcon,{className:"size-3"}),"Delete"]}),(p==null?void 0:p.online)&&e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:v=>{v.stopPropagation(),y(p)},children:[e.jsx(F.Power,{className:"size-3"}),"Take offline"]})]})]})})]},p.id));return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs(r.Tabs,{value:a,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:a==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[e.jsx(F.Plus,{className:"h-4 w-4 mr-2"}),u?"Loading...":`Add ${a==="pages"?"page":"Global Block"}`]})}),e.jsx("div",{className:"pt-0",children:e.jsx("div",{className:"space-y-2",children:u?e.jsx(Yt,{}):D(d)})})]})]}),e.jsx(Wt,{page:f,onClose:()=>g(null),onDelete:()=>{g(null)}}),e.jsx(Qt,{page:N,onClose:()=>y(null),onUnpublish:()=>{y(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 n=I();return O.useQuery({queryKey:["project-collections"],initialData:[],queryFn:async()=>await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_COLLECTIONS"})})).json()})},Ht=()=>{const n=I();return O.useMutation({mutationFn:async({collection:s,query:o})=>{try{return await(await fetch(n,{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:n,showUpsertPage:s,setShowUpsertPage:o})=>{const a=s.id,[i,d]=j.useState(a&&s.name||""),[u,f]=j.useState(a&&s.slug||""),[g,N]=j.useState(a?s.pageType||"":"page"),{data:y=[]}=st(),{mutate:D,isPending:b}=et(),{mutate:T,isPending:w}=Te(),p=b||w,v=()=>{a?T({name:i,slug:u,id:s.id,collection:s.global?"global":g},{onSuccess:()=>{o(void 0)}}):D({name:i,slug:u,collection:s.global?"global":g},{onSuccess:m=>{n(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:[a?"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=>N(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:y.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=>d(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:v,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?a?"Updating...":"Adding...":s.global?`${a?"Update":"Add"} global block`:`${a?"Update":"Add"} Page`})})]})]})})};function Zt(n){const{activePage:s,canClose:o,open:a,close:i}=n,[,d]=J(),[u,f]=j.useState(),g=N=>{window.history.pushState({},"",`?page=${N}`),d(new URLSearchParams({page:N})),window.dispatchEvent(new PopStateEvent("popstate")),f(void 0),i()};return e.jsx(r.Sheet,{open:a,onOpenChange:N=>{!N&&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:N=>f(N),activePage:s,editPage:g})}),u&&e.jsx(Xt,{editPage:g,showUpsertPage:u,setShowUpsertPage:f})]})})}const en=()=>{const{t:n}=Q.useTranslation(),{data:s,isFetching:o}=de(),a=Xe("getPreviewUrl",async u=>u),[i,d]=j.useState("");return j.useEffect(()=>{(async()=>{if(!a||!(s!=null&&s.slug)){d("");return}const u=await a((s==null?void 0:s.slug)||"");d(u)})()},[a,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(F.EyeIcon,{className:"h-4 w-4 mr-2"}),e.jsx("a",{href:i,target:"_blank",children:n("Preview")})]})},tn=()=>{const n=I();return O.useQuery({queryKey:["get-page-changes"],queryFn:async()=>await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_CHANGES"})})).json()})},Ye=({pages:n,selectedPages:s,handleCheckboxChange:o,loading:a,type:i})=>{if(a)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(n))return e.jsx("div",{className:"p-4 text-center text-gray-400 font-medium",children:"No changes available to publish"});const d=c.filter(n,{online:!0}),u=c.filter(n,{online:!1});return e.jsxs("div",{className:"space-y-2 px-1",children:[c.map(d,(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(F.GlobeIcon,{className:"h-4 w-4"}):e.jsx(F.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(F.GlobeIcon,{className:"h-4 w-4"}):e.jsx(F.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 nn({onClose:n=()=>console.log("Cancelled")}){const[s,o]=j.useState([]),{data:a,isFetching:i}=tn(),d=j.useMemo(()=>[...c.filter(a,w=>w.collection!=="global"&&w.online),...c.filter(a,w=>w.collection!=="global"&&!w.online)],[a]),u=j.useMemo(()=>[...c.filter(a,{collection:"global",online:!0}),...c.filter(a,{collection:"global",online:!1})],[a]),{mutate:f,isPending:g}=$t();j.useEffect(()=>{o(c.map(c.filter(a,{online:!0}),"id"))},[a]);const{isAllPagesSelected:N,isAllGlobalBlocksSelected:y}=j.useMemo(()=>{const w=d.length>0&&d.every(v=>s.includes(v.id)),p=u.length>0&&u.every(v=>s.includes(v.id));return{isAllPagesSelected:w,isAllGlobalBlocksSelected:p}},[d,u,s]),D=w=>{o(p=>c.includes(p,w)?c.filter(p,v=>v!==w):c.concat(p,w))},b=w=>{o(w==="globalBlocks"?v=>y?c.filter(v,m=>!c.find(u,{id:m})):c.uniq(c.concat(v,c.map(u,"id"))):v=>N?c.filter(v,m=>!c.find(d,{id:m})):c.uniq(c.concat(v,c.map(d,"id"))))},T=()=>{f({ids:s,theme:!1},{onSuccess:()=>{n()}})};return e.jsx(r.Dialog,{open:!0,onOpenChange:g?()=>{}:n,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(d)&&e.jsx("input",{checked:N,onClick:w=>{w.stopPropagation(),b("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(Ye,{type:"Pages",loading:i,pages:d,selectedPages:s,handleCheckboxChange:D})})]}),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:y,onClick:w=>{w.stopPropagation(),b("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(Ye,{type:"Global Blocks",loading:i,pages:u,selectedPages:s,handleCheckboxChange:D})})]})]})}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{disabled:g,variant:"outline",onClick:n,children:"Cancel"}),e.jsx(r.Button,{disabled:g||i||c.isEmpty(a),onClick:T,children:g?"Publishing...":"Publish"})]})]})})}Ot.loadWebBlocks();const an=n=>{const s=j.useRef([]),[o]=J(),a=o.get("page"),{data:i,isFetching:d}=de(),{data:u}=It(),{data:f,isFetching:g}=Bt(),{blocks:N}=Gt(f),{data:y}=Ze(),{data:D}=st(),b=Ft(),{uploadFile:T}=Mt(),{getUILibraryBlock:w,getUILibraryBlocks:p,onSave:v}=Lt(),{getGlobalBlocks:m,getGlobalBlockBlocks:C}=Ut(),{aiContext:Y,setAiContext:he}=ke(),{mutateAsync:ae}=Ht();s.current=N;const[fe,se]=j.useState(!1),[me,H]=j.useState(!1),[K,ge]=j.useState("SAVED");j.useEffect(()=>{const A=M=>{K==="UNSAVED"&&(M.preventDefault(),M.returnValue=!1)};return K==="UNSAVED"&&window.addEventListener("beforeunload",A),()=>{window.removeEventListener("beforeunload",A)}},[K]);const re=j.useMemo(()=>{const A={};return n.mediaManagerComponent&&(A.mediaManagerComponent=n.mediaManagerComponent,A.uploadMediaCallback=T),A},[n.mediaManagerComponent,T]),G=j.useMemo(()=>Array.isArray(n==null?void 0:n.uiLibraries)?[...u,...n==null?void 0:n.uiLibraries]:u,[u,n==null?void 0:n.uiLibraries]),q=j.useCallback(async(A,M)=>await ae({collection:A,query:M}),[ae]);return e.jsxs(e.Fragment,{children:[e.jsx(Q.ChaiBuilderEditor,{loading:g,fallbackLang:y.fallbackLang||"en",languages:y.languages||[],brandingOptions:(y==null?void 0:y.theme)||{},translations:n.translations||{},locale:n.locale||"en",htmlDir:n.htmlDir||"ltr",autoSaveSupport:n.autoSaveSupport||!1,autoSaveInterval:n.autoSaveInterval||15,onError:n.onError||console.error,getGlobalBlockBlocks:C,getGlobalBlocks:m,blocks:N,getUILibraryBlock:w,getUILibraryBlocks:p,uiLibraries:G,collections:D,searchCollectionItems:q,saveAiContextCallback:async A=>{if(!a)return!0;const M=s.current,z={_type:"@chai/ai-context",_value:c.isString(A)?A:""},ie=[...M,z];return await v({page:a,blocks:ie}),he(A),!0},onSaveStateChange:A=>ge(A),aiContext:Y,askAiCallBack:b,onSave:async({blocks:A})=>{if(!a)return!0;s.current=A;const M={_type:"@chai/ai-context",_value:c.isString(Y)?Y:""},z=[...A,M];return await v({page:a,blocks:z}),s.current=A,!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(F.File,{className:"h-4 w-4"}):e.jsx(F.GlobeIcon,{className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:(i==null?void 0:i.name)??""}),e.jsx(F.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[en,()=>e.jsxs(r.Button,{disabled:K!=="SAVED",size:"sm",variant:"default",onClick:()=>H(!0),children:[e.jsx(F.RocketIcon,{className:"h-4 w-4"})," Publish"]})]},sideBarComponents:{top:[...(i==null?void 0:i.collection)!=="global"?[{label:"SEO Setting",component:at,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"})]})})}]:[],...c.isEmpty(y==null?void 0:y.languages)?[]:[{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"})]})})})}]]},...re}),e.jsx(Zt,{activePage:a||"",canClose:!!a&&!c.isEmpty(i),open:!a||!d&&c.isEmpty(i)||fe,close:()=>se(!1)}),me&&e.jsx(nn,{onClose:()=>H(!1)})]})},He=new O.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),sn=n=>(He.setQueryData(["builder_props"],n),e.jsx(O.QueryClientProvider,{client:He,children:e.jsx(an,{...n})}));module.exports=sn;
|
|
30
|
+
<%s key={someKey} {...props} />`,Ne,K,At,K),We[K+Ne]=!0}}return t===n?Et(F):Nt(F),F}}function St(t,l,u){return Qe(t,l,u,!0)}function Tt(t,l,u){return Qe(t,l,u,!1)}var Pt=Tt,Dt=St;ae.Fragment=n,ae.jsx=Pt,ae.jsxs=Dt}()),ae}process.env.NODE_ENV==="production"?Ee.exports=Ft():Ee.exports=Lt();var e=Ee.exports;const Ze=(a,r)=>{const n=_.useQueryClient().getQueryData(["builder_props"]);return c.get(n,a,r)},I=()=>Ze("apiUrl","/chai/api"),Se=()=>{const a=_.useQueryClient(),{data:r}=_.useQuery({queryKey:["ai-context"],initialData:"",queryFn:()=>""});return{setAiContext:j.useCallback(n=>{a.setQueryData(["ai-context"],n)},[]),aiContext:r}},B=async(a,r)=>{const o=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),n=await o.json();if(n!=null&&n.error||o.status===400||!o.ok)throw new Error((n==null?void 0:n.error)||"Something went wrong.");return n},Ot=()=>{const a=I(),{aiContext:r}=Se();return j.useCallback(async(o,n,i,g)=>B(a,{action:"ASK_AI",data:{type:o,prompt:n,blocks:i,context:r,lang:g}}),[a,r])},It=()=>{const a=I(),{toast:r}=s.useToast();return{getUILibraryBlock:async(g,d)=>{const N=(await(await fetch(g.url+(d.path?"/blocks/"+d.path:"/"+d.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return Y.getBlocksFromHTML(`${N}`)},getUILibraryBlocks:async g=>{try{return(await(await fetch(g.url+"/blocks.json")).json()).map(m=>({...m,preview:g.url.replace("chaiblocks","")+m.preview}))}catch(d){return console.error(d),[]}},onSave:async({page:g,blocks:d})=>{try{const f=await B(a,{action:"UPDATE_PAGE",data:{id:g,blocks:d}});return r({title:"Success",description:"Page saved successfully",variant:"default"}),f}catch{return new Error("Failed to save blocks")}}}};function H(){const[a,r]=j.useState(new URLSearchParams(window.location.search));return j.useEffect(()=>{const o=()=>{r(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",o),()=>{window.removeEventListener("popstate",o)}},[]),[a,r]}const Te=()=>{const a=I();return _.useQuery({queryKey:["project-pages"],staleTime:1e3*60*5,queryFn:async()=>B(a,{action:"GET_PROJECT_PAGES"})||[]})},he=()=>{const[a]=H(),r=a.get("page"),{data:o,isFetching:n}=Te();return{data:j.useMemo(()=>c.find(o,{id:r})||{},[o,r]),isFetching:n}},Bt=()=>_.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"}]}),Gt=()=>{const[a]=H(),r=a.get("page"),o=I(),{setAiContext:n}=Se();return _.useQuery({queryKey:["page",r],initialData:[],queryFn:async()=>{const i=await B(o,{action:"GET_PAGE",data:{id:r,draft:!0}});console.log("## data",i);const g=i.blocks??[],d=c.find(g,{_type:"@chai/ai-context"});return n(c.get(d,"_value","")||""),g},enabled:!!r})},Ut=a=>j.useMemo(()=>{if(!a||c.isEmpty(a))return{blocks:[],theme:{}};const r=c.find(a,{_type:"@chai/theme"}),o=c.get(r,"_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 _.useQuery({queryKey:["website-settings"],initialData:{theme:{},fallbackLang:"",languages:[]},queryFn:async()=>B(a,{action:"GET_WEBSITE_SETTINGS"})})},Mt=()=>{const{data:a}=Te(),r=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 B(r,{action:"GET_PAGE",data:{id:o,draft:!0}})).blocks:[]}},qt=()=>({uploadFile:async r=>(console.log("uploadFile",r),{})}),ne={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(),r=_.useQueryClient(),{toast:o}=s.useToast();return _.useMutation({mutationFn:async n=>B(a,{action:"CREATE_PAGE",data:n}),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?r.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):r.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})}})},Pe=()=>{const a=I(),r=_.useQueryClient(),{toast:o}=s.useToast();return _.useMutation({mutationFn:async n=>B(a,{action:"UPDATE_PAGE",data:n}),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?r.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):r.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(),r=_.useQueryClient(),{toast:o}=s.useToast();return _.useMutation({mutationFn:async n=>B(a,{action:"DELETE_PAGE",data:{id:n==null?void 0:n.id}}),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?r.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):r.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})}})},$t=()=>{const a=I(),r=_.useQueryClient(),{toast:o}=s.useToast();return _.useMutation({mutationFn:async n=>B(a,{action:"TAKE_OFFLINE",data:{id:n==null?void 0:n.id}}),onSuccess:(n,i)=>{i&&(i!=null&&i.primaryPage)?r.invalidateQueries({queryKey:["language-pages",i==null?void 0:i.primaryPage]}):r.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})}})},Kt=()=>{const a=I(),{toast:r}=s.useToast(),o=_.useQueryClient();return _.useMutation({mutationFn:async({ids:n,theme:i})=>B(a,{action:"PUBLISH_CHANGES",data:{ids:n,theme:i}}),onSuccess:()=>{r({title:"Pages published"}),o.invalidateQueries({queryKey:["get-page-changes"]}),o.invalidateQueries({queryKey:["project-pages"]})},onError:()=>{r({title:"Failed to publish pages.",variant:"destructive"})}})},nt=()=>{const a=I(),[r]=H(),o=r.get("page");return _.useQuery({queryKey:["language-pages",o],initialData:[],queryFn:async()=>{if(!o)return null;const n=await B(a,{action:"GET_LANGUAGE_PAGES",data:{id:o}});return c.reverse(c.sortBy(n,"primaryPage"))}})},zt=()=>{const{selectedLang:a}=Y.useLanguages(),{data:r,isFetching:o}=nt();return{data:j.useMemo(()=>c.find(r,{lang:a||""})||{},[r,a]),isFetching:o}},st=()=>{const{data:a,isFetching:r}=zt(),o=a==null?void 0:a.seo,[n,i]=j.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o}),g=j.useRef({initial:n,updated:n}),{selectedLang:d,fallbackLang:f,languages:m}=Y.useLanguages(),N=d.length?d:f,{mutate:y,isPending:D}=Pe(),b=D;j.useEffect(()=>{!r&&o&&i({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...o})},[r,o]);const T=async()=>{y({id:a==null?void 0:a.id,seo:n}),g.current.initial=n,g.current.updated=n},w=()=>{i({...n,ogTitle:n.title,ogDescription:n.description})},x=()=>{i({...n,searchTitle:n.ogTitle,searchDescription:n.ogDescription})},v=h=>{const C={...n,[h.target.name]:h.target.name==="noIndex"||h.target.name==="noFollow"?h.target.checked:h.target.value};i(C),g.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," ",m.length>0&&e.jsxs("span",{className:"text-blue-500 font-semibold",children:["(",c.get(ne,N,N),")"]})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(s.Accordion,{type:"multiple",defaultValue:["page"],children:[e.jsxs(s.AccordionItem,{value:"page",children:[e.jsx(s.AccordionTrigger,{className:"text-blue-500",children:"Seo Page"}),e.jsx(s.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs pb-1",htmlFor:"title",children:"SEO Title"}),e.jsx(s.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:v,disabled:b,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(s.Label,{className:"text-xs pb-1",htmlFor:"description",children:"SEO Description"}),e.jsx(s.Textarea,{id:"description",name:"description",value:n.description,onChange:v,disabled:b,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(s.Label,{className:"text-xs pb-1",htmlFor:"title",children:"Canonical URL"}),e.jsx(s.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:v,disabled:b,placeholder:"Enter Canonical URL"})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(s.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:v,disabled:b,className:"h-4 w-4"}),e.jsx(s.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(s.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:v,disabled:b,className:"h-4 w-4"}),e.jsx(s.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(s.AccordionItem,{value:"og",children:[e.jsx(s.AccordionTrigger,{className:"text-blue-500",children:"OG"}),e.jsx(s.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(s.Button,{type:"button",variant:"outline",size:"sm",onClick:w,children:"Copy from SEO Settings"})}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs pb-1",htmlFor:"ogTitle",children:"OG Title"}),e.jsx(s.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:v,disabled:b,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(s.Label,{className:"text-xs pb-1",htmlFor:"ogDescription",children:"OG Description"}),e.jsx(s.Textarea,{id:"ogDescription",name:"ogDescription",value:n.ogDescription,onChange:v,disabled:b,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(s.Label,{className:"text-xs pb-1",htmlFor:"ogImage",children:"OG Image URL"}),e.jsx(s.Input,{type:"text",id:"ogImage",name:"ogImage",value:n.ogImage,onChange:v,disabled:b,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(s.AccordionItem,{value:"search",children:[e.jsx(s.AccordionTrigger,{className:"text-blue-500",children:"Search"}),e.jsx(s.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(s.Button,{type:"button",variant:"outline",size:"sm",onClick:x,children:"Copy from OG Settings"})}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs pb-1",htmlFor:"searchTitle",children:"Search Title"}),e.jsx(s.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:n.searchTitle,onChange:v,disabled:b,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(s.Label,{className:"text-xs pb-1",htmlFor:"searchDescription",children:"Search Description"}),e.jsx(s.Textarea,{id:"searchDescription",name:"searchDescription",value:n.searchDescription,onChange:v,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(s.AccordionItem,{value:"jsonLD",children:[e.jsx(s.AccordionTrigger,{className:"text-blue-500",children:"JSON-LD"}),e.jsx(s.AccordionContent,{children:e.jsx("div",{className:"space-y-4",children:e.jsx("div",{children:e.jsx(s.Textarea,{id:"jsonLD",name:"jsonLD",rows:3,value:n.jsonLD,onChange:v,placeholder:"Enter JSON-LD"})})})})]})]})}),e.jsx("div",{className:"w-full flex items-center justify-end mt-4",children:e.jsx(s.Button,{size:"lg",variant:"default",onClick:T,disabled:c.isEqual(g.current.initial,n)||b,children:D?"Saving...":"Save"})})]})};st.displayName="SeoPanel";const Vt=({langProps:a,onClose:r,languages:o})=>{const{data:n}=he(),[i,g]=j.useState(a.name||""),[d,f]=j.useState(a.edit?a.lang:""),[m,N]=j.useState(a.edit?a.slug:""),{mutate:y,isPending:D}=tt(),{mutate:b,isPending:T}=Pe(),w=!!(a!=null&&a.global),x=D||T,v=()=>{const h={name:i,lang:d,primaryPage:n==null?void 0:n.id,slug:m,collection:n==null?void 0:n.collection};h.global=w,a.edit&&(h.id=a==null?void 0:a.id),a.edit?b(h,{onSuccess:r}):y(h,{onSuccess:r})};return e.jsx(s.Dialog,{open:!!a,onOpenChange:r,children:e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:a.edit?"Edit language":"Add New language"}),e.jsx(s.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(s.Label,{htmlFor:"lang",className:"text-right",children:"Language"}),e.jsxs("select",{value:d,disabled:a.edit||c.isEmpty(o),onChange:h=>{const C=h.target.value;f(C),!w&&N(`/${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(ne,a.lang,a.lang):c.isEmpty(o)?"All available language page is created.":"Choose language"}),c.map(o,h=>e.jsx("option",{value:h,children:c.get(ne,h,h)},h))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{htmlFor:"slug",className:"text-right",children:"Page Name"}),e.jsx(s.Input,{id:"name",value:i,onChange:h=>g(h.target.value),className:"col-span-3",required:!0,placeholder:"Enter page name"})]}),!w&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(s.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",e.jsxs("small",{className:"font-light",children:["(Slug should start with /",d,")"]})]}),e.jsx(s.Input,{id:"slug",value:m,onChange:h=>{const C=h.target.value;c.startsWith(C,`/${d}`)&&N(c.toLower(c.trim(C)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:c.isEmpty(d),title:"Slug must start with /",placeholder:c.isEmpty(d)?"Choose language to add slug":"Enter page slug"})]})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:v,type:"button",disabled:x||!d||!w&&!c.startsWith(m,`/${d}`),children:x?a.edit?"Updating...":"Adding...":a.edit?"Update":"Add new language"})})]})]})})},Wt=()=>{const[a,r]=j.useState(null),{selectedLang:o,fallbackLang:n,setSelectedLang:i}=Y.useLanguages(),{data:g,isFetching:d}=nt(),{mutate:f,isPending:m}=at(),{data:N}=he(),{data:y}=et(),D=c.filter(c.get(y,"languages")||["en"],b=>!c.find(g,{lang:b})&&b!==c.get(y,"fallbackLang"));return e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsx("ul",{className:"space-y-2 mt-4",children:d?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(g,b=>{const T=b.lang,w=b.slug,x=!b.primaryPage,v=T===o;return x?null:e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`w-full p-2 rounded cursor-pointer flex items-center justify-between ${v?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>i(T),children:[e.jsxs("div",{className:" flex-1 gap-x-3",children:[e.jsx("div",{className:"text-[13px]",children:c.get(ne,x?n:T,T)}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Slug:",e.jsxs("b",{children:[" ",w]})]}),e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Name:",e.jsxs("b",{children:[" ",b.name," "]})]})]})]}),x?e.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[e.jsx(L.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(L.PencilIcon,{onClick:h=>{h.stopPropagation(),r({...b,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(L.TrashIcon,{className:"w-3 h-3 hover:text-red-500"})}),e.jsx(s.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(ne,T,T)})," language?"]}),e.jsx("div",{className:"flex items-center justify-end w-full",children:e.jsx(s.Button,{size:"sm",variant:"destructive",disabled:m,onClick:()=>f(b),children:m?"Deleting...":"Delete"})})]})})]})]})]},b.id),e.jsx("div",{className:"h-1 w-full border-b"})]})})}),e.jsx("div",{className:"flex justify-center w-full",children:e.jsx(s.Button,{variant:"default",size:"sm",disabled:c.isEmpty(D),onClick:()=>{r({name:N==null?void 0:N.name,lang:"",slug:"",edit:!1})},children:"+ Add new language"})}),a&&e.jsx(Vt,{languages:D,langProps:a,onClose:()=>r(null)})]})};function Qt({page:a,onClose:r,onDelete:o}){const[,n]=H(),{mutate:i,isPending:g}=at(),d=()=>{i(a,{onSuccess:()=>{window.history.replaceState(null,"","/"),n(new URLSearchParams({})),window.dispatchEvent(new PopStateEvent("popstate")),o()}})};return e.jsx(s.Dialog,{open:!!a,onOpenChange:r,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Confirm Deletion"}),e.jsxs(s.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(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:r,children:"Cancel"}),e.jsx(s.Button,{variant:"destructive",disabled:g,onClick:d,children:g?"Deleting...":"Delete"})]})]})})}const Yt=({page:a,onClose:r,onUnpublish:o})=>{const{mutate:n,isPending:i}=$t(),g=async()=>{n(a,{onSuccess:()=>{o()}})};return e.jsx(s.Dialog,{open:!!a,onOpenChange:r,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Confirm action"}),e.jsxs(s.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(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:r,children:"Cancel"}),e.jsx(s.Button,{variant:"destructive",disabled:i,onClick:g,children:i?"Updating...":"Take offline"})]})]})})},Ht=({activePage:a,editPage:r,onShowUpsertPage:o})=>{const[n,i]=j.useState("pages"),{data:g,isFetching:d}=Te(),[f,m]=j.useState(null),[N,y]=j.useState(null),D=T=>{var v;if(n==="globalBlocks")return b(c.filter(T,h=>!h.slug));const w=c.groupBy(c.filter(T,h=>h.slug),"collection"),x=Object.entries(w).sort(([h],[C])=>h?!C||h.toLowerCase()==="page"?-1:C.toLowerCase()==="page"?1:h.localeCompare(C):1);return e.jsx(s.Accordion,{type:"single",collapsible:!0,className:"w-full",defaultValue:((v=x[0])==null?void 0:v[0])||"uncategorized",children:x.map(([h,C])=>e.jsxs(s.AccordionItem,{value:h||"uncategorized",children:[e.jsx(s.AccordionTrigger,{className:"px-2",children:c.startCase(h)||"Uncategorized"}),e.jsx(s.AccordionContent,{className:"bg-white",children:e.jsx("div",{className:"space-y-2",children:b(C)})})]},h))})},b=T=>c.orderBy(T,"online","desc").map(x=>e.jsxs(s.Button,{onClick:()=>r(x.id),variant:x.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:x.global?e.jsx(L.GlobeIcon,{className:"h-4 w-4"}):e.jsx(L.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:[x.name??x.slug," ",(x==null?void 0:x.online)&&e.jsx("div",{style:{backgroundColor:"lightgreen"},className:"rounded-full w-2 h-2 mr-2"})]}),(x==null?void 0:x.slug)&&e.jsx("span",{className:"text-xs font-light",children:x.slug})]})]}),e.jsx("div",{className:"flex items-center space-x-4",children:e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,onClick:v=>v.stopPropagation(),children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:`h-8 w-8 p-0 hover:bg-transparent ${x.id===a?" hover:text-gray-200":"bg-transparent "}`,children:e.jsx(L.MoreVertical,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"text-sm",children:[e.jsxs(s.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:v=>{v.stopPropagation(),o({...x,global:n==="globalBlocks"})},children:[e.jsx(L.PencilIcon,{className:"size-3"}),"Edit"]}),e.jsxs(s.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:v=>{v.stopPropagation(),m(x)},children:[e.jsx(L.TrashIcon,{className:"size-3"}),"Delete"]}),(x==null?void 0:x.online)&&e.jsxs(s.DropdownMenuItem,{className:"flex items-center gap-2 cursor-pointer",onClick:v=>{v.stopPropagation(),y(x)},children:[e.jsx(L.Power,{className:"size-3"}),"Take offline"]})]})]})})]},x.id));return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs(s.Tabs,{value:n,className:"w-full",onValueChange:i,children:[e.jsxs(s.TabsList,{className:"w-full",children:[e.jsx(s.TabsTrigger,{value:"pages",className:"w-full",children:e.jsx("div",{className:"px-4",children:"Pages"})}),e.jsx(s.TabsTrigger,{value:"globalBlocks",className:"w-full",children:e.jsx("div",{className:"px-4",children:"Global Blocks"})})]}),d?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(s.Button,{variant:"default",size:"sm",disabled:d,onClick:()=>o({slug:"",name:"",global:n==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[e.jsx(L.Plus,{className:"h-4 w-4 mr-2"}),d?"Loading...":`Add ${n==="pages"?"page":"Global Block"}`]})}),e.jsx("div",{className:"pt-0",children:e.jsx("div",{className:"space-y-2",children:d?e.jsx(Jt,{}):D(g)})})]})]}),e.jsx(Qt,{page:f,onClose:()=>m(null),onDelete:()=>{m(null)}}),e.jsx(Yt,{page:N,onClose:()=>y(null),onUnpublish:()=>{y(null)}})]})};function Jt(){return e.jsx("div",{className:"h-32 w-full flex justify-center items-center text-sm animate-pulse",children:"Loading..."})}const rt=()=>{const a=I();return _.useQuery({queryKey:["project-collections"],initialData:[],queryFn:async()=>B(a,{action:"GET_COLLECTIONS"})})},Xt=()=>{const a=I();return _.useMutation({mutationFn:async({collection:r,query:o})=>{try{return B(a,{action:"SEARCH_PAGES",data:{collection:r,query:Array.isArray(o)&&o.length>0?o[0]:o}})||[]}catch{return[]}}})},Zt=({editPage:a,showUpsertPage:r,setShowUpsertPage:o})=>{const n=r.id,[i,g]=j.useState(n&&r.name||""),[d,f]=j.useState(n&&r.slug||""),[m,N]=j.useState(n?r.pageType||"":"page"),{data:y=[]}=rt(),{mutate:D,isPending:b}=tt(),{mutate:T,isPending:w}=Pe(),x=b||w,v=()=>{n?T({name:i,slug:d,id:r.id,collection:r.global?"global":m},{onSuccess:()=>{o(void 0)}}):D({name:i,slug:d,collection:r.global?"global":m},{onSuccess:h=>{a(h.page.id)}})};return e.jsx(s.Dialog,{open:!!r,onOpenChange:()=>o(void 0),children:e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{children:[n?"Edit":"Add New"," ",r.global?"Global Block":c.startCase(m)]}),e.jsxs(s.DialogDescription,{children:["Enter the details for the new"," ",r.global?"Global Block":`${c.startCase(m)}. Slug must start with /`]})]}),e.jsxs("form",{children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[!r.global&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{htmlFor:"pageType",children:"Type"}),e.jsx("select",{value:m,onChange:h=>N(h.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:y.map(h=>e.jsx("option",{value:h.key,children:h.name},h.key))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{htmlFor:"name",className:"text-right",children:"Name"}),e.jsx(s.Input,{id:"name",value:i,placeholder:`Enter ${r.global?"global block":"page"} name`,onChange:h=>g(h.target.value),className:"col-span-3",required:!0})]}),!r.global&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{htmlFor:"slug",className:"text-right",children:r.global?"Identifier":"Slug"}),e.jsx(s.Input,{id:"slug",value:d,onChange:h=>{var C;return f((C=h.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(s.DialogFooter,{children:e.jsx(s.Button,{onClick:v,type:"button",disabled:x||!i||!r.global&&!d.startsWith("/")||c.isEqual(r.name,i)&&c.isEqual(r.slug,d)&&c.isEqual(r.pageType,m),children:x?n?"Updating...":"Adding...":r.global?`${n?"Update":"Add"} global block`:`${n?"Update":"Add"} Page`})})]})]})})};function ea(a){const{activePage:r,canClose:o,open:n,close:i}=a,[,g]=H(),[d,f]=j.useState(),m=N=>{window.history.pushState({},"",`?page=${N}`),g(new URLSearchParams({page:N})),window.dispatchEvent(new PopStateEvent("popstate")),f(void 0),i()};return e.jsx(s.Sheet,{open:n,onOpenChange:N=>{!N&&o&&i()},children:e.jsxs(s.SheetContent,{side:"left",className:`border-border w-full ${o?"":"sheet-hide-close-btn"}`,children:[e.jsx("div",{children:e.jsx(Ht,{onShowUpsertPage:N=>f(N),activePage:r,editPage:m})}),d&&e.jsx(Zt,{editPage:m,showUpsertPage:d,setShowUpsertPage:f})]})})}const ta=()=>{const{t:a}=Y.useTranslation(),{data:r,isFetching:o}=he(),n=Ze("getPreviewUrl",async d=>d),[i,g]=j.useState("");return j.useEffect(()=>{(async()=>{if(!n||!(r!=null&&r.slug)){g("");return}const d=await n((r==null?void 0:r.slug)||"");g(d)})()},[n,r==null?void 0:r.slug]),!i||r!=null&&r.global||o?null:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"ml-2",children:[e.jsx(L.EyeIcon,{className:"h-4 w-4 mr-2"}),e.jsx("a",{href:i,target:"_blank",children:a("Preview")})]})},aa=()=>{const a=I();return _.useQuery({queryKey:["get-page-changes"],queryFn:async()=>B(a,{action:"GET_CHANGES"})})},Je=({pages:a,selectedPages:r,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 g=c.filter(a,{online:!0}),d=c.filter(a,{online:!1});return e.jsxs("div",{className:"space-y-2 px-1",children:[c.map(g,(f,m)=>e.jsxs("div",{className:`pt-2 flex justify-between ${m>0?"border-t":""}`,children:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx("input",{checked:c.includes(r,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(L.GlobeIcon,{className:"h-4 w-4"}):e.jsx(L.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(d)&&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(d,(f,m)=>e.jsxs("div",{className:`pt-2 flex justify-between ${m>0?"border-t":""}`,children:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx("input",{checked:c.includes(r,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(L.GlobeIcon,{className:"h-4 w-4"}):e.jsx(L.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 na({onClose:a=()=>console.log("Cancelled")}){const[r,o]=j.useState([]),{data:n,isFetching:i}=aa(),g=j.useMemo(()=>[...c.filter(n,w=>w.collection!=="global"&&w.online),...c.filter(n,w=>w.collection!=="global"&&!w.online)],[n]),d=j.useMemo(()=>[...c.filter(n,{collection:"global",online:!0}),...c.filter(n,{collection:"global",online:!1})],[n]),{mutate:f,isPending:m}=Kt();j.useEffect(()=>{o(c.map(c.filter(n,{online:!0}),"id"))},[n]);const{isAllPagesSelected:N,isAllGlobalBlocksSelected:y}=j.useMemo(()=>{const w=g.length>0&&g.every(v=>r.includes(v.id)),x=d.length>0&&d.every(v=>r.includes(v.id));return{isAllPagesSelected:w,isAllGlobalBlocksSelected:x}},[g,d,r]),D=w=>{o(x=>c.includes(x,w)?c.filter(x,v=>v!==w):c.concat(x,w))},b=w=>{o(w==="globalBlocks"?v=>y?c.filter(v,h=>!c.find(d,{id:h})):c.uniq(c.concat(v,c.map(d,"id"))):v=>N?c.filter(v,h=>!c.find(g,{id:h})):c.uniq(c.concat(v,c.map(g,"id"))))},T=()=>{f({ids:r,theme:!1},{onSuccess:()=>{a()}})};return e.jsx(s.Dialog,{open:!0,onOpenChange:m?()=>{}:a,children:e.jsxs(s.DialogContent,{className:"sm:max-w-[525px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Publish changes"}),e.jsx(s.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(s.Accordion,{type:"multiple",defaultValue:["pages","globalBlocks"],children:[e.jsxs(s.AccordionItem,{value:"pages",defaultChecked:!0,children:[e.jsx(s.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(g)&&e.jsx("input",{checked:N,onClick:w=>{w.stopPropagation(),b("pages")},type:"checkbox",className:"rounded focus:outline-none focus:ring-0 mt-1 cursor-pointer"}),"Pages"]})}),e.jsx(s.AccordionContent,{className:"px-4 pt-2",children:e.jsx(Je,{type:"Pages",loading:i,pages:g,selectedPages:r,handleCheckboxChange:D})})]}),e.jsxs(s.AccordionItem,{value:"globalBlocks",children:[e.jsx(s.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(d)&&e.jsx("input",{checked:y,onClick:w=>{w.stopPropagation(),b("globalBlocks")},type:"checkbox",className:"rounded focus:outline-none focus:ring-0 mt-1 cursor-pointer"}),"Global Block"]})}),e.jsx(s.AccordionContent,{className:"px-4 pt-2",children:e.jsx(Je,{type:"Global Blocks",loading:i,pages:d,selectedPages:r,handleCheckboxChange:D})})]})]})}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{disabled:m,variant:"outline",onClick:a,children:"Cancel"}),e.jsx(s.Button,{disabled:m||i||c.isEmpty(n),onClick:T,children:m?"Publishing...":"Publish"})]})]})})}Rt.loadWebBlocks();const sa=a=>{const r=j.useRef([]),[o]=H(),n=o.get("page"),{data:i,isFetching:g}=he(),{data:d}=Bt(),{data:f,isFetching:m}=Gt(),{blocks:N}=Ut(f),{data:y}=et(),{data:D}=rt(),b=Ot(),{uploadFile:T}=qt(),{getUILibraryBlock:w,getUILibraryBlocks:x,onSave:v}=It(),{getGlobalBlocks:h,getGlobalBlockBlocks:C}=Mt(),{aiContext:J,setAiContext:fe}=Se(),{mutateAsync:se}=Xt();r.current=N;const[me,re]=j.useState(!1),[ge,X]=j.useState(!1),[z,xe]=j.useState("SAVED");j.useEffect(()=>{const A=q=>{z==="UNSAVED"&&(q.preventDefault(),q.returnValue=!1)};return z==="UNSAVED"&&window.addEventListener("beforeunload",A),()=>{window.removeEventListener("beforeunload",A)}},[z]);const ie=j.useMemo(()=>{const A={};return a.mediaManagerComponent&&(A.mediaManagerComponent=a.mediaManagerComponent,A.uploadMediaCallback=T),A},[a.mediaManagerComponent,T]),U=j.useMemo(()=>Array.isArray(a==null?void 0:a.uiLibraries)?[...d,...a==null?void 0:a.uiLibraries]:d,[d,a==null?void 0:a.uiLibraries]),$=j.useCallback(async(A,q)=>await se({collection:A,query:q}),[se]);return e.jsxs(e.Fragment,{children:[e.jsx(Y.ChaiBuilderEditor,{loading:m,fallbackLang:y.fallbackLang||"en",languages:y.languages||[],brandingOptions:(y==null?void 0:y.theme)||{},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:C,getGlobalBlocks:h,blocks:N,getUILibraryBlock:w,getUILibraryBlocks:x,uiLibraries:U,collections:D,searchCollectionItems:$,saveAiContextCallback:async A=>{if(!n)return!0;const q=r.current,V={_type:"@chai/ai-context",_value:c.isString(A)?A:""},le=[...q,V];return await v({page:n,blocks:le}),fe(A),!0},onSaveStateChange:A=>xe(A),aiContext:J,askAiCallBack:b,onSave:async({blocks:A})=>{if(!n)return!0;r.current=A;const q={_type:"@chai/ai-context",_value:c.isString(J)?J:""},V=[...A,q];return await v({page:n,blocks:V}),r.current=A,!0},topBarComponents:{left:[()=>e.jsxs(s.Button,{variant:"default",className:"flex justify-start max-w-[250px] items-center w-full space-x-2 py-1",onClick:()=>re(!0),children:[c.includes(i.slug,"/")?e.jsx(L.File,{className:"h-4 w-4"}):e.jsx(L.GlobeIcon,{className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:(i==null?void 0:i.name)??""}),e.jsx(L.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[ta,()=>e.jsxs(s.Button,{disabled:z!=="SAVED",size:"sm",variant:"default",onClick:()=>X(!0),children:[e.jsx(L.RocketIcon,{className:"h-4 w-4"})," Publish"]})]},sideBarComponents:{top:[...(i==null?void 0:i.collection)!=="global"?[{label:"SEO Setting",component:st,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"})]})})}]:[],...c.isEmpty(y==null?void 0:y.languages)?[]:[{label:"Language Pages",component:Wt,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"})]})})})}]]},...ie}),e.jsx(ea,{activePage:n||"",canClose:!!n&&!c.isEmpty(i),open:!n||!g&&c.isEmpty(i)||me,close:()=>re(!1)}),ge&&e.jsx(na,{onClose:()=>X(!1)})]})},Xe=new _.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),ra=a=>(Xe.setQueryData(["builder_props"],a),e.jsx(_.QueryClientProvider,{client:Xe,children:e.jsx(sa,{...a})}));module.exports=ra;
|