@felte/element
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -112,2 +112,3 @@ /** | ||
let control; | ||
let onReset; | ||
if (typeof nameOrConfig === 'string') { | ||
@@ -117,2 +118,3 @@ name = nameOrConfig; | ||
touchOnChange = (_a = config === null || config === void 0 ? void 0 : config.touchOnChange) !== null && _a !== void 0 ? _a : false; | ||
onReset = config === null || config === void 0 ? void 0 : config.onReset; | ||
} | ||
@@ -123,2 +125,3 @@ else { | ||
touchOnChange = (_b = nameOrConfig.touchOnChange) !== null && _b !== void 0 ? _b : false; | ||
onReset = nameOrConfig === null || nameOrConfig === void 0 ? void 0 : nameOrConfig.onReset; | ||
} | ||
@@ -149,5 +152,12 @@ function dispatchEvent(eventType, value) { | ||
} | ||
function handleReset(e) { | ||
if (!onReset) | ||
return; | ||
setControlValue(control, defaultValue); | ||
onReset(e); | ||
} | ||
function field(node) { | ||
fieldNode = node; | ||
let observer; | ||
let formElement; | ||
if (isFormControl(node)) { | ||
@@ -178,2 +188,4 @@ control = node; | ||
observer.observe(control, observerConfig); | ||
formElement = control.closest('form'); | ||
formElement === null || formElement === void 0 ? void 0 : formElement.addEventListener('reset', handleReset); | ||
}); | ||
@@ -183,2 +195,3 @@ return { | ||
observer === null || observer === void 0 ? void 0 : observer.disconnect(); | ||
formElement === null || formElement === void 0 ? void 0 : formElement.removeEventListener('reset', handleReset); | ||
}, | ||
@@ -214,2 +227,3 @@ }; | ||
this.blurEvent = 'focusout'; | ||
this.composed = false; | ||
this._onBlur = failFor('blur'); | ||
@@ -225,2 +239,3 @@ this._ready = false; | ||
'blurevent', | ||
'composed', | ||
'value', | ||
@@ -255,2 +270,6 @@ ]; | ||
}, | ||
composed: { | ||
converter: (value) => value === '' || (!!value && value !== 'false'), | ||
name: 'composed', | ||
}, | ||
}; | ||
@@ -280,3 +299,3 @@ } | ||
var _a; | ||
const { name, inputEvent, blurEvent, touchOnChange, value: defaultValue, } = this; | ||
const { name, inputEvent, blurEvent, touchOnChange, value: defaultValue, composed, } = this; | ||
if (!name) | ||
@@ -287,3 +306,2 @@ throw new Error('<felte-field> must have a "name" attribute'); | ||
return; | ||
this._fieldElement = element; | ||
element[this.valueProp] = defaultValue; | ||
@@ -293,2 +311,6 @@ const { field, onInput, onBlur } = createField(name, { | ||
defaultValue, | ||
onReset: () => { | ||
this.value = defaultValue; | ||
element[this.valueProp] = defaultValue; | ||
}, | ||
}); | ||
@@ -299,3 +321,3 @@ this._onInput = onInput; | ||
const handleInput = (e) => { | ||
const target = e.target; | ||
const target = composed ? e.composedPath()[0] : e.target; | ||
this.value = target[this.valueProp]; | ||
@@ -302,0 +324,0 @@ }; |
@@ -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 a;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!==(a=l[0])&&void 0!==a?a:"");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 a(e,t){var a,l;let o,u,s,c,d;function v(e,t){if(!d)return;i(d,t);const n=new Event(e,{bubbles:!0,cancelable:!0});d.dispatchEvent(n)}function h(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 f(e){v(s?"change":"input",e)}return"string"==typeof e?(o=e,u=null==t?void 0:t.defaultValue,s=null!==(a=null==t?void 0:t.touchOnChange)&&void 0!==a&&a):(o=e.name,u=e.defaultValue,s=null!==(l=e.touchOnChange)&&void 0!==l&&l),{field:function(e){let t;return c=e,n(e)?(d=e,d.name=o,{}):(setTimeout((()=>{const a=c.parentNode;if(!a||a.nodeType!==Node.ELEMENT_NODE)return;const l=a.querySelector(`[name="${o}"]`);if(l&&n(l))d=l;else{const t=document.createElement("input");t.type="hidden",t.name=o,a.insertBefore(t,e.nextSibling),d=t}i(d,u),t=new MutationObserver(h),t.observe(d,r)})),{destroy(){null==t||t.disconnect()}})},onInput:f,onChange:f,onBlur:function(){v("focusout")}}}class l extends HTMLElement{constructor(){var e;super(...arguments),this.touchOnChange=!1,this.valueProp="value",this.inputEvent="input",this.blurEvent="focusout",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","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"}}}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}=this;if(!t)throw new Error('<felte-field> must have a "name" attribute');const o=this.children.item(0);if(!o)return;this._fieldElement=o,o[this.valueProp]=l;const{field:u,onInput:s,onBlur:c}=a(t,{touchOnChange:r,defaultValue:l});this._onInput=s,this._onBlur=c;const{destroy:d}=u(o),v=e=>{const t=e.target;this.value=t[this.valueProp]},h=()=>{c()};o.addEventListener(n,v),o.addEventListener(i,h),this._destroy=()=>{null==d||d(),o.removeEventListener(n,v),o.removeEventListener(n,h)},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,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.onReset):(a=e.name,u=e.defaultValue,s=null!==(l=e.touchOnChange)&&void 0!==l&&l,v=null==e?void 0:e.onReset),{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,onReset:()=>{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 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 n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}(e,(e=>t=e))(),t}class t extends Error{constructor(e,t){super(e),this.name="FelteSubmitError",this.response=t}}function n(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function r(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 n(e)||function(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}(e)||r(e)}function a(e){return e.nodeType===Node.ELEMENT_NODE}function o(e,t,n){const r=n=>String.prototype.split.call(t,n).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),i=r(/[,[\]]+?/)||r(/[,[\].]+?/);return void 0===i||i===e?n:i}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){return Object.keys(e||{}).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:u(e[n])?l(e[n]):Array.isArray(e[n])?[...e[n]]:e[n]})),{})}function c(e,t,n){e&&(e=l(e)),u(e)||(e={});const r=Array.isArray(t)?t:t.match(/[^.[\]]+/g)||[],i=r[r.length-1];if(!i)return e;let s=e;for(let e=0;e<r.length-1;e++){const t=r[e];if(!s[t]||!u(s[t])&&!Array.isArray(s[t])){const n=r[e+1];isNaN(Number(n))?s[t]={}:s[t]=[]}s=s[t]}return s[i]=n(s[i]),e}function d(e,t,n){return c(e,t,(()=>n))}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 n of e.children){if(s(n)&&t.add(n),i(n))for(const e of n.elements)s(e)&&t.add(e);n.childElementCount>0&&v(n).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(n(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(r(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(n(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(r(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 n of e.elements){if(i(n)&&h(n),!s(n)||!n.name)continue;p(n,o(t,f(n)))}}const g={attributes:!0,attributeFilter:["data-felte-validation-message","aria-invalid"]}; | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
function A(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}function E(e,t){return Object.keys(e).reduce(((r,n)=>Object.assign(Object.assign({},r),{[n]:t(e[n])})),{})}function w(e,t){return E(e,(e=>u(e)?w(e,t):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?t:e.map((e=>A(w(e,t),["key"]))):t))}function S(e=8){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let r="";for(let n=0;n<e;n++)r+=t.charAt(Math.floor(Math.random()*t.length));return r}function _(e){return e?E(e,(e=>u(e)?_(e):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?e:e.map((e=>{if(!u(e))return e;const t=_(e);return t.key||(t.key=S()),t})):e)):{}}function O(e){return e?E(e,(e=>u(e)?_(e):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?e:e.map((e=>{if(!u(e))return e;return A(_(e),["key"])})):e)):{}} | ||
function E(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}function A(e,t){return Object.keys(e).reduce(((n,r)=>Object.assign(Object.assign({},n),{[r]:t(e[r])})),{})}function w(e,t){return A(e,(e=>u(e)?w(e,t):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?t:e.map((e=>E(w(e,t),["key"]))):t))}function S(e=8){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let r=0;r<e;r++)n+=t.charAt(Math.floor(Math.random()*t.length));return n}function _(e){return e?A(e,(e=>u(e)?_(e):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?e:e.map((e=>{if(!u(e))return e;const t=_(e);return t.key||(t.key=S()),t})):e)):{}}function O(e){return e?A(e,(e=>u(e)?_(e):Array.isArray(e)?0===e.length||e.every((e=>"string"==typeof e))?e:e.map((e=>{if(!u(e))return e;return E(_(e),["key"])})):e)):{}} | ||
/*! ***************************************************************************** | ||
@@ -31,3 +31,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}(F(t,e),["key"])}return e}}function F(e,t){return E(e,(e=>u(e)?F(e,t):Array.isArray(e)?e.map(V(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 C(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 L({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:A}=t,E=C(v.update),O=C(h.update),V=C(m.update),j=C(y.update);function L(e){E((t=>{const r=e(t);return a&&b(a,r),r}))}const D=(e,t,r)=>{C(L)(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=C(g.update),P=C(p.update),N=C(A.update);return{public:{setData:E,setFields:D,setTouched:O,setErrors:V,setWarnings:j,setIsSubmitting:x,setIsDirty:P,setInteracted:N,validate:async function(){const t=e(v);h.set(w(t,!0)),A.set(null);const r=await n(t);return await i(t),r},reset:function(){D(l(f)),O((e=>F(e,!1))),A.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)?F(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)?F(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=F(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:E,_getFormNode:S,_getInitialValues:_,_setCurrentExtenders:V,_getCurrentExtenders:k}){const{setFields:j,setTouched:C,reset:L,setInitialValues:I}=i,{addValidator:M,addTransformer:W,validate:B,setIsDirty:$,setIsSubmitting:q}=i,R=A(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 A=null!==(a=null!==(i=p.onError)&&void 0!==i?i:null==r?void 0:r.onError)&&void 0!==a?a:h.onError,E=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 V=O(e(U)),T=await b(V,null==r?void 0:r.validate),j=await g(V,null==r?void 0:r.warn);if(j&&z.set(x(F(V,[]),j)),X.set(w(V,!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:V,errors:T})})),void G.set(!1)}const C=Object.assign(Object.assign({},R),{form:f,controls:f&&Array.from(f.elements).filter(s),config:Object.assign(Object.assign({},h),r)});try{const e=await _(V,C);null==f||f.dispatchEvent(y(Object.assign({response:e},C))),await(null==E?void 0:E(e,C))}catch(t){const r=v(Object.assign({error:t},C));if(null==f||f.dispatchEvent(r),!A&&!r.defaultPrevented)throw t;if(!A&&!r.errors)return;const n=r.errors||await(null==A?void 0:A(t,C));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:V,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:B,reset:L})}}t.requestSubmit||(t.requestSubmit=Z),V(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 A(e){const i=e.target;if(i&&s(i)&&!N(i)&&i.name)if(C(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&&(C(f(t),!0),Q.set(t.name))}function S(e){e.preventDefault(),L()}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)))}}E(t),I(x(l(c),_())),j(_()),X.set(b);const F=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)})),V(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)})),V(p.map(i("UPDATE"))),O(t))}}}));F.observe(t,{childList:!0,subtree:!0}),t.addEventListener("input",g),t.addEventListener("change",A),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(){F.disconnect(),t.removeEventListener("input",g),t.removeEventListener("change",A),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 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 R(e,t){if(u(e))return!t||u(t)&&0===Object.keys(t).length?F(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?F(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,R)}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?_(B(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:F(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=q([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(f,[]);const A=e(d),E=F(f,[]),S=e(E),V=e(l(E)),[T,k,j]=c([S,V],q,l(E)),C=F(f,[]),L=e(C),D=e(l(C)),[I,x,N]=c([L,D],q,l(C)),[M,H,W]=c([T,v],K,l(E)),[$,R,U]=c([I,v],z,l(C));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(L),ie=b(V),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=E,le=C;function ce(){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=F(e,[])})),n=T.subscribe((e=>{ue=e})),i=I.subscribe((e=>{le=e}));return k(),Q(),x(),H(),R(),y(),function(){e(),W(),j(),N(),U(),Y(),p(),r(),n(),i()}}function de(e){S.set(e(ue)),V.set({})}function fe(e){L.set(e(le)),D.set({})}return M.set=function(e){de((()=>e))},M.update=de,$.set=function(e){fe((()=>e))},$.update=fe,{data:A,errors:M,warnings:$,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 q(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 q(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._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","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"}}}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}=this;if(!t)throw new Error('<felte-field> must have a "name" attribute');const u=this.children.item(0);if(!u)return;this._fieldElement=u,u[this.valueProp]=o;const{field:l,onInput:c,onBlur:d}=function(e,t){var r,n;let i,o,u,l,c;function d(e,t){if(!c)return;p(c,t);const r=new Event(e,{bubbles:!0,cancelable:!0});c.dispatchEvent(r)}function f(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 v(e){d(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):(i=e.name,o=e.defaultValue,u=null!==(n=e.touchOnChange)&&void 0!==n&&n),{field:function(e){let t;return l=e,s(e)?(c=e,c.name=i,{}):(setTimeout((()=>{const r=l.parentNode;if(!r||!a(r))return;const n=r.querySelector(`[name="${i}"]`);if(n&&s(n))c=n;else{const t=document.createElement("input");t.type="hidden",t.name=i,r.insertBefore(t,e.nextSibling),c=t}p(c,o),t=new MutationObserver(f),t.observe(c,g)})),{destroy(){null==t||t.disconnect()}})},onInput:v,onChange:v,onBlur:function(){d("focusout")}}}(t,{touchOnChange:i,defaultValue:o});this._onInput=c,this._onBlur=d;const{destroy:f}=l(u),v=e=>{const t=e.target;this.value=t[this.valueProp]},h=()=>{d()};u.addEventListener(r,v),u.addEventListener(n,h),this._destroy=()=>{null==f||f(),u.removeEventListener(r,v),u.removeEventListener(r,h)},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:A}=G(t.storeFactory,e),E=c.update,w=c.set;c.update=t=>E((r=>_(B(t(r),e.transform)))),c.set=t=>w(_(B(t,e.transform)));const S=L({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:A}});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:A},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:V,createSubmitHandler:F,handleSubmit:T}=W(O);return Object.assign({data:c,errors:d,warnings:f,touched:v,isValid:h,isSubmitting:u,isValidating:l,isDirty:m,interacted:A,form:V,handleSubmit:T,createSubmitHandler:F,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 V(e){return function(t){if(u(t)){return function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(F(t,e),["key"])}return e}}function F(e,t){return A(e,(e=>u(e)?F(e,t):Array.isArray(e)?e.map(V(t)):t))}function T(e,t){if(!e||Object(e)!==e)return;void 0!==e&&(e=l(e));const n=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[],r=1===n.length?e:o(e,n.slice(0,-1).join("."));return Array.isArray(r)?r.splice(Number(n[n.length-1]),1):null==r||delete r[n[n.length-1]],e}function k(e,t,n,r){return c(e,t,(e=>void 0===e||Array.isArray(e)?(e||(e=[]),void 0===r?e.push(n):e.splice(r,0,n),e):e))}function j(e){return"function"==typeof e}function L(e){return(t,n)=>{if("string"==typeof t){const r=t;e((e=>{const t=j(n)?n(o(e,r)):n;return d(e,r,t)}))}else e((e=>j(t)?t(e):t))}}function C({stores:t,config:n,validateErrors:r,validateWarnings:i}){var s;let a,f=_(null!==(s=n.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),V=L(m.update),j=L(y.update);function C(e){A((t=>{const n=e(t);return a&&b(a,n),n}))}const D=(e,t,n)=>{L(C)(e,t),"string"==typeof e&&n&&O(e,!0)};function I(e){m.update(e),y.update(e),h.update(e),v.update((t=>{const n=e(t);return setTimeout((()=>a&&b(a,n))),n}))}const x=L(g.update),P=L(p.update),N=L(E.update);return{public:{setData:A,setFields:D,setTouched:O,setErrors:V,setWarnings:j,setIsSubmitting:x,setIsDirty:P,setInteracted:N,validate:async function(){const t=e(v);h.set(w(t,!0)),E.set(null);const n=await r(t);return await i(t),n},reset:function(){D(l(f)),O((e=>F(e,!1))),E.set(null),p.set(!1)},unsetField:function(e){I((t=>T(t,e)))},resetField:function(e){const t=o(f,e),n=!!u(t)&&w(t,!1),r=u(n)?F(n,[]):[];v.update((n=>{const r=d(n,e,t);return a&&b(a,r),r})),h.update((t=>d(t,e,n))),m.update((t=>d(t,e,r))),y.update((t=>d(t,e,r)))},addField:function(e,t,n){const r=!!u(t)&&w(t,!1),i=u(r)?F(r,[]):[];t=u(t)?Object.assign(Object.assign({},t),{key:S()}):t,m.update((t=>k(t,e,i,n))),y.update((t=>k(t,e,i,n))),h.update((t=>k(t,e,r,n))),v.update((r=>{const i=k(r,e,t,n);return setTimeout((()=>a&&b(a,i))),i}))},swapFields:function(e,t,n){I((r=>function(e,t,n,r){return c(e,t,(e=>e&&Array.isArray(e)?([e[n],e[r]]=[e[r],e[n]],e):e))}(r,e,t,n)))},moveField:function(e,t,n){I((r=>function(e,t,n,r){return c(e,t,(e=>e&&Array.isArray(e)?(e.splice(r,0,e.splice(n,1)[0]),e):e))}(r,e,t,n)))},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 n 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 n,createSuccessEvent:t=>new e(t)}}function I(...e){const t=e.pop(),n=l(e.shift());if(0===e.length)return n;for(const r of e){if(!r)continue;let e=t(n,r);if(void 0!==e)return e;const i=Array.from(new Set(Object.keys(n).concat(Object.keys(r))));for(const s of i)if(e=t(n[s],r[s]),void 0!==e)n[s]=e;else if(u(r[s])&&u(n[s]))n[s]=I(n[s],r[s],t);else if(Array.isArray(r[s]))n[s]=r[s].map(((e,r)=>{if(!u(e))return e;return I(Array.isArray(n[s])?n[s][r]:n[s],e,t)}));else if(u(r[s])){const e=F(l(r[s]),void 0);n[s]=I(e,r[s],t)}else void 0!==r[s]&&(n[s]=r[s])}return n}function x(...e){return I(...e,(()=>{}))}function P(e,t){return function(e,t){return Object.keys(e).some((n=>t(e[n])))}(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 n=Array.isArray(e)?e:[];return t.map(((e,t)=>{var r;return null!==(r=n[t])&&void 0!==r?r: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:V,_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(n){return async function(r){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==n?void 0:n.onError)&&void 0!==a?a:h.onError,A=null!==(u=null!==(o=p.onSuccess)&&void 0!==o?o:null==n?void 0:n.onSuccess)&&void 0!==u?u:h.onSuccess,_=null!==(d=null!==(c=null!==(l=p.onSubmit)&&void 0!==l?l:null==n?void 0:n.onSubmit)&&void 0!==c?c:h.onSubmit)&&void 0!==d?d:function(e){if(e)return async function(){let n=new FormData(e);const r=new URL(e.action),i="get"===e.method.toLowerCase()?"get":r.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||(n=new URLSearchParams(n)),"get"===i?(n.forEach(((e,t)=>{r.searchParams.append(t,e)})),s={method:i}):s={method:i,body:n,headers:{"Content-Type":a}};const o=await window.fetch(r.toString(),s);if(o.ok)return o;throw new t("An error occurred while submitting the form",o)}}(f);if(!_)return;if(null==r||r.preventDefault(),p.defaultPrevented)return;G.set(!0),Q.set(null);const V=O(e(U)),T=await b(V,null==n?void 0:n.validate),j=await g(V,null==n?void 0:n.warn);if(j&&z.set(x(F(V,[]),j)),X.set(w(V,!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:V,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),n)});try{const e=await _(V,L);null==f||f.dispatchEvent(y(Object.assign({response:e},L))),await(null==A?void 0:A(e,L))}catch(t){const n=v(Object.assign({error:t},L));if(null==f||f.dispatchEvent(n),!E&&!n.defaultPrevented)throw t;if(!E&&!n.errors)return;const r=n.errors||await(null==E?void 0:E(t,L));r&&(X.set(w(r,!0)),K.set(r),await new Promise((e=>setTimeout(e))),k().forEach((t=>{var n;return null===(n=t.onSubmitError)||void 0===n?void 0:n.call(t,{data:V,errors:e(K)})})))}finally{G.set(!1)}}}const Z=Y();return{form:function(t){function i(e){return function(n){return n({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),V(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)||r(t)||N(t))return;if(["checkbox","radio","file"].includes(t.type))return;if(!t.name)return;J.set(!0);const n=m(t);Q.set(t.name),U.update((e=>d(e,f(t),n)))}function E(e){const i=e.target;if(i&&s(i)&&!N(i)&&i.name)if(L(f(i),!0),Q.set(i.name),(r(i)||["checkbox","radio","file","hidden"].includes(i.type))&&J.set(!0),"hidden"===i.type&&U.update((e=>d(e,f(i),i.value))),r(i))!function(e){if(e.multiple){const t=Array.from(e.options).filter((e=>e.selected)).map((e=>e.value));U.update((n=>d(n,f(e),t)))}else U.update((t=>d(t,f(e),e.value)))}(i);else{if(!n(i))return;"checkbox"===i.type?function(e){const r=f(e),i=Array.from(t.querySelectorAll(`[name="${e.name}"]`)).filter((e=>!!s(e)&&r===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(n).filter((e=>e.checked)).map((e=>e.value)))))}(i):"radio"===i.type?function(e){const r=t.querySelectorAll(`[name="${e.name}"]`),i=Array.from(r).find((e=>n(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 n=Array.from(null!==(t=e.files)&&void 0!==t?t:[]);U.update((t=>d(t,f(e),e.multiple?n:n[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 n of t.reverse()){if(n.hasAttribute("data-felte-keep-on-remove")&&"false"!==n.dataset.felteKeepOnRemove)continue;const t=/.*(\[[0-9]+\]|\.[0-9]+)\.[^.]+$/;let r=f(n);const i=e(X);if(t.test(r)){const e=r.split(".").slice(0,-1).join("."),t=o(i,e);u(t)&&Object.keys(t).length<=1&&(r=e)}U.update((e=>T(e,r))),X.update((e=>T(e,r))),K.update((e=>T(e,r))),z.update((e=>T(e,r)))}}A(t),I(x(l(c),_())),j(_()),X.set(b);const F=new MutationObserver((function(e){for(const n of e)if("childList"===n.type){if(n.addedNodes.length>0){if(!Array.from(n.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)})),V(p.map(i("UPDATE")));const{defaultData:e,defaultTouched:r}=y(t);U.update((t=>H(t,e))),X.update((e=>H(e,r)))}if(n.removedNodes.length>0)for(const e of n.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)})),V(p.map(i("UPDATE"))),O(t))}}}));F.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 n of t.elements){if(!s(n)||!n.name)continue;const t=o(e,f(n)),r=Array.isArray(t)?t.join("\n"):"string"==typeof t?t:void 0;r!==n.dataset.felteValidationMessage&&(r?(n.dataset.felteValidationMessage=r,n.setAttribute("aria-invalid","true")):(delete n.dataset.felteValidationMessage,n.removeAttribute("aria-invalid")))}}));return{destroy(){F.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 n=[],r=Math.max(t.length,e.length);for(let i=0;i<r;i++){let r=e[i],s=t[i];u(r)||u(s)?n.push($([null!=r?r:{},null!=s?s:{}])):(Array.isArray(r)||(r=[r]),Array.isArray(s)||(s=[s]),n.push(...r,...s))}return n.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?F(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const n=Array.isArray(t)?t:[];return e.map(((e,t)=>{const r=n[t];return Array.isArray(r)&&0===r.length?null:e&&r||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?F(e,null):void 0;if(Array.isArray(e)){if(e.some(u))return;const n=Array.isArray(t)?t:[];return e.map(((e,t)=>{const r=n[t];return Array.isArray(r)&&0===r.length?null:r||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 n;return(...r)=>{clearTimeout(n),n=setTimeout((()=>{e.apply(this,r)}),t)}}function G(e,t){var n,r,i,s,a,o,u;const c=function(e){return function(t,n,r){const i=Array.isArray(t)?t:[t],s=new Array(i.length),a=e(r),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(n(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(n,r,i,s=!1){if(!i||!n)return;let a=r&&Object.keys(r).length>0?r:F(n,[]);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=n,(c=i)?(Array.isArray(c)?c:[c]).map((e=>e(l))):[]);var l,c;return u.forEach((async t=>{const n=await t;o.signal.aborted||(a=$([a,n]),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(f,[]);const E=e(d),A=F(f,[]),S=e(A),V=e(l(A)),[T,k,j]=c([S,V],$,l(A)),L=F(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 n;return G?!P(e,(e=>Array.isArray(e)?e.length>=1:!!e)):(G=!0,!t.validate&&!(null===(n=t.debounced)||void 0===n?void 0:n.validate))}),!t.validate&&!(null===(n=t.debounced)||void 0===n?void 0:n.validate));delete J.set,delete J.update;const Z=e(!1),ee=e(!1),te=e(null),ne=b(S),re=b(C),ie=b(V),se=b(D),ae=X(ie,null!==(i=null===(r=t.debounced)||void 0===r?void 0:r.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 n,r;const i=O(e);ne(i,g,t.validate),re(i,g,t.warn),ae(i,g,null===(n=t.debounced)||void 0===n?void 0:n.validate),oe(i,g,null===(r=t.debounced)||void 0===r?void 0:r.warn)})),n=v.subscribe((e=>{g=F(e,[])})),r=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(),n(),r(),i()}}function de(e){S.set(e(ue)),V.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,n){var r;const i=O(e),s=ne(i,g,null!=n?n:t.validate,!0);if(n)return s;const a=ie(i,g,null===(r=t.debounced)||void 0===r?void 0:r.validate,!0);return $(await Promise.all([s,a]))},validateWarnings:async function(e,n){var r;const i=O(e),s=re(i,g,null!=n?n:t.warn,!0);if(n)return s;const a=se(i,g,null===(r=t.debounced)||void 0===r?void 0:r.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,n)=>J(e,t[n])));if(u(e)&&u(t)){const n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every((n=>J(e[n],t[n])))}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,n){if(t===n)return;const{converter:r,name:i}=Q.attributeMap[e];this[i]=r(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:r,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 n,r;let i,o,u,l,c,d;function f(e,t){if(!c)return;p(c,t);const n=new Event(e,{bubbles:!0,cancelable:!0});c.dispatchEvent(n)}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!==(n=null==t?void 0:t.touchOnChange)&&void 0!==n&&n,d=null==t?void 0:t.onReset):(i=e.name,o=e.defaultValue,u=null!==(r=e.touchOnChange)&&void 0!==r&&r,d=null==e?void 0:e.onReset),{field:function(e){let t,n;return l=e,s(e)?(c=e,c.name=i,{}):(setTimeout((()=>{const r=l.parentNode;if(!r||!a(r))return;const u=r.querySelector(`[name="${i}"]`);if(u&&s(u))c=u;else{const t=document.createElement("input");t.type="hidden",t.name=i,r.insertBefore(t,e.nextSibling),c=t}p(c,o),t=new MutationObserver(v),t.observe(c,g),n=c.closest("form"),null==n||n.addEventListener("reset",h)})),{destroy(){null==t||t.disconnect(),null==n||n.removeEventListener("reset",h)}})},onInput:m,onChange:m,onBlur:function(){f("focusout")}}}(t,{touchOnChange:i,defaultValue:o,onReset:()=>{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(n,h),l.addEventListener(r,m),this._destroy=()=>{null==v||v(),l.removeEventListener(n,h),l.removeEventListener(n,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 n;const r=new Set;function i(t){if(s=t,((i=e)!=i?s==s:i!==s||i&&"object"==typeof i||"function"==typeof i)&&(e=t,n)){const t=!Y.length;for(const t of r)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 r.add(o),1===r.size&&(n=t(i)||Z),s(e),()=>{r.delete(o),n&&0===r.size&&(n(),n=null)}}}}function te(e){return function(){throw new TypeError(`Can't call "${e}" on HTMLFelteFormElement. The element is not ready yet.`)}}const ne=["data","errors","touched","warnings","isSubmitting","isDirty","isValid","isValidating","interacted"];class re 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 n=this._formElement;if(!n||this._destroy)return;this.elements=n.elements;const{form:r,cleanup:i,...s}=function(e,t){var n,r;function i(t,{debounced:n,level:r}={debounced:!1,level:"error"}){var i;const s="error"===r?"validate":"warn";null!==(i=e.debounced)&&void 0!==i||(e.debounced={});const a=n?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!==(n=e.extend)&&void 0!==n||(e.extend=[]),null!==(r=e.debounced)&&void 0!==r||(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((n=>_(R(t(n),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:V,createSubmitHandler:F,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:V,handleSubmit:T,createSubmitHandler:F,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=ne.map((e=>s[e].subscribe((t=>{if(J(t,this._storeValues[e]))return;this._storeValues[e]=t;const n=e.toLowerCase(),r=this[`on${n}change`];"function"==typeof r&&r(t),this.dispatchEvent(new Event(`${n}change`))})))),{destroy:o}=r(n),{createSubmitEvent:u,createErrorEvent:l,createSuccessEvent:c}=D(),d=e=>{const t=e,n=u();this.dispatchEvent(n),n.defaultPrevented&&t.preventDefault(),t.onSubmit=n.onSubmit,t.onSuccess=n.onSuccess,t.onError=n.onError},f=e=>{const t=c(e.detail);this.dispatchEvent(t)},v=e=>{const t=e,n=l(t.detail);this.dispatchEvent(n),t.errors=n.errors,n.defaultPrevented&&t.preventDefault()};n.addEventListener("feltesubmit",d),n.addEventListener("feltesuccess",f),n.addEventListener("felteerror",v),this._destroy=()=>{o(),i(),n.removeEventListener("feltesubmit",d),n.removeEventListener("feltesuccess",f),n.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,n){if(t!==n)switch(e){case"id":this.id=n}}}function ie(e,t){return document.addEventListener("felteconnect",(function n(r){const i=r.composedPath()[0];i.id===e&&(i.setConfiguration(t),document.removeEventListener("felteconnect",n))})),new Promise((t=>{document.addEventListener("felteready",(function n(r){const i=r.composedPath()[0];i.id===e&&(t(i),document.removeEventListener("felteready",n))}))}))}customElements.get("felte-form")||customElements.define("felte-form",re);export{Q as FelteField,re as FelteForm,t as FelteSubmitError,ie as prepareForm}; | ||
//# sourceMappingURL=index.min.js.map |
@@ -15,2 +15,3 @@ import { FieldValue } from '@felte/core'; | ||
blurEvent: string; | ||
composed: boolean; | ||
private _value?; | ||
@@ -26,3 +27,2 @@ set value(newValue: Value); | ||
onfeltefieldready?(): void; | ||
private _fieldElement?; | ||
private _createField; | ||
@@ -29,0 +29,0 @@ connectedCallback(): void; |
@@ -15,2 +15,3 @@ import { FieldValue } from '@felte/core'; | ||
blurEvent: string; | ||
composed: boolean; | ||
private _value?; | ||
@@ -26,3 +27,2 @@ set value(newValue: Value); | ||
onfeltefieldready?(): void; | ||
private _fieldElement?; | ||
private _createField; | ||
@@ -29,0 +29,0 @@ connectedCallback(): void; |
@@ -15,2 +15,3 @@ import { FieldValue, Obj, FormConfig, Keyed, Errors, Touched, Helpers, Form, Paths, FieldsSetter, ObjectSetter } from "@felte/core"; | ||
blurEvent: string; | ||
composed: boolean; | ||
private _value?; | ||
@@ -26,3 +27,2 @@ set value(newValue: Value); | ||
onfeltefieldready?(): void; | ||
private _fieldElement?; | ||
private _createField; | ||
@@ -29,0 +29,0 @@ connectedCallback(): void; |
@@ -15,2 +15,3 @@ import { FieldValue, Obj, FormConfig, Keyed, Errors, Touched, Helpers, Form, Paths, FieldsSetter, ObjectSetter } from "@felte/core"; | ||
blurEvent: string; | ||
composed: boolean; | ||
private _value?; | ||
@@ -26,3 +27,2 @@ set value(newValue: Value); | ||
onfeltefieldready?(): void; | ||
private _fieldElement?; | ||
private _createField; | ||
@@ -29,0 +29,0 @@ connectedCallback(): void; |
{ | ||
"name": "@felte/element", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"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.1.1" | ||
"@felte/core": "1.2.0" | ||
}, | ||
@@ -48,3 +48,3 @@ "publishConfig": { | ||
}, | ||
"readme": "# Felte: A form library for vanilla JS (custom element)\n\n[![Tests](https://github.com/pablo-abc/felte/workflows/Tests/badge.svg)](https://github.com/pablo-abc/felte/actions/workflows/test.yml)\n[![Bundle size](https://img.shields.io/bundlephobia/min/@felte/element)](https://bundlephobia.com/result?p=@felte/element)\n[![NPM Version](https://img.shields.io/npm/v/@felte/element)](https://www.npmjs.com/package/@felte/element)\n[![NPM Downloads](https://img.shields.io/npm/dw/@felte/element)](https://www.npmjs.com/package/@felte/element)\n[![codecov](https://codecov.io/gh/pablo-abc/felte/branch/main/graph/badge.svg?token=T73OJZ50LC)](https://codecov.io/gh/pablo-abc/felte)\n\nFelte is an extensible form library originally bult for Svelte. This package aims to provide Felte's functionality using a custom element. Felte, on its most simple form, only requires you to provide a `<form>` element to it in order to work.\n\n> **WARNING**: This package is under development, things might break on updates and documentation is almost non-existent besides this README.\n\n## Features\n\n- Single action to make your form reactive.\n- Use HTML5 native elements to create your form. (Only the `name` attribute is necessary).\n- Provides stores and helper functions to handle more complex use cases.\n- No assumptions on your validation strategy. Use any validation library you want or write your own strategy.\n- Handles addition and removal of form controls during runtime.\n- Official solutions for error reporting using `reporter` packages.\n- Well tested. Currently at [99% code coverage](https://app.codecov.io/gh/pablo-abc/felte) and constantly working on improving test quality.\n- Supports validation with [yup](/packages/validator-yup/README.md), [zod](/packages/validator-zod/README.md) and [superstruct](/packages/validator-superstruct/README.md).\n- Easily [extend its functionality](https://felte.dev/docs/element/extending-felte).\n\n## Simple usage example\n\nUsing Svelte as an example:\n\n```html\n<script type=\"module\">\n import { prepareForm } from '@felte/element';\n\n prepareForm('signin', {\n onSubmit: async (values) => {\n /* call to an api */\n },\n });\n</script>\n\n<felte-form id=\"signin\">\n <form>\n <input type=\"text\" name=\"email\" />\n <input type=\"password\" name=\"password\" />\n <input type=\"submit\" value=\"Sign in\" />\n </form>\n</felte-form>\n```\n\n## Installation\n\n```sh\nnpm install --save @felte/element\n\n# Or if you use yarn\n\nyarn add @felte/element\n```\n\n## Usage\n\nTo learn more about how to use `felte` to handle your forms, check the [official documentation](https://felte.dev/docs/element/getting-started). **TODO**: Add documentation\n\n## Framework compatibility\n\nThis package should work nicely with any framework. Specially if you're using the `prepareForm` method of creating your form. It also works really nice with frameworks that set attributes as properties or frameworks that provide syntax to set values to properties of elements instead of attributes.\n" | ||
"readme": "# Felte: A form library for vanilla JS (custom element)\n\n[![Tests](https://github.com/pablo-abc/felte/workflows/Tests/badge.svg)](https://github.com/pablo-abc/felte/actions/workflows/test.yml)\n[![Bundle size](https://img.shields.io/bundlephobia/min/@felte/element)](https://bundlephobia.com/result?p=@felte/element)\n[![NPM Version](https://img.shields.io/npm/v/@felte/element)](https://www.npmjs.com/package/@felte/element)\n[![NPM Downloads](https://img.shields.io/npm/dw/@felte/element)](https://www.npmjs.com/package/@felte/element)\n[![codecov](https://codecov.io/gh/pablo-abc/felte/branch/main/graph/badge.svg?token=T73OJZ50LC)](https://codecov.io/gh/pablo-abc/felte)\n\nFelte is an extensible form library originally bult for Svelte. This package aims to provide Felte's functionality using a custom element. Felte, on its most simple form, only requires you to provide a `<form>` element to it in order to work.\n\n> **WARNING**: This package is under development, things might break on updates and documentation is almost non-existent besides this README.\n\n## Features\n\n- Single action to make your form reactive.\n- Use HTML5 native elements to create your form. (Only the `name` attribute is necessary).\n- Provides stores and helper functions to handle more complex use cases.\n- No assumptions on your validation strategy. Use any validation library you want or write your own strategy.\n- Handles addition and removal of form controls during runtime.\n- Official solutions for error reporting using `reporter` packages.\n- Well tested. Currently at [99% code coverage](https://app.codecov.io/gh/pablo-abc/felte) and constantly working on improving test quality.\n- Supports validation with [yup](/packages/validator-yup/README.md), [zod](/packages/validator-zod/README.md) and [superstruct](/packages/validator-superstruct/README.md).\n- Easily [extend its functionality](https://felte.dev/docs/element/extending-felte).\n\n## Simple usage example\n\nUsing Svelte as an example:\n\n```html\n<script type=\"module\">\n import { prepareForm } from '@felte/element';\n\n // Needs to run _before_ `<felte-form>` connects.\n // Make sure to call it at the top leve of the module.\n prepareForm('signin', {\n onSubmit: async (values) => {\n /* call to an api */\n },\n });\n</script>\n\n<felte-form id=\"signin\">\n <form>\n <input type=\"text\" name=\"email\" />\n <input type=\"password\" name=\"password\" />\n <input type=\"submit\" value=\"Sign in\" />\n </form>\n</felte-form>\n```\n\n## Installation\n\n```sh\nnpm install --save @felte/element\n\n# Or if you use yarn\n\nyarn add @felte/element\n```\n\n## Usage\n\nTo learn more about how to use `felte` to handle your forms, check the [official documentation](https://felte.dev/docs/element/getting-started). **TODO**: Add documentation\n\n## Framework compatibility\n\nThis package should work nicely with any framework. Specially if you're using the `prepareForm` method of creating your form. It also works really nice with frameworks that set attributes as properties or frameworks that provide syntax to set values to properties of elements instead of attributes.\n" | ||
} |
@@ -33,2 +33,4 @@ # Felte: A form library for vanilla JS (custom element) | ||
// Needs to run _before_ `<felte-form>` connects. | ||
// Make sure to call it at the top leve of the module. | ||
prepareForm('signin', { | ||
@@ -35,0 +37,0 @@ onSubmit: async (values) => { |
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 not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
936492
5089
68
0
+ Added@felte/core@1.2.0(transitive)
- Removed@felte/core@1.1.1(transitive)
Updated@felte/core@1.2.0