monobill-mintui 0.6.631 → 0.6.633

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.
@@ -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) => {
@@ -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`){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;
@@ -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) => {
@@ -211,7 +211,7 @@ var t = {
211
211
  return e !== null && e !== "false";
212
212
  }
213
213
  constructor() {
214
- super(), this._configuration = null, this._rows = [], this._search = "", this._currentPage = 1, this._perPage = 15, this._totalRows = 0, this._lastPage = 0, this._offset = 0, this._loaded = !1, this._fetching = !1, this._loading = !1, this._loadingPage = null, this._fetchError = null, this._searching = !1, this._sorting = !1, this._sortingColumn = null, this._type = "provided", this._searchTimeoutId = null, this._sortTimeoutId = null, this._searchColumns = [], this._exportColumns = {}, this._columns = [], this._tableId = "", this._searchInput = null, this._tableContainer = null, this._paginationContainer = null, this._skeletonContainer = null, this._inMintCard = !1, this._virtualBodyScrollEl = null, this._virtualScrollHandler = null, this._virtualWindowRaf = null, this._virtualLastRangeStart = -1, this._virtualLastRangeEnd = -1, this._virtualLastRangeCacheSig = "", this._virtualResizeObserver = null, this._virtualWindowResizeHandler = null, this._virtualRowCache = /* @__PURE__ */ new Map(), this._virtualRangeFetching = !1, this._mobileListMql = null, this._boundMobileListMqlListener = null, this._virtualFetchGeneration = 0, this._virtualAjaxPrefetchTimer = null, this._fixedChromeResizeObserver = null, this._utilityClassObserver = null;
214
+ super(), this._configuration = null, this._rows = [], this._search = "", this._currentPage = 1, this._perPage = 15, this._totalRows = 0, this._lastPage = 0, this._offset = 0, this._loaded = !1, this._fetching = !1, this._loading = !1, this._loadingPage = null, this._fetchError = null, this._searching = !1, this._sorting = !1, this._sortingColumnData = null, this._type = "provided", this._searchTimeoutId = null, this._sortTimeoutId = null, this._searchColumns = [], this._exportColumns = {}, this._columns = [], this._tableId = "", this._searchInput = null, this._tableContainer = null, this._paginationContainer = null, this._skeletonContainer = null, this._inMintCard = !1, this._virtualBodyScrollEl = null, this._virtualScrollHandler = null, this._virtualWindowRaf = null, this._virtualLastRangeStart = -1, this._virtualLastRangeEnd = -1, this._virtualLastRangeCacheSig = "", this._virtualResizeObserver = null, this._virtualWindowResizeHandler = null, this._virtualRowCache = /* @__PURE__ */ new Map(), this._virtualRangeFetching = !1, this._mobileListMql = null, this._boundMobileListMqlListener = null, this._virtualFetchGeneration = 0, this._virtualAjaxPrefetchTimer = null, this._fixedChromeResizeObserver = null, this._utilityClassObserver = null;
215
215
  }
216
216
  get inMintCard() {
217
217
  return this._inMintCard;
@@ -290,7 +290,7 @@ var t = {
290
290
  let u = Math.floor(o / a) + 1;
291
291
  r.content?.current_page !== void 0 && r.content.current_page === u ? this._currentPage = r.content.current_page : this._currentPage = u, this._offset = (this._currentPage - 1) * a, this._lastPage = r.content?.last_page || 1, this._fetching = !1, this._loaded = !0, this._loading = !1, this._fetchError = null, this._searching = !1;
292
292
  let d = this._sorting;
293
- d && this._updateSortIcons(), this._sorting = !1, this._sortingColumn = null, d && this._updateSortIcons(), this.dispatchEvent(new CustomEvent("loaded", { detail: { rows: this._rows } })), this._updateSearchIcon();
293
+ this._sorting = !1, this._sortingColumnData = null, this.dispatchEvent(new CustomEvent("loaded", { detail: { rows: this._rows } })), this._updateSearchIcon();
294
294
  let f = `tbody[data-mint-rt-tbody="${this._tableId}"]`, p = !!this.querySelector(f);
295
295
  if (this._virtualScrollActive() && this._type === "ajax") p || this.render(), s.forEach((e, t) => {
296
296
  this._virtualRowCache.set(o + t, e);
@@ -312,8 +312,9 @@ var t = {
312
312
  });
313
313
  }, 0);
314
314
  } else this.render();
315
+ d && this._updateSortIcons();
315
316
  } catch (e) {
316
- this._fetching = !1, this._loading = !1, this._loadingPage = null, this._loaded = !0, this._searching = !1, this._fetchError = e instanceof Error ? e.message : "Failed to fetch data", console.error("mint-resource-table: Error fetching data", e), this._updateSearchIcon(), this.querySelector(`#${this._tableId}`)?.closest("table")?.querySelector("tbody") ? (this._updateTableBody(), this._loadingPage = null, this._updatePagination()) : this.render();
317
+ this._fetching = !1, this._loading = !1, this._loadingPage = null, this._loaded = !0, this._searching = !1, this._fetchError = e instanceof Error ? e.message : "Failed to fetch data", console.error("mint-resource-table: Error fetching data", e), this._sorting && (this._sorting = !1, this._sortingColumnData = null, this._updateSortIcons()), this._updateSearchIcon(), this.querySelector(`#${this._tableId}`)?.closest("table")?.querySelector("tbody") ? (this._updateTableBody(), this._loadingPage = null, this._updatePagination()) : this.render();
317
318
  }
