md-editor-v3
Version:
Markdown editor for vue3, developed in jsx and typescript, dark theme、beautify content by prettier、render articles directly、paste or clip the picture and upload it...
2 lines (1 loc) • 5.25 kB
JavaScript
;const e=require("vue"),i=require("./config.cjs"),S=require("./index5.cjs"),x=require("./dom.cjs"),k=require("./vue-tsx.cjs"),t=require("lucide-vue-next"),z=()=>e.createVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-github-icon"},[e.createVNode("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"},null),e.createVNode("path",{d:"M9 18c-4.51 2-5-2-7-2"},null)]),P={bold:t.Bold,underline:t.Underline,italic:t.Italic,"strike-through":t.Strikethrough,title:t.Heading,sub:t.Subscript,sup:t.Superscript,quote:t.Quote,"unordered-list":t.List,"ordered-list":t.ListOrdered,task:t.ListTodo,"code-row":t.Code,code:t.SquareCode,link:t.Link,image:t.Image,table:t.Table,revoke:t.Reply,next:t.Forward,save:t.Save,prettier:t.SquareCode,minimize:t.Minimize2,maximize:t.Maximize2,"fullscreen-exit":t.Shrink,fullscreen:t.Expand,"preview-only":t.View,preview:t.Eye,"preview-html":t.CodeXml,catalog:t.ListTree,github:z,mermaid:t.ChartArea,formula:t.SquareSigma,close:t.X,delete:t.Trash2,upload:t.Upload},$=e.defineComponent({name:`${i.prefix}-icon-set`,props:{name:{type:String,default:""}},setup(n){return()=>e.h(P[n.name],{class:`${i.prefix}-icon`})}}),p=e.defineComponent({name:`${i.prefix}-icon`,props:{name:{type:String,default:""}},setup(n){const d=e.inject("customIcon");return()=>{const r=d.value[n.name];return typeof r=="object"?typeof r.component=="object"?e.h(r.component,r.props):e.createVNode("span",{innerHTML:r.component},null):e.createVNode($,{name:n.name},null)}}}),B={title:{type:[String,Object],default:""},visible:{type:Boolean,default:!1},width:{type:String,default:"auto"},height:{type:String,default:"auto"},onClose:{type:Function},showAdjust:{type:Boolean,default:!1},isFullscreen:{type:Boolean,default:!1},onAdjust:{type:Function,default:()=>{}},class:{type:String,default:void 0},style:{type:[Object,String],default:()=>({})},showMask:{type:Boolean,default:!0}},m=e.defineComponent({name:"MdModal",props:B,emits:["onClose"],setup(n,d){const r=e.inject("theme"),C=e.inject("rootRef"),f=e.ref(n.visible),c=e.ref([`${i.prefix}-modal`]),h=e.ref(),v=e.ref(),y=e.ref(),b=e.shallowRef();let u=()=>{};const o=e.reactive({maskStyle:{zIndex:-1},modalStyle:{zIndex:-1},initPos:{insetInlineStart:"0px",insetBlockStart:"0px"},historyPos:{insetInlineStart:"0px",insetBlockStart:"0px"}}),w=e.computed(()=>n.isFullscreen?{width:"100%",height:"100%"}:{width:n.width,height:n.height});e.watch(()=>n.isFullscreen,l=>{l?u():e.nextTick(()=>{u=x.keyMove(v.value,(a,s)=>{o.initPos.insetInlineStart=a+"px",o.initPos.insetBlockStart=s+"px"})})}),e.watch(()=>n.visible,l=>{l?(o.maskStyle.zIndex=i.globalConfig.editorConfig.zIndex+S.getZIndexIncrement(),o.modalStyle.zIndex=i.globalConfig.editorConfig.zIndex+S.getZIndexIncrement(),c.value.push("zoom-in"),f.value=l,e.nextTick(()=>{const a=h.value.offsetWidth/2,s=h.value.offsetHeight/2,N=document.documentElement.clientWidth/2,M=document.documentElement.clientHeight/2;o.initPos.insetInlineStart=N-a+"px",o.initPos.insetBlockStart=M-s+"px",n.isFullscreen||(u=x.keyMove(v.value,(V,j)=>{o.initPos.insetInlineStart=V+"px",o.initPos.insetBlockStart=j+"px"}))}),setTimeout(()=>{c.value=c.value.filter(a=>a!=="zoom-in")},140)):(c.value.push("zoom-out"),u(),setTimeout(()=>{c.value=c.value.filter(a=>a!=="zoom-out"),f.value=l},130))});const g=e.computed(()=>({display:f.value?"block":"none"})),I=e.computed(()=>{if(typeof n.style=="string"){const l=Object.entries(g.value).map(([a,s])=>`${a}: ${s}`).join("; ");return[n.style,l].join("; ")}else return n.style instanceof Object?{...g.value,...n.style}:g.value});return e.onMounted(()=>{const l=C.value?.getRootNode();y.value=l instanceof Document?document.body:l}),()=>{const l=k.getSlot({ctx:d}),a=k.getSlot({props:n,ctx:d},"title");return y.value?e.createVNode(e.Teleport,{to:y.value},{default:()=>[e.createVNode("div",{ref:b,class:`${i.prefix}-modal-container`,"data-theme":r.value},[e.createVNode("div",{class:n.class,style:I.value},[n.showMask&&e.createVNode("div",{class:`${i.prefix}-modal-mask`,style:o.maskStyle,onClick:()=>{n.onClose?.(),d.emit("onClose")}},null),e.createVNode("div",{class:c.value,style:{...o.modalStyle,...o.initPos,...w.value},ref:h},[e.createVNode("div",{class:`${i.prefix}-modal-header`,ref:v},[a||""]),e.createVNode("div",{class:`${i.prefix}-modal-body`},[l]),e.createVNode("div",{class:`${i.prefix}-modal-func`},[n.showAdjust&&e.createVNode("div",{class:`${i.prefix}-modal-adjust`,onClick:s=>{s.stopPropagation(),n.isFullscreen?o.initPos=o.historyPos:(o.historyPos=o.initPos,o.initPos={insetInlineStart:"0",insetBlockStart:"0"}),n.onAdjust(!n.isFullscreen)}},[e.createVNode(p,{name:n.isFullscreen?"minimize":"maximize"},null)]),e.createVNode("div",{class:`${i.prefix}-modal-close`,onClick:s=>{s.stopPropagation(),n.onClose?.(),d.emit("onClose")}},[e.createVNode(p,{name:"close"},null)])])])])])]}):""}}});m.install=n=>(n.component(m.name,m),n);exports.Icon=p;exports.MdModal=m;