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