md-editor-v3 1.7.2 → 1.7.3

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.
@@ -4523,7 +4523,9 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
4523
4523
  const htmlChanged = () => {
4524
4524
  nextTick(() => {
4525
4525
  if (props2.setting.preview && !previewOnly) {
4526
- clearScrollAuto = scrollAuto(textAreaRef.value, previewRef.value || htmlRef.value);
4526
+ setTimeout(() => {
4527
+ clearScrollAuto = scrollAuto(textAreaRef.value, previewRef.value || htmlRef.value);
4528
+ }, 0);
4527
4529
  }
4528
4530
  initCopyEntry();
4529
4531
  });
@@ -56,7 +56,7 @@ Please report this to https://github.com/markedjs/marked.`,o.silent)return"<p>An
56
56
  `).map(q=>`${B}${q}`).join(`
57
57
  `),D=w.substring(0,w.length-j.length),v=T.substring(H.length,T.length),p=!0,F=E,s=-j.length-H.length}else{const T=u.value.substring(0,u.selectionStart);/\n$/.test(T)||T===""?(m=`${B}${i}`,p=!0):m=B}break}case"shiftTab":{i=((x=window.getSelection())==null?void 0:x.toString())||"";const{tabWidth:E=2}=h,{prefixStr:B,prefixStrEndRow:w,subfixStrEndRow:T,prefixSupply:j,subfixSupply:H}=ge(u),G=new RegExp(`^\\s{${E}}`),K=(q=!1,ie=!1)=>{const ee=`${j}${i}${H}`;if(G.test(ee)){const J=B.length-(ie?0:E),le=q?J+i.length-E:J;return ue(u,J,le),`${w}${ee.replace(G,"")}${T}`}else if(/^\s/.test(ee)){const J=ee.replace(/^\s/,""),le=ee.length-J.length,te=u.selectionStart-(ie?0:le),ae=q?te+i.length-le:te;return ue(u,te,ae),`${w}${J}${T}`}else m=i};if(i===""){const q=K();if(q)return q}else if(/\n/.test(i)){const ie=`${j}${i}${H}`.split(`
58
58
  `);let[ee,J]=[0,0];const le=ie.map((te,ae)=>{if(G.test(te))return ae===0&&(ee=E),J+=E,te.replace(G,"");if(/^\s/.test(te)){const oe=te.replace(/^\s/,"");return J+=te.length-oe.length,oe}return te}).join(`
59
- `);return ue(u,u.selectionStart-ee,u.selectionEnd-J),`${w}${le}${T}`}else{const q=K(!0,!0);if(q)return q}break}case"ctrlC":{const{prefixSupply:E,subfixSupply:B}=ge(u);return he(i===""?`${E}${B}`:i),u.value}case"ctrlX":{const{prefixStrEndRow:E,subfixStrEndRow:B,prefixStr:w,subfixStr:T,prefixSupply:j,subfixSupply:H}=ge(u);return i===""?(he(`${j}${H}`),ue(u,E.length),`${E}${B.replace(/^\n/,"")}`):(he(i),ue(u,w.length),`${w}${T}`)}case"ctrlD":{const{prefixStrEndRow:E,subfixStrEndRow:B}=ge(u);return ue(u,E.length),`${E}${B.replace(/^\n/,"")}`}}}return Le(u,m,{deviationStart:F,deviationEnd:s,select:p,prefixVal:D,subfixVal:v})},jt=(r,i)=>{var p,D;const u=t.inject("previewOnly"),h=t.inject("historyLength"),m=t.inject("editorId");if(u)return;let F=-1;const s={list:[{content:r.value,startPos:((p=i.value)==null?void 0:p.selectionStart)||0,endPos:((D=i.value)==null?void 0:D.selectionEnd)||0}],userUpdated:!0,curr:0};t.watch(()=>r.value,v=>{var E,B;clearTimeout(F);const A=((E=i.value)==null?void 0:E.selectionStart)||0,x=((B=i.value)==null?void 0:B.selectionEnd)||0;F=setTimeout(()=>{if(s.userUpdated){s.curr<s.list.length-1&&(s.list=s.list.slice(0,s.curr+1)),s.list.length>h&&s.list.shift();const w=s.list.pop();w.startPos=A,w.endPos=x,Array.prototype.push.call(s.list,w,{content:v,startPos:A,endPos:x}),s.curr=s.list.length-1}else s.userUpdated=!0},10)}),t.onMounted(()=>{N.on(m,{name:"ctrlZ",callback(){s.userUpdated=!1,s.curr=s.curr-1<0?0:s.curr-1;const v=s.list[s.curr];r.onChange(v.content),ue(i.value,v.startPos,v.endPos)}}),N.on(m,{name:"ctrlShiftZ",callback(){s.userUpdated=!1,s.curr=s.curr+1===s.list.length?s.curr:s.curr+1;const v=s.list[s.curr];r.onChange(v.content),ue(i.value,v.startPos,v.endPos)}})})},Rt=r=>{const i=t.inject("showCodeRowNumber"),u=t.inject("editorId"),h=t.ref(!1);let m=[];const F=new pe.Renderer;F.heading=(...D)=>{const[,v,A]=D;return m.push({text:A,level:v}),r.markedHeading(...D)},F.image=(D,v,A)=>`<figure><img src="${D}" alt="${A}"><figcaption>${A}</figcaption></figure>`,pe.setOptions({renderer:F,breaks:!0}),r.hljs&&pe.setOptions({highlight:D=>{const v=r.hljs.highlightAuto(D).value;return i?Ze(v):`<span class="code-block">${v}</span>`}});const s=t.computed(()=>{m=[];const D=pe(r.value);return h.value,D}),p=()=>{pe.setOptions({highlight:D=>{const v=window.hljs.highlightAuto(D).value;return i?Ze(v):`<span class="code-block">${v}</span>`}}),h.value=!0};return t.watch(()=>s.value,D=>{r.onHtmlChanged(D),r.onGetCatalog(m),N.emit(u,"catalogChanged",m)}),{html:s,highlightLoad:p}},Lt=(r,i,u,h,m)=>{const F=t.inject("previewOnly"),s=t.inject("usedLanguageText"),p=t.inject("editorId");let D=()=>{};const v=()=>{document.querySelectorAll(`#${p} .${C}-preview pre`).forEach(x=>{var B;const E=document.createElement("span");E.setAttribute("class","copy-button"),E.innerText=((B=s.value.copyCode)==null?void 0:B.text)||"\u590D\u5236\u4EE3\u7801",E.addEventListener("click",()=>{var w;he(x.querySelector("code").innerText),E.innerText=((w=s.value.copyCode)==null?void 0:w.tips)||"\u5DF2\u590D\u5236\uFF01",setTimeout(()=>{var T;E.innerText=((T=s.value.copyCode)==null?void 0:T.text)||"\u590D\u5236\u4EE3\u7801"},1500)}),x.appendChild(E)})},A=()=>{t.nextTick(()=>{r.setting.preview&&!F&&(D=Ke(u.value,h.value||m.value)),v()})};t.watch(()=>i.value,A),t.watch(()=>r.setting.preview,x=>{x&&!F?t.nextTick(()=>{D=Ke(u.value,h.value||m.value)}):D()}),t.onMounted(A)},Ht=(r,i)=>{const u=t.inject("previewOnly"),h=t.inject("tabWidth"),m=t.inject("editorId"),F=t.ref("");return t.onMounted(()=>{var s,p;u||((s=i.value)==null||s.addEventListener("select",()=>{var D;F.value=((D=window.getSelection())==null?void 0:D.toString())||""}),(p=i.value)==null||p.addEventListener("keypress",D=>{var v,A,x;if(D.key==="Enter"){const E=(v=i.value)==null?void 0:v.selectionStart,B=(A=i.value)==null?void 0:A.value.substring(0,E),w=(x=i.value)==null?void 0:x.value.substring(E),T=B==null?void 0:B.lastIndexOf(`
59
+ `);return ue(u,u.selectionStart-ee,u.selectionEnd-J),`${w}${le}${T}`}else{const q=K(!0,!0);if(q)return q}break}case"ctrlC":{const{prefixSupply:E,subfixSupply:B}=ge(u);return he(i===""?`${E}${B}`:i),u.value}case"ctrlX":{const{prefixStrEndRow:E,subfixStrEndRow:B,prefixStr:w,subfixStr:T,prefixSupply:j,subfixSupply:H}=ge(u);return i===""?(he(`${j}${H}`),ue(u,E.length),`${E}${B.replace(/^\n/,"")}`):(he(i),ue(u,w.length),`${w}${T}`)}case"ctrlD":{const{prefixStrEndRow:E,subfixStrEndRow:B}=ge(u);return ue(u,E.length),`${E}${B.replace(/^\n/,"")}`}}}return Le(u,m,{deviationStart:F,deviationEnd:s,select:p,prefixVal:D,subfixVal:v})},jt=(r,i)=>{var p,D;const u=t.inject("previewOnly"),h=t.inject("historyLength"),m=t.inject("editorId");if(u)return;let F=-1;const s={list:[{content:r.value,startPos:((p=i.value)==null?void 0:p.selectionStart)||0,endPos:((D=i.value)==null?void 0:D.selectionEnd)||0}],userUpdated:!0,curr:0};t.watch(()=>r.value,v=>{var E,B;clearTimeout(F);const A=((E=i.value)==null?void 0:E.selectionStart)||0,x=((B=i.value)==null?void 0:B.selectionEnd)||0;F=setTimeout(()=>{if(s.userUpdated){s.curr<s.list.length-1&&(s.list=s.list.slice(0,s.curr+1)),s.list.length>h&&s.list.shift();const w=s.list.pop();w.startPos=A,w.endPos=x,Array.prototype.push.call(s.list,w,{content:v,startPos:A,endPos:x}),s.curr=s.list.length-1}else s.userUpdated=!0},10)}),t.onMounted(()=>{N.on(m,{name:"ctrlZ",callback(){s.userUpdated=!1,s.curr=s.curr-1<0?0:s.curr-1;const v=s.list[s.curr];r.onChange(v.content),ue(i.value,v.startPos,v.endPos)}}),N.on(m,{name:"ctrlShiftZ",callback(){s.userUpdated=!1,s.curr=s.curr+1===s.list.length?s.curr:s.curr+1;const v=s.list[s.curr];r.onChange(v.content),ue(i.value,v.startPos,v.endPos)}})})},Rt=r=>{const i=t.inject("showCodeRowNumber"),u=t.inject("editorId"),h=t.ref(!1);let m=[];const F=new pe.Renderer;F.heading=(...D)=>{const[,v,A]=D;return m.push({text:A,level:v}),r.markedHeading(...D)},F.image=(D,v,A)=>`<figure><img src="${D}" alt="${A}"><figcaption>${A}</figcaption></figure>`,pe.setOptions({renderer:F,breaks:!0}),r.hljs&&pe.setOptions({highlight:D=>{const v=r.hljs.highlightAuto(D).value;return i?Ze(v):`<span class="code-block">${v}</span>`}});const s=t.computed(()=>{m=[];const D=pe(r.value);return h.value,D}),p=()=>{pe.setOptions({highlight:D=>{const v=window.hljs.highlightAuto(D).value;return i?Ze(v):`<span class="code-block">${v}</span>`}}),h.value=!0};return t.watch(()=>s.value,D=>{r.onHtmlChanged(D),r.onGetCatalog(m),N.emit(u,"catalogChanged",m)}),{html:s,highlightLoad:p}},Lt=(r,i,u,h,m)=>{const F=t.inject("previewOnly"),s=t.inject("usedLanguageText"),p=t.inject("editorId");let D=()=>{};const v=()=>{document.querySelectorAll(`#${p} .${C}-preview pre`).forEach(x=>{var B;const E=document.createElement("span");E.setAttribute("class","copy-button"),E.innerText=((B=s.value.copyCode)==null?void 0:B.text)||"\u590D\u5236\u4EE3\u7801",E.addEventListener("click",()=>{var w;he(x.querySelector("code").innerText),E.innerText=((w=s.value.copyCode)==null?void 0:w.tips)||"\u5DF2\u590D\u5236\uFF01",setTimeout(()=>{var T;E.innerText=((T=s.value.copyCode)==null?void 0:T.text)||"\u590D\u5236\u4EE3\u7801"},1500)}),x.appendChild(E)})},A=()=>{t.nextTick(()=>{r.setting.preview&&!F&&setTimeout(()=>{D=Ke(u.value,h.value||m.value)},0),v()})};t.watch(()=>i.value,A),t.watch(()=>r.setting.preview,x=>{x&&!F?t.nextTick(()=>{D=Ke(u.value,h.value||m.value)}):D()}),t.onMounted(A)},Ht=(r,i)=>{const u=t.inject("previewOnly"),h=t.inject("tabWidth"),m=t.inject("editorId"),F=t.ref("");return t.onMounted(()=>{var s,p;u||((s=i.value)==null||s.addEventListener("select",()=>{var D;F.value=((D=window.getSelection())==null?void 0:D.toString())||""}),(p=i.value)==null||p.addEventListener("keypress",D=>{var v,A,x;if(D.key==="Enter"){const E=(v=i.value)==null?void 0:v.selectionStart,B=(A=i.value)==null?void 0:A.value.substring(0,E),w=(x=i.value)==null?void 0:x.value.substring(E),T=B==null?void 0:B.lastIndexOf(`
60
60
  `),j=B==null?void 0:B.substring(T+1,E);if(/^\d+\.\s|^-\s/.test(j))if(D.cancelBubble=!0,D.preventDefault(),D.stopPropagation(),/^\d+\.\s+$|^-\s+$/.test(j)){const H=B==null?void 0:B.replace(new RegExp(j+"$"),"");r.onChange(H+w),ue(i.value,H==null?void 0:H.length)}else if(/^-\s+.+/.test(j))r.onChange(Le(i.value,`
61
61
  - `,{}));else{const H=j==null?void 0:j.match(/\d+(?=\.)/),G=H&&Number(H[0])+1||1;r.onChange(Le(i.value,`
62
62
  ${G}. `,{}))}}}),N.on(m,{name:"replace",callback(D,v={}){r.onChange(zt(D,F.value,i.value,Re(fe({},v),{tabWidth:h})))}}))}),N.on(m,{name:"selectTextChange",callback(s){F.value=s}}),{selectedText:F}};var Ot=t.defineComponent({name:"MDEditorContent",props:{value:{type:String,default:""},hljs:{type:Object,default:null},onChange:{type:Function,default:()=>()=>{}},setting:{type:Object,default:()=>({})},onHtmlChanged:{type:Function,default:()=>()=>{}},onGetCatalog:{type:Function,default:()=>()=>{}},markedHeading:{type:Function,default:()=>(r,i)=>`<h${i} id="${r}"><a href="#${r}">${r}</a></h${i}>`}},setup(r){const i=t.inject("highlight"),u=t.inject("previewOnly"),h=t.inject("showCodeRowNumber"),m=t.inject("previewTheme"),F=t.inject("editorId"),s=t.ref(),p=t.ref(),D=t.ref(),{html:v,highlightLoad:A}=Rt(r);Lt(r,v,s,p,D);const{selectedText:x}=Ht(r,s);return jt(r,s),()=>t.createVNode(t.Fragment,null,[t.createVNode("div",{class:[`${C}-content`]},[!u&&t.createVNode("div",{class:[`${C}-input-wrapper`]},[t.createVNode("textarea",{id:`${F}-textarea`,ref:s,value:r.value,onInput:E=>{x.value="",r.onChange(E.target.value)},class:[r.setting.preview||r.setting.htmlPreview?"":"textarea-only"]},null)]),r.setting.preview&&t.createVNode("div",{ref:p,id:`${C}-preview`,class:[`${C}-preview`,`${m==null?void 0:m.value}-theme`,h&&`${C}-scrn`],innerHTML:v.value},null),r.setting.htmlPreview&&t.createVNode(t.Fragment,null,[t.createVNode("div",{ref:D,class:`${C}-html`},[v.value])])]),r.hljs===null&&t.createVNode(t.Teleport,{to:"head"},{default:()=>[t.createVNode("link",{rel:"stylesheet",href:i.value.css},null),t.createVNode("script",{src:i.value.js,onLoad:A},null)]})])}});const Qe=t.defineComponent({props:{tocItem:{type:Object,default:()=>({})},markedHeadingId:{type:Function,default:()=>{}}},setup(r){return()=>t.createVNode("div",{class:`${C}-catalog-link`,onClick:i=>{i.stopPropagation();const u=r.markedHeadingId(r.tocItem.text,r.tocItem.level),h=document.getElementById(u),m=document.getElementById(`${C}-preview`);if(h){const F=h.offsetTop;m==null||m.scrollTo({top:F,behavior:"smooth"})}}},[t.createVNode("span",null,[r.tocItem.text]),r.tocItem.children&&r.tocItem.children.map(i=>t.createVNode(Qe,{markedHeadingId:r.markedHeadingId,key:i.text,tocItem:i},null))])}});var mn="";const Pt=t.defineComponent({props:{markedHeadingId:{type:Function,default:()=>{}}},setup(r){const i=t.inject("editorId"),u=t.reactive({list:[],show:!1}),h=t.computed(()=>{const m=[];return u.list.forEach(({text:F,level:s})=>{const p={level:s,text:F};if(m.length===0)m.push(p);else{let D=m[m.length-1];if(p.level>D.level)for(let v=D.level+1;v<=6;v++){const{children:A}=D;if(!A){D.children=[p];break}if(D=A[A.length-1],p.level<=D.level){A.push(p);break}}else m.push(p)}}),m});return t.onMounted(()=>{N.on(i,{name:"catalogChanged",callback:m=>{u.list=m}}),N.on(i,{name:"catalogShow",callback:()=>{u.show=!u.show}})}),()=>u.show?t.createVNode("div",{class:`${C}-catalog`},[h.value.map(m=>t.createVNode(Qe,{markedHeadingId:r.markedHeadingId,tocItem:m,key:m.text},null))]):""}});var bn="",Cn="";const C="md",Ye=r=>r,Ut={modelValue:{type:String,default:""},theme:{type:String,default:"light"},editorClass:{type:String,default:""},hljs:{type:Object,default:null},highlightJs:{type:String,default:W.js},highlightCss:{type:String,default:""},historyLength:{type:Number,default:10},onChange:{type:Function},onSave:{type:Function},onUploadImg:{type:Function},pageFullScreen:{type:Boolean,default:!1},preview:{type:Boolean,default:!0},htmlPreview:{type:Boolean,default:!1},previewOnly:{type:Boolean,default:!1},language:{type:String,default:"zh-CN"},languageUserDefined:{type:Object,default:()=>({})},toolbars:{type:Array,default:mt},toolbarsExclude:{type:Array,default:[]},prettier:{type:Boolean,default:!0},prettierCDN:{type:String,default:Pe.main},prettierMDCDN:{type:String,default:Pe.markdown},onHtmlChanged:{type:Function},Cropper:{type:Function,default:null},cropperCss:{type:String,default:Ue.css},cropperJs:{type:String,default:Ue.js},iconfontJs:{type:String,default:M},onGetCatalog:{type:Function},editorId:{type:String,default:"md-editor-v3"},tabWidth:{type:Number,default:2},showCodeRowNumber:{type:Boolean,default:!1},screenfull:{type:Object,default:null},screenfullJs:{type:String,default:Dt},previewTheme:{type:String,default:"default"},markedHeading:{type:Function,default:(r,i,u)=>{const h=Ye(u);return r!==u?`<h${i} id="${h}">${r}</h${i}>`:`<h${i} id="${h}"><a href="#${h}">${u}</a></h${i}>`}},style:{type:Object,default:()=>({})},markedHeadingId:{type:Function,default:Ye}};var Ae=t.defineComponent({name:"MdEditorV3",props:Ut,setup(r,i){const{hljs:u,previewOnly:h,iconfontJs:m,prettier:F,prettierCDN:s,prettierMDCDN:p,Cropper:D,cropperCss:v,cropperJs:A,editorId:x,screenfull:E,screenfullJs:B}=r;Ct(r,i),Ft(r);const w=t.reactive({pageFullScreen:r.pageFullScreen,fullscreen:!1,preview:r.preview,htmlPreview:r.preview?!1:r.htmlPreview}),T=(K,q)=>{w[q]=K,q==="preview"&&w.preview?w.htmlPreview=!1:q==="htmlPreview"&&w.htmlPreview&&(w.preview=!1)};let j="";const H=()=>{w.pageFullScreen||w.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=j};t.watch(()=>[w.pageFullScreen,w.fullscreen],H),t.onMounted(()=>{h||N.on(x,{name:"uploadImage",callback(K,q){const ie=ee=>{ee.forEach(J=>{setTimeout(()=>{N.emit(x,"replace","image",{desc:"",url:J})},0)}),q&&q()};r.onUploadImg?r.onUploadImg(K,ie):i.emit("onUploadImg",K,ie)}}),j=document.body.style.overflow,H()}),t.onBeforeUnmount(()=>{N.clear(x)});const G=t.computed(()=>!r.toolbarsExclude.includes("catalog")&&r.toolbars.includes("catalog"));return()=>t.createVNode("div",{id:x,class:[C,r.editorClass,r.theme==="dark"&&`${C}-dark`,w.fullscreen||w.pageFullScreen?`${C}-fullscreen`:"",h&&`${C}-previewOnly`],style:r.style},[!h&&t.createVNode(Bt,{prettier:F,screenfull:E,screenfullJs:B,toolbars:r.toolbars,toolbarsExclude:r.toolbarsExclude,setting:w,updateSetting:T},null),t.createVNode(Ot,{hljs:u,value:r.modelValue,onChange:K=>{r.onChange?r.onChange(K):i.emit("update:modelValue",K)},setting:w,onHtmlChanged:K=>{r.onHtmlChanged?r.onHtmlChanged(K):i.emit("onHtmlChanged",K)},onGetCatalog:K=>{r.onGetCatalog?r.onGetCatalog(K):i.emit("onGetCatalog",K)},markedHeading:r.markedHeading},null),G.value&&t.createVNode(Pt,{markedHeadingId:r.markedHeadingId},null),!h&&t.createVNode(t.Teleport,{to:"head"},{default:()=>[t.createVNode("script",{src:m},null)]}),F&&!h&&t.createVNode(t.Teleport,{to:"head"},{default:()=>[t.createVNode("script",{src:s},null),t.createVNode("script",{src:p},null)]}),!h&&D===null&&t.createVNode(t.Teleport,{to:"head"},{default:()=>[t.createVNode("link",{href:v,rel:"stylesheet"},null),t.createVNode("script",{src:A},null)]})])}});return Ae.install=r=>(r.component(Ae.name,Ae),r),Ae});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md-editor-v3",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "keywords": [
5
5
  "vue",
6
6
  "vue3",