monobill-mintui 0.6.684 → 0.6.686

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 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-CGXHKbMq.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-Cfhjb8tV.js`),require(`../chunks/popover-Bek5fgHz.js`);var t=`data-mint-native-select-part`,n=class extends HTMLElement{static get observedAttributes(){return[`name`,`value`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`multiple`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._select=null,this._wrapper=null,this._caretUpIcon=null,this._caretDownIcon=null,this._changeHandler=null,this._optionObserver=null,this._childrenObserver=null,this._hostOptionsObserverRaf=null,this._generatedControlId=`mint-native-select-${Math.random().toString(36).slice(2,10)}`}connectedCallback(){this.classList.add(`mint-native-select-host`),this.getLabel()||console.error(`mint-native-select: The "label" attribute is required. Please provide a label for the select.`),this.render(),this._childrenObserver&&this._childrenObserver.disconnect(),this._childrenObserver=new MutationObserver(e=>{if(e.some(e=>{let t=e.target;if(this._select&&(t===this._select||this._select.contains(t)))return!1;let n=Array.from(e.addedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`))||Array.from(e.removedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)),r=e.type===`attributes`&&e.target.nodeType===Node.ELEMENT_NODE&&(e.target.tagName===`OPTION`||e.target.tagName===`OPTGROUP`);return n||r})){if(this._hostOptionsObserverRaf!==null)return;this._hostOptionsObserverRaf=requestAnimationFrame(()=>{this._hostOptionsObserverRaf=null,this.isConnected&&this.render()})}}),this._childrenObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`selected`,`disabled`]})}disconnectedCallback(){this._select&&this._changeHandler&&(this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=null),this._optionObserver&&=(this._optionObserver.disconnect(),null),this._childrenObserver&&=(this._childrenObserver.disconnect(),null),this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null)}isLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._syncSelectAccessibility());return}if(e===`loading`){this.render();return}if(e===`value`){if(this._select)if(this.isMultiple()){let e=[];try{let t=n?JSON.parse(n):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=n?[String(n)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=n||``;return}this.render()}}getName(){return this.getAttribute(`name`)||``}getValue(){if(this.isMultiple()&&this._select){let e=Array.from(this._select.selectedOptions).map(e=>e.value);return JSON.stringify(e)}return this.hasAttribute(`value`)?this.getAttribute(`value`)||``:this._select?this._select.value:``}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(e=>String(e)):e==null||e===``?[]:[String(e)];this.setAttribute(`value`,JSON.stringify(t)),this._select&&Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)});return}let t=e==null?``:String(e);this.setAttribute(`value`,t),this._select&&(this._select.value=t)}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{if(this.isMultiple()){this.setValue(e);return}let t=e||``;(this.getAttribute(`value`)||``)!==t&&this.setAttribute(`value`,t),this._select&&requestAnimationFrame(()=>{this._select&&(t===``||Array.from(this._select.options).some(e=>e.value===t))&&this._select.value!==t&&(this._select.value=t)})}catch{}}isDisabled(){let e=this.getAttribute(`disabled`);return e!==null&&e!==`false`}isMultiple(){let e=this.getAttribute(`multiple`);return e!==null&&e!==`false`}isRequired(){let e=this.getAttribute(`required`);return e!==null&&e!==`false`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getSelectClasses(){return[`mint-native-select-control`,this.isMultiple()?`is-multiple`:``,this.hasError()?`has-error`:``].filter(Boolean).join(` `)}render(){this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null);let e=this.isLoading(),n=this.isMultiple(),r=this.getValue(),i=[];this._select&&Array.from(this._select.children).forEach(e=>{(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)&&i.push(e.cloneNode(!0))}),Array.from(this.children).forEach(e=>{e instanceof HTMLElement&&e.hasAttribute(t)&&e.remove()}),this._wrapper=null,this._select=null;let a=Array.from(this.children).filter(e=>e.tagName===`OPTION`||e.tagName===`OPTGROUP`).map(e=>e.cloneNode(!0)),o=this.getLabel(),s=this.getInfo(),c=this.getId()||this._generatedControlId,l=this.getName(),u=this.isDisabled(),d=this.hasError();if(o){let e=document.createElement(`label`);e.setAttribute(t,`label`),e.className=`mint-native-select-label`,c&&e.setAttribute(`for`,c);let n=document.createTextNode(o);e.appendChild(n),this.appendChild(e)}this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(t,`wrapper`),this._wrapper.className=`mint-native-select-control-wrap`,this.appendChild(this._wrapper),this._select=document.createElement(`select`),this._select.className=this.getSelectClasses(),c&&(this._select.id=c),l&&(this._select.name=l),u&&(this._select.disabled=!0),this._select.required=this.isRequired(),n&&(this._select.multiple=!0),this._select.setAttribute(`aria-invalid`,d?`true`:`false`);let f=this.getAttribute(`aria-label`)?.trim(),p=this.getAttribute(`aria-labelledby`)?.trim();p?this._select.setAttribute(`aria-labelledby`,p):o?this._select.removeAttribute(`aria-label`):this._select.setAttribute(`aria-label`,f||`Select an option`);let m=a.length>0?a:i;if(m.length>0&&m.forEach(e=>{this._select.appendChild(e)}),this._select.options.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`Select an option`,e.disabled=!0,e.selected=!0,this._select.appendChild(e)}if(n){let e=[];try{let t=r?JSON.parse(r):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=r?[String(r)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=r||``;if(this._changeHandler&&this._select&&this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=e=>{let t=e.target,r=n?Array.from(t.selectedOptions).map(e=>e.value):t.value,i=n?JSON.stringify(r):String(r||``);(this.getAttribute(`value`)||``)!==i&&(i?this.setAttribute(`value`,i):this.removeAttribute(`value`));let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener(`change`,this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{let e=this.getAttribute(`value`)||this.value||``;this._select&&e&&requestAnimationFrame(()=>{if(this._select)if(n){let t=[];try{let n=JSON.parse(e);t=Array.isArray(n)?n.map(e=>String(e)):[]}catch{t=[String(e)]}Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)})}else Array.from(this._select.options).some(t=>t.value===e)&&this._select.value!==e&&(this._select.value=e)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),n)this._caretUpIcon=null,this._caretDownIcon=null;else{let e=document.createElement(`div`);e.className=`mint-native-select-caret`,this._caretUpIcon=document.createElement(`mint-icon`),this._caretUpIcon.setAttribute(`name`,`caret-up`),this._caretUpIcon.className=`mint-native-select-caret-up`,this._caretUpIcon.setAttribute(`aria-hidden`,`true`),e.appendChild(this._caretUpIcon),this._caretDownIcon=document.createElement(`mint-icon`),this._caretDownIcon.setAttribute(`name`,`caret-down`),this._caretDownIcon.className=`mint-native-select-caret-down`,this._caretDownIcon.setAttribute(`aria-hidden`,`true`),e.appendChild(this._caretDownIcon),this._wrapper.appendChild(e)}if(s){let e=document.createElement(`div`);e.setAttribute(t,`info`),e.className=`mint-native-select-info`,e.textContent=s,this.appendChild(e)}this._renderErrorState(),this._syncSelectAccessibility(),this._renderSkeleton(e)}_renderSkeleton(e){let t=this.querySelector(`.mint-native-select-skeleton-container`),n=this._wrapper;if(e){t||(t=document.createElement(`div`),t.className=`mint-native-select-skeleton-container`,t.setAttribute(`aria-hidden`,`true`),n?n.appendChild(t):this.appendChild(t));let e=t.querySelector(`.mint-native-select-skeleton`);e||(e=document.createElement(`div`),t.appendChild(e));let r=this.isMultiple();e.classList.toggle(`is-multiple`,r),e.style.height=r?`5rem`:`2rem`,t.style.display=`block`,this._select&&(this._select.style.opacity=`0`,this._select.style.pointerEvents=`none`,this._select.setAttribute(`aria-busy`,`true`))}else t&&(t.style.display=`none`),this._select&&(this._select.style.opacity=`1`,this._select.style.pointerEvents=`auto`,this._select.removeAttribute(`aria-busy`))}_renderErrorState(){let e=this.hasError(),n=this.getErrorMessage(),r=this.querySelector(`.mint-native-select-error`);e&&n?(r?r.hasAttribute(t)||r.setAttribute(t,`error`):(r=document.createElement(`div`),r.setAttribute(t,`error`),r.className=`mint-native-select-error`,this.appendChild(r)),r.textContent=n):r&&r.remove()}_syncSelectAccessibility(){if(!this._select)return;let e=this._select.id||this._generatedControlId,n=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),r=this.querySelector(`[${t}="info"]`),i=this.querySelector(`.mint-native-select-error`);r&&(r.id=`${e}-info`,n.push(r.id)),i&&(i.id=`${e}-error`,n.push(i.id)),n.length?this._select.setAttribute(`aria-describedby`,Array.from(new Set(n)).join(` `)):this._select.removeAttribute(`aria-describedby`)}};customElements.get(`mint-native-select`)||e.t(`mint-native-select`,n);var r=`data-mint-select-part`,i=class extends HTMLElement{constructor(...e){super(...e),this._native=null,this._trigger=null,this._popover=null,this._list=null,this._observer=null,this._syncing=!1,this._typeahead=``,this._typeaheadTimer=null,this._id=`mint-select-${Math.random().toString(36).slice(2,10)}`}static get observedAttributes(){return[`name`,`value`,`values`,`multiple`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`loading`,`placeholder`,`aria-label`,`aria-labelledby`,`aria-describedby`,`form`]}connectedCallback(){this.classList.add(`mint-select-host`),this.render(),this._observer?.disconnect(),this._observer=new MutationObserver(e=>{this._syncing||e.some(e=>{let t=e.target instanceof Element?e.target:e.target.parentElement;return t===this||t?.closest(`[${r}]`)?!1:e.type===`attributes`?[`value`,`label`,`disabled`,`selected`].includes(e.attributeName):t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement||[...e.addedNodes,...e.removedNodes].some(e=>e instanceof HTMLOptionElement||e instanceof HTMLOptGroupElement)})&&this.render()}),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`label`,`disabled`,`selected`]})}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._typeaheadTimer!==null&&window.clearTimeout(this._typeaheadTimer)}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`values`&&this._native&&this.isMultiple()){this._applyValues(this.parseValues(n)),this.updateDisplay();return}if(e===`multiple`&&this._native){this.render();return}if(e===`value`&&this._native){this.isMultiple()?this._applyValues(n?[n]:[]):this._native.value=n||``,this.updateDisplay();return}this.render()}}get value(){return this.isMultiple()?this.values:this._native?.value||this.getAttribute(`value`)||``}set value(e){this.setValue(e)}get values(){return this._native&&this.isMultiple()?Array.from(this._native.selectedOptions,e=>e.value):this.parseValues(this.getAttribute(`values`))}set values(e){this.setValue(e)}getValue(){return this.value}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(String):e==null||e===``?[]:[String(e)];this.setAttribute(`values`,JSON.stringify(t)),this._applyValues(t)}else{let t=e==null?``:String(e);this.setAttribute(`value`,t),this._native&&(this._native.value=t)}this.updateDisplay()}isDisabled(){return this.hasAttribute(`disabled`)&&this.getAttribute(`disabled`)!==`false`}isLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}isRequired(){return this.hasAttribute(`required`)&&this.getAttribute(`required`)!==`false`}isMultiple(){return this.hasAttribute(`multiple`)&&this.getAttribute(`multiple`)!==`false`}hasError(){return this.getAttribute(`error`)===`true`}parseValues(e){if(!e)return[];try{let t=JSON.parse(e);if(Array.isArray(t)){if(t.length===1&&typeof t[0]==`string`&&t[0].trim().startsWith(`[`))try{let e=JSON.parse(t[0]);if(Array.isArray(e))return e.map(String)}catch{}return t.map(String)}}catch{}return[e]}_applyValues(e){if(!this._native)return;let t=new Set(e);Array.from(this._native.options).forEach(e=>{e.selected=t.has(e.value)})}options(){return Array.from(this.querySelectorAll(`:scope > option, :scope > optgroup > option`))}selectedOption(){return this._native?.selectedOptions[0]||this.options().find(e=>e.value===this.value)}render(){let e=this._native?.value??this.getAttribute(`value`)??``,t=this._native&&this._native.multiple?Array.from(this._native.selectedOptions,e=>e.value):this.parseValues(this.getAttribute(`values`));this._syncing=!0,Array.from(this.children).forEach(e=>{e.hasAttribute(r)&&e.remove()});let n=this.getAttribute(`label`)?.trim()||``,i=this.getAttribute(`id`)||this._id;if(n){let e=document.createElement(`label`);e.setAttribute(r,`label`),e.className=`mint-select-label`,e.htmlFor=`${i}-trigger`,e.textContent=n,this.append(e)}let a=document.createElement(`div`);a.setAttribute(r,`wrap`),a.className=`mint-select-control-wrap`,a.style.position=`relative`,this.append(a);let o=document.createElement(`button`);o.type=`button`,o.id=`${i}-trigger`,o.className=`mint-select-trigger`,o.disabled=this.isDisabled()||this.isLoading(),o.setAttribute(`role`,`combobox`),o.setAttribute(`aria-busy`,String(this.isLoading())),o.setAttribute(`aria-haspopup`,`listbox`),o.setAttribute(`aria-expanded`,`false`),o.setAttribute(`aria-required`,String(this.isRequired())),o.setAttribute(`aria-invalid`,String(this.hasError()));let s=this.getAttribute(`aria-labelledby`),c=this.getAttribute(`aria-label`)?.trim();if(s?o.setAttribute(`aria-labelledby`,s):!n&&c?o.setAttribute(`aria-label`,c):n&&o.setAttribute(`aria-labelledby`,`${i}-label`),n){let e=this.querySelector(`[${r}="label"]`);e&&(e.id=`${i}-label`)}let l=document.createElement(`span`);l.className=`mint-select-value`,o.append(l);let u=document.createElement(`span`);u.className=`mint-select-caret`,u.setAttribute(`aria-hidden`,`true`),u.innerHTML=`<mint-icon name="caret-up"></mint-icon><mint-icon name="caret-down"></mint-icon>`,o.append(u),a.append(o);let d=null;this.isLoading()?(d=document.createElement(`div`),d.className=`mint-select-skeleton`,d.setAttribute(`aria-hidden`,`true`),d.style.cssText=`position:absolute;inset:0;z-index:1;border:1px solid var(--mint-color-border,#dfe6e0);border-radius:.5rem;background:var(--mint-color-surface-muted,#e8eee9);animation:mint-select-pulse 1.4s ease-in-out infinite;`,a.append(d),o.style.visibility=`hidden`,this.setAttribute(`aria-busy`,`true`)):this.removeAttribute(`aria-busy`);let f=document.createElement(`select`);f.setAttribute(r,`native`),f.className=`mint-select-native-control`,f.id=`${i}-native`,f.name=this.getAttribute(`name`)||``,f.multiple=this.isMultiple(),this.hasAttribute(`form`)&&f.setAttribute(`form`,this.getAttribute(`form`)||``),f.required=this.isRequired(),f.disabled=this.isDisabled(),f.tabIndex=-1,f.setAttribute(`aria-hidden`,`true`),f.setAttribute(`aria-invalid`,String(this.hasError()));let p=[this.getAttribute(`aria-describedby`),n?`${i}-label`:``,this.getAttribute(`info`)?`${i}-info`:``,this.getAttribute(`error-message`)?`${i}-error`:``].filter(Boolean).join(` `);if(p&&f.setAttribute(`aria-describedby`,p),this.options().forEach(e=>f.append(e.cloneNode(!0))),!f.options.length){let e=document.createElement(`option`);e.value=``,e.textContent=this.getAttribute(`placeholder`)||`Select an option`,e.disabled=!0,f.append(e)}if(f.multiple){let n=t.length?t:this.parseValues(this.getAttribute(`values`)).length?this.parseValues(this.getAttribute(`values`)):e?[e]:[];n.length&&Array.from(f.options).forEach(e=>{e.selected=n.includes(e.value)})}else f.value=e;a.append(f),this._native=f,this._trigger=o;let m=document.createElement(`mint-popover`);m.className=`mint-select-popover`,m.setAttribute(r,`popover`),m.setAttribute(`trigger-id`,o.id),m.setAttribute(`trigger-toggle`,`false`),m.setAttribute(`direction`,`down`),m.setAttribute(`trigger-align`,`start`),m.setAttribute(`align-selected`,`true`),m.setAttribute(`distance`,`4`),m.setAttribute(`padding`,`0`),m.setAttribute(`aria-label`,n?`${n} options`:`Select options`);let h=document.createElement(`div`);h.className=`mint-select-options`,h.id=`${i}-listbox`,h.setAttribute(`role`,`listbox`),h.setAttribute(`aria-multiselectable`,String(this.isMultiple())),o.setAttribute(`aria-controls`,h.id),m.append(h),this.append(m),this._popover=m,this._list=h,this.renderOptions(),this.updateDisplay(),this.bindEvents();let g=this.getAttribute(`info`);if(g){let e=document.createElement(`div`);e.setAttribute(r,`info`),e.className=`mint-select-info`,e.id=`${i}-info`,e.textContent=g,this.append(e)}let _=this.getAttribute(`error-message`);if(this.hasError()&&_){let e=document.createElement(`div`);e.setAttribute(r,`error`),e.className=`mint-select-error`,e.id=`${i}-error`,e.textContent=_,this.append(e)}this._syncing=!1}renderOptions(){this._list&&(this._list.replaceChildren(),Array.from(this.children).filter(e=>e.tagName===`OPTION`||e.tagName===`OPTGROUP`).forEach(e=>{if(e instanceof HTMLOptGroupElement){let t=document.createElement(`div`);t.className=`mint-select-group-label`,t.setAttribute(`role`,`presentation`),t.textContent=e.label,this._list.append(t),Array.from(e.children).forEach(t=>this.addOption(t,e.disabled))}else this.addOption(e,!1)}))}addOption(e,t){if(!this._list)return;let n=document.createElement(`button`);n.type=`button`,n.className=`mint-select-option`,n.dataset.value=e.value,n.setAttribute(`role`,`option`),n.setAttribute(`aria-selected`,String(this.isMultiple()?this.values.includes(e.value):e.value===this.value)),n.disabled=e.disabled||t||this.isDisabled(),n.tabIndex=-1;let r=document.createElement(`span`);r.textContent=e.label||e.textContent||``,n.append(r);let i=document.createElement(`mint-icon`);i.setAttribute(`name`,`check`),i.setAttribute(`aria-hidden`,`true`),i.className=`mint-select-option-check`,n.append(i),this._list.append(n)}updateDisplay(){if(!this._native||!this._trigger)return;let e=this.selectedOption(),t=this.values,n=this.isMultiple()?t.map(e=>this.options().find(t=>t.value===e)?.label||e):[],r=this._trigger.querySelector(`.mint-select-value`);r&&(r.textContent=this.isMultiple()?n.join(`, `)||this.getAttribute(`placeholder`)||`Select an option`:e?.label||e?.textContent?.trim()||this.getAttribute(`placeholder`)||`Select an option`,r.classList.toggle(`is-placeholder`,this.isMultiple()?t.length===0:!e||e.value===``)),this._trigger.setAttribute(`aria-invalid`,String(this.hasError())),this._trigger.setAttribute(`aria-haspopup`,`listbox`),this._list?.setAttribute(`aria-multiselectable`,String(this.isMultiple())),this._list?.querySelectorAll(`[role="option"]`).forEach(e=>e.setAttribute(`aria-selected`,String(this.isMultiple()?t.includes(e.dataset.value||``):e.dataset.value===this._native.value)))}bindEvents(){!this._trigger||!this._popover||!this._native||!this._list||(this._trigger.onclick=()=>{this._popover.style.setProperty(`--mint-select-popover-width`,`${this._trigger.getBoundingClientRect().width}px`),this._popover.hasAttribute(`open`)?this._popover.close():this.openPopover()},this._trigger.onkeydown=e=>{let t=Array.from(this._list.querySelectorAll(`[role="option"]:not(:disabled)`));if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),this._popover.hasAttribute(`open`)||this.openPopover();let n=t.findIndex(e=>e.dataset.value===(this.isMultiple()?this.values[0]:this._native.value));t[e.key===`ArrowDown`?Math.min(t.length-1,n+1):Math.max(0,n<=0?0:n-1)]?.focus()}else if(e.key===`Enter`||e.key===` `)if(this._popover.hasAttribute(`open`)){e.preventDefault();let t=this._list.querySelector(`[role="option"]:focus`);t?this.selectOption(t.dataset.value||``):this.openPopover()}else e.key===` `&&(e.preventDefault(),this.openPopover());else e.key===`Escape`&&this._popover.hasAttribute(`open`)?(e.preventDefault(),this._popover.close(),this._trigger.focus()):e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&this.typeahead(e.key)},this._list.onclick=e=>{let t=e.target.closest(`[role="option"]`);t&&!t.disabled&&this.selectOption(t.dataset.value||``)},this._list.onkeydown=e=>{let t=Array.from(this._list.querySelectorAll(`[role="option"]:not(:disabled)`)),n=t.indexOf(e.target),r=n;if(e.key===`ArrowDown`)r=Math.min(t.length-1,n+1);else if(e.key===`ArrowUp`)r=Math.max(0,n-1);else if(e.key===`Home`)r=0;else if(e.key===`End`)r=t.length-1;else if(e.key===`Escape`){e.preventDefault(),this._popover.close(),this._trigger.focus();return}else if(e.key===`Enter`||e.key===` `){e.preventDefault(),this.selectOption(e.target.dataset.value||``);return}else if(e.key.length===1){this.typeahead(e.key);return}else return;e.preventDefault(),t[r]?.focus()},this._native.onchange=()=>{this.isMultiple()?this.setAttribute(`values`,JSON.stringify(this.values)):this.setAttribute(`value`,this._native.value),this.updateDisplay(),this.dispatchSelectionEvents()})}openPopover(){this._popover&&this._popover.open()}selectOption(e){if(this._native){if(this.isMultiple()){let t=new Set(this.values);t.has(e)?t.delete(e):t.add(e);let n=[...t];this._applyValues(n),this.setAttribute(`values`,JSON.stringify(n)),this.updateDisplay(),this.dispatchSelectionEvents();return}this._native.value=e,this.setAttribute(`value`,e),this.updateDisplay(),this._popover?.close(),this._trigger?.focus(),this.dispatchSelectionEvents()}}dispatchSelectionEvents(){let e=this.isMultiple()?this.values:this._native?.value||``,t=this.isMultiple()?{value:e,values:e}:{value:e};this.dispatchEvent(new CustomEvent(`input`,{bubbles:!0,composed:!0,detail:t})),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:t}))}typeahead(e){this._typeahead+=e.toLocaleLowerCase(),this._typeaheadTimer!==null&&window.clearTimeout(this._typeaheadTimer),this._typeaheadTimer=window.setTimeout(()=>{this._typeahead=``},700);let t=Array.from(this._list?.querySelectorAll(`[role="option"]:not(:disabled)`)||[]).find(e=>e.textContent?.trim().toLocaleLowerCase().startsWith(this._typeahead));t&&(this._popover?.hasAttribute(`open`)||this.openPopover(),t.focus())}};customElements.get(`mint-select`)||e.t(`mint-select`,i),exports.NativeSelect=n,exports.default=i;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../chunks/icon-CGXHKbMq.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-Cfhjb8tV.js`),require(`../chunks/popover-Bek5fgHz.js`);var t=`data-mint-native-select-part`,n=class extends HTMLElement{static get observedAttributes(){return[`name`,`value`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`multiple`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._select=null,this._wrapper=null,this._caretUpIcon=null,this._caretDownIcon=null,this._changeHandler=null,this._optionObserver=null,this._childrenObserver=null,this._hostOptionsObserverRaf=null,this._generatedControlId=`mint-native-select-${Math.random().toString(36).slice(2,10)}`}connectedCallback(){this.classList.add(`mint-native-select-host`),this.getLabel()||console.error(`mint-native-select: The "label" attribute is required. Please provide a label for the select.`),this.render(),this._childrenObserver&&this._childrenObserver.disconnect(),this._childrenObserver=new MutationObserver(e=>{if(e.some(e=>{let t=e.target;if(this._select&&(t===this._select||this._select.contains(t)))return!1;let n=Array.from(e.addedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`))||Array.from(e.removedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)),r=e.type===`attributes`&&e.target.nodeType===Node.ELEMENT_NODE&&(e.target.tagName===`OPTION`||e.target.tagName===`OPTGROUP`);return n||r})){if(this._hostOptionsObserverRaf!==null)return;this._hostOptionsObserverRaf=requestAnimationFrame(()=>{this._hostOptionsObserverRaf=null,this.isConnected&&this.render()})}}),this._childrenObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`selected`,`disabled`]})}disconnectedCallback(){this._select&&this._changeHandler&&(this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=null),this._optionObserver&&=(this._optionObserver.disconnect(),null),this._childrenObserver&&=(this._childrenObserver.disconnect(),null),this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null)}isLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._syncSelectAccessibility());return}if(e===`loading`){this.render();return}if(e===`value`){if(this._select)if(this.isMultiple()){let e=[];try{let t=n?JSON.parse(n):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=n?[String(n)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=n||``;return}this.render()}}getName(){return this.getAttribute(`name`)||``}getValue(){if(this.isMultiple()&&this._select){let e=Array.from(this._select.selectedOptions).map(e=>e.value);return JSON.stringify(e)}return this.hasAttribute(`value`)?this.getAttribute(`value`)||``:this._select?this._select.value:``}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(e=>String(e)):e==null||e===``?[]:[String(e)];this.setAttribute(`value`,JSON.stringify(t)),this._select&&Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)});return}let t=e==null?``:String(e);this.setAttribute(`value`,t),this._select&&(this._select.value=t)}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{if(this.isMultiple()){this.setValue(e);return}let t=e||``;(this.getAttribute(`value`)||``)!==t&&this.setAttribute(`value`,t),this._select&&requestAnimationFrame(()=>{this._select&&(t===``||Array.from(this._select.options).some(e=>e.value===t))&&this._select.value!==t&&(this._select.value=t)})}catch{}}isDisabled(){let e=this.getAttribute(`disabled`);return e!==null&&e!==`false`}isMultiple(){let e=this.getAttribute(`multiple`);return e!==null&&e!==`false`}isRequired(){let e=this.getAttribute(`required`);return e!==null&&e!==`false`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getSelectClasses(){return[`mint-native-select-control`,this.isMultiple()?`is-multiple`:``,this.hasError()?`has-error`:``].filter(Boolean).join(` `)}render(){this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null);let e=this.isLoading(),n=this.isMultiple(),r=this.getValue(),i=[];this._select&&Array.from(this._select.children).forEach(e=>{(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)&&i.push(e.cloneNode(!0))}),Array.from(this.children).forEach(e=>{e instanceof HTMLElement&&e.hasAttribute(t)&&e.remove()}),this._wrapper=null,this._select=null;let a=Array.from(this.children).filter(e=>e.tagName===`OPTION`||e.tagName===`OPTGROUP`).map(e=>e.cloneNode(!0)),o=this.getLabel(),s=this.getInfo(),c=this.getId()||this._generatedControlId,l=this.getName(),u=this.isDisabled(),d=this.hasError();if(o){let e=document.createElement(`label`);e.setAttribute(t,`label`),e.className=`mint-native-select-label`,c&&e.setAttribute(`for`,c);let n=document.createTextNode(o);e.appendChild(n),this.appendChild(e)}this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(t,`wrapper`),this._wrapper.className=`mint-native-select-control-wrap`,this.appendChild(this._wrapper),this._select=document.createElement(`select`),this._select.className=this.getSelectClasses(),c&&(this._select.id=c),l&&(this._select.name=l),u&&(this._select.disabled=!0),this._select.required=this.isRequired(),n&&(this._select.multiple=!0),this._select.setAttribute(`aria-invalid`,d?`true`:`false`);let f=this.getAttribute(`aria-label`)?.trim(),p=this.getAttribute(`aria-labelledby`)?.trim();p?this._select.setAttribute(`aria-labelledby`,p):o?this._select.removeAttribute(`aria-label`):this._select.setAttribute(`aria-label`,f||`Select an option`);let m=a.length>0?a:i;if(m.length>0&&m.forEach(e=>{this._select.appendChild(e)}),this._select.options.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`Select an option`,e.disabled=!0,e.selected=!0,this._select.appendChild(e)}if(n){let e=[];try{let t=r?JSON.parse(r):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=r?[String(r)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=r||``;if(this._changeHandler&&this._select&&this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=e=>{let t=e.target,r=n?Array.from(t.selectedOptions).map(e=>e.value):t.value,i=n?JSON.stringify(r):String(r||``);(this.getAttribute(`value`)||``)!==i&&(i?this.setAttribute(`value`,i):this.removeAttribute(`value`));let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener(`change`,this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{let e=this.getAttribute(`value`)||this.value||``;this._select&&e&&requestAnimationFrame(()=>{if(this._select)if(n){let t=[];try{let n=JSON.parse(e);t=Array.isArray(n)?n.map(e=>String(e)):[]}catch{t=[String(e)]}Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)})}else Array.from(this._select.options).some(t=>t.value===e)&&this._select.value!==e&&(this._select.value=e)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),n)this._caretUpIcon=null,this._caretDownIcon=null;else{let e=document.createElement(`div`);e.className=`mint-native-select-caret`,this._caretUpIcon=document.createElement(`mint-icon`),this._caretUpIcon.setAttribute(`name`,`caret-up`),this._caretUpIcon.className=`mint-native-select-caret-up`,this._caretUpIcon.setAttribute(`aria-hidden`,`true`),e.appendChild(this._caretUpIcon),this._caretDownIcon=document.createElement(`mint-icon`),this._caretDownIcon.setAttribute(`name`,`caret-down`),this._caretDownIcon.className=`mint-native-select-caret-down`,this._caretDownIcon.setAttribute(`aria-hidden`,`true`),e.appendChild(this._caretDownIcon),this._wrapper.appendChild(e)}if(s){let e=document.createElement(`div`);e.setAttribute(t,`info`),e.className=`mint-native-select-info`,e.textContent=s,this.appendChild(e)}this._renderErrorState(),this._syncSelectAccessibility(),this._renderSkeleton(e)}_renderSkeleton(e){let t=this.querySelector(`.mint-native-select-skeleton-container`),n=this._wrapper;if(e){t||(t=document.createElement(`div`),t.className=`mint-native-select-skeleton-container`,t.setAttribute(`aria-hidden`,`true`),n?n.appendChild(t):this.appendChild(t));let e=t.querySelector(`.mint-native-select-skeleton`);e||(e=document.createElement(`div`),t.appendChild(e));let r=this.isMultiple();e.classList.toggle(`is-multiple`,r),e.style.height=r?`5rem`:`2rem`,t.style.display=`block`,this._select&&(this._select.style.opacity=`0`,this._select.style.pointerEvents=`none`,this._select.setAttribute(`aria-busy`,`true`))}else t&&(t.style.display=`none`),this._select&&(this._select.style.opacity=`1`,this._select.style.pointerEvents=`auto`,this._select.removeAttribute(`aria-busy`))}_renderErrorState(){let e=this.hasError(),n=this.getErrorMessage(),r=this.querySelector(`.mint-native-select-error`);e&&n?(r?r.hasAttribute(t)||r.setAttribute(t,`error`):(r=document.createElement(`div`),r.setAttribute(t,`error`),r.className=`mint-native-select-error`,this.appendChild(r)),r.textContent=n):r&&r.remove()}_syncSelectAccessibility(){if(!this._select)return;let e=this._select.id||this._generatedControlId,n=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),r=this.querySelector(`[${t}="info"]`),i=this.querySelector(`.mint-native-select-error`);r&&(r.id=`${e}-info`,n.push(r.id)),i&&(i.id=`${e}-error`,n.push(i.id)),n.length?this._select.setAttribute(`aria-describedby`,Array.from(new Set(n)).join(` `)):this._select.removeAttribute(`aria-describedby`)}};customElements.get(`mint-native-select`)||e.t(`mint-native-select`,n);var r=`data-mint-select-part`,i=class extends HTMLElement{constructor(...e){super(...e),this._native=null,this._trigger=null,this._popover=null,this._list=null,this._observer=null,this._syncing=!1,this._typeahead=``,this._typeaheadTimer=null,this._pointerSelectedOption=null,this._id=`mint-select-${Math.random().toString(36).slice(2,10)}`}static get observedAttributes(){return[`name`,`value`,`values`,`multiple`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`loading`,`placeholder`,`aria-label`,`aria-labelledby`,`aria-describedby`,`form`]}connectedCallback(){this.classList.add(`mint-select-host`),this.render(),this._observer?.disconnect(),this._observer=new MutationObserver(e=>{this._syncing||e.some(e=>{let t=e.target instanceof Element?e.target:e.target.parentElement;return t===this||t?.closest(`[${r}]`)?!1:e.type===`attributes`?[`value`,`label`,`disabled`,`selected`].includes(e.attributeName):t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement||[...e.addedNodes,...e.removedNodes].some(e=>e instanceof HTMLOptionElement||e instanceof HTMLOptGroupElement)})&&this.render()}),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`label`,`disabled`,`selected`]})}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._typeaheadTimer!==null&&window.clearTimeout(this._typeaheadTimer)}attributeChangedCallback(e,t,n){if(!(t===n||!this.isConnected)){if(e===`values`&&this._native&&this.isMultiple()){this._applyValues(this.parseValues(n)),this.updateDisplay();return}if(e===`multiple`&&this._native){this.render();return}if(e===`value`&&this._native){this.isMultiple()?this._applyValues(n?[n]:[]):this._native.value=n||``,this.updateDisplay();return}this.render()}}get value(){return this.isMultiple()?this.values:this._native?.value||this.getAttribute(`value`)||``}set value(e){this.setValue(e)}get values(){return this._native&&this.isMultiple()?Array.from(this._native.selectedOptions,e=>e.value):this.parseValues(this.getAttribute(`values`))}set values(e){this.setValue(e)}getValue(){return this.value}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(String):e==null||e===``?[]:[String(e)];this.setAttribute(`values`,JSON.stringify(t)),this._applyValues(t)}else{let t=e==null?``:String(e);this.setAttribute(`value`,t),this._native&&(this._native.value=t)}this.updateDisplay()}isDisabled(){return this.hasAttribute(`disabled`)&&this.getAttribute(`disabled`)!==`false`}isLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}isRequired(){return this.hasAttribute(`required`)&&this.getAttribute(`required`)!==`false`}isMultiple(){return this.hasAttribute(`multiple`)&&this.getAttribute(`multiple`)!==`false`}hasError(){return this.getAttribute(`error`)===`true`}parseValues(e){if(!e)return[];try{let t=JSON.parse(e);if(Array.isArray(t)){if(t.length===1&&typeof t[0]==`string`&&t[0].trim().startsWith(`[`))try{let e=JSON.parse(t[0]);if(Array.isArray(e))return e.map(String)}catch{}return t.map(String)}}catch{}return[e]}_applyValues(e){if(!this._native)return;let t=new Set(e);Array.from(this._native.options).forEach(e=>{e.selected=t.has(e.value)})}options(){return Array.from(this.querySelectorAll(`:scope > option, :scope > optgroup > option`))}selectedOption(){return this._native?.selectedOptions[0]||this.options().find(e=>e.value===this.value)}render(){let e=this._native?.value||this.getAttribute(`value`)||``,t=this._native?.multiple?Array.from(this._native.selectedOptions,e=>e.value):[],n=t.length?t:this.parseValues(this.getAttribute(`values`));this._syncing=!0,Array.from(this.children).forEach(e=>{e.hasAttribute(r)&&e.remove()});let i=this.getAttribute(`label`)?.trim()||``,a=this.getAttribute(`id`)||this._id;if(i){let e=document.createElement(`label`);e.setAttribute(r,`label`),e.className=`mint-select-label`,e.htmlFor=`${a}-trigger`,e.textContent=i,this.append(e)}let o=document.createElement(`div`);o.setAttribute(r,`wrap`),o.className=`mint-select-control-wrap`,o.style.position=`relative`,this.append(o);let s=document.createElement(`button`);s.type=`button`,s.id=`${a}-trigger`,s.className=`mint-select-trigger`,s.disabled=this.isDisabled()||this.isLoading(),s.setAttribute(`role`,`combobox`),s.setAttribute(`aria-busy`,String(this.isLoading())),s.setAttribute(`aria-haspopup`,`listbox`),s.setAttribute(`aria-expanded`,`false`),s.setAttribute(`aria-required`,String(this.isRequired())),s.setAttribute(`aria-invalid`,String(this.hasError()));let c=this.getAttribute(`aria-labelledby`),l=this.getAttribute(`aria-label`)?.trim();if(c?s.setAttribute(`aria-labelledby`,c):!i&&l?s.setAttribute(`aria-label`,l):i&&s.setAttribute(`aria-labelledby`,`${a}-label`),i){let e=this.querySelector(`[${r}="label"]`);e&&(e.id=`${a}-label`)}let u=document.createElement(`span`);u.className=`mint-select-value`,s.append(u);let d=document.createElement(`span`);d.className=`mint-select-caret`,d.setAttribute(`aria-hidden`,`true`),d.innerHTML=`<mint-icon name="caret-up"></mint-icon><mint-icon name="caret-down"></mint-icon>`,s.append(d),o.append(s);let f=null;this.isLoading()?(f=document.createElement(`div`),f.className=`mint-select-skeleton`,f.setAttribute(`aria-hidden`,`true`),f.style.cssText=`position:absolute;inset:0;z-index:1;border:1px solid var(--mint-color-border,#dfe6e0);border-radius:.5rem;background:var(--mint-color-surface-muted,#e8eee9);animation:mint-select-pulse 1.4s ease-in-out infinite;`,o.append(f),s.style.visibility=`hidden`,this.setAttribute(`aria-busy`,`true`)):this.removeAttribute(`aria-busy`);let p=document.createElement(`select`);p.setAttribute(r,`native`),p.className=`mint-select-native-control`,p.id=`${a}-native`,p.name=this.getAttribute(`name`)||``,p.multiple=this.isMultiple(),this.hasAttribute(`form`)&&p.setAttribute(`form`,this.getAttribute(`form`)||``),p.required=this.isRequired(),p.disabled=this.isDisabled(),p.tabIndex=-1,p.setAttribute(`aria-hidden`,`true`),p.setAttribute(`aria-invalid`,String(this.hasError()));let m=[this.getAttribute(`aria-describedby`),i?`${a}-label`:``,this.getAttribute(`info`)?`${a}-info`:``,this.getAttribute(`error-message`)?`${a}-error`:``].filter(Boolean).join(` `);if(m&&p.setAttribute(`aria-describedby`,m),this.options().forEach(e=>p.append(e.cloneNode(!0))),!p.options.length){let e=document.createElement(`option`);e.value=``,e.textContent=this.getAttribute(`placeholder`)||`Select an option`,e.disabled=!0,p.append(e)}if(p.multiple){let t=n.length?n:this.parseValues(this.getAttribute(`values`)).length?this.parseValues(this.getAttribute(`values`)):e?[e]:[];t.length&&Array.from(p.options).forEach(e=>{e.selected=t.includes(e.value)})}else p.value=e;o.append(p),this._native=p,this._trigger=s;let h=document.createElement(`mint-popover`);h.className=`mint-select-popover`,h.setAttribute(r,`popover`),h.setAttribute(`trigger-id`,s.id),h.setAttribute(`trigger-toggle`,`false`),h.setAttribute(`direction`,`down`),h.setAttribute(`trigger-align`,`start`),h.setAttribute(`align-selected`,`true`),h.setAttribute(`distance`,`4`),h.setAttribute(`padding`,`0`),h.setAttribute(`aria-label`,i?`${i} options`:`Select options`);let g=document.createElement(`div`);g.className=`mint-select-options`,g.id=`${a}-listbox`,g.setAttribute(`role`,`listbox`),g.setAttribute(`aria-multiselectable`,String(this.isMultiple())),s.setAttribute(`aria-controls`,g.id),h.append(g),this.append(h),this._popover=h,this._list=g,this.renderOptions(),this.updateDisplay(),this.bindEvents();let _=this.getAttribute(`info`);if(_){let e=document.createElement(`div`);e.setAttribute(r,`info`),e.className=`mint-select-info`,e.id=`${a}-info`,e.textContent=_,this.append(e)}let v=this.getAttribute(`error-message`);if(this.hasError()&&v){let e=document.createElement(`div`);e.setAttribute(r,`error`),e.className=`mint-select-error`,e.id=`${a}-error`,e.textContent=v,this.append(e)}this._syncing=!1}renderOptions(){this._list&&(this._list.replaceChildren(),Array.from(this.children).filter(e=>e.tagName===`OPTION`||e.tagName===`OPTGROUP`).forEach(e=>{if(e instanceof HTMLOptGroupElement){let t=document.createElement(`div`);t.className=`mint-select-group-label`,t.setAttribute(`role`,`presentation`),t.textContent=e.label,this._list.append(t),Array.from(e.children).forEach(t=>this.addOption(t,e.disabled))}else this.addOption(e,!1)}))}addOption(e,t){if(!this._list)return;let n=document.createElement(`button`);n.type=`button`,n.className=`mint-select-option`,n.dataset.value=e.value,n.setAttribute(`role`,`option`),n.setAttribute(`aria-selected`,String(this.isMultiple()?this.values.includes(e.value):e.value===this.value)),n.disabled=e.disabled||t||this.isDisabled(),n.tabIndex=-1;let r=document.createElement(`span`);r.textContent=e.label||e.textContent||``,n.append(r);let i=document.createElement(`mint-icon`);i.setAttribute(`name`,`check`),i.setAttribute(`aria-hidden`,`true`),i.className=`mint-select-option-check`,n.append(i),this._list.append(n)}updateDisplay(){if(!this._native||!this._trigger)return;let e=this.selectedOption(),t=this.values,n=this.isMultiple()?t.map(e=>this.options().find(t=>t.value===e)?.label||e):[],r=this._trigger.querySelector(`.mint-select-value`);r&&(r.textContent=this.isMultiple()?n.join(`, `)||this.getAttribute(`placeholder`)||`Select an option`:e?.label||e?.textContent?.trim()||this.getAttribute(`placeholder`)||`Select an option`,r.classList.toggle(`is-placeholder`,this.isMultiple()?t.length===0:!e||e.value===``)),this._trigger.setAttribute(`aria-invalid`,String(this.hasError())),this._trigger.setAttribute(`aria-haspopup`,`listbox`),this._list?.setAttribute(`aria-multiselectable`,String(this.isMultiple())),this._list?.querySelectorAll(`[role="option"]`).forEach(e=>e.setAttribute(`aria-selected`,String(this.isMultiple()?t.includes(e.dataset.value||``):e.dataset.value===this._native.value)))}bindEvents(){!this._trigger||!this._popover||!this._native||!this._list||(this._trigger.onclick=()=>{this._popover.style.setProperty(`--mint-select-popover-width`,`${this._trigger.getBoundingClientRect().width}px`),this._popover.hasAttribute(`open`)?this._popover.close():this.openPopover()},this._trigger.onkeydown=e=>{let t=Array.from(this._list.querySelectorAll(`[role="option"]:not(:disabled)`));if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),this._popover.hasAttribute(`open`)||this.openPopover();let n=t.findIndex(e=>e.dataset.value===(this.isMultiple()?this.values[0]:this._native.value));t[e.key===`ArrowDown`?Math.min(t.length-1,n+1):Math.max(0,n<=0?0:n-1)]?.focus()}else if(e.key===`Enter`||e.key===` `)if(this._popover.hasAttribute(`open`)){e.preventDefault();let t=this._list.querySelector(`[role="option"]:focus`);t?this.selectOption(t.dataset.value||``):this.openPopover()}else e.key===` `&&(e.preventDefault(),this.openPopover());else e.key===`Escape`&&this._popover.hasAttribute(`open`)?(e.preventDefault(),this._popover.close(),this._trigger.focus()):e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&this.typeahead(e.key)},this._list.onpointerdown=e=>{let t=e.target.closest(`[role="option"]`);if(!t||t.disabled)return;e.preventDefault();let n=t.dataset.value||``;this._pointerSelectedOption={value:n,time:Date.now()},this.selectOption(n)},this._list.onclick=e=>{let t=e.target.closest(`[role="option"]`);if(!t||t.disabled)return;let n=t.dataset.value||``,r=this._pointerSelectedOption?.value===n&&Date.now()-this._pointerSelectedOption.time<1e3;this._pointerSelectedOption=null,r||this.selectOption(n)},this._list.onkeydown=e=>{let t=Array.from(this._list.querySelectorAll(`[role="option"]:not(:disabled)`)),n=t.indexOf(e.target),r=n;if(e.key===`ArrowDown`)r=Math.min(t.length-1,n+1);else if(e.key===`ArrowUp`)r=Math.max(0,n-1);else if(e.key===`Home`)r=0;else if(e.key===`End`)r=t.length-1;else if(e.key===`Escape`){e.preventDefault(),this._popover.close(),this._trigger.focus();return}else if(e.key===`Enter`||e.key===` `){e.preventDefault(),this.selectOption(e.target.dataset.value||``);return}else if(e.key.length===1){this.typeahead(e.key);return}else return;e.preventDefault(),t[r]?.focus()},this._native.onchange=()=>{this.isMultiple()?this.setAttribute(`values`,JSON.stringify(this.values)):this.setAttribute(`value`,this._native.value),this.updateDisplay(),this.dispatchSelectionEvents()})}openPopover(){this._popover&&this._popover.open()}selectOption(e){if(this._native){if(this.isMultiple()){let t=new Set(this.values);t.has(e)?t.delete(e):t.add(e);let n=[...t];this._applyValues(n),this.setAttribute(`values`,JSON.stringify(n)),this.updateDisplay(),this.dispatchSelectionEvents();return}this._native.value=e,this.setAttribute(`value`,e),this.updateDisplay(),this._popover?.close(),this._trigger?.focus(),this.dispatchSelectionEvents()}}dispatchSelectionEvents(){let e=this.isMultiple()?this.values:this._native?.value||``,t=this.isMultiple()?{value:e,values:e}:{value:e};this.dispatchEvent(new CustomEvent(`input`,{bubbles:!0,composed:!0,detail:t})),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:t}))}typeahead(e){this._typeahead+=e.toLocaleLowerCase(),this._typeaheadTimer!==null&&window.clearTimeout(this._typeaheadTimer),this._typeaheadTimer=window.setTimeout(()=>{this._typeahead=``},700);let t=Array.from(this._list?.querySelectorAll(`[role="option"]:not(:disabled)`)||[]).find(e=>e.textContent?.trim().toLocaleLowerCase().startsWith(this._typeahead));t&&(this._popover?.hasAttribute(`open`)||this.openPopover(),t.focus())}};customElements.get(`mint-select`)||e.t(`mint-select`,i),exports.NativeSelect=n,exports.default=i;
@@ -274,7 +274,7 @@ customElements.get("mint-native-select") || e("mint-native-select", n);
274
274
  //#region src/components/select/Select.ts
