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.7 to 0.3.0

13

dist/index.d.ts

@@ -1,5 +0,8 @@

import { Form, FormConfigWithInitialValues, FormConfigWithoutInitialValues, Stores, Obj } from "@felte/common";
type Adapters<Data extends Obj> = {
stores: Stores<Data>;
import { Form, FormConfigWithInitialValues, FormConfigWithoutInitialValues, StoreFactory, Obj } from "@felte/common";
type Adapters = {
storeFactory: StoreFactory;
};
type CoreForm<Data extends Obj = any> = Form<Data> & {
cleanup(): void;
};
/**

@@ -13,3 +16,3 @@ * Creates the stores and `form` action to make the form reactive.

*/
declare function createForm<Data extends Obj, Ext extends Obj = Obj>(config: FormConfigWithInitialValues<Data> & Ext, adapters: Adapters<Data>): Form<Data>;
declare function createForm<Data extends Obj = any, Ext extends Obj = any>(config: FormConfigWithInitialValues<Data> & Ext, adapters: Adapters): CoreForm<Data>;
/**

@@ -21,5 +24,5 @@ * Creates the stores and `form` action to make the form reactive.

*/
declare function createForm<Data extends Obj, Ext extends Obj = Obj>(config: FormConfigWithoutInitialValues<Data> & Ext, adapters: Adapters<Data>): Form<Data>;
declare function createForm<Data extends Obj = any, Ext extends Obj = any>(config: FormConfigWithoutInitialValues<Data> & Ext, adapters: Adapters): CoreForm<Data>;
export { Adapters, createForm };
export * from '@felte/common';
//# sourceMappingURL=index.d.ts.map

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

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

"dependencies": {
"@felte/common": "0.5.4"
"@felte/common": "0.6.0"
},

@@ -44,4 +44,6 @@ "publishConfig": {

"docs:build": "typedoc --out ../../docs",
"dev": "rollup -cw"
"dev": "rollup -cw",
"test": "jest",
"test:ci": "jest --coverage"
}
}

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

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