@tanstack/react-form 0.0.7 → 0.0.8

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.
Files changed (37) hide show
  1. package/build/cjs/createFormFactory.js +2 -3
  2. package/build/cjs/createFormFactory.js.map +1 -1
  3. package/build/cjs/formContext.js.map +1 -1
  4. package/build/cjs/index.js +1 -2
  5. package/build/cjs/index.js.map +1 -1
  6. package/build/cjs/useField.js +46 -11
  7. package/build/cjs/useField.js.map +1 -1
  8. package/build/cjs/useForm.js +6 -4
  9. package/build/cjs/useForm.js.map +1 -1
  10. package/build/esm/index.js +47 -22
  11. package/build/esm/index.js.map +1 -1
  12. package/build/stats-html.html +1 -1
  13. package/build/stats-react.json +97 -153
  14. package/build/types/form-core/src/FieldApi.d.ts +2 -1
  15. package/build/types/form-core/src/FormApi.d.ts +2 -2
  16. package/build/types/form-core/src/utils.d.ts +7 -1
  17. package/build/types/index.d.ts +30 -22
  18. package/build/types/react-form/src/createFormFactory.d.ts +2 -3
  19. package/build/types/react-form/src/formContext.d.ts +8 -2
  20. package/build/types/react-form/src/index.d.ts +2 -4
  21. package/build/types/react-form/src/useField.d.ts +23 -8
  22. package/build/types/react-form/src/useForm.d.ts +2 -3
  23. package/build/umd/index.development.js +61 -32
  24. package/build/umd/index.development.js.map +1 -1
  25. package/build/umd/index.production.js +2 -2
  26. package/build/umd/index.production.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/createFormFactory.ts +4 -5
  29. package/src/formContext.ts +4 -1
  30. package/src/index.ts +2 -5
  31. package/src/useField.tsx +138 -0
  32. package/src/useForm.tsx +7 -6
  33. package/build/cjs/Field.js +0 -54
  34. package/build/cjs/Field.js.map +0 -1
  35. package/build/types/react-form/src/Field.d.ts +0 -9
  36. package/src/Field.tsx +0 -36
  37. package/src/useField.ts +0 -50
