@chaibuilder/pages 0.1.0-beta.1

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/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Chai Builder Local
2
+ ---
3
+
4
+ Chai Builder Local is an idea of using Chai Builder in local development to create UI quickly inside the builder.
5
+
6
+ ### Core Idea:
7
+ ---
8
+
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@chaibuilder/sdk");Object.keys(t).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
@@ -0,0 +1,4 @@
1
+
2
+ export * from "@chaibuilder/sdk";
3
+
4
+ export { }
@@ -0,0 +1 @@
1
+ export * from "@chaibuilder/sdk";
package/dist/index.cjs ADDED
@@ -0,0 +1,30 @@
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={};/**
2
+ * @license React
3
+ * react-jsx-runtime.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
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={};/**
10
+ * @license React
11
+ * react-jsx-runtime.development.js
12
+ *
13
+ * Copyright (c) Facebook, Inc. and its affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
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`
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=`
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:
26
+ let props = %s;
27
+ <%s {...props} />
28
+ React keys must be passed directly to JSX without using spread:
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;
@@ -0,0 +1,11 @@
1
+ import { ChaiBuilderEditorProps } from '@chaibuilder/sdk';
2
+ import { JSX as JSX_2 } from 'react/jsx-runtime';
3
+
4
+ declare const ChaiBuilderForge: (props: ChaiBuilderForgeProps) => JSX_2.Element;
5
+ export default ChaiBuilderForge;
6
+
7
+ declare type ChaiBuilderForgeProps = {
8
+ apiUrl?: string;
9
+ } & Pick<ChaiBuilderEditorProps, "onError" | "layout" | "layoutVariant" | "translations" | "locale" | "htmlDir" | "autoSaveSupport" | "autoSaveInterval" | "getUILibraryBlocks" | "getUILibraryBlock" | "fallbackLang" | "languages">;
10
+
11
+ export { }