HuanMengAdmin/admin-client/dist/static/js/index-e085a9e5.js
2024-07-18 02:27:50 +08:00

2 lines
5.8 KiB
JavaScript

import{g as v,o as x,M as q,a as y,q as O,P as F,r as R,u as T,v as G,w as K,x as V,f as X,i as j,y as z,G as Q,S as $,z as H,A as J,B as C,C as U}from"./CodeGeneration.vue_vue_type_script_setup_true_lang-5f97ed0e.js";import"./index-5ce8de01.js";import"./CodeGenerationService-c4b0b4fb.js";const M=K({block:{open:"<!--",close:"-->"}}),I=V.configure({props:[X.add(r=>{if(!(!r.is("Block")||r.is("Document")))return(m,s)=>({from:s.doc.lineAt(m.from).to,to:m.to})}),j.add({Document:()=>null}),z.add({Document:M})]});function B(r){return new T(M,r,[],"markdown")}const Y=B(I),Z=I.configure([Q,$,H,J]),D=B(Z);function _(r,m){return s=>{if(s&&r){let e=null;if(s=/\S*/.exec(s)[0],typeof r=="function"?e=r(s):e=C.matchLanguageName(r,s,!0),e instanceof C)return e.support?e.support.language.parser:U.getSkippingParser(e.load());if(e)return e.parser}return m?m.parser:null}}class L{constructor(m,s,e,o,i,n,f){this.node=m,this.from=s,this.to=e,this.spaceBefore=o,this.spaceAfter=i,this.type=n,this.item=f}blank(m,s=!0){let e=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(m!=null){for(;e.length<m;)e+=" ";return e}else{for(let o=this.to-this.from-e.length-this.spaceAfter.length;o>0;o--)e+=" ";return e+(s?this.spaceAfter:"")}}marker(m,s){let e=this.node.name=="OrderedList"?String(+N(this.item,m)[2]+s):"";return this.spaceBefore+e+this.type+this.spaceAfter}}function E(r,m){let s=[];for(let o=r;o&&o.name!="Document";o=o.parent)(o.name=="ListItem"||o.name=="Blockquote"||o.name=="FencedCode")&&s.push(o);let e=[];for(let o=s.length-1;o>=0;o--){let i=s[o],n,f=m.lineAt(i.from),t=i.from-f.from;if(i.name=="FencedCode")e.push(new L(i,t,t,"","","",null));else if(i.name=="Blockquote"&&(n=/^[ \t]*>( ?)/.exec(f.text.slice(t))))e.push(new L(i,t,t+n[0].length,"",n[1],">",null));else if(i.name=="ListItem"&&i.parent.name=="OrderedList"&&(n=/^([ \t]*)\d+([.)])([ \t]*)/.exec(f.text.slice(t)))){let a=n[3],l=n[0].length;a.length>=4&&(a=a.slice(0,a.length-4),l-=4),e.push(new L(i.parent,t,t+l,n[1],a,n[2],i))}else if(i.name=="ListItem"&&i.parent.name=="BulletList"&&(n=/^([ \t]*)([-+*])([ \t]{1,4}\[[ xX]\])?([ \t]+)/.exec(f.text.slice(t)))){let a=n[4],l=n[0].length;a.length>4&&(a=a.slice(0,a.length-4),l-=4);let d=n[2];n[3]&&(d+=n[3].replace(/[xX]/," ")),e.push(new L(i.parent,t,t+l,n[1],a,d,i))}}return e}function N(r,m){return/^(\s*)(\d+)(?=[.)])/.exec(m.sliceString(r.from,r.from+10))}function A(r,m,s,e=0){for(let o=-1,i=r;;){if(i.name=="ListItem"){let f=N(i,m),t=+f[2];if(o>=0){if(t!=o+1)return;s.push({from:i.from+f[1].length,to:i.from+f[0].length,insert:String(o+2+e)})}o=t}let n=i.nextSibling;if(!n)break;i=n}}const W=({state:r,dispatch:m})=>{let s=v(r),{doc:e}=r,o=null,i=r.changeByRange(n=>{if(!n.empty||!D.isActiveAt(r,n.from))return o={range:n};let f=n.from,t=e.lineAt(f),a=E(s.resolveInner(f,-1),e);for(;a.length&&a[a.length-1].from>f-t.from;)a.pop();if(!a.length)return o={range:n};let l=a[a.length-1];if(l.to-l.spaceAfter.length>f-t.from)return o={range:n};let d=f>=l.to-l.spaceAfter.length&&!/\S/.test(t.text.slice(l.to));if(l.item&&d)if(l.node.firstChild.to>=f||t.from>0&&!/[^\s>]/.test(e.lineAt(t.from-1).text)){let u=a.length>1?a[a.length-2]:null,c,h="";u&&u.item?(c=t.from+u.from,h=u.marker(e,1)):c=t.from+(u?u.to:0);let w=[{from:c,to:f,insert:h}];return l.node.name=="OrderedList"&&A(l.item,e,w,-2),u&&u.node.name=="OrderedList"&&A(u.item,e,w),{range:x.cursor(c+h.length),changes:w}}else{let u="";for(let c=0,h=a.length-2;c<=h;c++)u+=a[c].blank(c<h?a[c+1].from-u.length:null,c<h);return u+=r.lineBreak,{range:x.cursor(f+u.length),changes:{from:t.from,insert:u}}}if(l.node.name=="Blockquote"&&d&&t.from){let u=e.lineAt(t.from-1),c=/>\s*$/.exec(u.text);if(c&&c.index==l.from){let h=r.changes([{from:u.from+c.index,to:u.to},{from:t.from+l.from,to:t.to}]);return{range:n.map(h),changes:h}}}let p=[];l.node.name=="OrderedList"&&A(l.item,e,p);let b=l.item&&l.item.from<t.from,g="";if(!b||/^[\s\d.)\-+*>]*/.exec(t.text)[0].length>=l.to)for(let u=0,c=a.length-1;u<=c;u++)g+=u==c&&!b?a[u].marker(e,1):a[u].blank(u<c?a[u+1].from-g.length:null);let k=f;for(;k>t.from&&/\s/.test(t.text.charAt(k-t.from-1));)k--;return g=r.lineBreak+g,p.push({from:k,to:f,insert:g}),{range:x.cursor(k+g.length),changes:p}});return o?!1:(m(r.update(i,{scrollIntoView:!0,userEvent:"input"})),!0)};function S(r){return r.name=="QuoteMark"||r.name=="ListMark"}function ee(r,m){let s=r.resolveInner(m,-1),e=m;S(s)&&(e=s.from,s=s.parent);for(let o;o=s.childBefore(e);)if(S(o))e=o.from;else if(o.name=="OrderedList"||o.name=="BulletList")s=o.lastChild,e=s.to;else break;return s}const te=({state:r,dispatch:m})=>{let s=v(r),e=null,o=r.changeByRange(i=>{let n=i.from,{doc:f}=r;if(i.empty&&D.isActiveAt(r,i.from)){let t=f.lineAt(n),a=E(ee(s,n),f);if(a.length){let l=a[a.length-1],d=l.to-l.spaceAfter.length+(l.spaceAfter?1:0);if(n-t.from>d&&!/\S/.test(t.text.slice(d,n-t.from)))return{range:x.cursor(t.from+d),changes:{from:t.from+d,to:n}};if(n-t.from==d){let p=t.from+l.from;if(l.item&&l.node.from<l.item.from&&/\S/.test(t.text.slice(l.from,l.to)))return{range:i,changes:{from:p,to:t.from+l.to,insert:l.blank(l.to-l.from)}};if(p<n)return{range:x.cursor(p),changes:{from:p,to:n}}}}}return e={range:i}});return e?!1:(m(r.update(o,{scrollIntoView:!0,userEvent:"delete"})),!0)},re=[{key:"Enter",run:W},{key:"Backspace",run:te}],P=G({matchClosingTags:!1});function le(r={}){let{codeLanguages:m,defaultCodeLanguage:s,addKeymap:e=!0,base:{parser:o}=Y}=r;if(!(o instanceof q))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let i=r.extensions?[r.extensions]:[],n=[P.support],f;s instanceof y?(n.push(s.support),f=s.language):s&&(f=s);let t=m||f?_(m,f):void 0;return i.push(O({codeParser:t,htmlParser:P.language.parser})),e&&n.push(F.high(R.of(re))),new y(B(o.configure(i)),n)}export{Y as commonmarkLanguage,te as deleteMarkupBackward,W as insertNewlineContinueMarkup,le as markdown,re as markdownKeymap,D as markdownLanguage};