decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
5 lines (4 loc) • 8.94 kB
JavaScript
import{c as W,j as y,b as q,r as P,D as z,v as B,w as F,x as M,B as A,t as N}from"./index-ztdGKvBm.js";import{i as $}from"./CheckCircle-DZ8MNpCP.js";import{e as H}from"./agent-icon-BYWtutu9.js";import{MonacoCodeEditor as V}from"./monaco-editor-CLzWWWtl.js";import{u as G,k as L}from"./use-never-published-BJeGnEQC.js";function Q({open:n,onOpenChange:e,pageKey:r,decofile:t,onSave:a}){const s=q(),i=t[r],o=i===void 0,c=o?"":JSON.stringify(i,null,2),[l,p]=P.useState(!1),[v,m]=P.useState(c),[C,D]=P.useState(!1),u=!a||o,E=v!==c,f=()=>{navigator.clipboard.writeText(v).then(()=>{p(!0),setTimeout(()=>p(!1),2e3)})},h=async w=>{if(!a||C)return;let S;try{S=JSON.parse(w)}catch{N.error(s("sectionsEditor.pageJsonDialog.invalidJsonError"));return}D(!0);try{const g=await a(S);L(g)||N.success(s("sectionsEditor.pageJsonDialog.saveSuccess")),e(!1)}catch(g){N.error(s("sectionsEditor.pageJsonDialog.saveError",{error:g instanceof Error?g.message:String(g)}))}finally{D(!1)}};return y.jsx(z,{open:n,onOpenChange:e,children:y.jsxs(B,{className:"flex h-[85vh] w-[95vw] flex-col gap-0 overflow-hidden p-0 sm:max-w-6xl",children:[y.jsxs(F,{className:"shrink-0 px-4 py-3 border-b flex-row items-center justify-between space-y-0",children:[y.jsx(M,{className:"text-sm font-semibold",children:s("sectionsEditor.pageJsonDialog.title")}),y.jsxs("div",{className:"flex items-center gap-2 mr-8",children:[y.jsxs(A,{variant:"ghost",size:"sm",onClick:f,className:"text-xs",children:[l?y.jsx($,{size:12}):y.jsx(H,{size:12}),s(l?"sectionsEditor.pageJsonDialog.copied":"sectionsEditor.pageJsonDialog.copy")]}),!u&&y.jsx(A,{size:"sm",onClick:()=>h(v),disabled:!E||C,className:"h-7 text-xs",children:s(C?"sectionsEditor.pageJsonDialog.saving":"sectionsEditor.pageJsonDialog.save")})]})]}),o?y.jsxs("div",{className:"p-4 text-xs font-mono text-foreground/60",children:["// ",s("sectionsEditor.pageJsonDialog.pageNotFound")]}):y.jsx("div",{className:"min-h-0 flex-1 py-2",children:y.jsx(V,{code:c,language:"json",readOnly:u,height:"100%",onChange:w=>m(w??""),onSave:w=>{h(w)}})})]})})}function we(n){const e=W.c(10);let r,t;e[0]!==n?({params:r,...t}=n,e[0]=n,e[1]=r,e[2]=t):(r=e[1],t=e[2]);let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a={holdsCopy:!0},e[3]=a):a=e[3];const s=G(r,a);let i;e[4]!==t.pageKey||e[5]!==s?(i=c=>s.mutateAsync({blockKey:t.pageKey,data:c}),e[4]=t.pageKey,e[5]=s,e[6]=i):i=e[6];let o;return e[7]!==t||e[8]!==i?(o=y.jsx(Q,{...t,onSave:i}),e[7]=t,e[8]=i,e[9]=o):o=e[9],o}var X=Object.prototype.toString,j=Array.isArray||function(e){return X.call(e)==="[object Array]"};function O(n){return typeof n=="function"}function Y(n){return j(n)?"array":typeof n}function U(n){return n.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function I(n,e){return n!=null&&typeof n=="object"&&e in n}function Z(n,e){return n!=null&&typeof n!="object"&&n.hasOwnProperty&&n.hasOwnProperty(e)}var ee=RegExp.prototype.test;function te(n,e){return ee.call(n,e)}var re=/\S/;function ne(n){return!te(re,n)}var se={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};function ae(n){return String(n).replace(/[&<>"'`=\/]/g,function(r){return se[r]})}var ie=/\s*/,oe=/\s+/,_=/\s*=/,ce=/\s*\}/,le=/#|\^|\/|>|\{|&|=|!/;function ue(n,e){if(!n)return[];var r=!1,t=[],a=[],s=[],i=!1,o=!1,c="",l=0;function p(){if(i&&!o)for(;s.length;)delete a[s.pop()];else s=[];i=!1,o=!1}var v,m,C;function D(b){if(typeof b=="string"&&(b=b.split(oe,2)),!j(b)||b.length!==2)throw new Error("Invalid tags: "+b);v=new RegExp(U(b[0])+"\\s*"),m=new RegExp("\\s*"+U(b[1])),C=new RegExp("\\s*"+U("}"+b[1]))}D(e||x.tags);for(var u=new T(n),E,f,h,w,S,g;!u.eos();){if(E=u.pos,h=u.scanUntil(v),h)for(var J=0,K=h.length;J<K;++J)w=h.charAt(J),ne(w)?(s.push(a.length),c+=w):(o=!0,r=!0,c+=" "),a.push(["text",w,E,E+1]),E+=1,w===`
`&&(p(),c="",l=0,r=!1);if(!u.scan(v))break;if(i=!0,f=u.scan(le)||"name",u.scan(ie),f==="="?(h=u.scanUntil(_),u.scan(_),u.scanUntil(m)):f==="{"?(h=u.scanUntil(C),u.scan(ce),u.scanUntil(m),f="&"):h=u.scanUntil(m),!u.scan(m))throw new Error("Unclosed tag at "+u.pos);if(f==">"?S=[f,h,E,u.pos,c,l,r]:S=[f,h,E,u.pos],l++,a.push(S),f==="#"||f==="^")t.push(S);else if(f==="/"){if(g=t.pop(),!g)throw new Error('Unopened section "'+h+'" at '+E);if(g[1]!==h)throw new Error('Unclosed section "'+g[1]+'" at '+E)}else f==="name"||f==="{"||f==="&"?o=!0:f==="="&&D(h)}if(p(),g=t.pop(),g)throw new Error('Unclosed section "'+g[1]+'" at '+u.pos);return fe(pe(a))}function pe(n){for(var e=[],r,t,a=0,s=n.length;a<s;++a)r=n[a],r&&(r[0]==="text"&&t&&t[0]==="text"?(t[1]+=r[1],t[3]=r[3]):(e.push(r),t=r));return e}function fe(n){for(var e=[],r=e,t=[],a,s,i=0,o=n.length;i<o;++i)switch(a=n[i],a[0]){case"#":case"^":r.push(a),t.push(a),r=a[4]=[];break;case"/":s=t.pop(),s[5]=a[2],r=t.length>0?t[t.length-1][4]:e;break;default:r.push(a)}return e}function T(n){this.string=n,this.tail=n,this.pos=0}T.prototype.eos=function(){return this.tail===""};T.prototype.scan=function(e){var r=this.tail.match(e);if(!r||r.index!==0)return"";var t=r[0];return this.tail=this.tail.substring(t.length),this.pos+=t.length,t};T.prototype.scanUntil=function(e){var r=this.tail.search(e),t;switch(r){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,r),this.tail=this.tail.substring(r)}return this.pos+=t.length,t};function k(n,e){this.view=n,this.cache={".":this.view},this.parent=e}k.prototype.push=function(e){return new k(e,this)};k.prototype.lookup=function(e){var r=this.cache,t;if(r.hasOwnProperty(e))t=r[e];else{for(var a=this,s,i,o,c=!1;a;){if(e.indexOf(".")>0)for(s=a.view,i=e.split("."),o=0;s!=null&&o<i.length;)o===i.length-1&&(c=I(s,i[o])||Z(s,i[o])),s=s[i[o++]];else s=a.view[e],c=I(a.view,e);if(c){t=s;break}a=a.parent}r[e]=t}return O(t)&&(t=t.call(this.view)),t};function d(){this.templateCache={_cache:{},set:function(e,r){this._cache[e]=r},get:function(e){return this._cache[e]},clear:function(){this._cache={}}}}d.prototype.clearCache=function(){typeof this.templateCache<"u"&&this.templateCache.clear()};d.prototype.parse=function(e,r){var t=this.templateCache,a=e+":"+(r||x.tags).join(":"),s=typeof t<"u",i=s?t.get(a):void 0;return i==null&&(i=ue(e,r),s&&t.set(a,i)),i};d.prototype.render=function(e,r,t,a){var s=this.getConfigTags(a),i=this.parse(e,s),o=r instanceof k?r:new k(r,void 0);return this.renderTokens(i,o,t,e,a)};d.prototype.renderTokens=function(e,r,t,a,s){for(var i="",o,c,l,p=0,v=e.length;p<v;++p)l=void 0,o=e[p],c=o[0],c==="#"?l=this.renderSection(o,r,t,a,s):c==="^"?l=this.renderInverted(o,r,t,a,s):c===">"?l=this.renderPartial(o,r,t,s):c==="&"?l=this.unescapedValue(o,r):c==="name"?l=this.escapedValue(o,r,s):c==="text"&&(l=this.rawValue(o)),l!==void 0&&(i+=l);return i};d.prototype.renderSection=function(e,r,t,a,s){var i=this,o="",c=r.lookup(e[1]);function l(m){return i.render(m,r,t,s)}if(c){if(j(c))for(var p=0,v=c.length;p<v;++p)o+=this.renderTokens(e[4],r.push(c[p]),t,a,s);else if(typeof c=="object"||typeof c=="string"||typeof c=="number")o+=this.renderTokens(e[4],r.push(c),t,a,s);else if(O(c)){if(typeof a!="string")throw new Error("Cannot use higher-order sections without the original template");c=c.call(r.view,a.slice(e[3],e[5]),l),c!=null&&(o+=c)}else o+=this.renderTokens(e[4],r,t,a,s);return o}};d.prototype.renderInverted=function(e,r,t,a,s){var i=r.lookup(e[1]);if(!i||j(i)&&i.length===0)return this.renderTokens(e[4],r,t,a,s)};d.prototype.indentPartial=function(e,r,t){for(var a=r.replace(/[^ \t]/g,""),s=e.split(`
`),i=0;i<s.length;i++)s[i].length&&(i>0||!t)&&(s[i]=a+s[i]);return s.join(`
`)};d.prototype.renderPartial=function(e,r,t,a){if(t){var s=this.getConfigTags(a),i=O(t)?t(e[1]):t[e[1]];if(i!=null){var o=e[6],c=e[5],l=e[4],p=i;c==0&&l&&(p=this.indentPartial(i,l,o));var v=this.parse(p,s);return this.renderTokens(v,r,t,p,a)}}};d.prototype.unescapedValue=function(e,r){var t=r.lookup(e[1]);if(t!=null)return t};d.prototype.escapedValue=function(e,r,t){var a=this.getConfigEscape(t)||x.escape,s=r.lookup(e[1]);if(s!=null)return typeof s=="number"&&a===x.escape?String(s):a(s)};d.prototype.rawValue=function(e){return e[1]};d.prototype.getConfigTags=function(e){return j(e)?e:e&&typeof e=="object"?e.tags:void 0};d.prototype.getConfigEscape=function(e){if(e&&typeof e=="object"&&!j(e))return e.escape};var x={name:"mustache.js",version:"4.2.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(n){R.templateCache=n},get templateCache(){return R.templateCache}},R=new d;x.clearCache=function(){return R.clearCache()};x.parse=function(e,r){return R.parse(e,r)};x.render=function(e,r,t,a){if(typeof e!="string")throw new TypeError('Invalid template! Template should be a "string" but "'+Y(e)+'" was given as the first argument for mustache#render(template, view, partials)');return R.render(e,r,t,a)};x.escape=ae;x.Scanner=T;x.Context=k;x.Writer=d;export{Q as P,we as S,x as m};