@formisch/preact 0.9.6 → 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,6 +1,6 @@
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
 
@@ -9,9 +9,33 @@ import { JSX } from "preact";
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
38
  //#region src/types/signal/signal.d.ts
14
-
15
39
  /**
16
40
  * Batch interface.
17
41
  */
@@ -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,11 +310,11 @@ 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
319
  //#region src/types/path/path.d.ts
296
320
  /**
@@ -393,6 +417,28 @@ type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path =
393
417
  * based on the given value.
394
418
  */
395
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;
396
442
  //#endregion
397
443
  //#region src/array/copyItemState/copyItemState.d.ts
398
444
  /**
@@ -411,7 +457,7 @@ type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArra
411
457
  /**
412
458
  * Focus field config interface.
413
459
  */
414
- interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
460
+ interface FocusFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
415
461
  /**
416
462
  * The path to the field to focus.
417
463
  */
@@ -425,7 +471,7 @@ interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPa
425
471
  * @param form The form store containing the field.
426
472
  * @param config The focus field configuration.
427
473
  */
428
- 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;
429
475
  //#endregion
430
476
  //#region src/getAllErrors/getAllErrors.d.ts
431
477
  /**
@@ -439,6 +485,93 @@ declare function focus<TSchema extends Schema, TFieldPath extends RequiredPath>(
439
485
  */
440
486
  declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
441
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
442
575
  //#region src/getErrors/getErrors.d.ts
443
576
  /**
444
577
  * Get form errors config interface.
@@ -452,7 +585,7 @@ interface GetFormErrorsConfig {
452
585
  /**
453
586
  * Get field errors config interface.
454
587
  */
455
- interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
588
+ interface GetFieldErrorsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
456
589
  /**
457
590
  * The path to the field to retrieve errors from.
458
591
  */
@@ -467,7 +600,7 @@ interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends Requir
467
600
  *
468
601
  * @returns A non-empty array of error messages, or null if no errors exist.
469
602
  */
470
- 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;
471
604
  /**
472
605
  * Retrieves error messages from the form. When called without a config,
473
606
  * returns form-level errors. When called with a path, returns errors for
@@ -478,7 +611,7 @@ declare function getErrors<TSchema extends Schema>(form: BaseFormStore<TSchema>)
478
611
  *
479
612
  * @returns A non-empty array of error messages, or null if no errors exist.
480
613
  */
481
- 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;
482
615
  //#endregion
483
616
  //#region src/getInput/getInput.d.ts
484
617
  /**
@@ -493,7 +626,7 @@ interface GetFormInputConfig {
493
626
  /**
494
627
  * Get field input config interface.
495
628
  */
496
- interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
629
+ interface GetFieldInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
497
630
  /**
498
631
  * The path to the field to retrieve input from.
499
632
  */
@@ -507,7 +640,7 @@ interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends Require
507
640
  *
508
641
  * @returns The partial input values of the form or the specified field.
509
642
  */
510
- 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>>;
511
644
  /**
512
645
  * Retrieves the current input value of a specific field or the entire form.
513
646
  * Returns a partial object as not all fields may have been set.
@@ -517,7 +650,7 @@ declare function getInput<TSchema extends Schema>(form: BaseFormStore<TSchema>):
517
650
  *
518
651
  * @returns The partial input values of the form or the specified field.
519
652
  */
520
- 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>>;
521
654
  //#endregion
522
655
  //#region src/handleSubmit/handleSubmit.d.ts
523
656
  /**
@@ -530,7 +663,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
530
663
  *
531
664
  * @returns A submit event handler function to attach to the form element.
532
665
  */
533
- 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>;
534
667
  /**
535
668
  * Creates a submit event handler for the form that prevents default browser
536
669
  * submission, validates the form input, and calls the provided handler if
@@ -541,13 +674,13 @@ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchem
541
674
  *
542
675
  * @returns A submit event handler function to attach to the form element.
543
676
  */
544
- 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>;
545
678
  //#endregion
