/**
 * Minified by jsDelivr using Terser v5.37.0.
 * Original file: /npm/quill-mentions@0.2.4/src/js/mentions.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var AJAXController=require("./controller").AJAXController,Controller=require("./controller").Controller,View=require("./view"),extend=require("./utilities/extend"),defaultFactory=require("./defaults/defaults"),KEYUP=require("./keyboard").keyup,KEYDOWN=require("./keyboard").keydown;function QuillMentions(t,e){this.quill=t;var i=defaultFactory(e),n=this.quill.addContainer(i.containerClassName);this.triggerSymbol=i.triggerSymbol,this.includeTrigger=i.includeTrigger,this.matcher=i.matcher,this.mentionClass=i.mentionClass,this.currentMention=null,this.selectedChoiceIndex=-1,this.setView(n,i).setController(i).listenTextChange(t).listenSelectionChange(t).listenClick(n).addFormat(),i.hotkeys&&this.listenHotKeys(t),this._cachedRange=null,this.charSinceMention=0}module.exports=QuillMentions,QuillMentions.prototype.setView=function(t,e){var i={},n=e.noMatchMessage,r=e.marginTop;return i.list=e.template,i.listItem=e.choiceTemplate,i.error=e.noMatchTemplate,this.view=new View(t,i,{errMessage:n,marginTop:r}),this},QuillMentions.prototype.setController=function(t){if(!this.view)throw new Error("Must set view before controller.");var e,i={max:t.choiceMax};return t.ajax?(e=t.ajax.format,extend(i,t.ajax),this.controller=new AJAXController(e,this.view,i)):(e=t.format,i.data=t.choices,this.controller=new Controller(e,this.view,i)),this},QuillMentions.prototype.listenTextChange=function(t){var e=this.quill.constructor.events.TEXT_CHANGE;return t.on(e,function(e,i){if("api"===i)return;var n,r,o=this.findMention();o?(r=this,this.charSinceMention=0,this._cachedRange=t.getSelection(),this.currentMention=o,this._addTemporaryMentionSpan(),n=o[0].replace(this.triggerSymbol,""),this.controller.search(n,(function(){r.view.show(r.quill)}))):(this.charSinceMention++,this.view.hide())}.bind(this)),this},QuillMentions.prototype.listenSelectionChange=function(t){var e=t.constructor.events.SELECTION_CHANGE;return t.on(e,function(t){t||this.view.hide()}.bind(this)),this},QuillMentions.prototype.listenHotKeys=function(t){return t.container.addEventListener("keydown",function(t){var e=t.keyCode||t.which;this.view.isHidden()||KEYDOWN[e]&&(KEYDOWN[e].call(this),t.stopPropagation(),t.preventDefault())}.bind(this)),t.container.addEventListener("keyup",function(t){var e=t.keyCode||t.which;this.view.isHidden()&&1!==this.charSinceMention||KEYUP[e]&&KEYUP[e].call(this)}.bind(this)),this},QuillMentions.prototype.listenClick=function(t){return t.addEventListener("click",e.bind(this)),t.addEventListener("touchend",e.bind(this)),this;function e(t){var e=t.target||t.srcElement;"li"===e.tagName.toLowerCase()&&this.addMention(e),t.stopPropagation()}},QuillMentions.prototype.findMention=function(){var t=(this.quill.getSelection()||this._cachedRange).end,e=this.quill.getText(0,t);return this.matcher.exec(e)},QuillMentions.prototype.addMention=function(t){var e=this.currentMention.index,i=(this.includeTrigger?this.triggerSymbol:"")+t.dataset.display,n=e+i.length+1;this.quill.deleteText(e,e+this.currentMention[0].length),this.quill.insertText(e,i,"mention",this.mentionClass+"-"+t.dataset.mention),this.quill.insertText(e+i.length," "),this.quill.setSelection(n,n),this.view.hide()},QuillMentions.prototype._addTemporaryMentionSpan=function(t){var e=this.currentMention.index,i=this.currentMention[0];this.quill.deleteText(e,e+this.currentMention[0].length),this.quill.insertText(e,i,"mention","is-typing-mention")},QuillMentions.prototype.hasSelection=function(){return-1!==this.selectedChoiceIndex},QuillMentions.prototype.addFormat=function(t){return this.quill.addFormat("mention",{tag:"SPAN",class:"ql-"}),this};
//# sourceMappingURL=/sm/c911a617a37c63001c0de1a385b5f87adf45e5eb58397d39eedf82bc97c50238.map