mobx-react-hook-form 6.0.1 → 6.1.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/form/form.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EACL,KAAK,OAAO,EACZ,iBAAiB,EACjB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEjE,KAAK,aAAa,CAAC,YAAY,SAAS,WAAW,IACjD,SAAS,CAAC,YAAY,CAAC,GAAG;IACxB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEJ,qBAAa,IAAI,CACf,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,CACjC,YAAW,aAAa,CAAC,YAAY,CAAC;IAEtC,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,OAAO,CAAS;IACzB,SAAS,EAAE,OAAO,CAAS;IAC3B,WAAW,EAAE,OAAO,CAAS;IAC7B,kBAAkB,EAAE,OAAO,CAAS;IACpC,YAAY,EAAE,OAAO,CAAS;IAC9B,YAAY,EAAE,OAAO,CAAS;IAC9B,O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AAC,YAAY,EAAE,UAAU,CAAC,GAAG,SAAS,EAC3D,UAAU,cAAc,UAOxB;IAEF;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,CAAC,EAAE,kBAAkB;IAkC7B;;;;;;;OAOG;IACH,KAAK,CAAC,CAAC,CAAC,EAAE,kBAAkB;IAK5B,IAAI,SAAS,YAEZ;IAED,kBAAkB,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC,YAAY,CAAC,EAAE;IAsCzE,OAAO,CAAC,eAAe;IAyBvB,SAAS,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,SAAS,CAAC;IAEnE,OAAO,CAAC,4BAA4B,CAKlC;IAEF,OAAO,CAAC,uBAAuB,CAQ7B;IAEF,OAAO,IAAI,IAAI;CAIhB;AAED,eAAO,MAAM,UAAU,GACrB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,QAAQ,UAAU,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,qDAC3C,CAAC;AAEtB;;GAEG;AACH,qBAAa,QAAQ,CACnB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,CACjC,SAAQ,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC;CAAG"}
@@ -1,4 +1,5 @@
1
1
  import { DeepPartial, FieldError, FieldPath, FieldValues, SubmitErrorHandler, SubmitHandler, UseFormProps } from 'react-hook-form';
2
+ import { MaybeFn } from 'yummies/types';
2
3
  import { Form } from './form.js';
3
4
  export type AnyForm = Form<any, any, any>;
4
5
  /**
@@ -12,7 +13,7 @@ export interface FormParams<TFieldValues extends FieldValues = FieldValues, TCon
12
13
  /**
13
14
  * Async is not supported
14
15
  */
