remix-validated-form 4.3.1-beta.0 → 4.4.2
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/.turbo/turbo-build.log +5 -5
- package/browser/ValidatedForm.js +20 -35
- package/browser/hooks.d.ts +1 -1
- package/browser/hooks.js +10 -9
- package/browser/internal/hooks.d.ts +20 -9
- package/browser/internal/hooks.js +32 -23
- package/browser/internal/logic/getRadioChecked.js +1 -1
- package/browser/internal/state/cleanup.d.ts +2 -0
- package/browser/internal/state/cleanup.js +6 -0
- package/browser/internal/state/controlledFieldStore.d.ts +24 -0
- package/browser/internal/state/controlledFieldStore.js +57 -0
- package/browser/internal/state/controlledFields.d.ts +3 -116
- package/browser/internal/state/controlledFields.js +25 -68
- package/browser/internal/state/createFormStore.d.ts +40 -0
- package/browser/internal/state/createFormStore.js +83 -0
- package/browser/internal/state/storeFamily.d.ts +9 -0
- package/browser/internal/state/storeFamily.js +18 -0
- package/browser/internal/state/storeHooks.d.ts +5 -0
- package/browser/internal/state/storeHooks.js +10 -0
- package/browser/unreleased/formStateHooks.d.ts +15 -0
- package/browser/unreleased/formStateHooks.js +23 -14
- package/browser/userFacingFormContext.d.ts +15 -0
- package/browser/userFacingFormContext.js +6 -4
- package/dist/remix-validated-form.cjs.js +18 -1
- package/dist/remix-validated-form.cjs.js.map +1 -0
- package/dist/remix-validated-form.es.js +1039 -1729
- package/dist/remix-validated-form.es.js.map +1 -0
- package/dist/remix-validated-form.umd.js +18 -1
- package/dist/remix-validated-form.umd.js.map +1 -0
- package/dist/types/hooks.d.ts +1 -1
- package/dist/types/internal/hooks.d.ts +20 -9
- package/dist/types/internal/state/cleanup.d.ts +2 -0
- package/dist/types/internal/state/controlledFieldStore.d.ts +24 -0
- package/dist/types/internal/state/controlledFields.d.ts +3 -116
- package/dist/types/internal/state/createFormStore.d.ts +40 -0
- package/dist/types/internal/state/storeFamily.d.ts +9 -0
- package/dist/types/internal/state/storeHooks.d.ts +5 -0
- package/dist/types/unreleased/formStateHooks.d.ts +15 -0
- package/dist/types/userFacingFormContext.d.ts +15 -0
- package/package.json +4 -3
- package/src/ValidatedForm.tsx +38 -53
- package/src/hooks.ts +15 -18
- package/src/internal/hooks.ts +69 -45
- package/src/internal/logic/getRadioChecked.ts +1 -1
- package/src/internal/state/cleanup.ts +8 -0
- package/src/internal/state/controlledFieldStore.ts +91 -0
- package/src/internal/state/controlledFields.ts +31 -123
- package/src/internal/state/createFormStore.ts +152 -0
- package/src/internal/state/storeFamily.ts +24 -0
- package/src/internal/state/storeHooks.ts +22 -0
- package/src/unreleased/formStateHooks.ts +50 -27
- package/src/userFacingFormContext.ts +26 -5
- package/dist/types/internal/reset.d.ts +0 -28
- package/dist/types/internal/state/atomUtils.d.ts +0 -38
- package/dist/types/internal/state.d.ts +0 -343
- package/src/internal/reset.ts +0 -26
- package/src/internal/state/atomUtils.ts +0 -13
- package/src/internal/state.ts +0 -124
@@ -6,16 +6,19 @@ import {
|
|
6
6
|
useSetTouched,
|
7
7
|
useDefaultValuesForForm,
|
8
8
|
useFieldErrorsForForm,
|
9
|
-
|
9
|
+
useInternalIsSubmitting,
|
10
|
+
useInternalHasBeenSubmitted,
|
11
|
+
useTouchedFields,
|
12
|
+
useInternalIsValid,
|
13
|
+
useFieldErrors,
|
14
|
+
useValidateField,
|
15
|
+
useValidate,
|
16
|
+
useSetFieldErrors,
|
17
|
+
useResetFormElement,
|
18
|
+
useSyncedDefaultValues,
|
19
|
+
useFormActionProp,
|
20
|
+
useFormSubactionProp,
|
10
21
|
} from "../internal/hooks";
|
11
|
-
import {
|
12
|
-
fieldErrorsAtom,
|
13
|
-
formPropsAtom,
|
14
|
-
hasBeenSubmittedAtom,
|
15
|
-
isSubmittingAtom,
|
16
|
-
isValidAtom,
|
17
|
-
touchedFieldsAtom,
|
18
|
-
} from "../internal/state";
|
19
22
|
import { FieldErrors, TouchedFields } from "../validation/types";
|
20
23
|
|
21
24
|
export type FormState = {
|
@@ -35,29 +38,27 @@ export type FormState = {
|
|
35
38
|
* @param formId the id of the form. Only necessary if being used outside a ValidatedForm.
|
36
39
|
*/
|
37
40
|
export const useFormState = (formId?: string): FormState => {
|
38
|
-
const formContext = useInternalFormContext(formId, "
|
39
|
-
const
|
40
|
-
const
|
41
|
-
const
|
42
|
-
|
43
|
-
);
|
44
|
-
const
|
45
|
-
const isValid = useFormAtomValue(isValidAtom(formContext.formId));
|
41
|
+
const formContext = useInternalFormContext(formId, "useFormState");
|
42
|
+
const isSubmitting = useInternalIsSubmitting(formContext.formId);
|
43
|
+
const hasBeenSubmitted = useInternalHasBeenSubmitted(formContext.formId);
|
44
|
+
const touchedFields = useTouchedFields(formContext.formId);
|
45
|
+
const isValid = useInternalIsValid(formContext.formId);
|
46
|
+
const action = useFormActionProp(formContext.formId);
|
47
|
+
const subaction = useFormSubactionProp(formContext.formId);
|
46
48
|
|
49
|
+
const syncedDefaultValues = useSyncedDefaultValues(formContext.formId);
|
47
50
|
const defaultValuesToUse = useDefaultValuesForForm(formContext);
|
48
|
-
const hydratedDefaultValues =
|
49
|
-
|
50
|
-
);
|
51
|
+
const hydratedDefaultValues =
|
52
|
+
defaultValuesToUse.hydrateTo(syncedDefaultValues);
|
51
53
|
|
52
|
-
const fieldErrorsFromState =
|
53
|
-
fieldErrorsAtom(formContext.formId)
|
54
|
-
);
|
54
|
+
const fieldErrorsFromState = useFieldErrors(formContext.formId);
|
55
55
|
const fieldErrorsToUse = useFieldErrorsForForm(formContext);
|
56
56
|
const hydratedFieldErrors = fieldErrorsToUse.hydrateTo(fieldErrorsFromState);
|
57
57
|
|
58
58
|
return useMemo(
|
59
59
|
() => ({
|
60
|
-
|
60
|
+
action,
|
61
|
+
subaction,
|
61
62
|
defaultValues: hydratedDefaultValues,
|
62
63
|
fieldErrors: hydratedFieldErrors ?? {},
|
63
64
|
hasBeenSubmitted,
|
@@ -66,12 +67,13 @@ export const useFormState = (formId?: string): FormState => {
|
|
66
67
|
isValid,
|
67
68
|
}),
|
68
69
|
[
|
69
|
-
|
70
|
+
action,
|
70
71
|
hasBeenSubmitted,
|
71
72
|
hydratedDefaultValues,
|
72
73
|
hydratedFieldErrors,
|
73
74
|
isSubmitting,
|
74
75
|
isValid,
|
76
|
+
subaction,
|
75
77
|
touchedFields,
|
76
78
|
]
|
77
79
|
);
|
@@ -90,6 +92,21 @@ export type FormHelpers = {
|
|
90
92
|
* Change the touched state of the specified field.
|
91
93
|
*/
|
92
94
|
setTouched: (fieldName: string, touched: boolean) => void;
|
95
|
+
/**
|
96
|
+
* Validate the whole form and populate any errors.
|
97
|
+
*/
|
98
|
+
validate: () => Promise<void>;
|
99
|
+
/**
|
100
|
+
* Clears all errors on the form.
|
101
|
+
*/
|
102
|
+
clearAllErrors: () => void;
|
103
|
+
/**
|
104
|
+
* Resets the form.
|
105
|
+
*
|
106
|
+
* _Note_: The equivalent behavior can be achieved by calling formElement.reset()
|
107
|
+
* or clicking a button element with `type="reset"`.
|
108
|
+
*/
|
109
|
+
reset: () => void;
|
93
110
|
};
|
94
111
|
|
95
112
|
/**
|
@@ -100,14 +117,20 @@ export type FormHelpers = {
|
|
100
117
|
export const useFormHelpers = (formId?: string): FormHelpers => {
|
101
118
|
const formContext = useInternalFormContext(formId, "useFormHelpers");
|
102
119
|
const setTouched = useSetTouched(formContext);
|
103
|
-
const
|
120
|
+
const validateField = useValidateField(formContext.formId);
|
121
|
+
const validate = useValidate(formContext.formId);
|
104
122
|
const clearError = useClearError(formContext);
|
123
|
+
const setFieldErrors = useSetFieldErrors(formContext.formId);
|
124
|
+
const reset = useResetFormElement(formContext.formId);
|
105
125
|
return useMemo(
|
106
126
|
() => ({
|
107
127
|
setTouched,
|
108
128
|
validateField,
|
109
129
|
clearError,
|
130
|
+
validate,
|
131
|
+
clearAllErrors: () => setFieldErrors({}),
|
132
|
+
reset,
|
110
133
|
}),
|
111
|
-
[clearError, setTouched, validateField]
|
134
|
+
[clearError, reset, setFieldErrors, setTouched, validate, validateField]
|
112
135
|
);
|
113
136
|
};
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import { useCallback } from "react";
|
2
|
-
import {
|
3
|
-
|
2
|
+
import {
|
3
|
+
useInternalFormContext,
|
4
|
+
useRegisterReceiveFocus,
|
5
|
+
} from "./internal/hooks";
|
4
6
|
import { useFormHelpers, useFormState } from "./unreleased/formStateHooks";
|
5
7
|
import { FieldErrors, TouchedFields } from "./validation/types";
|
6
8
|
|
@@ -56,6 +58,21 @@ export type FormContextValue = {
|
|
56
58
|
* Change the touched state of the specified field.
|
57
59
|
*/
|
58
60
|
setFieldTouched: (fieldName: string, touched: boolean) => void;
|
61
|
+
/**
|
62
|
+
* Validate the whole form and populate any errors.
|
63
|
+
*/
|
64
|
+
validate: () => Promise<void>;
|
65
|
+
/**
|
66
|
+
* Clears all errors on the form.
|
67
|
+
*/
|
68
|
+
clearAllErrors: () => void;
|
69
|
+
/**
|
70
|
+
* Resets the form.
|
71
|
+
*
|
72
|
+
* _Note_: The equivalent behavior can be achieved by calling formElement.reset()
|
73
|
+
* or clicking a button element with `type="reset"`.
|
74
|
+
*/
|
75
|
+
reset: () => void;
|
59
76
|
};
|
60
77
|
|
61
78
|
/**
|
@@ -69,11 +86,12 @@ export const useFormContext = (formId?: string): FormContextValue => {
|
|
69
86
|
clearError: internalClearError,
|
70
87
|
setTouched,
|
71
88
|
validateField,
|
89
|
+
clearAllErrors,
|
90
|
+
validate,
|
91
|
+
reset,
|
72
92
|
} = useFormHelpers(formId);
|
73
93
|
|
74
|
-
const
|
75
|
-
formPropsAtom(context.formId)
|
76
|
-
);
|
94
|
+
const registerReceiveFocus = useRegisterReceiveFocus(context.formId);
|
77
95
|
|
78
96
|
const clearError = useCallback(
|
79
97
|
(...names: string[]) => {
|
@@ -90,5 +108,8 @@ export const useFormContext = (formId?: string): FormContextValue => {
|
|
90
108
|
validateField,
|
91
109
|
clearError,
|
92
110
|
registerReceiveFocus,
|
111
|
+
clearAllErrors,
|
112
|
+
validate,
|
113
|
+
reset,
|
93
114
|
};
|
94
115
|
};
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { InternalFormId } from "./state/atomUtils";
|
2
|
-
export declare const resetAtom: {
|
3
|
-
(param: InternalFormId): import("jotai").Atom<null> & {
|
4
|
-
write: (get: {
|
5
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
6
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
7
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
8
|
-
} & {
|
9
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
10
|
-
unstable_promise: true;
|
11
|
-
}): Value_3 | Promise<Value_3>;
|
12
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
13
|
-
unstable_promise: true;
|
14
|
-
}): Value_4 | Promise<Value_4>;
|
15
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
16
|
-
unstable_promise: true;
|
17
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
18
|
-
}, set: {
|
19
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
20
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
21
|
-
}, update: unknown) => void;
|
22
|
-
onMount?: (<S extends (update?: unknown) => void>(setAtom: S) => void | (() => void)) | undefined;
|
23
|
-
} & {
|
24
|
-
init: null;
|
25
|
-
};
|
26
|
-
remove(param: InternalFormId): void;
|
27
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
28
|
-
};
|
@@ -1,38 +0,0 @@
|
|
1
|
-
import { Atom } from "jotai";
|
2
|
-
export declare type InternalFormId = string | symbol;
|
3
|
-
export declare const formAtomFamily: <T>(data: T) => {
|
4
|
-
(param: InternalFormId): Atom<T> & {
|
5
|
-
write: (get: {
|
6
|
-
<Value>(atom: Atom<Value | Promise<Value>>): Value;
|
7
|
-
<Value_1>(atom: Atom<Promise<Value_1>>): Value_1;
|
8
|
-
<Value_2>(atom: Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
9
|
-
} & {
|
10
|
-
<Value_3>(atom: Atom<Value_3 | Promise<Value_3>>, options: {
|
11
|
-
unstable_promise: true;
|
12
|
-
}): Value_3 | Promise<Value_3>;
|
13
|
-
<Value_4>(atom: Atom<Promise<Value_4>>, options: {
|
14
|
-
unstable_promise: true;
|
15
|
-
}): Value_4 | Promise<Value_4>;
|
16
|
-
<Value_5>(atom: Atom<Value_5>, options: {
|
17
|
-
unstable_promise: true;
|
18
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
19
|
-
}, set: {
|
20
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
21
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
22
|
-
}, update: T | ((prev: T) => T)) => void;
|
23
|
-
onMount?: (<S extends import("jotai/core/atom").SetAtom<T | ((prev: T) => T), void>>(setAtom: S) => void | (() => void)) | undefined;
|
24
|
-
} & {
|
25
|
-
init: T;
|
26
|
-
};
|
27
|
-
remove(param: InternalFormId): void;
|
28
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
29
|
-
};
|
30
|
-
export declare type FieldAtomKey = {
|
31
|
-
formId: InternalFormId;
|
32
|
-
field: string;
|
33
|
-
};
|
34
|
-
export declare const fieldAtomFamily: <T extends Atom<unknown>>(func: (key: FieldAtomKey) => T) => {
|
35
|
-
(param: FieldAtomKey): T;
|
36
|
-
remove(param: FieldAtomKey): void;
|
37
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: FieldAtomKey) => boolean) | null): void;
|
38
|
-
};
|
@@ -1,343 +0,0 @@
|
|
1
|
-
import { FieldErrors, TouchedFields } from "../validation/types";
|
2
|
-
import { InternalFormId } from "./state/atomUtils";
|
3
|
-
export declare const ATOM_SCOPE: unique symbol;
|
4
|
-
export declare type SyncedFormProps = {
|
5
|
-
formId?: string;
|
6
|
-
action?: string;
|
7
|
-
subaction?: string;
|
8
|
-
defaultValues: {
|
9
|
-
[fieldName: string]: any;
|
10
|
-
};
|
11
|
-
validateField: (fieldName: string) => Promise<string | null>;
|
12
|
-
registerReceiveFocus: (fieldName: string, handler: () => void) => () => void;
|
13
|
-
};
|
14
|
-
export declare const isHydratedAtom: {
|
15
|
-
(param: InternalFormId): import("jotai").Atom<boolean> & {
|
16
|
-
write: (get: {
|
17
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
18
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
19
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
20
|
-
} & {
|
21
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
22
|
-
unstable_promise: true;
|
23
|
-
}): Value_3 | Promise<Value_3>;
|
24
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
25
|
-
unstable_promise: true;
|
26
|
-
}): Value_4 | Promise<Value_4>;
|
27
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
28
|
-
unstable_promise: true;
|
29
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
30
|
-
}, set: {
|
31
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
32
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
33
|
-
}, update: boolean | ((prev: boolean) => boolean)) => void;
|
34
|
-
onMount?: (<S extends (update: boolean | ((prev: boolean) => boolean)) => void>(setAtom: S) => void | (() => void)) | undefined;
|
35
|
-
} & {
|
36
|
-
init: boolean;
|
37
|
-
};
|
38
|
-
remove(param: InternalFormId): void;
|
39
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
40
|
-
};
|
41
|
-
export declare const isSubmittingAtom: {
|
42
|
-
(param: InternalFormId): import("jotai").Atom<boolean> & {
|
43
|
-
write: (get: {
|
44
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
45
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
46
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
47
|
-
} & {
|
48
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
49
|
-
unstable_promise: true;
|
50
|
-
}): Value_3 | Promise<Value_3>;
|
51
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
52
|
-
unstable_promise: true;
|
53
|
-
}): Value_4 | Promise<Value_4>;
|
54
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
55
|
-
unstable_promise: true;
|
56
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
57
|
-
}, set: {
|
58
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
59
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
60
|
-
}, update: boolean | ((prev: boolean) => boolean)) => void;
|
61
|
-
onMount?: (<S extends (update: boolean | ((prev: boolean) => boolean)) => void>(setAtom: S) => void | (() => void)) | undefined;
|
62
|
-
} & {
|
63
|
-
init: boolean;
|
64
|
-
};
|
65
|
-
remove(param: InternalFormId): void;
|
66
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
67
|
-
};
|
68
|
-
export declare const hasBeenSubmittedAtom: {
|
69
|
-
(param: InternalFormId): import("jotai").Atom<boolean> & {
|
70
|
-
write: (get: {
|
71
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
72
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
73
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
74
|
-
} & {
|
75
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
76
|
-
unstable_promise: true;
|
77
|
-
}): Value_3 | Promise<Value_3>;
|
78
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
79
|
-
unstable_promise: true;
|
80
|
-
}): Value_4 | Promise<Value_4>;
|
81
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
82
|
-
unstable_promise: true;
|
83
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
84
|
-
}, set: {
|
85
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
86
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
87
|
-
}, update: boolean | ((prev: boolean) => boolean)) => void;
|
88
|
-
onMount?: (<S extends (update: boolean | ((prev: boolean) => boolean)) => void>(setAtom: S) => void | (() => void)) | undefined;
|
89
|
-
} & {
|
90
|
-
init: boolean;
|
91
|
-
};
|
92
|
-
remove(param: InternalFormId): void;
|
93
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
94
|
-
};
|
95
|
-
export declare const fieldErrorsAtom: {
|
96
|
-
(param: InternalFormId): import("jotai").Atom<FieldErrors> & {
|
97
|
-
write: (get: {
|
98
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
99
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
100
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
101
|
-
} & {
|
102
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
103
|
-
unstable_promise: true;
|
104
|
-
}): Value_3 | Promise<Value_3>;
|
105
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
106
|
-
unstable_promise: true;
|
107
|
-
}): Value_4 | Promise<Value_4>;
|
108
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
109
|
-
unstable_promise: true;
|
110
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
111
|
-
}, set: {
|
112
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
113
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
114
|
-
}, update: FieldErrors | ((prev: FieldErrors) => FieldErrors)) => void;
|
115
|
-
onMount?: (<S extends (update: FieldErrors | ((prev: FieldErrors) => FieldErrors)) => void>(setAtom: S) => void | (() => void)) | undefined;
|
116
|
-
} & {
|
117
|
-
init: FieldErrors;
|
118
|
-
};
|
119
|
-
remove(param: InternalFormId): void;
|
120
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
121
|
-
};
|
122
|
-
export declare const touchedFieldsAtom: {
|
123
|
-
(param: InternalFormId): import("jotai").Atom<TouchedFields> & {
|
124
|
-
write: (get: {
|
125
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
126
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
127
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
128
|
-
} & {
|
129
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
130
|
-
unstable_promise: true;
|
131
|
-
}): Value_3 | Promise<Value_3>;
|
132
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
133
|
-
unstable_promise: true;
|
134
|
-
}): Value_4 | Promise<Value_4>;
|
135
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
136
|
-
unstable_promise: true;
|
137
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
138
|
-
}, set: {
|
139
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
140
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
141
|
-
}, update: TouchedFields | ((prev: TouchedFields) => TouchedFields)) => void;
|
142
|
-
onMount?: (<S extends (update: TouchedFields | ((prev: TouchedFields) => TouchedFields)) => void>(setAtom: S) => void | (() => void)) | undefined;
|
143
|
-
} & {
|
144
|
-
init: TouchedFields;
|
145
|
-
};
|
146
|
-
remove(param: InternalFormId): void;
|
147
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
148
|
-
};
|
149
|
-
export declare const formPropsAtom: {
|
150
|
-
(param: InternalFormId): import("jotai").Atom<SyncedFormProps> & {
|
151
|
-
write: (get: {
|
152
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
153
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
154
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
155
|
-
} & {
|
156
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
157
|
-
unstable_promise: true;
|
158
|
-
}): Value_3 | Promise<Value_3>;
|
159
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
160
|
-
unstable_promise: true;
|
161
|
-
}): Value_4 | Promise<Value_4>;
|
162
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
163
|
-
unstable_promise: true;
|
164
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
165
|
-
}, set: {
|
166
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
167
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
168
|
-
}, update: SyncedFormProps | ((prev: SyncedFormProps) => SyncedFormProps)) => void;
|
169
|
-
onMount?: (<S extends (update: SyncedFormProps | ((prev: SyncedFormProps) => SyncedFormProps)) => void>(setAtom: S) => void | (() => void)) | undefined;
|
170
|
-
} & {
|
171
|
-
init: SyncedFormProps;
|
172
|
-
};
|
173
|
-
remove(param: InternalFormId): void;
|
174
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
175
|
-
};
|
176
|
-
export declare const formElementAtom: {
|
177
|
-
(param: InternalFormId): import("jotai").Atom<HTMLFormElement | null> & {
|
178
|
-
write: (get: {
|
179
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
180
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
181
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
182
|
-
} & {
|
183
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
184
|
-
unstable_promise: true;
|
185
|
-
}): Value_3 | Promise<Value_3>;
|
186
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
187
|
-
unstable_promise: true;
|
188
|
-
}): Value_4 | Promise<Value_4>;
|
189
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
190
|
-
unstable_promise: true;
|
191
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
192
|
-
}, set: {
|
193
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
194
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
195
|
-
}, update: HTMLFormElement | ((prev: HTMLFormElement | null) => HTMLFormElement | null) | null) => void;
|
196
|
-
onMount?: (<S extends (update: HTMLFormElement | ((prev: HTMLFormElement | null) => HTMLFormElement | null) | null) => void>(setAtom: S) => void | (() => void)) | undefined;
|
197
|
-
} & {
|
198
|
-
init: HTMLFormElement | null;
|
199
|
-
};
|
200
|
-
remove(param: InternalFormId): void;
|
201
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
202
|
-
};
|
203
|
-
export declare const cleanupFormState: (formId: InternalFormId) => void;
|
204
|
-
export declare const isValidAtom: {
|
205
|
-
(param: InternalFormId): import("jotai").Atom<boolean>;
|
206
|
-
remove(param: InternalFormId): void;
|
207
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
208
|
-
};
|
209
|
-
export declare const startSubmitAtom: {
|
210
|
-
(param: InternalFormId): import("jotai").Atom<null> & {
|
211
|
-
write: (get: {
|
212
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
213
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
214
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
215
|
-
} & {
|
216
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
217
|
-
unstable_promise: true;
|
218
|
-
}): Value_3 | Promise<Value_3>;
|
219
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
220
|
-
unstable_promise: true;
|
221
|
-
}): Value_4 | Promise<Value_4>;
|
222
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
223
|
-
unstable_promise: true;
|
224
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
225
|
-
}, set: {
|
226
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
227
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
228
|
-
}, update: unknown) => void;
|
229
|
-
onMount?: (<S extends (update?: unknown) => void>(setAtom: S) => void | (() => void)) | undefined;
|
230
|
-
} & {
|
231
|
-
init: null;
|
232
|
-
};
|
233
|
-
remove(param: InternalFormId): void;
|
234
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
235
|
-
};
|
236
|
-
export declare const endSubmitAtom: {
|
237
|
-
(param: InternalFormId): import("jotai").Atom<null> & {
|
238
|
-
write: (get: {
|
239
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
240
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
241
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
242
|
-
} & {
|
243
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
244
|
-
unstable_promise: true;
|
245
|
-
}): Value_3 | Promise<Value_3>;
|
246
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
247
|
-
unstable_promise: true;
|
248
|
-
}): Value_4 | Promise<Value_4>;
|
249
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
250
|
-
unstable_promise: true;
|
251
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
252
|
-
}, set: {
|
253
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
254
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
255
|
-
}, update: unknown) => void;
|
256
|
-
onMount?: (<S extends (update?: unknown) => void>(setAtom: S) => void | (() => void)) | undefined;
|
257
|
-
} & {
|
258
|
-
init: null;
|
259
|
-
};
|
260
|
-
remove(param: InternalFormId): void;
|
261
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
262
|
-
};
|
263
|
-
export declare const setTouchedAtom: {
|
264
|
-
(param: InternalFormId): import("jotai").Atom<null> & {
|
265
|
-
write: (get: {
|
266
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
267
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
268
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
269
|
-
} & {
|
270
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
271
|
-
unstable_promise: true;
|
272
|
-
}): Value_3 | Promise<Value_3>;
|
273
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
274
|
-
unstable_promise: true;
|
275
|
-
}): Value_4 | Promise<Value_4>;
|
276
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
277
|
-
unstable_promise: true;
|
278
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
279
|
-
}, set: {
|
280
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
281
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
282
|
-
}, update: {
|
283
|
-
field: string;
|
284
|
-
touched: boolean;
|
285
|
-
}) => void;
|
286
|
-
onMount?: (<S extends (update: {
|
287
|
-
field: string;
|
288
|
-
touched: boolean;
|
289
|
-
}) => void>(setAtom: S) => void | (() => void)) | undefined;
|
290
|
-
} & {
|
291
|
-
init: null;
|
292
|
-
};
|
293
|
-
remove(param: InternalFormId): void;
|
294
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
295
|
-
};
|
296
|
-
export declare const setFieldErrorAtom: {
|
297
|
-
(param: InternalFormId): import("jotai").Atom<null> & {
|
298
|
-
write: (get: {
|
299
|
-
<Value>(atom: import("jotai").Atom<Value | Promise<Value>>): Value;
|
300
|
-
<Value_1>(atom: import("jotai").Atom<Promise<Value_1>>): Value_1;
|
301
|
-
<Value_2>(atom: import("jotai").Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
302
|
-
} & {
|
303
|
-
<Value_3>(atom: import("jotai").Atom<Value_3 | Promise<Value_3>>, options: {
|
304
|
-
unstable_promise: true;
|
305
|
-
}): Value_3 | Promise<Value_3>;
|
306
|
-
<Value_4>(atom: import("jotai").Atom<Promise<Value_4>>, options: {
|
307
|
-
unstable_promise: true;
|
308
|
-
}): Value_4 | Promise<Value_4>;
|
309
|
-
<Value_5>(atom: import("jotai").Atom<Value_5>, options: {
|
310
|
-
unstable_promise: true;
|
311
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
312
|
-
}, set: {
|
313
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
314
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
315
|
-
}, update: {
|
316
|
-
field: string;
|
317
|
-
error: string | undefined;
|
318
|
-
}) => void;
|
319
|
-
onMount?: (<S extends (update: {
|
320
|
-
field: string;
|
321
|
-
error: string | undefined;
|
322
|
-
}) => void>(setAtom: S) => void | (() => void)) | undefined;
|
323
|
-
} & {
|
324
|
-
init: null;
|
325
|
-
};
|
326
|
-
remove(param: InternalFormId): void;
|
327
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
328
|
-
};
|
329
|
-
export declare const fieldTouchedAtom: {
|
330
|
-
(param: import("./state/atomUtils").FieldAtomKey): import("jotai").WritableAtom<boolean, boolean, void>;
|
331
|
-
remove(param: import("./state/atomUtils").FieldAtomKey): void;
|
332
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: import("./state/atomUtils").FieldAtomKey) => boolean) | null): void;
|
333
|
-
};
|
334
|
-
export declare const fieldErrorAtom: {
|
335
|
-
(param: import("./state/atomUtils").FieldAtomKey): import("jotai").WritableAtom<string, string | undefined, void>;
|
336
|
-
remove(param: import("./state/atomUtils").FieldAtomKey): void;
|
337
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: import("./state/atomUtils").FieldAtomKey) => boolean) | null): void;
|
338
|
-
};
|
339
|
-
export declare const fieldDefaultValueAtom: {
|
340
|
-
(param: import("./state/atomUtils").FieldAtomKey): import("jotai").Atom<any>;
|
341
|
-
remove(param: import("./state/atomUtils").FieldAtomKey): void;
|
342
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: import("./state/atomUtils").FieldAtomKey) => boolean) | null): void;
|
343
|
-
};
|
package/src/internal/reset.ts
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
import { atom } from "jotai";
|
2
|
-
import { atomFamily } from "jotai/utils";
|
3
|
-
import lodashGet from "lodash/get";
|
4
|
-
import {
|
5
|
-
fieldErrorsAtom,
|
6
|
-
formPropsAtom,
|
7
|
-
hasBeenSubmittedAtom,
|
8
|
-
touchedFieldsAtom,
|
9
|
-
} from "./state";
|
10
|
-
import { InternalFormId } from "./state/atomUtils";
|
11
|
-
import { controlledFieldsAtom } from "./state/controlledFields";
|
12
|
-
|
13
|
-
export const resetAtom = atomFamily((formId: InternalFormId) =>
|
14
|
-
atom(null, (get, set) => {
|
15
|
-
set(fieldErrorsAtom(formId), {});
|
16
|
-
set(touchedFieldsAtom(formId), {});
|
17
|
-
set(hasBeenSubmittedAtom(formId), false);
|
18
|
-
|
19
|
-
const { defaultValues } = get(formPropsAtom(formId));
|
20
|
-
|
21
|
-
const controlledFields = get(controlledFieldsAtom(formId));
|
22
|
-
Object.entries(controlledFields).forEach(([name, atom]) =>
|
23
|
-
set(atom, lodashGet(defaultValues, name))
|
24
|
-
);
|
25
|
-
})
|
26
|
-
);
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { Atom, atom } from "jotai";
|
2
|
-
import { atomFamily } from "jotai/utils";
|
3
|
-
import isEqual from "lodash/isEqual";
|
4
|
-
|
5
|
-
export type InternalFormId = string | symbol;
|
6
|
-
|
7
|
-
export const formAtomFamily = <T>(data: T) =>
|
8
|
-
atomFamily((_: InternalFormId) => atom(data));
|
9
|
-
|
10
|
-
export type FieldAtomKey = { formId: InternalFormId; field: string };
|
11
|
-
export const fieldAtomFamily = <T extends Atom<unknown>>(
|
12
|
-
func: (key: FieldAtomKey) => T
|
13
|
-
) => atomFamily(func, isEqual);
|