md/js/app.429efbab.js

3 lines
84 KiB
JavaScript
Raw Normal View History

(function(e){function t(t){for(var i,r,a=t[0],l=t[1],c=t[2],u=0,m=[];u<a.length;u++)r=a[u],Object.prototype.hasOwnProperty.call(n,r)&&n[r]&&m.push(n[r][0]),n[r]=0;for(i in l)Object.prototype.hasOwnProperty.call(l,i)&&(e[i]=l[i]);d&&d(t);while(m.length)m.shift()();return s.push.apply(s,c||[]),o()}function o(){for(var e,t=0;t<s.length;t++){for(var o=s[t],i=!0,a=1;a<o.length;a++){var l=o[a];0!==n[l]&&(i=!1)}i&&(s.splice(t--,1),e=r(r.s=o[0]))}return e}var i={},n={app:0},s=[];function r(t){if(i[t])return i[t].exports;var o=i[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=i,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(o,i,function(t){return e[t]}.bind(null,i));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/md/";var a=window["webpackJsonp"]=window["webpackJsonp"]||[],l=a.push.bind(a);a.push=t,a=a.slice();for(var c=0;c<a.length;c++)t(a[c]);var d=l;s.push([0,"chunk-vendors"]),o()})({0:function(e,t,o){e.exports=o("3479")},"0620":function(e,t,o){},"0b4a":function(e,t,o){},"0ed7":function(e,t,o){},1:function(e,t){},10:function(e,t){},11:function(e,t){},12:function(e,t){},1208:function(e,t,o){"use strict";o("ff55")},13:function(e,t){},1386:function(e,t,o){"use strict";o("c8b3")},14:function(e,t){},15:function(e,t){},16:function(e,t){},"1bf9":function(e,t,o){},"1cd3":function(e,t,o){"use strict";var i=o("b481");const n=i["a"].create({baseURL:"",timeout:3e4});n.interceptors.request.use(e=>(/^(post)|(put)|(delete)$/i.test(e.method)&&e.data&&e.data.upload&&(e.headers["Content-Type"]="multipart/form-data"),e),e=>{Promise.reject(e)}),n.interceptors.response.use(e=>e.data?e.data:Promise.reject(e),e=>Promise.reject(e)),t["a"]=n},2:function(e,t){},"2b39":function(e,t,o){},3:function(e,t){},3479:function(e,t,o){"use strict";o.r(t);var i=o("ff9b"),n=o("ccbf"),s=o.n(n),r=o("acd4");o("b6f4"),o("e3f8"),o("8128"),o("fa17"),o("0b4a"),o("a6e0"),o("7fa7"),o("697d"),o("beaf"),o("6864"),o("8d07"),o("a176");i["default"].component(n["Message"].name,n["Message"]),i["default"].prototype.$loading=n["Loading"].service,i["default"].prototype.$message=n["Message"];var a=function(){var e=this,t=e._self._c,o=e._self._setupProxy;return t("div",{attrs:{id:"app"}},[t(o.CodemirrorEditor)],1)},l=[],c=function(){var e=this,t=e._self._c;return t("div",{staticClass:"container",class:{container_night:e.nightMode}},[t("el-container",[t("el-header",{staticClass:"editor__header"},[t("editor-header",{ref:"header",on:{addFormat:e.addFormat,formatContent:e.formatContent,refresh:e.onEditorRefresh,cssChanged:e.cssChanged,"import-md":e.importMD,download:e.downloadEditorContent,export:e.exportEditorContent,showCssEditor:function(t){e.showCssEditor=!e.showCssEditor},"show-about-dialog":function(t){e.aboutDialogVisible=!0},"show-dialog-form":function(t){e.insertFormDialogVisible=!0},"show-dialog-upload-img":function(t){e.dialogUploadImgVisible=!0},startCopy:function(t){e.isCoping=!0,e.backLight=!0},endCopy:e.endCopy}})],1),t("el-main",{staticClass:"main-body"},[t("el-row",{staticClass:"main-section"},[t("el-col",{ref:"codeMirrorWrapper",staticClass:"codeMirror-wrapper",attrs:{span:12},nativeOn:{contextmenu:function(t){return t.preventDefault(),e.openMenu.apply(null,arguments)}}},[t("textarea",{directives:[{name:"model",rawName:"v-model",value:e.source,expression:"source"}],attrs:{id:"editor",type:"textarea",placeholder:"Your markdown text here."},domProps:{value:e.source},on:{input:function(t){t.target.composing||(e.source=t.target.value)}}})]),t
//!影响到右键菜单的点击事件右键菜单的点击事件在组件内通过mousedown触发
this.rightClickMenuVisible=!1}),this.editor.on("scroll",()=>{this.rightClickMenuVisible=!1})},initCssEditor(){this.initCssEditorEntity(),this.cssEditor.on("keyup",(e,t)=>{(t.keyCode>=65&&t.keyCode<=90||189===t.keyCode)&&e.showHint(t)}),this.cssEditor.on("update",e=>{this.cssChanged(),q(this.cssEditor,"__css_content")})},cssChanged(){let e=L(this.cssEditor.getValue(0)),t=K(this.currentSize.replace("px",""));t=B(e,this.currentColor,t),this.setWxRendererOptions({theme:t}),this.onEditorRefresh()},codeThemeChanged(){let e=this.codeTheme,t=document.getElementById("hljs");if(void 0!=t)t.setAttribute("href",e);else{const t=document.createElement("link");t.setAttribute("type","text/css"),t.setAttribute("rel","stylesheet"),t.setAttribute("href",e),t.setAttribute("id","hljs"),document.head.appendChild(t)}},beforeUpload(e){const t=W(e);if(!t.ok)return this.$message.error(t.msg),!1;let o=localStorage.getItem("imgHost");o=o||"default",localStorage.setItem("imgHost",o);const i=localStorage.getItem(o+"Config"),n="default"==o||i;return!!n||(this.$message.error(`请先配置 ${o} 图床参数`),!1)},uploadImage(e,t){this.isImgLoading=!0,G(e).then(o=>{ct["a"].fileUpload(o,e).then(e=>{console.log(e),t?t(e):this.uploaded(e)}).catch(e=>{this.$message.error(e.message)})}).catch(e=>{this.$message.error(e.message)}),this.isImgLoading=!1},uploaded(e){if(console.log("图片上传之后: ",e),!e)return void this.$message.error("上传图片未知异常");this.dialogUploadImgVisible=!1;const t=this.editor.getCursor(),o=e,i=`![](${o})`;this.editor.replaceSelection(`\n${i}\n`,t),this.$message.success("图片上传成功"),this.onEditorRefresh()},leftAndRightScroll(){const e=e=>{let i,n;clearTimeout(this.timeout),"preview"===e?(i=this.$refs.preview.$el,n=document.getElementsByClassName("CodeMirror-scroll")[0],this.editor.off("scroll",t),this.timeout=setTimeout(()=>{this.editor.on("scroll",t)},300)):"editor"===e&&(i=document.getElementsByClassName("CodeMirror-scroll")[0],n=this.$refs.preview.$el,n.removeEventListener("scroll",o,!1),this.timeout=setTimeout(()=>{n.addEventListener("scroll",o,!1)},300));let s=i.scrollTop/(i.scrollHeight-i.offsetHeight),r=s*(n.scrollHeight-n.offsetHeight);n.scrollTo(0,r)},t=()=>{e("editor")},o=()=>{e("preview")};this.$refs.preview.$el.addEventListener("scroll",o,!1),this.editor.on("scroll",t)},onEditorRefresh(){this.codeThemeChanged(this.codeTheme),this.editorRefresh(),setTimeout(()=>window.PR.prettyPrint(),0)},endCopy(){this.backLight=!1,setTimeout(()=>{this.isCoping=!1},800)},addFormat(e,t=e){const{head:o,anchor:i}=this.editor.doc.sel.ranges[0];let n,s;o.line===i.line?o.ch<i.ch?(n=o,s=i):(n=i,s=o):o.line<i.line?(n=o,s=i):(n=i,s=o);const r=[];let a="";for(const c of this.editor.getValue())"\n"===c?(r.push(a),a=""):a+=c;r.push(a);let l="";for(let c=0;c<r.length;c++){const o=r[c];for(let i=0;i<o.length;i++)c===n.line&&i===n.ch&&(l+=e),c===s.line&&i===s.ch&&(l+=t),l+=o[i];c===s.line&&o.length===s.ch&&(l+=t),l+="\n"}this.editor.setValue(l)},importMD(e){this.editor.setValue(e),this.onEditorRefresh()},downloadEditorContent(){z(this.editor.getValue(0))},exportEditorContent(){this.$nextTick(()=>{H(),document.getElementById("output").innerHTML=this.output})},importMarkdownContent(){let e=document.getElementById("menu"),t=document.createElement("input");t.type="file",t.name="filename",t.accept=".txt,.md",e.appendChild(t),t.onchange=()=>{if(!t.files)return;const e=t.files[0];if(!/\.(txt|TXT|MD|md)$/.test(e.name))return void this.$message.error("不支持的文档格式");const o=new FileReader;o.readAsText(e),o.onload=e=>{let t=e.target.result;t=U(t),t&&(localStorage.setItem("__editor_content",t),this.editor.setValue(t),this.$message.success("文档导入成功"))}},t.click(),e.removeChild(t)},formatContent(){const e=U(this.editor.getValue(0));localStorage.setItem("__editor_content",e),this.editor.setValue(e)},openMenu(e){const t=105,o=this.$el.getBoundingClientRect().left,i=this.$el.offsetWidth,n=i-t,s=e.clientX-o;this.mouseLeft=Math.min(n,s),this.mouseTop=e.clientY+10,this.rightClickMenuVisible=!0},onMenuEvent(e){switch(e){case"re