@chaibuilder/pages 0.1.0-beta.13 → 0.1.0-beta.14
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 +8 -8
- package/dist/index.js +368 -369
- package/dist/server.cjs +1 -1
- package/dist/server.js +11 -9
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const E=require("react"),Dt=require("@chaibuilder/sdk/web-blocks"),
|
|
1
|
+
"use strict";const E=require("react"),Dt=require("@chaibuilder/sdk/web-blocks"),X=require("@chaibuilder/sdk"),R=require("@tanstack/react-query"),r=require("@chaibuilder/sdk/ui"),B=require("lucide-react"),h=require("lodash-es");var we={exports:{}},J={};/**
|
|
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 Qe;function _t(){if(Qe)return
|
|
9
|
+
*/var Qe;function _t(){if(Qe)return J;Qe=1;var a=E,o=Symbol.for("react.element"),l=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,s=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,f={key:!0,ref:!0,__self:!0,__source:!0};function u(v,g,j){var p,w={},C=null,_=null;j!==void 0&&(C=""+j),g.key!==void 0&&(C=""+g.key),g.ref!==void 0&&(_=g.ref);for(p in g)n.call(g,p)&&!f.hasOwnProperty(p)&&(w[p]=g[p]);if(v&&v.defaultProps)for(p in g=v.defaultProps,g)w[p]===void 0&&(w[p]=g[p]);return{$$typeof:o,type:v,key:C,ref:_,props:w,_owner:s.current}}return J.Fragment=l,J.jsx=u,J.jsxs=u,J}var Y={};/**
|
|
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 Ot(){return Je||(Je=1,process.env.NODE_ENV!=="production"&&function(){var a=E,o=Symbol.for("react.element"),l=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),v=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),
|
|
18
|
-
`+
|
|
17
|
+
*/var Je;function Ot(){return Je||(Je=1,process.env.NODE_ENV!=="production"&&function(){var a=E,o=Symbol.for("react.element"),l=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),v=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),_=Symbol.for("react.offscreen"),m=Symbol.iterator,y="@@iterator";function F(t){if(t===null||typeof t!="object")return null;var i=m&&t[m]||t[y];return typeof i=="function"?i:null}var k=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function P(t){{for(var i=arguments.length,c=new Array(i>1?i-1:0),d=1;d<i;d++)c[d-1]=arguments[d];le("error",t,c)}}function le(t,i,c){{var d=k.ReactDebugCurrentFrame,S=d.getStackAddendum();S!==""&&(i+="%s",c=c.concat([S]));var N=c.map(function(b){return String(b)});N.unshift("Warning: "+i),Function.prototype.apply.call(console[t],console,N)}}var ee=!1,V=!1,ce=!1,ue=!1,te=!1,G;G=Symbol.for("react.module.reference");function de(t){return!!(typeof t=="string"||typeof t=="function"||t===n||t===f||te||t===s||t===j||t===p||ue||t===_||ee||V||ce||typeof t=="object"&&t!==null&&(t.$$typeof===C||t.$$typeof===w||t.$$typeof===u||t.$$typeof===v||t.$$typeof===g||t.$$typeof===G||t.getModuleId!==void 0))}function he(t,i,c){var d=t.displayName;if(d)return d;var S=i.displayName||i.name||"";return S!==""?c+"("+S+")":c}function ae(t){return t.displayName||"Context"}function T(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 n:return"Fragment";case l:return"Portal";case f:return"Profiler";case s:return"StrictMode";case j:return"Suspense";case p:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case v:var i=t;return ae(i)+".Consumer";case u:var c=t;return ae(c._context)+".Provider";case g:return he(t,t.render,"ForwardRef");case w:var d=t.displayName||null;return d!==null?d:T(t.type)||"Memo";case C:{var S=t,N=S._payload,b=S._init;try{return T(b(N))}catch{return null}}}return null}var L=Object.assign,q=0,ne,Ne,Te,Pe,De,_e,Oe;function Re(){}Re.__reactDisabledLog=!0;function nt(){{if(q===0){ne=console.log,Ne=console.info,Te=console.warn,Pe=console.error,De=console.group,_e=console.groupCollapsed,Oe=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})}q++}}function st(){{if(q--,q===0){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:L({},t,{value:ne}),info:L({},t,{value:Ne}),warn:L({},t,{value:Te}),error:L({},t,{value:Pe}),group:L({},t,{value:De}),groupCollapsed:L({},t,{value:_e}),groupEnd:L({},t,{value:Oe})})}q<0&&P("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var fe=k.ReactCurrentDispatcher,ge;function se(t,i,c){{if(ge===void 0)try{throw Error()}catch(S){var d=S.stack.trim().match(/\n( *(at )?)/);ge=d&&d[1]||""}return`
|
|
18
|
+
`+ge+t}}var me=!1,re;{var rt=typeof WeakMap=="function"?WeakMap:Map;re=new rt}function Ae(t,i){if(!t||me)return"";{var c=re.get(t);if(c!==void 0)return c}var d;me=!0;var S=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var N;N=fe.current,fe.current=null,nt();try{if(i){var b=function(){throw Error()};if(Object.defineProperty(b.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(b,[])}catch(I){d=I}Reflect.construct(t,[],b)}else{try{b.call()}catch(I){d=I}t.call(b.prototype)}}else{try{throw Error()}catch(I){d=I}t()}}catch(I){if(I&&d&&typeof I.stack=="string"){for(var x=I.stack.split(`
|
|
19
19
|
`),A=d.stack.split(`
|
|
20
|
-
`),D=x.length-1,O=A.length-1;D>=1&&O>=0&&x[D]!==A[O];)O--;for(;D>=1&&O>=0;D--,O--)if(x[D]!==A[O]){if(D!==1||O!==1)do if(D--,O--,O<0||x[D]!==A[O]){var
|
|
21
|
-
`+x[D].replace(" at new "," at ");return t.displayName&&
|
|
20
|
+
`),D=x.length-1,O=A.length-1;D>=1&&O>=0&&x[D]!==A[O];)O--;for(;D>=1&&O>=0;D--,O--)if(x[D]!==A[O]){if(D!==1||O!==1)do if(D--,O--,O<0||x[D]!==A[O]){var M=`
|
|
21
|
+
`+x[D].replace(" at new "," at ");return t.displayName&&M.includes("<anonymous>")&&(M=M.replace("<anonymous>",t.displayName)),typeof t=="function"&&re.set(t,M),M}while(D>=1&&O>=0);break}}}finally{me=!1,fe.current=N,st(),Error.prepareStackTrace=S}var W=t?t.displayName||t.name:"",$=W?se(W):"";return typeof t=="function"&&re.set(t,$),$}function it(t,i,c){return Ae(t,!1)}function ot(t){var i=t.prototype;return!!(i&&i.isReactComponent)}function ie(t,i,c){if(t==null)return"";if(typeof t=="function")return Ae(t,ot(t));if(typeof t=="string")return se(t);switch(t){case j:return se("Suspense");case p:return se("SuspenseList")}if(typeof t=="object")switch(t.$$typeof){case g:return it(t.render);case w:return ie(t.type,i,c);case C:{var d=t,S=d._payload,N=d._init;try{return ie(N(S),i,c)}catch{}}}return""}var z=Object.prototype.hasOwnProperty,Fe={},Le=k.ReactDebugCurrentFrame;function oe(t){if(t){var i=t._owner,c=ie(t.type,t._source,i?i.type:null);Le.setExtraStackFrame(c)}else Le.setExtraStackFrame(null)}function lt(t,i,c,d,S){{var N=Function.call.bind(z);for(var b in t)if(N(t,b)){var x=void 0;try{if(typeof t[b]!="function"){var A=Error((d||"React class")+": "+c+" type `"+b+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[b]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw A.name="Invariant Violation",A}x=t[b](i,b,d,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(D){x=D}x&&!(x instanceof Error)&&(oe(S),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).",d||"React class",c,b,typeof x),oe(null)),x instanceof Error&&!(x.message in Fe)&&(Fe[x.message]=!0,oe(S),P("Failed %s type: %s",c,x.message),oe(null))}}}var ct=Array.isArray;function pe(t){return ct(t)}function ut(t){{var i=typeof Symbol=="function"&&Symbol.toStringTag,c=i&&t[Symbol.toStringTag]||t.constructor.name||"Object";return c}}function dt(t){try{return Ie(t),!1}catch{return!0}}function Ie(t){return""+t}function Be(t){if(dt(t))return P("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ut(t)),Ie(t)}var Q=k.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0},Ue,Me,xe;xe={};function ft(t){if(z.call(t,"ref")){var i=Object.getOwnPropertyDescriptor(t,"ref").get;if(i&&i.isReactWarning)return!1}return t.ref!==void 0}function gt(t){if(z.call(t,"key")){var i=Object.getOwnPropertyDescriptor(t,"key").get;if(i&&i.isReactWarning)return!1}return t.key!==void 0}function mt(t,i){if(typeof t.ref=="string"&&Q.current&&i&&Q.current.stateNode!==i){var c=T(Q.current.type);xe[c]||(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',T(Q.current.type),t.ref),xe[c]=!0)}}function pt(t,i){{var c=function(){Ue||(Ue=!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)",i))};c.isReactWarning=!0,Object.defineProperty(t,"key",{get:c,configurable:!0})}}function xt(t,i){{var c=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)",i))};c.isReactWarning=!0,Object.defineProperty(t,"ref",{get:c,configurable:!0})}}var vt=function(t,i,c,d,S,N,b){var x={$$typeof:o,type:t,key:i,ref:c,props:b,_owner:N};return x._store={},Object.defineProperty(x._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(x,"_self",{configurable:!1,enumerable:!1,writable:!1,value:d}),Object.defineProperty(x,"_source",{configurable:!1,enumerable:!1,writable:!1,value:S}),Object.freeze&&(Object.freeze(x.props),Object.freeze(x)),x};function bt(t,i,c,d,S){{var N,b={},x=null,A=null;c!==void 0&&(Be(c),x=""+c),gt(i)&&(Be(i.key),x=""+i.key),ft(i)&&(A=i.ref,mt(i,S));for(N in i)z.call(i,N)&&!ht.hasOwnProperty(N)&&(b[N]=i[N]);if(t&&t.defaultProps){var D=t.defaultProps;for(N in D)b[N]===void 0&&(b[N]=D[N])}if(x||A){var O=typeof t=="function"?t.displayName||t.name||"Unknown":t;x&&pt(b,O),A&&xt(b,O)}return vt(t,x,A,S,d,Q.current,b)}}var ve=k.ReactCurrentOwner,qe=k.ReactDebugCurrentFrame;function K(t){if(t){var i=t._owner,c=ie(t.type,t._source,i?i.type:null);qe.setExtraStackFrame(c)}else qe.setExtraStackFrame(null)}var be;be=!1;function ye(t){return typeof t=="object"&&t!==null&&t.$$typeof===o}function Ge(){{if(ve.current){var t=T(ve.current.type);if(t)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+t+"`."}return""}}function yt(t){return""}var $e={};function jt(t){{var i=Ge();if(!i){var c=typeof t=="string"?t:t.displayName||t.name;c&&(i=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+c+">.")}return i}}function Ke(t,i){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var c=jt(i);if($e[c])return;$e[c]=!0;var d="";t&&t._owner&&t._owner!==
|
|
25
|
+
Check the top-level render call using <`+c+">.")}return i}}function Ke(t,i){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var c=jt(i);if($e[c])return;$e[c]=!0;var d="";t&&t._owner&&t._owner!==ve.current&&(d=" It was passed a child from "+T(t._owner.type)+"."),K(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.',c,d),K(null)}}function We(t,i){{if(typeof t!="object")return;if(pe(t))for(var c=0;c<t.length;c++){var d=t[c];ye(d)&&Ke(d,i)}else if(ye(t))t._store&&(t._store.validated=!0);else if(t){var S=F(t);if(typeof S=="function"&&S!==t.entries)for(var N=S.call(t),b;!(b=N.next()).done;)ye(b.value)&&Ke(b.value,i)}}}function wt(t){{var i=t.type;if(i==null||typeof i=="string")return;var c;if(typeof i=="function")c=i.propTypes;else if(typeof i=="object"&&(i.$$typeof===g||i.$$typeof===w))c=i.propTypes;else return;if(c){var d=T(i);lt(c,t.props,"prop",d,t)}else if(i.PropTypes!==void 0&&!be){be=!0;var S=T(i);P("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",S||"Unknown")}typeof i.getDefaultProps=="function"&&!i.getDefaultProps.isReactClassApproved&&P("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function St(t){{for(var i=Object.keys(t.props),c=0;c<i.length;c++){var d=i[c];if(d!=="children"&&d!=="key"){K(t),P("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",d),K(null);break}}t.ref!==null&&(K(t),P("Invalid attribute `ref` supplied to `React.Fragment`."),K(null))}}var Ve={};function ze(t,i,c,d,S,N){{var b=de(t);if(!b){var x="";(t===void 0||typeof t=="object"&&t!==null&&Object.keys(t).length===0)&&(x+=" 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 A=yt();A?x+=A:x+=Ge();var D;t===null?D="null":pe(t)?D="array":t!==void 0&&t.$$typeof===o?(D="<"+(T(t.type)||"Unknown")+" />",x=" Did you accidentally export a JSX literal instead of a component?"):D=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",D,x)}var O=bt(t,i,c,S,N);if(O==null)return O;if(b){var M=i.children;if(M!==void 0)if(d)if(pe(M)){for(var W=0;W<M.length;W++)We(M[W],t);Object.freeze&&Object.freeze(M)}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(M,t)}if(z.call(i,"key")){var $=T(t),I=Object.keys(i).filter(function(Pt){return Pt!=="key"}),je=I.length>0?"{key: someKey, "+I.join(": ..., ")+": ...}":"{key: someKey}";if(!Ve[$+je]){var Tt=I.length>0?"{"+I.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} />`,we,G,Tt,G),Ve[G+we]=!0}}return t===n?St(O):wt(O),O}}function Ct(t,i,c){return ze(t,i,c,!0)}function kt(t,i,c){return ze(t,i,c,!1)}var Et=kt,Nt=Ct;X.Fragment=n,X.jsx=Et,X.jsxs=Nt}()),X}process.env.NODE_ENV==="production"?Se.exports=_t():Se.exports=Ot();var e=Se.exports;const Rt=(a,o)=>{const n=R.useQueryClient().getQueryData(["builder_props"]);return h.get(n,a,o)},B=()=>Rt("apiUrl","/chai"),Ce=()=>{const a=R.useQueryClient(),{data:o}=R.useQuery({queryKey:["ai-context"],initialData:"",queryFn:()=>""});return{setAiContext:E.useCallback(n=>{a.setQueryData(["ai-context"],n)},[]),aiContext:o}},At=()=>{const a=B(),{aiContext:o}=Ce();return E.useCallback(async(l,n,s,f)=>{const v=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ASK_AI",data:{type:l,prompt:n,blocks:s,aiContext:o,lang:f}})})).json();return console.log("data",v),v.error?{error:new Error(v.error)}:v},[a,o])},Ft=()=>{const a=B(),{toast:o}=r.useToast();return{getUILibraryBlock:async(f,u)=>{const j=(await(await fetch(f.url+(u.path?"/blocks/"+u.path:"/"+u.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return ee.getBlocksFromHTML(`${j}`)},getUILibraryBlocks:async f=>{try{return(await(await fetch(f.url+"/blocks.json")).json()).map(g=>({...g,preview:f.url.replace("chaiblocks","")+g.preview}))}catch(u){return console.error(u),[]}},onSave:async({page:f,blocks:u})=>{try{return(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:f,blocks:u}})})).ok?(o({title:"Success",description:"Page saved successfully",variant:"default"}),!0):new Error("Failed to save blocks")}catch(v){return v}}}};function te(){const[a,o]=E.useState(new URLSearchParams(window.location.search));return E.useEffect(()=>{const l=()=>{o(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",l),()=>{window.removeEventListener("popstate",l)}},[]),[a,o]}const ke=()=>{const a=B();return R.useQuery({queryKey:["project-pages"],staleTime:1e3*60*5,queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_PAGES"})})).json()})},He=()=>{const[a]=te(),o=a.get("page"),{data:l,isFetching:n}=ke();return{data:E.useMemo(()=>h.find(l,{id:o})||{},[l,o]),isFetching:n}},Lt=()=>R.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[a]=te(),o=a.get("page"),l=B(),{setAiContext:n}=Ce();return R.useQuery({queryKey:["page",o],initialData:[],queryFn:async()=>{const u=(await(await fetch(`${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:o,draft:!0}})})).json()).blocks??[],v=h.find(u,{_type:"@chai/ai-context"});return n(h.get(v,"_value","")||""),u},enabled:!!o})},Bt=a=>E.useMemo(()=>{if(!a||h.isEmpty(a))return{blocks:[],theme:{}};const o=h.find(a,{_type:"@chai/theme"}),l=h.get(o,"_value",{})||{},n=h.filter(a,s=>!h.includes(s==null?void 0:s._type,"@chai/"));return{theme:l,blocks:n}},[a]),Xe=()=>{const a=B();return R.useQuery({queryKey:["project-config"],initialData:{theme:{},fallbackLang:"",languages:[]},queryFn:async()=>{try{const l=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_CONFIG"})})).json();if(l!=null&&l.error)throw"";return l}catch{return{fallbackLang:"fr",languages:["en"],theme:{}}}}})},Ut=()=>{const{data:a}=ke(),o=B();return{getGlobalBlocks:async()=>{const l={};for(const n of a??[])h.isEmpty(n==null?void 0:n.slug)&&(l[n.id]={name:h.startCase(n.name??n.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:[]}},Mt=()=>{const a=B();return{uploadFile:async l=>{const n=new FormData;return n.append("action","UPLOAD_FILE"),n.append("file",l),(await fetch(a,{method:"POST",body:n})).json()}}},qt=()=>{const a=B(),{toast:o}=r.useToast();return R.useMutation({mutationFn:async l=>(await fetch(`${a}`,{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 a=B(),[o]=te(),l=o.get("page");return R.useQuery({queryKey:["language-pages",l],initialData:[],queryFn:async()=>{if(!l)return null;const s=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_LANGUAGE_PAGES",data:{id:l}})})).json();return h.reverse(h.sortBy(s,"primaryPage"))}})},Z={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"},Ze=()=>{const a=B(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>{var u;const f=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"CREATE_PAGE",data:n})})).json();if(f!=null&&f.error)throw new Error(((u=f==null?void 0:f.error)==null?void 0:u.message)||"Something went wrong.");return f},onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`New ${s.global?"global block":"page"} added successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to add new ${s.global?"global block":"page"}.`,description:n.message})}})},Ne=()=>{const a=B(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:n})})).json(),onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage||s!=null&&s.seo)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),s!=null&&s.seo?l({title:"SEO Settings updated successfully."}):l({title:`${s.global?"Global block":"Page"} updated successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to update ${s.global?"global block":"page"}.`,description:n.message})}})},et=()=>{const a=B(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"DELETE_PAGE",data:{id:n==null?void 0:n.id}})})).json(),onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`${s.global?"Global block":"Page"} deleted successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to delete ${s.global?"global block":"page"}.`,description:n.message})}})},Gt=()=>{const a=B(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UNPUBLISH_PAGE",data:{id:n==null?void 0:n.id}})})).json(),onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`${s.global?"Global block":"Page"} unpublished successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to unpublish ${s.global?"global block":"page"}.`,description:n.message})}})},tt=()=>{const{selectedLang:a}=ee.useLanguages(),{data:o,isFetching:l}=Ee();return{data:E.useMemo(()=>h.find(o,{lang:a||""})||{},[o,a]),isFetching:l}},at=()=>{const{data:a,isFetching:o}=tt(),l=a==null?void 0:a.seo,[n,s]=E.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l}),f=E.useRef({initial:n,updated:n}),{selectedLang:u,fallbackLang:v}=ee.useLanguages(),g=u.length?u:v,{mutate:j,isPending:C}=Ne(),m=C;E.useEffect(()=>{!o&&l&&s({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l})},[o,l]);const k=async()=>{j({id:a==null?void 0:a.id,seo:n}),f.current.initial=n,f.current.updated=n},_=()=>{s({...n,ogTitle:n.title,ogDescription:n.description})},p=()=>{s({...n,searchTitle:n.ogTitle,searchDescription:n.ogDescription})},y=I=>{const w={...n,[I.target.name]:I.target.name==="noIndex"||I.target.name==="noFollow"?I.target.checked:I.target.value};s(w),f.current.updated=w};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:h.get(Z,g,g)}),e.jsxs("span",{className:"text-[11px] text-gray-500",children:[" ","( ",a==null?void 0:a.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:n.title,onChange:y,disabled:m,placeholder:"Enter SEO title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The title should be between 10 and 60 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"description",children:"SEO Description"}),e.jsx(r.Textarea,{id:"description",name:"description",value:n.description,onChange:y,disabled:m,placeholder:"Enter SEO description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The description should be between 50 and 160 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"title",children:"Canonical URL"}),e.jsx(r.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:y,disabled:m,placeholder:"Enter Canonical URL"})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(r.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:y,disabled:m,className:"h-4 w-4"}),e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"noIndex",children:"No Index"})]}),e.jsx("p",{className:"mt-2 text-[10px] font-light text-gray-400",children:"Check this if you don't want search engines to index this page."})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(r.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:y,disabled:m,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:_,children:"Copy from SEO Settings"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogTitle",children:"OG Title"}),e.jsx(r.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:y,disabled:m,placeholder:"Enter OG title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG title should be between 10 and 60 characters."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogDescription",children:"OG Description"}),e.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",value:n.ogDescription,onChange:y,disabled:m,placeholder:"Enter OG description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The OG description should be between 50 and 160 characters."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogImage",children:"OG Image URL"}),e.jsx(r.Input,{type:"text",id:"ogImage",name:"ogImage",value:n.ogImage,onChange:y,disabled:m,placeholder:"Enter OG image URL"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"Enter a valid URL for the OG image."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"search",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"Search"}),e.jsx(r.AccordionContent,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(r.Button,{type:"button",variant:"outline",size:"sm",onClick:p,children:"Copy from OG Settings"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchTitle",children:"Search Title"}),e.jsx(r.Input,{type:"text",id:"searchTitle",name:"searchTitle",value:n.searchTitle,onChange:y,disabled:m,placeholder:"Enter search title"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search title should be between 10 and 60 characters."})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"searchDescription",children:"Search Description"}),e.jsx(r.Textarea,{id:"searchDescription",name:"searchDescription",value:n.searchDescription,onChange:y,placeholder:"Enter search description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search description should be between 50 and 160 characters."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"jsonLD",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"JSON-LD"}),e.jsx(r.AccordionContent,{children:e.jsx("div",{className:"space-y-4",children:e.jsx("div",{children:e.jsx(r.Textarea,{id:"jsonLD",name:"jsonLD",rows:3,value:n.jsonLD,onChange:y,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:h.isEqual(f.current.initial,n)||m,children:C?"Saving...":"Save"})})]})};at.displayName="SeoPanel";const $t=({langProps:a,onClose:o,languages:l})=>{const{data:n}=He(),[s,f]=E.useState(a.name||""),[u,v]=E.useState(a.edit?a.lang:""),[g,j]=E.useState(a.edit?a.slug:""),{mutate:C,isPending:m}=Ze(),{mutate:k,isPending:_}=Ne(),p=!!(n!=null&&n.global),y=m||_,I=()=>{const w={name:s,lang:u,primaryPage:n==null?void 0:n.id,slug:g};p||(w.global=!0),a.edit&&(w.id=a==null?void 0:a.id),a.edit?k(w,{onSuccess:o}):C(w,{onSuccess:o})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:o,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:a.edit?"Edit language":"Add New language"}),e.jsx(r.DialogDescription,{children:"Enter the details for the language"})]}),e.jsxs("form",{children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"lang",className:"text-right",children:"Language"}),e.jsxs("select",{value:u,disabled:a.edit||h.isEmpty(l),onChange:w=>{const T=w.target.value;v(T),!p&&j(`/${T}`)},className:"flex h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 col-span-3",children:[e.jsx("option",{value:"",disabled:!0,selected:!0,children:a.edit?h.get(Z,a.lang,a.lang):h.isEmpty(l)?"All available language page is created.":"Choose language"}),h.map(l,w=>e.jsx("option",{value:w,children:h.get(Z,w,w)},w))]})]}),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:s,onChange:w=>f(w.target.value),className:"col-span-3",required:!0,placeholder:"Enter page name"})]}),!p&&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:w=>{const T=w.target.value;h.startsWith(T,`/${u}`)&&j(h.toLower(h.trim(T)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:h.isEmpty(u),title:"Slug must start with /",placeholder:h.isEmpty(u)?"Choose language to add slug":"Enter page slug"})]})]}),e.jsx(r.DialogFooter,{children:e.jsx(r.Button,{onClick:I,type:"button",disabled:y||!u||!p&&!h.startsWith(g,`/${u}`),children:y?a.edit?"Updating...":"Adding...":a.edit?"Update":"Add new language"})})]})]})})},Kt=()=>{const[a,o]=E.useState(null),{selectedLang:l,fallbackLang:n,setSelectedLang:s}=ee.useLanguages(),{data:f,isFetching:u}=Ee(),{mutate:v,isPending:g}=et(),{data:j}=tt(),{data:C}=Xe(),m=h.filter(h.get(C,"languages")||["en"],k=>!h.find(f,{lang:k})&&k!==h.get(C,"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"})]}):h.map(f,k=>{const _=k.lang,p=k.slug,y=!k.primaryPage,I=_===l;return y?null:e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`w-full p-2 rounded cursor-pointer flex items-center justify-between ${I?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>s(_),children:[e.jsxs("div",{className:" flex-1 gap-x-3",children:[e.jsx("div",{className:"text-[13px]",children:h.get(Z,y?n:_,_)}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Slug:",e.jsxs("b",{children:[" ",p]})]}),e.jsxs("div",{className:"text-[11px] text-gray-500",children:["Name:",e.jsxs("b",{children:[" ",k.name," "]})]})]})]}),y?e.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[e.jsx(L.StarIcon,{fill:"orange",className:"w-3 h-3"}),e.jsx("b",{children:" Default"})]}):e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx(L.PencilIcon,{onClick:w=>{w.stopPropagation(),o({...k,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),e.jsxs(r.Popover,{children:[e.jsx(r.PopoverTrigger,{children:e.jsx(L.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:h.get(Z,_,_)})," language?"]}),e.jsx("div",{className:"flex items-center justify-end w-full",children:e.jsx(r.Button,{size:"sm",variant:"destructive",disabled:g,onClick:()=>v(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:h.isEmpty(m),onClick:()=>o({name:j==null?void 0:j.name,lang:"",slug:"",edit:!1}),children:"+ Add new language"})}),a&&e.jsx($t,{languages:m,langProps:a,onClose:()=>o(null)})]})};function Wt({page:a,onClose:o,onDelete:l}){const{mutate:n,isPending:s}=et(),f=()=>{n(a,{onSuccess:()=>{l()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:o,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm Deletion"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to remove ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)})," ",a!=null&&a.global?"global block?":"page? This will also delete all associated language pages."]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:o,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:s,onClick:f,children:s?"Deleting...":"Delete"})]})]})})}const Vt=({page:a,onClose:o,onUnpublish:l})=>{const{mutate:n,isPending:s}=Gt(),f=async()=>{n(a,{onSuccess:()=>{l()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:o,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm Unpublish"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to unpublish ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)}),"?"]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:o,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:s,onClick:f,children:s?"Unpublishing...":"Unpublish"})]})]})})},zt=({activePage:a,editPage:o,onShowUpsertPage:l})=>{const[n,s]=E.useState("pages"),{data:f,isFetching:u}=ke(),[v,g]=E.useState(null),[j,C]=E.useState(null),m=k=>h.orderBy(h.filter(k,p=>n==="pages"?p.slug:!p.slug),"name","asc").map(p=>e.jsxs(r.Button,{onClick:()=>o(p.id),variant:p.id===a?"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",children:[p.global?e.jsx(L.GlobeIcon,{className:"h-4 w-4"}):e.jsx(L.File,{className:"h-4 w-4"}),e.jsx("span",{children:p.name??p.slug}),(p==null?void 0:p.slug)&&e.jsxs("span",{className:"text-xs font-light",children:["( ",p.slug," )"]})]}),e.jsx("div",{className:"flex items-center space-x-4",children:e.jsxs(r.DropdownMenu,{children:[e.jsx(r.DropdownMenuTrigger,{asChild:!0,onClick:y=>y.stopPropagation(),children:e.jsx(r.Button,{variant:"ghost",size:"sm",className:`h-8 w-8 p-0 hover:bg-transparent ${p.id===a?" hover:text-gray-200":"bg-transparent "}`,children:e.jsx(L.MoreVertical,{className:"h-4 w-4"})})}),e.jsxs(r.DropdownMenuContent,{align:"end",className:"text-sm font-medium",children:[e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2",onClick:y=>{y.stopPropagation(),l({...p,global:n==="globalBlocks"})},children:[e.jsx(L.PencilIcon,{className:"size-3",strokeWidth:3}),"Edit"]}),e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2",onClick:y=>{y.stopPropagation(),g(p)},children:[e.jsx(L.TrashIcon,{className:"size-3",strokeWidth:3}),"Delete"]}),e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2",onClick:y=>{y.stopPropagation(),C(p)},children:[e.jsx(L.Power,{className:"size-3",strokeWidth:3}),"Unpublish"]})]})]})})]},p.id));return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs(r.Tabs,{value:n,className:"w-full",onValueChange:s,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 ",n==="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:()=>l({slug:"",name:"",global:n==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[e.jsx(L.Plus,{className:"h-4 w-4 mr-2"}),u?"Loading...":`Add new ${n==="pages"?"page":"global block"}`]})}),e.jsx("div",{className:"pt-4",children:e.jsx("div",{className:"space-y-2",children:u?e.jsx(Qt,{}):m(f)})})]})]}),e.jsx(Wt,{page:v,onClose:()=>g(null),onDelete:()=>{g(null)}}),e.jsx(Vt,{page:j,onClose:()=>C(null),onUnpublish:()=>{C(null)}})]})};function Qt(){return e.jsx("div",{className:"h-32 w-full flex justify-center items-center text-sm animate-pulse",children:"Loading..."})}const Jt=({editPage:a,showUpsertPage:o,setShowUpsertPage:l})=>{const n=o.id,[s,f]=E.useState(n&&o.name||""),[u,v]=E.useState(n&&o.slug||""),{mutate:g,isPending:j}=Ze(),{mutate:C,isPending:m}=Ne(),k=j||m,_=()=>{n?C({name:s,slug:u,id:o.id,global:!!o.global},{onSuccess:()=>{l(void 0)}}):g({name:s,slug:u,global:!!o.global},{onSuccess:p=>{a(p.id)}})};return e.jsx(r.Dialog,{open:!!o,onOpenChange:()=>l(void 0),children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsxs(r.DialogTitle,{children:[n?"Edit":"Add New"," ",o.global?"Global Block":"Page"]}),e.jsxs(r.DialogDescription,{children:["Enter the details for the new"," ",o.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:s,placeholder:`Enter ${o.global?"global block":"page"} name`,onChange:p=>f(p.target.value),className:"col-span-3",required:!0})]}),!o.global&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:o.global?"Identifier":"Slug"}),e.jsx(r.Input,{id:"slug",value:u,onChange:p=>{var y;return v((y=p.target.value)==null?void 0:y.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:_,type:"button",disabled:k||!s||!o.global&&!u.startsWith("/")||h.isEqual(o.name,s)&&h.isEqual(o.slug,u),children:k?n?"Updating...":"Adding...":o.global?`${n?"Update":"Add"} global block`:`${n?"Update":"Add"} Page`})})]})]})})};function Yt(a){const{activePage:o,canClose:l,open:n,close:s}=a,[,f]=te(),[u,v]=E.useState(),g=j=>{window.history.pushState({},"",`?page=${j}`),f(new URLSearchParams({page:j})),window.dispatchEvent(new PopStateEvent("popstate")),v(void 0),s()};return e.jsx(r.Sheet,{open:n,onOpenChange:j=>{!j&&l&&s()},children:e.jsxs(r.SheetContent,{side:"left",className:`border-border w-full ${l?"":"sheet-hide-close-btn"}`,children:[e.jsx("div",{children:e.jsx(zt,{onShowUpsertPage:j=>v(j),activePage:o,editPage:g})}),u&&e.jsx(Jt,{editPage:g,showUpsertPage:u,setShowUpsertPage:v})]})})}Dt.loadWebBlocks();const Ht=a=>{const o=E.useRef([]),[l]=te(),n=l.get("page"),{data:s,isFetching:f}=He(),{data:u}=Lt(),{data:v,isFetching:g}=It(),{blocks:j,theme:C}=Bt(v),{data:m}=Xe(),{data:k}=Ee(),_=At(),{uploadFile:p}=Mt(),{getUILibraryBlock:y,getUILibraryBlocks:I,onSave:w}=Ft(),{getGlobalBlocks:T,getGlobalBlockBlocks:ce}=Ut(),{mutate:ue,isPending:ae}=qt(),{aiContext:z,setAiContext:de}=Ce();o.current=j;const[he,Q]=E.useState(!1),[$,fe]=E.useState("SAVED");E.useEffect(()=>{const P=M=>{$==="UNSAVED"&&(M.preventDefault(),M.returnValue=!1)};return $==="UNSAVED"&&window.addEventListener("beforeunload",P),()=>{window.removeEventListener("beforeunload",P)}},[$]);const ne=E.useMemo(()=>{const P={};return m!=null&&m.theme&&(P.brandingOptions=m.theme),P},[m]),U=E.useMemo(()=>Array.isArray(a==null?void 0:a.uiLibraries)?[...u,...a==null?void 0:a.uiLibraries]:u,[u,a==null?void 0:a.uiLibraries]);return e.jsxs(e.Fragment,{children:[e.jsx(ee.ChaiBuilderEditor,{loading:g,...a.fallbackLang&&{fallbackLang:a.fallbackLang||"en"},...a.languages&&{languages:h.map(k,"lang")||[]},translations:a.translations||{},locale:a.locale||"en",htmlDir:a.htmlDir||"ltr",autoSaveSupport:a.autoSaveSupport||!1,autoSaveInterval:a.autoSaveInterval||15,uploadMediaCallback:p,onError:a.onError||console.error,getGlobalBlockBlocks:ce,getGlobalBlocks:T,blocks:j,getUILibraryBlock:y,getUILibraryBlocks:I,brandingOptions:C,uiLibraries:U,saveAiContextCallback:async P=>{if(!n)return!0;const M=o.current,K={_type:"@chai/ai-context",_value:h.isString(P)?P:""},se=[...M,K];return await w({page:n,blocks:se}),de(P),!0},onSaveStateChange:P=>fe(P),aiContext:z,askAiCallBack:_,onSave:async({blocks:P})=>{if(!n)return!0;o.current=P;const M={_type:"@chai/ai-context",_value:h.isString(z)?z:""},K=[...P,M];return await w({page:n,blocks:K}),o.current=P,!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:()=>Q(!0),children:[h.includes(s.slug,"/")?e.jsx(L.File,{className:"h-4 w-4"}):e.jsx(L.GlobeIcon,{className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:(s==null?void 0:s.name)??""}),e.jsx(L.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[()=>e.jsxs(r.Button,{disabled:ae||$!=="SAVED",size:"sm",variant:"default",onClick:()=>ue(n),children:[e.jsx(L.RocketIcon,{className:"h-4 w-4"})," "," ",ae?"Publishing...":"Publish"]})]},sideBarComponents:{top:[...s!=null&&s.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"})]})})}],...(m==null?void 0:m.languages.length)>0?[{label:"Language Pages",component:Kt,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"})]})})})}]:[]]},...ne}),e.jsx(Yt,{activePage:n||"",canClose:!!n&&!h.isEmpty(s),open:!n||!f&&h.isEmpty(s)||he,close:()=>Q(!1)})]})},Ye=new R.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),Xt=a=>(Ye.setQueryData(["builder_props"],a),e.jsx(R.QueryClientProvider,{client:Ye,children:e.jsx(Ht,{...a})}));module.exports=Xt;
|
|
30
|
+
<%s key={someKey} {...props} />`,je,$,Tt,$),Ve[$+je]=!0}}return t===n?St(O):wt(O),O}}function Ct(t,i,c){return ze(t,i,c,!0)}function kt(t,i,c){return ze(t,i,c,!1)}var Et=kt,Nt=Ct;Y.Fragment=n,Y.jsx=Et,Y.jsxs=Nt}()),Y}process.env.NODE_ENV==="production"?we.exports=_t():we.exports=Ot();var e=we.exports;const Rt=(a,o)=>{const n=R.useQueryClient().getQueryData(["builder_props"]);return h.get(n,a,o)},U=()=>Rt("apiUrl","/chai/api"),Se=()=>{const a=R.useQueryClient(),{data:o}=R.useQuery({queryKey:["ai-context"],initialData:"",queryFn:()=>""});return{setAiContext:E.useCallback(n=>{a.setQueryData(["ai-context"],n)},[]),aiContext:o}},At=()=>{const a=U(),{aiContext:o}=Se();return E.useCallback(async(l,n,s,f)=>{const v=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ASK_AI",data:{type:l,prompt:n,blocks:s,aiContext:o,lang:f}})})).json();return console.log("data",v),v.error?{error:new Error(v.error)}:v},[a,o])},Ft=()=>{const a=U(),{toast:o}=r.useToast();return{getUILibraryBlock:async(f,u)=>{const j=(await(await fetch(f.url+(u.path?"/blocks/"+u.path:"/"+u.uuid+".html"))).text()).replace(/---([\s\S]*?)---/g,"");return X.getBlocksFromHTML(`${j}`)},getUILibraryBlocks:async f=>{try{return(await(await fetch(f.url+"/blocks.json")).json()).map(g=>({...g,preview:f.url.replace("chaiblocks","")+g.preview}))}catch(u){return console.error(u),[]}},onSave:async({page:f,blocks:u})=>{try{return(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:{id:f,blocks:u}})})).ok?(o({title:"Success",description:"Page saved successfully",variant:"default"}),!0):new Error("Failed to save blocks")}catch(v){return v}}}};function Z(){const[a,o]=E.useState(new URLSearchParams(window.location.search));return E.useEffect(()=>{const l=()=>{o(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",l),()=>{window.removeEventListener("popstate",l)}},[]),[a,o]}const Ce=()=>{const a=U();return R.useQuery({queryKey:["project-pages"],staleTime:1e3*60*5,queryFn:async()=>await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_PAGES"})})).json()})},He=()=>{const[a]=Z(),o=a.get("page"),{data:l,isFetching:n}=Ce();return{data:E.useMemo(()=>h.find(l,{id:o})||{},[l,o]),isFetching:n}},Lt=()=>R.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[a]=Z(),o=a.get("page"),l=U(),{setAiContext:n}=Se();return R.useQuery({queryKey:["page",o],initialData:[],queryFn:async()=>{const u=(await(await fetch(`${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PAGE",data:{id:o,draft:!0}})})).json()).blocks??[],v=h.find(u,{_type:"@chai/ai-context"});return n(h.get(v,"_value","")||""),u},enabled:!!o})},Bt=a=>E.useMemo(()=>{if(!a||h.isEmpty(a))return{blocks:[],theme:{}};const o=h.find(a,{_type:"@chai/theme"}),l=h.get(o,"_value",{})||{},n=h.filter(a,s=>!h.includes(s==null?void 0:s._type,"@chai/"));return{theme:l,blocks:n}},[a]),Xe=()=>{const a=U();return R.useQuery({queryKey:["project-config"],initialData:{theme:{},fallbackLang:"",languages:[]},queryFn:async()=>{try{const l=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_PROJECT_CONFIG"})})).json();if(l!=null&&l.error)throw"";return l}catch{return{fallbackLang:"fr",languages:["en"],theme:{}}}}})},Ut=()=>{const{data:a}=Ce(),o=U();return{getGlobalBlocks:async()=>{const l={};for(const n of a??[])h.isEmpty(n==null?void 0:n.slug)&&(l[n.id]={name:h.startCase(n.name??n.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:[]}},Mt=()=>{const a=U();return{uploadFile:async l=>{const n=new FormData;return n.append("action","UPLOAD_FILE"),n.append("file",l),(await fetch(a,{method:"POST",body:n})).json()}}},qt=()=>{const a=U(),{toast:o}=r.useToast();return R.useMutation({mutationFn:async l=>(await fetch(`${a}`,{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"})}})},ke=()=>{const a=U(),[o]=Z(),l=o.get("page");return R.useQuery({queryKey:["language-pages",l],initialData:[],queryFn:async()=>{if(!l)return null;const s=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"GET_LANGUAGE_PAGES",data:{id:l}})})).json();return h.reverse(h.sortBy(s,"primaryPage"))}})},H={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"},Ze=()=>{const a=U(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>{var u;const f=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"CREATE_PAGE",data:n})})).json();if(f!=null&&f.error)throw new Error(((u=f==null?void 0:f.error)==null?void 0:u.message)||"Something went wrong.");return f},onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`New ${s.global?"global block":"page"} added successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to add new ${s.global?"global block":"page"}.`,description:n.message})}})},Ee=()=>{const a=U(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UPDATE_PAGE",data:n})})).json(),onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage||s!=null&&s.seo)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),s!=null&&s.seo?l({title:"SEO Settings updated successfully."}):l({title:`${s.global?"Global block":"Page"} updated successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to update ${s.global?"global block":"page"}.`,description:n.message})}})},et=()=>{const a=U(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"DELETE_PAGE",data:{id:n==null?void 0:n.id}})})).json(),onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`${s.global?"Global block":"Page"} deleted successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to delete ${s.global?"global block":"page"}.`,description:n.message})}})},Gt=()=>{const a=U(),o=R.useQueryClient(),{toast:l}=r.useToast();return R.useMutation({mutationFn:async n=>(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"UNPUBLISH_PAGE",data:{id:n==null?void 0:n.id}})})).json(),onSuccess:(n,s)=>{s&&(s!=null&&s.primaryPage)?o.invalidateQueries({queryKey:["language-pages",s==null?void 0:s.primaryPage]}):o.invalidateQueries({queryKey:["project-pages"]}),l({title:`${s.global?"Global block":"Page"} unpublished successfully.`})},onError:(n,s)=>{l({variant:"destructive",title:`Failed to unpublish ${s.global?"global block":"page"}.`,description:n.message})}})},tt=()=>{const{selectedLang:a}=X.useLanguages(),{data:o,isFetching:l}=ke();return{data:E.useMemo(()=>h.find(o,{lang:a||""})||{},[o,a]),isFetching:l}},at=()=>{const{data:a,isFetching:o}=tt(),l=a==null?void 0:a.seo,[n,s]=E.useState({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l}),f=E.useRef({initial:n,updated:n}),{selectedLang:u,fallbackLang:v}=X.useLanguages(),g=u.length?u:v,{mutate:j,isPending:p}=Ee(),w=p;E.useEffect(()=>{!o&&l&&s({title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",searchTitle:"",searchDescription:"",jsonLD:"",...l})},[o,l]);const C=async()=>{j({id:a==null?void 0:a.id,seo:n}),f.current.initial=n,f.current.updated=n},_=()=>{s({...n,ogTitle:n.title,ogDescription:n.description})},m=()=>{s({...n,searchTitle:n.ogTitle,searchDescription:n.ogDescription})},y=F=>{const k={...n,[F.target.name]:F.target.name==="noIndex"||F.target.name==="noFollow"?F.target.checked:F.target.value};s(k),f.current.updated=k};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:h.get(H,g,g)}),e.jsxs("span",{className:"text-[11px] text-gray-500",children:[" ","( ",a==null?void 0:a.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:n.title,onChange:y,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:n.description,onChange:y,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:n.canonicalUrl,onChange:y,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:n.noIndex,onChange:y,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:n.noFollow,onChange:y,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:_,children:"Copy from SEO Settings"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs pb-1",htmlFor:"ogTitle",children:"OG Title"}),e.jsx(r.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:y,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:n.ogDescription,onChange:y,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:n.ogImage,onChange:y,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:n.searchTitle,onChange:y,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:n.searchDescription,onChange:y,placeholder:"Enter search description"}),e.jsx("p",{className:"mt-1 text-[10px] font-light text-gray-400",children:"The search description should be between 50 and 160 characters."})]})]})})]}),e.jsxs(r.AccordionItem,{value:"jsonLD",children:[e.jsx(r.AccordionTrigger,{className:"text-blue-500",children:"JSON-LD"}),e.jsx(r.AccordionContent,{children:e.jsx("div",{className:"space-y-4",children:e.jsx("div",{children:e.jsx(r.Textarea,{id:"jsonLD",name:"jsonLD",rows:3,value:n.jsonLD,onChange:y,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:C,disabled:h.isEqual(f.current.initial,n)||w,children:p?"Saving...":"Save"})})]})};at.displayName="SeoPanel";const $t=({langProps:a,onClose:o,languages:l})=>{const{data:n}=He(),[s,f]=E.useState(a.name||""),[u,v]=E.useState(a.edit?a.lang:""),[g,j]=E.useState(a.edit?a.slug:""),{mutate:p,isPending:w}=Ze(),{mutate:C,isPending:_}=Ee(),m=!!(n!=null&&n.global),y=w||_,F=()=>{const k={name:s,lang:u,primaryPage:n==null?void 0:n.id,slug:g};m||(k.global=!0),a.edit&&(k.id=a==null?void 0:a.id),a.edit?C(k,{onSuccess:o}):p(k,{onSuccess:o})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:o,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:a.edit?"Edit language":"Add New language"}),e.jsx(r.DialogDescription,{children:"Enter the details for the language"})]}),e.jsxs("form",{children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"lang",className:"text-right",children:"Language"}),e.jsxs("select",{value:u,disabled:a.edit||h.isEmpty(l),onChange:k=>{const P=k.target.value;v(P),!m&&j(`/${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:a.edit?h.get(H,a.lang,a.lang):h.isEmpty(l)?"All available language page is created.":"Choose language"}),h.map(l,k=>e.jsx("option",{value:k,children:h.get(H,k,k)},k))]})]}),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:s,onChange:k=>f(k.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:k=>{const P=k.target.value;h.startsWith(P,`/${u}`)&&j(h.toLower(h.trim(P)))},className:"col-span-3",required:!0,pattern:"^/.*",disabled:h.isEmpty(u),title:"Slug must start with /",placeholder:h.isEmpty(u)?"Choose language to add slug":"Enter page slug"})]})]}),e.jsx(r.DialogFooter,{children:e.jsx(r.Button,{onClick:F,type:"button",disabled:y||!u||!m&&!h.startsWith(g,`/${u}`),children:y?a.edit?"Updating...":"Adding...":a.edit?"Update":"Add new language"})})]})]})})},Kt=()=>{const[a,o]=E.useState(null),{selectedLang:l,fallbackLang:n,setSelectedLang:s}=X.useLanguages(),{data:f,isFetching:u}=ke(),{mutate:v,isPending:g}=et(),{data:j}=tt(),{data:p}=Xe(),w=h.filter(h.get(p,"languages")||["en"],C=>!h.find(f,{lang:C})&&C!==h.get(p,"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"})]}):h.map(f,C=>{const _=C.lang,m=C.slug,y=!C.primaryPage,F=_===l;return y?null:e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`w-full p-2 rounded cursor-pointer flex items-center justify-between ${F?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>s(_),children:[e.jsxs("div",{className:" flex-1 gap-x-3",children:[e.jsx("div",{className:"text-[13px]",children:h.get(H,y?n:_,_)}),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:[" ",C.name," "]})]})]})]}),y?e.jsxs("div",{className:"flex items-center text-[11px] text-orange-500 gap-x-1",children:[e.jsx(B.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(B.PencilIcon,{onClick:k=>{k.stopPropagation(),o({...C,edit:!0})},className:"w-3 h-3 hover:text-blue-500"}),e.jsxs(r.Popover,{children:[e.jsx(r.PopoverTrigger,{children:e.jsx(B.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:h.get(H,_,_)})," language?"]}),e.jsx("div",{className:"flex items-center justify-end w-full",children:e.jsx(r.Button,{size:"sm",variant:"destructive",disabled:g,onClick:()=>v(C),children:g?"Deleting...":"Delete"})})]})})]})]})]},C.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:h.isEmpty(w),onClick:()=>o({name:j==null?void 0:j.name,lang:"",slug:"",edit:!1}),children:"+ Add new language"})}),a&&e.jsx($t,{languages:w,langProps:a,onClose:()=>o(null)})]})};function Wt({page:a,onClose:o,onDelete:l}){const{mutate:n,isPending:s}=et(),f=()=>{n(a,{onSuccess:()=>{l()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:o,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm Deletion"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to remove ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)})," ",a!=null&&a.global?"global block?":"page? This will also delete all associated language pages."]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:o,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:s,onClick:f,children:s?"Deleting...":"Delete"})]})]})})}const Vt=({page:a,onClose:o,onUnpublish:l})=>{const{mutate:n,isPending:s}=Gt(),f=async()=>{n(a,{onSuccess:()=>{l()}})};return e.jsx(r.Dialog,{open:!!a,onOpenChange:o,children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Confirm Unpublish"}),e.jsxs(r.DialogDescription,{children:["Are you sure you want to unpublish ",e.jsx("b",{children:(a==null?void 0:a.name)??(a==null?void 0:a.slug)}),"?"]})]}),e.jsxs(r.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:o,children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",disabled:s,onClick:f,children:s?"Unpublishing...":"Unpublish"})]})]})})},zt=({activePage:a,editPage:o,onShowUpsertPage:l})=>{const[n,s]=E.useState("pages"),{data:f,isFetching:u}=Ce(),[v,g]=E.useState(null),[j,p]=E.useState(null),w=C=>h.orderBy(h.filter(C,m=>n==="pages"?m.slug:!m.slug),"name","asc").map(m=>e.jsxs(r.Button,{onClick:()=>o(m.id),variant:m.id===a?"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",children:[m.global?e.jsx(B.GlobeIcon,{className:"h-4 w-4"}):e.jsx(B.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.jsx("div",{className:"flex items-center space-x-4",children:e.jsxs(r.DropdownMenu,{children:[e.jsx(r.DropdownMenuTrigger,{asChild:!0,onClick:y=>y.stopPropagation(),children:e.jsx(r.Button,{variant:"ghost",size:"sm",className:`h-8 w-8 p-0 hover:bg-transparent ${m.id===a?" hover:text-gray-200":"bg-transparent "}`,children:e.jsx(B.MoreVertical,{className:"h-4 w-4"})})}),e.jsxs(r.DropdownMenuContent,{align:"end",className:"text-sm font-medium",children:[e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2",onClick:y=>{y.stopPropagation(),l({...m,global:n==="globalBlocks"})},children:[e.jsx(B.PencilIcon,{className:"size-3",strokeWidth:3}),"Edit"]}),e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2",onClick:y=>{y.stopPropagation(),g(m)},children:[e.jsx(B.TrashIcon,{className:"size-3",strokeWidth:3}),"Delete"]}),e.jsxs(r.DropdownMenuItem,{className:"flex items-center gap-2",onClick:y=>{y.stopPropagation(),p(m)},children:[e.jsx(B.Power,{className:"size-3",strokeWidth:3}),"Unpublish"]})]})]})})]},m.id));return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs(r.Tabs,{value:n,className:"w-full",onValueChange:s,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 ",n==="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:()=>l({slug:"",name:"",global:n==="globalBlocks"}),className:"mb-4 w-1/2 bg-blue-500 hover:bg-blue-400",children:[e.jsx(B.Plus,{className:"h-4 w-4 mr-2"}),u?"Loading...":`Add new ${n==="pages"?"page":"global block"}`]})}),e.jsx("div",{className:"pt-4",children:e.jsx("div",{className:"space-y-2",children:u?e.jsx(Qt,{}):w(f)})})]})]}),e.jsx(Wt,{page:v,onClose:()=>g(null),onDelete:()=>{g(null)}}),e.jsx(Vt,{page:j,onClose:()=>p(null),onUnpublish:()=>{p(null)}})]})};function Qt(){return e.jsx("div",{className:"h-32 w-full flex justify-center items-center text-sm animate-pulse",children:"Loading..."})}const Jt=({editPage:a,showUpsertPage:o,setShowUpsertPage:l})=>{const n=o.id,[s,f]=E.useState(n&&o.name||""),[u,v]=E.useState(n&&o.slug||""),{mutate:g,isPending:j}=Ze(),{mutate:p,isPending:w}=Ee(),C=j||w,_=()=>{n?p({name:s,slug:u,id:o.id,global:!!o.global},{onSuccess:()=>{l(void 0)}}):g({name:s,slug:u,global:!!o.global},{onSuccess:m=>{a(m.id)}})};return e.jsx(r.Dialog,{open:!!o,onOpenChange:()=>l(void 0),children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsxs(r.DialogTitle,{children:[n?"Edit":"Add New"," ",o.global?"Global Block":"Page"]}),e.jsxs(r.DialogDescription,{children:["Enter the details for the new"," ",o.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:s,placeholder:`Enter ${o.global?"global block":"page"} name`,onChange:m=>f(m.target.value),className:"col-span-3",required:!0})]}),!o.global&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(r.Label,{htmlFor:"slug",className:"text-right",children:o.global?"Identifier":"Slug"}),e.jsx(r.Input,{id:"slug",value:u,onChange:m=>{var y;return v((y=m.target.value)==null?void 0:y.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:_,type:"button",disabled:C||!s||!o.global&&!u.startsWith("/")||h.isEqual(o.name,s)&&h.isEqual(o.slug,u),children:C?n?"Updating...":"Adding...":o.global?`${n?"Update":"Add"} global block`:`${n?"Update":"Add"} Page`})})]})]})})};function Yt(a){const{activePage:o,canClose:l,open:n,close:s}=a,[,f]=Z(),[u,v]=E.useState(),g=j=>{window.history.pushState({},"",`?page=${j}`),f(new URLSearchParams({page:j})),window.dispatchEvent(new PopStateEvent("popstate")),v(void 0),s()};return e.jsx(r.Sheet,{open:n,onOpenChange:j=>{!j&&l&&s()},children:e.jsxs(r.SheetContent,{side:"left",className:`border-border w-full ${l?"":"sheet-hide-close-btn"}`,children:[e.jsx("div",{children:e.jsx(zt,{onShowUpsertPage:j=>v(j),activePage:o,editPage:g})}),u&&e.jsx(Jt,{editPage:g,showUpsertPage:u,setShowUpsertPage:v})]})})}Dt.loadWebBlocks();const Ht=a=>{const o=E.useRef([]),[l]=Z(),n=l.get("page"),{data:s,isFetching:f}=He(),{data:u}=Lt(),{data:v,isFetching:g}=It(),{blocks:j}=Bt(v),{data:p}=Xe(),{data:w}=ke(),C=At(),{uploadFile:_}=Mt(),{getUILibraryBlock:m,getUILibraryBlocks:y,onSave:F}=Ft(),{getGlobalBlocks:k,getGlobalBlockBlocks:P}=Ut(),{mutate:le,isPending:ee}=qt(),{aiContext:V,setAiContext:ce}=Se();o.current=j;const[ue,te]=E.useState(!1),[G,de]=E.useState("SAVED");E.useEffect(()=>{const T=L=>{G==="UNSAVED"&&(L.preventDefault(),L.returnValue=!1)};return G==="UNSAVED"&&window.addEventListener("beforeunload",T),()=>{window.removeEventListener("beforeunload",T)}},[G]);const he=E.useMemo(()=>{const T={};return p!=null&&p.theme&&(T.brandingOptions=p.theme),T},[p]),ae=E.useMemo(()=>Array.isArray(a==null?void 0:a.uiLibraries)?[...u,...a==null?void 0:a.uiLibraries]:u,[u,a==null?void 0:a.uiLibraries]);return e.jsxs(e.Fragment,{children:[e.jsx(X.ChaiBuilderEditor,{loading:g,...a.fallbackLang&&{fallbackLang:a.fallbackLang||"en"},...a.languages&&{languages:h.map(w,"lang")||[]},translations:a.translations||{},locale:a.locale||"en",htmlDir:a.htmlDir||"ltr",autoSaveSupport:a.autoSaveSupport||!1,autoSaveInterval:a.autoSaveInterval||15,uploadMediaCallback:_,onError:a.onError||console.error,getGlobalBlockBlocks:P,getGlobalBlocks:k,blocks:j,getUILibraryBlock:m,getUILibraryBlocks:y,uiLibraries:ae,saveAiContextCallback:async T=>{if(!n)return!0;const L=o.current,q={_type:"@chai/ai-context",_value:h.isString(T)?T:""},ne=[...L,q];return await F({page:n,blocks:ne}),ce(T),!0},onSaveStateChange:T=>de(T),aiContext:V,askAiCallBack:C,onSave:async({blocks:T})=>{if(!n)return!0;o.current=T;const L={_type:"@chai/ai-context",_value:h.isString(V)?V:""},q=[...T,L];return await F({page:n,blocks:q}),o.current=T,!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:()=>te(!0),children:[h.includes(s.slug,"/")?e.jsx(B.File,{className:"h-4 w-4"}):e.jsx(B.GlobeIcon,{className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:(s==null?void 0:s.name)??""}),e.jsx(B.ArrowLeftRightIcon,{className:"h-4 w-4"})]},"template-viewer")],right:[()=>e.jsxs(r.Button,{disabled:ee||G!=="SAVED",size:"sm",variant:"default",onClick:()=>le(n),children:[e.jsx(B.RocketIcon,{className:"h-4 w-4"})," "," ",ee?"Publishing...":"Publish"]})]},sideBarComponents:{top:[...s!=null&&s.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"})]})})}],...(p==null?void 0:p.languages.length)>0?[{label:"Language Pages",component:Kt,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"})]})})})}]:[]]},...he}),e.jsx(Yt,{activePage:n||"",canClose:!!n&&!h.isEmpty(s),open:!n||!f&&h.isEmpty(s)||ue,close:()=>te(!1)})]})},Ye=new R.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1}}}),Xt=a=>(Ye.setQueryData(["builder_props"],a),e.jsx(R.QueryClientProvider,{client:Ye,children:e.jsx(Ht,{...a})}));module.exports=Xt;
|