@formisch/preact 0.10.0 → 0.12.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/dist/index.d.ts CHANGED
@@ -4,6 +4,177 @@ import { FocusEventHandler, FormHTMLAttributes, GenericEventHandler, InputEventH
4
4
 
5
5
  //#region ../../packages/core/dist/index.preact.d.ts
6
6
 
7
+ //#region src/types/utils/utils.d.ts
8
+ /**
9
+ * Checks if a type is `any`.
10
+ */
11
+ type IsAny<T> = 0 extends 1 & T ? true : false;
12
+ /**
13
+ * Checks if a type is `never`.
14
+ */
15
+ type IsNever<T> = [T] extends [never] ? true : false;
16
+ /**
17
+ * Constructs a type that is maybe a promise.
18
+ */
19
+ type MaybePromise<T> = T | Promise<T>;
20
+ /**
21
+ * Makes all properties deeply optional.
22
+ */
23
+ type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [TKey in keyof TValue]?: DeepPartial<TValue[TKey]> | undefined } : TValue | undefined;
24
+ /**
25
+ * Makes all value properties optional.
26
+ *
27
+ * Hint: For dynamic arrays, only plain objects and nested arrays have their
28
+ * values made optional. Primitives and class instances are kept as-is to avoid
29
+ * types like `(string | undefined)[]`.
30
+ */
31
+ type PartialValues<TValue> = TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? (TItem extends Record<PropertyKey, unknown> | readonly unknown[] ? { [TKey in keyof TItem]: PartialValues<TItem[TKey]> } : TItem)[] : { [TKey in keyof TValue]: PartialValues<TValue[TKey]> } : TValue extends Record<PropertyKey, unknown> ? { [TKey in keyof TValue]: PartialValues<TValue[TKey]> } : TValue | undefined;
32
+ //#endregion
33
+ //#region src/types/path/path.d.ts
34
+ /**
35
+ * Path key type.
36
+ */
37
+ type PathKey = string | number;
38
+ /**
39
+ * Path type.
40
+ */
41
+ type Path = readonly PathKey[];
42
+ /**
43
+ * Required path type.
44
+ */
45
+ type RequiredPath = readonly [PathKey, ...Path];
46
+ /**
47
+ * Extracts the exact keys of a tuple, array or object. Tuples return their
48
+ * literal numeric indices, dynamic arrays return `number`, objects return
49
+ * their `keyof` keys, and any other input returns `never`.
50
+ */
51
+ type ExactKeysOf<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<PropertyKey, unknown> ? keyof TValue & PathKey : never;
52
+ /**
53
+ * Returns the flat object of all indexable properties of `TValue`. For object
54
+ * unions, properties from every member are merged so that any single property
55
+ * is accessible. For primitives and other non-indexable types, the result is
56
+ * `{}`.
57
+ *
58
+ * Hint: This is necessary to make properties accessible across union members.
59
+ * By default, properties that do not exist in all union options are not
60
+ * accessible and result in "any" when accessed.
61
+ */
62
+ type PropertiesOf<TValue> = { [TKey in ExactKeysOf<TValue>]: TValue extends Record<TKey, infer TItem> ? TItem : never };
63
+ /**
64
+ * Lazily evaluates only the first valid path segment based on the given value.
65
+ */
66
+ type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends ExactKeysOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<Required<PropertiesOf<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<ExactKeysOf<TValue>> extends false ? readonly [...TValidPath, ExactKeysOf<TValue>] : TValidPath;
67
+ /**
68
+ * Returns the path if valid, otherwise the first possible valid path based on
69
+ * the given value.
70
+ */
71
+ type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<Required<TValue>, TPath> ? TPath : LazyPath<Required<TValue>, TPath>;
72
+ /**
73
+ * Detects whether the consuming project is configured with
74
+ * `exactOptionalPropertyTypes: true`.
75
+ *
76
+ * Hint: If `false` the built-in `Required<T>` strips `| undefined` from
77
+ * optional properties, so `Required<{ key?: undefined }>['key']` collapses
78
+ * to `never` — under strict mode the same expression yields `undefined`.
79
+ */
80
+ type IsExactOptionalProps = Required<{
81
+ key?: undefined;
82
+ }>["key"] extends never ? false : true;
83
+ /**
84
+ * Like the built-in `Required<T>`, but preserves `| undefined` in two
85
+ * places where `Required<T>` strips it:
86
+ *
87
+ * 1. Optional property values under `exactOptionalPropertyTypes: false`
88
+ * — without this, input typings for `v.optional`/`v.nullish` schemas
89
+ * narrow incorrectly (issue #15).
90
+ * 2. Array/tuple element types — e.g. `(string | undefined)[]` stays
91
+ * `(string | undefined)[]` instead of becoming `string[]`. Arrays
92
+ * fall through unchanged because they only have a numeric index
93
+ * signature and don't structurally extend `Record<PropertyKey,
94
+ * unknown>` (which requires string keys).
95
+ */
96
+ type ExactRequired<TValue> = TValue extends Record<PropertyKey, unknown> ? IsExactOptionalProps extends true ? Required<TValue> : { [TKey in keyof Required<TValue>]: TValue[TKey] } : TValue;
97
+ /**
98
+ * Extracts the value type at the given path.
99
+ */
100
+ type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends ExactKeysOf<ExactRequired<TValue>> ? PathValue<PropertiesOf<ExactRequired<TValue>>[TKey], TRest> : unknown : TValue;
101
+ /**
102
+ * Checks whether a value is a dynamic array or contains one anywhere in its
103
+ * shape. A fixed-length tuple is not itself a dynamic array, but it counts when
104
+ * it contains one, so paths can still navigate through tuples to reach nested
105
+ * arrays.
106
+ *
107
+ * Hint: The inner conditionals (`TValue extends readonly unknown[]` and
108
+ * `TValue extends Record<PropertyKey, unknown>`) distribute over union members,
109
+ * so the inner expression returns the union of each member's result (e.g.
110
+ * `true | false` when some members contain arrays and others don't).
111
+ * Downstream code uses `IsOrHasArray<T> extends true`, but
112
+ * `boolean extends true` is `false` — so we collapse the result via
113
+ * `true extends ...`, which is `true` whenever at least one union member
114
+ * contributed `true`.
115
+ */
116
+ type IsOrHasArray<TValue> = true extends (IsAny<TValue> extends true ? false : TValue extends readonly unknown[] ? number extends TValue["length"] ? true : IsOrHasArray<TValue[number]> : TValue extends Record<PropertyKey, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<TValue[TKey]> }[keyof TValue] : false) ? true : false;
117
+ /**
118
+ * Extracts the exact keys of a tuple, array or object that contain arrays.
119
+ */
120
+ type ExactKeysOfArrayPath<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<PropertyKey, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TKey : never }[keyof TValue] & PathKey : never;
121
+ /**
122
+ * Returns the flat object of indexable properties of `TValue` whose values
123
+ * are or contain arrays. Mirrors `PropertiesOf` but keyed by
124
+ * `ExactKeysOfArrayPath` so the lookup is provably valid for array-path
125
+ * navigation in `LazyArrayPath`.
126
+ */
127
+ type PropertiesOfArrayPath<TValue> = { [TKey in ExactKeysOfArrayPath<TValue>]: TValue extends Record<TKey, infer TItem> ? TItem : never };
128
+ /**
129
+ * Lazily evaluates only the first valid array path segment based on the given value.
130
+ */
131
+ type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? number extends TValue["length"] ? TValidPath : IsNever<ExactKeysOfArrayPath<TValue>> extends false ? readonly [...TValidPath, ExactKeysOfArrayPath<TValue>] : never : readonly [...TValidPath, ExactKeysOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends ExactKeysOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<Required<PropertiesOfArrayPath<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<ExactKeysOfArrayPath<TValue>> extends false ? readonly [...TValidPath, ExactKeysOfArrayPath<TValue>] : never;
132
+ /**
133
+ * Returns the path if valid, otherwise the first possible valid array path
134
+ * based on the given value.
135
+ */
136
+ type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
137
+ /**
138
+ * Recursive helper for `DirtyPath` that prepends `TKey` to each deeper path,
139
+ * or falls through to `never` when the child is not an object.
140
+ */
141
+ type DeepDirtyPath<TChild, TKey$1 extends PathKey, TDepth extends 0[]> = TChild extends Record<PropertyKey, unknown> ? readonly [TKey$1, ...DirtyPath<TChild, [...TDepth, 0]>] : never;
142
+ /**
143
+ * Returns the union of all `RequiredPath`s that `getDirtyPaths` can emit
144
+ * for a given input type. Object fields contribute their own path and the
145
+ * paths of their descendants; arrays and tuples are atomic and contribute
146
+ * only their own path, because dirty arrays are returned as complete units.
147
+ *
148
+ * Narrowing is exact for the first 5 levels of nesting; deeper paths fall
149
+ * back to `RequiredPath` to keep the result a complete superset of any
150
+ * path the runtime can address.
151
+ *
152
+ * Hint: Arrays and tuples are atomic because they don't structurally
153
+ * extend `Record<PropertyKey, unknown>` and so fall through to `never`
154
+ * via `DeepDirtyPath` — no explicit array check is needed. `TDepth` is
155
+ * a tuple-length counter capped at 5 to bound TypeScript instantiation
156
+ * cost.
157
+ */
158
+ type DirtyPath<TValue, TDepth extends 0[] = []> = TDepth["length"] extends 5 ? RequiredPath : TValue extends Record<PropertyKey, unknown> ? { [TKey in ExactKeysOf<TValue>]: readonly [TKey] | DeepDirtyPath<NonNullable<PropertiesOf<TValue>[TKey]>, TKey, TDepth> }[ExactKeysOf<TValue>] : never;
159
+ /**
160
+ * Recursive helper for `FieldPath` that prepends `TKey` to each deeper field
161
+ * path, or falls through to `never` when the child is a leaf value.
162
+ */
163
+ type DeepFieldPath<TChild, TKey$1 extends PathKey, TDepth extends 0[]> = TChild extends readonly unknown[] | Record<PropertyKey, unknown> ? readonly [TKey$1, ...FieldPath<TChild, [...TDepth, 0]>] : never;
164
+ /**
165
+ * Returns the union of all `RequiredPath`s that address a field within the
166
+ * given input type. Object and array fields contribute their own path and the
167
+ * paths of their descendants; unlike `DirtyPath`, arrays are recursed into so
168
+ * that fields at any depth, including array items, can be addressed. Leaf
169
+ * values contribute only their own path (emitted by their parent).
170
+ *
171
+ * Narrowing is exact for the first 5 levels of nesting; deeper paths fall
172
+ * back to `RequiredPath` to keep the result a complete superset of any path
173
+ * the runtime can address. `TDepth` is a tuple-length counter capped at 5 to
174
+ * bound TypeScript instantiation cost.
175
+ */
176
+ type FieldPath<TValue, TDepth extends 0[] = []> = TDepth["length"] extends 5 ? RequiredPath : TValue extends readonly unknown[] | Record<PropertyKey, unknown> ? { [TKey in ExactKeysOf<TValue>]: readonly [TKey] | DeepFieldPath<NonNullable<PropertiesOf<TValue>[TKey]>, TKey, TDepth> }[ExactKeysOf<TValue>] : never;
177
+ //#endregion
7
178
  //#region src/types/schema/schema.d.ts
8
179
  /**
9
180
  * Schema type.
@@ -59,11 +230,22 @@ interface InternalBaseStore {
59
230
  */
60
231
  name: string;
61
232
  /**
233
+ * The path to the field.
234
+ */
235
+ path: Path;
236
+ /**
62
237
  * The schema of the field.
63
238
  */
64
239
  schema: Schema;
65
240
  /**
66
241
  * The initial elements of the field.
242
+ *
243
+ * Hint: This may look unused, but do not remove it. `copyItemState` and
244
+ * `swapItemState` move the `elements` reference between field stores when
245
+ * array items are inserted, moved, removed or swapped, and `reset` restores
246
+ * each field's original element via `elements = initialElements`. Without it,
247
+ * focus and file reset target the wrong element after a reorder followed by a
248
+ * reset.
67
249
  */
68
250
  initialElements: FieldElement[];
69
251
  /**
@@ -79,6 +261,15 @@ interface InternalBaseStore {
79
261
  */
80
262
  isTouched: Signal<boolean>;
81
263
  /**
264
+ * The edited state of the field.
265
+ *
266
+ * Hint: Unlike `isTouched`, which is also set when a field is focused, this
267
+ * is only set when the field's value is changed. Unlike `isDirty`, it stays
268
+ * `true` even if the value is changed back to its initial value. It is only
269
+ * reset when the field is reset.
270
+ */
271
+ isEdited: Signal<boolean>;
272
+ /**
82
273
  * The dirty state of the field.
83
274
  */
84
275
  isDirty: Signal<boolean>;
@@ -92,6 +283,14 @@ interface InternalArrayStore extends InternalBaseStore {
92
283
  */
93
284
  kind: "array";
94
285
  /**
286
+ * Whether the array schema is wrapped in a nullish schema.
287
+ *
288
+ * Hint: This indicates whether a missing input should be represented as the
289
+ * nullish value (`null`/`undefined`) or as a present but empty array
290
+ * (`true`). It keeps resetting consistent with the initial state.
291
+ */
292
+ isNullish: boolean;
293
+ /**
95
294
  * The children of the array field.
96
295
  */
97
296
  children: InternalFieldStore[];
@@ -144,6 +343,14 @@ interface InternalObjectStore extends InternalBaseStore {
144
343
  */
145
344
  kind: "object";
146
345
  /**
346
+ * Whether the object schema is wrapped in a nullish schema.
347
+ *
348
+ * Hint: This indicates whether a missing input should be represented as the
349
+ * nullish value (`null`/`undefined`) or as a present but empty object
350
+ * (`true`). It keeps resetting consistent with the initial state.
351
+ */
352
+ isNullish: boolean;
353
+ /**
147
354
  * The children of the object field.
148
355
  */
149
356
  children: Record<string, InternalFieldStore>;
@@ -207,32 +414,6 @@ type InternalFieldStore = InternalArrayStore | InternalObjectStore | InternalVal
207
414
  */
208
415
  declare const INTERNAL: "~internal";
209
416
  //#endregion
210
- //#region src/types/utils/utils.d.ts
211
- /**
212
- * Checks if a type is `any`.
213
- */
214
- type IsAny<T> = 0 extends 1 & T ? true : false;
215
- /**
216
- * Checks if a type is `never`.
217
- */
218
- type IsNever<T> = [T] extends [never] ? true : false;
219
- /**
220
- * Constructs a type that is maybe a promise.
221
- */
222
- type MaybePromise<T> = T | Promise<T>;
223
- /**
224
- * Makes all properties deeply optional.
225
- */
226
- type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [TKey in keyof TValue]?: DeepPartial<TValue[TKey]> | undefined } : TValue | undefined;
227
- /**
228
- * Makes all value properties optional.
229
- *
230
- * Hint: For dynamic arrays, only plain objects and nested arrays have their
231
- * values made optional. Primitives and class instances are kept as-is to avoid
232
- * types like `(string | undefined)[]`.
233
- */
234
- type PartialValues<TValue> = TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? (TItem extends Record<PropertyKey, unknown> | readonly unknown[] ? { [TKey in keyof TItem]: PartialValues<TItem[TKey]> } : TItem)[] : { [TKey in keyof TValue]: PartialValues<TValue[TKey]> } : TValue extends Record<PropertyKey, unknown> ? { [TKey in keyof TValue]: PartialValues<TValue[TKey]> } : TValue | undefined;
235
- //#endregion
236
417
  //#region src/types/form/form.d.ts
237
418
  /**
238
419
  * Validation mode type.
@@ -316,174 +497,138 @@ type SubmitHandler<TSchema extends FormSchema> = (output: v.InferOutput<TSchema>
316
497
  */
317
498
  type SubmitEventHandler<TSchema extends FormSchema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
318
499
  //#endregion
319
- //#region src/types/path/path.d.ts
320
- /**
321
- * Path key type.
322
- */
323
- type PathKey = string | number;
324
- /**
325
- * Path type.
326
- */
327
- type Path = readonly PathKey[];
500
+ //#region src/array/copyItemState/copyItemState.d.ts
328
501
  /**
329
- * Required path type.
502
+ * Copies the deeply nested state (signal values) from one field store to
503
+ * another. This includes the `elements`, `errors`, `startInput`, `input`,
504
+ * `isTouched`, `isEdited`, `isDirty`, and for arrays `startItems` and `items`
505
+ * properties. Recursively walks through the field stores and copies all signal
506
+ * values.
507
+ *
508
+ * @param fromInternalFieldStore The source field store to copy from.
509
+ * @param toInternalFieldStore The destination field store to copy to.
330
510
  */
331
- type RequiredPath = readonly [PathKey, ...Path];
511
+ //#endregion
512
+ //#region ../../packages/methods/dist/index.preact.d.ts
513
+ //#region src/focus/focus.d.ts
514
+
332
515
  /**
333
- * Extracts the exact keys of a tuple, array or object. Tuples return their
334
- * literal numeric indices, dynamic arrays return `number`, objects return
335
- * their `keyof` keys, and any other input returns `never`.
516
+ * Focus field config interface.
336
517
  */
337
- type ExactKeysOf<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<PropertyKey, unknown> ? keyof TValue & PathKey : never;
518
+ interface FocusFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
519
+ /**
520
+ * The path to the field to focus.
521
+ */
522
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
523
+ }
338
524
  /**
339
- * Returns the flat object of all indexable properties of `TValue`. For object
340
- * unions, properties from every member are merged so that any single property
341
- * is accessible. For primitives and other non-indexable types, the result is
342
- * `{}`.
525
+ * Focuses the first focusable input element of a field. This is useful for
526
+ * programmatically setting focus to a specific field, such as after
527
+ * validation errors or user interactions.
343
528
  *
344
- * Hint: This is necessary to make properties accessible across union members.
345
- * By default, properties that do not exist in all union options are not
346
- * accessible and result in "any" when accessed.
529
+ * @param form The form store containing the field.
530
+ * @param config The focus field configuration.
347
531
  */
348
- type PropertiesOf<TValue> = { [TKey in ExactKeysOf<TValue>]: TValue extends Record<TKey, infer TItem> ? TItem : never };
532
+ declare function focus<TSchema extends FormSchema, TFieldPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: FocusFieldConfig<TSchema, TFieldPath>): void;
533
+ //#endregion
534
+ //#region src/getDeepErrorEntries/getDeepErrorEntries.d.ts
349
535
  /**
350
- * Lazily evaluates only the first valid path segment based on the given value.
536
+ * Deep error entry interface.
351
537
  */
