md-editor-v3 4.8.0 → 4.8.2
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/README.md +8 -2
- package/lib/cjs/MdEditor.cjs +13 -13
- package/lib/cjs/chunks/index.cjs +1 -1
- package/lib/es/MdEditor.mjs +73 -73
- package/lib/es/chunks/index.mjs +1 -1
- package/lib/style.css +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,10 +32,16 @@ Markdown editor for vue3, developed in `jsx` and `typescript`.
|
|
|
32
32
|
yarn add md-editor-v3
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
Use existing extension of language and theme, such as Japanese
|
|
36
36
|
|
|
37
37
|
```shell
|
|
38
|
-
yarn add @vavt/
|
|
38
|
+
yarn add @vavt/cm-extension
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Use existing components of toolbar, such as exporting content as PDF
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
yarn add @vavt/v3-extension
|
|
39
45
|
```
|
|
40
46
|
|
|
41
47
|
For more ways to use or contribute, please refer to: [md-editor-extension](https://github.com/imzbf/md-editor-extension)
|
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ht=Object.defineProperty;var vt=(e,l,o)=>l in e?ht(e,l,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[l]=o;var q=(e,l,o)=>(vt(e,typeof l!="symbol"?l+"":l,o),o);const t=require("vue"),r=require("./chunks/config.cjs"),le=require("@vavt/util"),K=require("./chunks/index2.cjs"),d=require("./chunks/index4.cjs"),pt=require("./chunks/dom.cjs"),x=require("./chunks/index3.cjs"),ee=require("codemirror"),ae=require("@codemirror/view"),Ct=require("@codemirror/language-data"),kt=require("@codemirror/lang-markdown"),E=require("@codemirror/state"),se=require("@codemirror/commands"),re=require("@codemirror/language"),s=require("@lezer/highlight"),xt=require("@codemirror/autocomplete"),P=require("./chunks/index.cjs"),bt=require("./MdCatalog.cjs"),et=require("./chunks/vue-tsx.cjs"),$t=require("./NormalToolbar.cjs"),Nt=require("./ModalToolbar.cjs");require("medium-zoom");require("copy-to-clipboard");require("markdown-it");require("markdown-it-image-figures");require("markdown-it-task-lists");require("lru-cache");const Vt=t.defineComponent({setup(){return()=>t.createVNode("div",{class:`${r.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 u,c,h,V;const l=t.inject("editorId");let o=(c=(u=r.configOption.editorExtensions)==null?void 0:u.screenfull)==null?void 0:c.instance;const a=(V=(h=r.configOption.editorExtensions)==null?void 0:h.screenfull)==null?void 0:V.js,n=t.ref(!1),i=C=>{if(!o){d.bus.emit(l,d.ERROR_CATCHER,{name:"fullscreen",message:"fullscreen is undefined"});return}o.isEnabled?(n.value=!0,(C===void 0?!o.isFullscreen:C)?o.request():o.exit()):console.error("browser does not support screenfull!")},f=()=>{o&&o.isEnabled&&o.on("change",()=>{(n.value||e.setting.fullscreen)&&(n.value=!1,e.updateSetting("fullscreen"))})},g=()=>{o=window.screenfull,f()};return t.onMounted(()=>{if(f(),!o){const C=document.createElement("script");C.src=a||r.screenfullUrl,C.onload=g,C.id=`${r.prefix}-screenfull`,pt.appendHandler(C,"screenfull")}}),t.onMounted(()=>{d.bus.on(l,{name:d.CHANGE_FULL_SCREEN,callback:i})}),{fullscreenHandler:i}},Tt={tableShape:{type:Array,default:()=>[6,4]},onSelected:{type:Function,default:()=>{}}},Et=t.defineComponent({name:"TableShape",props:Tt,setup(e){const l=t.reactive({x:-1,y:-1});return()=>t.createVNode("div",{class:`${r.prefix}-table-shape`,onMouseleave:()=>{l.x=-1,l.y=-1}},[new Array(e.tableShape[1]).fill("").map((o,a)=>t.createVNode("div",{class:`${r.prefix}-table-shape-row`,key:`table-shape-row-${a}`},[new Array(e.tableShape[0]).fill("").map((n,i)=>t.createVNode("div",{class:`${r.prefix}-table-shape-col`,key:`table-shape-col-${i}`,onMouseenter:()=>{l.x=a,l.y=i},onClick:()=>{e.onSelected(l)}},[t.createVNode("div",{class:[`${r.prefix}-table-shape-col-default`,a<=l.x&&i<=l.y&&`${r.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:()=>{}}},It=t.defineComponent({props:At,setup(e){const l=t.inject("usedLanguageText"),o=t.inject("editorId"),a=t.computed(()=>{var i,f;switch(e.type){case"link":return(i=l.value.linkModalTips)==null?void 0:i.linkTitle;case"image":return(f=l.value.linkModalTips)==null?void 0:f.imageTitle;default:return""}}),n=t.reactive({desc:"",url:""});return t.watch(()=>e.visible,i=>{i||setTimeout(()=>{n.desc="",n.url=""},200)}),()=>t.createVNode(x.MdModal,{title:a.value,visible:e.visible,onClose:e.onCancel},{default:()=>{var i,f,g,u,c;return[t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-desc-${o}`},[(i=l.value.linkModalTips)==null?void 0:i.descLabel]),t.createVNode("input",{placeholder:(f=l.value.linkModalTips)==null?void 0:f.descLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-desc-${o}`,type:"text",value:n.desc,onChange:h=>{n.desc=h.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-url-${o}`},[(g=l.value.linkModalTips)==null?void 0:g.urlLabel]),t.createVNode("input",{placeholder:(u=l.value.linkModalTips)==null?void 0:u.urlLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-url-${o}`,type:"text",value:n.url,onChange:h=>{n.url=h.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:[`${r.prefix}-btn`,`${r.prefix}-btn-row`],type:"button",onClick:()=>{e.onOk(n),n.desc="",n.url=""}},[(c=l.value.linkModalTips)==null?void 0:c.buttonOK])])]}})}}),Lt={visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Mt=t.defineComponent({props:Lt,setup(e){var h,V,C;const l=t.inject("usedLanguageText"),o=t.inject("editorId");let a=(C=(V=(h=r.configOption)==null?void 0:h.editorExtensions)==null?void 0:V.cropper)==null?void 0:C.instance;const n=t.ref(),i=t.ref(),f=t.ref(),g=t.reactive({cropperInited:!1,imgSelected:!1,imgSrc:"",isFullscreen:!1});let u=null;t.watch(()=>e.visible,()=>{e.visible&&!g.cropperInited&&(a=a||window.Cropper,n.value.onchange=()=>{if(!a){d.bus.emit(o,d.ERROR_CATCHER,{name:"Cropper",message:"Cropper is undefined"});return}const m=n.value.files||[];if(g.imgSelected=!0,(m==null?void 0:m.length)>0){const p=new FileReader;p.onload=b=>{g.imgSrc=b.target.result,t.nextTick(()=>{u=new a(i.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`})})},p.readAsDataURL(m[0])}})}),t.watch(()=>[g.imgSelected],()=>{f.value.style=""}),t.watch(()=>g.isFullscreen,()=>{t.nextTick(()=>{u==null||u.destroy(),f.value.style="",i.value&&(u=new a(i.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`}))})});const c=()=>{u.clear(),u.destroy(),u=null,n.value.value="",g.imgSelected=!1};return()=>{var m;return t.createVNode(x.MdModal,{class:`${r.prefix}-modal-clip`,title:(m=l.value.clipModalTips)==null?void 0:m.title,visible:e.visible,onClose:e.onCancel,showAdjust:!0,isFullscreen:g.isFullscreen,onAdjust:p=>{g.isFullscreen=p},width:"668px",height:"421px"},{default:()=>{var p,b;return[t.createVNode("div",{class:`${r.prefix}-form-item ${r.prefix}-clip`},[t.createVNode("div",{class:`${r.prefix}-clip-main`},[g.imgSelected?t.createVNode("div",{class:`${r.prefix}-clip-cropper`},[t.createVNode("img",{src:g.imgSrc,ref:i,style:{display:"none"},alt:""},null),t.createVNode("div",{class:`${r.prefix}-clip-delete`,onClick:c},[t.createVNode(x.Icon,{name:"delete"},null)])]):t.createVNode("div",{class:`${r.prefix}-clip-upload`,onClick:()=>{n.value.click()}},[t.createVNode(x.Icon,{name:"upload"},null)])]),t.createVNode("div",{class:`${r.prefix}-clip-preview`},[t.createVNode("div",{class:`${r.prefix}-clip-preview-target`,ref:f},null)])]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:`${r.prefix}-btn`,type:"button",onClick:()=>{if(u){const v=u.getCroppedCanvas();d.bus.emit(o,d.UPLOAD_IMAGE,[d.base642File(v.toDataURL("image/png"))],e.onOk),c()}}},[((p=l.value.clipModalTips)==null?void 0:p.buttonUpload)||((b=l.value.linkModalTips)==null?void 0:b.buttonOK)])]),t.createVNode("input",{ref:n,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:()=>{}}},Dt=t.defineComponent({props:Rt,setup(e){return()=>t.createVNode(t.Fragment,null,[t.createVNode(It,{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)])}}),Ht=t.defineComponent({name:"MDEditorToolbar",props:wt,setup(e){const l=t.inject("editorId"),o=t.inject("usedLanguageText"),a=t.inject("theme"),n=t.inject("language"),{fullscreenHandler:i}=yt(e),f=`${l}-toolbar-wrapper`,g=t.ref(),u=t.reactive({title:!1,catalog:!1,image:!1,table:!1,mermaid:!1,katex:!1}),c=(v,k)=>{d.bus.emit(l,d.REPLACE,v,k)},h=t.reactive({type:"link",linkVisible:!1,clipVisible:!1}),V=t.ref();t.onMounted(()=>{d.bus.on(l,{name:d.OPEN_MODALS,callback(v){h.type=v,h.linkVisible=!0}})});const C=t.computed(()=>{const v=e.toolbars.filter(S=>!e.toolbarsExclude.includes(S)),k=v.indexOf("="),N=k===-1?v:v.slice(0,k+1),w=k===-1?[]:v.slice(k,Number.MAX_SAFE_INTEGER);return[N,w]}),m=t.ref(),p=()=>{d.bus.emit(l,d.UPLOAD_IMAGE,Array.from(m.value.files||[])),m.value.value=""};t.onMounted(()=>{m.value.addEventListener("change",p)});const b=v=>{var k,N,w,S,A,Z,X,y,T,F,B,R,L,M,D,_,W,ne,Y,G,j,J,U,H,O,Q,ie,ge,be,he,ve,pe,Ce,ke,xe,$e,Ne,Ve,we,ye,Te,Ee,Se,Ae,Ie,Le,Me,Re,De,He,Oe,Pe,Be,Fe,qe,_e,We,je,Ue,Ge,ze,Ke,Ze,Xe,Ye,Je,Qe;if(r.allToolbar.includes(v))switch(v){case"-":return t.createVNode(Vt,null,null);case"bold":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(k=o.value.toolbarTips)==null?void 0:k.bold,onClick:()=>{c("bold")}},[t.createVNode(x.Icon,{name:"bold"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(N=o.value.toolbarTips)==null?void 0:N.bold])]);case"underline":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(w=o.value.toolbarTips)==null?void 0:w.underline,onClick:()=>{c("underline")}},[t.createVNode(x.Icon,{name:"underline"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(S=o.value.toolbarTips)==null?void 0:S.underline])]);case"italic":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(A=o.value.toolbarTips)==null?void 0:A.italic,onClick:()=>{c("italic")}},[t.createVNode(x.Icon,{name:"italic"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Z=o.value.toolbarTips)==null?void 0:Z.italic])]);case"strikeThrough":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(X=o.value.toolbarTips)==null?void 0:X.strikeThrough,onClick:()=>{c("strikeThrough")}},[t.createVNode(x.Icon,{name:"strike-through"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(y=o.value.toolbarTips)==null?void 0:y.strikeThrough])]);case"title":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.title,onChange:$=>{u.title=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{c("h1")}},[(T=o.value.titleItem)==null?void 0:T.h1]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{c("h2")}},[(F=o.value.titleItem)==null?void 0:F.h2]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{c("h3")}},[(B=o.value.titleItem)==null?void 0:B.h3]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{c("h4")}},[(R=o.value.titleItem)==null?void 0:R.h4]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{c("h5")}},[(L=o.value.titleItem)==null?void 0:L.h5]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{c("h6")}},[(M=o.value.titleItem)==null?void 0:M.h6])])},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.title},[t.createVNode(x.Icon,{name:"title"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.title])])]}});case"sub":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(D=o.value.toolbarTips)==null?void 0:D.sub,onClick:()=>{c("sub")}},[t.createVNode(x.Icon,{name:"sub"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(_=o.value.toolbarTips)==null?void 0:_.sub])]);case"sup":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(W=o.value.toolbarTips)==null?void 0:W.sup,onClick:()=>{c("sup")}},[t.createVNode(x.Icon,{name:"sup"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ne=o.value.toolbarTips)==null?void 0:ne.sup])]);case"quote":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Y=o.value.toolbarTips)==null?void 0:Y.quote,onClick:()=>{c("quote")}},[t.createVNode(x.Icon,{name:"quote"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(G=o.value.toolbarTips)==null?void 0:G.quote])]);case"unorderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(j=o.value.toolbarTips)==null?void 0:j.unorderedList,onClick:()=>{c("unorderedList")}},[t.createVNode(x.Icon,{name:"unordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(J=o.value.toolbarTips)==null?void 0:J.unorderedList])]);case"orderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(U=o.value.toolbarTips)==null?void 0:U.orderedList,onClick:()=>{c("orderedList")}},[t.createVNode(x.Icon,{name:"ordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(H=o.value.toolbarTips)==null?void 0:H.orderedList])]);case"task":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(O=o.value.toolbarTips)==null?void 0:O.task,onClick:()=>{c("task")}},[t.createVNode(x.Icon,{name:"task"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Q=o.value.toolbarTips)==null?void 0:Q.task])]);case"codeRow":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ie=o.value.toolbarTips)==null?void 0:ie.codeRow,onClick:()=>{c("codeRow")}},[t.createVNode(x.Icon,{name:"code-row"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ge=o.value.toolbarTips)==null?void 0:ge.codeRow])]);case"code":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(be=o.value.toolbarTips)==null?void 0:be.code,onClick:()=>{c("code")}},[t.createVNode(x.Icon,{name:"code"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(he=o.value.toolbarTips)==null?void 0:he.code])]);case"link":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ve=o.value.toolbarTips)==null?void 0:ve.link,onClick:()=>{h.type="link",h.linkVisible=!0}},[t.createVNode(x.Icon,{name:"link"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(pe=o.value.toolbarTips)==null?void 0:pe.link])]);case"image":return e.noUploadImg?t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ce=o.value.toolbarTips)==null?void 0:Ce.image,onClick:()=>{h.type="image",h.linkVisible=!0}},[t.createVNode(x.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ke=o.value.toolbarTips)==null?void 0:ke.image])]):t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.image,onChange:$=>{u.image=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{h.type="image",h.linkVisible=!0}},[(xe=o.value.imgTitleItem)==null?void 0:xe.link]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{m.value.click()}},[($e=o.value.imgTitleItem)==null?void 0:$e.upload]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{h.clipVisible=!0}},[(Ne=o.value.imgTitleItem)==null?void 0:Ne.clip2upload])])},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.image},[t.createVNode(x.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.image])])]}});case"table":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.table,onChange:$=>{u.table=$},key:"bar-table",overlay:t.createVNode(St,{tableShape:e.tableShape,onSelected:$=>{c("table",{selectedShape:$})}},null)},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.table},[t.createVNode(x.Icon,{name:"table"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.table])])]}});case"revoke":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ve=o.value.toolbarTips)==null?void 0:Ve.revoke,onClick:()=>{d.bus.emit(l,d.CTRL_Z)}},[t.createVNode(x.Icon,{name:"revoke"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(we=o.value.toolbarTips)==null?void 0:we.revoke])]);case"next":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ye=o.value.toolbarTips)==null?void 0:ye.next,onClick:()=>{d.bus.emit(l,d.CTRL_SHIFT_Z)}},[t.createVNode(x.Icon,{name:"next"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Te=o.value.toolbarTips)==null?void 0:Te.next])]);case"save":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ee=o.value.toolbarTips)==null?void 0:Ee.save,onClick:()=>{d.bus.emit(l,d.ON_SAVE)}},[t.createVNode(x.Icon,{name:"baocun"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Se=o.value.toolbarTips)==null?void 0:Se.save])]);case"prettier":return e.noPrettier?"":t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ae=o.value.toolbarTips)==null?void 0:Ae.prettier,onClick:()=>{c("prettier")}},[t.createVNode(x.Icon,{name:"prettier"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Ie=o.value.toolbarTips)==null?void 0:Ie.prettier])]);case"pageFullscreen":return!e.setting.fullscreen&&t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Le=o.value.toolbarTips)==null?void 0:Le.pageFullscreen,onClick:()=>{e.updateSetting("pageFullscreen")}},[t.createVNode(x.Icon,{name:e.setting.pageFullscreen?"suoxiao":"fangda"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Me=o.value.toolbarTips)==null?void 0:Me.pageFullscreen])]);case"fullscreen":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Re=o.value.toolbarTips)==null?void 0:Re.fullscreen,onClick:()=>{i()}},[t.createVNode(x.Icon,{name:e.setting.fullscreen?"fullscreen-exit":"fullscreen"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(De=o.value.toolbarTips)==null?void 0:De.fullscreen])]);case"preview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(He=o.value.toolbarTips)==null?void 0:He.preview,onClick:()=>{e.updateSetting("preview")}},[t.createVNode(x.Icon,{name:"preview"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Oe=o.value.toolbarTips)==null?void 0:Oe.preview])]);case"htmlPreview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Pe=o.value.toolbarTips)==null?void 0:Pe.htmlPreview,onClick:()=>{e.updateSetting("htmlPreview")}},[t.createVNode(x.Icon,{name:"coding"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Be=o.value.toolbarTips)==null?void 0:Be.htmlPreview])]);case"catalog":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Fe=o.value.toolbarTips)==null?void 0:Fe.catalog,onClick:()=>{d.bus.emit(l,d.CHANGE_CATALOG_VISIBLE)},key:"bar-catalog"},[t.createVNode(x.Icon,{name:"catalog"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(qe=o.value.toolbarTips)==null?void 0:qe.catalog])]);case"github":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(_e=o.value.toolbarTips)==null?void 0:_e.github,onClick:()=>le.linkTo("https://github.com/imzbf/md-editor-v3")},[t.createVNode(x.Icon,{name:"github"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(We=o.value.toolbarTips)==null?void 0:We.github])]);case"mermaid":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.mermaid,onChange:$=>{u.mermaid=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.mermaid=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("flow")}},[(je=o.value.mermaid)==null?void 0:je.flow]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("sequence")}},[(Ue=o.value.mermaid)==null?void 0:Ue.sequence]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("gantt")}},[(Ge=o.value.mermaid)==null?void 0:Ge.gantt]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("class")}},[(ze=o.value.mermaid)==null?void 0:ze.class]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("state")}},[(Ke=o.value.mermaid)==null?void 0:Ke.state]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("pie")}},[(Ze=o.value.mermaid)==null?void 0:Ze.pie]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("relationship")}},[(Xe=o.value.mermaid)==null?void 0:Xe.relationship]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{c("journey")}},[(Ye=o.value.mermaid)==null?void 0:Ye.journey])]),key:"bar-mermaid"},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.mermaid},[t.createVNode(x.Icon,{name:"mermaid"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.mermaid])])]}});case"katex":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.katex,onChange:$=>{u.katex=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.katex=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-katex`,onClick:()=>{c("katexInline")}},[(Je=o.value.katex)==null?void 0:Je.inline]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-katex`,onClick:()=>{c("katexBlock")}},[(Qe=o.value.katex)==null?void 0:Qe.block])]),key:"bar-katex"},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.katex},[t.createVNode(x.Icon,{name:"formula"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.katex])])]}})}else if(e.defToolbars instanceof Array){const $=e.defToolbars[v];return $?t.cloneVNode($,{theme:a.value,language:n.value,insert(ue){d.bus.emit(l,d.REPLACE,"universal",{generate:ue})}}):""}else if(e.defToolbars&&e.defToolbars.children instanceof Array){const $=e.defToolbars.children[v];return $?t.cloneVNode($,{theme:a.value,language:n.value,insert(ue){d.bus.emit(l,d.REPLACE,"universal",{generate:ue})}}):""}else return""};return t.watch(()=>e.toolbars,()=>{t.nextTick(()=>{g.value&&le.draggingScroll(g.value)})},{immediate:!0}),()=>{const v=C.value[0].map(N=>b(N)),k=C.value[1].map(N=>b(N));return t.createVNode(t.Fragment,null,[e.toolbars.length>0&&t.createVNode("div",{class:`${r.prefix}-toolbar-wrapper`,ref:g,id:f},[t.createVNode("div",{class:[`${r.prefix}-toolbar`,e.showToolbarName&&`${r.prefix}-stn`]},[t.createVNode("div",{class:`${r.prefix}-toolbar-left`,ref:V},[v]),t.createVNode("div",{class:`${r.prefix}-toolbar-right`},[k])])]),t.createVNode("input",{ref:m,accept:"image/*",type:"file",multiple:!0,style:{display:"none"}},null),t.createVNode(Dt,{linkVisible:h.linkVisible,clipVisible:h.clipVisible,type:h.type,onCancel:()=>{h.linkVisible=!1,h.clipVisible=!1},onOk:N=>{N&&c(h.type,{desc:N.desc,url:N.url}),h.linkVisible=!1,h.clipVisible=!1}},null)])}}}),Ot=(e,l)=>{const o=le.debounce(()=>{e.removeEventListener("scroll",a),e.addEventListener("scroll",a),l.removeEventListener("scroll",a),l.addEventListener("scroll",a)},50),a=n=>{const i=e.clientHeight,f=l.clientHeight,g=e.scrollHeight,u=l.scrollHeight,c=(g-i)/(u-f);n.target===e?(l.removeEventListener("scroll",a),l.scrollTo({top:e.scrollTop/c}),o()):(e.removeEventListener("scroll",a),e.scrollTo({top:l.scrollTop*c}),o())};return[()=>{o().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",a),l.removeEventListener("scroll",a)}]},Pt=(e,l,o)=>{const{view:a}=o,n=le.createSmoothScroll(),i=C=>a.lineBlockAt(a.state.doc.line(C).from).top,f=C=>a.lineBlockAt(a.state.doc.line(C).from).height;let g=[];const u=()=>{g=[];const C=Array.from(l.querySelectorAll("[data-line]")).map(v=>Number(v.dataset.line)+1),{lines:m}=a.state.doc;let p=1,b=C.shift()??m;for(let v=1;v<=m;v++)v===b&&(p=v,b=C.shift()||m+1),g.push({start:p,end:b-1})};let c=0,h=0;const V=le.throttle(C=>{var k,N,w,S,A,Z,X;if(!((k=l.firstElementChild)!=null&&k.firstElementChild))return;const m=a.lineBlockAtHeight(a.scrollDOM.scrollTop),{number:p}=a.state.doc.lineAt(m.from);if(p>g.length||a.state.doc.lines<g[g.length-1].end)return;let b=+getComputedStyle(l).paddingTop.replace("px","");const v=+getComputedStyle(l).paddingBottom.replace("px","");if(C.target===e){if(h!==0)return;c++;const y=g[p-1];let T=i(y.end)+f(y.end),F=0;const B=i(y.start),R=l.querySelector(`[data-line="${y.start-1}"]`)||((N=l.firstElementChild)==null?void 0:N.firstElementChild),L=l.querySelector(`[data-line="${y.end}"]`)||((w=l.lastElementChild)==null?void 0:w.lastElementChild);let M=0,D=0;B===0?R===L?(b=0,T=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight,F=a.scrollDOM.scrollTop/T,M=L.offsetTop+L.offsetHeight-l.clientHeight):(F=a.scrollDOM.scrollTop/T,M=L.offsetTop):T>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(F=(a.scrollDOM.scrollTop-B)/(a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight-B),D=R.offsetTop,M=l.scrollHeight-l.clientHeight-D+10):(F=(a.scrollDOM.scrollTop-B)/(T-B),D=R.offsetTop,M=L.offsetTop-D);const _=D-b+M*F;n(l,_,()=>{c--})}else{if(c!==0)return;h++;const y=Array.from(l.querySelectorAll("[data-line]")),T=l.scrollTop,F=l.scrollHeight;let B=y.length===0?1:Math.ceil(Number(y[y.length-1].dataset.line)*(T/F)),R=(S=l.firstElementChild)==null?void 0:S.firstElementChild;for(let H=B;H>=0;H--){const O=l.querySelector(`[data-line="${H}"]`);if(O&&O.offsetTop<=T){R=O,B=H;break}}let L=(A=l.firstElementChild)==null?void 0:A.firstElementChild,M=(Z=l.firstElementChild)==null?void 0:Z.lastElementChild;for(;y.length>0;){const H=y.indexOf(R);if(H+1>=y.length)break;const O=y[H+1];if(H===-1){M=O;break}const Q=R.offsetTop;if(Q>T){if(H===0){L=R,M=O;break}R=y[H-1];continue}const ie=O.offsetTop;if(Q<=T&&ie>T){L=R,M=O;break}R=O}const D=L.offsetTop;let _=M.offsetTop,W=0;const{start:ne,end:Y}=g[Number(L.dataset.line||0)],G=i(ne);let j=i(Y);const J=f(Y);let U=0;L===((X=l.firstElementChild)==null?void 0:X.firstElementChild)?(L===M?(_=M.offsetHeight-l.offsetHeight+b+v,U=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight):U=j+J-G,W=Math.max(T/_,0)):j>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(W=Math.max((T-D)/(l.scrollHeight-D-l.clientHeight),0),j=i(a.state.doc.lines)+f(a.state.doc.lines),U=8+j-G-e.clientHeight):(W=Math.max((T-D)/(_-D),0),U=j+J-G),n(e,G+U*W,()=>{h--})}},10);return[()=>{u(),e.addEventListener("scroll",V),l.addEventListener("scroll",V),e.dispatchEvent(new Event("scroll"))},()=>{g=[],e.removeEventListener("scroll",V),l.removeEventListener("scroll",V)}]},Bt=(e,l,o)=>{const a=t.inject("editorId");let n=()=>{},i=()=>{};const f=()=>{n();const g=document.querySelector(`#${a} .cm-scroller`),u=document.querySelector(`[id="${a}-preview-wrapper"][data-show="true"]`),c=document.querySelector(`[id="${a}-html-wrapper"][data-show="true"]`);(u||c)&&([i,n]=(u?Pt:Ot)(g,u||c,o.value)),e.scrollAuto&&i()};t.watch([l,t.toRef(e.setting,"preview"),t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"fullscreen"),t.toRef(e.setting,"pageFullscreen")],()=>{t.nextTick(f)}),t.watch(()=>e.scrollAuto,g=>{g?i():n()}),t.onMounted(f)},Ft=Bt,qt=(e,l,o)=>{var h,V,C,m,p,b;let a="",n=0,i=0,f=!0,g=!1;const u=l.getSelectedText(),c=(h=r.configOption.editorConfig)==null?void 0:h.mermaidTemplate;if(/^h[1-6]{1}$/.test(e)){const v=e.replace(/^h(\d)/,(k,N)=>new Array(Number(N)).fill("#",0,N).join(""));a=`${v} ${u}`,n=v.length+1}else if(e==="prettier"){const v=window.prettier||((C=(V=r.configOption.editorExtensions)==null?void 0:V.prettier)==null?void 0:C.prettierInstance),k=[((m=window.prettierPlugins)==null?void 0:m.markdown)||((b=(p=r.configOption.editorExtensions)==null?void 0:p.prettier)==null?void 0:b.parserMarkdownInstance)];!v||k[0]===void 0?(d.bus.emit(o.editorId,d.ERROR_CATCHER,{name:"prettier",message:"prettier is undefined"}),a=l.getValue()):a=v.format(l.getValue(),{parser:"markdown",plugins:k}),f=!1,g=!0}else switch(e){case"bold":{a=`**${u}**`,n=2,i=-2;break}case"underline":{a=`<u>${u}</u>`,n=3,i=-4;break}case"italic":{a=`*${u}*`,n=1,i=-1;break}case"strikeThrough":{a=`~~${u}~~`,n=2,i=-2;break}case"sub":{a=`<sub>${u}</sub>`,n=5,i=-6;break}case"sup":{a=`<sup>${u}</sup>`,n=5,i=-6;break}case"codeRow":{a="`"+u+"`",n=1,i=-1;break}case"quote":{a=`> ${u}`,n=2;break}case"orderedList":{a=`1. ${u}`,n=3;break}case"unorderedList":{a=`- ${u}`,n=2;break}case"task":{a=`- [ ] ${u}`,n=6;break}case"code":{const v=o.text||u||"",k=o.mode||"language";a=`\`\`\`${k}
|
|
1
|
+
"use strict";var ht=Object.defineProperty;var vt=(e,l,o)=>l in e?ht(e,l,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[l]=o;var q=(e,l,o)=>(vt(e,typeof l!="symbol"?l+"":l,o),o);const t=require("vue"),r=require("./chunks/config.cjs"),le=require("@vavt/util"),K=require("./chunks/index2.cjs"),d=require("./chunks/index4.cjs"),pt=require("./chunks/dom.cjs"),x=require("./chunks/index3.cjs"),ee=require("codemirror"),ae=require("@codemirror/view"),Ct=require("@codemirror/language-data"),kt=require("@codemirror/lang-markdown"),E=require("@codemirror/state"),ce=require("@codemirror/commands"),re=require("@codemirror/language"),c=require("@lezer/highlight"),xt=require("@codemirror/autocomplete"),P=require("./chunks/index.cjs"),bt=require("./MdCatalog.cjs"),et=require("./chunks/vue-tsx.cjs"),$t=require("./NormalToolbar.cjs"),Nt=require("./ModalToolbar.cjs");require("medium-zoom");require("copy-to-clipboard");require("markdown-it");require("markdown-it-image-figures");require("markdown-it-task-lists");require("lru-cache");const Vt=t.defineComponent({setup(){return()=>t.createVNode("div",{class:`${r.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 u,s,h,V;const l=t.inject("editorId");let o=(s=(u=r.configOption.editorExtensions)==null?void 0:u.screenfull)==null?void 0:s.instance;const a=(V=(h=r.configOption.editorExtensions)==null?void 0:h.screenfull)==null?void 0:V.js,n=t.ref(!1),i=C=>{if(!o){d.bus.emit(l,d.ERROR_CATCHER,{name:"fullscreen",message:"fullscreen is undefined"});return}o.isEnabled?(n.value=!0,(C===void 0?!o.isFullscreen:C)?o.request():o.exit()):console.error("browser does not support screenfull!")},f=()=>{o&&o.isEnabled&&o.on("change",()=>{(n.value||e.setting.fullscreen)&&(n.value=!1,e.updateSetting("fullscreen"))})},g=()=>{o=window.screenfull,f()};return t.onMounted(()=>{if(f(),!o){const C=document.createElement("script");C.src=a||r.screenfullUrl,C.onload=g,C.id=`${r.prefix}-screenfull`,pt.appendHandler(C,"screenfull")}}),t.onMounted(()=>{d.bus.on(l,{name:d.CHANGE_FULL_SCREEN,callback:i})}),{fullscreenHandler:i}},Tt={tableShape:{type:Array,default:()=>[6,4]},onSelected:{type:Function,default:()=>{}}},Et=t.defineComponent({name:"TableShape",props:Tt,setup(e){const l=t.reactive({x:-1,y:-1});return()=>t.createVNode("div",{class:`${r.prefix}-table-shape`,onMouseleave:()=>{l.x=-1,l.y=-1}},[new Array(e.tableShape[1]).fill("").map((o,a)=>t.createVNode("div",{class:`${r.prefix}-table-shape-row`,key:`table-shape-row-${a}`},[new Array(e.tableShape[0]).fill("").map((n,i)=>t.createVNode("div",{class:`${r.prefix}-table-shape-col`,key:`table-shape-col-${i}`,onMouseenter:()=>{l.x=a,l.y=i},onClick:()=>{e.onSelected(l)}},[t.createVNode("div",{class:[`${r.prefix}-table-shape-col-default`,a<=l.x&&i<=l.y&&`${r.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:()=>{}}},It=t.defineComponent({props:At,setup(e){const l=t.inject("usedLanguageText"),o=t.inject("editorId"),a=t.computed(()=>{var i,f;switch(e.type){case"link":return(i=l.value.linkModalTips)==null?void 0:i.linkTitle;case"image":return(f=l.value.linkModalTips)==null?void 0:f.imageTitle;default:return""}}),n=t.reactive({desc:"",url:""});return t.watch(()=>e.visible,i=>{i||setTimeout(()=>{n.desc="",n.url=""},200)}),()=>t.createVNode(x.MdModal,{title:a.value,visible:e.visible,onClose:e.onCancel},{default:()=>{var i,f,g,u,s;return[t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-desc-${o}`},[(i=l.value.linkModalTips)==null?void 0:i.descLabel]),t.createVNode("input",{placeholder:(f=l.value.linkModalTips)==null?void 0:f.descLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-desc-${o}`,type:"text",value:n.desc,onChange:h=>{n.desc=h.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-url-${o}`},[(g=l.value.linkModalTips)==null?void 0:g.urlLabel]),t.createVNode("input",{placeholder:(u=l.value.linkModalTips)==null?void 0:u.urlLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-url-${o}`,type:"text",value:n.url,onChange:h=>{n.url=h.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:[`${r.prefix}-btn`,`${r.prefix}-btn-row`],type:"button",onClick:()=>{e.onOk(n),n.desc="",n.url=""}},[(s=l.value.linkModalTips)==null?void 0:s.buttonOK])])]}})}}),Lt={visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Mt=t.defineComponent({props:Lt,setup(e){var h,V,C;const l=t.inject("usedLanguageText"),o=t.inject("editorId");let a=(C=(V=(h=r.configOption)==null?void 0:h.editorExtensions)==null?void 0:V.cropper)==null?void 0:C.instance;const n=t.ref(),i=t.ref(),f=t.ref(),g=t.reactive({cropperInited:!1,imgSelected:!1,imgSrc:"",isFullscreen:!1});let u=null;t.watch(()=>e.visible,()=>{e.visible&&!g.cropperInited&&(a=a||window.Cropper,n.value.onchange=()=>{if(!a){d.bus.emit(o,d.ERROR_CATCHER,{name:"Cropper",message:"Cropper is undefined"});return}const m=n.value.files||[];if(g.imgSelected=!0,(m==null?void 0:m.length)>0){const p=new FileReader;p.onload=b=>{g.imgSrc=b.target.result,t.nextTick(()=>{u=new a(i.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`})})},p.readAsDataURL(m[0])}})}),t.watch(()=>[g.imgSelected],()=>{f.value.style=""}),t.watch(()=>g.isFullscreen,()=>{t.nextTick(()=>{u==null||u.destroy(),f.value.style="",i.value&&(u=new a(i.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`}))})});const s=()=>{u.clear(),u.destroy(),u=null,n.value.value="",g.imgSelected=!1};return()=>{var m;return t.createVNode(x.MdModal,{class:`${r.prefix}-modal-clip`,title:(m=l.value.clipModalTips)==null?void 0:m.title,visible:e.visible,onClose:e.onCancel,showAdjust:!0,isFullscreen:g.isFullscreen,onAdjust:p=>{g.isFullscreen=p},width:"668px",height:"421px"},{default:()=>{var p,b;return[t.createVNode("div",{class:`${r.prefix}-form-item ${r.prefix}-clip`},[t.createVNode("div",{class:`${r.prefix}-clip-main`},[g.imgSelected?t.createVNode("div",{class:`${r.prefix}-clip-cropper`},[t.createVNode("img",{src:g.imgSrc,ref:i,style:{display:"none"},alt:""},null),t.createVNode("div",{class:`${r.prefix}-clip-delete`,onClick:s},[t.createVNode(x.Icon,{name:"delete"},null)])]):t.createVNode("div",{class:`${r.prefix}-clip-upload`,onClick:()=>{n.value.click()}},[t.createVNode(x.Icon,{name:"upload"},null)])]),t.createVNode("div",{class:`${r.prefix}-clip-preview`},[t.createVNode("div",{class:`${r.prefix}-clip-preview-target`,ref:f},null)])]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:`${r.prefix}-btn`,type:"button",onClick:()=>{if(u){const v=u.getCroppedCanvas();d.bus.emit(o,d.UPLOAD_IMAGE,[d.base642File(v.toDataURL("image/png"))],e.onOk),s()}}},[((p=l.value.clipModalTips)==null?void 0:p.buttonUpload)||((b=l.value.linkModalTips)==null?void 0:b.buttonOK)])]),t.createVNode("input",{ref:n,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:()=>{}}},Dt=t.defineComponent({props:Rt,setup(e){return()=>t.createVNode(t.Fragment,null,[t.createVNode(It,{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)])}}),Ht=t.defineComponent({name:"MDEditorToolbar",props:wt,setup(e){const l=t.inject("editorId"),o=t.inject("usedLanguageText"),a=t.inject("theme"),n=t.inject("language"),{fullscreenHandler:i}=yt(e),f=`${l}-toolbar-wrapper`,g=t.ref(),u=t.reactive({title:!1,catalog:!1,image:!1,table:!1,mermaid:!1,katex:!1}),s=(v,k)=>{d.bus.emit(l,d.REPLACE,v,k)},h=t.reactive({type:"link",linkVisible:!1,clipVisible:!1}),V=t.ref();t.onMounted(()=>{d.bus.on(l,{name:d.OPEN_MODALS,callback(v){h.type=v,h.linkVisible=!0}})});const C=t.computed(()=>{const v=e.toolbars.filter(S=>!e.toolbarsExclude.includes(S)),k=v.indexOf("="),N=k===-1?v:v.slice(0,k+1),w=k===-1?[]:v.slice(k,Number.MAX_SAFE_INTEGER);return[N,w]}),m=t.ref(),p=()=>{d.bus.emit(l,d.UPLOAD_IMAGE,Array.from(m.value.files||[])),m.value.value=""};t.onMounted(()=>{m.value.addEventListener("change",p)});const b=v=>{var k,N,w,S,A,Z,X,y,T,F,B,R,L,M,D,_,W,ne,Y,G,j,J,U,H,O,Q,ie,ge,be,he,ve,pe,Ce,ke,xe,$e,Ne,Ve,we,ye,Te,Ee,Se,Ae,Ie,Le,Me,Re,De,He,Oe,Pe,Be,Fe,qe,_e,We,je,Ue,Ge,ze,Ke,Ze,Xe,Ye,Je,Qe;if(r.allToolbar.includes(v))switch(v){case"-":return t.createVNode(Vt,null,null);case"bold":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(k=o.value.toolbarTips)==null?void 0:k.bold,onClick:()=>{s("bold")}},[t.createVNode(x.Icon,{name:"bold"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(N=o.value.toolbarTips)==null?void 0:N.bold])]);case"underline":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(w=o.value.toolbarTips)==null?void 0:w.underline,onClick:()=>{s("underline")}},[t.createVNode(x.Icon,{name:"underline"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(S=o.value.toolbarTips)==null?void 0:S.underline])]);case"italic":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(A=o.value.toolbarTips)==null?void 0:A.italic,onClick:()=>{s("italic")}},[t.createVNode(x.Icon,{name:"italic"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Z=o.value.toolbarTips)==null?void 0:Z.italic])]);case"strikeThrough":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(X=o.value.toolbarTips)==null?void 0:X.strikeThrough,onClick:()=>{s("strikeThrough")}},[t.createVNode(x.Icon,{name:"strike-through"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(y=o.value.toolbarTips)==null?void 0:y.strikeThrough])]);case"title":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.title,onChange:$=>{u.title=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{s("h1")}},[(T=o.value.titleItem)==null?void 0:T.h1]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{s("h2")}},[(F=o.value.titleItem)==null?void 0:F.h2]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{s("h3")}},[(B=o.value.titleItem)==null?void 0:B.h3]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{s("h4")}},[(R=o.value.titleItem)==null?void 0:R.h4]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{s("h5")}},[(L=o.value.titleItem)==null?void 0:L.h5]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{s("h6")}},[(M=o.value.titleItem)==null?void 0:M.h6])])},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.title},[t.createVNode(x.Icon,{name:"title"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.title])])]}});case"sub":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(D=o.value.toolbarTips)==null?void 0:D.sub,onClick:()=>{s("sub")}},[t.createVNode(x.Icon,{name:"sub"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(_=o.value.toolbarTips)==null?void 0:_.sub])]);case"sup":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(W=o.value.toolbarTips)==null?void 0:W.sup,onClick:()=>{s("sup")}},[t.createVNode(x.Icon,{name:"sup"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ne=o.value.toolbarTips)==null?void 0:ne.sup])]);case"quote":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Y=o.value.toolbarTips)==null?void 0:Y.quote,onClick:()=>{s("quote")}},[t.createVNode(x.Icon,{name:"quote"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(G=o.value.toolbarTips)==null?void 0:G.quote])]);case"unorderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(j=o.value.toolbarTips)==null?void 0:j.unorderedList,onClick:()=>{s("unorderedList")}},[t.createVNode(x.Icon,{name:"unordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(J=o.value.toolbarTips)==null?void 0:J.unorderedList])]);case"orderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(U=o.value.toolbarTips)==null?void 0:U.orderedList,onClick:()=>{s("orderedList")}},[t.createVNode(x.Icon,{name:"ordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(H=o.value.toolbarTips)==null?void 0:H.orderedList])]);case"task":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(O=o.value.toolbarTips)==null?void 0:O.task,onClick:()=>{s("task")}},[t.createVNode(x.Icon,{name:"task"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Q=o.value.toolbarTips)==null?void 0:Q.task])]);case"codeRow":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ie=o.value.toolbarTips)==null?void 0:ie.codeRow,onClick:()=>{s("codeRow")}},[t.createVNode(x.Icon,{name:"code-row"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ge=o.value.toolbarTips)==null?void 0:ge.codeRow])]);case"code":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(be=o.value.toolbarTips)==null?void 0:be.code,onClick:()=>{s("code")}},[t.createVNode(x.Icon,{name:"code"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(he=o.value.toolbarTips)==null?void 0:he.code])]);case"link":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ve=o.value.toolbarTips)==null?void 0:ve.link,onClick:()=>{h.type="link",h.linkVisible=!0}},[t.createVNode(x.Icon,{name:"link"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(pe=o.value.toolbarTips)==null?void 0:pe.link])]);case"image":return e.noUploadImg?t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ce=o.value.toolbarTips)==null?void 0:Ce.image,onClick:()=>{h.type="image",h.linkVisible=!0}},[t.createVNode(x.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ke=o.value.toolbarTips)==null?void 0:ke.image])]):t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.image,onChange:$=>{u.image=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{h.type="image",h.linkVisible=!0}},[(xe=o.value.imgTitleItem)==null?void 0:xe.link]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{m.value.click()}},[($e=o.value.imgTitleItem)==null?void 0:$e.upload]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{h.clipVisible=!0}},[(Ne=o.value.imgTitleItem)==null?void 0:Ne.clip2upload])])},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.image},[t.createVNode(x.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.image])])]}});case"table":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.table,onChange:$=>{u.table=$},key:"bar-table",overlay:t.createVNode(St,{tableShape:e.tableShape,onSelected:$=>{s("table",{selectedShape:$})}},null)},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.table},[t.createVNode(x.Icon,{name:"table"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.table])])]}});case"revoke":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ve=o.value.toolbarTips)==null?void 0:Ve.revoke,onClick:()=>{d.bus.emit(l,d.CTRL_Z)}},[t.createVNode(x.Icon,{name:"revoke"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(we=o.value.toolbarTips)==null?void 0:we.revoke])]);case"next":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ye=o.value.toolbarTips)==null?void 0:ye.next,onClick:()=>{d.bus.emit(l,d.CTRL_SHIFT_Z)}},[t.createVNode(x.Icon,{name:"next"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Te=o.value.toolbarTips)==null?void 0:Te.next])]);case"save":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ee=o.value.toolbarTips)==null?void 0:Ee.save,onClick:()=>{d.bus.emit(l,d.ON_SAVE)}},[t.createVNode(x.Icon,{name:"baocun"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Se=o.value.toolbarTips)==null?void 0:Se.save])]);case"prettier":return e.noPrettier?"":t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ae=o.value.toolbarTips)==null?void 0:Ae.prettier,onClick:()=>{s("prettier")}},[t.createVNode(x.Icon,{name:"prettier"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Ie=o.value.toolbarTips)==null?void 0:Ie.prettier])]);case"pageFullscreen":return!e.setting.fullscreen&&t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Le=o.value.toolbarTips)==null?void 0:Le.pageFullscreen,onClick:()=>{e.updateSetting("pageFullscreen")}},[t.createVNode(x.Icon,{name:e.setting.pageFullscreen?"suoxiao":"fangda"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Me=o.value.toolbarTips)==null?void 0:Me.pageFullscreen])]);case"fullscreen":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Re=o.value.toolbarTips)==null?void 0:Re.fullscreen,onClick:()=>{i()}},[t.createVNode(x.Icon,{name:e.setting.fullscreen?"fullscreen-exit":"fullscreen"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(De=o.value.toolbarTips)==null?void 0:De.fullscreen])]);case"preview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(He=o.value.toolbarTips)==null?void 0:He.preview,onClick:()=>{e.updateSetting("preview")}},[t.createVNode(x.Icon,{name:"preview"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Oe=o.value.toolbarTips)==null?void 0:Oe.preview])]);case"htmlPreview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Pe=o.value.toolbarTips)==null?void 0:Pe.htmlPreview,onClick:()=>{e.updateSetting("htmlPreview")}},[t.createVNode(x.Icon,{name:"coding"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Be=o.value.toolbarTips)==null?void 0:Be.htmlPreview])]);case"catalog":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Fe=o.value.toolbarTips)==null?void 0:Fe.catalog,onClick:()=>{d.bus.emit(l,d.CHANGE_CATALOG_VISIBLE)},key:"bar-catalog"},[t.createVNode(x.Icon,{name:"catalog"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(qe=o.value.toolbarTips)==null?void 0:qe.catalog])]);case"github":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(_e=o.value.toolbarTips)==null?void 0:_e.github,onClick:()=>le.linkTo("https://github.com/imzbf/md-editor-v3")},[t.createVNode(x.Icon,{name:"github"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(We=o.value.toolbarTips)==null?void 0:We.github])]);case"mermaid":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.mermaid,onChange:$=>{u.mermaid=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.mermaid=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("flow")}},[(je=o.value.mermaid)==null?void 0:je.flow]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("sequence")}},[(Ue=o.value.mermaid)==null?void 0:Ue.sequence]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("gantt")}},[(Ge=o.value.mermaid)==null?void 0:Ge.gantt]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("class")}},[(ze=o.value.mermaid)==null?void 0:ze.class]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("state")}},[(Ke=o.value.mermaid)==null?void 0:Ke.state]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("pie")}},[(Ze=o.value.mermaid)==null?void 0:Ze.pie]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("relationship")}},[(Xe=o.value.mermaid)==null?void 0:Xe.relationship]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{s("journey")}},[(Ye=o.value.mermaid)==null?void 0:Ye.journey])]),key:"bar-mermaid"},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.mermaid},[t.createVNode(x.Icon,{name:"mermaid"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.mermaid])])]}});case"katex":return t.createVNode(K.Dropdown,{relative:`#${f}`,visible:u.katex,onChange:$=>{u.katex=$},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.katex=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-katex`,onClick:()=>{s("katexInline")}},[(Je=o.value.katex)==null?void 0:Je.inline]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-katex`,onClick:()=>{s("katexBlock")}},[(Qe=o.value.katex)==null?void 0:Qe.block])]),key:"bar-katex"},{default:()=>{var $,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($=o.value.toolbarTips)==null?void 0:$.katex},[t.createVNode(x.Icon,{name:"formula"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.katex])])]}})}else if(e.defToolbars instanceof Array){const $=e.defToolbars[v];return $?t.cloneVNode($,{theme:a.value,language:n.value,insert(ue){d.bus.emit(l,d.REPLACE,"universal",{generate:ue})}}):""}else if(e.defToolbars&&e.defToolbars.children instanceof Array){const $=e.defToolbars.children[v];return $?t.cloneVNode($,{theme:a.value,language:n.value,insert(ue){d.bus.emit(l,d.REPLACE,"universal",{generate:ue})}}):""}else return""};return t.watch(()=>e.toolbars,()=>{t.nextTick(()=>{g.value&&le.draggingScroll(g.value)})},{immediate:!0}),()=>{const v=C.value[0].map(N=>b(N)),k=C.value[1].map(N=>b(N));return t.createVNode(t.Fragment,null,[e.toolbars.length>0&&t.createVNode("div",{class:`${r.prefix}-toolbar-wrapper`,ref:g,id:f},[t.createVNode("div",{class:[`${r.prefix}-toolbar`,e.showToolbarName&&`${r.prefix}-stn`]},[t.createVNode("div",{class:`${r.prefix}-toolbar-left`,ref:V},[v]),t.createVNode("div",{class:`${r.prefix}-toolbar-right`},[k])])]),t.createVNode("input",{ref:m,accept:"image/*",type:"file",multiple:!0,style:{display:"none"}},null),t.createVNode(Dt,{linkVisible:h.linkVisible,clipVisible:h.clipVisible,type:h.type,onCancel:()=>{h.linkVisible=!1,h.clipVisible=!1},onOk:N=>{N&&s(h.type,{desc:N.desc,url:N.url}),h.linkVisible=!1,h.clipVisible=!1}},null)])}}}),Ot=(e,l)=>{const o=le.debounce(()=>{e.removeEventListener("scroll",a),e.addEventListener("scroll",a),l.removeEventListener("scroll",a),l.addEventListener("scroll",a)},50),a=n=>{const i=e.clientHeight,f=l.clientHeight,g=e.scrollHeight,u=l.scrollHeight,s=(g-i)/(u-f);n.target===e?(l.removeEventListener("scroll",a),l.scrollTo({top:e.scrollTop/s}),o()):(e.removeEventListener("scroll",a),e.scrollTo({top:l.scrollTop*s}),o())};return[()=>{o().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",a),l.removeEventListener("scroll",a)}]},Pt=(e,l,o)=>{const{view:a}=o,n=le.createSmoothScroll(),i=C=>a.lineBlockAt(a.state.doc.line(C).from).top,f=C=>a.lineBlockAt(a.state.doc.line(C).from).height;let g=[];const u=()=>{g=[];const C=Array.from(l.querySelectorAll("[data-line]")).map(v=>Number(v.dataset.line)+1),{lines:m}=a.state.doc;let p=1,b=C.shift()??m;for(let v=1;v<=m;v++)v===b&&(p=v,b=C.shift()||m+1),g.push({start:p,end:b-1})};let s=0,h=0;const V=le.throttle(C=>{var k,N,w,S,A,Z,X;if(!((k=l.firstElementChild)!=null&&k.firstElementChild))return;const m=a.lineBlockAtHeight(a.scrollDOM.scrollTop),{number:p}=a.state.doc.lineAt(m.from);if(p>g.length||a.state.doc.lines<g[g.length-1].end)return;let b=+getComputedStyle(l).paddingTop.replace("px","");const v=+getComputedStyle(l).paddingBottom.replace("px","");if(C.target===e){if(h!==0)return;s++;const y=g[p-1];let T=i(y.end)+f(y.end),F=0;const B=i(y.start),R=l.querySelector(`[data-line="${y.start-1}"]`)||((N=l.firstElementChild)==null?void 0:N.firstElementChild),L=l.querySelector(`[data-line="${y.end}"]`)||((w=l.lastElementChild)==null?void 0:w.lastElementChild);let M=0,D=0;B===0?R===L?(b=0,T=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight,F=a.scrollDOM.scrollTop/T,M=L.offsetTop+L.offsetHeight-l.clientHeight):(F=a.scrollDOM.scrollTop/T,M=L.offsetTop):T>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(F=(a.scrollDOM.scrollTop-B)/(a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight-B),D=R.offsetTop,M=l.scrollHeight-l.clientHeight-D+10):(F=(a.scrollDOM.scrollTop-B)/(T-B),D=R.offsetTop,M=L.offsetTop-D);const _=D-b+M*F;n(l,_,()=>{s--})}else{if(s!==0)return;h++;const y=Array.from(l.querySelectorAll("[data-line]")),T=l.scrollTop,F=l.scrollHeight;let B=y.length===0?1:Math.ceil(Number(y[y.length-1].dataset.line)*(T/F)),R=(S=l.firstElementChild)==null?void 0:S.firstElementChild;for(let H=B;H>=0;H--){const O=l.querySelector(`[data-line="${H}"]`);if(O&&O.offsetTop<=T){R=O,B=H;break}}let L=(A=l.firstElementChild)==null?void 0:A.firstElementChild,M=(Z=l.firstElementChild)==null?void 0:Z.lastElementChild;for(;y.length>0;){const H=y.indexOf(R);if(H+1>=y.length)break;const O=y[H+1];if(H===-1){M=O;break}const Q=R.offsetTop;if(Q>T){if(H===0){L=R,M=O;break}R=y[H-1];continue}const ie=O.offsetTop;if(Q<=T&&ie>T){L=R,M=O;break}R=O}const D=L.offsetTop;let _=M.offsetTop,W=0;const{start:ne,end:Y}=g[Number(L.dataset.line||0)],G=i(ne);let j=i(Y);const J=f(Y);let U=0;L===((X=l.firstElementChild)==null?void 0:X.firstElementChild)?(L===M?(_=M.offsetHeight-l.offsetHeight+b+v,U=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight):U=j+J-G,W=Math.max(T/_,0)):j>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(W=Math.max((T-D)/(l.scrollHeight-D-l.clientHeight),0),j=i(a.state.doc.lines)+f(a.state.doc.lines),U=8+j-G-e.clientHeight):(W=Math.max((T-D)/(_-D),0),U=j+J-G),n(e,G+U*W,()=>{h--})}},10);return[()=>{u(),e.addEventListener("scroll",V),l.addEventListener("scroll",V),e.dispatchEvent(new Event("scroll"))},()=>{g=[],e.removeEventListener("scroll",V),l.removeEventListener("scroll",V)}]},Bt=(e,l,o)=>{const a=t.inject("editorId");let n=()=>{},i=()=>{};const f=()=>{n();const g=document.querySelector(`#${a} .cm-scroller`),u=document.querySelector(`[id="${a}-preview-wrapper"][data-show="true"]`),s=document.querySelector(`[id="${a}-html-wrapper"][data-show="true"]`);(u||s)&&([i,n]=(u?Pt:Ot)(g,u||s,o.value)),e.scrollAuto&&i()};t.watch([l,t.toRef(e.setting,"preview"),t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"fullscreen"),t.toRef(e.setting,"pageFullscreen")],()=>{t.nextTick(f)}),t.watch(()=>e.scrollAuto,g=>{g?i():n()}),t.onMounted(f)},Ft=Bt,qt=(e,l,o)=>{var h,V,C,m,p,b;let a="",n=0,i=0,f=!0,g=!1;const u=l.getSelectedText(),s=(h=r.configOption.editorConfig)==null?void 0:h.mermaidTemplate;if(/^h[1-6]{1}$/.test(e)){const v=e.replace(/^h(\d)/,(k,N)=>new Array(Number(N)).fill("#",0,N).join(""));a=`${v} ${u}`,n=v.length+1}else if(e==="prettier"){const v=window.prettier||((C=(V=r.configOption.editorExtensions)==null?void 0:V.prettier)==null?void 0:C.prettierInstance),k=[((m=window.prettierPlugins)==null?void 0:m.markdown)||((b=(p=r.configOption.editorExtensions)==null?void 0:p.prettier)==null?void 0:b.parserMarkdownInstance)];!v||k[0]===void 0?(d.bus.emit(o.editorId,d.ERROR_CATCHER,{name:"prettier",message:"prettier is undefined"}),a=l.getValue()):a=v.format(l.getValue(),{parser:"markdown",plugins:k}),f=!1,g=!0}else switch(e){case"bold":{a=`**${u}**`,n=2,i=-2;break}case"underline":{a=`<u>${u}</u>`,n=3,i=-4;break}case"italic":{a=`*${u}*`,n=1,i=-1;break}case"strikeThrough":{a=`~~${u}~~`,n=2,i=-2;break}case"sub":{a=`<sub>${u}</sub>`,n=5,i=-6;break}case"sup":{a=`<sup>${u}</sup>`,n=5,i=-6;break}case"codeRow":{a="`"+u+"`",n=1,i=-1;break}case"quote":{a=`> ${u}`,n=2;break}case"orderedList":{a=`1. ${u}`,n=3;break}case"unorderedList":{a=`- ${u}`,n=2;break}case"task":{a=`- [ ] ${u}`,n=6;break}case"code":{const v=o.text||u||"",k=o.mode||"language";a=`\`\`\`${k}
|
|
2
2
|
${v}
|
|
3
3
|
\`\`\`
|
|
4
4
|
`,n=3,i=3+k.length-a.length;break}case"table":{a="|";const{selectedShape:v={x:1,y:1}}=o,{x:k,y:N}=v;for(let w=0;w<=N;w++)a+=" col |";a+=`
|
|
@@ -6,17 +6,17 @@ ${v}
|
|
|
6
6
|
|`;for(let S=0;S<=N;S++)a+=" content |"}n=2,i=5-a.length;break}case"link":{const{desc:v,url:k}=o;a=`[${v}](${k})`,f=!1;break}case"image":{const{desc:v,url:k,urls:N}=o;N instanceof Array?a=N.reduce((w,S)=>w+`
|
|
7
7
|
`,""):a=`
|
|
8
8
|
`,f=!1;break}case"flow":{a=`\`\`\`mermaid
|
|
9
|
-
${(
|
|
9
|
+
${(s==null?void 0:s.flow)||`flowchart TD
|
|
10
10
|
Start --> Stop`}
|
|
11
11
|
\`\`\`
|
|
12
12
|
`,n=3,i=10-a.length;break}case"sequence":{a=`\`\`\`mermaid
|
|
13
|
-
${(
|
|
13
|
+
${(s==null?void 0:s.sequence)||`sequenceDiagram
|
|
14
14
|
A->>B: hello!
|
|
15
15
|
B-->>A: hi!
|
|
16
16
|
A-)B: bye!`}
|
|
17
17
|
\`\`\`
|
|
18
18
|
`,n=3,i=10-a.length;break}case"gantt":{a=`\`\`\`mermaid
|
|
19
|
-
${(
|
|
19
|
+
${(s==null?void 0:s.gantt)||`gantt
|
|
20
20
|
title A Gantt Diagram
|
|
21
21
|
dateFormat YYYY-MM-DD
|
|
22
22
|
section Section
|
|
@@ -24,27 +24,27 @@ A task :a1, 2014-01-01, 30d
|
|
|
24
24
|
Another task :after a1, 20d`}
|
|
25
25
|
\`\`\`
|
|
26
26
|
`,n=3,i=10-a.length;break}case"class":{a=`\`\`\`mermaid
|
|
27
|
-
${(
|
|
27
|
+
${(s==null?void 0:s.class)||`classDiagram
|
|
28
28
|
class Animal
|
|
29
29
|
Vehicle <|-- Car`}
|
|
30
30
|
\`\`\`
|
|
31
31
|
`,n=3,i=10-a.length;break}case"state":{a=`\`\`\`mermaid
|
|
32
|
-
${(
|
|
32
|
+
${(s==null?void 0:s.state)||`stateDiagram-v2
|
|
33
33
|
s1 --> s2`}
|
|
34
34
|
\`\`\`
|
|
35
35
|
`,n=3,i=10-a.length;break}case"pie":{a=`\`\`\`mermaid
|
|
36
|
-
${(
|
|
36
|
+
${(s==null?void 0:s.pie)||`pie title Pets adopted by volunteers
|
|
37
37
|
"Dogs" : 386
|
|
38
38
|
"Cats" : 85
|
|
39
39
|
"Rats" : 15`}
|
|
40
40
|
\`\`\`
|
|
41
41
|
`,n=3,i=10-a.length;break}case"relationship":{a=`\`\`\`mermaid
|
|
42
|
-
${(
|
|
42
|
+
${(s==null?void 0:s.relationship)||`erDiagram
|
|
43
43
|
CAR ||--o{ NAMED-DRIVER : allows
|
|
44
44
|
PERSON ||--o{ NAMED-DRIVER : is`}
|
|
45
45
|
\`\`\`
|
|
46
46
|
`,n=3,i=10-a.length;break}case"journey":{a=`\`\`\`mermaid
|
|
47
|
-
${(
|
|
47
|
+
${(s==null?void 0:s.journey)||`journey
|
|
48
48
|
title My working day
|
|
49
49
|
section Go to work
|
|
50
50
|
Make tea: 5: Me
|
|
@@ -57,11 +57,11 @@ ${(c==null?void 0:c.journey)||`journey
|
|
|
57
57
|
`,n=3,i=10-a.length;break}case"katexInline":{a="$$",n=1,i=-1;break}case"katexBlock":{a=`$$
|
|
58
58
|
|
|
59
59
|
$$
|
|
60
|
-
`,n=3,i=-4;break}case"universal":{const{generate:v}=o,k=v(u);a=k.targetValue,f=k.select,n=k.deviationStart,i=k.deviationEnd}}return{text:a,options:{select:f,deviationStart:n,deviationEnd:i,replaceAll:g}}},_t="#e5c07b",tt="var(--md-color)",Wt="#56b6c2",jt="#ffffff",te="var(--md-color)",ot="#e5c07b",Ut="#e5c07b",Gt="var(--md-color)",lt="#d19a66",zt="#c678dd",Kt="#21252b",Zt="#2c313a",at="var(--md-bk-color)",me="var(--md-bk-color)",Xt="#ceedfa33",rt="#528bff",Yt=ae.EditorView.theme({"&":{color:te,backgroundColor:at},".cm-content":{caretColor:rt},".cm-cursor, .cm-dropCursor":{borderLeftColor:rt},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Xt},".cm-panels":{backgroundColor:Kt,color:te},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#ceedfa33"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:at,color:te,borderRight:"1px solid",borderColor:"var(--md-border-color)"},".cm-activeLineGutter":{backgroundColor:Zt},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"1px solid var(--md-border-color)",backgroundColor:me},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:me,borderBottomColor:me},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{color:te}}},{dark:!0}),Jt=re.HighlightStyle.define([{tag:
|
|
60
|
+
`,n=3,i=-4;break}case"universal":{const{generate:v}=o,k=v(u);a=k.targetValue,f=k.select,n=k.deviationStart,i=k.deviationEnd}}return{text:a,options:{select:f,deviationStart:n,deviationEnd:i,replaceAll:g}}},_t="#e5c07b",tt="var(--md-color)",Wt="#56b6c2",jt="#ffffff",te="var(--md-color)",ot="#e5c07b",Ut="#e5c07b",Gt="var(--md-color)",lt="#d19a66",zt="#c678dd",Kt="#21252b",Zt="#2c313a",at="var(--md-bk-color)",me="var(--md-bk-color)",Xt="#ceedfa33",rt="#528bff",Yt=ae.EditorView.theme({"&":{color:te,backgroundColor:at},".cm-content":{caretColor:rt},".cm-cursor, .cm-dropCursor":{borderLeftColor:rt},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Xt},".cm-panels":{backgroundColor:Kt,color:te},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#ceedfa33"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:at,color:te,borderRight:"1px solid",borderColor:"var(--md-border-color)"},".cm-activeLineGutter":{backgroundColor:Zt},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"1px solid var(--md-border-color)",backgroundColor:me},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:me,borderBottomColor:me},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{color:te}}},{dark:!0}),Jt=re.HighlightStyle.define([{tag:c.tags.keyword,color:zt},{tag:[c.tags.name,c.tags.deleted,c.tags.character,c.tags.propertyName,c.tags.macroName],color:tt},{tag:[c.tags.function(c.tags.variableName),c.tags.labelName],color:Ut},{tag:[c.tags.color,c.tags.constant(c.tags.name),c.tags.standard(c.tags.name)],color:lt},{tag:[c.tags.definition(c.tags.name),c.tags.separator],color:te},{tag:[c.tags.typeName,c.tags.className,c.tags.number,c.tags.changed,c.tags.annotation,c.tags.modifier,c.tags.self,c.tags.namespace],color:_t},{tag:[c.tags.operator,c.tags.operatorKeyword,c.tags.url,c.tags.escape,c.tags.regexp,c.tags.link,c.tags.special(c.tags.string)],color:Wt},{tag:[c.tags.meta,c.tags.comment],color:ot},{tag:c.tags.strong,fontWeight:"bold"},{tag:c.tags.emphasis,fontStyle:"italic"},{tag:c.tags.strikethrough,textDecoration:"line-through"},{tag:c.tags.link,color:ot,textDecoration:"underline"},{tag:c.tags.heading,fontWeight:"bold",color:tt},{tag:[c.tags.atom,c.tags.bool,c.tags.special(c.tags.variableName)],color:lt},{tag:[c.tags.processingInstruction,c.tags.string,c.tags.inserted],color:Gt},{tag:c.tags.invalid,color:jt}]),nt=[Yt,re.syntaxHighlighting(Jt)],Qt="#e5c07b",it="#3f4a54",eo="#56b6c2",to="#fff",oe="#3f4a54",st="#2d8cf0",oo="#2d8cf0",lo="#3f4a54",ct="#d19a66",ao="#c678dd",ro="#21252b",no="#ceedfa33",dt="var(--md-bk-color)",fe="var(--md-bk-color)",io="#bad5fa",ut="#3f4a54",so=ae.EditorView.theme({"&":{color:oe,backgroundColor:dt},".cm-content":{caretColor:ut},".cm-cursor, .cm-dropCursor":{borderLeftColor:ut},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:io},".cm-panels":{backgroundColor:ro,color:oe},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#ceedfa33"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:dt,color:oe,borderRight:"1px solid",borderColor:"var(--md-border-color)"},".cm-activeLineGutter":{backgroundColor:no},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"1px solid var(--md-border-color)",backgroundColor:fe},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:fe,borderBottomColor:fe},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{color:oe}}}),co=re.HighlightStyle.define([{tag:c.tags.keyword,color:ao},{tag:[c.tags.name,c.tags.deleted,c.tags.character,c.tags.propertyName,c.tags.macroName],color:it},{tag:[c.tags.function(c.tags.variableName),c.tags.labelName],color:oo},{tag:[c.tags.color,c.tags.constant(c.tags.name),c.tags.standard(c.tags.name)],color:ct},{tag:[c.tags.definition(c.tags.name),c.tags.separator],color:oe},{tag:[c.tags.typeName,c.tags.className,c.tags.number,c.tags.changed,c.tags.annotation,c.tags.modifier,c.tags.self,c.tags.namespace],color:Qt},{tag:[c.tags.operator,c.tags.operatorKeyword,c.tags.url,c.tags.escape,c.tags.regexp,c.tags.link,c.tags.special(c.tags.string)],color:eo},{tag:[c.tags.meta,c.tags.comment],color:st},{tag:c.tags.strong,fontWeight:"bold"},{tag:c.tags.emphasis,fontStyle:"italic"},{tag:c.tags.strikethrough,textDecoration:"line-through"},{tag:c.tags.link,color:st,textDecoration:"underline"},{tag:c.tags.heading,fontWeight:"bold",color:it},{tag:[c.tags.atom,c.tags.bool,c.tags.special(c.tags.variableName)],color:ct},{tag:[c.tags.processingInstruction,c.tags.string,c.tags.inserted],color:lo},{tag:c.tags.invalid,color:to}]),mt=[so,re.syntaxHighlighting(co)],se=(e,l,o,a,n)=>(i,f,g,u)=>{const s=`${e}${l}`.slice(u-g);i.dispatch(i.state.replaceSelection(`${s}${o}${a}`));const h=g+f.label.length+(n==="title"?o.length:0);i.dispatch({selection:E.EditorSelection.create([E.EditorSelection.range(g+f.label.length+(n==="title"?1:-l.length),h),E.EditorSelection.cursor(h)],1)}),i.focus()},ft=e=>(l,o,a,n)=>{const i=e.slice(n-a);l.dispatch(l.state.replaceSelection(`${i} `))},uo=e=>{const l=o=>{const a=o.matchBefore(/^#+|^-\s*\[*\s*\]*|`+|\[|!\[*|^\|\s?\|?|^\$\$?|!+\s*\w*/);return a===null||a.from==a.to&&o.explicit?null:{from:a.from,options:[...["h1","h2","h3","h4","h5","h6"].map((n,i)=>{const f=new Array(i+1).fill("#").join("");return{label:f,type:"text",apply:ft(f)}}),...["unchecked","checked"].map(n=>{const i=n==="checked"?"- [x]":"- [ ]";return{label:i,type:"text",apply:ft(i)}}),...[["`",""],["```","language"],["```mermaid\n",""]].map(n=>({label:`${n[0]}${n[1]}`,type:"text",apply:se(n[0],n[1],"",n[0]==="`"?"`":"\n```","type")})),{label:"[]()",type:"text"},{label:"![]()",type:"text"},{label:"| |",type:"text",detail:"table",apply:`| col | col | col |
|
|
61
61
|
| - | - | - |
|
|
62
62
|
| content | content | content |
|
|
63
|
-
| content | content | content |`},{label:"$",type:"text",apply:
|
|
63
|
+
| content | content | content |`},{label:"$",type:"text",apply:se("$","","","$","type")},{label:"$$",type:"text",apply:se("$$","",`
|
|
64
64
|
`,`
|
|
65
|
-
$$`,"title")},...["note","abstract","info","tip","success","question","warning","failure","danger","bug","example","quote","hint","caution","error","attention"].map(n=>({label:`!!! ${n}`,type:"text",apply:
|
|
65
|
+
$$`,"title")},...["note","abstract","info","tip","success","question","warning","failure","danger","bug","example","quote","hint","caution","error","attention"].map(n=>({label:`!!! ${n}`,type:"text",apply:se("!!!",` ${n}`," Title",`
|
|
66
66
|
|
|
67
|
-
!!!`,"title")}))]}};return xt.autocompletion({override:e?[l,...e]:[l]})},gt=uo,z=e=>{const l=new E.Compartment;return a=>(l.get(e.state)?e.dispatch({effects:l.reconfigure(a)}):e.dispatch({effects:E.StateEffect.appendConfig.of(l.of(a))}),!0)};class mo{constructor(l){q(this,"view");q(this,"maxLength",Number.MAX_SAFE_INTEGER);q(this,"toggleTabSize");q(this,"togglePlaceholder");q(this,"setExtensions");q(this,"toggleDisabled");q(this,"toggleReadOnly");q(this,"toggleMaxlength");this.view=l,this.toggleTabSize=z(this.view),this.togglePlaceholder=z(this.view),this.setExtensions=z(this.view),this.toggleDisabled=z(this.view),this.toggleReadOnly=z(this.view),this.toggleMaxlength=z(this.view)}getValue(){return this.view.state.doc.toString()}setValue(l,o=0,a=this.view.state.doc.length){this.view.dispatch({changes:{from:o,to:a,insert:l}})}getSelectedText(){const{from:l,to:o}=this.view.state.selection.main;return this.view.state.sliceDoc(l,o)}replaceSelectedText(l,o={select:!0,deviationStart:0,deviationEnd:0,replaceAll:!1},a){try{if(o.replaceAll){if(this.setValue(l),l.length>this.maxLength)throw new Error("The input text is too long");return}if(this.view.state.doc.length-this.getSelectedText().length+l.length>this.maxLength)throw new Error("The input text is too long");const{from:n}=this.view.state.selection.main;if(this.view.dispatch(this.view.state.replaceSelection(l)),o.select){const i=n+l.length+o.deviationEnd;this.view.dispatch({selection:E.EditorSelection.create([E.EditorSelection.range(n+o.deviationStart,i),E.EditorSelection.cursor(i)],1)})}this.view.focus()}catch(n){if(n.message==="The input text is too long")d.bus.emit(a,d.ERROR_CATCHER,{name:"overlength",message:n.message,data:l});else throw n}}setTabSize(l){this.toggleTabSize([E.EditorState.tabSize.of(l),re.indentUnit.of(" ".repeat(l))])}setPlaceholder(l){this.togglePlaceholder(ae.placeholder(l))}focus(l){if(this.view.focus(),!l)return;let o=0,a=0,n=0;switch(l){case"start":break;case"end":{o=a=n=this.getValue().length;break}default:o=l.rangeAnchor||l.cursorPos,a=l.rangeHead||l.cursorPos,n=l.cursorPos}this.view.dispatch({scrollIntoView:!0,selection:E.EditorSelection.create([E.EditorSelection.range(o,a),E.EditorSelection.cursor(n)],1)})}setDisabled(l){this.toggleDisabled([ae.EditorView.editable.of(!l)])}setReadOnly(l){this.toggleReadOnly([E.EditorState.readOnly.of(l)])}setMaxLength(l){this.maxLength=l,this.toggleMaxlength([E.EditorState.changeFilter.of(o=>o.newDoc.length<=l)])}}const fo=e=>{const l=t.inject("editorId");return a=>{if(!a.clipboardData)return;if(a.clipboardData.files.length>0){const{files:i}=a.clipboardData;d.bus.emit(l,d.UPLOAD_IMAGE,Array.from(i).filter(f=>/image\/.*/.test(f.type))),a.preventDefault();return}if(e.autoDetectCode&&a.clipboardData.types.includes("vscode-editor-data")){const i=JSON.parse(a.clipboardData.getData("vscode-editor-data"));d.bus.emit(l,d.REPLACE,"code",{mode:i.mode,text:a.clipboardData.getData("text/plain")}),a.preventDefault();return}const n=a.clipboardData.getData("text/plain");e.maxlength&&n.length+e.modelValue.length>e.maxlength&&d.bus.emit(l,d.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:n})}},go=fo,bo=e=>{const l=t.inject("editorId");t.onMounted(()=>{d.bus.on(l,{name:d.TEXTAREA_FOCUS,callback(o){var a;(a=e.value)==null||a.focus(o)}})})},ho=bo,vo=(e,l)=>{const o={key:"Ctrl-b",mac:"Cmd-b",run:()=>(d.bus.emit(e,d.REPLACE,"bold"),!0)},a={key:"Ctrl-s",mac:"Cmd-s",run:S=>(d.bus.emit(e,d.ON_SAVE,S.state.doc.toString()),!0),shift:()=>(d.bus.emit(e,d.REPLACE,"strikeThrough"),!0)},n={key:"Ctrl-u",mac:"Cmd-u",run:()=>(d.bus.emit(e,d.REPLACE,"underline"),!0),shift:()=>(d.bus.emit(e,d.REPLACE,"unorderedList"),!0)},i={key:"Ctrl-i",mac:"Cmd-i",run:()=>(d.bus.emit(e,d.REPLACE,"italic"),!0),shift:()=>(d.bus.emit(e,d.OPEN_MODALS,"image"),!0)},f={key:"Ctrl-1",mac:"Cmd-1",run:()=>(d.bus.emit(e,d.REPLACE,"h1"),!0)},g={key:"Ctrl-2",mac:"Cmd-2",run:()=>(d.bus.emit(e,d.REPLACE,"h2"),!0)},u={key:"Ctrl-3",mac:"Cmd-3",run:()=>(d.bus.emit(e,d.REPLACE,"h3"),!0)},c={key:"Ctrl-4",mac:"Cmd-4",run:()=>(d.bus.emit(e,d.REPLACE,"h4"),!0)},h={key:"Ctrl-5",mac:"Cmd-5",run:()=>(d.bus.emit(e,d.REPLACE,"h5"),!0)},V={key:"Ctrl-6",mac:"Cmd-6",run:()=>(d.bus.emit(e,d.REPLACE,"h6"),!0)},C={key:"Ctrl-ArrowUp",mac:"Cmd-ArrowUp",run:()=>(d.bus.emit(e,d.REPLACE,"sup"),!0)},m={key:"Ctrl-ArrowDown",mac:"Cmd-ArrowDown",run:()=>(d.bus.emit(e,d.REPLACE,"sub"),!0)},p={key:"Ctrl-o",mac:"Cmd-o",run:()=>(d.bus.emit(e,d.REPLACE,"orderedList"),!0)},b={key:"Ctrl-c",mac:"Cmd-c",shift:()=>(d.bus.emit(e,d.REPLACE,"code"),!0),any(S,A){return(A.ctrlKey||A.metaKey)&&A.altKey&&A.code==="KeyC"?(d.bus.emit(e,d.REPLACE,"codeRow"),!0):!1}},v={key:"Ctrl-l",mac:"Cmd-l",run:()=>(d.bus.emit(e,d.OPEN_MODALS,"link"),!0)},k={key:"Ctrl-f",mac:"Cmd-f",shift:()=>l.noPrettier?!1:(d.bus.emit(e,d.REPLACE,"prettier"),!0)},N={any:(S,A)=>(A.ctrlKey||A.metaKey)&&A.altKey&&A.shiftKey&&A.code==="KeyT"?(d.bus.emit(e,d.REPLACE,"table"),!0):!1},w={key:"Ctrl-d",mac:"Cmd-d",run:se.deleteLine,preventDefault:!0};return[o,w,a,n,i,f,g,u,c,h,V,C,m,p,b,v,k,N]},po=vo,Co=e=>{const l=t.inject("tabWidth"),o=t.inject("editorId"),a=t.inject("theme"),n=t.ref(),i=t.shallowRef(),f=new E.Compartment,g=new E.Compartment,u=new E.Compartment,c=po(o,e),h=go(e),V=[ae.keymap.of([...c,se.indentWithTab]),ee.minimalSetup,f.of(kt.markdown({codeLanguages:Ct.languages})),ee.EditorView.lineWrapping,ee.EditorView.updateListener.of(m=>{m.docChanged&&e.onChange(m.state.doc.toString())}),ee.EditorView.domEventHandlers({paste:h,blur:e.onBlur,focus:e.onFocus,drop:e.onDrop,input:m=>{e.onInput&&e.onInput(m);const{data:p}=m;e.maxlength&&e.modelValue.length+p.length>e.maxlength&&d.bus.emit(o,d.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:p})}})],C=()=>{const m=[...V,g.of(a.value==="light"?mt:nt),u.of(gt(e.completions))];return r.configOption.codeMirrorExtensions(a.value,m,[...c])};return t.onMounted(()=>{const m=new ee.EditorView({doc:e.modelValue,parent:n.value,extensions:[C()]}),p=new mo(m);i.value=p,setTimeout(()=>{p.setTabSize(l),p.setDisabled(e.disabled),p.setReadOnly(e.readonly),e.placeholder&&p.setPlaceholder(e.placeholder),typeof e.maxlength=="number"&&p.setMaxLength(e.maxlength),e.autofocus&&m.focus()},0),d.bus.on(o,{name:d.CTRL_Z,callback(){se.undo(m)}}),d.bus.on(o,{name:d.CTRL_SHIFT_Z,callback(){se.redo(m)}}),d.bus.on(o,{name:d.REPLACE,callback(b,v={}){var w;const{text:k,options:N}=qt(b,i.value,v);(w=i.value)==null||w.replaceSelectedText(k,N,o)}})}),t.watch(a,()=>{var m;(m=i.value)==null||m.view.dispatch({effects:g.reconfigure(a.value==="light"?mt:nt)})},{deep:!0}),t.watch(()=>e.completions,()=>{var m;(m=i.value)==null||m.view.dispatch({effects:u.reconfigure(gt(e.completions))})},{deep:!0}),t.watch(()=>e.modelValue,()=>{var m,p;((m=i.value)==null?void 0:m.getValue())!==e.modelValue&&((p=i.value)==null||p.setValue(e.modelValue))}),t.watch(()=>e.placeholder,()=>{var m;(m=i.value)==null||m.setPlaceholder(e.placeholder)}),t.watch(()=>e.disabled,()=>{var m;(m=i.value)==null||m.setDisabled(e.disabled)}),t.watch(()=>e.readonly,()=>{var m;(m=i.value)==null||m.setDisabled(e.readonly)}),t.watch(()=>e.maxlength,()=>{var m;e.maxlength&&((m=i.value)==null||m.setMaxLength(e.maxlength))}),ho(i),{inputWrapperRef:n,codeMirrorUt:i}},ko=Co,xo=(e,l,o)=>{const a=t.reactive({resizedWidth:e.inputBoxWitdh}),n=t.reactive({width:e.inputBoxWitdh}),i=t.reactive({left:e.inputBoxWitdh,display:"initial"}),f=c=>{var p,b,v;const h=((p=l.value)==null?void 0:p.offsetWidth)||0,V=((b=l.value)==null?void 0:b.getBoundingClientRect().x)||0;let C=c.x-V;C<r.MinInputBoxWidth?C=r.MinInputBoxWidth:C>h-r.MinInputBoxWidth&&(C=h-r.MinInputBoxWidth);const m=`${C}px`;n.width=m,i.left=m,a.resizedWidth=m,(v=e.onInputBoxWitdhChange)==null||v.call(e,m)},g=()=>{document.addEventListener("mousemove",f)},u=()=>{document.removeEventListener("mousemove",f)};return t.onMounted(()=>{var c;(c=o.value)==null||c.addEventListener("mousedown",g),document.addEventListener("mouseup",u)}),t.onBeforeUnmount(()=>{var c,h;(c=o.value)==null||c.removeEventListener("mousedown",g),(h=o.value)==null||h.removeEventListener("mouseup",u)}),t.watch(()=>e.inputBoxWitdh,c=>{c&&(n.width=c,i.left=c)}),t.watch([t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"preview")],()=>{!e.setting.htmlPreview&&!e.setting.preview?(n.width="100%",i.display="none"):(n.width=a.resizedWidth,i.display="initial")},{immediate:!0}),{inputWrapperStyle:n,resizeOperateStyle:i}},$o=xo,No=t.defineComponent({name:"MDEditorContent",props:P.contentProps,setup(e){const l=t.inject("editorId"),o=t.ref(""),a=t.ref(),n=t.ref(),{inputWrapperRef:i,codeMirrorUt:f}=ko(e),{inputWrapperStyle:g,resizeOperateStyle:u}=$o(e,a,n);return Ft(e,o,f),()=>t.createVNode("div",{class:`${r.prefix}-content`,ref:a},[t.createVNode("div",{class:`${r.prefix}-input-wrapper`,style:g,ref:i},null),t.createVNode("div",{class:`${r.prefix}-resize-operate`,style:u,ref:n},null),t.createVNode(P.ContentPreview,{modelValue:e.modelValue,setting:e.setting,onHtmlChanged:c=>{o.value=c,e.onHtmlChanged(c)},onGetCatalog:e.onGetCatalog,mdHeadingId:e.mdHeadingId,noMermaid:e.noMermaid,sanitize:e.sanitize,noKatex:e.noKatex,formatCopiedText:e.formatCopiedText,noHighlight:e.noHighlight,noImgZoomIn:e.noImgZoomIn},null),e.catalogVisible&&t.createVNode(bt,{theme:e.theme,class:`${r.prefix}-catalog-editor`,editorId:l,mdHeadingId:e.mdHeadingId,key:"internal-catalog"},null)])}}),Vo=t.defineComponent({props:{modelValue:{type:String,default:""}},setup(e){const l=t.inject("usedLanguageText");return()=>{var o,a;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`},[`${(o=l.value.footer)==null?void 0:o.markdownTotal}:`]),t.createVNode("span",null,[((a=e.modelValue)==null?void 0:a.length)||0])])}}}),wo={checked:{type:Boolean,default:!1},onChange:{type:Function,default:()=>{}}},yo=t.defineComponent({props:wo,setup(e){return()=>t.createVNode("div",{class:[`${r.prefix}-checkbox`,e.checked&&`${r.prefix}-checkbox-checked`],onClick:()=>{e.onChange(!e.checked)}},null)}}),To={scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}}},Eo=t.defineComponent({props:To,setup(e){const l=t.inject("usedLanguageText");return()=>{var o;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`,onClick:()=>{e.onScrollAutoChange(!e.scrollAuto)}},[(o=l.value.footer)==null?void 0:o.scrollAuto]),t.createVNode(yo,{checked:e.scrollAuto,onChange:e.onScrollAutoChange},null)])}}}),So={modelValue:{type:String,default:""},footers:{type:Array,default:[]},scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}},defFooters:{type:Object}},Ao=t.defineComponent({name:"MDEditorFooter",props:So,setup(e){const l=t.computed(()=>{const a=e.footers.indexOf("="),n=a===-1?e.footers:e.footers.slice(0,a),i=a===-1?[]:e.footers.slice(a,Number.MAX_SAFE_INTEGER);return[n,i]}),o=a=>{if(r.allFooter.includes(a))switch(a){case"markdownTotal":return t.createVNode(Vo,{modelValue:e.modelValue},null);case"scrollSwitch":return t.createVNode(Eo,{scrollAuto:e.scrollAuto,onScrollAutoChange:e.onScrollAutoChange},null)}else return e.defFooters instanceof Array?e.defFooters[a]||"":e.defFooters&&e.defFooters.children instanceof Array&&e.defFooters.children[a]||""};return()=>{const a=l.value[0].map(i=>o(i)),n=l.value[1].map(i=>o(i));return t.createVNode("div",{class:`${r.prefix}-footer`},[t.createVNode("div",{class:`${r.prefix}-footer-left`},[a]),t.createVNode("div",{class:`${r.prefix}-footer-right`},[n])])}}}),Io=t.defineComponent({name:"MdEditorV3",props:P.editorProps,emits:P.editorEmits,setup(e,l){const{editorId:o,noKatex:a,noMermaid:n,noPrettier:i,noUploadImg:f,noHighlight:g}=e,u=t.reactive({scrollAuto:e.scrollAuto});P.useOnSave(e,l),P.useProvide(e),P.useExpansion(e),P.useErrorCatcher(e,l);const[c,h]=P.useConfig(e,l),V=P.useCatalog(e);return t.onBeforeUnmount(()=>{d.bus.clear(o)}),P.useExpose(e,l,V,c,h),()=>{var p;const C=et.getSlot({props:e,ctx:l},"defToolbars"),m=et.getSlot({props:e,ctx:l},"defFooters");return t.createVNode("div",{id:o,class:[r.prefix,e.class,e.theme==="dark"&&`${r.prefix}-dark`,c.fullscreen||c.pageFullscreen?`${r.prefix}-fullscreen`:""],style:e.style},[t.createVNode(Ht,{noPrettier:i,toolbars:e.toolbars,toolbarsExclude:e.toolbarsExclude,setting:c,updateSetting:h,tableShape:e.tableShape,defToolbars:C,noUploadImg:f,showToolbarName:e.showToolbarName},null),t.createVNode(No,{modelValue:e.modelValue,setting:c,mdHeadingId:e.mdHeadingId,noMermaid:n,noPrettier:i,sanitize:e.sanitize,placeholder:e.placeholder,noKatex:a,scrollAuto:u.scrollAuto,formatCopiedText:e.formatCopiedText,autofocus:e.autoFocus,disabled:e.disabled,readonly:e.readOnly,maxlength:e.maxLength,autoDetectCode:e.autoDetectCode,noHighlight:g,onChange:b=>{e.onChange?e.onChange(b):(l.emit("update:modelValue",b),l.emit("onChange",b))},onHtmlChanged:b=>{e.onHtmlChanged?e.onHtmlChanged(b):l.emit("onHtmlChanged",b)},onGetCatalog:b=>{e.onGetCatalog?e.onGetCatalog(b):l.emit("onGetCatalog",b)},onBlur:b=>{e.onBlur?e.onBlur(b):l.emit("onBlur",b)},onFocus:b=>{e.onFocus?e.onFocus(b):l.emit("onFocus",b)},onInput:b=>{e.onInput?e.onInput(b):l.emit("onInput",b)},completions:e.completions,catalogVisible:V.value,theme:e.theme,noImgZoomIn:e.noImgZoomIn,onDrop:b=>{e.onDrop?e.onDrop(b):l.emit("onDrop",b)},inputBoxWitdh:e.inputBoxWitdh,onInputBoxWitdhChange:b=>{e.onInputBoxWitdhChange?e.onInputBoxWitdhChange(b):l.emit("onInputBoxWitdhChange",b)}},null),((p=e.footers)==null?void 0:p.length)>0&&t.createVNode(Ao,{modelValue:e.modelValue,footers:e.footers,defFooters:m,scrollAuto:u.scrollAuto,onScrollAutoChange:b=>u.scrollAuto=b},null)])}}}),de=Io;de.install=e=>(e.component(de.name,de),e.use($t).use(K.DropdownToolbar).use(Nt).use(bt).use(P.MdPreview),e);module.exports=de;
|
|
67
|
+
!!!`,"title")}))]}};return xt.autocompletion({override:e?[l,...e]:[l]})},gt=uo,z=e=>{const l=new E.Compartment;return a=>(l.get(e.state)?e.dispatch({effects:l.reconfigure(a)}):e.dispatch({effects:E.StateEffect.appendConfig.of(l.of(a))}),!0)};class mo{constructor(l){q(this,"view");q(this,"maxLength",Number.MAX_SAFE_INTEGER);q(this,"toggleTabSize");q(this,"togglePlaceholder");q(this,"setExtensions");q(this,"toggleDisabled");q(this,"toggleReadOnly");q(this,"toggleMaxlength");this.view=l,this.toggleTabSize=z(this.view),this.togglePlaceholder=z(this.view),this.setExtensions=z(this.view),this.toggleDisabled=z(this.view),this.toggleReadOnly=z(this.view),this.toggleMaxlength=z(this.view)}getValue(){return this.view.state.doc.toString()}setValue(l,o=0,a=this.view.state.doc.length){this.view.dispatch({changes:{from:o,to:a,insert:l}})}getSelectedText(){const{from:l,to:o}=this.view.state.selection.main;return this.view.state.sliceDoc(l,o)}replaceSelectedText(l,o={select:!0,deviationStart:0,deviationEnd:0,replaceAll:!1},a){try{if(o.replaceAll){if(this.setValue(l),l.length>this.maxLength)throw new Error("The input text is too long");return}if(this.view.state.doc.length-this.getSelectedText().length+l.length>this.maxLength)throw new Error("The input text is too long");const{from:n}=this.view.state.selection.main;if(this.view.dispatch(this.view.state.replaceSelection(l)),o.select){const i=n+l.length+o.deviationEnd;this.view.dispatch({selection:E.EditorSelection.create([E.EditorSelection.range(n+o.deviationStart,i),E.EditorSelection.cursor(i)],1)})}this.view.focus()}catch(n){if(n.message==="The input text is too long")d.bus.emit(a,d.ERROR_CATCHER,{name:"overlength",message:n.message,data:l});else throw n}}setTabSize(l){this.toggleTabSize([E.EditorState.tabSize.of(l),re.indentUnit.of(" ".repeat(l))])}setPlaceholder(l){this.togglePlaceholder(ae.placeholder(l))}focus(l){if(this.view.focus(),!l)return;let o=0,a=0,n=0;switch(l){case"start":break;case"end":{o=a=n=this.getValue().length;break}default:o=l.rangeAnchor||l.cursorPos,a=l.rangeHead||l.cursorPos,n=l.cursorPos}this.view.dispatch({scrollIntoView:!0,selection:E.EditorSelection.create([E.EditorSelection.range(o,a),E.EditorSelection.cursor(n)],1)})}setDisabled(l){this.toggleDisabled([ae.EditorView.editable.of(!l)])}setReadOnly(l){this.toggleReadOnly([E.EditorState.readOnly.of(l)])}setMaxLength(l){this.maxLength=l,this.toggleMaxlength([E.EditorState.changeFilter.of(o=>o.newDoc.length<=l)])}}const fo=e=>{const l=t.inject("editorId");return a=>{if(!a.clipboardData)return;if(a.clipboardData.files.length>0){const{files:i}=a.clipboardData;d.bus.emit(l,d.UPLOAD_IMAGE,Array.from(i).filter(f=>/image\/.*/.test(f.type))),a.preventDefault();return}if(e.autoDetectCode&&a.clipboardData.types.includes("vscode-editor-data")){const i=JSON.parse(a.clipboardData.getData("vscode-editor-data"));d.bus.emit(l,d.REPLACE,"code",{mode:i.mode,text:a.clipboardData.getData("text/plain")}),a.preventDefault();return}const n=a.clipboardData.getData("text/plain");e.maxlength&&n.length+e.modelValue.length>e.maxlength&&d.bus.emit(l,d.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:n})}},go=fo,bo=e=>{const l=t.inject("editorId");t.onMounted(()=>{d.bus.on(l,{name:d.TEXTAREA_FOCUS,callback(o){var a;(a=e.value)==null||a.focus(o)}})})},ho=bo,vo=(e,l)=>{const o={key:"Ctrl-b",mac:"Cmd-b",run:()=>(d.bus.emit(e,d.REPLACE,"bold"),!0)},a={key:"Ctrl-s",mac:"Cmd-s",run:S=>(d.bus.emit(e,d.ON_SAVE,S.state.doc.toString()),!0),shift:()=>(d.bus.emit(e,d.REPLACE,"strikeThrough"),!0)},n={key:"Ctrl-u",mac:"Cmd-u",run:()=>(d.bus.emit(e,d.REPLACE,"underline"),!0),shift:()=>(d.bus.emit(e,d.REPLACE,"unorderedList"),!0)},i={key:"Ctrl-i",mac:"Cmd-i",run:()=>(d.bus.emit(e,d.REPLACE,"italic"),!0),shift:()=>(d.bus.emit(e,d.OPEN_MODALS,"image"),!0)},f={key:"Ctrl-1",mac:"Cmd-1",run:()=>(d.bus.emit(e,d.REPLACE,"h1"),!0)},g={key:"Ctrl-2",mac:"Cmd-2",run:()=>(d.bus.emit(e,d.REPLACE,"h2"),!0)},u={key:"Ctrl-3",mac:"Cmd-3",run:()=>(d.bus.emit(e,d.REPLACE,"h3"),!0)},s={key:"Ctrl-4",mac:"Cmd-4",run:()=>(d.bus.emit(e,d.REPLACE,"h4"),!0)},h={key:"Ctrl-5",mac:"Cmd-5",run:()=>(d.bus.emit(e,d.REPLACE,"h5"),!0)},V={key:"Ctrl-6",mac:"Cmd-6",run:()=>(d.bus.emit(e,d.REPLACE,"h6"),!0)},C={key:"Ctrl-ArrowUp",mac:"Cmd-ArrowUp",run:()=>(d.bus.emit(e,d.REPLACE,"sup"),!0)},m={key:"Ctrl-ArrowDown",mac:"Cmd-ArrowDown",run:()=>(d.bus.emit(e,d.REPLACE,"sub"),!0)},p={key:"Ctrl-o",mac:"Cmd-o",run:()=>(d.bus.emit(e,d.REPLACE,"orderedList"),!0)},b={key:"Ctrl-c",mac:"Cmd-c",shift:()=>(d.bus.emit(e,d.REPLACE,"code"),!0),any(S,A){return(A.ctrlKey||A.metaKey)&&A.altKey&&A.code==="KeyC"?(d.bus.emit(e,d.REPLACE,"codeRow"),!0):!1}},v={key:"Ctrl-l",mac:"Cmd-l",run:()=>(d.bus.emit(e,d.OPEN_MODALS,"link"),!0)},k={key:"Ctrl-f",mac:"Cmd-f",shift:()=>l.noPrettier?!1:(d.bus.emit(e,d.REPLACE,"prettier"),!0)},N={any:(S,A)=>(A.ctrlKey||A.metaKey)&&A.altKey&&A.shiftKey&&A.code==="KeyT"?(d.bus.emit(e,d.REPLACE,"table"),!0):!1},w={key:"Ctrl-d",mac:"Cmd-d",run:ce.deleteLine,preventDefault:!0};return[o,w,a,n,i,f,g,u,s,h,V,C,m,p,b,v,k,N]},po=vo,Co=e=>{const l=t.inject("tabWidth"),o=t.inject("editorId"),a=t.inject("theme"),n=t.ref(),i=t.shallowRef(),f=new E.Compartment,g=new E.Compartment,u=new E.Compartment,s=po(o,e),h=go(e),V=[ae.keymap.of([...s,ce.indentWithTab]),ee.minimalSetup,f.of(kt.markdown({codeLanguages:Ct.languages})),ee.EditorView.lineWrapping,ee.EditorView.updateListener.of(m=>{m.docChanged&&e.onChange(m.state.doc.toString())}),ee.EditorView.domEventHandlers({paste:h,blur:e.onBlur,focus:e.onFocus,drop:e.onDrop,input:m=>{e.onInput&&e.onInput(m);const{data:p}=m;e.maxlength&&e.modelValue.length+p.length>e.maxlength&&d.bus.emit(o,d.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:p})}})],C=()=>{const m=[...V,g.of(a.value==="light"?mt:nt),u.of(gt(e.completions))];return r.configOption.codeMirrorExtensions(a.value,m,[...s])};return t.onMounted(()=>{const m=new ee.EditorView({doc:e.modelValue,parent:n.value,extensions:[C()]}),p=new mo(m);i.value=p,setTimeout(()=>{p.setTabSize(l),p.setDisabled(e.disabled),p.setReadOnly(e.readonly),e.placeholder&&p.setPlaceholder(e.placeholder),typeof e.maxlength=="number"&&p.setMaxLength(e.maxlength),e.autofocus&&m.focus()},0),d.bus.on(o,{name:d.CTRL_Z,callback(){ce.undo(m)}}),d.bus.on(o,{name:d.CTRL_SHIFT_Z,callback(){ce.redo(m)}}),d.bus.on(o,{name:d.REPLACE,callback(b,v={}){var w;const{text:k,options:N}=qt(b,i.value,v);(w=i.value)==null||w.replaceSelectedText(k,N,o)}})}),t.watch(a,()=>{var m;(m=i.value)==null||m.view.dispatch({effects:g.reconfigure(a.value==="light"?mt:nt)})},{deep:!0}),t.watch(()=>e.completions,()=>{var m;(m=i.value)==null||m.view.dispatch({effects:u.reconfigure(gt(e.completions))})},{deep:!0}),t.watch(()=>e.modelValue,()=>{var m,p;((m=i.value)==null?void 0:m.getValue())!==e.modelValue&&((p=i.value)==null||p.setValue(e.modelValue))}),t.watch(()=>e.placeholder,()=>{var m;(m=i.value)==null||m.setPlaceholder(e.placeholder)}),t.watch(()=>e.disabled,()=>{var m;(m=i.value)==null||m.setDisabled(e.disabled)}),t.watch(()=>e.readonly,()=>{var m;(m=i.value)==null||m.setDisabled(e.readonly)}),t.watch(()=>e.maxlength,()=>{var m;e.maxlength&&((m=i.value)==null||m.setMaxLength(e.maxlength))}),ho(i),{inputWrapperRef:n,codeMirrorUt:i}},ko=Co,xo=(e,l,o)=>{const a=t.reactive({resizedWidth:e.inputBoxWitdh}),n=t.reactive({width:e.inputBoxWitdh}),i=t.reactive({left:e.inputBoxWitdh,display:"initial"}),f=s=>{var p,b,v;const h=((p=l.value)==null?void 0:p.offsetWidth)||0,V=((b=l.value)==null?void 0:b.getBoundingClientRect().x)||0;let C=s.x-V;C<r.MinInputBoxWidth?C=r.MinInputBoxWidth:C>h-r.MinInputBoxWidth&&(C=h-r.MinInputBoxWidth);const m=`${C}px`;n.width=m,i.left=m,a.resizedWidth=m,(v=e.onInputBoxWitdhChange)==null||v.call(e,m)},g=()=>{document.addEventListener("mousemove",f)},u=()=>{document.removeEventListener("mousemove",f)};return t.onMounted(()=>{var s;(s=o.value)==null||s.addEventListener("mousedown",g),document.addEventListener("mouseup",u)}),t.onBeforeUnmount(()=>{var s,h;(s=o.value)==null||s.removeEventListener("mousedown",g),(h=o.value)==null||h.removeEventListener("mouseup",u)}),t.watch(()=>e.inputBoxWitdh,s=>{s&&(n.width=s,i.left=s)}),t.watch([t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"preview")],()=>{!e.setting.htmlPreview&&!e.setting.preview?(n.width="100%",i.display="none"):(n.width=a.resizedWidth,i.display="initial")},{immediate:!0}),{inputWrapperStyle:n,resizeOperateStyle:i}},$o=xo,No=t.defineComponent({name:"MDEditorContent",props:P.contentProps,setup(e){const l=t.inject("editorId"),o=t.ref(""),a=t.ref(),n=t.ref(),{inputWrapperRef:i,codeMirrorUt:f}=ko(e),{inputWrapperStyle:g,resizeOperateStyle:u}=$o(e,a,n);return Ft(e,o,f),()=>t.createVNode("div",{class:`${r.prefix}-content${e.setting.htmlPreview||e.setting.preview?" has-preview":""}`,ref:a},[t.createVNode("div",{class:`${r.prefix}-input-wrapper`,style:g,ref:i},null),(e.setting.htmlPreview||e.setting.preview)&&t.createVNode("div",{class:`${r.prefix}-resize-operate`,style:u,ref:n},null),t.createVNode(P.ContentPreview,{modelValue:e.modelValue,setting:e.setting,onHtmlChanged:s=>{o.value=s,e.onHtmlChanged(s)},onGetCatalog:e.onGetCatalog,mdHeadingId:e.mdHeadingId,noMermaid:e.noMermaid,sanitize:e.sanitize,noKatex:e.noKatex,formatCopiedText:e.formatCopiedText,noHighlight:e.noHighlight,noImgZoomIn:e.noImgZoomIn},null),e.catalogVisible&&t.createVNode(bt,{theme:e.theme,class:`${r.prefix}-catalog-editor`,editorId:l,mdHeadingId:e.mdHeadingId,key:"internal-catalog"},null)])}}),Vo=t.defineComponent({props:{modelValue:{type:String,default:""}},setup(e){const l=t.inject("usedLanguageText");return()=>{var o,a;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`},[`${(o=l.value.footer)==null?void 0:o.markdownTotal}:`]),t.createVNode("span",null,[((a=e.modelValue)==null?void 0:a.length)||0])])}}}),wo={checked:{type:Boolean,default:!1},onChange:{type:Function,default:()=>{}}},yo=t.defineComponent({props:wo,setup(e){return()=>t.createVNode("div",{class:[`${r.prefix}-checkbox`,e.checked&&`${r.prefix}-checkbox-checked`],onClick:()=>{e.onChange(!e.checked)}},null)}}),To={scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}}},Eo=t.defineComponent({props:To,setup(e){const l=t.inject("usedLanguageText");return()=>{var o;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`,onClick:()=>{e.onScrollAutoChange(!e.scrollAuto)}},[(o=l.value.footer)==null?void 0:o.scrollAuto]),t.createVNode(yo,{checked:e.scrollAuto,onChange:e.onScrollAutoChange},null)])}}}),So={modelValue:{type:String,default:""},footers:{type:Array,default:[]},scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}},defFooters:{type:Object}},Ao=t.defineComponent({name:"MDEditorFooter",props:So,setup(e){const l=t.computed(()=>{const a=e.footers.indexOf("="),n=a===-1?e.footers:e.footers.slice(0,a),i=a===-1?[]:e.footers.slice(a,Number.MAX_SAFE_INTEGER);return[n,i]}),o=a=>{if(r.allFooter.includes(a))switch(a){case"markdownTotal":return t.createVNode(Vo,{modelValue:e.modelValue},null);case"scrollSwitch":return t.createVNode(Eo,{scrollAuto:e.scrollAuto,onScrollAutoChange:e.onScrollAutoChange},null)}else return e.defFooters instanceof Array?e.defFooters[a]||"":e.defFooters&&e.defFooters.children instanceof Array&&e.defFooters.children[a]||""};return()=>{const a=l.value[0].map(i=>o(i)),n=l.value[1].map(i=>o(i));return t.createVNode("div",{class:`${r.prefix}-footer`},[t.createVNode("div",{class:`${r.prefix}-footer-left`},[a]),t.createVNode("div",{class:`${r.prefix}-footer-right`},[n])])}}}),Io=t.defineComponent({name:"MdEditorV3",props:P.editorProps,emits:P.editorEmits,setup(e,l){const{editorId:o,noKatex:a,noMermaid:n,noPrettier:i,noUploadImg:f,noHighlight:g}=e,u=t.reactive({scrollAuto:e.scrollAuto});P.useOnSave(e,l),P.useProvide(e),P.useExpansion(e),P.useErrorCatcher(e,l);const[s,h]=P.useConfig(e,l),V=P.useCatalog(e);return t.onBeforeUnmount(()=>{d.bus.clear(o)}),P.useExpose(e,l,V,s,h),()=>{var p;const C=et.getSlot({props:e,ctx:l},"defToolbars"),m=et.getSlot({props:e,ctx:l},"defFooters");return t.createVNode("div",{id:o,class:[r.prefix,e.class,e.theme==="dark"&&`${r.prefix}-dark`,s.fullscreen||s.pageFullscreen?`${r.prefix}-fullscreen`:""],style:e.style},[t.createVNode(Ht,{noPrettier:i,toolbars:e.toolbars,toolbarsExclude:e.toolbarsExclude,setting:s,updateSetting:h,tableShape:e.tableShape,defToolbars:C,noUploadImg:f,showToolbarName:e.showToolbarName},null),t.createVNode(No,{modelValue:e.modelValue,setting:s,mdHeadingId:e.mdHeadingId,noMermaid:n,noPrettier:i,sanitize:e.sanitize,placeholder:e.placeholder,noKatex:a,scrollAuto:u.scrollAuto,formatCopiedText:e.formatCopiedText,autofocus:e.autoFocus,disabled:e.disabled,readonly:e.readOnly,maxlength:e.maxLength,autoDetectCode:e.autoDetectCode,noHighlight:g,onChange:b=>{e.onChange?e.onChange(b):(l.emit("update:modelValue",b),l.emit("onChange",b))},onHtmlChanged:b=>{e.onHtmlChanged?e.onHtmlChanged(b):l.emit("onHtmlChanged",b)},onGetCatalog:b=>{e.onGetCatalog?e.onGetCatalog(b):l.emit("onGetCatalog",b)},onBlur:b=>{e.onBlur?e.onBlur(b):l.emit("onBlur",b)},onFocus:b=>{e.onFocus?e.onFocus(b):l.emit("onFocus",b)},onInput:b=>{e.onInput?e.onInput(b):l.emit("onInput",b)},completions:e.completions,catalogVisible:V.value,theme:e.theme,noImgZoomIn:e.noImgZoomIn,onDrop:b=>{e.onDrop?e.onDrop(b):l.emit("onDrop",b)},inputBoxWitdh:e.inputBoxWitdh,onInputBoxWitdhChange:b=>{e.onInputBoxWitdhChange?e.onInputBoxWitdhChange(b):l.emit("onInputBoxWitdhChange",b)}},null),((p=e.footers)==null?void 0:p.length)>0&&t.createVNode(Ao,{modelValue:e.modelValue,footers:e.footers,defFooters:m,scrollAuto:u.scrollAuto,onScrollAutoChange:b=>u.scrollAuto=b},null)])}}}),de=Io;de.install=e=>(e.component(de.name,de),e.use($t).use(K.DropdownToolbar).use(Nt).use(bt).use(P.MdPreview),e);module.exports=de;
|
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
`+l(u,x,f,w,b);return`<div class="code-tabs">
|
|
6
6
|
<ul>
|
|
7
7
|
`+I+`</ul>
|
|
8
|
-
`+$+"</div>"};e.renderer.rules.fence=m},pe=de,me=e=>{["paragraph_open","table_open","ordered_list_open","bullet_list_open","blockquote_open","hr","html_block","fence"].forEach(i=>{const l=e.renderer.rules[i];l?e.renderer.rules[i]=(t,n,r,a,s)=>{let m;const u=l(t,n,r,a,s);return t[n].map&&t[n].level===0?(m=t[n].map[0],u.replace(/^(<[^>]*)/,`$1 data-line="${m}"`)):u}:e.renderer.rules[i]=(t,n,r,a,s)=>{let m;return t[n].map&&t[n].level===0&&(m=t[n].map[0],t[n].attrSet("data-line",String(m))),s.renderToken(t,n,r)}})},fe=(e,i)=>{const{editorConfig:l,markdownItConfig:t,markdownItPlugins:n}=d.configOption,r=c.inject("editorId"),a=c.inject("showCodeRowNumber"),s=c.inject("theme"),m=c.ref([]),u=J(e),o=ee(e),{reRenderRef:f,replaceMermaid:w}=Q(e),b=G({html:!0,breaks:!0});t(b);const h=[{type:"katex",plugin:le,options:{katexRef:o}},{type:"image",plugin:j,options:{figcaption:!0,classes:"md-zoom"}},{type:"admonition",plugin:ce,options:{}},{type:"taskList",plugin:D,options:{}},{type:"heading",plugin:ue,options:{mdHeadingId:e.mdHeadingId,headsRef:m}},{type:"codeTabs",plugin:pe,options:{editorId:r}}];e.noMermaid||h.push({type:"mermaid",plugin:ne,options:{themeRef:s}}),n(h).forEach(k=>{b.use(k.plugin,k.options)}),b.set({highlight:(k,I)=>{let $;!e.noHighlight&&u.value?u.value.getLanguage(I)?$=u.value.highlight(k,{language:I,ignoreIllegals:!0}).value:$=u.value.highlightAuto(k).value:$=b.utils.escapeHtml(k);const x=a?p.generateCodeRowNumber($.replace(/^\n+|\n+$/g,"")):`<span class="code-block">${$.replace(/^\n+|\n+$/g,"")}</span>`;return`<pre><code class="language-${I}" language=${I}>${x}</code></pre>`}}),me(b);const v=c.ref(e.sanitize(b.render(e.modelValue))),g=()=>{p.bus.emit(r,p.BUILD_FINISHED,v.value),e.onHtmlChanged(v.value),e.onGetCatalog(m.value),p.bus.emit(r,p.CATALOG_CHANGED,m.value),w()};c.onMounted(g);const C=P.debounce(async()=>{m.value=[],v.value=e.sanitize(b.render(e.modelValue)),g()},(l==null?void 0:l.renderDelay)!==void 0?l==null?void 0:l.renderDelay:i?0:500),y=c.computed(()=>(e.noKatex||o.value)&&(e.noHighlight||u.value));return c.watch([c.toRef(e,"modelValue"),y,f],C),c.onMounted(()=>{p.bus.on(r,{name:p.PUSH_CATALOG,callback(){p.bus.emit(r,p.CATALOG_CHANGED,m.value)}})}),{html:v}},he=fe,T={modelValue:{type:String,default:""},setting:{type:Object,default:()=>({})},onHtmlChanged:{type:Function,default:()=>{}},onGetCatalog:{type:Function,default:()=>{}},mdHeadingId:{type:Function,default:()=>""},noMermaid:{type:Boolean,default:!1},sanitize:{type:Function,default:e=>e},noKatex:{type:Boolean,default:!1},formatCopiedText:{type:Function,default:e=>e},noHighlight:{type:Boolean,default:!1},previewOnly:{type:Boolean,default:!1},noImgZoomIn:{type:Boolean}},ge={...T,onChange:{type:Function,default:()=>{}},placeholder:{type:String,default:""},scrollAuto:{type:Boolean},autofocus:{type:Boolean},disabled:{type:Boolean},readonly:{type:Boolean},maxlength:{type:Number},autoDetectCode:{type:Boolean},onBlur:{type:Function,default:()=>{}},onFocus:{type:Function,default:()=>{}},noPrettier:{type:Boolean},completions:{type:Array},catalogVisible:{type:Boolean},theme:{type:String,default:"light"},onInput:{type:Function},onDrop:{type:Function,default:()=>{}},inputBoxWitdh:{type:String},onInputBoxWitdhChange:{type:Function}},A=c.defineComponent({name:"ContentPreview",props:T,setup(e){const i=c.inject("editorId"),l=c.inject("previewTheme"),t=c.inject("showCodeRowNumber"),{html:n}=he(e,e.previewOnly);return K(e,n),q(e,n),()=>c.createVNode(c.Fragment,null,[c.createVNode("div",{id:`${i}-preview-wrapper`,class:`${d.prefix}-preview-wrapper`,"data-show":e.setting.preview,key:"content-preview-wrapper"},[c.createVNode("article",{id:`${i}-preview`,class:[`${d.prefix}-preview`,`${l==null?void 0:l.value}-theme`,t&&`${d.prefix}-scrn`],innerHTML:n.value},null)]),!e.previewOnly&&c.createVNode("div",{id:`${i}-html-wrapper`,class:`${d.prefix}-preview-wrapper`,"data-show":e.setting.htmlPreview,key:"html-preview-wrapper"},[c.createVNode("div",{class:`${d.prefix}-html`},[n.value])])])}}),ve=(e,i)=>{const{editorId:l}=e,t=c.reactive({buildFinished:!1,html:""});c.watch(()=>e.modelValue,()=>{t.buildFinished=!1}),c.onMounted(()=>{p.bus.on(l,{name:p.BUILD_FINISHED,callback(n){t.buildFinished=!0,t.html=n}}),p.bus.on(l,{name:p.ON_SAVE,callback(){const n=new Promise(r=>{if(t.buildFinished)r(t.html);else{const a=s=>{r(s),p.bus.remove(l,p.BUILD_FINISHED,a)};p.bus.on(l,{name:p.BUILD_FINISHED,callback:a})}});e.onSave?e.onSave(e.modelValue,n):i.emit("onSave",e.modelValue,n)}})})},M=e=>{var n,r;const{editorId:i}=e,l=(r=(n=d.configOption)==null?void 0:n.editorExtensions)==null?void 0:r.highlight;c.provide("editorId",i),c.provide("theme",c.computed(()=>e.theme)),c.provide("language",c.computed(()=>e.language)),c.provide("highlight",c.computed(()=>{const a={...d.codeCss,...l==null?void 0:l.css},s=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme;return{js:(l==null?void 0:l.js)||d.highlightUrl,css:a[e.codeTheme]?a[e.codeTheme][s]:d.codeCss.atom[s]}})),c.provide("showCodeRowNumber",e.showCodeRowNumber);const t=c.computed(()=>{var s,m;const a={...d.staticTextDefault,...(m=(s=d.configOption)==null?void 0:s.editorConfig)==null?void 0:m.languageUserDefined};return a[e.language]?a[e.language]:d.staticTextDefault["zh-CN"]});c.provide("usedLanguageText",t),c.provide("previewTheme",c.computed(()=>e.previewTheme)),c.provide("customIcon",c.computed(()=>e.customIcon))},ye=e=>{M(e),c.provide("tabWidth",e.tabWidth)},F=e=>{c.onMounted(()=>{var i,l;if(!e.noIconfont)if(d.configOption.iconfontType==="svg"){const t=document.createElement("script");t.src=((i=d.configOption.editorExtensions)==null?void 0:i.iconfont)||d.iconfontSvgUrl,t.id=`${d.prefix}-icon`,E.appendHandler(t)}else{const t=document.createElement("link");t.rel="stylesheet",t.href=((l=d.configOption.editorExtensions)==null?void 0:l.iconfontClass)||d.iconfontClassUrl,t.id=`${d.prefix}-icon-class`,E.appendHandler(t)}})},be=e=>{var s,m,u,o,f,w;const{noPrettier:i,noUploadImg:l}=e,{editorExtensions:t}=d.configOption,n=i||!!((m=(s=d.configOption.editorExtensions)==null?void 0:s.prettier)!=null&&m.prettierInstance),r=i||!!((o=(u=d.configOption.editorExtensions)==null?void 0:u.prettier)!=null&&o.parserMarkdownInstance),a=l||!!((w=(f=d.configOption.editorExtensions)==null?void 0:f.cropper)!=null&&w.instance);c.onMounted(()=>{var C,y,k,I;const b=document.createElement("script"),h=document.createElement("script");b.src=((C=t==null?void 0:t.prettier)==null?void 0:C.standaloneJs)||d.prettierUrl.main,b.id=`${d.prefix}-prettier`,h.src=((y=t==null?void 0:t.prettier)==null?void 0:y.parserMarkdownJs)||d.prettierUrl.markdown,h.id=`${d.prefix}-prettierMD`;const v=document.createElement("link");v.rel="stylesheet",v.href=((k=t==null?void 0:t.cropper)==null?void 0:k.css)||d.cropperUrl.css,v.id=`${d.prefix}-cropperCss`;const g=document.createElement("script");g.src=((I=t==null?void 0:t.cropper)==null?void 0:I.js)||d.cropperUrl.js,g.id=`${d.prefix}-cropper`,a||(E.appendHandler(v),E.appendHandler(g)),n||E.appendHandler(b),r||E.appendHandler(h)}),F(e)},we=(e,i)=>{const{editorId:l}=e;c.onMounted(()=>{p.bus.on(l,{name:p.ERROR_CATCHER,callback:t=>{e.onError instanceof Function?e.onError(t):i.emit("onError",t)}})})},ke=(e,i)=>{const{editorId:l}=e,t=c.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview}),n=(s,m)=>{t[s]=m===void 0?!t[s]:m,s==="preview"&&t.preview?t.htmlPreview=!1:s==="htmlPreview"&&t.htmlPreview&&(t.preview=!1)};let r="";const a=()=>{t.pageFullscreen||t.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=r};return c.watch(()=>[t.pageFullscreen,t.fullscreen],a),c.onMounted(()=>{p.bus.on(l,{name:p.UPLOAD_IMAGE,callback(s,m){const u=o=>{p.bus.emit(l,p.REPLACE,"image",{desc:"",urls:o}),m&&m()};e.onUploadImg?e.onUploadImg(s,u):i.emit("onUploadImg",s,u)}}),r=document.body.style.overflow,a()}),[t,n]},Ce=e=>{const{editorId:i}=e,l=c.ref(!1);return c.onMounted(()=>{p.bus.on(i,{name:p.CHANGE_CATALOG_VISIBLE,callback:n=>{n===void 0?l.value=!l.value:l.value=n}})}),c.computed(()=>!e.toolbarsExclude.includes("catalog")&&e.toolbars.includes("catalog")&&l.value)},Ie=(e,i,l,t,n)=>{const{editorId:r}=e;c.watch(()=>t.pageFullscreen,s=>{p.bus.emit(r,p.PAGE_FULL_SCREEN_CHANGED,s)}),c.watch(()=>t.fullscreen,s=>{p.bus.emit(r,p.FULL_SCREEN_CHANGED,s)}),c.watch(()=>t.preview,s=>{p.bus.emit(r,p.PREVIEW_CHANGED,s)}),c.watch(()=>t.htmlPreview,s=>{p.bus.emit(r,p.HTML_PREVIEW_CHANGED,s)}),c.watch(l,s=>{p.bus.emit(r,p.CATALOG_VISIBLE_CHANGED,s)});const a={on(s,m){switch(s){case"pageFullscreen":{p.bus.on(r,{name:p.PAGE_FULL_SCREEN_CHANGED,callback(u){m(u)}});break}case"fullscreen":{p.bus.on(r,{name:p.FULL_SCREEN_CHANGED,callback(u){m(u)}});break}case"preview":{p.bus.on(r,{name:p.PREVIEW_CHANGED,callback(u){m(u)}});break}case"htmlPreview":{p.bus.on(r,{name:p.HTML_PREVIEW_CHANGED,callback(u){m(u)}});break}case"catalog":{p.bus.on(r,{name:p.CATALOG_VISIBLE_CHANGED,callback(u){m(u)}});break}}},togglePageFullscreen(s){n("pageFullscreen",s)},toggleFullscreen(s){p.bus.emit(r,p.CHANGE_FULL_SCREEN,s)},togglePreview(s){n("preview",s)},toggleHtmlPreview(s){n("htmlPreview",s)},toggleCatalog(s){p.bus.emit(r,p.CHANGE_CATALOG_VISIBLE,s)},triggerSave(){p.bus.emit(r,p.ON_SAVE)},insert(s){p.bus.emit(r,p.REPLACE,"universal",{generate:s})},focus(s){p.bus.emit(r,p.TEXTAREA_FOCUS,s)}};i.expose(a)},$e=e=>e,R={modelValue:{type:String,default:""},theme:{type:String,default:"light"},class:{type:String,default:""},language:{type:String,default:"zh-CN"},onHtmlChanged:{type:Function},onGetCatalog:{type:Function},editorId:{type:String,default:d.defaultEditorId},showCodeRowNumber:{type:Boolean,default:!1},previewTheme:{type:String,default:"default"},style:{type:Object,default:()=>({})},mdHeadingId:{type:Function,default:$e},sanitize:{type:Function,default:e=>e},noMermaid:{type:Boolean,default:!1},noKatex:{type:Boolean,default:!1},codeTheme:{type:String,default:"atom"},noIconfont:{type:Boolean},formatCopiedText:{type:Function,default:e=>e},codeStyleReverse:{type:Boolean,default:!0},codeStyleReverseList:{type:Array,default:["default","mk-cute"]},noHighlight:{type:Boolean,default:!1},noImgZoomIn:{type:Boolean,default:!1},customIcon:{type:Object,default:{}}},Ee={...R,onChange:{type:Function},onSave:{type:Function},onUploadImg:{type:Function},pageFullscreen:{type:Boolean,default:!1},preview:{type:Boolean,default:!0},htmlPreview:{type:Boolean,default:!1},toolbars:{type:Array,default:d.allToolbar},toolbarsExclude:{type:Array,default:[]},noPrettier:{type:Boolean,default:!1},tabWidth:{type:Number,default:2},tableShape:{type:Array,default:()=>[6,4]},placeholder:{type:String,default:""},defToolbars:{type:[String,Object]},onError:{type:Function},footers:{type:Array,default:d.allFooter},scrollAuto:{type:Boolean,default:!0},defFooters:{type:[String,Object]},noUploadImg:{type:Boolean},autoFocus:{type:Boolean},disabled:{type:Boolean},readOnly:{type:Boolean},maxLength:{type:Number},autoDetectCode:{type:Boolean},onBlur:{type:Function},onFocus:{type:Function},completions:{type:Array},showToolbarName:{type:Boolean,default:!1},onInput:{type:Function},onDrop:{type:Function},inputBoxWitdh:{type:String,default:"50%"},onInputBoxWitdhChange:{type:Function}},L=["onHtmlChanged","onGetCatalog"],xe=[...L,"onChange","onSave","onUploadImg","onError","update:modelValue","onBlur","onFocus","onInput","onDrop","onInputBoxWitdhChange"],Se=c.defineComponent({name:"MdPreview",props:R,emits:L,setup(e,i){const{editorId:l,noKatex:t,noMermaid:n,noHighlight:r}=e;return M(e),F(e),c.onBeforeUnmount(()=>{p.bus.clear(l)}),()=>c.createVNode("div",{id:l,class:[d.prefix,e.class,e.theme==="dark"&&`${d.prefix}-dark`,`${d.prefix}-previewOnly`],style:e.style},[c.createVNode(A,{modelValue:e.modelValue,onHtmlChanged:a=>{e.onHtmlChanged?e.onHtmlChanged(a):i.emit("onHtmlChanged",a)},onGetCatalog:a=>{e.onGetCatalog?e.onGetCatalog(a):i.emit("onGetCatalog",a)},mdHeadingId:e.mdHeadingId,noMermaid:n,sanitize:e.sanitize,noKatex:t,formatCopiedText:e.formatCopiedText,noHighlight:r,noImgZoomIn:e.noImgZoomIn,previewOnly:!0},null)])}}),S=Se;S.install=e=>(e.component(S.name,S),e);exports.ContentPreview=A;exports.MdPreview=S;exports.contentProps=ge;exports.editorEmits=xe;exports.editorProps=Ee;exports.useCatalog=Ce;exports.useConfig=ke;exports.useErrorCatcher=we;exports.useExpansion=be;exports.useExpose=Ie;exports.useOnSave=ve;exports.useProvide=ye;
|
|
8
|
+
`+$+"</div>"};e.renderer.rules.fence=m},pe=de,me=e=>{["paragraph_open","table_open","ordered_list_open","bullet_list_open","blockquote_open","hr","html_block","fence"].forEach(i=>{const l=e.renderer.rules[i];l?e.renderer.rules[i]=(t,n,r,a,s)=>{let m;const u=l(t,n,r,a,s);return t[n].map&&t[n].level===0&&!/^<!--/.test(u)?(m=t[n].map[0],u.replace(/^(<[^>]*)/,`$1 data-line="${m}"`)):u}:e.renderer.rules[i]=(t,n,r,a,s)=>{let m;return t[n].map&&t[n].level===0&&(m=t[n].map[0],t[n].attrSet("data-line",String(m))),s.renderToken(t,n,r)}})},fe=(e,i)=>{const{editorConfig:l,markdownItConfig:t,markdownItPlugins:n}=d.configOption,r=c.inject("editorId"),a=c.inject("showCodeRowNumber"),s=c.inject("theme"),m=c.ref([]),u=J(e),o=ee(e),{reRenderRef:f,replaceMermaid:w}=Q(e),b=G({html:!0,breaks:!0});t(b);const h=[{type:"katex",plugin:le,options:{katexRef:o}},{type:"image",plugin:j,options:{figcaption:!0,classes:"md-zoom"}},{type:"admonition",plugin:ce,options:{}},{type:"taskList",plugin:D,options:{}},{type:"heading",plugin:ue,options:{mdHeadingId:e.mdHeadingId,headsRef:m}},{type:"codeTabs",plugin:pe,options:{editorId:r}}];e.noMermaid||h.push({type:"mermaid",plugin:ne,options:{themeRef:s}}),n(h).forEach(k=>{b.use(k.plugin,k.options)}),b.set({highlight:(k,I)=>{let $;!e.noHighlight&&u.value?u.value.getLanguage(I)?$=u.value.highlight(k,{language:I,ignoreIllegals:!0}).value:$=u.value.highlightAuto(k).value:$=b.utils.escapeHtml(k);const x=a?p.generateCodeRowNumber($.replace(/^\n+|\n+$/g,"")):`<span class="code-block">${$.replace(/^\n+|\n+$/g,"")}</span>`;return`<pre><code class="language-${I}" language=${I}>${x}</code></pre>`}}),me(b);const v=c.ref(e.sanitize(b.render(e.modelValue))),g=()=>{p.bus.emit(r,p.BUILD_FINISHED,v.value),e.onHtmlChanged(v.value),e.onGetCatalog(m.value),p.bus.emit(r,p.CATALOG_CHANGED,m.value),w()};c.onMounted(g);const C=P.debounce(async()=>{m.value=[],v.value=e.sanitize(b.render(e.modelValue)),g()},(l==null?void 0:l.renderDelay)!==void 0?l==null?void 0:l.renderDelay:i?0:500),y=c.computed(()=>(e.noKatex||o.value)&&(e.noHighlight||u.value));return c.watch([c.toRef(e,"modelValue"),y,f],C),c.onMounted(()=>{p.bus.on(r,{name:p.PUSH_CATALOG,callback(){p.bus.emit(r,p.CATALOG_CHANGED,m.value)}})}),{html:v}},he=fe,T={modelValue:{type:String,default:""},setting:{type:Object,default:()=>({})},onHtmlChanged:{type:Function,default:()=>{}},onGetCatalog:{type:Function,default:()=>{}},mdHeadingId:{type:Function,default:()=>""},noMermaid:{type:Boolean,default:!1},sanitize:{type:Function,default:e=>e},noKatex:{type:Boolean,default:!1},formatCopiedText:{type:Function,default:e=>e},noHighlight:{type:Boolean,default:!1},previewOnly:{type:Boolean,default:!1},noImgZoomIn:{type:Boolean}},ge={...T,onChange:{type:Function,default:()=>{}},placeholder:{type:String,default:""},scrollAuto:{type:Boolean},autofocus:{type:Boolean},disabled:{type:Boolean},readonly:{type:Boolean},maxlength:{type:Number},autoDetectCode:{type:Boolean},onBlur:{type:Function,default:()=>{}},onFocus:{type:Function,default:()=>{}},noPrettier:{type:Boolean},completions:{type:Array},catalogVisible:{type:Boolean},theme:{type:String,default:"light"},onInput:{type:Function},onDrop:{type:Function,default:()=>{}},inputBoxWitdh:{type:String},onInputBoxWitdhChange:{type:Function}},A=c.defineComponent({name:"ContentPreview",props:T,setup(e){const i=c.inject("editorId"),l=c.inject("previewTheme"),t=c.inject("showCodeRowNumber"),{html:n}=he(e,e.previewOnly);return K(e,n),q(e,n),()=>c.createVNode(c.Fragment,null,[c.createVNode("div",{id:`${i}-preview-wrapper`,class:`${d.prefix}-preview-wrapper`,"data-show":e.setting.preview,key:"content-preview-wrapper"},[c.createVNode("article",{id:`${i}-preview`,class:[`${d.prefix}-preview`,`${l==null?void 0:l.value}-theme`,t&&`${d.prefix}-scrn`],innerHTML:n.value},null)]),!e.previewOnly&&c.createVNode("div",{id:`${i}-html-wrapper`,class:`${d.prefix}-preview-wrapper`,"data-show":e.setting.htmlPreview,key:"html-preview-wrapper"},[c.createVNode("div",{class:`${d.prefix}-html`},[n.value])])])}}),ve=(e,i)=>{const{editorId:l}=e,t=c.reactive({buildFinished:!1,html:""});c.watch(()=>e.modelValue,()=>{t.buildFinished=!1}),c.onMounted(()=>{p.bus.on(l,{name:p.BUILD_FINISHED,callback(n){t.buildFinished=!0,t.html=n}}),p.bus.on(l,{name:p.ON_SAVE,callback(){const n=new Promise(r=>{if(t.buildFinished)r(t.html);else{const a=s=>{r(s),p.bus.remove(l,p.BUILD_FINISHED,a)};p.bus.on(l,{name:p.BUILD_FINISHED,callback:a})}});e.onSave?e.onSave(e.modelValue,n):i.emit("onSave",e.modelValue,n)}})})},M=e=>{var n,r;const{editorId:i}=e,l=(r=(n=d.configOption)==null?void 0:n.editorExtensions)==null?void 0:r.highlight;c.provide("editorId",i),c.provide("theme",c.computed(()=>e.theme)),c.provide("language",c.computed(()=>e.language)),c.provide("highlight",c.computed(()=>{const a={...d.codeCss,...l==null?void 0:l.css},s=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme;return{js:(l==null?void 0:l.js)||d.highlightUrl,css:a[e.codeTheme]?a[e.codeTheme][s]:d.codeCss.atom[s]}})),c.provide("showCodeRowNumber",e.showCodeRowNumber);const t=c.computed(()=>{var s,m;const a={...d.staticTextDefault,...(m=(s=d.configOption)==null?void 0:s.editorConfig)==null?void 0:m.languageUserDefined};return a[e.language]?a[e.language]:d.staticTextDefault["zh-CN"]});c.provide("usedLanguageText",t),c.provide("previewTheme",c.computed(()=>e.previewTheme)),c.provide("customIcon",c.computed(()=>e.customIcon))},ye=e=>{M(e),c.provide("tabWidth",e.tabWidth)},F=e=>{c.onMounted(()=>{var i,l;if(!e.noIconfont)if(d.configOption.iconfontType==="svg"){const t=document.createElement("script");t.src=((i=d.configOption.editorExtensions)==null?void 0:i.iconfont)||d.iconfontSvgUrl,t.id=`${d.prefix}-icon`,E.appendHandler(t)}else{const t=document.createElement("link");t.rel="stylesheet",t.href=((l=d.configOption.editorExtensions)==null?void 0:l.iconfontClass)||d.iconfontClassUrl,t.id=`${d.prefix}-icon-class`,E.appendHandler(t)}})},be=e=>{var s,m,u,o,f,w;const{noPrettier:i,noUploadImg:l}=e,{editorExtensions:t}=d.configOption,n=i||!!((m=(s=d.configOption.editorExtensions)==null?void 0:s.prettier)!=null&&m.prettierInstance),r=i||!!((o=(u=d.configOption.editorExtensions)==null?void 0:u.prettier)!=null&&o.parserMarkdownInstance),a=l||!!((w=(f=d.configOption.editorExtensions)==null?void 0:f.cropper)!=null&&w.instance);c.onMounted(()=>{var C,y,k,I;const b=document.createElement("script"),h=document.createElement("script");b.src=((C=t==null?void 0:t.prettier)==null?void 0:C.standaloneJs)||d.prettierUrl.main,b.id=`${d.prefix}-prettier`,h.src=((y=t==null?void 0:t.prettier)==null?void 0:y.parserMarkdownJs)||d.prettierUrl.markdown,h.id=`${d.prefix}-prettierMD`;const v=document.createElement("link");v.rel="stylesheet",v.href=((k=t==null?void 0:t.cropper)==null?void 0:k.css)||d.cropperUrl.css,v.id=`${d.prefix}-cropperCss`;const g=document.createElement("script");g.src=((I=t==null?void 0:t.cropper)==null?void 0:I.js)||d.cropperUrl.js,g.id=`${d.prefix}-cropper`,a||(E.appendHandler(v),E.appendHandler(g)),n||E.appendHandler(b),r||E.appendHandler(h)}),F(e)},we=(e,i)=>{const{editorId:l}=e;c.onMounted(()=>{p.bus.on(l,{name:p.ERROR_CATCHER,callback:t=>{e.onError instanceof Function?e.onError(t):i.emit("onError",t)}})})},ke=(e,i)=>{const{editorId:l}=e,t=c.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview}),n=(s,m)=>{t[s]=m===void 0?!t[s]:m,s==="preview"&&t.preview?t.htmlPreview=!1:s==="htmlPreview"&&t.htmlPreview&&(t.preview=!1)};let r="";const a=()=>{t.pageFullscreen||t.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=r};return c.watch(()=>[t.pageFullscreen,t.fullscreen],a),c.onMounted(()=>{p.bus.on(l,{name:p.UPLOAD_IMAGE,callback(s,m){const u=o=>{p.bus.emit(l,p.REPLACE,"image",{desc:"",urls:o}),m&&m()};e.onUploadImg?e.onUploadImg(s,u):i.emit("onUploadImg",s,u)}}),r=document.body.style.overflow,a()}),[t,n]},Ce=e=>{const{editorId:i}=e,l=c.ref(!1);return c.onMounted(()=>{p.bus.on(i,{name:p.CHANGE_CATALOG_VISIBLE,callback:n=>{n===void 0?l.value=!l.value:l.value=n}})}),c.computed(()=>!e.toolbarsExclude.includes("catalog")&&e.toolbars.includes("catalog")&&l.value)},Ie=(e,i,l,t,n)=>{const{editorId:r}=e;c.watch(()=>t.pageFullscreen,s=>{p.bus.emit(r,p.PAGE_FULL_SCREEN_CHANGED,s)}),c.watch(()=>t.fullscreen,s=>{p.bus.emit(r,p.FULL_SCREEN_CHANGED,s)}),c.watch(()=>t.preview,s=>{p.bus.emit(r,p.PREVIEW_CHANGED,s)}),c.watch(()=>t.htmlPreview,s=>{p.bus.emit(r,p.HTML_PREVIEW_CHANGED,s)}),c.watch(l,s=>{p.bus.emit(r,p.CATALOG_VISIBLE_CHANGED,s)});const a={on(s,m){switch(s){case"pageFullscreen":{p.bus.on(r,{name:p.PAGE_FULL_SCREEN_CHANGED,callback(u){m(u)}});break}case"fullscreen":{p.bus.on(r,{name:p.FULL_SCREEN_CHANGED,callback(u){m(u)}});break}case"preview":{p.bus.on(r,{name:p.PREVIEW_CHANGED,callback(u){m(u)}});break}case"htmlPreview":{p.bus.on(r,{name:p.HTML_PREVIEW_CHANGED,callback(u){m(u)}});break}case"catalog":{p.bus.on(r,{name:p.CATALOG_VISIBLE_CHANGED,callback(u){m(u)}});break}}},togglePageFullscreen(s){n("pageFullscreen",s)},toggleFullscreen(s){p.bus.emit(r,p.CHANGE_FULL_SCREEN,s)},togglePreview(s){n("preview",s)},toggleHtmlPreview(s){n("htmlPreview",s)},toggleCatalog(s){p.bus.emit(r,p.CHANGE_CATALOG_VISIBLE,s)},triggerSave(){p.bus.emit(r,p.ON_SAVE)},insert(s){p.bus.emit(r,p.REPLACE,"universal",{generate:s})},focus(s){p.bus.emit(r,p.TEXTAREA_FOCUS,s)}};i.expose(a)},$e=e=>e,R={modelValue:{type:String,default:""},theme:{type:String,default:"light"},class:{type:String,default:""},language:{type:String,default:"zh-CN"},onHtmlChanged:{type:Function},onGetCatalog:{type:Function},editorId:{type:String,default:d.defaultEditorId},showCodeRowNumber:{type:Boolean,default:!1},previewTheme:{type:String,default:"default"},style:{type:Object,default:()=>({})},mdHeadingId:{type:Function,default:$e},sanitize:{type:Function,default:e=>e},noMermaid:{type:Boolean,default:!1},noKatex:{type:Boolean,default:!1},codeTheme:{type:String,default:"atom"},noIconfont:{type:Boolean},formatCopiedText:{type:Function,default:e=>e},codeStyleReverse:{type:Boolean,default:!0},codeStyleReverseList:{type:Array,default:["default","mk-cute"]},noHighlight:{type:Boolean,default:!1},noImgZoomIn:{type:Boolean,default:!1},customIcon:{type:Object,default:{}}},Ee={...R,onChange:{type:Function},onSave:{type:Function},onUploadImg:{type:Function},pageFullscreen:{type:Boolean,default:!1},preview:{type:Boolean,default:!0},htmlPreview:{type:Boolean,default:!1},toolbars:{type:Array,default:d.allToolbar},toolbarsExclude:{type:Array,default:[]},noPrettier:{type:Boolean,default:!1},tabWidth:{type:Number,default:2},tableShape:{type:Array,default:()=>[6,4]},placeholder:{type:String,default:""},defToolbars:{type:[String,Object]},onError:{type:Function},footers:{type:Array,default:d.allFooter},scrollAuto:{type:Boolean,default:!0},defFooters:{type:[String,Object]},noUploadImg:{type:Boolean},autoFocus:{type:Boolean},disabled:{type:Boolean},readOnly:{type:Boolean},maxLength:{type:Number},autoDetectCode:{type:Boolean},onBlur:{type:Function},onFocus:{type:Function},completions:{type:Array},showToolbarName:{type:Boolean,default:!1},onInput:{type:Function},onDrop:{type:Function},inputBoxWitdh:{type:String,default:"50%"},onInputBoxWitdhChange:{type:Function}},L=["onHtmlChanged","onGetCatalog"],xe=[...L,"onChange","onSave","onUploadImg","onError","update:modelValue","onBlur","onFocus","onInput","onDrop","onInputBoxWitdhChange"],Se=c.defineComponent({name:"MdPreview",props:R,emits:L,setup(e,i){const{editorId:l,noKatex:t,noMermaid:n,noHighlight:r}=e;return M(e),F(e),c.onBeforeUnmount(()=>{p.bus.clear(l)}),()=>c.createVNode("div",{id:l,class:[d.prefix,e.class,e.theme==="dark"&&`${d.prefix}-dark`,`${d.prefix}-previewOnly`],style:e.style},[c.createVNode(A,{modelValue:e.modelValue,onHtmlChanged:a=>{e.onHtmlChanged?e.onHtmlChanged(a):i.emit("onHtmlChanged",a)},onGetCatalog:a=>{e.onGetCatalog?e.onGetCatalog(a):i.emit("onGetCatalog",a)},mdHeadingId:e.mdHeadingId,noMermaid:n,sanitize:e.sanitize,noKatex:t,formatCopiedText:e.formatCopiedText,noHighlight:r,noImgZoomIn:e.noImgZoomIn,previewOnly:!0},null)])}}),S=Se;S.install=e=>(e.component(S.name,S),e);exports.ContentPreview=A;exports.MdPreview=S;exports.contentProps=ge;exports.editorEmits=xe;exports.editorProps=Ee;exports.useCatalog=Ce;exports.useConfig=ke;exports.useErrorCatcher=we;exports.useExpansion=be;exports.useExpose=Ie;exports.useOnSave=ve;exports.useProvide=ye;
|