dootask/public/js/build/quill-mention-hi.28a68c12.js
2024-04-09 23:35:22 +08:00

3 lines
20 KiB
JavaScript
Vendored

import{Q as m}from"./quill.3119dd88.js";function b(o){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?b=function(e){return typeof e}:b=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b(o)}function M(o,e){if(!(o instanceof e))throw new TypeError("Cannot call a class as a function")}function L(o,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(o,n.key,n)}}function S(o,e,t){return e&&L(o.prototype,e),t&&L(o,t),o}function T(o,e,t){return e in o?Object.defineProperty(o,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):o[e]=t,o}function x(){return x=Object.assign||function(o){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n])}return o},x.apply(this,arguments)}function P(o,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&k(o,e)}function p(o){return p=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},p(o)}function k(o,e){return k=Object.setPrototypeOf||function(n,i){return n.__proto__=i,n},k(o,e)}function H(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function E(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function O(o,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return E(o)}function _(o){var e=H();return function(){var n=p(o),i;if(e){var s=p(this).constructor;i=Reflect.construct(n,arguments,s)}else i=n.apply(this,arguments);return O(this,i)}}function A(o,e){for(;!Object.prototype.hasOwnProperty.call(o,e)&&(o=p(o),o!==null););return o}function g(){return typeof Reflect!="undefined"&&Reflect.get?g=Reflect.get:g=function(e,t,n){var i=A(e,t);if(!!i){var s=Object.getOwnPropertyDescriptor(i,t);return s.get?s.get.call(arguments.length<3?e:n):s.value}},g.apply(this,arguments)}function B(o,e){if(!!o){if(typeof o=="string")return w(o,e);var t=Object.prototype.toString.call(o).slice(8,-1);if(t==="Object"&&o.constructor&&(t=o.constructor.name),t==="Map"||t==="Set")return Array.from(o);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return w(o,e)}}function w(o,e){(e==null||e>o.length)&&(e=o.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=o[t];return n}function N(o,e){var t=typeof Symbol!="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(!t){if(Array.isArray(o)||(t=B(o))||e&&o&&typeof o.length=="number"){t&&(o=t);var n=0,i=function(){};return{s:i,n:function(){return n>=o.length?{done:!0}:{done:!1,value:o[n++]}},e:function(l){throw l},f:i}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,a;return{s:function(){t=t.call(o)},n:function(){var l=t.next();return s=l.done,l},e:function(l){r=!0,a=l},f:function(){try{!s&&t.return!=null&&t.return()}finally{if(r)throw a}}}}var f={TAB:9,ENTER:13,ESCAPE:27,UP:38,DOWN:40};function D(o,e,t){var n=o;return Object.keys(e).forEach(function(i){t.indexOf(i)>-1?n.dataset[i]=e[i]:delete n.dataset[i]}),n}function R(o,e){return e.reduce(function(t,n){var i=o.lastIndexOf(n);return i>t.mentionCharIndex?{mentionChar:n,mentionCharIndex:i}:{mentionChar:t.mentionChar,mentionCharIndex:t.mentionCharIndex}},{mentionChar:null,mentionCharIndex:-1})}function q(o,e){return e.test(o)}function V(o,e,t){return o>-1?!(t&&!(o===0||!!e[o-1].match(/\s/g))):!1}function Q(o){return b(o)!=="object"||o===null?o:JSON.parse(JSON.stringify(o))}var W=m.import("blots/embed"),I=function(o){P(t,o);var e=_(t);function t(n,i){var s;return M(this,t),s=e.call(this,n,i),T(E(s),"hoverHandler",void 0),T(E(s),"hoverHandler",void 0),s.clickHandler=null,s.hoverHandler=null,s.mounted=!1,s}return S(t,[{key:"update",value:function(i,s){var r=this;if(t.isAndroid()){var a=N(i),l;try{for(a.s();!(l=a.n()).done;){var u=l.value;if(!(u.type==="attributes"&&u.attributeName==="contenteditable")){setTimeout(function(){return r.remove()},0);return}}}catch(h){a.e(h)}finally{a.f()}}else i.forEach(function(h){if(h.type==="characterData"&&(h.target===r.leftGuard||h.target===r.rightGuard)){var d=r.restore(h.target);d&&(s.range=d)}})}},{key:"attach",value:function(){g(p(t.prototype),"attach",this).call(this),this.mounted||(this.mounted=!0,this.clickHandler=this.getClickHandler(),this.hoverHandler=this.getHoverHandler(),this.domNode.addEventListener("click",this.clickHandler,!1),this.domNode.addEventListener("mouseenter",this.hoverHandler,!1))}},{key:"detach",value:function(){g(p(t.prototype),"detach",this).call(this),this.mounted=!1,this.clickHandler&&(this.domNode.removeEventListener("click",this.clickHandler),this.clickHandler=null)}},{key:"getClickHandler",value:function(){var i=this;return function(s){var r=i.buildEvent("mention-clicked",s);window.dispatchEvent(r),s.preventDefault()}}},{key:"getHoverHandler",value:function(){var i=this;return function(s){var r=i.buildEvent("mention-hovered",s);window.dispatchEvent(r),s.preventDefault()}}},{key:"buildEvent",value:function(i,s){var r=new Event(i,{bubbles:!0,cancelable:!0});return r.value=x({},this.domNode.dataset),r.event=s,r}}],[{key:"create",value:function(i){var s=g(p(t),"create",this).call(this),r=document.createElement("span");if(r.className="ql-mention-denotation-char",r.innerHTML=i.denotationChar,s.appendChild(r),s.innerHTML+=i.value,t.isAndroid()){var a=document.createElement("span");a.innerHTML="&nbsp;",a.setAttribute("style","display: inline-block; height: 1px; width: 1px; overflow: hidden; "),s.appendChild(a)}return t.setDataValues(s,i)}},{key:"setDataValues",value:function(i,s){setTimeout(function(){t.isAndroid()?i.getElementsByTagName("span")[0].setAttribute("contenteditable","inherit"):t.isChrome()&&i.getElementsByTagName("span")[0].parentNode.setAttribute("contenteditable","false")},0);var r=i;return Object.keys(s).forEach(function(a){r.dataset[a]=s[a]}),r}},{key:"value",value:function(i){return i.dataset}},{key:"isAndroid",value:function(){var i=typeof window!="undefined"&&window.navigator.userAgent.toLowerCase();return i&&i.indexOf("android")>0}},{key:"isChrome",value:function(){var i=typeof window!="undefined"&&window.navigator.userAgent.toLowerCase();return i.match(/Chrome/i)+""=="chrome"}}]),t}(W);I.blotName="mention";I.tagName="span";I.className="mention";m.register(I);var U=function(){function o(e,t){var n=this;M(this,o),this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.existingSourceExecutionToken=null,this.quill=e,this.options={source:null,renderItem:function(l){return"".concat(l.value)},renderLoading:function(){return null},onSelect:function(l,u){u(l)},mentionDenotationChars:["@"],showDenotationChar:!0,allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:31,offsetTop:2,offsetLeft:0,isolateCharacter:!1,fixMentionsToQuill:!1,positioningStrategy:"normal",defaultMenuOrientation:"bottom",blotName:"mention",dataAttributes:["id","value","denotationChar","link","target","disabled"],linkTarget:"_blank",onOpen:function(){return!0},onBeforeClose:function(){return!0},onClose:function(){return!0},listItemClass:"ql-mention-list-item",mentionContainerClass:"ql-mention-list-container",mentionListClass:"ql-mention-list",spaceAfterInsert:!0,selectKeys:[f.ENTER]},x(this.options,t,{dataAttributes:Array.isArray(t.dataAttributes)?this.options.dataAttributes.concat(t.dataAttributes):this.options.dataAttributes}),this.mentionContainer=document.createElement("div"),this.mentionContainer.className=this.options.mentionContainerClass?this.options.mentionContainerClass:"",this.mentionContainer.style.cssText="display: none; position: absolute;",this.mentionContainer.onmousemove=this.onContainerMouseMove.bind(this),this.options.fixMentionsToQuill&&(this.mentionContainer.style.width="auto"),this.mentionList=document.createElement("ul"),this.mentionList.id="quill-mention-list",e.root.setAttribute("aria-owns","quill-mention-list"),this.mentionList.className=this.options.mentionListClass?this.options.mentionListClass:"",this.mentionContainer.appendChild(this.mentionList),e.on("text-change",this.onTextChange.bind(this)),e.on("selection-change",this.onSelectionChange.bind(this)),e.container.addEventListener("paste",function(){setTimeout(function(){var a=e.getSelection();n.onSelectionChange(a)})}),e.keyboard.addBinding({key:f.TAB},this.selectHandler.bind(this)),e.keyboard.bindings[f.TAB].unshift(e.keyboard.bindings[f.TAB].pop());var i=N(this.options.selectKeys),s;try{for(i.s();!(s=i.n()).done;){var r=s.value;e.keyboard.addBinding({key:r},this.selectHandler.bind(this))}}catch(a){i.e(a)}finally{i.f()}e.keyboard.bindings[f.ENTER].unshift(e.keyboard.bindings[f.ENTER].pop()),e.keyboard.addBinding({key:f.ESCAPE},this.escapeHandler.bind(this)),e.keyboard.addBinding({key:f.UP},this.upHandler.bind(this)),e.keyboard.addBinding({key:f.DOWN},this.downHandler.bind(this))}return S(o,[{key:"selectHandler",value:function(){return this.isOpen&&!this.existingSourceExecutionToken?(this.selectItem(),!1):!0}},{key:"escapeHandler",value:function(){return this.isOpen?(this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList(),!1):!0}},{key:"upHandler",value:function(){return this.isOpen&&!this.existingSourceExecutionToken?(this.prevItem(),!1):!0}},{key:"downHandler",value:function(){return this.isOpen&&!this.existingSourceExecutionToken?(this.nextItem(),!1):!0}},{key:"showMentionList",value:function(){this.options.positioningStrategy==="fixed"?document.body.appendChild(this.mentionContainer):this.quill.container.appendChild(this.mentionContainer),this.mentionContainer.style.visibility="hidden",this.mentionContainer.style.display="",this.mentionContainer.scrollTop=0,this.setMentionContainerPosition(),this.setIsOpen(!0)}},{key:"hideMentionList",value:function(){this.options.onBeforeClose(),this.mentionContainer.style.display="none",this.mentionContainer.remove(),this.setIsOpen(!1),this.quill.root.removeAttribute("aria-activedescendant")}},{key:"highlightItem",value:function(){for(var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0,n=0;n<this.mentionList.childNodes.length;n+=1)this.mentionList.childNodes[n].classList.remove("selected");if(!(this.itemIndex===-1||this.mentionList.childNodes[this.itemIndex].dataset.disabled==="true")&&(this.mentionList.childNodes[this.itemIndex].classList.add("selected"),this.quill.root.setAttribute("aria-activedescendant",this.mentionList.childNodes[this.itemIndex].id),t)){var i=this.mentionList.childNodes[this.itemIndex].offsetHeight,s=this.mentionList.childNodes[this.itemIndex].offsetTop,r=this.mentionContainer.scrollTop,a=r+this.mentionContainer.offsetHeight;s<r?this.mentionContainer.scrollTop=s:s>a-i&&(this.mentionContainer.scrollTop+=s-a+i)}}},{key:"getItemData",value:function(){var t=this.mentionList.childNodes[this.itemIndex].dataset.link,n=typeof t!="undefined",i=this.mentionList.childNodes[this.itemIndex].dataset.target;return n&&(this.mentionList.childNodes[this.itemIndex].dataset.value='<a href="'.concat(t,'" target=').concat(i||this.options.linkTarget,">").concat(this.mentionList.childNodes[this.itemIndex].dataset.value)),this.mentionList.childNodes[this.itemIndex].dataset}},{key:"onContainerMouseMove",value:function(){this.suspendMouseEnter=!1}},{key:"selectItem",value:function(){var t=this;if(this.itemIndex!==-1){var n=this.getItemData();n.disabled||(this.options.onSelect(n,function(i){t.insertItem(i)}),this.hideMentionList())}}},{key:"insertItem",value:function(t,n){var i=t;if(i!==null){this.options.showDenotationChar||(i.denotationChar="");var s;n?s=this.cursorPos:(s=this.mentionCharPos,this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,m.sources.USER)),this.quill.insertEmbed(s,this.options.blotName,i,m.sources.USER),this.options.spaceAfterInsert?(this.quill.insertText(s+1," ",m.sources.USER),this.quill.setSelection(s+2,m.sources.USER)):this.quill.setSelection(s+1,m.sources.USER),this.hideMentionList()}}},{key:"onItemMouseEnter",value:function(t){if(!this.suspendMouseEnter){var n=Number(t.target.dataset.index);!Number.isNaN(n)&&n!==this.itemIndex&&(this.itemIndex=n,this.highlightItem(!1))}}},{key:"onDisabledItemMouseEnter",value:function(t){this.suspendMouseEnter||(this.itemIndex=-1,this.highlightItem(!1))}},{key:"onItemClick",value:function(t){t.button===0&&(t.preventDefault(),t.stopImmediatePropagation(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem())}},{key:"onItemMouseDown",value:function(t){t.preventDefault(),t.stopImmediatePropagation()}},{key:"renderLoading",value:function(){var t=this.options.renderLoading();if(!!t){if(this.mentionContainer.getElementsByClassName("ql-mention-loading").length>0){this.showMentionList();return}this.mentionList.innerHTML="";var n=document.createElement("div");n.className="ql-mention-loading",n.innerHTML=this.options.renderLoading(),this.mentionContainer.append(n),this.showMentionList()}}},{key:"removeLoading",value:function(){var t=this.mentionContainer.getElementsByClassName("ql-mention-loading");t.length>0&&t[0].remove()}},{key:"renderList",value:function(t,n,i){if(n&&n.length>0){this.removeLoading(),this.values=n,this.mentionList.innerHTML="";for(var s=-1,r=0;r<n.length;r+=1){var a=document.createElement("li");a.id="quill-mention-item-"+r,a.className=this.options.listItemClass?this.options.listItemClass:"",n[r].disabled?(a.className+=" disabled",a.setAttribute("aria-hidden","true")):s===-1&&(s=r),a.dataset.index=r,a.innerHTML=this.options.renderItem(n[r],i),n[r].disabled?a.onmouseenter=this.onDisabledItemMouseEnter.bind(this):(a.onmouseenter=this.onItemMouseEnter.bind(this),a.onmouseup=this.onItemClick.bind(this),a.onmousedown=this.onItemMouseDown.bind(this)),a.dataset.denotationChar=t,this.mentionList.appendChild(D(a,n[r],this.options.dataAttributes))}this.itemIndex=s,this.highlightItem(),this.showMentionList()}else this.hideMentionList()}},{key:"nextItem",value:function(){var t=0,n;do{t++,n=(this.itemIndex+t)%this.values.length;var i=this.mentionList.childNodes[n].dataset.disabled==="true";if(t===this.values.length+1){n=-1;break}}while(i);this.itemIndex=n,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"prevItem",value:function(){var t=0,n;do{t++,n=(this.itemIndex+this.values.length-t)%this.values.length;var i=this.mentionList.childNodes[n].dataset.disabled==="true";if(t===this.values.length+1){n=-1;break}}while(i);this.itemIndex=n,this.suspendMouseEnter=!0,this.highlightItem()}},{key:"containerBottomIsNotVisible",value:function(t,n){var i=t+this.mentionContainer.offsetHeight+n.top;return i>window.pageYOffset+window.innerHeight}},{key:"containerRightIsNotVisible",value:function(t,n){if(this.options.fixMentionsToQuill)return!1;var i=t+this.mentionContainer.offsetWidth+n.left,s=window.pageXOffset+document.documentElement.clientWidth;return i>s}},{key:"setIsOpen",value:function(t){this.isOpen!==t&&(t?this.options.onOpen():this.options.onClose(),this.isOpen=t)}},{key:"setMentionContainerPosition",value:function(){this.options.positioningStrategy==="fixed"?this.setMentionContainerPosition_Fixed():this.setMentionContainerPosition_Normal()}},{key:"setMentionContainerPosition_Normal",value:function(){var t=this,n=this.quill.container.getBoundingClientRect(),i=this.quill.getBounds(this.mentionCharPos),s=this.mentionContainer.offsetHeight,r=this.options.offsetTop,a=this.options.offsetLeft;if(this.options.fixMentionsToQuill){var l=0;this.mentionContainer.style.right="".concat(l,"px")}else a+=i.left;if(this.containerRightIsNotVisible(a,n)){var u=this.mentionContainer.offsetWidth+this.options.offsetLeft,h=n.width;a=h-u}if(this.options.defaultMenuOrientation==="top"){if(this.options.fixMentionsToQuill?r=-1*(s+this.options.offsetTop):r=i.top-(s+this.options.offsetTop),r+n.top<=0){var d=this.options.offsetTop;this.options.fixMentionsToQuill?d+=n.height:d+=i.bottom,r=d}}else if(this.options.fixMentionsToQuill?r+=n.height:r+=i.bottom,this.containerBottomIsNotVisible(r,n)){var v=this.options.offsetTop*-1;this.options.fixMentionsToQuill||(v+=i.top),r=v-s}r>=0?this.options.mentionContainerClass.split(" ").forEach(function(c){t.mentionContainer.classList.add("".concat(c,"-bottom")),t.mentionContainer.classList.remove("".concat(c,"-top"))}):this.options.mentionContainerClass.split(" ").forEach(function(c){t.mentionContainer.classList.add("".concat(c,"-top")),t.mentionContainer.classList.remove("".concat(c,"-bottom"))}),this.mentionContainer.style.top="".concat(r,"px"),this.mentionContainer.style.left="".concat(a,"px"),this.mentionContainer.style.visibility="visible"}},{key:"setMentionContainerPosition_Fixed",value:function(){var t=this;this.mentionContainer.style.position="fixed",this.mentionContainer.style.height=null;var n=Q(this.quill.container.getBoundingClientRect());n.top+=window.scrollY;var i=this.quill.getBounds(this.mentionCharPos),s={left:n.left+i.left,top:n.top+i.top,width:0,height:i.height},r=this.options.fixMentionsToQuill?n:s,a=this.options.offsetTop,l=this.options.offsetLeft;if(this.options.fixMentionsToQuill){var u=r.right;this.mentionContainer.style.right="".concat(u,"px")}else l+=r.left,l+this.mentionContainer.offsetWidth>document.documentElement.clientWidth&&(l-=l+this.mentionContainer.offsetWidth-document.documentElement.clientWidth);var h=r.top,d=document.documentElement.clientHeight-(r.top+r.height),v=this.mentionContainer.offsetHeight<=d,c=this.mentionContainer.offsetHeight<=h,y;this.options.defaultMenuOrientation==="top"&&c?y="top":this.options.defaultMenuOrientation==="bottom"&&v?y="bottom":y=d>h?"bottom":"top",y==="bottom"?(a=r.top+r.height,v||(this.mentionContainer.style.height=d-3+"px"),this.options.mentionContainerClass.split(" ").forEach(function(C){t.mentionContainer.classList.add("".concat(C,"-bottom")),t.mentionContainer.classList.remove("".concat(C,"-top"))})):(a=r.top-this.mentionContainer.offsetHeight,c||(this.mentionContainer.style.height=h-3+"px",a=3),this.options.mentionContainerClass.split(" ").forEach(function(C){t.mentionContainer.classList.add("".concat(C,"-top")),t.mentionContainer.classList.remove("".concat(C,"-bottom"))})),this.mentionContainer.style.top="".concat(a,"px"),this.mentionContainer.style.left="".concat(l,"px"),this.mentionContainer.style.visibility="visible"}},{key:"getTextBeforeCursor",value:function(){var t=Math.max(0,this.cursorPos-this.options.maxChars),n=this.quill.getText(t,this.cursorPos-t);return n}},{key:"onSomethingChange",value:function(){var t=this,n=this.quill.getSelection();if(n!=null){this.cursorPos=n.index;var i=this.getTextBeforeCursor(),s=R(i,this.options.mentionDenotationChars),r=s.mentionChar,a=s.mentionCharIndex;if(V(a,i,this.options.isolateCharacter)){var l=this.cursorPos-(i.length-a);this.mentionCharPos=l;var u=i.substring(a+r.length);if(u.length>=this.options.minChars&&q(u,this.getAllowedCharsRegex(r))){this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.renderLoading();var h={abandoned:!1};this.existingSourceExecutionToken=h,this.options.source(u,function(d,v){h.abandoned||(t.existingSourceExecutionToken=null,t.renderList(r,d,v))},r)}else this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList()}else this.existingSourceExecutionToken&&(this.existingSourceExecutionToken.abandoned=!0),this.hideMentionList()}}},{key:"getAllowedCharsRegex",value:function(t){return this.options.allowedChars instanceof RegExp?this.options.allowedChars:this.options.allowedChars(t)}},{key:"onTextChange",value:function(t,n,i){i==="user"&&this.onSomethingChange()}},{key:"onSelectionChange",value:function(t){t&&t.length===0?this.onSomethingChange():this.hideMentionList()}},{key:"openMenu",value:function(t){var n=this.quill.getSelection(!0);this.quill.insertText(n.index,t),this.quill.blur(),this.quill.focus()}}]),o}();m.register("modules/mention",U);