@formisch/preact 0.9.5 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,7 +59,11 @@ In addition, Formisch offers several functions (we call them "methods") that can
59
59
 
60
60
  ## Comparison
61
61
 
62
- What makes Formisch unique is its framework-agnostic core, which is fully native to the framework you are using. It works by inserting framework-specific reactivity blocks when the core package is built. The result is a small bundle size and native performance for any UI update. This feature, along with a few others, distinguishes Formisch from other form libraries. My vision for Formisch is to create a framework-agnostic platform similar to [Vite](https://vite.dev/), but for forms.
62
+ What makes Formisch unique is its framework-agnostic core, which is fully native to the framework you are using. It works by inserting framework-specific reactivity blocks when the core package is built, giving you native performance for any UI update. A modular methods API keeps bundles starting at just ~2.5 kB by only including the methods you import, and end-to-end type safety covers deeply nested paths and field arrays with TypeScript inference that stays fast even as forms grow.
63
+
64
+ ## Vision
65
+
66
+ My vision for Formisch is to create a framework-agnostic platform similar to [Vite](https://vite.dev/), but for forms — a shared core that lets the same mental model and codebase work natively across every modern UI framework.
63
67
 
64
68
  ## Partners
65
69
 
package/dist/index.d.ts CHANGED
@@ -1,23 +1,47 @@
1
1
  import * as v from "valibot";
2
2
  import { ReadonlySignal, Signal } from "@preact/signals";
3
- import { JSX } from "preact";
3
+ import { FocusEventHandler, FormHTMLAttributes, GenericEventHandler, InputEventHandler, JSX } from "preact";
4
4
 
5
5
  //#region ../../packages/core/dist/index.preact.d.ts
6
6
 
7
- //#region src/types/schema.d.ts
7
+ //#region src/types/schema/schema.d.ts
8
8
  /**
9
9
  * Schema type.
10
10
  */
11
11
  type Schema = v.GenericSchema | v.GenericSchemaAsync;
12
+ /**
13
+ * Object schema type.
14
+ */
15
+ type ObjectSchema = v.LooseObjectSchema<v.ObjectEntries, v.ErrorMessage<v.LooseObjectIssue> | undefined> | v.ObjectSchema<v.ObjectEntries, v.ErrorMessage<v.ObjectIssue> | undefined> | v.StrictObjectSchema<v.ObjectEntries, v.ErrorMessage<v.StrictObjectIssue> | undefined> | v.VariantSchema<string, v.VariantOptions<string>, v.ErrorMessage<v.VariantIssue> | undefined>;
16
+ /**
17
+ * Object schema async type.
18
+ */
19
+ type ObjectSchemaAsync = v.LooseObjectSchemaAsync<v.ObjectEntriesAsync, v.ErrorMessage<v.LooseObjectIssue> | undefined> | v.ObjectSchemaAsync<v.ObjectEntriesAsync, v.ErrorMessage<v.ObjectIssue> | undefined> | v.StrictObjectSchemaAsync<v.ObjectEntriesAsync, v.ErrorMessage<v.StrictObjectIssue> | undefined> | v.VariantSchemaAsync<string, v.VariantOptionsAsync<string>, v.ErrorMessage<v.VariantIssue> | undefined>;
20
+ /**
21
+ * Object root schema type.
22
+ */
23
+ type ObjectRootSchema = ObjectSchema | v.IntersectSchema<ObjectSchema[], v.ErrorMessage<v.IntersectIssue> | undefined> | v.UnionSchema<ObjectSchema[], v.ErrorMessage<v.UnionIssue<v.BaseIssue<unknown>>> | undefined>;
24
+ /**
25
+ * Object root schema async type.
26
+ */
27
+ type ObjectRootSchemaAsync = ObjectSchemaAsync | v.IntersectSchemaAsync<(ObjectSchema | ObjectSchemaAsync)[], v.ErrorMessage<v.IntersectIssue> | undefined> | v.UnionSchemaAsync<(ObjectSchema | ObjectSchemaAsync)[], v.ErrorMessage<v.UnionIssue<v.BaseIssue<unknown>>> | undefined>;
28
+ /**
29
+ * Form schema type.
30
+ *
31
+ * Hint: Forms must have an object root, so only object schemas (sync or async),
32
+ * combinators (intersect, union, variant) whose options resolve to objects, and
33
+ * `lazy` schemas wrapping any of these are allowed at the top level. Use
34
+ * {@link Schema} for nested field schemas.
35
+ */
36
+ type FormSchema = ObjectRootSchema | ObjectRootSchemaAsync | v.LazySchema<ObjectRootSchema> | v.LazySchemaAsync<ObjectRootSchema | ObjectRootSchemaAsync>;
12
37
  //#endregion
13
- //#region src/types/signal.d.ts
14
-
38
+ //#region src/types/signal/signal.d.ts
15
39
  /**
16
40
  * Batch interface.
17
41
  */
18
42
 
19
43
  //#endregion
20
- //#region src/types/field.d.ts
44
+ //#region src/types/field/field.d.ts
21
45
  /**
22
46
  * Field element type.
23
47
  */
@@ -183,7 +207,7 @@ type InternalFieldStore = InternalArrayStore | InternalObjectStore | InternalVal
183
207
  */
184
208
  declare const INTERNAL: "~internal";
185
209
  //#endregion
186
- //#region src/types/utils.d.ts
210
+ //#region src/types/utils/utils.d.ts
187
211
  /**
188
212
  * Checks if a type is `any`.
189
213
  */
@@ -209,7 +233,7 @@ type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonl
209
233
  */
210
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;
211
235
  //#endregion
212
- //#region src/types/form.d.ts
236
+ //#region src/types/form/form.d.ts
213
237
  /**
214
238
  * Validation mode type.
215
239
  */
@@ -217,7 +241,7 @@ type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submi
217
241
  /**
218
242
  * Form config interface.
219
243
  */
220
- interface FormConfig<TSchema extends Schema = Schema> {
244
+ interface FormConfig<TSchema extends FormSchema = FormSchema> {
221
245
  /**
222
246
  * The schema of the form.
223
247
  */
@@ -238,7 +262,7 @@ interface FormConfig<TSchema extends Schema = Schema> {
238
262
  /**
239
263
  * Internal form store interface.
240
264
  */
241
- interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObjectStore {
265
+ interface InternalFormStore<TSchema extends FormSchema = FormSchema> extends InternalObjectStore {
242
266
  /**
243
267
  * The element of the form.
244
268
  */
@@ -275,7 +299,7 @@ interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObj
275
299
  /**
276
300
  * Base form store interface.
277
301
  */
278
- interface BaseFormStore<TSchema extends Schema = Schema> {
302
+ interface BaseFormStore<TSchema extends FormSchema = FormSchema> {
279
303
  /**
280
304
  * The internal form store.
281
305
  *
@@ -286,13 +310,13 @@ interface BaseFormStore<TSchema extends Schema = Schema> {
286
310
  /**
287
311
  * Submit handler type.
288
312
  */
289
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
313
+ type SubmitHandler<TSchema extends FormSchema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
290
314
  /**
291
315
  * Submit event handler type.
292
316
  */
293
- type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
317
+ type SubmitEventHandler<TSchema extends FormSchema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
294
318
  //#endregion
295
- //#region src/types/path.d.ts
319
+ //#region src/types/path/path.d.ts
296
320
  /**
297
321
  * Path key type.
298
322
  */
@@ -306,47 +330,115 @@ type Path = readonly PathKey[];
306
330
  */
307
331
  type RequiredPath = readonly [PathKey, ...Path];
308
332
  /**
309
- * Extracts the exact keys of a tuple, array or object.
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`.
310
336
  */
311
- type KeyOf<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly unknown[] ? number extends TValue["length"] ? number : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? TIndex : never }[number] : TValue extends Record<string, unknown> ? keyof TValue & PathKey : never;
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;
312
338
  /**
313
- * Merges array and object unions into a single object.
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
+ * `{}`.
314
343
  *
315
- * Hint: This is necessary to make any property accessible. By default,
316
- * properties that do not exist in all union options are not accessible
317
- * and result in "any" when accessed.
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.
318
347
  */
319
- type MergeUnion<TValue> = { [TKey in KeyOf<TValue>]: TValue extends Record<TKey, infer TItem> ? TItem : never };
348
+ type PropertiesOf<TValue> = { [TKey in ExactKeysOf<TValue>]: TValue extends Record<TKey, infer TItem> ? TItem : never };
320
349
  /**
321
350
  * Lazily evaluates only the first valid path segment based on the given value.
322
351
  */
323
- 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;
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;
324
353
  /**
325
354
  * Returns the path if valid, otherwise the first possible valid path based on
326
355
  * the given value.
327
356
  */
328
357
  type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<Required<TValue>, TPath> ? TPath : LazyPath<Required<TValue>, TPath>;
329
358
  /**
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`.
365
+ */
366
+ type IsExactOptionalProps = Required<{
367
+ key?: undefined;
368
+ }>["key"] extends never ? false : true;
369
+ /**
370
+ * Like the built-in `Required<T>`, but preserves `| undefined` in two
371
+ * places where `Required<T>` strips it:
372
+ *
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
+ /**
330
384
  * Extracts the value type at the given path.
331
385
  */
332
- type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends KeyOf<Required<TValue>> ? PathValue<MergeUnion<Required<TValue>>[TKey], TRest> : unknown : TValue;
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;
333
387
  /**
334
- * Checks if a value is an array or contains one.
388
+ * Checks whether a value is an array or contains one anywhere in its shape.
389
+ *
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`.
335
398
  */
336
- type IsOrHasArray<TValue> = IsAny<TValue> extends true ? false : TValue extends readonly unknown[] ? true : TValue extends Record<string, unknown> ? true extends { [TKey in keyof TValue]: IsOrHasArray<TValue[TKey]> }[keyof TValue] ? true : false : false;
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;
337
400
  /**
338
401
  * Extracts the exact keys of a tuple, array or object that contain arrays.
339
402
  */
340
- 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;
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 };
341
411
  /**
342
412
  * Lazily evaluates only the first valid array path segment based on the given value.
343
413
  */
344
- 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;
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;
345
415
  /**
346
416
  * Returns the path if valid, otherwise the first possible valid array path
347
417
  * based on the given value.
348
418
  */
349
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.
430
+ *
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.
434
+ *
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.
440
+ */
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;
350
442
  //#endregion
351
443
  //#region src/array/copyItemState/copyItemState.d.ts
352
444
  /**
@@ -365,7 +457,7 @@ type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArra
365
457
  /**
366
458
  * Focus field config interface.
367
459
  */
368
- interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
460
+ interface FocusFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
369
461
  /**
370
462
  * The path to the field to focus.
371
463
  */
@@ -379,7 +471,7 @@ interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPa
379
471
  * @param form The form store containing the field.
380
472
  * @param config The focus field configuration.
381
473
  */
382
- declare function focus<TSchema extends Schema, TFieldPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: FocusFieldConfig<TSchema, TFieldPath>): void;
474
+ declare function focus<TSchema extends FormSchema, TFieldPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: FocusFieldConfig<TSchema, TFieldPath>): void;
383
475
  //#endregion
384
476
  //#region src/getAllErrors/getAllErrors.d.ts
385
477
  /**
@@ -393,6 +485,93 @@ declare function focus<TSchema extends Schema, TFieldPath extends RequiredPath>(
393
485
  */
394
486
  declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
395
487
  //#endregion
488
+ //#region src/getDirtyInput/getDirtyInput.d.ts
489
+ /**
490
+ * Get form dirty input config interface.
491
+ */
492
+ interface GetFormDirtyInputConfig {
493
+ /**
494
+ * The path to a field. Leave undefined to get the dirty input of the entire
495
+ * form.
496
+ */
497
+ readonly path?: undefined;
498
+ }
499
+ /**
500
+ * Get field dirty input config interface.
501
+ */
502
+ interface GetFieldDirtyInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
503
+ /**
504
+ * The path to the field to retrieve the dirty input from.
505
+ */
506
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
507
+ }
508
+ /**
509
+ * Retrieves only the dirty input values of a specific field or the entire
510
+ * form. Arrays are treated as atomic and returned in full if any item is
511
+ * dirty, while object keys without a dirty descendant are omitted. Returns
512
+ * `undefined` if no field in the inspected subtree is dirty.
513
+ *
514
+ * @param form The form store to retrieve dirty input from.
515
+ *
516
+ * @returns The dirty input of the form or specified field, or `undefined`.
517
+ */
518
+ declare function getDirtyInput<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): DeepPartial<v.InferInput<TSchema>> | undefined;
519
+ /**
520
+ * Retrieves only the dirty input values of a specific field or the entire
521
+ * form. Arrays are treated as atomic and returned in full if any item is
522
+ * dirty, while object keys without a dirty descendant are omitted. Returns
523
+ * `undefined` if no field in the inspected subtree is dirty.
524
+ *
525
+ * @param form The form store to retrieve dirty input from.
526
+ * @param config The get dirty input configuration.
527
+ *
528
+ * @returns The dirty input of the form or specified field, or `undefined`.
529
+ */
530
+ declare function getDirtyInput<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldDirtyInputConfig<TSchema, TFieldPath> : GetFormDirtyInputConfig): DeepPartial<TFieldPath extends RequiredPath ? PathValue<v.InferInput<TSchema>, TFieldPath> : v.InferInput<TSchema>> | undefined;
531
+ //#endregion
532
+ //#region src/getDirtyPaths/getDirtyPaths.d.ts
533
+ /**
534
+ * Get form dirty paths config interface.
535
+ */
536
+ interface GetFormDirtyPathsConfig {
537
+ /**
538
+ * The path to a field. Leave undefined to inspect the entire form.
539
+ */
540
+ readonly path?: undefined;
541
+ }
542
+ /**
543
+ * Get field dirty paths config interface.
544
+ */
545
+ interface GetFieldDirtyPathsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
546
+ /**
547
+ * The path to the field to inspect.
548
+ */
549
+ readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
550
+ }
551
+ /**
552
+ * Returns a list of paths to the dirty fields of a specific field or the
553
+ * entire form. Arrays are treated as atomic and contribute only their own
554
+ * path if any item is dirty, while object branches are recursed into. Returns
555
+ * an empty list if no field in the inspected subtree is dirty.
556
+ *
557
+ * @param form The form store to inspect.
558
+ *
559
+ * @returns The list of paths to the dirty fields.
560
+ */
561
+ declare function getDirtyPaths<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): DirtyPath<v.InferInput<TSchema>>[];
562
+ /**
563
+ * Returns a list of paths to the dirty fields of a specific field or the
564
+ * entire form. Arrays are treated as atomic and contribute only their own
565
+ * path if any item is dirty, while object branches are recursed into. Returns
566
+ * an empty list if no field in the inspected subtree is dirty.
567
+ *
568
+ * @param form The form store to inspect.
569
+ * @param config The get dirty paths configuration.
570
+ *
571
+ * @returns The list of paths to the dirty fields.
572
+ */
573
+ declare function getDirtyPaths<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldDirtyPathsConfig<TSchema, TFieldPath> : GetFormDirtyPathsConfig): DirtyPath<v.InferInput<TSchema>>[];
574
+ //#endregion
396
575
  //#region src/getErrors/getErrors.d.ts