15
- defaultValues?: DeepPartial<TFieldValues>;
16
+ defaultValues?: MaybeFn<DeepPartial<TFieldValues>>;
16
17
  /**
17
18
  * Abort signal for mobx form
18
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"form.types.d.ts","sourceRoot":"","sources":["../../src/form/form.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,UAAU,CACzB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,CACjC,SAAQ,IAAI,CACV,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACxD,eAAe,CAChB;IACD;;OAEG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IAC1C;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;OAEG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAC7C;;OAEG;IACH,cAAc,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAClD;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,WAAW,G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CACnB"}
package/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),e=require("mobx-react-lite"),r=require("react-hook-form"),i=require("linked-abort-controller"),s=require("mobx"),o=require("yummies/mobx"),a=require("yummies/type-guard"),l=t=>a.typeGuard.isObject(t)&&"type"in t;class d{values;isDirty=!1;isLoading=!1;isSubmitted=!1;isSubmitSuccessful=!1;isSubmitting=!1;isValidating=!1;isValid=!1;disabled=!1;submitCount=0;defaultValues;dirtyFields;touchedFields;validatingFields;errors;isReady=!1;setError;clearErrors;trigger;resetField;unregister;control;register;setFocus;setValue;getValues;resetForm;abortController;originalForm;_observableStruct;shouldFocusError;config;forceFormUpdate;constructor(t){this.abortController=new i.LinkedAbortController(t.abortSignal),this.shouldFocusError=t.shouldFocusError??!0,this.forceFormUpdate=!1,this.config={...t,defaultValues:{...t.defaultValues}},Object.defineProperty(this.config,"shouldFocusError",{get:()=>this.shouldFocusError}),this.originalForm=r.createFormControl(this.config);const e=t.defaultValues?{...t.defaultValues}:{};this.setError=(...t)=>(this.forceFormUpdate=!0,this.originalForm.setError(...t)),this.clearErrors=(...t)=>(this.forceFormUpdate=!0,this.originalForm.clearErrors(...t)),this.trigger=this.originalForm.trigger,this.resetField=(...t)=>(this.forceFormUpdate=!0,this.originalForm.resetField(...t)),this.unregister=this.originalForm.unregister,this.control=this.originalForm.control,this.register=this.originalForm.register,this.setFocus=this.originalForm.setFocus,this.setValue=(...t)=>(this.forceFormUpdate=!0,this.originalForm.setValue(...t)),this.getValues=this.originalForm.getValues,this.resetForm=(...t)=>(this.forceFormUpdate=!0,this.originalForm.reset(...t)),this._observableStruct=new o.DeepObservableStruct({values:this.originalForm.getValues(),errors:{},dirtyFields:{},touchedFields:{},validatingFields:{}}),this.values=this._observableStruct.data.values,this.errors=this._observableStruct.data.errors,this.validatingFields=this._observableStruct.data.validatingFields,this.dirtyFields=this._observableStruct.data.dirtyFields,this.touchedFields=this._observableStruct.data.touchedFields,Object.assign(this,{defaultValues:e});const a=this.originalForm.subscribe({formState:{values:!0,errors:!0,isValid:!0,isDirty:!0,isValidating:!0,dirtyFields:!0,touchedFields:!0,validatingFields:!0},callback:t=>{this.forceFormUpdate||!1===this.config.lazyUpdates?(this.forceFormUpdate=!1,this.updateFormState(t)):this.scheduleUpdateFormState(t)}});s.observable.ref(this,"isDirty"),s.observable.ref(this,"isLoading"),s.observable.ref(this,"isSubmitted"),s.observable.ref(this,"isSubmitSuccessful"),s.observable.ref(this,"isSubmitting"),s.observable.ref(this,"isValidating"),s.observable.ref(this,"isValid"),s.observable.ref(this,"disabled"),s.observable.ref(this,"submitCount"),s.observable.ref(this,"isReady"),s.observable.deep(this,"defaultValues"),s.computed(this,"hasErrors"),s.action(this,"updateFormState"),s.observable.ref(this,"originalForm"),s.action.bound(this,"submit"),s.action.bound(this,"reset"),s.makeObservable(this),this.abortController.signal.addEventListener("abort",()=>{a(),this.originalForm=null})}changeField=(t,e,r)=>this.setValue(t,e,{shouldDirty:!0,shouldValidate:this.isSubmitted,...r});submit(t){return new Promise((e,r)=>{if(!this.originalForm){const t=this.values??{},r=this.config.onSubmit?.(t);return r instanceof Promise?r.then(()=>e(t)):Promise.resolve(t)}this.originalForm.handleSubmit(async(t,i)=>{if(this.config.strictSubmitChecks){const t=this.getErrorsWithPaths(!0)[0];if(t)return this.setFocus(t.path),await(this.config.onSubmitFailed?.(this.errors,i)),void r(this.errors)}await(this.config.onSubmit?.(t,i)),e(t)},async(t,e)=>{await(this.config.onSubmitFailed?.(t,e)),r(t)})(t)})}reset(t){this.resetForm(),this.config.onReset?.(t)}get hasErrors(){return Object.keys(this.errors).length>0}getErrorsWithPaths(t){const e=[],r=(i,s="")=>{i&&"object"==typeof i&&Object.entries(i).forEach(([i,o])=>{const a=s?`${s}.${i}`:i;if(l(o)){if(e.push({path:a,error:o}),t)return}else Array.isArray(o)?o.forEach((i,s)=>{const o=`${a}.${s}`;if(l(i)){if(e.push({path:o,error:i}),t)return}else"object"==typeof i&&r(i,o)}):"object"==typeof o&&r(o,a)})};return r(this.errors),e}updateFormState({values:t,errors:e,dirtyFields:r,validatingFields:i,touchedFields:s,...o}){this.stopScheduledFormStateUpdate(),Object.entries(o).forEach(([t,e])=>{null!=e&&(this[t]=e)}),this._observableStruct.set({dirtyFields:r,errors:e,touchedFields:s,validatingFields:i,values:t})}lastTimeoutId;stopScheduledFormStateUpdate=()=>{void 0!==this.lastTimeoutId&&(clearTimeout(this.lastTimeoutId),this.lastTimeoutId=void 0)};scheduleUpdateFormState=t=>{this.stopScheduledFormStateUpdate(),this.lastTimeoutId=setTimeout(()=>{this.updateFormState(t),this.lastTimeoutId=void 0},this.config.lazyUpdatesTimer??0)};destroy(){this.abortController.abort(),this.stopScheduledFormStateUpdate()}}exports.Controller=i=>t.jsx(r.Controller,{...i,render:r=>t.jsx(e.Observer,{children:()=>i.render(r)})}),exports.Form=d,exports.MobxForm=class extends d{},exports.createForm=t=>new d(t),exports.isFieldError=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),e=require("mobx-react-lite"),r=require("react-hook-form"),s=require("linked-abort-controller"),i=require("mobx"),o=require("yummies/mobx"),a=require("yummies/type-guard"),l=t=>a.typeGuard.isObject(t)&&"type"in t;class h{values;isDirty=!1;isLoading=!1;isSubmitted=!1;isSubmitSuccessful=!1;isSubmitting=!1;isValidating=!1;isValid=!1;disabled=!1;submitCount=0;defaultValues;dirtyFields;touchedFields;validatingFields;errors;isReady=!1;setError;clearErrors;trigger;resetField;unregister;control;register;setFocus;setValue;getValues;resetForm;abortController;originalForm;_observableStruct;shouldFocusError;config;forceFormUpdate;constructor(t){this.abortController=new s.LinkedAbortController(t.abortSignal),this.shouldFocusError=t.shouldFocusError??!0,this.forceFormUpdate=!1;const e=t.defaultValues,a="function"==typeof e,l=a?e():e?{...e}:{};this.config={...t,defaultValues:{...l},shouldFocusError:this.shouldFocusError},this.originalForm=r.createFormControl(this.config),Object.defineProperty(this.originalForm.control._options,"shouldFocusError",{get:()=>this.shouldFocusError}),this.setError=(...t)=>(this.forceFormUpdate=!0,this.originalForm.setError(...t)),this.clearErrors=(...t)=>(this.forceFormUpdate=!0,this.originalForm.clearErrors(...t)),this.trigger=this.originalForm.trigger,this.resetField=(...t)=>(this.forceFormUpdate=!0,this.originalForm.resetField(...t)),this.unregister=this.originalForm.unregister,this.control=this.originalForm.control,this.register=this.originalForm.register,this.setFocus=this.originalForm.setFocus,this.setValue=(...t)=>(this.forceFormUpdate=!0,this.originalForm.setValue(...t)),this.getValues=this.originalForm.getValues,this.resetForm=(...t)=>(this.forceFormUpdate=!0,this.originalForm.reset(...t)),this._observableStruct=new o.DeepObservableStruct({values:this.originalForm.getValues(),errors:{},dirtyFields:{},touchedFields:{},validatingFields:{}}),this.values=this._observableStruct.data.values,this.errors=this._observableStruct.data.errors,this.validatingFields=this._observableStruct.data.validatingFields,this.dirtyFields=this._observableStruct.data.dirtyFields,this.touchedFields=this._observableStruct.data.touchedFields,this.defaultValues=l;const h=this.originalForm.subscribe({formState:{values:!0,errors:!0,isValid:!0,isDirty:!0,isValidating:!0,dirtyFields:!0,touchedFields:!0,validatingFields:!0},callback:t=>{this.forceFormUpdate||!1===this.config.lazyUpdates?(this.forceFormUpdate=!1,this.updateFormState(t)):this.scheduleUpdateFormState(t)}});i.observable.ref(this,"isDirty"),i.observable.ref(this,"isLoading"),i.observable.ref(this,"isSubmitted"),i.observable.ref(this,"isSubmitSuccessful"),i.observable.ref(this,"isSubmitting"),i.observable.ref(this,"isValidating"),i.observable.ref(this,"isValid"),i.observable.ref(this,"disabled"),i.observable.ref(this,"submitCount"),i.observable.ref(this,"isReady"),i.observable.deep(this,"defaultValues"),i.computed(this,"hasErrors"),i.action(this,"updateFormState"),i.observable.ref(this,"originalForm"),i.action.bound(this,"submit"),i.action.bound(this,"reset"),i.makeObservable(this),a&&i.reaction(()=>e(),t=>{this.resetForm(t)},{signal:this.abortController.signal,equals:i.comparer.structural}),this.abortController.signal.addEventListener("abort",()=>{h(),this.originalForm=null})}changeField=(t,e,r)=>this.setValue(t,e,{shouldDirty:!0,shouldValidate:this.isSubmitted,...r});submit(t){return new Promise((e,r)=>{if(!this.originalForm){const t=this.values??{},r=this.config.onSubmit?.(t);return r instanceof Promise?r.then(()=>e(t)):Promise.resolve(t)}this.originalForm.handleSubmit(async(t,s)=>{if(this.config.strictSubmitChecks){const t=this.getErrorsWithPaths(!0)[0];if(t)return this.setFocus(t.path),await(this.config.onSubmitFailed?.(this.errors,s)),void r(this.errors)}await(this.config.onSubmit?.(t,s)),e(t)},async(t,e)=>{await(this.config.onSubmitFailed?.(t,e)),r(t)})(t)})}reset(t){this.resetForm(),this.config.onReset?.(t)}get hasErrors(){return Object.keys(this.errors).length>0}getErrorsWithPaths(t){const e=[],r=(s,i="")=>{s&&"object"==typeof s&&Object.entries(s).forEach(([s,o])=>{const a=i?`${i}.${s}`:s;if(l(o)){if(e.push({path:a,error:o}),t)return}else Array.isArray(o)?o.forEach((s,i)=>{const o=`${a}.${i}`;if(l(s)){if(e.push({path:o,error:s}),t)return}else"object"==typeof s&&r(s,o)}):"object"==typeof o&&r(o,a)})};return r(this.errors),e}updateFormState({values:t,errors:e,dirtyFields:r,validatingFields:s,touchedFields:i,...o}){this.stopScheduledFormStateUpdate(),Object.entries(o).forEach(([t,e])=>{null!=e&&(this[t]=e)}),this._observableStruct.set({dirtyFields:r,errors:e,touchedFields:i,validatingFields:s,values:t})}lastTimeoutId;stopScheduledFormStateUpdate=()=>{void 0!==this.lastTimeoutId&&(clearTimeout(this.lastTimeoutId),this.lastTimeoutId=void 0)};scheduleUpdateFormState=t=>{this.stopScheduledFormStateUpdate(),this.lastTimeoutId=setTimeout(()=>{this.updateFormState(t),this.lastTimeoutId=void 0},this.config.lazyUpdatesTimer??0)};destroy(){this.abortController.abort(),this.stopScheduledFormStateUpdate()}}exports.Controller=s=>t.jsx(r.Controller,{...s,render:r=>t.jsx(e.Observer,{children:()=>s.render(r)})}),exports.Form=h,exports.MobxForm=class extends h{},exports.createForm=t=>new h(t),exports.isFieldError=l;
2
2
  //# sourceMappingURL=index.cjs.map
package/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/utils/is-field-error.ts","../src/form/form.ts","../src/components/controller.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport { action, computed, makeObservable, observable } from 'mobx';\nimport type { BaseSyntheticEvent } from 'react';\nimport {\n type Control,\n createFormControl,\n type DeepMap,\n type DeepPartial,\n type DefaultValues,\n type FieldErrors,\n type FieldPath,\n type FieldPathValue,\n type FieldValues,\n type FormState,\n type SetValueConfig,\n type UseFormClearErrors,\n type UseFormGetValues,\n type UseFormRegister,\n type UseFormReset,\n type UseFormResetField,\n type UseFormSetError,\n type UseFormSetFocus,\n type UseFormSetValue,\n type UseFormTrigger,\n type UseFormUnregister,\n} from 'react-hook-form';\nimport { DeepObservableStruct } from 'yummies/mobx';\nimport { isFieldError } from '../utils/index.js';\nimport type { ErrorWithPath, FormParams } from './form.types.js';\n\ntype FormFullState<TFieldValues extends FieldValues> =\n FormState<TFieldValues> & {\n values: TFieldValues;\n };\n\nexport class Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> implements FormFullState<TFieldValues>\n{\n values: TFieldValues;\n isDirty: boolean = false;\n isLoading: boolean = false;\n isSubmitted: boolean = false;\n isSubmitSuccessful: boolean = false;\n isSubmitting: boolean = false;\n isValidating: boolean = false;\n isValid: boolean = false;\n disabled: boolean = false;\n submitCount: number = 0;\n /**\n * If you want to change this property\n * Use {resetForm} method\n */\n defaultValues!: Readonly<DefaultValues<TFieldValues>>;\n dirtyFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n touchedFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n validatingFields: Partial<\n Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>\n >;\n errors: FieldErrors<TFieldValues>;\n isReady: boolean = false;\n\n /**\n * Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)\n *\n * @param name - the path name to the form field value.\n * @param error - an error object which contains type and optional message\n * @param options - whether or not to focus on the field\n *\n * @example\n * ```tsx\n * // when the error is not associated with any fields, `clearError` will need to invoke to clear the error\n * const onSubmit = () => setError(\"serverError\", { type: \"server\", message: \"Error occurred\"})\n *\n * <button onClick={() => setError(\"name\", { type: \"min\" })} />\n *\n * // focus on the input after setting the error\n * <button onClick={() => setError(\"name\", { type: \"max\" }, { shouldFocus: true })} />\n * ```\n */\n setError: UseFormSetError<TFieldValues>;\n\n /**\n * Clear the entire form errors.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)\n *\n * @param name - the path name to the form field value.\n *\n * @example\n * Clear all errors\n * ```tsx\n * clearErrors(); // clear the entire form error\n * clearErrors([\"name\", \"name1\"]) // clear an array of fields' error\n * clearErrors(\"name2\"); // clear a single field error\n * ```\n */\n clearErrors: UseFormClearErrors<TFieldValues>;\n\n /**\n * Trigger field or form validation\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)\n *\n * @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an array of fields, and a single field name will only trigger that field's validation.\n * @param options - should focus on the error field\n *\n * @returns validation result\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * trigger();\n * }, [trigger])\n *\n * <button onClick={async () => {\n * const result = await trigger(); // result will be a boolean value\n * }}>\n * trigger\n * </button>\n * ```\n */\n trigger: UseFormTrigger<TFieldValues>;\n\n /**\n * Reset a field state and reference.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * <input {...register(\"firstName\", { required: true })} />\n * <button type=\"button\" onClick={() => resetField(\"firstName\"))}>Reset</button>\n * ```\n */\n resetField: UseFormResetField<TFieldValues>;\n\n /**\n * Unregister a field reference and remove its value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * register(\"name\", { required: true })\n *\n * <button onClick={() => unregister(\"name\")} />\n * // there are various keep options to retain formState\n * <button onClick={() => unregister(\"name\", { keepErrors: true })} />\n * ```\n */\n unregister: UseFormUnregister<TFieldValues>;\n\n /**\n * Form control\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/control)\n *\n */\n control: Control<TFieldValues, TContext, TTransformedValues>;\n\n /**\n * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)\n *\n * @param name - the path name to the form field value, name is required and unique\n * @param options - register options include validation, disabled, unregister, value as and dependent validation\n *\n * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.\n *\n * @example\n * ```tsx\n * // Register HTML native input\n * <input {...register(\"input\")} />\n * <select {...register(\"select\")} />\n *\n * // Register options\n * <textarea {...register(\"textarea\", { required: \"This is required.\", maxLength: 20 })} />\n * <input type=\"number\" {...register(\"name2\", { valueAsNumber: true })} />\n * <input {...register(\"name3\", { deps: [\"name2\"] })} />\n *\n * // Register custom field at useEffect\n * useEffect(() => {\n * register(\"name4\");\n * register(\"name5\", { value: \"hiddenValue\" });\n * }, [register])\n *\n * // Register without ref\n * const { onChange, onBlur, name } = register(\"name6\")\n * <input onChange={onChange} onBlur={onBlur} name={name} />\n * ```\n */\n register: UseFormRegister<TFieldValues>;\n\n /**\n * Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)\n *\n * @param name - the path name to the form field value.\n * @param options - input focus behavior options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * setFocus(\"name\");\n * }, [setFocus])\n * // shouldSelect allows to select input's content on focus\n * <button onClick={() => setFocus(\"name\", { shouldSelect: true })}>Focus</button>\n * ```\n */\n setFocus: UseFormSetFocus<TFieldValues>;\n\n /**\n * Set a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * setValue('name', 'value', {\n * shouldValidate: true, // trigger validation\n * shouldTouch: true, // update touched fields form state\n * shouldDirty: true, // update dirty and dirty fields form state\n * });\n *\n * // Update a group fields\n * setValue('root', {\n * a: 'test', // setValue('root.a', 'data')\n * b: 'test1', // setValue('root.b', 'data')\n * });\n *\n * // Update a nested object field\n * setValue('select', { label: 'test', value: 'Test' });\n * ```\n */\n setValue: UseFormSetValue<TFieldValues>;\n\n /**\n * Get a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)\n *\n * @param fieldNames - the path name to the form field value.\n * @param options - returns only dirty fields or return only touchedFields\n *\n * @example\n * ```tsx\n * // Update a single field\n * getValues('name', 'value', {\n * dirtyFields: true, // returns only dirty fields\n * touchedFields: true, // returns only touchedFields\n * });\n *\n * // Get nested values\n * getValues('root.nested.0.value');\n * ```\n */\n getValues: UseFormGetValues<TFieldValues>;\n\n /**\n * Reset at the entire form state.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)\n *\n * @param values - the entire form values to be reset\n * @param keepStateOptions - keep form state options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * // reset the entire form after component mount or form defaultValues is ready\n * reset({\n * fieldA: \"test\"\n * fieldB: \"test\"\n * });\n * }, [reset])\n *\n * // reset by combine with existing form values\n * reset({\n * ...getValues(),\n * fieldB: \"test\"\n *});\n *\n * // reset and keep form state\n * reset({\n * ...getValues(),\n *}, {\n * keepErrors: true,\n * keepDirty: true\n *});\n * ```\n */\n resetForm: UseFormReset<TFieldValues>;\n\n protected abortController: AbortController;\n\n /**\n * Original react-hook-form form\n */\n originalForm: ReturnType<\n typeof createFormControl<TFieldValues, TContext, TTransformedValues>\n >;\n\n private _observableStruct: DeepObservableStruct<\n Pick<\n FormFullState<TFieldValues>,\n 'dirtyFields' | 'errors' | 'touchedFields' | 'validatingFields' | 'values'\n >\n >;\n\n shouldFocusError: boolean;\n\n private config: FormParams<TFieldValues, TContext, TTransformedValues>;\n\n // special hack to apply the same form value changes from the original form\n // using subscription\n private forceFormUpdate: boolean;\n\n constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\n this.forceFormUpdate = false;\n\n this.config = {\n ...config,\n defaultValues: {\n ...config.defaultValues,\n } as DefaultValues<TFieldValues>,\n };\n\n Object.defineProperty(this.config, 'shouldFocusError', {\n get: () => this.shouldFocusError,\n });\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n const defaultValues = config.defaultValues\n ? { ...config.defaultValues }\n : ({} as any);\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n\n Object.assign(this, {\n defaultValues,\n });\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (rawFormState) => {\n if (this.forceFormUpdate || this.config.lazyUpdates === false) {\n this.forceFormUpdate = false;\n this.updateFormState(rawFormState);\n } else {\n this.scheduleUpdateFormState(rawFormState);\n }\n },\n });\n\n observable.ref(this, 'isDirty');\n observable.ref(this, 'isLoading');\n observable.ref(this, 'isSubmitted');\n observable.ref(this, 'isSubmitSuccessful');\n observable.ref(this, 'isSubmitting');\n observable.ref(this, 'isValidating');\n observable.ref(this, 'isValid');\n observable.ref(this, 'disabled');\n observable.ref(this, 'submitCount');\n observable.ref(this, 'isReady');\n observable.deep(this, 'defaultValues');\n computed(this, 'hasErrors');\n action(this, 'updateFormState');\n\n observable.ref(this, 'originalForm');\n action.bound(this, 'submit');\n action.bound(this, 'reset');\n\n makeObservable(this);\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n // @ts-expect-error\n this.originalForm = null;\n });\n }\n\n /**\n * The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty\n * It should work the same as field.onChange from react-hook-form's Controller\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true });\n *\n * ** form submitted **\n *\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true, shouldValidate: true });\n * ```\n */\n changeField = <\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n >(\n name: TFieldName,\n value: FieldPathValue<TFieldValues, TFieldName> | undefined,\n options?: SetValueConfig,\n ) => {\n return this.setValue(name, value as any, {\n shouldDirty: true,\n shouldValidate: this.isSubmitted,\n ...options,\n });\n };\n\n /**\n * Method to manually submit form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onSubmit={form.submit} />\n */\n submit(e?: BaseSyntheticEvent) {\n return new Promise<TTransformedValues>((resolve, reject) => {\n if (this.originalForm) {\n this.originalForm.handleSubmit(\n async (data, event) => {\n if (this.config.strictSubmitChecks) {\n const anyErrorWithPath = this.getErrorsWithPaths(true)[0];\n if (anyErrorWithPath) {\n this.setFocus(anyErrorWithPath.path);\n await this.config.onSubmitFailed?.(this.errors, event);\n reject(this.errors);\n return;\n }\n }\n await this.config.onSubmit?.(data, event);\n resolve(data);\n },\n async (errors, event) => {\n await this.config.onSubmitFailed?.(errors, event);\n reject(errors);\n },\n )(e);\n } else {\n const emptyData = (this.values ?? {}) as unknown as TTransformedValues;\n const result = this.config.onSubmit?.(emptyData);\n if (result instanceof Promise) {\n return result.then(() => resolve(emptyData));\n } else {\n return Promise.resolve(emptyData);\n }\n }\n });\n }\n\n /**\n * Method to manually reset all form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onReset={form.reset} />\n */\n reset(e?: BaseSyntheticEvent) {\n this.resetForm();\n this.config.onReset?.(e);\n }\n\n get hasErrors() {\n return Object.keys(this.errors).length > 0;\n }\n\n getErrorsWithPaths(getOnlyFirst?: boolean): ErrorWithPath<TFieldValues>[] {\n const result: ErrorWithPath<TFieldValues>[] = [];\n\n const traverse = (obj: any, prefix = '') => {\n if (!obj || typeof obj !== 'object') return;\n\n Object.entries(obj).forEach(([key, value]) => {\n const path = (prefix ? `${prefix}.${key}` : key) as any;\n\n if (isFieldError(value)) {\n result.push({ path, error: value });\n if (getOnlyFirst) {\n return;\n }\n } else if (Array.isArray(value)) {\n value.forEach((item, idx) => {\n const arrayPath = `${path}.${idx}` as any;\n\n if (isFieldError(item)) {\n result.push({ path: arrayPath, error: item });\n if (getOnlyFirst) {\n return;\n }\n } else if (typeof item === 'object') {\n traverse(item, arrayPath);\n }\n });\n } else if (typeof value === 'object') {\n traverse(value, path);\n }\n });\n };\n\n traverse(this.errors);\n\n return result;\n }\n\n private updateFormState({\n values,\n errors,\n dirtyFields,\n validatingFields,\n touchedFields,\n ...simpleProperties\n }: Partial<FormFullState<TFieldValues>>) {\n this.stopScheduledFormStateUpdate();\n Object.entries(simpleProperties).forEach(([key, value]) => {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n });\n\n this._observableStruct.set({\n dirtyFields,\n errors,\n touchedFields,\n validatingFields,\n values,\n });\n }\n\n protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n private stopScheduledFormStateUpdate = () => {\n if (this.lastTimeoutId !== undefined) {\n clearTimeout(this.lastTimeoutId);\n this.lastTimeoutId = undefined;\n }\n };\n\n private scheduleUpdateFormState = (\n rawFormState: Partial<FormFullState<TFieldValues>>,\n ) => {\n this.stopScheduledFormStateUpdate();\n this.lastTimeoutId = setTimeout(() => {\n this.updateFormState(rawFormState);\n this.lastTimeoutId = undefined;\n }, this.config.lazyUpdatesTimer ?? 0);\n };\n\n destroy(): void {\n this.abortController.abort();\n this.stopScheduledFormStateUpdate();\n }\n}\n\nexport const createForm = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n config: FormParams<TFieldValues, TContext, TTransformedValues>,\n) => new Form(config);\n\n/**\n * @deprecated ⚠️ use `Form`. This export will be removed in next major release\n */\nexport class MobxForm<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> extends Form<TFieldValues, TContext, TTransformedValues> {}\n","import { Observer } from 'mobx-react-lite';\nimport { Controller as LibController } from 'react-hook-form';\n\nexport const Controller = ((props: any) => (\n <LibController\n {...props}\n render={(renderProps) => (\n <Observer>{() => props.render(renderProps)}</Observer>\n )}\n />\n)) as unknown as typeof LibController;\n"],"names":["isFieldError","value","typeGuard","isObject","Form","values","isDirty","isLoading","isSubmitted","isSubmitSuccessful","isSubmitting","isValidating","isValid","disabled","submitCount","defaultValues","dirtyFields","touchedFields","validatingFields","errors","isReady","setError","clearErrors","trigger","resetField","unregister","control","register","setFocus","setValue","getValues","resetForm","abortController","originalForm","_observableStruct","shouldFocusError","config","forceFormUpdate","constructor","this","LinkedAbortController","abortSignal","Object","defineProperty","get","createFormControl","args","reset","DeepObservableStruct","data","assign","subscription","subscribe","formState","callback","rawFormState","lazyUpdates","updateFormState","scheduleUpdateFormState","observable","ref","deep","computed","action","bound","makeObservable","signal","addEventListener","changeField","name","options","shouldDirty","shouldValidate","submit","e","Promise","resolve","reject","emptyData","result","onSubmit","then","handleSubmit","async","event","strictSubmitChecks","anyErrorWithPath","getErrorsWithPaths","path","onSubmitFailed","onReset","hasErrors","keys","length","getOnlyFirst","traverse","obj","prefix","entries","forEach","key","push","error","Array","isArray","item","idx","arrayPath","simpleProperties","stopScheduledFormStateUpdate","set","lastTimeoutId","clearTimeout","setTimeout","lazyUpdatesTimer","destroy","abort","props","jsx","LibController","render","renderProps","Observer","children"],"mappings":"gSAGaA,EAAgBC,GACpBC,EAAAA,UAAUC,SAASF,IAAU,SAAUA,EC+BzC,MAAMG,EAMXC,OACAC,SAAmB,EACnBC,WAAqB,EACrBC,aAAuB,EACvBC,oBAA8B,EAC9BC,cAAwB,EACxBC,cAAwB,EACxBC,SAAmB,EACnBC,UAAoB,EACpBC,YAAsB,EAKtBC,cACAC,YACAC,cACAC,iBAGAC,OACAC,SAAmB,EAuBnBC,SAkBAC,YA0BAC,QAiBAC,WAoBAC,WASAC,QAmCAC,SAoBAC,SA+BAC,SAuBAC,UAoCAC,UAEUC,gBAKVC,aAIQC,kBAORC,iBAEQC,OAIAC,gBAER,WAAAC,CAAYF,GACVG,KAAKP,gBAAkB,IAAIQ,wBAAsBJ,EAAOK,aAExDF,KAAKJ,iBAAmBC,EAAOD,mBAAoB,EACnDI,KAAKF,iBAAkB,EAEvBE,KAAKH,OAAS,IACTA,EACHrB,cAAe,IACVqB,EAAOrB,gBAId2B,OAAOC,eAAeJ,KAAKH,OAAQ,mBAAoB,CACrDQ,IAAK,IAAML,KAAKJ,mBAGlBI,KAAKN,aAAeY,oBAIlBN,KAAKH,QAEP,MAAMrB,EAAgBqB,EAAOrB,cACzB,IAAKqB,EAAOrB,eACX,CAAA,EAELwB,KAAKlB,SAAW,IAAIyB,KAClBP,KAAKF,iBAAkB,EAChBE,KAAKN,aAAaZ,YAAYyB,IAEvCP,KAAKjB,YAAc,IAAIwB,KACrBP,K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,6BAA+B,UACV,IAAvBtE,KAAKwE,gBACPC,aAAazE,KAAKwE,eAClBxE,KAAKwE,mBAAgB,IAIjBrD,wBACNH,IAEAhB,KAAKsE,+BACLtE,KAAKwE,cAAgBE,WAAW,KAC9B1E,KAAKkB,gBAAgBF,GACrBhB,KAAKwE,mBAAgB,GACpBxE,KAAKH,OAAO8E,kBAAoB,IAGrC,OAAAC,GACE5E,KAAKP,gBAAgBoF,QACrB7E,KAAKsE,8BACP,qBCnoB0BQ,GAC1BC,EAAAA,IAACC,EAAAA,WAAA,IACKF,EACJG,OAASC,GACPH,EAAAA,IAACI,EAAAA,UAAUC,SAAA,IAAMN,EAAMG,OAAOC,uCD6oB7B,cAIGrH,uBAVRgC,GACG,IAAIhC,EAAKgC"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils/is-field-error.ts","../src/form/form.ts","../src/components/controller.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport {\n action,\n comparer,\n computed,\n makeObservable,\n observable,\n reaction,\n} from 'mobx';\nimport type { BaseSyntheticEvent } from 'react';\nimport {\n type Control,\n createFormControl,\n type DeepMap,\n type DeepPartial,\n type DefaultValues,\n type FieldErrors,\n type FieldPath,\n type FieldPathValue,\n type FieldValues,\n type FormState,\n type SetValueConfig,\n type UseFormClearErrors,\n type UseFormGetValues,\n type UseFormRegister,\n type UseFormReset,\n type UseFormResetField,\n type UseFormSetError,\n type UseFormSetFocus,\n type UseFormSetValue,\n type UseFormTrigger,\n type UseFormUnregister,\n} from 'react-hook-form';\nimport { DeepObservableStruct } from 'yummies/mobx';\nimport { isFieldError } from '../utils/index.js';\nimport type { ErrorWithPath, FormParams } from './form.types.js';\n\ntype FormFullState<TFieldValues extends FieldValues> =\n FormState<TFieldValues> & {\n values: TFieldValues;\n };\n\nexport class Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> implements FormFullState<TFieldValues>\n{\n values: TFieldValues;\n isDirty: boolean = false;\n isLoading: boolean = false;\n isSubmitted: boolean = false;\n isSubmitSuccessful: boolean = false;\n isSubmitting: boolean = false;\n isValidating: boolean = false;\n isValid: boolean = false;\n disabled: boolean = false;\n submitCount: number = 0;\n /**\n * If you want to change this property\n * Use {resetForm} method\n */\n defaultValues: Readonly<DefaultValues<TFieldValues>>;\n dirtyFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n touchedFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n validatingFields: Partial<\n Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>\n >;\n errors: FieldErrors<TFieldValues>;\n isReady: boolean = false;\n\n /**\n * Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)\n *\n * @param name - the path name to the form field value.\n * @param error - an error object which contains type and optional message\n * @param options - whether or not to focus on the field\n *\n * @example\n * ```tsx\n * // when the error is not associated with any fields, `clearError` will need to invoke to clear the error\n * const onSubmit = () => setError(\"serverError\", { type: \"server\", message: \"Error occurred\"})\n *\n * <button onClick={() => setError(\"name\", { type: \"min\" })} />\n *\n * // focus on the input after setting the error\n * <button onClick={() => setError(\"name\", { type: \"max\" }, { shouldFocus: true })} />\n * ```\n */\n setError: UseFormSetError<TFieldValues>;\n\n /**\n * Clear the entire form errors.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)\n *\n * @param name - the path name to the form field value.\n *\n * @example\n * Clear all errors\n * ```tsx\n * clearErrors(); // clear the entire form error\n * clearErrors([\"name\", \"name1\"]) // clear an array of fields' error\n * clearErrors(\"name2\"); // clear a single field error\n * ```\n */\n clearErrors: UseFormClearErrors<TFieldValues>;\n\n /**\n * Trigger field or form validation\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)\n *\n * @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an array of fields, and a single field name will only trigger that field's validation.\n * @param options - should focus on the error field\n *\n * @returns validation result\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * trigger();\n * }, [trigger])\n *\n * <button onClick={async () => {\n * const result = await trigger(); // result will be a boolean value\n * }}>\n * trigger\n * </button>\n * ```\n */\n trigger: UseFormTrigger<TFieldValues>;\n\n /**\n * Reset a field state and reference.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * <input {...register(\"firstName\", { required: true })} />\n * <button type=\"button\" onClick={() => resetField(\"firstName\"))}>Reset</button>\n * ```\n */\n resetField: UseFormResetField<TFieldValues>;\n\n /**\n * Unregister a field reference and remove its value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * register(\"name\", { required: true })\n *\n * <button onClick={() => unregister(\"name\")} />\n * // there are various keep options to retain formState\n * <button onClick={() => unregister(\"name\", { keepErrors: true })} />\n * ```\n */\n unregister: UseFormUnregister<TFieldValues>;\n\n /**\n * Form control\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/control)\n *\n */\n control: Control<TFieldValues, TContext, TTransformedValues>;\n\n /**\n * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)\n *\n * @param name - the path name to the form field value, name is required and unique\n * @param options - register options include validation, disabled, unregister, value as and dependent validation\n *\n * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.\n *\n * @example\n * ```tsx\n * // Register HTML native input\n * <input {...register(\"input\")} />\n * <select {...register(\"select\")} />\n *\n * // Register options\n * <textarea {...register(\"textarea\", { required: \"This is required.\", maxLength: 20 })} />\n * <input type=\"number\" {...register(\"name2\", { valueAsNumber: true })} />\n * <input {...register(\"name3\", { deps: [\"name2\"] })} />\n *\n * // Register custom field at useEffect\n * useEffect(() => {\n * register(\"name4\");\n * register(\"name5\", { value: \"hiddenValue\" });\n * }, [register])\n *\n * // Register without ref\n * const { onChange, onBlur, name } = register(\"name6\")\n * <input onChange={onChange} onBlur={onBlur} name={name} />\n * ```\n */\n register: UseFormRegister<TFieldValues>;\n\n /**\n * Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)\n *\n * @param name - the path name to the form field value.\n * @param options - input focus behavior options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * setFocus(\"name\");\n * }, [setFocus])\n * // shouldSelect allows to select input's content on focus\n * <button onClick={() => setFocus(\"name\", { shouldSelect: true })}>Focus</button>\n * ```\n */\n setFocus: UseFormSetFocus<TFieldValues>;\n\n /**\n * Set a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * setValue('name', 'value', {\n * shouldValidate: true, // trigger validation\n * shouldTouch: true, // update touched fields form state\n * shouldDirty: true, // update dirty and dirty fields form state\n * });\n *\n * // Update a group fields\n * setValue('root', {\n * a: 'test', // setValue('root.a', 'data')\n * b: 'test1', // setValue('root.b', 'data')\n * });\n *\n * // Update a nested object field\n * setValue('select', { label: 'test', value: 'Test' });\n * ```\n */\n setValue: UseFormSetValue<TFieldValues>;\n\n /**\n * Get a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)\n *\n * @param fieldNames - the path name to the form field value.\n * @param options - returns only dirty fields or return only touchedFields\n *\n * @example\n * ```tsx\n * // Update a single field\n * getValues('name', 'value', {\n * dirtyFields: true, // returns only dirty fields\n * touchedFields: true, // returns only touchedFields\n * });\n *\n * // Get nested values\n * getValues('root.nested.0.value');\n * ```\n */\n getValues: UseFormGetValues<TFieldValues>;\n\n /**\n * Reset at the entire form state.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)\n *\n * @param values - the entire form values to be reset\n * @param keepStateOptions - keep form state options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * // reset the entire form after component mount or form defaultValues is ready\n * reset({\n * fieldA: \"test\"\n * fieldB: \"test\"\n * });\n * }, [reset])\n *\n * // reset by combine with existing form values\n * reset({\n * ...getValues(),\n * fieldB: \"test\"\n *});\n *\n * // reset and keep form state\n * reset({\n * ...getValues(),\n *}, {\n * keepErrors: true,\n * keepDirty: true\n *});\n * ```\n */\n resetForm: UseFormReset<TFieldValues>;\n\n protected abortController: AbortController;\n\n /**\n * Original react-hook-form form\n */\n originalForm: ReturnType<\n typeof createFormControl<TFieldValues, TContext, TTransformedValues>\n >;\n\n private _observableStruct: DeepObservableStruct<\n Pick<\n FormFullState<TFieldValues>,\n 'dirtyFields' | 'errors' | 'touchedFields' | 'validatingFields' | 'values'\n >\n >;\n\n shouldFocusError: boolean;\n\n private config: FormParams<TFieldValues, TContext, TTransformedValues>;\n\n // special hack to apply the same form value changes from the original form\n // using subscription\n private forceFormUpdate: boolean;\n\n constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\n this.forceFormUpdate = false;\n\n const defaultValuesRaw = config.defaultValues;\n const isDefaultValuesRawFn = typeof defaultValuesRaw === 'function';\n\n const defaultValues = isDefaultValuesRawFn\n ? defaultValuesRaw()\n : defaultValuesRaw\n ? { ...defaultValuesRaw }\n : ({} as any);\n\n this.config = {\n ...config,\n defaultValues: { ...defaultValues } as DefaultValues<TFieldValues>,\n shouldFocusError: this.shouldFocusError,\n };\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n Object.defineProperty(\n this.originalForm.control._options,\n 'shouldFocusError',\n {\n get: () => this.shouldFocusError,\n },\n );\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n this.defaultValues = defaultValues;\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (rawFormState) => {\n if (this.forceFormUpdate || this.config.lazyUpdates === false) {\n this.forceFormUpdate = false;\n this.updateFormState(rawFormState);\n } else {\n this.scheduleUpdateFormState(rawFormState);\n }\n },\n });\n\n observable.ref(this, 'isDirty');\n observable.ref(this, 'isLoading');\n observable.ref(this, 'isSubmitted');\n observable.ref(this, 'isSubmitSuccessful');\n observable.ref(this, 'isSubmitting');\n observable.ref(this, 'isValidating');\n observable.ref(this, 'isValid');\n observable.ref(this, 'disabled');\n observable.ref(this, 'submitCount');\n observable.ref(this, 'isReady');\n observable.deep(this, 'defaultValues');\n computed(this, 'hasErrors');\n action(this, 'updateFormState');\n\n observable.ref(this, 'originalForm');\n action.bound(this, 'submit');\n action.bound(this, 'reset');\n\n makeObservable(this);\n\n if (isDefaultValuesRawFn) {\n reaction(\n () => defaultValuesRaw(),\n (defaultValues) => {\n this.resetForm(defaultValues);\n },\n {\n signal: this.abortController.signal,\n equals: comparer.structural,\n },\n );\n }\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n // @ts-expect-error\n this.originalForm = null;\n });\n }\n\n /**\n * The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty\n * It should work the same as field.onChange from react-hook-form's Controller\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true });\n *\n * ** form submitted **\n *\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true, shouldValidate: true });\n * ```\n */\n changeField = <\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n >(\n name: TFieldName,\n value: FieldPathValue<TFieldValues, TFieldName> | undefined,\n options?: SetValueConfig,\n ) => {\n return this.setValue(name, value as any, {\n shouldDirty: true,\n shouldValidate: this.isSubmitted,\n ...options,\n });\n };\n\n /**\n * Method to manually submit form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onSubmit={form.submit} />\n */\n submit(e?: BaseSyntheticEvent) {\n return new Promise<TTransformedValues>((resolve, reject) => {\n if (this.originalForm) {\n this.originalForm.handleSubmit(\n async (data, event) => {\n if (this.config.strictSubmitChecks) {\n const anyErrorWithPath = this.getErrorsWithPaths(true)[0];\n if (anyErrorWithPath) {\n this.setFocus(anyErrorWithPath.path);\n await this.config.onSubmitFailed?.(this.errors, event);\n reject(this.errors);\n return;\n }\n }\n await this.config.onSubmit?.(data, event);\n resolve(data);\n },\n async (errors, event) => {\n await this.config.onSubmitFailed?.(errors, event);\n reject(errors);\n },\n )(e);\n } else {\n const emptyData = (this.values ?? {}) as unknown as TTransformedValues;\n const result = this.config.onSubmit?.(emptyData);\n if (result instanceof Promise) {\n return result.then(() => resolve(emptyData));\n } else {\n return Promise.resolve(emptyData);\n }\n }\n });\n }\n\n /**\n * Method to manually reset all form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onReset={form.reset} />\n */\n reset(e?: BaseSyntheticEvent) {\n this.resetForm();\n this.config.onReset?.(e);\n }\n\n get hasErrors() {\n return Object.keys(this.errors).length > 0;\n }\n\n getErrorsWithPaths(getOnlyFirst?: boolean): ErrorWithPath<TFieldValues>[] {\n const result: ErrorWithPath<TFieldValues>[] = [];\n\n const traverse = (obj: any, prefix = '') => {\n if (!obj || typeof obj !== 'object') return;\n\n Object.entries(obj).forEach(([key, value]) => {\n const path = (prefix ? `${prefix}.${key}` : key) as any;\n\n if (isFieldError(value)) {\n result.push({ path, error: value });\n if (getOnlyFirst) {\n return;\n }\n } else if (Array.isArray(value)) {\n value.forEach((item, idx) => {\n const arrayPath = `${path}.${idx}` as any;\n\n if (isFieldError(item)) {\n result.push({ path: arrayPath, error: item });\n if (getOnlyFirst) {\n return;\n }\n } else if (typeof item === 'object') {\n traverse(item, arrayPath);\n }\n });\n } else if (typeof value === 'object') {\n traverse(value, path);\n }\n });\n };\n\n traverse(this.errors);\n\n return result;\n }\n\n private updateFormState({\n values,\n errors,\n dirtyFields,\n validatingFields,\n touchedFields,\n ...simpleProperties\n }: Partial<FormFullState<TFieldValues>>) {\n this.stopScheduledFormStateUpdate();\n Object.entries(simpleProperties).forEach(([key, value]) => {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n });\n\n this._observableStruct.set({\n dirtyFields,\n errors,\n touchedFields,\n validatingFields,\n values,\n });\n }\n\n protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n private stopScheduledFormStateUpdate = () => {\n if (this.lastTimeoutId !== undefined) {\n clearTimeout(this.lastTimeoutId);\n this.lastTimeoutId = undefined;\n }\n };\n\n private scheduleUpdateFormState = (\n rawFormState: Partial<FormFullState<TFieldValues>>,\n ) => {\n this.stopScheduledFormStateUpdate();\n this.lastTimeoutId = setTimeout(() => {\n this.updateFormState(rawFormState);\n this.lastTimeoutId = undefined;\n }, this.config.lazyUpdatesTimer ?? 0);\n };\n\n destroy(): void {\n this.abortController.abort();\n this.stopScheduledFormStateUpdate();\n }\n}\n\nexport const createForm = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n config: FormParams<TFieldValues, TContext, TTransformedValues>,\n) => new Form(config);\n\n/**\n * @deprecated ⚠️ use `Form`. This export will be removed in next major release\n */\nexport class MobxForm<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> extends Form<TFieldValues, TContext, TTransformedValues> {}\n","import { Observer } from 'mobx-react-lite';\nimport { Controller as LibController } from 'react-hook-form';\n\nexport const Controller = ((props: any) => (\n <LibController\n {...props}\n render={(renderProps) => (\n <Observer>{() => props.render(renderProps)}</Observer>\n )}\n />\n)) as unknown as typeof LibController;\n"],"names":["isFieldError","value","typeGuard","isObject","Form","values","isDirty","isLoading","isSubmitted","isSubmitSuccessful","isSubmitting","isValidating","isValid","disabled","submitCount","defaultValues","dirtyFields","touchedFields","validatingFields","errors","isReady","setError","clearErrors","trigger","resetField","unregister","control","register","setFocus","setValue","getValues","resetForm","abortController","originalForm","_observableStruct","shouldFocusError","config","forceFormUpdate","constructor","this","LinkedAbortController","abortSignal","defaultValuesRaw","isDefaultValuesRawFn","createFormControl","Object","defineProperty","_options","get","args","reset","DeepObservableStruct","data","subscription","subscribe","formState","callback","rawFormState","lazyUpdates","updateFormState","scheduleUpdateFormState","observable","ref","deep","computed","action","bound","makeObservable","reaction","signal","equals","comparer","structural","addEventListener","changeField","name","options","shouldDirty","shouldValidate","submit","e","Promise","resolve","reject","emptyData","result","onSubmit","then","handleSubmit","async","event","strictSubmitChecks","anyErrorWithPath","getErrorsWithPaths","path","onSubmitFailed","onReset","hasErrors","keys","length","getOnlyFirst","traverse","obj","prefix","entries","forEach","key","push","error","Array","isArray","item","idx","arrayPath","simpleProperties","stopScheduledFormStateUpdate","set","lastTimeoutId","clearTimeout","setTimeout","lazyUpdatesTimer","destroy","abort","props","jsx","LibController","render","renderProps","Observer","children"],"mappings":"gSAGaA,EAAgBC,GACpBC,EAAAA,UAAUC,SAASF,IAAU,SAAUA,ECsCzC,MAAMG,EAMXC,OACAC,SAAmB,EACnBC,WAAqB,EACrBC,aAAuB,EACvBC,oBAA8B,EAC9BC,cAAwB,EACxBC,cAAwB,EACxBC,SAAmB,EACnBC,UAAoB,EACpBC,YAAsB,EAKtBC,cACAC,YACAC,cACAC,iBAGAC,OACA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EAAAA,UAAUC,SAAA,IAAMN,EAAMG,OAAOC,uCDsqB7B,cAIG3H,uBAVRgC,GACG,IAAIhC,EAAKgC"}
package/index.js CHANGED
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
2
2
  import { Observer } from "mobx-react-lite";
3
3
  import { Controller as Controller$1, createFormControl } from "react-hook-form";
4
4
  import { LinkedAbortController } from "linked-abort-controller";
5
- import { observable, computed, action, makeObservable } from "mobx";
5
+ import { observable, computed, action, makeObservable, reaction, comparer } from "mobx";
6
6
  import { DeepObservableStruct } from "yummies/mobx";
7
7
  import { typeGuard } from "yummies/type-guard";
8
8
  const Controller = ((props) => /* @__PURE__ */ jsx(
@@ -298,17 +298,22 @@ class Form {
298
298
  this.abortController = new LinkedAbortController(config.abortSignal);
299
299
  this.shouldFocusError = config.shouldFocusError ?? true;
300
300
  this.forceFormUpdate = false;
301
+ const defaultValuesRaw = config.defaultValues;
302
+ const isDefaultValuesRawFn = typeof defaultValuesRaw === "function";
303
+ const defaultValues = isDefaultValuesRawFn ? defaultValuesRaw() : defaultValuesRaw ? { ...defaultValuesRaw } : {};
301
304
  this.config = {
302
305
  ...config,
303
- defaultValues: {
304
- ...config.defaultValues
305
- }
306
+ defaultValues: { ...defaultValues },
307
+ shouldFocusError: this.shouldFocusError
306
308
  };
307
- Object.defineProperty(this.config, "shouldFocusError", {
308
- get: () => this.shouldFocusError
309
- });
310
309
  this.originalForm = createFormControl(this.config);
311
- const defaultValues = config.defaultValues ? { ...config.defaultValues } : {};
310
+ Object.defineProperty(
311
+ this.originalForm.control._options,
312
+ "shouldFocusError",
313
+ {
314
+ get: () => this.shouldFocusError
315
+ }
316
+ );
312
317
  this.setError = (...args) => {
313
318
  this.forceFormUpdate = true;
314
319
  return this.originalForm.setError(...args);
@@ -347,9 +352,7 @@ class Form {
347
352
  this.validatingFields = this._observableStruct.data.validatingFields;
348
353
  this.dirtyFields = this._observableStruct.data.dirtyFields;
349
354
  this.touchedFields = this._observableStruct.data.touchedFields;
350
- Object.assign(this, {
351
- defaultValues
352
- });
355
+ this.defaultValues = defaultValues;
353
356
  const subscription = this.originalForm.subscribe({
354
357
  formState: {
355
358
  values: true,
@@ -387,6 +390,18 @@ class Form {
387
390
  action.bound(this, "submit");
388
391
  action.bound(this, "reset");
389
392
  makeObservable(this);
393
+ if (isDefaultValuesRawFn) {
394
+ reaction(
395
+ () => defaultValuesRaw(),
396
+ (defaultValues2) => {
397
+ this.resetForm(defaultValues2);
398
+ },
399
+ {
400
+ signal: this.abortController.signal,
401
+ equals: comparer.structural
402
+ }
403
+ );
404
+ }
390
405
  this.abortController.signal.addEventListener("abort", () => {
391
406
  subscription();
392
407
  this.originalForm = null;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/components/controller.tsx","../src/utils/is-field-error.ts","../src/form/form.ts"],"sourcesContent":["import { Observer } from 'mobx-react-lite';\nimport { Controller as LibController } from 'react-hook-form';\n\nexport const Controller = ((props: any) => (\n <LibController\n {...props}\n render={(renderProps) => (\n <Observer>{() => props.render(renderProps)}</Observer>\n )}\n />\n)) as unknown as typeof LibController;\n","import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport { action, computed, makeObservable, observable } from 'mobx';\nimport type { BaseSyntheticEvent } from 'react';\nimport {\n type Control,\n createFormControl,\n type DeepMap,\n type DeepPartial,\n type DefaultValues,\n type FieldErrors,\n type FieldPath,\n type FieldPathValue,\n type FieldValues,\n type FormState,\n type SetValueConfig,\n type UseFormClearErrors,\n type UseFormGetValues,\n type UseFormRegister,\n type UseFormReset,\n type UseFormResetField,\n type UseFormSetError,\n type UseFormSetFocus,\n type UseFormSetValue,\n type UseFormTrigger,\n type UseFormUnregister,\n} from 'react-hook-form';\nimport { DeepObservableStruct } from 'yummies/mobx';\nimport { isFieldError } from '../utils/index.js';\nimport type { ErrorWithPath, FormParams } from './form.types.js';\n\ntype FormFullState<TFieldValues extends FieldValues> =\n FormState<TFieldValues> & {\n values: TFieldValues;\n };\n\nexport class Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> implements FormFullState<TFieldValues>\n{\n values: TFieldValues;\n isDirty: boolean = false;\n isLoading: boolean = false;\n isSubmitted: boolean = false;\n isSubmitSuccessful: boolean = false;\n isSubmitting: boolean = false;\n isValidating: boolean = false;\n isValid: boolean = false;\n disabled: boolean = false;\n submitCount: number = 0;\n /**\n * If you want to change this property\n * Use {resetForm} method\n */\n defaultValues!: Readonly<DefaultValues<TFieldValues>>;\n dirtyFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n touchedFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n validatingFields: Partial<\n Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>\n >;\n errors: FieldErrors<TFieldValues>;\n isReady: boolean = false;\n\n /**\n * Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)\n *\n * @param name - the path name to the form field value.\n * @param error - an error object which contains type and optional message\n * @param options - whether or not to focus on the field\n *\n * @example\n * ```tsx\n * // when the error is not associated with any fields, `clearError` will need to invoke to clear the error\n * const onSubmit = () => setError(\"serverError\", { type: \"server\", message: \"Error occurred\"})\n *\n * <button onClick={() => setError(\"name\", { type: \"min\" })} />\n *\n * // focus on the input after setting the error\n * <button onClick={() => setError(\"name\", { type: \"max\" }, { shouldFocus: true })} />\n * ```\n */\n setError: UseFormSetError<TFieldValues>;\n\n /**\n * Clear the entire form errors.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)\n *\n * @param name - the path name to the form field value.\n *\n * @example\n * Clear all errors\n * ```tsx\n * clearErrors(); // clear the entire form error\n * clearErrors([\"name\", \"name1\"]) // clear an array of fields' error\n * clearErrors(\"name2\"); // clear a single field error\n * ```\n */\n clearErrors: UseFormClearErrors<TFieldValues>;\n\n /**\n * Trigger field or form validation\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)\n *\n * @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an array of fields, and a single field name will only trigger that field's validation.\n * @param options - should focus on the error field\n *\n * @returns validation result\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * trigger();\n * }, [trigger])\n *\n * <button onClick={async () => {\n * const result = await trigger(); // result will be a boolean value\n * }}>\n * trigger\n * </button>\n * ```\n */\n trigger: UseFormTrigger<TFieldValues>;\n\n /**\n * Reset a field state and reference.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * <input {...register(\"firstName\", { required: true })} />\n * <button type=\"button\" onClick={() => resetField(\"firstName\"))}>Reset</button>\n * ```\n */\n resetField: UseFormResetField<TFieldValues>;\n\n /**\n * Unregister a field reference and remove its value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * register(\"name\", { required: true })\n *\n * <button onClick={() => unregister(\"name\")} />\n * // there are various keep options to retain formState\n * <button onClick={() => unregister(\"name\", { keepErrors: true })} />\n * ```\n */\n unregister: UseFormUnregister<TFieldValues>;\n\n /**\n * Form control\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/control)\n *\n */\n control: Control<TFieldValues, TContext, TTransformedValues>;\n\n /**\n * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)\n *\n * @param name - the path name to the form field value, name is required and unique\n * @param options - register options include validation, disabled, unregister, value as and dependent validation\n *\n * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.\n *\n * @example\n * ```tsx\n * // Register HTML native input\n * <input {...register(\"input\")} />\n * <select {...register(\"select\")} />\n *\n * // Register options\n * <textarea {...register(\"textarea\", { required: \"This is required.\", maxLength: 20 })} />\n * <input type=\"number\" {...register(\"name2\", { valueAsNumber: true })} />\n * <input {...register(\"name3\", { deps: [\"name2\"] })} />\n *\n * // Register custom field at useEffect\n * useEffect(() => {\n * register(\"name4\");\n * register(\"name5\", { value: \"hiddenValue\" });\n * }, [register])\n *\n * // Register without ref\n * const { onChange, onBlur, name } = register(\"name6\")\n * <input onChange={onChange} onBlur={onBlur} name={name} />\n * ```\n */\n register: UseFormRegister<TFieldValues>;\n\n /**\n * Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)\n *\n * @param name - the path name to the form field value.\n * @param options - input focus behavior options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * setFocus(\"name\");\n * }, [setFocus])\n * // shouldSelect allows to select input's content on focus\n * <button onClick={() => setFocus(\"name\", { shouldSelect: true })}>Focus</button>\n * ```\n */\n setFocus: UseFormSetFocus<TFieldValues>;\n\n /**\n * Set a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * setValue('name', 'value', {\n * shouldValidate: true, // trigger validation\n * shouldTouch: true, // update touched fields form state\n * shouldDirty: true, // update dirty and dirty fields form state\n * });\n *\n * // Update a group fields\n * setValue('root', {\n * a: 'test', // setValue('root.a', 'data')\n * b: 'test1', // setValue('root.b', 'data')\n * });\n *\n * // Update a nested object field\n * setValue('select', { label: 'test', value: 'Test' });\n * ```\n */\n setValue: UseFormSetValue<TFieldValues>;\n\n /**\n * Get a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)\n *\n * @param fieldNames - the path name to the form field value.\n * @param options - returns only dirty fields or return only touchedFields\n *\n * @example\n * ```tsx\n * // Update a single field\n * getValues('name', 'value', {\n * dirtyFields: true, // returns only dirty fields\n * touchedFields: true, // returns only touchedFields\n * });\n *\n * // Get nested values\n * getValues('root.nested.0.value');\n * ```\n */\n getValues: UseFormGetValues<TFieldValues>;\n\n /**\n * Reset at the entire form state.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)\n *\n * @param values - the entire form values to be reset\n * @param keepStateOptions - keep form state options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * // reset the entire form after component mount or form defaultValues is ready\n * reset({\n * fieldA: \"test\"\n * fieldB: \"test\"\n * });\n * }, [reset])\n *\n * // reset by combine with existing form values\n * reset({\n * ...getValues(),\n * fieldB: \"test\"\n *});\n *\n * // reset and keep form state\n * reset({\n * ...getValues(),\n *}, {\n * keepErrors: true,\n * keepDirty: true\n *});\n * ```\n */\n resetForm: UseFormReset<TFieldValues>;\n\n protected abortController: AbortController;\n\n /**\n * Original react-hook-form form\n */\n originalForm: ReturnType<\n typeof createFormControl<TFieldValues, TContext, TTransformedValues>\n >;\n\n private _observableStruct: DeepObservableStruct<\n Pick<\n FormFullState<TFieldValues>,\n 'dirtyFields' | 'errors' | 'touchedFields' | 'validatingFields' | 'values'\n >\n >;\n\n shouldFocusError: boolean;\n\n private config: FormParams<TFieldValues, TContext, TTransformedValues>;\n\n // special hack to apply the same form value changes from the original form\n // using subscription\n private forceFormUpdate: boolean;\n\n constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\n this.forceFormUpdate = false;\n\n this.config = {\n ...config,\n defaultValues: {\n ...config.defaultValues,\n } as DefaultValues<TFieldValues>,\n };\n\n Object.defineProperty(this.config, 'shouldFocusError', {\n get: () => this.shouldFocusError,\n });\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n const defaultValues = config.defaultValues\n ? { ...config.defaultValues }\n : ({} as any);\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n\n Object.assign(this, {\n defaultValues,\n });\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (rawFormState) => {\n if (this.forceFormUpdate || this.config.lazyUpdates === false) {\n this.forceFormUpdate = false;\n this.updateFormState(rawFormState);\n } else {\n this.scheduleUpdateFormState(rawFormState);\n }\n },\n });\n\n observable.ref(this, 'isDirty');\n observable.ref(this, 'isLoading');\n observable.ref(this, 'isSubmitted');\n observable.ref(this, 'isSubmitSuccessful');\n observable.ref(this, 'isSubmitting');\n observable.ref(this, 'isValidating');\n observable.ref(this, 'isValid');\n observable.ref(this, 'disabled');\n observable.ref(this, 'submitCount');\n observable.ref(this, 'isReady');\n observable.deep(this, 'defaultValues');\n computed(this, 'hasErrors');\n action(this, 'updateFormState');\n\n observable.ref(this, 'originalForm');\n action.bound(this, 'submit');\n action.bound(this, 'reset');\n\n makeObservable(this);\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n // @ts-expect-error\n this.originalForm = null;\n });\n }\n\n /**\n * The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty\n * It should work the same as field.onChange from react-hook-form's Controller\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true });\n *\n * ** form submitted **\n *\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true, shouldValidate: true });\n * ```\n */\n changeField = <\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n >(\n name: TFieldName,\n value: FieldPathValue<TFieldValues, TFieldName> | undefined,\n options?: SetValueConfig,\n ) => {\n return this.setValue(name, value as any, {\n shouldDirty: true,\n shouldValidate: this.isSubmitted,\n ...options,\n });\n };\n\n /**\n * Method to manually submit form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onSubmit={form.submit} />\n */\n submit(e?: BaseSyntheticEvent) {\n return new Promise<TTransformedValues>((resolve, reject) => {\n if (this.originalForm) {\n this.originalForm.handleSubmit(\n async (data, event) => {\n if (this.config.strictSubmitChecks) {\n const anyErrorWithPath = this.getErrorsWithPaths(true)[0];\n if (anyErrorWithPath) {\n this.setFocus(anyErrorWithPath.path);\n await this.config.onSubmitFailed?.(this.errors, event);\n reject(this.errors);\n return;\n }\n }\n await this.config.onSubmit?.(data, event);\n resolve(data);\n },\n async (errors, event) => {\n await this.config.onSubmitFailed?.(errors, event);\n reject(errors);\n },\n )(e);\n } else {\n const emptyData = (this.values ?? {}) as unknown as TTransformedValues;\n const result = this.config.onSubmit?.(emptyData);\n if (result instanceof Promise) {\n return result.then(() => resolve(emptyData));\n } else {\n return Promise.resolve(emptyData);\n }\n }\n });\n }\n\n /**\n * Method to manually reset all form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onReset={form.reset} />\n */\n reset(e?: BaseSyntheticEvent) {\n this.resetForm();\n this.config.onReset?.(e);\n }\n\n get hasErrors() {\n return Object.keys(this.errors).length > 0;\n }\n\n getErrorsWithPaths(getOnlyFirst?: boolean): ErrorWithPath<TFieldValues>[] {\n const result: ErrorWithPath<TFieldValues>[] = [];\n\n const traverse = (obj: any, prefix = '') => {\n if (!obj || typeof obj !== 'object') return;\n\n Object.entries(obj).forEach(([key, value]) => {\n const path = (prefix ? `${prefix}.${key}` : key) as any;\n\n if (isFieldError(value)) {\n result.push({ path, error: value });\n if (getOnlyFirst) {\n return;\n }\n } else if (Array.isArray(value)) {\n value.forEach((item, idx) => {\n const arrayPath = `${path}.${idx}` as any;\n\n if (isFieldError(item)) {\n result.push({ path: arrayPath, error: item });\n if (getOnlyFirst) {\n return;\n }\n } else if (typeof item === 'object') {\n traverse(item, arrayPath);\n }\n });\n } else if (typeof value === 'object') {\n traverse(value, path);\n }\n });\n };\n\n traverse(this.errors);\n\n return result;\n }\n\n private updateFormState({\n values,\n errors,\n dirtyFields,\n validatingFields,\n touchedFields,\n ...simpleProperties\n }: Partial<FormFullState<TFieldValues>>) {\n this.stopScheduledFormStateUpdate();\n Object.entries(simpleProperties).forEach(([key, value]) => {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n });\n\n this._observableStruct.set({\n dirtyFields,\n errors,\n touchedFields,\n validatingFields,\n values,\n });\n }\n\n protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n private stopScheduledFormStateUpdate = () => {\n if (this.lastTimeoutId !== undefined) {\n clearTimeout(this.lastTimeoutId);\n this.lastTimeoutId = undefined;\n }\n };\n\n private scheduleUpdateFormState = (\n rawFormState: Partial<FormFullState<TFieldValues>>,\n ) => {\n this.stopScheduledFormStateUpdate();\n this.lastTimeoutId = setTimeout(() => {\n this.updateFormState(rawFormState);\n this.lastTimeoutId = undefined;\n }, this.config.lazyUpdatesTimer ?? 0);\n };\n\n destroy(): void {\n this.abortController.abort();\n this.stopScheduledFormStateUpdate();\n }\n}\n\nexport const createForm = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n config: FormParams<TFieldValues, TContext, TTransformedValues>,\n) => new Form(config);\n\n/**\n * @deprecated ⚠️ use `Form`. This export will be removed in next major release\n */\nexport class MobxForm<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> extends Form<TFieldValues, TContext, TTransformedValues> {}\n"],"names":["LibController"],"mappings":";;;;;;;AAGO,MAAM,cAAc,CAAC,UAC1B;AAAA,EAACA;AAAAA,EAAA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AA,MACzB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EACH;AAAA,EAEU;AAAA,EAEF,+BAA+B,MAAM;AAC3C,QAAI,KAAK,kBAAkB,QAAW;AACpC,mBAAa,KAAK,aAAa;AAC/B,WAAK,gBAAgB;AAAA,IACvB;AAAA,EACF;AAAA,EAEQ,0BAA0B,CAChC,iBACG;AACH,SAAK,6BAAA;AACL,SAAK,gBAAgB,WAAW,MAAM;AACpC,WAAK,gBAAgB,YAAY;AACjC,WAAK,gBAAgB;AAAA,IACvB,GAAG,KAAK,OAAO,oBAAoB,CAAC;AAAA,EACtC;AAAA,EAEA,UAAgB;AACd,SAAK,gBAAgB,MAAA;AACrB,SAAK,6BAAA;AAAA,EACP;AACF;AAEO,MAAM,aAAa,CAKxB,WACG,IAAI,KAAK,MAAM;AAKb,MAAM,iBAIH,KAAiD;AAAC;"}
1
+ {"version":3,"file":"index.js","sources":["../src/components/controller.tsx","../src/utils/is-field-error.ts","../src/form/form.ts"],"sourcesContent":["import { Observer } from 'mobx-react-lite';\nimport { Controller as LibController } from 'react-hook-form';\n\nexport const Controller = ((props: any) => (\n <LibController\n {...props}\n render={(renderProps) => (\n <Observer>{() => props.render(renderProps)}</Observer>\n )}\n />\n)) as unknown as typeof LibController;\n","import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport {\n action,\n comparer,\n computed,\n makeObservable,\n observable,\n reaction,\n} from 'mobx';\nimport type { BaseSyntheticEvent } from 'react';\nimport {\n type Control,\n createFormControl,\n type DeepMap,\n type DeepPartial,\n type DefaultValues,\n type FieldErrors,\n type FieldPath,\n type FieldPathValue,\n type FieldValues,\n type FormState,\n type SetValueConfig,\n type UseFormClearErrors,\n type UseFormGetValues,\n type UseFormRegister,\n type UseFormReset,\n type UseFormResetField,\n type UseFormSetError,\n type UseFormSetFocus,\n type UseFormSetValue,\n type UseFormTrigger,\n type UseFormUnregister,\n} from 'react-hook-form';\nimport { DeepObservableStruct } from 'yummies/mobx';\nimport { isFieldError } from '../utils/index.js';\nimport type { ErrorWithPath, FormParams } from './form.types.js';\n\ntype FormFullState<TFieldValues extends FieldValues> =\n FormState<TFieldValues> & {\n values: TFieldValues;\n };\n\nexport class Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> implements FormFullState<TFieldValues>\n{\n values: TFieldValues;\n isDirty: boolean = false;\n isLoading: boolean = false;\n isSubmitted: boolean = false;\n isSubmitSuccessful: boolean = false;\n isSubmitting: boolean = false;\n isValidating: boolean = false;\n isValid: boolean = false;\n disabled: boolean = false;\n submitCount: number = 0;\n /**\n * If you want to change this property\n * Use {resetForm} method\n */\n defaultValues: Readonly<DefaultValues<TFieldValues>>;\n dirtyFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n touchedFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n validatingFields: Partial<\n Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>\n >;\n errors: FieldErrors<TFieldValues>;\n isReady: boolean = false;\n\n /**\n * Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)\n *\n * @param name - the path name to the form field value.\n * @param error - an error object which contains type and optional message\n * @param options - whether or not to focus on the field\n *\n * @example\n * ```tsx\n * // when the error is not associated with any fields, `clearError` will need to invoke to clear the error\n * const onSubmit = () => setError(\"serverError\", { type: \"server\", message: \"Error occurred\"})\n *\n * <button onClick={() => setError(\"name\", { type: \"min\" })} />\n *\n * // focus on the input after setting the error\n * <button onClick={() => setError(\"name\", { type: \"max\" }, { shouldFocus: true })} />\n * ```\n */\n setError: UseFormSetError<TFieldValues>;\n\n /**\n * Clear the entire form errors.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)\n *\n * @param name - the path name to the form field value.\n *\n * @example\n * Clear all errors\n * ```tsx\n * clearErrors(); // clear the entire form error\n * clearErrors([\"name\", \"name1\"]) // clear an array of fields' error\n * clearErrors(\"name2\"); // clear a single field error\n * ```\n */\n clearErrors: UseFormClearErrors<TFieldValues>;\n\n /**\n * Trigger field or form validation\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)\n *\n * @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an array of fields, and a single field name will only trigger that field's validation.\n * @param options - should focus on the error field\n *\n * @returns validation result\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * trigger();\n * }, [trigger])\n *\n * <button onClick={async () => {\n * const result = await trigger(); // result will be a boolean value\n * }}>\n * trigger\n * </button>\n * ```\n */\n trigger: UseFormTrigger<TFieldValues>;\n\n /**\n * Reset a field state and reference.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * <input {...register(\"firstName\", { required: true })} />\n * <button type=\"button\" onClick={() => resetField(\"firstName\"))}>Reset</button>\n * ```\n */\n resetField: UseFormResetField<TFieldValues>;\n\n /**\n * Unregister a field reference and remove its value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * register(\"name\", { required: true })\n *\n * <button onClick={() => unregister(\"name\")} />\n * // there are various keep options to retain formState\n * <button onClick={() => unregister(\"name\", { keepErrors: true })} />\n * ```\n */\n unregister: UseFormUnregister<TFieldValues>;\n\n /**\n * Form control\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/control)\n *\n */\n control: Control<TFieldValues, TContext, TTransformedValues>;\n\n /**\n * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)\n *\n * @param name - the path name to the form field value, name is required and unique\n * @param options - register options include validation, disabled, unregister, value as and dependent validation\n *\n * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.\n *\n * @example\n * ```tsx\n * // Register HTML native input\n * <input {...register(\"input\")} />\n * <select {...register(\"select\")} />\n *\n * // Register options\n * <textarea {...register(\"textarea\", { required: \"This is required.\", maxLength: 20 })} />\n * <input type=\"number\" {...register(\"name2\", { valueAsNumber: true })} />\n * <input {...register(\"name3\", { deps: [\"name2\"] })} />\n *\n * // Register custom field at useEffect\n * useEffect(() => {\n * register(\"name4\");\n * register(\"name5\", { value: \"hiddenValue\" });\n * }, [register])\n *\n * // Register without ref\n * const { onChange, onBlur, name } = register(\"name6\")\n * <input onChange={onChange} onBlur={onBlur} name={name} />\n * ```\n */\n register: UseFormRegister<TFieldValues>;\n\n /**\n * Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)\n *\n * @param name - the path name to the form field value.\n * @param options - input focus behavior options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * setFocus(\"name\");\n * }, [setFocus])\n * // shouldSelect allows to select input's content on focus\n * <button onClick={() => setFocus(\"name\", { shouldSelect: true })}>Focus</button>\n * ```\n */\n setFocus: UseFormSetFocus<TFieldValues>;\n\n /**\n * Set a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * setValue('name', 'value', {\n * shouldValidate: true, // trigger validation\n * shouldTouch: true, // update touched fields form state\n * shouldDirty: true, // update dirty and dirty fields form state\n * });\n *\n * // Update a group fields\n * setValue('root', {\n * a: 'test', // setValue('root.a', 'data')\n * b: 'test1', // setValue('root.b', 'data')\n * });\n *\n * // Update a nested object field\n * setValue('select', { label: 'test', value: 'Test' });\n * ```\n */\n setValue: UseFormSetValue<TFieldValues>;\n\n /**\n * Get a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)\n *\n * @param fieldNames - the path name to the form field value.\n * @param options - returns only dirty fields or return only touchedFields\n *\n * @example\n * ```tsx\n * // Update a single field\n * getValues('name', 'value', {\n * dirtyFields: true, // returns only dirty fields\n * touchedFields: true, // returns only touchedFields\n * });\n *\n * // Get nested values\n * getValues('root.nested.0.value');\n * ```\n */\n getValues: UseFormGetValues<TFieldValues>;\n\n /**\n * Reset at the entire form state.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)\n *\n * @param values - the entire form values to be reset\n * @param keepStateOptions - keep form state options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * // reset the entire form after component mount or form defaultValues is ready\n * reset({\n * fieldA: \"test\"\n * fieldB: \"test\"\n * });\n * }, [reset])\n *\n * // reset by combine with existing form values\n * reset({\n * ...getValues(),\n * fieldB: \"test\"\n *});\n *\n * // reset and keep form state\n * reset({\n * ...getValues(),\n *}, {\n * keepErrors: true,\n * keepDirty: true\n *});\n * ```\n */\n resetForm: UseFormReset<TFieldValues>;\n\n protected abortController: AbortController;\n\n /**\n * Original react-hook-form form\n */\n originalForm: ReturnType<\n typeof createFormControl<TFieldValues, TContext, TTransformedValues>\n >;\n\n private _observableStruct: DeepObservableStruct<\n Pick<\n FormFullState<TFieldValues>,\n 'dirtyFields' | 'errors' | 'touchedFields' | 'validatingFields' | 'values'\n >\n >;\n\n shouldFocusError: boolean;\n\n private config: FormParams<TFieldValues, TContext, TTransformedValues>;\n\n // special hack to apply the same form value changes from the original form\n // using subscription\n private forceFormUpdate: boolean;\n\n constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\n this.forceFormUpdate = false;\n\n const defaultValuesRaw = config.defaultValues;\n const isDefaultValuesRawFn = typeof defaultValuesRaw === 'function';\n\n const defaultValues = isDefaultValuesRawFn\n ? defaultValuesRaw()\n : defaultValuesRaw\n ? { ...defaultValuesRaw }\n : ({} as any);\n\n this.config = {\n ...config,\n defaultValues: { ...defaultValues } as DefaultValues<TFieldValues>,\n shouldFocusError: this.shouldFocusError,\n };\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n Object.defineProperty(\n this.originalForm.control._options,\n 'shouldFocusError',\n {\n get: () => this.shouldFocusError,\n },\n );\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n this.defaultValues = defaultValues;\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (rawFormState) => {\n if (this.forceFormUpdate || this.config.lazyUpdates === false) {\n this.forceFormUpdate = false;\n this.updateFormState(rawFormState);\n } else {\n this.scheduleUpdateFormState(rawFormState);\n }\n },\n });\n\n observable.ref(this, 'isDirty');\n observable.ref(this, 'isLoading');\n observable.ref(this, 'isSubmitted');\n observable.ref(this, 'isSubmitSuccessful');\n observable.ref(this, 'isSubmitting');\n observable.ref(this, 'isValidating');\n observable.ref(this, 'isValid');\n observable.ref(this, 'disabled');\n observable.ref(this, 'submitCount');\n observable.ref(this, 'isReady');\n observable.deep(this, 'defaultValues');\n computed(this, 'hasErrors');\n action(this, 'updateFormState');\n\n observable.ref(this, 'originalForm');\n action.bound(this, 'submit');\n action.bound(this, 'reset');\n\n makeObservable(this);\n\n if (isDefaultValuesRawFn) {\n reaction(\n () => defaultValuesRaw(),\n (defaultValues) => {\n this.resetForm(defaultValues);\n },\n {\n signal: this.abortController.signal,\n equals: comparer.structural,\n },\n );\n }\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n // @ts-expect-error\n this.originalForm = null;\n });\n }\n\n /**\n * The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty\n * It should work the same as field.onChange from react-hook-form's Controller\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true });\n *\n * ** form submitted **\n *\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true, shouldValidate: true });\n * ```\n */\n changeField = <\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n >(\n name: TFieldName,\n value: FieldPathValue<TFieldValues, TFieldName> | undefined,\n options?: SetValueConfig,\n ) => {\n return this.setValue(name, value as any, {\n shouldDirty: true,\n shouldValidate: this.isSubmitted,\n ...options,\n });\n };\n\n /**\n * Method to manually submit form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onSubmit={form.submit} />\n */\n submit(e?: BaseSyntheticEvent) {\n return new Promise<TTransformedValues>((resolve, reject) => {\n if (this.originalForm) {\n this.originalForm.handleSubmit(\n async (data, event) => {\n if (this.config.strictSubmitChecks) {\n const anyErrorWithPath = this.getErrorsWithPaths(true)[0];\n if (anyErrorWithPath) {\n this.setFocus(anyErrorWithPath.path);\n await this.config.onSubmitFailed?.(this.errors, event);\n reject(this.errors);\n return;\n }\n }\n await this.config.onSubmit?.(data, event);\n resolve(data);\n },\n async (errors, event) => {\n await this.config.onSubmitFailed?.(errors, event);\n reject(errors);\n },\n )(e);\n } else {\n const emptyData = (this.values ?? {}) as unknown as TTransformedValues;\n const result = this.config.onSubmit?.(emptyData);\n if (result instanceof Promise) {\n return result.then(() => resolve(emptyData));\n } else {\n return Promise.resolve(emptyData);\n }\n }\n });\n }\n\n /**\n * Method to manually reset all form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onReset={form.reset} />\n */\n reset(e?: BaseSyntheticEvent) {\n this.resetForm();\n this.config.onReset?.(e);\n }\n\n get hasErrors() {\n return Object.keys(this.errors).length > 0;\n }\n\n getErrorsWithPaths(getOnlyFirst?: boolean): ErrorWithPath<TFieldValues>[] {\n const result: ErrorWithPath<TFieldValues>[] = [];\n\n const traverse = (obj: any, prefix = '') => {\n if (!obj || typeof obj !== 'object') return;\n\n Object.entries(obj).forEach(([key, value]) => {\n const path = (prefix ? `${prefix}.${key}` : key) as any;\n\n if (isFieldError(value)) {\n result.push({ path, error: value });\n if (getOnlyFirst) {\n return;\n }\n } else if (Array.isArray(value)) {\n value.forEach((item, idx) => {\n const arrayPath = `${path}.${idx}` as any;\n\n if (isFieldError(item)) {\n result.push({ path: arrayPath, error: item });\n if (getOnlyFirst) {\n return;\n }\n } else if (typeof item === 'object') {\n traverse(item, arrayPath);\n }\n });\n } else if (typeof value === 'object') {\n traverse(value, path);\n }\n });\n };\n\n traverse(this.errors);\n\n return result;\n }\n\n private updateFormState({\n values,\n errors,\n dirtyFields,\n validatingFields,\n touchedFields,\n ...simpleProperties\n }: Partial<FormFullState<TFieldValues>>) {\n this.stopScheduledFormStateUpdate();\n Object.entries(simpleProperties).forEach(([key, value]) => {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n });\n\n this._observableStruct.set({\n dirtyFields,\n errors,\n touchedFields,\n validatingFields,\n values,\n });\n }\n\n protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n private stopScheduledFormStateUpdate = () => {\n if (this.lastTimeoutId !== undefined) {\n clearTimeout(this.lastTimeoutId);\n this.lastTimeoutId = undefined;\n }\n };\n\n private scheduleUpdateFormState = (\n rawFormState: Partial<FormFullState<TFieldValues>>,\n ) => {\n this.stopScheduledFormStateUpdate();\n this.lastTimeoutId = setTimeout(() => {\n this.updateFormState(rawFormState);\n this.lastTimeoutId = undefined;\n }, this.config.lazyUpdatesTimer ?? 0);\n };\n\n destroy(): void {\n this.abortController.abort();\n this.stopScheduledFormStateUpdate();\n }\n}\n\nexport const createForm = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n config: FormParams<TFieldValues, TContext, TTransformedValues>,\n) => new Form(config);\n\n/**\n * @deprecated ⚠️ use `Form`. This export will be removed in next major release\n */\nexport class MobxForm<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> extends Form<TFieldValues, TContext, TTransformedValues> {}\n"],"names":["LibController","defaultValues"],"mappings":";;;;;;;AAGO,MAAM,cAAc,CAAC,UAC1B;AAAA,EAACA;AAAAA,EAAA;AAAA,IACE,GAAG;AAAA,IACJ,QAAQ,CAAC,gBACP,oBAAC,YAAU,UAAA,MAAM,MAAM,OAAO,WAAW,EAAA,CAAE;AAAA,EAAA;AAE/C;ACNK,MAAM,eAAe,CAAC,UAAwC;AACnE,SAAO,UAAU,SAAS,KAAK,KAAK,UAAU;AAChD;ACqCO,MAAM,KAKb;AAAA,EACE;AAAA,EACA,UAAmB;AAAA,EACnB,YAAqB;AAAA,EACrB,cAAuB;AAAA,EACvB,qBAA8B;AAAA,EAC9B,eAAwB;AAAA,EACxB,eAAwB;AAAA,EACxB,UAAmB;AAAA,EACnB,WAAoB;AAAA,EACpB,cAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA,UAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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I,KAAK,MAAM;AAKb,MAAM,iBAIH,KAAiD;AAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-react-hook-form",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],