treeselectjs 0.3.5 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -8
- package/dist/treeselectjs.cjs.js +1 -0
- package/dist/treeselectjs.css +1 -0
- package/dist/{treeselect-js.d.ts → treeselectjs.d.ts} +17 -11
- package/dist/treeselectjs.mjs.js +1 -0
- package/package.json +10 -9
- package/dist/treeselect-js.cjs.js +0 -1
- package/dist/treeselect-js.css +0 -1
- package/dist/treeselect-js.mjs.js +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ const { Treeselect } = require('treeselectjs')
|
|
|
24
24
|
```
|
|
25
25
|
Import css file with styles
|
|
26
26
|
```
|
|
27
|
-
@import 'treeselectjs/dist/
|
|
27
|
+
@import 'treeselectjs/dist/treeselectjs.css'
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
Example
|
|
@@ -41,14 +41,14 @@ const options = [
|
|
|
41
41
|
value: 'London',
|
|
42
42
|
children: [
|
|
43
43
|
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
name: 'Chelsea',
|
|
45
|
+
value: 'Chelsea',
|
|
46
|
+
children: []
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
name: 'West End',
|
|
50
|
+
value: 'West End',
|
|
51
|
+
children: []
|
|
52
52
|
}
|
|
53
53
|
]
|
|
54
54
|
},
|
|
@@ -110,6 +110,7 @@ Name | Type (default) | Description
|
|
|
110
110
|
**alwaysOpen** | Boolean (false) | List will be always opened. You can use it for comfortable style changing. If you what to use it as an opened list, turn `staticList` to `true`.
|
|
111
111
|
**showTags** | Boolean (true) | Selected values look like tags. The false value shows results as '{count} elements selected'. You can change text if you use `tagsCountText` prop. For one selected element, you will see a name of this element.
|
|
112
112
|
**tagsCountText** | String ('elements selected') | This text will be shown if you use 'showTags'. This text will be inserted after the count of the selected elements - ```'{count} {tagsCountText}'```.
|
|
113
|
+
**showCount** | Boolean (false) | Shows count of children near the group's name.
|
|
113
114
|
**clearable** | Boolean (true) | Clear icon is available.
|
|
114
115
|
**searchable** | Boolean (true) | Search is available.
|
|
115
116
|
**placeholder** | String ('Search...') | Placeholder text.
|
|
@@ -119,6 +120,7 @@ Name | Type (default) | Description
|
|
|
119
120
|
**emptyText** | String ('No results found...') | A empty list text.
|
|
120
121
|
**staticList** | Boolean (false) | Add the list as a static DOM element. List doesn't overlap content. This prop will be ignored if you use `appendToBody`.
|
|
121
122
|
**id** | String ('') | id attribute for the accessibility.
|
|
123
|
+
**isSingleSelect** | Boolean (false) | Converts multi-select to the single value select. Checkboxes will be removed. You should pass only one id instead of array of values. Also you can set **showTags** to false. It helps to show treeselect as a dropdown.
|
|
122
124
|
**iconElements** | Object({ arrowUp, ... }) | Object contains all svg icons. You can use HTMLElement or a String to reset values from the default Object. Object: ```iconElements: { arrowUp, arrowDown, arrowRight, attention, clear, cross, check, partialCheck }```. After reset of icon you have to update styles if it is necessary, use `alwaysOpen` prop for more comfortable work with styles changes.
|
|
123
125
|
**inputCallback** | (value) => void (undefined) | Callback method for `input` if you don't what use eventListener.
|
|
124
126
|
|
|
@@ -142,4 +144,6 @@ Name | Params | Description
|
|
|
142
144
|
3) Use **updateValue()** method to update only the value.
|
|
143
145
|
4) If you need to delete List from the DOM when you don't need treeselect anymore - call **destroy()**.
|
|
144
146
|
5) Do not use **duplicated** values for the options. You will see a error with duplicated values.
|
|
145
|
-
6) **Value** prop inside the **options** prop should be a **String** or **Number**.
|
|
147
|
+
6) **Value** prop inside the **options** prop should be a **String** or **Number**.
|
|
148
|
+
7) If you use **isSingleSelect** prop, you should pass only a single **id** as a value.
|
|
149
|
+
8) If you use **isSingleSelect** prop, you can set **showTags** to false. It helps to show treeselect as a dropdown.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t,e,s,i){Object.defineProperty(t,e,{get:s,set:i,enumerable:!0,configurable:!0})}t(module.exports,"Treeselect",(function(){return oe}),(function(t){return oe=t}));var e={};t(e,"TreeselectInput",(function(){return W}),(function(t){return W=t}));const s={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>'},i=(t,e)=>{if(e.innerHTML="","string"==typeof t)e.innerHTML=t;else{const s=t.cloneNode(!0);e.appendChild(s)}},l=t=>{const e=t?Object.assign({},t):{};return Object.keys(s).forEach((t=>{e[t]||(e[t]=s[t])})),e};var n,o,a,c,r,h,d,u,p,m,f,v,w,g,E,k,b,y,L,C,_,x,T,S,O,A,H,P,B=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},M=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};class W{focus(){setTimeout((()=>B(this,a,"f").focus()),0)}blur(){this.isOpened&&B(this,n,"m",f).call(this),this.clearSearch(),B(this,a,"f").blur()}updateValue(t){this.value=t,B(this,n,"m",d).call(this),B(this,n,"m",m).call(this)}removeItem(t){this.value=this.value.filter((e=>e.id!==t)),B(this,n,"m",P).call(this),B(this,n,"m",d).call(this),B(this,n,"m",m).call(this)}clear(){this.value=[],B(this,n,"m",P).call(this),B(this,n,"m",d).call(this),this.clearSearch()}openClose(){B(this,n,"m",f).call(this)}clearSearch(){this.searchText="",this.searchCallback(""),B(this,n,"m",m).call(this)}constructor({value:t,showTags:e,tagsCountText:s,clearable:i,isAlwaysOpened:l,searchable:d,placeholder:u,disabled:p,id:m,iconElements:f,inputCallback:w,searchCallback:E,openCallback:k,closeCallback:b,keydownCallback:y,focusCallback:L}){n.add(this),o.set(this,void 0),a.set(this,void 0),c.set(this,void 0),r.set(this,void 0),this.value=t,this.showTags=e,this.tagsCountText=s,this.searchable=d,this.placeholder=u,this.clearable=i,this.isAlwaysOpened=l,this.disabled=p,this.id=m,this.iconElements=f,this.isOpened=!1,this.searchText="",M(this,o,B(this,n,"m",g).call(this),"f"),M(this,a,B(this,n,"m",C).call(this),"f"),M(this,c,B(this,n,"m",T).call(this),"f"),M(this,r,null,"f"),this.inputCallback=w,this.searchCallback=E,this.openCallback=k,this.closeCallback=b,this.keydownCallback=y,this.focusCallback=L,this.srcElement=B(this,n,"m",v).call(this,B(this,o,"f"),B(this,a,"f"),B(this,c,"f")),B(this,n,"m",h).call(this)}}o=new WeakMap,a=new WeakMap,c=new WeakMap,r=new WeakMap,n=new WeakSet,h=function(){B(this,n,"m",d).call(this),B(this,n,"m",m).call(this),B(this,n,"m",u).call(this)},d=function(){B(this,o,"f").innerHTML="",this.showTags?B(this,o,"f").append(...B(this,n,"m",E).call(this)):B(this,o,"f").appendChild(B(this,n,"m",L).call(this)),B(this,o,"f").appendChild(B(this,a,"f"))},u=function(){const t=[];B(this,c,"f").innerHTML="",this.clearable&&t.push(B(this,n,"m",S).call(this)),this.isAlwaysOpened||t.push(B(this,n,"m",A).call(this,this.isOpened)),t.length&&B(this,c,"f").append(...t)},p=function(){if(!this.isAlwaysOpened&&B(this,r,"f")){const t=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;i(t,B(this,r,"f"))}},m=function(){var t;(null===(t=this.value)||void 0===t?void 0:t.length)?(B(this,a,"f").removeAttribute("placeholder"),this.srcElement.classList.remove("treeselect-input--value-not-selected")):(B(this,a,"f").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"),B(this,a,"f").value=this.searchText},f=function(){this.isOpened=!this.isOpened,B(this,n,"m",p).call(this),this.isOpened?this.openCallback():this.closeCallback()},v=function(t,e,s){const i=document.createElement("div");return i.classList.add("treeselect-input"),i.setAttribute("tabindex","-1"),i.addEventListener("mousedown",(t=>B(this,n,"m",w).call(this,t))),i.addEventListener("focus",(()=>this.focusCallback()),!0),t.appendChild(e),i.append(t,s),i},w=function(t){t.preventDefault(),t.stopPropagation(),this.isOpened||B(this,n,"m",f).call(this),this.focus()},g=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__tags"),t},E=function(){return this.value.map((t=>{const e=document.createElement("div");e.classList.add("treeselect-input__tags-element"),e.setAttribute("tabindex","-1"),e.setAttribute("tag-id",t.id.toString()),e.setAttribute("title",t.name);const s=B(this,n,"m",b).call(this,t.name),i=B(this,n,"m",y).call(this);return e.addEventListener("mousedown",(e=>B(this,n,"m",k).call(this,e,t.id))),e.append(s,i),e}))},k=function(t,e){t.preventDefault(),t.stopPropagation(),this.removeItem(e),this.focus()},b=function(t){const e=document.createElement("span");return e.classList.add("treeselect-input__tags-name"),e.innerHTML=t,e},y=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-cross"),i(this.iconElements.cross,t),t},L=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-count"),this.value.length?(t.innerHTML=1===this.value.length?this.value[0].name:`${this.value.length} ${this.tagsCountText}`,t):(t.innerHTML="",t)},C=function(){const t=document.createElement("input");return t.classList.add("treeselect-input__edit"),t.setAttribute("id",this.id),this.disabled&&t.setAttribute("tabindex","-1"),t.addEventListener("keydown",(t=>B(this,n,"m",_).call(this,t))),t.addEventListener("input",(e=>B(this,n,"m",x).call(this,e,t))),t},_=function(t){t.stopPropagation(),"Backspace"!==t.key||this.searchText.length||!this.value.length||this.showTags||this.clear(),"Backspace"===t.key&&!this.searchText.length&&this.value.length&&this.removeItem(this.value[this.value.length-1].id),"Space"!==t.code||this.searchText&&this.searchable||B(this,n,"m",f).call(this),"Enter"===t.key&&t.preventDefault(),this.keydownCallback(t.key),this.focus()},x=function(t,e){t.stopPropagation();const s=this.searchText,i=e.value.trim();if(0!==s.length||0!==i.length){if(this.searchable){const e=t.target.value;this.searchCallback(e),this.isOpened||B(this,n,"m",f).call(this)}else e.value="";this.searchText=e.value}else e.value=""},T=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__operators"),t},S=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__clear"),t.setAttribute("tabindex","-1"),i(this.iconElements.clear,t),t.addEventListener("mousedown",(t=>B(this,n,"m",O).call(this,t))),t},O=function(t){t.preventDefault(),t.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},A=function(t){M(this,r,document.createElement("span"),"f"),B(this,r,"f").classList.add("treeselect-input__arrow");const e=t?this.iconElements.arrowUp:this.iconElements.arrowDown;return i(e,B(this,r,"f")),B(this,r,"f").addEventListener("mousedown",(t=>B(this,n,"m",H).call(this,t))),B(this,r,"f")},H=function(t){t.stopPropagation(),t.preventDefault(),this.focus(),B(this,n,"m",f).call(this)},P=function(){this.inputCallback(this.value)};var G={};t(G,"TreeselectList",(function(){return Bt}),(function(t){return Bt=t}));const N=(t,e,s="",i=0)=>t.reduce(((t,l)=>{var n;const o=!!(null===(n=l.children)||void 0===n?void 0:n.length),a=i>=e&&o,c=i>e;if(t.push({id:l.value,name:l.name,childOf:s,isGroup:o,checked:!1,isPartialChecked:!1,level:i,isClosed:a,hidden:c}),o){const s=N(l.children,e,l.value,i+1);t.push(...s)}return t}),[]),j=({id:t,checked:e},s)=>{s.forEach((i=>{i.childOf===t&&(i.checked=null==e||e,i.isPartialChecked=!1,i.isGroup&&j(i,s))}))},D=(t,e)=>{const s=e.find((e=>e.id===t)),i=e.filter((t=>t.childOf===(null==s?void 0:s.id)));if(!s)return;const l=i.every((t=>t.checked)),n=i.some((t=>t.isPartialChecked||t.checked))&&!l,o=!l&&!n;l&&(s.checked=!0,s.isPartialChecked=!1),n&&(s.checked=!1,s.isPartialChecked=!0),o&&(s.checked=!1,s.isPartialChecked=!1),s.childOf&&D(s.childOf,e)},q=({id:t,isGroup:e,childOf:s,checked:i},l)=>{e&&j({id:t,checked:i},l),s&&D(s,l)},I=(t,e)=>e.reduce(((s,i)=>(i.childOf===t&&(s.push(i),i.isGroup&&s.push(...I(i.id,e))),s)),[]),V=(t,e)=>e.reduce(((s,i)=>(i.id===t&&(s.push(i),i.childOf&&s.push(...V(i.childOf,e))),s)),[]),$=t=>{const{onlyGroupsIds:e,allItems:s}=t.reduce(((t,e)=>e.checked?(e.isGroup&&t.onlyGroupsIds.push(e.id),t.allItems.push(e),t):t),{onlyGroupsIds:[],allItems:[]});return s.filter((t=>!e.some((e=>e===t.childOf))))},R=(t,{id:e,isClosed:s})=>{t.filter((t=>t.childOf===e)).forEach((e=>{e.hidden=null!=s&&s,e.isGroup&&!e.isClosed&&R(t,{id:e.id,isClosed:s})}))},z=(t,e)=>{const s=((t,e)=>t.reduce(((s,i)=>{if(i.name.toLowerCase().includes(e.toLowerCase())){if(s.push(i),i.isGroup){const e=I(i.id,t);s.push(...e)}if(i.childOf){const e=V(i.childOf,t);s.push(...e)}}return s}),[]))(t,e);t.forEach((e=>{s.some((t=>t.id===e.id))?(e.isGroup&&(e.isClosed=!1,R(t,e)),e.hidden=!1):e.hidden=!0}))},U=(t,e)=>{(t=>{t.forEach((t=>{t.checked=!1,t.isPartialChecked=!1}))})(e);e.filter((e=>t.some((t=>t===e.id)))).forEach((t=>{t.checked=!0,t.isPartialChecked=!1,q(t,e)}))};var Y,F,J,K,X,Q,Z,tt,et,st,it,lt,nt,ot,at,ct,rt,ht,dt,ut,pt,mt,ft,vt,wt,gt,Et,kt,bt=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},yt=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const Lt=(t,e,s)=>{t.forEach((i=>{const l=e.querySelector(`[input-id="${i.id}"]`),n=Ht(l);l.checked=i.checked,Ct(i,n),_t(i,n),xt(i,n,s),Tt(i,n),Ot(i,n,t),St(i,l,s)})),At(t,e)},Ct=(t,e)=>{t.checked?e.classList.add("treeselect-list__item--checked"):e.classList.remove("treeselect-list__item--checked")},_t=(t,e)=>{t.isPartialChecked?e.classList.add("treeselect-list__item--partial-checked"):e.classList.remove("treeselect-list__item--partial-checked")},xt=(t,e,s)=>{if(t.isGroup){const l=e.querySelector(".treeselect-list__item-icon"),n=t.isClosed?s.arrowRight:s.arrowDown;i(n,l),t.isClosed?e.classList.add("treeselect-list__item--closed"):e.classList.remove("treeselect-list__item--closed")}},Tt=(t,e)=>{t.hidden?e.classList.add("treeselect-list__item--hidden"):e.classList.remove("treeselect-list__item--hidden")},St=(t,e,s)=>{const l=e.parentNode.querySelector(".treeselect-list__item-checkbox-icon");t.checked?i(s.check,l):t.isPartialChecked?i(s.partialCheck,l):l.innerHTML=""},Ot=(t,e,s)=>{if(0===t.level){const i=s.some((e=>e.isGroup&&e.level===t.level)),l=!t.isGroup&&i?"20px":"5px";e.style.paddingLeft=t.isGroup?"0":l}else e.style.paddingLeft=t.isGroup?20*t.level+"px":20*t.level+20+"px";e.setAttribute("level",t.level.toString()),e.setAttribute("group",t.isGroup.toString())},At=(t,e)=>{const s=t.some((t=>!t.hidden)),i=e.querySelector(".treeselect-list__empty");s?i.classList.add("treeselect-list__empty--hidden"):i.classList.remove("treeselect-list__empty--hidden")},Ht=t=>t.parentNode.parentNode,Pt=(t,e)=>e.find((e=>e.id.toString()===t));class Bt{updateValue(t){var e,s,i,l;this.value=t,e=t,s=this.flattedOptions,i=this.srcElement,l=this.iconElements,U(e,s),Lt(s,i,l),bt(this,Y,"m",Et).call(this)}updateSearchValue(t){if(t===this.searchText)return;const e=""===this.searchText&&""!==t;this.searchText=t,e&&(this.flattedOptionsBeforeSearch=JSON.parse(JSON.stringify(this.flattedOptions))),""===this.searchText&&(this.flattedOptions=this.flattedOptionsBeforeSearch.map((t=>{const e=this.flattedOptions.find((e=>e.id===t.id));return e.isClosed=t.isClosed,e.hidden=t.hidden,e})),this.flattedOptionsBeforeSearch=[]),this.searchText&&z(this.flattedOptions,t),Lt(this.flattedOptions,this.srcElement,this.iconElements),this.focusFirstListElement()}callKeyAction(t){yt(this,J,!1,"f");const e=this.srcElement.querySelector(".treeselect-list__item--focused");"Enter"===t&&e&&e.dispatchEvent(new Event("mousedown")),"ArrowLeft"!==t&&"ArrowRight"!==t||bt(this,Y,"m",K).call(this,e,t),"ArrowDown"!==t&&"ArrowUp"!==t||bt(this,Y,"m",X).call(this,e,t)}focusFirstListElement(){const t="treeselect-list__item--focused",e=this.srcElement.querySelector(`.${t}`),s=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Ht(t)).display));if(!s.length)return;e&&e.classList.remove(t);Ht(s[0]).classList.add(t)}constructor({options:t,value:e,openLevel:s,listSlotHtmlComponent:i,emptyText:l,isSingleSelect:n,iconElements:o,showCount:a,inputCallback:c,arrowClickCallback:r,mouseupCallback:h}){Y.add(this),F.set(this,null),J.set(this,!0),this.options=t,this.value=e,this.openLevel=null!=s?s:0,this.listSlotHtmlComponent=null!=i?i:null,this.emptyText=null!=l?l:"No results found...",this.isSingleSelect=null!=n&&n,this.showCount=null!=a&&a,this.iconElements=o,this.searchText="",this.flattedOptions=N(this.options,this.openLevel),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[]},this.srcElement=bt(this,Y,"m",Q).call(this),this.inputCallback=c,this.arrowClickCallback=r,this.mouseupCallback=h,this.updateValue(this.value),(t=>{const{duplications:e}=t.reduce(((t,e)=>(t.allItems.some((t=>t.toString()===e.id.toString()))&&t.duplications.push(e.id),t.allItems.push(e.id),t)),{duplications:[],allItems:[]});e.length&&console.error(`Validation: You have duplicated values: ${e.join(", ")}! You should use unique values.`)})(this.flattedOptions)}}F=new WeakMap,J=new WeakMap,Y=new WeakSet,K=function(t,e){if(!t)return;const s=t.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),i=Pt(s,this.flattedOptions),l=t.querySelector(".treeselect-list__item-icon");"ArrowLeft"===e&&!i.isClosed&&i.isGroup&&l.dispatchEvent(new Event("mousedown")),"ArrowRight"===e&&i.isClosed&&i.isGroup&&l.dispatchEvent(new Event("mousedown"))},X=function(t,e){var s;const i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Ht(t)).display));if(i.length)if(t){const t=i.findIndex((t=>Ht(t).classList.contains("treeselect-list__item--focused")));Ht(i[t]).classList.remove("treeselect-list__item--focused");const l="ArrowDown"===e?t+1:t-1,n="ArrowDown"===e?0:i.length-1,o=null!==(s=i[l])&&void 0!==s?s:i[n],a=!i[l],c=Ht(o);c.classList.add("treeselect-list__item--focused");const r=this.srcElement.getBoundingClientRect(),h=c.getBoundingClientRect();if(a&&"ArrowDown"===e)return void this.srcElement.scroll(0,0);if(a&&"ArrowUp"===e)return void this.srcElement.scroll(0,this.srcElement.scrollHeight);if(r.y+r.height<h.y+h.height)return void this.srcElement.scroll(0,this.srcElement.scrollTop+h.height);if(r.y>h.y)return void this.srcElement.scroll(0,this.srcElement.scrollTop-h.height)}else{Ht(i[0]).classList.add("treeselect-list__item--focused")}},Q=function(){const t=bt(this,Y,"m",Z).call(this),e=bt(this,Y,"m",st).call(this,this.options);t.append(...e);const s=bt(this,Y,"m",it).call(this);s&&t.append(s);const i=bt(this,Y,"m",lt).call(this);return t.append(i),t},Z=function(){const t=document.createElement("div");return t.classList.add("treeselect-list"),this.isSingleSelect&&t.classList.add("treeselect-list--single-select"),t.addEventListener("mouseout",(t=>bt(this,Y,"m",tt).call(this,t))),t.addEventListener("mousemove",(()=>bt(this,Y,"m",et).call(this))),t.addEventListener("mouseup",(()=>this.mouseupCallback()),!0),t},tt=function(t){t.stopPropagation(),bt(this,F,"f")&&bt(this,J,"f")&&bt(this,F,"f").classList.add("treeselect-list__item--focused")},et=function(){yt(this,J,!0,"f")},st=function t(e){return e.reduce(((e,s)=>{var i;if(null===(i=s.children)||void 0===i?void 0:i.length){const i=bt(this,Y,"m",nt).call(this,s),l=bt(this,Y,"m",t).call(this,s.children);return i.append(...l),e.push(i),e}const l=bt(this,Y,"m",ot).call(this,s,!1);return e.push(l),e}),[])},it=function(){if(!this.listSlotHtmlComponent)return null;const t=document.createElement("div");return t.classList.add("treeselect-list__slot"),t.appendChild(this.listSlotHtmlComponent),t},lt=function(){const t=document.createElement("div");t.classList.add("treeselect-list__empty"),t.setAttribute("title",this.emptyText);const e=document.createElement("span");e.classList.add("treeselect-list__empty-icon"),i(this.iconElements.attention,e);const s=document.createElement("span");return s.classList.add("treeselect-list__empty-text"),s.innerHTML=this.emptyText,t.append(e,s),t},nt=function(t){const e=document.createElement("div");e.setAttribute("group-container-id",t.value.toString()),e.classList.add("treeselect-list__group-container");const s=bt(this,Y,"m",ot).call(this,t,!0);return e.appendChild(s),e},ot=function(t,e){const s=bt(this,Y,"m",at).call(this,t);if(e){const t=bt(this,Y,"m",dt).call(this);s.appendChild(t)}const i=bt(this,Y,"m",pt).call(this,t),l=bt(this,Y,"m",mt).call(this,t,e);return s.append(i,l),s},at=function(t){const e=document.createElement("div");return e.setAttribute("tabindex","-1"),e.setAttribute("title",t.name),e.classList.add("treeselect-list__item"),e.addEventListener("mouseover",(()=>bt(this,Y,"m",ct).call(this,e)),!0),e.addEventListener("mouseout",(()=>bt(this,Y,"m",rt).call(this,e)),!0),e.addEventListener("mousedown",(e=>bt(this,Y,"m",ht).call(this,e,t))),e},ct=function(t){bt(this,J,"f")&&bt(this,Y,"m",gt).call(this,!0,t)},rt=function(t){bt(this,J,"f")&&(bt(this,Y,"m",gt).call(this,!1,t),yt(this,F,t,"f"))},ht=function(t,e){t.preventDefault(),t.stopPropagation();const s=t.target.querySelector(".treeselect-list__item-checkbox");s.checked=!s.checked,bt(this,Y,"m",vt).call(this,s,e)},dt=function(){const t=document.createElement("span");return t.setAttribute("tabindex","-1"),t.classList.add("treeselect-list__item-icon"),i(this.iconElements.arrowDown,t),t.addEventListener("mousedown",(t=>bt(this,Y,"m",ut).call(this,t))),t},ut=function(t){t.preventDefault(),t.stopPropagation(),bt(this,Y,"m",wt).call(this,t)},pt=function(t){const e=document.createElement("div");e.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");return i.setAttribute("tabindex","-1"),i.setAttribute("type","checkbox"),i.setAttribute("input-id",t.value.toString()),i.classList.add("treeselect-list__item-checkbox"),e.append(s,i),e},mt=function(t,e){const s=document.createElement("label");if(s.innerHTML=t.name,s.classList.add("treeselect-list__item-label"),e&&this.showCount){const e=bt(this,Y,"m",ft).call(this,t);s.appendChild(e)}return s},ft=function(t){const e=document.createElement("span"),s=this.flattedOptions.filter((e=>e.childOf===t.value));return e.innerHTML=`(${s.length})`,e.classList.add("treeselect-list__item-label-counter"),e},vt=function(t,e){const s=this.flattedOptions.find((t=>t.id===e.value)),i=(null==s?void 0:s.isGroup)&&this.isSingleSelect;if(s&&!i){if(this.isSingleSelect){const[t]=this.value;if(s.id===t)return;U([s.id],this.flattedOptions)}else s.checked=t.checked,s.isPartialChecked=!1,q(s,this.flattedOptions);Lt(this.flattedOptions,this.srcElement,this.iconElements),bt(this,Y,"m",kt).call(this)}},wt=function(t){var e,s,i;const l=null===(s=null===(e=t.target)||void 0===e?void 0:e.parentNode)||void 0===s?void 0:s.querySelector("[input-id]"),n=null!==(i=null==l?void 0:l.getAttribute("input-id"))&&void 0!==i?i:null,o=Pt(n,this.flattedOptions);o&&(o.isClosed=!o.isClosed,R(this.flattedOptions,o),Lt(this.flattedOptions,this.srcElement,this.iconElements),this.arrowClickCallback())},gt=function(t,e){const s="treeselect-list__item--focused";if(t){const t=Array.from(this.srcElement.querySelectorAll(`.${s}`));t.length&&t.forEach((t=>t.classList.remove(s))),e.classList.add(s)}else e.classList.remove(s)},Et=function(){var t;this.selectedNodes={nodes:(t=this.flattedOptions,t.filter((t=>t.checked&&!t.isGroup))),groupedNodes:$(this.flattedOptions)}},kt=function(){bt(this,Y,"m",Et).call(this),this.inputCallback(this.selectedNodes),this.value=this.selectedNodes.nodes.map((t=>t.id))};var Mt,Wt,Gt,Nt,jt,Dt,qt,It,Vt,$t,Rt,zt,Ut,Yt,Ft,Jt,Kt,Xt,Qt,Zt,te,ee,se=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},ie=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const le=t=>t.map((t=>t.id)),ne=t=>t?Array.isArray(t)?t:[t]:[];class oe{mount(){var t;this.destroy();const{container:e,list:s,input:i}=se(this,Mt,"m",Vt).call(this);this.srcElement=e,ie(this,Wt,s,"f"),ie(this,Gt,i,"f"),ie(this,jt,this.scrollWindowHandler.bind(this),"f"),ie(this,Dt,this.scrollWindowHandler.bind(this),"f"),ie(this,qt,this.focusWindowHandler.bind(this),"f"),ie(this,It,this.blurWindowHandler.bind(this),"f"),this.alwaysOpen&&(null===(t=se(this,Gt,"f"))||void 0===t||t.openClose()),this.disabled&&this.srcElement.classList.add("treeselect--disabled")}updateValue(t){var e;const s=se(this,Wt,"f");if(s){const i=ne(t);s.updateValue(i);const{groupedNodes:l,nodes:n}=s.selectedNodes,o=this.grouped?l:n;null===(e=se(this,Gt,"f"))||void 0===e||e.updateValue(o)}}destroy(){this.srcElement&&(se(this,Mt,"m",Kt).call(this),this.srcElement.innerHTML="",this.srcElement=null,se(this,Mt,"m",te).call(this,!0))}focus(){se(this,Gt,"f")&&se(this,Gt,"f").focus()}toggleOpenClose(){se(this,Gt,"f")&&(se(this,Gt,"f").openClose(),se(this,Gt,"f").focus())}scrollWindowHandler(){this.updateListPosition()}focusWindowHandler(t){var e,s,i;(null===(e=this.srcElement)||void 0===e?void 0:e.contains(t.target))||(null===(s=se(this,Wt,"f"))||void 0===s?void 0:s.srcElement.contains(t.target))||(null===(i=se(this,Gt,"f"))||void 0===i||i.blur(),se(this,Mt,"m",te).call(this,!1),se(this,Mt,"m",Qt).call(this,!1))}blurWindowHandler(){var t;null===(t=se(this,Gt,"f"))||void 0===t||t.blur(),se(this,Mt,"m",te).call(this,!1),se(this,Mt,"m",Qt).call(this,!1)}updateListPosition(){var t;const e=this.srcElement,s=null===(t=se(this,Wt,"f"))||void 0===t?void 0:t.srcElement;if(!e||!s)return;s.style.transform="";const{y:i,height:l}=s.getBoundingClientRect(),{x:n,y:o,height:a,width:c}=e.getBoundingClientRect(),r=window.innerHeight-o-a,h=o>r&&o>=l&&r<l;this.appendToBody&&(s.style.transform=h?`translateY(${o-i-l}px)`:`translateY(${o+a-i}px)`,s.style.width=`${c}px`,s.style.left=`${n+window.scrollX}px`);const d=h?"top":"bottom";s.getAttribute("direction")!==d&&(s.setAttribute("direction",d),se(this,Mt,"m",Xt).call(this,h,this.appendToBody))}constructor({parentHtmlContainer:t,value:e,options:s,openLevel:i,appendToBody:n,alwaysOpen:o,showTags:a,tagsCountText:c,clearable:r,searchable:h,placeholder:d,grouped:u,listSlotHtmlComponent:p,disabled:m,emptyText:f,staticList:v,id:w,isSingleSelect:g,showCount:E,iconElements:k,inputCallback:b}){Mt.add(this),Wt.set(this,null),Gt.set(this,null),Nt.set(this,null),jt.set(this,null),Dt.set(this,null),qt.set(this,null),It.set(this,null),(({parentHtmlContainer:t,staticList:e,appendToBody:s,isSingleSelect:i,value:l})=>{t||console.error("Validation: parentHtmlContainer prop is required!"),e&&s&&console.error("Validation: You should set staticList to false if you use appendToBody!"),i&&Array.isArray(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!")})({parentHtmlContainer:t,value:e,staticList:v,appendToBody:n,isSingleSelect:g}),this.parentHtmlContainer=t,this.value=ne(e),this.options=null!=s?s:[],this.openLevel=null!=i?i:0,this.appendToBody=null==n||n,this.alwaysOpen=!(!o||m),this.showTags=null==a||a,this.tagsCountText=null!=c?c:"elements selected",this.clearable=null==r||r,this.searchable=null==h||h,this.placeholder=null!=d?d:"Search...",this.grouped=null==u||u,this.listSlotHtmlComponent=null!=p?p:null,this.disabled=null!=m&&m,this.emptyText=null!=f?f:"No results found...",this.staticList=!(!v||this.appendToBody),this.id=null!=w?w:"",this.isSingleSelect=null!=g&&g,this.showCount=null!=E&&E,this.iconElements=l(k),this.inputCallback=b,this.isListOpened=!1,this.srcElement=null,this.mount()}}Wt=new WeakMap,Gt=new WeakMap,Nt=new WeakMap,jt=new WeakMap,Dt=new WeakMap,qt=new WeakMap,It=new WeakMap,Mt=new WeakSet,Vt=function(){const t=this.parentHtmlContainer;t.classList.add("treeselect");const s=new(0,G.TreeselectList)({options:this.options,value:this.value,openLevel:this.openLevel,listSlotHtmlComponent:this.listSlotHtmlComponent,emptyText:this.emptyText,isSingleSelect:this.isSingleSelect,showCount:this.showCount,iconElements:this.iconElements,inputCallback:t=>se(this,Mt,"m",Yt).call(this,t),arrowClickCallback:()=>se(this,Mt,"m",Ft).call(this),mouseupCallback:()=>{var t;return null===(t=se(this,Gt,"f"))||void 0===t?void 0:t.focus()}}),{groupedNodes:i,nodes:l}=s.selectedNodes,n=new(0,e.TreeselectInput)({value:this.grouped?i:l,showTags:this.showTags,tagsCountText:this.tagsCountText,clearable:this.clearable,isAlwaysOpened:this.alwaysOpen,searchable:this.searchable,placeholder:this.placeholder,disabled:this.disabled,id:this.id,iconElements:this.iconElements,inputCallback:t=>se(this,Mt,"m",$t).call(this,t),searchCallback:t=>se(this,Mt,"m",zt).call(this,t),openCallback:()=>se(this,Mt,"m",Jt).call(this),closeCallback:()=>se(this,Mt,"m",Kt).call(this),keydownCallback:t=>se(this,Mt,"m",Rt).call(this,t),focusCallback:()=>se(this,Mt,"m",Ut).call(this)});return this.appendToBody&&ie(this,Nt,new ResizeObserver((()=>this.updateListPosition())),"f"),t.append(n.srcElement),{container:t,list:s,input:n}},$t=function(t){var e,s,i;const l=le(t);null===(e=se(this,Wt,"f"))||void 0===e||e.updateValue(l);const n=null===(i=null===(s=se(this,Wt,"f"))||void 0===s?void 0:s.selectedNodes)||void 0===i?void 0:i.nodes;this.value=n?le(n):[],se(this,Mt,"m",ee).call(this)},Rt=function(t){var e;this.isListOpened&&(null===(e=se(this,Wt,"f"))||void 0===e||e.callKeyAction(t))},zt=function(t){var e;null===(e=se(this,Wt,"f"))||void 0===e||e.updateSearchValue(t),this.updateListPosition()},Ut=function(){se(this,Mt,"m",Qt).call(this,!0),se(this,qt,"f")&&se(this,qt,"f")&&se(this,It,"f")&&(document.addEventListener("mousedown",se(this,qt,"f"),!0),document.addEventListener("focus",se(this,qt,"f"),!0),window.addEventListener("blur",se(this,It,"f")))},Yt=function(t){var e,s,i;const{groupedNodes:l,nodes:n}=t,o=this.grouped?l:n;null===(e=se(this,Gt,"f"))||void 0===e||e.updateValue(o),this.value=le(n),this.isSingleSelect&&(null===(s=se(this,Gt,"f"))||void 0===s||s.openClose(),null===(i=se(this,Gt,"f"))||void 0===i||i.clearSearch()),setTimeout((()=>{var t;null===(t=se(this,Gt,"f"))||void 0===t||t.focus()}),0),se(this,Mt,"m",ee).call(this)},Ft=function(){var t;null===(t=se(this,Gt,"f"))||void 0===t||t.focus(),this.updateListPosition()},Jt=function(){var t;this.isListOpened=!0,se(this,jt,"f")&&se(this,Dt,"f")&&(window.addEventListener("scroll",se(this,jt,"f"),!0),window.addEventListener("resize",se(this,Dt,"f"))),se(this,Wt,"f")&&this.srcElement&&(this.appendToBody?(document.body.appendChild(se(this,Wt,"f").srcElement),null===(t=se(this,Nt,"f"))||void 0===t||t.observe(this.srcElement)):this.srcElement.appendChild(se(this,Wt,"f").srcElement),this.updateListPosition(),se(this,Mt,"m",Zt).call(this,!0),se(this,Wt,"f").focusFirstListElement())},Kt=function(){var t;if(this.alwaysOpen)return;if(this.isListOpened=!1,se(this,jt,"f")&&se(this,Dt,"f")&&(window.removeEventListener("scroll",se(this,jt,"f"),!0),window.removeEventListener("resize",se(this,Dt,"f"))),!se(this,Wt,"f")||!this.srcElement)return;(this.appendToBody?document.body.contains(se(this,Wt,"f").srcElement):this.srcElement.contains(se(this,Wt,"f").srcElement))&&(this.appendToBody?(document.body.removeChild(se(this,Wt,"f").srcElement),null===(t=se(this,Nt,"f"))||void 0===t||t.disconnect()):this.srcElement.removeChild(se(this,Wt,"f").srcElement),se(this,Mt,"m",Zt).call(this,!1))},Xt=function(t,e){if(!se(this,Wt,"f")||!se(this,Gt,"f"))return;const s=e?"treeselect-list--top-to-body":"treeselect-list--top",i=e?"treeselect-list--bottom-to-body":"treeselect-list--bottom";t?(se(this,Wt,"f").srcElement.classList.add(s),se(this,Wt,"f").srcElement.classList.remove(i),se(this,Gt,"f").srcElement.classList.add("treeselect-input--top"),se(this,Gt,"f").srcElement.classList.remove("treeselect-input--bottom")):(se(this,Wt,"f").srcElement.classList.remove(s),se(this,Wt,"f").srcElement.classList.add(i),se(this,Gt,"f").srcElement.classList.remove("treeselect-input--top"),se(this,Gt,"f").srcElement.classList.add("treeselect-input--bottom"))},Qt=function(t){se(this,Gt,"f")&&se(this,Wt,"f")&&(t?(se(this,Gt,"f").srcElement.classList.add("treeselect-input--focused"),se(this,Wt,"f").srcElement.classList.add("treeselect-list--focused")):(se(this,Gt,"f").srcElement.classList.remove("treeselect-input--focused"),se(this,Wt,"f").srcElement.classList.remove("treeselect-list--focused")))},Zt=function(t){var e,s,i,l;t?null===(e=se(this,Gt,"f"))||void 0===e||e.srcElement.classList.add("treeselect-input--opened"):null===(s=se(this,Gt,"f"))||void 0===s||s.srcElement.classList.remove("treeselect-input--opened"),this.staticList?null===(i=se(this,Wt,"f"))||void 0===i||i.srcElement.classList.add("treeselect-list--static"):null===(l=se(this,Wt,"f"))||void 0===l||l.srcElement.classList.remove("treeselect-list--static")},te=function(t){se(this,jt,"f")&&se(this,Dt,"f")&&se(this,qt,"f")&&se(this,It,"f")&&(this.alwaysOpen&&!t||(window.removeEventListener("scroll",se(this,jt,"f"),!0),window.removeEventListener("resize",se(this,Dt,"f"))),document.removeEventListener("mousedown",se(this,qt,"f"),!0),document.removeEventListener("focus",se(this,qt,"f"),!0),window.removeEventListener("blur",se(this,It,"f")))},ee=function(){var t;const e=((t,e)=>{if(e){const[e]=t;return e}return t})(this.value,this.isSingleSelect);null===(t=this.srcElement)||void 0===t||t.dispatchEvent(new CustomEvent("input",{detail:e})),this.inputCallback&&this.inputCallback(e)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.treeselect-input{width:100%;box-sizing:border-box;min-height:37px;cursor:text;background-color:#fff;border:1px solid #d7dde4;border-radius:4px;flex-wrap:wrap;align-items:center;padding:2px 40px 2px 4px;display:flex;position:relative}.treeselect-input--unsearchable{cursor:default}.treeselect-input--unsearchable .treeselect-input__edit{caret-color:#0000;cursor:default}.treeselect-input--unsearchable .treeselect-input__edit:focus{z-index:-1;position:absolute}.treeselect-input--value-not-selected.treeselect-input--unsearchable .treeselect-input__edit:focus{z-index:auto;width:auto;position:static}.treeselect-input--value-not-selected .treeselect-input__edit{width:auto;z-index:auto}.treeselect-input--value-not-selected .treeselect-input__tags{gap:0}.treeselect-input__tags{max-width:100%;box-sizing:border-box;flex-wrap:wrap;align-items:center;gap:4px;display:inline-flex}.treeselect-input__tags-element{cursor:pointer;max-width:100%;box-sizing:border-box;background-color:#d7dde4;border-radius:2px;align-items:center;padding:2px 5px;font-size:14px;display:inline-flex}.treeselect-input__tags-element:hover{background-color:#c5c7cb}.treeselect-input__tags-element:hover .treeselect-input__tags-cross svg{stroke:#eb4c42}.treeselect-input__tags-name{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.treeselect-input__tags-cross{margin-left:2px;display:flex}.treeselect-input__tags-cross svg{width:12px;height:12px}.treeselect-input__tags-count{white-space:nowrap;text-overflow:ellipsis;font-size:14px;overflow:hidden}.treeselect-input__edit{width:0;z-index:-1;min-width:0;border:none;flex:1;font-size:14px;position:absolute}.treeselect-input__edit:focus{min-width:30px;z-index:auto;width:auto;outline:none;position:static}.treeselect-input__operators{max-width:40px;display:flex;position:absolute;right:2px}.treeselect-input__clear{cursor:pointer;display:flex}.treeselect-input__clear svg{stroke:#c5c7cb;width:17px;min-width:17px;height:20px}.treeselect-input__clear:hover svg{stroke:#838790}.treeselect-input__arrow{cursor:pointer;display:flex}.treeselect-input__arrow svg{stroke:#c5c7cb;width:20px;min-width:20px;height:20px}.treeselect-input__arrow:hover svg{stroke:#838790}.treeselect-list{width:100%;box-sizing:border-box;max-height:300px;background-color:#fff;border:1px solid #d7dde4;overflow-y:auto}.treeselect-list__group-container{box-sizing:border-box}.treeselect-list__item{box-sizing:border-box;cursor:pointer;height:30px;align-items:center;display:flex}.treeselect-list__item:focus{outline:none}.treeselect-list__item--focused{background-color:azure!important}.treeselect-list__item--hidden{display:none}.treeselect-list__item-icon{cursor:pointer;height:20px;width:20px;min-width:20px;align-items:center;display:flex}.treeselect-list__item-icon svg{pointer-events:none;width:100%;height:100%;stroke:#c5c7cb}.treeselect-list__item-icon *{pointer-events:none}.treeselect-list__item-icon:hover svg{stroke:#838790}.treeselect-list__item-checkbox-container{width:20px;height:20px;min-width:20px;pointer-events:none;box-sizing:border-box;background-color:#fff;border:1px solid #d7dde4;border-radius:3px;position:relative}.treeselect-list__item-checkbox-container svg{height:100%;width:100%;position:absolute}.treeselect-list__item-checkbox{width:0;height:0;pointer-events:none;z-index:-1;margin:0;position:absolute}.treeselect-list__item-checkbox-icon{height:100%;width:100%;position:absolute;top:0;left:0}.treeselect-list__item-label{width:100%;text-overflow:ellipsis;word-break:keep-all;white-space:nowrap;pointer-events:none;padding-left:5px;font-size:14px;overflow:hidden}.treeselect-list__item-label-counter{color:#838790;margin-left:3px;font-size:13px}.treeselect-list__empty{height:30px;align-items:center;padding-left:4px;display:flex}.treeselect-list__empty--hidden{display:none}.treeselect-list__empty-icon{align-items:center;display:flex}.treeselect-list__empty-text{text-overflow:ellipsis;word-break:keep-all;white-space:nowrap;padding-left:5px;font-size:14px;overflow:hidden}.treeselect-list__slot{box-sizing:border-box;width:100%;max-width:100%;background-color:#fff;position:sticky;bottom:0}.treeselect-list.treeselect-list--single-select .treeselect-list__item-checkbox-container{display:none}.treeselect-list__item .treeselect-list__item-checkbox-container svg{stroke:#0000}.treeselect-list__item--checked .treeselect-list__item-checkbox-container svg,.treeselect-list__item--partial-checked .treeselect-list__item-checkbox-container svg{stroke:#fff}.treeselect-list__item--checked .treeselect-list__item-checkbox-container,.treeselect-list__item--partial-checked .treeselect-list__item-checkbox-container{background-color:#52c67e}.treeselect{width:100%;box-sizing:border-box;position:relative}.treeselect--disabled{pointer-events:none}.treeselect-list{box-sizing:border-box;z-index:1000;border-radius:4px;position:absolute;left:0}.treeselect .treeselect-list{position:absolute}.treeselect .treeselect-list--static{position:static}.treeselect-input--focused{border-color:#101010}.treeselect-input--opened.treeselect-input--top{border-top-color:#0000;border-top-left-radius:0;border-top-right-radius:0}.treeselect-input--opened.treeselect-input--bottom{border-bottom-color:#0000;border-bottom-left-radius:0;border-bottom-right-radius:0}.treeselect-list--focused{border-color:#101010}.treeselect-list--top,.treeselect-list--top-to-body{border-bottom-color:#d7dde4;border-bottom-left-radius:0;border-bottom-right-radius:0}.treeselect-list--bottom,.treeselect-list--bottom-to-body{border-top-color:#d7dde4;border-top-left-radius:0;border-top-right-radius:0}.treeselect-list--top{bottom:100%;left:0}.treeselect-list--bottom{top:100%;left:0}
|
|
@@ -4,9 +4,9 @@ type OptionType = {
|
|
|
4
4
|
name: string;
|
|
5
5
|
children: OptionType[];
|
|
6
6
|
};
|
|
7
|
-
interface
|
|
7
|
+
interface ITreeselect {
|
|
8
8
|
parentHtmlContainer: HTMLElement;
|
|
9
|
-
value: ValueOptionType[];
|
|
9
|
+
value: ValueOptionType[] | ValueOptionType;
|
|
10
10
|
options: OptionType[];
|
|
11
11
|
openLevel: number;
|
|
12
12
|
appendToBody: boolean;
|
|
@@ -22,19 +22,21 @@ interface ITreeslect {
|
|
|
22
22
|
emptyText: string;
|
|
23
23
|
staticList: boolean;
|
|
24
24
|
id: string;
|
|
25
|
+
isSingleSelect: boolean;
|
|
26
|
+
showCount: boolean;
|
|
25
27
|
iconElements: IconsType;
|
|
26
28
|
isListOpened: boolean;
|
|
27
29
|
srcElement: HTMLElement | null;
|
|
28
|
-
inputCallback: ((value: ValueOptionType[]) => void) | undefined;
|
|
30
|
+
inputCallback: ((value: ValueOptionType[] | ValueOptionType) => void) | undefined;
|
|
29
31
|
mount: () => void;
|
|
30
|
-
updateValue: (newValue: ValueOptionType[]) => void;
|
|
32
|
+
updateValue: (newValue: ValueOptionType[] | ValueOptionType) => void;
|
|
31
33
|
destroy: () => void;
|
|
32
34
|
focus: () => void;
|
|
33
35
|
toggleOpenClose: () => void;
|
|
34
36
|
}
|
|
35
|
-
interface
|
|
37
|
+
interface ITreeselectParams {
|
|
36
38
|
parentHtmlContainer: HTMLElement;
|
|
37
|
-
value?: ValueOptionType[];
|
|
39
|
+
value?: ValueOptionType[] | ValueOptionType;
|
|
38
40
|
options?: OptionType[];
|
|
39
41
|
openLevel?: number;
|
|
40
42
|
appendToBody?: boolean;
|
|
@@ -50,8 +52,10 @@ interface ITreeslectParams {
|
|
|
50
52
|
emptyText?: string;
|
|
51
53
|
staticList?: boolean;
|
|
52
54
|
id?: string;
|
|
55
|
+
isSingleSelect?: boolean;
|
|
56
|
+
showCount?: boolean;
|
|
53
57
|
iconElements?: Partial<IconsType>;
|
|
54
|
-
inputCallback?: (value: ValueOptionType[]) => void;
|
|
58
|
+
inputCallback?: (value: ValueOptionType[] | ValueOptionType) => void;
|
|
55
59
|
}
|
|
56
60
|
type IconsType = {
|
|
57
61
|
arrowUp: string | HTMLElement;
|
|
@@ -63,7 +67,7 @@ type IconsType = {
|
|
|
63
67
|
check: string | HTMLElement;
|
|
64
68
|
partialCheck: string | HTMLElement;
|
|
65
69
|
};
|
|
66
|
-
export class Treeselect implements
|
|
70
|
+
export class Treeselect implements ITreeselect {
|
|
67
71
|
#private;
|
|
68
72
|
parentHtmlContainer: HTMLElement;
|
|
69
73
|
value: ValueOptionType[];
|
|
@@ -82,13 +86,15 @@ export class Treeselect implements ITreeslect {
|
|
|
82
86
|
emptyText: string;
|
|
83
87
|
staticList: boolean;
|
|
84
88
|
id: string;
|
|
89
|
+
isSingleSelect: boolean;
|
|
90
|
+
showCount: boolean;
|
|
85
91
|
iconElements: IconsType;
|
|
86
|
-
inputCallback: ((value: ValueOptionType[]) => void) | undefined;
|
|
92
|
+
inputCallback: ((value: ValueOptionType[] | ValueOptionType) => void) | undefined;
|
|
87
93
|
isListOpened: boolean;
|
|
88
94
|
srcElement: HTMLElement | null;
|
|
89
|
-
constructor({ parentHtmlContainer, value, options, openLevel, appendToBody, alwaysOpen, showTags, tagsCountText, clearable, searchable, placeholder, grouped, listSlotHtmlComponent, disabled, emptyText, staticList, id, iconElements, inputCallback }:
|
|
95
|
+
constructor({ parentHtmlContainer, value, options, openLevel, appendToBody, alwaysOpen, showTags, tagsCountText, clearable, searchable, placeholder, grouped, listSlotHtmlComponent, disabled, emptyText, staticList, id, isSingleSelect, showCount, iconElements, inputCallback }: ITreeselectParams);
|
|
90
96
|
mount(): void;
|
|
91
|
-
updateValue(newValue: ValueOptionType[]): void;
|
|
97
|
+
updateValue(newValue: ValueOptionType[] | ValueOptionType): void;
|
|
92
98
|
destroy(): void;
|
|
93
99
|
focus(): void;
|
|
94
100
|
toggleOpenClose(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t,e,s,i){Object.defineProperty(t,e,{get:s,set:i,enumerable:!0,configurable:!0})}var e={};t(e,"Treeselect",(function(){return ae}),(function(t){return ae=t}));var s={};t(s,"TreeselectInput",(function(){return G}),(function(t){return G=t}));const i={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>'},l=(t,e)=>{if(e.innerHTML="","string"==typeof t)e.innerHTML=t;else{const s=t.cloneNode(!0);e.appendChild(s)}},n=t=>{const e=t?Object.assign({},t):{};return Object.keys(i).forEach((t=>{e[t]||(e[t]=i[t])})),e};var o,a,c,r,h,d,u,p,m,f,v,w,g,E,k,b,y,L,C,_,x,T,S,O,A,H,P,B,M=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},W=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};class G{focus(){setTimeout((()=>M(this,c,"f").focus()),0)}blur(){this.isOpened&&M(this,o,"m",v).call(this),this.clearSearch(),M(this,c,"f").blur()}updateValue(t){this.value=t,M(this,o,"m",u).call(this),M(this,o,"m",f).call(this)}removeItem(t){this.value=this.value.filter((e=>e.id!==t)),M(this,o,"m",B).call(this),M(this,o,"m",u).call(this),M(this,o,"m",f).call(this)}clear(){this.value=[],M(this,o,"m",B).call(this),M(this,o,"m",u).call(this),this.clearSearch()}openClose(){M(this,o,"m",v).call(this)}clearSearch(){this.searchText="",this.searchCallback(""),M(this,o,"m",f).call(this)}constructor({value:t,showTags:e,tagsCountText:s,clearable:i,isAlwaysOpened:l,searchable:n,placeholder:u,disabled:p,id:m,iconElements:f,inputCallback:v,searchCallback:g,openCallback:k,closeCallback:b,keydownCallback:y,focusCallback:L}){o.add(this),a.set(this,void 0),c.set(this,void 0),r.set(this,void 0),h.set(this,void 0),this.value=t,this.showTags=e,this.tagsCountText=s,this.searchable=n,this.placeholder=u,this.clearable=i,this.isAlwaysOpened=l,this.disabled=p,this.id=m,this.iconElements=f,this.isOpened=!1,this.searchText="",W(this,a,M(this,o,"m",E).call(this),"f"),W(this,c,M(this,o,"m",_).call(this),"f"),W(this,r,M(this,o,"m",S).call(this),"f"),W(this,h,null,"f"),this.inputCallback=v,this.searchCallback=g,this.openCallback=k,this.closeCallback=b,this.keydownCallback=y,this.focusCallback=L,this.srcElement=M(this,o,"m",w).call(this,M(this,a,"f"),M(this,c,"f"),M(this,r,"f")),M(this,o,"m",d).call(this)}}a=new WeakMap,c=new WeakMap,r=new WeakMap,h=new WeakMap,o=new WeakSet,d=function(){M(this,o,"m",u).call(this),M(this,o,"m",f).call(this),M(this,o,"m",p).call(this)},u=function(){M(this,a,"f").innerHTML="",this.showTags?M(this,a,"f").append(...M(this,o,"m",k).call(this)):M(this,a,"f").appendChild(M(this,o,"m",C).call(this)),M(this,a,"f").appendChild(M(this,c,"f"))},p=function(){const t=[];M(this,r,"f").innerHTML="",this.clearable&&t.push(M(this,o,"m",O).call(this)),this.isAlwaysOpened||t.push(M(this,o,"m",H).call(this,this.isOpened)),t.length&&M(this,r,"f").append(...t)},m=function(){if(!this.isAlwaysOpened&&M(this,h,"f")){const t=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;l(t,M(this,h,"f"))}},f=function(){var t;(null===(t=this.value)||void 0===t?void 0:t.length)?(M(this,c,"f").removeAttribute("placeholder"),this.srcElement.classList.remove("treeselect-input--value-not-selected")):(M(this,c,"f").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"),M(this,c,"f").value=this.searchText},v=function(){this.isOpened=!this.isOpened,M(this,o,"m",m).call(this),this.isOpened?this.openCallback():this.closeCallback()},w=function(t,e,s){const i=document.createElement("div");return i.classList.add("treeselect-input"),i.setAttribute("tabindex","-1"),i.addEventListener("mousedown",(t=>M(this,o,"m",g).call(this,t))),i.addEventListener("focus",(()=>this.focusCallback()),!0),t.appendChild(e),i.append(t,s),i},g=function(t){t.preventDefault(),t.stopPropagation(),this.isOpened||M(this,o,"m",v).call(this),this.focus()},E=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__tags"),t},k=function(){return this.value.map((t=>{const e=document.createElement("div");e.classList.add("treeselect-input__tags-element"),e.setAttribute("tabindex","-1"),e.setAttribute("tag-id",t.id.toString()),e.setAttribute("title",t.name);const s=M(this,o,"m",y).call(this,t.name),i=M(this,o,"m",L).call(this);return e.addEventListener("mousedown",(e=>M(this,o,"m",b).call(this,e,t.id))),e.append(s,i),e}))},b=function(t,e){t.preventDefault(),t.stopPropagation(),this.removeItem(e),this.focus()},y=function(t){const e=document.createElement("span");return e.classList.add("treeselect-input__tags-name"),e.innerHTML=t,e},L=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-cross"),l(this.iconElements.cross,t),t},C=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-count"),this.value.length?(t.innerHTML=1===this.value.length?this.value[0].name:`${this.value.length} ${this.tagsCountText}`,t):(t.innerHTML="",t)},_=function(){const t=document.createElement("input");return t.classList.add("treeselect-input__edit"),t.setAttribute("id",this.id),this.disabled&&t.setAttribute("tabindex","-1"),t.addEventListener("keydown",(t=>M(this,o,"m",x).call(this,t))),t.addEventListener("input",(e=>M(this,o,"m",T).call(this,e,t))),t},x=function(t){t.stopPropagation(),"Backspace"!==t.key||this.searchText.length||!this.value.length||this.showTags||this.clear(),"Backspace"===t.key&&!this.searchText.length&&this.value.length&&this.removeItem(this.value[this.value.length-1].id),"Space"!==t.code||this.searchText&&this.searchable||M(this,o,"m",v).call(this),"Enter"===t.key&&t.preventDefault(),this.keydownCallback(t.key),this.focus()},T=function(t,e){t.stopPropagation();const s=this.searchText,i=e.value.trim();if(0!==s.length||0!==i.length){if(this.searchable){const e=t.target.value;this.searchCallback(e),this.isOpened||M(this,o,"m",v).call(this)}else e.value="";this.searchText=e.value}else e.value=""},S=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__operators"),t},O=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__clear"),t.setAttribute("tabindex","-1"),l(this.iconElements.clear,t),t.addEventListener("mousedown",(t=>M(this,o,"m",A).call(this,t))),t},A=function(t){t.preventDefault(),t.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},H=function(t){W(this,h,document.createElement("span"),"f"),M(this,h,"f").classList.add("treeselect-input__arrow");const e=t?this.iconElements.arrowUp:this.iconElements.arrowDown;return l(e,M(this,h,"f")),M(this,h,"f").addEventListener("mousedown",(t=>M(this,o,"m",P).call(this,t))),M(this,h,"f")},P=function(t){t.stopPropagation(),t.preventDefault(),this.focus(),M(this,o,"m",v).call(this)},B=function(){this.inputCallback(this.value)};var N={};t(N,"TreeselectList",(function(){return Mt}),(function(t){return Mt=t}));const j=(t,e,s="",i=0)=>t.reduce(((t,l)=>{var n;const o=!!(null===(n=l.children)||void 0===n?void 0:n.length),a=i>=e&&o,c=i>e;if(t.push({id:l.value,name:l.name,childOf:s,isGroup:o,checked:!1,isPartialChecked:!1,level:i,isClosed:a,hidden:c}),o){const s=j(l.children,e,l.value,i+1);t.push(...s)}return t}),[]),D=({id:t,checked:e},s)=>{s.forEach((i=>{i.childOf===t&&(i.checked=null==e||e,i.isPartialChecked=!1,i.isGroup&&D(i,s))}))},q=(t,e)=>{const s=e.find((e=>e.id===t)),i=e.filter((t=>t.childOf===(null==s?void 0:s.id)));if(!s)return;const l=i.every((t=>t.checked)),n=i.some((t=>t.isPartialChecked||t.checked))&&!l,o=!l&&!n;l&&(s.checked=!0,s.isPartialChecked=!1),n&&(s.checked=!1,s.isPartialChecked=!0),o&&(s.checked=!1,s.isPartialChecked=!1),s.childOf&&q(s.childOf,e)},I=({id:t,isGroup:e,childOf:s,checked:i},l)=>{e&&D({id:t,checked:i},l),s&&q(s,l)},V=(t,e)=>e.reduce(((s,i)=>(i.childOf===t&&(s.push(i),i.isGroup&&s.push(...V(i.id,e))),s)),[]),$=(t,e)=>e.reduce(((s,i)=>(i.id===t&&(s.push(i),i.childOf&&s.push(...$(i.childOf,e))),s)),[]),R=t=>{const{onlyGroupsIds:e,allItems:s}=t.reduce(((t,e)=>e.checked?(e.isGroup&&t.onlyGroupsIds.push(e.id),t.allItems.push(e),t):t),{onlyGroupsIds:[],allItems:[]});return s.filter((t=>!e.some((e=>e===t.childOf))))},z=(t,{id:e,isClosed:s})=>{t.filter((t=>t.childOf===e)).forEach((e=>{e.hidden=null!=s&&s,e.isGroup&&!e.isClosed&&z(t,{id:e.id,isClosed:s})}))},U=(t,e)=>{const s=((t,e)=>t.reduce(((s,i)=>{if(i.name.toLowerCase().includes(e.toLowerCase())){if(s.push(i),i.isGroup){const e=V(i.id,t);s.push(...e)}if(i.childOf){const e=$(i.childOf,t);s.push(...e)}}return s}),[]))(t,e);t.forEach((e=>{s.some((t=>t.id===e.id))?(e.isGroup&&(e.isClosed=!1,z(t,e)),e.hidden=!1):e.hidden=!0}))},Y=(t,e)=>{(t=>{t.forEach((t=>{t.checked=!1,t.isPartialChecked=!1}))})(e);e.filter((e=>t.some((t=>t===e.id)))).forEach((t=>{t.checked=!0,t.isPartialChecked=!1,I(t,e)}))};var F,J,K,X,Q,Z,tt,et,st,it,lt,nt,ot,at,ct,rt,ht,dt,ut,pt,mt,ft,vt,wt,gt,Et,kt,bt,yt=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},Lt=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const Ct=(t,e,s)=>{t.forEach((i=>{const l=e.querySelector(`[input-id="${i.id}"]`),n=Pt(l);l.checked=i.checked,_t(i,n),xt(i,n),Tt(i,n,s),St(i,n),At(i,n,t),Ot(i,l,s)})),Ht(t,e)},_t=(t,e)=>{t.checked?e.classList.add("treeselect-list__item--checked"):e.classList.remove("treeselect-list__item--checked")},xt=(t,e)=>{t.isPartialChecked?e.classList.add("treeselect-list__item--partial-checked"):e.classList.remove("treeselect-list__item--partial-checked")},Tt=(t,e,s)=>{if(t.isGroup){const i=e.querySelector(".treeselect-list__item-icon"),n=t.isClosed?s.arrowRight:s.arrowDown;l(n,i),t.isClosed?e.classList.add("treeselect-list__item--closed"):e.classList.remove("treeselect-list__item--closed")}},St=(t,e)=>{t.hidden?e.classList.add("treeselect-list__item--hidden"):e.classList.remove("treeselect-list__item--hidden")},Ot=(t,e,s)=>{const i=e.parentNode.querySelector(".treeselect-list__item-checkbox-icon");t.checked?l(s.check,i):t.isPartialChecked?l(s.partialCheck,i):i.innerHTML=""},At=(t,e,s)=>{if(0===t.level){const i=s.some((e=>e.isGroup&&e.level===t.level)),l=!t.isGroup&&i?"20px":"5px";e.style.paddingLeft=t.isGroup?"0":l}else e.style.paddingLeft=t.isGroup?20*t.level+"px":20*t.level+20+"px";e.setAttribute("level",t.level.toString()),e.setAttribute("group",t.isGroup.toString())},Ht=(t,e)=>{const s=t.some((t=>!t.hidden)),i=e.querySelector(".treeselect-list__empty");s?i.classList.add("treeselect-list__empty--hidden"):i.classList.remove("treeselect-list__empty--hidden")},Pt=t=>t.parentNode.parentNode,Bt=(t,e)=>e.find((e=>e.id.toString()===t));class Mt{updateValue(t){var e,s,i,l;this.value=t,e=t,s=this.flattedOptions,i=this.srcElement,l=this.iconElements,Y(e,s),Ct(s,i,l),yt(this,F,"m",kt).call(this)}updateSearchValue(t){if(t===this.searchText)return;const e=""===this.searchText&&""!==t;this.searchText=t,e&&(this.flattedOptionsBeforeSearch=JSON.parse(JSON.stringify(this.flattedOptions))),""===this.searchText&&(this.flattedOptions=this.flattedOptionsBeforeSearch.map((t=>{const e=this.flattedOptions.find((e=>e.id===t.id));return e.isClosed=t.isClosed,e.hidden=t.hidden,e})),this.flattedOptionsBeforeSearch=[]),this.searchText&&U(this.flattedOptions,t),Ct(this.flattedOptions,this.srcElement,this.iconElements),this.focusFirstListElement()}callKeyAction(t){Lt(this,K,!1,"f");const e=this.srcElement.querySelector(".treeselect-list__item--focused");"Enter"===t&&e&&e.dispatchEvent(new Event("mousedown")),"ArrowLeft"!==t&&"ArrowRight"!==t||yt(this,F,"m",X).call(this,e,t),"ArrowDown"!==t&&"ArrowUp"!==t||yt(this,F,"m",Q).call(this,e,t)}focusFirstListElement(){const t="treeselect-list__item--focused",e=this.srcElement.querySelector(`.${t}`),s=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Pt(t)).display));if(!s.length)return;e&&e.classList.remove(t);Pt(s[0]).classList.add(t)}constructor({options:t,value:e,openLevel:s,listSlotHtmlComponent:i,emptyText:l,isSingleSelect:n,iconElements:o,showCount:a,inputCallback:c,arrowClickCallback:r,mouseupCallback:h}){F.add(this),J.set(this,null),K.set(this,!0),this.options=t,this.value=e,this.openLevel=null!=s?s:0,this.listSlotHtmlComponent=null!=i?i:null,this.emptyText=null!=l?l:"No results found...",this.isSingleSelect=null!=n&&n,this.showCount=null!=a&&a,this.iconElements=o,this.searchText="",this.flattedOptions=j(this.options,this.openLevel),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[]},this.srcElement=yt(this,F,"m",Z).call(this),this.inputCallback=c,this.arrowClickCallback=r,this.mouseupCallback=h,this.updateValue(this.value),(t=>{const{duplications:e}=t.reduce(((t,e)=>(t.allItems.some((t=>t.toString()===e.id.toString()))&&t.duplications.push(e.id),t.allItems.push(e.id),t)),{duplications:[],allItems:[]});e.length&&console.error(`Validation: You have duplicated values: ${e.join(", ")}! You should use unique values.`)})(this.flattedOptions)}}J=new WeakMap,K=new WeakMap,F=new WeakSet,X=function(t,e){if(!t)return;const s=t.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),i=Bt(s,this.flattedOptions),l=t.querySelector(".treeselect-list__item-icon");"ArrowLeft"===e&&!i.isClosed&&i.isGroup&&l.dispatchEvent(new Event("mousedown")),"ArrowRight"===e&&i.isClosed&&i.isGroup&&l.dispatchEvent(new Event("mousedown"))},Q=function(t,e){var s;const i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Pt(t)).display));if(i.length)if(t){const t=i.findIndex((t=>Pt(t).classList.contains("treeselect-list__item--focused")));Pt(i[t]).classList.remove("treeselect-list__item--focused");const l="ArrowDown"===e?t+1:t-1,n="ArrowDown"===e?0:i.length-1,o=null!==(s=i[l])&&void 0!==s?s:i[n],a=!i[l],c=Pt(o);c.classList.add("treeselect-list__item--focused");const r=this.srcElement.getBoundingClientRect(),h=c.getBoundingClientRect();if(a&&"ArrowDown"===e)return void this.srcElement.scroll(0,0);if(a&&"ArrowUp"===e)return void this.srcElement.scroll(0,this.srcElement.scrollHeight);if(r.y+r.height<h.y+h.height)return void this.srcElement.scroll(0,this.srcElement.scrollTop+h.height);if(r.y>h.y)return void this.srcElement.scroll(0,this.srcElement.scrollTop-h.height)}else{Pt(i[0]).classList.add("treeselect-list__item--focused")}},Z=function(){const t=yt(this,F,"m",tt).call(this),e=yt(this,F,"m",it).call(this,this.options);t.append(...e);const s=yt(this,F,"m",lt).call(this);s&&t.append(s);const i=yt(this,F,"m",nt).call(this);return t.append(i),t},tt=function(){const t=document.createElement("div");return t.classList.add("treeselect-list"),this.isSingleSelect&&t.classList.add("treeselect-list--single-select"),t.addEventListener("mouseout",(t=>yt(this,F,"m",et).call(this,t))),t.addEventListener("mousemove",(()=>yt(this,F,"m",st).call(this))),t.addEventListener("mouseup",(()=>this.mouseupCallback()),!0),t},et=function(t){t.stopPropagation(),yt(this,J,"f")&&yt(this,K,"f")&&yt(this,J,"f").classList.add("treeselect-list__item--focused")},st=function(){Lt(this,K,!0,"f")},it=function t(e){return e.reduce(((e,s)=>{var i;if(null===(i=s.children)||void 0===i?void 0:i.length){const i=yt(this,F,"m",ot).call(this,s),l=yt(this,F,"m",t).call(this,s.children);return i.append(...l),e.push(i),e}const l=yt(this,F,"m",at).call(this,s,!1);return e.push(l),e}),[])},lt=function(){if(!this.listSlotHtmlComponent)return null;const t=document.createElement("div");return t.classList.add("treeselect-list__slot"),t.appendChild(this.listSlotHtmlComponent),t},nt=function(){const t=document.createElement("div");t.classList.add("treeselect-list__empty"),t.setAttribute("title",this.emptyText);const e=document.createElement("span");e.classList.add("treeselect-list__empty-icon"),l(this.iconElements.attention,e);const s=document.createElement("span");return s.classList.add("treeselect-list__empty-text"),s.innerHTML=this.emptyText,t.append(e,s),t},ot=function(t){const e=document.createElement("div");e.setAttribute("group-container-id",t.value.toString()),e.classList.add("treeselect-list__group-container");const s=yt(this,F,"m",at).call(this,t,!0);return e.appendChild(s),e},at=function(t,e){const s=yt(this,F,"m",ct).call(this,t);if(e){const t=yt(this,F,"m",ut).call(this);s.appendChild(t)}const i=yt(this,F,"m",mt).call(this,t),l=yt(this,F,"m",ft).call(this,t,e);return s.append(i,l),s},ct=function(t){const e=document.createElement("div");return e.setAttribute("tabindex","-1"),e.setAttribute("title",t.name),e.classList.add("treeselect-list__item"),e.addEventListener("mouseover",(()=>yt(this,F,"m",rt).call(this,e)),!0),e.addEventListener("mouseout",(()=>yt(this,F,"m",ht).call(this,e)),!0),e.addEventListener("mousedown",(e=>yt(this,F,"m",dt).call(this,e,t))),e},rt=function(t){yt(this,K,"f")&&yt(this,F,"m",Et).call(this,!0,t)},ht=function(t){yt(this,K,"f")&&(yt(this,F,"m",Et).call(this,!1,t),Lt(this,J,t,"f"))},dt=function(t,e){t.preventDefault(),t.stopPropagation();const s=t.target.querySelector(".treeselect-list__item-checkbox");s.checked=!s.checked,yt(this,F,"m",wt).call(this,s,e)},ut=function(){const t=document.createElement("span");return t.setAttribute("tabindex","-1"),t.classList.add("treeselect-list__item-icon"),l(this.iconElements.arrowDown,t),t.addEventListener("mousedown",(t=>yt(this,F,"m",pt).call(this,t))),t},pt=function(t){t.preventDefault(),t.stopPropagation(),yt(this,F,"m",gt).call(this,t)},mt=function(t){const e=document.createElement("div");e.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");return i.setAttribute("tabindex","-1"),i.setAttribute("type","checkbox"),i.setAttribute("input-id",t.value.toString()),i.classList.add("treeselect-list__item-checkbox"),e.append(s,i),e},ft=function(t,e){const s=document.createElement("label");if(s.innerHTML=t.name,s.classList.add("treeselect-list__item-label"),e&&this.showCount){const e=yt(this,F,"m",vt).call(this,t);s.appendChild(e)}return s},vt=function(t){const e=document.createElement("span"),s=this.flattedOptions.filter((e=>e.childOf===t.value));return e.innerHTML=`(${s.length})`,e.classList.add("treeselect-list__item-label-counter"),e},wt=function(t,e){const s=this.flattedOptions.find((t=>t.id===e.value)),i=(null==s?void 0:s.isGroup)&&this.isSingleSelect;if(s&&!i){if(this.isSingleSelect){const[t]=this.value;if(s.id===t)return;Y([s.id],this.flattedOptions)}else s.checked=t.checked,s.isPartialChecked=!1,I(s,this.flattedOptions);Ct(this.flattedOptions,this.srcElement,this.iconElements),yt(this,F,"m",bt).call(this)}},gt=function(t){var e,s,i;const l=null===(s=null===(e=t.target)||void 0===e?void 0:e.parentNode)||void 0===s?void 0:s.querySelector("[input-id]"),n=null!==(i=null==l?void 0:l.getAttribute("input-id"))&&void 0!==i?i:null,o=Bt(n,this.flattedOptions);o&&(o.isClosed=!o.isClosed,z(this.flattedOptions,o),Ct(this.flattedOptions,this.srcElement,this.iconElements),this.arrowClickCallback())},Et=function(t,e){const s="treeselect-list__item--focused";if(t){const t=Array.from(this.srcElement.querySelectorAll(`.${s}`));t.length&&t.forEach((t=>t.classList.remove(s))),e.classList.add(s)}else e.classList.remove(s)},kt=function(){var t;this.selectedNodes={nodes:(t=this.flattedOptions,t.filter((t=>t.checked&&!t.isGroup))),groupedNodes:R(this.flattedOptions)}},bt=function(){yt(this,F,"m",kt).call(this),this.inputCallback(this.selectedNodes),this.value=this.selectedNodes.nodes.map((t=>t.id))};var Wt,Gt,Nt,jt,Dt,qt,It,Vt,$t,Rt,zt,Ut,Yt,Ft,Jt,Kt,Xt,Qt,Zt,te,ee,se,ie=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},le=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const ne=t=>t.map((t=>t.id)),oe=t=>t?Array.isArray(t)?t:[t]:[];class ae{mount(){var t;this.destroy();const{container:e,list:s,input:i}=ie(this,Wt,"m",$t).call(this);this.srcElement=e,le(this,Gt,s,"f"),le(this,Nt,i,"f"),le(this,Dt,this.scrollWindowHandler.bind(this),"f"),le(this,qt,this.scrollWindowHandler.bind(this),"f"),le(this,It,this.focusWindowHandler.bind(this),"f"),le(this,Vt,this.blurWindowHandler.bind(this),"f"),this.alwaysOpen&&(null===(t=ie(this,Nt,"f"))||void 0===t||t.openClose()),this.disabled&&this.srcElement.classList.add("treeselect--disabled")}updateValue(t){var e;const s=ie(this,Gt,"f");if(s){const i=oe(t);s.updateValue(i);const{groupedNodes:l,nodes:n}=s.selectedNodes,o=this.grouped?l:n;null===(e=ie(this,Nt,"f"))||void 0===e||e.updateValue(o)}}destroy(){this.srcElement&&(ie(this,Wt,"m",Xt).call(this),this.srcElement.innerHTML="",this.srcElement=null,ie(this,Wt,"m",ee).call(this,!0))}focus(){ie(this,Nt,"f")&&ie(this,Nt,"f").focus()}toggleOpenClose(){ie(this,Nt,"f")&&(ie(this,Nt,"f").openClose(),ie(this,Nt,"f").focus())}scrollWindowHandler(){this.updateListPosition()}focusWindowHandler(t){var e,s,i;(null===(e=this.srcElement)||void 0===e?void 0:e.contains(t.target))||(null===(s=ie(this,Gt,"f"))||void 0===s?void 0:s.srcElement.contains(t.target))||(null===(i=ie(this,Nt,"f"))||void 0===i||i.blur(),ie(this,Wt,"m",ee).call(this,!1),ie(this,Wt,"m",Zt).call(this,!1))}blurWindowHandler(){var t;null===(t=ie(this,Nt,"f"))||void 0===t||t.blur(),ie(this,Wt,"m",ee).call(this,!1),ie(this,Wt,"m",Zt).call(this,!1)}updateListPosition(){var t;const e=this.srcElement,s=null===(t=ie(this,Gt,"f"))||void 0===t?void 0:t.srcElement;if(!e||!s)return;s.style.transform="";const{y:i,height:l}=s.getBoundingClientRect(),{x:n,y:o,height:a,width:c}=e.getBoundingClientRect(),r=window.innerHeight-o-a,h=o>r&&o>=l&&r<l;this.appendToBody&&(s.style.transform=h?`translateY(${o-i-l}px)`:`translateY(${o+a-i}px)`,s.style.width=`${c}px`,s.style.left=`${n+window.scrollX}px`);const d=h?"top":"bottom";s.getAttribute("direction")!==d&&(s.setAttribute("direction",d),ie(this,Wt,"m",Qt).call(this,h,this.appendToBody))}constructor({parentHtmlContainer:t,value:e,options:s,openLevel:i,appendToBody:l,alwaysOpen:o,showTags:a,tagsCountText:c,clearable:r,searchable:h,placeholder:d,grouped:u,listSlotHtmlComponent:p,disabled:m,emptyText:f,staticList:v,id:w,isSingleSelect:g,showCount:E,iconElements:k,inputCallback:b}){Wt.add(this),Gt.set(this,null),Nt.set(this,null),jt.set(this,null),Dt.set(this,null),qt.set(this,null),It.set(this,null),Vt.set(this,null),(({parentHtmlContainer:t,staticList:e,appendToBody:s,isSingleSelect:i,value:l})=>{t||console.error("Validation: parentHtmlContainer prop is required!"),e&&s&&console.error("Validation: You should set staticList to false if you use appendToBody!"),i&&Array.isArray(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!")})({parentHtmlContainer:t,value:e,staticList:v,appendToBody:l,isSingleSelect:g}),this.parentHtmlContainer=t,this.value=oe(e),this.options=null!=s?s:[],this.openLevel=null!=i?i:0,this.appendToBody=null==l||l,this.alwaysOpen=!(!o||m),this.showTags=null==a||a,this.tagsCountText=null!=c?c:"elements selected",this.clearable=null==r||r,this.searchable=null==h||h,this.placeholder=null!=d?d:"Search...",this.grouped=null==u||u,this.listSlotHtmlComponent=null!=p?p:null,this.disabled=null!=m&&m,this.emptyText=null!=f?f:"No results found...",this.staticList=!(!v||this.appendToBody),this.id=null!=w?w:"",this.isSingleSelect=null!=g&&g,this.showCount=null!=E&&E,this.iconElements=n(k),this.inputCallback=b,this.isListOpened=!1,this.srcElement=null,this.mount()}}Gt=new WeakMap,Nt=new WeakMap,jt=new WeakMap,Dt=new WeakMap,qt=new WeakMap,It=new WeakMap,Vt=new WeakMap,Wt=new WeakSet,$t=function(){const t=this.parentHtmlContainer;t.classList.add("treeselect");const e=new(0,N.TreeselectList)({options:this.options,value:this.value,openLevel:this.openLevel,listSlotHtmlComponent:this.listSlotHtmlComponent,emptyText:this.emptyText,isSingleSelect:this.isSingleSelect,showCount:this.showCount,iconElements:this.iconElements,inputCallback:t=>ie(this,Wt,"m",Ft).call(this,t),arrowClickCallback:()=>ie(this,Wt,"m",Jt).call(this),mouseupCallback:()=>{var t;return null===(t=ie(this,Nt,"f"))||void 0===t?void 0:t.focus()}}),{groupedNodes:i,nodes:l}=e.selectedNodes,n=new(0,s.TreeselectInput)({value:this.grouped?i:l,showTags:this.showTags,tagsCountText:this.tagsCountText,clearable:this.clearable,isAlwaysOpened:this.alwaysOpen,searchable:this.searchable,placeholder:this.placeholder,disabled:this.disabled,id:this.id,iconElements:this.iconElements,inputCallback:t=>ie(this,Wt,"m",Rt).call(this,t),searchCallback:t=>ie(this,Wt,"m",Ut).call(this,t),openCallback:()=>ie(this,Wt,"m",Kt).call(this),closeCallback:()=>ie(this,Wt,"m",Xt).call(this),keydownCallback:t=>ie(this,Wt,"m",zt).call(this,t),focusCallback:()=>ie(this,Wt,"m",Yt).call(this)});return this.appendToBody&&le(this,jt,new ResizeObserver((()=>this.updateListPosition())),"f"),t.append(n.srcElement),{container:t,list:e,input:n}},Rt=function(t){var e,s,i;const l=ne(t);null===(e=ie(this,Gt,"f"))||void 0===e||e.updateValue(l);const n=null===(i=null===(s=ie(this,Gt,"f"))||void 0===s?void 0:s.selectedNodes)||void 0===i?void 0:i.nodes;this.value=n?ne(n):[],ie(this,Wt,"m",se).call(this)},zt=function(t){var e;this.isListOpened&&(null===(e=ie(this,Gt,"f"))||void 0===e||e.callKeyAction(t))},Ut=function(t){var e;null===(e=ie(this,Gt,"f"))||void 0===e||e.updateSearchValue(t),this.updateListPosition()},Yt=function(){ie(this,Wt,"m",Zt).call(this,!0),ie(this,It,"f")&&ie(this,It,"f")&&ie(this,Vt,"f")&&(document.addEventListener("mousedown",ie(this,It,"f"),!0),document.addEventListener("focus",ie(this,It,"f"),!0),window.addEventListener("blur",ie(this,Vt,"f")))},Ft=function(t){var e,s,i;const{groupedNodes:l,nodes:n}=t,o=this.grouped?l:n;null===(e=ie(this,Nt,"f"))||void 0===e||e.updateValue(o),this.value=ne(n),this.isSingleSelect&&(null===(s=ie(this,Nt,"f"))||void 0===s||s.openClose(),null===(i=ie(this,Nt,"f"))||void 0===i||i.clearSearch()),setTimeout((()=>{var t;null===(t=ie(this,Nt,"f"))||void 0===t||t.focus()}),0),ie(this,Wt,"m",se).call(this)},Jt=function(){var t;null===(t=ie(this,Nt,"f"))||void 0===t||t.focus(),this.updateListPosition()},Kt=function(){var t;this.isListOpened=!0,ie(this,Dt,"f")&&ie(this,qt,"f")&&(window.addEventListener("scroll",ie(this,Dt,"f"),!0),window.addEventListener("resize",ie(this,qt,"f"))),ie(this,Gt,"f")&&this.srcElement&&(this.appendToBody?(document.body.appendChild(ie(this,Gt,"f").srcElement),null===(t=ie(this,jt,"f"))||void 0===t||t.observe(this.srcElement)):this.srcElement.appendChild(ie(this,Gt,"f").srcElement),this.updateListPosition(),ie(this,Wt,"m",te).call(this,!0),ie(this,Gt,"f").focusFirstListElement())},Xt=function(){var t;if(this.alwaysOpen)return;if(this.isListOpened=!1,ie(this,Dt,"f")&&ie(this,qt,"f")&&(window.removeEventListener("scroll",ie(this,Dt,"f"),!0),window.removeEventListener("resize",ie(this,qt,"f"))),!ie(this,Gt,"f")||!this.srcElement)return;(this.appendToBody?document.body.contains(ie(this,Gt,"f").srcElement):this.srcElement.contains(ie(this,Gt,"f").srcElement))&&(this.appendToBody?(document.body.removeChild(ie(this,Gt,"f").srcElement),null===(t=ie(this,jt,"f"))||void 0===t||t.disconnect()):this.srcElement.removeChild(ie(this,Gt,"f").srcElement),ie(this,Wt,"m",te).call(this,!1))},Qt=function(t,e){if(!ie(this,Gt,"f")||!ie(this,Nt,"f"))return;const s=e?"treeselect-list--top-to-body":"treeselect-list--top",i=e?"treeselect-list--bottom-to-body":"treeselect-list--bottom";t?(ie(this,Gt,"f").srcElement.classList.add(s),ie(this,Gt,"f").srcElement.classList.remove(i),ie(this,Nt,"f").srcElement.classList.add("treeselect-input--top"),ie(this,Nt,"f").srcElement.classList.remove("treeselect-input--bottom")):(ie(this,Gt,"f").srcElement.classList.remove(s),ie(this,Gt,"f").srcElement.classList.add(i),ie(this,Nt,"f").srcElement.classList.remove("treeselect-input--top"),ie(this,Nt,"f").srcElement.classList.add("treeselect-input--bottom"))},Zt=function(t){ie(this,Nt,"f")&&ie(this,Gt,"f")&&(t?(ie(this,Nt,"f").srcElement.classList.add("treeselect-input--focused"),ie(this,Gt,"f").srcElement.classList.add("treeselect-list--focused")):(ie(this,Nt,"f").srcElement.classList.remove("treeselect-input--focused"),ie(this,Gt,"f").srcElement.classList.remove("treeselect-list--focused")))},te=function(t){var e,s,i,l;t?null===(e=ie(this,Nt,"f"))||void 0===e||e.srcElement.classList.add("treeselect-input--opened"):null===(s=ie(this,Nt,"f"))||void 0===s||s.srcElement.classList.remove("treeselect-input--opened"),this.staticList?null===(i=ie(this,Gt,"f"))||void 0===i||i.srcElement.classList.add("treeselect-list--static"):null===(l=ie(this,Gt,"f"))||void 0===l||l.srcElement.classList.remove("treeselect-list--static")},ee=function(t){ie(this,Dt,"f")&&ie(this,qt,"f")&&ie(this,It,"f")&&ie(this,Vt,"f")&&(this.alwaysOpen&&!t||(window.removeEventListener("scroll",ie(this,Dt,"f"),!0),window.removeEventListener("resize",ie(this,qt,"f"))),document.removeEventListener("mousedown",ie(this,It,"f"),!0),document.removeEventListener("focus",ie(this,It,"f"),!0),window.removeEventListener("blur",ie(this,Vt,"f")))},se=function(){var t;const e=((t,e)=>{if(e){const[e]=t;return e}return t})(this.value,this.isSingleSelect);null===(t=this.srcElement)||void 0===t||t.dispatchEvent(new CustomEvent("input",{detail:e})),this.inputCallback&&this.inputCallback(e)};export{ae as Treeselect,e as default};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "treeselectjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Treeselect JS",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"module": "dist/
|
|
7
|
-
"types": "dist/
|
|
5
|
+
"main": "dist/treeselectjs.cjs.js",
|
|
6
|
+
"module": "dist/treeselectjs.mjs.js",
|
|
7
|
+
"types": "dist/treeselectjs.d.ts",
|
|
8
8
|
"targets": {
|
|
9
9
|
"main": {
|
|
10
|
-
"source": "src/
|
|
10
|
+
"source": "src/treeselectjs.ts",
|
|
11
11
|
"outputFormat": "commonjs",
|
|
12
12
|
"isLibrary": true,
|
|
13
13
|
"optimize": true,
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"module": {
|
|
20
|
-
"source": "src/
|
|
20
|
+
"source": "src/treeselectjs.ts",
|
|
21
21
|
"outputFormat": "esmodule",
|
|
22
22
|
"isLibrary": true,
|
|
23
23
|
"optimize": true,
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
},
|
|
29
29
|
"types": {
|
|
30
30
|
"isLibrary": true,
|
|
31
|
-
"source": "src/
|
|
31
|
+
"source": "src/treeselectjs.ts",
|
|
32
32
|
"optimize": true,
|
|
33
33
|
"sourceMap": false
|
|
34
34
|
},
|
|
35
35
|
"css": {
|
|
36
|
-
"source": "src/
|
|
36
|
+
"source": "src/treeselectjs.css",
|
|
37
37
|
"distDir": "dist",
|
|
38
38
|
"isLibrary": true,
|
|
39
39
|
"optimize": true,
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "parcel build",
|
|
45
|
-
"watch": "parcel watch"
|
|
45
|
+
"watch": "parcel watch",
|
|
46
|
+
"prettier": "prettier --w src && prettier --w demo"
|
|
46
47
|
},
|
|
47
48
|
"repository": {
|
|
48
49
|
"type": "git",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function t(t,e,s,i){Object.defineProperty(t,e,{get:s,set:i,enumerable:!0,configurable:!0})}t(module.exports,"Treeselect",(function(){return ne}),(function(t){return ne=t}));var e={};t(e,"TreeselectInput",(function(){return W}),(function(t){return W=t}));const s={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>'},i=(t,e)=>{if(e.innerHTML="","string"==typeof t)e.innerHTML=t;else{const s=t.cloneNode(!0);e.appendChild(s)}},l=t=>{const e=t?Object.assign({},t):{};return Object.keys(s).forEach((t=>{e[t]||(e[t]=s[t])})),e};var n,o,c,a,r,h,d,u,p,m,f,v,w,E,g,k,b,L,y,C,_,x,T,O,A,S,H,P,B=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},M=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};class W{focus(){B(this,c,"f").focus()}blur(){this.isOpened&&B(this,n,"m",f).call(this),this.searchText="",this.searchCallback(""),B(this,n,"m",m).call(this),B(this,c,"f").blur()}updateValue(t){this.value=t,B(this,n,"m",d).call(this),B(this,n,"m",m).call(this)}removeItem(t){this.value=this.value.filter((e=>e.id!==t)),B(this,n,"m",P).call(this),B(this,n,"m",d).call(this),B(this,n,"m",m).call(this)}clear(){this.value=[],this.searchText="",this.searchCallback(""),B(this,n,"m",P).call(this),B(this,n,"m",d).call(this),B(this,n,"m",m).call(this)}openClose(){B(this,n,"m",f).call(this)}constructor({value:t,showTags:e,tagsCountText:s,clearable:i,isAlwaysOpened:l,searchable:d,placeholder:u,disabled:p,id:m,iconElements:f,inputCallback:w,searchCallback:g,openCallback:k,closeCallback:b,keydownCallback:L,focusCallback:y}){n.add(this),o.set(this,void 0),c.set(this,void 0),a.set(this,void 0),r.set(this,void 0),this.value=t,this.showTags=e,this.tagsCountText=s,this.searchable=d,this.placeholder=u,this.clearable=i,this.isAlwaysOpened=l,this.disabled=p,this.id=m,this.iconElements=f,this.isOpened=!1,this.searchText="",M(this,o,B(this,n,"m",E).call(this),"f"),M(this,c,B(this,n,"m",C).call(this),"f"),M(this,a,B(this,n,"m",T).call(this),"f"),M(this,r,null,"f"),this.inputCallback=w,this.searchCallback=g,this.openCallback=k,this.closeCallback=b,this.keydownCallback=L,this.focusCallback=y,this.srcElement=B(this,n,"m",v).call(this,B(this,o,"f"),B(this,c,"f"),B(this,a,"f")),B(this,n,"m",h).call(this)}}o=new WeakMap,c=new WeakMap,a=new WeakMap,r=new WeakMap,n=new WeakSet,h=function(){B(this,n,"m",d).call(this),B(this,n,"m",m).call(this),B(this,n,"m",u).call(this)},d=function(){B(this,o,"f").innerHTML="",this.showTags?B(this,o,"f").append(...B(this,n,"m",g).call(this)):B(this,o,"f").appendChild(B(this,n,"m",y).call(this)),B(this,o,"f").appendChild(B(this,c,"f"))},u=function(){const t=[];B(this,a,"f").innerHTML="",this.clearable&&t.push(B(this,n,"m",O).call(this)),this.isAlwaysOpened||t.push(B(this,n,"m",S).call(this,this.isOpened)),t.length&&B(this,a,"f").append(...t)},p=function(){if(!this.isAlwaysOpened&&B(this,r,"f")){const t=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;i(t,B(this,r,"f"))}},m=function(){var t;(null===(t=this.value)||void 0===t?void 0:t.length)?(B(this,c,"f").removeAttribute("placeholder"),this.srcElement.classList.remove("treeselect-input--value-not-selected")):(B(this,c,"f").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"),B(this,c,"f").value=this.searchText},f=function(){this.isOpened=!this.isOpened,B(this,n,"m",p).call(this),this.isOpened?this.openCallback():this.closeCallback()},v=function(t,e,s){const i=document.createElement("div");return i.classList.add("treeselect-input"),i.setAttribute("tabindex","-1"),i.addEventListener("mousedown",(t=>B(this,n,"m",w).call(this,t))),i.addEventListener("focus",(()=>this.focusCallback()),!0),t.appendChild(e),i.append(t,s),i},w=function(t){t.preventDefault(),this.isOpened||B(this,n,"m",f).call(this),this.focus()},E=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__tags"),t},g=function(){return this.value.map((t=>{const e=document.createElement("div");e.classList.add("treeselect-input__tags-element"),e.setAttribute("tabindex","-1"),e.setAttribute("tag-id",t.id.toString()),e.setAttribute("title",t.name);const s=B(this,n,"m",b).call(this,t.name),i=B(this,n,"m",L).call(this);return e.addEventListener("mousedown",(e=>B(this,n,"m",k).call(this,e,t.id))),e.append(s,i),e}))},k=function(t,e){t.preventDefault(),t.stopPropagation(),this.removeItem(e),this.focus()},b=function(t){const e=document.createElement("span");return e.classList.add("treeselect-input__tags-name"),e.innerHTML=t,e},L=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-cross"),i(this.iconElements.cross,t),t},y=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-count"),this.value.length?(t.innerHTML=1===this.value.length?this.value[0].name:`${this.value.length} ${this.tagsCountText}`,t):(t.innerHTML="",t)},C=function(){const t=document.createElement("input");return t.classList.add("treeselect-input__edit"),t.setAttribute("id",this.id),this.disabled&&t.setAttribute("tabindex","-1"),t.addEventListener("keydown",(t=>B(this,n,"m",_).call(this,t))),t.addEventListener("input",(e=>B(this,n,"m",x).call(this,e,t))),t},_=function(t){"Backspace"!==t.key||this.searchText.length||!this.value.length||this.showTags||this.clear(),"Backspace"===t.key&&!this.searchText.length&&this.value.length&&this.removeItem(this.value[this.value.length-1].id),"Space"!==t.code||this.searchText&&this.searchable||B(this,n,"m",f).call(this),this.keydownCallback(t.key),this.focus()},x=function(t,e){t.stopPropagation();const s=this.searchText,i=e.value.trim();if(0!==s.length||0!==i.length){if(this.searchable){const e=t.target.value;this.searchCallback(e),this.isOpened||B(this,n,"m",f).call(this)}else e.value="";this.searchText=e.value}else e.value=""},T=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__operators"),t},O=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__clear"),t.setAttribute("tabindex","-1"),i(this.iconElements.clear,t),t.addEventListener("mousedown",(t=>B(this,n,"m",A).call(this,t))),t},A=function(t){t.preventDefault(),t.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},S=function(t){M(this,r,document.createElement("span"),"f"),B(this,r,"f").classList.add("treeselect-input__arrow");const e=t?this.iconElements.arrowUp:this.iconElements.arrowDown;return i(e,B(this,r,"f")),B(this,r,"f").addEventListener("mousedown",(t=>B(this,n,"m",H).call(this,t))),B(this,r,"f")},H=function(t){t.stopPropagation(),t.preventDefault(),this.focus(),B(this,n,"m",f).call(this)},P=function(){this.inputCallback(this.value)};var N={};t(N,"TreeselectList",(function(){return Bt}),(function(t){return Bt=t}));const j=(t,e,s="",i=0)=>t.reduce(((t,l)=>{var n;const o=!!(null===(n=l.children)||void 0===n?void 0:n.length),c=i>=e&&o,a=i>e;if(t.push({id:l.value,name:l.name,childOf:s,isGroup:o,checked:!1,isPartialChecked:!1,level:i,isClosed:c,hidden:a}),o){const s=j(l.children,e,l.value,i+1);t.push(...s)}return t}),[]),G=({id:t,checked:e},s)=>{s.forEach((i=>{i.childOf===t&&(i.checked=null==e||e,i.isPartialChecked=!1,i.isGroup&&G(i,s))}))},q=(t,e)=>{const s=e.find((e=>e.id===t)),i=e.filter((t=>t.childOf===(null==s?void 0:s.id)));if(!s)return;const l=i.every((t=>t.checked)),n=i.some((t=>t.isPartialChecked||t.checked))&&!l,o=!l&&!n;l&&(s.checked=!0,s.isPartialChecked=!1),n&&(s.checked=!1,s.isPartialChecked=!0),o&&(s.checked=!1,s.isPartialChecked=!1),s.childOf&&q(s.childOf,e)},I=({id:t,isGroup:e,childOf:s,checked:i},l)=>{e&&G({id:t,checked:i},l),s&&q(s,l)},D=(t,e)=>e.reduce(((s,i)=>(i.childOf===t&&(s.push(i),i.isGroup&&s.push(...D(i.id,e))),s)),[]),V=(t,e)=>e.reduce(((s,i)=>(i.id===t&&(s.push(i),i.childOf&&s.push(...V(i.childOf,e))),s)),[]),$=t=>{const{onlyGroupsIds:e,allItems:s}=t.reduce(((t,e)=>e.checked?(e.isGroup&&t.onlyGroupsIds.push(e.id),t.allItems.push(e),t):t),{onlyGroupsIds:[],allItems:[]});return s.filter((t=>!e.some((e=>e===t.childOf))))},R=(t,{id:e,isClosed:s})=>{t.filter((t=>t.childOf===e)).forEach((e=>{e.hidden=null!=s&&s,e.isGroup&&!e.isClosed&&R(t,{id:e.id,isClosed:s})}))},z=(t,e)=>{const s=((t,e)=>t.reduce(((s,i)=>{if(i.name.toLowerCase().includes(e.toLowerCase())){if(s.push(i),i.isGroup){const e=D(i.id,t);s.push(...e)}if(i.childOf){const e=V(i.childOf,t);s.push(...e)}}return s}),[]))(t,e);t.forEach((e=>{s.some((t=>t.id===e.id))?(e.isGroup&&(e.isClosed=!1,R(t,e)),e.hidden=!1):e.hidden=!0}))},U=(t,e)=>{(t=>{t.forEach((t=>{t.checked=!1,t.isPartialChecked=!1}))})(e);e.filter((e=>t.some((t=>t===e.id)))).forEach((t=>{t.checked=!0,t.isPartialChecked=!1,I(t,e)}))};var Y,F,J,K,X,Q,Z,tt,et,st,it,lt,nt,ot,ct,at,rt,ht,dt,ut,pt,mt,ft,vt,wt,Et,gt,kt=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},bt=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const Lt=(t,e,s,i)=>{U(t,e),yt(e,s,i)},yt=(t,e,s)=>{t.forEach((i=>{const l=e.querySelector(`[input-id="${i.id}"]`),n=Ht(l);l.checked=i.checked,Ct(i,n),_t(i,n),xt(i,n,s),Tt(i,n),At(i,n,t),Ot(i,l,s)})),St(t,e)},Ct=(t,e)=>{t.checked?e.classList.add("treeselect-list__item--checked"):e.classList.remove("treeselect-list__item--checked")},_t=(t,e)=>{t.isPartialChecked?e.classList.add("treeselect-list__item--partial-checked"):e.classList.remove("treeselect-list__item--partial-checked")},xt=(t,e,s)=>{if(t.isGroup){const l=e.querySelector(".treeselect-list__item-icon"),n=t.isClosed?s.arrowRight:s.arrowDown;i(n,l),t.isClosed?e.classList.add("treeselect-list__item--closed"):e.classList.remove("treeselect-list__item--closed")}},Tt=(t,e)=>{t.hidden?e.classList.add("treeselect-list__item--hidden"):e.classList.remove("treeselect-list__item--hidden")},Ot=(t,e,s)=>{const l=e.parentNode.querySelector(".treeselect-list__item-checkbox-icon");t.checked?i(s.check,l):t.isPartialChecked?i(s.partialCheck,l):l.innerHTML=""},At=(t,e,s)=>{if(0===t.level){const i=s.some((e=>e.isGroup&&e.level===t.level)),l=!t.isGroup&&i?"20px":"5px";e.style.paddingLeft=t.isGroup?"0":l}else e.style.paddingLeft=t.isGroup?20*t.level+"px":20*t.level+20+"px";e.setAttribute("level",t.level.toString()),e.setAttribute("group",t.isGroup.toString())},St=(t,e)=>{const s=t.some((t=>!t.hidden)),i=e.querySelector(".treeselect-list__empty");s?i.classList.add("treeselect-list__empty--hidden"):i.classList.remove("treeselect-list__empty--hidden")},Ht=t=>t.parentNode.parentNode,Pt=(t,e)=>e.find((e=>e.id.toString()===t));class Bt{updateValue(t){Lt(t,this.flattedOptions,this.srcElement,this.iconElements),kt(this,Y,"m",Et).call(this)}updateSearchValue(t){if(t===this.searchText)return;const e=""===this.searchText&&""!==t;this.searchText=t,e&&(this.flattedOptionsBeforeSearch=JSON.parse(JSON.stringify(this.flattedOptions))),""===this.searchText&&(this.flattedOptions=this.flattedOptionsBeforeSearch.map((t=>{const e=this.flattedOptions.find((e=>e.id===t.id));return e.isClosed=t.isClosed,e.hidden=t.hidden,e})),this.flattedOptionsBeforeSearch=[]),this.searchText&&z(this.flattedOptions,t),yt(this.flattedOptions,this.srcElement,this.iconElements),this.focusFirstListElement()}callKeyAction(t){bt(this,J,!1,"f");const e=this.srcElement.querySelector(".treeselect-list__item--focused");"Enter"===t&&e&&e.dispatchEvent(new Event("mousedown")),"ArrowLeft"!==t&&"ArrowRight"!==t||kt(this,Y,"m",K).call(this,e,t),"ArrowDown"!==t&&"ArrowUp"!==t||kt(this,Y,"m",X).call(this,e,t)}focusFirstListElement(){const t="treeselect-list__item--focused",e=this.srcElement.querySelector(`.${t}`),s=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Ht(t)).display));if(!s.length)return;e&&e.classList.remove(t);Ht(s[0]).classList.add(t)}constructor({options:t,value:e,openLevel:s,listSlotHtmlComponent:i,emptyText:l,iconElements:n,inputCallback:o,arrowClickCallback:c,mouseupCallback:a}){Y.add(this),F.set(this,null),J.set(this,!0),this.options=t,this.value=e,this.openLevel=null!=s?s:0,this.listSlotHtmlComponent=null!=i?i:null,this.emptyText=null!=l?l:"No results found...",this.iconElements=n,this.searchText="",this.flattedOptions=j(this.options,this.openLevel),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[]},this.srcElement=kt(this,Y,"m",Q).call(this),this.inputCallback=o,this.arrowClickCallback=c,this.mouseupCallback=a,this.updateValue(this.value),(t=>{const{duplications:e}=t.reduce(((t,e)=>(t.allItems.some((t=>t.toString()===e.id.toString()))&&t.duplications.push(e.id),t.allItems.push(e.id),t)),{duplications:[],allItems:[]});e.length&&console.error(`Validation: You have duplicated values: ${e.join(", ")}! You should use unique values.`)})(this.flattedOptions)}}F=new WeakMap,J=new WeakMap,Y=new WeakSet,K=function(t,e){if(!t)return;const s=t.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),i=Pt(s,this.flattedOptions),l=t.querySelector(".treeselect-list__item-icon");"ArrowLeft"!==e||i.isClosed||l.dispatchEvent(new Event("mousedown")),"ArrowRight"===e&&i.isClosed&&l.dispatchEvent(new Event("mousedown"))},X=function(t,e){var s;const i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Ht(t)).display));if(i.length)if(t){const t=i.findIndex((t=>Ht(t).classList.contains("treeselect-list__item--focused")));Ht(i[t]).classList.remove("treeselect-list__item--focused");const l="ArrowDown"===e?t+1:t-1,n="ArrowDown"===e?0:i.length-1,o=null!==(s=i[l])&&void 0!==s?s:i[n],c=!i[l],a=Ht(o);a.classList.add("treeselect-list__item--focused");const r=this.srcElement.getBoundingClientRect(),h=a.getBoundingClientRect();if(c&&"ArrowDown"===e)return void this.srcElement.scroll(0,0);if(c&&"ArrowUp"===e)return void this.srcElement.scroll(0,this.srcElement.scrollHeight);if(r.y+r.height<h.y+h.height)return void this.srcElement.scroll(0,this.srcElement.scrollTop+h.height);if(r.y>h.y)return void this.srcElement.scroll(0,this.srcElement.scrollTop-h.height)}else{Ht(i[0]).classList.add("treeselect-list__item--focused")}},Q=function(){const t=kt(this,Y,"m",Z).call(this),e=kt(this,Y,"m",st).call(this,this.options);t.append(...e);const s=kt(this,Y,"m",it).call(this);s&&t.append(s);const i=kt(this,Y,"m",lt).call(this);return t.append(i),t},Z=function(){const t=document.createElement("div");return t.classList.add("treeselect-list"),t.addEventListener("mouseout",(t=>kt(this,Y,"m",tt).call(this,t))),t.addEventListener("mousemove",(()=>kt(this,Y,"m",et).call(this))),t.addEventListener("mouseup",(()=>this.mouseupCallback()),!0),t},tt=function(t){t.stopPropagation(),kt(this,F,"f")&&kt(this,J,"f")&&kt(this,F,"f").classList.add("treeselect-list__item--focused")},et=function(){bt(this,J,!0,"f")},st=function t(e){return e.reduce(((e,s)=>{var i;if(null===(i=s.children)||void 0===i?void 0:i.length){const i=kt(this,Y,"m",nt).call(this,s),l=kt(this,Y,"m",t).call(this,s.children);return i.append(...l),e.push(i),e}const l=kt(this,Y,"m",ot).call(this,s,!1);return e.push(l),e}),[])},it=function(){if(!this.listSlotHtmlComponent)return null;const t=document.createElement("div");return t.classList.add("treeselect-list__slot"),t.appendChild(this.listSlotHtmlComponent),t},lt=function(){const t=document.createElement("div");t.classList.add("treeselect-list__empty"),t.setAttribute("title",this.emptyText);const e=document.createElement("span");e.classList.add("treeselect-list__empty-icon"),i(this.iconElements.attention,e);const s=document.createElement("span");return s.classList.add("treeselect-list__empty-text"),s.innerHTML=this.emptyText,t.append(e,s),t},nt=function(t){const e=document.createElement("div");e.setAttribute("group-container-id",t.value.toString()),e.classList.add("treeselect-list__group-container");const s=kt(this,Y,"m",ot).call(this,t,!0);return e.appendChild(s),e},ot=function(t,e){const s=kt(this,Y,"m",ct).call(this,t);if(e){const t=kt(this,Y,"m",dt).call(this);s.appendChild(t)}const i=kt(this,Y,"m",pt).call(this,t),l=kt(this,Y,"m",mt).call(this,t);return s.append(i,l),s},ct=function(t){const e=document.createElement("div");return e.setAttribute("tabindex","-1"),e.setAttribute("title",t.name),e.classList.add("treeselect-list__item"),e.addEventListener("mouseover",(()=>kt(this,Y,"m",at).call(this,e)),!0),e.addEventListener("mouseout",(()=>kt(this,Y,"m",rt).call(this,e)),!0),e.addEventListener("mousedown",(e=>kt(this,Y,"m",ht).call(this,e,t))),e},at=function(t){kt(this,J,"f")&&kt(this,Y,"m",wt).call(this,!0,t)},rt=function(t){kt(this,J,"f")&&(kt(this,Y,"m",wt).call(this,!1,t),bt(this,F,t,"f"))},ht=function(t,e){t.stopPropagation();const s=t.target.querySelector(".treeselect-list__item-checkbox");s.checked=!s.checked,kt(this,Y,"m",ft).call(this,s,e)},dt=function(){const t=document.createElement("span");return t.setAttribute("tabindex","-1"),t.classList.add("treeselect-list__item-icon"),i(this.iconElements.arrowDown,t),t.addEventListener("mousedown",(t=>kt(this,Y,"m",ut).call(this,t))),t},ut=function(t){t.stopPropagation(),kt(this,Y,"m",vt).call(this,t)},pt=function(t){const e=document.createElement("div");e.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");return i.setAttribute("tabindex","-1"),i.setAttribute("type","checkbox"),i.setAttribute("input-id",t.value.toString()),i.classList.add("treeselect-list__item-checkbox"),e.append(s,i),e},mt=function(t){const e=document.createElement("label");return e.innerHTML=t.name,e.classList.add("treeselect-list__item-label"),e},ft=function(t,e){const s=this.flattedOptions.find((t=>t.id===e.value));s&&(s.checked=t.checked,s.isPartialChecked=!1,I(s,this.flattedOptions),yt(this.flattedOptions,this.srcElement,this.iconElements),kt(this,Y,"m",gt).call(this))},vt=function(t){var e,s,i;const l=null===(s=null===(e=t.target)||void 0===e?void 0:e.parentNode)||void 0===s?void 0:s.querySelector("[input-id]"),n=null!==(i=null==l?void 0:l.getAttribute("input-id"))&&void 0!==i?i:null,o=Pt(n,this.flattedOptions);o&&(o.isClosed=!o.isClosed,R(this.flattedOptions,o),yt(this.flattedOptions,this.srcElement,this.iconElements),this.arrowClickCallback())},wt=function(t,e){const s="treeselect-list__item--focused";if(t){const t=Array.from(this.srcElement.querySelectorAll(`.${s}`));t.length&&t.forEach((t=>t.classList.remove(s))),e.classList.add(s)}else e.classList.remove(s)},Et=function(){var t;this.selectedNodes={nodes:(t=this.flattedOptions,t.filter((t=>t.checked&&!t.isGroup))),groupedNodes:$(this.flattedOptions)}},gt=function(){kt(this,Y,"m",Et).call(this),this.inputCallback(this.selectedNodes)};var Mt,Wt,Nt,jt,Gt,qt,It,Dt,Vt,$t,Rt,zt,Ut,Yt,Ft,Jt,Kt,Xt,Qt,Zt,te,ee,se=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},ie=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const le=t=>t.map((t=>t.id));class ne{mount(){var t;this.destroy();const{container:e,list:s,input:i}=se(this,Mt,"m",Vt).call(this);this.srcElement=e,ie(this,Wt,s,"f"),ie(this,Nt,i,"f"),ie(this,Gt,this.scrollWindowHandler.bind(this),"f"),ie(this,qt,this.scrollWindowHandler.bind(this),"f"),ie(this,It,this.focusWindowHandler.bind(this),"f"),ie(this,Dt,this.blurWindowHandler.bind(this),"f"),this.alwaysOpen&&(null===(t=se(this,Nt,"f"))||void 0===t||t.openClose()),this.disabled&&this.srcElement.classList.add("treeselect--disabled")}updateValue(t){var e;const s=se(this,Wt,"f");if(s){s.updateValue(t);const{groupedNodes:i,nodes:l}=s.selectedNodes,n=this.grouped?i:l;null===(e=se(this,Nt,"f"))||void 0===e||e.updateValue(n)}}destroy(){this.srcElement&&(se(this,Mt,"m",Kt).call(this),this.srcElement.innerHTML="",this.srcElement=null,se(this,Mt,"m",te).call(this,!0))}focus(){se(this,Nt,"f")&&se(this,Nt,"f").focus()}toggleOpenClose(){se(this,Nt,"f")&&(se(this,Nt,"f").openClose(),se(this,Nt,"f").focus())}scrollWindowHandler(){this.updateListPosition()}focusWindowHandler(t){var e,s,i;(null===(e=this.srcElement)||void 0===e?void 0:e.contains(t.target))||(null===(s=se(this,Wt,"f"))||void 0===s?void 0:s.srcElement.contains(t.target))||(null===(i=se(this,Nt,"f"))||void 0===i||i.blur(),se(this,Mt,"m",te).call(this,!1),se(this,Mt,"m",Qt).call(this,!1))}blurWindowHandler(){var t;null===(t=se(this,Nt,"f"))||void 0===t||t.blur(),se(this,Mt,"m",te).call(this,!1),se(this,Mt,"m",Qt).call(this,!1)}updateListPosition(){var t;const e=this.srcElement,s=null===(t=se(this,Wt,"f"))||void 0===t?void 0:t.srcElement;if(!e||!s)return;s.style.transform="";const{y:i,height:l}=s.getBoundingClientRect(),{x:n,y:o,height:c,width:a}=e.getBoundingClientRect(),r=window.innerHeight-o-c,h=o>r&&o>=l&&r<l;this.appendToBody&&(s.style.transform=h?`translateY(${o-i-l}px)`:`translateY(${o+c-i}px)`,s.style.width=`${a}px`,s.style.left=`${n+window.scrollX}px`);const d=h?"top":"bottom";s.getAttribute("direction")!==d&&(s.setAttribute("direction",d),se(this,Mt,"m",Xt).call(this,h,this.appendToBody))}constructor({parentHtmlContainer:t,value:e,options:s,openLevel:i,appendToBody:n,alwaysOpen:o,showTags:c,tagsCountText:a,clearable:r,searchable:h,placeholder:d,grouped:u,listSlotHtmlComponent:p,disabled:m,emptyText:f,staticList:v,id:w,iconElements:E,inputCallback:g}){Mt.add(this),Wt.set(this,null),Nt.set(this,null),jt.set(this,null),Gt.set(this,null),qt.set(this,null),It.set(this,null),Dt.set(this,null),(({parentHtmlContainer:t,staticList:e,appendToBody:s})=>{t||console.error("Validation: parentHtmlContainer prop is required!"),e&&s&&console.error("Validation: You should set staticList to false if you use appendToBody!")})({parentHtmlContainer:t,staticList:v,appendToBody:n}),this.parentHtmlContainer=t,this.value=null!=e?e:[],this.options=null!=s?s:[],this.openLevel=null!=i?i:0,this.appendToBody=null==n||n,this.alwaysOpen=!(!o||m),this.showTags=null==c||c,this.tagsCountText=null!=a?a:"elements selected",this.clearable=null==r||r,this.searchable=null==h||h,this.placeholder=null!=d?d:"Search...",this.grouped=null==u||u,this.listSlotHtmlComponent=null!=p?p:null,this.disabled=null!=m&&m,this.emptyText=null!=f?f:"No results found...",this.staticList=!(!v||this.appendToBody),this.id=null!=w?w:"",this.iconElements=l(E),this.inputCallback=g,this.isListOpened=!1,this.srcElement=null,this.mount()}}Wt=new WeakMap,Nt=new WeakMap,jt=new WeakMap,Gt=new WeakMap,qt=new WeakMap,It=new WeakMap,Dt=new WeakMap,Mt=new WeakSet,Vt=function(){const t=this.parentHtmlContainer;t.classList.add("treeselect");const s=new(0,N.TreeselectList)({options:this.options,value:this.value,openLevel:this.openLevel,listSlotHtmlComponent:this.listSlotHtmlComponent,emptyText:this.emptyText,iconElements:this.iconElements,inputCallback:t=>se(this,Mt,"m",Yt).call(this,t),arrowClickCallback:()=>se(this,Mt,"m",Ft).call(this),mouseupCallback:()=>{var t;return null===(t=se(this,Nt,"f"))||void 0===t?void 0:t.focus()}}),{groupedNodes:i,nodes:l}=s.selectedNodes,n=new(0,e.TreeselectInput)({value:this.grouped?i:l,showTags:this.showTags,tagsCountText:this.tagsCountText,clearable:this.clearable,isAlwaysOpened:this.alwaysOpen,searchable:this.searchable,placeholder:this.placeholder,disabled:this.disabled,id:this.id,iconElements:this.iconElements,inputCallback:t=>se(this,Mt,"m",$t).call(this,t),searchCallback:t=>se(this,Mt,"m",zt).call(this,t),openCallback:()=>se(this,Mt,"m",Jt).call(this),closeCallback:()=>se(this,Mt,"m",Kt).call(this),keydownCallback:t=>se(this,Mt,"m",Rt).call(this,t),focusCallback:()=>se(this,Mt,"m",Ut).call(this)});return this.appendToBody&&ie(this,jt,new ResizeObserver((()=>this.updateListPosition())),"f"),t.append(n.srcElement),{container:t,list:s,input:n}},$t=function(t){var e,s,i;const l=le(t);null===(e=se(this,Wt,"f"))||void 0===e||e.updateValue(l);const n=null===(i=null===(s=se(this,Wt,"f"))||void 0===s?void 0:s.selectedNodes)||void 0===i?void 0:i.nodes;this.value=n?le(n):[],se(this,Mt,"m",ee).call(this)},Rt=function(t){var e;this.isListOpened&&(null===(e=se(this,Wt,"f"))||void 0===e||e.callKeyAction(t))},zt=function(t){var e;null===(e=se(this,Wt,"f"))||void 0===e||e.updateSearchValue(t),this.updateListPosition()},Ut=function(){se(this,Mt,"m",Qt).call(this,!0),se(this,It,"f")&&se(this,It,"f")&&se(this,Dt,"f")&&(document.addEventListener("mousedown",se(this,It,"f"),!0),document.addEventListener("focus",se(this,It,"f"),!0),window.addEventListener("blur",se(this,Dt,"f")))},Yt=function(t){var e,s;const{groupedNodes:i,nodes:l}=t,n=this.grouped?i:l;null===(e=se(this,Nt,"f"))||void 0===e||e.updateValue(n),this.value=le(l),null===(s=se(this,Nt,"f"))||void 0===s||s.focus(),se(this,Mt,"m",ee).call(this)},Ft=function(){var t;null===(t=se(this,Nt,"f"))||void 0===t||t.focus(),this.updateListPosition()},Jt=function(){var t;this.isListOpened=!0,se(this,Gt,"f")&&se(this,qt,"f")&&(window.addEventListener("scroll",se(this,Gt,"f"),!0),window.addEventListener("resize",se(this,qt,"f"))),se(this,Wt,"f")&&this.srcElement&&(this.appendToBody?(document.body.appendChild(se(this,Wt,"f").srcElement),null===(t=se(this,jt,"f"))||void 0===t||t.observe(this.srcElement)):this.srcElement.appendChild(se(this,Wt,"f").srcElement),this.updateListPosition(),se(this,Mt,"m",Zt).call(this,!0),se(this,Wt,"f").focusFirstListElement())},Kt=function(){var t;if(this.alwaysOpen)return;if(this.isListOpened=!1,se(this,Gt,"f")&&se(this,qt,"f")&&(window.removeEventListener("scroll",se(this,Gt,"f"),!0),window.removeEventListener("resize",se(this,qt,"f"))),!se(this,Wt,"f")||!this.srcElement)return;(this.appendToBody?document.body.contains(se(this,Wt,"f").srcElement):this.srcElement.contains(se(this,Wt,"f").srcElement))&&(this.appendToBody?(document.body.removeChild(se(this,Wt,"f").srcElement),null===(t=se(this,jt,"f"))||void 0===t||t.disconnect()):this.srcElement.removeChild(se(this,Wt,"f").srcElement),se(this,Mt,"m",Zt).call(this,!1))},Xt=function(t,e){if(!se(this,Wt,"f")||!se(this,Nt,"f"))return;const s=e?"treeselect-list--top-to-body":"treeselect-list--top",i=e?"treeselect-list--bottom-to-body":"treeselect-list--bottom";t?(se(this,Wt,"f").srcElement.classList.add(s),se(this,Wt,"f").srcElement.classList.remove(i),se(this,Nt,"f").srcElement.classList.add("treeselect-input--top"),se(this,Nt,"f").srcElement.classList.remove("treeselect-input--bottom")):(se(this,Wt,"f").srcElement.classList.remove(s),se(this,Wt,"f").srcElement.classList.add(i),se(this,Nt,"f").srcElement.classList.remove("treeselect-input--top"),se(this,Nt,"f").srcElement.classList.add("treeselect-input--bottom"))},Qt=function(t){se(this,Nt,"f")&&se(this,Wt,"f")&&(t?(se(this,Nt,"f").srcElement.classList.add("treeselect-input--focused"),se(this,Wt,"f").srcElement.classList.add("treeselect-list--focused")):(se(this,Nt,"f").srcElement.classList.remove("treeselect-input--focused"),se(this,Wt,"f").srcElement.classList.remove("treeselect-list--focused")))},Zt=function(t){var e,s,i,l;t?null===(e=se(this,Nt,"f"))||void 0===e||e.srcElement.classList.add("treeselect-input--opened"):null===(s=se(this,Nt,"f"))||void 0===s||s.srcElement.classList.remove("treeselect-input--opened"),this.staticList?null===(i=se(this,Wt,"f"))||void 0===i||i.srcElement.classList.add("treeselect-list--static"):null===(l=se(this,Wt,"f"))||void 0===l||l.srcElement.classList.remove("treeselect-list--static")},te=function(t){se(this,Gt,"f")&&se(this,qt,"f")&&se(this,It,"f")&&se(this,Dt,"f")&&(this.alwaysOpen&&!t||(window.removeEventListener("scroll",se(this,Gt,"f"),!0),window.removeEventListener("resize",se(this,qt,"f"))),document.removeEventListener("mousedown",se(this,It,"f"),!0),document.removeEventListener("focus",se(this,It,"f"),!0),window.removeEventListener("blur",se(this,Dt,"f")))},ee=function(){var t;null===(t=this.srcElement)||void 0===t||t.dispatchEvent(new CustomEvent("input",{detail:this.value})),this.inputCallback&&this.inputCallback(this.value)};
|
package/dist/treeselect-js.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.treeselect-input{width:100%;box-sizing:border-box;min-height:37px;cursor:text;background-color:#fff;border:1px solid #d7dde4;border-radius:4px;flex-wrap:wrap;align-items:center;padding:2px 40px 2px 4px;display:flex;position:relative}.treeselect-input--unsearchable{cursor:default}.treeselect-input--unsearchable .treeselect-input__edit{caret-color:#0000;cursor:default}.treeselect-input--unsearchable .treeselect-input__edit:focus{z-index:-1;position:absolute}.treeselect-input--value-not-selected .treeselect-input__edit{width:auto;z-index:auto}.treeselect-input--value-not-selected .treeselect-input__tags{gap:0}.treeselect-input__tags{max-width:100%;box-sizing:border-box;flex-wrap:wrap;align-items:center;gap:4px;display:inline-flex}.treeselect-input__tags-element{cursor:pointer;max-width:100%;box-sizing:border-box;background-color:#d7dde4;border-radius:2px;align-items:center;padding:2px 5px;font-size:14px;display:inline-flex}.treeselect-input__tags-element:hover{background-color:#c5c7cb}.treeselect-input__tags-element:hover .treeselect-input__tags-cross svg{stroke:#eb4c42}.treeselect-input__tags-name{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.treeselect-input__tags-cross{margin-left:2px;display:flex}.treeselect-input__tags-cross svg{width:12px;height:12px}.treeselect-input__tags-count{white-space:nowrap;text-overflow:ellipsis;font-size:14px;overflow:hidden}.treeselect-input__edit{width:0;z-index:-1;min-width:0;border:none;flex:1;font-size:14px;position:absolute}.treeselect-input__edit:focus{min-width:30px;z-index:auto;width:auto;outline:none;position:static}.treeselect-input__operators{max-width:40px;display:flex;position:absolute;right:2px}.treeselect-input__clear{cursor:pointer;display:flex}.treeselect-input__clear svg{stroke:#c5c7cb;width:17px;min-width:17px;height:20px}.treeselect-input__clear:hover svg{stroke:#838790}.treeselect-input__arrow{cursor:pointer;display:flex}.treeselect-input__arrow svg{stroke:#c5c7cb;width:20px;min-width:20px;height:20px}.treeselect-input__arrow:hover svg{stroke:#838790}.treeselect-list{width:100%;box-sizing:border-box;max-height:300px;background-color:#fff;border:1px solid #d7dde4;overflow-y:auto}.treeselect-list__group-container{box-sizing:border-box}.treeselect-list__item{box-sizing:border-box;cursor:pointer;height:30px;align-items:center;display:flex}.treeselect-list__item:focus{outline:none}.treeselect-list__item--focused{background-color:azure!important}.treeselect-list__item--hidden{display:none}.treeselect-list__item-icon{cursor:pointer;height:20px;width:20px;min-width:20px;align-items:center;display:flex}.treeselect-list__item-icon svg{pointer-events:none;width:100%;height:100%;stroke:#c5c7cb}.treeselect-list__item-icon *{pointer-events:none}.treeselect-list__item-icon:hover svg{stroke:#838790}.treeselect-list__item-checkbox-container{width:20px;height:20px;min-width:20px;pointer-events:none;box-sizing:border-box;background-color:#fff;border:1px solid #d7dde4;border-radius:3px;position:relative}.treeselect-list__item-checkbox-container svg{height:100%;width:100%;position:absolute}.treeselect-list__item-checkbox{width:0;height:0;pointer-events:none;z-index:-1;margin:0;position:absolute}.treeselect-list__item-checkbox-icon{height:100%;width:100%;position:absolute;top:0;left:0}.treeselect-list__item-label{width:100%;text-overflow:ellipsis;word-break:keep-all;white-space:nowrap;pointer-events:none;padding-left:5px;font-size:14px;overflow:hidden}.treeselect-list__empty{height:30px;align-items:center;padding-left:4px;display:flex}.treeselect-list__empty--hidden{display:none}.treeselect-list__empty-icon{align-items:center;display:flex}.treeselect-list__empty-text{text-overflow:ellipsis;word-break:keep-all;white-space:nowrap;padding-left:5px;font-size:14px;overflow:hidden}.treeselect-list__slot{box-sizing:border-box;width:100%;max-width:100%;background-color:#fff;position:sticky;bottom:0}.treeselect-list__item .treeselect-list__item-checkbox-container svg{stroke:#0000}.treeselect-list__item--checked .treeselect-list__item-checkbox-container svg,.treeselect-list__item--partial-checked .treeselect-list__item-checkbox-container svg{stroke:#fff}.treeselect-list__item--checked .treeselect-list__item-checkbox-container,.treeselect-list__item--partial-checked .treeselect-list__item-checkbox-container{background-color:#52c67e}.treeselect{width:100%;box-sizing:border-box;position:relative}.treeselect--disabled{pointer-events:none}.treeselect-list{box-sizing:border-box;z-index:1000;border-radius:4px;position:absolute;left:0}.treeselect .treeselect-list{position:absolute}.treeselect .treeselect-list--static{position:static}.treeselect-input--focused{border-color:#101010}.treeselect-input--opened.treeselect-input--top{border-top-color:#0000;border-top-left-radius:0;border-top-right-radius:0}.treeselect-input--opened.treeselect-input--bottom{border-bottom-color:#0000;border-bottom-left-radius:0;border-bottom-right-radius:0}.treeselect-list--focused{border-color:#101010}.treeselect-list--top,.treeselect-list--top-to-body{border-bottom-color:#d7dde4;border-bottom-left-radius:0;border-bottom-right-radius:0}.treeselect-list--bottom,.treeselect-list--bottom-to-body{border-top-color:#d7dde4;border-top-left-radius:0;border-top-right-radius:0}.treeselect-list--top{bottom:100%;left:0}.treeselect-list--bottom{top:100%;left:0}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function t(t,e,s,i){Object.defineProperty(t,e,{get:s,set:i,enumerable:!0,configurable:!0})}var e={};t(e,"Treeselect",(function(){return oe}),(function(t){return oe=t}));var s={};t(s,"TreeselectInput",(function(){return N}),(function(t){return N=t}));const i={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>'},l=(t,e)=>{if(e.innerHTML="","string"==typeof t)e.innerHTML=t;else{const s=t.cloneNode(!0);e.appendChild(s)}},n=t=>{const e=t?Object.assign({},t):{};return Object.keys(i).forEach((t=>{e[t]||(e[t]=i[t])})),e};var o,c,a,r,h,d,u,p,m,f,v,w,E,g,k,b,L,y,C,_,x,T,O,A,S,H,P,B,M=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},W=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};class N{focus(){M(this,a,"f").focus()}blur(){this.isOpened&&M(this,o,"m",v).call(this),this.searchText="",this.searchCallback(""),M(this,o,"m",f).call(this),M(this,a,"f").blur()}updateValue(t){this.value=t,M(this,o,"m",u).call(this),M(this,o,"m",f).call(this)}removeItem(t){this.value=this.value.filter((e=>e.id!==t)),M(this,o,"m",B).call(this),M(this,o,"m",u).call(this),M(this,o,"m",f).call(this)}clear(){this.value=[],this.searchText="",this.searchCallback(""),M(this,o,"m",B).call(this),M(this,o,"m",u).call(this),M(this,o,"m",f).call(this)}openClose(){M(this,o,"m",v).call(this)}constructor({value:t,showTags:e,tagsCountText:s,clearable:i,isAlwaysOpened:l,searchable:n,placeholder:u,disabled:p,id:m,iconElements:f,inputCallback:v,searchCallback:E,openCallback:k,closeCallback:b,keydownCallback:L,focusCallback:y}){o.add(this),c.set(this,void 0),a.set(this,void 0),r.set(this,void 0),h.set(this,void 0),this.value=t,this.showTags=e,this.tagsCountText=s,this.searchable=n,this.placeholder=u,this.clearable=i,this.isAlwaysOpened=l,this.disabled=p,this.id=m,this.iconElements=f,this.isOpened=!1,this.searchText="",W(this,c,M(this,o,"m",g).call(this),"f"),W(this,a,M(this,o,"m",_).call(this),"f"),W(this,r,M(this,o,"m",O).call(this),"f"),W(this,h,null,"f"),this.inputCallback=v,this.searchCallback=E,this.openCallback=k,this.closeCallback=b,this.keydownCallback=L,this.focusCallback=y,this.srcElement=M(this,o,"m",w).call(this,M(this,c,"f"),M(this,a,"f"),M(this,r,"f")),M(this,o,"m",d).call(this)}}c=new WeakMap,a=new WeakMap,r=new WeakMap,h=new WeakMap,o=new WeakSet,d=function(){M(this,o,"m",u).call(this),M(this,o,"m",f).call(this),M(this,o,"m",p).call(this)},u=function(){M(this,c,"f").innerHTML="",this.showTags?M(this,c,"f").append(...M(this,o,"m",k).call(this)):M(this,c,"f").appendChild(M(this,o,"m",C).call(this)),M(this,c,"f").appendChild(M(this,a,"f"))},p=function(){const t=[];M(this,r,"f").innerHTML="",this.clearable&&t.push(M(this,o,"m",A).call(this)),this.isAlwaysOpened||t.push(M(this,o,"m",H).call(this,this.isOpened)),t.length&&M(this,r,"f").append(...t)},m=function(){if(!this.isAlwaysOpened&&M(this,h,"f")){const t=this.isOpened?this.iconElements.arrowUp:this.iconElements.arrowDown;l(t,M(this,h,"f"))}},f=function(){var t;(null===(t=this.value)||void 0===t?void 0:t.length)?(M(this,a,"f").removeAttribute("placeholder"),this.srcElement.classList.remove("treeselect-input--value-not-selected")):(M(this,a,"f").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"),M(this,a,"f").value=this.searchText},v=function(){this.isOpened=!this.isOpened,M(this,o,"m",m).call(this),this.isOpened?this.openCallback():this.closeCallback()},w=function(t,e,s){const i=document.createElement("div");return i.classList.add("treeselect-input"),i.setAttribute("tabindex","-1"),i.addEventListener("mousedown",(t=>M(this,o,"m",E).call(this,t))),i.addEventListener("focus",(()=>this.focusCallback()),!0),t.appendChild(e),i.append(t,s),i},E=function(t){t.preventDefault(),this.isOpened||M(this,o,"m",v).call(this),this.focus()},g=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__tags"),t},k=function(){return this.value.map((t=>{const e=document.createElement("div");e.classList.add("treeselect-input__tags-element"),e.setAttribute("tabindex","-1"),e.setAttribute("tag-id",t.id.toString()),e.setAttribute("title",t.name);const s=M(this,o,"m",L).call(this,t.name),i=M(this,o,"m",y).call(this);return e.addEventListener("mousedown",(e=>M(this,o,"m",b).call(this,e,t.id))),e.append(s,i),e}))},b=function(t,e){t.preventDefault(),t.stopPropagation(),this.removeItem(e),this.focus()},L=function(t){const e=document.createElement("span");return e.classList.add("treeselect-input__tags-name"),e.innerHTML=t,e},y=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-cross"),l(this.iconElements.cross,t),t},C=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__tags-count"),this.value.length?(t.innerHTML=1===this.value.length?this.value[0].name:`${this.value.length} ${this.tagsCountText}`,t):(t.innerHTML="",t)},_=function(){const t=document.createElement("input");return t.classList.add("treeselect-input__edit"),t.setAttribute("id",this.id),this.disabled&&t.setAttribute("tabindex","-1"),t.addEventListener("keydown",(t=>M(this,o,"m",x).call(this,t))),t.addEventListener("input",(e=>M(this,o,"m",T).call(this,e,t))),t},x=function(t){"Backspace"!==t.key||this.searchText.length||!this.value.length||this.showTags||this.clear(),"Backspace"===t.key&&!this.searchText.length&&this.value.length&&this.removeItem(this.value[this.value.length-1].id),"Space"!==t.code||this.searchText&&this.searchable||M(this,o,"m",v).call(this),this.keydownCallback(t.key),this.focus()},T=function(t,e){t.stopPropagation();const s=this.searchText,i=e.value.trim();if(0!==s.length||0!==i.length){if(this.searchable){const e=t.target.value;this.searchCallback(e),this.isOpened||M(this,o,"m",v).call(this)}else e.value="";this.searchText=e.value}else e.value=""},O=function(){const t=document.createElement("div");return t.classList.add("treeselect-input__operators"),t},A=function(){const t=document.createElement("span");return t.classList.add("treeselect-input__clear"),t.setAttribute("tabindex","-1"),l(this.iconElements.clear,t),t.addEventListener("mousedown",(t=>M(this,o,"m",S).call(this,t))),t},S=function(t){t.preventDefault(),t.stopPropagation(),(this.searchText.length||this.value.length)&&this.clear(),this.focus()},H=function(t){W(this,h,document.createElement("span"),"f"),M(this,h,"f").classList.add("treeselect-input__arrow");const e=t?this.iconElements.arrowUp:this.iconElements.arrowDown;return l(e,M(this,h,"f")),M(this,h,"f").addEventListener("mousedown",(t=>M(this,o,"m",P).call(this,t))),M(this,h,"f")},P=function(t){t.stopPropagation(),t.preventDefault(),this.focus(),M(this,o,"m",v).call(this)},B=function(){this.inputCallback(this.value)};var j={};t(j,"TreeselectList",(function(){return Mt}),(function(t){return Mt=t}));const G=(t,e,s="",i=0)=>t.reduce(((t,l)=>{var n;const o=!!(null===(n=l.children)||void 0===n?void 0:n.length),c=i>=e&&o,a=i>e;if(t.push({id:l.value,name:l.name,childOf:s,isGroup:o,checked:!1,isPartialChecked:!1,level:i,isClosed:c,hidden:a}),o){const s=G(l.children,e,l.value,i+1);t.push(...s)}return t}),[]),q=({id:t,checked:e},s)=>{s.forEach((i=>{i.childOf===t&&(i.checked=null==e||e,i.isPartialChecked=!1,i.isGroup&&q(i,s))}))},I=(t,e)=>{const s=e.find((e=>e.id===t)),i=e.filter((t=>t.childOf===(null==s?void 0:s.id)));if(!s)return;const l=i.every((t=>t.checked)),n=i.some((t=>t.isPartialChecked||t.checked))&&!l,o=!l&&!n;l&&(s.checked=!0,s.isPartialChecked=!1),n&&(s.checked=!1,s.isPartialChecked=!0),o&&(s.checked=!1,s.isPartialChecked=!1),s.childOf&&I(s.childOf,e)},D=({id:t,isGroup:e,childOf:s,checked:i},l)=>{e&&q({id:t,checked:i},l),s&&I(s,l)},V=(t,e)=>e.reduce(((s,i)=>(i.childOf===t&&(s.push(i),i.isGroup&&s.push(...V(i.id,e))),s)),[]),$=(t,e)=>e.reduce(((s,i)=>(i.id===t&&(s.push(i),i.childOf&&s.push(...$(i.childOf,e))),s)),[]),R=t=>{const{onlyGroupsIds:e,allItems:s}=t.reduce(((t,e)=>e.checked?(e.isGroup&&t.onlyGroupsIds.push(e.id),t.allItems.push(e),t):t),{onlyGroupsIds:[],allItems:[]});return s.filter((t=>!e.some((e=>e===t.childOf))))},z=(t,{id:e,isClosed:s})=>{t.filter((t=>t.childOf===e)).forEach((e=>{e.hidden=null!=s&&s,e.isGroup&&!e.isClosed&&z(t,{id:e.id,isClosed:s})}))},U=(t,e)=>{const s=((t,e)=>t.reduce(((s,i)=>{if(i.name.toLowerCase().includes(e.toLowerCase())){if(s.push(i),i.isGroup){const e=V(i.id,t);s.push(...e)}if(i.childOf){const e=$(i.childOf,t);s.push(...e)}}return s}),[]))(t,e);t.forEach((e=>{s.some((t=>t.id===e.id))?(e.isGroup&&(e.isClosed=!1,z(t,e)),e.hidden=!1):e.hidden=!0}))},Y=(t,e)=>{(t=>{t.forEach((t=>{t.checked=!1,t.isPartialChecked=!1}))})(e);e.filter((e=>t.some((t=>t===e.id)))).forEach((t=>{t.checked=!0,t.isPartialChecked=!1,D(t,e)}))};var F,J,K,X,Q,Z,tt,et,st,it,lt,nt,ot,ct,at,rt,ht,dt,ut,pt,mt,ft,vt,wt,Et,gt,kt,bt=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},Lt=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const yt=(t,e,s,i)=>{Y(t,e),Ct(e,s,i)},Ct=(t,e,s)=>{t.forEach((i=>{const l=e.querySelector(`[input-id="${i.id}"]`),n=Pt(l);l.checked=i.checked,_t(i,n),xt(i,n),Tt(i,n,s),Ot(i,n),St(i,n,t),At(i,l,s)})),Ht(t,e)},_t=(t,e)=>{t.checked?e.classList.add("treeselect-list__item--checked"):e.classList.remove("treeselect-list__item--checked")},xt=(t,e)=>{t.isPartialChecked?e.classList.add("treeselect-list__item--partial-checked"):e.classList.remove("treeselect-list__item--partial-checked")},Tt=(t,e,s)=>{if(t.isGroup){const i=e.querySelector(".treeselect-list__item-icon"),n=t.isClosed?s.arrowRight:s.arrowDown;l(n,i),t.isClosed?e.classList.add("treeselect-list__item--closed"):e.classList.remove("treeselect-list__item--closed")}},Ot=(t,e)=>{t.hidden?e.classList.add("treeselect-list__item--hidden"):e.classList.remove("treeselect-list__item--hidden")},At=(t,e,s)=>{const i=e.parentNode.querySelector(".treeselect-list__item-checkbox-icon");t.checked?l(s.check,i):t.isPartialChecked?l(s.partialCheck,i):i.innerHTML=""},St=(t,e,s)=>{if(0===t.level){const i=s.some((e=>e.isGroup&&e.level===t.level)),l=!t.isGroup&&i?"20px":"5px";e.style.paddingLeft=t.isGroup?"0":l}else e.style.paddingLeft=t.isGroup?20*t.level+"px":20*t.level+20+"px";e.setAttribute("level",t.level.toString()),e.setAttribute("group",t.isGroup.toString())},Ht=(t,e)=>{const s=t.some((t=>!t.hidden)),i=e.querySelector(".treeselect-list__empty");s?i.classList.add("treeselect-list__empty--hidden"):i.classList.remove("treeselect-list__empty--hidden")},Pt=t=>t.parentNode.parentNode,Bt=(t,e)=>e.find((e=>e.id.toString()===t));class Mt{updateValue(t){yt(t,this.flattedOptions,this.srcElement,this.iconElements),bt(this,F,"m",gt).call(this)}updateSearchValue(t){if(t===this.searchText)return;const e=""===this.searchText&&""!==t;this.searchText=t,e&&(this.flattedOptionsBeforeSearch=JSON.parse(JSON.stringify(this.flattedOptions))),""===this.searchText&&(this.flattedOptions=this.flattedOptionsBeforeSearch.map((t=>{const e=this.flattedOptions.find((e=>e.id===t.id));return e.isClosed=t.isClosed,e.hidden=t.hidden,e})),this.flattedOptionsBeforeSearch=[]),this.searchText&&U(this.flattedOptions,t),Ct(this.flattedOptions,this.srcElement,this.iconElements),this.focusFirstListElement()}callKeyAction(t){Lt(this,K,!1,"f");const e=this.srcElement.querySelector(".treeselect-list__item--focused");"Enter"===t&&e&&e.dispatchEvent(new Event("mousedown")),"ArrowLeft"!==t&&"ArrowRight"!==t||bt(this,F,"m",X).call(this,e,t),"ArrowDown"!==t&&"ArrowUp"!==t||bt(this,F,"m",Q).call(this,e,t)}focusFirstListElement(){const t="treeselect-list__item--focused",e=this.srcElement.querySelector(`.${t}`),s=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Pt(t)).display));if(!s.length)return;e&&e.classList.remove(t);Pt(s[0]).classList.add(t)}constructor({options:t,value:e,openLevel:s,listSlotHtmlComponent:i,emptyText:l,iconElements:n,inputCallback:o,arrowClickCallback:c,mouseupCallback:a}){F.add(this),J.set(this,null),K.set(this,!0),this.options=t,this.value=e,this.openLevel=null!=s?s:0,this.listSlotHtmlComponent=null!=i?i:null,this.emptyText=null!=l?l:"No results found...",this.iconElements=n,this.searchText="",this.flattedOptions=G(this.options,this.openLevel),this.flattedOptionsBeforeSearch=this.flattedOptions,this.selectedNodes={nodes:[],groupedNodes:[]},this.srcElement=bt(this,F,"m",Z).call(this),this.inputCallback=o,this.arrowClickCallback=c,this.mouseupCallback=a,this.updateValue(this.value),(t=>{const{duplications:e}=t.reduce(((t,e)=>(t.allItems.some((t=>t.toString()===e.id.toString()))&&t.duplications.push(e.id),t.allItems.push(e.id),t)),{duplications:[],allItems:[]});e.length&&console.error(`Validation: You have duplicated values: ${e.join(", ")}! You should use unique values.`)})(this.flattedOptions)}}J=new WeakMap,K=new WeakMap,F=new WeakSet,X=function(t,e){if(!t)return;const s=t.querySelector(".treeselect-list__item-checkbox").getAttribute("input-id"),i=Bt(s,this.flattedOptions),l=t.querySelector(".treeselect-list__item-icon");"ArrowLeft"!==e||i.isClosed||l.dispatchEvent(new Event("mousedown")),"ArrowRight"===e&&i.isClosed&&l.dispatchEvent(new Event("mousedown"))},Q=function(t,e){var s;const i=Array.from(this.srcElement.querySelectorAll(".treeselect-list__item-checkbox")).filter((t=>"none"!==window.getComputedStyle(Pt(t)).display));if(i.length)if(t){const t=i.findIndex((t=>Pt(t).classList.contains("treeselect-list__item--focused")));Pt(i[t]).classList.remove("treeselect-list__item--focused");const l="ArrowDown"===e?t+1:t-1,n="ArrowDown"===e?0:i.length-1,o=null!==(s=i[l])&&void 0!==s?s:i[n],c=!i[l],a=Pt(o);a.classList.add("treeselect-list__item--focused");const r=this.srcElement.getBoundingClientRect(),h=a.getBoundingClientRect();if(c&&"ArrowDown"===e)return void this.srcElement.scroll(0,0);if(c&&"ArrowUp"===e)return void this.srcElement.scroll(0,this.srcElement.scrollHeight);if(r.y+r.height<h.y+h.height)return void this.srcElement.scroll(0,this.srcElement.scrollTop+h.height);if(r.y>h.y)return void this.srcElement.scroll(0,this.srcElement.scrollTop-h.height)}else{Pt(i[0]).classList.add("treeselect-list__item--focused")}},Z=function(){const t=bt(this,F,"m",tt).call(this),e=bt(this,F,"m",it).call(this,this.options);t.append(...e);const s=bt(this,F,"m",lt).call(this);s&&t.append(s);const i=bt(this,F,"m",nt).call(this);return t.append(i),t},tt=function(){const t=document.createElement("div");return t.classList.add("treeselect-list"),t.addEventListener("mouseout",(t=>bt(this,F,"m",et).call(this,t))),t.addEventListener("mousemove",(()=>bt(this,F,"m",st).call(this))),t.addEventListener("mouseup",(()=>this.mouseupCallback()),!0),t},et=function(t){t.stopPropagation(),bt(this,J,"f")&&bt(this,K,"f")&&bt(this,J,"f").classList.add("treeselect-list__item--focused")},st=function(){Lt(this,K,!0,"f")},it=function t(e){return e.reduce(((e,s)=>{var i;if(null===(i=s.children)||void 0===i?void 0:i.length){const i=bt(this,F,"m",ot).call(this,s),l=bt(this,F,"m",t).call(this,s.children);return i.append(...l),e.push(i),e}const l=bt(this,F,"m",ct).call(this,s,!1);return e.push(l),e}),[])},lt=function(){if(!this.listSlotHtmlComponent)return null;const t=document.createElement("div");return t.classList.add("treeselect-list__slot"),t.appendChild(this.listSlotHtmlComponent),t},nt=function(){const t=document.createElement("div");t.classList.add("treeselect-list__empty"),t.setAttribute("title",this.emptyText);const e=document.createElement("span");e.classList.add("treeselect-list__empty-icon"),l(this.iconElements.attention,e);const s=document.createElement("span");return s.classList.add("treeselect-list__empty-text"),s.innerHTML=this.emptyText,t.append(e,s),t},ot=function(t){const e=document.createElement("div");e.setAttribute("group-container-id",t.value.toString()),e.classList.add("treeselect-list__group-container");const s=bt(this,F,"m",ct).call(this,t,!0);return e.appendChild(s),e},ct=function(t,e){const s=bt(this,F,"m",at).call(this,t);if(e){const t=bt(this,F,"m",ut).call(this);s.appendChild(t)}const i=bt(this,F,"m",mt).call(this,t),l=bt(this,F,"m",ft).call(this,t);return s.append(i,l),s},at=function(t){const e=document.createElement("div");return e.setAttribute("tabindex","-1"),e.setAttribute("title",t.name),e.classList.add("treeselect-list__item"),e.addEventListener("mouseover",(()=>bt(this,F,"m",rt).call(this,e)),!0),e.addEventListener("mouseout",(()=>bt(this,F,"m",ht).call(this,e)),!0),e.addEventListener("mousedown",(e=>bt(this,F,"m",dt).call(this,e,t))),e},rt=function(t){bt(this,K,"f")&&bt(this,F,"m",Et).call(this,!0,t)},ht=function(t){bt(this,K,"f")&&(bt(this,F,"m",Et).call(this,!1,t),Lt(this,J,t,"f"))},dt=function(t,e){t.stopPropagation();const s=t.target.querySelector(".treeselect-list__item-checkbox");s.checked=!s.checked,bt(this,F,"m",vt).call(this,s,e)},ut=function(){const t=document.createElement("span");return t.setAttribute("tabindex","-1"),t.classList.add("treeselect-list__item-icon"),l(this.iconElements.arrowDown,t),t.addEventListener("mousedown",(t=>bt(this,F,"m",pt).call(this,t))),t},pt=function(t){t.stopPropagation(),bt(this,F,"m",wt).call(this,t)},mt=function(t){const e=document.createElement("div");e.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");return i.setAttribute("tabindex","-1"),i.setAttribute("type","checkbox"),i.setAttribute("input-id",t.value.toString()),i.classList.add("treeselect-list__item-checkbox"),e.append(s,i),e},ft=function(t){const e=document.createElement("label");return e.innerHTML=t.name,e.classList.add("treeselect-list__item-label"),e},vt=function(t,e){const s=this.flattedOptions.find((t=>t.id===e.value));s&&(s.checked=t.checked,s.isPartialChecked=!1,D(s,this.flattedOptions),Ct(this.flattedOptions,this.srcElement,this.iconElements),bt(this,F,"m",kt).call(this))},wt=function(t){var e,s,i;const l=null===(s=null===(e=t.target)||void 0===e?void 0:e.parentNode)||void 0===s?void 0:s.querySelector("[input-id]"),n=null!==(i=null==l?void 0:l.getAttribute("input-id"))&&void 0!==i?i:null,o=Bt(n,this.flattedOptions);o&&(o.isClosed=!o.isClosed,z(this.flattedOptions,o),Ct(this.flattedOptions,this.srcElement,this.iconElements),this.arrowClickCallback())},Et=function(t,e){const s="treeselect-list__item--focused";if(t){const t=Array.from(this.srcElement.querySelectorAll(`.${s}`));t.length&&t.forEach((t=>t.classList.remove(s))),e.classList.add(s)}else e.classList.remove(s)},gt=function(){var t;this.selectedNodes={nodes:(t=this.flattedOptions,t.filter((t=>t.checked&&!t.isGroup))),groupedNodes:R(this.flattedOptions)}},kt=function(){bt(this,F,"m",gt).call(this),this.inputCallback(this.selectedNodes)};var Wt,Nt,jt,Gt,qt,It,Dt,Vt,$t,Rt,zt,Ut,Yt,Ft,Jt,Kt,Xt,Qt,Zt,te,ee,se,ie=function(t,e,s,i){if("a"===s&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?i:"a"===s?i.call(t):i?i.value:e.get(t)},le=function(t,e,s,i,l){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!l:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?l.call(t,s):l?l.value=s:e.set(t,s),s};const ne=t=>t.map((t=>t.id));class oe{mount(){var t;this.destroy();const{container:e,list:s,input:i}=ie(this,Wt,"m",$t).call(this);this.srcElement=e,le(this,Nt,s,"f"),le(this,jt,i,"f"),le(this,qt,this.scrollWindowHandler.bind(this),"f"),le(this,It,this.scrollWindowHandler.bind(this),"f"),le(this,Dt,this.focusWindowHandler.bind(this),"f"),le(this,Vt,this.blurWindowHandler.bind(this),"f"),this.alwaysOpen&&(null===(t=ie(this,jt,"f"))||void 0===t||t.openClose()),this.disabled&&this.srcElement.classList.add("treeselect--disabled")}updateValue(t){var e;const s=ie(this,Nt,"f");if(s){s.updateValue(t);const{groupedNodes:i,nodes:l}=s.selectedNodes,n=this.grouped?i:l;null===(e=ie(this,jt,"f"))||void 0===e||e.updateValue(n)}}destroy(){this.srcElement&&(ie(this,Wt,"m",Xt).call(this),this.srcElement.innerHTML="",this.srcElement=null,ie(this,Wt,"m",ee).call(this,!0))}focus(){ie(this,jt,"f")&&ie(this,jt,"f").focus()}toggleOpenClose(){ie(this,jt,"f")&&(ie(this,jt,"f").openClose(),ie(this,jt,"f").focus())}scrollWindowHandler(){this.updateListPosition()}focusWindowHandler(t){var e,s,i;(null===(e=this.srcElement)||void 0===e?void 0:e.contains(t.target))||(null===(s=ie(this,Nt,"f"))||void 0===s?void 0:s.srcElement.contains(t.target))||(null===(i=ie(this,jt,"f"))||void 0===i||i.blur(),ie(this,Wt,"m",ee).call(this,!1),ie(this,Wt,"m",Zt).call(this,!1))}blurWindowHandler(){var t;null===(t=ie(this,jt,"f"))||void 0===t||t.blur(),ie(this,Wt,"m",ee).call(this,!1),ie(this,Wt,"m",Zt).call(this,!1)}updateListPosition(){var t;const e=this.srcElement,s=null===(t=ie(this,Nt,"f"))||void 0===t?void 0:t.srcElement;if(!e||!s)return;s.style.transform="";const{y:i,height:l}=s.getBoundingClientRect(),{x:n,y:o,height:c,width:a}=e.getBoundingClientRect(),r=window.innerHeight-o-c,h=o>r&&o>=l&&r<l;this.appendToBody&&(s.style.transform=h?`translateY(${o-i-l}px)`:`translateY(${o+c-i}px)`,s.style.width=`${a}px`,s.style.left=`${n+window.scrollX}px`);const d=h?"top":"bottom";s.getAttribute("direction")!==d&&(s.setAttribute("direction",d),ie(this,Wt,"m",Qt).call(this,h,this.appendToBody))}constructor({parentHtmlContainer:t,value:e,options:s,openLevel:i,appendToBody:l,alwaysOpen:o,showTags:c,tagsCountText:a,clearable:r,searchable:h,placeholder:d,grouped:u,listSlotHtmlComponent:p,disabled:m,emptyText:f,staticList:v,id:w,iconElements:E,inputCallback:g}){Wt.add(this),Nt.set(this,null),jt.set(this,null),Gt.set(this,null),qt.set(this,null),It.set(this,null),Dt.set(this,null),Vt.set(this,null),(({parentHtmlContainer:t,staticList:e,appendToBody:s})=>{t||console.error("Validation: parentHtmlContainer prop is required!"),e&&s&&console.error("Validation: You should set staticList to false if you use appendToBody!")})({parentHtmlContainer:t,staticList:v,appendToBody:l}),this.parentHtmlContainer=t,this.value=null!=e?e:[],this.options=null!=s?s:[],this.openLevel=null!=i?i:0,this.appendToBody=null==l||l,this.alwaysOpen=!(!o||m),this.showTags=null==c||c,this.tagsCountText=null!=a?a:"elements selected",this.clearable=null==r||r,this.searchable=null==h||h,this.placeholder=null!=d?d:"Search...",this.grouped=null==u||u,this.listSlotHtmlComponent=null!=p?p:null,this.disabled=null!=m&&m,this.emptyText=null!=f?f:"No results found...",this.staticList=!(!v||this.appendToBody),this.id=null!=w?w:"",this.iconElements=n(E),this.inputCallback=g,this.isListOpened=!1,this.srcElement=null,this.mount()}}Nt=new WeakMap,jt=new WeakMap,Gt=new WeakMap,qt=new WeakMap,It=new WeakMap,Dt=new WeakMap,Vt=new WeakMap,Wt=new WeakSet,$t=function(){const t=this.parentHtmlContainer;t.classList.add("treeselect");const e=new(0,j.TreeselectList)({options:this.options,value:this.value,openLevel:this.openLevel,listSlotHtmlComponent:this.listSlotHtmlComponent,emptyText:this.emptyText,iconElements:this.iconElements,inputCallback:t=>ie(this,Wt,"m",Ft).call(this,t),arrowClickCallback:()=>ie(this,Wt,"m",Jt).call(this),mouseupCallback:()=>{var t;return null===(t=ie(this,jt,"f"))||void 0===t?void 0:t.focus()}}),{groupedNodes:i,nodes:l}=e.selectedNodes,n=new(0,s.TreeselectInput)({value:this.grouped?i:l,showTags:this.showTags,tagsCountText:this.tagsCountText,clearable:this.clearable,isAlwaysOpened:this.alwaysOpen,searchable:this.searchable,placeholder:this.placeholder,disabled:this.disabled,id:this.id,iconElements:this.iconElements,inputCallback:t=>ie(this,Wt,"m",Rt).call(this,t),searchCallback:t=>ie(this,Wt,"m",Ut).call(this,t),openCallback:()=>ie(this,Wt,"m",Kt).call(this),closeCallback:()=>ie(this,Wt,"m",Xt).call(this),keydownCallback:t=>ie(this,Wt,"m",zt).call(this,t),focusCallback:()=>ie(this,Wt,"m",Yt).call(this)});return this.appendToBody&&le(this,Gt,new ResizeObserver((()=>this.updateListPosition())),"f"),t.append(n.srcElement),{container:t,list:e,input:n}},Rt=function(t){var e,s,i;const l=ne(t);null===(e=ie(this,Nt,"f"))||void 0===e||e.updateValue(l);const n=null===(i=null===(s=ie(this,Nt,"f"))||void 0===s?void 0:s.selectedNodes)||void 0===i?void 0:i.nodes;this.value=n?ne(n):[],ie(this,Wt,"m",se).call(this)},zt=function(t){var e;this.isListOpened&&(null===(e=ie(this,Nt,"f"))||void 0===e||e.callKeyAction(t))},Ut=function(t){var e;null===(e=ie(this,Nt,"f"))||void 0===e||e.updateSearchValue(t),this.updateListPosition()},Yt=function(){ie(this,Wt,"m",Zt).call(this,!0),ie(this,Dt,"f")&&ie(this,Dt,"f")&&ie(this,Vt,"f")&&(document.addEventListener("mousedown",ie(this,Dt,"f"),!0),document.addEventListener("focus",ie(this,Dt,"f"),!0),window.addEventListener("blur",ie(this,Vt,"f")))},Ft=function(t){var e,s;const{groupedNodes:i,nodes:l}=t,n=this.grouped?i:l;null===(e=ie(this,jt,"f"))||void 0===e||e.updateValue(n),this.value=ne(l),null===(s=ie(this,jt,"f"))||void 0===s||s.focus(),ie(this,Wt,"m",se).call(this)},Jt=function(){var t;null===(t=ie(this,jt,"f"))||void 0===t||t.focus(),this.updateListPosition()},Kt=function(){var t;this.isListOpened=!0,ie(this,qt,"f")&&ie(this,It,"f")&&(window.addEventListener("scroll",ie(this,qt,"f"),!0),window.addEventListener("resize",ie(this,It,"f"))),ie(this,Nt,"f")&&this.srcElement&&(this.appendToBody?(document.body.appendChild(ie(this,Nt,"f").srcElement),null===(t=ie(this,Gt,"f"))||void 0===t||t.observe(this.srcElement)):this.srcElement.appendChild(ie(this,Nt,"f").srcElement),this.updateListPosition(),ie(this,Wt,"m",te).call(this,!0),ie(this,Nt,"f").focusFirstListElement())},Xt=function(){var t;if(this.alwaysOpen)return;if(this.isListOpened=!1,ie(this,qt,"f")&&ie(this,It,"f")&&(window.removeEventListener("scroll",ie(this,qt,"f"),!0),window.removeEventListener("resize",ie(this,It,"f"))),!ie(this,Nt,"f")||!this.srcElement)return;(this.appendToBody?document.body.contains(ie(this,Nt,"f").srcElement):this.srcElement.contains(ie(this,Nt,"f").srcElement))&&(this.appendToBody?(document.body.removeChild(ie(this,Nt,"f").srcElement),null===(t=ie(this,Gt,"f"))||void 0===t||t.disconnect()):this.srcElement.removeChild(ie(this,Nt,"f").srcElement),ie(this,Wt,"m",te).call(this,!1))},Qt=function(t,e){if(!ie(this,Nt,"f")||!ie(this,jt,"f"))return;const s=e?"treeselect-list--top-to-body":"treeselect-list--top",i=e?"treeselect-list--bottom-to-body":"treeselect-list--bottom";t?(ie(this,Nt,"f").srcElement.classList.add(s),ie(this,Nt,"f").srcElement.classList.remove(i),ie(this,jt,"f").srcElement.classList.add("treeselect-input--top"),ie(this,jt,"f").srcElement.classList.remove("treeselect-input--bottom")):(ie(this,Nt,"f").srcElement.classList.remove(s),ie(this,Nt,"f").srcElement.classList.add(i),ie(this,jt,"f").srcElement.classList.remove("treeselect-input--top"),ie(this,jt,"f").srcElement.classList.add("treeselect-input--bottom"))},Zt=function(t){ie(this,jt,"f")&&ie(this,Nt,"f")&&(t?(ie(this,jt,"f").srcElement.classList.add("treeselect-input--focused"),ie(this,Nt,"f").srcElement.classList.add("treeselect-list--focused")):(ie(this,jt,"f").srcElement.classList.remove("treeselect-input--focused"),ie(this,Nt,"f").srcElement.classList.remove("treeselect-list--focused")))},te=function(t){var e,s,i,l;t?null===(e=ie(this,jt,"f"))||void 0===e||e.srcElement.classList.add("treeselect-input--opened"):null===(s=ie(this,jt,"f"))||void 0===s||s.srcElement.classList.remove("treeselect-input--opened"),this.staticList?null===(i=ie(this,Nt,"f"))||void 0===i||i.srcElement.classList.add("treeselect-list--static"):null===(l=ie(this,Nt,"f"))||void 0===l||l.srcElement.classList.remove("treeselect-list--static")},ee=function(t){ie(this,qt,"f")&&ie(this,It,"f")&&ie(this,Dt,"f")&&ie(this,Vt,"f")&&(this.alwaysOpen&&!t||(window.removeEventListener("scroll",ie(this,qt,"f"),!0),window.removeEventListener("resize",ie(this,It,"f"))),document.removeEventListener("mousedown",ie(this,Dt,"f"),!0),document.removeEventListener("focus",ie(this,Dt,"f"),!0),window.removeEventListener("blur",ie(this,Vt,"f")))},se=function(){var t;null===(t=this.srcElement)||void 0===t||t.dispatchEvent(new CustomEvent("input",{detail:this.value})),this.inputCallback&&this.inputCallback(this.value)};export{oe as Treeselect,e as default};
|