546
679
  //#region src/insert/insert.d.ts
547
680
  /**
548
681
  * Insert array field config interface.
549
682
  */
550
- interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
683
+ interface InsertConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
551
684
  /**
552
685
  * The path to the field array to insert into.
553
686
  */
@@ -568,13 +701,13 @@ interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredP
568
701
  * @param form The form store containing the field array.
569
702
  * @param config The insert configuration specifying the path, index, and initial value.
570
703
  */
571
- 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;
572
705
  //#endregion
573
706
  //#region src/move/move.d.ts
574
707
  /**
575
708
  * Move array field config interface.
576
709
  */
577
- interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
710
+ interface MoveConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
578
711
  /**
579
712
  * The path to the field array to move an item within.
580
713
  */
@@ -595,13 +728,38 @@ interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPat
595
728
  * @param form The form store containing the field array.
596
729
  * @param config The move configuration specifying the path and source/destination indices.
597
730
  */
598
- 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;
599
757
  //#endregion
600
758
  //#region src/remove/remove.d.ts
601
759
  /**
602
760
  * Remove array field config interface.
603
761
  */
604
- interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
762
+ interface RemoveConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
605
763
  /**
606
764
  * The path to the field array to remove an item from.
607
765
  */
@@ -618,13 +776,13 @@ interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredP
618
776
  * @param form The form store containing the field array.
619
777
  * @param config The remove configuration specifying the path and index.
620
778
  */
621
- 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;
622
780
  //#endregion
623
781
  //#region src/replace/replace.d.ts
624
782
  /**
625
783
  * Replace array field config interface.
626
784
  */
627
- interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
785
+ interface ReplaceConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
628
786
  /**
629
787
  * The path to the field array to replace an item within.
630
788
  */
@@ -644,7 +802,7 @@ interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends Required
644
802
  * @param form The form store containing the field array.
645
803
  * @param config The replace configuration specifying the path, index, and initial input.
646
804
  */
647
- 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;
648
806
  //#endregion
649
807
  //#region src/reset/reset.d.ts
650
808
  /**
@@ -667,7 +825,7 @@ interface ResetBaseConfig {
667
825
  /**
668
826
  * Reset form config interface.
669
827
  */
