mobx-react-hook-form 6.2.1 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/form/form.d.ts +5 -2
- package/form/form.d.ts.map +1 -1
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.js +57 -26
- package/index.js.map +1 -1
- package/package.json +2 -2
package/form/form.d.ts
CHANGED
|
@@ -279,9 +279,11 @@ export declare class Form<TFieldValues extends FieldValues = FieldValues, TConte
|
|
|
279
279
|
originalForm: ReturnType<typeof createFormControl<TFieldValues, TContext, TTransformedValues>>;
|
|
280
280
|
private _observableStruct;
|
|
281
281
|
shouldFocusError: boolean;
|
|
282
|
-
|
|
282
|
+
protected config: FormParams<TFieldValues, TContext, TTransformedValues>;
|
|
283
283
|
private forceFormUpdate;
|
|
284
|
+
private forceFormValuesUpdate;
|
|
284
285
|
constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>);
|
|
286
|
+
get isTouched(): boolean;
|
|
285
287
|
/**
|
|
286
288
|
* The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty
|
|
287
289
|
* It should work the same as field.onChange from react-hook-form's Controller
|
|
@@ -324,7 +326,8 @@ export declare class Form<TFieldValues extends FieldValues = FieldValues, TConte
|
|
|
324
326
|
*/
|
|
325
327
|
reset(e?: BaseSyntheticEvent): void;
|
|
326
328
|
get hasErrors(): boolean;
|
|
327
|
-
getErrorsWithPaths(getOnlyFirst?: boolean): ErrorWithPath<TFieldValues>[];
|
|
329
|
+
getErrorsWithPaths(getOnlyFirst?: boolean, errors?: FieldErrors<TFieldValues>): ErrorWithPath<TFieldValues>[];
|
|
330
|
+
validate(focusOnError?: boolean): Promise<TTransformedValues | null>;
|
|
328
331
|
private updateFormState;
|
|
329
332
|
protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
330
333
|
private stopScheduledFormStateUpdate;
|
package/form/form.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/form/form.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EACL,KAAK,OAAO,EACZ,iBAAiB,EACjB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;
|
|
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;AAIzB,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEjE,KAAK,aAAa,CAAC,YAAY,SAAS,WAAW,IACjD,SAAS,CAAC,Y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Property(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
|
|
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 u{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;forceFormValuesUpdate;constructor(t){this.abortController=new i.LinkedAbortController(t.abortSignal),this.shouldFocusError=t.shouldFocusError??!0,this.forceFormUpdate=!1,this.forceFormValuesUpdate=!1;const e=t.defaultValues,a="function"==typeof e,l=a?e():e?{...e}:{};this.config={...t,defaultValues:{...l},shouldFocusError:this.shouldFocusError},this.originalForm=r.createFormControl(this.config),Object.defineProperty(this.originalForm.control._options,"shouldFocusError",{get:()=>this.shouldFocusError}),this.setError=(...t)=>(this.forceFormUpdate=!0,this.originalForm.setError(...t)),this.clearErrors=(...t)=>(this.forceFormUpdate=!0,this.originalForm.clearErrors(...t)),this.trigger=this.originalForm.trigger,this.resetField=(...t)=>(this.forceFormUpdate=!0,this.originalForm.resetField(...t)),this.unregister=this.originalForm.unregister,this.control=this.originalForm.control,this.register=this.originalForm.register,this.setFocus=this.originalForm.setFocus,this.setValue=(...t)=>(this.forceFormUpdate=!0,this.forceFormValuesUpdate=!0,this.originalForm.setValue(...t)),this.getValues=this.originalForm.getValues,this.resetForm=(...t)=>(this.forceFormUpdate=!0,this.originalForm.reset(...t)),this._observableStruct=new o.DeepObservableStruct({values:this.originalForm.getValues(),errors:{},dirtyFields:{},touchedFields:{},validatingFields:{}}),this.values=this._observableStruct.data.values,this.errors=this._observableStruct.data.errors,this.validatingFields=this._observableStruct.data.validatingFields,this.dirtyFields=this._observableStruct.data.dirtyFields,this.touchedFields=this._observableStruct.data.touchedFields,this.defaultValues=l;const u=this.originalForm.subscribe({formState:{values:!0,errors:!0,isValid:!0,isDirty:!0,isValidating:!0,dirtyFields:!0,touchedFields:!0,validatingFields:!0},callback:t=>{this.forceFormUpdate||this.forceFormValuesUpdate||!1===this.config.lazyUpdates?(this.forceFormUpdate?this.forceFormUpdate=!1:this.forceFormValuesUpdate&&(this.forceFormValuesUpdate=!1),this.updateFormState(t)):this.scheduleUpdateFormState(t)}});o.applyObservable(this,[[s.observable.ref,"isDirty","isLoading","isSubmitted","isSubmitSuccessful","isSubmitting","isValidating","isValid","disabled","submitCount","isReady","originalForm"],[s.observable.deep,"defaultValues"],[s.computed,"hasErrors","isTouched"],[s.action,"updateFormState"],[s.action.bound,"submit","reset"]],!0),a&&s.reaction(()=>e(),t=>{this.resetForm(t)},{signal:this.abortController.signal,equals:s.comparer.structural}),this.abortController.signal.addEventListener("abort",()=>{u()})}get isTouched(){return Object.keys(this.touchedFields||{}).length>0}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,e=this.errors){const r=[],i=(e,s="")=>{e&&"object"==typeof e&&Object.entries(e).forEach(([e,o])=>{const a=s?`${s}.${e}`:e;if(l(o)){if(r.push({path:a,error:o}),t)return}else Array.isArray(o)?o.forEach((e,s)=>{const o=`${a}.${s}`;if(l(e)){if(r.push({path:o,error:e}),t)return}else"object"==typeof e&&i(e,o)}):"object"==typeof o&&i(o,a)})};return i(e),r}async validate(t){let e=null;const r=this.config.onSubmit,i=this.config.onSubmitFailed,s=this.shouldFocusError;this.shouldFocusError=!!t,this.config.onSubmit=void 0,this.config.onSubmitFailed=void 0;try{e=await this.submit()}catch(o){}return this.shouldFocusError=s,this.config.onSubmit=r,this.config.onSubmitFailed=i,e}updateFormState(t){this.stopScheduledFormStateUpdate();let e=!1;const r={};Object.entries(t).forEach(([t,i])=>{switch(t){case"touchedFields":case"validatingFields":case"dirtyFields":case"errors":case"values":e=!0,r[t]=i;break;default:null!=i&&(this[t]=i)}}),e&&this._observableStruct.set(r)}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=u,exports.MobxForm=class extends u{},exports.createForm=t=>new u(t),exports.isFieldError=l;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/is-field-error.ts","../src/form/form.ts","../src/components/controller.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport { action, comparer, computed, observable, reaction } 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 { applyObservable, DeepObservableStruct } from 'yummies/mobx';\nimport { isFieldError } from '../utils/index.js';\nimport type { ErrorWithPath, FormParams } from './form.types.js';\n\ntype FormFullState<TFieldValues extends FieldValues> =\n FormState<TFieldValues> & {\n values: TFieldValues;\n };\n\nexport class Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> implements FormFullState<TFieldValues>\n{\n values: TFieldValues;\n isDirty: boolean = false;\n isLoading: boolean = false;\n isSubmitted: boolean = false;\n isSubmitSuccessful: boolean = false;\n isSubmitting: boolean = false;\n isValidating: boolean = false;\n isValid: boolean = false;\n disabled: boolean = false;\n submitCount: number = 0;\n /**\n * If you want to change this property\n * Use {resetForm} method\n */\n defaultValues: Readonly<DefaultValues<TFieldValues>>;\n dirtyFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n touchedFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n validatingFields: Partial<\n Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>\n >;\n errors: FieldErrors<TFieldValues>;\n isReady: boolean = false;\n\n /**\n * Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)\n *\n * @param name - the path name to the form field value.\n * @param error - an error object which contains type and optional message\n * @param options - whether or not to focus on the field\n *\n * @example\n * ```tsx\n * // when the error is not associated with any fields, `clearError` will need to invoke to clear the error\n * const onSubmit = () => setError(\"serverError\", { type: \"server\", message: \"Error occurred\"})\n *\n * <button onClick={() => setError(\"name\", { type: \"min\" })} />\n *\n * // focus on the input after setting the error\n * <button onClick={() => setError(\"name\", { type: \"max\" }, { shouldFocus: true })} />\n * ```\n */\n setError: UseFormSetError<TFieldValues>;\n\n /**\n * Clear the entire form errors.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)\n *\n * @param name - the path name to the form field value.\n *\n * @example\n * Clear all errors\n * ```tsx\n * clearErrors(); // clear the entire form error\n * clearErrors([\"name\", \"name1\"]) // clear an array of fields' error\n * clearErrors(\"name2\"); // clear a single field error\n * ```\n */\n clearErrors: UseFormClearErrors<TFieldValues>;\n\n /**\n * Trigger field or form validation\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)\n *\n * @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an array of fields, and a single field name will only trigger that field's validation.\n * @param options - should focus on the error field\n *\n * @returns validation result\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * trigger();\n * }, [trigger])\n *\n * <button onClick={async () => {\n * const result = await trigger(); // result will be a boolean value\n * }}>\n * trigger\n * </button>\n * ```\n */\n trigger: UseFormTrigger<TFieldValues>;\n\n /**\n * Reset a field state and reference.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * <input {...register(\"firstName\", { required: true })} />\n * <button type=\"button\" onClick={() => resetField(\"firstName\"))}>Reset</button>\n * ```\n */\n resetField: UseFormResetField<TFieldValues>;\n\n /**\n * Unregister a field reference and remove its value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * register(\"name\", { required: true })\n *\n * <button onClick={() => unregister(\"name\")} />\n * // there are various keep options to retain formState\n * <button onClick={() => unregister(\"name\", { keepErrors: true })} />\n * ```\n */\n unregister: UseFormUnregister<TFieldValues>;\n\n /**\n * Form control\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/control)\n *\n */\n control: Control<TFieldValues, TContext, TTransformedValues>;\n\n /**\n * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)\n *\n * @param name - the path name to the form field value, name is required and unique\n * @param options - register options include validation, disabled, unregister, value as and dependent validation\n *\n * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.\n *\n * @example\n * ```tsx\n * // Register HTML native input\n * <input {...register(\"input\")} />\n * <select {...register(\"select\")} />\n *\n * // Register options\n * <textarea {...register(\"textarea\", { required: \"This is required.\", maxLength: 20 })} />\n * <input type=\"number\" {...register(\"name2\", { valueAsNumber: true })} />\n * <input {...register(\"name3\", { deps: [\"name2\"] })} />\n *\n * // Register custom field at useEffect\n * useEffect(() => {\n * register(\"name4\");\n * register(\"name5\", { value: \"hiddenValue\" });\n * }, [register])\n *\n * // Register without ref\n * const { onChange, onBlur, name } = register(\"name6\")\n * <input onChange={onChange} onBlur={onBlur} name={name} />\n * ```\n */\n register: UseFormRegister<TFieldValues>;\n\n /**\n * Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)\n *\n * @param name - the path name to the form field value.\n * @param options - input focus behavior options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * setFocus(\"name\");\n * }, [setFocus])\n * // shouldSelect allows to select input's content on focus\n * <button onClick={() => setFocus(\"name\", { shouldSelect: true })}>Focus</button>\n * ```\n */\n setFocus: UseFormSetFocus<TFieldValues>;\n\n /**\n * Set a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * setValue('name', 'value', {\n * shouldValidate: true, // trigger validation\n * shouldTouch: true, // update touched fields form state\n * shouldDirty: true, // update dirty and dirty fields form state\n * });\n *\n * // Update a group fields\n * setValue('root', {\n * a: 'test', // setValue('root.a', 'data')\n * b: 'test1', // setValue('root.b', 'data')\n * });\n *\n * // Update a nested object field\n * setValue('select', { label: 'test', value: 'Test' });\n * ```\n */\n setValue: UseFormSetValue<TFieldValues>;\n\n /**\n * Get a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)\n *\n * @param fieldNames - the path name to the form field value.\n * @param options - returns only dirty fields or return only touchedFields\n *\n * @example\n * ```tsx\n * // Update a single field\n * getValues('name', 'value', {\n * dirtyFields: true, // returns only dirty fields\n * touchedFields: true, // returns only touchedFields\n * });\n *\n * // Get nested values\n * getValues('root.nested.0.value');\n * ```\n */\n getValues: UseFormGetValues<TFieldValues>;\n\n /**\n * Reset at the entire form state.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)\n *\n * @param values - the entire form values to be reset\n * @param keepStateOptions - keep form state options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * // reset the entire form after component mount or form defaultValues is ready\n * reset({\n * fieldA: \"test\"\n * fieldB: \"test\"\n * });\n * }, [reset])\n *\n * // reset by combine with existing form values\n * reset({\n * ...getValues(),\n * fieldB: \"test\"\n *});\n *\n * // reset and keep form state\n * reset({\n * ...getValues(),\n *}, {\n * keepErrors: true,\n * keepDirty: true\n *});\n * ```\n */\n resetForm: UseFormReset<TFieldValues>;\n\n protected abortController: AbortController;\n\n /**\n * Original react-hook-form form\n */\n originalForm: ReturnType<\n typeof createFormControl<TFieldValues, TContext, TTransformedValues>\n >;\n\n private _observableStruct: DeepObservableStruct<\n Pick<\n FormFullState<TFieldValues>,\n 'dirtyFields' | 'errors' | 'touchedFields' | 'validatingFields' | 'values'\n >\n >;\n\n shouldFocusError: boolean;\n\n private config: FormParams<TFieldValues, TContext, TTransformedValues>;\n\n // special hack to apply the same form value changes from the original form\n // using subscription\n private forceFormUpdate: boolean;\n\n constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\n this.forceFormUpdate = false;\n\n const defaultValuesRaw = config.defaultValues;\n const isDefaultValuesRawFn = typeof defaultValuesRaw === 'function';\n\n const defaultValues = isDefaultValuesRawFn\n ? defaultValuesRaw()\n : defaultValuesRaw\n ? { ...defaultValuesRaw }\n : ({} as any);\n\n this.config = {\n ...config,\n defaultValues: { ...defaultValues } as DefaultValues<TFieldValues>,\n shouldFocusError: this.shouldFocusError,\n };\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n Object.defineProperty(\n this.originalForm.control._options,\n 'shouldFocusError',\n {\n get: () => this.shouldFocusError,\n },\n );\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n this.defaultValues = defaultValues;\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (rawFormState) => {\n if (this.forceFormUpdate || this.config.lazyUpdates === false) {\n this.forceFormUpdate = false;\n this.updateFormState(rawFormState);\n } else {\n this.scheduleUpdateFormState(rawFormState);\n }\n },\n });\n\n applyObservable(\n this,\n [\n [\n observable.ref,\n 'isDirty',\n 'isLoading',\n 'isSubmitted',\n 'isSubmitSuccessful',\n 'isSubmitting',\n 'isValidating',\n 'isValid',\n 'disabled',\n 'submitCount',\n 'isReady',\n 'originalForm',\n ],\n [observable.deep, 'defaultValues'],\n [computed, 'hasErrors'],\n [action, 'updateFormState'],\n [action.bound, 'submit', 'reset'],\n ],\n true,\n );\n\n if (isDefaultValuesRawFn) {\n reaction(\n () => defaultValuesRaw(),\n (defaultValues) => {\n this.resetForm(defaultValues);\n },\n {\n signal: this.abortController.signal,\n equals: comparer.structural,\n },\n );\n }\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n });\n }\n\n /**\n * The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty\n * It should work the same as field.onChange from react-hook-form's Controller\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true });\n *\n * ** form submitted **\n *\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true, shouldValidate: true });\n * ```\n */\n changeField = <\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n >(\n name: TFieldName,\n value: FieldPathValue<TFieldValues, TFieldName> | undefined,\n options?: SetValueConfig,\n ) => {\n return this.setValue(name, value as any, {\n shouldDirty: true,\n shouldValidate: this.isSubmitted,\n ...options,\n });\n };\n\n /**\n * Method to manually submit form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onSubmit={form.submit} />\n */\n submit(e?: BaseSyntheticEvent) {\n return new Promise<TTransformedValues>((resolve, reject) => {\n if (this.originalForm) {\n this.originalForm.handleSubmit(\n async (data, event) => {\n if (this.config.strictSubmitChecks) {\n const anyErrorWithPath = this.getErrorsWithPaths(true)[0];\n if (anyErrorWithPath) {\n this.setFocus(anyErrorWithPath.path);\n await this.config.onSubmitFailed?.(this.errors, event);\n reject(this.errors);\n return;\n }\n }\n await this.config.onSubmit?.(data, event);\n resolve(data);\n },\n async (errors, event) => {\n await this.config.onSubmitFailed?.(errors, event);\n reject(errors);\n },\n )(e);\n } else {\n const emptyData = (this.values ?? {}) as unknown as TTransformedValues;\n const result = this.config.onSubmit?.(emptyData);\n if (result instanceof Promise) {\n return result.then(() => resolve(emptyData));\n } else {\n return Promise.resolve(emptyData);\n }\n }\n });\n }\n\n /**\n * Method to manually reset all form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onReset={form.reset} />\n */\n reset(e?: BaseSyntheticEvent) {\n this.resetForm();\n this.config.onReset?.(e);\n }\n\n get hasErrors() {\n return Object.keys(this.errors).length > 0;\n }\n\n getErrorsWithPaths(getOnlyFirst?: boolean): ErrorWithPath<TFieldValues>[] {\n const result: ErrorWithPath<TFieldValues>[] = [];\n\n const traverse = (obj: any, prefix = '') => {\n if (!obj || typeof obj !== 'object') return;\n\n Object.entries(obj).forEach(([key, value]) => {\n const path = (prefix ? `${prefix}.${key}` : key) as any;\n\n if (isFieldError(value)) {\n result.push({ path, error: value });\n if (getOnlyFirst) {\n return;\n }\n } else if (Array.isArray(value)) {\n value.forEach((item, idx) => {\n const arrayPath = `${path}.${idx}` as any;\n\n if (isFieldError(item)) {\n result.push({ path: arrayPath, error: item });\n if (getOnlyFirst) {\n return;\n }\n } else if (typeof item === 'object') {\n traverse(item, arrayPath);\n }\n });\n } else if (typeof value === 'object') {\n traverse(value, path);\n }\n });\n };\n\n traverse(this.errors);\n\n return result;\n }\n\n private updateFormState({\n values,\n errors,\n dirtyFields,\n validatingFields,\n touchedFields,\n ...simpleProperties\n }: Partial<FormFullState<TFieldValues>>) {\n this.stopScheduledFormStateUpdate();\n Object.entries(simpleProperties).forEach(([key, value]) => {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n });\n\n this._observableStruct.set({\n dirtyFields,\n errors,\n touchedFields,\n validatingFields,\n values,\n });\n }\n\n protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n private stopScheduledFormStateUpdate = () => {\n if (this.lastTimeoutId !== undefined) {\n clearTimeout(this.lastTimeoutId);\n this.lastTimeoutId = undefined;\n }\n };\n\n private scheduleUpdateFormState = (\n rawFormState: Partial<FormFullState<TFieldValues>>,\n ) => {\n this.stopScheduledFormStateUpdate();\n this.lastTimeoutId = setTimeout(() => {\n this.updateFormState(rawFormState);\n this.lastTimeoutId = undefined;\n }, this.config.lazyUpdatesTimer ?? 0);\n };\n\n destroy(): void {\n this.abortController.abort();\n this.stopScheduledFormStateUpdate();\n }\n}\n\nexport const createForm = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n config: FormParams<TFieldValues, TContext, TTransformedValues>,\n) => new Form(config);\n\n/**\n * @deprecated ⚠️ use `Form`. This export will be removed in next major release\n */\nexport class MobxForm<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> extends Form<TFieldValues, TContext, TTransformedValues> {}\n","import { Observer } from 'mobx-react-lite';\nimport { Controller as LibController } from 'react-hook-form';\n\nexport const Controller = ((props: any) => (\n <LibController\n {...props}\n render={(renderProps) => (\n <Observer>{() => props.render(renderProps)}</Observer>\n )}\n />\n)) as unknown as typeof LibController;\n"],"names":["isFieldError","value","typeGuard","isObject","Form","values","isDirty","isLoading","isSubmitted","isSubmitSuccessful","isSubmitting","isValidating","isValid","disabled","submitCount","defaultValues","dirtyFields","touchedFields","validatingFields","errors","isReady","setError","clearErrors","trigger","resetField","unregister","control","register","setFocus","setValue","getValues","resetForm","abortController","originalForm","_observableStruct","shouldFocusError","config","forceFormUpdate","constructor","this","LinkedAbortController","abortSignal","defaultValuesRaw","isDefaultValuesRawFn","createFormControl","Object","defineProperty","_options","get","args","reset","DeepObservableStruct","data","subscription","subscribe","formState","callback","rawFormState","lazyUpdates","updateFormState","scheduleUpdateFormState","applyObservable","observable","ref","deep","computed","action","bound","reaction","signal","equals","comparer","structural","addEventListener","changeField","name","options","shouldDirty","shouldValidate","submit","e","Promise","resolve","reject","emptyData","result","onSubmit","then","handleSubmit","async","event","strictSubmitChecks","anyErrorWithPath","getErrorsWithPaths","path","onSubmitFailed","onReset","hasErrors","keys","length","getOnlyFirst","traverse","obj","prefix","entries","forEach","key","push","error","Array","isArray","item","idx","arrayPath","simpleProperties","stopScheduledFormStateUpdate","set","lastTimeoutId","clearTimeout","setTimeout","lazyUpdatesTimer","destroy","abort","props","jsx","LibController","render","renderProps","Observer","children"],"mappings":"gSAGaA,EAAgBC,GACpBC,EAAAA,UAAUC,SAASF,IAAU,SAAUA,EC+BzC,MAAMG,EAMXC,OACAC,SAAmB,EACnBC,WAAqB,EACrBC,aAAuB,EACvBC,oBAA8B,EAC9BC,cAAwB,EACxBC,cAAwB,EACxBC,SAAmB,EACnBC,UAAoB,EACpBC,YAAsB,EAKtBC,cACAC,YACAC,cACAC,iBAGAC,OACAC,SAAmB,EAuBnBC,SAkBAC,YA0BAC,QAiBAC,WAoBAC,WASAC,QAmCAC,SAoBAC,SA+BAC,SAuBAC,UAoCAC,UAEUC,gBAKVC,aAIQC,kBAORC,iBAEQC,OAIAC,gBAER,WAAAC,CAAYF,GACVG,KAAKP,gBAAkB,IAAIQ,wBAAsBJ,EAAOK,aAExDF,KAAKJ,iBAAmBC,EAAOD,mBAAoB,EACnDI,KAAKF,iBAAkB,EAEvB,MAAMK,EAAmBN,EAAOrB,cAC1B4B,EAAmD,mBAArBD,EAE9B3B,EAAgB4B,EAClBD,IACAA,EACE,IAAKA,GACJ,CAAA,EAEPH,KAAKH,OAAS,IACTA,EACHrB,cAAe,IAAKA,GACpBoB,iBAAkBI,KAAKJ,kBAGzBI,KAAKN,aAAeW,oBAIlBL,KAAKH,QAEPS,OAAOC,eACLP,KAAKN,aAAaP,QAAQqB,SAC1B,mBACA,CACEC,IAAK,IAAMT,KAAKJ,mBAIpBI,KAAKlB,SAAW,IAAI4B,KAClBV,KAAKF,iBAAkB,EAChBE,KAAKN,aAAaZ,YAAY4B,IAEvCV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5E,KAAK8E,cAAgBE,WAAW,KAC9BhF,KAAKoB,gBAAgBF,GACrBlB,KAAK8E,mBAAgB,GACpB9E,KAAKH,OAAOoF,kBAAoB,IAGrC,OAAAC,GACElF,KAAKP,gBAAgB0F,QACrBnF,KAAK4E,8BACP,qBCxpB0BQ,GAC1BC,EAAAA,IAACC,EAAAA,WAAA,IACKF,EACJG,OAASC,GACPH,EAAAA,IAACI,EAAAA,UAAUC,SAAA,IAAMN,EAAMG,OAAOC,uCDkqB7B,cAIG3H,uBAVRgC,GACG,IAAIhC,EAAKgC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/is-field-error.ts","../src/form/form.ts","../src/components/controller.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport { action, comparer, computed, observable, reaction } 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 { applyObservable, DeepObservableStruct } from 'yummies/mobx';\nimport type { AnyObject } from 'yummies/types';\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 protected 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 private forceFormValuesUpdate: 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 this.forceFormValuesUpdate = false;\n\n const defaultValuesRaw = config.defaultValues;\n const isDefaultValuesRawFn = typeof defaultValuesRaw === 'function';\n\n const defaultValues = isDefaultValuesRawFn\n ? defaultValuesRaw()\n : defaultValuesRaw\n ? { ...defaultValuesRaw }\n : ({} as any);\n\n this.config = {\n ...config,\n defaultValues: { ...defaultValues } as DefaultValues<TFieldValues>,\n shouldFocusError: this.shouldFocusError,\n };\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n Object.defineProperty(\n this.originalForm.control._options,\n 'shouldFocusError',\n {\n get: () => this.shouldFocusError,\n },\n );\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n this.forceFormValuesUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n this.defaultValues = defaultValues;\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (upd) => {\n if (\n this.forceFormUpdate ||\n this.forceFormValuesUpdate ||\n this.config.lazyUpdates === false\n ) {\n if (this.forceFormUpdate) {\n this.forceFormUpdate = false;\n } else if (this.forceFormValuesUpdate) {\n this.forceFormValuesUpdate = false;\n }\n\n this.updateFormState(upd);\n } else {\n this.scheduleUpdateFormState(upd);\n }\n },\n });\n\n applyObservable(\n this,\n [\n [\n observable.ref,\n 'isDirty',\n 'isLoading',\n 'isSubmitted',\n 'isSubmitSuccessful',\n 'isSubmitting',\n 'isValidating',\n 'isValid',\n 'disabled',\n 'submitCount',\n 'isReady',\n 'originalForm',\n ],\n [observable.deep, 'defaultValues'],\n [computed, 'hasErrors', 'isTouched'],\n [action, 'updateFormState'],\n [action.bound, 'submit', 'reset'],\n ],\n true,\n );\n\n if (isDefaultValuesRawFn) {\n reaction(\n () => defaultValuesRaw(),\n (defaultValues) => {\n this.resetForm(defaultValues);\n },\n {\n signal: this.abortController.signal,\n equals: comparer.structural,\n },\n );\n }\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n });\n }\n\n get isTouched() {\n return Object.keys(this.touchedFields || {}).length > 0;\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(\n getOnlyFirst?: boolean,\n errors = this.errors,\n ): 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(errors);\n\n return result;\n }\n\n async validate(focusOnError?: boolean): Promise<TTransformedValues | null> {\n let result: TTransformedValues | null = null;\n\n const originalSubmitHandler = this.config.onSubmit;\n const originalSubmitFailedHandler = this.config.onSubmitFailed;\n const originalShouldFocusError = this.shouldFocusError;\n\n this.shouldFocusError = !!focusOnError;\n this.config.onSubmit = undefined;\n this.config.onSubmitFailed = undefined;\n\n try {\n result = await this.submit();\n } catch (_) {}\n\n this.shouldFocusError = originalShouldFocusError;\n this.config.onSubmit = originalSubmitHandler;\n this.config.onSubmitFailed = originalSubmitFailedHandler;\n\n return result;\n }\n\n private updateFormState(\n formStateUpdate: Partial<FormFullState<TFieldValues>>,\n ) {\n this.stopScheduledFormStateUpdate();\n\n let hasKeys = false;\n const upd: AnyObject = {};\n\n Object.entries(formStateUpdate).forEach(([key, value]) => {\n switch (key) {\n case 'touchedFields':\n case 'validatingFields':\n case 'dirtyFields':\n case 'errors':\n case 'values': {\n hasKeys = true;\n upd[key] = value;\n break;\n }\n default: {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n }\n }\n });\n\n if (hasKeys) {\n this._observableStruct.set(upd);\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","forceFormValuesUpdate","constructor","this","LinkedAbortController","abortSignal","defaultValuesRaw","isDefaultValuesRawFn","createFormControl","Object","defineProperty","_options","get","args","reset","DeepObservableStruct","data","subscription","subscribe","formState","callback","upd","lazyUpdates","updateFormState","scheduleUpdateFormState","applyObservable","observable","ref","deep","computed","action","bound","reaction","signal","equals","comparer","structural","addEventListener","isTouched","keys","length","changeField","name","options","shouldDirty","shouldValidate","submit","e","Promise","resolve","reject","emptyData","result","onSubmit","then","handleSubmit","async","event","strictSubmitChecks","anyErrorWithPath","getErrorsWithPaths","path","onSubmitFailed","onReset","hasErrors","getOnlyFirst","traverse","obj","prefix","entries","forEach","key","push","error","Array","isArray","item","idx","arrayPath","validate","focusOnError","originalSubmitHandler","originalSubmitFailedHandler","originalShouldFocusError","_","formStateUpdate","stopScheduledFormStateUpdate","hasKeys","set","lastTimeoutId","clearTimeout","rawFormState","setTimeout","lazyUpdatesTimer","destroy","abort","props","jsx","LibController","render","renderProps","Observer","children"],"mappings":"gSAGaA,EAAgBC,GACpBC,EAAAA,UAAUC,SAASF,IAAU,SAAUA,ECgCzC,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,iBAEUC,OAIFC,gBACAC,sBAER,WAAAC,CAAYH,GACVI,KAAKR,gBAAkB,IAAIS,wBAAsBL,EAAOM,aAExDF,KAAKL,iBAAmBC,EAAOD,mBAAoB,EACnDK,KAAKH,iBAAkB,EACvBG,KAAKF,uBAAwB,EAE7B,MAAMK,EAAmBP,EAAOrB,cAC1B6B,EAAmD,mBAArBD,EAE9B5B,EAAgB6B,EAClBD,IACAA,EACE,IAAKA,GACJ,CAAA,EAEPH,KAAKJ,OAAS,IACTA,EACHrB,cAAe,IAAKA,GACpBoB,iBAAkBK,KAAKL,kBAGzBK,KAAKP,aAAeY,oBAIlBL,KAAKJ,QAEPU,OAAOC,eACLP,KAAKP,aAAaP,QAAQsB,SAC1B,mBACA,CACEC,IAAK,IAAMT,KAAKL,mBAIpBK,KAAKnB,SAAW,IAAI6B,KAClBV,KAAKH,iBAAkB,EAChBG,KAAKP,aAA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AOsD,cAAW,EACvBlD,KAAKJ,OAAO+D,oBAAiB,EAE7B,IACEV,QAAejD,KAAK2C,QACtB,OAASsC,GAAI,CAMb,OAJAjF,KAAKL,iBAAmBqF,EACxBhF,KAAKJ,OAAOsD,SAAW4B,EACvB9E,KAAKJ,OAAO+D,eAAiBoB,EAEtB9B,CACT,CAEQ,eAAA7B,CACN8D,GAEAlF,KAAKmF,+BAEL,IAAIC,GAAU,EACd,MAAMlE,EAAiB,CAAA,EAEvBZ,OAAO4D,QAAQgB,GAAiBf,QAAQ,EAAEC,EAAK3G,MAC7C,OAAQ2G,GACN,IAAK,gBACL,IAAK,mBACL,IAAK,cACL,IAAK,SACL,IAAK,SACHgB,GAAU,EACVlE,EAAIkD,GAAO3G,EACX,MAEF,QACe,MAATA,IAEFuC,KAAKoE,GAAO3G,MAMhB2H,GACFpF,KAAKN,kBAAkB2F,IAAInE,EAE/B,CAEUoE,cAEFH,6BAA+B,UACV,IAAvBnF,KAAKsF,gBACPC,aAAavF,KAAKsF,eAClBtF,KAAKsF,mBAAgB,IAIjBjE,wBACNmE,IAEAxF,KAAKmF,+BACLnF,KAAKsF,cAAgBG,WAAW,KAC9BzF,KAAKoB,gBAAgBoE,GACrBxF,KAAKsF,mBAAgB,GACpBtF,KAAKJ,OAAO8F,kBAAoB,IAGrC,OAAAC,GACE3F,KAAKR,gBAAgBoG,QACrB5F,KAAKmF,8BACP,qBC1sB0BU,GAC1BC,EAAAA,IAACC,EAAAA,WAAA,IACKF,EACJG,OAASC,GACPH,EAAAA,IAACI,EAAAA,UAAUC,SAAA,IAAMN,EAAMG,OAAOC,uCDotB7B,cAIGrI,uBAVRgC,GACG,IAAIhC,EAAKgC"}
|
package/index.js
CHANGED
|
@@ -294,10 +294,12 @@ class Form {
|
|
|
294
294
|
// special hack to apply the same form value changes from the original form
|
|
295
295
|
// using subscription
|
|
296
296
|
forceFormUpdate;
|
|
297
|
+
forceFormValuesUpdate;
|
|
297
298
|
constructor(config) {
|
|
298
299
|
this.abortController = new LinkedAbortController(config.abortSignal);
|
|
299
300
|
this.shouldFocusError = config.shouldFocusError ?? true;
|
|
300
301
|
this.forceFormUpdate = false;
|
|
302
|
+
this.forceFormValuesUpdate = false;
|
|
301
303
|
const defaultValuesRaw = config.defaultValues;
|
|
302
304
|
const isDefaultValuesRawFn = typeof defaultValuesRaw === "function";
|
|
303
305
|
const defaultValues = isDefaultValuesRawFn ? defaultValuesRaw() : defaultValuesRaw ? { ...defaultValuesRaw } : {};
|
|
@@ -333,6 +335,7 @@ class Form {
|
|
|
333
335
|
this.setFocus = this.originalForm.setFocus;
|
|
334
336
|
this.setValue = (...args) => {
|
|
335
337
|
this.forceFormUpdate = true;
|
|
338
|
+
this.forceFormValuesUpdate = true;
|
|
336
339
|
return this.originalForm.setValue(...args);
|
|
337
340
|
};
|
|
338
341
|
this.getValues = this.originalForm.getValues;
|
|
@@ -364,12 +367,16 @@ class Form {
|
|
|
364
367
|
touchedFields: true,
|
|
365
368
|
validatingFields: true
|
|
366
369
|
},
|
|
367
|
-
callback: (
|
|
368
|
-
if (this.forceFormUpdate || this.config.lazyUpdates === false) {
|
|
369
|
-
this.forceFormUpdate
|
|
370
|
-
|
|
370
|
+
callback: (upd) => {
|
|
371
|
+
if (this.forceFormUpdate || this.forceFormValuesUpdate || this.config.lazyUpdates === false) {
|
|
372
|
+
if (this.forceFormUpdate) {
|
|
373
|
+
this.forceFormUpdate = false;
|
|
374
|
+
} else if (this.forceFormValuesUpdate) {
|
|
375
|
+
this.forceFormValuesUpdate = false;
|
|
376
|
+
}
|
|
377
|
+
this.updateFormState(upd);
|
|
371
378
|
} else {
|
|
372
|
-
this.scheduleUpdateFormState(
|
|
379
|
+
this.scheduleUpdateFormState(upd);
|
|
373
380
|
}
|
|
374
381
|
}
|
|
375
382
|
});
|
|
@@ -391,7 +398,7 @@ class Form {
|
|
|
391
398
|
"originalForm"
|
|
392
399
|
],
|
|
393
400
|
[observable.deep, "defaultValues"],
|
|
394
|
-
[computed, "hasErrors"],
|
|
401
|
+
[computed, "hasErrors", "isTouched"],
|
|
395
402
|
[action, "updateFormState"],
|
|
396
403
|
[action.bound, "submit", "reset"]
|
|
397
404
|
],
|
|
@@ -413,6 +420,9 @@ class Form {
|
|
|
413
420
|
subscription();
|
|
414
421
|
});
|
|
415
422
|
}
|
|
423
|
+
get isTouched() {
|
|
424
|
+
return Object.keys(this.touchedFields || {}).length > 0;
|
|
425
|
+
}
|
|
416
426
|
/**
|
|
417
427
|
* The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty
|
|
418
428
|
* It should work the same as field.onChange from react-hook-form's Controller
|
|
@@ -498,7 +508,7 @@ class Form {
|
|
|
498
508
|
get hasErrors() {
|
|
499
509
|
return Object.keys(this.errors).length > 0;
|
|
500
510
|
}
|
|
501
|
-
getErrorsWithPaths(getOnlyFirst) {
|
|
511
|
+
getErrorsWithPaths(getOnlyFirst, errors = this.errors) {
|
|
502
512
|
const result = [];
|
|
503
513
|
const traverse = (obj, prefix = "") => {
|
|
504
514
|
if (!obj || typeof obj !== "object") return;
|
|
@@ -526,30 +536,51 @@ class Form {
|
|
|
526
536
|
}
|
|
527
537
|
});
|
|
528
538
|
};
|
|
529
|
-
traverse(
|
|
539
|
+
traverse(errors);
|
|
540
|
+
return result;
|
|
541
|
+
}
|
|
542
|
+
async validate(focusOnError) {
|
|
543
|
+
let result = null;
|
|
544
|
+
const originalSubmitHandler = this.config.onSubmit;
|
|
545
|
+
const originalSubmitFailedHandler = this.config.onSubmitFailed;
|
|
546
|
+
const originalShouldFocusError = this.shouldFocusError;
|
|
547
|
+
this.shouldFocusError = !!focusOnError;
|
|
548
|
+
this.config.onSubmit = void 0;
|
|
549
|
+
this.config.onSubmitFailed = void 0;
|
|
550
|
+
try {
|
|
551
|
+
result = await this.submit();
|
|
552
|
+
} catch (_) {
|
|
553
|
+
}
|
|
554
|
+
this.shouldFocusError = originalShouldFocusError;
|
|
555
|
+
this.config.onSubmit = originalSubmitHandler;
|
|
556
|
+
this.config.onSubmitFailed = originalSubmitFailedHandler;
|
|
530
557
|
return result;
|
|
531
558
|
}
|
|
532
|
-
updateFormState({
|
|
533
|
-
values,
|
|
534
|
-
errors,
|
|
535
|
-
dirtyFields,
|
|
536
|
-
validatingFields,
|
|
537
|
-
touchedFields,
|
|
538
|
-
...simpleProperties
|
|
539
|
-
}) {
|
|
559
|
+
updateFormState(formStateUpdate) {
|
|
540
560
|
this.stopScheduledFormStateUpdate();
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
561
|
+
let hasKeys = false;
|
|
562
|
+
const upd = {};
|
|
563
|
+
Object.entries(formStateUpdate).forEach(([key, value]) => {
|
|
564
|
+
switch (key) {
|
|
565
|
+
case "touchedFields":
|
|
566
|
+
case "validatingFields":
|
|
567
|
+
case "dirtyFields":
|
|
568
|
+
case "errors":
|
|
569
|
+
case "values": {
|
|
570
|
+
hasKeys = true;
|
|
571
|
+
upd[key] = value;
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
default: {
|
|
575
|
+
if (value != null) {
|
|
576
|
+
this[key] = value;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
544
579
|
}
|
|
545
580
|
});
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
touchedFields,
|
|
550
|
-
validatingFields,
|
|
551
|
-
values
|
|
552
|
-
});
|
|
581
|
+
if (hasKeys) {
|
|
582
|
+
this._observableStruct.set(upd);
|
|
583
|
+
}
|
|
553
584
|
}
|
|
554
585
|
lastTimeoutId;
|
|
555
586
|
stopScheduledFormStateUpdate = () => {
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/components/controller.tsx","../src/utils/is-field-error.ts","../src/form/form.ts"],"sourcesContent":["import { Observer } from 'mobx-react-lite';\nimport { Controller as LibController } from 'react-hook-form';\n\nexport const Controller = ((props: any) => (\n <LibController\n {...props}\n render={(renderProps) => (\n <Observer>{() => props.render(renderProps)}</Observer>\n )}\n />\n)) as unknown as typeof LibController;\n","import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport { action, comparer, computed, observable, reaction } 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 { applyObservable, DeepObservableStruct } from 'yummies/mobx';\nimport { isFieldError } from '../utils/index.js';\nimport type { ErrorWithPath, FormParams } from './form.types.js';\n\ntype FormFullState<TFieldValues extends FieldValues> =\n FormState<TFieldValues> & {\n values: TFieldValues;\n };\n\nexport class Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> implements FormFullState<TFieldValues>\n{\n values: TFieldValues;\n isDirty: boolean = false;\n isLoading: boolean = false;\n isSubmitted: boolean = false;\n isSubmitSuccessful: boolean = false;\n isSubmitting: boolean = false;\n isValidating: boolean = false;\n isValid: boolean = false;\n disabled: boolean = false;\n submitCount: number = 0;\n /**\n * If you want to change this property\n * Use {resetForm} method\n */\n defaultValues: Readonly<DefaultValues<TFieldValues>>;\n dirtyFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n touchedFields: Partial<Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>>;\n validatingFields: Partial<\n Readonly<DeepMap<DeepPartial<TFieldValues>, boolean>>\n >;\n errors: FieldErrors<TFieldValues>;\n isReady: boolean = false;\n\n /**\n * Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)\n *\n * @param name - the path name to the form field value.\n * @param error - an error object which contains type and optional message\n * @param options - whether or not to focus on the field\n *\n * @example\n * ```tsx\n * // when the error is not associated with any fields, `clearError` will need to invoke to clear the error\n * const onSubmit = () => setError(\"serverError\", { type: \"server\", message: \"Error occurred\"})\n *\n * <button onClick={() => setError(\"name\", { type: \"min\" })} />\n *\n * // focus on the input after setting the error\n * <button onClick={() => setError(\"name\", { type: \"max\" }, { shouldFocus: true })} />\n * ```\n */\n setError: UseFormSetError<TFieldValues>;\n\n /**\n * Clear the entire form errors.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)\n *\n * @param name - the path name to the form field value.\n *\n * @example\n * Clear all errors\n * ```tsx\n * clearErrors(); // clear the entire form error\n * clearErrors([\"name\", \"name1\"]) // clear an array of fields' error\n * clearErrors(\"name2\"); // clear a single field error\n * ```\n */\n clearErrors: UseFormClearErrors<TFieldValues>;\n\n /**\n * Trigger field or form validation\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)\n *\n * @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an array of fields, and a single field name will only trigger that field's validation.\n * @param options - should focus on the error field\n *\n * @returns validation result\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * trigger();\n * }, [trigger])\n *\n * <button onClick={async () => {\n * const result = await trigger(); // result will be a boolean value\n * }}>\n * trigger\n * </button>\n * ```\n */\n trigger: UseFormTrigger<TFieldValues>;\n\n /**\n * Reset a field state and reference.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * <input {...register(\"firstName\", { required: true })} />\n * <button type=\"button\" onClick={() => resetField(\"firstName\"))}>Reset</button>\n * ```\n */\n resetField: UseFormResetField<TFieldValues>;\n\n /**\n * Unregister a field reference and remove its value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)\n *\n * @param name - the path name to the form field value.\n * @param options - keep form state options\n *\n * @example\n * ```tsx\n * register(\"name\", { required: true })\n *\n * <button onClick={() => unregister(\"name\")} />\n * // there are various keep options to retain formState\n * <button onClick={() => unregister(\"name\", { keepErrors: true })} />\n * ```\n */\n unregister: UseFormUnregister<TFieldValues>;\n\n /**\n * Form control\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/control)\n *\n */\n control: Control<TFieldValues, TContext, TTransformedValues>;\n\n /**\n * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)\n *\n * @param name - the path name to the form field value, name is required and unique\n * @param options - register options include validation, disabled, unregister, value as and dependent validation\n *\n * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.\n *\n * @example\n * ```tsx\n * // Register HTML native input\n * <input {...register(\"input\")} />\n * <select {...register(\"select\")} />\n *\n * // Register options\n * <textarea {...register(\"textarea\", { required: \"This is required.\", maxLength: 20 })} />\n * <input type=\"number\" {...register(\"name2\", { valueAsNumber: true })} />\n * <input {...register(\"name3\", { deps: [\"name2\"] })} />\n *\n * // Register custom field at useEffect\n * useEffect(() => {\n * register(\"name4\");\n * register(\"name5\", { value: \"hiddenValue\" });\n * }, [register])\n *\n * // Register without ref\n * const { onChange, onBlur, name } = register(\"name6\")\n * <input onChange={onChange} onBlur={onBlur} name={name} />\n * ```\n */\n register: UseFormRegister<TFieldValues>;\n\n /**\n * Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)\n *\n * @param name - the path name to the form field value.\n * @param options - input focus behavior options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * setFocus(\"name\");\n * }, [setFocus])\n * // shouldSelect allows to select input's content on focus\n * <button onClick={() => setFocus(\"name\", { shouldSelect: true })}>Focus</button>\n * ```\n */\n setFocus: UseFormSetFocus<TFieldValues>;\n\n /**\n * Set a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * setValue('name', 'value', {\n * shouldValidate: true, // trigger validation\n * shouldTouch: true, // update touched fields form state\n * shouldDirty: true, // update dirty and dirty fields form state\n * });\n *\n * // Update a group fields\n * setValue('root', {\n * a: 'test', // setValue('root.a', 'data')\n * b: 'test1', // setValue('root.b', 'data')\n * });\n *\n * // Update a nested object field\n * setValue('select', { label: 'test', value: 'Test' });\n * ```\n */\n setValue: UseFormSetValue<TFieldValues>;\n\n /**\n * Get a single field value, or a group of fields value.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)\n *\n * @param fieldNames - the path name to the form field value.\n * @param options - returns only dirty fields or return only touchedFields\n *\n * @example\n * ```tsx\n * // Update a single field\n * getValues('name', 'value', {\n * dirtyFields: true, // returns only dirty fields\n * touchedFields: true, // returns only touchedFields\n * });\n *\n * // Get nested values\n * getValues('root.nested.0.value');\n * ```\n */\n getValues: UseFormGetValues<TFieldValues>;\n\n /**\n * Reset at the entire form state.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)\n *\n * @param values - the entire form values to be reset\n * @param keepStateOptions - keep form state options\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * // reset the entire form after component mount or form defaultValues is ready\n * reset({\n * fieldA: \"test\"\n * fieldB: \"test\"\n * });\n * }, [reset])\n *\n * // reset by combine with existing form values\n * reset({\n * ...getValues(),\n * fieldB: \"test\"\n *});\n *\n * // reset and keep form state\n * reset({\n * ...getValues(),\n *}, {\n * keepErrors: true,\n * keepDirty: true\n *});\n * ```\n */\n resetForm: UseFormReset<TFieldValues>;\n\n protected abortController: AbortController;\n\n /**\n * Original react-hook-form form\n */\n originalForm: ReturnType<\n typeof createFormControl<TFieldValues, TContext, TTransformedValues>\n >;\n\n private _observableStruct: DeepObservableStruct<\n Pick<\n FormFullState<TFieldValues>,\n 'dirtyFields' | 'errors' | 'touchedFields' | 'validatingFields' | 'values'\n >\n >;\n\n shouldFocusError: boolean;\n\n private config: FormParams<TFieldValues, TContext, TTransformedValues>;\n\n // special hack to apply the same form value changes from the original form\n // using subscription\n private forceFormUpdate: boolean;\n\n constructor(config: FormParams<TFieldValues, TContext, TTransformedValues>) {\n this.abortController = new LinkedAbortController(config.abortSignal);\n\n this.shouldFocusError = config.shouldFocusError ?? true;\n this.forceFormUpdate = false;\n\n const defaultValuesRaw = config.defaultValues;\n const isDefaultValuesRawFn = typeof defaultValuesRaw === 'function';\n\n const defaultValues = isDefaultValuesRawFn\n ? defaultValuesRaw()\n : defaultValuesRaw\n ? { ...defaultValuesRaw }\n : ({} as any);\n\n this.config = {\n ...config,\n defaultValues: { ...defaultValues } as DefaultValues<TFieldValues>,\n shouldFocusError: this.shouldFocusError,\n };\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n Object.defineProperty(\n this.originalForm.control._options,\n 'shouldFocusError',\n {\n get: () => this.shouldFocusError,\n },\n );\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n this.defaultValues = defaultValues;\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (rawFormState) => {\n if (this.forceFormUpdate || this.config.lazyUpdates === false) {\n this.forceFormUpdate = false;\n this.updateFormState(rawFormState);\n } else {\n this.scheduleUpdateFormState(rawFormState);\n }\n },\n });\n\n applyObservable(\n this,\n [\n [\n observable.ref,\n 'isDirty',\n 'isLoading',\n 'isSubmitted',\n 'isSubmitSuccessful',\n 'isSubmitting',\n 'isValidating',\n 'isValid',\n 'disabled',\n 'submitCount',\n 'isReady',\n 'originalForm',\n ],\n [observable.deep, 'defaultValues'],\n [computed, 'hasErrors'],\n [action, 'updateFormState'],\n [action.bound, 'submit', 'reset'],\n ],\n true,\n );\n\n if (isDefaultValuesRawFn) {\n reaction(\n () => defaultValuesRaw(),\n (defaultValues) => {\n this.resetForm(defaultValues);\n },\n {\n signal: this.abortController.signal,\n equals: comparer.structural,\n },\n );\n }\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n });\n }\n\n /**\n * The same as setValue, but will trigger validation if form was submitted, also marks this field as dirty\n * It should work the same as field.onChange from react-hook-form's Controller\n *\n * @param name - the path name to the form field value.\n * @param value - field value\n * @param options - should validate or update form state\n *\n * @example\n * ```tsx\n * // Update a single field\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true });\n *\n * ** form submitted **\n *\n * changeField('name', 'value');\n * ->\n * setValue('name', 'value', { shouldDirty: true, shouldValidate: true });\n * ```\n */\n changeField = <\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n >(\n name: TFieldName,\n value: FieldPathValue<TFieldValues, TFieldName> | undefined,\n options?: SetValueConfig,\n ) => {\n return this.setValue(name, value as any, {\n shouldDirty: true,\n shouldValidate: this.isSubmitted,\n ...options,\n });\n };\n\n /**\n * Method to manually submit form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onSubmit={form.submit} />\n */\n submit(e?: BaseSyntheticEvent) {\n return new Promise<TTransformedValues>((resolve, reject) => {\n if (this.originalForm) {\n this.originalForm.handleSubmit(\n async (data, event) => {\n if (this.config.strictSubmitChecks) {\n const anyErrorWithPath = this.getErrorsWithPaths(true)[0];\n if (anyErrorWithPath) {\n this.setFocus(anyErrorWithPath.path);\n await this.config.onSubmitFailed?.(this.errors, event);\n reject(this.errors);\n return;\n }\n }\n await this.config.onSubmit?.(data, event);\n resolve(data);\n },\n async (errors, event) => {\n await this.config.onSubmitFailed?.(errors, event);\n reject(errors);\n },\n )(e);\n } else {\n const emptyData = (this.values ?? {}) as unknown as TTransformedValues;\n const result = this.config.onSubmit?.(emptyData);\n if (result instanceof Promise) {\n return result.then(() => resolve(emptyData));\n } else {\n return Promise.resolve(emptyData);\n }\n }\n });\n }\n\n /**\n * Method to manually reset all form.\n * Used to attach this method to <form /> element\n *\n * @example\n *\n * <form onReset={form.reset} />\n */\n reset(e?: BaseSyntheticEvent) {\n this.resetForm();\n this.config.onReset?.(e);\n }\n\n get hasErrors() {\n return Object.keys(this.errors).length > 0;\n }\n\n getErrorsWithPaths(getOnlyFirst?: boolean): ErrorWithPath<TFieldValues>[] {\n const result: ErrorWithPath<TFieldValues>[] = [];\n\n const traverse = (obj: any, prefix = '') => {\n if (!obj || typeof obj !== 'object') return;\n\n Object.entries(obj).forEach(([key, value]) => {\n const path = (prefix ? `${prefix}.${key}` : key) as any;\n\n if (isFieldError(value)) {\n result.push({ path, error: value });\n if (getOnlyFirst) {\n return;\n }\n } else if (Array.isArray(value)) {\n value.forEach((item, idx) => {\n const arrayPath = `${path}.${idx}` as any;\n\n if (isFieldError(item)) {\n result.push({ path: arrayPath, error: item });\n if (getOnlyFirst) {\n return;\n }\n } else if (typeof item === 'object') {\n traverse(item, arrayPath);\n }\n });\n } else if (typeof value === 'object') {\n traverse(value, path);\n }\n });\n };\n\n traverse(this.errors);\n\n return result;\n }\n\n private updateFormState({\n values,\n errors,\n dirtyFields,\n validatingFields,\n touchedFields,\n ...simpleProperties\n }: Partial<FormFullState<TFieldValues>>) {\n this.stopScheduledFormStateUpdate();\n Object.entries(simpleProperties).forEach(([key, value]) => {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n });\n\n this._observableStruct.set({\n dirtyFields,\n errors,\n touchedFields,\n validatingFields,\n values,\n });\n }\n\n protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n private stopScheduledFormStateUpdate = () => {\n if (this.lastTimeoutId !== undefined) {\n clearTimeout(this.lastTimeoutId);\n this.lastTimeoutId = undefined;\n }\n };\n\n private scheduleUpdateFormState = (\n rawFormState: Partial<FormFullState<TFieldValues>>,\n ) => {\n this.stopScheduledFormStateUpdate();\n this.lastTimeoutId = setTimeout(() => {\n this.updateFormState(rawFormState);\n this.lastTimeoutId = undefined;\n }, this.config.lazyUpdatesTimer ?? 0);\n };\n\n destroy(): void {\n this.abortController.abort();\n this.stopScheduledFormStateUpdate();\n }\n}\n\nexport const createForm = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n config: FormParams<TFieldValues, TContext, TTransformedValues>,\n) => new Form(config);\n\n/**\n * @deprecated ⚠️ use `Form`. This export will be removed in next major release\n */\nexport class MobxForm<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> extends Form<TFieldValues, TContext, TTransformedValues> {}\n"],"names":["LibController","defaultValues"],"mappings":";;;;;;;AAGO,MAAM,cAAc,CAAC,UAC1B;AAAA,EAACA;AAAAA,EAAA;AAAA,IACE,GAAG;AAAA,IACJ,QAAQ,CAAC,gBACP,oBAAC,YAAU,UAAA,MAAM,MAAM,OAAO,WAAW,EAAA,CAAE;AAAA,EAAA;AAE/C;ACNK,MAAM,eAAe,CAAC,UAAwC;AACnE,SAAO,UAAU,SAAS,KAAK,KAAK,UAAU;AAChD;AC8BO,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,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A,IACvB,GAAG,KAAK,OAAO,oBAAoB,CAAC;AAAA,EACtC;AAAA,EAEA,UAAgB;AACd,SAAK,gBAAgB,MAAA;AACrB,SAAK,6BAAA;AAAA,EACP;AACF;AAEO,MAAM,aAAa,CAKxB,WACG,IAAI,KAAK,MAAM;AAKb,MAAM,iBAIH,KAAiD;AAAC;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/components/controller.tsx","../src/utils/is-field-error.ts","../src/form/form.ts"],"sourcesContent":["import { Observer } from 'mobx-react-lite';\nimport { Controller as LibController } from 'react-hook-form';\n\nexport const Controller = ((props: any) => (\n <LibController\n {...props}\n render={(renderProps) => (\n <Observer>{() => props.render(renderProps)}</Observer>\n )}\n />\n)) as unknown as typeof LibController;\n","import type { FieldError } from 'react-hook-form';\nimport { typeGuard } from 'yummies/type-guard';\n\nexport const isFieldError = (value: unknown): value is FieldError => {\n return typeGuard.isObject(value) && 'type' in value;\n};\n","import { LinkedAbortController } from 'linked-abort-controller';\nimport { action, comparer, computed, observable, reaction } 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 { applyObservable, DeepObservableStruct } from 'yummies/mobx';\nimport type { AnyObject } from 'yummies/types';\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 protected 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 private forceFormValuesUpdate: 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 this.forceFormValuesUpdate = false;\n\n const defaultValuesRaw = config.defaultValues;\n const isDefaultValuesRawFn = typeof defaultValuesRaw === 'function';\n\n const defaultValues = isDefaultValuesRawFn\n ? defaultValuesRaw()\n : defaultValuesRaw\n ? { ...defaultValuesRaw }\n : ({} as any);\n\n this.config = {\n ...config,\n defaultValues: { ...defaultValues } as DefaultValues<TFieldValues>,\n shouldFocusError: this.shouldFocusError,\n };\n\n this.originalForm = createFormControl<\n TFieldValues,\n TContext,\n TTransformedValues\n >(this.config as any);\n\n Object.defineProperty(\n this.originalForm.control._options,\n 'shouldFocusError',\n {\n get: () => this.shouldFocusError,\n },\n );\n\n this.setError = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.setError(...args);\n };\n this.clearErrors = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.clearErrors(...args);\n };\n this.trigger = this.originalForm.trigger;\n this.resetField = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.resetField(...args);\n };\n this.unregister = this.originalForm.unregister;\n this.control = this.originalForm.control;\n this.register = this.originalForm.register;\n this.setFocus = this.originalForm.setFocus;\n this.setValue = (...args) => {\n this.forceFormUpdate = true;\n this.forceFormValuesUpdate = true;\n return this.originalForm.setValue(...args);\n };\n this.getValues = this.originalForm.getValues;\n this.resetForm = (...args) => {\n this.forceFormUpdate = true;\n return this.originalForm.reset(...args);\n };\n\n this._observableStruct = new DeepObservableStruct({\n values: this.originalForm.getValues(),\n errors: {},\n dirtyFields: {},\n touchedFields: {},\n validatingFields: {},\n });\n\n this.values = this._observableStruct.data.values;\n this.errors = this._observableStruct.data.errors;\n this.validatingFields = this._observableStruct.data.validatingFields;\n this.dirtyFields = this._observableStruct.data.dirtyFields;\n this.touchedFields = this._observableStruct.data.touchedFields;\n this.defaultValues = defaultValues;\n\n const subscription = this.originalForm.subscribe({\n formState: {\n values: true,\n errors: true,\n isValid: true,\n isDirty: true,\n isValidating: true,\n dirtyFields: true,\n touchedFields: true,\n validatingFields: true,\n },\n callback: (upd) => {\n if (\n this.forceFormUpdate ||\n this.forceFormValuesUpdate ||\n this.config.lazyUpdates === false\n ) {\n if (this.forceFormUpdate) {\n this.forceFormUpdate = false;\n } else if (this.forceFormValuesUpdate) {\n this.forceFormValuesUpdate = false;\n }\n\n this.updateFormState(upd);\n } else {\n this.scheduleUpdateFormState(upd);\n }\n },\n });\n\n applyObservable(\n this,\n [\n [\n observable.ref,\n 'isDirty',\n 'isLoading',\n 'isSubmitted',\n 'isSubmitSuccessful',\n 'isSubmitting',\n 'isValidating',\n 'isValid',\n 'disabled',\n 'submitCount',\n 'isReady',\n 'originalForm',\n ],\n [observable.deep, 'defaultValues'],\n [computed, 'hasErrors', 'isTouched'],\n [action, 'updateFormState'],\n [action.bound, 'submit', 'reset'],\n ],\n true,\n );\n\n if (isDefaultValuesRawFn) {\n reaction(\n () => defaultValuesRaw(),\n (defaultValues) => {\n this.resetForm(defaultValues);\n },\n {\n signal: this.abortController.signal,\n equals: comparer.structural,\n },\n );\n }\n\n this.abortController.signal.addEventListener('abort', () => {\n subscription();\n });\n }\n\n get isTouched() {\n return Object.keys(this.touchedFields || {}).length > 0;\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(\n getOnlyFirst?: boolean,\n errors = this.errors,\n ): 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(errors);\n\n return result;\n }\n\n async validate(focusOnError?: boolean): Promise<TTransformedValues | null> {\n let result: TTransformedValues | null = null;\n\n const originalSubmitHandler = this.config.onSubmit;\n const originalSubmitFailedHandler = this.config.onSubmitFailed;\n const originalShouldFocusError = this.shouldFocusError;\n\n this.shouldFocusError = !!focusOnError;\n this.config.onSubmit = undefined;\n this.config.onSubmitFailed = undefined;\n\n try {\n result = await this.submit();\n } catch (_) {}\n\n this.shouldFocusError = originalShouldFocusError;\n this.config.onSubmit = originalSubmitHandler;\n this.config.onSubmitFailed = originalSubmitFailedHandler;\n\n return result;\n }\n\n private updateFormState(\n formStateUpdate: Partial<FormFullState<TFieldValues>>,\n ) {\n this.stopScheduledFormStateUpdate();\n\n let hasKeys = false;\n const upd: AnyObject = {};\n\n Object.entries(formStateUpdate).forEach(([key, value]) => {\n switch (key) {\n case 'touchedFields':\n case 'validatingFields':\n case 'dirtyFields':\n case 'errors':\n case 'values': {\n hasKeys = true;\n upd[key] = value;\n break;\n }\n default: {\n if (value != null) {\n // @ts-expect-error\n this[key] = value;\n }\n }\n }\n });\n\n if (hasKeys) {\n this._observableStruct.set(upd);\n }\n }\n\n protected lastTimeoutId: ReturnType<typeof setTimeout> | undefined;\n\n private stopScheduledFormStateUpdate = () => {\n if (this.lastTimeoutId !== undefined) {\n clearTimeout(this.lastTimeoutId);\n this.lastTimeoutId = undefined;\n }\n };\n\n private scheduleUpdateFormState = (\n rawFormState: Partial<FormFullState<TFieldValues>>,\n ) => {\n this.stopScheduledFormStateUpdate();\n this.lastTimeoutId = setTimeout(() => {\n this.updateFormState(rawFormState);\n this.lastTimeoutId = undefined;\n }, this.config.lazyUpdatesTimer ?? 0);\n };\n\n destroy(): void {\n this.abortController.abort();\n this.stopScheduledFormStateUpdate();\n }\n}\n\nexport const createForm = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n config: FormParams<TFieldValues, TContext, TTransformedValues>,\n) => new Form(config);\n\n/**\n * @deprecated ⚠️ use `Form`. This export will be removed in next major release\n */\nexport class MobxForm<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> extends Form<TFieldValues, TContext, TTransformedValues> {}\n"],"names":["LibController","defaultValues"],"mappings":";;;;;;;AAGO,MAAM,cAAc,CAAC,UAC1B;AAAA,EAACA;AAAAA,EAAA;AAAA,IACE,GAAG;AAAA,IACJ,QAAQ,CAAC,gBACP,oBAAC,YAAU,UAAA,MAAM,MAAM,OAAO,WAAW,EAAA,CAAE;AAAA,EAAA;AAE/C;ACNK,MAAM,eAAe,CAAC,UAAwC;AACnE,SAAO,UAAU,SAAS,KAAK,KAAK,UAAU;AAChD;AC+BO,MAAM,KAKb;AAAA,EACE;AAAA,EACA,UAAmB;AAAA,EACnB,YAAqB;AAAA,EACrB,cAAuB;AAAA,EACvB,qBAA8B;AAAA,EAC9B,eAAwB;AAAA,EACxB,eAAwB;AAAA,EACxB,UAAmB;AAAA,EACnB,WAAoB;AAAA,EACpB,cAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA,UAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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Q,eAAe,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACxD,cAAQ,KAAA;AAAA,QACN,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK,UAAU;AACb,oBAAU;AACV,cAAI,GAAG,IAAI;AACX;AAAA,QACF;AAAA,QACA,SAAS;AACP,cAAI,SAAS,MAAM;AAEjB,iBAAK,GAAG,IAAI;AAAA,UACd;AAAA,QACF;AAAA,MAAA;AAAA,IAEJ,CAAC;AAED,QAAI,SAAS;AACX,WAAK,kBAAkB,IAAI,GAAG;AAAA,IAChC;AAAA,EACF;AAAA,EAEU;AAAA,EAEF,+BAA+B,MAAM;AAC3C,QAAI,KAAK,kBAAkB,QAAW;AACpC,mBAAa,KAAK,aAAa;AAC/B,WAAK,gBAAgB;AAAA,IACvB;AAAA,EACF;AAAA,EAEQ,0BAA0B,CAChC,iBACG;AACH,SAAK,6BAAA;AACL,SAAK,gBAAgB,WAAW,MAAM;AACpC,WAAK,gBAAgB,YAAY;AACjC,WAAK,gBAAgB;AAAA,IACvB,GAAG,KAAK,OAAO,oBAAoB,CAAC;AAAA,EACtC;AAAA,EAEA,UAAgB;AACd,SAAK,gBAAgB,MAAA;AACrB,SAAK,6BAAA;AAAA,EACP;AACF;AAEO,MAAM,aAAa,CAKxB,WACG,IAAI,KAAK,MAAM;AAKb,MAAM,iBAIH,KAAiD;AAAC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-react-hook-form",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@types/react": "^18.0.0 || ^19.0.0",
|
|
25
25
|
"linked-abort-controller": "^1.1.0",
|
|
26
|
-
"yummies": "^7.0
|
|
26
|
+
"yummies": "^7.10.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@biomejs/biome": "2.2.6",
|