@angular/forms 21.0.0-rc.1 → 21.0.0-rc.2
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 +1 -2
- package/fesm2022/forms.mjs +132 -133
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals.mjs +140 -65
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/types/forms.d.ts +26 -1
- package/types/signals.d.ts +236 -141
package/types/signals.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.0.0-rc.
|
|
2
|
+
* @license Angular v21.0.0-rc.2
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { HttpResourceRequest, HttpResourceOptions } from '@angular/common/http';
|
|
8
8
|
import * as i0 from '@angular/core';
|
|
9
|
-
import { InjectionToken, ɵControl as _Control, ɵCONTROL as _CONTROL, ɵFieldState as _FieldState, Signal, ResourceRef, InputSignal, ModelSignal, OutputRef, WritableSignal, DestroyableInjector, Injector } from '@angular/core';
|
|
9
|
+
import { InjectionToken, ɵControl as _Control, ɵCONTROL as _CONTROL, ɵInteropControl as _InteropControl, ɵFieldState as _FieldState, Signal, ResourceRef, InputSignal, ModelSignal, OutputRef, WritableSignal, DestroyableInjector, Injector } from '@angular/core';
|
|
10
|
+
import * as _angular_forms from '@angular/forms';
|
|
10
11
|
import { NgControl, AbstractControl, ValidationErrors, FormControlStatus, ControlValueAccessor, ValidatorFn } from '@angular/forms';
|
|
11
12
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
12
13
|
|
|
@@ -71,19 +72,16 @@ declare const FIELD: InjectionToken<Field<unknown>>;
|
|
|
71
72
|
declare class Field<T> implements _Control<T> {
|
|
72
73
|
private readonly injector;
|
|
73
74
|
readonly field: i0.InputSignal<FieldTree<T>>;
|
|
74
|
-
readonly state: i0.Signal<FieldState<T, string | number>>;
|
|
75
|
+
readonly state: i0.Signal<[T] extends [_angular_forms.AbstractControl<any, any, any>] ? CompatFieldState<T, string | number> : FieldState<T, string | number>>;
|
|
75
76
|
readonly [_CONTROL]: undefined;
|
|
76
77
|
/** Any `ControlValueAccessor` instances provided on the host element. */
|
|
77
78
|
private readonly controlValueAccessors;
|
|
78
79
|
/** A lazily instantiated fake `NgControl`. */
|
|
79
80
|
private interopNgControl;
|
|
80
81
|
/** A `ControlValueAccessor`, if configured, for the host component. */
|
|
81
|
-
|
|
82
|
-
get ɵhasInteropControl(): boolean;
|
|
82
|
+
get ɵinteropControl(): _InteropControl | undefined;
|
|
83
83
|
/** Lazily instantiates a fake `NgControl` for this field. */
|
|
84
|
-
|
|
85
|
-
ɵinteropControlCreate(): void;
|
|
86
|
-
ɵinteropControlUpdate(): void;
|
|
84
|
+
protected getOrCreateNgControl(): InteropNgControl;
|
|
87
85
|
ɵregister(): void;
|
|
88
86
|
static ɵfac: i0.ɵɵFactoryDeclaration<Field<any>, never>;
|
|
89
87
|
static ɵdir: i0.ɵɵDirectiveDeclaration<Field<any>, "[field]", never, { "field": { "alias": "field"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
@@ -130,7 +128,7 @@ declare class AggregateMetadataKey<TAcc, TItem> {
|
|
|
130
128
|
*
|
|
131
129
|
* @experimental 21.0.0
|
|
132
130
|
*/
|
|
133
|
-
declare function reducedMetadataKey<TAcc, TItem>(reduce: (acc: TAcc, item: TItem) => TAcc, getInitial: () => TAcc): AggregateMetadataKey<TAcc, TItem>;
|
|
131
|
+
declare function reducedMetadataKey<TAcc, TItem>(reduce: (acc: TAcc, item: TItem) => TAcc, getInitial: NoInfer<() => TAcc>): AggregateMetadataKey<TAcc, TItem>;
|
|
134
132
|
/**
|
|
135
133
|
* Creates an {@link AggregateMetadataKey} that reduces its individual values into a list.
|
|
136
134
|
*
|
|
@@ -386,7 +384,7 @@ declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: Va
|
|
|
386
384
|
* @category validation
|
|
387
385
|
* @experimental 21.0.0
|
|
388
386
|
*/
|
|
389
|
-
declare function customError<E extends Partial<
|
|
387
|
+
declare function customError<E extends Partial<ValidationError.WithField>>(obj: WithField<E>): CustomValidationError;
|
|
390
388
|
/**
|
|
391
389
|
* Create a custom error
|
|
392
390
|
* @param obj The object to create an error from
|
|
@@ -394,7 +392,7 @@ declare function customError<E extends Partial<ValidationErrorWithField>>(obj: W
|
|
|
394
392
|
* @category validation
|
|
395
393
|
* @experimental 21.0.0
|
|
396
394
|
*/
|
|
397
|
-
declare function customError<E extends Partial<
|
|
395
|
+
declare function customError<E extends Partial<ValidationError.WithField>>(obj?: E): WithoutField<CustomValidationError>;
|
|
398
396
|
/**
|
|
399
397
|
* Common interface for all validation errors.
|
|
400
398
|
*
|
|
@@ -412,34 +410,36 @@ interface ValidationError {
|
|
|
412
410
|
/** Human readable error message. */
|
|
413
411
|
readonly message?: string;
|
|
414
412
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
413
|
+
declare namespace ValidationError {
|
|
414
|
+
/**
|
|
415
|
+
* Validation error with a field.
|
|
416
|
+
*
|
|
417
|
+
* This is returned from field state, e.g., catField.errors() would be of a list of errors with
|
|
418
|
+
* `field: catField` bound to state.
|
|
419
|
+
*/
|
|
420
|
+
interface WithField extends ValidationError {
|
|
421
|
+
/** The field associated with this error. */
|
|
422
|
+
readonly field: FieldTree<unknown>;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Validation error with optional field.
|
|
426
|
+
*
|
|
427
|
+
* This is generally used in places where the result might have a field.
|
|
428
|
+
* e.g., as a result of a `validateTree`, or when handling form submission.
|
|
429
|
+
*/
|
|
430
|
+
interface WithOptionalField extends ValidationError {
|
|
431
|
+
/** The field associated with this error. */
|
|
432
|
+
readonly field?: FieldTree<unknown>;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Validation error with no field.
|
|
436
|
+
*
|
|
437
|
+
* This is used to strongly enforce that fields are not allowed in validation result.
|
|
438
|
+
*/
|
|
439
|
+
interface WithoutField extends ValidationError {
|
|
440
|
+
/** The field associated with this error. */
|
|
441
|
+
readonly field?: never;
|
|
442
|
+
}
|
|
443
443
|
}
|
|
444
444
|
/**
|
|
445
445
|
* A custom error that may contain additional properties
|
|
@@ -673,7 +673,7 @@ type ValidationSuccess = null | undefined | void;
|
|
|
673
673
|
* @category types
|
|
674
674
|
* @experimental 21.0.0
|
|
675
675
|
*/
|
|
676
|
-
type TreeValidationResult<E extends
|
|
676
|
+
type TreeValidationResult<E extends ValidationError.WithOptionalField = ValidationError.WithOptionalField> = ValidationSuccess | OneOrMany<E>;
|
|
677
677
|
/**
|
|
678
678
|
* A validation result where all errors explicitly define their target field.
|
|
679
679
|
*
|
|
@@ -714,16 +714,18 @@ type AsyncValidationResult<E extends ValidationError = ValidationError> = Valida
|
|
|
714
714
|
* @category types
|
|
715
715
|
* @experimental 21.0.0
|
|
716
716
|
*/
|
|
717
|
-
type FieldTree<
|
|
717
|
+
type FieldTree<TModel, TKey extends string | number = string | number> = (() => [TModel] extends [AbstractControl] ? CompatFieldState<TModel, TKey> : FieldState<TModel, TKey>) & ([TModel] extends [AbstractControl] ? object : [TModel] extends [Array<infer U>] ? ReadonlyArrayLike<MaybeFieldTree<U, number>> : TModel extends Record<string, any> ? Subfields<TModel> : object);
|
|
718
718
|
/**
|
|
719
|
-
* The sub-fields that a user can navigate to from a `FieldTree<
|
|
719
|
+
* The sub-fields that a user can navigate to from a `FieldTree<TModel>`.
|
|
720
720
|
*
|
|
721
|
-
* @template
|
|
721
|
+
* @template TModel The type of the data which the parent field is wrapped around.
|
|
722
722
|
*
|
|
723
723
|
* @experimental 21.0.0
|
|
724
724
|
*/
|
|
725
|
-
type Subfields<
|
|
726
|
-
readonly [K in keyof
|
|
725
|
+
type Subfields<TModel> = {
|
|
726
|
+
readonly [K in keyof TModel as TModel[K] extends Function ? never : K]: MaybeFieldTree<TModel[K], string>;
|
|
727
|
+
} & {
|
|
728
|
+
[Symbol.iterator](): Iterator<[string, MaybeFieldTree<TModel[keyof TModel], string>]>;
|
|
727
729
|
};
|
|
728
730
|
/**
|
|
729
731
|
* An iterable object with the same shape as a readonly array.
|
|
@@ -740,12 +742,12 @@ type ReadonlyArrayLike<T> = Pick<ReadonlyArray<T>, number | 'length' | typeof Sy
|
|
|
740
742
|
* For example `MaybeField<{a: number} | undefined, TKey>` would be equivalent to
|
|
741
743
|
* `undefined | FieldTree<{a: number}, TKey>`.
|
|
742
744
|
*
|
|
743
|
-
* @template
|
|
745
|
+
* @template TModel The type of the data which the field is wrapped around.
|
|
744
746
|
* @template TKey The type of the property key which this field resides under in its parent.
|
|
745
747
|
*
|
|
746
748
|
* @experimental 21.0.0
|
|
747
749
|
*/
|
|
748
|
-
type MaybeFieldTree<
|
|
750
|
+
type MaybeFieldTree<TModel, TKey extends string | number = string | number> = (TModel & undefined) | FieldTree<Exclude<TModel, undefined>, TKey>;
|
|
749
751
|
/**
|
|
750
752
|
* Contains all of the state (e.g. value, statuses, etc.) associated with a `FieldTree`, exposed as
|
|
751
753
|
* signals.
|
|
@@ -772,11 +774,11 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
772
774
|
*/
|
|
773
775
|
readonly hidden: Signal<boolean>;
|
|
774
776
|
readonly disabledReasons: Signal<readonly DisabledReason[]>;
|
|
775
|
-
readonly errors: Signal<
|
|
777
|
+
readonly errors: Signal<ValidationError.WithField[]>;
|
|
776
778
|
/**
|
|
777
779
|
* A signal containing the {@link errors} of the field and its descendants.
|
|
778
780
|
*/
|
|
779
|
-
readonly errorSummary: Signal<
|
|
781
|
+
readonly errorSummary: Signal<ValidationError.WithField[]>;
|
|
780
782
|
/**
|
|
781
783
|
* A signal indicating whether the field's value is currently valid.
|
|
782
784
|
*
|
|
@@ -839,6 +841,31 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
839
841
|
*/
|
|
840
842
|
reset(): void;
|
|
841
843
|
}
|
|
844
|
+
/**
|
|
845
|
+
* This is FieldState also providing access to the wrapped FormControl.
|
|
846
|
+
*
|
|
847
|
+
* @category interop
|
|
848
|
+
* @experimental 21.0.0
|
|
849
|
+
*/
|
|
850
|
+
type CompatFieldState<TControl extends AbstractControl, TKey extends string | number = string | number> = FieldState<TControl extends AbstractControl<unknown, infer TValue> ? TValue : never, TKey> & {
|
|
851
|
+
control: Signal<TControl>;
|
|
852
|
+
};
|
|
853
|
+
/**
|
|
854
|
+
* Allows declaring whether the Rules are supported for a given path.
|
|
855
|
+
*
|
|
856
|
+
* @experimental 21.0.0
|
|
857
|
+
**/
|
|
858
|
+
type SchemaPathRules = SchemaPathRules.Supported | SchemaPathRules.Unsupported;
|
|
859
|
+
declare namespace SchemaPathRules {
|
|
860
|
+
/**
|
|
861
|
+
* Used for paths that support settings rules.
|
|
862
|
+
*/
|
|
863
|
+
type Supported = 1;
|
|
864
|
+
/**
|
|
865
|
+
* Used for paths that do not support settings rules, e.g., compatPath.
|
|
866
|
+
*/
|
|
867
|
+
type Unsupported = 2;
|
|
868
|
+
}
|
|
842
869
|
/**
|
|
843
870
|
* An object that represents a location in the `FieldTree` tree structure and is used to bind logic to a
|
|
844
871
|
* particular part of the structure prior to the creation of the form. Because the `FieldPath`
|
|
@@ -850,10 +877,34 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
850
877
|
* @category types
|
|
851
878
|
* @experimental 21.0.0
|
|
852
879
|
*/
|
|
853
|
-
type
|
|
854
|
-
[ɵɵTYPE]:
|
|
855
|
-
|
|
856
|
-
|
|
880
|
+
type SchemaPath<TValue, TSupportsRules extends SchemaPathRules = SchemaPathRules.Supported, TPathKind extends PathKind = PathKind.Root> = {
|
|
881
|
+
[ɵɵTYPE]: {
|
|
882
|
+
value: () => TValue;
|
|
883
|
+
supportsRules: TSupportsRules;
|
|
884
|
+
pathKind: TPathKind;
|
|
885
|
+
};
|
|
886
|
+
};
|
|
887
|
+
/**
|
|
888
|
+
* Schema path used if the value is an AbstractControl.
|
|
889
|
+
*
|
|
890
|
+
* @category interop
|
|
891
|
+
* @experimental 21.0.0
|
|
892
|
+
*/
|
|
893
|
+
type CompatSchemaPath<TControl extends AbstractControl, TPathKind extends PathKind = PathKind.Root> = SchemaPath<TControl extends AbstractControl<unknown, infer TValue> ? TValue : never, SchemaPathRules.Unsupported, TPathKind> & {
|
|
894
|
+
[ɵɵTYPE]: {
|
|
895
|
+
control: TControl;
|
|
896
|
+
};
|
|
897
|
+
};
|
|
898
|
+
/**
|
|
899
|
+
* Nested schema path.
|
|
900
|
+
*
|
|
901
|
+
* It mirrors the structure of a given data structure, and allows applying rules to the appropriate
|
|
902
|
+
* fields.
|
|
903
|
+
*
|
|
904
|
+
* @experimental 21.0.0
|
|
905
|
+
*/
|
|
906
|
+
type SchemaPathTree<TModel, TPathKind extends PathKind = PathKind.Root> = (TModel extends AbstractControl ? CompatSchemaPath<TModel, TPathKind> : SchemaPath<TModel, SchemaPathRules.Supported, TPathKind>) & (TModel extends AbstractControl ? unknown : TModel extends Array<any> ? unknown : TModel extends Record<string, any> ? {
|
|
907
|
+
[K in keyof TModel]: MaybeSchemaPathTree<TModel[K], PathKind.Child>;
|
|
857
908
|
} : unknown);
|
|
858
909
|
/**
|
|
859
910
|
* Helper type for defining `FieldPath`. Given a type `TValue` that may include `undefined`, it
|
|
@@ -867,7 +918,7 @@ type FieldPath<TValue, TPathKind extends PathKind = PathKind.Root> = {
|
|
|
867
918
|
*
|
|
868
919
|
* @experimental 21.0.0
|
|
869
920
|
*/
|
|
870
|
-
type
|
|
921
|
+
type MaybeSchemaPathTree<TModel, TPathKind extends PathKind = PathKind.Root> = (TModel & undefined) | SchemaPathTree<Exclude<TModel, undefined>, TPathKind>;
|
|
871
922
|
/**
|
|
872
923
|
* Defines logic for a form.
|
|
873
924
|
*
|
|
@@ -876,29 +927,29 @@ type MaybeFieldPath<TValue, TPathKind extends PathKind = PathKind.Root> = (TValu
|
|
|
876
927
|
* @category types
|
|
877
928
|
* @experimental 21.0.0
|
|
878
929
|
*/
|
|
879
|
-
type Schema<in
|
|
880
|
-
[ɵɵTYPE]: SchemaFn<
|
|
930
|
+
type Schema<in TModel> = {
|
|
931
|
+
[ɵɵTYPE]: SchemaFn<TModel, PathKind.Root>;
|
|
881
932
|
};
|
|
882
933
|
/**
|
|
883
934
|
* Function that defines rules for a schema.
|
|
884
935
|
*
|
|
885
|
-
* @template
|
|
936
|
+
* @template TModel The type of data stored in the form that this schema function is attached to.
|
|
886
937
|
* @template TPathKind The kind of path this schema function can be bound to.
|
|
887
938
|
*
|
|
888
939
|
* @category types
|
|
889
940
|
* @experimental 21.0.0
|
|
890
941
|
*/
|
|
891
|
-
type SchemaFn<
|
|
942
|
+
type SchemaFn<TModel, TPathKind extends PathKind = PathKind.Root> = (p: SchemaPathTree<TModel, TPathKind>) => void;
|
|
892
943
|
/**
|
|
893
944
|
* A schema or schema definition function.
|
|
894
945
|
*
|
|
895
|
-
* @template
|
|
946
|
+
* @template TModel The type of data stored in the form that this schema function is attached to.
|
|
896
947
|
* @template TPathKind The kind of path this schema function can be bound to.
|
|
897
948
|
*
|
|
898
949
|
* @category types
|
|
899
950
|
* @experimental 21.0.0
|
|
900
951
|
*/
|
|
901
|
-
type SchemaOrSchemaFn<
|
|
952
|
+
type SchemaOrSchemaFn<TModel, TPathKind extends PathKind = PathKind.Root> = Schema<TModel> | SchemaFn<TModel, TPathKind>;
|
|
902
953
|
/**
|
|
903
954
|
* A function that receives the `FieldContext` for the field the logic is bound to and returns
|
|
904
955
|
* a specific result type.
|
|
@@ -921,7 +972,7 @@ type LogicFn<TValue, TReturn, TPathKind extends PathKind = PathKind.Root> = (ctx
|
|
|
921
972
|
* @category validation
|
|
922
973
|
* @experimental 21.0.0
|
|
923
974
|
*/
|
|
924
|
-
type FieldValidator<TValue, TPathKind extends PathKind = PathKind.Root> = LogicFn<TValue, ValidationResult<
|
|
975
|
+
type FieldValidator<TValue, TPathKind extends PathKind = PathKind.Root> = LogicFn<TValue, ValidationResult<ValidationError.WithoutField>, TPathKind>;
|
|
925
976
|
/**
|
|
926
977
|
* A function that takes the `FieldContext` for the field being validated and returns a
|
|
927
978
|
* `TreeValidationResult` indicating errors for the field and its sub-fields.
|
|
@@ -966,11 +1017,14 @@ interface RootFieldContext<TValue> {
|
|
|
966
1017
|
/** The current field. */
|
|
967
1018
|
readonly field: FieldTree<TValue>;
|
|
968
1019
|
/** Gets the value of the field represented by the given path. */
|
|
969
|
-
|
|
1020
|
+
valueOf<PValue>(p: SchemaPath<PValue, SchemaPathRules>): PValue;
|
|
970
1021
|
/** Gets the state of the field represented by the given path. */
|
|
971
|
-
|
|
1022
|
+
stateOf<PControl extends AbstractControl>(p: CompatSchemaPath<PControl>): CompatFieldState<PControl>;
|
|
1023
|
+
stateOf<PValue>(p: SchemaPath<PValue, SchemaPathRules>): FieldState<PValue>;
|
|
972
1024
|
/** Gets the field represented by the given path. */
|
|
973
|
-
|
|
1025
|
+
fieldTreeOf<PModel>(p: SchemaPathTree<PModel>): FieldTree<PModel>;
|
|
1026
|
+
/** The list of keys that lead from the root field to the current field. */
|
|
1027
|
+
readonly pathKeys: Signal<readonly string[]>;
|
|
974
1028
|
}
|
|
975
1029
|
/**
|
|
976
1030
|
* Field context that is available for all fields that are a child of another field.
|
|
@@ -991,6 +1045,24 @@ interface ItemFieldContext<TValue> extends ChildFieldContext<TValue> {
|
|
|
991
1045
|
/** The index of the current field in its parent field. */
|
|
992
1046
|
readonly index: Signal<number>;
|
|
993
1047
|
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Gets the item type of an object that is possibly an array.
|
|
1050
|
+
*
|
|
1051
|
+
* @experimental 21.0.0
|
|
1052
|
+
*/
|
|
1053
|
+
type ItemType<T extends Object> = T extends ReadonlyArray<any> ? T[number] : T[keyof T];
|
|
1054
|
+
/**
|
|
1055
|
+
* A function that defines custom debounce logic for a field.
|
|
1056
|
+
*
|
|
1057
|
+
* This function receives the {@link FieldContext} for the field and should return a `Promise<void>`
|
|
1058
|
+
* to delay an update, or `void` to apply an update immediately.
|
|
1059
|
+
*
|
|
1060
|
+
* @template TValue The type of value stored in the field.
|
|
1061
|
+
* @template TPathKind The kind of path the debouncer is applied to (root field, child field, or item of an array).
|
|
1062
|
+
*
|
|
1063
|
+
* @experimental 21.0.0
|
|
1064
|
+
*/
|
|
1065
|
+
type Debouncer<TValue, TPathKind extends PathKind = PathKind.Root> = (context: FieldContext<TValue, TPathKind>) => Promise<void> | void;
|
|
994
1066
|
|
|
995
1067
|
/**
|
|
996
1068
|
* A function that takes the result of an async operation and the current field context, and maps it
|
|
@@ -1112,7 +1184,7 @@ interface HttpValidatorOptions<TValue, TResult, TPathKind extends PathKind = Pat
|
|
|
1112
1184
|
* @category validation
|
|
1113
1185
|
* @experimental 21.0.0
|
|
1114
1186
|
*/
|
|
1115
|
-
declare function validateAsync<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1187
|
+
declare function validateAsync<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: AsyncValidatorOptions<TValue, TParams, TResult, TPathKind>): void;
|
|
1116
1188
|
/**
|
|
1117
1189
|
* Adds async validation to the field corresponding to the given path based on an httpResource.
|
|
1118
1190
|
* Async validation for a field only runs once all synchronous validation is passing.
|
|
@@ -1126,7 +1198,7 @@ declare function validateAsync<TValue, TParams, TResult, TPathKind extends PathK
|
|
|
1126
1198
|
* @category validation
|
|
1127
1199
|
* @experimental 21.0.0
|
|
1128
1200
|
*/
|
|
1129
|
-
declare function validateHttp<TValue, TResult = unknown, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1201
|
+
declare function validateHttp<TValue, TResult = unknown, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: HttpValidatorOptions<TValue, TResult, TPathKind>): void;
|
|
1130
1202
|
|
|
1131
1203
|
/**
|
|
1132
1204
|
* The base set of properties shared by all form control contracts.
|
|
@@ -1267,6 +1339,20 @@ interface FormCheckboxControl extends FormUiControl {
|
|
|
1267
1339
|
readonly value?: undefined;
|
|
1268
1340
|
}
|
|
1269
1341
|
|
|
1342
|
+
/**
|
|
1343
|
+
* Configures the frequency at which a form field is updated by UI events.
|
|
1344
|
+
*
|
|
1345
|
+
* When this rule is applied, updates from the UI to the form model will be delayed until either
|
|
1346
|
+
* the field is touched, or the most recently debounced update resolves.
|
|
1347
|
+
*
|
|
1348
|
+
* @param path The target path to debounce.
|
|
1349
|
+
* @param durationOrDebouncer Either a debounce duration in milliseconds, or a custom
|
|
1350
|
+
* {@link Debouncer} function.
|
|
1351
|
+
*
|
|
1352
|
+
* @experimental 21.0.0
|
|
1353
|
+
*/
|
|
1354
|
+
declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, durationOrDebouncer: number | Debouncer<TValue, TPathKind>): void;
|
|
1355
|
+
|
|
1270
1356
|
/**
|
|
1271
1357
|
* Adds logic to a field to conditionally disable it. A disabled field does not contribute to the
|
|
1272
1358
|
* validation, touched/dirty, or other state of its parent field.
|
|
@@ -1280,7 +1366,7 @@ interface FormCheckboxControl extends FormUiControl {
|
|
|
1280
1366
|
* @category logic
|
|
1281
1367
|
* @experimental 21.0.0
|
|
1282
1368
|
*/
|
|
1283
|
-
declare function disabled<TValue, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1369
|
+
declare function disabled<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: string | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>): void;
|
|
1284
1370
|
/**
|
|
1285
1371
|
* Adds logic to a field to conditionally make it readonly. A readonly field does not contribute to
|
|
1286
1372
|
* the validation, touched/dirty, or other state of its parent field.
|
|
@@ -1293,7 +1379,7 @@ declare function disabled<TValue, TPathKind extends PathKind = PathKind.Root>(pa
|
|
|
1293
1379
|
* @category logic
|
|
1294
1380
|
* @experimental 21.0.0
|
|
1295
1381
|
*/
|
|
1296
|
-
declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1382
|
+
declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
|
|
1297
1383
|
/**
|
|
1298
1384
|
* Adds logic to a field to conditionally hide it. A hidden field does not contribute to the
|
|
1299
1385
|
* validation, touched/dirty, or other state of its parent field.
|
|
@@ -1314,7 +1400,7 @@ declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(pa
|
|
|
1314
1400
|
* @category logic
|
|
1315
1401
|
* @experimental 21.0.0
|
|
1316
1402
|
*/
|
|
1317
|
-
declare function hidden<TValue, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1403
|
+
declare function hidden<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
|
|
1318
1404
|
/**
|
|
1319
1405
|
* Adds logic to a field to determine if the field has validation errors.
|
|
1320
1406
|
*
|
|
@@ -1326,7 +1412,7 @@ declare function hidden<TValue, TPathKind extends PathKind = PathKind.Root>(path
|
|
|
1326
1412
|
* @category logic
|
|
1327
1413
|
* @experimental 21.0.0
|
|
1328
1414
|
*/
|
|
1329
|
-
declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1415
|
+
declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<FieldValidator<TValue, TPathKind>>): void;
|
|
1330
1416
|
/**
|
|
1331
1417
|
* Adds logic to a field to determine if the field or any of its child fields has validation errors.
|
|
1332
1418
|
*
|
|
@@ -1339,7 +1425,7 @@ declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(pa
|
|
|
1339
1425
|
* @category logic
|
|
1340
1426
|
* @experimental 21.0.0
|
|
1341
1427
|
*/
|
|
1342
|
-
declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1428
|
+
declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<TreeValidator<TValue, TPathKind>>): void;
|
|
1343
1429
|
/**
|
|
1344
1430
|
* Adds a value to an {@link AggregateMetadataKey} of a field.
|
|
1345
1431
|
*
|
|
@@ -1353,7 +1439,7 @@ declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root
|
|
|
1353
1439
|
* @category logic
|
|
1354
1440
|
* @experimental 21.0.0
|
|
1355
1441
|
*/
|
|
1356
|
-
declare function aggregateMetadata<TValue, TMetadataItem, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1442
|
+
declare function aggregateMetadata<TValue, TMetadataItem, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, key: AggregateMetadataKey<any, TMetadataItem>, logic: NoInfer<LogicFn<TValue, TMetadataItem, TPathKind>>): void;
|
|
1357
1443
|
/**
|
|
1358
1444
|
* Creates a new {@link MetadataKey} and defines the value of the new metadata key for the given field.
|
|
1359
1445
|
*
|
|
@@ -1365,7 +1451,7 @@ declare function aggregateMetadata<TValue, TMetadataItem, TPathKind extends Path
|
|
|
1365
1451
|
* @category logic
|
|
1366
1452
|
* @experimental 21.0.0
|
|
1367
1453
|
*/
|
|
1368
|
-
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1454
|
+
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
|
|
1369
1455
|
/**
|
|
1370
1456
|
* Defines the value of a {@link MetadataKey} for a given field.
|
|
1371
1457
|
*
|
|
@@ -1378,7 +1464,7 @@ declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.R
|
|
|
1378
1464
|
* @category logic
|
|
1379
1465
|
* @experimental 21.0.0
|
|
1380
1466
|
*/
|
|
1381
|
-
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path:
|
|
1467
|
+
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, key: MetadataKey<TData>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
|
|
1382
1468
|
|
|
1383
1469
|
/** Represents a result that should be ignored because its predicate indicates it is not active. */
|
|
1384
1470
|
declare const IGNORED: unique symbol;
|
|
@@ -1393,7 +1479,7 @@ interface Predicate {
|
|
|
1393
1479
|
* The path which this predicate was created for. This is used to determine the correct
|
|
1394
1480
|
* `FieldContext` to pass to the predicate function.
|
|
1395
1481
|
*/
|
|
1396
|
-
readonly path:
|
|
1482
|
+
readonly path: SchemaPath<any>;
|
|
1397
1483
|
}
|
|
1398
1484
|
/**
|
|
1399
1485
|
* Represents a predicate that is bound to a particular depth in the field tree. This is needed for
|
|
@@ -1492,11 +1578,11 @@ declare class LogicContainer {
|
|
|
1492
1578
|
/** Logic that determines if the field is read-only. */
|
|
1493
1579
|
readonly readonly: BooleanOrLogic;
|
|
1494
1580
|
/** Logic that produces synchronous validation errors for the field. */
|
|
1495
|
-
readonly syncErrors: ArrayMergeIgnoreLogic<
|
|
1581
|
+
readonly syncErrors: ArrayMergeIgnoreLogic<ValidationError.WithField, null>;
|
|
1496
1582
|
/** Logic that produces synchronous validation errors for the field's subtree. */
|
|
1497
|
-
readonly syncTreeErrors: ArrayMergeIgnoreLogic<
|
|
1583
|
+
readonly syncTreeErrors: ArrayMergeIgnoreLogic<ValidationError.WithField, null>;
|
|
1498
1584
|
/** Logic that produces asynchronous validation results (errors or 'pending'). */
|
|
1499
|
-
readonly asyncErrors: ArrayMergeIgnoreLogic<
|
|
1585
|
+
readonly asyncErrors: ArrayMergeIgnoreLogic<ValidationError.WithField | 'pending', null>;
|
|
1500
1586
|
/** A map of aggregate metadata keys to the `AbstractLogic` instances that compute their values. */
|
|
1501
1587
|
private readonly aggregateMetadataKeys;
|
|
1502
1588
|
/** A map of metadata keys to the factory functions that create their values. */
|
|
@@ -1524,7 +1610,7 @@ declare class LogicContainer {
|
|
|
1524
1610
|
* @param key The `AggregateMetadataKey` for which to get the logic.
|
|
1525
1611
|
* @returns The `AbstractLogic` associated with the key.
|
|
1526
1612
|
*/
|
|
1527
|
-
getAggregateMetadata<T>(key: AggregateMetadataKey<
|
|
1613
|
+
getAggregateMetadata<T>(key: AggregateMetadataKey<any, T>): AbstractLogic<T>;
|
|
1528
1614
|
/**
|
|
1529
1615
|
* Adds a factory function for a given metadata key.
|
|
1530
1616
|
* @param key The `MetadataKey` to associate the factory with.
|
|
@@ -1609,10 +1695,10 @@ declare class LogicNodeBuilder extends AbstractLogicNodeBuilder {
|
|
|
1609
1695
|
addHiddenRule(logic: LogicFn<any, boolean>): void;
|
|
1610
1696
|
addDisabledReasonRule(logic: LogicFn<any, DisabledReason | undefined>): void;
|
|
1611
1697
|
addReadonlyRule(logic: LogicFn<any, boolean>): void;
|
|
1612
|
-
addSyncErrorRule(logic: LogicFn<any, ValidationResult<
|
|
1613
|
-
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult<
|
|
1614
|
-
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult<
|
|
1615
|
-
addAggregateMetadataRule<T>(key: AggregateMetadataKey<
|
|
1698
|
+
addSyncErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithField>>): void;
|
|
1699
|
+
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithField>>): void;
|
|
1700
|
+
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult<ValidationError.WithField>>): void;
|
|
1701
|
+
addAggregateMetadataRule<T>(key: AggregateMetadataKey<any, T>, logic: LogicFn<any, T>): void;
|
|
1616
1702
|
addMetadataFactory<D>(key: MetadataKey<D>, factory: (ctx: FieldContext<any>) => D): void;
|
|
1617
1703
|
getChild(key: PropertyKey): LogicNodeBuilder;
|
|
1618
1704
|
hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
@@ -1705,7 +1791,7 @@ declare class FieldPathNode {
|
|
|
1705
1791
|
/**
|
|
1706
1792
|
* A proxy that wraps the path node, allowing navigation to its child paths via property access.
|
|
1707
1793
|
*/
|
|
1708
|
-
readonly fieldPathProxy:
|
|
1794
|
+
readonly fieldPathProxy: SchemaPath<any>;
|
|
1709
1795
|
/**
|
|
1710
1796
|
* For a root path node this will contain the root logic builder. For non-root nodes,
|
|
1711
1797
|
* they determine their logic builder from their parent so this is undefined.
|
|
@@ -1720,10 +1806,6 @@ declare class FieldPathNode {
|
|
|
1720
1806
|
keyInParent: PropertyKey | undefined);
|
|
1721
1807
|
/** The logic builder used to accumulate logic on this path node. */
|
|
1722
1808
|
get builder(): LogicNodeBuilder;
|
|
1723
|
-
/**
|
|
1724
|
-
* Gets the special path node containing the per-element logic that applies to *all* children paths.
|
|
1725
|
-
*/
|
|
1726
|
-
get element(): FieldPathNode;
|
|
1727
1809
|
/**
|
|
1728
1810
|
* Gets the path node for the given child property key.
|
|
1729
1811
|
* Child paths are created automatically on first access if they do not exist already.
|
|
@@ -1736,7 +1818,7 @@ declare class FieldPathNode {
|
|
|
1736
1818
|
*/
|
|
1737
1819
|
mergeIn(other: SchemaImpl, predicate?: Predicate): void;
|
|
1738
1820
|
/** Extracts the underlying path node from the given path proxy. */
|
|
1739
|
-
static unwrapFieldPath(formPath:
|
|
1821
|
+
static unwrapFieldPath(formPath: SchemaPath<unknown, SchemaPathRules>): FieldPathNode;
|
|
1740
1822
|
/** Creates a new root path node to be passed in to a schema function. */
|
|
1741
1823
|
static newRoot(): FieldPathNode;
|
|
1742
1824
|
}
|
|
@@ -1842,6 +1924,7 @@ declare class FieldNodeState {
|
|
|
1842
1924
|
*/
|
|
1843
1925
|
readonly hidden: Signal<boolean>;
|
|
1844
1926
|
readonly name: Signal<string>;
|
|
1927
|
+
debouncer(): Promise<void> | void;
|
|
1845
1928
|
/** Whether this field is considered non-interactive.
|
|
1846
1929
|
*
|
|
1847
1930
|
* A field is considered non-interactive if one of the following is true:
|
|
@@ -1863,7 +1946,7 @@ declare class FieldSubmitState {
|
|
|
1863
1946
|
*/
|
|
1864
1947
|
readonly selfSubmitting: WritableSignal<boolean>;
|
|
1865
1948
|
/** Server errors that are associated with this field. */
|
|
1866
|
-
readonly serverErrors: WritableSignal<readonly
|
|
1949
|
+
readonly serverErrors: WritableSignal<readonly ValidationError.WithField[]>;
|
|
1867
1950
|
constructor(node: FieldNode);
|
|
1868
1951
|
/**
|
|
1869
1952
|
* Whether this form is currently in the process of being submitted.
|
|
@@ -1877,14 +1960,14 @@ interface ValidationState {
|
|
|
1877
1960
|
* The full set of synchronous tree errors visible to this field. This includes ones that are
|
|
1878
1961
|
* targeted at a descendant field rather than at this field.
|
|
1879
1962
|
*/
|
|
1880
|
-
rawSyncTreeErrors: Signal<
|
|
1963
|
+
rawSyncTreeErrors: Signal<ValidationError.WithField[]>;
|
|
1881
1964
|
/**
|
|
1882
1965
|
* The full set of synchronous errors for this field, including synchronous tree errors and server
|
|
1883
1966
|
* errors. Server errors are considered "synchronous" because they are imperatively added. From
|
|
1884
1967
|
* the perspective of the field state they are either there or not, they are never in a pending
|
|
1885
1968
|
* state.
|
|
1886
1969
|
*/
|
|
1887
|
-
syncErrors: Signal<
|
|
1970
|
+
syncErrors: Signal<ValidationError.WithField[]>;
|
|
1888
1971
|
/**
|
|
1889
1972
|
* Whether the field is considered valid according solely to its synchronous validators.
|
|
1890
1973
|
* Errors resulting from a previous submit attempt are also considered for this state.
|
|
@@ -1895,21 +1978,21 @@ interface ValidationState {
|
|
|
1895
1978
|
* targeted at a descendant field rather than at this field, as well as sentinel 'pending' values
|
|
1896
1979
|
* indicating that the validator is still running and an error could still occur.
|
|
1897
1980
|
*/
|
|
1898
|
-
rawAsyncErrors: Signal<(
|
|
1981
|
+
rawAsyncErrors: Signal<(ValidationError.WithField | 'pending')[]>;
|
|
1899
1982
|
/**
|
|
1900
1983
|
* The asynchronous tree errors visible to this field that are specifically targeted at this field
|
|
1901
1984
|
* rather than a descendant. This also includes all 'pending' sentinel values, since those could
|
|
1902
1985
|
* theoretically result in errors for this field.
|
|
1903
1986
|
*/
|
|
1904
|
-
asyncErrors: Signal<(
|
|
1987
|
+
asyncErrors: Signal<(ValidationError.WithField | 'pending')[]>;
|
|
1905
1988
|
/**
|
|
1906
1989
|
* The combined set of all errors that currently apply to this field.
|
|
1907
1990
|
*/
|
|
1908
|
-
errors: Signal<
|
|
1991
|
+
errors: Signal<ValidationError.WithField[]>;
|
|
1909
1992
|
/**
|
|
1910
1993
|
* The combined set of all errors that currently apply to this field and its descendants.
|
|
1911
1994
|
*/
|
|
1912
|
-
errorSummary: Signal<
|
|
1995
|
+
errorSummary: Signal<ValidationError.WithField[]>;
|
|
1913
1996
|
/**
|
|
1914
1997
|
* Whether this field has any asynchronous validators still pending.
|
|
1915
1998
|
*/
|
|
@@ -1980,19 +2063,26 @@ declare class FieldNode implements FieldState<unknown> {
|
|
|
1980
2063
|
readonly metadataState: FieldMetadataState;
|
|
1981
2064
|
readonly nodeState: FieldNodeState;
|
|
1982
2065
|
readonly submitState: FieldSubmitState;
|
|
1983
|
-
private _context;
|
|
1984
2066
|
readonly fieldAdapter: FieldAdapter;
|
|
2067
|
+
private _context;
|
|
1985
2068
|
get context(): FieldContext<unknown>;
|
|
1986
2069
|
/**
|
|
1987
2070
|
* Proxy to this node which allows navigation of the form graph below it.
|
|
1988
2071
|
*/
|
|
1989
2072
|
readonly fieldProxy: FieldTree<any>;
|
|
1990
2073
|
constructor(options: FieldNodeOptions);
|
|
2074
|
+
/**
|
|
2075
|
+
* The most recent promise returned by the debouncer, or `undefined` if no debounce is active.
|
|
2076
|
+
* This is used to ensure that only the most recent debounce operation updates the field's value.
|
|
2077
|
+
*/
|
|
2078
|
+
private readonly pendingSync;
|
|
1991
2079
|
get logicNode(): LogicNode;
|
|
1992
2080
|
get value(): WritableSignal<unknown>;
|
|
2081
|
+
private _controlValue;
|
|
2082
|
+
get controlValue(): Signal<unknown>;
|
|
1993
2083
|
get keyInParent(): Signal<string | number>;
|
|
1994
|
-
get errors(): Signal<
|
|
1995
|
-
get errorSummary(): Signal<
|
|
2084
|
+
get errors(): Signal<ValidationError.WithField[]>;
|
|
2085
|
+
get errorSummary(): Signal<ValidationError.WithField[]>;
|
|
1996
2086
|
get pending(): Signal<boolean>;
|
|
1997
2087
|
get valid(): Signal<boolean>;
|
|
1998
2088
|
get invalid(): Signal<boolean>;
|
|
@@ -2029,6 +2119,26 @@ declare class FieldNode implements FieldState<unknown> {
|
|
|
2029
2119
|
* Note this does not change the data model, which can be reset directly if desired.
|
|
2030
2120
|
*/
|
|
2031
2121
|
reset(): void;
|
|
2122
|
+
/**
|
|
2123
|
+
* Sets the control value of the field. This value may be debounced before it is synchronized with
|
|
2124
|
+
* the field's {@link value} signal, depending on the debounce configuration.
|
|
2125
|
+
*/
|
|
2126
|
+
setControlValue(newValue: unknown): void;
|
|
2127
|
+
/**
|
|
2128
|
+
* Synchronizes the {@link controlValue} with the {@link value} signal immediately.
|
|
2129
|
+
*
|
|
2130
|
+
* This also clears any pending debounce operations.
|
|
2131
|
+
*/
|
|
2132
|
+
private sync;
|
|
2133
|
+
/**
|
|
2134
|
+
* Initiates a debounced {@link sync}.
|
|
2135
|
+
*
|
|
2136
|
+
* If a debouncer is configured, the synchronization will occur after the debouncer. If no
|
|
2137
|
+
* debouncer is configured, the synchronization happens immediately. If a new
|
|
2138
|
+
* {@link setControlValue} call occurs while a debounce is pending, the previous debounce
|
|
2139
|
+
* operation is ignored in favor of the new one.
|
|
2140
|
+
*/
|
|
2141
|
+
private debounceSync;
|
|
2032
2142
|
/**
|
|
2033
2143
|
* Creates a new root field node for a new form.
|
|
2034
2144
|
*/
|
|
@@ -2077,7 +2187,7 @@ declare abstract class FieldNodeStructure {
|
|
|
2077
2187
|
/** The root field that this field descends from. */
|
|
2078
2188
|
abstract readonly root: FieldNode;
|
|
2079
2189
|
/** The list of property keys to follow to get from the `root` to this field. */
|
|
2080
|
-
abstract readonly pathKeys: Signal<readonly
|
|
2190
|
+
abstract readonly pathKeys: Signal<readonly string[]>;
|
|
2081
2191
|
/** The parent field of this field. */
|
|
2082
2192
|
abstract readonly parent: FieldNode | undefined;
|
|
2083
2193
|
/** Added to array elements for tracking purposes. */
|
|
@@ -2104,7 +2214,7 @@ declare class RootFieldNodeStructure extends FieldNodeStructure {
|
|
|
2104
2214
|
readonly value: WritableSignal<unknown>;
|
|
2105
2215
|
get parent(): undefined;
|
|
2106
2216
|
get root(): FieldNode;
|
|
2107
|
-
get pathKeys(): Signal<readonly
|
|
2217
|
+
get pathKeys(): Signal<readonly string[]>;
|
|
2108
2218
|
get keyInParent(): Signal<string>;
|
|
2109
2219
|
readonly childrenMap: Signal<Map<TrackingKey, FieldNode> | undefined>;
|
|
2110
2220
|
/**
|
|
@@ -2126,7 +2236,7 @@ declare class RootFieldNodeStructure extends FieldNodeStructure {
|
|
|
2126
2236
|
declare class ChildFieldNodeStructure extends FieldNodeStructure {
|
|
2127
2237
|
readonly parent: ParentFieldNode;
|
|
2128
2238
|
readonly root: FieldNode;
|
|
2129
|
-
readonly pathKeys: Signal<readonly
|
|
2239
|
+
readonly pathKeys: Signal<readonly string[]>;
|
|
2130
2240
|
readonly keyInParent: Signal<string>;
|
|
2131
2241
|
readonly value: WritableSignal<unknown>;
|
|
2132
2242
|
readonly childrenMap: Signal<Map<TrackingKey, FieldNode> | undefined>;
|
|
@@ -2298,12 +2408,12 @@ interface FormOptions {
|
|
|
2298
2408
|
* structure will match the shape of the model and any changes to the form data will be written to
|
|
2299
2409
|
* the model.
|
|
2300
2410
|
* @return A `FieldTree` representing a form around the data model.
|
|
2301
|
-
* @template
|
|
2411
|
+
* @template TModel The type of the data model.
|
|
2302
2412
|
*
|
|
2303
2413
|
* @category structure
|
|
2304
2414
|
* @experimental 21.0.0
|
|
2305
2415
|
*/
|
|
2306
|
-
declare function form<
|
|
2416
|
+
declare function form<TModel>(model: WritableSignal<TModel>): FieldTree<TModel>;
|
|
2307
2417
|
/**
|
|
2308
2418
|
* Creates a form wrapped around the given model data. A form is represented as simply a `FieldTree`
|
|
2309
2419
|
* of the model data.
|
|
@@ -2349,7 +2459,7 @@ declare function form<TValue>(model: WritableSignal<TValue>): FieldTree<TValue>;
|
|
|
2349
2459
|
* @category structure
|
|
2350
2460
|
* @experimental 21.0.0
|
|
2351
2461
|
*/
|
|
2352
|
-
declare function form<
|
|
2462
|
+
declare function form<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | FormOptions): FieldTree<TModel>;
|
|
2353
2463
|
/**
|
|
2354
2464
|
* Creates a form wrapped around the given model data. A form is represented as simply a `FieldTree`
|
|
2355
2465
|
* of the model data.
|
|
@@ -2375,7 +2485,7 @@ declare function form<TValue>(model: WritableSignal<TValue>, schemaOrOptions: Sc
|
|
|
2375
2485
|
* ```
|
|
2376
2486
|
* const nameForm = form(signal({first: '', last: ''}), (name) => {
|
|
2377
2487
|
* required(name.first);
|
|
2378
|
-
*
|
|
2488
|
+
* validate(name.last, ({value}) => !/^[a-z]+$/i.test(value()) ? customError({kind: 'alphabet-only'}) : undefined);
|
|
2379
2489
|
* });
|
|
2380
2490
|
* nameForm().valid(); // false
|
|
2381
2491
|
* nameForm().value.set({first: 'John', last: 'Doe'});
|
|
@@ -2388,12 +2498,12 @@ declare function form<TValue>(model: WritableSignal<TValue>, schemaOrOptions: Sc
|
|
|
2388
2498
|
* @param schema A schema or a function used to specify logic for the form (e.g. validation, disabled fields, etc.)
|
|
2389
2499
|
* @param options The form options
|
|
2390
2500
|
* @return A `FieldTree` representing a form around the data model.
|
|
2391
|
-
* @template
|
|
2501
|
+
* @template TModel The type of the data model.
|
|
2392
2502
|
*
|
|
2393
2503
|
* @category structure
|
|
2394
2504
|
* @experimental 21.0.0
|
|
2395
2505
|
*/
|
|
2396
|
-
declare function form<
|
|
2506
|
+
declare function form<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: FormOptions): FieldTree<TModel>;
|
|
2397
2507
|
/**
|
|
2398
2508
|
* Applies a schema to each item of an array.
|
|
2399
2509
|
*
|
|
@@ -2408,22 +2518,6 @@ declare function form<TValue>(model: WritableSignal<TValue>, schema: SchemaOrSch
|
|
|
2408
2518
|
* });
|
|
2409
2519
|
* ```
|
|
2410
2520
|
*
|
|
2411
|
-
* When binding logic to the array items, the `FieldTree` for the array item is passed as an
|
|
2412
|
-
* additional argument. This can be used to reference other properties on the item.
|
|
2413
|
-
*
|
|
2414
|
-
* @example
|
|
2415
|
-
* ```
|
|
2416
|
-
* const namesForm = form(signal([{first: '', last: ''}]), (names) => {
|
|
2417
|
-
* applyEach(names, (name) => {
|
|
2418
|
-
* error(
|
|
2419
|
-
* name.last,
|
|
2420
|
-
* (value, nameField) => value === nameField.first().value(),
|
|
2421
|
-
* 'Last name must be different than first name',
|
|
2422
|
-
* );
|
|
2423
|
-
* });
|
|
2424
|
-
* });
|
|
2425
|
-
* ```
|
|
2426
|
-
*
|
|
2427
2521
|
* @param path The target path for an array field whose items the schema will be applied to.
|
|
2428
2522
|
* @param schema A schema for an element of the array, or function that binds logic to an
|
|
2429
2523
|
* element of the array.
|
|
@@ -2432,7 +2526,8 @@ declare function form<TValue>(model: WritableSignal<TValue>, schema: SchemaOrSch
|
|
|
2432
2526
|
* @category structure
|
|
2433
2527
|
* @experimental 21.0.0
|
|
2434
2528
|
*/
|
|
2435
|
-
declare function applyEach<TValue
|
|
2529
|
+
declare function applyEach<TValue extends ReadonlyArray<any>>(path: SchemaPath<TValue>, schema: NoInfer<SchemaOrSchemaFn<TValue[number], PathKind.Item>>): void;
|
|
2530
|
+
declare function applyEach<TValue extends Object>(path: SchemaPath<TValue>, schema: NoInfer<SchemaOrSchemaFn<ItemType<TValue>, PathKind.Child>>): void;
|
|
2436
2531
|
/**
|
|
2437
2532
|
* Applies a predefined schema to a given `FieldPath`.
|
|
2438
2533
|
*
|
|
@@ -2454,7 +2549,7 @@ declare function applyEach<TValue>(path: FieldPath<TValue[]>, schema: NoInfer<Sc
|
|
|
2454
2549
|
* @category structure
|
|
2455
2550
|
* @experimental 21.0.0
|
|
2456
2551
|
*/
|
|
2457
|
-
declare function apply<TValue>(path:
|
|
2552
|
+
declare function apply<TValue>(path: SchemaPath<TValue>, schema: NoInfer<SchemaOrSchemaFn<TValue>>): void;
|
|
2458
2553
|
/**
|
|
2459
2554
|
* Conditionally applies a predefined schema to a given `FieldPath`.
|
|
2460
2555
|
*
|
|
@@ -2466,7 +2561,7 @@ declare function apply<TValue>(path: FieldPath<TValue>, schema: NoInfer<SchemaOr
|
|
|
2466
2561
|
* @category structure
|
|
2467
2562
|
* @experimental 21.0.0
|
|
2468
2563
|
*/
|
|
2469
|
-
declare function applyWhen<TValue>(path:
|
|
2564
|
+
declare function applyWhen<TValue>(path: SchemaPath<TValue>, logic: LogicFn<TValue, boolean>, schema: NoInfer<SchemaOrSchemaFn<TValue>>): void;
|
|
2470
2565
|
/**
|
|
2471
2566
|
* Conditionally applies a predefined schema to a given `FieldPath`.
|
|
2472
2567
|
*
|
|
@@ -2480,7 +2575,7 @@ declare function applyWhen<TValue>(path: FieldPath<TValue>, logic: LogicFn<TValu
|
|
|
2480
2575
|
* @category structure
|
|
2481
2576
|
* @experimental 21.0.0
|
|
2482
2577
|
*/
|
|
2483
|
-
declare function applyWhenValue<TValue, TNarrowed extends TValue>(path:
|
|
2578
|
+
declare function applyWhenValue<TValue, TNarrowed extends TValue>(path: SchemaPath<TValue>, predicate: (value: TValue) => value is TNarrowed, schema: SchemaOrSchemaFn<TNarrowed>): void;
|
|
2484
2579
|
/**
|
|
2485
2580
|
* Conditionally applies a predefined schema to a given `FieldPath`.
|
|
2486
2581
|
*
|
|
@@ -2493,7 +2588,7 @@ declare function applyWhenValue<TValue, TNarrowed extends TValue>(path: FieldPat
|
|
|
2493
2588
|
* @category structure
|
|
2494
2589
|
* @experimental 21.0.0
|
|
2495
2590
|
*/
|
|
2496
|
-
declare function applyWhenValue<TValue>(path:
|
|
2591
|
+
declare function applyWhenValue<TValue>(path: SchemaPath<TValue>, predicate: (value: TValue) => boolean, schema: NoInfer<SchemaOrSchemaFn<TValue>>): void;
|
|
2497
2592
|
/**
|
|
2498
2593
|
* Submits a given `FieldTree` using the given action function and applies any server errors
|
|
2499
2594
|
* resulting from the action to the field. Server errors returned by the `action` will be integrated
|
|
@@ -2523,12 +2618,12 @@ declare function applyWhenValue<TValue>(path: FieldPath<TValue>, predicate: (val
|
|
|
2523
2618
|
* @param form The field to submit.
|
|
2524
2619
|
* @param action An asynchronous action used to submit the field. The action may return server
|
|
2525
2620
|
* errors.
|
|
2526
|
-
* @template
|
|
2621
|
+
* @template TModel The data type of the field being submitted.
|
|
2527
2622
|
*
|
|
2528
2623
|
* @category submission
|
|
2529
2624
|
* @experimental 21.0.0
|
|
2530
2625
|
*/
|
|
2531
|
-
declare function submit<
|
|
2626
|
+
declare function submit<TModel>(form: FieldTree<TModel>, action: (form: FieldTree<TModel>) => Promise<TreeValidationResult>): Promise<void>;
|
|
2532
2627
|
/**
|
|
2533
2628
|
* Creates a `Schema` that adds logic rules to a form.
|
|
2534
2629
|
* @param fn A **non-reactive** function that sets up reactive logic rules for the form.
|
|
@@ -2573,7 +2668,7 @@ type BaseValidatorConfig<TValue, TPathKind extends PathKind = PathKind.Root> = {
|
|
|
2573
2668
|
* @category validation
|
|
2574
2669
|
* @experimental 21.0.0
|
|
2575
2670
|
*/
|
|
2576
|
-
declare function email<TPathKind extends PathKind = PathKind.Root>(path:
|
|
2671
|
+
declare function email<TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<string, SchemaPathRules.Supported, TPathKind>, config?: BaseValidatorConfig<string, TPathKind>): void;
|
|
2577
2672
|
|
|
2578
2673
|
/**
|
|
2579
2674
|
* Binds a validator to the given path that requires the value to be less than or equal to the
|
|
@@ -2591,7 +2686,7 @@ declare function email<TPathKind extends PathKind = PathKind.Root>(path: FieldPa
|
|
|
2591
2686
|
* @category validation
|
|
2592
2687
|
* @experimental 21.0.0
|
|
2593
2688
|
*/
|
|
2594
|
-
declare function max<TPathKind extends PathKind = PathKind.Root>(path:
|
|
2689
|
+
declare function max<TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<number, SchemaPathRules.Supported, TPathKind>, maxValue: number | LogicFn<number, number | undefined, TPathKind>, config?: BaseValidatorConfig<number, TPathKind>): void;
|
|
2595
2690
|
|
|
2596
2691
|
/**
|
|
2597
2692
|
* Binds a validator to the given path that requires the length of the value to be less than or
|
|
@@ -2610,7 +2705,7 @@ declare function max<TPathKind extends PathKind = PathKind.Root>(path: FieldPath
|
|
|
2610
2705
|
* @category validation
|
|
2611
2706
|
* @experimental 21.0.0
|
|
2612
2707
|
*/
|
|
2613
|
-
declare function maxLength<TValue extends ValueWithLengthOrSize, TPathKind extends PathKind = PathKind.Root>(path:
|
|
2708
|
+
declare function maxLength<TValue extends ValueWithLengthOrSize, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, maxLength: number | LogicFn<TValue, number | undefined, TPathKind>, config?: BaseValidatorConfig<TValue, TPathKind>): void;
|
|
2614
2709
|
|
|
2615
2710
|
/**
|
|
2616
2711
|
* Binds a validator to the given path that requires the value to be greater than or equal to
|
|
@@ -2628,7 +2723,7 @@ declare function maxLength<TValue extends ValueWithLengthOrSize, TPathKind exten
|
|
|
2628
2723
|
* @category validation
|
|
2629
2724
|
* @experimental 21.0.0
|
|
2630
2725
|
*/
|
|
2631
|
-
declare function min<TPathKind extends PathKind = PathKind.Root>(path:
|
|
2726
|
+
declare function min<TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<number, SchemaPathRules.Supported, TPathKind>, minValue: number | LogicFn<number, number | undefined, TPathKind>, config?: BaseValidatorConfig<number, TPathKind>): void;
|
|
2632
2727
|
|
|
2633
2728
|
/**
|
|
2634
2729
|
* Binds a validator to the given path that requires the length of the value to be greater than or
|
|
@@ -2647,7 +2742,7 @@ declare function min<TPathKind extends PathKind = PathKind.Root>(path: FieldPath
|
|
|
2647
2742
|
* @category validation
|
|
2648
2743
|
* @experimental 21.0.0
|
|
2649
2744
|
*/
|
|
2650
|
-
declare function minLength<TValue extends ValueWithLengthOrSize, TPathKind extends PathKind = PathKind.Root>(path:
|
|
2745
|
+
declare function minLength<TValue extends ValueWithLengthOrSize, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, minLength: number | LogicFn<TValue, number | undefined, TPathKind>, config?: BaseValidatorConfig<TValue, TPathKind>): void;
|
|
2651
2746
|
|
|
2652
2747
|
/**
|
|
2653
2748
|
* Binds a validator to the given path that requires the value to match a specific regex pattern.
|
|
@@ -2664,7 +2759,7 @@ declare function minLength<TValue extends ValueWithLengthOrSize, TPathKind exten
|
|
|
2664
2759
|
* @category validation
|
|
2665
2760
|
* @experimental 21.0.0
|
|
2666
2761
|
*/
|
|
2667
|
-
declare function pattern<TPathKind extends PathKind = PathKind.Root>(path:
|
|
2762
|
+
declare function pattern<TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<string, SchemaPathRules.Supported, TPathKind>, pattern: RegExp | LogicFn<string | undefined, RegExp | undefined, TPathKind>, config?: BaseValidatorConfig<string, TPathKind>): void;
|
|
2668
2763
|
|
|
2669
2764
|
/**
|
|
2670
2765
|
* Binds a validator to the given path that requires the value to be non-empty.
|
|
@@ -2683,7 +2778,7 @@ declare function pattern<TPathKind extends PathKind = PathKind.Root>(path: Field
|
|
|
2683
2778
|
* @category validation
|
|
2684
2779
|
* @experimental 21.0.0
|
|
2685
2780
|
*/
|
|
2686
|
-
declare function required<TValue, TPathKind extends PathKind = PathKind.Root>(path:
|
|
2781
|
+
declare function required<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, config?: BaseValidatorConfig<TValue, TPathKind> & {
|
|
2687
2782
|
when?: NoInfer<LogicFn<TValue, boolean, TPathKind>>;
|
|
2688
2783
|
}): void;
|
|
2689
2784
|
|
|
@@ -2719,7 +2814,7 @@ type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
|
|
|
2719
2814
|
* @category validation
|
|
2720
2815
|
* @experimental 21.0.0
|
|
2721
2816
|
*/
|
|
2722
|
-
declare function validateStandardSchema<TSchema,
|
|
2817
|
+
declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema>): void;
|
|
2723
2818
|
|
|
2724
|
-
export { AggregateMetadataKey, CustomValidationError, EmailValidationError, FIELD, Field, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, StandardSchemaValidationError, aggregateMetadata, andMetadataKey, apply, applyEach, applyWhen, applyWhenValue, createMetadataKey, customError, disabled, email, emailError, form, hidden, listMetadataKey, max, maxError, maxLength, maxLengthError, maxMetadataKey, metadata, min, minError, minLength, minLengthError, minMetadataKey, orMetadataKey, pattern, patternError, readonly, reducedMetadataKey, required, requiredError, schema, standardSchemaError, submit, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
|
|
2725
|
-
export type { AsyncValidationResult, AsyncValidatorOptions, ChildFieldContext, DisabledReason, FieldContext,
|
|
2819
|
+
export { AggregateMetadataKey, CustomValidationError, EmailValidationError, FIELD, Field, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, SchemaPathRules, StandardSchemaValidationError, ValidationError, aggregateMetadata, andMetadataKey, apply, applyEach, applyWhen, applyWhenValue, createMetadataKey, customError, debounce, disabled, email, emailError, form, hidden, listMetadataKey, max, maxError, maxLength, maxLengthError, maxMetadataKey, metadata, min, minError, minLength, minLengthError, minMetadataKey, orMetadataKey, pattern, patternError, readonly, reducedMetadataKey, required, requiredError, schema, standardSchemaError, submit, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
|
|
2820
|
+
export type { AsyncValidationResult, AsyncValidatorOptions, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, FieldContext, FieldState, FieldTree, FieldValidator, FormCheckboxControl, FormOptions, FormUiControl, FormValueControl, HttpValidatorOptions, IgnoreUnknownProperties, ItemFieldContext, ItemType, LogicFn, MapToErrorsFn, MaybeFieldTree, MaybeSchemaPathTree, OneOrMany, ReadonlyArrayLike, RemoveStringIndexUnknownKey, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPath, SchemaPathTree, Subfields, SubmittedStatus, TreeValidationResult, TreeValidator, ValidationResult, ValidationSuccess, Validator, WithField, WithOptionalField, WithoutField };
|