@dcodegroup-au/dsg-vue 0.1.13 → 0.1.14

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.
@@ -256,7 +256,7 @@ window.addEventListener("message", (e) => {
256
256
  `);h--)if(a.textContent.charAt(h)!==" "&&a.textContent.charAt(h)!==" "){u=!1;break}o===0&&(u=!1);for(var f=!0,h=o-1;h<a.textContent.length;h++)if(a.textContent.charAt(h)!==" "&&a.textContent.charAt(h)!==`
257
257
  `){f=!1;break}f&&/^#{1,6} $/.test(a.textContent)&&(f=!1);var S=(0,C.W)(getSelection().getRangeAt(0).startContainer);if(S&&S.textContent===""&&(Be(t),S.remove()),u&&a.getAttribute("data-type")!=="code-block"||f||Wt(a.innerHTML)||Vt(a.innerHTML)&&a.previousElementSibling){typeof t.options.input=="function"&&t.options.input(D(t));return}r.inputType==="insertParagraph"&&n.element.innerHTML==="<p><br></p><p><br></p>"&&a.previousElementSibling.remove(),wt(t,i,r)}}}),this.element.addEventListener("click",function(r){if(r.target.tagName==="INPUT"){var i=r.target;i.checked?i.setAttribute("checked","checked"):i.removeAttribute("checked"),n.preventInput=!0,getSelection().rangeCount>0&&(0,k.Hc)(getSelection().getRangeAt(0)),ce(t);return}if(r.target.tagName==="IMG"&&!r.target.parentElement.classList.contains("vditor-wysiwyg__preview")){r.target.getAttribute("data-type")==="link-ref"?en(t,r.target):Zn(r,t);return}var a=(0,s.lG)(r.target,"A");if(a){t.options.link.click?t.options.link.click(a):t.options.link.isOpen&&window.open(a.getAttribute("href")),r.preventDefault();return}var o=(0,k.zh)(t);if(r.target.isEqualNode(n.element)&&n.element.lastElementChild&&o.collapsed){var u=n.element.lastElementChild.getBoundingClientRect();r.y>u.top+u.height&&(n.element.lastElementChild.tagName==="P"&&n.element.lastElementChild.textContent.trim().replace(E.g.ZWSP,"")===""?(o.selectNodeContents(n.element.lastElementChild),o.collapse(!1)):(n.element.insertAdjacentHTML("beforeend",'<p data-block="0">'.concat(E.g.ZWSP,"<wbr></p>")),(0,k.ib)(n.element,o)))}Ze(t);var h=(0,s.fb)(r.target,"vditor-wysiwyg__preview");h||(h=(0,s.fb)((0,k.zh)(t).startContainer,"vditor-wysiwyg__preview")),h&&at(h,t),ht(r,t)}),this.element.addEventListener("keyup",function(r){if(!(r.isComposing||(0,l.yl)(r))){r.key==="Enter"&&be(t),(r.key==="Backspace"||r.key==="Delete")&&t.wysiwyg.element.innerHTML!==""&&t.wysiwyg.element.childNodes.length===1&&t.wysiwyg.element.firstElementChild&&t.wysiwyg.element.firstElementChild.tagName==="P"&&t.wysiwyg.element.firstElementChild.childElementCount===0&&(t.wysiwyg.element.textContent===""||t.wysiwyg.element.textContent===`
258
258
  `)&&(t.wysiwyg.element.innerHTML="");var i=(0,k.zh)(t);if(r.key==="Backspace"&&(0,l.vU)()&&i.startContainer.textContent===`
259
- `&&i.startOffset===1&&(i.startContainer.textContent=""),_t(t,i),Ze(t),!(r.key!=="ArrowDown"&&r.key!=="ArrowRight"&&r.key!=="Backspace"&&r.key!=="ArrowLeft"&&r.key!=="ArrowUp")){(r.key==="ArrowLeft"||r.key==="ArrowRight")&&t.hint.render(t);var a=(0,s.fb)(i.startContainer,"vditor-wysiwyg__preview");if(!a&&i.startContainer.nodeType!==3&&i.startOffset>0){var o=i.startContainer;o.classList.contains("vditor-wysiwyg__block")&&(a=o.lastElementChild)}if(a){var u=a.previousElementSibling;if(u.style.display==="none"){r.key==="ArrowDown"||r.key==="ArrowRight"?at(a,t):at(a,t,!1);return}var h=a.previousElementSibling;if(h.tagName==="PRE"&&(h=h.firstElementChild),r.key==="ArrowDown"||r.key==="ArrowRight"){var o=a.parentElement,f=Kn(o);if(f&&f.nodeType!==3){var S=f.querySelector(".vditor-wysiwyg__preview");if(S){at(S,t);return}}if(f.nodeType===3){for(;f.textContent.length===0&&f.nextSibling;)f=f.nextSibling;i.setStart(f,1)}else i.setStart(f.firstChild,0)}else i.selectNodeContents(h),i.collapse(!1)}}}})},e})(),Si=(function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(r[a]=i[a])},e(t,n)};return function(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),Ci=(function(e){Si(t,e);function t(n,r){var i=e.call(this)||this;if(i.isDestroyed=!1,i.version=E.H,typeof n=="string"){if(r?r.cache?r.cache.id||(r.cache.id="vditor".concat(n)):r.cache={id:"vditor".concat(n)}:r={cache:{id:"vditor".concat(n)}},!document.getElementById(n))return i.showErrorTip("Failed to get element by id: ".concat(n)),i;n=document.getElementById(n)}var a=new vi(r),o=a.merge();if(o.i18n)window.VditorI18n=o.i18n,i.init(n,o);else if(["de_DE","en_US","es_ES","fr_FR","ja_JP","ko_KR","pt_BR","ru_RU","sv_SE","vi_VN","zh_CN","zh_TW"].includes(o.lang)){var u="vditorI18nScript",h=u+o.lang;document.querySelectorAll('head script[id^="'.concat(u,'"]')).forEach(function(f){f.id!==h&&document.head.removeChild(f)}),(0,A.G)("".concat(o.cdn,"/dist/js/i18n/").concat(o.lang,".js"),h).then(function(){i.init(n,o)}).catch(function(f){i.showErrorTip("GET ".concat(o.cdn,"/dist/js/i18n/").concat(o.lang,".js net::ERR_ABORTED 404 (Not Found)"))})}else throw new Error("options.lang error, see https://ld246.com/article/1549638745630#options");return i}return t.prototype.showErrorTip=function(n){var r=new Hn;document.body.appendChild(r.element),r.show(n,0)},t.prototype.updateToolbarConfig=function(n){this.vditor.toolbar.updateConfig(this.vditor,n)},t.prototype.setTheme=function(n,r,i,a){this.vditor.options.theme=n,pe(this.vditor),r&&(this.vditor.options.preview.theme.current=r,(0,X.Z)(r,a||this.vditor.options.preview.theme.path)),i&&(this.vditor.options.preview.hljs.style=i,(0,On.Y)(i,this.vditor.options.cdn))},t.prototype.getValue=function(){return D(this.vditor)},t.prototype.getCurrentMode=function(){return this.vditor.currentMode},t.prototype.focus=function(){this.vditor.currentMode==="sv"?this.vditor.sv.element.focus():this.vditor.currentMode==="wysiwyg"?this.vditor.wysiwyg.element.focus():this.vditor.currentMode==="ir"&&this.vditor.ir.element.focus()},t.prototype.blur=function(){this.vditor.currentMode==="sv"?this.vditor.sv.element.blur():this.vditor.currentMode==="wysiwyg"?this.vditor.wysiwyg.element.blur():this.vditor.currentMode==="ir"&&this.vditor.ir.element.blur()},t.prototype.disabled=function(){b(this.vditor,["subToolbar","hint","popover"]),d(this.vditor.toolbar.elements,E.g.EDIT_TOOLBARS.concat(["undo","redo","fullscreen","edit-mode"])),this.vditor[this.vditor.currentMode].element.setAttribute("contenteditable","false")},t.prototype.enable=function(){m(this.vditor.toolbar.elements,E.g.EDIT_TOOLBARS.concat(["undo","redo","fullscreen","edit-mode"])),this.vditor.undo.resetIcon(this.vditor),this.vditor[this.vditor.currentMode].element.setAttribute("contenteditable","true")},t.prototype.getSelection=function(){if(this.vditor.currentMode==="wysiwyg")return st(this.vditor.wysiwyg.element);if(this.vditor.currentMode==="sv")return st(this.vditor.sv.element);if(this.vditor.currentMode==="ir")return st(this.vditor.ir.element)},t.prototype.renderPreview=function(n){this.vditor.preview.render(this.vditor,n)},t.prototype.getCursorPosition=function(){return(0,k.Ny)(this.vditor[this.vditor.currentMode].element)},t.prototype.isUploading=function(){return this.vditor.upload.isUploading},t.prototype.clearCache=function(){this.vditor.options.cache.enable&&(0,l.pK)()&&localStorage.removeItem(this.vditor.options.cache.id)},t.prototype.disabledCache=function(){this.vditor.options.cache.enable=!1},t.prototype.enableCache=function(){if(!this.vditor.options.cache.id)throw new Error("need options.cache.id, see https://ld246.com/article/1549638745630#options");this.vditor.options.cache.enable=!0},t.prototype.html2md=function(n){return this.vditor.lute.HTML2Md(n)},t.prototype.exportJSON=function(n){return this.vditor.lute.RenderJSON(n)},t.prototype.getHTML=function(){return xn(this.vditor)},t.prototype.tip=function(n,r){this.vditor.tip.show(n,r)},t.prototype.setPreviewMode=function(n){Kt(n,this.vditor)},t.prototype.deleteValue=function(){window.getSelection().isCollapsed||document.execCommand("delete",!1)},t.prototype.updateValue=function(n){document.execCommand("insertHTML",!1,n)},t.prototype.insertValue=function(n,r){r===void 0&&(r=!0);var i=(0,k.zh)(this.vditor);i.collapse(!0);var a=document.createElement("template");a.innerHTML=n,i.insertNode(a.content.cloneNode(!0)),i.collapse(!1),this.vditor.currentMode==="sv"?(this.vditor.sv.preventInput=!0,r&&ie(this.vditor)):this.vditor.currentMode==="wysiwyg"?r&&wt(this.vditor,getSelection().getRangeAt(0)):this.vditor.currentMode==="ir"&&(this.vditor.ir.preventInput=!0,r&&qe(this.vditor,getSelection().getRangeAt(0),!0))},t.prototype.insertMD=function(n){this.vditor.currentMode==="ir"?(0,k.oC)(this.vditor.lute.Md2VditorIRDOM(n),this.vditor):this.vditor.currentMode==="wysiwyg"?(0,k.oC)(this.vditor.lute.Md2VditorDOM(n),this.vditor):jt(this.vditor,n),this.vditor.outline.render(this.vditor),ee(this.vditor)},t.prototype.setValue=function(n,r){var i=this;r===void 0&&(r=!1),this.vditor.currentMode==="sv"?(this.vditor.sv.element.innerHTML="<div data-block='0'>".concat(this.vditor.lute.SpinVditorSVDOM(n),"</div>"),Ce(this.vditor,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1})):this.vditor.currentMode==="wysiwyg"?tn(this.vditor,n,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1}):(this.vditor.ir.element.innerHTML=this.vditor.lute.Md2VditorIRDOM(n),this.vditor.ir.element.querySelectorAll(".vditor-ir__preview[data-render='2']").forEach(function(a){Se(a,i.vditor)}),We(this.vditor,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1})),this.vditor.outline.render(this.vditor),n||(b(this.vditor,["emoji","headings","submenu","hint"]),this.vditor.wysiwyg.popover&&(this.vditor.wysiwyg.popover.style.display="none"),this.clearCache()),r&&this.clearStack()},t.prototype.insertEmptyBlock=function(n){lt(this.vditor,n)},t.prototype.clearStack=function(){this.vditor.undo.clearStack(this.vditor),this.vditor.undo.addToUndoStack(this.vditor)},t.prototype.destroy=function(){this.vditor.element.innerHTML=this.vditor.originalInnerHTML,this.vditor.element.classList.remove("vditor"),this.vditor.element.removeAttribute("style");var n=document.getElementById("vditorIconScript");n&&n.remove(),this.clearCache(),Yt(),this.vditor.wysiwyg.unbindListener(),this.vditor.options.after=void 0,this.isDestroyed=!0},t.prototype.getCommentIds=function(){return this.vditor.currentMode!=="wysiwyg"?[]:this.vditor.wysiwyg.getComments(this.vditor,!0)},t.prototype.hlCommentIds=function(n){if(this.vditor.currentMode==="wysiwyg"){var r=function(i){i.classList.remove("vditor-comment--hover"),n.forEach(function(a){i.getAttribute("data-cmtids").indexOf(a)>-1&&i.classList.add("vditor-comment--hover")})};this.vditor.wysiwyg.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)}),this.vditor.preview.element.style.display!=="none"&&this.vditor.preview.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)})}},t.prototype.unHlCommentIds=function(n){if(this.vditor.currentMode==="wysiwyg"){var r=function(i){n.forEach(function(a){i.getAttribute("data-cmtids").indexOf(a)>-1&&i.classList.remove("vditor-comment--hover")})};this.vditor.wysiwyg.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)}),this.vditor.preview.element.style.display!=="none"&&this.vditor.preview.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)})}},t.prototype.removeCommentIds=function(n){var r=this;if(this.vditor.currentMode==="wysiwyg"){var i=function(a,o){var u=a.getAttribute("data-cmtids").split(" ");u.find(function(h,f){if(h===o)return u.splice(f,1),!0}),u.length===0?(a.outerHTML=a.innerHTML,(0,k.zh)(r.vditor).collapse(!0)):a.setAttribute("data-cmtids",u.join(" "))};n.forEach(function(a){r.vditor.wysiwyg.element.querySelectorAll(".vditor-comment").forEach(function(o){i(o,a)}),r.vditor.preview.element.style.display!=="none"&&r.vditor.preview.element.querySelectorAll(".vditor-comment").forEach(function(o){i(o,a)})}),ce(this.vditor,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1})}},t.prototype.init=function(n,r){var i=this;this.isDestroyed||(this.vditor={currentMode:r.mode,element:n,hint:new pr(r.hint.extend),lute:void 0,options:r,originalInnerHTML:n.innerHTML,outline:new gr(window.VditorI18n.outline),tip:new Hn},this.vditor.sv=new vr(this.vditor),this.vditor.undo=new bi,this.vditor.wysiwyg=new Ei(this.vditor),this.vditor.ir=new hr(this.vditor),this.vditor.toolbar=new gi(this.vditor),r.resize.enable&&(this.vditor.resize=new wr(this.vditor)),this.vditor.toolbar.elements.devtools&&(this.vditor.devtools=new c),(r.upload.url||r.upload.handler)&&(this.vditor.upload=new rr),(0,A.G)(r._lutePath||"".concat(r.cdn,"/dist/js/lute/lute.min.js"),"vditorLuteScript").then(function(){i.vditor.lute=(0,mr.X)({autoSpace:i.vditor.options.preview.markdown.autoSpace,gfmAutoLink:i.vditor.options.preview.markdown.gfmAutoLink,codeBlockPreview:i.vditor.options.preview.markdown.codeBlockPreview,emojiSite:i.vditor.options.hint.emojiPath,emojis:i.vditor.options.hint.emoji,fixTermTypo:i.vditor.options.preview.markdown.fixTermTypo,footnotes:i.vditor.options.preview.markdown.footnotes,headingAnchor:!1,inlineMathDigit:i.vditor.options.preview.math.inlineDigit,linkBase:i.vditor.options.preview.markdown.linkBase,linkPrefix:i.vditor.options.preview.markdown.linkPrefix,listStyle:i.vditor.options.preview.markdown.listStyle,mark:i.vditor.options.preview.markdown.mark,mathBlockPreview:i.vditor.options.preview.markdown.mathBlockPreview,paragraphBeginningSpace:i.vditor.options.preview.markdown.paragraphBeginningSpace,sanitize:i.vditor.options.preview.markdown.sanitize,toc:i.vditor.options.preview.markdown.toc}),i.vditor.preview=new br(i.vditor),He(i.vditor),r.after&&r.after(),r.icon&&(0,A.J)("".concat(r.cdn,"/dist/js/icons/").concat(r.icon,".js"),"vditorIconScript")}))},t})(Z.default);const Li=Ci})(),Me=Me.default,Me})()})})(Tt)),Tt.exports}var Ai=_i();const xi=Mi.getDefaultExportFromCjs(Ai),Di={class:"dsg-editor"},Hi={ref:"vditor",class:"dsg-editor__vditor"},Oi={key:0,class:"dsg-editor--error-wrapper"},Ni=fe.defineComponent({__name:"DsgEditor",props:fe.mergeModels({label:{default:""},targetModel:{default:null},targetModelClass:{default:""},mediaUploadEndpoint:{default:""},csrf:{default:""},errors:{default:()=>[]}},{modelValue:{required:!0},modelModifiers:{}}),emits:fe.mergeModels(["on-before-input","on-after-input","update:modelValue"],["update:modelValue"]),setup(ve,{expose:Jt,emit:pt}){let rt=fe.useModel(ve,"modelValue"),Y=fe.ref(rt);fe.watch(()=>Y.value,(w,b)=>{m("update:modelValue",w)});const Me=fe.ref(),Z=fe.useTemplateRef("vditor"),E=()=>({modelId:ve.targetModel?ve.targetModel.id:"",modelClass:ve.targetModelClass?ve.targetModelClass:""}),M=(w,b)=>{if(!w)return!1;w.nodeType===3&&(w=w.parentElement);let g=w,s=!1;for(;g&&!s&&!g.classList.contains("vditor-reset");)g.nodeName===b?s=!0:g=g.parentElement;return s&&g},D=w=>{let b;const g=w[w.currentMode].element;return getSelection().rangeCount>0&&(b=getSelection().getRangeAt(0),g.isEqualNode(b.startContainer)||g.contains(b.startContainer))?b:w[w.currentMode].range?w[w.currentMode].range:(g.focus(),b=g.ownerDocument.createRange(),b.setStart(g,0),b.collapse(!0),b)},A=w=>{let b=D(Me.value.vditor);const g=M(b.startContainer,"LI");if(!g||g.nextElementSibling||g.previousElementSibling)return!1;if(g.parentNode?.previousSibling?.nodeName==="UL"&&g.parentNode?.previousSibling?.firstChild.classList.contains("vditor-task")){let s=g.parentNode?.previousSibling,C=g.parentNode;s.appendChild(g),g.classList.add("vditor-task");let _=document.createElement("input");_.setAttribute("type","checkbox"),g.insertBefore(_,g.firstChild),C&&C.parentNode&&C.parentNode.removeChild(C),b.setStartAfter(g),b.collapse(!0)}},c=()=>ve.csrf?ve.csrf:window.csrf,l=w=>new Promise(b=>{new MutationObserver((s,C)=>{const _=document.querySelector(w);_&&(C.disconnect(),b(_))}).observe(document.body,{childList:!0,subtree:!0})}),y=w=>{w.addEventListener("paste",b=>{if("clipboardData"in b&&b.clipboardData?.items){for(const g of b.clipboardData.items)if(g.type.startsWith("image/")){const s=b.clipboardData?.files[0].name.split(".").slice(0,-1).join("")||"pasted-image",C=g.type.split("/")[1];if(b.preventDefault(),b.stopPropagation(),ve.mediaUploadEndpoint&&c()!==""){const _=new FormData,x=E();Object.keys(x).forEach(L=>{_.append(L,x[L])}),_.append("file",g.getAsFile()),fetch(ve.mediaUploadEndpoint,{method:"POST",headers:{"X-CSRF-TOKEN":c()},body:_}).then(L=>L.json()).then(L=>{Me.value?.insertMD(`![${L.filename}](${L.file_url})
259
+ `&&i.startOffset===1&&(i.startContainer.textContent=""),_t(t,i),Ze(t),!(r.key!=="ArrowDown"&&r.key!=="ArrowRight"&&r.key!=="Backspace"&&r.key!=="ArrowLeft"&&r.key!=="ArrowUp")){(r.key==="ArrowLeft"||r.key==="ArrowRight")&&t.hint.render(t);var a=(0,s.fb)(i.startContainer,"vditor-wysiwyg__preview");if(!a&&i.startContainer.nodeType!==3&&i.startOffset>0){var o=i.startContainer;o.classList.contains("vditor-wysiwyg__block")&&(a=o.lastElementChild)}if(a){var u=a.previousElementSibling;if(u.style.display==="none"){r.key==="ArrowDown"||r.key==="ArrowRight"?at(a,t):at(a,t,!1);return}var h=a.previousElementSibling;if(h.tagName==="PRE"&&(h=h.firstElementChild),r.key==="ArrowDown"||r.key==="ArrowRight"){var o=a.parentElement,f=Kn(o);if(f&&f.nodeType!==3){var S=f.querySelector(".vditor-wysiwyg__preview");if(S){at(S,t);return}}if(f.nodeType===3){for(;f.textContent.length===0&&f.nextSibling;)f=f.nextSibling;i.setStart(f,1)}else i.setStart(f.firstChild,0)}else i.selectNodeContents(h),i.collapse(!1)}}}})},e})(),Si=(function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(r[a]=i[a])},e(t,n)};return function(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),Ci=(function(e){Si(t,e);function t(n,r){var i=e.call(this)||this;if(i.isDestroyed=!1,i.version=E.H,typeof n=="string"){if(r?r.cache?r.cache.id||(r.cache.id="vditor".concat(n)):r.cache={id:"vditor".concat(n)}:r={cache:{id:"vditor".concat(n)}},!document.getElementById(n))return i.showErrorTip("Failed to get element by id: ".concat(n)),i;n=document.getElementById(n)}var a=new vi(r),o=a.merge();if(o.i18n)window.VditorI18n=o.i18n,i.init(n,o);else if(["de_DE","en_US","es_ES","fr_FR","ja_JP","ko_KR","pt_BR","ru_RU","sv_SE","vi_VN","zh_CN","zh_TW"].includes(o.lang)){var u="vditorI18nScript",h=u+o.lang;document.querySelectorAll('head script[id^="'.concat(u,'"]')).forEach(function(f){f.id!==h&&document.head.removeChild(f)}),(0,A.G)("".concat(o.cdn,"/dist/js/i18n/").concat(o.lang,".js"),h).then(function(){i.init(n,o)}).catch(function(f){i.showErrorTip("GET ".concat(o.cdn,"/dist/js/i18n/").concat(o.lang,".js net::ERR_ABORTED 404 (Not Found)"))})}else throw new Error("options.lang error, see https://ld246.com/article/1549638745630#options");return i}return t.prototype.showErrorTip=function(n){var r=new Hn;document.body.appendChild(r.element),r.show(n,0)},t.prototype.updateToolbarConfig=function(n){this.vditor.toolbar.updateConfig(this.vditor,n)},t.prototype.setTheme=function(n,r,i,a){this.vditor.options.theme=n,pe(this.vditor),r&&(this.vditor.options.preview.theme.current=r,(0,X.Z)(r,a||this.vditor.options.preview.theme.path)),i&&(this.vditor.options.preview.hljs.style=i,(0,On.Y)(i,this.vditor.options.cdn))},t.prototype.getValue=function(){return D(this.vditor)},t.prototype.getCurrentMode=function(){return this.vditor.currentMode},t.prototype.focus=function(){this.vditor.currentMode==="sv"?this.vditor.sv.element.focus():this.vditor.currentMode==="wysiwyg"?this.vditor.wysiwyg.element.focus():this.vditor.currentMode==="ir"&&this.vditor.ir.element.focus()},t.prototype.blur=function(){this.vditor.currentMode==="sv"?this.vditor.sv.element.blur():this.vditor.currentMode==="wysiwyg"?this.vditor.wysiwyg.element.blur():this.vditor.currentMode==="ir"&&this.vditor.ir.element.blur()},t.prototype.disabled=function(){b(this.vditor,["subToolbar","hint","popover"]),d(this.vditor.toolbar.elements,E.g.EDIT_TOOLBARS.concat(["undo","redo","fullscreen","edit-mode"])),this.vditor[this.vditor.currentMode].element.setAttribute("contenteditable","false")},t.prototype.enable=function(){m(this.vditor.toolbar.elements,E.g.EDIT_TOOLBARS.concat(["undo","redo","fullscreen","edit-mode"])),this.vditor.undo.resetIcon(this.vditor),this.vditor[this.vditor.currentMode].element.setAttribute("contenteditable","true")},t.prototype.getSelection=function(){if(this.vditor.currentMode==="wysiwyg")return st(this.vditor.wysiwyg.element);if(this.vditor.currentMode==="sv")return st(this.vditor.sv.element);if(this.vditor.currentMode==="ir")return st(this.vditor.ir.element)},t.prototype.renderPreview=function(n){this.vditor.preview.render(this.vditor,n)},t.prototype.getCursorPosition=function(){return(0,k.Ny)(this.vditor[this.vditor.currentMode].element)},t.prototype.isUploading=function(){return this.vditor.upload.isUploading},t.prototype.clearCache=function(){this.vditor.options.cache.enable&&(0,l.pK)()&&localStorage.removeItem(this.vditor.options.cache.id)},t.prototype.disabledCache=function(){this.vditor.options.cache.enable=!1},t.prototype.enableCache=function(){if(!this.vditor.options.cache.id)throw new Error("need options.cache.id, see https://ld246.com/article/1549638745630#options");this.vditor.options.cache.enable=!0},t.prototype.html2md=function(n){return this.vditor.lute.HTML2Md(n)},t.prototype.exportJSON=function(n){return this.vditor.lute.RenderJSON(n)},t.prototype.getHTML=function(){return xn(this.vditor)},t.prototype.tip=function(n,r){this.vditor.tip.show(n,r)},t.prototype.setPreviewMode=function(n){Kt(n,this.vditor)},t.prototype.deleteValue=function(){window.getSelection().isCollapsed||document.execCommand("delete",!1)},t.prototype.updateValue=function(n){document.execCommand("insertHTML",!1,n)},t.prototype.insertValue=function(n,r){r===void 0&&(r=!0);var i=(0,k.zh)(this.vditor);i.collapse(!0);var a=document.createElement("template");a.innerHTML=n,i.insertNode(a.content.cloneNode(!0)),i.collapse(!1),this.vditor.currentMode==="sv"?(this.vditor.sv.preventInput=!0,r&&ie(this.vditor)):this.vditor.currentMode==="wysiwyg"?r&&wt(this.vditor,getSelection().getRangeAt(0)):this.vditor.currentMode==="ir"&&(this.vditor.ir.preventInput=!0,r&&qe(this.vditor,getSelection().getRangeAt(0),!0))},t.prototype.insertMD=function(n){this.vditor.currentMode==="ir"?(0,k.oC)(this.vditor.lute.Md2VditorIRDOM(n),this.vditor):this.vditor.currentMode==="wysiwyg"?(0,k.oC)(this.vditor.lute.Md2VditorDOM(n),this.vditor):jt(this.vditor,n),this.vditor.outline.render(this.vditor),ee(this.vditor)},t.prototype.setValue=function(n,r){var i=this;r===void 0&&(r=!1),this.vditor.currentMode==="sv"?(this.vditor.sv.element.innerHTML="<div data-block='0'>".concat(this.vditor.lute.SpinVditorSVDOM(n),"</div>"),Ce(this.vditor,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1})):this.vditor.currentMode==="wysiwyg"?tn(this.vditor,n,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1}):(this.vditor.ir.element.innerHTML=this.vditor.lute.Md2VditorIRDOM(n),this.vditor.ir.element.querySelectorAll(".vditor-ir__preview[data-render='2']").forEach(function(a){Se(a,i.vditor)}),We(this.vditor,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1})),this.vditor.outline.render(this.vditor),n||(b(this.vditor,["emoji","headings","submenu","hint"]),this.vditor.wysiwyg.popover&&(this.vditor.wysiwyg.popover.style.display="none"),this.clearCache()),r&&this.clearStack()},t.prototype.insertEmptyBlock=function(n){lt(this.vditor,n)},t.prototype.clearStack=function(){this.vditor.undo.clearStack(this.vditor),this.vditor.undo.addToUndoStack(this.vditor)},t.prototype.destroy=function(){this.vditor.element.innerHTML=this.vditor.originalInnerHTML,this.vditor.element.classList.remove("vditor"),this.vditor.element.removeAttribute("style");var n=document.getElementById("vditorIconScript");n&&n.remove(),this.clearCache(),Yt(),this.vditor.wysiwyg.unbindListener(),this.vditor.options.after=void 0,this.isDestroyed=!0},t.prototype.getCommentIds=function(){return this.vditor.currentMode!=="wysiwyg"?[]:this.vditor.wysiwyg.getComments(this.vditor,!0)},t.prototype.hlCommentIds=function(n){if(this.vditor.currentMode==="wysiwyg"){var r=function(i){i.classList.remove("vditor-comment--hover"),n.forEach(function(a){i.getAttribute("data-cmtids").indexOf(a)>-1&&i.classList.add("vditor-comment--hover")})};this.vditor.wysiwyg.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)}),this.vditor.preview.element.style.display!=="none"&&this.vditor.preview.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)})}},t.prototype.unHlCommentIds=function(n){if(this.vditor.currentMode==="wysiwyg"){var r=function(i){n.forEach(function(a){i.getAttribute("data-cmtids").indexOf(a)>-1&&i.classList.remove("vditor-comment--hover")})};this.vditor.wysiwyg.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)}),this.vditor.preview.element.style.display!=="none"&&this.vditor.preview.element.querySelectorAll(".vditor-comment").forEach(function(i){r(i)})}},t.prototype.removeCommentIds=function(n){var r=this;if(this.vditor.currentMode==="wysiwyg"){var i=function(a,o){var u=a.getAttribute("data-cmtids").split(" ");u.find(function(h,f){if(h===o)return u.splice(f,1),!0}),u.length===0?(a.outerHTML=a.innerHTML,(0,k.zh)(r.vditor).collapse(!0)):a.setAttribute("data-cmtids",u.join(" "))};n.forEach(function(a){r.vditor.wysiwyg.element.querySelectorAll(".vditor-comment").forEach(function(o){i(o,a)}),r.vditor.preview.element.style.display!=="none"&&r.vditor.preview.element.querySelectorAll(".vditor-comment").forEach(function(o){i(o,a)})}),ce(this.vditor,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1})}},t.prototype.init=function(n,r){var i=this;this.isDestroyed||(this.vditor={currentMode:r.mode,element:n,hint:new pr(r.hint.extend),lute:void 0,options:r,originalInnerHTML:n.innerHTML,outline:new gr(window.VditorI18n.outline),tip:new Hn},this.vditor.sv=new vr(this.vditor),this.vditor.undo=new bi,this.vditor.wysiwyg=new Ei(this.vditor),this.vditor.ir=new hr(this.vditor),this.vditor.toolbar=new gi(this.vditor),r.resize.enable&&(this.vditor.resize=new wr(this.vditor)),this.vditor.toolbar.elements.devtools&&(this.vditor.devtools=new c),(r.upload.url||r.upload.handler)&&(this.vditor.upload=new rr),(0,A.G)(r._lutePath||"".concat(r.cdn,"/dist/js/lute/lute.min.js"),"vditorLuteScript").then(function(){i.vditor.lute=(0,mr.X)({autoSpace:i.vditor.options.preview.markdown.autoSpace,gfmAutoLink:i.vditor.options.preview.markdown.gfmAutoLink,codeBlockPreview:i.vditor.options.preview.markdown.codeBlockPreview,emojiSite:i.vditor.options.hint.emojiPath,emojis:i.vditor.options.hint.emoji,fixTermTypo:i.vditor.options.preview.markdown.fixTermTypo,footnotes:i.vditor.options.preview.markdown.footnotes,headingAnchor:!1,inlineMathDigit:i.vditor.options.preview.math.inlineDigit,linkBase:i.vditor.options.preview.markdown.linkBase,linkPrefix:i.vditor.options.preview.markdown.linkPrefix,listStyle:i.vditor.options.preview.markdown.listStyle,mark:i.vditor.options.preview.markdown.mark,mathBlockPreview:i.vditor.options.preview.markdown.mathBlockPreview,paragraphBeginningSpace:i.vditor.options.preview.markdown.paragraphBeginningSpace,sanitize:i.vditor.options.preview.markdown.sanitize,toc:i.vditor.options.preview.markdown.toc}),i.vditor.preview=new br(i.vditor),He(i.vditor),r.after&&r.after(),r.icon&&(0,A.J)("".concat(r.cdn,"/dist/js/icons/").concat(r.icon,".js"),"vditorIconScript")}))},t})(Z.default);const Li=Ci})(),Me=Me.default,Me})()})})(Tt)),Tt.exports}var Ai=_i();const xi=Mi.getDefaultExportFromCjs(Ai),Di={class:"dsg-editor"},Hi={ref:"vditor",class:"dsg-editor__vditor"},Oi={key:0,class:"dsg-editor--error-wrapper"},Ni=fe.defineComponent({__name:"DsgEditor",props:fe.mergeModels({label:{default:""},targetModel:{default:null},targetModelClass:{default:""},mediaUploadEndpoint:{default:""},csrf:{default:""},errors:{default:()=>[]}},{modelValue:{required:!0},modelModifiers:{}}),emits:fe.mergeModels(["on-before-input","on-after-input","update:modelValue"],["update:modelValue"]),setup(ve,{expose:Jt,emit:pt}){let rt=fe.useModel(ve,"modelValue"),Y=fe.ref(rt);fe.watch(()=>Y.value,(w,b)=>{m("update:modelValue",w)});const Me=fe.ref(),Z=fe.useTemplateRef("vditor"),E=()=>({modelId:ve.targetModel?ve.targetModel.id:"",modelClass:ve.targetModelClass?ve.targetModelClass:""}),M=(w,b)=>{if(!w)return!1;w.nodeType===3&&(w=w.parentElement);let g=w,s=!1;for(;g&&!s&&!g.classList.contains("vditor-reset");)g.nodeName===b?s=!0:g=g.parentElement;return s&&g},D=w=>{let b;const g=w[w.currentMode].element;return getSelection().rangeCount>0&&(b=getSelection().getRangeAt(0),g.isEqualNode(b.startContainer)||g.contains(b.startContainer))?b:w[w.currentMode].range?w[w.currentMode].range:(g.focus(),b=g.ownerDocument.createRange(),b.setStart(g,0),b.collapse(!0),b)},A=w=>{let b=D(Me.value.vditor);const g=M(b.startContainer,"LI");if(!g||g.nextElementSibling||g.previousElementSibling)return!1;if(g.parentNode?.previousSibling?.nodeName==="UL"&&g.parentNode?.previousSibling?.firstChild.classList.contains("vditor-task")){let s=g.parentNode?.previousSibling,C=g.parentNode;s.appendChild(g),g.classList.add("vditor-task");let _=document.createElement("input");_.setAttribute("type","checkbox"),g.insertBefore(_,g.firstChild),C&&C.parentNode&&C.parentNode.removeChild(C),b.setStartAfter(g),b.collapse(!0)}},c=()=>ve.csrf?ve.csrf:window.csrf,l=w=>new Promise(b=>{new MutationObserver((s,C)=>{const _=document.querySelector(w);_&&(C.disconnect(),b(_))}).observe(document.body,{childList:!0,subtree:!0})}),y=w=>{w.addEventListener("paste",b=>{if("clipboardData"in b&&b.clipboardData?.items){for(const g of b.clipboardData.items)if(g.type.startsWith("image/")){const s=b.clipboardData?.files[0].name.split(".").slice(0,-1).join("")||"pasted-image",C=g.type.split("/")[1];if(b.preventDefault(),b.stopPropagation(),ve.mediaUploadEndpoint&&c()!==""){const _=new FormData,x=E();Object.keys(x).forEach(L=>{_.append(L,x[L])}),_.append("file[]",g.getAsFile()),fetch(ve.mediaUploadEndpoint,{method:"POST",headers:{"X-CSRF-TOKEN":c()},body:_}).then(L=>L.json()).then(L=>{Me.value?.insertMD(`![${L.filename}](${L.file_url})
260
260
  `)}).catch(()=>{Me.value?.vditor.tip.show("The file upload failed",5e3)});return}else{const _=new FileReader;_.readAsDataURL(g.getAsFile()),_.onload=()=>{const x=_.result;Me.value?.insertMD(`![${s}.${C}](${x})
261
261
  `)}}}}},!0)},p=()=>{let w=["emoji","headings","bold","italic","strike","link","|","list","ordered-list","check","outdent","indent","|","quote","line","code","inline-code","insert-before","insert-after","|"];ve.mediaUploadEndpoint&&c()!==""&&w.push("upload");let b=["table","|","undo","redo","|","fullscreen",{name:"more",toolbar:["both","export","outline","preview","devtools","info","help"]}];for(let g=0;g<b.length;g++)w.push(b[g]);return w};fe.onMounted(()=>{let w={mode:"wysiwyg",height:"auto",minHeight:300,lang:"en_US",toolbarConfig:{pin:!0},cache:{enable:!1},preview:{maxWidth:2e3},toolbar:p(),after:()=>{Z.value.getElementsByClassName("vditor-wysiwyg")[0].addEventListener("keyup",g=>{g.key==="Enter"&&A()&&g.preventDefault()}),Y.value&&Me.value?.setValue(Y.value)},input:b=>{m("on-before-input",Y.value,b),Y.value=b,m("on-after-input",b)},upload:{}};ve.mediaUploadEndpoint&&c()!==""&&(w.upload={accept:"image/*",url:ve.mediaUploadEndpoint,headers:{"X-CSRF-TOKEN":c()},extraData:E(),multiple:!1,error:b=>{Me.value?.vditor.tip.show("The file upload failed",5e3)},success:(b,g)=>{const s=JSON.parse(g);document.execCommand("insertHTML",!1,`![${s.filename}](${s.file_url})
262
262
  `),Y.value=Me.value.getValue(),Me.value?.setValue(Me.value.getValue()),m("update:modelValue",Y.value),Me.value?.vditor.tip.hide()}}),Z.value&&(Me.value=new xi(Z.value,w),l("pre.vditor-reset").then(b=>{y(b)}))});const m=pt;return Jt({getEditor:()=>Me.value,getEditorValue:()=>Y.value}),(w,b)=>(fe.openBlock(),fe.createElementBlock("div",Di,[fe.createElementVNode("div",null,[ve.label?(fe.openBlock(),fe.createBlock(ki._sfc_main,{key:0,classes:"dsg-editor__label",label:ve.label},null,8,["label"])):fe.createCommentVNode("",!0),fe.createElementVNode("div",Hi,null,512)]),ve.errors&&ve.errors.length?(fe.openBlock(),fe.createElementBlock("div",Oi,[(fe.openBlock(!0),fe.createElementBlock(fe.Fragment,null,fe.renderList(ve.errors,(g,s)=>(fe.openBlock(),fe.createElementBlock("div",{class:"dsg-editor--error",key:s},fe.toDisplayString(g),1))),128))])):fe.createCommentVNode("",!0)]))}}),Vn=Ni,Ri={DsgEditor:Vn};exports.DsgEditor=Vn;exports.default=Ri;
@@ -8104,7 +8104,7 @@ const Fi = /* @__PURE__ */ ji(Wi), qi = { class: "dsg-editor" }, Ki = {
8104
8104
  const _ = new FormData(), x = E();
8105
8105
  Object.keys(x).forEach((L) => {
8106
8106
  _.append(L, x[L]);
8107
- }), _.append("file", g.getAsFile()), fetch(we.mediaUploadEndpoint, {
8107
+ }), _.append("file[]", g.getAsFile()), fetch(we.mediaUploadEndpoint, {
8108
8108
  method: "POST",
8109
8109
  headers: {
8110
8110
  "X-CSRF-TOKEN": c()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcodegroup-au/dsg-vue",
3
3
  "description": "Front-end Vue/Tailwind DSG for UntitledUI.",
4
- "version": "0.1.13",
4
+ "version": "0.1.14",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "preinstall": "npx only-allow pnpm",