352
- type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends ExactKeysOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<Required<PropertiesOf<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<ExactKeysOf<TValue>> extends false ? readonly [...TValidPath, ExactKeysOf<TValue>] : TValidPath;
538
+ interface DeepErrorEntry<TValue = unknown> {
539
+ /**
540
+ * The path to the field with errors, or an empty path for form-level errors.
541
+ */
542
+ readonly path: unknown extends TValue ? Path : readonly [] | FieldPath<TValue>;
543
+ /**
544
+ * The error messages of the field.
545
+ */
546
+ readonly errors: [string, ...string[]];
547
+ }
353
548
  /**
354
- * Returns the path if valid, otherwise the first possible valid path based on
355
- * the given value.
549
+ * Get form deep error entries config interface.
356
550
  */
357
- type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<Required<TValue>, TPath> ? TPath : LazyPath<Required<TValue>, TPath>;
551
+ interface GetFormDeepErrorEntriesConfig {
552
+ /**
553
+ * The path to a field. Leave undefined to get the entries of the entire form.
554
+ */
555
+ readonly path?: undefined;
556
+ }
358
557
  /**
359
- * Detects whether the consuming project is configured with
360
- * `exactOptionalPropertyTypes: true`.
361
- *
362
- * Hint: If `false` the built-in `Required<T>` strips `| undefined` from
363
- * optional properties, so `Required<{ key?: undefined }>['key']` collapses
364
- * to `never` — under strict mode the same expression yields `undefined`.
558
+ * Get field deep error entries config interface.
365
559
  */
366
- type IsExactOptionalProps = Required<{
367
- key?: undefined;
368
- }>["key"] extends never ? false : true;
560
+ interface GetFieldDeepErrorEntriesConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
561
+ /**
562
+ * The path to the field to retrieve the entries from.
563
+ */
564
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
565
+ }
369
566
  /**
370
- * Like the built-in `Required<T>`, but preserves `| undefined` in two
371
- * places where `Required<T>` strips it:
567
+ * Retrieves the errors of a specific field or the entire form as a list of
568
+ * entries, each pairing the path to a field with its error messages. This is
569
+ * useful for building custom error summaries that link each message back to
570
+ * its field. Form-level errors are included with an empty path.
372
571
  *
373
- * 1. Optional property values under `exactOptionalPropertyTypes: false`
374
- * — without this, input typings for `v.optional`/`v.nullish` schemas
375
- * narrow incorrectly (issue #15).
376
- * 2. Array/tuple element types — e.g. `(string | undefined)[]` stays
377
- * `(string | undefined)[]` instead of becoming `string[]`. Arrays
378
- * fall through unchanged because they only have a numeric index
379
- * signature and don't structurally extend `Record<PropertyKey,
380
- * unknown>` (which requires string keys).
381
- */
382
- type ExactRequired<TValue> = TValue extends Record<PropertyKey, unknown> ? IsExactOptionalProps extends true ? Required<TValue> : { [TKey in keyof Required<TValue>]: TValue[TKey] } : TValue;
383
- /**
384
- * Extracts the value type at the given path.
385
- */
386
- type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends ExactKeysOf<ExactRequired<TValue>> ? PathValue<PropertiesOf<ExactRequired<TValue>>[TKey], TRest> : unknown : TValue;
387
- /**
388
- * Checks whether a value is an array or contains one anywhere in its shape.
572
+ * @param form The form store to retrieve error entries from.
389
573
  *
390
- * Hint: The inner conditionals (`TValue extends readonly unknown[]` and
391
- * `TValue extends Record<PropertyKey, unknown>`) distribute over union members,
392
- * so the inner expression returns the union of each member's result (e.g.
393
- * `true | false` when some members contain arrays and others don't).
394
- * Downstream code uses `IsOrHasArray<T> extends true`, but
395
- * `boolean extends true` is `false` — so we collapse the result via
396
- * `true extends ...`, which is `true` whenever at least one union member
397
- * contributed `true`.
398
- */
399
- type IsOrHasArray<TValue> = true extends (IsAny<TValue> extends true ? false : TValue extends readonly unknown[] ? true : TValue extends Record<PropertyKey, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<TValue[TKey]> }[keyof TValue] : false) ? true : false;
400
- /**
401
- * Extracts the exact keys of a tuple, array or object that contain arrays.
574
+ * @returns A list of path and error message entries.
402
575
  */
403
- type ExactKeysOfArrayPath<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<PropertyKey, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TKey : never }[keyof TValue] & PathKey : never;
404
- /**
405
- * Returns the flat object of indexable properties of `TValue` whose values
406
- * are or contain arrays. Mirrors `PropertiesOf` but keyed by
407
- * `ExactKeysOfArrayPath` so the lookup is provably valid for array-path
408
- * navigation in `LazyArrayPath`.
409
- */
410
- type PropertiesOfArrayPath<TValue> = { [TKey in ExactKeysOfArrayPath<TValue>]: TValue extends Record<TKey, infer TItem> ? TItem : never };
411
- /**
412
- * Lazily evaluates only the first valid array path segment based on the given value.
413
- */
414
- type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? TValidPath : readonly [...TValidPath, ExactKeysOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends ExactKeysOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<Required<PropertiesOfArrayPath<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<ExactKeysOfArrayPath<TValue>> extends false ? readonly [...TValidPath, ExactKeysOfArrayPath<TValue>] : never;
576
+ declare function getDeepErrorEntries<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): DeepErrorEntry<v.InferInput<TSchema>>[];
415
577
  /**
416
- * Returns the path if valid, otherwise the first possible valid array path
417
- * based on the given value.
418
- */
419
- type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
420
- /**
421
- * Recursive helper for `DirtyPath` that prepends `TKey` to each deeper path,
422
- * or falls through to `never` when the child is not an object.
423
- */
424
- type DeepDirtyPath<TChild, TKey$1 extends PathKey, TDepth extends 0[]> = TChild extends Record<PropertyKey, unknown> ? readonly [TKey$1, ...DirtyPath<TChild, [...TDepth, 0]>] : never;
425
- /**
426
- * Returns the union of all `RequiredPath`s that `getDirtyPaths` can emit
427
- * for a given input type. Object fields contribute their own path and the
428
- * paths of their descendants; arrays and tuples are atomic and contribute
429
- * only their own path, because dirty arrays are returned as complete units.
578
+ * Retrieves the errors of a specific field or the entire form as a list of
579
+ * entries, each pairing the path to a field with its error messages. This is
580
+ * useful for building custom error summaries that link each message back to
581
+ * its field. Form-level errors are included with an empty path.
430
582
  *
431
- * Narrowing is exact for the first 5 levels of nesting; deeper paths fall
432
- * back to `RequiredPath` to keep the result a complete superset of any
433
- * path the runtime can address.
583
+ * @param form The form store to retrieve error entries from.
584
+ * @param config The get deep error entries configuration.
434
585
  *
435
- * Hint: Arrays and tuples are atomic because they don't structurally
436
- * extend `Record<PropertyKey, unknown>` and so fall through to `never`
437
- * via `DeepDirtyPath` — no explicit array check is needed. `TDepth` is
438
- * a tuple-length counter capped at 5 to bound TypeScript instantiation
439
- * cost.
586
+ * @returns A list of path and error message entries.
440
587
  */