318
319
  }
319
320
  _getRows() {
@@ -883,18 +884,18 @@ var t = {
883
884
  _toggleSort(e) {
884
885
  if (!this._configuration || !e.data || !e.sortable) return;
885
886
  let t = e.data;
886
- if (this._sortTimeoutId !== null && (clearTimeout(this._sortTimeoutId), this._sortTimeoutId = null), this._sorting = !0, this._sortingColumn = e, this._updateSortIcons(), this._type === "ajax") this._sortTimeoutId = window.setTimeout(() => {
887
+ if (this._sortTimeoutId !== null && (clearTimeout(this._sortTimeoutId), this._sortTimeoutId = null), this._sorting = !0, this._sortingColumnData = t.toLowerCase(), this._updateSortIcons(), this._type === "ajax") this._sortTimeoutId = window.setTimeout(() => {
887
888
  if (this._sortTimeoutId = null, !this._configuration || !t || !e.sortable) return;
888
889
  let n = this._configuration.sort || "asc";
889
890
  this._configuration.sortBy?.toLowerCase() === t.toLowerCase() && (n = n === "desc" ? "asc" : "desc"), this._configuration.sort = n, this._configuration.sortBy = t, this._updateSortIcons(), this._offset = 0, this._currentPage = 1, this._fetching = !1, this._loading = !1, this._fetchData(void 0, !1, this._perPage, 0);
890
891
  }, 10);
891
892
  else {
892
893
  let e = this._configuration.sort || "asc";
893
- this._configuration.sortBy?.toLowerCase() === t.toLowerCase() && (e = e === "desc" ? "asc" : "desc"), this._configuration.sort = e, this._configuration.sortBy = t, this._currentPage = 1, this._sorting = !1, this._sortingColumn = null, this._updateSortIcons(), this.render(), this._virtualScrollActive() && queueMicrotask(() => this._scrollVirtualTableTopIntoView());
894
+ this._configuration.sortBy?.toLowerCase() === t.toLowerCase() && (e = e === "desc" ? "asc" : "desc"), this._configuration.sort = e, this._configuration.sortBy = t, this._currentPage = 1, this._sorting = !1, this._sortingColumnData = null, this._updateSortIcons(), this.render(), this._virtualScrollActive() && queueMicrotask(() => this._scrollVirtualTableTopIntoView());
894
895
  }
895
896
  }
896
897
  _getSortClass(e) {
897
- return this._sorting && this._sortingColumn === e ? "spinner" : this._configuration?.sortBy?.toLowerCase() === e.data?.toLowerCase() ? this._configuration?.sort?.toLowerCase() === "desc" ? "caret-down" : "caret-up" : "";
898
+ return this._sorting && this._sortingColumnData === e.data?.toLowerCase() ? "spinner" : this._configuration?.sortBy?.toLowerCase() === e.data?.toLowerCase() ? this._configuration?.sort?.toLowerCase() === "desc" ? "caret-down" : "caret-up" : "";
898
899
  }
899
900
  _updateSortIcons() {
900
901
  if (!this._configuration) return;
@@ -902,12 +903,12 @@ var t = {
902
903
  if (!e.sortable || e.hidden) return;
903
904
  let n = this.querySelector(`th[data-column-key="${t}"]`);
904
905
  if (!n) return;
905
- let r = n.querySelector(":scope > div.flex.items-center");
906
+ let r = n.querySelector(":scope > [data-mint-rt-sort-label]");
906
907
  if (!r) return;
907
- let i = r.querySelector(":scope > div.ml-2.flex.items-center"), a = this._getSortClass(e), o = () => {
908
+ let i = r.querySelector(":scope > [data-mint-rt-sort-icon]"), a = this._getSortClass(e), o = () => {
908
909
  if (!i) {
909
910
  let e = document.createElement("div");
910
- e.className = "ml-2 flex items-center", r.appendChild(e), i = e;
911
+ e.className = "ml-2 flex items-center", e.setAttribute("data-mint-rt-sort-icon", ""), r.appendChild(e), i = e;
911
912
  }
912
913
  return i;
913
914
  }, s = () => {
@@ -915,15 +916,10 @@ var t = {
915
916
  };
916
917
  if (a === "spinner") {
917
918
  let e = o();
918
- if (e.querySelector("mint-icon")?.remove(), !e.querySelector("mint-spinner")) {
919
- let t = document.createElement("mint-spinner");
920
- t.className = "w-4 h-4", e.appendChild(t);
921
- }
919
+ e.firstElementChild?.tagName !== "MINT-SPINNER" && (e.innerHTML = "<mint-spinner class=\"w-4 h-4\"></mint-spinner>");
922
920
  } else if (a === "caret-up" || a === "caret-down") {
923
- let e = o();
924
- e.querySelector("mint-spinner")?.remove();
925
- let t = e.querySelector("mint-icon");
926
- t || (t = document.createElement("mint-icon"), e.appendChild(t)), t.setAttribute("name", a), t.className = "w-4 h-4";
921
+ let e = o(), t = e.firstElementChild;
922
+ (t?.tagName !== "MINT-ICON" || t.getAttribute("name") !== a) && (e.innerHTML = `<mint-icon name="${a}" class="w-4 h-4"></mint-icon>`);
927
923
  } else s();
928
924
  }), this._syncMobileSortPopoverIcons();
929
925
  let e = this.querySelector(`#mint-rt-mobile-sort-btn-${this._tableId}`);
@@ -1072,6 +1068,16 @@ var t = {
1072
1068
  break;
1073
1069
  }
1074
1070
  }
1071
+ _toolbarButtonsHtml(e) {
1072
+ let t = (this._configuration?.buttons || []).map((e, t) => ({
1073
+ button: e,
1074
+ index: t
1075
+ })).filter(({ button: t }) => (t.position || "right") === e);
1076
+ return t.length ? `<div class="flex shrink-0 items-center gap-2">${t.map(({ button: e, index: t }) => {
1077
+ let n = e.icon ? ` icon="${this._escapeHtml(e.icon)}"` : "", r = e.tone ? ` tone="${this._escapeHtml(e.tone)}"` : "", i = e.icon === "plus" ? "solid" : e.variant || "solid", a = this._escapeHtml(i), o = this._escapeHtml(e.class || ""), s = e.ariaLabel ? ` aria-label="${this._escapeHtml(e.ariaLabel)}"` : "";
1078
+ return `<mint-button variant="${a}" class="${o}" data-button-type="${this._escapeHtml(e.type || "custom")}" data-button-index="${t}"${n}${r}${s}>${e.label ? this._escapeHtml(e.label) : ""}</mint-button>`;
1079
+ }).join("")}</div>` : "";
1080
+ }
1075
1081
  _downloadCSV() {
1076
1082
  if (!this._configuration) return;
1077
1083
  let e = this.querySelector(`#${this._tableId}`) || this.querySelector("table");
@@ -1112,9 +1118,9 @@ var t = {
1112
1118
  if (e.hidden) return;
1113
1119
  let r = n ? "" : ` width="${e.width || ""}"`, i = e.sortable ? " data-mint-rt-sortable=\"\"" : "";
1114
1120
  if (a += `<th${r} style="${this._getStyle(e)}" class="${this._getClasses(e)}" data-column-key="${t}"${i}>`, e.showLabel !== !1) {
1115
- if (a += "<div class=\"flex items-center\">", a += `<div class="flex-1">${e.raw ? e.label : this._escapeHtml(e.label)}</div>`, e.sortable) {
1121
+ if (a += "<div class=\"flex items-center\" data-mint-rt-sort-label>", a += `<div class="flex-1">${e.raw ? e.label : this._escapeHtml(e.label)}</div>`, e.sortable) {
1116
1122
  let t = this._getSortClass(e);
1117
- t === "spinner" ? a += "<div class=\"ml-2 flex items-center\"><mint-spinner class=\"w-4 h-4\"></mint-spinner></div>" : (t === "caret-up" || t === "caret-down") && (a += `<div class="ml-2 flex items-center"><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`);
1123
+ t === "spinner" ? a += "<div class=\"ml-2 flex items-center\" data-mint-rt-sort-icon><mint-spinner class=\"w-4 h-4\"></mint-spinner></div>" : (t === "caret-up" || t === "caret-down") && (a += `<div class="ml-2 flex items-center" data-mint-rt-sort-icon><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`);
1118
1124
  }
1119
1125
  a += "</div>";
1120
1126
  }
@@ -1140,14 +1146,11 @@ var t = {
1140
1146
  this._inMintCard ? "p-3.5" : "mb-3",
1141
1147
  e ? "sticky top-0 z-20 bg-white dark:bg-mint-nav border-b border-gray-200 dark:border-mint-divider" : ""
1142
1148
  ].filter(Boolean).join(" ");
1143
- if (i += `<div id="mint-rt-fixed-controls-${this._tableId}" class="${t}">`, i += "<div class=\"flex min-w-0 flex-1 items-center gap-2\">", i += this._buildMobileSortToolbarHtml(), this._configuration.showSearch !== !1) {
1149
+ if (i += `<div id="mint-rt-fixed-controls-${this._tableId}" class="${t}">`, i += "<div class=\"flex min-w-0 flex-1 items-center gap-2\">", i += this._buildMobileSortToolbarHtml(), i += this._toolbarButtonsHtml("left"), this._configuration.showSearch !== !1) {
1144
1150
  let e = `search-${this._tableId}`, t = this._escapeHtml(this._configuration.searchPlaceholder || "Search...");
1145
1151
  i += `<mint-input id="${e}" type="search" label="" placeholder="${t}" class="min-w-0 flex-1" icon="search" value="${this._escapeHtml(this._search)}"></mint-input>`;
1146
1152
  }
1147
- i += "<div class=\"flex shrink-0 items-center gap-2\">", this._configuration.buttons && this._configuration.buttons.forEach((e) => {
1148
- let t = e.icon ? ` icon="${this._escapeHtml(e.icon)}"` : "", n = e.tone ? ` tone="${this._escapeHtml(e.tone)}"` : "", r = e.variant ? this._escapeHtml(e.variant) : "solid", a = this._escapeHtml(e.class || ""), o = e.ariaLabel ? ` aria-label="${this._escapeHtml(e.ariaLabel)}"` : "";
1149
- i += `<mint-button variant="${r}" class="${a}" data-button-type="${e.type || "custom"}"${t}${n}${o}>`, e.label && (i += this._escapeHtml(e.label)), i += "</mint-button>";
1150
- }), i += "</div>", i += "</div>", i += "</div>";
1153
+ i += this._toolbarButtonsHtml("right"), i += "</div>", i += "</div>";
1151
1154
  }
1152
1155
  if ((this._type === "ajax" && !this._loaded || this._type === "provided" && r) && !this._fetchError && !this._sorting) {
1153
1156
  let e = this._fixedHeader() ? " data-mint-rt-scroll-inner=\"\"" : "", t = this._fixedHeader() && this._fixedControls(), n = this._fixedHeader() ? t ? "sticky top-[var(--mint-rt-fixed-controls-h,0px)] z-30 " : "sticky top-0 z-30 " : "sticky top-0 z-10 ";
@@ -1155,9 +1158,9 @@ var t = {
1155
1158
  if (e.hidden) return;
1156
1159
  let n = e.sortable ? " data-mint-rt-sortable=\"\"" : "";
1157
1160
  if (i += `<th width="${e.width || ""}" style="${this._getStyle(e)}" class="${this._getClasses(e)}" data-column-key="${t}"${n}>`, e.showLabel !== !1) {
1158
- if (i += "<div class=\"flex items-center\">", i += `<div class="flex-1">${e.raw ? e.label : this._escapeHtml(e.label)}</div>`, e.sortable) {
1161
+ if (i += "<div class=\"flex items-center\" data-mint-rt-sort-label>", i += `<div class="flex-1">${e.raw ? e.label : this._escapeHtml(e.label)}</div>`, e.sortable) {
1159
1162
  let t = this._getSortClass(e);
1160
- t === "spinner" ? i += "<div class=\"ml-2 flex items-center\"><mint-spinner class=\"w-4 h-4\"></mint-spinner></div>" : (t === "caret-up" || t === "caret-down") && (i += `<div class="ml-2 flex items-center"><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`);
1163
+ t === "spinner" ? i += "<div class=\"ml-2 flex items-center\" data-mint-rt-sort-icon><mint-spinner class=\"w-4 h-4\"></mint-spinner></div>" : (t === "caret-up" || t === "caret-down") && (i += `<div class="ml-2 flex items-center" data-mint-rt-sort-icon><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`);
1161
1164
  }
1162
1165
  i += "</div>";
1163
1166
  }
@@ -1269,9 +1272,9 @@ var t = {
1269
1272
  let n = parseInt(e.getAttribute("data-column-key") || "0", 10), r = this._configuration?.columns[n];
1270
1273
  r && (this._closeMobileSortPopover(), this._toggleSort(r));
1271
1274
  });
1272
- }), this.querySelectorAll("[data-button-type]").forEach((e) => {
1275
+ }), this.querySelectorAll("mint-button[data-button-index]").forEach((e) => {
1273
1276
  e.addEventListener("click", () => {
1274
- let t = e.getAttribute("data-button-type"), n = this._configuration?.buttons?.find((e) => (e.type || "custom") === t);
1277
+ let t = Number.parseInt(e.getAttribute("data-button-index") || "", 10), n = Number.isInteger(t) ? this._configuration?.buttons?.[t] : void 0;
1275
1278
  n && this._handleButtonClick(n);
1276
1279
  });
1277
1280
  }), this._attachPaginationListeners(), this._virtualScrollActive() && (this._type === "provided" || this._type === "ajax") && this._attachVirtualScrollListeners(), this._fixedHeader() && this._fixedControls() && queueMicrotask(() => {