@formisch/react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +82 -0
- package/dist/index.d.ts +1073 -0
- package/dist/index.js +1039 -0
- package/package.json +72 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1073 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { ChangeEventHandler, FocusEventHandler, FormHTMLAttributes, ReactElement } from "react";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/core/dist/index.vanilla.d.ts
|
|
5
|
+
|
|
6
|
+
//#region src/types/schema.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Schema type.
|
|
9
|
+
*/
|
|
10
|
+
type Schema = v.GenericSchema | v.GenericSchemaAsync;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types/signal.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* Signal interface.
|
|
15
|
+
*/
|
|
16
|
+
interface Signal<T> {
|
|
17
|
+
/**
|
|
18
|
+
* The value of the signal.
|
|
19
|
+
*/
|
|
20
|
+
value: T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Batch interface.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/types/field.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* Field element type.
|
|
30
|
+
*/
|
|
31
|
+
type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
32
|
+
/**
|
|
33
|
+
* Internal base store interface.
|
|
34
|
+
*/
|
|
35
|
+
interface InternalBaseStore {
|
|
36
|
+
/**
|
|
37
|
+
* The kind of field store.
|
|
38
|
+
*/
|
|
39
|
+
kind: "array" | "object" | "value";
|
|
40
|
+
/**
|
|
41
|
+
* The name of the field.
|
|
42
|
+
*/
|
|
43
|
+
name: string;
|
|
44
|
+
/**
|
|
45
|
+
* The schema of the field.
|
|
46
|
+
*/
|
|
47
|
+
schema: Schema;
|
|
48
|
+
/**
|
|
49
|
+
* The initial elements of the field.
|
|
50
|
+
*/
|
|
51
|
+
initialElements: FieldElement[];
|
|
52
|
+
/**
|
|
53
|
+
* The elements of the field.
|
|
54
|
+
*/
|
|
55
|
+
elements: FieldElement[];
|
|
56
|
+
/**
|
|
57
|
+
* The errors of the field.
|
|
58
|
+
*/
|
|
59
|
+
errors: Signal<[string, ...string[]] | null>;
|
|
60
|
+
/**
|
|
61
|
+
* The touched state of the field.
|
|
62
|
+
*/
|
|
63
|
+
isTouched: Signal<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* The dirty state of the field.
|
|
66
|
+
*/
|
|
67
|
+
isDirty: Signal<boolean>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Internal array store interface.
|
|
71
|
+
*/
|
|
72
|
+
interface InternalArrayStore extends InternalBaseStore {
|
|
73
|
+
/**
|
|
74
|
+
* The kind of field store.
|
|
75
|
+
*/
|
|
76
|
+
kind: "array";
|
|
77
|
+
/**
|
|
78
|
+
* The children of the array field.
|
|
79
|
+
*/
|
|
80
|
+
children: InternalFieldStore[];
|
|
81
|
+
/**
|
|
82
|
+
* The initial input of the array field.
|
|
83
|
+
*
|
|
84
|
+
* Hint: The initial input is used for resetting and may only be changed
|
|
85
|
+
* during this process. It does not move when a field is moved.
|
|
86
|
+
*/
|
|
87
|
+
initialInput: Signal<true | null | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* The start input of the array field.
|
|
90
|
+
*
|
|
91
|
+
* Hint: The start input is used to determine whether the field is dirty
|
|
92
|
+
* and moves with it.
|
|
93
|
+
*/
|
|
94
|
+
startInput: Signal<true | null | undefined>;
|
|
95
|
+
/**
|
|
96
|
+
* The input of the array field.
|
|
97
|
+
*
|
|
98
|
+
* Hint: The input indicates whether it is `null`, `undefined`, or found in
|
|
99
|
+
* the children.
|
|
100
|
+
*/
|
|
101
|
+
input: Signal<true | null | undefined>;
|
|
102
|
+
/**
|
|
103
|
+
* The initial items of the array field.
|
|
104
|
+
*
|
|
105
|
+
* Hint: The initial items are used for resetting and may only be changed
|
|
106
|
+
* during this process. It does not move when a field is moved.
|
|
107
|
+
*/
|
|
108
|
+
initialItems: Signal<string[]>;
|
|
109
|
+
/**
|
|
110
|
+
* The start items of the array field.
|
|
111
|
+
*
|
|
112
|
+
* Hint: The start items are used to determine whether the field is dirty
|
|
113
|
+
* and moves with it.
|
|
114
|
+
*/
|
|
115
|
+
startItems: Signal<string[]>;
|
|
116
|
+
/**
|
|
117
|
+
* The items of the array field.
|
|
118
|
+
*/
|
|
119
|
+
items: Signal<string[]>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Internal object store interface.
|
|
123
|
+
*/
|
|
124
|
+
interface InternalObjectStore extends InternalBaseStore {
|
|
125
|
+
/**
|
|
126
|
+
* The kind of field store.
|
|
127
|
+
*/
|
|
128
|
+
kind: "object";
|
|
129
|
+
/**
|
|
130
|
+
* The children of the object field.
|
|
131
|
+
*/
|
|
132
|
+
children: Record<string, InternalFieldStore>;
|
|
133
|
+
/**
|
|
134
|
+
* The initial input of the object field.
|
|
135
|
+
*
|
|
136
|
+
* Hint: The initial input is used for resetting and may only be changed
|
|
137
|
+
* during this process. It does not move when a field is moved.
|
|
138
|
+
*/
|
|
139
|
+
initialInput: Signal<true | null | undefined>;
|
|
140
|
+
/**
|
|
141
|
+
* The start input of the object field.
|
|
142
|
+
*
|
|
143
|
+
* Hint: The start input is used to determine whether the field is dirty
|
|
144
|
+
* and moves with it.
|
|
145
|
+
*/
|
|
146
|
+
startInput: Signal<true | null | undefined>;
|
|
147
|
+
/**
|
|
148
|
+
* The input of the object field.
|
|
149
|
+
*
|
|
150
|
+
* Hint: The input indicates whether it is `null`, `undefined`, or found in
|
|
151
|
+
* the children.
|
|
152
|
+
*/
|
|
153
|
+
input: Signal<true | null | undefined>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Internal value store interface.
|
|
157
|
+
*/
|
|
158
|
+
interface InternalValueStore extends InternalBaseStore {
|
|
159
|
+
/**
|
|
160
|
+
* The kind of field store.
|
|
161
|
+
*/
|
|
162
|
+
kind: "value";
|
|
163
|
+
/**
|
|
164
|
+
* The initial input of the value field.
|
|
165
|
+
*
|
|
166
|
+
* Hint: The initial input is used for resetting and may only be changed
|
|
167
|
+
* during this process. It does not move when a field is moved.
|
|
168
|
+
*/
|
|
169
|
+
initialInput: Signal<unknown>;
|
|
170
|
+
/**
|
|
171
|
+
* The start input of the value field.
|
|
172
|
+
*
|
|
173
|
+
* Hint: The start input is used to determine whether the field is dirty
|
|
174
|
+
* and moves with it.
|
|
175
|
+
*/
|
|
176
|
+
startInput: Signal<unknown>;
|
|
177
|
+
/**
|
|
178
|
+
* The input of the value field.
|
|
179
|
+
*/
|
|
180
|
+
input: Signal<unknown>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Internal field store type.
|
|
184
|
+
*/
|
|
185
|
+
type InternalFieldStore = InternalArrayStore | InternalObjectStore | InternalValueStore;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/values.d.ts
|
|
188
|
+
/**
|
|
189
|
+
* Internal symbol constant.
|
|
190
|
+
*/
|
|
191
|
+
declare const INTERNAL: "~internal";
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/types/utils.d.ts
|
|
194
|
+
/**
|
|
195
|
+
* Checks if a type is `any`.
|
|
196
|
+
*/
|
|
197
|
+
type IsAny<Type> = 0 extends 1 & Type ? true : false;
|
|
198
|
+
/**
|
|
199
|
+
* Checks if a type is `never`.
|
|
200
|
+
*/
|
|
201
|
+
type IsNever<Type> = [Type] extends [never] ? true : false;
|
|
202
|
+
/**
|
|
203
|
+
* Constructs a type that is maybe a promise.
|
|
204
|
+
*/
|
|
205
|
+
type MaybePromise<TValue> = TValue | Promise<TValue>;
|
|
206
|
+
/**
|
|
207
|
+
* Makes all properties deeply optional.
|
|
208
|
+
*/
|
|
209
|
+
type DeepPartial<TValue> = TValue extends readonly unknown[] ? number extends TValue["length"] ? TValue : { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue extends Record<PropertyKey, unknown> ? { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Makes all value properties optional.
|
|
212
|
+
*/
|
|
213
|
+
type PartialValues<TValue> = TValue extends readonly unknown[] ? number extends TValue["length"] ? TValue : { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue extends Record<PropertyKey, unknown> ? { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue | undefined;
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/types/form.d.ts
|
|
216
|
+
/**
|
|
217
|
+
* Validation mode type.
|
|
218
|
+
*/
|
|
219
|
+
type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submit";
|
|
220
|
+
/**
|
|
221
|
+
* Form config interface.
|
|
222
|
+
*/
|
|
223
|
+
interface FormConfig<TSchema extends Schema = Schema> {
|
|
224
|
+
/**
|
|
225
|
+
* The schema of the form.
|
|
226
|
+
*/
|
|
227
|
+
readonly schema: TSchema;
|
|
228
|
+
/**
|
|
229
|
+
* The initial input of the form.
|
|
230
|
+
*/
|
|
231
|
+
readonly initialInput?: DeepPartial<v.InferInput<TSchema>> | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* The validation mode of the form.
|
|
234
|
+
*/
|
|
235
|
+
readonly validate?: ValidationMode | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* The revalidation mode of the form.
|
|
238
|
+
*/
|
|
239
|
+
readonly revalidate?: Exclude<ValidationMode, "initial"> | undefined;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Internal form store interface.
|
|
243
|
+
*/
|
|
244
|
+
interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObjectStore {
|
|
245
|
+
/**
|
|
246
|
+
* The element of the form.
|
|
247
|
+
*/
|
|
248
|
+
element?: HTMLFormElement;
|
|
249
|
+
/**
|
|
250
|
+
* The number of active validators.
|
|
251
|
+
*/
|
|
252
|
+
validators: number;
|
|
253
|
+
/**
|
|
254
|
+
* The validation mode of the form.
|
|
255
|
+
*/
|
|
256
|
+
validate: ValidationMode;
|
|
257
|
+
/**
|
|
258
|
+
* The revalidation mode of the form.
|
|
259
|
+
*/
|
|
260
|
+
revalidate: Exclude<ValidationMode, "initial">;
|
|
261
|
+
/**
|
|
262
|
+
* The parse function of the form.
|
|
263
|
+
*/
|
|
264
|
+
parse: (input: unknown) => Promise<v.SafeParseResult<TSchema>>;
|
|
265
|
+
/**
|
|
266
|
+
* The submitting state of the form.
|
|
267
|
+
*/
|
|
268
|
+
isSubmitting: Signal<boolean>;
|
|
269
|
+
/**
|
|
270
|
+
* The submitted state of the form.
|
|
271
|
+
*/
|
|
272
|
+
isSubmitted: Signal<boolean>;
|
|
273
|
+
/**
|
|
274
|
+
* The validating state of the form.
|
|
275
|
+
*/
|
|
276
|
+
isValidating: Signal<boolean>;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Base form store interface.
|
|
280
|
+
*/
|
|
281
|
+
interface BaseFormStore<TSchema extends Schema = Schema> {
|
|
282
|
+
/**
|
|
283
|
+
* The internal form store.
|
|
284
|
+
*
|
|
285
|
+
* @internal
|
|
286
|
+
*/
|
|
287
|
+
readonly [INTERNAL]: InternalFormStore<TSchema>;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Submit handler type.
|
|
291
|
+
*/
|
|
292
|
+
type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/types/path.d.ts
|
|
295
|
+
/**
|
|
296
|
+
* Path key type.
|
|
297
|
+
*/
|
|
298
|
+
type PathKey = string | number;
|
|
299
|
+
/**
|
|
300
|
+
* Path type.
|
|
301
|
+
*/
|
|
302
|
+
type Path = readonly PathKey[];
|
|
303
|
+
/**
|
|
304
|
+
* Required path type.
|
|
305
|
+
*/
|
|
306
|
+
type RequiredPath = readonly [PathKey, ...Path];
|
|
307
|
+
/**
|
|
308
|
+
* Extracts the exact keys of a tuple, array or object.
|
|
309
|
+
*/
|
|
310
|
+
type KeyOf<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly unknown[] ? number extends TValue["length"] ? number : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? TIndex : never }[number] : TValue extends Record<string, unknown> ? keyof TValue & PathKey : never;
|
|
311
|
+
/**
|
|
312
|
+
* Merges array and object unions into a single object.
|
|
313
|
+
*
|
|
314
|
+
* Hint: This is necessary to make any property accessible. By default,
|
|
315
|
+
* properties that do not exist in all union options are not accessible
|
|
316
|
+
* and result in "any" when accessed.
|
|
317
|
+
*/
|
|
318
|
+
type MergeUnion<T> = { [K in KeyOf<T>]: T extends Record<K, infer V> ? V : never };
|
|
319
|
+
/**
|
|
320
|
+
* Lazily evaluates only the first valid path segment based on the given value.
|
|
321
|
+
*/
|
|
322
|
+
type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends KeyOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOf<TValue>> extends false ? readonly [...TValidPath, KeyOf<TValue>] : TValidPath;
|
|
323
|
+
/**
|
|
324
|
+
* Returns the path if valid, otherwise the first possible valid path based on
|
|
325
|
+
* the given value.
|
|
326
|
+
*/
|
|
327
|
+
type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<Required<TValue>, TPath> ? TPath : LazyPath<Required<TValue>, TPath>;
|
|
328
|
+
/**
|
|
329
|
+
* Extracts the value type at the given path.
|
|
330
|
+
*/
|
|
331
|
+
type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends KeyOf<Required<TValue>> ? PathValue<MergeUnion<Required<TValue>>[TKey], TRest> : unknown : TValue;
|
|
332
|
+
/**
|
|
333
|
+
* Checks if a value is an array or contains one.
|
|
334
|
+
*/
|
|
335
|
+
type IsOrHasArray<TValue> = IsAny<TValue> extends true ? false : TValue extends readonly unknown[] ? true : TValue extends Record<string, unknown> ? true extends { [TKey in keyof TValue]: IsOrHasArray<TValue[TKey]> }[keyof TValue] ? true : false : false;
|
|
336
|
+
/**
|
|
337
|
+
* Extracts the exact keys of a tuple, array or object that contain arrays.
|
|
338
|
+
*/
|
|
339
|
+
type KeyOfArrayPath<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? IsOrHasArray<TItem> extends true ? number : never : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TIndex : never : never }[number] : TValue extends Record<string, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TKey : never }[keyof TValue] & PathKey : never;
|
|
340
|
+
/**
|
|
341
|
+
* Lazily evaluates only the first valid array path segment based on the given value.
|
|
342
|
+
*/
|
|
343
|
+
type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? TValidPath : readonly [...TValidPath, KeyOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends KeyOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOfArrayPath<TValue>> extends false ? readonly [...TValidPath, KeyOfArrayPath<TValue>] : never;
|
|
344
|
+
/**
|
|
345
|
+
* Returns the path if valid, otherwise the first possible valid array path
|
|
346
|
+
* based on the given value.
|
|
347
|
+
*/
|
|
348
|
+
type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/array/copyItemState/copyItemState.d.ts
|
|
351
|
+
/**
|
|
352
|
+
* Copies the deeply nested state (signal values) from one field store to
|
|
353
|
+
* another. This includes the `elements`, `errors`, `startInput`, `input`,
|
|
354
|
+
* `isTouched`, `isDirty`, and for arrays `startItems` and `items` properties.
|
|
355
|
+
* Recursively walks through the field stores and copies all signal values.
|
|
356
|
+
*
|
|
357
|
+
* @param fromInternalFieldStore The source field store to copy from.
|
|
358
|
+
* @param toInternalFieldStore The destination field store to copy to.
|
|
359
|
+
*/
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region ../../packages/methods/dist/index.vanilla.d.ts
|
|
362
|
+
//#region src/focus/focus.d.ts
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Focus field config interface.
|
|
366
|
+
*/
|
|
367
|
+
interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
368
|
+
/**
|
|
369
|
+
* The path to the field to focus.
|
|
370
|
+
*/
|
|
371
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Focuses the first input element of a field. This is useful for
|
|
375
|
+
* programmatically setting focus to a specific field, such as after
|
|
376
|
+
* validation errors or user interactions.
|
|
377
|
+
*
|
|
378
|
+
* @param form The form store containing the field.
|
|
379
|
+
* @param config The focus field configuration.
|
|
380
|
+
*/
|
|
381
|
+
declare function focus<TSchema extends Schema, TFieldPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: FocusFieldConfig<TSchema, TFieldPath>): void;
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/getAllErrors/getAllErrors.d.ts
|
|
384
|
+
/**
|
|
385
|
+
* Retrieves all error messages from all fields in the form by walking through
|
|
386
|
+
* the entire field store tree. This is useful for displaying a summary of all
|
|
387
|
+
* validation errors across the form.
|
|
388
|
+
*
|
|
389
|
+
* @param form The form store to retrieve errors from.
|
|
390
|
+
*
|
|
391
|
+
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
392
|
+
*/
|
|
393
|
+
declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
|
|
394
|
+
//#endregion
|
|
395
|
+
//#region src/getErrors/getErrors.d.ts
|
|
396
|
+
/**
|
|
397
|
+
* Get form errors config interface.
|
|
398
|
+
*/
|
|
399
|
+
interface GetFormErrorsConfig {
|
|
400
|
+
/**
|
|
401
|
+
* The path to a field. Leave undefined to get form-level errors.
|
|
402
|
+
*/
|
|
403
|
+
readonly path?: undefined;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Get field errors config interface.
|
|
407
|
+
*/
|
|
408
|
+
interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
409
|
+
/**
|
|
410
|
+
* The path to the field to retrieve errors from.
|
|
411
|
+
*/
|
|
412
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Retrieves error messages from the form. When called without a config,
|
|
416
|
+
* returns form-level errors. When called with a path, returns errors for
|
|
417
|
+
* that specific field.
|
|
418
|
+
*
|
|
419
|
+
* @param form The form store to retrieve errors from.
|
|
420
|
+
*
|
|
421
|
+
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
422
|
+
*/
|
|
423
|
+
declare function getErrors<TSchema extends Schema>(form: BaseFormStore<TSchema>): [string, ...string[]] | null;
|
|
424
|
+
/**
|
|
425
|
+
* Retrieves error messages from the form. When called without a config,
|
|
426
|
+
* returns form-level errors. When called with a path, returns errors for
|
|
427
|
+
* that specific field.
|
|
428
|
+
*
|
|
429
|
+
* @param form The form store to retrieve errors from.
|
|
430
|
+
* @param config The get errors configuration.
|
|
431
|
+
*
|
|
432
|
+
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
433
|
+
*/
|
|
434
|
+
declare function getErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldErrorsConfig<TSchema, TFieldPath> : GetFormErrorsConfig): [string, ...string[]] | null;
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/getInput/getInput.d.ts
|
|
437
|
+
/**
|
|
438
|
+
* Get form input config interface.
|
|
439
|
+
*/
|
|
440
|
+
interface GetFormInputConfig {
|
|
441
|
+
/**
|
|
442
|
+
* The path to a field. Leave undefined to get the entire form input.
|
|
443
|
+
*/
|
|
444
|
+
readonly path?: undefined;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Get field input config interface.
|
|
448
|
+
*/
|
|
449
|
+
interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
450
|
+
/**
|
|
451
|
+
* The path to the field to retrieve input from.
|
|
452
|
+
*/
|
|
453
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Retrieves the current input value of a specific field or the entire form.
|
|
457
|
+
* Returns a partial object as not all fields may have been set.
|
|
458
|
+
*
|
|
459
|
+
* @param form The form store to retrieve input from.
|
|
460
|
+
*
|
|
461
|
+
* @returns The partial input values of the form or the specified field.
|
|
462
|
+
*/
|
|
463
|
+
declare function getInput<TSchema extends Schema>(form: BaseFormStore<TSchema>): PartialValues<v.InferInput<TSchema>>;
|
|
464
|
+
/**
|
|
465
|
+
* Retrieves the current input value of a specific field or the entire form.
|
|
466
|
+
* Returns a partial object as not all fields may have been set.
|
|
467
|
+
*
|
|
468
|
+
* @param form The form store to retrieve input from.
|
|
469
|
+
* @param config The get input configuration.
|
|
470
|
+
*
|
|
471
|
+
* @returns The partial input values of the form or the specified field.
|
|
472
|
+
*/
|
|
473
|
+
declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldInputConfig<TSchema, TFieldPath> : GetFormInputConfig): PartialValues<TFieldPath extends RequiredPath ? PathValue<v.InferInput<TSchema>, TFieldPath> : v.InferInput<TSchema>>;
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/handleSubmit/handleSubmit.d.ts
|
|
476
|
+
/**
|
|
477
|
+
* Creates a submit event handler for the form that prevents default browser
|
|
478
|
+
* submission, validates the form input, and calls the provided handler if
|
|
479
|
+
* validation succeeds. This is designed to be used with the form's onsubmit event.
|
|
480
|
+
*
|
|
481
|
+
* @param form The form store to handle submission for.
|
|
482
|
+
* @param handler The submit handler function called with validated output if validation succeeds.
|
|
483
|
+
*
|
|
484
|
+
* @returns A submit event handler function to attach to the form element.
|
|
485
|
+
*/
|
|
486
|
+
declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/insert/insert.d.ts
|
|
489
|
+
/**
|
|
490
|
+
* Insert array field config interface.
|
|
491
|
+
*/
|
|
492
|
+
interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
493
|
+
/**
|
|
494
|
+
* The path to the field array to insert into.
|
|
495
|
+
*/
|
|
496
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
497
|
+
/**
|
|
498
|
+
* The index to insert the new item at. If undefined, appends to the end.
|
|
499
|
+
*/
|
|
500
|
+
readonly at?: number | undefined;
|
|
501
|
+
/**
|
|
502
|
+
* The partial initial input value for the new item.
|
|
503
|
+
*/
|
|
504
|
+
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Inserts a new item into a field array at the specified index. All items at
|
|
508
|
+
* or after the insertion point are shifted up by one index.
|
|
509
|
+
*
|
|
510
|
+
* @param form The form store containing the field array.
|
|
511
|
+
* @param config The insert configuration specifying the path, index, and initial value.
|
|
512
|
+
*/
|
|
513
|
+
declare function insert<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region src/move/move.d.ts
|
|
516
|
+
/**
|
|
517
|
+
* Move array field config interface.
|
|
518
|
+
*/
|
|
519
|
+
interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
520
|
+
/**
|
|
521
|
+
* The path to the field array to move an item within.
|
|
522
|
+
*/
|
|
523
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
524
|
+
/**
|
|
525
|
+
* The index of the item to move from.
|
|
526
|
+
*/
|
|
527
|
+
readonly from: number;
|
|
528
|
+
/**
|
|
529
|
+
* The index to move the item to.
|
|
530
|
+
*/
|
|
531
|
+
readonly to: number;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Moves an item from one index to another within a field array. All items
|
|
535
|
+
* between the source and destination indices are shifted accordingly.
|
|
536
|
+
*
|
|
537
|
+
* @param form The form store containing the field array.
|
|
538
|
+
* @param config The move configuration specifying the path and source/destination indices.
|
|
539
|
+
*/
|
|
540
|
+
declare function move<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: MoveConfig<TSchema, TFieldArrayPath>): void;
|
|
541
|
+
//#endregion
|
|
542
|
+
//#region src/remove/remove.d.ts
|
|
543
|
+
/**
|
|
544
|
+
* Remove array field config interface.
|
|
545
|
+
*/
|
|
546
|
+
interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
547
|
+
/**
|
|
548
|
+
* The path to the field array to remove an item from.
|
|
549
|
+
*/
|
|
550
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
551
|
+
/**
|
|
552
|
+
* The index of the item to remove.
|
|
553
|
+
*/
|
|
554
|
+
readonly at: number;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Removes an item from a field array at the specified index. All items after
|
|
558
|
+
* the removed item are shifted down by one index.
|
|
559
|
+
*
|
|
560
|
+
* @param form The form store containing the field array.
|
|
561
|
+
* @param config The remove configuration specifying the path and index.
|
|
562
|
+
*/
|
|
563
|
+
declare function remove<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: RemoveConfig<TSchema, TFieldArrayPath>): void;
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/replace/replace.d.ts
|
|
566
|
+
/**
|
|
567
|
+
* Replace array field config interface.
|
|
568
|
+
*/
|
|
569
|
+
interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
570
|
+
/**
|
|
571
|
+
* The path to the field array to replace an item within.
|
|
572
|
+
*/
|
|
573
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
574
|
+
/**
|
|
575
|
+
* The index of the item to replace.
|
|
576
|
+
*/
|
|
577
|
+
readonly at: number;
|
|
578
|
+
/**
|
|
579
|
+
* The partial initial input value for the replacement item.
|
|
580
|
+
*/
|
|
581
|
+
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Replaces an item in a field array at the specified index with new initial input.
|
|
585
|
+
*
|
|
586
|
+
* @param form The form store containing the field array.
|
|
587
|
+
* @param config The replace configuration specifying the path, index, and initial input.
|
|
588
|
+
*/
|
|
589
|
+
declare function replace<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: ReplaceConfig<TSchema, TFieldArrayPath>): void;
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/reset/reset.d.ts
|
|
592
|
+
/**
|
|
593
|
+
* Reset base config interface.
|
|
594
|
+
*/
|
|
595
|
+
interface ResetBaseConfig {
|
|
596
|
+
/**
|
|
597
|
+
* Whether to keep the current input values during reset. Defaults to false.
|
|
598
|
+
*/
|
|
599
|
+
readonly keepInput?: boolean | undefined;
|
|
600
|
+
/**
|
|
601
|
+
* Whether to keep the touched state during reset. Defaults to false.
|
|
602
|
+
*/
|
|
603
|
+
readonly keepTouched?: boolean | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* Whether to keep the error messages during reset. Defaults to false.
|
|
606
|
+
*/
|
|
607
|
+
readonly keepErrors?: boolean | undefined;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Reset form config interface.
|
|
611
|
+
*/
|
|
612
|
+
interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
|
|
613
|
+
/**
|
|
614
|
+
* The path to a field. Leave undefined to reset the entire form.
|
|
615
|
+
*/
|
|
616
|
+
readonly path?: undefined;
|
|
617
|
+
/**
|
|
618
|
+
* The new initial input to reset to. If provided, replaces the form's
|
|
619
|
+
* initial input.
|
|
620
|
+
*/
|
|
621
|
+
readonly initialInput?: DeepPartial<v.InferInput<TSchema>> | undefined;
|
|
622
|
+
/**
|
|
623
|
+
* Whether to keep the submitted state during reset. Defaults to false.
|
|
624
|
+
*/
|
|
625
|
+
readonly keepSubmitted?: boolean | undefined;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Reset field config interface.
|
|
629
|
+
*/
|
|
630
|
+
interface ResetFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
|
|
631
|
+
/**
|
|
632
|
+
* The path to the field to reset.
|
|
633
|
+
*/
|
|
634
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
635
|
+
/**
|
|
636
|
+
* The new initial input to reset the field to. If provided, replaces the
|
|
637
|
+
* field's initial input.
|
|
638
|
+
*/
|
|
639
|
+
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, TFieldPath>>;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Resets a specific field or the entire form to its initial state. Provides
|
|
643
|
+
* fine-grained control over which state to preserve during reset through the
|
|
644
|
+
* configuration options.
|
|
645
|
+
*
|
|
646
|
+
* @param form The form store to reset.
|
|
647
|
+
*/
|
|
648
|
+
declare function reset(form: BaseFormStore): void;
|
|
649
|
+
/**
|
|
650
|
+
* Resets a specific field or the entire form to its initial state. Provides
|
|
651
|
+
* fine-grained control over which state to preserve during reset through the
|
|
652
|
+
* configuration options.
|
|
653
|
+
*
|
|
654
|
+
* @param form The form store to reset.
|
|
655
|
+
* @param config The reset configuration specifying what to reset and what to keep.
|
|
656
|
+
*/
|
|
657
|
+
declare function reset<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? ResetFieldConfig<TSchema, TFieldPath> : ResetFormConfig<TSchema>): void;
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region src/setErrors/setErrors.d.ts
|
|
660
|
+
/**
|
|
661
|
+
* Set form errors config interface.
|
|
662
|
+
*/
|
|
663
|
+
interface SetFormErrorsConfig {
|
|
664
|
+
/**
|
|
665
|
+
* The path to a field. Leave undefined to set form-level errors.
|
|
666
|
+
*/
|
|
667
|
+
readonly path?: undefined;
|
|
668
|
+
/**
|
|
669
|
+
* The error messages to set, or null to clear errors.
|
|
670
|
+
*/
|
|
671
|
+
readonly errors: [string, ...string[]] | null;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Set field errors config interface.
|
|
675
|
+
*/
|
|
676
|
+
interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
677
|
+
/**
|
|
678
|
+
* The path to the field to set errors on.
|
|
679
|
+
*/
|
|
680
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
681
|
+
/**
|
|
682
|
+
* The error messages to set, or null to clear errors.
|
|
683
|
+
*/
|
|
684
|
+
readonly errors: [string, ...string[]] | null;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Sets or clears error messages on the form or a specific field. This is
|
|
688
|
+
* useful for setting custom validation errors that don't come from schema
|
|
689
|
+
* validation.
|
|
690
|
+
*
|
|
691
|
+
* @param form The form store to set errors on.
|
|
692
|
+
* @param config The set errors configuration specifying the path and error messages.
|
|
693
|
+
*/
|
|
694
|
+
declare function setErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldErrorsConfig<TSchema, TFieldPath> : SetFormErrorsConfig): void;
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region src/setInput/setInput.d.ts
|
|
697
|
+
/**
|
|
698
|
+
* Set form input config interface.
|
|
699
|
+
*/
|
|
700
|
+
interface SetFormInputConfig<TSchema extends Schema> {
|
|
701
|
+
/**
|
|
702
|
+
* The path to a field. Leave undefined to set the entire form input.
|
|
703
|
+
*/
|
|
704
|
+
readonly path?: undefined;
|
|
705
|
+
/**
|
|
706
|
+
* The input value to set for the form.
|
|
707
|
+
*/
|
|
708
|
+
readonly input: v.InferInput<TSchema>;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Set field input config interface.
|
|
712
|
+
*/
|
|
713
|
+
interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
714
|
+
/**
|
|
715
|
+
* The path to the field to set input on.
|
|
716
|
+
*/
|
|
717
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
718
|
+
/**
|
|
719
|
+
* The input value to set for the field.
|
|
720
|
+
*/
|
|
721
|
+
readonly input: PathValue<v.InferInput<TSchema>, TFieldPath>;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Sets the input value of a specific field or the entire form. This updates
|
|
725
|
+
* the field value(s) and triggers validation if required by the form's
|
|
726
|
+
* validation mode.
|
|
727
|
+
*
|
|
728
|
+
* @param form The form store to set input on.
|
|
729
|
+
* @param config The set form input configuration specifying the new input values.
|
|
730
|
+
*/
|
|
731
|
+
declare function setInput<TSchema extends Schema>(form: BaseFormStore<TSchema>, config: SetFormInputConfig<TSchema>): void;
|
|
732
|
+
/**
|
|
733
|
+
* Sets the input value of a specific field or the entire form. This updates
|
|
734
|
+
* the field value(s) and triggers validation if required by the form's
|
|
735
|
+
* validation mode.
|
|
736
|
+
*
|
|
737
|
+
* @param form The form store to set input on.
|
|
738
|
+
* @param config The set input configuration specifying the path and new value.
|
|
739
|
+
*/
|
|
740
|
+
declare function setInput<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldInputConfig<TSchema, TFieldPath> : SetFormInputConfig<TSchema>): void;
|
|
741
|
+
//#endregion
|
|
742
|
+
//#region src/submit/submit.d.ts
|
|
743
|
+
/**
|
|
744
|
+
* Programmatically requests form submission by calling the native
|
|
745
|
+
* `requestSubmit()` method on the underlying form element.
|
|
746
|
+
*
|
|
747
|
+
* @param form The form store to submit.
|
|
748
|
+
*/
|
|
749
|
+
declare function submit(form: BaseFormStore): void;
|
|
750
|
+
//#endregion
|
|
751
|
+
//#region src/swap/swap.d.ts
|
|
752
|
+
/**
|
|
753
|
+
* Swap array field config interface.
|
|
754
|
+
*/
|
|
755
|
+
interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
756
|
+
/**
|
|
757
|
+
* The path to the field array to swap items within.
|
|
758
|
+
*/
|
|
759
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
760
|
+
/**
|
|
761
|
+
* The index of the first item to swap.
|
|
762
|
+
*/
|
|
763
|
+
readonly at: number;
|
|
764
|
+
/**
|
|
765
|
+
* The index of the second item to swap with the first.
|
|
766
|
+
*/
|
|
767
|
+
readonly and: number;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Swaps two items in a field array by exchanging their positions.
|
|
771
|
+
*
|
|
772
|
+
* @param form The form store containing the field array.
|
|
773
|
+
* @param config The swap configuration specifying the path and indices to swap.
|
|
774
|
+
*/
|
|
775
|
+
declare function swap<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: SwapConfig<TSchema, TFieldArrayPath>): void;
|
|
776
|
+
//#endregion
|
|
777
|
+
//#region src/validate/validate.d.ts
|
|
778
|
+
/**
|
|
779
|
+
* Validate form config interface.
|
|
780
|
+
*/
|
|
781
|
+
interface ValidateFormConfig {
|
|
782
|
+
/**
|
|
783
|
+
* Whether to focus the first field with errors after validation. Defaults to false.
|
|
784
|
+
*/
|
|
785
|
+
readonly shouldFocus?: boolean | undefined;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Validates the entire form input against its schema. Returns a safe parse result
|
|
789
|
+
* indicating success or failure with detailed issues. Optionally focuses the first
|
|
790
|
+
* field with validation errors.
|
|
791
|
+
*
|
|
792
|
+
* @param form The form store to validate.
|
|
793
|
+
* @param config The validate form configuration specifying focus behavior.
|
|
794
|
+
*
|
|
795
|
+
* @returns A promise resolving to the validation result.
|
|
796
|
+
*/
|
|
797
|
+
declare function validate<TSchema extends Schema>(form: BaseFormStore<TSchema>, config?: ValidateFormConfig): Promise<v.SafeParseResult<TSchema>>;
|
|
798
|
+
//#endregion
|
|
799
|
+
//#endregion
|
|
800
|
+
//#region src/types/field.d.ts
|
|
801
|
+
/**
|
|
802
|
+
* Field element props interface.
|
|
803
|
+
*/
|
|
804
|
+
interface FieldElementProps {
|
|
805
|
+
/**
|
|
806
|
+
* The name attribute of the field element.
|
|
807
|
+
*/
|
|
808
|
+
readonly name: string;
|
|
809
|
+
/**
|
|
810
|
+
* Whether to autofocus the field element when there are errors.
|
|
811
|
+
*/
|
|
812
|
+
readonly autoFocus: boolean;
|
|
813
|
+
/**
|
|
814
|
+
* The ref callback to register the field element.
|
|
815
|
+
*/
|
|
816
|
+
readonly ref: (element: FieldElement | null) => void;
|
|
817
|
+
/**
|
|
818
|
+
* The focus event handler of the field element.
|
|
819
|
+
*/
|
|
820
|
+
readonly onFocus: FocusEventHandler<FieldElement>;
|
|
821
|
+
/**
|
|
822
|
+
* The change event handler of the field element.
|
|
823
|
+
*/
|
|
824
|
+
readonly onChange: ChangeEventHandler<FieldElement>;
|
|
825
|
+
/**
|
|
826
|
+
* The blur event handler of the field element.
|
|
827
|
+
*/
|
|
828
|
+
readonly onBlur: FocusEventHandler<FieldElement>;
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Field store interface.
|
|
832
|
+
*/
|
|
833
|
+
interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
834
|
+
/**
|
|
835
|
+
* The path to the field within the form.
|
|
836
|
+
*/
|
|
837
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
838
|
+
/**
|
|
839
|
+
* The current input value of the field.
|
|
840
|
+
*/
|
|
841
|
+
readonly input: PartialValues<PathValue<v.InferInput<TSchema>, TFieldPath>>;
|
|
842
|
+
/**
|
|
843
|
+
* The current error messages of the field.
|
|
844
|
+
*/
|
|
845
|
+
readonly errors: [string, ...string[]] | null;
|
|
846
|
+
/**
|
|
847
|
+
* Whether the field has been touched.
|
|
848
|
+
*/
|
|
849
|
+
readonly isTouched: boolean;
|
|
850
|
+
/**
|
|
851
|
+
* Whether the field input differs from its initial value.
|
|
852
|
+
*/
|
|
853
|
+
readonly isDirty: boolean;
|
|
854
|
+
/**
|
|
855
|
+
* Whether the field is valid according to the schema.
|
|
856
|
+
*/
|
|
857
|
+
readonly isValid: boolean;
|
|
858
|
+
/**
|
|
859
|
+
* The props to spread onto the field element for integration.
|
|
860
|
+
*/
|
|
861
|
+
readonly props: FieldElementProps;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Field array store interface.
|
|
865
|
+
*/
|
|
866
|
+
interface FieldArrayStore<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
867
|
+
/**
|
|
868
|
+
* The path to the array field within the form.
|
|
869
|
+
*/
|
|
870
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
871
|
+
/**
|
|
872
|
+
* The item IDs of the array field.
|
|
873
|
+
*/
|
|
874
|
+
readonly items: string[];
|
|
875
|
+
/**
|
|
876
|
+
* The current error messages of the field array.
|
|
877
|
+
*/
|
|
878
|
+
readonly errors: [string, ...string[]] | null;
|
|
879
|
+
/**
|
|
880
|
+
* Whether the field array has been touched.
|
|
881
|
+
*/
|
|
882
|
+
readonly isTouched: boolean;
|
|
883
|
+
/**
|
|
884
|
+
* Whether the field array input differs from its initial value.
|
|
885
|
+
*/
|
|
886
|
+
readonly isDirty: boolean;
|
|
887
|
+
/**
|
|
888
|
+
* Whether the field array is valid according to the schema.
|
|
889
|
+
*/
|
|
890
|
+
readonly isValid: boolean;
|
|
891
|
+
}
|
|
892
|
+
//#endregion
|
|
893
|
+
//#region src/types/form.d.ts
|
|
894
|
+
/**
|
|
895
|
+
* Form store interface.
|
|
896
|
+
*/
|
|
897
|
+
interface FormStore<TSchema extends Schema = Schema> extends BaseFormStore<TSchema> {
|
|
898
|
+
/**
|
|
899
|
+
* Whether the form is currently submitting.
|
|
900
|
+
*/
|
|
901
|
+
readonly isSubmitting: boolean;
|
|
902
|
+
/**
|
|
903
|
+
* Whether the form has been submitted.
|
|
904
|
+
*/
|
|
905
|
+
readonly isSubmitted: boolean;
|
|
906
|
+
/**
|
|
907
|
+
* Whether the form is currently validating.
|
|
908
|
+
*/
|
|
909
|
+
readonly isValidating: boolean;
|
|
910
|
+
/**
|
|
911
|
+
* Whether any field in the form has been touched.
|
|
912
|
+
*/
|
|
913
|
+
readonly isTouched: boolean;
|
|
914
|
+
/**
|
|
915
|
+
* Whether any field in the form differs from its initial value.
|
|
916
|
+
*/
|
|
917
|
+
readonly isDirty: boolean;
|
|
918
|
+
/**
|
|
919
|
+
* Whether the form is valid according to the schema.
|
|
920
|
+
*/
|
|
921
|
+
readonly isValid: boolean;
|
|
922
|
+
/**
|
|
923
|
+
* The current error messages of the form.
|
|
924
|
+
*
|
|
925
|
+
* Hint: This property only contains validation errors at the root level
|
|
926
|
+
* of the form. To get all errors from all fields, use `getAllErrors`.
|
|
927
|
+
*/
|
|
928
|
+
readonly errors: [string, ...string[]] | null;
|
|
929
|
+
}
|
|
930
|
+
//#endregion
|
|
931
|
+
//#region src/components/Field/Field.d.ts
|
|
932
|
+
/**
|
|
933
|
+
* Field component props interface.
|
|
934
|
+
*/
|
|
935
|
+
interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
936
|
+
/**
|
|
937
|
+
* The form store to which the field belongs.
|
|
938
|
+
*/
|
|
939
|
+
readonly of: FormStore<TSchema>;
|
|
940
|
+
/**
|
|
941
|
+
* The path to the field within the form schema.
|
|
942
|
+
*/
|
|
943
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
944
|
+
/**
|
|
945
|
+
* The render function that receives the field store and returns JSX.
|
|
946
|
+
*/
|
|
947
|
+
readonly children: (store: FieldStore<TSchema, TFieldPath>) => ReactElement;
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Headless form field component that provides reactive properties and state.
|
|
951
|
+
* The field component takes a form store, path to field, and a render function
|
|
952
|
+
* that receives a field store to display field state and handle user interactions.
|
|
953
|
+
*
|
|
954
|
+
* @param props The field component props.
|
|
955
|
+
*
|
|
956
|
+
* @returns The UI of the field to be rendered.
|
|
957
|
+
*/
|
|
958
|
+
declare function Field<TSchema extends Schema, TFieldPath extends RequiredPath>({
|
|
959
|
+
of,
|
|
960
|
+
path,
|
|
961
|
+
children
|
|
962
|
+
}: FieldProps<TSchema, TFieldPath>): ReactElement;
|
|
963
|
+
//#endregion
|
|
964
|
+
//#region src/components/FieldArray/FieldArray.d.ts
|
|
965
|
+
/**
|
|
966
|
+
* FieldArray component props interface.
|
|
967
|
+
*/
|
|
968
|
+
interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
969
|
+
/**
|
|
970
|
+
* The form store to which the field array belongs.
|
|
971
|
+
*/
|
|
972
|
+
readonly of: FormStore<TSchema>;
|
|
973
|
+
/**
|
|
974
|
+
* The path to the field array within the form schema.
|
|
975
|
+
*/
|
|
976
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
977
|
+
/**
|
|
978
|
+
* The render function that receives the field array store and returns JSX.
|
|
979
|
+
*/
|
|
980
|
+
readonly children: (store: FieldArrayStore<TSchema, TFieldArrayPath>) => ReactElement;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Headless field array component that provides reactive properties and state.
|
|
984
|
+
* The field array component takes a form store, path to array field, and a render
|
|
985
|
+
* function that receives a field array store to manage array items and handle
|
|
986
|
+
* array operations.
|
|
987
|
+
*
|
|
988
|
+
* @param props The field array component props.
|
|
989
|
+
*
|
|
990
|
+
* @returns The UI of the field array to be rendered.
|
|
991
|
+
*/
|
|
992
|
+
declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>({
|
|
993
|
+
of,
|
|
994
|
+
path,
|
|
995
|
+
children
|
|
996
|
+
}: FieldArrayProps<TSchema, TFieldArrayPath>): ReactElement;
|
|
997
|
+
//#endregion
|
|
998
|
+
//#region src/components/Form/Form.d.ts
|
|
999
|
+
/**
|
|
1000
|
+
* Form component props type.
|
|
1001
|
+
*/
|
|
1002
|
+
type FormProps<TSchema extends Schema = Schema> = Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "novalidate" | "noValidate"> & {
|
|
1003
|
+
/**
|
|
1004
|
+
* The form store instance.
|
|
1005
|
+
*/
|
|
1006
|
+
readonly of: FormStore<TSchema>;
|
|
1007
|
+
/**
|
|
1008
|
+
* The submit handler called when the form is submitted and validation succeeds.
|
|
1009
|
+
*/
|
|
1010
|
+
readonly onSubmit: SubmitHandler<TSchema>;
|
|
1011
|
+
};
|
|
1012
|
+
/**
|
|
1013
|
+
* Form component that manages form submission and applies internal state.
|
|
1014
|
+
* Wraps form element and passes submission events to the provided handler.
|
|
1015
|
+
*
|
|
1016
|
+
* @param props The form component props.
|
|
1017
|
+
*
|
|
1018
|
+
* @returns The a native form element.
|
|
1019
|
+
*/
|
|
1020
|
+
declare function Form<TSchema extends Schema>(props: FormProps<TSchema>): ReactElement;
|
|
1021
|
+
//#endregion
|
|
1022
|
+
//#region src/hooks/useField/useField.d.ts
|
|
1023
|
+
/**
|
|
1024
|
+
* Use field config interface.
|
|
1025
|
+
*/
|
|
1026
|
+
interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
1027
|
+
/**
|
|
1028
|
+
* The path to the field within the form schema.
|
|
1029
|
+
*/
|
|
1030
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Creates a reactive field store of a specific field within a form store.
|
|
1034
|
+
*
|
|
1035
|
+
* @param form The form store instance.
|
|
1036
|
+
* @param config The field configuration.
|
|
1037
|
+
*
|
|
1038
|
+
* @returns The field store with reactive properties and element props.
|
|
1039
|
+
*/
|
|
1040
|
+
declare function useField<TSchema extends Schema, TFieldPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldConfig<TSchema, TFieldPath>): FieldStore<TSchema, TFieldPath>;
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/hooks/useFieldArray/useFieldArray.d.ts
|
|
1043
|
+
/**
|
|
1044
|
+
* Use field array config interface.
|
|
1045
|
+
*/
|
|
1046
|
+
interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
1047
|
+
/**
|
|
1048
|
+
* The path to the array field within the form schema.
|
|
1049
|
+
*/
|
|
1050
|
+
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Creates a reactive field array store of a specific field array within a form store.
|
|
1054
|
+
*
|
|
1055
|
+
* @param form The form store instance.
|
|
1056
|
+
* @param config The field array configuration.
|
|
1057
|
+
*
|
|
1058
|
+
* @returns The field array store with reactive properties for array management.
|
|
1059
|
+
*/
|
|
1060
|
+
declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldArrayConfig<TSchema, TFieldArrayPath>): FieldArrayStore<TSchema, TFieldArrayPath>;
|
|
1061
|
+
//#endregion
|
|
1062
|
+
//#region src/hooks/useForm/useForm.d.ts
|
|
1063
|
+
/**
|
|
1064
|
+
* Creates a reactive form store from a form configuration. The form store
|
|
1065
|
+
* manages form state and provides reactive properties.
|
|
1066
|
+
*
|
|
1067
|
+
* @param config The form configuration.
|
|
1068
|
+
*
|
|
1069
|
+
* @returns The form store with reactive properties.
|
|
1070
|
+
*/
|
|
1071
|
+
declare function useForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
|
|
1072
|
+
//#endregion
|
|
1073
|
+
export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
|