397
576
  /**
398
577
  * Get form errors config interface.
@@ -406,7 +585,7 @@ interface GetFormErrorsConfig {
406
585
  /**
407
586
  * Get field errors config interface.
408
587
  */
409
- interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
588
+ interface GetFieldErrorsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
410
589
  /**
411
590
  * The path to the field to retrieve errors from.
412
591
  */
@@ -421,7 +600,7 @@ interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends Requir
421
600
  *
422
601
  * @returns A non-empty array of error messages, or null if no errors exist.
423
602
  */
424
- declare function getErrors<TSchema extends Schema>(form: BaseFormStore<TSchema>): [string, ...string[]] | null;
603
+ declare function getErrors<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): [string, ...string[]] | null;
425
604
  /**
426
605
  * Retrieves error messages from the form. When called without a config,
427
606
  * returns form-level errors. When called with a path, returns errors for
@@ -432,7 +611,7 @@ declare function getErrors<TSchema extends Schema>(form: BaseFormStore<TSchema>)
432
611
  *
433
612
  * @returns A non-empty array of error messages, or null if no errors exist.
434
613
  */
435
- 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;
614
+ declare function getErrors<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldErrorsConfig<TSchema, TFieldPath> : GetFormErrorsConfig): [string, ...string[]] | null;
436
615
  //#endregion
437
616
  //#region src/getInput/getInput.d.ts
438
617
  /**
@@ -447,7 +626,7 @@ interface GetFormInputConfig {
447
626
  /**
448
627
  * Get field input config interface.
449
628
  */
450
- interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
629
+ interface GetFieldInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
451
630
  /**
452
631
  * The path to the field to retrieve input from.
453
632
  */
@@ -461,7 +640,7 @@ interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends Require
461
640
  *
462
641
  * @returns The partial input values of the form or the specified field.
463
642
  */
464
- declare function getInput<TSchema extends Schema>(form: BaseFormStore<TSchema>): PartialValues<v.InferInput<TSchema>>;
643
+ declare function getInput<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): PartialValues<v.InferInput<TSchema>>;
465
644
  /**
466
645
  * Retrieves the current input value of a specific field or the entire form.
467
646
  * Returns a partial object as not all fields may have been set.
@@ -471,7 +650,7 @@ declare function getInput<TSchema extends Schema>(form: BaseFormStore<TSchema>):
471
650
  *
472
651
  * @returns The partial input values of the form or the specified field.
473
652
  */
474
- 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>>;
653
+ declare function getInput<TSchema extends FormSchema, 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>>;
475
654
  //#endregion
476
655
  //#region src/handleSubmit/handleSubmit.d.ts
