Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@felte/element

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@felte/element - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

2

dist/felte-field.js

@@ -131,3 +131,3 @@ /**

bubbles: true,
cancelable: true,
composed: true,
});

@@ -134,0 +134,0 @@ control.dispatchEvent(customEvent);

@@ -1,2 +0,2 @@

function e(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function t(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function n(n){return e(n)||function(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}(n)||t(n)}function i(i,r){var o;if(!n(i))return;const l=r;if(e(i)){if("checkbox"===i.type){const e=l;return void 0===e||"boolean"==typeof e?void(i.checked=!!e):void(Array.isArray(e)&&(e.includes(i.value)?i.checked=!0:i.checked=!1))}if("radio"===i.type){const e=l;return void(i.value===e?i.checked=!0:i.checked=!1)}if("file"===i.type)return i.files=null,void(i.value="")}else if(t(i)){if(i.multiple){if(Array.isArray(l)){i.value=String(null!==(o=l[0])&&void 0!==o?o:"");for(const e of i.options)l.includes(e.value)?e.selected=!0:e.selected=!1}}else{i.value=String(null!=l?l:"");for(const e of i.options)e.value===l?e.selected=!0:e.selected=!1}return}i.value=String(null!=l?l:"")}const r={attributes:!0,attributeFilter:["data-felte-validation-message","aria-invalid"]};function o(e,t){var o,l;let a,u,s,c,d,v;function h(e,t){if(!d)return;i(d,t);const n=new Event(e,{bubbles:!0,cancelable:!0});d.dispatchEvent(n)}function f(e){e.forEach((()=>{const e=d.getAttribute("aria-invalid");e?c.setAttribute("aria-invalid",e):c.removeAttribute("aria-invalid");const t=d.getAttribute("data-felte-validation-message");t?c.setAttribute("data-felte-validation-message",t):c.removeAttribute("data-felte-validation-message")}))}function m(e){v&&(i(d,u),v(e))}function p(e){h(s?"change":"input",e)}return"string"==typeof e?(a=e,u=null==t?void 0:t.defaultValue,s=null!==(o=null==t?void 0:t.touchOnChange)&&void 0!==o&&o,v=null==t?void 0:t.onFormReset):(a=e.name,u=e.defaultValue,s=null!==(l=e.touchOnChange)&&void 0!==l&&l,v=null==e?void 0:e.onFormReset),{field:function(e){let t,o;return c=e,n(e)?(d=e,d.name=a,{}):(setTimeout((()=>{const l=c.parentNode;if(!l||l.nodeType!==Node.ELEMENT_NODE)return;const s=l.querySelector(`[name="${a}"]`);if(s&&n(s))d=s;else{const t=document.createElement("input");t.type="hidden",t.name=a,l.insertBefore(t,e.nextSibling),d=t}i(d,u),t=new MutationObserver(f),t.observe(d,r),o=d.closest("form"),null==o||o.addEventListener("reset",m)})),{destroy(){null==t||t.disconnect(),null==o||o.removeEventListener("reset",m)}})},onInput:p,onChange:p,onBlur:function(){h("focusout")}}}class l extends HTMLElement{constructor(){var e;super(...arguments),this.touchOnChange=!1,this.valueProp="value",this.inputEvent="input",this.blurEvent="focusout",this.composed=!1,this._onBlur=(e="blur",function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFieldElement. The element is not ready yet.`)}),this._ready=!1}static get observedAttributes(){return["name","touchonchange","valueprop","inputevent","blurevent","composed","value"]}static get attributeMap(){return{name:{converter:String,name:"name"},touchonchange:{converter:e=>""===e||!!e&&"false"!==e,name:"touchOnChange"},valueprop:{converter:String,name:"valueProp"},inputevent:{converter:String,name:"inputEvent"},blurevent:{converter:String,name:"blurEvent"},value:{converter:String,name:"value"},composed:{converter:e=>""===e||!!e&&"false"!==e,name:"composed"}}}attributeChangedCallback(e,t,n){if(t===n)return;const{converter:i,name:r}=l.attributeMap[e];this[r]=i(n)}set value(e){var t;null===(t=this._onInput)||void 0===t||t.call(this,e),this._value=e}get value(){return this._value}blur(){this._onBlur()}get ready(){return this._ready}_createField(){var e;const{name:t,inputEvent:n,blurEvent:i,touchOnChange:r,value:l,composed:a}=this;if(!t)throw new Error('<felte-field> must have a "name" attribute');const u=this.children.item(0);if(!u)return;u[this.valueProp]=l;const{field:s,onInput:c,onBlur:d}=o(t,{touchOnChange:r,defaultValue:l,onFormReset:()=>{this.value=l,u[this.valueProp]=l}});this._onInput=c,this._onBlur=d;const{destroy:v}=s(u),h=e=>{const t=a?e.composedPath()[0]:e.target;this.value=t[this.valueProp]},f=()=>{d()};u.addEventListener(n,h),u.addEventListener(i,f),this._destroy=()=>{null==v||v(),u.removeEventListener(n,h),u.removeEventListener(n,f)},this._ready=!0,null===(e=this.onfeltefieldready)||void 0===e||e.call(this),this.dispatchEvent(new Event("feltefieldready"))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&this._createField()}))}disconnectedCallback(){var e;null===(e=this._destroy)||void 0===e||e.call(this)}}customElements.get("felte-field")||customElements.define("felte-field",l);export{l as FelteField};
function e(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function t(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function n(n){return e(n)||function(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}(n)||t(n)}function i(i,r){var o;if(!n(i))return;const l=r;if(e(i)){if("checkbox"===i.type){const e=l;return void 0===e||"boolean"==typeof e?void(i.checked=!!e):void(Array.isArray(e)&&(e.includes(i.value)?i.checked=!0:i.checked=!1))}if("radio"===i.type){const e=l;return void(i.value===e?i.checked=!0:i.checked=!1)}if("file"===i.type)return i.files=null,void(i.value="")}else if(t(i)){if(i.multiple){if(Array.isArray(l)){i.value=String(null!==(o=l[0])&&void 0!==o?o:"");for(const e of i.options)l.includes(e.value)?e.selected=!0:e.selected=!1}}else{i.value=String(null!=l?l:"");for(const e of i.options)e.value===l?e.selected=!0:e.selected=!1}return}i.value=String(null!=l?l:"")}const r={attributes:!0,attributeFilter:["data-felte-validation-message","aria-invalid"]};function o(e,t){var o,l;let a,u,s,c,d,v;function h(e,t){if(!d)return;i(d,t);const n=new Event(e,{bubbles:!0,composed:!0});d.dispatchEvent(n)}function f(e){e.forEach((()=>{const e=d.getAttribute("aria-invalid");e?c.setAttribute("aria-invalid",e):c.removeAttribute("aria-invalid");const t=d.getAttribute("data-felte-validation-message");t?c.setAttribute("data-felte-validation-message",t):c.removeAttribute("data-felte-validation-message")}))}function m(e){v&&(i(d,u),v(e))}function p(e){h(s?"change":"input",e)}return"string"==typeof e?(a=e,u=null==t?void 0:t.defaultValue,s=null!==(o=null==t?void 0:t.touchOnChange)&&void 0!==o&&o,v=null==t?void 0:t.onFormReset):(a=e.name,u=e.defaultValue,s=null!==(l=e.touchOnChange)&&void 0!==l&&l,v=null==e?void 0:e.onFormReset),{field:function(e){let t,o;return c=e,n(e)?(d=e,d.name=a,{}):(setTimeout((()=>{const l=c.parentNode;if(!l||l.nodeType!==Node.ELEMENT_NODE)return;const s=l.querySelector(`[name="${a}"]`);if(s&&n(s))d=s;else{const t=document.createElement("input");t.type="hidden",t.name=a,l.insertBefore(t,e.nextSibling),d=t}i(d,u),t=new MutationObserver(f),t.observe(d,r),o=d.closest("form"),null==o||o.addEventListener("reset",m)})),{destroy(){null==t||t.disconnect(),null==o||o.removeEventListener("reset",m)}})},onInput:p,onChange:p,onBlur:function(){h("focusout")}}}class l extends HTMLElement{constructor(){var e;super(...arguments),this.touchOnChange=!1,this.valueProp="value",this.inputEvent="input",this.blurEvent="focusout",this.composed=!1,this._onBlur=(e="blur",function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFieldElement. The element is not ready yet.`)}),this._ready=!1}static get observedAttributes(){return["name","touchonchange","valueprop","inputevent","blurevent","composed","value"]}static get attributeMap(){return{name:{converter:String,name:"name"},touchonchange:{converter:e=>""===e||!!e&&"false"!==e,name:"touchOnChange"},valueprop:{converter:String,name:"valueProp"},inputevent:{converter:String,name:"inputEvent"},blurevent:{converter:String,name:"blurEvent"},value:{converter:String,name:"value"},composed:{converter:e=>""===e||!!e&&"false"!==e,name:"composed"}}}attributeChangedCallback(e,t,n){if(t===n)return;const{converter:i,name:r}=l.attributeMap[e];this[r]=i(n)}set value(e){var t;null===(t=this._onInput)||void 0===t||t.call(this,e),this._value=e}get value(){return this._value}blur(){this._onBlur()}get ready(){return this._ready}_createField(){var e;const{name:t,inputEvent:n,blurEvent:i,touchOnChange:r,value:l,composed:a}=this;if(!t)throw new Error('<felte-field> must have a "name" attribute');const u=this.children.item(0);if(!u)return;u[this.valueProp]=l;const{field:s,onInput:c,onBlur:d}=o(t,{touchOnChange:r,defaultValue:l,onFormReset:()=>{this.value=l,u[this.valueProp]=l}});this._onInput=c,this._onBlur=d;const{destroy:v}=s(u),h=e=>{const t=a?e.composedPath()[0]:e.target;this.value=t[this.valueProp]},f=()=>{d()};u.addEventListener(n,h),u.addEventListener(i,f),this._destroy=()=>{null==v||v(),u.removeEventListener(n,h),u.removeEventListener(n,f)},this._ready=!0,null===(e=this.onfeltefieldready)||void 0===e||e.call(this),this.dispatchEvent(new Event("feltefieldready"))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&this._createField()}))}disconnectedCallback(){var e;null===(e=this._destroy)||void 0===e||e.call(this)}}customElements.get("felte-field")||customElements.define("felte-field",l);export{l as FelteField};
//# sourceMappingURL=felte-field.min.js.map

@@ -1,2 +0,2 @@

function e(e){let t;return function(e,...t){const r=e.subscribe(...t);return r.unsubscribe?()=>r.unsubscribe():r}(e,(e=>t=e))(),t}class t extends Error{constructor(e,t){super(e),this.name="FelteSubmitError",this.response=t}}function r(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function n(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function i(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function s(e){return r(e)||function(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}(e)||n(e)}function a(e){return e.nodeType===Node.ELEMENT_NODE}function o(e,t,r){const n=r=>String.prototype.split.call(t,r).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),i=n(/[,[\]]+?/)||n(/[,[\].]+?/);return void 0===i||i===e?r:i}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){return Object.keys(e||{}).reduce(((t,r)=>Object.assign(Object.assign({},t),{[r]:u(e[r])?l(e[r]):Array.isArray(e[r])?[...e[r]]:e[r]})),{})}function d(e,t,r){e&&(e=l(e)),u(e)||(e={});const n=Array.isArray(t)?t:t.match(/[^.[\]]+/g)||[],i=n[n.length-1];if(!i)return e;let s=e;for(let e=0;e<n.length-1;e++){const t=n[e];if(!s[t]||!u(s[t])&&!Array.isArray(s[t])){const r=n[e+1];isNaN(Number(r))?s[t]={}:s[t]=[]}s=s[t]}return s[i]=r(s[i]),e}function c(e,t,r){return d(e,t,(()=>r))}function f(e,t){return null!=t?t:s(e)?e.name:""}function v(e){if(s(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const r of e.children){if(s(r)&&t.add(r),i(r))for(const e of r.elements)s(e)&&t.add(e);r.childElementCount>0&&v(r).forEach((e=>t.add(e)))}return Array.from(t)}function h(e){for(const t of e.elements)(s(t)||i(t))&&e.hasAttribute("data-felte-keep-on-remove")&&!t.hasAttribute("data-felte-keep-on-remove")&&(t.dataset.felteKeepOnRemove=e.dataset.felteKeepOnRemove)}function m(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function y(e){var t;let a={},u={};for(const l of e.elements){if(i(l)&&h(l),!s(l)||!l.name)continue;const v=f(l);if(r(l)){if("checkbox"===l.type){if(void 0===o(a,v)){if(1===Array.from(e.querySelectorAll(`[name="${l.name}"]`)).filter((e=>!!s(e)&&v===f(e))).length){a=c(a,v,l.checked),u=c(u,v,!1);continue}a=c(a,v,l.checked?[l.value]:[]),u=c(u,v,!1);continue}Array.isArray(o(a,v))&&l.checked&&(a=d(a,v,(e=>[...e,l.value])));continue}if("radio"===l.type){if(o(a,v))continue;a=c(a,v,l.checked?l.value:void 0),u=c(u,v,!1);continue}if("file"===l.type){a=c(a,v,l.multiple?Array.from(l.files||[]):null===(t=l.files)||void 0===t?void 0:t[0]),u=c(u,v,!1);continue}}else if(n(l)){if(l.multiple){const e=Array.from(l.options).filter((e=>e.selected)).map((e=>e.value));a=c(a,v,e)}else a=c(a,v,l.value);u=c(u,v,!1);continue}const y=m(l);a=c(a,v,y),u=c(u,v,!1)}return{defaultData:a,defaultTouched:u}}function p(e,t){var i;if(!s(e))return;const a=t;if(r(e)){if("checkbox"===e.type){const t=a;return void 0===t||"boolean"==typeof t?void(e.checked=!!t):void(Array.isArray(t)&&(t.includes(e.value)?e.checked=!0:e.checked=!1))}if("radio"===e.type){const t=a;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}else if(n(e)){if(e.multiple){if(Array.isArray(a)){e.value=String(null!==(i=a[0])&&void 0!==i?i:"");for(const t of e.options)a.includes(t.value)?t.selected=!0:t.selected=!1}}else{e.value=String(null!=a?a:"");for(const t of e.options)t.value===a?t.selected=!0:t.selected=!1}return}e.value=String(null!=a?a:"")}function b(e,t){for(const r of e.elements){if(i(r)&&h(r),!s(r)||!r.name)continue;p(r,o(t,f(r)))}}
function e(e){let t;return function(e,...t){const r=e.subscribe(...t);return r.unsubscribe?()=>r.unsubscribe():r}(e,(e=>t=e))(),t}class t extends Error{constructor(e,t){super(e),this.name="FelteSubmitError",this.response=t}}function r(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function n(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function i(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function s(e){return r(e)||function(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}(e)||n(e)}function a(e){return e.nodeType===Node.ELEMENT_NODE}function o(e,t,r){const n=r=>String.prototype.split.call(t,r).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),i=n(/[,[\]]+?/)||n(/[,[\].]+?/);return void 0===i||i===e?r:i}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){return Object.keys(e||{}).reduce(((t,r)=>Object.assign(Object.assign({},t),{[r]:u(e[r])?l(e[r]):Array.isArray(e[r])?[...e[r]]:e[r]})),{})}function d(e,t,r){e&&(e=l(e)),u(e)||(e={});const n=Array.isArray(t)?t:t.match(/[^.[\]]+/g)||[],i=n[n.length-1];if(!i)return e;let s=e;for(let e=0;e<n.length-1;e++){const t=n[e];if(!s[t]||!u(s[t])&&!Array.isArray(s[t])){const r=n[e+1];isNaN(Number(r))?s[t]={}:s[t]=[]}s=s[t]}return s[i]=r(s[i]),e}function c(e,t,r){return d(e,t,(()=>r))}function f(e,t){return null!=t?t:s(e)?e.name:""}function v(e){if(s(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const r of e.children){if(s(r)&&t.add(r),i(r))for(const e of r.elements)s(e)&&t.add(e);r.childElementCount>0&&v(r).forEach((e=>t.add(e)))}return Array.from(t)}function h(e){for(const t of e.elements)(s(t)||i(t))&&e.hasAttribute("data-felte-keep-on-remove")&&!t.hasAttribute("data-felte-keep-on-remove")&&(t.dataset.felteKeepOnRemove=e.dataset.felteKeepOnRemove)}function m(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function y(e){var t;let a={},u={};for(const l of e.elements){if(i(l)&&h(l),!s(l)||!l.name)continue;const v=f(l);if(r(l)){if("checkbox"===l.type){if(void 0===o(a,v)){if(1===Array.from(e.querySelectorAll(`[name="${l.name}"]`)).filter((e=>!!s(e)&&v===f(e))).length){a=c(a,v,l.checked),u=c(u,v,!1);continue}a=c(a,v,l.checked?[l.value]:[]),u=c(u,v,!1);continue}Array.isArray(o(a,v))&&l.checked&&(a=d(a,v,(e=>[...e,l.value])));continue}if("radio"===l.type){if(o(a,v))continue;a=c(a,v,l.checked?l.value:void 0),u=c(u,v,!1);continue}if("file"===l.type){a=c(a,v,l.multiple?Array.from(l.files||[]):null===(t=l.files)||void 0===t?void 0:t[0]),u=c(u,v,!1);continue}}else if(n(l)){if(l.multiple){const e=Array.from(l.options).filter((e=>e.selected)).map((e=>e.value));a=c(a,v,e)}else a=c(a,v,l.value);u=c(u,v,!1);continue}const y=m(l);a=c(a,v,y),u=c(u,v,!1)}return{defaultData:a,defaultTouched:u}}function b(e,t){var i;if(!s(e))return;const a=t;if(r(e)){if("checkbox"===e.type){const t=a;return void 0===t||"boolean"==typeof t?void(e.checked=!!t):void(Array.isArray(t)&&(t.includes(e.value)?e.checked=!0:e.checked=!1))}if("radio"===e.type){const t=a;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}else if(n(e)){if(e.multiple){if(Array.isArray(a)){e.value=String(null!==(i=a[0])&&void 0!==i?i:"");for(const t of e.options)a.includes(t.value)?t.selected=!0:t.selected=!1}}else{e.value=String(null!=a?a:"");for(const t of e.options)t.value===a?t.selected=!0:t.selected=!1}return}e.value=String(null!=a?a:"")}function p(e,t){for(const r of e.elements){if(i(r)&&h(r),!s(r)||!r.name)continue;b(r,o(t,f(r)))}}
/*! *****************************************************************************

@@ -29,3 +29,3 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function V(e){return function(t){if(u(t)){return function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(_(t,e),["key"])}return e}}function _(e,t){return A(e,(e=>u(e)?_(e,t):Array.isArray(e)?e.map(V(t)):t))}function F(e,t){if(!e||Object(e)!==e)return;void 0!==e&&(e=l(e));const r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[],n=1===r.length?e:o(e,r.slice(0,-1).join("."));return Array.isArray(n)?n.splice(Number(r[r.length-1]),1):null==n||delete n[r[r.length-1]],e}function j(e,t,r,n){return d(e,t,(e=>void 0===e||Array.isArray(e)?(e||(e=[]),void 0===n?e.push(r):e.splice(n,0,r),e):e))}function k(e){return"function"==typeof e}function T(e){return(t,r)=>{if("string"==typeof t){const n=t;e((e=>{const t=k(r)?r(o(e,n)):r;return c(e,n,t)}))}else e((e=>k(t)?t(e):t))}}function D({stores:t,config:r,validateErrors:n,validateWarnings:i}){var s;let a,f=S(null!==(s=r.initialValues)&&void 0!==s?s:{});const{data:v,touched:h,errors:m,warnings:y,isDirty:p,isSubmitting:g,interacted:A}=t,O=T(v.update),V=T(h.update),k=T(m.update),D=T(y.update);function I(e){O((t=>{const r=e(t);return a&&b(a,r),r}))}const x=(e,t,r)=>{T(I)(e,t),"string"==typeof e&&r&&V(e,!0)};function L(e){m.update(e),y.update(e),h.update(e),v.update((t=>{const r=e(t);return setTimeout((()=>a&&b(a,r))),r}))}const C=T(g.update),N=T(p.update),P=T(A.update);return{public:{setData:O,setFields:x,setTouched:V,setErrors:k,setWarnings:D,setIsSubmitting:C,setIsDirty:N,setInteracted:P,validate:async function(){const t=e(v);h.set(E(t,!0)),A.set(null);const r=await n(t);return await i(t),r},reset:function(){x(l(f)),V((e=>_(e,!1))),A.set(null),p.set(!1)},unsetField:function(e){L((t=>F(t,e)))},resetField:function(e){const t=o(f,e),r=!!u(t)&&E(t,!1),n=u(r)?_(r,[]):[];v.update((r=>{const n=c(r,e,t);return a&&b(a,n),n})),h.update((t=>c(t,e,r))),m.update((t=>c(t,e,n))),y.update((t=>c(t,e,n)))},addField:function(e,t,r){const n=!!u(t)&&E(t,!1),i=u(n)?_(n,[]):[];t=u(t)?Object.assign(Object.assign({},t),{key:w()}):t,m.update((t=>j(t,e,i,r))),y.update((t=>j(t,e,i,r))),h.update((t=>j(t,e,n,r))),v.update((n=>{const i=j(n,e,t,r);return setTimeout((()=>a&&b(a,i))),i}))},swapFields:function(e,t,r){L((n=>function(e,t,r,n){return d(e,t,(e=>e&&Array.isArray(e)?([e[r],e[n]]=[e[n],e[r]],e):e))}(n,e,t,r)))},moveField:function(e,t,r){L((n=>function(e,t,r,n){return d(e,t,(e=>e&&Array.isArray(e)?(e.splice(n,0,e.splice(r,1)[0]),e):e))}(n,e,t,r)))},setInitialValues:e=>{f=S(e)}},private:{_setFormNode(e){a=e},_getFormNode:()=>a,_getInitialValues:()=>f}}}function I(){class e extends CustomEvent{constructor(e){super("feltesuccess",{detail:e})}}class t extends CustomEvent{constructor(e){super("felteerror",{detail:e,cancelable:!0})}setErrors(e){this.preventDefault(),this.errors=e}}class r extends Event{constructor(){super("feltesubmit",{cancelable:!0})}handleSubmit(e){this.onSubmit=e}handleError(e){this.onError=e}handleSuccess(e){this.onSuccess=e}}return{createErrorEvent:e=>new t(e),createSubmitEvent:()=>new r,createSuccessEvent:t=>new e(t)}}function x(...e){const t=e.pop(),r=l(e.shift());if(0===e.length)return r;for(const n of e){if(!n)continue;let e=t(r,n);if(void 0!==e)return e;const i=Array.from(new Set(Object.keys(r).concat(Object.keys(n))));for(const s of i)if(e=t(r[s],n[s]),void 0!==e)r[s]=e;else if(u(n[s])&&u(r[s]))r[s]=x(r[s],n[s],t);else if(Array.isArray(n[s]))r[s]=n[s].map(((e,n)=>{if(!u(e))return e;return x(Array.isArray(r[s])?r[s][n]:r[s],e,t)}));else if(u(n[s])){const e=_(l(n[s]),void 0);r[s]=x(e,n[s],t)}else void 0!==n[s]&&(r[s]=n[s])}return r}function L(...e){return x(...e,(()=>{}))}function C(e,t){return function(e,t){return Object.keys(e).some((r=>t(e[r])))}(e,(e=>u(e)?C(e,t):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?t(e):e.some((e=>u(e)?C(e,t):t(e))):t(e)))}function N(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function P(e,t){if(!u(e)||!u(t)){if(Array.isArray(t)){if(t.some(u))return;const r=Array.isArray(e)?e:[];return t.map(((e,t)=>{var n;return null!==(n=r[t])&&void 0!==n?n:e}))}return void 0!==e?e:void 0}}function M(...e){return x(...e,P)}function W({helpers:i,stores:d,config:h,extender:p,validateErrors:b,validateWarnings:A,_setFormNode:w,_getFormNode:S,_getInitialValues:V,_setCurrentExtenders:j,_getCurrentExtenders:k}){const{setFields:T,setTouched:D,reset:x,setInitialValues:P}=i,{addValidator:W,addTransformer:H,validate:q,setIsDirty:R,setIsSubmitting:U}=i,$=g(i,["addValidator","addTransformer","validate","setIsDirty","setIsSubmitting"]),{data:B,errors:K,warnings:z,touched:X,isSubmitting:G,isDirty:J,interacted:Q}=d;function Y(r){return async function(n){var i,a,o,u,l,d,c;const f=S(),{createErrorEvent:v,createSubmitEvent:m,createSuccessEvent:y}=I(),p=m();null==f||f.dispatchEvent(p);const g=null!==(a=null!==(i=p.onError)&&void 0!==i?i:null==r?void 0:r.onError)&&void 0!==a?a:h.onError,w=null!==(u=null!==(o=p.onSuccess)&&void 0!==o?o:null==r?void 0:r.onSuccess)&&void 0!==u?u:h.onSuccess,V=null!==(c=null!==(d=null!==(l=p.onSubmit)&&void 0!==l?l:null==r?void 0:r.onSubmit)&&void 0!==d?d:h.onSubmit)&&void 0!==c?c:function(e){if(e)return async function(){let r=new FormData(e);const n=new URL(e.action),i="get"===e.method.toLowerCase()?"get":n.searchParams.get("_method")||e.method;let s,a=e.enctype;e.querySelector('input[type="file"]')&&(a="multipart/form-data"),"get"!==i&&"application/x-www-form-urlencoded"!==a||(r=new URLSearchParams(r)),"get"===i?(r.forEach(((e,t)=>{n.searchParams.append(t,e)})),s={method:i}):s={method:i,body:r,headers:{"Content-Type":a}};const o=await window.fetch(n.toString(),s);if(o.ok)return o;throw new t("An error occurred while submitting the form",o)}}(f);if(!V)return;if(null==n||n.preventDefault(),p.defaultPrevented)return;G.set(!0),Q.set(null);const F=O(e(B)),j=await b(F,null==r?void 0:r.validate),T=await A(F,null==r?void 0:r.warn);if(T&&z.set(L(_(F,[]),T)),X.set(E(F,!0)),j){X.set(E(j,!0));if(C(j,(e=>Array.isArray(e)?e.length>=1:!!e)))return await new Promise((e=>setTimeout(e))),k().forEach((e=>{var t;return null===(t=e.onSubmitError)||void 0===t?void 0:t.call(e,{data:F,errors:j})})),void G.set(!1)}const D=Object.assign(Object.assign({},$),{form:f,controls:f&&Array.from(f.elements).filter(s),config:Object.assign(Object.assign({},h),r)});try{const e=await V(F,D);null==f||f.dispatchEvent(y(Object.assign({response:e},D))),await(null==w?void 0:w(e,D))}catch(t){const r=v(Object.assign({error:t},D));if(null==f||f.dispatchEvent(r),!g&&!r.defaultPrevented)throw t;if(!g&&!r.errors)return;const n=r.errors||await(null==g?void 0:g(t,D));n&&(X.set(E(n,!0)),K.set(n),await new Promise((e=>setTimeout(e))),k().forEach((t=>{var r;return null===(r=t.onSubmitError)||void 0===r?void 0:r.call(t,{data:F,errors:e(K)})})))}finally{G.set(!1)}}}const Z=Y();return{form:function(t){function i(e){return function(r){return r({form:t,stage:e,controls:Array.from(t.elements).filter(s),data:B,errors:K,warnings:z,touched:X,config:h,addValidator:W,addTransformer:H,setFields:T,validate:q,reset:x})}}t.requestSubmit||(t.requestSubmit=Z),j(p.map(i("MOUNT"))),t.noValidate=!!h.validate;const{defaultData:d,defaultTouched:b}=y(t);function g(e){const t=e.target;if(!t||!s(t)||n(t)||N(t))return;if(["checkbox","radio","file"].includes(t.type))return;if(!t.name)return;J.set(!0);const r=m(t);Q.set(t.name),B.update((e=>c(e,f(t),r)))}function A(e){const i=e.target;if(i&&s(i)&&!N(i)&&i.name)if(D(f(i),!0),Q.set(i.name),(n(i)||["checkbox","radio","file","hidden"].includes(i.type))&&J.set(!0),"hidden"===i.type&&B.update((e=>c(e,f(i),i.value))),n(i))!function(e){if(e.multiple){const t=Array.from(e.options).filter((e=>e.selected)).map((e=>e.value));B.update((r=>c(r,f(e),t)))}else B.update((t=>c(t,f(e),e.value)))}(i);else{if(!r(i))return;"checkbox"===i.type?function(e){const n=f(e),i=Array.from(t.querySelectorAll(`[name="${e.name}"]`)).filter((e=>!!s(e)&&n===f(e)));if(0!==i.length)1===i.length?B.update((t=>c(t,f(e),e.checked))):B.update((t=>c(t,f(e),i.filter(r).filter((e=>e.checked)).map((e=>e.value)))))}(i):"radio"===i.type?function(e){const n=t.querySelectorAll(`[name="${e.name}"]`),i=Array.from(n).find((e=>r(e)&&e.checked));B.update((t=>c(t,f(e),null==i?void 0:i.value)))}(i):"file"===i.type&&function(e){var t;const r=Array.from(null!==(t=e.files)&&void 0!==t?t:[]);B.update((t=>c(t,f(e),e.multiple?r:r[0])))}(i)}}function E(e){const t=e.target;t&&s(t)&&!N(t)&&t.name&&(D(f(t),!0),Q.set(t.name))}function S(e){e.preventDefault(),x()}function O(t){for(const r of t.reverse()){if(r.hasAttribute("data-felte-keep-on-remove")&&"false"!==r.dataset.felteKeepOnRemove)continue;const t=/.*(\[[0-9]+\]|\.[0-9]+)\.[^.]+$/;let n=f(r);const i=e(X);if(t.test(n)){const e=n.split(".").slice(0,-1).join("."),t=o(i,e);u(t)&&Object.keys(t).length<=1&&(n=e)}B.update((e=>F(e,n))),X.update((e=>F(e,n))),K.update((e=>F(e,n))),z.update((e=>F(e,n)))}}w(t),P(L(l(d),V())),T(V()),X.set(b);const _=new MutationObserver((function(e){for(const r of e)if("childList"===r.type){if(r.addedNodes.length>0){if(!Array.from(r.addedNodes).some((e=>{if(!a(e))return!1;if(s(e))return!0;return v(e).length>0})))continue;k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),j(p.map(i("UPDATE")));const{defaultData:e,defaultTouched:n}=y(t);B.update((t=>M(t,e))),X.update((e=>M(e,n)))}if(r.removedNodes.length>0)for(const e of r.removedNodes){if(!a(e))continue;const t=v(e);0!==t.length&&(k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),j(p.map(i("UPDATE"))),O(t))}}}));_.observe(t,{childList:!0,subtree:!0}),t.addEventListener("input",g),t.addEventListener("change",A),t.addEventListener("focusout",E),t.addEventListener("submit",Z),t.addEventListener("reset",S);const I=K.subscribe((e=>{for(const r of t.elements){if(!s(r)||!r.name)continue;const t=o(e,f(r)),n=Array.isArray(t)?t.join("\n"):"string"==typeof t?t:void 0;n!==r.dataset.felteValidationMessage&&(n?(r.dataset.felteValidationMessage=n,r.setAttribute("aria-invalid","true")):(delete r.dataset.felteValidationMessage,r.removeAttribute("aria-invalid")))}}));return{destroy(){_.disconnect(),t.removeEventListener("input",g),t.removeEventListener("change",A),t.removeEventListener("focusout",E),t.removeEventListener("submit",Z),t.removeEventListener("reset",S),I(),k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)}))}}},createSubmitHandler:Y,handleSubmit:Z}}function H(e,t){return t?Array.isArray(t)?t.reduce(((e,t)=>t(e)),e):t(e):e}function q(e,t){if(!u(e)&&!u(t)){if(null===e||""===e)return t;if(null===t||""===t)return e;if(!t)return e;if(e&&t){if(Array.isArray(e)){if(!Array.isArray(t))return[...e,t];const r=[],n=Math.max(t.length,e.length);for(let i=0;i<n;i++){let n=e[i],s=t[i];u(n)||u(s)?r.push(R([null!=n?n:{},null!=s?s:{}])):(Array.isArray(n)||(n=[n]),Array.isArray(s)||(s=[s]),r.push(...n,...s))}return r.filter(Boolean)}return Array.isArray(t)||(t=[t]),[e,...t].reduce(((e,t)=>e.concat(t)),[]).filter(Boolean)}}}function R(e){return x(...e,q)}function U(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?_(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:e&&n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?e?t:null:e&&t?[t]:null}function $(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?_(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?t:t?[t]:null}function B([e,t]){return x(t,e,U)}function K([e,t]){return x(t,e,$)}function z(e,t=300){let r;return(...n)=>{clearTimeout(r),r=setTimeout((()=>{e.apply(this,n)}),t)}}function X(e,t){var r,n,i,s,a,o,u;const d=function(e){return function(t,r,n){const i=Array.isArray(t)?t:[t],s=new Array(i.length),a=e(n),o=a.set,u=a.subscribe;let l;return a.subscribe=function(e){const t=u(e);return()=>{t()}},[a,function(){l=i.map(((e,t)=>e.subscribe((e=>{s[t]=e,o(r(s))}))))},function(){null==l||l.forEach((e=>e()))}]}}(e),c=t.initialValues=t.initialValues?S(H(l(t.initialValues),t.transform)):{},f=E(O(c),!1),v=e(f),h=e(0),[m,y,p]=d([v,h],(([e,t])=>C(e,(e=>!!e))&&t>=1),!1);function b(e){let t;return async function(r,n,i,s=!1){if(!i||!r)return;let a=n&&Object.keys(n).length>0?n:_(r,[]);const o=function(e){const t={aborted:!1,priority:e};return{signal:t,abort(){t.aborted=!0}}}(s);if((null==t?void 0:t.signal.priority)&&!s||(null==t||t.abort(),t=o),t.signal.priority&&!s)return;h.update((e=>e+1));const u=(l=r,(d=i)?(Array.isArray(d)?d:[d]).map((e=>e(l))):[]);var l,d;return u.forEach((async t=>{const r=await t;o.signal.aborted||(a=R([a,r]),e.set(a))})),await Promise.all(u),t=void 0,h.update((e=>e-1)),a}}delete m.set,delete m.update;let g=_(f,[]);const A=e(c),w=_(f,[]),V=e(w),F=e(l(w)),[j,k,T]=d([V,F],R,l(w)),D=_(f,[]),I=e(D),x=e(l(D)),[L,N,P]=d([I,x],R,l(D)),[M,W,q]=d([j,v],B,l(w)),[U,$,X]=d([L,v],K,l(D));let G=!1;const[J,Q,Y]=d(j,(([e])=>{var r;return G?!C(e,(e=>Array.isArray(e)?e.length>=1:!!e)):(G=!0,!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate))}),!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate));delete J.set,delete J.update;const Z=e(!1),ee=e(!1),te=e(null),re=b(V),ne=b(I),ie=b(F),se=b(x),ae=z(ie,null!==(i=null===(n=t.debounced)||void 0===n?void 0:n.validateTimeout)&&void 0!==i?i:null===(s=t.debounced)||void 0===s?void 0:s.timeout),oe=z(se,null!==(o=null===(a=t.debounced)||void 0===a?void 0:a.warnTimeout)&&void 0!==o?o:null===(u=t.debounced)||void 0===u?void 0:u.timeout);let ue=w,le=D;function de(){const e=A.subscribe((e=>{var r,n;const i=O(e);re(i,g,t.validate),ne(i,g,t.warn),ae(i,g,null===(r=t.debounced)||void 0===r?void 0:r.validate),oe(i,g,null===(n=t.debounced)||void 0===n?void 0:n.warn)})),r=v.subscribe((e=>{g=_(e,[])})),n=j.subscribe((e=>{ue=e})),i=L.subscribe((e=>{le=e}));return k(),Q(),N(),W(),$(),y(),function(){e(),q(),T(),P(),X(),Y(),p(),r(),n(),i()}}function ce(e){V.set(e(ue)),F.set({})}function fe(e){I.set(e(le)),x.set({})}return M.set=function(e){ce((()=>e))},M.update=ce,U.set=function(e){fe((()=>e))},U.update=fe,{data:A,errors:M,warnings:U,touched:v,isValid:J,isSubmitting:Z,isDirty:ee,isValidating:m,interacted:te,validateErrors:async function(e,r){var n;const i=O(e),s=re(i,g,null!=r?r:t.validate,!0);if(r)return s;const a=ie(i,g,null===(n=t.debounced)||void 0===n?void 0:n.validate,!0);return R(await Promise.all([s,a]))},validateWarnings:async function(e,r){var n;const i=O(e),s=ne(i,g,null!=r?r:t.warn,!0);if(r)return s;const a=se(i,g,null===(n=t.debounced)||void 0===n?void 0:n.warn,!0);return R(await Promise.all([s,a]))},cleanup:t.preventStoreStart?()=>{}:de(),start:de}}function G(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every(((e,r)=>G(e,t[r])));if(u(e)&&u(t)){const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&r.every((r=>G(e[r],t[r])))}return!1}const J=[],Q=()=>{};function Y(e,t=Q){let r;const n=new Set;function i(t){if(s=t,((i=e)!=i?s==s:i!==s||i&&"object"==typeof i||"function"==typeof i)&&(e=t,r)){const t=!J.length;for(const t of n)t[1](),J.push(t,e);if(t){for(let e=0;e<J.length;e+=2)J[e][0](J[e+1]);J.length=0}}var i,s}return{set:i,update:function(t){i(t(e))},subscribe:function(s,a=Q){const o=[s,a];return n.add(o),1===n.size&&(r=t(i)||Q),s(e),()=>{n.delete(o),r&&0===n.size&&(r(),r=null)}}}}function Z(e){return function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFormElement. The element is not ready yet.`)}}const ee=["data","errors","touched","warnings","isSubmitting","isDirty","isValid","isValidating","interacted"];class te extends HTMLElement{constructor(){super(...arguments),this.id="",this._configuration={},this._storeValues={data:void 0,errors:void 0,touched:void 0,warnings:void 0,isSubmitting:!1,isDirty:!1,isValid:void 0,isValidating:!1,interacted:null},this.setData=Z("setData"),this.setFields=Z("setFields"),this.setInitialValues=Z("setInitialValues"),this.addField=Z("addField"),this.unsetField=Z("unsetField"),this.swapFields=Z("swapFields"),this.moveField=Z("moveField"),this.resetField=Z("resetField"),this.reset=Z("reset"),this.submit=Z("submit"),this.createSubmitHandler=Z("createSubmitHandler"),this.setErrors=Z("setErrors"),this.setTouched=Z("setTouched"),this.setWarnings=Z("setWarnings"),this.setIsSubmitting=Z("setIsSubmitting"),this.setIsDirty=Z("setIsDirty"),this.setInteracted=Z("setInteracted"),this._ready=!1,this.validate=Z("validate"),this._formElement=null,this._onChildChange=()=>{var e;const t=this.querySelector("form");t&&t!==this._formElement&&(this._formElement=t,null===(e=this._destroy)||void 0===e||e.call(this),this._createForm(this._configuration))}}setConfiguration(e){this._configuration=e,this._destroy&&(this._destroy(),this._destroy=void 0,this._ready=!1,this._createForm(e))}get data(){return this._storeValues.data}get errors(){return this._storeValues.errors}get touched(){return this._storeValues.touched}get warnings(){return this._storeValues.warnings}get isSubmitting(){return this._storeValues.isSubmitting}get isDirty(){return this._storeValues.isDirty}get isValid(){return this._storeValues.isValid}get isValidating(){return this._storeValues.isValidating}get interacted(){return this._storeValues.interacted}get ready(){return this._ready}_createForm(e){var t;const r=this._formElement;if(!r||this._destroy)return;this.elements=r.elements;const{form:n,cleanup:i,...s}=function(e,t){var r,n;function i(t,{debounced:r,level:n}={debounced:!1,level:"error"}){var i;const s="error"===n?"validate":"warn";null!==(i=e.debounced)&&void 0!==i||(e.debounced={});const a=r?e.debounced:e;a[s]?a[s]=[...a[s],t]:a[s]=[t]}function s(t){e.transform?e.transform=[...e.transform,t]:e.transform=[t]}null!==(r=e.extend)&&void 0!==r||(e.extend=[]),null!==(n=e.debounced)&&void 0!==n||(e.debounced={}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]),e.debounced.validate&&!Array.isArray(e.debounced.validate)&&(e.debounced.validate=[e.debounced.validate]),e.transform&&!Array.isArray(e.transform)&&(e.transform=[e.transform]),e.warn&&!Array.isArray(e.warn)&&(e.warn=[e.warn]),e.debounced.warn&&!Array.isArray(e.debounced.warn)&&(e.debounced.warn=[e.debounced.warn]);const a=Array.isArray(e.extend)?e.extend:[e.extend];let o=[];const{isSubmitting:u,isValidating:l,data:d,errors:c,warnings:f,touched:v,isValid:h,isDirty:m,cleanup:y,start:p,validateErrors:b,validateWarnings:g,interacted:A}=X(t.storeFactory,e),E=d.update,w=d.set;d.update=t=>E((r=>S(H(t(r),e.transform)))),d.set=t=>w(S(H(t,e.transform)));const O=D({extender:a,config:e,addValidator:i,addTransformer:s,validateErrors:b,validateWarnings:g,stores:{data:d,errors:c,warnings:f,touched:v,isValid:h,isValidating:l,isSubmitting:u,isDirty:m,interacted:A}});o=a.map((t=>t({stage:"SETUP",errors:c,warnings:f,touched:v,data:d,config:e,addValidator:i,addTransformer:s,setFields:O.public.setFields,reset:O.public.reset,validate:O.public.validate})));const V=Object.assign({config:e,stores:{data:d,touched:v,errors:c,warnings:f,isSubmitting:u,isValidating:l,isValid:h,isDirty:m,interacted:A},helpers:Object.assign(Object.assign({},O.public),{addTransformer:s,addValidator:i}),extender:a,validateErrors:b,validateWarnings:g,_getCurrentExtenders:()=>o,_setCurrentExtenders:e=>{o=e}},O.private),{form:_,createSubmitHandler:F,handleSubmit:j}=W(V);return Object.assign({data:d,errors:c,warnings:f,touched:v,isValid:h,isSubmitting:u,isValidating:l,isDirty:m,interacted:A,form:_,handleSubmit:j,createSubmitHandler:F,cleanup:y,startStores:p},O.public)}(e,{storeFactory:Y});this.setData=s.setData,this.setFields=s.setFields,this.setErrors=s.setErrors,this.setTouched=s.setTouched,this.setWarnings=s.setWarnings,this.setIsSubmitting=s.setIsSubmitting,this.setIsDirty=s.setIsDirty,this.setInteracted=s.setInteracted,this.setInitialValues=s.setInitialValues,this.validate=s.validate,this.addField=s.addField,this.unsetField=s.unsetField,this.swapFields=s.swapFields,this.moveField=s.moveField,this.resetField=s.resetField,this.reset=s.reset,this.submit=s.handleSubmit,this.createSubmitHandler=s.createSubmitHandler;const a=ee.map((e=>s[e].subscribe((t=>{if(G(t,this._storeValues[e]))return;this._storeValues[e]=t;const r=e.toLowerCase(),n=this[`on${r}change`];"function"==typeof n&&n(t),this.dispatchEvent(new Event(`${r}change`))})))),{destroy:o}=n(r),{createSubmitEvent:u,createErrorEvent:l,createSuccessEvent:d}=I(),c=e=>{const t=e,r=u();this.dispatchEvent(r),r.defaultPrevented&&t.preventDefault(),t.onSubmit=r.onSubmit,t.onSuccess=r.onSuccess,t.onError=r.onError},f=e=>{const t=d(e.detail);this.dispatchEvent(t)},v=e=>{const t=e,r=l(t.detail);this.dispatchEvent(r),t.errors=r.errors,r.defaultPrevented&&t.preventDefault()};r.addEventListener("feltesubmit",c),r.addEventListener("feltesuccess",f),r.addEventListener("felteerror",v),this._destroy=()=>{o(),i(),r.removeEventListener("feltesubmit",c),r.removeEventListener("feltesuccess",f),r.removeEventListener("felteerror",v),a.forEach((e=>e()))},this._ready=!0,null===(t=this.onfelteready)||void 0===t||t.call(this),this.dispatchEvent(new Event("felteready",{bubbles:!0,composed:!0}))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&(this.dispatchEvent(new Event("felteconnect",{bubbles:!0,composed:!0})),this._onChildChange(),this._observer=new MutationObserver(this._onChildChange),this._observer.observe(this,{childList:!0}))}))}disconnectedCallback(){var e,t;null===(e=this._destroy)||void 0===e||e.call(this),null===(t=this._observer)||void 0===t||t.disconnect()}static get observedAttributes(){return["id"]}attributeChangedCallback(e,t,r){if(t!==r)switch(e){case"id":this.id=r}}}customElements.get("felte-form")||customElements.define("felte-form",te);export{te as FelteForm,t as FelteSubmitError};
***************************************************************************** */function V(e){return function(t){if(u(t)){return function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(_(t,e),["key"])}return e}}function _(e,t){return A(e,(e=>u(e)?_(e,t):Array.isArray(e)?e.map(V(t)):t))}function F(e,t){if(!e||Object(e)!==e)return;void 0!==e&&(e=l(e));const r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[],n=1===r.length?e:o(e,r.slice(0,-1).join("."));return Array.isArray(n)?n.splice(Number(r[r.length-1]),1):null==n||delete n[r[r.length-1]],e}function j(e,t,r,n){return d(e,t,(e=>void 0===e||Array.isArray(e)?(e||(e=[]),void 0===n?e.push(r):e.splice(n,0,r),e):e))}function k(e){return"function"==typeof e}function T(e){return(t,r)=>{if("string"==typeof t){const n=t;e((e=>{const t=k(r)?r(o(e,n)):r;return c(e,n,t)}))}else e((e=>k(t)?t(e):t))}}function D({stores:t,config:r,validateErrors:n,validateWarnings:i}){var s;let a,f=S(null!==(s=r.initialValues)&&void 0!==s?s:{});const{data:v,touched:h,errors:m,warnings:y,isDirty:b,isSubmitting:g,interacted:A}=t,O=T(v.update),V=T(h.update),k=T(m.update),D=T(y.update);function I(e){O((t=>{const r=e(t);return a&&p(a,r),r}))}const x=(e,t,r)=>{T(I)(e,t),"string"==typeof e&&r&&V(e,!0)};function L(e){m.update(e),y.update(e),h.update(e),v.update((t=>{const r=e(t);return setTimeout((()=>a&&p(a,r))),r}))}const C=T(g.update),N=T(b.update),P=T(A.update);return{public:{setData:O,setFields:x,setTouched:V,setErrors:k,setWarnings:D,setIsSubmitting:C,setIsDirty:N,setInteracted:P,validate:async function(){const t=e(v);h.set(E(t,!0)),A.set(null);const r=await n(t);return await i(t),r},reset:function(){x(l(f)),V((e=>_(e,!1))),A.set(null),b.set(!1)},unsetField:function(e){L((t=>F(t,e)))},resetField:function(e){const t=o(f,e),r=!!u(t)&&E(t,!1),n=u(r)?_(r,[]):[];v.update((r=>{const n=c(r,e,t);return a&&p(a,n),n})),h.update((t=>c(t,e,r))),m.update((t=>c(t,e,n))),y.update((t=>c(t,e,n)))},addField:function(e,t,r){const n=!!u(t)&&E(t,!1),i=u(n)?_(n,[]):[];t=u(t)?Object.assign(Object.assign({},t),{key:w()}):t,m.update((t=>j(t,e,i,r))),y.update((t=>j(t,e,i,r))),h.update((t=>j(t,e,n,r))),v.update((n=>{const i=j(n,e,t,r);return setTimeout((()=>a&&p(a,i))),i}))},swapFields:function(e,t,r){L((n=>function(e,t,r,n){return d(e,t,(e=>e&&Array.isArray(e)?([e[r],e[n]]=[e[n],e[r]],e):e))}(n,e,t,r)))},moveField:function(e,t,r){L((n=>function(e,t,r,n){return d(e,t,(e=>e&&Array.isArray(e)?(e.splice(n,0,e.splice(r,1)[0]),e):e))}(n,e,t,r)))},setInitialValues:e=>{f=S(e)}},private:{_setFormNode(e){a=e},_getFormNode:()=>a,_getInitialValues:()=>f}}}function I(){class e extends CustomEvent{constructor(e){super("feltesuccess",{detail:e})}}class t extends CustomEvent{constructor(e){super("felteerror",{detail:e,cancelable:!0})}setErrors(e){this.preventDefault(),this.errors=e}}class r extends Event{constructor(){super("feltesubmit",{cancelable:!0})}handleSubmit(e){this.onSubmit=e}handleError(e){this.onError=e}handleSuccess(e){this.onSuccess=e}}return{createErrorEvent:e=>new t(e),createSubmitEvent:()=>new r,createSuccessEvent:t=>new e(t)}}function x(...e){const t=e.pop(),r=l(e.shift());if(0===e.length)return r;for(const n of e){if(!n)continue;let e=t(r,n);if(void 0!==e)return e;const i=Array.from(new Set(Object.keys(r).concat(Object.keys(n))));for(const s of i)if(e=t(r[s],n[s]),void 0!==e)r[s]=e;else if(u(n[s])&&u(r[s]))r[s]=x(r[s],n[s],t);else if(Array.isArray(n[s]))r[s]=n[s].map(((e,n)=>{if(!u(e))return e;return x(Array.isArray(r[s])?r[s][n]:r[s],e,t)}));else if(u(n[s])){const e=_(l(n[s]),void 0);r[s]=x(e,n[s],t)}else void 0!==n[s]&&(r[s]=n[s])}return r}function L(...e){return x(...e,(()=>{}))}function C(e,t){return function(e,t){return Object.keys(e).some((r=>t(e[r])))}(e,(e=>u(e)?C(e,t):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?t(e):e.some((e=>u(e)?C(e,t):t(e))):t(e)))}function N(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function P(e,t){let r;return(...n)=>{clearTimeout(r),r=setTimeout((()=>{e.apply(this,n)}),t)}}function M(e,t){if(!u(e)||!u(t)){if(Array.isArray(t)){if(t.some(u))return;const r=Array.isArray(e)?e:[];return t.map(((e,t)=>{var n;return null!==(n=r[t])&&void 0!==n?n:e}))}return void 0!==e?e:void 0}}function W(...e){return x(...e,M)}function H({helpers:i,stores:d,config:h,extender:b,validateErrors:p,validateWarnings:A,_setFormNode:w,_getFormNode:S,_getInitialValues:V,_setCurrentExtenders:j,_getCurrentExtenders:k}){const{setFields:T,setTouched:D,reset:x,setInitialValues:M}=i,{addValidator:H,addTransformer:q,validate:R,setIsDirty:U,setIsSubmitting:$}=i,B=g(i,["addValidator","addTransformer","validate","setIsDirty","setIsSubmitting"]),{data:K,errors:z,warnings:X,touched:G,isSubmitting:J,isDirty:Q,interacted:Y}=d;function Z(r){return async function(n){var i,a,o,u,l,d,c;const f=S(),{createErrorEvent:v,createSubmitEvent:m,createSuccessEvent:y}=I(),b=m();null==f||f.dispatchEvent(b);const g=null!==(a=null!==(i=b.onError)&&void 0!==i?i:null==r?void 0:r.onError)&&void 0!==a?a:h.onError,w=null!==(u=null!==(o=b.onSuccess)&&void 0!==o?o:null==r?void 0:r.onSuccess)&&void 0!==u?u:h.onSuccess,V=null!==(c=null!==(d=null!==(l=b.onSubmit)&&void 0!==l?l:null==r?void 0:r.onSubmit)&&void 0!==d?d:h.onSubmit)&&void 0!==c?c:function(e){if(e)return async function(){let r=new FormData(e);const n=new URL(e.action),i="get"===e.method.toLowerCase()?"get":n.searchParams.get("_method")||e.method;let s,a=e.enctype;e.querySelector('input[type="file"]')&&(a="multipart/form-data"),"get"!==i&&"application/x-www-form-urlencoded"!==a||(r=new URLSearchParams(r)),"get"===i?(r.forEach(((e,t)=>{n.searchParams.append(t,e)})),s={method:i}):s={method:i,body:r,headers:{"Content-Type":a}};const o=await window.fetch(n.toString(),s);if(o.ok)return o;throw new t("An error occurred while submitting the form",o)}}(f);if(!V)return;if(null==n||n.preventDefault(),b.defaultPrevented)return;J.set(!0),Y.set(null);const F=O(e(K)),j=await p(F,null==r?void 0:r.validate),T=await A(F,null==r?void 0:r.warn);if(T&&X.set(L(_(F,[]),T)),G.set(E(F,!0)),j){G.set(E(j,!0));if(C(j,(e=>Array.isArray(e)?e.length>=1:!!e)))return await new Promise((e=>setTimeout(e))),k().forEach((e=>{var t;return null===(t=e.onSubmitError)||void 0===t?void 0:t.call(e,{data:F,errors:j})})),void J.set(!1)}const D=Object.assign(Object.assign({},B),{form:f,controls:f&&Array.from(f.elements).filter(s),config:Object.assign(Object.assign({},h),r)});try{const e=await V(F,D);null==f||f.dispatchEvent(y(Object.assign({response:e},D))),await(null==w?void 0:w(e,D))}catch(t){const r=v(Object.assign({error:t},D));if(null==f||f.dispatchEvent(r),!g&&!r.defaultPrevented)throw t;if(!g&&!r.errors)return;const n=r.errors||await(null==g?void 0:g(t,D));n&&(G.set(E(n,!0)),z.set(n),await new Promise((e=>setTimeout(e))),k().forEach((t=>{var r;return null===(r=t.onSubmitError)||void 0===r?void 0:r.call(t,{data:F,errors:e(z)})})))}finally{J.set(!1)}}}const ee=Z();return{form:function(t){function i(e){return function(r){return r({form:t,stage:e,controls:Array.from(t.elements).filter(s),data:K,errors:z,warnings:X,touched:G,config:h,addValidator:H,addTransformer:q,setFields:T,validate:R,reset:x})}}t.requestSubmit||(t.requestSubmit=ee),j(b.map(i("MOUNT"))),t.noValidate=!!h.validate;const{defaultData:d,defaultTouched:p}=y(t);function g(e){const t=e.target;if(!t||!s(t)||n(t)||N(t))return;if(["checkbox","radio","file"].includes(t.type))return;if(!t.name)return;Q.set(!0);const r=m(t);Y.set(t.name),K.update((e=>c(e,f(t),r)))}function A(e){const i=e.target;if(i&&s(i)&&!N(i)&&i.name)if(D(f(i),!0),Y.set(i.name),(n(i)||["checkbox","radio","file","hidden"].includes(i.type))&&Q.set(!0),"hidden"===i.type&&K.update((e=>c(e,f(i),i.value))),n(i))!function(e){if(e.multiple){const t=Array.from(e.options).filter((e=>e.selected)).map((e=>e.value));K.update((r=>c(r,f(e),t)))}else K.update((t=>c(t,f(e),e.value)))}(i);else{if(!r(i))return;"checkbox"===i.type?function(e){const n=f(e),i=Array.from(t.querySelectorAll(`[name="${e.name}"]`)).filter((e=>!!s(e)&&n===f(e)));if(0!==i.length)1===i.length?K.update((t=>c(t,f(e),e.checked))):K.update((t=>c(t,f(e),i.filter(r).filter((e=>e.checked)).map((e=>e.value)))))}(i):"radio"===i.type?function(e){const n=t.querySelectorAll(`[name="${e.name}"]`),i=Array.from(n).find((e=>r(e)&&e.checked));K.update((t=>c(t,f(e),null==i?void 0:i.value)))}(i):"file"===i.type&&function(e){var t;const r=Array.from(null!==(t=e.files)&&void 0!==t?t:[]);K.update((t=>c(t,f(e),e.multiple?r:r[0])))}(i)}}function E(e){const t=e.target;t&&s(t)&&!N(t)&&t.name&&(D(f(t),!0),Y.set(t.name))}function S(e){e.preventDefault(),x()}w(t),M(L(l(d),V())),T(V()),G.set(p);const O=P((()=>{k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),j(b.map(i("UPDATE")));const{defaultData:e,defaultTouched:r}=y(t);K.update((t=>W(t,e))),G.update((e=>W(e,r)))}),0);let _=[];const I=P((()=>{k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),j(b.map(i("UPDATE"))),function(t){let r=e(K),n=e(G),i=e(z),s=e(X);for(const a of t.reverse()){if(a.hasAttribute("data-felte-keep-on-remove")&&"false"!==a.dataset.felteKeepOnRemove)continue;const t=/.*(\[[0-9]+\]|\.[0-9]+)\.[^.]+$/;let l=f(a);const d=e(G);if(t.test(l)){const e=l.split(".").slice(0,-1).join("."),t=o(d,e);u(t)&&Object.keys(t).length<=1&&(l=e)}r=F(r,l),n=F(n,l),i=F(i,l),s=F(s,l)}K.set(r),G.set(n),z.set(i),X.set(s)}(_),_=[]}),0),C=new MutationObserver((function(e){for(const t of e)if("childList"===t.type){if(t.addedNodes.length>0){if(!Array.from(t.addedNodes).some((e=>{if(!a(e))return!1;if(s(e))return!0;return v(e).length>0})))continue;O()}if(t.removedNodes.length>0)for(const e of t.removedNodes){if(!a(e))continue;const t=v(e);0!==t.length&&(_.push(...t),I())}}}));C.observe(t,{childList:!0,subtree:!0}),t.addEventListener("input",g),t.addEventListener("change",A),t.addEventListener("focusout",E),t.addEventListener("submit",ee),t.addEventListener("reset",S);const U=z.subscribe((e=>{for(const r of t.elements){if(!s(r)||!r.name)continue;const t=o(e,f(r)),n=Array.isArray(t)?t.join("\n"):"string"==typeof t?t:void 0;n!==r.dataset.felteValidationMessage&&(n?(r.dataset.felteValidationMessage=n,r.setAttribute("aria-invalid","true")):(delete r.dataset.felteValidationMessage,r.removeAttribute("aria-invalid")))}}));return{destroy(){C.disconnect(),t.removeEventListener("input",g),t.removeEventListener("change",A),t.removeEventListener("focusout",E),t.removeEventListener("submit",ee),t.removeEventListener("reset",S),U(),k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)}))}}},createSubmitHandler:Z,handleSubmit:ee}}function q(e,t){return t?Array.isArray(t)?t.reduce(((e,t)=>t(e)),e):t(e):e}function R(e,t){if(!u(e)&&!u(t)){if(null===e||""===e)return t;if(null===t||""===t)return e;if(!t)return e;if(e&&t){if(Array.isArray(e)){if(!Array.isArray(t))return[...e,t];const r=[],n=Math.max(t.length,e.length);for(let i=0;i<n;i++){let n=e[i],s=t[i];u(n)||u(s)?r.push(U([null!=n?n:{},null!=s?s:{}])):(Array.isArray(n)||(n=[n]),Array.isArray(s)||(s=[s]),r.push(...n,...s))}return r.filter(Boolean)}return Array.isArray(t)||(t=[t]),[e,...t].reduce(((e,t)=>e.concat(t)),[]).filter(Boolean)}}}function U(e){return x(...e,R)}function $(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?_(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:e&&n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?e?t:null:e&&t?[t]:null}function B(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?_(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?t:t?[t]:null}function K([e,t]){return x(t,e,$)}function z([e,t]){return x(t,e,B)}function X(e,t){var r,n,i,s,a,o,u,d,c;const f=function(e){return function(t,r,n){const i=Array.isArray(t)?t:[t],s=new Array(i.length),a=e(n),o=a.set,u=a.subscribe;let l;return a.subscribe=function(e){const t=u(e);return()=>{t()}},[a,function(){l=i.map(((e,t)=>e.subscribe((e=>{s[t]=e,o(r(s))}))))},function(){null==l||l.forEach((e=>e()))}]}}(e),v=t.initialValues=t.initialValues?S(q(l(t.initialValues),t.transform)):{},h=E(O(v),!1),m=e(h),y=e(0),[b,p,g]=f([m,y],(([e,t])=>C(e,(e=>!!e))&&t>=1),!1);function A(e){let t;return async function(r,n,i,s=!1){if(!i||!r)return;let a=n&&Object.keys(n).length>0?n:_(r,[]);const o=function(e){const t={aborted:!1,priority:e};return{signal:t,abort(){t.aborted=!0}}}(s);if((null==t?void 0:t.signal.priority)&&!s||(null==t||t.abort(),t=o),t.signal.priority&&!s)return;y.update((e=>e+1));const u=(l=r,(d=i)?(Array.isArray(d)?d:[d]).map((e=>e(l))):[]);var l,d;return u.forEach((async t=>{const r=await t;o.signal.aborted||(a=U([a,r]),e.set(a))})),await Promise.all(u),t=void 0,y.update((e=>e-1)),a}}delete b.set,delete b.update;let w=_(h,[]);const V=e(v),F=_(h,[]),j=e(F),k=e(l(F)),[T,D,I]=f([j,k],U,l(F)),x=_(h,[]),L=e(x),N=e(l(x)),[M,W,H]=f([L,N],U,l(x)),[R,$,B]=f([T,m],K,l(F)),[X,G,J]=f([M,m],z,l(x));let Q=!1;const[Y,Z,ee]=f(T,(([e])=>{var r;return Q?!C(e,(e=>Array.isArray(e)?e.length>=1:!!e)):(Q=!0,!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate))}),!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate));delete Y.set,delete Y.update;const te=e(!1),re=e(!1),ne=e(null),ie=A(j),se=A(L),ae=A(k),oe=A(N),ue=P(ae,null!==(a=null!==(i=null===(n=t.debounced)||void 0===n?void 0:n.validateTimeout)&&void 0!==i?i:null===(s=t.debounced)||void 0===s?void 0:s.timeout)&&void 0!==a?a:300),le=P(oe,null!==(c=null!==(u=null===(o=t.debounced)||void 0===o?void 0:o.warnTimeout)&&void 0!==u?u:null===(d=t.debounced)||void 0===d?void 0:d.timeout)&&void 0!==c?c:300);let de=F,ce=x;function fe(){const e=V.subscribe((e=>{var r,n;const i=O(e);ie(i,w,t.validate),se(i,w,t.warn),ue(i,w,null===(r=t.debounced)||void 0===r?void 0:r.validate),le(i,w,null===(n=t.debounced)||void 0===n?void 0:n.warn)})),r=m.subscribe((e=>{w=_(e,[])})),n=T.subscribe((e=>{de=e})),i=M.subscribe((e=>{ce=e}));return D(),Z(),W(),$(),G(),p(),function(){e(),B(),I(),H(),J(),ee(),g(),r(),n(),i()}}function ve(e){j.set(e(de)),k.set({})}function he(e){L.set(e(ce)),N.set({})}return R.set=function(e){ve((()=>e))},R.update=ve,X.set=function(e){he((()=>e))},X.update=he,{data:V,errors:R,warnings:X,touched:m,isValid:Y,isSubmitting:te,isDirty:re,isValidating:b,interacted:ne,validateErrors:async function(e,r){var n;const i=O(e),s=ie(i,w,null!=r?r:t.validate,!0);if(r)return s;const a=ae(i,w,null===(n=t.debounced)||void 0===n?void 0:n.validate,!0);return U(await Promise.all([s,a]))},validateWarnings:async function(e,r){var n;const i=O(e),s=se(i,w,null!=r?r:t.warn,!0);if(r)return s;const a=oe(i,w,null===(n=t.debounced)||void 0===n?void 0:n.warn,!0);return U(await Promise.all([s,a]))},cleanup:t.preventStoreStart?()=>{}:fe(),start:fe}}function G(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every(((e,r)=>G(e,t[r])));if(u(e)&&u(t)){const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&r.every((r=>G(e[r],t[r])))}return!1}const J=[],Q=()=>{};function Y(e,t=Q){let r;const n=new Set;function i(t){if(s=t,((i=e)!=i?s==s:i!==s||i&&"object"==typeof i||"function"==typeof i)&&(e=t,r)){const t=!J.length;for(const t of n)t[1](),J.push(t,e);if(t){for(let e=0;e<J.length;e+=2)J[e][0](J[e+1]);J.length=0}}var i,s}return{set:i,update:function(t){i(t(e))},subscribe:function(s,a=Q){const o=[s,a];return n.add(o),1===n.size&&(r=t(i)||Q),s(e),()=>{n.delete(o),r&&0===n.size&&(r(),r=null)}}}}function Z(e){return function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFormElement. The element is not ready yet.`)}}const ee=["data","errors","touched","warnings","isSubmitting","isDirty","isValid","isValidating","interacted"];class te extends HTMLElement{constructor(){super(...arguments),this.id="",this._configuration={},this._storeValues={data:void 0,errors:void 0,touched:void 0,warnings:void 0,isSubmitting:!1,isDirty:!1,isValid:void 0,isValidating:!1,interacted:null},this.setData=Z("setData"),this.setFields=Z("setFields"),this.setInitialValues=Z("setInitialValues"),this.addField=Z("addField"),this.unsetField=Z("unsetField"),this.swapFields=Z("swapFields"),this.moveField=Z("moveField"),this.resetField=Z("resetField"),this.reset=Z("reset"),this.submit=Z("submit"),this.createSubmitHandler=Z("createSubmitHandler"),this.setErrors=Z("setErrors"),this.setTouched=Z("setTouched"),this.setWarnings=Z("setWarnings"),this.setIsSubmitting=Z("setIsSubmitting"),this.setIsDirty=Z("setIsDirty"),this.setInteracted=Z("setInteracted"),this._ready=!1,this.validate=Z("validate"),this._formElement=null,this._onChildChange=()=>{var e;const t=this.querySelector("form");t&&t!==this._formElement&&(this._formElement=t,null===(e=this._destroy)||void 0===e||e.call(this),this._createForm(this._configuration))}}setConfiguration(e){this._configuration=e,this._destroy&&(this._destroy(),this._destroy=void 0,this._ready=!1,this._createForm(e))}get data(){return this._storeValues.data}get errors(){return this._storeValues.errors}get touched(){return this._storeValues.touched}get warnings(){return this._storeValues.warnings}get isSubmitting(){return this._storeValues.isSubmitting}get isDirty(){return this._storeValues.isDirty}get isValid(){return this._storeValues.isValid}get isValidating(){return this._storeValues.isValidating}get interacted(){return this._storeValues.interacted}get ready(){return this._ready}_createForm(e){var t;const r=this._formElement;if(!r||this._destroy)return;this.elements=r.elements;const{form:n,cleanup:i,...s}=function(e,t){var r,n;function i(t,{debounced:r,level:n}={debounced:!1,level:"error"}){var i;const s="error"===n?"validate":"warn";null!==(i=e.debounced)&&void 0!==i||(e.debounced={});const a=r?e.debounced:e;a[s]?a[s]=[...a[s],t]:a[s]=[t]}function s(t){e.transform?e.transform=[...e.transform,t]:e.transform=[t]}null!==(r=e.extend)&&void 0!==r||(e.extend=[]),null!==(n=e.debounced)&&void 0!==n||(e.debounced={}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]),e.debounced.validate&&!Array.isArray(e.debounced.validate)&&(e.debounced.validate=[e.debounced.validate]),e.transform&&!Array.isArray(e.transform)&&(e.transform=[e.transform]),e.warn&&!Array.isArray(e.warn)&&(e.warn=[e.warn]),e.debounced.warn&&!Array.isArray(e.debounced.warn)&&(e.debounced.warn=[e.debounced.warn]);const a=Array.isArray(e.extend)?e.extend:[e.extend];let o=[];const{isSubmitting:u,isValidating:l,data:d,errors:c,warnings:f,touched:v,isValid:h,isDirty:m,cleanup:y,start:b,validateErrors:p,validateWarnings:g,interacted:A}=X(t.storeFactory,e),E=d.update,w=d.set;d.update=t=>E((r=>S(q(t(r),e.transform)))),d.set=t=>w(S(q(t,e.transform)));const O=D({extender:a,config:e,addValidator:i,addTransformer:s,validateErrors:p,validateWarnings:g,stores:{data:d,errors:c,warnings:f,touched:v,isValid:h,isValidating:l,isSubmitting:u,isDirty:m,interacted:A}});o=a.map((t=>t({stage:"SETUP",errors:c,warnings:f,touched:v,data:d,config:e,addValidator:i,addTransformer:s,setFields:O.public.setFields,reset:O.public.reset,validate:O.public.validate})));const V=Object.assign({config:e,stores:{data:d,touched:v,errors:c,warnings:f,isSubmitting:u,isValidating:l,isValid:h,isDirty:m,interacted:A},helpers:Object.assign(Object.assign({},O.public),{addTransformer:s,addValidator:i}),extender:a,validateErrors:p,validateWarnings:g,_getCurrentExtenders:()=>o,_setCurrentExtenders:e=>{o=e}},O.private),{form:_,createSubmitHandler:F,handleSubmit:j}=H(V);return Object.assign({data:d,errors:c,warnings:f,touched:v,isValid:h,isSubmitting:u,isValidating:l,isDirty:m,interacted:A,form:_,handleSubmit:j,createSubmitHandler:F,cleanup:y,startStores:b},O.public)}(e,{storeFactory:Y});this.setData=s.setData,this.setFields=s.setFields,this.setErrors=s.setErrors,this.setTouched=s.setTouched,this.setWarnings=s.setWarnings,this.setIsSubmitting=s.setIsSubmitting,this.setIsDirty=s.setIsDirty,this.setInteracted=s.setInteracted,this.setInitialValues=s.setInitialValues,this.validate=s.validate,this.addField=s.addField,this.unsetField=s.unsetField,this.swapFields=s.swapFields,this.moveField=s.moveField,this.resetField=s.resetField,this.reset=s.reset,this.submit=s.handleSubmit,this.createSubmitHandler=s.createSubmitHandler;const a=ee.map((e=>s[e].subscribe((t=>{if(G(t,this._storeValues[e]))return;this._storeValues[e]=t;const r=e.toLowerCase(),n=this[`on${r}change`];"function"==typeof n&&n(t),this.dispatchEvent(new Event(`${r}change`))})))),{destroy:o}=n(r),{createSubmitEvent:u,createErrorEvent:l,createSuccessEvent:d}=I(),c=e=>{const t=e,r=u();this.dispatchEvent(r),r.defaultPrevented&&t.preventDefault(),t.onSubmit=r.onSubmit,t.onSuccess=r.onSuccess,t.onError=r.onError},f=e=>{const t=d(e.detail);this.dispatchEvent(t)},v=e=>{const t=e,r=l(t.detail);this.dispatchEvent(r),t.errors=r.errors,r.defaultPrevented&&t.preventDefault()};r.addEventListener("feltesubmit",c),r.addEventListener("feltesuccess",f),r.addEventListener("felteerror",v),this._destroy=()=>{o(),i(),r.removeEventListener("feltesubmit",c),r.removeEventListener("feltesuccess",f),r.removeEventListener("felteerror",v),a.forEach((e=>e()))},this._ready=!0,null===(t=this.onfelteready)||void 0===t||t.call(this),this.dispatchEvent(new Event("felteready",{bubbles:!0,composed:!0}))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&(this.dispatchEvent(new Event("felteconnect",{bubbles:!0,composed:!0})),this._onChildChange(),this._observer=new MutationObserver(this._onChildChange),this._observer.observe(this,{childList:!0}))}))}disconnectedCallback(){var e,t;null===(e=this._destroy)||void 0===e||e.call(this),null===(t=this._observer)||void 0===t||t.disconnect()}static get observedAttributes(){return["id"]}attributeChangedCallback(e,t,r){if(t!==r)switch(e){case"id":this.id=r}}}customElements.get("felte-form")||customElements.define("felte-form",te);export{te as FelteForm,t as FelteSubmitError};
//# sourceMappingURL=felte-form.min.js.map

@@ -1,2 +0,2 @@

function e(e){let t;return function(e,...t){const r=e.subscribe(...t);return r.unsubscribe?()=>r.unsubscribe():r}(e,(e=>t=e))(),t}class t extends Error{constructor(e,t){super(e),this.name="FelteSubmitError",this.response=t}}function r(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function n(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function i(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function s(e){return r(e)||function(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}(e)||n(e)}function a(e){return e.nodeType===Node.ELEMENT_NODE}function o(e,t,r){const n=r=>String.prototype.split.call(t,r).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),i=n(/[,[\]]+?/)||n(/[,[\].]+?/);return void 0===i||i===e?r:i}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){return Object.keys(e||{}).reduce(((t,r)=>Object.assign(Object.assign({},t),{[r]:u(e[r])?l(e[r]):Array.isArray(e[r])?[...e[r]]:e[r]})),{})}function c(e,t,r){e&&(e=l(e)),u(e)||(e={});const n=Array.isArray(t)?t:t.match(/[^.[\]]+/g)||[],i=n[n.length-1];if(!i)return e;let s=e;for(let e=0;e<n.length-1;e++){const t=n[e];if(!s[t]||!u(s[t])&&!Array.isArray(s[t])){const r=n[e+1];isNaN(Number(r))?s[t]={}:s[t]=[]}s=s[t]}return s[i]=r(s[i]),e}function d(e,t,r){return c(e,t,(()=>r))}function f(e,t){return null!=t?t:s(e)?e.name:""}function v(e){if(s(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const r of e.children){if(s(r)&&t.add(r),i(r))for(const e of r.elements)s(e)&&t.add(e);r.childElementCount>0&&v(r).forEach((e=>t.add(e)))}return Array.from(t)}function h(e){for(const t of e.elements)(s(t)||i(t))&&e.hasAttribute("data-felte-keep-on-remove")&&!t.hasAttribute("data-felte-keep-on-remove")&&(t.dataset.felteKeepOnRemove=e.dataset.felteKeepOnRemove)}function m(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function y(e){var t;let a={},u={};for(const l of e.elements){if(i(l)&&h(l),!s(l)||!l.name)continue;const v=f(l);if(r(l)){if("checkbox"===l.type){if(void 0===o(a,v)){if(1===Array.from(e.querySelectorAll(`[name="${l.name}"]`)).filter((e=>!!s(e)&&v===f(e))).length){a=d(a,v,l.checked),u=d(u,v,!1);continue}a=d(a,v,l.checked?[l.value]:[]),u=d(u,v,!1);continue}Array.isArray(o(a,v))&&l.checked&&(a=c(a,v,(e=>[...e,l.value])));continue}if("radio"===l.type){if(o(a,v))continue;a=d(a,v,l.checked?l.value:void 0),u=d(u,v,!1);continue}if("file"===l.type){a=d(a,v,l.multiple?Array.from(l.files||[]):null===(t=l.files)||void 0===t?void 0:t[0]),u=d(u,v,!1);continue}}else if(n(l)){if(l.multiple){const e=Array.from(l.options).filter((e=>e.selected)).map((e=>e.value));a=d(a,v,e)}else a=d(a,v,l.value);u=d(u,v,!1);continue}const y=m(l);a=d(a,v,y),u=d(u,v,!1)}return{defaultData:a,defaultTouched:u}}function p(e,t){var i;if(!s(e))return;const a=t;if(r(e)){if("checkbox"===e.type){const t=a;return void 0===t||"boolean"==typeof t?void(e.checked=!!t):void(Array.isArray(t)&&(t.includes(e.value)?e.checked=!0:e.checked=!1))}if("radio"===e.type){const t=a;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}else if(n(e)){if(e.multiple){if(Array.isArray(a)){e.value=String(null!==(i=a[0])&&void 0!==i?i:"");for(const t of e.options)a.includes(t.value)?t.selected=!0:t.selected=!1}}else{e.value=String(null!=a?a:"");for(const t of e.options)t.value===a?t.selected=!0:t.selected=!1}return}e.value=String(null!=a?a:"")}function b(e,t){for(const r of e.elements){if(i(r)&&h(r),!s(r)||!r.name)continue;p(r,o(t,f(r)))}}const g={attributes:!0,attributeFilter:["data-felte-validation-message","aria-invalid"]};
function e(e){let t;return function(e,...t){const r=e.subscribe(...t);return r.unsubscribe?()=>r.unsubscribe():r}(e,(e=>t=e))(),t}class t extends Error{constructor(e,t){super(e),this.name="FelteSubmitError",this.response=t}}function r(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function n(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function i(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function s(e){return r(e)||function(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}(e)||n(e)}function o(e){return e.nodeType===Node.ELEMENT_NODE}function a(e,t,r){const n=r=>String.prototype.split.call(t,r).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),i=n(/[,[\]]+?/)||n(/[,[\].]+?/);return void 0===i||i===e?r:i}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){return Object.keys(e||{}).reduce(((t,r)=>Object.assign(Object.assign({},t),{[r]:u(e[r])?l(e[r]):Array.isArray(e[r])?[...e[r]]:e[r]})),{})}function c(e,t,r){e&&(e=l(e)),u(e)||(e={});const n=Array.isArray(t)?t:t.match(/[^.[\]]+/g)||[],i=n[n.length-1];if(!i)return e;let s=e;for(let e=0;e<n.length-1;e++){const t=n[e];if(!s[t]||!u(s[t])&&!Array.isArray(s[t])){const r=n[e+1];isNaN(Number(r))?s[t]={}:s[t]=[]}s=s[t]}return s[i]=r(s[i]),e}function d(e,t,r){return c(e,t,(()=>r))}function f(e,t){return null!=t?t:s(e)?e.name:""}function v(e){if(s(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const r of e.children){if(s(r)&&t.add(r),i(r))for(const e of r.elements)s(e)&&t.add(e);r.childElementCount>0&&v(r).forEach((e=>t.add(e)))}return Array.from(t)}function h(e){for(const t of e.elements)(s(t)||i(t))&&e.hasAttribute("data-felte-keep-on-remove")&&!t.hasAttribute("data-felte-keep-on-remove")&&(t.dataset.felteKeepOnRemove=e.dataset.felteKeepOnRemove)}function m(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function y(e){var t;let o={},u={};for(const l of e.elements){if(i(l)&&h(l),!s(l)||!l.name)continue;const v=f(l);if(r(l)){if("checkbox"===l.type){if(void 0===a(o,v)){if(1===Array.from(e.querySelectorAll(`[name="${l.name}"]`)).filter((e=>!!s(e)&&v===f(e))).length){o=d(o,v,l.checked),u=d(u,v,!1);continue}o=d(o,v,l.checked?[l.value]:[]),u=d(u,v,!1);continue}Array.isArray(a(o,v))&&l.checked&&(o=c(o,v,(e=>[...e,l.value])));continue}if("radio"===l.type){if(a(o,v))continue;o=d(o,v,l.checked?l.value:void 0),u=d(u,v,!1);continue}if("file"===l.type){o=d(o,v,l.multiple?Array.from(l.files||[]):null===(t=l.files)||void 0===t?void 0:t[0]),u=d(u,v,!1);continue}}else if(n(l)){if(l.multiple){const e=Array.from(l.options).filter((e=>e.selected)).map((e=>e.value));o=d(o,v,e)}else o=d(o,v,l.value);u=d(u,v,!1);continue}const y=m(l);o=d(o,v,y),u=d(u,v,!1)}return{defaultData:o,defaultTouched:u}}function p(e,t){var i;if(!s(e))return;const o=t;if(r(e)){if("checkbox"===e.type){const t=o;return void 0===t||"boolean"==typeof t?void(e.checked=!!t):void(Array.isArray(t)&&(t.includes(e.value)?e.checked=!0:e.checked=!1))}if("radio"===e.type){const t=o;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}else if(n(e)){if(e.multiple){if(Array.isArray(o)){e.value=String(null!==(i=o[0])&&void 0!==i?i:"");for(const t of e.options)o.includes(t.value)?t.selected=!0:t.selected=!1}}else{e.value=String(null!=o?o:"");for(const t of e.options)t.value===o?t.selected=!0:t.selected=!1}return}e.value=String(null!=o?o:"")}function b(e,t){for(const r of e.elements){if(i(r)&&h(r),!s(r)||!r.name)continue;p(r,a(t,f(r)))}}const g={attributes:!0,attributeFilter:["data-felte-validation-message","aria-invalid"]};
/*! *****************************************************************************

@@ -30,3 +30,3 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function F(e){return function(t){if(u(t)){return function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(V(t,e),["key"])}return e}}function V(e,t){return A(e,(e=>u(e)?V(e,t):Array.isArray(e)?e.map(F(t)):t))}function T(e,t){if(!e||Object(e)!==e)return;void 0!==e&&(e=l(e));const r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[],n=1===r.length?e:o(e,r.slice(0,-1).join("."));return Array.isArray(n)?n.splice(Number(r[r.length-1]),1):null==n||delete n[r[r.length-1]],e}function k(e,t,r,n){return c(e,t,(e=>void 0===e||Array.isArray(e)?(e||(e=[]),void 0===n?e.push(r):e.splice(n,0,r),e):e))}function j(e){return"function"==typeof e}function L(e){return(t,r)=>{if("string"==typeof t){const n=t;e((e=>{const t=j(r)?r(o(e,n)):r;return d(e,n,t)}))}else e((e=>j(t)?t(e):t))}}function C({stores:t,config:r,validateErrors:n,validateWarnings:i}){var s;let a,f=_(null!==(s=r.initialValues)&&void 0!==s?s:{});const{data:v,touched:h,errors:m,warnings:y,isDirty:p,isSubmitting:g,interacted:E}=t,A=L(v.update),O=L(h.update),F=L(m.update),j=L(y.update);function C(e){A((t=>{const r=e(t);return a&&b(a,r),r}))}const D=(e,t,r)=>{L(C)(e,t),"string"==typeof e&&r&&O(e,!0)};function I(e){m.update(e),y.update(e),h.update(e),v.update((t=>{const r=e(t);return setTimeout((()=>a&&b(a,r))),r}))}const x=L(g.update),P=L(p.update),N=L(E.update);return{public:{setData:A,setFields:D,setTouched:O,setErrors:F,setWarnings:j,setIsSubmitting:x,setIsDirty:P,setInteracted:N,validate:async function(){const t=e(v);h.set(w(t,!0)),E.set(null);const r=await n(t);return await i(t),r},reset:function(){D(l(f)),O((e=>V(e,!1))),E.set(null),p.set(!1)},unsetField:function(e){I((t=>T(t,e)))},resetField:function(e){const t=o(f,e),r=!!u(t)&&w(t,!1),n=u(r)?V(r,[]):[];v.update((r=>{const n=d(r,e,t);return a&&b(a,n),n})),h.update((t=>d(t,e,r))),m.update((t=>d(t,e,n))),y.update((t=>d(t,e,n)))},addField:function(e,t,r){const n=!!u(t)&&w(t,!1),i=u(n)?V(n,[]):[];t=u(t)?Object.assign(Object.assign({},t),{key:S()}):t,m.update((t=>k(t,e,i,r))),y.update((t=>k(t,e,i,r))),h.update((t=>k(t,e,n,r))),v.update((n=>{const i=k(n,e,t,r);return setTimeout((()=>a&&b(a,i))),i}))},swapFields:function(e,t,r){I((n=>function(e,t,r,n){return c(e,t,(e=>e&&Array.isArray(e)?([e[r],e[n]]=[e[n],e[r]],e):e))}(n,e,t,r)))},moveField:function(e,t,r){I((n=>function(e,t,r,n){return c(e,t,(e=>e&&Array.isArray(e)?(e.splice(n,0,e.splice(r,1)[0]),e):e))}(n,e,t,r)))},setInitialValues:e=>{f=_(e)}},private:{_setFormNode(e){a=e},_getFormNode:()=>a,_getInitialValues:()=>f}}}function D(){class e extends CustomEvent{constructor(e){super("feltesuccess",{detail:e})}}class t extends CustomEvent{constructor(e){super("felteerror",{detail:e,cancelable:!0})}setErrors(e){this.preventDefault(),this.errors=e}}class r extends Event{constructor(){super("feltesubmit",{cancelable:!0})}handleSubmit(e){this.onSubmit=e}handleError(e){this.onError=e}handleSuccess(e){this.onSuccess=e}}return{createErrorEvent:e=>new t(e),createSubmitEvent:()=>new r,createSuccessEvent:t=>new e(t)}}function I(...e){const t=e.pop(),r=l(e.shift());if(0===e.length)return r;for(const n of e){if(!n)continue;let e=t(r,n);if(void 0!==e)return e;const i=Array.from(new Set(Object.keys(r).concat(Object.keys(n))));for(const s of i)if(e=t(r[s],n[s]),void 0!==e)r[s]=e;else if(u(n[s])&&u(r[s]))r[s]=I(r[s],n[s],t);else if(Array.isArray(n[s]))r[s]=n[s].map(((e,n)=>{if(!u(e))return e;return I(Array.isArray(r[s])?r[s][n]:r[s],e,t)}));else if(u(n[s])){const e=V(l(n[s]),void 0);r[s]=I(e,n[s],t)}else void 0!==n[s]&&(r[s]=n[s])}return r}function x(...e){return I(...e,(()=>{}))}function P(e,t){return function(e,t){return Object.keys(e).some((r=>t(e[r])))}(e,(e=>u(e)?P(e,t):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?t(e):e.some((e=>u(e)?P(e,t):t(e))):t(e)))}function N(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function M(e,t){if(!u(e)||!u(t)){if(Array.isArray(t)){if(t.some(u))return;const r=Array.isArray(e)?e:[];return t.map(((e,t)=>{var n;return null!==(n=r[t])&&void 0!==n?n:e}))}return void 0!==e?e:void 0}}function H(...e){return I(...e,M)}function W({helpers:i,stores:c,config:h,extender:p,validateErrors:b,validateWarnings:g,_setFormNode:A,_getFormNode:S,_getInitialValues:_,_setCurrentExtenders:F,_getCurrentExtenders:k}){const{setFields:j,setTouched:L,reset:C,setInitialValues:I}=i,{addValidator:M,addTransformer:W,validate:R,setIsDirty:B,setIsSubmitting:$}=i,q=E(i,["addValidator","addTransformer","validate","setIsDirty","setIsSubmitting"]),{data:U,errors:K,warnings:z,touched:X,isSubmitting:G,isDirty:J,interacted:Q}=c;function Y(r){return async function(n){var i,a,o,u,l,c,d;const f=S(),{createErrorEvent:v,createSubmitEvent:m,createSuccessEvent:y}=D(),p=m();null==f||f.dispatchEvent(p);const E=null!==(a=null!==(i=p.onError)&&void 0!==i?i:null==r?void 0:r.onError)&&void 0!==a?a:h.onError,A=null!==(u=null!==(o=p.onSuccess)&&void 0!==o?o:null==r?void 0:r.onSuccess)&&void 0!==u?u:h.onSuccess,_=null!==(d=null!==(c=null!==(l=p.onSubmit)&&void 0!==l?l:null==r?void 0:r.onSubmit)&&void 0!==c?c:h.onSubmit)&&void 0!==d?d:function(e){if(e)return async function(){let r=new FormData(e);const n=new URL(e.action),i="get"===e.method.toLowerCase()?"get":n.searchParams.get("_method")||e.method;let s,a=e.enctype;e.querySelector('input[type="file"]')&&(a="multipart/form-data"),"get"!==i&&"application/x-www-form-urlencoded"!==a||(r=new URLSearchParams(r)),"get"===i?(r.forEach(((e,t)=>{n.searchParams.append(t,e)})),s={method:i}):s={method:i,body:r,headers:{"Content-Type":a}};const o=await window.fetch(n.toString(),s);if(o.ok)return o;throw new t("An error occurred while submitting the form",o)}}(f);if(!_)return;if(null==n||n.preventDefault(),p.defaultPrevented)return;G.set(!0),Q.set(null);const F=O(e(U)),T=await b(F,null==r?void 0:r.validate),j=await g(F,null==r?void 0:r.warn);if(j&&z.set(x(V(F,[]),j)),X.set(w(F,!0)),T){X.set(w(T,!0));if(P(T,(e=>Array.isArray(e)?e.length>=1:!!e)))return await new Promise((e=>setTimeout(e))),k().forEach((e=>{var t;return null===(t=e.onSubmitError)||void 0===t?void 0:t.call(e,{data:F,errors:T})})),void G.set(!1)}const L=Object.assign(Object.assign({},q),{form:f,controls:f&&Array.from(f.elements).filter(s),config:Object.assign(Object.assign({},h),r)});try{const e=await _(F,L);null==f||f.dispatchEvent(y(Object.assign({response:e},L))),await(null==A?void 0:A(e,L))}catch(t){const r=v(Object.assign({error:t},L));if(null==f||f.dispatchEvent(r),!E&&!r.defaultPrevented)throw t;if(!E&&!r.errors)return;const n=r.errors||await(null==E?void 0:E(t,L));n&&(X.set(w(n,!0)),K.set(n),await new Promise((e=>setTimeout(e))),k().forEach((t=>{var r;return null===(r=t.onSubmitError)||void 0===r?void 0:r.call(t,{data:F,errors:e(K)})})))}finally{G.set(!1)}}}const Z=Y();return{form:function(t){function i(e){return function(r){return r({form:t,stage:e,controls:Array.from(t.elements).filter(s),data:U,errors:K,warnings:z,touched:X,config:h,addValidator:M,addTransformer:W,setFields:j,validate:R,reset:C})}}t.requestSubmit||(t.requestSubmit=Z),F(p.map(i("MOUNT"))),t.noValidate=!!h.validate;const{defaultData:c,defaultTouched:b}=y(t);function g(e){const t=e.target;if(!t||!s(t)||n(t)||N(t))return;if(["checkbox","radio","file"].includes(t.type))return;if(!t.name)return;J.set(!0);const r=m(t);Q.set(t.name),U.update((e=>d(e,f(t),r)))}function E(e){const i=e.target;if(i&&s(i)&&!N(i)&&i.name)if(L(f(i),!0),Q.set(i.name),(n(i)||["checkbox","radio","file","hidden"].includes(i.type))&&J.set(!0),"hidden"===i.type&&U.update((e=>d(e,f(i),i.value))),n(i))!function(e){if(e.multiple){const t=Array.from(e.options).filter((e=>e.selected)).map((e=>e.value));U.update((r=>d(r,f(e),t)))}else U.update((t=>d(t,f(e),e.value)))}(i);else{if(!r(i))return;"checkbox"===i.type?function(e){const n=f(e),i=Array.from(t.querySelectorAll(`[name="${e.name}"]`)).filter((e=>!!s(e)&&n===f(e)));if(0!==i.length)1===i.length?U.update((t=>d(t,f(e),e.checked))):U.update((t=>d(t,f(e),i.filter(r).filter((e=>e.checked)).map((e=>e.value)))))}(i):"radio"===i.type?function(e){const n=t.querySelectorAll(`[name="${e.name}"]`),i=Array.from(n).find((e=>r(e)&&e.checked));U.update((t=>d(t,f(e),null==i?void 0:i.value)))}(i):"file"===i.type&&function(e){var t;const r=Array.from(null!==(t=e.files)&&void 0!==t?t:[]);U.update((t=>d(t,f(e),e.multiple?r:r[0])))}(i)}}function w(e){const t=e.target;t&&s(t)&&!N(t)&&t.name&&(L(f(t),!0),Q.set(t.name))}function S(e){e.preventDefault(),C()}function O(t){for(const r of t.reverse()){if(r.hasAttribute("data-felte-keep-on-remove")&&"false"!==r.dataset.felteKeepOnRemove)continue;const t=/.*(\[[0-9]+\]|\.[0-9]+)\.[^.]+$/;let n=f(r);const i=e(X);if(t.test(n)){const e=n.split(".").slice(0,-1).join("."),t=o(i,e);u(t)&&Object.keys(t).length<=1&&(n=e)}U.update((e=>T(e,n))),X.update((e=>T(e,n))),K.update((e=>T(e,n))),z.update((e=>T(e,n)))}}A(t),I(x(l(c),_())),j(_()),X.set(b);const V=new MutationObserver((function(e){for(const r of e)if("childList"===r.type){if(r.addedNodes.length>0){if(!Array.from(r.addedNodes).some((e=>{if(!a(e))return!1;if(s(e))return!0;return v(e).length>0})))continue;k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),F(p.map(i("UPDATE")));const{defaultData:e,defaultTouched:n}=y(t);U.update((t=>H(t,e))),X.update((e=>H(e,n)))}if(r.removedNodes.length>0)for(const e of r.removedNodes){if(!a(e))continue;const t=v(e);0!==t.length&&(k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),F(p.map(i("UPDATE"))),O(t))}}}));V.observe(t,{childList:!0,subtree:!0}),t.addEventListener("input",g),t.addEventListener("change",E),t.addEventListener("focusout",w),t.addEventListener("submit",Z),t.addEventListener("reset",S);const D=K.subscribe((e=>{for(const r of t.elements){if(!s(r)||!r.name)continue;const t=o(e,f(r)),n=Array.isArray(t)?t.join("\n"):"string"==typeof t?t:void 0;n!==r.dataset.felteValidationMessage&&(n?(r.dataset.felteValidationMessage=n,r.setAttribute("aria-invalid","true")):(delete r.dataset.felteValidationMessage,r.removeAttribute("aria-invalid")))}}));return{destroy(){V.disconnect(),t.removeEventListener("input",g),t.removeEventListener("change",E),t.removeEventListener("focusout",w),t.removeEventListener("submit",Z),t.removeEventListener("reset",S),D(),k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)}))}}},createSubmitHandler:Y,handleSubmit:Z}}function R(e,t){return t?Array.isArray(t)?t.reduce(((e,t)=>t(e)),e):t(e):e}function B(e,t){if(!u(e)&&!u(t)){if(null===e||""===e)return t;if(null===t||""===t)return e;if(!t)return e;if(e&&t){if(Array.isArray(e)){if(!Array.isArray(t))return[...e,t];const r=[],n=Math.max(t.length,e.length);for(let i=0;i<n;i++){let n=e[i],s=t[i];u(n)||u(s)?r.push($([null!=n?n:{},null!=s?s:{}])):(Array.isArray(n)||(n=[n]),Array.isArray(s)||(s=[s]),r.push(...n,...s))}return r.filter(Boolean)}return Array.isArray(t)||(t=[t]),[e,...t].reduce(((e,t)=>e.concat(t)),[]).filter(Boolean)}}}function $(e){return I(...e,B)}function q(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?V(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:e&&n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?e?t:null:e&&t?[t]:null}function U(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?V(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?t:t?[t]:null}function K([e,t]){return I(t,e,q)}function z([e,t]){return I(t,e,U)}function X(e,t=300){let r;return(...n)=>{clearTimeout(r),r=setTimeout((()=>{e.apply(this,n)}),t)}}function G(e,t){var r,n,i,s,a,o,u;const c=function(e){return function(t,r,n){const i=Array.isArray(t)?t:[t],s=new Array(i.length),a=e(n),o=a.set,u=a.subscribe;let l;return a.subscribe=function(e){const t=u(e);return()=>{t()}},[a,function(){l=i.map(((e,t)=>e.subscribe((e=>{s[t]=e,o(r(s))}))))},function(){null==l||l.forEach((e=>e()))}]}}(e),d=t.initialValues=t.initialValues?_(R(l(t.initialValues),t.transform)):{},f=w(O(d),!1),v=e(f),h=e(0),[m,y,p]=c([v,h],(([e,t])=>P(e,(e=>!!e))&&t>=1),!1);function b(e){let t;return async function(r,n,i,s=!1){if(!i||!r)return;let a=n&&Object.keys(n).length>0?n:V(r,[]);const o=function(e){const t={aborted:!1,priority:e};return{signal:t,abort(){t.aborted=!0}}}(s);if((null==t?void 0:t.signal.priority)&&!s||(null==t||t.abort(),t=o),t.signal.priority&&!s)return;h.update((e=>e+1));const u=(l=r,(c=i)?(Array.isArray(c)?c:[c]).map((e=>e(l))):[]);var l,c;return u.forEach((async t=>{const r=await t;o.signal.aborted||(a=$([a,r]),e.set(a))})),await Promise.all(u),t=void 0,h.update((e=>e-1)),a}}delete m.set,delete m.update;let g=V(f,[]);const E=e(d),A=V(f,[]),S=e(A),F=e(l(A)),[T,k,j]=c([S,F],$,l(A)),L=V(f,[]),C=e(L),D=e(l(L)),[I,x,N]=c([C,D],$,l(L)),[M,H,W]=c([T,v],K,l(A)),[B,q,U]=c([I,v],z,l(L));let G=!1;const[J,Q,Y]=c(T,(([e])=>{var r;return G?!P(e,(e=>Array.isArray(e)?e.length>=1:!!e)):(G=!0,!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate))}),!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate));delete J.set,delete J.update;const Z=e(!1),ee=e(!1),te=e(null),re=b(S),ne=b(C),ie=b(F),se=b(D),ae=X(ie,null!==(i=null===(n=t.debounced)||void 0===n?void 0:n.validateTimeout)&&void 0!==i?i:null===(s=t.debounced)||void 0===s?void 0:s.timeout),oe=X(se,null!==(o=null===(a=t.debounced)||void 0===a?void 0:a.warnTimeout)&&void 0!==o?o:null===(u=t.debounced)||void 0===u?void 0:u.timeout);let ue=A,le=L;function ce(){const e=E.subscribe((e=>{var r,n;const i=O(e);re(i,g,t.validate),ne(i,g,t.warn),ae(i,g,null===(r=t.debounced)||void 0===r?void 0:r.validate),oe(i,g,null===(n=t.debounced)||void 0===n?void 0:n.warn)})),r=v.subscribe((e=>{g=V(e,[])})),n=T.subscribe((e=>{ue=e})),i=I.subscribe((e=>{le=e}));return k(),Q(),x(),H(),q(),y(),function(){e(),W(),j(),N(),U(),Y(),p(),r(),n(),i()}}function de(e){S.set(e(ue)),F.set({})}function fe(e){C.set(e(le)),D.set({})}return M.set=function(e){de((()=>e))},M.update=de,B.set=function(e){fe((()=>e))},B.update=fe,{data:E,errors:M,warnings:B,touched:v,isValid:J,isSubmitting:Z,isDirty:ee,isValidating:m,interacted:te,validateErrors:async function(e,r){var n;const i=O(e),s=re(i,g,null!=r?r:t.validate,!0);if(r)return s;const a=ie(i,g,null===(n=t.debounced)||void 0===n?void 0:n.validate,!0);return $(await Promise.all([s,a]))},validateWarnings:async function(e,r){var n;const i=O(e),s=ne(i,g,null!=r?r:t.warn,!0);if(r)return s;const a=se(i,g,null===(n=t.debounced)||void 0===n?void 0:n.warn,!0);return $(await Promise.all([s,a]))},cleanup:t.preventStoreStart?()=>{}:ce(),start:ce}}function J(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every(((e,r)=>J(e,t[r])));if(u(e)&&u(t)){const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&r.every((r=>J(e[r],t[r])))}return!1}class Q extends HTMLElement{constructor(){var e;super(...arguments),this.touchOnChange=!1,this.valueProp="value",this.inputEvent="input",this.blurEvent="focusout",this.composed=!1,this._onBlur=(e="blur",function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFieldElement. The element is not ready yet.`)}),this._ready=!1}static get observedAttributes(){return["name","touchonchange","valueprop","inputevent","blurevent","composed","value"]}static get attributeMap(){return{name:{converter:String,name:"name"},touchonchange:{converter:e=>""===e||!!e&&"false"!==e,name:"touchOnChange"},valueprop:{converter:String,name:"valueProp"},inputevent:{converter:String,name:"inputEvent"},blurevent:{converter:String,name:"blurEvent"},value:{converter:String,name:"value"},composed:{converter:e=>""===e||!!e&&"false"!==e,name:"composed"}}}attributeChangedCallback(e,t,r){if(t===r)return;const{converter:n,name:i}=Q.attributeMap[e];this[i]=n(r)}set value(e){var t;null===(t=this._onInput)||void 0===t||t.call(this,e),this._value=e}get value(){return this._value}blur(){this._onBlur()}get ready(){return this._ready}_createField(){var e;const{name:t,inputEvent:r,blurEvent:n,touchOnChange:i,value:o,composed:u}=this;if(!t)throw new Error('<felte-field> must have a "name" attribute');const l=this.children.item(0);if(!l)return;l[this.valueProp]=o;const{field:c,onInput:d,onBlur:f}=function(e,t){var r,n;let i,o,u,l,c,d;function f(e,t){if(!c)return;p(c,t);const r=new Event(e,{bubbles:!0,cancelable:!0});c.dispatchEvent(r)}function v(e){e.forEach((()=>{const e=c.getAttribute("aria-invalid");e?l.setAttribute("aria-invalid",e):l.removeAttribute("aria-invalid");const t=c.getAttribute("data-felte-validation-message");t?l.setAttribute("data-felte-validation-message",t):l.removeAttribute("data-felte-validation-message")}))}function h(e){d&&(p(c,o),d(e))}function m(e){f(u?"change":"input",e)}return"string"==typeof e?(i=e,o=null==t?void 0:t.defaultValue,u=null!==(r=null==t?void 0:t.touchOnChange)&&void 0!==r&&r,d=null==t?void 0:t.onFormReset):(i=e.name,o=e.defaultValue,u=null!==(n=e.touchOnChange)&&void 0!==n&&n,d=null==e?void 0:e.onFormReset),{field:function(e){let t,r;return l=e,s(e)?(c=e,c.name=i,{}):(setTimeout((()=>{const n=l.parentNode;if(!n||!a(n))return;const u=n.querySelector(`[name="${i}"]`);if(u&&s(u))c=u;else{const t=document.createElement("input");t.type="hidden",t.name=i,n.insertBefore(t,e.nextSibling),c=t}p(c,o),t=new MutationObserver(v),t.observe(c,g),r=c.closest("form"),null==r||r.addEventListener("reset",h)})),{destroy(){null==t||t.disconnect(),null==r||r.removeEventListener("reset",h)}})},onInput:m,onChange:m,onBlur:function(){f("focusout")}}}(t,{touchOnChange:i,defaultValue:o,onFormReset:()=>{this.value=o,l[this.valueProp]=o}});this._onInput=d,this._onBlur=f;const{destroy:v}=c(l),h=e=>{const t=u?e.composedPath()[0]:e.target;this.value=t[this.valueProp]},m=()=>{f()};l.addEventListener(r,h),l.addEventListener(n,m),this._destroy=()=>{null==v||v(),l.removeEventListener(r,h),l.removeEventListener(r,m)},this._ready=!0,null===(e=this.onfeltefieldready)||void 0===e||e.call(this),this.dispatchEvent(new Event("feltefieldready"))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&this._createField()}))}disconnectedCallback(){var e;null===(e=this._destroy)||void 0===e||e.call(this)}}customElements.get("felte-field")||customElements.define("felte-field",Q);const Y=[],Z=()=>{};function ee(e,t=Z){let r;const n=new Set;function i(t){if(s=t,((i=e)!=i?s==s:i!==s||i&&"object"==typeof i||"function"==typeof i)&&(e=t,r)){const t=!Y.length;for(const t of n)t[1](),Y.push(t,e);if(t){for(let e=0;e<Y.length;e+=2)Y[e][0](Y[e+1]);Y.length=0}}var i,s}return{set:i,update:function(t){i(t(e))},subscribe:function(s,a=Z){const o=[s,a];return n.add(o),1===n.size&&(r=t(i)||Z),s(e),()=>{n.delete(o),r&&0===n.size&&(r(),r=null)}}}}function te(e){return function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFormElement. The element is not ready yet.`)}}const re=["data","errors","touched","warnings","isSubmitting","isDirty","isValid","isValidating","interacted"];class ne extends HTMLElement{constructor(){super(...arguments),this.id="",this._configuration={},this._storeValues={data:void 0,errors:void 0,touched:void 0,warnings:void 0,isSubmitting:!1,isDirty:!1,isValid:void 0,isValidating:!1,interacted:null},this.setData=te("setData"),this.setFields=te("setFields"),this.setInitialValues=te("setInitialValues"),this.addField=te("addField"),this.unsetField=te("unsetField"),this.swapFields=te("swapFields"),this.moveField=te("moveField"),this.resetField=te("resetField"),this.reset=te("reset"),this.submit=te("submit"),this.createSubmitHandler=te("createSubmitHandler"),this.setErrors=te("setErrors"),this.setTouched=te("setTouched"),this.setWarnings=te("setWarnings"),this.setIsSubmitting=te("setIsSubmitting"),this.setIsDirty=te("setIsDirty"),this.setInteracted=te("setInteracted"),this._ready=!1,this.validate=te("validate"),this._formElement=null,this._onChildChange=()=>{var e;const t=this.querySelector("form");t&&t!==this._formElement&&(this._formElement=t,null===(e=this._destroy)||void 0===e||e.call(this),this._createForm(this._configuration))}}setConfiguration(e){this._configuration=e,this._destroy&&(this._destroy(),this._destroy=void 0,this._ready=!1,this._createForm(e))}get data(){return this._storeValues.data}get errors(){return this._storeValues.errors}get touched(){return this._storeValues.touched}get warnings(){return this._storeValues.warnings}get isSubmitting(){return this._storeValues.isSubmitting}get isDirty(){return this._storeValues.isDirty}get isValid(){return this._storeValues.isValid}get isValidating(){return this._storeValues.isValidating}get interacted(){return this._storeValues.interacted}get ready(){return this._ready}_createForm(e){var t;const r=this._formElement;if(!r||this._destroy)return;this.elements=r.elements;const{form:n,cleanup:i,...s}=function(e,t){var r,n;function i(t,{debounced:r,level:n}={debounced:!1,level:"error"}){var i;const s="error"===n?"validate":"warn";null!==(i=e.debounced)&&void 0!==i||(e.debounced={});const a=r?e.debounced:e;a[s]?a[s]=[...a[s],t]:a[s]=[t]}function s(t){e.transform?e.transform=[...e.transform,t]:e.transform=[t]}null!==(r=e.extend)&&void 0!==r||(e.extend=[]),null!==(n=e.debounced)&&void 0!==n||(e.debounced={}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]),e.debounced.validate&&!Array.isArray(e.debounced.validate)&&(e.debounced.validate=[e.debounced.validate]),e.transform&&!Array.isArray(e.transform)&&(e.transform=[e.transform]),e.warn&&!Array.isArray(e.warn)&&(e.warn=[e.warn]),e.debounced.warn&&!Array.isArray(e.debounced.warn)&&(e.debounced.warn=[e.debounced.warn]);const a=Array.isArray(e.extend)?e.extend:[e.extend];let o=[];const{isSubmitting:u,isValidating:l,data:c,errors:d,warnings:f,touched:v,isValid:h,isDirty:m,cleanup:y,start:p,validateErrors:b,validateWarnings:g,interacted:E}=G(t.storeFactory,e),A=c.update,w=c.set;c.update=t=>A((r=>_(R(t(r),e.transform)))),c.set=t=>w(_(R(t,e.transform)));const S=C({extender:a,config:e,addValidator:i,addTransformer:s,validateErrors:b,validateWarnings:g,stores:{data:c,errors:d,warnings:f,touched:v,isValid:h,isValidating:l,isSubmitting:u,isDirty:m,interacted:E}});o=a.map((t=>t({stage:"SETUP",errors:d,warnings:f,touched:v,data:c,config:e,addValidator:i,addTransformer:s,setFields:S.public.setFields,reset:S.public.reset,validate:S.public.validate})));const O=Object.assign({config:e,stores:{data:c,touched:v,errors:d,warnings:f,isSubmitting:u,isValidating:l,isValid:h,isDirty:m,interacted:E},helpers:Object.assign(Object.assign({},S.public),{addTransformer:s,addValidator:i}),extender:a,validateErrors:b,validateWarnings:g,_getCurrentExtenders:()=>o,_setCurrentExtenders:e=>{o=e}},S.private),{form:F,createSubmitHandler:V,handleSubmit:T}=W(O);return Object.assign({data:c,errors:d,warnings:f,touched:v,isValid:h,isSubmitting:u,isValidating:l,isDirty:m,interacted:E,form:F,handleSubmit:T,createSubmitHandler:V,cleanup:y,startStores:p},S.public)}(e,{storeFactory:ee});this.setData=s.setData,this.setFields=s.setFields,this.setErrors=s.setErrors,this.setTouched=s.setTouched,this.setWarnings=s.setWarnings,this.setIsSubmitting=s.setIsSubmitting,this.setIsDirty=s.setIsDirty,this.setInteracted=s.setInteracted,this.setInitialValues=s.setInitialValues,this.validate=s.validate,this.addField=s.addField,this.unsetField=s.unsetField,this.swapFields=s.swapFields,this.moveField=s.moveField,this.resetField=s.resetField,this.reset=s.reset,this.submit=s.handleSubmit,this.createSubmitHandler=s.createSubmitHandler;const a=re.map((e=>s[e].subscribe((t=>{if(J(t,this._storeValues[e]))return;this._storeValues[e]=t;const r=e.toLowerCase(),n=this[`on${r}change`];"function"==typeof n&&n(t),this.dispatchEvent(new Event(`${r}change`))})))),{destroy:o}=n(r),{createSubmitEvent:u,createErrorEvent:l,createSuccessEvent:c}=D(),d=e=>{const t=e,r=u();this.dispatchEvent(r),r.defaultPrevented&&t.preventDefault(),t.onSubmit=r.onSubmit,t.onSuccess=r.onSuccess,t.onError=r.onError},f=e=>{const t=c(e.detail);this.dispatchEvent(t)},v=e=>{const t=e,r=l(t.detail);this.dispatchEvent(r),t.errors=r.errors,r.defaultPrevented&&t.preventDefault()};r.addEventListener("feltesubmit",d),r.addEventListener("feltesuccess",f),r.addEventListener("felteerror",v),this._destroy=()=>{o(),i(),r.removeEventListener("feltesubmit",d),r.removeEventListener("feltesuccess",f),r.removeEventListener("felteerror",v),a.forEach((e=>e()))},this._ready=!0,null===(t=this.onfelteready)||void 0===t||t.call(this),this.dispatchEvent(new Event("felteready",{bubbles:!0,composed:!0}))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&(this.dispatchEvent(new Event("felteconnect",{bubbles:!0,composed:!0})),this._onChildChange(),this._observer=new MutationObserver(this._onChildChange),this._observer.observe(this,{childList:!0}))}))}disconnectedCallback(){var e,t;null===(e=this._destroy)||void 0===e||e.call(this),null===(t=this._observer)||void 0===t||t.disconnect()}static get observedAttributes(){return["id"]}attributeChangedCallback(e,t,r){if(t!==r)switch(e){case"id":this.id=r}}}function ie(e,t){return document.addEventListener("felteconnect",(function r(n){const i=n.composedPath()[0];i.id===e&&(i.setConfiguration(t),document.removeEventListener("felteconnect",r))})),new Promise((t=>{document.addEventListener("felteready",(function r(n){const i=n.composedPath()[0];i.id===e&&(t(i),document.removeEventListener("felteready",r))}))}))}customElements.get("felte-form")||customElements.define("felte-form",ne);export{Q as FelteField,ne as FelteForm,t as FelteSubmitError,ie as prepareForm};
***************************************************************************** */function F(e){return function(t){if(u(t)){return function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(V(t,e),["key"])}return e}}function V(e,t){return A(e,(e=>u(e)?V(e,t):Array.isArray(e)?e.map(F(t)):t))}function T(e,t){if(!e||Object(e)!==e)return;void 0!==e&&(e=l(e));const r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[],n=1===r.length?e:a(e,r.slice(0,-1).join("."));return Array.isArray(n)?n.splice(Number(r[r.length-1]),1):null==n||delete n[r[r.length-1]],e}function k(e,t,r,n){return c(e,t,(e=>void 0===e||Array.isArray(e)?(e||(e=[]),void 0===n?e.push(r):e.splice(n,0,r),e):e))}function j(e){return"function"==typeof e}function L(e){return(t,r)=>{if("string"==typeof t){const n=t;e((e=>{const t=j(r)?r(a(e,n)):r;return d(e,n,t)}))}else e((e=>j(t)?t(e):t))}}function C({stores:t,config:r,validateErrors:n,validateWarnings:i}){var s;let o,f=_(null!==(s=r.initialValues)&&void 0!==s?s:{});const{data:v,touched:h,errors:m,warnings:y,isDirty:p,isSubmitting:g,interacted:E}=t,A=L(v.update),O=L(h.update),F=L(m.update),j=L(y.update);function C(e){A((t=>{const r=e(t);return o&&b(o,r),r}))}const D=(e,t,r)=>{L(C)(e,t),"string"==typeof e&&r&&O(e,!0)};function I(e){m.update(e),y.update(e),h.update(e),v.update((t=>{const r=e(t);return setTimeout((()=>o&&b(o,r))),r}))}const x=L(g.update),P=L(p.update),N=L(E.update);return{public:{setData:A,setFields:D,setTouched:O,setErrors:F,setWarnings:j,setIsSubmitting:x,setIsDirty:P,setInteracted:N,validate:async function(){const t=e(v);h.set(w(t,!0)),E.set(null);const r=await n(t);return await i(t),r},reset:function(){D(l(f)),O((e=>V(e,!1))),E.set(null),p.set(!1)},unsetField:function(e){I((t=>T(t,e)))},resetField:function(e){const t=a(f,e),r=!!u(t)&&w(t,!1),n=u(r)?V(r,[]):[];v.update((r=>{const n=d(r,e,t);return o&&b(o,n),n})),h.update((t=>d(t,e,r))),m.update((t=>d(t,e,n))),y.update((t=>d(t,e,n)))},addField:function(e,t,r){const n=!!u(t)&&w(t,!1),i=u(n)?V(n,[]):[];t=u(t)?Object.assign(Object.assign({},t),{key:S()}):t,m.update((t=>k(t,e,i,r))),y.update((t=>k(t,e,i,r))),h.update((t=>k(t,e,n,r))),v.update((n=>{const i=k(n,e,t,r);return setTimeout((()=>o&&b(o,i))),i}))},swapFields:function(e,t,r){I((n=>function(e,t,r,n){return c(e,t,(e=>e&&Array.isArray(e)?([e[r],e[n]]=[e[n],e[r]],e):e))}(n,e,t,r)))},moveField:function(e,t,r){I((n=>function(e,t,r,n){return c(e,t,(e=>e&&Array.isArray(e)?(e.splice(n,0,e.splice(r,1)[0]),e):e))}(n,e,t,r)))},setInitialValues:e=>{f=_(e)}},private:{_setFormNode(e){o=e},_getFormNode:()=>o,_getInitialValues:()=>f}}}function D(){class e extends CustomEvent{constructor(e){super("feltesuccess",{detail:e})}}class t extends CustomEvent{constructor(e){super("felteerror",{detail:e,cancelable:!0})}setErrors(e){this.preventDefault(),this.errors=e}}class r extends Event{constructor(){super("feltesubmit",{cancelable:!0})}handleSubmit(e){this.onSubmit=e}handleError(e){this.onError=e}handleSuccess(e){this.onSuccess=e}}return{createErrorEvent:e=>new t(e),createSubmitEvent:()=>new r,createSuccessEvent:t=>new e(t)}}function I(...e){const t=e.pop(),r=l(e.shift());if(0===e.length)return r;for(const n of e){if(!n)continue;let e=t(r,n);if(void 0!==e)return e;const i=Array.from(new Set(Object.keys(r).concat(Object.keys(n))));for(const s of i)if(e=t(r[s],n[s]),void 0!==e)r[s]=e;else if(u(n[s])&&u(r[s]))r[s]=I(r[s],n[s],t);else if(Array.isArray(n[s]))r[s]=n[s].map(((e,n)=>{if(!u(e))return e;return I(Array.isArray(r[s])?r[s][n]:r[s],e,t)}));else if(u(n[s])){const e=V(l(n[s]),void 0);r[s]=I(e,n[s],t)}else void 0!==n[s]&&(r[s]=n[s])}return r}function x(...e){return I(...e,(()=>{}))}function P(e,t){return function(e,t){return Object.keys(e).some((r=>t(e[r])))}(e,(e=>u(e)?P(e,t):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?t(e):e.some((e=>u(e)?P(e,t):t(e))):t(e)))}function N(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function M(e,t){let r;return(...n)=>{clearTimeout(r),r=setTimeout((()=>{e.apply(this,n)}),t)}}function H(e,t){if(!u(e)||!u(t)){if(Array.isArray(t)){if(t.some(u))return;const r=Array.isArray(e)?e:[];return t.map(((e,t)=>{var n;return null!==(n=r[t])&&void 0!==n?n:e}))}return void 0!==e?e:void 0}}function W(...e){return I(...e,H)}function R({helpers:i,stores:c,config:h,extender:p,validateErrors:b,validateWarnings:g,_setFormNode:A,_getFormNode:S,_getInitialValues:_,_setCurrentExtenders:F,_getCurrentExtenders:k}){const{setFields:j,setTouched:L,reset:C,setInitialValues:I}=i,{addValidator:H,addTransformer:R,validate:B,setIsDirty:$,setIsSubmitting:q}=i,U=E(i,["addValidator","addTransformer","validate","setIsDirty","setIsSubmitting"]),{data:K,errors:z,warnings:X,touched:G,isSubmitting:J,isDirty:Q,interacted:Y}=c;function Z(r){return async function(n){var i,o,a,u,l,c,d;const f=S(),{createErrorEvent:v,createSubmitEvent:m,createSuccessEvent:y}=D(),p=m();null==f||f.dispatchEvent(p);const E=null!==(o=null!==(i=p.onError)&&void 0!==i?i:null==r?void 0:r.onError)&&void 0!==o?o:h.onError,A=null!==(u=null!==(a=p.onSuccess)&&void 0!==a?a:null==r?void 0:r.onSuccess)&&void 0!==u?u:h.onSuccess,_=null!==(d=null!==(c=null!==(l=p.onSubmit)&&void 0!==l?l:null==r?void 0:r.onSubmit)&&void 0!==c?c:h.onSubmit)&&void 0!==d?d:function(e){if(e)return async function(){let r=new FormData(e);const n=new URL(e.action),i="get"===e.method.toLowerCase()?"get":n.searchParams.get("_method")||e.method;let s,o=e.enctype;e.querySelector('input[type="file"]')&&(o="multipart/form-data"),"get"!==i&&"application/x-www-form-urlencoded"!==o||(r=new URLSearchParams(r)),"get"===i?(r.forEach(((e,t)=>{n.searchParams.append(t,e)})),s={method:i}):s={method:i,body:r,headers:{"Content-Type":o}};const a=await window.fetch(n.toString(),s);if(a.ok)return a;throw new t("An error occurred while submitting the form",a)}}(f);if(!_)return;if(null==n||n.preventDefault(),p.defaultPrevented)return;J.set(!0),Y.set(null);const F=O(e(K)),T=await b(F,null==r?void 0:r.validate),j=await g(F,null==r?void 0:r.warn);if(j&&X.set(x(V(F,[]),j)),G.set(w(F,!0)),T){G.set(w(T,!0));if(P(T,(e=>Array.isArray(e)?e.length>=1:!!e)))return await new Promise((e=>setTimeout(e))),k().forEach((e=>{var t;return null===(t=e.onSubmitError)||void 0===t?void 0:t.call(e,{data:F,errors:T})})),void J.set(!1)}const L=Object.assign(Object.assign({},U),{form:f,controls:f&&Array.from(f.elements).filter(s),config:Object.assign(Object.assign({},h),r)});try{const e=await _(F,L);null==f||f.dispatchEvent(y(Object.assign({response:e},L))),await(null==A?void 0:A(e,L))}catch(t){const r=v(Object.assign({error:t},L));if(null==f||f.dispatchEvent(r),!E&&!r.defaultPrevented)throw t;if(!E&&!r.errors)return;const n=r.errors||await(null==E?void 0:E(t,L));n&&(G.set(w(n,!0)),z.set(n),await new Promise((e=>setTimeout(e))),k().forEach((t=>{var r;return null===(r=t.onSubmitError)||void 0===r?void 0:r.call(t,{data:F,errors:e(z)})})))}finally{J.set(!1)}}}const ee=Z();return{form:function(t){function i(e){return function(r){return r({form:t,stage:e,controls:Array.from(t.elements).filter(s),data:K,errors:z,warnings:X,touched:G,config:h,addValidator:H,addTransformer:R,setFields:j,validate:B,reset:C})}}t.requestSubmit||(t.requestSubmit=ee),F(p.map(i("MOUNT"))),t.noValidate=!!h.validate;const{defaultData:c,defaultTouched:b}=y(t);function g(e){const t=e.target;if(!t||!s(t)||n(t)||N(t))return;if(["checkbox","radio","file"].includes(t.type))return;if(!t.name)return;Q.set(!0);const r=m(t);Y.set(t.name),K.update((e=>d(e,f(t),r)))}function E(e){const i=e.target;if(i&&s(i)&&!N(i)&&i.name)if(L(f(i),!0),Y.set(i.name),(n(i)||["checkbox","radio","file","hidden"].includes(i.type))&&Q.set(!0),"hidden"===i.type&&K.update((e=>d(e,f(i),i.value))),n(i))!function(e){if(e.multiple){const t=Array.from(e.options).filter((e=>e.selected)).map((e=>e.value));K.update((r=>d(r,f(e),t)))}else K.update((t=>d(t,f(e),e.value)))}(i);else{if(!r(i))return;"checkbox"===i.type?function(e){const n=f(e),i=Array.from(t.querySelectorAll(`[name="${e.name}"]`)).filter((e=>!!s(e)&&n===f(e)));if(0!==i.length)1===i.length?K.update((t=>d(t,f(e),e.checked))):K.update((t=>d(t,f(e),i.filter(r).filter((e=>e.checked)).map((e=>e.value)))))}(i):"radio"===i.type?function(e){const n=t.querySelectorAll(`[name="${e.name}"]`),i=Array.from(n).find((e=>r(e)&&e.checked));K.update((t=>d(t,f(e),null==i?void 0:i.value)))}(i):"file"===i.type&&function(e){var t;const r=Array.from(null!==(t=e.files)&&void 0!==t?t:[]);K.update((t=>d(t,f(e),e.multiple?r:r[0])))}(i)}}function w(e){const t=e.target;t&&s(t)&&!N(t)&&t.name&&(L(f(t),!0),Y.set(t.name))}function S(e){e.preventDefault(),C()}A(t),I(x(l(c),_())),j(_()),G.set(b);const O=M((()=>{k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),F(p.map(i("UPDATE")));const{defaultData:e,defaultTouched:r}=y(t);K.update((t=>W(t,e))),G.update((e=>W(e,r)))}),0);let V=[];const D=M((()=>{k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)})),F(p.map(i("UPDATE"))),function(t){let r=e(K),n=e(G),i=e(z),s=e(X);for(const o of t.reverse()){if(o.hasAttribute("data-felte-keep-on-remove")&&"false"!==o.dataset.felteKeepOnRemove)continue;const t=/.*(\[[0-9]+\]|\.[0-9]+)\.[^.]+$/;let l=f(o);const c=e(G);if(t.test(l)){const e=l.split(".").slice(0,-1).join("."),t=a(c,e);u(t)&&Object.keys(t).length<=1&&(l=e)}r=T(r,l),n=T(n,l),i=T(i,l),s=T(s,l)}K.set(r),G.set(n),z.set(i),X.set(s)}(V),V=[]}),0),P=new MutationObserver((function(e){for(const t of e)if("childList"===t.type){if(t.addedNodes.length>0){if(!Array.from(t.addedNodes).some((e=>{if(!o(e))return!1;if(s(e))return!0;return v(e).length>0})))continue;O()}if(t.removedNodes.length>0)for(const e of t.removedNodes){if(!o(e))continue;const t=v(e);0!==t.length&&(V.push(...t),D())}}}));P.observe(t,{childList:!0,subtree:!0}),t.addEventListener("input",g),t.addEventListener("change",E),t.addEventListener("focusout",w),t.addEventListener("submit",ee),t.addEventListener("reset",S);const $=z.subscribe((e=>{for(const r of t.elements){if(!s(r)||!r.name)continue;const t=a(e,f(r)),n=Array.isArray(t)?t.join("\n"):"string"==typeof t?t:void 0;n!==r.dataset.felteValidationMessage&&(n?(r.dataset.felteValidationMessage=n,r.setAttribute("aria-invalid","true")):(delete r.dataset.felteValidationMessage,r.removeAttribute("aria-invalid")))}}));return{destroy(){P.disconnect(),t.removeEventListener("input",g),t.removeEventListener("change",E),t.removeEventListener("focusout",w),t.removeEventListener("submit",ee),t.removeEventListener("reset",S),$(),k().forEach((e=>{var t;return null===(t=e.destroy)||void 0===t?void 0:t.call(e)}))}}},createSubmitHandler:Z,handleSubmit:ee}}function B(e,t){return t?Array.isArray(t)?t.reduce(((e,t)=>t(e)),e):t(e):e}function $(e,t){if(!u(e)&&!u(t)){if(null===e||""===e)return t;if(null===t||""===t)return e;if(!t)return e;if(e&&t){if(Array.isArray(e)){if(!Array.isArray(t))return[...e,t];const r=[],n=Math.max(t.length,e.length);for(let i=0;i<n;i++){let n=e[i],s=t[i];u(n)||u(s)?r.push(q([null!=n?n:{},null!=s?s:{}])):(Array.isArray(n)||(n=[n]),Array.isArray(s)||(s=[s]),r.push(...n,...s))}return r.filter(Boolean)}return Array.isArray(t)||(t=[t]),[e,...t].reduce(((e,t)=>e.concat(t)),[]).filter(Boolean)}}}function q(e){return I(...e,$)}function U(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?V(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:e&&n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?e?t:null:e&&t?[t]:null}function K(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?V(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const r=Array.isArray(t)?t:[];return e.map(((e,t)=>{const n=r[t];return Array.isArray(n)&&0===n.length?null:n||null}))}return Array.isArray(t)&&0===t.length?null:Array.isArray(t)?t:t?[t]:null}function z([e,t]){return I(t,e,U)}function X([e,t]){return I(t,e,K)}function G(e,t){var r,n,i,s,o,a,u,c,d;const f=function(e){return function(t,r,n){const i=Array.isArray(t)?t:[t],s=new Array(i.length),o=e(n),a=o.set,u=o.subscribe;let l;return o.subscribe=function(e){const t=u(e);return()=>{t()}},[o,function(){l=i.map(((e,t)=>e.subscribe((e=>{s[t]=e,a(r(s))}))))},function(){null==l||l.forEach((e=>e()))}]}}(e),v=t.initialValues=t.initialValues?_(B(l(t.initialValues),t.transform)):{},h=w(O(v),!1),m=e(h),y=e(0),[p,b,g]=f([m,y],(([e,t])=>P(e,(e=>!!e))&&t>=1),!1);function E(e){let t;return async function(r,n,i,s=!1){if(!i||!r)return;let o=n&&Object.keys(n).length>0?n:V(r,[]);const a=function(e){const t={aborted:!1,priority:e};return{signal:t,abort(){t.aborted=!0}}}(s);if((null==t?void 0:t.signal.priority)&&!s||(null==t||t.abort(),t=a),t.signal.priority&&!s)return;y.update((e=>e+1));const u=(l=r,(c=i)?(Array.isArray(c)?c:[c]).map((e=>e(l))):[]);var l,c;return u.forEach((async t=>{const r=await t;a.signal.aborted||(o=q([o,r]),e.set(o))})),await Promise.all(u),t=void 0,y.update((e=>e-1)),o}}delete p.set,delete p.update;let A=V(h,[]);const S=e(v),F=V(h,[]),T=e(F),k=e(l(F)),[j,L,C]=f([T,k],q,l(F)),D=V(h,[]),I=e(D),x=e(l(D)),[N,H,W]=f([I,x],q,l(D)),[R,$,U]=f([j,m],z,l(F)),[K,G,J]=f([N,m],X,l(D));let Q=!1;const[Y,Z,ee]=f(j,(([e])=>{var r;return Q?!P(e,(e=>Array.isArray(e)?e.length>=1:!!e)):(Q=!0,!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate))}),!t.validate&&!(null===(r=t.debounced)||void 0===r?void 0:r.validate));delete Y.set,delete Y.update;const te=e(!1),re=e(!1),ne=e(null),ie=E(T),se=E(I),oe=E(k),ae=E(x),ue=M(oe,null!==(o=null!==(i=null===(n=t.debounced)||void 0===n?void 0:n.validateTimeout)&&void 0!==i?i:null===(s=t.debounced)||void 0===s?void 0:s.timeout)&&void 0!==o?o:300),le=M(ae,null!==(d=null!==(u=null===(a=t.debounced)||void 0===a?void 0:a.warnTimeout)&&void 0!==u?u:null===(c=t.debounced)||void 0===c?void 0:c.timeout)&&void 0!==d?d:300);let ce=F,de=D;function fe(){const e=S.subscribe((e=>{var r,n;const i=O(e);ie(i,A,t.validate),se(i,A,t.warn),ue(i,A,null===(r=t.debounced)||void 0===r?void 0:r.validate),le(i,A,null===(n=t.debounced)||void 0===n?void 0:n.warn)})),r=m.subscribe((e=>{A=V(e,[])})),n=j.subscribe((e=>{ce=e})),i=N.subscribe((e=>{de=e}));return L(),Z(),H(),$(),G(),b(),function(){e(),U(),C(),W(),J(),ee(),g(),r(),n(),i()}}function ve(e){T.set(e(ce)),k.set({})}function he(e){I.set(e(de)),x.set({})}return R.set=function(e){ve((()=>e))},R.update=ve,K.set=function(e){he((()=>e))},K.update=he,{data:S,errors:R,warnings:K,touched:m,isValid:Y,isSubmitting:te,isDirty:re,isValidating:p,interacted:ne,validateErrors:async function(e,r){var n;const i=O(e),s=ie(i,A,null!=r?r:t.validate,!0);if(r)return s;const o=oe(i,A,null===(n=t.debounced)||void 0===n?void 0:n.validate,!0);return q(await Promise.all([s,o]))},validateWarnings:async function(e,r){var n;const i=O(e),s=se(i,A,null!=r?r:t.warn,!0);if(r)return s;const o=ae(i,A,null===(n=t.debounced)||void 0===n?void 0:n.warn,!0);return q(await Promise.all([s,o]))},cleanup:t.preventStoreStart?()=>{}:fe(),start:fe}}function J(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every(((e,r)=>J(e,t[r])));if(u(e)&&u(t)){const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&r.every((r=>J(e[r],t[r])))}return!1}class Q extends HTMLElement{constructor(){var e;super(...arguments),this.touchOnChange=!1,this.valueProp="value",this.inputEvent="input",this.blurEvent="focusout",this.composed=!1,this._onBlur=(e="blur",function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFieldElement. The element is not ready yet.`)}),this._ready=!1}static get observedAttributes(){return["name","touchonchange","valueprop","inputevent","blurevent","composed","value"]}static get attributeMap(){return{name:{converter:String,name:"name"},touchonchange:{converter:e=>""===e||!!e&&"false"!==e,name:"touchOnChange"},valueprop:{converter:String,name:"valueProp"},inputevent:{converter:String,name:"inputEvent"},blurevent:{converter:String,name:"blurEvent"},value:{converter:String,name:"value"},composed:{converter:e=>""===e||!!e&&"false"!==e,name:"composed"}}}attributeChangedCallback(e,t,r){if(t===r)return;const{converter:n,name:i}=Q.attributeMap[e];this[i]=n(r)}set value(e){var t;null===(t=this._onInput)||void 0===t||t.call(this,e),this._value=e}get value(){return this._value}blur(){this._onBlur()}get ready(){return this._ready}_createField(){var e;const{name:t,inputEvent:r,blurEvent:n,touchOnChange:i,value:a,composed:u}=this;if(!t)throw new Error('<felte-field> must have a "name" attribute');const l=this.children.item(0);if(!l)return;l[this.valueProp]=a;const{field:c,onInput:d,onBlur:f}=function(e,t){var r,n;let i,a,u,l,c,d;function f(e,t){if(!c)return;p(c,t);const r=new Event(e,{bubbles:!0,composed:!0});c.dispatchEvent(r)}function v(e){e.forEach((()=>{const e=c.getAttribute("aria-invalid");e?l.setAttribute("aria-invalid",e):l.removeAttribute("aria-invalid");const t=c.getAttribute("data-felte-validation-message");t?l.setAttribute("data-felte-validation-message",t):l.removeAttribute("data-felte-validation-message")}))}function h(e){d&&(p(c,a),d(e))}function m(e){f(u?"change":"input",e)}return"string"==typeof e?(i=e,a=null==t?void 0:t.defaultValue,u=null!==(r=null==t?void 0:t.touchOnChange)&&void 0!==r&&r,d=null==t?void 0:t.onFormReset):(i=e.name,a=e.defaultValue,u=null!==(n=e.touchOnChange)&&void 0!==n&&n,d=null==e?void 0:e.onFormReset),{field:function(e){let t,r;return l=e,s(e)?(c=e,c.name=i,{}):(setTimeout((()=>{const n=l.parentNode;if(!n||!o(n))return;const u=n.querySelector(`[name="${i}"]`);if(u&&s(u))c=u;else{const t=document.createElement("input");t.type="hidden",t.name=i,n.insertBefore(t,e.nextSibling),c=t}p(c,a),t=new MutationObserver(v),t.observe(c,g),r=c.closest("form"),null==r||r.addEventListener("reset",h)})),{destroy(){null==t||t.disconnect(),null==r||r.removeEventListener("reset",h)}})},onInput:m,onChange:m,onBlur:function(){f("focusout")}}}(t,{touchOnChange:i,defaultValue:a,onFormReset:()=>{this.value=a,l[this.valueProp]=a}});this._onInput=d,this._onBlur=f;const{destroy:v}=c(l),h=e=>{const t=u?e.composedPath()[0]:e.target;this.value=t[this.valueProp]},m=()=>{f()};l.addEventListener(r,h),l.addEventListener(n,m),this._destroy=()=>{null==v||v(),l.removeEventListener(r,h),l.removeEventListener(r,m)},this._ready=!0,null===(e=this.onfeltefieldready)||void 0===e||e.call(this),this.dispatchEvent(new Event("feltefieldready"))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&this._createField()}))}disconnectedCallback(){var e;null===(e=this._destroy)||void 0===e||e.call(this)}}customElements.get("felte-field")||customElements.define("felte-field",Q);const Y=[],Z=()=>{};function ee(e,t=Z){let r;const n=new Set;function i(t){if(s=t,((i=e)!=i?s==s:i!==s||i&&"object"==typeof i||"function"==typeof i)&&(e=t,r)){const t=!Y.length;for(const t of n)t[1](),Y.push(t,e);if(t){for(let e=0;e<Y.length;e+=2)Y[e][0](Y[e+1]);Y.length=0}}var i,s}return{set:i,update:function(t){i(t(e))},subscribe:function(s,o=Z){const a=[s,o];return n.add(a),1===n.size&&(r=t(i)||Z),s(e),()=>{n.delete(a),r&&0===n.size&&(r(),r=null)}}}}function te(e){return function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFormElement. The element is not ready yet.`)}}const re=["data","errors","touched","warnings","isSubmitting","isDirty","isValid","isValidating","interacted"];class ne extends HTMLElement{constructor(){super(...arguments),this.id="",this._configuration={},this._storeValues={data:void 0,errors:void 0,touched:void 0,warnings:void 0,isSubmitting:!1,isDirty:!1,isValid:void 0,isValidating:!1,interacted:null},this.setData=te("setData"),this.setFields=te("setFields"),this.setInitialValues=te("setInitialValues"),this.addField=te("addField"),this.unsetField=te("unsetField"),this.swapFields=te("swapFields"),this.moveField=te("moveField"),this.resetField=te("resetField"),this.reset=te("reset"),this.submit=te("submit"),this.createSubmitHandler=te("createSubmitHandler"),this.setErrors=te("setErrors"),this.setTouched=te("setTouched"),this.setWarnings=te("setWarnings"),this.setIsSubmitting=te("setIsSubmitting"),this.setIsDirty=te("setIsDirty"),this.setInteracted=te("setInteracted"),this._ready=!1,this.validate=te("validate"),this._formElement=null,this._onChildChange=()=>{var e;const t=this.querySelector("form");t&&t!==this._formElement&&(this._formElement=t,null===(e=this._destroy)||void 0===e||e.call(this),this._createForm(this._configuration))}}setConfiguration(e){this._configuration=e,this._destroy&&(this._destroy(),this._destroy=void 0,this._ready=!1,this._createForm(e))}get data(){return this._storeValues.data}get errors(){return this._storeValues.errors}get touched(){return this._storeValues.touched}get warnings(){return this._storeValues.warnings}get isSubmitting(){return this._storeValues.isSubmitting}get isDirty(){return this._storeValues.isDirty}get isValid(){return this._storeValues.isValid}get isValidating(){return this._storeValues.isValidating}get interacted(){return this._storeValues.interacted}get ready(){return this._ready}_createForm(e){var t;const r=this._formElement;if(!r||this._destroy)return;this.elements=r.elements;const{form:n,cleanup:i,...s}=function(e,t){var r,n;function i(t,{debounced:r,level:n}={debounced:!1,level:"error"}){var i;const s="error"===n?"validate":"warn";null!==(i=e.debounced)&&void 0!==i||(e.debounced={});const o=r?e.debounced:e;o[s]?o[s]=[...o[s],t]:o[s]=[t]}function s(t){e.transform?e.transform=[...e.transform,t]:e.transform=[t]}null!==(r=e.extend)&&void 0!==r||(e.extend=[]),null!==(n=e.debounced)&&void 0!==n||(e.debounced={}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]),e.debounced.validate&&!Array.isArray(e.debounced.validate)&&(e.debounced.validate=[e.debounced.validate]),e.transform&&!Array.isArray(e.transform)&&(e.transform=[e.transform]),e.warn&&!Array.isArray(e.warn)&&(e.warn=[e.warn]),e.debounced.warn&&!Array.isArray(e.debounced.warn)&&(e.debounced.warn=[e.debounced.warn]);const o=Array.isArray(e.extend)?e.extend:[e.extend];let a=[];const{isSubmitting:u,isValidating:l,data:c,errors:d,warnings:f,touched:v,isValid:h,isDirty:m,cleanup:y,start:p,validateErrors:b,validateWarnings:g,interacted:E}=G(t.storeFactory,e),A=c.update,w=c.set;c.update=t=>A((r=>_(B(t(r),e.transform)))),c.set=t=>w(_(B(t,e.transform)));const S=C({extender:o,config:e,addValidator:i,addTransformer:s,validateErrors:b,validateWarnings:g,stores:{data:c,errors:d,warnings:f,touched:v,isValid:h,isValidating:l,isSubmitting:u,isDirty:m,interacted:E}});a=o.map((t=>t({stage:"SETUP",errors:d,warnings:f,touched:v,data:c,config:e,addValidator:i,addTransformer:s,setFields:S.public.setFields,reset:S.public.reset,validate:S.public.validate})));const O=Object.assign({config:e,stores:{data:c,touched:v,errors:d,warnings:f,isSubmitting:u,isValidating:l,isValid:h,isDirty:m,interacted:E},helpers:Object.assign(Object.assign({},S.public),{addTransformer:s,addValidator:i}),extender:o,validateErrors:b,validateWarnings:g,_getCurrentExtenders:()=>a,_setCurrentExtenders:e=>{a=e}},S.private),{form:F,createSubmitHandler:V,handleSubmit:T}=R(O);return Object.assign({data:c,errors:d,warnings:f,touched:v,isValid:h,isSubmitting:u,isValidating:l,isDirty:m,interacted:E,form:F,handleSubmit:T,createSubmitHandler:V,cleanup:y,startStores:p},S.public)}(e,{storeFactory:ee});this.setData=s.setData,this.setFields=s.setFields,this.setErrors=s.setErrors,this.setTouched=s.setTouched,this.setWarnings=s.setWarnings,this.setIsSubmitting=s.setIsSubmitting,this.setIsDirty=s.setIsDirty,this.setInteracted=s.setInteracted,this.setInitialValues=s.setInitialValues,this.validate=s.validate,this.addField=s.addField,this.unsetField=s.unsetField,this.swapFields=s.swapFields,this.moveField=s.moveField,this.resetField=s.resetField,this.reset=s.reset,this.submit=s.handleSubmit,this.createSubmitHandler=s.createSubmitHandler;const o=re.map((e=>s[e].subscribe((t=>{if(J(t,this._storeValues[e]))return;this._storeValues[e]=t;const r=e.toLowerCase(),n=this[`on${r}change`];"function"==typeof n&&n(t),this.dispatchEvent(new Event(`${r}change`))})))),{destroy:a}=n(r),{createSubmitEvent:u,createErrorEvent:l,createSuccessEvent:c}=D(),d=e=>{const t=e,r=u();this.dispatchEvent(r),r.defaultPrevented&&t.preventDefault(),t.onSubmit=r.onSubmit,t.onSuccess=r.onSuccess,t.onError=r.onError},f=e=>{const t=c(e.detail);this.dispatchEvent(t)},v=e=>{const t=e,r=l(t.detail);this.dispatchEvent(r),t.errors=r.errors,r.defaultPrevented&&t.preventDefault()};r.addEventListener("feltesubmit",d),r.addEventListener("feltesuccess",f),r.addEventListener("felteerror",v),this._destroy=()=>{a(),i(),r.removeEventListener("feltesubmit",d),r.removeEventListener("feltesuccess",f),r.removeEventListener("felteerror",v),o.forEach((e=>e()))},this._ready=!0,null===(t=this.onfelteready)||void 0===t||t.call(this),this.dispatchEvent(new Event("felteready",{bubbles:!0,composed:!0}))}connectedCallback(){setTimeout((()=>{this.isConnected&&!this._destroy&&(this.dispatchEvent(new Event("felteconnect",{bubbles:!0,composed:!0})),this._onChildChange(),this._observer=new MutationObserver(this._onChildChange),this._observer.observe(this,{childList:!0}))}))}disconnectedCallback(){var e,t;null===(e=this._destroy)||void 0===e||e.call(this),null===(t=this._observer)||void 0===t||t.disconnect()}static get observedAttributes(){return["id"]}attributeChangedCallback(e,t,r){if(t!==r)switch(e){case"id":this.id=r}}}function ie(e,t){return document.addEventListener("felteconnect",(function r(n){const i=n.composedPath()[0];i.id===e&&(i.setConfiguration(t),document.removeEventListener("felteconnect",r))})),new Promise((t=>{document.addEventListener("felteready",(function r(n){const i=n.composedPath()[0];i.id===e&&(t(i),document.removeEventListener("felteready",r))}))}))}customElements.get("felte-form")||customElements.define("felte-form",ne);export{Q as FelteField,ne as FelteForm,t as FelteSubmitError,ie as prepareForm};
//# sourceMappingURL=index.min.js.map
{
"name": "@felte/element",
"version": "0.2.5",
"version": "0.2.6",
"description": "An extensible form library that can be used as a custom element",

@@ -29,3 +29,3 @@ "main": "dist/index.js",

"dependencies": {
"@felte/core": "1.2.1"
"@felte/core": "1.2.2"
},

@@ -32,0 +32,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc