@chaibuilder/pages 0.1.0-beta.2 → 0.1.0-beta.20

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