477
656
  /**
@@ -484,7 +663,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
484
663
  *
485
664
  * @returns A submit event handler function to attach to the form element.
486
665
  */
487
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
666
+ declare function handleSubmit<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
488
667
  /**
489
668
  * Creates a submit event handler for the form that prevents default browser
490
669
  * submission, validates the form input, and calls the provided handler if
@@ -495,13 +674,13 @@ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchem
495
674
  *
496
675
  * @returns A submit event handler function to attach to the form element.
497
676
  */
498
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
677
+ declare function handleSubmit<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
499
678
  //#endregion
500
679
  //#region src/insert/insert.d.ts
501
680
  /**
502
681
  * Insert array field config interface.
503
682
  */
504
- interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
683
+ interface InsertConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
505
684
  /**
506
685
  * The path to the field array to insert into.
507
686
  */
@@ -522,13 +701,13 @@ interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredP
522
701
  * @param form The form store containing the field array.
523
702
  * @param config The insert configuration specifying the path, index, and initial value.
524
703
  */
525
- declare function insert<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
704
+ declare function insert<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
526
705
  //#endregion
527
706
  //#region src/move/move.d.ts
528
707
  /**
529
708
  * Move array field config interface.
530
709
  */
531
- interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
710
+ interface MoveConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
532
711
  /**
533
712
  * The path to the field array to move an item within.
534
713
  */
@@ -549,13 +728,38 @@ interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPat
549
728
  * @param form The form store containing the field array.
550
729
  * @param config The move configuration specifying the path and source/destination indices.
551
730
  */
552
- declare function move<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: MoveConfig<TSchema, TFieldArrayPath>): void;
731
+ declare function move<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: MoveConfig<TSchema, TFieldArrayPath>): void;
732
+ //#endregion
733
+ //#region src/pickDirty/pickDirty.d.ts
734
+ /**
735
+ * Pick dirty config interface.
736
+ */
737
+ interface PickDirtyConfig<TValue extends object> {
738
+ /**
739
+ * The value to filter down to its dirty parts. Must be structurally
740
+ * compatible with the form's schema.
741
+ */
742
+ readonly from: TValue;
743
+ }
744
+ /**
745
+ * Picks only the dirty parts of the given value, using the form's dirty fields
746
+ * as a structural mask. Arrays are treated as atomic and object keys without a
747
+ * dirty descendant are omitted. Returns `undefined` if no field is dirty.
748
+ * Useful for filtering a validated output down to its changed parts before
749
+ * submitting.
750
+ *
751
+ * @param form The form store providing the dirty mask.
752
+ * @param config The pick dirty configuration.
753
+ *
754
+ * @returns The dirty parts of the value, or `undefined`.
755
+ */
756
+ declare function pickDirty<TSchema extends FormSchema, TValue extends object>(form: BaseFormStore<TSchema>, config: PickDirtyConfig<TValue>): DeepPartial<TValue> | undefined;
553
757
  //#endregion
554
758
  //#region src/remove/remove.d.ts
555
759
  /**
556
760
  * Remove array field config interface.
557
761
  */
558
- interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
762
+ interface RemoveConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
559
763
  /**
560
764
  * The path to the field array to remove an item from.
561
765
  */
@@ -572,13 +776,13 @@ interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredP
572
776
  * @param form The form store containing the field array.
573
777
  * @param config The remove configuration specifying the path and index.
574
778
  */
575
- declare function remove<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: RemoveConfig<TSchema, TFieldArrayPath>): void;
779
+ declare function remove<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: RemoveConfig<TSchema, TFieldArrayPath>): void;
576
780
  //#endregion
577
781
  //#region src/replace/replace.d.ts
578
782
  /**
579
783
  * Replace array field config interface.
580
784
  */
581
- interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
785
+ interface ReplaceConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
582
786
  /**
583
787
  * The path to the field array to replace an item within.
584
788
  */
@@ -598,7 +802,7 @@ interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends Required
598
802
  * @param form The form store containing the field array.
599
803
  * @param config The replace configuration specifying the path, index, and initial input.
600
804
  */
601
- declare function replace<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: ReplaceConfig<TSchema, TFieldArrayPath>): void;
805
+ declare function replace<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: ReplaceConfig<TSchema, TFieldArrayPath>): void;
602
806
  //#endregion
603
807
  //#region src/reset/reset.d.ts
604
808
  /**
@@ -621,7 +825,7 @@ interface ResetBaseConfig {
621
825
  /**
622
826
  * Reset form config interface.
623
827
  */
