11 lines
30 KiB
JavaScript
Raw Normal View History

(self.webpackChunk=self.webpackChunk||[]).push([["tribute"],{"./node_modules/tributejs/dist/tribute.min.js":function(V){(function(k,M){V.exports=M()})(this,function(){"use strict";function k(a,t){if(!(a instanceof t))throw new TypeError("Cannot call a class as a function")}function M(a,t){for(var e=0;e<t.length;e++){var n=t[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(a,n.key,n)}}function E(a,t,e){return t&&M(a.prototype,t),e&&M(a,e),a}function G(a,t){return function(e){if(Array.isArray(e))return e}(a)||function(e,n){if(Symbol.iterator in Object(e)||Object.prototype.toString.call(e)==="[object Arguments]"){var i=[],r=!0,o=!1,u=void 0;try{for(var l,s=e[Symbol.iterator]();!(r=(l=s.next()).done)&&(i.push(l.value),!n||i.length!==n);r=!0);}catch(c){o=!0,u=c}finally{try{r||s.return==null||s.return()}finally{if(o)throw u}}return i}}(a,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}if(Array.prototype.find||(Array.prototype.find=function(a){if(this===null)throw new TypeError("Array.prototype.find called on null or undefined");if(typeof a!="function")throw new TypeError("predicate must be a function");for(var t,e=Object(this),n=e.length>>>0,i=arguments[1],r=0;r<n;r++)if(t=e[r],a.call(i,t,r,e))return t}),window&&typeof window.CustomEvent!="function"){var L=function(a,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var e=document.createEvent("CustomEvent");return e.initCustomEvent(a,t.bubbles,t.cancelable,t.detail),e};window.Event!==void 0&&(L.prototype=window.Event.prototype),window.CustomEvent=L}var J=function(){function a(t){k(this,a),this.tribute=t,this.tribute.events=this}return E(a,[{key:"bind",value:function(t){t.boundKeydown=this.keydown.bind(t,this),t.boundKeyup=this.keyup.bind(t,this),t.boundInput=this.input.bind(t,this),t.addEventListener("keydown",t.boundKeydown,!1),t.addEventListener("keyup",t.boundKeyup,!1),t.addEventListener("input",t.boundInput,!1)}},{key:"unbind",value:function(t){t.removeEventListener("keydown",t.boundKeydown,!1),t.removeEventListener("keyup",t.boundKeyup,!1),t.removeEventListener("input",t.boundInput,!1),delete t.boundKeydown,delete t.boundKeyup,delete t.boundInput}},{key:"keydown",value:function(t,e){t.shouldDeactivate(e)&&(t.tribute.isActive=!1,t.tribute.hideMenu());var n=this;t.commandEvent=!1,a.keys().forEach(function(i){i.key===e.keyCode&&(t.commandEvent=!0,t.callbacks()[i.value.toLowerCase()](e,n))})}},{key:"input",value:function(t,e){t.inputEvent=!0,t.keyup.call(this,t,e)}},{key:"click",value:function(t,e){var n=t.tribute;if(n.menu&&n.menu.contains(e.target)){var i=e.target;for(e.preventDefault(),e.stopPropagation();i.nodeName.toLowerCase()!=="li";)if(!(i=i.parentNode)||i===n.menu)throw new Error("cannot find the <li> container for the click");n.selectItemAtIndex(i.getAttribute("data-index"),e),n.hideMenu()}else n.current.element&&!n.current.externalTrigger&&(n.current.externalTrigger=!1,setTimeout(function(){return n.hideMenu()}))}},{key:"keyup",value:function(t,e){if(t.inputEvent&&(t.inputEvent=!1),t.updateSelection(this),e.keyCode!==27){if(!t.tribute.allowSpaces&&t.tribute.hasTrailingSpace)return t.tribute.hasTrailingSpace=!1,t.commandEvent=!0,void t.callbacks().space(e,this);if(!t.tribute.isActive)if(t.tribute.autocompleteMode)t.callbacks().triggerChar(e,this,"");else{var n=t.getKeyCode(t,this,e);if(isNaN(n)||!n)return;var i=t.tribute.triggers().find(function(r){return r.charCodeAt(0)===n});i!==void 0&&t.callbacks().triggerChar(e,this,i)}t.tribute.current.mentionText.length<t.tribute.current.collection.menuShowMinLength||((t.tribute.current.trigger||t.tribute.autocompleteMode)&&t.commandEvent===!1||t.tribute.isActive&&e.keyCode===8)&&t.tribute.showMenuFor(this,!0)}}},{key:"shouldDeactivate",value:function(t){if(!this.tribute.isActive)return!1;if(this.tribute.current.mentionText.length===0){var e=!1;return a.keys().forEach(function(n){t.keyCode===n.key&&(e=!0)}),!e}return!1}},{key:"getKeyCode",value:function(t,e,n){var i=t.tribute,r=i.range.getTriggerInfo(!1,i.hasTrailingSpace,!0,i.a
left: `).concat(e.left,`px;
right: `).concat(e.right,`px;
bottom: `).concat(e.bottom,`px;
position: absolute;
display: block;`),e.left==="auto"&&(this.tribute.menu.style.left="auto"),e.top==="auto"&&(this.tribute.menu.style.top="auto"),t&&this.scrollIntoView(),window.setTimeout(function(){var o={width:n.tribute.menu.offsetWidth,height:n.tribute.menu.offsetHeight},u=n.isMenuOffScreen(e,o),l=window.innerWidth>o.width&&(u.left||u.right),s=window.innerHeight>o.height&&(u.top||u.bottom);(l||s)&&(n.tribute.menu.style.cssText="display: none",n.positionMenuAtCaret(t))},0)}else this.tribute.menu.style.cssText="display: none"}},{key:"selectElement",value:function(t,e,n){var i,r=t;if(e)for(var o=0;o<e.length;o++){if((r=r.childNodes[e[o]])===void 0)return;for(;r.length<n;)n-=r.length,r=r.nextSibling;r.childNodes.length!==0||r.length||(r=r.previousSibling)}var u=this.getWindowSelection();(i=this.getDocument().createRange()).setStart(r,n),i.setEnd(r,n),i.collapse(!0);try{u.removeAllRanges()}catch{}u.addRange(i),t.focus()}},{key:"replaceTriggerText",value:function(t,e,n,i,r){var o=this.getTriggerInfo(!0,n,e,this.tribute.allowSpaces,this.tribute.autocompleteMode);if(o!==void 0){var u=this.tribute.current,l=new CustomEvent("tribute-replaced",{detail:{item:r,instance:u,context:o,event:i}});if(this.isContentEditable(u.element)){t+=typeof this.tribute.replaceTextSuffix=="string"?this.tribute.replaceTextSuffix:"\xA0";var s=o.mentionPosition+o.mentionText.length;this.tribute.autocompleteMode||(s+=o.mentionTriggerChar.length),this.pasteHtml(t,o.mentionPosition,s)}else{var c=this.tribute.current.element,f=typeof this.tribute.replaceTextSuffix=="string"?this.tribute.replaceTextSuffix:" ";t+=f;var h=o.mentionPosition,m=o.mentionPosition+o.mentionText.length+f.length;this.tribute.autocompleteMode||(m+=o.mentionTriggerChar.length-1),c.value=c.value.substring(0,h)+t+c.value.substring(m,c.value.length),c.selectionStart=h+t.length,c.selectionEnd=h+t.length}u.element.dispatchEvent(new CustomEvent("input",{bubbles:!0})),u.element.dispatchEvent(l)}}},{key:"pasteHtml",value:function(t,e,n){var i,r;r=this.getWindowSelection(),(i=this.getDocument().createRange()).setStart(r.anchorNode,e),i.setEnd(r.anchorNode,n),i.deleteContents();var o=this.getDocument().createElement("div");o.innerHTML=t;for(var u,l,s=this.getDocument().createDocumentFragment();u=o.firstChild;)l=s.appendChild(u);i.insertNode(s),l&&((i=i.cloneRange()).setStartAfter(l),i.collapse(!0),r.removeAllRanges(),r.addRange(i))}},{key:"getWindowSelection",value:function(){return this.tribute.collection.iframe?this.tribute.collection.iframe.contentWindow.getSelection():window.getSelection()}},{key:"getNodePositionInParent",value:function(t){if(t.parentNode===null)return 0;for(var e=0;e<t.parentNode.childNodes.length;e++)if(t.parentNode.childNodes[e]===t)return e}},{key:"getContentEditableSelectedPath",value:function(t){var e=this.getWindowSelection(),n=e.anchorNode,i=[];if(n!=null){for(var r,o=n.contentEditable;n!==null&&o!=="true";)r=this.getNodePositionInParent(n),i.push(r),(n=n.parentNode)!==null&&(o=n.contentEditable);return i.reverse(),{selected:n,path:i,offset:e.getRangeAt(0).startOffset}}}},{key:"getTextPrecedingCurrentSelection",value:function(){var t=this.tribute.current,e="";if(this.isContentEditable(t.element)){var n=this.getWindowSelection().anchorNode;if(n!=null){var i=n.textContent,r=this.getWindowSelection().getRangeAt(0).startOffset;i&&r>=0&&(e=i.substring(0,r))}}else{var o=this.tribute.current.element;if(o){var u=o.selectionStart;o.value&&u>=0&&(e=o.value.substring(0,u))}}return e}},{key:"getLastWordInText",value:function(t){var e=(t=t.replace(/\u00A0/g," ")).split(/\s+/);return e[e.length-1].trim()}},{key:"getTriggerInfo",value:function(t,e,n,i,r){var o,u,l,s=this,c=this.tribute.current;if(this.isContentEditable(c.element)){var f=this.getContentEditableSelectedPath(c);f&&(o=f.selected,u=f.path,l=f.offset)}else o=this.tribute.current.element;var h=this.getTextPrecedingCurrentSelection(),m=this.getLastWordInText(h);if(r)return{mentionPosition:h.length-m.length,mentionText:m,mentionSelectedElement:o,mentionSelectedPath:u,mentionSelectedOffset:l};if(h!=null)
left: 0px;
position: fixed;
display: block;
visibility; hidden;`,t.width=this.tribute.menu.offsetWidth,t.height=this.tribute.menu.offsetHeight,this.tribute.menu.style.cssText="display: none;",t}},{key:"getTextAreaOrInputUnderlinePosition",value:function(t,e,n){var i=window.mozInnerScreenX!==null,r=this.getDocument().createElement("div");r.id="input-textarea-caret-position-mirror-div",this.getDocument().body.appendChild(r);var o=r.style,u=window.getComputedStyle?getComputedStyle(t):t.currentStyle;o.whiteSpace="pre-wrap",t.nodeName!=="INPUT"&&(o.wordWrap="break-word"),o.position="absolute",o.visibility="hidden",["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing"].forEach(function(C){o[C]=u[C]}),i?(o.width="".concat(parseInt(u.width)-2,"px"),t.scrollHeight>parseInt(u.height)&&(o.overflowY="scroll")):o.overflow="hidden",r.textContent=t.value.substring(0,e),t.nodeName==="INPUT"&&(r.textContent=r.textContent.replace(/\s/g,"\xA0"));var l=this.getDocument().createElement("span");l.textContent=t.value.substring(e)||".",r.appendChild(l);var s=t.getBoundingClientRect(),c=document.documentElement,f=(window.pageXOffset||c.scrollLeft)-(c.clientLeft||0),h=(window.pageYOffset||c.scrollTop)-(c.clientTop||0),m=0,v=0;this.menuContainerIsBody&&(m=s.top,v=s.left);var d={top:m+h+l.offsetTop+parseInt(u.borderTopWidth)+parseInt(u.fontSize)-t.scrollTop,left:v+f+l.offsetLeft+parseInt(u.borderLeftWidth)},p=window.innerWidth,y=window.innerHeight,b=this.getMenuDimensions(),w=this.isMenuOffScreen(d,b);w.right&&(d.right=p-d.left,d.left="auto");var T=this.tribute.menuContainer?this.tribute.menuContainer.offsetHeight:this.getDocument().body.offsetHeight;if(w.bottom){var S=T-(y-(this.tribute.menuContainer?this.tribute.menuContainer.getBoundingClientRect():this.getDocument().body.getBoundingClientRect()).top);d.bottom=S+(y-s.top-l.offsetTop),d.top="auto"}return(w=this.isMenuOffScreen(d,b)).left&&(d.left=p>b.width?f+p-b.width:f,delete d.right),w.top&&(d.top=y>b.height?h+y-b.height:h,delete d.bottom),this.getDocument().body.removeChild(r),d}},{key:"getContentEditableCaretPosition",value:function(t){var e,n=this.getWindowSelection();(e=this.getDocument().createRange()).setStart(n.anchorNode,t),e.setEnd(n.anchorNode,t),e.collapse(!1);var i=e.getBoundingClientRect(),r=document.documentElement,o=(window.pageXOffset||r.scrollLeft)-(r.clientLeft||0),u=(window.pageYOffset||r.scrollTop)-(r.clientTop||0),l={left:i.left+o,top:i.top+i.height+u},s=window.innerWidth,c=window.innerHeight,f=this.getMenuDimensions(),h=this.isMenuOffScreen(l,f);h.right&&(l.left="auto",l.right=s-i.left-o);var m=this.tribute.menuContainer?this.tribute.menuContainer.offsetHeight:this.getDocument().body.offsetHeight;if(h.bottom){var v=m-(c-(this.tribute.menuContainer?this.tribute.menuContainer.getBoundingClientRect():this.getDocument().body.getBoundingClientRect()).top);l.top="auto",l.bottom=v+(c-i.top)}return(h=this.isMenuOffScreen(l,f)).left&&(l.left=s>f.width?o+s-f.width:o,delete l.right),h.top&&(l.top=c>f.height?u+c-f.height:u,delete l.bottom),this.menuContainerIsBody||(l.left=l.left?l.left-this.tribute.menuContainer.offsetLeft:l.left,l.top=l.top?l.top-this.tribute.menuContainer.offsetTop:l.top),l}},{key:"scrollIntoView",value:function(t){var e,n=this.menu;if(n!==void 0){for(;e===void 0||e.height===0;)if((e=n.getBoundingClientRect()).height===0&&((n=n.childNodes[0])===void 0||!n.getBoundingClientRect))return;var i=e.top,r=i+e.height;if(i<0)window.scrollTo(0,window.pageYOffset+e.top-20);else if(r>window.innerHeight){var o=window.pageYOffset+e.top-20;o-window.pageYOffset>100&&(o=window.pageYOffset+100);var u=window.pageYOffset-(window.innerHeight-r);u>o&&(u=o),window.scrollTo(0,u)}}}},{key:"menuContainerIsBody",get:function(){return this.tribute.menuContainer===docume