441
- type DirtyPath<TValue, TDepth extends 0[] = []> = TDepth["length"] extends 5 ? RequiredPath : TValue extends Record<PropertyKey, unknown> ? { [TKey in ExactKeysOf<TValue>]: readonly [TKey] | DeepDirtyPath<NonNullable<PropertiesOf<TValue>[TKey]>, TKey, TDepth> }[ExactKeysOf<TValue>] : never;
588
+ declare function getDeepErrorEntries<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldDeepErrorEntriesConfig<TSchema, TFieldPath> : GetFormDeepErrorEntriesConfig): DeepErrorEntry<v.InferInput<TSchema>>[];
442
589
  //#endregion
443
- //#region src/array/copyItemState/copyItemState.d.ts
590
+ //#region src/getDeepErrors/getDeepErrors.d.ts
444
591
  /**
445
- * Copies the deeply nested state (signal values) from one field store to
446
- * another. This includes the `elements`, `errors`, `startInput`, `input`,
447
- * `isTouched`, `isDirty`, and for arrays `startItems` and `items` properties.
448
- * Recursively walks through the field stores and copies all signal values.
449
- *
450
- * @param fromInternalFieldStore The source field store to copy from.
451
- * @param toInternalFieldStore The destination field store to copy to.
592
+ * Get form deep errors config interface.
452
593
  */
