multiple-select-vanilla
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,2 +0,2 @@ | ||
var Z=Object.defineProperty;var tt=(o,t,e)=>t in o?Z(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>(tt(o,typeof t!="symbol"?t+"":t,e),e);var L=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];if(typeof t?.forEach=="function")t.forEach(a=>{for(let h of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(a,h))&&(a.addEventListener(h,i,l),this._boundedEvents.push({element:a,eventName:h,listener:i,groupName:s}))});else for(let a of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(t,a))&&(t.addEventListener(a,i,l),this._boundedEvents.push({element:t,eventName:a,listener:i,groupName: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 e=this._boundedEvents.pop(),{element:i,eventName:l,listener:s}=e;this.unbind(i,l,s)}}};var G=typeof window<"u"&&window.multipleSelect!==void 0?window.multipleSelect:{locales:{}},et={formatSelectAll(){return"[Select all]"},formatAllSelected(){return"All selected"},formatCountSelected(o,t){return`${o} of ${t} selected`},formatNoMatchesFound(){return"No matches found"},formatOkButton(){return"OK"}};G.locales["en-US"]=et;var H=G.locales;var it=50,st=4,F={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,infiniteScroll:!1,virtualScroll:!0,cssStyler:()=>null,styler:()=>!1,textTemplate:o=>o.innerHTML.trim(),labelTemplate:o=>o.label,onOpen:()=>!1,onClose:()=>!1,onCheckAll:()=>!1,onUncheckAll:()=>!1,onFocus:()=>!1,onBlur:()=>!1,onOptgroupClick:()=>!1,onBeforeClick:()=>!0,onClick:()=>!1,onFilter:()=>!1,onClear:()=>!1,onAfterCreate:()=>!1,onDestroy:()=>!1,onAfterDestroy:()=>!1,onDestroyed:()=>!1},lt=["init","getOptions","refreshOptions","getSelects","setSelects","enable","disable","open","close","check","uncheck","checkAll","uncheckAll","checkInvert","focus","blur","refresh","destroy"];Object.assign(F,H["en-US"]);var ot={BLOCK_ROWS:it,CLUSTER_BLOCKS:st,DEFAULTS:F,METHODS:lt},u=ot;function q(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 T(o){let t=()=>{let l={};for(let s in o)Object.prototype.hasOwnProperty.call(o,s)&&(l[s]=T(o[s]));return l},e=()=>o.map(l=>T(l)),i=Object.prototype.toString.call(o).slice(8,-1).toLowerCase();return i==="object"?t():i==="array"?e():o}function _(o){return o!=null&&o!==""}function K(o,t){return typeof o=="object"?Object.fromEntries(t?Object.entries(o).filter(([e,i])=>!_(i)&&!t.includes(e)||_(i)):Object.entries(o).filter(([e,i])=>_(i))):o}function U(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 g(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 z(o){return o.replace(/(\b)(on[a-z]+)(\s*)=([^>]*)|javascript:([^>]*)[^>]*|(<\s*)(\/*)script([<>]*).*(<\s*)(\/*)script(>*)|(<|<)(\/*)(script|script defer)(.*)(>|>|>">)/gi,"")}function O(o){return Object.keys(o).forEach(t=>o[t]===void 0?delete o[t]:""),o}function V(o){return o.replace(/[\W_]+(.)/g,(t,e)=>e.toUpperCase())}function f(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 I(o){let t={};if(o){let e=o.replace(/\s/g,"").split(";");for(let i of e){let[l,s]=i.trim().split(":");l&&(t[V(l)]=s.trim())}console.warn("[multiple-select-vanilla] Please note that `styler` is deprecated, please migrate to `cssStyler` when possible.")}return t}function x(o){let t=0,e=0,i=0,l=0,s=window.innerHeight??0,n=window.innerWidth??0,a=rt(),h=a.top,c=a.left,p=k(o);if(p){let m=p.top??0,E=p.left??0;e=m-h,t=s-(m-h),i=E-c,l=n-(E-c)}return{top:e,bottom:t,left:i,right:l}}function d(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&&e.appendChild(i),i}function X(o,t,e){let i=o.props?.innerHTML?nt(o.props,"innerHTML"):o.props,l=d(o.tagName,K(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)X(n,l,s);return t?.appendChild(l),l}function b(o){return o.hasOwnProperty("tagName")?X(o):document.createElement("li")}function y(o){for(;o?.firstChild;)o.lastChild&&o.removeChild(o.lastChild);return o}function k(o){if(!o)return;let t=o?.getBoundingClientRect?.(),e=0,i=0,l=0,s=0;return t?.top!==void 0&&t.left!==void 0&&(e=t.top+window.pageYOffset,i=t.left+window.pageXOffset,s=t.right,l=t.bottom),{top:e,left:i,bottom:l,right:s}}function S(o,t,e){let i=parseFloat(o.style[e]);if(!i||Number.isNaN(i)){switch(t){case"outer":i=o[e==="width"?"offsetWidth":"offsetHeight"];break;case"scroll":i=o[e==="width"?"scrollWidth":"scrollHeight"];break;case"inner":default:i=o[e==="width"?"clientWidth":"clientHeight"];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";let n=window.getComputedStyle(o)[e];i=parseFloat(n),Number.isNaN(i)&&(i=0),o.style.display=l,o.style.position=s}return i||0}function N(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 h of a.replace(n,"").split(" "))i.classList.contains(h)&&(s?i?.tagName.toLowerCase()===s&&(e=i):e=i);i=i.parentElement}return e}function Y(o,t){o.parentNode?.insertBefore(t,o.nextSibling)}function nt(o,t){let{[t]:e,...i}=o;return i}function R(o,t){o?.style&&(o.style.display=o.style.display==="none"&&t!==!1||t===!0?"block":"none")}function gt(o,t){if(o?.classList){let i=t===!0||!o.classList.contains("selected")?"add":"remove";o.classList[i]("selected")}}function rt(){return{left:window.pageXOffset||document.documentElement.scrollLeft||0,top:window.pageYOffset||document.documentElement.scrollTop||0}}var M=class{constructor(t){r(this,"cache");r(this,"clusterRows");r(this,"dataStart");r(this,"dataEnd");r(this,"rows");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,"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),y(this.contentEl)}}initDOM(t){if(typeof this.clusterHeight>"u"){this.cache.scrollTop=this.scrollEl.scrollTop;let n=b(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);y(this.contentEl),i&&l?(e.topOffset&&this.contentEl.appendChild(this.getExtra("top",e.topOffset)),e.rows.forEach(n=>this.contentEl.appendChild(b(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=[],h=i;s<1&&h++;for(let c=i;c<l;c++)t[c]&&a.push(t[c]);return this.dataStart=i,this.dataEnd=l,{topOffset:s,bottomOffset:n,rowsAbove:h,rows:a}}checkChanges(t,e){let i=e!==this.cache[t];return this.cache[t]=e,i}getExtra(t,e){let i=document.createElement("li");return i.className=`virtual-scroll-${t}`,e&&(i.style.height=`${e}px`),i}};var v=".ms-select-all, ul[role=combobox] li[role=option]",at=".ms-select-all.highlighted, ul[role=combobox] li[role=option].highlighted",D=class{constructor(t,e){this.elm=t;r(this,"_bindEventService");r(this,"allSelected",!1);r(this,"fromHtml",!1);r(this,"choiceElm");r(this,"closeElm");r(this,"closeSearchElm");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,"ulElm");r(this,"parentElm");r(this,"labelElm");r(this,"selectAllParentElm");r(this,"selectAllElm");r(this,"searchInputElm");r(this,"selectGroupElms");r(this,"selectItemElms");r(this,"noResultsElm");r(this,"options");r(this,"selectAllName","");r(this,"selectGroupName","");r(this,"selectItemName","");r(this,"openDelayTimer");r(this,"updateDataStart");r(this,"updateDataEnd");r(this,"virtualScroll");r(this,"_currentHighlightIndex",-1);r(this,"_currentSelectedElm");r(this,"isMoveUpRecalcRequired",!1);r(this,"locales",{});this.options=Object.assign({},u.DEFAULTS,this.elm.dataset,e),this._bindEventService=new L({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.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=document.createElement("label"),this.labelElm.htmlFor=this.elm.id),this.labelElm?.querySelector("input")&&(this.labelElm=null),typeof this.options.single>"u"&&(this.options.single=!this.elm.multiple),this.parentElm=d("div",{className:`ms-parent ${this.elm.className||""} ${this.options.classes}`,dataset:{test:"sel"}});let e=this.elm.getAttribute("title")||"";e&&(this.parentElm.title=e),this.options.placeholder=this.options.placeholder||this.elm.getAttribute("placeholder")||"",this.choiceElm=d("button",{className:"ms-choice",type:"button"},this.parentElm),this.choiceElm.appendChild(d("span",{className:"ms-placeholder",textContent:this.options.placeholder})),this.options.showClear&&this.choiceElm.appendChild(d("div",{className:"icon-close"})),this.choiceElm.appendChild(d("div",{className:"icon-caret"})),this.dropElm=d("div",{className:`ms-drop ${this.options.position}`,ariaExpanded:"false"},this.parentElm),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(".icon-close"),this.options.dropWidth&&(this.dropElm.style.width=typeof this.options.dropWidth=="string"?this.options.dropWidth:`${this.options.dropWidth}px`),Y(this.elm,this.parentElm),this.elm.disabled&&this.choiceElm.classList.add("disabled"),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",l=>{l.target===this.choiceElm||N(l.target,".ms-choice")===this.choiceElm||(l.target===this.dropElm||N(l.target,".ms-drop")!==this.dropElm&&l.target!==this.elm)&&this.options.isOpen&&this.close()},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.dataTotal=U(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.update(!0),this.options.isOpen&&this.open(10),this.options.openOnHover&&this.parentElm&&(this._bindEventService.bind(this.parentElm,"mouseover",()=>this.open(null)),this._bindEventService.bind(this.parentElm,"mouseout",()=>this.close()))}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(){if(this.options.filter&&(this.filterParentElm=d("div",{className:"ms-search"},this.dropElm),this.filterParentElm.appendChild(d("input",{autocomplete:"off",autocapitalize:"off",spellcheck:!1,type:"text",placeholder:this.options.filterPlaceholder||"\u{1F50E}\uFE0E"})),this.options.showSearchClear&&this.filterParentElm.appendChild(d("span",{className:"icon-close"}))),this.options.selectAll&&!this.options.single){let t=this.elm.getAttribute("name")||this.options.name||"";this.selectAllParentElm=d("div",{className:"ms-select-all",dataset:{key:"select_all"}});let e=document.createElement("label");d("input",{type:"checkbox",ariaChecked:String(this.allSelected),checked:this.allSelected,dataset:{name:`selectAll${t}`}},e),e.appendChild(d("span",{textContent:this.formatSelectAll()})),this.selectAllParentElm.appendChild(e),this.dropElm.appendChild(this.selectAllParentElm)}this.ulElm=document.createElement("ul"),this.ulElm.role="combobox",this.ulElm.ariaExpanded="false",this.ulElm.ariaMultiSelectable=String(!this.options.single),this.dropElm.appendChild(this.ulElm),this.options.showOkButton&&!this.options.single&&(this.okButtonElm=d("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),this.options.virtualScroll&&e.length>u.BLOCK_ROWS*u.CLUSTER_BLOCKS){this.virtualScroll?.destroy();let i=this.dropElm.style.display!=="none";i||(this.dropElm.style.left="-10000",this.dropElm.style.display="block",this.dropElm.ariaExpanded="true");let l=()=>{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),this.updateDataEnd>this.getDataLength()&&(this.updateDataEnd=this.getDataLength()),this.ulElm&&(this.isMoveUpRecalcRequired?this.recalculateArrowMove("up"):this.virtualScroll.dataStart>this.updateDataStart&&this.recalculateArrowMove("down")))};this.ulElm&&(this.virtualScroll=new M({rows:e,scrollEl:this.ulElm,contentEl:this.ulElm,sanitizer:this.options.sanitizer,callback:()=>{l(),this.events()}})),l(),i||(this.dropElm.style.left="0",this.dropElm.style.display="none",this.dropElm.ariaExpanded="false")}else this.ulElm&&(y(this.ulElm),e.forEach(i=>this.ulElm.appendChild(b(i)))),this.updateDataStart=0,this.updateDataEnd=this.updateData.length,this.virtualScroll=null;return this.events(),e}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",dataset:{key:"infinite"}}}),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="";if(!t?.visible)return[];if(this.updateData.push(t),this.options.single&&!this.options.singleRadio&&(n="hide-radio "),t.selected&&(n+="selected "),t.type==="optgroup"){let C=[],J=this.options.hideOptgroupCheckboxes||this.options.single?{tagName:"span",props:{dataset:{name:this.selectGroupName,key:t._key}}}:{tagName:"input",props:{type:"checkbox",dataset:{name:this.selectGroupName,key:t._key},checked:!!t.selected,disabled:t.disabled}};!n.includes("hide-radio")&&(this.options.hideOptgroupCheckboxes||this.options.single)&&(n+="hide-radio ");let W={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(W.props,t.label);let A={tagName:"li",props:{className:`group${this.options.single||t.disabled?" disabled":""} ${n}`.trim(),role:"option",ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:`optgroup${this.options.single||t.disabled?" disabled":""}`},children:[J,W]}]},$=this.options.cssStyler(t),j=String(this.options.styler(t)||"");return j&&(A.props.style=I(j)),$&&(A.props.style=$),C.push(A),t.children.forEach(Q=>C.push(...this.initListItem(Q,1))),C}if(n+=t.classes||"",e&&this.options.single&&(n+=`option-level-${e} `),t.divider)return[{tagName:"li",props:{className:"option-divider"}}];let a=l||n?(l+n).trim():"";t.disabled&&(a+=" disabled");let h=`${t.disabled?"disabled":""}`,c={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(c.props,t.text);let p={tagName:"input",props:{type:s,value:encodeURI(t.value),dataset:{key:t._key,name:this.selectItemName},checked:!!t.selected,disabled:!!t.disabled}};t.selected&&(p.attrs={checked:"checked"});let m={tagName:"li",props:{className:a,role:"option",title:i,ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:h},children:[p,c]}]},E=this.options.cssStyler(t),B=String(this.options.styler(t)||"");return B&&(m.props.style=I(B)),E&&(m.props.style=E),[m]}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;this.allSelected=this.data?.filter(i=>i.selected&&!i.disabled&&i.visible).length===this.data?.filter(i=>!i.disabled&&i.visible&&!i.divider).length,t||(this.allSelected?this.options.onCheckAll():e===0&&this.options.onUncheckAll())}initView(){let t;window.getComputedStyle?(t=window.getComputedStyle(this.elm).width,t==="auto"&&(t=S(this.dropElm,"outer","width")+20)):t=S(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.closeSearchElm=this.filterParentElm?.querySelector(".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.selectItemElms=this.dropElm.querySelectorAll(`input[data-name="${this.selectItemName}"]:enabled`),this.noResultsElm=this.dropElm.querySelector(".ms-no-results");let t=e=>{e.preventDefault(),!e.target.classList.contains("icon-close")&&this[this.options.isOpen?"close":"open"]()};this.labelElm&&this._bindEventService.bind(this.labelElm,"click",e=>{e.target.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.options.keepOpen&&(this.close(),this.choiceElm.focus())}),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.closeSearchElm&&this._bindEventService.bind(this.closeSearchElm,"click",e=>{e.preventDefault(),this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter()}),this.searchInputElm&&(this._bindEventService.bind(this.searchInputElm,"keydown",e=>{e.code==="Tab"&&e.shiftKey&&this.close()},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.selectItemElms?.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(),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._bindEventService.bind(this.selectGroupElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key);this._checkGroup(s,l),this.options.onOptgroupClick(O({label:s.label,selected:s.selected,data:s._data,children:s.children.map(n=>{if(n)return O({text:n.text,value:n.value,selected:n.selected,disabled:n.disabled,data:n._data})})}))},void 0,"group-checkbox-list"),this._bindEventService.bind(this.selectItemElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key),n=()=>{this.options.single&&this.options.isOpen&&!this.options.keepOpen&&this.close()};if(this.options.onBeforeClick(s)===!1){n();return}this._check(s,l),this.options.onClick(O({text:s.text,value:s.value,selected:s.selected,data:s._data})),n()},void 0,"input-checkbox-list"),this.lastFocusedItemKey&&this.dropElm.querySelector(`li[data-key=${this.lastFocusedItemKey}]`)?.focus(),this._bindEventService.bind(this.dropElm,"mouseover",e=>{let i=e.target.closest(".ms-select-all")||e.target.closest("li");if(this.dropElm.contains(i)){let l=this.dropElm?.querySelectorAll(v)||[],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))}},void 0,"hover-highlight"),this._bindEventService.bind(this.dropElm,"keydown",e=>{switch(e.key){case"ArrowUp":e.preventDefault(),this.moveFocusUp();break;case"ArrowDown":e.preventDefault(),this.moveFocusDown();break;case"Enter":case" ":{let i=e.target.closest(".ms-select-all")||e.target.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}}},void 0,"arrow-highlight"),this.ulElm&&this.options.infiniteScroll&&this._bindEventService.bind(this.ulElm,"scroll",this.infiniteScrollHandler.bind(this),void 0,"option-list-scroll")}infiniteScrollHandler(t){t.target&&this.ulElm&&t.target.scrollTop+t.target.clientHeight===this.ulElm.scrollHeight&&(this.virtualScroll?this.initListItems():this.ulElm.scrollTop=0,this._currentHighlightIndex=0,this.highlightCurrentOption())}open(t=0){t!==null&&t>=0?(clearTimeout(this.openDelayTimer),this.openDelayTimer=setTimeout(()=>this.openDrop(),t)):this.openDrop()}openDrop(){if(this.choiceElm?.classList.contains("disabled"))return;if(this.options.isOpen=!0,this.parentElm.classList.add("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.add("open"),this.dropElm.style.display="block",this.dropElm.ariaExpanded="true",this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="block"),this.noResultsElm&&(this.noResultsElm.style.display="none"),this.getDataLength()||(this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="none"),this.noResultsElm&&(this.noResultsElm.style.display="block")),this.options.container){let s=k(this.dropElm),n;this.options.container instanceof Node?n=this.options.container:typeof this.options.container=="string"&&(n=this.options.container==="body"?document.body:document.querySelector(this.options.container)),n.appendChild(this.dropElm),this.dropElm.style.top=`${s?.top??0}px`,this.dropElm.style.left=`${s?.left??0}px`,this.dropElm.style.minWidth="auto",this.dropElm.style.width=`${S(this.parentElm,"outer","width")}px`}let t=this.options.minHeight,e=this.options.maxHeight;this.options.maxHeightUnit==="row"&&(e=S(this.dropElm.querySelector("ul>li"),"outer","height")*this.options.maxHeight);let i=this.dropElm.querySelector("ul");i&&(t&&(i.style.minHeight=`${t}px`),i.style.maxHeight=`${e}px`),this.dropElm.querySelectorAll(".multiple").forEach(s=>{s.style.width=`${this.options.multipleWidth}px`}),this.getDataLength()&&this.options.filter?(this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter(!0)):this.selectAllElm?this.selectAllElm.focus():i&&(i.tabIndex=0,i.focus()),this.moveFocusDown(),this.options.autoAdjustDropWidthByTextSize&&this.adjustDropWidthByText();let l=this.options.position;if(this.options.autoAdjustDropHeight){if(this.options.autoAdjustDropPosition){let{bottom:s,top:n}=x(this.dropElm),a=this.dropElm.getBoundingClientRect().height;l=s<a&&n>s?"top":"bottom"}this.adjustDropHeight(l)}this.options.autoAdjustDropPosition&&this.adjustDropPosition(!0),this.options.onOpen()}highlightCurrentOption(){let t=this.dropElm?.querySelectorAll(v)||[];if(this._currentHighlightIndex<=t.length){let e=t[this._currentHighlightIndex];e&&(this.lastFocusedItemKey=e.dataset.key||"",this._currentSelectedElm=e,e.scrollIntoView({block:"nearest"}),this.changeCurrentOptionHighlight(e))}}changeCurrentOptionHighlight(t){t.classList.add("highlighted"),(this.dropElm?.querySelectorAll(at)||[]).forEach(i=>{i!==t&&i.classList.remove("highlighted")})}moveFocusDown(){let t=this.dropElm?.querySelectorAll(v)||[];this._currentHighlightIndex<t.length-1&&(this._currentHighlightIndex++,t[this._currentHighlightIndex]?.classList.contains("disabled")&&this.moveFocusDown()),this.highlightCurrentOption()}moveFocusUp(){let t=this.dropElm?.querySelectorAll(v)||[],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.moveFocusUp()),this.highlightCurrentOption()}recalculateArrowMove(t){let e=this.dropElm?.querySelectorAll(v)||[],i=Array.from(e).findIndex(l=>l.dataset.key===this.lastFocusedItemKey);this._currentHighlightIndex=i-1,t==="down"?this.moveFocusDown():t==="up"&&(this.moveFocusUp(),this.isMoveUpRecalcRequired=!1)}close(){this.options.isOpen=!1,this.parentElm.classList.remove("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.remove("open"),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()}applyAsTextOrHtmlWhenEnabled(t,e){t||(t={}),this.isRenderAsHtml?t.innerHTML=typeof this.options.sanitizer=="function"?this.options.sanitizer(e):e:t.textContent=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 c=e.join(this.options.displayDelimiter);return this.options.useSelectOptionLabelToHtml?z(c):c}return i.join(this.options.displayDelimiter)};if(l){if(s===0){let c=this.options.placeholder||"";l.classList.add("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,c)}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.displayTitle||this.options.addTitle){this.options.addTitle&&console.warn("[Multiple-Select-Vanilla] Please note that the `addTitle` option was deprecated and replaced by `displayTitle`.");let c=this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml?"value":"text";l.title=this.getSelects(c).join(this.options.displayDelimiter)}}let h=this.getSelects();this.options.single?this.elm.value=h.length?h[0]:"":Array.from(this.elm.options).forEach(c=>{c.selected=h.some(p=>p===c.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");n&&(l.selected&&!n.classList.contains("selected")?(n.classList.add("selected"),n.ariaSelected="true"):l.selected||(n.classList.remove("selected"),n.ariaSelected="false"))}}let e=this.data?.filter(i=>i.visible).length===0;this.selectAllElm&&(this.selectAllElm.ariaChecked=String(this.allSelected),this.selectAllElm.checked=this.allSelected,R(this.selectAllElm.closest("li"),!e)),R(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?T(e):this.options}refreshOptions(t){q(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 h=!1;if(e==="text"){let c=document.createElement("div");this.applyAsTextOrHtmlWhenEnabled(c,a.text),h=t.includes(c.textContent?.trim()??"")}else h=t.includes(a._value||a.value),!h&&a.value===`${+a.value}`&&(h=t.includes(+a.value));a.selected!==h&&(l=!0),a.selected=h}};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?.classList.remove("disabled")}disable(){this.choiceElm?.classList.add("disabled")}check(t){let e=g(this.data,"value",t);e&&this._check(e,!0)}uncheck(t){let e=g(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:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalLabel:n,originalSearch:e,row:s});s.visible=a;for(let h of s.children)h&&(h.visible=a)}}else{for(let n of s.children)if(n!=null){let a=`${n?.text??""}`;n.visible=this.options.customFilter({text:f(a.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalText:a,originalSearch:e,row:n,parent:s})}s.visible=s.children.filter(n=>n?.visible).length>0}else{let n=`${s?.text??""}`;s.visible=this.options.customFilter({text:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(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:h}=x(this.parentElm),c=this.options.maxHeight;if(e?c=a-n-this.options.adjustedHeightPadding:c=h-n-this.options.adjustedHeightPadding,!this.options.maxHeight||this.options.maxHeight&&c<this.options.maxHeight){let p=this.dropElm?.querySelector("ul");return p&&(p.style.maxHeight=`${c}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}=k(this.parentElm),a=this.dropElm.getBoundingClientRect().height,h=this.dropElm.getBoundingClientRect().width,c=document.body.offsetWidth||window.innerWidth,p=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")}c-h<n&&(this.dropElm.style.left=`${n-(h-p)}px`)}return e}adjustDropWidthByText(){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"),s=26,n=i?.clientWidth??0+s,h=l.scrollHeight>l.clientHeight?this.getScrollbarWidth():0,c=0;this.dropElm.querySelectorAll("li label").forEach(p=>{p.scrollWidth>c&&(c=p.scrollWidth)}),c+=s+h,c<n&&(c=n),this.options.maxWidth&&c>this.options.maxWidth&&(c=this.options.maxWidth),this.options.minWidth&&c<this.options.minWidth&&(c=this.options.minWidth),(e==="100%"||+e<c)&&(this.dropElm.style.width=`${c}px`,this.dropElm.style.maxWidth=`${c}px`)}getScrollbarWidth(){let t=document.createElement("div");t.style.visibility="hidden",t.style.width="100px",document.body.appendChild(t);let e=t.offsetWidth;t.style.overflow="scroll";let i=document.createElement("div");i.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()}formatSelectAll(){return this.options.selectAllText||this.options.formatSelectAll()}};var w=(o,t)=>typeof o=="string"?P(document.querySelectorAll(o),t):o instanceof Node?P([o],t):P(o,t);function P(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 D(s,t||{}),s._multipleSelect.init();let n=s._multipleSelect.getOptions(!1);n.onHardDestroy=()=>delete s._multipleSelect,n.onAfterHardDestroyed=()=>i[l]=null,i.push(s._multipleSelect)}catch(n){console.error(n)}}return i.length===1?i[0]:i}w.defaults=u.DEFAULTS;w.locales={...H};w.methods=u.METHODS;typeof window<"u"&&(window.multipleSelect=w);export{L as BindingEventService,D as MultipleSelectInstance,M as VirtualScroll,x as calculateAvailableSpace,q as compareObjects,b as convertItemRowToHtml,I as convertStringStyleToElementStyle,d as createDomElement,X as createDomStructure,T as deepCopy,y as emptyElement,g as findByParam,N as findParent,k as getElementOffset,S as getElementSize,Y as insertAfter,_ as isDefined,w as multipleSelect,K as objectRemoveEmptyProps,nt as omitProp,f as removeDiacritics,O as removeUndefined,U as setDataKeys,z as stripScripts,V as toCamelCase,R as toggleElement,gt as toggleElementClass,rt as windowScrollPosition}; | ||
var Z=Object.defineProperty;var tt=(o,t,e)=>t in o?Z(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>(tt(o,typeof t!="symbol"?t+"":t,e),e);var L=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];if(typeof t?.forEach=="function")t.forEach(a=>{for(let h of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(a,h))&&(a.addEventListener(h,i,l),this._boundedEvents.push({element:a,eventName:h,listener:i,groupName:s}))});else for(let a of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(t,a))&&(t.addEventListener(a,i,l),this._boundedEvents.push({element:t,eventName:a,listener:i,groupName: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 e=this._boundedEvents.pop(),{element:i,eventName:l,listener:s}=e;this.unbind(i,l,s)}}};var G=typeof window<"u"&&window.multipleSelect!==void 0?window.multipleSelect:{locales:{}},et={formatSelectAll(){return"[Select all]"},formatAllSelected(){return"All selected"},formatCountSelected(o,t){return`${o} of ${t} selected`},formatNoMatchesFound(){return"No matches found"},formatOkButton(){return"OK"}};G.locales["en-US"]=et;var H=G.locales;var it=50,st=4,F={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,infiniteScroll:!1,virtualScroll:!0,cssStyler:()=>null,styler:()=>!1,textTemplate:o=>o.innerHTML.trim(),labelTemplate:o=>o.label,onOpen:()=>!1,onClose:()=>!1,onCheckAll:()=>!1,onUncheckAll:()=>!1,onFocus:()=>!1,onBlur:()=>!1,onOptgroupClick:()=>!1,onBeforeClick:()=>!0,onClick:()=>!1,onFilter:()=>!1,onClear:()=>!1,onAfterCreate:()=>!1,onDestroy:()=>!1,onAfterDestroy:()=>!1,onDestroyed:()=>!1},lt=["init","getOptions","refreshOptions","getSelects","setSelects","enable","disable","open","close","check","uncheck","checkAll","uncheckAll","checkInvert","focus","blur","refresh","destroy"];Object.assign(F,H["en-US"]);var ot={BLOCK_ROWS:it,CLUSTER_BLOCKS:st,DEFAULTS:F,METHODS:lt},u=ot;function q(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 T(o){let t=()=>{let l={};for(let s in o)Object.prototype.hasOwnProperty.call(o,s)&&(l[s]=T(o[s]));return l},e=()=>o.map(l=>T(l)),i=Object.prototype.toString.call(o).slice(8,-1).toLowerCase();return i==="object"?t():i==="array"?e():o}function _(o){return o!=null&&o!==""}function K(o,t){return typeof o=="object"?Object.fromEntries(t?Object.entries(o).filter(([e,i])=>!_(i)&&!t.includes(e)||_(i)):Object.entries(o).filter(([e,i])=>_(i))):o}function U(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 g(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 z(o){return o.replace(/(\b)(on[a-z]+)(\s*)=([^>]*)|javascript:([^>]*)[^>]*|(<\s*)(\/*)script([<>]*).*(<\s*)(\/*)script(>*)|(<|<)(\/*)(script|script defer)(.*)(>|>|>">)/gi,"")}function O(o){return Object.keys(o).forEach(t=>o[t]===void 0?delete o[t]:""),o}function V(o){return o.replace(/[\W_]+(.)/g,(t,e)=>e.toUpperCase())}function f(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 I(o){let t={};if(o){let e=o.replace(/\s/g,"").split(";");for(let i of e){let[l,s]=i.trim().split(":");l&&(t[V(l)]=s.trim())}console.warn("[multiple-select-vanilla] Please note that `styler` is deprecated, please migrate to `cssStyler` when possible.")}return t}function x(o){let t=0,e=0,i=0,l=0,s=window.innerHeight??0,n=window.innerWidth??0,a=rt(),h=a.top,c=a.left,p=k(o);if(p){let m=p.top??0,E=p.left??0;e=m-h,t=s-(m-h),i=E-c,l=n-(E-c)}return{top:e,bottom:t,left:i,right:l}}function d(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&&e.appendChild(i),i}function X(o,t,e){let i=o.props?.innerHTML?nt(o.props,"innerHTML"):o.props,l=d(o.tagName,K(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)X(n,l,s);return t?.appendChild(l),l}function b(o){return o.hasOwnProperty("tagName")?X(o):document.createElement("li")}function y(o){for(;o?.firstChild;)o.lastChild&&o.removeChild(o.lastChild);return o}function k(o){if(!o)return;let t=o?.getBoundingClientRect?.(),e=0,i=0,l=0,s=0;return t?.top!==void 0&&t.left!==void 0&&(e=t.top+window.pageYOffset,i=t.left+window.pageXOffset,s=t.right,l=t.bottom),{top:e,left:i,bottom:l,right:s}}function S(o,t,e){let i=parseFloat(o.style[e]);if(!i||Number.isNaN(i)){switch(t){case"outer":i=o[e==="width"?"offsetWidth":"offsetHeight"];break;case"scroll":i=o[e==="width"?"scrollWidth":"scrollHeight"];break;case"inner":default:i=o[e==="width"?"clientWidth":"clientHeight"];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";let n=window.getComputedStyle(o)[e];i=parseFloat(n),Number.isNaN(i)&&(i=0),o.style.display=l,o.style.position=s}return i||0}function N(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 h of a.replace(n,"").split(" "))i.classList.contains(h)&&(s?i?.tagName.toLowerCase()===s&&(e=i):e=i);i=i.parentElement}return e}function Y(o,t){o.parentNode?.insertBefore(t,o.nextSibling)}function nt(o,t){let{[t]:e,...i}=o;return i}function R(o,t){o?.style&&(o.style.display=o.style.display==="none"&&t!==!1||t===!0?"block":"none")}function gt(o,t){if(o?.classList){let i=t===!0||!o.classList.contains("selected")?"add":"remove";o.classList[i]("selected")}}function rt(){return{left:window.pageXOffset||document.documentElement.scrollLeft||0,top:window.pageYOffset||document.documentElement.scrollTop||0}}var M=class{constructor(t){r(this,"cache");r(this,"clusterRows");r(this,"dataStart");r(this,"dataEnd");r(this,"rows");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,"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),y(this.contentEl)}}initDOM(t){if(typeof this.clusterHeight>"u"){this.cache.scrollTop=this.scrollEl.scrollTop;let n=b(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);y(this.contentEl),i&&l?(e.topOffset&&this.contentEl.appendChild(this.getExtra("top",e.topOffset)),e.rows.forEach(n=>this.contentEl.appendChild(b(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=[],h=i;s<1&&h++;for(let c=i;c<l;c++)t[c]&&a.push(t[c]);return this.dataStart=i,this.dataEnd=l,{topOffset:s,bottomOffset:n,rowsAbove:h,rows:a}}checkChanges(t,e){let i=e!==this.cache[t];return this.cache[t]=e,i}getExtra(t,e){let i=document.createElement("li");return i.className=`virtual-scroll-${t}`,e&&(i.style.height=`${e}px`),i}};var v=".ms-select-all, ul[role=combobox] li[role=option]",at=".ms-select-all.highlighted, ul[role=combobox] li[role=option].highlighted",D=class{constructor(t,e){this.elm=t;r(this,"_bindEventService");r(this,"allSelected",!1);r(this,"fromHtml",!1);r(this,"choiceElm");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,"ulElm");r(this,"parentElm");r(this,"labelElm");r(this,"selectAllParentElm");r(this,"selectAllElm");r(this,"searchInputElm");r(this,"selectGroupElms");r(this,"selectItemElms");r(this,"noResultsElm");r(this,"options");r(this,"selectAllName","");r(this,"selectGroupName","");r(this,"selectItemName","");r(this,"openDelayTimer");r(this,"updateDataStart");r(this,"updateDataEnd");r(this,"virtualScroll");r(this,"_currentHighlightIndex",-1);r(this,"_currentSelectedElm");r(this,"isMoveUpRecalcRequired",!1);r(this,"locales",{});this.options=Object.assign({},u.DEFAULTS,this.elm.dataset,e),this._bindEventService=new L({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.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=document.createElement("label"),this.labelElm.htmlFor=this.elm.id),this.labelElm?.querySelector("input")&&(this.labelElm=null),typeof this.options.single>"u"&&(this.options.single=!this.elm.multiple),this.parentElm=d("div",{className:`ms-parent ${this.elm.className||""} ${this.options.classes}`,dataset:{test:"sel"}});let e=this.elm.getAttribute("title")||"";e&&(this.parentElm.title=e),this.options.placeholder=this.options.placeholder||this.elm.getAttribute("placeholder")||"",this.choiceElm=d("button",{className:"ms-choice",type:"button"},this.parentElm),this.choiceElm.appendChild(d("span",{className:"ms-placeholder",textContent:this.options.placeholder})),this.options.showClear&&this.choiceElm.appendChild(d("div",{className:"icon-close"})),this.choiceElm.appendChild(d("div",{className:"icon-caret"})),this.dropElm=d("div",{className:`ms-drop ${this.options.position}`,ariaExpanded:"false"},this.parentElm),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(".icon-close"),this.options.dropWidth&&(this.dropElm.style.width=typeof this.options.dropWidth=="string"?this.options.dropWidth:`${this.options.dropWidth}px`),Y(this.elm,this.parentElm),this.elm.disabled&&this.choiceElm.classList.add("disabled"),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",l=>{l.target===this.choiceElm||N(l.target,".ms-choice")===this.choiceElm||(l.target===this.dropElm||N(l.target,".ms-drop")!==this.dropElm&&l.target!==this.elm)&&this.options.isOpen&&this.close()},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.dataTotal=U(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.update(!0),this.options.isOpen&&this.open(10),this.options.openOnHover&&this.parentElm&&(this._bindEventService.bind(this.parentElm,"mouseover",()=>this.open(null)),this._bindEventService.bind(this.parentElm,"mouseout",()=>this.close()))}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(){if(this.options.filter&&(this.filterParentElm=d("div",{className:"ms-search"},this.dropElm),this.filterParentElm.appendChild(d("input",{autocomplete:"off",autocapitalize:"off",spellcheck:!1,type:"text",placeholder:this.options.filterPlaceholder||"\u{1F50E}\uFE0E"})),this.options.showSearchClear&&this.filterParentElm.appendChild(d("span",{className:"icon-close"}))),this.options.selectAll&&!this.options.single){let t=this.elm.getAttribute("name")||this.options.name||"";this.selectAllParentElm=d("div",{className:"ms-select-all",dataset:{key:"select_all"}});let e=document.createElement("label");d("input",{type:"checkbox",ariaChecked:String(this.allSelected),checked:this.allSelected,dataset:{name:`selectAll${t}`}},e),e.appendChild(d("span",{textContent:this.formatSelectAll()})),this.selectAllParentElm.appendChild(e),this.dropElm.appendChild(this.selectAllParentElm)}this.ulElm=document.createElement("ul"),this.ulElm.role="combobox",this.ulElm.ariaExpanded="false",this.ulElm.ariaMultiSelectable=String(!this.options.single),this.dropElm.appendChild(this.ulElm),this.options.showOkButton&&!this.options.single&&(this.okButtonElm=d("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),this.options.virtualScroll&&e.length>u.BLOCK_ROWS*u.CLUSTER_BLOCKS){this.virtualScroll?.destroy();let i=this.dropElm.style.display!=="none";i||(this.dropElm.style.left="-10000",this.dropElm.style.display="block",this.dropElm.ariaExpanded="true");let l=()=>{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),this.updateDataEnd>this.getDataLength()&&(this.updateDataEnd=this.getDataLength()),this.ulElm&&(this.isMoveUpRecalcRequired?this.recalculateArrowMove("up"):this.virtualScroll.dataStart>this.updateDataStart&&this.recalculateArrowMove("down")))};this.ulElm&&(this.virtualScroll=new M({rows:e,scrollEl:this.ulElm,contentEl:this.ulElm,sanitizer:this.options.sanitizer,callback:()=>{l(),this.events()}})),l(),i||(this.dropElm.style.left="0",this.dropElm.style.display="none",this.dropElm.ariaExpanded="false")}else this.ulElm&&(y(this.ulElm),e.forEach(i=>this.ulElm.appendChild(b(i)))),this.updateDataStart=0,this.updateDataEnd=this.updateData.length,this.virtualScroll=null;return this.events(),e}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",dataset:{key:"infinite"}}}),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="";if(!t?.visible)return[];if(this.updateData.push(t),this.options.single&&!this.options.singleRadio&&(n="hide-radio "),t.selected&&(n+="selected "),t.type==="optgroup"){let C=[],J=this.options.hideOptgroupCheckboxes||this.options.single?{tagName:"span",props:{dataset:{name:this.selectGroupName,key:t._key}}}:{tagName:"input",props:{type:"checkbox",dataset:{name:this.selectGroupName,key:t._key},checked:!!t.selected,disabled:t.disabled}};!n.includes("hide-radio")&&(this.options.hideOptgroupCheckboxes||this.options.single)&&(n+="hide-radio ");let W={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(W.props,t.label);let A={tagName:"li",props:{className:`group${this.options.single||t.disabled?" disabled":""} ${n}`.trim(),role:"option",ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:`optgroup${this.options.single||t.disabled?" disabled":""}`},children:[J,W]}]},$=this.options.cssStyler(t),j=String(this.options.styler(t)||"");return j&&(A.props.style=I(j)),$&&(A.props.style=$),C.push(A),t.children.forEach(Q=>C.push(...this.initListItem(Q,1))),C}if(n+=t.classes||"",e&&this.options.single&&(n+=`option-level-${e} `),t.divider)return[{tagName:"li",props:{className:"option-divider"}}];let a=l||n?(l+n).trim():"";t.disabled&&(a+=" disabled");let h=`${t.disabled?"disabled":""}`,c={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(c.props,t.text);let p={tagName:"input",props:{type:s,value:encodeURI(t.value),dataset:{key:t._key,name:this.selectItemName},checked:!!t.selected,disabled:!!t.disabled}};t.selected&&(p.attrs={checked:"checked"});let m={tagName:"li",props:{className:a,role:"option",title:i,ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:h},children:[p,c]}]},E=this.options.cssStyler(t),B=String(this.options.styler(t)||"");return B&&(m.props.style=I(B)),E&&(m.props.style=E),[m]}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;this.allSelected=this.data?.filter(i=>i.selected&&!i.disabled&&i.visible).length===this.data?.filter(i=>!i.disabled&&i.visible&&!i.divider).length,t||(this.allSelected?this.options.onCheckAll():e===0&&this.options.onUncheckAll())}initView(){let t;window.getComputedStyle?(t=window.getComputedStyle(this.elm).width,t==="auto"&&(t=S(this.dropElm,"outer","width")+20)):t=S(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(".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.selectItemElms=this.dropElm.querySelectorAll(`input[data-name="${this.selectItemName}"]:enabled`),this.noResultsElm=this.dropElm.querySelector(".ms-no-results");let t=e=>{e.preventDefault(),!e.target.classList.contains("icon-close")&&this[this.options.isOpen?"close":"open"]()};this.labelElm&&this._bindEventService.bind(this.labelElm,"click",e=>{e.target.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.options.keepOpen&&(this.close(),this.choiceElm.focus())}),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.moveFocusDown(),this.filter()}),this.searchInputElm&&(this._bindEventService.bind(this.searchInputElm,"keydown",e=>{e.code==="Tab"&&e.shiftKey&&this.close()},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.selectItemElms?.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(),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._bindEventService.bind(this.selectGroupElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key);this._checkGroup(s,l),this.options.onOptgroupClick(O({label:s.label,selected:s.selected,data:s._data,children:s.children.map(n=>{if(n)return O({text:n.text,value:n.value,selected:n.selected,disabled:n.disabled,data:n._data})})}))},void 0,"group-checkbox-list"),this._bindEventService.bind(this.selectItemElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key),n=()=>{this.options.single&&this.options.isOpen&&!this.options.keepOpen&&this.close()};if(this.options.onBeforeClick(s)===!1){n();return}this._check(s,l),this.options.onClick(O({text:s.text,value:s.value,selected:s.selected,data:s._data})),n()},void 0,"input-checkbox-list"),this.lastFocusedItemKey&&this.dropElm.querySelector(`li[data-key=${this.lastFocusedItemKey}]`)?.focus(),this._bindEventService.bind(this.dropElm,"mouseover",e=>{let i=e.target.closest(".ms-select-all")||e.target.closest("li");if(this.dropElm.contains(i)){let l=this.dropElm?.querySelectorAll(v)||[],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))}},void 0,"hover-highlight"),this._bindEventService.bind(this.dropElm,"keydown",e=>{switch(e.key){case"ArrowUp":e.preventDefault(),this.moveFocusUp();break;case"ArrowDown":e.preventDefault(),this.moveFocusDown();break;case"Enter":case" ":{let i=e.target.closest(".ms-select-all")||e.target.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}}},void 0,"arrow-highlight"),this.ulElm&&this.options.infiniteScroll&&this._bindEventService.bind(this.ulElm,"scroll",this.infiniteScrollHandler.bind(this),void 0,"option-list-scroll")}infiniteScrollHandler(t){t.target&&this.ulElm&&t.target.scrollTop+t.target.clientHeight===this.ulElm.scrollHeight&&(this.virtualScroll?this.initListItems():this.ulElm.scrollTop=0,this._currentHighlightIndex=0,this.highlightCurrentOption())}open(t=0){t!==null&&t>=0?(clearTimeout(this.openDelayTimer),this.openDelayTimer=setTimeout(()=>this.openDrop(),t)):this.openDrop()}openDrop(){if(this.choiceElm?.classList.contains("disabled"))return;if(this.options.isOpen=!0,this.parentElm.classList.add("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.add("open"),this.dropElm.style.display="block",this.dropElm.ariaExpanded="true",this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="block"),this.noResultsElm&&(this.noResultsElm.style.display="none"),this.getDataLength()||(this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="none"),this.noResultsElm&&(this.noResultsElm.style.display="block")),this.options.container){let s=k(this.dropElm),n;this.options.container instanceof Node?n=this.options.container:typeof this.options.container=="string"&&(n=this.options.container==="body"?document.body:document.querySelector(this.options.container)),n.appendChild(this.dropElm),this.dropElm.style.top=`${s?.top??0}px`,this.dropElm.style.left=`${s?.left??0}px`,this.dropElm.style.minWidth="auto",this.dropElm.style.width=`${S(this.parentElm,"outer","width")}px`}let t=this.options.minHeight,e=this.options.maxHeight;this.options.maxHeightUnit==="row"&&(e=S(this.dropElm.querySelector("ul>li"),"outer","height")*this.options.maxHeight);let i=this.dropElm.querySelector("ul");i&&(t&&(i.style.minHeight=`${t}px`),i.style.maxHeight=`${e}px`),this.dropElm.querySelectorAll(".multiple").forEach(s=>{s.style.width=`${this.options.multipleWidth}px`}),this.getDataLength()&&this.options.filter?(this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter(!0)):this.selectAllElm?this.selectAllElm.focus():i&&(i.tabIndex=0,i.focus()),this._currentHighlightIndex<0?this.moveFocusDown():this.highlightCurrentOption(),this.options.autoAdjustDropWidthByTextSize&&this.adjustDropWidthByText();let l=this.options.position;if(this.options.autoAdjustDropHeight){if(this.options.autoAdjustDropPosition){let{bottom:s,top:n}=x(this.dropElm),a=this.dropElm.getBoundingClientRect().height;l=s<a&&n>s?"top":"bottom"}this.adjustDropHeight(l)}this.options.autoAdjustDropPosition&&this.adjustDropPosition(!0),this.options.onOpen()}highlightCurrentOption(){let t=this.dropElm?.querySelectorAll(v)||[];if(this._currentHighlightIndex<=t.length){let e=t[this._currentHighlightIndex];e&&(this.lastFocusedItemKey=e.dataset.key||"",this._currentSelectedElm=e,e.scrollIntoView({block:"nearest"}),this.changeCurrentOptionHighlight(e))}}changeCurrentOptionHighlight(t){t.classList.add("highlighted"),(this.dropElm?.querySelectorAll(at)||[]).forEach(i=>{i!==t&&i.classList.remove("highlighted")})}moveFocusDown(){let t=this.dropElm?.querySelectorAll(v)||[];this._currentHighlightIndex<t.length-1&&(this._currentHighlightIndex++,t[this._currentHighlightIndex]?.classList.contains("disabled")&&this.moveFocusDown()),this.highlightCurrentOption()}moveFocusUp(){let t=this.dropElm?.querySelectorAll(v)||[],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.moveFocusUp()),this.highlightCurrentOption()}recalculateArrowMove(t){let e=this.dropElm?.querySelectorAll(v)||[],i=Array.from(e).findIndex(l=>l.dataset.key===this.lastFocusedItemKey);this._currentHighlightIndex=i-1,t==="down"?this.moveFocusDown():t==="up"&&(this.moveFocusUp(),this.isMoveUpRecalcRequired=!1)}close(){this.options.isOpen=!1,this.parentElm.classList.remove("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.remove("open"),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()}applyAsTextOrHtmlWhenEnabled(t,e){t||(t={}),this.isRenderAsHtml?t.innerHTML=typeof this.options.sanitizer=="function"?this.options.sanitizer(e):e:t.textContent=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 c=e.join(this.options.displayDelimiter);return this.options.useSelectOptionLabelToHtml?z(c):c}return i.join(this.options.displayDelimiter)};if(l){if(s===0){let c=this.options.placeholder||"";l.classList.add("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,c)}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.displayTitle||this.options.addTitle){this.options.addTitle&&console.warn("[Multiple-Select-Vanilla] Please note that the `addTitle` option was deprecated and replaced by `displayTitle`.");let c=this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml?"value":"text";l.title=this.getSelects(c).join(this.options.displayDelimiter)}}let h=this.getSelects();this.options.single?this.elm.value=h.length?h[0]:"":Array.from(this.elm.options).forEach(c=>{c.selected=h.some(p=>p===c.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");n&&(l.selected&&!n.classList.contains("selected")?(n.classList.add("selected"),n.ariaSelected="true"):l.selected||(n.classList.remove("selected"),n.ariaSelected="false"))}}let e=this.data?.filter(i=>i.visible).length===0;this.selectAllElm&&(this.selectAllElm.ariaChecked=String(this.allSelected),this.selectAllElm.checked=this.allSelected,R(this.selectAllElm.closest("li"),!e)),R(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?T(e):this.options}refreshOptions(t){q(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 h=!1;if(e==="text"){let c=document.createElement("div");this.applyAsTextOrHtmlWhenEnabled(c,a.text),h=t.includes(c.textContent?.trim()??"")}else h=t.includes(a._value||a.value),!h&&a.value===`${+a.value}`&&(h=t.includes(+a.value));a.selected!==h&&(l=!0),a.selected=h}};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?.classList.remove("disabled")}disable(){this.choiceElm?.classList.add("disabled")}check(t){let e=g(this.data,"value",t);e&&this._check(e,!0)}uncheck(t){let e=g(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:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalLabel:n,originalSearch:e,row:s});s.visible=a;for(let h of s.children)h&&(h.visible=a)}}else{for(let n of s.children)if(n!=null){let a=`${n?.text??""}`;n.visible=this.options.customFilter({text:f(a.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalText:a,originalSearch:e,row:n,parent:s})}s.visible=s.children.filter(n=>n?.visible).length>0}else{let n=`${s?.text??""}`;s.visible=this.options.customFilter({text:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(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:h}=x(this.parentElm),c=this.options.maxHeight;if(e?c=a-n-this.options.adjustedHeightPadding:c=h-n-this.options.adjustedHeightPadding,!this.options.maxHeight||this.options.maxHeight&&c<this.options.maxHeight){let p=this.dropElm?.querySelector("ul");return p&&(p.style.maxHeight=`${c}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}=k(this.parentElm),a=this.dropElm.getBoundingClientRect().height,h=this.dropElm.getBoundingClientRect().width,c=document.body.offsetWidth||window.innerWidth,p=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")}c-h<n&&(this.dropElm.style.left=`${n-(h-p)}px`)}return e}adjustDropWidthByText(){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"),s=26,n=i?.clientWidth??0+s,h=l.scrollHeight>l.clientHeight?this.getScrollbarWidth():0,c=0;this.dropElm.querySelectorAll("li label").forEach(p=>{p.scrollWidth>c&&(c=p.scrollWidth)}),c+=s+h,c<n&&(c=n),this.options.maxWidth&&c>this.options.maxWidth&&(c=this.options.maxWidth),this.options.minWidth&&c<this.options.minWidth&&(c=this.options.minWidth),(e==="100%"||+e<c)&&(this.dropElm.style.width=`${c}px`,this.dropElm.style.maxWidth=`${c}px`)}getScrollbarWidth(){let t=document.createElement("div");t.style.visibility="hidden",t.style.width="100px",document.body.appendChild(t);let e=t.offsetWidth;t.style.overflow="scroll";let i=document.createElement("div");i.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()}formatSelectAll(){return this.options.selectAllText||this.options.formatSelectAll()}};var w=(o,t)=>typeof o=="string"?P(document.querySelectorAll(o),t):o instanceof Node?P([o],t):P(o,t);function P(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 D(s,t||{}),s._multipleSelect.init();let n=s._multipleSelect.getOptions(!1);n.onHardDestroy=()=>delete s._multipleSelect,n.onAfterHardDestroyed=()=>i[l]=null,i.push(s._multipleSelect)}catch(n){console.error(n)}}return i.length===1?i[0]:i}w.defaults=u.DEFAULTS;w.locales={...H};w.methods=u.METHODS;typeof window<"u"&&(window.multipleSelect=w);export{L as BindingEventService,D as MultipleSelectInstance,M as VirtualScroll,x as calculateAvailableSpace,q as compareObjects,b as convertItemRowToHtml,I as convertStringStyleToElementStyle,d as createDomElement,X as createDomStructure,T as deepCopy,y as emptyElement,g as findByParam,N as findParent,k as getElementOffset,S as getElementSize,Y as insertAfter,_ as isDefined,w as multipleSelect,K as objectRemoveEmptyProps,nt as omitProp,f as removeDiacritics,O as removeUndefined,U as setDataKeys,z as stripScripts,V as toCamelCase,R as toggleElement,gt as toggleElementClass,rt as windowScrollPosition}; | ||
//# sourceMappingURL=multiple-select.js.map |
@@ -1,2 +0,2 @@ | ||
var Z=Object.defineProperty;var tt=(o,t,e)=>t in o?Z(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>(tt(o,typeof t!="symbol"?t+"":t,e),e);var L=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];if(typeof t?.forEach=="function")t.forEach(a=>{for(let h of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(a,h))&&(a.addEventListener(h,i,l),this._boundedEvents.push({element:a,eventName:h,listener:i,groupName:s}))});else for(let a of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(t,a))&&(t.addEventListener(a,i,l),this._boundedEvents.push({element:t,eventName:a,listener:i,groupName: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 e=this._boundedEvents.pop(),{element:i,eventName:l,listener:s}=e;this.unbind(i,l,s)}}};var G=typeof window<"u"&&window.multipleSelect!==void 0?window.multipleSelect:{locales:{}},et={formatSelectAll(){return"[Select all]"},formatAllSelected(){return"All selected"},formatCountSelected(o,t){return`${o} of ${t} selected`},formatNoMatchesFound(){return"No matches found"},formatOkButton(){return"OK"}};G.locales["en-US"]=et;var H=G.locales;var it=50,st=4,F={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,infiniteScroll:!1,virtualScroll:!0,cssStyler:()=>null,styler:()=>!1,textTemplate:o=>o.innerHTML.trim(),labelTemplate:o=>o.label,onOpen:()=>!1,onClose:()=>!1,onCheckAll:()=>!1,onUncheckAll:()=>!1,onFocus:()=>!1,onBlur:()=>!1,onOptgroupClick:()=>!1,onBeforeClick:()=>!0,onClick:()=>!1,onFilter:()=>!1,onClear:()=>!1,onAfterCreate:()=>!1,onDestroy:()=>!1,onAfterDestroy:()=>!1,onDestroyed:()=>!1},lt=["init","getOptions","refreshOptions","getSelects","setSelects","enable","disable","open","close","check","uncheck","checkAll","uncheckAll","checkInvert","focus","blur","refresh","destroy"];Object.assign(F,H["en-US"]);var ot={BLOCK_ROWS:it,CLUSTER_BLOCKS:st,DEFAULTS:F,METHODS:lt},u=ot;function q(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 T(o){let t=()=>{let l={};for(let s in o)Object.prototype.hasOwnProperty.call(o,s)&&(l[s]=T(o[s]));return l},e=()=>o.map(l=>T(l)),i=Object.prototype.toString.call(o).slice(8,-1).toLowerCase();return i==="object"?t():i==="array"?e():o}function _(o){return o!=null&&o!==""}function K(o,t){return typeof o=="object"?Object.fromEntries(t?Object.entries(o).filter(([e,i])=>!_(i)&&!t.includes(e)||_(i)):Object.entries(o).filter(([e,i])=>_(i))):o}function U(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 g(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 z(o){return o.replace(/(\b)(on[a-z]+)(\s*)=([^>]*)|javascript:([^>]*)[^>]*|(<\s*)(\/*)script([<>]*).*(<\s*)(\/*)script(>*)|(<|<)(\/*)(script|script defer)(.*)(>|>|>">)/gi,"")}function O(o){return Object.keys(o).forEach(t=>o[t]===void 0?delete o[t]:""),o}function V(o){return o.replace(/[\W_]+(.)/g,(t,e)=>e.toUpperCase())}function f(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 I(o){let t={};if(o){let e=o.replace(/\s/g,"").split(";");for(let i of e){let[l,s]=i.trim().split(":");l&&(t[V(l)]=s.trim())}console.warn("[multiple-select-vanilla] Please note that `styler` is deprecated, please migrate to `cssStyler` when possible.")}return t}function x(o){let t=0,e=0,i=0,l=0,s=window.innerHeight??0,n=window.innerWidth??0,a=rt(),h=a.top,c=a.left,p=k(o);if(p){let m=p.top??0,E=p.left??0;e=m-h,t=s-(m-h),i=E-c,l=n-(E-c)}return{top:e,bottom:t,left:i,right:l}}function d(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&&e.appendChild(i),i}function X(o,t,e){let i=o.props?.innerHTML?nt(o.props,"innerHTML"):o.props,l=d(o.tagName,K(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)X(n,l,s);return t?.appendChild(l),l}function b(o){return o.hasOwnProperty("tagName")?X(o):document.createElement("li")}function y(o){for(;o?.firstChild;)o.lastChild&&o.removeChild(o.lastChild);return o}function k(o){if(!o)return;let t=o?.getBoundingClientRect?.(),e=0,i=0,l=0,s=0;return t?.top!==void 0&&t.left!==void 0&&(e=t.top+window.pageYOffset,i=t.left+window.pageXOffset,s=t.right,l=t.bottom),{top:e,left:i,bottom:l,right:s}}function S(o,t,e){let i=parseFloat(o.style[e]);if(!i||Number.isNaN(i)){switch(t){case"outer":i=o[e==="width"?"offsetWidth":"offsetHeight"];break;case"scroll":i=o[e==="width"?"scrollWidth":"scrollHeight"];break;case"inner":default:i=o[e==="width"?"clientWidth":"clientHeight"];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";let n=window.getComputedStyle(o)[e];i=parseFloat(n),Number.isNaN(i)&&(i=0),o.style.display=l,o.style.position=s}return i||0}function N(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 h of a.replace(n,"").split(" "))i.classList.contains(h)&&(s?i?.tagName.toLowerCase()===s&&(e=i):e=i);i=i.parentElement}return e}function Y(o,t){o.parentNode?.insertBefore(t,o.nextSibling)}function nt(o,t){let{[t]:e,...i}=o;return i}function R(o,t){o?.style&&(o.style.display=o.style.display==="none"&&t!==!1||t===!0?"block":"none")}function gt(o,t){if(o?.classList){let i=t===!0||!o.classList.contains("selected")?"add":"remove";o.classList[i]("selected")}}function rt(){return{left:window.pageXOffset||document.documentElement.scrollLeft||0,top:window.pageYOffset||document.documentElement.scrollTop||0}}var M=class{constructor(t){r(this,"cache");r(this,"clusterRows");r(this,"dataStart");r(this,"dataEnd");r(this,"rows");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,"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),y(this.contentEl)}}initDOM(t){if(typeof this.clusterHeight>"u"){this.cache.scrollTop=this.scrollEl.scrollTop;let n=b(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);y(this.contentEl),i&&l?(e.topOffset&&this.contentEl.appendChild(this.getExtra("top",e.topOffset)),e.rows.forEach(n=>this.contentEl.appendChild(b(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=[],h=i;s<1&&h++;for(let c=i;c<l;c++)t[c]&&a.push(t[c]);return this.dataStart=i,this.dataEnd=l,{topOffset:s,bottomOffset:n,rowsAbove:h,rows:a}}checkChanges(t,e){let i=e!==this.cache[t];return this.cache[t]=e,i}getExtra(t,e){let i=document.createElement("li");return i.className=`virtual-scroll-${t}`,e&&(i.style.height=`${e}px`),i}};var v=".ms-select-all, ul[role=combobox] li[role=option]",at=".ms-select-all.highlighted, ul[role=combobox] li[role=option].highlighted",D=class{constructor(t,e){this.elm=t;r(this,"_bindEventService");r(this,"allSelected",!1);r(this,"fromHtml",!1);r(this,"choiceElm");r(this,"closeElm");r(this,"closeSearchElm");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,"ulElm");r(this,"parentElm");r(this,"labelElm");r(this,"selectAllParentElm");r(this,"selectAllElm");r(this,"searchInputElm");r(this,"selectGroupElms");r(this,"selectItemElms");r(this,"noResultsElm");r(this,"options");r(this,"selectAllName","");r(this,"selectGroupName","");r(this,"selectItemName","");r(this,"openDelayTimer");r(this,"updateDataStart");r(this,"updateDataEnd");r(this,"virtualScroll");r(this,"_currentHighlightIndex",-1);r(this,"_currentSelectedElm");r(this,"isMoveUpRecalcRequired",!1);r(this,"locales",{});this.options=Object.assign({},u.DEFAULTS,this.elm.dataset,e),this._bindEventService=new L({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.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=document.createElement("label"),this.labelElm.htmlFor=this.elm.id),this.labelElm?.querySelector("input")&&(this.labelElm=null),typeof this.options.single>"u"&&(this.options.single=!this.elm.multiple),this.parentElm=d("div",{className:`ms-parent ${this.elm.className||""} ${this.options.classes}`,dataset:{test:"sel"}});let e=this.elm.getAttribute("title")||"";e&&(this.parentElm.title=e),this.options.placeholder=this.options.placeholder||this.elm.getAttribute("placeholder")||"",this.choiceElm=d("button",{className:"ms-choice",type:"button"},this.parentElm),this.choiceElm.appendChild(d("span",{className:"ms-placeholder",textContent:this.options.placeholder})),this.options.showClear&&this.choiceElm.appendChild(d("div",{className:"icon-close"})),this.choiceElm.appendChild(d("div",{className:"icon-caret"})),this.dropElm=d("div",{className:`ms-drop ${this.options.position}`,ariaExpanded:"false"},this.parentElm),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(".icon-close"),this.options.dropWidth&&(this.dropElm.style.width=typeof this.options.dropWidth=="string"?this.options.dropWidth:`${this.options.dropWidth}px`),Y(this.elm,this.parentElm),this.elm.disabled&&this.choiceElm.classList.add("disabled"),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",l=>{l.target===this.choiceElm||N(l.target,".ms-choice")===this.choiceElm||(l.target===this.dropElm||N(l.target,".ms-drop")!==this.dropElm&&l.target!==this.elm)&&this.options.isOpen&&this.close()},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.dataTotal=U(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.update(!0),this.options.isOpen&&this.open(10),this.options.openOnHover&&this.parentElm&&(this._bindEventService.bind(this.parentElm,"mouseover",()=>this.open(null)),this._bindEventService.bind(this.parentElm,"mouseout",()=>this.close()))}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(){if(this.options.filter&&(this.filterParentElm=d("div",{className:"ms-search"},this.dropElm),this.filterParentElm.appendChild(d("input",{autocomplete:"off",autocapitalize:"off",spellcheck:!1,type:"text",placeholder:this.options.filterPlaceholder||"\u{1F50E}\uFE0E"})),this.options.showSearchClear&&this.filterParentElm.appendChild(d("span",{className:"icon-close"}))),this.options.selectAll&&!this.options.single){let t=this.elm.getAttribute("name")||this.options.name||"";this.selectAllParentElm=d("div",{className:"ms-select-all",dataset:{key:"select_all"}});let e=document.createElement("label");d("input",{type:"checkbox",ariaChecked:String(this.allSelected),checked:this.allSelected,dataset:{name:`selectAll${t}`}},e),e.appendChild(d("span",{textContent:this.formatSelectAll()})),this.selectAllParentElm.appendChild(e),this.dropElm.appendChild(this.selectAllParentElm)}this.ulElm=document.createElement("ul"),this.ulElm.role="combobox",this.ulElm.ariaExpanded="false",this.ulElm.ariaMultiSelectable=String(!this.options.single),this.dropElm.appendChild(this.ulElm),this.options.showOkButton&&!this.options.single&&(this.okButtonElm=d("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),this.options.virtualScroll&&e.length>u.BLOCK_ROWS*u.CLUSTER_BLOCKS){this.virtualScroll?.destroy();let i=this.dropElm.style.display!=="none";i||(this.dropElm.style.left="-10000",this.dropElm.style.display="block",this.dropElm.ariaExpanded="true");let l=()=>{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),this.updateDataEnd>this.getDataLength()&&(this.updateDataEnd=this.getDataLength()),this.ulElm&&(this.isMoveUpRecalcRequired?this.recalculateArrowMove("up"):this.virtualScroll.dataStart>this.updateDataStart&&this.recalculateArrowMove("down")))};this.ulElm&&(this.virtualScroll=new M({rows:e,scrollEl:this.ulElm,contentEl:this.ulElm,sanitizer:this.options.sanitizer,callback:()=>{l(),this.events()}})),l(),i||(this.dropElm.style.left="0",this.dropElm.style.display="none",this.dropElm.ariaExpanded="false")}else this.ulElm&&(y(this.ulElm),e.forEach(i=>this.ulElm.appendChild(b(i)))),this.updateDataStart=0,this.updateDataEnd=this.updateData.length,this.virtualScroll=null;return this.events(),e}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",dataset:{key:"infinite"}}}),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="";if(!t?.visible)return[];if(this.updateData.push(t),this.options.single&&!this.options.singleRadio&&(n="hide-radio "),t.selected&&(n+="selected "),t.type==="optgroup"){let C=[],J=this.options.hideOptgroupCheckboxes||this.options.single?{tagName:"span",props:{dataset:{name:this.selectGroupName,key:t._key}}}:{tagName:"input",props:{type:"checkbox",dataset:{name:this.selectGroupName,key:t._key},checked:!!t.selected,disabled:t.disabled}};!n.includes("hide-radio")&&(this.options.hideOptgroupCheckboxes||this.options.single)&&(n+="hide-radio ");let W={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(W.props,t.label);let A={tagName:"li",props:{className:`group${this.options.single||t.disabled?" disabled":""} ${n}`.trim(),role:"option",ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:`optgroup${this.options.single||t.disabled?" disabled":""}`},children:[J,W]}]},$=this.options.cssStyler(t),j=String(this.options.styler(t)||"");return j&&(A.props.style=I(j)),$&&(A.props.style=$),C.push(A),t.children.forEach(Q=>C.push(...this.initListItem(Q,1))),C}if(n+=t.classes||"",e&&this.options.single&&(n+=`option-level-${e} `),t.divider)return[{tagName:"li",props:{className:"option-divider"}}];let a=l||n?(l+n).trim():"";t.disabled&&(a+=" disabled");let h=`${t.disabled?"disabled":""}`,c={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(c.props,t.text);let p={tagName:"input",props:{type:s,value:encodeURI(t.value),dataset:{key:t._key,name:this.selectItemName},checked:!!t.selected,disabled:!!t.disabled}};t.selected&&(p.attrs={checked:"checked"});let m={tagName:"li",props:{className:a,role:"option",title:i,ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:h},children:[p,c]}]},E=this.options.cssStyler(t),B=String(this.options.styler(t)||"");return B&&(m.props.style=I(B)),E&&(m.props.style=E),[m]}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;this.allSelected=this.data?.filter(i=>i.selected&&!i.disabled&&i.visible).length===this.data?.filter(i=>!i.disabled&&i.visible&&!i.divider).length,t||(this.allSelected?this.options.onCheckAll():e===0&&this.options.onUncheckAll())}initView(){let t;window.getComputedStyle?(t=window.getComputedStyle(this.elm).width,t==="auto"&&(t=S(this.dropElm,"outer","width")+20)):t=S(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.closeSearchElm=this.filterParentElm?.querySelector(".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.selectItemElms=this.dropElm.querySelectorAll(`input[data-name="${this.selectItemName}"]:enabled`),this.noResultsElm=this.dropElm.querySelector(".ms-no-results");let t=e=>{e.preventDefault(),!e.target.classList.contains("icon-close")&&this[this.options.isOpen?"close":"open"]()};this.labelElm&&this._bindEventService.bind(this.labelElm,"click",e=>{e.target.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.options.keepOpen&&(this.close(),this.choiceElm.focus())}),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.closeSearchElm&&this._bindEventService.bind(this.closeSearchElm,"click",e=>{e.preventDefault(),this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter()}),this.searchInputElm&&(this._bindEventService.bind(this.searchInputElm,"keydown",e=>{e.code==="Tab"&&e.shiftKey&&this.close()},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.selectItemElms?.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(),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._bindEventService.bind(this.selectGroupElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key);this._checkGroup(s,l),this.options.onOptgroupClick(O({label:s.label,selected:s.selected,data:s._data,children:s.children.map(n=>{if(n)return O({text:n.text,value:n.value,selected:n.selected,disabled:n.disabled,data:n._data})})}))},void 0,"group-checkbox-list"),this._bindEventService.bind(this.selectItemElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key),n=()=>{this.options.single&&this.options.isOpen&&!this.options.keepOpen&&this.close()};if(this.options.onBeforeClick(s)===!1){n();return}this._check(s,l),this.options.onClick(O({text:s.text,value:s.value,selected:s.selected,data:s._data})),n()},void 0,"input-checkbox-list"),this.lastFocusedItemKey&&this.dropElm.querySelector(`li[data-key=${this.lastFocusedItemKey}]`)?.focus(),this._bindEventService.bind(this.dropElm,"mouseover",e=>{let i=e.target.closest(".ms-select-all")||e.target.closest("li");if(this.dropElm.contains(i)){let l=this.dropElm?.querySelectorAll(v)||[],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))}},void 0,"hover-highlight"),this._bindEventService.bind(this.dropElm,"keydown",e=>{switch(e.key){case"ArrowUp":e.preventDefault(),this.moveFocusUp();break;case"ArrowDown":e.preventDefault(),this.moveFocusDown();break;case"Enter":case" ":{let i=e.target.closest(".ms-select-all")||e.target.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}}},void 0,"arrow-highlight"),this.ulElm&&this.options.infiniteScroll&&this._bindEventService.bind(this.ulElm,"scroll",this.infiniteScrollHandler.bind(this),void 0,"option-list-scroll")}infiniteScrollHandler(t){t.target&&this.ulElm&&t.target.scrollTop+t.target.clientHeight===this.ulElm.scrollHeight&&(this.virtualScroll?this.initListItems():this.ulElm.scrollTop=0,this._currentHighlightIndex=0,this.highlightCurrentOption())}open(t=0){t!==null&&t>=0?(clearTimeout(this.openDelayTimer),this.openDelayTimer=setTimeout(()=>this.openDrop(),t)):this.openDrop()}openDrop(){if(this.choiceElm?.classList.contains("disabled"))return;if(this.options.isOpen=!0,this.parentElm.classList.add("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.add("open"),this.dropElm.style.display="block",this.dropElm.ariaExpanded="true",this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="block"),this.noResultsElm&&(this.noResultsElm.style.display="none"),this.getDataLength()||(this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="none"),this.noResultsElm&&(this.noResultsElm.style.display="block")),this.options.container){let s=k(this.dropElm),n;this.options.container instanceof Node?n=this.options.container:typeof this.options.container=="string"&&(n=this.options.container==="body"?document.body:document.querySelector(this.options.container)),n.appendChild(this.dropElm),this.dropElm.style.top=`${s?.top??0}px`,this.dropElm.style.left=`${s?.left??0}px`,this.dropElm.style.minWidth="auto",this.dropElm.style.width=`${S(this.parentElm,"outer","width")}px`}let t=this.options.minHeight,e=this.options.maxHeight;this.options.maxHeightUnit==="row"&&(e=S(this.dropElm.querySelector("ul>li"),"outer","height")*this.options.maxHeight);let i=this.dropElm.querySelector("ul");i&&(t&&(i.style.minHeight=`${t}px`),i.style.maxHeight=`${e}px`),this.dropElm.querySelectorAll(".multiple").forEach(s=>{s.style.width=`${this.options.multipleWidth}px`}),this.getDataLength()&&this.options.filter?(this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter(!0)):this.selectAllElm?this.selectAllElm.focus():i&&(i.tabIndex=0,i.focus()),this.moveFocusDown(),this.options.autoAdjustDropWidthByTextSize&&this.adjustDropWidthByText();let l=this.options.position;if(this.options.autoAdjustDropHeight){if(this.options.autoAdjustDropPosition){let{bottom:s,top:n}=x(this.dropElm),a=this.dropElm.getBoundingClientRect().height;l=s<a&&n>s?"top":"bottom"}this.adjustDropHeight(l)}this.options.autoAdjustDropPosition&&this.adjustDropPosition(!0),this.options.onOpen()}highlightCurrentOption(){let t=this.dropElm?.querySelectorAll(v)||[];if(this._currentHighlightIndex<=t.length){let e=t[this._currentHighlightIndex];e&&(this.lastFocusedItemKey=e.dataset.key||"",this._currentSelectedElm=e,e.scrollIntoView({block:"nearest"}),this.changeCurrentOptionHighlight(e))}}changeCurrentOptionHighlight(t){t.classList.add("highlighted"),(this.dropElm?.querySelectorAll(at)||[]).forEach(i=>{i!==t&&i.classList.remove("highlighted")})}moveFocusDown(){let t=this.dropElm?.querySelectorAll(v)||[];this._currentHighlightIndex<t.length-1&&(this._currentHighlightIndex++,t[this._currentHighlightIndex]?.classList.contains("disabled")&&this.moveFocusDown()),this.highlightCurrentOption()}moveFocusUp(){let t=this.dropElm?.querySelectorAll(v)||[],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.moveFocusUp()),this.highlightCurrentOption()}recalculateArrowMove(t){let e=this.dropElm?.querySelectorAll(v)||[],i=Array.from(e).findIndex(l=>l.dataset.key===this.lastFocusedItemKey);this._currentHighlightIndex=i-1,t==="down"?this.moveFocusDown():t==="up"&&(this.moveFocusUp(),this.isMoveUpRecalcRequired=!1)}close(){this.options.isOpen=!1,this.parentElm.classList.remove("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.remove("open"),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()}applyAsTextOrHtmlWhenEnabled(t,e){t||(t={}),this.isRenderAsHtml?t.innerHTML=typeof this.options.sanitizer=="function"?this.options.sanitizer(e):e:t.textContent=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 c=e.join(this.options.displayDelimiter);return this.options.useSelectOptionLabelToHtml?z(c):c}return i.join(this.options.displayDelimiter)};if(l){if(s===0){let c=this.options.placeholder||"";l.classList.add("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,c)}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.displayTitle||this.options.addTitle){this.options.addTitle&&console.warn("[Multiple-Select-Vanilla] Please note that the `addTitle` option was deprecated and replaced by `displayTitle`.");let c=this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml?"value":"text";l.title=this.getSelects(c).join(this.options.displayDelimiter)}}let h=this.getSelects();this.options.single?this.elm.value=h.length?h[0]:"":Array.from(this.elm.options).forEach(c=>{c.selected=h.some(p=>p===c.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");n&&(l.selected&&!n.classList.contains("selected")?(n.classList.add("selected"),n.ariaSelected="true"):l.selected||(n.classList.remove("selected"),n.ariaSelected="false"))}}let e=this.data?.filter(i=>i.visible).length===0;this.selectAllElm&&(this.selectAllElm.ariaChecked=String(this.allSelected),this.selectAllElm.checked=this.allSelected,R(this.selectAllElm.closest("li"),!e)),R(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?T(e):this.options}refreshOptions(t){q(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 h=!1;if(e==="text"){let c=document.createElement("div");this.applyAsTextOrHtmlWhenEnabled(c,a.text),h=t.includes(c.textContent?.trim()??"")}else h=t.includes(a._value||a.value),!h&&a.value===`${+a.value}`&&(h=t.includes(+a.value));a.selected!==h&&(l=!0),a.selected=h}};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?.classList.remove("disabled")}disable(){this.choiceElm?.classList.add("disabled")}check(t){let e=g(this.data,"value",t);e&&this._check(e,!0)}uncheck(t){let e=g(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:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalLabel:n,originalSearch:e,row:s});s.visible=a;for(let h of s.children)h&&(h.visible=a)}}else{for(let n of s.children)if(n!=null){let a=`${n?.text??""}`;n.visible=this.options.customFilter({text:f(a.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalText:a,originalSearch:e,row:n,parent:s})}s.visible=s.children.filter(n=>n?.visible).length>0}else{let n=`${s?.text??""}`;s.visible=this.options.customFilter({text:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(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:h}=x(this.parentElm),c=this.options.maxHeight;if(e?c=a-n-this.options.adjustedHeightPadding:c=h-n-this.options.adjustedHeightPadding,!this.options.maxHeight||this.options.maxHeight&&c<this.options.maxHeight){let p=this.dropElm?.querySelector("ul");return p&&(p.style.maxHeight=`${c}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}=k(this.parentElm),a=this.dropElm.getBoundingClientRect().height,h=this.dropElm.getBoundingClientRect().width,c=document.body.offsetWidth||window.innerWidth,p=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")}c-h<n&&(this.dropElm.style.left=`${n-(h-p)}px`)}return e}adjustDropWidthByText(){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"),s=26,n=i?.clientWidth??0+s,h=l.scrollHeight>l.clientHeight?this.getScrollbarWidth():0,c=0;this.dropElm.querySelectorAll("li label").forEach(p=>{p.scrollWidth>c&&(c=p.scrollWidth)}),c+=s+h,c<n&&(c=n),this.options.maxWidth&&c>this.options.maxWidth&&(c=this.options.maxWidth),this.options.minWidth&&c<this.options.minWidth&&(c=this.options.minWidth),(e==="100%"||+e<c)&&(this.dropElm.style.width=`${c}px`,this.dropElm.style.maxWidth=`${c}px`)}getScrollbarWidth(){let t=document.createElement("div");t.style.visibility="hidden",t.style.width="100px",document.body.appendChild(t);let e=t.offsetWidth;t.style.overflow="scroll";let i=document.createElement("div");i.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()}formatSelectAll(){return this.options.selectAllText||this.options.formatSelectAll()}};var w=(o,t)=>typeof o=="string"?P(document.querySelectorAll(o),t):o instanceof Node?P([o],t):P(o,t);function P(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 D(s,t||{}),s._multipleSelect.init();let n=s._multipleSelect.getOptions(!1);n.onHardDestroy=()=>delete s._multipleSelect,n.onAfterHardDestroyed=()=>i[l]=null,i.push(s._multipleSelect)}catch(n){console.error(n)}}return i.length===1?i[0]:i}w.defaults=u.DEFAULTS;w.locales={...H};w.methods=u.METHODS;typeof window<"u"&&(window.multipleSelect=w);export{L as BindingEventService,D as MultipleSelectInstance,M as VirtualScroll,x as calculateAvailableSpace,q as compareObjects,b as convertItemRowToHtml,I as convertStringStyleToElementStyle,d as createDomElement,X as createDomStructure,T as deepCopy,y as emptyElement,g as findByParam,N as findParent,k as getElementOffset,S as getElementSize,Y as insertAfter,_ as isDefined,w as multipleSelect,K as objectRemoveEmptyProps,nt as omitProp,f as removeDiacritics,O as removeUndefined,U as setDataKeys,z as stripScripts,V as toCamelCase,R as toggleElement,gt as toggleElementClass,rt as windowScrollPosition}; | ||
var Z=Object.defineProperty;var tt=(o,t,e)=>t in o?Z(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>(tt(o,typeof t!="symbol"?t+"":t,e),e);var L=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];if(typeof t?.forEach=="function")t.forEach(a=>{for(let h of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(a,h))&&(a.addEventListener(h,i,l),this._boundedEvents.push({element:a,eventName:h,listener:i,groupName:s}))});else for(let a of n)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(t,a))&&(t.addEventListener(a,i,l),this._boundedEvents.push({element:t,eventName:a,listener:i,groupName: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 e=this._boundedEvents.pop(),{element:i,eventName:l,listener:s}=e;this.unbind(i,l,s)}}};var G=typeof window<"u"&&window.multipleSelect!==void 0?window.multipleSelect:{locales:{}},et={formatSelectAll(){return"[Select all]"},formatAllSelected(){return"All selected"},formatCountSelected(o,t){return`${o} of ${t} selected`},formatNoMatchesFound(){return"No matches found"},formatOkButton(){return"OK"}};G.locales["en-US"]=et;var H=G.locales;var it=50,st=4,F={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,infiniteScroll:!1,virtualScroll:!0,cssStyler:()=>null,styler:()=>!1,textTemplate:o=>o.innerHTML.trim(),labelTemplate:o=>o.label,onOpen:()=>!1,onClose:()=>!1,onCheckAll:()=>!1,onUncheckAll:()=>!1,onFocus:()=>!1,onBlur:()=>!1,onOptgroupClick:()=>!1,onBeforeClick:()=>!0,onClick:()=>!1,onFilter:()=>!1,onClear:()=>!1,onAfterCreate:()=>!1,onDestroy:()=>!1,onAfterDestroy:()=>!1,onDestroyed:()=>!1},lt=["init","getOptions","refreshOptions","getSelects","setSelects","enable","disable","open","close","check","uncheck","checkAll","uncheckAll","checkInvert","focus","blur","refresh","destroy"];Object.assign(F,H["en-US"]);var ot={BLOCK_ROWS:it,CLUSTER_BLOCKS:st,DEFAULTS:F,METHODS:lt},u=ot;function q(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 T(o){let t=()=>{let l={};for(let s in o)Object.prototype.hasOwnProperty.call(o,s)&&(l[s]=T(o[s]));return l},e=()=>o.map(l=>T(l)),i=Object.prototype.toString.call(o).slice(8,-1).toLowerCase();return i==="object"?t():i==="array"?e():o}function _(o){return o!=null&&o!==""}function K(o,t){return typeof o=="object"?Object.fromEntries(t?Object.entries(o).filter(([e,i])=>!_(i)&&!t.includes(e)||_(i)):Object.entries(o).filter(([e,i])=>_(i))):o}function U(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 g(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 z(o){return o.replace(/(\b)(on[a-z]+)(\s*)=([^>]*)|javascript:([^>]*)[^>]*|(<\s*)(\/*)script([<>]*).*(<\s*)(\/*)script(>*)|(<|<)(\/*)(script|script defer)(.*)(>|>|>">)/gi,"")}function O(o){return Object.keys(o).forEach(t=>o[t]===void 0?delete o[t]:""),o}function V(o){return o.replace(/[\W_]+(.)/g,(t,e)=>e.toUpperCase())}function f(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 I(o){let t={};if(o){let e=o.replace(/\s/g,"").split(";");for(let i of e){let[l,s]=i.trim().split(":");l&&(t[V(l)]=s.trim())}console.warn("[multiple-select-vanilla] Please note that `styler` is deprecated, please migrate to `cssStyler` when possible.")}return t}function x(o){let t=0,e=0,i=0,l=0,s=window.innerHeight??0,n=window.innerWidth??0,a=rt(),h=a.top,c=a.left,p=k(o);if(p){let m=p.top??0,E=p.left??0;e=m-h,t=s-(m-h),i=E-c,l=n-(E-c)}return{top:e,bottom:t,left:i,right:l}}function d(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&&e.appendChild(i),i}function X(o,t,e){let i=o.props?.innerHTML?nt(o.props,"innerHTML"):o.props,l=d(o.tagName,K(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)X(n,l,s);return t?.appendChild(l),l}function b(o){return o.hasOwnProperty("tagName")?X(o):document.createElement("li")}function y(o){for(;o?.firstChild;)o.lastChild&&o.removeChild(o.lastChild);return o}function k(o){if(!o)return;let t=o?.getBoundingClientRect?.(),e=0,i=0,l=0,s=0;return t?.top!==void 0&&t.left!==void 0&&(e=t.top+window.pageYOffset,i=t.left+window.pageXOffset,s=t.right,l=t.bottom),{top:e,left:i,bottom:l,right:s}}function S(o,t,e){let i=parseFloat(o.style[e]);if(!i||Number.isNaN(i)){switch(t){case"outer":i=o[e==="width"?"offsetWidth":"offsetHeight"];break;case"scroll":i=o[e==="width"?"scrollWidth":"scrollHeight"];break;case"inner":default:i=o[e==="width"?"clientWidth":"clientHeight"];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";let n=window.getComputedStyle(o)[e];i=parseFloat(n),Number.isNaN(i)&&(i=0),o.style.display=l,o.style.position=s}return i||0}function N(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 h of a.replace(n,"").split(" "))i.classList.contains(h)&&(s?i?.tagName.toLowerCase()===s&&(e=i):e=i);i=i.parentElement}return e}function Y(o,t){o.parentNode?.insertBefore(t,o.nextSibling)}function nt(o,t){let{[t]:e,...i}=o;return i}function R(o,t){o?.style&&(o.style.display=o.style.display==="none"&&t!==!1||t===!0?"block":"none")}function gt(o,t){if(o?.classList){let i=t===!0||!o.classList.contains("selected")?"add":"remove";o.classList[i]("selected")}}function rt(){return{left:window.pageXOffset||document.documentElement.scrollLeft||0,top:window.pageYOffset||document.documentElement.scrollTop||0}}var M=class{constructor(t){r(this,"cache");r(this,"clusterRows");r(this,"dataStart");r(this,"dataEnd");r(this,"rows");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,"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),y(this.contentEl)}}initDOM(t){if(typeof this.clusterHeight>"u"){this.cache.scrollTop=this.scrollEl.scrollTop;let n=b(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);y(this.contentEl),i&&l?(e.topOffset&&this.contentEl.appendChild(this.getExtra("top",e.topOffset)),e.rows.forEach(n=>this.contentEl.appendChild(b(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=[],h=i;s<1&&h++;for(let c=i;c<l;c++)t[c]&&a.push(t[c]);return this.dataStart=i,this.dataEnd=l,{topOffset:s,bottomOffset:n,rowsAbove:h,rows:a}}checkChanges(t,e){let i=e!==this.cache[t];return this.cache[t]=e,i}getExtra(t,e){let i=document.createElement("li");return i.className=`virtual-scroll-${t}`,e&&(i.style.height=`${e}px`),i}};var v=".ms-select-all, ul[role=combobox] li[role=option]",at=".ms-select-all.highlighted, ul[role=combobox] li[role=option].highlighted",D=class{constructor(t,e){this.elm=t;r(this,"_bindEventService");r(this,"allSelected",!1);r(this,"fromHtml",!1);r(this,"choiceElm");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,"ulElm");r(this,"parentElm");r(this,"labelElm");r(this,"selectAllParentElm");r(this,"selectAllElm");r(this,"searchInputElm");r(this,"selectGroupElms");r(this,"selectItemElms");r(this,"noResultsElm");r(this,"options");r(this,"selectAllName","");r(this,"selectGroupName","");r(this,"selectItemName","");r(this,"openDelayTimer");r(this,"updateDataStart");r(this,"updateDataEnd");r(this,"virtualScroll");r(this,"_currentHighlightIndex",-1);r(this,"_currentSelectedElm");r(this,"isMoveUpRecalcRequired",!1);r(this,"locales",{});this.options=Object.assign({},u.DEFAULTS,this.elm.dataset,e),this._bindEventService=new L({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.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=document.createElement("label"),this.labelElm.htmlFor=this.elm.id),this.labelElm?.querySelector("input")&&(this.labelElm=null),typeof this.options.single>"u"&&(this.options.single=!this.elm.multiple),this.parentElm=d("div",{className:`ms-parent ${this.elm.className||""} ${this.options.classes}`,dataset:{test:"sel"}});let e=this.elm.getAttribute("title")||"";e&&(this.parentElm.title=e),this.options.placeholder=this.options.placeholder||this.elm.getAttribute("placeholder")||"",this.choiceElm=d("button",{className:"ms-choice",type:"button"},this.parentElm),this.choiceElm.appendChild(d("span",{className:"ms-placeholder",textContent:this.options.placeholder})),this.options.showClear&&this.choiceElm.appendChild(d("div",{className:"icon-close"})),this.choiceElm.appendChild(d("div",{className:"icon-caret"})),this.dropElm=d("div",{className:`ms-drop ${this.options.position}`,ariaExpanded:"false"},this.parentElm),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(".icon-close"),this.options.dropWidth&&(this.dropElm.style.width=typeof this.options.dropWidth=="string"?this.options.dropWidth:`${this.options.dropWidth}px`),Y(this.elm,this.parentElm),this.elm.disabled&&this.choiceElm.classList.add("disabled"),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",l=>{l.target===this.choiceElm||N(l.target,".ms-choice")===this.choiceElm||(l.target===this.dropElm||N(l.target,".ms-drop")!==this.dropElm&&l.target!==this.elm)&&this.options.isOpen&&this.close()},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.dataTotal=U(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.update(!0),this.options.isOpen&&this.open(10),this.options.openOnHover&&this.parentElm&&(this._bindEventService.bind(this.parentElm,"mouseover",()=>this.open(null)),this._bindEventService.bind(this.parentElm,"mouseout",()=>this.close()))}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(){if(this.options.filter&&(this.filterParentElm=d("div",{className:"ms-search"},this.dropElm),this.filterParentElm.appendChild(d("input",{autocomplete:"off",autocapitalize:"off",spellcheck:!1,type:"text",placeholder:this.options.filterPlaceholder||"\u{1F50E}\uFE0E"})),this.options.showSearchClear&&this.filterParentElm.appendChild(d("span",{className:"icon-close"}))),this.options.selectAll&&!this.options.single){let t=this.elm.getAttribute("name")||this.options.name||"";this.selectAllParentElm=d("div",{className:"ms-select-all",dataset:{key:"select_all"}});let e=document.createElement("label");d("input",{type:"checkbox",ariaChecked:String(this.allSelected),checked:this.allSelected,dataset:{name:`selectAll${t}`}},e),e.appendChild(d("span",{textContent:this.formatSelectAll()})),this.selectAllParentElm.appendChild(e),this.dropElm.appendChild(this.selectAllParentElm)}this.ulElm=document.createElement("ul"),this.ulElm.role="combobox",this.ulElm.ariaExpanded="false",this.ulElm.ariaMultiSelectable=String(!this.options.single),this.dropElm.appendChild(this.ulElm),this.options.showOkButton&&!this.options.single&&(this.okButtonElm=d("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),this.options.virtualScroll&&e.length>u.BLOCK_ROWS*u.CLUSTER_BLOCKS){this.virtualScroll?.destroy();let i=this.dropElm.style.display!=="none";i||(this.dropElm.style.left="-10000",this.dropElm.style.display="block",this.dropElm.ariaExpanded="true");let l=()=>{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),this.updateDataEnd>this.getDataLength()&&(this.updateDataEnd=this.getDataLength()),this.ulElm&&(this.isMoveUpRecalcRequired?this.recalculateArrowMove("up"):this.virtualScroll.dataStart>this.updateDataStart&&this.recalculateArrowMove("down")))};this.ulElm&&(this.virtualScroll=new M({rows:e,scrollEl:this.ulElm,contentEl:this.ulElm,sanitizer:this.options.sanitizer,callback:()=>{l(),this.events()}})),l(),i||(this.dropElm.style.left="0",this.dropElm.style.display="none",this.dropElm.ariaExpanded="false")}else this.ulElm&&(y(this.ulElm),e.forEach(i=>this.ulElm.appendChild(b(i)))),this.updateDataStart=0,this.updateDataEnd=this.updateData.length,this.virtualScroll=null;return this.events(),e}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",dataset:{key:"infinite"}}}),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="";if(!t?.visible)return[];if(this.updateData.push(t),this.options.single&&!this.options.singleRadio&&(n="hide-radio "),t.selected&&(n+="selected "),t.type==="optgroup"){let C=[],J=this.options.hideOptgroupCheckboxes||this.options.single?{tagName:"span",props:{dataset:{name:this.selectGroupName,key:t._key}}}:{tagName:"input",props:{type:"checkbox",dataset:{name:this.selectGroupName,key:t._key},checked:!!t.selected,disabled:t.disabled}};!n.includes("hide-radio")&&(this.options.hideOptgroupCheckboxes||this.options.single)&&(n+="hide-radio ");let W={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(W.props,t.label);let A={tagName:"li",props:{className:`group${this.options.single||t.disabled?" disabled":""} ${n}`.trim(),role:"option",ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:`optgroup${this.options.single||t.disabled?" disabled":""}`},children:[J,W]}]},$=this.options.cssStyler(t),j=String(this.options.styler(t)||"");return j&&(A.props.style=I(j)),$&&(A.props.style=$),C.push(A),t.children.forEach(Q=>C.push(...this.initListItem(Q,1))),C}if(n+=t.classes||"",e&&this.options.single&&(n+=`option-level-${e} `),t.divider)return[{tagName:"li",props:{className:"option-divider"}}];let a=l||n?(l+n).trim():"";t.disabled&&(a+=" disabled");let h=`${t.disabled?"disabled":""}`,c={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(c.props,t.text);let p={tagName:"input",props:{type:s,value:encodeURI(t.value),dataset:{key:t._key,name:this.selectItemName},checked:!!t.selected,disabled:!!t.disabled}};t.selected&&(p.attrs={checked:"checked"});let m={tagName:"li",props:{className:a,role:"option",title:i,ariaSelected:String(!!t.selected),dataset:{key:t._key}},children:[{tagName:"label",props:{className:h},children:[p,c]}]},E=this.options.cssStyler(t),B=String(this.options.styler(t)||"");return B&&(m.props.style=I(B)),E&&(m.props.style=E),[m]}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;this.allSelected=this.data?.filter(i=>i.selected&&!i.disabled&&i.visible).length===this.data?.filter(i=>!i.disabled&&i.visible&&!i.divider).length,t||(this.allSelected?this.options.onCheckAll():e===0&&this.options.onUncheckAll())}initView(){let t;window.getComputedStyle?(t=window.getComputedStyle(this.elm).width,t==="auto"&&(t=S(this.dropElm,"outer","width")+20)):t=S(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(".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.selectItemElms=this.dropElm.querySelectorAll(`input[data-name="${this.selectItemName}"]:enabled`),this.noResultsElm=this.dropElm.querySelector(".ms-no-results");let t=e=>{e.preventDefault(),!e.target.classList.contains("icon-close")&&this[this.options.isOpen?"close":"open"]()};this.labelElm&&this._bindEventService.bind(this.labelElm,"click",e=>{e.target.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.options.keepOpen&&(this.close(),this.choiceElm.focus())}),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.moveFocusDown(),this.filter()}),this.searchInputElm&&(this._bindEventService.bind(this.searchInputElm,"keydown",e=>{e.code==="Tab"&&e.shiftKey&&this.close()},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.selectItemElms?.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(),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._bindEventService.bind(this.selectGroupElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key);this._checkGroup(s,l),this.options.onOptgroupClick(O({label:s.label,selected:s.selected,data:s._data,children:s.children.map(n=>{if(n)return O({text:n.text,value:n.value,selected:n.selected,disabled:n.disabled,data:n._data})})}))},void 0,"group-checkbox-list"),this._bindEventService.bind(this.selectItemElms,"click",e=>{let i=e.currentTarget,l=i.checked,s=g(this.data,"_key",i.dataset.key),n=()=>{this.options.single&&this.options.isOpen&&!this.options.keepOpen&&this.close()};if(this.options.onBeforeClick(s)===!1){n();return}this._check(s,l),this.options.onClick(O({text:s.text,value:s.value,selected:s.selected,data:s._data})),n()},void 0,"input-checkbox-list"),this.lastFocusedItemKey&&this.dropElm.querySelector(`li[data-key=${this.lastFocusedItemKey}]`)?.focus(),this._bindEventService.bind(this.dropElm,"mouseover",e=>{let i=e.target.closest(".ms-select-all")||e.target.closest("li");if(this.dropElm.contains(i)){let l=this.dropElm?.querySelectorAll(v)||[],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))}},void 0,"hover-highlight"),this._bindEventService.bind(this.dropElm,"keydown",e=>{switch(e.key){case"ArrowUp":e.preventDefault(),this.moveFocusUp();break;case"ArrowDown":e.preventDefault(),this.moveFocusDown();break;case"Enter":case" ":{let i=e.target.closest(".ms-select-all")||e.target.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}}},void 0,"arrow-highlight"),this.ulElm&&this.options.infiniteScroll&&this._bindEventService.bind(this.ulElm,"scroll",this.infiniteScrollHandler.bind(this),void 0,"option-list-scroll")}infiniteScrollHandler(t){t.target&&this.ulElm&&t.target.scrollTop+t.target.clientHeight===this.ulElm.scrollHeight&&(this.virtualScroll?this.initListItems():this.ulElm.scrollTop=0,this._currentHighlightIndex=0,this.highlightCurrentOption())}open(t=0){t!==null&&t>=0?(clearTimeout(this.openDelayTimer),this.openDelayTimer=setTimeout(()=>this.openDrop(),t)):this.openDrop()}openDrop(){if(this.choiceElm?.classList.contains("disabled"))return;if(this.options.isOpen=!0,this.parentElm.classList.add("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.add("open"),this.dropElm.style.display="block",this.dropElm.ariaExpanded="true",this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="block"),this.noResultsElm&&(this.noResultsElm.style.display="none"),this.getDataLength()||(this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="none"),this.noResultsElm&&(this.noResultsElm.style.display="block")),this.options.container){let s=k(this.dropElm),n;this.options.container instanceof Node?n=this.options.container:typeof this.options.container=="string"&&(n=this.options.container==="body"?document.body:document.querySelector(this.options.container)),n.appendChild(this.dropElm),this.dropElm.style.top=`${s?.top??0}px`,this.dropElm.style.left=`${s?.left??0}px`,this.dropElm.style.minWidth="auto",this.dropElm.style.width=`${S(this.parentElm,"outer","width")}px`}let t=this.options.minHeight,e=this.options.maxHeight;this.options.maxHeightUnit==="row"&&(e=S(this.dropElm.querySelector("ul>li"),"outer","height")*this.options.maxHeight);let i=this.dropElm.querySelector("ul");i&&(t&&(i.style.minHeight=`${t}px`),i.style.maxHeight=`${e}px`),this.dropElm.querySelectorAll(".multiple").forEach(s=>{s.style.width=`${this.options.multipleWidth}px`}),this.getDataLength()&&this.options.filter?(this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter(!0)):this.selectAllElm?this.selectAllElm.focus():i&&(i.tabIndex=0,i.focus()),this._currentHighlightIndex<0?this.moveFocusDown():this.highlightCurrentOption(),this.options.autoAdjustDropWidthByTextSize&&this.adjustDropWidthByText();let l=this.options.position;if(this.options.autoAdjustDropHeight){if(this.options.autoAdjustDropPosition){let{bottom:s,top:n}=x(this.dropElm),a=this.dropElm.getBoundingClientRect().height;l=s<a&&n>s?"top":"bottom"}this.adjustDropHeight(l)}this.options.autoAdjustDropPosition&&this.adjustDropPosition(!0),this.options.onOpen()}highlightCurrentOption(){let t=this.dropElm?.querySelectorAll(v)||[];if(this._currentHighlightIndex<=t.length){let e=t[this._currentHighlightIndex];e&&(this.lastFocusedItemKey=e.dataset.key||"",this._currentSelectedElm=e,e.scrollIntoView({block:"nearest"}),this.changeCurrentOptionHighlight(e))}}changeCurrentOptionHighlight(t){t.classList.add("highlighted"),(this.dropElm?.querySelectorAll(at)||[]).forEach(i=>{i!==t&&i.classList.remove("highlighted")})}moveFocusDown(){let t=this.dropElm?.querySelectorAll(v)||[];this._currentHighlightIndex<t.length-1&&(this._currentHighlightIndex++,t[this._currentHighlightIndex]?.classList.contains("disabled")&&this.moveFocusDown()),this.highlightCurrentOption()}moveFocusUp(){let t=this.dropElm?.querySelectorAll(v)||[],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.moveFocusUp()),this.highlightCurrentOption()}recalculateArrowMove(t){let e=this.dropElm?.querySelectorAll(v)||[],i=Array.from(e).findIndex(l=>l.dataset.key===this.lastFocusedItemKey);this._currentHighlightIndex=i-1,t==="down"?this.moveFocusDown():t==="up"&&(this.moveFocusUp(),this.isMoveUpRecalcRequired=!1)}close(){this.options.isOpen=!1,this.parentElm.classList.remove("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.remove("open"),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()}applyAsTextOrHtmlWhenEnabled(t,e){t||(t={}),this.isRenderAsHtml?t.innerHTML=typeof this.options.sanitizer=="function"?this.options.sanitizer(e):e:t.textContent=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 c=e.join(this.options.displayDelimiter);return this.options.useSelectOptionLabelToHtml?z(c):c}return i.join(this.options.displayDelimiter)};if(l){if(s===0){let c=this.options.placeholder||"";l.classList.add("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,c)}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.displayTitle||this.options.addTitle){this.options.addTitle&&console.warn("[Multiple-Select-Vanilla] Please note that the `addTitle` option was deprecated and replaced by `displayTitle`.");let c=this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml?"value":"text";l.title=this.getSelects(c).join(this.options.displayDelimiter)}}let h=this.getSelects();this.options.single?this.elm.value=h.length?h[0]:"":Array.from(this.elm.options).forEach(c=>{c.selected=h.some(p=>p===c.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");n&&(l.selected&&!n.classList.contains("selected")?(n.classList.add("selected"),n.ariaSelected="true"):l.selected||(n.classList.remove("selected"),n.ariaSelected="false"))}}let e=this.data?.filter(i=>i.visible).length===0;this.selectAllElm&&(this.selectAllElm.ariaChecked=String(this.allSelected),this.selectAllElm.checked=this.allSelected,R(this.selectAllElm.closest("li"),!e)),R(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?T(e):this.options}refreshOptions(t){q(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 h=!1;if(e==="text"){let c=document.createElement("div");this.applyAsTextOrHtmlWhenEnabled(c,a.text),h=t.includes(c.textContent?.trim()??"")}else h=t.includes(a._value||a.value),!h&&a.value===`${+a.value}`&&(h=t.includes(+a.value));a.selected!==h&&(l=!0),a.selected=h}};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?.classList.remove("disabled")}disable(){this.choiceElm?.classList.add("disabled")}check(t){let e=g(this.data,"value",t);e&&this._check(e,!0)}uncheck(t){let e=g(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:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalLabel:n,originalSearch:e,row:s});s.visible=a;for(let h of s.children)h&&(h.visible=a)}}else{for(let n of s.children)if(n!=null){let a=`${n?.text??""}`;n.visible=this.options.customFilter({text:f(a.toString().toLowerCase(),this.options.diacriticParser),search:f(i,this.options.diacriticParser),originalText:a,originalSearch:e,row:n,parent:s})}s.visible=s.children.filter(n=>n?.visible).length>0}else{let n=`${s?.text??""}`;s.visible=this.options.customFilter({text:f(n.toString().toLowerCase(),this.options.diacriticParser),search:f(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:h}=x(this.parentElm),c=this.options.maxHeight;if(e?c=a-n-this.options.adjustedHeightPadding:c=h-n-this.options.adjustedHeightPadding,!this.options.maxHeight||this.options.maxHeight&&c<this.options.maxHeight){let p=this.dropElm?.querySelector("ul");return p&&(p.style.maxHeight=`${c}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}=k(this.parentElm),a=this.dropElm.getBoundingClientRect().height,h=this.dropElm.getBoundingClientRect().width,c=document.body.offsetWidth||window.innerWidth,p=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")}c-h<n&&(this.dropElm.style.left=`${n-(h-p)}px`)}return e}adjustDropWidthByText(){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"),s=26,n=i?.clientWidth??0+s,h=l.scrollHeight>l.clientHeight?this.getScrollbarWidth():0,c=0;this.dropElm.querySelectorAll("li label").forEach(p=>{p.scrollWidth>c&&(c=p.scrollWidth)}),c+=s+h,c<n&&(c=n),this.options.maxWidth&&c>this.options.maxWidth&&(c=this.options.maxWidth),this.options.minWidth&&c<this.options.minWidth&&(c=this.options.minWidth),(e==="100%"||+e<c)&&(this.dropElm.style.width=`${c}px`,this.dropElm.style.maxWidth=`${c}px`)}getScrollbarWidth(){let t=document.createElement("div");t.style.visibility="hidden",t.style.width="100px",document.body.appendChild(t);let e=t.offsetWidth;t.style.overflow="scroll";let i=document.createElement("div");i.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()}formatSelectAll(){return this.options.selectAllText||this.options.formatSelectAll()}};var w=(o,t)=>typeof o=="string"?P(document.querySelectorAll(o),t):o instanceof Node?P([o],t):P(o,t);function P(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 D(s,t||{}),s._multipleSelect.init();let n=s._multipleSelect.getOptions(!1);n.onHardDestroy=()=>delete s._multipleSelect,n.onAfterHardDestroyed=()=>i[l]=null,i.push(s._multipleSelect)}catch(n){console.error(n)}}return i.length===1?i[0]:i}w.defaults=u.DEFAULTS;w.locales={...H};w.methods=u.METHODS;typeof window<"u"&&(window.multipleSelect=w);export{L as BindingEventService,D as MultipleSelectInstance,M as VirtualScroll,x as calculateAvailableSpace,q as compareObjects,b as convertItemRowToHtml,I as convertStringStyleToElementStyle,d as createDomElement,X as createDomStructure,T as deepCopy,y as emptyElement,g as findByParam,N as findParent,k as getElementOffset,S as getElementSize,Y as insertAfter,_ as isDefined,w as multipleSelect,K as objectRemoveEmptyProps,nt as omitProp,f as removeDiacritics,O as removeUndefined,U as setDataKeys,z as stripScripts,V as toCamelCase,R as toggleElement,gt as toggleElementClass,rt as windowScrollPosition}; | ||
//# sourceMappingURL=multiple-select.js.map |
@@ -12,3 +12,3 @@ /// <reference types="node" /> | ||
protected closeElm?: HTMLElement | null; | ||
protected closeSearchElm?: HTMLElement | null; | ||
protected clearSearchIconElm?: HTMLElement | null; | ||
protected filterText: string; | ||
@@ -15,0 +15,0 @@ protected updateData: any[]; |
{ | ||
"name": "multiple-select-vanilla", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"main": "./dist/multiple-select.cjs", | ||
@@ -11,4 +11,4 @@ "module": "./dist/multiple-select.js", | ||
"node": "./dist/multiple-select.cjs", | ||
"require": "./dist/multiple-select.cjs", | ||
"default": "./dist/multiple-select.js" | ||
"import": "./dist/multiple-select.js", | ||
"require": "./dist/multiple-select.cjs" | ||
}, | ||
@@ -50,3 +50,3 @@ "./dist/browser/*": "./dist/browser/*", | ||
}, | ||
"gitHead": "33396eaeab85e2b186f7a91e95412e053e8f71f6" | ||
} | ||
"gitHead": "1f712f136835c0982ef84dd5915f4e01e96354ca" | ||
} |
@@ -32,3 +32,3 @@ /** | ||
protected closeElm?: HTMLElement | null; | ||
protected closeSearchElm?: HTMLElement | null; | ||
protected clearSearchIconElm?: HTMLElement | null; | ||
protected filterText = ''; | ||
@@ -722,3 +722,3 @@ protected updateData: any[] = []; | ||
this.closeSearchElm = this.filterParentElm?.querySelector('.icon-close'); | ||
this.clearSearchIconElm = this.filterParentElm?.querySelector('.icon-close'); | ||
this.searchInputElm = this.dropElm.querySelector<HTMLInputElement>('.ms-search input'); | ||
@@ -779,4 +779,4 @@ this.selectAllElm = this.dropElm.querySelector<HTMLInputElement>(`input[data-name="${this.selectAllName}"]`); | ||
if (this.closeSearchElm) { | ||
this._bindEventService.bind(this.closeSearchElm, 'click', ((e: MouseEvent) => { | ||
if (this.clearSearchIconElm) { | ||
this._bindEventService.bind(this.clearSearchIconElm, 'click', ((e: MouseEvent) => { | ||
e.preventDefault(); | ||
@@ -787,2 +787,5 @@ if (this.searchInputElm) { | ||
} | ||
// move highlight back to top of the list | ||
this._currentHighlightIndex = -1; | ||
this.moveFocusDown(); | ||
this.filter(); | ||
@@ -1103,4 +1106,11 @@ }) as EventListener); | ||
} | ||
this.moveFocusDown(); | ||
if (this._currentHighlightIndex < 0) { | ||
// on open drop initial, we'll focus on next available option | ||
this.moveFocusDown(); | ||
} else { | ||
// if it was already opened earlier, we'll keep same option index focused | ||
this.highlightCurrentOption(); | ||
} | ||
if (this.options.autoAdjustDropWidthByTextSize) { | ||
@@ -1107,0 +1117,0 @@ this.adjustDropWidthByText(); |
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 not supported yet
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 not supported yet
Sorry, the diff of this file is not supported yet
1060287
4565