670
- interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
828
+ interface ResetFormConfig<TSchema extends FormSchema> extends ResetBaseConfig {
671
829
  /**
672
830
  * The path to a field. Leave undefined to reset the entire form.
673
831
  */
@@ -685,7 +843,7 @@ interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
685
843
  /**
686
844
  * Reset field config interface.
687
845
  */
688
- interface ResetFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
846
+ interface ResetFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
689
847
  /**
690
848
  * The path to the field to reset.
691
849
  */
@@ -712,7 +870,7 @@ declare function reset(form: BaseFormStore): void;
712
870
  * @param form The form store to reset.
713
871
  * @param config The reset configuration specifying what to reset and what to keep.
714
872
  */
715
- 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;
716
874
  //#endregion
717
875
  //#region src/setErrors/setErrors.d.ts
718
876
  /**
@@ -731,7 +889,7 @@ interface SetFormErrorsConfig {
731
889
  /**
732
890
  * Set field errors config interface.
733
891
  */
734
- interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
892
+ interface SetFieldErrorsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
735
893
  /**
736
894
  * The path to the field to set errors on.
737
895
  */
@@ -749,13 +907,13 @@ interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends Requir
749
907
  * @param form The form store to set errors on.
750
908
  * @param config The set errors configuration specifying the path and error messages.
751
909
  */
752
- 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;
753
911
  //#endregion
754
912
  //#region src/setInput/setInput.d.ts
755
913
  /**
756
914
  * Set form input config interface.
757
915
  */
758
- interface SetFormInputConfig<TSchema extends Schema> {
916
+ interface SetFormInputConfig<TSchema extends FormSchema> {
759
917
  /**
760
918
  * The path to a field. Leave undefined to set the entire form input.
761
919
  */
@@ -768,7 +926,7 @@ interface SetFormInputConfig<TSchema extends Schema> {
768
926
  /**
769
927
  * Set field input config interface.
770
928
  */
771
- interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
929
+ interface SetFieldInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
772
930
  /**
773
931
  * The path to the field to set input on.
774
932
  */
@@ -786,7 +944,7 @@ interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends Require
786
944
  * @param form The form store to set input on.
787
945
  * @param config The set form input configuration specifying the new input values.
788
946
  */
789
- 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;
790
948
  /**
791
949
  * Sets the input value of a specific field or the entire form. This updates
792
950
  * the field value(s) and triggers validation if required by the form's
@@ -795,7 +953,7 @@ declare function setInput<TSchema extends Schema>(form: BaseFormStore<TSchema>,
795
953
  * @param form The form store to set input on.
796
954
  * @param config The set input configuration specifying the path and new value.
797
955
  */
798
- 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;
799
957
  //#endregion
800
958
  //#region src/submit/submit.d.ts
801
959
  /**
@@ -810,7 +968,7 @@ declare function submit(form: BaseFormStore): void;
810
968
  /**
811
969
  * Swap array field config interface.
812
970
  */
813
- interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
971
+ interface SwapConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
814
972
  /**
815
973
  * The path to the field array to swap items within.
816
974
  */
@@ -830,7 +988,7 @@ interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPat
830
988
  * @param form The form store containing the field array.
831
989
  * @param config The swap configuration specifying the path and indices to swap.
832
990
  */
833
- 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;
834
992
  //#endregion
835
993
  //#region src/validate/validate.d.ts
836
994
  /**
@@ -852,7 +1010,7 @@ interface ValidateFormConfig {
852
1010
  *
853
1011
  * @returns A promise resolving to the validation result.
854
1012
  */
855
- 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>>;
856
1014
  //#endregion
857
1015
  //#endregion
858
1016
  //#region src/types/field.d.ts
@@ -871,28 +1029,28 @@ interface FieldElementProps {
871
1029
  /**
872
1030
  * The ref callback to register the field element.
873
1031
  */
874
- readonly ref: (element: FieldElement) => void;
1032
+ readonly ref: (element: FieldElement | null) => void;
875
1033
  /**
876
1034
  * The focus event handler of the field element.
877
1035
  */
878
- readonly onFocus: JSX.FocusEventHandler<FieldElement>;
1036
+ readonly onFocus: FocusEventHandler<FieldElement>;
879
1037
  /**
880
1038
  * The input event handler of the field element.
881
1039
  */
882
- readonly onInput: JSX.InputEventHandler<FieldElement>;
1040
+ readonly onInput: InputEventHandler<FieldElement>;
883
1041
  /**
884
1042
  * The change event handler of the field element.
885
1043
  */
886
- readonly onChange: JSX.GenericEventHandler<FieldElement>;
1044
+ readonly onChange: GenericEventHandler<FieldElement>;
887
1045
  /**
888
1046
  * The blur event handler of the field element.
889
1047
  */
890
- readonly onBlur: JSX.FocusEventHandler<FieldElement>;
1048
+ readonly onBlur: FocusEventHandler<FieldElement>;
891
1049
  }
892
1050
  /**
893
1051
  * Field store interface.
894
1052
  */
895
- interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
1053
+ interface FieldStore<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
896
1054
  /**
897
1055
  * The path to the field within the form.
898
1056
  */
@@ -929,7 +1087,7 @@ interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends Require
929
1087
  /**
930
1088
  * Field array store interface.
931
1089
  */
932
- interface FieldArrayStore<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1090
+ interface FieldArrayStore<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
933
1091
  /**
934
1092
  * The path to the array field within the form.
935
1093
  */
@@ -960,7 +1118,7 @@ interface FieldArrayStore<TSchema extends Schema = Schema, TFieldArrayPath exten
960
1118
  /**
961
1119
  * Form store interface.
962
1120
  */
963
- interface FormStore<TSchema extends Schema = Schema> extends BaseFormStore<TSchema> {
1121
+ interface FormStore<TSchema extends FormSchema = FormSchema> extends BaseFormStore<TSchema> {
964
1122
  /**
965
1123
  * Whether the form is currently submitting.
966
1124
  */
@@ -998,7 +1156,7 @@ interface FormStore<TSchema extends Schema = Schema> extends BaseFormStore<TSche
998
1156
  /**
999
1157
  * Field component props interface.
1000
1158
  */
1001
- interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
1159
+ interface FieldProps<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
1002
1160
  /**
1003
1161
  * The form store to which the field belongs.
1004
1162
  */
@@ -1021,7 +1179,7 @@ interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends Require
1021
1179
  *
1022
1180
  * @returns The UI of the field to be rendered.
1023
1181
  */
1024
- declare function Field<TSchema extends Schema, TFieldPath extends RequiredPath>({
1182
+ declare function Field<TSchema extends FormSchema, TFieldPath extends RequiredPath>({
1025
1183
  of,
1026
1184
  path,
1027
1185
  children
@@ -1031,7 +1189,7 @@ declare function Field<TSchema extends Schema, TFieldPath extends RequiredPath>(
1031
1189
  /**
1032
1190
  * FieldArray component props interface.
1033
1191
  */
1034
- interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1192
+ interface FieldArrayProps<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1035
1193
  /**
1036
1194
  * The form store to which the field array belongs.
1037
1195
  */
@@ -1055,7 +1213,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
1055
1213
  *
1056
1214
  * @returns The UI of the field array to be rendered.
1057
1215
  */
1058
- declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>({
1216
+ declare function FieldArray<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>({
1059
1217
  of,
1060
1218
  path,
1061
1219
  children
@@ -1065,7 +1223,7 @@ declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends Requ
1065
1223
  /**
1066
1224
  * Form component props type.
1067
1225
  */
1068
- 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"> & {
1069
1227
  /**
1070
1228
  * The form store instance.
1071
1229
  */
@@ -1083,13 +1241,13 @@ type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HT
1083
1241
  *
1084
1242
  * @returns The a native form element.
1085
1243
  */
1086
- declare function Form<TSchema extends Schema>(props: FormProps<TSchema>): JSX.Element;
1244
+ declare function Form<TSchema extends FormSchema>(props: FormProps<TSchema>): JSX.Element;
1087
1245
  //#endregion
1088
1246
  //#region src/hooks/useField/useField.d.ts
1089
1247
  /**
1090
1248
  * Use field config interface.
1091
1249
  */
1092
- interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
1250
+ interface UseFieldConfig<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
1093
1251
  /**
1094
1252
  * The path to the field within the form schema.
1095
1253
  */
@@ -1103,13 +1261,13 @@ interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends Req
1103
1261
  *
1104
1262
  * @returns The field store with reactive properties and element props.
1105
1263
  */
1106
- 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>;
1107
1265
  //#endregion
1108
1266
  //#region src/hooks/useFieldArray/useFieldArray.d.ts
1109
1267
  /**
1110
1268
  * Use field array config interface.
1111
1269
  */
1112
- interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1270
+ interface UseFieldArrayConfig<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
1113
1271
  /**
1114
1272
  * The path to the array field within the form schema.
1115
1273
  */
@@ -1123,7 +1281,7 @@ interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath e
1123
1281
  *
1124
1282
  * @returns The field array store with reactive properties for array management.
1125
1283
  */
1126
- 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>;
1127
1285
  //#endregion
1128
1286
  //#region src/hooks/useForm/useForm.d.ts
1129
1287
  /**
@@ -1134,6 +1292,6 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
1134
1292
  *
1135
1293
  * @returns The form store with reactive properties.
1136
1294
  */
1137
- declare function useForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
1295
+ declare function useForm<TSchema extends FormSchema>(config: FormConfig<TSchema>): FormStore<TSchema>;
1138
1296
  //#endregion
1139
- 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
@@ -233,6 +233,63 @@ function swapItemState(firstInternalFieldStore, secondInternalFieldStore) {
233
233
  });
234
234
  }
235
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
+ /**
236
293
  * Returns the current input of the field store. For arrays and objects,
237
294
  * recursively collects input from all children. Returns `null` or `undefined`
238
295
  * for nullish array/object inputs, or the primitive value for value fields.
@@ -289,28 +346,6 @@ function getElementInput(element, internalFieldStore) {
289
346
  return element.value;
290
347
  }
291
348
  /**
292
- * Returns whether the specified boolean property is true for the field store
293
- * or any of its nested children. Recursively checks arrays and objects.
294
- *
295
- * @param internalFieldStore The field store to check.
296
- * @param type The boolean property type to check.
297
- *
298
- * @returns Whether the property is true.
299
- */
300
- /* @__NO_SIDE_EFFECTS__ */
301
- function getFieldBool(internalFieldStore, type) {
302
- if (internalFieldStore[type].value) return true;
303
- if (internalFieldStore.kind === "array") {
304
- for (let index = 0; index < internalFieldStore.items.value.length; index++) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[index], type)) return true;
305
- return false;
306
- }
307
- if (internalFieldStore.kind == "object") {
308
- for (const key in internalFieldStore.children) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[key], type)) return true;
309
- return false;
310
- }
311
- return false;
312
- }
313
- /**
314
349
  * Returns the field store at the specified path by traversing the form store's
315
350
  * children hierarchy.
316
351
  *
@@ -567,6 +602,17 @@ function getAllErrors(form) {
567
602
  return allErrors;
568
603
  }
569
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__ */
570
616
  function getErrors(form, config) {
571
617
  return (config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL]).errors.value;
572
618
  }
@@ -660,6 +706,48 @@ function move(form, config) {
660
706
  });
661
707
  }
662
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
+ /**
663
751
  * Removes an item from a field array at the specified index. All items after
664
752
  * the removed item are shifted down by one index.
665
753
  *
@@ -952,4 +1040,4 @@ function Form({ of, onSubmit, ...other }) {
952
1040
  }
953
1041
 
954
1042
  //#endregion
955
- 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
3
  "description": "The lightweight, schema-first, and fully type-safe form library for Preact",
4
- "version": "0.9.6",
4
+ "version": "0.10.0",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -44,18 +44,18 @@
44
44
  "@formisch/core": "workspace:*",
45
45
  "@formisch/eslint-config": "workspace:*",
46
46
  "@formisch/methods": "workspace:*",
47
- "@preact/preset-vite": "^2.9.3",
48
- "@preact/signals": "^2.2.1",
47
+ "@preact/preset-vite": "^2.10.5",
48
+ "@preact/signals": "^2.9.0",
49
49
  "@testing-library/jest-dom": "^6.6.0",
50
50
  "@testing-library/preact": "^3.2.4",
51
51
  "@vitest/coverage-v8": "^3.2.4",
52
52
  "eslint": "^9.31.0",
53
53
  "eslint-config-preact": "^2.0.0",
54
54
  "jsdom": "^26.1.0",
55
- "preact": "^10.25.3",
55
+ "preact": "^10.29.2",
56
56
  "tsdown": "^0.16.8",
57
57
  "typescript": "^5.8.3",
58
- "valibot": "^1.2.0",
58
+ "valibot": "^1.4.1",
59
59
  "vite": "^6.0.4",
60
60
  "vitest": "^3.2.4"
61
61
  },
@@ -63,7 +63,7 @@
63
63
  "@preact/signals": "^2.0.0",
64
64
  "preact": "^10.0.0",
65
65
  "typescript": ">=5",
66
- "valibot": "^1.0.0"
66
+ "valibot": "^1.4.1"
67
67
  },
68
68
  "peerDependenciesMeta": {
69
69
  "typescript": {