md-editor-v3 4.12.0 → 4.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/DropdownToolbar.cjs +3 -1
- package/lib/cjs/MdCatalog.cjs +270 -1
- package/lib/cjs/MdEditor.cjs +3101 -58
- package/lib/cjs/MdModal.cjs +3 -1
- package/lib/cjs/MdPreview.cjs +3 -1
- package/lib/cjs/ModalToolbar.cjs +124 -1
- package/lib/cjs/NormalToolbar.cjs +61 -1
- package/lib/cjs/chunks/config.cjs +290 -1
- package/lib/cjs/chunks/dom.cjs +64 -1
- package/lib/cjs/chunks/index.cjs +1863 -8
- package/lib/cjs/chunks/index2.cjs +198 -1
- package/lib/cjs/chunks/index3.cjs +270 -1
- package/lib/cjs/chunks/index4.cjs +141 -2
- package/lib/cjs/chunks/vue-tsx.cjs +10 -1
- package/lib/cjs/config.cjs +12 -1
- package/lib/cjs/index.cjs +25 -1
- package/lib/es/DropdownToolbar.mjs +2 -2
- package/lib/es/MdCatalog.mjs +164 -114
- package/lib/es/MdEditor.mjs +2292 -1677
- package/lib/es/MdModal.mjs +2 -2
- package/lib/es/MdPreview.mjs +2 -2
- package/lib/es/ModalToolbar.mjs +55 -38
- package/lib/es/NormalToolbar.mjs +26 -18
- package/lib/es/chunks/config.mjs +73 -54
- package/lib/es/chunks/dom.mjs +57 -24
- package/lib/es/chunks/index.mjs +1093 -611
- package/lib/es/chunks/index2.mjs +126 -78
- package/lib/es/chunks/index3.mjs +185 -111
- package/lib/es/chunks/index4.mjs +124 -73
- package/lib/es/chunks/vue-tsx.mjs +8 -8
- package/lib/es/config.mjs +11 -10
- package/lib/es/index.mjs +23 -23
- package/lib/preview.css +200 -1
- package/lib/style.css +592 -1
- package/lib/types/MdEditor/components/Modal/Modal.d.ts +1 -1
- package/lib/types/MdEditor/components/Modal/index.d.ts +3 -3
- package/lib/umd/index.js +75625 -114
- package/package.json +1 -1
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -1,67 +1,3110 @@
|
|
|
1
|
-
"use strict";var ht=Object.defineProperty;var vt=(e,a,o)=>a in e?ht(e,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[a]=o;var F=(e,a,o)=>(vt(e,typeof a!="symbol"?a+"":a,o),o);const t=require("vue"),l=require("./chunks/config.cjs"),ee=require("@vavt/util"),U=require("./chunks/index2.cjs"),u=require("./chunks/index4.cjs"),pt=require("./chunks/dom.cjs"),N=require("./chunks/index3.cjs"),Y=require("codemirror"),te=require("@codemirror/view"),Ct=require("@codemirror/language-data"),kt=require("@codemirror/lang-markdown"),S=require("@codemirror/state"),j=require("@codemirror/commands"),oe=require("@codemirror/language"),s=require("@lezer/highlight"),xt=require("@codemirror/autocomplete"),O=require("./chunks/index.cjs"),bt=require("./MdCatalog.cjs"),et=require("./chunks/vue-tsx.cjs"),Nt=require("./NormalToolbar.cjs"),$t=require("./ModalToolbar.cjs"),Vt=t.defineComponent({setup(){return()=>t.createVNode("div",{class:`${l.prefix}-divider`},null)}}),wt={noPrettier:{type:Boolean},toolbars:{type:Array,default:()=>[]},toolbarsExclude:{type:Array,default:()=>[]},setting:{type:Object,default:()=>({})},screenfull:{type:Object,default:null},screenfullJs:{type:String,default:""},updateSetting:{type:Function,default:()=>{}},tableShape:{type:Array,default:()=>[6,4]},defToolbars:{type:Object},noUploadImg:{type:Boolean},showToolbarName:{type:Boolean}},yt=e=>{var f,c,g,x;const a=t.inject("editorId");let o=(c=(f=l.configOption.editorExtensions)==null?void 0:f.screenfull)==null?void 0:c.instance;const r=(x=(g=l.configOption.editorExtensions)==null?void 0:g.screenfull)==null?void 0:x.js,i=t.ref(!1),n=k=>{if(!o){u.bus.emit(a,u.ERROR_CATCHER,{name:"fullscreen",message:"fullscreen is undefined"});return}o.isEnabled?(i.value=!0,(k===void 0?!o.isFullscreen:k)?o.request():o.exit()):console.error("browser does not support screenfull!")},h=()=>{o&&o.isEnabled&&o.on("change",()=>{(i.value||e.setting.fullscreen)&&(i.value=!1,e.updateSetting("fullscreen"))})},b=()=>{o=window.screenfull,h()};return t.onMounted(()=>{if(h(),!o){const k=document.createElement("script");k.src=r||l.screenfullUrl,k.onload=b,k.id=`${l.prefix}-screenfull`,pt.appendHandler(k,"screenfull")}}),t.onMounted(()=>{u.bus.on(a,{name:u.CHANGE_FULL_SCREEN,callback:n})}),{fullscreenHandler:n}},Tt={tableShape:{type:Array,default:()=>[6,4]},onSelected:{type:Function,default:()=>{}}},Et=t.defineComponent({name:"TableShape",props:Tt,setup(e){const a=t.reactive({x:-1,y:-1});return()=>t.createVNode("div",{class:`${l.prefix}-table-shape`,onMouseleave:()=>{a.x=-1,a.y=-1}},[new Array(e.tableShape[1]).fill("").map((o,r)=>t.createVNode("div",{class:`${l.prefix}-table-shape-row`,key:`table-shape-row-${r}`},[new Array(e.tableShape[0]).fill("").map((i,n)=>t.createVNode("div",{class:`${l.prefix}-table-shape-col`,key:`table-shape-col-${n}`,onMouseenter:()=>{a.x=r,a.y=n},onClick:()=>{e.onSelected(a)}},[t.createVNode("div",{class:[`${l.prefix}-table-shape-col-default`,r<=a.x&&n<=a.y&&`${l.prefix}-table-shape-col-include`]},null)]))]))])}}),St=Et,At={type:{type:String,default:"link"},visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Lt=t.defineComponent({props:At,setup(e){const a=t.inject("usedLanguageText"),o=t.inject("editorId"),r=t.computed(()=>{var n,h;switch(e.type){case"link":return(n=a.value.linkModalTips)==null?void 0:n.linkTitle;case"image":return(h=a.value.linkModalTips)==null?void 0:h.imageTitle;default:return""}}),i=t.reactive({desc:"",url:""});return t.watch(()=>e.visible,n=>{n||setTimeout(()=>{i.desc="",i.url=""},200)}),()=>t.createVNode(N.MdModal,{title:r.value,visible:e.visible,onClose:e.onCancel},{default:()=>{var n,h,b,f,c;return[t.createVNode("div",{class:`${l.prefix}-form-item`},[t.createVNode("label",{class:`${l.prefix}-label`,for:`link-desc-${o}`},[(n=a.value.linkModalTips)==null?void 0:n.descLabel]),t.createVNode("input",{placeholder:(h=a.value.linkModalTips)==null?void 0:h.descLabelPlaceHolder,class:`${l.prefix}-input`,id:`link-desc-${o}`,type:"text",value:i.desc,onChange:g=>{i.desc=g.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${l.prefix}-form-item`},[t.createVNode("label",{class:`${l.prefix}-label`,for:`link-url-${o}`},[(b=a.value.linkModalTips)==null?void 0:b.urlLabel]),t.createVNode("input",{placeholder:(f=a.value.linkModalTips)==null?void 0:f.urlLabelPlaceHolder,class:`${l.prefix}-input`,id:`link-url-${o}`,type:"text",value:i.url,onChange:g=>{i.url=g.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${l.prefix}-form-item`},[t.createVNode("button",{class:[`${l.prefix}-btn`,`${l.prefix}-btn-row`],type:"button",onClick:()=>{e.onOk(i),i.desc="",i.url=""}},[(c=a.value.linkModalTips)==null?void 0:c.buttonOK])])]}})}}),It={visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Mt=t.defineComponent({props:It,setup(e){var g,x,k;const a=t.inject("usedLanguageText"),o=t.inject("editorId");let r=(k=(x=(g=l.configOption)==null?void 0:g.editorExtensions)==null?void 0:x.cropper)==null?void 0:k.instance;const i=t.ref(),n=t.ref(),h=t.ref(),b=t.reactive({cropperInited:!1,imgSelected:!1,imgSrc:"",isFullscreen:!1});let f=null;t.watch(()=>e.visible,()=>{e.visible&&!b.cropperInited&&(r=r||window.Cropper,i.value.onchange=()=>{if(!r){u.bus.emit(o,u.ERROR_CATCHER,{name:"Cropper",message:"Cropper is undefined"});return}const w=i.value.files||[];if(b.imgSelected=!0,(w==null?void 0:w.length)>0){const y=new FileReader;y.onload=T=>{b.imgSrc=T.target.result,t.nextTick(()=>{f=new r(n.value,{viewMode:2,preview:`.${l.prefix}-clip-preview-target`})})},y.readAsDataURL(w[0])}})}),t.watch(()=>[b.imgSelected],()=>{h.value.style=""}),t.watch(()=>b.isFullscreen,()=>{t.nextTick(()=>{f==null||f.destroy(),h.value.style="",n.value&&(f=new r(n.value,{viewMode:2,preview:`.${l.prefix}-clip-preview-target`}))})});const c=()=>{f.clear(),f.destroy(),f=null,i.value.value="",b.imgSelected=!1};return()=>{var w;return t.createVNode(N.MdModal,{class:`${l.prefix}-modal-clip`,title:(w=a.value.clipModalTips)==null?void 0:w.title,visible:e.visible,onClose:e.onCancel,showAdjust:!0,isFullscreen:b.isFullscreen,onAdjust:y=>{b.isFullscreen=y},width:"668px",height:"421px"},{default:()=>{var y,T;return[t.createVNode("div",{class:`${l.prefix}-form-item ${l.prefix}-clip`},[t.createVNode("div",{class:`${l.prefix}-clip-main`},[b.imgSelected?t.createVNode("div",{class:`${l.prefix}-clip-cropper`},[t.createVNode("img",{src:b.imgSrc,ref:n,style:{display:"none"},alt:""},null),t.createVNode("div",{class:`${l.prefix}-clip-delete`,onClick:c},[t.createVNode(N.Icon,{name:"delete"},null)])]):t.createVNode("div",{class:`${l.prefix}-clip-upload`,onClick:()=>{i.value.click()}},[t.createVNode(N.Icon,{name:"upload"},null)])]),t.createVNode("div",{class:`${l.prefix}-clip-preview`},[t.createVNode("div",{class:`${l.prefix}-clip-preview-target`,ref:h},null)])]),t.createVNode("div",{class:`${l.prefix}-form-item`},[t.createVNode("button",{class:`${l.prefix}-btn`,type:"button",onClick:()=>{if(f){const d=f.getCroppedCanvas();u.bus.emit(o,u.UPLOAD_IMAGE,[u.base642File(d.toDataURL("image/png"))],e.onOk),c()}}},[((y=a.value.clipModalTips)==null?void 0:y.buttonUpload)||((T=a.value.linkModalTips)==null?void 0:T.buttonOK)])]),t.createVNode("input",{ref:i,accept:"image/*",type:"file",multiple:!1,style:{display:"none"}},null)]}})}}}),Rt={type:{type:String,default:"link"},linkVisible:{type:Boolean,default:!1},clipVisible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Ht=t.defineComponent({props:Rt,setup(e){return()=>t.createVNode(t.Fragment,null,[t.createVNode(Lt,{type:e.type,visible:e.linkVisible,onOk:e.onOk,onCancel:e.onCancel},null),t.createVNode(Mt,{visible:e.clipVisible,onOk:e.onOk,onCancel:e.onCancel},null)])}}),Dt=t.defineComponent({name:"MDEditorToolbar",props:wt,setup(e){const a=t.inject("editorId"),o=t.inject("usedLanguageText"),r=t.inject("theme"),i=t.inject("language"),{fullscreenHandler:n}=yt(e),h=`${a}-toolbar-wrapper`,b=t.ref(),f=t.reactive({title:!1,catalog:!1,image:!1,table:!1,mermaid:!1,katex:!1}),c=(d,m)=>{u.bus.emit(a,u.REPLACE,d,m)},g=t.reactive({type:"link",linkVisible:!1,clipVisible:!1}),x=t.ref();t.onMounted(()=>{u.bus.on(a,{name:u.OPEN_MODALS,callback(d){g.type=d,g.linkVisible=!0}})});const k=t.computed(()=>{const d=e.toolbars.filter(p=>!e.toolbarsExclude.includes(p)),m=d.indexOf("="),v=m===-1?d:d.slice(0,m+1),C=m===-1?[]:d.slice(m,Number.MAX_SAFE_INTEGER);return[v,C]}),w=t.ref(),y=()=>{u.bus.emit(a,u.UPLOAD_IMAGE,Array.from(w.value.files||[])),w.value.value=""};t.onMounted(()=>{w.value.addEventListener("change",y)});const T=d=>{var m,v,C,p,V,A,E,L,B,R,H,D,z,q,_,K,Z,X,W,P,I,re,se,de,ue,me,fe,ge,be,he,ve,pe,Ce,ke,xe,Ne,$e,Ve,we,ye,Te,Ee,Se,Ae,Le,Ie,Me,Re,He,De,Pe,Be,Oe,Fe,qe,_e,We,je,ze,Ge,Ue,Ke,Ze,Xe,Ye,Je,Qe;if(l.allToolbar.includes(d))switch(d){case"-":return t.createVNode(Vt,null,null);case"bold":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(m=o.value.toolbarTips)==null?void 0:m.bold,onClick:()=>{c("bold")}},[t.createVNode(N.Icon,{name:"bold"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(v=o.value.toolbarTips)==null?void 0:v.bold])]);case"underline":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(C=o.value.toolbarTips)==null?void 0:C.underline,onClick:()=>{c("underline")}},[t.createVNode(N.Icon,{name:"underline"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(p=o.value.toolbarTips)==null?void 0:p.underline])]);case"italic":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(V=o.value.toolbarTips)==null?void 0:V.italic,onClick:()=>{c("italic")}},[t.createVNode(N.Icon,{name:"italic"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(A=o.value.toolbarTips)==null?void 0:A.italic])]);case"strikeThrough":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(E=o.value.toolbarTips)==null?void 0:E.strikeThrough,onClick:()=>{c("strikeThrough")}},[t.createVNode(N.Icon,{name:"strike-through"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(L=o.value.toolbarTips)==null?void 0:L.strikeThrough])]);case"title":return t.createVNode(U.Dropdown,{relative:`#${h}`,visible:f.title,onChange:$=>{f.title=$},overlay:t.createVNode("ul",{class:`${l.prefix}-menu`,onClick:()=>{f.title=!1}},[t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-title`,onClick:()=>{c("h1")}},[(B=o.value.titleItem)==null?void 0:B.h1]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-title`,onClick:()=>{c("h2")}},[(R=o.value.titleItem)==null?void 0:R.h2]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-title`,onClick:()=>{c("h3")}},[(H=o.value.titleItem)==null?void 0:H.h3]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-title`,onClick:()=>{c("h4")}},[(D=o.value.titleItem)==null?void 0:D.h4]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-title`,onClick:()=>{c("h5")}},[(z=o.value.titleItem)==null?void 0:z.h5]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-title`,onClick:()=>{c("h6")}},[(q=o.value.titleItem)==null?void 0:q.h6])])},{default:()=>{var $,M;return[t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.title},[t.createVNode(N.Icon,{name:"title"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(M=o.value.toolbarTips)==null?void 0:M.title])])]}});case"sub":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(_=o.value.toolbarTips)==null?void 0:_.sub,onClick:()=>{c("sub")}},[t.createVNode(N.Icon,{name:"sub"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(K=o.value.toolbarTips)==null?void 0:K.sub])]);case"sup":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Z=o.value.toolbarTips)==null?void 0:Z.sup,onClick:()=>{c("sup")}},[t.createVNode(N.Icon,{name:"sup"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(X=o.value.toolbarTips)==null?void 0:X.sup])]);case"quote":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(W=o.value.toolbarTips)==null?void 0:W.quote,onClick:()=>{c("quote")}},[t.createVNode(N.Icon,{name:"quote"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(P=o.value.toolbarTips)==null?void 0:P.quote])]);case"unorderedList":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(I=o.value.toolbarTips)==null?void 0:I.unorderedList,onClick:()=>{c("unorderedList")}},[t.createVNode(N.Icon,{name:"unordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(re=o.value.toolbarTips)==null?void 0:re.unorderedList])]);case"orderedList":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(se=o.value.toolbarTips)==null?void 0:se.orderedList,onClick:()=>{c("orderedList")}},[t.createVNode(N.Icon,{name:"ordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(de=o.value.toolbarTips)==null?void 0:de.orderedList])]);case"task":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(ue=o.value.toolbarTips)==null?void 0:ue.task,onClick:()=>{c("task")}},[t.createVNode(N.Icon,{name:"task"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(me=o.value.toolbarTips)==null?void 0:me.task])]);case"codeRow":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(fe=o.value.toolbarTips)==null?void 0:fe.codeRow,onClick:()=>{c("codeRow")}},[t.createVNode(N.Icon,{name:"code-row"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(ge=o.value.toolbarTips)==null?void 0:ge.codeRow])]);case"code":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(be=o.value.toolbarTips)==null?void 0:be.code,onClick:()=>{c("code")}},[t.createVNode(N.Icon,{name:"code"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(he=o.value.toolbarTips)==null?void 0:he.code])]);case"link":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(ve=o.value.toolbarTips)==null?void 0:ve.link,onClick:()=>{g.type="link",g.linkVisible=!0}},[t.createVNode(N.Icon,{name:"link"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(pe=o.value.toolbarTips)==null?void 0:pe.link])]);case"image":return e.noUploadImg?t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Ce=o.value.toolbarTips)==null?void 0:Ce.image,onClick:()=>{g.type="image",g.linkVisible=!0}},[t.createVNode(N.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(ke=o.value.toolbarTips)==null?void 0:ke.image])]):t.createVNode(U.Dropdown,{relative:`#${h}`,visible:f.image,onChange:$=>{f.image=$},overlay:t.createVNode("ul",{class:`${l.prefix}-menu`,onClick:()=>{f.title=!1}},[t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-image`,onClick:()=>{g.type="image",g.linkVisible=!0}},[(xe=o.value.imgTitleItem)==null?void 0:xe.link]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-image`,onClick:()=>{w.value.click()}},[(Ne=o.value.imgTitleItem)==null?void 0:Ne.upload]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-image`,onClick:()=>{g.clipVisible=!0}},[($e=o.value.imgTitleItem)==null?void 0:$e.clip2upload])])},{default:()=>{var $,M;return[t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.image},[t.createVNode(N.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(M=o.value.toolbarTips)==null?void 0:M.image])])]}});case"table":return t.createVNode(U.Dropdown,{relative:`#${h}`,visible:f.table,onChange:$=>{f.table=$},key:"bar-table",overlay:t.createVNode(St,{tableShape:e.tableShape,onSelected:$=>{c("table",{selectedShape:$})}},null)},{default:()=>{var $,M;return[t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.table},[t.createVNode(N.Icon,{name:"table"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(M=o.value.toolbarTips)==null?void 0:M.table])])]}});case"revoke":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Ve=o.value.toolbarTips)==null?void 0:Ve.revoke,onClick:()=>{u.bus.emit(a,u.CTRL_Z)}},[t.createVNode(N.Icon,{name:"revoke"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(we=o.value.toolbarTips)==null?void 0:we.revoke])]);case"next":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(ye=o.value.toolbarTips)==null?void 0:ye.next,onClick:()=>{u.bus.emit(a,u.CTRL_SHIFT_Z)}},[t.createVNode(N.Icon,{name:"next"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(Te=o.value.toolbarTips)==null?void 0:Te.next])]);case"save":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Ee=o.value.toolbarTips)==null?void 0:Ee.save,onClick:()=>{u.bus.emit(a,u.ON_SAVE)}},[t.createVNode(N.Icon,{name:"baocun"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(Se=o.value.toolbarTips)==null?void 0:Se.save])]);case"prettier":return e.noPrettier?"":t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Ae=o.value.toolbarTips)==null?void 0:Ae.prettier,onClick:()=>{c("prettier")}},[t.createVNode(N.Icon,{name:"prettier"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(Le=o.value.toolbarTips)==null?void 0:Le.prettier])]);case"pageFullscreen":return!e.setting.fullscreen&&t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Ie=o.value.toolbarTips)==null?void 0:Ie.pageFullscreen,onClick:()=>{e.updateSetting("pageFullscreen")}},[t.createVNode(N.Icon,{name:e.setting.pageFullscreen?"suoxiao":"fangda"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(Me=o.value.toolbarTips)==null?void 0:Me.pageFullscreen])]);case"fullscreen":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Re=o.value.toolbarTips)==null?void 0:Re.fullscreen,onClick:()=>{n()}},[t.createVNode(N.Icon,{name:e.setting.fullscreen?"fullscreen-exit":"fullscreen"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(He=o.value.toolbarTips)==null?void 0:He.fullscreen])]);case"preview":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(De=o.value.toolbarTips)==null?void 0:De.preview,onClick:()=>{e.updateSetting("preview")}},[t.createVNode(N.Icon,{name:"preview"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(Pe=o.value.toolbarTips)==null?void 0:Pe.preview])]);case"htmlPreview":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Be=o.value.toolbarTips)==null?void 0:Be.htmlPreview,onClick:()=>{e.updateSetting("htmlPreview")}},[t.createVNode(N.Icon,{name:"coding"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(Oe=o.value.toolbarTips)==null?void 0:Oe.htmlPreview])]);case"catalog":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(Fe=o.value.toolbarTips)==null?void 0:Fe.catalog,onClick:()=>{u.bus.emit(a,u.CHANGE_CATALOG_VISIBLE)},key:"bar-catalog"},[t.createVNode(N.Icon,{name:"catalog"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(qe=o.value.toolbarTips)==null?void 0:qe.catalog])]);case"github":return t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:(_e=o.value.toolbarTips)==null?void 0:_e.github,onClick:()=>ee.linkTo("https://github.com/imzbf/md-editor-v3")},[t.createVNode(N.Icon,{name:"github"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(We=o.value.toolbarTips)==null?void 0:We.github])]);case"mermaid":return t.createVNode(U.Dropdown,{relative:`#${h}`,visible:f.mermaid,onChange:$=>{f.mermaid=$},overlay:t.createVNode("ul",{class:`${l.prefix}-menu`,onClick:()=>{f.mermaid=!1}},[t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("flow")}},[(je=o.value.mermaid)==null?void 0:je.flow]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("sequence")}},[(ze=o.value.mermaid)==null?void 0:ze.sequence]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("gantt")}},[(Ge=o.value.mermaid)==null?void 0:Ge.gantt]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("class")}},[(Ue=o.value.mermaid)==null?void 0:Ue.class]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("state")}},[(Ke=o.value.mermaid)==null?void 0:Ke.state]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("pie")}},[(Ze=o.value.mermaid)==null?void 0:Ze.pie]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("relationship")}},[(Xe=o.value.mermaid)==null?void 0:Xe.relationship]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-mermaid`,onClick:()=>{c("journey")}},[(Ye=o.value.mermaid)==null?void 0:Ye.journey])]),key:"bar-mermaid"},{default:()=>{var $,M;return[t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.mermaid},[t.createVNode(N.Icon,{name:"mermaid"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(M=o.value.toolbarTips)==null?void 0:M.mermaid])])]}});case"katex":return t.createVNode(U.Dropdown,{relative:`#${h}`,visible:f.katex,onChange:$=>{f.katex=$},overlay:t.createVNode("ul",{class:`${l.prefix}-menu`,onClick:()=>{f.katex=!1}},[t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-katex`,onClick:()=>{c("katexInline")}},[(Je=o.value.katex)==null?void 0:Je.inline]),t.createVNode("li",{class:`${l.prefix}-menu-item ${l.prefix}-menu-item-katex`,onClick:()=>{c("katexBlock")}},[(Qe=o.value.katex)==null?void 0:Qe.block])]),key:"bar-katex"},{default:()=>{var $,M;return[t.createVNode("div",{class:`${l.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.katex},[t.createVNode(N.Icon,{name:"formula"},null),e.showToolbarName&&t.createVNode("div",{class:`${l.prefix}-toolbar-item-name`},[(M=o.value.toolbarTips)==null?void 0:M.katex])])]}})}else if(e.defToolbars instanceof Array){const $=e.defToolbars[d];return $?t.cloneVNode($,{theme:r.value,language:i.value,insert(ne){u.bus.emit(a,u.REPLACE,"universal",{generate:ne})}}):""}else if(e.defToolbars&&e.defToolbars.children instanceof Array){const $=e.defToolbars.children[d];return $?t.cloneVNode($,{theme:r.value,language:i.value,insert(ne){u.bus.emit(a,u.REPLACE,"universal",{generate:ne})}}):""}else return""};return t.watch(()=>e.toolbars,()=>{t.nextTick(()=>{b.value&&ee.draggingScroll(b.value)})},{immediate:!0}),()=>{const d=k.value[0].map(v=>T(v)),m=k.value[1].map(v=>T(v));return t.createVNode(t.Fragment,null,[e.toolbars.length>0&&t.createVNode("div",{class:`${l.prefix}-toolbar-wrapper`,ref:b,id:h},[t.createVNode("div",{class:[`${l.prefix}-toolbar`,e.showToolbarName&&`${l.prefix}-stn`]},[t.createVNode("div",{class:`${l.prefix}-toolbar-left`,ref:x},[d]),t.createVNode("div",{class:`${l.prefix}-toolbar-right`},[m])])]),t.createVNode("input",{ref:w,accept:"image/*",type:"file",multiple:!0,style:{display:"none"}},null),t.createVNode(Ht,{linkVisible:g.linkVisible,clipVisible:g.clipVisible,type:g.type,onCancel:()=>{g.linkVisible=!1,g.clipVisible=!1},onOk:v=>{v&&c(g.type,{desc:v.desc,url:v.url}),g.linkVisible=!1,g.clipVisible=!1}},null)])}}}),Pt=`.${l.prefix}-preview > [data-line]`,Bt=(e,a)=>{const o=ee.debounce(()=>{e.removeEventListener("scroll",r),e.addEventListener("scroll",r),a.removeEventListener("scroll",r),a.addEventListener("scroll",r)},50),r=i=>{const n=e.clientHeight,h=a.clientHeight,b=e.scrollHeight,f=a.scrollHeight,c=(b-n)/(f-h);i.target===e?(a.removeEventListener("scroll",r),a.scrollTo({top:e.scrollTop/c}),o()):(e.removeEventListener("scroll",r),e.scrollTo({top:a.scrollTop*c}),o())};return[()=>{o().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",r),a.removeEventListener("scroll",r)}]},Ot=(e,a,o)=>{const{view:r}=o,i=ee.createSmoothScroll(),n=d=>r.lineBlockAt(r.state.doc.line(d).from).top,h=d=>r.lineBlockAt(r.state.doc.line(d).from).height;let b=[],f=[],c=[];const g=()=>{b=[],f=[],c=[],f=f.concat(Array.from(a.querySelectorAll(Pt)));const d=f.map(p=>Number(p.dataset.line)+1);c=c.concat(d);const{lines:m}=r.state.doc;let v=1,C=d.shift()??m;for(let p=1;p<=m;p++)p===C&&(v=p,C=d.shift()||m+1),b.push({start:v,end:C-1})};let x=0,k=0;const w=()=>{var q,_;if(k!==0)return!1;x++;const{scrollDOM:d,contentHeight:m}=r;let v=+getComputedStyle(a).paddingTop.replace("px","");const C=r.lineBlockAtHeight(d.scrollTop),{number:p}=r.state.doc.lineAt(C.from),V=b[p-1];if(!V)return!1;let A=n(V.end)+h(V.end),E=0;const L=n(V.start),B=a.querySelector(`[data-line="${V.start-1}"]`)||((q=a.firstElementChild)==null?void 0:q.firstElementChild),R=a.querySelector(`[data-line="${V.end}"]`)||((_=a.lastElementChild)==null?void 0:_.lastElementChild);let H=0,D=0;L===0?(E=d.scrollTop/A,B===R?(v=0,A=m-d.offsetHeight,H=R.offsetTop+R.offsetHeight-a.clientHeight):H=R.offsetTop):(E=(d.scrollTop-L)/(A-L),D=B.offsetTop,H=R.offsetTop-D),A>d.scrollHeight-d.clientHeight&&(E=(d.scrollTop-L)/(d.scrollHeight-d.clientHeight-L),D=B.offsetTop,H=a.scrollHeight-a.clientHeight-D+10);const z=D-v+H*E;i(a,z,()=>{x--})},y=()=>{var z,q,_,K,Z,X;if(x!==0)return;k++;const{scrollDOM:d}=r,m=a.scrollTop,v=a.scrollHeight;let C=(z=a.firstElementChild)==null?void 0:z.firstElementChild,p=(q=a.firstElementChild)==null?void 0:q.lastElementChild;if(c.length>0){let W=Math.ceil(Number(c[c.length-1])*(m/v)),P=c.findLastIndex(I=>I<=W);P=P===-1?0:P,W=c[P];for(let I=P;I>=0&&I<c.length;)if(f[I].offsetTop>m){if(I-1>=0){I--;continue}W=-1,P=I;break}else{if(I+1<=c.length&&f[I+1].offsetTop<m){I++;continue}W=c[I],P=I;break}switch(W){case-1:{C=(_=a.firstElementChild)==null?void 0:_.firstElementChild,p=f[P];break}case c.length-1:{C=f[P],p=(K=a.firstElementChild)==null?void 0:K.lastElementChild;break}default:C=f[P],p=f[P+1]}}const V=C===((Z=a.firstElementChild)==null?void 0:Z.firstElementChild)?0:C.offsetTop;let A=p.offsetTop,E=0;const{start:L,end:B}=b[Number(C.dataset.line||0)],R=n(L);let H=n(B+1),D=0;H>d.scrollHeight-d.clientHeight||p.scrollTop>a.scrollHeight-a.clientHeight?(E=Math.max((m-V)/(a.scrollHeight-V-a.clientHeight),0),H=n(r.state.doc.lines)+h(r.state.doc.lines),D=8+H-R-e.clientHeight):C===((X=a.firstElementChild)==null?void 0:X.firstElementChild)?(C===p&&(A=p.offsetTop+p.offsetHeight+ +getComputedStyle(p).marginBottom.replace("px","")),D=H,E=Math.max(m/A,0)):(E=Math.max((m-V)/(A-V),0),D=H-R),i(e,R+D*E,()=>{k--})},T=ee.throttle(d=>{var p;const{scrollDOM:m,contentHeight:v}=r,C=m.clientHeight;if(v<=C||a.firstElementChild.clientHeight<=a.clientHeight||r.state.doc.lines<((p=b[b.length-1])==null?void 0:p.end))return!1;d.target===e?w():y()},8);return[()=>{g(),e.addEventListener("scroll",T),a.addEventListener("scroll",T),e.dispatchEvent(new Event("scroll"))},()=>{e.removeEventListener("scroll",T),a.removeEventListener("scroll",T)}]},Ft=(e,a,o)=>{const r=t.inject("editorId");let i=()=>{},n=()=>{};const h=()=>{i();const b=document.querySelector(`#${r} .cm-scroller`),f=document.querySelector(`[id="${r}-preview-wrapper"]`),c=document.querySelector(`[id="${r}-html-wrapper"]`);(f||c)&&([n,i]=(f?Ot:Bt)(b,f||c,o.value)),e.scrollAuto&&n()};t.watch([a,t.toRef(e.setting,"preview"),t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"fullscreen"),t.toRef(e.setting,"pageFullscreen")],()=>{t.nextTick(h)}),t.watch(()=>e.scrollAuto,b=>{b?n():i()}),t.onMounted(h)},qt=(e,a,o)=>{var g,x,k,w,y,T;let r="",i=0,n=0,h=!0,b=!1;const f=a.getSelectedText(),c=(g=l.configOption.editorConfig)==null?void 0:g.mermaidTemplate;if(/^h[1-6]{1}$/.test(e)){const d=e.replace(/^h(\d)/,(m,v)=>new Array(Number(v)).fill("#",0,v).join(""));r=`${d} ${f}`,i=d.length+1}else if(e==="prettier"){const d=window.prettier||((k=(x=l.configOption.editorExtensions)==null?void 0:x.prettier)==null?void 0:k.prettierInstance),m=[((w=window.prettierPlugins)==null?void 0:w.markdown)||((T=(y=l.configOption.editorExtensions)==null?void 0:y.prettier)==null?void 0:T.parserMarkdownInstance)];!d||m[0]===void 0?(u.bus.emit(o.editorId,u.ERROR_CATCHER,{name:"prettier",message:"prettier is undefined"}),r=a.getValue()):r=d.format(a.getValue(),{parser:"markdown",plugins:m}),h=!1,b=!0}else switch(e){case"bold":{r=`**${f}**`,i=2,n=-2;break}case"underline":{r=`<u>${f}</u>`,i=3,n=-4;break}case"italic":{r=`*${f}*`,i=1,n=-1;break}case"strikeThrough":{r=`~~${f}~~`,i=2,n=-2;break}case"sub":{r=`<sub>${f}</sub>`,i=5,n=-6;break}case"sup":{r=`<sup>${f}</sup>`,i=5,n=-6;break}case"codeRow":{r="`"+f+"`",i=1,n=-1;break}case"quote":{r=`> ${f}`,i=2;break}case"orderedList":{r=`1. ${f}`,i=3;break}case"unorderedList":{r=`- ${f}`,i=2;break}case"task":{r=`- [ ] ${f}`,i=6;break}case"code":{const d=o.text||f||"",m=o.mode||"language";r=`\`\`\`${m}
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
const vue = require("vue");
|
|
9
|
+
const config = require("./chunks/config.cjs");
|
|
10
|
+
const util = require("@vavt/util");
|
|
11
|
+
const DropdownToolbar = require("./chunks/index2.cjs");
|
|
12
|
+
const index = require("./chunks/index4.cjs");
|
|
13
|
+
const dom = require("./chunks/dom.cjs");
|
|
14
|
+
const MdModal = require("./chunks/index3.cjs");
|
|
15
|
+
const codemirror = require("codemirror");
|
|
16
|
+
const view = require("@codemirror/view");
|
|
17
|
+
const languageData = require("@codemirror/language-data");
|
|
18
|
+
const langMarkdown = require("@codemirror/lang-markdown");
|
|
19
|
+
const state = require("@codemirror/state");
|
|
20
|
+
const commands = require("@codemirror/commands");
|
|
21
|
+
const language = require("@codemirror/language");
|
|
22
|
+
const highlight = require("@lezer/highlight");
|
|
23
|
+
const autocomplete = require("@codemirror/autocomplete");
|
|
24
|
+
const MdPreview = require("./chunks/index.cjs");
|
|
25
|
+
const MdCatalog = require("./MdCatalog.cjs");
|
|
26
|
+
const vueTsx = require("./chunks/vue-tsx.cjs");
|
|
27
|
+
const NormalToolbar = require("./NormalToolbar.cjs");
|
|
28
|
+
const ModalToolbar = require("./ModalToolbar.cjs");
|
|
29
|
+
const Divider = /* @__PURE__ */ vue.defineComponent({
|
|
30
|
+
setup() {
|
|
31
|
+
return () => vue.createVNode("div", {
|
|
32
|
+
"class": `${config.prefix}-divider`
|
|
33
|
+
}, null);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const toolbarProps = {
|
|
37
|
+
noPrettier: {
|
|
38
|
+
type: Boolean
|
|
39
|
+
},
|
|
40
|
+
// 工具栏选择显示
|
|
41
|
+
toolbars: {
|
|
42
|
+
type: Array,
|
|
43
|
+
default: () => []
|
|
44
|
+
},
|
|
45
|
+
// 工具栏选择不显示
|
|
46
|
+
toolbarsExclude: {
|
|
47
|
+
type: Array,
|
|
48
|
+
default: () => []
|
|
49
|
+
},
|
|
50
|
+
setting: {
|
|
51
|
+
type: Object,
|
|
52
|
+
default: () => ({})
|
|
53
|
+
},
|
|
54
|
+
screenfull: {
|
|
55
|
+
type: Object,
|
|
56
|
+
default: null
|
|
57
|
+
},
|
|
58
|
+
screenfullJs: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: ""
|
|
61
|
+
},
|
|
62
|
+
updateSetting: {
|
|
63
|
+
type: Function,
|
|
64
|
+
default: () => {
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
tableShape: {
|
|
68
|
+
type: Array,
|
|
69
|
+
default: () => [6, 4]
|
|
70
|
+
},
|
|
71
|
+
defToolbars: {
|
|
72
|
+
type: Object
|
|
73
|
+
},
|
|
74
|
+
noUploadImg: {
|
|
75
|
+
type: Boolean
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* 是否在工具栏下面显示对应的文字名称
|
|
79
|
+
*
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
showToolbarName: {
|
|
83
|
+
type: Boolean
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const useSreenfull = (props2) => {
|
|
87
|
+
var _a, _b, _c, _d;
|
|
88
|
+
const editorId = vue.inject("editorId");
|
|
89
|
+
let screenfull = (_b = (_a = config.configOption.editorExtensions) == null ? void 0 : _a.screenfull) == null ? void 0 : _b.instance;
|
|
90
|
+
const screenfullJs = (_d = (_c = config.configOption.editorExtensions) == null ? void 0 : _c.screenfull) == null ? void 0 : _d.js;
|
|
91
|
+
const screenfullMe = vue.ref(false);
|
|
92
|
+
const fullscreenHandler = (status) => {
|
|
93
|
+
if (!screenfull) {
|
|
94
|
+
index.bus.emit(editorId, index.ERROR_CATCHER, {
|
|
95
|
+
name: "fullscreen",
|
|
96
|
+
message: "fullscreen is undefined"
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (screenfull.isEnabled) {
|
|
101
|
+
screenfullMe.value = true;
|
|
102
|
+
const targetStatus = status === void 0 ? !screenfull.isFullscreen : status;
|
|
103
|
+
if (targetStatus) {
|
|
104
|
+
screenfull.request();
|
|
105
|
+
} else {
|
|
106
|
+
screenfull.exit();
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
console.error("browser does not support screenfull!");
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const onScreenfullEvent = () => {
|
|
113
|
+
if (screenfull && screenfull.isEnabled) {
|
|
114
|
+
screenfull.on("change", () => {
|
|
115
|
+
if (screenfullMe.value || props2.setting.fullscreen) {
|
|
116
|
+
screenfullMe.value = false;
|
|
117
|
+
props2.updateSetting("fullscreen");
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const screenfullLoad = () => {
|
|
123
|
+
screenfull = window.screenfull;
|
|
124
|
+
onScreenfullEvent();
|
|
125
|
+
};
|
|
126
|
+
vue.onMounted(() => {
|
|
127
|
+
onScreenfullEvent();
|
|
128
|
+
if (!screenfull) {
|
|
129
|
+
const screenScript = document.createElement("script");
|
|
130
|
+
screenScript.src = screenfullJs || config.screenfullUrl;
|
|
131
|
+
screenScript.onload = screenfullLoad;
|
|
132
|
+
screenScript.id = `${config.prefix}-screenfull`;
|
|
133
|
+
dom.appendHandler(screenScript, "screenfull");
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
vue.onMounted(() => {
|
|
137
|
+
index.bus.on(editorId, {
|
|
138
|
+
name: index.CHANGE_FULL_SCREEN,
|
|
139
|
+
callback: fullscreenHandler
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
return { fullscreenHandler };
|
|
143
|
+
};
|
|
144
|
+
const props$6 = {
|
|
145
|
+
tableShape: {
|
|
146
|
+
type: Array,
|
|
147
|
+
default: () => [6, 4]
|
|
148
|
+
},
|
|
149
|
+
onSelected: {
|
|
150
|
+
type: Function,
|
|
151
|
+
default: () => {
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const TableShape = /* @__PURE__ */ vue.defineComponent({
|
|
156
|
+
name: "TableShape",
|
|
157
|
+
props: props$6,
|
|
158
|
+
setup(props2) {
|
|
159
|
+
const hoverPosition = vue.reactive({
|
|
160
|
+
x: -1,
|
|
161
|
+
y: -1
|
|
162
|
+
});
|
|
163
|
+
return () => vue.createVNode("div", {
|
|
164
|
+
"class": `${config.prefix}-table-shape`,
|
|
165
|
+
"onMouseleave": () => {
|
|
166
|
+
hoverPosition.x = -1;
|
|
167
|
+
hoverPosition.y = -1;
|
|
168
|
+
}
|
|
169
|
+
}, [new Array(props2.tableShape[1]).fill("").map((_, rowIndex) => vue.createVNode("div", {
|
|
170
|
+
"class": `${config.prefix}-table-shape-row`,
|
|
171
|
+
"key": `table-shape-row-${rowIndex}`
|
|
172
|
+
}, [new Array(props2.tableShape[0]).fill("").map((_2, colIndex) => vue.createVNode("div", {
|
|
173
|
+
"class": `${config.prefix}-table-shape-col`,
|
|
174
|
+
"key": `table-shape-col-${colIndex}`,
|
|
175
|
+
"onMouseenter": () => {
|
|
176
|
+
hoverPosition.x = rowIndex;
|
|
177
|
+
hoverPosition.y = colIndex;
|
|
178
|
+
},
|
|
179
|
+
"onClick": () => {
|
|
180
|
+
props2.onSelected(hoverPosition);
|
|
181
|
+
}
|
|
182
|
+
}, [vue.createVNode("div", {
|
|
183
|
+
"class": [`${config.prefix}-table-shape-col-default`, rowIndex <= hoverPosition.x && colIndex <= hoverPosition.y && `${config.prefix}-table-shape-col-include`]
|
|
184
|
+
}, null)]))]))]);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
const TableShape$1 = TableShape;
|
|
188
|
+
const props$5 = {
|
|
189
|
+
type: {
|
|
190
|
+
type: String,
|
|
191
|
+
default: "link"
|
|
192
|
+
},
|
|
193
|
+
visible: {
|
|
194
|
+
type: Boolean,
|
|
195
|
+
default: false
|
|
196
|
+
},
|
|
197
|
+
onCancel: {
|
|
198
|
+
type: Function,
|
|
199
|
+
default: () => {
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
onOk: {
|
|
203
|
+
type: Function,
|
|
204
|
+
default: () => {
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const LinkModal = /* @__PURE__ */ vue.defineComponent({
|
|
209
|
+
props: props$5,
|
|
210
|
+
setup(props2) {
|
|
211
|
+
const ult = vue.inject("usedLanguageText");
|
|
212
|
+
const editorId = vue.inject("editorId");
|
|
213
|
+
const title = vue.computed(() => {
|
|
214
|
+
var _a, _b;
|
|
215
|
+
switch (props2.type) {
|
|
216
|
+
case "link": {
|
|
217
|
+
return (_a = ult.value.linkModalTips) == null ? void 0 : _a.linkTitle;
|
|
218
|
+
}
|
|
219
|
+
case "image": {
|
|
220
|
+
return (_b = ult.value.linkModalTips) == null ? void 0 : _b.imageTitle;
|
|
221
|
+
}
|
|
222
|
+
default: {
|
|
223
|
+
return "";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
const linkData = vue.reactive({
|
|
228
|
+
desc: "",
|
|
229
|
+
url: ""
|
|
230
|
+
});
|
|
231
|
+
vue.watch(() => props2.visible, (nVal) => {
|
|
232
|
+
if (!nVal) {
|
|
233
|
+
setTimeout(() => {
|
|
234
|
+
linkData.desc = "";
|
|
235
|
+
linkData.url = "";
|
|
236
|
+
}, 200);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
return () => vue.createVNode(MdModal.MdModal, {
|
|
240
|
+
"title": title.value,
|
|
241
|
+
"visible": props2.visible,
|
|
242
|
+
"onClose": props2.onCancel
|
|
243
|
+
}, {
|
|
244
|
+
default: () => {
|
|
245
|
+
var _a, _b, _c, _d, _e;
|
|
246
|
+
return [vue.createVNode("div", {
|
|
247
|
+
"class": `${config.prefix}-form-item`
|
|
248
|
+
}, [vue.createVNode("label", {
|
|
249
|
+
"class": `${config.prefix}-label`,
|
|
250
|
+
"for": `link-desc-${editorId}`
|
|
251
|
+
}, [(_a = ult.value.linkModalTips) == null ? void 0 : _a.descLabel]), vue.createVNode("input", {
|
|
252
|
+
"placeholder": (_b = ult.value.linkModalTips) == null ? void 0 : _b.descLabelPlaceHolder,
|
|
253
|
+
"class": `${config.prefix}-input`,
|
|
254
|
+
"id": `link-desc-${editorId}`,
|
|
255
|
+
"type": "text",
|
|
256
|
+
"value": linkData.desc,
|
|
257
|
+
"onChange": (e) => {
|
|
258
|
+
linkData.desc = e.target.value;
|
|
259
|
+
},
|
|
260
|
+
"autocomplete": "off"
|
|
261
|
+
}, null)]), vue.createVNode("div", {
|
|
262
|
+
"class": `${config.prefix}-form-item`
|
|
263
|
+
}, [vue.createVNode("label", {
|
|
264
|
+
"class": `${config.prefix}-label`,
|
|
265
|
+
"for": `link-url-${editorId}`
|
|
266
|
+
}, [(_c = ult.value.linkModalTips) == null ? void 0 : _c.urlLabel]), vue.createVNode("input", {
|
|
267
|
+
"placeholder": (_d = ult.value.linkModalTips) == null ? void 0 : _d.urlLabelPlaceHolder,
|
|
268
|
+
"class": `${config.prefix}-input`,
|
|
269
|
+
"id": `link-url-${editorId}`,
|
|
270
|
+
"type": "text",
|
|
271
|
+
"value": linkData.url,
|
|
272
|
+
"onChange": (e) => {
|
|
273
|
+
linkData.url = e.target.value;
|
|
274
|
+
},
|
|
275
|
+
"autocomplete": "off"
|
|
276
|
+
}, null)]), vue.createVNode("div", {
|
|
277
|
+
"class": `${config.prefix}-form-item`
|
|
278
|
+
}, [vue.createVNode("button", {
|
|
279
|
+
"class": [`${config.prefix}-btn`, `${config.prefix}-btn-row`],
|
|
280
|
+
"type": "button",
|
|
281
|
+
"onClick": () => {
|
|
282
|
+
props2.onOk(linkData);
|
|
283
|
+
linkData.desc = "";
|
|
284
|
+
linkData.url = "";
|
|
285
|
+
}
|
|
286
|
+
}, [(_e = ult.value.linkModalTips) == null ? void 0 : _e.buttonOK])])];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
const props$4 = {
|
|
292
|
+
visible: {
|
|
293
|
+
type: Boolean,
|
|
294
|
+
default: false
|
|
295
|
+
},
|
|
296
|
+
onCancel: {
|
|
297
|
+
type: Function,
|
|
298
|
+
default: () => {
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
onOk: {
|
|
302
|
+
type: Function,
|
|
303
|
+
default: () => {
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const ClipModal = /* @__PURE__ */ vue.defineComponent({
|
|
308
|
+
props: props$4,
|
|
309
|
+
setup(props2) {
|
|
310
|
+
var _a, _b, _c;
|
|
311
|
+
const ult = vue.inject("usedLanguageText");
|
|
312
|
+
const editorId = vue.inject("editorId");
|
|
313
|
+
let Cropper = (_c = (_b = (_a = config.configOption) == null ? void 0 : _a.editorExtensions) == null ? void 0 : _b.cropper) == null ? void 0 : _c.instance;
|
|
314
|
+
const uploadRef = vue.ref();
|
|
315
|
+
const uploadImgRef = vue.ref();
|
|
316
|
+
const previewTargetRef = vue.ref();
|
|
317
|
+
const data = vue.reactive({
|
|
318
|
+
cropperInited: false,
|
|
319
|
+
imgSelected: false,
|
|
320
|
+
imgSrc: "",
|
|
321
|
+
// 是否全屏
|
|
322
|
+
isFullscreen: false
|
|
323
|
+
});
|
|
324
|
+
let cropper = null;
|
|
325
|
+
vue.watch(() => props2.visible, () => {
|
|
326
|
+
if (props2.visible && !data.cropperInited) {
|
|
327
|
+
Cropper = Cropper || window.Cropper;
|
|
328
|
+
uploadRef.value.onchange = () => {
|
|
329
|
+
if (!Cropper) {
|
|
330
|
+
index.bus.emit(editorId, index.ERROR_CATCHER, {
|
|
331
|
+
name: "Cropper",
|
|
332
|
+
message: "Cropper is undefined"
|
|
333
|
+
});
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const fileList = uploadRef.value.files || [];
|
|
337
|
+
data.imgSelected = true;
|
|
338
|
+
if ((fileList == null ? void 0 : fileList.length) > 0) {
|
|
339
|
+
const fileReader = new FileReader();
|
|
340
|
+
fileReader.onload = (e) => {
|
|
341
|
+
data.imgSrc = e.target.result;
|
|
342
|
+
vue.nextTick(() => {
|
|
343
|
+
cropper = new Cropper(uploadImgRef.value, {
|
|
344
|
+
viewMode: 2,
|
|
345
|
+
preview: `.${config.prefix}-clip-preview-target`
|
|
346
|
+
// aspectRatio: 16 / 9,
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
fileReader.readAsDataURL(fileList[0]);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
vue.watch(() => [data.imgSelected], () => {
|
|
356
|
+
previewTargetRef.value.style = "";
|
|
357
|
+
});
|
|
358
|
+
vue.watch(() => data.isFullscreen, () => {
|
|
359
|
+
vue.nextTick(() => {
|
|
360
|
+
cropper == null ? void 0 : cropper.destroy();
|
|
361
|
+
previewTargetRef.value.style = "";
|
|
362
|
+
if (uploadImgRef.value) {
|
|
363
|
+
cropper = new Cropper(uploadImgRef.value, {
|
|
364
|
+
viewMode: 2,
|
|
365
|
+
preview: `.${config.prefix}-clip-preview-target`
|
|
366
|
+
// aspectRatio: 16 / 9,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
const reset = () => {
|
|
372
|
+
cropper.clear();
|
|
373
|
+
cropper.destroy();
|
|
374
|
+
cropper = null;
|
|
375
|
+
uploadRef.value.value = "";
|
|
376
|
+
data.imgSelected = false;
|
|
377
|
+
};
|
|
378
|
+
return () => {
|
|
379
|
+
var _a2;
|
|
380
|
+
return vue.createVNode(MdModal.MdModal, {
|
|
381
|
+
"class": `${config.prefix}-modal-clip`,
|
|
382
|
+
"title": (_a2 = ult.value.clipModalTips) == null ? void 0 : _a2.title,
|
|
383
|
+
"visible": props2.visible,
|
|
384
|
+
"onClose": props2.onCancel,
|
|
385
|
+
"showAdjust": true,
|
|
386
|
+
"isFullscreen": data.isFullscreen,
|
|
387
|
+
"onAdjust": (val) => {
|
|
388
|
+
data.isFullscreen = val;
|
|
389
|
+
},
|
|
390
|
+
"width": "668px",
|
|
391
|
+
"height": "421px"
|
|
392
|
+
}, {
|
|
393
|
+
default: () => {
|
|
394
|
+
var _a3, _b2;
|
|
395
|
+
return [vue.createVNode("div", {
|
|
396
|
+
"class": `${config.prefix}-form-item ${config.prefix}-clip`
|
|
397
|
+
}, [vue.createVNode("div", {
|
|
398
|
+
"class": `${config.prefix}-clip-main`
|
|
399
|
+
}, [data.imgSelected ? vue.createVNode("div", {
|
|
400
|
+
"class": `${config.prefix}-clip-cropper`
|
|
401
|
+
}, [vue.createVNode("img", {
|
|
402
|
+
"src": data.imgSrc,
|
|
403
|
+
"ref": uploadImgRef,
|
|
404
|
+
"style": {
|
|
405
|
+
display: "none"
|
|
406
|
+
},
|
|
407
|
+
"alt": ""
|
|
408
|
+
}, null), vue.createVNode("div", {
|
|
409
|
+
"class": `${config.prefix}-clip-delete`,
|
|
410
|
+
"onClick": reset
|
|
411
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
412
|
+
"name": "delete"
|
|
413
|
+
}, null)])]) : vue.createVNode("div", {
|
|
414
|
+
"class": `${config.prefix}-clip-upload`,
|
|
415
|
+
"onClick": () => {
|
|
416
|
+
uploadRef.value.click();
|
|
417
|
+
}
|
|
418
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
419
|
+
"name": "upload"
|
|
420
|
+
}, null)])]), vue.createVNode("div", {
|
|
421
|
+
"class": `${config.prefix}-clip-preview`
|
|
422
|
+
}, [vue.createVNode("div", {
|
|
423
|
+
"class": `${config.prefix}-clip-preview-target`,
|
|
424
|
+
"ref": previewTargetRef
|
|
425
|
+
}, null)])]), vue.createVNode("div", {
|
|
426
|
+
"class": `${config.prefix}-form-item`
|
|
427
|
+
}, [vue.createVNode("button", {
|
|
428
|
+
"class": `${config.prefix}-btn`,
|
|
429
|
+
"type": "button",
|
|
430
|
+
"onClick": () => {
|
|
431
|
+
if (cropper) {
|
|
432
|
+
const cvs = cropper.getCroppedCanvas();
|
|
433
|
+
index.bus.emit(editorId, index.UPLOAD_IMAGE, [index.base642File(cvs.toDataURL("image/png"))], props2.onOk);
|
|
434
|
+
reset();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}, [((_a3 = ult.value.clipModalTips) == null ? void 0 : _a3.buttonUpload) || ((_b2 = ult.value.linkModalTips) == null ? void 0 : _b2.buttonOK)])]), vue.createVNode("input", {
|
|
438
|
+
"ref": uploadRef,
|
|
439
|
+
"accept": "image/*",
|
|
440
|
+
"type": "file",
|
|
441
|
+
"multiple": false,
|
|
442
|
+
"style": {
|
|
443
|
+
display: "none"
|
|
444
|
+
}
|
|
445
|
+
}, null)];
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
const props$3 = {
|
|
452
|
+
type: {
|
|
453
|
+
type: String,
|
|
454
|
+
default: "link"
|
|
455
|
+
},
|
|
456
|
+
linkVisible: {
|
|
457
|
+
type: Boolean,
|
|
458
|
+
default: false
|
|
459
|
+
},
|
|
460
|
+
clipVisible: {
|
|
461
|
+
type: Boolean,
|
|
462
|
+
default: false
|
|
463
|
+
},
|
|
464
|
+
onCancel: {
|
|
465
|
+
type: Function,
|
|
466
|
+
default: () => {
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
onOk: {
|
|
470
|
+
type: Function,
|
|
471
|
+
default: () => {
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
const Modals = /* @__PURE__ */ vue.defineComponent({
|
|
476
|
+
props: props$3,
|
|
477
|
+
setup(props2) {
|
|
478
|
+
return () => vue.createVNode(vue.Fragment, null, [vue.createVNode(LinkModal, {
|
|
479
|
+
"type": props2.type,
|
|
480
|
+
"visible": props2.linkVisible,
|
|
481
|
+
"onOk": props2.onOk,
|
|
482
|
+
"onCancel": props2.onCancel
|
|
483
|
+
}, null), vue.createVNode(ClipModal, {
|
|
484
|
+
"visible": props2.clipVisible,
|
|
485
|
+
"onOk": props2.onOk,
|
|
486
|
+
"onCancel": props2.onCancel
|
|
487
|
+
}, null)]);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
const ToolBar = /* @__PURE__ */ vue.defineComponent({
|
|
491
|
+
name: "MDEditorToolbar",
|
|
492
|
+
props: toolbarProps,
|
|
493
|
+
setup(props2) {
|
|
494
|
+
const editorId = vue.inject("editorId");
|
|
495
|
+
const ult = vue.inject("usedLanguageText");
|
|
496
|
+
const theme = vue.inject("theme");
|
|
497
|
+
const language2 = vue.inject("language");
|
|
498
|
+
const {
|
|
499
|
+
fullscreenHandler
|
|
500
|
+
} = useSreenfull(props2);
|
|
501
|
+
const wrapperId = `${editorId}-toolbar-wrapper`;
|
|
502
|
+
const wrapperRef = vue.ref();
|
|
503
|
+
const visible = vue.reactive({
|
|
504
|
+
title: false,
|
|
505
|
+
catalog: false,
|
|
506
|
+
// 图片上传下拉
|
|
507
|
+
image: false,
|
|
508
|
+
// 表格预选
|
|
509
|
+
table: false,
|
|
510
|
+
// mermaid
|
|
511
|
+
mermaid: false,
|
|
512
|
+
katex: false
|
|
513
|
+
});
|
|
514
|
+
const emitHandler = (direct, params) => {
|
|
515
|
+
index.bus.emit(editorId, index.REPLACE, direct, params);
|
|
516
|
+
};
|
|
517
|
+
const modalData = vue.reactive({
|
|
518
|
+
type: "link",
|
|
519
|
+
linkVisible: false,
|
|
520
|
+
clipVisible: false
|
|
521
|
+
});
|
|
522
|
+
const toolbarLeftRef = vue.ref();
|
|
523
|
+
vue.onMounted(() => {
|
|
524
|
+
index.bus.on(editorId, {
|
|
525
|
+
name: index.OPEN_MODALS,
|
|
526
|
+
callback(type) {
|
|
527
|
+
modalData.type = type;
|
|
528
|
+
modalData.linkVisible = true;
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
const splitedbar = vue.computed(() => {
|
|
533
|
+
const excluedBars = props2.toolbars.filter((barItem) => !props2.toolbarsExclude.includes(barItem));
|
|
534
|
+
const moduleSplitIndex = excluedBars.indexOf("=");
|
|
535
|
+
const barLeft = moduleSplitIndex === -1 ? excluedBars : excluedBars.slice(0, moduleSplitIndex + 1);
|
|
536
|
+
const barRight = moduleSplitIndex === -1 ? [] : excluedBars.slice(moduleSplitIndex, Number.MAX_SAFE_INTEGER);
|
|
537
|
+
return [barLeft, barRight];
|
|
538
|
+
});
|
|
539
|
+
const uploadRef = vue.ref();
|
|
540
|
+
const uploadHandler = () => {
|
|
541
|
+
index.bus.emit(editorId, index.UPLOAD_IMAGE, Array.from(uploadRef.value.files || []));
|
|
542
|
+
uploadRef.value.value = "";
|
|
543
|
+
};
|
|
544
|
+
vue.onMounted(() => {
|
|
545
|
+
uploadRef.value.addEventListener("change", uploadHandler);
|
|
546
|
+
});
|
|
547
|
+
const barRender = (barItem) => {
|
|
548
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma;
|
|
549
|
+
if (config.allToolbar.includes(barItem)) {
|
|
550
|
+
switch (barItem) {
|
|
551
|
+
case "-": {
|
|
552
|
+
return vue.createVNode(Divider, null, null);
|
|
553
|
+
}
|
|
554
|
+
case "bold": {
|
|
555
|
+
return vue.createVNode("div", {
|
|
556
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
557
|
+
"title": (_a = ult.value.toolbarTips) == null ? void 0 : _a.bold,
|
|
558
|
+
"onClick": () => {
|
|
559
|
+
emitHandler("bold");
|
|
560
|
+
}
|
|
561
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
562
|
+
"name": "bold"
|
|
563
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
564
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
565
|
+
}, [(_b = ult.value.toolbarTips) == null ? void 0 : _b.bold])]);
|
|
566
|
+
}
|
|
567
|
+
case "underline": {
|
|
568
|
+
return vue.createVNode("div", {
|
|
569
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
570
|
+
"title": (_c = ult.value.toolbarTips) == null ? void 0 : _c.underline,
|
|
571
|
+
"onClick": () => {
|
|
572
|
+
emitHandler("underline");
|
|
573
|
+
}
|
|
574
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
575
|
+
"name": "underline"
|
|
576
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
577
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
578
|
+
}, [(_d = ult.value.toolbarTips) == null ? void 0 : _d.underline])]);
|
|
579
|
+
}
|
|
580
|
+
case "italic": {
|
|
581
|
+
return vue.createVNode("div", {
|
|
582
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
583
|
+
"title": (_e = ult.value.toolbarTips) == null ? void 0 : _e.italic,
|
|
584
|
+
"onClick": () => {
|
|
585
|
+
emitHandler("italic");
|
|
586
|
+
}
|
|
587
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
588
|
+
"name": "italic"
|
|
589
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
590
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
591
|
+
}, [(_f = ult.value.toolbarTips) == null ? void 0 : _f.italic])]);
|
|
592
|
+
}
|
|
593
|
+
case "strikeThrough": {
|
|
594
|
+
return vue.createVNode("div", {
|
|
595
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
596
|
+
"title": (_g = ult.value.toolbarTips) == null ? void 0 : _g.strikeThrough,
|
|
597
|
+
"onClick": () => {
|
|
598
|
+
emitHandler("strikeThrough");
|
|
599
|
+
}
|
|
600
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
601
|
+
"name": "strike-through"
|
|
602
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
603
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
604
|
+
}, [(_h = ult.value.toolbarTips) == null ? void 0 : _h.strikeThrough])]);
|
|
605
|
+
}
|
|
606
|
+
case "title": {
|
|
607
|
+
return vue.createVNode(DropdownToolbar.Dropdown, {
|
|
608
|
+
"relative": `#${wrapperId}`,
|
|
609
|
+
"visible": visible.title,
|
|
610
|
+
"onChange": (v) => {
|
|
611
|
+
visible.title = v;
|
|
612
|
+
},
|
|
613
|
+
"overlay": vue.createVNode("ul", {
|
|
614
|
+
"class": `${config.prefix}-menu`,
|
|
615
|
+
"onClick": () => {
|
|
616
|
+
visible.title = false;
|
|
617
|
+
}
|
|
618
|
+
}, [vue.createVNode("li", {
|
|
619
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-title`,
|
|
620
|
+
"onClick": () => {
|
|
621
|
+
emitHandler("h1");
|
|
622
|
+
}
|
|
623
|
+
}, [(_i = ult.value.titleItem) == null ? void 0 : _i.h1]), vue.createVNode("li", {
|
|
624
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-title`,
|
|
625
|
+
"onClick": () => {
|
|
626
|
+
emitHandler("h2");
|
|
627
|
+
}
|
|
628
|
+
}, [(_j = ult.value.titleItem) == null ? void 0 : _j.h2]), vue.createVNode("li", {
|
|
629
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-title`,
|
|
630
|
+
"onClick": () => {
|
|
631
|
+
emitHandler("h3");
|
|
632
|
+
}
|
|
633
|
+
}, [(_k = ult.value.titleItem) == null ? void 0 : _k.h3]), vue.createVNode("li", {
|
|
634
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-title`,
|
|
635
|
+
"onClick": () => {
|
|
636
|
+
emitHandler("h4");
|
|
637
|
+
}
|
|
638
|
+
}, [(_l = ult.value.titleItem) == null ? void 0 : _l.h4]), vue.createVNode("li", {
|
|
639
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-title`,
|
|
640
|
+
"onClick": () => {
|
|
641
|
+
emitHandler("h5");
|
|
642
|
+
}
|
|
643
|
+
}, [(_m = ult.value.titleItem) == null ? void 0 : _m.h5]), vue.createVNode("li", {
|
|
644
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-title`,
|
|
645
|
+
"onClick": () => {
|
|
646
|
+
emitHandler("h6");
|
|
647
|
+
}
|
|
648
|
+
}, [(_n = ult.value.titleItem) == null ? void 0 : _n.h6])])
|
|
649
|
+
}, {
|
|
650
|
+
default: () => {
|
|
651
|
+
var _a2, _b2;
|
|
652
|
+
return [vue.createVNode("div", {
|
|
653
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
654
|
+
"title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.title
|
|
655
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
656
|
+
"name": "title"
|
|
657
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
658
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
659
|
+
}, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.title])])];
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
case "sub": {
|
|
664
|
+
return vue.createVNode("div", {
|
|
665
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
666
|
+
"title": (_o = ult.value.toolbarTips) == null ? void 0 : _o.sub,
|
|
667
|
+
"onClick": () => {
|
|
668
|
+
emitHandler("sub");
|
|
669
|
+
}
|
|
670
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
671
|
+
"name": "sub"
|
|
672
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
673
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
674
|
+
}, [(_p = ult.value.toolbarTips) == null ? void 0 : _p.sub])]);
|
|
675
|
+
}
|
|
676
|
+
case "sup": {
|
|
677
|
+
return vue.createVNode("div", {
|
|
678
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
679
|
+
"title": (_q = ult.value.toolbarTips) == null ? void 0 : _q.sup,
|
|
680
|
+
"onClick": () => {
|
|
681
|
+
emitHandler("sup");
|
|
682
|
+
}
|
|
683
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
684
|
+
"name": "sup"
|
|
685
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
686
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
687
|
+
}, [(_r = ult.value.toolbarTips) == null ? void 0 : _r.sup])]);
|
|
688
|
+
}
|
|
689
|
+
case "quote": {
|
|
690
|
+
return vue.createVNode("div", {
|
|
691
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
692
|
+
"title": (_s = ult.value.toolbarTips) == null ? void 0 : _s.quote,
|
|
693
|
+
"onClick": () => {
|
|
694
|
+
emitHandler("quote");
|
|
695
|
+
}
|
|
696
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
697
|
+
"name": "quote"
|
|
698
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
699
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
700
|
+
}, [(_t = ult.value.toolbarTips) == null ? void 0 : _t.quote])]);
|
|
701
|
+
}
|
|
702
|
+
case "unorderedList": {
|
|
703
|
+
return vue.createVNode("div", {
|
|
704
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
705
|
+
"title": (_u = ult.value.toolbarTips) == null ? void 0 : _u.unorderedList,
|
|
706
|
+
"onClick": () => {
|
|
707
|
+
emitHandler("unorderedList");
|
|
708
|
+
}
|
|
709
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
710
|
+
"name": "unordered-list"
|
|
711
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
712
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
713
|
+
}, [(_v = ult.value.toolbarTips) == null ? void 0 : _v.unorderedList])]);
|
|
714
|
+
}
|
|
715
|
+
case "orderedList": {
|
|
716
|
+
return vue.createVNode("div", {
|
|
717
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
718
|
+
"title": (_w = ult.value.toolbarTips) == null ? void 0 : _w.orderedList,
|
|
719
|
+
"onClick": () => {
|
|
720
|
+
emitHandler("orderedList");
|
|
721
|
+
}
|
|
722
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
723
|
+
"name": "ordered-list"
|
|
724
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
725
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
726
|
+
}, [(_x = ult.value.toolbarTips) == null ? void 0 : _x.orderedList])]);
|
|
727
|
+
}
|
|
728
|
+
case "task": {
|
|
729
|
+
return vue.createVNode("div", {
|
|
730
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
731
|
+
"title": (_y = ult.value.toolbarTips) == null ? void 0 : _y.task,
|
|
732
|
+
"onClick": () => {
|
|
733
|
+
emitHandler("task");
|
|
734
|
+
}
|
|
735
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
736
|
+
"name": "task"
|
|
737
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
738
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
739
|
+
}, [(_z = ult.value.toolbarTips) == null ? void 0 : _z.task])]);
|
|
740
|
+
}
|
|
741
|
+
case "codeRow": {
|
|
742
|
+
return vue.createVNode("div", {
|
|
743
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
744
|
+
"title": (_A = ult.value.toolbarTips) == null ? void 0 : _A.codeRow,
|
|
745
|
+
"onClick": () => {
|
|
746
|
+
emitHandler("codeRow");
|
|
747
|
+
}
|
|
748
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
749
|
+
"name": "code-row"
|
|
750
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
751
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
752
|
+
}, [(_B = ult.value.toolbarTips) == null ? void 0 : _B.codeRow])]);
|
|
753
|
+
}
|
|
754
|
+
case "code": {
|
|
755
|
+
return vue.createVNode("div", {
|
|
756
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
757
|
+
"title": (_C = ult.value.toolbarTips) == null ? void 0 : _C.code,
|
|
758
|
+
"onClick": () => {
|
|
759
|
+
emitHandler("code");
|
|
760
|
+
}
|
|
761
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
762
|
+
"name": "code"
|
|
763
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
764
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
765
|
+
}, [(_D = ult.value.toolbarTips) == null ? void 0 : _D.code])]);
|
|
766
|
+
}
|
|
767
|
+
case "link": {
|
|
768
|
+
return vue.createVNode("div", {
|
|
769
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
770
|
+
"title": (_E = ult.value.toolbarTips) == null ? void 0 : _E.link,
|
|
771
|
+
"onClick": () => {
|
|
772
|
+
modalData.type = "link";
|
|
773
|
+
modalData.linkVisible = true;
|
|
774
|
+
}
|
|
775
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
776
|
+
"name": "link"
|
|
777
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
778
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
779
|
+
}, [(_F = ult.value.toolbarTips) == null ? void 0 : _F.link])]);
|
|
780
|
+
}
|
|
781
|
+
case "image": {
|
|
782
|
+
return props2.noUploadImg ? vue.createVNode("div", {
|
|
783
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
784
|
+
"title": (_G = ult.value.toolbarTips) == null ? void 0 : _G.image,
|
|
785
|
+
"onClick": () => {
|
|
786
|
+
modalData.type = "image";
|
|
787
|
+
modalData.linkVisible = true;
|
|
788
|
+
}
|
|
789
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
790
|
+
"name": "image"
|
|
791
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
792
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
793
|
+
}, [(_H = ult.value.toolbarTips) == null ? void 0 : _H.image])]) : vue.createVNode(DropdownToolbar.Dropdown, {
|
|
794
|
+
"relative": `#${wrapperId}`,
|
|
795
|
+
"visible": visible.image,
|
|
796
|
+
"onChange": (v) => {
|
|
797
|
+
visible.image = v;
|
|
798
|
+
},
|
|
799
|
+
"overlay": vue.createVNode("ul", {
|
|
800
|
+
"class": `${config.prefix}-menu`,
|
|
801
|
+
"onClick": () => {
|
|
802
|
+
visible.title = false;
|
|
803
|
+
}
|
|
804
|
+
}, [vue.createVNode("li", {
|
|
805
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-image`,
|
|
806
|
+
"onClick": () => {
|
|
807
|
+
modalData.type = "image";
|
|
808
|
+
modalData.linkVisible = true;
|
|
809
|
+
}
|
|
810
|
+
}, [(_I = ult.value.imgTitleItem) == null ? void 0 : _I.link]), vue.createVNode("li", {
|
|
811
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-image`,
|
|
812
|
+
"onClick": () => {
|
|
813
|
+
uploadRef.value.click();
|
|
814
|
+
}
|
|
815
|
+
}, [(_J = ult.value.imgTitleItem) == null ? void 0 : _J.upload]), vue.createVNode("li", {
|
|
816
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-image`,
|
|
817
|
+
"onClick": () => {
|
|
818
|
+
modalData.clipVisible = true;
|
|
819
|
+
}
|
|
820
|
+
}, [(_K = ult.value.imgTitleItem) == null ? void 0 : _K.clip2upload])])
|
|
821
|
+
}, {
|
|
822
|
+
default: () => {
|
|
823
|
+
var _a2, _b2;
|
|
824
|
+
return [vue.createVNode("div", {
|
|
825
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
826
|
+
"title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.image
|
|
827
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
828
|
+
"name": "image"
|
|
829
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
830
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
831
|
+
}, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.image])])];
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
case "table": {
|
|
836
|
+
return vue.createVNode(DropdownToolbar.Dropdown, {
|
|
837
|
+
"relative": `#${wrapperId}`,
|
|
838
|
+
"visible": visible.table,
|
|
839
|
+
"onChange": (v) => {
|
|
840
|
+
visible.table = v;
|
|
841
|
+
},
|
|
842
|
+
"key": "bar-table",
|
|
843
|
+
"overlay": vue.createVNode(TableShape$1, {
|
|
844
|
+
"tableShape": props2.tableShape,
|
|
845
|
+
"onSelected": (selectedShape) => {
|
|
846
|
+
emitHandler("table", {
|
|
847
|
+
selectedShape
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
}, null)
|
|
851
|
+
}, {
|
|
852
|
+
default: () => {
|
|
853
|
+
var _a2, _b2;
|
|
854
|
+
return [vue.createVNode("div", {
|
|
855
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
856
|
+
"title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.table
|
|
857
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
858
|
+
"name": "table"
|
|
859
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
860
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
861
|
+
}, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.table])])];
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
case "revoke": {
|
|
866
|
+
return vue.createVNode("div", {
|
|
867
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
868
|
+
"title": (_L = ult.value.toolbarTips) == null ? void 0 : _L.revoke,
|
|
869
|
+
"onClick": () => {
|
|
870
|
+
index.bus.emit(editorId, index.CTRL_Z);
|
|
871
|
+
}
|
|
872
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
873
|
+
"name": "revoke"
|
|
874
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
875
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
876
|
+
}, [(_M = ult.value.toolbarTips) == null ? void 0 : _M.revoke])]);
|
|
877
|
+
}
|
|
878
|
+
case "next": {
|
|
879
|
+
return vue.createVNode("div", {
|
|
880
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
881
|
+
"title": (_N = ult.value.toolbarTips) == null ? void 0 : _N.next,
|
|
882
|
+
"onClick": () => {
|
|
883
|
+
index.bus.emit(editorId, index.CTRL_SHIFT_Z);
|
|
884
|
+
}
|
|
885
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
886
|
+
"name": "next"
|
|
887
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
888
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
889
|
+
}, [(_O = ult.value.toolbarTips) == null ? void 0 : _O.next])]);
|
|
890
|
+
}
|
|
891
|
+
case "save": {
|
|
892
|
+
return vue.createVNode("div", {
|
|
893
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
894
|
+
"title": (_P = ult.value.toolbarTips) == null ? void 0 : _P.save,
|
|
895
|
+
"onClick": () => {
|
|
896
|
+
index.bus.emit(editorId, index.ON_SAVE);
|
|
897
|
+
}
|
|
898
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
899
|
+
"name": "baocun"
|
|
900
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
901
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
902
|
+
}, [(_Q = ult.value.toolbarTips) == null ? void 0 : _Q.save])]);
|
|
903
|
+
}
|
|
904
|
+
case "prettier": {
|
|
905
|
+
return !props2.noPrettier ? vue.createVNode("div", {
|
|
906
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
907
|
+
"title": (_R = ult.value.toolbarTips) == null ? void 0 : _R.prettier,
|
|
908
|
+
"onClick": () => {
|
|
909
|
+
emitHandler("prettier");
|
|
910
|
+
}
|
|
911
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
912
|
+
"name": "prettier"
|
|
913
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
914
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
915
|
+
}, [(_S = ult.value.toolbarTips) == null ? void 0 : _S.prettier])]) : "";
|
|
916
|
+
}
|
|
917
|
+
case "pageFullscreen": {
|
|
918
|
+
return !props2.setting.fullscreen && vue.createVNode("div", {
|
|
919
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
920
|
+
"title": (_T = ult.value.toolbarTips) == null ? void 0 : _T.pageFullscreen,
|
|
921
|
+
"onClick": () => {
|
|
922
|
+
props2.updateSetting("pageFullscreen");
|
|
923
|
+
}
|
|
924
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
925
|
+
"name": props2.setting.pageFullscreen ? "suoxiao" : "fangda"
|
|
926
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
927
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
928
|
+
}, [(_U = ult.value.toolbarTips) == null ? void 0 : _U.pageFullscreen])]);
|
|
929
|
+
}
|
|
930
|
+
case "fullscreen": {
|
|
931
|
+
return vue.createVNode("div", {
|
|
932
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
933
|
+
"title": (_V = ult.value.toolbarTips) == null ? void 0 : _V.fullscreen,
|
|
934
|
+
"onClick": () => {
|
|
935
|
+
fullscreenHandler();
|
|
936
|
+
}
|
|
937
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
938
|
+
"name": props2.setting.fullscreen ? "fullscreen-exit" : "fullscreen"
|
|
939
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
940
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
941
|
+
}, [(_W = ult.value.toolbarTips) == null ? void 0 : _W.fullscreen])]);
|
|
942
|
+
}
|
|
943
|
+
case "preview": {
|
|
944
|
+
return vue.createVNode("div", {
|
|
945
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
946
|
+
"title": (_X = ult.value.toolbarTips) == null ? void 0 : _X.preview,
|
|
947
|
+
"onClick": () => {
|
|
948
|
+
props2.updateSetting("preview");
|
|
949
|
+
}
|
|
950
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
951
|
+
"name": "preview"
|
|
952
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
953
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
954
|
+
}, [(_Y = ult.value.toolbarTips) == null ? void 0 : _Y.preview])]);
|
|
955
|
+
}
|
|
956
|
+
case "htmlPreview": {
|
|
957
|
+
return vue.createVNode("div", {
|
|
958
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
959
|
+
"title": (_Z = ult.value.toolbarTips) == null ? void 0 : _Z.htmlPreview,
|
|
960
|
+
"onClick": () => {
|
|
961
|
+
props2.updateSetting("htmlPreview");
|
|
962
|
+
}
|
|
963
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
964
|
+
"name": "coding"
|
|
965
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
966
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
967
|
+
}, [(__ = ult.value.toolbarTips) == null ? void 0 : __.htmlPreview])]);
|
|
968
|
+
}
|
|
969
|
+
case "catalog": {
|
|
970
|
+
return vue.createVNode("div", {
|
|
971
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
972
|
+
"title": (_$ = ult.value.toolbarTips) == null ? void 0 : _$.catalog,
|
|
973
|
+
"onClick": () => {
|
|
974
|
+
index.bus.emit(editorId, index.CHANGE_CATALOG_VISIBLE);
|
|
975
|
+
},
|
|
976
|
+
"key": "bar-catalog"
|
|
977
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
978
|
+
"name": "catalog"
|
|
979
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
980
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
981
|
+
}, [(_aa = ult.value.toolbarTips) == null ? void 0 : _aa.catalog])]);
|
|
982
|
+
}
|
|
983
|
+
case "github": {
|
|
984
|
+
return vue.createVNode("div", {
|
|
985
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
986
|
+
"title": (_ba = ult.value.toolbarTips) == null ? void 0 : _ba.github,
|
|
987
|
+
"onClick": () => util.linkTo("https://github.com/imzbf/md-editor-v3")
|
|
988
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
989
|
+
"name": "github"
|
|
990
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
991
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
992
|
+
}, [(_ca = ult.value.toolbarTips) == null ? void 0 : _ca.github])]);
|
|
993
|
+
}
|
|
994
|
+
case "mermaid": {
|
|
995
|
+
return vue.createVNode(DropdownToolbar.Dropdown, {
|
|
996
|
+
"relative": `#${wrapperId}`,
|
|
997
|
+
"visible": visible.mermaid,
|
|
998
|
+
"onChange": (v) => {
|
|
999
|
+
visible.mermaid = v;
|
|
1000
|
+
},
|
|
1001
|
+
"overlay": vue.createVNode("ul", {
|
|
1002
|
+
"class": `${config.prefix}-menu`,
|
|
1003
|
+
"onClick": () => {
|
|
1004
|
+
visible.mermaid = false;
|
|
1005
|
+
}
|
|
1006
|
+
}, [vue.createVNode("li", {
|
|
1007
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1008
|
+
"onClick": () => {
|
|
1009
|
+
emitHandler("flow");
|
|
1010
|
+
}
|
|
1011
|
+
}, [(_da = ult.value.mermaid) == null ? void 0 : _da.flow]), vue.createVNode("li", {
|
|
1012
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1013
|
+
"onClick": () => {
|
|
1014
|
+
emitHandler("sequence");
|
|
1015
|
+
}
|
|
1016
|
+
}, [(_ea = ult.value.mermaid) == null ? void 0 : _ea.sequence]), vue.createVNode("li", {
|
|
1017
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1018
|
+
"onClick": () => {
|
|
1019
|
+
emitHandler("gantt");
|
|
1020
|
+
}
|
|
1021
|
+
}, [(_fa = ult.value.mermaid) == null ? void 0 : _fa.gantt]), vue.createVNode("li", {
|
|
1022
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1023
|
+
"onClick": () => {
|
|
1024
|
+
emitHandler("class");
|
|
1025
|
+
}
|
|
1026
|
+
}, [(_ga = ult.value.mermaid) == null ? void 0 : _ga.class]), vue.createVNode("li", {
|
|
1027
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1028
|
+
"onClick": () => {
|
|
1029
|
+
emitHandler("state");
|
|
1030
|
+
}
|
|
1031
|
+
}, [(_ha = ult.value.mermaid) == null ? void 0 : _ha.state]), vue.createVNode("li", {
|
|
1032
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1033
|
+
"onClick": () => {
|
|
1034
|
+
emitHandler("pie");
|
|
1035
|
+
}
|
|
1036
|
+
}, [(_ia = ult.value.mermaid) == null ? void 0 : _ia.pie]), vue.createVNode("li", {
|
|
1037
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1038
|
+
"onClick": () => {
|
|
1039
|
+
emitHandler("relationship");
|
|
1040
|
+
}
|
|
1041
|
+
}, [(_ja = ult.value.mermaid) == null ? void 0 : _ja.relationship]), vue.createVNode("li", {
|
|
1042
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-mermaid`,
|
|
1043
|
+
"onClick": () => {
|
|
1044
|
+
emitHandler("journey");
|
|
1045
|
+
}
|
|
1046
|
+
}, [(_ka = ult.value.mermaid) == null ? void 0 : _ka.journey])]),
|
|
1047
|
+
"key": "bar-mermaid"
|
|
1048
|
+
}, {
|
|
1049
|
+
default: () => {
|
|
1050
|
+
var _a2, _b2;
|
|
1051
|
+
return [vue.createVNode("div", {
|
|
1052
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
1053
|
+
"title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.mermaid
|
|
1054
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
1055
|
+
"name": "mermaid"
|
|
1056
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
1057
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
1058
|
+
}, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.mermaid])])];
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
case "katex": {
|
|
1063
|
+
return vue.createVNode(DropdownToolbar.Dropdown, {
|
|
1064
|
+
"relative": `#${wrapperId}`,
|
|
1065
|
+
"visible": visible.katex,
|
|
1066
|
+
"onChange": (v) => {
|
|
1067
|
+
visible.katex = v;
|
|
1068
|
+
},
|
|
1069
|
+
"overlay": vue.createVNode("ul", {
|
|
1070
|
+
"class": `${config.prefix}-menu`,
|
|
1071
|
+
"onClick": () => {
|
|
1072
|
+
visible.katex = false;
|
|
1073
|
+
}
|
|
1074
|
+
}, [vue.createVNode("li", {
|
|
1075
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-katex`,
|
|
1076
|
+
"onClick": () => {
|
|
1077
|
+
emitHandler("katexInline");
|
|
1078
|
+
}
|
|
1079
|
+
}, [(_la = ult.value.katex) == null ? void 0 : _la.inline]), vue.createVNode("li", {
|
|
1080
|
+
"class": `${config.prefix}-menu-item ${config.prefix}-menu-item-katex`,
|
|
1081
|
+
"onClick": () => {
|
|
1082
|
+
emitHandler("katexBlock");
|
|
1083
|
+
}
|
|
1084
|
+
}, [(_ma = ult.value.katex) == null ? void 0 : _ma.block])]),
|
|
1085
|
+
"key": "bar-katex"
|
|
1086
|
+
}, {
|
|
1087
|
+
default: () => {
|
|
1088
|
+
var _a2, _b2;
|
|
1089
|
+
return [vue.createVNode("div", {
|
|
1090
|
+
"class": `${config.prefix}-toolbar-item`,
|
|
1091
|
+
"title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.katex
|
|
1092
|
+
}, [vue.createVNode(MdModal.Icon, {
|
|
1093
|
+
"name": "formula"
|
|
1094
|
+
}, null), props2.showToolbarName && vue.createVNode("div", {
|
|
1095
|
+
"class": `${config.prefix}-toolbar-item-name`
|
|
1096
|
+
}, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.katex])])];
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
} else if (props2.defToolbars instanceof Array) {
|
|
1102
|
+
const defItem = props2.defToolbars[barItem];
|
|
1103
|
+
if (defItem) {
|
|
1104
|
+
const defItemCloned = vue.cloneVNode(defItem, {
|
|
1105
|
+
theme: theme.value,
|
|
1106
|
+
language: language2.value,
|
|
1107
|
+
insert(generate) {
|
|
1108
|
+
index.bus.emit(editorId, index.REPLACE, "universal", {
|
|
1109
|
+
generate
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
return defItemCloned;
|
|
1114
|
+
}
|
|
1115
|
+
return "";
|
|
1116
|
+
} else if (props2.defToolbars && props2.defToolbars.children instanceof Array) {
|
|
1117
|
+
const defItem = props2.defToolbars.children[barItem];
|
|
1118
|
+
if (defItem) {
|
|
1119
|
+
const defItemCloned = vue.cloneVNode(defItem, {
|
|
1120
|
+
theme: theme.value,
|
|
1121
|
+
language: language2.value,
|
|
1122
|
+
insert(generate) {
|
|
1123
|
+
index.bus.emit(editorId, index.REPLACE, "universal", {
|
|
1124
|
+
generate
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
return defItemCloned;
|
|
1129
|
+
}
|
|
1130
|
+
return "";
|
|
1131
|
+
} else {
|
|
1132
|
+
return "";
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
vue.watch(() => props2.toolbars, () => {
|
|
1136
|
+
vue.nextTick(() => {
|
|
1137
|
+
if (wrapperRef.value) {
|
|
1138
|
+
util.draggingScroll(wrapperRef.value);
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
}, {
|
|
1142
|
+
immediate: true
|
|
1143
|
+
});
|
|
1144
|
+
return () => {
|
|
1145
|
+
const LeftBar = splitedbar.value[0].map((barItem) => barRender(barItem));
|
|
1146
|
+
const RightBar = splitedbar.value[1].map((barItem) => barRender(barItem));
|
|
1147
|
+
return vue.createVNode(vue.Fragment, null, [props2.toolbars.length > 0 && vue.createVNode("div", {
|
|
1148
|
+
"class": `${config.prefix}-toolbar-wrapper`,
|
|
1149
|
+
"ref": wrapperRef,
|
|
1150
|
+
"id": wrapperId
|
|
1151
|
+
}, [vue.createVNode("div", {
|
|
1152
|
+
"class": [`${config.prefix}-toolbar`, props2.showToolbarName && `${config.prefix}-stn`]
|
|
1153
|
+
}, [vue.createVNode("div", {
|
|
1154
|
+
"class": `${config.prefix}-toolbar-left`,
|
|
1155
|
+
"ref": toolbarLeftRef
|
|
1156
|
+
}, [LeftBar]), vue.createVNode("div", {
|
|
1157
|
+
"class": `${config.prefix}-toolbar-right`
|
|
1158
|
+
}, [RightBar])])]), vue.createVNode("input", {
|
|
1159
|
+
"ref": uploadRef,
|
|
1160
|
+
"accept": "image/*",
|
|
1161
|
+
"type": "file",
|
|
1162
|
+
"multiple": true,
|
|
1163
|
+
"style": {
|
|
1164
|
+
display: "none"
|
|
1165
|
+
}
|
|
1166
|
+
}, null), vue.createVNode(Modals, {
|
|
1167
|
+
"linkVisible": modalData.linkVisible,
|
|
1168
|
+
"clipVisible": modalData.clipVisible,
|
|
1169
|
+
"type": modalData.type,
|
|
1170
|
+
"onCancel": () => {
|
|
1171
|
+
modalData.linkVisible = false;
|
|
1172
|
+
modalData.clipVisible = false;
|
|
1173
|
+
},
|
|
1174
|
+
"onOk": (data) => {
|
|
1175
|
+
if (data) {
|
|
1176
|
+
emitHandler(modalData.type, {
|
|
1177
|
+
desc: data.desc,
|
|
1178
|
+
url: data.url
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
modalData.linkVisible = false;
|
|
1182
|
+
modalData.clipVisible = false;
|
|
1183
|
+
}
|
|
1184
|
+
}, null)]);
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
const DATA_LINE_SELECTOR = `.${config.prefix}-preview > [data-line]`;
|
|
1189
|
+
const scrollAutoWithScale = (pEle, cEle) => {
|
|
1190
|
+
const addEvent = util.debounce(() => {
|
|
1191
|
+
pEle.removeEventListener("scroll", scrollHandler);
|
|
1192
|
+
pEle.addEventListener("scroll", scrollHandler);
|
|
1193
|
+
cEle.removeEventListener("scroll", scrollHandler);
|
|
1194
|
+
cEle.addEventListener("scroll", scrollHandler);
|
|
1195
|
+
}, 50);
|
|
1196
|
+
const scrollHandler = (e) => {
|
|
1197
|
+
const pHeight = pEle.clientHeight;
|
|
1198
|
+
const cHeight = cEle.clientHeight;
|
|
1199
|
+
const pScrollHeight = pEle.scrollHeight;
|
|
1200
|
+
const cScrollHeight = cEle.scrollHeight;
|
|
1201
|
+
const scale = (pScrollHeight - pHeight) / (cScrollHeight - cHeight);
|
|
1202
|
+
if (e.target === pEle) {
|
|
1203
|
+
cEle.removeEventListener("scroll", scrollHandler);
|
|
1204
|
+
cEle.scrollTo({
|
|
1205
|
+
top: pEle.scrollTop / scale
|
|
1206
|
+
// behavior: 'smooth'
|
|
1207
|
+
});
|
|
1208
|
+
addEvent();
|
|
1209
|
+
} else {
|
|
1210
|
+
pEle.removeEventListener("scroll", scrollHandler);
|
|
1211
|
+
pEle.scrollTo({
|
|
1212
|
+
top: cEle.scrollTop * scale
|
|
1213
|
+
// behavior: 'smooth'
|
|
1214
|
+
});
|
|
1215
|
+
addEvent();
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
return [
|
|
1219
|
+
() => {
|
|
1220
|
+
addEvent().finally(() => {
|
|
1221
|
+
pEle.dispatchEvent(new Event("scroll"));
|
|
1222
|
+
});
|
|
1223
|
+
},
|
|
1224
|
+
() => {
|
|
1225
|
+
pEle.removeEventListener("scroll", scrollHandler);
|
|
1226
|
+
cEle.removeEventListener("scroll", scrollHandler);
|
|
1227
|
+
}
|
|
1228
|
+
];
|
|
1229
|
+
};
|
|
1230
|
+
const scrollAuto = (pEle, cEle, codeMirrorUt) => {
|
|
1231
|
+
const { view: view2 } = codeMirrorUt;
|
|
1232
|
+
const smoothScroll = util.createSmoothScroll();
|
|
1233
|
+
const getTopByLine = (line) => {
|
|
1234
|
+
return view2.lineBlockAt(view2.state.doc.line(line).from).top;
|
|
1235
|
+
};
|
|
1236
|
+
const getHeightByLine = (line) => {
|
|
1237
|
+
return view2.lineBlockAt(view2.state.doc.line(line).from).height;
|
|
1238
|
+
};
|
|
1239
|
+
let blockMap = [];
|
|
1240
|
+
let elesHasLineNumber = [];
|
|
1241
|
+
let startLines = [];
|
|
1242
|
+
const buildMap = () => {
|
|
1243
|
+
blockMap = [];
|
|
1244
|
+
elesHasLineNumber = [];
|
|
1245
|
+
startLines = [];
|
|
1246
|
+
elesHasLineNumber = elesHasLineNumber.concat(
|
|
1247
|
+
Array.from(cEle.querySelectorAll(DATA_LINE_SELECTOR))
|
|
1248
|
+
);
|
|
1249
|
+
const startLinesCalc = elesHasLineNumber.map((item) => Number(item.dataset.line) + 1);
|
|
1250
|
+
startLines = startLines.concat(startLinesCalc);
|
|
1251
|
+
const { lines } = view2.state.doc;
|
|
1252
|
+
let start = 1;
|
|
1253
|
+
let end = startLinesCalc.shift() ?? lines;
|
|
1254
|
+
for (let i = 1; i <= lines; i++) {
|
|
1255
|
+
if (i === end) {
|
|
1256
|
+
start = i;
|
|
1257
|
+
end = startLinesCalc.shift() || lines + 1;
|
|
1258
|
+
}
|
|
1259
|
+
blockMap.push({
|
|
1260
|
+
start,
|
|
1261
|
+
end: end - 1
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
let pLock = 0;
|
|
1266
|
+
let cLock = 0;
|
|
1267
|
+
const pEleHandler = () => {
|
|
1268
|
+
var _a, _b;
|
|
1269
|
+
if (cLock !== 0) {
|
|
1270
|
+
return false;
|
|
1271
|
+
}
|
|
1272
|
+
pLock++;
|
|
1273
|
+
const { scrollDOM, contentHeight } = view2;
|
|
1274
|
+
let cElePaddingTop = +getComputedStyle(cEle).paddingTop.replace("px", "");
|
|
1275
|
+
const blockInfo = view2.lineBlockAtHeight(scrollDOM.scrollTop);
|
|
1276
|
+
const { number: currLine } = view2.state.doc.lineAt(blockInfo.from);
|
|
1277
|
+
const blockData = blockMap[currLine - 1];
|
|
1278
|
+
if (!blockData) {
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
let endLinePosition = getTopByLine(blockData.end) + getHeightByLine(blockData.end);
|
|
1282
|
+
let scale = 0;
|
|
1283
|
+
const startTop = getTopByLine(blockData.start);
|
|
1284
|
+
const startEle = cEle.querySelector(`[data-line="${blockData.start - 1}"]`) || ((_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild);
|
|
1285
|
+
const endEle = cEle.querySelector(`[data-line="${blockData.end}"]`) || ((_b = cEle.lastElementChild) == null ? void 0 : _b.lastElementChild);
|
|
1286
|
+
let blockHeight = 0;
|
|
1287
|
+
let startEleOffetTop = 0;
|
|
1288
|
+
if (startTop === 0) {
|
|
1289
|
+
scale = scrollDOM.scrollTop / endLinePosition;
|
|
1290
|
+
if (startEle === endEle) {
|
|
1291
|
+
cElePaddingTop = 0;
|
|
1292
|
+
endLinePosition = contentHeight - scrollDOM.offsetHeight;
|
|
1293
|
+
blockHeight = endEle.offsetTop + endEle.offsetHeight - cEle.clientHeight;
|
|
1294
|
+
} else {
|
|
1295
|
+
blockHeight = endEle.offsetTop;
|
|
1296
|
+
}
|
|
1297
|
+
} else {
|
|
1298
|
+
scale = (scrollDOM.scrollTop - startTop) / (endLinePosition - startTop);
|
|
1299
|
+
startEleOffetTop = startEle.offsetTop;
|
|
1300
|
+
blockHeight = endEle.offsetTop - startEleOffetTop;
|
|
1301
|
+
}
|
|
1302
|
+
if (endLinePosition > scrollDOM.scrollHeight - scrollDOM.clientHeight) {
|
|
1303
|
+
scale = (scrollDOM.scrollTop - startTop) / (scrollDOM.scrollHeight - scrollDOM.clientHeight - startTop);
|
|
1304
|
+
startEleOffetTop = startEle.offsetTop;
|
|
1305
|
+
blockHeight = cEle.scrollHeight - cEle.clientHeight - startEleOffetTop + 10;
|
|
1306
|
+
}
|
|
1307
|
+
const scrollToTop = startEleOffetTop - cElePaddingTop + blockHeight * scale;
|
|
1308
|
+
smoothScroll(cEle, scrollToTop, () => {
|
|
1309
|
+
pLock--;
|
|
1310
|
+
});
|
|
1311
|
+
};
|
|
1312
|
+
const cEleHandler = () => {
|
|
1313
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1314
|
+
if (pLock !== 0) {
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
cLock++;
|
|
1318
|
+
const { scrollDOM } = view2;
|
|
1319
|
+
const cScrollTop = cEle.scrollTop;
|
|
1320
|
+
const cScrollHeight = cEle.scrollHeight;
|
|
1321
|
+
let realEleStart = (_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild;
|
|
1322
|
+
let realEleEnd = (_b = cEle.firstElementChild) == null ? void 0 : _b.lastElementChild;
|
|
1323
|
+
if (startLines.length > 0) {
|
|
1324
|
+
let virtualLine = Math.ceil(
|
|
1325
|
+
Number(startLines[startLines.length - 1]) * (cScrollTop / cScrollHeight)
|
|
1326
|
+
);
|
|
1327
|
+
let startLineIndex = startLines.findLastIndex((value) => value <= virtualLine);
|
|
1328
|
+
startLineIndex = startLineIndex === -1 ? 0 : startLineIndex;
|
|
1329
|
+
virtualLine = startLines[startLineIndex];
|
|
1330
|
+
for (let i = startLineIndex; i >= 0 && i < startLines.length; ) {
|
|
1331
|
+
const currentElementTop = elesHasLineNumber[i].offsetTop;
|
|
1332
|
+
if (currentElementTop > cScrollTop) {
|
|
1333
|
+
if (i - 1 >= 0) {
|
|
1334
|
+
i--;
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
virtualLine = -1;
|
|
1338
|
+
startLineIndex = i;
|
|
1339
|
+
break;
|
|
1340
|
+
} else {
|
|
1341
|
+
if (i + 1 <= startLines.length && elesHasLineNumber[i + 1].offsetTop < cScrollTop) {
|
|
1342
|
+
i++;
|
|
1343
|
+
continue;
|
|
1344
|
+
}
|
|
1345
|
+
virtualLine = startLines[i];
|
|
1346
|
+
startLineIndex = i;
|
|
1347
|
+
break;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
switch (virtualLine) {
|
|
1351
|
+
case -1: {
|
|
1352
|
+
realEleStart = (_c = cEle.firstElementChild) == null ? void 0 : _c.firstElementChild;
|
|
1353
|
+
realEleEnd = elesHasLineNumber[startLineIndex];
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
case startLines.length - 1: {
|
|
1357
|
+
realEleStart = elesHasLineNumber[startLineIndex];
|
|
1358
|
+
realEleEnd = (_d = cEle.firstElementChild) == null ? void 0 : _d.lastElementChild;
|
|
1359
|
+
break;
|
|
1360
|
+
}
|
|
1361
|
+
default: {
|
|
1362
|
+
realEleStart = elesHasLineNumber[startLineIndex];
|
|
1363
|
+
realEleEnd = elesHasLineNumber[startLineIndex + 1];
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
const eleStartOffsetTop = realEleStart === ((_e = cEle.firstElementChild) == null ? void 0 : _e.firstElementChild) ? 0 : realEleStart.offsetTop;
|
|
1368
|
+
let eleEndOffsetTop = realEleEnd.offsetTop;
|
|
1369
|
+
let scale = 0;
|
|
1370
|
+
const { start, end } = blockMap[Number(realEleStart.dataset.line || 0)];
|
|
1371
|
+
const firstLineScrollTop = getTopByLine(start);
|
|
1372
|
+
let endLineScrollTop = getTopByLine(end + 1);
|
|
1373
|
+
let blockHeight = 0;
|
|
1374
|
+
if (endLineScrollTop > scrollDOM.scrollHeight - scrollDOM.clientHeight || realEleEnd.scrollTop > cEle.scrollHeight - cEle.clientHeight) {
|
|
1375
|
+
scale = Math.max(
|
|
1376
|
+
(cScrollTop - eleStartOffsetTop) / (cEle.scrollHeight - eleStartOffsetTop - cEle.clientHeight),
|
|
1377
|
+
0
|
|
1378
|
+
);
|
|
1379
|
+
endLineScrollTop = getTopByLine(view2.state.doc.lines) + getHeightByLine(view2.state.doc.lines);
|
|
1380
|
+
blockHeight = 8 + endLineScrollTop - firstLineScrollTop - pEle.clientHeight;
|
|
1381
|
+
} else if (realEleStart === ((_f = cEle.firstElementChild) == null ? void 0 : _f.firstElementChild)) {
|
|
1382
|
+
if (realEleStart === realEleEnd) {
|
|
1383
|
+
eleEndOffsetTop = realEleEnd.offsetTop + realEleEnd.offsetHeight + +getComputedStyle(realEleEnd).marginBottom.replace("px", "");
|
|
1384
|
+
blockHeight = endLineScrollTop;
|
|
1385
|
+
} else {
|
|
1386
|
+
blockHeight = endLineScrollTop;
|
|
1387
|
+
}
|
|
1388
|
+
scale = Math.max(cScrollTop / eleEndOffsetTop, 0);
|
|
1389
|
+
} else {
|
|
1390
|
+
scale = Math.max(
|
|
1391
|
+
(cScrollTop - eleStartOffsetTop) / (eleEndOffsetTop - eleStartOffsetTop),
|
|
1392
|
+
0
|
|
1393
|
+
);
|
|
1394
|
+
blockHeight = endLineScrollTop - firstLineScrollTop;
|
|
1395
|
+
}
|
|
1396
|
+
smoothScroll(pEle, firstLineScrollTop + blockHeight * scale, () => {
|
|
1397
|
+
cLock--;
|
|
1398
|
+
});
|
|
1399
|
+
};
|
|
1400
|
+
const scrollHandler = util.throttle((e) => {
|
|
1401
|
+
var _a;
|
|
1402
|
+
const { scrollDOM, contentHeight } = view2;
|
|
1403
|
+
const scrollDomHeight = scrollDOM.clientHeight;
|
|
1404
|
+
if (contentHeight <= scrollDomHeight || cEle.firstElementChild.clientHeight <= cEle.clientHeight) {
|
|
1405
|
+
return false;
|
|
1406
|
+
}
|
|
1407
|
+
if (view2.state.doc.lines < ((_a = blockMap[blockMap.length - 1]) == null ? void 0 : _a.end)) {
|
|
1408
|
+
return false;
|
|
1409
|
+
}
|
|
1410
|
+
if (e.target === pEle) {
|
|
1411
|
+
pEleHandler();
|
|
1412
|
+
} else {
|
|
1413
|
+
cEleHandler();
|
|
1414
|
+
}
|
|
1415
|
+
}, 8);
|
|
1416
|
+
return [
|
|
1417
|
+
() => {
|
|
1418
|
+
buildMap();
|
|
1419
|
+
pEle.addEventListener("scroll", scrollHandler);
|
|
1420
|
+
cEle.addEventListener("scroll", scrollHandler);
|
|
1421
|
+
pEle.dispatchEvent(new Event("scroll"));
|
|
1422
|
+
},
|
|
1423
|
+
() => {
|
|
1424
|
+
pEle.removeEventListener("scroll", scrollHandler);
|
|
1425
|
+
cEle.removeEventListener("scroll", scrollHandler);
|
|
1426
|
+
}
|
|
1427
|
+
];
|
|
1428
|
+
};
|
|
1429
|
+
const useAutoScroll = (props2, html, codeMirrorUt) => {
|
|
1430
|
+
const editorId = vue.inject("editorId");
|
|
1431
|
+
let clearScrollAuto = () => {
|
|
1432
|
+
};
|
|
1433
|
+
let initScrollAuto = () => {
|
|
1434
|
+
};
|
|
1435
|
+
const rebindEvent = () => {
|
|
1436
|
+
clearScrollAuto();
|
|
1437
|
+
const cmScroller = document.querySelector(
|
|
1438
|
+
`#${editorId} .cm-scroller`
|
|
1439
|
+
);
|
|
1440
|
+
const previewEle = document.querySelector(
|
|
1441
|
+
`[id="${editorId}-preview-wrapper"]`
|
|
1442
|
+
);
|
|
1443
|
+
const htmlEle = document.querySelector(
|
|
1444
|
+
`[id="${editorId}-html-wrapper"]`
|
|
1445
|
+
);
|
|
1446
|
+
if (previewEle || htmlEle) {
|
|
1447
|
+
const scrollHandler = previewEle ? scrollAuto : scrollAutoWithScale;
|
|
1448
|
+
const cEle = previewEle || htmlEle;
|
|
1449
|
+
[initScrollAuto, clearScrollAuto] = scrollHandler(
|
|
1450
|
+
cmScroller,
|
|
1451
|
+
cEle,
|
|
1452
|
+
codeMirrorUt.value
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
if (props2.scrollAuto) {
|
|
1456
|
+
initScrollAuto();
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
vue.watch(
|
|
1460
|
+
[
|
|
1461
|
+
html,
|
|
1462
|
+
vue.toRef(props2.setting, "preview"),
|
|
1463
|
+
vue.toRef(props2.setting, "htmlPreview"),
|
|
1464
|
+
vue.toRef(props2.setting, "fullscreen"),
|
|
1465
|
+
vue.toRef(props2.setting, "pageFullscreen")
|
|
1466
|
+
],
|
|
1467
|
+
() => {
|
|
1468
|
+
vue.nextTick(rebindEvent);
|
|
1469
|
+
}
|
|
1470
|
+
);
|
|
1471
|
+
vue.watch(
|
|
1472
|
+
() => props2.scrollAuto,
|
|
1473
|
+
(sa) => {
|
|
1474
|
+
if (sa) {
|
|
1475
|
+
initScrollAuto();
|
|
1476
|
+
} else {
|
|
1477
|
+
clearScrollAuto();
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
);
|
|
1481
|
+
vue.onMounted(rebindEvent);
|
|
1482
|
+
};
|
|
1483
|
+
const directive2flag = (direct, codeMirrorUt, params) => {
|
|
1484
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1485
|
+
let targetValue = "";
|
|
1486
|
+
let deviationStart = 0;
|
|
1487
|
+
let deviationEnd = 0;
|
|
1488
|
+
let select = true;
|
|
1489
|
+
let replaceAll = false;
|
|
1490
|
+
const selectedText = codeMirrorUt.getSelectedText();
|
|
1491
|
+
const mermaidTemplate = (_a = config.configOption.editorConfig) == null ? void 0 : _a.mermaidTemplate;
|
|
1492
|
+
if (/^h[1-6]{1}$/.test(direct)) {
|
|
1493
|
+
const pix = direct.replace(/^h(\d)/, (_, num) => {
|
|
1494
|
+
return new Array(Number(num)).fill("#", 0, num).join("");
|
|
1495
|
+
});
|
|
1496
|
+
targetValue = `${pix} ${selectedText}`;
|
|
1497
|
+
deviationStart = pix.length + 1;
|
|
1498
|
+
} else if (direct === "prettier") {
|
|
1499
|
+
const prettier = window.prettier || ((_c = (_b = config.configOption.editorExtensions) == null ? void 0 : _b.prettier) == null ? void 0 : _c.prettierInstance);
|
|
1500
|
+
const prettierPlugins = [
|
|
1501
|
+
((_d = window.prettierPlugins) == null ? void 0 : _d.markdown) || ((_f = (_e = config.configOption.editorExtensions) == null ? void 0 : _e.prettier) == null ? void 0 : _f.parserMarkdownInstance)
|
|
1502
|
+
];
|
|
1503
|
+
if (!prettier || prettierPlugins[0] === void 0) {
|
|
1504
|
+
index.bus.emit(params.editorId, index.ERROR_CATCHER, {
|
|
1505
|
+
name: "prettier",
|
|
1506
|
+
message: "prettier is undefined"
|
|
1507
|
+
});
|
|
1508
|
+
targetValue = codeMirrorUt.getValue();
|
|
1509
|
+
} else {
|
|
1510
|
+
targetValue = prettier.format(codeMirrorUt.getValue(), {
|
|
1511
|
+
parser: "markdown",
|
|
1512
|
+
plugins: prettierPlugins
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
select = false;
|
|
1516
|
+
replaceAll = true;
|
|
1517
|
+
} else {
|
|
1518
|
+
switch (direct) {
|
|
1519
|
+
case "bold": {
|
|
1520
|
+
targetValue = `**${selectedText}**`;
|
|
1521
|
+
deviationStart = 2;
|
|
1522
|
+
deviationEnd = -2;
|
|
1523
|
+
break;
|
|
1524
|
+
}
|
|
1525
|
+
case "underline": {
|
|
1526
|
+
targetValue = `<u>${selectedText}</u>`;
|
|
1527
|
+
deviationStart = 3;
|
|
1528
|
+
deviationEnd = -4;
|
|
1529
|
+
break;
|
|
1530
|
+
}
|
|
1531
|
+
case "italic": {
|
|
1532
|
+
targetValue = `*${selectedText}*`;
|
|
1533
|
+
deviationStart = 1;
|
|
1534
|
+
deviationEnd = -1;
|
|
1535
|
+
break;
|
|
1536
|
+
}
|
|
1537
|
+
case "strikeThrough": {
|
|
1538
|
+
targetValue = `~~${selectedText}~~`;
|
|
1539
|
+
deviationStart = 2;
|
|
1540
|
+
deviationEnd = -2;
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
case "sub": {
|
|
1544
|
+
targetValue = `<sub>${selectedText}</sub>`;
|
|
1545
|
+
deviationStart = 5;
|
|
1546
|
+
deviationEnd = -6;
|
|
1547
|
+
break;
|
|
1548
|
+
}
|
|
1549
|
+
case "sup": {
|
|
1550
|
+
targetValue = `<sup>${selectedText}</sup>`;
|
|
1551
|
+
deviationStart = 5;
|
|
1552
|
+
deviationEnd = -6;
|
|
1553
|
+
break;
|
|
1554
|
+
}
|
|
1555
|
+
case "codeRow": {
|
|
1556
|
+
targetValue = "`" + selectedText + "`";
|
|
1557
|
+
deviationStart = 1;
|
|
1558
|
+
deviationEnd = -1;
|
|
1559
|
+
break;
|
|
1560
|
+
}
|
|
1561
|
+
case "quote": {
|
|
1562
|
+
targetValue = `> ${selectedText}`;
|
|
1563
|
+
deviationStart = 2;
|
|
1564
|
+
break;
|
|
1565
|
+
}
|
|
1566
|
+
case "orderedList": {
|
|
1567
|
+
targetValue = `1. ${selectedText}`;
|
|
1568
|
+
deviationStart = 3;
|
|
1569
|
+
break;
|
|
1570
|
+
}
|
|
1571
|
+
case "unorderedList": {
|
|
1572
|
+
targetValue = `- ${selectedText}`;
|
|
1573
|
+
deviationStart = 2;
|
|
1574
|
+
break;
|
|
1575
|
+
}
|
|
1576
|
+
case "task": {
|
|
1577
|
+
targetValue = `- [ ] ${selectedText}`;
|
|
1578
|
+
deviationStart = 6;
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
case "code": {
|
|
1582
|
+
const text = params.text || selectedText || "";
|
|
1583
|
+
const mode = params.mode || "language";
|
|
1584
|
+
targetValue = `\`\`\`${mode}
|
|
1585
|
+
${text}
|
|
3
1586
|
\`\`\`
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1587
|
+
`;
|
|
1588
|
+
deviationStart = 3;
|
|
1589
|
+
deviationEnd = 3 + mode.length - targetValue.length;
|
|
1590
|
+
break;
|
|
1591
|
+
}
|
|
1592
|
+
case "table": {
|
|
1593
|
+
targetValue = "|";
|
|
1594
|
+
const { selectedShape = { x: 1, y: 1 } } = params;
|
|
1595
|
+
const { x, y } = selectedShape;
|
|
1596
|
+
for (let i = 0; i <= y; i++) {
|
|
1597
|
+
targetValue += " col |";
|
|
1598
|
+
}
|
|
1599
|
+
targetValue += "\n|";
|
|
1600
|
+
for (let i = 0; i <= y; i++) {
|
|
1601
|
+
targetValue += " - |";
|
|
1602
|
+
}
|
|
1603
|
+
for (let row = 0; row <= x; row++) {
|
|
1604
|
+
targetValue += "\n|";
|
|
1605
|
+
for (let col = 0; col <= y; col++) {
|
|
1606
|
+
targetValue += " content |";
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
deviationStart = 2;
|
|
1610
|
+
deviationEnd = 5 - targetValue.length;
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
case "link": {
|
|
1614
|
+
const { desc, url } = params;
|
|
1615
|
+
targetValue = `[${desc}](${url})`;
|
|
1616
|
+
select = false;
|
|
1617
|
+
break;
|
|
1618
|
+
}
|
|
1619
|
+
case "image": {
|
|
1620
|
+
const { desc, url, urls } = params;
|
|
1621
|
+
if (urls instanceof Array) {
|
|
1622
|
+
targetValue = urls.reduce((pVal, _url) => {
|
|
1623
|
+
const {
|
|
1624
|
+
url: url2 = "",
|
|
1625
|
+
alt = "",
|
|
1626
|
+
title = ""
|
|
1627
|
+
} = typeof _url === "object" ? _url : { url: _url };
|
|
1628
|
+
return pVal + `
|
|
1629
|
+
`;
|
|
1630
|
+
}, "");
|
|
1631
|
+
} else {
|
|
1632
|
+
targetValue = `
|
|
1633
|
+
`;
|
|
1634
|
+
}
|
|
1635
|
+
select = false;
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
case "flow": {
|
|
1639
|
+
targetValue = `\`\`\`mermaid
|
|
1640
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.flow) || "flowchart TD \n Start --> Stop"}
|
|
11
1641
|
\`\`\`
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1642
|
+
`;
|
|
1643
|
+
deviationStart = 3;
|
|
1644
|
+
deviationEnd = 10 - targetValue.length;
|
|
1645
|
+
break;
|
|
1646
|
+
}
|
|
1647
|
+
case "sequence": {
|
|
1648
|
+
targetValue = `\`\`\`mermaid
|
|
1649
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.sequence) || "sequenceDiagram\n A->>B: hello!\n B-->>A: hi!\n A-)B: bye!"}
|
|
17
1650
|
\`\`\`
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1651
|
+
`;
|
|
1652
|
+
deviationStart = 3;
|
|
1653
|
+
deviationEnd = 10 - targetValue.length;
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
case "gantt": {
|
|
1657
|
+
targetValue = `\`\`\`mermaid
|
|
1658
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.gantt) || "gantt\ntitle A Gantt Diagram\ndateFormat YYYY-MM-DD\nsection Section\nA task :a1, 2014-01-01, 30d\nAnother task :after a1, 20d"}
|
|
25
1659
|
\`\`\`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1660
|
+
`;
|
|
1661
|
+
deviationStart = 3;
|
|
1662
|
+
deviationEnd = 10 - targetValue.length;
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
case "class": {
|
|
1666
|
+
targetValue = `\`\`\`mermaid
|
|
1667
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.class) || "classDiagram\n class Animal\n Vehicle <|-- Car"}
|
|
30
1668
|
\`\`\`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1669
|
+
`;
|
|
1670
|
+
deviationStart = 3;
|
|
1671
|
+
deviationEnd = 10 - targetValue.length;
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
case "state": {
|
|
1675
|
+
targetValue = `\`\`\`mermaid
|
|
1676
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.state) || "stateDiagram-v2\n s1 --> s2"}
|
|
34
1677
|
\`\`\`
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1678
|
+
`;
|
|
1679
|
+
deviationStart = 3;
|
|
1680
|
+
deviationEnd = 10 - targetValue.length;
|
|
1681
|
+
break;
|
|
1682
|
+
}
|
|
1683
|
+
case "pie": {
|
|
1684
|
+
targetValue = `\`\`\`mermaid
|
|
1685
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.pie) || 'pie title Pets adopted by volunteers\n "Dogs" : 386\n "Cats" : 85\n "Rats" : 15'}
|
|
40
1686
|
\`\`\`
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1687
|
+
`;
|
|
1688
|
+
deviationStart = 3;
|
|
1689
|
+
deviationEnd = 10 - targetValue.length;
|
|
1690
|
+
break;
|
|
1691
|
+
}
|
|
1692
|
+
case "relationship": {
|
|
1693
|
+
targetValue = `\`\`\`mermaid
|
|
1694
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.relationship) || "erDiagram\n CAR ||--o{ NAMED-DRIVER : allows\n PERSON ||--o{ NAMED-DRIVER : is"}
|
|
45
1695
|
\`\`\`
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
section Go home
|
|
54
|
-
Go downstairs: 5: Me
|
|
55
|
-
Sit down: 5: Me`}
|
|
1696
|
+
`;
|
|
1697
|
+
deviationStart = 3;
|
|
1698
|
+
deviationEnd = 10 - targetValue.length;
|
|
1699
|
+
break;
|
|
1700
|
+
}
|
|
1701
|
+
case "journey": {
|
|
1702
|
+
targetValue = `\`\`\`mermaid
|
|
1703
|
+
${(mermaidTemplate == null ? void 0 : mermaidTemplate.journey) || "journey\n title My working day\n section Go to work\n Make tea: 5: Me\n Go upstairs: 3: Me\n Do work: 1: Me, Cat\n section Go home\n Go downstairs: 5: Me\n Sit down: 5: Me"}
|
|
56
1704
|
\`\`\`
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
!!!`,"title")}))]}};return xt.autocompletion({override:e?[a,...e]:[a]})},G=e=>{const a=new S.Compartment;return r=>(a.get(e.state)?e.dispatch({effects:a.reconfigure(r)}):e.dispatch({effects:S.StateEffect.appendConfig.of(a.of(r))}),!0)};class uo{constructor(a){F(this,"view");F(this,"maxLength",Number.MAX_SAFE_INTEGER);F(this,"toggleTabSize");F(this,"togglePlaceholder");F(this,"setExtensions");F(this,"toggleDisabled");F(this,"toggleReadOnly");F(this,"toggleMaxlength");this.view=a,this.toggleTabSize=G(this.view),this.togglePlaceholder=G(this.view),this.setExtensions=G(this.view),this.toggleDisabled=G(this.view),this.toggleReadOnly=G(this.view),this.toggleMaxlength=G(this.view)}getValue(){return this.view.state.doc.toString()}setValue(a,o=0,r=this.view.state.doc.length){this.view.dispatch({changes:{from:o,to:r,insert:a}})}getSelectedText(){const{from:a,to:o}=this.view.state.selection.main;return this.view.state.sliceDoc(a,o)}replaceSelectedText(a,o={select:!0,deviationStart:0,deviationEnd:0,replaceAll:!1},r){try{if(o.replaceAll){if(this.setValue(a),a.length>this.maxLength)throw new Error("The input text is too long");return}if(this.view.state.doc.length-this.getSelectedText().length+a.length>this.maxLength)throw new Error("The input text is too long");const{from:i}=this.view.state.selection.main;if(this.view.dispatch(this.view.state.replaceSelection(a)),o.select){const n=i+a.length+o.deviationEnd;this.view.dispatch({selection:S.EditorSelection.create([S.EditorSelection.range(i+o.deviationStart,n),S.EditorSelection.cursor(n)],1)})}this.view.focus()}catch(i){if(i.message==="The input text is too long")u.bus.emit(r,u.ERROR_CATCHER,{name:"overlength",message:i.message,data:a});else throw i}}setTabSize(a){this.toggleTabSize([S.EditorState.tabSize.of(a),oe.indentUnit.of(" ".repeat(a))])}setPlaceholder(a){this.togglePlaceholder(te.placeholder(a))}focus(a){if(this.view.focus(),!a)return;let o=0,r=0,i=0;switch(a){case"start":break;case"end":{o=r=i=this.getValue().length;break}default:o=a.rangeAnchor||a.cursorPos,r=a.rangeHead||a.cursorPos,i=a.cursorPos}this.view.dispatch({scrollIntoView:!0,selection:S.EditorSelection.create([S.EditorSelection.range(o,r),S.EditorSelection.cursor(i)],1)})}setDisabled(a){this.toggleDisabled([te.EditorView.editable.of(!a)])}setReadOnly(a){this.toggleReadOnly([S.EditorState.readOnly.of(a)])}setMaxLength(a){this.maxLength=a,this.toggleMaxlength([S.EditorState.changeFilter.of(o=>o.newDoc.length<=a)])}}const mo=e=>{const a=t.inject("editorId");return r=>{if(!r.clipboardData)return;if(r.clipboardData.files.length>0){const{files:n}=r.clipboardData;u.bus.emit(a,u.UPLOAD_IMAGE,Array.from(n).filter(h=>/image\/.*/.test(h.type))),r.preventDefault();return}if(e.autoDetectCode&&r.clipboardData.types.includes("vscode-editor-data")){const n=JSON.parse(r.clipboardData.getData("vscode-editor-data"));u.bus.emit(a,u.REPLACE,"code",{mode:n.mode,text:r.clipboardData.getData("text/plain")}),r.preventDefault();return}const i=r.clipboardData.getData("text/plain");e.maxlength&&i.length+e.modelValue.length>e.maxlength&&u.bus.emit(a,u.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:i})}},fo=(e,a)=>{const o={key:"Ctrl-b",mac:"Cmd-b",run:()=>(u.bus.emit(e,u.REPLACE,"bold"),!0)},r={key:"Ctrl-s",mac:"Cmd-s",run:p=>(u.bus.emit(e,u.ON_SAVE,p.state.doc.toString()),!0),shift:()=>(u.bus.emit(e,u.REPLACE,"strikeThrough"),!0)},i={key:"Ctrl-u",mac:"Cmd-u",run:()=>(u.bus.emit(e,u.REPLACE,"underline"),!0),shift:()=>(u.bus.emit(e,u.REPLACE,"unorderedList"),!0)},n={key:"Ctrl-i",mac:"Cmd-i",run:()=>(u.bus.emit(e,u.REPLACE,"italic"),!0),shift:()=>(u.bus.emit(e,u.OPEN_MODALS,"image"),!0)},h={key:"Ctrl-1",mac:"Cmd-1",run:()=>(u.bus.emit(e,u.REPLACE,"h1"),!0)},b={key:"Ctrl-2",mac:"Cmd-2",run:()=>(u.bus.emit(e,u.REPLACE,"h2"),!0)},f={key:"Ctrl-3",mac:"Cmd-3",run:()=>(u.bus.emit(e,u.REPLACE,"h3"),!0)},c={key:"Ctrl-4",mac:"Cmd-4",run:()=>(u.bus.emit(e,u.REPLACE,"h4"),!0)},g={key:"Ctrl-5",mac:"Cmd-5",run:()=>(u.bus.emit(e,u.REPLACE,"h5"),!0)},x={key:"Ctrl-6",mac:"Cmd-6",run:()=>(u.bus.emit(e,u.REPLACE,"h6"),!0)},k={key:"Ctrl-ArrowUp",mac:"Cmd-ArrowUp",run:()=>(u.bus.emit(e,u.REPLACE,"sup"),!0)},w={key:"Ctrl-ArrowDown",mac:"Cmd-ArrowDown",run:()=>(u.bus.emit(e,u.REPLACE,"sub"),!0)},y={key:"Ctrl-o",mac:"Cmd-o",run:()=>(u.bus.emit(e,u.REPLACE,"orderedList"),!0)},T={key:"Ctrl-c",mac:"Cmd-c",shift:()=>(u.bus.emit(e,u.REPLACE,"code"),!0),any(p,V){return(V.ctrlKey||V.metaKey)&&V.altKey&&V.code==="KeyC"?(u.bus.emit(e,u.REPLACE,"codeRow"),!0):!1}},d={key:"Ctrl-l",mac:"Cmd-l",run:()=>(u.bus.emit(e,u.OPEN_MODALS,"link"),!0)},m={key:"Ctrl-f",mac:"Cmd-f",shift:()=>a.noPrettier?!1:(u.bus.emit(e,u.REPLACE,"prettier"),!0)},v={any:(p,V)=>(V.ctrlKey||V.metaKey)&&V.altKey&&V.shiftKey&&V.code==="KeyT"?(u.bus.emit(e,u.REPLACE,"table"),!0):!1},C={key:"Ctrl-d",mac:"Cmd-d",run:j.deleteLine,preventDefault:!0};return[o,C,r,i,n,h,b,f,c,g,x,k,w,y,T,d,m,v]},go=e=>{const a=t.inject("tabWidth"),o=t.inject("editorId"),r=t.inject("theme"),i=t.ref(),n=t.shallowRef(),h=new S.Compartment,b=new S.Compartment,f=new S.Compartment,c=new S.Compartment,g=new S.Compartment,x=fo(o,e),k=t.ref(!1),y={paste:mo(e),blur:e.onBlur,focus:e.onFocus,drop:e.onDrop,compositionstart:()=>{console.log("compositionstart"),k.value=!0},compositionend:(m,v)=>{console.log("compositionend"),k.value=!1,e.updateModelValue(v.state.doc.toString())},input:m=>{e.onInput&&e.onInput(m);const{data:v}=m;e.maxlength&&e.modelValue.length+v.length>e.maxlength&&u.bus.emit(o,u.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:v})}},T=[te.keymap.of([...j.defaultKeymap,...j.historyKeymap,...x,j.indentWithTab]),c.of(j.history()),h.of(kt.markdown({codeLanguages:Ct.languages})),Y.EditorView.lineWrapping,Y.EditorView.updateListener.of(m=>{m.docChanged&&(e.onChange(m.state.doc.toString()),k.value||e.updateModelValue(m.state.doc.toString()))}),g.of(Y.EditorView.domEventHandlers(y))],d=()=>{const m=[...T,b.of(r.value==="light"?mt:nt),f.of(gt(e.completions))];return l.configOption.codeMirrorExtensions(r.value,m,[...x])};return t.onMounted(()=>{const m=new Y.EditorView({doc:e.modelValue,parent:i.value,extensions:[d()]}),v=new uo(m);n.value=v,setTimeout(()=>{v.setTabSize(a),v.setDisabled(e.disabled),v.setReadOnly(e.readonly),e.placeholder&&v.setPlaceholder(e.placeholder),typeof e.maxlength=="number"&&v.setMaxLength(e.maxlength),e.autofocus&&m.focus()},0),u.bus.on(o,{name:u.CTRL_Z,callback(){j.undo(m)}}),u.bus.on(o,{name:u.CTRL_SHIFT_Z,callback(){j.redo(m)}}),u.bus.on(o,{name:u.REPLACE,callback(C,p={}){var E;const{text:V,options:A}=qt(C,n.value,p);(E=n.value)==null||E.replaceSelectedText(V,A,o)}}),u.bus.on(o,{name:u.EVENT_LISTENER,callback(C){var A;const p={...y},V=Object.keys(y);for(const E in C){const L=E;V.includes(L)?p[L]=(B,R)=>{C[L](B,R),B.defaultPrevented||y[L](B,R)}:p[L]=C[L]}(A=n.value)==null||A.view.dispatch({effects:g.reconfigure(Y.EditorView.domEventHandlers(p))})}})}),t.watch(r,()=>{var m;(m=n.value)==null||m.view.dispatch({effects:b.reconfigure(r.value==="light"?mt:nt)})},{deep:!0}),t.watch(()=>e.completions,()=>{var m;(m=n.value)==null||m.view.dispatch({effects:f.reconfigure(gt(e.completions))})},{deep:!0}),t.watch(()=>e.modelValue,()=>{var m,v;((m=n.value)==null?void 0:m.getValue())!==e.modelValue&&((v=n.value)==null||v.setValue(e.modelValue))}),t.watch(()=>e.placeholder,()=>{var m;(m=n.value)==null||m.setPlaceholder(e.placeholder)}),t.watch(()=>e.disabled,()=>{var m;(m=n.value)==null||m.setDisabled(e.disabled)}),t.watch(()=>e.readonly,()=>{var m;(m=n.value)==null||m.setDisabled(e.readonly)}),t.watch(()=>e.maxlength,()=>{var m;e.maxlength&&((m=n.value)==null||m.setMaxLength(e.maxlength))}),{inputWrapperRef:i,codeMirrorUt:n,resetHistory(){var m,v;(m=n.value)==null||m.view.dispatch({effects:c.reconfigure([])}),(v=n.value)==null||v.view.dispatch({effects:c.reconfigure(j.history())})}}},bo=(e,a,o)=>{const r=t.reactive({resizedWidth:e.inputBoxWitdh}),i=t.reactive({width:e.inputBoxWitdh}),n=t.reactive({left:e.inputBoxWitdh,display:"initial"}),h=c=>{var y,T,d;const g=((y=a.value)==null?void 0:y.offsetWidth)||0,x=((T=a.value)==null?void 0:T.getBoundingClientRect().x)||0;let k=c.x-x;k<l.MinInputBoxWidth?k=l.MinInputBoxWidth:k>g-l.MinInputBoxWidth&&(k=g-l.MinInputBoxWidth);const w=`${k}px`;i.width=w,n.left=w,r.resizedWidth=w,(d=e.onInputBoxWitdhChange)==null||d.call(e,w)},b=()=>{document.addEventListener("mousemove",h)},f=()=>{document.removeEventListener("mousemove",h)};return t.onMounted(()=>{var c;(c=o.value)==null||c.addEventListener("mousedown",b),document.addEventListener("mouseup",f)}),t.onBeforeUnmount(()=>{var c,g;(c=o.value)==null||c.removeEventListener("mousedown",b),(g=o.value)==null||g.removeEventListener("mouseup",f)}),t.watch(()=>e.inputBoxWitdh,c=>{c&&(i.width=c,n.left=c)}),t.watch([t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"preview")],()=>{!e.setting.htmlPreview&&!e.setting.preview?(i.width="100%",n.display="none"):(i.width=r.resizedWidth,n.display="initial")},{immediate:!0}),{inputWrapperStyle:i,resizeOperateStyle:n}},ho=t.defineComponent({name:"MDEditorContent",props:O.contentProps,setup(e,a){const o=t.inject("editorId"),r=t.ref(""),i=t.ref(),n=t.ref(),{inputWrapperRef:h,codeMirrorUt:b,resetHistory:f}=go(e),{inputWrapperStyle:c,resizeOperateStyle:g}=bo(e,i,n);return Ft(e,r,b),a.expose({getSelectedText(){var x;return(x=b.value)==null?void 0:x.getSelectedText()},focus(x){var k;(k=b.value)==null||k.focus(x)},resetHistory:f}),()=>t.createVNode("div",{class:`${l.prefix}-content${e.setting.htmlPreview||e.setting.preview?" has-preview":""}`,ref:i},[t.createVNode("div",{class:`${l.prefix}-input-wrapper`,style:c,ref:h},null),(e.setting.htmlPreview||e.setting.preview)&&t.createVNode("div",{class:`${l.prefix}-resize-operate`,style:g,ref:n},null),t.createVNode(O.ContentPreview,{modelValue:e.modelValue,setting:e.setting,onHtmlChanged:x=>{r.value=x,e.onHtmlChanged(x)},onGetCatalog:e.onGetCatalog,mdHeadingId:e.mdHeadingId,noMermaid:e.noMermaid,sanitize:e.sanitize,noKatex:e.noKatex,formatCopiedText:e.formatCopiedText,noHighlight:e.noHighlight,noImgZoomIn:e.noImgZoomIn,sanitizeMermaid:e.sanitizeMermaid},null),e.catalogVisible&&t.createVNode(bt,{theme:e.theme,class:`${l.prefix}-catalog-editor`,editorId:o,mdHeadingId:e.mdHeadingId,key:"internal-catalog"},null)])}}),vo=t.defineComponent({props:{modelValue:{type:String,default:""}},setup(e){const a=t.inject("usedLanguageText");return()=>{var o,r;return t.createVNode("div",{class:`${l.prefix}-footer-item`},[t.createVNode("label",{class:`${l.prefix}-footer-label`},[`${(o=a.value.footer)==null?void 0:o.markdownTotal}:`]),t.createVNode("span",null,[((r=e.modelValue)==null?void 0:r.length)||0])])}}}),po={checked:{type:Boolean,default:!1},onChange:{type:Function,default:()=>{}}},Co=t.defineComponent({props:po,setup(e){return()=>t.createVNode("div",{class:[`${l.prefix}-checkbox`,e.checked&&`${l.prefix}-checkbox-checked`],onClick:()=>{e.onChange(!e.checked)}},null)}}),ko={scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}}},xo=t.defineComponent({props:ko,setup(e){const a=t.inject("usedLanguageText");return()=>{var o;return t.createVNode("div",{class:`${l.prefix}-footer-item`},[t.createVNode("label",{class:`${l.prefix}-footer-label`,onClick:()=>{e.onScrollAutoChange(!e.scrollAuto)}},[(o=a.value.footer)==null?void 0:o.scrollAuto]),t.createVNode(Co,{checked:e.scrollAuto,onChange:e.onScrollAutoChange},null)])}}}),No={modelValue:{type:String,default:""},footers:{type:Array,default:[]},scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}},defFooters:{type:Object}},$o=t.defineComponent({name:"MDEditorFooter",props:No,setup(e){const a=t.computed(()=>{const r=e.footers.indexOf("="),i=r===-1?e.footers:e.footers.slice(0,r),n=r===-1?[]:e.footers.slice(r,Number.MAX_SAFE_INTEGER);return[i,n]}),o=r=>{if(l.allFooter.includes(r))switch(r){case"markdownTotal":return t.createVNode(vo,{modelValue:e.modelValue},null);case"scrollSwitch":return t.createVNode(xo,{scrollAuto:e.scrollAuto,onScrollAutoChange:e.onScrollAutoChange},null)}else return e.defFooters instanceof Array?e.defFooters[r]||"":e.defFooters&&e.defFooters.children instanceof Array&&e.defFooters.children[r]||""};return()=>{const r=a.value[0].map(n=>o(n)),i=a.value[1].map(n=>o(n));return t.createVNode("div",{class:`${l.prefix}-footer`},[t.createVNode("div",{class:`${l.prefix}-footer-left`},[r]),t.createVNode("div",{class:`${l.prefix}-footer-right`},[i])])}}}),le=t.defineComponent({name:"MdEditorV3",props:O.editorProps,emits:O.editorEmits,setup(e,a){const{editorId:o,noKatex:r,noMermaid:i,noPrettier:n,noUploadImg:h,noHighlight:b}=e,f=t.reactive({scrollAuto:e.scrollAuto}),c=t.ref();O.useOnSave(e,a),O.useProvide(e),O.useExpansion(e),O.useErrorCatcher(e,a);const[g,x]=O.useConfig(e,a),k=O.useCatalog(e);return t.onBeforeUnmount(()=>{u.bus.clear(o)}),O.useExpose(e,a,k,g,x,c),()=>{var T;const w=et.getSlot({props:e,ctx:a},"defToolbars"),y=et.getSlot({props:e,ctx:a},"defFooters");return t.createVNode("div",{id:o,class:[l.prefix,e.class,e.theme==="dark"&&`${l.prefix}-dark`,g.fullscreen||g.pageFullscreen?`${l.prefix}-fullscreen`:""],style:e.style},[t.createVNode(Dt,{noPrettier:n,toolbars:e.toolbars,toolbarsExclude:e.toolbarsExclude,setting:g,updateSetting:x,tableShape:e.tableShape,defToolbars:w,noUploadImg:h,showToolbarName:e.showToolbarName},null),t.createVNode(ho,{ref:c,modelValue:e.modelValue,setting:g,mdHeadingId:e.mdHeadingId,noMermaid:i,noPrettier:n,sanitize:e.sanitize,placeholder:e.placeholder,noKatex:r,scrollAuto:f.scrollAuto,formatCopiedText:e.formatCopiedText,autofocus:e.autoFocus,disabled:e.disabled,readonly:e.readOnly,maxlength:e.maxLength,autoDetectCode:e.autoDetectCode,noHighlight:b,updateModelValue:d=>{a.emit("update:modelValue",d)},onChange:d=>{e.onChange&&e.onChange(d),a.emit("onChange",d)},onHtmlChanged:d=>{e.onHtmlChanged&&e.onHtmlChanged(d),a.emit("onHtmlChanged",d)},onGetCatalog:d=>{e.onGetCatalog&&e.onGetCatalog(d),a.emit("onGetCatalog",d)},onBlur:d=>{e.onBlur&&e.onBlur(d),a.emit("onBlur",d)},onFocus:d=>{e.onFocus&&e.onFocus(d),a.emit("onFocus",d)},onInput:d=>{e.onInput&&e.onInput(d),a.emit("onInput",d)},completions:e.completions,catalogVisible:k.value,theme:e.theme,noImgZoomIn:e.noImgZoomIn,onDrop:d=>{e.onDrop&&e.onDrop(d),a.emit("onDrop",d)},inputBoxWitdh:e.inputBoxWitdh,onInputBoxWitdhChange:d=>{e.onInputBoxWitdhChange&&e.onInputBoxWitdhChange(d),a.emit("onInputBoxWitdhChange",d)},sanitizeMermaid:e.sanitizeMermaid},null),((T=e.footers)==null?void 0:T.length)>0&&t.createVNode($o,{modelValue:e.modelValue,footers:e.footers,defFooters:y,scrollAuto:f.scrollAuto,onScrollAutoChange:d=>f.scrollAuto=d},null)])}}});le.install=e=>(e.component(le.name,le),e.use(Nt).use(U.DropdownToolbar).use($t).use(bt).use(O.MdPreview),e);module.exports=le;
|
|
1705
|
+
`;
|
|
1706
|
+
deviationStart = 3;
|
|
1707
|
+
deviationEnd = 10 - targetValue.length;
|
|
1708
|
+
break;
|
|
1709
|
+
}
|
|
1710
|
+
case "katexInline": {
|
|
1711
|
+
targetValue = "$$";
|
|
1712
|
+
deviationStart = 1;
|
|
1713
|
+
deviationEnd = -1;
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
1716
|
+
case "katexBlock": {
|
|
1717
|
+
targetValue = "$$\n\n$$\n";
|
|
1718
|
+
deviationStart = 3;
|
|
1719
|
+
deviationEnd = -4;
|
|
1720
|
+
break;
|
|
1721
|
+
}
|
|
1722
|
+
case "universal": {
|
|
1723
|
+
const { generate } = params;
|
|
1724
|
+
const insertOptions = generate(selectedText);
|
|
1725
|
+
targetValue = insertOptions.targetValue;
|
|
1726
|
+
select = insertOptions.select ?? true;
|
|
1727
|
+
deviationStart = insertOptions.deviationStart || 0;
|
|
1728
|
+
deviationEnd = insertOptions.deviationEnd || 0;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
return {
|
|
1733
|
+
text: targetValue,
|
|
1734
|
+
options: {
|
|
1735
|
+
// 是否选中
|
|
1736
|
+
select,
|
|
1737
|
+
// 选中时,开始位置的偏移量
|
|
1738
|
+
deviationStart,
|
|
1739
|
+
// 结束的偏移量
|
|
1740
|
+
deviationEnd,
|
|
1741
|
+
// 是否整个替换
|
|
1742
|
+
replaceAll
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
};
|
|
1746
|
+
const chalky$1 = "#e5c07b", coral$1 = "var(--md-color)", cyan$1 = "#56b6c2", invalid$1 = "#ffffff", ivory$1 = "var(--md-color)", stone$1 = "#e5c07b", malibu$1 = "#e5c07b", sage$1 = "var(--md-color)", whiskey$1 = "#d19a66", violet$1 = "#c678dd", darkBackground$1 = "#21252b", highlightBackground$1 = "#2c313a", background$1 = "var(--md-bk-color)", tooltipBackground$1 = "var(--md-bk-color)", selection$1 = "#ceedfa33", cursor$1 = "#528bff";
|
|
1747
|
+
const oneDarkTheme = view.EditorView.theme(
|
|
1748
|
+
{
|
|
1749
|
+
"&": {
|
|
1750
|
+
color: ivory$1,
|
|
1751
|
+
backgroundColor: background$1
|
|
1752
|
+
},
|
|
1753
|
+
".cm-content": {
|
|
1754
|
+
caretColor: cursor$1
|
|
1755
|
+
},
|
|
1756
|
+
".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor$1 },
|
|
1757
|
+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection$1 },
|
|
1758
|
+
".cm-panels": { backgroundColor: darkBackground$1, color: ivory$1 },
|
|
1759
|
+
".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
|
|
1760
|
+
".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
|
|
1761
|
+
".cm-searchMatch": {
|
|
1762
|
+
backgroundColor: "#72a1ff59",
|
|
1763
|
+
outline: "1px solid #457dff"
|
|
1764
|
+
},
|
|
1765
|
+
".cm-searchMatch.cm-searchMatch-selected": {
|
|
1766
|
+
backgroundColor: "#6199ff2f"
|
|
1767
|
+
},
|
|
1768
|
+
".cm-activeLine": { backgroundColor: "#ceedfa33" },
|
|
1769
|
+
".cm-selectionMatch": { backgroundColor: "#aafe661a" },
|
|
1770
|
+
"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": {
|
|
1771
|
+
backgroundColor: "#bad0f847"
|
|
1772
|
+
},
|
|
1773
|
+
".cm-gutters": {
|
|
1774
|
+
backgroundColor: background$1,
|
|
1775
|
+
color: ivory$1,
|
|
1776
|
+
borderRight: "1px solid",
|
|
1777
|
+
borderColor: "var(--md-border-color)"
|
|
1778
|
+
},
|
|
1779
|
+
".cm-activeLineGutter": {
|
|
1780
|
+
backgroundColor: highlightBackground$1
|
|
1781
|
+
},
|
|
1782
|
+
".cm-foldPlaceholder": {
|
|
1783
|
+
backgroundColor: "transparent",
|
|
1784
|
+
border: "none",
|
|
1785
|
+
color: "#ddd"
|
|
1786
|
+
},
|
|
1787
|
+
".cm-tooltip": {
|
|
1788
|
+
border: "1px solid var(--md-border-color)",
|
|
1789
|
+
backgroundColor: tooltipBackground$1
|
|
1790
|
+
},
|
|
1791
|
+
".cm-tooltip .cm-tooltip-arrow:before": {
|
|
1792
|
+
borderTopColor: "transparent",
|
|
1793
|
+
borderBottomColor: "transparent"
|
|
1794
|
+
},
|
|
1795
|
+
".cm-tooltip .cm-tooltip-arrow:after": {
|
|
1796
|
+
borderTopColor: tooltipBackground$1,
|
|
1797
|
+
borderBottomColor: tooltipBackground$1
|
|
1798
|
+
},
|
|
1799
|
+
".cm-tooltip-autocomplete": {
|
|
1800
|
+
"& > ul > li[aria-selected]": {
|
|
1801
|
+
color: ivory$1
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
},
|
|
1805
|
+
{ dark: true }
|
|
1806
|
+
);
|
|
1807
|
+
const oneDarkHighlightStyle = language.HighlightStyle.define([
|
|
1808
|
+
{ tag: highlight.tags.keyword, color: violet$1 },
|
|
1809
|
+
{ tag: [highlight.tags.name, highlight.tags.deleted, highlight.tags.character, highlight.tags.propertyName, highlight.tags.macroName], color: coral$1 },
|
|
1810
|
+
{ tag: [highlight.tags.function(highlight.tags.variableName), highlight.tags.labelName], color: malibu$1 },
|
|
1811
|
+
{ tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)], color: whiskey$1 },
|
|
1812
|
+
{ tag: [highlight.tags.definition(highlight.tags.name), highlight.tags.separator], color: ivory$1 },
|
|
1813
|
+
{
|
|
1814
|
+
tag: [
|
|
1815
|
+
highlight.tags.typeName,
|
|
1816
|
+
highlight.tags.className,
|
|
1817
|
+
highlight.tags.number,
|
|
1818
|
+
highlight.tags.changed,
|
|
1819
|
+
highlight.tags.annotation,
|
|
1820
|
+
highlight.tags.modifier,
|
|
1821
|
+
highlight.tags.self,
|
|
1822
|
+
highlight.tags.namespace
|
|
1823
|
+
],
|
|
1824
|
+
color: chalky$1
|
|
1825
|
+
},
|
|
1826
|
+
{
|
|
1827
|
+
tag: [
|
|
1828
|
+
highlight.tags.operator,
|
|
1829
|
+
highlight.tags.operatorKeyword,
|
|
1830
|
+
highlight.tags.url,
|
|
1831
|
+
highlight.tags.escape,
|
|
1832
|
+
highlight.tags.regexp,
|
|
1833
|
+
highlight.tags.link,
|
|
1834
|
+
highlight.tags.special(highlight.tags.string)
|
|
1835
|
+
],
|
|
1836
|
+
color: cyan$1
|
|
1837
|
+
},
|
|
1838
|
+
{ tag: [highlight.tags.meta, highlight.tags.comment], color: stone$1 },
|
|
1839
|
+
{ tag: highlight.tags.strong, fontWeight: "bold" },
|
|
1840
|
+
{ tag: highlight.tags.emphasis, fontStyle: "italic" },
|
|
1841
|
+
{ tag: highlight.tags.strikethrough, textDecoration: "line-through" },
|
|
1842
|
+
{ tag: highlight.tags.link, color: stone$1, textDecoration: "underline" },
|
|
1843
|
+
{ tag: highlight.tags.heading, fontWeight: "bold", color: coral$1 },
|
|
1844
|
+
{ tag: [highlight.tags.atom, highlight.tags.bool, highlight.tags.special(highlight.tags.variableName)], color: whiskey$1 },
|
|
1845
|
+
{ tag: [highlight.tags.processingInstruction, highlight.tags.string, highlight.tags.inserted], color: sage$1 },
|
|
1846
|
+
{ tag: highlight.tags.invalid, color: invalid$1 }
|
|
1847
|
+
]);
|
|
1848
|
+
const oneDark = [
|
|
1849
|
+
oneDarkTheme,
|
|
1850
|
+
language.syntaxHighlighting(oneDarkHighlightStyle)
|
|
1851
|
+
];
|
|
1852
|
+
const chalky = "#e5c07b", coral = "#3f4a54", cyan = "#56b6c2", invalid = "#fff", ivory = "#3f4a54", stone = "#2d8cf0", malibu = "#2d8cf0", sage = "#3f4a54", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#21252b", highlightBackground = "#ceedfa33", background = "var(--md-bk-color)", tooltipBackground = "var(--md-bk-color)", selection = "#bad5fa", cursor = "#3f4a54";
|
|
1853
|
+
const oneLightTheme = view.EditorView.theme(
|
|
1854
|
+
{
|
|
1855
|
+
"&": {
|
|
1856
|
+
color: ivory,
|
|
1857
|
+
backgroundColor: background
|
|
1858
|
+
},
|
|
1859
|
+
".cm-content": {
|
|
1860
|
+
caretColor: cursor
|
|
1861
|
+
},
|
|
1862
|
+
".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor },
|
|
1863
|
+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection },
|
|
1864
|
+
".cm-panels": { backgroundColor: darkBackground, color: ivory },
|
|
1865
|
+
".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
|
|
1866
|
+
".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
|
|
1867
|
+
".cm-searchMatch": {
|
|
1868
|
+
backgroundColor: "#72a1ff59",
|
|
1869
|
+
outline: "1px solid #457dff"
|
|
1870
|
+
},
|
|
1871
|
+
".cm-searchMatch.cm-searchMatch-selected": {
|
|
1872
|
+
backgroundColor: "#6199ff2f"
|
|
1873
|
+
},
|
|
1874
|
+
".cm-activeLine": { backgroundColor: "#ceedfa33" },
|
|
1875
|
+
".cm-selectionMatch": { backgroundColor: "#aafe661a" },
|
|
1876
|
+
"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": {
|
|
1877
|
+
backgroundColor: "#bad0f847"
|
|
1878
|
+
},
|
|
1879
|
+
".cm-gutters": {
|
|
1880
|
+
backgroundColor: background,
|
|
1881
|
+
color: ivory,
|
|
1882
|
+
borderRight: "1px solid",
|
|
1883
|
+
borderColor: "var(--md-border-color)"
|
|
1884
|
+
},
|
|
1885
|
+
".cm-activeLineGutter": {
|
|
1886
|
+
backgroundColor: highlightBackground
|
|
1887
|
+
},
|
|
1888
|
+
".cm-foldPlaceholder": {
|
|
1889
|
+
backgroundColor: "transparent",
|
|
1890
|
+
border: "none",
|
|
1891
|
+
color: "#ddd"
|
|
1892
|
+
},
|
|
1893
|
+
".cm-tooltip": {
|
|
1894
|
+
border: "1px solid var(--md-border-color)",
|
|
1895
|
+
backgroundColor: tooltipBackground
|
|
1896
|
+
},
|
|
1897
|
+
".cm-tooltip .cm-tooltip-arrow:before": {
|
|
1898
|
+
borderTopColor: "transparent",
|
|
1899
|
+
borderBottomColor: "transparent"
|
|
1900
|
+
},
|
|
1901
|
+
".cm-tooltip .cm-tooltip-arrow:after": {
|
|
1902
|
+
borderTopColor: tooltipBackground,
|
|
1903
|
+
borderBottomColor: tooltipBackground
|
|
1904
|
+
},
|
|
1905
|
+
".cm-tooltip-autocomplete": {
|
|
1906
|
+
"& > ul > li[aria-selected]": {
|
|
1907
|
+
color: ivory
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
// { dark: true }
|
|
1912
|
+
);
|
|
1913
|
+
const oneLightHighlightStyle = language.HighlightStyle.define([
|
|
1914
|
+
{ tag: highlight.tags.keyword, color: violet },
|
|
1915
|
+
{ tag: [highlight.tags.name, highlight.tags.deleted, highlight.tags.character, highlight.tags.propertyName, highlight.tags.macroName], color: coral },
|
|
1916
|
+
{ tag: [highlight.tags.function(highlight.tags.variableName), highlight.tags.labelName], color: malibu },
|
|
1917
|
+
{ tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)], color: whiskey },
|
|
1918
|
+
{ tag: [highlight.tags.definition(highlight.tags.name), highlight.tags.separator], color: ivory },
|
|
1919
|
+
{
|
|
1920
|
+
tag: [
|
|
1921
|
+
highlight.tags.typeName,
|
|
1922
|
+
highlight.tags.className,
|
|
1923
|
+
highlight.tags.number,
|
|
1924
|
+
highlight.tags.changed,
|
|
1925
|
+
highlight.tags.annotation,
|
|
1926
|
+
highlight.tags.modifier,
|
|
1927
|
+
highlight.tags.self,
|
|
1928
|
+
highlight.tags.namespace
|
|
1929
|
+
],
|
|
1930
|
+
color: chalky
|
|
1931
|
+
},
|
|
1932
|
+
{
|
|
1933
|
+
tag: [
|
|
1934
|
+
highlight.tags.operator,
|
|
1935
|
+
highlight.tags.operatorKeyword,
|
|
1936
|
+
highlight.tags.url,
|
|
1937
|
+
highlight.tags.escape,
|
|
1938
|
+
highlight.tags.regexp,
|
|
1939
|
+
highlight.tags.link,
|
|
1940
|
+
highlight.tags.special(highlight.tags.string)
|
|
1941
|
+
],
|
|
1942
|
+
color: cyan
|
|
1943
|
+
},
|
|
1944
|
+
{ tag: [highlight.tags.meta, highlight.tags.comment], color: stone },
|
|
1945
|
+
{ tag: highlight.tags.strong, fontWeight: "bold" },
|
|
1946
|
+
{ tag: highlight.tags.emphasis, fontStyle: "italic" },
|
|
1947
|
+
{ tag: highlight.tags.strikethrough, textDecoration: "line-through" },
|
|
1948
|
+
{ tag: highlight.tags.link, color: stone, textDecoration: "underline" },
|
|
1949
|
+
{ tag: highlight.tags.heading, fontWeight: "bold", color: coral },
|
|
1950
|
+
{ tag: [highlight.tags.atom, highlight.tags.bool, highlight.tags.special(highlight.tags.variableName)], color: whiskey },
|
|
1951
|
+
{ tag: [highlight.tags.processingInstruction, highlight.tags.string, highlight.tags.inserted], color: sage },
|
|
1952
|
+
{ tag: highlight.tags.invalid, color: invalid }
|
|
1953
|
+
]);
|
|
1954
|
+
const oneLight = [
|
|
1955
|
+
oneLightTheme,
|
|
1956
|
+
language.syntaxHighlighting(oneLightHighlightStyle)
|
|
1957
|
+
];
|
|
1958
|
+
const getPairApply = (flag, type, title, suffix, selectType) => {
|
|
1959
|
+
return (view2, _completion, from, to) => {
|
|
1960
|
+
const label = `${flag}${type}`.slice(to - from);
|
|
1961
|
+
view2.dispatch(view2.state.replaceSelection(`${label}${title}${suffix}`));
|
|
1962
|
+
const newTo = from + _completion.label.length + (selectType === "title" ? title.length : 0);
|
|
1963
|
+
view2.dispatch({
|
|
1964
|
+
selection: state.EditorSelection.create(
|
|
1965
|
+
[
|
|
1966
|
+
state.EditorSelection.range(
|
|
1967
|
+
from + _completion.label.length + (selectType === "title" ? 1 : -type.length),
|
|
1968
|
+
newTo
|
|
1969
|
+
),
|
|
1970
|
+
state.EditorSelection.cursor(newTo)
|
|
1971
|
+
],
|
|
1972
|
+
1
|
|
1973
|
+
)
|
|
1974
|
+
});
|
|
1975
|
+
view2.focus();
|
|
1976
|
+
};
|
|
1977
|
+
};
|
|
1978
|
+
const getApply = (_label) => {
|
|
1979
|
+
return (view2, _completion, from, to) => {
|
|
1980
|
+
const label = _label.slice(to - from);
|
|
1981
|
+
view2.dispatch(view2.state.replaceSelection(`${label} `));
|
|
1982
|
+
};
|
|
1983
|
+
};
|
|
1984
|
+
const createAutocompletion = (completions) => {
|
|
1985
|
+
const defaultCompletion = (context) => {
|
|
1986
|
+
const word = context.matchBefore(
|
|
1987
|
+
/^#+|^-\s*\[*\s*\]*|`+|\[|!\[*|^\|\s?\|?|^\$\$?|!+\s*\w*/
|
|
1988
|
+
);
|
|
1989
|
+
if (word === null || word.from == word.to && context.explicit) {
|
|
1990
|
+
return null;
|
|
1991
|
+
}
|
|
1992
|
+
return {
|
|
1993
|
+
from: word.from,
|
|
1994
|
+
options: [
|
|
1995
|
+
// 标题
|
|
1996
|
+
...["h1", "h2", "h3", "h4", "h5", "h6"].map((key, index2) => {
|
|
1997
|
+
const label = new Array(index2 + 1).fill("#").join("");
|
|
1998
|
+
return {
|
|
1999
|
+
label,
|
|
2000
|
+
type: "text",
|
|
2001
|
+
apply: getApply(label)
|
|
2002
|
+
};
|
|
2003
|
+
}),
|
|
2004
|
+
// 任务列表
|
|
2005
|
+
...["unchecked", "checked"].map((key) => {
|
|
2006
|
+
const label = key === "checked" ? "- [x]" : "- [ ]";
|
|
2007
|
+
return {
|
|
2008
|
+
label,
|
|
2009
|
+
type: "text",
|
|
2010
|
+
apply: getApply(label)
|
|
2011
|
+
};
|
|
2012
|
+
}),
|
|
2013
|
+
// 代码
|
|
2014
|
+
...[
|
|
2015
|
+
["`", ""],
|
|
2016
|
+
["```", "language"],
|
|
2017
|
+
["```mermaid\n", ""]
|
|
2018
|
+
].map((c) => {
|
|
2019
|
+
return {
|
|
2020
|
+
label: `${c[0]}${c[1]}`,
|
|
2021
|
+
type: "text",
|
|
2022
|
+
apply: getPairApply(c[0], c[1], "", c[0] === "`" ? "`" : "\n```", "type")
|
|
2023
|
+
};
|
|
2024
|
+
}),
|
|
2025
|
+
// 链接
|
|
2026
|
+
{
|
|
2027
|
+
label: "[]()",
|
|
2028
|
+
type: "text"
|
|
2029
|
+
},
|
|
2030
|
+
{
|
|
2031
|
+
label: "![]()",
|
|
2032
|
+
type: "text"
|
|
2033
|
+
},
|
|
2034
|
+
// 表格
|
|
2035
|
+
{
|
|
2036
|
+
label: "| |",
|
|
2037
|
+
type: "text",
|
|
2038
|
+
detail: "table",
|
|
2039
|
+
apply: "| col | col | col |\n| - | - | - |\n| content | content | content |\n| content | content | content |"
|
|
2040
|
+
},
|
|
2041
|
+
// 公式
|
|
2042
|
+
{
|
|
2043
|
+
label: "$",
|
|
2044
|
+
type: "text",
|
|
2045
|
+
apply: getPairApply("$", "", "", "$", "type")
|
|
2046
|
+
},
|
|
2047
|
+
{
|
|
2048
|
+
label: "$$",
|
|
2049
|
+
type: "text",
|
|
2050
|
+
apply: getPairApply("$$", "", "\n", "\n$$", "title")
|
|
2051
|
+
},
|
|
2052
|
+
// 那啥?
|
|
2053
|
+
...[
|
|
2054
|
+
"note",
|
|
2055
|
+
"abstract",
|
|
2056
|
+
"info",
|
|
2057
|
+
"tip",
|
|
2058
|
+
"success",
|
|
2059
|
+
"question",
|
|
2060
|
+
"warning",
|
|
2061
|
+
"failure",
|
|
2062
|
+
"danger",
|
|
2063
|
+
"bug",
|
|
2064
|
+
"example",
|
|
2065
|
+
"quote",
|
|
2066
|
+
"hint",
|
|
2067
|
+
"caution",
|
|
2068
|
+
"error",
|
|
2069
|
+
"attention"
|
|
2070
|
+
].map((key) => {
|
|
2071
|
+
const label = `!!! ${key}`;
|
|
2072
|
+
return {
|
|
2073
|
+
label,
|
|
2074
|
+
type: "text",
|
|
2075
|
+
apply: getPairApply("!!!", ` ${key}`, " Title", "\n\n!!!", "title")
|
|
2076
|
+
};
|
|
2077
|
+
})
|
|
2078
|
+
]
|
|
2079
|
+
};
|
|
2080
|
+
};
|
|
2081
|
+
return autocomplete.autocompletion({
|
|
2082
|
+
override: completions ? [defaultCompletion, ...completions] : [defaultCompletion]
|
|
2083
|
+
});
|
|
2084
|
+
};
|
|
2085
|
+
const toggleWith = (view2) => {
|
|
2086
|
+
const mc = new state.Compartment();
|
|
2087
|
+
const toggle = (extension) => {
|
|
2088
|
+
mc.get(view2.state) ? view2.dispatch({ effects: mc.reconfigure(extension) }) : view2.dispatch({
|
|
2089
|
+
effects: state.StateEffect.appendConfig.of(mc.of(extension))
|
|
2090
|
+
});
|
|
2091
|
+
return true;
|
|
2092
|
+
};
|
|
2093
|
+
return toggle;
|
|
2094
|
+
};
|
|
2095
|
+
class CodeMirrorUt {
|
|
2096
|
+
constructor(view2) {
|
|
2097
|
+
__publicField(this, "view");
|
|
2098
|
+
__publicField(this, "maxLength", Number.MAX_SAFE_INTEGER);
|
|
2099
|
+
// 切换tabSize的执行方法。切换时,Compartment实例需要相同
|
|
2100
|
+
__publicField(this, "toggleTabSize");
|
|
2101
|
+
__publicField(this, "togglePlaceholder");
|
|
2102
|
+
/**
|
|
2103
|
+
* 设置全部的扩展
|
|
2104
|
+
*/
|
|
2105
|
+
__publicField(this, "setExtensions");
|
|
2106
|
+
__publicField(this, "toggleDisabled");
|
|
2107
|
+
__publicField(this, "toggleReadOnly");
|
|
2108
|
+
__publicField(this, "toggleMaxlength");
|
|
2109
|
+
this.view = view2;
|
|
2110
|
+
this.toggleTabSize = toggleWith(this.view);
|
|
2111
|
+
this.togglePlaceholder = toggleWith(this.view);
|
|
2112
|
+
this.setExtensions = toggleWith(this.view);
|
|
2113
|
+
this.toggleDisabled = toggleWith(this.view);
|
|
2114
|
+
this.toggleReadOnly = toggleWith(this.view);
|
|
2115
|
+
this.toggleMaxlength = toggleWith(this.view);
|
|
2116
|
+
}
|
|
2117
|
+
getValue() {
|
|
2118
|
+
return this.view.state.doc.toString();
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* 设置内容
|
|
2122
|
+
*
|
|
2123
|
+
* @param insert 待插入内容
|
|
2124
|
+
* @param from 插入开始位置
|
|
2125
|
+
* @param to 插入结束位置
|
|
2126
|
+
*/
|
|
2127
|
+
setValue(insert, from = 0, to = this.view.state.doc.length) {
|
|
2128
|
+
this.view.dispatch({
|
|
2129
|
+
changes: {
|
|
2130
|
+
from,
|
|
2131
|
+
to,
|
|
2132
|
+
insert
|
|
2133
|
+
}
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* 获取选中的文本
|
|
2138
|
+
*/
|
|
2139
|
+
getSelectedText() {
|
|
2140
|
+
const { from, to } = this.view.state.selection.main;
|
|
2141
|
+
return this.view.state.sliceDoc(from, to);
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* 使用新的内容替换选中的内容
|
|
2145
|
+
*
|
|
2146
|
+
* @param text 待替换内容
|
|
2147
|
+
* @param options 替换后是否选中
|
|
2148
|
+
*/
|
|
2149
|
+
replaceSelectedText(text, options = {
|
|
2150
|
+
// 是否选中
|
|
2151
|
+
select: true,
|
|
2152
|
+
// 选中时,开始位置的偏移量
|
|
2153
|
+
deviationStart: 0,
|
|
2154
|
+
// 结束的偏移量
|
|
2155
|
+
deviationEnd: 0,
|
|
2156
|
+
// 直接替换所有文本
|
|
2157
|
+
replaceAll: false
|
|
2158
|
+
}, editorId) {
|
|
2159
|
+
try {
|
|
2160
|
+
if (options.replaceAll) {
|
|
2161
|
+
this.setValue(text);
|
|
2162
|
+
if (text.length > this.maxLength) {
|
|
2163
|
+
throw new Error("The input text is too long");
|
|
2164
|
+
}
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
if (this.view.state.doc.length - this.getSelectedText().length + text.length > this.maxLength) {
|
|
2168
|
+
throw new Error("The input text is too long");
|
|
2169
|
+
}
|
|
2170
|
+
const { from } = this.view.state.selection.main;
|
|
2171
|
+
this.view.dispatch(this.view.state.replaceSelection(text));
|
|
2172
|
+
if (options.select) {
|
|
2173
|
+
const to = from + text.length + options.deviationEnd;
|
|
2174
|
+
this.view.dispatch({
|
|
2175
|
+
selection: state.EditorSelection.create(
|
|
2176
|
+
[
|
|
2177
|
+
state.EditorSelection.range(from + options.deviationStart, to),
|
|
2178
|
+
state.EditorSelection.cursor(to)
|
|
2179
|
+
],
|
|
2180
|
+
1
|
|
2181
|
+
)
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
this.view.focus();
|
|
2185
|
+
} catch (e) {
|
|
2186
|
+
if (e.message === "The input text is too long") {
|
|
2187
|
+
index.bus.emit(editorId, index.ERROR_CATCHER, {
|
|
2188
|
+
name: "overlength",
|
|
2189
|
+
message: e.message,
|
|
2190
|
+
data: text
|
|
2191
|
+
});
|
|
2192
|
+
} else {
|
|
2193
|
+
throw e;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
/**
|
|
2198
|
+
* 设置tabSize
|
|
2199
|
+
*
|
|
2200
|
+
* @param tabSize 需要切换的大小
|
|
2201
|
+
*/
|
|
2202
|
+
setTabSize(tabSize) {
|
|
2203
|
+
this.toggleTabSize([
|
|
2204
|
+
state.EditorState.tabSize.of(tabSize),
|
|
2205
|
+
language.indentUnit.of(" ".repeat(tabSize))
|
|
2206
|
+
]);
|
|
2207
|
+
}
|
|
2208
|
+
/**
|
|
2209
|
+
* 设置placeholder
|
|
2210
|
+
*
|
|
2211
|
+
* @param t 目标内容
|
|
2212
|
+
*/
|
|
2213
|
+
setPlaceholder(t) {
|
|
2214
|
+
this.togglePlaceholder(view.placeholder(t));
|
|
2215
|
+
}
|
|
2216
|
+
focus(options) {
|
|
2217
|
+
this.view.focus();
|
|
2218
|
+
if (!options) {
|
|
2219
|
+
return;
|
|
2220
|
+
}
|
|
2221
|
+
let anchor = 0;
|
|
2222
|
+
let head = 0;
|
|
2223
|
+
let pos = 0;
|
|
2224
|
+
switch (options) {
|
|
2225
|
+
case "start": {
|
|
2226
|
+
break;
|
|
2227
|
+
}
|
|
2228
|
+
case "end": {
|
|
2229
|
+
const length = this.getValue().length;
|
|
2230
|
+
anchor = head = pos = length;
|
|
2231
|
+
break;
|
|
2232
|
+
}
|
|
2233
|
+
default: {
|
|
2234
|
+
anchor = options.rangeAnchor || options.cursorPos;
|
|
2235
|
+
head = options.rangeHead || options.cursorPos;
|
|
2236
|
+
pos = options.cursorPos;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
this.view.dispatch({
|
|
2240
|
+
scrollIntoView: true,
|
|
2241
|
+
selection: state.EditorSelection.create(
|
|
2242
|
+
[state.EditorSelection.range(anchor, head), state.EditorSelection.cursor(pos)],
|
|
2243
|
+
1
|
|
2244
|
+
)
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
setDisabled(d) {
|
|
2248
|
+
this.toggleDisabled([view.EditorView.editable.of(!d)]);
|
|
2249
|
+
}
|
|
2250
|
+
setReadOnly(r) {
|
|
2251
|
+
this.toggleReadOnly([state.EditorState.readOnly.of(r)]);
|
|
2252
|
+
}
|
|
2253
|
+
setMaxLength(ml) {
|
|
2254
|
+
this.maxLength = ml;
|
|
2255
|
+
this.toggleMaxlength([
|
|
2256
|
+
state.EditorState.changeFilter.of((tr) => {
|
|
2257
|
+
return tr.newDoc.length <= ml;
|
|
2258
|
+
})
|
|
2259
|
+
]);
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
const usePasteUpload = (props2) => {
|
|
2263
|
+
const editorId = vue.inject("editorId");
|
|
2264
|
+
const pasteHandler = (e) => {
|
|
2265
|
+
if (!e.clipboardData) {
|
|
2266
|
+
return;
|
|
2267
|
+
}
|
|
2268
|
+
if (e.clipboardData.files.length > 0) {
|
|
2269
|
+
const { files } = e.clipboardData;
|
|
2270
|
+
index.bus.emit(
|
|
2271
|
+
editorId,
|
|
2272
|
+
index.UPLOAD_IMAGE,
|
|
2273
|
+
Array.from(files).filter((file) => {
|
|
2274
|
+
return /image\/.*/.test(file.type);
|
|
2275
|
+
})
|
|
2276
|
+
);
|
|
2277
|
+
e.preventDefault();
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
if (props2.autoDetectCode && e.clipboardData.types.includes("vscode-editor-data")) {
|
|
2281
|
+
const vscCoodInfo = JSON.parse(e.clipboardData.getData("vscode-editor-data"));
|
|
2282
|
+
index.bus.emit(editorId, index.REPLACE, "code", {
|
|
2283
|
+
mode: vscCoodInfo.mode,
|
|
2284
|
+
text: e.clipboardData.getData("text/plain")
|
|
2285
|
+
});
|
|
2286
|
+
e.preventDefault();
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
2289
|
+
const targetValue = e.clipboardData.getData("text/plain");
|
|
2290
|
+
if (props2.maxlength && targetValue.length + props2.modelValue.length > props2.maxlength) {
|
|
2291
|
+
index.bus.emit(editorId, index.ERROR_CATCHER, {
|
|
2292
|
+
name: "overlength",
|
|
2293
|
+
message: "The input text is too long",
|
|
2294
|
+
data: targetValue
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2298
|
+
return pasteHandler;
|
|
2299
|
+
};
|
|
2300
|
+
const createCommands = (id, contentProps) => {
|
|
2301
|
+
const CtrlB = {
|
|
2302
|
+
key: "Ctrl-b",
|
|
2303
|
+
mac: "Cmd-b",
|
|
2304
|
+
run: () => {
|
|
2305
|
+
index.bus.emit(id, index.REPLACE, "bold");
|
|
2306
|
+
return true;
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
const CtrlS = {
|
|
2310
|
+
key: "Ctrl-s",
|
|
2311
|
+
mac: "Cmd-s",
|
|
2312
|
+
run: (view2) => {
|
|
2313
|
+
index.bus.emit(id, index.ON_SAVE, view2.state.doc.toString());
|
|
2314
|
+
return true;
|
|
2315
|
+
},
|
|
2316
|
+
shift: () => {
|
|
2317
|
+
index.bus.emit(id, index.REPLACE, "strikeThrough");
|
|
2318
|
+
return true;
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
const CtrlU = {
|
|
2322
|
+
key: "Ctrl-u",
|
|
2323
|
+
mac: "Cmd-u",
|
|
2324
|
+
run: () => {
|
|
2325
|
+
index.bus.emit(id, index.REPLACE, "underline");
|
|
2326
|
+
return true;
|
|
2327
|
+
},
|
|
2328
|
+
shift: () => {
|
|
2329
|
+
index.bus.emit(id, index.REPLACE, "unorderedList");
|
|
2330
|
+
return true;
|
|
2331
|
+
}
|
|
2332
|
+
};
|
|
2333
|
+
const CtrlI = {
|
|
2334
|
+
key: "Ctrl-i",
|
|
2335
|
+
mac: "Cmd-i",
|
|
2336
|
+
run: () => {
|
|
2337
|
+
index.bus.emit(id, index.REPLACE, "italic");
|
|
2338
|
+
return true;
|
|
2339
|
+
},
|
|
2340
|
+
shift: () => {
|
|
2341
|
+
index.bus.emit(id, index.OPEN_MODALS, "image");
|
|
2342
|
+
return true;
|
|
2343
|
+
}
|
|
2344
|
+
};
|
|
2345
|
+
const Ctrl1 = {
|
|
2346
|
+
key: "Ctrl-1",
|
|
2347
|
+
mac: "Cmd-1",
|
|
2348
|
+
run: () => {
|
|
2349
|
+
index.bus.emit(id, index.REPLACE, "h1");
|
|
2350
|
+
return true;
|
|
2351
|
+
}
|
|
2352
|
+
};
|
|
2353
|
+
const Ctrl2 = {
|
|
2354
|
+
key: "Ctrl-2",
|
|
2355
|
+
mac: "Cmd-2",
|
|
2356
|
+
run: () => {
|
|
2357
|
+
index.bus.emit(id, index.REPLACE, "h2");
|
|
2358
|
+
return true;
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2361
|
+
const Ctrl3 = {
|
|
2362
|
+
key: "Ctrl-3",
|
|
2363
|
+
mac: "Cmd-3",
|
|
2364
|
+
run: () => {
|
|
2365
|
+
index.bus.emit(id, index.REPLACE, "h3");
|
|
2366
|
+
return true;
|
|
2367
|
+
}
|
|
2368
|
+
};
|
|
2369
|
+
const Ctrl4 = {
|
|
2370
|
+
key: "Ctrl-4",
|
|
2371
|
+
mac: "Cmd-4",
|
|
2372
|
+
run: () => {
|
|
2373
|
+
index.bus.emit(id, index.REPLACE, "h4");
|
|
2374
|
+
return true;
|
|
2375
|
+
}
|
|
2376
|
+
};
|
|
2377
|
+
const Ctrl5 = {
|
|
2378
|
+
key: "Ctrl-5",
|
|
2379
|
+
mac: "Cmd-5",
|
|
2380
|
+
run: () => {
|
|
2381
|
+
index.bus.emit(id, index.REPLACE, "h5");
|
|
2382
|
+
return true;
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
const Ctrl6 = {
|
|
2386
|
+
key: "Ctrl-6",
|
|
2387
|
+
mac: "Cmd-6",
|
|
2388
|
+
run: () => {
|
|
2389
|
+
index.bus.emit(id, index.REPLACE, "h6");
|
|
2390
|
+
return true;
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
2393
|
+
const CtrlArrowUp = {
|
|
2394
|
+
key: "Ctrl-ArrowUp",
|
|
2395
|
+
mac: "Cmd-ArrowUp",
|
|
2396
|
+
run: () => {
|
|
2397
|
+
index.bus.emit(id, index.REPLACE, "sup");
|
|
2398
|
+
return true;
|
|
2399
|
+
}
|
|
2400
|
+
};
|
|
2401
|
+
const CtrlArrowDown = {
|
|
2402
|
+
key: "Ctrl-ArrowDown",
|
|
2403
|
+
mac: "Cmd-ArrowDown",
|
|
2404
|
+
run: () => {
|
|
2405
|
+
index.bus.emit(id, index.REPLACE, "sub");
|
|
2406
|
+
return true;
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
const CtrlO = {
|
|
2410
|
+
key: "Ctrl-o",
|
|
2411
|
+
mac: "Cmd-o",
|
|
2412
|
+
run: () => {
|
|
2413
|
+
index.bus.emit(id, index.REPLACE, "orderedList");
|
|
2414
|
+
return true;
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
const CtrlC = {
|
|
2418
|
+
key: "Ctrl-c",
|
|
2419
|
+
mac: "Cmd-c",
|
|
2420
|
+
shift: () => {
|
|
2421
|
+
index.bus.emit(id, index.REPLACE, "code");
|
|
2422
|
+
return true;
|
|
2423
|
+
},
|
|
2424
|
+
any(_view, e) {
|
|
2425
|
+
if ((e.ctrlKey || e.metaKey) && e.altKey && e.code === "KeyC") {
|
|
2426
|
+
index.bus.emit(id, index.REPLACE, "codeRow");
|
|
2427
|
+
return true;
|
|
2428
|
+
}
|
|
2429
|
+
return false;
|
|
2430
|
+
}
|
|
2431
|
+
};
|
|
2432
|
+
const CtrlL = {
|
|
2433
|
+
key: "Ctrl-l",
|
|
2434
|
+
mac: "Cmd-l",
|
|
2435
|
+
run: () => {
|
|
2436
|
+
index.bus.emit(id, index.OPEN_MODALS, "link");
|
|
2437
|
+
return true;
|
|
2438
|
+
}
|
|
2439
|
+
};
|
|
2440
|
+
const CtrlF = {
|
|
2441
|
+
key: "Ctrl-f",
|
|
2442
|
+
mac: "Cmd-f",
|
|
2443
|
+
shift: () => {
|
|
2444
|
+
if (!contentProps.noPrettier) {
|
|
2445
|
+
index.bus.emit(id, index.REPLACE, "prettier");
|
|
2446
|
+
return true;
|
|
2447
|
+
}
|
|
2448
|
+
return false;
|
|
2449
|
+
}
|
|
2450
|
+
};
|
|
2451
|
+
const CtrlT = {
|
|
2452
|
+
any: (_view, e) => {
|
|
2453
|
+
if ((e.ctrlKey || e.metaKey) && e.altKey && e.shiftKey && e.code === "KeyT") {
|
|
2454
|
+
index.bus.emit(id, index.REPLACE, "table");
|
|
2455
|
+
return true;
|
|
2456
|
+
}
|
|
2457
|
+
return false;
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
const CtrlD = {
|
|
2461
|
+
key: "Ctrl-d",
|
|
2462
|
+
mac: "Cmd-d",
|
|
2463
|
+
run: commands.deleteLine,
|
|
2464
|
+
preventDefault: true
|
|
2465
|
+
};
|
|
2466
|
+
return [
|
|
2467
|
+
CtrlB,
|
|
2468
|
+
CtrlD,
|
|
2469
|
+
CtrlS,
|
|
2470
|
+
CtrlU,
|
|
2471
|
+
CtrlI,
|
|
2472
|
+
Ctrl1,
|
|
2473
|
+
Ctrl2,
|
|
2474
|
+
Ctrl3,
|
|
2475
|
+
Ctrl4,
|
|
2476
|
+
Ctrl5,
|
|
2477
|
+
Ctrl6,
|
|
2478
|
+
CtrlArrowUp,
|
|
2479
|
+
CtrlArrowDown,
|
|
2480
|
+
CtrlO,
|
|
2481
|
+
CtrlC,
|
|
2482
|
+
CtrlL,
|
|
2483
|
+
CtrlF,
|
|
2484
|
+
CtrlT
|
|
2485
|
+
];
|
|
2486
|
+
};
|
|
2487
|
+
const useCodeMirror = (props2) => {
|
|
2488
|
+
const tabWidth = vue.inject("tabWidth");
|
|
2489
|
+
const editorId = vue.inject("editorId");
|
|
2490
|
+
const theme = vue.inject("theme");
|
|
2491
|
+
const inputWrapperRef = vue.ref();
|
|
2492
|
+
const codeMirrorUt = vue.shallowRef();
|
|
2493
|
+
const languageComp = new state.Compartment(), themeComp = new state.Compartment(), autocompletionComp = new state.Compartment(), historyComp = new state.Compartment(), eventComp = new state.Compartment();
|
|
2494
|
+
const mdEditorCommands = createCommands(editorId, props2);
|
|
2495
|
+
const spelling = vue.ref(false);
|
|
2496
|
+
const pasteHandler = usePasteUpload(props2);
|
|
2497
|
+
const domEventHandlers = {
|
|
2498
|
+
paste: pasteHandler,
|
|
2499
|
+
blur: props2.onBlur,
|
|
2500
|
+
focus: props2.onFocus,
|
|
2501
|
+
drop: props2.onDrop,
|
|
2502
|
+
compositionstart: () => {
|
|
2503
|
+
console.log("compositionstart");
|
|
2504
|
+
spelling.value = true;
|
|
2505
|
+
},
|
|
2506
|
+
compositionend: (_e, view2) => {
|
|
2507
|
+
console.log("compositionend");
|
|
2508
|
+
spelling.value = false;
|
|
2509
|
+
props2.updateModelValue(view2.state.doc.toString());
|
|
2510
|
+
},
|
|
2511
|
+
input: (e) => {
|
|
2512
|
+
if (props2.onInput) {
|
|
2513
|
+
props2.onInput(e);
|
|
2514
|
+
}
|
|
2515
|
+
const { data } = e;
|
|
2516
|
+
if (props2.maxlength && props2.modelValue.length + data.length > props2.maxlength) {
|
|
2517
|
+
index.bus.emit(editorId, index.ERROR_CATCHER, {
|
|
2518
|
+
name: "overlength",
|
|
2519
|
+
message: "The input text is too long",
|
|
2520
|
+
data
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
const defaultExtensions = [
|
|
2526
|
+
view.keymap.of([...commands.defaultKeymap, ...commands.historyKeymap, ...mdEditorCommands, commands.indentWithTab]),
|
|
2527
|
+
historyComp.of(commands.history()),
|
|
2528
|
+
languageComp.of(langMarkdown.markdown({ codeLanguages: languageData.languages })),
|
|
2529
|
+
// 横向换行
|
|
2530
|
+
codemirror.EditorView.lineWrapping,
|
|
2531
|
+
codemirror.EditorView.updateListener.of((update) => {
|
|
2532
|
+
if (update.docChanged) {
|
|
2533
|
+
props2.onChange(update.state.doc.toString());
|
|
2534
|
+
if (!spelling.value) {
|
|
2535
|
+
props2.updateModelValue(update.state.doc.toString());
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
}),
|
|
2539
|
+
eventComp.of(codemirror.EditorView.domEventHandlers(domEventHandlers))
|
|
2540
|
+
];
|
|
2541
|
+
const getExtensions = () => {
|
|
2542
|
+
const extensions = [
|
|
2543
|
+
...defaultExtensions,
|
|
2544
|
+
themeComp.of(theme.value === "light" ? oneLight : oneDark),
|
|
2545
|
+
autocompletionComp.of(createAutocompletion(props2.completions))
|
|
2546
|
+
];
|
|
2547
|
+
return config.configOption.codeMirrorExtensions(theme.value, extensions, [
|
|
2548
|
+
...mdEditorCommands
|
|
2549
|
+
]);
|
|
2550
|
+
};
|
|
2551
|
+
vue.onMounted(() => {
|
|
2552
|
+
const view2 = new codemirror.EditorView({
|
|
2553
|
+
doc: props2.modelValue,
|
|
2554
|
+
parent: inputWrapperRef.value,
|
|
2555
|
+
extensions: [getExtensions()]
|
|
2556
|
+
});
|
|
2557
|
+
const nc = new CodeMirrorUt(view2);
|
|
2558
|
+
codeMirrorUt.value = nc;
|
|
2559
|
+
setTimeout(() => {
|
|
2560
|
+
nc.setTabSize(tabWidth);
|
|
2561
|
+
nc.setDisabled(props2.disabled);
|
|
2562
|
+
nc.setReadOnly(props2.readonly);
|
|
2563
|
+
props2.placeholder && nc.setPlaceholder(props2.placeholder);
|
|
2564
|
+
typeof props2.maxlength === "number" && nc.setMaxLength(props2.maxlength);
|
|
2565
|
+
props2.autofocus && view2.focus();
|
|
2566
|
+
}, 0);
|
|
2567
|
+
index.bus.on(editorId, {
|
|
2568
|
+
name: index.CTRL_Z,
|
|
2569
|
+
callback() {
|
|
2570
|
+
commands.undo(view2);
|
|
2571
|
+
}
|
|
2572
|
+
});
|
|
2573
|
+
index.bus.on(editorId, {
|
|
2574
|
+
name: index.CTRL_SHIFT_Z,
|
|
2575
|
+
callback() {
|
|
2576
|
+
commands.redo(view2);
|
|
2577
|
+
}
|
|
2578
|
+
});
|
|
2579
|
+
index.bus.on(editorId, {
|
|
2580
|
+
name: index.REPLACE,
|
|
2581
|
+
callback(direct, params = {}) {
|
|
2582
|
+
var _a;
|
|
2583
|
+
const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
|
|
2584
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
|
|
2585
|
+
}
|
|
2586
|
+
});
|
|
2587
|
+
index.bus.on(editorId, {
|
|
2588
|
+
name: index.EVENT_LISTENER,
|
|
2589
|
+
callback(handlers) {
|
|
2590
|
+
var _a;
|
|
2591
|
+
const nextDomEventHandlers = {
|
|
2592
|
+
...domEventHandlers
|
|
2593
|
+
};
|
|
2594
|
+
const defaultEventNames = Object.keys(domEventHandlers);
|
|
2595
|
+
for (const eventName in handlers) {
|
|
2596
|
+
const en = eventName;
|
|
2597
|
+
if (defaultEventNames.includes(en)) {
|
|
2598
|
+
nextDomEventHandlers[en] = (e, v) => {
|
|
2599
|
+
handlers[en](e, v);
|
|
2600
|
+
if (!e.defaultPrevented) {
|
|
2601
|
+
domEventHandlers[en](e, v);
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
} else {
|
|
2605
|
+
nextDomEventHandlers[en] = handlers[en];
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
|
|
2609
|
+
effects: eventComp.reconfigure(
|
|
2610
|
+
codemirror.EditorView.domEventHandlers(nextDomEventHandlers)
|
|
2611
|
+
)
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
});
|
|
2615
|
+
});
|
|
2616
|
+
vue.watch(
|
|
2617
|
+
theme,
|
|
2618
|
+
() => {
|
|
2619
|
+
var _a;
|
|
2620
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
|
|
2621
|
+
effects: themeComp.reconfigure(theme.value === "light" ? oneLight : oneDark)
|
|
2622
|
+
});
|
|
2623
|
+
},
|
|
2624
|
+
{
|
|
2625
|
+
deep: true
|
|
2626
|
+
}
|
|
2627
|
+
);
|
|
2628
|
+
vue.watch(
|
|
2629
|
+
() => props2.completions,
|
|
2630
|
+
() => {
|
|
2631
|
+
var _a;
|
|
2632
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
|
|
2633
|
+
effects: autocompletionComp.reconfigure(createAutocompletion(props2.completions))
|
|
2634
|
+
});
|
|
2635
|
+
},
|
|
2636
|
+
{
|
|
2637
|
+
deep: true
|
|
2638
|
+
}
|
|
2639
|
+
);
|
|
2640
|
+
vue.watch(
|
|
2641
|
+
() => props2.modelValue,
|
|
2642
|
+
() => {
|
|
2643
|
+
var _a, _b;
|
|
2644
|
+
if (((_a = codeMirrorUt.value) == null ? void 0 : _a.getValue()) !== props2.modelValue) {
|
|
2645
|
+
(_b = codeMirrorUt.value) == null ? void 0 : _b.setValue(props2.modelValue);
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
);
|
|
2649
|
+
vue.watch(
|
|
2650
|
+
() => props2.placeholder,
|
|
2651
|
+
() => {
|
|
2652
|
+
var _a;
|
|
2653
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.setPlaceholder(props2.placeholder);
|
|
2654
|
+
}
|
|
2655
|
+
);
|
|
2656
|
+
vue.watch(
|
|
2657
|
+
() => props2.disabled,
|
|
2658
|
+
() => {
|
|
2659
|
+
var _a;
|
|
2660
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.setDisabled(props2.disabled);
|
|
2661
|
+
}
|
|
2662
|
+
);
|
|
2663
|
+
vue.watch(
|
|
2664
|
+
() => props2.readonly,
|
|
2665
|
+
() => {
|
|
2666
|
+
var _a;
|
|
2667
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.setDisabled(props2.readonly);
|
|
2668
|
+
}
|
|
2669
|
+
);
|
|
2670
|
+
vue.watch(
|
|
2671
|
+
() => props2.maxlength,
|
|
2672
|
+
() => {
|
|
2673
|
+
var _a;
|
|
2674
|
+
if (props2.maxlength) {
|
|
2675
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.setMaxLength(props2.maxlength);
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
);
|
|
2679
|
+
return {
|
|
2680
|
+
inputWrapperRef,
|
|
2681
|
+
codeMirrorUt,
|
|
2682
|
+
resetHistory() {
|
|
2683
|
+
var _a, _b;
|
|
2684
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
|
|
2685
|
+
effects: historyComp.reconfigure([])
|
|
2686
|
+
});
|
|
2687
|
+
(_b = codeMirrorUt.value) == null ? void 0 : _b.view.dispatch({
|
|
2688
|
+
effects: historyComp.reconfigure(commands.history())
|
|
2689
|
+
});
|
|
2690
|
+
}
|
|
2691
|
+
};
|
|
2692
|
+
};
|
|
2693
|
+
const useResize = (props2, contentRef, resizeRef) => {
|
|
2694
|
+
const state2 = vue.reactive({
|
|
2695
|
+
resizedWidth: props2.inputBoxWitdh
|
|
2696
|
+
});
|
|
2697
|
+
const inputWrapperStyle = vue.reactive({
|
|
2698
|
+
width: props2.inputBoxWitdh
|
|
2699
|
+
});
|
|
2700
|
+
const resizeOperateStyle = vue.reactive({
|
|
2701
|
+
left: props2.inputBoxWitdh,
|
|
2702
|
+
display: "initial"
|
|
2703
|
+
});
|
|
2704
|
+
const resizeMousemove = (e) => {
|
|
2705
|
+
var _a, _b, _c;
|
|
2706
|
+
const maxWidth = ((_a = contentRef.value) == null ? void 0 : _a.offsetWidth) || 0;
|
|
2707
|
+
const contentX = ((_b = contentRef.value) == null ? void 0 : _b.getBoundingClientRect().x) || 0;
|
|
2708
|
+
let nextWidth = e.x - contentX;
|
|
2709
|
+
if (nextWidth < config.MinInputBoxWidth) {
|
|
2710
|
+
nextWidth = config.MinInputBoxWidth;
|
|
2711
|
+
} else if (nextWidth > maxWidth - config.MinInputBoxWidth) {
|
|
2712
|
+
nextWidth = maxWidth - config.MinInputBoxWidth;
|
|
2713
|
+
}
|
|
2714
|
+
const ibw = `${nextWidth}px`;
|
|
2715
|
+
inputWrapperStyle.width = ibw;
|
|
2716
|
+
resizeOperateStyle.left = ibw;
|
|
2717
|
+
state2.resizedWidth = ibw;
|
|
2718
|
+
(_c = props2.onInputBoxWitdhChange) == null ? void 0 : _c.call(props2, ibw);
|
|
2719
|
+
};
|
|
2720
|
+
const resizeMousedown = () => {
|
|
2721
|
+
document.addEventListener("mousemove", resizeMousemove);
|
|
2722
|
+
};
|
|
2723
|
+
const resizeMouseup = () => {
|
|
2724
|
+
document.removeEventListener("mousemove", resizeMousemove);
|
|
2725
|
+
};
|
|
2726
|
+
vue.onMounted(() => {
|
|
2727
|
+
var _a;
|
|
2728
|
+
(_a = resizeRef.value) == null ? void 0 : _a.addEventListener("mousedown", resizeMousedown);
|
|
2729
|
+
document.addEventListener("mouseup", resizeMouseup);
|
|
2730
|
+
});
|
|
2731
|
+
vue.onBeforeUnmount(() => {
|
|
2732
|
+
var _a, _b;
|
|
2733
|
+
(_a = resizeRef.value) == null ? void 0 : _a.removeEventListener("mousedown", resizeMousedown);
|
|
2734
|
+
(_b = resizeRef.value) == null ? void 0 : _b.removeEventListener("mouseup", resizeMouseup);
|
|
2735
|
+
});
|
|
2736
|
+
vue.watch(
|
|
2737
|
+
() => props2.inputBoxWitdh,
|
|
2738
|
+
(nVal) => {
|
|
2739
|
+
if (nVal) {
|
|
2740
|
+
inputWrapperStyle.width = nVal;
|
|
2741
|
+
resizeOperateStyle.left = nVal;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
);
|
|
2745
|
+
vue.watch(
|
|
2746
|
+
[vue.toRef(props2.setting, "htmlPreview"), vue.toRef(props2.setting, "preview")],
|
|
2747
|
+
() => {
|
|
2748
|
+
if (!props2.setting.htmlPreview && !props2.setting.preview) {
|
|
2749
|
+
inputWrapperStyle.width = "100%";
|
|
2750
|
+
resizeOperateStyle.display = "none";
|
|
2751
|
+
} else {
|
|
2752
|
+
inputWrapperStyle.width = state2.resizedWidth;
|
|
2753
|
+
resizeOperateStyle.display = "initial";
|
|
2754
|
+
}
|
|
2755
|
+
},
|
|
2756
|
+
{
|
|
2757
|
+
immediate: true
|
|
2758
|
+
}
|
|
2759
|
+
);
|
|
2760
|
+
return { inputWrapperStyle, resizeOperateStyle };
|
|
2761
|
+
};
|
|
2762
|
+
const Content = /* @__PURE__ */ vue.defineComponent({
|
|
2763
|
+
name: "MDEditorContent",
|
|
2764
|
+
props: MdPreview.contentProps,
|
|
2765
|
+
setup(props2, ctx) {
|
|
2766
|
+
const editorId = vue.inject("editorId");
|
|
2767
|
+
const html = vue.ref("");
|
|
2768
|
+
const contentRef = vue.ref();
|
|
2769
|
+
const resizeRef = vue.ref();
|
|
2770
|
+
const {
|
|
2771
|
+
inputWrapperRef,
|
|
2772
|
+
codeMirrorUt,
|
|
2773
|
+
resetHistory
|
|
2774
|
+
} = useCodeMirror(props2);
|
|
2775
|
+
const {
|
|
2776
|
+
inputWrapperStyle,
|
|
2777
|
+
resizeOperateStyle
|
|
2778
|
+
} = useResize(props2, contentRef, resizeRef);
|
|
2779
|
+
useAutoScroll(props2, html, codeMirrorUt);
|
|
2780
|
+
ctx.expose({
|
|
2781
|
+
getSelectedText() {
|
|
2782
|
+
var _a;
|
|
2783
|
+
return (_a = codeMirrorUt.value) == null ? void 0 : _a.getSelectedText();
|
|
2784
|
+
},
|
|
2785
|
+
focus(options) {
|
|
2786
|
+
var _a;
|
|
2787
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.focus(options);
|
|
2788
|
+
},
|
|
2789
|
+
resetHistory
|
|
2790
|
+
});
|
|
2791
|
+
return () => {
|
|
2792
|
+
return vue.createVNode("div", {
|
|
2793
|
+
"class": `${config.prefix}-content${props2.setting.htmlPreview || props2.setting.preview ? " has-preview" : ""}`,
|
|
2794
|
+
"ref": contentRef
|
|
2795
|
+
}, [vue.createVNode("div", {
|
|
2796
|
+
"class": `${config.prefix}-input-wrapper`,
|
|
2797
|
+
"style": inputWrapperStyle,
|
|
2798
|
+
"ref": inputWrapperRef
|
|
2799
|
+
}, null), (props2.setting.htmlPreview || props2.setting.preview) && vue.createVNode("div", {
|
|
2800
|
+
"class": `${config.prefix}-resize-operate`,
|
|
2801
|
+
"style": resizeOperateStyle,
|
|
2802
|
+
"ref": resizeRef
|
|
2803
|
+
}, null), vue.createVNode(MdPreview.ContentPreview, {
|
|
2804
|
+
"modelValue": props2.modelValue,
|
|
2805
|
+
"setting": props2.setting,
|
|
2806
|
+
"onHtmlChanged": (html_) => {
|
|
2807
|
+
html.value = html_;
|
|
2808
|
+
props2.onHtmlChanged(html_);
|
|
2809
|
+
},
|
|
2810
|
+
"onGetCatalog": props2.onGetCatalog,
|
|
2811
|
+
"mdHeadingId": props2.mdHeadingId,
|
|
2812
|
+
"noMermaid": props2.noMermaid,
|
|
2813
|
+
"sanitize": props2.sanitize,
|
|
2814
|
+
"noKatex": props2.noKatex,
|
|
2815
|
+
"formatCopiedText": props2.formatCopiedText,
|
|
2816
|
+
"noHighlight": props2.noHighlight,
|
|
2817
|
+
"noImgZoomIn": props2.noImgZoomIn,
|
|
2818
|
+
"sanitizeMermaid": props2.sanitizeMermaid
|
|
2819
|
+
}, null), props2.catalogVisible && vue.createVNode(MdCatalog, {
|
|
2820
|
+
"theme": props2.theme,
|
|
2821
|
+
"class": `${config.prefix}-catalog-editor`,
|
|
2822
|
+
"editorId": editorId,
|
|
2823
|
+
"mdHeadingId": props2.mdHeadingId,
|
|
2824
|
+
"key": "internal-catalog"
|
|
2825
|
+
}, null)]);
|
|
2826
|
+
};
|
|
2827
|
+
}
|
|
2828
|
+
});
|
|
2829
|
+
const MarkdownTotal = /* @__PURE__ */ vue.defineComponent({
|
|
2830
|
+
props: {
|
|
2831
|
+
modelValue: {
|
|
2832
|
+
type: String,
|
|
2833
|
+
default: ""
|
|
2834
|
+
}
|
|
2835
|
+
},
|
|
2836
|
+
setup(props2) {
|
|
2837
|
+
const ult = vue.inject("usedLanguageText");
|
|
2838
|
+
return () => {
|
|
2839
|
+
var _a, _b;
|
|
2840
|
+
return vue.createVNode("div", {
|
|
2841
|
+
"class": `${config.prefix}-footer-item`
|
|
2842
|
+
}, [vue.createVNode("label", {
|
|
2843
|
+
"class": `${config.prefix}-footer-label`
|
|
2844
|
+
}, [`${(_a = ult.value.footer) == null ? void 0 : _a.markdownTotal}:`]), vue.createVNode("span", null, [((_b = props2.modelValue) == null ? void 0 : _b.length) || 0])]);
|
|
2845
|
+
};
|
|
2846
|
+
}
|
|
2847
|
+
});
|
|
2848
|
+
const props$2 = {
|
|
2849
|
+
checked: {
|
|
2850
|
+
type: Boolean,
|
|
2851
|
+
default: false
|
|
2852
|
+
},
|
|
2853
|
+
onChange: {
|
|
2854
|
+
type: Function,
|
|
2855
|
+
default: () => {
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
};
|
|
2859
|
+
const Checkbox = /* @__PURE__ */ vue.defineComponent({
|
|
2860
|
+
props: props$2,
|
|
2861
|
+
setup(props2) {
|
|
2862
|
+
return () => {
|
|
2863
|
+
return vue.createVNode("div", {
|
|
2864
|
+
"class": [`${config.prefix}-checkbox`, props2.checked && `${config.prefix}-checkbox-checked`],
|
|
2865
|
+
"onClick": () => {
|
|
2866
|
+
props2.onChange(!props2.checked);
|
|
2867
|
+
}
|
|
2868
|
+
}, null);
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
});
|
|
2872
|
+
const props$1 = {
|
|
2873
|
+
scrollAuto: {
|
|
2874
|
+
type: Boolean
|
|
2875
|
+
},
|
|
2876
|
+
onScrollAutoChange: {
|
|
2877
|
+
type: Function,
|
|
2878
|
+
default: () => {
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
};
|
|
2882
|
+
const ScrollAuto = /* @__PURE__ */ vue.defineComponent({
|
|
2883
|
+
props: props$1,
|
|
2884
|
+
setup(props2) {
|
|
2885
|
+
const ult = vue.inject("usedLanguageText");
|
|
2886
|
+
return () => {
|
|
2887
|
+
var _a;
|
|
2888
|
+
return vue.createVNode("div", {
|
|
2889
|
+
"class": `${config.prefix}-footer-item`
|
|
2890
|
+
}, [vue.createVNode("label", {
|
|
2891
|
+
"class": `${config.prefix}-footer-label`,
|
|
2892
|
+
"onClick": () => {
|
|
2893
|
+
props2.onScrollAutoChange(!props2.scrollAuto);
|
|
2894
|
+
}
|
|
2895
|
+
}, [(_a = ult.value.footer) == null ? void 0 : _a.scrollAuto]), vue.createVNode(Checkbox, {
|
|
2896
|
+
"checked": props2.scrollAuto,
|
|
2897
|
+
"onChange": props2.onScrollAutoChange
|
|
2898
|
+
}, null)]);
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
const props = {
|
|
2903
|
+
modelValue: {
|
|
2904
|
+
type: String,
|
|
2905
|
+
default: ""
|
|
2906
|
+
},
|
|
2907
|
+
footers: {
|
|
2908
|
+
type: Array,
|
|
2909
|
+
default: []
|
|
2910
|
+
},
|
|
2911
|
+
scrollAuto: {
|
|
2912
|
+
type: Boolean
|
|
2913
|
+
},
|
|
2914
|
+
onScrollAutoChange: {
|
|
2915
|
+
type: Function,
|
|
2916
|
+
default: () => {
|
|
2917
|
+
}
|
|
2918
|
+
},
|
|
2919
|
+
defFooters: {
|
|
2920
|
+
type: Object
|
|
2921
|
+
}
|
|
2922
|
+
};
|
|
2923
|
+
const Footer = /* @__PURE__ */ vue.defineComponent({
|
|
2924
|
+
name: "MDEditorFooter",
|
|
2925
|
+
props,
|
|
2926
|
+
setup(props2) {
|
|
2927
|
+
const splitedItems = vue.computed(() => {
|
|
2928
|
+
const moduleSplitIndex = props2.footers.indexOf("=");
|
|
2929
|
+
const barLeft = moduleSplitIndex === -1 ? props2.footers : props2.footers.slice(0, moduleSplitIndex);
|
|
2930
|
+
const barRight = moduleSplitIndex === -1 ? [] : props2.footers.slice(moduleSplitIndex, Number.MAX_SAFE_INTEGER);
|
|
2931
|
+
return [barLeft, barRight];
|
|
2932
|
+
});
|
|
2933
|
+
const footerRender = (name) => {
|
|
2934
|
+
if (config.allFooter.includes(name)) {
|
|
2935
|
+
switch (name) {
|
|
2936
|
+
case "markdownTotal": {
|
|
2937
|
+
return vue.createVNode(MarkdownTotal, {
|
|
2938
|
+
"modelValue": props2.modelValue
|
|
2939
|
+
}, null);
|
|
2940
|
+
}
|
|
2941
|
+
case "scrollSwitch": {
|
|
2942
|
+
return vue.createVNode(ScrollAuto, {
|
|
2943
|
+
"scrollAuto": props2.scrollAuto,
|
|
2944
|
+
"onScrollAutoChange": props2.onScrollAutoChange
|
|
2945
|
+
}, null);
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
} else if (props2.defFooters instanceof Array) {
|
|
2949
|
+
return props2.defFooters[name] || "";
|
|
2950
|
+
} else if (props2.defFooters && props2.defFooters.children instanceof Array) {
|
|
2951
|
+
return props2.defFooters.children[name] || "";
|
|
2952
|
+
} else {
|
|
2953
|
+
return "";
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
return () => {
|
|
2957
|
+
const LeftFooter = splitedItems.value[0].map((name) => footerRender(name));
|
|
2958
|
+
const RightFooter = splitedItems.value[1].map((name) => footerRender(name));
|
|
2959
|
+
return vue.createVNode("div", {
|
|
2960
|
+
"class": `${config.prefix}-footer`
|
|
2961
|
+
}, [vue.createVNode("div", {
|
|
2962
|
+
"class": `${config.prefix}-footer-left`
|
|
2963
|
+
}, [LeftFooter]), vue.createVNode("div", {
|
|
2964
|
+
"class": `${config.prefix}-footer-right`
|
|
2965
|
+
}, [RightFooter])]);
|
|
2966
|
+
};
|
|
2967
|
+
}
|
|
2968
|
+
});
|
|
2969
|
+
const Editor = /* @__PURE__ */ vue.defineComponent({
|
|
2970
|
+
name: "MdEditorV3",
|
|
2971
|
+
props: MdPreview.editorProps,
|
|
2972
|
+
emits: MdPreview.editorEmits,
|
|
2973
|
+
setup(props2, ctx) {
|
|
2974
|
+
const {
|
|
2975
|
+
editorId,
|
|
2976
|
+
noKatex,
|
|
2977
|
+
noMermaid,
|
|
2978
|
+
noPrettier,
|
|
2979
|
+
noUploadImg,
|
|
2980
|
+
noHighlight
|
|
2981
|
+
} = props2;
|
|
2982
|
+
const state2 = vue.reactive({
|
|
2983
|
+
scrollAuto: props2.scrollAuto
|
|
2984
|
+
});
|
|
2985
|
+
const codeRef = vue.ref();
|
|
2986
|
+
MdPreview.useOnSave(props2, ctx);
|
|
2987
|
+
MdPreview.useProvide(props2);
|
|
2988
|
+
MdPreview.useExpansion(props2);
|
|
2989
|
+
MdPreview.useErrorCatcher(props2, ctx);
|
|
2990
|
+
const [setting, updateSetting] = MdPreview.useConfig(props2, ctx);
|
|
2991
|
+
const catalogVisible = MdPreview.useCatalog(props2);
|
|
2992
|
+
vue.onBeforeUnmount(() => {
|
|
2993
|
+
index.bus.clear(editorId);
|
|
2994
|
+
});
|
|
2995
|
+
MdPreview.useExpose(props2, ctx, catalogVisible, setting, updateSetting, codeRef);
|
|
2996
|
+
return () => {
|
|
2997
|
+
var _a;
|
|
2998
|
+
const defToolbars = vueTsx.getSlot({
|
|
2999
|
+
props: props2,
|
|
3000
|
+
ctx
|
|
3001
|
+
}, "defToolbars");
|
|
3002
|
+
const defFooters = vueTsx.getSlot({
|
|
3003
|
+
props: props2,
|
|
3004
|
+
ctx
|
|
3005
|
+
}, "defFooters");
|
|
3006
|
+
return vue.createVNode("div", {
|
|
3007
|
+
"id": editorId,
|
|
3008
|
+
"class": [config.prefix, props2.class, props2.theme === "dark" && `${config.prefix}-dark`, setting.fullscreen || setting.pageFullscreen ? `${config.prefix}-fullscreen` : ""],
|
|
3009
|
+
"style": props2.style
|
|
3010
|
+
}, [vue.createVNode(ToolBar, {
|
|
3011
|
+
"noPrettier": noPrettier,
|
|
3012
|
+
"toolbars": props2.toolbars,
|
|
3013
|
+
"toolbarsExclude": props2.toolbarsExclude,
|
|
3014
|
+
"setting": setting,
|
|
3015
|
+
"updateSetting": updateSetting,
|
|
3016
|
+
"tableShape": props2.tableShape,
|
|
3017
|
+
"defToolbars": defToolbars,
|
|
3018
|
+
"noUploadImg": noUploadImg,
|
|
3019
|
+
"showToolbarName": props2.showToolbarName
|
|
3020
|
+
}, null), vue.createVNode(Content, {
|
|
3021
|
+
"ref": codeRef,
|
|
3022
|
+
"modelValue": props2.modelValue,
|
|
3023
|
+
"setting": setting,
|
|
3024
|
+
"mdHeadingId": props2.mdHeadingId,
|
|
3025
|
+
"noMermaid": noMermaid,
|
|
3026
|
+
"noPrettier": noPrettier,
|
|
3027
|
+
"sanitize": props2.sanitize,
|
|
3028
|
+
"placeholder": props2.placeholder,
|
|
3029
|
+
"noKatex": noKatex,
|
|
3030
|
+
"scrollAuto": state2.scrollAuto,
|
|
3031
|
+
"formatCopiedText": props2.formatCopiedText,
|
|
3032
|
+
"autofocus": props2.autoFocus,
|
|
3033
|
+
"disabled": props2.disabled,
|
|
3034
|
+
"readonly": props2.readOnly,
|
|
3035
|
+
"maxlength": props2.maxLength,
|
|
3036
|
+
"autoDetectCode": props2.autoDetectCode,
|
|
3037
|
+
"noHighlight": noHighlight,
|
|
3038
|
+
"updateModelValue": (value) => {
|
|
3039
|
+
ctx.emit("update:modelValue", value);
|
|
3040
|
+
},
|
|
3041
|
+
"onChange": (value) => {
|
|
3042
|
+
if (props2.onChange) {
|
|
3043
|
+
props2.onChange(value);
|
|
3044
|
+
}
|
|
3045
|
+
ctx.emit("onChange", value);
|
|
3046
|
+
},
|
|
3047
|
+
"onHtmlChanged": (html) => {
|
|
3048
|
+
if (props2.onHtmlChanged) {
|
|
3049
|
+
props2.onHtmlChanged(html);
|
|
3050
|
+
}
|
|
3051
|
+
ctx.emit("onHtmlChanged", html);
|
|
3052
|
+
},
|
|
3053
|
+
"onGetCatalog": (list) => {
|
|
3054
|
+
if (props2.onGetCatalog) {
|
|
3055
|
+
props2.onGetCatalog(list);
|
|
3056
|
+
}
|
|
3057
|
+
ctx.emit("onGetCatalog", list);
|
|
3058
|
+
},
|
|
3059
|
+
"onBlur": (e) => {
|
|
3060
|
+
if (props2.onBlur) {
|
|
3061
|
+
props2.onBlur(e);
|
|
3062
|
+
}
|
|
3063
|
+
ctx.emit("onBlur", e);
|
|
3064
|
+
},
|
|
3065
|
+
"onFocus": (e) => {
|
|
3066
|
+
if (props2.onFocus) {
|
|
3067
|
+
props2.onFocus(e);
|
|
3068
|
+
}
|
|
3069
|
+
ctx.emit("onFocus", e);
|
|
3070
|
+
},
|
|
3071
|
+
"onInput": (e) => {
|
|
3072
|
+
if (props2.onInput) {
|
|
3073
|
+
props2.onInput(e);
|
|
3074
|
+
}
|
|
3075
|
+
ctx.emit("onInput", e);
|
|
3076
|
+
},
|
|
3077
|
+
"completions": props2.completions,
|
|
3078
|
+
"catalogVisible": catalogVisible.value,
|
|
3079
|
+
"theme": props2.theme,
|
|
3080
|
+
"noImgZoomIn": props2.noImgZoomIn,
|
|
3081
|
+
"onDrop": (e) => {
|
|
3082
|
+
if (props2.onDrop) {
|
|
3083
|
+
props2.onDrop(e);
|
|
3084
|
+
}
|
|
3085
|
+
ctx.emit("onDrop", e);
|
|
3086
|
+
},
|
|
3087
|
+
"inputBoxWitdh": props2.inputBoxWitdh,
|
|
3088
|
+
"onInputBoxWitdhChange": (width) => {
|
|
3089
|
+
if (props2.onInputBoxWitdhChange) {
|
|
3090
|
+
props2.onInputBoxWitdhChange(width);
|
|
3091
|
+
}
|
|
3092
|
+
ctx.emit("onInputBoxWitdhChange", width);
|
|
3093
|
+
},
|
|
3094
|
+
"sanitizeMermaid": props2.sanitizeMermaid
|
|
3095
|
+
}, null), ((_a = props2.footers) == null ? void 0 : _a.length) > 0 && vue.createVNode(Footer, {
|
|
3096
|
+
"modelValue": props2.modelValue,
|
|
3097
|
+
"footers": props2.footers,
|
|
3098
|
+
"defFooters": defFooters,
|
|
3099
|
+
"scrollAuto": state2.scrollAuto,
|
|
3100
|
+
"onScrollAutoChange": (v) => state2.scrollAuto = v
|
|
3101
|
+
}, null)]);
|
|
3102
|
+
};
|
|
3103
|
+
}
|
|
3104
|
+
});
|
|
3105
|
+
Editor.install = (app) => {
|
|
3106
|
+
app.component(Editor.name, Editor);
|
|
3107
|
+
app.use(NormalToolbar).use(DropdownToolbar.DropdownToolbar).use(ModalToolbar).use(MdCatalog).use(MdPreview.MdPreview);
|
|
3108
|
+
return app;
|
|
3109
|
+
};
|
|
3110
|
+
module.exports = Editor;
|