feature-form 0.0.48 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/create-form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var g=require("@blgc/utils"),
|
|
1
|
+
"use strict";var g=require("@blgc/utils"),y=require("feature-state"),k=require("./form-field/create-form-field.js"),E=require("./form-field/is-form-field.js"),h=require("./types/form-field.js"),P=Object.defineProperty,M=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,j=(s,l,i)=>l in s?P(s,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[l]=i,w=(s,l)=>{for(var i in l||(l={}))C.call(l,i)&&j(s,i,l[i]);if(M)for(var i of M(l))D.call(l,i)&&j(s,i,l[i]);return s},p=(s,l,i)=>new Promise((V,v)=>{var F=o=>{try{u(i.next(o))}catch(e){v(e)}},S=o=>{try{u(i.throw(o))}catch(e){v(e)}},u=o=>o.done?V(o.value):Promise.resolve(o.value).then(F,S);u((i=i.apply(s,l)).next())});function I(s){const{fields:l,collectErrorMode:i="firstError",disabled:V=!1,validateMode:v=g.bitwiseFlag(h.FormFieldValidateMode.OnSubmit),reValidateMode:F=g.bitwiseFlag(h.FormFieldReValidateMode.OnBlur,h.FormFieldReValidateMode.OnSubmit),onValidSubmit:S,onInvalidSubmit:u,notifyOnStatusChange:o=!0}=s;return g.withNew({_features:[],_config:{disabled:V},_validSubmitCallbacks:S!=null?[S]:[],_invalidSubmitCallbacks:u!=null?[u]:[],fields:Object.fromEntries(Object.entries(l).map(([e,t])=>{var r,b,m,d;return[e,E.isFormField(t)?t:k.createFormField(t.defaultValue,{key:e,validator:t.validator,collectErrorMode:(r=t.collectErrorMode)!=null?r:i,validateMode:(b=t.validateMode)!=null?b:v,reValidateMode:(m=t.reValidateMode)!=null?m:F,editable:(d=t.editable)!=null?d:!0,notifyOnStatusChange:o})]})),isValid:y.createState(!1),isValidating:y.createState(!1),isSubmitted:y.createState(!1),isSubmitting:y.createState(!1),_new(){for(const e of Object.values(this.fields))e.status.listen(()=>p(this,null,function*(){yield this._revalidate(!0)}),{key:"form_revalidate"})},_revalidate(e=!1){return p(this,null,function*(){const t=Object.values(this.fields);return e||(this.isValidating.set(!0),yield Promise.all(t.map(r=>r.validate())),this.isValidating.set(!1)),this.isValid.set(t.every(r=>r.isValid())),this.isValid.get()})},submit(){return p(this,arguments,function*(e={}){const{context:t,assignToInitial:r=!1,onInvalidSubmit:b,onValidSubmit:m,postSubmitCallback:d}=e;this.isSubmitting.set(!0);const _=[];for(const a of Object.values(this.fields))a.isSubmitting.set(!0),(a.isSubmitted.get()&&a._config.reValidateMode.has(h.FormFieldReValidateMode.OnSubmit)||!a.isSubmitted.get()&&a._config.validateMode.has(h.FormFieldValidateMode.OnSubmit))&&_.push(a.validate());yield Promise.all(_),this._revalidate(!0);const c=this.getValidData(),f=[];if(c!=null){for(const a of this._validSubmitCallbacks)f.push(a(c,t));typeof m=="function"&&f.push(m(c,t))}else{const a=this.getErrors();for(const n of this._invalidSubmitCallbacks)f.push(n(a,t));typeof b=="function"&&f.push(b(a,t))}let O=null;d!=null?O=(yield Promise.all(f)).reduce((a,n)=>n!=null&&typeof n=="object"?w(w({},a),n):a,{}):yield Promise.all(f);for(const[a,n]of Object.entries(this.fields))c!=null&&Object.prototype.hasOwnProperty.call(c,a)&&r&&(n._intialValue=g.deepCopy(c[a])),n.isSubmitted.set(!0),n.isSubmitting.set(!1);return this.isSubmitted.set(!0),this.isSubmitting.set(!1),d==null||d(this,O!=null?O:{}),this.isValid.get()})},validate(){return p(this,null,function*(){return this._revalidate(!1)})},getField(e){return this.fields[e]},getValidData(){if(!this.isValid.get())return null;const e={};for(const[t,r]of Object.entries(this.fields))e[t]=r.get();return e},getErrors(){const e={};for(const[t,r]of Object.entries(this.fields))switch(r.status._v.type){case"INVALID":e[t]=r.status._v.errors;break;case"UNVALIDATED":e[t]=[{code:"unvalidated",message:`${t.toString()} was not yet validated!`,path:t}];break}return e},reset(){for(const e of Object.values(this.fields))e.reset();this.isSubmitted.set(!1),this._revalidate(!0)}})}exports.createForm=I;
|
package/dist/esm/create-form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bitwiseFlag as
|
|
1
|
+
import{bitwiseFlag as j,withNew as E,deepCopy as P}from"@blgc/utils";import{createState as p}from"feature-state";import{createFormField as C}from"./form-field/create-form-field.js";import{isFormField as D}from"./form-field/is-form-field.js";import{FormFieldValidateMode as w,FormFieldReValidateMode as V}from"./types/form-field.js";var I=Object.defineProperty,M=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,F=(r,s,i)=>s in r?I(r,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[s]=i,k=(r,s)=>{for(var i in s||(s={}))x.call(s,i)&&F(r,i,s[i]);if(M)for(var i of M(s))A.call(s,i)&&F(r,i,s[i]);return r},g=(r,s,i)=>new Promise((y,h)=>{var S=o=>{try{u(i.next(o))}catch(t){h(t)}},v=o=>{try{u(i.throw(o))}catch(t){h(t)}},u=o=>o.done?y(o.value):Promise.resolve(o.value).then(S,v);u((i=i.apply(r,s)).next())});function N(r){const{fields:s,collectErrorMode:i="firstError",disabled:y=!1,validateMode:h=j(w.OnSubmit),reValidateMode:S=j(V.OnBlur,V.OnSubmit),onValidSubmit:v,onInvalidSubmit:u,notifyOnStatusChange:o=!0}=r;return E({_features:[],_config:{disabled:y},_validSubmitCallbacks:v!=null?[v]:[],_invalidSubmitCallbacks:u!=null?[u]:[],fields:Object.fromEntries(Object.entries(s).map(([t,e])=>{var a,b,m,d;return[t,D(e)?e:C(e.defaultValue,{key:t,validator:e.validator,collectErrorMode:(a=e.collectErrorMode)!=null?a:i,validateMode:(b=e.validateMode)!=null?b:h,reValidateMode:(m=e.reValidateMode)!=null?m:S,editable:(d=e.editable)!=null?d:!0,notifyOnStatusChange:o})]})),isValid:p(!1),isValidating:p(!1),isSubmitted:p(!1),isSubmitting:p(!1),_new(){for(const t of Object.values(this.fields))t.status.listen(()=>g(this,null,function*(){yield this._revalidate(!0)}),{key:"form_revalidate"})},_revalidate(t=!1){return g(this,null,function*(){const e=Object.values(this.fields);return t||(this.isValidating.set(!0),yield Promise.all(e.map(a=>a.validate())),this.isValidating.set(!1)),this.isValid.set(e.every(a=>a.isValid())),this.isValid.get()})},submit(){return g(this,arguments,function*(t={}){const{context:e,assignToInitial:a=!1,onInvalidSubmit:b,onValidSubmit:m,postSubmitCallback:d}=t;this.isSubmitting.set(!0);const _=[];for(const l of Object.values(this.fields))l.isSubmitting.set(!0),(l.isSubmitted.get()&&l._config.reValidateMode.has(V.OnSubmit)||!l.isSubmitted.get()&&l._config.validateMode.has(w.OnSubmit))&&_.push(l.validate());yield Promise.all(_),this._revalidate(!0);const f=this.getValidData(),c=[];if(f!=null){for(const l of this._validSubmitCallbacks)c.push(l(f,e));typeof m=="function"&&c.push(m(f,e))}else{const l=this.getErrors();for(const n of this._invalidSubmitCallbacks)c.push(n(l,e));typeof b=="function"&&c.push(b(l,e))}let O=null;d!=null?O=(yield Promise.all(c)).reduce((l,n)=>n!=null&&typeof n=="object"?k(k({},l),n):l,{}):yield Promise.all(c);for(const[l,n]of Object.entries(this.fields))f!=null&&Object.prototype.hasOwnProperty.call(f,l)&&a&&(n._intialValue=P(f[l])),n.isSubmitted.set(!0),n.isSubmitting.set(!1);return this.isSubmitted.set(!0),this.isSubmitting.set(!1),d==null||d(this,O!=null?O:{}),this.isValid.get()})},validate(){return g(this,null,function*(){return this._revalidate(!1)})},getField(t){return this.fields[t]},getValidData(){if(!this.isValid.get())return null;const t={};for(const[e,a]of Object.entries(this.fields))t[e]=a.get();return t},getErrors(){const t={};for(const[e,a]of Object.entries(this.fields))switch(a.status._v.type){case"INVALID":t[e]=a.status._v.errors;break;case"UNVALIDATED":t[e]=[{code:"unvalidated",message:`${e.toString()} was not yet validated!`,path:e}];break}return t},reset(){for(const t of Object.values(this.fields))t.reset();this.isSubmitted.set(!1),this._revalidate(!0)}})}export{N as createForm};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feature-form",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Straightforward, typesafe, and feature-based form library for ReactJs",
|
|
6
6
|
"keywords": [],
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@blgc/types": "0.0.17",
|
|
27
|
-
"feature-state": "0.0.51",
|
|
28
27
|
"validation-adapter": "0.0.23",
|
|
28
|
+
"feature-state": "0.0.51",
|
|
29
29
|
"@blgc/utils": "0.0.49"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^22.13.10",
|
|
33
|
-
"@blgc/config": "0.0.
|
|
33
|
+
"@blgc/config": "0.0.34",
|
|
34
34
|
"rollup-presets": "0.0.21"
|
|
35
35
|
},
|
|
36
36
|
"size-limit": [
|