selective-ui 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- /*! Selective UI v1.0.1 | MIT License */
2
- var t,e;t=this,e=function(t){"use strict";function e(t){return new class{element;#t=null;#e=null;#i=!1;constructor(t=null){t&&this.setElement(t)}setElement(t){this.element="string"==typeof t?document.querySelector(t):t}cancel(){return this.#t&&(clearTimeout(this.#t),this.#t=null),this.#e&&(clearTimeout(this.#e),this.#e=null),this.#i=!1,this}getHiddenDimensions(t="flex"){const e={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const i=window.getComputedStyle(this.element),s=parseFloat(i.borderTopWidth),n=parseFloat(i.borderBottomWidth),o=this.element.scrollHeight+s+n,h=this.element.getBoundingClientRect(),l={width:h.width,height:h.height+s+n,scrollHeight:o};return Object.assign(this.element.style,e),l}expand(t){this.cancel(),this.#i=!0;const{duration:e=200,display:i="flex",width:s,left:n,top:o,maxHeight:h,realHeight:l,position:a="bottom",onComplete:r}=t;return Object.assign(this.element.style,{display:i,width:s+"px",left:n+"px",top:("bottom"===a?o:o+l)+"px",maxHeight:h+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===a),this.element.classList.toggle("position-bottom","bottom"===a),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${e}ms, height ${e}ms, opacity ${e}ms`,top:o+"px",height:l+"px",opacity:"1",overflow:l>=h?"auto":"hidden"}),this.#t=setTimeout(()=>{this.element.style.transition="none",this.#i=!1,r&&r()},e)}),this}collapse(t){this.cancel(),this.#i=!0;const{duration:e=200,onComplete:i}=t,s=this.element.offsetHeight,n=this.element.offsetTop,o=this.element.classList.contains("position-top")?"top":"bottom",h=this.element.scrollHeight-this.element.offsetHeight>0,l="top"===o?n+s:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${e}ms, top ${e}ms, opacity ${e}ms`,height:"0px",top:l+"px",opacity:"0",overflow:h?"auto":"hidden"}),this.#t=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.#i=!1,i&&i()},e)}),this}showSwipeWidth(t){this.cancel(),this.#i=!0;const{duration:e=200,display:i="block",onComplete:s}=t;Object.assign(this.element.style,{transition:"none",display:i,width:"fit-content"});const n=this.getHiddenDimensions(i).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${e}ms`,width:n+"px",overflow:"hidden"})}),this.#t=setTimeout(()=>{Object.assign(this.element.style,{width:null,overflow:null,transition:null}),this.#i=!1,s&&s()},e),this}hideSwipeWidth(t){this.cancel(),this.#i=!0;const{duration:e=200,onComplete:i}=t,s=this.getHiddenDimensions().width;return Object.assign(this.element.style,{transition:"none",width:s+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${e}ms`,width:"0px",overflow:"hidden"})}),this.#t=setTimeout(()=>{Object.assign(this.element.style,{width:null,overflow:null,transition:null,display:null}),this.#i=!1,i&&i()},e),this}resize(t){this.#e&&clearTimeout(this.#e);const{duration:e=200,width:i,left:s,top:n,maxHeight:o,realHeight:h,position:l="bottom",animate:a=!0,onComplete:r}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==l,u=this.element.scrollHeight>o;return this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),c&&(this.element.style.transition=`top ${e}ms ease-out, height ${e}ms ease-out, max-height ${e}ms ease-out;`),requestAnimationFrame(()=>{const t={width:i+"px",left:s+"px",top:n+"px",maxHeight:o+"px",height:h+"px",overflowY:u?"auto":"hidden"};a&&(c||Math.abs(this.element.offsetHeight-h)>5)?t.transition=`height ${e}ms, top ${e}ms`:this.#e=setTimeout(()=>{this.element.style.transition="none"},e),Object.assign(this.element.style,t),a&&(c||Math.abs(this.element.offsetHeight-h)>1)?this.#e=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,r&&r()},e):(c&&delete this.element.style.transition,r&&r())}),this}get isAnimating(){return this.#i}}(t)}function i(t,e={}){if(D&&"undefined"!=typeof window&&window[k])return window[k].bind(t,e);V.bind(t,e)}function s(t){return D&&"undefined"!=typeof window&&window[k]?window[k].find(t):V.find(t)}function n(t){return D&&"undefined"!=typeof window&&window[k]?window[k].destroy(t):V.destroy(t)}function o(t,e={}){return D&&"undefined"!=typeof window&&window[k]?window[k].rebind(t,e):V.rebind(t,e)}function h(t){return D&&"undefined"!=typeof window&&window[k]?window[k].effector(t):e(t)}class l{defaultConfig={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}};bindedMap=new Map;unbindedMap=new Map;bindedCommand=[]}class a{static#s=null;static get iStorage(){return!this.#s&&(this.#s=new l),this.#s}static timerProcess={executeStored:{},setExecute:function(t,e,i=50,s=!1){this.executeStored[t]||(this.executeStored[t]=[]),this.executeStored[t].push({execute:e,timeout:i,once:s})},clearExecute:function(t){delete this.executeStored[t]},run:function(t,...e){let i=this.executeStored[t];this.timerRunner[t]||(this.timerRunner[t]={});for(const s in i){const n=i[s];this.timerRunner[t][s]||(this.timerRunner[t][s]={}),n&&(clearTimeout(this.timerRunner[t][s]),this.timerRunner[t][s]=setTimeout(()=>{n&&n.execute(e.length>0?e:null),n.once&&delete this.executeStored[t][s]},n.timeout))}},timerRunner:{}};static isNullOrEmpty(t){return"boolean"!=typeof t&&(null==t||""===t||0===t||"0"===t)}static jsCopyObject(t){if(null===t||"object"!=typeof t)return t;let e=Array.isArray(t)?[]:{};for(let i in t)t.hasOwnProperty(i)&&(e[i]=this.jsCopyObject(t[i]));return e}static randomString(t=6){let e="";for(let i=0;i<t;i++)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return e}static getElements(t){if(!t)return[];if("string"==typeof t){const e=document.querySelectorAll(t);return Array.from(e)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static nodeCreator(t={}){return this.nodeCloner(document.createElement(t.node),t,!0)}static nodeCloner(t=document.documentElement,e=null,i=!1){const s={...e},n=i?t:this.nodeToElement(t.cloneNode(!0));return"string"==typeof s.classList?n.classList.add(s.classList):Array.isArray(s.classList)&&n.classList.add(...s.classList),delete s.classList,["style","dataset"].forEach(t=>{Object.assign(n[t],s[t]),delete s[t]}),s.role&&(n.setAttribute("role",s.role),delete s.role),s.ariaLive&&(n.setAttribute("aria-live",s.ariaLive),delete s.ariaLive),s.ariaLabelledby&&(n.setAttribute("aria-labelledby",s.ariaLabelledby),delete s.ariaLabelledby),s.ariaControls&&(n.setAttribute("aria-controls",s.ariaControls),delete s.ariaControls),s.ariaHaspopup&&(n.setAttribute("aria-haspopup",s.ariaHaspopup),delete s.ariaHaspopup),s.ariaMultiselectable&&(n.setAttribute("aria-multiselectable",s.ariaMultiselectable),delete s.ariaMultiselectable),s.ariaAutocomplete&&(n.setAttribute("aria-autocomplete",s.ariaAutocomplete),delete s.ariaAutocomplete),s.event&&(Object.entries(s.event).forEach(([t,e])=>{n.addEventListener(t,e)}),delete s.event),Object.entries(s).forEach(([t,e])=>{null===e?n.removeAttribute(t):n[t]=e}),n}static nodeToElement(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static mountView(t){return this.mountNode(t)}static mountNode(t,e=null,i=!1,s=!1,n={}){let o=null;for(let h in t){const l=t[h],a=l.tag?.tagName?l.tag:this.nodeCreator(l.tag);n[h]=a,l.child&&this.mountNode(l.child,a,!1,!1,n),e?i?e.prepend(a):e.append(a):s||o||(o=a)}return s||(n.id=this.randomString(7),e||(n={tags:n,view:o})),n}static setStyle(t,e,i=null){const s="string"==typeof e?{[e]:i}:{...e},n=this.getElements(t);if(n&&"object"==typeof n)for(let o=0;o<n.length;o++){const t=n[o];t&&Object.assign(t.style,s)}}static buildConfig(t,e){let i=this.jsCopyObject(e);for(let s in i)t[s]?i[s]=t[s]:void 0!==t?.dataset[s]&&(i[s]=t.dataset[s]);return i}static mergeConfig(...t){if(0==t.length)return{};if(1==t.length)return this.jsCopyObject(t[0]);{const e=this.jsCopyObject(t[0]);for(let i=1;i<t.length;i++){const s=t[i];for(let t in s)if("on"==t){const i=s[t];for(let s in i)e[t][s].push(i[s])}else e[t]=s[t]}return e}}static string2Boolean(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static removeBinderMap(t){return this.iStorage.bindedMap.delete(t)}static getBinderMap(t){return this.iStorage.bindedMap.get(t)}static setBinderMap(t,e){this.iStorage.bindedMap.set(t,e)}static removeUnbinderMap(t){return this.iStorage.unbindedMap.delete(t)}static getUnbinderMap(t){return this.iStorage.unbindedMap.get(t)}static setUnbinderMap(t,e){this.iStorage.unbindedMap.set(t,e)}static getDefaultConfig(){return this.iStorage.defaultConfig}static getBindedCommand(){return this.iStorage.bindedCommand}static tagTranslate(t){if(null==t)return"";t=(t+"").replace(/&lt;`/g,"<").replace(/`&gt;/g,">").replace(/<`/g,"<").replace(/`>/g,">").trim();const e=globalThis?.document;if(!e||"function"!=typeof e.createElement)return(t=(t=t.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,"")).replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,"")).replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,"");const i=e.createElement("div");return i.innerHTML=t,i.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),i.querySelectorAll("*").forEach(t=>{[...t.attributes].forEach(e=>{const i=e.name||"",s=e.value||"";(/^on/i.test(i)||/^(href|src|xlink:href)$/i.test(i)&&/^javascript:/i.test(s))&&t.removeAttribute(i)})}),(i.innerHTML||"").trim()}static stripHtml(t){let e=document.createElement("DIV");e.innerHTML=t;let i=e.textContent||e.innerText||"";return e.remove(),i.trim()}static string2normalize(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static parseSelectToArray(t){const e=[];return Array.from(t.children).forEach(t=>{"OPTGROUP"===t.tagName?(e.push(t),Array.from(t.children).forEach(i=>{i.__parentGroup=t,e.push(i)})):"OPTION"===t.tagName&&e.push(t)}),e}static IsIOS(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static any2px(t){const e=(t+"").trim();if(e.endsWith("px"))return e;if(e.endsWith("vh"))return window.innerHeight*parseFloat(e)/100+"px";if(e.endsWith("vw"))return window.innerWidth*parseFloat(e)/100+"px";const i=parseFloat(getComputedStyle(document.documentElement).fontSize);if(e.endsWith("rem"))return i*parseFloat(e)+"px";const s=this.nodeCreator({node:"div",style:{height:e,opacity:0}});document.body.appendChild(s);const n=s.offsetHeight+"px";return s.remove(),n}}class r{static buildEventToken(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},callback:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static callEvent(t,...e){const{token:i,callback:s}=this.buildEventToken();for(let n=0;n<e.length;n++){const o=e[n];if("function"==typeof o&&(t&&Array.isArray(t)?o(s,...t):o(s),i.isCancel||!i.isContinue))break}return i}static trigger(t,e,i={bubbles:!0,cancelable:!0}){const s=new Event(e,i);return t.dispatchEvent(s),s}static callFunctions(t,...e){if(Array.isArray(t))for(const i of t)"function"==typeof i&&i(...e)}}class c{static resizeBox(t,e){const i=a.getBinderMap(t).options,s=i.minWidth,n=i.minHeight;let o=t.offsetWidth+"px",h=t.offsetHeight+"px";parseInt(i.width,10)>0&&(o=i.width),parseInt(i.height,10)>0&&(h=i.height),a.setStyle(e,{width:o,height:h,minWidth:s,minHeight:n})}}class u{constructor(t){t&&this.init(t)}node=null;#n=null;init(t){this.node=a.nodeCreator({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.#n=t}get(){return this.#n.placeholder}set(t,e=!0){e&&(this.#n.placeholder=t),t=a.tagTranslate(t),this.node.innerHTML=this.#n.allowHtml?t:a.stripHtml(t)}}class d{constructor(){this.#o()}node=null;#o(){this.node=a.nodeCreator({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}setDropdown(t){t?this.node.classList.add("drop-down"):this.node.classList.remove("drop-down")}}class p{nodeMounted;node;options=null;#h=[];#l=[];constructor(t=null){t&&this.init(t)}init(t){this.nodeMounted=a.mountNode({OptionHandle:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},child:{SelectAll:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{r.callFunctions(this.#h)}}},DeSelectAll:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{r.callFunctions(this.#l)}}}}}}),this.node=this.nodeMounted.view,this.options=t}available(){return a.string2Boolean(this.options.multiple)&&a.string2Boolean(this.options.selectall)}refresh(){this.available()?this.show():this.hide()}show(){this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}OnSelectAll(t=null){this.#h.push(t)}OnDeSelectAll(t=null){this.#l.push(t)}}class g{isInit=!1;element=null;#a=null;#r=null;#c;constructor(){this.isInit=!0,this.#c=this.#u.bind(this)}onChanged(t){}#u(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.onChanged({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const e=t.getBoundingClientRect(),i="function"==typeof window?.getComputedStyle?window.getComputedStyle(t):null;this.onChanged({width:e?.width??0,height:e?.height??0,top:e?.top??0,left:e?.left??0,padding:{top:parseFloat(i?.paddingTop??"0"),right:parseFloat(i?.paddingRight??"0"),bottom:parseFloat(i?.paddingBottom??"0"),left:parseFloat(i?.paddingLeft??"0")},border:{top:parseFloat(i?.borderTopWidth??"0"),right:parseFloat(i?.borderRightWidth??"0"),bottom:parseFloat(i?.borderBottomWidth??"0"),left:parseFloat(i?.borderLeftWidth??"0")},margin:{top:parseFloat(i?.marginTop??"0"),right:parseFloat(i?.marginRight??"0"),bottom:parseFloat(i?.marginBottom??"0"),left:parseFloat(i?.marginLeft??"0")}})}trigger(){this.#u()}connect(t){if(!(t instanceof Element))throw Error("Element không hợp lệ");this.element=t,this.#a=new ResizeObserver(this.#c),this.#a.observe(t),this.#r=new MutationObserver(this.#c),this.#r.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.#c,!0),window.addEventListener("resize",this.#c),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.#c),window.visualViewport.addEventListener("scroll",this.#c))}disconnect(){this.#a?.disconnect?.(),this.#r?.disconnect?.(),this.onChanged=()=>{},window.removeEventListener("scroll",this.#c,!0),window.removeEventListener("resize",this.#c),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.#c),window.visualViewport.removeEventListener("scroll",this.#c)),this.#a=null,this.#r=null,this.element=null}}class m{targetElement=null;options=null;view=null;position=-1;isInit=!1;get value(){return this.targetElement.getAttribute("value")}constructor(t,e=null,i=null){this.options=t,this.targetElement=e,this.view=i}update(t){this.targetElement=t,this.onTargetChanged()}onTargetChanged(){}}class f{parent=null;constructor(t){this.parent=t}render(){}update(){}view=null;getView(){return this.view.view}getTag(t){return this.view.tags[t]}getTags(){return this.view.tags}}class w extends f{view;render(){const t=a.randomString(7);this.view=a.mountView({GroupView:{tag:{node:"div",classList:["selective-ui-group"],role:"group",ariaLabelledby:`seui-${t}-header`,id:`seui-${t}-group`},child:{GroupHeader:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},GroupItems:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.updateLabel()}updateLabel(t=null){null!==t&&(this.view.tags.GroupHeader.textContent=t)}getItemsContainer(){return this.view.tags.GroupItems}updateVisibility(){const t=Array.from(this.view.tags.GroupItems.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}setCollapsed(t){this.view.view.classList.toggle("collapsed",t),this.view.tags.GroupHeader.setAttribute("aria-expanded",t?"false":"true")}}class b extends f{view;isMultiple=!1;hasImage=!1;optionConfig=null;render(){const t=["selective-ui-option-view"],e=a.randomString(7),i="option_"+e;this.isMultiple&&t.push("multiple"),this.hasImage&&(t.push("has-image"),t.push("image-"+this.optionConfig?.imagePosition));const s={OptionInput:{tag:{node:"input",type:this.isMultiple?"checkbox":"radio",classList:"allow-choice",id:i}},...this.hasImage&&{OptionImage:{tag:{node:"img",classList:"option-image",style:{width:this.optionConfig?.imageWidth||"60px",height:this.optionConfig?.imageHeight||"60px",borderRadius:this.optionConfig?.imageBorderRadius||"4px"}}}},OptionLabel:{tag:{node:"label",htmlFor:i,classList:["align-vertical-"+this.optionConfig?.labelValign,"align-horizontal-"+this.optionConfig?.labelHalign]},child:{LabelContent:{tag:{node:"div"}}}}};this.view=a.mountView({OptionView:{tag:{node:"div",id:`seui-${e}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},child:s}}),this.parent.appendChild(this.view.view),this.applyConfigToDOM()}update(){this.applyConfigToDOM()}applyConfigToDOM(){const t=this.view;if(!t||!t.view)return;const e=t.view,i=t.tags?.OptionInput,s=t.tags?.OptionLabel,n=!!this.isMultiple,o=!!this.hasImage,h=this.optionConfig?.imagePosition||"right",l=this.optionConfig?.imageWidth||"60px",a=this.optionConfig?.imageHeight||"60px",r=this.optionConfig?.imageBorderRadius||"4px",c=this.optionConfig?.labelValign||"center",u=this.optionConfig?.labelHalign||"left",d=["selective-ui-option-view"];if(n&&d.push("multiple"),o&&d.push("has-image","image-"+h),e.className=d.join(" "),i){const t=n?"checkbox":"radio";i.type!==t&&(i.type=t)}s&&(s.className=`align-vertical-${c} align-horizontal-${u}`);let p=t.tags?.OptionImage;if(o){p||(p=document.createElement("img"),p.className="option-image",s&&s.parentElement?e.insertBefore(p,s):e.appendChild(p),t.tags.OptionImage=p);const i=p.style;i.width=l,i.height=a,i.borderRadius=r}else p&&(p.remove(),t.tags.OptionImage=null)}}class y extends m{#d=[];#p=[];#g=[];#m=!0;#f=!1;group=null;get imageSrc(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.imageSrc}get value(){return this.targetElement.value}get selected(){return this.targetElement.selected}set selected(t){this.selectedNonTrigger=t,r.callEvent([this,t],...this.#d)}get visible(){return this.#m}set visible(t){if(this.#m===t)return;this.#m=t;const e=this.view?.getView();e&&e.classList.toggle("hide",!t),r.callEvent([this,t],...this.#g)}get selectedNonTrigger(){return this.selected}set selectedNonTrigger(t){const e=this.view?.getTag("OptionInput"),i=this.view?.getView();e&&(e.checked=t),i&&(i.classList.toggle("checked",!!t),i.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement.selected=t,r.callEvent([this,t],...this.#p)}get text(){const t=a.tagTranslate(this.dataset?.mask??this.targetElement.text);return this.options.allowHtml?t:a.stripHtml(t)}get textContent(){return this.options.allowHtml?a.stripHtml(this.text).trim():this.text.trim()}get dataset(){return this.targetElement.dataset??{}}get highlighted(){return this.#f}set highlighted(t){const e=!!t,i=this.view?.getView?.();this.#f!==e&&(this.#f=e),i&&i.classList.toggle("highlight",e)}onSelected(t){this.#d.push(t)}onInternalSelected(t){this.#p.push(t)}onVisibilityChanged(t){this.#g.push(t)}onTargetChanged(){const t=this.view.getTag("LabelContent");t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const e=this.view.getTag("OptionImage");e&&this.hasImage&&(e.src=this.imageSrc,e.alt=this.text),this.selectedNonTrigger=this.targetElement.selected}}class v extends m{label="";items=[];collapsed=!1;#w=[];constructor(t,e){super(t,e),e&&(this.label=e.label,this.collapsed=a.string2Boolean(e.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get selectedItems(){return this.items.filter(t=>t.selected)}get visibleItems(){return this.items.filter(t=>t.visible)}get hasVisibleItems(){return this.visibleItems.length>0}update(t){this.label=t.label,this.view&&this.view.updateLabel(this.label)}onTargetChanged(){this.view&&(this.view.updateLabel(this.label),this.view.setCollapsed(this.collapsed))}onCollapsedChanged(t){this.#w.push(t)}toggleCollapse(){this.collapsed=!this.collapsed,this.view&&this.view.setCollapsed(this.collapsed),r.callEvent([this,this.collapsed],...this.#w)}addItem(t){this.items.push(t),t.group=this}removeItem(t){const e=this.items.indexOf(t);e>-1&&(this.items.splice(e,1),t.group=null)}updateVisibility(){this.view&&this.view.updateVisibility()}}class x{items=[];adapterKey=a.randomString(12);isSkipEvent=!1;constructor(t=[]){this.items=t,this.onInit()}onInit(){}onViewHolder(t,e,i){t.isInit?e.update():e.render()}onPropChanging(t,e){a.timerProcess.setExecute(`${t}ing_${this.adapterKey}`,e,1)}onPropChanged(t,e){a.timerProcess.setExecute(`${t}_${this.adapterKey}`,e)}changeProp(t,...e){a.timerProcess.run(`${t}_${this.adapterKey}`,...e)}changingProp(t,...e){a.timerProcess.run(`${t}ing_${this.adapterKey}`,...e)}viewHolder(t,e){return null}itemCount(){return this.items.length}setItems(t){this.changingProp("items",t),this.items=t,this.changeProp("items",t)}syncFromSource(t){this.setItems(t)}updateRecyclerView(t){for(let e=0;e<this.itemCount();e++){let i=this.items[e].view;this.items[e].isInit||(i=this.viewHolder(t,this.items[e])),this.onViewHolder(this.items[e],i,e),this.items[e].isInit=!0}}updateData(t){}}class O{#b=[];#y;#v;#x;#O;options=null;constructor(t){this.options=t}setupAdapter(t){this.#y=t}setupRecyclerView(t){this.#x=t}createModelResources(t){this.#b=[];let e=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)e=new v(this.options,t),this.#b.push(e);else if("OPTION"===t.tagName){const i=new y(this.options,t);t.__parentGroup&&e&&t.__parentGroup===e.targetElement?(e.addItem(i),i.group=e):(this.#b.push(i),e=null)}}),this.#b}replace(t){this.createModelResources(t),this.#v&&this.#v.syncFromSource(this.#b),this.refresh()}notify(){this.#v&&this.refresh()}load(t,e={},i={}){this.#v=new this.#y(this.#b),Object.assign(this.#v,e),this.#O=new this.#x(t),this.#O.setAdapter(this.#v),Object.assign(this.#O,i)}update(t){const e=this.#b,i=[],s=new Map,n=new Map;e.forEach(t=>{t instanceof v?s.set(t.label,t):t instanceof y&&n.set(t.value,t)});let o=null,h=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){let e=t;const n=s.get(e.label);n?(n.update(e),n.position=h,n.items=[],o=n,i.push(n),s.delete(e.label)):(o=new v(this.options,e),o.position=h,i.push(o)),h++}else if("OPTION"===t.tagName){let e=t;const s=n.get(e.value);if(s)s.update(e),s.position=h,e.__parentGroup&&o?(o.addItem(s),s.group=o):(s.group=null,i.push(s)),n.delete(e.value);else{const t=new y(this.options,e);t.position=h,e.__parentGroup&&o?(o.addItem(t),t.group=o):i.push(t)}h++}}),s.forEach(t=>{t.view&&t.view.getView()?.remove()}),n.forEach(t=>{t.view&&t.view.getView()?.remove()}),this.#b=i,this.#v&&this.#v.updateData(this.#b),this.onUpdated(),this.refresh()}onUpdated(){}skipEvent(t){this.#v.isSkipEvent=t}refresh(){this.#O&&(this.#O.refresh(),this.onUpdated())}getResources(){return{modelList:this.#b,adapter:this.#v,recyclerView:this.#O}}triggerChanging(t){this.#v.changingProp(t)}triggerChanged(t){this.#v.changeProp(t)}}class C{node=null;options=null;constructor(t=null){t&&this.init(t)}init(t){this.options=t,this.node=a.nodeCreator({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}get isVisible(){return!this.node.classList.contains("hide")}}class A{node=null;options=null;constructor(t=null){t&&this.init(t)}init(t){this.options=t,this.node=a.nodeCreator({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",t),this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}get isVisible(){return!this.node.classList.contains("hide")}}class S extends x{isMultiple=!1;#C=[];#A=-1;#S=null;groups=[];flatOptions=[];constructor(t=[]){super(t),this.#L()}#L(){this.flatOptions=[],this.groups=[],this.items.forEach(t=>{t instanceof v?(this.groups.push(t),this.flatOptions.push(...t.items)):t instanceof y&&this.flatOptions.push(t)})}viewHolder(t,e){return e instanceof v?new w(t):new b(t)}onViewHolder(t,e,i){t.position=i,t instanceof v?this.#M(t,e,i):t instanceof y&&this.#T(t,e,i),t.isInit=!0}#M(t,e,i){super.onViewHolder(t,e,i),t.view=e;const s=e.getTag("GroupHeader");s.textContent=t.label,t.isInit||(s.style.cursor="pointer",s.addEventListener("click",()=>{t.toggleCollapse()}),t.onCollapsedChanged((t,e,i)=>{e.items.forEach(t=>{const e=t.view?.getView();e&&(e.style.display=i?"none":"")}),this.onCollapsedChange(e,i)}));const n=e.getItemsContainer();t.items.forEach((t,e)=>{let i=t.view;t.isInit||(i=new b(n)),this.#T(t,i,e),t.isInit=!0}),e.setCollapsed(t.collapsed),e.updateVisibility()}#T(t,e,i){if(e.isMultiple=this.isMultiple,e.hasImage=t.hasImage,e.optionConfig={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.isInit?e.update():super.onViewHolder(t,e,i),t.view=e,t.hasImage){const i=e.getTag("OptionImage");i&&(i.src=t.imageSrc,i.alt=t.text)}e.getTag("LabelContent").innerHTML=t.text,t.isInit||(e.getTag("OptionView").addEventListener("click",e=>{e.stopPropagation(),e.preventDefault(),this.isSkipEvent||(this.isMultiple?(this.changingProp("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.changingProp("select"),setTimeout(()=>{this.#S&&(this.#S.selected=!1),t.selected=!0},5)))}),e.getTag("OptionView").title=t.textContent,e.getTag("OptionView").addEventListener("mouseenter",()=>{this.isSkipEvent||this.setHighlight(this.flatOptions.indexOf(t),!1)}),t.onSelected(()=>{this.changeProp("selected")}),t.onInternalSelected((e,i,s)=>{s&&(this.#S=t),this.changeProp("selected_internal")}),t.onVisibilityChanged((t,e)=>{e.group&&e.group.updateVisibility(),this.#H()})),t.selected&&(this.#S=t,t.selectedNonTrigger=!0)}setItems(t){this.changingProp("items",t),this.items=t,this.#L(),this.changeProp("items",t)}syncFromSource(t){this.setItems(t)}updateData(t){this.items=t,this.#L()}getSelectedItems(){return this.flatOptions.filter(t=>t.selected)}getSelectedItem(){return this.flatOptions.find(t=>t.selected)}checkAll(t){this.isMultiple&&this.flatOptions.forEach(e=>{e.selected=t})}onVisibilityChanged(t){this.#C.push(t)}#H(){const t=this.flatOptions.filter(t=>t.visible).length,e=this.flatOptions.length;this.#C.forEach(i=>{i({visibleCount:t,totalCount:e,hasVisible:t>0,isEmpty:0===e})})}getVisibilityStats(){const t=this.flatOptions.filter(t=>t.visible).length,e=this.flatOptions.length;return{visibleCount:t,totalCount:e,hasVisible:t>0,isEmpty:0===e}}resetHighlight(){this.setHighlight(0)}navigate(t,e=!0){const i=this.flatOptions.filter(t=>t.visible);if(0===i.length)return;let s=i.findIndex(t=>t===this.flatOptions[this.#A]);-1===s&&(s=-1);let n=s+t;n>=i.length&&(n=0),n<0&&(n=i.length-1);const o=this.flatOptions.indexOf(i[n]);this.setHighlight(o,e)}selectHighlighted(){if(this.#A>-1&&this.flatOptions[this.#A]){const t=this.flatOptions[this.#A];if(t.visible){const e=t.view?.getView();e&&e.click()}}}setHighlight(t,e=!0){let i=0;if("number"==typeof t)i=t;else if(t instanceof y){const e=this.flatOptions.indexOf(t);i=e>-1?e:0}else i=0;this.#A>-1&&this.flatOptions[this.#A]&&(this.flatOptions[this.#A].highlighted=!1);for(let s=i;s<this.flatOptions.length;s++){const t=this.flatOptions[s];if(t.visible){if(t.highlighted=!0,this.#A=s,e){const e=t.view?.getView();e&&e.scrollIntoView({block:"center",behavior:"smooth"})}return void this.onHighlightChange(s,t.view?.getView()?.id)}}}onHighlightChange(t,e){}onCollapsedChange(t,e){}}class L{#I;constructor(t=null,e=null,i=null){this.#I=i,t&&e&&this.init(t,e)}options=null;isCreated=!1;optionAdapter=null;node=null;#E=null;#P;#j=null;optionHandle=null;emptyState=null;loadingState=null;recyclerView=null;#F=null;#V=null;#$=null;init(t,e){this.optionHandle=new p(e),this.emptyState=new C(e),this.loadingState=new A(e);const i=a.mountNode({PopupContainer:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:e.panelHeight}},child:{OptionHandle:{tag:this.optionHandle.node},OptionsContainer:{tag:{id:e.SEID_LIST,node:"div",classList:"selective-ui-options-container",role:"listbox"}},LoadingState:{tag:this.loadingState.node},EmptyState:{tag:this.emptyState.node}}}});this.node=i.view,this.#F=i.tags.OptionsContainer,this.#j=a.getBinderMap(t),this.options=e,this.#I.load(this.#F,{isMultiple:e.multiple});const s=this.#I.getResources();this.optionAdapter=s.adapter,this.recyclerView=s.recyclerView,this.optionHandle.OnSelectAll(()=>{s.adapter.checkAll(!0)}),this.optionHandle.OnDeSelectAll(()=>{s.adapter.checkAll(!1)}),this.#k()}async showLoading(){clearTimeout(this.#$),this.#I.skipEvent(!0),!1!==a.string2Boolean(this.options.loadingfield)&&(this.loadingState.show(this.optionAdapter.getVisibilityStats().hasVisible),this.optionHandle.hide(),this.triggerResize())}async hideLoading(){clearTimeout(this.#$),this.#$=setTimeout(()=>{this.#I.skipEvent(!1),this.loadingState.hide();const t=this.optionAdapter.getVisibilityStats();this.#D(t),this.triggerResize()},200)}#k(){this.optionAdapter.onVisibilityChanged(t=>{this.#D(t)}),this.optionAdapter.onPropChanged("items",()=>{const t=this.optionAdapter.getVisibilityStats();this.#D(t),this.triggerResize()})}#D(t=null){t||(t=this.optionAdapter.getVisibilityStats()),t?.isEmpty?(this.emptyState.show("nodata"),this.#F.classList.add("hide"),this.optionHandle.hide()):t&&!t.hasVisible?(this.emptyState.show("notfound"),this.#F.classList.add("hide"),this.optionHandle.hide()):(this.emptyState.hide(),this.#F.classList.remove("hide"),this.optionHandle.refresh())}onAdapterPropChanging(t,e){this.optionAdapter.onPropChanging(t,e)}onAdapterPropChanged(t,e){this.optionAdapter.onPropChanged(t,e)}setupEffector(t){this.#E=t}open(t=null){this.isCreated||(document.body.appendChild(this.node),this.isCreated=!0,this.#P=new g,this.#E.setElement(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.optionHandle.refresh(),this.#D();const e=this.#R(),{position:i,top:s,maxHeight:n,realHeight:o}=this.#z(e);this.#E.expand({duration:this.options.animationtime,display:"flex",width:e.width,left:e.left,top:s,maxHeight:n,realHeight:o,position:i,onComplete:()=>{this.#P.onChanged=t=>this.#N(t),this.#P.connect(this.#j.container.tags.ViewPanel),t&&t()}})}close(t=null){this.isCreated&&(this.#P.disconnect(),this.#E.collapse({duration:this.options.animationtime,onComplete:t}))}triggerResize(){this.isCreated&&this.#P.trigger()}setupInfiniteScroll(t,e){this.#V=async()=>{const e=t.getPaginationState();if(!e.isPaginationEnabled)return;const i=this.node;if(i.scrollHeight-i.scrollTop-i.clientHeight<100&&!e.isLoading&&e.hasMore){const e=await t.loadMore();!e.success&&e.message&&console.log("Load more:",e.message)}},this.node.addEventListener("scroll",this.#V)}#R(){const t=this.#j.container.tags.ViewPanel,e=t.getBoundingClientRect(),i=window.getComputedStyle(t),s=window.visualViewport,n=a.IsIOS();return{width:e.width,height:e.height,top:e.top-(s&&n?s.offsetTop:0),left:e.left-(s&&n?s.offsetLeft:0),padding:{top:parseFloat(i.paddingTop),right:parseFloat(i.paddingRight),bottom:parseFloat(i.paddingBottom),left:parseFloat(i.paddingLeft)},border:{top:parseFloat(i.borderTopWidth),right:parseFloat(i.borderRightWidth),bottom:parseFloat(i.borderBottomWidth),left:parseFloat(i.borderLeftWidth)}}}#z(t){const e=window.visualViewport,i=a.IsIOS(),s=e?.height??window.innerHeight,n=e&&i?e.offsetTop:0,o=this.#E.getHiddenDimensions("flex").scrollHeight,h=parseFloat(this.options.panelHeight)||220,l=parseFloat(this.options.panelMinHeight)||100,r=s-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=h,p=Math.min(o,d);const g=r-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(r-15,h)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,h)):r>=c?(u="bottom",d=Math.max(r-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+n:t.top-p-3+n,maxHeight:d,realHeight:p,contentHeight:o}}#N(t){const{position:e,top:i,maxHeight:s,realHeight:n}=this.#z(t);this.#E.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:i,maxHeight:s,realHeight:n,position:e,animate:!0})}}class M{constructor(t=null){this.options=t,t&&this.init(t)}nodeMounted=null;node=null;SearchInput=null;onSearch=null;options=null;onNavigate=null;onEnter=null;onEsc=null;init(t){this.nodeMounted=a.mountNode({SearchBox:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},child:{SearchInput:{tag:{id:a.randomString(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",ariaControls:t.SEID_LIST,ariaAutocomplete:"list"}}}}}),this.node=this.nodeMounted.view,this.SearchInput=this.nodeMounted.tags.SearchInput;let e=!1;const i=this.nodeMounted.tags.SearchInput;i.addEventListener("mousedown",t=>{t.stopPropagation()}),i.addEventListener("mouseup",t=>{t.stopPropagation()}),i.addEventListener("keydown",t=>{e=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),e=!0,this.onNavigate?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),e=!0,this.onNavigate?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),e=!0,this.onEnter?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),e=!0,this.onEsc?.())}),i.addEventListener("input",()=>{e||this.onSearch&&this.onSearch(this.nodeMounted.tags.SearchInput.value,!0)})}show(){this.node.classList.remove("hide"),this.SearchInput.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.SearchInput.focus()})}hide(){this.node.classList.add("hide")}clear(t=!0){this.nodeMounted.tags.SearchInput.value="",this.onSearch&&this.onSearch("",t)}setPlaceHolder(t){this.SearchInput.placeholder=a.stripHtml(t)}setActiveDescendant(t){this.SearchInput.setAttribute("aria-activedescendant",t)}}class T{viewElement=null;adapter=null;constructor(t=null){this.viewElement=t}setView(t){this.viewElement=t}setAdapter(t){this.adapter=t,t.onPropChanging("items",()=>{this.clear()}),t.onPropChanged("items",()=>{this.render()}),this.render()}clear(){this.viewElement&&this.viewElement.replaceChildren()}render(){this.adapter&&this.viewElement&&this.adapter.updateRecyclerView(this.viewElement)}refresh(){this.render()}}class H{nodeMounted=null;node=null;options=null;selectUIMask;parentMask;modelManager;constructor(t=null){t&&this.init(t)}init(t){this.nodeMounted=a.mountNode({AccessoryBox:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.nodeMounted.view,this.options=t}setRoot(t){this.selectUIMask=t,this.parentMask=t.parentElement,this.refreshLocation()}refreshLocation(){this.parentMask.insertBefore(this.node,"top"==this.options.accessoryStyle?this.selectUIMask:this.selectUIMask.nextSibling)}setModelManager(t){this.modelManager=t}setModelData(t){this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{a.mountNode({AccessoryItem:{tag:{node:"div",classList:["accessory-item"]},child:{Button:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:()=>{this.modelManager.triggerChanging("select"),setTimeout(()=>{t.selected=!1},10)}}},Content:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),r.trigger(window,"resize")}}class I{#B;#I;#U=null;#G=null;#q=null;#W={currentPage:0,totalPages:1,hasMore:!1,isLoading:!1,currentKeyword:"",isPaginationEnabled:!1};constructor(t,e){this.#B=t,this.#I=e}isAjax(){return!!this.#U}setAjax(t){this.#U=t}setPopup(t){this.#q=t}getPaginationState(){return{...this.#W}}resetPagination(){this.#W={currentPage:0,totalPages:1,hasMore:!1,isLoading:!1,currentKeyword:"",isPaginationEnabled:this.#W.isPaginationEnabled}}clear(){this.#W.currentKeyword="";const{modelList:t}=this.#I.getResources(),e=[];for(const i of t)i instanceof y?e.push(i):i instanceof v&&Array.isArray(i.items)&&e.push(...i.items);e.forEach(t=>{t.visible=!0})}async search(t,e=!1){return this.#U&&this.#U?this.#_(t,e):this.#K(t)}async loadMore(){return this.#U&&this.#U?this.#W.isLoading?{success:!1,message:"Already loading"}:this.#W.isPaginationEnabled?this.#W.hasMore?(this.#W.currentPage++,this.#_(this.#W.currentKeyword,!0)):{success:!1,message:"No more data"}:{success:!1,message:"Pagination not enabled"}:{success:!1,message:"Ajax not enabled"}}async#K(t){this.compareSearchTrigger(t)&&(this.#W.currentKeyword=t);const e=((t||"")+"").toLowerCase(),i=a.string2normalize(e),{modelList:s}=this.#I.getResources(),n=[];for(const h of s)h instanceof y?n.push(h):h instanceof v&&Array.isArray(h.items)&&n.push(...h.items);let o=!1;return n.forEach(t=>{const s=((t.textContent||t.text||"")+"").toLowerCase(),n=a.string2normalize(s),h=""===e||s.includes(e)||n.includes(i);t.visible=h,h&&(o=!0)}),{success:!0,hasResults:o,isEmpty:0===n.length}}compareSearchTrigger(t){return t!==this.#W.currentKeyword}async#_(t,e=!1){const i=this.#U;this.compareSearchTrigger(t)&&(this.resetPagination(),this.#W.currentKeyword=t,e=!1),this.#W.isLoading=!0,this.#q?.showLoading(),this.#G?.abort(),this.#G=new AbortController;const s=this.#W.currentPage,n=Array.from(this.#B.selectedOptions).map(t=>t.value).join(",");let o;"function"==typeof i.data?(o=i.data(t,s),o&&!o.selectedValue&&(o.selectedValue=n)):o={search:t,page:s,selectedValue:n,...i.data||{}};try{let t;if("POST"===i.method){const e=new URLSearchParams;Object.keys(o).forEach(t=>{e.append(t,o[t])}),t=await fetch(i.url,{method:"POST",body:e,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.#G.signal})}else{const e=""+new URLSearchParams(o);t=await fetch(`${i.url}?${e}`,{signal:this.#G.signal})}let s=await t.json();const n=this.#Q(s);return n.hasPagination?(this.#W.isPaginationEnabled=!0,this.#W.currentPage=n.page,this.#W.totalPages=n.totalPages,this.#W.hasMore=n.hasMore):this.#W.isPaginationEnabled=!1,this.#Y(n.items,i.keepSelected,e),this.#W.isLoading=!1,this.#q?.hideLoading(),{success:!0,hasResults:n.items.length>0,isEmpty:0===n.items.length,hasPagination:n.hasPagination,hasMore:n.hasMore,currentPage:n.page,totalPages:n.totalPages}}catch(h){return this.#W.isLoading=!1,this.#q?.hideLoading(),"AbortError"===h.name?{success:!1,message:"Request aborted"}:(console.error("Ajax search error:",h),{success:!1,message:h.message})}}#Q(t){let e=[],i=!1,s=0,n=1,o=!1;return t.object&&Array.isArray(t.object)?(e=t.object,void 0!==t.page&&(i=!0,s=parseInt(t.page)||0,n=parseInt(t.totalPages||t.total_page)||1,o=s<n-1)):t.data&&Array.isArray(t.data)?(e=t.data,void 0!==t.page&&(i=!0,s=parseInt(t.page)||0,n=parseInt(t.totalPages||t.total_page)||1,o=t.hasMore??s<n-1)):Array.isArray(t)?e=t:t.items&&Array.isArray(t.items)&&(e=t.items,t.pagination&&(i=!0,s=parseInt(t.pagination.page)||0,n=parseInt(t.pagination.totalPages||t.pagination.total_page)||1,o=t.pagination.hasMore??s<n-1)),e=e.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.isGroup||t.group||t.label)return{type:"optgroup",label:t.label||t.name||t.title||"",data:t.data||{},options:(t.options||t.items||[]).map(t=>({value:t.value||t.id||t.key||"",text:t.text||t.label||t.name||t.title||"",selected:t.selected||!1,data:t.data||(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};let e=t.data||{};return t?.imgsrc&&(e.imgsrc=t.imgsrc),{type:"option",value:t.value||t.id||t.key||"",text:t.text||t.label||t.name||t.title||"",selected:t.selected||!1,data:e}}),{items:e,hasPagination:i,page:s,totalPages:n,hasMore:o}}#Y(t,e,i=!1){const s=this.#B;let n=[];e&&(n=Array.from(s.selectedOptions).map(t=>t.value)),i||(s.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)s.appendChild(t);else if("optgroup"===t.type){const i=document.createElement("optgroup");i.label=t.label,t.data&&Object.keys(t.data).forEach(e=>{i.dataset[e]=t.data[e]}),t.options&&Array.isArray(t.options)&&t.options.forEach(t=>{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(e=>{s.dataset[e]=t.data[e]}),(t.selected||e&&n.includes(s.value))&&(s.selected=!0),i.appendChild(s)}),s.appendChild(i)}else{const i=document.createElement("option");i.value=t.value,i.text=t.text,t.data&&Object.keys(t.data).forEach(e=>{i.dataset[e]=t.data[e]}),(t.selected||e&&n.includes(i.value))&&(i.selected=!0),s.appendChild(i)}}),s.dispatchEvent(new CustomEvent("options:changed"))}}class E{#J;#B;#X=null;constructor(t){this.#J=new MutationObserver(()=>{clearTimeout(this.#X),this.#X=setTimeout(()=>{this.onChanged(t)},50)}),this.#B=t,t.addEventListener("options:changed",()=>{this.onChanged(t)})}connect(){this.#J.observe(this.#B,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}onChanged(t){}disconnect(){clearTimeout(this.#X),this.#J.disconnect()}}class P{#J;#Z;#X=null;constructor(t){this.#Z=t,this.#J=new MutationObserver(t=>{let e=!1;for(const i of t)if("attributes"===i.type&&i.attributeName?.startsWith("data-")){e=!0;break}e&&(clearTimeout(this.#X),this.#X=setTimeout(()=>{this.onChanged({...this.#Z.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.onChanged({...this.#Z.dataset})})}connect(){this.#J.observe(this.#Z,{attributes:!0,attributeOldValue:!0})}onChanged(t){}disconnect(){clearTimeout(this.#X),this.#J.disconnect()}}class j{constructor(t=null,e=null){t&&this.init(t,e)}container={};oldValue=null;node=null;options=null;optionModelManager=null;isOpen=!1;hasLoadedOnce=!1;isBeforeSearch=!1;Selective=null;get isDisabled(){return this.options.disabled}set isDisabled(t){this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",""+t),this.container.tags.ViewPanel.setAttribute("aria-disabled",""+t)}get isReadOnly(){return this.options.readonly}set isReadOnly(t){this.options.readonly=t,this.node.classList.toggle("readonly",t)}get isVisible(){return this.options.visible}set isVisible(t){this.options.visible=t,this.node.classList.toggle("invisible",!t)}init(t,i){const s=a.getBinderMap(t).options,n=new u(s),o=new d,h=new M(s),l=e(),r=new O(s),p=new H(s),g=new I(t,r),m=new E(t),f=new P(t);this.Selective=i,this.options=s,n.node.id=s.SEID_HOLDER;const w=a.mountNode({Container:{tag:{node:"div",classList:"selective-ui-MAIN"},child:{ViewPanel:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,role:"combobox",ariaExpanded:"false",ariaLabelledby:s.SEID_HOLDER,ariaControls:s.SEID_LIST,ariaHaspopup:"true",ariaMultiselectable:s.multiple?"true":"false",onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.getAction()?.open())}},child:{PlaceHolder:{tag:n.node},Directive:{tag:o.node},SearchBox:{tag:h.node}}}}}});this.container=w,this.node=this.container.view,t.parentNode.insertBefore(this.node,t),this.node.insertBefore(t,w.tags.ViewPanel),p.setRoot(w.tags.ViewPanel),p.setModelManager(r),w.tags.ViewPanel.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),c.resizeBox(t,w.tags.ViewPanel),t.classList.add("init"),r.setupAdapter(S),r.setupRecyclerView(T),r.createModelResources(a.parseSelectToArray(t)),r.onUpdated=()=>{w.popup.triggerResize()},this.optionModelManager=r,w.searchController=g,w.placeholder=n,w.directive=o,w.popup=new L(t,s,r),w.popup.setupEffector(l),w.popup.setupInfiniteScroll(g,s),w.popup.onAdapterPropChanged("selected",()=>{this.getAction()?.change(null,!0)}),w.popup.onAdapterPropChanged("selected_internal",()=>{this.getAction()?.change(null,!1)}),w.popup.onAdapterPropChanging("select",()=>{this.oldValue=this.getAction()?.value??""}),w.searchbox=h,w.effector=l,w.targetElement=t,w.accessorybox=p,this.getAction()?.change(null,!1),m.connect(),m.onChanged=t=>{r.update(a.parseSelectToArray(t)),this.getAction()?.refreshMask()},w.selectObserver=m,w.datasetObserver=f,f.connect(),t.addEventListener("options:changed",()=>{r.update(a.parseSelectToArray(t)),this.getAction()?.refreshMask(),w.popup?.triggerResize?.()}),f.onChanged=t=>{a.string2Boolean(t.disabled)!=this.isDisabled&&(this.isDisabled=a.string2Boolean(t.disabled)),a.string2Boolean(t.readonly)!=this.isReadOnly&&(this.isReadOnly=a.string2Boolean(t.readonly)),a.string2Boolean(t.visible)!=this.isVisible&&(this.isVisible=a.string2Boolean(t.visible??"1"))},s.ajax&&g.setAjax(s.ajax);const b=w.popup.optionAdapter;let y=(t,e)=>{e||""!=t?(""!=t&&(this.isBeforeSearch=!0),g.search(t).then(t=>{w.popup.triggerResize(),t.hasResults&&setTimeout(()=>{b.resetHighlight()},s.animationtime)}).catch(t=>{console.error("Search error:",t)})):g.clear()},v=null;h.onSearch=(t,e)=>{g.compareSearchTrigger(t)&&(g.isAjax()?(clearTimeout(v),w.popup.showLoading(),v=setTimeout(()=>{y(t,e)},s.delaysearchtime)):y(t,e))},g.setPopup(w.popup),h.onNavigate=t=>{b.navigate(t)},h.onEnter=()=>{b.selectHighlighted()},b.onHighlightChange=(t,e)=>{h.setActiveDescendant(e)},b.onCollapsedChange=()=>{w.popup.triggerResize()},h.onEsc=()=>{this.getAction()?.close(),w.tags.ViewPanel.focus()},this.isDisabled=a.string2Boolean(s.disabled),this.isReadOnly=a.string2Boolean(s.readonly)}deInit(){const t=this.container||{},{selectObserver:e,datasetObserver:i}=t;e?.disconnect&&e.disconnect(),i?.disconnect&&i.disconnect()}getAction(){const t=this.container,e=this,i=a.getBinderMap(t.targetElement);if(!i)return null;const s=i.options;let n={get placeholder(){return t.placeholder.get()},set placeholder(e){t.placeholder?.set(e),t.searchbox?.setPlaceHolder(e)},get oldValue(){return e.oldValue},set value(t){this.setValue(null,t,!0)},get value(){let t=this.valueArray;const e=t.length;return e>1?t:0==e?"":t[0]},get valueArray(){let t=[];return e.getModelOption().forEach(e=>{e.selected&&t.push(e.value)}),t},get valueString(){return this.valueArray.join(s.customDelimiter)},get valueOptions(){let t=[];return e.getModelOption().forEach(e=>{e.selected&&t.push(e)}),t},get mask(){let t=[];return e.getModelOption().forEach(e=>{e.selected&&t.push(e.text)}),t},get valueText(){var t=[];e.getModelOption().forEach(e=>{e.selected&&t.push(e.text)});const i=t.length;return i>1?t:0==i?"":t[0]},get isOpen(){return e.isOpen},selectAll(t,i=!0){if(!(s.multiple&&s.maxSelected>0&&e.getModelOption().length>s.maxSelected)&&!this.disabled&&!this.readonly&&s.multiple){if(i){if(r.callEvent([this],...s.on.beforeChange).isCancel)return;e.oldValue=this.value}e.getModelOption().forEach(t=>{t.selectedNonTrigger=!0}),this.change(!1,i)}},deSelectAll(t,i=!0){if(!this.disabled&&!this.readonly&&s.multiple){if(i){if(r.callEvent([this],...s.on.beforeChange).isCancel)return;e.oldValue=this.value}e.getModelOption().forEach(t=>{t.selectedNonTrigger=!1}),this.change(!1,i)}},setValue(i=null,n,o=!0,h=!1){if(!Array.isArray(n)&&(n=[n]),!(s.multiple&&s.maxSelected>0&&n.length>s.maxSelected)&&(h||!this.disabled&&!this.readonly)){if(o){if(r.callEvent([this],...s.on.beforeChange).isCancel)return;e.oldValue=this.value}e.getModelOption().forEach(t=>{t.selectedNonTrigger=n.some(e=>e==t.value)}),s.multiple||(t.targetElement.value=n[0]),this.change(!1,o)}},open(){if(e.isOpen)return!1;let i=e.Selective.find();if(!i.isEmpty&&i.close().isCancel)return!1;if(this.disabled)return!1;if(r.callEvent([this],...s.on.beforeShow).isCancel)return!1;e.isOpen=!0,t.directive.setDropdown(!0);const n=t.popup.optionAdapter,o=n.getSelectedItem();return o?n.setHighlight(o,!1):n.resetHighlight(),e.hasLoadedOnce&&!e.isBeforeSearch||!s?.ajax||(t.popup.showLoading(),e.hasLoadedOnce=!0,e.isBeforeSearch=!1,setTimeout(()=>{t.popup&&t.searchController&&t.searchController.search("").then(()=>t.popup?.triggerResize?.()).catch(t=>console.error("Initial ajax load error:",t))},s.animationtime)),t.popup.open(),t.searchbox.show(),t.tags.ViewPanel.setAttribute("aria-expanded","true"),r.callEvent([this],...s.on.show),!0},close(){return!!e.isOpen&&!r.callEvent([this],...s.on.beforeClose).isCancel&&(e.isOpen=!1,t.directive.setDropdown(!1),t.popup.close(()=>{t.searchbox.clear(!1)}),t.searchbox.hide(),t.tags.ViewPanel.setAttribute("aria-expanded","false"),r.callEvent([this],...s.on.close),!0)},toggle(){e.isOpen?this.close():this.open()},change(i=null,n=!0){if(n){if(s.multiple&&s.maxSelected>0&&this.valueArray.length>s.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(r.callEvent([this,this.value],...s.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.accessorybox.setModelData(this.valueOptions),n&&(t.targetElement&&r.trigger(t.targetElement,"change"),r.callEvent([this,this.value],...s.on.change),e.options.autoclose&&this.close())},refreshMask(){let i=s.placeholder;!s.multiple&&e.getModelOption().length>0&&(i=this.mask[0]),i??=s.placeholder,t.placeholder.set(i,!1),t.searchbox.setPlaceHolder(i)},on(t,e,i){s.on[e]||(s.on[e]=[]),s.on[e].push(i)},ajax(e,i){t.searchController.setAjax(i)}};return this.createSymProp(n,"disabled","isDisabled"),this.createSymProp(n,"readonly","isReadOnly"),this.createSymProp(n,"visible","isVisible"),n}createSymProp(t,e,i){const s=this;Object.defineProperty(t,e,{get:()=>s[i],set(t){s[i]=t,s.container.targetElement.dataset[e]=t},enumerable:!0,configurable:!0})}getModelOption(t=null){if(!this.optionModelManager)return[];const{modelList:e}=this.optionModelManager.getResources(),i=[];for(const s of e)s instanceof y?i.push(s):s instanceof v&&Array.isArray(s.items)&&s.items.length&&i.push(...s.items);return"boolean"==typeof t?i.filter(e=>e.selected===t):i}}class F{#tt=!1;#J=null;#et=[];onDetect(t){this.#et.push(t)}clearDetect(){this.#et=[]}start(t){if(this.#tt)return;this.#tt=!0;const e=t.toUpperCase(),i=t.toLowerCase();this.#J=new MutationObserver(t=>{t.forEach(t=>{t.addedNodes.forEach(t=>{const s=t;1===s.nodeType&&(s.tagName===e&&this.#it(s),s.querySelectorAll(i).forEach(t=>{this.#it(t)}))})})}),this.#J.observe(document.body,{childList:!0,subtree:!0})}stop(){this.#tt&&(this.#tt=!1,this.#J.disconnect(),this.#J=null)}#it(t){this.#et.forEach(e=>{e(t)})}}class V{EAObserver=null;static bindedQueries=new Map;static bind(t,e){e=a.mergeConfig(a.getDefaultConfig(),e),this.bindedQueries.set(t,e);const i=this,s=a.randomString();a.timerProcess.setExecute(s,()=>{r.callEvent([i.find(t)],...e.on.load),a.timerProcess.clearExecute(s),e.on.load=[]}),a.getElements(t).forEach(t=>{(async()=>{"SELECT"==t.tagName&&(a.removeUnbinderMap(t),this.applySelectBox(t,e)&&a.timerProcess.run(s))})()}),a.getBindedCommand().includes(t)||a.getBindedCommand().push(t)}static find(t="*"){let e={isEmpty:!0};if("*"==t&&""==(t=a.getBindedCommand().join(", ")))return e;const i=a.getElements(t);if(0==i.length)return e;const s=a.getBinderMap(i[0]);if(!s)return e;for(let n in s.action)e[n]=this.#st(n,s.action);if(e){let t={};for(let s in e){const n=e[s];switch(n.type){case"get-set":this.#nt(t,n.name,i);break;case"func":this.#ot(t,n.name,i)}}return t.isEmpty=!1,t}}static Observer(){this.EAObserver=new F,this.EAObserver.onDetect(t=>{this.bindedQueries.forEach((e,i)=>{try{t.matches(i)&&this.applySelectBox(t,e)}catch(s){console.warn("Invalid selector: "+i,s)}})}),this.EAObserver.start("select")}static destroy(t=null){null===t?this.destroyAll():"string"==typeof t?this.destroyByQuery(t):t instanceof HTMLSelectElement&&this.destroyElement(t)}static destroyAll(){a.getBindedCommand().forEach(t=>{this.destroyByQuery(t)}),this.bindedQueries.clear(),a.getBindedCommand().length=0,this.EAObserver.stop()}static destroyByQuery(t){a.getElements(t).forEach(t=>{"SELECT"===t.tagName&&this.destroyElement(t)}),this.bindedQueries.delete(t);const e=a.getBindedCommand(),i=e.indexOf(t);i>-1&&e.splice(i,1)}static destroyElement(t){const e=a.getBinderMap(t);if(!e)return;a.setUnbinderMap(t,e);const i=!!this.EAObserver;i&&this.EAObserver.stop();try{e.self.deInit?.()}catch(n){}const s=e.container?.element||t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.selectiveId,s&&s.parentNode?s.parentNode.replaceChild(t,s):document.body.appendChild(t),a.removeBinderMap(t),i&&this.bindedQueries.size>0&&this.EAObserver.start("select")}static rebind(t,e){this.destroyByQuery(t),this.bind(t,e)}static applySelectBox(t,e){if(a.getBinderMap(t)||a.getUnbinderMap(t))return!1;const i=a.randomString(8),s=a.buildConfig(t,e);s.SEID=i,s.SEID_LIST=`seui-${i}-optionlist`,s.SEID_HOLDER=`seui-${i}-placeholder`;const n={options:s};a.setBinderMap(t,n);const o=new j(t,this);return n.container=o.container,n.action=o.getAction(),n.self=o,o.container.view.addEventListener("mouseup",()=>{n.action.toggle()}),!0}static#st(t,e){const i=Object.getOwnPropertyDescriptor(e,t);let s="variable";return i.get||i.set&&"function"!=typeof e[t]?s="get-set":"function"==typeof e[t]&&(s="func"),{type:s,name:t}}static#nt(t,e,i){Object.defineProperty(t,e,{get:()=>a.getBinderMap(i[0]).action[e],set(t){i.forEach(i=>{const s=a.getBinderMap(i);s&&(s.action[e]=t)})},enumerable:!0,configurable:!0})}static#ot(t,e,i){t[e]=(...s)=>{for(let t=0;t<i.length;t++){const n=a.getBinderMap(i[t]);if(!n)continue;const o=r.buildEventToken();if(n.action[e](o.callback,...s),!o.token.isContinue)break}return t}}}const $="1.0.3",k="SelectiveUI",D=(R=k,"undefined"!=typeof window&&(window[R]&&window[R].__loaded?(console.warn(`[${R}] Already loaded (v${window[R].__version}). Using existing instance. Please remove duplicate <script> tags.`),!0):(window[R]=window[R]||{},window[R].__loading=!0,!1)));var R;if(!D){let z=!1;function N(){z||(z=!0,document.addEventListener("mousedown",()=>{const t=a.getBindedCommand();if(t.length>0){const e=V.find(t.join(", "));e.isEmpty||e.close()}}),V.Observer(),((t,e,i)=>{"undefined"!=typeof window&&(window[t].__loaded=!0,window[t].__loading=!1,window[t].__version=e,Object.assign(window[t],i),Object.freeze(window[t]),console.log(`[${t}] v${e} loaded successfully`))})(k,$,{bind:i,find:s,destroy:n,rebind:o,effector:h,version:$}))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",N):N()}t.bind=i,t.destroy=n,t.effector=h,t.find=s,t.name=k,t.rebind=o,t.version=$},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
1
+ /*! Selective UI v1.0.4 | MIT License */
2
+ var t,e;t=this,e=function(t){"use strict";function e(t){return new class{element;#t=null;#e=null;#i=!1;constructor(t=null){t&&this.setElement(t)}setElement(t){this.element="string"==typeof t?document.querySelector(t):t}cancel(){return this.#t&&(clearTimeout(this.#t),this.#t=null),this.#e&&(clearTimeout(this.#e),this.#e=null),this.#i=!1,this}getHiddenDimensions(t="flex"){const e={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const i=window.getComputedStyle(this.element),s=parseFloat(i.borderTopWidth),n=parseFloat(i.borderBottomWidth),o=this.element.scrollHeight+s+n,h=this.element.getBoundingClientRect(),l={width:h.width,height:h.height+s+n,scrollHeight:o};return Object.assign(this.element.style,e),l}expand(t){this.cancel(),this.#i=!0;const{duration:e=200,display:i="flex",width:s,left:n,top:o,maxHeight:h,realHeight:l,position:a="bottom",onComplete:r}=t;return Object.assign(this.element.style,{display:i,width:s+"px",left:n+"px",top:("bottom"===a?o:o+l)+"px",maxHeight:h+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===a),this.element.classList.toggle("position-bottom","bottom"===a),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${e}ms, height ${e}ms, opacity ${e}ms`,top:o+"px",height:l+"px",opacity:"1",overflow:l>=h?"auto":"hidden"}),this.#t=setTimeout(()=>{this.element.style.transition="none",this.#i=!1,r&&r()},e)}),this}collapse(t){this.cancel(),this.#i=!0;const{duration:e=200,onComplete:i}=t,s=this.element.offsetHeight,n=this.element.offsetTop,o=this.element.classList.contains("position-top")?"top":"bottom",h=this.element.scrollHeight-this.element.offsetHeight>0,l="top"===o?n+s:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${e}ms, top ${e}ms, opacity ${e}ms`,height:"0px",top:l+"px",opacity:"0",overflow:h?"auto":"hidden"}),this.#t=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.#i=!1,i&&i()},e)}),this}showSwipeWidth(t){this.cancel(),this.#i=!0;const{duration:e=200,display:i="block",onComplete:s}=t;Object.assign(this.element.style,{transition:"none",display:i,width:"fit-content"});const n=this.getHiddenDimensions(i).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${e}ms`,width:n+"px",overflow:"hidden"})}),this.#t=setTimeout(()=>{Object.assign(this.element.style,{width:null,overflow:null,transition:null}),this.#i=!1,s&&s()},e),this}hideSwipeWidth(t){this.cancel(),this.#i=!0;const{duration:e=200,onComplete:i}=t,s=this.getHiddenDimensions().width;return Object.assign(this.element.style,{transition:"none",width:s+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${e}ms`,width:"0px",overflow:"hidden"})}),this.#t=setTimeout(()=>{Object.assign(this.element.style,{width:null,overflow:null,transition:null,display:null}),this.#i=!1,i&&i()},e),this}resize(t){this.#e&&clearTimeout(this.#e);const{duration:e=200,width:i,left:s,top:n,maxHeight:o,realHeight:h,position:l="bottom",animate:a=!0,onComplete:r}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==l,u=this.element.scrollHeight>o;return this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),c&&(this.element.style.transition=`top ${e}ms ease-out, height ${e}ms ease-out, max-height ${e}ms ease-out;`),requestAnimationFrame(()=>{const t={width:i+"px",left:s+"px",top:n+"px",maxHeight:o+"px",height:h+"px",overflowY:u?"auto":"hidden"};a&&(c||Math.abs(this.element.offsetHeight-h)>5)?t.transition=`height ${e}ms, top ${e}ms`:this.#e=setTimeout(()=>{this.element.style.transition="none"},e),Object.assign(this.element.style,t),a&&(c||Math.abs(this.element.offsetHeight-h)>1)?this.#e=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,r&&r()},e):(c&&delete this.element.style.transition,r&&r())}),this}get isAnimating(){return this.#i}}(t)}function i(t,e={}){if(R&&"undefined"!=typeof window&&window[k])return window[k].bind(t,e);V.bind(t,e)}function s(t){return R&&"undefined"!=typeof window&&window[k]?window[k].find(t):V.find(t)}function n(t){return R&&"undefined"!=typeof window&&window[k]?window[k].destroy(t):V.destroy(t)}function o(t,e={}){return R&&"undefined"!=typeof window&&window[k]?window[k].rebind(t,e):V.rebind(t,e)}function h(t){return R&&"undefined"!=typeof window&&window[k]?window[k].effector(t):e(t)}class l{defaultConfig={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}};bindedMap=new Map;unbindedMap=new Map;bindedCommand=[]}class a{static#s=null;static get iStorage(){return!this.#s&&(this.#s=new l),this.#s}static timerProcess={executeStored:{},setExecute:function(t,e,i=50,s=!1){this.executeStored[t]||(this.executeStored[t]=[]),this.executeStored[t].push({execute:e,timeout:i,once:s})},clearExecute:function(t){delete this.executeStored[t]},run:function(t,...e){let i=this.executeStored[t];this.timerRunner[t]||(this.timerRunner[t]={});for(const s in i){const n=i[s];this.timerRunner[t][s]||(this.timerRunner[t][s]={}),n&&(clearTimeout(this.timerRunner[t][s]),this.timerRunner[t][s]=setTimeout(()=>{n&&n.execute(e.length>0?e:null),n.once&&delete this.executeStored[t][s]},n.timeout))}},timerRunner:{}};static isNullOrEmpty(t){return"boolean"!=typeof t&&(null==t||""===t||0===t||"0"===t)}static jsCopyObject(t){if(null===t||"object"!=typeof t)return t;let e=Array.isArray(t)?[]:{};for(let i in t)t.hasOwnProperty(i)&&(e[i]=this.jsCopyObject(t[i]));return e}static randomString(t=6){let e="";for(let i=0;i<t;i++)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return e}static getElements(t){if(!t)return[];if("string"==typeof t){const e=document.querySelectorAll(t);return Array.from(e)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static nodeCreator(t={}){return this.nodeCloner(document.createElement(t.node),t,!0)}static nodeCloner(t=document.documentElement,e=null,i=!1){const s={...e},n=i?t:this.nodeToElement(t.cloneNode(!0));return"string"==typeof s.classList?n.classList.add(s.classList):Array.isArray(s.classList)&&n.classList.add(...s.classList),delete s.classList,["style","dataset"].forEach(t=>{Object.assign(n[t],s[t]),delete s[t]}),s.role&&(n.setAttribute("role",s.role),delete s.role),s.ariaLive&&(n.setAttribute("aria-live",s.ariaLive),delete s.ariaLive),s.ariaLabelledby&&(n.setAttribute("aria-labelledby",s.ariaLabelledby),delete s.ariaLabelledby),s.ariaControls&&(n.setAttribute("aria-controls",s.ariaControls),delete s.ariaControls),s.ariaHaspopup&&(n.setAttribute("aria-haspopup",s.ariaHaspopup),delete s.ariaHaspopup),s.ariaMultiselectable&&(n.setAttribute("aria-multiselectable",s.ariaMultiselectable),delete s.ariaMultiselectable),s.ariaAutocomplete&&(n.setAttribute("aria-autocomplete",s.ariaAutocomplete),delete s.ariaAutocomplete),s.event&&(Object.entries(s.event).forEach(([t,e])=>{n.addEventListener(t,e)}),delete s.event),Object.entries(s).forEach(([t,e])=>{null===e?n.removeAttribute(t):n[t]=e}),n}static nodeToElement(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static mountView(t){return this.mountNode(t)}static mountNode(t,e=null,i=!1,s=!1,n={}){let o=null;for(let h in t){const l=t[h],a=l.tag?.tagName?l.tag:this.nodeCreator(l.tag);n[h]=a,l.child&&this.mountNode(l.child,a,!1,!1,n),e?i?e.prepend(a):e.append(a):s||o||(o=a)}return s||(n.id=this.randomString(7),e||(n={tags:n,view:o})),n}static setStyle(t,e,i=null){const s="string"==typeof e?{[e]:i}:{...e},n=this.getElements(t);if(n&&"object"==typeof n)for(let o=0;o<n.length;o++){const t=n[o];t&&Object.assign(t.style,s)}}static buildConfig(t,e){let i=this.jsCopyObject(e);for(let s in i)t[s]?i[s]=t[s]:void 0!==t?.dataset[s]&&(i[s]=t.dataset[s]);return i}static mergeConfig(...t){if(0==t.length)return{};if(1==t.length)return this.jsCopyObject(t[0]);{const e=this.jsCopyObject(t[0]);for(let i=1;i<t.length;i++){const s=t[i];for(let t in s)if("on"==t){const i=s[t];for(let s in i)e[t][s].push(i[s])}else e[t]=s[t]}return e}}static string2Boolean(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static removeBinderMap(t){return this.iStorage.bindedMap.delete(t)}static getBinderMap(t){return this.iStorage.bindedMap.get(t)}static setBinderMap(t,e){this.iStorage.bindedMap.set(t,e)}static removeUnbinderMap(t){return this.iStorage.unbindedMap.delete(t)}static getUnbinderMap(t){return this.iStorage.unbindedMap.get(t)}static setUnbinderMap(t,e){this.iStorage.unbindedMap.set(t,e)}static getDefaultConfig(){return this.iStorage.defaultConfig}static getBindedCommand(){return this.iStorage.bindedCommand}static tagTranslate(t){if(null==t)return"";t=(t+"").replace(/&lt;`/g,"<").replace(/`&gt;/g,">").replace(/<`/g,"<").replace(/`>/g,">").trim();const e=globalThis?.document;if(!e||"function"!=typeof e.createElement)return(t=(t=t.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,"")).replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,"")).replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,"");const i=e.createElement("div");return i.innerHTML=t,i.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),i.querySelectorAll("*").forEach(t=>{[...t.attributes].forEach(e=>{const i=e.name||"",s=e.value||"";(/^on/i.test(i)||/^(href|src|xlink:href)$/i.test(i)&&/^javascript:/i.test(s))&&t.removeAttribute(i)})}),(i.innerHTML||"").trim()}static stripHtml(t){let e=document.createElement("DIV");e.innerHTML=t;let i=e.textContent||e.innerText||"";return e.remove(),i.trim()}static string2normalize(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static parseSelectToArray(t){const e=[];return Array.from(t.children).forEach(t=>{"OPTGROUP"===t.tagName?(e.push(t),Array.from(t.children).forEach(i=>{i.__parentGroup=t,e.push(i)})):"OPTION"===t.tagName&&e.push(t)}),e}static IsIOS(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static any2px(t){const e=(t+"").trim();if(e.endsWith("px"))return e;if(e.endsWith("vh"))return window.innerHeight*parseFloat(e)/100+"px";if(e.endsWith("vw"))return window.innerWidth*parseFloat(e)/100+"px";const i=parseFloat(getComputedStyle(document.documentElement).fontSize);if(e.endsWith("rem"))return i*parseFloat(e)+"px";const s=this.nodeCreator({node:"div",style:{height:e,opacity:0}});document.body.appendChild(s);const n=s.offsetHeight+"px";return s.remove(),n}}class r{static buildEventToken(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},callback:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static callEvent(t,...e){const{token:i,callback:s}=this.buildEventToken();for(let n=0;n<e.length;n++){const o=e[n];if("function"==typeof o&&(t&&Array.isArray(t)?o(s,...t):o(s),i.isCancel||!i.isContinue))break}return i}static trigger(t,e,i={bubbles:!0,cancelable:!0}){const s=new Event(e,i);return t.dispatchEvent(s),s}static callFunctions(t,...e){if(Array.isArray(t))for(const i of t)"function"==typeof i&&i(...e)}}class c{static resizeBox(t,e){const i=a.getBinderMap(t).options,s=i.minWidth,n=i.minHeight;let o=t.offsetWidth+"px",h=t.offsetHeight+"px";parseInt(i.width,10)>0&&(o=i.width),parseInt(i.height,10)>0&&(h=i.height),a.setStyle(e,{width:o,height:h,minWidth:s,minHeight:n})}}class u{constructor(t){t&&this.init(t)}node=null;#n=null;init(t){this.node=a.nodeCreator({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.#n=t}get(){return this.#n.placeholder}set(t,e=!0){e&&(this.#n.placeholder=t),t=a.tagTranslate(t),this.node.innerHTML=this.#n.allowHtml?t:a.stripHtml(t)}}class d{constructor(){this.#o()}node=null;#o(){this.node=a.nodeCreator({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}setDropdown(t){t?this.node.classList.add("drop-down"):this.node.classList.remove("drop-down")}}class p{nodeMounted;node;options=null;#h=[];#l=[];constructor(t=null){t&&this.init(t)}init(t){this.nodeMounted=a.mountNode({OptionHandle:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},child:{SelectAll:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{r.callFunctions(this.#h)}}},DeSelectAll:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{r.callFunctions(this.#l)}}}}}}),this.node=this.nodeMounted.view,this.options=t}available(){return a.string2Boolean(this.options.multiple)&&a.string2Boolean(this.options.selectall)}refresh(){this.available()?this.show():this.hide()}show(){this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}OnSelectAll(t=null){this.#h.push(t)}OnDeSelectAll(t=null){this.#l.push(t)}}class g{isInit=!1;element=null;#a=null;#r=null;#c;constructor(){this.isInit=!0,this.#c=this.#u.bind(this)}onChanged(t){}#u(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.onChanged({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const e=t.getBoundingClientRect(),i="function"==typeof window?.getComputedStyle?window.getComputedStyle(t):null;this.onChanged({width:e?.width??0,height:e?.height??0,top:e?.top??0,left:e?.left??0,padding:{top:parseFloat(i?.paddingTop??"0"),right:parseFloat(i?.paddingRight??"0"),bottom:parseFloat(i?.paddingBottom??"0"),left:parseFloat(i?.paddingLeft??"0")},border:{top:parseFloat(i?.borderTopWidth??"0"),right:parseFloat(i?.borderRightWidth??"0"),bottom:parseFloat(i?.borderBottomWidth??"0"),left:parseFloat(i?.borderLeftWidth??"0")},margin:{top:parseFloat(i?.marginTop??"0"),right:parseFloat(i?.marginRight??"0"),bottom:parseFloat(i?.marginBottom??"0"),left:parseFloat(i?.marginLeft??"0")}})}trigger(){this.#u()}connect(t){if(!(t instanceof Element))throw Error("Element không hợp lệ");this.element=t,this.#a=new ResizeObserver(this.#c),this.#a.observe(t),this.#r=new MutationObserver(this.#c),this.#r.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.#c,!0),window.addEventListener("resize",this.#c),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.#c),window.visualViewport.addEventListener("scroll",this.#c))}disconnect(){this.#a?.disconnect?.(),this.#r?.disconnect?.(),this.onChanged=()=>{},window.removeEventListener("scroll",this.#c,!0),window.removeEventListener("resize",this.#c),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.#c),window.visualViewport.removeEventListener("scroll",this.#c)),this.#a=null,this.#r=null,this.element=null}}class m{targetElement=null;options=null;view=null;position=-1;isInit=!1;get value(){return this.targetElement.getAttribute("value")}constructor(t,e=null,i=null){this.options=t,this.targetElement=e,this.view=i}update(t){this.targetElement=t,this.onTargetChanged()}onTargetChanged(){}}class f{parent=null;constructor(t){this.parent=t}render(){}update(){}view=null;getView(){return this.view.view}getTag(t){return this.view.tags[t]}getTags(){return this.view.tags}}class w extends f{view;render(){const t=a.randomString(7);this.view=a.mountView({GroupView:{tag:{node:"div",classList:["selective-ui-group"],role:"group",ariaLabelledby:`seui-${t}-header`,id:`seui-${t}-group`},child:{GroupHeader:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},GroupItems:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.updateLabel()}updateLabel(t=null){null!==t&&(this.view.tags.GroupHeader.textContent=t)}getItemsContainer(){return this.view.tags.GroupItems}updateVisibility(){const t=Array.from(this.view.tags.GroupItems.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}setCollapsed(t){this.view.view.classList.toggle("collapsed",t),this.view.tags.GroupHeader.setAttribute("aria-expanded",t?"false":"true")}}class b extends f{view;isMultiple=!1;hasImage=!1;optionConfig=null;render(){const t=["selective-ui-option-view"],e=a.randomString(7),i="option_"+e;this.isMultiple&&t.push("multiple"),this.hasImage&&(t.push("has-image"),t.push("image-"+this.optionConfig?.imagePosition));const s={OptionInput:{tag:{node:"input",type:this.isMultiple?"checkbox":"radio",classList:"allow-choice",id:i}},...this.hasImage&&{OptionImage:{tag:{node:"img",classList:"option-image",style:{width:this.optionConfig?.imageWidth||"60px",height:this.optionConfig?.imageHeight||"60px",borderRadius:this.optionConfig?.imageBorderRadius||"4px"}}}},OptionLabel:{tag:{node:"label",htmlFor:i,classList:["align-vertical-"+this.optionConfig?.labelValign,"align-horizontal-"+this.optionConfig?.labelHalign]},child:{LabelContent:{tag:{node:"div"}}}}};this.view=a.mountView({OptionView:{tag:{node:"div",id:`seui-${e}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},child:s}}),this.parent.appendChild(this.view.view),this.applyConfigToDOM()}update(){this.applyConfigToDOM()}applyConfigToDOM(){const t=this.view;if(!t||!t.view)return;const e=t.view,i=t.tags?.OptionInput,s=t.tags?.OptionLabel,n=!!this.isMultiple,o=!!this.hasImage,h=this.optionConfig?.imagePosition||"right",l=this.optionConfig?.imageWidth||"60px",a=this.optionConfig?.imageHeight||"60px",r=this.optionConfig?.imageBorderRadius||"4px",c=this.optionConfig?.labelValign||"center",u=this.optionConfig?.labelHalign||"left",d=["selective-ui-option-view"];if(n&&d.push("multiple"),o&&d.push("has-image","image-"+h),e.className=d.join(" "),i){const t=n?"checkbox":"radio";i.type!==t&&(i.type=t)}s&&(s.className=`align-vertical-${c} align-horizontal-${u}`);let p=t.tags?.OptionImage;if(o){p||(p=document.createElement("img"),p.className="option-image",s&&s.parentElement?e.insertBefore(p,s):e.appendChild(p),t.tags.OptionImage=p);const i=p.style;i.width=l,i.height=a,i.borderRadius=r}else p&&(p.remove(),t.tags.OptionImage=null)}}class y extends m{#d=[];#p=[];#g=[];#m=!0;#f=!1;group=null;get imageSrc(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.imageSrc}get value(){return this.targetElement.value}get selected(){return this.targetElement.selected}set selected(t){this.selectedNonTrigger=t,r.callEvent([this,t],...this.#d)}get visible(){return this.#m}set visible(t){if(this.#m===t)return;this.#m=t;const e=this.view?.getView();e&&e.classList.toggle("hide",!t),r.callEvent([this,t],...this.#g)}get selectedNonTrigger(){return this.selected}set selectedNonTrigger(t){const e=this.view?.getTag("OptionInput"),i=this.view?.getView();e&&(e.checked=t),i&&(i.classList.toggle("checked",!!t),i.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement.selected=t,r.callEvent([this,t],...this.#p)}get text(){const t=a.tagTranslate(this.dataset?.mask??this.targetElement.text);return this.options.allowHtml?t:a.stripHtml(t)}get textContent(){return this.options.allowHtml?a.stripHtml(this.text).trim():this.text.trim()}get dataset(){return this.targetElement.dataset??{}}get highlighted(){return this.#f}set highlighted(t){const e=!!t,i=this.view?.getView?.();this.#f!==e&&(this.#f=e),i&&i.classList.toggle("highlight",e)}onSelected(t){this.#d.push(t)}onInternalSelected(t){this.#p.push(t)}onVisibilityChanged(t){this.#g.push(t)}onTargetChanged(){const t=this.view.getTag("LabelContent");t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const e=this.view.getTag("OptionImage");e&&this.hasImage&&(e.src=this.imageSrc,e.alt=this.text),this.selectedNonTrigger=this.targetElement.selected}}class v extends m{label="";items=[];collapsed=!1;#w=[];constructor(t,e){super(t,e),e&&(this.label=e.label,this.collapsed=a.string2Boolean(e.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get selectedItems(){return this.items.filter(t=>t.selected)}get visibleItems(){return this.items.filter(t=>t.visible)}get hasVisibleItems(){return this.visibleItems.length>0}update(t){this.label=t.label,this.view&&this.view.updateLabel(this.label)}onTargetChanged(){this.view&&(this.view.updateLabel(this.label),this.view.setCollapsed(this.collapsed))}onCollapsedChanged(t){this.#w.push(t)}toggleCollapse(){this.collapsed=!this.collapsed,this.view&&this.view.setCollapsed(this.collapsed),r.callEvent([this,this.collapsed],...this.#w)}addItem(t){this.items.push(t),t.group=this}removeItem(t){const e=this.items.indexOf(t);e>-1&&(this.items.splice(e,1),t.group=null)}updateVisibility(){this.view&&this.view.updateVisibility()}}class x{items=[];adapterKey=a.randomString(12);isSkipEvent=!1;constructor(t=[]){this.items=t,this.onInit()}onInit(){}onViewHolder(t,e,i){t.isInit?e.update():e.render()}onPropChanging(t,e){a.timerProcess.setExecute(`${t}ing_${this.adapterKey}`,e,1)}onPropChanged(t,e){a.timerProcess.setExecute(`${t}_${this.adapterKey}`,e)}changeProp(t,...e){a.timerProcess.run(`${t}_${this.adapterKey}`,...e)}changingProp(t,...e){a.timerProcess.run(`${t}ing_${this.adapterKey}`,...e)}viewHolder(t,e){return null}itemCount(){return this.items.length}setItems(t){this.changingProp("items",t),this.items=t,this.changeProp("items",t)}syncFromSource(t){this.setItems(t)}updateRecyclerView(t){for(let e=0;e<this.itemCount();e++){let i=this.items[e].view;this.items[e].isInit||(i=this.viewHolder(t,this.items[e])),this.onViewHolder(this.items[e],i,e),this.items[e].isInit=!0}}updateData(t){}}class O{#b=[];#y;#v;#x;#O;options=null;constructor(t){this.options=t}setupAdapter(t){this.#y=t}setupRecyclerView(t){this.#x=t}createModelResources(t){this.#b=[];let e=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)e=new v(this.options,t),this.#b.push(e);else if("OPTION"===t.tagName){const i=new y(this.options,t);t.__parentGroup&&e&&t.__parentGroup===e.targetElement?(e.addItem(i),i.group=e):(this.#b.push(i),e=null)}}),this.#b}replace(t){this.createModelResources(t),this.#v&&this.#v.syncFromSource(this.#b),this.refresh()}notify(){this.#v&&this.refresh()}load(t,e={},i={}){this.#v=new this.#y(this.#b),Object.assign(this.#v,e),this.#O=new this.#x(t),this.#O.setAdapter(this.#v),Object.assign(this.#O,i)}update(t){const e=this.#b,i=[],s=new Map,n=new Map;e.forEach(t=>{t instanceof v?s.set(t.label,t):t instanceof y&&n.set(t.value,t)});let o=null,h=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){let e=t;const n=s.get(e.label);n?(n.update(e),n.position=h,n.items=[],o=n,i.push(n),s.delete(e.label)):(o=new v(this.options,e),o.position=h,i.push(o)),h++}else if("OPTION"===t.tagName){let e=t;const s=n.get(e.value);if(s)s.update(e),s.position=h,e.__parentGroup&&o?(o.addItem(s),s.group=o):(s.group=null,i.push(s)),n.delete(e.value);else{const t=new y(this.options,e);t.position=h,e.__parentGroup&&o?(o.addItem(t),t.group=o):i.push(t)}h++}}),s.forEach(t=>{t.view&&t.view.getView()?.remove()}),n.forEach(t=>{t.view&&t.view.getView()?.remove()}),this.#b=i,this.#v&&this.#v.updateData(this.#b),this.onUpdated(),this.refresh()}onUpdated(){}skipEvent(t){this.#v.isSkipEvent=t}refresh(){this.#O&&(this.#O.refresh(),this.onUpdated())}getResources(){return{modelList:this.#b,adapter:this.#v,recyclerView:this.#O}}triggerChanging(t){this.#v.changingProp(t)}triggerChanged(t){this.#v.changeProp(t)}}class C{node=null;options=null;constructor(t=null){t&&this.init(t)}init(t){this.options=t,this.node=a.nodeCreator({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}get isVisible(){return!this.node.classList.contains("hide")}}class S{node=null;options=null;constructor(t=null){t&&this.init(t)}init(t){this.options=t,this.node=a.nodeCreator({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",t),this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}get isVisible(){return!this.node.classList.contains("hide")}}class A extends x{isMultiple=!1;#C=[];#S=-1;#A=null;groups=[];flatOptions=[];constructor(t=[]){super(t),this.#T()}#T(){this.flatOptions=[],this.groups=[],this.items.forEach(t=>{t instanceof v?(this.groups.push(t),this.flatOptions.push(...t.items)):t instanceof y&&this.flatOptions.push(t)})}viewHolder(t,e){return e instanceof v?new w(t):new b(t)}onViewHolder(t,e,i){t.position=i,t instanceof v?this.#L(t,e,i):t instanceof y&&this.#M(t,e,i),t.isInit=!0}#L(t,e,i){super.onViewHolder(t,e,i),t.view=e;const s=e.getTag("GroupHeader");s.textContent=t.label,t.isInit||(s.style.cursor="pointer",s.addEventListener("click",()=>{t.toggleCollapse()}),t.onCollapsedChanged((t,e,i)=>{e.items.forEach(t=>{const e=t.view?.getView();e&&(e.style.display=i?"none":"")}),this.onCollapsedChange(e,i)}));const n=e.getItemsContainer();t.items.forEach((t,e)=>{let i=t.view;t.isInit||(i=new b(n)),this.#M(t,i,e),t.isInit=!0}),e.setCollapsed(t.collapsed),e.updateVisibility()}#M(t,e,i){if(e.isMultiple=this.isMultiple,e.hasImage=t.hasImage,e.optionConfig={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.isInit?e.update():super.onViewHolder(t,e,i),t.view=e,t.hasImage){const i=e.getTag("OptionImage");i&&(i.src=t.imageSrc,i.alt=t.text)}e.getTag("LabelContent").innerHTML=t.text,t.isInit||(e.getTag("OptionView").addEventListener("click",e=>{e.stopPropagation(),e.preventDefault(),this.isSkipEvent||(this.isMultiple?(this.changingProp("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.changingProp("select"),setTimeout(()=>{this.#A&&(this.#A.selected=!1),t.selected=!0},5)))}),e.getTag("OptionView").title=t.textContent,e.getTag("OptionView").addEventListener("mouseenter",()=>{this.isSkipEvent||this.setHighlight(this.flatOptions.indexOf(t),!1)}),t.onSelected(()=>{this.changeProp("selected")}),t.onInternalSelected((e,i,s)=>{s&&(this.#A=t),this.changeProp("selected_internal")}),t.onVisibilityChanged((t,e)=>{e.group&&e.group.updateVisibility(),this.#H()})),t.selected&&(this.#A=t,t.selectedNonTrigger=!0)}setItems(t){this.changingProp("items",t),this.items=t,this.#T(),this.changeProp("items",t)}syncFromSource(t){this.setItems(t)}updateData(t){this.items=t,this.#T()}getSelectedItems(){return this.flatOptions.filter(t=>t.selected)}getSelectedItem(){return this.flatOptions.find(t=>t.selected)}checkAll(t){this.isMultiple&&this.flatOptions.forEach(e=>{e.selected=t})}onVisibilityChanged(t){this.#C.push(t)}#H(){const t=this.flatOptions.filter(t=>t.visible).length,e=this.flatOptions.length;this.#C.forEach(i=>{i({visibleCount:t,totalCount:e,hasVisible:t>0,isEmpty:0===e})})}getVisibilityStats(){const t=this.flatOptions.filter(t=>t.visible).length,e=this.flatOptions.length;return{visibleCount:t,totalCount:e,hasVisible:t>0,isEmpty:0===e}}resetHighlight(){this.setHighlight(0)}navigate(t,e=!0){const i=this.flatOptions.filter(t=>t.visible);if(0===i.length)return;let s=i.findIndex(t=>t===this.flatOptions[this.#S]);-1===s&&(s=-1);let n=s+t;n>=i.length&&(n=0),n<0&&(n=i.length-1);const o=this.flatOptions.indexOf(i[n]);this.setHighlight(o,e)}selectHighlighted(){if(this.#S>-1&&this.flatOptions[this.#S]){const t=this.flatOptions[this.#S];if(t.visible){const e=t.view?.getView();e&&e.click()}}}setHighlight(t,e=!0){let i=0;if("number"==typeof t)i=t;else if(t instanceof y){const e=this.flatOptions.indexOf(t);i=e>-1?e:0}else i=0;this.#S>-1&&this.flatOptions[this.#S]&&(this.flatOptions[this.#S].highlighted=!1);for(let s=i;s<this.flatOptions.length;s++){const t=this.flatOptions[s];if(t.visible){if(t.highlighted=!0,this.#S=s,e){const e=t.view?.getView();e&&e.scrollIntoView({block:"center",behavior:"smooth"})}return void this.onHighlightChange(s,t.view?.getView()?.id)}}}onHighlightChange(t,e){}onCollapsedChange(t,e){}}class T{#P;constructor(t=null,e=null,i=null){this.#P=i,t&&e&&this.init(t,e)}options=null;isCreated=!1;optionAdapter=null;node=null;#E=null;#I;#j=null;optionHandle=null;emptyState=null;loadingState=null;recyclerView=null;#F=null;#V=null;#$=null;init(t,e){this.optionHandle=new p(e),this.emptyState=new C(e),this.loadingState=new S(e);const i=a.mountNode({PopupContainer:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:e.panelHeight}},child:{OptionHandle:{tag:this.optionHandle.node},OptionsContainer:{tag:{id:e.SEID_LIST,node:"div",classList:"selective-ui-options-container",role:"listbox"}},LoadingState:{tag:this.loadingState.node},EmptyState:{tag:this.emptyState.node}}}});this.node=i.view,this.#F=i.tags.OptionsContainer,this.#j=a.getBinderMap(t),this.options=e,this.#P.load(this.#F,{isMultiple:e.multiple});const s=this.#P.getResources();this.optionAdapter=s.adapter,this.recyclerView=s.recyclerView,this.optionHandle.OnSelectAll(()=>{s.adapter.checkAll(!0)}),this.optionHandle.OnDeSelectAll(()=>{s.adapter.checkAll(!1)}),this.#k()}async showLoading(){clearTimeout(this.#$),this.#P.skipEvent(!0),!1!==a.string2Boolean(this.options.loadingfield)&&(this.loadingState.show(this.optionAdapter.getVisibilityStats().hasVisible),this.optionHandle.hide(),this.triggerResize())}async hideLoading(){clearTimeout(this.#$),this.#$=setTimeout(()=>{this.#P.skipEvent(!1),this.loadingState.hide();const t=this.optionAdapter.getVisibilityStats();this.#R(t),this.triggerResize()},200)}#k(){this.optionAdapter.onVisibilityChanged(t=>{this.#R(t)}),this.optionAdapter.onPropChanged("items",()=>{const t=this.optionAdapter.getVisibilityStats();this.#R(t),this.triggerResize()})}#R(t=null){t||(t=this.optionAdapter.getVisibilityStats()),t?.isEmpty?(this.emptyState.show("nodata"),this.#F.classList.add("hide"),this.optionHandle.hide()):t&&!t.hasVisible?(this.emptyState.show("notfound"),this.#F.classList.add("hide"),this.optionHandle.hide()):(this.emptyState.hide(),this.#F.classList.remove("hide"),this.optionHandle.refresh())}onAdapterPropChanging(t,e){this.optionAdapter.onPropChanging(t,e)}onAdapterPropChanged(t,e){this.optionAdapter.onPropChanged(t,e)}setupEffector(t){this.#E=t}open(t=null){this.isCreated||(document.body.appendChild(this.node),this.isCreated=!0,this.#I=new g,this.#E.setElement(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.optionHandle.refresh(),this.#R();const e=this.#D(),{position:i,top:s,maxHeight:n,realHeight:o}=this.#z(e);this.#E.expand({duration:this.options.animationtime,display:"flex",width:e.width,left:e.left,top:s,maxHeight:n,realHeight:o,position:i,onComplete:()=>{this.#I.onChanged=t=>this.#N(t),this.#I.connect(this.#j.container.tags.ViewPanel),t&&t()}})}close(t=null){this.isCreated&&(this.#I.disconnect(),this.#E.collapse({duration:this.options.animationtime,onComplete:t}))}triggerResize(){this.isCreated&&this.#I.trigger()}setupInfiniteScroll(t,e){this.#V=async()=>{const e=t.getPaginationState();if(!e.isPaginationEnabled)return;const i=this.node;if(i.scrollHeight-i.scrollTop-i.clientHeight<100&&!e.isLoading&&e.hasMore){const e=await t.loadMore();!e.success&&e.message&&console.log("Load more:",e.message)}},this.node.addEventListener("scroll",this.#V)}#D(){const t=this.#j.container.tags.ViewPanel,e=t.getBoundingClientRect(),i=window.getComputedStyle(t),s=window.visualViewport,n=a.IsIOS();return{width:e.width,height:e.height,top:e.top-(s&&n?s.offsetTop:0),left:e.left-(s&&n?s.offsetLeft:0),padding:{top:parseFloat(i.paddingTop),right:parseFloat(i.paddingRight),bottom:parseFloat(i.paddingBottom),left:parseFloat(i.paddingLeft)},border:{top:parseFloat(i.borderTopWidth),right:parseFloat(i.borderRightWidth),bottom:parseFloat(i.borderBottomWidth),left:parseFloat(i.borderLeftWidth)}}}#z(t){const e=window.visualViewport,i=a.IsIOS(),s=e?.height??window.innerHeight,n=e&&i?e.offsetTop:0,o=this.#E.getHiddenDimensions("flex").scrollHeight,h=parseFloat(this.options.panelHeight)||220,l=parseFloat(this.options.panelMinHeight)||100,r=s-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=h,p=Math.min(o,d);const g=r-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(r-15,h)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,h)):r>=c?(u="bottom",d=Math.max(r-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+n:t.top-p-3+n,maxHeight:d,realHeight:p,contentHeight:o}}#N(t){const{position:e,top:i,maxHeight:s,realHeight:n}=this.#z(t);this.#E.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:i,maxHeight:s,realHeight:n,position:e,animate:!0})}}class L{constructor(t=null){this.options=t,t&&this.init(t)}nodeMounted=null;node=null;SearchInput=null;onSearch=null;options=null;onNavigate=null;onEnter=null;onEsc=null;init(t){this.nodeMounted=a.mountNode({SearchBox:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},child:{SearchInput:{tag:{id:a.randomString(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",ariaControls:t.SEID_LIST,ariaAutocomplete:"list"}}}}}),this.node=this.nodeMounted.view,this.SearchInput=this.nodeMounted.tags.SearchInput;let e=!1;const i=this.nodeMounted.tags.SearchInput;i.addEventListener("mousedown",t=>{t.stopPropagation()}),i.addEventListener("mouseup",t=>{t.stopPropagation()}),i.addEventListener("keydown",t=>{e=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),e=!0,this.onNavigate?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),e=!0,this.onNavigate?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),e=!0,this.onEnter?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),e=!0,this.onEsc?.())}),i.addEventListener("input",()=>{e||this.onSearch&&this.onSearch(this.nodeMounted.tags.SearchInput.value,!0)})}show(){this.node.classList.remove("hide"),this.SearchInput.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.SearchInput.focus()})}hide(){this.node.classList.add("hide")}clear(t=!0){this.nodeMounted.tags.SearchInput.value="",this.onSearch&&this.onSearch("",t)}setPlaceHolder(t){this.SearchInput.placeholder=a.stripHtml(t)}setActiveDescendant(t){this.SearchInput.setAttribute("aria-activedescendant",t)}}class M{viewElement=null;adapter=null;constructor(t=null){this.viewElement=t}setView(t){this.viewElement=t}setAdapter(t){this.adapter=t,t.onPropChanging("items",()=>{this.clear()}),t.onPropChanged("items",()=>{this.render()}),this.render()}clear(){this.viewElement&&this.viewElement.replaceChildren()}render(){this.adapter&&this.viewElement&&this.adapter.updateRecyclerView(this.viewElement)}refresh(){this.render()}}class H{nodeMounted=null;node=null;options=null;selectUIMask;parentMask;modelManager;constructor(t=null){t&&this.init(t)}init(t){this.nodeMounted=a.mountNode({AccessoryBox:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.nodeMounted.view,this.options=t}setRoot(t){this.selectUIMask=t,this.parentMask=t.parentElement,this.refreshLocation()}refreshLocation(){this.parentMask.insertBefore(this.node,"top"==this.options.accessoryStyle?this.selectUIMask:this.selectUIMask.nextSibling)}setModelManager(t){this.modelManager=t}setModelData(t){this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{a.mountNode({AccessoryItem:{tag:{node:"div",classList:["accessory-item"]},child:{Button:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:()=>{this.modelManager.triggerChanging("select"),setTimeout(()=>{t.selected=!1},10)}}},Content:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),r.trigger(window,"resize")}}class P{#B;#P;#U=null;#G=null;#_=null;#q={currentPage:0,totalPages:1,hasMore:!1,isLoading:!1,currentKeyword:"",isPaginationEnabled:!1};constructor(t,e){this.#B=t,this.#P=e}isAjax(){return!!this.#U}async loadByValues(t){if(!this.#U)return{success:!1,items:[],message:"Ajax not configured"};const e=Array.isArray(t)?t:[t];if(0===e.length)return{success:!0,items:[]};try{const t=this.#U;let i,s;if(i="function"==typeof t.dataByValues?t.dataByValues(e):{values:e.join(","),load_by_values:"1",..."function"==typeof t.data?t.data("",0):t.data||{}},"POST"===t.method){const e=new URLSearchParams;Object.keys(i).forEach(t=>{e.append(t,i[t])}),s=await fetch(t.url,{method:"POST",body:e,headers:{"Content-Type":"application/x-www-form-urlencoded"}})}else{const e=""+new URLSearchParams(i);s=await fetch(`${t.url}?${e}`)}if(!s.ok)throw Error("HTTP error! status: "+s.status);const n=await s.json();return{success:!0,items:this.#W(n).items}}catch(i){return console.error("Load by values error:",i),{success:!1,message:i.message,items:[]}}}checkMissingValues(t){const e=Array.from(this.#B.options).map(t=>t.value);return{existing:t.filter(t=>e.includes(t)),missing:t.filter(t=>!e.includes(t))}}setAjax(t){this.#U=t}setPopup(t){this.#_=t}getPaginationState(){return{...this.#q}}resetPagination(){this.#q={currentPage:0,totalPages:1,hasMore:!1,isLoading:!1,currentKeyword:"",isPaginationEnabled:this.#q.isPaginationEnabled}}clear(){this.#q.currentKeyword="";const{modelList:t}=this.#P.getResources(),e=[];for(const i of t)i instanceof y?e.push(i):i instanceof v&&Array.isArray(i.items)&&e.push(...i.items);e.forEach(t=>{t.visible=!0})}async search(t,e=!1){return this.#U&&this.#U?this.#K(t,e):this.#Q(t)}async loadMore(){return this.#U&&this.#U?this.#q.isLoading?{success:!1,message:"Already loading"}:this.#q.isPaginationEnabled?this.#q.hasMore?(this.#q.currentPage++,this.#K(this.#q.currentKeyword,!0)):{success:!1,message:"No more data"}:{success:!1,message:"Pagination not enabled"}:{success:!1,message:"Ajax not enabled"}}async#Q(t){this.compareSearchTrigger(t)&&(this.#q.currentKeyword=t);const e=((t||"")+"").toLowerCase(),i=a.string2normalize(e),{modelList:s}=this.#P.getResources(),n=[];for(const h of s)h instanceof y?n.push(h):h instanceof v&&Array.isArray(h.items)&&n.push(...h.items);let o=!1;return n.forEach(t=>{const s=((t.textContent||t.text||"")+"").toLowerCase(),n=a.string2normalize(s),h=""===e||s.includes(e)||n.includes(i);t.visible=h,h&&(o=!0)}),{success:!0,hasResults:o,isEmpty:0===n.length}}compareSearchTrigger(t){return t!==this.#q.currentKeyword}async#K(t,e=!1){const i=this.#U;this.compareSearchTrigger(t)&&(this.resetPagination(),this.#q.currentKeyword=t,e=!1),this.#q.isLoading=!0,this.#_?.showLoading(),this.#G?.abort(),this.#G=new AbortController;const s=this.#q.currentPage,n=Array.from(this.#B.selectedOptions).map(t=>t.value).join(",");let o;"function"==typeof i.data?(o=i.data(t,s),o&&!o.selectedValue&&(o.selectedValue=n)):o={search:t,page:s,selectedValue:n,...i.data||{}};try{let t;if("POST"===i.method){const e=new URLSearchParams;Object.keys(o).forEach(t=>{e.append(t,o[t])}),t=await fetch(i.url,{method:"POST",body:e,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.#G.signal})}else{const e=""+new URLSearchParams(o);t=await fetch(`${i.url}?${e}`,{signal:this.#G.signal})}let s=await t.json();const n=this.#W(s);return n.hasPagination?(this.#q.isPaginationEnabled=!0,this.#q.currentPage=n.page,this.#q.totalPages=n.totalPages,this.#q.hasMore=n.hasMore):this.#q.isPaginationEnabled=!1,this.#Y(n.items,i.keepSelected,e),this.#q.isLoading=!1,this.#_?.hideLoading(),{success:!0,hasResults:n.items.length>0,isEmpty:0===n.items.length,hasPagination:n.hasPagination,hasMore:n.hasMore,currentPage:n.page,totalPages:n.totalPages}}catch(h){return this.#q.isLoading=!1,this.#_?.hideLoading(),"AbortError"===h.name?{success:!1,message:"Request aborted"}:(console.error("Ajax search error:",h),{success:!1,message:h.message})}}#W(t){let e=[],i=!1,s=0,n=1,o=!1;return t.object&&Array.isArray(t.object)?(e=t.object,void 0!==t.page&&(i=!0,s=parseInt(t.page)||0,n=parseInt(t.totalPages||t.total_page)||1,o=s<n-1)):t.data&&Array.isArray(t.data)?(e=t.data,void 0!==t.page&&(i=!0,s=parseInt(t.page)||0,n=parseInt(t.totalPages||t.total_page)||1,o=t.hasMore??s<n-1)):Array.isArray(t)?e=t:t.items&&Array.isArray(t.items)&&(e=t.items,t.pagination&&(i=!0,s=parseInt(t.pagination.page)||0,n=parseInt(t.pagination.totalPages||t.pagination.total_page)||1,o=t.pagination.hasMore??s<n-1)),e=e.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.isGroup||t.group||t.label)return{type:"optgroup",label:t.label||t.name||t.title||"",data:t.data||{},options:(t.options||t.items||[]).map(t=>({value:t.value||t.id||t.key||"",text:t.text||t.label||t.name||t.title||"",selected:t.selected||!1,data:t.data||(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};let e=t.data||{};return t?.imgsrc&&(e.imgsrc=t.imgsrc),{type:"option",value:t.value||t.id||t.key||"",text:t.text||t.label||t.name||t.title||"",selected:t.selected||!1,data:e}}),{items:e,hasPagination:i,page:s,totalPages:n,hasMore:o}}#Y(t,e,i=!1){const s=this.#B;let n=[];e&&(n=Array.from(s.selectedOptions).map(t=>t.value)),i||(s.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)s.appendChild(t);else if("optgroup"===t.type){const i=document.createElement("optgroup");i.label=t.label,t.data&&Object.keys(t.data).forEach(e=>{i.dataset[e]=t.data[e]}),t.options&&Array.isArray(t.options)&&t.options.forEach(t=>{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(e=>{s.dataset[e]=t.data[e]}),(t.selected||e&&n.includes(s.value))&&(s.selected=!0),i.appendChild(s)}),s.appendChild(i)}else{const i=document.createElement("option");i.value=t.value,i.text=t.text,t.data&&Object.keys(t.data).forEach(e=>{i.dataset[e]=t.data[e]}),(t.selected||e&&n.includes(i.value))&&(i.selected=!0),s.appendChild(i)}}),s.dispatchEvent(new CustomEvent("options:changed"))}}class E{#J;#B;#X=null;constructor(t){this.#J=new MutationObserver(()=>{clearTimeout(this.#X),this.#X=setTimeout(()=>{this.onChanged(t)},50)}),this.#B=t,t.addEventListener("options:changed",()=>{this.onChanged(t)})}connect(){this.#J.observe(this.#B,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}onChanged(t){}disconnect(){clearTimeout(this.#X),this.#J.disconnect()}}class I{#J;#Z;#X=null;constructor(t){this.#Z=t,this.#J=new MutationObserver(t=>{let e=!1;for(const i of t)if("attributes"===i.type&&i.attributeName?.startsWith("data-")){e=!0;break}e&&(clearTimeout(this.#X),this.#X=setTimeout(()=>{this.onChanged({...this.#Z.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.onChanged({...this.#Z.dataset})})}connect(){this.#J.observe(this.#Z,{attributes:!0,attributeOldValue:!0})}onChanged(t){}disconnect(){clearTimeout(this.#X),this.#J.disconnect()}}class j{constructor(t=null,e=null){t&&this.init(t,e)}container={};oldValue=null;node=null;options=null;optionModelManager=null;isOpen=!1;hasLoadedOnce=!1;isBeforeSearch=!1;Selective=null;get isDisabled(){return this.options.disabled}set isDisabled(t){this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",""+t),this.container.tags.ViewPanel.setAttribute("aria-disabled",""+t)}get isReadOnly(){return this.options.readonly}set isReadOnly(t){this.options.readonly=t,this.node.classList.toggle("readonly",t)}get isVisible(){return this.options.visible}set isVisible(t){this.options.visible=t,this.node.classList.toggle("invisible",!t)}init(t,i){const s=a.getBinderMap(t).options,n=new u(s),o=new d,h=new L(s),l=e(),r=new O(s),p=new H(s),g=new P(t,r),m=new E(t),f=new I(t);this.Selective=i,this.options=s,n.node.id=s.SEID_HOLDER;const w=a.mountNode({Container:{tag:{node:"div",classList:"selective-ui-MAIN"},child:{ViewPanel:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.getAction()?.open())}},child:{PlaceHolder:{tag:n.node},Directive:{tag:o.node},SearchBox:{tag:h.node}}}}}});this.container=w,this.node=this.container.view,t.parentNode.insertBefore(this.node,t),this.node.insertBefore(t,w.tags.ViewPanel),p.setRoot(w.tags.ViewPanel),p.setModelManager(r),w.tags.ViewPanel.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),c.resizeBox(t,w.tags.ViewPanel),t.classList.add("init"),r.setupAdapter(A),r.setupRecyclerView(M),r.createModelResources(a.parseSelectToArray(t)),r.onUpdated=()=>{w.popup.triggerResize()},this.optionModelManager=r,w.searchController=g,w.placeholder=n,w.directive=o,w.popup=new T(t,s,r),w.popup.setupEffector(l),w.popup.setupInfiniteScroll(g,s),w.popup.onAdapterPropChanged("selected",()=>{this.getAction()?.change(null,!0)}),w.popup.onAdapterPropChanged("selected_internal",()=>{this.getAction()?.change(null,!1)}),w.popup.onAdapterPropChanging("select",()=>{this.oldValue=this.getAction()?.value??""}),w.searchbox=h,w.effector=l,w.targetElement=t,w.accessorybox=p,this.getAction()?.change(null,!1),m.connect(),m.onChanged=t=>{r.update(a.parseSelectToArray(t)),this.getAction()?.refreshMask()},w.selectObserver=m,w.datasetObserver=f,f.connect(),t.addEventListener("options:changed",()=>{r.update(a.parseSelectToArray(t)),this.getAction()?.refreshMask(),w.popup?.triggerResize?.()}),f.onChanged=t=>{a.string2Boolean(t.disabled)!=this.isDisabled&&(this.isDisabled=a.string2Boolean(t.disabled)),a.string2Boolean(t.readonly)!=this.isReadOnly&&(this.isReadOnly=a.string2Boolean(t.readonly)),a.string2Boolean(t.visible)!=this.isVisible&&(this.isVisible=a.string2Boolean(t.visible??"1"))},s.ajax&&g.setAjax(s.ajax);const b=w.popup.optionAdapter;let y=(t,e)=>{e||""!=t?(""!=t&&(this.isBeforeSearch=!0),g.search(t).then(t=>{w.popup.triggerResize(),t.hasResults&&setTimeout(()=>{b.resetHighlight()},s.animationtime)}).catch(t=>{console.error("Search error:",t)})):g.clear()},v=null;h.onSearch=(t,e)=>{g.compareSearchTrigger(t)&&(g.isAjax()?(clearTimeout(v),w.popup.showLoading(),v=setTimeout(()=>{y(t,e)},s.delaysearchtime)):y(t,e))},g.setPopup(w.popup),h.onNavigate=t=>{b.navigate(t)},h.onEnter=()=>{b.selectHighlighted()},b.onHighlightChange=(t,e)=>{h.setActiveDescendant(e)},b.onCollapsedChange=()=>{w.popup.triggerResize()},h.onEsc=()=>{this.getAction()?.close(),w.tags.ViewPanel.focus()},this.isDisabled=a.string2Boolean(s.disabled),this.isReadOnly=a.string2Boolean(s.readonly)}deInit(){const t=this.container||{},{selectObserver:e,datasetObserver:i}=t;e?.disconnect&&e.disconnect(),i?.disconnect&&i.disconnect()}getAction(){const t=this.container,e=this,i=a.getBinderMap(t.targetElement);if(!i)return null;const s=i.options;let n={get placeholder(){return t.placeholder.get()},set placeholder(e){t.placeholder?.set(e),t.searchbox?.setPlaceHolder(e)},get oldValue(){return e.oldValue},set value(t){this.setValue(null,t,!0)},get value(){let t=this.valueArray;const e=t.length;return e>1?t:0==e?"":t[0]},get valueArray(){let t=[];return e.getModelOption().forEach(e=>{e.selected&&t.push(e.value)}),t},get valueString(){return this.valueArray.join(s.customDelimiter)},get valueOptions(){let t=[];return e.getModelOption().forEach(e=>{e.selected&&t.push(e)}),t},get mask(){let t=[];return e.getModelOption().forEach(e=>{e.selected&&t.push(e.text)}),t},get valueText(){var t=[];e.getModelOption().forEach(e=>{e.selected&&t.push(e.text)});const i=t.length;return i>1?t:0==i?"":t[0]},get isOpen(){return e.isOpen},selectAll(t,i=!0){if(!(s.multiple&&s.maxSelected>0&&e.getModelOption().length>s.maxSelected)&&!this.disabled&&!this.readonly&&s.multiple){if(i){if(r.callEvent([this],...s.on.beforeChange).isCancel)return;e.oldValue=this.value}e.getModelOption().forEach(t=>{t.selectedNonTrigger=!0}),this.change(!1,i)}},deSelectAll(t,i=!0){if(!this.disabled&&!this.readonly&&s.multiple){if(i){if(r.callEvent([this],...s.on.beforeChange).isCancel)return;e.oldValue=this.value}e.getModelOption().forEach(t=>{t.selectedNonTrigger=!1}),this.change(!1,i)}},setValue(i=null,n,o=!0,h=!1){if(!Array.isArray(n)&&(n=[n]),0===(n=n.filter(t=>""!==t&&null!=t)).length)return e.getModelOption().forEach(t=>{t.selectedNonTrigger=!1}),void this.change(!1,o);if(s.multiple&&s.maxSelected>0&&n.length>s.maxSelected)console.warn(`Cannot select more than ${s.maxSelected} items`);else if(h||!this.disabled&&!this.readonly){if(t.searchController?.isAjax()){const{missing:i}=t.searchController.checkMissingValues(n);i.length>0&&(console.log(`Loading ${i.length} missing values from server...`),(async()=>{s.loadingfield&&t.popup?.showLoading();try{const s=await t.searchController.loadByValues(i);s.success&&s.items.length>0?(s.items.forEach(t=>{i.includes(t.value)&&(t.selected=!0)}),t.searchController["#applyAjaxResult"](s.items,!0,!0),setTimeout(()=>{e.getModelOption().forEach(t=>{t.selectedNonTrigger=n.some(e=>e==t.value)}),this.change(!1,!1)},100)):i.length>0&&console.warn(`Could not load ${i.length} values:`,i)}catch(o){console.error("Error loading missing values:",o)}finally{s.loadingfield&&t.popup?.hideLoading()}})())}if(o){if(r.callEvent([this],...s.on.beforeChange).isCancel)return;e.oldValue=this.value}e.getModelOption().forEach(t=>{t.selectedNonTrigger=n.some(e=>e==t.value)}),!s.multiple&&n.length>0&&(t.targetElement.value=n[0]),this.change(!1,o)}},open(){if(e.isOpen)return!1;let i=e.Selective.find();if(!i.isEmpty&&i.close().isCancel)return!1;if(this.disabled)return!1;if(r.callEvent([this],...s.on.beforeShow).isCancel)return!1;e.isOpen=!0,t.directive.setDropdown(!0);const n=t.popup.optionAdapter,o=n.getSelectedItem();o?n.setHighlight(o,!1):n.resetHighlight(),e.hasLoadedOnce&&!e.isBeforeSearch||!s?.ajax||(t.popup.showLoading(),e.hasLoadedOnce=!0,e.isBeforeSearch=!1,setTimeout(()=>{t.popup&&t.searchController&&t.searchController.search("").then(()=>t.popup?.triggerResize?.()).catch(t=>console.error("Initial ajax load error:",t))},s.animationtime)),t.popup.open(),t.searchbox.show();const h=t.tags.ViewPanel;return h.setAttribute("aria-expanded","true"),h.setAttribute("aria-controls",s.SEID_LIST),h.setAttribute("aria-haspopup","listbox"),h.setAttribute("aria-labelledby",s.SEID_HOLDER),s.multiple&&h.setAttribute("aria-multiselectable","true"),r.callEvent([this],...s.on.show),!0},close(){return!!e.isOpen&&!r.callEvent([this],...s.on.beforeClose).isCancel&&(e.isOpen=!1,t.directive.setDropdown(!1),t.popup.close(()=>{t.searchbox.clear(!1)}),t.searchbox.hide(),t.tags.ViewPanel.setAttribute("aria-expanded","false"),r.callEvent([this],...s.on.close),!0)},toggle(){e.isOpen?this.close():this.open()},change(i=null,n=!0){if(n){if(s.multiple&&s.maxSelected>0&&this.valueArray.length>s.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(r.callEvent([this,this.value],...s.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.accessorybox.setModelData(this.valueOptions),n&&(t.targetElement&&r.trigger(t.targetElement,"change"),r.callEvent([this,this.value],...s.on.change),e.options.autoclose&&this.close())},refreshMask(){let i=s.placeholder;!s.multiple&&e.getModelOption().length>0&&(i=this.mask[0]),i??=s.placeholder,t.placeholder.set(i,!1),t.searchbox.setPlaceHolder(i)},on(t,e,i){s.on[e]||(s.on[e]=[]),s.on[e].push(i)},ajax(e,i){t.searchController.setAjax(i)}};return this.createSymProp(n,"disabled","isDisabled"),this.createSymProp(n,"readonly","isReadOnly"),this.createSymProp(n,"visible","isVisible"),n}createSymProp(t,e,i){const s=this;Object.defineProperty(t,e,{get:()=>s[i],set(t){s[i]=t,s.container.targetElement.dataset[e]=t},enumerable:!0,configurable:!0})}getModelOption(t=null){if(!this.optionModelManager)return[];const{modelList:e}=this.optionModelManager.getResources(),i=[];for(const s of e)s instanceof y?i.push(s):s instanceof v&&Array.isArray(s.items)&&s.items.length&&i.push(...s.items);return"boolean"==typeof t?i.filter(e=>e.selected===t):i}}class F{#tt=!1;#J=null;#et=[];onDetect(t){this.#et.push(t)}clearDetect(){this.#et=[]}start(t){if(this.#tt)return;this.#tt=!0;const e=t.toUpperCase(),i=t.toLowerCase();this.#J=new MutationObserver(t=>{t.forEach(t=>{t.addedNodes.forEach(t=>{const s=t;1===s.nodeType&&(s.tagName===e&&this.#it(s),s.querySelectorAll(i).forEach(t=>{this.#it(t)}))})})}),this.#J.observe(document.body,{childList:!0,subtree:!0})}stop(){this.#tt&&(this.#tt=!1,this.#J.disconnect(),this.#J=null)}#it(t){this.#et.forEach(e=>{e(t)})}}class V{EAObserver=null;static bindedQueries=new Map;static bind(t,e){e=a.mergeConfig(a.getDefaultConfig(),e),this.bindedQueries.set(t,e);const i=this,s=a.randomString();a.timerProcess.setExecute(s,()=>{r.callEvent([i.find(t)],...e.on.load),a.timerProcess.clearExecute(s),e.on.load=[]}),a.getElements(t).forEach(t=>{(async()=>{"SELECT"==t.tagName&&(a.removeUnbinderMap(t),this.applySelectBox(t,e)&&a.timerProcess.run(s))})()}),a.getBindedCommand().includes(t)||a.getBindedCommand().push(t)}static find(t="*"){let e={isEmpty:!0};if("*"==t&&""==(t=a.getBindedCommand().join(", ")))return e;const i=a.getElements(t);if(0==i.length)return e;const s=a.getBinderMap(i[0]);if(!s)return e;for(let n in s.action)e[n]=this.#st(n,s.action);if(e){let t={};for(let s in e){const n=e[s];switch(n.type){case"get-set":this.#nt(t,n.name,i);break;case"func":this.#ot(t,n.name,i)}}return t.isEmpty=!1,t}}static Observer(){this.EAObserver=new F,this.EAObserver.onDetect(t=>{this.bindedQueries.forEach((e,i)=>{try{t.matches(i)&&this.applySelectBox(t,e)}catch(s){console.warn("Invalid selector: "+i,s)}})}),this.EAObserver.start("select")}static destroy(t=null){null===t?this.destroyAll():"string"==typeof t?this.destroyByQuery(t):t instanceof HTMLSelectElement&&this.destroyElement(t)}static destroyAll(){a.getBindedCommand().forEach(t=>{this.destroyByQuery(t)}),this.bindedQueries.clear(),a.getBindedCommand().length=0,this.EAObserver.stop()}static destroyByQuery(t){a.getElements(t).forEach(t=>{"SELECT"===t.tagName&&this.destroyElement(t)}),this.bindedQueries.delete(t);const e=a.getBindedCommand(),i=e.indexOf(t);i>-1&&e.splice(i,1)}static destroyElement(t){const e=a.getBinderMap(t);if(!e)return;a.setUnbinderMap(t,e);const i=!!this.EAObserver;i&&this.EAObserver.stop();try{e.self.deInit?.()}catch(n){}const s=e.container?.element||t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.selectiveId,s&&s.parentNode?s.parentNode.replaceChild(t,s):document.body.appendChild(t),a.removeBinderMap(t),i&&this.bindedQueries.size>0&&this.EAObserver.start("select")}static rebind(t,e){this.destroyByQuery(t),this.bind(t,e)}static applySelectBox(t,e){if(a.getBinderMap(t)||a.getUnbinderMap(t))return!1;const i=a.randomString(8),s=a.buildConfig(t,e);s.SEID=i,s.SEID_LIST=`seui-${i}-optionlist`,s.SEID_HOLDER=`seui-${i}-placeholder`;const n={options:s};a.setBinderMap(t,n);const o=new j(t,this);return n.container=o.container,n.action=o.getAction(),n.self=o,o.container.view.addEventListener("mouseup",()=>{n.action.toggle()}),!0}static#st(t,e){const i=Object.getOwnPropertyDescriptor(e,t);let s="variable";return i.get||i.set&&"function"!=typeof e[t]?s="get-set":"function"==typeof e[t]&&(s="func"),{type:s,name:t}}static#nt(t,e,i){Object.defineProperty(t,e,{get:()=>a.getBinderMap(i[0]).action[e],set(t){i.forEach(i=>{const s=a.getBinderMap(i);s&&(s.action[e]=t)})},enumerable:!0,configurable:!0})}static#ot(t,e,i){t[e]=(...s)=>{for(let t=0;t<i.length;t++){const n=a.getBinderMap(i[t]);if(!n)continue;const o=r.buildEventToken();if(n.action[e](o.callback,...s),!o.token.isContinue)break}return t}}}const $="1.0.4",k="SelectiveUI",R=(D=k,"undefined"!=typeof window&&(window[D]&&window[D].__loaded?(console.warn(`[${D}] Already loaded (v${window[D].__version}). Using existing instance. Please remove duplicate <script> tags.`),!0):(window[D]=window[D]||{},window[D].__loading=!0,!1)));var D;if(!R){let z=!1;function N(){z||(z=!0,document.addEventListener("mousedown",()=>{const t=a.getBindedCommand();if(t.length>0){const e=V.find(t.join(", "));e.isEmpty||e.close()}}),V.Observer(),((t,e,i)=>{"undefined"!=typeof window&&(window[t].__loaded=!0,window[t].__loading=!1,window[t].__version=e,Object.assign(window[t],i),Object.freeze(window[t]),console.log(`[${t}] v${e} loaded successfully`))})(k,$,{bind:i,find:s,destroy:n,rebind:o,effector:h,version:$}))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",N):N()}t.bind=i,t.destroy=n,t.effector=h,t.find=s,t.name=k,t.rebind=o,t.version=$},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
Binary file
@@ -1,4 +1,4 @@
1
- /*! Selective UI v1.0.1 | MIT License */
1
+ /*! Selective UI v1.0.4 | MIT License */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -4190,6 +4190,88 @@
4190
4190
  return !(!this.#ajaxConfig);
4191
4191
  }
4192
4192
 
4193
+ /**
4194
+ * Load specific options by their values from server
4195
+ * @param {string|string[]} values - Values to load
4196
+ * @returns {Promise<{success: boolean, items: Array, message?: string}>}
4197
+ */
4198
+ async loadByValues(values) {
4199
+ if (!this.#ajaxConfig) {
4200
+ return { success: false, items: [], message: "Ajax not configured" };
4201
+ }
4202
+
4203
+ const valuesArray = Array.isArray(values) ? values : [values];
4204
+ if (valuesArray.length === 0) {
4205
+ return { success: true, items: [] };
4206
+ }
4207
+
4208
+ try {
4209
+ const cfg = this.#ajaxConfig;
4210
+
4211
+ let payload;
4212
+ if (typeof cfg.dataByValues === "function") {
4213
+ payload = cfg.dataByValues(valuesArray);
4214
+ } else {
4215
+ payload = {
4216
+ values: valuesArray.join(","),
4217
+ load_by_values: "1",
4218
+ ...(typeof cfg.data === "function" ? cfg.data("", 0) : (cfg.data || {}))
4219
+ };
4220
+ }
4221
+
4222
+ let response;
4223
+ if (cfg.method === "POST") {
4224
+ const formData = new URLSearchParams();
4225
+ Object.keys(payload).forEach(key => {
4226
+ formData.append(key, payload[key]);
4227
+ });
4228
+
4229
+ response = await fetch(cfg.url, {
4230
+ method: "POST",
4231
+ body: formData,
4232
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
4233
+ });
4234
+ } else {
4235
+ const params = new URLSearchParams(payload).toString();
4236
+ response = await fetch(`${cfg.url}?${params}`);
4237
+ }
4238
+
4239
+ if (!response.ok) {
4240
+ throw new Error(`HTTP error! status: ${response.status}`);
4241
+ }
4242
+
4243
+ const data = await response.json();
4244
+ const result = this.#parseResponse(data);
4245
+
4246
+ return {
4247
+ success: true,
4248
+ items: result.items
4249
+ };
4250
+ } catch (error) {
4251
+ console.error("Load by values error:", error);
4252
+ return {
4253
+ success: false,
4254
+ message: error.message,
4255
+ items: []
4256
+ };
4257
+ }
4258
+ }
4259
+
4260
+ /**
4261
+ * Check if values exist in current options
4262
+ * @param {string[]} values - Values to check
4263
+ * @returns {{existing: string[], missing: string[]}}
4264
+ */
4265
+ checkMissingValues(values) {
4266
+ const allOptions = Array.from(this.#select.options);
4267
+ const existingValues = allOptions.map(opt => opt.value);
4268
+
4269
+ const existing = values.filter(v => existingValues.includes(v));
4270
+ const missing = values.filter(v => !existingValues.includes(v));
4271
+
4272
+ return { existing, missing };
4273
+ }
4274
+
4193
4275
  /**
4194
4276
  * Configures AJAX settings used for remote searching and pagination.
4195
4277
  *
@@ -4922,13 +5004,7 @@
4922
5004
  tag: {
4923
5005
  node: "div",
4924
5006
  classList: "selective-ui-view",
4925
- tabIndex: 0,
4926
- role: "combobox",
4927
- ariaExpanded: "false",
4928
- ariaLabelledby: options.SEID_HOLDER,
4929
- ariaControls: options.SEID_LIST,
4930
- ariaHaspopup: "true",
4931
- ariaMultiselectable: options.multiple ? "true" : "false",
5007
+ tabIndex: 0,
4932
5008
  onkeydown: (e) => {
4933
5009
  if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
4934
5010
  e.preventDefault();
@@ -5248,10 +5324,21 @@
5248
5324
  },
5249
5325
  setValue(evtToken = null, value, trigger = true, force = false) {
5250
5326
  !Array.isArray(value) && (value = [value]);
5327
+
5328
+ value = value.filter(v => v !== "" && v != null);
5329
+
5330
+ if (value.length === 0) {
5331
+ superThis.getModelOption().forEach(modelOption => {
5332
+ modelOption["selectedNonTrigger"] = false;
5333
+ });
5334
+ this.change(false, trigger);
5335
+ return;
5336
+ }
5251
5337
 
5252
5338
  if (bindedOptions.multiple && bindedOptions.maxSelected > 0) {
5253
5339
  if (value.length > bindedOptions.maxSelected) {
5254
- return
5340
+ console.warn(`Cannot select more than ${bindedOptions.maxSelected} items`);
5341
+ return;
5255
5342
  }
5256
5343
  }
5257
5344
 
@@ -5259,12 +5346,58 @@
5259
5346
  return;
5260
5347
  }
5261
5348
 
5349
+ if (container.searchController?.isAjax()) {
5350
+ const { existing, missing } = container.searchController.checkMissingValues(value);
5351
+
5352
+ if (missing.length > 0) {
5353
+ console.log(`Loading ${missing.length} missing values from server...`);
5354
+
5355
+ (async () => {
5356
+ if (bindedOptions.loadingfield) {
5357
+ container.popup?.showLoading();
5358
+ }
5359
+
5360
+ try {
5361
+ const result = await container.searchController.loadByValues(missing);
5362
+
5363
+ if (result.success && result.items.length > 0) {
5364
+ result.items.forEach(item => {
5365
+ if (missing.includes(item.value)) {
5366
+ item.selected = true;
5367
+ }
5368
+ });
5369
+
5370
+ container.searchController['#applyAjaxResult'](
5371
+ result.items,
5372
+ true,
5373
+ true
5374
+ );
5375
+
5376
+ setTimeout(() => {
5377
+ superThis.getModelOption().forEach(modelOption => {
5378
+ modelOption["selectedNonTrigger"] = value.some(v => v == modelOption["value"]);
5379
+ });
5380
+ this.change(false, false);
5381
+ }, 100);
5382
+ } else if (missing.length > 0) {
5383
+ console.warn(`Could not load ${missing.length} values:`, missing);
5384
+ }
5385
+ } catch (error) {
5386
+ console.error("Error loading missing values:", error);
5387
+ } finally {
5388
+ if (bindedOptions.loadingfield) {
5389
+ container.popup?.hideLoading();
5390
+ }
5391
+ }
5392
+ })();
5393
+ }
5394
+ }
5395
+
5262
5396
  if (trigger) {
5263
5397
  const beforeChangeToken = iEvents.callEvent([this], ...bindedOptions.on.beforeChange);
5264
5398
  if (beforeChangeToken.isCancel) {
5265
5399
  return;
5266
5400
  }
5267
-
5268
5401
  superThis.oldValue = this.value;
5269
5402
  }
5270
5403
 
@@ -5272,7 +5405,7 @@
5272
5405
  modelOption["selectedNonTrigger"] = value.some(v => v == modelOption["value"]);
5273
5406
  });
5274
5407
 
5275
- if (!bindedOptions.multiple){
5408
+ if (!bindedOptions.multiple && value.length > 0) {
5276
5409
  container.targetElement.value = value[0];
5277
5410
  }
5278
5411
 
@@ -5324,8 +5457,14 @@
5324
5457
 
5325
5458
  container.popup.open();
5326
5459
  container.searchbox.show();
5327
-
5328
- container.tags.ViewPanel.setAttribute("aria-expanded", "true");
5460
+ const ViewPanel = /** @type {HTMLElement} */ (container.tags.ViewPanel);
5461
+ ViewPanel.setAttribute("aria-expanded", "true");
5462
+ ViewPanel.setAttribute("aria-controls", bindedOptions.SEID_LIST);
5463
+ ViewPanel.setAttribute("aria-haspopup", "listbox");
5464
+ ViewPanel.setAttribute("aria-labelledby", bindedOptions.SEID_HOLDER);
5465
+ if (bindedOptions.multiple) {
5466
+ ViewPanel.setAttribute("aria-multiselectable", "true");
5467
+ }
5329
5468
 
5330
5469
  iEvents.callEvent([this], ...bindedOptions.on.show);
5331
5470
 
@@ -5993,7 +6132,7 @@
5993
6132
  console.log(`[${name}] v${version} loaded successfully`);
5994
6133
  }
5995
6134
 
5996
- const version = "1.0.3";
6135
+ const version = "1.0.4";
5997
6136
  const name = "SelectiveUI";
5998
6137
 
5999
6138
  const alreadyLoaded = checkDuplicate(name);