275
275
  var r = "data-mint-select-part", i = class extends HTMLElement {
276
276
  constructor(...e) {
277
- super(...e), this._native = null, this._trigger = null, this._popover = null, this._list = null, this._observer = null, this._syncing = !1, this._typeahead = "", this._typeaheadTimer = null, this._id = `mint-select-${Math.random().toString(36).slice(2, 10)}`;
277
+ super(...e), this._native = null, this._trigger = null, this._popover = null, this._list = null, this._observer = null, this._syncing = !1, this._typeahead = "", this._typeaheadTimer = null, this._pointerSelectedOption = null, this._id = `mint-select-${Math.random().toString(36).slice(2, 10)}`;
278
278
  }
279
279
  static get observedAttributes() {
280
280
  return [
@@ -409,62 +409,62 @@ var r = "data-mint-select-part", i = class extends HTMLElement {
409
409
  return this._native?.selectedOptions[0] || this.options().find((e) => e.value === this.value);
410
410
  }
411
411
  render() {
412
- let e = this._native?.value ?? this.getAttribute("value") ?? "", t = this._native && this._native.multiple ? Array.from(this._native.selectedOptions, (e) => e.value) : this.parseValues(this.getAttribute("values"));
412
+ let e = this._native?.value || this.getAttribute("value") || "", t = this._native?.multiple ? Array.from(this._native.selectedOptions, (e) => e.value) : [], n = t.length ? t : this.parseValues(this.getAttribute("values"));
413
413
  this._syncing = !0, Array.from(this.children).forEach((e) => {
414
414
  e.hasAttribute(r) && e.remove();
415
415
  });
416
- let n = this.getAttribute("label")?.trim() || "", i = this.getAttribute("id") || this._id;
417
- if (n) {
416
+ let i = this.getAttribute("label")?.trim() || "", a = this.getAttribute("id") || this._id;
417
+ if (i) {
418
418
  let e = document.createElement("label");
419
- e.setAttribute(r, "label"), e.className = "mint-select-label", e.htmlFor = `${i}-trigger`, e.textContent = n, this.append(e);
419
+ e.setAttribute(r, "label"), e.className = "mint-select-label", e.htmlFor = `${a}-trigger`, e.textContent = i, this.append(e);
420
420
  }
421
- let a = document.createElement("div");
422
- a.setAttribute(r, "wrap"), a.className = "mint-select-control-wrap", a.style.position = "relative", this.append(a);
423
- let o = document.createElement("button");
424
- o.type = "button", o.id = `${i}-trigger`, o.className = "mint-select-trigger", o.disabled = this.isDisabled() || this.isLoading(), o.setAttribute("role", "combobox"), o.setAttribute("aria-busy", String(this.isLoading())), o.setAttribute("aria-haspopup", "listbox"), o.setAttribute("aria-expanded", "false"), o.setAttribute("aria-required", String(this.isRequired())), o.setAttribute("aria-invalid", String(this.hasError()));
425
- let s = this.getAttribute("aria-labelledby"), c = this.getAttribute("aria-label")?.trim();
426
- if (s ? o.setAttribute("aria-labelledby", s) : !n && c ? o.setAttribute("aria-label", c) : n && o.setAttribute("aria-labelledby", `${i}-label`), n) {
421
+ let o = document.createElement("div");
422
+ o.setAttribute(r, "wrap"), o.className = "mint-select-control-wrap", o.style.position = "relative", this.append(o);
423
+ let s = document.createElement("button");
424
+ s.type = "button", s.id = `${a}-trigger`, s.className = "mint-select-trigger", s.disabled = this.isDisabled() || this.isLoading(), s.setAttribute("role", "combobox"), s.setAttribute("aria-busy", String(this.isLoading())), s.setAttribute("aria-haspopup", "listbox"), s.setAttribute("aria-expanded", "false"), s.setAttribute("aria-required", String(this.isRequired())), s.setAttribute("aria-invalid", String(this.hasError()));
425
+ let c = this.getAttribute("aria-labelledby"), l = this.getAttribute("aria-label")?.trim();
426
+ if (c ? s.setAttribute("aria-labelledby", c) : !i && l ? s.setAttribute("aria-label", l) : i && s.setAttribute("aria-labelledby", `${a}-label`), i) {
427
427
  let e = this.querySelector(`[${r}="label"]`);
428
- e && (e.id = `${i}-label`);
428
+ e && (e.id = `${a}-label`);
429
429
  }
430
- let l = document.createElement("span");
431
- l.className = "mint-select-value", o.append(l);
432
430
  let u = document.createElement("span");
433
- u.className = "mint-select-caret", u.setAttribute("aria-hidden", "true"), u.innerHTML = "<mint-icon name=\"caret-up\"></mint-icon><mint-icon name=\"caret-down\"></mint-icon>", o.append(u), a.append(o);
434
- let d = null;
435
- this.isLoading() ? (d = document.createElement("div"), d.className = "mint-select-skeleton", d.setAttribute("aria-hidden", "true"), d.style.cssText = "position:absolute;inset:0;z-index:1;border:1px solid var(--mint-color-border,#dfe6e0);border-radius:.5rem;background:var(--mint-color-surface-muted,#e8eee9);animation:mint-select-pulse 1.4s ease-in-out infinite;", a.append(d), o.style.visibility = "hidden", this.setAttribute("aria-busy", "true")) : this.removeAttribute("aria-busy");
436
- let f = document.createElement("select");
437
- f.setAttribute(r, "native"), f.className = "mint-select-native-control", f.id = `${i}-native`, f.name = this.getAttribute("name") || "", f.multiple = this.isMultiple(), this.hasAttribute("form") && f.setAttribute("form", this.getAttribute("form") || ""), f.required = this.isRequired(), f.disabled = this.isDisabled(), f.tabIndex = -1, f.setAttribute("aria-hidden", "true"), f.setAttribute("aria-invalid", String(this.hasError()));
438
- let p = [
431
+ u.className = "mint-select-value", s.append(u);
432
+ let d = document.createElement("span");
433
+ d.className = "mint-select-caret", d.setAttribute("aria-hidden", "true"), d.innerHTML = "<mint-icon name=\"caret-up\"></mint-icon><mint-icon name=\"caret-down\"></mint-icon>", s.append(d), o.append(s);
434
+ let f = null;
435
+ this.isLoading() ? (f = document.createElement("div"), f.className = "mint-select-skeleton", f.setAttribute("aria-hidden", "true"), f.style.cssText = "position:absolute;inset:0;z-index:1;border:1px solid var(--mint-color-border,#dfe6e0);border-radius:.5rem;background:var(--mint-color-surface-muted,#e8eee9);animation:mint-select-pulse 1.4s ease-in-out infinite;", o.append(f), s.style.visibility = "hidden", this.setAttribute("aria-busy", "true")) : this.removeAttribute("aria-busy");
436
+ let p = document.createElement("select");
437
+ p.setAttribute(r, "native"), p.className = "mint-select-native-control", p.id = `${a}-native`, p.name = this.getAttribute("name") || "", p.multiple = this.isMultiple(), this.hasAttribute("form") && p.setAttribute("form", this.getAttribute("form") || ""), p.required = this.isRequired(), p.disabled = this.isDisabled(), p.tabIndex = -1, p.setAttribute("aria-hidden", "true"), p.setAttribute("aria-invalid", String(this.hasError()));
438
+ let m = [
439
439
  this.getAttribute("aria-describedby"),
440
- n ? `${i}-label` : "",
441
- this.getAttribute("info") ? `${i}-info` : "",
442
- this.getAttribute("error-message") ? `${i}-error` : ""
440
+ i ? `${a}-label` : "",
441
+ this.getAttribute("info") ? `${a}-info` : "",
442
+ this.getAttribute("error-message") ? `${a}-error` : ""
443
443
  ].filter(Boolean).join(" ");
444
- if (p && f.setAttribute("aria-describedby", p), this.options().forEach((e) => f.append(e.cloneNode(!0))), !f.options.length) {
444
+ if (m && p.setAttribute("aria-describedby", m), this.options().forEach((e) => p.append(e.cloneNode(!0))), !p.options.length) {
445
445
  let e = document.createElement("option");
446
- e.value = "", e.textContent = this.getAttribute("placeholder") || "Select an option", e.disabled = !0, f.append(e);
446
+ e.value = "", e.textContent = this.getAttribute("placeholder") || "Select an option", e.disabled = !0, p.append(e);
447
447
  }
448
- if (f.multiple) {
449
- let n = t.length ? t : this.parseValues(this.getAttribute("values")).length ? this.parseValues(this.getAttribute("values")) : e ? [e] : [];
450
- n.length && Array.from(f.options).forEach((e) => {
451
- e.selected = n.includes(e.value);
448
+ if (p.multiple) {
449
+ let t = n.length ? n : this.parseValues(this.getAttribute("values")).length ? this.parseValues(this.getAttribute("values")) : e ? [e] : [];
450
+ t.length && Array.from(p.options).forEach((e) => {
451
+ e.selected = t.includes(e.value);
452
452
  });
453
- } else f.value = e;
454
- a.append(f), this._native = f, this._trigger = o;
455
- let m = document.createElement("mint-popover");
456
- m.className = "mint-select-popover", m.setAttribute(r, "popover"), m.setAttribute("trigger-id", o.id), m.setAttribute("trigger-toggle", "false"), m.setAttribute("direction", "down"), m.setAttribute("trigger-align", "start"), m.setAttribute("align-selected", "true"), m.setAttribute("distance", "4"), m.setAttribute("padding", "0"), m.setAttribute("aria-label", n ? `${n} options` : "Select options");
457
- let h = document.createElement("div");
458
- h.className = "mint-select-options", h.id = `${i}-listbox`, h.setAttribute("role", "listbox"), h.setAttribute("aria-multiselectable", String(this.isMultiple())), o.setAttribute("aria-controls", h.id), m.append(h), this.append(m), this._popover = m, this._list = h, this.renderOptions(), this.updateDisplay(), this.bindEvents();
459
- let g = this.getAttribute("info");
460
- if (g) {
453
+ } else p.value = e;
454
+ o.append(p), this._native = p, this._trigger = s;
455
+ let h = document.createElement("mint-popover");
456
+ h.className = "mint-select-popover", h.setAttribute(r, "popover"), h.setAttribute("trigger-id", s.id), h.setAttribute("trigger-toggle", "false"), h.setAttribute("direction", "down"), h.setAttribute("trigger-align", "start"), h.setAttribute("align-selected", "true"), h.setAttribute("distance", "4"), h.setAttribute("padding", "0"), h.setAttribute("aria-label", i ? `${i} options` : "Select options");
457
+ let g = document.createElement("div");
458
+ g.className = "mint-select-options", g.id = `${a}-listbox`, g.setAttribute("role", "listbox"), g.setAttribute("aria-multiselectable", String(this.isMultiple())), s.setAttribute("aria-controls", g.id), h.append(g), this.append(h), this._popover = h, this._list = g, this.renderOptions(), this.updateDisplay(), this.bindEvents();
459
+ let _ = this.getAttribute("info");
460
+ if (_) {
461
461
  let e = document.createElement("div");
462
- e.setAttribute(r, "info"), e.className = "mint-select-info", e.id = `${i}-info`, e.textContent = g, this.append(e);
462
+ e.setAttribute(r, "info"), e.className = "mint-select-info", e.id = `${a}-info`, e.textContent = _, this.append(e);
463
463
  }
464
- let _ = this.getAttribute("error-message");
465
- if (this.hasError() && _) {
464
+ let v = this.getAttribute("error-message");
465
+ if (this.hasError() && v) {
466
466
  let e = document.createElement("div");
467
- e.setAttribute(r, "error"), e.className = "mint-select-error", e.id = `${i}-error`, e.textContent = _, this.append(e);
467
+ e.setAttribute(r, "error"), e.className = "mint-select-error", e.id = `${a}-error`, e.textContent = v, this.append(e);
468
468
  }
469
469
  this._syncing = !1;
470
470
  }
@@ -505,9 +505,20 @@ var r = "data-mint-select-part", i = class extends HTMLElement {
505
505
  t ? this.selectOption(t.dataset.value || "") : this.openPopover();
506
506
  } else e.key === " " && (e.preventDefault(), this.openPopover());
507
507
  else e.key === "Escape" && this._popover.hasAttribute("open") ? (e.preventDefault(), this._popover.close(), this._trigger.focus()) : e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && this.typeahead(e.key);
508
+ }, this._list.onpointerdown = (e) => {
509
+ let t = e.target.closest("[role=\"option\"]");
510
+ if (!t || t.disabled) return;
511
+ e.preventDefault();
512
+ let n = t.dataset.value || "";
513
+ this._pointerSelectedOption = {
514
+ value: n,
515
+ time: Date.now()
516
+ }, this.selectOption(n);
508
517
  }, this._list.onclick = (e) => {
509
518
  let t = e.target.closest("[role=\"option\"]");
510
- t && !t.disabled && this.selectOption(t.dataset.value || "");
519
+ if (!t || t.disabled) return;
520
+ let n = t.dataset.value || "", r = this._pointerSelectedOption?.value === n && Date.now() - this._pointerSelectedOption.time < 1e3;
521
+ this._pointerSelectedOption = null, r || this.selectOption(n);
511
522
  }, this._list.onkeydown = (e) => {
512
523
  let t = Array.from(this._list.querySelectorAll("[role=\"option\"]:not(:disabled)")), n = t.indexOf(e.target), r = n;
513
524
  if (e.key === "ArrowDown") r = Math.min(t.length - 1, n + 1);