feature-form 0.0.1
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/README.md +11 -0
- package/dist/cjs/create-form.js +1 -0
- package/dist/cjs/form-field/create-form-field.js +1 -0
- package/dist/cjs/form-field/create-status.js +1 -0
- package/dist/cjs/form-field/is-form-field.js +1 -0
- package/dist/cjs/form-field/validator/create-validator.js +1 -0
- package/dist/cjs/form-field/validator/valibot.js +1 -0
- package/dist/cjs/form-field/validator/yup.js +1 -0
- package/dist/cjs/form-field/validator/zod.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/esm/create-form.js +1 -0
- package/dist/esm/form-field/create-form-field.js +1 -0
- package/dist/esm/form-field/create-status.js +1 -0
- package/dist/esm/form-field/is-form-field.js +1 -0
- package/dist/esm/form-field/validator/create-validator.js +1 -0
- package/dist/esm/form-field/validator/valibot.js +1 -0
- package/dist/esm/form-field/validator/yup.js +1 -0
- package/dist/esm/form-field/validator/zod.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/types/create-form.d.ts +25 -0
- package/dist/types/create-form.d.ts.map +1 -0
- package/dist/types/form-field/create-form-field.d.ts +8 -0
- package/dist/types/form-field/create-form-field.d.ts.map +1 -0
- package/dist/types/form-field/create-status.d.ts +3 -0
- package/dist/types/form-field/create-status.d.ts.map +1 -0
- package/dist/types/form-field/index.d.ts +5 -0
- package/dist/types/form-field/index.d.ts.map +1 -0
- package/dist/types/form-field/is-form-field.d.ts +3 -0
- package/dist/types/form-field/is-form-field.d.ts.map +1 -0
- package/dist/types/form-field/validator/create-validator.d.ts +3 -0
- package/dist/types/form-field/validator/create-validator.d.ts.map +1 -0
- package/dist/types/form-field/validator/index.d.ts +5 -0
- package/dist/types/form-field/validator/index.d.ts.map +1 -0
- package/dist/types/form-field/validator/valibot.d.ts +4 -0
- package/dist/types/form-field/validator/valibot.d.ts.map +1 -0
- package/dist/types/form-field/validator/yup.d.ts +4 -0
- package/dist/types/form-field/validator/yup.d.ts.map +1 -0
- package/dist/types/form-field/validator/zod.d.ts +4 -0
- package/dist/types/form-field/validator/zod.d.ts.map +1 -0
- package/dist/types/has-features.d.ts +3 -0
- package/dist/types/has-features.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/features.d.ts +16 -0
- package/dist/types/types/features.d.ts.map +1 -0
- package/dist/types/types/form-field.d.ts +65 -0
- package/dist/types/types/form-field.d.ts.map +1 -0
- package/dist/types/types/form.d.ts +37 -0
- package/dist/types/types/form.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var y=require("./form-field/create-form-field.js");require("feature-state"),require("@ibg/utils"),require("valibot"),require("yup"),require("zod");var M=Object.defineProperty,m=Object.getOwnPropertySymbols,S=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,h=(a,r,i)=>r in a?M(a,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):a[r]=i,V=(a,r)=>{for(var i in r||(r={}))S.call(r,i)&&h(a,i,r[i]);if(m)for(var i of m(r))g.call(r,i)&&h(a,i,r[i]);return a},d=(a,r,i)=>new Promise((c,s)=>{var f=e=>{try{n(i.next(e))}catch(t){s(t)}},b=e=>{try{n(i.throw(e))}catch(t){s(t)}},n=e=>e.done?c(e.value):Promise.resolve(e.value).then(f,b);n((i=i.apply(a,r)).next())});function p(a){const{fields:r,collectErrorMode:i="firstError",disabled:c=!1,validateMode:s="onSubmit",reValidateMode:f="onBlur",onSubmit:b=null}=a,n={_:null,_features:["base"],_config:{collectErrorMode:i,disabled:c,onSubmit:b},fields:Object.fromEntries(Object.entries(r).map(([e,t])=>{var l,u,o,v;return[e,y.createFormField(t.defaultValue,{key:e,validator:t.validator,collectErrorMode:(l=t.collectErrorMode)!=null?l:i,validateMode:(u=t.validateMode)!=null?u:s,reValidateMode:(o=t.reValidateMode)!=null?o:f,editable:(v=t.editable)!=null?v:!0})]})),isValid:!1,isSubmitted:!1,_revalidate(e=!1){return d(this,null,function*(){let t=!0;for(const l of Object.values(this.fields))e?t=l.isValid&&t:t=(yield l.validate())&&t;return this.isValid=t,t})},submit(){return d(this,null,function*(){var e,t;const l={};for(const[u,o]of Object.entries(this.fields))(o.isSubmitted&&o._config.reValidateMode==="onSubmit"||!o.isSubmitted&&o._config.validateMode==="onSubmit")&&(yield o.validate()),o.isSubmitted=!0,l[u]=o.get();return this.isSubmitted=!0,this.isValid&&((t=(e=this._config).onSubmit)==null||t.call(e,l)),this.isValid})},validate(){return d(this,null,function*(){return this._revalidate(!1)})},getField(e){return this.fields[e]},reset(){for(const e of Object.values(this.fields))e.reset();this.isSubmitted=!1}};for(const e of Object.values(n.fields))e.listen(t=>d(this,[t],function*({state:l}){(l.isSubmitted&&l._config.reValidateMode==="onChange"||!l.isSubmitted&&l._config.validateMode==="onChange"||l._config.validateMode==="onTouched"&&l.isTouched)&&(yield l.validate())})),e.status.listen(()=>d(this,null,function*(){yield n._revalidate(!0)}));return n}function O(a,r){return V({validator:a},r)}exports.createForm=p,exports.fromValidator=O;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=require("feature-state"),v=require("@ibg/utils"),f=require("./create-status.js"),y=(r,o,i)=>new Promise((d,s)=>{var l=t=>{try{a(i.next(t))}catch(e){s(e)}},u=t=>{try{a(i.throw(t))}catch(e){s(e)}},a=t=>t.done?d(t.value):Promise.resolve(t.value).then(l,u);a((i=i.apply(r,o)).next())});function _(r,o){const{key:i,validator:d,editable:s=!0,reValidateMode:l="onBlur",validateMode:u="onSubmit",collectErrorMode:a="firstError",notifyOnStatusChange:t=!0}=o,e=c.createState(r);e._features.push("form-field");const n=f.createStatus({type:"UNVALIDATED"});t&&n.listen(()=>{e._notify()});const h={_config:{editable:s,validateMode:u,reValidateMode:l,collectErrorMode:a},_intialValue:v.deepCopy(e._value),_validator:d,key:i,isValid:!1,isTouched:!1,isSubmitted:!1,status:n,validate(){return y(this,null,function*(){return this.isValid=yield this._validator.validate(this),this.status._notify(),this.isValid})},blur(){(this.isSubmitted&&this._config.reValidateMode==="onBlur"||!this.isSubmitted&&(this._config.validateMode==="onBlur"||this._config.validateMode==="onTouched"&&!this.isTouched))&&this.validate(),this.isTouched=!0},reset(){this.set(this._intialValue),this.isTouched=!1,this.isSubmitted=!1,this.isValid=!1,this.status.set({type:"UNVALIDATED"})}};return Object.assign(e,h)}exports.createFormField=_;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=require("feature-state");function a(r){const t=s.createState(r);return t._features.push("form-field-status"),Object.assign(t,{registerError(e){this._value.type==="INVALID"?this._value.errors.push(e):this._value={type:"INVALID",errors:[e]}}})}exports.createStatus=a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function i(e){return typeof e=="object"&&e!=null&&"_features"in e&&Array.isArray(e._features)&&e._features.includes("form-field")}exports.isFormField=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=require("@ibg/utils"),v=(e,t,a)=>new Promise((l,s)=>{var h=i=>{try{n(a.next(i))}catch(r){s(r)}},u=i=>{try{n(a.throw(i))}catch(r){s(r)}},n=i=>i.done?l(i.value):Promise.resolve(i.value).then(h,u);n((a=a.apply(e,t)).next())});function o(e){return{_validationChain:e,isValidating:!1,push(t){this._validationChain.push(t)},append(t){this._validationChain.push(...t._validationChain)},validate(t){return v(this,null,function*(){this.isValidating=!0;for(const a of this._validationChain)if(yield a.validate(t),t._config.collectErrorMode==="firstError"&&t.status.get().type==="INVALID")break;return t.status.get().type==="UNVALIDATED"&&(t.status._value={type:"VALID"}),this.isValidating=!1,t.status.get().type==="VALID"})},clone(){return o(d.deepCopy(this._validationChain))}}}exports.createValidator=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=require("valibot"),v=require("./create-validator.js"),d=(i,a,e)=>new Promise((o,r)=>{var c=t=>{try{s(e.next(t))}catch(l){r(l)}},u=t=>{try{s(e.throw(t))}catch(l){r(l)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(c,u);s((e=e.apply(i,a)).next())});function f(i){return v.createValidator([{key:"valibot",validate:a=>d(this,null,function*(){var e;const o=yield n.safeParseAsync(i,a.get(),{abortPipeEarly:a._config.collectErrorMode==="firstError"});if(o.issues!=null)for(const r of o.issues)a.status.registerError({code:r.type,message:r.message,path:(e=n.getDotPath(r))!=null?e:void 0})})}])}exports.valibotValidator=f;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=require("yup"),p=require("./create-validator.js"),y=(i,e,t)=>new Promise((n,r)=>{var o=a=>{try{s(t.next(a))}catch(l){r(l)}},c=a=>{try{s(t.throw(a))}catch(l){r(l)}},s=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,c);s((t=t.apply(i,e)).next())});function h(i){return p.createValidator([{key:"yup",validate:e=>y(this,null,function*(){var t,n;try{yield i.validate(e.get(),{abortEarly:e._config.collectErrorMode==="firstError"})}catch(r){if(r instanceof u.ValidationError){r.inner.length===0&&e.status.registerError({code:(t=r.type)!=null?t:"unknown",message:r.message.replace("this",e.key),path:r.path});for(const o of r.inner)e.status.registerError({code:(n=o.type)!=null?n:"unknown",message:o.message.replace("this",e.key),path:o.path})}}})}])}exports.yupValidator=h;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("zod"),i=require("./create-validator.js");function s(o){return i.createValidator([{key:"zod",validate:e=>{try{o.parse(e.get())}catch(a){if(a instanceof t.ZodError)for(const r of a.errors)e.status.registerError({code:r.code,message:r.message,path:r.path.join(".")})}}}])}exports.zodValidator=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./create-form.js"),a=require("./form-field/create-form-field.js"),e=require("./form-field/create-status.js"),t=require("./form-field/is-form-field.js"),i=require("./form-field/validator/create-validator.js"),o=require("./form-field/validator/valibot.js"),d=require("./form-field/validator/yup.js"),l=require("./form-field/validator/zod.js");exports.createForm=r.createForm,exports.fromValidator=r.fromValidator,exports.createFormField=a.createFormField,exports.createStatus=e.createStatus,exports.isFormField=t.isFormField,exports.createValidator=i.createValidator,exports.valibotValidator=o.valibotValidator,exports.yupValidator=d.yupValidator,exports.zodValidator=l.zodValidator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createFormField as p}from"./form-field/create-form-field.js";import"feature-state";import"@ibg/utils";import"valibot";import"yup";import"zod";var y=Object.defineProperty,v=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,h=(o,r,i)=>r in o?y(o,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[r]=i,g=(o,r)=>{for(var i in r||(r={}))M.call(r,i)&&h(o,i,r[i]);if(v)for(var i of v(r))S.call(r,i)&&h(o,i,r[i]);return o},d=(o,r,i)=>new Promise((c,s)=>{var f=t=>{try{n(i.next(t))}catch(e){s(e)}},b=t=>{try{n(i.throw(t))}catch(e){s(e)}},n=t=>t.done?c(t.value):Promise.resolve(t.value).then(f,b);n((i=i.apply(o,r)).next())});function V(o){const{fields:r,collectErrorMode:i="firstError",disabled:c=!1,validateMode:s="onSubmit",reValidateMode:f="onBlur",onSubmit:b=null}=o,n={_:null,_features:["base"],_config:{collectErrorMode:i,disabled:c,onSubmit:b},fields:Object.fromEntries(Object.entries(r).map(([t,e])=>{var l,u,a,m;return[t,p(e.defaultValue,{key:t,validator:e.validator,collectErrorMode:(l=e.collectErrorMode)!=null?l:i,validateMode:(u=e.validateMode)!=null?u:s,reValidateMode:(a=e.reValidateMode)!=null?a:f,editable:(m=e.editable)!=null?m:!0})]})),isValid:!1,isSubmitted:!1,_revalidate(t=!1){return d(this,null,function*(){let e=!0;for(const l of Object.values(this.fields))t?e=l.isValid&&e:e=(yield l.validate())&&e;return this.isValid=e,e})},submit(){return d(this,null,function*(){var t,e;const l={};for(const[u,a]of Object.entries(this.fields))(a.isSubmitted&&a._config.reValidateMode==="onSubmit"||!a.isSubmitted&&a._config.validateMode==="onSubmit")&&(yield a.validate()),a.isSubmitted=!0,l[u]=a.get();return this.isSubmitted=!0,this.isValid&&((e=(t=this._config).onSubmit)==null||e.call(t,l)),this.isValid})},validate(){return d(this,null,function*(){return this._revalidate(!1)})},getField(t){return this.fields[t]},reset(){for(const t of Object.values(this.fields))t.reset();this.isSubmitted=!1}};for(const t of Object.values(n.fields))t.listen(e=>d(this,[e],function*({state:l}){(l.isSubmitted&&l._config.reValidateMode==="onChange"||!l.isSubmitted&&l._config.validateMode==="onChange"||l._config.validateMode==="onTouched"&&l.isTouched)&&(yield l.validate())})),t.status.listen(()=>d(this,null,function*(){yield n._revalidate(!0)}));return n}function O(o,r){return g({validator:o},r)}export{V as createForm,O as fromValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createState as c}from"feature-state";import{deepCopy as f}from"@ibg/utils";import{createStatus as v}from"./create-status.js";var m=(o,r,i)=>new Promise((d,s)=>{var l=t=>{try{a(i.next(t))}catch(e){s(e)}},n=t=>{try{a(i.throw(t))}catch(e){s(e)}},a=t=>t.done?d(t.value):Promise.resolve(t.value).then(l,n);a((i=i.apply(o,r)).next())});function y(o,r){const{key:i,validator:d,editable:s=!0,reValidateMode:l="onBlur",validateMode:n="onSubmit",collectErrorMode:a="firstError",notifyOnStatusChange:t=!0}=r,e=c(o);e._features.push("form-field");const u=v({type:"UNVALIDATED"});t&&u.listen(()=>{e._notify()});const h={_config:{editable:s,validateMode:n,reValidateMode:l,collectErrorMode:a},_intialValue:f(e._value),_validator:d,key:i,isValid:!1,isTouched:!1,isSubmitted:!1,status:u,validate(){return m(this,null,function*(){return this.isValid=yield this._validator.validate(this),this.status._notify(),this.isValid})},blur(){(this.isSubmitted&&this._config.reValidateMode==="onBlur"||!this.isSubmitted&&(this._config.validateMode==="onBlur"||this._config.validateMode==="onTouched"&&!this.isTouched))&&this.validate(),this.isTouched=!0},reset(){this.set(this._intialValue),this.isTouched=!1,this.isSubmitted=!1,this.isValid=!1,this.status.set({type:"UNVALIDATED"})}};return Object.assign(e,h)}export{y as createFormField};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createState as s}from"feature-state";function a(e){const t=s(e);return t._features.push("form-field-status"),Object.assign(t,{registerError(r){this._value.type==="INVALID"?this._value.errors.push(r):this._value={type:"INVALID",errors:[r]}}})}export{a as createStatus};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(e){return typeof e=="object"&&e!=null&&"_features"in e&&Array.isArray(e._features)&&e._features.includes("form-field")}export{r as isFormField};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{deepCopy as u}from"@ibg/utils";var p=(e,t,a)=>new Promise((l,o)=>{var h=i=>{try{n(a.next(i))}catch(r){o(r)}},d=i=>{try{n(a.throw(i))}catch(r){o(r)}},n=i=>i.done?l(i.value):Promise.resolve(i.value).then(h,d);n((a=a.apply(e,t)).next())});function s(e){return{_validationChain:e,isValidating:!1,push(t){this._validationChain.push(t)},append(t){this._validationChain.push(...t._validationChain)},validate(t){return p(this,null,function*(){this.isValidating=!0;for(const a of this._validationChain)if(yield a.validate(t),t._config.collectErrorMode==="firstError"&&t.status.get().type==="INVALID")break;return t.status.get().type==="UNVALIDATED"&&(t.status._value={type:"VALID"}),this.isValidating=!1,t.status.get().type==="VALID"})},clone(){return s(u(this._validationChain))}}}export{s as createValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{safeParseAsync as u,getDotPath as f}from"valibot";import{createValidator as v}from"./create-validator.js";var d=(s,o,t)=>new Promise((a,r)=>{var n=e=>{try{i(t.next(e))}catch(l){r(l)}},c=e=>{try{i(t.throw(e))}catch(l){r(l)}},i=e=>e.done?a(e.value):Promise.resolve(e.value).then(n,c);i((t=t.apply(s,o)).next())});function m(s){return v([{key:"valibot",validate:o=>d(this,null,function*(){var t;const a=yield u(s,o.get(),{abortPipeEarly:o._config.collectErrorMode==="firstError"});if(a.issues!=null)for(const r of a.issues)o.status.registerError({code:r.type,message:r.message,path:(t=f(r))!=null?t:void 0})})}])}export{m as valibotValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ValidationError as p}from"yup";import{createValidator as u}from"./create-validator.js";var h=(i,e,t)=>new Promise((n,r)=>{var a=o=>{try{s(t.next(o))}catch(l){r(l)}},c=o=>{try{s(t.throw(o))}catch(l){r(l)}},s=o=>o.done?n(o.value):Promise.resolve(o.value).then(a,c);s((t=t.apply(i,e)).next())});function y(i){return u([{key:"yup",validate:e=>h(this,null,function*(){var t,n;try{yield i.validate(e.get(),{abortEarly:e._config.collectErrorMode==="firstError"})}catch(r){if(r instanceof p){r.inner.length===0&&e.status.registerError({code:(t=r.type)!=null?t:"unknown",message:r.message.replace("this",e.key),path:r.path});for(const a of r.inner)e.status.registerError({code:(n=a.type)!=null?n:"unknown",message:a.message.replace("this",e.key),path:a.path})}}})}])}export{y as yupValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ZodError as a}from"zod";import{createValidator as s}from"./create-validator.js";function i(e){return s([{key:"zod",validate:o=>{try{e.parse(o.get())}catch(t){if(t instanceof a)for(const r of t.errors)o.status.registerError({code:r.code,message:r.message,path:r.path.join(".")})}}}])}export{i as zodValidator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createForm as t,fromValidator as e}from"./create-form.js";import{createFormField as m}from"./form-field/create-form-field.js";import{createStatus as i}from"./form-field/create-status.js";import{isFormField as d}from"./form-field/is-form-field.js";import{createValidator as x}from"./form-field/validator/create-validator.js";import{valibotValidator as V}from"./form-field/validator/valibot.js";import{yupValidator as s}from"./form-field/validator/yup.js";import{zodValidator as b}from"./form-field/validator/zod.js";export{t as createForm,m as createFormField,i as createStatus,x as createValidator,e as fromValidator,d as isFormField,V as valibotValidator,s as yupValidator,b as zodValidator};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type TForm, type TFormConfig, type TFormData, type TFormFieldReValidateMode, type TFormFieldStateConfig, type TFormFieldValidateMode, type TFormFieldValidator } from './types';
|
|
2
|
+
export declare function createForm<GFormData extends TFormData>(config: TCreateFormConfig<GFormData>): TForm<GFormData, ['base']>;
|
|
3
|
+
export interface TCreateFormConfig<GFormData extends TFormData> extends Partial<TFormConfig<GFormData>> {
|
|
4
|
+
/**
|
|
5
|
+
* Form fields
|
|
6
|
+
*/
|
|
7
|
+
fields: TCreateFormConfigFormFields<GFormData>;
|
|
8
|
+
/**
|
|
9
|
+
* Validation strategy after submitting.
|
|
10
|
+
*/
|
|
11
|
+
validateMode?: TFormFieldValidateMode;
|
|
12
|
+
/**
|
|
13
|
+
* Validation strategy before submitting.
|
|
14
|
+
*/
|
|
15
|
+
reValidateMode?: TFormFieldReValidateMode;
|
|
16
|
+
}
|
|
17
|
+
export type TCreateFormConfigFormFields<GFormData extends TFormData> = {
|
|
18
|
+
[Key in keyof GFormData]: TCreateFormConfigFormField<GFormData[Key]>;
|
|
19
|
+
};
|
|
20
|
+
export interface TCreateFormConfigFormField<GValue> extends Partial<TFormFieldStateConfig> {
|
|
21
|
+
defaultValue?: GValue;
|
|
22
|
+
validator: TFormFieldValidator<GValue>;
|
|
23
|
+
}
|
|
24
|
+
export declare function fromValidator<GValue>(validator: TFormFieldValidator<GValue>, config: Omit<TCreateFormConfigFormField<GValue>, 'validator'>): TCreateFormConfigFormField<GValue>;
|
|
25
|
+
//# sourceMappingURL=create-form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-form.d.ts","sourceRoot":"","sources":["../../src/create-form.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,wBAAwB,EAE7B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,UAAU,CAAC,SAAS,SAAS,SAAS,EACrD,MAAM,EAAE,iBAAiB,CAAC,SAAS,CAAC,GAClC,KAAK,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,CAgH5B;AAED,MAAM,WAAW,iBAAiB,CAAC,SAAS,SAAS,SAAS,CAC7D,SAAQ,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACvC;;OAEG;IACH,MAAM,EAAE,2BAA2B,CAAC,SAAS,CAAC,CAAC;IAC/C;;OAEG;IACH,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC;;OAEG;IACH,cAAc,CAAC,EAAE,wBAAwB,CAAC;CAC1C;AAED,MAAM,MAAM,2BAA2B,CAAC,SAAS,SAAS,SAAS,IAAI;KACrE,GAAG,IAAI,MAAM,SAAS,GAAG,0BAA0B,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;CACpE,CAAC;AAEF,MAAM,WAAW,0BAA0B,CAAC,MAAM,CAAE,SAAQ,OAAO,CAAC,qBAAqB,CAAC;IACzF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;CACvC;AAID,wBAAgB,aAAa,CAAC,MAAM,EACnC,SAAS,EAAE,mBAAmB,CAAC,MAAM,CAAC,EACtC,MAAM,EAAE,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,GAC3D,0BAA0B,CAAC,MAAM,CAAC,CAEpC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type TFormField, type TFormFieldStateConfig, type TFormFieldValidator } from '../types';
|
|
2
|
+
export declare function createFormField<GValue>(initialValue: GValue | undefined, config: TCreateFormFieldConfig<GValue>): TFormField<GValue>;
|
|
3
|
+
export interface TCreateFormFieldConfig<GValue> extends Partial<TFormFieldStateConfig> {
|
|
4
|
+
key: string;
|
|
5
|
+
validator: TFormFieldValidator<GValue>;
|
|
6
|
+
notifyOnStatusChange?: boolean;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=create-form-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-form-field.d.ts","sourceRoot":"","sources":["../../../src/form-field/create-form-field.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,UAAU,EACf,KAAK,qBAAqB,EAE1B,KAAK,mBAAmB,EACxB,MAAM,UAAU,CAAC;AAGlB,wBAAgB,eAAe,CAAC,MAAM,EACrC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,MAAM,EAAE,sBAAsB,CAAC,MAAM,CAAC,GACpC,UAAU,CAAC,MAAM,CAAC,CAiEpB;AAED,MAAM,WAAW,sBAAsB,CAAC,MAAM,CAAE,SAAQ,OAAO,CAAC,qBAAqB,CAAC;IACrF,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-status.d.ts","sourceRoot":"","sources":["../../../src/form-field/create-status.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAE7E,wBAAgB,YAAY,CAAC,YAAY,EAAE,qBAAqB,GAAG,gBAAgB,CAiBlF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/form-field/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-form-field.d.ts","sourceRoot":"","sources":["../../../src/form-field/is-form-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,WAAW,CAAC,MAAM,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAAC,MAAM,CAAC,CAQzF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-validator.d.ts","sourceRoot":"","sources":["../../../../src/form-field/validator/create-validator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,yBAAyB,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvF,wBAAgB,eAAe,CAAC,MAAM,EACrC,eAAe,EAAE,yBAAyB,CAAC,MAAM,CAAC,GAChD,mBAAmB,CAAC,MAAM,CAAC,CAmC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/form-field/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type BaseIssue, type BaseSchema } from 'valibot';
|
|
2
|
+
import { type TFormFieldValidator } from '../../types';
|
|
3
|
+
export declare function valibotValidator<GValue>(schema: BaseSchema<GValue, unknown, BaseIssue<unknown>>): TFormFieldValidator<GValue>;
|
|
4
|
+
//# sourceMappingURL=valibot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valibot.d.ts","sourceRoot":"","sources":["../../../../src/form-field/validator/valibot.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtF,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,wBAAgB,gBAAgB,CAAC,MAAM,EACtC,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,GACrD,mBAAmB,CAAC,MAAM,CAAC,CAqB7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yup.d.ts","sourceRoot":"","sources":["../../../../src/form-field/validator/yup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,MAAM,EAAE,MAAM,KAAK,CAAC;AAEnD,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC,CA8BxF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../../../src/form-field/validator/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAqBxF"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TFeatureKeys, TForm, TFormData } from './types';
|
|
2
|
+
export declare function hasFeatures<GFormData extends TFormData, GFeatureKeys extends TFeatureKeys[], GHasFeatureKeys extends TFeatureKeys[]>(form: TForm<GFormData, GFeatureKeys>, features: GHasFeatureKeys): form is TForm<GFormData, (GFeatureKeys[number] | GHasFeatureKeys[number])[]>;
|
|
3
|
+
//# sourceMappingURL=has-features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-features.d.ts","sourceRoot":"","sources":["../../src/has-features.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE9D,wBAAgB,WAAW,CAC1B,SAAS,SAAS,SAAS,EAC3B,YAAY,SAAS,YAAY,EAAE,EACnC,eAAe,SAAS,YAAY,EAAE,EAEtC,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,YAAY,CAAC,EACpC,QAAQ,EAAE,eAAe,GACvB,IAAI,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAE9E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TFormFieldStateFeature, TFormFielStatusStateFeature } from './types';
|
|
2
|
+
export * from './create-form';
|
|
3
|
+
export * from './form-field';
|
|
4
|
+
export * from './types';
|
|
5
|
+
declare module 'feature-state' {
|
|
6
|
+
interface TThirdPartyFeatures<GValue> {
|
|
7
|
+
'form-field': TFormFieldStateFeature<GValue>;
|
|
8
|
+
'form-field-status': TFormFielStatusStateFeature;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAEnF,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,OAAO,QAAQ,eAAe,CAAC;IAC9B,UAAU,mBAAmB,CAAC,MAAM;QACnC,YAAY,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC7C,mBAAmB,EAAE,2BAA2B,CAAC;KACjD;CACD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TUnionToIntersection } from '@ibg/utils';
|
|
2
|
+
import { type TFormData } from './form';
|
|
3
|
+
export type TFeatures<GFormData extends TFormData = TFormData> = {
|
|
4
|
+
base: {
|
|
5
|
+
_: null;
|
|
6
|
+
};
|
|
7
|
+
} & TThirdPartyFeatures<GFormData>;
|
|
8
|
+
export interface TThirdPartyFeatures<GFormData> {
|
|
9
|
+
}
|
|
10
|
+
export type TFeatureKeys<GFormData extends TFormData = TFormData> = keyof TFeatures<GFormData>;
|
|
11
|
+
export type TSelectFeatureObjects<GFormData extends TFormData, GSelectedFeatureKeys extends TFeatureKeys[]> = {
|
|
12
|
+
[K in GSelectedFeatureKeys[number]]: TFeatures<GFormData>[K];
|
|
13
|
+
};
|
|
14
|
+
export type TSelectFeatures<GFormData extends TFormData, GSelectedFeatureKeys extends TFeatureKeys[], GSelectedFeatureObjects extends TSelectFeatureObjects<GFormData, GSelectedFeatureKeys> = TSelectFeatureObjects<GFormData, GSelectedFeatureKeys>> = TUnionToIntersection<GSelectedFeatureObjects[keyof GSelectedFeatureObjects]>;
|
|
15
|
+
export type TEnforceFeatures<GFeatureKeys extends TFeatureKeys[], GToEnforceFeatureKeys extends TFeatureKeys[]> = Exclude<GToEnforceFeatureKeys[number], GFeatureKeys[number]> extends never ? GFeatureKeys : GFeatureKeys | GToEnforceFeatureKeys;
|
|
16
|
+
//# sourceMappingURL=features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../../src/types/features.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,SAAS,CAAC,SAAS,SAAS,SAAS,GAAG,SAAS,IAAI;IAChE,IAAI,EAAE;QAAE,CAAC,EAAE,IAAI,CAAA;KAAE,CAAC;CAClB,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAInC,MAAM,WAAW,mBAAmB,CAAC,SAAS;CAAI;AAElD,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,SAAS,GAAG,SAAS,IAAI,MAAM,SAAS,CAAC,SAAS,CAAC,CAAC;AAE/F,MAAM,MAAM,qBAAqB,CAChC,SAAS,SAAS,SAAS,EAC3B,oBAAoB,SAAS,YAAY,EAAE,IACxC;KACF,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,eAAe,CAC1B,SAAS,SAAS,SAAS,EAC3B,oBAAoB,SAAS,YAAY,EAAE,EAC3C,uBAAuB,SAAS,qBAAqB,CACpD,SAAS,EACT,oBAAoB,CACpB,GAAG,qBAAqB,CAAC,SAAS,EAAE,oBAAoB,CAAC,IACvD,oBAAoB,CAAC,uBAAuB,CAAC,MAAM,uBAAuB,CAAC,CAAC,CAAC;AAEjF,MAAM,MAAM,gBAAgB,CAC3B,YAAY,SAAS,YAAY,EAAE,EACnC,qBAAqB,SAAS,YAAY,EAAE,IAE5C,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GACvE,YAAY,GACZ,YAAY,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type TState } from 'feature-state';
|
|
2
|
+
import { type TCollectErrorMode } from './form';
|
|
3
|
+
export type TFormField<GValue> = TState<GValue | undefined, ['base', 'form-field']>;
|
|
4
|
+
export interface TFormFieldStateFeature<GValue> {
|
|
5
|
+
_config: TFormFieldStateConfig;
|
|
6
|
+
_intialValue: GValue | undefined;
|
|
7
|
+
_validator: TFormFieldValidator<GValue>;
|
|
8
|
+
key: string;
|
|
9
|
+
isValid: boolean;
|
|
10
|
+
isTouched: boolean;
|
|
11
|
+
isSubmitted: boolean;
|
|
12
|
+
status: TFormFieldStatus;
|
|
13
|
+
validate: () => Promise<boolean>;
|
|
14
|
+
blur: () => void;
|
|
15
|
+
reset: () => void;
|
|
16
|
+
}
|
|
17
|
+
export interface TFormFieldStateConfig {
|
|
18
|
+
editable: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Validation strategy before submitting.
|
|
21
|
+
*/
|
|
22
|
+
validateMode: TFormFieldValidateMode;
|
|
23
|
+
/**
|
|
24
|
+
* Validation strategy after submitting.
|
|
25
|
+
*/
|
|
26
|
+
reValidateMode: TFormFieldReValidateMode;
|
|
27
|
+
collectErrorMode: TCollectErrorMode;
|
|
28
|
+
}
|
|
29
|
+
export type TFormFieldValidateMode = 'onBlur' | 'onChange' | 'onSubmit' | 'onTouched';
|
|
30
|
+
export type TFormFieldReValidateMode = 'onBlur' | 'onChange' | 'onSubmit';
|
|
31
|
+
export type TFormFieldStatus = TState<TFormFieldStatusValue, ['base', 'form-field-status']>;
|
|
32
|
+
export interface TFormFielStatusStateFeature {
|
|
33
|
+
registerError: (error: TInvalidFormFieldError) => void;
|
|
34
|
+
}
|
|
35
|
+
export type TFormFieldStatusValue = TInvalidFormFieldStatus | TValidFormFieldStatus | TUnvalidatedFormFieldStatus;
|
|
36
|
+
export interface TInvalidFormFieldStatus {
|
|
37
|
+
type: 'INVALID';
|
|
38
|
+
errors: TInvalidFormFieldError[];
|
|
39
|
+
}
|
|
40
|
+
export interface TValidFormFieldStatus {
|
|
41
|
+
type: 'VALID';
|
|
42
|
+
}
|
|
43
|
+
export interface TUnvalidatedFormFieldStatus {
|
|
44
|
+
type: 'UNVALIDATED';
|
|
45
|
+
}
|
|
46
|
+
export interface TInvalidFormFieldError {
|
|
47
|
+
code: string;
|
|
48
|
+
message?: string;
|
|
49
|
+
path?: string;
|
|
50
|
+
}
|
|
51
|
+
export type TValidateFormFieldFunction<GValue> = (formField: TFormField<GValue>) => Promise<void> | void;
|
|
52
|
+
export interface TFormFieldValidationLink<GValue> {
|
|
53
|
+
key: string;
|
|
54
|
+
validate: TValidateFormFieldFunction<GValue>;
|
|
55
|
+
}
|
|
56
|
+
export type TFormFieldValidationChain<GValue> = TFormFieldValidationLink<GValue>[];
|
|
57
|
+
export interface TFormFieldValidator<GValue> {
|
|
58
|
+
_validationChain: TFormFieldValidationChain<GValue>;
|
|
59
|
+
isValidating: boolean;
|
|
60
|
+
validate: (formField: TFormField<GValue>) => Promise<boolean>;
|
|
61
|
+
append: (validator: TFormFieldValidator<GValue>) => void;
|
|
62
|
+
clone: () => TFormFieldValidator<GValue>;
|
|
63
|
+
push: (...validateFunctions: TFormFieldValidationLink<GValue>[]) => void;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=form-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-field.d.ts","sourceRoot":"","sources":["../../../src/types/form-field.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type TFeatureKeys, type TSelectFeatures } from './features';
|
|
2
|
+
import { type TFormField, type TFormFieldValidator } from './form-field';
|
|
3
|
+
export type TForm<GFormData extends TFormData, GSelectedFeatureKeys extends TFeatureKeys[]> = {
|
|
4
|
+
_features: string[];
|
|
5
|
+
_config: TFormConfig<GFormData>;
|
|
6
|
+
fields: TFormFields<GFormData>;
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
isSubmitted: boolean;
|
|
9
|
+
_revalidate: (cached?: boolean) => Promise<boolean>;
|
|
10
|
+
submit: () => Promise<boolean>;
|
|
11
|
+
validate: () => Promise<boolean>;
|
|
12
|
+
getField: <GKey extends keyof TFormFields<GFormData>>(key: GKey) => TFormFields<GFormData>[GKey];
|
|
13
|
+
reset: () => void;
|
|
14
|
+
} & TSelectFeatures<GFormData, GSelectedFeatureKeys>;
|
|
15
|
+
export type TFormFields<GFormData extends TFormData> = {
|
|
16
|
+
[Key in keyof GFormData]: TFormField<GFormData[Key]>;
|
|
17
|
+
};
|
|
18
|
+
export type TFormValidators<GFormData extends TFormData> = {
|
|
19
|
+
[Key in keyof GFormData]: TFormFieldValidator<GFormData[Key]>;
|
|
20
|
+
};
|
|
21
|
+
export type TFormData = Record<string, unknown>;
|
|
22
|
+
export interface TFormConfig<GFormData extends TFormData> {
|
|
23
|
+
/**
|
|
24
|
+
* Indicates if the form is disabled.
|
|
25
|
+
*/
|
|
26
|
+
disabled: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Error collection mode. 'firstError' gathers only the first error per field, 'all' gathers all errors.
|
|
29
|
+
*/
|
|
30
|
+
collectErrorMode: TCollectErrorMode;
|
|
31
|
+
/**
|
|
32
|
+
* Called once form is submitted
|
|
33
|
+
*/
|
|
34
|
+
onSubmit: ((data: GFormData) => void) | null;
|
|
35
|
+
}
|
|
36
|
+
export type TCollectErrorMode = 'firstError' | 'all';
|
|
37
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/types/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAKzE,MAAM,MAAM,KAAK,CAAC,SAAS,SAAS,SAAS,EAAE,oBAAoB,SAAS,YAAY,EAAE,IAAI;IAC7F,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,EAAE,CAAC,IAAI,SAAS,MAAM,WAAW,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,KAAK,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;IACjG,KAAK,EAAE,MAAM,IAAI,CAAC;CAClB,GAAG,eAAe,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAErD,MAAM,MAAM,WAAW,CAAC,SAAS,SAAS,SAAS,IAAI;KACrD,GAAG,IAAI,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,SAAS,SAAS,SAAS,IAAI;KACzD,GAAG,IAAI,MAAM,SAAS,GAAG,mBAAmB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;CAC7D,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD,MAAM,WAAW,WAAW,CAAC,SAAS,SAAS,SAAS;IACvD;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,gBAAgB,EAAE,iBAAiB,CAAC;IACpC;;OAEG;IACH,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "feature-form",
|
|
3
|
+
"description": "Straightforward, typesafe, and feature-based form library for ReactJs",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"private": false,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "shx rm -rf dist && ../../scripts/cli.sh bundle",
|
|
8
|
+
"start:dev": "tsc -w",
|
|
9
|
+
"lint": "eslint --ext .js,.ts src/",
|
|
10
|
+
"clean": "shx rm -rf dist && shx rm -rf node_modules && shx rm -rf .turbo",
|
|
11
|
+
"install:clean": "pnpm run clean && pnpm install",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"update:latest": "pnpm update --latest",
|
|
14
|
+
"size": "size-limit --why"
|
|
15
|
+
},
|
|
16
|
+
"source": "./src/index.ts",
|
|
17
|
+
"main": "./dist/cjs/index.js",
|
|
18
|
+
"module": "./dist/esm/index.js",
|
|
19
|
+
"types": "./dist/types/index.d.ts",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/inbeta-group/monorepo.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [],
|
|
25
|
+
"author": "@bennoinbeta",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/inbeta-group/monorepo/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://inbeta.group/?source=github",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@ibg/utils": "workspace:*",
|
|
33
|
+
"feature-state": "workspace:*"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@ibg/config": "workspace:*",
|
|
37
|
+
"@types/node": "^20.14.1",
|
|
38
|
+
"valibot": "^0.32.0",
|
|
39
|
+
"yup": "^1.4.0",
|
|
40
|
+
"zod": "^3.23.8"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"README.md"
|
|
45
|
+
],
|
|
46
|
+
"size-limit": [
|
|
47
|
+
{
|
|
48
|
+
"path": "dist/esm/index.js"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|