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