@angular/forms 21.2.0-next.1 → 21.2.0-next.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/fesm2022/_structure-chunk.mjs +116 -26
- package/fesm2022/_structure-chunk.mjs.map +1 -1
- package/fesm2022/forms.mjs +128 -128
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +386 -47
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +402 -68
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/resources/code-examples.db +0 -0
- package/types/_structure-chunk.d.ts +253 -1039
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +131 -8
- package/types/signals.d.ts +6 -41
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.2.0-next.
|
|
2
|
+
* @license Angular v21.2.0-next.2
|
|
3
3
|
* (c) 2010-2026 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as i0 from '@angular/core';
|
|
8
|
-
import { Signal,
|
|
8
|
+
import { Signal, WritableSignal, InjectionToken, Injector, Provider } from '@angular/core';
|
|
9
9
|
import * as _angular_forms from '@angular/forms';
|
|
10
|
-
import { AbstractControl,
|
|
10
|
+
import { AbstractControl, ValidationErrors, FormControlStatus, ControlValueAccessor, ValidatorFn } from '@angular/forms';
|
|
11
11
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -176,6 +176,70 @@ declare const MAX_LENGTH: MetadataKey<Signal<number | undefined>, number | undef
|
|
|
176
176
|
*/
|
|
177
177
|
declare const PATTERN: MetadataKey<Signal<RegExp[]>, RegExp | undefined, RegExp[]>;
|
|
178
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Utility type that removes a string index key when its value is `unknown`,
|
|
181
|
+
* i.e. `{[key: string]: unknown}`. It allows specific string keys to pass through, even if their
|
|
182
|
+
* value is `unknown`, e.g. `{key: unknown}`.
|
|
183
|
+
*
|
|
184
|
+
* @experimental 21.0.0
|
|
185
|
+
*/
|
|
186
|
+
type RemoveStringIndexUnknownKey<K, V> = string extends K ? unknown extends V ? never : K : K;
|
|
187
|
+
/**
|
|
188
|
+
* Utility type that recursively ignores unknown string index properties on the given object.
|
|
189
|
+
* We use this on the `TSchema` type in `validateStandardSchema` in order to accommodate Zod's
|
|
190
|
+
* `looseObject` which includes `{[key: string]: unknown}` as part of the type.
|
|
191
|
+
*
|
|
192
|
+
* @experimental 21.0.0
|
|
193
|
+
*/
|
|
194
|
+
type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
|
|
195
|
+
[K in keyof T as RemoveStringIndexUnknownKey<K, T[K]>]: IgnoreUnknownProperties<T[K]>;
|
|
196
|
+
} : T;
|
|
197
|
+
/**
|
|
198
|
+
* Validates a field using a `StandardSchemaV1` compatible validator (e.g. a Zod validator).
|
|
199
|
+
*
|
|
200
|
+
* See https://github.com/standard-schema/standard-schema for more about standard schema.
|
|
201
|
+
*
|
|
202
|
+
* @param path The `FieldPath` to the field to validate.
|
|
203
|
+
* @param schema The standard schema compatible validator to use for validation.
|
|
204
|
+
* @template TSchema The type validated by the schema. This may be either the full `TValue` type,
|
|
205
|
+
* or a partial of it.
|
|
206
|
+
* @template TValue The type of value stored in the field being validated.
|
|
207
|
+
*
|
|
208
|
+
* @see [Signal Form Schema Validation](guide/forms/signals/validation#integration-with-schema-validation-libraries)
|
|
209
|
+
* @category validation
|
|
210
|
+
* @experimental 21.0.0
|
|
211
|
+
*/
|
|
212
|
+
declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema>): void;
|
|
213
|
+
/**
|
|
214
|
+
* Create a standard schema issue error associated with the target field
|
|
215
|
+
* @param issue The standard schema issue
|
|
216
|
+
* @param options The validation error options
|
|
217
|
+
*
|
|
218
|
+
* @category validation
|
|
219
|
+
* @experimental 21.0.0
|
|
220
|
+
*/
|
|
221
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: WithFieldTree<ValidationErrorOptions>): StandardSchemaValidationError;
|
|
222
|
+
/**
|
|
223
|
+
* Create a standard schema issue error
|
|
224
|
+
* @param issue The standard schema issue
|
|
225
|
+
* @param options The optional validation error options
|
|
226
|
+
*
|
|
227
|
+
* @category validation
|
|
228
|
+
* @experimental 21.0.0
|
|
229
|
+
*/
|
|
230
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions): WithoutFieldTree<StandardSchemaValidationError>;
|
|
231
|
+
/**
|
|
232
|
+
* An error used to indicate an issue validating against a standard schema.
|
|
233
|
+
*
|
|
234
|
+
* @category validation
|
|
235
|
+
* @experimental 21.0.0
|
|
236
|
+
*/
|
|
237
|
+
declare class StandardSchemaValidationError extends BaseNgValidationError {
|
|
238
|
+
readonly issue: StandardSchemaV1.Issue;
|
|
239
|
+
readonly kind = "standardSchema";
|
|
240
|
+
constructor(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions);
|
|
241
|
+
}
|
|
242
|
+
|
|
179
243
|
/**
|
|
180
244
|
* Symbol used to retain generic type information when it would otherwise be lost.
|
|
181
245
|
*/
|
|
@@ -333,7 +397,64 @@ type MaybeFieldTree<TModel, TKey extends string | number = string | number> = (T
|
|
|
333
397
|
* @category structure
|
|
334
398
|
* @experimental 21.0.0
|
|
335
399
|
*/
|
|
336
|
-
interface FieldState<TValue, TKey extends string | number = string | number>
|
|
400
|
+
interface FieldState<TValue, TKey extends string | number = string | number> {
|
|
401
|
+
/**
|
|
402
|
+
* A writable signal containing the value for this field.
|
|
403
|
+
*
|
|
404
|
+
* Updating this signal will update the data model that the field is bound to.
|
|
405
|
+
*
|
|
406
|
+
* While updates from the UI control are eventually reflected here, they may be delayed if
|
|
407
|
+
* debounced.
|
|
408
|
+
*/
|
|
409
|
+
readonly value: WritableSignal<TValue>;
|
|
410
|
+
/**
|
|
411
|
+
* A signal indicating whether the field is currently disabled.
|
|
412
|
+
*/
|
|
413
|
+
readonly disabled: Signal<boolean>;
|
|
414
|
+
/**
|
|
415
|
+
* A signal indicating the field's maximum value, if applicable.
|
|
416
|
+
*
|
|
417
|
+
* Applies to `<input>` with a numeric or date `type` attribute and custom controls.
|
|
418
|
+
*/
|
|
419
|
+
readonly max?: Signal<number | undefined>;
|
|
420
|
+
/**
|
|
421
|
+
* A signal indicating the field's maximum string length, if applicable.
|
|
422
|
+
*
|
|
423
|
+
* Applies to `<input>`, `<textarea>`, and custom controls.
|
|
424
|
+
*/
|
|
425
|
+
readonly maxLength?: Signal<number | undefined>;
|
|
426
|
+
/**
|
|
427
|
+
* A signal indicating the field's minimum value, if applicable.
|
|
428
|
+
*
|
|
429
|
+
* Applies to `<input>` with a numeric or date `type` attribute and custom controls.
|
|
430
|
+
*/
|
|
431
|
+
readonly min?: Signal<number | undefined>;
|
|
432
|
+
/**
|
|
433
|
+
* A signal indicating the field's minimum string length, if applicable.
|
|
434
|
+
*
|
|
435
|
+
* Applies to `<input>`, `<textarea>`, and custom controls.
|
|
436
|
+
*/
|
|
437
|
+
readonly minLength?: Signal<number | undefined>;
|
|
438
|
+
/**
|
|
439
|
+
* A signal of a unique name for the field, by default based on the name of its parent field.
|
|
440
|
+
*/
|
|
441
|
+
readonly name: Signal<string>;
|
|
442
|
+
/**
|
|
443
|
+
* A signal indicating the patterns the field must match.
|
|
444
|
+
*/
|
|
445
|
+
readonly pattern: Signal<readonly RegExp[]>;
|
|
446
|
+
/**
|
|
447
|
+
* A signal indicating whether the field is currently readonly.
|
|
448
|
+
*/
|
|
449
|
+
readonly readonly: Signal<boolean>;
|
|
450
|
+
/**
|
|
451
|
+
* A signal indicating whether the field is required.
|
|
452
|
+
*/
|
|
453
|
+
readonly required: Signal<boolean>;
|
|
454
|
+
/**
|
|
455
|
+
* A signal indicating whether the field has been touched by the user.
|
|
456
|
+
*/
|
|
457
|
+
readonly touched: Signal<boolean>;
|
|
337
458
|
/**
|
|
338
459
|
* A signal indicating whether field value has been changed by user.
|
|
339
460
|
*/
|
|
@@ -398,6 +519,22 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
398
519
|
* The {@link FormField} directives that bind this field to a UI control.
|
|
399
520
|
*/
|
|
400
521
|
readonly formFieldBindings: Signal<readonly FormField<unknown>[]>;
|
|
522
|
+
/**
|
|
523
|
+
* A signal containing the value of the control to which this field is bound.
|
|
524
|
+
*
|
|
525
|
+
* This differs from {@link value} in that it's not subject to debouncing, and thus is used to
|
|
526
|
+
* buffer debounced updates from the control to the field. This will also not take into account
|
|
527
|
+
* the {@link controlValue} of children.
|
|
528
|
+
*/
|
|
529
|
+
readonly controlValue: WritableSignal<TValue>;
|
|
530
|
+
/**
|
|
531
|
+
* Sets the dirty status of the field to `true`.
|
|
532
|
+
*/
|
|
533
|
+
markAsDirty(): void;
|
|
534
|
+
/**
|
|
535
|
+
* Sets the touched status of the field to `true`.
|
|
536
|
+
*/
|
|
537
|
+
markAsTouched(): void;
|
|
401
538
|
/**
|
|
402
539
|
* Reads a metadata value from the field.
|
|
403
540
|
* @param key The metadata key to read.
|
|
@@ -687,9 +824,29 @@ type ItemType<T extends Object> = T extends ReadonlyArray<any> ? T[number] : T[k
|
|
|
687
824
|
type Debouncer<TValue, TPathKind extends PathKind = PathKind.Root> = (context: FieldContext<TValue, TPathKind>, abortSignal: AbortSignal) => Promise<void> | void;
|
|
688
825
|
|
|
689
826
|
/**
|
|
690
|
-
*
|
|
691
|
-
|
|
692
|
-
|
|
827
|
+
* Represents a combination of `NgControl` and `AbstractControl`.
|
|
828
|
+
*
|
|
829
|
+
* Note: We have this separate interface, rather than implementing the relevant parts of the two
|
|
830
|
+
* controls with something like `InteropNgControl implements Pick<NgControl, ...>, Pick<AbstractControl, ...>`
|
|
831
|
+
* because it confuses the internal JS minifier which can cause collisions in field names.
|
|
832
|
+
*/
|
|
833
|
+
interface CombinedControl {
|
|
834
|
+
value: any;
|
|
835
|
+
valid: boolean;
|
|
836
|
+
invalid: boolean;
|
|
837
|
+
touched: boolean;
|
|
838
|
+
untouched: boolean;
|
|
839
|
+
disabled: boolean;
|
|
840
|
+
enabled: boolean;
|
|
841
|
+
errors: ValidationErrors | null;
|
|
842
|
+
pristine: boolean;
|
|
843
|
+
dirty: boolean;
|
|
844
|
+
status: FormControlStatus;
|
|
845
|
+
control: AbstractControl<any, any>;
|
|
846
|
+
valueAccessor: ControlValueAccessor | null;
|
|
847
|
+
hasValidator(validator: ValidatorFn): boolean;
|
|
848
|
+
updateValueAndValidity(): void;
|
|
849
|
+
}
|
|
693
850
|
/**
|
|
694
851
|
* A fake version of `NgControl` provided by the `Field` directive. This allows interoperability
|
|
695
852
|
* with a wider range of components designed to work with reactive forms, in particular ones that
|
|
@@ -697,7 +854,7 @@ type InteropSharedKeys = 'value' | 'valid' | 'invalid' | 'touched' | 'untouched'
|
|
|
697
854
|
* the real `NgControl`, but does implement some of the most commonly used ones that have a clear
|
|
698
855
|
* equivalent in signal forms.
|
|
699
856
|
*/
|
|
700
|
-
declare class InteropNgControl implements
|
|
857
|
+
declare class InteropNgControl implements CombinedControl {
|
|
701
858
|
protected field: () => FieldState<unknown>;
|
|
702
859
|
constructor(field: () => FieldState<unknown>);
|
|
703
860
|
readonly control: AbstractControl<any, any>;
|
|
@@ -718,14 +875,18 @@ declare class InteropNgControl implements Pick<NgControl, InteropSharedKeys | 'c
|
|
|
718
875
|
updateValueAndValidity(): void;
|
|
719
876
|
}
|
|
720
877
|
|
|
721
|
-
|
|
878
|
+
declare const ɵNgFieldDirective: unique symbol;
|
|
879
|
+
interface FormFieldBindingOptions {
|
|
722
880
|
/**
|
|
723
881
|
* Focuses the binding.
|
|
724
882
|
*
|
|
725
883
|
* If not specified, Signal Forms will attempt to focus the host element of the `FormField` when
|
|
726
884
|
* asked to focus this binding.
|
|
727
885
|
*/
|
|
728
|
-
focus
|
|
886
|
+
readonly focus?: (focusOptions?: FocusOptions) => void;
|
|
887
|
+
/**
|
|
888
|
+
* Source of parse errors for this binding.
|
|
889
|
+
*/
|
|
729
890
|
readonly parseErrors?: Signal<ValidationError.WithoutFieldTree[]>;
|
|
730
891
|
}
|
|
731
892
|
/**
|
|
@@ -755,33 +916,64 @@ declare const FORM_FIELD: InjectionToken<FormField<unknown>>;
|
|
|
755
916
|
* @experimental 21.0.0
|
|
756
917
|
*/
|
|
757
918
|
declare class FormField<T> {
|
|
758
|
-
readonly element: HTMLElement;
|
|
759
|
-
readonly injector: Injector;
|
|
760
919
|
readonly fieldTree: i0.InputSignal<FieldTree<T>>;
|
|
920
|
+
/**
|
|
921
|
+
* `FieldState` for the currently bound field.
|
|
922
|
+
*/
|
|
761
923
|
readonly state: Signal<[T] extends [_angular_forms.AbstractControl<any, any, any>] ? CompatFieldState<T, string | number> : FieldState<T, string | number>>;
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
readonly
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
924
|
+
/**
|
|
925
|
+
* The node injector for the element this field binding.
|
|
926
|
+
*/
|
|
927
|
+
readonly injector: Injector;
|
|
928
|
+
/**
|
|
929
|
+
* The DOM element hosting this field binding.
|
|
930
|
+
*/
|
|
931
|
+
readonly element: HTMLElement;
|
|
932
|
+
private readonly elementIsNativeFormElement;
|
|
933
|
+
private readonly elementAcceptsNumericValues;
|
|
934
|
+
private readonly elementAcceptsTextualValues;
|
|
935
|
+
/**
|
|
936
|
+
* Current focus implementation, set by `registerAsBinding`.
|
|
937
|
+
*/
|
|
938
|
+
private focuser;
|
|
770
939
|
/** Any `ControlValueAccessor` instances provided on the host element. */
|
|
771
940
|
private readonly controlValueAccessors;
|
|
941
|
+
private readonly config;
|
|
942
|
+
private readonly parseErrorsSource;
|
|
772
943
|
/** A lazily instantiated fake `NgControl`. */
|
|
773
|
-
private
|
|
944
|
+
private _interopNgControl;
|
|
774
945
|
/** Lazily instantiates a fake `NgControl` for this form field. */
|
|
775
|
-
protected
|
|
946
|
+
protected get interopNgControl(): InteropNgControl;
|
|
947
|
+
/** Errors associated with this form field. */
|
|
948
|
+
readonly errors: Signal<ValidationError.WithFieldTree[]>;
|
|
949
|
+
/** Whether this `FormField` has been registered as a binding on its associated `FieldState`. */
|
|
950
|
+
private isFieldBinding;
|
|
951
|
+
/**
|
|
952
|
+
* Creates an `afterRenderEffect` that applies the configured class bindings to the host element
|
|
953
|
+
* if needed.
|
|
954
|
+
*/
|
|
955
|
+
private installClassBindingEffect;
|
|
956
|
+
/**
|
|
957
|
+
* Focuses this field binding.
|
|
958
|
+
*
|
|
959
|
+
* By default, this will focus the host DOM element. However, custom `FormUiControl`s can
|
|
960
|
+
* implement custom focusing behavior.
|
|
961
|
+
*/
|
|
962
|
+
focus(options?: FocusOptions): void;
|
|
776
963
|
/**
|
|
777
964
|
* Registers this `FormField` as a binding on its associated `FieldState`.
|
|
778
965
|
*
|
|
779
966
|
* This method should be called at most once for a given `FormField`. A `FormField` placed on a
|
|
780
967
|
* custom control (`FormUiControl`) automatically registers that custom control as a binding.
|
|
781
968
|
*/
|
|
782
|
-
registerAsBinding(bindingOptions?: FormFieldBindingOptions
|
|
783
|
-
/**
|
|
784
|
-
|
|
969
|
+
registerAsBinding(bindingOptions?: FormFieldBindingOptions): void;
|
|
970
|
+
/**
|
|
971
|
+
* The presence of this symbol tells the template type-checker that this directive is a control
|
|
972
|
+
* directive and should be type-checked as such. We don't use the `ɵngControlCreate` method below
|
|
973
|
+
* as it's marked internal and removed from the public API. A symbol is used instead to avoid
|
|
974
|
+
* polluting the public API with the marker.
|
|
975
|
+
*/
|
|
976
|
+
readonly [ɵNgFieldDirective]: true;
|
|
785
977
|
static ɵfac: i0.ɵɵFactoryDeclaration<FormField<any>, never>;
|
|
786
978
|
static ɵdir: i0.ɵɵDirectiveDeclaration<FormField<any>, "[formField]", ["formField"], { "fieldTree": { "alias": "formField"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
787
979
|
}
|
|
@@ -947,24 +1139,6 @@ declare function emailError(options: WithFieldTree<ValidationErrorOptions>): Ema
|
|
|
947
1139
|
* @experimental 21.0.0
|
|
948
1140
|
*/
|
|
949
1141
|
declare function emailError(options?: ValidationErrorOptions): WithoutFieldTree<EmailValidationError>;
|
|
950
|
-
/**
|
|
951
|
-
* Create a standard schema issue error associated with the target field
|
|
952
|
-
* @param issue The standard schema issue
|
|
953
|
-
* @param options The validation error options
|
|
954
|
-
*
|
|
955
|
-
* @category validation
|
|
956
|
-
* @experimental 21.0.0
|
|
957
|
-
*/
|
|
958
|
-
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: WithFieldTree<ValidationErrorOptions>): StandardSchemaValidationError;
|
|
959
|
-
/**
|
|
960
|
-
* Create a standard schema issue error
|
|
961
|
-
* @param issue The standard schema issue
|
|
962
|
-
* @param options The optional validation error options
|
|
963
|
-
*
|
|
964
|
-
* @category validation
|
|
965
|
-
* @experimental 21.0.0
|
|
966
|
-
*/
|
|
967
|
-
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions): WithoutFieldTree<StandardSchemaValidationError>;
|
|
968
1142
|
/**
|
|
969
1143
|
* Common interface for all validation errors.
|
|
970
1144
|
*
|
|
@@ -1035,7 +1209,7 @@ declare namespace ValidationError {
|
|
|
1035
1209
|
*
|
|
1036
1210
|
* @experimental 21.0.0
|
|
1037
1211
|
*/
|
|
1038
|
-
declare abstract class
|
|
1212
|
+
declare abstract class BaseNgValidationError implements ValidationError {
|
|
1039
1213
|
/** Brand the class to avoid Typescript structural matching */
|
|
1040
1214
|
private __brand;
|
|
1041
1215
|
/** Identifies the kind of error. */
|
|
@@ -1052,7 +1226,7 @@ declare abstract class _NgValidationError implements ValidationError {
|
|
|
1052
1226
|
* @category validation
|
|
1053
1227
|
* @experimental 21.0.0
|
|
1054
1228
|
*/
|
|
1055
|
-
declare class RequiredValidationError extends
|
|
1229
|
+
declare class RequiredValidationError extends BaseNgValidationError {
|
|
1056
1230
|
readonly kind = "required";
|
|
1057
1231
|
}
|
|
1058
1232
|
/**
|
|
@@ -1061,7 +1235,7 @@ declare class RequiredValidationError extends _NgValidationError {
|
|
|
1061
1235
|
* @category validation
|
|
1062
1236
|
* @experimental 21.0.0
|
|
1063
1237
|
*/
|
|
1064
|
-
declare class MinValidationError extends
|
|
1238
|
+
declare class MinValidationError extends BaseNgValidationError {
|
|
1065
1239
|
readonly min: number;
|
|
1066
1240
|
readonly kind = "min";
|
|
1067
1241
|
constructor(min: number, options?: ValidationErrorOptions);
|
|
@@ -1072,7 +1246,7 @@ declare class MinValidationError extends _NgValidationError {
|
|
|
1072
1246
|
* @category validation
|
|
1073
1247
|
* @experimental 21.0.0
|
|
1074
1248
|
*/
|
|
1075
|
-
declare class MaxValidationError extends
|
|
1249
|
+
declare class MaxValidationError extends BaseNgValidationError {
|
|
1076
1250
|
readonly max: number;
|
|
1077
1251
|
readonly kind = "max";
|
|
1078
1252
|
constructor(max: number, options?: ValidationErrorOptions);
|
|
@@ -1083,7 +1257,7 @@ declare class MaxValidationError extends _NgValidationError {
|
|
|
1083
1257
|
* @category validation
|
|
1084
1258
|
* @experimental 21.0.0
|
|
1085
1259
|
*/
|
|
1086
|
-
declare class MinLengthValidationError extends
|
|
1260
|
+
declare class MinLengthValidationError extends BaseNgValidationError {
|
|
1087
1261
|
readonly minLength: number;
|
|
1088
1262
|
readonly kind = "minLength";
|
|
1089
1263
|
constructor(minLength: number, options?: ValidationErrorOptions);
|
|
@@ -1094,7 +1268,7 @@ declare class MinLengthValidationError extends _NgValidationError {
|
|
|
1094
1268
|
* @category validation
|
|
1095
1269
|
* @experimental 21.0.0
|
|
1096
1270
|
*/
|
|
1097
|
-
declare class MaxLengthValidationError extends
|
|
1271
|
+
declare class MaxLengthValidationError extends BaseNgValidationError {
|
|
1098
1272
|
readonly maxLength: number;
|
|
1099
1273
|
readonly kind = "maxLength";
|
|
1100
1274
|
constructor(maxLength: number, options?: ValidationErrorOptions);
|
|
@@ -1105,7 +1279,7 @@ declare class MaxLengthValidationError extends _NgValidationError {
|
|
|
1105
1279
|
* @category validation
|
|
1106
1280
|
* @experimental 21.0.0
|
|
1107
1281
|
*/
|
|
1108
|
-
declare class PatternValidationError extends
|
|
1282
|
+
declare class PatternValidationError extends BaseNgValidationError {
|
|
1109
1283
|
readonly pattern: RegExp;
|
|
1110
1284
|
readonly kind = "pattern";
|
|
1111
1285
|
constructor(pattern: RegExp, options?: ValidationErrorOptions);
|
|
@@ -1116,20 +1290,9 @@ declare class PatternValidationError extends _NgValidationError {
|
|
|
1116
1290
|
* @category validation
|
|
1117
1291
|
* @experimental 21.0.0
|
|
1118
1292
|
*/
|
|
1119
|
-
declare class EmailValidationError extends
|
|
1293
|
+
declare class EmailValidationError extends BaseNgValidationError {
|
|
1120
1294
|
readonly kind = "email";
|
|
1121
1295
|
}
|
|
1122
|
-
/**
|
|
1123
|
-
* An error used to indicate an issue validating against a standard schema.
|
|
1124
|
-
*
|
|
1125
|
-
* @category validation
|
|
1126
|
-
* @experimental 21.0.0
|
|
1127
|
-
*/
|
|
1128
|
-
declare class StandardSchemaValidationError extends _NgValidationError {
|
|
1129
|
-
readonly issue: StandardSchemaV1.Issue;
|
|
1130
|
-
readonly kind = "standardSchema";
|
|
1131
|
-
constructor(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions);
|
|
1132
|
-
}
|
|
1133
1296
|
/**
|
|
1134
1297
|
* The base class for all built-in, non-custom errors. This class can be used to check if an error
|
|
1135
1298
|
* is one of the standard kinds, allowing you to switch on the kind to further narrow the type.
|
|
@@ -1176,992 +1339,40 @@ interface SignalFormsConfig {
|
|
|
1176
1339
|
*/
|
|
1177
1340
|
declare function provideSignalFormsConfig(config: SignalFormsConfig): Provider[];
|
|
1178
1341
|
|
|
1179
|
-
/** Represents a result that should be ignored because its predicate indicates it is not active. */
|
|
1180
|
-
declare const IGNORED: unique symbol;
|
|
1181
|
-
/**
|
|
1182
|
-
* A predicate that indicates whether an `AbstractLogic` instance is currently active, or should be
|
|
1183
|
-
* ignored.
|
|
1184
|
-
*/
|
|
1185
|
-
interface Predicate {
|
|
1186
|
-
/** A boolean logic function that returns true if the logic is considered active. */
|
|
1187
|
-
readonly fn: LogicFn<any, boolean>;
|
|
1188
|
-
/**
|
|
1189
|
-
* The path which this predicate was created for. This is used to determine the correct
|
|
1190
|
-
* `FieldContext` to pass to the predicate function.
|
|
1191
|
-
*/
|
|
1192
|
-
readonly path: SchemaPath<any>;
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Represents a predicate that is bound to a particular depth in the field tree. This is needed for
|
|
1196
|
-
* recursively applied logic to ensure that the predicate is evaluated against the correct
|
|
1197
|
-
* application of that logic.
|
|
1198
|
-
*
|
|
1199
|
-
* Consider the following example:
|
|
1200
|
-
*
|
|
1201
|
-
* ```ts
|
|
1202
|
-
* const s = schema(p => {
|
|
1203
|
-
* disabled(p.data);
|
|
1204
|
-
* applyWhen(p.next, ({valueOf}) => valueOf(p.data) === 1, s);
|
|
1205
|
-
* });
|
|
1206
|
-
*
|
|
1207
|
-
* const f = form(signal({data: 0, next: {data: 1, next: {data: 2, next: undefined}}}), s);
|
|
1208
|
-
*
|
|
1209
|
-
* const isDisabled = f.next.next.data().disabled();
|
|
1210
|
-
* ```
|
|
1211
|
-
*
|
|
1212
|
-
* In order to determine `isDisabled` we need to evaluate the predicate from `applyWhen` *twice*.
|
|
1213
|
-
* Once to see if the schema should be applied to `f.next` and again to see if it should be applied
|
|
1214
|
-
* to `f.next.next`. The `depth` tells us which field we should be evaluating against each time.
|
|
1215
|
-
*/
|
|
1216
|
-
interface BoundPredicate extends Predicate {
|
|
1217
|
-
/** The depth in the field tree at which this predicate is bound. */
|
|
1218
|
-
readonly depth: number;
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Base class for all logic. It is responsible for combining the results from multiple individual
|
|
1222
|
-
* logic functions registered in the schema, and using them to derive the value for some associated
|
|
1223
|
-
* piece of field state.
|
|
1224
|
-
*/
|
|
1225
|
-
declare abstract class AbstractLogic<TReturn, TValue = TReturn> {
|
|
1226
|
-
/**
|
|
1227
|
-
* A list of predicates that conditionally enable all logic in this logic instance.
|
|
1228
|
-
* The logic is only enabled when *all* of the predicates evaluate to true.
|
|
1229
|
-
*/
|
|
1230
|
-
private predicates;
|
|
1231
|
-
/** The set of logic functions that contribute to the value of the associated state. */
|
|
1232
|
-
protected readonly fns: Array<LogicFn<any, TValue | typeof IGNORED>>;
|
|
1233
|
-
constructor(
|
|
1234
|
-
/**
|
|
1235
|
-
* A list of predicates that conditionally enable all logic in this logic instance.
|
|
1236
|
-
* The logic is only enabled when *all* of the predicates evaluate to true.
|
|
1237
|
-
*/
|
|
1238
|
-
predicates: ReadonlyArray<BoundPredicate>);
|
|
1239
|
-
/**
|
|
1240
|
-
* Computes the value of the associated field state based on the logic functions and predicates
|
|
1241
|
-
* registered with this logic instance.
|
|
1242
|
-
*/
|
|
1243
|
-
abstract compute(arg: FieldContext<any>): TReturn;
|
|
1244
|
-
/**
|
|
1245
|
-
* The default value that the associated field state should assume if there are no logic functions
|
|
1246
|
-
* registered by the schema (or if the logic is disabled by a predicate).
|
|
1247
|
-
*/
|
|
1248
|
-
abstract get defaultValue(): TReturn;
|
|
1249
|
-
/** Registers a logic function with this logic instance. */
|
|
1250
|
-
push(logicFn: LogicFn<any, TValue>): void;
|
|
1251
|
-
/**
|
|
1252
|
-
* Merges in the logic from another logic instance, subject to the predicates of both the other
|
|
1253
|
-
* instance and this instance.
|
|
1254
|
-
*/
|
|
1255
|
-
mergeIn(other: AbstractLogic<TReturn, TValue>): void;
|
|
1256
|
-
}
|
|
1257
|
-
/** Logic that combines its individual logic function results with logical OR. */
|
|
1258
|
-
declare class BooleanOrLogic extends AbstractLogic<boolean> {
|
|
1259
|
-
get defaultValue(): boolean;
|
|
1260
|
-
compute(arg: FieldContext<any>): boolean;
|
|
1261
|
-
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Logic that combines its individual logic function results by aggregating them in an array.
|
|
1264
|
-
* Depending on its `ignore` function it may ignore certain values, omitting them from the array.
|
|
1265
|
-
*/
|
|
1266
|
-
declare class ArrayMergeIgnoreLogic<TElement, TIgnore = never> extends AbstractLogic<readonly TElement[], TElement | readonly (TElement | TIgnore)[] | TIgnore | undefined | void> {
|
|
1267
|
-
private ignore;
|
|
1268
|
-
/** Creates an instance of this class that ignores `null` values. */
|
|
1269
|
-
static ignoreNull<TElement>(predicates: ReadonlyArray<BoundPredicate>): ArrayMergeIgnoreLogic<TElement, null>;
|
|
1270
|
-
constructor(predicates: ReadonlyArray<BoundPredicate>, ignore: undefined | ((e: TElement | undefined | TIgnore) => e is TIgnore));
|
|
1271
|
-
get defaultValue(): never[];
|
|
1272
|
-
compute(arg: FieldContext<any>): readonly TElement[];
|
|
1273
|
-
}
|
|
1274
|
-
/** Logic that combines its individual logic function results by aggregating them in an array. */
|
|
1275
|
-
declare class ArrayMergeLogic<TElement> extends ArrayMergeIgnoreLogic<TElement, never> {
|
|
1276
|
-
constructor(predicates: ReadonlyArray<BoundPredicate>);
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Container for all the different types of logic that can be applied to a field
|
|
1280
|
-
* (disabled, hidden, errors, etc.)
|
|
1281
|
-
*/
|
|
1282
|
-
declare class LogicContainer {
|
|
1283
|
-
private predicates;
|
|
1284
|
-
/** Logic that determines if the field is hidden. */
|
|
1285
|
-
readonly hidden: BooleanOrLogic;
|
|
1286
|
-
/** Logic that determines reasons for the field being disabled. */
|
|
1287
|
-
readonly disabledReasons: ArrayMergeLogic<DisabledReason>;
|
|
1288
|
-
/** Logic that determines if the field is read-only. */
|
|
1289
|
-
readonly readonly: BooleanOrLogic;
|
|
1290
|
-
/** Logic that produces synchronous validation errors for the field. */
|
|
1291
|
-
readonly syncErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree, null>;
|
|
1292
|
-
/** Logic that produces synchronous validation errors for the field's subtree. */
|
|
1293
|
-
readonly syncTreeErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree, null>;
|
|
1294
|
-
/** Logic that produces asynchronous validation results (errors or 'pending'). */
|
|
1295
|
-
readonly asyncErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree | 'pending', null>;
|
|
1296
|
-
/** A map of metadata keys to the `AbstractLogic` instances that compute their values. */
|
|
1297
|
-
private readonly metadata;
|
|
1298
|
-
/**
|
|
1299
|
-
* Constructs a new `Logic` container.
|
|
1300
|
-
* @param predicates An array of predicates that must all be true for the logic
|
|
1301
|
-
* functions within this container to be active.
|
|
1302
|
-
*/
|
|
1303
|
-
constructor(predicates: ReadonlyArray<BoundPredicate>);
|
|
1304
|
-
/** Checks whether there is logic for the given metadata key. */
|
|
1305
|
-
hasMetadata(key: MetadataKey<any, any, any>): boolean;
|
|
1306
|
-
/**
|
|
1307
|
-
* Gets an iterable of [metadata key, logic function] pairs.
|
|
1308
|
-
* @returns An iterable of metadata keys.
|
|
1309
|
-
*/
|
|
1310
|
-
getMetadataKeys(): MapIterator<MetadataKey<unknown, unknown, unknown>>;
|
|
1311
|
-
/**
|
|
1312
|
-
* Retrieves or creates the `AbstractLogic` for a given metadata key.
|
|
1313
|
-
* @param key The `MetadataKey` for which to get the logic.
|
|
1314
|
-
* @returns The `AbstractLogic` associated with the key.
|
|
1315
|
-
*/
|
|
1316
|
-
getMetadata<T>(key: MetadataKey<any, T, any>): AbstractLogic<T>;
|
|
1317
|
-
/**
|
|
1318
|
-
* Merges logic from another `Logic` instance into this one.
|
|
1319
|
-
* @param other The `Logic` instance to merge from.
|
|
1320
|
-
*/
|
|
1321
|
-
mergeIn(other: LogicContainer): void;
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
/**
|
|
1325
|
-
* Abstract base class for building a `LogicNode`.
|
|
1326
|
-
* This class defines the interface for adding various logic rules (e.g., hidden, disabled)
|
|
1327
|
-
* and data factories to a node in the logic tree.
|
|
1328
|
-
* LogicNodeBuilders are 1:1 with nodes in the Schema tree.
|
|
1329
|
-
*/
|
|
1330
|
-
declare abstract class AbstractLogicNodeBuilder {
|
|
1331
|
-
/** The depth of this node in the schema tree. */
|
|
1332
|
-
protected readonly depth: number;
|
|
1333
|
-
constructor(
|
|
1334
|
-
/** The depth of this node in the schema tree. */
|
|
1335
|
-
depth: number);
|
|
1336
|
-
/** Adds a rule to determine if a field should be hidden. */
|
|
1337
|
-
abstract addHiddenRule(logic: LogicFn<any, boolean>): void;
|
|
1338
|
-
/** Adds a rule to determine if a field should be disabled, and for what reason. */
|
|
1339
|
-
abstract addDisabledReasonRule(logic: LogicFn<any, DisabledReason | undefined>): void;
|
|
1340
|
-
/** Adds a rule to determine if a field should be read-only. */
|
|
1341
|
-
abstract addReadonlyRule(logic: LogicFn<any, boolean>): void;
|
|
1342
|
-
/** Adds a rule for synchronous validation errors for a field. */
|
|
1343
|
-
abstract addSyncErrorRule(logic: LogicFn<any, ValidationResult>): void;
|
|
1344
|
-
/** Adds a rule for synchronous validation errors that apply to a subtree. */
|
|
1345
|
-
abstract addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult>): void;
|
|
1346
|
-
/** Adds a rule for asynchronous validation errors for a field. */
|
|
1347
|
-
abstract addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult>): void;
|
|
1348
|
-
/** Adds a rule to compute metadata for a field. */
|
|
1349
|
-
abstract addMetadataRule<M>(key: MetadataKey<unknown, M, unknown>, logic: LogicFn<any, M>): void;
|
|
1350
|
-
/**
|
|
1351
|
-
* Gets a builder for a child node associated with the given property key.
|
|
1352
|
-
* @param key The property key of the child.
|
|
1353
|
-
* @returns A `LogicNodeBuilder` for the child.
|
|
1354
|
-
*/
|
|
1355
|
-
abstract getChild(key: PropertyKey): LogicNodeBuilder;
|
|
1356
|
-
/**
|
|
1357
|
-
* Checks whether a particular `AbstractLogicNodeBuilder` has been merged into this one.
|
|
1358
|
-
* @param builder The builder to check for.
|
|
1359
|
-
* @returns True if the builder has been merged, false otherwise.
|
|
1360
|
-
*/
|
|
1361
|
-
abstract hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
1362
|
-
/**
|
|
1363
|
-
* Builds the `LogicNode` from the accumulated rules and child builders.
|
|
1364
|
-
* @returns The constructed `LogicNode`.
|
|
1365
|
-
*/
|
|
1366
|
-
build(): LogicNode;
|
|
1367
|
-
}
|
|
1368
|
-
/**
|
|
1369
|
-
* A builder for `LogicNode`. Used to add logic to the final `LogicNode` tree.
|
|
1370
|
-
* This builder supports merging multiple sources of logic, potentially with predicates,
|
|
1371
|
-
* preserving the order of rule application.
|
|
1372
|
-
*/
|
|
1373
|
-
declare class LogicNodeBuilder extends AbstractLogicNodeBuilder {
|
|
1374
|
-
constructor(depth: number);
|
|
1375
|
-
/**
|
|
1376
|
-
* The current `NonMergeableLogicNodeBuilder` being used to add rules directly to this
|
|
1377
|
-
* `LogicNodeBuilder`. Do not use this directly, call `getCurrent()` which will create a current
|
|
1378
|
-
* builder if there is none.
|
|
1379
|
-
*/
|
|
1380
|
-
private current;
|
|
1381
|
-
/**
|
|
1382
|
-
* Stores all builders that contribute to this node, along with any predicates
|
|
1383
|
-
* that gate their application.
|
|
1384
|
-
*/
|
|
1385
|
-
readonly all: {
|
|
1386
|
-
builder: AbstractLogicNodeBuilder;
|
|
1387
|
-
predicate?: Predicate;
|
|
1388
|
-
}[];
|
|
1389
|
-
addHiddenRule(logic: LogicFn<any, boolean>): void;
|
|
1390
|
-
addDisabledReasonRule(logic: LogicFn<any, DisabledReason | undefined>): void;
|
|
1391
|
-
addReadonlyRule(logic: LogicFn<any, boolean>): void;
|
|
1392
|
-
addSyncErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1393
|
-
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1394
|
-
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1395
|
-
addMetadataRule<T>(key: MetadataKey<unknown, T, any>, logic: LogicFn<any, T>): void;
|
|
1396
|
-
getChild(key: PropertyKey): LogicNodeBuilder;
|
|
1397
|
-
hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
1398
|
-
/**
|
|
1399
|
-
* Merges logic from another `LogicNodeBuilder` into this one.
|
|
1400
|
-
* If a `predicate` is provided, all logic from the `other` builder will only apply
|
|
1401
|
-
* when the predicate evaluates to true.
|
|
1402
|
-
* @param other The `LogicNodeBuilder` to merge in.
|
|
1403
|
-
* @param predicate An optional predicate to gate the merged logic.
|
|
1404
|
-
*/
|
|
1405
|
-
mergeIn(other: LogicNodeBuilder, predicate?: Predicate): void;
|
|
1406
|
-
/**
|
|
1407
|
-
* Gets the current `NonMergeableLogicNodeBuilder` for adding rules directly to this
|
|
1408
|
-
* `LogicNodeBuilder`. If no current builder exists, a new one is created.
|
|
1409
|
-
* The current builder is cleared whenever `mergeIn` is called to preserve the order
|
|
1410
|
-
* of rules when merging separate builder trees.
|
|
1411
|
-
* @returns The current `NonMergeableLogicNodeBuilder`.
|
|
1412
|
-
*/
|
|
1413
|
-
private getCurrent;
|
|
1414
|
-
/**
|
|
1415
|
-
* Creates a new root `LogicNodeBuilder`.
|
|
1416
|
-
* @returns A new instance of `LogicNodeBuilder`.
|
|
1417
|
-
*/
|
|
1418
|
-
static newRoot(): LogicNodeBuilder;
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Represents a node in the logic tree, containing all logic applicable
|
|
1422
|
-
* to a specific field or path in the form structure.
|
|
1423
|
-
* LogicNodes are 1:1 with nodes in the Field tree.
|
|
1424
|
-
*/
|
|
1425
|
-
interface LogicNode {
|
|
1426
|
-
/** The collection of logic rules (hidden, disabled, errors, etc.) for this node. */
|
|
1427
|
-
readonly logic: LogicContainer;
|
|
1428
|
-
/**
|
|
1429
|
-
* Retrieves the `LogicNode` for a child identified by the given property key.
|
|
1430
|
-
* @param key The property key of the child.
|
|
1431
|
-
* @returns The `LogicNode` for the specified child.
|
|
1432
|
-
*/
|
|
1433
|
-
getChild(key: PropertyKey): LogicNode;
|
|
1434
|
-
/**
|
|
1435
|
-
* Checks whether the logic from a particular `AbstractLogicNodeBuilder` has been merged into this
|
|
1436
|
-
* node.
|
|
1437
|
-
* @param builder The builder to check for.
|
|
1438
|
-
* @returns True if the builder has been merged, false otherwise.
|
|
1439
|
-
*/
|
|
1440
|
-
hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
/**
|
|
1444
|
-
* Implements the `Schema` concept.
|
|
1445
|
-
*/
|
|
1446
|
-
declare class SchemaImpl {
|
|
1447
|
-
private schemaFn;
|
|
1448
|
-
constructor(schemaFn: SchemaFn<unknown>);
|
|
1449
|
-
/**
|
|
1450
|
-
* Compiles this schema within the current root compilation context. If the schema was previously
|
|
1451
|
-
* compiled within this context, we reuse the cached FieldPathNode, otherwise we create a new one
|
|
1452
|
-
* and cache it in the compilation context.
|
|
1453
|
-
*/
|
|
1454
|
-
compile(): FieldPathNode;
|
|
1455
|
-
/**
|
|
1456
|
-
* Creates a SchemaImpl from the given SchemaOrSchemaFn.
|
|
1457
|
-
*/
|
|
1458
|
-
static create(schema: SchemaImpl | SchemaOrSchemaFn<any>): SchemaImpl;
|
|
1459
|
-
/**
|
|
1460
|
-
* Compiles the given schema in a fresh compilation context. This clears the cached results of any
|
|
1461
|
-
* previous compilations.
|
|
1462
|
-
*/
|
|
1463
|
-
static rootCompile(schema: SchemaImpl | SchemaOrSchemaFn<any> | undefined): FieldPathNode;
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
/**
|
|
1467
|
-
* A path in the schema on which logic is stored so that it can be added to the corresponding field
|
|
1468
|
-
* when the field is created.
|
|
1469
|
-
*/
|
|
1470
|
-
declare class FieldPathNode {
|
|
1471
|
-
/** The property keys used to navigate from the root path to this path. */
|
|
1472
|
-
readonly keys: PropertyKey[];
|
|
1473
|
-
/** The parent of this path node. */
|
|
1474
|
-
private readonly parent;
|
|
1475
|
-
/** The key of this node in its parent. */
|
|
1476
|
-
private readonly keyInParent;
|
|
1477
|
-
/** The root path node from which this path node is descended. */
|
|
1478
|
-
readonly root: FieldPathNode;
|
|
1479
|
-
/**
|
|
1480
|
-
* A map containing all child path nodes that have been created on this path.
|
|
1481
|
-
* Child path nodes are created automatically on first access if they do not exist already.
|
|
1482
|
-
*/
|
|
1483
|
-
private readonly children;
|
|
1484
|
-
/**
|
|
1485
|
-
* A proxy that wraps the path node, allowing navigation to its child paths via property access.
|
|
1486
|
-
*/
|
|
1487
|
-
readonly fieldPathProxy: SchemaPath<any>;
|
|
1488
|
-
/**
|
|
1489
|
-
* For a root path node this will contain the root logic builder. For non-root nodes,
|
|
1490
|
-
* they determine their logic builder from their parent so this is undefined.
|
|
1491
|
-
*/
|
|
1492
|
-
private readonly logicBuilder;
|
|
1493
|
-
protected constructor(
|
|
1494
|
-
/** The property keys used to navigate from the root path to this path. */
|
|
1495
|
-
keys: PropertyKey[], root: FieldPathNode | undefined,
|
|
1496
|
-
/** The parent of this path node. */
|
|
1497
|
-
parent: FieldPathNode | undefined,
|
|
1498
|
-
/** The key of this node in its parent. */
|
|
1499
|
-
keyInParent: PropertyKey | undefined);
|
|
1500
|
-
/** The logic builder used to accumulate logic on this path node. */
|
|
1501
|
-
get builder(): LogicNodeBuilder;
|
|
1502
|
-
/**
|
|
1503
|
-
* Gets the path node for the given child property key.
|
|
1504
|
-
* Child paths are created automatically on first access if they do not exist already.
|
|
1505
|
-
*/
|
|
1506
|
-
getChild(key: PropertyKey): FieldPathNode;
|
|
1507
|
-
/**
|
|
1508
|
-
* Merges in logic from another schema to this one.
|
|
1509
|
-
* @param other The other schema to merge in the logic from
|
|
1510
|
-
* @param predicate A predicate indicating when the merged in logic should be active.
|
|
1511
|
-
*/
|
|
1512
|
-
mergeIn(other: SchemaImpl, predicate?: Predicate): void;
|
|
1513
|
-
/** Extracts the underlying path node from the given path proxy. */
|
|
1514
|
-
static unwrapFieldPath(formPath: SchemaPath<unknown, SchemaPathRules>): FieldPathNode;
|
|
1515
|
-
/** Creates a new root path node to be passed in to a schema function. */
|
|
1516
|
-
static newRoot(): FieldPathNode;
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
/**
|
|
1520
|
-
* Tracks custom metadata associated with a `FieldNode`.
|
|
1521
|
-
*/
|
|
1522
|
-
declare class FieldMetadataState {
|
|
1523
|
-
private readonly node;
|
|
1524
|
-
/** A map of all `MetadataKey` that have been defined for this field. */
|
|
1525
|
-
private readonly metadata;
|
|
1526
|
-
constructor(node: FieldNode);
|
|
1527
|
-
/** Gets the value of an `MetadataKey` for the field. */
|
|
1528
|
-
get<T>(key: MetadataKey<T, unknown, unknown>): T | undefined;
|
|
1529
|
-
/** Checks whether the current metadata state has the given metadata key. */
|
|
1530
|
-
has(key: MetadataKey<any, any, any>): boolean;
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
/**
|
|
1534
|
-
* The non-validation and non-submit state associated with a `FieldNode`, such as touched and dirty
|
|
1535
|
-
* status, as well as derived logical state.
|
|
1536
|
-
*/
|
|
1537
|
-
declare class FieldNodeState {
|
|
1538
|
-
private readonly node;
|
|
1539
|
-
/**
|
|
1540
|
-
* Indicates whether this field has been touched directly by the user (as opposed to indirectly by
|
|
1541
|
-
* touching a child field).
|
|
1542
|
-
*
|
|
1543
|
-
* A field is considered directly touched when a user stops editing it for the first time (i.e. on blur)
|
|
1544
|
-
*/
|
|
1545
|
-
private readonly selfTouched;
|
|
1546
|
-
/**
|
|
1547
|
-
* Indicates whether this field has been dirtied directly by the user (as opposed to indirectly by
|
|
1548
|
-
* dirtying a child field).
|
|
1549
|
-
*
|
|
1550
|
-
* A field is considered directly dirtied if a user changed the value of the field at least once.
|
|
1551
|
-
*/
|
|
1552
|
-
private readonly selfDirty;
|
|
1553
|
-
/**
|
|
1554
|
-
* Marks this specific field as touched.
|
|
1555
|
-
*/
|
|
1556
|
-
markAsTouched(): void;
|
|
1557
|
-
/**
|
|
1558
|
-
* Marks this specific field as dirty.
|
|
1559
|
-
*/
|
|
1560
|
-
markAsDirty(): void;
|
|
1561
|
-
/**
|
|
1562
|
-
* Marks this specific field as not dirty.
|
|
1563
|
-
*/
|
|
1564
|
-
markAsPristine(): void;
|
|
1565
|
-
/**
|
|
1566
|
-
* Marks this specific field as not touched.
|
|
1567
|
-
*/
|
|
1568
|
-
markAsUntouched(): void;
|
|
1569
|
-
/** The {@link FormField} directives that bind this field to a UI control. */
|
|
1570
|
-
readonly formFieldBindings: i0.WritableSignal<readonly FormField<unknown>[]>;
|
|
1571
|
-
constructor(node: FieldNode);
|
|
1572
|
-
/**
|
|
1573
|
-
* Whether this field is considered dirty.
|
|
1574
|
-
*
|
|
1575
|
-
* A field is considered dirty if one of the following is true:
|
|
1576
|
-
* - It was directly dirtied and is interactive
|
|
1577
|
-
* - One of its children is considered dirty
|
|
1578
|
-
*/
|
|
1579
|
-
readonly dirty: Signal<boolean>;
|
|
1580
|
-
/**
|
|
1581
|
-
* Whether this field is considered touched.
|
|
1582
|
-
*
|
|
1583
|
-
* A field is considered touched if one of the following is true:
|
|
1584
|
-
* - It was directly touched and is interactive
|
|
1585
|
-
* - One of its children is considered touched
|
|
1586
|
-
*/
|
|
1587
|
-
readonly touched: Signal<boolean>;
|
|
1588
|
-
/**
|
|
1589
|
-
* The reasons for this field's disablement. This includes disabled reasons for any parent field
|
|
1590
|
-
* that may have been disabled, indirectly causing this field to be disabled as well.
|
|
1591
|
-
* The `field` property of the `DisabledReason` can be used to determine which field ultimately
|
|
1592
|
-
* caused the disablement.
|
|
1593
|
-
*/
|
|
1594
|
-
readonly disabledReasons: Signal<readonly DisabledReason[]>;
|
|
1595
|
-
/**
|
|
1596
|
-
* Whether this field is considered disabled.
|
|
1597
|
-
*
|
|
1598
|
-
* A field is considered disabled if one of the following is true:
|
|
1599
|
-
* - The schema contains logic that directly disabled it
|
|
1600
|
-
* - Its parent field is considered disabled
|
|
1601
|
-
*/
|
|
1602
|
-
readonly disabled: Signal<boolean>;
|
|
1603
|
-
/**
|
|
1604
|
-
* Whether this field is considered readonly.
|
|
1605
|
-
*
|
|
1606
|
-
* A field is considered readonly if one of the following is true:
|
|
1607
|
-
* - The schema contains logic that directly made it readonly
|
|
1608
|
-
* - Its parent field is considered readonly
|
|
1609
|
-
*/
|
|
1610
|
-
readonly readonly: Signal<boolean>;
|
|
1611
|
-
/**
|
|
1612
|
-
* Whether this field is considered hidden.
|
|
1613
|
-
*
|
|
1614
|
-
* A field is considered hidden if one of the following is true:
|
|
1615
|
-
* - The schema contains logic that directly hides it
|
|
1616
|
-
* - Its parent field is considered hidden
|
|
1617
|
-
*/
|
|
1618
|
-
readonly hidden: Signal<boolean>;
|
|
1619
|
-
readonly name: Signal<string>;
|
|
1620
|
-
/**
|
|
1621
|
-
* An optional {@link Debouncer} factory for this field.
|
|
1622
|
-
*/
|
|
1623
|
-
readonly debouncer: Signal<((signal: AbortSignal) => Promise<void> | void) | undefined>;
|
|
1624
|
-
/** Whether this field is considered non-interactive.
|
|
1625
|
-
*
|
|
1626
|
-
* A field is considered non-interactive if one of the following is true:
|
|
1627
|
-
* - It is hidden
|
|
1628
|
-
* - It is disabled
|
|
1629
|
-
* - It is readonly
|
|
1630
|
-
*/
|
|
1631
|
-
private readonly isNonInteractive;
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
/**
|
|
1635
|
-
* State of a `FieldNode` that's associated with form submission.
|
|
1636
|
-
*/
|
|
1637
|
-
declare class FieldSubmitState {
|
|
1638
|
-
private readonly node;
|
|
1639
|
-
/**
|
|
1640
|
-
* Whether this field was directly submitted (as opposed to indirectly by a parent field being submitted)
|
|
1641
|
-
* and is still in the process of submitting.
|
|
1642
|
-
*/
|
|
1643
|
-
readonly selfSubmitting: WritableSignal<boolean>;
|
|
1644
|
-
/** Submission errors that are associated with this field. */
|
|
1645
|
-
readonly submissionErrors: WritableSignal<readonly ValidationError.WithFieldTree[]>;
|
|
1646
|
-
constructor(node: FieldNode);
|
|
1647
|
-
/**
|
|
1648
|
-
* Whether this form is currently in the process of being submitted.
|
|
1649
|
-
* Either because the field was submitted directly, or because a parent field was submitted.
|
|
1650
|
-
*/
|
|
1651
|
-
readonly submitting: Signal<boolean>;
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
interface ValidationState {
|
|
1655
|
-
/**
|
|
1656
|
-
* The full set of synchronous tree errors visible to this field. This includes ones that are
|
|
1657
|
-
* targeted at a descendant field rather than at this field.
|
|
1658
|
-
*/
|
|
1659
|
-
rawSyncTreeErrors: Signal<ValidationError.WithFieldTree[]>;
|
|
1660
|
-
/**
|
|
1661
|
-
* The full set of synchronous errors for this field, including synchronous tree errors and submission
|
|
1662
|
-
* errors. Submission errors are considered "synchronous" because they are imperatively added. From
|
|
1663
|
-
* the perspective of the field state they are either there or not, they are never in a pending
|
|
1664
|
-
* state.
|
|
1665
|
-
*/
|
|
1666
|
-
syncErrors: Signal<ValidationError.WithFieldTree[]>;
|
|
1667
|
-
/**
|
|
1668
|
-
* Whether the field is considered valid according solely to its synchronous validators.
|
|
1669
|
-
* Errors resulting from a previous submit attempt are also considered for this state.
|
|
1670
|
-
*/
|
|
1671
|
-
syncValid: Signal<boolean>;
|
|
1672
|
-
/**
|
|
1673
|
-
* The full set of asynchronous tree errors visible to this field. This includes ones that are
|
|
1674
|
-
* targeted at a descendant field rather than at this field, as well as sentinel 'pending' values
|
|
1675
|
-
* indicating that the validator is still running and an error could still occur.
|
|
1676
|
-
*/
|
|
1677
|
-
rawAsyncErrors: Signal<(ValidationError.WithFieldTree | 'pending')[]>;
|
|
1678
|
-
/**
|
|
1679
|
-
* The asynchronous tree errors visible to this field that are specifically targeted at this field
|
|
1680
|
-
* rather than a descendant. This also includes all 'pending' sentinel values, since those could
|
|
1681
|
-
* theoretically result in errors for this field.
|
|
1682
|
-
*/
|
|
1683
|
-
asyncErrors: Signal<(ValidationError.WithFieldTree | 'pending')[]>;
|
|
1684
|
-
/**
|
|
1685
|
-
* The combined set of all errors that currently apply to this field.
|
|
1686
|
-
*/
|
|
1687
|
-
errors: Signal<ValidationError.WithFieldTree[]>;
|
|
1688
|
-
parseErrors: Signal<ValidationError.WithFormField[]>;
|
|
1689
|
-
/**
|
|
1690
|
-
* The combined set of all errors that currently apply to this field and its descendants.
|
|
1691
|
-
*/
|
|
1692
|
-
errorSummary: Signal<ValidationError.WithFieldTree[]>;
|
|
1693
|
-
/**
|
|
1694
|
-
* Whether this field has any asynchronous validators still pending.
|
|
1695
|
-
*/
|
|
1696
|
-
pending: Signal<boolean>;
|
|
1697
|
-
/**
|
|
1698
|
-
* The validation status of the field.
|
|
1699
|
-
* - The status is 'valid' if neither the field nor any of its children has any errors or pending
|
|
1700
|
-
* validators.
|
|
1701
|
-
* - The status is 'invalid' if the field or any of its children has an error
|
|
1702
|
-
* (regardless of pending validators)
|
|
1703
|
-
* - The status is 'unknown' if neither the field nor any of its children has any errors,
|
|
1704
|
-
* but the field or any of its children does have a pending validator.
|
|
1705
|
-
*
|
|
1706
|
-
* A field is considered valid if *all* of the following are true:
|
|
1707
|
-
* - It has no errors or pending validators
|
|
1708
|
-
* - All of its children are considered valid
|
|
1709
|
-
* A field is considered invalid if *any* of the following are true:
|
|
1710
|
-
* - It has an error
|
|
1711
|
-
* - Any of its children is considered invalid
|
|
1712
|
-
* A field is considered to have unknown validity status if it is not valid or invalid.
|
|
1713
|
-
*/
|
|
1714
|
-
status: Signal<'valid' | 'invalid' | 'unknown'>;
|
|
1715
|
-
/**
|
|
1716
|
-
* Whether the field is considered valid.
|
|
1717
|
-
*
|
|
1718
|
-
* A field is considered valid if *all* of the following are true:
|
|
1719
|
-
* - It has no errors or pending validators
|
|
1720
|
-
* - All of its children are considered valid
|
|
1721
|
-
*
|
|
1722
|
-
* Note: `!valid()` is *not* the same as `invalid()`. Both `valid()` and `invalid()` can be false
|
|
1723
|
-
* if there are currently no errors, but validators are still pending.
|
|
1724
|
-
*/
|
|
1725
|
-
valid: Signal<boolean>;
|
|
1726
|
-
/**
|
|
1727
|
-
* Whether the field is considered invalid.
|
|
1728
|
-
*
|
|
1729
|
-
* A field is considered invalid if *any* of the following are true:
|
|
1730
|
-
* - It has an error
|
|
1731
|
-
* - Any of its children is considered invalid
|
|
1732
|
-
*
|
|
1733
|
-
* Note: `!invalid()` is *not* the same as `valid()`. Both `valid()` and `invalid()` can be false
|
|
1734
|
-
* if there are currently no errors, but validators are still pending.
|
|
1735
|
-
*/
|
|
1736
|
-
invalid: Signal<boolean>;
|
|
1737
|
-
/**
|
|
1738
|
-
* Indicates whether validation should be skipped for this field because it is hidden, disabled,
|
|
1739
|
-
* or readonly.
|
|
1740
|
-
*/
|
|
1741
|
-
shouldSkipValidation: Signal<boolean>;
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
/**
|
|
1745
|
-
* Internal node in the form tree for a given field.
|
|
1746
|
-
*
|
|
1747
|
-
* Field nodes have several responsibilities:
|
|
1748
|
-
* - They track instance state for the particular field (touched)
|
|
1749
|
-
* - They compute signals for derived state (valid, disabled, etc) based on their associated
|
|
1750
|
-
* `LogicNode`
|
|
1751
|
-
* - They act as the public API for the field (they implement the `FieldState` interface)
|
|
1752
|
-
* - They implement navigation of the form tree via `.parent` and `.getChild()`.
|
|
1753
|
-
*
|
|
1754
|
-
* This class is largely a wrapper that aggregates several smaller pieces that each manage a subset of
|
|
1755
|
-
* the responsibilities.
|
|
1756
|
-
*/
|
|
1757
|
-
declare class FieldNode implements FieldState<unknown> {
|
|
1758
|
-
readonly structure: FieldNodeStructure;
|
|
1759
|
-
readonly validationState: ValidationState;
|
|
1760
|
-
readonly metadataState: FieldMetadataState;
|
|
1761
|
-
readonly nodeState: FieldNodeState;
|
|
1762
|
-
readonly submitState: FieldSubmitState;
|
|
1763
|
-
readonly fieldAdapter: FieldAdapter;
|
|
1764
|
-
private _context;
|
|
1765
|
-
get context(): FieldContext<unknown>;
|
|
1766
|
-
/**
|
|
1767
|
-
* Proxy to this node which allows navigation of the form graph below it.
|
|
1768
|
-
*/
|
|
1769
|
-
readonly fieldProxy: FieldTree<any>;
|
|
1770
|
-
private readonly pathNode;
|
|
1771
|
-
constructor(options: FieldNodeOptions);
|
|
1772
|
-
focusBoundControl(options?: FocusOptions): void;
|
|
1773
|
-
/**
|
|
1774
|
-
* Gets the Field directive binding that should be focused when the developer calls
|
|
1775
|
-
* `focusBoundControl` on this node.
|
|
1776
|
-
*
|
|
1777
|
-
* This will prioritize focusable bindings to this node, and if multiple exist, it will return
|
|
1778
|
-
* the first one in the DOM. If no focusable bindings exist on this node, it will return the
|
|
1779
|
-
* first focusable binding in the DOM for any descendant node of this one.
|
|
1780
|
-
*/
|
|
1781
|
-
private getBindingForFocus;
|
|
1782
|
-
/**
|
|
1783
|
-
* The `AbortController` for the currently debounced sync, or `undefined` if there is none.
|
|
1784
|
-
*
|
|
1785
|
-
* This is used to cancel a pending debounced sync when {@link setControlValue} is called again
|
|
1786
|
-
* before the pending debounced sync resolves. It will also cancel any pending debounced sync
|
|
1787
|
-
* automatically when recomputed due to `value` being set directly from others sources.
|
|
1788
|
-
*/
|
|
1789
|
-
private readonly pendingSync;
|
|
1790
|
-
get logicNode(): LogicNode;
|
|
1791
|
-
get value(): WritableSignal<unknown>;
|
|
1792
|
-
private _controlValue;
|
|
1793
|
-
get controlValue(): Signal<unknown>;
|
|
1794
|
-
get keyInParent(): Signal<string | number>;
|
|
1795
|
-
get errors(): Signal<ValidationError.WithFieldTree[]>;
|
|
1796
|
-
get parseErrors(): Signal<ValidationError.WithFormField[]>;
|
|
1797
|
-
get errorSummary(): Signal<ValidationError.WithFieldTree[]>;
|
|
1798
|
-
get pending(): Signal<boolean>;
|
|
1799
|
-
get valid(): Signal<boolean>;
|
|
1800
|
-
get invalid(): Signal<boolean>;
|
|
1801
|
-
get dirty(): Signal<boolean>;
|
|
1802
|
-
get touched(): Signal<boolean>;
|
|
1803
|
-
get disabled(): Signal<boolean>;
|
|
1804
|
-
get disabledReasons(): Signal<readonly DisabledReason[]>;
|
|
1805
|
-
get hidden(): Signal<boolean>;
|
|
1806
|
-
get readonly(): Signal<boolean>;
|
|
1807
|
-
get formFieldBindings(): Signal<readonly FormField<unknown>[]>;
|
|
1808
|
-
get submitting(): Signal<boolean>;
|
|
1809
|
-
get name(): Signal<string>;
|
|
1810
|
-
get max(): Signal<number | undefined> | undefined;
|
|
1811
|
-
get maxLength(): Signal<number | undefined> | undefined;
|
|
1812
|
-
get min(): Signal<number | undefined> | undefined;
|
|
1813
|
-
get minLength(): Signal<number | undefined> | undefined;
|
|
1814
|
-
get pattern(): Signal<readonly RegExp[]>;
|
|
1815
|
-
get required(): Signal<boolean>;
|
|
1816
|
-
metadata<M>(key: MetadataKey<M, any, any>): M | undefined;
|
|
1817
|
-
hasMetadata(key: MetadataKey<any, any, any>): boolean;
|
|
1818
|
-
/**
|
|
1819
|
-
* Marks this specific field as touched.
|
|
1820
|
-
*/
|
|
1821
|
-
markAsTouched(): void;
|
|
1822
|
-
/**
|
|
1823
|
-
* Marks this specific field as dirty.
|
|
1824
|
-
*/
|
|
1825
|
-
markAsDirty(): void;
|
|
1826
|
-
/**
|
|
1827
|
-
* Resets the {@link touched} and {@link dirty} state of the field and its descendants.
|
|
1828
|
-
*
|
|
1829
|
-
* Note this does not change the data model, which can be reset directly if desired.
|
|
1830
|
-
*
|
|
1831
|
-
* @param value Optional value to set to the form. If not passed, the value will not be changed.
|
|
1832
|
-
*/
|
|
1833
|
-
reset(value?: unknown): void;
|
|
1834
|
-
private _reset;
|
|
1835
|
-
/**
|
|
1836
|
-
* Sets the control value of the field. This value may be debounced before it is synchronized with
|
|
1837
|
-
* the field's {@link value} signal, depending on the debounce configuration.
|
|
1838
|
-
*/
|
|
1839
|
-
setControlValue(newValue: unknown): void;
|
|
1840
|
-
/**
|
|
1841
|
-
* Synchronizes the {@link controlValue} with the {@link value} signal immediately.
|
|
1842
|
-
*/
|
|
1843
|
-
private sync;
|
|
1844
|
-
/**
|
|
1845
|
-
* If there is a pending sync, abort it and sync immediately.
|
|
1846
|
-
*/
|
|
1847
|
-
private flushSync;
|
|
1848
|
-
/**
|
|
1849
|
-
* Initiates a debounced {@link sync}.
|
|
1850
|
-
*
|
|
1851
|
-
* If a debouncer is configured, the synchronization will occur after the debouncer resolves. If
|
|
1852
|
-
* no debouncer is configured, the synchronization happens immediately. If {@link setControlValue}
|
|
1853
|
-
* is called again while a debounce is pending, the previous debounce operation is aborted in
|
|
1854
|
-
* favor of the new one.
|
|
1855
|
-
*/
|
|
1856
|
-
private debounceSync;
|
|
1857
|
-
/**
|
|
1858
|
-
* Creates a new root field node for a new form.
|
|
1859
|
-
*/
|
|
1860
|
-
static newRoot<T>(fieldManager: FormFieldManager, value: WritableSignal<T>, pathNode: FieldPathNode, adapter: FieldAdapter): FieldNode;
|
|
1861
|
-
createStructure(options: FieldNodeOptions): RootFieldNodeStructure | ChildFieldNodeStructure;
|
|
1862
|
-
private newChild;
|
|
1863
|
-
}
|
|
1864
|
-
/**
|
|
1865
|
-
* Field node of a field that has children.
|
|
1866
|
-
* This simplifies and makes certain types cleaner.
|
|
1867
|
-
*/
|
|
1868
|
-
interface ParentFieldNode extends FieldNode {
|
|
1869
|
-
readonly value: WritableSignal<Record<string, unknown>>;
|
|
1870
|
-
readonly structure: FieldNodeStructure & {
|
|
1871
|
-
value: WritableSignal<Record<string, unknown>>;
|
|
1872
|
-
};
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
/**
|
|
1876
|
-
* Key by which a parent `FieldNode` tracks its children.
|
|
1877
|
-
*
|
|
1878
|
-
* Often this is the actual property key of the child, but in the case of arrays it could be a
|
|
1879
|
-
* tracking key allocated for the object.
|
|
1880
|
-
*/
|
|
1881
|
-
type TrackingKey = PropertyKey & {
|
|
1882
|
-
__brand: 'FieldIdentity';
|
|
1883
|
-
};
|
|
1884
|
-
type ChildNodeCtor = (key: string, trackingKey: TrackingKey | undefined, isArray: boolean) => FieldNode;
|
|
1885
|
-
/** Structural component of a `FieldNode` which tracks its path, parent, and children. */
|
|
1886
|
-
declare abstract class FieldNodeStructure {
|
|
1887
|
-
/**
|
|
1888
|
-
* Computed map of child fields, based on the current value of this field.
|
|
1889
|
-
*
|
|
1890
|
-
* This structure reacts to `this.value` and produces a new `ChildrenData` when the
|
|
1891
|
-
* value changes structurally (fields added/removed/moved).
|
|
1892
|
-
*/
|
|
1893
|
-
protected abstract readonly childrenMap: Signal<ChildrenData | undefined>;
|
|
1894
|
-
/** The field's value. */
|
|
1895
|
-
abstract readonly value: WritableSignal<unknown>;
|
|
1896
|
-
/**
|
|
1897
|
-
* The key of this field in its parent field.
|
|
1898
|
-
* Attempting to read this for the root field will result in an error being thrown.
|
|
1899
|
-
*/
|
|
1900
|
-
abstract readonly keyInParent: Signal<string>;
|
|
1901
|
-
/** The field manager responsible for managing this field. */
|
|
1902
|
-
abstract readonly fieldManager: FormFieldManager;
|
|
1903
|
-
/** The root field that this field descends from. */
|
|
1904
|
-
abstract readonly root: FieldNode;
|
|
1905
|
-
/** The list of property keys to follow to get from the `root` to this field. */
|
|
1906
|
-
abstract readonly pathKeys: Signal<readonly string[]>;
|
|
1907
|
-
/** The parent field of this field. */
|
|
1908
|
-
abstract readonly parent: FieldNode | undefined;
|
|
1909
|
-
readonly logic: LogicNode;
|
|
1910
|
-
readonly node: FieldNode;
|
|
1911
|
-
readonly createChildNode: ChildNodeCtor;
|
|
1912
|
-
/** Added to array elements for tracking purposes. */
|
|
1913
|
-
readonly identitySymbol: symbol;
|
|
1914
|
-
/** Lazily initialized injector. Do not access directly, access via `injector` getter instead. */
|
|
1915
|
-
private _injector;
|
|
1916
|
-
/** Lazily initialized injector. */
|
|
1917
|
-
get injector(): DestroyableInjector;
|
|
1918
|
-
constructor(logic: LogicNode, node: FieldNode, createChildNode: ChildNodeCtor);
|
|
1919
|
-
/** Gets the child fields of this field. */
|
|
1920
|
-
children(): readonly FieldNode[];
|
|
1921
|
-
/** Retrieve a child `FieldNode` of this node by property key. */
|
|
1922
|
-
getChild(key: PropertyKey): FieldNode | undefined;
|
|
1923
|
-
/**
|
|
1924
|
-
* Perform a reduction over a field's children (if any) and return the result.
|
|
1925
|
-
*
|
|
1926
|
-
* Optionally, the reduction is short circuited based on the provided `shortCircuit` function.
|
|
1927
|
-
*/
|
|
1928
|
-
reduceChildren<T>(initialValue: T, fn: (child: FieldNode, value: T) => T, shortCircuit?: (value: T) => boolean): T;
|
|
1929
|
-
/** Destroys the field when it is no longer needed. */
|
|
1930
|
-
destroy(): void;
|
|
1931
|
-
/**
|
|
1932
|
-
* Creates a keyInParent signal for a field node.
|
|
1933
|
-
*
|
|
1934
|
-
* For root nodes, returns ROOT_KEY_IN_PARENT which throws when accessed.
|
|
1935
|
-
* For child nodes, creates a computed that tracks the field's current key in its parent,
|
|
1936
|
-
* with special handling for tracked array elements.
|
|
1937
|
-
*
|
|
1938
|
-
* @param options The field node options
|
|
1939
|
-
* @param identityInParent The tracking identity (only for tracked array children)
|
|
1940
|
-
* @param initialKeyInParent The initial key in parent (only for child nodes)
|
|
1941
|
-
* @returns A signal representing the field's key in its parent
|
|
1942
|
-
*/
|
|
1943
|
-
protected createKeyInParent(options: FieldNodeOptions, identityInParent: TrackingKey | undefined, initialKeyInParent: string | undefined): Signal<string>;
|
|
1944
|
-
protected createChildrenMap(): Signal<ChildrenData | undefined>;
|
|
1945
|
-
/**
|
|
1946
|
-
* Creates a "reader" computed for the given key.
|
|
1947
|
-
*
|
|
1948
|
-
* A reader is a computed signal that memoizes the access of the `FieldNode` stored at this key
|
|
1949
|
-
* (or returns `undefined` if no such field exists). Accessing fields via the reader ensures that
|
|
1950
|
-
* reactive consumers aren't notified unless the field at a key actually changes.
|
|
1951
|
-
*/
|
|
1952
|
-
private createReader;
|
|
1953
|
-
}
|
|
1954
|
-
/** The structural component of a `FieldNode` that is the root of its field tree. */
|
|
1955
|
-
declare class RootFieldNodeStructure extends FieldNodeStructure {
|
|
1956
|
-
readonly fieldManager: FormFieldManager;
|
|
1957
|
-
readonly value: WritableSignal<unknown>;
|
|
1958
|
-
get parent(): undefined;
|
|
1959
|
-
get root(): FieldNode;
|
|
1960
|
-
get pathKeys(): Signal<readonly string[]>;
|
|
1961
|
-
get keyInParent(): Signal<string>;
|
|
1962
|
-
protected readonly childrenMap: Signal<ChildrenData | undefined>;
|
|
1963
|
-
/**
|
|
1964
|
-
* Creates the structure for the root node of a field tree.
|
|
1965
|
-
*
|
|
1966
|
-
* @param node The full field node that this structure belongs to
|
|
1967
|
-
* @param pathNode The path corresponding to this node in the schema
|
|
1968
|
-
* @param logic The logic to apply to this field
|
|
1969
|
-
* @param fieldManager The field manager for this field
|
|
1970
|
-
* @param value The value signal for this field
|
|
1971
|
-
* @param adapter Adapter that knows how to create new fields and appropriate state.
|
|
1972
|
-
* @param createChildNode A factory function to create child nodes for this field.
|
|
1973
|
-
*/
|
|
1974
|
-
constructor(
|
|
1975
|
-
/** The full field node that corresponds to this structure. */
|
|
1976
|
-
node: FieldNode, logic: LogicNode, fieldManager: FormFieldManager, value: WritableSignal<unknown>, createChildNode: ChildNodeCtor);
|
|
1977
|
-
}
|
|
1978
|
-
/** The structural component of a child `FieldNode` within a field tree. */
|
|
1979
|
-
declare class ChildFieldNodeStructure extends FieldNodeStructure {
|
|
1980
|
-
readonly logic: LogicNode;
|
|
1981
|
-
readonly parent: ParentFieldNode;
|
|
1982
|
-
readonly root: FieldNode;
|
|
1983
|
-
readonly pathKeys: Signal<readonly string[]>;
|
|
1984
|
-
readonly keyInParent: Signal<string>;
|
|
1985
|
-
readonly value: WritableSignal<unknown>;
|
|
1986
|
-
readonly childrenMap: Signal<ChildrenData | undefined>;
|
|
1987
|
-
get fieldManager(): FormFieldManager;
|
|
1988
|
-
/**
|
|
1989
|
-
* Creates the structure for a child field node in a field tree.
|
|
1990
|
-
*
|
|
1991
|
-
* @param node The full field node that this structure belongs to
|
|
1992
|
-
* @param pathNode The path corresponding to this node in the schema
|
|
1993
|
-
* @param logic The logic to apply to this field
|
|
1994
|
-
* @param parent The parent field node for this node
|
|
1995
|
-
* @param identityInParent The identity used to track this field in its parent
|
|
1996
|
-
* @param initialKeyInParent The key of this field in its parent at the time of creation
|
|
1997
|
-
* @param adapter Adapter that knows how to create new fields and appropriate state.
|
|
1998
|
-
* @param createChildNode A factory function to create child nodes for this field.
|
|
1999
|
-
*/
|
|
2000
|
-
constructor(node: FieldNode, logic: LogicNode, parent: ParentFieldNode, identityInParent: TrackingKey | undefined, initialKeyInParent: string, createChildNode: ChildNodeCtor);
|
|
2001
|
-
}
|
|
2002
|
-
/** Options passed when constructing a root field node. */
|
|
2003
|
-
interface RootFieldNodeOptions {
|
|
2004
|
-
/** Kind of node, used to differentiate root node options from child node options. */
|
|
2005
|
-
readonly kind: 'root';
|
|
2006
|
-
/** The path node corresponding to this field in the schema. */
|
|
2007
|
-
readonly pathNode: FieldPathNode;
|
|
2008
|
-
/** The logic to apply to this field. */
|
|
2009
|
-
readonly logic: LogicNode;
|
|
2010
|
-
/** The value signal for this field. */
|
|
2011
|
-
readonly value: WritableSignal<unknown>;
|
|
2012
|
-
/** The field manager for this field. */
|
|
2013
|
-
readonly fieldManager: FormFieldManager;
|
|
2014
|
-
/** This allows for more granular field and state management, and is currently used for compat. */
|
|
2015
|
-
readonly fieldAdapter: FieldAdapter;
|
|
2016
|
-
}
|
|
2017
|
-
/** Options passed when constructing a child field node. */
|
|
2018
|
-
interface ChildFieldNodeOptions {
|
|
2019
|
-
/** Kind of node, used to differentiate root node options from child node options. */
|
|
2020
|
-
readonly kind: 'child';
|
|
2021
|
-
/** The parent field node of this field. */
|
|
2022
|
-
readonly parent: ParentFieldNode;
|
|
2023
|
-
/** The path node corresponding to this field in the schema. */
|
|
2024
|
-
readonly pathNode: FieldPathNode;
|
|
2025
|
-
/** The logic to apply to this field. */
|
|
2026
|
-
readonly logic: LogicNode;
|
|
2027
|
-
/** The key of this field in its parent at the time of creation. */
|
|
2028
|
-
readonly initialKeyInParent: string;
|
|
2029
|
-
/** The identity used to track this field in its parent. */
|
|
2030
|
-
readonly identityInParent: TrackingKey | undefined;
|
|
2031
|
-
/** This allows for more granular field and state management, and is currently used for compat. */
|
|
2032
|
-
readonly fieldAdapter: FieldAdapter;
|
|
2033
|
-
}
|
|
2034
|
-
/** Options passed when constructing a field node. */
|
|
2035
|
-
type FieldNodeOptions = RootFieldNodeOptions | ChildFieldNodeOptions;
|
|
2036
|
-
/**
|
|
2037
|
-
* Derived data regarding child fields for a specific parent field.
|
|
2038
|
-
*/
|
|
2039
|
-
interface ChildrenData {
|
|
2040
|
-
/**
|
|
2041
|
-
* Tracks `ChildData` for each property key within the parent.
|
|
2042
|
-
*/
|
|
2043
|
-
readonly byPropertyKey: ReadonlyMap<string, ChildData>;
|
|
2044
|
-
/**
|
|
2045
|
-
* Tracks the instance of child `FieldNode`s by their tracking key, which is always 1:1 with the
|
|
2046
|
-
* fields, even if they move around in the parent.
|
|
2047
|
-
*/
|
|
2048
|
-
readonly byTrackingKey?: ReadonlyMap<TrackingKey, FieldNode>;
|
|
2049
|
-
}
|
|
2050
|
-
/**
|
|
2051
|
-
* Data for a specific child within a parent.
|
|
2052
|
-
*/
|
|
2053
|
-
interface ChildData {
|
|
2054
|
-
/**
|
|
2055
|
-
* A computed signal to access the `FieldNode` currently stored at a specific key.
|
|
2056
|
-
*
|
|
2057
|
-
* Because this is a computed, it only updates whenever the `FieldNode` at that key changes.
|
|
2058
|
-
* Because `ChildData` is always associated with a specific key via `ChildrenData.byPropertyKey`,
|
|
2059
|
-
* this computed gives a stable way to watch the field stored for a given property and only
|
|
2060
|
-
* receives notifications when that field changes.
|
|
2061
|
-
*/
|
|
2062
|
-
readonly reader: Signal<FieldNode | undefined>;
|
|
2063
|
-
/**
|
|
2064
|
-
* The child `FieldNode` currently stored at this key.
|
|
2065
|
-
*/
|
|
2066
|
-
node: FieldNode;
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
1342
|
/**
|
|
2070
|
-
*
|
|
1343
|
+
* Options that can be specified when submitting a form.
|
|
2071
1344
|
*
|
|
2072
|
-
*
|
|
2073
|
-
* or resources. When a field is no longer connected to the form, these owned entities should be
|
|
2074
|
-
* destroyed, which is the job of the `FormFieldManager`.
|
|
2075
|
-
*/
|
|
2076
|
-
declare class FormFieldManager {
|
|
2077
|
-
readonly injector: Injector;
|
|
2078
|
-
readonly rootName: string;
|
|
2079
|
-
constructor(injector: Injector, rootName: string | undefined);
|
|
2080
|
-
/**
|
|
2081
|
-
* Contains all child field structures that have been created as part of the current form.
|
|
2082
|
-
* New child structures are automatically added when they are created.
|
|
2083
|
-
* Structures are destroyed and removed when they are no longer reachable from the root.
|
|
2084
|
-
*/
|
|
2085
|
-
readonly structures: Set<FieldNodeStructure>;
|
|
2086
|
-
/**
|
|
2087
|
-
* Creates an effect that runs when the form's structure changes and checks for structures that
|
|
2088
|
-
* have become unreachable to clean up.
|
|
2089
|
-
*
|
|
2090
|
-
* For example, consider a form wrapped around the following model: `signal([0, 1, 2])`.
|
|
2091
|
-
* This form would have 4 nodes as part of its structure tree.
|
|
2092
|
-
* One structure for the root array, and one structure for each element of the array.
|
|
2093
|
-
* Now imagine the data is updated: `model.set([0])`. In this case the structure for the first
|
|
2094
|
-
* element can still be reached from the root, but the structures for the second and third
|
|
2095
|
-
* elements are now orphaned and not connected to the root. Thus they will be destroyed.
|
|
2096
|
-
*
|
|
2097
|
-
* @param root The root field structure.
|
|
2098
|
-
*/
|
|
2099
|
-
createFieldManagementEffect(root: FieldNodeStructure): void;
|
|
2100
|
-
/**
|
|
2101
|
-
* Collects all structures reachable from the given structure into the given set.
|
|
2102
|
-
*
|
|
2103
|
-
* @param structure The root structure
|
|
2104
|
-
* @param liveStructures The set of reachable structures to populate
|
|
2105
|
-
*/
|
|
2106
|
-
private markStructuresLive;
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
/**
|
|
2110
|
-
* Adapter allowing customization of the creation logic for a field and its associated
|
|
2111
|
-
* structure and state.
|
|
1345
|
+
* @experimental 21.2.0
|
|
2112
1346
|
*/
|
|
2113
|
-
interface
|
|
2114
|
-
/**
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
*/
|
|
2119
|
-
createStructure(node: FieldNode, options: FieldNodeOptions): FieldNodeStructure;
|
|
2120
|
-
/**
|
|
2121
|
-
* Creates node validation state
|
|
2122
|
-
* @param param
|
|
2123
|
-
* @param options
|
|
2124
|
-
*/
|
|
2125
|
-
createValidationState(param: FieldNode, options: FieldNodeOptions): ValidationState;
|
|
2126
|
-
/**
|
|
2127
|
-
* Creates node state.
|
|
2128
|
-
* @param param
|
|
2129
|
-
* @param options
|
|
2130
|
-
*/
|
|
2131
|
-
createNodeState(param: FieldNode, options: FieldNodeOptions): FieldNodeState;
|
|
2132
|
-
/**
|
|
2133
|
-
* Creates a custom child node.
|
|
2134
|
-
* @param options
|
|
2135
|
-
*/
|
|
2136
|
-
newChild(options: ChildFieldNodeOptions): FieldNode;
|
|
1347
|
+
interface FormSubmitOptions<TModel> {
|
|
1348
|
+
/** Function to run when submitting the form data (when form is valid). */
|
|
1349
|
+
action: (form: FieldTree<TModel>) => Promise<TreeValidationResult>;
|
|
1350
|
+
/** Function to run when attempting to submit the form data but validation is failing. */
|
|
1351
|
+
onInvalid?: (form: FieldTree<TModel>) => void;
|
|
2137
1352
|
/**
|
|
2138
|
-
*
|
|
2139
|
-
*
|
|
2140
|
-
*
|
|
2141
|
-
*
|
|
2142
|
-
* @param adapter
|
|
1353
|
+
* Whether to ignore any of the validators when submitting:
|
|
1354
|
+
* - 'pending': Will submit if there are no invalid validators, pending validators do not block submission (default)
|
|
1355
|
+
* - 'none': Will not submit unless all validators are passing, pending validators block submission
|
|
1356
|
+
* - 'ignore': Will always submit regardless of invalid or pending validators
|
|
2143
1357
|
*/
|
|
2144
|
-
|
|
1358
|
+
ignoreValidators?: 'pending' | 'none' | 'all';
|
|
2145
1359
|
}
|
|
2146
|
-
|
|
2147
1360
|
/**
|
|
2148
1361
|
* Options that may be specified when creating a form.
|
|
2149
1362
|
*
|
|
2150
1363
|
* @category structure
|
|
2151
1364
|
* @experimental 21.0.0
|
|
2152
1365
|
*/
|
|
2153
|
-
interface FormOptions {
|
|
1366
|
+
interface FormOptions<TModel> {
|
|
2154
1367
|
/**
|
|
2155
1368
|
* The injector to use for dependency injection. If this is not provided, the injector for the
|
|
2156
1369
|
* current [injection context](guide/di/dependency-injection-context), will be used.
|
|
2157
1370
|
*/
|
|
2158
1371
|
injector?: Injector;
|
|
1372
|
+
/** The name of the root form, used in generating name attributes for the fields. */
|
|
2159
1373
|
name?: string;
|
|
2160
|
-
/**
|
|
2161
|
-
|
|
2162
|
-
* Currently this is used to support interop with reactive forms.
|
|
2163
|
-
*/
|
|
2164
|
-
adapter?: FieldAdapter;
|
|
1374
|
+
/** Options that define how to handle form submission. */
|
|
1375
|
+
submission?: FormSubmitOptions<TModel>;
|
|
2165
1376
|
}
|
|
2166
1377
|
/**
|
|
2167
1378
|
* Creates a form wrapped around the given model data. A form is represented as simply a `FieldTree`
|
|
@@ -2235,7 +1446,7 @@ declare function form<TModel>(model: WritableSignal<TModel>): FieldTree<TModel>;
|
|
|
2235
1446
|
* @category structure
|
|
2236
1447
|
* @experimental 21.0.0
|
|
2237
1448
|
*/
|
|
2238
|
-
declare function form<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | FormOptions): FieldTree<TModel>;
|
|
1449
|
+
declare function form<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | FormOptions<TModel>): FieldTree<TModel>;
|
|
2239
1450
|
/**
|
|
2240
1451
|
* Creates a form wrapped around the given model data. A form is represented as simply a `FieldTree`
|
|
2241
1452
|
* of the model data.
|
|
@@ -2279,7 +1490,7 @@ declare function form<TModel>(model: WritableSignal<TModel>, schemaOrOptions: Sc
|
|
|
2279
1490
|
* @category structure
|
|
2280
1491
|
* @experimental 21.0.0
|
|
2281
1492
|
*/
|
|
2282
|
-
declare function form<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: FormOptions): FieldTree<TModel>;
|
|
1493
|
+
declare function form<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: FormOptions<TModel>): FieldTree<TModel>;
|
|
2283
1494
|
/**
|
|
2284
1495
|
* Applies a schema to each item of an array.
|
|
2285
1496
|
*
|
|
@@ -2386,21 +1597,24 @@ declare function applyWhenValue<TValue>(path: SchemaPath<TValue>, predicate: (va
|
|
|
2386
1597
|
* }
|
|
2387
1598
|
*
|
|
2388
1599
|
* const registrationForm = form(signal({username: 'god', password: ''}));
|
|
2389
|
-
* submit(registrationForm,
|
|
2390
|
-
*
|
|
1600
|
+
* submit(registrationForm, {
|
|
1601
|
+
* action: async (f) => {
|
|
1602
|
+
* return registerNewUser(registrationForm);
|
|
1603
|
+
* }
|
|
2391
1604
|
* });
|
|
2392
1605
|
* registrationForm.username().errors(); // [{kind: 'server', message: 'Username already taken'}]
|
|
2393
1606
|
* ```
|
|
2394
1607
|
*
|
|
2395
1608
|
* @param form The field to submit.
|
|
2396
|
-
* @param
|
|
2397
|
-
*
|
|
1609
|
+
* @param options Options for the submission.
|
|
1610
|
+
* @returns Whether the submission was successful.
|
|
2398
1611
|
* @template TModel The data type of the field being submitted.
|
|
2399
1612
|
*
|
|
2400
1613
|
* @category submission
|
|
2401
1614
|
* @experimental 21.0.0
|
|
2402
1615
|
*/
|
|
2403
|
-
declare function submit<TModel>(form: FieldTree<TModel>,
|
|
1616
|
+
declare function submit<TModel>(form: FieldTree<TModel>, options?: FormSubmitOptions<TModel>): Promise<boolean>;
|
|
1617
|
+
declare function submit<TModel>(form: FieldTree<TModel>, action: FormSubmitOptions<TModel>['action']): Promise<boolean>;
|
|
2404
1618
|
/**
|
|
2405
1619
|
* Creates a `Schema` that adds logic rules to a form.
|
|
2406
1620
|
* @param fn A **non-reactive** function that sets up reactive logic rules for the form.
|
|
@@ -2412,5 +1626,5 @@ declare function submit<TModel>(form: FieldTree<TModel>, action: (form: FieldTre
|
|
|
2412
1626
|
*/
|
|
2413
1627
|
declare function schema<TValue>(fn: SchemaFn<TValue>): Schema<TValue>;
|
|
2414
1628
|
|
|
2415
|
-
export { EmailValidationError, FORM_FIELD, FormField, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MetadataReducer, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, SchemaPathRules, StandardSchemaValidationError, ValidationError, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit };
|
|
2416
|
-
export type { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, FieldContext, FieldState, FieldTree, FieldValidator, FormFieldBindingOptions, FormOptions, ItemFieldContext, ItemType, LogicFn, MaybeFieldTree, MaybeSchemaPathTree, MetadataSetterType, OneOrMany, ReadonlyArrayLike, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPath, SchemaPathTree, SignalFormsConfig, Subfields, TreeValidationResult, TreeValidator, ValidationResult, ValidationSuccess, Validator, WithField, WithFieldTree, WithOptionalField, WithOptionalFieldTree, WithoutField, WithoutFieldTree };
|
|
1629
|
+
export { BaseNgValidationError, EmailValidationError, FORM_FIELD, FormField, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MetadataReducer, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, SchemaPathRules, StandardSchemaValidationError, ValidationError, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit, validateStandardSchema, ɵNgFieldDirective };
|
|
1630
|
+
export type { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, FieldContext, FieldState, FieldTree, FieldValidator, FormFieldBindingOptions, FormOptions, FormSubmitOptions, IgnoreUnknownProperties, ItemFieldContext, ItemType, LogicFn, MaybeFieldTree, MaybeSchemaPathTree, MetadataSetterType, OneOrMany, ReadonlyArrayLike, RemoveStringIndexUnknownKey, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPath, SchemaPathTree, SignalFormsConfig, Subfields, TreeValidationResult, TreeValidator, ValidationErrorOptions, ValidationResult, ValidationSuccess, Validator, WithField, WithFieldTree, WithOptionalField, WithOptionalFieldTree, WithoutField, WithoutFieldTree };
|