624
- interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
828
+ interface ResetFormConfig<TSchema extends FormSchema> extends ResetBaseConfig {
625
829
  /**
626
830
  * The path to a field. Leave undefined to reset the entire form.
627
831
  */
@@ -639,7 +843,7 @@ interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
639
843
  /**
640
844
  * Reset field config interface.
641
845
  */
642
- interface ResetFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
846
+ interface ResetFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
643
847
  /**
644
848
  * The path to the field to reset.
645
849
  */
@@ -666,7 +870,7 @@ declare function reset(form: BaseFormStore): void;
666
870
  * @param form The form store to reset.
667
871
  * @param config The reset configuration specifying what to reset and what to keep.
668
872
  */
669
- declare function reset<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? ResetFieldConfig<TSchema, TFieldPath> : ResetFormConfig<TSchema>): void;
873
+ declare function reset<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? ResetFieldConfig<TSchema, TFieldPath> : ResetFormConfig<TSchema>): void;
670
874
  //#endregion
671
875
  //#region src/setErrors/setErrors.d.ts
672
876
  /**
@@ -685,7 +889,7 @@ interface SetFormErrorsConfig {
685
889
  /**
686
890
  * Set field errors config interface.
687
891
  */
688
- interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
892
+ interface SetFieldErrorsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
689
893
  /**
690
894
  * The path to the field to set errors on.
691
895
  */
@@ -703,13 +907,13 @@ interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends Requir
703
907
  * @param form The form store to set errors on.
704
908
  * @param config The set errors configuration specifying the path and error messages.
705
909
  */
706
- declare function setErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldErrorsConfig<TSchema, TFieldPath> : SetFormErrorsConfig): void;
910
+ declare function setErrors<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldErrorsConfig<TSchema, TFieldPath> : SetFormErrorsConfig): void;
707
911
  //#endregion
708
912
  //#region src/setInput/setInput.d.ts
709
913
  /**
710
914
  * Set form input config interface.
711
915
  */
712
- interface SetFormInputConfig<TSchema extends Schema> {
916
+ interface SetFormInputConfig<TSchema extends FormSchema> {
713
917
  /**
714
918
  * The path to a field. Leave undefined to set the entire form input.
715
919
  */
@@ -722,7 +926,7 @@ interface SetFormInputConfig<TSchema extends Schema> {
722
926
  /**
723
927
  * Set field input config interface.
724
928
  */
725
- interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
929
+ interface SetFieldInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
726
930
  /**
727
931
  * The path to the field to set input on.
728
932
  */
@@ -740,7 +944,7 @@ interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends Require
740
944
  * @param form The form store to set input on.
741
945
  * @param config The set form input configuration specifying the new input values.
742
946
  */
743
- declare function setInput<TSchema extends Schema>(form: BaseFormStore<TSchema>, config: SetFormInputConfig<TSchema>): void;
947
+ declare function setInput<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, config: SetFormInputConfig<TSchema>): void;
744
948
  /**
745
949
  * Sets the input value of a specific field or the entire form. This updates
746
950
  * the field value(s) and triggers validation if required by the form's
@@ -749,7 +953,7 @@ declare function setInput<TSchema extends Schema>(form: BaseFormStore<TSchema>,
749
953
  * @param form The form store to set input on.
750
954
  * @param config The set input configuration specifying the path and new value.
751
955
  */
752
- declare function setInput<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldInputConfig<TSchema, TFieldPath> : SetFormInputConfig<TSchema>): void;
956
+ declare function setInput<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldInputConfig<TSchema, TFieldPath> : SetFormInputConfig<TSchema>): void;
753
957
  //#endregion
754
958
  //#region src/submit/submit.d.ts
755
959
  /**
@@ -764,7 +968,7 @@ declare function submit(form: BaseFormStore): void;
764
968
  /**
765
969
  * Swap array field config interface.
766
970
  */
767
- interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
971
+ interface SwapConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
768
972
  /**
769
973
  * The path to the field array to swap items within.
770
974
  */
@@ -784,7 +988,7 @@ interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPat
784
988
  * @param form The form store containing the field array.
785
989
  * @param config The swap configuration specifying the path and indices to swap.
786
990
  */
787
- declare function swap<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: SwapConfig<TSchema, TFieldArrayPath>): void;
991
+ declare function swap<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: SwapConfig<TSchema, TFieldArrayPath>): void;
788
992
  //#endregion
789
993
  //#region src/validate/validate.d.ts
790
994
  /**
@@ -806,7 +1010,7 @@ interface ValidateFormConfig {
806
1010
  *
807
1011
  * @returns A promise resolving to the validation result.
808
1012
  */
809
- declare function validate<TSchema extends Schema>(form: BaseFormStore<TSchema>, config?: ValidateFormConfig): Promise<v.SafeParseResult<TSchema>>;
1013
+ declare function validate<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, config?: ValidateFormConfig): Promise<v.SafeParseResult<TSchema>>;
810
1014
  //#endregion
811
1015
  //#endregion
812
1016
  //#region src/types/field.d.ts
@@ -825,28 +1029,28 @@ interface FieldElementProps {
825
1029
  /**
826
1030
  * The ref callback to register the field element.
827
1031
  */
828
- readonly ref: (element: FieldElement) => void;
1032
+ readonly ref: (element: FieldElement | null) => void;
829
1033
  /**
830
1034
  * The focus event handler of the field element.
831
1035
  */
832
- readonly onFocus: JSX.FocusEventHandler<FieldElement>;
1036
+ readonly onFocus: FocusEventHandler<FieldElement>;
833
1037
  /**
834
1038
  * The input event handler of the field element.
835
1039
  */
836
- readonly onInput: JSX.InputEventHandler<FieldElement>;
1040
+ readonly onInput: InputEventHandler<FieldElement>;
837
1041
  /**
838
1042
  * The change event handler of the field element.
839
1043
  */
840
- readonly onChange: JSX.GenericEventHandler<FieldElement>;
1044
+ readonly onChange: GenericEventHandler<FieldElement>;
841
1045
  /**
842
1046
  * The blur event handler of the field element.
843
1047
  */
844
- readonly onBlur: JSX.FocusEventHandler<FieldElement>;
1048
+ readonly onBlur: FocusEventHandler<FieldElement>;
845
1049
  }