453
- //#endregion
454
- //#region ../../packages/methods/dist/index.preact.d.ts
455
- //#region src/focus/focus.d.ts
456
-
594
+ interface GetFormDeepErrorsConfig {
595
+ /**
596
+ * The path to a field. Leave undefined to get the errors of the entire form.
597
+ */
598
+ readonly path?: undefined;
599
+ }
457
600
  /**
458
- * Focus field config interface.
601
+ * Get field deep errors config interface.
459
602
  */
460
- interface FocusFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
603
+ interface GetFieldDeepErrorsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
461
604
  /**
462
- * The path to the field to focus.
605
+ * The path to the field to retrieve the errors from.
463
606
  */
464
607
  readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
465
608
  }
466
609
  /**
467
- * Focuses the first input element of a field. This is useful for
468
- * programmatically setting focus to a specific field, such as after
469
- * validation errors or user interactions.
610
+ * Retrieves all error messages of a specific field or the entire form by
611
+ * walking through the field store and all its descendants. This is useful for
612
+ * displaying a summary of all validation errors within a section or the whole
613
+ * form. Form-level errors are included.
470
614
  *
471
- * @param form The form store containing the field.
472
- * @param config The focus field configuration.
615
+ * @param form The form store to retrieve errors from.
616
+ *
617
+ * @returns A non-empty array of error messages, or null if no errors exist.
473
618
  */
474
- declare function focus<TSchema extends FormSchema, TFieldPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: FocusFieldConfig<TSchema, TFieldPath>): void;
475
- //#endregion
476
- //#region src/getAllErrors/getAllErrors.d.ts
619
+ declare function getDeepErrors<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): [string, ...string[]] | null;
477
620
  /**
478
- * Retrieves all error messages from all fields in the form by walking through
479
- * the entire field store tree. This is useful for displaying a summary of all
480
- * validation errors across the form.
621
+ * Retrieves all error messages of a specific field or the entire form by
622
+ * walking through the field store and all its descendants. This is useful for
623
+ * displaying a summary of all validation errors within a section or the whole
624
+ * form. Form-level errors are included.
481
625
  *
482
626
  * @param form The form store to retrieve errors from.
627
+ * @param config The get deep errors configuration.
483
628
  *
484
629
  * @returns A non-empty array of error messages, or null if no errors exist.
485
630
  */
486
- declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
631
+ declare function getDeepErrors<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldDeepErrorsConfig<TSchema, TFieldPath> : GetFormDeepErrorsConfig): [string, ...string[]] | null;
487
632
  //#endregion
488
633
  //#region src/getDirtyInput/getDirtyInput.d.ts
489
634
  /**
@@ -703,6 +848,172 @@ interface InsertConfig<TSchema extends FormSchema, TFieldArrayPath extends Requi
703
848
  */
704
849
  declare function insert<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
705
850
  //#endregion
