UNPKG

multiple-select-vanilla

Version:

This lib allows you to select multiple elements with checkboxes

3 lines (2 loc) 46.6 kB
var lt=Object.defineProperty;var ot=(o,t,e)=>t in o?lt(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>ot(o,typeof t!="symbol"?t+"":t,e);var Z=typeof window<"u"&&window.multipleSelect!==void 0?window.multipleSelect:{locales:{}},nt={formatSelectAll(){return"[Select all]"},formatAllSelected(){return"All selected"},formatCountSelected(o,t){return`${o} of ${t} selected`},formatNoMatchesFound(){return"No matches found"},formatOkButton(){return"OK"},formatLazyLoading(){return"Loading..."}};Z.locales["en-US"]=nt;var P=Z.locales;var rt=50,at=4,d=()=>!1,ct=()=>!0,tt={name:"",placeholder:"",classes:"",classPrefix:"",data:void 0,locale:void 0,selectAll:!0,single:void 0,singleRadio:!1,multiple:!1,hideOptgroupCheckboxes:!1,multipleWidth:80,width:void 0,dropWidth:void 0,maxHeight:250,maxHeightUnit:"px",position:"bottom",displayValues:!1,displayTitle:!1,displayDelimiter:", ",minimumCountSelected:3,ellipsis:!1,isOpen:!1,keepOpen:!1,openOnHover:!1,container:null,filter:!1,filterGroup:!1,filterPlaceholder:"",filterAcceptOnEnter:!1,filterByDataLength:void 0,customFilter(o){let{text:t,label:e,search:i}=o;return(e||t||"").includes(i)},showClear:!1,autoAdjustDropHeight:!1,autoAdjustDropPosition:!1,autoAdjustDropWidthByTextSize:!1,adjustedHeightPadding:10,useSelectOptionLabel:!1,useSelectOptionLabelToHtml:!1,navigationHighlight:!0,infiniteScroll:!1,virtualScroll:!0,cssStyler:()=>null,textTemplate:o=>o.innerHTML.trim(),labelTemplate:o=>o.label,onBeforeOpen:d,onChange:d,onOpen:d,onClose:d,onCheckAll:d,onUncheckAll:d,onFocus:d,onBlur:d,onOptgroupClick:d,onBeforeClick:ct,onClick:d,onFilter:d,onFilterClear:d,onClear:d,onAfterCreate:d,onDestroy:d,onAfterDestroy:d,onDestroyed:d},ht=["init","getOptions","refreshOptions","getSelects","setSelects","enable","disable","open","close","check","uncheck","checkAll","uncheckAll","checkInvert","focus","blur","refresh","destroy"];Object.assign(tt,P["en-US"]);var pt={BLOCK_ROWS:rt,CLUSTER_BLOCKS:at,DEFAULTS:tt,METHODS:ht},u=pt;var T=class{constructor(t){r(this,"_distinctEvent");r(this,"_boundedEvents",[]);this._distinctEvent=t?.distinctEvent??!1}get boundedEvents(){return this._boundedEvents}dispose(){this.unbindAll(),this._boundedEvents=[]}bind(t,e,i,l,s=""){let n=Array.isArray(e)?e:[e];typeof t?.forEach=="function"?t.forEach(a=>this.bindElementEvents(a,n,i,l,s)):this.bindElementEvents(t,n,i,l,s)}hasBinding(t,e){return this._boundedEvents.some(i=>i.element===t&&(!e||i.eventName===e))}unbind(t,e,i){if(t){let l=Array.isArray(t)?t:[t],s=Array.isArray(e)?e:[e||""];for(let n of l){i||(i=this._boundedEvents.find(a=>{if(a.element===n&&(!e||a.eventName===e))return a.listener}));for(let a of s)n?.removeEventListener?.(a,i)}}}unbindAll(t){if(t){let e=Array.isArray(t)?t:[t];for(let i=this._boundedEvents.length-1;i>=0;--i){let l=this._boundedEvents[i];if(e.some(s=>s===l.groupName)){let{element:s,eventName:n,listener:a}=l;this.unbind(s,n,a),this._boundedEvents.splice(i,1)}}}else for(;this._boundedEvents.length>0;){let{element:e,eventName:i,listener:l}=this._boundedEvents.pop();this.unbind(e,i,l)}}bindElementEvents(t,e,i,l,s=""){for(let n of e)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(t,n))&&(t.addEventListener(n,i,l),this._boundedEvents.push({element:t,eventName:n,listener:i,groupName:s}))}};function G(o,t,e=!1){let i=Object.keys(o),l=Object.keys(t);if(e&&i.length!==l.length)return!1;for(let s of i)if(l.includes(s)&&o[s]!==t[s])return!1;return!0}function O(o){return typeof o!="object"||o===null?o:Array.isArray(o)?o.map(O):typeof o=="function"?o:Object.fromEntries(Object.entries(o).map(([t,e])=>[t,O(e)]))}function y(o){return o!=null&&o!==""}function z(o,t){return typeof o=="object"?Object.fromEntries(t?Object.entries(o).filter(([e,i])=>!y(i)&&!t.includes(e)||y(i)):Object.entries(o).filter(([e,i])=>y(i))):o}function q(o){let t=0;return o.forEach((e,i)=>{e.type==="optgroup"?(e._key=`group_${i}`,e.visible=typeof e.visible>"u"?!0:e.visible,e.children.forEach((l,s)=>{l&&(l.visible=typeof l?.visible>"u"?!0:l.visible,l.divider||(l._key=`option_${i}_${s}`,t+=1))})):(e.visible=typeof e.visible>"u"?!0:e.visible,e.divider||(e._key=`option_${i}`,t+=1))}),t}function S(o,t,e){if(Array.isArray(o))for(let i of o){if(i[t]===e||i[t]===`${+i[t]}`&&+i[t]===e)return i;if(i.type==="optgroup"){for(let l of i.children)if(l&&(l[t]===e||l[t]===`${+l[t]}`&&+l[t]===e))return l}}}function F(o){return o.replace(/(\b)(on[a-z]+)(\s*)=([^>]*)|javascript:([^>]*)[^>]*|(<\s*)(\/*)script([<>]*).*(<\s*)(\/*)script(>*)|(&lt;|&#60;)(\/*)(script|script defer)(.*)(&#62;|&gt;|&gt;">)/gi,"")}function k(o){return Object.keys(o).forEach(t=>y(o[t])?"":delete o[t]),o}function g(o,t){if(typeof o!="string")return o;if(typeof t=="function")return t(o);if(typeof o.normalize=="function")return o.normalize("NFD").replace(/[\u0300-\u036F]/g,"");throw new Error("[Multiple-Select-Vanilla] `normalize()` function is not defined, you can optionally provide a custom parser via the `diacriticParser` option.")}function x(o){let{innerHeight:t=0,innerWidth:e=0}=window,{top:i,left:l}=st(),{top:s=0,left:n=0}=C(o)||{};return{top:s-i,bottom:t-(s-i),left:n-l,right:e-(n-l)}}function M(o=""){return o.split(" ").filter(t=>t)}function p(o,t,e){let i=document.createElement(o);return t&&Object.keys(t).forEach(l=>{let s=t[l];typeof s=="object"?Object.assign(i[l],s):i[l]=t[l]}),e?.appendChild(i),i}function K(o,t,e){let i=o.props?.innerHTML?it(o.props,"innerHTML"):o.props,l=p(o.tagName,z(i,["className","title","style"]),t),s=e;if(s||(s=l),o.props.innerHTML&&(l.innerHTML=o.props.innerHTML),o.attrs)for(let n of Object.keys(o.attrs))l.setAttribute(n,o.attrs[n]);if(o.children)for(let n of o.children)K(n,l,s);return t?.appendChild(l),l}function L(o){return o.hasOwnProperty("tagName")?K(o):document.createElement("li")}function v(o){for(;o?.firstChild;)o.lastChild&&o.removeChild(o.lastChild);return o}function C(o){if(o){let{top:t,left:e,bottom:i,right:l}=o.getBoundingClientRect();return{top:t+window.pageYOffset,left:e+window.pageXOffset,bottom:i,right:l}}}function D(o,t,e){if(!o)return 0;let i=Number.parseFloat(o.style[e]);if(!i||Number.isNaN(i)){let l=e==="height"?"Height":"Width";switch(t){case"outer":i=o[`offset${l}`];break;case"scroll":i=o[`scroll${l}`];break;case"inner":default:i=o[`client${l}`];break}i=o.getBoundingClientRect()[e]}if(!i||Number.isNaN(i)){let l=o.style.display,s=o.style.position;o.style.display="block",o.style.position="absolute",i=H(o,e),o.style.display=l,o.style.position=s}return i||0}function H(o,t){let e=window.getComputedStyle(o)[t],i=Number.parseFloat(e);return Number.isNaN(i)&&(i=0),i}function B(o,t){let e=null,i=o?.parentElement;for(;i;){let[l,s,n,a]=t.match(/^([a-z]*)([#.]{1})([a-z-]+)$/i)||[];if(n&&a)for(let c of a.replace(n,"").split(" "))i.classList.contains(c)&&(s?i?.tagName.toLowerCase()===s&&(e=i):e=i);i=i.parentElement}return e}function et(o){if(y(o)){let t=document.createElement("textarea");return t.innerHTML=o.toString().replace(/&#(\d+);/g,(e,i)=>String.fromCharCode(i)),t.value}return""}function U(o,t){o.parentNode?.insertBefore(t,o.nextSibling)}function it(o,t){let{[t]:e,...i}=o;return i}function j(o,t){o?.style&&(o.style.display=o.style.display==="none"&&t!==!1||t===!0?"block":"none")}function st(){return{left:window.pageXOffset||document.documentElement.scrollLeft||0,top:window.pageYOffset||document.documentElement.scrollTop||0}}var w=class{constructor(t){r(this,"clusterRows");r(this,"cache");r(this,"scrollEl");r(this,"blockHeight");r(this,"clusterHeight");r(this,"contentEl");r(this,"parentEl");r(this,"itemHeight");r(this,"lastCluster");r(this,"scrollTop");r(this,"dataStart");r(this,"dataEnd");r(this,"rows");r(this,"destroy");r(this,"callback");r(this,"sanitizer");this.rows=t.rows,this.scrollEl=t.scrollEl,this.contentEl=t.contentEl,this.parentEl=t.contentEl?.parentElement,this.callback=t.callback,this.cache={},this.scrollTop=this.scrollEl.scrollTop,this.initDOM(this.rows),this.scrollEl.scrollTop=this.scrollTop,this.lastCluster=0;let e=()=>{this.lastCluster!==(this.lastCluster=this.getNum())&&(this.initDOM(this.rows),this.callback())};this.scrollEl.addEventListener("scroll",e,!1),this.destroy=()=>{this.scrollEl.removeEventListener("scroll",e,!1),v(this.contentEl)}}reset(t){this.lastCluster=0,this.cache={},v(this.contentEl),this.initDOM(t)}initDOM(t){if(typeof this.clusterHeight>"u"){this.cache.scrollTop=this.scrollEl.scrollTop;let n=L(t[0]);this.contentEl.appendChild(n),this.contentEl.appendChild(n),this.contentEl.appendChild(n),this.cache.data=[t[0]],this.getRowsHeight()}let e=this.initData(t,this.getNum()),i=this.checkChanges("data",e.rows),l=this.checkChanges("top",e.topOffset),s=this.checkChanges("bottom",e.bottomOffset);v(this.contentEl),i&&l?(e.topOffset&&this.contentEl.appendChild(this.getExtra("top",e.topOffset)),e.rows.forEach(n=>this.contentEl.appendChild(L(n))),e.bottomOffset&&this.contentEl.appendChild(this.getExtra("bottom",e.bottomOffset))):s&&this.contentEl.lastChild&&(this.contentEl.lastChild.style.height=`${e.bottomOffset}px`)}getRowsHeight(){if(typeof this.itemHeight>"u"){let t=this.parentEl?.style.display||"";this.parentEl&&(t===""||t==="none")&&(this.parentEl.style.display="block");let e=this.contentEl.children,i=e[Math.floor(e.length/2)];this.itemHeight=i.offsetHeight,this.parentEl&&(this.parentEl.style.display=t)}this.blockHeight=this.itemHeight*u.BLOCK_ROWS,this.clusterRows=u.BLOCK_ROWS*u.CLUSTER_BLOCKS,this.clusterHeight=this.blockHeight*u.CLUSTER_BLOCKS}getNum(){this.scrollTop=this.scrollEl.scrollTop;let t=(this.clusterHeight||0)-(this.blockHeight||0);return t&&Math.floor(this.scrollTop/t)||0}initData(t,e){if(t.length<u.BLOCK_ROWS)return{topOffset:0,bottomOffset:0,rowsAbove:0,rows:t};let i=Math.max((this.clusterRows-u.BLOCK_ROWS)*e,0),l=i+this.clusterRows,s=Math.max(i*this.itemHeight,0),n=Math.max((t.length-l)*this.itemHeight,0),a=[],c=i;s<1&&c++;for(let h=i;h<l;h++)t[h]&&a.push(t[h]);return this.dataStart=i,this.dataEnd=l,{topOffset:s,bottomOffset:n,rowsAbove:c,rows:a}}checkChanges(t,e){let i=e!==this.cache[t];return this.cache[t]=e,i}getExtra(t,e){let i=p("li",{className:`virtual-scroll-${t}`});return e&&(i.style.height=`${e}px`),i}};var A=".ms-select-all, ul li[data-key]",dt=".ms-select-all.highlighted, ul li[data-key].highlighted",_=class{constructor(t,e){this.elm=t;r(this,"_bindEventService");r(this,"isAllSelected",!1);r(this,"isPartiallyAllSelected",!1);r(this,"fromHtml",!1);r(this,"choiceElm");r(this,"selectClearElm");r(this,"closeElm");r(this,"clearSearchIconElm");r(this,"filterText","");r(this,"updateData",[]);r(this,"data",[]);r(this,"dataTotal");r(this,"dropElm");r(this,"okButtonElm");r(this,"filterParentElm");r(this,"lastFocusedItemKey","");r(this,"lastMouseOverPosition","");r(this,"ulElm");r(this,"parentElm");r(this,"labelElm");r(this,"selectAllParentElm");r(this,"selectAllElm");r(this,"searchInputElm");r(this,"selectGroupElms");r(this,"selectCheckboxElms");r(this,"noResultsElm");r(this,"options");r(this,"selectAllName","");r(this,"selectGroupName","");r(this,"selectItemName","");r(this,"scrolledByMouse",!1);r(this,"openDelayTimer");r(this,"updateDataStart");r(this,"updateDataEnd");r(this,"virtualScroll");r(this,"_currentHighlightIndex",-1);r(this,"_currentSelectedElm");r(this,"_isLazyLoaded",!1);r(this,"isMoveUpRecalcRequired",!1);r(this,"locales",{});this.options=Object.assign({},u.DEFAULTS,this.elm.dataset,e),this._bindEventService=new T({distinctEvent:!0})}get isRenderAsHtml(){return this.options.renderOptionLabelAsHtml||this.options.useSelectOptionLabelToHtml}init(){this.initLocale(),this.initContainer(),this.initData(),this.initSelected(!0),this.initFilter(),this.initDrop(),this.initView(),this.options.onAfterCreate()}destroy(t=!0){this.elm&&this.parentElm&&(this.options.onDestroy({hardDestroy:t}),t&&this.options.onHardDestroy(),this.elm.parentElement&&this.parentElm.parentElement&&this.elm.parentElement.insertBefore(this.elm,this.parentElm.parentElement.firstChild),this.elm.classList.remove("ms-offscreen"),this._bindEventService.unbindAll(),this.virtualScroll?.destroy(),this.dropElm?.remove(),this.dropElm=void 0,this.parentElm.parentNode?.removeChild(this.parentElm),this.fromHtml&&(delete this.options.data,this.fromHtml=!1),this.options.onAfterDestroy({hardDestroy:t}),t&&(this.options.onAfterHardDestroy?.(),Object.keys(this.options).forEach(e=>delete this[e])))}initLocale(){if(this.options.locale){if(typeof this.options.locale=="object"){Object.assign(this.options,this.options.locale);return}let t=window.multipleSelect.locales,e=this.options.locale.split(/-|_/);if(e[0]=e[0].toLowerCase(),e[1]&&(e[1]=e[1].toUpperCase()),t[this.options.locale])Object.assign(this.options,t[this.options.locale]);else if(t[e.join("-")])Object.assign(this.options,t[e.join("-")]);else if(t[e[0]])Object.assign(this.options,t[e[0]]);else throw new Error(`[multiple-select-vanilla] invalid locales "${this.options.locale}", make sure to import it before using it`)}}initContainer(){let t=this.elm.getAttribute("name")||this.options.name||"";this.options.classes&&this.elm.classList.add(this.options.classes),this.options.classPrefix&&(this.elm.classList.add(this.options.classPrefix),this.options.size&&this.elm.classList.add(`${this.options.classPrefix}-${this.options.size}`)),this.elm.style.display="none",this.labelElm=this.elm.closest("label"),!this.labelElm&&this.elm.id&&(this.labelElm=p("label",{htmlFor:this.elm.id})),this.labelElm?.querySelector("input")&&(this.labelElm=null),this.options.single===void 0&&(this.options.single=!this.elm.multiple),this.parentElm=p("div",{className:M(`ms-parent ${this.elm.className||""} ${this.options.classes}`).join(" "),dataset:{test:"sel"}}),this.options.darkMode&&this.parentElm.classList.add("ms-dark-mode");let e=this.elm.getAttribute("title")||"";e&&(this.parentElm.title=e),this.options.placeholder=this.options.placeholder||this.elm.getAttribute("placeholder")||"",this.choiceElm=p("button",{className:"ms-choice",type:"button"},this.parentElm),this.options.labelId&&(this.choiceElm.id=this.options.labelId,this.choiceElm.setAttribute("aria-labelledby",this.options.labelId)),this.choiceElm.appendChild(p("span",{className:"ms-placeholder",textContent:this.options.placeholder})),this.options.showClear&&(this.selectClearElm=p("div",{className:"ms-icon ms-icon-close"}),this.selectClearElm.style.display="none",this.choiceElm.appendChild(this.selectClearElm)),this.choiceElm.appendChild(p("div",{className:"ms-icon ms-icon-caret"})),this.dropElm=p("div",{className:`ms-drop ${this.options.position}`,ariaExpanded:"false"},this.parentElm),this.options.darkMode&&this.dropElm.classList.add("ms-dark-mode"),t&&(this.dropElm.dataset.name=t);let i=this.elm.getAttribute("data-test")||this.options.dataTest;i&&(this.parentElm.dataset.test=i,this.dropElm.dataset.test=i),this.closeElm=this.choiceElm.querySelector(".ms-icon-close");let l=["minWidth","maxWidth","width","dropWidth"];for(let s of l)if(this.options[s]){let n=s==="dropWidth"?"width":s;this.dropElm.style[n]=typeof this.options[s]=="string"?this.options[s]:`${this.options[s]}px`}U(this.elm,this.parentElm),this.elm.disabled&&(this.choiceElm.classList.add("disabled"),this.choiceElm.disabled=!0),this.selectAllName=`selectAll${t}`,this.selectGroupName=`selectGroup${t}`,this.selectItemName=`selectItem${t}`,this.options.keepOpen||(this._bindEventService.unbindAll("body-click"),this._bindEventService.bind(document.body,"click",(s=>{this.getEventTarget(s)===this.choiceElm||B(this.getEventTarget(s),".ms-choice")===this.choiceElm||(this.getEventTarget(s)===this.dropElm||B(this.getEventTarget(s),".ms-drop")!==this.dropElm&&this.getEventTarget(s)!==this.elm)&&this.options.isOpen&&this.close("body.click")}),void 0,"body-click"))}initData(){let t=[];if(this.options.data){if(Array.isArray(this.options.data))this.data=this.options.data.map(e=>typeof e=="string"||typeof e=="number"?{text:e,value:e}:e);else if(typeof this.options.data=="object"){for(let[e,i]of Object.entries(this.options.data))t.push({value:e,text:`${i}`});this.data=t}}else this.elm.childNodes.forEach(e=>{let i=this.initRow(e);i&&t.push(i)}),this.options.data=t,this.data=t,this.fromHtml=!0;this.data&&this.options.preFilter&&(this.data=this.data.filter(this.options.preFilter)),this.data&&this.options.preSort&&(this.data=this.data.sort(this.options.preSort)),this.dataTotal=q(this.data||[])}initRow(t,e){let i={};return t.tagName?.toLowerCase()==="option"?(i.type="option",i.text=this.options.textTemplate(t),i.value=t.value,i.visible=!0,i.selected=!!t.selected,i.disabled=e||t.disabled,i.classes=t.getAttribute("class")||"",i.title=t.getAttribute("title")||"",t.dataset.value&&(i._value=t.dataset.value),Object.keys(t.dataset).length&&(i._data=t.dataset,i._data.divider&&(i.divider=i._data.divider)),i):t.tagName?.toLowerCase()==="optgroup"?(i.type="optgroup",i.label=this.options.labelTemplate(t),i.visible=!0,i.selected=!!t.selected,i.disabled=t.disabled,i.children=[],Object.keys(t.dataset).length&&(i._data=t.dataset),t.childNodes.forEach(l=>{i.children.push(this.initRow(l,i.disabled))}),i):null}initDrop(){this.initList(!this.options.lazyData),this.update(!0),this.options.isOpen&&this.open(0),this.options.openOnHover&&this.parentElm&&(this._bindEventService.bind(this.parentElm,"mouseover",()=>this.open(null)),this._bindEventService.bind(this.parentElm,"mouseout",()=>this.close("hover.mouseout")))}initFilter(){if(this.filterText="",this.options.filter||!this.options.filterByDataLength)return;let t=0;for(let e of this.data||[])e.type==="optgroup"?t+=e.children.length:t+=1;this.options.filter=t>this.options.filterByDataLength}initList(t=!0){if(t&&(this.options.filter&&(this.filterParentElm=p("div",{className:"ms-search"},this.dropElm),this.filterParentElm.appendChild(p("input",{autocomplete:"off",autocapitalize:"off",spellcheck:!1,type:"text",placeholder:this.options.filterPlaceholder||"\u{1F50E}\uFE0E"})),this.options.showSearchClear&&this.filterParentElm.appendChild(p("span",{className:"ms-icon ms-icon-close"}))),this.options.selectAll&&!this.options.single)){let e=this.elm.getAttribute("name")||this.options.name||"";this.selectAllParentElm=p("div",{className:"ms-select-all",dataset:{key:"select_all"}});let i=document.createElement("label"),s=`ms-icon ${this.isAllSelected?"ms-icon-check":this.isPartiallyAllSelected?"ms-icon-minus":"ms-icon-uncheck"}`,n=p("div",{className:"icon-checkbox-container"},i);p("input",{type:"checkbox",ariaChecked:String(this.isAllSelected),checked:this.isAllSelected,dataset:{name:`selectAll${e}`}},n),p("div",{className:s},n),i.appendChild(p("span",{textContent:this.formatSelectAll()})),this.selectAllParentElm.appendChild(i),this.dropElm?.appendChild(this.selectAllParentElm)}this.ulElm=p("ul",{className:"ms-list",role:"listbox",ariaExpanded:"false",ariaMultiSelectable:String(!this.options.single)}),this.dropElm?.appendChild(this.ulElm),t&&this.options.showOkButton&&!this.options.single&&(this.okButtonElm=p("button",{className:"ms-ok-button",type:"button",textContent:this.formatOkButton()},this.dropElm)),this.initListItems()}initListItems(){let t=0,e=this.getListRows();if(this.options.selectAll&&!this.options.single&&(t=-1),e.length>u.BLOCK_ROWS*u.CLUSTER_BLOCKS){let i=this.dropElm&&this.dropElm?.style.display!=="none";!i&&this.dropElm&&(this.dropElm.style.left="-10000",this.dropElm.style.display="block",this.dropElm.ariaExpanded="true");let l=()=>{if(this.virtualScroll){this._currentHighlightIndex=0,this.updateDataStart=this.virtualScroll.dataStart+t,this.updateDataEnd=this.virtualScroll.dataEnd+t,this.updateDataStart<0&&(this.updateDataStart=0,this._currentHighlightIndex=0);let s=this.getDataLength();this.updateDataEnd>s&&(this.updateDataEnd=s),this.ulElm&&(this.isMoveUpRecalcRequired?this.recalculateArrowMove("up"):this.virtualScroll.dataStart>this.updateDataStart&&this.recalculateArrowMove("down"))}};this.ulElm&&(this.virtualScroll?this.virtualScroll.reset(e):this.virtualScroll=new w({rows:e,scrollEl:this.ulElm,contentEl:this.ulElm,sanitizer:this.options.sanitizer,callback:()=>{l(),this.events()}})),l(),!i&&this.dropElm&&(this.dropElm.style.left="0",this.dropElm.style.display="none",this.dropElm.ariaExpanded="false")}else this.ulElm&&(v(this.ulElm),e.forEach(i=>this.ulElm.appendChild(L(i)))),this.updateDataStart=0,this.updateDataEnd=this.updateData.length;return this.events(),e}getEventTarget(t){try{return t.composedPath?.()[0]||t.path?.[0]||t.target}catch{return t.target}}getListRows(){let t=[];return this.updateData=[],this.data?.forEach(e=>t.push(...this.initListItem(e))),this.options.infiniteScroll&&t.push({tagName:"li",props:{className:"ms-infinite-option",role:"option"}}),t.push({tagName:"li",props:{className:"ms-no-results",textContent:this.formatNoMatchesFound()}}),t}initListItem(t,e=0){let i=t?.title||"",l=this.options.multiple?"multiple":"",s=this.options.single?"radio":"checkbox",n=!!t?.selected,a=this.options.single&&!this.options.singleRadio,c="";if(!t?.visible)return[];if(this.updateData.push(t),a&&(c="hide-radio "),t.selected&&(c+="selected "),t.type==="optgroup"){let W=[],N;if(this.options.hideOptgroupCheckboxes||this.options.single)N={tagName:"span",props:{dataset:{name:this.selectGroupName,key:t._key}}};else{let R={tagName:"input",props:{type:"checkbox",dataset:{name:this.selectGroupName,key:t._key},checked:n,disabled:t.disabled}};a?N=R:N={tagName:"div",props:{className:`icon-checkbox-container${s==="radio"?" radio":""}`},children:[R,{tagName:"div",props:{className:`ms-icon ${n?s==="radio"?"ms-icon-radio":"ms-icon-check":"ms-icon-uncheck"}`}}]}}!c.includes("hide-radio")&&(this.options.hideOptgroupCheckboxes||this.options.single)&&(c+="hide-radio ");let Y={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(Y.props,t.label);let J={tagName:"li",props:{className:M(`group${this.options.single||t.disabled?" disabled":""} ${c}`).join(" "),role:"option",ariaSelected:String(n),dataset:{key:t._key}},children:[{tagName:"label",props:{className:M(`optgroup${this.options.single||t.disabled?" disabled":""}`).join(" ")},children:[N,Y]}]},Q=this.options.cssStyler(t);return Q&&(J.props.style=Q),W.push(J),t.children.forEach(R=>W.push(...this.initListItem(R,1))),W}if(c+=t.classes||"",e&&this.options.single&&(c+=`option-level-${e} `),t.divider)return[{tagName:"li",props:{className:"option-divider"}}];let h=l||c?(l+c).trim():"";t.disabled&&(h+=" disabled");let f=`${t.disabled?"disabled":""}`,m={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(m.props,t.text);let b={tagName:"input",props:{type:s,value:encodeURI(t.value),dataset:{key:t._key,name:this.selectItemName},checked:n,disabled:!!t.disabled}};t.selected&&(b.attrs={checked:"checked"});let $={tagName:"div",props:{className:`icon-checkbox-container${s==="radio"?" radio":""}`},children:[b,{tagName:"div",props:{className:`ms-icon ${b.props.checked?s==="radio"?"ms-icon-radio":"ms-icon-check":"ms-icon-uncheck"}`}}]},E={tagName:"li",props:{role:"option",title:i,ariaSelected:String(n),dataset:{key:t._key}},children:[{tagName:"label",props:{className:f},children:[a?b:$,m]}]};h&&(E.props.className=h);let X=this.options.cssStyler(t);return X&&(E.props.style=X),[E]}initSelected(t=!1){let e=0;for(let i of this.data||[])if(i.type==="optgroup"){let l=i.children.filter(s=>s?.selected&&!s.disabled&&s.visible).length;i.children.length&&(i.selected=!this.options.single&&l&&l===i.children.filter(s=>s&&!s.disabled&&s.visible&&!s.divider).length),e+=l}else e+=i.selected&&!i.disabled&&i.visible?1:0;if(this.isAllSelected=this.data?.filter(i=>i.selected&&!i.disabled&&i.visible).length===this.data?.filter(i=>!i.disabled&&i.visible&&!i.divider).length,this.isPartiallyAllSelected=!this.isAllSelected&&e>0,!t){let i="";this.isAllSelected?i="onCheckAll":e===0&&(i="onUncheckAll"),i&&(this.options[i](),this.handleOnChange(i))}}initView(){let t;window.getComputedStyle?(t=window.getComputedStyle(this.elm).width,t==="auto"&&(t=D(this.dropElm,"outer","width")+20)):t=D(this.elm,"outer","width")+20,this.parentElm.style.width=`${this.options.width||t}px`,this.elm.classList.add("ms-offscreen")}events(){this._bindEventService.unbindAll(["ok-button","search-input","select-all-checkbox","input-checkbox-list","group-checkbox-list","hover-highlight","arrow-highlight","option-list-scroll"]),this.clearSearchIconElm=this.filterParentElm?.querySelector(".ms-icon-close"),this.searchInputElm=this.dropElm?.querySelector(".ms-search input"),this.selectAllElm=this.dropElm?.querySelector(`input[data-name="${this.selectAllName}"]`),this.selectGroupElms=this.dropElm?.querySelectorAll(`input[data-name="${this.selectGroupName}"],span[data-name="${this.selectGroupName}"]`),this.selectCheckboxElms=this.dropElm?.querySelectorAll(`input[data-name="${this.selectItemName}"]:enabled`),this.noResultsElm=this.dropElm?.querySelector(".ms-no-results");let t=e=>{e.preventDefault(),!this.getEventTarget(e).classList.contains("ms-icon-close")&&(this.options.isOpen?this.close("toggle.close"):this.open())};this.labelElm&&this._bindEventService.bind(this.labelElm,"click",(e=>{this.getEventTarget(e).nodeName.toLowerCase()==="label"&&(t(e),(!this.options.filter||!this.options.isOpen)&&this.focus(),e.stopPropagation())})),this._bindEventService.bind(this.choiceElm,"click",t),this.options.onFocus&&this._bindEventService.bind(this.choiceElm,"focus",this.options.onFocus),this.options.onBlur&&this._bindEventService.bind(this.choiceElm,"blur",this.options.onBlur),this._bindEventService.bind(this.parentElm,"keydown",(e=>{e.code==="Escape"&&this.handleEscapeKey()})),this.closeElm&&this._bindEventService.bind(this.closeElm,"click",(e=>{e.preventDefault(),this._checkAll(!1,!0),this.initSelected(!1),this.updateSelected(),this.update(),this.options.onClear()})),this.clearSearchIconElm&&this._bindEventService.bind(this.clearSearchIconElm,"click",(e=>{e.preventDefault(),this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this._currentHighlightIndex=-1,this.moveHighlightDown(),this.filter(),this.options.onFilterClear()})),this.searchInputElm&&(this._bindEventService.bind(this.searchInputElm,"keydown",(e=>{e.code==="Tab"&&e.shiftKey&&this.close("key.shift+tab")}),void 0,"search-input"),this._bindEventService.bind(this.searchInputElm,"keyup",(e=>{if(this.options.filterAcceptOnEnter&&["Enter","Space"].includes(e.code)&&this.searchInputElm?.value){if(this.options.single){let i=[];this.selectCheckboxElms?.forEach(l=>{l.closest("li")?.style.display!=="none"&&i.push(l)}),i.length&&i[0].hasAttribute("data-name")&&this.setSelects([i[0].value])}else this.selectAllElm?.click();this.close(`key.${e.code.toLowerCase()}`),this.focus();return}this.filter()}),void 0,"search-input")),this.selectAllElm&&this._bindEventService.bind(this.selectAllElm,"click",(e=>this._checkAll(e.currentTarget?.checked)),void 0,"select-all-checkbox"),this.okButtonElm&&this._bindEventService.bind(this.okButtonElm,"click",(e=>{t(e),e.stopPropagation()}),void 0,"ok-button"),this.selectGroupElms&&this._bindEventService.bind(this.selectGroupElms,"click",(e=>{let i=e.currentTarget,l=i.checked,s=S(this.data,"_key",i.dataset.key);this._checkGroup(s,l),this.options.onOptgroupClick(k({label:s.label,selected:!!s.selected,data:s._data,children:s.children.filter(n=>n).map(n=>k({label:n.text,value:n.value,selected:n.selected,disabled:n.disabled,data:n._data}))})),this.handleOnChange("onOptgroupClick",{label:s.label,selected:!!s.selected,type:s.type})}),void 0,"group-checkbox-list"),this.selectCheckboxElms&&this._bindEventService.bind(this.selectCheckboxElms,"click",(e=>{let i=e.currentTarget,l=i.checked,s=S(this.data,"_key",i.dataset.key),n=()=>{this.options.single&&this.options.isOpen&&!this.options.keepOpen&&this.close("selection")};if(this.options.onBeforeClick(s)===!1){n();return}this._check(s,l),this.options.onClick(k({label:s.text,value:s.value,selected:s.selected,data:s._data})),this.handleOnChange("onClick",{label:s.text,value:s.value,selected:s.selected,type:s.type}),n()}),void 0,"input-checkbox-list"),this.lastFocusedItemKey&&this.dropElm&&this.dropElm.querySelector(`li[data-key=${this.lastFocusedItemKey}]`)?.focus(),this.options.navigationHighlight&&this.dropElm&&(this._bindEventService.bind(this.dropElm,"mouseover",(e=>{let i=this.getEventTarget(e).closest(".ms-select-all")||this.getEventTarget(e).closest("li");if(this.dropElm?.contains(i)&&this.lastMouseOverPosition!==`${e.clientX}:${e.clientY}`){let l=this.dropElm?.querySelectorAll(A)||[],s=Array.from(l).findIndex(n=>n.dataset.key===i.dataset.key);this._currentHighlightIndex!==s&&!i.classList.contains("disabled")&&(this._currentSelectedElm=i,this._currentHighlightIndex=s,this.changeCurrentOptionHighlight(i))}this.lastMouseOverPosition=`${e.clientX}:${e.clientY}`}),void 0,"hover-highlight"),this._bindEventService.bind(this.dropElm,"keydown",(e=>{switch(e.key){case"ArrowUp":e.preventDefault(),this.moveHighlightUp();break;case"ArrowDown":e.preventDefault(),this.moveHighlightDown();break;case"Escape":this.handleEscapeKey();break;case"Enter":case" ":{if(document.activeElement!==this.okButtonElm){let i=this.getEventTarget(e).closest(".ms-select-all")||this.getEventTarget(e).closest("li");if(e.key===" "&&this.options.filter||this.options.filterAcceptOnEnter&&!i)return;e.preventDefault(),this._currentSelectedElm?.querySelector("input")?.click(),this.options.single&&(this.choiceElm.focus(),this.lastFocusedItemKey=this.choiceElm?.dataset.key||"")}break}case"Tab":{e.preventDefault();let i=!this.options.single&&this.options.showOkButton;i&&e.shiftKey&&document.activeElement===this.okButtonElm?(this.focusSelectAllOrList(),this.highlightCurrentOption(),this.filterParentElm?.querySelector("input")?.focus()):i&&!e.shiftKey&&document.activeElement!==this.okButtonElm?(this.changeCurrentOptionHighlight(),this.okButtonElm?.focus()):(this.options.onBlur(e),this.options.isOpen&&this.options.closeOnTab&&this.close("blur"));break}}}),void 0,"arrow-highlight")),this.ulElm&&this.options.infiniteScroll&&this._bindEventService.bind(this.ulElm,"scroll",this.infiniteScrollHandler.bind(this),void 0,"option-list-scroll")}handleOnChange(t,e){this.options.onChange({eventName:t,item:e,selection:{labels:this.getSelects("text"),values:this.getSelects("value")}})}handleEscapeKey(){this.options.keepOpen||(this.close("key.escape"),this.choiceElm.focus())}infiniteScrollHandler(t,e,i){let l=!1;t&&this.getEventTarget(t)&&this.ulElm&&this.scrolledByMouse?this.getEventTarget(t).scrollTop+this.getEventTarget(t).clientHeight===this.ulElm.scrollHeight&&(l=!0):e!==void 0&&e+1===i&&(l=!0),l&&this.ulElm&&(this.virtualScroll?this.initListItems():this.ulElm.scrollTop=0,this._currentHighlightIndex=0,this.highlightCurrentOption())}open(t=0){return new Promise(e=>{t!==null&&t>=0?(window.clearTimeout(this.openDelayTimer),this.openDelayTimer=window.setTimeout(()=>{this.openDrop(),e()},t)):(this.openDrop(),e())})}openDrop(){if(!this.dropElm||this.choiceElm?.classList.contains("disabled"))return;this.options.onBeforeOpen();let t=!1;if(this.options.lazyData&&!this._isLazyLoaded&&(t=!0,this.dropElm?.querySelector("ul.ms-list")?.remove(),this.options.lazyData().then(e=>{this.options.data=e,this._isLazyLoaded=!0,this.dropElm?.querySelector(".ms-loading")?.remove(),this.initData(),this.initList(!0),this.update(),this.adjustDropSizeAndPosition()})),this.options.isOpen=!0,this.parentElm.classList.add("ms-parent-open"),this.choiceElm?.querySelector("div.ms-icon-caret")?.classList.add("open"),this.dropElm.style.display="block",this.dropElm.ariaExpanded="true",this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="inline-flex"),this.noResultsElm&&(this.noResultsElm.style.display="none"),!this.getDataLength())if(this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="none"),t&&!this._isLazyLoaded&&!this.dropElm.querySelector(".ms-loading")){let e=p("div",{className:"ms-loading"});e.appendChild(p("div",{className:"ms-icon ms-icon-loading ms-spin"})),e.appendChild(p("span",{textContent:this.formatLazyLoading()})),this.dropElm.appendChild(e)}else this.noResultsElm&&(this.noResultsElm.style.display="block");this.adjustDropSizeAndPosition(),(!t||this._isLazyLoaded)&&(this.getDataLength()&&this.options.filter?(this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter(!0)):this.focusSelectAllOrList()),this._currentHighlightIndex<0?this.moveHighlightDown():this.highlightCurrentOption(),this.options.onOpen()}adjustDropSizeAndPosition(){if(this.dropElm){if(this.options.container){let l;this.options.container instanceof Node?l=this.options.container:typeof this.options.container=="string"&&(l=this.options.container==="body"?document.body:document.querySelector(this.options.container)),l.appendChild(this.dropElm);let{top:s=0,left:n=0}=C(this.parentElm)||{};this.dropElm.style.top=`${s+this.parentElm.offsetHeight}px`,this.dropElm.style.left=`${n}px`,this.dropElm.style.width=`${this.parentElm.offsetWidth}px`,this.dropElm.style.minWidth="auto"}let t=this.options.minHeight,e=this.options.maxHeight;this.options.maxHeightUnit==="row"&&(e=D(this.dropElm.querySelector("ul>li"),"outer","height")*this.options.maxHeight),this.ulElm??=this.dropElm.querySelector("ul"),this.ulElm&&(t&&(!this.options.lazyData||this._isLazyLoaded)&&(this.ulElm.style.minHeight=`${t}px`),this.ulElm.style.maxHeight=`${e}px`),this.dropElm.querySelectorAll(".multiple").forEach(l=>{l.style.width=`${this.options.multipleWidth}px`}),this.options.autoAdjustDropWidthByTextSize&&this.adjustDropWidthByText();let i=this.options.position;if(this.options.autoAdjustDropHeight){if(this.options.autoAdjustDropPosition){let{bottom:l,top:s}=x(this.dropElm),n=this.dropElm.getBoundingClientRect().height;i=l<n&&s>l?"top":"bottom"}this.adjustDropHeight(i)}this.options.autoAdjustDropPosition&&this.adjustDropPosition(!0)}}focusSelectAllOrList(){this.selectAllElm?this.selectAllElm.focus():this.ulElm&&(this.ulElm.tabIndex=0,this.ulElm.focus())}highlightCurrentOption(){let t=this.dropElm?.querySelectorAll(A)||[];if(this._currentHighlightIndex<=t.length){let e=t[this._currentHighlightIndex];e&&(this.lastFocusedItemKey=e.dataset.key||"",this._currentSelectedElm=e,this.scrolledByMouse=!1,e.scrollIntoView({block:"nearest"}),this.changeCurrentOptionHighlight(e),window.setTimeout(()=>this.scrolledByMouse=!0,10))}}changeCurrentOptionHighlight(t){t?.classList.add("highlighted"),(this.dropElm?.querySelectorAll(dt)||[]).forEach(i=>{i!==t&&i.classList.remove("highlighted")})}moveHighlightDown(){let t=this.dropElm?.querySelectorAll(A)||[],e=t.length;this._currentHighlightIndex<e-1?(this._currentHighlightIndex++,t[this._currentHighlightIndex]?.classList.contains("disabled")&&this.moveHighlightDown()):this.options.infiniteScroll&&this.infiniteScrollHandler(null,this._currentHighlightIndex,e),this.highlightCurrentOption()}moveHighlightUp(){let t=this.dropElm?.querySelectorAll(A)||[],e=this.options.single?0:1;if(this.virtualScroll&&this._currentHighlightIndex<=e&&this.updateDataStart>0&&this.ulElm){let i=t[this._currentHighlightIndex+(this.options.single?0:1)],l=i?.dataset.key;this.lastFocusedItemKey=l,this.ulElm.scrollTop=this.ulElm.scrollTop-i?.getBoundingClientRect().height||10,this.isMoveUpRecalcRequired=!0;return}this._currentHighlightIndex>0&&(this._currentHighlightIndex--,t[this._currentHighlightIndex]?.classList.contains("disabled")&&this.moveHighlightUp()),this.highlightCurrentOption()}recalculateArrowMove(t){let e=this.dropElm?.querySelectorAll(A)||[],i=Array.from(e).findIndex(l=>l.dataset.key===this.lastFocusedItemKey);this._currentHighlightIndex=i-1,t==="down"?this.moveHighlightDown():t==="up"&&(this.moveHighlightUp(),this.isMoveUpRecalcRequired=!1)}close(t){this.options.isOpen=!1,this.parentElm.classList.remove("ms-parent-open"),this.choiceElm?.querySelector("div.ms-icon-caret")?.classList.remove("open"),this.dropElm&&(this.dropElm.style.display="none",this.dropElm.ariaExpanded="false",this.options.container&&(this.parentElm.appendChild(this.dropElm),this.dropElm.style.top="auto",this.dropElm.style.left="auto")),this.options.onClose(t)}applyAsTextOrHtmlWhenEnabled(t,e){t||(t={}),this.isRenderAsHtml?t.innerHTML=typeof this.options.sanitizer=="function"?this.options.sanitizer(e):e:t.textContent=et(e)}update(t=!1){let e=this.getSelects(),i=this.getSelects("text");this.options.displayValues&&(i=e);let l=this.choiceElm?.querySelector("span"),s=e.length,n=null,a=()=>{if(this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml){let h=e.join(this.options.displayDelimiter);return this.options.useSelectOptionLabelToHtml?F(h):h}return i.join(this.options.displayDelimiter)};if(l){if(s===0){let h=this.options.placeholder||"";l.classList.add("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,h)}else s<this.options.minimumCountSelected?n=a():this.formatAllSelected()&&s===this.dataTotal?n=this.formatAllSelected():this.options.ellipsis&&s>this.options.minimumCountSelected?n=`${i.slice(0,this.options.minimumCountSelected).join(this.options.displayDelimiter)}...`:this.formatCountSelected(s,this.dataTotal)&&s>this.options.minimumCountSelected?n=this.formatCountSelected(s,this.dataTotal):n=a();if(n!==null&&(l?.classList.remove("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,n)),this.options.showClear&&this.selectClearElm){let h=n?"block":"none";this.selectClearElm.style.display=h}if(this.options.displayTitle){let h=this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml?"value":"text";l.title=this.getSelects(h).join(this.options.displayDelimiter)}}let c=this.getSelects();this.options.single?this.elm.value=c.length?c[0]:"":Array.from(this.elm.options).forEach(h=>{h.selected=c.some(f=>f===h.value)}),t||this.elm.dispatchEvent(new Event("change"))}updateSelected(t){for(let i=this.updateDataStart;i<this.updateDataEnd;i++){let l=this.updateData[i],s=this.dropElm?.querySelector(`input[data-key=${l._key}]`);if(s){s.checked=l.selected;let n=s.closest("li"),a=n?.querySelector(".icon-checkbox-container div");n&&(l.selected&&!n.classList.contains("selected")?(n.classList.add("selected"),n.ariaSelected="true",a&&(a.className=`ms-icon ms-icon-${s.type==="radio"?"radio":"check"}`)):l.selected||(n.classList.remove("selected"),n.ariaSelected="false",a&&(a.className="ms-icon ms-icon-uncheck")))}}let e=!this.data?.some(i=>i.visible);if(this.selectAllElm){this.selectAllElm.ariaChecked=String(this.isAllSelected);let i=this.dropElm?.querySelector(".ms-select-all .icon-checkbox-container div");if(i){let l="";this.isAllSelected?l="ms-icon-check":this.isPartiallyAllSelected?l="ms-icon-minus":l="ms-icon-uncheck",i.className=`ms-icon ${l}`}this.selectAllElm.checked=this.isAllSelected,j(this.selectAllElm.closest("li"),!e)}j(this.noResultsElm,e),this.virtualScroll&&(this.virtualScroll.rows=t??this.getListRows())}getData(){return this.options.data}getDataLength(){return this.data?.length??0}getOptions(t=!0){let e=Object.assign({},this.options);return delete e.data,t?O(e):this.options}refreshOptions(t){G(this.options,t,!0)||(this.options=Object.assign(this.options,t),this.destroy(!1),this.init())}getDropElement(){return this.dropElm}getParentElement(){return this.parentElm}getSelects(t="value"){let e=[];for(let i of this.data||[])if(i.type==="optgroup"){let l=i.children.filter(s=>s?.selected);if(!l.length)continue;if(t==="value"||this.options.single)e.push(...l.map(s=>t==="value"&&s._value||s[t]));else{let s=[];s.push("["),s.push(i.label),s.push(`: ${l.map(n=>n[t]).join(", ")}`),s.push("]"),e.push(s.join(""))}}else i.selected&&e.push(t==="value"&&i._value||i[t]);return e}setSelects(t,e="value",i=!1){let l=!1,s=n=>{for(let a of n){let c=!1;if(e==="text"){let h=document.createElement("div");this.applyAsTextOrHtmlWhenEnabled(h,a.text),c=t.includes(h.textContent?.trim()??"")}else c=t.includes(a._value||a.value),!c&&a.value===`${+a.value}`&&(c=t.includes(+a.value));a.selected!==c&&(l=!0),a.selected=c}};for(let n of this.data||[])n.type==="optgroup"?s(n.children):s([n]);l&&(this.initSelected(i),this.updateSelected(),this.update(i))}enable(){this.choiceElm&&(this.choiceElm.classList.remove("disabled"),this.choiceElm.disabled=!1)}disable(){this.choiceElm&&(this.choiceElm?.classList.add("disabled"),this.choiceElm.disabled=!0)}check(t){let e=S(this.data,"value",t);e&&this._check(e,!0)}uncheck(t){let e=S(this.data,"value",t);e&&this._check(e,!1)}_check(t,e){this.options.single&&this._checkAll(!1,!0),t.selected=e,this.initSelected(),this.updateSelected(),this.update()}checkAll(){this._checkAll(!0)}uncheckAll(){this._checkAll(!1)}_checkAll(t,e){for(let i of this.data||[])i.type==="optgroup"?this._checkGroup(i,t,!0):!i.disabled&&!i.divider&&(e||i.visible)&&(i.selected=t);e||(this.initSelected(),this.updateSelected(),this.update())}_checkGroup(t,e,i){t.selected=e,t.children.forEach(l=>{l&&!l.disabled&&!l.divider&&(i||l.visible)&&(l.selected=e)}),i||(this.initSelected(),this.updateSelected(),this.update())}checkInvert(){if(!this.options.single){for(let t of this.data||[])if(t.type==="optgroup")for(let e of t.children)e&&(e.divider||(e.selected=!e.selected));else t&&!t.divider&&(t.selected=!t.selected);this.initSelected(),this.updateSelected(),this.update()}}focus(){this.choiceElm?.focus(),this.options.onFocus()}blur(){this.choiceElm?.blur(),this.options.onBlur()}refresh(){this.destroy(!1),this.init()}filter(t){let e=this.searchInputElm?.value.trim()??"",i=e.toLowerCase();if(this.filterText===i)return;this.filterText=i;for(let s of this.data||[])if(s.type==="optgroup")if(this.options.filterGroup){let n=`${s?.label??""}`;if(s!=null){let a=this.options.customFilter({label:g(n.toString().toLowerCase(),this.options.diacriticParser),search:g(i,this.options.diacriticParser),originalLabel:n,originalSearch:e,row:s});s.visible=a;for(let c of s.children)c&&(c.visible=a)}}else{for(let n of s.children)if(n!=null){let a=`${n?.text??""}`;n.visible=this.options.customFilter({text:g(a.toString().toLowerCase(),this.options.diacriticParser),search:g(i,this.options.diacriticParser),originalText:a,originalSearch:e,row:n,parent:s})}s.visible=s.children.some(n=>n?.visible)}else{let n=`${s?.text??""}`;s.visible=this.options.customFilter({text:g(n.toString().toLowerCase(),this.options.diacriticParser),search:g(i,this.options.diacriticParser),originalText:n,originalSearch:e,row:s})}let l=this.initListItems();this.initSelected(t),this.updateSelected(l),t||this.options.onFilter(e)}adjustDropHeight(t){let e=t!=="top",i=this.filterParentElm?.getBoundingClientRect().height??0,l=this.okButtonElm?.getBoundingClientRect().height??0,s=this.options.single?0:this.selectAllParentElm?.getBoundingClientRect().height??0,n=i+l+s+5,{bottom:a,top:c}=x(this.parentElm),h=this.options.maxHeight;if(e?h=a-n-this.options.adjustedHeightPadding:h=c-n-this.options.adjustedHeightPadding,!this.options.maxHeight||this.options.maxHeight&&h<this.options.maxHeight){let f=this.dropElm?.querySelector("ul");return f&&(f.style.maxHeight=`${h}px`),!0}return!1}adjustDropPosition(t){let e="bottom";if(this.dropElm&&this.parentElm){let{bottom:i,top:l}=x(this.dropElm),{top:s,left:n}=C(this.parentElm),a=this.dropElm.getBoundingClientRect().height,c=this.dropElm.getBoundingClientRect().width,h=document.body.offsetWidth||window.innerWidth,f=this.parentElm.getBoundingClientRect().width;if(i>a)e="bottom";else if(a>i&&l>i){if(this.options.container){let m=s-a;m<0&&(m=0),(m>0||t)&&(e="top",this.dropElm.style.top=`${m<0?0:m}px`)}else e="top",this.dropElm.classList.add(e);this.dropElm.classList.remove("bottom")}h-c<n&&(this.dropElm.style.left=`${n-(c-f)}px`)}return e}adjustDropWidthByText(){if(this.dropElm){let e=this.parentElm.scrollWidth;(this.options.dropWidth||this.options.width)&&(e=this.options.dropWidth||this.options.width||0);let i=this.dropElm.querySelector(".ms-select-all span"),l=this.dropElm.querySelector("ul");if(l){let s=0,n=0,a=(i?.clientWidth??0)+n,h=l.scrollHeight>l.clientHeight?this.getScrollbarWidth():0;n+=H(l,"paddingLeft")*2;let f=!1;for(let m of Array.from(l.querySelectorAll("li"))){let b=m.querySelector("label"),$=m.querySelector(".icon-checkbox-container"),E=m.querySelector("span");b&&E?.textContent&&(f||(n+=H(m,"paddingLeft")*2,n+=H(b,"paddingLeft")*2,n+=H(E,"paddingLeft"),n+=$?.offsetWidth??0,f=!0),E.offsetWidth>s&&(s=E.offsetWidth))}s+=n+h,s<a&&(s=a),this.options.maxWidth&&s>this.options.maxWidth&&(s=this.options.maxWidth),this.options.minWidth&&s<this.options.minWidth&&(s=this.options.minWidth),(e==="100%"||+e<s)&&(this.dropElm.style.minWidth="auto",this.dropElm.style.width=`${s}px`)}}}getScrollbarWidth(){let t=p("div",{style:{visibility:"hidden",width:"100px"}});document.body.appendChild(t);let e=t.offsetWidth;t.style.overflow="scroll";let i=p("div",{style:{width:"100%"}});t.appendChild(i);let l=i.offsetWidth;return t.parentNode?.removeChild(t),e-l}formatAllSelected(){return this.options.allSelectedText||this.options.formatAllSelected()}formatCountSelected(t,e){return this.options.countSelectedText?this.options.countSelectedText.replace("#",`${t}`).replace("%",`${e}`):this.options.formatCountSelected(t,e)}formatNoMatchesFound(){return this.options.noMatchesFoundText||this.options.formatNoMatchesFound()}formatOkButton(){return this.options.okButtonText||this.options.formatOkButton()}formatLazyLoading(){return this.options.lazyLoadingText||this.options.formatLazyLoading()}formatSelectAll(){return this.options.selectAllText||this.options.formatSelectAll()}};var I=(o,t)=>typeof o=="string"?V(document.querySelectorAll(o),t):o instanceof Node?V([o],t):V(o,t);function V(o,t){let e=Array.from(o),i=[];for(let l=0;l<e.length;l++){let s=e[l];try{s._multipleSelect!==void 0&&(s._multipleSelect.destroy(),delete s._multipleSelect),s._multipleSelect=new _(s,t||{}),s._multipleSelect.init();let n=s._multipleSelect.getOptions(!1);n.onHardDestroy=()=>delete s._multipleSelect,n.onAfterHardDestroy=()=>i[l]=null,i.push(s._multipleSelect)}catch(n){console.error(n)}}return i.length===1?i[0]:i}I.defaults=u.DEFAULTS;I.locales={...P};I.methods=u.METHODS;window!==void 0&&(window.multipleSelect=I);export{T as BindingEventService,_ as MultipleSelectInstance,w as VirtualScroll,x as calculateAvailableSpace,M as classNameToList,G as compareObjects,L as convertItemRowToHtml,p as createDomElement,K as createDomStructure,O as deepCopy,v as emptyElement,S as findByParam,B as findParent,C as getOffset,D as getSize,U as insertAfter,y as isDefined,I as multipleSelect,z as objectRemoveEmptyProps,it as omitProp,g as removeDiacritics,k as removeUndefined,q as setDataKeys,F as stripScripts,j as toggleElement,st as windowScrollPosition}; //# sourceMappingURL=index.js.map