monobill-mintui 0.6.718 → 0.6.721
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.
- package/bin/component-dependencies.json +1 -0
- package/dist/checkbox.css +1 -1
- package/dist/components/alert/browser.js +4 -4
- package/dist/components/alert/index.cjs +1 -1
- package/dist/components/alert/index.js +4 -4
- package/dist/components/back-button/browser.js +1 -1
- package/dist/components/back-button/index.cjs +1 -1
- package/dist/components/back-button/index.js +1 -1
- package/dist/components/bottom-navigation/browser.js +2 -2
- package/dist/components/bottom-navigation/index.cjs +1 -1
- package/dist/components/bottom-navigation/index.js +2 -2
- package/dist/components/button/browser.js +1 -1
- package/dist/components/button/index.cjs +1 -1
- package/dist/components/button/index.js +1 -1
- package/dist/components/checkbox/Checkbox.d.ts +3 -0
- package/dist/components/checkbox/Checkbox.d.ts.map +1 -1
- package/dist/components/checkbox/browser.js +2 -186
- package/dist/components/checkbox/index.cjs +1 -1
- package/dist/components/checkbox/index.js +2 -186
- package/dist/components/chip/browser.js +1 -1
- package/dist/components/chip/index.cjs +1 -1
- package/dist/components/chip/index.js +1 -1
- package/dist/components/chunks/{back-button-By8eO_KR.js → back-button-C0ajSqKu.js} +2 -2
- package/dist/components/chunks/{back-button-BGzrOtpx.js → back-button-Dw4NF_vN.js} +1 -1
- package/dist/components/chunks/{button-B_yN18B-.js → button-B4BMYTk1.js} +1 -1
- package/dist/components/chunks/{button-JPTyQfRs.js → button-BTQHrE0x.js} +2 -2
- package/dist/components/chunks/caret-down-DbFlPN-2.js +1 -0
- package/dist/components/chunks/{caret-down-ZjQN2yKq.js → caret-down-pn6aBT-u.js} +1 -1
- package/dist/components/chunks/caret-right-B8gOXLh9.js +1 -0
- package/dist/components/chunks/{caret-right-BlRbsLlh.js → caret-right-DDGEbhEH.js} +1 -1
- package/dist/components/chunks/checkbox-BKU8fiY7.js +1 -0
- package/dist/components/chunks/checkbox-p-Fb5ojp.js +193 -0
- package/dist/components/chunks/{chip-BUaS7ks-.js → chip-B0kg_vr8.js} +1 -1
- package/dist/components/chunks/{chip-XuYPtZ3Z.js → chip-bcCOd6-h.js} +3 -3
- package/dist/components/chunks/{close-Cn8XLO1c.js → close-8VXvDCau.js} +1 -1
- package/dist/components/chunks/close-CWAmmMRg.js +1 -0
- package/dist/components/chunks/{confirm-action-CX_FEzCR.js → confirm-action-BW1UwJNu.js} +2 -2
- package/dist/components/chunks/{confirm-action-86hDdUKT.js → confirm-action-sovGys0x.js} +1 -1
- package/dist/components/chunks/{date-picker-J8AtC8Py.js → date-picker-CDEVgbw7.js} +1 -1
- package/dist/components/chunks/{date-picker-BLqafHuc.js → date-picker-R2gbHZCP.js} +5 -5
- package/dist/components/chunks/{icon-CWOP4Com.js → icon-B9P0jyS2.js} +6 -6
- package/dist/components/chunks/icon-CIAsmizQ.js +1 -0
- package/dist/components/chunks/icon-Cia9x_J2.js +1 -0
- package/dist/components/chunks/{icon-hyFz3uhh.js → icon-DAB2KLeo.js} +217 -207
- package/dist/components/chunks/{input-BI4nrOaG.js → input-BXC4lMG_.js} +1 -1
- package/dist/components/chunks/{input-B-njkq5j.js → input-B_q63xQu.js} +3 -3
- package/dist/components/chunks/{modal-BEv3P1P0.js → modal-BixpSAyU.js} +10 -30
- package/dist/components/chunks/{modal-ux6cqTde.js → modal-BrIOYE1W.js} +1 -1
- package/dist/components/chunks/{popover-0YEhBrgv.js → popover-CWWKb7L1.js} +1 -1
- package/dist/components/chunks/{popover-CE2t5dKP.js → popover-DPNBidSz.js} +1 -1
- package/dist/components/chunks/search-CGQa7dR2.js +1 -0
- package/dist/components/chunks/{search-BwjKBnv9.js → search-COAeeXxO.js} +1 -1
- package/dist/components/chunks/{select-DS2CJyXR.js → select-CHImyDWO.js} +1 -1
- package/dist/components/chunks/{select-DDnYtBVR.js → select-CnN6eiFK.js} +3 -3
- package/dist/components/chunks/{table-slcPmVWy.js → table-B_S4xwx3.js} +1 -1
- package/dist/components/chunks/{table-B_g7lNzN.js → table-C6ufpGLx.js} +1 -1
- package/dist/components/chunks/{time-picker-EAyF05v1.js → time-picker-CijVykQ3.js} +1 -1
- package/dist/components/chunks/{time-picker-MtNyIZFb.js → time-picker-NksIqyuD.js} +3 -3
- package/dist/components/chunks/{warning-DKCaTYO6.js → warning-CVnTPaMj.js} +1 -1
- package/dist/components/chunks/{warning-DAYbxh3S.js → warning-vve-cXPr.js} +1 -1
- package/dist/components/confirm-action/browser.js +1 -1
- package/dist/components/confirm-action/index.cjs +1 -1
- package/dist/components/confirm-action/index.js +1 -1
- package/dist/components/date-picker/browser.js +1 -1
- package/dist/components/date-picker/index.cjs +1 -1
- package/dist/components/date-picker/index.js +1 -1
- package/dist/components/datetime-picker/browser.js +3 -3
- package/dist/components/datetime-picker/index.cjs +1 -1
- package/dist/components/datetime-picker/index.js +3 -3
- package/dist/components/dropzone/browser.js +4 -4
- package/dist/components/dropzone/index.cjs +1 -1
- package/dist/components/dropzone/index.js +4 -4
- package/dist/components/icon/browser.js +1 -1
- package/dist/components/icon/icons/code.d.ts +3 -0
- package/dist/components/icon/icons/code.d.ts.map +1 -0
- package/dist/components/icon/icons/index.d.ts +1 -0
- package/dist/components/icon/icons/index.d.ts.map +1 -1
- package/dist/components/icon/index.cjs +1 -1
- package/dist/components/icon/index.js +1 -1
- package/dist/components/input/browser.js +1 -1
- package/dist/components/input/index.cjs +1 -1
- package/dist/components/input/index.js +1 -1
- package/dist/components/link/browser.js +1 -1
- package/dist/components/link/index.cjs +1 -1
- package/dist/components/link/index.js +1 -1
- package/dist/components/modal/Modal.d.ts +0 -1
- package/dist/components/modal/Modal.d.ts.map +1 -1
- package/dist/components/modal/browser.js +1 -1
- package/dist/components/modal/index.cjs +1 -1
- package/dist/components/modal/index.js +1 -1
- package/dist/components/navigation/browser.js +4 -4
- package/dist/components/navigation/index.cjs +1 -1
- package/dist/components/navigation/index.js +4 -4
- package/dist/components/off-canvas/browser.js +3 -3
- package/dist/components/off-canvas/index.cjs +1 -1
- package/dist/components/off-canvas/index.js +3 -3
- package/dist/components/page/browser.js +4 -4
- package/dist/components/page/index.cjs +1 -1
- package/dist/components/page/index.js +4 -4
- package/dist/components/popover/browser.js +1 -1
- package/dist/components/popover/index.cjs +1 -1
- package/dist/components/popover/index.js +1 -1
- package/dist/components/resource-table/ResourceTable.d.ts +25 -0
- package/dist/components/resource-table/ResourceTable.d.ts.map +1 -1
- package/dist/components/resource-table/browser.js +127 -35
- package/dist/components/resource-table/index.cjs +2 -2
- package/dist/components/resource-table/index.js +127 -35
- package/dist/components/scroll-fade/browser.js +1 -1
- package/dist/components/scroll-fade/index.cjs +1 -1
- package/dist/components/scroll-fade/index.js +1 -1
- package/dist/components/search/browser.js +7 -7
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +7 -7
- package/dist/components/select/browser.js +1 -1
- package/dist/components/select/index.cjs +1 -1
- package/dist/components/select/index.js +1 -1
- package/dist/components/side-navigation/browser.js +6 -6
- package/dist/components/side-navigation/index.cjs +1 -1
- package/dist/components/side-navigation/index.js +6 -6
- package/dist/components/sortable/browser.js +1 -1
- package/dist/components/sortable/index.cjs +1 -1
- package/dist/components/sortable/index.js +1 -1
- package/dist/components/stack/browser.js +1 -1
- package/dist/components/stack/index.cjs +1 -1
- package/dist/components/stack/index.js +1 -1
- package/dist/components/switch/browser.js +2 -2
- package/dist/components/switch/index.cjs +1 -1
- package/dist/components/switch/index.js +2 -2
- package/dist/components/table/browser.js +1 -1
- package/dist/components/table/index.cjs +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/tabs/browser.js +1 -1
- package/dist/components/tabs/index.cjs +1 -1
- package/dist/components/tabs/index.js +1 -1
- package/dist/components/tags/browser.js +4 -4
- package/dist/components/tags/index.cjs +1 -1
- package/dist/components/tags/index.js +4 -4
- package/dist/components/time-picker/browser.js +1 -1
- package/dist/components/time-picker/index.cjs +1 -1
- package/dist/components/time-picker/index.js +1 -1
- package/dist/components/tree/browser.js +5 -5
- package/dist/components/tree/index.cjs +1 -1
- package/dist/components/tree/index.js +5 -5
- package/dist/icons/code.svg +3 -0
- package/dist/index.cjs +11 -11
- package/dist/index.css +3 -3
- package/dist/index.js +521 -434
- package/dist/modal.css +1 -1
- package/dist/navigation-search.json +7 -0
- package/dist/resource-table.css +1 -1
- package/package.json +1 -1
- package/dist/components/chunks/caret-down-BFHFcMyL.js +0 -1
- package/dist/components/chunks/caret-right--YnEL-Ny.js +0 -1
- package/dist/components/chunks/close-DSrpkGHJ.js +0 -1
- package/dist/components/chunks/icon-D6C1XGp2.js +0 -1
- package/dist/components/chunks/icon-l34kRIZg.js +0 -1
- package/dist/components/chunks/search-q3dkl4-X.js +0 -1
- /package/dist/components/chunks/{ScrollFade-DvzPIk2A.js → ScrollFade-Cg9fVO0V.js} +0 -0
- /package/dist/components/chunks/{ScrollFade-BMs09zZN.js → ScrollFade-Dfq2B1Hm.js} +0 -0
- /package/dist/components/chunks/{link-DVKhDl3O.js → link-B_fNmwOk.js} +0 -0
- /package/dist/components/chunks/{link-ACOyvLkd.js → link-BxTQfAW9.js} +0 -0
- /package/dist/components/chunks/{sortable-BSw58wy_.js → sortable-Bql13n3L.js} +0 -0
- /package/dist/components/chunks/{sortable-D3et5wXB.js → sortable-DdT2ptc5.js} +0 -0
- /package/dist/components/chunks/{stack-DEIdHS0n.js → stack-CK2o4-As.js} +0 -0
- /package/dist/components/chunks/{stack-CzcHNnl8.js → stack-CKUu8IVZ.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./icon-CWOP4Com.js`),t=require(`./register-element-tCL_F1YI.js`);require(`./icon-D6C1XGp2.js`),require(`./caret-down-BFHFcMyL.js`),e.a({name:`caret-up`,viewBox:`0 0 24 24`,path:`M5 15l7-7 7 7`,strokeLinecap:`round`,strokeLinejoin:`round`});var n=class extends HTMLElement{static get observedAttributes(){return[`type`,`placeholder`,`value`,`disabled`,`id`,`name`,`required`,`readonly`,`rows`,`min`,`max`,`step`,`decimal-places`,`thousands-separator`,`decimal-point`,`icon`,`label`,`info`,`error`,`error-message`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._input=null,this._textarea=null,this._element=null,this._wrapper=null,this._icon=null,this._prependSlotContainer=null,this._appendSlotContainer=null,this._colorPicker=null,this._colorTextInput=null,this._colorContainer=null,this._colorPickerWrapper=null,this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null,this._contentObserver=null,this._focusHandler=null,this._a11yId=``,this._blurHandler=null,this._clickHandler=null,this._clickOutsideHandler=null,this._renderFrame=null}connectedCallback(){this.classList.add(`mint-input-host`),this.render(),this._observeContentMutations()}disconnectedCallback(){this.removeEventListeners(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._syncControlAccessibility(),this._element&&(this._element.className=this.getInputClasses()),this._colorTextInput&&(this._colorTextInput.className=this.getInputClasses());return}if(e===`loading`){this.render();return}this.render()}}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(e=>{e.some(e=>e.type===`childList`?e.target===this:e.type===`attributes`&&e.target.hasAttribute(`slot`))&&this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}getType(){return this.getAttribute(`type`)||`text`}getRows(){let e=this.getAttribute(`rows`);return e?parseInt(e,10):3}_getNormalizedType(){let e=this.getType();return e===`datetime`?`datetime-local`:e===`money`?`text`:e===`textarea`?`textarea`:e}_isTextarea(){return this.getType()===`textarea`}_isMoney(){return this.getType()===`money`}_getMoneyDecimalPlaces(){let e=this.getAttribute(`decimal-places`);return e===null||!/^\d+$/.test(e)?2:Math.min(20,Number(e))}_formatMoneyValue(e,t){let n=e.trim();if(!n)return``;let r=this._getMoneyDecimalPlaces(),i=this.getAttribute(`decimal-point`)??`.`,a=this.getAttribute(`thousands-separator`)??`,`,o=i||`.`,s=a===o?``:a,c=/^\(.*\)$/.test(n),l=c?n.slice(1,-1).trim():n;s&&(l=l.split(s).join(``)),l=l.replace(/[\s$€£¥₹₩₽¢]/g,``);let u=l.split(o);u.length>2&&u.splice(1,u.length-1,u.slice(1).join(``));let d=u[0]??``,f=u.length>1?u[1]:``,p=c||d.startsWith(`-`);if((d.startsWith(`+`)||d.startsWith(`-`))&&(d=d.slice(1)),!/^\d*$/.test(d)||!/^\d*$/.test(f))return null;let m=u.length>1;if(!d&&!f)return m&&t?`${p?`-`:``}0${o}${`0`.repeat(r)}`:!t&&(p||m)?p?`-`:`0${o}`:null;d=(d||`0`).replace(/^0+(?=\d)/,``);let h=f.slice(0,r),g=t?h.padEnd(r,`0`):h;if(t&&f.length>r){let e=10n**BigInt(r),t=BigInt(`${d}${g}`||`0`),n=f[r]>=`5`?t+1n:t;d=(n/e).toString(),g=r?(n%e).toString().padStart(r,`0`):``}let _=s?d.replace(/\B(?=(\d{3})+(?!\d))/g,s):d;return`${p?`-`:``}${_}${r>0&&(t||m)?`${o}${t?g:h}`:``}`}_formatMoneyInput(e){if(!this._isMoney()||!this._input)return;let t=this._input,n=t.value,r=t.selectionStart??n.length,i=n.slice(0,r),a=this.getAttribute(`decimal-point`)??`.`,o=i.indexOf(a||`.`),s=(o<0?i:i.slice(0,o)).replace(/\D/g,``).length,c=o<0?0:i.slice(o+(a||`.`).length).replace(/\D/g,``).length,l=o>=0,u=this._formatMoneyValue(n,e)??`0`;if(u!==n&&(t.value=u,document.activeElement===t)){let e=0;if(l){let t=u.indexOf(a||`.`);if(t>=0){e=t+(a||`.`).length;let n=0;for(;e<u.length&&n<c;)/\d/.test(u[e])&&n++,e++}else e=u.length}else{let t=0;for(u.startsWith(`-`)&&i.startsWith(`-`)&&(e=1);e<u.length&&t<s;)/\d/.test(u[e])&&t++,e++}t.setSelectionRange(e,e)}}_isColor(){return this.getType()===`color`}_isNumber(){return this.getType()===`number`}getPlaceholder(){return this.getAttribute(`placeholder`)||``}getValue(){return this._isColor()?this._colorTextInput?this._colorTextInput.value:this._colorPicker?this._colorPicker.value:this.getAttribute(`value`)||`#000000`:this._element?this._element.value:this.getAttribute(`value`)||``}set value(e){try{this._isColor()?(this._colorPicker&&(this._colorPicker.value=e||`#000000`),this._colorTextInput&&(this._colorTextInput.value=e||`#000000`)):this._element&&(this._element.value=e),e?this.setAttribute(`value`,e):this.removeAttribute(`value`)}catch{}}get value(){try{return this.getValue()||``}catch{return``}}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getName(){return this.getAttribute(`name`)||``}getIcon(){return this.getAttribute(`icon`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getInputClasses(){let e=this._isTextarea(),t=!!this.getIcon(),n=this.querySelector(`[slot="prepend"]`)!==null,r=this.querySelector(`[slot="append"]`)!==null,i=this._isColor(),a=this._isNumber(),o=this.hasError();return[`mint-input-control`,e&&`is-textarea`,t&&`has-icon`,i&&`is-color`,n&&`has-prepend`,r&&`has-append`,a&&`is-number`,o&&`has-error`].filter(Boolean).join(` `)}_syncSlotAdornments(e,t){if(!this._wrapper)return;if(e||this._isColor()){this._prependSlotContainer?.classList.add(`is-hidden`),this._appendSlotContainer?.classList.add(`is-hidden`);return}this._prependSlotContainer||(this._prependSlotContainer=document.createElement(`div`),this._prependSlotContainer.className=`mint-input-adornment mint-input-prepend-slot`,this._wrapper.appendChild(this._prependSlotContainer)),this._appendSlotContainer||(this._appendSlotContainer=document.createElement(`div`),this._appendSlotContainer.className=`mint-input-adornment mint-input-append-slot`,this._wrapper.appendChild(this._appendSlotContainer)),[...Array.from(this._prependSlotContainer.querySelectorAll(`[slot]`)),...Array.from(this._appendSlotContainer.querySelectorAll(`[slot]`)),...Array.from(this.querySelectorAll(`:scope > [slot="prepend"], :scope > [slot="append"]`))].forEach(e=>{e.getAttribute(`slot`)===`prepend`?this._prependSlotContainer.appendChild(e):e.getAttribute(`slot`)===`append`&&this._appendSlotContainer.appendChild(e)});let n=Array.from(this._prependSlotContainer.querySelectorAll(`[slot="prepend"]`)),r=Array.from(this._appendSlotContainer.querySelectorAll(`[slot="append"]`));this._prependSlotContainer.classList.toggle(`is-hidden`,n.length===0),this._appendSlotContainer.classList.toggle(`is-hidden`,r.length===0),t&&n.length?this._wrapper.style.setProperty(`--mint-input-icon-left`,`${this._prependSlotContainer.getBoundingClientRect().width+8}px`):this._wrapper.style.removeProperty(`--mint-input-icon-left`),this._element&&(n.length&&this._wrapper.insertBefore(this._prependSlotContainer,this._element),r.length&&this._element.insertAdjacentElement(`afterend`,this._appendSlotContainer))}isLoading(){return this.getAttribute(`loading`)===`true`}render(){this.getType();let e=this._getNormalizedType(),t=this._isTextarea(),n=this._isMoney(),r=this._isColor(),i=this.getPlaceholder(),a=this.isDisabled(),o=this.isReadonly(),s=this.isRequired(),c=this.getId(),l=this.getName(),u=this.getAttribute(`value`)||(r?`#000000`:``),d=this.getRows(),f=this.getIcon(),p=this.getLabel(),m=this.getInfo(),h=this.isLoading();if(r&&this._renderSkeleton(h),r){this._input&&=(this._input.remove(),null),this._textarea&&=(this._textarea.remove(),null),this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&=(this._colorContainer.remove(),null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null),this._colorPickerWrapper||(this._colorPickerWrapper=document.createElement(`div`),this._colorPickerWrapper.className=`mint-color-picker-wrapper`,this._wrapper.appendChild(this._colorPickerWrapper),this._colorPicker=document.createElement(`input`),this._colorPicker.type=`color`,this._colorPicker.className=`mint-color-picker`,this._colorPickerWrapper.appendChild(this._colorPicker),this._focusHandler=e=>{this._colorPickerWrapper&&this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&requestAnimationFrame(()=>{this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&this._colorPickerWrapper?.classList.add(`is-focused`)})},this._blurHandler=()=>{this._colorPickerWrapper&&this._colorPickerWrapper.classList.remove(`is-focused`)},this._colorPicker.addEventListener(`focus`,this._focusHandler),this._colorPicker.addEventListener(`blur`,this._blurHandler),this._colorPicker.addEventListener(`input`,()=>{let e=this._colorPicker?.value||`#000000`;this._colorTextInput&&(this._colorTextInput.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0}))}),this._colorPicker.addEventListener(`change`,()=>{let e=this._colorPicker?.value||`#000000`;this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))})),this._colorTextInput||(this._colorTextInput=document.createElement(`input`),this._colorTextInput.type=`text`,this._colorTextInput.className=this.getInputClasses(),this._colorTextInput.placeholder=i||`#000000`,this._colorTextInput.pattern=`^#[0-9A-Fa-f]{6}$`,this._wrapper.appendChild(this._colorTextInput),this._colorTextInput.addEventListener(`input`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)&&(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0})))}),this._colorTextInput.addEventListener(`blur`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)?(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e)):this._colorPicker&&this._colorTextInput&&(this._colorTextInput.value=this._colorPicker.value),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this._colorPicker?.value||`#000000`},bubbles:!0,cancelable:!0}))}));let e=u||`#000000`;if(this._colorPicker&&this._colorPicker.value!==e&&(this._colorPicker.value=e),this._colorTextInput&&this._colorTextInput.value!==e&&(this._colorTextInput.value=e),this._colorPicker&&(this._colorPicker.disabled=a),this._colorPickerWrapper&&(a?this._colorPickerWrapper.classList.add(`is-disabled`):this._colorPickerWrapper.classList.remove(`is-disabled`)),this._colorTextInput&&(this._colorTextInput.disabled=a,this._colorTextInput.readOnly=o,this._colorTextInput.required=s),this._colorTextInput){let e=this._colorTextInput;c?e.id=c:e.removeAttribute(`id`),l?e.name=l:e.removeAttribute(`name`),e.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._element=e}this._renderErrorState();let t=this.querySelector(`.mint-input-label-container`);if(p||m){t||(t=document.createElement(`div`),t.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(t,this._wrapper):this.insertBefore(t,this.firstChild));let e=t.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,t.insertBefore(e,t.firstChild)),e.textContent=p;let n=c||this._colorTextInput?.id;if(n)e.setAttribute(`for`,n);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._colorTextInput&&(this._colorTextInput.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let n=t.querySelector(`.mint-input-info`);m?(n||(n=document.createElement(`span`),n.className=`mint-input-info`,t.appendChild(n)),n.textContent=m,a?n.classList.add(`is-disabled`):n.classList.remove(`is-disabled`)):n&&n.remove()}else t&&t.remove();return}if(this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null,this._colorPicker=null,this._colorTextInput=null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null,this._colorPicker=null,this._colorTextInput=null),f&&!t?this._icon?this._icon.setAttribute(`name`,f):(this._icon=document.createElement(`mint-icon`),this._icon.setAttribute(`name`,f),this._icon.className=`mint-input-icon`,this._wrapper.appendChild(this._icon)):this._icon&&=(this._icon.remove(),null),this._syncSlotAdornments(t,!!f),this._isNumber()&&!t){if(!this._numberSpinnerContainer){this._numberSpinnerContainer=document.createElement(`div`),this._numberSpinnerContainer.className=`mint-input-spinner`,this._wrapper.appendChild(this._numberSpinnerContainer),this._numberIncrementButton=document.createElement(`button`),this._numberIncrementButton.type=`button`,this._numberIncrementButton.className=`mint-input-spinner-button`;let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`caret-up`),e.className=`mint-input-spinner-icon`,this._numberIncrementButton.appendChild(e),this._numberSpinnerContainer.appendChild(this._numberIncrementButton),this._numberDecrementButton=document.createElement(`button`),this._numberDecrementButton.type=`button`,this._numberDecrementButton.className=`mint-input-spinner-button`;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`caret-down`),t.className=`mint-input-spinner-icon`,this._numberDecrementButton.appendChild(t),this._numberSpinnerContainer.appendChild(this._numberDecrementButton),this._numberIncrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e+t;r!==void 0&&i>r&&(i=r),n!==void 0&&i<n&&(i=n),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}}),this._numberDecrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e-t;n!==void 0&&i<n&&(i=n),r!==void 0&&i>r&&(i=r),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}})}this._numberIncrementButton&&(this._numberIncrementButton.disabled=a||o),this._numberDecrementButton&&(this._numberDecrementButton.disabled=a||o)}else this._numberSpinnerContainer&&(this._numberSpinnerContainer.remove(),this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null);if(t){if(this._input&&=(this._input.remove(),null),this._textarea||(this._textarea=document.createElement(`textarea`),this._element=this._textarea,this._wrapper.appendChild(this._textarea),this.setupEventListeners()),this._element=this._textarea,this._textarea.placeholder=i,this._textarea.disabled=a,this._textarea.readOnly=o,this._textarea.required=s,this._textarea.rows=d,this._textarea.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),u!==this._textarea.value&&(this._textarea.value=u),c?this._textarea.id=c:this._textarea.removeAttribute(`id`),l?this._textarea.name=l:this._textarea.removeAttribute(`name`),this._textarea.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._textarea.value&&(this._textarea.value=e.trim()),this.removeChild(this.firstChild)}}else{this._textarea&&=(this._textarea.remove(),null),this._input||(this._input=document.createElement(`input`),this._element=this._input,this._wrapper.appendChild(this._input),this.setupEventListeners()),this._element=this._input,this._input.type=e,this._input.placeholder=i,this._input.disabled=a,this._input.readOnly=o,this._input.required=s,this._input.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._input.min=this.getAttribute(`min`)??``,this._input.max=this.getAttribute(`max`)??``,this._input.step=this.getAttribute(`step`)??``,n?(this._input.inputMode=`decimal`,this._input.removeAttribute(`pattern`)):(this._input.removeAttribute(`inputmode`),this._input.removeAttribute(`pattern`));let t=n&&document.activeElement===this._input;if(u!==this._input.value&&!t&&(this._input.value=u),c?this._input.id=c:this._input.removeAttribute(`id`),l?this._input.name=l:this._input.removeAttribute(`name`),this._input.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._input.value&&(this._input.value=e.trim()),this.removeChild(this.firstChild)}t||this._formatMoneyInput(!0)}let g=this.querySelector(`.mint-input-label-container`);if(p||m){g||(g=document.createElement(`div`),g.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(g,this._wrapper):this.insertBefore(g,this.firstChild));let e=g.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,g.insertBefore(e,g.firstChild)),e.textContent=p;let t=c||this._element?.id||this._colorTextInput?.id||this._input?.id||this._textarea?.id;if(t)e.setAttribute(`for`,t);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._element?this._element.id=t:this._colorTextInput?this._colorTextInput.id=t:this._input?this._input.id=t:this._textarea&&(this._textarea.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let t=g.querySelector(`.mint-input-info`);m?(t||(t=document.createElement(`span`),t.className=`mint-input-info`,g.appendChild(t)),t.textContent=m,a?t.classList.add(`is-disabled`):t.classList.remove(`is-disabled`)):t&&t.remove()}else g&&g.remove();this._syncSlotAdornments(t,!!f),this._renderErrorState(),this._syncControlAccessibility(),this._renderSkeleton(h)}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-input-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-input-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncControlAccessibility(){let e=this._element;if(!e)return;this._a11yId||=this.getId()||`mint-input-${Math.random().toString(36).slice(2,10)}`;let t=this.getAttribute(`aria-label`)?.trim(),n=!!this.querySelector(`.mint-input-label`);t?e.setAttribute(`aria-label`,t):!n&&this.getAttribute(`placeholder`)?.trim()?e.setAttribute(`aria-label`,this.getAttribute(`placeholder`).trim()):e.removeAttribute(`aria-label`);let r=this.querySelector(`.mint-input-info`),i=this.querySelector(`.mint-input-error`),a=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean);r&&(r.id=`${this._a11yId}-info`,a.push(r.id)),i&&(i.id=`${this._a11yId}-error`,a.push(i.id)),e.setAttribute(`aria-invalid`,String(this.hasError())),a.length?e.setAttribute(`aria-describedby`,Array.from(new Set(a)).join(` `)):e.removeAttribute(`aria-describedby`);let o=this.getAttribute(`aria-labelledby`)?.trim();o?e.setAttribute(`aria-labelledby`,o):e.removeAttribute(`aria-labelledby`)}setupEventListeners(){this._element&&(this._element.addEventListener(`beforeinput`,e=>{if(!this._isMoney()||!(e instanceof InputEvent)||!e.inputType.startsWith(`insert`))return;let t=this.getAttribute(`decimal-point`)??`.`,n=e.data??e.dataTransfer?.getData(`text/plain`)??``;if(!n)return;let r=this._input?.value.indexOf(t)??-1;if(t&&n===t&&r>=0){e.preventDefault();let n=r+t.length;this._input?.setSelectionRange(n,n);return}let i=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=t?RegExp(`[^0-9${i}]`,`g`):/[^0-9]/g;n.replace(a,``)!==n&&e.preventDefault()}),this._element.addEventListener(`input`,()=>{let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`);let t=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(t),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0,composed:!0}))}),this._element.addEventListener(`blur`,()=>{this._formatMoneyInput(!0);let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))}))}removeEventListeners(){this._colorPicker&&(this._focusHandler&&=(this._colorPicker.removeEventListener(`focus`,this._focusHandler),null),this._blurHandler&&=(this._colorPicker.removeEventListener(`blur`,this._blurHandler),null))}focus(){this._isColor()&&this._colorTextInput?this._colorTextInput.focus():this._element?.focus()}blur(){this._isColor()&&this._colorTextInput?this._colorTextInput.blur():this._element?.blur()}_renderSkeleton(e){this.classList.toggle(`is-loading`,e);let t=this.querySelector(`.mint-input-skeleton-container`),n=this._wrapper||this.querySelector(`.mint-input-wrapper`);if(e){t||(t=document.createElement(`div`),t.className=`mint-input-skeleton-container`,n?(n.classList.add(`mint-input-positioned`),n.appendChild(t)):(this.classList.add(`mint-input-positioned`),this.appendChild(t)));let e=t.querySelector(`.mint-input-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-input-skeleton`,t.appendChild(e)),e.parentElement||t.appendChild(e)}}};customElements.get(`mint-input`)||t.t(`mint-input`,n),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
|
|
1
|
+
const e=require(`./icon-B9P0jyS2.js`),t=require(`./register-element-tCL_F1YI.js`);require(`./icon-Cia9x_J2.js`),require(`./caret-down-DbFlPN-2.js`),e.a({name:`caret-up`,viewBox:`0 0 24 24`,path:`M5 15l7-7 7 7`,strokeLinecap:`round`,strokeLinejoin:`round`});var n=class extends HTMLElement{static get observedAttributes(){return[`type`,`placeholder`,`value`,`disabled`,`id`,`name`,`required`,`readonly`,`rows`,`min`,`max`,`step`,`decimal-places`,`thousands-separator`,`decimal-point`,`icon`,`label`,`info`,`error`,`error-message`,`loading`,`aria-label`,`aria-labelledby`,`aria-describedby`]}constructor(){super(),this._input=null,this._textarea=null,this._element=null,this._wrapper=null,this._icon=null,this._prependSlotContainer=null,this._appendSlotContainer=null,this._colorPicker=null,this._colorTextInput=null,this._colorContainer=null,this._colorPickerWrapper=null,this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null,this._contentObserver=null,this._focusHandler=null,this._a11yId=``,this._blurHandler=null,this._clickHandler=null,this._clickOutsideHandler=null,this._renderFrame=null}connectedCallback(){this.classList.add(`mint-input-host`),this.render(),this._observeContentMutations()}disconnectedCallback(){this.removeEventListeners(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._syncControlAccessibility(),this._element&&(this._element.className=this.getInputClasses()),this._colorTextInput&&(this._colorTextInput.className=this.getInputClasses());return}if(e===`loading`){this.render();return}this.render()}}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(e=>{e.some(e=>e.type===`childList`?e.target===this:e.type===`attributes`&&e.target.hasAttribute(`slot`))&&this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}getType(){return this.getAttribute(`type`)||`text`}getRows(){let e=this.getAttribute(`rows`);return e?parseInt(e,10):3}_getNormalizedType(){let e=this.getType();return e===`datetime`?`datetime-local`:e===`money`?`text`:e===`textarea`?`textarea`:e}_isTextarea(){return this.getType()===`textarea`}_isMoney(){return this.getType()===`money`}_getMoneyDecimalPlaces(){let e=this.getAttribute(`decimal-places`);return e===null||!/^\d+$/.test(e)?2:Math.min(20,Number(e))}_formatMoneyValue(e,t){let n=e.trim();if(!n)return``;let r=this._getMoneyDecimalPlaces(),i=this.getAttribute(`decimal-point`)??`.`,a=this.getAttribute(`thousands-separator`)??`,`,o=i||`.`,s=a===o?``:a,c=/^\(.*\)$/.test(n),l=c?n.slice(1,-1).trim():n;s&&(l=l.split(s).join(``)),l=l.replace(/[\s$€£¥₹₩₽¢]/g,``);let u=l.split(o);u.length>2&&u.splice(1,u.length-1,u.slice(1).join(``));let d=u[0]??``,f=u.length>1?u[1]:``,p=c||d.startsWith(`-`);if((d.startsWith(`+`)||d.startsWith(`-`))&&(d=d.slice(1)),!/^\d*$/.test(d)||!/^\d*$/.test(f))return null;let m=u.length>1;if(!d&&!f)return m&&t?`${p?`-`:``}0${o}${`0`.repeat(r)}`:!t&&(p||m)?p?`-`:`0${o}`:null;d=(d||`0`).replace(/^0+(?=\d)/,``);let h=f.slice(0,r),g=t?h.padEnd(r,`0`):h;if(t&&f.length>r){let e=10n**BigInt(r),t=BigInt(`${d}${g}`||`0`),n=f[r]>=`5`?t+1n:t;d=(n/e).toString(),g=r?(n%e).toString().padStart(r,`0`):``}let _=s?d.replace(/\B(?=(\d{3})+(?!\d))/g,s):d;return`${p?`-`:``}${_}${r>0&&(t||m)?`${o}${t?g:h}`:``}`}_formatMoneyInput(e){if(!this._isMoney()||!this._input)return;let t=this._input,n=t.value,r=t.selectionStart??n.length,i=n.slice(0,r),a=this.getAttribute(`decimal-point`)??`.`,o=i.indexOf(a||`.`),s=(o<0?i:i.slice(0,o)).replace(/\D/g,``).length,c=o<0?0:i.slice(o+(a||`.`).length).replace(/\D/g,``).length,l=o>=0,u=this._formatMoneyValue(n,e)??`0`;if(u!==n&&(t.value=u,document.activeElement===t)){let e=0;if(l){let t=u.indexOf(a||`.`);if(t>=0){e=t+(a||`.`).length;let n=0;for(;e<u.length&&n<c;)/\d/.test(u[e])&&n++,e++}else e=u.length}else{let t=0;for(u.startsWith(`-`)&&i.startsWith(`-`)&&(e=1);e<u.length&&t<s;)/\d/.test(u[e])&&t++,e++}t.setSelectionRange(e,e)}}_isColor(){return this.getType()===`color`}_isNumber(){return this.getType()===`number`}getPlaceholder(){return this.getAttribute(`placeholder`)||``}getValue(){return this._isColor()?this._colorTextInput?this._colorTextInput.value:this._colorPicker?this._colorPicker.value:this.getAttribute(`value`)||`#000000`:this._element?this._element.value:this.getAttribute(`value`)||``}set value(e){try{this._isColor()?(this._colorPicker&&(this._colorPicker.value=e||`#000000`),this._colorTextInput&&(this._colorTextInput.value=e||`#000000`)):this._element&&(this._element.value=e),e?this.setAttribute(`value`,e):this.removeAttribute(`value`)}catch{}}get value(){try{return this.getValue()||``}catch{return``}}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getName(){return this.getAttribute(`name`)||``}getIcon(){return this.getAttribute(`icon`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getInputClasses(){let e=this._isTextarea(),t=!!this.getIcon(),n=this.querySelector(`[slot="prepend"]`)!==null,r=this.querySelector(`[slot="append"]`)!==null,i=this._isColor(),a=this._isNumber(),o=this.hasError();return[`mint-input-control`,e&&`is-textarea`,t&&`has-icon`,i&&`is-color`,n&&`has-prepend`,r&&`has-append`,a&&`is-number`,o&&`has-error`].filter(Boolean).join(` `)}_syncSlotAdornments(e,t){if(!this._wrapper)return;if(e||this._isColor()){this._prependSlotContainer?.classList.add(`is-hidden`),this._appendSlotContainer?.classList.add(`is-hidden`);return}this._prependSlotContainer||(this._prependSlotContainer=document.createElement(`div`),this._prependSlotContainer.className=`mint-input-adornment mint-input-prepend-slot`,this._wrapper.appendChild(this._prependSlotContainer)),this._appendSlotContainer||(this._appendSlotContainer=document.createElement(`div`),this._appendSlotContainer.className=`mint-input-adornment mint-input-append-slot`,this._wrapper.appendChild(this._appendSlotContainer)),[...Array.from(this._prependSlotContainer.querySelectorAll(`[slot]`)),...Array.from(this._appendSlotContainer.querySelectorAll(`[slot]`)),...Array.from(this.querySelectorAll(`:scope > [slot="prepend"], :scope > [slot="append"]`))].forEach(e=>{e.getAttribute(`slot`)===`prepend`?this._prependSlotContainer.appendChild(e):e.getAttribute(`slot`)===`append`&&this._appendSlotContainer.appendChild(e)});let n=Array.from(this._prependSlotContainer.querySelectorAll(`[slot="prepend"]`)),r=Array.from(this._appendSlotContainer.querySelectorAll(`[slot="append"]`));this._prependSlotContainer.classList.toggle(`is-hidden`,n.length===0),this._appendSlotContainer.classList.toggle(`is-hidden`,r.length===0),t&&n.length?this._wrapper.style.setProperty(`--mint-input-icon-left`,`${this._prependSlotContainer.getBoundingClientRect().width+8}px`):this._wrapper.style.removeProperty(`--mint-input-icon-left`),this._element&&(n.length&&this._wrapper.insertBefore(this._prependSlotContainer,this._element),r.length&&this._element.insertAdjacentElement(`afterend`,this._appendSlotContainer))}isLoading(){return this.getAttribute(`loading`)===`true`}render(){this.getType();let e=this._getNormalizedType(),t=this._isTextarea(),n=this._isMoney(),r=this._isColor(),i=this.getPlaceholder(),a=this.isDisabled(),o=this.isReadonly(),s=this.isRequired(),c=this.getId(),l=this.getName(),u=this.getAttribute(`value`)||(r?`#000000`:``),d=this.getRows(),f=this.getIcon(),p=this.getLabel(),m=this.getInfo(),h=this.isLoading();if(r&&this._renderSkeleton(h),r){this._input&&=(this._input.remove(),null),this._textarea&&=(this._textarea.remove(),null),this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&=(this._colorContainer.remove(),null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null),this._colorPickerWrapper||(this._colorPickerWrapper=document.createElement(`div`),this._colorPickerWrapper.className=`mint-color-picker-wrapper`,this._wrapper.appendChild(this._colorPickerWrapper),this._colorPicker=document.createElement(`input`),this._colorPicker.type=`color`,this._colorPicker.className=`mint-color-picker`,this._colorPickerWrapper.appendChild(this._colorPicker),this._focusHandler=e=>{this._colorPickerWrapper&&this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&requestAnimationFrame(()=>{this._colorPicker&&this._colorPicker.matches(`:focus-visible`)&&this._colorPickerWrapper?.classList.add(`is-focused`)})},this._blurHandler=()=>{this._colorPickerWrapper&&this._colorPickerWrapper.classList.remove(`is-focused`)},this._colorPicker.addEventListener(`focus`,this._focusHandler),this._colorPicker.addEventListener(`blur`,this._blurHandler),this._colorPicker.addEventListener(`input`,()=>{let e=this._colorPicker?.value||`#000000`;this._colorTextInput&&(this._colorTextInput.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0}))}),this._colorPicker.addEventListener(`change`,()=>{let e=this._colorPicker?.value||`#000000`;this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))})),this._colorTextInput||(this._colorTextInput=document.createElement(`input`),this._colorTextInput.type=`text`,this._colorTextInput.className=this.getInputClasses(),this._colorTextInput.placeholder=i||`#000000`,this._colorTextInput.pattern=`^#[0-9A-Fa-f]{6}$`,this._wrapper.appendChild(this._colorTextInput),this._colorTextInput.addEventListener(`input`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)&&(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0})))}),this._colorTextInput.addEventListener(`blur`,()=>{let e=this._colorTextInput?.value||``;/^#[0-9A-Fa-f]{6}$/.test(e)?(this._colorPicker&&(this._colorPicker.value=e),this.setAttribute(`value`,e)):this._colorPicker&&this._colorTextInput&&(this._colorTextInput.value=this._colorPicker.value),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this._colorPicker?.value||`#000000`},bubbles:!0,cancelable:!0}))}));let e=u||`#000000`;if(this._colorPicker&&this._colorPicker.value!==e&&(this._colorPicker.value=e),this._colorTextInput&&this._colorTextInput.value!==e&&(this._colorTextInput.value=e),this._colorPicker&&(this._colorPicker.disabled=a),this._colorPickerWrapper&&(a?this._colorPickerWrapper.classList.add(`is-disabled`):this._colorPickerWrapper.classList.remove(`is-disabled`)),this._colorTextInput&&(this._colorTextInput.disabled=a,this._colorTextInput.readOnly=o,this._colorTextInput.required=s),this._colorTextInput){let e=this._colorTextInput;c?e.id=c:e.removeAttribute(`id`),l?e.name=l:e.removeAttribute(`name`),e.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._element=e}this._renderErrorState();let t=this.querySelector(`.mint-input-label-container`);if(p||m){t||(t=document.createElement(`div`),t.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(t,this._wrapper):this.insertBefore(t,this.firstChild));let e=t.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,t.insertBefore(e,t.firstChild)),e.textContent=p;let n=c||this._colorTextInput?.id;if(n)e.setAttribute(`for`,n);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._colorTextInput&&(this._colorTextInput.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let n=t.querySelector(`.mint-input-info`);m?(n||(n=document.createElement(`span`),n.className=`mint-input-info`,t.appendChild(n)),n.textContent=m,a?n.classList.add(`is-disabled`):n.classList.remove(`is-disabled`)):n&&n.remove()}else t&&t.remove();return}if(this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`mint-input-wrapper`,this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null,this._colorPicker=null,this._colorTextInput=null),this._colorPickerWrapper&&!r&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null,this._colorPicker=null,this._colorTextInput=null),f&&!t?this._icon?this._icon.setAttribute(`name`,f):(this._icon=document.createElement(`mint-icon`),this._icon.setAttribute(`name`,f),this._icon.className=`mint-input-icon`,this._wrapper.appendChild(this._icon)):this._icon&&=(this._icon.remove(),null),this._syncSlotAdornments(t,!!f),this._isNumber()&&!t){if(!this._numberSpinnerContainer){this._numberSpinnerContainer=document.createElement(`div`),this._numberSpinnerContainer.className=`mint-input-spinner`,this._wrapper.appendChild(this._numberSpinnerContainer),this._numberIncrementButton=document.createElement(`button`),this._numberIncrementButton.type=`button`,this._numberIncrementButton.className=`mint-input-spinner-button`;let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`caret-up`),e.className=`mint-input-spinner-icon`,this._numberIncrementButton.appendChild(e),this._numberSpinnerContainer.appendChild(this._numberIncrementButton),this._numberDecrementButton=document.createElement(`button`),this._numberDecrementButton.type=`button`,this._numberDecrementButton.className=`mint-input-spinner-button`;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`caret-down`),t.className=`mint-input-spinner-icon`,this._numberDecrementButton.appendChild(t),this._numberSpinnerContainer.appendChild(this._numberDecrementButton),this._numberIncrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e+t;r!==void 0&&i>r&&(i=r),n!==void 0&&i<n&&(i=n),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}}),this._numberDecrementButton.addEventListener(`click`,e=>{if(e.preventDefault(),e.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){let e=parseFloat(this._input.value)||0,t=parseFloat(this._input.step)||1,n=this._input.min?parseFloat(this._input.min):void 0,r=this._input.max?parseFloat(this._input.max):void 0,i=e-t;n!==void 0&&i<n&&(i=n),r!==void 0&&i>r&&(i=r),this._input.value=i.toString(),this.setAttribute(`value`,i.toString()),this._input.dispatchEvent(new Event(`input`,{bubbles:!0})),this._input.dispatchEvent(new Event(`change`,{bubbles:!0}))}})}this._numberIncrementButton&&(this._numberIncrementButton.disabled=a||o),this._numberDecrementButton&&(this._numberDecrementButton.disabled=a||o)}else this._numberSpinnerContainer&&(this._numberSpinnerContainer.remove(),this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null);if(t){if(this._input&&=(this._input.remove(),null),this._textarea||(this._textarea=document.createElement(`textarea`),this._element=this._textarea,this._wrapper.appendChild(this._textarea),this.setupEventListeners()),this._element=this._textarea,this._textarea.placeholder=i,this._textarea.disabled=a,this._textarea.readOnly=o,this._textarea.required=s,this._textarea.rows=d,this._textarea.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),u!==this._textarea.value&&(this._textarea.value=u),c?this._textarea.id=c:this._textarea.removeAttribute(`id`),l?this._textarea.name=l:this._textarea.removeAttribute(`name`),this._textarea.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._textarea.value&&(this._textarea.value=e.trim()),this.removeChild(this.firstChild)}}else{this._textarea&&=(this._textarea.remove(),null),this._input||(this._input=document.createElement(`input`),this._element=this._input,this._wrapper.appendChild(this._input),this.setupEventListeners()),this._element=this._input,this._input.type=e,this._input.placeholder=i,this._input.disabled=a,this._input.readOnly=o,this._input.required=s,this._input.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`),this._input.min=this.getAttribute(`min`)??``,this._input.max=this.getAttribute(`max`)??``,this._input.step=this.getAttribute(`step`)??``,n?(this._input.inputMode=`decimal`,this._input.removeAttribute(`pattern`)):(this._input.removeAttribute(`inputmode`),this._input.removeAttribute(`pattern`));let t=n&&document.activeElement===this._input;if(u!==this._input.value&&!t&&(this._input.value=u),c?this._input.id=c:this._input.removeAttribute(`id`),l?this._input.name=l:this._input.removeAttribute(`name`),this._input.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){let e=this.firstChild.textContent;e&&!this._input.value&&(this._input.value=e.trim()),this.removeChild(this.firstChild)}t||this._formatMoneyInput(!0)}let g=this.querySelector(`.mint-input-label-container`);if(p||m){g||(g=document.createElement(`div`),g.className=`mint-input-label-container`,this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(g,this._wrapper):this.insertBefore(g,this.firstChild));let e=g.querySelector(`.mint-input-label`);if(p){e||(e=document.createElement(`label`),e.className=`mint-input-label`,g.insertBefore(e,g.firstChild)),e.textContent=p;let t=c||this._element?.id||this._colorTextInput?.id||this._input?.id||this._textarea?.id;if(t)e.setAttribute(`for`,t);else{let t=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._element?this._element.id=t:this._colorTextInput?this._colorTextInput.id=t:this._input?this._input.id=t:this._textarea&&(this._textarea.id=t),e.setAttribute(`for`,t)}a?e.classList.add(`is-disabled`):e.classList.remove(`is-disabled`)}else e&&e.remove();let t=g.querySelector(`.mint-input-info`);m?(t||(t=document.createElement(`span`),t.className=`mint-input-info`,g.appendChild(t)),t.textContent=m,a?t.classList.add(`is-disabled`):t.classList.remove(`is-disabled`)):t&&t.remove()}else g&&g.remove();this._syncSlotAdornments(t,!!f),this._renderErrorState(),this._syncControlAccessibility(),this._renderSkeleton(h)}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-input-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-input-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncControlAccessibility(){let e=this._element;if(!e)return;this._a11yId||=this.getId()||`mint-input-${Math.random().toString(36).slice(2,10)}`;let t=this.getAttribute(`aria-label`)?.trim(),n=!!this.querySelector(`.mint-input-label`);t?e.setAttribute(`aria-label`,t):!n&&this.getAttribute(`placeholder`)?.trim()?e.setAttribute(`aria-label`,this.getAttribute(`placeholder`).trim()):e.removeAttribute(`aria-label`);let r=this.querySelector(`.mint-input-info`),i=this.querySelector(`.mint-input-error`),a=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean);r&&(r.id=`${this._a11yId}-info`,a.push(r.id)),i&&(i.id=`${this._a11yId}-error`,a.push(i.id)),e.setAttribute(`aria-invalid`,String(this.hasError())),a.length?e.setAttribute(`aria-describedby`,Array.from(new Set(a)).join(` `)):e.removeAttribute(`aria-describedby`);let o=this.getAttribute(`aria-labelledby`)?.trim();o?e.setAttribute(`aria-labelledby`,o):e.removeAttribute(`aria-labelledby`)}setupEventListeners(){this._element&&(this._element.addEventListener(`beforeinput`,e=>{if(!this._isMoney()||!(e instanceof InputEvent)||!e.inputType.startsWith(`insert`))return;let t=this.getAttribute(`decimal-point`)??`.`,n=e.data??e.dataTransfer?.getData(`text/plain`)??``;if(!n)return;let r=this._input?.value.indexOf(t)??-1;if(t&&n===t&&r>=0){e.preventDefault();let n=r+t.length;this._input?.setSelectionRange(n,n);return}let i=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=t?RegExp(`[^0-9${i}]`,`g`):/[^0-9]/g;n.replace(a,``)!==n&&e.preventDefault()}),this._element.addEventListener(`input`,()=>{let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`);let t=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(t),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:e},bubbles:!0,cancelable:!0,composed:!0}))}),this._element.addEventListener(`blur`,()=>{this._formatMoneyInput(!0);let e=this._element?.value||``;e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:e},bubbles:!0,cancelable:!0}))}))}removeEventListeners(){this._colorPicker&&(this._focusHandler&&=(this._colorPicker.removeEventListener(`focus`,this._focusHandler),null),this._blurHandler&&=(this._colorPicker.removeEventListener(`blur`,this._blurHandler),null))}focus(){this._isColor()&&this._colorTextInput?this._colorTextInput.focus():this._element?.focus()}blur(){this._isColor()&&this._colorTextInput?this._colorTextInput.blur():this._element?.blur()}_renderSkeleton(e){this.classList.toggle(`is-loading`,e);let t=this.querySelector(`.mint-input-skeleton-container`),n=this._wrapper||this.querySelector(`.mint-input-wrapper`);if(e){t||(t=document.createElement(`div`),t.className=`mint-input-skeleton-container`,n?(n.classList.add(`mint-input-positioned`),n.appendChild(t)):(this.classList.add(`mint-input-positioned`),this.appendChild(t)));let e=t.querySelector(`.mint-input-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-input-skeleton`,t.appendChild(e)),e.parentElement||t.appendChild(e)}}};customElements.get(`mint-input`)||t.t(`mint-input`,n),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as e } from "./icon-
|
|
1
|
+
import { a as e } from "./icon-DAB2KLeo.js";
|
|
2
2
|
import { t } from "./register-element-BFYmIynH.js";
|
|
3
|
-
import "./icon-
|
|
4
|
-
import "./caret-down-
|
|
3
|
+
import "./icon-CIAsmizQ.js";
|
|
4
|
+
import "./caret-down-pn6aBT-u.js";
|
|
5
5
|
e({
|
|
6
6
|
name: "caret-up",
|
|
7
7
|
viewBox: "0 0 24 24",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./icon-
|
|
1
|
+
import "./icon-DAB2KLeo.js";
|
|
2
2
|
import { t as e } from "./register-element-BFYmIynH.js";
|
|
3
3
|
import "./text-C-6UCBp-.js";
|
|
4
|
-
import "./button-
|
|
5
|
-
import "./stack-
|
|
4
|
+
import "./button-BTQHrE0x.js";
|
|
5
|
+
import "./stack-CKUu8IVZ.js";
|
|
6
6
|
//#region src/components/modal/Modal.js
|
|
7
7
|
var t = /* @__PURE__ */ new Set(), n = null;
|
|
8
8
|
function r(e) {
|
|
@@ -121,14 +121,10 @@ var a = class extends HTMLElement {
|
|
|
121
121
|
}
|
|
122
122
|
_animateEnter() {
|
|
123
123
|
let e = this._modal?.querySelector(".modal-content");
|
|
124
|
-
e && (this._exitTimer &&= (clearTimeout(this._exitTimer), null), this._backdropTimer &&= (clearTimeout(this._backdropTimer), null), this.classList.remove("mint-modal-closing"), this.classList.remove("mint-modal-open"), this.classList.add("mint-modal-open"), this.classList.remove("mint-hidden"), e.style.transform = "none", e.style.opacity = "0", e.style.transition = "none", requestAnimationFrame(() => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.isOpen() && (e.style.transform = "scale(1)", e.style.opacity = "1", e.style.borderRadius = t, window.setTimeout(() => {
|
|
129
|
-
this.isOpen() && (e.style.transition = "", e.style.transform = "none");
|
|
130
|
-
}, 380));
|
|
131
|
-
});
|
|
124
|
+
e && (this._exitTimer &&= (clearTimeout(this._exitTimer), null), this._backdropTimer &&= (clearTimeout(this._backdropTimer), null), this.classList.remove("mint-modal-closing"), this.classList.remove("mint-modal-open"), this.classList.add("mint-modal-open"), this.classList.remove("mint-hidden"), e.style.transform = "none", e.style.opacity = "0", e.style.transition = "none", e.getBoundingClientRect(), requestAnimationFrame(() => {
|
|
125
|
+
this.isOpen() && (e.style.transition = "opacity 200ms ease-out", e.style.opacity = "1", this._backdropTimer = window.setTimeout(() => {
|
|
126
|
+
e.style.transition = "", e.style.opacity = "", e.style.transform = "", this._backdropTimer = null;
|
|
127
|
+
}, 220));
|
|
132
128
|
}));
|
|
133
129
|
}
|
|
134
130
|
_findTriggerElement(e) {
|
|
@@ -155,22 +151,6 @@ var a = class extends HTMLElement {
|
|
|
155
151
|
y: t.y
|
|
156
152
|
} : null;
|
|
157
153
|
}
|
|
158
|
-
_setTransformOrigin(e) {
|
|
159
|
-
let t = this._findTriggerElement(this._triggerElement);
|
|
160
|
-
this._triggerElement = t;
|
|
161
|
-
let n = this._findTriggerPoint(t);
|
|
162
|
-
if (n) {
|
|
163
|
-
let t = e.getBoundingClientRect();
|
|
164
|
-
e.style.transformOrigin = `${n.x - t.left}px ${n.y - t.top}px`, this._triggerPoint = n;
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
this._triggerPoint = {
|
|
168
|
-
x: window.innerWidth / 2,
|
|
169
|
-
y: 0
|
|
170
|
-
};
|
|
171
|
-
let r = e.getBoundingClientRect();
|
|
172
|
-
e.style.transformOrigin = `${this._triggerPoint.x - r.left}px ${this._triggerPoint.y - r.top}px`;
|
|
173
|
-
}
|
|
174
154
|
_animateExit() {
|
|
175
155
|
this.classList.remove("mint-modal-open"), this._backdropTimer &&= (clearTimeout(this._backdropTimer), null);
|
|
176
156
|
let e = this._modal?.querySelector(".modal-content");
|
|
@@ -178,9 +158,9 @@ var a = class extends HTMLElement {
|
|
|
178
158
|
this.classList.add("mint-hidden"), this.classList.remove("mint-modal-closing"), i(this);
|
|
179
159
|
return;
|
|
180
160
|
}
|
|
181
|
-
this._exitTimer && clearTimeout(this._exitTimer), this.classList.add("mint-modal-closing"), e.style.transition = "opacity
|
|
182
|
-
this._exitTimer = null, !this.isOpen() && (this.classList.add("mint-hidden"), this.classList.remove("mint-modal-closing"), e.style.transform = "", e.style.opacity = "", e.style.
|
|
183
|
-
},
|
|
161
|
+
this._exitTimer && clearTimeout(this._exitTimer), this.classList.add("mint-modal-closing"), e.style.transition = "opacity 200ms ease-in", e.style.opacity = "0", this._exitTimer = setTimeout(() => {
|
|
162
|
+
this._exitTimer = null, !this.isOpen() && (this.classList.add("mint-hidden"), this.classList.remove("mint-modal-closing"), e.style.transform = "", e.style.opacity = "", e.style.transition = "", i(this));
|
|
163
|
+
}, 200);
|
|
184
164
|
}
|
|
185
165
|
};
|
|
186
166
|
typeof customElements < "u" && !customElements.get("mint-modal") && e("mint-modal", a);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./icon-
|
|
1
|
+
require(`./icon-B9P0jyS2.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-CfvRRKGZ.js`),require(`./button-B4BMYTk1.js`),require(`./stack-CK2o4-As.js`);var t=new Set,n=null;function r(e){if(!t.has(e)){if(t.size===0){let e=document.documentElement;n={scrollY:window.scrollY||window.pageYOffset||0,rootOverflow:e.style.overflow,rootOverscrollBehavior:e.style.overscrollBehavior},e.style.overflow=`hidden`,e.style.overscrollBehavior=`none`}t.add(e)}}function i(e){if(!t.delete(e)||t.size>0||!n)return;let r=n;n=null;let i=document.documentElement;i.style.overflow=r.rootOverflow,i.style.overscrollBehavior=r.rootOverscrollBehavior,window.scrollTo({left:0,top:r.scrollY,behavior:`instant`})}var a=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`,`size`]}constructor(){super(),this._overlay=null,this._modal=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._triggerElement=null,this._triggerPoint=null,this._renderedOpen=!1,this._lastPointerPoint=null,this._pointerDownHandler=null,this._darkModeObserver=null,this._exitTimer=null,this._backdropTimer=null}connectedCallback(){this.isOpen()||this.classList.add(`mint-hidden`),this.render(),this._observeDarkMode(),this._pointerDownHandler=e=>{this._lastPointerPoint={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()}},document.addEventListener(`pointerdown`,this._pointerDownHandler,!0)}disconnectedCallback(){i(this),this._pointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._pointerDownHandler,!0),null),this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null)}attributeChangedCallback(e,t,n){t!==n&&(e===`open`&&n!==null&&!this._triggerElement&&(this._triggerElement=this._findTriggerElement(),this._triggerPoint=this._findTriggerPoint(this._triggerElement)),this.render())}getId(){return this.getAttribute(`id`)||``}getHeading(){return this.getAttribute(`heading`)||``}getSize(){let e=this.getAttribute(`size`);return e===`small`||e===`large`?e:`default`}isOpen(){return this.hasAttribute(`open`)}open(e){this._triggerElement=this._findTriggerElement(e),this._triggerPoint=this._findTriggerPoint(this._triggerElement),this.setAttribute(`open`,``)}close(){this.removeAttribute(`open`)}render(){let e=this.getId(),t=this.getHeading(),n=this.isOpen(),i=this.getSize();if(e&&(this.id=e),this._overlay||(this._overlay=document.createElement(`div`),this._overlay.className=`mint-modal-overlay`,this._overlay.addEventListener(`click`,()=>this.close()),this.appendChild(this._overlay)),this._modal||(this._modal=document.createElement(`div`),this._modal.className=`mint-modal-shell`,this.appendChild(this._modal)),n){let e=this._modal.querySelector(`.modal-content`);e||(e=document.createElement(`div`),e.className=`modal-content`,this._modal.appendChild(e)),this._renderedOpen||(this._renderedOpen=!0,r(this),this._animateEnter())}else this._renderedOpen&&(this._renderedOpen=!1,this._animateExit());let a=this._modal.querySelector(`.modal-content`);a||(a=document.createElement(`div`),a.className=`modal-content`,this._modal.appendChild(a)),a.classList.remove(`modal-content--small`,`modal-content--large`),i!==`default`&&a.classList.add(`modal-content--${i}`),this._header||(this._header=document.createElement(`div`),this._header.className=`mint-modal-header`,a.appendChild(this._header)),this._headingSlot||(this._headingSlot=document.createElement(`div`),this._headingSlot.className=`mint-modal-heading`,this._headingSlot.setAttribute(`slot`,`heading`),this._header.appendChild(this._headingSlot));let o=this._headingSlot.querySelector(`mint-text`);t?(o||(o=document.createElement(`mint-text`),o.setAttribute(`size`,`sub-heading`),o.setAttribute(`bold`,``),this._headingSlot.appendChild(o)),o.textContent=t):o&&o.remove(),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._headingSlot&&e.getAttribute(`slot`)===`heading`).forEach(e=>{e.parentElement!==this._headingSlot&&this._headingSlot.appendChild(e)}),this._closeButton||(this._closeButton=document.createElement(`mint-button`),this._closeButton.classList.add(`mint-modal-close-button`),this._closeButton.setAttribute(`variant`,`ghost`),this._closeButton.setAttribute(`icon`,`close`),this._closeButton.addEventListener(`click`,()=>this.close()),this._header.appendChild(this._closeButton)),this._bodySlot||(this._bodySlot=document.createElement(`div`),this._bodySlot.className=`mint-modal-body`,this._bodySlot.setAttribute(`slot`,`body`),a.appendChild(this._bodySlot)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._bodySlot&&e.getAttribute(`slot`)===`body`).forEach(e=>{e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)});let s=Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`),c=this._actionsSlot?.querySelector(`mint-stack`),l=!!c&&c.children.length>0;if(s.length||l){this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`p-4 border-t border-gray-200 dark:border-mint-divider`,this._actionsSlot.setAttribute(`slot`,`actions`),a.appendChild(this._actionsSlot));let e=this._actionsSlot.querySelector(`mint-stack`);e||(e=document.createElement(`mint-stack`),e.setAttribute(`direction`,`horizontal`),e.setAttribute(`align-content`,`right`),e.className=`mint-actions-stack`,this._actionsSlot.appendChild(e)),s.forEach(t=>{Array.from(t.children).forEach(t=>e.appendChild(t)),t.remove()})}else this._actionsSlot&&=(this._actionsSlot.remove(),null);Array.from(this.children).forEach(e=>{e!==this._overlay&&e!==this._modal&&e.getAttribute(`slot`)!==`heading`&&e.getAttribute(`slot`)!==`body`&&e.getAttribute(`slot`)!==`actions`&&e!==this._headingSlot&&e!==this._bodySlot&&e!==this._actionsSlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._modal)return;document.documentElement?.classList.contains(`dark`)||document.documentElement?.dataset.mintTheme;let e=this._modal.querySelector(`.modal-content`);e&&(e.style.background=`var(--mint-color-surface-raised)`)}_observeDarkMode(){if(!this._darkModeObserver){if(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),!document.documentElement)return;this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`data-mint-theme`]})}}_animateEnter(){let e=this._modal?.querySelector(`.modal-content`);e&&(this._exitTimer&&=(clearTimeout(this._exitTimer),null),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null),this.classList.remove(`mint-modal-closing`),this.classList.remove(`mint-modal-open`),this.classList.add(`mint-modal-open`),this.classList.remove(`mint-hidden`),e.style.transform=`none`,e.style.opacity=`0`,e.style.transition=`none`,e.getBoundingClientRect(),requestAnimationFrame(()=>{this.isOpen()&&(e.style.transition=`opacity 200ms ease-out`,e.style.opacity=`1`,this._backdropTimer=window.setTimeout(()=>{e.style.transition=``,e.style.opacity=``,e.style.transform=``,this._backdropTimer=null},220))}))}_findTriggerElement(e){if(typeof e==`string`){let t=document.getElementById(e);return t&&!this.contains(t)?t:null}if(e instanceof HTMLElement)return e.isConnected&&!this.contains(e)?e:null;let t=this.getAttribute(`trigger-id`);if(t){let e=document.getElementById(t);if(e&&!this.contains(e))return e}let n=document.activeElement;return n instanceof HTMLElement&&n.isConnected&&n!==document.body&&!this.contains(n)?n:null}_findTriggerPoint(e){if(!e)return null;let t=this._lastPointerPoint;if(!t||Date.now()-t.time>1e3)return null;let n=t.target instanceof Node?t.target:null;return n===e||n&&e.contains(n)?{x:t.x,y:t.y}:null}_animateExit(){this.classList.remove(`mint-modal-open`),this._backdropTimer&&=(clearTimeout(this._backdropTimer),null);let e=this._modal?.querySelector(`.modal-content`);if(!e){this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`),i(this);return}this._exitTimer&&clearTimeout(this._exitTimer),this.classList.add(`mint-modal-closing`),e.style.transition=`opacity 200ms ease-in`,e.style.opacity=`0`,this._exitTimer=setTimeout(()=>{this._exitTimer=null,!this.isOpen()&&(this.classList.add(`mint-hidden`),this.classList.remove(`mint-modal-closing`),e.style.transform=``,e.style.opacity=``,e.style.transition=``,i(this))},200)}};typeof customElements<`u`&&!customElements.get(`mint-modal`)&&e.t(`mint-modal`,a),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./register-element-tCL_F1YI.js`),t=require(`./ScrollFade-BMs09zZN.js`);var n=new Set([`up`,`down`,`left`,`right`]);function r(e){let t=e.getBoundingClientRect(),n=Math.max(0,t.top),r=Math.min(window.innerWidth,t.right),i=Math.min(window.innerHeight,t.bottom),a=Math.max(0,t.left);for(let t=e.parentElement;t&&t!==document.body;t=t.parentElement){let e=getComputedStyle(t),o=t.getBoundingClientRect();/(auto|scroll|hidden|clip)/.test(e.overflowY)&&(n=Math.max(n,o.top),i=Math.min(i,o.bottom)),/(auto|scroll|hidden|clip)/.test(e.overflowX)&&(a=Math.max(a,o.left),r=Math.min(r,o.right))}return i>n&&r>a}var i=class extends HTMLElement{static get observedAttributes(){return[`direction`,`open`,`trigger-id`,`trigger-toggle`,`trigger-align`,`align-selected`,`padding`,`hover`,`distance`]}constructor(){super(),this._trigger=null,this._triggerLookupTimer=null,this._clickHandler=null,this._hoverEnterHandler=null,this._hoverLeaveHandler=null,this._outsideHandler=null,this._escapeHandler=null,this._positionHandler=null,this._scrollHandler=null,this._resizeObserver=null,this._hoverCloseTimer=null,this._closeAnimationTimer=null,this._blobAnimation=null,this._disposeScrollFade=null}connectedCallback(){this.render(),this._disposeScrollFade?.();let e=this.classList.contains(`mint-select-popover`)?this.querySelector(`.mint-select-options`):this;this._disposeScrollFade=t.n(e||this,e?`vertical`:`both`),this._setupTrigger()}disconnectedCallback(){this._removeTrigger(),this._removeOpenListeners(),this._disposeScrollFade?.(),this._disposeScrollFade=null,clearTimeout(this._hoverCloseTimer),clearTimeout(this._closeAnimationTimer),this._blobAnimation?.cancel()}attributeChangedCallback(e,t,n){t===n||!this.isConnected||((e===`trigger-id`||e===`trigger-toggle`||e===`hover`)&&this._setupTrigger(),this.render())}getDirection(){let e=this.getAttribute(`direction`)||`down`;return n.has(e)?e:`down`}getTriggerId(){return this.getAttribute(`trigger-id`)||``}_findTrigger(e){let t=this.getRootNode();return t instanceof ShadowRoot?t.querySelector(`#${CSS.escape(e)}`):document.getElementById(e)}isOpen(){return this.hasAttribute(`open`)&&this.getAttribute(`open`)!==`false`}isHoverEnabled(){return this.hasAttribute(`hover`)&&this.getAttribute(`hover`)!==`false`}isTriggerToggleEnabled(){return this.getAttribute(`trigger-toggle`)!==`false`}open(){this.setAttribute(`open`,`true`)}close(){this.removeAttribute(`open`)}_removeTrigger(){clearTimeout(this._triggerLookupTimer),this._triggerLookupTimer=null,this._trigger&&(this._clickHandler&&this._trigger.removeEventListener(`click`,this._clickHandler),this._hoverEnterHandler&&this._trigger.removeEventListener(`mouseenter`,this._hoverEnterHandler),this._hoverLeaveHandler&&this._trigger.removeEventListener(`mouseleave`,this._hoverLeaveHandler),this._hoverEnterHandler&&this.removeEventListener(`mouseenter`,this._hoverEnterHandler),this._hoverLeaveHandler&&this.removeEventListener(`mouseleave`,this._hoverLeaveHandler),this._trigger.removeAttribute(`aria-haspopup`),this._trigger.removeAttribute(`aria-expanded`),this._trigger=null,this._clickHandler=this._hoverEnterHandler=this._hoverLeaveHandler=null)}_setupTrigger(){this._removeTrigger();let e=this.getTriggerId();if(e){if(this._trigger=this._findTrigger(e),!this._trigger){this._triggerLookupTimer=setTimeout(()=>{this.isConnected&&this.getTriggerId()===e&&!this._trigger&&this._setupTrigger()},40);return}this._syncLayerZIndex(),this._trigger.setAttribute(`aria-haspopup`,`true`),this._trigger.setAttribute(`aria-expanded`,String(this.isOpen())),this.isTriggerToggleEnabled()&&(this._clickHandler=e=>{this._trigger?.tagName===`A`&&e.preventDefault(),this.isOpen()?this.close():this.open()},this._trigger.addEventListener(`click`,this._clickHandler)),this.isHoverEnabled()&&(this._hoverEnterHandler=()=>{clearTimeout(this._hoverCloseTimer),this.open()},this._hoverLeaveHandler=()=>this._scheduleHoverClose(),this._trigger.addEventListener(`mouseenter`,this._hoverEnterHandler),this._trigger.addEventListener(`mouseleave`,this._hoverLeaveHandler),this.addEventListener(`mouseenter`,this._hoverEnterHandler),this.addEventListener(`mouseleave`,this._hoverLeaveHandler))}}_getLayerZIndex(){let e=900,t=this._trigger||this.parentElement;for(;t&&t!==document.documentElement;){let n=Number.parseInt(getComputedStyle(t).zIndex,10);Number.isFinite(n)&&(e=Math.max(e,n)),t=t.parentElement}return Math.max(901,e+1)}_syncLayerZIndex(){this.style.zIndex=String(this._getLayerZIndex())}_scheduleHoverClose(){clearTimeout(this._hoverCloseTimer),this._hoverCloseTimer=setTimeout(()=>{!this._trigger?.matches(`:hover`)&&!this.matches(`:hover`)&&this.close()},140)}_removeOpenListeners(){this._outsideHandler&&document.removeEventListener(`click`,this._outsideHandler),this._escapeHandler&&document.removeEventListener(`keydown`,this._escapeHandler),this._positionHandler&&window.removeEventListener(`resize`,this._positionHandler),this._scrollHandler&&window.removeEventListener(`scroll`,this._scrollHandler,!0),this._resizeObserver?.disconnect(),this._resizeObserver=null,this._outsideHandler=this._escapeHandler=this._positionHandler=this._scrollHandler=null}_setOpenListeners(){if(!this._outsideHandler){if(this._outsideHandler=e=>{let t=e.composedPath();t.includes(this)||t.includes(this._trigger)||(e.target instanceof Element?e.target:null)?.closest(`[data-keep-popover-open]`)||this.close()},this._escapeHandler=e=>{e.key===`Escape`&&(this.close(),this._trigger?.focus?.())},this._positionHandler=()=>{this.isOpen()&&(this._position(),this._alignSelectedOptionToTrigger())},this._scrollHandler=e=>{if(!this.isOpen())return;let t=e.target;if(!(t instanceof Node&&(t===this||this.contains(t)))){if(this.classList.contains(`mint-select-popover`)){!this._trigger||!r(this._trigger)?this.close():(this._position({allowViewportFlip:!1,clampToViewport:!1}),this._alignSelectedOptionToTrigger());return}this._position({allowViewportFlip:!1,clampToViewport:!1}),this._alignSelectedOptionToTrigger()}},typeof ResizeObserver<`u`&&this._trigger){this._resizeObserver=new ResizeObserver(()=>{this.isOpen()&&(this._position(),this._alignSelectedOptionToTrigger())}),this.classList.contains(`mint-select-popover`)||this._resizeObserver.observe(this);let e=this._trigger,t=0;for(;e&&e!==document.documentElement&&t<8;)this._resizeObserver.observe(e),e=e.parentElement,t+=1}setTimeout(()=>{this.isOpen()&&this._outsideHandler&&document.addEventListener(`click`,this._outsideHandler)},0),document.addEventListener(`keydown`,this._escapeHandler),window.addEventListener(`resize`,this._positionHandler),window.addEventListener(`scroll`,this._scrollHandler,!0)}}_getFixedPositionContext(){for(let e=this.parentElement;e&&e!==document.documentElement;e=e.parentElement){let t=getComputedStyle(e),n=`${t.contain} ${t.willChange}`;if(!(t.transform!==`none`||t.perspective!==`none`||t.filter!==`none`||t.backdropFilter!==`none`||[`layout`,`paint`,`strict`,`content`,`transform`,`perspective`,`filter`].some(e=>n.includes(e))))continue;let r=e.getBoundingClientRect(),i=r.width/(e.offsetWidth||r.width)||1,a=r.height/(e.offsetHeight||r.height)||1;return{scaleX:i,scaleY:a,originLeft:r.left+(parseFloat(t.borderLeftWidth)||0)*i,originTop:r.top+(parseFloat(t.borderTopWidth)||0)*a}}return{scaleX:1,scaleY:1,originLeft:0,originTop:0}}_position({allowViewportFlip:e=!0,clampToViewport:t=!0}={}){let n=this._findTrigger(this.getTriggerId());n&&n!==this._trigger&&this._setupTrigger();let r=n||this._trigger;if(!r)return;let i=r.getBoundingClientRect(),a=this._getFixedPositionContext(),o={width:this.offsetWidth*a.scaleX,height:this.offsetHeight*a.scaleY},s=this._distancePx(),c=s*a.scaleX,l=s*a.scaleY,u=e?this.getDirection():this.dataset.direction||this.getDirection(),d=0,f=0,p=this.getAttribute(`trigger-align`)||`center`;if(u===`down`||u===`up`){let t=i.bottom+l,n=i.top-o.height-l;e&&u===`down`&&t+o.height>innerHeight-12&&n>=12?u=`up`:e&&u===`up`&&n<12&&t+o.height<=innerHeight-12&&(u=`down`);let r=this.hasAttribute(`align-selected`)?this.querySelector(`[role="option"][aria-selected="true"]`):null;if(r){let e=r.closest(`[role="listbox"]`);if(e&&e.scrollHeight>e.clientHeight+1){let t=Math.max(0,e.scrollHeight-e.clientHeight),n=r.offsetTop-Math.max(0,(e.clientHeight-r.offsetHeight)/2);e.scrollTop=Math.max(0,Math.min(t,n))}}if(d=u===`down`?t:n,r&&this.classList.contains(`mint-select-popover`)){let e=this.getBoundingClientRect(),t=r.getBoundingClientRect().top-e.top;d=i.top-t}f=p===`start`?i.left:p===`end`?i.right-o.width:i.left+(i.width-o.width)/2}else{let t=i.right+c,n=i.left-o.width-c;e&&u===`right`&&t+o.width>innerWidth-12&&n>=12?u=`left`:e&&u===`left`&&n<12&&t+o.width<=innerWidth-12&&(u=`right`),f=u===`right`?t:n,d=p===`start`?i.top:p===`end`?i.bottom-o.height:i.top+(i.height-o.height)/2}let m=t&&!this.classList.contains(`mint-select-popover`)?Math.max(12,Math.min(d,innerHeight-o.height-12)):d,h=t?Math.max(12,Math.min(f,innerWidth-o.width-12)):f,g=(m-a.originTop)/a.scaleY,_=(h-a.originLeft)/a.scaleX;this.style.top=`${g}px`,this.style.left=`${_}px`,this.dataset.direction=u,this.style.setProperty(`--mint-popover-origin-x`,`${(i.left+i.width/2-h)/a.scaleX}px`),this.style.setProperty(`--mint-popover-origin-y`,`${(i.top+i.height/2-m)/a.scaleY}px`)}_alignSelectedOptionToTrigger(){if(!this.classList.contains(`mint-select-popover`)||!this._trigger)return;let e=this.querySelector(`[role="option"][aria-selected="true"]`);if(!e)return;let t=this._trigger.getBoundingClientRect(),n=e.closest(`[role="listbox"]`),r=window.visualViewport,i=r?.offsetTop??0,a=r?.height??window.innerHeight,o=Math.max(0,a-24);this.style.maxHeight=`${o}px`,this.style.overflowY=`auto`;let s=this.getBoundingClientRect(),c=e.getBoundingClientRect(),l=i+12,u=Math.max(l,i+a-12-s.height),d=Math.max(l,Math.min(t.top-(c.top-s.top),u));if(n){let r=t.top-d,o=c.top-s.top;n.scrollTop+=o-r,s=this.getBoundingClientRect(),c=e.getBoundingClientRect();let u=t.top-(c.top-s.top),f=Math.max(l,i+a-12-s.height);d=Math.max(l,Math.min(u,f))}this.style.top=`${d}px`}_distancePx(){let e=(this.getAttribute(`distance`)||`8px`).trim(),t=Number.parseFloat(e);return Number.isFinite(t)?e.endsWith(`rem`)?t*(parseFloat(getComputedStyle(document.documentElement).fontSize)||16):Math.max(0,t):8}_animateBlob(e){if(this._blobAnimation?.cancel(),this._blobAnimation=null,typeof this.animate!=`function`)return 0;let t=getComputedStyle(this).borderRadius||`.75rem`;if(matchMedia(`(prefers-reduced-motion: reduce)`).matches)return 0;let n=e?380:280,r=[{transform:`scale(.035, .035)`,borderRadius:`50%`,opacity:.94,offset:0},{transform:`scale(.3, .42)`,borderRadius:`50%`,opacity:1,offset:.58},{transform:`scale(1.035, .96)`,borderRadius:`1rem`,offset:.9},{transform:`scale(1)`,borderRadius:t,offset:1}],i=e?r:[...r].reverse().map(({offset:e,...t})=>({...t,offset:1-e}));return this._blobAnimation=this.animate(i,{duration:n,easing:e?`cubic-bezier(.2, .8, .2, 1)`:`cubic-bezier(.4, 0, .8, .2)`,fill:`both`}),n}render(){let e=this.isOpen();this._syncLayerZIndex();let t=this.hasAttribute(`data-open`)||this.dataset.state===`closing`,n=this.hasAttribute(`data-open`);if(this.toggleAttribute(`data-open`,e),this.setAttribute(`aria-hidden`,String(!e)),this._trigger&&this._trigger.setAttribute(`aria-expanded`,String(e)),e){clearTimeout(this._closeAnimationTimer);let e=!n||this.dataset.state===`closing`;e&&(this._blobAnimation?.cancel(),this._blobAnimation=null),this.dataset.state=`open`,this._setOpenListeners(),this._position(),this._alignSelectedOptionToTrigger(),e&&!this.classList.contains(`mint-select-popover`)&&this._animateBlob(!0),requestAnimationFrame(()=>requestAnimationFrame(()=>{this.isOpen()&&(this._position(),this._alignSelectedOptionToTrigger())}))}else if(this._removeOpenListeners(),t){this.dataset.state=`closing`;let e=this._animateBlob(!1);e?this._closeAnimationTimer=setTimeout(()=>{this.dataset.state===`closing`&&(this._blobAnimation?.cancel(),this._blobAnimation=null,this.dataset.state=`closed`)},e):this.dataset.state=`closed`}else this.dataset.state=`closed`}};typeof customElements<`u`&&!customElements.get(`mint-popover`)&&e.t(`mint-popover`,i),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
|
|
1
|
+
const e=require(`./register-element-tCL_F1YI.js`),t=require(`./ScrollFade-Dfq2B1Hm.js`);var n=new Set([`up`,`down`,`left`,`right`]);function r(e){let t=e.getBoundingClientRect(),n=Math.max(0,t.top),r=Math.min(window.innerWidth,t.right),i=Math.min(window.innerHeight,t.bottom),a=Math.max(0,t.left);for(let t=e.parentElement;t&&t!==document.body;t=t.parentElement){let e=getComputedStyle(t),o=t.getBoundingClientRect();/(auto|scroll|hidden|clip)/.test(e.overflowY)&&(n=Math.max(n,o.top),i=Math.min(i,o.bottom)),/(auto|scroll|hidden|clip)/.test(e.overflowX)&&(a=Math.max(a,o.left),r=Math.min(r,o.right))}return i>n&&r>a}var i=class extends HTMLElement{static get observedAttributes(){return[`direction`,`open`,`trigger-id`,`trigger-toggle`,`trigger-align`,`align-selected`,`padding`,`hover`,`distance`]}constructor(){super(),this._trigger=null,this._triggerLookupTimer=null,this._clickHandler=null,this._hoverEnterHandler=null,this._hoverLeaveHandler=null,this._outsideHandler=null,this._escapeHandler=null,this._positionHandler=null,this._scrollHandler=null,this._resizeObserver=null,this._hoverCloseTimer=null,this._closeAnimationTimer=null,this._blobAnimation=null,this._disposeScrollFade=null}connectedCallback(){this.render(),this._disposeScrollFade?.();let e=this.classList.contains(`mint-select-popover`)?this.querySelector(`.mint-select-options`):this;this._disposeScrollFade=t.n(e||this,e?`vertical`:`both`),this._setupTrigger()}disconnectedCallback(){this._removeTrigger(),this._removeOpenListeners(),this._disposeScrollFade?.(),this._disposeScrollFade=null,clearTimeout(this._hoverCloseTimer),clearTimeout(this._closeAnimationTimer),this._blobAnimation?.cancel()}attributeChangedCallback(e,t,n){t===n||!this.isConnected||((e===`trigger-id`||e===`trigger-toggle`||e===`hover`)&&this._setupTrigger(),this.render())}getDirection(){let e=this.getAttribute(`direction`)||`down`;return n.has(e)?e:`down`}getTriggerId(){return this.getAttribute(`trigger-id`)||``}_findTrigger(e){let t=this.getRootNode();return t instanceof ShadowRoot?t.querySelector(`#${CSS.escape(e)}`):document.getElementById(e)}isOpen(){return this.hasAttribute(`open`)&&this.getAttribute(`open`)!==`false`}isHoverEnabled(){return this.hasAttribute(`hover`)&&this.getAttribute(`hover`)!==`false`}isTriggerToggleEnabled(){return this.getAttribute(`trigger-toggle`)!==`false`}open(){this.setAttribute(`open`,`true`)}close(){this.removeAttribute(`open`)}_removeTrigger(){clearTimeout(this._triggerLookupTimer),this._triggerLookupTimer=null,this._trigger&&(this._clickHandler&&this._trigger.removeEventListener(`click`,this._clickHandler),this._hoverEnterHandler&&this._trigger.removeEventListener(`mouseenter`,this._hoverEnterHandler),this._hoverLeaveHandler&&this._trigger.removeEventListener(`mouseleave`,this._hoverLeaveHandler),this._hoverEnterHandler&&this.removeEventListener(`mouseenter`,this._hoverEnterHandler),this._hoverLeaveHandler&&this.removeEventListener(`mouseleave`,this._hoverLeaveHandler),this._trigger.removeAttribute(`aria-haspopup`),this._trigger.removeAttribute(`aria-expanded`),this._trigger=null,this._clickHandler=this._hoverEnterHandler=this._hoverLeaveHandler=null)}_setupTrigger(){this._removeTrigger();let e=this.getTriggerId();if(e){if(this._trigger=this._findTrigger(e),!this._trigger){this._triggerLookupTimer=setTimeout(()=>{this.isConnected&&this.getTriggerId()===e&&!this._trigger&&this._setupTrigger()},40);return}this._syncLayerZIndex(),this._trigger.setAttribute(`aria-haspopup`,`true`),this._trigger.setAttribute(`aria-expanded`,String(this.isOpen())),this.isTriggerToggleEnabled()&&(this._clickHandler=e=>{this._trigger?.tagName===`A`&&e.preventDefault(),this.isOpen()?this.close():this.open()},this._trigger.addEventListener(`click`,this._clickHandler)),this.isHoverEnabled()&&(this._hoverEnterHandler=()=>{clearTimeout(this._hoverCloseTimer),this.open()},this._hoverLeaveHandler=()=>this._scheduleHoverClose(),this._trigger.addEventListener(`mouseenter`,this._hoverEnterHandler),this._trigger.addEventListener(`mouseleave`,this._hoverLeaveHandler),this.addEventListener(`mouseenter`,this._hoverEnterHandler),this.addEventListener(`mouseleave`,this._hoverLeaveHandler))}}_getLayerZIndex(){let e=900,t=this._trigger||this.parentElement;for(;t&&t!==document.documentElement;){let n=Number.parseInt(getComputedStyle(t).zIndex,10);Number.isFinite(n)&&(e=Math.max(e,n)),t=t.parentElement}return Math.max(901,e+1)}_syncLayerZIndex(){this.style.zIndex=String(this._getLayerZIndex())}_scheduleHoverClose(){clearTimeout(this._hoverCloseTimer),this._hoverCloseTimer=setTimeout(()=>{!this._trigger?.matches(`:hover`)&&!this.matches(`:hover`)&&this.close()},140)}_removeOpenListeners(){this._outsideHandler&&document.removeEventListener(`click`,this._outsideHandler),this._escapeHandler&&document.removeEventListener(`keydown`,this._escapeHandler),this._positionHandler&&window.removeEventListener(`resize`,this._positionHandler),this._scrollHandler&&window.removeEventListener(`scroll`,this._scrollHandler,!0),this._resizeObserver?.disconnect(),this._resizeObserver=null,this._outsideHandler=this._escapeHandler=this._positionHandler=this._scrollHandler=null}_setOpenListeners(){if(!this._outsideHandler){if(this._outsideHandler=e=>{let t=e.composedPath();t.includes(this)||t.includes(this._trigger)||(e.target instanceof Element?e.target:null)?.closest(`[data-keep-popover-open]`)||this.close()},this._escapeHandler=e=>{e.key===`Escape`&&(this.close(),this._trigger?.focus?.())},this._positionHandler=()=>{this.isOpen()&&(this._position(),this._alignSelectedOptionToTrigger())},this._scrollHandler=e=>{if(!this.isOpen())return;let t=e.target;if(!(t instanceof Node&&(t===this||this.contains(t)))){if(this.classList.contains(`mint-select-popover`)){!this._trigger||!r(this._trigger)?this.close():(this._position({allowViewportFlip:!1,clampToViewport:!1}),this._alignSelectedOptionToTrigger());return}this._position({allowViewportFlip:!1,clampToViewport:!1}),this._alignSelectedOptionToTrigger()}},typeof ResizeObserver<`u`&&this._trigger){this._resizeObserver=new ResizeObserver(()=>{this.isOpen()&&(this._position(),this._alignSelectedOptionToTrigger())}),this.classList.contains(`mint-select-popover`)||this._resizeObserver.observe(this);let e=this._trigger,t=0;for(;e&&e!==document.documentElement&&t<8;)this._resizeObserver.observe(e),e=e.parentElement,t+=1}setTimeout(()=>{this.isOpen()&&this._outsideHandler&&document.addEventListener(`click`,this._outsideHandler)},0),document.addEventListener(`keydown`,this._escapeHandler),window.addEventListener(`resize`,this._positionHandler),window.addEventListener(`scroll`,this._scrollHandler,!0)}}_getFixedPositionContext(){for(let e=this.parentElement;e&&e!==document.documentElement;e=e.parentElement){let t=getComputedStyle(e),n=`${t.contain} ${t.willChange}`;if(!(t.transform!==`none`||t.perspective!==`none`||t.filter!==`none`||t.backdropFilter!==`none`||[`layout`,`paint`,`strict`,`content`,`transform`,`perspective`,`filter`].some(e=>n.includes(e))))continue;let r=e.getBoundingClientRect(),i=r.width/(e.offsetWidth||r.width)||1,a=r.height/(e.offsetHeight||r.height)||1;return{scaleX:i,scaleY:a,originLeft:r.left+(parseFloat(t.borderLeftWidth)||0)*i,originTop:r.top+(parseFloat(t.borderTopWidth)||0)*a}}return{scaleX:1,scaleY:1,originLeft:0,originTop:0}}_position({allowViewportFlip:e=!0,clampToViewport:t=!0}={}){let n=this._findTrigger(this.getTriggerId());n&&n!==this._trigger&&this._setupTrigger();let r=n||this._trigger;if(!r)return;let i=r.getBoundingClientRect(),a=this._getFixedPositionContext(),o={width:this.offsetWidth*a.scaleX,height:this.offsetHeight*a.scaleY},s=this._distancePx(),c=s*a.scaleX,l=s*a.scaleY,u=e?this.getDirection():this.dataset.direction||this.getDirection(),d=0,f=0,p=this.getAttribute(`trigger-align`)||`center`;if(u===`down`||u===`up`){let t=i.bottom+l,n=i.top-o.height-l;e&&u===`down`&&t+o.height>innerHeight-12&&n>=12?u=`up`:e&&u===`up`&&n<12&&t+o.height<=innerHeight-12&&(u=`down`);let r=this.hasAttribute(`align-selected`)?this.querySelector(`[role="option"][aria-selected="true"]`):null;if(r){let e=r.closest(`[role="listbox"]`);if(e&&e.scrollHeight>e.clientHeight+1){let t=Math.max(0,e.scrollHeight-e.clientHeight),n=r.offsetTop-Math.max(0,(e.clientHeight-r.offsetHeight)/2);e.scrollTop=Math.max(0,Math.min(t,n))}}if(d=u===`down`?t:n,r&&this.classList.contains(`mint-select-popover`)){let e=this.getBoundingClientRect(),t=r.getBoundingClientRect().top-e.top;d=i.top-t}f=p===`start`?i.left:p===`end`?i.right-o.width:i.left+(i.width-o.width)/2}else{let t=i.right+c,n=i.left-o.width-c;e&&u===`right`&&t+o.width>innerWidth-12&&n>=12?u=`left`:e&&u===`left`&&n<12&&t+o.width<=innerWidth-12&&(u=`right`),f=u===`right`?t:n,d=p===`start`?i.top:p===`end`?i.bottom-o.height:i.top+(i.height-o.height)/2}let m=t&&!this.classList.contains(`mint-select-popover`)?Math.max(12,Math.min(d,innerHeight-o.height-12)):d,h=t?Math.max(12,Math.min(f,innerWidth-o.width-12)):f,g=(m-a.originTop)/a.scaleY,_=(h-a.originLeft)/a.scaleX;this.style.top=`${g}px`,this.style.left=`${_}px`,this.dataset.direction=u,this.style.setProperty(`--mint-popover-origin-x`,`${(i.left+i.width/2-h)/a.scaleX}px`),this.style.setProperty(`--mint-popover-origin-y`,`${(i.top+i.height/2-m)/a.scaleY}px`)}_alignSelectedOptionToTrigger(){if(!this.classList.contains(`mint-select-popover`)||!this._trigger)return;let e=this.querySelector(`[role="option"][aria-selected="true"]`);if(!e)return;let t=this._trigger.getBoundingClientRect(),n=e.closest(`[role="listbox"]`),r=window.visualViewport,i=r?.offsetTop??0,a=r?.height??window.innerHeight,o=Math.max(0,a-24);this.style.maxHeight=`${o}px`,this.style.overflowY=`auto`;let s=this.getBoundingClientRect(),c=e.getBoundingClientRect(),l=i+12,u=Math.max(l,i+a-12-s.height),d=Math.max(l,Math.min(t.top-(c.top-s.top),u));if(n){let r=t.top-d,o=c.top-s.top;n.scrollTop+=o-r,s=this.getBoundingClientRect(),c=e.getBoundingClientRect();let u=t.top-(c.top-s.top),f=Math.max(l,i+a-12-s.height);d=Math.max(l,Math.min(u,f))}this.style.top=`${d}px`}_distancePx(){let e=(this.getAttribute(`distance`)||`8px`).trim(),t=Number.parseFloat(e);return Number.isFinite(t)?e.endsWith(`rem`)?t*(parseFloat(getComputedStyle(document.documentElement).fontSize)||16):Math.max(0,t):8}_animateBlob(e){if(this._blobAnimation?.cancel(),this._blobAnimation=null,typeof this.animate!=`function`)return 0;let t=getComputedStyle(this).borderRadius||`.75rem`;if(matchMedia(`(prefers-reduced-motion: reduce)`).matches)return 0;let n=e?380:280,r=[{transform:`scale(.035, .035)`,borderRadius:`50%`,opacity:.94,offset:0},{transform:`scale(.3, .42)`,borderRadius:`50%`,opacity:1,offset:.58},{transform:`scale(1.035, .96)`,borderRadius:`1rem`,offset:.9},{transform:`scale(1)`,borderRadius:t,offset:1}],i=e?r:[...r].reverse().map(({offset:e,...t})=>({...t,offset:1-e}));return this._blobAnimation=this.animate(i,{duration:n,easing:e?`cubic-bezier(.2, .8, .2, 1)`:`cubic-bezier(.4, 0, .8, .2)`,fill:`both`}),n}render(){let e=this.isOpen();this._syncLayerZIndex();let t=this.hasAttribute(`data-open`)||this.dataset.state===`closing`,n=this.hasAttribute(`data-open`);if(this.toggleAttribute(`data-open`,e),this.setAttribute(`aria-hidden`,String(!e)),this._trigger&&this._trigger.setAttribute(`aria-expanded`,String(e)),e){clearTimeout(this._closeAnimationTimer);let e=!n||this.dataset.state===`closing`;e&&(this._blobAnimation?.cancel(),this._blobAnimation=null),this.dataset.state=`open`,this._setOpenListeners(),this._position(),this._alignSelectedOptionToTrigger(),e&&!this.classList.contains(`mint-select-popover`)&&this._animateBlob(!0),requestAnimationFrame(()=>requestAnimationFrame(()=>{this.isOpen()&&(this._position(),this._alignSelectedOptionToTrigger())}))}else if(this._removeOpenListeners(),t){this.dataset.state=`closing`;let e=this._animateBlob(!1);e?this._closeAnimationTimer=setTimeout(()=>{this.dataset.state===`closing`&&(this._blobAnimation?.cancel(),this._blobAnimation=null,this.dataset.state=`closed`)},e):this.dataset.state=`closed`}else this.dataset.state=`closed`}};typeof customElements<`u`&&!customElements.get(`mint-popover`)&&e.t(`mint-popover`,i),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`./icon-B9P0jyS2.js`).a({name:`search`,viewBox:`0 0 24 24`,path:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`,strokeLinecap:`round`,strokeLinejoin:`round`});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./icon-CWOP4Com.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./icon-D6C1XGp2.js`),require(`./popover-0YEhBrgv.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._prependNodes=[],this._appendNodes=[],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();this._collectAdornments();let 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);let f=this._makeAdornment(`prepend`,this._prependNodes);f&&this._wrapper.appendChild(f),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 p=this.getAttribute(`aria-label`)?.trim(),m=this.getAttribute(`aria-labelledby`)?.trim();m?this._select.setAttribute(`aria-labelledby`,m):o?this._select.removeAttribute(`aria-label`):this._select.setAttribute(`aria-label`,p||`Select an option`);let h=a.length>0?a:i;if(h.length>0&&h.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||``;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});let g=document.createElement(`div`);if(g.className=`mint-native-select-control-main`,g.appendChild(this._select),this._wrapper.appendChild(g),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),g.appendChild(e)}let _=this._makeAdornment(`append`,this._appendNodes);if(_&&this._wrapper.appendChild(_),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)}_collectAdornments(){let e=[...this._prependNodes,...this._appendNodes,...Array.from(this.querySelectorAll(`:scope > [slot="prepend"], :scope > [slot="append"]`))];this._prependNodes=e.filter(e=>e.getAttribute(`slot`)===`prepend`),this._appendNodes=e.filter(e=>e.getAttribute(`slot`)===`append`),this._prependNodes.forEach(e=>this.appendChild(e)),this._appendNodes.forEach(e=>this.appendChild(e))}_makeAdornment(e,t){if(!t.length)return null;let n=document.createElement(`span`);return n.className=`mint-native-select-adornment mint-native-select-${e}-slot`,t.forEach(e=>n.appendChild(e)),n}_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._prependNodes=[],this._appendNodes=[],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,this._collectAdornments(),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=this._makeAdornment(`prepend`,this._prependNodes);s&&o.append(s);let c=document.createElement(`button`);c.type=`button`,c.id=`${a}-trigger`,c.className=`mint-select-trigger`,c.disabled=this.isDisabled()||this.isLoading(),c.setAttribute(`role`,`combobox`),c.setAttribute(`aria-busy`,String(this.isLoading())),c.setAttribute(`aria-haspopup`,`listbox`),c.setAttribute(`aria-expanded`,`false`),c.setAttribute(`aria-required`,String(this.isRequired())),c.setAttribute(`aria-invalid`,String(this.hasError()));let l=this.getAttribute(`aria-labelledby`),u=this.getAttribute(`aria-label`)?.trim();if(l?c.setAttribute(`aria-labelledby`,l):!i&&u?c.setAttribute(`aria-label`,u):i&&c.setAttribute(`aria-labelledby`,`${a}-label`),i){let e=this.querySelector(`[${r}="label"]`);e&&(e.id=`${a}-label`)}let d=document.createElement(`span`);d.className=`mint-select-value`,c.append(d);let f=document.createElement(`span`);f.className=`mint-select-caret`,f.setAttribute(`aria-hidden`,`true`),f.innerHTML=`<mint-icon name="caret-up"></mint-icon><mint-icon name="caret-down"></mint-icon>`,c.append(f),o.append(c);let p=this._makeAdornment(`append`,this._appendNodes);p&&o.append(p);let m=null;this.isLoading()?(m=document.createElement(`div`),m.className=`mint-select-skeleton`,m.setAttribute(`aria-hidden`,`true`),m.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(m),c.style.visibility=`hidden`,this.setAttribute(`aria-busy`,`true`)):this.removeAttribute(`aria-busy`);let h=document.createElement(`select`);h.setAttribute(r,`native`),h.className=`mint-select-native-control`,h.id=`${a}-native`,h.name=this.getAttribute(`name`)||``,h.multiple=this.isMultiple(),this.hasAttribute(`form`)&&h.setAttribute(`form`,this.getAttribute(`form`)||``),h.required=this.isRequired(),h.disabled=this.isDisabled(),h.tabIndex=-1,h.setAttribute(`aria-hidden`,`true`),h.setAttribute(`aria-invalid`,String(this.hasError()));let g=[this.getAttribute(`aria-describedby`),i?`${a}-label`:``,this.getAttribute(`info`)?`${a}-info`:``,this.getAttribute(`error-message`)?`${a}-error`:``].filter(Boolean).join(` `);if(g&&h.setAttribute(`aria-describedby`,g),this.options().forEach(e=>h.append(e.cloneNode(!0))),!h.options.length){let e=document.createElement(`option`);e.value=``,e.textContent=this.getAttribute(`placeholder`)||`Select an option`,e.disabled=!0,h.append(e)}if(h.multiple){let t=n.length?n:this.parseValues(this.getAttribute(`values`)).length?this.parseValues(this.getAttribute(`values`)):e?[e]:[];t.length&&Array.from(h.options).forEach(e=>{e.selected=t.includes(e.value)})}else h.value=e;o.append(h),this._native=h,this._trigger=c;let _=document.createElement(`mint-popover`);_.className=`mint-select-popover`,_.setAttribute(r,`popover`),_.setAttribute(`trigger-id`,c.id),_.setAttribute(`trigger-toggle`,`false`),_.setAttribute(`direction`,`down`),_.setAttribute(`trigger-align`,`start`),_.setAttribute(`align-selected`,`true`),_.setAttribute(`distance`,`4`),_.setAttribute(`padding`,`0`),_.setAttribute(`aria-label`,i?`${i} options`:`Select options`);let v=document.createElement(`div`);v.className=`mint-select-options`,v.id=`${a}-listbox`,v.setAttribute(`role`,`listbox`),v.setAttribute(`aria-multiselectable`,String(this.isMultiple())),c.setAttribute(`aria-controls`,v.id),_.append(v),this.append(_),this._popover=_,this._list=v,this.renderOptions(),this.updateDisplay(),this.bindEvents();let y=this.getAttribute(`info`);if(y){let e=document.createElement(`div`);e.setAttribute(r,`info`),e.className=`mint-select-info`,e.id=`${a}-info`,e.textContent=y,this.append(e)}let b=this.getAttribute(`error-message`);if(this.hasError()&&b){let e=document.createElement(`div`);e.setAttribute(r,`error`),e.className=`mint-select-error`,e.id=`${a}-error`,e.textContent=b,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)}))}_collectAdornments(){let e=[...this._prependNodes,...this._appendNodes,...Array.from(this.querySelectorAll(`:scope > [slot="prepend"], :scope > [slot="append"]`))];this._prependNodes=e.filter(e=>e.getAttribute(`slot`)===`prepend`),this._appendNodes=e.filter(e=>e.getAttribute(`slot`)===`append`),this._prependNodes.forEach(e=>this.append(e)),this._appendNodes.forEach(e=>this.append(e))}_makeAdornment(e,t){if(!t.length)return null;let n=document.createElement(`span`);return n.className=`mint-select-adornment mint-select-${e}-slot`,t.forEach(e=>n.append(e)),n}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?.getAttribute(`data-display-label`)||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),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
|
|
1
|
+
require(`./icon-B9P0jyS2.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./icon-Cia9x_J2.js`),require(`./popover-CWWKb7L1.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._prependNodes=[],this._appendNodes=[],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();this._collectAdornments();let 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);let f=this._makeAdornment(`prepend`,this._prependNodes);f&&this._wrapper.appendChild(f),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 p=this.getAttribute(`aria-label`)?.trim(),m=this.getAttribute(`aria-labelledby`)?.trim();m?this._select.setAttribute(`aria-labelledby`,m):o?this._select.removeAttribute(`aria-label`):this._select.setAttribute(`aria-label`,p||`Select an option`);let h=a.length>0?a:i;if(h.length>0&&h.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||``;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});let g=document.createElement(`div`);if(g.className=`mint-native-select-control-main`,g.appendChild(this._select),this._wrapper.appendChild(g),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),g.appendChild(e)}let _=this._makeAdornment(`append`,this._appendNodes);if(_&&this._wrapper.appendChild(_),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)}_collectAdornments(){let e=[...this._prependNodes,...this._appendNodes,...Array.from(this.querySelectorAll(`:scope > [slot="prepend"], :scope > [slot="append"]`))];this._prependNodes=e.filter(e=>e.getAttribute(`slot`)===`prepend`),this._appendNodes=e.filter(e=>e.getAttribute(`slot`)===`append`),this._prependNodes.forEach(e=>this.appendChild(e)),this._appendNodes.forEach(e=>this.appendChild(e))}_makeAdornment(e,t){if(!t.length)return null;let n=document.createElement(`span`);return n.className=`mint-native-select-adornment mint-native-select-${e}-slot`,t.forEach(e=>n.appendChild(e)),n}_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._prependNodes=[],this._appendNodes=[],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,this._collectAdornments(),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=this._makeAdornment(`prepend`,this._prependNodes);s&&o.append(s);let c=document.createElement(`button`);c.type=`button`,c.id=`${a}-trigger`,c.className=`mint-select-trigger`,c.disabled=this.isDisabled()||this.isLoading(),c.setAttribute(`role`,`combobox`),c.setAttribute(`aria-busy`,String(this.isLoading())),c.setAttribute(`aria-haspopup`,`listbox`),c.setAttribute(`aria-expanded`,`false`),c.setAttribute(`aria-required`,String(this.isRequired())),c.setAttribute(`aria-invalid`,String(this.hasError()));let l=this.getAttribute(`aria-labelledby`),u=this.getAttribute(`aria-label`)?.trim();if(l?c.setAttribute(`aria-labelledby`,l):!i&&u?c.setAttribute(`aria-label`,u):i&&c.setAttribute(`aria-labelledby`,`${a}-label`),i){let e=this.querySelector(`[${r}="label"]`);e&&(e.id=`${a}-label`)}let d=document.createElement(`span`);d.className=`mint-select-value`,c.append(d);let f=document.createElement(`span`);f.className=`mint-select-caret`,f.setAttribute(`aria-hidden`,`true`),f.innerHTML=`<mint-icon name="caret-up"></mint-icon><mint-icon name="caret-down"></mint-icon>`,c.append(f),o.append(c);let p=this._makeAdornment(`append`,this._appendNodes);p&&o.append(p);let m=null;this.isLoading()?(m=document.createElement(`div`),m.className=`mint-select-skeleton`,m.setAttribute(`aria-hidden`,`true`),m.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(m),c.style.visibility=`hidden`,this.setAttribute(`aria-busy`,`true`)):this.removeAttribute(`aria-busy`);let h=document.createElement(`select`);h.setAttribute(r,`native`),h.className=`mint-select-native-control`,h.id=`${a}-native`,h.name=this.getAttribute(`name`)||``,h.multiple=this.isMultiple(),this.hasAttribute(`form`)&&h.setAttribute(`form`,this.getAttribute(`form`)||``),h.required=this.isRequired(),h.disabled=this.isDisabled(),h.tabIndex=-1,h.setAttribute(`aria-hidden`,`true`),h.setAttribute(`aria-invalid`,String(this.hasError()));let g=[this.getAttribute(`aria-describedby`),i?`${a}-label`:``,this.getAttribute(`info`)?`${a}-info`:``,this.getAttribute(`error-message`)?`${a}-error`:``].filter(Boolean).join(` `);if(g&&h.setAttribute(`aria-describedby`,g),this.options().forEach(e=>h.append(e.cloneNode(!0))),!h.options.length){let e=document.createElement(`option`);e.value=``,e.textContent=this.getAttribute(`placeholder`)||`Select an option`,e.disabled=!0,h.append(e)}if(h.multiple){let t=n.length?n:this.parseValues(this.getAttribute(`values`)).length?this.parseValues(this.getAttribute(`values`)):e?[e]:[];t.length&&Array.from(h.options).forEach(e=>{e.selected=t.includes(e.value)})}else h.value=e;o.append(h),this._native=h,this._trigger=c;let _=document.createElement(`mint-popover`);_.className=`mint-select-popover`,_.setAttribute(r,`popover`),_.setAttribute(`trigger-id`,c.id),_.setAttribute(`trigger-toggle`,`false`),_.setAttribute(`direction`,`down`),_.setAttribute(`trigger-align`,`start`),_.setAttribute(`align-selected`,`true`),_.setAttribute(`distance`,`4`),_.setAttribute(`padding`,`0`),_.setAttribute(`aria-label`,i?`${i} options`:`Select options`);let v=document.createElement(`div`);v.className=`mint-select-options`,v.id=`${a}-listbox`,v.setAttribute(`role`,`listbox`),v.setAttribute(`aria-multiselectable`,String(this.isMultiple())),c.setAttribute(`aria-controls`,v.id),_.append(v),this.append(_),this._popover=_,this._list=v,this.renderOptions(),this.updateDisplay(),this.bindEvents();let y=this.getAttribute(`info`);if(y){let e=document.createElement(`div`);e.setAttribute(r,`info`),e.className=`mint-select-info`,e.id=`${a}-info`,e.textContent=y,this.append(e)}let b=this.getAttribute(`error-message`);if(this.hasError()&&b){let e=document.createElement(`div`);e.setAttribute(r,`error`),e.className=`mint-select-error`,e.id=`${a}-error`,e.textContent=b,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)}))}_collectAdornments(){let e=[...this._prependNodes,...this._appendNodes,...Array.from(this.querySelectorAll(`:scope > [slot="prepend"], :scope > [slot="append"]`))];this._prependNodes=e.filter(e=>e.getAttribute(`slot`)===`prepend`),this._appendNodes=e.filter(e=>e.getAttribute(`slot`)===`append`),this._prependNodes.forEach(e=>this.append(e)),this._appendNodes.forEach(e=>this.append(e))}_makeAdornment(e,t){if(!t.length)return null;let n=document.createElement(`span`);return n.className=`mint-select-adornment mint-select-${e}-slot`,t.forEach(e=>n.append(e)),n}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?.getAttribute(`data-display-label`)||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),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./icon-
|
|
1
|
+
import "./icon-DAB2KLeo.js";
|
|
2
2
|
import { t as e } from "./register-element-BFYmIynH.js";
|
|
3
|
-
import "./icon-
|
|
4
|
-
import "./popover-
|
|
3
|
+
import "./icon-CIAsmizQ.js";
|
|
4
|
+
import "./popover-DPNBidSz.js";
|
|
5
5
|
//#region src/components/select/NativeSelect.ts
|
|
6
6
|
var t = "data-mint-native-select-part", n = class extends HTMLElement {
|
|
7
7
|
static get observedAttributes() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./register-element-tCL_F1YI.js`),t=require(`./ScrollFade-
|
|
1
|
+
const e=require(`./register-element-tCL_F1YI.js`),t=require(`./ScrollFade-Dfq2B1Hm.js`);var n=class extends HTMLElement{constructor(...e){super(...e),this._observer=null,this._disposeScrollFade=null}connectedCallback(){this.classList.add(`mint-table-host`),this._disposeScrollFade=t.n(this,`both`),this._observeChanges(),this._applyStyles(),requestAnimationFrame(()=>{this._applyStyles(),setTimeout(()=>this._applyStyles(),0)})}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._disposeScrollFade?.(),this._disposeScrollFade=null}_observeChanges(){this._observer=new MutationObserver(()=>this._applyStyles()),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!1})}_applyStyles(){this._observer?.disconnect();let e=Array.from(this.querySelectorAll(`table`));if(e.length===0){this._observer&&this._observeChanges();return}e.forEach(e=>{let t=!!e.closest(`[id^="mint-rt-vscroll-"]`)||!!e.closest(`mint-resource-table[data-mint-rt-fixed-header]`);e.classList.add(`mint-table-native`),e.classList.toggle(`mint-table-pinned-layout`,t)});let t=e.find(e=>e.querySelector(`thead`))??e[0],n=e.find(e=>e.querySelector(`tbody`))??e[0],r=t.querySelector(`thead`);r&&r.querySelectorAll(`th`).forEach(e=>{let t=e.querySelector(`mint-icon`),n=t?.getAttribute(`name`)||``,r=e.hasAttribute(`data-mint-rt-sortable`)||t!==null&&n!==`ellipsis`;e.classList.toggle(`mint-table-sortable`,r);let i=e.closest(`table`),a=i?.closest(`mint-resource-table`),o=!!i?.closest(`[id^="mint-rt-vscroll-"]`)||!!a?.hasAttribute(`data-mint-rt-fixed-header`);e.classList.toggle(`mint-table-pinned-header`,o)});let i=n.querySelector(`tbody`);if(i){let e=Array.from(i.querySelectorAll(`tr`)),t=!!n.closest(`[id^="mint-rt-vscroll-"]`)||!!n.closest(`mint-resource-table`)?.hasAttribute(`data-mint-rt-fixed-header`),r=e.findIndex(e=>e.getAttribute(`data-mint-rt-spacer`)===`bottom`);e.forEach((n,i)=>{let a=n.hasAttribute(`data-mint-rt-spacer`),o=n.hasAttribute(`data-row-clickable`);n.classList.toggle(`mint-table-spacer`,a),n.classList.toggle(`mint-table-clickable`,o&&!a),n.classList.toggle(`mint-table-row-bordered`,!a&&!t&&i!==e.length-1),Array.from(n.querySelectorAll(`td`)).forEach(o=>{let s=n.hasAttribute(`data-mint-rt-last-row`),c=r===-1&&i===e.length-1;o.classList.toggle(`mint-table-cell-bordered`,t&&!a&&!s&&!c),this._restoreCell(o)})})}n.querySelectorAll(`tfoot td`).forEach(e=>this._restoreCell(e)),this._observer&&this._observeChanges()}_restoreCell(e){if(e.dataset.mtProcessed!==`true`)return;let t={};Array.from(e.attributes).forEach(e=>{e.name.startsWith(`data-`)&&e.name!==`data-original`&&e.name!==`data-mt-processed`&&(t[e.name]=e.value)});let n=e.getAttribute(`data-original`)||``;e.dataset.mtProcessed=``,e.innerHTML=n,Object.entries(t).forEach(([t,n])=>e.setAttribute(t,n))}};customElements.get(`mint-table`)||e.t(`mint-table`,n),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./icon-CWOP4Com.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-CfvRRKGZ.js`),require(`./input-BI4nrOaG.js`),require(`./popover-0YEhBrgv.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._triggerId=`mint-time-picker-trigger-${Math.random().toString(36).slice(2,10)}`,this._popover=null,this._popoverObserver=null,this._triggerClickObserver=null,this._inputEl=null,this._hiddenInput=null,this._prependSlotNodes=[],this._appendSlotNodes=[],this._slotObserver=null,this._single={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeStart={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeEnd={hour:5,minute:0,second:0,meridiem:`PM`},this._invalidFromInput=!1}static get observedAttributes(){return[`value`,`inline`,`label`,`info`,`disabled`,`id`,`name`,`required`,`readonly`,`range`,`hours`,`minutes`,`seconds`,`error`,`error-message`]}connectedCallback(){this.classList.add(`mint-time-picker-host`),this._parseAndApplyValue(this.getAttribute(`value`)||``),this.render(),this._slotObserver=new MutationObserver(e=>{e.some(e=>e.type===`attributes`&&e.target.hasAttribute(`slot`)||e.type===`childList`&&e.target===this&&Array.from(e.addedNodes).some(e=>e instanceof HTMLElement&&(e.slot===`prepend`||e.slot===`append`)))&&this.render()}),this._slotObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`slot`]})}disconnectedCallback(){this._slotObserver?.disconnect(),this._slotObserver=null,this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._triggerClickObserver&&=(document.removeEventListener(`click`,this._triggerClickObserver,!0),null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`value`){this._parseAndApplyValue(n||``),this._syncHiddenInput(),this._syncInputValue();{let e=(this._popover||this).querySelector(`[data-mint-time-picker-body="true"]`);e&&this._buildPopoverContent(e)}return}e!==`error`&&e!==`error-message`&&(this._invalidFromInput=!1),this.render()}}get value(){return this.getValue()}set value(e){this.setValue(e||``)}getValue(){return this.getAttribute(`value`)||``}setValue(e){e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this._parseAndApplyValue(e||``),this._syncHiddenInput(),this._syncInputValue()}isRange(){return this.getAttribute(`range`)===`true`}isHoursEnabled(){let e=this.getAttribute(`hours`);return e===null?!0:e!==`false`}isMinutesEnabled(){let e=this.getAttribute(`minutes`);return e===null?!0:e!==`false`}isSecondsEnabled(){let e=this.getAttribute(`seconds`);return e===null?!1:e!==`false`}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasExternalError(){return this.getAttribute(`error`)===`true`}getExternalErrorMessage(){return this.getAttribute(`error-message`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getName(){return this.getAttribute(`name`)||``}_getEffectiveError(){return{hasError:this.hasExternalError(),message:this.getExternalErrorMessage()}}_formatParts(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=[];return t&&i.push(e.hour.toString()),n&&i.push(e.minute.toString().padStart(2,`0`)),r&&i.push(e.second.toString().padStart(2,`0`)),t?`${i.join(`:`)} ${e.meridiem.toLowerCase()}`:i.join(`:`)}_to24Hour(e){let t=e.hour%12;return e.meridiem===`PM`&&(t+=12),{hour:t,minute:e.minute,second:e.second}}_formatParts24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=this._to24Hour(e),a=[];return t&&a.push(i.hour.toString().padStart(2,`0`)),n&&a.push(i.minute.toString().padStart(2,`0`)),r&&a.push(i.second.toString().padStart(2,`0`)),a.join(`:`)}_getDisplayValue(){return this.isRange()?`${this._formatParts(this._rangeStart)} - ${this._formatParts(this._rangeEnd)}`:this._formatParts(this._single)}_getOutputValue(){return this.isRange()?`${this._formatParts24(this._rangeStart)} - ${this._formatParts24(this._rangeEnd)}`:this._formatParts24(this._single)}_getExpectedFormat(){let e=this.isHoursEnabled(),t=this.isMinutesEnabled(),n=this.isSecondsEnabled(),r=[];e&&r.push(`h`),t&&r.push(`mm`),n&&r.push(`ss`);let i=e?`${r.join(`:`)} am/pm`:r.join(`:`);return this.isRange()?`${i} - ${i}`:i}_syncHiddenInput(){this._hiddenInput&&(this._hiddenInput.value=this.getValue()||this._getOutputValue())}_syncInputValue(){this._inputEl&&(this._inputEl.value=this._getDisplayValue(),typeof this._inputEl.render==`function`&&this._inputEl.render())}_emitChangeFromPicker(){let e=this._getOutputValue();this._invalidFromInput=!1,this.setAttribute(`value`,e),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_parseSingle(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?\s*(am|pm)$/i);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0),s=e[4].toUpperCase();return t<1||t>12||n&&(a<0||a>59)||r&&(o<0||o>59)?null:{hour:t,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseSingleOutput24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0);if(t<0||t>23||n&&(a<0||a>59)||r&&(o<0||o>59))return null;let s=t>=12?`PM`:`AM`;return{hour:t%12==0?12:t%12,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseAndApplyValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingleOutput24(t||``),i=this._parseSingleOutput24(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingleOutput24(e);return t?(this._single=t,!0):!1}_parseAndApplyDisplayValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingle(t||``),i=this._parseSingle(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingle(e);return t?(this._single=t,!0):!1}_handleTypedValue(e){let t=e.trim();if(!t){this._invalidFromInput=!1,this.removeAttribute(`value`),this._syncHiddenInput(),this._syncInputValue();return}if(!this._parseAndApplyDisplayValue(t)){this._invalidFromInput=!0,this.removeAttribute(`value`),this._inputEl&&(this._inputEl.value=``),this._syncHiddenInput(),this.render(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}));return}this._invalidFromInput=!1;let n=this._getOutputValue();this.setAttribute(`value`,n),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_buildColumn(e,t,n,r=!0,i=`standard`,a=`Time`){let o=document.createElement(`div`);return o.className=`mint-time-picker-column mint-time-picker-column-${i}${r?` mint-time-picker-column-divider`:``}`,o.setAttribute(`role`,`group`),o.setAttribute(`aria-label`,a),e.forEach(e=>{let r=document.createElement(`button`);r.type=`button`;let i=e===t;r.className=`mint-time-picker-option${i?` is-selected`:``}`,r.dataset.selected=i?`true`:`false`,r.setAttribute(`aria-pressed`,String(i)),r.setAttribute(`aria-label`,`${a}: ${e}`),r.textContent=e,r.addEventListener(`click`,()=>n(e)),o.appendChild(r)}),o}_centerSelectedInColumn(e){let t=e.querySelector(`button[data-selected="true"]`);if(!t)return;let n=t.offsetTop-e.offsetTop-(e.clientHeight/2-t.offsetHeight/2),r=Math.max(0,Math.min(e.scrollHeight-e.clientHeight,n));e.scrollTo({top:r,behavior:`instant`})}_centerAllColumnsInPopoverBody(){let e=(this._popover||this).querySelector(`[data-mint-time-picker-body="true"]`);e&&Array.from(e.querySelectorAll(`.mint-time-picker-column`)).forEach(e=>this._centerSelectedInColumn(e))}_setupPopoverOpenObserver(){this._popover&&(this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._popoverObserver=new MutationObserver(()=>{this._popover?.getAttribute(`open`)===`true`&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:[`open`]}))}_buildPickerSet(e,t,n){let r=this.isHoursEnabled(),i=this.isMinutesEnabled(),a=this.isSecondsEnabled(),o=document.createElement(`div`),s=(r?1:0)+(i?1:0)+(a?1:0)+(r?1:0);o.className=`mint-time-picker-wheel`,o.style.gridTemplateColumns=`repeat(${Math.max(s,1)}, minmax(0, 1fr))`;let c=Array.from({length:12},(e,t)=>(t+1).toString().padStart(2,`0`)),l=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),u=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),d=[`AM`,`PM`],f=[];r&&f.push(this._buildColumn(c,t.hour.toString().padStart(2,`0`),e=>{n({...t,hour:Number(e)})},!0,`tall`,`Hour`)),i&&f.push(this._buildColumn(l,t.minute.toString().padStart(2,`0`),e=>{n({...t,minute:Number(e)})},!0,`tall`,`Minute`)),a&&f.push(this._buildColumn(u,t.second.toString().padStart(2,`0`),e=>{n({...t,second:Number(e)})},!0,`tall`,`Second`)),r&&f.push(this._buildColumn(d,t.meridiem,e=>{n({...t,meridiem:e})},!0,`tall`,`Meridiem`)),f.forEach((e,t)=>{t===f.length-1&&e.classList.remove(`mint-time-picker-column-divider`),o.appendChild(e)}),e.appendChild(o)}_buildPopoverContent(e){if(e.innerHTML=``,!this.isRange()){this._buildPickerSet(e,this._single,t=>{this._single=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)}),requestAnimationFrame(()=>this._centerAllColumnsInPopoverBody());return}let t=document.createElement(`div`);t.className=`mint-time-picker-range`;let n=document.createElement(`div`),r=document.createElement(`mint-text`);r.setAttribute(`variant`,`muted`),r.className=`mint-time-picker-range-label`,r.textContent=`Start`,n.appendChild(r),this._buildPickerSet(n,this._rangeStart,t=>{this._rangeStart=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)});let i=document.createElement(`div`),a=document.createElement(`mint-text`);a.setAttribute(`variant`,`muted`),a.className=`mint-time-picker-range-label`,a.textContent=`End`,i.appendChild(a),this._buildPickerSet(i,this._rangeEnd,t=>{this._rangeEnd=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)}),t.appendChild(n),t.appendChild(i),e.appendChild(t),requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})}render(){let e=this.isDisabled(),t=this.isReadonly(),n=this._getEffectiveError();this._collectAdornmentNodes(),this._triggerClickObserver&&=(document.removeEventListener(`click`,this._triggerClickObserver,!0),null),this.innerHTML=``;let r=document.createElement(`div`);r.className=`mint-time-picker-control`;let i=this.getAttribute(`inline`)===`true`;i||(this._inputEl=document.createElement(`mint-input`),this._inputEl.id=this._triggerId,this._inputEl.classList.add(`mint-time-picker-trigger`),this._inputEl.setAttribute(`type`,`text`),this._inputEl.setAttribute(`icon`,`clock`),this._inputEl.setAttribute(`placeholder`,this._getExpectedFormat()),this._inputEl.setAttribute(`label`,this.getLabel()),this._inputEl.setAttribute(`info`,this.getInfo()),this._inputEl.setAttribute(`value`,this._getDisplayValue()),this._inputEl.setAttribute(`error`,n.hasError?`true`:`false`),this._inputEl.setAttribute(`error-message`,n.message||``),this._prependSlotNodes.forEach(e=>this._inputEl.appendChild(e)),this._appendSlotNodes.forEach(e=>this._inputEl.appendChild(e)),e&&this._inputEl.setAttribute(`disabled`,`true`),t&&this._inputEl.setAttribute(`readonly`,`true`),this._inputEl.addEventListener(`change`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())}),this._inputEl.addEventListener(`blur`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())},!0),r.appendChild(this._inputEl)),this._hiddenInput=document.createElement(`input`),this._hiddenInput.type=`hidden`,this._hiddenInput.name=this.getName(),this._hiddenInput.required=this.isRequired(),r.appendChild(this._hiddenInput),this._syncHiddenInput();let a=document.createElement(`div`);if(a.setAttribute(`data-mint-time-picker-body`,`true`),a.className=`mint-time-picker-popover`,this._buildPopoverContent(a),i?(this._popover=null,r.appendChild(a),requestAnimationFrame(()=>this._centerAllColumnsInPopoverBody())):(this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`trigger-id`,this._triggerId),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`),this._popover.setAttribute(`distance`,`6px`),(e||t)&&this._popover.setAttribute(`open`,`false`),this._popover.appendChild(a),r.appendChild(this._popover),this._setupPopoverOpenObserver()),this.appendChild(r),!i&&this._inputEl){let e=this._inputEl;this._triggerClickObserver=t=>{t.composedPath().includes(e)&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._popover?.getAttribute(`open`)===`true`&&this._centerAllColumnsInPopoverBody()})})},document.addEventListener(`click`,this._triggerClickObserver,!0)}}_collectAdornmentNodes(){let e=[...this._prependSlotNodes,...this._appendSlotNodes,...Array.from(this.querySelectorAll(`[slot="prepend"], [slot="append"]`))];this._prependSlotNodes=e.filter(e=>e.getAttribute(`slot`)===`prepend`),this._appendSlotNodes=e.filter(e=>e.getAttribute(`slot`)===`append`)}};customElements.get(`mint-time-picker`)||e.t(`mint-time-picker`,t),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
1
|
+
require(`./icon-B9P0jyS2.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-CfvRRKGZ.js`),require(`./input-BXC4lMG_.js`),require(`./popover-CWWKb7L1.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._triggerId=`mint-time-picker-trigger-${Math.random().toString(36).slice(2,10)}`,this._popover=null,this._popoverObserver=null,this._triggerClickObserver=null,this._inputEl=null,this._hiddenInput=null,this._prependSlotNodes=[],this._appendSlotNodes=[],this._slotObserver=null,this._single={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeStart={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeEnd={hour:5,minute:0,second:0,meridiem:`PM`},this._invalidFromInput=!1}static get observedAttributes(){return[`value`,`inline`,`label`,`info`,`disabled`,`id`,`name`,`required`,`readonly`,`range`,`hours`,`minutes`,`seconds`,`error`,`error-message`]}connectedCallback(){this.classList.add(`mint-time-picker-host`),this._parseAndApplyValue(this.getAttribute(`value`)||``),this.render(),this._slotObserver=new MutationObserver(e=>{e.some(e=>e.type===`attributes`&&e.target.hasAttribute(`slot`)||e.type===`childList`&&e.target===this&&Array.from(e.addedNodes).some(e=>e instanceof HTMLElement&&(e.slot===`prepend`||e.slot===`append`)))&&this.render()}),this._slotObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`slot`]})}disconnectedCallback(){this._slotObserver?.disconnect(),this._slotObserver=null,this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._triggerClickObserver&&=(document.removeEventListener(`click`,this._triggerClickObserver,!0),null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`value`){this._parseAndApplyValue(n||``),this._syncHiddenInput(),this._syncInputValue();{let e=(this._popover||this).querySelector(`[data-mint-time-picker-body="true"]`);e&&this._buildPopoverContent(e)}return}e!==`error`&&e!==`error-message`&&(this._invalidFromInput=!1),this.render()}}get value(){return this.getValue()}set value(e){this.setValue(e||``)}getValue(){return this.getAttribute(`value`)||``}setValue(e){e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this._parseAndApplyValue(e||``),this._syncHiddenInput(),this._syncInputValue()}isRange(){return this.getAttribute(`range`)===`true`}isHoursEnabled(){let e=this.getAttribute(`hours`);return e===null?!0:e!==`false`}isMinutesEnabled(){let e=this.getAttribute(`minutes`);return e===null?!0:e!==`false`}isSecondsEnabled(){let e=this.getAttribute(`seconds`);return e===null?!1:e!==`false`}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasExternalError(){return this.getAttribute(`error`)===`true`}getExternalErrorMessage(){return this.getAttribute(`error-message`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getName(){return this.getAttribute(`name`)||``}_getEffectiveError(){return{hasError:this.hasExternalError(),message:this.getExternalErrorMessage()}}_formatParts(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=[];return t&&i.push(e.hour.toString()),n&&i.push(e.minute.toString().padStart(2,`0`)),r&&i.push(e.second.toString().padStart(2,`0`)),t?`${i.join(`:`)} ${e.meridiem.toLowerCase()}`:i.join(`:`)}_to24Hour(e){let t=e.hour%12;return e.meridiem===`PM`&&(t+=12),{hour:t,minute:e.minute,second:e.second}}_formatParts24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=this._to24Hour(e),a=[];return t&&a.push(i.hour.toString().padStart(2,`0`)),n&&a.push(i.minute.toString().padStart(2,`0`)),r&&a.push(i.second.toString().padStart(2,`0`)),a.join(`:`)}_getDisplayValue(){return this.isRange()?`${this._formatParts(this._rangeStart)} - ${this._formatParts(this._rangeEnd)}`:this._formatParts(this._single)}_getOutputValue(){return this.isRange()?`${this._formatParts24(this._rangeStart)} - ${this._formatParts24(this._rangeEnd)}`:this._formatParts24(this._single)}_getExpectedFormat(){let e=this.isHoursEnabled(),t=this.isMinutesEnabled(),n=this.isSecondsEnabled(),r=[];e&&r.push(`h`),t&&r.push(`mm`),n&&r.push(`ss`);let i=e?`${r.join(`:`)} am/pm`:r.join(`:`);return this.isRange()?`${i} - ${i}`:i}_syncHiddenInput(){this._hiddenInput&&(this._hiddenInput.value=this.getValue()||this._getOutputValue())}_syncInputValue(){this._inputEl&&(this._inputEl.value=this._getDisplayValue(),typeof this._inputEl.render==`function`&&this._inputEl.render())}_emitChangeFromPicker(){let e=this._getOutputValue();this._invalidFromInput=!1,this.setAttribute(`value`,e),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_parseSingle(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?\s*(am|pm)$/i);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0),s=e[4].toUpperCase();return t<1||t>12||n&&(a<0||a>59)||r&&(o<0||o>59)?null:{hour:t,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseSingleOutput24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0);if(t<0||t>23||n&&(a<0||a>59)||r&&(o<0||o>59))return null;let s=t>=12?`PM`:`AM`;return{hour:t%12==0?12:t%12,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseAndApplyValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingleOutput24(t||``),i=this._parseSingleOutput24(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingleOutput24(e);return t?(this._single=t,!0):!1}_parseAndApplyDisplayValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingle(t||``),i=this._parseSingle(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingle(e);return t?(this._single=t,!0):!1}_handleTypedValue(e){let t=e.trim();if(!t){this._invalidFromInput=!1,this.removeAttribute(`value`),this._syncHiddenInput(),this._syncInputValue();return}if(!this._parseAndApplyDisplayValue(t)){this._invalidFromInput=!0,this.removeAttribute(`value`),this._inputEl&&(this._inputEl.value=``),this._syncHiddenInput(),this.render(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}));return}this._invalidFromInput=!1;let n=this._getOutputValue();this.setAttribute(`value`,n),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_buildColumn(e,t,n,r=!0,i=`standard`,a=`Time`){let o=document.createElement(`div`);return o.className=`mint-time-picker-column mint-time-picker-column-${i}${r?` mint-time-picker-column-divider`:``}`,o.setAttribute(`role`,`group`),o.setAttribute(`aria-label`,a),e.forEach(e=>{let r=document.createElement(`button`);r.type=`button`;let i=e===t;r.className=`mint-time-picker-option${i?` is-selected`:``}`,r.dataset.selected=i?`true`:`false`,r.setAttribute(`aria-pressed`,String(i)),r.setAttribute(`aria-label`,`${a}: ${e}`),r.textContent=e,r.addEventListener(`click`,()=>n(e)),o.appendChild(r)}),o}_centerSelectedInColumn(e){let t=e.querySelector(`button[data-selected="true"]`);if(!t)return;let n=t.offsetTop-e.offsetTop-(e.clientHeight/2-t.offsetHeight/2),r=Math.max(0,Math.min(e.scrollHeight-e.clientHeight,n));e.scrollTo({top:r,behavior:`instant`})}_centerAllColumnsInPopoverBody(){let e=(this._popover||this).querySelector(`[data-mint-time-picker-body="true"]`);e&&Array.from(e.querySelectorAll(`.mint-time-picker-column`)).forEach(e=>this._centerSelectedInColumn(e))}_setupPopoverOpenObserver(){this._popover&&(this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._popoverObserver=new MutationObserver(()=>{this._popover?.getAttribute(`open`)===`true`&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:[`open`]}))}_buildPickerSet(e,t,n){let r=this.isHoursEnabled(),i=this.isMinutesEnabled(),a=this.isSecondsEnabled(),o=document.createElement(`div`),s=(r?1:0)+(i?1:0)+(a?1:0)+(r?1:0);o.className=`mint-time-picker-wheel`,o.style.gridTemplateColumns=`repeat(${Math.max(s,1)}, minmax(0, 1fr))`;let c=Array.from({length:12},(e,t)=>(t+1).toString().padStart(2,`0`)),l=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),u=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),d=[`AM`,`PM`],f=[];r&&f.push(this._buildColumn(c,t.hour.toString().padStart(2,`0`),e=>{n({...t,hour:Number(e)})},!0,`tall`,`Hour`)),i&&f.push(this._buildColumn(l,t.minute.toString().padStart(2,`0`),e=>{n({...t,minute:Number(e)})},!0,`tall`,`Minute`)),a&&f.push(this._buildColumn(u,t.second.toString().padStart(2,`0`),e=>{n({...t,second:Number(e)})},!0,`tall`,`Second`)),r&&f.push(this._buildColumn(d,t.meridiem,e=>{n({...t,meridiem:e})},!0,`tall`,`Meridiem`)),f.forEach((e,t)=>{t===f.length-1&&e.classList.remove(`mint-time-picker-column-divider`),o.appendChild(e)}),e.appendChild(o)}_buildPopoverContent(e){if(e.innerHTML=``,!this.isRange()){this._buildPickerSet(e,this._single,t=>{this._single=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)}),requestAnimationFrame(()=>this._centerAllColumnsInPopoverBody());return}let t=document.createElement(`div`);t.className=`mint-time-picker-range`;let n=document.createElement(`div`),r=document.createElement(`mint-text`);r.setAttribute(`variant`,`muted`),r.className=`mint-time-picker-range-label`,r.textContent=`Start`,n.appendChild(r),this._buildPickerSet(n,this._rangeStart,t=>{this._rangeStart=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)});let i=document.createElement(`div`),a=document.createElement(`mint-text`);a.setAttribute(`variant`,`muted`),a.className=`mint-time-picker-range-label`,a.textContent=`End`,i.appendChild(a),this._buildPickerSet(i,this._rangeEnd,t=>{this._rangeEnd=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)}),t.appendChild(n),t.appendChild(i),e.appendChild(t),requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})}render(){let e=this.isDisabled(),t=this.isReadonly(),n=this._getEffectiveError();this._collectAdornmentNodes(),this._triggerClickObserver&&=(document.removeEventListener(`click`,this._triggerClickObserver,!0),null),this.innerHTML=``;let r=document.createElement(`div`);r.className=`mint-time-picker-control`;let i=this.getAttribute(`inline`)===`true`;i||(this._inputEl=document.createElement(`mint-input`),this._inputEl.id=this._triggerId,this._inputEl.classList.add(`mint-time-picker-trigger`),this._inputEl.setAttribute(`type`,`text`),this._inputEl.setAttribute(`icon`,`clock`),this._inputEl.setAttribute(`placeholder`,this._getExpectedFormat()),this._inputEl.setAttribute(`label`,this.getLabel()),this._inputEl.setAttribute(`info`,this.getInfo()),this._inputEl.setAttribute(`value`,this._getDisplayValue()),this._inputEl.setAttribute(`error`,n.hasError?`true`:`false`),this._inputEl.setAttribute(`error-message`,n.message||``),this._prependSlotNodes.forEach(e=>this._inputEl.appendChild(e)),this._appendSlotNodes.forEach(e=>this._inputEl.appendChild(e)),e&&this._inputEl.setAttribute(`disabled`,`true`),t&&this._inputEl.setAttribute(`readonly`,`true`),this._inputEl.addEventListener(`change`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())}),this._inputEl.addEventListener(`blur`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())},!0),r.appendChild(this._inputEl)),this._hiddenInput=document.createElement(`input`),this._hiddenInput.type=`hidden`,this._hiddenInput.name=this.getName(),this._hiddenInput.required=this.isRequired(),r.appendChild(this._hiddenInput),this._syncHiddenInput();let a=document.createElement(`div`);if(a.setAttribute(`data-mint-time-picker-body`,`true`),a.className=`mint-time-picker-popover`,this._buildPopoverContent(a),i?(this._popover=null,r.appendChild(a),requestAnimationFrame(()=>this._centerAllColumnsInPopoverBody())):(this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`trigger-id`,this._triggerId),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`),this._popover.setAttribute(`distance`,`6px`),(e||t)&&this._popover.setAttribute(`open`,`false`),this._popover.appendChild(a),r.appendChild(this._popover),this._setupPopoverOpenObserver()),this.appendChild(r),!i&&this._inputEl){let e=this._inputEl;this._triggerClickObserver=t=>{t.composedPath().includes(e)&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._popover?.getAttribute(`open`)===`true`&&this._centerAllColumnsInPopoverBody()})})},document.addEventListener(`click`,this._triggerClickObserver,!0)}}_collectAdornmentNodes(){let e=[...this._prependSlotNodes,...this._appendSlotNodes,...Array.from(this.querySelectorAll(`[slot="prepend"], [slot="append"]`))];this._prependSlotNodes=e.filter(e=>e.getAttribute(`slot`)===`prepend`),this._appendSlotNodes=e.filter(e=>e.getAttribute(`slot`)===`append`)}};customElements.get(`mint-time-picker`)||e.t(`mint-time-picker`,t),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./icon-
|
|
1
|
+
import "./icon-DAB2KLeo.js";
|
|
2
2
|
import { t as e } from "./register-element-BFYmIynH.js";
|
|
3
3
|
import "./text-C-6UCBp-.js";
|
|
4
|
-
import "./input-
|
|
5
|
-
import "./popover-
|
|
4
|
+
import "./input-B_q63xQu.js";
|
|
5
|
+
import "./popover-DPNBidSz.js";
|
|
6
6
|
//#region src/components/time-picker/TimePicker.ts
|
|
7
7
|
var t = class extends HTMLElement {
|
|
8
8
|
constructor(...e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./icon-
|
|
1
|
+
require(`./icon-B9P0jyS2.js`).a({name:`warning`,viewBox:`0 0 24 24`,path:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z`,strokeLinecap:`round`,strokeLinejoin:`round`});
|
|
@@ -18,5 +18,5 @@ __mintLoadStyle('icon', '../../icon.css')
|
|
|
18
18
|
__mintLoadStyle('text', '../../text.css')
|
|
19
19
|
__mintLoadStyle('stack', '../../stack.css')
|
|
20
20
|
__mintLoadStyle('confirm-action', '../../confirm-action.css')
|
|
21
|
-
import { n as e, t } from "../chunks/confirm-action-
|
|
21
|
+
import { n as e, t } from "../chunks/confirm-action-BW1UwJNu.js";
|
|
22
22
|
export { t as confirm, e as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/confirm-action-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/confirm-action-sovGys0x.js`);exports.confirm=e.t,exports.default=e.n;
|