react-f0rm 0.2.2 → 0.3.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/README.md +527 -33
- package/dist/devtools/index.cjs.js +737 -0
- package/dist/devtools/index.cjs.js.map +1 -0
- package/dist/devtools/index.d.ts +33 -0
- package/dist/devtools/index.mjs +717 -0
- package/dist/devtools/index.mjs.map +1 -0
- package/dist/form-61297bc0.d.ts +578 -0
- package/dist/form-94c70b4b.mjs +378 -0
- package/dist/form-94c70b4b.mjs.map +1 -0
- package/dist/form-b9441d8c.cjs.js +387 -0
- package/dist/form-b9441d8c.cjs.js.map +1 -0
- package/dist/index.cjs.js +1257 -157
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +357 -53
- package/dist/index.mjs +1676 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +1257 -157
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -2
- package/dist/index.umd.min.js.map +1 -1
- package/dist/resolvers/standard-schema.cjs.js +90 -0
- package/dist/resolvers/standard-schema.cjs.js.map +1 -0
- package/dist/resolvers/standard-schema.d.ts +66 -0
- package/dist/resolvers/standard-schema.mjs +86 -0
- package/dist/resolvers/standard-schema.mjs.map +1 -0
- package/dist/resolvers/yup.cjs.js +12 -2
- package/dist/resolvers/yup.cjs.js.map +1 -1
- package/dist/resolvers/yup.d.ts +2 -2
- package/dist/resolvers/yup.mjs +23 -0
- package/dist/resolvers/yup.mjs.map +1 -0
- package/dist/resolvers/zod.cjs.js +14 -1
- package/dist/resolvers/zod.cjs.js.map +1 -1
- package/dist/resolvers/zod.d.ts +2 -2
- package/dist/resolvers/zod.mjs +23 -0
- package/dist/resolvers/zod.mjs.map +1 -0
- package/dist/validate-148fe167.d.ts +22 -0
- package/package.json +34 -8
- package/dist/form-d06e6444.d.ts +0 -201
- package/dist/index.esm.js +0 -593
- package/dist/index.esm.js.map +0 -1
- package/dist/resolvers/yup.esm.js +0 -13
- package/dist/resolvers/yup.esm.js.map +0 -1
- package/dist/resolvers/zod.esm.js +0 -10
- package/dist/resolvers/zod.esm.js.map +0 -1
- package/dist/validate-0f17f86a.d.ts +0 -8
package/dist/form-d06e6444.d.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from '@for-fun/event-emitter';
|
|
2
|
-
|
|
3
|
-
type PathValue$1 = (string | number)[];
|
|
4
|
-
type Name$1 = string | PathValue$1;
|
|
5
|
-
type Path = {
|
|
6
|
-
value: PathValue$1;
|
|
7
|
-
key: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type PathValue = (string | number)[];
|
|
11
|
-
type Name = string | PathValue;
|
|
12
|
-
interface Form<T extends Record<string, any> = any> {
|
|
13
|
-
emitter: EventEmitter;
|
|
14
|
-
revalidateOnChange: boolean;
|
|
15
|
-
initialValues: T;
|
|
16
|
-
values: Map<string, any>;
|
|
17
|
-
errors: Map<string, string>;
|
|
18
|
-
touched: Set<string>;
|
|
19
|
-
validators: Map<string, () => void>;
|
|
20
|
-
validating: Set<string>;
|
|
21
|
-
validate?: (values: T) => Record<string, string> | Promise<Record<string, string>>;
|
|
22
|
-
isSubmitting: boolean;
|
|
23
|
-
submitCount: number;
|
|
24
|
-
isSubmitSuccessful: boolean | undefined;
|
|
25
|
-
}
|
|
26
|
-
type Options<T extends Record<string, any> = any> = {
|
|
27
|
-
initialValues?: T;
|
|
28
|
-
validateOnSubmit?: boolean;
|
|
29
|
-
validateOnChange?: boolean;
|
|
30
|
-
validateOnBlur?: boolean;
|
|
31
|
-
revalidateOnChange?: boolean;
|
|
32
|
-
revalidateOnBlur?: boolean;
|
|
33
|
-
validate?: (values: T) => Record<string, string> | Promise<Record<string, string>>;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Create form instance
|
|
37
|
-
* @param options
|
|
38
|
-
* @return form instance
|
|
39
|
-
*/
|
|
40
|
-
declare function create<T extends Record<string, any> = any>(options?: Options<T>): Form<T>;
|
|
41
|
-
/**
|
|
42
|
-
* Get form values
|
|
43
|
-
* @param form
|
|
44
|
-
*/
|
|
45
|
-
declare function getValues(form: Form): any;
|
|
46
|
-
/**
|
|
47
|
-
* Get field value
|
|
48
|
-
* @param form
|
|
49
|
-
* @param name
|
|
50
|
-
*/
|
|
51
|
-
declare function getValue(form: Form, name: Name): any;
|
|
52
|
-
/**
|
|
53
|
-
* Get field value by path
|
|
54
|
-
* @param form
|
|
55
|
-
* @param path
|
|
56
|
-
*/
|
|
57
|
-
declare function getValueByPath({ initialValues, values }: Form, path: Path): any;
|
|
58
|
-
/**
|
|
59
|
-
* Set field value
|
|
60
|
-
* @param form
|
|
61
|
-
* @param name
|
|
62
|
-
* @param value
|
|
63
|
-
*/
|
|
64
|
-
declare function setValue(form: Form, name: Name, value: any): void;
|
|
65
|
-
/**
|
|
66
|
-
* Set field value
|
|
67
|
-
* @param form
|
|
68
|
-
* @param path
|
|
69
|
-
* @param value
|
|
70
|
-
*/
|
|
71
|
-
declare function setValueByPath({ emitter, values }: Form, path: Path, value: any): void;
|
|
72
|
-
/**
|
|
73
|
-
* Get field error
|
|
74
|
-
* @param form
|
|
75
|
-
* @param name
|
|
76
|
-
*/
|
|
77
|
-
declare function getError(form: Form, name: Name): string | undefined;
|
|
78
|
-
/**
|
|
79
|
-
* Get field error by path
|
|
80
|
-
* @param form
|
|
81
|
-
* @param path
|
|
82
|
-
*/
|
|
83
|
-
declare function getErrorByPath({ errors }: Form, path: Path): string | undefined;
|
|
84
|
-
/**
|
|
85
|
-
* Get all errors
|
|
86
|
-
* @param form
|
|
87
|
-
* @return array of error strings
|
|
88
|
-
*/
|
|
89
|
-
declare function getErrors({ errors }: Form): string[];
|
|
90
|
-
/**
|
|
91
|
-
* Get first error string
|
|
92
|
-
* @param form
|
|
93
|
-
* @return first error string or undefined
|
|
94
|
-
*/
|
|
95
|
-
declare function getFirstError({ errors }: Form): string | undefined;
|
|
96
|
-
declare function unsetValidatingByPath({ emitter, validating }: Form, { key }: Path): void;
|
|
97
|
-
declare function setValidatingByPath({ emitter, validating }: Form, { key }: Path): void;
|
|
98
|
-
/**
|
|
99
|
-
* Set field error
|
|
100
|
-
* @param form
|
|
101
|
-
* @param name
|
|
102
|
-
* @param error
|
|
103
|
-
*/
|
|
104
|
-
declare function setError(form: Form, name: Name, error: string | undefined): void;
|
|
105
|
-
/**
|
|
106
|
-
* Set field error
|
|
107
|
-
* @param form
|
|
108
|
-
* @param path
|
|
109
|
-
* @param error
|
|
110
|
-
*/
|
|
111
|
-
declare function setErrorByPath({ emitter, errors }: Form, path: Path, error: string | undefined): void;
|
|
112
|
-
/**
|
|
113
|
-
* Clear errors
|
|
114
|
-
* @param form
|
|
115
|
-
*/
|
|
116
|
-
declare function clearErrors({ emitter, errors }: Form): void;
|
|
117
|
-
/**
|
|
118
|
-
* Set field touched state
|
|
119
|
-
* @param form
|
|
120
|
-
* @param name
|
|
121
|
-
*/
|
|
122
|
-
declare function setTouched(form: Form, name: Name): void;
|
|
123
|
-
/**
|
|
124
|
-
* Set field touched state
|
|
125
|
-
* @param form
|
|
126
|
-
* @param path
|
|
127
|
-
*/
|
|
128
|
-
declare function setTouchedByPath({ emitter, touched }: Form, { key }: Path): void;
|
|
129
|
-
/**
|
|
130
|
-
* Check if field has been touched
|
|
131
|
-
* @param form
|
|
132
|
-
* @param name
|
|
133
|
-
*/
|
|
134
|
-
declare function hasTouched(form: Form, name: Name): boolean;
|
|
135
|
-
/**
|
|
136
|
-
* Check if field has been touched
|
|
137
|
-
* @param form
|
|
138
|
-
* @param path
|
|
139
|
-
*/
|
|
140
|
-
declare function hasTouchedByPath({ touched }: Form, path: Path): boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Is dirty -- any value differs from initialValues
|
|
143
|
-
* @param form
|
|
144
|
-
*/
|
|
145
|
-
declare function isDirty({ initialValues, values }: Form): boolean;
|
|
146
|
-
/**
|
|
147
|
-
* Is touched -- any field has been touched
|
|
148
|
-
* @param form
|
|
149
|
-
*/
|
|
150
|
-
declare function isTouched({ touched }: Form): boolean;
|
|
151
|
-
/**
|
|
152
|
-
* Remove field
|
|
153
|
-
* @param form
|
|
154
|
-
* @param name
|
|
155
|
-
*/
|
|
156
|
-
declare function removeField(form: Form, name: Name): void;
|
|
157
|
-
/**
|
|
158
|
-
* Remove field
|
|
159
|
-
* @param form
|
|
160
|
-
* @param path
|
|
161
|
-
*/
|
|
162
|
-
declare function removeFieldByPath(form: Form, { key }: Path): void;
|
|
163
|
-
/**
|
|
164
|
-
* Set form initialValues
|
|
165
|
-
* @param form
|
|
166
|
-
* @param initialValues
|
|
167
|
-
*/
|
|
168
|
-
declare function setInitialValues(form: Form, initialValues: any): void;
|
|
169
|
-
/**
|
|
170
|
-
* Reset form
|
|
171
|
-
* @param form
|
|
172
|
-
* @param initialValues
|
|
173
|
-
*/
|
|
174
|
-
declare function reset(form: Form, initialValues?: any): void;
|
|
175
|
-
/**
|
|
176
|
-
* @param form
|
|
177
|
-
*/
|
|
178
|
-
declare function hasErrors({ errors }: Form): boolean;
|
|
179
|
-
/**
|
|
180
|
-
* Trigger all fields validate.
|
|
181
|
-
* @param form
|
|
182
|
-
*/
|
|
183
|
-
declare function trigger(form: Form): void;
|
|
184
|
-
/**
|
|
185
|
-
* Validate and throw if any field error.
|
|
186
|
-
* @param form
|
|
187
|
-
* @return resolve if no error; reject and stop validate if has an error
|
|
188
|
-
*/
|
|
189
|
-
declare function ensureValidate(form: Form): Promise<void>;
|
|
190
|
-
/**
|
|
191
|
-
* Validate and return if any field error.
|
|
192
|
-
* @param form
|
|
193
|
-
* @return error message string or void
|
|
194
|
-
*/
|
|
195
|
-
declare function validate(form: Form): Promise<void | string>;
|
|
196
|
-
declare function setIsSubmitting(form: Form, value: boolean): void;
|
|
197
|
-
declare function incrementSubmitCount(form: Form): void;
|
|
198
|
-
declare function setSubmitSuccessful(form: Form, value: boolean): void;
|
|
199
|
-
|
|
200
|
-
export { reset as A, hasErrors as B, trigger as C, ensureValidate as D, validate as E, setIsSubmitting as G, incrementSubmitCount as H, setSubmitSuccessful as I, create as c, getValue as d, getValueByPath as e, setValueByPath as f, getValues as g, getError as h, getErrorByPath as i, getErrors as j, getFirstError as k, setValidatingByPath as l, setError as m, setErrorByPath as n, clearErrors as o, setTouched as p, setTouchedByPath as q, hasTouched as r, setValue as s, hasTouchedByPath as t, unsetValidatingByPath as u, isDirty as v, isTouched as w, removeField as x, removeFieldByPath as y, setInitialValues as z };
|
|
201
|
-
export type { Form as F, Name as N, Options as O, Path as P, Name$1 as a, PathValue as b };
|