diff --git a/README.md b/README.md
index 77a2902..da263c6 100644
--- a/README.md
+++ b/README.md
@@ -62,9 +62,12 @@ SelectTree::make('category_id')
// Expand the tree with selected values
->expandSelected(false)
-// All groups will be opened to this level
+// All groups will be opened to this level
->defaultOpenLevel(2)
+// Specify the list's force direction. Options include: auto (default), top, and bottom.
+->directon('top')
+
// Display individual leaf nodes instead of the main group when all leaf nodes are selected
->grouped(false)
diff --git a/resources/dist/tree.js b/resources/dist/tree.js
index d39941e..441840c 100644
--- a/resources/dist/tree.js
+++ b/resources/dist/tree.js
@@ -1 +1 @@
-var hi=Object.defineProperty,ci=(e,t,s)=>t in e?hi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,c=(e,t,s)=>(ci(e,typeof t!="symbol"?t+"":t,s),s),Bt=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},n=(e,t,s)=>(Bt(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)=>(Bt(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s),a=(e,t,s)=>(Bt(e,t,"access private method"),s),Pt={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)}},Vt=e=>{let t=e?{...e}:{};return Object.keys(Pt).forEach(s=>{t[s]||(t[s]=Pt[s])}),t},oi=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,M,F).call(this),a(this,G,U).call(this)}removeItem(t){this.value=this.value.filter(s=>s.id!==t),a(this,K,qe).call(this),a(this,M,F).call(this),a(this,G,U).call(this)}clear(){this.value=[],a(this,K,qe).call(this),a(this,M,F).call(this),this.clearSearch()}openClose(){a(this,A,H).call(this)}clearSearch(){this.searchText="",this.searchCallback(""),a(this,G,U).call(this)}};N=new WeakMap,S=new WeakMap,D=new WeakMap,E=new WeakMap,Se=new WeakSet,As=function(){a(this,M,F).call(this),a(this,G,U).call(this),a(this,Le,Mt).call(this)},M=new WeakSet,F=function(){if(n(this,N).innerHTML="",this.showTags){n(this,N).append(...a(this,Te,Dt).call(this));let e=oi(this.value);this.nameChangeCallback(e)}else{let e=a(this,Be,Rt).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,Ge,zt).call(this)),this.isAlwaysOpened||e.push(a(this,De,Jt).call(this,this.isOpened)),e.length&&n(this,D).append(...e)},ye=new WeakSet,Gt=function(){if(!this.isAlwaysOpened&&n(this,E)){let e=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;T(e,n(this,E))}},G=new WeakSet,U=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,Gt).call(this),this.isOpened?this.openCallback():this.closeCallback()},xe=new WeakSet,Bs=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,It).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,It=function(e){e.stopPropagation(),this.isOpened||a(this,A,H).call(this),this.focus()},We=new WeakSet,Hs=function(){let e=document.createElement("div");return e.classList.add("treeselect-input__tags"),e},Te=new WeakSet,Dt=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,qt).call(this,e.name),i=a(this,Ae,jt).call(this);return t.addEventListener("mousedown",l=>a(this,Oe,$t).call(this,l,e.id)),t.append(s,i),t})},Oe=new WeakSet,$t=function(e,t){e.preventDefault(),e.stopPropagation(),this.removeItem(t),this.focus()},Ne=new WeakSet,qt=function(e){let t=document.createElement("span");return t.classList.add("treeselect-input__tags-name"),t.textContent=e,t},Ae=new WeakSet,jt=function(){let e=document.createElement("span");return e.classList.add("treeselect-input__tags-cross"),T(this.iconElements.cross,e),e},Be=new WeakSet,Rt=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,Ps=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,Ft).call(this,t)),e.addEventListener("input",t=>a(this,Ve,Ut).call(this,t,e)),e},Pe=new WeakSet,Ft=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,Ut=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},Me=new WeakSet,Vs=function(){let e=document.createElement("div");return e.classList.add("treeselect-input__operators"),e},Ge=new WeakSet,zt=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,Yt).call(this,t)),e},Ie=new WeakSet,Yt=function(e){e.preventDefault(),e.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},De=new WeakSet,Jt=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,Kt).call(this,s)),n(this,E)},$e=new WeakSet,Kt=function(e){e.stopPropagation(),e.preventDefault(),this.focus(),a(this,A,H).call(this)},K=new WeakSet,qe=function(){this.inputCallback(this.value)};var Ms=(e,t,s,i)=>{pi(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=Ht(o,t,i);o.checked=r})},Ht=({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=Gs(!!t,l,s);return Is(l,s),o},Gs=(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):Ds(i,s)?$s(i)?(t.checked=!1,t.isPartialChecked=!1,t.disabled=!0,t.checked):(t.checked=!1,t.isPartialChecked=!0,i.forEach(l=>{Gs(e,l,s)}),t.checked):(t.checked=!0,t.isPartialChecked=!1,Re(t,i,s),t.checked)},Is=(e,t)=>{let s=t.find(i=>i.id===e.childOf);s&&(ri(s,t),Is(s,t))},ri=(e,t)=>{let s=pe(e,t);if($s(s)){e.checked=!1,e.isPartialChecked=!1,e.disabled=!0;return}if(di(s)){e.checked=!0,e.isPartialChecked=!1;return}if(ui(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=pe(l,i);Re({checked:e,disabled:t},o,i)})},Ds=(e,t)=>e.some(s=>s.disabled)?!0:e.some(s=>{if(s.isGroup){let i=pe(s,t);return Ds(i,t)}return!1}),$s=e=>e.every(t=>!!t.disabled),di=e=>e.every(t=>!!t.checked),ui=e=>e.some(t=>!!t.checked||!!t.isPartialChecked),pi=e=>{e.forEach(t=>{t.checked=!1,t.isPartialChecked=!1})},mi=(e,t,s)=>{let i={level:0,groupId:""},l=qs(e,t,i.groupId,i.level);return ki(l,s)},qs=(e,t,s,i)=>e.reduce((l,o)=>{var r;let p=!!((r=o.children)!=null&&r.length),w=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:w,hidden:f,disabled:o.disabled??!1}),p){let k=qs(o.children,t,o.value,i+1);l.push(...k)}return l},[]),pe=({id:e},t)=>t.filter(s=>s.childOf===e),wi=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}},ki=(e,t)=>(e.filter(s=>!!s.disabled).forEach(({id:s})=>Ht({id:s,checked:!1},e,t)),e),me=(e,{id:t,isClosed:s})=>{pe({id:t},e).forEach(i=>{i.hidden=s??!1,i.isGroup&&!i.isClosed&&me(e,{id:i.id,isClosed:s})})},vi=e=>{e.filter(t=>t.isGroup&&!t.disabled&&(t.checked||t.isPartialChecked)).forEach(t=>{t.isClosed=!1,me(e,t)})},fi=(e,t)=>{let s=bi(e,t);e.forEach(i=>{s.some(({id:l})=>l===i.id)?(i.isGroup&&(i.isClosed=!1,me(e,i)),i.hidden=!1):i.hidden=!0})},bi=(e,t)=>e.reduce((s,i)=>{if(i.name.toLowerCase().includes(t.toLowerCase())){if(s.push(i),i.isGroup){let l=js(i.id,e);s.push(...l)}if(i.childOf){let l=Rs(i.childOf,e);s.push(...l)}}return s},[]),js=(e,t)=>t.reduce((s,i)=>(i.childOf===e&&(s.push(i),i.isGroup&&s.push(...js(i.id,t))),s),[]),Rs=(e,t)=>t.reduce((s,i)=>(i.id===e&&(s.push(i),i.childOf&&s.push(...Rs(i.childOf,t))),s),[]),gi=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.`)},Ci=(e,t,s,i,l,o,r,p,w)=>{Ms(e,t,l,w),p&&r&&vi(t),he(t,s,i,o)},he=(e,t,s,i)=>{e.forEach(l=>{let o=t.querySelector(`[input-id="${l.id}"]`),r=_(o);o.checked=l.checked,Ei(l,r,i),Si(l,r),Li(l,r),yi(l,r,s),xi(l,r),Wi(l,r,e),_i(l,o,s)}),Ti(e,t)},Ei=(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")},Si=(e,t)=>{e.isPartialChecked?t.classList.add("treeselect-list__item--partial-checked"):t.classList.remove("treeselect-list__item--partial-checked")},Li=(e,t)=>{e.disabled?t.classList.add("treeselect-list__item--disabled"):t.classList.remove("treeselect-list__item--disabled")},yi=(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")}},xi=(e,t)=>{e.hidden?t.classList.add("treeselect-list__item--hidden"):t.classList.remove("treeselect-list__item--hidden")},_i=(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=""},Wi=(e,t,s)=>{let i=e.level===0,l=20,o=5;if(i){let r=s.some(w=>w.isGroup&&w.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())},Ti=(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,Xt=(e,t)=>t.find(s=>s.id.toString()===e),Oi=e=>_(e).querySelector(".treeselect-list__item-icon"),Ni=(e,t)=>{t&&Object.keys(t).forEach(s=>{let i=t[s];typeof i=="string"&&e.setAttribute(s,i)})},I,P,W,X,Fe,Fs,Ue,Us,ze,zs,Ye,Qt,Je,Zt,Ke,es,Q,ve,Xe,ts,Qe,ss,Ze,is,Z,fe,et,ls,tt,ns,st,as,it,hs,lt,cs,nt,os,at,rs,ht,ds,ct,us,ot,ps,rt,ms,ee,be,ce,dt,ut,ws,pt=class{constructor({options:t,value:s,openLevel:i,listSlotHtmlComponent:l,emptyText:o,isSingleSelect:r,iconElements:p,showCount:w,disabledBranchNode:f,expandSelected:k,isIndependentNodes:v,inputCallback:b,arrowClickCallback:g,mouseupCallback:L}){h(this,Fe),h(this,Ue),h(this,ze),h(this,Ye),h(this,Je),h(this,Ke),h(this,Q),h(this,Xe),h(this,Qe),h(this,Ze),h(this,Z),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,ee),h(this,ce),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,X,!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=w??!1,this.disabledBranchNode=f??!1,this.expandSelected=k??!1,this.isIndependentNodes=v??!1,this.iconElements=p,this.searchText="",this.flattedOptions=mi(this.options,this.openLevel,this.isIndependentNodes),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[],allNodes:[]},this.srcElement=a(this,ze,zs).call(this),this.inputCallback=b,this.arrowClickCallback=g,this.mouseupCallback=L,gi(this.flattedOptions)}updateValue(t){this.value=t,m(this,W,this.isSingleSelect?this.value:[]),Ci(t,this.flattedOptions,this.srcElement,this.iconElements,this.isSingleSelect,n(this,W),this.expandSelected,n(this,X),this.isIndependentNodes),m(this,X,!1),a(this,ce,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&&fi(this.flattedOptions,t),he(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,Fe,Fs).call(this,s,t),(i==="ArrowDown"||i==="ArrowUp")&&a(this,Ue,Us).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,X=new WeakMap,Fe=new WeakSet,Fs=function(e,t){if(!e)return;let s=t.key,i=e.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),l=Xt(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())},Ue=new WeakSet,Us=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],w=!i[o],f=_(p);f.classList.add("treeselect-list__item--focused");let k=this.srcElement.getBoundingClientRect(),v=f.getBoundingClientRect();if(w&&t==="ArrowDown"){this.srcElement.scroll(0,0);return}if(w&&t==="ArrowUp"){this.srcElement.scroll(0,this.srcElement.scrollHeight);return}let b=((s=this.listSlotHtmlComponent)==null?void 0:s.clientHeight)??0;if(k.y+k.heightv.y){this.srcElement.scroll(0,this.srcElement.scrollTop-v.height);return}}},ze=new WeakSet,zs=function(){let e=a(this,Ye,Qt).call(this),t=a(this,Q,ve).call(this,this.options);e.append(...t);let s=a(this,Qe,ss).call(this);e.append(s);let i=a(this,Xe,ts).call(this);return i&&e.append(i),e},Ye=new WeakSet,Qt=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,Zt).call(this,t)),e.addEventListener("mousemove",()=>a(this,Ke,es).call(this)),e.addEventListener("mouseup",()=>this.mouseupCallback(),!0),e},Je=new WeakSet,Zt=function(e){e.stopPropagation(),n(this,I)&&n(this,P)&&n(this,I).classList.add("treeselect-list__item--focused")},Ke=new WeakSet,es=function(){m(this,P,!0)},Q=new WeakSet,ve=function(e){return e.reduce((t,s)=>{var i;if((i=s.children)!=null&&i.length){let o=a(this,Ze,is).call(this,s),r=a(this,Q,ve).call(this,s.children);return o.append(...r),t.push(o),t}let l=a(this,Z,fe).call(this,s,!1);return t.push(l),t},[])},Xe=new WeakSet,ts=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,ss=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,is=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,Z,fe).call(this,e,!0);return t.appendChild(s),t},Z=new WeakSet,fe=function(e,t){let s=a(this,et,ls).call(this,e);if(t){let o=a(this,lt,cs).call(this);s.appendChild(o),s.classList.add("treeselect-list__item--group")}let i=a(this,at,rs).call(this,e),l=a(this,ht,ds).call(this,e,t);return s.append(i,l),s},et=new WeakSet,ls=function(e){let t=document.createElement("div");return Ni(t,e.htmlAttr),t.setAttribute("tabindex","-1"),t.setAttribute("title",e.name),t.classList.add("treeselect-list__item"),t.addEventListener("mouseover",()=>a(this,tt,ns).call(this,t),!0),t.addEventListener("mouseout",()=>a(this,st,as).call(this,t),!0),t.addEventListener("mousedown",s=>a(this,it,hs).call(this,s,e)),t},tt=new WeakSet,ns=function(e){n(this,P)&&a(this,ee,be).call(this,!0,e)},st=new WeakSet,as=function(e){n(this,P)&&(a(this,ee,be).call(this,!1,e),m(this,I,e))},it=new WeakSet,hs=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,ps).call(this,i,t)},lt=new WeakSet,cs=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,os).call(this,t)),e},nt=new WeakSet,os=function(e){e.preventDefault(),e.stopPropagation(),a(this,rt,ms).call(this,e)},at=new WeakSet,rs=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,ds=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,us).call(this,e);s.appendChild(i)}return s},ct=new WeakSet,us=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,ps=function(e,t){let s=this.flattedOptions.find(i=>i.id===t.value);if(s){if(s!=null&&s.isGroup&&this.disabledBranchNode){let i=Oi(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]),Ms([s.id],this.flattedOptions,this.isSingleSelect,this.isIndependentNodes)}else{s.checked=e.checked;let i=Ht(s,this.flattedOptions,this.isIndependentNodes);e.checked=i}he(this.flattedOptions,this.srcElement,this.iconElements,n(this,W)),a(this,ut,ws).call(this)}},rt=new WeakSet,ms=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=Xt(l,this.flattedOptions);o&&(o.isClosed=!o.isClosed,me(this.flattedOptions,o),he(this.flattedOptions,this.srcElement,this.iconElements,n(this,W)),this.arrowClickCallback())},ee=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)},ce=new WeakSet,dt=function(){let{ungroupedNodes:e,groupedNodes:t,allNodes:s}=wi(this.flattedOptions);this.selectedNodes={nodes:e,groupedNodes:t,allNodes:s}},ut=new WeakSet,ws=function(){a(this,ce,dt).call(this),this.inputCallback(this.selectedNodes),this.value=this.selectedNodes.nodes.map(e=>e.id)};var ks=({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!")},J=e=>e.map(t=>t.id),Ai=e=>e?Array.isArray(e)?e:[e]:[],Bi=(e,t)=>{if(t){let[s]=e;return s??null}return e},d,u,q,te,j,y,x,C,B,se,mt,ie,ge,wt,vs,kt,fs,vt,bs,ft,gs,bt,Cs,gt,Es,oe,Ct,Et,Ss,St,Ls,Lt,ys,yt,xs,re,xt,_t,Ys,z,de,le,Ce,R,ne,Wt,_s,ae,Ee,Tt,Ws,Ot,Ts,Nt,Os,At,Ns,ue=class{constructor({parentHtmlContainer:t,value:s,options:i,openLevel:l,appendToBody:o,alwaysOpen:r,showTags:p,tagsCountText:w,clearable:f,searchable:k,placeholder:v,grouped:b,isGroupedValue:g,listSlotHtmlComponent:L,disabled:O,emptyText:$,staticList:V,id:we,ariaLabel:ke,isSingleSelect:Y,showCount:Js,disabledBranchNode:Ks,direction:Xs,expandSelected:Qs,saveScrollPosition:Zs,isIndependentNodes:ei,iconElements:ti,inputCallback:si,openCallback:ii,closeCallback:li,nameChangeCallback:ni,searchCallback:ai}){h(this,se),h(this,ie),h(this,wt),h(this,kt),h(this,vt),h(this,ft),h(this,bt),h(this,gt),h(this,oe),h(this,Et),h(this,St),h(this,Lt),h(this,yt),h(this,re),h(this,_t),h(this,z),h(this,le),h(this,R),h(this,Wt),h(this,ae),h(this,Tt),h(this,Ot),h(this,Nt),h(this,At),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,"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,q,null),h(this,te,0),h(this,j,0),h(this,y,null),h(this,x,null),h(this,C,null),h(this,B,null),ks({parentHtmlContainer:t,value:s,staticList:V,appendToBody:o,isSingleSelect:Y}),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=w??"elements selected",this.clearable=f??!0,this.searchable=k??!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=we??"",this.ariaLabel=ke??"",this.isSingleSelect=Y??!1,this.showCount=Js??!1,this.disabledBranchNode=Ks??!1,this.direction=Xs??"auto",this.expandSelected=Qs??!1,this.saveScrollPosition=Zs??!0,this.isIndependentNodes=ei??!1,this.iconElements=Vt(ti),this.inputCallback=si,this.openCallback=ii,this.closeCallback=li,this.nameChangeCallback=ni,this.searchCallback=ai,this.ungroupedValue=[],this.groupedValue=[],this.allValue=[],this.isListOpened=!1,this.selectedName="",this.srcElement=null,a(this,se,mt).call(this,s)}mount(){ks({parentHtmlContainer:this.parentHtmlContainer,value:this.value,staticList:this.staticList,appendToBody:this.appendToBody,isSingleSelect:this.isSingleSelect}),this.iconElements=Vt(this.iconElements),a(this,se,mt).call(this,this.value)}updateValue(t){let s=Ai(t),i=n(this,d);i&&(i.updateValue(s),a(this,oe,Ct).call(this,i?.selectedNodes))}destroy(){this.srcElement&&(a(this,re,xt).call(this),this.srcElement.innerHTML="",this.srcElement=null,a(this,R,ne).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,R,ne).call(this,!1),a(this,z,de).call(this,!1))}blurWindowHandler(){var t;(t=n(this,u))==null||t.blur(),a(this,R,ne).call(this,!1),a(this,z,de).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:w}=s.getBoundingClientRect(),f=window.innerHeight,k=r,v=f-r-p,b=k>v&&k>=l&&va(this,Et,Ss).call(this,i),arrowClickCallback:()=>a(this,St,Ls).call(this),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,kt,fs).call(this,i),searchCallback:i=>a(this,ft,gs).call(this,i),openCallback:()=>a(this,yt,xs).call(this),closeCallback:()=>a(this,re,xt).call(this),keydownCallback:i=>a(this,vt,bs).call(this,i),focusCallback:()=>a(this,bt,Cs).call(this),blurCallback:()=>a(this,gt,Es).call(this),nameChangeCallback:i=>a(this,Lt,ys).call(this,i)});return this.appendToBody&&m(this,q,new ResizeObserver(()=>this.updateListPosition())),e.append(s.srcElement),{container:e,list:t,input:s}},kt=new WeakSet,fs=function(e){var t,s;let i=J(e);(t=n(this,d))==null||t.updateValue(i);let l=((s=n(this,d))==null?void 0:s.selectedNodes)??{};a(this,ie,ge).call(this,l),a(this,ae,Ee).call(this)},vt=new WeakSet,bs=function(e){var t;this.isListOpened&&((t=n(this,d))==null||t.callKeyAction(e))},ft=new WeakSet,gs=function(e){n(this,j)&&clearTimeout(n(this,j)),m(this,j,window.setTimeout(()=>{var t;(t=n(this,d))==null||t.updateSearchValue(e),this.updateListPosition()},350)),a(this,At,Ns).call(this,e)},bt=new WeakSet,Cs=function(){a(this,z,de).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,Es=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)},oe=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,ie,ge).call(this,e)},Et=new WeakSet,Ss=function(e){var t,s,i;a(this,oe,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,ae,Ee).call(this)},St=new WeakSet,Ls=function(){var e;(e=n(this,u))==null||e.focus(),this.updateListPosition()},Lt=new WeakSet,ys=function(e){this.selectedName!==e&&(this.selectedName=e,a(this,Tt,Ws).call(this))},yt=new WeakSet,xs=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,q))==null||e.observe(this.srcElement)):this.srcElement.appendChild(n(this,d).srcElement),this.updateListPosition(),a(this,le,Ce).call(this,!0),a(this,Wt,_s).call(this),a(this,Ot,Ts).call(this))},re=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,te,n(this,d).srcElement.scrollTop),this.appendToBody?(document.body.removeChild(n(this,d).srcElement),(e=n(this,q))==null||e.disconnect()):this.srcElement.removeChild(n(this,d).srcElement),a(this,le,Ce).call(this,!1),a(this,Nt,Os).call(this))},_t=new WeakSet,Ys=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"))},z=new WeakSet,de=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")))},le=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")},R=new WeakSet,ne=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,_s=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,te)):(s=n(this,d))==null||s.focusFirstListElement()},ae=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,Ws=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,Ts=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,Os=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,Ns=function(e){var t;let s=e?.trim()??"";(t=this.srcElement)==null||t.dispatchEvent(new CustomEvent("search",{detail:s})),this.searchCallback&&this.searchCallback(s)};function Hi({state:e,name:t,options:s,searchable:i,showCount:l,placeholder:o,disabledBranchNode:r=!0,disabled:p=!1,isSingleSelect:w=!0,showTags:f=!0,clearable:k=!0,isIndependentNodes:v=!0,alwaysOpen:b=!1,emptyText:g,expandSelected:L=!0,grouped:O=!0,openLevel:$=0}){return{state:e,tree:null,init(){this.tree=new ue({id:`tree-${t}-id`,ariaLabel:`tree-${t}-label`,parentHtmlContainer:this.$refs.tree,value:this.state,options:s,searchable:i,showCount:l,placeholder:o,disabledBranchNode:r,disabled:p,isSingleSelect:w,showTags:f,clearable:k,isIndependentNodes:v,alwaysOpen:b,emptyText:g,expandSelected:L,grouped:O,openLevel:$}),this.tree.srcElement.addEventListener("input",V=>{this.state=V.detail})}}}export{Hi as default};
+var hi=Object.defineProperty,ci=(e,t,s)=>t in e?hi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,c=(e,t,s)=>(ci(e,typeof t!="symbol"?t+"":t,s),s),Bt=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},n=(e,t,s)=>(Bt(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)=>(Bt(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s),a=(e,t,s)=>(Bt(e,t,"access private method"),s),Pt={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)}},Vt=e=>{let t=e?{...e}:{};return Object.keys(Pt).forEach(s=>{t[s]||(t[s]=Pt[s])}),t},oi=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,M,U).call(this),a(this,G,z).call(this)}removeItem(t){this.value=this.value.filter(s=>s.id!==t),a(this,X,qe).call(this),a(this,M,U).call(this),a(this,G,z).call(this)}clear(){this.value=[],a(this,X,qe).call(this),a(this,M,U).call(this),this.clearSearch()}openClose(){a(this,A,H).call(this)}clearSearch(){this.searchText="",this.searchCallback(""),a(this,G,z).call(this)}};N=new WeakMap,S=new WeakMap,D=new WeakMap,E=new WeakMap,Se=new WeakSet,As=function(){a(this,M,U).call(this),a(this,G,z).call(this),a(this,Le,Mt).call(this)},M=new WeakSet,U=function(){if(n(this,N).innerHTML="",this.showTags){n(this,N).append(...a(this,Te,Dt).call(this));let e=oi(this.value);this.nameChangeCallback(e)}else{let e=a(this,Be,Rt).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,Ge,zt).call(this)),this.isAlwaysOpened||e.push(a(this,De,Jt).call(this,this.isOpened)),e.length&&n(this,D).append(...e)},ye=new WeakSet,Gt=function(){if(!this.isAlwaysOpened&&n(this,E)){let e=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;T(e,n(this,E))}},G=new WeakSet,z=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,Gt).call(this),this.isOpened?this.openCallback():this.closeCallback()},xe=new WeakSet,Bs=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,It).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,It=function(e){e.stopPropagation(),this.isOpened||a(this,A,H).call(this),this.focus()},We=new WeakSet,Hs=function(){let e=document.createElement("div");return e.classList.add("treeselect-input__tags"),e},Te=new WeakSet,Dt=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,qt).call(this,e.name),i=a(this,Ae,jt).call(this);return t.addEventListener("mousedown",l=>a(this,Oe,$t).call(this,l,e.id)),t.append(s,i),t})},Oe=new WeakSet,$t=function(e,t){e.preventDefault(),e.stopPropagation(),this.removeItem(t),this.focus()},Ne=new WeakSet,qt=function(e){let t=document.createElement("span");return t.classList.add("treeselect-input__tags-name"),t.textContent=e,t},Ae=new WeakSet,jt=function(){let e=document.createElement("span");return e.classList.add("treeselect-input__tags-cross"),T(this.iconElements.cross,e),e},Be=new WeakSet,Rt=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,Ps=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,Ft).call(this,t)),e.addEventListener("input",t=>a(this,Ve,Ut).call(this,t,e)),e},Pe=new WeakSet,Ft=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,Ut=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},Me=new WeakSet,Vs=function(){let e=document.createElement("div");return e.classList.add("treeselect-input__operators"),e},Ge=new WeakSet,zt=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,Yt).call(this,t)),e},Ie=new WeakSet,Yt=function(e){e.preventDefault(),e.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},De=new WeakSet,Jt=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,Kt).call(this,s)),n(this,E)},$e=new WeakSet,Kt=function(e){e.stopPropagation(),e.preventDefault(),this.focus(),a(this,A,H).call(this)},X=new WeakSet,qe=function(){this.inputCallback(this.value)};var Ms=(e,t,s,i)=>{pi(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=Ht(o,t,i);o.checked=r})},Ht=({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=Gs(!!t,l,s);return Is(l,s),o},Gs=(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):Ds(i,s)?$s(i)?(t.checked=!1,t.isPartialChecked=!1,t.disabled=!0,t.checked):(t.checked=!1,t.isPartialChecked=!0,i.forEach(l=>{Gs(e,l,s)}),t.checked):(t.checked=!0,t.isPartialChecked=!1,Re(t,i,s),t.checked)},Is=(e,t)=>{let s=t.find(i=>i.id===e.childOf);s&&(ri(s,t),Is(s,t))},ri=(e,t)=>{let s=me(e,t);if($s(s)){e.checked=!1,e.isPartialChecked=!1,e.disabled=!0;return}if(di(s)){e.checked=!0,e.isPartialChecked=!1;return}if(ui(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=me(l,i);Re({checked:e,disabled:t},o,i)})},Ds=(e,t)=>e.some(s=>s.disabled)?!0:e.some(s=>{if(s.isGroup){let i=me(s,t);return Ds(i,t)}return!1}),$s=e=>e.every(t=>!!t.disabled),di=e=>e.every(t=>!!t.checked),ui=e=>e.some(t=>!!t.checked||!!t.isPartialChecked),pi=e=>{e.forEach(t=>{t.checked=!1,t.isPartialChecked=!1})},mi=(e,t,s)=>{let i={level:0,groupId:""},l=qs(e,t,i.groupId,i.level);return ki(l,s)},qs=(e,t,s,i)=>e.reduce((l,o)=>{var r;let p=!!((r=o.children)!=null&&r.length),w=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:w,hidden:f,disabled:o.disabled??!1}),p){let k=qs(o.children,t,o.value,i+1);l.push(...k)}return l},[]),me=({id:e},t)=>t.filter(s=>s.childOf===e),wi=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}},ki=(e,t)=>(e.filter(s=>!!s.disabled).forEach(({id:s})=>Ht({id:s,checked:!1},e,t)),e),we=(e,{id:t,isClosed:s})=>{me({id:t},e).forEach(i=>{i.hidden=s??!1,i.isGroup&&!i.isClosed&&we(e,{id:i.id,isClosed:s})})},vi=e=>{e.filter(t=>t.isGroup&&!t.disabled&&(t.checked||t.isPartialChecked)).forEach(t=>{t.isClosed=!1,we(e,t)})},fi=(e,t)=>{let s=bi(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})},bi=(e,t)=>e.reduce((s,i)=>{if(i.name.toLowerCase().includes(t.toLowerCase())){if(s.push(i),i.isGroup){let l=js(i.id,e);s.push(...l)}if(i.childOf){let l=Rs(i.childOf,e);s.push(...l)}}return s},[]),js=(e,t)=>t.reduce((s,i)=>(i.childOf===e&&(s.push(i),i.isGroup&&s.push(...js(i.id,t))),s),[]),Rs=(e,t)=>t.reduce((s,i)=>(i.id===e&&(s.push(i),i.childOf&&s.push(...Rs(i.childOf,t))),s),[]),gi=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.`)},Ci=(e,t,s,i,l,o,r,p,w)=>{Ms(e,t,l,w),p&&r&&vi(t),ce(t,s,i,o)},ce=(e,t,s,i)=>{e.forEach(l=>{let o=t.querySelector(`[input-id="${l.id}"]`),r=_(o);o.checked=l.checked,Ei(l,r,i),Si(l,r),Li(l,r),yi(l,r,s),xi(l,r),Wi(l,r,e),_i(l,o,s)}),Ti(e,t)},Ei=(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")},Si=(e,t)=>{e.isPartialChecked?t.classList.add("treeselect-list__item--partial-checked"):t.classList.remove("treeselect-list__item--partial-checked")},Li=(e,t)=>{e.disabled?t.classList.add("treeselect-list__item--disabled"):t.classList.remove("treeselect-list__item--disabled")},yi=(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")}},xi=(e,t)=>{e.hidden?t.classList.add("treeselect-list__item--hidden"):t.classList.remove("treeselect-list__item--hidden")},_i=(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=""},Wi=(e,t,s)=>{let i=e.level===0,l=20,o=5;if(i){let r=s.some(w=>w.isGroup&&w.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())},Ti=(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,Xt=(e,t)=>t.find(s=>s.id.toString()===e),Oi=e=>_(e).querySelector(".treeselect-list__item-icon"),Ni=(e,t)=>{t&&Object.keys(t).forEach(s=>{let i=t[s];typeof i=="string"&&e.setAttribute(s,i)})},I,P,W,Q,Fe,Fs,Ue,Us,ze,zs,Ye,Qt,Je,Zt,Ke,es,Z,ve,Xe,ts,Qe,ss,Ze,is,ee,fe,et,ls,tt,ns,st,as,it,hs,lt,cs,nt,os,at,rs,ht,ds,ct,us,ot,ps,rt,ms,te,be,oe,dt,ut,ws,pt=class{constructor({options:t,value:s,openLevel:i,listSlotHtmlComponent:l,emptyText:o,isSingleSelect:r,iconElements:p,showCount:w,disabledBranchNode:f,expandSelected:k,isIndependentNodes:v,inputCallback:b,arrowClickCallback:g,mouseupCallback:L}){h(this,Fe),h(this,Ue),h(this,ze),h(this,Ye),h(this,Je),h(this,Ke),h(this,Z),h(this,Xe),h(this,Qe),h(this,Ze),h(this,ee),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,te),h(this,oe),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,Q,!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=w??!1,this.disabledBranchNode=f??!1,this.expandSelected=k??!1,this.isIndependentNodes=v??!1,this.iconElements=p,this.searchText="",this.flattedOptions=mi(this.options,this.openLevel,this.isIndependentNodes),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[],allNodes:[]},this.srcElement=a(this,ze,zs).call(this),this.inputCallback=b,this.arrowClickCallback=g,this.mouseupCallback=L,gi(this.flattedOptions)}updateValue(t){this.value=t,m(this,W,this.isSingleSelect?this.value:[]),Ci(t,this.flattedOptions,this.srcElement,this.iconElements,this.isSingleSelect,n(this,W),this.expandSelected,n(this,Q),this.isIndependentNodes),m(this,Q,!1),a(this,oe,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&&fi(this.flattedOptions,t),ce(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,Fe,Fs).call(this,s,t),(i==="ArrowDown"||i==="ArrowUp")&&a(this,Ue,Us).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,Q=new WeakMap,Fe=new WeakSet,Fs=function(e,t){if(!e)return;let s=t.key,i=e.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),l=Xt(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())},Ue=new WeakSet,Us=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],w=!i[o],f=_(p);f.classList.add("treeselect-list__item--focused");let k=this.srcElement.getBoundingClientRect(),v=f.getBoundingClientRect();if(w&&t==="ArrowDown"){this.srcElement.scroll(0,0);return}if(w&&t==="ArrowUp"){this.srcElement.scroll(0,this.srcElement.scrollHeight);return}let b=((s=this.listSlotHtmlComponent)==null?void 0:s.clientHeight)??0;if(k.y+k.heightv.y){this.srcElement.scroll(0,this.srcElement.scrollTop-v.height);return}}},ze=new WeakSet,zs=function(){let e=a(this,Ye,Qt).call(this),t=a(this,Z,ve).call(this,this.options);e.append(...t);let s=a(this,Qe,ss).call(this);e.append(s);let i=a(this,Xe,ts).call(this);return i&&e.append(i),e},Ye=new WeakSet,Qt=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,Zt).call(this,t)),e.addEventListener("mousemove",()=>a(this,Ke,es).call(this)),e.addEventListener("mouseup",()=>this.mouseupCallback(),!0),e},Je=new WeakSet,Zt=function(e){e.stopPropagation(),n(this,I)&&n(this,P)&&n(this,I).classList.add("treeselect-list__item--focused")},Ke=new WeakSet,es=function(){m(this,P,!0)},Z=new WeakSet,ve=function(e){return e.reduce((t,s)=>{var i;if((i=s.children)!=null&&i.length){let o=a(this,Ze,is).call(this,s),r=a(this,Z,ve).call(this,s.children);return o.append(...r),t.push(o),t}let l=a(this,ee,fe).call(this,s,!1);return t.push(l),t},[])},Xe=new WeakSet,ts=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,ss=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,is=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,ee,fe).call(this,e,!0);return t.appendChild(s),t},ee=new WeakSet,fe=function(e,t){let s=a(this,et,ls).call(this,e);if(t){let o=a(this,lt,cs).call(this);s.appendChild(o),s.classList.add("treeselect-list__item--group")}let i=a(this,at,rs).call(this,e),l=a(this,ht,ds).call(this,e,t);return s.append(i,l),s},et=new WeakSet,ls=function(e){let t=document.createElement("div");return Ni(t,e.htmlAttr),t.setAttribute("tabindex","-1"),t.setAttribute("title",e.name),t.classList.add("treeselect-list__item"),t.addEventListener("mouseover",()=>a(this,tt,ns).call(this,t),!0),t.addEventListener("mouseout",()=>a(this,st,as).call(this,t),!0),t.addEventListener("mousedown",s=>a(this,it,hs).call(this,s,e)),t},tt=new WeakSet,ns=function(e){n(this,P)&&a(this,te,be).call(this,!0,e)},st=new WeakSet,as=function(e){n(this,P)&&(a(this,te,be).call(this,!1,e),m(this,I,e))},it=new WeakSet,hs=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,ps).call(this,i,t)},lt=new WeakSet,cs=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,os).call(this,t)),e},nt=new WeakSet,os=function(e){e.preventDefault(),e.stopPropagation(),a(this,rt,ms).call(this,e)},at=new WeakSet,rs=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,ds=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,us).call(this,e);s.appendChild(i)}return s},ct=new WeakSet,us=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,ps=function(e,t){let s=this.flattedOptions.find(i=>i.id===t.value);if(s){if(s!=null&&s.isGroup&&this.disabledBranchNode){let i=Oi(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]),Ms([s.id],this.flattedOptions,this.isSingleSelect,this.isIndependentNodes)}else{s.checked=e.checked;let i=Ht(s,this.flattedOptions,this.isIndependentNodes);e.checked=i}ce(this.flattedOptions,this.srcElement,this.iconElements,n(this,W)),a(this,ut,ws).call(this)}},rt=new WeakSet,ms=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=Xt(l,this.flattedOptions);o&&(o.isClosed=!o.isClosed,we(this.flattedOptions,o),ce(this.flattedOptions,this.srcElement,this.iconElements,n(this,W)),this.arrowClickCallback())},te=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)},oe=new WeakSet,dt=function(){let{ungroupedNodes:e,groupedNodes:t,allNodes:s}=wi(this.flattedOptions);this.selectedNodes={nodes:e,groupedNodes:t,allNodes:s}},ut=new WeakSet,ws=function(){a(this,oe,dt).call(this),this.inputCallback(this.selectedNodes),this.value=this.selectedNodes.nodes.map(e=>e.id)};var ks=({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!")},K=e=>e.map(t=>t.id),Ai=e=>e?Array.isArray(e)?e:[e]:[],Bi=(e,t)=>{if(t){let[s]=e;return s??null}return e},d,u,j,se,R,y,x,C,B,ie,mt,le,ge,wt,vs,kt,fs,vt,bs,ft,gs,bt,Cs,gt,Es,re,Ct,Et,Ss,St,Ls,Lt,ys,yt,xs,de,xt,_t,Ys,Y,ue,ne,Ce,F,ae,Wt,_s,he,Ee,Tt,Ws,Ot,Ts,Nt,Os,At,Ns,pe=class{constructor({parentHtmlContainer:t,value:s,options:i,openLevel:l,appendToBody:o,alwaysOpen:r,showTags:p,tagsCountText:w,clearable:f,searchable:k,placeholder:v,grouped:b,isGroupedValue:g,listSlotHtmlComponent:L,disabled:O,emptyText:$,staticList:V,id:q,ariaLabel:ke,isSingleSelect:J,showCount:Js,disabledBranchNode:Ks,direction:Xs,expandSelected:Qs,saveScrollPosition:Zs,isIndependentNodes:ei,iconElements:ti,inputCallback:si,openCallback:ii,closeCallback:li,nameChangeCallback:ni,searchCallback:ai}){h(this,ie),h(this,le),h(this,wt),h(this,kt),h(this,vt),h(this,ft),h(this,bt),h(this,gt),h(this,re),h(this,Et),h(this,St),h(this,Lt),h(this,yt),h(this,de),h(this,_t),h(this,Y),h(this,ne),h(this,F),h(this,Wt),h(this,he),h(this,Tt),h(this,Ot),h(this,Nt),h(this,At),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,"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,j,null),h(this,se,0),h(this,R,0),h(this,y,null),h(this,x,null),h(this,C,null),h(this,B,null),ks({parentHtmlContainer:t,value:s,staticList:V,appendToBody:o,isSingleSelect:J}),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=w??"elements selected",this.clearable=f??!0,this.searchable=k??!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=ke??"",this.isSingleSelect=J??!1,this.showCount=Js??!1,this.disabledBranchNode=Ks??!1,this.direction=Xs??"auto",this.expandSelected=Qs??!1,this.saveScrollPosition=Zs??!0,this.isIndependentNodes=ei??!1,this.iconElements=Vt(ti),this.inputCallback=si,this.openCallback=ii,this.closeCallback=li,this.nameChangeCallback=ni,this.searchCallback=ai,this.ungroupedValue=[],this.groupedValue=[],this.allValue=[],this.isListOpened=!1,this.selectedName="",this.srcElement=null,a(this,ie,mt).call(this,s)}mount(){ks({parentHtmlContainer:this.parentHtmlContainer,value:this.value,staticList:this.staticList,appendToBody:this.appendToBody,isSingleSelect:this.isSingleSelect}),this.iconElements=Vt(this.iconElements),a(this,ie,mt).call(this,this.value)}updateValue(t){let s=Ai(t),i=n(this,d);i&&(i.updateValue(s),a(this,re,Ct).call(this,i?.selectedNodes))}destroy(){this.srcElement&&(a(this,de,xt).call(this),this.srcElement.innerHTML="",this.srcElement=null,a(this,F,ae).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,F,ae).call(this,!1),a(this,Y,ue).call(this,!1))}blurWindowHandler(){var t;(t=n(this,u))==null||t.blur(),a(this,F,ae).call(this,!1),a(this,Y,ue).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:w}=s.getBoundingClientRect(),f=window.innerHeight,k=r,v=f-r-p,b=k>v&&k>=l&&va(this,Et,Ss).call(this,i),arrowClickCallback:()=>a(this,St,Ls).call(this),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,kt,fs).call(this,i),searchCallback:i=>a(this,ft,gs).call(this,i),openCallback:()=>a(this,yt,xs).call(this),closeCallback:()=>a(this,de,xt).call(this),keydownCallback:i=>a(this,vt,bs).call(this,i),focusCallback:()=>a(this,bt,Cs).call(this),blurCallback:()=>a(this,gt,Es).call(this),nameChangeCallback:i=>a(this,Lt,ys).call(this,i)});return this.appendToBody&&m(this,j,new ResizeObserver(()=>this.updateListPosition())),e.append(s.srcElement),{container:e,list:t,input:s}},kt=new WeakSet,fs=function(e){var t,s;let i=K(e);(t=n(this,d))==null||t.updateValue(i);let l=((s=n(this,d))==null?void 0:s.selectedNodes)??{};a(this,le,ge).call(this,l),a(this,he,Ee).call(this)},vt=new WeakSet,bs=function(e){var t;this.isListOpened&&((t=n(this,d))==null||t.callKeyAction(e))},ft=new WeakSet,gs=function(e){n(this,R)&&clearTimeout(n(this,R)),m(this,R,window.setTimeout(()=>{var t;(t=n(this,d))==null||t.updateSearchValue(e),this.updateListPosition()},350)),a(this,At,Ns).call(this,e)},bt=new WeakSet,Cs=function(){a(this,Y,ue).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,Es=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)},re=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,le,ge).call(this,e)},Et=new WeakSet,Ss=function(e){var t,s,i;a(this,re,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,he,Ee).call(this)},St=new WeakSet,Ls=function(){var e;(e=n(this,u))==null||e.focus(),this.updateListPosition()},Lt=new WeakSet,ys=function(e){this.selectedName!==e&&(this.selectedName=e,a(this,Tt,Ws).call(this))},yt=new WeakSet,xs=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,j))==null||e.observe(this.srcElement)):this.srcElement.appendChild(n(this,d).srcElement),this.updateListPosition(),a(this,ne,Ce).call(this,!0),a(this,Wt,_s).call(this),a(this,Ot,Ts).call(this))},de=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,se,n(this,d).srcElement.scrollTop),this.appendToBody?(document.body.removeChild(n(this,d).srcElement),(e=n(this,j))==null||e.disconnect()):this.srcElement.removeChild(n(this,d).srcElement),a(this,ne,Ce).call(this,!1),a(this,Nt,Os).call(this))},_t=new WeakSet,Ys=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"))},Y=new WeakSet,ue=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")))},ne=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")},F=new WeakSet,ae=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,_s=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,se)):(s=n(this,d))==null||s.focusFirstListElement()},he=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,Ws=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,Ts=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,Os=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,Ns=function(e){var t;let s=e?.trim()??"";(t=this.srcElement)==null||t.dispatchEvent(new CustomEvent("search",{detail:s})),this.searchCallback&&this.searchCallback(s)};function Hi({state:e,name:t,options:s,searchable:i,showCount:l,placeholder:o,disabledBranchNode:r=!0,disabled:p=!1,isSingleSelect:w=!0,showTags:f=!0,clearable:k=!0,isIndependentNodes:v=!0,alwaysOpen:b=!1,emptyText:g,expandSelected:L=!0,grouped:O=!0,openLevel:$=0,direction:V="auto"}){return{state:e,tree:null,init(){this.tree=new pe({id:`tree-${t}-id`,ariaLabel:`tree-${t}-label`,parentHtmlContainer:this.$refs.tree,value:this.state,options:s,searchable:i,showCount:l,placeholder:o,disabledBranchNode:r,disabled:p,isSingleSelect:w,showTags:f,clearable:k,isIndependentNodes:v,alwaysOpen:b,emptyText:g,expandSelected:L,grouped:O,openLevel:$,direction:V}),this.tree.srcElement.addEventListener("input",q=>{this.state=q.detail})}}}export{Hi as default};
diff --git a/resources/js/index.js b/resources/js/index.js
index 0586036..99660c2 100644
--- a/resources/js/index.js
+++ b/resources/js/index.js
@@ -18,7 +18,8 @@ export default function tree(
emptyText,
expandSelected = true,
grouped = true,
- openLevel = 0
+ openLevel = 0,
+ direction = 'auto'
}) {
return {
state,
@@ -43,7 +44,8 @@ export default function tree(
emptyText,
expandSelected,
grouped,
- openLevel
+ openLevel,
+ direction
});
this.tree.srcElement.addEventListener('input', (e) => {
diff --git a/resources/views/select-tree.blade.php b/resources/views/select-tree.blade.php
index b98e6d0..37f55fd 100644
--- a/resources/views/select-tree.blade.php
+++ b/resources/views/select-tree.blade.php
@@ -29,6 +29,7 @@
expandSelected: '{{ $getExpandSelected() }}',
grouped: '{{ $getGrouped() }}',
openLevel: '{{ $getDefaultOpenLevel() }}',
+ direction: '{{ $getDirection() }}',
})"
>
diff --git a/src/SelectTree.php b/src/SelectTree.php
index fa4ece3..bf1623e 100644
--- a/src/SelectTree.php
+++ b/src/SelectTree.php
@@ -47,6 +47,8 @@ class SelectTree extends Field
protected Closure|int $defaultOpenLevel;
+ protected string $direction = 'auto';
+
protected function setUp(): void
{
// Load the state from relationships using a callback function.
@@ -127,6 +129,13 @@ public function withCount(bool $withCount = true): static
return $this;
}
+ public function direction(string $direction): static
+ {
+ $this->direction = $direction;
+
+ return $this;
+ }
+
public function getRelationship(): BelongsToMany|BelongsTo
{
return $this->getModelInstance()->{$this->evaluate($this->relationship)}();
@@ -252,4 +261,9 @@ public function getEmptyLabel(): string
{
return $this->emptyLabel ? $this->evaluate($this->emptyLabel) : __('No results found');
}
+
+ public function getDirection(): string
+ {
+ return $this->evaluate($this->direction);
+ }
}