851
+ //#region src/isDirty/isDirty.d.ts
852
+ /**
853
+ * Is form dirty config interface.
854
+ */
855
+ interface IsFormDirtyConfig {
856
+ /**
857
+ * The path to a field. Leave undefined to check the entire form.
858
+ */
859
+ readonly path?: undefined;
860
+ }
861
+ /**
862
+ * Is field dirty config interface.
863
+ */
864
+ interface IsFieldDirtyConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
865
+ /**
866
+ * The path to the field to check for dirtiness.
867
+ */
868
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
869
+ }
870
+ /**
871
+ * Checks whether a specific field or the entire form is dirty by walking
872
+ * through the field store and all its descendants. A field is dirty when its
873
+ * input differs from its initial value.
874
+ *
875
+ * @param form The form store to check for dirtiness.
876
+ *
877
+ * @returns Whether the field or form is dirty.
878
+ */
879
+ declare function isDirty<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): boolean;
880
+ /**
881
+ * Checks whether a specific field or the entire form is dirty by walking
882
+ * through the field store and all its descendants. A field is dirty when its
883
+ * input differs from its initial value.
884
+ *
885
+ * @param form The form store to check for dirtiness.
886
+ * @param config The is dirty configuration.
887
+ *
888
+ * @returns Whether the field or form is dirty.
889
+ */
890
+ declare function isDirty<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? IsFieldDirtyConfig<TSchema, TFieldPath> : IsFormDirtyConfig): boolean;
891
+ //#endregion
892
+ //#region src/isEdited/isEdited.d.ts
893
+ /**
894
+ * Is form edited config interface.
895
+ */
896
+ interface IsFormEditedConfig {
897
+ /**
898
+ * The path to a field. Leave undefined to check the entire form.
899
+ */
900
+ readonly path?: undefined;
901
+ }
902
+ /**
903
+ * Is field edited config interface.
904
+ */
905
+ interface IsFieldEditedConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
906
+ /**
907
+ * The path to the field to check for being edited.
908
+ */
909
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
910
+ }
911
+ /**
912
+ * Checks whether a specific field or the entire form is edited by walking
913
+ * through the field store and all its descendants. A field is edited once its
914
+ * value has been changed by the user.
915
+ *
916
+ * @param form The form store to check for being edited.
917
+ *
918
+ * @returns Whether the field or form is edited.
919
+ */
920
+ declare function isEdited<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): boolean;
921
+ /**
922
+ * Checks whether a specific field or the entire form is edited by walking
923
+ * through the field store and all its descendants. A field is edited once its
924
+ * value has been changed by the user.
925
+ *
926
+ * @param form The form store to check for being edited.
927
+ * @param config The is edited configuration.
928
+ *
929
+ * @returns Whether the field or form is edited.
930
+ */
931
+ declare function isEdited<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? IsFieldEditedConfig<TSchema, TFieldPath> : IsFormEditedConfig): boolean;
932
+ //#endregion
933
+ //#region src/isTouched/isTouched.d.ts
934
+ /**
935
+ * Is form touched config interface.
936
+ */
937
+ interface IsFormTouchedConfig {
938
+ /**
939
+ * The path to a field. Leave undefined to check the entire form.
940
+ */
941
+ readonly path?: undefined;
942
+ }
943
+ /**
944
+ * Is field touched config interface.
945
+ */
946
+ interface IsFieldTouchedConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
947
+ /**
948
+ * The path to the field to check for being touched.
949
+ */
950
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
951
+ }
952
+ /**
953
+ * Checks whether a specific field or the entire form is touched by walking
954
+ * through the field store and all its descendants. A field is touched once it
955
+ * has received and lost focus.
956
+ *
957
+ * @param form The form store to check for being touched.
958
+ *
959
+ * @returns Whether the field or form is touched.
960
+ */
961
+ declare function isTouched<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): boolean;
962
+ /**
963
+ * Checks whether a specific field or the entire form is touched by walking
964
+ * through the field store and all its descendants. A field is touched once it
965
+ * has received and lost focus.
966
+ *
967
+ * @param form The form store to check for being touched.
968
+ * @param config The is touched configuration.
969
+ *
970
+ * @returns Whether the field or form is touched.
971
+ */
972
+ declare function isTouched<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? IsFieldTouchedConfig<TSchema, TFieldPath> : IsFormTouchedConfig): boolean;
973
+ //#endregion
974
+ //#region src/isValid/isValid.d.ts
975
+ /**
976
+ * Is form valid config interface.
977
+ */
978
+ interface IsFormValidConfig {
979
+ /**
980
+ * The path to a field. Leave undefined to check the entire form.
981
+ */
982
+ readonly path?: undefined;
983
+ }
984
+ /**
985
+ * Is field valid config interface.
986
+ */
987
+ interface IsFieldValidConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
988
+ /**
989
+ * The path to the field to check for validity.
990
+ */
991
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
992
+ }
993
+ /**
994
+ * Checks whether a specific field or the entire form is valid by walking
995
+ * through the field store and all its descendants. A field is valid when
996
+ * neither it nor any of its descendants contains an error. Form-level errors
997
+ * are included.
998
+ *
999
+ * @param form The form store to check for validity.
1000
+ *
1001
+ * @returns Whether the field or form is valid.
1002
+ */
1003
+ declare function isValid<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): boolean;
1004
+ /**
1005
+ * Checks whether a specific field or the entire form is valid by walking
1006
+ * through the field store and all its descendants. A field is valid when
1007
+ * neither it nor any of its descendants contains an error. Form-level errors
1008
+ * are included.
1009
+ *
1010
+ * @param form The form store to check for validity.
1011
+ * @param config The is valid configuration.
1012
+ *
1013
+ * @returns Whether the field or form is valid.
1014
+ */
1015
+ declare function isValid<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? IsFieldValidConfig<TSchema, TFieldPath> : IsFormValidConfig): boolean;
1016
+ //#endregion
706
1017
  //#region src/move/move.d.ts
