Code-CoxsN5zH.js 3.8 KB

12
  1. const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor.main-DpNMXfyH.js","assets/index-DT8qTvyx.js","assets/index-We5Babj5.css","assets/editor-CIwA5Sev.css"])))=>i.map(i=>d[i]);
  2. import{s as _,f as L,al as T,ai as v,o as x,E as b,G as y,v as z,w as R,aE as S,bx as H,z as k,D as A}from"./index-DT8qTvyx.js";var M=function(g){_(o,g);function o(t){var e=g.call(this,t)||this;return e.toDispose=[],e.codeRef=L.createRef(),e}return o.prototype.shouldComponentUpdate=function(t){return T(o.propsList,this.props,t)||this.resolveLanguage(this.props)!==this.resolveLanguage(t)||v(this.props)!==v(t)},o.prototype.componentDidMount=function(){var t=this;x(()=>import("./editor.main-DpNMXfyH.js").then(e=>e.b),__vite__mapDeps([0,1,2,3])).then(function(e){return t.handleMonaco(e)})},o.prototype.componentDidUpdate=function(t){var e,a;return b(this,void 0,void 0,function(){var i,n,r,d,s,u,l;return y(this,function(c){switch(c.label){case 0:return i=this.props,n=this.codeRef.current,!((e=this===null||this===void 0?void 0:this.monaco)===null||e===void 0)&&e.editor&&n?(r=i.tabSize,d=(a=v(this.props))!==null&&a!==void 0?a:"",s=this.resolveLanguage(),u=this.registerAndGetTheme(),this.monaco.editor.setTheme(u),[4,this.monaco.editor.colorize(d,s,{tabSize:r})]):[3,2];case 1:l=c.sent(),n.innerHTML=l,c.label=2;case 2:return[2]}})})},o.prototype.handleMonaco=function(t){var e,a;return b(this,void 0,void 0,function(){var i,n,r,d,s,u;return y(this,function(l){switch(l.label){case 0:return t?(this.monaco=t,i=this.props.tabSize,n=(e=v(this.props))!==null&&e!==void 0?e:"",r=this.resolveLanguage(),d=this.codeRef.current,d&&(!((a=this.monaco)===null||a===void 0)&&a.editor)?(s=this.registerAndGetTheme(),this.monaco.editor.setTheme(s),[4,this.monaco.editor.colorize(n,r,{tabSize:i})]):[3,2]):[2];case 1:u=l.sent(),d.innerHTML=u,l.label=2;case 2:return[2]}})})},o.prototype.resolveLanguage=function(t){var e=t??this.props,a=e.customLang,i=e.data,n=e.language,r=n===void 0?"plaintext":n;return z(r)&&(r=R(r,i)),a&&a.name&&(r=a.name),r},o.prototype.registerAndGetTheme=function(){var t,e,a,i,n=this.monaco,r=this.props,d=r.theme,s=r.editorTheme;if(s=s||(d==="dark"?"vs-dark":"vs"),!n)return s;if(this.customLang&&this.customLang.name&&Array.isArray(this.customLang.tokens)&&this.customLang.tokens.length){var u=this.customLang.name,l=!((a=this.customLang)===null||a===void 0)&&a.colors&&S((i=this.customLang)===null||i===void 0?void 0:i.colors)?this.customLang.colors:{};n.languages.register({id:u});var c=[],f=[];try{for(var m=H(this.customLang.tokens),h=m.next();!h.done;h=m.next()){var p=h.value,C=new RegExp(p.regex,p.regexFlags||void 0);c.push([C,p.name]),f.push({token:p.name,foreground:p.color,background:p.background,fontStyle:p.fontStyle})}}catch(w){t={error:w}}finally{try{h&&!h.done&&(e=m.return)&&e.call(m)}finally{if(t)throw t.error}}return n.languages.setMonarchTokensProvider(u,{tokenizer:{root:c}}),n.editor.defineTheme(u,{base:"vs",inherit:!1,rules:f,colors:l}),u}return s},o.prototype.render=function(){var t=v(this.props),e=this.props,a=e.className,i=e.maxHeight,n=e.style,r=n===void 0?{}:n,d=e.classnames,s=e.editorTheme,u=e.customLang,l=e.wordWrap,c=e.wrapperComponent,f=this.resolveLanguage(),m=typeof t=="string"&&t.split(/\r?\n/).length>1,h=c||(m?"pre":"code");return u&&(this.customLang=u),i&&(r.maxHeight=r.maxHeight||i,r.overflow="auto"),L.createElement(h,{ref:this.codeRef,className:d("Code",{"Code--dark":s&&["vs-dark","hc-black"].includes(s),"Code-pre-wrap":h==="pre","word-break":l},a),style:r,"data-lang":f},t)},o.propsList=["language","editorTheme","tabSize","wordWrap","customLang","style"],o.defaultProps={language:"plaintext",tabSize:4,wordWrap:!0},o}(L.Component),E=function(g){_(o,g);function o(){return g!==null&&g.apply(this,arguments)||this}return o=k([A({type:"code"})],o),o}(M);export{E as CodeRenderer,M as default};