monobill-mintui 0.6.632 → 0.6.634

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- require(`./icon-B_7c8b8e.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-Cpl5ljSe.js`),require(`./button-DbxqmBWQ.js`),require(`./stack-D1uh4L79.js`);var t=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`]}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(){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`)||``}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();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,this._animateEnter())}else this._renderedOpen&&(this._renderedOpen=!1,this._animateExit());let r=this._modal.querySelector(`.modal-content`);r||(r=document.createElement(`div`),r.className=`modal-content`,this._modal.appendChild(r)),this._header||(this._header=document.createElement(`div`),this._header.className=`mint-modal-header`,r.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 i=this._headingSlot.querySelector(`mint-text`);t?(i||(i=document.createElement(`mint-text`),i.setAttribute(`size`,`sub-heading`),i.setAttribute(`bold`,``),this._headingSlot.appendChild(i)),i.textContent=t):i&&i.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.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`),r.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)}),this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`mint-modal-actions`,this._actionsSlot.setAttribute(`slot`,`actions`),r.appendChild(this._actionsSlot));let a=this._actionsSlot.querySelector(`mint-stack`);a||(a=document.createElement(`mint-stack`),a.setAttribute(`direction`,`horizontal`),a.className=`mint-actions-stack`,this._actionsSlot.appendChild(a)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`).forEach(e=>{Array.from(e.children).forEach(e=>{e.parentElement!==a&&a.appendChild(e)}),e.parentElement&&e.remove()}),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`,requestAnimationFrame(()=>{if(!this.isOpen())return;let t=window.getComputedStyle(e).borderRadius;this._setTransformOrigin(e),e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,e.getBoundingClientRect(),e.style.transition=`opacity 320ms ease-out, transform 360ms cubic-bezier(0.2, 0.8, 0.2, 1), border-radius 360ms cubic-bezier(0.2, 0.8, 0.2, 1)`,requestAnimationFrame(()=>{this.isOpen()&&(e.style.transform=`scale(1)`,e.style.opacity=`1`,e.style.borderRadius=t)})}))}_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}_setTransformOrigin(e){let t=this._findTriggerElement(this._triggerElement);this._triggerElement=t;let n=this._findTriggerPoint(t);if(n){let t=e.getBoundingClientRect();e.style.transformOrigin=`${n.x-t.left}px ${n.y-t.top}px`,this._triggerPoint=n;return}this._triggerPoint={x:window.innerWidth/2,y:0};let r=e.getBoundingClientRect();e.style.transformOrigin=`${this._triggerPoint.x-r.left}px ${this._triggerPoint.y-r.top}px`}_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`);return}this._exitTimer&&clearTimeout(this._exitTimer),this.classList.add(`mint-modal-closing`),e.style.transition=`opacity 220ms ease-in, transform 260ms cubic-bezier(0.4, 0, 1, 1), border-radius 260ms cubic-bezier(0.4, 0, 1, 1)`,e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,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.borderRadius=``,e.style.transition=``)},280)}};typeof customElements<`u`&&!customElements.get(`mint-modal`)&&e.t(`mint-modal`,t),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
1
+ require(`./icon-B_7c8b8e.js`);const e=require(`./register-element-tCL_F1YI.js`);require(`./text-Cpl5ljSe.js`),require(`./button-DbxqmBWQ.js`),require(`./stack-D1uh4L79.js`);var t=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`]}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(){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`)||``}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();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,this._animateEnter())}else this._renderedOpen&&(this._renderedOpen=!1,this._animateExit());let r=this._modal.querySelector(`.modal-content`);r||(r=document.createElement(`div`),r.className=`modal-content`,this._modal.appendChild(r)),this._header||(this._header=document.createElement(`div`),this._header.className=`mint-modal-header`,r.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 i=this._headingSlot.querySelector(`mint-text`);t?(i||(i=document.createElement(`mint-text`),i.setAttribute(`size`,`sub-heading`),i.setAttribute(`bold`,``),this._headingSlot.appendChild(i)),i.textContent=t):i&&i.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.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`),r.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)}),this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`mint-modal-actions`,this._actionsSlot.setAttribute(`slot`,`actions`),r.appendChild(this._actionsSlot));let a=this._actionsSlot.querySelector(`mint-stack`);a||(a=document.createElement(`mint-stack`),a.setAttribute(`direction`,`horizontal`),a.className=`mint-actions-stack`,this._actionsSlot.appendChild(a)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._modal&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`).forEach(e=>{Array.from(e.children).forEach(e=>{e.parentElement!==a&&a.appendChild(e)}),e.parentElement&&e.remove()}),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`,requestAnimationFrame(()=>{if(!this.isOpen())return;let t=window.getComputedStyle(e).borderRadius;this._setTransformOrigin(e),e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,e.getBoundingClientRect(),e.style.transition=`opacity 320ms ease-out, transform 360ms cubic-bezier(0.2, 0.8, 0.2, 1), border-radius 360ms cubic-bezier(0.2, 0.8, 0.2, 1)`,requestAnimationFrame(()=>{this.isOpen()&&(e.style.transform=`scale(1)`,e.style.opacity=`1`,e.style.borderRadius=t,window.setTimeout(()=>{this.isOpen()&&(e.style.transition=``,e.style.transform=`none`)},380))})}))}_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}_setTransformOrigin(e){let t=this._findTriggerElement(this._triggerElement);this._triggerElement=t;let n=this._findTriggerPoint(t);if(n){let t=e.getBoundingClientRect();e.style.transformOrigin=`${n.x-t.left}px ${n.y-t.top}px`,this._triggerPoint=n;return}this._triggerPoint={x:window.innerWidth/2,y:0};let r=e.getBoundingClientRect();e.style.transformOrigin=`${this._triggerPoint.x-r.left}px ${this._triggerPoint.y-r.top}px`}_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`);return}this._exitTimer&&clearTimeout(this._exitTimer),this.classList.add(`mint-modal-closing`),e.style.transition=`opacity 220ms ease-in, transform 260ms cubic-bezier(0.4, 0, 1, 1), border-radius 260ms cubic-bezier(0.4, 0, 1, 1)`,e.style.borderRadius=`50%`,e.style.transform=`scale(0.1, 0.2)`,e.style.opacity=`0.9`,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.borderRadius=``,e.style.transition=``)},280)}};typeof customElements<`u`&&!customElements.get(`mint-modal`)&&e.t(`mint-modal`,t),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
@@ -92,7 +92,9 @@ var t = class extends HTMLElement {
92
92
  if (!this.isOpen()) return;
93
93
  let t = window.getComputedStyle(e).borderRadius;
94
94
  this._setTransformOrigin(e), e.style.borderRadius = "50%", e.style.transform = "scale(0.1, 0.2)", e.style.opacity = "0.9", e.getBoundingClientRect(), e.style.transition = "opacity 320ms ease-out, transform 360ms cubic-bezier(0.2, 0.8, 0.2, 1), border-radius 360ms cubic-bezier(0.2, 0.8, 0.2, 1)", requestAnimationFrame(() => {
95
- this.isOpen() && (e.style.transform = "scale(1)", e.style.opacity = "1", e.style.borderRadius = t);
95
+ this.isOpen() && (e.style.transform = "scale(1)", e.style.opacity = "1", e.style.borderRadius = t, window.setTimeout(() => {
96
+ this.isOpen() && (e.style.transition = "", e.style.transform = "none");
97
+ }, 380));
96
98
  });
97
99
  }));
98
100
  }
@@ -21,7 +21,7 @@ __mintLoadStyle('confirm-action', '../../confirm-action.css')
21
21
  import { t as e } from "../chunks/register-element-BFYmIynH.js";
22
22
  import "../chunks/text-Bmfl6CxJ.js";
23
23
  import "../chunks/button-BYQbRAwl.js";
24
- import "../chunks/modal-CPcIPIO7.js";
24
+ import "../chunks/modal-DKNBqbQD.js";
25
25
  //#region src/components/confirm-action/ConfirmAction.ts
26
26
  var t = class extends HTMLElement {
27
27
  constructor(...e) {
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/text-Cpl5ljSe.js`),require(`../chunks/button-DbxqmBWQ.js`),require(`../chunks/modal-CNBmdA63.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._modal=null,this._actionsFooter=null,this._confirmButton=null,this._cancelButton=null,this._pendingResolve=null,this._modalObserver=null,this._lastAction=null,this._onConfirmClick=null,this._onCancelClick=null}connectedCallback(){this._ensureModal(),this._observeModalOpenState()}disconnectedCallback(){this._modalObserver&&=(this._modalObserver.disconnect(),null),this._pendingResolve=null}async showConfirm(e){if(this._ensureModal(),!this._modal||!this._confirmButton||!this._cancelButton)return!1;let t=e.question?.trim()||`Are you sure?`,n=e.tone||`action`,r=e.confirmLabel?.trim()||`Confirm`,i=e.cancelLabel?.trim()||`Cancel`;this._lastAction=null,this._modal.setAttribute(`heading`,t),this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-${n} mint-confirm-action-confirm`,this._confirmButton.textContent=r,this._cancelButton.textContent=i;let a=new Promise(e=>{this._pendingResolve=e});return requestAnimationFrame(()=>{this._modal.open?.(),this._mountActionsFooter()}),a}_ensureModal(){this._modal||(this._modal=document.createElement(`mint-modal`),this._modal.setAttribute(`heading`,`Are you sure?`),this._modal.setAttribute(`size`,`small`),this._modal.setAttribute(`hide-close-button`,``),this._cancelButton=document.createElement(`button`),this._cancelButton.type=`button`,this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._cancelButton.textContent=`Cancel`,this._confirmButton=document.createElement(`button`),this._confirmButton.type=`button`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-action mint-confirm-action-confirm`,this._confirmButton.textContent=`Confirm`,this._actionsFooter=document.createElement(`div`),this._actionsFooter.className=`mint-confirm-action-footer`,this._actionsFooter.append(this._cancelButton,this._confirmButton),this._onCancelClick=()=>{this._lastAction=`cancel`,this._modal?.close?.()},this._onConfirmClick=()=>{this._lastAction=`confirm`,this._modal?.close?.()},this._cancelButton.addEventListener(`click`,this._onCancelClick),this._confirmButton.addEventListener(`click`,this._onConfirmClick),this.appendChild(this._modal))}_mountActionsFooter(){let e=this._modal?.querySelector(`.modal-content`);!e||!this._actionsFooter||(e.querySelectorAll(`:scope > [slot="body"], :scope > [slot="actions"]`).forEach(e=>{!e.textContent?.trim()&&!e.querySelector(`button, mint-button, a, input, select, textarea`)&&e.remove()}),this._actionsFooter.parentElement!==e&&e.appendChild(this._actionsFooter))}_observeModalOpenState(){!this._modal||this._modalObserver||(this._modalObserver=new MutationObserver(()=>{if((this._modal?.hasAttribute(`open`)??!1)||!this._pendingResolve)return;let e=this._pendingResolve;this._pendingResolve=null;let t=this._lastAction===`confirm`;this._lastAction=null,e(t)}),this._modalObserver.observe(this._modal,{attributes:!0,attributeFilter:[`open`]}))}};customElements.get(`mint-confirm-action`)||e.t(`mint-confirm-action`,t);var n=[],r=!1;function i(){return typeof document>`u`||document.body?Promise.resolve():new Promise(e=>{if(typeof window>`u`){e();return}window.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0})})}async function a(){if(await i(),typeof document>`u`)throw Error(`mintui.confirm is only available in browser environments.`);let e=document.querySelector(`mint-confirm-action[data-mint-confirm-action-root="true"]`);if(e)return e;let t=document.createElement(`mint-confirm-action`);return t.setAttribute(`data-mint-confirm-action-root`,`true`),document.body.appendChild(t),t}function o(e){let t=(e||`action`).toString().trim().toLowerCase().replace(/^tone:\s*/,``);return t===`action`||t===`info`||t===`warning`||t===`danger`?t:`action`}async function s(){if(!r){r=!0;try{for(;n.length>0;){let e=n.shift();e&&(await(await a()).showConfirm({question:e.question,tone:o(e.tone),confirmLabel:e.confirmLabel||`Confirm`,cancelLabel:e.cancelLabel||`Cancel`})?e.confirmed?.():e.cancelled?.())}}finally{r=!1}}}function c(e,t,r,i=`action`,a=`Confirm`,o=`Cancel`){typeof window>`u`||(n.push({question:e,confirmed:t,cancelled:r,tone:i,confirmLabel:a,cancelLabel:o}),s())}if(typeof window<`u`){let e=window.mintui||{};e.confirm=c,window.mintui=e}exports.confirm=c,exports.default=t;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/text-Cpl5ljSe.js`),require(`../chunks/button-DbxqmBWQ.js`),require(`../chunks/modal-BZ-VwNkW.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._modal=null,this._actionsFooter=null,this._confirmButton=null,this._cancelButton=null,this._pendingResolve=null,this._modalObserver=null,this._lastAction=null,this._onConfirmClick=null,this._onCancelClick=null}connectedCallback(){this._ensureModal(),this._observeModalOpenState()}disconnectedCallback(){this._modalObserver&&=(this._modalObserver.disconnect(),null),this._pendingResolve=null}async showConfirm(e){if(this._ensureModal(),!this._modal||!this._confirmButton||!this._cancelButton)return!1;let t=e.question?.trim()||`Are you sure?`,n=e.tone||`action`,r=e.confirmLabel?.trim()||`Confirm`,i=e.cancelLabel?.trim()||`Cancel`;this._lastAction=null,this._modal.setAttribute(`heading`,t),this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-${n} mint-confirm-action-confirm`,this._confirmButton.textContent=r,this._cancelButton.textContent=i;let a=new Promise(e=>{this._pendingResolve=e});return requestAnimationFrame(()=>{this._modal.open?.(),this._mountActionsFooter()}),a}_ensureModal(){this._modal||(this._modal=document.createElement(`mint-modal`),this._modal.setAttribute(`heading`,`Are you sure?`),this._modal.setAttribute(`size`,`small`),this._modal.setAttribute(`hide-close-button`,``),this._cancelButton=document.createElement(`button`),this._cancelButton.type=`button`,this._cancelButton.className=`mint-button-core mint-button-ghost mint-button-tone-neutral mint-confirm-action-cancel`,this._cancelButton.textContent=`Cancel`,this._confirmButton=document.createElement(`button`),this._confirmButton.type=`button`,this._confirmButton.className=`mint-button-core mint-button-solid mint-button-tone-action mint-confirm-action-confirm`,this._confirmButton.textContent=`Confirm`,this._actionsFooter=document.createElement(`div`),this._actionsFooter.className=`mint-confirm-action-footer`,this._actionsFooter.append(this._cancelButton,this._confirmButton),this._onCancelClick=()=>{this._lastAction=`cancel`,this._modal?.close?.()},this._onConfirmClick=()=>{this._lastAction=`confirm`,this._modal?.close?.()},this._cancelButton.addEventListener(`click`,this._onCancelClick),this._confirmButton.addEventListener(`click`,this._onConfirmClick),this.appendChild(this._modal))}_mountActionsFooter(){let e=this._modal?.querySelector(`.modal-content`);!e||!this._actionsFooter||(e.querySelectorAll(`:scope > [slot="body"], :scope > [slot="actions"]`).forEach(e=>{!e.textContent?.trim()&&!e.querySelector(`button, mint-button, a, input, select, textarea`)&&e.remove()}),this._actionsFooter.parentElement!==e&&e.appendChild(this._actionsFooter))}_observeModalOpenState(){!this._modal||this._modalObserver||(this._modalObserver=new MutationObserver(()=>{if((this._modal?.hasAttribute(`open`)??!1)||!this._pendingResolve)return;let e=this._pendingResolve;this._pendingResolve=null;let t=this._lastAction===`confirm`;this._lastAction=null,e(t)}),this._modalObserver.observe(this._modal,{attributes:!0,attributeFilter:[`open`]}))}};customElements.get(`mint-confirm-action`)||e.t(`mint-confirm-action`,t);var n=[],r=!1;function i(){return typeof document>`u`||document.body?Promise.resolve():new Promise(e=>{if(typeof window>`u`){e();return}window.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0})})}async function a(){if(await i(),typeof document>`u`)throw Error(`mintui.confirm is only available in browser environments.`);let e=document.querySelector(`mint-confirm-action[data-mint-confirm-action-root="true"]`);if(e)return e;let t=document.createElement(`mint-confirm-action`);return t.setAttribute(`data-mint-confirm-action-root`,`true`),document.body.appendChild(t),t}function o(e){let t=(e||`action`).toString().trim().toLowerCase().replace(/^tone:\s*/,``);return t===`action`||t===`info`||t===`warning`||t===`danger`?t:`action`}async function s(){if(!r){r=!0;try{for(;n.length>0;){let e=n.shift();e&&(await(await a()).showConfirm({question:e.question,tone:o(e.tone),confirmLabel:e.confirmLabel||`Confirm`,cancelLabel:e.cancelLabel||`Cancel`})?e.confirmed?.():e.cancelled?.())}}finally{r=!1}}}function c(e,t,r,i=`action`,a=`Confirm`,o=`Cancel`){typeof window>`u`||(n.push({question:e,confirmed:t,cancelled:r,tone:i,confirmLabel:a,cancelLabel:o}),s())}if(typeof window<`u`){let e=window.mintui||{};e.confirm=c,window.mintui=e}exports.confirm=c,exports.default=t;
@@ -9,7 +9,7 @@ import '../../confirm-action.css'
9
9
  import { t as e } from "../chunks/register-element-BFYmIynH.js";
10
10
  import "../chunks/text-Bmfl6CxJ.js";
11
11
  import "../chunks/button-BYQbRAwl.js";
12
- import "../chunks/modal-CPcIPIO7.js";
12
+ import "../chunks/modal-DKNBqbQD.js";
13
13
  //#region src/components/confirm-action/ConfirmAction.ts
14
14
  var t = class extends HTMLElement {
15
15
  constructor(...e) {
@@ -383,12 +383,12 @@ var t = class extends HTMLElement {
383
383
  for (let n of t) {
384
384
  let t = this._getFieldElements(n).filter((e) => !this._isControlDisabledForSubmit(e));
385
385
  if (t.length !== 0) try {
386
- let r = this._extractFieldValue(t), i = r instanceof FileList ? Array.from(r) : r;
387
- if (t.every((e) => e instanceof HTMLInputElement ? e.type === "checkbox" || e.type === "radio" : [
386
+ let r = this._extractFieldValue(t), i = r instanceof FileList ? Array.from(r) : r, a = (e) => e instanceof HTMLInputElement ? e.type === "checkbox" || e.type === "radio" : [
388
387
  "MINT-CHECKBOX",
389
388
  "MINT-CHOICE",
390
389
  "MINT-SWITCH"
391
- ].includes(e.tagName)) && (i === "" || i == null || Array.isArray(i) && i.length === 0)) continue;
390
+ ].includes(e.tagName), o = t.length === 1 && ["MINT-CHECKBOX", "MINT-SWITCH"].includes(t[0].tagName);
391
+ if (t.every(a) && !o && (i === "" || i == null || Array.isArray(i) && i.length === 0)) continue;
392
392
  e[n] = i;
393
393
  } catch {}
394
394
  }
@@ -429,7 +429,7 @@ var t = class extends HTMLElement {
429
429
  let [t, r] = n.split(":");
430
430
  switch (t) {
431
431
  case "required":
432
- if (e == null || typeof e == "string" && e.trim() === "" || e instanceof FileList && e.length === 0 || Array.isArray(e) && e.length === 0) return "This field is required.";
432
+ if (e == null || e === !1 || typeof e == "string" && e.trim() === "" || e instanceof FileList && e.length === 0 || Array.isArray(e) && e.length === 0) return "This field is required.";
433
433
  break;
434
434
  case "string":
435
435
  if (typeof e != "string") return "Must be a string.";
@@ -527,7 +527,7 @@ var t = class extends HTMLElement {
527
527
  let e = null;
528
528
  return n.tags === void 0 ? typeof n.getTags == "function" && (e = n.getTags()) : e = n.tags, Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : e?.value || e?.label || "").filter((e) => e.trim() !== "") : [];
529
529
  }
530
- return n.tagName === "MINT-CHECKBOX" || n.tagName === "MINT-SWITCH" ? (n.checked === void 0 ? n.hasAttribute("checked") : n.checked) ? n.getAttribute("value") || "on" : "" : n.tagName === "MINT-CHOICE" ? (typeof n.getValue == "function" ? n.getValue() : "") || "" : n.value === void 0 ? n.getAttribute("value") || "" : n.value;
530
+ return n.tagName === "MINT-CHECKBOX" || n.tagName === "MINT-SWITCH" ? !!(n.checked === void 0 ? n.hasAttribute("checked") : n.checked) : n.tagName === "MINT-CHOICE" ? (typeof n.getValue == "function" ? n.getValue() : "") || "" : n.value === void 0 ? n.getAttribute("value") || "" : n.value;
531
531
  }
532
532
  _flagFieldError(e, t) {
533
533
  e.length !== 0 && e.forEach((e) => {
@@ -665,8 +665,8 @@ var t = class extends HTMLElement {
665
665
  }
666
666
  } catch {}
667
667
  e.tags !== void 0 && (e.tags = n.map((e) => {
668
- if (typeof e == "string") {
669
- let n = e.trim();
668
+ if (typeof e == "string" || typeof e == "number") {
669
+ let n = String(e).trim();
670
670
  return {
671
671
  value: n,
672
672
  label: t.get(n.toLowerCase()) || n,
@@ -1 +1 @@
1
- const e=require(`../chunks/register-element-tCL_F1YI.js`);var t=class extends HTMLElement{static get observedAttributes(){return[`action`,`method`,`enctype`,`data-form-data`,`loading`,`headers`,`submitting`]}constructor(){super(),this._form=null,this._submitHandler=null,this._hostSubmitHandler=null,this._errors={},this._fieldBlurHandlers=new Map,this._fieldChangeHandlers=new Map,this._observer=null,this._formData=null,this._headers=null,this._buttonStates=new Map,this._attrSubmittingMintFields=new Map,this._attrSubmittingNativeFields=new Map,this._attrSubmittingMintButtons=new Map,this._attrSubmittingNativeButtons=new Map,this._reactiveDataProxy=null,this._reactiveDataObserver=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}connectedCallback(){this._render(),this._ensureSubmitHandler(),this._setupBlurValidation();let e=this.getAttribute(`headers`);e&&this._parseHeaders(e),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(this._formData)this._isReactiveObject(this._formData)?this._setupObjectDataObserver(this._formData):this._lastDataSnapshot||=this._createDataSnapshot(this._formData),this._applyFormData();else{let e=this.getAttribute(`data-form-data`);e&&(this._parseFormData(e),this._applyFormData())}this._propagateLoadingState(),this._applySubmittingAttributeState()})})}disconnectedCallback(){this._form&&this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._hostSubmitHandler&&this.removeEventListener(`submit`,this._hostSubmitHandler),this._restoreSubmittingAttributeState(),this._cleanupBlurValidation(),this._stopReactiveDataObserver()}reset(){this._clearErrors(),this._formData?(this._lastAppliedDataSnapshot=null,this._applyFormData()):this.clear()}clear(){this._clearErrors(),this._form&&this._form.reset(),this._resetCustomFields()}submit(){if(this._form){if(typeof this._form.requestSubmit==`function`){this._form.requestSubmit();return}this._handleSubmit(new Event(`submit`,{bubbles:!0,cancelable:!0}))}}attributeChangedCallback(e,t,n){e===`form-data`?(this._parseFormData(n),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})):e===`headers`?this._parseHeaders(n):e===`loading`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._propagateLoadingState()}):this._propagateLoadingState():e===`submitting`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._applySubmittingAttributeState()}):this._applySubmittingAttributeState():this._applyFormAttributes()}get data(){return this._formData}set data(e){this._stopReactiveDataObserver(),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null,e&&typeof e==`object`&&!Array.isArray(e)?(this._formData=e,this._isReactiveObject(e)?this._setupObjectDataObserver(e):this._lastDataSnapshot=this._createDataSnapshot(e)):e==null?this._formData=null:this._parseFormData(e),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})})}get headers(){return this._headers}set headers(e){if(e&&typeof e==`object`&&!Array.isArray(e))this._headers=e;else if(e==null)this._headers=null;else if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_render(){if(this.classList.add(`mint-form-host`),!this._form){for(this._form=document.createElement(`form`),this._form.classList.add(`mint-form-content`),this._form.noValidate=!0;this.firstChild;)this._form.appendChild(this.firstChild);this.appendChild(this._form)}this._ensureSubmitHandler(),this._applyFormAttributes()}_ensureSubmitHandler(){this._form&&(this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._submitHandler=e=>{e.preventDefault(),e.stopImmediatePropagation(),this._handleSubmit(e)},this._form.addEventListener(`submit`,this._submitHandler,!0))}_applyFormAttributes(){if(!this._form)return;let e=this.getAttribute(`action`)||``,t=this.getAttribute(`method`)||``,n=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;e&&(this._form.action=e),t&&(this._form.method=t),this._form.enctype=n}async _handleSubmit(e){if(e.preventDefault(),!this._form)return;this._clearErrors(),this._syncDropzoneFiles();let t=this._collectValidationRules(),n=new FormData(this._form),r=this._formDataToValues(n);if(this._formData){let e=this._getObjectValue(this._formData);e&&typeof e==`object`&&!Array.isArray(e)&&(r={...this._extractReactiveData(e),...r})}let i=this._collectLiveControlValues();if(r={...r,...i},!this._validate(r,t)){this.dispatchEvent(new CustomEvent(`invalid`,{detail:{errors:this._errors},bubbles:!0,cancelable:!0,composed:!0}));return}let a=new CustomEvent(`submit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),a.form=this;let o=new CustomEvent(`mintFormSubmit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});if(o.form=this,this.dispatchEvent(o),a.defaultPrevented||o.defaultPrevented)return;let s=this.getAttribute(`action`),c=this.getAttribute(`method`);if(!(!s||!c)){this._setButtonsSubmitting();try{let e=await this._submitData(n,r);this.dispatchEvent(new CustomEvent(`submitsuccess`,{detail:e,bubbles:!0,cancelable:!0}))}catch(e){e?.status===422&&e?.data?.errors&&this._applyServerErrors(e.data.errors),this.dispatchEvent(new CustomEvent(`submiterror`,{detail:{error:e},bubbles:!0,cancelable:!0}))}finally{this._restoreButtonsState()}}}async _submitData(e,t){let n=this.getAttribute(`action`),r=this.getAttribute(`method`),i=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;if(!n)return{status:0,ok:!0,data:{values:t}};let a=Array.from(e.values()).some(e=>e instanceof File),o=null,s={},c=n;if(typeof window<`u`&&window.mintForm?.defaults?.headers?.common&&Object.assign(s,window.mintForm.defaults.headers.common),this._headers&&Object.assign(s,this._headers),r===`GET`){let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),c+=(n.includes(`?`)?`&`:`?`)+t.toString()}else if(i===`multipart/form-data`||a)o=e;else if(i===`application/json`)o=JSON.stringify(t),s[`Content-Type`]=`application/json`;else{let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),o=t,s[`Content-Type`]=`application/x-www-form-urlencoded`}if(typeof fetch==`function`)try{let e=await fetch(c,{method:r||`POST`,body:r===`GET`?null:o,headers:s}),t=await e.text().catch(()=>``),n=t;try{n=JSON.parse(t)}catch{}if(!e.ok){let t={status:e.status,data:n,response:{status:e.status,data:n}};throw await this._applyErrorInterceptors(t)}let i={status:e.status,ok:e.ok,data:n};return await this._applySuccessInterceptors(i)}catch(e){if(e.response)throw e;let t={status:e.status||0,data:e.data||e.message||`Network error`,response:{status:e.status||0,data:e.data||e.message||`Network error`}};throw await this._applyErrorInterceptors(t)}let l=this;return await new Promise(async(e,t)=>{let n=new XMLHttpRequest;n.open(r||`POST`,c,!0),Object.entries(s).forEach(([e,t])=>n.setRequestHeader(e,t)),n.onload=async function(){let{status:r,responseText:i}=n;if(r>=200&&r<300){let n=i;try{n=JSON.parse(i)}catch{}try{let t={status:r,ok:!0,data:n};e(await l._applySuccessInterceptors(t))}catch(e){t(e)}}else{let e=i;try{e=JSON.parse(i)}catch{}try{let n={status:r,data:e,response:{status:r,data:e}};t(await l._applyErrorInterceptors(n))}catch(e){t(e)}}},n.onerror=async function(){try{let e={status:n.status||0,data:n.responseText||`Network error`,response:{status:n.status||0,data:n.responseText||`Network error`}};t(await l._applyErrorInterceptors(e))}catch(e){t(e)}},n.send(r===`GET`?null:o)})}async _applySuccessInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return e;let t=e,n=window.mintForm.interceptors.response.handlers;for(let e of n)e.fulfilled&&(t=await e.fulfilled(t));return t}async _applyErrorInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return Promise.reject(e);let t=e,n=window.mintForm.interceptors.response.handlers;for(let e=n.length-1;e>=0;e--){let r=n[e];if(r.rejected)try{if(t=await r.rejected(t),t!==void 0)return t}catch(e){t=e}}return Promise.reject(t)}_formDataToValues(e){let t={};return e.forEach((e,n)=>{e instanceof File?(t[n]||(t[n]=[]),t[n].push(e)):n in t?Array.isArray(t[n])?(t[n].length>0&&t[n][0]instanceof File,t[n].push(e)):t[n]=[t[n],e]:t[n]=e}),this._form&&(Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n&&e.files!==void 0&&e.files){let r=e.files;if(r.length>0){let e=Array.from(r);t[n]&&Array.isArray(t[n])?e.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=e}}}),Array.from(this._form.querySelectorAll(`input[type="file"][name]`)).forEach(e=>{let n=e.name;if(n&&e.files&&e.files.length>0){let r=Array.from(e.files);t[n]&&Array.isArray(t[n])?r.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=r}}),Array.from(this._form.querySelectorAll(`mint-tags[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n){let r=[];e.tags===void 0?typeof e.getTags==`function`&&(r=e.getTags()):r=e.tags,Array.isArray(r)&&r.length>0?t[n]=r.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):t[n]=[]}})),t}_isControlDisabledForSubmit(e){let t=e;for(;t&&t!==this._form;){if((t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLButtonElement)&&t.disabled)return!0;let e=t.getAttribute(`disabled`);if(e!==null&&e!==`false`)return!0;t=t.parentElement}return!1}_collectLiveControlValues(){let e={};if(!this._form)return e;let t=new Set,n=Array.from(this._form.querySelectorAll([`input[name]`,`textarea[name]`,`select[name]`,`mint-input[name]`,`mint-select[name]`,`mint-date-picker[name]`,`mint-time-picker[name]`,`mint-dropzone[name]`,`mint-checkbox[name]`,`mint-choice[name]`,`mint-switch[name]`,`mint-tags[name]`].join(`,`)));for(let e of n){let n=e.getAttribute(`name`);!n||this._isControlDisabledForSubmit(e)||t.add(n)}for(let n of t){let t=this._getFieldElements(n).filter(e=>!this._isControlDisabledForSubmit(e));if(t.length!==0)try{let r=this._extractFieldValue(t),i=r instanceof FileList?Array.from(r):r;if(t.every(e=>e instanceof HTMLInputElement?e.type===`checkbox`||e.type===`radio`:[`MINT-CHECKBOX`,`MINT-CHOICE`,`MINT-SWITCH`].includes(e.tagName))&&(i===``||i==null||Array.isArray(i)&&i.length===0))continue;e[n]=i}catch{}}return e}_collectValidationRules(){let e={};return this._form&&Array.from(this._form.querySelectorAll(`[name][validation]`)).forEach(t=>{let n=t.getAttribute(`name`)||``,r=t.getAttribute(`validation`);if(!n||!r)return;let i=this._parseRules(r);i.length&&(e[n]=i)}),e}_parseRules(e){if(!e)return[];try{let t=e.replace(/'/g,`"`),n=JSON.parse(t);if(Array.isArray(n))return n.map(e=>String(e))}catch{}return e.split(`,`).map(e=>e.trim()).filter(Boolean)}_validate(e,t){let n=!0;return this._errors={},Object.entries(t||{}).forEach(([e,t])=>{let r=Array.isArray(t)?t:[t],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(n=!1,this._errors[e]=o,this._flagFieldError(i,o)):this._clearFieldError(i)}),n}_validateField(e){let t=this._collectValidationRules();if(!t[e])return;let n=t[e],r=Array.isArray(n)?n:[n],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(this._errors[e]=o,this._flagFieldError(i,o)):(this._clearFieldError(i),delete this._errors[e])}_validateRules(e,t){for(let n of t){let[t,r]=n.split(`:`);switch(t){case`required`:if(e==null||typeof e==`string`&&e.trim()===``||e instanceof FileList&&e.length===0||Array.isArray(e)&&e.length===0)return`This field is required.`;break;case`string`:if(typeof e!=`string`)return`Must be a string.`;break;case`email`:if(typeof e==`string`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()))return`Enter a valid email.`;break;case`number`:{let t=Number(e);if(Number.isNaN(t))return`Must be a number.`;break}case`min`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length<t)return`Must be at least ${t} characters.`;if(Array.isArray(e)&&e.length<t)return`Select at least ${t}.`;if(e instanceof FileList&&e.length<t)return`Upload at least ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)<t)return`Must be at least ${t}.`;break}case`max`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length>t)return`Must be at most ${t} characters.`;if(Array.isArray(e)&&e.length>t)return`Select no more than ${t}.`;if(e instanceof FileList&&e.length>t)return`Upload no more than ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)>t)return`Must be at most ${t}.`;break}default:break}}return null}_getFieldElements(e){if(!this._form)return[];let t=Array.from(this._form.querySelectorAll(`[name="${e}"]`)),n=t.filter(e=>e.tagName===`MINT-SELECT`);if(n.length>0){let r=[];return n.forEach(t=>{let n=t.querySelector(`select[name="`+e+`"]`);n&&r.push(n)}),t.filter(e=>e.tagName!==`MINT-SELECT`).concat(r)}if(t.filter(e=>e.tagName===`MINT-TAGS`).length>0)return t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`));let r=t.filter(e=>e.tagName===`INPUT`&&e.closest(`mint-tags`));if(r.length>0){let e=[];return r.forEach(t=>{let n=t.closest(`mint-tags`);n&&!e.includes(n)&&e.push(n)}),t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`)).concat(e)}return t}_extractFieldValue(e){if(e.length===0)return``;let t=e.find(e=>e instanceof HTMLSelectElement);if(t)return t.multiple?Array.from(t.selectedOptions).map(e=>e.value):t.value;if(e.length>1){let t=e.filter(e=>e instanceof HTMLInputElement);if(t.length>0&&t.length===e.length){let e=t.filter(e=>e.checked);if(t.every(e=>e.type===`radio`))return e.length>0?e[0].value||`on`:``;if(t.every(e=>e.type===`checkbox`))return e.map(e=>e.value||`on`)}let n=e.filter(e=>e.tagName===`MINT-CHOICE`);if(n.length>0&&n.length===e.length){let e=n.find(e=>typeof e.getValue==`function`?e.getValue()!==``:e.querySelector(`mint-choice-option[checked]`)!==null);if(e){if(typeof e.getValue==`function`)return e.getValue();let t=e.querySelector(`mint-choice-option[checked]`);if(t)return t.getAttribute(`value`)||``}return``}let r=e.filter(e=>e.tagName===`MINT-CHECKBOX`);if(r.length>0&&r.length===e.length)return r.filter(e=>e.checked===void 0?e.hasAttribute(`checked`):e.checked).map(e=>e.getAttribute(`value`)||`on`)}let n=e[0];if(n instanceof HTMLInputElement)return n.type===`file`?n.files:n.type===`checkbox`||n.type===`radio`?n.checked?n.value||`on`:``:n.value;if(n instanceof HTMLTextAreaElement)return n.value;if(n.tagName===`MINT-SELECT`){let e=n.querySelector(`select`);if(e)return e.multiple?Array.from(e.selectedOptions).map(e=>e.value):e.value;if(typeof n.getValue==`function`){let e=n.getValue();if(e!=null&&e!==``)return e}return n.getAttribute(`value`)||``}if(n.tagName===`MINT-DROPZONE`&&n.files!==void 0)return n.files;if(n.tagName===`MINT-TAGS`){let e=null;return n.tags===void 0?typeof n.getTags==`function`&&(e=n.getTags()):e=n.tags,Array.isArray(e)?e.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):[]}return n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`?(n.checked===void 0?n.hasAttribute(`checked`):n.checked)?n.getAttribute(`value`)||`on`:``:n.tagName===`MINT-CHOICE`?(typeof n.getValue==`function`?n.getValue():``)||``:n.value===void 0?n.getAttribute(`value`)||``:n.value}_flagFieldError(e,t){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.setAttribute(`aria-invalid`,`true`);let n=this._resolveHost(e);n&&(n.setAttribute(`error`,`true`),n.setAttribute(`error-message`,t),n.setAttribute(`data-mint-form-error`,`true`))})}_clearFieldError(e){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.removeAttribute(`aria-invalid`);let t=this._resolveHost(e);t&&(t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`))})}_clearErrors(){this.querySelectorAll(`[data-mint-form-error]`).forEach(e=>{let t=e;t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`)}),this._form&&this._form.querySelectorAll(`[aria-invalid="true"]`).forEach(e=>{e.removeAttribute(`aria-invalid`)}),this._errors={}}setFormErrors(e){this._applyServerErrors(e)}_applyServerErrors(e){this._clearErrors(),Object.entries(e).forEach(([e,t])=>{let n=Array.isArray(t)?t[0]||`Validation error`:t||`Validation error`,r=this._getFieldElements(e);r.length>0&&(this._errors[e]=n,this._flagFieldError(r,n))})}_parseFormData(e){if(!e){this._formData=null;return}if(typeof e==`object`&&!Array.isArray(e)){this._formData=e;return}if(typeof e==`string`)try{this._formData=JSON.parse(e)}catch{this._formData=null}else this._formData=null}_parseHeaders(e){if(!e){this._headers=null;return}if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_applyFormData(){if(!this._formData||!this._form)return;let e=this._getObjectValue(this._formData);if(!e||typeof e!=`object`||Array.isArray(e))return;let t=this._extractReactiveData(e),n=this._createDataSnapshot(t),r=this._lastAppliedDataSnapshot,i=new Set;if(r?(Object.keys(n).forEach(e=>{let t=r[e],a=n[e];JSON.stringify(t)!==JSON.stringify(a)&&i.add(e)}),Object.keys(r).forEach(e=>{e in n||i.add(e)})):Object.keys(n).forEach(e=>i.add(e)),i.size===0)return;let a=()=>{i.forEach(e=>{let t=n[e],r=this._getFieldElements(e);if(r.length===0){setTimeout(()=>{let t=this._getFieldElements(e);if(t.length===0)return;let n=this._formData?this._getObjectValue(this._formData):null;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[e];this._applyValueToField(t,e,r)},300);return}this._applyValueToField(r,e,t)}),this._lastAppliedDataSnapshot=n};requestAnimationFrame(()=>{requestAnimationFrame(()=>{a()})})}_applyValueToField(e,t,n){e.forEach(e=>{let r=e.tagName;try{if(r===`MINT-INPUT`)e.value!==void 0&&(e.value=n||``);else if(r===`MINT-DATE-PICKER`)typeof e.setValue==`function`&&e.setValue(n||``);else if(r===`MINT-TIME-PICKER`)typeof e.setValue==`function`?e.setValue(n==null?``:String(n)):e.value!==void 0&&(e.value=n==null?``:String(n));else if(r===`MINT-SELECT`||r===`SELECT`)if(r===`SELECT`){let t=e,r=t.closest(`mint-select`);if(r&&typeof r.setValue==`function`)r.setValue(n);else if(t.multiple){let e=Array.isArray(n)?n.map(e=>String(e)):n==null||n===``?[]:[String(n)];Array.from(t.options).forEach(t=>{t.selected=e.includes(t.value)})}else t.value=n==null?``:String(n)}else typeof e.setValue==`function`&&e.setValue(n);else if(r===`MINT-CHOICE`)typeof e.setValue==`function`?e.setValue(n==null?``:String(n)):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=e.getAttribute(`value`)===n});else if(r===`MINT-CHECKBOX`||r===`MINT-SWITCH`){let t=n===!0||n===`true`||n===`on`||n===1||n===`1`;e.checked===void 0?t?e.setAttribute(`checked`,`true`):e.removeAttribute(`checked`):e.checked=t}else if(r===`MINT-TAGS`)if(Array.isArray(n)){let t=new Map;try{let n=e.getAttribute(`predefined-tags`);if(n){let e=JSON.parse(n);Array.isArray(e)&&(t=new Map(e.map(e=>{if(typeof e==`string`){let t=e.trim();return t?[t.toLowerCase(),t]:null}if(!e||typeof e!=`object`)return null;let t=String(e.value??``).trim();if(!t)return null;let n=String(e.label??t);return[t.toLowerCase(),n]}).filter(e=>e!==null)))}}catch{}e.tags!==void 0&&(e.tags=n.map(e=>{if(typeof e==`string`){let n=e.trim();return{value:n,label:t.get(n.toLowerCase())||n,dismissable:!0}}if(e&&typeof e==`object`){let n=String(e.value??``).trim(),r=t.get(n.toLowerCase())||String(e.label??n);return{...e,value:n,label:r,dismissable:e.dismissable!==!1}}return e}))}else e.tags!==void 0&&(e.tags=[]);else if(e instanceof HTMLInputElement){if(e.type===`file`)return;e.type===`checkbox`||e.type===`radio`?e.checked=n===!0||n===`true`||n===`on`||n===1||n===`1`:e.value=n||``}else (e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(e.value=n||``)}catch(e){console.warn(`Failed to set value for field ${t}:`,e)}})}_resetCustomFields(){this.querySelectorAll(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{e.removeAttribute(`error`),e.removeAttribute(`error-message`);let t=e.tagName;if(t===`MINT-INPUT`)try{e.value=``}catch{}else if(t===`MINT-DATE-PICKER`)try{e.setValue?.(``)}catch{}else if(t===`MINT-SELECT`)try{e.setValue?.(``)}catch{}else if(t===`MINT-DROPZONE`){let t=e.querySelector(`input[type="file"]`);t&&(t.value=``)}else if(t===`MINT-CHECKBOX`||t===`MINT-SWITCH`)try{if(e.checked!==void 0)e.checked=!1;else{e.removeAttribute(`checked`);let t=e.querySelector(`input[type="checkbox"], input[type="radio"]`);t&&(t.checked=!1)}}catch{}else if(t===`MINT-CHOICE`)try{typeof e.setValue==`function`?e.setValue(``):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=!1})}catch{}else if(t===`MINT-TAGS`)try{e.tags=[]}catch{}})}_resolveHost(e){if(e.tagName===`MINT-CHOICE-OPTION`){let t=e.closest(`mint-choice`);if(t)return t}return e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)||e}_setupBlurValidation(){if(!this._form)return;let e=e=>{let t=e.target;if(!t)return;let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);if(!r||!this._collectValidationRules()[r])return;let i=this._extractFieldValue([n]),a=i!=null&&(typeof i==`string`?i.trim()!==``:i instanceof FileList||Array.isArray(i)?i.length>0:!0),o=n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&(t.hasAttribute(`aria-invalid`)||t.closest(`[data-mint-form-error]`)),s=!!n.closest(`mint-tags`),c=n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`||n.tagName===`MINT-CHOICE`||t instanceof HTMLElement&&(t.closest(`mint-checkbox, mint-switch, mint-choice`)||t.closest(`mint-choice-option`)),l=n.tagName===`MINT-DATE-PICKER`||t instanceof HTMLElement&&t.closest(`mint-date-picker`);(a||o||s||c||l)&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`blur`,e,!0),this._fieldBlurHandlers.set(this._form,e);let t=e=>{let t=e.target;if(!t)return;if(!(t instanceof HTMLInputElement&&t.type===`file`)){let e=this._findFieldElement(t),n=e?this._getFieldName(e):null;e&&n&&this._syncFieldToReactiveData(e,n)}if(e.type===`tags-change`&&t.tagName===`MINT-TAGS`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLSelectElement||t.tagName===`MINT-SELECT`||t.closest(`mint-select`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(e.type===`choice-change`&&t.tagName===`MINT-CHOICE`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLInputElement&&t.type===`checkbox`||t.tagName===`MINT-CHECKBOX`||t.tagName===`MINT-SWITCH`||t.closest(`mint-checkbox, mint-switch`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);r&&this._collectValidationRules()[r]&&(n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&t.hasAttribute(`aria-invalid`))&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`change`,t,!0),this._form.addEventListener(`input`,t,!0),this._form.addEventListener(`tags-change`,t,!0),this._form.addEventListener(`choice-change`,t,!0),this._fieldChangeHandlers.set(this._form,t)}_findFieldElement(e){let t=e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`);if(t&&t.hasAttribute(`name`))return t;if(e.hasAttribute(`name`)&&(e.tagName.startsWith(`MINT-`)||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)||(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.hasAttribute(`name`))return e;let n=e;for(;n&&n!==this._form;){if(n.hasAttribute(`name`))return n;n=n.parentElement}return null}_getFieldName(e){return e.hasAttribute(`name`)||e.tagName.startsWith(`MINT-`)?e.getAttribute(`name`):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.name||null}_syncFieldToReactiveData(e,t){if(!this._formData||!t)return;let n=this._getObjectValue(this._formData);if(!n||typeof n!=`object`||Array.isArray(n))return;let r=this._getFieldElements(t),i=this._extractFieldValue(r.length?r:[e]);n[t]=this._normalizeReactiveValue(r,i),this._lastDataSnapshot=this._createDataSnapshot(n)}_normalizeReactiveValue(e,t){if(t instanceof FileList)return Array.from(t);if(Array.isArray(t))return t;let n=e[0];return e.length===1&&(n instanceof HTMLInputElement&&n.type===`checkbox`||n?.tagName===`MINT-CHECKBOX`||n?.tagName===`MINT-SWITCH`)?!!t:t??``}_cleanupBlurValidation(){if(this._form&&this._fieldBlurHandlers.has(this._form)){let e=this._fieldBlurHandlers.get(this._form);e&&this._form.removeEventListener(`blur`,e,!0),this._fieldBlurHandlers.delete(this._form)}if(this._form&&this._fieldChangeHandlers.has(this._form)){let e=this._fieldChangeHandlers.get(this._form);e&&(this._form.removeEventListener(`change`,e,!0),this._form.removeEventListener(`input`,e,!0),this._form.removeEventListener(`tags-change`,e,!0),this._form.removeEventListener(`choice-change`,e,!0)),this._fieldChangeHandlers.delete(this._form)}this._observer&&=(this._observer.disconnect(),null)}_syncDropzoneFiles(){this._form&&Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{typeof e.syncFiles==`function`&&e.syncFiles()})}_isSubmittingAttrActive(){let e=this.getAttribute(`submitting`);return e!==null&&e!==`false`}_applySubmittingAttributeState(){if(this._form){if(!this._isSubmittingAttrActive()){this._restoreSubmittingAttributeState();return}this._attrSubmittingMintFields.size>0||this._attrSubmittingNativeFields.size>0||this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0||(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`;this._attrSubmittingMintFields.set(e,t),t||e.setAttribute(`disabled`,`true`),typeof e.render==`function`&&e.render()}),this._form.querySelectorAll(`input, textarea, select`).forEach(e=>{if(e.closest(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags, mint-button`)||e instanceof HTMLInputElement&&e.type===`hidden`)return;let t=e.disabled;this._attrSubmittingNativeFields.set(e,t),t||(e.disabled=!0)}),Array.from(this.querySelectorAll(`mint-button`)).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._attrSubmittingMintButtons.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&!n&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),Array.from(this.querySelectorAll(`button`)).forEach(e=>{if(e.closest(`mint-button, mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`))return;let t=e.disabled;this._attrSubmittingNativeButtons.set(e,t),t||(e.disabled=!0)}))}}_restoreSubmittingAttributeState(){this._attrSubmittingMintFields.forEach((e,t)=>{e?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintFields.clear(),this._attrSubmittingNativeFields.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeFields.clear(),this._attrSubmittingMintButtons.forEach((e,t)=>{e.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),e.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintButtons.clear(),this._attrSubmittingNativeButtons.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeButtons.clear()}_propagateLoadingState(){if(!this._form)return;let e=this.getAttribute(`loading`),t=e!==null&&e!==`false`;Array.from(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)).forEach(e=>{t?e.setAttribute(`loading`,`true`):e.removeAttribute(`loading`),typeof e.render==`function`&&e.render()})}_setButtonsSubmitting(){if(!this._form)return;this._buttonStates.clear();let e=Array.from(this.querySelectorAll(`mint-button`)),t=Array.from(this.querySelectorAll(`button`));e.forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._buttonStates.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),t.forEach(e=>{if(e.closest(`mint-button`))return;let t=e.disabled;this._buttonStates.set(e,{disabled:t,loading:!1}),t||(e.disabled=!0)})}_restoreButtonsState(){if(!this._form)return;let e=this._isSubmittingAttrActive()&&(this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0),t=Array.from(this.querySelectorAll(`mint-button`)),n=Array.from(this.querySelectorAll(`button`));t.forEach(t=>{if(e&&this._attrSubmittingMintButtons.has(t))return;let n=this._buttonStates.get(t);n&&(n.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),n.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render())}),n.forEach(t=>{if(t.closest(`mint-button`)||e&&this._attrSubmittingNativeButtons.has(t))return;let n=this._buttonStates.get(t);n&&(t.disabled=n.disabled)}),this._buttonStates.clear()}_isReactiveObject(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}_createDataSnapshot(e){try{let t=this._extractReactiveData(e);return JSON.parse(JSON.stringify(t))}catch{return{...this._extractReactiveData(e)}}}_extractReactiveData(e){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>this._extractReactiveData(e));let t=this._getObjectValue(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=this._extractReactiveData(t[n]));return e}return t}_hasDataChanged(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch{return!0}}_getObjectValue(e){return e}_setupObjectDataObserver(e){if(this._stopReactiveDataObserver(),!this.isConnected)return;let t=this._getObjectValue(e);if(t&&typeof t==`object`&&!Array.isArray(t))this._lastDataSnapshot=this._createDataSnapshot(t);else{this._lastDataSnapshot=null;return}let n=()=>{if(!this._formData||!this._lastDataSnapshot){this._stopReactiveDataObserver();return}let e=this._getObjectValue(this._formData);if(e&&typeof e==`object`&&!Array.isArray(e)){let t=this._createDataSnapshot(e);this._hasDataChanged(t,this._lastDataSnapshot)&&(this._lastDataSnapshot=t,requestAnimationFrame(()=>{this._applyFormData()}))}this.isConnected&&this._formData?this._reactiveDataObserver=requestAnimationFrame(n):this._stopReactiveDataObserver()};this._reactiveDataObserver=requestAnimationFrame(n)}_stopReactiveDataObserver(){this._reactiveDataObserver!==null&&(cancelAnimationFrame(this._reactiveDataObserver),this._reactiveDataObserver=null),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}};customElements.get(`mint-form`)||e.t(`mint-form`,t),typeof window<`u`&&(window.mintForm=window.mintForm||{defaults:{headers:{common:{}}},interceptors:{response:{handlers:[]}}},window.mintForm.interceptors.response.use||(window.mintForm.interceptors.response.use=function(e,t){return window.mintForm.interceptors.response.handlers.push({fulfilled:e,rejected:t}),window.mintForm.interceptors.response.handlers.length-1})),module.exports=t;
1
+ const e=require(`../chunks/register-element-tCL_F1YI.js`);var t=class extends HTMLElement{static get observedAttributes(){return[`action`,`method`,`enctype`,`data-form-data`,`loading`,`headers`,`submitting`]}constructor(){super(),this._form=null,this._submitHandler=null,this._hostSubmitHandler=null,this._errors={},this._fieldBlurHandlers=new Map,this._fieldChangeHandlers=new Map,this._observer=null,this._formData=null,this._headers=null,this._buttonStates=new Map,this._attrSubmittingMintFields=new Map,this._attrSubmittingNativeFields=new Map,this._attrSubmittingMintButtons=new Map,this._attrSubmittingNativeButtons=new Map,this._reactiveDataProxy=null,this._reactiveDataObserver=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}connectedCallback(){this._render(),this._ensureSubmitHandler(),this._setupBlurValidation();let e=this.getAttribute(`headers`);e&&this._parseHeaders(e),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(this._formData)this._isReactiveObject(this._formData)?this._setupObjectDataObserver(this._formData):this._lastDataSnapshot||=this._createDataSnapshot(this._formData),this._applyFormData();else{let e=this.getAttribute(`data-form-data`);e&&(this._parseFormData(e),this._applyFormData())}this._propagateLoadingState(),this._applySubmittingAttributeState()})})}disconnectedCallback(){this._form&&this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._hostSubmitHandler&&this.removeEventListener(`submit`,this._hostSubmitHandler),this._restoreSubmittingAttributeState(),this._cleanupBlurValidation(),this._stopReactiveDataObserver()}reset(){this._clearErrors(),this._formData?(this._lastAppliedDataSnapshot=null,this._applyFormData()):this.clear()}clear(){this._clearErrors(),this._form&&this._form.reset(),this._resetCustomFields()}submit(){if(this._form){if(typeof this._form.requestSubmit==`function`){this._form.requestSubmit();return}this._handleSubmit(new Event(`submit`,{bubbles:!0,cancelable:!0}))}}attributeChangedCallback(e,t,n){e===`form-data`?(this._parseFormData(n),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})):e===`headers`?this._parseHeaders(n):e===`loading`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._propagateLoadingState()}):this._propagateLoadingState():e===`submitting`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._applySubmittingAttributeState()}):this._applySubmittingAttributeState():this._applyFormAttributes()}get data(){return this._formData}set data(e){this._stopReactiveDataObserver(),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null,e&&typeof e==`object`&&!Array.isArray(e)?(this._formData=e,this._isReactiveObject(e)?this._setupObjectDataObserver(e):this._lastDataSnapshot=this._createDataSnapshot(e)):e==null?this._formData=null:this._parseFormData(e),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})})}get headers(){return this._headers}set headers(e){if(e&&typeof e==`object`&&!Array.isArray(e))this._headers=e;else if(e==null)this._headers=null;else if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_render(){if(this.classList.add(`mint-form-host`),!this._form){for(this._form=document.createElement(`form`),this._form.classList.add(`mint-form-content`),this._form.noValidate=!0;this.firstChild;)this._form.appendChild(this.firstChild);this.appendChild(this._form)}this._ensureSubmitHandler(),this._applyFormAttributes()}_ensureSubmitHandler(){this._form&&(this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._submitHandler=e=>{e.preventDefault(),e.stopImmediatePropagation(),this._handleSubmit(e)},this._form.addEventListener(`submit`,this._submitHandler,!0))}_applyFormAttributes(){if(!this._form)return;let e=this.getAttribute(`action`)||``,t=this.getAttribute(`method`)||``,n=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;e&&(this._form.action=e),t&&(this._form.method=t),this._form.enctype=n}async _handleSubmit(e){if(e.preventDefault(),!this._form)return;this._clearErrors(),this._syncDropzoneFiles();let t=this._collectValidationRules(),n=new FormData(this._form),r=this._formDataToValues(n);if(this._formData){let e=this._getObjectValue(this._formData);e&&typeof e==`object`&&!Array.isArray(e)&&(r={...this._extractReactiveData(e),...r})}let i=this._collectLiveControlValues();if(r={...r,...i},!this._validate(r,t)){this.dispatchEvent(new CustomEvent(`invalid`,{detail:{errors:this._errors},bubbles:!0,cancelable:!0,composed:!0}));return}let a=new CustomEvent(`submit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),a.form=this;let o=new CustomEvent(`mintFormSubmit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});if(o.form=this,this.dispatchEvent(o),a.defaultPrevented||o.defaultPrevented)return;let s=this.getAttribute(`action`),c=this.getAttribute(`method`);if(!(!s||!c)){this._setButtonsSubmitting();try{let e=await this._submitData(n,r);this.dispatchEvent(new CustomEvent(`submitsuccess`,{detail:e,bubbles:!0,cancelable:!0}))}catch(e){e?.status===422&&e?.data?.errors&&this._applyServerErrors(e.data.errors),this.dispatchEvent(new CustomEvent(`submiterror`,{detail:{error:e},bubbles:!0,cancelable:!0}))}finally{this._restoreButtonsState()}}}async _submitData(e,t){let n=this.getAttribute(`action`),r=this.getAttribute(`method`),i=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;if(!n)return{status:0,ok:!0,data:{values:t}};let a=Array.from(e.values()).some(e=>e instanceof File),o=null,s={},c=n;if(typeof window<`u`&&window.mintForm?.defaults?.headers?.common&&Object.assign(s,window.mintForm.defaults.headers.common),this._headers&&Object.assign(s,this._headers),r===`GET`){let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),c+=(n.includes(`?`)?`&`:`?`)+t.toString()}else if(i===`multipart/form-data`||a)o=e;else if(i===`application/json`)o=JSON.stringify(t),s[`Content-Type`]=`application/json`;else{let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),o=t,s[`Content-Type`]=`application/x-www-form-urlencoded`}if(typeof fetch==`function`)try{let e=await fetch(c,{method:r||`POST`,body:r===`GET`?null:o,headers:s}),t=await e.text().catch(()=>``),n=t;try{n=JSON.parse(t)}catch{}if(!e.ok){let t={status:e.status,data:n,response:{status:e.status,data:n}};throw await this._applyErrorInterceptors(t)}let i={status:e.status,ok:e.ok,data:n};return await this._applySuccessInterceptors(i)}catch(e){if(e.response)throw e;let t={status:e.status||0,data:e.data||e.message||`Network error`,response:{status:e.status||0,data:e.data||e.message||`Network error`}};throw await this._applyErrorInterceptors(t)}let l=this;return await new Promise(async(e,t)=>{let n=new XMLHttpRequest;n.open(r||`POST`,c,!0),Object.entries(s).forEach(([e,t])=>n.setRequestHeader(e,t)),n.onload=async function(){let{status:r,responseText:i}=n;if(r>=200&&r<300){let n=i;try{n=JSON.parse(i)}catch{}try{let t={status:r,ok:!0,data:n};e(await l._applySuccessInterceptors(t))}catch(e){t(e)}}else{let e=i;try{e=JSON.parse(i)}catch{}try{let n={status:r,data:e,response:{status:r,data:e}};t(await l._applyErrorInterceptors(n))}catch(e){t(e)}}},n.onerror=async function(){try{let e={status:n.status||0,data:n.responseText||`Network error`,response:{status:n.status||0,data:n.responseText||`Network error`}};t(await l._applyErrorInterceptors(e))}catch(e){t(e)}},n.send(r===`GET`?null:o)})}async _applySuccessInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return e;let t=e,n=window.mintForm.interceptors.response.handlers;for(let e of n)e.fulfilled&&(t=await e.fulfilled(t));return t}async _applyErrorInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return Promise.reject(e);let t=e,n=window.mintForm.interceptors.response.handlers;for(let e=n.length-1;e>=0;e--){let r=n[e];if(r.rejected)try{if(t=await r.rejected(t),t!==void 0)return t}catch(e){t=e}}return Promise.reject(t)}_formDataToValues(e){let t={};return e.forEach((e,n)=>{e instanceof File?(t[n]||(t[n]=[]),t[n].push(e)):n in t?Array.isArray(t[n])?(t[n].length>0&&t[n][0]instanceof File,t[n].push(e)):t[n]=[t[n],e]:t[n]=e}),this._form&&(Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n&&e.files!==void 0&&e.files){let r=e.files;if(r.length>0){let e=Array.from(r);t[n]&&Array.isArray(t[n])?e.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=e}}}),Array.from(this._form.querySelectorAll(`input[type="file"][name]`)).forEach(e=>{let n=e.name;if(n&&e.files&&e.files.length>0){let r=Array.from(e.files);t[n]&&Array.isArray(t[n])?r.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=r}}),Array.from(this._form.querySelectorAll(`mint-tags[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n){let r=[];e.tags===void 0?typeof e.getTags==`function`&&(r=e.getTags()):r=e.tags,Array.isArray(r)&&r.length>0?t[n]=r.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):t[n]=[]}})),t}_isControlDisabledForSubmit(e){let t=e;for(;t&&t!==this._form;){if((t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLButtonElement)&&t.disabled)return!0;let e=t.getAttribute(`disabled`);if(e!==null&&e!==`false`)return!0;t=t.parentElement}return!1}_collectLiveControlValues(){let e={};if(!this._form)return e;let t=new Set,n=Array.from(this._form.querySelectorAll([`input[name]`,`textarea[name]`,`select[name]`,`mint-input[name]`,`mint-select[name]`,`mint-date-picker[name]`,`mint-time-picker[name]`,`mint-dropzone[name]`,`mint-checkbox[name]`,`mint-choice[name]`,`mint-switch[name]`,`mint-tags[name]`].join(`,`)));for(let e of n){let n=e.getAttribute(`name`);!n||this._isControlDisabledForSubmit(e)||t.add(n)}for(let n of t){let t=this._getFieldElements(n).filter(e=>!this._isControlDisabledForSubmit(e));if(t.length!==0)try{let r=this._extractFieldValue(t),i=r instanceof FileList?Array.from(r):r,a=e=>e instanceof HTMLInputElement?e.type===`checkbox`||e.type===`radio`:[`MINT-CHECKBOX`,`MINT-CHOICE`,`MINT-SWITCH`].includes(e.tagName),o=t.length===1&&[`MINT-CHECKBOX`,`MINT-SWITCH`].includes(t[0].tagName);if(t.every(a)&&!o&&(i===``||i==null||Array.isArray(i)&&i.length===0))continue;e[n]=i}catch{}}return e}_collectValidationRules(){let e={};return this._form&&Array.from(this._form.querySelectorAll(`[name][validation]`)).forEach(t=>{let n=t.getAttribute(`name`)||``,r=t.getAttribute(`validation`);if(!n||!r)return;let i=this._parseRules(r);i.length&&(e[n]=i)}),e}_parseRules(e){if(!e)return[];try{let t=e.replace(/'/g,`"`),n=JSON.parse(t);if(Array.isArray(n))return n.map(e=>String(e))}catch{}return e.split(`,`).map(e=>e.trim()).filter(Boolean)}_validate(e,t){let n=!0;return this._errors={},Object.entries(t||{}).forEach(([e,t])=>{let r=Array.isArray(t)?t:[t],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(n=!1,this._errors[e]=o,this._flagFieldError(i,o)):this._clearFieldError(i)}),n}_validateField(e){let t=this._collectValidationRules();if(!t[e])return;let n=t[e],r=Array.isArray(n)?n:[n],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(this._errors[e]=o,this._flagFieldError(i,o)):(this._clearFieldError(i),delete this._errors[e])}_validateRules(e,t){for(let n of t){let[t,r]=n.split(`:`);switch(t){case`required`:if(e==null||e===!1||typeof e==`string`&&e.trim()===``||e instanceof FileList&&e.length===0||Array.isArray(e)&&e.length===0)return`This field is required.`;break;case`string`:if(typeof e!=`string`)return`Must be a string.`;break;case`email`:if(typeof e==`string`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()))return`Enter a valid email.`;break;case`number`:{let t=Number(e);if(Number.isNaN(t))return`Must be a number.`;break}case`min`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length<t)return`Must be at least ${t} characters.`;if(Array.isArray(e)&&e.length<t)return`Select at least ${t}.`;if(e instanceof FileList&&e.length<t)return`Upload at least ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)<t)return`Must be at least ${t}.`;break}case`max`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length>t)return`Must be at most ${t} characters.`;if(Array.isArray(e)&&e.length>t)return`Select no more than ${t}.`;if(e instanceof FileList&&e.length>t)return`Upload no more than ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)>t)return`Must be at most ${t}.`;break}default:break}}return null}_getFieldElements(e){if(!this._form)return[];let t=Array.from(this._form.querySelectorAll(`[name="${e}"]`)),n=t.filter(e=>e.tagName===`MINT-SELECT`);if(n.length>0){let r=[];return n.forEach(t=>{let n=t.querySelector(`select[name="`+e+`"]`);n&&r.push(n)}),t.filter(e=>e.tagName!==`MINT-SELECT`).concat(r)}if(t.filter(e=>e.tagName===`MINT-TAGS`).length>0)return t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`));let r=t.filter(e=>e.tagName===`INPUT`&&e.closest(`mint-tags`));if(r.length>0){let e=[];return r.forEach(t=>{let n=t.closest(`mint-tags`);n&&!e.includes(n)&&e.push(n)}),t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`)).concat(e)}return t}_extractFieldValue(e){if(e.length===0)return``;let t=e.find(e=>e instanceof HTMLSelectElement);if(t)return t.multiple?Array.from(t.selectedOptions).map(e=>e.value):t.value;if(e.length>1){let t=e.filter(e=>e instanceof HTMLInputElement);if(t.length>0&&t.length===e.length){let e=t.filter(e=>e.checked);if(t.every(e=>e.type===`radio`))return e.length>0?e[0].value||`on`:``;if(t.every(e=>e.type===`checkbox`))return e.map(e=>e.value||`on`)}let n=e.filter(e=>e.tagName===`MINT-CHOICE`);if(n.length>0&&n.length===e.length){let e=n.find(e=>typeof e.getValue==`function`?e.getValue()!==``:e.querySelector(`mint-choice-option[checked]`)!==null);if(e){if(typeof e.getValue==`function`)return e.getValue();let t=e.querySelector(`mint-choice-option[checked]`);if(t)return t.getAttribute(`value`)||``}return``}let r=e.filter(e=>e.tagName===`MINT-CHECKBOX`);if(r.length>0&&r.length===e.length)return r.filter(e=>e.checked===void 0?e.hasAttribute(`checked`):e.checked).map(e=>e.getAttribute(`value`)||`on`)}let n=e[0];if(n instanceof HTMLInputElement)return n.type===`file`?n.files:n.type===`checkbox`||n.type===`radio`?n.checked?n.value||`on`:``:n.value;if(n instanceof HTMLTextAreaElement)return n.value;if(n.tagName===`MINT-SELECT`){let e=n.querySelector(`select`);if(e)return e.multiple?Array.from(e.selectedOptions).map(e=>e.value):e.value;if(typeof n.getValue==`function`){let e=n.getValue();if(e!=null&&e!==``)return e}return n.getAttribute(`value`)||``}if(n.tagName===`MINT-DROPZONE`&&n.files!==void 0)return n.files;if(n.tagName===`MINT-TAGS`){let e=null;return n.tags===void 0?typeof n.getTags==`function`&&(e=n.getTags()):e=n.tags,Array.isArray(e)?e.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):[]}return n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`?!!(n.checked===void 0?n.hasAttribute(`checked`):n.checked):n.tagName===`MINT-CHOICE`?(typeof n.getValue==`function`?n.getValue():``)||``:n.value===void 0?n.getAttribute(`value`)||``:n.value}_flagFieldError(e,t){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.setAttribute(`aria-invalid`,`true`);let n=this._resolveHost(e);n&&(n.setAttribute(`error`,`true`),n.setAttribute(`error-message`,t),n.setAttribute(`data-mint-form-error`,`true`))})}_clearFieldError(e){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.removeAttribute(`aria-invalid`);let t=this._resolveHost(e);t&&(t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`))})}_clearErrors(){this.querySelectorAll(`[data-mint-form-error]`).forEach(e=>{let t=e;t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`)}),this._form&&this._form.querySelectorAll(`[aria-invalid="true"]`).forEach(e=>{e.removeAttribute(`aria-invalid`)}),this._errors={}}setFormErrors(e){this._applyServerErrors(e)}_applyServerErrors(e){this._clearErrors(),Object.entries(e).forEach(([e,t])=>{let n=Array.isArray(t)?t[0]||`Validation error`:t||`Validation error`,r=this._getFieldElements(e);r.length>0&&(this._errors[e]=n,this._flagFieldError(r,n))})}_parseFormData(e){if(!e){this._formData=null;return}if(typeof e==`object`&&!Array.isArray(e)){this._formData=e;return}if(typeof e==`string`)try{this._formData=JSON.parse(e)}catch{this._formData=null}else this._formData=null}_parseHeaders(e){if(!e){this._headers=null;return}if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_applyFormData(){if(!this._formData||!this._form)return;let e=this._getObjectValue(this._formData);if(!e||typeof e!=`object`||Array.isArray(e))return;let t=this._extractReactiveData(e),n=this._createDataSnapshot(t),r=this._lastAppliedDataSnapshot,i=new Set;if(r?(Object.keys(n).forEach(e=>{let t=r[e],a=n[e];JSON.stringify(t)!==JSON.stringify(a)&&i.add(e)}),Object.keys(r).forEach(e=>{e in n||i.add(e)})):Object.keys(n).forEach(e=>i.add(e)),i.size===0)return;let a=()=>{i.forEach(e=>{let t=n[e],r=this._getFieldElements(e);if(r.length===0){setTimeout(()=>{let t=this._getFieldElements(e);if(t.length===0)return;let n=this._formData?this._getObjectValue(this._formData):null;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[e];this._applyValueToField(t,e,r)},300);return}this._applyValueToField(r,e,t)}),this._lastAppliedDataSnapshot=n};requestAnimationFrame(()=>{requestAnimationFrame(()=>{a()})})}_applyValueToField(e,t,n){e.forEach(e=>{let r=e.tagName;try{if(r===`MINT-INPUT`)e.value!==void 0&&(e.value=n||``);else if(r===`MINT-DATE-PICKER`)typeof e.setValue==`function`&&e.setValue(n||``);else if(r===`MINT-TIME-PICKER`)typeof e.setValue==`function`?e.setValue(n==null?``:String(n)):e.value!==void 0&&(e.value=n==null?``:String(n));else if(r===`MINT-SELECT`||r===`SELECT`)if(r===`SELECT`){let t=e,r=t.closest(`mint-select`);if(r&&typeof r.setValue==`function`)r.setValue(n);else if(t.multiple){let e=Array.isArray(n)?n.map(e=>String(e)):n==null||n===``?[]:[String(n)];Array.from(t.options).forEach(t=>{t.selected=e.includes(t.value)})}else t.value=n==null?``:String(n)}else typeof e.setValue==`function`&&e.setValue(n);else if(r===`MINT-CHOICE`)typeof e.setValue==`function`?e.setValue(n==null?``:String(n)):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=e.getAttribute(`value`)===n});else if(r===`MINT-CHECKBOX`||r===`MINT-SWITCH`){let t=n===!0||n===`true`||n===`on`||n===1||n===`1`;e.checked===void 0?t?e.setAttribute(`checked`,`true`):e.removeAttribute(`checked`):e.checked=t}else if(r===`MINT-TAGS`)if(Array.isArray(n)){let t=new Map;try{let n=e.getAttribute(`predefined-tags`);if(n){let e=JSON.parse(n);Array.isArray(e)&&(t=new Map(e.map(e=>{if(typeof e==`string`){let t=e.trim();return t?[t.toLowerCase(),t]:null}if(!e||typeof e!=`object`)return null;let t=String(e.value??``).trim();if(!t)return null;let n=String(e.label??t);return[t.toLowerCase(),n]}).filter(e=>e!==null)))}}catch{}e.tags!==void 0&&(e.tags=n.map(e=>{if(typeof e==`string`||typeof e==`number`){let n=String(e).trim();return{value:n,label:t.get(n.toLowerCase())||n,dismissable:!0}}if(e&&typeof e==`object`){let n=String(e.value??``).trim(),r=t.get(n.toLowerCase())||String(e.label??n);return{...e,value:n,label:r,dismissable:e.dismissable!==!1}}return e}))}else e.tags!==void 0&&(e.tags=[]);else if(e instanceof HTMLInputElement){if(e.type===`file`)return;e.type===`checkbox`||e.type===`radio`?e.checked=n===!0||n===`true`||n===`on`||n===1||n===`1`:e.value=n||``}else (e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(e.value=n||``)}catch(e){console.warn(`Failed to set value for field ${t}:`,e)}})}_resetCustomFields(){this.querySelectorAll(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{e.removeAttribute(`error`),e.removeAttribute(`error-message`);let t=e.tagName;if(t===`MINT-INPUT`)try{e.value=``}catch{}else if(t===`MINT-DATE-PICKER`)try{e.setValue?.(``)}catch{}else if(t===`MINT-SELECT`)try{e.setValue?.(``)}catch{}else if(t===`MINT-DROPZONE`){let t=e.querySelector(`input[type="file"]`);t&&(t.value=``)}else if(t===`MINT-CHECKBOX`||t===`MINT-SWITCH`)try{if(e.checked!==void 0)e.checked=!1;else{e.removeAttribute(`checked`);let t=e.querySelector(`input[type="checkbox"], input[type="radio"]`);t&&(t.checked=!1)}}catch{}else if(t===`MINT-CHOICE`)try{typeof e.setValue==`function`?e.setValue(``):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=!1})}catch{}else if(t===`MINT-TAGS`)try{e.tags=[]}catch{}})}_resolveHost(e){if(e.tagName===`MINT-CHOICE-OPTION`){let t=e.closest(`mint-choice`);if(t)return t}return e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)||e}_setupBlurValidation(){if(!this._form)return;let e=e=>{let t=e.target;if(!t)return;let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);if(!r||!this._collectValidationRules()[r])return;let i=this._extractFieldValue([n]),a=i!=null&&(typeof i==`string`?i.trim()!==``:i instanceof FileList||Array.isArray(i)?i.length>0:!0),o=n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&(t.hasAttribute(`aria-invalid`)||t.closest(`[data-mint-form-error]`)),s=!!n.closest(`mint-tags`),c=n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`||n.tagName===`MINT-CHOICE`||t instanceof HTMLElement&&(t.closest(`mint-checkbox, mint-switch, mint-choice`)||t.closest(`mint-choice-option`)),l=n.tagName===`MINT-DATE-PICKER`||t instanceof HTMLElement&&t.closest(`mint-date-picker`);(a||o||s||c||l)&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`blur`,e,!0),this._fieldBlurHandlers.set(this._form,e);let t=e=>{let t=e.target;if(!t)return;if(!(t instanceof HTMLInputElement&&t.type===`file`)){let e=this._findFieldElement(t),n=e?this._getFieldName(e):null;e&&n&&this._syncFieldToReactiveData(e,n)}if(e.type===`tags-change`&&t.tagName===`MINT-TAGS`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLSelectElement||t.tagName===`MINT-SELECT`||t.closest(`mint-select`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(e.type===`choice-change`&&t.tagName===`MINT-CHOICE`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLInputElement&&t.type===`checkbox`||t.tagName===`MINT-CHECKBOX`||t.tagName===`MINT-SWITCH`||t.closest(`mint-checkbox, mint-switch`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);r&&this._collectValidationRules()[r]&&(n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&t.hasAttribute(`aria-invalid`))&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`change`,t,!0),this._form.addEventListener(`input`,t,!0),this._form.addEventListener(`tags-change`,t,!0),this._form.addEventListener(`choice-change`,t,!0),this._fieldChangeHandlers.set(this._form,t)}_findFieldElement(e){let t=e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`);if(t&&t.hasAttribute(`name`))return t;if(e.hasAttribute(`name`)&&(e.tagName.startsWith(`MINT-`)||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)||(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.hasAttribute(`name`))return e;let n=e;for(;n&&n!==this._form;){if(n.hasAttribute(`name`))return n;n=n.parentElement}return null}_getFieldName(e){return e.hasAttribute(`name`)||e.tagName.startsWith(`MINT-`)?e.getAttribute(`name`):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.name||null}_syncFieldToReactiveData(e,t){if(!this._formData||!t)return;let n=this._getObjectValue(this._formData);if(!n||typeof n!=`object`||Array.isArray(n))return;let r=this._getFieldElements(t),i=this._extractFieldValue(r.length?r:[e]);n[t]=this._normalizeReactiveValue(r,i),this._lastDataSnapshot=this._createDataSnapshot(n)}_normalizeReactiveValue(e,t){if(t instanceof FileList)return Array.from(t);if(Array.isArray(t))return t;let n=e[0];return e.length===1&&(n instanceof HTMLInputElement&&n.type===`checkbox`||n?.tagName===`MINT-CHECKBOX`||n?.tagName===`MINT-SWITCH`)?!!t:t??``}_cleanupBlurValidation(){if(this._form&&this._fieldBlurHandlers.has(this._form)){let e=this._fieldBlurHandlers.get(this._form);e&&this._form.removeEventListener(`blur`,e,!0),this._fieldBlurHandlers.delete(this._form)}if(this._form&&this._fieldChangeHandlers.has(this._form)){let e=this._fieldChangeHandlers.get(this._form);e&&(this._form.removeEventListener(`change`,e,!0),this._form.removeEventListener(`input`,e,!0),this._form.removeEventListener(`tags-change`,e,!0),this._form.removeEventListener(`choice-change`,e,!0)),this._fieldChangeHandlers.delete(this._form)}this._observer&&=(this._observer.disconnect(),null)}_syncDropzoneFiles(){this._form&&Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{typeof e.syncFiles==`function`&&e.syncFiles()})}_isSubmittingAttrActive(){let e=this.getAttribute(`submitting`);return e!==null&&e!==`false`}_applySubmittingAttributeState(){if(this._form){if(!this._isSubmittingAttrActive()){this._restoreSubmittingAttributeState();return}this._attrSubmittingMintFields.size>0||this._attrSubmittingNativeFields.size>0||this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0||(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`;this._attrSubmittingMintFields.set(e,t),t||e.setAttribute(`disabled`,`true`),typeof e.render==`function`&&e.render()}),this._form.querySelectorAll(`input, textarea, select`).forEach(e=>{if(e.closest(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags, mint-button`)||e instanceof HTMLInputElement&&e.type===`hidden`)return;let t=e.disabled;this._attrSubmittingNativeFields.set(e,t),t||(e.disabled=!0)}),Array.from(this.querySelectorAll(`mint-button`)).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._attrSubmittingMintButtons.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&!n&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),Array.from(this.querySelectorAll(`button`)).forEach(e=>{if(e.closest(`mint-button, mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`))return;let t=e.disabled;this._attrSubmittingNativeButtons.set(e,t),t||(e.disabled=!0)}))}}_restoreSubmittingAttributeState(){this._attrSubmittingMintFields.forEach((e,t)=>{e?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintFields.clear(),this._attrSubmittingNativeFields.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeFields.clear(),this._attrSubmittingMintButtons.forEach((e,t)=>{e.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),e.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintButtons.clear(),this._attrSubmittingNativeButtons.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeButtons.clear()}_propagateLoadingState(){if(!this._form)return;let e=this.getAttribute(`loading`),t=e!==null&&e!==`false`;Array.from(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)).forEach(e=>{t?e.setAttribute(`loading`,`true`):e.removeAttribute(`loading`),typeof e.render==`function`&&e.render()})}_setButtonsSubmitting(){if(!this._form)return;this._buttonStates.clear();let e=Array.from(this.querySelectorAll(`mint-button`)),t=Array.from(this.querySelectorAll(`button`));e.forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._buttonStates.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),t.forEach(e=>{if(e.closest(`mint-button`))return;let t=e.disabled;this._buttonStates.set(e,{disabled:t,loading:!1}),t||(e.disabled=!0)})}_restoreButtonsState(){if(!this._form)return;let e=this._isSubmittingAttrActive()&&(this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0),t=Array.from(this.querySelectorAll(`mint-button`)),n=Array.from(this.querySelectorAll(`button`));t.forEach(t=>{if(e&&this._attrSubmittingMintButtons.has(t))return;let n=this._buttonStates.get(t);n&&(n.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),n.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render())}),n.forEach(t=>{if(t.closest(`mint-button`)||e&&this._attrSubmittingNativeButtons.has(t))return;let n=this._buttonStates.get(t);n&&(t.disabled=n.disabled)}),this._buttonStates.clear()}_isReactiveObject(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}_createDataSnapshot(e){try{let t=this._extractReactiveData(e);return JSON.parse(JSON.stringify(t))}catch{return{...this._extractReactiveData(e)}}}_extractReactiveData(e){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>this._extractReactiveData(e));let t=this._getObjectValue(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=this._extractReactiveData(t[n]));return e}return t}_hasDataChanged(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch{return!0}}_getObjectValue(e){return e}_setupObjectDataObserver(e){if(this._stopReactiveDataObserver(),!this.isConnected)return;let t=this._getObjectValue(e);if(t&&typeof t==`object`&&!Array.isArray(t))this._lastDataSnapshot=this._createDataSnapshot(t);else{this._lastDataSnapshot=null;return}let n=()=>{if(!this._formData||!this._lastDataSnapshot){this._stopReactiveDataObserver();return}let e=this._getObjectValue(this._formData);if(e&&typeof e==`object`&&!Array.isArray(e)){let t=this._createDataSnapshot(e);this._hasDataChanged(t,this._lastDataSnapshot)&&(this._lastDataSnapshot=t,requestAnimationFrame(()=>{this._applyFormData()}))}this.isConnected&&this._formData?this._reactiveDataObserver=requestAnimationFrame(n):this._stopReactiveDataObserver()};this._reactiveDataObserver=requestAnimationFrame(n)}_stopReactiveDataObserver(){this._reactiveDataObserver!==null&&(cancelAnimationFrame(this._reactiveDataObserver),this._reactiveDataObserver=null),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}};customElements.get(`mint-form`)||e.t(`mint-form`,t),typeof window<`u`&&(window.mintForm=window.mintForm||{defaults:{headers:{common:{}}},interceptors:{response:{handlers:[]}}},window.mintForm.interceptors.response.use||(window.mintForm.interceptors.response.use=function(e,t){return window.mintForm.interceptors.response.handlers.push({fulfilled:e,rejected:t}),window.mintForm.interceptors.response.handlers.length-1})),module.exports=t;
@@ -371,12 +371,12 @@ var t = class extends HTMLElement {
371
371
  for (let n of t) {
372
372
  let t = this._getFieldElements(n).filter((e) => !this._isControlDisabledForSubmit(e));
373
373
  if (t.length !== 0) try {
374
- let r = this._extractFieldValue(t), i = r instanceof FileList ? Array.from(r) : r;
375
- if (t.every((e) => e instanceof HTMLInputElement ? e.type === "checkbox" || e.type === "radio" : [
374
+ let r = this._extractFieldValue(t), i = r instanceof FileList ? Array.from(r) : r, a = (e) => e instanceof HTMLInputElement ? e.type === "checkbox" || e.type === "radio" : [
376
375
  "MINT-CHECKBOX",
377
376
  "MINT-CHOICE",
378
377
  "MINT-SWITCH"
379
- ].includes(e.tagName)) && (i === "" || i == null || Array.isArray(i) && i.length === 0)) continue;
378
+ ].includes(e.tagName), o = t.length === 1 && ["MINT-CHECKBOX", "MINT-SWITCH"].includes(t[0].tagName);
379
+ if (t.every(a) && !o && (i === "" || i == null || Array.isArray(i) && i.length === 0)) continue;
380
380
  e[n] = i;
381
381
  } catch {}
382
382
  }
@@ -417,7 +417,7 @@ var t = class extends HTMLElement {
417
417
  let [t, r] = n.split(":");
418
418
  switch (t) {
419
419
  case "required":
420
- if (e == null || typeof e == "string" && e.trim() === "" || e instanceof FileList && e.length === 0 || Array.isArray(e) && e.length === 0) return "This field is required.";
420
+ if (e == null || e === !1 || typeof e == "string" && e.trim() === "" || e instanceof FileList && e.length === 0 || Array.isArray(e) && e.length === 0) return "This field is required.";
421
421
  break;
422
422
  case "string":
423
423
  if (typeof e != "string") return "Must be a string.";
@@ -515,7 +515,7 @@ var t = class extends HTMLElement {
515
515
  let e = null;
516
516
  return n.tags === void 0 ? typeof n.getTags == "function" && (e = n.getTags()) : e = n.tags, Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : e?.value || e?.label || "").filter((e) => e.trim() !== "") : [];
517
517
  }
518
- return n.tagName === "MINT-CHECKBOX" || n.tagName === "MINT-SWITCH" ? (n.checked === void 0 ? n.hasAttribute("checked") : n.checked) ? n.getAttribute("value") || "on" : "" : n.tagName === "MINT-CHOICE" ? (typeof n.getValue == "function" ? n.getValue() : "") || "" : n.value === void 0 ? n.getAttribute("value") || "" : n.value;
518
+ return n.tagName === "MINT-CHECKBOX" || n.tagName === "MINT-SWITCH" ? !!(n.checked === void 0 ? n.hasAttribute("checked") : n.checked) : n.tagName === "MINT-CHOICE" ? (typeof n.getValue == "function" ? n.getValue() : "") || "" : n.value === void 0 ? n.getAttribute("value") || "" : n.value;
519
519
  }
520
520
  _flagFieldError(e, t) {
521
521
  e.length !== 0 && e.forEach((e) => {
@@ -653,8 +653,8 @@ var t = class extends HTMLElement {
653
653
  }
654
654
  } catch {}
655
655
  e.tags !== void 0 && (e.tags = n.map((e) => {
656
- if (typeof e == "string") {
657
- let n = e.trim();
656
+ if (typeof e == "string" || typeof e == "number") {
657
+ let n = String(e).trim();
658
658
  return {
659
659
  value: n,
660
660
  label: t.get(n.toLowerCase()) || n,
@@ -17,5 +17,5 @@ __mintLoadStyle('icon', '../../icon.css')
17
17
  __mintLoadStyle('text', '../../text.css')
18
18
  __mintLoadStyle('stack', '../../stack.css')
19
19
  __mintLoadStyle('modal', '../../modal.css')
20
- import { t as e } from "../chunks/modal-CPcIPIO7.js";
20
+ import { t as e } from "../chunks/modal-DKNBqbQD.js";
21
21
  export { e as default };
@@ -1 +1 @@
1
- const e=require(`../chunks/modal-CNBmdA63.js`);module.exports=e.t;
1
+ const e=require(`../chunks/modal-BZ-VwNkW.js`);module.exports=e.t;
@@ -5,5 +5,5 @@ import '../../icon.css'
5
5
  import '../../text.css'
6
6
  import '../../stack.css'
7
7
  import '../../modal.css'
8
- import { t as e } from "../chunks/modal-CPcIPIO7.js";
8
+ import { t as e } from "../chunks/modal-DKNBqbQD.js";
9
9
  export { e as default };
@@ -188,31 +188,57 @@ var t = class extends HTMLElement {
188
188
  }), this._predefinedFieldResizeObserver.observe(this._container), this._syncPredefinedPopoverBodyMinWidth(e);
189
189
  }
190
190
  _renderPredefinedPopover() {
191
- if (!this._container || !this._chipsWrap || (this._disconnectPredefinedFieldResizeObserver(), this.querySelectorAll("[data-mint-tags-predefined=\"true\"]").forEach((e) => e.remove()), !this._predefinedTags.length) || !this._input || !this._input.id) return;
192
- let e = this._getAvailablePredefinedTags();
193
- if (this.isPredefinedOnly() && e.length === 0) return;
194
- let t = `${this.getAttribute("id") || this._input.id}-tags-field`;
195
- this._container.id = t;
196
- let n = document.createElement("mint-popover");
197
- n.setAttribute("trigger-id", t), n.setAttribute("trigger-toggle", "false"), n.setAttribute("trigger-align", "start"), n.setAttribute("direction", "down"), n.setAttribute("padding", "0"), n.setAttribute("distance", "6px"), n.dataset.mintTagsPredefined = "true";
198
- let r = document.createElement("div");
199
- if (r.dataset.mintTagsPredefinedBody = "true", r.className = "mint-tags-options", r.addEventListener("mousedown", (e) => {
191
+ if (!this._container || !this._chipsWrap) return;
192
+ let e = this._getPredefinedPopoverEl();
193
+ if (this._disconnectPredefinedFieldResizeObserver(), !this._predefinedTags.length) {
194
+ e?.remove();
195
+ return;
196
+ }
197
+ if (!this._input || !this._input.id) return;
198
+ let t = this._getAvailablePredefinedTags();
199
+ if (this.isPredefinedOnly() && t.length === 0) {
200
+ e?.remove();
201
+ return;
202
+ }
203
+ let n = `${this.getAttribute("id") || this._input.id}-tags-field`;
204
+ this._container.id = n;
205
+ let r = e || document.createElement("mint-popover");
206
+ e || (r.setAttribute("trigger-id", n), r.setAttribute("trigger-toggle", "false"), r.setAttribute("trigger-align", "start"), r.setAttribute("direction", "down"), r.setAttribute("padding", "0"), r.setAttribute("distance", "6px"), r.dataset.mintTagsPredefined = "true");
207
+ let i = document.createElement("ul");
208
+ i.dataset.mintTagsPredefinedBody = "true", i.className = "mint-tags-options", i.setAttribute("role", "list");
209
+ let a = [];
210
+ if (i.addEventListener("mousedown", (e) => {
200
211
  e.preventDefault();
201
- }), e.length) e.forEach((e) => {
202
- let t = document.createElement("mint-button");
203
- t.setAttribute("type", "button"), t.setAttribute("variant", "ghost"), t.setAttribute("full-width", "true"), t.setAttribute("align", "left"), t.classList.add("mint-tags-option"), t.textContent = e.label || e.value, t.addEventListener("mousedown", (e) => {
212
+ }), t.length) t.forEach((e) => {
213
+ let t = document.createElement("li");
214
+ t.className = "mint-tags-option-item";
215
+ let n = document.createElement("mint-button");
216
+ n.setAttribute("type", "button"), n.setAttribute("variant", "ghost"), n.setAttribute("full-width", "true"), n.setAttribute("align", "left"), n.classList.add("mint-tags-option");
217
+ let r = e.label || e.value;
218
+ a.push({
219
+ option: n,
220
+ label: r
221
+ }), n.addEventListener("mousedown", (e) => {
204
222
  e.preventDefault();
205
- }, !0), t.addEventListener("click", () => {
206
- this._addTag(e), n.removeAttribute("open"), requestAnimationFrame(() => {
207
- this._input?.focus({ preventScroll: !0 }), this._container?.setAttribute("data-mint-tags-active", "true");
223
+ }, !0), n.addEventListener("click", () => {
224
+ this._predefinedBlurCloseTimer !== null && (window.clearTimeout(this._predefinedBlurCloseTimer), this._predefinedBlurCloseTimer = null), this._suppressNextPredefinedBlurClose = !0, this._addTag(e), requestAnimationFrame(() => {
225
+ this._suppressNextPredefinedBlurClose = !1, this._input?.focus({ preventScroll: !0 }), this._container?.setAttribute("data-mint-tags-active", "true");
208
226
  });
209
- }), r.appendChild(t);
227
+ }), t.appendChild(n), i.appendChild(t);
210
228
  });
211
229
  else {
212
230
  let e = document.createElement("div");
213
- e.className = "mint-tags-empty", e.textContent = "No tags available", r.appendChild(e);
231
+ e.className = "mint-tags-empty", e.textContent = "No tags available";
232
+ let t = document.createElement("li");
233
+ t.className = "mint-tags-option-item", t.appendChild(e), i.appendChild(t);
214
234
  }
215
- n.appendChild(r), this._container.appendChild(n), this._attachPredefinedPopoverOpenOnInputFocus(), this._attachPredefinedFieldResizeObserver(r);
235
+ if (e) {
236
+ let t = e.querySelector("[data-mint-tags-predefined-body]");
237
+ t ? t.replaceWith(i) : r.appendChild(i);
238
+ } else r.appendChild(i), this._container.appendChild(r);
239
+ a.forEach(({ option: e, label: t }) => {
240
+ e.textContent = t;
241
+ }), this._attachPredefinedPopoverOpenOnInputFocus(), this._attachPredefinedFieldResizeObserver(i);
216
242
  }
217
243
  _getPredefinedPopoverEl() {
218
244
  return this.querySelector("mint-popover[data-mint-tags-predefined=\"true\"]");
@@ -1 +1 @@
1
- require(`../chunks/icon-B_7c8b8e.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/button-DbxqmBWQ.js`),require(`../chunks/chip-8BYSJ7yI.js`),require(`../chunks/popover-BeaGf_JC.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._container=null,this._chipsWrap=null,this._input=null,this._tags=[],this._predefinedTags=[],this._placeholder=`Add tag`,this._predefinedPopoverOpenListenersAttached=!1,this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose=!1,this._dragIndex=null,this._dragChip=null,this._isPointerDragging=!1,this._pointerMoveHandler=null,this._pointerUpHandler=null,this._containerFocusRingListeners=!1,this._predefinedFieldResizeObserver=null,this._predefinedPopoverBodyEl=null}static get observedAttributes(){return[`tags`,`placeholder`,`predefined-tags`,`predefined-only`,`sortable`,`label`,`info`,`error`,`error-message`,`name`,`id`,`required`,`loading`]}connectedCallback(){this._parseAttrs(),this._render(),this._pointerMoveHandler||(this._pointerMoveHandler=e=>this._onPointerMove(e),window.addEventListener(`pointermove`,this._pointerMoveHandler)),this._pointerUpHandler||(this._pointerUpHandler=e=>this._onPointerUp(e),window.addEventListener(`pointerup`,this._pointerUpHandler),window.addEventListener(`pointercancel`,this._pointerUpHandler))}disconnectedCallback(){this._disconnectPredefinedFieldResizeObserver()}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._syncInputAccessibility(),this._container&&this._container.classList.toggle(`mint-tags-field-error`,this.hasError());return}if(e===`loading`){this._parseAttrs(),this._render();return}this._parseAttrs(),this._render()}}set tags(e){this._tags=Array.isArray(e)?[...e]:[],this._syncAttr(),this._render()}get tags(){return[...this._tags]}_parseAttrs(){let e=this.getAttribute(`tags`);e&&(this._tags=this._parseTagItems(e,`tags`));let t=this.getAttribute(`placeholder`);t!==null&&(this._placeholder=t);let n=this.getAttribute(`predefined-tags`);this._predefinedTags=this._parseTagItems(n,`predefined-tags`)}_parseTagItems(e,t){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{if(typeof e==`string`){let t=e.trim();return t?{value:t,label:t,dismissable:!0}:null}if(!e||typeof e!=`object`)return null;let t=e,n=String(t.value??``).trim();return n?{value:n,label:String(t.label??n),dismissable:t.dismissable!==!1}:null}).filter(e=>e!==null):[]}catch(e){return console.warn(`mint-tags: failed to parse ${t} attribute`,e),[]}}_syncAttr(){this.setAttribute(`tags`,JSON.stringify(this._tags))}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}hasError(){return this.getAttribute(`error`)===`true`}_attachContainerFocusRingListeners(){!this._container||this._containerFocusRingListeners||(this._containerFocusRingListeners=!0,this._container.addEventListener(`focusin`,()=>{this._container?.setAttribute(`data-mint-tags-active`,`true`)}),this._container.addEventListener(`focusout`,()=>{requestAnimationFrame(()=>{this._container&&(this._container.contains(document.activeElement)||this._container.removeAttribute(`data-mint-tags-active`))})}))}getErrorMessage(){return this.getAttribute(`error-message`)||``}getName(){return this.getAttribute(`name`)||``}getId(){return this.getAttribute(`id`)||``}isRequired(){return this.getAttribute(`required`)===`true`}isLoading(){return this.hasAttribute(`loading`)}isPredefinedOnly(){return this.getAttribute(`predefined-only`)===`true`}_render(){this.classList.add(`mint-tags-host`);let e=this.isLoading(),t=this.getLabel(),n=this.getInfo(),r=this.hasError(),i=this.getId()||`mint-tags-${Math.random().toString(36).substr(2,9)}`;this.getId()||this.setAttribute(`id`,i),this._container?this._input&&(this._input.placeholder=this._placeholder):(this._container=document.createElement(`div`),this._container.className=`mint-tags-field`,this._container.classList.toggle(`mint-tags-field-error`,r),this._container.addEventListener(`pointerdown`,e=>this._onContainerPointerDown(e)),this._attachContainerFocusRingListeners(),this._chipsWrap=document.createElement(`div`),this._chipsWrap.className=`mint-tags-chips`,this._chipsWrap.addEventListener(`dragover`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._chipsWrap.addEventListener(`drop`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._input=document.createElement(`input`),this._input.type=`text`,this._input.placeholder=this._placeholder,this._input.className=`mint-tags-input`,this._input.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this._addFromInput())}),this._container.appendChild(this._chipsWrap),this.appendChild(this._container)),this._input&&(this.isPredefinedOnly()&&this._predefinedTags.length>0?this._input.setAttribute(`readonly`,`true`):this._input.removeAttribute(`readonly`)),this._container&&this._container.classList.toggle(`mint-tags-field-error`,r);let a=this.querySelector(`.mint-tags-label-container`);if(t){a||(a=document.createElement(`div`),a.className=`mint-tags-label-container`,this._container&&this._container.parentElement===this?this.insertBefore(a,this._container):this.insertBefore(a,this.firstChild));let e=a.querySelector(`.mint-tags-label`);t?(e||(e=document.createElement(`label`),e.className=`mint-tags-label`,a.appendChild(e)),e.textContent=t,e.setAttribute(`for`,i)):e&&e.remove()}else a&&a.remove();let o=this.querySelector(`.mint-tags-info`);n?(o||(o=document.createElement(`span`),o.className=`mint-tags-info`,this._container&&this._container.parentElement===this?this.insertBefore(o,this._container.nextSibling):this.appendChild(o)),o.textContent=n):o&&o.remove();let s=this.getName();s?(this.setAttribute(`name`,s),this._input&&(this._input.name=s,this._input.id=i)):(this.removeAttribute(`name`),this._input&&(this._input.removeAttribute(`name`),this._input.id=i)),this._wireInputBackspace(),this._renderChips(),this._renderPredefinedPopover(),this._renderErrorState(),this._syncInputAccessibility(),this._renderSkeleton(e)}_getAvailablePredefinedTags(){let e=new Set(this._tags.map(e=>e.value.toLowerCase()));return this._predefinedTags.filter(t=>!e.has(t.value.toLowerCase()))}_shouldShowInput(){return this._input?!this.isPredefinedOnly()||!this._predefinedTags.length?!0:this._getAvailablePredefinedTags().length>0:!1}_disconnectPredefinedFieldResizeObserver(){this._predefinedFieldResizeObserver&&=(this._predefinedFieldResizeObserver.disconnect(),null),this._predefinedPopoverBodyEl=null}_syncPredefinedPopoverBodyMinWidth(e){if(!this._container)return;let t=this._container.offsetWidth;t>0?e.style.minWidth=`${Math.max(t,200)}px`:e.style.minWidth=`12rem`}_attachPredefinedFieldResizeObserver(e){if(this._disconnectPredefinedFieldResizeObserver(),!this._container||typeof ResizeObserver>`u`){this._syncPredefinedPopoverBodyMinWidth(e);return}this._predefinedPopoverBodyEl=e,this._predefinedFieldResizeObserver=new ResizeObserver(()=>{!this._predefinedPopoverBodyEl||!this._container||this._syncPredefinedPopoverBodyMinWidth(this._predefinedPopoverBodyEl)}),this._predefinedFieldResizeObserver.observe(this._container),this._syncPredefinedPopoverBodyMinWidth(e)}_renderPredefinedPopover(){if(!this._container||!this._chipsWrap||(this._disconnectPredefinedFieldResizeObserver(),this.querySelectorAll(`[data-mint-tags-predefined="true"]`).forEach(e=>e.remove()),!this._predefinedTags.length)||!this._input||!this._input.id)return;let e=this._getAvailablePredefinedTags();if(this.isPredefinedOnly()&&e.length===0)return;let t=`${this.getAttribute(`id`)||this._input.id}-tags-field`;this._container.id=t;let n=document.createElement(`mint-popover`);n.setAttribute(`trigger-id`,t),n.setAttribute(`trigger-toggle`,`false`),n.setAttribute(`trigger-align`,`start`),n.setAttribute(`direction`,`down`),n.setAttribute(`padding`,`0`),n.setAttribute(`distance`,`6px`),n.dataset.mintTagsPredefined=`true`;let r=document.createElement(`div`);if(r.dataset.mintTagsPredefinedBody=`true`,r.className=`mint-tags-options`,r.addEventListener(`mousedown`,e=>{e.preventDefault()}),e.length)e.forEach(e=>{let t=document.createElement(`mint-button`);t.setAttribute(`type`,`button`),t.setAttribute(`variant`,`ghost`),t.setAttribute(`full-width`,`true`),t.setAttribute(`align`,`left`),t.classList.add(`mint-tags-option`),t.textContent=e.label||e.value,t.addEventListener(`mousedown`,e=>{e.preventDefault()},!0),t.addEventListener(`click`,()=>{this._addTag(e),n.removeAttribute(`open`),requestAnimationFrame(()=>{this._input?.focus({preventScroll:!0}),this._container?.setAttribute(`data-mint-tags-active`,`true`)})}),r.appendChild(t)});else{let e=document.createElement(`div`);e.className=`mint-tags-empty`,e.textContent=`No tags available`,r.appendChild(e)}n.appendChild(r),this._container.appendChild(n),this._attachPredefinedPopoverOpenOnInputFocus(),this._attachPredefinedFieldResizeObserver(r)}_getPredefinedPopoverEl(){return this.querySelector(`mint-popover[data-mint-tags-predefined="true"]`)}_attachPredefinedPopoverOpenOnInputFocus(){!this._input||!this._predefinedTags.length||this._predefinedPopoverOpenListenersAttached||(this._predefinedPopoverOpenListenersAttached=!0,this._input.addEventListener(`focus`,()=>{if(this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this.isLoading())return;let e=this._getPredefinedPopoverEl();e&&e.setAttribute(`open`,`true`)}),this._input.addEventListener(`blur`,()=>{this._predefinedBlurCloseTimer!==null&&window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=window.setTimeout(()=>{if(this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose){this._suppressNextPredefinedBlurClose=!1;return}this._getPredefinedPopoverEl()?.removeAttribute(`open`)},150)}))}_renderSkeleton(e){let t=this._container;if(!t)return;let n=t.querySelector(`.mint-tags-skeleton`);e?(n||(n=document.createElement(`div`),n.className=`mint-tags-skeleton`,t.appendChild(n)),n.style.display=`block`,this._chipsWrap&&(this._chipsWrap.style.visibility=`hidden`,this._chipsWrap.style.pointerEvents=`none`),this._input&&(this._input.style.visibility=`hidden`,this._input.style.pointerEvents=`none`)):(n&&(n.style.display=`none`),this._chipsWrap&&(this._chipsWrap.style.visibility=`visible`,this._chipsWrap.style.pointerEvents=`auto`),this._input&&(this._input.style.visibility=`visible`,this._input.style.pointerEvents=`auto`))}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-tags-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-tags-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncInputAccessibility(){if(!this._input)return;let e=this.getId()||`mint-tags-${Math.random().toString(36).slice(2,10)}`;this._input.id=e;let t=this.getLabel().trim();t?this._input.setAttribute(`aria-label`,t):this._placeholder.trim()?this._input.setAttribute(`aria-label`,this._placeholder.trim()):this._input.setAttribute(`aria-label`,`Add tag`),this._input.setAttribute(`aria-invalid`,String(this.hasError()));let n=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),r=this.querySelector(`.mint-tags-info`),i=this.querySelector(`.mint-tags-error`);r&&(r.id=`${e}-info`,n.push(r.id)),i&&(i.id=`${e}-error`,n.push(i.id)),n.length?this._input.setAttribute(`aria-describedby`,Array.from(new Set(n)).join(` `)):this._input.removeAttribute(`aria-describedby`)}_renderChips(){if(!this._chipsWrap)return;this._chipsWrap.innerHTML=``;let e=0;this._tags.forEach(t=>{let n=document.createElement(`mint-chip`);n.dataset.index=String(e++),n.dataset.value=t.value,n.draggable=this.hasAttribute(`sortable`),n.draggable&&n.classList.add(`mint-tags-chip-draggable`),t.dismissable&&(n.setAttribute(`dismissable`,`true`),n.addEventListener(`dismissed`,()=>this._removeTag(t.value))),this._chipsWrap.appendChild(n);let r=n.querySelector(`[data-mt-chip-text]`);r&&(r.textContent=t.label||t.value),this._setupChipEvents(n,t),n.draggable&&(n.addEventListener(`dragstart`,e=>this._onDragStart(e,n)),n.addEventListener(`dragover`,e=>this._onDragOverChip(e,n)),n.addEventListener(`drop`,e=>this._onDrop(e)),n.addEventListener(`dragend`,()=>this._onDragEnd())),this.hasAttribute(`sortable`)&&n.addEventListener(`pointerdown`,e=>this._onPointerDown(e,n))}),this._input&&this._shouldShowInput()&&(this.hasAttribute(`sortable`)&&(this._input.addEventListener(`dragover`,e=>this._onDragOverInput(e)),this._input.addEventListener(`drop`,e=>this._onDrop(e)),this._input.addEventListener(`dragend`,()=>this._onDragEnd())),this._chipsWrap.appendChild(this._input))}_addFromInput(){if(!this._input)return;let e=this._input.value.trim();if(!e)return;if(this._tags.some(t=>t.value.toLowerCase()===e.toLowerCase())){this._input.value=``;return}let t=this._predefinedTags.find(t=>t.value.toLowerCase()===e.toLowerCase());if(this.isPredefinedOnly()){if(!t){this._input.value=``;return}this._addTag(t)}else this._addTag(t||{value:e,label:e,dismissable:!0});this._input.value=``,setTimeout(()=>{this._input?.focus()},10)}_addTag(e){this._tags.some(t=>t.value.toLowerCase()===e.value.toLowerCase())||(this._tags.push({value:e.value,label:e.label||e.value,dismissable:e.dismissable!==!1}),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange())}_removeTag(e){this._tags=this._tags.filter(t=>t.value!==e),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange()}_emitChange(){this.dispatchEvent(new CustomEvent(`tags-change`,{bubbles:!0,composed:!0,detail:{tags:this.tags}}))}_focusLastChip(){let e=this._chipsWrap?.querySelectorAll(`mint-chip`);e&&e.length>0&&e[e.length-1].focus({preventScroll:!0})}_focusInput(){setTimeout(()=>{this._input?.focus({preventScroll:!0})},10)}_wireInputBackspace(){this._input&&this._input.addEventListener(`keydown`,e=>{e.key===`Backspace`&&this._input?.value===``&&(e.preventDefault(),this._focusLastChip())})}_setupChipEvents(e,t){e.tabIndex=0,e.addEventListener(`keydown`,e=>{(e.key===`Backspace`||e.key===`Delete`)&&t.dismissable&&(e.preventDefault(),this._removeTag(t.value),this._focusInput())})}_onContainerPointerDown(e){if(!this._input||!this._input.isConnected||this._input.parentElement!==this._chipsWrap||e.button!==0||e.defaultPrevented)return;let t=e.composedPath();if(!t.some(e=>e===this._input)&&!t.some(e=>e instanceof Element&&e.closest(`mint-chip`)!=null)){this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this._suppressNextPredefinedBlurClose=!0,e.preventDefault();try{this._input.focus({preventScroll:!0})}catch{}this._predefinedTags.length>0&&this._getPredefinedPopoverEl()?.setAttribute(`open`,`true`)}}_onDragStart(e,t){this.hasAttribute(`sortable`)&&(this._dragChip=t,this._dragIndex=Number(t.dataset.index),e.dataTransfer?.setData(`text/plain`,t.dataset.index||``),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.dropEffect=`move`),t.classList.add(`mint-tags-chip-dragging`))}_reorderTags(e,t){if(e<0||t<0||e>=this._tags.length||t>=this._tags.length)return;let n=[...this._tags],[r]=n.splice(e,1);n.splice(t,0,r),this._tags=n,this._syncAttr(),this._renderChips(),this._emitChange()}_onDragOverInput(e){this.hasAttribute(`sortable`)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),this._dragChip&&this._chipsWrap&&this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input))}_onDragOverChip(e,t){if(!this.hasAttribute(`sortable`)||(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),!this._dragChip||!this._chipsWrap)||t===this._dragChip)return;let n=t.getBoundingClientRect();if(e.clientX<n.left+n.width*.5){if(this._dragChip.nextSibling===t)return;this._chipsWrap.insertBefore(this._dragChip,t)}else{if(t.nextSibling===this._dragChip)return;let e=t.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}}_onDrop(e){this.hasAttribute(`sortable`)&&e.preventDefault()}_onDragEnd(){this._dragChip&&this._dragChip.classList.remove(`mint-tags-chip-dragging`),this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}_syncOrderFromDom(){if(!this._chipsWrap)return;let e=Array.from(this._chipsWrap.querySelectorAll(`mint-chip`));if(e.length===0)return;let t=[];e.forEach(e=>{let n=e.dataset.value;if(!n)return;let r=this._tags.find(e=>e.value===n);r&&t.push(r)}),t.length===this._tags.length&&(this._tags=t,this._syncAttr(),this._renderChips(),this._emitChange())}_onPointerDown(e,t){if(this.hasAttribute(`sortable`)&&e.pointerType!==`mouse`){this._isPointerDragging=!0,this._dragChip=t,this._dragIndex=Number(t.dataset.index);try{t.setPointerCapture(e.pointerId)}catch{}t.classList.add(`mint-tags-chip-dragging`,`mint-tags-chip-no-select`),e.preventDefault()}}_onPointerMove(e){if(!this._isPointerDragging||!this._dragChip||!this._chipsWrap||e.pointerType===`mouse`)return;let t=document.elementFromPoint(e.clientX,e.clientY);if(!t)return;let n=t.closest(`mint-chip`);if(n&&n!==this._dragChip){let t=n.getBoundingClientRect();if(e.clientX<t.left+t.width*.5)this._dragChip.nextSibling!==n&&this._chipsWrap.insertBefore(this._dragChip,n);else if(n.nextSibling!==this._dragChip){let e=n.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}return}this._input&&t.closest(`input`)===this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input)}_onPointerUp(e){if(this._isPointerDragging){if(this._isPointerDragging=!1,this._dragChip){try{this._dragChip.releasePointerCapture(e.pointerId)}catch{}this._dragChip.classList.remove(`mint-tags-chip-dragging`,`mint-tags-chip-no-select`)}this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}}};customElements.get(`mint-tags`)||e.t(`mint-tags`,t),module.exports=t;
1
+ require(`../chunks/icon-B_7c8b8e.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/button-DbxqmBWQ.js`),require(`../chunks/chip-8BYSJ7yI.js`),require(`../chunks/popover-BeaGf_JC.js`);var t=class extends HTMLElement{constructor(...e){super(...e),this._container=null,this._chipsWrap=null,this._input=null,this._tags=[],this._predefinedTags=[],this._placeholder=`Add tag`,this._predefinedPopoverOpenListenersAttached=!1,this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose=!1,this._dragIndex=null,this._dragChip=null,this._isPointerDragging=!1,this._pointerMoveHandler=null,this._pointerUpHandler=null,this._containerFocusRingListeners=!1,this._predefinedFieldResizeObserver=null,this._predefinedPopoverBodyEl=null}static get observedAttributes(){return[`tags`,`placeholder`,`predefined-tags`,`predefined-only`,`sortable`,`label`,`info`,`error`,`error-message`,`name`,`id`,`required`,`loading`]}connectedCallback(){this._parseAttrs(),this._render(),this._pointerMoveHandler||(this._pointerMoveHandler=e=>this._onPointerMove(e),window.addEventListener(`pointermove`,this._pointerMoveHandler)),this._pointerUpHandler||(this._pointerUpHandler=e=>this._onPointerUp(e),window.addEventListener(`pointerup`,this._pointerUpHandler),window.addEventListener(`pointercancel`,this._pointerUpHandler))}disconnectedCallback(){this._disconnectPredefinedFieldResizeObserver()}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._syncInputAccessibility(),this._container&&this._container.classList.toggle(`mint-tags-field-error`,this.hasError());return}if(e===`loading`){this._parseAttrs(),this._render();return}this._parseAttrs(),this._render()}}set tags(e){this._tags=Array.isArray(e)?[...e]:[],this._syncAttr(),this._render()}get tags(){return[...this._tags]}_parseAttrs(){let e=this.getAttribute(`tags`);e&&(this._tags=this._parseTagItems(e,`tags`));let t=this.getAttribute(`placeholder`);t!==null&&(this._placeholder=t);let n=this.getAttribute(`predefined-tags`);this._predefinedTags=this._parseTagItems(n,`predefined-tags`)}_parseTagItems(e,t){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{if(typeof e==`string`){let t=e.trim();return t?{value:t,label:t,dismissable:!0}:null}if(!e||typeof e!=`object`)return null;let t=e,n=String(t.value??``).trim();return n?{value:n,label:String(t.label??n),dismissable:t.dismissable!==!1}:null}).filter(e=>e!==null):[]}catch(e){return console.warn(`mint-tags: failed to parse ${t} attribute`,e),[]}}_syncAttr(){this.setAttribute(`tags`,JSON.stringify(this._tags))}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}hasError(){return this.getAttribute(`error`)===`true`}_attachContainerFocusRingListeners(){!this._container||this._containerFocusRingListeners||(this._containerFocusRingListeners=!0,this._container.addEventListener(`focusin`,()=>{this._container?.setAttribute(`data-mint-tags-active`,`true`)}),this._container.addEventListener(`focusout`,()=>{requestAnimationFrame(()=>{this._container&&(this._container.contains(document.activeElement)||this._container.removeAttribute(`data-mint-tags-active`))})}))}getErrorMessage(){return this.getAttribute(`error-message`)||``}getName(){return this.getAttribute(`name`)||``}getId(){return this.getAttribute(`id`)||``}isRequired(){return this.getAttribute(`required`)===`true`}isLoading(){return this.hasAttribute(`loading`)}isPredefinedOnly(){return this.getAttribute(`predefined-only`)===`true`}_render(){this.classList.add(`mint-tags-host`);let e=this.isLoading(),t=this.getLabel(),n=this.getInfo(),r=this.hasError(),i=this.getId()||`mint-tags-${Math.random().toString(36).substr(2,9)}`;this.getId()||this.setAttribute(`id`,i),this._container?this._input&&(this._input.placeholder=this._placeholder):(this._container=document.createElement(`div`),this._container.className=`mint-tags-field`,this._container.classList.toggle(`mint-tags-field-error`,r),this._container.addEventListener(`pointerdown`,e=>this._onContainerPointerDown(e)),this._attachContainerFocusRingListeners(),this._chipsWrap=document.createElement(`div`),this._chipsWrap.className=`mint-tags-chips`,this._chipsWrap.addEventListener(`dragover`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._chipsWrap.addEventListener(`drop`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._input=document.createElement(`input`),this._input.type=`text`,this._input.placeholder=this._placeholder,this._input.className=`mint-tags-input`,this._input.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this._addFromInput())}),this._container.appendChild(this._chipsWrap),this.appendChild(this._container)),this._input&&(this.isPredefinedOnly()&&this._predefinedTags.length>0?this._input.setAttribute(`readonly`,`true`):this._input.removeAttribute(`readonly`)),this._container&&this._container.classList.toggle(`mint-tags-field-error`,r);let a=this.querySelector(`.mint-tags-label-container`);if(t){a||(a=document.createElement(`div`),a.className=`mint-tags-label-container`,this._container&&this._container.parentElement===this?this.insertBefore(a,this._container):this.insertBefore(a,this.firstChild));let e=a.querySelector(`.mint-tags-label`);t?(e||(e=document.createElement(`label`),e.className=`mint-tags-label`,a.appendChild(e)),e.textContent=t,e.setAttribute(`for`,i)):e&&e.remove()}else a&&a.remove();let o=this.querySelector(`.mint-tags-info`);n?(o||(o=document.createElement(`span`),o.className=`mint-tags-info`,this._container&&this._container.parentElement===this?this.insertBefore(o,this._container.nextSibling):this.appendChild(o)),o.textContent=n):o&&o.remove();let s=this.getName();s?(this.setAttribute(`name`,s),this._input&&(this._input.name=s,this._input.id=i)):(this.removeAttribute(`name`),this._input&&(this._input.removeAttribute(`name`),this._input.id=i)),this._wireInputBackspace(),this._renderChips(),this._renderPredefinedPopover(),this._renderErrorState(),this._syncInputAccessibility(),this._renderSkeleton(e)}_getAvailablePredefinedTags(){let e=new Set(this._tags.map(e=>e.value.toLowerCase()));return this._predefinedTags.filter(t=>!e.has(t.value.toLowerCase()))}_shouldShowInput(){return this._input?!this.isPredefinedOnly()||!this._predefinedTags.length?!0:this._getAvailablePredefinedTags().length>0:!1}_disconnectPredefinedFieldResizeObserver(){this._predefinedFieldResizeObserver&&=(this._predefinedFieldResizeObserver.disconnect(),null),this._predefinedPopoverBodyEl=null}_syncPredefinedPopoverBodyMinWidth(e){if(!this._container)return;let t=this._container.offsetWidth;t>0?e.style.minWidth=`${Math.max(t,200)}px`:e.style.minWidth=`12rem`}_attachPredefinedFieldResizeObserver(e){if(this._disconnectPredefinedFieldResizeObserver(),!this._container||typeof ResizeObserver>`u`){this._syncPredefinedPopoverBodyMinWidth(e);return}this._predefinedPopoverBodyEl=e,this._predefinedFieldResizeObserver=new ResizeObserver(()=>{!this._predefinedPopoverBodyEl||!this._container||this._syncPredefinedPopoverBodyMinWidth(this._predefinedPopoverBodyEl)}),this._predefinedFieldResizeObserver.observe(this._container),this._syncPredefinedPopoverBodyMinWidth(e)}_renderPredefinedPopover(){if(!this._container||!this._chipsWrap)return;let e=this._getPredefinedPopoverEl();if(this._disconnectPredefinedFieldResizeObserver(),!this._predefinedTags.length){e?.remove();return}if(!this._input||!this._input.id)return;let t=this._getAvailablePredefinedTags();if(this.isPredefinedOnly()&&t.length===0){e?.remove();return}let n=`${this.getAttribute(`id`)||this._input.id}-tags-field`;this._container.id=n;let r=e||document.createElement(`mint-popover`);e||(r.setAttribute(`trigger-id`,n),r.setAttribute(`trigger-toggle`,`false`),r.setAttribute(`trigger-align`,`start`),r.setAttribute(`direction`,`down`),r.setAttribute(`padding`,`0`),r.setAttribute(`distance`,`6px`),r.dataset.mintTagsPredefined=`true`);let i=document.createElement(`ul`);i.dataset.mintTagsPredefinedBody=`true`,i.className=`mint-tags-options`,i.setAttribute(`role`,`list`);let a=[];if(i.addEventListener(`mousedown`,e=>{e.preventDefault()}),t.length)t.forEach(e=>{let t=document.createElement(`li`);t.className=`mint-tags-option-item`;let n=document.createElement(`mint-button`);n.setAttribute(`type`,`button`),n.setAttribute(`variant`,`ghost`),n.setAttribute(`full-width`,`true`),n.setAttribute(`align`,`left`),n.classList.add(`mint-tags-option`);let r=e.label||e.value;a.push({option:n,label:r}),n.addEventListener(`mousedown`,e=>{e.preventDefault()},!0),n.addEventListener(`click`,()=>{this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this._suppressNextPredefinedBlurClose=!0,this._addTag(e),requestAnimationFrame(()=>{this._suppressNextPredefinedBlurClose=!1,this._input?.focus({preventScroll:!0}),this._container?.setAttribute(`data-mint-tags-active`,`true`)})}),t.appendChild(n),i.appendChild(t)});else{let e=document.createElement(`div`);e.className=`mint-tags-empty`,e.textContent=`No tags available`;let t=document.createElement(`li`);t.className=`mint-tags-option-item`,t.appendChild(e),i.appendChild(t)}if(e){let t=e.querySelector(`[data-mint-tags-predefined-body]`);t?t.replaceWith(i):r.appendChild(i)}else r.appendChild(i),this._container.appendChild(r);a.forEach(({option:e,label:t})=>{e.textContent=t}),this._attachPredefinedPopoverOpenOnInputFocus(),this._attachPredefinedFieldResizeObserver(i)}_getPredefinedPopoverEl(){return this.querySelector(`mint-popover[data-mint-tags-predefined="true"]`)}_attachPredefinedPopoverOpenOnInputFocus(){!this._input||!this._predefinedTags.length||this._predefinedPopoverOpenListenersAttached||(this._predefinedPopoverOpenListenersAttached=!0,this._input.addEventListener(`focus`,()=>{if(this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this.isLoading())return;let e=this._getPredefinedPopoverEl();e&&e.setAttribute(`open`,`true`)}),this._input.addEventListener(`blur`,()=>{this._predefinedBlurCloseTimer!==null&&window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=window.setTimeout(()=>{if(this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose){this._suppressNextPredefinedBlurClose=!1;return}this._getPredefinedPopoverEl()?.removeAttribute(`open`)},150)}))}_renderSkeleton(e){let t=this._container;if(!t)return;let n=t.querySelector(`.mint-tags-skeleton`);e?(n||(n=document.createElement(`div`),n.className=`mint-tags-skeleton`,t.appendChild(n)),n.style.display=`block`,this._chipsWrap&&(this._chipsWrap.style.visibility=`hidden`,this._chipsWrap.style.pointerEvents=`none`),this._input&&(this._input.style.visibility=`hidden`,this._input.style.pointerEvents=`none`)):(n&&(n.style.display=`none`),this._chipsWrap&&(this._chipsWrap.style.visibility=`visible`,this._chipsWrap.style.pointerEvents=`auto`),this._input&&(this._input.style.visibility=`visible`,this._input.style.pointerEvents=`auto`))}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-tags-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-tags-error`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_syncInputAccessibility(){if(!this._input)return;let e=this.getId()||`mint-tags-${Math.random().toString(36).slice(2,10)}`;this._input.id=e;let t=this.getLabel().trim();t?this._input.setAttribute(`aria-label`,t):this._placeholder.trim()?this._input.setAttribute(`aria-label`,this._placeholder.trim()):this._input.setAttribute(`aria-label`,`Add tag`),this._input.setAttribute(`aria-invalid`,String(this.hasError()));let n=(this.getAttribute(`aria-describedby`)||``).split(/\s+/).filter(Boolean),r=this.querySelector(`.mint-tags-info`),i=this.querySelector(`.mint-tags-error`);r&&(r.id=`${e}-info`,n.push(r.id)),i&&(i.id=`${e}-error`,n.push(i.id)),n.length?this._input.setAttribute(`aria-describedby`,Array.from(new Set(n)).join(` `)):this._input.removeAttribute(`aria-describedby`)}_renderChips(){if(!this._chipsWrap)return;this._chipsWrap.innerHTML=``;let e=0;this._tags.forEach(t=>{let n=document.createElement(`mint-chip`);n.dataset.index=String(e++),n.dataset.value=t.value,n.draggable=this.hasAttribute(`sortable`),n.draggable&&n.classList.add(`mint-tags-chip-draggable`),t.dismissable&&(n.setAttribute(`dismissable`,`true`),n.addEventListener(`dismissed`,()=>this._removeTag(t.value))),this._chipsWrap.appendChild(n);let r=n.querySelector(`[data-mt-chip-text]`);r&&(r.textContent=t.label||t.value),this._setupChipEvents(n,t),n.draggable&&(n.addEventListener(`dragstart`,e=>this._onDragStart(e,n)),n.addEventListener(`dragover`,e=>this._onDragOverChip(e,n)),n.addEventListener(`drop`,e=>this._onDrop(e)),n.addEventListener(`dragend`,()=>this._onDragEnd())),this.hasAttribute(`sortable`)&&n.addEventListener(`pointerdown`,e=>this._onPointerDown(e,n))}),this._input&&this._shouldShowInput()&&(this.hasAttribute(`sortable`)&&(this._input.addEventListener(`dragover`,e=>this._onDragOverInput(e)),this._input.addEventListener(`drop`,e=>this._onDrop(e)),this._input.addEventListener(`dragend`,()=>this._onDragEnd())),this._chipsWrap.appendChild(this._input))}_addFromInput(){if(!this._input)return;let e=this._input.value.trim();if(!e)return;if(this._tags.some(t=>t.value.toLowerCase()===e.toLowerCase())){this._input.value=``;return}let t=this._predefinedTags.find(t=>t.value.toLowerCase()===e.toLowerCase());if(this.isPredefinedOnly()){if(!t){this._input.value=``;return}this._addTag(t)}else this._addTag(t||{value:e,label:e,dismissable:!0});this._input.value=``,setTimeout(()=>{this._input?.focus()},10)}_addTag(e){this._tags.some(t=>t.value.toLowerCase()===e.value.toLowerCase())||(this._tags.push({value:e.value,label:e.label||e.value,dismissable:e.dismissable!==!1}),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange())}_removeTag(e){this._tags=this._tags.filter(t=>t.value!==e),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange()}_emitChange(){this.dispatchEvent(new CustomEvent(`tags-change`,{bubbles:!0,composed:!0,detail:{tags:this.tags}}))}_focusLastChip(){let e=this._chipsWrap?.querySelectorAll(`mint-chip`);e&&e.length>0&&e[e.length-1].focus({preventScroll:!0})}_focusInput(){setTimeout(()=>{this._input?.focus({preventScroll:!0})},10)}_wireInputBackspace(){this._input&&this._input.addEventListener(`keydown`,e=>{e.key===`Backspace`&&this._input?.value===``&&(e.preventDefault(),this._focusLastChip())})}_setupChipEvents(e,t){e.tabIndex=0,e.addEventListener(`keydown`,e=>{(e.key===`Backspace`||e.key===`Delete`)&&t.dismissable&&(e.preventDefault(),this._removeTag(t.value),this._focusInput())})}_onContainerPointerDown(e){if(!this._input||!this._input.isConnected||this._input.parentElement!==this._chipsWrap||e.button!==0||e.defaultPrevented)return;let t=e.composedPath();if(!t.some(e=>e===this._input)&&!t.some(e=>e instanceof Element&&e.closest(`mint-chip`)!=null)){this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this._suppressNextPredefinedBlurClose=!0,e.preventDefault();try{this._input.focus({preventScroll:!0})}catch{}this._predefinedTags.length>0&&this._getPredefinedPopoverEl()?.setAttribute(`open`,`true`)}}_onDragStart(e,t){this.hasAttribute(`sortable`)&&(this._dragChip=t,this._dragIndex=Number(t.dataset.index),e.dataTransfer?.setData(`text/plain`,t.dataset.index||``),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.dropEffect=`move`),t.classList.add(`mint-tags-chip-dragging`))}_reorderTags(e,t){if(e<0||t<0||e>=this._tags.length||t>=this._tags.length)return;let n=[...this._tags],[r]=n.splice(e,1);n.splice(t,0,r),this._tags=n,this._syncAttr(),this._renderChips(),this._emitChange()}_onDragOverInput(e){this.hasAttribute(`sortable`)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),this._dragChip&&this._chipsWrap&&this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input))}_onDragOverChip(e,t){if(!this.hasAttribute(`sortable`)||(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),!this._dragChip||!this._chipsWrap)||t===this._dragChip)return;let n=t.getBoundingClientRect();if(e.clientX<n.left+n.width*.5){if(this._dragChip.nextSibling===t)return;this._chipsWrap.insertBefore(this._dragChip,t)}else{if(t.nextSibling===this._dragChip)return;let e=t.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}}_onDrop(e){this.hasAttribute(`sortable`)&&e.preventDefault()}_onDragEnd(){this._dragChip&&this._dragChip.classList.remove(`mint-tags-chip-dragging`),this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}_syncOrderFromDom(){if(!this._chipsWrap)return;let e=Array.from(this._chipsWrap.querySelectorAll(`mint-chip`));if(e.length===0)return;let t=[];e.forEach(e=>{let n=e.dataset.value;if(!n)return;let r=this._tags.find(e=>e.value===n);r&&t.push(r)}),t.length===this._tags.length&&(this._tags=t,this._syncAttr(),this._renderChips(),this._emitChange())}_onPointerDown(e,t){if(this.hasAttribute(`sortable`)&&e.pointerType!==`mouse`){this._isPointerDragging=!0,this._dragChip=t,this._dragIndex=Number(t.dataset.index);try{t.setPointerCapture(e.pointerId)}catch{}t.classList.add(`mint-tags-chip-dragging`,`mint-tags-chip-no-select`),e.preventDefault()}}_onPointerMove(e){if(!this._isPointerDragging||!this._dragChip||!this._chipsWrap||e.pointerType===`mouse`)return;let t=document.elementFromPoint(e.clientX,e.clientY);if(!t)return;let n=t.closest(`mint-chip`);if(n&&n!==this._dragChip){let t=n.getBoundingClientRect();if(e.clientX<t.left+t.width*.5)this._dragChip.nextSibling!==n&&this._chipsWrap.insertBefore(this._dragChip,n);else if(n.nextSibling!==this._dragChip){let e=n.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}return}this._input&&t.closest(`input`)===this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input)}_onPointerUp(e){if(this._isPointerDragging){if(this._isPointerDragging=!1,this._dragChip){try{this._dragChip.releasePointerCapture(e.pointerId)}catch{}this._dragChip.classList.remove(`mint-tags-chip-dragging`,`mint-tags-chip-no-select`)}this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}}};customElements.get(`mint-tags`)||e.t(`mint-tags`,t),module.exports=t;