707
1018
  /**
708
1019
  * Move array field config interface.
@@ -818,6 +1129,10 @@ interface ResetBaseConfig {
818
1129
  */
819
1130
  readonly keepTouched?: boolean | undefined;
820
1131
  /**
1132
+ * Whether to keep the edited state during reset. Defaults to false.
1133
+ */
1134
+ readonly keepEdited?: boolean | undefined;
1135
+ /**
821
1136
  * Whether to keep the error messages during reset. Defaults to false.
822
1137
  */
823
1138
  readonly keepErrors?: boolean | undefined;
@@ -1068,6 +1383,10 @@ interface FieldStore<TSchema extends FormSchema = FormSchema, TFieldPath extends
1068
1383
  */
1069
1384
  readonly isTouched: ReadonlySignal<boolean>;
1070
1385
  /**
1386
+ * Whether the field value has been edited.
1387
+ */
1388
+ readonly isEdited: ReadonlySignal<boolean>;
1389
+ /**
1071
1390
  * Whether the field input differs from its initial value.
1072
1391
  */
1073
1392
  readonly isDirty: ReadonlySignal<boolean>;
@@ -1105,6 +1424,10 @@ interface FieldArrayStore<TSchema extends FormSchema = FormSchema, TFieldArrayPa
1105
1424
  */
1106
1425
  readonly isTouched: ReadonlySignal<boolean>;
1107
1426
  /**
1427
+ * Whether the field array value has been edited.
1428
+ */
1429
+ readonly isEdited: ReadonlySignal<boolean>;
1430
+ /**
1108
1431
  * Whether the field array input differs from its initial value.
1109
1432
  */
1110
1433
  readonly isDirty: ReadonlySignal<boolean>;
@@ -1136,6 +1459,10 @@ interface FormStore<TSchema extends FormSchema = FormSchema> extends BaseFormSto
1136
1459
  */
1137
1460
  readonly isTouched: ReadonlySignal<boolean>;
1138
1461
  /**
1462
+ * Whether any field in the form has been edited.
1463
+ */
1464
+ readonly isEdited: ReadonlySignal<boolean>;
1465
+ /**
1139
1466
  * Whether any field in the form differs from its initial value.
1140
1467
  */
1141
1468
  readonly isDirty: ReadonlySignal<boolean>;
@@ -1147,7 +1474,7 @@ interface FormStore<TSchema extends FormSchema = FormSchema> extends BaseFormSto
1147
1474
  * The current error messages of the form.
1148
1475
  *
1149
1476
  * Hint: This property only contains validation errors at the root level
1150
- * of the form. To get all errors from all fields, use `getAllErrors`.
1477
+ * of the form. To get all errors from all fields, use `getDeepErrors`.
1151
1478
  */
1152
1479
  readonly errors: ReadonlySignal<[string, ...string[]] | null>;
1153
1480
  }
@@ -1294,4 +1621,4 @@ declare function useFieldArray<TSchema extends FormSchema, TFieldArrayPath exten
1294
1621
  */
1295
1622
  declare function useForm<TSchema extends FormSchema>(config: FormConfig<TSchema>): FormStore<TSchema>;
1296
1623
  //#endregion
1297
- export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, type FormSchema, FormStore, GetFieldDirtyInputConfig, GetFieldDirtyPathsConfig, GetFieldErrorsConfig, GetFieldInputConfig, GetFormDirtyInputConfig, GetFormDirtyPathsConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, PickDirtyConfig, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitEventHandler, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getDirtyInput, getDirtyPaths, getErrors, getInput, handleSubmit, insert, move, pickDirty, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
1624
+ export { DeepErrorEntry, type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, type FormSchema, FormStore, GetFieldDeepErrorEntriesConfig, GetFieldDeepErrorsConfig, GetFieldDirtyInputConfig, GetFieldDirtyPathsConfig, GetFieldErrorsConfig, GetFieldInputConfig, GetFormDeepErrorEntriesConfig, GetFormDeepErrorsConfig, GetFormDirtyInputConfig, GetFormDirtyPathsConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, IsFieldDirtyConfig, IsFieldEditedConfig, IsFieldTouchedConfig, IsFieldValidConfig, IsFormDirtyConfig, IsFormEditedConfig, IsFormTouchedConfig, IsFormValidConfig, MoveConfig, type PartialValues, type PathValue, PickDirtyConfig, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitEventHandler, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getDeepErrorEntries, getDeepErrors, getDirtyInput, getDirtyPaths, getErrors, getInput, handleSubmit, insert, isDirty, isEdited, isTouched, isValid, move, pickDirty, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };