slim-select
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -7,3 +7,3 @@ import Settings from './settings'; | ||
addable?: (value: string) => Promise<OptionOptional | string> | OptionOptional | string | false | undefined | null; | ||
setSelected: (value: string[], runAfterChange: boolean) => void; | ||
setSelected: (value: string | string[], runAfterChange: boolean) => void; | ||
addOption: (option: Option) => void; | ||
@@ -10,0 +10,0 @@ search: (search: string) => void; |
@@ -14,2 +14,3 @@ /// <reference types="node" /> | ||
showSearch: boolean; | ||
ariaLabel: string; | ||
searchPlaceholder: string; | ||
@@ -16,0 +17,0 @@ searchText: string; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SlimSelect=t()}(this,(function(){"use strict";function e(){return Math.random().toString(36).substring(2,10)}function t(e,t=50,s=!1){let i;return function(...n){const a=self,l=s&&!i;clearTimeout(i),i=setTimeout((()=>{i=null,s||e.apply(a,n)}),t),l&&e.apply(a,n)}}function s(e,t){return JSON.stringify(e)===JSON.stringify(t)}class i{constructor(t){this.id="",this.style="",this.class=[],this.isMultiple=!1,this.isOpen=!1,this.isFullOpen=!1,this.intervalMove=null,t||(t={}),this.id="ss-"+e(),this.style=t.style||"",this.class=t.class||[],this.disabled=void 0!==t.disabled&&t.disabled,this.alwaysOpen=void 0!==t.alwaysOpen&&t.alwaysOpen,this.showSearch=void 0===t.showSearch||t.showSearch,this.searchPlaceholder=t.searchPlaceholder||"Search",this.searchText=t.searchText||"No Results",this.searchingText=t.searchingText||"Searching...",this.searchHighlight=void 0!==t.searchHighlight&&t.searchHighlight,this.closeOnSelect=void 0===t.closeOnSelect||t.closeOnSelect,this.contentLocation=t.contentLocation||document.body,this.contentPosition=t.contentPosition||"absolute",this.openPosition=t.openPosition||"auto",this.placeholderText=void 0!==t.placeholderText?t.placeholderText:"Select Value",this.allowDeselect=void 0!==t.allowDeselect&&t.allowDeselect,this.hideSelected=void 0!==t.hideSelected&&t.hideSelected,this.showOptionTooltips=void 0!==t.showOptionTooltips&&t.showOptionTooltips,this.minSelected=t.minSelected||0,this.maxSelected=t.maxSelected||1e3,this.timeoutDelay=t.timeoutDelay||200,this.maxValuesShown=t.maxValuesShown||20,this.maxValuesMessage=t.maxValuesMessage||"{number} selected"}}class n{constructor(t){if(this.id=t.id&&""!==t.id?t.id:e(),this.label=t.label||"",this.selectAll=void 0!==t.selectAll&&t.selectAll,this.selectAllText=t.selectAllText||"Select All",this.closable=t.closable||"off",this.options=[],t.options)for(const e of t.options)this.options.push(new a(e))}}class a{constructor(t){this.id=t.id&&""!==t.id?t.id:e(),this.value=void 0===t.value?t.text:t.value,this.text=t.text||"",this.html=t.html||"",this.selected=void 0!==t.selected&&t.selected,this.display=void 0===t.display||t.display,this.disabled=void 0!==t.disabled&&t.disabled,this.mandatory=void 0!==t.mandatory&&t.mandatory,this.placeholder=void 0!==t.placeholder&&t.placeholder,this.class=t.class||"",this.style=t.style||"",this.data=t.data||{}}}class l{constructor(e,t){this.selectType="single",this.data=[],this.selectType=e,this.setData(t)}validateDataArray(e){if(!Array.isArray(e))return new Error("Data must be an array");for(let t of e){if(!(t instanceof n||"label"in t))return t instanceof a||"text"in t?this.validateOption(t):new Error("Data object must be a valid optgroup or option");if(!("label"in t))return new Error("Optgroup must have a label");if("options"in t&&t.options)for(let e of t.options)return this.validateOption(e)}return null}validateOption(e){return"text"in e?null:new Error("Option must have a text")}partialToFullData(e){let t=[];return e.forEach((e=>{if(e instanceof n||"label"in e){let s=[];"options"in e&&e.options&&e.options.forEach((e=>{s.push(new a(e))})),s.length>0&&t.push(new n(e))}(e instanceof a||"text"in e)&&t.push(new a(e))})),t}setData(e){this.data=this.partialToFullData(e),"single"===this.selectType&&this.setSelectedBy("value",this.getSelected())}getData(){return this.filter(null,!0)}getDataOptions(){return this.filter(null,!1)}addOption(e){this.setData(this.getData().concat(new a(e)))}setSelectedBy(e,t){let s=null,i=!1;for(let l of this.data){if(l instanceof n)for(let n of l.options)s||(s=n),n.selected=!i&&t.includes(n[e]),n.selected&&"single"===this.selectType&&(i=!0);l instanceof a&&(s||(s=l),l.selected=!i&&t.includes(l[e]),l.selected&&"single"===this.selectType&&(i=!0))}"single"===this.selectType&&s&&!i&&(s.selected=!0)}getSelected(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.value)})),t}getSelectedOptions(){return this.filter((e=>e.selected),!1)}getSelectedIDs(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.id)})),t}getOptgroupByID(e){for(let t of this.data)if(t instanceof n&&t.id===e)return t;return null}getOptionByID(e){let t=this.filter((t=>t.id===e),!1);return t.length?t[0]:null}search(e,t){return""===(e=e.trim())?this.getData():this.filter((s=>t(s,e)),!0)}filter(e,t){const s=[];return this.data.forEach((i=>{if(i instanceof n){let l=[];if(i.options.forEach((i=>{e&&!e(i)||(t?l.push(new a(i)):s.push(new a(i)))})),l.length>0){let e=new n(i);e.options=l,s.push(e)}}i instanceof a&&(e&&!e(i)||s.push(new a(i)))})),s}getSelectType(){return this.selectType}}class o{constructor(e,t,s){this.classes={main:"ss-main",placeholder:"ss-placeholder",values:"ss-values",single:"ss-single",max:"ss-max",value:"ss-value",valueText:"ss-value-text",valueDelete:"ss-value-delete",valueOut:"ss-value-out",deselect:"ss-deselect",deselectPath:"M10,10 L90,90 M10,90 L90,10",arrow:"ss-arrow",arrowClose:"M10,30 L50,70 L90,30",arrowOpen:"M10,70 L50,30 L90,70",content:"ss-content",openAbove:"ss-open-above",openBelow:"ss-open-below",search:"ss-search",searchHighlighter:"ss-search-highlight",searching:"ss-searching",addable:"ss-addable",addablePath:"M50,10 L50,90 M10,50 L90,50",list:"ss-list",optgroup:"ss-optgroup",optgroupLabel:"ss-optgroup-label",optgroupLabelText:"ss-optgroup-label-text",optgroupActions:"ss-optgroup-actions",optgroupSelectAll:"ss-selectall",optgroupSelectAllBox:"M60,10 L10,10 L10,90 L90,90 L90,50",optgroupSelectAllCheck:"M30,45 L50,70 L90,10",optgroupClosable:"ss-closable",option:"ss-option",optionDelete:"M10,10 L90,90 M10,90 L90,10",highlighted:"ss-highlighted",open:"ss-open",close:"ss-close",selected:"ss-selected",error:"ss-error",disabled:"ss-disabled",hide:"ss-hide"},this.store=t,this.settings=e,this.callbacks=s,this.main=this.mainDiv(),this.content=this.contentDiv(),this.updateClassStyles(),this.updateAriaAttributes(),this.settings.contentLocation.appendChild(this.content.main)}enable(){this.main.main.classList.remove(this.classes.disabled),this.content.search.input.disabled=!1}disable(){this.main.main.classList.add(this.classes.disabled),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute("d",this.classes.arrowOpen),this.main.main.classList.add("up"===this.settings.openPosition?this.classes.openAbove:this.classes.openBelow),this.main.main.setAttribute("aria-expanded","true"),this.moveContent();const e=this.store.getSelectedOptions();if(e.length){const t=e[e.length-1].id,s=this.content.list.querySelector('[data-id="'+t+'"]');s&&this.ensureElementInView(this.content.list,s)}}close(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.remove(this.classes.openBelow),this.main.main.setAttribute("aria-expanded","false"),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.main.arrow.path.setAttribute("d",this.classes.arrowClose)}updateClassStyles(){if(this.main.main.className="",this.main.main.removeAttribute("style"),this.content.main.className="",this.content.main.removeAttribute("style"),this.main.main.classList.add(this.classes.main),this.content.main.classList.add(this.classes.content),""!==this.settings.style&&(this.main.main.style.cssText=this.settings.style,this.content.main.style.cssText=this.settings.style),this.settings.class.length)for(const e of this.settings.class)""!==e.trim()&&(this.main.main.classList.add(e.trim()),this.content.main.classList.add(e.trim()));"relative"===this.settings.contentPosition&&this.content.main.classList.add("ss-"+this.settings.contentPosition)}updateAriaAttributes(){this.main.main.role="combobox",this.main.main.setAttribute("aria-haspopup","listbox"),this.main.main.setAttribute("aria-controls",this.content.main.id),this.main.main.setAttribute("aria-expanded","false"),this.content.main.setAttribute("role","listbox")}mainDiv(){var e;const t=document.createElement("div");t.dataset.id=this.settings.id,t.id=this.settings.id,t.tabIndex=0,t.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Enter":case" ":this.callbacks.open();const t=this.content.list.querySelector("."+this.classes.highlighted);return t&&t.click(),!1;case"Escape":return this.callbacks.close(),!1}},t.onclick=e=>{this.settings.disabled||(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};const s=document.createElement("div");s.classList.add(this.classes.values),t.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.deselect);const n=null===(e=this.store)||void 0===e?void 0:e.getSelectedOptions();!this.settings.allowDeselect||this.settings.isMultiple&&n&&n.length<=0?i.classList.add(this.classes.hide):i.classList.remove(this.classes.hide),i.onclick=e=>{if(e.stopPropagation(),this.settings.disabled)return;let t=!0;const s=this.store.getSelectedOptions(),i=[];this.callbacks.beforeChange&&(t=!0===this.callbacks.beforeChange(i,s)),t&&(this.settings.isMultiple?(this.callbacks.setSelected([],!1),this.updateDeselectAll()):this.callbacks.setSelected([""],!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(i))};const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.deselectPath),a.appendChild(l),i.appendChild(a),t.appendChild(i);const o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.classList.add(this.classes.arrow),o.setAttribute("viewBox","0 0 100 100");const c=document.createElementNS("http://www.w3.org/2000/svg","path");return c.setAttribute("d",this.classes.arrowClose),this.settings.alwaysOpen&&o.classList.add(this.classes.hide),o.appendChild(c),t.appendChild(o),{main:t,values:s,deselect:{main:i,svg:a,path:l},arrow:{main:o,path:c}}}mainFocus(e){"click"!==e&&this.main.main.focus({preventScroll:!0})}placeholder(){const e=this.store.filter((e=>e.placeholder),!1);let t=this.settings.placeholderText;e.length&&(""!==e[0].html?t=e[0].html:""!==e[0].text&&(t=e[0].text));const s=document.createElement("div");return s.classList.add(this.classes.placeholder),s.innerHTML=t,s}renderValues(){this.settings.isMultiple?this.renderMultipleValues():this.renderSingleValue()}renderSingleValue(){const e=this.store.filter((e=>e.selected&&!e.placeholder),!1),t=e.length>0?e[0]:null;if(t){const e=document.createElement("div");e.classList.add(this.classes.single),t.html?e.innerHTML=t.html:e.innerText=t.text,this.main.values.innerHTML=e.outerHTML}else this.main.values.innerHTML=this.placeholder().outerHTML;this.settings.allowDeselect&&e.length?this.main.deselect.main.classList.remove(this.classes.hide):this.main.deselect.main.classList.add(this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter((e=>e.selected&&e.display),!1);if(0===t.length)return void(this.main.values.innerHTML=this.placeholder().outerHTML);{const e=this.main.values.querySelector("."+this.classes.placeholder);e&&e.remove()}if(t.length>this.settings.maxValuesShown){const e=document.createElement("div");return e.classList.add(this.classes.max),e.textContent=this.settings.maxValuesMessage.replace("{number}",t.length.toString()),void(this.main.values.innerHTML=e.outerHTML)}{const e=this.main.values.querySelector("."+this.classes.max);e&&e.remove()}let s=[];for(let i=0;i<e.length;i++){const n=e[i],a=n.getAttribute("data-id");if(a){t.filter((e=>e.id===a),!1).length||s.push(n)}}for(const e of s)e.classList.add(this.classes.valueOut),setTimeout((()=>{this.main.values.hasChildNodes()&&this.main.values.contains(e)&&this.main.values.removeChild(e)}),100);e=this.main.values.childNodes;for(let s=0;s<t.length;s++){let i=!0;for(let n=0;n<e.length;n++)t[s].id===String(e[n].dataset.id)&&(i=!1);i&&(0===e.length?this.main.values.appendChild(this.multipleValue(t[s])):0===s?this.main.values.insertBefore(this.multipleValue(t[s]),e[s]):e[s-1].insertAdjacentElement("afterend",this.multipleValue(t[s])))}this.updateDeselectAll()}multipleValue(e){const t=document.createElement("div");t.classList.add(this.classes.value),t.dataset.id=e.id;const s=document.createElement("div");if(s.classList.add(this.classes.valueText),s.innerText=e.text,t.appendChild(s),!e.mandatory){const s=document.createElement("div");s.classList.add(this.classes.valueDelete),s.onclick=t=>{if(t.preventDefault(),t.stopPropagation(),this.settings.disabled)return;let s=!0;const i=this.store.getSelectedOptions(),l=i.filter((t=>t.selected&&t.id!==e.id),!0);if(!(this.settings.minSelected&&l.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(s=!0===this.callbacks.beforeChange(l,i)),s)){let e=[];for(const t of l){if(t instanceof n)for(const s of t.options)e.push(s.value);t instanceof a&&e.push(t.value)}this.callbacks.setSelected(e,!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(l),this.updateDeselectAll()}};const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optionDelete),i.appendChild(l),s.appendChild(i),t.appendChild(s)}return t}contentDiv(){const e=document.createElement("div");e.dataset.id=this.settings.id,e.id=this.settings.id;const t=this.searchDiv();e.appendChild(t.main);const s=this.listDiv();return e.appendChild(s),{main:e,search:t,list:s}}moveContent(){"relative"!==this.settings.contentPosition&&"down"!==this.settings.openPosition?"up"!==this.settings.openPosition?"up"===this.putContent()?this.moveContentAbove():this.moveContentBelow():this.moveContentAbove():this.moveContentBelow()}searchDiv(){const e=document.createElement("div"),s=document.createElement("input"),i=document.createElement("div");e.classList.add(this.classes.search);const n={main:e,input:s};if(this.settings.showSearch||(e.classList.add(this.classes.hide),s.readOnly=!0),s.type="search",s.placeholder=this.settings.searchPlaceholder,s.tabIndex=-1,s.setAttribute("aria-label",this.settings.searchPlaceholder),s.setAttribute("autocapitalize","off"),s.setAttribute("autocomplete","off"),s.setAttribute("autocorrect","off"),s.oninput=t((e=>{this.callbacks.search(e.target.value)}),100),s.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Escape":return this.callbacks.close(),!1;case"Enter":case" ":if(this.callbacks.addable&&e.ctrlKey)return i.click(),!1;{const e=this.content.list.querySelector("."+this.classes.highlighted);if(e)return e.click(),!1}return!0}},e.appendChild(s),this.callbacks.addable){i.classList.add(this.classes.addable);const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 100 100");const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",this.classes.addablePath),t.appendChild(s),i.appendChild(t),i.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;const t=this.content.search.input.value.trim();if(""===t)return void this.content.search.input.focus();const s=e=>{let t=new a(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.value),this.callbacks.setSelected(e,!0)}else this.callbacks.setSelected([t.value],!0);this.callbacks.search(""),this.settings.closeOnSelect&&setTimeout((()=>{this.callbacks.close()}),100)},i=this.callbacks.addable(t);!1!==i&&null!=i&&(i instanceof Promise?i.then((e=>{s("string"==typeof e?{text:e,value:e}:e)})):s("string"==typeof i?{text:i,value:i}:i))},e.appendChild(i),n.addable={main:i,svg:t,path:s}}return n}searchFocus(){this.content.search.input.focus()}getOptions(e=!1,t=!1,s=!1){let i="."+this.classes.option;return e&&(i+=":not(."+this.classes.placeholder+")"),t&&(i+=":not(."+this.classes.disabled+")"),s&&(i+=":not(."+this.classes.hide+")"),Array.from(this.content.list.querySelectorAll(i))}highlight(e){const t=this.getOptions(!0,!0,!0);if(0!==t.length)if(1!==t.length||t[0].classList.contains(this.classes.highlighted)){for(let s=0;s<t.length;s++)if(t[s].classList.contains(this.classes.highlighted)){const i=t[s];i.classList.remove(this.classes.highlighted);const n=i.parentElement;if(n&&n.classList.contains(this.classes.open)){const e=n.querySelector("."+this.classes.optgroupLabel);e&&e.click()}let a=t["down"===e?s+1<t.length?s+1:0:s-1>=0?s-1:t.length-1];a.classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,a);const l=a.parentElement;if(l&&l.classList.contains(this.classes.close)){const e=l.querySelector("."+this.classes.optgroupLabel);e&&e.click()}return}t["down"===e?0:t.length-1].classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,t["down"===e?0:t.length-1])}else t[0].classList.add(this.classes.highlighted)}listDiv(){const e=document.createElement("div");return e.classList.add(this.classes.list),e}renderError(e){this.content.list.innerHTML="";const t=document.createElement("div");t.classList.add(this.classes.error),t.textContent=e,this.content.list.appendChild(t)}renderSearching(){this.content.list.innerHTML="";const e=document.createElement("div");e.classList.add(this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e)}renderOptions(e){if(this.content.list.innerHTML="",0===e.length){const e=document.createElement("div");return e.classList.add(this.classes.search),e.innerHTML=this.settings.searchText,void this.content.list.appendChild(e)}for(const t of e){if(t instanceof n){const e=document.createElement("div");e.classList.add(this.classes.optgroup);const s=document.createElement("div");s.classList.add(this.classes.optgroupLabel),e.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.optgroupLabelText),i.textContent=t.label,s.appendChild(i);const n=document.createElement("div");if(n.classList.add(this.classes.optgroupActions),s.appendChild(n),this.settings.isMultiple&&t.selectAll){const e=document.createElement("div");e.classList.add(this.classes.optgroupSelectAll);let s=!0;for(const e of t.options)if(!e.selected){s=!1;break}s&&e.classList.add(this.classes.selected);const i=document.createElement("span");i.textContent=t.selectAllText,e.appendChild(i);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),e.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optgroupSelectAllBox),a.appendChild(l);const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.classes.optgroupSelectAllCheck),a.appendChild(o),e.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation();const i=this.store.getSelected();if(s){const e=i.filter((e=>{for(const s of t.options)if(e===s.value)return!1;return!0}));this.callbacks.setSelected(e,!0)}else{const e=i.concat(t.options.map((e=>e.value)));for(const e of t.options)this.store.getOptionByID(e.id)||this.callbacks.addOption(e);this.callbacks.setSelected(e,!0)}})),n.appendChild(e)}if("off"!==t.closable){const i=document.createElement("div");i.classList.add(this.classes.optgroupClosable);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),a.classList.add(this.classes.arrow),i.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");a.appendChild(l),t.options.some((e=>e.selected))||""!==this.content.search.input.value.trim()?(i.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"open"===t.closable?(e.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"close"===t.closable&&(e.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose)),s.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),e.classList.contains(this.classes.close)?(e.classList.remove(this.classes.close),e.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):(e.classList.remove(this.classes.open),e.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose))})),n.appendChild(i)}e.appendChild(s);for(const s of t.options)e.appendChild(this.option(s));this.content.list.appendChild(e)}t instanceof a&&this.content.list.appendChild(this.option(t))}}option(e){if(e.placeholder){const e=document.createElement("div");return e.classList.add(this.classes.option),e.classList.add(this.classes.hide),e}const t=document.createElement("div");return t.dataset.id=e.id,t.id=e.id,t.classList.add(this.classes.option),t.setAttribute("role","option"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.style&&(t.style.cssText=e.style),this.settings.searchHighlight&&""!==this.content.search.input.value.trim()?t.innerHTML=this.highlightText(""!==e.html?e.html:e.text,this.content.search.input.value,this.classes.searchHighlighter):""!==e.html?t.innerHTML=e.html:t.textContent=e.text,this.settings.showOptionTooltips&&t.textContent&&t.setAttribute("title",t.textContent),e.display||t.classList.add(this.classes.hide),e.disabled&&t.classList.add(this.classes.disabled),e.selected&&this.settings.hideSelected&&t.classList.add(this.classes.hide),e.selected?(t.classList.add(this.classes.selected),t.setAttribute("aria-selected","true"),this.main.main.setAttribute("aria-activedescendant",t.id)):(t.classList.remove(this.classes.selected),t.setAttribute("aria-selected","false")),t.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation();const s=this.store.getSelected(),i=t.currentTarget,n=String(i.dataset.id);if(e.disabled||e.selected&&!this.settings.allowDeselect)return;if(this.settings.isMultiple&&this.settings.maxSelected<=s.length&&!e.selected||this.settings.isMultiple&&this.settings.minSelected>=s.length&&e.selected)return;let a=!1;const l=this.store.getSelectedOptions();let o=[];this.settings.isMultiple&&(o=e.selected?l.filter((e=>e.id!==n)):l.concat(e)),this.settings.isMultiple||(o=e.selected?[]:[e]),this.callbacks.beforeChange||(a=!0),this.callbacks.beforeChange&&(a=!1!==this.callbacks.beforeChange(o,l)),a&&(this.store.getOptionByID(n)||this.callbacks.addOption(e),this.callbacks.setSelected(o.map((e=>e.value)),!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(o))})),t}destroy(){this.main.main.remove(),this.content.main.remove()}highlightText(e,t,s){let i=e;const n=new RegExp("("+t.trim()+")(?![^<]*>[^<>]*</)","i");if(!e.match(n))return e;const a=e.match(n).index,l=a+e.match(n)[0].toString().length,o=e.substring(a,l);return i=i.replace(n,`<mark class="${s}">${o}</mark>`),i}moveContentAbove(){const e=this.main.main.offsetHeight,t=this.content.main.offsetHeight;this.main.main.classList.remove(this.classes.openBelow),this.main.main.classList.add(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.content.main.classList.add(this.classes.openAbove);const s=this.main.main.getBoundingClientRect();this.content.main.style.margin="-"+(e+t-1)+"px 0px 0px 0px",this.content.main.style.top=s.top+s.height+window.scrollY+"px",this.content.main.style.left=s.left+window.scrollX+"px",this.content.main.style.width=s.width+"px"}moveContentBelow(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.add(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.add(this.classes.openBelow);const e=this.main.main.getBoundingClientRect();this.content.main.style.margin="-1px 0px 0px 0px","relative"!==this.settings.contentPosition&&(this.content.main.style.top=e.top+e.height+window.scrollY+"px",this.content.main.style.left=e.left+window.scrollX+"px",this.content.main.style.width=e.width+"px")}ensureElementInView(e,t){const s=e.scrollTop+e.offsetTop,i=s+e.clientHeight,n=t.offsetTop,a=n+t.clientHeight;n<s?e.scrollTop-=s-n:a>i&&(e.scrollTop+=a-i)}putContent(){const e=this.main.main.offsetHeight,t=this.main.main.getBoundingClientRect(),s=this.content.main.offsetHeight;return window.innerHeight-(t.top+e)<=s&&t.top>s?"up":"down"}updateDeselectAll(){if(!this.store||!this.settings)return;const e=this.store.getSelectedOptions(),t=e&&e.length>0,s=this.settings.isMultiple,i=this.settings.allowDeselect,n=this.main.deselect.main,a=this.classes.hide;!i||s&&!t?n.classList.add(a):n.classList.remove(a)}}class c{constructor(e){this.listen=!1,this.observer=null,this.select=e,this.select.addEventListener("change",this.valueChange.bind(this),{passive:!0}),this.observer=new MutationObserver(this.observeCall.bind(this)),this.changeListen(!0)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){this.select.tabIndex=-1,this.select.style.display="none",this.select.setAttribute("aria-hidden","true")}showUI(){this.select.removeAttribute("tabindex"),this.select.style.display="",this.select.removeAttribute("aria-hidden")}changeListen(e){this.listen=e,e&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),e||this.observer&&this.observer.disconnect()}valueChange(e){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedValues()),!0}observeCall(e){if(!this.listen)return;let t=!1,s=!1,i=!1;for(const n of e)n.target===this.select&&("disabled"===n.attributeName&&(s=!0),"class"===n.attributeName&&(t=!0)),"OPTGROUP"!==n.target.nodeName&&"OPTION"!==n.target.nodeName||(i=!0);t&&this.onClassChange&&this.onClassChange(this.select.className.split(" ")),s&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),i&&this.onOptionsChange&&(this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0))}getData(){let e=[];const t=this.select.childNodes;for(const s of t)"OPTGROUP"===s.nodeName&&e.push(this.getDataFromOptgroup(s)),"OPTION"===s.nodeName&&e.push(this.getDataFromOption(s));return e}getDataFromOptgroup(e){let t={id:e.id,label:e.label,selectAll:!!e.dataset&&"true"===e.dataset.selectall,selectAllText:e.dataset?e.dataset.selectalltext:"Select all",closable:e.dataset?e.dataset.closable:"off",options:[]};const s=e.childNodes;for(const e of s)"OPTION"===e.nodeName&&t.options.push(this.getDataFromOption(e));return t}getDataFromOption(e){return{id:e.id,value:e.value,text:e.text,html:e.dataset&&e.dataset.html?e.dataset.html:"",selected:e.selected,display:"none"!==e.style.display,disabled:e.disabled,mandatory:!!e.dataset&&"true"===e.dataset.mandatory,placeholder:"true"===e.dataset.placeholder,class:e.className,style:e.style.cssText,data:e.dataset}}getSelectedValues(){let e=[];const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}return e}setSelected(e){this.changeListen(!1);const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}this.changeListen(!0)}updateSelect(e,t,s){this.changeListen(!1),e&&(this.select.dataset.id=e),t&&(this.select.style.cssText=t),s&&(this.select.className="",s.forEach((e=>{""!==e.trim()&&this.select.classList.add(e.trim())}))),this.changeListen(!0)}updateOptions(e){this.changeListen(!1),this.select.innerHTML="";for(const t of e)t instanceof n&&this.select.appendChild(this.createOptgroup(t)),t instanceof a&&this.select.appendChild(this.createOption(t));this.select.dispatchEvent(new Event("change")),this.changeListen(!0)}createOptgroup(e){const t=document.createElement("optgroup");if(t.id=e.id,t.label=e.label,e.selectAll&&(t.dataset.selectAll="true"),"off"!==e.closable&&(t.dataset.closable=e.closable),e.options)for(const s of e.options)t.appendChild(this.createOption(s));return t}createOption(e){const t=document.createElement("option");return t.id=e.id,t.value=e.value,t.innerHTML=e.text,""!==e.html&&t.setAttribute("data-html",e.html),e.selected&&(t.selected=e.selected),e.disabled&&(t.disabled=!0),!1===e.display&&(t.style.display="none"),e.placeholder&&t.setAttribute("data-placeholder","true"),e.mandatory&&t.setAttribute("data-mandatory","true"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.data&&"object"==typeof e.data&&Object.keys(e.data).forEach((s=>{t.setAttribute("data-"+function(e){const t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(e=>"-"+e.toLowerCase()));return e[0]===e[0].toUpperCase()?t.substring(1):t}(s),e.data[s])})),t}destroy(){this.changeListen(!1),this.select.removeEventListener("change",this.valueChange.bind(this)),this.observer&&(this.observer.disconnect(),this.observer=null),delete this.select.dataset.id,this.showUI()}}return class{constructor(e){var s;if(this.events={search:void 0,searchFilter:(e,t)=>-1!==e.text.toLowerCase().indexOf(t.toLowerCase()),addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0},this.windowResize=t((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.windowScroll=t((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.documentClick=e=>{this.settings.isOpen&&e.target&&!function(e,t){function s(e,s){return s&&e&&e.classList&&e.classList.contains(s)||s&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}return s(e,t)||function e(t,i){return t&&t!==document?s(t,i)?t:e(t.parentNode,i):null}(e,t)}(e.target,this.settings.id)&&this.close(e.type)},this.windowVisibilityChange=()=>{document.hidden&&this.close()},this.selectEl="string"==typeof e.select?document.querySelector(e.select):e.select,!this.selectEl)return void(e.events&&e.events.error&&e.events.error(new Error("Could not find select element")));if("SELECT"!==this.selectEl.tagName)return void(e.events&&e.events.error&&e.events.error(new Error("Element isnt of type select")));this.selectEl.dataset.ssid&&this.destroy(),this.settings=new i(e.settings);const n=["afterChange","beforeOpen","afterOpen","beforeClose","afterClose"];for(const s in e.events)e.events.hasOwnProperty(s)&&(-1!==n.indexOf(s)?this.events[s]=t(e.events[s],100):this.events[s]=e.events[s]);this.settings.disabled=(null===(s=e.settings)||void 0===s?void 0:s.disabled)?e.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(" "),this.select=new c(this.selectEl),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.onValueChange=e=>{this.setSelected(e)},this.select.onClassChange=e=>{this.settings.class=e,this.render.updateClassStyles()},this.select.onDisabledChange=e=>{e?this.disable():this.enable()},this.select.onOptionsChange=e=>{this.setData(e)},this.store=new l(this.settings.isMultiple?"multiple":"single",e.data?e.data:this.select.getData()),e.data&&this.select.updateOptions(this.store.getData());const a={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:this.setSelected.bind(this),addOption:this.addOption.bind(this),search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.render=new o(this.settings,this.store,a),this.render.renderValues(),this.render.renderOptions(this.store.getData());const h=this.selectEl.getAttribute("aria-label"),r=this.selectEl.getAttribute("aria-labelledby");h?this.render.main.main.setAttribute("aria-label",h):r&&this.render.main.main.setAttribute("aria-labelledby",r),this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),document.addEventListener("click",this.documentClick),window.addEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.addEventListener("scroll",this.windowScroll,!1),document.addEventListener("visibilitychange",this.windowVisibilityChange),this.settings.disabled&&this.disable(),this.settings.alwaysOpen&&this.open(),this.selectEl.slim=this}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){const t=this.store.getSelected(),i=this.store.validateDataArray(e);if(i)return void(this.events.error&&this.events.error(i));this.store.setData(e);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),this.render.renderOptions(n),this.events.afterChange&&!s(t,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}getSelected(){return this.store.getSelected()}setSelected(e,t=!0){const i=this.store.getSelected();this.store.setSelectedBy("value",Array.isArray(e)?e:[e]);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),""!==this.render.content.search.input.value?this.search(this.render.content.search.input.value):this.render.renderOptions(n),t&&this.events.afterChange&&!s(i,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}addOption(e){const t=this.store.getSelected();this.store.getDataOptions().some((t=>{var s;return t.value===(null!==(s=e.value)&&void 0!==s?s:e.text)}))||this.store.addOption(e);const i=this.store.getData();this.select.updateOptions(i),this.render.renderValues(),this.render.renderOptions(i),this.events.afterChange&&!s(t,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}open(){this.settings.disabled||this.settings.isOpen||(this.events.beforeOpen&&this.events.beforeOpen(),this.render.open(),this.settings.showSearch&&this.render.searchFocus(),this.settings.isOpen=!0,setTimeout((()=>{this.events.afterOpen&&this.events.afterOpen(),this.settings.isOpen&&(this.settings.isFullOpen=!0)}),this.settings.timeoutDelay),"absolute"===this.settings.contentPosition&&(this.settings.intervalMove&&clearInterval(this.settings.intervalMove),this.settings.intervalMove=setInterval(this.render.moveContent.bind(this.render),500)))}close(e=null){this.settings.isOpen&&!this.settings.alwaysOpen&&(this.events.beforeClose&&this.events.beforeClose(),this.render.close(),""!==this.render.content.search.input.value&&this.search(""),this.render.mainFocus(e),this.settings.isOpen=!1,this.settings.isFullOpen=!1,setTimeout((()=>{this.events.afterClose&&this.events.afterClose()}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove))}search(e){if(this.render.content.search.input.value!==e&&(this.render.content.search.input.value=e),!this.events.search)return void this.render.renderOptions(""===e?this.store.getData():this.store.search(e,this.events.searchFilter));this.render.renderSearching();const t=this.events.search(e,this.store.getSelectedOptions());t instanceof Promise?t.then((e=>{this.render.renderOptions(this.store.partialToFullData(e))})).catch((e=>{this.render.renderError("string"==typeof e?e:e.message)})):Array.isArray(t)?this.render.renderOptions(this.store.partialToFullData(t)):this.render.renderError("Search event must return a promise or an array of data")}destroy(){document.removeEventListener("click",this.documentClick),window.removeEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.removeEventListener("scroll",this.windowScroll,!1),document.removeEventListener("visibilitychange",this.windowVisibilityChange),this.store.setData([]),this.render.destroy(),this.select.destroy()}}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SlimSelect=e()}(this,(function(){"use strict";function t(){return Math.random().toString(36).substring(2,10)}function e(t,e=50,s=!1){let i;return function(...n){const a=self,l=s&&!i;clearTimeout(i),i=setTimeout((()=>{i=null,s||t.apply(a,n)}),e),l&&t.apply(a,n)}}function s(t,e){return JSON.stringify(t)===JSON.stringify(e)}class i{constructor(e){this.id="",this.style="",this.class=[],this.isMultiple=!1,this.isOpen=!1,this.isFullOpen=!1,this.intervalMove=null,e||(e={}),this.id="ss-"+t(),this.style=e.style||"",this.class=e.class||[],this.disabled=void 0!==e.disabled&&e.disabled,this.alwaysOpen=void 0!==e.alwaysOpen&&e.alwaysOpen,this.showSearch=void 0===e.showSearch||e.showSearch,this.ariaLabel=e.ariaLabel||"Combobox",this.searchPlaceholder=e.searchPlaceholder||"Search",this.searchText=e.searchText||"No Results",this.searchingText=e.searchingText||"Searching...",this.searchHighlight=void 0!==e.searchHighlight&&e.searchHighlight,this.closeOnSelect=void 0===e.closeOnSelect||e.closeOnSelect,this.contentLocation=e.contentLocation||document.body,this.contentPosition=e.contentPosition||"absolute",this.openPosition=e.openPosition||"auto",this.placeholderText=void 0!==e.placeholderText?e.placeholderText:"Select Value",this.allowDeselect=void 0!==e.allowDeselect&&e.allowDeselect,this.hideSelected=void 0!==e.hideSelected&&e.hideSelected,this.showOptionTooltips=void 0!==e.showOptionTooltips&&e.showOptionTooltips,this.minSelected=e.minSelected||0,this.maxSelected=e.maxSelected||1e3,this.timeoutDelay=e.timeoutDelay||200,this.maxValuesShown=e.maxValuesShown||20,this.maxValuesMessage=e.maxValuesMessage||"{number} selected"}}class n{constructor(e){if(this.id=e.id&&""!==e.id?e.id:t(),this.label=e.label||"",this.selectAll=void 0!==e.selectAll&&e.selectAll,this.selectAllText=e.selectAllText||"Select All",this.closable=e.closable||"off",this.options=[],e.options)for(const t of e.options)this.options.push(new a(t))}}class a{constructor(e){this.id=e.id&&""!==e.id?e.id:t(),this.value=void 0===e.value?e.text:e.value,this.text=e.text||"",this.html=e.html||"",this.selected=void 0!==e.selected&&e.selected,this.display=void 0===e.display||e.display,this.disabled=void 0!==e.disabled&&e.disabled,this.mandatory=void 0!==e.mandatory&&e.mandatory,this.placeholder=void 0!==e.placeholder&&e.placeholder,this.class=e.class||"",this.style=e.style||"",this.data=e.data||{}}}class l{constructor(t,e){this.selectType="single",this.data=[],this.selectType=t,this.setData(e)}validateDataArray(t){if(!Array.isArray(t))return new Error("Data must be an array");for(let e of t){if(!(e instanceof n||"label"in e))return e instanceof a||"text"in e?this.validateOption(e):new Error("Data object must be a valid optgroup or option");if(!("label"in e))return new Error("Optgroup must have a label");if("options"in e&&e.options)for(let t of e.options)return this.validateOption(t)}return null}validateOption(t){return"text"in t?null:new Error("Option must have a text")}partialToFullData(t){let e=[];return t.forEach((t=>{if(t instanceof n||"label"in t){let s=[];"options"in t&&t.options&&t.options.forEach((t=>{s.push(new a(t))})),s.length>0&&e.push(new n(t))}(t instanceof a||"text"in t)&&e.push(new a(t))})),e}setData(t){this.data=this.partialToFullData(t),"single"===this.selectType&&this.setSelectedBy("value",this.getSelected())}getData(){return this.filter(null,!0)}getDataOptions(){return this.filter(null,!1)}addOption(t){this.setData(this.getData().concat(new a(t)))}setSelectedBy(t,e){let s=null,i=!1;for(let l of this.data){if(l instanceof n)for(let n of l.options)s||(s=n),n.selected=!i&&e.includes(n[t]),n.selected&&"single"===this.selectType&&(i=!0);l instanceof a&&(s||(s=l),l.selected=!i&&e.includes(l[t]),l.selected&&"single"===this.selectType&&(i=!0))}"single"===this.selectType&&s&&!i&&(s.selected=!0)}getSelected(){let t=this.getSelectedOptions(),e=[];return t.forEach((t=>{e.push(t.value)})),e}getSelectedOptions(){return this.filter((t=>t.selected),!1)}getSelectedIDs(){let t=this.getSelectedOptions(),e=[];return t.forEach((t=>{e.push(t.id)})),e}getOptgroupByID(t){for(let e of this.data)if(e instanceof n&&e.id===t)return e;return null}getOptionByID(t){let e=this.filter((e=>e.id===t),!1);return e.length?e[0]:null}getSelectType(){return this.selectType}getFirstOption(){let t=null;for(let e of this.data)if(e instanceof n?t=e.options[0]:e instanceof a&&(t=e),t)break;return t}search(t,e){return""===(t=t.trim())?this.getData():this.filter((s=>e(s,t)),!0)}filter(t,e){const s=[];return this.data.forEach((i=>{if(i instanceof n){let l=[];if(i.options.forEach((i=>{t&&!t(i)||(e?l.push(new a(i)):s.push(new a(i)))})),l.length>0){let t=new n(i);t.options=l,s.push(t)}}i instanceof a&&(t&&!t(i)||s.push(new a(i)))})),s}}class o{constructor(t,e,s){this.classes={main:"ss-main",placeholder:"ss-placeholder",values:"ss-values",single:"ss-single",max:"ss-max",value:"ss-value",valueText:"ss-value-text",valueDelete:"ss-value-delete",valueOut:"ss-value-out",deselect:"ss-deselect",deselectPath:"M10,10 L90,90 M10,90 L90,10",arrow:"ss-arrow",arrowClose:"M10,30 L50,70 L90,30",arrowOpen:"M10,70 L50,30 L90,70",content:"ss-content",openAbove:"ss-open-above",openBelow:"ss-open-below",search:"ss-search",searchHighlighter:"ss-search-highlight",searching:"ss-searching",addable:"ss-addable",addablePath:"M50,10 L50,90 M10,50 L90,50",list:"ss-list",optgroup:"ss-optgroup",optgroupLabel:"ss-optgroup-label",optgroupLabelText:"ss-optgroup-label-text",optgroupActions:"ss-optgroup-actions",optgroupSelectAll:"ss-selectall",optgroupSelectAllBox:"M60,10 L10,10 L10,90 L90,90 L90,50",optgroupSelectAllCheck:"M30,45 L50,70 L90,10",optgroupClosable:"ss-closable",option:"ss-option",optionDelete:"M10,10 L90,90 M10,90 L90,10",highlighted:"ss-highlighted",open:"ss-open",close:"ss-close",selected:"ss-selected",error:"ss-error",disabled:"ss-disabled",hide:"ss-hide"},this.store=e,this.settings=t,this.callbacks=s,this.main=this.mainDiv(),this.content=this.contentDiv(),this.updateClassStyles(),this.updateAriaAttributes(),this.settings.contentLocation.appendChild(this.content.main)}enable(){this.main.main.classList.remove(this.classes.disabled),this.content.search.input.disabled=!1}disable(){this.main.main.classList.add(this.classes.disabled),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute("d",this.classes.arrowOpen),this.main.main.classList.add("up"===this.settings.openPosition?this.classes.openAbove:this.classes.openBelow),this.main.main.setAttribute("aria-expanded","true"),this.moveContent();const t=this.store.getSelectedOptions();if(t.length){const e=t[t.length-1].id,s=this.content.list.querySelector('[data-id="'+e+'"]');s&&this.ensureElementInView(this.content.list,s)}}close(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.remove(this.classes.openBelow),this.main.main.setAttribute("aria-expanded","false"),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.main.arrow.path.setAttribute("d",this.classes.arrowClose)}updateClassStyles(){if(this.main.main.className="",this.main.main.removeAttribute("style"),this.content.main.className="",this.content.main.removeAttribute("style"),this.main.main.classList.add(this.classes.main),this.content.main.classList.add(this.classes.content),""!==this.settings.style&&(this.main.main.style.cssText=this.settings.style,this.content.main.style.cssText=this.settings.style),this.settings.class.length)for(const t of this.settings.class)""!==t.trim()&&(this.main.main.classList.add(t.trim()),this.content.main.classList.add(t.trim()));"relative"===this.settings.contentPosition&&this.content.main.classList.add("ss-"+this.settings.contentPosition)}updateAriaAttributes(){this.main.main.role="combobox",this.main.main.setAttribute("aria-haspopup","listbox"),this.main.main.setAttribute("aria-controls",this.content.main.id),this.main.main.setAttribute("aria-expanded","false"),this.content.main.setAttribute("role","listbox")}mainDiv(){var t;const e=document.createElement("div");e.dataset.id=this.settings.id,e.setAttribute("aria-label",this.settings.ariaLabel),e.tabIndex=0,e.onkeydown=t=>{switch(t.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===t.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Enter":case" ":this.callbacks.open();const e=this.content.list.querySelector("."+this.classes.highlighted);return e&&e.click(),!1;case"Escape":return this.callbacks.close(),!1}return!1},e.onclick=t=>{this.settings.disabled||(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};const s=document.createElement("div");s.classList.add(this.classes.values),e.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.deselect);const n=null===(t=this.store)||void 0===t?void 0:t.getSelectedOptions();!this.settings.allowDeselect||this.settings.isMultiple&&n&&n.length<=0?i.classList.add(this.classes.hide):i.classList.remove(this.classes.hide),i.onclick=t=>{if(t.stopPropagation(),this.settings.disabled)return;let e=!0;const s=this.store.getSelectedOptions(),i=[];if(this.callbacks.beforeChange&&(e=!0===this.callbacks.beforeChange(i,s)),e){if(this.settings.isMultiple)this.callbacks.setSelected([],!1),this.updateDeselectAll();else{const t=this.store.getFirstOption(),e=t?t.value:"";this.callbacks.setSelected(e,!1)}this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(this.store.getSelectedOptions())}};const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.deselectPath),a.appendChild(l),i.appendChild(a),e.appendChild(i);const o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.classList.add(this.classes.arrow),o.setAttribute("viewBox","0 0 100 100");const c=document.createElementNS("http://www.w3.org/2000/svg","path");return c.setAttribute("d",this.classes.arrowClose),this.settings.alwaysOpen&&o.classList.add(this.classes.hide),o.appendChild(c),e.appendChild(o),{main:e,values:s,deselect:{main:i,svg:a,path:l},arrow:{main:o,path:c}}}mainFocus(t){"click"!==t&&this.main.main.focus({preventScroll:!0})}placeholder(){const t=this.store.filter((t=>t.placeholder),!1);let e=this.settings.placeholderText;t.length&&(""!==t[0].html?e=t[0].html:""!==t[0].text&&(e=t[0].text));const s=document.createElement("div");return s.classList.add(this.classes.placeholder),s.innerHTML=e,s}renderValues(){this.settings.isMultiple?this.renderMultipleValues():this.renderSingleValue()}renderSingleValue(){const t=this.store.filter((t=>t.selected&&!t.placeholder),!1),e=t.length>0?t[0]:null;if(e){const t=document.createElement("div");t.classList.add(this.classes.single),e.html?t.innerHTML=e.html:t.innerText=e.text,this.main.values.innerHTML=t.outerHTML}else this.main.values.innerHTML=this.placeholder().outerHTML;this.settings.allowDeselect&&t.length?this.main.deselect.main.classList.remove(this.classes.hide):this.main.deselect.main.classList.add(this.classes.hide)}renderMultipleValues(){let t=this.main.values.childNodes,e=this.store.filter((t=>t.selected&&t.display),!1);if(0===e.length)return void(this.main.values.innerHTML=this.placeholder().outerHTML);{const t=this.main.values.querySelector("."+this.classes.placeholder);t&&t.remove()}if(e.length>this.settings.maxValuesShown){const t=document.createElement("div");return t.classList.add(this.classes.max),t.textContent=this.settings.maxValuesMessage.replace("{number}",e.length.toString()),void(this.main.values.innerHTML=t.outerHTML)}{const t=this.main.values.querySelector("."+this.classes.max);t&&t.remove()}let s=[];for(let i=0;i<t.length;i++){const n=t[i],a=n.getAttribute("data-id");if(a){e.filter((t=>t.id===a),!1).length||s.push(n)}}for(const t of s)t.classList.add(this.classes.valueOut),setTimeout((()=>{this.main.values.hasChildNodes()&&this.main.values.contains(t)&&this.main.values.removeChild(t)}),100);t=this.main.values.childNodes;for(let s=0;s<e.length;s++){let i=!0;for(let n=0;n<t.length;n++)e[s].id===String(t[n].dataset.id)&&(i=!1);i&&(0===t.length?this.main.values.appendChild(this.multipleValue(e[s])):0===s?this.main.values.insertBefore(this.multipleValue(e[s]),t[s]):t[s-1].insertAdjacentElement("afterend",this.multipleValue(e[s])))}this.updateDeselectAll()}multipleValue(t){const e=document.createElement("div");e.classList.add(this.classes.value),e.dataset.id=t.id;const s=document.createElement("div");if(s.classList.add(this.classes.valueText),s.innerText=t.text,e.appendChild(s),!t.mandatory){const s=document.createElement("div");s.classList.add(this.classes.valueDelete),s.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),this.settings.disabled)return;let s=!0;const i=this.store.getSelectedOptions(),l=i.filter((e=>e.selected&&e.id!==t.id),!0);if(!(this.settings.minSelected&&l.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(s=!0===this.callbacks.beforeChange(l,i)),s)){let t=[];for(const e of l){if(e instanceof n)for(const s of e.options)t.push(s.value);e instanceof a&&t.push(e.value)}this.callbacks.setSelected(t,!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(l),this.updateDeselectAll()}};const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optionDelete),i.appendChild(l),s.appendChild(i),e.appendChild(s)}return e}contentDiv(){const t=document.createElement("div");t.dataset.id=this.settings.id;const e=this.searchDiv();t.appendChild(e.main);const s=this.listDiv();return t.appendChild(s),{main:t,search:e,list:s}}moveContent(){"relative"!==this.settings.contentPosition&&"down"!==this.settings.openPosition?"up"!==this.settings.openPosition?"up"===this.putContent()?this.moveContentAbove():this.moveContentBelow():this.moveContentAbove():this.moveContentBelow()}searchDiv(){const t=document.createElement("div"),s=document.createElement("input"),i=document.createElement("div");t.classList.add(this.classes.search);const n={main:t,input:s};if(this.settings.showSearch||(t.classList.add(this.classes.hide),s.readOnly=!0),s.type="search",s.placeholder=this.settings.searchPlaceholder,s.tabIndex=-1,s.setAttribute("aria-label",this.settings.searchPlaceholder),s.setAttribute("autocapitalize","off"),s.setAttribute("autocomplete","off"),s.setAttribute("autocorrect","off"),s.oninput=e((t=>{this.callbacks.search(t.target.value)}),100),s.onkeydown=t=>{switch(t.key){case"ArrowUp":case"ArrowDown":return"ArrowDown"===t.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Escape":return this.callbacks.close(),!1;case"Enter":case" ":if(this.callbacks.addable&&t.ctrlKey)return i.click(),!1;{const t=this.content.list.querySelector("."+this.classes.highlighted);if(t)return t.click(),!1}return!0}return!0},t.appendChild(s),this.callbacks.addable){i.classList.add(this.classes.addable);const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 100 100");const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",this.classes.addablePath),e.appendChild(s),i.appendChild(e),i.onclick=t=>{if(t.preventDefault(),t.stopPropagation(),!this.callbacks.addable)return;const e=this.content.search.input.value.trim();if(""===e)return void this.content.search.input.focus();const s=t=>{let e=new a(t);if(this.callbacks.addOption(e),this.settings.isMultiple){let t=this.store.getSelected();t.push(e.value),this.callbacks.setSelected(t,!0)}else this.callbacks.setSelected([e.value],!0);this.callbacks.search(""),this.settings.closeOnSelect&&setTimeout((()=>{this.callbacks.close()}),100)},i=this.callbacks.addable(e);!1!==i&&null!=i&&(i instanceof Promise?i.then((t=>{s("string"==typeof t?{text:t,value:t}:t)})):s("string"==typeof i?{text:i,value:i}:i))},t.appendChild(i),n.addable={main:i,svg:e,path:s}}return n}searchFocus(){this.content.search.input.focus()}getOptions(t=!1,e=!1,s=!1){let i="."+this.classes.option;return t&&(i+=":not(."+this.classes.placeholder+")"),e&&(i+=":not(."+this.classes.disabled+")"),s&&(i+=":not(."+this.classes.hide+")"),Array.from(this.content.list.querySelectorAll(i))}highlight(t){const e=this.getOptions(!0,!0,!0);if(0===e.length)return;if(1===e.length&&!e[0].classList.contains(this.classes.highlighted))return void e[0].classList.add(this.classes.highlighted);let s=!1;for(const t of e)t.classList.contains(this.classes.highlighted)&&(s=!0);if(!s)for(const t of e)if(t.classList.contains(this.classes.selected)){t.classList.add(this.classes.highlighted);break}for(let s=0;s<e.length;s++)if(e[s].classList.contains(this.classes.highlighted)){const i=e[s];i.classList.remove(this.classes.highlighted);const n=i.parentElement;if(n&&n.classList.contains(this.classes.open)){const t=n.querySelector("."+this.classes.optgroupLabel);t&&t.click()}let a=e["down"===t?s+1<e.length?s+1:0:s-1>=0?s-1:e.length-1];a.classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,a);const l=a.parentElement;if(l&&l.classList.contains(this.classes.close)){const t=l.querySelector("."+this.classes.optgroupLabel);t&&t.click()}return}e["down"===t?0:e.length-1].classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,e["down"===t?0:e.length-1])}listDiv(){const t=document.createElement("div");return t.classList.add(this.classes.list),t}renderError(t){this.content.list.innerHTML="";const e=document.createElement("div");e.classList.add(this.classes.error),e.textContent=t,this.content.list.appendChild(e)}renderSearching(){this.content.list.innerHTML="";const t=document.createElement("div");t.classList.add(this.classes.searching),t.textContent=this.settings.searchingText,this.content.list.appendChild(t)}renderOptions(t){if(this.content.list.innerHTML="",0===t.length){const t=document.createElement("div");return t.classList.add(this.classes.search),t.innerHTML=this.settings.searchText,void this.content.list.appendChild(t)}for(const e of t){if(e instanceof n){const t=document.createElement("div");t.classList.add(this.classes.optgroup);const s=document.createElement("div");s.classList.add(this.classes.optgroupLabel),t.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.optgroupLabelText),i.textContent=e.label,s.appendChild(i);const n=document.createElement("div");if(n.classList.add(this.classes.optgroupActions),s.appendChild(n),this.settings.isMultiple&&e.selectAll){const t=document.createElement("div");t.classList.add(this.classes.optgroupSelectAll);let s=!0;for(const t of e.options)if(!t.selected){s=!1;break}s&&t.classList.add(this.classes.selected);const i=document.createElement("span");i.textContent=e.selectAllText,t.appendChild(i);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),t.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optgroupSelectAllBox),a.appendChild(l);const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.classes.optgroupSelectAllCheck),a.appendChild(o),t.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation();const i=this.store.getSelected();if(s){const t=i.filter((t=>{for(const s of e.options)if(t===s.value)return!1;return!0}));this.callbacks.setSelected(t,!0)}else{const t=i.concat(e.options.map((t=>t.value)));for(const t of e.options)this.store.getOptionByID(t.id)||this.callbacks.addOption(t);this.callbacks.setSelected(t,!0)}})),n.appendChild(t)}if("off"!==e.closable){const i=document.createElement("div");i.classList.add(this.classes.optgroupClosable);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),a.classList.add(this.classes.arrow),i.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");a.appendChild(l),e.options.some((t=>t.selected))||""!==this.content.search.input.value.trim()?(i.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"open"===e.closable?(t.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"close"===e.closable&&(t.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose)),s.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation(),t.classList.contains(this.classes.close)?(t.classList.remove(this.classes.close),t.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):(t.classList.remove(this.classes.open),t.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose))})),n.appendChild(i)}t.appendChild(s);for(const s of e.options)t.appendChild(this.option(s));this.content.list.appendChild(t)}e instanceof a&&this.content.list.appendChild(this.option(e))}}option(t){if(t.placeholder){const t=document.createElement("div");return t.classList.add(this.classes.option),t.classList.add(this.classes.hide),t}const e=document.createElement("div");return e.dataset.id=t.id,e.id=t.id,e.classList.add(this.classes.option),e.setAttribute("role","option"),t.class&&t.class.split(" ").forEach((t=>{e.classList.add(t)})),t.style&&(e.style.cssText=t.style),this.settings.searchHighlight&&""!==this.content.search.input.value.trim()?e.innerHTML=this.highlightText(""!==t.html?t.html:t.text,this.content.search.input.value,this.classes.searchHighlighter):""!==t.html?e.innerHTML=t.html:e.textContent=t.text,this.settings.showOptionTooltips&&e.textContent&&e.setAttribute("title",e.textContent),t.display||e.classList.add(this.classes.hide),t.disabled&&e.classList.add(this.classes.disabled),t.selected&&this.settings.hideSelected&&e.classList.add(this.classes.hide),t.selected?(e.classList.add(this.classes.selected),e.setAttribute("aria-selected","true"),this.main.main.setAttribute("aria-activedescendant",e.id)):(e.classList.remove(this.classes.selected),e.setAttribute("aria-selected","false")),e.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation();const s=this.store.getSelected(),i=e.currentTarget,n=String(i.dataset.id);if(t.disabled||t.selected&&!this.settings.allowDeselect)return;if(this.settings.isMultiple&&this.settings.maxSelected<=s.length&&!t.selected||this.settings.isMultiple&&this.settings.minSelected>=s.length&&t.selected)return;let a=!1;const l=this.store.getSelectedOptions();let o=[];this.settings.isMultiple&&(o=t.selected?l.filter((t=>t.id!==n)):l.concat(t)),this.settings.isMultiple||(o=t.selected?[]:[t]),this.callbacks.beforeChange||(a=!0),this.callbacks.beforeChange&&(a=!1!==this.callbacks.beforeChange(o,l)),a&&(this.store.getOptionByID(n)||this.callbacks.addOption(t),this.callbacks.setSelected(o.map((t=>t.value)),!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(o))})),e}destroy(){this.main.main.remove(),this.content.main.remove()}highlightText(t,e,s){let i=t;const n=new RegExp("("+e.trim()+")(?![^<]*>[^<>]*</)","i");if(!t.match(n))return t;const a=t.match(n).index,l=a+t.match(n)[0].toString().length,o=t.substring(a,l);return i=i.replace(n,`<mark class="${s}">${o}</mark>`),i}moveContentAbove(){const t=this.main.main.offsetHeight,e=this.content.main.offsetHeight;this.main.main.classList.remove(this.classes.openBelow),this.main.main.classList.add(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.content.main.classList.add(this.classes.openAbove);const s=this.main.main.getBoundingClientRect();this.content.main.style.margin="-"+(t+e-1)+"px 0px 0px 0px",this.content.main.style.top=s.top+s.height+window.scrollY+"px",this.content.main.style.left=s.left+window.scrollX+"px",this.content.main.style.width=s.width+"px"}moveContentBelow(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.add(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.add(this.classes.openBelow);const t=this.main.main.getBoundingClientRect();this.content.main.style.margin="-1px 0px 0px 0px","relative"!==this.settings.contentPosition&&(this.content.main.style.top=t.top+t.height+window.scrollY+"px",this.content.main.style.left=t.left+window.scrollX+"px",this.content.main.style.width=t.width+"px")}ensureElementInView(t,e){const s=t.scrollTop+t.offsetTop,i=s+t.clientHeight,n=e.offsetTop,a=n+e.clientHeight;n<s?t.scrollTop-=s-n:a>i&&(t.scrollTop+=a-i)}putContent(){const t=this.main.main.offsetHeight,e=this.main.main.getBoundingClientRect(),s=this.content.main.offsetHeight;return window.innerHeight-(e.top+t)<=s&&e.top>s?"up":"down"}updateDeselectAll(){if(!this.store||!this.settings)return;const t=this.store.getSelectedOptions(),e=t&&t.length>0,s=this.settings.isMultiple,i=this.settings.allowDeselect,n=this.main.deselect.main,a=this.classes.hide;!i||s&&!e?n.classList.add(a):n.classList.remove(a)}}class c{constructor(t){this.listen=!1,this.observer=null,this.select=t,this.valueChange=this.valueChange.bind(this),this.select.addEventListener("change",this.valueChange,{passive:!0}),this.observer=new MutationObserver(this.observeCall.bind(this)),this.changeListen(!0)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){this.select.tabIndex=-1,this.select.style.display="none",this.select.setAttribute("aria-hidden","true")}showUI(){this.select.removeAttribute("tabindex"),this.select.style.display="",this.select.removeAttribute("aria-hidden")}changeListen(t){this.listen=t,t&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),t||this.observer&&this.observer.disconnect()}valueChange(t){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedValues()),!0}observeCall(t){if(!this.listen)return;let e=!1,s=!1,i=!1;for(const n of t)n.target===this.select&&("disabled"===n.attributeName&&(s=!0),"class"===n.attributeName&&(e=!0)),"OPTGROUP"!==n.target.nodeName&&"OPTION"!==n.target.nodeName||(i=!0);e&&this.onClassChange&&this.onClassChange(this.select.className.split(" ")),s&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),i&&this.onOptionsChange&&(this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0))}getData(){let t=[];const e=this.select.childNodes;for(const s of e)"OPTGROUP"===s.nodeName&&t.push(this.getDataFromOptgroup(s)),"OPTION"===s.nodeName&&t.push(this.getDataFromOption(s));return t}getDataFromOptgroup(t){let e={id:t.id,label:t.label,selectAll:!!t.dataset&&"true"===t.dataset.selectall,selectAllText:t.dataset?t.dataset.selectalltext:"Select all",closable:t.dataset?t.dataset.closable:"off",options:[]};const s=t.childNodes;for(const t of s)"OPTION"===t.nodeName&&e.options.push(this.getDataFromOption(t));return e}getDataFromOption(t){return{id:t.id,value:t.value,text:t.text,html:t.dataset&&t.dataset.html?t.dataset.html:"",selected:t.selected,display:"none"!==t.style.display,disabled:t.disabled,mandatory:!!t.dataset&&"true"===t.dataset.mandatory,placeholder:"true"===t.dataset.placeholder,class:t.className,style:t.style.cssText,data:t.dataset}}getSelectedValues(){let t=[];const e=this.select.childNodes;for(const s of e){if("OPTGROUP"===s.nodeName){const e=s.childNodes;for(const s of e)if("OPTION"===s.nodeName){const e=s;e.selected&&t.push(e.value)}}if("OPTION"===s.nodeName){const e=s;e.selected&&t.push(e.value)}}return t}setSelected(t){this.changeListen(!1);const e=this.select.childNodes;for(const s of e){if("OPTGROUP"===s.nodeName){const e=s.childNodes;for(const s of e)if("OPTION"===s.nodeName){const e=s;e.selected=t.includes(e.value)}}if("OPTION"===s.nodeName){const e=s;e.selected=t.includes(e.value)}}this.changeListen(!0)}updateSelect(t,e,s){this.changeListen(!1),t&&(this.select.dataset.id=t),e&&(this.select.style.cssText=e),s&&(this.select.className="",s.forEach((t=>{""!==t.trim()&&this.select.classList.add(t.trim())}))),this.changeListen(!0)}updateOptions(t){this.changeListen(!1),this.select.innerHTML="";for(const e of t)e instanceof n&&this.select.appendChild(this.createOptgroup(e)),e instanceof a&&this.select.appendChild(this.createOption(e));this.select.dispatchEvent(new Event("change")),this.changeListen(!0)}createOptgroup(t){const e=document.createElement("optgroup");if(e.id=t.id,e.label=t.label,t.selectAll&&(e.dataset.selectAll="true"),"off"!==t.closable&&(e.dataset.closable=t.closable),t.options)for(const s of t.options)e.appendChild(this.createOption(s));return e}createOption(t){const e=document.createElement("option");return e.id=t.id,e.value=t.value,e.innerHTML=t.text,""!==t.html&&e.setAttribute("data-html",t.html),t.selected&&(e.selected=t.selected),t.disabled&&(e.disabled=!0),!1===t.display&&(e.style.display="none"),t.placeholder&&e.setAttribute("data-placeholder","true"),t.mandatory&&e.setAttribute("data-mandatory","true"),t.class&&t.class.split(" ").forEach((t=>{e.classList.add(t)})),t.data&&"object"==typeof t.data&&Object.keys(t.data).forEach((s=>{e.setAttribute("data-"+function(t){const e=t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()));return t[0]===t[0].toUpperCase()?e.substring(1):e}(s),t.data[s])})),e}destroy(){this.changeListen(!1),this.select.removeEventListener("change",this.valueChange),this.observer&&(this.observer.disconnect(),this.observer=null),delete this.select.dataset.id,this.showUI()}}return class{constructor(t){var s;if(this.events={search:void 0,searchFilter:(t,e)=>-1!==t.text.toLowerCase().indexOf(e.toLowerCase()),addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0},this.windowResize=e((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.windowScroll=e((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.documentClick=t=>{this.settings.isOpen&&t.target&&!function(t,e){function s(t,s){return s&&t&&t.classList&&t.classList.contains(s)||s&&t&&t.dataset&&t.dataset.id&&t.dataset.id===e?t:null}return s(t,e)||function t(e,i){return e&&e!==document?s(e,i)?e:t(e.parentNode,i):null}(t,e)}(t.target,this.settings.id)&&this.close(t.type)},this.windowVisibilityChange=()=>{document.hidden&&this.close()},this.selectEl="string"==typeof t.select?document.querySelector(t.select):t.select,!this.selectEl)return void(t.events&&t.events.error&&t.events.error(new Error("Could not find select element")));if("SELECT"!==this.selectEl.tagName)return void(t.events&&t.events.error&&t.events.error(new Error("Element isnt of type select")));this.selectEl.dataset.ssid&&this.destroy(),this.settings=new i(t.settings);const n=["afterChange","beforeOpen","afterOpen","beforeClose","afterClose"];for(const s in t.events)t.events.hasOwnProperty(s)&&(-1!==n.indexOf(s)?this.events[s]=e(t.events[s],100):this.events[s]=t.events[s]);this.settings.disabled=(null===(s=t.settings)||void 0===s?void 0:s.disabled)?t.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(" "),this.select=new c(this.selectEl),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.onValueChange=t=>{this.setSelected(t)},this.select.onClassChange=t=>{this.settings.class=t,this.render.updateClassStyles()},this.select.onDisabledChange=t=>{t?this.disable():this.enable()},this.select.onOptionsChange=t=>{this.setData(t)},this.store=new l(this.settings.isMultiple?"multiple":"single",t.data?t.data:this.select.getData()),t.data&&this.select.updateOptions(this.store.getData());const a={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:this.setSelected.bind(this),addOption:this.addOption.bind(this),search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.render=new o(this.settings,this.store,a),this.render.renderValues(),this.render.renderOptions(this.store.getData());const h=this.selectEl.getAttribute("aria-label"),r=this.selectEl.getAttribute("aria-labelledby");h?this.render.main.main.setAttribute("aria-label",h):r&&this.render.main.main.setAttribute("aria-labelledby",r),this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),document.addEventListener("click",this.documentClick),window.addEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.addEventListener("scroll",this.windowScroll,!1),document.addEventListener("visibilitychange",this.windowVisibilityChange),this.settings.disabled&&this.disable(),this.settings.alwaysOpen&&this.open(),this.selectEl.slim=this}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(t){const e=this.store.getSelected(),i=this.store.validateDataArray(t);if(i)return void(this.events.error&&this.events.error(i));this.store.setData(t);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),this.render.renderOptions(n),this.events.afterChange&&!s(e,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}getSelected(){return this.store.getSelected()}setSelected(t,e=!0){const i=this.store.getSelected();this.store.setSelectedBy("value",Array.isArray(t)?t:[t]);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),""!==this.render.content.search.input.value?this.search(this.render.content.search.input.value):this.render.renderOptions(n),e&&this.events.afterChange&&!s(i,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}addOption(t){const e=this.store.getSelected();this.store.getDataOptions().some((e=>{var s;return e.value===(null!==(s=t.value)&&void 0!==s?s:t.text)}))||this.store.addOption(t);const i=this.store.getData();this.select.updateOptions(i),this.render.renderValues(),this.render.renderOptions(i),this.events.afterChange&&!s(e,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}open(){this.settings.disabled||this.settings.isOpen||(this.events.beforeOpen&&this.events.beforeOpen(),this.render.open(),this.settings.showSearch&&this.render.searchFocus(),this.settings.isOpen=!0,setTimeout((()=>{this.events.afterOpen&&this.events.afterOpen(),this.settings.isOpen&&(this.settings.isFullOpen=!0)}),this.settings.timeoutDelay),"absolute"===this.settings.contentPosition&&(this.settings.intervalMove&&clearInterval(this.settings.intervalMove),this.settings.intervalMove=setInterval(this.render.moveContent.bind(this.render),500)))}close(t=null){this.settings.isOpen&&!this.settings.alwaysOpen&&(this.events.beforeClose&&this.events.beforeClose(),this.render.close(),""!==this.render.content.search.input.value&&this.search(""),this.render.mainFocus(t),this.settings.isOpen=!1,this.settings.isFullOpen=!1,setTimeout((()=>{this.events.afterClose&&this.events.afterClose()}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove))}search(t){if(this.render.content.search.input.value!==t&&(this.render.content.search.input.value=t),!this.events.search)return void this.render.renderOptions(""===t?this.store.getData():this.store.search(t,this.events.searchFilter));this.render.renderSearching();const e=this.events.search(t,this.store.getSelectedOptions());e instanceof Promise?e.then((t=>{this.render.renderOptions(this.store.partialToFullData(t))})).catch((t=>{this.render.renderError("string"==typeof t?t:t.message)})):Array.isArray(e)?this.render.renderOptions(this.store.partialToFullData(e)):this.render.renderError("Search event must return a promise or an array of data")}destroy(){document.removeEventListener("click",this.documentClick),window.removeEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.removeEventListener("scroll",this.windowScroll,!1),document.removeEventListener("visibilitychange",this.windowVisibilityChange),this.store.setData([]),this.render.destroy(),this.select.destroy()}}})); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SlimSelect=t()}(this,(function(){"use strict";function e(){return Math.random().toString(36).substring(2,10)}function t(e,t=50,s=!1){let i;return function(...n){const a=self,l=s&&!i;clearTimeout(i),i=setTimeout((()=>{i=null,s||e.apply(a,n)}),t),l&&e.apply(a,n)}}function s(e,t){return JSON.stringify(e)===JSON.stringify(t)}class i{constructor(t){this.id="",this.style="",this.class=[],this.isMultiple=!1,this.isOpen=!1,this.isFullOpen=!1,this.intervalMove=null,t||(t={}),this.id="ss-"+e(),this.style=t.style||"",this.class=t.class||[],this.disabled=void 0!==t.disabled&&t.disabled,this.alwaysOpen=void 0!==t.alwaysOpen&&t.alwaysOpen,this.showSearch=void 0===t.showSearch||t.showSearch,this.searchPlaceholder=t.searchPlaceholder||"Search",this.searchText=t.searchText||"No Results",this.searchingText=t.searchingText||"Searching...",this.searchHighlight=void 0!==t.searchHighlight&&t.searchHighlight,this.closeOnSelect=void 0===t.closeOnSelect||t.closeOnSelect,this.contentLocation=t.contentLocation||document.body,this.contentPosition=t.contentPosition||"absolute",this.openPosition=t.openPosition||"auto",this.placeholderText=void 0!==t.placeholderText?t.placeholderText:"Select Value",this.allowDeselect=void 0!==t.allowDeselect&&t.allowDeselect,this.hideSelected=void 0!==t.hideSelected&&t.hideSelected,this.showOptionTooltips=void 0!==t.showOptionTooltips&&t.showOptionTooltips,this.minSelected=t.minSelected||0,this.maxSelected=t.maxSelected||1e3,this.timeoutDelay=t.timeoutDelay||200,this.maxValuesShown=t.maxValuesShown||20,this.maxValuesMessage=t.maxValuesMessage||"{number} selected"}}class n{constructor(t){if(this.id=t.id&&""!==t.id?t.id:e(),this.label=t.label||"",this.selectAll=void 0!==t.selectAll&&t.selectAll,this.selectAllText=t.selectAllText||"Select All",this.closable=t.closable||"off",this.options=[],t.options)for(const e of t.options)this.options.push(new a(e))}}class a{constructor(t){this.id=t.id&&""!==t.id?t.id:e(),this.value=void 0===t.value?t.text:t.value,this.text=t.text||"",this.html=t.html||"",this.selected=void 0!==t.selected&&t.selected,this.display=void 0===t.display||t.display,this.disabled=void 0!==t.disabled&&t.disabled,this.mandatory=void 0!==t.mandatory&&t.mandatory,this.placeholder=void 0!==t.placeholder&&t.placeholder,this.class=t.class||"",this.style=t.style||"",this.data=t.data||{}}}class l{constructor(e,t){this.selectType="single",this.data=[],this.selectType=e,this.setData(t)}validateDataArray(e){if(!Array.isArray(e))return new Error("Data must be an array");for(let t of e){if(!(t instanceof n||"label"in t))return t instanceof a||"text"in t?this.validateOption(t):new Error("Data object must be a valid optgroup or option");if(!("label"in t))return new Error("Optgroup must have a label");if("options"in t&&t.options)for(let e of t.options)return this.validateOption(e)}return null}validateOption(e){return"text"in e?null:new Error("Option must have a text")}partialToFullData(e){let t=[];return e.forEach((e=>{if(e instanceof n||"label"in e){let s=[];"options"in e&&e.options&&e.options.forEach((e=>{s.push(new a(e))})),s.length>0&&t.push(new n(e))}(e instanceof a||"text"in e)&&t.push(new a(e))})),t}setData(e){this.data=this.partialToFullData(e),"single"===this.selectType&&this.setSelectedBy("value",this.getSelected())}getData(){return this.filter(null,!0)}getDataOptions(){return this.filter(null,!1)}addOption(e){this.setData(this.getData().concat(new a(e)))}setSelectedBy(e,t){let s=null,i=!1;for(let l of this.data){if(l instanceof n)for(let n of l.options)s||(s=n),n.selected=!i&&t.includes(n[e]),n.selected&&"single"===this.selectType&&(i=!0);l instanceof a&&(s||(s=l),l.selected=!i&&t.includes(l[e]),l.selected&&"single"===this.selectType&&(i=!0))}"single"===this.selectType&&s&&!i&&(s.selected=!0)}getSelected(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.value)})),t}getSelectedOptions(){return this.filter((e=>e.selected),!1)}getSelectedIDs(){let e=this.getSelectedOptions(),t=[];return e.forEach((e=>{t.push(e.id)})),t}getOptgroupByID(e){for(let t of this.data)if(t instanceof n&&t.id===e)return t;return null}getOptionByID(e){let t=this.filter((t=>t.id===e),!1);return t.length?t[0]:null}search(e,t){return""===(e=e.trim())?this.getData():this.filter((s=>t(s,e)),!0)}filter(e,t){const s=[];return this.data.forEach((i=>{if(i instanceof n){let l=[];if(i.options.forEach((i=>{e&&!e(i)||(t?l.push(new a(i)):s.push(new a(i)))})),l.length>0){let e=new n(i);e.options=l,s.push(e)}}i instanceof a&&(e&&!e(i)||s.push(new a(i)))})),s}getSelectType(){return this.selectType}}class o{constructor(e,t,s){this.classes={main:"ss-main",placeholder:"ss-placeholder",values:"ss-values",single:"ss-single",max:"ss-max",value:"ss-value",valueText:"ss-value-text",valueDelete:"ss-value-delete",valueOut:"ss-value-out",deselect:"ss-deselect",deselectPath:"M10,10 L90,90 M10,90 L90,10",arrow:"ss-arrow",arrowClose:"M10,30 L50,70 L90,30",arrowOpen:"M10,70 L50,30 L90,70",content:"ss-content",openAbove:"ss-open-above",openBelow:"ss-open-below",search:"ss-search",searchHighlighter:"ss-search-highlight",searching:"ss-searching",addable:"ss-addable",addablePath:"M50,10 L50,90 M10,50 L90,50",list:"ss-list",optgroup:"ss-optgroup",optgroupLabel:"ss-optgroup-label",optgroupLabelText:"ss-optgroup-label-text",optgroupActions:"ss-optgroup-actions",optgroupSelectAll:"ss-selectall",optgroupSelectAllBox:"M60,10 L10,10 L10,90 L90,90 L90,50",optgroupSelectAllCheck:"M30,45 L50,70 L90,10",optgroupClosable:"ss-closable",option:"ss-option",optionDelete:"M10,10 L90,90 M10,90 L90,10",highlighted:"ss-highlighted",open:"ss-open",close:"ss-close",selected:"ss-selected",error:"ss-error",disabled:"ss-disabled",hide:"ss-hide"},this.store=t,this.settings=e,this.callbacks=s,this.main=this.mainDiv(),this.content=this.contentDiv(),this.updateClassStyles(),this.updateAriaAttributes(),this.settings.contentLocation.appendChild(this.content.main)}enable(){this.main.main.classList.remove(this.classes.disabled),this.content.search.input.disabled=!1}disable(){this.main.main.classList.add(this.classes.disabled),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute("d",this.classes.arrowOpen),this.main.main.classList.add("up"===this.settings.openPosition?this.classes.openAbove:this.classes.openBelow),this.main.main.setAttribute("aria-expanded","true"),this.moveContent();const e=this.store.getSelectedOptions();if(e.length){const t=e[e.length-1].id,s=this.content.list.querySelector('[data-id="'+t+'"]');s&&this.ensureElementInView(this.content.list,s)}}close(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.remove(this.classes.openBelow),this.main.main.setAttribute("aria-expanded","false"),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.main.arrow.path.setAttribute("d",this.classes.arrowClose)}updateClassStyles(){if(this.main.main.className="",this.main.main.removeAttribute("style"),this.content.main.className="",this.content.main.removeAttribute("style"),this.main.main.classList.add(this.classes.main),this.content.main.classList.add(this.classes.content),""!==this.settings.style&&(this.main.main.style.cssText=this.settings.style,this.content.main.style.cssText=this.settings.style),this.settings.class.length)for(const e of this.settings.class)""!==e.trim()&&(this.main.main.classList.add(e.trim()),this.content.main.classList.add(e.trim()));"relative"===this.settings.contentPosition&&this.content.main.classList.add("ss-"+this.settings.contentPosition)}updateAriaAttributes(){this.main.main.role="combobox",this.main.main.setAttribute("aria-haspopup","listbox"),this.main.main.setAttribute("aria-controls",this.content.main.id),this.main.main.setAttribute("aria-expanded","false"),this.content.main.setAttribute("role","listbox")}mainDiv(){var e;const t=document.createElement("div");t.dataset.id=this.settings.id,t.id=this.settings.id,t.tabIndex=0,t.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Enter":case" ":this.callbacks.open();const t=this.content.list.querySelector("."+this.classes.highlighted);return t&&t.click(),!1;case"Escape":return this.callbacks.close(),!1}},t.onclick=e=>{this.settings.disabled||(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};const s=document.createElement("div");s.classList.add(this.classes.values),t.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.deselect);const n=null===(e=this.store)||void 0===e?void 0:e.getSelectedOptions();!this.settings.allowDeselect||this.settings.isMultiple&&n&&n.length<=0?i.classList.add(this.classes.hide):i.classList.remove(this.classes.hide),i.onclick=e=>{if(e.stopPropagation(),this.settings.disabled)return;let t=!0;const s=this.store.getSelectedOptions(),i=[];this.callbacks.beforeChange&&(t=!0===this.callbacks.beforeChange(i,s)),t&&(this.settings.isMultiple?(this.callbacks.setSelected([],!1),this.updateDeselectAll()):this.callbacks.setSelected([""],!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(i))};const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.deselectPath),a.appendChild(l),i.appendChild(a),t.appendChild(i);const o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.classList.add(this.classes.arrow),o.setAttribute("viewBox","0 0 100 100");const c=document.createElementNS("http://www.w3.org/2000/svg","path");return c.setAttribute("d",this.classes.arrowClose),this.settings.alwaysOpen&&o.classList.add(this.classes.hide),o.appendChild(c),t.appendChild(o),{main:t,values:s,deselect:{main:i,svg:a,path:l},arrow:{main:o,path:c}}}mainFocus(e){"click"!==e&&this.main.main.focus({preventScroll:!0})}placeholder(){const e=this.store.filter((e=>e.placeholder),!1);let t=this.settings.placeholderText;e.length&&(""!==e[0].html?t=e[0].html:""!==e[0].text&&(t=e[0].text));const s=document.createElement("div");return s.classList.add(this.classes.placeholder),s.innerHTML=t,s}renderValues(){this.settings.isMultiple?this.renderMultipleValues():this.renderSingleValue()}renderSingleValue(){const e=this.store.filter((e=>e.selected&&!e.placeholder),!1),t=e.length>0?e[0]:null;if(t){const e=document.createElement("div");e.classList.add(this.classes.single),t.html?e.innerHTML=t.html:e.innerText=t.text,this.main.values.innerHTML=e.outerHTML}else this.main.values.innerHTML=this.placeholder().outerHTML;this.settings.allowDeselect&&e.length?this.main.deselect.main.classList.remove(this.classes.hide):this.main.deselect.main.classList.add(this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter((e=>e.selected&&e.display),!1);if(0===t.length)return void(this.main.values.innerHTML=this.placeholder().outerHTML);{const e=this.main.values.querySelector("."+this.classes.placeholder);e&&e.remove()}if(t.length>this.settings.maxValuesShown){const e=document.createElement("div");return e.classList.add(this.classes.max),e.textContent=this.settings.maxValuesMessage.replace("{number}",t.length.toString()),void(this.main.values.innerHTML=e.outerHTML)}{const e=this.main.values.querySelector("."+this.classes.max);e&&e.remove()}let s=[];for(let i=0;i<e.length;i++){const n=e[i],a=n.getAttribute("data-id");if(a){t.filter((e=>e.id===a),!1).length||s.push(n)}}for(const e of s)e.classList.add(this.classes.valueOut),setTimeout((()=>{this.main.values.hasChildNodes()&&this.main.values.contains(e)&&this.main.values.removeChild(e)}),100);e=this.main.values.childNodes;for(let s=0;s<t.length;s++){let i=!0;for(let n=0;n<e.length;n++)t[s].id===String(e[n].dataset.id)&&(i=!1);i&&(0===e.length?this.main.values.appendChild(this.multipleValue(t[s])):0===s?this.main.values.insertBefore(this.multipleValue(t[s]),e[s]):e[s-1].insertAdjacentElement("afterend",this.multipleValue(t[s])))}this.updateDeselectAll()}multipleValue(e){const t=document.createElement("div");t.classList.add(this.classes.value),t.dataset.id=e.id;const s=document.createElement("div");if(s.classList.add(this.classes.valueText),s.innerText=e.text,t.appendChild(s),!e.mandatory){const s=document.createElement("div");s.classList.add(this.classes.valueDelete),s.onclick=t=>{if(t.preventDefault(),t.stopPropagation(),this.settings.disabled)return;let s=!0;const i=this.store.getSelectedOptions(),l=i.filter((t=>t.selected&&t.id!==e.id),!0);if(!(this.settings.minSelected&&l.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(s=!0===this.callbacks.beforeChange(l,i)),s)){let e=[];for(const t of l){if(t instanceof n)for(const s of t.options)e.push(s.value);t instanceof a&&e.push(t.value)}this.callbacks.setSelected(e,!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(l),this.updateDeselectAll()}};const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optionDelete),i.appendChild(l),s.appendChild(i),t.appendChild(s)}return t}contentDiv(){const e=document.createElement("div");e.dataset.id=this.settings.id,e.id=this.settings.id;const t=this.searchDiv();e.appendChild(t.main);const s=this.listDiv();return e.appendChild(s),{main:e,search:t,list:s}}moveContent(){"relative"!==this.settings.contentPosition&&"down"!==this.settings.openPosition?"up"!==this.settings.openPosition?"up"===this.putContent()?this.moveContentAbove():this.moveContentBelow():this.moveContentAbove():this.moveContentBelow()}searchDiv(){const e=document.createElement("div"),s=document.createElement("input"),i=document.createElement("div");e.classList.add(this.classes.search);const n={main:e,input:s};if(this.settings.showSearch||(e.classList.add(this.classes.hide),s.readOnly=!0),s.type="search",s.placeholder=this.settings.searchPlaceholder,s.tabIndex=-1,s.setAttribute("aria-label",this.settings.searchPlaceholder),s.setAttribute("autocapitalize","off"),s.setAttribute("autocomplete","off"),s.setAttribute("autocorrect","off"),s.oninput=t((e=>{this.callbacks.search(e.target.value)}),100),s.onkeydown=e=>{switch(e.key){case"ArrowUp":case"ArrowDown":return"ArrowDown"===e.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Escape":return this.callbacks.close(),!1;case"Enter":case" ":if(this.callbacks.addable&&e.ctrlKey)return i.click(),!1;{const e=this.content.list.querySelector("."+this.classes.highlighted);if(e)return e.click(),!1}return!0}},e.appendChild(s),this.callbacks.addable){i.classList.add(this.classes.addable);const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 100 100");const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",this.classes.addablePath),t.appendChild(s),i.appendChild(t),i.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;const t=this.content.search.input.value.trim();if(""===t)return void this.content.search.input.focus();const s=e=>{let t=new a(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.value),this.callbacks.setSelected(e,!0)}else this.callbacks.setSelected([t.value],!0);this.callbacks.search(""),this.settings.closeOnSelect&&setTimeout((()=>{this.callbacks.close()}),100)},i=this.callbacks.addable(t);!1!==i&&null!=i&&(i instanceof Promise?i.then((e=>{s("string"==typeof e?{text:e,value:e}:e)})):s("string"==typeof i?{text:i,value:i}:i))},e.appendChild(i),n.addable={main:i,svg:t,path:s}}return n}searchFocus(){this.content.search.input.focus()}getOptions(e=!1,t=!1,s=!1){let i="."+this.classes.option;return e&&(i+=":not(."+this.classes.placeholder+")"),t&&(i+=":not(."+this.classes.disabled+")"),s&&(i+=":not(."+this.classes.hide+")"),Array.from(this.content.list.querySelectorAll(i))}highlight(e){const t=this.getOptions(!0,!0,!0);if(0!==t.length)if(1!==t.length||t[0].classList.contains(this.classes.highlighted)){for(let s=0;s<t.length;s++)if(t[s].classList.contains(this.classes.highlighted)){const i=t[s];i.classList.remove(this.classes.highlighted);const n=i.parentElement;if(n&&n.classList.contains(this.classes.open)){const e=n.querySelector("."+this.classes.optgroupLabel);e&&e.click()}let a=t["down"===e?s+1<t.length?s+1:0:s-1>=0?s-1:t.length-1];a.classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,a);const l=a.parentElement;if(l&&l.classList.contains(this.classes.close)){const e=l.querySelector("."+this.classes.optgroupLabel);e&&e.click()}return}t["down"===e?0:t.length-1].classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,t["down"===e?0:t.length-1])}else t[0].classList.add(this.classes.highlighted)}listDiv(){const e=document.createElement("div");return e.classList.add(this.classes.list),e}renderError(e){this.content.list.innerHTML="";const t=document.createElement("div");t.classList.add(this.classes.error),t.textContent=e,this.content.list.appendChild(t)}renderSearching(){this.content.list.innerHTML="";const e=document.createElement("div");e.classList.add(this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e)}renderOptions(e){if(this.content.list.innerHTML="",0===e.length){const e=document.createElement("div");return e.classList.add(this.classes.search),e.innerHTML=this.settings.searchText,void this.content.list.appendChild(e)}for(const t of e){if(t instanceof n){const e=document.createElement("div");e.classList.add(this.classes.optgroup);const s=document.createElement("div");s.classList.add(this.classes.optgroupLabel),e.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.optgroupLabelText),i.textContent=t.label,s.appendChild(i);const n=document.createElement("div");if(n.classList.add(this.classes.optgroupActions),s.appendChild(n),this.settings.isMultiple&&t.selectAll){const e=document.createElement("div");e.classList.add(this.classes.optgroupSelectAll);let s=!0;for(const e of t.options)if(!e.selected){s=!1;break}s&&e.classList.add(this.classes.selected);const i=document.createElement("span");i.textContent=t.selectAllText,e.appendChild(i);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),e.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optgroupSelectAllBox),a.appendChild(l);const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.classes.optgroupSelectAllCheck),a.appendChild(o),e.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation();const i=this.store.getSelected();if(s){const e=i.filter((e=>{for(const s of t.options)if(e===s.value)return!1;return!0}));this.callbacks.setSelected(e,!0)}else{const e=i.concat(t.options.map((e=>e.value)));for(const e of t.options)this.store.getOptionByID(e.id)||this.callbacks.addOption(e);this.callbacks.setSelected(e,!0)}})),n.appendChild(e)}if("off"!==t.closable){const i=document.createElement("div");i.classList.add(this.classes.optgroupClosable);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),a.classList.add(this.classes.arrow),i.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");a.appendChild(l),t.options.some((e=>e.selected))||""!==this.content.search.input.value.trim()?(i.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"open"===t.closable?(e.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"close"===t.closable&&(e.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose)),s.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),e.classList.contains(this.classes.close)?(e.classList.remove(this.classes.close),e.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):(e.classList.remove(this.classes.open),e.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose))})),n.appendChild(i)}e.appendChild(s);for(const s of t.options)e.appendChild(this.option(s));this.content.list.appendChild(e)}t instanceof a&&this.content.list.appendChild(this.option(t))}}option(e){if(e.placeholder){const e=document.createElement("div");return e.classList.add(this.classes.option),e.classList.add(this.classes.hide),e}const t=document.createElement("div");return t.dataset.id=e.id,t.id=e.id,t.classList.add(this.classes.option),t.setAttribute("role","option"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.style&&(t.style.cssText=e.style),this.settings.searchHighlight&&""!==this.content.search.input.value.trim()?t.innerHTML=this.highlightText(""!==e.html?e.html:e.text,this.content.search.input.value,this.classes.searchHighlighter):""!==e.html?t.innerHTML=e.html:t.textContent=e.text,this.settings.showOptionTooltips&&t.textContent&&t.setAttribute("title",t.textContent),e.display||t.classList.add(this.classes.hide),e.disabled&&t.classList.add(this.classes.disabled),e.selected&&this.settings.hideSelected&&t.classList.add(this.classes.hide),e.selected?(t.classList.add(this.classes.selected),t.setAttribute("aria-selected","true"),this.main.main.setAttribute("aria-activedescendant",t.id)):(t.classList.remove(this.classes.selected),t.setAttribute("aria-selected","false")),t.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation();const s=this.store.getSelected(),i=t.currentTarget,n=String(i.dataset.id);if(e.disabled||e.selected&&!this.settings.allowDeselect)return;if(this.settings.isMultiple&&this.settings.maxSelected<=s.length&&!e.selected||this.settings.isMultiple&&this.settings.minSelected>=s.length&&e.selected)return;let a=!1;const l=this.store.getSelectedOptions();let o=[];this.settings.isMultiple&&(o=e.selected?l.filter((e=>e.id!==n)):l.concat(e)),this.settings.isMultiple||(o=e.selected?[]:[e]),this.callbacks.beforeChange||(a=!0),this.callbacks.beforeChange&&(a=!1!==this.callbacks.beforeChange(o,l)),a&&(this.store.getOptionByID(n)||this.callbacks.addOption(e),this.callbacks.setSelected(o.map((e=>e.value)),!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(o))})),t}destroy(){this.main.main.remove(),this.content.main.remove()}highlightText(e,t,s){let i=e;const n=new RegExp("("+t.trim()+")(?![^<]*>[^<>]*</)","i");if(!e.match(n))return e;const a=e.match(n).index,l=a+e.match(n)[0].toString().length,o=e.substring(a,l);return i=i.replace(n,`<mark class="${s}">${o}</mark>`),i}moveContentAbove(){const e=this.main.main.offsetHeight,t=this.content.main.offsetHeight;this.main.main.classList.remove(this.classes.openBelow),this.main.main.classList.add(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.content.main.classList.add(this.classes.openAbove);const s=this.main.main.getBoundingClientRect();this.content.main.style.margin="-"+(e+t-1)+"px 0px 0px 0px",this.content.main.style.top=s.top+s.height+window.scrollY+"px",this.content.main.style.left=s.left+window.scrollX+"px",this.content.main.style.width=s.width+"px"}moveContentBelow(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.add(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.add(this.classes.openBelow);const e=this.main.main.getBoundingClientRect();this.content.main.style.margin="-1px 0px 0px 0px","relative"!==this.settings.contentPosition&&(this.content.main.style.top=e.top+e.height+window.scrollY+"px",this.content.main.style.left=e.left+window.scrollX+"px",this.content.main.style.width=e.width+"px")}ensureElementInView(e,t){const s=e.scrollTop+e.offsetTop,i=s+e.clientHeight,n=t.offsetTop,a=n+t.clientHeight;n<s?e.scrollTop-=s-n:a>i&&(e.scrollTop+=a-i)}putContent(){const e=this.main.main.offsetHeight,t=this.main.main.getBoundingClientRect(),s=this.content.main.offsetHeight;return window.innerHeight-(t.top+e)<=s&&t.top>s?"up":"down"}updateDeselectAll(){if(!this.store||!this.settings)return;const e=this.store.getSelectedOptions(),t=e&&e.length>0,s=this.settings.isMultiple,i=this.settings.allowDeselect,n=this.main.deselect.main,a=this.classes.hide;!i||s&&!t?n.classList.add(a):n.classList.remove(a)}}class c{constructor(e){this.listen=!1,this.observer=null,this.select=e,this.select.addEventListener("change",this.valueChange.bind(this),{passive:!0}),this.observer=new MutationObserver(this.observeCall.bind(this)),this.changeListen(!0)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){this.select.tabIndex=-1,this.select.style.display="none",this.select.setAttribute("aria-hidden","true")}showUI(){this.select.removeAttribute("tabindex"),this.select.style.display="",this.select.removeAttribute("aria-hidden")}changeListen(e){this.listen=e,e&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),e||this.observer&&this.observer.disconnect()}valueChange(e){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedValues()),!0}observeCall(e){if(!this.listen)return;let t=!1,s=!1,i=!1;for(const n of e)n.target===this.select&&("disabled"===n.attributeName&&(s=!0),"class"===n.attributeName&&(t=!0)),"OPTGROUP"!==n.target.nodeName&&"OPTION"!==n.target.nodeName||(i=!0);t&&this.onClassChange&&this.onClassChange(this.select.className.split(" ")),s&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),i&&this.onOptionsChange&&(this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0))}getData(){let e=[];const t=this.select.childNodes;for(const s of t)"OPTGROUP"===s.nodeName&&e.push(this.getDataFromOptgroup(s)),"OPTION"===s.nodeName&&e.push(this.getDataFromOption(s));return e}getDataFromOptgroup(e){let t={id:e.id,label:e.label,selectAll:!!e.dataset&&"true"===e.dataset.selectall,selectAllText:e.dataset?e.dataset.selectalltext:"Select all",closable:e.dataset?e.dataset.closable:"off",options:[]};const s=e.childNodes;for(const e of s)"OPTION"===e.nodeName&&t.options.push(this.getDataFromOption(e));return t}getDataFromOption(e){return{id:e.id,value:e.value,text:e.text,html:e.dataset&&e.dataset.html?e.dataset.html:"",selected:e.selected,display:"none"!==e.style.display,disabled:e.disabled,mandatory:!!e.dataset&&"true"===e.dataset.mandatory,placeholder:"true"===e.dataset.placeholder,class:e.className,style:e.style.cssText,data:e.dataset}}getSelectedValues(){let e=[];const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected&&e.push(t.value)}}return e}setSelected(e){this.changeListen(!1);const t=this.select.childNodes;for(const s of t){if("OPTGROUP"===s.nodeName){const t=s.childNodes;for(const s of t)if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}if("OPTION"===s.nodeName){const t=s;t.selected=e.includes(t.value)}}this.changeListen(!0)}updateSelect(e,t,s){this.changeListen(!1),e&&(this.select.dataset.id=e),t&&(this.select.style.cssText=t),s&&(this.select.className="",s.forEach((e=>{""!==e.trim()&&this.select.classList.add(e.trim())}))),this.changeListen(!0)}updateOptions(e){this.changeListen(!1),this.select.innerHTML="";for(const t of e)t instanceof n&&this.select.appendChild(this.createOptgroup(t)),t instanceof a&&this.select.appendChild(this.createOption(t));this.select.dispatchEvent(new Event("change")),this.changeListen(!0)}createOptgroup(e){const t=document.createElement("optgroup");if(t.id=e.id,t.label=e.label,e.selectAll&&(t.dataset.selectAll="true"),"off"!==e.closable&&(t.dataset.closable=e.closable),e.options)for(const s of e.options)t.appendChild(this.createOption(s));return t}createOption(e){const t=document.createElement("option");return t.id=e.id,t.value=e.value,t.innerHTML=e.text,""!==e.html&&t.setAttribute("data-html",e.html),e.selected&&(t.selected=e.selected),e.disabled&&(t.disabled=!0),!1===e.display&&(t.style.display="none"),e.placeholder&&t.setAttribute("data-placeholder","true"),e.mandatory&&t.setAttribute("data-mandatory","true"),e.class&&e.class.split(" ").forEach((e=>{t.classList.add(e)})),e.data&&"object"==typeof e.data&&Object.keys(e.data).forEach((s=>{t.setAttribute("data-"+function(e){const t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(e=>"-"+e.toLowerCase()));return e[0]===e[0].toUpperCase()?t.substring(1):t}(s),e.data[s])})),t}destroy(){this.changeListen(!1),this.select.removeEventListener("change",this.valueChange.bind(this)),this.observer&&(this.observer.disconnect(),this.observer=null),delete this.select.dataset.id,this.showUI()}}return class{constructor(e){var s;if(this.events={search:void 0,searchFilter:(e,t)=>-1!==e.text.toLowerCase().indexOf(t.toLowerCase()),addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0},this.windowResize=t((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.windowScroll=t((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.documentClick=e=>{this.settings.isOpen&&e.target&&!function(e,t){function s(e,s){return s&&e&&e.classList&&e.classList.contains(s)||s&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}return s(e,t)||function e(t,i){return t&&t!==document?s(t,i)?t:e(t.parentNode,i):null}(e,t)}(e.target,this.settings.id)&&this.close(e.type)},this.windowVisibilityChange=()=>{document.hidden&&this.close()},this.selectEl="string"==typeof e.select?document.querySelector(e.select):e.select,!this.selectEl)return void(e.events&&e.events.error&&e.events.error(new Error("Could not find select element")));if("SELECT"!==this.selectEl.tagName)return void(e.events&&e.events.error&&e.events.error(new Error("Element isnt of type select")));this.selectEl.dataset.ssid&&this.destroy(),this.settings=new i(e.settings);const n=["afterChange","beforeOpen","afterOpen","beforeClose","afterClose"];for(const s in e.events)e.events.hasOwnProperty(s)&&(-1!==n.indexOf(s)?this.events[s]=t(e.events[s],100):this.events[s]=e.events[s]);this.settings.disabled=(null===(s=e.settings)||void 0===s?void 0:s.disabled)?e.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(" "),this.select=new c(this.selectEl),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.onValueChange=e=>{this.setSelected(e)},this.select.onClassChange=e=>{this.settings.class=e,this.render.updateClassStyles()},this.select.onDisabledChange=e=>{e?this.disable():this.enable()},this.select.onOptionsChange=e=>{this.setData(e)},this.store=new l(this.settings.isMultiple?"multiple":"single",e.data?e.data:this.select.getData()),e.data&&this.select.updateOptions(this.store.getData());const a={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:this.setSelected.bind(this),addOption:this.addOption.bind(this),search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.render=new o(this.settings,this.store,a),this.render.renderValues(),this.render.renderOptions(this.store.getData());const h=this.selectEl.getAttribute("aria-label"),r=this.selectEl.getAttribute("aria-labelledby");h?this.render.main.main.setAttribute("aria-label",h):r&&this.render.main.main.setAttribute("aria-labelledby",r),this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),document.addEventListener("click",this.documentClick),window.addEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.addEventListener("scroll",this.windowScroll,!1),document.addEventListener("visibilitychange",this.windowVisibilityChange),this.settings.disabled&&this.disable(),this.settings.alwaysOpen&&this.open(),this.selectEl.slim=this}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){const t=this.store.getSelected(),i=this.store.validateDataArray(e);if(i)return void(this.events.error&&this.events.error(i));this.store.setData(e);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),this.render.renderOptions(n),this.events.afterChange&&!s(t,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}getSelected(){return this.store.getSelected()}setSelected(e,t=!0){const i=this.store.getSelected();this.store.setSelectedBy("value",Array.isArray(e)?e:[e]);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),""!==this.render.content.search.input.value?this.search(this.render.content.search.input.value):this.render.renderOptions(n),t&&this.events.afterChange&&!s(i,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}addOption(e){const t=this.store.getSelected();this.store.getDataOptions().some((t=>{var s;return t.value===(null!==(s=e.value)&&void 0!==s?s:e.text)}))||this.store.addOption(e);const i=this.store.getData();this.select.updateOptions(i),this.render.renderValues(),this.render.renderOptions(i),this.events.afterChange&&!s(t,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}open(){this.settings.disabled||this.settings.isOpen||(this.events.beforeOpen&&this.events.beforeOpen(),this.render.open(),this.settings.showSearch&&this.render.searchFocus(),this.settings.isOpen=!0,setTimeout((()=>{this.events.afterOpen&&this.events.afterOpen(),this.settings.isOpen&&(this.settings.isFullOpen=!0)}),this.settings.timeoutDelay),"absolute"===this.settings.contentPosition&&(this.settings.intervalMove&&clearInterval(this.settings.intervalMove),this.settings.intervalMove=setInterval(this.render.moveContent.bind(this.render),500)))}close(e=null){this.settings.isOpen&&!this.settings.alwaysOpen&&(this.events.beforeClose&&this.events.beforeClose(),this.render.close(),""!==this.render.content.search.input.value&&this.search(""),this.render.mainFocus(e),this.settings.isOpen=!1,this.settings.isFullOpen=!1,setTimeout((()=>{this.events.afterClose&&this.events.afterClose()}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove))}search(e){if(this.render.content.search.input.value!==e&&(this.render.content.search.input.value=e),!this.events.search)return void this.render.renderOptions(""===e?this.store.getData():this.store.search(e,this.events.searchFilter));this.render.renderSearching();const t=this.events.search(e,this.store.getSelectedOptions());t instanceof Promise?t.then((e=>{this.render.renderOptions(this.store.partialToFullData(e))})).catch((e=>{this.render.renderError("string"==typeof e?e:e.message)})):Array.isArray(t)?this.render.renderOptions(this.store.partialToFullData(t)):this.render.renderError("Search event must return a promise or an array of data")}destroy(){document.removeEventListener("click",this.documentClick),window.removeEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.removeEventListener("scroll",this.windowScroll,!1),document.removeEventListener("visibilitychange",this.windowVisibilityChange),this.store.setData([]),this.render.destroy(),this.select.destroy()}}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SlimSelect=e()}(this,(function(){"use strict";function t(){return Math.random().toString(36).substring(2,10)}function e(t,e=50,s=!1){let i;return function(...n){const a=self,l=s&&!i;clearTimeout(i),i=setTimeout((()=>{i=null,s||t.apply(a,n)}),e),l&&t.apply(a,n)}}function s(t,e){return JSON.stringify(t)===JSON.stringify(e)}class i{constructor(e){this.id="",this.style="",this.class=[],this.isMultiple=!1,this.isOpen=!1,this.isFullOpen=!1,this.intervalMove=null,e||(e={}),this.id="ss-"+t(),this.style=e.style||"",this.class=e.class||[],this.disabled=void 0!==e.disabled&&e.disabled,this.alwaysOpen=void 0!==e.alwaysOpen&&e.alwaysOpen,this.showSearch=void 0===e.showSearch||e.showSearch,this.ariaLabel=e.ariaLabel||"Combobox",this.searchPlaceholder=e.searchPlaceholder||"Search",this.searchText=e.searchText||"No Results",this.searchingText=e.searchingText||"Searching...",this.searchHighlight=void 0!==e.searchHighlight&&e.searchHighlight,this.closeOnSelect=void 0===e.closeOnSelect||e.closeOnSelect,this.contentLocation=e.contentLocation||document.body,this.contentPosition=e.contentPosition||"absolute",this.openPosition=e.openPosition||"auto",this.placeholderText=void 0!==e.placeholderText?e.placeholderText:"Select Value",this.allowDeselect=void 0!==e.allowDeselect&&e.allowDeselect,this.hideSelected=void 0!==e.hideSelected&&e.hideSelected,this.showOptionTooltips=void 0!==e.showOptionTooltips&&e.showOptionTooltips,this.minSelected=e.minSelected||0,this.maxSelected=e.maxSelected||1e3,this.timeoutDelay=e.timeoutDelay||200,this.maxValuesShown=e.maxValuesShown||20,this.maxValuesMessage=e.maxValuesMessage||"{number} selected"}}class n{constructor(e){if(this.id=e.id&&""!==e.id?e.id:t(),this.label=e.label||"",this.selectAll=void 0!==e.selectAll&&e.selectAll,this.selectAllText=e.selectAllText||"Select All",this.closable=e.closable||"off",this.options=[],e.options)for(const t of e.options)this.options.push(new a(t))}}class a{constructor(e){this.id=e.id&&""!==e.id?e.id:t(),this.value=void 0===e.value?e.text:e.value,this.text=e.text||"",this.html=e.html||"",this.selected=void 0!==e.selected&&e.selected,this.display=void 0===e.display||e.display,this.disabled=void 0!==e.disabled&&e.disabled,this.mandatory=void 0!==e.mandatory&&e.mandatory,this.placeholder=void 0!==e.placeholder&&e.placeholder,this.class=e.class||"",this.style=e.style||"",this.data=e.data||{}}}class l{constructor(t,e){this.selectType="single",this.data=[],this.selectType=t,this.setData(e)}validateDataArray(t){if(!Array.isArray(t))return new Error("Data must be an array");for(let e of t){if(!(e instanceof n||"label"in e))return e instanceof a||"text"in e?this.validateOption(e):new Error("Data object must be a valid optgroup or option");if(!("label"in e))return new Error("Optgroup must have a label");if("options"in e&&e.options)for(let t of e.options)return this.validateOption(t)}return null}validateOption(t){return"text"in t?null:new Error("Option must have a text")}partialToFullData(t){let e=[];return t.forEach((t=>{if(t instanceof n||"label"in t){let s=[];"options"in t&&t.options&&t.options.forEach((t=>{s.push(new a(t))})),s.length>0&&e.push(new n(t))}(t instanceof a||"text"in t)&&e.push(new a(t))})),e}setData(t){this.data=this.partialToFullData(t),"single"===this.selectType&&this.setSelectedBy("value",this.getSelected())}getData(){return this.filter(null,!0)}getDataOptions(){return this.filter(null,!1)}addOption(t){this.setData(this.getData().concat(new a(t)))}setSelectedBy(t,e){let s=null,i=!1;for(let l of this.data){if(l instanceof n)for(let n of l.options)s||(s=n),n.selected=!i&&e.includes(n[t]),n.selected&&"single"===this.selectType&&(i=!0);l instanceof a&&(s||(s=l),l.selected=!i&&e.includes(l[t]),l.selected&&"single"===this.selectType&&(i=!0))}"single"===this.selectType&&s&&!i&&(s.selected=!0)}getSelected(){let t=this.getSelectedOptions(),e=[];return t.forEach((t=>{e.push(t.value)})),e}getSelectedOptions(){return this.filter((t=>t.selected),!1)}getSelectedIDs(){let t=this.getSelectedOptions(),e=[];return t.forEach((t=>{e.push(t.id)})),e}getOptgroupByID(t){for(let e of this.data)if(e instanceof n&&e.id===t)return e;return null}getOptionByID(t){let e=this.filter((e=>e.id===t),!1);return e.length?e[0]:null}getSelectType(){return this.selectType}getFirstOption(){let t=null;for(let e of this.data)if(e instanceof n?t=e.options[0]:e instanceof a&&(t=e),t)break;return t}search(t,e){return""===(t=t.trim())?this.getData():this.filter((s=>e(s,t)),!0)}filter(t,e){const s=[];return this.data.forEach((i=>{if(i instanceof n){let l=[];if(i.options.forEach((i=>{t&&!t(i)||(e?l.push(new a(i)):s.push(new a(i)))})),l.length>0){let t=new n(i);t.options=l,s.push(t)}}i instanceof a&&(t&&!t(i)||s.push(new a(i)))})),s}}class o{constructor(t,e,s){this.classes={main:"ss-main",placeholder:"ss-placeholder",values:"ss-values",single:"ss-single",max:"ss-max",value:"ss-value",valueText:"ss-value-text",valueDelete:"ss-value-delete",valueOut:"ss-value-out",deselect:"ss-deselect",deselectPath:"M10,10 L90,90 M10,90 L90,10",arrow:"ss-arrow",arrowClose:"M10,30 L50,70 L90,30",arrowOpen:"M10,70 L50,30 L90,70",content:"ss-content",openAbove:"ss-open-above",openBelow:"ss-open-below",search:"ss-search",searchHighlighter:"ss-search-highlight",searching:"ss-searching",addable:"ss-addable",addablePath:"M50,10 L50,90 M10,50 L90,50",list:"ss-list",optgroup:"ss-optgroup",optgroupLabel:"ss-optgroup-label",optgroupLabelText:"ss-optgroup-label-text",optgroupActions:"ss-optgroup-actions",optgroupSelectAll:"ss-selectall",optgroupSelectAllBox:"M60,10 L10,10 L10,90 L90,90 L90,50",optgroupSelectAllCheck:"M30,45 L50,70 L90,10",optgroupClosable:"ss-closable",option:"ss-option",optionDelete:"M10,10 L90,90 M10,90 L90,10",highlighted:"ss-highlighted",open:"ss-open",close:"ss-close",selected:"ss-selected",error:"ss-error",disabled:"ss-disabled",hide:"ss-hide"},this.store=e,this.settings=t,this.callbacks=s,this.main=this.mainDiv(),this.content=this.contentDiv(),this.updateClassStyles(),this.updateAriaAttributes(),this.settings.contentLocation.appendChild(this.content.main)}enable(){this.main.main.classList.remove(this.classes.disabled),this.content.search.input.disabled=!1}disable(){this.main.main.classList.add(this.classes.disabled),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute("d",this.classes.arrowOpen),this.main.main.classList.add("up"===this.settings.openPosition?this.classes.openAbove:this.classes.openBelow),this.main.main.setAttribute("aria-expanded","true"),this.moveContent();const t=this.store.getSelectedOptions();if(t.length){const e=t[t.length-1].id,s=this.content.list.querySelector('[data-id="'+e+'"]');s&&this.ensureElementInView(this.content.list,s)}}close(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.remove(this.classes.openBelow),this.main.main.setAttribute("aria-expanded","false"),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.main.arrow.path.setAttribute("d",this.classes.arrowClose)}updateClassStyles(){if(this.main.main.className="",this.main.main.removeAttribute("style"),this.content.main.className="",this.content.main.removeAttribute("style"),this.main.main.classList.add(this.classes.main),this.content.main.classList.add(this.classes.content),""!==this.settings.style&&(this.main.main.style.cssText=this.settings.style,this.content.main.style.cssText=this.settings.style),this.settings.class.length)for(const t of this.settings.class)""!==t.trim()&&(this.main.main.classList.add(t.trim()),this.content.main.classList.add(t.trim()));"relative"===this.settings.contentPosition&&this.content.main.classList.add("ss-"+this.settings.contentPosition)}updateAriaAttributes(){this.main.main.role="combobox",this.main.main.setAttribute("aria-haspopup","listbox"),this.main.main.setAttribute("aria-controls",this.content.main.id),this.main.main.setAttribute("aria-expanded","false"),this.content.main.setAttribute("role","listbox")}mainDiv(){var t;const e=document.createElement("div");e.dataset.id=this.settings.id,e.setAttribute("aria-label",this.settings.ariaLabel),e.tabIndex=0,e.onkeydown=t=>{switch(t.key){case"ArrowUp":case"ArrowDown":return this.callbacks.open(),"ArrowDown"===t.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Enter":case" ":this.callbacks.open();const e=this.content.list.querySelector("."+this.classes.highlighted);return e&&e.click(),!1;case"Escape":return this.callbacks.close(),!1}return!1},e.onclick=t=>{this.settings.disabled||(this.settings.isOpen?this.callbacks.close():this.callbacks.open())};const s=document.createElement("div");s.classList.add(this.classes.values),e.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.deselect);const n=null===(t=this.store)||void 0===t?void 0:t.getSelectedOptions();!this.settings.allowDeselect||this.settings.isMultiple&&n&&n.length<=0?i.classList.add(this.classes.hide):i.classList.remove(this.classes.hide),i.onclick=t=>{if(t.stopPropagation(),this.settings.disabled)return;let e=!0;const s=this.store.getSelectedOptions(),i=[];if(this.callbacks.beforeChange&&(e=!0===this.callbacks.beforeChange(i,s)),e){if(this.settings.isMultiple)this.callbacks.setSelected([],!1),this.updateDeselectAll();else{const t=this.store.getFirstOption(),e=t?t.value:"";this.callbacks.setSelected(e,!1)}this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(this.store.getSelectedOptions())}};const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.deselectPath),a.appendChild(l),i.appendChild(a),e.appendChild(i);const o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.classList.add(this.classes.arrow),o.setAttribute("viewBox","0 0 100 100");const c=document.createElementNS("http://www.w3.org/2000/svg","path");return c.setAttribute("d",this.classes.arrowClose),this.settings.alwaysOpen&&o.classList.add(this.classes.hide),o.appendChild(c),e.appendChild(o),{main:e,values:s,deselect:{main:i,svg:a,path:l},arrow:{main:o,path:c}}}mainFocus(t){"click"!==t&&this.main.main.focus({preventScroll:!0})}placeholder(){const t=this.store.filter((t=>t.placeholder),!1);let e=this.settings.placeholderText;t.length&&(""!==t[0].html?e=t[0].html:""!==t[0].text&&(e=t[0].text));const s=document.createElement("div");return s.classList.add(this.classes.placeholder),s.innerHTML=e,s}renderValues(){this.settings.isMultiple?this.renderMultipleValues():this.renderSingleValue()}renderSingleValue(){const t=this.store.filter((t=>t.selected&&!t.placeholder),!1),e=t.length>0?t[0]:null;if(e){const t=document.createElement("div");t.classList.add(this.classes.single),e.html?t.innerHTML=e.html:t.innerText=e.text,this.main.values.innerHTML=t.outerHTML}else this.main.values.innerHTML=this.placeholder().outerHTML;this.settings.allowDeselect&&t.length?this.main.deselect.main.classList.remove(this.classes.hide):this.main.deselect.main.classList.add(this.classes.hide)}renderMultipleValues(){let t=this.main.values.childNodes,e=this.store.filter((t=>t.selected&&t.display),!1);if(0===e.length)return void(this.main.values.innerHTML=this.placeholder().outerHTML);{const t=this.main.values.querySelector("."+this.classes.placeholder);t&&t.remove()}if(e.length>this.settings.maxValuesShown){const t=document.createElement("div");return t.classList.add(this.classes.max),t.textContent=this.settings.maxValuesMessage.replace("{number}",e.length.toString()),void(this.main.values.innerHTML=t.outerHTML)}{const t=this.main.values.querySelector("."+this.classes.max);t&&t.remove()}let s=[];for(let i=0;i<t.length;i++){const n=t[i],a=n.getAttribute("data-id");if(a){e.filter((t=>t.id===a),!1).length||s.push(n)}}for(const t of s)t.classList.add(this.classes.valueOut),setTimeout((()=>{this.main.values.hasChildNodes()&&this.main.values.contains(t)&&this.main.values.removeChild(t)}),100);t=this.main.values.childNodes;for(let s=0;s<e.length;s++){let i=!0;for(let n=0;n<t.length;n++)e[s].id===String(t[n].dataset.id)&&(i=!1);i&&(0===t.length?this.main.values.appendChild(this.multipleValue(e[s])):0===s?this.main.values.insertBefore(this.multipleValue(e[s]),t[s]):t[s-1].insertAdjacentElement("afterend",this.multipleValue(e[s])))}this.updateDeselectAll()}multipleValue(t){const e=document.createElement("div");e.classList.add(this.classes.value),e.dataset.id=t.id;const s=document.createElement("div");if(s.classList.add(this.classes.valueText),s.innerText=t.text,e.appendChild(s),!t.mandatory){const s=document.createElement("div");s.classList.add(this.classes.valueDelete),s.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),this.settings.disabled)return;let s=!0;const i=this.store.getSelectedOptions(),l=i.filter((e=>e.selected&&e.id!==t.id),!0);if(!(this.settings.minSelected&&l.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(s=!0===this.callbacks.beforeChange(l,i)),s)){let t=[];for(const e of l){if(e instanceof n)for(const s of e.options)t.push(s.value);e instanceof a&&t.push(e.value)}this.callbacks.setSelected(t,!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(l),this.updateDeselectAll()}};const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 100 100");const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optionDelete),i.appendChild(l),s.appendChild(i),e.appendChild(s)}return e}contentDiv(){const t=document.createElement("div");t.dataset.id=this.settings.id;const e=this.searchDiv();t.appendChild(e.main);const s=this.listDiv();return t.appendChild(s),{main:t,search:e,list:s}}moveContent(){"relative"!==this.settings.contentPosition&&"down"!==this.settings.openPosition?"up"!==this.settings.openPosition?"up"===this.putContent()?this.moveContentAbove():this.moveContentBelow():this.moveContentAbove():this.moveContentBelow()}searchDiv(){const t=document.createElement("div"),s=document.createElement("input"),i=document.createElement("div");t.classList.add(this.classes.search);const n={main:t,input:s};if(this.settings.showSearch||(t.classList.add(this.classes.hide),s.readOnly=!0),s.type="search",s.placeholder=this.settings.searchPlaceholder,s.tabIndex=-1,s.setAttribute("aria-label",this.settings.searchPlaceholder),s.setAttribute("autocapitalize","off"),s.setAttribute("autocomplete","off"),s.setAttribute("autocorrect","off"),s.oninput=e((t=>{this.callbacks.search(t.target.value)}),100),s.onkeydown=t=>{switch(t.key){case"ArrowUp":case"ArrowDown":return"ArrowDown"===t.key?this.highlight("down"):this.highlight("up"),!1;case"Tab":return this.callbacks.close(),!0;case"Escape":return this.callbacks.close(),!1;case"Enter":case" ":if(this.callbacks.addable&&t.ctrlKey)return i.click(),!1;{const t=this.content.list.querySelector("."+this.classes.highlighted);if(t)return t.click(),!1}return!0}return!0},t.appendChild(s),this.callbacks.addable){i.classList.add(this.classes.addable);const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 100 100");const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",this.classes.addablePath),e.appendChild(s),i.appendChild(e),i.onclick=t=>{if(t.preventDefault(),t.stopPropagation(),!this.callbacks.addable)return;const e=this.content.search.input.value.trim();if(""===e)return void this.content.search.input.focus();const s=t=>{let e=new a(t);if(this.callbacks.addOption(e),this.settings.isMultiple){let t=this.store.getSelected();t.push(e.value),this.callbacks.setSelected(t,!0)}else this.callbacks.setSelected([e.value],!0);this.callbacks.search(""),this.settings.closeOnSelect&&setTimeout((()=>{this.callbacks.close()}),100)},i=this.callbacks.addable(e);!1!==i&&null!=i&&(i instanceof Promise?i.then((t=>{s("string"==typeof t?{text:t,value:t}:t)})):s("string"==typeof i?{text:i,value:i}:i))},t.appendChild(i),n.addable={main:i,svg:e,path:s}}return n}searchFocus(){this.content.search.input.focus()}getOptions(t=!1,e=!1,s=!1){let i="."+this.classes.option;return t&&(i+=":not(."+this.classes.placeholder+")"),e&&(i+=":not(."+this.classes.disabled+")"),s&&(i+=":not(."+this.classes.hide+")"),Array.from(this.content.list.querySelectorAll(i))}highlight(t){const e=this.getOptions(!0,!0,!0);if(0===e.length)return;if(1===e.length&&!e[0].classList.contains(this.classes.highlighted))return void e[0].classList.add(this.classes.highlighted);let s=!1;for(const t of e)t.classList.contains(this.classes.highlighted)&&(s=!0);if(!s)for(const t of e)if(t.classList.contains(this.classes.selected)){t.classList.add(this.classes.highlighted);break}for(let s=0;s<e.length;s++)if(e[s].classList.contains(this.classes.highlighted)){const i=e[s];i.classList.remove(this.classes.highlighted);const n=i.parentElement;if(n&&n.classList.contains(this.classes.open)){const t=n.querySelector("."+this.classes.optgroupLabel);t&&t.click()}let a=e["down"===t?s+1<e.length?s+1:0:s-1>=0?s-1:e.length-1];a.classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,a);const l=a.parentElement;if(l&&l.classList.contains(this.classes.close)){const t=l.querySelector("."+this.classes.optgroupLabel);t&&t.click()}return}e["down"===t?0:e.length-1].classList.add(this.classes.highlighted),this.ensureElementInView(this.content.list,e["down"===t?0:e.length-1])}listDiv(){const t=document.createElement("div");return t.classList.add(this.classes.list),t}renderError(t){this.content.list.innerHTML="";const e=document.createElement("div");e.classList.add(this.classes.error),e.textContent=t,this.content.list.appendChild(e)}renderSearching(){this.content.list.innerHTML="";const t=document.createElement("div");t.classList.add(this.classes.searching),t.textContent=this.settings.searchingText,this.content.list.appendChild(t)}renderOptions(t){if(this.content.list.innerHTML="",0===t.length){const t=document.createElement("div");return t.classList.add(this.classes.search),t.innerHTML=this.settings.searchText,void this.content.list.appendChild(t)}for(const e of t){if(e instanceof n){const t=document.createElement("div");t.classList.add(this.classes.optgroup);const s=document.createElement("div");s.classList.add(this.classes.optgroupLabel),t.appendChild(s);const i=document.createElement("div");i.classList.add(this.classes.optgroupLabelText),i.textContent=e.label,s.appendChild(i);const n=document.createElement("div");if(n.classList.add(this.classes.optgroupActions),s.appendChild(n),this.settings.isMultiple&&e.selectAll){const t=document.createElement("div");t.classList.add(this.classes.optgroupSelectAll);let s=!0;for(const t of e.options)if(!t.selected){s=!1;break}s&&t.classList.add(this.classes.selected);const i=document.createElement("span");i.textContent=e.selectAllText,t.appendChild(i);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),t.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",this.classes.optgroupSelectAllBox),a.appendChild(l);const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",this.classes.optgroupSelectAllCheck),a.appendChild(o),t.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation();const i=this.store.getSelected();if(s){const t=i.filter((t=>{for(const s of e.options)if(t===s.value)return!1;return!0}));this.callbacks.setSelected(t,!0)}else{const t=i.concat(e.options.map((t=>t.value)));for(const t of e.options)this.store.getOptionByID(t.id)||this.callbacks.addOption(t);this.callbacks.setSelected(t,!0)}})),n.appendChild(t)}if("off"!==e.closable){const i=document.createElement("div");i.classList.add(this.classes.optgroupClosable);const a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("viewBox","0 0 100 100"),a.classList.add(this.classes.arrow),i.appendChild(a);const l=document.createElementNS("http://www.w3.org/2000/svg","path");a.appendChild(l),e.options.some((t=>t.selected))||""!==this.content.search.input.value.trim()?(i.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"open"===e.closable?(t.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):"close"===e.closable&&(t.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose)),s.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation(),t.classList.contains(this.classes.close)?(t.classList.remove(this.classes.close),t.classList.add(this.classes.open),l.setAttribute("d",this.classes.arrowOpen)):(t.classList.remove(this.classes.open),t.classList.add(this.classes.close),l.setAttribute("d",this.classes.arrowClose))})),n.appendChild(i)}t.appendChild(s);for(const s of e.options)t.appendChild(this.option(s));this.content.list.appendChild(t)}e instanceof a&&this.content.list.appendChild(this.option(e))}}option(t){if(t.placeholder){const t=document.createElement("div");return t.classList.add(this.classes.option),t.classList.add(this.classes.hide),t}const e=document.createElement("div");return e.dataset.id=t.id,e.id=t.id,e.classList.add(this.classes.option),e.setAttribute("role","option"),t.class&&t.class.split(" ").forEach((t=>{e.classList.add(t)})),t.style&&(e.style.cssText=t.style),this.settings.searchHighlight&&""!==this.content.search.input.value.trim()?e.innerHTML=this.highlightText(""!==t.html?t.html:t.text,this.content.search.input.value,this.classes.searchHighlighter):""!==t.html?e.innerHTML=t.html:e.textContent=t.text,this.settings.showOptionTooltips&&e.textContent&&e.setAttribute("title",e.textContent),t.display||e.classList.add(this.classes.hide),t.disabled&&e.classList.add(this.classes.disabled),t.selected&&this.settings.hideSelected&&e.classList.add(this.classes.hide),t.selected?(e.classList.add(this.classes.selected),e.setAttribute("aria-selected","true"),this.main.main.setAttribute("aria-activedescendant",e.id)):(e.classList.remove(this.classes.selected),e.setAttribute("aria-selected","false")),e.addEventListener("click",(e=>{e.preventDefault(),e.stopPropagation();const s=this.store.getSelected(),i=e.currentTarget,n=String(i.dataset.id);if(t.disabled||t.selected&&!this.settings.allowDeselect)return;if(this.settings.isMultiple&&this.settings.maxSelected<=s.length&&!t.selected||this.settings.isMultiple&&this.settings.minSelected>=s.length&&t.selected)return;let a=!1;const l=this.store.getSelectedOptions();let o=[];this.settings.isMultiple&&(o=t.selected?l.filter((t=>t.id!==n)):l.concat(t)),this.settings.isMultiple||(o=t.selected?[]:[t]),this.callbacks.beforeChange||(a=!0),this.callbacks.beforeChange&&(a=!1!==this.callbacks.beforeChange(o,l)),a&&(this.store.getOptionByID(n)||this.callbacks.addOption(t),this.callbacks.setSelected(o.map((t=>t.value)),!1),this.settings.closeOnSelect&&this.callbacks.close(),this.callbacks.afterChange&&this.callbacks.afterChange(o))})),e}destroy(){this.main.main.remove(),this.content.main.remove()}highlightText(t,e,s){let i=t;const n=new RegExp("("+e.trim()+")(?![^<]*>[^<>]*</)","i");if(!t.match(n))return t;const a=t.match(n).index,l=a+t.match(n)[0].toString().length,o=t.substring(a,l);return i=i.replace(n,`<mark class="${s}">${o}</mark>`),i}moveContentAbove(){const t=this.main.main.offsetHeight,e=this.content.main.offsetHeight;this.main.main.classList.remove(this.classes.openBelow),this.main.main.classList.add(this.classes.openAbove),this.content.main.classList.remove(this.classes.openBelow),this.content.main.classList.add(this.classes.openAbove);const s=this.main.main.getBoundingClientRect();this.content.main.style.margin="-"+(t+e-1)+"px 0px 0px 0px",this.content.main.style.top=s.top+s.height+window.scrollY+"px",this.content.main.style.left=s.left+window.scrollX+"px",this.content.main.style.width=s.width+"px"}moveContentBelow(){this.main.main.classList.remove(this.classes.openAbove),this.main.main.classList.add(this.classes.openBelow),this.content.main.classList.remove(this.classes.openAbove),this.content.main.classList.add(this.classes.openBelow);const t=this.main.main.getBoundingClientRect();this.content.main.style.margin="-1px 0px 0px 0px","relative"!==this.settings.contentPosition&&(this.content.main.style.top=t.top+t.height+window.scrollY+"px",this.content.main.style.left=t.left+window.scrollX+"px",this.content.main.style.width=t.width+"px")}ensureElementInView(t,e){const s=t.scrollTop+t.offsetTop,i=s+t.clientHeight,n=e.offsetTop,a=n+e.clientHeight;n<s?t.scrollTop-=s-n:a>i&&(t.scrollTop+=a-i)}putContent(){const t=this.main.main.offsetHeight,e=this.main.main.getBoundingClientRect(),s=this.content.main.offsetHeight;return window.innerHeight-(e.top+t)<=s&&e.top>s?"up":"down"}updateDeselectAll(){if(!this.store||!this.settings)return;const t=this.store.getSelectedOptions(),e=t&&t.length>0,s=this.settings.isMultiple,i=this.settings.allowDeselect,n=this.main.deselect.main,a=this.classes.hide;!i||s&&!e?n.classList.add(a):n.classList.remove(a)}}class c{constructor(t){this.listen=!1,this.observer=null,this.select=t,this.valueChange=this.valueChange.bind(this),this.select.addEventListener("change",this.valueChange,{passive:!0}),this.observer=new MutationObserver(this.observeCall.bind(this)),this.changeListen(!0)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){this.select.tabIndex=-1,this.select.style.display="none",this.select.setAttribute("aria-hidden","true")}showUI(){this.select.removeAttribute("tabindex"),this.select.style.display="",this.select.removeAttribute("aria-hidden")}changeListen(t){this.listen=t,t&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),t||this.observer&&this.observer.disconnect()}valueChange(t){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedValues()),!0}observeCall(t){if(!this.listen)return;let e=!1,s=!1,i=!1;for(const n of t)n.target===this.select&&("disabled"===n.attributeName&&(s=!0),"class"===n.attributeName&&(e=!0)),"OPTGROUP"!==n.target.nodeName&&"OPTION"!==n.target.nodeName||(i=!0);e&&this.onClassChange&&this.onClassChange(this.select.className.split(" ")),s&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),i&&this.onOptionsChange&&(this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0))}getData(){let t=[];const e=this.select.childNodes;for(const s of e)"OPTGROUP"===s.nodeName&&t.push(this.getDataFromOptgroup(s)),"OPTION"===s.nodeName&&t.push(this.getDataFromOption(s));return t}getDataFromOptgroup(t){let e={id:t.id,label:t.label,selectAll:!!t.dataset&&"true"===t.dataset.selectall,selectAllText:t.dataset?t.dataset.selectalltext:"Select all",closable:t.dataset?t.dataset.closable:"off",options:[]};const s=t.childNodes;for(const t of s)"OPTION"===t.nodeName&&e.options.push(this.getDataFromOption(t));return e}getDataFromOption(t){return{id:t.id,value:t.value,text:t.text,html:t.dataset&&t.dataset.html?t.dataset.html:"",selected:t.selected,display:"none"!==t.style.display,disabled:t.disabled,mandatory:!!t.dataset&&"true"===t.dataset.mandatory,placeholder:"true"===t.dataset.placeholder,class:t.className,style:t.style.cssText,data:t.dataset}}getSelectedValues(){let t=[];const e=this.select.childNodes;for(const s of e){if("OPTGROUP"===s.nodeName){const e=s.childNodes;for(const s of e)if("OPTION"===s.nodeName){const e=s;e.selected&&t.push(e.value)}}if("OPTION"===s.nodeName){const e=s;e.selected&&t.push(e.value)}}return t}setSelected(t){this.changeListen(!1);const e=this.select.childNodes;for(const s of e){if("OPTGROUP"===s.nodeName){const e=s.childNodes;for(const s of e)if("OPTION"===s.nodeName){const e=s;e.selected=t.includes(e.value)}}if("OPTION"===s.nodeName){const e=s;e.selected=t.includes(e.value)}}this.changeListen(!0)}updateSelect(t,e,s){this.changeListen(!1),t&&(this.select.dataset.id=t),e&&(this.select.style.cssText=e),s&&(this.select.className="",s.forEach((t=>{""!==t.trim()&&this.select.classList.add(t.trim())}))),this.changeListen(!0)}updateOptions(t){this.changeListen(!1),this.select.innerHTML="";for(const e of t)e instanceof n&&this.select.appendChild(this.createOptgroup(e)),e instanceof a&&this.select.appendChild(this.createOption(e));this.select.dispatchEvent(new Event("change")),this.changeListen(!0)}createOptgroup(t){const e=document.createElement("optgroup");if(e.id=t.id,e.label=t.label,t.selectAll&&(e.dataset.selectAll="true"),"off"!==t.closable&&(e.dataset.closable=t.closable),t.options)for(const s of t.options)e.appendChild(this.createOption(s));return e}createOption(t){const e=document.createElement("option");return e.id=t.id,e.value=t.value,e.innerHTML=t.text,""!==t.html&&e.setAttribute("data-html",t.html),t.selected&&(e.selected=t.selected),t.disabled&&(e.disabled=!0),!1===t.display&&(e.style.display="none"),t.placeholder&&e.setAttribute("data-placeholder","true"),t.mandatory&&e.setAttribute("data-mandatory","true"),t.class&&t.class.split(" ").forEach((t=>{e.classList.add(t)})),t.data&&"object"==typeof t.data&&Object.keys(t.data).forEach((s=>{e.setAttribute("data-"+function(t){const e=t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()));return t[0]===t[0].toUpperCase()?e.substring(1):e}(s),t.data[s])})),e}destroy(){this.changeListen(!1),this.select.removeEventListener("change",this.valueChange),this.observer&&(this.observer.disconnect(),this.observer=null),delete this.select.dataset.id,this.showUI()}}return class{constructor(t){var s;if(this.events={search:void 0,searchFilter:(t,e)=>-1!==t.text.toLowerCase().indexOf(e.toLowerCase()),addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0},this.windowResize=e((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.windowScroll=e((()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()})),this.documentClick=t=>{this.settings.isOpen&&t.target&&!function(t,e){function s(t,s){return s&&t&&t.classList&&t.classList.contains(s)||s&&t&&t.dataset&&t.dataset.id&&t.dataset.id===e?t:null}return s(t,e)||function t(e,i){return e&&e!==document?s(e,i)?e:t(e.parentNode,i):null}(t,e)}(t.target,this.settings.id)&&this.close(t.type)},this.windowVisibilityChange=()=>{document.hidden&&this.close()},this.selectEl="string"==typeof t.select?document.querySelector(t.select):t.select,!this.selectEl)return void(t.events&&t.events.error&&t.events.error(new Error("Could not find select element")));if("SELECT"!==this.selectEl.tagName)return void(t.events&&t.events.error&&t.events.error(new Error("Element isnt of type select")));this.selectEl.dataset.ssid&&this.destroy(),this.settings=new i(t.settings);const n=["afterChange","beforeOpen","afterOpen","beforeClose","afterClose"];for(const s in t.events)t.events.hasOwnProperty(s)&&(-1!==n.indexOf(s)?this.events[s]=e(t.events[s],100):this.events[s]=t.events[s]);this.settings.disabled=(null===(s=t.settings)||void 0===s?void 0:s.disabled)?t.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(" "),this.select=new c(this.selectEl),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.onValueChange=t=>{this.setSelected(t)},this.select.onClassChange=t=>{this.settings.class=t,this.render.updateClassStyles()},this.select.onDisabledChange=t=>{t?this.disable():this.enable()},this.select.onOptionsChange=t=>{this.setData(t)},this.store=new l(this.settings.isMultiple?"multiple":"single",t.data?t.data:this.select.getData()),t.data&&this.select.updateOptions(this.store.getData());const a={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:this.setSelected.bind(this),addOption:this.addOption.bind(this),search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.render=new o(this.settings,this.store,a),this.render.renderValues(),this.render.renderOptions(this.store.getData());const h=this.selectEl.getAttribute("aria-label"),r=this.selectEl.getAttribute("aria-labelledby");h?this.render.main.main.setAttribute("aria-label",h):r&&this.render.main.main.setAttribute("aria-labelledby",r),this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),document.addEventListener("click",this.documentClick),window.addEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.addEventListener("scroll",this.windowScroll,!1),document.addEventListener("visibilitychange",this.windowVisibilityChange),this.settings.disabled&&this.disable(),this.settings.alwaysOpen&&this.open(),this.selectEl.slim=this}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(t){const e=this.store.getSelected(),i=this.store.validateDataArray(t);if(i)return void(this.events.error&&this.events.error(i));this.store.setData(t);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),this.render.renderOptions(n),this.events.afterChange&&!s(e,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}getSelected(){return this.store.getSelected()}setSelected(t,e=!0){const i=this.store.getSelected();this.store.setSelectedBy("value",Array.isArray(t)?t:[t]);const n=this.store.getData();this.select.updateOptions(n),this.render.renderValues(),""!==this.render.content.search.input.value?this.search(this.render.content.search.input.value):this.render.renderOptions(n),e&&this.events.afterChange&&!s(i,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}addOption(t){const e=this.store.getSelected();this.store.getDataOptions().some((e=>{var s;return e.value===(null!==(s=t.value)&&void 0!==s?s:t.text)}))||this.store.addOption(t);const i=this.store.getData();this.select.updateOptions(i),this.render.renderValues(),this.render.renderOptions(i),this.events.afterChange&&!s(e,this.store.getSelected())&&this.events.afterChange(this.store.getSelectedOptions())}open(){this.settings.disabled||this.settings.isOpen||(this.events.beforeOpen&&this.events.beforeOpen(),this.render.open(),this.settings.showSearch&&this.render.searchFocus(),this.settings.isOpen=!0,setTimeout((()=>{this.events.afterOpen&&this.events.afterOpen(),this.settings.isOpen&&(this.settings.isFullOpen=!0)}),this.settings.timeoutDelay),"absolute"===this.settings.contentPosition&&(this.settings.intervalMove&&clearInterval(this.settings.intervalMove),this.settings.intervalMove=setInterval(this.render.moveContent.bind(this.render),500)))}close(t=null){this.settings.isOpen&&!this.settings.alwaysOpen&&(this.events.beforeClose&&this.events.beforeClose(),this.render.close(),""!==this.render.content.search.input.value&&this.search(""),this.render.mainFocus(t),this.settings.isOpen=!1,this.settings.isFullOpen=!1,setTimeout((()=>{this.events.afterClose&&this.events.afterClose()}),this.settings.timeoutDelay),this.settings.intervalMove&&clearInterval(this.settings.intervalMove))}search(t){if(this.render.content.search.input.value!==t&&(this.render.content.search.input.value=t),!this.events.search)return void this.render.renderOptions(""===t?this.store.getData():this.store.search(t,this.events.searchFilter));this.render.renderSearching();const e=this.events.search(t,this.store.getSelectedOptions());e instanceof Promise?e.then((t=>{this.render.renderOptions(this.store.partialToFullData(t))})).catch((t=>{this.render.renderError("string"==typeof t?t:t.message)})):Array.isArray(e)?this.render.renderOptions(this.store.partialToFullData(e)):this.render.renderError("Search event must return a promise or an array of data")}destroy(){document.removeEventListener("click",this.documentClick),window.removeEventListener("resize",this.windowResize,!1),"auto"===this.settings.openPosition&&window.removeEventListener("scroll",this.windowScroll,!1),document.removeEventListener("visibilitychange",this.windowVisibilityChange),this.store.setData([]),this.render.destroy(),this.select.destroy()}}})); |
@@ -73,2 +73,4 @@ export type DataArray = DataObject[]; | ||
getOptionByID(id: string): Option | null; | ||
getSelectType(): string; | ||
getFirstOption(): Option | null; | ||
search(search: string, searchFilter: (opt: Option, search: string) => boolean): DataArray; | ||
@@ -78,4 +80,3 @@ filter(filter: { | ||
} | null, includeOptgroup: boolean): DataArray; | ||
getSelectType(): string; | ||
} | ||
export {}; |
{ | ||
"name": "slim-select", | ||
"description": "Slim advanced select dropdown", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"author": "Brian Voelker <brian@webiswhatido.com> (http://webiswhatido.com)", | ||
@@ -21,4 +21,5 @@ "homepage": "https://slimselectjs.com", | ||
".": { | ||
"import": "./dist/slimselect.js", | ||
"require": "./dist/slimselect.umd.js", | ||
"import": "./dist/slimselect.es.js" | ||
"types": "./dist/*.d.ts" | ||
}, | ||
@@ -53,32 +54,56 @@ "./styles": "./dist/slimselect.css" | ||
}, | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.6.1", | ||
"@rollup/plugin-babel": "^6.0.3", | ||
"@rollup/plugin-commonjs": "^25.0.2", | ||
"@rollup/plugin-node-resolve": "^15.1.0", | ||
"@rollup/plugin-terser": "^0.4.3", | ||
"@rollup/plugin-typescript": "^11.1.2", | ||
"@jest/globals": "^29.7.0", | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@rollup/plugin-typescript": "^11.1.5", | ||
"@slim-select/vue": "workspace:src/vue", | ||
"@types/downloadjs": "^1.4.3", | ||
"@vitejs/plugin-vue": "^4.2.3", | ||
"@types/downloadjs": "^1.4.6", | ||
"@vitejs/plugin-vue": "^4.5.0", | ||
"clipboard": "^2.0.11", | ||
"downloadjs": "^1.4.7", | ||
"jest": "^29.6.1", | ||
"jest-environment-jsdom": "^29.6.1", | ||
"prettier": "^2.8.8", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"prettier": "^3.1.0", | ||
"prismjs": "^1.29.0", | ||
"rimraf": "^5.0.1", | ||
"rollup": "^3.26.2", | ||
"rollup-plugin-typescript2": "^0.35.0", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.5.2", | ||
"rollup-plugin-typescript2": "^0.36.0", | ||
"rollup-plugin-vue": "^6.0.0", | ||
"sass": "^1.63.6", | ||
"ts-jest": "^29.1.1", | ||
"tslib": "^2.6.0", | ||
"typescript": "^5.1.6", | ||
"vite": "^4.4.2", | ||
"vue": "^3.3.4", | ||
"vue-router": "^4.2.4", | ||
"vue-tsc": "^1.8.4", | ||
"vuex": "^4.0.2" | ||
"sass": "^1.59.2", | ||
"ts-jest": "^29.0.5", | ||
"tslib": "^2.5.0", | ||
"typescript": "^4.9.5", | ||
"vite": "^4.1.4", | ||
"vue": "^3.2.47", | ||
"vue-router": "^4.1.6", | ||
"vue-tsc": "^1.2.0", | ||
"vuex": "^4.0.2", | ||
"@rollup/plugin-replace": "^5.0.2", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^14.0.0", | ||
"@testing-library/user-event": "^14.4.3", | ||
"@types/jest": "^29.5.1", | ||
"@types/react": "^18.0.28", | ||
"@types/react-dom": "^18.0.11", | ||
"@typescript-eslint/eslint-plugin": "^5.59.2", | ||
"@typescript-eslint/parser": "^5.59.2", | ||
"@vitejs/plugin-react": "^4.0.0", | ||
"eslint": "^8.39.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-react": "^7.32.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.3.4", | ||
"identity-obj-proxy": "^3.0.0", | ||
"jest-canvas-mock": "^2.5.0", | ||
"rollup-plugin-peer-deps-external": "^2.2.4", | ||
"vite-plugin-dts": "^2.3.0" | ||
} | ||
} |
@@ -8,4 +8,4 @@ /** | ||
import SlimSelect from './' | ||
import { OptionOptional } from 'src/vue/dist/slim-select/store' | ||
import { Config } from 'src/vue/dist/slim-select' | ||
import { OptionOptional } from './store' | ||
import { Config } from './index' | ||
@@ -12,0 +12,0 @@ describe('SlimSelect Module', () => { |
@@ -9,3 +9,3 @@ import { debounce } from './helpers' | ||
addable?: (value: string) => Promise<OptionOptional | string> | OptionOptional | string | false | undefined | null | ||
setSelected: (value: string[], runAfterChange: boolean) => void | ||
setSelected: (value: string | string[], runAfterChange: boolean) => void | ||
addOption: (option: Option) => void | ||
@@ -234,4 +234,7 @@ search: (search: string) => void | ||
main.dataset.id = this.settings.id | ||
main.id = this.settings.id | ||
// main.id = this.settings.id+'-main' // Remove for now as it is not needed | ||
// Add label | ||
main.setAttribute('aria-label', this.settings.ariaLabel) | ||
// Set tabable to allow tabbing to the element | ||
@@ -243,3 +246,3 @@ main.tabIndex = 0 | ||
// when you may not have a search bar | ||
main.onkeydown = (e: KeyboardEvent) => { | ||
main.onkeydown = (e: KeyboardEvent): boolean => { | ||
// Convert above if else statemets to switch | ||
@@ -267,6 +270,8 @@ switch (e.key) { | ||
} | ||
return false | ||
} | ||
// Add onclick for main div | ||
main.onclick = (e: Event) => { | ||
main.onclick = (e: Event): void => { | ||
// Dont do anything if disabled | ||
@@ -321,3 +326,7 @@ if (this.settings.disabled) { | ||
} else { | ||
this.callbacks.setSelected([''], false) | ||
// Get first option and set it as selected | ||
const firstOption = this.store.getFirstOption() | ||
const value = firstOption ? firstOption.value : '' | ||
this.callbacks.setSelected(value, false) | ||
} | ||
@@ -332,3 +341,3 @@ | ||
if (this.callbacks.afterChange) { | ||
this.callbacks.afterChange(after) | ||
this.callbacks.afterChange(this.store.getSelectedOptions()) | ||
} | ||
@@ -633,3 +642,3 @@ } | ||
main.dataset.id = this.settings.id | ||
main.id = this.settings.id | ||
// main.id = this.settings.id + '-content' // Remove for now as it is not needed | ||
@@ -706,3 +715,3 @@ // Add search | ||
// Deal with keyboard events on search input field | ||
input.onkeydown = (e: KeyboardEvent) => { | ||
input.onkeydown = (e: KeyboardEvent): boolean => { | ||
// Convert above if else statemets to switch | ||
@@ -738,2 +747,4 @@ switch (e.key) { | ||
} | ||
return true // Allow normal typing | ||
} | ||
@@ -879,3 +890,3 @@ | ||
if (options.length === 1) { | ||
// Check if option doesnt already has highlighted class | ||
// Check if option doesnt already have highlighted class | ||
if (!options[0].classList.contains(this.classes.highlighted)) { | ||
@@ -887,4 +898,23 @@ options[0].classList.add(this.classes.highlighted) | ||
// Loop through options and see if there are no highlighted ones | ||
let highlighted = false | ||
for (const o of options) { | ||
if (o.classList.contains(this.classes.highlighted)) { | ||
highlighted = true | ||
} | ||
} | ||
// If no highlighted, see if any are selected and if so highlight selected first one | ||
if (!highlighted) { | ||
for (const o of options) { | ||
if (o.classList.contains(this.classes.selected)) { | ||
o.classList.add(this.classes.highlighted) | ||
break | ||
} | ||
} | ||
} | ||
// Loop through options and find the highlighted one | ||
for (let i = 0; i < options.length; i++) { | ||
// Found highlighted option | ||
if (options[i].classList.contains(this.classes.highlighted)) { | ||
@@ -891,0 +921,0 @@ const prevOption = options[i] |
@@ -20,4 +20,5 @@ import { kebabCase } from './helpers' | ||
this.valueChange = this.valueChange.bind(this) | ||
// Add change event listener | ||
this.select.addEventListener('change', this.valueChange.bind(this), { | ||
this.select.addEventListener('change', this.valueChange, { | ||
// allow bubbling of event | ||
@@ -365,3 +366,3 @@ passive: true, | ||
// Remove event change listener | ||
this.select.removeEventListener('change', this.valueChange.bind(this)) | ||
this.select.removeEventListener('change', this.valueChange) | ||
@@ -368,0 +369,0 @@ // Disconnect observer and null |
@@ -20,2 +20,3 @@ import { generateID } from './helpers' | ||
public showSearch: boolean | ||
public ariaLabel: string | ||
public searchPlaceholder: string | ||
@@ -51,2 +52,3 @@ public searchText: string | ||
this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true | ||
this.ariaLabel = settings.ariaLabel || 'Combobox' | ||
this.searchPlaceholder = settings.searchPlaceholder || 'Search' | ||
@@ -53,0 +55,0 @@ this.searchText = settings.searchText || 'No Results' |
@@ -287,2 +287,22 @@ import { generateID } from './helpers' | ||
public getSelectType(): string { | ||
return this.selectType | ||
} | ||
public getFirstOption(): Option | null { | ||
let option: Option | null = null | ||
for (let dataObj of this.data) { | ||
if (dataObj instanceof Optgroup) { | ||
option = dataObj.options[0] | ||
} else if (dataObj instanceof Option) { | ||
option = dataObj | ||
} | ||
if (option) { | ||
break | ||
} | ||
} | ||
return option | ||
} | ||
// Take in search string and return filtered list of values | ||
@@ -346,5 +366,2 @@ public search(search: string, searchFilter: (opt: Option, search: string) => boolean): DataArray { | ||
public getSelectType(): string { | ||
return this.selectType | ||
} | ||
} |
@@ -0,0 +0,0 @@ export declare function generateID(): string; |
@@ -0,0 +0,0 @@ import Settings, { SettingsPartial } from './settings'; |
@@ -7,3 +7,3 @@ import Settings from './settings'; | ||
addable?: (value: string) => Promise<OptionOptional | string> | OptionOptional | string | false | undefined | null; | ||
setSelected: (value: string[], runAfterChange: boolean) => void; | ||
setSelected: (value: string | string[], runAfterChange: boolean) => void; | ||
addOption: (option: Option) => void; | ||
@@ -10,0 +10,0 @@ search: (search: string) => void; |
@@ -0,0 +0,0 @@ import { DataArray, DataArrayPartial, Optgroup, OptgroupOptional, Option } from './store'; |
@@ -14,2 +14,3 @@ /// <reference types="node" /> | ||
showSearch: boolean; | ||
ariaLabel: string; | ||
searchPlaceholder: string; | ||
@@ -16,0 +17,0 @@ searchText: string; |
@@ -73,2 +73,4 @@ export type DataArray = DataObject[]; | ||
getOptionByID(id: string): Option | null; | ||
getSelectType(): string; | ||
getFirstOption(): Option | null; | ||
search(search: string, searchFilter: (opt: Option, search: string) => boolean): DataArray; | ||
@@ -78,4 +80,3 @@ filter(filter: { | ||
} | null, includeOptgroup: boolean): DataArray; | ||
getSelectType(): string; | ||
} | ||
export {}; |
declare const hello = "hello world"; | ||
export default hello; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { PropType } from 'vue'; | ||
@@ -40,7 +41,8 @@ import SlimSelect, { Events } from '../slim-select'; | ||
intervalMove: { | ||
ref: () => NodeJS.Timeout; | ||
unref: () => NodeJS.Timeout; | ||
hasRef: () => boolean; | ||
refresh: () => NodeJS.Timeout; | ||
[Symbol.toPrimitive]: () => number; | ||
ref: () => NodeJS.Timeout; | ||
unref: () => NodeJS.Timeout; | ||
[Symbol.dispose]: () => void; | ||
} | null; | ||
@@ -50,2 +52,3 @@ disabled: boolean; | ||
showSearch: boolean; | ||
ariaLabel: string; | ||
searchPlaceholder: string; | ||
@@ -107,5 +110,6 @@ searchText: string; | ||
getOptionByID: (id: string) => Option | null; | ||
getSelectType: () => string; | ||
getFirstOption: () => Option | null; | ||
search: (search: string, searchFilter: (opt: Option, search: string) => boolean) => import("../slim-select/store").DataArray; | ||
filter: (filter: ((opt: Option) => boolean) | null, includeOptgroup: boolean) => import("../slim-select/store").DataArray; | ||
getSelectType: () => string; | ||
}; | ||
@@ -121,7 +125,8 @@ render: { | ||
intervalMove: { | ||
ref: () => NodeJS.Timeout; | ||
unref: () => NodeJS.Timeout; | ||
hasRef: () => boolean; | ||
refresh: () => NodeJS.Timeout; | ||
[Symbol.toPrimitive]: () => number; | ||
ref: () => NodeJS.Timeout; | ||
unref: () => NodeJS.Timeout; | ||
[Symbol.dispose]: () => void; | ||
} | null; | ||
@@ -131,2 +136,3 @@ disabled: boolean; | ||
showSearch: boolean; | ||
ariaLabel: string; | ||
searchPlaceholder: string; | ||
@@ -164,5 +170,6 @@ searchText: string; | ||
getOptionByID: (id: string) => Option | null; | ||
getSelectType: () => string; | ||
getFirstOption: () => Option | null; | ||
search: (search: string, searchFilter: (opt: Option, search: string) => boolean) => import("../slim-select/store").DataArray; | ||
filter: (filter: ((opt: Option) => boolean) | null, includeOptgroup: boolean) => import("../slim-select/store").DataArray; | ||
getSelectType: () => string; | ||
}; | ||
@@ -173,3 +180,3 @@ callbacks: { | ||
addable?: ((value: string) => string | false | import("../slim-select/store").OptionOptional | Promise<string | import("../slim-select/store").OptionOptional> | null | undefined) | undefined; | ||
setSelected: (value: string[], runAfterChange: boolean) => void; | ||
setSelected: (value: string | string[], runAfterChange: boolean) => void; | ||
addOption: (option: Option) => void; | ||
@@ -176,0 +183,0 @@ search: (search: string) => void; |
@@ -24,3 +24,3 @@ { | ||
}, | ||
"include": ["dist/", "src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue"] | ||
"include": ["dist/", "src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue", "src/react/src/index.tsx"] | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
909275
70
20026
2
48
+ Addedreact@^18.2.0
+ Addedreact-dom@^18.2.0
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedreact@18.3.1(transitive)
+ Addedreact-dom@18.3.1(transitive)
+ Addedscheduler@0.23.2(transitive)