mobx-react-hook-form 5.10.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{mobx-form/mobx-form.d.ts → form/form.d.ts} +4 -2
- package/form/form.d.ts.map +1 -0
- package/{mobx-form/mobx-form.types.d.ts → form/form.types.d.ts} +2 -2
- package/form/form.types.d.ts.map +1 -0
- package/form/index.d.ts +3 -0
- package/form/index.d.ts.map +1 -0
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +29 -26
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/mobx-form/index.d.ts +0 -3
- package/mobx-form/index.d.ts.map +0 -1
- package/mobx-form/mobx-form.d.ts.map +0 -1
- package/mobx-form/mobx-form.types.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseSyntheticEvent } from 'react';
|
|
2
2
|
import { Control, createFormControl, DeepMap, DeepPartial, DefaultValues, FieldErrors, FieldPath, FieldPathValue, FieldValues, FormState, SetValueConfig, UseFormClearErrors, UseFormGetValues, UseFormRegister, UseFormReset, UseFormResetField, UseFormSetError, UseFormSetFocus, UseFormSetValue, UseFormTrigger, UseFormUnregister } from 'react-hook-form';
|
|
3
|
-
import { ErrorWithPath, FormParams } from './
|
|
3
|
+
import { ErrorWithPath, FormParams } from './form.types.js';
|
|
4
4
|
type FormFullState<TFieldValues extends FieldValues> = FormState<TFieldValues> & {
|
|
5
5
|
values: TFieldValues;
|
|
6
6
|
};
|
|
@@ -280,6 +280,7 @@ export declare class Form<TFieldValues extends FieldValues = FieldValues, TConte
|
|
|
280
280
|
private _observableStruct;
|
|
281
281
|
shouldFocusError: boolean;
|
|
282
282
|
private config;
|
|
283
|
+
private forceFormUpdate;
|
|
283
284
|
constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>);
|
|
284
285
|
/**
|
|
285
286
|
* The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty
|
|
@@ -330,10 +331,11 @@ export declare class Form<TFieldValues extends FieldValues = FieldValues, TConte
|
|
|
330
331
|
private scheduleUpdateFormState;
|
|
331
332
|
destroy(): void;
|
|
332
333
|
}
|
|
334
|
+
export declare const createForm: <TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>(config: FormParams<TFieldValues, TContext, TTransformedValues>) => Form<TFieldValues, TContext, TTransformedValues>;
|
|
333
335
|
/**
|
|
334
336
|
* @deprecated ⚠️ use `Form`. This export will be removed in next major release
|
|
335
337
|
*/
|
|
336
338
|
export declare class MobxForm<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues> extends Form<TFieldValues, TContext, TTransformedValues> {
|
|
337
339
|
}
|
|
338
340
|
export {};
|
|
339
|
-
//# sourceMappingURL=
|
|
341
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +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,CA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AAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,EAEpE,MAAM,UAAU,EAChB,OAAO,cAAc,CAAC,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,5 +1,5 @@
|
|
|
1
1
|
import { DeepPartial, FieldError, FieldPath, FieldValues, SubmitErrorHandler, SubmitHandler, UseFormProps } from 'react-hook-form';
|
|
2
|
-
import { Form } from './
|
|
2
|
+
import { Form } from './form.js';
|
|
3
3
|
export type AnyForm = Form<any, any, any>;
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated ⚠️ use `AnyForm`. This export will be removed in next major release
|
|
@@ -54,4 +54,4 @@ export interface ErrorWithPath<TFieldValues extends FieldValues = FieldValues, T
|
|
|
54
54
|
path: TFieldName;
|
|
55
55
|
error: FieldError;
|
|
56
56
|
}
|
|
57
|
-
//# sourceMappingURL=
|
|
57
|
+
//# sourceMappingURL=form.types.d.ts.map
|
|
@@ -0,0 +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,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,IAC/B,UAAU,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AAE3D,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,OAAO,IAAI,OAAO,CAC7D,CAAC,CAAC,QAAQ,CAAC,EACX,SAAS,GAAG,IAAI,CACjB,CAAC;AAEF,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,IAAI,CAC1E,GAAG,EACH,GAAG,EACH,MAAM,kBAAkB,CACzB,GACG,kBAAkB,GAClB,KAAK,CAAC;AAEV,MAAM,WAAW,aAAa,CAC5B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,UAAU,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC;IAEpE,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,UAAU,CAAC;CACnB"}
|
package/form/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/form/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
|
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"),
|
|
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;
|
|
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/mobx-form/mobx-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 computed,\n isObservableObject,\n makeObservable,\n observable,\n toJS,\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 get,\n type SetValueConfig,\n set,\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 './mobx-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 constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\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() {\n return this.shouldFocusError;\n },\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 = action((...args) => {\n set(this.errors, args[0], args[1]);\n return this.originalForm.setError(...args);\n });\n this.clearErrors = this.originalForm.clearErrors;\n this.trigger = this.originalForm.trigger;\n this.resetField = action((...args) => {\n set(this.values, args[0], get(this.defaultValues, args[0]));\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 = action((...args) => {\n set(this.values, args[0], args[1]);\n return this.originalForm.setValue(...args);\n });\n this.getValues = this.originalForm.getValues;\n this.resetForm = action((...args) => {\n let defaultValues = args[0] ?? this.defaultValues;\n\n if (isObservableObject(defaultValues)) {\n defaultValues = toJS(defaultValues);\n } else {\n defaultValues = structuredClone(defaultValues);\n }\n\n // @ts-expect-error\n this.values = defaultValues;\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.config.lazyUpdates === 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 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 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\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","constructor","this","LinkedAbortController","abortSignal","Object","defineProperty","get","createFormControl","action","args","set","isObservableObject","toJS","structuredClone","reset","DeepObservableStruct","data","assign","subscription","subscribe","formState","callback","rawFormState","lazyUpdates","updateFormState","scheduleUpdateFormState","observable","ref","deep","computed","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","lastTimeoutId","stopScheduledFormStateUpdate","clearTimeout","setTimeout","lazyUpdatesTimer","destroy","abort","props","jsx","LibController","render","renderProps","Observer","children"],"mappings":"gSAGaA,EAAgBC,GACpBC,EAAAA,UAAUC,SAASF,IAAU,SAAUA,ECwCzC,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,OAER,WAAAC,CAAYD,GACVE,KAAKN,gBAAkB,IAAIO,wBAAsBH,EAAOI,aAExDF,KAAKH,iBAAmBC,EAAOD,mBAAoB,EAEnDG,KAAKF,OAAS,IACTA,EACHrB,cAAe,IACVqB,EAAOrB,gBAId0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GAAGnB,KAAQkB,IAE7B,GAAI7G,EAAa4G,IAEf,GADA1B,EAAOsB,KAAK,CAAEb,KAAMmB,EAAWL,MAAOG,IAClCX,EACF,WAEuB,iBAATW,GAChBV,EAASU,EAAME,KAGO,iBAAV7G,GAChBiG,EAASjG,EAAO0F,MAOtB,OAFAO,EAAS5D,KAAKnB,QAEP+D,CACT,CAEQ,eAAArB,EAAgBxD,OACtBA,EAAAc,OACAA,EAAAH,YACAA,EAAAE,iBACAA,EAAAD,cACAA,KACG8F,IAEHtE,OAAO4D,QAAQU,GAAkBT,QAAQ,EAAEC,EAAKtG,MACjC,MAATA,IAEFqC,KAAKiE,GAAOtG,KAIhBqC,KAAKJ,kBAAkBa,IAAI,CACzB/B,cACAG,SACAF,gBACAC,mBACAb,UAEJ,CAEU2G,cAEFC,6BAA+B,UACV,IAAvB3E,KAAK0E,gBACPE,aAAa5E,KAAK0E,eAClB1E,KAAK0E,mBAAgB,IAIjBlD,wBACNH,IAEArB,KAAK2E,+BACL3E,KAAK0E,cAAgBG,WAAW,KAC9B7E,KAAKuB,gBAAgBF,GACrBrB,KAAK0E,mBAAgB,GACpB1E,KAAKF,OAAOgF,kBAAoB,IAGrC,OAAAC,GACE/E,KAAKN,gBAAgBsF,QACrBhF,KAAK2E,8BACP,qBC7oB0BM,GAC1BC,EAAAA,IAACC,EAAAA,WAAA,IACKF,EACJG,OAASC,GACPH,EAAAA,IAACI,EAAAA,UAAUC,SAAA,IAAMN,EAAMG,OAAOC,uCD+oB7B,cAIGvH"}
|
|
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,WAA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VRgC,GACG,IAAIhC,EAAKgC"}
|
package/index.d.ts
CHANGED
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Observer } from "mobx-react-lite";
|
|
3
|
-
import { Controller as Controller$1, createFormControl
|
|
3
|
+
import { Controller as Controller$1, createFormControl } from "react-hook-form";
|
|
4
4
|
import { LinkedAbortController } from "linked-abort-controller";
|
|
5
|
-
import {
|
|
5
|
+
import { observable, computed, action, makeObservable } from "mobx";
|
|
6
6
|
import { DeepObservableStruct } from "yummies/mobx";
|
|
7
7
|
import { typeGuard } from "yummies/type-guard";
|
|
8
8
|
const Controller = ((props) => /* @__PURE__ */ jsx(
|
|
@@ -291,9 +291,13 @@ class Form {
|
|
|
291
291
|
_observableStruct;
|
|
292
292
|
shouldFocusError;
|
|
293
293
|
config;
|
|
294
|
+
// special hack to apply the same form value changes from the original form
|
|
295
|
+
// using subscription
|
|
296
|
+
forceFormUpdate;
|
|
294
297
|
constructor(config) {
|
|
295
298
|
this.abortController = new LinkedAbortController(config.abortSignal);
|
|
296
299
|
this.shouldFocusError = config.shouldFocusError ?? true;
|
|
300
|
+
this.forceFormUpdate = false;
|
|
297
301
|
this.config = {
|
|
298
302
|
...config,
|
|
299
303
|
defaultValues: {
|
|
@@ -301,41 +305,36 @@ class Form {
|
|
|
301
305
|
}
|
|
302
306
|
};
|
|
303
307
|
Object.defineProperty(this.config, "shouldFocusError", {
|
|
304
|
-
get()
|
|
305
|
-
return this.shouldFocusError;
|
|
306
|
-
}
|
|
308
|
+
get: () => this.shouldFocusError
|
|
307
309
|
});
|
|
308
310
|
this.originalForm = createFormControl(this.config);
|
|
309
311
|
const defaultValues = config.defaultValues ? { ...config.defaultValues } : {};
|
|
310
|
-
this.setError =
|
|
311
|
-
|
|
312
|
+
this.setError = (...args) => {
|
|
313
|
+
this.forceFormUpdate = true;
|
|
312
314
|
return this.originalForm.setError(...args);
|
|
313
|
-
}
|
|
314
|
-
this.clearErrors =
|
|
315
|
+
};
|
|
316
|
+
this.clearErrors = (...args) => {
|
|
317
|
+
this.forceFormUpdate = true;
|
|
318
|
+
return this.originalForm.clearErrors(...args);
|
|
319
|
+
};
|
|
315
320
|
this.trigger = this.originalForm.trigger;
|
|
316
|
-
this.resetField =
|
|
317
|
-
|
|
321
|
+
this.resetField = (...args) => {
|
|
322
|
+
this.forceFormUpdate = true;
|
|
318
323
|
return this.originalForm.resetField(...args);
|
|
319
|
-
}
|
|
324
|
+
};
|
|
320
325
|
this.unregister = this.originalForm.unregister;
|
|
321
326
|
this.control = this.originalForm.control;
|
|
322
327
|
this.register = this.originalForm.register;
|
|
323
328
|
this.setFocus = this.originalForm.setFocus;
|
|
324
|
-
this.setValue =
|
|
325
|
-
|
|
329
|
+
this.setValue = (...args) => {
|
|
330
|
+
this.forceFormUpdate = true;
|
|
326
331
|
return this.originalForm.setValue(...args);
|
|
327
|
-
}
|
|
332
|
+
};
|
|
328
333
|
this.getValues = this.originalForm.getValues;
|
|
329
|
-
this.resetForm =
|
|
330
|
-
|
|
331
|
-
if (isObservableObject(defaultValues2)) {
|
|
332
|
-
defaultValues2 = toJS(defaultValues2);
|
|
333
|
-
} else {
|
|
334
|
-
defaultValues2 = structuredClone(defaultValues2);
|
|
335
|
-
}
|
|
336
|
-
this.values = defaultValues2;
|
|
334
|
+
this.resetForm = (...args) => {
|
|
335
|
+
this.forceFormUpdate = true;
|
|
337
336
|
return this.originalForm.reset(...args);
|
|
338
|
-
}
|
|
337
|
+
};
|
|
339
338
|
this._observableStruct = new DeepObservableStruct({
|
|
340
339
|
values: this.originalForm.getValues(),
|
|
341
340
|
errors: {},
|
|
@@ -363,7 +362,8 @@ class Form {
|
|
|
363
362
|
validatingFields: true
|
|
364
363
|
},
|
|
365
364
|
callback: (rawFormState) => {
|
|
366
|
-
if (this.config.lazyUpdates === false) {
|
|
365
|
+
if (this.forceFormUpdate || this.config.lazyUpdates === false) {
|
|
366
|
+
this.forceFormUpdate = false;
|
|
367
367
|
this.updateFormState(rawFormState);
|
|
368
368
|
} else {
|
|
369
369
|
this.scheduleUpdateFormState(rawFormState);
|
|
@@ -415,7 +415,7 @@ class Form {
|
|
|
415
415
|
* ```
|
|
416
416
|
*/
|
|
417
417
|
changeField = (name, value, options) => {
|
|
418
|
-
this.setValue(name, value, {
|
|
418
|
+
return this.setValue(name, value, {
|
|
419
419
|
shouldDirty: true,
|
|
420
420
|
shouldValidate: this.isSubmitted,
|
|
421
421
|
...options
|
|
@@ -516,6 +516,7 @@ class Form {
|
|
|
516
516
|
touchedFields,
|
|
517
517
|
...simpleProperties
|
|
518
518
|
}) {
|
|
519
|
+
this.stopScheduledFormStateUpdate();
|
|
519
520
|
Object.entries(simpleProperties).forEach(([key, value]) => {
|
|
520
521
|
if (value != null) {
|
|
521
522
|
this[key] = value;
|
|
@@ -548,12 +549,14 @@ class Form {
|
|
|
548
549
|
this.stopScheduledFormStateUpdate();
|
|
549
550
|
}
|
|
550
551
|
}
|
|
552
|
+
const createForm = (config) => new Form(config);
|
|
551
553
|
class MobxForm extends Form {
|
|
552
554
|
}
|
|
553
555
|
export {
|
|
554
556
|
Controller,
|
|
555
557
|
Form,
|
|
556
558
|
MobxForm,
|
|
559
|
+
createForm,
|
|
557
560
|
isFieldError
|
|
558
561
|
};
|
|
559
562
|
//# sourceMappingURL=index.js.map
|
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/mobx-form/mobx-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 computed,\n isObservableObject,\n makeObservable,\n observable,\n toJS,\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 get,\n type SetValueConfig,\n set,\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 './mobx-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 constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\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() {\n return this.shouldFocusError;\n },\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 = action((...args) => {\n set(this.errors, args[0], args[1]);\n return this.originalForm.setError(...args);\n });\n this.clearErrors = this.originalForm.clearErrors;\n this.trigger = this.originalForm.trigger;\n this.resetField = action((...args) => {\n set(this.values, args[0], get(this.defaultValues, args[0]));\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 = action((...args) => {\n set(this.values, args[0], args[1]);\n return this.originalForm.setValue(...args);\n });\n this.getValues = this.originalForm.getValues;\n this.resetForm = action((...args) => {\n let defaultValues = args[0] ?? this.defaultValues;\n\n if (isObservableObject(defaultValues)) {\n defaultValues = toJS(defaultValues);\n } else {\n defaultValues = structuredClone(defaultValues);\n }\n\n // @ts-expect-error\n this.values = defaultValues;\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.config.lazyUpdates === 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 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 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\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;ACuCO,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;AAA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AG,KAAK,OAAO,oBAAoB,CAAC;AAAA,EACtC;AAAA,EAEA,UAAgB;AACd,SAAK,gBAAgB,MAAA;AACrB,SAAK,6BAAA;AAAA,EACP;AACF;AAKO,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 { 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;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;AC8BO,MAAM,KAKb;AAAA,EACE;AAAA,EACA,UAAmB;AAAA,EACnB,YAAqB;AAAA,EACrB,cAAuB;AAAA,E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W,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;"}
|
package/package.json
CHANGED
package/mobx-form/index.d.ts
DELETED
package/mobx-form/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mobx-form/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mobx-form.d.ts","sourceRoot":"","sources":["../../src/mobx-form/mobx-form.ts"],"names":[],"mappings":"AASA,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,EAEd,KAAK,cAAc,EAEnB,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,sBAAsB,CAAC;AAEtE,KAAK,aAAa,CAAC,YAAY,SAAS,WAAW,IACjD,SAAS,CAAC,YAAY,C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