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

@felte/core

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@felte/core - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

9

CHANGELOG.md
# @felte/core
## 0.2.1
### Patch Changes
- 096f9a5: Pass a `context` to `onSubmit` calls
- f79c67f: Listen to programmatic changes of inputs
- Updated dependencies [096f9a5]
- @felte/common@0.5.1
## 0.2.0

@@ -4,0 +13,0 @@

2

dist/index.js

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Core={})}(this,(function(e){"use strict";function t(e,t){return Object.keys(e).some((n=>t(e[n])))}function n(e,t){return Object.keys(e).reduce(((n,r)=>Object.assign(Object.assign({},n),{[r]:t(e[r])})),{})}function r(e){return"[object Object]"===Object.prototype.toString.call(e)}function o(e){return Object.keys(e||{}).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:r(e[n])?o(e[n]):Array.isArray(e[n])?[...e[n]]:e[n]})),{})}function i(e,t){return n(e,(e=>r(e)?i(e,t):Array.isArray(e)?e.map(function(e){return function(t){return r(t)?i(t,e):e}}(t)):t))}function a(...e){const t=e.pop(),n=o(e.shift());if(0===e.length)return n;for(const u of e){if(!u)continue;const e=Object.keys(u);for(const l of e){const e=t(n[l],u[l]);if(void 0!==e)n[l]=e;else if(r(u[l])&&r(n[l]))n[l]=a(n[l],u[l],t);else if(Array.isArray(u[l]))n[l]=u[l].map(((e,o)=>r(e)?a(Array.isArray(n[l])?n[l][o]:n[l],e,t):e));else if(r(u[l])){const e=i(o(u[l]),void 0);n[l]=a(e,u[l],t)}else void 0!==u[l]&&(n[l]=u[l])}}return n}function u(e,t){if(!r(e)||!r(t)){if(Array.isArray(t)){if(t.some(r))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 l(...e){return a(...e,u)}function d(...e){return a(...e,(()=>{}))}function s(e,t,n){const r=n=>String.prototype.split.call(t,n).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),o=r(/[,[\]]+?/)||r(/[,[\].]+?/);return void 0===o||o===e?n:o}function c(e,t,n){Object(e)!==e?e={}:void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n,e}function f(e,t){var n;if(Object(e)!==e)return;void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return null===(n=r.slice(0,-1).reduce(((e,t)=>Object(e[t])===e[t]?e[t]:void 0),e))||void 0===n||delete n[r[r.length-1]],e}function v(e,t,n){Object(e)!==e&&(e={});let r=t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n(s(e,t)),e}function m(e,n){return t(e,(e=>r(e)?m(e,n):n(e)))}function y(e){return e.hasAttribute("data-felte-index")?Number(e.dataset.felteIndex):void 0}function p(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function h(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function g(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function b(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function A(e){return p(e)||h(e)||g(e)}function E(e){return e.nodeType===Node.ELEMENT_NODE}function O(e,t){const n=y(e);let r="";t?r=t:A(e)&&(r=e.name),r=void 0===n?r:`${r}[${n}]`;let o=e.parentNode;if(!o)return r;for(;o&&"FORM"!==o.nodeName;){if(b(o)&&o.name){const e=y(o);r=`${void 0===e?o.name:`${o.name}[${e}]`}.${r}`}o=o.parentNode}return r}function S(e){const t=e.dataset.felteFieldset,n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;return t?`${t}.${r}`:r}function j(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function x(e){if(A(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const n of e.children){if(A(n)&&t.add(n),b(n))for(const e of n.elements)A(e)&&t.add(e);n.childElementCount>0&&x(n).forEach((e=>t.add(e)))}return Array.from(t)}function N(e){for(const t of e.elements)if(A(t)||b(t)){if(e.name&&t.name){const n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;t.dataset.felteFieldset=e.dataset.felteFieldset?`${e.dataset.felteFieldset}.${r}`:r}"true"!==e.dataset.felteUnsetOnRemove||t.hasAttribute("data-felte-unset-on-remove")||(t.dataset.felteUnsetOnRemove="true")}}function F(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function k(e){var t;let n={};for(const r of e.elements){if(b(r)&&N(r),!A(r)||!r.name)continue;const o=O(r),i=y(r);if(p(r)){if("checkbox"===r.type){if(void 0===s(n,o)){if(1===Array.from(e.querySelectorAll(`[name="${r.name}"]`)).filter((e=>!!A(e)&&(void 0!==i?Number(e.dataset.felteIndex)===i:o===O(e)))).length){n=c(n,o,r.checked);continue}n=c(n,o,r.checked?[r.value]:[]);continue}Array.isArray(s(n,o))&&r.checked&&v(n,o,(e=>(void 0===i||Array.isArray(e)||(e=[]),[...e,r.value])));continue}if("radio"===r.type){if(s(n,o))continue;n=c(n,o,r.checked?r.value:void 0);continue}if("file"===r.type){n=c(n,o,r.multiple?Array.from(r.files||[]):null===(t=r.files)||void 0===t?void 0:t[0]);continue}}const a=F(r);n=c(n,o,a)}return{defaultData:n}}function $(e,t){if(!A(e))return;const n=t;if(p(e)){if("checkbox"===e.type){const t=n;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=n;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}e.value=String(null!=n?n:"")}function V(e,t){for(const n of e.elements){if(b(n)&&N(n),!A(n)||!n.name)continue;$(n,s(t,O(n)))}}function T(e,t){if(!r(e)&&!r(t)){if(null===e)return t;if(null===t)return e;if(e&&t)return Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]),[...e,...t]}}async function _(e,t){if(!t)return;if(!Array.isArray(t))return t(e);return a(...await Promise.all(t.map((t=>t(e)))),T)}function L(){}function D(e){let t;return function(e,...t){if(null==e)return L;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}(e,(e=>t=e))(),t}function M({stores:e,config:t,currentExtenders:n,extender:r,addValidator:a}){var u;const{isSubmitting:v,data:h,touched:b,errors:N}=e;function T(e){var r,o,a;const u=null!==(r=null==e?void 0:e.onSubmit)&&void 0!==r?r:t.onSubmit,l=null!==(o=null==e?void 0:e.validate)&&void 0!==o?o:t.validate,d=null!==(a=null==e?void 0:e.onError)&&void 0!==a?a:t.onError;return async function(e){null==e||e.preventDefault(),v.set(!0);const t=D(h),r=await _(t,l);if(b.update((e=>i(e,!0))),r){N.set(r);if(m(r,(e=>!!e)))return n.forEach((e=>{var n;return null===(n=null==e?void 0:e.onSubmitError)||void 0===n?void 0:n.call(e,{data:t,errors:r})})),void v.set(!1)}try{await u(t)}catch(e){if(!d)throw e;const r=d(e);r&&(N.set(r),n.forEach((e=>{var n;return null===(n=null==e?void 0:e.onSubmitError)||void 0===n?void 0:n.call(e,{data:t,errors:r})})))}finally{v.set(!1)}}}function L(e,t){const n=void 0===t?e:`${e}[${t}]`;b.update((e=>c(e,n,!0)))}function M(e){h.set(o(e)),I&&V(I,e)}let I,w=null!==(u=t.initialValues)&&void 0!==u?u:{};const C=T();return{handleSubmit:C,createSubmitHandler:T,reset:function(){M(o(w)),b.update((e=>i(e,!1)))},setTouched:L,setError:function(e,t){N.update((n=>c(n,e,t)))},setField:function(e,t,n=!0){if(h.update((n=>c(n,e,t))),n&&L(e),I)for(const n of I.elements){if(!A(n)||!n.name)continue;const r=O(n);if(e===r)return void $(n,t)}},setFields:M,validate:async function(){const e=D(h);b.update((e=>i(e,!0)));const n=await _(e,t.validate);return N.set(n||{}),n},form:function(e){function u(n){return n({form:e,controls:Array.from(e.elements).filter(A),data:h,errors:N,touched:b,config:t,addValidator:a})}n=r.map(u),e.noValidate=!!t.validate;const{defaultData:v}=k(e);function m(t){const n=y(t),r=O(t),o=Array.from(e.querySelectorAll(`[name="${t.name}"]`)).filter((e=>{if(!A(e))return!1;if(void 0!==n){return Number(e.dataset.felteIndex)===n}return r===O(e)}));return 1===o.length?h.update((e=>c(e,O(t),t.checked))):h.update((e=>c(e,O(t),o.filter(p).filter((e=>e.checked)).map((e=>e.value)))))}function $(e){var n;const r=e.target;if(!r||!A(r)||g(r)||j(r))return;if(["checkbox","radio","file"].includes(r.type))return;if(!r.name)return;(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.input)&&L(O(r));const o=F(r);h.update((e=>c(e,O(r),o)))}function V(n){var r;const o=n.target;o&&A(o)&&!j(o)&&o.name&&((null===(r=t.touchTriggerEvents)||void 0===r?void 0:r.change)&&L(O(o)),g(o)&&h.update((e=>c(e,O(o),o.value))),p(o)&&("checkbox"===o.type&&m(o),"radio"===o.type&&function(t){const n=e.querySelectorAll(`[name="${t.name}"]`),r=Array.from(n).find((e=>p(e)&&e.checked));h.update((e=>c(e,O(t),null==r?void 0:r.value)))}(o),"file"===o.type&&function(e){const t=e.files;h.update((n=>c(n,O(e),e.multiple?Array.from(null!=t?t:[]):null==t?void 0:t[0])))}(o)))}function T(e){var n;const r=e.target;r&&A(r)&&!j(r)&&r.name&&(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.blur)&&L(O(r))}function _(e){for(const t of e)"true"===t.dataset.felteUnsetOnRemove&&h.update((e=>f(e,S(t))))}I=e,w=d(o(v),w),M(w),b.set(i(w,!1));const D=new MutationObserver((function(t){for(const o of t)if("childList"===o.type){if(o.addedNodes.length>0){if(!Array.from(o.addedNodes).some((e=>{if(!E(e))return!1;if(A(e))return!0;return x(e).length>0})))continue;n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(u);const{defaultData:t}=k(e),a=i(t,!1);h.update((e=>l(e,t))),b.update((e=>l(e,a)))}if(o.removedNodes.length>0)for(const e of o.removedNodes){if(!E(e))continue;const t=x(e);0!==t.length&&(n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(u),_(t))}}}));D.observe(e,{childList:!0,subtree:!0}),e.addEventListener("input",$),e.addEventListener("change",V),e.addEventListener("focusout",T),e.addEventListener("submit",C);const P=N.subscribe((t=>{for(const n of e.elements){if(!A(n)||!n.name)continue;const e=s(t,O(n)),r=Array.isArray(e)?e.join("\n"):"string"==typeof e?e:void 0;r!==n.dataset.felteValidationMessage&&(r?n.dataset.felteValidationMessage=r:delete n.dataset.felteValidationMessage)}}));return{destroy(){D.disconnect(),e.removeEventListener("input",$),e.removeEventListener("change",V),e.removeEventListener("focusout",T),e.removeEventListener("submit",C),P(),n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)}))}}}}}e._cloneDeep=o,e._defaultsDeep=l,e._get=s,e._isPlainObject=r,e._mapValues=n,e._merge=d,e._mergeWith=a,e._set=c,e._some=t,e._unset=f,e._update=v,e.addAttrsFromFieldset=N,e.createForm=function(e,t){var n,i;function u(t){e.validate?e.validate=[...e.validate,t]:e.validate=[t]}null!==(n=e.extend)&&void 0!==n||(e.extend=[]),null!==(i=e.touchTriggerEvents)&&void 0!==i||(e.touchTriggerEvents={change:!0,blur:!0}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]);const l=Array.isArray(e.extend)?e.extend:[e.extend];let d=[];const{isSubmitting:s,data:c,errors:f,touched:v,isValid:m}=t.stores;d=l.map((t=>t({errors:f,touched:v,data:c,config:e,addValidator:u})));const y=M({currentExtenders:d,extender:l,config:e,addValidator:u,stores:{data:c,errors:f,touched:v,isValid:m,isSubmitting:s}});function p(e,t){if(!r(e))return e!==t}function h(e,t){if(!r(e))return t||e}return Object.assign({data:Object.assign(Object.assign({},c),{set:function(t){return v.update((n=>{const r=a(o(t),e.initialValues,p);return a(r,n,h)})),c.set(t)}}),errors:f,touched:v,isValid:m,isSubmitting:s},y)},e.deepSet=i,e.deepSome=m,e.executeValidation=_,e.getFormControls=x,e.getFormDefaultValues=k,e.getIndex=y,e.getInputTextOrNumber=F,e.getPath=O,e.getPathFromDataset=S,e.isElement=E,e.isFieldSetElement=b,e.isFieldValue=function(e){return Array.isArray(e)?0===e.length||e.some((e=>e instanceof File||"string"==typeof e)):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||e instanceof File},e.isFormControl=A,e.isInputElement=p,e.isSelectElement=g,e.isTextAreaElement=h,e.setControlValue=$,e.setForm=V,e.shouldIgnore=j,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Core={})}(this,(function(e){"use strict";function t(e,t){return Object.keys(e).some((n=>t(e[n])))}function n(e,t){return Object.keys(e).reduce(((n,r)=>Object.assign(Object.assign({},n),{[r]:t(e[r])})),{})}function r(e){return"[object Object]"===Object.prototype.toString.call(e)}function o(e){return Object.keys(e||{}).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:r(e[n])?o(e[n]):Array.isArray(e[n])?[...e[n]]:e[n]})),{})}function i(e,t){return n(e,(e=>r(e)?i(e,t):Array.isArray(e)?e.map(function(e){return function(t){return r(t)?i(t,e):e}}(t)):t))}function a(...e){const t=e.pop(),n=o(e.shift());if(0===e.length)return n;for(const u of e){if(!u)continue;const e=Object.keys(u);for(const l of e){const e=t(n[l],u[l]);if(void 0!==e)n[l]=e;else if(r(u[l])&&r(n[l]))n[l]=a(n[l],u[l],t);else if(Array.isArray(u[l]))n[l]=u[l].map(((e,o)=>r(e)?a(Array.isArray(n[l])?n[l][o]:n[l],e,t):e));else if(r(u[l])){const e=i(o(u[l]),void 0);n[l]=a(e,u[l],t)}else void 0!==u[l]&&(n[l]=u[l])}}return n}function u(e,t){if(!r(e)||!r(t)){if(Array.isArray(t)){if(t.some(r))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 l(...e){return a(...e,u)}function c(...e){return a(...e,(()=>{}))}function s(e,t,n){const r=n=>String.prototype.split.call(t,n).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),o=r(/[,[\]]+?/)||r(/[,[\].]+?/);return void 0===o||o===e?n:o}function d(e,t,n){Object(e)!==e?e={}:void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n,e}function f(e,t){var n;if(Object(e)!==e)return;void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return null===(n=r.slice(0,-1).reduce(((e,t)=>Object(e[t])===e[t]?e[t]:void 0),e))||void 0===n||delete n[r[r.length-1]],e}function v(e,t,n){Object(e)!==e&&(e={});let r=t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n(s(e,t)),e}function m(e,n){return t(e,(e=>r(e)?m(e,n):n(e)))}function y(e){return e.hasAttribute("data-felte-index")?Number(e.dataset.felteIndex):void 0}function p(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function g(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function h(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function b(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function A(e){return p(e)||g(e)||h(e)}function E(e){return e.nodeType===Node.ELEMENT_NODE}function O(e,t){const n=y(e);let r="";t?r=t:A(e)&&(r=e.name),r=void 0===n?r:`${r}[${n}]`;let o=e.parentNode;if(!o)return r;for(;o&&"FORM"!==o.nodeName;){if(b(o)&&o.name){const e=y(o);r=`${void 0===e?o.name:`${o.name}[${e}]`}.${r}`}o=o.parentNode}return r}function j(e){const t=e.dataset.felteFieldset,n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;return t?`${t}.${r}`:r}function x(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function S(e){if(A(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const n of e.children){if(A(n)&&t.add(n),b(n))for(const e of n.elements)A(e)&&t.add(e);n.childElementCount>0&&S(n).forEach((e=>t.add(e)))}return Array.from(t)}function k(e){for(const t of e.elements)if(A(t)||b(t)){if(e.name&&t.name){const n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;t.dataset.felteFieldset=e.dataset.felteFieldset?`${e.dataset.felteFieldset}.${r}`:r}"true"!==e.dataset.felteUnsetOnRemove||t.hasAttribute("data-felte-unset-on-remove")||(t.dataset.felteUnsetOnRemove="true")}}function N(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function F(e){var t;let n={};for(const r of e.elements){if(b(r)&&k(r),!A(r)||!r.name)continue;const o=O(r),i=y(r);if(p(r)){if("checkbox"===r.type){if(void 0===s(n,o)){if(1===Array.from(e.querySelectorAll(`[name="${r.name}"]`)).filter((e=>!!A(e)&&(void 0!==i?Number(e.dataset.felteIndex)===i:o===O(e)))).length){n=d(n,o,r.checked);continue}n=d(n,o,r.checked?[r.value]:[]);continue}Array.isArray(s(n,o))&&r.checked&&v(n,o,(e=>(void 0===i||Array.isArray(e)||(e=[]),[...e,r.value])));continue}if("radio"===r.type){if(s(n,o))continue;n=d(n,o,r.checked?r.value:void 0);continue}if("file"===r.type){n=d(n,o,r.multiple?Array.from(r.files||[]):null===(t=r.files)||void 0===t?void 0:t[0]);continue}}const a=N(r);n=d(n,o,a)}return{defaultData:n}}function $(e,t){if(!A(e))return;const n=t;if(p(e)){if("checkbox"===e.type){const t=n;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=n;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}e.value=String(null!=n?n:"")}function T(e,t){for(const n of e.elements){if(b(n)&&k(n),!A(n)||!n.name)continue;$(n,s(t,O(n)))}}function V(e,t){if(!r(e)&&!r(t)){if(null===e)return t;if(null===t)return e;if(e&&t)return Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]),[...e,...t]}}async function L(e,t){if(!t)return;if(!Array.isArray(t))return t(e);return a(...await Promise.all(t.map((t=>t(e)))),V)}function _(){}function D(e){let t;return function(e,...t){if(null==e)return _;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}(e,(e=>t=e))(),t}e._cloneDeep=o,e._defaultsDeep=l,e._get=s,e._isPlainObject=r,e._mapValues=n,e._merge=c,e._mergeWith=a,e._set=d,e._some=t,e._unset=f,e._update=v,e.addAttrsFromFieldset=k,e.createForm=function(e,t){var n,u;function v(t){e.validate?e.validate=[...e.validate,t]:e.validate=[t]}null!==(n=e.extend)&&void 0!==n||(e.extend=[]),null!==(u=e.touchTriggerEvents)&&void 0!==u||(e.touchTriggerEvents={change:!0,blur:!0}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]);const g=Array.isArray(e.extend)?e.extend:[e.extend];let b=[];const{isSubmitting:k,data:V,errors:_,touched:M,isValid:I}=t.stores;b=g.map((t=>t({errors:_,touched:M,data:V,config:e,addValidator:v})));const w=function({stores:e,config:t,currentExtenders:n,extender:r,addValidator:a}){var u;const{isSubmitting:v,data:g,touched:b,errors:k}=e;function V(e){var r,o,a;const u=null!==(r=null==e?void 0:e.onSubmit)&&void 0!==r?r:t.onSubmit,l=null!==(o=null==e?void 0:e.validate)&&void 0!==o?o:t.validate,c=null!==(a=null==e?void 0:e.onError)&&void 0!==a?a:t.onError;return async function(r){null==r||r.preventDefault(),v.set(!0);const o=D(g),a=await L(o,l);if(b.update((e=>i(e,!0))),a&&(k.set(a),m(a,(e=>!!e))))return n.forEach((e=>{var t;return null===(t=null==e?void 0:e.onSubmitError)||void 0===t?void 0:t.call(e,{data:o,errors:a})})),void v.set(!1);try{await u(o,{form:I,controls:I&&Array.from(I.elements).filter(A),config:Object.assign(Object.assign({},t),e)})}catch(e){if(!c)throw e;const t=c(e);t&&(k.set(t),n.forEach((e=>{var n;return null===(n=null==e?void 0:e.onSubmitError)||void 0===n?void 0:n.call(e,{data:o,errors:t})})))}finally{v.set(!1)}}}function _(e,t){const n=void 0===t?e:`${e}[${t}]`;b.update((e=>d(e,n,!0)))}function M(e){g.set(o(e)),I&&T(I,e)}let I,w=null!==(u=t.initialValues)&&void 0!==u?u:{};const P=V();return{handleSubmit:P,createSubmitHandler:V,reset:function(){M(o(w)),b.update((e=>i(e,!1)))},setTouched:_,setError:function(e,t){k.update((n=>d(n,e,t)))},setField:function(e,t,n=!0){if(g.update((n=>d(n,e,t))),n&&_(e),I)for(const n of I.elements){if(!A(n)||!n.name)continue;const r=O(n);if(e===r)return void $(n,t)}},setFields:M,validate:async function(){const e=D(g);b.update((e=>i(e,!0)));const n=await L(e,t.validate);return k.set(n||{}),n},form:function(e){function u(n){return n({form:e,controls:Array.from(e.elements).filter(A),data:g,errors:k,touched:b,config:t,addValidator:a})}function v(){for(const t of Array.from(e.elements).filter(A)){if(x(t))continue;let e="value";p(t)&&["checkbox","radio"].includes(t.type)&&(e="checked"),p(t)&&"file"===t.type&&(e="files");const n=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,e);Object.defineProperty(t,e,{configurable:!0,set(e){var r;if(null===(r=null==n?void 0:n.set)||void 0===r||r.call(t,e),p(t)){if("checkbox"===t.type)return $(t);if("radio"===t.type)return T(t);if("file"===t.type)return V(t)}const o=h(t)?t.value:N(t);g.update((e=>d(e,O(t),o)))},get:null==n?void 0:n.get})}}n=r.map(u),e.noValidate=!!t.validate;const{defaultData:m}=F(e);function $(t){const n=y(t),r=O(t),o=Array.from(e.querySelectorAll(`[name="${t.name}"]`)).filter((e=>!!A(e)&&(void 0!==n?Number(e.dataset.felteIndex)===n:r===O(e))));return 1===o.length?g.update((e=>d(e,O(t),t.checked))):g.update((e=>d(e,O(t),o.filter(p).filter((e=>e.checked)).map((e=>e.value)))))}function T(t){const n=e.querySelectorAll(`[name="${t.name}"]`),r=Array.from(n).find((e=>p(e)&&e.checked));g.update((e=>d(e,O(t),null==r?void 0:r.value)))}function V(e){const t=e.files;g.update((n=>d(n,O(e),e.multiple?Array.from(null!=t?t:[]):null==t?void 0:t[0])))}function L(e){var n;const r=e.target;if(!r||!A(r)||h(r)||x(r))return;if(["checkbox","radio","file"].includes(r.type))return;if(!r.name)return;(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.input)&&_(O(r));const o=N(r);g.update((e=>d(e,O(r),o)))}function D(e){var n;const r=e.target;r&&A(r)&&!x(r)&&r.name&&((null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.change)&&_(O(r)),h(r)&&g.update((e=>d(e,O(r),r.value))),p(r)&&("checkbox"===r.type&&$(r),"radio"===r.type&&T(r),"file"===r.type&&V(r)))}function C(e){var n;const r=e.target;r&&A(r)&&!x(r)&&r.name&&(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.blur)&&_(O(r))}function R(e){for(const t of e)"true"===t.dataset.felteUnsetOnRemove&&g.update((e=>f(e,j(t))))}I=e,w=c(o(m),w),M(w),b.set(i(w,!1));const U=new MutationObserver((function(t){for(const o of t)if("childList"===o.type){if(o.addedNodes.length>0){if(v(),!Array.from(o.addedNodes).some((e=>!!E(e)&&(!!A(e)||S(e).length>0))))continue;n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(u);const{defaultData:t}=F(e),a=i(t,!1);g.update((e=>l(e,t))),b.update((e=>l(e,a)))}if(o.removedNodes.length>0)for(const e of o.removedNodes){if(!E(e))continue;const t=S(e);0!==t.length&&(n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(u),R(t))}}}));U.observe(e,{childList:!0,subtree:!0}),v(),e.addEventListener("input",L),e.addEventListener("change",D),e.addEventListener("focusout",C),e.addEventListener("submit",P);const q=k.subscribe((t=>{for(const n of e.elements){if(!A(n)||!n.name)continue;const e=s(t,O(n)),r=Array.isArray(e)?e.join("\n"):"string"==typeof e?e:void 0;r!==n.dataset.felteValidationMessage&&(r?n.dataset.felteValidationMessage=r:delete n.dataset.felteValidationMessage)}}));return{destroy(){U.disconnect(),e.removeEventListener("input",L),e.removeEventListener("change",D),e.removeEventListener("focusout",C),e.removeEventListener("submit",P),q(),n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)}))}}}}}({currentExtenders:b,extender:g,config:e,addValidator:v,stores:{data:V,errors:_,touched:M,isValid:I,isSubmitting:k}});function P(e,t){if(!r(e))return e!==t}function C(e,t){if(!r(e))return t||e}return Object.assign({data:Object.assign(Object.assign({},V),{set:function(t){return M.update((n=>{const r=a(o(t),e.initialValues,P);return a(r,n,C)})),V.set(t)}}),errors:_,touched:M,isValid:I,isSubmitting:k},w)},e.deepSet=i,e.deepSome=m,e.executeValidation=L,e.getFormControls=S,e.getFormDefaultValues=F,e.getIndex=y,e.getInputTextOrNumber=N,e.getPath=O,e.getPathFromDataset=j,e.isElement=E,e.isFieldSetElement=b,e.isFieldValue=function(e){return Array.isArray(e)?0===e.length||e.some((e=>e instanceof File||"string"==typeof e)):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||e instanceof File},e.isFormControl=A,e.isInputElement=p,e.isSelectElement=h,e.isTextAreaElement=g,e.setControlValue=$,e.setForm=T,e.shouldIgnore=x,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map
{
"name": "@felte/core",
"version": "0.2.0",
"version": "0.2.1",
"description": "Core package for FelteJS",

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

"dependencies": {
"@felte/common": "0.5.0"
"@felte/common": "0.5.1"
},

@@ -26,0 +26,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 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