UNPKG

decocms

Version:

Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools

5 lines (4 loc) • 8.55 kB
import{u as S}from"./use-organization-settings-C2vcrj4S.js";import{b as A}from"./repository-binding-D_Xc1yRH.js";import{M as B,m as I,b as P,c as q,g as O,s as E,d as z,e as N}from"./usage-stats-B0_Yl-r0.js";import{m as R}from"./markdown-CJR_ooUO.js";import{T as D,c as F,C as K,d as j,s as w}from"./use-never-published-BJeGnEQC.js";import{a2 as W,a3 as Q}from"./category-tree-DGOo1BAt.js";import{s as G,T as J}from"./index-BL01DXCf.js";function Tt(){return S("blog_ai_enabled")}function St(t){return A(t)?.metadata?.legacyBlogPostFormat??!1}function wt(){return S("hide_default_blog_blocks")}const U=/<(h[1-6]|p|ul|ol|div|img|br|blockquote|section|article|figure)\b|<\/[a-z]/i;function L(t){return U.test(t)}function Lt(t){const e=t.trim();return e?L(e)?rt(e):st(e):{title:"",sections:[]}}function b(t){return t.replace(/&nbsp;/gi," ").replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,'"').replace(/&#0?39;|&apos;/gi,"'").replace(/&amp;/gi,"&")}function p(t){let e=t,n;do n=e,e=e.replace(/<[^>]+>/g,"");while(e!==n);return b(e).replace(/\s+/g," ").trim()}function V(t){let e=t,n;do n=e,e=e.replace(/<!--[\s\S]*?-->/g,"");while(e!==n);return e}function X(t){let e=t,n;do n=e,e=e.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/gi,"");while(e!==n);return e}function M(t){let e=t,n;do n=e,e=X(V(e));while(e!==n);return e}const Y=/^(a|b|strong|i|em|u|s|code|br|span|sub|sup)$/;function m(t){let e="";for(const n of t)n.charCodeAt(0)>31&&(e+=n);return e=e.trim(),!/^[a-z][a-z0-9+.-]*:/i.test(e)||/^(https?|mailto|tel):/i.test(e)}function Z(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}const tt=/^<\/?([a-z][a-z0-9]*)\b([^>]*)>/i;function et(t,e,n){const r=e.toLowerCase();if(!Y.test(r))return"";if(t.startsWith("</"))return`</${r}>`;if(r!=="a")return`<${r}>`;const i=b(n.match(/href\s*=\s*"([^"]*)"/i)?.[1]??"");return m(i)&&i?`<a href="${Z(i)}">`:"<a>"}function v(t){const e=M(t);let n="",r=0;for(;r<e.length;){const i=e.indexOf("<",r);if(i===-1){n+=e.slice(r);break}n+=e.slice(r,i);const s=tt.exec(e.slice(i));if(!s){n+="&lt;",r=i+1;continue}n+=et(s[0],s[1]??"",s[2]??""),r=i+s[0].length}return n}function f(t,e){const n=t.match(new RegExp(`${e}\\s*=\\s*"([^"]*)"`,"i"));return n?.[1]?b(n[1]):""}const nt=/<(h[1-6]|p|ul|ol|blockquote|figure)\b[^>]*>([\s\S]*?)<\/\1\s*>|<hr\b[^>]*\/?>|<img\b[^>]*>/gi;function rt(t){const e=M(t);let n="";const r=[];for(const i of e.matchAll(nt)){const s=i[1]?.toLowerCase(),a=i[2]??"",c=i[0];if(!s){if(/^<img/i.test(c)){const o=f(c,"src");o&&m(o)&&r.push({kind:"image",url:o,alt:f(c,"alt"),caption:""})}else r.push({kind:"divider"});continue}if(/^h[1-6]$/.test(s)){const o=p(a);if(!o)continue;if(s==="h1"&&!n){n=o;continue}r.push({kind:"heading",text:o,level:s.slice(1)})}else if(s==="p"){const o=v(a.trim());p(o)&&r.push({kind:"paragraph",html:o})}else if(s==="ul"||s==="ol"){const o=[...a.matchAll(/<li\b[^>]*>([\s\S]*?)<\/li\s*>/gi)].map(l=>p(l[1]??"")).filter(Boolean);o.length&&r.push({kind:"list",items:o,ordered:s==="ol"})}else if(s==="blockquote"){const o=p(a);o&&r.push({kind:"quote",text:o})}else if(s==="figure"){const o=a.match(/<img\b[^>]*>/i)?.[0],l=o?f(o,"src"):"",u=p(a.match(/<figcaption\b[^>]*>([\s\S]*?)<\/figcaption\s*>/i)?.[1]??"");l&&m(l)&&r.push({kind:"image",url:l,alt:o?f(o,"alt"):"",caption:u})}}return{title:n,sections:r}}function it(t){return t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,'<a href="$2">$1</a>').replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>").replace(/(^|[^*])\*([^*]+)\*/g,"$1<em>$2</em>").replace(/`([^`]+)`/g,"<code>$1</code>")}function st(t){const e=t.replace(/\r\n?/g,` `).split(` `);let n="";const r=[];let i=[],s=null,a=[];const c=()=>{i.length&&(r.push({kind:"paragraph",html:v(it(i.join(" ")))}),i=[])},o=()=>{s&&(r.push({kind:"list",items:s.items,ordered:s.ordered}),s=null)},l=()=>{a.length&&(r.push({kind:"quote",text:a.join(" ")}),a=[])},u=()=>{c(),o(),l()};for(const _ of e){const d=_.trimEnd(),h=d.match(/^(#{1,6})\s+(.*)$/),k=d.match(/^!\[([^\]]*)\]\(([^)\s]+)\)\s*$/),y=d.match(/^\s*(?:[-*+]|\d+\.)\s+(.*)$/),H=/^\s*\d+\./.test(d),x=d.match(/^>\s?(.*)$/);if(!d.trim())u();else if(h){u();const g=h[2]?.trim()??"",T=String(h[1]?.length??1);T==="1"&&!n?n=g:g&&r.push({kind:"heading",text:g,level:T})}else if(/^(-{3,}|\*{3,}|_{3,})$/.test(d.trim()))u(),r.push({kind:"divider"});else if(k){u();const g=k[2]??"";m(g)&&r.push({kind:"image",url:g,alt:k[1]??"",caption:""})}else y?(c(),l(),s||(s={items:[],ordered:H}),s.items.push(y[1]?.trim()??"")):x?(c(),o(),a.push(x[1]?.trim()??"")):(o(),l(),i.push(d.trim()))}return u(),{title:n,sections:r}}const ot={heading:"Heading",paragraph:"Paragraph",list:"List",quote:"Quote",divider:"Divider",image:"BlockImage"};function Mt(t,e){const n=[];for(const r of t){const i=e[ot[r.kind]];if(i)switch(r.kind){case"heading":n.push({__resolveType:i,text:r.text,level:r.level});break;case"paragraph":n.push({__resolveType:i,html:r.html});break;case"list":n.push({__resolveType:i,items:r.items.join(` `),style:r.ordered?"ordered":"unordered"});break;case"quote":n.push({__resolveType:i,quote:r.text});break;case"divider":n.push({__resolveType:i});break;case"image":n.push({__resolveType:i,url:r.url,alt:r.alt,caption:r.caption,size:"normal"});break}}return n}function vt({title:t,body:e,takenSlugs:n,now:r}){const i=t.trim();return{title:i,slug:i?W(i,n):Q(""),date:r.toISOString().slice(0,10),excerpt:"",image:"",alt:"",authors:[],categories:[],...e,status:"in_review"}}const at=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,lt=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,ct=B.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:t=>t.getAttribute("data-color")||O(t,"background-color")||t.style.backgroundColor,renderHTML:t=>t.color?{"data-color":t.color,style:`background-color: ${t.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:t}){return["mark",q(this.options.HTMLAttributes,t),0]},renderMarkdown:(t,e)=>`==${e.renderChildren(t)}==`,parseMarkdown:(t,e)=>e.applyMark("highlight",e.parseInline(t.tokens||[])),markdownTokenizer:{name:"highlight",level:"inline",start:t=>t.indexOf("=="),tokenize(t,e,n){const r=/^(==)([^=]+)(==)/.exec(t);if(r){const i=r[2].trim(),s=n.inlineTokens(i);return{type:"highlight",raw:r[0],text:i,tokens:s}}}},addCommands(){return{setHighlight:t=>({commands:e})=>e.setMark(this.name,t),toggleHighlight:t=>({commands:e})=>e.toggleMark(this.name,t),unsetHighlight:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[P({find:at,type:this.type})]},addPasteRules(){return[I({find:lt,type:this.type})]}});var ut=ct;function dt(){return[E.configure({link:{openOnClick:!1,HTMLAttributes:{target:null,rel:null}},trailingNode:!1}),j.configure({types:["heading","paragraph","codeBlock","image","bulletList","orderedList","blockquote"]}),D,F,K,G.configure({inline:!0,allowBase64:!1}),ut.configure({multicolor:!0}),J.configure({table:{resizable:!1}})]}function $t(t){const e=w(t);return e.toLowerCase().startsWith("data:")?"":e}function gt(t){return t==="<p></p>"?"":t}function $(t){return t.text??(t.content??[]).map($).join("")}function C(t){if(t.type==="image"){const n=w(String(t.attrs?.src??""));return n?{...t,attrs:{...t.attrs,src:n}}:null}if(!t.content?.length)return t;const e=t.content.map(C).filter(n=>n!==null);return e.length||t.type==="doc"?{...t,content:e}:null}function pt(t,e){return C(N(t,e))??{type:"doc"}}function Ct(t){const e=t.trim();if(!e)return{title:"",content:""};const n=L(e)?e:R.parse(e,{async:!1}),r=dt(),i=pt(n,r),s=i.content??[],a=s.findIndex(l=>l.type==="heading"&&l.attrs?.level===1),c=a>=0?$(s[a]).trim():"",o=s.filter((l,u)=>u!==a);return o.length===0?{title:c,content:""}:{title:c,content:gt(z({...i,content:o},r))}}function _t(t,e,{neverPublished:n=!1}={}){return e&&n?t==="post"?"sandbox.postEditor.deletePostConfirmBodyNeverPublished":"sandbox.contentBrowser.deleteDialog.descriptionNeverPublished":t==="section"?e?"sandbox.contentBrowser.deleteDialog.descriptionSectionDraft":"sandbox.contentBrowser.deleteDialog.descriptionSection":t==="post"?e?"sandbox.postEditor.deletePostConfirmBodyDraft":"sandbox.postEditor.deletePostConfirmBody":e?"sandbox.contentBrowser.deleteDialog.descriptionDraft":"sandbox.contentBrowser.deleteDialog.descriptionPermanent"}export{St as a,wt as b,vt as c,_t as d,gt as e,dt as f,$t as g,Ct as i,L as l,Lt as p,Mt as s,Tt as u};