/* Tagify v4.27.0 - tags input component By: Yair Even-Or https://github.com/yairEO/tagify Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This Software may not be rebranded and sold as a library under any other name other than "Tagify" (by owner) or as part of another library. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react/jsx-runtime"),require("react"),require("react-dom/server"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react/jsx-runtime","react","react-dom/server","prop-types"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Tagify={},t.jsxRuntime,t.React,t.server,t.propTypes)}(this,(function(t,e,n,i,s){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=a(n),r="​";function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n/g,">").replace(/"/g,""").replace(/`|'/g,"'"):t}function y(t){var e=Object.prototype.toString.call(t).split(" ")[1].slice(0,-1);return t===Object(t)&&"Array"!=e&&"Function"!=e&&"RegExp"!=e&&"HTMLUnknownElement"!=e}function b(t,e,n){var i,s;function a(t,e){for(var n in e)if(e.hasOwnProperty(n)){if(y(e[n])){y(t[n])?a(t[n],e[n]):t[n]=Object.assign({},e[n]);continue}if(Array.isArray(e[n])){t[n]=Object.assign([],e[n]);continue}t[n]=e[n]}}return i=t,(null!=(s=Object)&&"undefined"!=typeof Symbol&&s[Symbol.hasInstance]?s[Symbol.hasInstance](i):i instanceof s)||(t={}),a(t,e),n&&a(t,n),t}function w(){var t=[],e={},n=!0,i=!1,s=void 0;try{for(var a,o=arguments[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var r=a.value,l=!0,d=!1,c=void 0;try{for(var u,g=r[Symbol.iterator]();!(l=(u=g.next()).done);l=!0){var h=u.value;y(h)?e[h.value]||(t.push(h),e[h.value]=1):t.includes(h)||t.push(h)}}catch(t){d=!0,c=t}finally{try{l||null==g.return||g.return()}finally{if(d)throw c}}}}catch(t){i=!0,s=t}finally{try{n||null==o.return||o.return()}finally{if(i)throw s}}return t}function T(t){return String.prototype.normalize?"string"==typeof t?t.normalize("NFD").replace(/[\u0300-\u036f]/g,""):void 0:t}var O=function(){return/(?=.*chrome)(?=.*android)/i.test(navigator.userAgent)};function D(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(function(t){return(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)}))}function x(t){return t&&t.classList&&t.classList.contains(this.settings.classNames.tag)}function S(t){return t&&t.closest(this.settings.classNames.tagSelector)}function E(t,e){var n=window.getSelection();return e=e||n.getRangeAt(0),"string"==typeof t&&(t=document.createTextNode(t)),e&&(e.deleteContents(),e.insertNode(t)),t}function I(t,e,n){return t?(e&&(t.__tagifyTagData=n?e:b({},t.__tagifyTagData||{},e)),t.__tagifyTagData):(c.warn("tag element doesn't exist",{tagElm:t,data:e}),e)}function M(t){if(t&&t.parentNode){var e=t,n=window.getSelection(),i=n.getRangeAt(0);n.rangeCount&&(i.setStartAfter(e),i.collapse(!0),n.removeAllRanges(),n.addRange(i))}}function N(t,e){t.forEach((function(t){if(I(t.previousSibling)||!t.previousSibling){var n=document.createTextNode("ā€‹");t.before(n),e&&M(n)}}))}var _={delimiters:",",pattern:null,tagTextProp:"value",maxTags:1/0,callbacks:{},addTagOnBlur:!0,addTagOn:["blur","tab","enter"],onChangeAfterBlur:!0,duplicates:!1,whitelist:[],blacklist:[],enforceWhitelist:!1,userInput:!0,focusable:!0,keepInvalidTags:!1,createInvalidTags:!0,mixTagsAllowedAfter:/,|\.|\:|\s/,mixTagsInterpolator:["[[","]]"],backspace:!0,skipInvalid:!1,pasteAsTags:!0,editTags:{clicks:2,keepInvalid:!0},transformTag:function(){},trim:!0,a11y:{focusableTags:!1},mixMode:{insertAfterTag:"Ā "},autoComplete:{enabled:!0,rightKey:!1,tabKey:!1},classNames:{namespace:"tagify",mixMode:"tagify--mix",selectMode:"tagify--select",input:"tagify__input",focus:"tagify--focus",tagNoAnimation:"tagify--noAnim",tagInvalid:"tagify--invalid",tagNotAllowed:"tagify--notAllowed",scopeLoading:"tagify--loading",hasMaxTags:"tagify--hasMaxTags",hasNoTags:"tagify--noTags",empty:"tagify--empty",inputInvalid:"tagify__input--invalid",dropdown:"tagify__dropdown",dropdownWrapper:"tagify__dropdown__wrapper",dropdownHeader:"tagify__dropdown__header",dropdownFooter:"tagify__dropdown__footer",dropdownItem:"tagify__dropdown__item",dropdownItemActive:"tagify__dropdown__item--active",dropdownItemHidden:"tagify__dropdown__item--hidden",dropdownItemSelected:"tagify__dropdown__item--selected",dropdownInital:"tagify__dropdown--initial",tag:"tagify__tag",tagText:"tagify__tag-text",tagX:"tagify__tag__removeBtn",tagLoading:"tagify__tag--loading",tagEditing:"tagify__tag--editable",tagFlash:"tagify__tag--flash",tagHide:"tagify__tag--hide"},dropdown:{classname:"",enabled:2,maxItems:10,searchKeys:["value","searchBy"],fuzzySearch:!0,caseSensitive:!1,accentedSearch:!0,includeSelectedTags:!1,escapeHTML:!0,highlightFirst:!0,closeOnSelect:!0,clearOnSelect:!0,position:"all",appendTarget:null},hooks:{beforeRemoveTag:function(){return Promise.resolve()},beforePaste:function(){return Promise.resolve()},suggestionClick:function(){return Promise.resolve()},beforeKeyDown:function(){return Promise.resolve()}}};function A(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function C(t){for(var e=1;e0&&void 0!==arguments[0])||arguments[0],e=this.dropdown.events.callbacks,n=this.listeners.dropdown=this.listeners.dropdown||{position:this.dropdown.position.bind(this,null),onKeyDown:e.onKeyDown.bind(this),onMouseOver:e.onMouseOver.bind(this),onMouseLeave:e.onMouseLeave.bind(this),onClick:e.onClick.bind(this),onScroll:e.onScroll.bind(this)},i=t?"addEventListener":"removeEventListener";"manual"!=this.settings.dropdown.position&&(document[i]("scroll",n.position,!0),window[i]("resize",n.position),window[i]("keydown",n.onKeyDown)),this.DOM.dropdown[i]("mouseover",n.onMouseOver),this.DOM.dropdown[i]("mouseleave",n.onMouseLeave),this.DOM.dropdown[i]("mousedown",n.onClick),this.DOM.dropdown.content[i]("scroll",n.onScroll)},callbacks:{onKeyDown:function(t){var e=this;if(this.state.hasFocus&&!this.state.composing){var n=this.settings,i=this.DOM.dropdown.querySelector(n.classNames.dropdownItemActiveSelector),s=this.dropdown.getSuggestionDataByNode(i),a="mix"==n.mode,o="select"==n.mode;n.hooks.beforeKeyDown(t,{tagify:this}).then((function(r){switch(t.key){case"ArrowDown":case"ArrowUp":case"Down":case"Up":t.preventDefault();var l=e.dropdown.getAllSuggestionsRefs(),d="ArrowUp"==t.key||"Up"==t.key;i&&(i=e.dropdown.getNextOrPrevOption(i,!d)),i&&i.matches(n.classNames.dropdownItemSelector)||(i=l[d?l.length-1:0]),e.dropdown.highlightOption(i,!0);break;case"Escape":case"Esc":e.dropdown.hide();break;case"ArrowRight":if(e.state.actions.ArrowLeft||n.autoComplete.rightKey)return;case"Tab":var u=!n.autoComplete.rightKey||!n.autoComplete.tabKey;if(!a&&!o&&i&&u&&!e.state.editing&&s){t.preventDefault();var g=e.dropdown.getMappedValue(s);return e.input.autocomplete.set.call(e,g),!1}return!0;case"Enter":t.preventDefault(),n.hooks.suggestionClick(t,{tagify:e,tagData:s,suggestionElm:i}).then((function(){if(i)return e.dropdown.selectOption(i),i=e.dropdown.getNextOrPrevOption(i,!d),void e.dropdown.highlightOption(i);e.dropdown.hide(),a||e.addTags(e.state.inputText.trim(),!0)})).catch((function(t){return c.warn(t)}));break;case"Backspace":if(a||e.state.editing.scope)return;var h=e.input.raw.call(e);""!=h&&8203!=h.charCodeAt(0)||(!0===n.backspace?e.removeTags():"edit"==n.backspace&&setTimeout(e.editTag.bind(e),0))}}))}},onMouseOver:function(t){var e=t.target.closest(this.settings.classNames.dropdownItemSelector);this.dropdown.highlightOption(e)},onMouseLeave:function(t){this.dropdown.highlightOption()},onClick:function(t){var e=this;if(0==t.button&&t.target!=this.DOM.dropdown&&t.target!=this.DOM.dropdown.content){var n=t.target.closest(this.settings.classNames.dropdownItemSelector),i=this.dropdown.getSuggestionDataByNode(n);this.state.actions.selectOption=!0,setTimeout((function(){return e.state.actions.selectOption=!1}),50),this.settings.hooks.suggestionClick(t,{tagify:this,tagData:i,suggestionElm:n}).then((function(){n?e.dropdown.selectOption(n,t):e.dropdown.hide()})).catch((function(t){return c.warn(t)}))}},onScroll:function(t){var e=t.target,n=e.scrollTop/(e.scrollHeight-e.parentNode.clientHeight)*100;this.trigger("dropdown:scroll",{percentage:Math.round(n)})}}},refilter:function(t){t=t||this.state.dropdown.query||"",this.suggestedListItems=this.dropdown.filterListItems(t),this.dropdown.fill(),this.suggestedListItems.length||this.dropdown.hide(),this.trigger("dropdown:updated",this.DOM.dropdown)},getSuggestionDataByNode:function(t){for(var e,n=t&&t.getAttribute("value"),i=this.suggestedListItems.length;i--;){if(y(e=this.suggestedListItems[i])&&e.value==n)return e;if(e==n)return{value:e}}},getNextOrPrevOption:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.dropdown.getAllSuggestionsRefs(),i=n.findIndex((function(e){return e===t}));return e?n[i+1]:n[i-1]},highlightOption:function(t,e){var n,i=this.settings.classNames.dropdownItemActive;if(this.state.ddItemElm&&(this.state.ddItemElm.classList.remove(i),this.state.ddItemElm.removeAttribute("aria-selected")),!t)return this.state.ddItemData=null,this.state.ddItemElm=null,void this.input.autocomplete.suggest.call(this);n=this.dropdown.getSuggestionDataByNode(t),this.state.ddItemData=n,this.state.ddItemElm=t,t.classList.add(i),t.setAttribute("aria-selected",!0),e&&(t.parentNode.scrollTop=t.clientHeight+t.offsetTop-t.parentNode.clientHeight),this.settings.autoComplete&&(this.input.autocomplete.suggest.call(this,n),this.dropdown.position())},selectOption:function(t,e){var n=this,i=this.settings,s=i.dropdown,a=s.clearOnSelect,o=s.closeOnSelect;if(!t)return this.addTags(this.state.inputText,!0),void(o&&this.dropdown.hide());e=e||{};var r=t.getAttribute("value"),l="noMatch"==r,d="mix"==i.mode,c=this.suggestedListItems.find((function(t){var e;return(null!==(e=t.value)&&void 0!==e?e:t)==r}));if(this.trigger("dropdown:select",{data:c,elm:t,event:e}),r&&(c||l)){if(this.state.editing){var u=this.normalizeTags([c])[0];c=i.transformTag.call(this,u)||u,this.onEditTagDone(null,b({__isValid:!0},c))}else this[d?"addMixTags":"addTags"]([c||this.input.raw.call(this)],a);(d||this.DOM.input.parentNode)&&(setTimeout((function(){n.DOM.input.focus(),n.toggleFocusClass(!0)})),o&&setTimeout(this.dropdown.hide.bind(this)),t.addEventListener("transitionend",(function(){n.dropdown.fillHeaderFooter(),setTimeout((function(){t.remove(),n.dropdown.refilter()}),100)}),{once:!0}),t.classList.add(this.settings.classNames.dropdownItemHidden))}else o&&setTimeout(this.dropdown.hide.bind(this))},selectAll:function(t){this.suggestedListItems.length=0,this.dropdown.hide(),this.dropdown.filterListItems("");var e=this.dropdown.filterListItems("");return t||(e=this.state.dropdown.suggestions),this.addTags(e,!0),this},filterListItems:function(t,e){var n,i,s,a,o,r,l=function(){var t,l,d=void 0,c=void 0;t=p[b],i=(null!=(l=Object)&&"undefined"!=typeof Symbol&&l[Symbol.hasInstance]?l[Symbol.hasInstance](t):t instanceof l)?p[b]:{value:p[b]};var f,m=!Object.keys(i).some((function(t){return v.includes(t)}))?["value"]:v;u.fuzzySearch&&!e.exact?(a=m.reduce((function(t,e){return t+" "+(i[e]||"")}),"").toLowerCase().trim(),u.accentedSearch&&(a=T(a),r=T(r)),d=0==a.indexOf(r),c=a===r,f=a,s=r.toLowerCase().split(" ").every((function(t){return f.includes(t.toLowerCase())}))):(d=!0,s=m.some((function(t){var n=""+(i[t]||"");return u.accentedSearch&&(n=T(n),r=T(r)),u.caseSensitive||(n=n.toLowerCase()),c=n===r,e.exact?n===r:0==n.indexOf(r)}))),o=!u.includeSelectedTags&&n.isTagDuplicate(y(i)?i.value:i),s&&!o&&(c&&d?h.push(i):"startsWith"==u.sortby&&d?g.unshift(i):g.push(i))},d=this,c=this.settings,u=c.dropdown,g=(e=e||{},[]),h=[],p=c.whitelist,f=u.maxItems>=0?u.maxItems:1/0,m=u.includeSelectedTags||"select"==c.mode,v=u.searchKeys,b=0;if(!(t="select"==c.mode&&this.value.length&&this.value[0][c.tagTextProp]==t?"":t)||!v.length)return g=m?p:p.filter((function(t){return!d.isTagDuplicate(y(t)?t.value:t)})),this.state.dropdown.suggestions=g,g.slice(0,f);for(r=u.caseSensitive?""+t:(""+t).toLowerCase();bt.length)&&(e=t.length);for(var n=0,i=new Array(e);n=0,r=this.dropdown.getAppendTarget();return o?(this.DOM.scope.setAttribute("aria-expanded",!0),document.body.contains(this.DOM.dropdown)||(this.DOM.dropdown.classList.add(a.classNames.dropdownInital),this.dropdown.position(s),r.appendChild(this.DOM.dropdown),setTimeout((function(){return i.DOM.dropdown.classList.remove(a.classNames.dropdownInital)}))),this):this},fill:function(t){t="string"==typeof t?t:this.dropdown.createListHTML(t||this.suggestedListItems);var e,n=this.settings.templates.dropdownContent.call(this,t);this.DOM.dropdown.content.innerHTML=(e=n)?e.replace(/\>[\r\n ]+\<").split(/>\s+<").trim():""},fillHeaderFooter:function(){var t=this.dropdown.filterListItems(this.state.dropdown.query),e=this.parseTemplate("dropdownHeader",[t]),n=this.parseTemplate("dropdownFooter",[t]),i=this.dropdown.getHeaderRef(),s=this.dropdown.getFooterRef();e&&(null==i||i.parentNode.replaceChild(e,i)),n&&(null==s||s.parentNode.replaceChild(n,s))},position:function(t){var e=this.settings.dropdown,n=this.dropdown.getAppendTarget();if("manual"!=e.position&&n){var i,s,a,o,r,l,d,c,u,g=this.DOM.dropdown,h=e.RTL,p=n===document.body,f=n===this.DOM.scope,m=p?window.pageYOffset:n.scrollTop,v=document.fullscreenElement||document.webkitFullscreenElement||document.documentElement,y=v.clientHeight,b=Math.max(v.clientWidth||0,window.innerWidth||0)>480?e.position:"all",w=this.DOM["input"==b?"input":"scope"];if(t=t||g.clientHeight,this.state.dropdown.visible){if("text"==b?(a=(i=function(){var t=document.getSelection();if(t.rangeCount){var e,n,i=t.getRangeAt(0),s=i.startContainer,a=i.startOffset;if(a>0)return(n=document.createRange()).setStart(s,a-1),n.setEnd(s,a),{left:(e=n.getBoundingClientRect()).right,top:e.top,bottom:e.bottom};if(s.getBoundingClientRect)return s.getBoundingClientRect()}return{left:-9999,top:-9999}}()).bottom,s=i.top,o=i.left,r="auto"):(l=function(t){var e=0,n=0;for(t=t.parentNode;t&&t!=v;)e+=t.offsetTop||0,n+=t.offsetLeft||0,t=t.parentNode;return{top:e,left:n}}(n),i=w.getBoundingClientRect(),s=f?-1:i.top-l.top,a=(f?i.height:i.bottom-l.top)-1,o=f?-1:i.left-l.left,r=i.width+"px"),!p){var T=function(){for(var t=0,n=e.appendTarget.parentNode;n;)t+=n.scrollTop||0,n=n.parentNode;return t}();s+=T,a+=T}var O;s=Math.floor(s),a=Math.ceil(a),c=((d=null!==(O=e.placeAbove)&&void 0!==O?O:y-i.bottom\n ').concat(this.settings.templates.input.call(this),"\n ").concat(r,"\n ")},input:function(){var t=this.settings,e=t.placeholder||r;return"')},tag:function(t,e){var n=e.settings;return'\n \n
\n ').concat(t[n.tagTextProp]||t.value,"\n
\n
")},dropdown:function(t){var e=t.dropdown,n="manual"==e.position;return'
\n
\n
')},dropdownContent:function(t){var e=this.settings.templates,n=this.state.dropdown.suggestions;return"\n ".concat(e.dropdownHeader.call(this,n),"\n ").concat(t,"\n ").concat(e.dropdownFooter.call(this,n),"\n ")},dropdownItem:function(t){return"
').concat(t.mappedValue||t.value,"
")},dropdownHeader:function(t){return"
')},dropdownFooter:function(t){var e=t.length-this.settings.dropdown.maxItems;return e>0?"
\n ').concat(e," more items. Refine your search.\n
"):""},dropdownItemNoMatch:null};function z(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);nt.length)&&(e=t.length);for(var n=0,i=new Array(e);n0&&void 0!==arguments[0])||arguments[0],n=this.settings,i=this.events.callbacks,s=e?"addEventListener":"removeEventListener";if(!this.state.mainEvents||!e){for(var a in this.state.mainEvents=e,e&&!this.listeners.main&&(this.events.bindGlobal.call(this),this.settings.isJQueryPlugin&&jQuery(this.DOM.originalInput).on("tagify.removeAllTags",this.removeAllTags.bind(this))),t=this.listeners.main=this.listeners.main||{keydown:["input",i.onKeydown.bind(this)],click:["scope",i.onClickScope.bind(this)],dblclick:"select"!=n.mode&&["scope",i.onDoubleClickScope.bind(this)],paste:["input",i.onPaste.bind(this)],drop:["input",i.onDrop.bind(this)],compositionstart:["input",i.onCompositionStart.bind(this)],compositionend:["input",i.onCompositionEnd.bind(this)]})t[a]&&this.DOM[t[a][0]][s](a,t[a][1]);var o=this.listeners.main.inputMutationObserver||new MutationObserver(i.onInputDOMChange.bind(this));o.disconnect(),"mix"==n.mode&&o.observe(this.DOM.input,{childList:!0}),this.events.bindOriginaInputListener.call(this)}},bindOriginaInputListener:function(t){var e=(t||0)+500;this.listeners.main&&(clearInterval(this.listeners.main.originalInputValueObserverInterval),this.listeners.main.originalInputValueObserverInterval=setInterval(this.events.callbacks.observeOriginalInputValue.bind(this),e))},bindGlobal:function(t){var e,n=this.events.callbacks,i=t?"removeEventListener":"addEventListener";if(this.listeners&&(t||!this.listeners.global)){this.listeners.global=this.listeners.global||[{type:this.isIE?"keydown":"input",target:this.DOM.input,cb:n[this.isIE?"onInputIE":"onInput"].bind(this)},{type:"keydown",target:window,cb:n.onWindowKeyDown.bind(this)},{type:"focusin",target:this.DOM.scope,cb:n.onFocusBlur.bind(this)},{type:"focusout",target:this.DOM.scope,cb:n.onFocusBlur.bind(this)},{type:"click",target:document,cb:n.onClickAnywhere.bind(this),useCapture:!0}];var s=!0,a=!1,o=void 0;try{for(var r,l=this.listeners.global[Symbol.iterator]();!(s=(r=l.next()).done);s=!0)(e=r.value).target[i](e.type,e.cb,!!e.useCapture)}catch(t){a=!0,o=t}finally{try{s||null==l.return||l.return()}finally{if(a)throw o}}}},unbindGlobal:function(){this.events.bindGlobal.call(this,!0)},callbacks:{onFocusBlur:function(t){var e,n,i=this.settings,s=S.call(this,t.target),a=x.call(this,t.target),o=t.target.classList.contains(i.classNames.tagX),r="focusin"==t.type,l="focusout"==t.type;s&&r&&!a&&!o&&this.toggleFocusClass(this.state.hasFocus=+new Date);var d=t.target?this.trim(this.DOM.input.textContent):"",c=null===(n=this.value)||void 0===n||null===(e=n[0])||void 0===e?void 0:e[i.tagTextProp],u=i.dropdown.enabled>=0,g={relatedTarget:t.relatedTarget},h=this.state.actions.selectOption&&(u||!i.dropdown.closeOnSelect),p=this.state.actions.addNew&&u;if(l){if(t.relatedTarget===this.DOM.scope)return this.dropdown.hide(),void this.DOM.input.focus();this.postUpdate(),i.onChangeAfterBlur&&this.triggerChangeEvent()}if(!(h||p||o))if(r||s?(this.state.hasFocus=+new Date,this.toggleFocusClass(this.state.hasFocus)):this.state.hasFocus=!1,"mix"!=i.mode){if(r){if(!i.focusable)return;var f=0===i.dropdown.enabled&&!this.state.dropdown.visible;return this.toggleFocusClass(!0),this.trigger("focus",g),void(!f||a&&"select"!==i.mode||this.dropdown.show(this.value.length?"":void 0))}if(l){if(this.trigger("blur",g),this.loading(!1),"select"==i.mode){if(this.value.length){var m=this.getTagElms()[0];d=this.trim(m.textContent)}c===d&&(d="")}d&&!this.state.actions.selectOption&&i.addTagOnBlur&&i.addTagOn.includes("blur")&&this.addTags(d,!0)}s||(this.DOM.input.removeAttribute("style"),this.dropdown.hide())}else r?this.trigger("focus",g):l&&(this.trigger("blur",g),this.loading(!1),this.dropdown.hide(),this.state.dropdown.visible=void 0,this.setStateSelection())},onCompositionStart:function(t){this.state.composing=!0},onCompositionEnd:function(t){this.state.composing=!1},onWindowKeyDown:function(t){var e,n=this.settings,i=document.activeElement,s=S.call(this,i)&&this.DOM.scope.contains(document.activeElement),a=s&&i.hasAttribute("readonly");if(this.state.hasFocus||s&&!a){e=i.nextElementSibling;var o=t.target.classList.contains(n.classNames.tagX);switch(t.key){case"Backspace":n.readonly||this.state.editing||(this.removeTags(i),(e||this.DOM.input).focus());break;case"Enter":if(o)return void this.removeTags(t.target.parentNode);n.a11y.focusableTags&&x.call(this,i)&&setTimeout(this.editTag.bind(this),0,i);break;case"ArrowDown":this.state.dropdown.visible||"mix"==n.mode||this.dropdown.show()}}},onKeydown:function(t){var e=this,n=this.settings;if(!this.state.composing&&n.userInput){"select"==n.mode&&n.enforceWhitelist&&this.value.length&&"Tab"!=t.key&&t.preventDefault();var i=this.trim(t.target.textContent);this.trigger("keydown",{event:t}),n.hooks.beforeKeyDown(t,{tagify:this}).then((function(s){if("mix"==n.mode){switch(t.key){case"Left":case"ArrowLeft":e.state.actions.ArrowLeft=!0;break;case"Delete":case"Backspace":if(e.state.editing)return;var a=document.getSelection(),o="Delete"==t.key&&a.anchorOffset==(a.anchorNode.length||0),r=a.anchorNode.previousSibling,l=1==a.anchorNode.nodeType||!a.anchorOffset&&r&&1==r.nodeType&&a.anchorNode.previousSibling;p(e.DOM.input.innerHTML);var d,c,u,g=e.getTagElms(),h=1===a.anchorNode.length&&a.anchorNode.nodeValue==String.fromCharCode(8203);if("edit"==n.backspace&&l)return d=1==a.anchorNode.nodeType?null:a.anchorNode.previousElementSibling,setTimeout(e.editTag.bind(e),0,d),void t.preventDefault();if(O()&&Q(l,Element))return u=m(l),l.hasAttribute("readonly")||l.remove(),e.DOM.input.focus(),void setTimeout((function(){M(u),e.DOM.input.click()}));if("BR"==a.anchorNode.nodeName)return;if((o||l)&&1==a.anchorNode.nodeType?c=0==a.anchorOffset?o?g[0]:null:g[Math.min(g.length,a.anchorOffset)-1]:o?c=a.anchorNode.nextElementSibling:Q(l,Element)&&(c=l),3==a.anchorNode.nodeType&&!a.anchorNode.nodeValue&&a.anchorNode.previousElementSibling&&t.preventDefault(),(l||o)&&!n.backspace)return void t.preventDefault();if("Range"!=a.type&&!a.anchorOffset&&a.anchorNode==e.DOM.input&&"Delete"!=t.key)return void t.preventDefault();if("Range"!=a.type&&c&&c.hasAttribute("readonly"))return void M(m(c));"Delete"==t.key&&h&&I(a.anchorNode.nextSibling)&&e.removeTags(a.anchorNode.nextSibling),clearTimeout(B),B=setTimeout((function(){var t=document.getSelection();p(e.DOM.input.innerHTML),!o&&t.anchorNode.previousSibling,e.value=[].map.call(g,(function(t,n){var i=I(t);if(t.parentNode||i.readonly)return i;e.trigger("remove",{tag:t,index:n,data:i})})).filter((function(t){return t}))}),20)}return!0}var f="manual"==n.dropdown.position;switch(t.key){case"Backspace":"select"==n.mode&&n.enforceWhitelist&&e.value.length?e.removeTags():e.state.dropdown.visible&&"manual"!=n.dropdown.position||""!=t.target.textContent&&8203!=i.charCodeAt(0)||(!0===n.backspace?e.removeTags():"edit"==n.backspace&&setTimeout(e.editTag.bind(e),0));break;case"Esc":case"Escape":if(e.state.dropdown.visible)return;t.target.blur();break;case"Down":case"ArrowDown":e.state.dropdown.visible||e.dropdown.show();break;case"ArrowRight":var v=e.state.inputSuggestion||e.state.ddItemData;if(v&&n.autoComplete.rightKey)return void e.addTags([v],!0);break;case"Tab":var y="select"==n.mode;if(!i||y)return!0;t.preventDefault();case"Enter":if(e.state.dropdown.visible&&!f)return;t.preventDefault(),setTimeout((function(){e.state.dropdown.visible&&!f||e.state.actions.selectOption||!n.addTagOn.includes(t.key.toLowerCase())||e.addTags(i,!0)}))}})).catch((function(t){return t}))}},onInput:function(t){this.postUpdate();var e=this.settings;if("mix"==e.mode)return this.events.callbacks.onMixTagsInput.call(this,t);var n=this.input.normalize.call(this,void 0,{trim:!1}),i=n.length>=e.dropdown.enabled,s={value:n,inputElm:this.DOM.input},a=this.validateTag({value:n});"select"==e.mode&&this.toggleScopeValidation(a),s.isValid=a,this.state.inputText!=n&&(this.input.set.call(this,n,!1),-1!=n.search(e.delimiters)?this.addTags(n)&&this.input.set.call(this):e.dropdown.enabled>=0&&this.dropdown[i?"show":"hide"](n),this.trigger("input",s))},onMixTagsInput:function(t){var e,n,i,s,a,o,r,l,d=this,c=this.settings,u=this.value.length,g=this.getTagElms(),h=document.createDocumentFragment(),p=window.getSelection().getRangeAt(0),f=[].map.call(g,(function(t){return I(t).value}));if("deleteContentBackward"==t.inputType&&O()&&this.events.callbacks.onKeydown.call(this,{target:t.target,key:"Backspace"}),N(this.getTagElms()),this.value.slice().forEach((function(t){t.readonly&&!f.includes(t.value)&&h.appendChild(d.createTagElem(t))})),h.childNodes.length&&(p.insertNode(h),this.setRangeAtStartEnd(!1,h.lastChild)),g.length!=u)return this.value=[].map.call(this.getTagElms(),(function(t){return I(t)})),void this.update({withoutChangeEvent:!0});if(this.hasMaxTags())return!0;if(window.getSelection&&(o=window.getSelection()).rangeCount>0&&3==o.anchorNode.nodeType){if((p=o.getRangeAt(0).cloneRange()).collapse(!0),p.setStart(o.focusNode,0),i=(e=p.toString().slice(0,p.endOffset)).split(c.pattern).length-1,(n=e.match(c.pattern))&&(s=e.slice(e.lastIndexOf(n[n.length-1]))),s){if(this.state.actions.ArrowLeft=!1,this.state.tag={prefix:s.match(c.pattern)[0],value:s.replace(c.pattern,"")},this.state.tag.baseOffset=o.baseOffset-this.state.tag.value.length,l=this.state.tag.value.match(c.delimiters))return this.state.tag.value=this.state.tag.value.replace(c.delimiters,""),this.state.tag.delimiters=l[0],this.addTags(this.state.tag.value,c.dropdown.clearOnSelect),void this.dropdown.hide();a=this.state.tag.value.length>=c.dropdown.enabled;try{r=(r=this.state.flaggedTags[this.state.tag.baseOffset]).prefix==this.state.tag.prefix&&r.value[0]==this.state.tag.value[0],this.state.flaggedTags[this.state.tag.baseOffset]&&!this.state.tag.value&&delete this.state.flaggedTags[this.state.tag.baseOffset]}catch(t){}(r||i500||!e.focusable)?this.state.dropdown.visible?this.dropdown.hide():0===e.dropdown.enabled&&"mix"!=e.mode&&this.dropdown.show(this.value.length?"":void 0):"select"!=e.mode||0!==e.dropdown.enabled||this.state.dropdown.visible||(this.events.callbacks.onDoubleClickScope.call(this,Y(function(t){for(var e=1;e=this.settings.dropdown.enabled&&(this.state.editing&&(this.state.editing.value=o),this.dropdown.show(o)),this.trigger("edit:input",{tag:i,index:s,data:b({},this.value[s],{newValue:o}),event:e})},onEditTagPaste:function(t,e){var n=(e.clipboardData||window.clipboardData).getData("Text");e.preventDefault();var i=E(n);this.setRangeAtStartEnd(!1,i)},onEditTagClick:function(t,e){this.events.callbacks.onClickScope.call(this,e)},onEditTagFocus:function(t){this.state.editing={scope:t,input:t.querySelector("[contenteditable]")}},onEditTagBlur:function(t,e){var n=x.call(this,e.relatedTarget);if("select"==this.settings.mode&&n&&e.relatedTarget.contains(e.target))this.dropdown.hide();else if(this.state.editing&&(this.state.hasFocus||this.toggleFocusClass(),this.DOM.scope.contains(t))){var i,s,a,o=this.settings,r=t.closest("."+o.classNames.tag),l=I(r),d=this.input.normalize.call(this,t),c=($(i={},o.tagTextProp,d),$(i,"__tagId",l.__tagId),i),u=l.__originalData,g=this.editTagChangeDetected(b(l,c)),h=this.validateTag(c);if(d)if(g){var p;if(s=this.hasMaxTags(),a=b({},u,($(p={},o.tagTextProp,this.trim(d)),$(p,"__isValid",h),p)),o.transformTag.call(this,a,u),!0!==(h=(!s||!0===u.__isValid)&&this.validateTag(a))){if(this.trigger("invalid",{data:a,tag:r,message:h}),o.editTags.keepInvalid)return;o.keepInvalidTags?a.__isValid=h:a=u}else o.keepInvalidTags&&(delete a.title,delete a["aria-invalid"],delete a.class);this.onEditTagDone(r,a)}else this.onEditTagDone(r,u);else this.onEditTagDone(r)}},onEditTagkeydown:function(t,e){if(!this.state.composing)switch(this.trigger("edit:keydown",{event:t}),t.key){case"Esc":case"Escape":this.state.editing=!1,!!e.__tagifyTagData.__originalData.value?e.parentNode.replaceChild(e.__tagifyTagData.__originalHTML,e):e.remove();break;case"Enter":case"Tab":t.preventDefault();setTimeout((function(){return t.target.blur()}),0)}},onDoubleClickScope:function(t){var e,n,i=t.target.closest("."+this.settings.classNames.tag),s=I(i),a=this.settings;i&&!1!==s.editable&&(e=i.classList.contains(this.settings.classNames.tagEditing),n=i.hasAttribute("readonly"),a.readonly||e||n||!this.settings.editTags||!a.userInput||(this.events.callbacks.onEditTagFocus.call(this,i),this.editTag(i)),this.toggleFocusClass(!0),"select"!=a.mode&&this.trigger("dblclick",{tag:i,index:this.getNodeIndex(i),data:I(i)}))},onInputDOMChange:function(t){var e=this;t.forEach((function(t){t.addedNodes.forEach((function(t){if("

"==t.outerHTML)t.replaceWith(document.createElement("br"));else if(1==t.nodeType&&t.querySelector(e.settings.classNames.tagSelector)){var n,i=document.createTextNode("");3==t.childNodes[0].nodeType&&"BR"!=t.previousSibling.nodeName&&(i=document.createTextNode("\n")),(n=t).replaceWith.apply(n,Z([i].concat(Z(Z(t.childNodes).slice(0,-1))))),M(i)}else if(x.call(e,t)){var s;if(3!=(null===(s=t.previousSibling)||void 0===s?void 0:s.nodeType)||t.previousSibling.textContent||t.previousSibling.remove(),t.previousSibling&&"BR"==t.previousSibling.nodeName){t.previousSibling.replaceWith("\nā€‹");for(var a=t.nextSibling,o="";a;)o+=a.textContent,a=a.nextSibling;o.trim()&&M(t.previousSibling)}else t.previousSibling&&!I(t.previousSibling)||t.before("ā€‹")}})),t.removedNodes.forEach((function(t){t&&"BR"==t.nodeName&&x.call(e,n)&&(e.removeTags(n),e.fixFirefoxLastTagNoCaret())}))}));var n=this.DOM.input.lastChild;n&&""==n.nodeValue&&n.remove(),n&&"BR"==n.nodeName||this.DOM.input.appendChild(document.createElement("br"))}}};function et(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);nt.length)&&(e=t.length);for(var n=0,i=new Array(e);n=0||(s[n]=t[n]);return s}(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(s[n]=t[n])}return s}function gt(t){return function(t){if(Array.isArray(t))return rt(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return rt(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return rt(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ht(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}ot.prototype={_dropdown:U,placeCaretAfterNode:M,getSetTagData:I,helpers:{sameStr:u,removeCollectionProp:g,omit:h,isObject:y,parseHTML:f,escapeHTML:v,extend:b,concatWithoutDups:w,getUID:D,isNodeTag:x},customEventsList:["change","add","remove","invalid","input","paste","click","keydown","focus","blur","edit:input","edit:beforeUpdate","edit:updated","edit:start","edit:keydown","dropdown:show","dropdown:hide","dropdown:select","dropdown:updated","dropdown:noMatch","dropdown:scroll"],dataProps:["__isValid","__removed","__originalData","__originalHTML","__tagId"],trim:function(t){return this.settings.trim&&t&&"string"==typeof t?t.trim():t},parseHTML:f,templates:q,parseTemplate:function(t,e){return f((t=this.settings.templates[t]||t).apply(this,e))},set whitelist(t){var e=t&&Array.isArray(t);this.settings.whitelist=e?t:[],this.setPersistedData(e?t:[],"whitelist")},get whitelist(){return this.settings.whitelist},set userInput(t){this.settings.userInput=!!t,this.setContentEditable(!!t)},get userInput(){return this.settings.userInput},generateClassSelectors:function(t){var e=function(e){var n=e;Object.defineProperty(t,n+"Selector",{get:function(){return"."+this[n].split(" ")[0]}})};for(var n in t)e(n)},applySettings:function(t,e){var n,i;_.templates=this.templates;var s=b({},_,"mix"==e.mode?{dropdown:{position:"text"}}:{}),a=this.settings=b({},s,e);if(a.disabled=t.hasAttribute("disabled"),a.readonly=a.readonly||t.hasAttribute("readonly"),a.placeholder=v(t.getAttribute("placeholder")||a.placeholder||""),a.required=t.hasAttribute("required"),this.generateClassSelectors(a.classNames),void 0===a.dropdown.includeSelectedTags&&(a.dropdown.includeSelectedTags=a.duplicates),this.isIE&&(a.autoComplete=!1),["whitelist","blacklist"].forEach((function(e){var n=t.getAttribute("data-"+e);n&&it(n=n.split(a.delimiters),Array)&&(a[e]=n)})),"autoComplete"in e&&!y(e.autoComplete)&&(a.autoComplete=_.autoComplete,a.autoComplete.enabled=e.autoComplete),"mix"==a.mode&&(a.pattern=a.pattern||/@/,a.autoComplete.rightKey=!0,a.delimiters=e.delimiters||null,a.tagTextProp&&!a.dropdown.searchKeys.includes(a.tagTextProp)&&a.dropdown.searchKeys.push(a.tagTextProp)),t.pattern)try{a.pattern=new RegExp(t.pattern)}catch(t){}if(a.delimiters){a._delimiters=a.delimiters;try{a.delimiters=new RegExp(this.settings.delimiters,"g")}catch(t){}}a.disabled&&(a.userInput=!1),this.TEXTS=st({},K,a.texts||{}),("select"!=a.mode||(null===(n=e.dropdown)||void 0===n?void 0:n.enabled))&&a.userInput||(a.dropdown.enabled=0),a.dropdown.appendTarget=(null===(i=e.dropdown)||void 0===i?void 0:i.appendTarget)||document.body;var o=this.getPersistedData("whitelist");Array.isArray(o)&&(this.whitelist=Array.isArray(a.whitelist)?w(a.whitelist,o):o)},getAttributes:function(t){var e,n=this.getCustomAttributes(t),i="";for(e in n)i+=" "+e+(void 0!==t[e]?'="'.concat(n[e],'"'):"");return i},getCustomAttributes:function(t){if(!y(t))return"";var e,n={};for(e in t)"__"!=e.slice(0,2)&&"class"!=e&&t.hasOwnProperty(e)&&void 0!==t[e]&&(n[e]=v(t[e]));return n},setStateSelection:function(){var t=window.getSelection(),e={anchorOffset:t.anchorOffset,anchorNode:t.anchorNode,range:t.getRangeAt&&t.rangeCount&&t.getRangeAt(0)};return this.state.selection=e,e},getCSSVars:function(){var t,e,n,i=getComputedStyle(this.DOM.scope,null);this.CSSVars={tagHideTransition:(t=function(t){if(!t)return{};var e=(t=t.trim().split(" ")[0]).split(/\d+/g).filter((function(t){return t})).pop().trim();return{value:+t.split(e).filter((function(t){return t}))[0].trim(),unit:e}}((n="tag-hide-transition",i.getPropertyValue("--"+n))),e=t.value,"s"==t.unit?1e3*e:e)}},build:function(t){var e=this.DOM,n=t.closest("label");this.settings.mixMode.integrated?(e.originalInput=null,e.scope=t,e.input=t):(e.originalInput=t,e.originalInput_tabIndex=t.tabIndex,e.scope=this.parseTemplate("wrapper",[t,this.settings]),e.input=e.scope.querySelector(this.settings.classNames.inputSelector),t.parentNode.insertBefore(e.scope,t),t.tabIndex=-1),n&&n.setAttribute("for","")},destroy:function(){this.events.unbindGlobal.call(this),this.DOM.scope.parentNode.removeChild(this.DOM.scope),this.DOM.originalInput.tabIndex=this.DOM.originalInput_tabIndex,delete this.DOM.originalInput.__tagify,this.dropdown.hide(!0),this.removeAllCustomListeners(),clearTimeout(this.dropdownHide__bindEventsTimeout),clearInterval(this.listeners.main.originalInputValueObserverInterval)},loadOriginalValues:function(t){var e,n=this.settings;if(this.state.blockChangeEvent=!0,void 0===t){var i=this.getPersistedData("value");t=i&&!this.DOM.originalInput.value?i:n.mixMode.integrated?this.DOM.input.textContent:this.DOM.originalInput.value}if(this.removeAllTags(),t)if("mix"==n.mode)this.parseMixTags(t),(e=this.DOM.input.lastChild)&&"BR"==e.tagName||this.DOM.input.insertAdjacentHTML("beforeend","
");else{try{it(JSON.parse(t),Array)&&(t=JSON.parse(t))}catch(t){}this.addTags(t,!0).forEach((function(t){return t&&t.classList.add(n.classNames.tagNoAnimation)}))}else this.postUpdate();this.state.lastOriginalValueReported=n.mixMode.integrated?"":this.DOM.originalInput.value},cloneEvent:function(t){var e={};for(var n in t)"path"!=n&&(e[n]=t[n]);return e},loading:function(t){return this.state.isLoading=t,this.DOM.scope.classList[t?"add":"remove"](this.settings.classNames.scopeLoading),this},tagLoading:function(t,e){return t&&t.classList[e?"add":"remove"](this.settings.classNames.tagLoading),this},toggleClass:function(t,e){"string"==typeof t&&this.DOM.scope.classList.toggle(t,e)},toggleScopeValidation:function(t){var e=!0===t||void 0===t;!this.settings.required&&t&&t===this.TEXTS.empty&&(e=!0),this.toggleClass(this.settings.classNames.tagInvalid,!e),this.DOM.scope.title=e?"":t},toggleFocusClass:function(t){this.toggleClass(this.settings.classNames.focus,!!t)},setPlaceholder:function(t){var e=this;["data","aria"].forEach((function(n){return e.DOM.input.setAttribute("".concat(n,"-placeholder"),t)}))},triggerChangeEvent:function(){if(!this.settings.mixMode.integrated){var t=this.DOM.originalInput,e=this.state.lastOriginalValueReported!==t.value,n=new CustomEvent("change",{bubbles:!0});e&&(this.state.lastOriginalValueReported=t.value,n.simulated=!0,t._valueTracker&&t._valueTracker.setValue(Math.random()),t.dispatchEvent(n),this.trigger("change",this.state.lastOriginalValueReported),t.value=this.state.lastOriginalValueReported)}},events:tt,fixFirefoxLastTagNoCaret:function(){},setRangeAtStartEnd:function(t,e){if(e){t="number"==typeof t?t:!!t,e=e.lastChild||e;var n=document.getSelection();if(it(n.focusNode,Element)&&!this.DOM.input.contains(n.focusNode))return!0;try{n.rangeCount>=1&&["Start","End"].forEach((function(i){return n.getRangeAt(0)["set"+i](e,t||e.length)}))}catch(t){console.warn(t)}}},insertAfterTag:function(t,e){if(e=e||this.settings.mixMode.insertAfterTag,t&&t.parentNode&&e)return e="string"==typeof e?document.createTextNode(e):e,t.parentNode.insertBefore(e,t.nextSibling),e},editTagChangeDetected:function(t){var e=t.__originalData;for(var n in e)if(!this.dataProps.includes(n)&&t[n]!=e[n])return!0;return!1},getTagTextNode:function(t){return t.querySelector(this.settings.classNames.tagTextSelector)},setTagTextNode:function(t,e){this.getTagTextNode(t).innerHTML=v(e)},editTag:function(t,e){var n=this;t=t||this.getLastTag(),e=e||{};var i=this.settings,s=this.getTagTextNode(t),a=this.getNodeIndex(t),o=I(t),r=this.events.callbacks,l=!0,d="select"==i.mode;if(!d&&this.dropdown.hide(),s){if(!it(o,Object)||!("editable"in o)||o.editable)return o=I(t,{__originalData:b({},o),__originalHTML:t.cloneNode(!0)}),I(o.__originalHTML,o.__originalData),s.setAttribute("contenteditable",!0),t.classList.add(i.classNames.tagEditing),s.addEventListener("click",r.onEditTagClick.bind(this,t)),s.addEventListener("blur",r.onEditTagBlur.bind(this,this.getTagTextNode(t))),s.addEventListener("input",r.onEditTagInput.bind(this,s)),s.addEventListener("paste",r.onEditTagPaste.bind(this,s)),s.addEventListener("keydown",(function(e){return r.onEditTagkeydown.call(n,e,t)})),s.addEventListener("compositionstart",r.onCompositionStart.bind(this)),s.addEventListener("compositionend",r.onCompositionEnd.bind(this)),e.skipValidation||(l=this.editTagToggleValidity(t)),s.originalIsValid=l,this.trigger("edit:start",{tag:t,index:a,data:o,isValid:l}),s.focus(),!d&&this.setRangeAtStartEnd(!1,s),0===i.dropdown.enabled&&!d&&this.dropdown.show(),this.state.hasFocus=!0,this}else c.warn("Cannot find element in Tag template: .",i.classNames.tagTextSelector)},editTagToggleValidity:function(t,e){var n;if(e=e||I(t))return(n=!("__isValid"in e)||!0===e.__isValid)||this.removeTagsFromValue(t),this.update(),t.classList.toggle(this.settings.classNames.tagNotAllowed,!n),e.__isValid=n,e.__isValid;c.warn("tag has no data: ",t,e)},onEditTagDone:function(t,e){t=t||this.state.editing.scope,e=e||{};var n,i,s={tag:t,index:this.getNodeIndex(t),previousData:I(t),data:e},a=this.settings;this.trigger("edit:beforeUpdate",s,{cloneData:!1}),this.state.editing=!1,delete e.__originalData,delete e.__originalHTML,t&&(void 0!==(i=e[a.tagTextProp])?null===(n=(i+="").trim)||void 0===n?void 0:n.call(i):a.tagTextProp in e?void 0:e.value)?(t=this.replaceTag(t,e),this.editTagToggleValidity(t,e),a.a11y.focusableTags?t.focus():"select"!=a.mode&&M(t)):t&&this.removeTags(t),this.trigger("edit:updated",s),this.dropdown.hide(),this.settings.keepInvalidTags&&this.reCheckInvalidTags()},replaceTag:function(t,e){e&&""!==e.value&&void 0!==e.value||(e=t.__tagifyTagData),e.__isValid&&1!=e.__isValid&&b(e,this.getInvalidTagAttrs(e,e.__isValid));var n=this.createTagElem(e);return t.parentNode.replaceChild(n,t),this.updateValueByDOMTags(),n},updateValueByDOMTags:function(){var t=this;this.value.length=0;var e=this.settings.classNames,n=[e.tagNotAllowed.split(" ")[0],e.tagHide];[].forEach.call(this.getTagElms(),(function(e){at(e.classList).some((function(t){return n.includes(t)}))||t.value.push(I(e))})),this.update()},injectAtCaret:function(t,e){var n;if(!(e=e||(null===(n=this.state.selection)||void 0===n?void 0:n.range))&&t)return this.appendMixTags(t),this;var i=E(t,e);return this.setRangeAtStartEnd(!1,i),this.updateValueByDOMTags(),this.update(),this},input:{set:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.settings,i=n.dropdown.closeOnSelect;this.state.inputText=t,e&&(this.DOM.input.innerHTML=v(""+t),t&&this.toggleClass(n.classNames.empty,!this.DOM.input.innerHTML)),!t&&i&&this.dropdown.hide.bind(this),this.input.autocomplete.suggest.call(this),this.input.validate.call(this)},raw:function(){return this.DOM.input.textContent},validate:function(){var t=!this.state.inputText||!0===this.validateTag({value:this.state.inputText});return this.DOM.input.classList.toggle(this.settings.classNames.inputInvalid,!t),t},normalize:function(t,e){var n=t||this.DOM.input,i=[];n.childNodes.forEach((function(t){return 3==t.nodeType&&i.push(t.nodeValue)})),i=i.join("\n");try{i=i.replace(/(?:\r\n|\r|\n)/g,this.settings.delimiters.source.charAt(0))}catch(t){}return i=i.replace(/\s/g," "),(null==e?void 0:e.trim)?this.trim(i):i},autocomplete:{suggest:function(t){if(this.settings.autoComplete.enabled){"object"!=typeof(t=t||{value:""})&&(t={value:t});var e=this.dropdown.getMappedValue(t);if("number"!=typeof e){var n=this.state.inputText.toLowerCase(),i=e.substr(0,this.state.inputText.length).toLowerCase(),s=e.substring(this.state.inputText.length);e&&this.state.inputText&&i==n?(this.DOM.input.setAttribute("data-suggest",s),this.state.inputSuggestion=t):(this.DOM.input.removeAttribute("data-suggest"),delete this.state.inputSuggestion)}}},set:function(t){var e=this.DOM.input.getAttribute("data-suggest"),n=t||(e?this.state.inputText+e:null);return!!n&&("mix"==this.settings.mode?this.replaceTextWithNode(document.createTextNode(this.state.tag.prefix+n)):(this.input.set.call(this,n),this.setRangeAtStartEnd(!1,this.DOM.input)),this.input.autocomplete.suggest.call(this),this.dropdown.hide(),!0)}}},getTagIdx:function(t){return this.value.findIndex((function(e){return e.__tagId==(t||{}).__tagId}))},getNodeIndex:function(t){var e=0;if(t)for(;t=t.previousElementSibling;)e++;return e},getTagElms:function(){for(var t=arguments.length,e=new Array(t),n=0;n=this.settings.maxTags&&this.TEXTS.exceed},setReadonly:function(t,e){var n=this.settings;this.DOM.scope.contains(document.activeElement)&&document.activeElement.blur(),n[e||"readonly"]=t,this.DOM.scope[(t?"set":"remove")+"Attribute"](e||"readonly",!0),this.settings.userInput=!0,this.setContentEditable(!t)},setContentEditable:function(t){this.DOM.input.contentEditable=t,this.DOM.input.tabIndex=t?0:-1},setDisabled:function(t){this.setReadonly(t,"disabled")},normalizeTags:function(t){var e=this,n=this.settings,i=n.whitelist,s=n.delimiters,a=n.mode,o=n.tagTextProp,r=[],l=!!i&&it(i[0],Object),d=Array.isArray(t),c=d&&t[0].value,u=function(t){return(t+"").split(s).reduce((function(t,n){var i,s=e.trim(n);return s&&t.push((nt(i={},o,s),nt(i,"value",s),i)),t}),[])};if("number"==typeof t&&(t=t.toString()),"string"==typeof t){if(!t.trim())return[];t=u(t)}else d&&(t=t.reduce((function(t,n){if(y(n)){var i=b({},n);o in i||(o="value"),i[o]=e.trim(i[o]),i[o]&&t.push(i)}else if(n){var s;(s=t).push.apply(s,at(u(n)))}return t}),[]));return l&&!c&&(t.forEach((function(t){var n=r.map((function(t){return t.value})),i=e.dropdown.filterListItems.call(e,t[o],{exact:!0});e.settings.duplicates||(i=i.filter((function(t){return!n.includes(t.value)})));var s=i.length>1?e.getWhitelistItem(t[o],o,i):i[0];s&&it(s,Object)?r.push(s):"mix"!=a&&(null==t.value&&(t.value=t[o]),r.push(t))})),r.length&&(t=r)),t},parseMixTags:function(t){var e=this,n=this.settings,i=n.mixTagsInterpolator,s=n.duplicates,a=n.transformTag,o=n.enforceWhitelist,r=n.maxTags,l=n.tagTextProp,d=[];t=t.split(i[0]).map((function(t,n){var c,u,g,h=t.split(i[1]),p=h[0],f=d.length==r;try{if(p==+p)throw Error;u=JSON.parse(p)}catch(t){u=e.normalizeTags(p)[0]||{value:p}}if(a.call(e,u),f||!(h.length>1)||o&&!e.isTagWhitelisted(u.value)||!s&&e.isTagDuplicate(u.value)){if(t)return n?i[0]+t:t}else u[c=u[l]?l:"value"]=e.trim(u[c]),g=e.createTagElem(u),d.push(u),g.classList.add(e.settings.classNames.tagNoAnimation),h[0]=g.outerHTML,e.value.push(u);return h.join("")})).join(""),this.DOM.input.innerHTML=t,this.DOM.input.appendChild(document.createTextNode("")),this.DOM.input.normalize();var c=this.getTagElms();return c.forEach((function(t,e){return I(t,d[e])})),this.update({withoutChangeEvent:!0}),N(c,this.state.hasFocus),t},replaceTextWithNode:function(t,e){if(this.state.tag||e){e=e||this.state.tag.prefix+this.state.tag.value;var n,i,s=this.state.selection||window.getSelection(),a=s.anchorNode,o=this.state.tag.delimiters?this.state.tag.delimiters.length:0;return a.splitText(s.anchorOffset-o),-1==(n=a.nodeValue.lastIndexOf(e))?!0:(i=a.splitText(n),t&&a.parentNode.replaceChild(t,i),!0)}},prepareNewTagNode:function(t,e){e=e||{};var n=this.settings,i=[],s={},a=Object.assign({},t,{value:t.value+""});if(t=Object.assign({},a),n.transformTag.call(this,t),t.__isValid=this.hasMaxTags()||this.validateTag(t),!0!==t.__isValid){if(e.skipInvalid)return;if(b(s,this.getInvalidTagAttrs(t,t.__isValid),{__preInvalidData:a}),t.__isValid==this.TEXTS.duplicate&&this.flashTag(this.getTagElmByValue(t.value)),!n.createInvalidTags)return void i.push(t.value)}return"readonly"in t&&(t.readonly?s["aria-readonly"]=!0:delete t.readonly),{tagElm:this.createTagElem(t,s),tagData:t,aggregatedInvalidInput:i}},postProcessNewTagNode:function(t,e){var n=this,i=this.settings,s=e.__isValid;s&&!0===s?(this.value.push(e),setTimeout((function(){n.trigger("add",{tag:t,index:n.value.length-1,data:e})}))):(this.trigger("invalid",{data:e,index:this.value.length,tag:t,message:s}),i.keepInvalidTags||setTimeout((function(){return n.removeTags(t,!0)}),1e3)),this.dropdown.position()},selectTag:function(t,e){var n=this;if(!this.settings.enforceWhitelist||this.isTagWhitelisted(e.value)){this.state.actions.selectOption&&setTimeout((function(){return n.setRangeAtStartEnd(!1,n.DOM.input)}));var i=this.getLastTag();return i?this.replaceTag(i,e):this.appendTag(t),this.value[0]=e,this.update(),this.trigger("add",{tag:t,data:e}),[t]}},addEmptyTag:function(t){var e=b({value:""},t||{}),n=this.createTagElem(e);I(n,e),this.appendTag(n),this.editTag(n,{skipValidation:!0}),this.toggleFocusClass(!0)},addTags:function(t,e,n){var i=this,s=[],a=this.settings,o=[],r=document.createDocumentFragment();if(!t||0==t.length)return s;switch(t=this.normalizeTags(t),a.mode){case"mix":return this.addMixTags(t);case"select":e=!1,this.removeAllTags()}return this.DOM.input.removeAttribute("style"),t.forEach((function(t){var e=i.prepareNewTagNode(t,{skipInvalid:n||a.skipInvalid});if(e){var l=e.tagElm;if(t=e.tagData,o=e.aggregatedInvalidInput,s.push(l),"select"==a.mode)return i.selectTag(l,t);r.appendChild(l),i.postProcessNewTagNode(l,t)}})),this.appendTag(r),this.update(),t.length&&e&&(this.input.set.call(this,a.createInvalidTags?"":o.join(a._delimiters)),this.setRangeAtStartEnd(!1,this.DOM.input)),this.dropdown.refilter(),s},addMixTags:function(t){var e=this;if((t=this.normalizeTags(t))[0].prefix||this.state.tag)return this.prefixedTextToTag(t[0]);var n=document.createDocumentFragment();return t.forEach((function(t){var i=e.prepareNewTagNode(t);n.appendChild(i.tagElm),e.insertAfterTag(i.tagElm),e.postProcessNewTagNode(i.tagElm,i.tagData)})),this.appendMixTags(n),n.children},appendMixTags:function(t){var e=!!this.state.selection;e?this.injectAtCaret(t):(this.DOM.input.focus(),(e=this.setStateSelection()).range.setStart(this.DOM.input,e.range.endOffset),e.range.setEnd(this.DOM.input,e.range.endOffset),this.DOM.input.appendChild(t),this.updateValueByDOMTags(),this.update())},prefixedTextToTag:function(t){var e,n,i,s=this,a=this.settings,o=null===(e=this.state.tag)||void 0===e?void 0:e.delimiters;if(t.prefix=t.prefix||this.state.tag?this.state.tag.prefix:(a.pattern.source||a.pattern)[0],i=this.prepareNewTagNode(t),n=i.tagElm,this.replaceTextWithNode(n)||this.DOM.input.appendChild(n),setTimeout((function(){return n.classList.add(s.settings.classNames.tagNoAnimation)}),300),this.value.push(i.tagData),this.update(),!o){var r=this.insertAfterTag(n)||n;setTimeout(M,0,r)}return this.state.tag=null,this.postProcessNewTagNode(n,i.tagData),n},appendTag:function(t){var e=this.DOM,n=e.input;e.scope.insertBefore(t,n)},createTagElem:function(t,e){t.__tagId=D();var n,i=b({},t,st({value:v(t.value+"")},e));return function(t){for(var e,n=document.createNodeIterator(t,NodeFilter.SHOW_TEXT,null,!1);e=n.nextNode();)e.textContent.trim()||e.parentNode.removeChild(e)}(n=this.parseTemplate("tag",[i,this])),I(n,t),n},reCheckInvalidTags:function(){var t=this,e=this.settings;this.getTagElms(e.classNames.tagNotAllowed).forEach((function(n,i){var s=I(n),a=t.hasMaxTags(),o=t.validateTag(s),r=!0===o&&!a;if("select"==e.mode&&t.toggleScopeValidation(o),r)return s=s.__preInvalidData?s.__preInvalidData:{value:s.value},t.replaceTag(n,s);n.title=a||o}))},removeTags:function(t,e,n){var i,s=this,a=this.settings;if(t=t&&it(t,HTMLElement)?[t]:it(t,Array)?t:t?[t]:[this.getLastTag()].filter((function(t){return t})),i=t.reduce((function(t,e){e&&"string"==typeof e&&(e=s.getTagElmByValue(e));var n=I(e);return e&&n&&!n.readonly&&t.push({node:e,idx:s.getTagIdx(n),data:I(e,{__removed:!0})}),t}),[]),n="number"==typeof n?n:this.CSSVars.tagHideTransition,"select"==a.mode&&(n=0,this.input.set.call(this)),1==i.length&&"select"!=a.mode&&i[0].node.classList.contains(a.classNames.tagNotAllowed)&&(e=!0),i.length)return a.hooks.beforeRemoveTag(i,{tagify:this}).then((function(){var t=function(t){t.node.parentNode&&(t.node.parentNode.removeChild(t.node),e?a.keepInvalidTags&&this.trigger("remove",{tag:t.node,index:t.idx}):(this.trigger("remove",{tag:t.node,index:t.idx,data:t.data}),this.dropdown.refilter(),this.dropdown.position(),this.DOM.input.normalize(),a.keepInvalidTags&&this.reCheckInvalidTags()))};n&&n>10&&1==i.length?function(e){e.node.style.width=parseFloat(window.getComputedStyle(e.node).width)+"px",document.body.clientTop,e.node.classList.add(a.classNames.tagHide),setTimeout(t.bind(this),n,e)}.call(s,i[0]):i.forEach(t.bind(s)),e||(s.removeTagsFromValue(i.map((function(t){return t.node}))),s.update(),"select"==a.mode&&a.userInput&&s.setContentEditable(!0))})).catch((function(t){}))},removeTagsFromDOM:function(){this.getTagElms().forEach((function(t){return t.remove()}))},removeTagsFromValue:function(t){var e=this;(t=Array.isArray(t)?t:[t]).forEach((function(t){var n=I(t),i=e.getTagIdx(n);i>-1&&e.value.splice(i,1)}))},removeAllTags:function(t){var e=this;t=t||{},this.value=[],"mix"==this.settings.mode?this.DOM.input.innerHTML="":this.removeTagsFromDOM(),this.dropdown.refilter(),this.dropdown.position(),this.state.dropdown.visible&&setTimeout((function(){e.DOM.input.focus()})),"select"==this.settings.mode&&(this.input.set.call(this),this.settings.userInput&&this.setContentEditable(!0)),this.update(t)},postUpdate:function(){this.state.blockChangeEvent=!1;var t,e,n=this.settings,i=n.classNames,s="mix"==n.mode?n.mixMode.integrated?this.DOM.input.textContent:this.DOM.originalInput.value.trim():this.value.length+this.input.raw.call(this).length;(this.toggleClass(i.hasMaxTags,this.value.length>=n.maxTags),this.toggleClass(i.hasNoTags,!this.value.length),this.toggleClass(i.empty,!s),"select"==n.mode)&&this.toggleScopeValidation(null===(e=this.value)||void 0===e||null===(t=e[0])||void 0===t?void 0:t.__isValid)},setOriginalInputValue:function(t){var e=this.DOM.originalInput;this.settings.mixMode.integrated||(e.value=t,e.tagifyValue=e.value,this.setPersistedData(t,"value"))},update:function(t){clearTimeout(this.debouncedUpdateTimeout),this.debouncedUpdateTimeout=setTimeout(function(){var e=this.getInputValue();this.setOriginalInputValue(e),this.settings.onChangeAfterBlur&&(t||{}).withoutChangeEvent||this.state.blockChangeEvent||this.triggerChangeEvent();this.postUpdate()}.bind(this),100),this.events.bindOriginaInputListener.call(this,100)},getInputValue:function(){var t=this.getCleanValue();return"mix"==this.settings.mode?this.getMixedTagsAsString(t):t.length?this.settings.originalInputValueFormat?this.settings.originalInputValueFormat(t):JSON.stringify(t):""},getCleanValue:function(t){return g(t||this.value,this.dataProps)},getMixedTagsAsString:function(){var t="",e=this,n=this.settings,i=n.originalInputValueFormat||JSON.stringify,s=n.mixTagsInterpolator;return function n(a){a.childNodes.forEach((function(a){if(1==a.nodeType){var o=I(a);if("BR"==a.tagName&&(t+="\r\n"),o&&x.call(e,a)){if(o.__removed)return;t+=s[0]+i(h(o,e.dataProps))+s[1]}else a.getAttribute("style")||["B","I","U"].includes(a.tagName)?t+=a.textContent:"DIV"!=a.tagName&&"P"!=a.tagName||(t+="\r\n",n(a))}else t+=a.textContent}))}(this.DOM.input),t}},ot.prototype.removeTag=ot.prototype.removeTags;var pt=function(t){return t};var ft=function(t){var s=t.name,a=t.value,o=t.loading,r=void 0!==o&&o,l=t.onInput,d=void 0===l?pt:l,c=t.onAdd,u=void 0===c?pt:c,g=t.onRemove,h=void 0===g?pt:g,p=t.onEditInput,f=void 0===p?pt:p,m=t.onEditBeforeUpdate,v=void 0===m?pt:m,y=t.onEditUpdated,b=void 0===y?pt:y,w=t.onEditStart,T=void 0===w?pt:w,O=t.onEditKeydown,D=void 0===O?pt:O,x=t.onInvalid,S=void 0===x?pt:x,E=t.onClick,I=void 0===E?pt:E,M=t.onKeydown,N=void 0===M?pt:M,_=t.onFocus,A=void 0===_?pt:_,C=t.onBlur,k=void 0===C?pt:C,L=t.onChange,j=void 0===L?pt:L,P=t.onDropdownShow,V=void 0===P?pt:P,R=t.onDropdownHide,F=void 0===R?pt:R,H=t.onDropdownSelect,B=void 0===H?pt:H,U=t.onDropdownScroll,W=void 0===U?pt:U,K=t.onDropdownNoMatch,q=void 0===K?pt:K,z=t.onDropdownUpdated,X=void 0===z?pt:z,J=t.readOnly,G=t.disabled,$=t.userInput,Q=void 0===$||$,Y=t.children,Z=t.settings,tt=void 0===Z?{}:Z,et=t.InputMode,nt=void 0===et?"input":et,it=t.autoFocus,st=t.className,at=t.whitelist,rt=t.tagifyRef,lt=t.placeholder,ct=void 0===lt?"":lt,ut=t.defaultValue,ft=t.showDropdown,mt=n.useRef(),vt=n.useRef(),yt=n.useRef(),bt=n.useRef(),wt=ut||a,Tt=n.useMemo((function(){return{ref:vt,name:s,defaultValue:Y||"string"==typeof wt?wt:JSON.stringify(wt),className:st,readOnly:J,disabled:G,autoFocus:it,placeholder:ct}}),[]),Ot=n.useCallback((function(){it&&yt.current&&yt.current.DOM.input.focus()}),[yt]);return n.useEffect((function(){!function(t){if(t){var n=function(n){var s=t[n];String(s).includes("jsxRuntime")&&(t[n]=function(){for(var t=arguments.length,n=new Array(t),a=0;a