@@ -29,7 +29,7 @@ class l{listeners=new Set;batching=!1;queue=[];constructor(t,e){this.state=t,thi
29
29
  * LICENSE.md file in the root directory of this source tree.
30
30
  *
31
31
  * @license MIT
32
- */function r(t,e){return"function"==typeof t?t(e):t}function u(t,e,i){const s=g(e);return function t(e){if(!s.length)return r(i,e);const a=s.shift();if("string"==typeof a)return"object"==typeof e?{...e,[a]:t(e[a])}:{[a]:t()};if("number"==typeof a){if(Array.isArray(e)){const i=e.slice(0,a);return[...i.length?i:new Array(a),t(e[a]),...e.slice(a+1)]}return[...new Array(a),t()]}throw new Error("Uh oh!")}(t)}const h=/^(\d*)$/gm,d=/\.(\d*)\./gm,c=/^(\d*)\./gm,f=/\.(\d*$)/gm,m=/\.{2,}/gm,v="__int__",p="__int__$1";function g(t){if("string"!=typeof t)throw new Error;return t.replace("[",".").replace("]","").replace(h,p).replace(d,".__int__$1.").replace(c,"__int__$1.").replace(f,".__int__$1").replace(m,".").split(".").map((t=>0===t.indexOf(v)?parseInt(t.substring(v.length),10):t))}function b(t){return{values:{},fieldMeta:{},canSubmit:!0,isFieldsValid:!1,isFieldsValidating:!1,isFormValid:!1,isFormValidating:!1,isSubmitted:!1,isSubmitting:!1,isTouched:!1,isValid:!1,isValidating:!1,submissionAttempts:0,formValidationCount:0,...t}}class V{constructor(t){var e,i;this.options={},this.fieldInfo={},this.validationMeta={},this.update=t=>{this.store.batch((()=>{t.defaultState&&t.defaultState!==this.options.defaultState&&this.store.setState((e=>({...e,...t.defaultState}))),t.defaultValues!==this.options.defaultValues&&this.store.setState((e=>({...e,values:t.defaultValues})))})),this.options=t},this.reset=()=>this.store.setState((()=>b(this.options.defaultValues))),this.validateAllFields=async()=>{const t=[];return this.store.batch((()=>{Object.values(this.fieldInfo).forEach((e=>{Object.values(e.instances).forEach((e=>{e.state.meta.isTouched||(e.setMeta((t=>({...t,isTouched:!0}))),e.options.validate&&t.push(e.validate()))}))}))})),Promise.all(t)},this.validateForm=async()=>{const{validate:t}=this.options;if(!t)return;this.store.setState((t=>({...t,isValidating:!0,formValidationCount:t.formValidationCount+1})));const e=this.state.formValidationCount,i=()=>e===this.state.formValidationCount;this.validationMeta.validationPromise||(this.validationMeta.validationPromise=new Promise(((t,e)=>{this.validationMeta.validationResolve=t,this.validationMeta.validationReject=e})));return(async()=>{try{const a=await t(this.state.values,this);var e,s;if(i())this.store.setState((t=>({...t,isValidating:!1,error:a?"string"==typeof a?a:"Invalid Form Values":null}))),null==(e=(s=this.validationMeta).validationResolve)||e.call(s,a)}catch(t){var a,n;if(i())null==(a=(n=this.validationMeta).validationReject)||a.call(n,t)}finally{delete this.validationMeta.validationPromise}})(),this.validationMeta.validationPromise},this.handleSubmit=async t=>{if(t.preventDefault(),t.stopPropagation(),this.store.setState((t=>({...t,isSubmitted:!1,submissionAttempts:t.submissionAttempts+1}))),!this.state.canSubmit)return;this.store.setState((t=>({...t,isSubmitting:!0})));const e=()=>{this.store.setState((t=>({...t,isSubmitting:!1})))};var i,s,a,n;if(await this.validateAllFields(),!this.state.isFieldsValid)return e(),void(null==(i=(s=this.options).onInvalidSubmit)||i.call(s,this.state.values,this));if(await this.validateForm(),!this.state.isValid)return e(),void(null==(a=(n=this.options).onInvalidSubmit)||a.call(n,this.state.values,this));try{var o,l;await(null==(o=(l=this.options).onSubmit)?void 0:o.call(l,this.state.values,this)),this.store.batch((()=>{this.store.setState((t=>({...t,isSubmitted:!0}))),e()}))}catch(t){throw e(),t}},this.getFieldValue=t=>{return e=this.state.values,g(t).reduce(((t,e)=>{if(void 0!==t)return t[e]}),e);var e},this.getFieldMeta=t=>this.state.fieldMeta[t],this.getFieldInfo=t=>{var e;return(e=this.fieldInfo)[t]||(e[t]={instances:{}})},this.setFieldMeta=(t,e)=>{this.store.setState((i=>({...i,fieldMeta:{...i.fieldMeta,[t]:r(e,i.fieldMeta[t])}})))},this.setFieldValue=(t,e,i)=>{var s;const a=null==(s=null==i?void 0:i.touch)||s;this.store.batch((()=>{this.store.setState((i=>({...i,values:u(i.values,t,e)}))),a&&this.setFieldMeta(t,(t=>({...t,isTouched:!0})))}))},this.pushFieldValue=(t,e,i)=>this.setFieldValue(t,(t=>[...Array.isArray(t)?t:[],e]),i),this.insertFieldValue=(t,e,i,s)=>{this.setFieldValue(t,(t=>t.map(((t,s)=>s===e?i:t))),s)},this.spliceFieldValue=(t,e,i)=>{this.setFieldValue(t,(t=>t.filter(((t,i)=>i!==e))),i)},this.swapFieldValues=(t,e,i)=>{this.setFieldValue(t,(t=>{const s=t[e],a=t[i];return u(u(t,[e],a),[i],s)}))},this.store=new l(b({...null==t?void 0:t.defaultState,values:null!=(e=null==t?void 0:t.defaultValues)?e:null==t||null==(i=t.defaultState)?void 0:i.values,isFormValid:!(null!=t&&t.validate)}),{onUpdate:t=>{const e=Object.values(t.fieldMeta),i=e.some((t=>null==t?void 0:t.isValidating)),s=!e.some((t=>null==t?void 0:t.error)),a=e.some((t=>null==t?void 0:t.isTouched)),n=i||t.isFormValidating,o=!t.formError,l=s&&o,r=0===t.submissionAttempts&&!a||!n&&!t.isSubmitting&&l;t={...t,isFieldsValidating:i,isFieldsValid:s,isFormValid:o,isValid:l,canSubmit:r,isTouched:a},this.store.state=t,this.state=t}}),this.state=this.store.state,this.update(t||{})}}var y=0;function F(t){return"__private_"+y+++"_"+t}function S(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}let w=0;var M=F("updateStore"),O=F("leaseValidateAsync");class j{constructor(t){var e;this.options={},this.mount=()=>{const t=this.getInfo();t.instances[this.uid]=this;const e=this.form.store.subscribe((()=>{S(this,M)[M]()}));return()=>{e(),delete t.instances[this.uid],Object.keys(t.instances).length||delete this.form.fieldInfo[this.name]}},Object.defineProperty(this,M,{writable:!0,value:()=>{this.store.batch((()=>{const t=this.getValue(),e=this.getMeta();t!==this.state.value&&this.store.setState((e=>({...e,value:t}))),e!==this.state.meta&&this.store.setState((t=>({...t,meta:e})))}))}}),this.update=t=>{var e,i,s,a;this.options={validatePristine:null!=(e=this.form.options.defaultValidatePristine)&&e,validateOn:null!=(i=this.form.options.defaultValidateOn)?i:"change",validateAsyncOn:null!=(s=this.form.options.defaultValidateAsyncOn)?s:"blur",validateAsyncDebounceMs:null!=(a=this.form.options.defaultValidateAsyncDebounceMs)?a:0,...t},void 0===this.state.value&&void 0!==this.options.defaultValue&&this.setValue(this.options.defaultValue),void 0===this.getMeta()&&this.setMeta(this.state.meta)},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(t,e)=>this.form.setFieldValue(this.name,t,e),this.getMeta=()=>this.form.getFieldMeta(this.name),this.setMeta=t=>this.form.setFieldMeta(this.name,t),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=t=>this.form.pushFieldValue(this.name,t),this.insertValue=(t,e)=>this.form.insertFieldValue(this.name,t,e),this.removeValue=t=>this.form.spliceFieldValue(this.name,t),this.swapValues=(t,e)=>this.form.swapFieldValues(this.name,t,e),this.getSubField=t=>new j({name:this.name+"."+t,form:this.form}),this.validateSync=async(t=this.state.value)=>{const{validate:e}=this.options;if(!e)return;const i=(this.getInfo().validationCount||0)+1;this.getInfo().validationCount=i;const s=P(e(t,this));this.state.meta.error!==s&&this.setMeta((t=>({...t,error:s}))),this.state.meta.error&&this.cancelValidateAsync()},Object.defineProperty(this,O,{writable:!0,value:()=>{const t=(this.getInfo().validationAsyncCount||0)+1;return this.getInfo().validationAsyncCount=t,t}}),this.cancelValidateAsync=()=>{S(this,O)[O](),this.setMeta((t=>({...t,isValidating:!1})))},this.validateAsync=async(t=this.state.value)=>{const{validateAsync:e,validateAsyncDebounceMs:i}=this.options;if(!e)return;!0!==this.state.meta.isValidating&&this.setMeta((t=>({...t,isValidating:!0})));const s=S(this,O)[O](),a=()=>s===this.getInfo().validationAsyncCount;if(this.getInfo().validationPromise||(this.getInfo().validationPromise=new Promise(((t,e)=>{this.getInfo().validationResolve=t,this.getInfo().validationReject=e}))),i>0&&await new Promise((t=>setTimeout(t,i))),a())try{const i=await e(t,this);if(a()){var n,o;const t=P(i);this.setMeta((e=>({...e,isValidating:!1,error:t}))),null==(n=(o=this.getInfo()).validationResolve)||n.call(o,t)}}catch(t){var l,r;if(a())throw null==(l=(r=this.getInfo()).validationReject)||l.call(r,t),t}finally{a()&&(this.setMeta((t=>({...t,isValidating:!1}))),delete this.getInfo().validationPromise)}return this.getInfo().validationPromise},this.shouldValidate=(t,e)=>{const{validateOn:i,validateAsyncOn:s}=this.options,a=function(t){return t?A[t]:3}(e);return Object.keys(A).some((e=>t?s:i===e&&a>=A[e]))},this.validate=async(t,e)=>{if(this.options.validatePristine||this.state.meta.isTouched)return this.shouldValidate(!1,t)&&this.validateSync(e),this.state.meta.error?this.state.meta.error:this.shouldValidate(!0,t)?this.validateAsync(e):void 0},this.getChangeProps=(t={})=>({...t,value:this.state.value,onChange:e=>{this.setValue(e),null==t.onChange||t.onChange(e)},onBlur:e=>{this.setMeta((t=>({...t,isTouched:!0}))),this.validate("blur"),null==t.onBlur||t.onBlur(e)}}),this.getInputProps=(t={})=>({...t,value:String(this.state.value),onChange:e=>{this.setValue(e.target.value),null==t.onChange||t.onChange(e.target.value)},onBlur:this.getChangeProps(t).onBlur}),this.form=t.form,this.uid=w++;let i="";this.form.fieldName&&(i=this.form.fieldName+"."),this.name=i+t.name,this.store=new l({value:this.getValue(),meta:null!=(e=this.getMeta())?e:{isValidating:!1,isTouched:!1,...this.options.defaultMeta}},{onUpdate:t=>{t.meta.touchedError=t.meta.isTouched?t.meta.error:void 0;const e=this.state;this.state=t,t.value!==e.value&&this.validate("change",t.value)}}),this.state=this.store.state,this.update(t)}}const A={change:0,blur:1,submit:2};function P(t){if(t)return"string"!=typeof t?"Invalid Form Values":t}function I(){return I=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},I.apply(this,arguments)}
32
+ */function r(t,e){return"function"==typeof t?t(e):t}function u(t,e,i){const s=g(e);return function t(e){if(!s.length)return r(i,e);const a=s.shift();if("string"==typeof a)return"object"==typeof e?{...e,[a]:t(e[a])}:{[a]:t()};if("number"==typeof a){if(Array.isArray(e)){const i=e.slice(0,a);return[...i.length?i:new Array(a),t(e[a]),...e.slice(a+1)]}return[...new Array(a),t()]}throw new Error("Uh oh!")}(t)}const h=/^(\d*)$/gm,d=/\.(\d*)\./gm,c=/^(\d*)\./gm,f=/\.(\d*$)/gm,m=/\.{2,}/gm,v="__int__",p="__int__$1";function g(t){if("string"!=typeof t)throw new Error;return t.replace("[",".").replace("]","").replace(h,p).replace(d,".__int__$1.").replace(c,"__int__$1.").replace(f,".__int__$1").replace(m,".").split(".").map((t=>0===t.indexOf(v)?parseInt(t.substring(v.length),10):t))}function b(t){return{values:{},fieldMeta:{},canSubmit:!0,isFieldsValid:!1,isFieldsValidating:!1,isFormValid:!1,isFormValidating:!1,isSubmitted:!1,isSubmitting:!1,isTouched:!1,isValid:!1,isValidating:!1,submissionAttempts:0,formValidationCount:0,...t}}class y{constructor(t){var e,i;this.options={},this.fieldInfo={},this.validationMeta={},this.update=t=>{t&&(this.store.batch((()=>{t.defaultState&&t.defaultState!==this.options.defaultState&&this.store.setState((e=>({...e,...t.defaultState}))),t.defaultValues!==this.options.defaultValues&&this.store.setState((e=>({...e,values:t.defaultValues})))})),this.options=t)},this.reset=()=>this.store.setState((()=>b(this.options.defaultValues))),this.validateAllFields=async()=>{const t=[];return this.store.batch((()=>{Object.values(this.fieldInfo).forEach((e=>{Object.values(e.instances).forEach((e=>{e.state.meta.isTouched||(e.setMeta((t=>({...t,isTouched:!0}))),e.options.validate&&t.push(e.validate()))}))}))})),Promise.all(t)},this.validateForm=async()=>{const{validate:t}=this.options;if(!t)return;this.store.setState((t=>({...t,isValidating:!0,formValidationCount:t.formValidationCount+1})));const e=this.state.formValidationCount,i=()=>e===this.state.formValidationCount;this.validationMeta.validationPromise||(this.validationMeta.validationPromise=new Promise(((t,e)=>{this.validationMeta.validationResolve=t,this.validationMeta.validationReject=e})));return(async()=>{try{const a=await t(this.state.values,this);var e,s;if(i())this.store.setState((t=>({...t,isValidating:!1,error:a?"string"==typeof a?a:"Invalid Form Values":null}))),null==(e=(s=this.validationMeta).validationResolve)||e.call(s,a)}catch(t){var a,n;if(i())null==(a=(n=this.validationMeta).validationReject)||a.call(n,t)}finally{delete this.validationMeta.validationPromise}})(),this.validationMeta.validationPromise},this.handleSubmit=async t=>{if(t.preventDefault(),t.stopPropagation(),this.store.setState((t=>({...t,isSubmitted:!1,submissionAttempts:t.submissionAttempts+1}))),!this.state.canSubmit)return;this.store.setState((t=>({...t,isSubmitting:!0})));const e=()=>{this.store.setState((t=>({...t,isSubmitting:!1})))};var i,s,a,n;if(await this.validateAllFields(),!this.state.isFieldsValid)return e(),void(null==(i=(s=this.options).onInvalidSubmit)||i.call(s,this.state.values,this));if(await this.validateForm(),!this.state.isValid)return e(),void(null==(a=(n=this.options).onInvalidSubmit)||a.call(n,this.state.values,this));try{var o,l;await(null==(o=(l=this.options).onSubmit)?void 0:o.call(l,this.state.values,this)),this.store.batch((()=>{this.store.setState((t=>({...t,isSubmitted:!0}))),e()}))}catch(t){throw e(),t}},this.getFieldValue=t=>{return e=this.state.values,g(t).reduce(((t,e)=>{if(void 0!==t)return t[e]}),e);var e},this.getFieldMeta=t=>this.state.fieldMeta[t],this.getFieldInfo=t=>{var e;return(e=this.fieldInfo)[t]||(e[t]={instances:{}})},this.setFieldMeta=(t,e)=>{this.store.setState((i=>({...i,fieldMeta:{...i.fieldMeta,[t]:r(e,i.fieldMeta[t])}})))},this.setFieldValue=(t,e,i)=>{var s;const a=null==(s=null==i?void 0:i.touch)||s;this.store.batch((()=>{this.store.setState((i=>({...i,values:u(i.values,t,e)}))),a&&this.setFieldMeta(t,(t=>({...t,isTouched:!0})))}))},this.pushFieldValue=(t,e,i)=>this.setFieldValue(t,(t=>[...Array.isArray(t)?t:[],e]),i),this.insertFieldValue=(t,e,i,s)=>{this.setFieldValue(t,(t=>t.map(((t,s)=>s===e?i:t))),s)},this.removeFieldValue=(t,e,i)=>{this.setFieldValue(t,(t=>t.filter(((t,i)=>i!==e))),i)},this.swapFieldValues=(t,e,i)=>{this.setFieldValue(t,(t=>{const s=t[e],a=t[i];return u(u(t,[e],a),[i],s)}))},this.store=new l(b({...null==t?void 0:t.defaultState,values:null!=(e=null==t?void 0:t.defaultValues)?e:null==t||null==(i=t.defaultState)?void 0:i.values,isFormValid:!(null!=t&&t.validate)}),{onUpdate:t=>{const e=Object.values(t.fieldMeta),i=e.some((t=>null==t?void 0:t.isValidating)),s=!e.some((t=>null==t?void 0:t.error)),a=e.some((t=>null==t?void 0:t.isTouched)),n=i||t.isFormValidating,o=!t.formError,l=s&&o,r=0===t.submissionAttempts&&!a||!n&&!t.isSubmitting&&l;t={...t,isFieldsValidating:i,isFieldsValid:s,isFormValid:o,isValid:l,canSubmit:r,isTouched:a},this.store.state=t,this.state=t,console.log(this.state)}}),this.state=this.store.state,this.update(t||{})}}var V=0;function F(t){return"__private_"+V+++"_"+t}function S(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}let w=0;var M=F("updateStore"),O=F("leaseValidateAsync");class j{constructor(t){var e;this.options={},this.mount=()=>{const t=this.getInfo();t.instances[this.uid]=this;const e=this.form.store.subscribe((()=>{S(this,M)[M]()}));return()=>{e(),delete t.instances[this.uid],Object.keys(t.instances).length||delete this.form.fieldInfo[this.name]}},Object.defineProperty(this,M,{writable:!0,value:()=>{this.store.batch((()=>{const t=this.getValue(),e=this.getMeta();t!==this.state.value&&this.store.setState((e=>({...e,value:t}))),e!==this.state.meta&&this.store.setState((t=>({...t,meta:e})))}))}}),this.update=t=>{var e,i,s,a;this.options={validatePristine:null!=(e=this.form.options.defaultValidatePristine)&&e,validateOn:null!=(i=this.form.options.defaultValidateOn)?i:"change",validateAsyncOn:null!=(s=this.form.options.defaultValidateAsyncOn)?s:"blur",validateAsyncDebounceMs:null!=(a=this.form.options.defaultValidateAsyncDebounceMs)?a:0,...t},void 0===this.state.value&&void 0!==this.options.defaultValue&&this.setValue(this.options.defaultValue),void 0===this.getMeta()&&this.setMeta(this.state.meta)},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(t,e)=>this.form.setFieldValue(this.name,t,e),this.getMeta=()=>this.form.getFieldMeta(this.name),this.setMeta=t=>this.form.setFieldMeta(this.name,t),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=t=>this.form.pushFieldValue(this.name,t),this.insertValue=(t,e)=>this.form.insertFieldValue(this.name,t,e),this.removeValue=t=>this.form.removeFieldValue(this.name,t),this.swapValues=(t,e)=>this.form.swapFieldValues(this.name,t,e),this.getSubField=t=>new j({name:this.name+"."+t,form:this.form}),this.validateSync=async(t=this.state.value)=>{const{validate:e}=this.options;if(!e)return;const i=(this.getInfo().validationCount||0)+1;this.getInfo().validationCount=i;const s=P(e(t,this));this.state.meta.error!==s&&this.setMeta((t=>({...t,error:s}))),this.state.meta.error&&this.cancelValidateAsync()},Object.defineProperty(this,O,{writable:!0,value:()=>{const t=(this.getInfo().validationAsyncCount||0)+1;return this.getInfo().validationAsyncCount=t,t}}),this.cancelValidateAsync=()=>{S(this,O)[O](),this.setMeta((t=>({...t,isValidating:!1})))},this.validateAsync=async(t=this.state.value)=>{const{validateAsync:e,validateAsyncDebounceMs:i}=this.options;if(!e)return;!0!==this.state.meta.isValidating&&this.setMeta((t=>({...t,isValidating:!0})));const s=S(this,O)[O](),a=()=>s===this.getInfo().validationAsyncCount;if(this.getInfo().validationPromise||(this.getInfo().validationPromise=new Promise(((t,e)=>{this.getInfo().validationResolve=t,this.getInfo().validationReject=e}))),i>0&&await new Promise((t=>setTimeout(t,i))),a())try{const i=await e(t,this);if(a()){var n,o;const t=P(i);this.setMeta((e=>({...e,isValidating:!1,error:t}))),null==(n=(o=this.getInfo()).validationResolve)||n.call(o,t)}}catch(t){var l,r;if(a())throw null==(l=(r=this.getInfo()).validationReject)||l.call(r,t),t}finally{a()&&(this.setMeta((t=>({...t,isValidating:!1}))),delete this.getInfo().validationPromise)}return this.getInfo().validationPromise},this.shouldValidate=(t,e)=>{const{validateOn:i,validateAsyncOn:s}=this.options,a=function(t){return t?A[t]:3}(e);return Object.keys(A).some((e=>t?s:i===e&&a>=A[e]))},this.validate=async(t,e)=>{if(this.options.validatePristine||this.state.meta.isTouched)return this.shouldValidate(!1,t)&&this.validateSync(e),this.state.meta.error?this.state.meta.error:this.shouldValidate(!0,t)?this.validateAsync(e):void 0},this.getChangeProps=(t={})=>({...t,value:this.state.value,onChange:e=>{this.setValue(e),null==t.onChange||t.onChange(e)},onBlur:e=>{this.setMeta((t=>({...t,isTouched:!0}))),this.validate("blur"),null==t.onBlur||t.onBlur(e)}}),this.getInputProps=(t={})=>({...t,value:String(this.state.value),onChange:e=>{this.setValue(e.target.value),null==t.onChange||t.onChange(e.target.value)},onBlur:this.getChangeProps(t).onBlur}),this.form=t.form,this.uid=w++,this.name=t.name,this.store=new l({value:this.getValue(),meta:null!=(e=this.getMeta())?e:{isValidating:!1,isTouched:!1,...this.options.defaultMeta}},{onUpdate:t=>{t.meta.touchedError=t.meta.isTouched?t.meta.error:void 0;const e=this.state;this.state=t,t.value!==e.value&&this.validate("change",t.value),console.log(this)}}),this.state=this.store.state,this.update(t)}}const A={change:0,blur:1,submit:2};function P(t){if(t)return"string"!=typeof t?"Invalid Form Values":t}function I(){return I=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},I.apply(this,arguments)}
33
33
  /**
34
34
  * react-store
35
35
  *
@@ -39,5 +39,5 @@ class l{listeners=new Set;batching=!1;queue=[];constructor(t,e){this.state=t,thi
39
39
  * LICENSE.md file in the root directory of this source tree.
40
40
  *
41
41
  * @license MIT
42
- */function _(t,i=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),i,C)}function C(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const i=Object.keys(t);if(i.length!==Object.keys(e).length)return!1;for(let s=0;s<i.length;s++)if(!Object.prototype.hasOwnProperty.call(e,i[s])||!Object.is(t[i[s]],e[i[s]]))return!1;return!0}const E=n.createContext(null);function T(){return t=>R(t)}function R(t){const e=function(){const t=n.useContext(E);if(!t)throw new Error("You are trying to use the form API outside of a form!");return t}(),[i]=n.useState((()=>new j({...t,form:e})));return i.update({...t,form:e}),_(i.store),n.useEffect((()=>i.mount()),[i]),i}function x(){return t=>n.createElement(q,t)}function q({children:t,...e}){return r(t,R(e))}function $(t){const[e]=o.default.useState((()=>{const e=new V(t);return e.Form=function(t){return({children:e,noFormElement:i,...s})=>{const a=t.useStore((t=>t.isSubmitting));return o.default.createElement(E.Provider,{value:t},i?e:o.default.createElement("form",I({onSubmit:t.handleSubmit,disabled:a},s),e))}}(e),e.Field=x(),e.useField=T(),e.useStore=t=>_(e.store,t),e.Subscribe=t=>r(t.children,_(e.store,t.selector)),e}));return e}t.Field=q,t.FieldApi=j,t.FormApi=V,t.createFormFactory=function(t){return{useForm:e=>$({...t,...e}),useField:T(),Field:x()}},t.functionalUpdate=r,t.useField=R,t.useForm=$,Object.defineProperty(t,"__esModule",{value:!0})}));
42
+ */function _(t,i=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),i,C)}function C(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const i=Object.keys(t);if(i.length!==Object.keys(e).length)return!1;for(let s=0;s<i.length;s++)if(!Object.prototype.hasOwnProperty.call(e,i[s])||!Object.is(t[i[s]],e[i[s]]))return!1;return!0}const E=n.createContext(null);function T(t){const{formApi:e,parentFieldName:i}=function(){const t=n.useContext(E);if(!t)throw new Error("You are trying to use the form API outside of a form!");return t}(),[s]=n.useState((()=>{const s=("number"==typeof t.index?[i,t.index,t.name]:[i,t.name]).filter((t=>void 0!==t)).join("."),a=new j({...t,form:e,name:s});return a.Field=x,a}));return s.update({...t,form:e}),_(s.store,"array"===t.mode?t=>[t.meta,Object.keys(t.value||[]).length]:void 0),n.useEffect((()=>s.mount()),[s]),s}function x({children:t,...e}){const i=T(e);return n.createElement(E.Provider,{value:{formApi:i.form,parentFieldName:i.name},children:r(t,i)})}function R(t){const[e]=o.default.useState((()=>{const e=new y(t);return e.Form=function(t){return({children:e,noFormElement:i,...s})=>{const a=t.useStore((t=>t.isSubmitting));return o.default.createElement(E.Provider,{value:{formApi:t}},i?e:o.default.createElement("form",I({onSubmit:t.handleSubmit,disabled:a},s),e))}}(e),e.Field=x,e.useField=T,e.useStore=t=>_(e.store,t),e.Subscribe=t=>r(t.children,_(e.store,t.selector)),e}));return e.update(t),e}t.Field=x,t.FieldApi=j,t.FormApi=y,t.createFormFactory=function(t){return{useForm:e=>R({...t,...e}),useField:T,Field:x}},t.functionalUpdate=r,t.useField=T,t.useForm=R,Object.defineProperty(t,"__esModule",{value:!0})}));
43
43
  //# sourceMappingURL=index.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.production.js","sources":["../../../../node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js","../../../form-core/build/esm/index.js","../../../../node_modules/.pnpm/@tanstack+react-store@0.0.1-beta.84_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/esm/index.js","../../src/formContext.ts","../../src/useField.ts","../../src/Field.tsx","../../src/useForm.tsx","../../src/createFormFactory.ts"],"sourcesContent":["/**\n * store\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nclass Store {\n listeners = new Set();\n batching = false;\n queue = [];\n constructor(initialState, options) {\n this.state = initialState;\n this.options = options;\n }\n subscribe = listener => {\n this.listeners.add(listener);\n const unsub = this.options?.onSubscribe?.(listener, this);\n return () => {\n this.listeners.delete(listener);\n unsub?.();\n };\n };\n setState = updater => {\n const previous = this.state;\n this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);\n if (this.state === previous) return;\n this.options?.onUpdate?.(this.state, previous);\n this.queue.push(() => {\n this.listeners.forEach(listener => listener(this.state, previous));\n });\n this.#flush();\n };\n #flush = () => {\n if (this.batching) return;\n this.queue.forEach(cb => cb());\n this.queue = [];\n };\n batch = cb => {\n this.batching = true;\n cb();\n this.batching = false;\n this.#flush();\n };\n}\n\nexport { Store };\n//# sourceMappingURL=index.js.map\n","/**\n * form-core\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nimport { Store } from '@tanstack/store';\n\nfunction functionalUpdate(updater, input) {\n return typeof updater === 'function' ? updater(input) : updater;\n}\nfunction getBy(obj, path) {\n const pathArray = makePathArray(path);\n const pathObj = pathArray;\n return pathObj.reduce((current, pathPart) => {\n if (typeof current !== 'undefined') {\n return current[pathPart];\n }\n\n return undefined;\n }, obj);\n}\nfunction setBy(obj, _path, updater) {\n const path = makePathArray(_path);\n\n function doSet(parent) {\n if (!path.length) {\n return functionalUpdate(updater, parent);\n }\n\n const key = path.shift();\n\n if (typeof key === 'string') {\n if (typeof parent === 'object') {\n return { ...parent,\n [key]: doSet(parent[key])\n };\n }\n\n return {\n [key]: doSet()\n };\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n const prefix = parent.slice(0, key);\n return [...(prefix.length ? prefix : new Array(key)), doSet(parent[key]), ...parent.slice(key + 1)];\n }\n\n return [...new Array(key), doSet()];\n }\n\n throw new Error('Uh oh!');\n }\n\n return doSet(obj);\n}\nconst reFindNumbers0 = /^(\\d*)$/gm;\nconst reFindNumbers1 = /\\.(\\d*)\\./gm;\nconst reFindNumbers2 = /^(\\d*)\\./gm;\nconst reFindNumbers3 = /\\.(\\d*$)/gm;\nconst reFindMultiplePeriods = /\\.{2,}/gm;\nconst intPrefix = '__int__';\nconst intReplace = intPrefix + \"$1\";\n\nfunction makePathArray(str) {\n if (typeof str !== 'string') {\n throw new Error();\n }\n\n return str.replace('[', '.').replace(']', '').replace(reFindNumbers0, intReplace).replace(reFindNumbers1, \".\" + intReplace + \".\").replace(reFindNumbers2, intReplace + \".\").replace(reFindNumbers3, \".\" + intReplace).replace(reFindMultiplePeriods, '.').split('.').map(d => {\n if (d.indexOf(intPrefix) === 0) {\n return parseInt(d.substring(intPrefix.length), 10);\n }\n\n return d;\n });\n}\n\nfunction getDefaultFormState(defaultState) {\n return {\n values: {},\n fieldMeta: {},\n canSubmit: true,\n isFieldsValid: false,\n isFieldsValidating: false,\n isFormValid: false,\n isFormValidating: false,\n isSubmitted: false,\n isSubmitting: false,\n isTouched: false,\n isValid: false,\n isValidating: false,\n submissionAttempts: 0,\n formValidationCount: 0,\n ...defaultState\n };\n}\n\nclass FormApi {\n // // This carries the context for nested fields\n constructor(_opts) {\n var _opts$defaultValues, _opts$defaultState;\n\n this.options = {};\n this.fieldInfo = {};\n this.validationMeta = {};\n\n this.update = options => {\n this.store.batch(() => {\n if (options.defaultState && options.defaultState !== this.options.defaultState) {\n this.store.setState(prev => ({ ...prev,\n ...options.defaultState\n }));\n }\n\n if (options.defaultValues !== this.options.defaultValues) {\n this.store.setState(prev => ({ ...prev,\n values: options.defaultValues\n }));\n }\n });\n this.options = options;\n };\n\n this.reset = () => this.store.setState(() => getDefaultFormState(this.options.defaultValues));\n\n this.validateAllFields = async () => {\n const fieldValidationPromises = [];\n this.store.batch(() => {\n void Object.values(this.fieldInfo).forEach(field => {\n Object.values(field.instances).forEach(instance => {\n // If any fields are not touched\n if (!instance.state.meta.isTouched) {\n // Mark them as touched\n instance.setMeta(prev => ({ ...prev,\n isTouched: true\n })); // Validate the field\n\n if (instance.options.validate) {\n fieldValidationPromises.push(instance.validate());\n }\n }\n });\n });\n });\n return Promise.all(fieldValidationPromises);\n };\n\n this.validateForm = async () => {\n const {\n validate\n } = this.options;\n\n if (!validate) {\n return;\n } // Use the formValidationCount for all field instances to\n // track freshness of the validation\n\n\n this.store.setState(prev => ({ ...prev,\n isValidating: true,\n formValidationCount: prev.formValidationCount + 1\n }));\n const formValidationCount = this.state.formValidationCount;\n\n const checkLatest = () => formValidationCount === this.state.formValidationCount;\n\n if (!this.validationMeta.validationPromise) {\n this.validationMeta.validationPromise = new Promise((resolve, reject) => {\n this.validationMeta.validationResolve = resolve;\n this.validationMeta.validationReject = reject;\n });\n }\n\n const doValidation = async () => {\n try {\n const error = await validate(this.state.values, this);\n\n if (checkLatest()) {\n var _this$validationMeta$, _this$validationMeta;\n\n this.store.setState(prev => ({ ...prev,\n isValidating: false,\n error: error ? typeof error === 'string' ? error : 'Invalid Form Values' : null\n }));\n (_this$validationMeta$ = (_this$validationMeta = this.validationMeta).validationResolve) == null ? void 0 : _this$validationMeta$.call(_this$validationMeta, error);\n }\n } catch (err) {\n if (checkLatest()) {\n var _this$validationMeta$2, _this$validationMeta2;\n\n (_this$validationMeta$2 = (_this$validationMeta2 = this.validationMeta).validationReject) == null ? void 0 : _this$validationMeta$2.call(_this$validationMeta2, err);\n }\n } finally {\n delete this.validationMeta.validationPromise;\n }\n };\n\n doValidation();\n return this.validationMeta.validationPromise;\n };\n\n this.handleSubmit = async e => {\n e.preventDefault();\n e.stopPropagation(); // Check to see that the form and all fields have been touched\n // If they have not, touch them all and run validation\n // Run form validation\n // Submit the form\n\n this.store.setState(old => ({ ...old,\n // Submittion attempts mark the form as not submitted\n isSubmitted: false,\n // Count submission attempts\n submissionAttempts: old.submissionAttempts + 1\n })); // Don't let invalid forms submit\n\n if (!this.state.canSubmit) return;\n this.store.setState(d => ({ ...d,\n isSubmitting: true\n }));\n\n const done = () => {\n this.store.setState(prev => ({ ...prev,\n isSubmitting: false\n }));\n }; // Validate all fields\n\n\n await this.validateAllFields(); // Fields are invalid, do not submit\n\n if (!this.state.isFieldsValid) {\n var _this$options$onInval, _this$options;\n\n done();\n (_this$options$onInval = (_this$options = this.options).onInvalidSubmit) == null ? void 0 : _this$options$onInval.call(_this$options, this.state.values, this);\n return;\n } // Run validation for the form\n\n\n await this.validateForm();\n\n if (!this.state.isValid) {\n var _this$options$onInval2, _this$options2;\n\n done();\n (_this$options$onInval2 = (_this$options2 = this.options).onInvalidSubmit) == null ? void 0 : _this$options$onInval2.call(_this$options2, this.state.values, this);\n return;\n }\n\n try {\n var _this$options$onSubmi, _this$options3;\n\n // Run the submit code\n await ((_this$options$onSubmi = (_this$options3 = this.options).onSubmit) == null ? void 0 : _this$options$onSubmi.call(_this$options3, this.state.values, this));\n this.store.batch(() => {\n this.store.setState(prev => ({ ...prev,\n isSubmitted: true\n }));\n done();\n });\n } catch (err) {\n done();\n throw err;\n }\n };\n\n this.getFieldValue = field => getBy(this.state.values, field);\n\n this.getFieldMeta = field => {\n return this.state.fieldMeta[field];\n };\n\n this.getFieldInfo = field => {\n var _this$fieldInfo;\n\n return (_this$fieldInfo = this.fieldInfo)[field] || (_this$fieldInfo[field] = {\n instances: {}\n });\n };\n\n this.setFieldMeta = (field, updater) => {\n this.store.setState(prev => {\n return { ...prev,\n fieldMeta: { ...prev.fieldMeta,\n [field]: functionalUpdate(updater, prev.fieldMeta[field])\n }\n };\n });\n };\n\n this.setFieldValue = (field, updater, opts) => {\n var _opts$touch;\n\n const touch = (_opts$touch = opts == null ? void 0 : opts.touch) != null ? _opts$touch : true;\n this.store.batch(() => {\n this.store.setState(prev => {\n return { ...prev,\n values: setBy(prev.values, field, updater)\n };\n });\n\n if (touch) {\n this.setFieldMeta(field, prev => ({ ...prev,\n isTouched: true\n }));\n }\n });\n };\n\n this.pushFieldValue = (field, value, opts) => {\n return this.setFieldValue(field, prev => [...(Array.isArray(prev) ? prev : []), value], opts);\n };\n\n this.insertFieldValue = (field, index, value, opts) => {\n this.setFieldValue(field, prev => {\n // invariant( // TODO: bring in invariant\n // Array.isArray(prev),\n // `Cannot insert a field value into a non-array field. Check that this field's existing value is an array: ${field}.`\n // )\n return prev.map((d, i) => i === index ? value : d);\n }, opts);\n };\n\n this.spliceFieldValue = (field, index, opts) => {\n this.setFieldValue(field, prev => {\n // invariant( // TODO: bring in invariant\n // Array.isArray(prev),\n // `Cannot insert a field value into a non-array field. Check that this field's existing value is an array: ${field}.`\n // )\n return prev.filter((_d, i) => i !== index);\n }, opts);\n };\n\n this.swapFieldValues = (field, index1, index2) => {\n this.setFieldValue(field, prev => {\n const prev1 = prev[index1];\n const prev2 = prev[index2];\n return setBy(setBy(prev, [index1], prev2), [index2], prev1);\n });\n };\n\n this.store = new Store(getDefaultFormState({ ...(_opts == null ? void 0 : _opts.defaultState),\n values: (_opts$defaultValues = _opts == null ? void 0 : _opts.defaultValues) != null ? _opts$defaultValues : _opts == null ? void 0 : (_opts$defaultState = _opts.defaultState) == null ? void 0 : _opts$defaultState.values,\n isFormValid: !(_opts != null && _opts.validate)\n }), {\n onUpdate: next => {\n // Computed state\n const fieldMetaValues = Object.values(next.fieldMeta);\n const isFieldsValidating = fieldMetaValues.some(field => field == null ? void 0 : field.isValidating);\n const isFieldsValid = !fieldMetaValues.some(field => field == null ? void 0 : field.error);\n const isTouched = fieldMetaValues.some(field => field == null ? void 0 : field.isTouched);\n const isValidating = isFieldsValidating || next.isFormValidating;\n const isFormValid = !next.formError;\n const isValid = isFieldsValid && isFormValid;\n const canSubmit = next.submissionAttempts === 0 && !isTouched || !isValidating && !next.isSubmitting && isValid;\n next = { ...next,\n isFieldsValidating,\n isFieldsValid,\n isFormValid,\n isValid,\n canSubmit,\n isTouched\n }; // Create a shortcut for the state\n // Write it back to the store\n\n this.store.state = next;\n this.state = next;\n }\n });\n this.state = this.store.state;\n this.update(_opts || {});\n }\n\n}\n\nvar id = 0;\n\nfunction _classPrivateFieldLooseKey(name) {\n return \"__private_\" + id++ + \"_\" + name;\n}\n\nfunction _classPrivateFieldLooseBase(receiver, privateKey) {\n if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {\n throw new TypeError(\"attempted to use private field on non-instance\");\n }\n\n return receiver;\n}\n\nlet uid = 0;\n\nvar _updateStore = /*#__PURE__*/_classPrivateFieldLooseKey(\"updateStore\");\n\nvar _leaseValidateAsync = /*#__PURE__*/_classPrivateFieldLooseKey(\"leaseValidateAsync\");\n\nclass FieldApi {\n constructor(_opts) {\n var _this$getMeta;\n\n this.options = {};\n\n this.mount = () => {\n const info = this.getInfo();\n info.instances[this.uid] = this;\n const unsubscribe = this.form.store.subscribe(() => {\n _classPrivateFieldLooseBase(this, _updateStore)[_updateStore]();\n });\n return () => {\n unsubscribe();\n delete info.instances[this.uid];\n\n if (!Object.keys(info.instances).length) {\n delete this.form.fieldInfo[this.name];\n }\n };\n };\n\n Object.defineProperty(this, _updateStore, {\n writable: true,\n value: () => {\n this.store.batch(() => {\n const nextValue = this.getValue();\n const nextMeta = this.getMeta();\n\n if (nextValue !== this.state.value) {\n this.store.setState(prev => ({ ...prev,\n value: nextValue\n }));\n }\n\n if (nextMeta !== this.state.meta) {\n this.store.setState(prev => ({ ...prev,\n meta: nextMeta\n }));\n }\n });\n }\n });\n\n this.update = opts => {\n var _this$form$options$de, _this$form$options$de2, _this$form$options$de3, _this$form$options$de4;\n\n this.options = {\n validatePristine: (_this$form$options$de = this.form.options.defaultValidatePristine) != null ? _this$form$options$de : false,\n validateOn: (_this$form$options$de2 = this.form.options.defaultValidateOn) != null ? _this$form$options$de2 : 'change',\n validateAsyncOn: (_this$form$options$de3 = this.form.options.defaultValidateAsyncOn) != null ? _this$form$options$de3 : 'blur',\n validateAsyncDebounceMs: (_this$form$options$de4 = this.form.options.defaultValidateAsyncDebounceMs) != null ? _this$form$options$de4 : 0,\n ...opts\n }; // Default Value\n\n if (this.state.value === undefined && this.options.defaultValue !== undefined) {\n this.setValue(this.options.defaultValue);\n } // Default Meta\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\n\n if (this.getMeta() === undefined) {\n this.setMeta(this.state.meta);\n }\n };\n\n this.getValue = () => this.form.getFieldValue(this.name);\n\n this.setValue = (updater, options) => this.form.setFieldValue(this.name, updater, options);\n\n this.getMeta = () => this.form.getFieldMeta(this.name);\n\n this.setMeta = updater => this.form.setFieldMeta(this.name, updater);\n\n this.getInfo = () => this.form.getFieldInfo(this.name);\n\n this.pushValue = value => this.form.pushFieldValue(this.name, value);\n\n this.insertValue = (index, value) => this.form.insertFieldValue(this.name, index, value);\n\n this.removeValue = index => this.form.spliceFieldValue(this.name, index);\n\n this.swapValues = (aIndex, bIndex) => this.form.swapFieldValues(this.name, aIndex, bIndex);\n\n this.getSubField = name => new FieldApi({\n name: this.name + \".\" + name,\n form: this.form\n });\n\n this.validateSync = async (value = this.state.value) => {\n const {\n validate\n } = this.options;\n\n if (!validate) {\n return;\n } // Use the validationCount for all field instances to\n // track freshness of the validation\n\n\n const validationCount = (this.getInfo().validationCount || 0) + 1;\n this.getInfo().validationCount = validationCount;\n const error = normalizeError(validate(value, this));\n\n if (this.state.meta.error !== error) {\n this.setMeta(prev => ({ ...prev,\n error\n }));\n } // If a sync error is encountered, cancel any async validation\n\n\n if (this.state.meta.error) {\n this.cancelValidateAsync();\n }\n };\n\n Object.defineProperty(this, _leaseValidateAsync, {\n writable: true,\n value: () => {\n const count = (this.getInfo().validationAsyncCount || 0) + 1;\n this.getInfo().validationAsyncCount = count;\n return count;\n }\n });\n\n this.cancelValidateAsync = () => {\n // Lease a new validation count to ignore any pending validations\n _classPrivateFieldLooseBase(this, _leaseValidateAsync)[_leaseValidateAsync](); // Cancel any pending validation state\n\n\n this.setMeta(prev => ({ ...prev,\n isValidating: false\n }));\n };\n\n this.validateAsync = async (value = this.state.value) => {\n const {\n validateAsync,\n validateAsyncDebounceMs\n } = this.options;\n\n if (!validateAsync) {\n return;\n }\n\n if (this.state.meta.isValidating !== true) this.setMeta(prev => ({ ...prev,\n isValidating: true\n })); // Use the validationCount for all field instances to\n // track freshness of the validation\n\n const validationAsyncCount = _classPrivateFieldLooseBase(this, _leaseValidateAsync)[_leaseValidateAsync]();\n\n const checkLatest = () => validationAsyncCount === this.getInfo().validationAsyncCount;\n\n if (!this.getInfo().validationPromise) {\n this.getInfo().validationPromise = new Promise((resolve, reject) => {\n this.getInfo().validationResolve = resolve;\n this.getInfo().validationReject = reject;\n });\n }\n\n if (validateAsyncDebounceMs > 0) {\n await new Promise(r => setTimeout(r, validateAsyncDebounceMs));\n } // Only kick off validation if this validation is the latest attempt\n\n\n if (checkLatest()) {\n try {\n const rawError = await validateAsync(value, this);\n\n if (checkLatest()) {\n var _this$getInfo$validat, _this$getInfo;\n\n const error = normalizeError(rawError);\n this.setMeta(prev => ({ ...prev,\n isValidating: false,\n error\n }));\n (_this$getInfo$validat = (_this$getInfo = this.getInfo()).validationResolve) == null ? void 0 : _this$getInfo$validat.call(_this$getInfo, error);\n }\n } catch (error) {\n if (checkLatest()) {\n var _this$getInfo$validat2, _this$getInfo2;\n\n (_this$getInfo$validat2 = (_this$getInfo2 = this.getInfo()).validationReject) == null ? void 0 : _this$getInfo$validat2.call(_this$getInfo2, error);\n throw error;\n }\n } finally {\n if (checkLatest()) {\n this.setMeta(prev => ({ ...prev,\n isValidating: false\n }));\n delete this.getInfo().validationPromise;\n }\n }\n } // Always return the latest validation promise to the caller\n\n\n return this.getInfo().validationPromise;\n };\n\n this.shouldValidate = (isAsync, cause) => {\n const {\n validateOn,\n validateAsyncOn\n } = this.options;\n const level = getValidationCauseLevel(cause); // Must meet *at least* the validation level to validate,\n // e.g. if validateOn is 'change' and validateCause is 'blur',\n // the field will still validate\n\n return Object.keys(validateCauseLevels).some(d => isAsync ? validateAsyncOn : validateOn === d && level >= validateCauseLevels[d]);\n };\n\n this.validate = async (cause, value) => {\n // If the field is pristine and validatePristine is false, do not validate\n if (!this.options.validatePristine && !this.state.meta.isTouched) return; // Attempt to sync validate first\n\n if (this.shouldValidate(false, cause)) {\n this.validateSync(value);\n } // If there is an error, return it, do not attempt async validation\n\n\n if (this.state.meta.error) {\n return this.state.meta.error;\n } // No error? Attempt async validation\n\n\n if (this.shouldValidate(true, cause)) {\n return this.validateAsync(value);\n } // If there is no sync error or async validation attempt, there is no error\n\n\n return undefined;\n };\n\n this.getChangeProps = (props = {}) => {\n return { ...props,\n value: this.state.value,\n onChange: value => {\n this.setValue(value);\n props.onChange == null ? void 0 : props.onChange(value);\n },\n onBlur: e => {\n this.setMeta(prev => ({ ...prev,\n isTouched: true\n }));\n this.validate('blur');\n props.onBlur == null ? void 0 : props.onBlur(e);\n }\n };\n };\n\n this.getInputProps = (props = {}) => {\n return { ...props,\n value: String(this.state.value),\n onChange: e => {\n this.setValue(e.target.value);\n props.onChange == null ? void 0 : props.onChange(e.target.value);\n },\n onBlur: this.getChangeProps(props).onBlur\n };\n };\n\n this.form = _opts.form;\n this.uid = uid++; // Support field prefixing from FieldScope\n\n let fieldPrefix = '';\n\n if (this.form.fieldName) {\n fieldPrefix = this.form.fieldName + \".\";\n }\n\n this.name = fieldPrefix + _opts.name;\n this.store = new Store({\n value: this.getValue(),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n meta: (_this$getMeta = this.getMeta()) != null ? _this$getMeta : {\n isValidating: false,\n isTouched: false,\n ...this.options.defaultMeta\n }\n }, {\n onUpdate: next => {\n next.meta.touchedError = next.meta.isTouched ? next.meta.error : undefined; // Do not validate pristine fields\n\n const prevState = this.state;\n this.state = next;\n\n if (next.value !== prevState.value) {\n this.validate('change', next.value);\n }\n }\n });\n this.state = this.store.state;\n this.update(_opts);\n }\n\n}\nconst validateCauseLevels = {\n change: 0,\n blur: 1,\n submit: 2\n};\n\nfunction getValidationCauseLevel(cause) {\n return !cause ? 3 : validateCauseLevels[cause];\n}\n\nfunction normalizeError(rawError) {\n if (rawError) {\n if (typeof rawError !== 'string') {\n return 'Invalid Form Values';\n }\n\n return rawError;\n }\n\n return undefined;\n}\n\nexport { FieldApi, FormApi, functionalUpdate, getBy, setBy };\n//# sourceMappingURL=index.js.map\n","/**\n * react-store\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';\nexport * from '@tanstack/store';\n\nfunction useStore(store, selector = d => d) {\n const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);\n return slice;\n}\nfunction shallow(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n return false;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {\n return false;\n }\n }\n return true;\n}\n\nexport { shallow, useStore };\n//# sourceMappingURL=index.js.map\n","import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<FormApi<any> | null>(null)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n","import * as React from 'react'\n//\nimport { useStore } from '@tanstack/react-store'\nimport type { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core'\nimport { FieldApi } from '@tanstack/form-core'\nimport { useFormContext } from './formContext'\nimport type { FormFactory } from './createFormFactory'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldOptions<TData, TFormData> {\n formFactory?: FormFactory<TFormData>\n }\n}\n\nexport type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(\n opts?: { name: TField } & FieldOptions<\n DeepValue<TFormData, TField>,\n TFormData\n >,\n) => FieldApi<DeepValue<TFormData, TField>, TFormData>\n\nexport function createUseField<TFormData>(): UseField<TFormData> {\n return (opts) => {\n return useField(opts as any)\n }\n}\n\nexport function useField<TData, TFormData>(\n opts: FieldOptions<TData, TFormData> & {\n // selector: (state: FieldApi<TData, TFormData>) => TSelected\n },\n): FieldApi<TData, TFormData> {\n // Get the form API either manually or from context\n const formApi = useFormContext()\n\n const [fieldApi] = React.useState<FieldApi<TData, TFormData>>(\n () => new FieldApi({ ...opts, form: formApi }),\n )\n\n // Keep options up to date as they are rendered\n fieldApi.update({ ...opts, form: formApi })\n\n useStore(fieldApi.store)\n\n // Instantiates field meta and removes it when unrendered\n React.useEffect(() => fieldApi.mount(), [fieldApi])\n\n return fieldApi\n}\n","import * as React from 'react'\nimport {\n functionalUpdate,\n type DeepKeys,\n type DeepValue,\n type FieldApi,\n type FieldOptions,\n} from '@tanstack/form-core'\nimport { useField } from './useField'\n\n//\n\nexport type FieldComponent<TFormData> = <TField extends DeepKeys<TFormData>>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<DeepValue<TFormData, TField>, TFormData>) => any\n name: TField\n} & Omit<FieldOptions<DeepValue<TFormData, TField>, TFormData>, 'name'>) => any\n\nexport function createFieldComponent<TFormData>() {\n const ConnectedField: FieldComponent<TFormData> = (props) => (\n <Field {...(props as any)} />\n )\n return ConnectedField\n}\n\nexport function Field<TData, TFormData>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TFormData>) => any\n} & FieldOptions<TData, TFormData>) {\n const fieldApi = useField(fieldOptions as any)\n return functionalUpdate(children, fieldApi as any)\n}\n","import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { createFieldComponent, type FieldComponent } from './Field'\nimport { createUseField, type UseField } from './useField'\nimport { formContext } from './formContext'\n\ndeclare module '@tanstack/form-core' {\n interface Register {\n FormSubmitEvent: React.FormEvent<HTMLFormElement>\n }\n\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Form: FormComponent\n Field: FieldComponent<TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children:\n | ((state: NoInfer<TSelected>) => React.ReactNode)\n | React.ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = React.useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n api.Form = createFormComponent(api)\n api.Field = createFieldComponent<TData>()\n api.useField = createUseField<TData>()\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n return formApi as any\n}\n\nexport type FormProps = React.HTMLProps<HTMLFormElement> & {\n children: React.ReactNode\n noFormElement?: boolean\n}\n\nexport type FormComponent = (props: FormProps) => any\n\nfunction createFormComponent(formApi: FormApi<any>) {\n const Form: FormComponent = ({ children, noFormElement, ...rest }) => {\n const isSubmitting = formApi.useStore((state) => state.isSubmitting)\n\n return (\n <formContext.Provider value={formApi}>\n {noFormElement ? (\n children\n ) : (\n <form\n onSubmit={formApi.handleSubmit}\n disabled={isSubmitting}\n {...rest}\n >\n {children}\n </form>\n )}\n </formContext.Provider>\n )\n }\n\n return Form\n}\n","import type { FormApi, FormOptions } from '@tanstack/form-core'\nimport { createUseField, type UseField } from './useField'\nimport { useForm } from './useForm'\nimport { createFieldComponent, type FieldComponent } from './Field'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n return useForm<TFormData>({ ...defaultOpts, ...opts } as any) as any\n },\n useField: createUseField<TFormData>(),\n Field: createFieldComponent<TFormData>(),\n }\n}\n"],"names":["Store","listeners","Set","batching","queue","constructor","initialState","options","this","state","subscribe","listener","add","unsub","onSubscribe","delete","setState","updater","previous","updateFn","onUpdate","push","forEach","flush","cb","batch","functionalUpdate","input","setBy","obj","_path","path","makePathArray","doSet","parent","length","key","shift","Array","isArray","prefix","slice","Error","reFindNumbers0","reFindNumbers1","reFindNumbers2","reFindNumbers3","reFindMultiplePeriods","intPrefix","intReplace","str","replace","split","map","d","indexOf","parseInt","substring","getDefaultFormState","defaultState","values","fieldMeta","canSubmit","isFieldsValid","isFieldsValidating","isFormValid","isFormValidating","isSubmitted","isSubmitting","isTouched","isValid","isValidating","submissionAttempts","formValidationCount","FormApi","_opts","_opts$defaultValues","_opts$defaultState","fieldInfo","validationMeta","update","store","prev","defaultValues","reset","validateAllFields","async","fieldValidationPromises","Object","field","instances","instance","meta","setMeta","validate","Promise","all","validateForm","checkLatest","validationPromise","resolve","reject","validationResolve","validationReject","error","_this$validationMeta$","_this$validationMeta","call","err","_this$validationMeta$2","_this$validationMeta2","doValidation","handleSubmit","e","preventDefault","stopPropagation","old","done","_this$options$onInval","_this$options","_this$options$onInval2","_this$options2","onInvalidSubmit","_this$options$onSubmi","_this$options3","onSubmit","getFieldValue","getBy","reduce","current","pathPart","getFieldMeta","getFieldInfo","_this$fieldInfo","setFieldMeta","setFieldValue","opts","_opts$touch","touch","pushFieldValue","value","insertFieldValue","index","i","spliceFieldValue","filter","_d","swapFieldValues","index1","index2","prev1","prev2","next","fieldMetaValues","some","formError","id","_classPrivateFieldLooseKey","name","_classPrivateFieldLooseBase","receiver","privateKey","prototype","hasOwnProperty","TypeError","uid","_updateStore","_leaseValidateAsync","FieldApi","_this$getMeta","mount","info","getInfo","unsubscribe","form","keys","defineProperty","writable","nextValue","getValue","nextMeta","getMeta","_this$form$options$de","_this$form$options$de2","_this$form$options$de3","_this$form$options$de4","validatePristine","defaultValidatePristine","validateOn","defaultValidateOn","validateAsyncOn","defaultValidateAsyncOn","validateAsyncDebounceMs","defaultValidateAsyncDebounceMs","undefined","defaultValue","setValue","pushValue","insertValue","removeValue","swapValues","aIndex","bIndex","getSubField","validateSync","validationCount","normalizeError","cancelValidateAsync","count","validationAsyncCount","validateAsync","r","setTimeout","rawError","_this$getInfo$validat","_this$getInfo","_this$getInfo$validat2","_this$getInfo2","shouldValidate","isAsync","cause","level","validateCauseLevels","getValidationCauseLevel","getChangeProps","props","onChange","onBlur","getInputProps","String","target","fieldPrefix","fieldName","defaultMeta","touchedError","prevState","change","blur","submit","useStore","selector","useSyncExternalStoreWithSelector","shallow","objA","objB","is","keysA","formContext","React","createContext","createUseField","useField","formApi","useContext","useFormContext","fieldApi","useState","useEffect","createFieldComponent","Field","children","fieldOptions","useForm","api","Form","noFormElement","rest","createElement","Provider","_extends","disabled","createFormComponent","Subscribe","defaultOpts"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUA,MAAMA,EACJC,UAAY,IAAIC,IAChBC,UAAW,EACXC,MAAQ,GACRC,YAAYC,EAAcC,GACxBC,KAAKC,MAAQH,EACbE,KAAKD,QAAUA,EAEjBG,UAAYC,IACVH,KAAKP,UAAUW,IAAID,GACnB,MAAME,EAAQL,KAAKD,SAASO,cAAcH,EAAUH,MACpD,MAAO,KACLA,KAAKP,UAAUc,OAAOJ,GACtBE,QAGJG,SAAWC,IACT,MAAMC,EAAWV,KAAKC,MACtBD,KAAKC,MAAQD,KAAKD,SAASY,SAAWX,KAAKD,QAAQY,SAASD,EAAtBV,CAAgCS,GAAWA,EAAQC,GACrFV,KAAKC,QAAUS,IACnBV,KAAKD,SAASa,WAAWZ,KAAKC,MAAOS,GACrCV,KAAKJ,MAAMiB,MAAK,KACdb,KAAKP,UAAUqB,SAAQX,GAAYA,EAASH,KAAKC,MAAOS,QAE1DV,MAAKe,MAEPA,GAAS,KACHf,KAAKL,WACTK,KAAKJ,MAA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ETC,GAAYP,EAAMQ,UACvB,IAAM,IAAIxF,EAAS,IAAKhC,EAAMsC,KAAM8E,MAWtC,OAPAG,EAAS/K,OAAO,IAAKwD,EAAMsC,KAAM8E,IAEjCb,EAASgB,EAAS9K,OAGlBuK,EAAMS,WAAU,IAAMF,EAASrF,SAAS,CAACqF,IAElCA,EC5BF,SAASG,IAId,OAHmDjC,GACjDuB,gBAACW,EAAWlC,GAKT,SAASkC,GAAwBC,SACtCA,KACGC,IAKH,OAAO3O,EAAiB0O,EADPT,EAASU,ICFrB,SAASC,EAAe9H,GAC7B,MAAOoH,GAAWJ,EAAK,QAACQ,UAAS,KAE/B,MAAMO,EAAM,IAAI7L,EAAe8D,GAuB/B,OArBA+H,EAAIC,KAkCR,SAA6BZ,GAqB3B,MApB4B,EAAGQ,WAAUK,mBAAkBC,MACzD,MAAMtM,EAAewL,EAAQb,UAAUtO,GAAUA,EAAM2D,eAEvD,OACEoL,UAAAmB,cAACpB,EAAYqB,SAAb,CAAsBhI,MAAOgH,GAC1Ba,EACCL,EAEAZ,EAAAA,QAAAmB,cAAA,OAAAE,EAAA,CACEhJ,SAAU+H,EAAQ5I,aAClB8J,SAAU1M,GACNsM,GAEHN,KAhDEW,CAAoBR,GAC/BA,EAAIJ,MAAQD,IACZK,EAAIZ,SAAWD,IACfa,EAAIxB,SAEFC,GAGOD,EAASwB,EAAItL,MAAO+J,GAE7BuB,EAAIS,UAEF/C,GAEOvM,EACLuM,EAAMmC,SAENrB,EAASwB,EAAItL,MAAOgJ,EAAMe,WAIvBuB,KAGT,OAAOX,yDCjDF,SACLqB,GAEA,MAAO,CACLX,QAAU9H,GACD8H,EAAmB,IAAKW,KAAgBzI,IAEjDmH,SAAUD,IACVS,MAAOD"}