846
1050
  /**
847
1051
  * Field store interface.
848
1052
  */
849
- interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
1053
+ interface FieldStore<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
850
1054
  /**
851
1055
  * The path to the field within the form.
852
1056
  */
@@ -883,7 +1087,7 @@ interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends Require
883
1087
  /**
884
1088
  * Field array store interface.
885
1089
  */
886
- interface FieldArrayStore<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1090
+ interface FieldArrayStore<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
887
1091
  /**
888
1092
  * The path to the array field within the form.
889
1093
  */
@@ -914,7 +1118,7 @@ interface FieldArrayStore<TSchema extends Schema = Schema, TFieldArrayPath exten
914
1118
  /**
915
1119
  * Form store interface.
916
1120
  */
917
- interface FormStore<TSchema extends Schema = Schema> extends BaseFormStore<TSchema> {
1121
+ interface FormStore<TSchema extends FormSchema = FormSchema> extends BaseFormStore<TSchema> {
918
1122
  /**
919
1123
  * Whether the form is currently submitting.
920
1124
  */
@@ -952,7 +1156,7 @@ interface FormStore<TSchema extends Schema = Schema> extends BaseFormStore<TSche
952
1156
  /**
953
1157
  * Field component props interface.
954
1158
  */
955
- interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
1159
+ interface FieldProps<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
956
1160
  /**
957
1161
  * The form store to which the field belongs.
958
1162
  */
@@ -975,7 +1179,7 @@ interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends Require
975
1179
  *
976
1180
  * @returns The UI of the field to be rendered.
977
1181
  */
978
- declare function Field<TSchema extends Schema, TFieldPath extends RequiredPath>({
1182
+ declare function Field<TSchema extends FormSchema, TFieldPath extends RequiredPath>({
979
1183
  of,
980
1184
  path,
981
1185
  children
@@ -985,7 +1189,7 @@ declare function Field<TSchema extends Schema, TFieldPath extends RequiredPath>(
985
1189
  /**
986
1190
  * FieldArray component props interface.
987
1191
  */
988
- interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1192
+ interface FieldArrayProps<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
989
1193
  /**
990
1194
  * The form store to which the field array belongs.
991
1195
  */
@@ -1009,7 +1213,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
1009
1213
  *
1010
1214
  * @returns The UI of the field array to be rendered.
1011
1215
  */
1012
- declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>({
1216
+ declare function FieldArray<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>({
1013
1217
  of,
1014
1218
  path,
1015
1219
  children
@@ -1019,7 +1223,7 @@ declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends Requ
1019
1223
  /**
1020
1224
  * Form component props type.
1021
1225
  */
1022
- type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "novalidate" | "noValidate"> & {
1226
+ type FormProps<TSchema extends FormSchema = FormSchema> = Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "novalidate" | "noValidate"> & {
1023
1227
  /**
1024
1228
  * The form store instance.
1025
1229
  */
@@ -1037,13 +1241,13 @@ type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HT
1037
1241
  *
1038
1242
  * @returns The a native form element.
1039
1243
  */
1040
- declare function Form<TSchema extends Schema>(props: FormProps<TSchema>): JSX.Element;
1244
+ declare function Form<TSchema extends FormSchema>(props: FormProps<TSchema>): JSX.Element;
1041
1245
  //#endregion
1042
1246
  //#region src/hooks/useField/useField.d.ts
1043
1247
  /**
1044
1248
  * Use field config interface.
1045
1249
  */
1046
- interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
1250
+ interface UseFieldConfig<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
1047
1251
  /**
1048
1252
  * The path to the field within the form schema.
1049
1253
  */
@@ -1057,13 +1261,13 @@ interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends Req
1057
1261
  *
1058
1262
  * @returns The field store with reactive properties and element props.
1059
1263
  */
1060
- declare function useField<TSchema extends Schema, TFieldPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldConfig<TSchema, TFieldPath>): FieldStore<TSchema, TFieldPath>;
1264
+ declare function useField<TSchema extends FormSchema, TFieldPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldConfig<TSchema, TFieldPath>): FieldStore<TSchema, TFieldPath>;
1061
1265
  //#endregion
1062
1266
  //#region src/hooks/useFieldArray/useFieldArray.d.ts
1063
1267
  /**
1064
1268
  * Use field array config interface.
1065
1269
  */
1066
- interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1270
+ interface UseFieldArrayConfig<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1067
1271
  /**
1068
1272
  * The path to the array field within the form schema.
1069
1273
  */
@@ -1077,7 +1281,7 @@ interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath e
1077
1281
  *
1078
1282
  * @returns The field array store with reactive properties for array management.
1079
1283
  */
1080
- declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldArrayConfig<TSchema, TFieldArrayPath>): FieldArrayStore<TSchema, TFieldArrayPath>;
1284
+ declare function useFieldArray<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldArrayConfig<TSchema, TFieldArrayPath>): FieldArrayStore<TSchema, TFieldArrayPath>;
1081
1285
  //#endregion
1082
1286
  //#region src/hooks/useForm/useForm.d.ts
1083
1287
  /**
@@ -1088,6 +1292,6 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
1088
1292
  *
1089
1293
  * @returns The form store with reactive properties.
1090
1294
  */
1091
- declare function useForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
1295
+ declare function useForm<TSchema extends FormSchema>(config: FormConfig<TSchema>): FormStore<TSchema>;
1092
1296
  //#endregion
1093
- 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 SubmitEventHandler, 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 };
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 };
package/dist/index.js CHANGED
@@ -76,7 +76,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
76
76
  if (internalFieldStore.kind === "object") {
77
77
  internalFieldStore.children ??= {};
78
78
  for (const key in schema.entries) {
79
- internalFieldStore.children[key] = {};
79
+ internalFieldStore.children[key] ??= {};
80
80
  path.push(key);
81
81
  initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
82
82
  path.pop();
@@ -87,6 +87,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
87
87
  internalFieldStore.input = createSignal(objectInput);
88
88
  }
89
89
  } else {
90
+ if (internalFieldStore.kind && internalFieldStore.kind !== "value") throw new Error(`Store initialized as "${internalFieldStore.kind}" cannot be reinitialized as "value"`);
90
91
  internalFieldStore.kind = "value";
91
92
  if (internalFieldStore.kind === "value") {
92
93
  internalFieldStore.initialInput = createSignal(initialInput);
@@ -232,6 +233,63 @@ function swapItemState(firstInternalFieldStore, secondInternalFieldStore) {
232
233
  });
233
234
  }
234
235
  /**
236
+ * Returns whether the specified boolean property is true for the field store
237
+ * or any of its nested children. Recursively checks arrays and objects.
238
+ *
239
+ * @param internalFieldStore The field store to check.
240
+ * @param type The boolean property type to check.
241
+ *
242
+ * @returns Whether the property is true.
243
+ */
244
+ /* @__NO_SIDE_EFFECTS__ */
245
+ function getFieldBool(internalFieldStore, type) {
246
+ if (internalFieldStore[type].value) return true;
247
+ if (internalFieldStore.kind === "array") {
248
+ for (let index = 0; index < internalFieldStore.items.value.length; index++) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[index], type)) return true;
249
+ return false;
250
+ }
251
+ if (internalFieldStore.kind == "object") {
252
+ for (const key in internalFieldStore.children) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[key], type)) return true;
253
+ return false;
254
+ }
255
+ return false;
256
+ }
257
+ /**
258
+ * Returns only the dirty input of the field store. Arrays are treated as
259
+ * atomic and returned in full if any item is dirty, while object keys without
260
+ * a dirty descendant are omitted. Returns `undefined` if no descendant is
261
+ * dirty.
262
+ *
263
+ * @param internalFieldStore The field store to get dirty input from.
264
+ * @param dirtyOnly Whether to only include dirty fields. Defaults to `true`.
265
+ *
266
+ * @returns The dirty input, or `undefined` if no descendant is dirty.
267
+ */
268
+ /* @__NO_SIDE_EFFECTS__ */
269
+ function getDirtyFieldInput(internalFieldStore, dirtyOnly = true) {
270
+ if (dirtyOnly && !/* @__PURE__ */ getFieldBool(internalFieldStore, "isDirty")) return;
271
+ if (internalFieldStore.kind === "array") {
272
+ if (internalFieldStore.input.value) {
273
+ const value = [];
274
+ for (let index = 0; index < internalFieldStore.items.value.length; index++) value[index] = /* @__PURE__ */ getDirtyFieldInput(internalFieldStore.children[index], false);
275
+ return value;
276
+ }
277
+ return internalFieldStore.input.value;
278
+ }
279
+ if (internalFieldStore.kind === "object") {
280
+ if (internalFieldStore.input.value) {
281
+ const value = {};
282
+ for (const key in internalFieldStore.children) {
283
+ const child = internalFieldStore.children[key];
284
+ if (!dirtyOnly || /* @__PURE__ */ getFieldBool(child, "isDirty")) value[key] = /* @__PURE__ */ getDirtyFieldInput(child, dirtyOnly);
285
+ }
286
+ return value;
287
+ }
288
+ return internalFieldStore.input.value;
289
+ }
290
+ return internalFieldStore.input.value;
291
+ }
292
+ /**
235
293
  * Returns the current input of the field store. For arrays and objects,
236
294
  * recursively collects input from all children. Returns `null` or `undefined`
237
295
  * for nullish array/object inputs, or the primitive value for value fields.
@@ -288,28 +346,6 @@ function getElementInput(element, internalFieldStore) {
288
346
  return element.value;
289
347
  }
290
348
  /**
291
- * Returns whether the specified boolean property is true for the field store
292
- * or any of its nested children. Recursively checks arrays and objects.
293
- *
294
- * @param internalFieldStore The field store to check.
295
- * @param type The boolean property type to check.
296
- *
297
- * @returns Whether the property is true.
298
- */
299
- /* @__NO_SIDE_EFFECTS__ */
300
- function getFieldBool(internalFieldStore, type) {
301
- if (internalFieldStore[type].value) return true;
302
- if (internalFieldStore.kind === "array") {
303
- for (let index = 0; index < internalFieldStore.items.value.length; index++) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[index], type)) return true;
304
- return false;
305
- }
306
- if (internalFieldStore.kind == "object") {
307
- for (const key in internalFieldStore.children) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[key], type)) return true;
308
- return false;
309
- }
310
- return false;
311
- }
312
- /**
313
349
  * Returns the field store at the specified path by traversing the form store's
314
350
  * children hierarchy.
315
351
  *
@@ -566,6 +602,17 @@ function getAllErrors(form) {
566
602
  return allErrors;
567
603
  }
568
604
  /* @__NO_SIDE_EFFECTS__ */
605
+ function getDirtyInput(form, config) {
606
+ return getDirtyFieldInput(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL]);
607
+ }
608
+ /* @__NO_SIDE_EFFECTS__ */
609
+ function getDirtyPaths(form, config) {
610
+ config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL];
611
+ const paths = [];
612
+ config?.path && [...config.path];
613
+ return paths;
614
+ }
615
+ /* @__NO_SIDE_EFFECTS__ */
569
616
  function getErrors(form, config) {
570
617
  return (config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL]).errors.value;
571
618
  }
@@ -659,6 +706,48 @@ function move(form, config) {
659
706
  });
660
707
  }
661
708
  /**
709
+ * Picks only the dirty parts of the given value, using the form's dirty fields
710
+ * as a structural mask. Arrays are treated as atomic and object keys without a
711
+ * dirty descendant are omitted. Returns `undefined` if no field is dirty.
712
+ * Useful for filtering a validated output down to its changed parts before
713
+ * submitting.
714
+ *
715
+ * @param form The form store providing the dirty mask.
716
+ * @param config The pick dirty configuration.
717
+ *
718
+ * @returns The dirty parts of the value, or `undefined`.
719
+ */
720
+ /* @__NO_SIDE_EFFECTS__ */
721
+ function pickDirty(form, config) {
722
+ if (!getFieldBool(form[INTERNAL], "isDirty")) return;
723
+ const result = /* @__PURE__ */ pickFieldValue(form[INTERNAL], config.from);
724
+ return Object.keys(result).length ? result : void 0;
725
+ }
726
+ /**
727
+ * Recursively picks the dirty parts of a value using the field store as a
728
+ * structural mask, reading from the supplied value rather than the form's own
729
+ * input. Objects with non-nullish input recurse into their dirty children that
730
+ * are present in the value, while arrays, primitives, nullish-cleared fields
731
+ * and shape-diverging values are returned as-is.
732
+ *
733
+ * @param internalFieldStore The field store used as the dirty mask.
734
+ * @param value The value to pick the dirty parts from.
735
+ *
736
+ * @returns The dirty parts of the value.
737
+ */
738
+ /* @__NO_SIDE_EFFECTS__ */
739
+ function pickFieldValue(internalFieldStore, value) {
740
+ if (internalFieldStore.kind === "object" && internalFieldStore.input.value && value && typeof value === "object" && !Array.isArray(value)) {
741
+ const result = {};
742
+ for (const key in internalFieldStore.children) {
743
+ const child = internalFieldStore.children[key];
744
+ if (getFieldBool(child, "isDirty") && key in value) result[key] = /* @__PURE__ */ pickFieldValue(child, value[key]);
745
+ }
746
+ return result;
747
+ }
748
+ return value;
749
+ }
750
+ /**
662
751
  * Removes an item from a field array at the specified index. All items after
663
752
  * the removed item are shifted down by one index.
664
753
  *
@@ -704,7 +793,7 @@ function reset(form, config) {
704
793
  untrack(() => {
705
794
  const internalFormStore = form[INTERNAL];
706
795
  const internalFieldStore = config?.path ? getFieldStore(internalFormStore, config.path) : internalFormStore;
707
- if (config?.initialInput) setInitialFieldInput(internalFieldStore, config.initialInput);
796
+ if (config && "initialInput" in config) setInitialFieldInput(internalFieldStore, config.initialInput);
708
797
  walkFieldStore(internalFieldStore, (internalFieldStore$1) => {
709
798
  internalFieldStore$1.elements = internalFieldStore$1.initialElements;
710
799
  if (!config?.keepErrors) internalFieldStore$1.errors.value = null;
@@ -951,4 +1040,4 @@ function Form({ of, onSubmit, ...other }) {
951
1040
  }
952
1041
 
953
1042
  //#endregion
954
- export { Field, FieldArray, Form, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
1043
+ export { Field, FieldArray, Form, focus, getAllErrors, getDirtyInput, getDirtyPaths, getErrors, getInput, handleSubmit, insert, move, pickDirty, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/preact",
3
- "description": "The modular and type-safe form library for Preact",
4
- "version": "0.9.5",
3
+ "description": "The lightweight, schema-first, and fully type-safe form library for Preact",
4
+ "version": "0.10.0",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -34,6 +34,7 @@
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsdown",
37
+ "test": "vitest run --typecheck",
37
38
  "lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
38
39
  "lint.fix": "eslint \"src/**/*.ts*\" --fix",
39
40
  "format": "prettier --write ./src",
@@ -43,21 +44,26 @@
43
44
  "@formisch/core": "workspace:*",
44
45
  "@formisch/eslint-config": "workspace:*",
45
46
  "@formisch/methods": "workspace:*",
46
- "@preact/preset-vite": "^2.9.3",
47
- "@preact/signals": "^2.2.1",
47
+ "@preact/preset-vite": "^2.10.5",
48
+ "@preact/signals": "^2.9.0",
49
+ "@testing-library/jest-dom": "^6.6.0",
50
+ "@testing-library/preact": "^3.2.4",
51
+ "@vitest/coverage-v8": "^3.2.4",
48
52
  "eslint": "^9.31.0",
49
53
  "eslint-config-preact": "^2.0.0",
50
- "preact": "^10.25.3",
54
+ "jsdom": "^26.1.0",
55
+ "preact": "^10.29.2",
51
56
  "tsdown": "^0.16.8",
52
57
  "typescript": "^5.8.3",
53
- "valibot": "^1.2.0",
54
- "vite": "^6.0.4"
58
+ "valibot": "^1.4.1",
59
+ "vite": "^6.0.4",
60
+ "vitest": "^3.2.4"
55
61
  },
56
62
  "peerDependencies": {
57
63
  "@preact/signals": "^2.0.0",
58
64
  "preact": "^10.0.0",
59
65
  "typescript": ">=5",
60
- "valibot": "^1.0.0"
66
+ "valibot": "^1.4.1"
61
67
  },
62
68
  "peerDependenciesMeta": {
63
69
  "typescript": {