diff --git a/resources/dist/tree.js b/resources/dist/tree.js index 96dd317..c19316c 100644 --- a/resources/dist/tree.js +++ b/resources/dist/tree.js @@ -1 +1 @@ -var ri=Object.defineProperty,di=(e,t,s)=>t in e?ri(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,c=(e,t,s)=>(di(e,typeof t!="symbol"?t+"":t,s),s),Ht=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},n=(e,t,s)=>(Ht(e,t,"read from private field"),s?s.call(e):t.get(e)),h=(e,t,s)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,s)},m=(e,t,s,i)=>(Ht(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s),a=(e,t,s)=>(Ht(e,t,"access private method"),s),Vt={arrowUp:'',arrowDown:'',arrowRight:'',attention:'',clear:'',cross:'',check:'',partialCheck:''},T=(e,t)=>{if(t.innerHTML="",typeof e=="string")t.innerHTML=e;else{let s=e.cloneNode(!0);t.appendChild(s)}},Gt=e=>{let t=e?{...e}:{};return Object.keys(Vt).forEach(s=>{t[s]||(t[s]=Vt[s])}),t},ui=e=>e.reduce((t,{name:s},i)=>(t+=s,in(this,S).focus(),0)}blur(){this.isOpened&&a(this,A,H).call(this),this.clearSearch(),n(this,S).blur()}updateValue(t){this.value=t,a(this,G,F).call(this),a(this,M,Y).call(this)}removeItem(t){this.value=this.value.filter(s=>s.id!==t),a(this,Q,qe).call(this),a(this,G,F).call(this),a(this,M,Y).call(this)}clear(){this.value=[],a(this,Q,qe).call(this),a(this,G,F).call(this),this.clearSearch()}openClose(){a(this,A,H).call(this)}clearSearch(){this.searchText="",this.searchCallback(""),a(this,M,Y).call(this)}};N=new WeakMap,S=new WeakMap,D=new WeakMap,E=new WeakMap,Se=new WeakSet,Hs=function(){a(this,G,F).call(this),a(this,M,Y).call(this),a(this,Le,Mt).call(this)},G=new WeakSet,F=function(){if(n(this,N).innerHTML="",this.showTags){n(this,N).append(...a(this,Te,$t).call(this));let e=ui(this.value);this.nameChangeCallback(e)}else{let e=a(this,Be,Ut).call(this);n(this,N).appendChild(e),this.nameChangeCallback(e.innerText)}n(this,N).appendChild(n(this,S))},Le=new WeakSet,Mt=function(){let e=[];n(this,D).innerHTML="",this.clearable&&e.push(a(this,Me,Yt).call(this)),this.isAlwaysOpened||e.push(a(this,De,Kt).call(this,this.isOpened)),e.length&&n(this,D).append(...e)},ye=new WeakSet,It=function(){if(!this.isAlwaysOpened&&n(this,E)){let e=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;T(e,n(this,E))}},M=new WeakSet,Y=function(){var e;(e=this.value)!=null&&e.length?(n(this,S).removeAttribute("placeholder"),this.srcElement.classList.remove("treeselect-input--value-not-selected")):(n(this,S).setAttribute("placeholder",this.placeholder),this.srcElement.classList.add("treeselect-input--value-not-selected")),this.searchable?this.srcElement.classList.remove("treeselect-input--unsearchable"):this.srcElement.classList.add("treeselect-input--unsearchable"),this.isSingleSelect?this.srcElement.classList.add("treeselect-input--is-single-select"):this.srcElement.classList.remove("treeselect-input--is-single-select"),n(this,S).value=this.searchText},A=new WeakSet,H=function(){this.isOpened=!this.isOpened,a(this,ye,It).call(this),this.isOpened?this.openCallback():this.closeCallback()},xe=new WeakSet,Ps=function(e,t,s){let i=document.createElement("div");return i.classList.add("treeselect-input"),i.setAttribute("tabindex","-1"),i.addEventListener("mousedown",l=>a(this,_e,Dt).call(this,l)),i.addEventListener("focus",()=>this.focusCallback(),!0),i.addEventListener("blur",()=>this.blurCallback(),!0),e.appendChild(t),i.append(e,s),i},_e=new WeakSet,Dt=function(e){e.stopPropagation(),this.isOpened||a(this,A,H).call(this),this.focus()},We=new WeakSet,Vs=function(){let e=document.createElement("div");return e.classList.add("treeselect-input__tags"),e},Te=new WeakSet,$t=function(){return this.value.map(e=>{let t=document.createElement("div");t.classList.add("treeselect-input__tags-element"),t.setAttribute("tabindex","-1"),t.setAttribute("tag-id",e.id.toString()),t.setAttribute("title",e.name);let s=a(this,Ne,jt).call(this,e.name),i=a(this,Ae,Rt).call(this);return t.addEventListener("mousedown",l=>a(this,Oe,qt).call(this,l,e.id)),t.append(s,i),t})},Oe=new WeakSet,qt=function(e,t){e.preventDefault(),e.stopPropagation(),this.removeItem(t),this.focus()},Ne=new WeakSet,jt=function(e){let t=document.createElement("span");return t.classList.add("treeselect-input__tags-name"),t.textContent=e,t},Ae=new WeakSet,Rt=function(){let e=document.createElement("span");return e.classList.add("treeselect-input__tags-cross"),T(this.iconElements.cross,e),e},Be=new WeakSet,Ut=function(){let e=document.createElement("span");if(e.classList.add("treeselect-input__tags-count"),!this.value.length)return e.textContent="",e.setAttribute("title",""),e;let t=this.value.length===1?this.value[0].name:`${this.value.length} ${this.tagsCountText}`;return e.textContent=t,e.setAttribute("title",t),e},He=new WeakSet,Gs=function(){let e=document.createElement("input");return e.classList.add("treeselect-input__edit"),this.id&&e.setAttribute("id",this.id),(!this.searchable||this.disabled)&&e.setAttribute("readonly","readonly"),this.disabled&&e.setAttribute("tabindex","-1"),this.ariaLabel.length&&e.setAttribute("aria-label",this.ariaLabel),e.addEventListener("keydown",t=>a(this,Pe,zt).call(this,t)),e.addEventListener("input",t=>a(this,Ve,Ft).call(this,t,e)),e},Pe=new WeakSet,zt=function(e){e.stopPropagation();let t=e.key;t==="Backspace"&&!this.searchText.length&&this.value.length&&!this.showTags&&this.clear(),t==="Backspace"&&!this.searchText.length&&this.value.length&&this.removeItem(this.value[this.value.length-1].id),e.code==="Space"&&(!this.searchText||!this.searchable)&&a(this,A,H).call(this),(t==="Enter"||t==="ArrowDown"||t==="ArrowUp")&&e.preventDefault(),this.keydownCallback(e),t!=="Tab"&&this.focus()},Ve=new WeakSet,Ft=function(e,t){e.stopPropagation();let s=this.searchText,i=t.value.trim();if(s.length===0&&i.length===0){t.value="";return}if(this.searchable){let l=e.target.value;this.searchCallback(l),this.isOpened||a(this,A,H).call(this)}else t.value="";this.searchText=t.value},Ge=new WeakSet,Ms=function(){let e=document.createElement("div");return e.classList.add("treeselect-input__operators"),e},Me=new WeakSet,Yt=function(){let e=document.createElement("span");return e.classList.add("treeselect-input__clear"),e.setAttribute("tabindex","-1"),T(this.iconElements.clear,e),e.addEventListener("mousedown",t=>a(this,Ie,Jt).call(this,t)),e},Ie=new WeakSet,Jt=function(e){e.preventDefault(),e.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},De=new WeakSet,Kt=function(e){m(this,E,document.createElement("span")),n(this,E).classList.add("treeselect-input__arrow");let t=e?this.iconElements.arrowUp:this.iconElements.arrowDown;return T(t,n(this,E)),n(this,E).addEventListener("mousedown",s=>a(this,$e,Xt).call(this,s)),n(this,E)},$e=new WeakSet,Xt=function(e){e.stopPropagation(),e.preventDefault(),this.focus(),a(this,A,H).call(this)},Q=new WeakSet,qe=function(){this.inputCallback(this.value)};var Is=(e,t,s,i)=>{wi(t);let l=t.filter(o=>!o.disabled&&e.some(r=>r===o.id));if(s&&l.length){l[0].checked=!0;return}l.forEach(o=>{o.checked=!0;let r=Pt(o,t,i);o.checked=r})},Pt=({id:e,checked:t},s,i)=>{let l=s.find(r=>r.id===e);if(!l)return!1;if(i)return l.checked=l.disabled?!1:!!t,l.checked;let o=Ds(!!t,l,s);return $s(l,s),o},Ds=(e,t,s)=>{if(!t.isGroup)return t.checked=t.disabled?!1:!!e,t.isPartialChecked=!1,t.checked;let i=s.filter(l=>l.childOf===t.id);return!e||t.disabled||t.isPartialChecked?(t.checked=!1,t.isPartialChecked=!1,Re(t,i,s),t.checked):qs(i,s)?js(i)?(t.checked=!1,t.isPartialChecked=!1,t.disabled=!0,t.checked):(t.checked=!1,t.isPartialChecked=!0,i.forEach(l=>{Ds(e,l,s)}),t.checked):(t.checked=!0,t.isPartialChecked=!1,Re(t,i,s),t.checked)},$s=(e,t)=>{let s=t.find(i=>i.id===e.childOf);s&&(pi(s,t),$s(s,t))},pi=(e,t)=>{let s=ke(e,t);if(js(s)){e.checked=!1,e.isPartialChecked=!1,e.disabled=!0;return}if(mi(s)){e.checked=!0,e.isPartialChecked=!1;return}if(ki(s)){e.checked=!1,e.isPartialChecked=!0;return}e.checked=!1,e.isPartialChecked=!1},Re=({checked:e,disabled:t},s,i)=>{s.forEach(l=>{l.disabled=!!t||!!l.disabled,l.checked=!!e&&!l.disabled,l.isPartialChecked=!1;let o=ke(l,i);Re({checked:e,disabled:t},o,i)})},qs=(e,t)=>e.some(s=>s.disabled)?!0:e.some(s=>{if(s.isGroup){let i=ke(s,t);return qs(i,t)}return!1}),js=e=>e.every(t=>!!t.disabled),mi=e=>e.every(t=>!!t.checked),ki=e=>e.some(t=>!!t.checked||!!t.isPartialChecked),wi=e=>{e.forEach(t=>{t.checked=!1,t.isPartialChecked=!1})},vi=(e,t,s)=>{let i={level:0,groupId:""},l=Rs(e,t,i.groupId,i.level);return bi(l,s)},Rs=(e,t,s,i)=>e.reduce((l,o)=>{var r;let p=!!((r=o.children)!=null&&r.length),k=i>=t&&p,f=i>t;if(l.push({id:o.value,name:o.name,childOf:s,isGroup:p,checked:!1,isPartialChecked:!1,level:i,isClosed:k,hidden:f,disabled:o.disabled??!1}),p){let w=Rs(o.children,t,o.value,i+1);l.push(...w)}return l},[]),ke=({id:e},t)=>t.filter(s=>s.childOf===e),fi=e=>{let{ungroupedNodes:t,allGroupedNodes:s,allNodes:i}=e.reduce((o,r)=>(r.checked&&(o.allNodes.push(r),r.isGroup?o.allGroupedNodes.push(r):o.ungroupedNodes.push(r)),o),{ungroupedNodes:[],allGroupedNodes:[],allNodes:[]}),l=i.filter(o=>!s.some(({id:r})=>r===o.childOf));return{ungroupedNodes:t,groupedNodes:l,allNodes:i}},bi=(e,t)=>(e.filter(s=>!!s.disabled).forEach(({id:s})=>Pt({id:s,checked:!1},e,t)),e),we=(e,{id:t,isClosed:s})=>{ke({id:t},e).forEach(i=>{i.hidden=s??!1,i.isGroup&&!i.isClosed&&we(e,{id:i.id,isClosed:s})})},gi=e=>{e.filter(t=>t.isGroup&&!t.disabled&&(t.checked||t.isPartialChecked)).forEach(t=>{t.isClosed=!1,we(e,t)})},Ci=(e,t)=>{let s=Ei(e,t);e.forEach(i=>{s.some(({id:l})=>l===i.id)?(i.isGroup&&(i.isClosed=!1,we(e,i)),i.hidden=!1):i.hidden=!0})},Ei=(e,t)=>e.reduce((s,i)=>{if(i.name.toLowerCase().includes(t.toLowerCase())){if(s.push(i),i.isGroup){let l=Us(i.id,e);s.push(...l)}if(i.childOf){let l=zs(i.childOf,e);s.push(...l)}}return s},[]),Us=(e,t)=>t.reduce((s,i)=>(i.childOf===e&&(s.push(i),i.isGroup&&s.push(...Us(i.id,t))),s),[]),zs=(e,t)=>t.reduce((s,i)=>(i.id===e&&(s.push(i),i.childOf&&s.push(...zs(i.childOf,t))),s),[]),Si=e=>{let{duplications:t}=e.reduce((s,i)=>(s.allItems.some(l=>l.toString()===i.id.toString())&&s.duplications.push(i.id),s.allItems.push(i.id),s),{duplications:[],allItems:[]});t.length&&console.error(`Validation: You have duplicated values: ${t.join(", ")}! You should use unique values.`)},Li=(e,t,s,i,l,o,r,p,k)=>{Is(e,t,l,k),p&&r&&gi(t),oe(t,s,i,o)},oe=(e,t,s,i)=>{e.forEach(l=>{let o=t.querySelector(`[input-id="${l.id}"]`),r=_(o);o.checked=l.checked,yi(l,r,i),xi(l,r),_i(l,r),Wi(l,r,s),Ti(l,r),Ni(l,r,e),Oi(l,o,s)}),Ai(e,t)},yi=(e,t,s)=>{e.checked?t.classList.add("treeselect-list__item--checked"):t.classList.remove("treeselect-list__item--checked"),Array.isArray(s)&&s[0]===e.id&&!e.disabled?t.classList.add("treeselect-list__item--single-selected"):t.classList.remove("treeselect-list__item--single-selected")},xi=(e,t)=>{e.isPartialChecked?t.classList.add("treeselect-list__item--partial-checked"):t.classList.remove("treeselect-list__item--partial-checked")},_i=(e,t)=>{e.disabled?t.classList.add("treeselect-list__item--disabled"):t.classList.remove("treeselect-list__item--disabled")},Wi=(e,t,s)=>{if(e.isGroup){let i=t.querySelector(".treeselect-list__item-icon"),l=e.isClosed?s.arrowRight:s.arrowDown;T(l,i),e.isClosed?t.classList.add("treeselect-list__item--closed"):t.classList.remove("treeselect-list__item--closed")}},Ti=(e,t)=>{e.hidden?t.classList.add("treeselect-list__item--hidden"):t.classList.remove("treeselect-list__item--hidden")},Oi=(e,t,s)=>{let i=t.parentNode.querySelector(".treeselect-list__item-checkbox-icon");e.checked?T(s.check,i):e.isPartialChecked?T(s.partialCheck,i):i.innerHTML=""},Ni=(e,t,s)=>{let i=e.level===0,l=20,o=5;if(i){let r=s.some(k=>k.isGroup&&k.level===e.level),p=!e.isGroup&&r?`${l}px`:`${o}px`;t.style.paddingLeft=e.isGroup?"0":p}else t.style.paddingLeft=e.isGroup?`${e.level*l}px`:`${e.level*l+l}px`;t.setAttribute("level",e.level.toString()),t.setAttribute("group",e.isGroup.toString())},Ai=(e,t)=>{let s=e.some(l=>!l.hidden),i=t.querySelector(".treeselect-list__empty");s?i.classList.add("treeselect-list__empty--hidden"):i.classList.remove("treeselect-list__empty--hidden")},_=e=>e.parentNode.parentNode,Qt=(e,t)=>t.find(s=>s.id.toString()===e),Bi=e=>_(e).querySelector(".treeselect-list__item-icon"),Hi=(e,t)=>{t&&Object.keys(t).forEach(s=>{let i=t[s];typeof i=="string"&&e.setAttribute(s,i)})},I,P,W,Z,Ue,Fs,ze,Ys,Fe,Js,Ye,Zt,Je,es,Ke,ts,ee,ve,Xe,ss,Qe,is,Ze,ls,te,fe,et,ns,tt,as,st,hs,it,cs,lt,os,nt,rs,at,ds,ht,us,ct,ps,ot,ms,rt,ks,se,be,re,dt,ut,ws,pt=class{constructor({options:t,value:s,openLevel:i,listSlotHtmlComponent:l,emptyText:o,isSingleSelect:r,iconElements:p,showCount:k,disabledBranchNode:f,expandSelected:w,isIndependentNodes:v,inputCallback:b,arrowClickCallback:g,mouseupCallback:L}){h(this,Ue),h(this,ze),h(this,Fe),h(this,Ye),h(this,Je),h(this,Ke),h(this,ee),h(this,Xe),h(this,Qe),h(this,Ze),h(this,te),h(this,et),h(this,tt),h(this,st),h(this,it),h(this,lt),h(this,nt),h(this,at),h(this,ht),h(this,ct),h(this,ot),h(this,rt),h(this,se),h(this,re),h(this,ut),c(this,"options"),c(this,"value"),c(this,"openLevel"),c(this,"listSlotHtmlComponent"),c(this,"emptyText"),c(this,"isSingleSelect"),c(this,"showCount"),c(this,"disabledBranchNode"),c(this,"expandSelected"),c(this,"isIndependentNodes"),c(this,"iconElements"),c(this,"searchText"),c(this,"flattedOptions"),c(this,"flattedOptionsBeforeSearch"),c(this,"selectedNodes"),c(this,"srcElement"),c(this,"inputCallback"),c(this,"arrowClickCallback"),c(this,"mouseupCallback"),h(this,I,null),h(this,P,!0),h(this,W,[]),h(this,Z,!0),this.options=t,this.value=s,this.openLevel=i??0,this.listSlotHtmlComponent=l??null,this.emptyText=o??"No results found...",this.isSingleSelect=r??!1,this.showCount=k??!1,this.disabledBranchNode=f??!1,this.expandSelected=w??!1,this.isIndependentNodes=v??!1,this.iconElements=p,this.searchText="",this.flattedOptions=vi(this.options,this.openLevel,this.isIndependentNodes),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[],allNodes:[]},this.srcElement=a(this,Fe,Js).call(this),this.inputCallback=b,this.arrowClickCallback=g,this.mouseupCallback=L,Si(this.flattedOptions)}updateValue(t){this.value=t,m(this,W,this.isSingleSelect?this.value:[]),Li(t,this.flattedOptions,this.srcElement,this.iconElements,this.isSingleSelect,n(this,W),this.expandSelected,n(this,Z),this.isIndependentNodes),m(this,Z,!1),a(this,re,dt).call(this)}updateSearchValue(t){if(t===this.searchText)return;let s=this.searchText===""&&t!=="";this.searchText=t,s&&(this.flattedOptionsBeforeSearch=JSON.parse(JSON.stringify(this.flattedOptions))),this.searchText===""&&(this.flattedOptions=this.flattedOptionsBeforeSearch.map(i=>{let l=this.flattedOptions.find(o=>o.id===i.id);return l.isClosed=i.isClosed,l.hidden=i.hidden,l}),this.flattedOptionsBeforeSearch=[]),this.searchText&&Ci(this.flattedOptions,t),oe(this.flattedOptions,this.srcElement,this.iconElements,n(this,W)),this.focusFirstListElement()}callKeyAction(t){m(this,P,!1);let s=this.srcElement.querySelector(".treeselect-list__item--focused");if(s?.classList.contains("treeselect-list__item--hidden"))return;let i=t.key;i==="Enter"&&s&&s.dispatchEvent(new Event("mousedown")),(i==="ArrowLeft"||i==="ArrowRight")&&a(this,Ue,Fs).call(this,s,t),(i==="ArrowDown"||i==="ArrowUp")&&a(this,ze,Ys).call(this,s,i)}focusFirstListElement(){let t="treeselect-list__item--focused",s=this.srcElement.querySelector(`.${t}`),i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter(l=>window.getComputedStyle(_(l)).display!=="none");i.length&&(s&&s.classList.remove(t),_(i[0]).classList.add(t))}isLastFocusedElementExist(){return!!n(this,I)}};I=new WeakMap,P=new WeakMap,W=new WeakMap,Z=new WeakMap,Ue=new WeakSet,Fs=function(e,t){if(!e)return;let s=t.key,i=e.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),l=Qt(i,this.flattedOptions),o=e.querySelector(".treeselect-list__item-icon");s==="ArrowLeft"&&!l.isClosed&&l.isGroup&&(o.dispatchEvent(new Event("mousedown")),t.preventDefault()),s==="ArrowRight"&&l.isClosed&&l.isGroup&&(o.dispatchEvent(new Event("mousedown")),t.preventDefault())},ze=new WeakSet,Ys=function(e,t){var s;let i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter(l=>window.getComputedStyle(_(l)).display!=="none");if(i.length)if(!e)_(i[0]).classList.add("treeselect-list__item--focused");else{let l=i.findIndex(g=>_(g).classList.contains("treeselect-list__item--focused"));_(i[l]).classList.remove("treeselect-list__item--focused");let o=t==="ArrowDown"?l+1:l-1,r=t==="ArrowDown"?0:i.length-1,p=i[o]??i[r],k=!i[o],f=_(p);f.classList.add("treeselect-list__item--focused");let w=this.srcElement.getBoundingClientRect(),v=f.getBoundingClientRect();if(k&&t==="ArrowDown"){this.srcElement.scroll(0,0);return}if(k&&t==="ArrowUp"){this.srcElement.scroll(0,this.srcElement.scrollHeight);return}let b=((s=this.listSlotHtmlComponent)==null?void 0:s.clientHeight)??0;if(w.y+w.heightv.y){this.srcElement.scroll(0,this.srcElement.scrollTop-v.height);return}}},Fe=new WeakSet,Js=function(){let e=a(this,Ye,Zt).call(this),t=a(this,ee,ve).call(this,this.options);e.append(...t);let s=a(this,Qe,is).call(this);e.append(s);let i=a(this,Xe,ss).call(this);return i&&e.append(i),e},Ye=new WeakSet,Zt=function(){let e=document.createElement("div");return e.classList.add("treeselect-list"),this.isSingleSelect&&e.classList.add("treeselect-list--single-select"),this.disabledBranchNode&&e.classList.add("treeselect-list--disabled-branch-node"),e.addEventListener("mouseout",t=>a(this,Je,es).call(this,t)),e.addEventListener("mousemove",()=>a(this,Ke,ts).call(this)),e.addEventListener("mouseup",()=>this.mouseupCallback(),!0),e},Je=new WeakSet,es=function(e){e.stopPropagation(),n(this,I)&&n(this,P)&&n(this,I).classList.add("treeselect-list__item--focused")},Ke=new WeakSet,ts=function(){m(this,P,!0)},ee=new WeakSet,ve=function(e){return e.reduce((t,s)=>{var i;if((i=s.children)!=null&&i.length){let o=a(this,Ze,ls).call(this,s),r=a(this,ee,ve).call(this,s.children);return o.append(...r),t.push(o),t}let l=a(this,te,fe).call(this,s,!1);return t.push(l),t},[])},Xe=new WeakSet,ss=function(){if(!this.listSlotHtmlComponent)return null;let e=document.createElement("div");return e.classList.add("treeselect-list__slot"),e.appendChild(this.listSlotHtmlComponent),e},Qe=new WeakSet,is=function(){let e=document.createElement("div");e.classList.add("treeselect-list__empty"),e.setAttribute("title",this.emptyText);let t=document.createElement("span");t.classList.add("treeselect-list__empty-icon"),T(this.iconElements.attention,t);let s=document.createElement("span");return s.classList.add("treeselect-list__empty-text"),s.textContent=this.emptyText,e.append(t,s),e},Ze=new WeakSet,ls=function(e){let t=document.createElement("div");t.setAttribute("group-container-id",e.value.toString()),t.classList.add("treeselect-list__group-container");let s=a(this,te,fe).call(this,e,!0);return t.appendChild(s),t},te=new WeakSet,fe=function(e,t){let s=a(this,et,ns).call(this,e);if(t){let o=a(this,lt,os).call(this);s.appendChild(o),s.classList.add("treeselect-list__item--group")}let i=a(this,at,ds).call(this,e),l=a(this,ht,us).call(this,e,t);return s.append(i,l),s},et=new WeakSet,ns=function(e){let t=document.createElement("div");return Hi(t,e.htmlAttr),t.setAttribute("tabindex","-1"),t.setAttribute("title",e.name),t.classList.add("treeselect-list__item"),t.addEventListener("mouseover",()=>a(this,tt,as).call(this,t),!0),t.addEventListener("mouseout",()=>a(this,st,hs).call(this,t),!0),t.addEventListener("mousedown",s=>a(this,it,cs).call(this,s,e)),t},tt=new WeakSet,as=function(e){n(this,P)&&a(this,se,be).call(this,!0,e)},st=new WeakSet,hs=function(e){n(this,P)&&(a(this,se,be).call(this,!1,e),m(this,I,e))},it=new WeakSet,cs=function(e,t){var s;if(e.preventDefault(),e.stopPropagation(),(s=this.flattedOptions.find(l=>l.id===t.value))==null?void 0:s.disabled)return;let i=e.target.querySelector(".treeselect-list__item-checkbox");i.checked=!i.checked,a(this,ot,ms).call(this,i,t)},lt=new WeakSet,os=function(){let e=document.createElement("span");return e.setAttribute("tabindex","-1"),e.classList.add("treeselect-list__item-icon"),T(this.iconElements.arrowDown,e),e.addEventListener("mousedown",t=>a(this,nt,rs).call(this,t)),e},nt=new WeakSet,rs=function(e){e.preventDefault(),e.stopPropagation(),a(this,rt,ks).call(this,e)},at=new WeakSet,ds=function(e){let t=document.createElement("div");t.classList.add("treeselect-list__item-checkbox-container");let s=document.createElement("span");s.classList.add("treeselect-list__item-checkbox-icon"),s.innerHTML="";let i=document.createElement("input");return i.setAttribute("tabindex","-1"),i.setAttribute("type","checkbox"),i.setAttribute("input-id",e.value.toString()),i.classList.add("treeselect-list__item-checkbox"),t.append(s,i),t},ht=new WeakSet,us=function(e,t){let s=document.createElement("label");if(s.textContent=e.name,s.classList.add("treeselect-list__item-label"),t&&this.showCount){let i=a(this,ct,ps).call(this,e);s.appendChild(i)}return s},ct=new WeakSet,ps=function(e){let t=document.createElement("span"),s=this.flattedOptions.filter(i=>i.childOf===e.value);return t.textContent=`(${s.length})`,t.classList.add("treeselect-list__item-label-counter"),t},ot=new WeakSet,ms=function(e,t){let s=this.flattedOptions.find(i=>i.id===t.value);if(s){if(s!=null&&s.isGroup&&this.disabledBranchNode){let i=Bi(e);i?.dispatchEvent(new Event("mousedown"));return}if(this.isSingleSelect){let[i]=n(this,W);if(s.id===i)return;m(this,W,[s.id]),Is([s.id],this.flattedOptions,this.isSingleSelect,this.isIndependentNodes)}else{s.checked=e.checked;let i=Pt(s,this.flattedOptions,this.isIndependentNodes);e.checked=i}oe(this.flattedOptions,this.srcElement,this.iconElements,n(this,W)),a(this,ut,ws).call(this)}},rt=new WeakSet,ks=function(e){var t,s;let i=(s=(t=e.target)==null?void 0:t.parentNode)==null?void 0:s.querySelector("[input-id]"),l=i?.getAttribute("input-id")??null,o=Qt(l,this.flattedOptions);o&&(o.isClosed=!o.isClosed,we(this.flattedOptions,o),oe(this.flattedOptions,this.srcElement,this.iconElements,n(this,W)),this.arrowClickCallback(o.id,o.isClosed))},se=new WeakSet,be=function(e,t){let s="treeselect-list__item--focused";if(e){let i=Array.from(this.srcElement.querySelectorAll(`.${s}`));i.length&&i.forEach(l=>l.classList.remove(s)),t.classList.add(s)}else t.classList.remove(s)},re=new WeakSet,dt=function(){let{ungroupedNodes:e,groupedNodes:t,allNodes:s}=fi(this.flattedOptions);this.selectedNodes={nodes:e,groupedNodes:t,allNodes:s}},ut=new WeakSet,ws=function(){a(this,re,dt).call(this),this.inputCallback(this.selectedNodes),this.value=this.selectedNodes.nodes.map(e=>e.id)};var vs=({parentHtmlContainer:e,staticList:t,appendToBody:s,isSingleSelect:i,value:l,direction:o})=>{e||console.error("Validation: parentHtmlContainer prop is required!"),t&&s&&console.error("Validation: You should set staticList to false if you use appendToBody!"),i&&Array.isArray(l)&&console.error("Validation: if you use isSingleSelect prop, you should pass a single value!"),!i&&!Array.isArray(l)&&console.error("Validation: you should pass an array as a value!"),o&&o!=="auto"&&o!=="bottom"&&o!=="top"&&console.error("Validation: you should pass (auto | top | bottom | undefined) as a value for the direction prop!")},X=e=>e.map(t=>t.id),Pi=e=>e?Array.isArray(e)?e:[e]:[],Vi=(e,t)=>{if(t){let[s]=e;return s??null}return e},d,u,R,ie,U,y,x,C,B,le,mt,ne,ge,kt,fs,wt,bs,vt,gs,ft,Cs,bt,Es,gt,Ss,de,Ct,Et,Ls,St,ys,Lt,xs,yt,_s,ue,xt,_t,Ks,J,pe,ae,Ce,z,he,Wt,Ws,ce,Ee,Tt,Ts,Ot,Os,Nt,Ns,At,As,Bt,Bs,me=class{constructor({parentHtmlContainer:t,value:s,options:i,openLevel:l,appendToBody:o,alwaysOpen:r,showTags:p,tagsCountText:k,clearable:f,searchable:w,placeholder:v,grouped:b,isGroupedValue:g,listSlotHtmlComponent:L,disabled:O,emptyText:$,staticList:V,id:q,ariaLabel:j,isSingleSelect:K,showCount:Xs,disabledBranchNode:Qs,direction:Zs,expandSelected:ei,saveScrollPosition:ti,isIndependentNodes:si,iconElements:ii,inputCallback:li,openCallback:ni,closeCallback:ai,nameChangeCallback:hi,searchCallback:ci,openCloseGroupCallback:oi}){h(this,le),h(this,ne),h(this,kt),h(this,wt),h(this,vt),h(this,ft),h(this,bt),h(this,gt),h(this,de),h(this,Et),h(this,St),h(this,Lt),h(this,yt),h(this,ue),h(this,_t),h(this,J),h(this,ae),h(this,z),h(this,Wt),h(this,ce),h(this,Tt),h(this,Ot),h(this,Nt),h(this,At),h(this,Bt),c(this,"parentHtmlContainer"),c(this,"value"),c(this,"options"),c(this,"openLevel"),c(this,"appendToBody"),c(this,"alwaysOpen"),c(this,"showTags"),c(this,"tagsCountText"),c(this,"clearable"),c(this,"searchable"),c(this,"placeholder"),c(this,"grouped"),c(this,"isGroupedValue"),c(this,"listSlotHtmlComponent"),c(this,"disabled"),c(this,"emptyText"),c(this,"staticList"),c(this,"id"),c(this,"ariaLabel"),c(this,"isSingleSelect"),c(this,"showCount"),c(this,"disabledBranchNode"),c(this,"direction"),c(this,"expandSelected"),c(this,"saveScrollPosition"),c(this,"isIndependentNodes"),c(this,"iconElements"),c(this,"inputCallback"),c(this,"openCallback"),c(this,"closeCallback"),c(this,"nameChangeCallback"),c(this,"searchCallback"),c(this,"openCloseGroupCallback"),c(this,"ungroupedValue"),c(this,"groupedValue"),c(this,"allValue"),c(this,"isListOpened"),c(this,"selectedName"),c(this,"srcElement"),h(this,d,null),h(this,u,null),h(this,R,null),h(this,ie,0),h(this,U,0),h(this,y,null),h(this,x,null),h(this,C,null),h(this,B,null),vs({parentHtmlContainer:t,value:s,staticList:V,appendToBody:o,isSingleSelect:K}),this.parentHtmlContainer=t,this.value=[],this.options=i??[],this.openLevel=l??0,this.appendToBody=o??!1,this.alwaysOpen=!!(r&&!O),this.showTags=p??!0,this.tagsCountText=k??"elements selected",this.clearable=f??!0,this.searchable=w??!0,this.placeholder=v??"Search...",this.grouped=b??!0,this.isGroupedValue=g??!1,this.listSlotHtmlComponent=L??null,this.disabled=O??!1,this.emptyText=$??"No results found...",this.staticList=!!(V&&!this.appendToBody),this.id=q??"",this.ariaLabel=j??"",this.isSingleSelect=K??!1,this.showCount=Xs??!1,this.disabledBranchNode=Qs??!1,this.direction=Zs??"auto",this.expandSelected=ei??!1,this.saveScrollPosition=ti??!0,this.isIndependentNodes=si??!1,this.iconElements=Gt(ii),this.inputCallback=li,this.openCallback=ni,this.closeCallback=ai,this.nameChangeCallback=hi,this.searchCallback=ci,this.openCloseGroupCallback=oi,this.ungroupedValue=[],this.groupedValue=[],this.allValue=[],this.isListOpened=!1,this.selectedName="",this.srcElement=null,a(this,le,mt).call(this,s)}mount(){vs({parentHtmlContainer:this.parentHtmlContainer,value:this.value,staticList:this.staticList,appendToBody:this.appendToBody,isSingleSelect:this.isSingleSelect}),this.iconElements=Gt(this.iconElements),a(this,le,mt).call(this,this.value)}updateValue(t){let s=Pi(t),i=n(this,d);i&&(i.updateValue(s),a(this,de,Ct).call(this,i?.selectedNodes))}destroy(){this.srcElement&&(a(this,ue,xt).call(this),this.srcElement.innerHTML="",this.srcElement=null,a(this,z,he).call(this,!0))}focus(){n(this,u)&&n(this,u).focus()}toggleOpenClose(){n(this,u)&&(n(this,u).openClose(),n(this,u).focus())}scrollWindowHandler(){this.updateListPosition()}focusWindowHandler(t){var s,i,l;(s=this.srcElement)!=null&&s.contains(t.target)||(i=n(this,d))!=null&&i.srcElement.contains(t.target)||((l=n(this,u))==null||l.blur(),a(this,z,he).call(this,!1),a(this,J,pe).call(this,!1))}blurWindowHandler(){var t;(t=n(this,u))==null||t.blur(),a(this,z,he).call(this,!1),a(this,J,pe).call(this,!1)}updateListPosition(){var t;let s=this.srcElement,i=(t=n(this,d))==null?void 0:t.srcElement;if(!s||!i)return;let{height:l}=i.getBoundingClientRect(),{x:o,y:r,height:p,width:k}=s.getBoundingClientRect(),f=window.innerHeight,w=r,v=f-r-p,b=w>v&&w>=l&&va(this,Et,Ls).call(this,i),arrowClickCallback:(i,l)=>a(this,St,ys).call(this,i,l),mouseupCallback:()=>{var i;return(i=n(this,u))==null?void 0:i.focus()}}),s=new je({value:[],showTags:this.showTags,tagsCountText:this.tagsCountText,clearable:this.clearable,isAlwaysOpened:this.alwaysOpen,searchable:this.searchable,placeholder:this.placeholder,disabled:this.disabled,isSingleSelect:this.isSingleSelect,id:this.id,ariaLabel:this.ariaLabel,iconElements:this.iconElements,inputCallback:i=>a(this,wt,bs).call(this,i),searchCallback:i=>a(this,ft,Cs).call(this,i),openCallback:()=>a(this,yt,_s).call(this),closeCallback:()=>a(this,ue,xt).call(this),keydownCallback:i=>a(this,vt,gs).call(this,i),focusCallback:()=>a(this,bt,Es).call(this),blurCallback:()=>a(this,gt,Ss).call(this),nameChangeCallback:i=>a(this,Lt,xs).call(this,i)});return this.appendToBody&&m(this,R,new ResizeObserver(()=>this.updateListPosition())),e.append(s.srcElement),{container:e,list:t,input:s}},wt=new WeakSet,bs=function(e){var t,s;let i=X(e);(t=n(this,d))==null||t.updateValue(i);let l=((s=n(this,d))==null?void 0:s.selectedNodes)??{};a(this,ne,ge).call(this,l),a(this,ce,Ee).call(this)},vt=new WeakSet,gs=function(e){var t;this.isListOpened&&((t=n(this,d))==null||t.callKeyAction(e))},ft=new WeakSet,Cs=function(e){n(this,U)&&clearTimeout(n(this,U)),m(this,U,window.setTimeout(()=>{var t;(t=n(this,d))==null||t.updateSearchValue(e),this.updateListPosition()},350)),a(this,At,As).call(this,e)},bt=new WeakSet,Es=function(){a(this,J,pe).call(this,!0),n(this,C)&&n(this,C)&&n(this,B)&&(document.addEventListener("mousedown",n(this,C),!0),document.addEventListener("focus",n(this,C),!0),window.addEventListener("blur",n(this,B)))},gt=new WeakSet,Ss=function(){setTimeout(()=>{var e,t;let s=(e=n(this,u))==null?void 0:e.srcElement.contains(document.activeElement),i=(t=n(this,d))==null?void 0:t.srcElement.contains(document.activeElement);!s&&!i&&this.blurWindowHandler()},1)},de=new WeakSet,Ct=function(e){var t;if(!e)return;let s=[];this.isIndependentNodes||this.isSingleSelect?s=e.allNodes:this.grouped?s=e.groupedNodes:s=e.nodes,(t=n(this,u))==null||t.updateValue(s),a(this,ne,ge).call(this,e)},Et=new WeakSet,Ls=function(e){var t,s,i;a(this,de,Ct).call(this,e),this.isSingleSelect&&!this.alwaysOpen&&((t=n(this,u))==null||t.openClose(),(s=n(this,u))==null||s.clearSearch()),(i=n(this,u))==null||i.focus(),a(this,ce,Ee).call(this)},St=new WeakSet,ys=function(e,t){var s;(s=n(this,u))==null||s.focus(),this.updateListPosition(),a(this,Bt,Bs).call(this,e,t)},Lt=new WeakSet,xs=function(e){this.selectedName!==e&&(this.selectedName=e,a(this,Tt,Ts).call(this))},yt=new WeakSet,_s=function(){var e;this.isListOpened=!0,n(this,y)&&n(this,x)&&(window.addEventListener("scroll",n(this,y),!0),window.addEventListener("resize",n(this,x))),!(!n(this,d)||!this.srcElement)&&(this.appendToBody?(document.body.appendChild(n(this,d).srcElement),(e=n(this,R))==null||e.observe(this.srcElement)):this.srcElement.appendChild(n(this,d).srcElement),this.updateListPosition(),a(this,ae,Ce).call(this,!0),a(this,Wt,Ws).call(this),a(this,Ot,Os).call(this))},ue=new WeakSet,xt=function(){var e;this.alwaysOpen||(this.isListOpened=!1,n(this,y)&&n(this,x)&&(window.removeEventListener("scroll",n(this,y),!0),window.removeEventListener("resize",n(this,x))),!n(this,d)||!this.srcElement)||!(this.appendToBody?document.body.contains(n(this,d).srcElement):this.srcElement.contains(n(this,d).srcElement))||(m(this,ie,n(this,d).srcElement.scrollTop),this.appendToBody?(document.body.removeChild(n(this,d).srcElement),(e=n(this,R))==null||e.disconnect()):this.srcElement.removeChild(n(this,d).srcElement),a(this,ae,Ce).call(this,!1),a(this,Nt,Ns).call(this))},_t=new WeakSet,Ks=function(e,t){if(!n(this,d)||!n(this,u))return;let s=t?"treeselect-list--top-to-body":"treeselect-list--top",i=t?"treeselect-list--bottom-to-body":"treeselect-list--bottom";e?(n(this,d).srcElement.classList.add(s),n(this,d).srcElement.classList.remove(i),n(this,u).srcElement.classList.add("treeselect-input--top"),n(this,u).srcElement.classList.remove("treeselect-input--bottom")):(n(this,d).srcElement.classList.remove(s),n(this,d).srcElement.classList.add(i),n(this,u).srcElement.classList.remove("treeselect-input--top"),n(this,u).srcElement.classList.add("treeselect-input--bottom"))},J=new WeakSet,pe=function(e){!n(this,u)||!n(this,d)||(e?(n(this,u).srcElement.classList.add("treeselect-input--focused"),n(this,d).srcElement.classList.add("treeselect-list--focused")):(n(this,u).srcElement.classList.remove("treeselect-input--focused"),n(this,d).srcElement.classList.remove("treeselect-list--focused")))},ae=new WeakSet,Ce=function(e){var t,s,i,l;e?(t=n(this,u))==null||t.srcElement.classList.add("treeselect-input--opened"):(s=n(this,u))==null||s.srcElement.classList.remove("treeselect-input--opened"),this.staticList?(i=n(this,d))==null||i.srcElement.classList.add("treeselect-list--static"):(l=n(this,d))==null||l.srcElement.classList.remove("treeselect-list--static")},z=new WeakSet,he=function(e){!n(this,y)||!n(this,x)||!n(this,C)||!n(this,B)||((!this.alwaysOpen||e)&&(window.removeEventListener("scroll",n(this,y),!0),window.removeEventListener("resize",n(this,x))),document.removeEventListener("mousedown",n(this,C),!0),document.removeEventListener("focus",n(this,C),!0),window.removeEventListener("blur",n(this,B)))},Wt=new WeakSet,Ws=function(){var e,t,s;let i=(e=n(this,d))==null?void 0:e.isLastFocusedElementExist();this.saveScrollPosition&&i?(t=n(this,d))==null||t.srcElement.scroll(0,n(this,ie)):(s=n(this,d))==null||s.focusFirstListElement()},ce=new WeakSet,Ee=function(){var e;(e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("input",{detail:this.value})),this.inputCallback&&this.inputCallback(this.value)},Tt=new WeakSet,Ts=function(){var e;(e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("name-change",{detail:this.selectedName})),this.nameChangeCallback&&this.nameChangeCallback(this.selectedName)},Ot=new WeakSet,Os=function(){var e;this.alwaysOpen||((e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("open",{detail:this.value})),this.openCallback&&this.openCallback(this.value))},Nt=new WeakSet,Ns=function(){var e;this.alwaysOpen||((e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("close",{detail:this.value})),this.closeCallback&&this.closeCallback(this.value))},At=new WeakSet,As=function(e){var t;let s=e?.trim()??"";(t=this.srcElement)==null||t.dispatchEvent(new CustomEvent("search",{detail:s})),this.searchCallback&&this.searchCallback(s)},Bt=new WeakSet,Bs=function(e,t){var s;(s=this.srcElement)==null||s.dispatchEvent(new CustomEvent("open-close-group",{detail:{groupId:e,isClosed:t}})),this.openCloseGroupCallback&&this.openCloseGroupCallback(e,t)};function Gi({state:e,name:t,options:s,searchable:i,showCount:l,placeholder:o,rtl:r,disabledBranchNode:p=!0,disabled:k=!1,isSingleSelect:f=!0,showTags:w=!0,clearable:v=!0,isIndependentNodes:b=!0,alwaysOpen:g=!1,emptyText:L,expandSelected:O=!0,grouped:$=!0,openLevel:V=0,direction:q="auto"}){return{state:e,tree:null,init(){this.tree=new me({id:`tree-${t}-id`,ariaLabel:`tree-${t}-label`,parentHtmlContainer:this.$refs.tree,value:this.state,options:s,searchable:i,showCount:l,placeholder:o,disabledBranchNode:p,disabled:k,isSingleSelect:f,showTags:w,clearable:v,isIndependentNodes:b,alwaysOpen:g,emptyText:L,expandSelected:O,grouped:$,openLevel:V,direction:q,rtl:r}),this.tree.srcElement.addEventListener("input",j=>{this.state=j.detail})}}}export{Gi as default}; +var di=Object.defineProperty,ui=(t,e,s)=>e in t?di(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,c=(t,e,s)=>(ui(t,typeof e!="symbol"?e+"":e,s),s),He=(t,e,s)=>{if(!e.has(t))throw TypeError("Cannot "+s)},l=(t,e,s)=>(He(t,e,"read from private field"),s?s.call(t):e.get(t)),h=(t,e,s)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,s)},m=(t,e,s,i)=>(He(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),a=(t,e,s)=>(He(t,e,"access private method"),s),Ve={arrowUp:'',arrowDown:'',arrowRight:'',attention:'',clear:'',cross:'',check:'',partialCheck:''},O=(t,e)=>{if(e.innerHTML="",typeof t=="string")e.innerHTML=t;else{let s=t.cloneNode(!0);e.appendChild(s)}},Ge=t=>{let e=t?{...t}:{};return Object.keys(Ve).forEach(s=>{e[s]||(e[s]=Ve[s])}),e},pi=t=>t.reduce((e,{name:s},i)=>(e+=s,il(this,L).focus(),0)}blur(){this.isOpened&&a(this,A,H).call(this),this.clearSearch(),l(this,L).blur()}updateValue(e){this.value=e,a(this,G,F).call(this),a(this,M,Y).call(this)}removeItem(e){this.value=this.value.filter(s=>s.id!==e),a(this,Q,qt).call(this),a(this,G,F).call(this),a(this,M,Y).call(this)}clear(){this.value=[],a(this,Q,qt).call(this),a(this,G,F).call(this),this.clearSearch()}openClose(){a(this,A,H).call(this)}clearSearch(){this.searchText="",this.searchCallback(""),a(this,M,Y).call(this)}};N=new WeakMap,L=new WeakMap,D=new WeakMap,S=new WeakMap,St=new WeakSet,Hs=function(){a(this,G,F).call(this),a(this,M,Y).call(this),a(this,Lt,Me).call(this)},G=new WeakSet,F=function(){if(l(this,N).innerHTML="",this.showTags){l(this,N).append(...a(this,Tt,$e).call(this));let t=pi(this.value);this.nameChangeCallback(t)}else{let t=a(this,Bt,Ue).call(this);l(this,N).appendChild(t),this.nameChangeCallback(t.innerText)}l(this,N).appendChild(l(this,L))},Lt=new WeakSet,Me=function(){let t=[];l(this,D).innerHTML="",this.clearable&&t.push(a(this,Mt,Ye).call(this)),this.isAlwaysOpened||t.push(a(this,Dt,Ke).call(this,this.isOpened)),t.length&&l(this,D).append(...t)},yt=new WeakSet,Ie=function(){if(!this.isAlwaysOpened&&l(this,S)){let t=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;O(t,l(this,S))}},M=new WeakSet,Y=function(){var t;(t=this.value)!=null&&t.length?(l(this,L).removeAttribute("placeholder"),this.srcElement.classList.remove("treeselect-input--value-not-selected")):(l(this,L).setAttribute("placeholder",this.placeholder),this.srcElement.classList.add("treeselect-input--value-not-selected")),this.searchable?this.srcElement.classList.remove("treeselect-input--unsearchable"):this.srcElement.classList.add("treeselect-input--unsearchable"),this.isSingleSelect?this.srcElement.classList.add("treeselect-input--is-single-select"):this.srcElement.classList.remove("treeselect-input--is-single-select"),l(this,L).value=this.searchText},A=new WeakSet,H=function(){this.isOpened=!this.isOpened,a(this,yt,Ie).call(this),this.isOpened?this.openCallback():this.closeCallback()},xt=new WeakSet,Ps=function(t,e,s){let i=document.createElement("div");return i.classList.add("treeselect-input"),i.setAttribute("tabindex","-1"),i.addEventListener("mousedown",n=>a(this,_t,De).call(this,n)),i.addEventListener("focus",()=>this.focusCallback(),!0),i.addEventListener("blur",()=>this.blurCallback(),!0),t.appendChild(e),i.append(t,s),i},_t=new WeakSet,De=function(t){t.stopPropagation(),this.isOpened||a(this,A,H).call(this),this.focus()},Wt=new WeakSet,Vs=function(){let t=document.createElement("div");return t.classList.add("treeselect-input__tags"),t},Tt=new WeakSet,$e=function(){return this.value.map(t=>{let e=document.createElement("div");e.classList.add("treeselect-input__tags-element"),e.setAttribute("tabindex","-1"),e.setAttribute("tag-id",t.id.toString()),e.setAttribute("title",t.name);let s=a(this,Nt,je).call(this,t.name),i=a(this,At,Re).call(this);return e.addEventListener("mousedown",n=>a(this,Ot,qe).call(this,n,t.id)),e.append(s,i),e})},Ot=new WeakSet,qe=function(t,e){t.preventDefault(),t.stopPropagation(),this.removeItem(e),this.focus()},Nt=new WeakSet,je=function(t){let e=document.createElement("span");return e.classList.add("treeselect-input__tags-name"),e.textContent=t,e},At=new WeakSet,Re=function(){let t=document.createElement("span");return t.classList.add("treeselect-input__tags-cross"),O(this.iconElements.cross,t),t},Bt=new WeakSet,Ue=function(){let t=document.createElement("span");if(t.classList.add("treeselect-input__tags-count"),!this.value.length)return t.textContent="",t.setAttribute("title",""),t;let e=this.value.length===1?this.value[0].name:`${this.value.length} ${this.tagsCountText}`;return t.textContent=e,t.setAttribute("title",e),t},Ht=new WeakSet,Gs=function(){let t=document.createElement("input");return t.classList.add("treeselect-input__edit"),this.id&&t.setAttribute("id",this.id),(!this.searchable||this.disabled)&&t.setAttribute("readonly","readonly"),this.disabled&&t.setAttribute("tabindex","-1"),this.ariaLabel.length&&t.setAttribute("aria-label",this.ariaLabel),t.addEventListener("keydown",e=>a(this,Pt,ze).call(this,e)),t.addEventListener("input",e=>a(this,Vt,Fe).call(this,e,t)),t},Pt=new WeakSet,ze=function(t){t.stopPropagation();let e=t.key;e==="Backspace"&&!this.searchText.length&&this.value.length&&!this.showTags&&this.clear(),e==="Backspace"&&!this.searchText.length&&this.value.length&&this.removeItem(this.value[this.value.length-1].id),t.code==="Space"&&(!this.searchText||!this.searchable)&&a(this,A,H).call(this),(e==="Enter"||e==="ArrowDown"||e==="ArrowUp")&&t.preventDefault(),this.keydownCallback(t),e!=="Tab"&&this.focus()},Vt=new WeakSet,Fe=function(t,e){t.stopPropagation();let s=this.searchText,i=e.value.trim();if(s.length===0&&i.length===0){e.value="";return}if(this.searchable){let n=t.target.value;this.searchCallback(n),this.isOpened||a(this,A,H).call(this)}else e.value="";this.searchText=e.value},Gt=new WeakSet,Ms=function(){let t=document.createElement("div");return t.classList.add("treeselect-input__operators"),t},Mt=new WeakSet,Ye=function(){let t=document.createElement("span");return t.classList.add("treeselect-input__clear"),t.setAttribute("tabindex","-1"),O(this.iconElements.clear,t),t.addEventListener("mousedown",e=>a(this,It,Je).call(this,e)),t},It=new WeakSet,Je=function(t){t.preventDefault(),t.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},Dt=new WeakSet,Ke=function(t){m(this,S,document.createElement("span")),l(this,S).classList.add("treeselect-input__arrow");let e=t?this.iconElements.arrowUp:this.iconElements.arrowDown;return O(e,l(this,S)),l(this,S).addEventListener("mousedown",s=>a(this,$t,Xe).call(this,s)),l(this,S)},$t=new WeakSet,Xe=function(t){t.stopPropagation(),t.preventDefault(),this.focus(),a(this,A,H).call(this)},Q=new WeakSet,qt=function(){this.inputCallback(this.value)};var Is=(t,e,s,i)=>{vi(e);let n=e.filter(o=>!o.disabled&&t.some(r=>r===o.id));if(s&&n.length){n[0].checked=!0;return}n.forEach(o=>{o.checked=!0;let r=Pe(o,e,i);o.checked=r})},Pe=({id:t,checked:e},s,i)=>{let n=s.find(r=>r.id===t);if(!n)return!1;if(i)return n.checked=n.disabled?!1:!!e,n.checked;let o=Ds(!!e,n,s);return $s(n,s),o},Ds=(t,e,s)=>{if(!e.isGroup)return e.checked=e.disabled?!1:!!t,e.isPartialChecked=!1,e.checked;let i=s.filter(n=>n.childOf===e.id);return!t||e.disabled||e.isPartialChecked?(e.checked=!1,e.isPartialChecked=!1,Rt(e,i,s),e.checked):qs(i,s)?js(i)?(e.checked=!1,e.isPartialChecked=!1,e.disabled=!0,e.checked):(e.checked=!1,e.isPartialChecked=!0,i.forEach(n=>{Ds(t,n,s)}),e.checked):(e.checked=!0,e.isPartialChecked=!1,Rt(e,i,s),e.checked)},$s=(t,e)=>{let s=e.find(i=>i.id===t.childOf);s&&(mi(s,e),$s(s,e))},mi=(t,e)=>{let s=kt(t,e);if(js(s)){t.checked=!1,t.isPartialChecked=!1,t.disabled=!0;return}if(ki(s)){t.checked=!0,t.isPartialChecked=!1;return}if(wi(s)){t.checked=!1,t.isPartialChecked=!0;return}t.checked=!1,t.isPartialChecked=!1},Rt=({checked:t,disabled:e},s,i)=>{s.forEach(n=>{n.disabled=!!e||!!n.disabled,n.checked=!!t&&!n.disabled,n.isPartialChecked=!1;let o=kt(n,i);Rt({checked:t,disabled:e},o,i)})},qs=(t,e)=>t.some(s=>s.disabled)?!0:t.some(s=>{if(s.isGroup){let i=kt(s,e);return qs(i,e)}return!1}),js=t=>t.every(e=>!!e.disabled),ki=t=>t.every(e=>!!e.checked),wi=t=>t.some(e=>!!e.checked||!!e.isPartialChecked),vi=t=>{t.forEach(e=>{e.checked=!1,e.isPartialChecked=!1})},fi=(t,e,s)=>{let i={level:0,groupId:""},n=Rs(t,e,i.groupId,i.level);return gi(n,s)},Rs=(t,e,s,i)=>t.reduce((n,o)=>{var r;let u=!!((r=o.children)!=null&&r.length),v=i>=e&&u,k=i>e;if(n.push({id:o.value,name:o.name,childOf:s,isGroup:u,checked:!1,isPartialChecked:!1,level:i,isClosed:v,hidden:k,disabled:o.disabled??!1}),u){let w=Rs(o.children,e,o.value,i+1);n.push(...w)}return n},[]),kt=({id:t},e)=>e.filter(s=>s.childOf===t),bi=t=>{let{ungroupedNodes:e,allGroupedNodes:s,allNodes:i}=t.reduce((o,r)=>(r.checked&&(o.allNodes.push(r),r.isGroup?o.allGroupedNodes.push(r):o.ungroupedNodes.push(r)),o),{ungroupedNodes:[],allGroupedNodes:[],allNodes:[]}),n=i.filter(o=>!s.some(({id:r})=>r===o.childOf));return{ungroupedNodes:e,groupedNodes:n,allNodes:i}},gi=(t,e)=>(t.filter(s=>!!s.disabled).forEach(({id:s})=>Pe({id:s,checked:!1},t,e)),t),wt=(t,{id:e,isClosed:s})=>{kt({id:e},t).forEach(i=>{i.hidden=s??!1,i.isGroup&&!i.isClosed&&wt(t,{id:i.id,isClosed:s})})},Ci=t=>{t.filter(e=>e.isGroup&&!e.disabled&&(e.checked||e.isPartialChecked)).forEach(e=>{e.isClosed=!1,wt(t,e)})},Ei=(t,e)=>{let s=Si(t,e);t.forEach(i=>{s.some(({id:n})=>n===i.id)?(i.isGroup&&(i.isClosed=!1,wt(t,i)),i.hidden=!1):i.hidden=!0})},Si=(t,e)=>t.reduce((s,i)=>{if(i.name.toLowerCase().includes(e.toLowerCase())){if(s.push(i),i.isGroup){let n=Us(i.id,t);s.push(...n)}if(i.childOf){let n=zs(i.childOf,t);s.push(...n)}}return s},[]),Us=(t,e)=>e.reduce((s,i)=>(i.childOf===t&&(s.push(i),i.isGroup&&s.push(...Us(i.id,e))),s),[]),zs=(t,e)=>e.reduce((s,i)=>(i.id===t&&(s.push(i),i.childOf&&s.push(...zs(i.childOf,e))),s),[]),Li=t=>{let{duplications:e}=t.reduce((s,i)=>(s.allItems.some(n=>n.toString()===i.id.toString())&&s.duplications.push(i.id),s.allItems.push(i.id),s),{duplications:[],allItems:[]});e.length&&console.error(`Validation: You have duplicated values: ${e.join(", ")}! You should use unique values.`)},yi=(t,e,s,i,n,o,r,u,v,k)=>{Is(t,e,n,v),u&&r&&Ci(e),ot(e,s,i,o,k)},ot=(t,e,s,i,n)=>{t.forEach(o=>{let r=e.querySelector(`[input-id="${o.id}"]`),u=W(r);r.checked=o.checked,xi(o,u,i),_i(o,u),Wi(o,u),Ti(o,u,s),Oi(o,u),Ai(o,u,t,n),Ni(o,r,s)}),Bi(t,e)},xi=(t,e,s)=>{t.checked?e.classList.add("treeselect-list__item--checked"):e.classList.remove("treeselect-list__item--checked"),Array.isArray(s)&&s[0]===t.id&&!t.disabled?e.classList.add("treeselect-list__item--single-selected"):e.classList.remove("treeselect-list__item--single-selected")},_i=(t,e)=>{t.isPartialChecked?e.classList.add("treeselect-list__item--partial-checked"):e.classList.remove("treeselect-list__item--partial-checked")},Wi=(t,e)=>{t.disabled?e.classList.add("treeselect-list__item--disabled"):e.classList.remove("treeselect-list__item--disabled")},Ti=(t,e,s)=>{if(t.isGroup){let i=e.querySelector(".treeselect-list__item-icon"),n=t.isClosed?s.arrowRight:s.arrowDown;O(n,i),t.isClosed?e.classList.add("treeselect-list__item--closed"):e.classList.remove("treeselect-list__item--closed")}},Oi=(t,e)=>{t.hidden?e.classList.add("treeselect-list__item--hidden"):e.classList.remove("treeselect-list__item--hidden")},Ni=(t,e,s)=>{let i=e.parentNode.querySelector(".treeselect-list__item-checkbox-icon");t.checked?O(s.check,i):t.isPartialChecked?O(s.partialCheck,i):i.innerHTML=""},Ai=(t,e,s,i)=>{let n=t.level===0,o=20,r=5;if(n){let u=s.some(w=>w.isGroup&&w.level===t.level),v=!t.isGroup&&u?`${o}px`:`${r}px`,k=t.isGroup?"0":v;i?e.style.paddingRight=k:e.style.paddingLeft=k}else{let u=t.isGroup?`${t.level*o}px`:`${t.level*o+o}px`;i?e.style.paddingRight=u:e.style.paddingLeft=u}e.setAttribute("level",t.level.toString()),e.setAttribute("group",t.isGroup.toString())},Bi=(t,e)=>{let s=t.some(n=>!n.hidden),i=e.querySelector(".treeselect-list__empty");s?i.classList.add("treeselect-list__empty--hidden"):i.classList.remove("treeselect-list__empty--hidden")},W=t=>t.parentNode.parentNode,Qe=(t,e)=>e.find(s=>s.id.toString()===t),Hi=t=>W(t).querySelector(".treeselect-list__item-icon"),Pi=(t,e)=>{e&&Object.keys(e).forEach(s=>{let i=e[s];typeof i=="string"&&t.setAttribute(s,i)})},I,P,T,Z,Ut,Fs,zt,Ys,Ft,Js,Yt,Ze,Jt,ts,Kt,es,tt,vt,Xt,ss,Qt,is,Zt,ls,et,ft,te,ns,ee,as,se,hs,ie,cs,le,os,ne,rs,ae,ds,he,us,ce,ps,oe,ms,re,ks,st,bt,rt,de,ue,ws,pe=class{constructor({options:e,value:s,openLevel:i,listSlotHtmlComponent:n,emptyText:o,isSingleSelect:r,iconElements:u,showCount:v,disabledBranchNode:k,expandSelected:w,isIndependentNodes:f,rtl:b,inputCallback:g,arrowClickCallback:y,mouseupCallback:C}){h(this,Ut),h(this,zt),h(this,Ft),h(this,Yt),h(this,Jt),h(this,Kt),h(this,tt),h(this,Xt),h(this,Qt),h(this,Zt),h(this,et),h(this,te),h(this,ee),h(this,se),h(this,ie),h(this,le),h(this,ne),h(this,ae),h(this,he),h(this,ce),h(this,oe),h(this,re),h(this,st),h(this,rt),h(this,ue),c(this,"options"),c(this,"value"),c(this,"openLevel"),c(this,"listSlotHtmlComponent"),c(this,"emptyText"),c(this,"isSingleSelect"),c(this,"showCount"),c(this,"disabledBranchNode"),c(this,"expandSelected"),c(this,"isIndependentNodes"),c(this,"rtl"),c(this,"iconElements"),c(this,"searchText"),c(this,"flattedOptions"),c(this,"flattedOptionsBeforeSearch"),c(this,"selectedNodes"),c(this,"srcElement"),c(this,"inputCallback"),c(this,"arrowClickCallback"),c(this,"mouseupCallback"),h(this,I,null),h(this,P,!0),h(this,T,[]),h(this,Z,!0),this.options=e,this.value=s,this.openLevel=i??0,this.listSlotHtmlComponent=n??null,this.emptyText=o??"No results found...",this.isSingleSelect=r??!1,this.showCount=v??!1,this.disabledBranchNode=k??!1,this.expandSelected=w??!1,this.isIndependentNodes=f??!1,this.rtl=b??!1,this.iconElements=u,this.searchText="",this.flattedOptions=fi(this.options,this.openLevel,this.isIndependentNodes),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[],allNodes:[]},this.srcElement=a(this,Ft,Js).call(this),this.inputCallback=g,this.arrowClickCallback=y,this.mouseupCallback=C,Li(this.flattedOptions)}updateValue(e){this.value=e,m(this,T,this.isSingleSelect?this.value:[]),yi(e,this.flattedOptions,this.srcElement,this.iconElements,this.isSingleSelect,l(this,T),this.expandSelected,l(this,Z),this.isIndependentNodes,this.rtl),m(this,Z,!1),a(this,rt,de).call(this)}updateSearchValue(e){if(e===this.searchText)return;let s=this.searchText===""&&e!=="";this.searchText=e,s&&(this.flattedOptionsBeforeSearch=JSON.parse(JSON.stringify(this.flattedOptions))),this.searchText===""&&(this.flattedOptions=this.flattedOptionsBeforeSearch.map(i=>{let n=this.flattedOptions.find(o=>o.id===i.id);return n.isClosed=i.isClosed,n.hidden=i.hidden,n}),this.flattedOptionsBeforeSearch=[]),this.searchText&&Ei(this.flattedOptions,e),ot(this.flattedOptions,this.srcElement,this.iconElements,l(this,T),this.rtl),this.focusFirstListElement()}callKeyAction(e){m(this,P,!1);let s=this.srcElement.querySelector(".treeselect-list__item--focused");if(s?.classList.contains("treeselect-list__item--hidden"))return;let i=e.key;i==="Enter"&&s&&s.dispatchEvent(new Event("mousedown")),(i==="ArrowLeft"||i==="ArrowRight")&&a(this,Ut,Fs).call(this,s,e),(i==="ArrowDown"||i==="ArrowUp")&&a(this,zt,Ys).call(this,s,i)}focusFirstListElement(){let e="treeselect-list__item--focused",s=this.srcElement.querySelector(`.${e}`),i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter(n=>window.getComputedStyle(W(n)).display!=="none");i.length&&(s&&s.classList.remove(e),W(i[0]).classList.add(e))}isLastFocusedElementExist(){return!!l(this,I)}};I=new WeakMap,P=new WeakMap,T=new WeakMap,Z=new WeakMap,Ut=new WeakSet,Fs=function(t,e){if(!t)return;let s=e.key,i=t.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),n=Qe(i,this.flattedOptions),o=t.querySelector(".treeselect-list__item-icon");s==="ArrowLeft"&&!n.isClosed&&n.isGroup&&(o.dispatchEvent(new Event("mousedown")),e.preventDefault()),s==="ArrowRight"&&n.isClosed&&n.isGroup&&(o.dispatchEvent(new Event("mousedown")),e.preventDefault())},zt=new WeakSet,Ys=function(t,e){var s;let i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter(n=>window.getComputedStyle(W(n)).display!=="none");if(i.length)if(!t)W(i[0]).classList.add("treeselect-list__item--focused");else{let n=i.findIndex(g=>W(g).classList.contains("treeselect-list__item--focused"));W(i[n]).classList.remove("treeselect-list__item--focused");let o=e==="ArrowDown"?n+1:n-1,r=e==="ArrowDown"?0:i.length-1,u=i[o]??i[r],v=!i[o],k=W(u);k.classList.add("treeselect-list__item--focused");let w=this.srcElement.getBoundingClientRect(),f=k.getBoundingClientRect();if(v&&e==="ArrowDown"){this.srcElement.scroll(0,0);return}if(v&&e==="ArrowUp"){this.srcElement.scroll(0,this.srcElement.scrollHeight);return}let b=((s=this.listSlotHtmlComponent)==null?void 0:s.clientHeight)??0;if(w.y+w.heightf.y){this.srcElement.scroll(0,this.srcElement.scrollTop-f.height);return}}},Ft=new WeakSet,Js=function(){let t=a(this,Yt,Ze).call(this),e=a(this,tt,vt).call(this,this.options);t.append(...e);let s=a(this,Qt,is).call(this);t.append(s);let i=a(this,Xt,ss).call(this);return i&&t.append(i),t},Yt=new WeakSet,Ze=function(){let t=document.createElement("div");return t.classList.add("treeselect-list"),this.isSingleSelect&&t.classList.add("treeselect-list--single-select"),this.disabledBranchNode&&t.classList.add("treeselect-list--disabled-branch-node"),t.addEventListener("mouseout",e=>a(this,Jt,ts).call(this,e)),t.addEventListener("mousemove",()=>a(this,Kt,es).call(this)),t.addEventListener("mouseup",()=>this.mouseupCallback(),!0),t},Jt=new WeakSet,ts=function(t){t.stopPropagation(),l(this,I)&&l(this,P)&&l(this,I).classList.add("treeselect-list__item--focused")},Kt=new WeakSet,es=function(){m(this,P,!0)},tt=new WeakSet,vt=function(t){return t.reduce((e,s)=>{var i;if((i=s.children)!=null&&i.length){let o=a(this,Zt,ls).call(this,s),r=a(this,tt,vt).call(this,s.children);return o.append(...r),e.push(o),e}let n=a(this,et,ft).call(this,s,!1);return e.push(n),e},[])},Xt=new WeakSet,ss=function(){if(!this.listSlotHtmlComponent)return null;let t=document.createElement("div");return t.classList.add("treeselect-list__slot"),t.appendChild(this.listSlotHtmlComponent),t},Qt=new WeakSet,is=function(){let t=document.createElement("div");t.classList.add("treeselect-list__empty"),t.setAttribute("title",this.emptyText);let e=document.createElement("span");e.classList.add("treeselect-list__empty-icon"),O(this.iconElements.attention,e);let s=document.createElement("span");return s.classList.add("treeselect-list__empty-text"),s.textContent=this.emptyText,t.append(e,s),t},Zt=new WeakSet,ls=function(t){let e=document.createElement("div");e.setAttribute("group-container-id",t.value.toString()),e.classList.add("treeselect-list__group-container");let s=a(this,et,ft).call(this,t,!0);return e.appendChild(s),e},et=new WeakSet,ft=function(t,e){let s=a(this,te,ns).call(this,t);if(e){let o=a(this,le,os).call(this);s.appendChild(o),s.classList.add("treeselect-list__item--group")}let i=a(this,ae,ds).call(this,t),n=a(this,he,us).call(this,t,e);return s.append(i,n),s},te=new WeakSet,ns=function(t){let e=document.createElement("div");return Pi(e,t.htmlAttr),e.setAttribute("tabindex","-1"),e.setAttribute("title",t.name),e.classList.add("treeselect-list__item"),e.addEventListener("mouseover",()=>a(this,ee,as).call(this,e),!0),e.addEventListener("mouseout",()=>a(this,se,hs).call(this,e),!0),e.addEventListener("mousedown",s=>a(this,ie,cs).call(this,s,t)),e},ee=new WeakSet,as=function(t){l(this,P)&&a(this,st,bt).call(this,!0,t)},se=new WeakSet,hs=function(t){l(this,P)&&(a(this,st,bt).call(this,!1,t),m(this,I,t))},ie=new WeakSet,cs=function(t,e){var s;if(t.preventDefault(),t.stopPropagation(),(s=this.flattedOptions.find(n=>n.id===e.value))==null?void 0:s.disabled)return;let i=t.target.querySelector(".treeselect-list__item-checkbox");i.checked=!i.checked,a(this,oe,ms).call(this,i,e)},le=new WeakSet,os=function(){let t=document.createElement("span");return t.setAttribute("tabindex","-1"),t.classList.add("treeselect-list__item-icon"),O(this.iconElements.arrowDown,t),t.addEventListener("mousedown",e=>a(this,ne,rs).call(this,e)),t},ne=new WeakSet,rs=function(t){t.preventDefault(),t.stopPropagation(),a(this,re,ks).call(this,t)},ae=new WeakSet,ds=function(t){let e=document.createElement("div");e.classList.add("treeselect-list__item-checkbox-container");let s=document.createElement("span");s.classList.add("treeselect-list__item-checkbox-icon"),s.innerHTML="";let i=document.createElement("input");return i.setAttribute("tabindex","-1"),i.setAttribute("type","checkbox"),i.setAttribute("input-id",t.value.toString()),i.classList.add("treeselect-list__item-checkbox"),e.append(s,i),e},he=new WeakSet,us=function(t,e){let s=document.createElement("label");if(s.textContent=t.name,s.classList.add("treeselect-list__item-label"),e&&this.showCount){let i=a(this,ce,ps).call(this,t);s.appendChild(i)}return s},ce=new WeakSet,ps=function(t){let e=document.createElement("span"),s=this.flattedOptions.filter(i=>i.childOf===t.value);return e.textContent=`(${s.length})`,e.classList.add("treeselect-list__item-label-counter"),e},oe=new WeakSet,ms=function(t,e){let s=this.flattedOptions.find(i=>i.id===e.value);if(s){if(s!=null&&s.isGroup&&this.disabledBranchNode){let i=Hi(t);i?.dispatchEvent(new Event("mousedown"));return}if(this.isSingleSelect){let[i]=l(this,T);if(s.id===i)return;m(this,T,[s.id]),Is([s.id],this.flattedOptions,this.isSingleSelect,this.isIndependentNodes)}else{s.checked=t.checked;let i=Pe(s,this.flattedOptions,this.isIndependentNodes);t.checked=i}ot(this.flattedOptions,this.srcElement,this.iconElements,l(this,T),this.rtl),a(this,ue,ws).call(this)}},re=new WeakSet,ks=function(t){var e,s;let i=(s=(e=t.target)==null?void 0:e.parentNode)==null?void 0:s.querySelector("[input-id]"),n=i?.getAttribute("input-id")??null,o=Qe(n,this.flattedOptions);o&&(o.isClosed=!o.isClosed,wt(this.flattedOptions,o),ot(this.flattedOptions,this.srcElement,this.iconElements,l(this,T),this.rtl),this.arrowClickCallback(o.id,o.isClosed))},st=new WeakSet,bt=function(t,e){let s="treeselect-list__item--focused";if(t){let i=Array.from(this.srcElement.querySelectorAll(`.${s}`));i.length&&i.forEach(n=>n.classList.remove(s)),e.classList.add(s)}else e.classList.remove(s)},rt=new WeakSet,de=function(){let{ungroupedNodes:t,groupedNodes:e,allNodes:s}=bi(this.flattedOptions);this.selectedNodes={nodes:t,groupedNodes:e,allNodes:s}},ue=new WeakSet,ws=function(){a(this,rt,de).call(this),this.inputCallback(this.selectedNodes),this.value=this.selectedNodes.nodes.map(t=>t.id)};var vs=({parentHtmlContainer:t,staticList:e,appendToBody:s,isSingleSelect:i,value:n,direction:o})=>{t||console.error("Validation: parentHtmlContainer prop is required!"),e&&s&&console.error("Validation: You should set staticList to false if you use appendToBody!"),i&&Array.isArray(n)&&console.error("Validation: if you use isSingleSelect prop, you should pass a single value!"),!i&&!Array.isArray(n)&&console.error("Validation: you should pass an array as a value!"),o&&o!=="auto"&&o!=="bottom"&&o!=="top"&&console.error("Validation: you should pass (auto | top | bottom | undefined) as a value for the direction prop!")},X=t=>t.map(e=>e.id),Vi=t=>t?Array.isArray(t)?t:[t]:[],Gi=(t,e)=>{if(e){let[s]=t;return s??null}return t},d,p,R,it,U,x,_,E,B,lt,me,nt,gt,ke,fs,we,bs,ve,gs,fe,Cs,be,Es,ge,Ss,dt,Ce,Ee,Ls,Se,ys,Le,xs,ye,_s,ut,xe,_e,Ks,J,pt,at,Ct,z,ht,We,Ws,ct,Et,Te,Ts,Oe,Os,Ne,Ns,Ae,As,Be,Bs,mt=class{constructor({parentHtmlContainer:e,value:s,options:i,openLevel:n,appendToBody:o,alwaysOpen:r,showTags:u,tagsCountText:v,clearable:k,searchable:w,placeholder:f,grouped:b,isGroupedValue:g,listSlotHtmlComponent:y,disabled:C,emptyText:$,staticList:V,id:q,ariaLabel:j,isSingleSelect:K,showCount:Xs,disabledBranchNode:Qs,direction:Zs,expandSelected:ti,saveScrollPosition:ei,isIndependentNodes:si,rtl:ii,iconElements:li,inputCallback:ni,openCallback:ai,closeCallback:hi,nameChangeCallback:ci,searchCallback:oi,openCloseGroupCallback:ri}){h(this,lt),h(this,nt),h(this,ke),h(this,we),h(this,ve),h(this,fe),h(this,be),h(this,ge),h(this,dt),h(this,Ee),h(this,Se),h(this,Le),h(this,ye),h(this,ut),h(this,_e),h(this,J),h(this,at),h(this,z),h(this,We),h(this,ct),h(this,Te),h(this,Oe),h(this,Ne),h(this,Ae),h(this,Be),c(this,"parentHtmlContainer"),c(this,"value"),c(this,"options"),c(this,"openLevel"),c(this,"appendToBody"),c(this,"alwaysOpen"),c(this,"showTags"),c(this,"tagsCountText"),c(this,"clearable"),c(this,"searchable"),c(this,"placeholder"),c(this,"grouped"),c(this,"isGroupedValue"),c(this,"listSlotHtmlComponent"),c(this,"disabled"),c(this,"emptyText"),c(this,"staticList"),c(this,"id"),c(this,"ariaLabel"),c(this,"isSingleSelect"),c(this,"showCount"),c(this,"disabledBranchNode"),c(this,"direction"),c(this,"expandSelected"),c(this,"saveScrollPosition"),c(this,"isIndependentNodes"),c(this,"rtl"),c(this,"iconElements"),c(this,"inputCallback"),c(this,"openCallback"),c(this,"closeCallback"),c(this,"nameChangeCallback"),c(this,"searchCallback"),c(this,"openCloseGroupCallback"),c(this,"ungroupedValue"),c(this,"groupedValue"),c(this,"allValue"),c(this,"isListOpened"),c(this,"selectedName"),c(this,"srcElement"),h(this,d,null),h(this,p,null),h(this,R,null),h(this,it,0),h(this,U,0),h(this,x,null),h(this,_,null),h(this,E,null),h(this,B,null),vs({parentHtmlContainer:e,value:s,staticList:V,appendToBody:o,isSingleSelect:K}),this.parentHtmlContainer=e,this.value=[],this.options=i??[],this.openLevel=n??0,this.appendToBody=o??!1,this.alwaysOpen=!!(r&&!C),this.showTags=u??!0,this.tagsCountText=v??"elements selected",this.clearable=k??!0,this.searchable=w??!0,this.placeholder=f??"Search...",this.grouped=b??!0,this.isGroupedValue=g??!1,this.listSlotHtmlComponent=y??null,this.disabled=C??!1,this.emptyText=$??"No results found...",this.staticList=!!(V&&!this.appendToBody),this.id=q??"",this.ariaLabel=j??"",this.isSingleSelect=K??!1,this.showCount=Xs??!1,this.disabledBranchNode=Qs??!1,this.direction=Zs??"auto",this.expandSelected=ti??!1,this.saveScrollPosition=ei??!0,this.isIndependentNodes=si??!1,this.rtl=ii??!1,this.iconElements=Ge(li),this.inputCallback=ni,this.openCallback=ai,this.closeCallback=hi,this.nameChangeCallback=ci,this.searchCallback=oi,this.openCloseGroupCallback=ri,this.ungroupedValue=[],this.groupedValue=[],this.allValue=[],this.isListOpened=!1,this.selectedName="",this.srcElement=null,a(this,lt,me).call(this,s)}mount(){vs({parentHtmlContainer:this.parentHtmlContainer,value:this.value,staticList:this.staticList,appendToBody:this.appendToBody,isSingleSelect:this.isSingleSelect}),this.iconElements=Ge(this.iconElements),a(this,lt,me).call(this,this.value)}updateValue(e){let s=Vi(e),i=l(this,d);i&&(i.updateValue(s),a(this,dt,Ce).call(this,i?.selectedNodes))}destroy(){this.srcElement&&(a(this,ut,xe).call(this),this.srcElement.innerHTML="",this.srcElement=null,a(this,z,ht).call(this,!0))}focus(){l(this,p)&&l(this,p).focus()}toggleOpenClose(){l(this,p)&&(l(this,p).openClose(),l(this,p).focus())}scrollWindowHandler(){this.updateListPosition()}focusWindowHandler(e){var s,i,n;(s=this.srcElement)!=null&&s.contains(e.target)||(i=l(this,d))!=null&&i.srcElement.contains(e.target)||((n=l(this,p))==null||n.blur(),a(this,z,ht).call(this,!1),a(this,J,pt).call(this,!1))}blurWindowHandler(){var e;(e=l(this,p))==null||e.blur(),a(this,z,ht).call(this,!1),a(this,J,pt).call(this,!1)}updateListPosition(){var e;let s=this.srcElement,i=(e=l(this,d))==null?void 0:e.srcElement;if(!s||!i)return;let{height:n}=i.getBoundingClientRect(),{x:o,y:r,height:u,width:v}=s.getBoundingClientRect(),k=window.innerHeight,w=r,f=k-r-u,b=w>f&&w>=n&&fa(this,Ee,Ls).call(this,i),arrowClickCallback:(i,n)=>a(this,Se,ys).call(this,i,n),mouseupCallback:()=>{var i;return(i=l(this,p))==null?void 0:i.focus()}}),s=new jt({value:[],showTags:this.showTags,tagsCountText:this.tagsCountText,clearable:this.clearable,isAlwaysOpened:this.alwaysOpen,searchable:this.searchable,placeholder:this.placeholder,disabled:this.disabled,isSingleSelect:this.isSingleSelect,id:this.id,ariaLabel:this.ariaLabel,iconElements:this.iconElements,inputCallback:i=>a(this,we,bs).call(this,i),searchCallback:i=>a(this,fe,Cs).call(this,i),openCallback:()=>a(this,ye,_s).call(this),closeCallback:()=>a(this,ut,xe).call(this),keydownCallback:i=>a(this,ve,gs).call(this,i),focusCallback:()=>a(this,be,Es).call(this),blurCallback:()=>a(this,ge,Ss).call(this),nameChangeCallback:i=>a(this,Le,xs).call(this,i)});return this.appendToBody&&m(this,R,new ResizeObserver(()=>this.updateListPosition())),t.append(s.srcElement),{container:t,list:e,input:s}},we=new WeakSet,bs=function(t){var e,s;let i=X(t);(e=l(this,d))==null||e.updateValue(i);let n=((s=l(this,d))==null?void 0:s.selectedNodes)??{};a(this,nt,gt).call(this,n),a(this,ct,Et).call(this)},ve=new WeakSet,gs=function(t){var e;this.isListOpened&&((e=l(this,d))==null||e.callKeyAction(t))},fe=new WeakSet,Cs=function(t){l(this,U)&&clearTimeout(l(this,U)),m(this,U,window.setTimeout(()=>{var e;(e=l(this,d))==null||e.updateSearchValue(t),this.updateListPosition()},350)),a(this,Ae,As).call(this,t)},be=new WeakSet,Es=function(){a(this,J,pt).call(this,!0),l(this,E)&&l(this,E)&&l(this,B)&&(document.addEventListener("mousedown",l(this,E),!0),document.addEventListener("focus",l(this,E),!0),window.addEventListener("blur",l(this,B)))},ge=new WeakSet,Ss=function(){setTimeout(()=>{var t,e;let s=(t=l(this,p))==null?void 0:t.srcElement.contains(document.activeElement),i=(e=l(this,d))==null?void 0:e.srcElement.contains(document.activeElement);!s&&!i&&this.blurWindowHandler()},1)},dt=new WeakSet,Ce=function(t){var e;if(!t)return;let s=[];this.isIndependentNodes||this.isSingleSelect?s=t.allNodes:this.grouped?s=t.groupedNodes:s=t.nodes,(e=l(this,p))==null||e.updateValue(s),a(this,nt,gt).call(this,t)},Ee=new WeakSet,Ls=function(t){var e,s,i;a(this,dt,Ce).call(this,t),this.isSingleSelect&&!this.alwaysOpen&&((e=l(this,p))==null||e.openClose(),(s=l(this,p))==null||s.clearSearch()),(i=l(this,p))==null||i.focus(),a(this,ct,Et).call(this)},Se=new WeakSet,ys=function(t,e){var s;(s=l(this,p))==null||s.focus(),this.updateListPosition(),a(this,Be,Bs).call(this,t,e)},Le=new WeakSet,xs=function(t){this.selectedName!==t&&(this.selectedName=t,a(this,Te,Ts).call(this))},ye=new WeakSet,_s=function(){var t;this.isListOpened=!0,l(this,x)&&l(this,_)&&(window.addEventListener("scroll",l(this,x),!0),window.addEventListener("resize",l(this,_))),!(!l(this,d)||!this.srcElement)&&(this.appendToBody?(document.body.appendChild(l(this,d).srcElement),(t=l(this,R))==null||t.observe(this.srcElement)):this.srcElement.appendChild(l(this,d).srcElement),this.updateListPosition(),a(this,at,Ct).call(this,!0),a(this,We,Ws).call(this),a(this,Oe,Os).call(this))},ut=new WeakSet,xe=function(){var t;this.alwaysOpen||(this.isListOpened=!1,l(this,x)&&l(this,_)&&(window.removeEventListener("scroll",l(this,x),!0),window.removeEventListener("resize",l(this,_))),!l(this,d)||!this.srcElement)||!(this.appendToBody?document.body.contains(l(this,d).srcElement):this.srcElement.contains(l(this,d).srcElement))||(m(this,it,l(this,d).srcElement.scrollTop),this.appendToBody?(document.body.removeChild(l(this,d).srcElement),(t=l(this,R))==null||t.disconnect()):this.srcElement.removeChild(l(this,d).srcElement),a(this,at,Ct).call(this,!1),a(this,Ne,Ns).call(this))},_e=new WeakSet,Ks=function(t,e){if(!l(this,d)||!l(this,p))return;let s=e?"treeselect-list--top-to-body":"treeselect-list--top",i=e?"treeselect-list--bottom-to-body":"treeselect-list--bottom";t?(l(this,d).srcElement.classList.add(s),l(this,d).srcElement.classList.remove(i),l(this,p).srcElement.classList.add("treeselect-input--top"),l(this,p).srcElement.classList.remove("treeselect-input--bottom")):(l(this,d).srcElement.classList.remove(s),l(this,d).srcElement.classList.add(i),l(this,p).srcElement.classList.remove("treeselect-input--top"),l(this,p).srcElement.classList.add("treeselect-input--bottom"))},J=new WeakSet,pt=function(t){!l(this,p)||!l(this,d)||(t?(l(this,p).srcElement.classList.add("treeselect-input--focused"),l(this,d).srcElement.classList.add("treeselect-list--focused")):(l(this,p).srcElement.classList.remove("treeselect-input--focused"),l(this,d).srcElement.classList.remove("treeselect-list--focused")))},at=new WeakSet,Ct=function(t){var e,s,i,n;t?(e=l(this,p))==null||e.srcElement.classList.add("treeselect-input--opened"):(s=l(this,p))==null||s.srcElement.classList.remove("treeselect-input--opened"),this.staticList?(i=l(this,d))==null||i.srcElement.classList.add("treeselect-list--static"):(n=l(this,d))==null||n.srcElement.classList.remove("treeselect-list--static")},z=new WeakSet,ht=function(t){!l(this,x)||!l(this,_)||!l(this,E)||!l(this,B)||((!this.alwaysOpen||t)&&(window.removeEventListener("scroll",l(this,x),!0),window.removeEventListener("resize",l(this,_))),document.removeEventListener("mousedown",l(this,E),!0),document.removeEventListener("focus",l(this,E),!0),window.removeEventListener("blur",l(this,B)))},We=new WeakSet,Ws=function(){var t,e,s;let i=(t=l(this,d))==null?void 0:t.isLastFocusedElementExist();this.saveScrollPosition&&i?(e=l(this,d))==null||e.srcElement.scroll(0,l(this,it)):(s=l(this,d))==null||s.focusFirstListElement()},ct=new WeakSet,Et=function(){var t;(t=this.srcElement)==null||t.dispatchEvent(new CustomEvent("input",{detail:this.value})),this.inputCallback&&this.inputCallback(this.value)},Te=new WeakSet,Ts=function(){var t;(t=this.srcElement)==null||t.dispatchEvent(new CustomEvent("name-change",{detail:this.selectedName})),this.nameChangeCallback&&this.nameChangeCallback(this.selectedName)},Oe=new WeakSet,Os=function(){var t;this.alwaysOpen||((t=this.srcElement)==null||t.dispatchEvent(new CustomEvent("open",{detail:this.value})),this.openCallback&&this.openCallback(this.value))},Ne=new WeakSet,Ns=function(){var t;this.alwaysOpen||((t=this.srcElement)==null||t.dispatchEvent(new CustomEvent("close",{detail:this.value})),this.closeCallback&&this.closeCallback(this.value))},Ae=new WeakSet,As=function(t){var e;let s=t?.trim()??"";(e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("search",{detail:s})),this.searchCallback&&this.searchCallback(s)},Be=new WeakSet,Bs=function(t,e){var s;(s=this.srcElement)==null||s.dispatchEvent(new CustomEvent("open-close-group",{detail:{groupId:t,isClosed:e}})),this.openCloseGroupCallback&&this.openCloseGroupCallback(t,e)};function Mi({state:t,name:e,options:s,searchable:i,showCount:n,placeholder:o,rtl:r,disabledBranchNode:u=!0,disabled:v=!1,isSingleSelect:k=!0,showTags:w=!0,clearable:f=!0,isIndependentNodes:b=!0,alwaysOpen:g=!1,emptyText:y,expandSelected:C=!0,grouped:$=!0,openLevel:V=0,direction:q="auto"}){return{state:t,tree:null,init(){this.tree=new mt({id:`tree-${e}-id`,ariaLabel:`tree-${e}-label`,parentHtmlContainer:this.$refs.tree,value:this.state,options:s,searchable:i,showCount:n,placeholder:o,disabledBranchNode:u,disabled:v,isSingleSelect:k,showTags:w,clearable:f,isIndependentNodes:b,alwaysOpen:g,emptyText:y,expandSelected:C,grouped:$,openLevel:V,direction:q,rtl:r}),this.tree.srcElement.addEventListener("input",j=>{this.state=j.detail})}}}export{Mi as default};