1
+ {"version":3,"file":"index.production.js","sources":["../../../../node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js","../../../form-core/build/esm/index.js","../../../../node_modules/.pnpm/@tanstack+react-store@0.0.1-beta.84_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/esm/index.js","../../src/formContext.ts","../../src/useField.tsx","../../src/useForm.tsx","../../src/createFormFactory.ts"],"sourcesContent":["/**\n * store\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nclass Store {\n listeners = new Set();\n batching = false;\n queue = [];\n constructor(initialState, options) {\n this.state = initialState;\n this.options = options;\n }\n subscribe = listener => {\n this.listeners.add(listener);\n const unsub = this.options?.onSubscribe?.(listener, this);\n return () => {\n this.listeners.delete(listener);\n unsub?.();\n };\n };\n setState = updater => {\n const previous = this.state;\n this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);\n if (this.state === previous) return;\n this.options?.onUpdate?.(this.state, previous);\n this.queue.push(() => {\n this.listeners.forEach(listener => listener(this.state, previous));\n });\n this.#flush();\n };\n #flush = () => {\n if (this.batching) return;\n this.queue.forEach(cb => cb());\n this.queue = [];\n };\n batch = cb => {\n this.batching = true;\n cb();\n this.batching = false;\n this.#flush();\n };\n}\n\nexport { Store };\n//# sourceMappingURL=index.js.map\n","/**\n * form-core\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nimport { Store } from '@tanstack/store';\n\nfunction functionalUpdate(updater, input) {\n return typeof updater === 'function' ? updater(input) : updater;\n}\nfunction getBy(obj, path) {\n const pathArray = makePathArray(path);\n const pathObj = pathArray;\n return pathObj.reduce((current, pathPart) => {\n if (typeof current !== 'undefined') {\n return current[pathPart];\n }\n\n return undefined;\n }, obj);\n}\nfunction setBy(obj, _path, updater) {\n const path = makePathArray(_path);\n\n function doSet(parent) {\n if (!path.length) {\n return functionalUpdate(updater, parent);\n }\n\n const key = path.shift();\n\n if (typeof key === 'string') {\n if (typeof parent === 'object') {\n return { ...parent,\n [key]: doSet(parent[key])\n };\n }\n\n return {\n [key]: doSet()\n };\n }\n\n if (typeof key === 'number') {\n if (Array.isArray(parent)) {\n const prefix = parent.slice(0, key);\n return [...(prefix.length ? prefix : new Array(key)), doSet(parent[key]), ...parent.slice(key + 1)];\n }\n\n return [...new Array(key), doSet()];\n }\n\n throw new Error('Uh oh!');\n }\n\n return doSet(obj);\n}\nconst reFindNumbers0 = /^(\\d*)$/gm;\nconst reFindNumbers1 = /\\.(\\d*)\\./gm;\nconst reFindNumbers2 = /^(\\d*)\\./gm;\nconst reFindNumbers3 = /\\.(\\d*$)/gm;\nconst reFindMultiplePeriods = /\\.{2,}/gm;\nconst intPrefix = '__int__';\nconst intReplace = intPrefix + \"$1\";\n\nfunction makePathArray(str) {\n if (typeof str !== 'string') {\n throw new Error();\n }\n\n return str.replace('[', '.').replace(']', '').replace(reFindNumbers0, intReplace).replace(reFindNumbers1, \".\" + intReplace + \".\").replace(reFindNumbers2, intReplace + \".\").replace(reFindNumbers3, \".\" + intReplace).replace(reFindMultiplePeriods, '.').split('.').map(d => {\n if (d.indexOf(intPrefix) === 0) {\n return parseInt(d.substring(intPrefix.length), 10);\n }\n\n return d;\n });\n}\n\nfunction getDefaultFormState(defaultState) {\n return {\n values: {},\n fieldMeta: {},\n canSubmit: true,\n isFieldsValid: false,\n isFieldsValidating: false,\n isFormValid: false,\n isFormValidating: false,\n isSubmitted: false,\n isSubmitting: false,\n isTouched: false,\n isValid: false,\n isValidating: false,\n submissionAttempts: 0,\n formValidationCount: 0,\n ...defaultState\n };\n}\n\nclass FormApi {\n // // This carries the context for nested fields\n constructor(_opts) {\n var _opts$defaultValues, _opts$defaultState;\n\n this.options = {};\n this.fieldInfo = {};\n this.validationMeta = {};\n\n this.update = options => {\n if (!options) return;\n this.store.batch(() => {\n if (options.defaultState && options.defaultState !== this.options.defaultState) {\n this.store.setState(prev => ({ ...prev,\n ...options.defaultState\n }));\n }\n\n if (options.defaultValues !== this.options.defaultValues) {\n this.store.setState(prev => ({ ...prev,\n values: options.defaultValues\n }));\n }\n });\n this.options = options;\n };\n\n this.reset = () => this.store.setState(() => getDefaultFormState(this.options.defaultValues));\n\n this.validateAllFields = async () => {\n const fieldValidationPromises = [];\n this.store.batch(() => {\n void Object.values(this.fieldInfo).forEach(field => {\n Object.values(field.instances).forEach(instance => {\n // If any fields are not touched\n if (!instance.state.meta.isTouched) {\n // Mark them as touched\n instance.setMeta(prev => ({ ...prev,\n isTouched: true\n })); // Validate the field\n\n if (instance.options.validate) {\n fieldValidationPromises.push(instance.validate());\n }\n }\n });\n });\n });\n return Promise.all(fieldValidationPromises);\n };\n\n this.validateForm = async () => {\n const {\n validate\n } = this.options;\n\n if (!validate) {\n return;\n } // Use the formValidationCount for all field instances to\n // track freshness of the validation\n\n\n this.store.setState(prev => ({ ...prev,\n isValidating: true,\n formValidationCount: prev.formValidationCount + 1\n }));\n const formValidationCount = this.state.formValidationCount;\n\n const checkLatest = () => formValidationCount === this.state.formValidationCount;\n\n if (!this.validationMeta.validationPromise) {\n this.validationMeta.validationPromise = new Promise((resolve, reject) => {\n this.validationMeta.validationResolve = resolve;\n this.validationMeta.validationReject = reject;\n });\n }\n\n const doValidation = async () => {\n try {\n const error = await validate(this.state.values, this);\n\n if (checkLatest()) {\n var _this$validationMeta$, _this$validationMeta;\n\n this.store.setState(prev => ({ ...prev,\n isValidating: false,\n error: error ? typeof error === 'string' ? error : 'Invalid Form Values' : null\n }));\n (_this$validationMeta$ = (_this$validationMeta = this.validationMeta).validationResolve) == null ? void 0 : _this$validationMeta$.call(_this$validationMeta, error);\n }\n } catch (err) {\n if (checkLatest()) {\n var _this$validationMeta$2, _this$validationMeta2;\n\n (_this$validationMeta$2 = (_this$validationMeta2 = this.validationMeta).validationReject) == null ? void 0 : _this$validationMeta$2.call(_this$validationMeta2, err);\n }\n } finally {\n delete this.validationMeta.validationPromise;\n }\n };\n\n doValidation();\n return this.validationMeta.validationPromise;\n };\n\n this.handleSubmit = async e => {\n e.preventDefault();\n e.stopPropagation(); // Check to see that the form and all fields have been touched\n // If they have not, touch them all and run validation\n // Run form validation\n // Submit the form\n\n this.store.setState(old => ({ ...old,\n // Submittion attempts mark the form as not submitted\n isSubmitted: false,\n // Count submission attempts\n submissionAttempts: old.submissionAttempts + 1\n })); // Don't let invalid forms submit\n\n if (!this.state.canSubmit) return;\n this.store.setState(d => ({ ...d,\n isSubmitting: true\n }));\n\n const done = () => {\n this.store.setState(prev => ({ ...prev,\n isSubmitting: false\n }));\n }; // Validate all fields\n\n\n await this.validateAllFields(); // Fields are invalid, do not submit\n\n if (!this.state.isFieldsValid) {\n var _this$options$onInval, _this$options;\n\n done();\n (_this$options$onInval = (_this$options = this.options).onInvalidSubmit) == null ? void 0 : _this$options$onInval.call(_this$options, this.state.values, this);\n return;\n } // Run validation for the form\n\n\n await this.validateForm();\n\n if (!this.state.isValid) {\n var _this$options$onInval2, _this$options2;\n\n done();\n (_this$options$onInval2 = (_this$options2 = this.options).onInvalidSubmit) == null ? void 0 : _this$options$onInval2.call(_this$options2, this.state.values, this);\n return;\n }\n\n try {\n var _this$options$onSubmi, _this$options3;\n\n // Run the submit code\n await ((_this$options$onSubmi = (_this$options3 = this.options).onSubmit) == null ? void 0 : _this$options$onSubmi.call(_this$options3, this.state.values, this));\n this.store.batch(() => {\n this.store.setState(prev => ({ ...prev,\n isSubmitted: true\n }));\n done();\n });\n } catch (err) {\n done();\n throw err;\n }\n };\n\n this.getFieldValue = field => getBy(this.state.values, field);\n\n this.getFieldMeta = field => {\n return this.state.fieldMeta[field];\n };\n\n this.getFieldInfo = field => {\n var _this$fieldInfo;\n\n return (_this$fieldInfo = this.fieldInfo)[field] || (_this$fieldInfo[field] = {\n instances: {}\n });\n };\n\n this.setFieldMeta = (field, updater) => {\n this.store.setState(prev => {\n return { ...prev,\n fieldMeta: { ...prev.fieldMeta,\n [field]: functionalUpdate(updater, prev.fieldMeta[field])\n }\n };\n });\n };\n\n this.setFieldValue = (field, updater, opts) => {\n var _opts$touch;\n\n const touch = (_opts$touch = opts == null ? void 0 : opts.touch) != null ? _opts$touch : true;\n this.store.batch(() => {\n this.store.setState(prev => {\n return { ...prev,\n values: setBy(prev.values, field, updater)\n };\n });\n\n if (touch) {\n this.setFieldMeta(field, prev => ({ ...prev,\n isTouched: true\n }));\n }\n });\n };\n\n this.pushFieldValue = (field, value, opts) => {\n return this.setFieldValue(field, prev => [...(Array.isArray(prev) ? prev : []), value], opts);\n };\n\n this.insertFieldValue = (field, index, value, opts) => {\n this.setFieldValue(field, prev => {\n // invariant( // TODO: bring in invariant\n // Array.isArray(prev),\n // `Cannot insert a field value into a non-array field. Check that this field's existing value is an array: ${field}.`\n // )\n return prev.map((d, i) => i === index ? value : d);\n }, opts);\n };\n\n this.removeFieldValue = (field, index, opts) => {\n this.setFieldValue(field, prev => {\n // invariant( // TODO: bring in invariant\n // Array.isArray(prev),\n // `Cannot insert a field value into a non-array field. Check that this field's existing value is an array: ${field}.`\n // )\n return prev.filter((_d, i) => i !== index);\n }, opts);\n };\n\n this.swapFieldValues = (field, index1, index2) => {\n this.setFieldValue(field, prev => {\n const prev1 = prev[index1];\n const prev2 = prev[index2];\n return setBy(setBy(prev, [index1], prev2), [index2], prev1);\n });\n };\n\n this.store = new Store(getDefaultFormState({ ...(_opts == null ? void 0 : _opts.defaultState),\n values: (_opts$defaultValues = _opts == null ? void 0 : _opts.defaultValues) != null ? _opts$defaultValues : _opts == null ? void 0 : (_opts$defaultState = _opts.defaultState) == null ? void 0 : _opts$defaultState.values,\n isFormValid: !(_opts != null && _opts.validate)\n }), {\n onUpdate: next => {\n // Computed state\n const fieldMetaValues = Object.values(next.fieldMeta);\n const isFieldsValidating = fieldMetaValues.some(field => field == null ? void 0 : field.isValidating);\n const isFieldsValid = !fieldMetaValues.some(field => field == null ? void 0 : field.error);\n const isTouched = fieldMetaValues.some(field => field == null ? void 0 : field.isTouched);\n const isValidating = isFieldsValidating || next.isFormValidating;\n const isFormValid = !next.formError;\n const isValid = isFieldsValid && isFormValid;\n const canSubmit = next.submissionAttempts === 0 && !isTouched || !isValidating && !next.isSubmitting && isValid;\n next = { ...next,\n isFieldsValidating,\n isFieldsValid,\n isFormValid,\n isValid,\n canSubmit,\n isTouched\n }; // Create a shortcut for the state\n // Write it back to the store\n\n this.store.state = next;\n this.state = next;\n console.log(this.state);\n }\n });\n this.state = this.store.state;\n this.update(_opts || {});\n }\n\n}\n\nvar id = 0;\n\nfunction _classPrivateFieldLooseKey(name) {\n return \"__private_\" + id++ + \"_\" + name;\n}\n\nfunction _classPrivateFieldLooseBase(receiver, privateKey) {\n if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {\n throw new TypeError(\"attempted to use private field on non-instance\");\n }\n\n return receiver;\n}\n\nlet uid = 0;\n\nvar _updateStore = /*#__PURE__*/_classPrivateFieldLooseKey(\"updateStore\");\n\nvar _leaseValidateAsync = /*#__PURE__*/_classPrivateFieldLooseKey(\"leaseValidateAsync\");\n\nclass FieldApi {\n constructor(_opts) {\n var _this$getMeta;\n\n this.options = {};\n\n this.mount = () => {\n const info = this.getInfo();\n info.instances[this.uid] = this;\n const unsubscribe = this.form.store.subscribe(() => {\n _classPrivateFieldLooseBase(this, _updateStore)[_updateStore]();\n });\n return () => {\n unsubscribe();\n delete info.instances[this.uid];\n\n if (!Object.keys(info.instances).length) {\n delete this.form.fieldInfo[this.name];\n }\n };\n };\n\n Object.defineProperty(this, _updateStore, {\n writable: true,\n value: () => {\n this.store.batch(() => {\n const nextValue = this.getValue();\n const nextMeta = this.getMeta();\n\n if (nextValue !== this.state.value) {\n this.store.setState(prev => ({ ...prev,\n value: nextValue\n }));\n }\n\n if (nextMeta !== this.state.meta) {\n this.store.setState(prev => ({ ...prev,\n meta: nextMeta\n }));\n }\n });\n }\n });\n\n this.update = opts => {\n var _this$form$options$de, _this$form$options$de2, _this$form$options$de3, _this$form$options$de4;\n\n this.options = {\n validatePristine: (_this$form$options$de = this.form.options.defaultValidatePristine) != null ? _this$form$options$de : false,\n validateOn: (_this$form$options$de2 = this.form.options.defaultValidateOn) != null ? _this$form$options$de2 : 'change',\n validateAsyncOn: (_this$form$options$de3 = this.form.options.defaultValidateAsyncOn) != null ? _this$form$options$de3 : 'blur',\n validateAsyncDebounceMs: (_this$form$options$de4 = this.form.options.defaultValidateAsyncDebounceMs) != null ? _this$form$options$de4 : 0,\n ...opts\n }; // Default Value\n\n if (this.state.value === undefined && this.options.defaultValue !== undefined) {\n this.setValue(this.options.defaultValue);\n } // Default Meta\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n\n\n if (this.getMeta() === undefined) {\n this.setMeta(this.state.meta);\n }\n };\n\n this.getValue = () => {\n return this.form.getFieldValue(this.name);\n };\n\n this.setValue = (updater, options) => this.form.setFieldValue(this.name, updater, options);\n\n this.getMeta = () => this.form.getFieldMeta(this.name);\n\n this.setMeta = updater => this.form.setFieldMeta(this.name, updater);\n\n this.getInfo = () => this.form.getFieldInfo(this.name);\n\n this.pushValue = value => this.form.pushFieldValue(this.name, value);\n\n this.insertValue = (index, value) => this.form.insertFieldValue(this.name, index, value);\n\n this.removeValue = index => this.form.removeFieldValue(this.name, index);\n\n this.swapValues = (aIndex, bIndex) => this.form.swapFieldValues(this.name, aIndex, bIndex);\n\n this.getSubField = name => new FieldApi({\n name: this.name + \".\" + name,\n form: this.form\n });\n\n this.validateSync = async (value = this.state.value) => {\n const {\n validate\n } = this.options;\n\n if (!validate) {\n return;\n } // Use the validationCount for all field instances to\n // track freshness of the validation\n\n\n const validationCount = (this.getInfo().validationCount || 0) + 1;\n this.getInfo().validationCount = validationCount;\n const error = normalizeError(validate(value, this));\n\n if (this.state.meta.error !== error) {\n this.setMeta(prev => ({ ...prev,\n error\n }));\n } // If a sync error is encountered, cancel any async validation\n\n\n if (this.state.meta.error) {\n this.cancelValidateAsync();\n }\n };\n\n Object.defineProperty(this, _leaseValidateAsync, {\n writable: true,\n value: () => {\n const count = (this.getInfo().validationAsyncCount || 0) + 1;\n this.getInfo().validationAsyncCount = count;\n return count;\n }\n });\n\n this.cancelValidateAsync = () => {\n // Lease a new validation count to ignore any pending validations\n _classPrivateFieldLooseBase(this, _leaseValidateAsync)[_leaseValidateAsync](); // Cancel any pending validation state\n\n\n this.setMeta(prev => ({ ...prev,\n isValidating: false\n }));\n };\n\n this.validateAsync = async (value = this.state.value) => {\n const {\n validateAsync,\n validateAsyncDebounceMs\n } = this.options;\n\n if (!validateAsync) {\n return;\n }\n\n if (this.state.meta.isValidating !== true) this.setMeta(prev => ({ ...prev,\n isValidating: true\n })); // Use the validationCount for all field instances to\n // track freshness of the validation\n\n const validationAsyncCount = _classPrivateFieldLooseBase(this, _leaseValidateAsync)[_leaseValidateAsync]();\n\n const checkLatest = () => validationAsyncCount === this.getInfo().validationAsyncCount;\n\n if (!this.getInfo().validationPromise) {\n this.getInfo().validationPromise = new Promise((resolve, reject) => {\n this.getInfo().validationResolve = resolve;\n this.getInfo().validationReject = reject;\n });\n }\n\n if (validateAsyncDebounceMs > 0) {\n await new Promise(r => setTimeout(r, validateAsyncDebounceMs));\n } // Only kick off validation if this validation is the latest attempt\n\n\n if (checkLatest()) {\n try {\n const rawError = await validateAsync(value, this);\n\n if (checkLatest()) {\n var _this$getInfo$validat, _this$getInfo;\n\n const error = normalizeError(rawError);\n this.setMeta(prev => ({ ...prev,\n isValidating: false,\n error\n }));\n (_this$getInfo$validat = (_this$getInfo = this.getInfo()).validationResolve) == null ? void 0 : _this$getInfo$validat.call(_this$getInfo, error);\n }\n } catch (error) {\n if (checkLatest()) {\n var _this$getInfo$validat2, _this$getInfo2;\n\n (_this$getInfo$validat2 = (_this$getInfo2 = this.getInfo()).validationReject) == null ? void 0 : _this$getInfo$validat2.call(_this$getInfo2, error);\n throw error;\n }\n } finally {\n if (checkLatest()) {\n this.setMeta(prev => ({ ...prev,\n isValidating: false\n }));\n delete this.getInfo().validationPromise;\n }\n }\n } // Always return the latest validation promise to the caller\n\n\n return this.getInfo().validationPromise;\n };\n\n this.shouldValidate = (isAsync, cause) => {\n const {\n validateOn,\n validateAsyncOn\n } = this.options;\n const level = getValidationCauseLevel(cause); // Must meet *at least* the validation level to validate,\n // e.g. if validateOn is 'change' and validateCause is 'blur',\n // the field will still validate\n\n return Object.keys(validateCauseLevels).some(d => isAsync ? validateAsyncOn : validateOn === d && level >= validateCauseLevels[d]);\n };\n\n this.validate = async (cause, value) => {\n // If the field is pristine and validatePristine is false, do not validate\n if (!this.options.validatePristine && !this.state.meta.isTouched) return; // Attempt to sync validate first\n\n if (this.shouldValidate(false, cause)) {\n this.validateSync(value);\n } // If there is an error, return it, do not attempt async validation\n\n\n if (this.state.meta.error) {\n return this.state.meta.error;\n } // No error? Attempt async validation\n\n\n if (this.shouldValidate(true, cause)) {\n return this.validateAsync(value);\n } // If there is no sync error or async validation attempt, there is no error\n\n\n return undefined;\n };\n\n this.getChangeProps = (props = {}) => {\n return { ...props,\n value: this.state.value,\n onChange: value => {\n this.setValue(value);\n props.onChange == null ? void 0 : props.onChange(value);\n },\n onBlur: e => {\n this.setMeta(prev => ({ ...prev,\n isTouched: true\n }));\n this.validate('blur');\n props.onBlur == null ? void 0 : props.onBlur(e);\n }\n };\n };\n\n this.getInputProps = (props = {}) => {\n return { ...props,\n value: String(this.state.value),\n onChange: e => {\n this.setValue(e.target.value);\n props.onChange == null ? void 0 : props.onChange(e.target.value);\n },\n onBlur: this.getChangeProps(props).onBlur\n };\n };\n\n this.form = _opts.form;\n this.uid = uid++; // Support field prefixing from FieldScope\n // let fieldPrefix = ''\n // if (this.form.fieldName) {\n // fieldPrefix = `${this.form.fieldName}.`\n // }\n\n this.name = _opts.name;\n this.store = new Store({\n value: this.getValue(),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n meta: (_this$getMeta = this.getMeta()) != null ? _this$getMeta : {\n isValidating: false,\n isTouched: false,\n ...this.options.defaultMeta\n }\n }, {\n onUpdate: next => {\n next.meta.touchedError = next.meta.isTouched ? next.meta.error : undefined; // Do not validate pristine fields\n\n const prevState = this.state;\n this.state = next;\n\n if (next.value !== prevState.value) {\n this.validate('change', next.value);\n }\n\n console.log(this);\n }\n });\n this.state = this.store.state;\n this.update(_opts);\n }\n\n}\nconst validateCauseLevels = {\n change: 0,\n blur: 1,\n submit: 2\n};\n\nfunction getValidationCauseLevel(cause) {\n return !cause ? 3 : validateCauseLevels[cause];\n}\n\nfunction normalizeError(rawError) {\n if (rawError) {\n if (typeof rawError !== 'string') {\n return 'Invalid Form Values';\n }\n\n return rawError;\n }\n\n return undefined;\n}\n\nexport { FieldApi, FormApi, functionalUpdate, getBy, setBy };\n//# sourceMappingURL=index.js.map\n","/**\n * react-store\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';\nexport * from '@tanstack/store';\n\nfunction useStore(store, selector = d => d) {\n const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);\n return slice;\n}\nfunction shallow(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n return false;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {\n return false;\n }\n }\n return true;\n}\n\nexport { shallow, useStore };\n//# sourceMappingURL=index.js.map\n","import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n","import * as React from 'react'\n//\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n FieldOptions,\n Narrow,\n} from '@tanstack/form-core'\nimport { FieldApi, functionalUpdate } from '@tanstack/form-core'\nimport { useFormContext, formContext } from './formContext'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<TData, TFormData> {\n Field: FieldComponent<TData, TFormData>\n }\n}\n\nexport type UseFieldOptions<TData, TFormData> = FieldOptions<\n TData,\n TFormData\n> & {\n mode?: 'value' | 'array'\n}\n\nexport type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(\n opts?: { name: Narrow<TField> } & UseFieldOptions<\n DeepValue<TFormData, TField>,\n TFormData\n >,\n) => FieldApi<DeepValue<TFormData, TField>, TFormData>\n\nexport function useField<TData, TFormData>(\n opts: UseFieldOptions<TData, TFormData>,\n): FieldApi<TData, TFormData> {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const [fieldApi] = React.useState<FieldApi<TData, TFormData>>(() => {\n const name = (\n typeof opts.index === 'number'\n ? [parentFieldName, opts.index, opts.name]\n : [parentFieldName, opts.name]\n )\n .filter((d) => d !== undefined)\n .join('.')\n\n const api = new FieldApi({ ...opts, form: formApi, name: name as any })\n\n api.Field = Field as any\n\n return api\n })\n\n // Keep options up to date as they are rendered\n fieldApi.update({ ...opts, form: formApi })\n\n useStore(\n fieldApi.store,\n opts.mode === 'array'\n ? (state: any) => {\n return [state.meta, Object.keys(state.value || []).length]\n }\n : undefined,\n )\n\n // Instantiates field meta and removes it when unrendered\n React.useEffect(() => fieldApi.mount(), [fieldApi])\n\n return fieldApi\n}\n\n// export type FieldValue<TFormData, TField> = TFormData extends any[]\n// ? TField extends `[${infer TIndex extends number | 'i'}].${infer TRest}`\n// ? DeepValue<TFormData[TIndex extends 'i' ? number : TIndex], TRest>\n// : TField extends `[${infer TIndex extends number | 'i'}]`\n// ? TFormData[TIndex extends 'i' ? number : TIndex]\n// : never\n// : TField extends `${infer TPrefix}[${infer TIndex extends\n// | number\n// | 'i'}].${infer TRest}`\n// ? DeepValue<\n// DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex],\n// TRest\n// >\n// : TField extends `${infer TPrefix}[${infer TIndex extends number | 'i'}]`\n// ? DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex]\n// : DeepValue<TFormData, TField>\n\nexport type FieldValue<TFormData, TField> = TFormData extends any[]\n ? unknown extends TField\n ? TFormData[number]\n : DeepValue<TFormData[number], TField>\n : DeepValue<TFormData, TField>\n\n// type Test1 = FieldValue<{ foo: { bar: string }[] }, 'foo'>\n// // ^?\n// type Test2 = FieldValue<{ foo: { bar: string }[] }, 'foo[i]'>\n// // ^?\n// type Test3 = FieldValue<{ foo: { bar: string }[] }, 'foo[2].bar'>\n// // ^?\n\nexport type FieldComponent<TParentData, TFormData> = <TField>({\n children,\n ...fieldOptions\n}: {\n children: (\n fieldApi: FieldApi<FieldValue<TParentData, TField>, TFormData>,\n ) => any\n} & Omit<\n UseFieldOptions<FieldValue<TParentData, TField>, TFormData>,\n 'name' | 'index'\n> &\n (TParentData extends any[]\n ? {\n name?: TField extends undefined ? TField : DeepKeys<TParentData>\n index: number\n }\n : {\n name: TField extends undefined ? TField : DeepKeys<TParentData>\n index?: never\n })) => any\n\nexport function Field<TData, TFormData>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TFormData>) => any\n} & UseFieldOptions<TData, TFormData>) {\n const fieldApi = useField(fieldOptions as any)\n return (\n <formContext.Provider\n value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n","import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\ndeclare module '@tanstack/form-core' {\n interface Register {\n FormSubmitEvent: React.FormEvent<HTMLFormElement>\n }\n\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Form: FormComponent\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children:\n | ((state: NoInfer<TSelected>) => React.ReactNode)\n | React.ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = React.useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n api.Form = createFormComponent(api)\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.update(opts)\n\n return formApi as any\n}\n\nexport type FormProps = React.HTMLProps<HTMLFormElement> & {\n children: React.ReactNode\n noFormElement?: boolean\n}\n\nexport type FormComponent = (props: FormProps) => any\n\nfunction createFormComponent(formApi: FormApi<any>) {\n const Form: FormComponent = ({ children, noFormElement, ...rest }) => {\n const isSubmitting = formApi.useStore((state) => state.isSubmitting)\n\n return (\n <formContext.Provider value={{ formApi }}>\n {noFormElement ? (\n children\n ) : (\n <form\n onSubmit={formApi.handleSubmit}\n disabled={isSubmitting}\n {...rest}\n >\n {children}\n </form>\n )}\n </formContext.Provider>\n )\n }\n\n return Form\n}\n","import type { FormApi, FormOptions } from '@tanstack/form-core'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n return useForm<TFormData>({ ...defaultOpts, ...opts } as any) as any\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"names":["Store","listeners","Set","batching","queue","constructor","initialState","options","this","state","subscribe","listener","add","unsub","onSubscribe","delete","setState","updater","previous","updateFn","onUpdate","push","forEach","flush","cb","batch","functionalUpdate","input","setBy","obj","_path","path","makePathArray","doSet","parent","length","key","shift","Array","isArray","prefix","slice","Error","reFindNumbers0","reFindNumbers1","reFindNumbers2","reFindNumbers3","reFindMultiplePeriods","intPrefix","intReplace","str","replace","split","map","d","indexOf","parseInt","substring","getDefaultFormState","defaultState","values","fieldMeta","canSubmit","isFieldsValid","isFieldsValidating","isFormValid","isFormValidating","isSubmitted","isSubmitting","isTouched","isValid","isValidating","submissionAttempts","formValidationCount","FormApi","_opts","_opts$defaultValues","_opts$defaultState","fieldInfo","validationMeta","update","store","prev","defaultValues","reset","validateAllFields","async","fieldValidationPromises","Object","field","instances","instance","meta","setMeta","validate","Promise","all","validateForm","checkLatest","validationPromise","resolve","reject","validationResolve","validationReject","error","_this$validationMeta$","_this$validationMeta","call","err","_this$validationMeta$2","_this$validationMeta2","doValidation","handleSubmit","e","preventDefault","stopPropagation","old","done","_this$options$onInval","_this$options","_this$options$onInval2","_this$options2","onInvalidSubmit","_this$options$onSubmi","_this$options3","onSubmit","getFieldValue","getBy","reduce","current","pathPart","getFieldMeta","getFieldInfo","_this$fieldInfo","setFieldMeta","setFieldValue","opts","_opts$touch","touch","pushFieldValue","value","insertFieldValue","index","i","removeFieldValue","filter","_d","swapFieldValues","index1","index2","prev1","prev2","next","fieldMetaValues","some","formError","console","log","id","_classPrivateFieldLooseKey","name","_classPrivateFieldLooseBase","receiver","privateKey","prototype","hasOwnProperty","TypeError","uid","_updateStore","_leaseValidateAsync","FieldApi","_this$getMeta","mount","info","getInfo","unsubscribe","form","keys","defineProperty","writable","nextValue","getValue","nextMeta","getMeta","_this$form$options$de","_this$form$options$de2","_this$form$options$de3","_this$form$options$de4","validatePristine","defaultValidatePristine","validateOn","defaultValidateOn","validateAsyncOn","defaultValidateAsyncOn","validateAsyncDebounceMs","defaultValidateAsyncDebounceMs","undefined","defaultValue","setValue","pushValue","insertValue","removeValue","swapValues","aIndex","bIndex","getSubField","validateSync","validationCount","normalizeError","cancelValidateAsync","count","validationAsyncCount","validateAsync","r","setTimeout","rawError","_this$getInfo$validat","_this$getInfo","_this$getInfo$validat2","_this$getInfo2","shouldValidate","isAsync","cause","level","validateCauseLevels","getValidationCauseLevel","getChangeProps","props","onChange","onBlur","getInputProps","String","target","defaultMeta","touchedError","prevState","change","blur","submit","useStore","selector","useSyncExternalStoreWithSelector","shallow","objA","objB","is","keysA","formContext","React","createContext","useField","formApi","parentFieldName","useContext","useFormContext","fieldApi","useState","join","api","Field","mode","useEffect","children","fieldOptions","createElement","Provider","useForm","Form","noFormElement","rest","_extends","disabled","createFormComponent","Subscribe","defaultOpts"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUA,MAAMA,EACJC,UAAY,IAAIC,IAChBC,UAAW,EACXC,MAAQ,GACRC,YAAYC,EAAcC,GACxBC,KAAKC,MAAQH,EACbE,KAAKD,QAAUA,EAEjBG,UAAYC,IACVH,KAAKP,UAAUW,IAAID,GACnB,MAAME,EAAQL,KAAKD,SAASO,cAAcH,EAAUH,MACpD,MAAO,KACLA,KAAKP,UAAUc,OAAOJ,GACtBE,QAGJG,SAAWC,IACT,MAAMC,EAAWV,KAAKC,MACtBD,KAAKC,MAAQD,KAAKD,SAASY,SAAWX,KAAKD,QAAQY,SAASD,EAAtBV,CAAgCS,GAAWA,EAAQC,GACrFV,KAAKC,QAAUS,IACnBV,KAAKD,SAASa,WAAWZ,KAAKC,MAAOS,GACrCV,KAAKJ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M,GACNyM,GAEHP,KAlDEU,CAAoBd,GAC/BA,EAAIC,MAAQA,EACZD,EAAIR,SAAWA,EACfQ,EAAInB,SAEFC,GAGOD,EAASmB,EAAIjL,MAAO+J,GAE7BkB,EAAIe,UAEF9C,GAEOzM,EACLyM,EAAMmC,SAENvB,EAASmB,EAAIjL,MAAOkJ,EAAMa,WAIvBkB,KAKT,OAFAP,EAAQ3K,OAAOwD,GAERmH,yDCnDF,SACLuB,GAEA,MAAO,CACLR,QAAUlI,GACDkI,EAAmB,IAAKQ,KAAgB1I,IAEjDkH,SAAUA,EACVS,MAAOA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-form",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Powerful, type-safe forms for React.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@tanstack/react-store": "0.0.1-beta.84",
32
- "@tanstack/form-core": "0.0.7"
32
+ "@tanstack/form-core": "0.0.8"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "^17.0.0 || ^18.0.0",
@@ -1,12 +1,11 @@
1
1
  import type { FormApi, FormOptions } from '@tanstack/form-core'
2
- import { createUseField, type UseField } from './useField'
2
+ import { type UseField, type FieldComponent, Field, useField } from './useField'
3
3
  import { useForm } from './useForm'
4
- import { createFieldComponent, type FieldComponent } from './Field'
5
4
 
6
5
  export type FormFactory<TFormData> = {
7
6
  useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>
8
7
  useField: UseField<TFormData>
9
- Field: FieldComponent<TFormData>
8
+ Field: FieldComponent<TFormData, TFormData>
10
9
  }
11
10
 
12
11
  export function createFormFactory<TFormData>(
@@ -16,7 +15,7 @@ export function createFormFactory<TFormData>(
16
15
  useForm: (opts) => {
17
16
  return useForm<TFormData>({ ...defaultOpts, ...opts } as any) as any
18
17
  },
19
- useField: createUseField<TFormData>(),
20
- Field: createFieldComponent<TFormData>(),
18
+ useField: useField as any,
19
+ Field: Field as any,
21
20
  }
22
21
  }
@@ -1,7 +1,10 @@
1
1
  import type { FormApi } from '@tanstack/form-core'
2
2
  import * as React from 'react'
3
3
 
4
- export const formContext = React.createContext<FormApi<any> | null>(null)
4
+ export const formContext = React.createContext<{
5
+ formApi: FormApi<any>
6
+ parentFieldName?: string
7
+ } | null>(null!)
5
8
 
6
9
  export function useFormContext() {
7
10
  const formApi = React.useContext(formContext)
package/src/index.ts CHANGED
@@ -25,11 +25,8 @@ export { FormApi, FieldApi, functionalUpdate } from '@tanstack/form-core'
25
25
  export type { FormComponent, FormProps } from './useForm'
26
26
  export { useForm } from './useForm'
27
27
 
28
- export type { FieldComponent } from './Field'
29
- export { Field } from './Field'
30
-
31
- export type { UseField } from './useField'
32
- export { useField } from './useField'
28
+ export type { UseField, FieldComponent } from './useField'
29
+ export { useField, Field } from './useField'
33
30
 
34
31
  export type { FormFactory } from './createFormFactory'
35
32
  export { createFormFactory } from './createFormFactory'
@@ -0,0 +1,138 @@
1
+ import * as React from 'react'
2
+ //
3
+ import { useStore } from '@tanstack/react-store'
4
+ import type {
5
+ DeepKeys,
6
+ DeepValue,
7
+ FieldOptions,
8
+ Narrow,
9
+ } from '@tanstack/form-core'
10
+ import { FieldApi, functionalUpdate } from '@tanstack/form-core'
11
+ import { useFormContext, formContext } from './formContext'
12
+
13
+ declare module '@tanstack/form-core' {
14
+ // eslint-disable-next-line no-shadow
15
+ interface FieldApi<TData, TFormData> {
16
+ Field: FieldComponent<TData, TFormData>
17
+ }
18
+ }
19
+
20
+ export type UseFieldOptions<TData, TFormData> = FieldOptions<
21
+ TData,
22
+ TFormData
23
+ > & {
24
+ mode?: 'value' | 'array'
25
+ }
26
+
27
+ export type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(
28
+ opts?: { name: Narrow<TField> } & UseFieldOptions<
29
+ DeepValue<TFormData, TField>,
30
+ TFormData
31
+ >,
32
+ ) => FieldApi<DeepValue<TFormData, TField>, TFormData>
33
+
34
+ export function useField<TData, TFormData>(
35
+ opts: UseFieldOptions<TData, TFormData>,
36
+ ): FieldApi<TData, TFormData> {
37
+ // Get the form API either manually or from context
38
+ const { formApi, parentFieldName } = useFormContext()
39
+
40
+ const [fieldApi] = React.useState<FieldApi<TData, TFormData>>(() => {
41
+ const name = (
42
+ typeof opts.index === 'number'
43
+ ? [parentFieldName, opts.index, opts.name]
44
+ : [parentFieldName, opts.name]
45
+ )
46
+ .filter((d) => d !== undefined)
47
+ .join('.')
48
+
49
+ const api = new FieldApi({ ...opts, form: formApi, name: name as any })
50
+
51
+ api.Field = Field as any
52
+
53
+ return api
54
+ })
55
+
56
+ // Keep options up to date as they are rendered
57
+ fieldApi.update({ ...opts, form: formApi })
58
+
59
+ useStore(
60
+ fieldApi.store,
61
+ opts.mode === 'array'
62
+ ? (state: any) => {
63
+ return [state.meta, Object.keys(state.value || []).length]
64
+ }
65
+ : undefined,
66
+ )
67
+
68
+ // Instantiates field meta and removes it when unrendered
69
+ React.useEffect(() => fieldApi.mount(), [fieldApi])
70
+
71
+ return fieldApi
72
+ }
73
+
74
+ // export type FieldValue<TFormData, TField> = TFormData extends any[]
75
+ // ? TField extends `[${infer TIndex extends number | 'i'}].${infer TRest}`
76
+ // ? DeepValue<TFormData[TIndex extends 'i' ? number : TIndex], TRest>
77
+ // : TField extends `[${infer TIndex extends number | 'i'}]`
78
+ // ? TFormData[TIndex extends 'i' ? number : TIndex]
79
+ // : never
80
+ // : TField extends `${infer TPrefix}[${infer TIndex extends
81
+ // | number
82
+ // | 'i'}].${infer TRest}`
83
+ // ? DeepValue<
84
+ // DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex],
85
+ // TRest
86
+ // >
87
+ // : TField extends `${infer TPrefix}[${infer TIndex extends number | 'i'}]`
88
+ // ? DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex]
89
+ // : DeepValue<TFormData, TField>
90
+
91
+ export type FieldValue<TFormData, TField> = TFormData extends any[]
92
+ ? unknown extends TField
93
+ ? TFormData[number]
94
+ : DeepValue<TFormData[number], TField>
95
+ : DeepValue<TFormData, TField>
96
+
97
+ // type Test1 = FieldValue<{ foo: { bar: string }[] }, 'foo'>
98
+ // // ^?
99
+ // type Test2 = FieldValue<{ foo: { bar: string }[] }, 'foo[i]'>
100
+ // // ^?
101
+ // type Test3 = FieldValue<{ foo: { bar: string }[] }, 'foo[2].bar'>
102
+ // // ^?
103
+
104
+ export type FieldComponent<TParentData, TFormData> = <TField>({
105
+ children,
106
+ ...fieldOptions
107
+ }: {
108
+ children: (
109
+ fieldApi: FieldApi<FieldValue<TParentData, TField>, TFormData>,
110
+ ) => any
111
+ } & Omit<
112
+ UseFieldOptions<FieldValue<TParentData, TField>, TFormData>,
113
+ 'name' | 'index'
114
+ > &
115
+ (TParentData extends any[]
116
+ ? {
117
+ name?: TField extends undefined ? TField : DeepKeys<TParentData>
118
+ index: number
119
+ }
120
+ : {
121
+ name: TField extends undefined ? TField : DeepKeys<TParentData>
122
+ index?: never
123
+ })) => any
124
+
125
+ export function Field<TData, TFormData>({
126
+ children,
127
+ ...fieldOptions
128
+ }: {
129
+ children: (fieldApi: FieldApi<TData, TFormData>) => any
130
+ } & UseFieldOptions<TData, TFormData>) {
131
+ const fieldApi = useField(fieldOptions as any)
132
+ return (
133
+ <formContext.Provider
134
+ value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}
135
+ children={functionalUpdate(children, fieldApi as any)}
136
+ />
137
+ )
138
+ }
package/src/useForm.tsx CHANGED
@@ -3,8 +3,7 @@ import { FormApi, functionalUpdate } from '@tanstack/form-core'
3
3
  import type { NoInfer } from '@tanstack/react-store'
4
4
  import { useStore } from '@tanstack/react-store'
5
5
  import React from 'react'
6
- import { createFieldComponent, type FieldComponent } from './Field'
7
- import { createUseField, type UseField } from './useField'
6
+ import { type UseField, type FieldComponent, Field, useField } from './useField'
8
7
  import { formContext } from './formContext'
9
8
 
10
9
  declare module '@tanstack/form-core' {
@@ -15,7 +14,7 @@ declare module '@tanstack/form-core' {
15
14
  // eslint-disable-next-line no-shadow
16
15
  interface FormApi<TFormData> {
17
16
  Form: FormComponent
18
- Field: FieldComponent<TFormData>
17
+ Field: FieldComponent<TFormData, TFormData>
19
18
  useField: UseField<TFormData>
20
19
  useStore: <TSelected = NoInfer<FormState<TFormData>>>(
21
20
  selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,
@@ -35,8 +34,8 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
35
34
  const api = new FormApi<TData>(opts)
36
35
 
37
36
  api.Form = createFormComponent(api)
38
- api.Field = createFieldComponent<TData>()
39
- api.useField = createUseField<TData>()
37
+ api.Field = Field as any
38
+ api.useField = useField as any
40
39
  api.useStore = (
41
40
  // @ts-ignore
42
41
  selector,
@@ -58,6 +57,8 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
58
57
  return api
59
58
  })
60
59
 
60
+ formApi.update(opts)
61
+
61
62
  return formApi as any
62
63
  }
63
64
 
@@ -73,7 +74,7 @@ function createFormComponent(formApi: FormApi<any>) {
73
74
  const isSubmitting = formApi.useStore((state) => state.isSubmitting)
74
75
 
75
76
  return (
76
- <formContext.Provider value={formApi}>
77
+ <formContext.Provider value={{ formApi }}>
77
78
  {noFormElement ? (
78
79
  children
79
80
  ) : (