@formisch/solid 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev.js +46 -30
- package/dist/dev.jsx +46 -30
- package/dist/index.d.ts +702 -25
- package/dist/index.js +46 -30
- package/dist/index.jsx +46 -30
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -2,55 +2,192 @@ import * as v from "valibot";
|
|
|
2
2
|
import { JSX } from "solid-js";
|
|
3
3
|
|
|
4
4
|
//#region ../../packages/core/dist/index.solid.d.ts
|
|
5
|
+
|
|
5
6
|
//#region src/types/schema.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Schema type.
|
|
9
|
+
*/
|
|
6
10
|
type Schema = v.GenericSchema | v.GenericSchemaAsync;
|
|
7
11
|
//#endregion
|
|
8
12
|
//#region src/types/signal.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* Signal interface.
|
|
15
|
+
*/
|
|
9
16
|
interface Signal<T> {
|
|
17
|
+
/**
|
|
18
|
+
* The value of the signal.
|
|
19
|
+
*/
|
|
10
20
|
value: T;
|
|
11
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Batch interface.
|
|
24
|
+
*/
|
|
25
|
+
|
|
12
26
|
//#endregion
|
|
13
27
|
//#region src/types/field.d.ts
|
|
14
28
|
/**
|
|
15
|
-
*
|
|
29
|
+
* Field element type.
|
|
16
30
|
*/
|
|
17
31
|
type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
32
|
+
/**
|
|
33
|
+
* Internal base store interface.
|
|
34
|
+
*/
|
|
18
35
|
interface InternalBaseStore {
|
|
36
|
+
/**
|
|
37
|
+
* The kind of field store.
|
|
38
|
+
*/
|
|
19
39
|
kind: "array" | "object" | "value";
|
|
40
|
+
/**
|
|
41
|
+
* The name of the field.
|
|
42
|
+
*/
|
|
20
43
|
name: string;
|
|
44
|
+
/**
|
|
45
|
+
* The schema of the field.
|
|
46
|
+
*/
|
|
21
47
|
schema: Schema;
|
|
48
|
+
/**
|
|
49
|
+
* The initial elements of the field.
|
|
50
|
+
*/
|
|
22
51
|
initialElements: FieldElement[];
|
|
52
|
+
/**
|
|
53
|
+
* The elements of the field.
|
|
54
|
+
*/
|
|
23
55
|
elements: FieldElement[];
|
|
56
|
+
/**
|
|
57
|
+
* The errors of the field.
|
|
58
|
+
*/
|
|
24
59
|
errors: Signal<[string, ...string[]] | null>;
|
|
60
|
+
/**
|
|
61
|
+
* The touched state of the field.
|
|
62
|
+
*/
|
|
25
63
|
isTouched: Signal<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* The dirty state of the field.
|
|
66
|
+
*/
|
|
26
67
|
isDirty: Signal<boolean>;
|
|
27
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Internal array store interface.
|
|
71
|
+
*/
|
|
28
72
|
interface InternalArrayStore extends InternalBaseStore {
|
|
73
|
+
/**
|
|
74
|
+
* The kind of field store.
|
|
75
|
+
*/
|
|
29
76
|
kind: "array";
|
|
77
|
+
/**
|
|
78
|
+
* The children of the array field.
|
|
79
|
+
*/
|
|
30
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
|
+
*/
|
|
31
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
|
+
*/
|
|
32
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
|
+
*/
|
|
33
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
|
+
*/
|
|
34
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
|
+
*/
|
|
35
115
|
startItems: Signal<string[]>;
|
|
116
|
+
/**
|
|
117
|
+
* The items of the array field.
|
|
118
|
+
*/
|
|
36
119
|
items: Signal<string[]>;
|
|
37
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Internal object store interface.
|
|
123
|
+
*/
|
|
38
124
|
interface InternalObjectStore extends InternalBaseStore {
|
|
125
|
+
/**
|
|
126
|
+
* The kind of field store.
|
|
127
|
+
*/
|
|
39
128
|
kind: "object";
|
|
129
|
+
/**
|
|
130
|
+
* The children of the object field.
|
|
131
|
+
*/
|
|
40
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
|
+
*/
|
|
41
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
|
+
*/
|
|
42
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
|
+
*/
|
|
43
153
|
input: Signal<true | null | undefined>;
|
|
44
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Internal value store interface.
|
|
157
|
+
*/
|
|
45
158
|
interface InternalValueStore extends InternalBaseStore {
|
|
159
|
+
/**
|
|
160
|
+
* The kind of field store.
|
|
161
|
+
*/
|
|
46
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
|
+
*/
|
|
47
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
|
+
*/
|
|
48
176
|
startInput: Signal<unknown>;
|
|
177
|
+
/**
|
|
178
|
+
* The input of the value field.
|
|
179
|
+
*/
|
|
49
180
|
input: Signal<unknown>;
|
|
50
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Internal field store type.
|
|
184
|
+
*/
|
|
51
185
|
type InternalFieldStore = InternalArrayStore | InternalObjectStore | InternalValueStore;
|
|
52
186
|
//#endregion
|
|
53
187
|
//#region src/values.d.ts
|
|
188
|
+
/**
|
|
189
|
+
* Internal symbol constant.
|
|
190
|
+
*/
|
|
54
191
|
declare const INTERNAL: "~internal";
|
|
55
192
|
//#endregion
|
|
56
193
|
//#region src/types/utils.d.ts
|
|
@@ -77,28 +214,81 @@ type PartialValues<TValue> = TValue extends readonly unknown[] ? number extends
|
|
|
77
214
|
//#endregion
|
|
78
215
|
//#region src/types/form.d.ts
|
|
79
216
|
/**
|
|
80
|
-
*
|
|
217
|
+
* Validation mode type.
|
|
81
218
|
*/
|
|
82
219
|
type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submit";
|
|
220
|
+
/**
|
|
221
|
+
* Form config interface.
|
|
222
|
+
*/
|
|
83
223
|
interface FormConfig<TSchema extends Schema = Schema> {
|
|
224
|
+
/**
|
|
225
|
+
* The schema of the form.
|
|
226
|
+
*/
|
|
84
227
|
readonly schema: TSchema;
|
|
228
|
+
/**
|
|
229
|
+
* The initial input of the form.
|
|
230
|
+
*/
|
|
85
231
|
readonly initialInput?: DeepPartial<v.InferInput<TSchema>> | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* The validation mode of the form.
|
|
234
|
+
*/
|
|
86
235
|
readonly validate?: ValidationMode | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* The revalidation mode of the form.
|
|
238
|
+
*/
|
|
87
239
|
readonly revalidate?: Exclude<ValidationMode, "initial"> | undefined;
|
|
88
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Internal form store interface.
|
|
243
|
+
*/
|
|
89
244
|
interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObjectStore {
|
|
245
|
+
/**
|
|
246
|
+
* The element of the form.
|
|
247
|
+
*/
|
|
90
248
|
element?: HTMLFormElement;
|
|
249
|
+
/**
|
|
250
|
+
* The number of active validators.
|
|
251
|
+
*/
|
|
91
252
|
validators: number;
|
|
253
|
+
/**
|
|
254
|
+
* The validation mode of the form.
|
|
255
|
+
*/
|
|
92
256
|
validate: ValidationMode;
|
|
257
|
+
/**
|
|
258
|
+
* The revalidation mode of the form.
|
|
259
|
+
*/
|
|
93
260
|
revalidate: Exclude<ValidationMode, "initial">;
|
|
261
|
+
/**
|
|
262
|
+
* The parse function of the form.
|
|
263
|
+
*/
|
|
94
264
|
parse: (input: unknown) => Promise<v.SafeParseResult<TSchema>>;
|
|
265
|
+
/**
|
|
266
|
+
* The submitting state of the form.
|
|
267
|
+
*/
|
|
95
268
|
isSubmitting: Signal<boolean>;
|
|
269
|
+
/**
|
|
270
|
+
* The submitted state of the form.
|
|
271
|
+
*/
|
|
96
272
|
isSubmitted: Signal<boolean>;
|
|
273
|
+
/**
|
|
274
|
+
* The validating state of the form.
|
|
275
|
+
*/
|
|
97
276
|
isValidating: Signal<boolean>;
|
|
98
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Base form store interface.
|
|
280
|
+
*/
|
|
99
281
|
interface BaseFormStore<TSchema extends Schema = Schema> {
|
|
100
|
-
|
|
282
|
+
/**
|
|
283
|
+
* The internal form store.
|
|
284
|
+
*
|
|
285
|
+
* @internal
|
|
286
|
+
*/
|
|
287
|
+
readonly [INTERNAL]: InternalFormStore<TSchema>;
|
|
101
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Submit handler type.
|
|
291
|
+
*/
|
|
102
292
|
type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
|
|
103
293
|
//#endregion
|
|
104
294
|
//#region src/types/path.d.ts
|
|
@@ -127,7 +317,7 @@ type KeyOf<TValue> = IsAny<TValue> extends true ? never : TValue extends readonl
|
|
|
127
317
|
*/
|
|
128
318
|
type MergeUnion<T> = { [K in KeyOf<T>]: T extends Record<K, infer V> ? V : never };
|
|
129
319
|
/**
|
|
130
|
-
* Lazily
|
|
320
|
+
* Lazily evaluates only the first valid path segment based on the given value.
|
|
131
321
|
*/
|
|
132
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;
|
|
133
323
|
/**
|
|
@@ -148,196 +338,597 @@ type IsOrHasArray<TValue> = IsAny<TValue> extends true ? false : TValue extends
|
|
|
148
338
|
*/
|
|
149
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;
|
|
150
340
|
/**
|
|
151
|
-
* Lazily
|
|
341
|
+
* Lazily evaluates only the first valid array path segment based on the given value.
|
|
152
342
|
*/
|
|
153
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;
|
|
154
344
|
/**
|
|
155
|
-
* Returns the path if valid, otherwise the first possible valid array path
|
|
156
|
-
* the given value.
|
|
345
|
+
* Returns the path if valid, otherwise the first possible valid array path
|
|
346
|
+
* based on the given value.
|
|
157
347
|
*/
|
|
158
348
|
type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
|
|
159
349
|
//#endregion
|
|
160
350
|
//#region src/array/copyItemState/copyItemState.d.ts
|
|
161
351
|
/**
|
|
162
|
-
* Copies the deeply nested state (signal values) from one
|
|
163
|
-
* This includes the `
|
|
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.
|
|
164
355
|
* Recursively walks through the field stores and copies all signal values.
|
|
165
356
|
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @param toIndex - The destination index to copy to
|
|
357
|
+
* @param fromInternalFieldStore The source field store to copy from.
|
|
358
|
+
* @param toInternalFieldStore The destination field store to copy to.
|
|
169
359
|
*/
|
|
170
360
|
//#endregion
|
|
171
361
|
//#region ../../packages/methods/dist/index.solid.d.ts
|
|
172
362
|
//#region src/focus/focus.d.ts
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Focus field config interface.
|
|
366
|
+
*/
|
|
173
367
|
interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
174
|
-
|
|
368
|
+
/**
|
|
369
|
+
* The path to the field to focus.
|
|
370
|
+
*/
|
|
175
371
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
176
372
|
}
|
|
177
|
-
|
|
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;
|
|
178
382
|
//#endregion
|
|
179
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
|
+
*/
|
|
180
393
|
declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
|
|
181
394
|
//#endregion
|
|
182
395
|
//#region src/getErrors/getErrors.d.ts
|
|
396
|
+
/**
|
|
397
|
+
* Get form errors config interface.
|
|
398
|
+
*/
|
|
183
399
|
interface GetFormErrorsConfig {
|
|
400
|
+
/**
|
|
401
|
+
* The path to a field. Leave undefined to get form-level errors.
|
|
402
|
+
*/
|
|
184
403
|
readonly path?: undefined;
|
|
185
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Get field errors config interface.
|
|
407
|
+
*/
|
|
186
408
|
interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
409
|
+
/**
|
|
410
|
+
* The path to the field to retrieve errors from.
|
|
411
|
+
*/
|
|
187
412
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
188
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
|
+
*/
|
|
189
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
|
+
*/
|
|
190
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;
|
|
191
435
|
//#endregion
|
|
192
436
|
//#region src/getInput/getInput.d.ts
|
|
437
|
+
/**
|
|
438
|
+
* Get form input config interface.
|
|
439
|
+
*/
|
|
193
440
|
interface GetFormInputConfig {
|
|
441
|
+
/**
|
|
442
|
+
* The path to a field. Leave undefined to get the entire form input.
|
|
443
|
+
*/
|
|
194
444
|
readonly path?: undefined;
|
|
195
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Get field input config interface.
|
|
448
|
+
*/
|
|
196
449
|
interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
450
|
+
/**
|
|
451
|
+
* The path to the field to retrieve input from.
|
|
452
|
+
*/
|
|
197
453
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
198
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
|
+
*/
|
|
199
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
|
+
*/
|
|
200
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>>;
|
|
201
474
|
//#endregion
|
|
202
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
|
+
*/
|
|
203
486
|
declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => void;
|
|
204
487
|
//#endregion
|
|
205
488
|
//#region src/insert/insert.d.ts
|
|
489
|
+
/**
|
|
490
|
+
* Insert array field config interface.
|
|
491
|
+
*/
|
|
206
492
|
interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
493
|
+
/**
|
|
494
|
+
* The path to the field array to insert into.
|
|
495
|
+
*/
|
|
207
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
|
+
*/
|
|
208
500
|
readonly at?: number | undefined;
|
|
501
|
+
/**
|
|
502
|
+
* The partial initial input value for the new item.
|
|
503
|
+
*/
|
|
209
504
|
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
|
|
210
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
|
+
*/
|
|
211
513
|
declare function insert<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
|
|
212
514
|
//#endregion
|
|
213
515
|
//#region src/move/move.d.ts
|
|
516
|
+
/**
|
|
517
|
+
* Move array field config interface.
|
|
518
|
+
*/
|
|
214
519
|
interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
520
|
+
/**
|
|
521
|
+
* The path to the field array to move an item within.
|
|
522
|
+
*/
|
|
215
523
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
524
|
+
/**
|
|
525
|
+
* The index of the item to move from.
|
|
526
|
+
*/
|
|
216
527
|
readonly from: number;
|
|
528
|
+
/**
|
|
529
|
+
* The index to move the item to.
|
|
530
|
+
*/
|
|
217
531
|
readonly to: number;
|
|
218
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
|
+
*/
|
|
219
540
|
declare function move<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: MoveConfig<TSchema, TFieldArrayPath>): void;
|
|
220
541
|
//#endregion
|
|
221
542
|
//#region src/remove/remove.d.ts
|
|
543
|
+
/**
|
|
544
|
+
* Remove array field config interface.
|
|
545
|
+
*/
|
|
222
546
|
interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
547
|
+
/**
|
|
548
|
+
* The path to the field array to remove an item from.
|
|
549
|
+
*/
|
|
223
550
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
551
|
+
/**
|
|
552
|
+
* The index of the item to remove.
|
|
553
|
+
*/
|
|
224
554
|
readonly at: number;
|
|
225
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
|
+
*/
|
|
226
563
|
declare function remove<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: RemoveConfig<TSchema, TFieldArrayPath>): void;
|
|
227
564
|
//#endregion
|
|
228
565
|
//#region src/replace/replace.d.ts
|
|
566
|
+
/**
|
|
567
|
+
* Replace array field config interface.
|
|
568
|
+
*/
|
|
229
569
|
interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
570
|
+
/**
|
|
571
|
+
* The path to the field array to replace an item within.
|
|
572
|
+
*/
|
|
230
573
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
574
|
+
/**
|
|
575
|
+
* The index of the item to replace.
|
|
576
|
+
*/
|
|
231
577
|
readonly at: number;
|
|
578
|
+
/**
|
|
579
|
+
* The partial initial input value for the replacement item.
|
|
580
|
+
*/
|
|
232
581
|
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
|
|
233
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
|
+
*/
|
|
234
589
|
declare function replace<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: ReplaceConfig<TSchema, TFieldArrayPath>): void;
|
|
235
590
|
//#endregion
|
|
236
591
|
//#region src/reset/reset.d.ts
|
|
592
|
+
/**
|
|
593
|
+
* Reset base config interface.
|
|
594
|
+
*/
|
|
237
595
|
interface ResetBaseConfig {
|
|
596
|
+
/**
|
|
597
|
+
* Whether to keep the current input values during reset. Defaults to false.
|
|
598
|
+
*/
|
|
238
599
|
readonly keepInput?: boolean | undefined;
|
|
600
|
+
/**
|
|
601
|
+
* Whether to keep the touched state during reset. Defaults to false.
|
|
602
|
+
*/
|
|
239
603
|
readonly keepTouched?: boolean | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* Whether to keep the error messages during reset. Defaults to false.
|
|
606
|
+
*/
|
|
240
607
|
readonly keepErrors?: boolean | undefined;
|
|
241
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* Reset form config interface.
|
|
611
|
+
*/
|
|
242
612
|
interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
|
|
613
|
+
/**
|
|
614
|
+
* The path to a field. Leave undefined to reset the entire form.
|
|
615
|
+
*/
|
|
243
616
|
readonly path?: undefined;
|
|
617
|
+
/**
|
|
618
|
+
* The new initial input to reset to. If provided, replaces the form's
|
|
619
|
+
* initial input.
|
|
620
|
+
*/
|
|
244
621
|
readonly initialInput?: DeepPartial<v.InferInput<TSchema>> | undefined;
|
|
245
|
-
|
|
622
|
+
/**
|
|
623
|
+
* Whether to keep the submitted state during reset. Defaults to false.
|
|
624
|
+
*/
|
|
246
625
|
readonly keepSubmitted?: boolean | undefined;
|
|
247
626
|
}
|
|
627
|
+
/**
|
|
628
|
+
* Reset field config interface.
|
|
629
|
+
*/
|
|
248
630
|
interface ResetFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
|
|
631
|
+
/**
|
|
632
|
+
* The path to the field to reset.
|
|
633
|
+
*/
|
|
249
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
|
+
*/
|
|
250
639
|
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, TFieldPath>>;
|
|
251
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
|
+
*/
|
|
252
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
|
+
*/
|
|
253
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;
|
|
254
658
|
//#endregion
|
|
255
659
|
//#region src/setErrors/setErrors.d.ts
|
|
660
|
+
/**
|
|
661
|
+
* Set form errors config interface.
|
|
662
|
+
*/
|
|
256
663
|
interface SetFormErrorsConfig {
|
|
664
|
+
/**
|
|
665
|
+
* The path to a field. Leave undefined to set form-level errors.
|
|
666
|
+
*/
|
|
257
667
|
readonly path?: undefined;
|
|
668
|
+
/**
|
|
669
|
+
* The error messages to set, or null to clear errors.
|
|
670
|
+
*/
|
|
258
671
|
readonly errors: [string, ...string[]] | null;
|
|
259
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* Set field errors config interface.
|
|
675
|
+
*/
|
|
260
676
|
interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
677
|
+
/**
|
|
678
|
+
* The path to the field to set errors on.
|
|
679
|
+
*/
|
|
261
680
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
681
|
+
/**
|
|
682
|
+
* The error messages to set, or null to clear errors.
|
|
683
|
+
*/
|
|
262
684
|
readonly errors: [string, ...string[]] | null;
|
|
263
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
|
+
*/
|
|
264
694
|
declare function setErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldErrorsConfig<TSchema, TFieldPath> : SetFormErrorsConfig): void;
|
|
265
695
|
//#endregion
|
|
266
696
|
//#region src/setInput/setInput.d.ts
|
|
697
|
+
/**
|
|
698
|
+
* Set form input config interface.
|
|
699
|
+
*/
|
|
267
700
|
interface SetFormInputConfig<TSchema extends Schema> {
|
|
701
|
+
/**
|
|
702
|
+
* The path to a field. Leave undefined to set the entire form input.
|
|
703
|
+
*/
|
|
268
704
|
readonly path?: undefined;
|
|
705
|
+
/**
|
|
706
|
+
* The input value to set for the form.
|
|
707
|
+
*/
|
|
269
708
|
readonly input: v.InferInput<TSchema>;
|
|
270
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* Set field input config interface.
|
|
712
|
+
*/
|
|
271
713
|
interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
714
|
+
/**
|
|
715
|
+
* The path to the field to set input on.
|
|
716
|
+
*/
|
|
272
717
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
718
|
+
/**
|
|
719
|
+
* The input value to set for the field.
|
|
720
|
+
*/
|
|
273
721
|
readonly input: PathValue<v.InferInput<TSchema>, TFieldPath>;
|
|
274
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
|
+
*/
|
|
275
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
|
+
*/
|
|
276
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;
|
|
277
741
|
//#endregion
|
|
278
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
|
+
*/
|
|
279
749
|
declare function submit(form: BaseFormStore): void;
|
|
280
750
|
//#endregion
|
|
281
751
|
//#region src/swap/swap.d.ts
|
|
752
|
+
/**
|
|
753
|
+
* Swap array field config interface.
|
|
754
|
+
*/
|
|
282
755
|
interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
756
|
+
/**
|
|
757
|
+
* The path to the field array to swap items within.
|
|
758
|
+
*/
|
|
283
759
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
760
|
+
/**
|
|
761
|
+
* The index of the first item to swap.
|
|
762
|
+
*/
|
|
284
763
|
readonly at: number;
|
|
764
|
+
/**
|
|
765
|
+
* The index of the second item to swap with the first.
|
|
766
|
+
*/
|
|
285
767
|
readonly and: number;
|
|
286
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
|
+
*/
|
|
287
775
|
declare function swap<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: SwapConfig<TSchema, TFieldArrayPath>): void;
|
|
288
776
|
//#endregion
|
|
289
777
|
//#region src/validate/validate.d.ts
|
|
778
|
+
/**
|
|
779
|
+
* Validate form config interface.
|
|
780
|
+
*/
|
|
290
781
|
interface ValidateFormConfig {
|
|
782
|
+
/**
|
|
783
|
+
* Whether to focus the first field with errors after validation. Defaults to false.
|
|
784
|
+
*/
|
|
291
785
|
readonly shouldFocus?: boolean | undefined;
|
|
292
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
|
+
*/
|
|
293
797
|
declare function validate<TSchema extends Schema>(form: BaseFormStore<TSchema>, config?: ValidateFormConfig): Promise<v.SafeParseResult<TSchema>>;
|
|
294
798
|
//#endregion
|
|
295
799
|
//#endregion
|
|
296
800
|
//#region src/types/field.d.ts
|
|
297
801
|
/**
|
|
298
|
-
*
|
|
802
|
+
* Field element props interface.
|
|
299
803
|
*/
|
|
300
804
|
interface FieldElementProps {
|
|
805
|
+
/**
|
|
806
|
+
* The name attribute of the field element.
|
|
807
|
+
*/
|
|
301
808
|
readonly name: string;
|
|
809
|
+
/**
|
|
810
|
+
* Whether to autofocus the field element when there are errors.
|
|
811
|
+
*/
|
|
302
812
|
readonly autofocus: boolean;
|
|
813
|
+
/**
|
|
814
|
+
* The ref callback to register the field element.
|
|
815
|
+
*/
|
|
303
816
|
readonly ref: (element: FieldElement) => void;
|
|
817
|
+
/**
|
|
818
|
+
* The focus event handler of the field element.
|
|
819
|
+
*/
|
|
304
820
|
readonly onFocus: JSX.EventHandler<FieldElement, FocusEvent>;
|
|
821
|
+
/**
|
|
822
|
+
* The input event handler of the field element.
|
|
823
|
+
*/
|
|
305
824
|
readonly onInput: JSX.EventHandler<FieldElement, InputEvent>;
|
|
825
|
+
/**
|
|
826
|
+
* The change event handler of the field element.
|
|
827
|
+
*/
|
|
306
828
|
readonly onChange: JSX.EventHandler<FieldElement, Event>;
|
|
829
|
+
/**
|
|
830
|
+
* The blur event handler of the field element.
|
|
831
|
+
*/
|
|
307
832
|
readonly onBlur: JSX.EventHandler<FieldElement, FocusEvent>;
|
|
308
833
|
}
|
|
309
834
|
/**
|
|
310
|
-
*
|
|
835
|
+
* Field store interface.
|
|
311
836
|
*/
|
|
312
837
|
interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
838
|
+
/**
|
|
839
|
+
* The path to the field within the form.
|
|
840
|
+
*/
|
|
313
841
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
842
|
+
/**
|
|
843
|
+
* The current input value of the field.
|
|
844
|
+
*/
|
|
314
845
|
readonly input: PartialValues<PathValue<v.InferInput<TSchema>, TFieldPath>>;
|
|
846
|
+
/**
|
|
847
|
+
* The current error messages of the field.
|
|
848
|
+
*/
|
|
315
849
|
readonly errors: [string, ...string[]] | null;
|
|
850
|
+
/**
|
|
851
|
+
* Whether the field has been touched.
|
|
852
|
+
*/
|
|
316
853
|
readonly isTouched: boolean;
|
|
854
|
+
/**
|
|
855
|
+
* Whether the field input differs from its initial value.
|
|
856
|
+
*/
|
|
317
857
|
readonly isDirty: boolean;
|
|
858
|
+
/**
|
|
859
|
+
* Whether the field is valid according to the schema.
|
|
860
|
+
*/
|
|
318
861
|
readonly isValid: boolean;
|
|
862
|
+
/**
|
|
863
|
+
* The props to spread onto the field element for integration.
|
|
864
|
+
*/
|
|
319
865
|
readonly props: FieldElementProps;
|
|
320
866
|
}
|
|
321
867
|
/**
|
|
322
|
-
*
|
|
868
|
+
* Field array store interface.
|
|
323
869
|
*/
|
|
324
870
|
interface FieldArrayStore<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
871
|
+
/**
|
|
872
|
+
* The path to the array field within the form.
|
|
873
|
+
*/
|
|
325
874
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
875
|
+
/**
|
|
876
|
+
* The item IDs of the array field.
|
|
877
|
+
*/
|
|
326
878
|
readonly items: string[];
|
|
879
|
+
/**
|
|
880
|
+
* The current error messages of the field array.
|
|
881
|
+
*/
|
|
327
882
|
readonly errors: [string, ...string[]] | null;
|
|
883
|
+
/**
|
|
884
|
+
* Whether the field array has been touched.
|
|
885
|
+
*/
|
|
328
886
|
readonly isTouched: boolean;
|
|
887
|
+
/**
|
|
888
|
+
* Whether the field array input differs from its initial value.
|
|
889
|
+
*/
|
|
329
890
|
readonly isDirty: boolean;
|
|
891
|
+
/**
|
|
892
|
+
* Whether the field array is valid according to the schema.
|
|
893
|
+
*/
|
|
330
894
|
readonly isValid: boolean;
|
|
331
895
|
}
|
|
332
896
|
//#endregion
|
|
333
897
|
//#region src/types/form.d.ts
|
|
898
|
+
/**
|
|
899
|
+
* Form store interface.
|
|
900
|
+
*/
|
|
334
901
|
interface FormStore<TSchema extends Schema = Schema> extends BaseFormStore<TSchema> {
|
|
902
|
+
/**
|
|
903
|
+
* Whether the form is currently submitting.
|
|
904
|
+
*/
|
|
335
905
|
readonly isSubmitting: boolean;
|
|
906
|
+
/**
|
|
907
|
+
* Whether the form has been submitted.
|
|
908
|
+
*/
|
|
336
909
|
readonly isSubmitted: boolean;
|
|
910
|
+
/**
|
|
911
|
+
* Whether the form is currently validating.
|
|
912
|
+
*/
|
|
337
913
|
readonly isValidating: boolean;
|
|
914
|
+
/**
|
|
915
|
+
* Whether any field in the form has been touched.
|
|
916
|
+
*/
|
|
338
917
|
readonly isTouched: boolean;
|
|
918
|
+
/**
|
|
919
|
+
* Whether any field in the form differs from its initial value.
|
|
920
|
+
*/
|
|
339
921
|
readonly isDirty: boolean;
|
|
922
|
+
/**
|
|
923
|
+
* Whether the form is valid according to the schema.
|
|
924
|
+
*/
|
|
340
925
|
readonly isValid: boolean;
|
|
926
|
+
/**
|
|
927
|
+
* The current error messages of the form.
|
|
928
|
+
*
|
|
929
|
+
* Hint: This property only contains validation errors at the root level
|
|
930
|
+
* of the form. To get all errors from all fields, use `getAllErrors`.
|
|
931
|
+
*/
|
|
341
932
|
readonly errors: [string, ...string[]] | null;
|
|
342
933
|
}
|
|
343
934
|
//#endregion
|
|
@@ -349,53 +940,139 @@ type MaybeGetter<TValue> = TValue | (() => TValue);
|
|
|
349
940
|
//#endregion
|
|
350
941
|
//#region src/components/Field/Field.d.ts
|
|
351
942
|
/**
|
|
352
|
-
*
|
|
943
|
+
* Field component props interface.
|
|
353
944
|
*/
|
|
354
945
|
interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
946
|
+
/**
|
|
947
|
+
* The form store to which the field belongs.
|
|
948
|
+
*/
|
|
355
949
|
readonly of: FormStore<TSchema>;
|
|
950
|
+
/**
|
|
951
|
+
* The path to the field within the form schema.
|
|
952
|
+
*/
|
|
356
953
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
954
|
+
/**
|
|
955
|
+
* The render function that receives the field store and returns JSX.
|
|
956
|
+
*/
|
|
357
957
|
readonly children: (store: FieldStore<TSchema, TFieldPath>) => JSX.Element;
|
|
358
958
|
}
|
|
359
959
|
/**
|
|
360
|
-
* Headless form field that provides reactive properties and state.
|
|
960
|
+
* Headless form field component that provides reactive properties and state.
|
|
961
|
+
* The field component takes a form store, path to field, and a render function
|
|
962
|
+
* that receives a field store to display field state and handle user interactions.
|
|
963
|
+
*
|
|
964
|
+
* @param props The field component props.
|
|
965
|
+
*
|
|
966
|
+
* @returns The UI of the field to be rendered.
|
|
361
967
|
*/
|
|
362
968
|
declare function Field<TSchema extends Schema, TFieldPath extends RequiredPath>(props: FieldProps<TSchema, TFieldPath>): JSX.Element;
|
|
363
969
|
//#endregion
|
|
364
970
|
//#region src/components/FieldArray/FieldArray.d.ts
|
|
365
971
|
/**
|
|
366
|
-
*
|
|
972
|
+
* FieldArray component props interface.
|
|
367
973
|
*/
|
|
368
974
|
interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
975
|
+
/**
|
|
976
|
+
* The form store to which the field array belongs.
|
|
977
|
+
*/
|
|
369
978
|
readonly of: FormStore<TSchema>;
|
|
979
|
+
/**
|
|
980
|
+
* The path to the field array within the form schema.
|
|
981
|
+
*/
|
|
370
982
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
983
|
+
/**
|
|
984
|
+
* The render function that receives the field array store and returns JSX.
|
|
985
|
+
*/
|
|
371
986
|
readonly children: (store: FieldArrayStore<TSchema, TFieldArrayPath>) => JSX.Element;
|
|
372
987
|
}
|
|
373
988
|
/**
|
|
374
|
-
* Headless field array that provides reactive properties and state.
|
|
989
|
+
* Headless field array that provides reactive properties and state. The field array
|
|
990
|
+
* component takes a form store, path to array field, and a render function that receives
|
|
991
|
+
* a field array store to manage array items and handle array operations.
|
|
992
|
+
*
|
|
993
|
+
* @param props The field array component props.
|
|
994
|
+
*
|
|
995
|
+
* @returns The UI of the field array to be rendered.
|
|
375
996
|
*/
|
|
376
997
|
declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(props: FieldArrayProps<TSchema, TFieldArrayPath>): JSX.Element;
|
|
377
998
|
//#endregion
|
|
378
999
|
//#region src/components/Form/Form.d.ts
|
|
1000
|
+
/**
|
|
1001
|
+
* Form component props type.
|
|
1002
|
+
*/
|
|
379
1003
|
type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "novalidate" | "noValidate"> & {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
1004
|
+
/**
|
|
1005
|
+
* The form store instance.
|
|
1006
|
+
*/
|
|
1007
|
+
readonly of: FormStore<TSchema>;
|
|
1008
|
+
/**
|
|
1009
|
+
* The child elements to render within the form.
|
|
1010
|
+
*/
|
|
1011
|
+
readonly children: JSX.Element;
|
|
1012
|
+
/**
|
|
1013
|
+
* The submit handler called when the form is submitted and validation succeeds.
|
|
1014
|
+
*/
|
|
1015
|
+
readonly onSubmit: SubmitHandler<TSchema>;
|
|
383
1016
|
};
|
|
1017
|
+
/**
|
|
1018
|
+
* Form component that manages form submission and applies internal state.
|
|
1019
|
+
* Wraps form element and passes submission events to the provided handler.
|
|
1020
|
+
*
|
|
1021
|
+
* @param props The form component props.
|
|
1022
|
+
*
|
|
1023
|
+
* @returns The a native form element.
|
|
1024
|
+
*/
|
|
384
1025
|
declare function Form<TSchema extends Schema>(props: FormProps<TSchema>): JSX.Element;
|
|
385
1026
|
//#endregion
|
|
386
1027
|
//#region src/primitives/createForm/createForm.d.ts
|
|
1028
|
+
/**
|
|
1029
|
+
* Creates a reactive form store from a form configuration. The form store
|
|
1030
|
+
* manages form state and provides reactive properties.
|
|
1031
|
+
*
|
|
1032
|
+
* @param config The form configuration.
|
|
1033
|
+
*
|
|
1034
|
+
* @returns The form store with reactive properties.
|
|
1035
|
+
*/
|
|
387
1036
|
declare function createForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
|
|
388
1037
|
//#endregion
|
|
389
1038
|
//#region src/primitives/useField/useField.d.ts
|
|
1039
|
+
/**
|
|
1040
|
+
* Use field config interface.
|
|
1041
|
+
*/
|
|
390
1042
|
interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
1043
|
+
/**
|
|
1044
|
+
* The path to the field within the form schema.
|
|
1045
|
+
*/
|
|
391
1046
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
392
1047
|
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Creates a reactive field store of a specific field within a form store.
|
|
1050
|
+
*
|
|
1051
|
+
* @param form The form store instance.
|
|
1052
|
+
* @param config The field configuration.
|
|
1053
|
+
*
|
|
1054
|
+
* @returns The field store with reactive properties and element props.
|
|
1055
|
+
*/
|
|
393
1056
|
declare function useField<TSchema extends Schema, TFieldPath extends RequiredPath>(form: MaybeGetter<FormStore<TSchema>>, config: MaybeGetter<UseFieldConfig<TSchema, TFieldPath>>): FieldStore<TSchema, TFieldPath>;
|
|
394
1057
|
//#endregion
|
|
395
1058
|
//#region src/primitives/useFieldArray/useFieldArray.d.ts
|
|
1059
|
+
/**
|
|
1060
|
+
* Use field array config interface.
|
|
1061
|
+
*/
|
|
396
1062
|
interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
1063
|
+
/**
|
|
1064
|
+
* The path to the field array within the form schema.
|
|
1065
|
+
*/
|
|
397
1066
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
398
1067
|
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Creates a reactive field array store of a specific field array within a form store.
|
|
1070
|
+
*
|
|
1071
|
+
* @param form The form store instance.
|
|
1072
|
+
* @param config The field array configuration.
|
|
1073
|
+
*
|
|
1074
|
+
* @returns The field array store with reactive properties for array management.
|
|
1075
|
+
*/
|
|
399
1076
|
declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: MaybeGetter<FormStore<TSchema>>, config: MaybeGetter<UseFieldArrayConfig<TSchema, TFieldArrayPath>>): FieldArrayStore<TSchema, TFieldArrayPath>;
|
|
400
1077
|
//#endregion
|
|
401
1078
|
export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MaybeGetter, 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, createForm, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, validate };
|