UNPKG

treeselectjs

Version:
2 lines (1 loc) 42.4 kB
(function(f,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(f=typeof globalThis<"u"?globalThis:f||self,f.Treeselect=m())})(this,function(){"use strict";var As=Object.defineProperty;var Oe=f=>{throw TypeError(f)};var Is=(f,m,v)=>m in f?As(f,m,{enumerable:!0,configurable:!0,writable:!0,value:v}):f[m]=v;var c=(f,m,v)=>Is(f,typeof m!="symbol"?m+"":m,v),oe=(f,m,v)=>m.has(f)||Oe("Cannot "+v);var n=(f,m,v)=>(oe(f,m,"read from private field"),v?v.call(f):m.get(f)),C=(f,m,v)=>m.has(f)?Oe("Cannot add the same private member more than once"):m instanceof WeakSet?m.add(f):m.set(f,v),E=(f,m,v,Q)=>(oe(f,m,"write to private field"),Q?Q.call(f,v):m.set(f,v),v),a=(f,m,v)=>(oe(f,m,"access private method"),v);var H,T,G,A,d,He,X,Pe,Be,Z,R,Ve,De,Ge,Me,Fe,Re,$e,je,We,Ue,ze,Ye,qe,Ke,Xe,Ze,he,M,B,F,Y,o,J,Je,Qe,et,tt,st,it,de,lt,nt,at,ue,rt,ct,ot,ht,dt,ut,mt,pt,ft,me,gt,bt,pe,te,fe,Ct,p,g,$,q,j,N,_,I,V,h,ge,be,Et,vt,wt,kt,Lt,St,Ce,xt,yt,Tt,At,Ee,ve,se,we,ie,It,ke,Nt,_t,Ot,Ht,Pt;const f={arrowUp:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 15l-6-6-6 6"/></svg>',arrowDown:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>',arrowRight:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>',attention:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>',clear:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg>',cross:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>',check:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>',partialCheck:'<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 25" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"></line></svg>'},m=(l,e)=>{if(e.innerHTML="",typeof l=="string")e.innerHTML=l;else{const t=l.cloneNode(!0);e.appendChild(t)}},v=l=>{const e=l?{...l}:{};return Object.keys(f).forEach(t=>{e[t]||(e[t]=f[t])}),e},Q=l=>l.reduce((e,{name:t},s)=>(e+=t,s<l.length-1&&(e+=", "),e),"");class Bt{constructor({value:e,showTags:t,tagsCountText:s,clearable:i,isAlwaysOpened:r,searchable:u,placeholder:b,disabled:L,isSingleSelect:x,id:k,ariaLabel:w,iconElements:S,inputCallback:y,searchCallback:O,openCallback:P,closeCallback:D,keydownCallback:K,focusCallback:W,blurCallback:re,nameChangeCallback:ce}){C(this,d);c(this,"value");c(this,"showTags");c(this,"tagsCountText");c(this,"clearable");c(this,"isAlwaysOpened");c(this,"searchable");c(this,"placeholder");c(this,"disabled");c(this,"isSingleSelect");c(this,"id");c(this,"ariaLabel");c(this,"iconElements");c(this,"isOpened");c(this,"searchText");c(this,"srcElement");C(this,H);C(this,T);C(this,G);C(this,A);c(this,"inputCallback");c(this,"searchCallback");c(this,"openCallback");c(this,"closeCallback");c(this,"keydownCallback");c(this,"focusCallback");c(this,"blurCallback");c(this,"nameChangeCallback");this.value=e,this.showTags=t,this.tagsCountText=s,this.searchable=u,this.placeholder=b,this.clearable=i,this.isAlwaysOpened=r,this.disabled=L,this.isSingleSelect=x,this.id=k,this.ariaLabel=w,this.iconElements=S,this.isOpened=!1,this.searchText="",E(this,H,a(this,d,Ge).call(this)),E(this,T,a(this,d,We).call(this)),E(this,G,a(this,d,Ye).call(this)),E(this,A,null),this.inputCallback=y,this.searchCallback=O,this.openCallback=P,this.closeCallback=D,this.keydownCallback=K,this.focusCallback=W,this.blurCallback=re,this.nameChangeCallback=ce,this.srcElement=a(this,d,Ve).call(this,{htmlTagsSection:n(this,H),htmlEditControl:n(this,T),htmlOperators:n(this,G)}),a(this,d,He).call(this)}focus(){setTimeout(()=>n(this,T).focus(),0)}blur(){this.isOpened&&a(this,d,R).call(this),this.clearSearch(),n(this,T).blur()}updateValue(e){this.value=e,a(this,d,X).call(this),a(this,d,Z).call(this)}removeItem(e){this.value=this.value.filter(t=>t.id!==e),a(this,d,he).call(this),a(this,d,X).call(this),a(this,d,Z).call(this)}clear(){this.value=[],a(this,d,he).call(this),a(this,d,X).call(this),this.clearSearch()}openClose(){a(this,d,R).call(this)}clearSearch(){this.searchText="",this.searchCallback(""),a(this,d,Z).call(this)}}H=new WeakMap,T=new WeakMap,G=new WeakMap,A=new WeakMap,d=new WeakSet,He=function(){a(this,d,X).call(this),a(this,d,Z).call(this),a(this,d,Pe).call(this)},X=function(){if(n(this,H).innerHTML="",this.showTags){n(this,H).append(...a(this,d,Me).call(this));const e=Q(this.value);this.nameChangeCallback(e)}else{const e=a(this,d,je).call(this);n(this,H).appendChild(e),this.nameChangeCallback(e.innerText)}n(this,H).appendChild(n(this,T))},Pe=function(){const e=[];n(this,G).innerHTML="",this.clearable&&e.push(a(this,d,qe).call(this)),this.isAlwaysOpened||e.push(a(this,d,Xe).call(this,this.isOpened)),e.length&&n(this,G).append(...e)},Be=function(){if(!this.isAlwaysOpened&&n(this,A)){const e=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;m(e,n(this,A))}},Z=function(){var e;(e=this.value)!=null&&e.length?(n(this,T).removeAttribute("placeholder"),this.srcElement.classList.remove("treeselect-input--value-not-selected")):(n(this,T).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,T).value=this.searchText},R=function(){this.isOpened=!this.isOpened,a(this,d,Be).call(this),this.isOpened?this.openCallback():this.closeCallback()},Ve=function({htmlTagsSection:e,htmlEditControl:t,htmlOperators:s}){const i=document.createElement("div");return i.classList.add("treeselect-input"),i.setAttribute("tabindex","-1"),i.addEventListener("mousedown",r=>a(this,d,De).call(this,r)),i.addEventListener("focus",()=>this.focusCallback(),!0),i.addEventListener("blur",()=>this.blurCallback(),!0),e.appendChild(t),i.append(e,s),i},De=function(e){e.stopPropagation(),this.isOpened||a(this,d,R).call(this),this.focus()},Ge=function(){const e=document.createElement("div");return e.classList.add("treeselect-input__tags"),e},Me=function(){return this.value.map(e=>{const 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);const s=a(this,d,Re).call(this,e.name),i=a(this,d,$e).call(this);return t.addEventListener("mousedown",r=>a(this,d,Fe).call(this,r,e.id)),t.append(s,i),t})},Fe=function(e,t){e.preventDefault(),e.stopPropagation(),this.removeItem(t),this.focus()},Re=function(e){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-name"),t.textContent=e,t},$e=function(){const e=document.createElement("span");return e.classList.add("treeselect-input__tags-cross"),m(this.iconElements.cross,e),e},je=function(){const e=document.createElement("span");if(e.classList.add("treeselect-input__tags-count"),!this.value.length)return e.textContent="",e.setAttribute("title",""),e;const t=this.value.length===1?this.value[0].name:`${this.value.length} ${this.tagsCountText}`;return e.textContent=t,e.setAttribute("title",t),e},We=function(){const 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,d,Ue).call(this,t)),e.addEventListener("input",t=>a(this,d,ze).call(this,t,e)),e},Ue=function(e){e.stopPropagation();const 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,d,R).call(this),(t==="Enter"||t==="ArrowDown"||t==="ArrowUp")&&e.preventDefault(),this.keydownCallback(e),t!=="Tab"&&this.focus()},ze=function(e,t){e.stopPropagation();const s=this.searchText,i=t.value.trim();if(s.length===0&&i.length===0){t.value="";return}if(this.searchable){const r=e.target.value;this.searchCallback(r),this.isOpened||a(this,d,R).call(this)}else t.value="";this.searchText=t.value},Ye=function(){const e=document.createElement("div");return e.classList.add("treeselect-input__operators"),e},qe=function(){const e=document.createElement("span");return e.classList.add("treeselect-input__clear"),e.setAttribute("tabindex","-1"),m(this.iconElements.clear,e),e.addEventListener("mousedown",t=>a(this,d,Ke).call(this,t)),e},Ke=function(e){e.preventDefault(),e.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},Xe=function(e){E(this,A,document.createElement("span")),n(this,A).classList.add("treeselect-input__arrow");const t=e?this.iconElements.arrowUp:this.iconElements.arrowDown;return m(t,n(this,A)),n(this,A).addEventListener("mousedown",s=>a(this,d,Ze).call(this,s)),n(this,A)},Ze=function(e){e.stopPropagation(),e.preventDefault(),this.focus(),a(this,d,R).call(this)},he=function(){this.inputCallback(this.value)};const Le=({newValue:l,optionsTreeMap:e,isSingleSelect:t,isIndependentNodes:s})=>{Mt(e);const i=l.map(u=>e.get(u)??null).filter(u=>u!==null&&!u.disabled),[r]=i;if(t&&i.length&&r){r.checked=!0;return}i.forEach(u=>{u.checked=!0;const b=le({option:u,optionsTreeMap:e,isIndependentNodes:s});u.checked=b})},le=({option:{id:l,checked:e},optionsTreeMap:t,isIndependentNodes:s})=>{const i=t.get(l)??null;if(i===null)return!1;if(s)return i.checked=!i.disabled&&e,i.checked;const r=Se({checked:e,currentOption:i,optionsTreeMap:t});return xe({childOption:i,optionsTreeMap:t}),r},Se=({checked:l,currentOption:e,optionsTreeMap:t})=>{if(!e.isGroup)return e.checked=!e.disabled&&l,e.isPartialChecked=!1,e.checked;const s=U({id:e.id,optionsTreeMap:t});return!l||e.disabled||e.isPartialChecked?(e.checked=!1,e.isPartialChecked=!1,ne({option:e,children:s,optionsTreeMap:t}),e.checked):ye({children:s,optionsTreeMap:t})?Te(s)?(e.checked=!1,e.isPartialChecked=!1,e.disabled=!0,e.checked):(e.checked=!1,e.isPartialChecked=!0,s.forEach(b=>{Se({checked:l,currentOption:b,optionsTreeMap:t})}),e.checked):(e.checked=!0,e.isPartialChecked=!1,ne({option:e,children:s,optionsTreeMap:t}),e.checked)},xe=({childOption:l,optionsTreeMap:e})=>{const t=e.get(l.childOf)??null;t!==null&&(Vt({parentOption:t,optionsTreeMap:e}),xe({childOption:t,optionsTreeMap:e}))},Vt=({parentOption:l,optionsTreeMap:e})=>{const t=U({id:l.id,optionsTreeMap:e});if(Te(t)){l.checked=!1,l.isPartialChecked=!1,l.disabled=!0;return}if(Dt(t)){l.checked=!0,l.isPartialChecked=!1;return}if(Gt(t)){l.checked=!1,l.isPartialChecked=!0;return}l.checked=!1,l.isPartialChecked=!1},ne=({option:{checked:l,disabled:e},children:t,optionsTreeMap:s})=>{t.forEach(i=>{i.disabled=e||i.disabled,i.checked=l&&!i.disabled,i.isPartialChecked=!1;const r=U({id:i.id,optionsTreeMap:s});ne({option:{checked:l,disabled:e},children:r,optionsTreeMap:s})})},ye=({children:l,optionsTreeMap:e})=>l.some(s=>s.disabled)?!0:l.some(s=>{if(!s.isGroup)return!1;const i=U({id:s.id,optionsTreeMap:e});return ye({children:i,optionsTreeMap:e})}),Te=l=>l.every(e=>!!e.disabled),Dt=l=>l.every(e=>e.checked),Gt=l=>l.some(e=>e.checked||e.isPartialChecked),Mt=l=>{l.forEach(e=>{e.checked=!1,e.isPartialChecked=!1})},Ft=({options:l,openLevel:e,isIndependentNodes:t})=>{const s={level:0,groupId:""},i=new Map;return Ae({optionsTreeMap:i,options:l,openLevel:e,groupId:s.groupId,level:s.level}),jt({optionsTreeMap:i,isIndependentNodes:t}),i},Ae=({optionsTreeMap:l,options:e,openLevel:t,groupId:s,level:i})=>{e.forEach(r=>{var w,S;const u=(((w=r.children)==null?void 0:w.length)??0)>0,b=i>=t&&u,L=i>t,x=((S=r.children)==null?void 0:S.map(y=>y.value))??[],k=r.value;l.has(k)&&console.error(`Validation: You have duplicated option value: ${k}! You should use unique values. Duplicates will lead to unexpected behavior.`),l.set(k,{id:k,name:r.name,childOf:s,isGroup:u,checked:!1,isPartialChecked:!1,level:i,isClosed:b,hidden:L,disabled:r.disabled??!1,isGroupSelectable:!u||(r.isGroupSelectable??!0),children:x,checkboxHtmlElement:null,itemHtmlElement:null,arrowItemHtmlElement:null,checkboxIconHtmlElement:null}),u&&Ae({optionsTreeMap:l,options:r.children,openLevel:t,groupId:k,level:i+1})})},Rt=(l,e)=>l===null?null:e.get(l)??e.get(parseInt(l))??null,U=({id:l,optionsTreeMap:e})=>{const t=e.get(l)??null;return t===null?[]:t.children.reduce((s,i)=>{const r=e.get(i)??null;return r!==null&&s.push(r),s},[])},$t=l=>{const e=[],t=[],s=[];l.forEach(r=>{r.checked&&(s.push(r),r.isGroup?t.push(r):e.push(r))});const i=s.filter(r=>!t.some(({id:u})=>u===r.childOf));return{ungroupedNodes:e,groupedNodes:i,allNodes:s}},jt=({optionsTreeMap:l,isIndependentNodes:e})=>{const t=[];l.forEach(s=>{s.disabled&&t.push(s)}),t.forEach(({id:s})=>le({option:{id:s,checked:!1},optionsTreeMap:l,isIndependentNodes:e}))},z=(l,{id:e,isClosed:t})=>{U({id:e,optionsTreeMap:l}).forEach(i=>{i.hidden=t??!1,i.isGroup&&!i.isClosed&&z(l,{id:i.id,isClosed:t})})},Wt=(l,e)=>{if(e){Ut(l);return}l.forEach(t=>{t.checked&&ae(t.childOf,l),t.isGroup&&!t.disabled&&(t.checked||t.isPartialChecked)&&(t.isClosed=!1,z(l,t))})},Ut=l=>{let e=null;for(const[t,s]of l)if(s.checked&&!s.disabled){e=s;break}e&&(e.isGroup&&(e.isClosed=!1,z(l,e)),ae(e.childOf,l))},ae=(l,e)=>{const t=e.get(l)??null;t&&(t.isClosed=!1,z(e,t),ae(t.childOf,e))},zt=(l,e)=>{l.forEach(t=>{const s=t.name.toLowerCase().includes(e.toLowerCase());s&&(t.isGroup&&(t.isClosed=!0),t.childOf&&Ie(t.childOf,l)),t.hidden=!s})},Ie=(l,e)=>{const t=e.get(l)??null;t&&(t.hidden=!1,t.isClosed=!1,Ie(t.childOf,e))},Yt=({optionsTreeMap:l,beforeSearchStateMap:e})=>{l.forEach(t=>{const s=e.get(t.id);s&&(t.hidden=s.hidden,t.isClosed=s.isClosed)}),e.clear()},qt=({optionsTreeMap:l,beforeSearchStateMap:e})=>{e.clear(),l.forEach(t=>{e.set(t.id,{hidden:t.hidden,isClosed:t.isClosed})})},Kt=l=>new IntersectionObserver(e=>{e.forEach(t=>{t.target.classList.toggle("treeselect-list__item--scroll-not-visible",!t.isIntersecting)})},{root:l,threshold:.5}),Xt=({optionsTreeMap:l,emptyListHtmlElement:e,iconElements:t,previousSingleSelectedValue:s,rtl:i})=>{l.forEach(r=>{const u=r.checkboxHtmlElement;u&&(u.checked=r.checked),es({option:r,previousSingleSelectedValue:s}),ts(r),ss(r),is({option:r,iconElements:t}),ls(r),Zt({option:r,optionsTreeMap:l,rtl:i}),ns({option:r,iconElements:t}),as(r)}),Jt({optionsTreeMap:l,emptyListHtmlElement:e})},Zt=({option:l,optionsTreeMap:e,rtl:t})=>{const s=l.level===0,i=20,r=5;let u="0";if(s){let L=!1;for(const[k,w]of e)if(w.isGroup&&w.level===l.level){L=!0;break}const x=!l.isGroup&&L?`${i}px`:`${r}px`;u=l.isGroup?"0":x}else u=l.isGroup?`${l.level*i}px`:`${l.level*i+i}px`;const b=l.itemHtmlElement;b&&(t?b.style.paddingRight=u:b.style.paddingLeft=u,b.setAttribute("level",l.level.toString()),b.setAttribute("group",l.isGroup.toString()))},Jt=({optionsTreeMap:l,emptyListHtmlElement:e})=>{let t=!1;for(const[s,i]of l)if(!i.hidden){t=!0;break}e==null||e.classList.toggle("treeselect-list__empty--hidden",t)},Qt=(l,e)=>{e&&Object.keys(e).forEach(t=>{const s=e[t];typeof s=="string"&&l.setAttribute(t,s)})},es=({option:l,previousSingleSelectedValue:e})=>{const t=l.itemHtmlElement;t==null||t.classList.toggle("treeselect-list__item--checked",l.checked);const s=Array.isArray(e)&&e[0]===l.id&&!l.disabled;t==null||t.classList.toggle("treeselect-list__item--single-selected",s)},ts=l=>{const e=l.itemHtmlElement;e==null||e.classList.toggle("treeselect-list__item--partial-checked",l.isPartialChecked)},ss=l=>{const e=l.itemHtmlElement;e==null||e.classList.toggle("treeselect-list__item--disabled",l.disabled)},is=({option:l,iconElements:e})=>{const t=l.arrowItemHtmlElement;if(l.isGroup&&t){const s=l.isClosed?e.arrowRight:e.arrowDown;m(s,t);const i=l.itemHtmlElement;i==null||i.classList.toggle("treeselect-list__item--closed",l.isClosed)}},ls=l=>{const e=l.itemHtmlElement;e==null||e.classList.toggle("treeselect-list__item--hidden",l.hidden)},ns=({option:l,iconElements:e})=>{const t=l.checkboxIconHtmlElement;t&&(l.checked?m(e.check,t):l.isPartialChecked?m(e.partialCheck,t):t.innerHTML="")},as=l=>{const e=l.itemHtmlElement;e==null||e.classList.toggle("treeselect-list__item--non-selectable-group",!l.isGroupSelectable)},rs=({newValue:l,optionsTreeMap:e,isSingleSelect:t,expandSelected:s,isFirstValueUpdate:i,isIndependentNodes:r})=>{Le({newValue:l,optionsTreeMap:e,isSingleSelect:t,isIndependentNodes:r}),i&&s&&Wt(e,t)};class cs{constructor({options:e,value:t,openLevel:s,listSlotHtmlComponent:i,tagsSortFn:r,emptyText:u,isSingleSelect:b,iconElements:L,showCount:x,disabledBranchNode:k,expandSelected:w,isIndependentNodes:S,rtl:y,listClassName:O,isBoostedRendering:P,inputCallback:D,arrowClickCallback:K,mouseupCallback:W}){C(this,o);c(this,"options");c(this,"value");c(this,"openLevel");c(this,"listSlotHtmlComponent");c(this,"tagsSortFn");c(this,"emptyText");c(this,"isSingleSelect");c(this,"showCount");c(this,"disabledBranchNode");c(this,"expandSelected");c(this,"isIndependentNodes");c(this,"rtl");c(this,"listClassName");c(this,"isBoostedRendering");c(this,"iconElements");c(this,"searchText");c(this,"intersectionItemsObserver");c(this,"selectedNodes");c(this,"optionsTreeMap");c(this,"beforeSearchStateMap");c(this,"emptyListHtmlElement");c(this,"srcElement");c(this,"inputCallback");c(this,"arrowClickCallback");c(this,"mouseupCallback");C(this,M,null);C(this,B,!0);C(this,F,[]);C(this,Y,!0);this.options=e,this.value=t,this.openLevel=s??0,this.listSlotHtmlComponent=i??null,this.tagsSortFn=r??null,this.emptyText=u??"No results found...",this.isSingleSelect=b??!1,this.showCount=x??!1,this.disabledBranchNode=k??!1,this.expandSelected=w??!1,this.isIndependentNodes=S??!1,this.rtl=y??!1,this.listClassName=O??"",this.isBoostedRendering=P,this.iconElements=L,this.searchText="",this.intersectionItemsObserver=null,this.selectedNodes={nodes:[],groupedNodes:[],allNodes:[]},this.optionsTreeMap=Ft({options:this.options,openLevel:this.openLevel,isIndependentNodes:this.isIndependentNodes}),this.beforeSearchStateMap=new Map,this.emptyListHtmlElement=null,this.srcElement=a(this,o,et).call(this),this.inputCallback=D,this.arrowClickCallback=K,this.mouseupCallback=W}updateValue(e){this.value=e,E(this,F,this.isSingleSelect?this.value:[]),rs({newValue:e,optionsTreeMap:this.optionsTreeMap,isSingleSelect:this.isSingleSelect,expandSelected:this.expandSelected,isFirstValueUpdate:n(this,Y),isIndependentNodes:this.isIndependentNodes}),a(this,o,J).call(this),E(this,Y,!1),a(this,o,fe).call(this)}updateSearchValue(e){if(e===this.searchText)return;const t=this.searchText===""&&e!=="";this.searchText=e,t&&qt({beforeSearchStateMap:this.beforeSearchStateMap,optionsTreeMap:this.optionsTreeMap}),this.searchText===""&&Yt({beforeSearchStateMap:this.beforeSearchStateMap,optionsTreeMap:this.optionsTreeMap}),this.searchText&&zt(this.optionsTreeMap,e),a(this,o,J).call(this),this.focusFirstListElement()}callKeyAction(e){E(this,B,!1);const t=this.srcElement.querySelector(".treeselect-list__item--focused");if(t==null?void 0:t.classList.contains("treeselect-list__item--hidden"))return;const i=e.key;i==="Enter"&&t&&t.dispatchEvent(new Event("mousedown")),(i==="ArrowLeft"||i==="ArrowRight")&&a(this,o,Je).call(this,t,e),(i==="ArrowDown"||i==="ArrowUp")&&a(this,o,Qe).call(this,t,i)}focusFirstListElement(){const e="treeselect-list__item--focused",t=this.srcElement.querySelector(`.${e}`),s=a(this,o,me).call(this);if(!s.length)return;t&&t.classList.remove(e);const[i]=s;i.classList.add(e)}isLastFocusedElementExist(){return!!n(this,M)}destroy(){this.intersectionItemsObserver&&this.intersectionItemsObserver.disconnect()}}M=new WeakMap,B=new WeakMap,F=new WeakMap,Y=new WeakMap,o=new WeakSet,J=function(){Xt({optionsTreeMap:this.optionsTreeMap,emptyListHtmlElement:this.emptyListHtmlElement,iconElements:this.iconElements,previousSingleSelectedValue:n(this,F),rtl:this.rtl})},Je=function(e,t){if(!e)return;const s=t.key,r=e.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),u=Rt(r,this.optionsTreeMap),b=u.arrowItemHtmlElement;s==="ArrowLeft"&&!u.isClosed&&u.isGroup&&(b.dispatchEvent(new Event("mousedown")),t.preventDefault()),s==="ArrowRight"&&u.isClosed&&u.isGroup&&(b.dispatchEvent(new Event("mousedown")),t.preventDefault())},Qe=function(e,t){var r;const s=a(this,o,me).call(this);if(!s.length)return;const i="treeselect-list__item--focused";if(e){const u=s.findIndex(P=>P.classList.contains(i));s[u].classList.remove(i);const L=t==="ArrowDown"?u+1:u-1,x=t==="ArrowDown"?0:s.length-1,k=!s[L],w=s[L]??s[x];w.classList.add(i);const S=this.srcElement.getBoundingClientRect(),y=w.getBoundingClientRect();if(k&&t==="ArrowDown"){this.srcElement.scroll(0,0);return}if(k&&t==="ArrowUp"){this.srcElement.scroll(0,this.srcElement.scrollHeight);return}const O=((r=this.listSlotHtmlComponent)==null?void 0:r.clientHeight)??0;if(S.y+S.height<y.y+y.height+O){this.srcElement.scroll(0,this.srcElement.scrollTop+y.height);return}if(S.y>y.y){this.srcElement.scroll(0,this.srcElement.scrollTop-y.height);return}}else{const[u]=s;u.classList.add(i)}},et=function(){const e=a(this,o,tt).call(this),t=a(this,o,de).call(this,this.options);e.append(...t);const s=a(this,o,nt).call(this);e.append(s);const i=a(this,o,lt).call(this);return i&&e.append(i),e},tt=function(){const e=document.createElement("div");return e.classList.add("treeselect-list"),this.listClassName.length>0&&e.classList.add(this.listClassName),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,o,st).call(this,t)),e.addEventListener("mousemove",()=>a(this,o,it).call(this)),e.addEventListener("mouseup",()=>this.mouseupCallback(),!0),this.isBoostedRendering&&(this.intersectionItemsObserver=Kt(e)),e},st=function(e){e.stopPropagation(),n(this,M)&&n(this,B)&&n(this,M).classList.add("treeselect-list__item--focused")},it=function(){E(this,B,!0)},de=function(e){return e.reduce((t,s)=>{var r;if((r=s.children)!=null&&r.length){const u=a(this,o,at).call(this,s),b=a(this,o,de).call(this,s.children);return u.append(...b),t.push(u),t}const i=a(this,o,ue).call(this,s,!1);return t.push(i),t},[])},lt=function(){if(!this.listSlotHtmlComponent)return null;const e=document.createElement("div");return e.classList.add("treeselect-list__slot"),e.appendChild(this.listSlotHtmlComponent),e},nt=function(){const e=document.createElement("div");e.classList.add("treeselect-list__empty"),e.setAttribute("title",this.emptyText);const t=document.createElement("span");t.classList.add("treeselect-list__empty-icon"),m(this.iconElements.attention,t);const s=document.createElement("span");return s.classList.add("treeselect-list__empty-text"),s.textContent=this.emptyText,e.append(t,s),this.emptyListHtmlElement=e,e},at=function(e){const t=document.createElement("div");t.setAttribute("group-container-id",e.value.toString()),t.classList.add("treeselect-list__group-container");const s=a(this,o,ue).call(this,e,!0);return t.appendChild(s),t},ue=function(e,t){const s=a(this,o,rt).call(this,e);if(t){const u=a(this,o,dt).call(this,e);s.appendChild(u),s.classList.add("treeselect-list__item--group")}const i=a(this,o,mt).call(this,e),r=a(this,o,pt).call(this,e,t);return s.append(i,r),s},rt=function(e){const t=document.createElement("div");t.setAttribute("tabindex","-1"),t.setAttribute("title",e.name),Qt(t,e.htmlAttr),t.classList.add("treeselect-list__item"),t.addEventListener("mouseover",()=>a(this,o,ct).call(this,t),!0),t.addEventListener("mouseout",()=>a(this,o,ot).call(this,t),!0),t.addEventListener("mousedown",i=>a(this,o,ht).call(this,i,e)),this.intersectionItemsObserver&&this.intersectionItemsObserver.observe(t);const s=this.optionsTreeMap.get(e.value);return s&&(s.itemHtmlElement=t),t},ct=function(e){n(this,B)&&a(this,o,pe).call(this,!0,e)},ot=function(e){n(this,B)&&(a(this,o,pe).call(this,!1,e),E(this,M,e))},ht=function(e,t){e.preventDefault(),e.stopPropagation();const s=this.optionsTreeMap.get(t.value)??null;if(s!=null&&s.disabled)return;const i=s==null?void 0:s.checkboxHtmlElement;i&&(i.checked=!i.checked,a(this,o,gt).call(this,i,t))},dt=function(e){const t=document.createElement("span");t.setAttribute("tabindex","-1"),t.classList.add("treeselect-list__item-icon"),m(this.iconElements.arrowDown,t),t.addEventListener("mousedown",i=>a(this,o,ut).call(this,i,e));const s=this.optionsTreeMap.get(e.value);return s&&(s.arrowItemHtmlElement=t),t},ut=function(e,t){e.preventDefault(),e.stopPropagation(),a(this,o,bt).call(this,t)},mt=function(e){const t=document.createElement("div");t.classList.add("treeselect-list__item-checkbox-container");const s=document.createElement("span");s.classList.add("treeselect-list__item-checkbox-icon"),s.innerHTML="";const i=document.createElement("input");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);const r=this.optionsTreeMap.get(e.value);return r&&(r.checkboxHtmlElement=i,r.checkboxIconHtmlElement=s),t},pt=function(e,t){const s=document.createElement("label");if(s.textContent=e.name,s.classList.add("treeselect-list__item-label"),t&&this.showCount){const i=a(this,o,ft).call(this,e);s.appendChild(i)}return s},ft=function(e){var i;const t=document.createElement("span"),s=((i=this.optionsTreeMap.get(e.value))==null?void 0:i.children)??[];return t.textContent=`(${s.length})`,t.classList.add("treeselect-list__item-label-counter"),t},me=function(){const e=[];return this.optionsTreeMap.forEach(t=>{!t.hidden&&t.itemHtmlElement&&e.push(t.itemHtmlElement)}),e},gt=function(e,t){const s=this.optionsTreeMap.get(t.value)??null;if(s===null)return;const i=s.isGroupSelectable??!0;if(s.isGroup&&(this.disabledBranchNode||!i)){const r=s.arrowItemHtmlElement;r==null||r.dispatchEvent(new Event("mousedown"));return}if(this.isSingleSelect){const[r]=n(this,F);if(s.id===r)return;E(this,F,[s.id]),Le({newValue:[s.id],optionsTreeMap:this.optionsTreeMap,isSingleSelect:this.isSingleSelect,isIndependentNodes:this.isIndependentNodes})}else{s.checked=e.checked;const r=le({option:s,optionsTreeMap:this.optionsTreeMap,isIndependentNodes:this.isIndependentNodes});e.checked=r}a(this,o,J).call(this),a(this,o,Ct).call(this)},bt=function(e){const t=this.optionsTreeMap.get(e.value)??null;t!==null&&(t.isClosed=!t.isClosed,z(this.optionsTreeMap,t),a(this,o,J).call(this),this.arrowClickCallback(t.id,t.isClosed))},pe=function(e,t){const s="treeselect-list__item--focused";if(e){const i=Array.from(this.srcElement.querySelectorAll(`.${s}`));i.length&&i.forEach(r=>r.classList.remove(s)),t.classList.add(s)}else t.classList.remove(s)},te=function(e){return this.tagsSortFn===null?e:[...e].sort((t,s)=>this.tagsSortFn({value:t.id,name:t.name},{value:s.id,name:s.name}))},fe=function(){const{ungroupedNodes:e,groupedNodes:t,allNodes:s}=$t(this.optionsTreeMap);this.selectedNodes={nodes:a(this,o,te).call(this,e),groupedNodes:a(this,o,te).call(this,t),allNodes:a(this,o,te).call(this,s)}},Ct=function(){a(this,o,fe).call(this),this.inputCallback(this.selectedNodes),this.value=this.selectedNodes.nodes.map(e=>e.id)};const Ne=({parentHtmlContainer:l,staticList:e,appendToBody:t,isSingleSelect:s,value:i,direction:r})=>{l||console.error("Validation: parentHtmlContainer prop is required!"),e&&t&&console.error("Validation: You should set staticList to false if you use appendToBody!"),s&&Array.isArray(i)&&console.error("Validation: if you use isSingleSelect prop, you should pass a single value!"),!s&&!Array.isArray(i)&&console.error("Validation: you should pass an array as a value!"),r&&r!=="auto"&&r!=="bottom"&&r!=="top"&&console.error("Validation: you should pass (auto | top | bottom | undefined) as a value for the direction prop!")},ee=l=>l.map(e=>e.id),os=l=>l==null?[]:Array.isArray(l)?l:[l],hs=(l,e)=>{if(e){const[t]=l;return t??null}return l};class ds{constructor({parentHtmlContainer:e,value:t,options:s,openLevel:i,appendToBody:r,alwaysOpen:u,showTags:b,tagsCountText:L,tagsSortFn:x,clearable:k,searchable:w,placeholder:S,grouped:y,isGroupedValue:O,listSlotHtmlComponent:P,disabled:D,emptyText:K,staticList:W,id:re,ariaLabel:ce,isSingleSelect:_e,showCount:us,disabledBranchNode:ms,direction:ps,expandSelected:fs,saveScrollPosition:gs,isIndependentNodes:bs,rtl:Cs,listClassName:Es,isBoostedRendering:vs,iconElements:ws,inputCallback:ks,openCallback:Ls,closeCallback:Ss,nameChangeCallback:xs,searchCallback:ys,openCloseGroupCallback:Ts}){C(this,h);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,"tagsSortFn");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,"listClassName");c(this,"isBoostedRendering");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");C(this,p,null);C(this,g,null);C(this,$,null);C(this,q,0);C(this,j,0);C(this,N,null);C(this,_,null);C(this,I,null);C(this,V,null);Ne({parentHtmlContainer:e,value:t,staticList:W,appendToBody:r,isSingleSelect:_e}),this.parentHtmlContainer=e,this.value=[],this.options=s??[],this.openLevel=i??0,this.appendToBody=r??!1,this.alwaysOpen=!!(u&&!D),this.showTags=b??!0,this.tagsCountText=L??"elements selected",this.tagsSortFn=x??null,this.clearable=k??!0,this.searchable=w??!0,this.placeholder=S??"Search...",this.grouped=y??!0,this.isGroupedValue=O??!1,this.listSlotHtmlComponent=P??null,this.disabled=D??!1,this.emptyText=K??"No results found...",this.staticList=!!(W&&!this.appendToBody),this.id=re??"",this.ariaLabel=ce??"",this.isSingleSelect=_e??!1,this.showCount=us??!1,this.disabledBranchNode=ms??!1,this.direction=ps??"auto",this.expandSelected=fs??!1,this.saveScrollPosition=gs??!0,this.isIndependentNodes=bs??!1,this.rtl=Cs??!1,this.listClassName=Es??"",this.isBoostedRendering=vs??!1,this.iconElements=v(ws),this.inputCallback=ks,this.openCallback=Ls,this.closeCallback=Ss,this.nameChangeCallback=xs,this.searchCallback=ys,this.openCloseGroupCallback=Ts,this.ungroupedValue=[],this.groupedValue=[],this.allValue=[],this.isListOpened=!1,this.selectedName="",this.srcElement=null,a(this,h,ge).call(this,t)}mount(){Ne({parentHtmlContainer:this.parentHtmlContainer,value:this.value,staticList:this.staticList,appendToBody:this.appendToBody,isSingleSelect:this.isSingleSelect}),this.iconElements=v(this.iconElements),a(this,h,ge).call(this,this.value)}updateValue(e){const t=os(e),s=n(this,p);s&&(s.updateValue(t),a(this,h,Ce).call(this,s==null?void 0:s.selectedNodes))}destroy(){var e;this.srcElement&&(a(this,h,Ee).call(this),this.srcElement.innerHTML="",this.srcElement=null,a(this,h,ie).call(this,!0),(e=n(this,p))==null||e.destroy())}focus(){n(this,g)&&n(this,g).focus()}toggleOpenClose(){n(this,g)&&(n(this,g).openClose(),n(this,g).focus())}scrollWindowHandler(){this.updateListPosition()}focusWindowHandler(e){var s,i,r;((s=this.srcElement)==null?void 0:s.contains(e.target))||((i=n(this,p))==null?void 0:i.srcElement.contains(e.target))||((r=n(this,g))==null||r.blur(),a(this,h,ie).call(this,!1),a(this,h,se).call(this,!1))}blurWindowHandler(){var e;(e=n(this,g))==null||e.blur(),a(this,h,ie).call(this,!1),a(this,h,se).call(this,!1)}updateListPosition(){var O;const e=this.srcElement,t=(O=n(this,p))==null?void 0:O.srcElement;if(!e||!t)return;if(this.staticList){t.setAttribute("direction","bottom"),a(this,h,ve).call(this,!1,this.appendToBody);return}const{height:s}=t.getBoundingClientRect(),{x:i,y:r,height:u,width:b}=e.getBoundingClientRect(),L=window.innerHeight,x=r,k=L-r-u;let w=x>k&&x>=s&&k<s;if(this.direction!=="auto"&&(w=this.direction==="top"),this.appendToBody){(t.style.top!=="0px"||t.style.left!=="0px")&&(t.style.top="0px",t.style.left="0px");const P=i+window.scrollX,D=w?r+window.scrollY-s:r+window.scrollY+u;t.style.transform=`translate(${P}px,${D}px)`,t.style.width=`${b}px`}const S=w?"top":"bottom";t.getAttribute("direction")!==S&&(t.setAttribute("direction",S),a(this,h,ve).call(this,w,this.appendToBody))}}return p=new WeakMap,g=new WeakMap,$=new WeakMap,q=new WeakMap,j=new WeakMap,N=new WeakMap,_=new WeakMap,I=new WeakMap,V=new WeakMap,h=new WeakSet,ge=function(e){var r;this.destroy();const{container:t,list:s,input:i}=a(this,h,Et).call(this);this.srcElement=t,E(this,p,s),E(this,g,i),E(this,N,this.scrollWindowHandler.bind(this)),E(this,_,this.scrollWindowHandler.bind(this)),E(this,I,this.focusWindowHandler.bind(this)),E(this,V,this.blurWindowHandler.bind(this)),this.alwaysOpen&&((r=n(this,g))==null||r.openClose()),this.disabled?this.srcElement.classList.add("treeselect--disabled"):this.srcElement.classList.remove("treeselect--disabled"),this.updateValue(e??this.value)},be=function({groupedNodes:e,nodes:t,allNodes:s}){this.ungroupedValue=t?ee(t):[],this.groupedValue=e?ee(e):[],this.allValue=s?ee(s):[];let i=[];this.isIndependentNodes||this.isSingleSelect?i=this.allValue:this.isGroupedValue?i=this.groupedValue:i=this.ungroupedValue,this.value=hs(i,this.isSingleSelect)},Et=function(){const e=this.parentHtmlContainer;e.classList.add("treeselect");const t=new cs({value:[],options:this.options,openLevel:this.openLevel,listSlotHtmlComponent:this.listSlotHtmlComponent,tagsSortFn:this.tagsSortFn,emptyText:this.emptyText,isSingleSelect:this.isSingleSelect,showCount:this.showCount,disabledBranchNode:this.disabledBranchNode,expandSelected:this.expandSelected,isIndependentNodes:this.isIndependentNodes,rtl:this.rtl,listClassName:this.listClassName,isBoostedRendering:this.isBoostedRendering,iconElements:this.iconElements,inputCallback:i=>a(this,h,xt).call(this,i),arrowClickCallback:(i,r)=>a(this,h,yt).call(this,i,r),mouseupCallback:()=>{var i;return(i=n(this,g))==null?void 0:i.focus()}}),s=new Bt({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,h,vt).call(this,i),searchCallback:i=>a(this,h,kt).call(this,i),openCallback:()=>a(this,h,At).call(this),closeCallback:()=>a(this,h,Ee).call(this),keydownCallback:i=>a(this,h,wt).call(this,i),focusCallback:()=>a(this,h,Lt).call(this),blurCallback:()=>a(this,h,St).call(this),nameChangeCallback:i=>a(this,h,Tt).call(this,i)});return this.rtl&&(e.setAttribute("dir","rtl"),t.srcElement.setAttribute("dir","rtl")),this.appendToBody&&E(this,$,new ResizeObserver(()=>this.updateListPosition())),e.append(s.srcElement),{container:e,list:t,input:s}},vt=function(e){var i,r;const t=ee(e);(i=n(this,p))==null||i.updateValue(t);const s=((r=n(this,p))==null?void 0:r.selectedNodes)??{};a(this,h,be).call(this,s),a(this,h,ke).call(this)},wt=function(e){var t;this.isListOpened&&((t=n(this,p))==null||t.callKeyAction(e))},kt=function(e){n(this,j)&&clearTimeout(n(this,j)),E(this,j,window.setTimeout(()=>{var t;(t=n(this,p))==null||t.updateSearchValue(e),this.updateListPosition()},350)),a(this,h,Ht).call(this,e)},Lt=function(){a(this,h,se).call(this,!0),n(this,I)&&n(this,I)&&n(this,V)&&(document.addEventListener("mousedown",n(this,I),!0),document.addEventListener("focus",n(this,I),!0),window.addEventListener("blur",n(this,V)))},St=function(){setTimeout(()=>{var s,i;const e=(s=n(this,g))==null?void 0:s.srcElement.contains(document.activeElement),t=(i=n(this,p))==null?void 0:i.srcElement.contains(document.activeElement);!e&&!t&&this.blurWindowHandler()},1)},Ce=function(e){var s;if(!e)return;let t=[];this.isIndependentNodes||this.isSingleSelect?t=e.allNodes:this.grouped?t=e.groupedNodes:t=e.nodes,(s=n(this,g))==null||s.updateValue(t),a(this,h,be).call(this,e)},xt=function(e){var t,s,i;a(this,h,Ce).call(this,e),this.isSingleSelect&&!this.alwaysOpen&&((t=n(this,g))==null||t.openClose(),(s=n(this,g))==null||s.clearSearch()),(i=n(this,g))==null||i.focus(),a(this,h,ke).call(this)},yt=function(e,t){var s;(s=n(this,g))==null||s.focus(),this.updateListPosition(),a(this,h,Pt).call(this,e,t)},Tt=function(e){this.selectedName!==e&&(this.selectedName=e,a(this,h,Nt).call(this))},At=function(){var e;this.isListOpened=!0,n(this,N)&&n(this,_)&&(window.addEventListener("scroll",n(this,N),!0),window.addEventListener("resize",n(this,_))),!(!n(this,p)||!this.srcElement)&&(this.appendToBody?(document.body.appendChild(n(this,p).srcElement),(e=n(this,$))==null||e.observe(this.srcElement)):this.srcElement.appendChild(n(this,p).srcElement),this.updateListPosition(),a(this,h,we).call(this,!0),a(this,h,It).call(this),a(this,h,_t).call(this))},Ee=function(){var t;this.alwaysOpen||(this.isListOpened=!1,n(this,N)&&n(this,_)&&(window.removeEventListener("scroll",n(this,N),!0),window.removeEventListener("resize",n(this,_))),!n(this,p)||!this.srcElement)||!(this.appendToBody?document.body.contains(n(this,p).srcElement):this.srcElement.contains(n(this,p).srcElement))||(E(this,q,n(this,p).srcElement.scrollTop),this.appendToBody?(document.body.removeChild(n(this,p).srcElement),(t=n(this,$))==null||t.disconnect()):this.srcElement.removeChild(n(this,p).srcElement),a(this,h,we).call(this,!1),a(this,h,Ot).call(this))},ve=function(e,t){if(!n(this,p)||!n(this,g))return;const s=t?"treeselect-list--top-to-body":"treeselect-list--top",i=t?"treeselect-list--bottom-to-body":"treeselect-list--bottom";e?(n(this,p).srcElement.classList.add(s),n(this,p).srcElement.classList.remove(i),n(this,g).srcElement.classList.add("treeselect-input--top"),n(this,g).srcElement.classList.remove("treeselect-input--bottom")):(n(this,p).srcElement.classList.remove(s),n(this,p).srcElement.classList.add(i),n(this,g).srcElement.classList.remove("treeselect-input--top"),n(this,g).srcElement.classList.add("treeselect-input--bottom"))},se=function(e){!n(this,g)||!n(this,p)||(e?(n(this,g).srcElement.classList.add("treeselect-input--focused"),n(this,p).srcElement.classList.add("treeselect-list--focused")):(n(this,g).srcElement.classList.remove("treeselect-input--focused"),n(this,p).srcElement.classList.remove("treeselect-list--focused")))},we=function(e){var t,s,i,r;e?(t=n(this,g))==null||t.srcElement.classList.add("treeselect-input--opened"):(s=n(this,g))==null||s.srcElement.classList.remove("treeselect-input--opened"),this.staticList?(i=n(this,p))==null||i.srcElement.classList.add("treeselect-list--static"):(r=n(this,p))==null||r.srcElement.classList.remove("treeselect-list--static")},ie=function(e){!n(this,N)||!n(this,_)||!n(this,I)||!n(this,V)||((!this.alwaysOpen||e)&&(window.removeEventListener("scroll",n(this,N),!0),window.removeEventListener("resize",n(this,_))),document.removeEventListener("mousedown",n(this,I),!0),document.removeEventListener("focus",n(this,I),!0),window.removeEventListener("blur",n(this,V)))},It=function(){var t,s,i;const e=(t=n(this,p))==null?void 0:t.isLastFocusedElementExist();this.saveScrollPosition&&e?(s=n(this,p))==null||s.srcElement.scroll(0,n(this,q)):(i=n(this,p))==null||i.focusFirstListElement()},ke=function(){var e;(e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("input",{detail:this.value})),this.inputCallback&&this.inputCallback(this.value)},Nt=function(){var e;(e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("name-change",{detail:this.selectedName})),this.nameChangeCallback&&this.nameChangeCallback(this.selectedName)},_t=function(){var e;this.alwaysOpen||((e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("open",{detail:this.value})),this.openCallback&&this.openCallback(this.value))},Ot=function(){var e;this.alwaysOpen||((e=this.srcElement)==null||e.dispatchEvent(new CustomEvent("close",{detail:this.value})),this.closeCallback&&this.closeCallback(this.value))},Ht=function(e){var s;const t=(e==null?void 0:e.trim())??"";(s=this.srcElement)==null||s.dispatchEvent(new CustomEvent("search",{detail:t})),this.searchCallback&&this.searchCallback(t)},Pt=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)},ds});