@angular/forms 21.1.0-next.1 → 21.1.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 +453 -385
- package/fesm2022/_structure-chunk.mjs.map +1 -1
- package/fesm2022/forms.mjs +133 -133
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +9 -6
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +276 -293
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/types/_structure-chunk.d.ts +788 -708
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +1 -1
- package/types/signals.d.ts +191 -225
package/fesm2022/signals.mjs
CHANGED
|
@@ -1,280 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.1.0-next.
|
|
2
|
+
* @license Angular v21.1.0-next.2
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { httpResource } from '@angular/common/http';
|
|
8
7
|
import * as i0 from '@angular/core';
|
|
9
|
-
import {
|
|
10
|
-
import { isArray, assertPathIsCurrent, addDefaultField, FieldPathNode, createMetadataKey, DEBOUNCER, REQUIRED, MAX, MAX_LENGTH, MIN, MIN_LENGTH, PATTERN } from './_structure-chunk.mjs';
|
|
11
|
-
export { AggregateMetadataKey, MetadataKey, andMetadataKey, apply, applyEach, applyWhen, applyWhenValue, form, listMetadataKey, maxMetadataKey, minMetadataKey, orMetadataKey, reducedMetadataKey, schema, submit } from './_structure-chunk.mjs';
|
|
8
|
+
import { InjectionToken, inject, ElementRef, Injector, input, computed, ɵCONTROL as _CONTROL, effect, Directive, ɵɵcontrolCreate as __controlCreate, ɵcontrolUpdate as _controlUpdate, ɵisPromise as _isPromise, resource } from '@angular/core';
|
|
12
9
|
import { Validators, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
|
|
10
|
+
import { assertPathIsCurrent, FieldPathNode, isArray, addDefaultField, metadata, createMetadataKey, MAX, MAX_LENGTH, MIN, MIN_LENGTH, PATTERN, REQUIRED, createManagedMetadataKey, DEBOUNCER } from './_structure-chunk.mjs';
|
|
11
|
+
export { MetadataKey, MetadataReducer, apply, applyEach, applyWhen, applyWhenValue, form, schema, submit } from './_structure-chunk.mjs';
|
|
12
|
+
import { httpResource } from '@angular/common/http';
|
|
13
13
|
import '@angular/core/primitives/signals';
|
|
14
14
|
|
|
15
|
-
function requiredError(options) {
|
|
16
|
-
return new RequiredValidationError(options);
|
|
17
|
-
}
|
|
18
|
-
function minError(min, options) {
|
|
19
|
-
return new MinValidationError(min, options);
|
|
20
|
-
}
|
|
21
|
-
function maxError(max, options) {
|
|
22
|
-
return new MaxValidationError(max, options);
|
|
23
|
-
}
|
|
24
|
-
function minLengthError(minLength, options) {
|
|
25
|
-
return new MinLengthValidationError(minLength, options);
|
|
26
|
-
}
|
|
27
|
-
function maxLengthError(maxLength, options) {
|
|
28
|
-
return new MaxLengthValidationError(maxLength, options);
|
|
29
|
-
}
|
|
30
|
-
function patternError(pattern, options) {
|
|
31
|
-
return new PatternValidationError(pattern, options);
|
|
32
|
-
}
|
|
33
|
-
function emailError(options) {
|
|
34
|
-
return new EmailValidationError(options);
|
|
35
|
-
}
|
|
36
|
-
function standardSchemaError(issue, options) {
|
|
37
|
-
return new StandardSchemaValidationError(issue, options);
|
|
38
|
-
}
|
|
39
|
-
function customError(obj) {
|
|
40
|
-
return new CustomValidationError(obj);
|
|
41
|
-
}
|
|
42
|
-
class CustomValidationError {
|
|
43
|
-
__brand = undefined;
|
|
44
|
-
kind = '';
|
|
45
|
-
field;
|
|
46
|
-
message;
|
|
47
|
-
constructor(options) {
|
|
48
|
-
if (options) {
|
|
49
|
-
Object.assign(this, options);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
class _NgValidationError {
|
|
54
|
-
__brand = undefined;
|
|
55
|
-
kind = '';
|
|
56
|
-
field;
|
|
57
|
-
message;
|
|
58
|
-
constructor(options) {
|
|
59
|
-
if (options) {
|
|
60
|
-
Object.assign(this, options);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
class RequiredValidationError extends _NgValidationError {
|
|
65
|
-
kind = 'required';
|
|
66
|
-
}
|
|
67
|
-
class MinValidationError extends _NgValidationError {
|
|
68
|
-
min;
|
|
69
|
-
kind = 'min';
|
|
70
|
-
constructor(min, options) {
|
|
71
|
-
super(options);
|
|
72
|
-
this.min = min;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
class MaxValidationError extends _NgValidationError {
|
|
76
|
-
max;
|
|
77
|
-
kind = 'max';
|
|
78
|
-
constructor(max, options) {
|
|
79
|
-
super(options);
|
|
80
|
-
this.max = max;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
class MinLengthValidationError extends _NgValidationError {
|
|
84
|
-
minLength;
|
|
85
|
-
kind = 'minLength';
|
|
86
|
-
constructor(minLength, options) {
|
|
87
|
-
super(options);
|
|
88
|
-
this.minLength = minLength;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
class MaxLengthValidationError extends _NgValidationError {
|
|
92
|
-
maxLength;
|
|
93
|
-
kind = 'maxLength';
|
|
94
|
-
constructor(maxLength, options) {
|
|
95
|
-
super(options);
|
|
96
|
-
this.maxLength = maxLength;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
class PatternValidationError extends _NgValidationError {
|
|
100
|
-
pattern;
|
|
101
|
-
kind = 'pattern';
|
|
102
|
-
constructor(pattern, options) {
|
|
103
|
-
super(options);
|
|
104
|
-
this.pattern = pattern;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
class EmailValidationError extends _NgValidationError {
|
|
108
|
-
kind = 'email';
|
|
109
|
-
}
|
|
110
|
-
class StandardSchemaValidationError extends _NgValidationError {
|
|
111
|
-
issue;
|
|
112
|
-
kind = 'standardSchema';
|
|
113
|
-
constructor(issue, options) {
|
|
114
|
-
super(options);
|
|
115
|
-
this.issue = issue;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const NgValidationError = _NgValidationError;
|
|
119
|
-
|
|
120
|
-
function getLengthOrSize(value) {
|
|
121
|
-
const v = value;
|
|
122
|
-
return typeof v.length === 'number' ? v.length : v.size;
|
|
123
|
-
}
|
|
124
|
-
function getOption(opt, ctx) {
|
|
125
|
-
return opt instanceof Function ? opt(ctx) : opt;
|
|
126
|
-
}
|
|
127
|
-
function isEmpty(value) {
|
|
128
|
-
if (typeof value === 'number') {
|
|
129
|
-
return isNaN(value);
|
|
130
|
-
}
|
|
131
|
-
return value === '' || value === false || value == null;
|
|
132
|
-
}
|
|
133
|
-
function isPlainError(error) {
|
|
134
|
-
return typeof error === 'object' && (Object.getPrototypeOf(error) === Object.prototype || Object.getPrototypeOf(error) === null);
|
|
135
|
-
}
|
|
136
|
-
function ensureCustomValidationError(error) {
|
|
137
|
-
if (isPlainError(error)) {
|
|
138
|
-
return customError(error);
|
|
139
|
-
}
|
|
140
|
-
return error;
|
|
141
|
-
}
|
|
142
|
-
function ensureCustomValidationResult(result) {
|
|
143
|
-
if (result === null || result === undefined) {
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
146
|
-
if (isArray(result)) {
|
|
147
|
-
return result.map(ensureCustomValidationError);
|
|
148
|
-
}
|
|
149
|
-
return ensureCustomValidationError(result);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function disabled(path, logic) {
|
|
153
|
-
assertPathIsCurrent(path);
|
|
154
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
155
|
-
pathNode.builder.addDisabledReasonRule(ctx => {
|
|
156
|
-
let result = true;
|
|
157
|
-
if (typeof logic === 'string') {
|
|
158
|
-
result = logic;
|
|
159
|
-
} else if (logic) {
|
|
160
|
-
result = logic(ctx);
|
|
161
|
-
}
|
|
162
|
-
if (typeof result === 'string') {
|
|
163
|
-
return {
|
|
164
|
-
field: ctx.field,
|
|
165
|
-
message: result
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
return result ? {
|
|
169
|
-
field: ctx.field
|
|
170
|
-
} : undefined;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
function readonly(path, logic = () => true) {
|
|
174
|
-
assertPathIsCurrent(path);
|
|
175
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
176
|
-
pathNode.builder.addReadonlyRule(logic);
|
|
177
|
-
}
|
|
178
|
-
function hidden(path, logic) {
|
|
179
|
-
assertPathIsCurrent(path);
|
|
180
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
181
|
-
pathNode.builder.addHiddenRule(logic);
|
|
182
|
-
}
|
|
183
|
-
function validate(path, logic) {
|
|
184
|
-
assertPathIsCurrent(path);
|
|
185
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
186
|
-
pathNode.builder.addSyncErrorRule(ctx => {
|
|
187
|
-
return ensureCustomValidationResult(addDefaultField(logic(ctx), ctx.field));
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
function validateTree(path, logic) {
|
|
191
|
-
assertPathIsCurrent(path);
|
|
192
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
193
|
-
pathNode.builder.addSyncTreeErrorRule(ctx => addDefaultField(logic(ctx), ctx.field));
|
|
194
|
-
}
|
|
195
|
-
function aggregateMetadata(path, key, logic) {
|
|
196
|
-
assertPathIsCurrent(path);
|
|
197
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
198
|
-
pathNode.builder.addAggregateMetadataRule(key, logic);
|
|
199
|
-
}
|
|
200
|
-
function metadata(path, ...rest) {
|
|
201
|
-
assertPathIsCurrent(path);
|
|
202
|
-
let key;
|
|
203
|
-
let factory;
|
|
204
|
-
if (rest.length === 2) {
|
|
205
|
-
[key, factory] = rest;
|
|
206
|
-
} else {
|
|
207
|
-
[factory] = rest;
|
|
208
|
-
}
|
|
209
|
-
key ??= createMetadataKey();
|
|
210
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
211
|
-
pathNode.builder.addMetadataFactory(key, factory);
|
|
212
|
-
return key;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function validateAsync(path, opts) {
|
|
216
|
-
assertPathIsCurrent(path);
|
|
217
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
218
|
-
const RESOURCE = metadata(path, ctx => {
|
|
219
|
-
const params = computed(() => {
|
|
220
|
-
const node = ctx.stateOf(path);
|
|
221
|
-
const validationState = node.validationState;
|
|
222
|
-
if (validationState.shouldSkipValidation() || !validationState.syncValid()) {
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
return opts.params(ctx);
|
|
226
|
-
}, ...(ngDevMode ? [{
|
|
227
|
-
debugName: "params"
|
|
228
|
-
}] : []));
|
|
229
|
-
return opts.factory(params);
|
|
230
|
-
});
|
|
231
|
-
pathNode.builder.addAsyncErrorRule(ctx => {
|
|
232
|
-
const res = ctx.state.metadata(RESOURCE);
|
|
233
|
-
let errors;
|
|
234
|
-
switch (res.status()) {
|
|
235
|
-
case 'idle':
|
|
236
|
-
return undefined;
|
|
237
|
-
case 'loading':
|
|
238
|
-
case 'reloading':
|
|
239
|
-
return 'pending';
|
|
240
|
-
case 'resolved':
|
|
241
|
-
case 'local':
|
|
242
|
-
if (!res.hasValue()) {
|
|
243
|
-
return undefined;
|
|
244
|
-
}
|
|
245
|
-
errors = opts.onSuccess(res.value(), ctx);
|
|
246
|
-
return addDefaultField(errors, ctx.field);
|
|
247
|
-
case 'error':
|
|
248
|
-
errors = opts.onError(res.error(), ctx);
|
|
249
|
-
return addDefaultField(errors, ctx.field);
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
function validateHttp(path, opts) {
|
|
254
|
-
validateAsync(path, {
|
|
255
|
-
params: opts.request,
|
|
256
|
-
factory: request => httpResource(request, opts.options),
|
|
257
|
-
onSuccess: opts.onSuccess,
|
|
258
|
-
onError: opts.onError
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function debounce(path, durationOrDebouncer) {
|
|
263
|
-
assertPathIsCurrent(path);
|
|
264
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
265
|
-
const debouncer = typeof durationOrDebouncer === 'function' ? durationOrDebouncer : durationOrDebouncer > 0 ? debounceForDuration(durationOrDebouncer) : immediate;
|
|
266
|
-
pathNode.builder.addAggregateMetadataRule(DEBOUNCER, () => debouncer);
|
|
267
|
-
}
|
|
268
|
-
function debounceForDuration(durationInMilliseconds) {
|
|
269
|
-
return (_context, abortSignal) => {
|
|
270
|
-
return new Promise(resolve => {
|
|
271
|
-
const timeoutId = setTimeout(resolve, durationInMilliseconds);
|
|
272
|
-
abortSignal.addEventListener('abort', () => clearTimeout(timeoutId));
|
|
273
|
-
});
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function immediate() {}
|
|
277
|
-
|
|
278
15
|
const SIGNAL_FORMS_CONFIG = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'SIGNAL_FORMS_CONFIG' : '');
|
|
279
16
|
|
|
280
17
|
function provideSignalFormsConfig(config) {
|
|
@@ -349,24 +86,21 @@ class InteropNgControl {
|
|
|
349
86
|
valueAccessor = null;
|
|
350
87
|
hasValidator(validator) {
|
|
351
88
|
if (validator === Validators.required) {
|
|
352
|
-
return this.field().
|
|
89
|
+
return this.field().required();
|
|
353
90
|
}
|
|
354
91
|
return false;
|
|
355
92
|
}
|
|
356
93
|
updateValueAndValidity() {}
|
|
357
94
|
}
|
|
358
95
|
|
|
359
|
-
const FIELD = new InjectionToken(typeof ngDevMode !== undefined && ngDevMode ? 'FIELD' : '');
|
|
96
|
+
const FIELD = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FIELD' : '');
|
|
360
97
|
const controlInstructions = {
|
|
361
98
|
create: __controlCreate,
|
|
362
99
|
update: _controlUpdate
|
|
363
100
|
};
|
|
364
101
|
class Field {
|
|
102
|
+
element = inject(ElementRef).nativeElement;
|
|
365
103
|
injector = inject(Injector);
|
|
366
|
-
config = inject(SIGNAL_FORMS_CONFIG, {
|
|
367
|
-
optional: true
|
|
368
|
-
});
|
|
369
|
-
classes = Object.entries(this.config?.classes ?? {}).map(([className, computation]) => [className, computed(() => computation(this.state()))]);
|
|
370
104
|
field = input.required(...(ngDevMode ? [{
|
|
371
105
|
debugName: "field"
|
|
372
106
|
}] : []));
|
|
@@ -374,6 +108,10 @@ class Field {
|
|
|
374
108
|
debugName: "state"
|
|
375
109
|
}] : []));
|
|
376
110
|
[_CONTROL] = controlInstructions;
|
|
111
|
+
config = inject(SIGNAL_FORMS_CONFIG, {
|
|
112
|
+
optional: true
|
|
113
|
+
});
|
|
114
|
+
classes = Object.entries(this.config?.classes ?? {}).map(([className, computation]) => [className, computed(() => computation(this.state()))]);
|
|
377
115
|
controlValueAccessors = inject(NG_VALUE_ACCESSOR, {
|
|
378
116
|
optional: true,
|
|
379
117
|
self: true
|
|
@@ -398,7 +136,7 @@ class Field {
|
|
|
398
136
|
}
|
|
399
137
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
400
138
|
minVersion: "12.0.0",
|
|
401
|
-
version: "21.1.0-next.
|
|
139
|
+
version: "21.1.0-next.2",
|
|
402
140
|
ngImport: i0,
|
|
403
141
|
type: Field,
|
|
404
142
|
deps: [],
|
|
@@ -406,7 +144,7 @@ class Field {
|
|
|
406
144
|
});
|
|
407
145
|
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
408
146
|
minVersion: "17.1.0",
|
|
409
|
-
version: "21.1.0-next.
|
|
147
|
+
version: "21.1.0-next.2",
|
|
410
148
|
type: Field,
|
|
411
149
|
isStandalone: true,
|
|
412
150
|
selector: "[field]",
|
|
@@ -431,7 +169,7 @@ class Field {
|
|
|
431
169
|
}
|
|
432
170
|
i0.ɵɵngDeclareClassMetadata({
|
|
433
171
|
minVersion: "12.0.0",
|
|
434
|
-
version: "21.1.0-next.
|
|
172
|
+
version: "21.1.0-next.2",
|
|
435
173
|
ngImport: i0,
|
|
436
174
|
type: Field,
|
|
437
175
|
decorators: [{
|
|
@@ -459,6 +197,185 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
459
197
|
}
|
|
460
198
|
});
|
|
461
199
|
|
|
200
|
+
function disabled(path, logic) {
|
|
201
|
+
assertPathIsCurrent(path);
|
|
202
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
203
|
+
pathNode.builder.addDisabledReasonRule(ctx => {
|
|
204
|
+
let result = true;
|
|
205
|
+
if (typeof logic === 'string') {
|
|
206
|
+
result = logic;
|
|
207
|
+
} else if (logic) {
|
|
208
|
+
result = logic(ctx);
|
|
209
|
+
}
|
|
210
|
+
if (typeof result === 'string') {
|
|
211
|
+
return {
|
|
212
|
+
field: ctx.field,
|
|
213
|
+
message: result
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return result ? {
|
|
217
|
+
field: ctx.field
|
|
218
|
+
} : undefined;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function hidden(path, logic) {
|
|
223
|
+
assertPathIsCurrent(path);
|
|
224
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
225
|
+
pathNode.builder.addHiddenRule(logic);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function readonly(path, logic = () => true) {
|
|
229
|
+
assertPathIsCurrent(path);
|
|
230
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
231
|
+
pathNode.builder.addReadonlyRule(logic);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function requiredError(options) {
|
|
235
|
+
return new RequiredValidationError(options);
|
|
236
|
+
}
|
|
237
|
+
function minError(min, options) {
|
|
238
|
+
return new MinValidationError(min, options);
|
|
239
|
+
}
|
|
240
|
+
function maxError(max, options) {
|
|
241
|
+
return new MaxValidationError(max, options);
|
|
242
|
+
}
|
|
243
|
+
function minLengthError(minLength, options) {
|
|
244
|
+
return new MinLengthValidationError(minLength, options);
|
|
245
|
+
}
|
|
246
|
+
function maxLengthError(maxLength, options) {
|
|
247
|
+
return new MaxLengthValidationError(maxLength, options);
|
|
248
|
+
}
|
|
249
|
+
function patternError(pattern, options) {
|
|
250
|
+
return new PatternValidationError(pattern, options);
|
|
251
|
+
}
|
|
252
|
+
function emailError(options) {
|
|
253
|
+
return new EmailValidationError(options);
|
|
254
|
+
}
|
|
255
|
+
function standardSchemaError(issue, options) {
|
|
256
|
+
return new StandardSchemaValidationError(issue, options);
|
|
257
|
+
}
|
|
258
|
+
function customError(obj) {
|
|
259
|
+
return new CustomValidationError(obj);
|
|
260
|
+
}
|
|
261
|
+
class CustomValidationError {
|
|
262
|
+
__brand = undefined;
|
|
263
|
+
kind = '';
|
|
264
|
+
field;
|
|
265
|
+
message;
|
|
266
|
+
constructor(options) {
|
|
267
|
+
if (options) {
|
|
268
|
+
Object.assign(this, options);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
class _NgValidationError {
|
|
273
|
+
__brand = undefined;
|
|
274
|
+
kind = '';
|
|
275
|
+
field;
|
|
276
|
+
message;
|
|
277
|
+
constructor(options) {
|
|
278
|
+
if (options) {
|
|
279
|
+
Object.assign(this, options);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
class RequiredValidationError extends _NgValidationError {
|
|
284
|
+
kind = 'required';
|
|
285
|
+
}
|
|
286
|
+
class MinValidationError extends _NgValidationError {
|
|
287
|
+
min;
|
|
288
|
+
kind = 'min';
|
|
289
|
+
constructor(min, options) {
|
|
290
|
+
super(options);
|
|
291
|
+
this.min = min;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
class MaxValidationError extends _NgValidationError {
|
|
295
|
+
max;
|
|
296
|
+
kind = 'max';
|
|
297
|
+
constructor(max, options) {
|
|
298
|
+
super(options);
|
|
299
|
+
this.max = max;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
class MinLengthValidationError extends _NgValidationError {
|
|
303
|
+
minLength;
|
|
304
|
+
kind = 'minLength';
|
|
305
|
+
constructor(minLength, options) {
|
|
306
|
+
super(options);
|
|
307
|
+
this.minLength = minLength;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
class MaxLengthValidationError extends _NgValidationError {
|
|
311
|
+
maxLength;
|
|
312
|
+
kind = 'maxLength';
|
|
313
|
+
constructor(maxLength, options) {
|
|
314
|
+
super(options);
|
|
315
|
+
this.maxLength = maxLength;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
class PatternValidationError extends _NgValidationError {
|
|
319
|
+
pattern;
|
|
320
|
+
kind = 'pattern';
|
|
321
|
+
constructor(pattern, options) {
|
|
322
|
+
super(options);
|
|
323
|
+
this.pattern = pattern;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
class EmailValidationError extends _NgValidationError {
|
|
327
|
+
kind = 'email';
|
|
328
|
+
}
|
|
329
|
+
class StandardSchemaValidationError extends _NgValidationError {
|
|
330
|
+
issue;
|
|
331
|
+
kind = 'standardSchema';
|
|
332
|
+
constructor(issue, options) {
|
|
333
|
+
super(options);
|
|
334
|
+
this.issue = issue;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const NgValidationError = _NgValidationError;
|
|
338
|
+
|
|
339
|
+
function getLengthOrSize(value) {
|
|
340
|
+
const v = value;
|
|
341
|
+
return typeof v.length === 'number' ? v.length : v.size;
|
|
342
|
+
}
|
|
343
|
+
function getOption(opt, ctx) {
|
|
344
|
+
return opt instanceof Function ? opt(ctx) : opt;
|
|
345
|
+
}
|
|
346
|
+
function isEmpty(value) {
|
|
347
|
+
if (typeof value === 'number') {
|
|
348
|
+
return isNaN(value);
|
|
349
|
+
}
|
|
350
|
+
return value === '' || value === false || value == null;
|
|
351
|
+
}
|
|
352
|
+
function isPlainError(error) {
|
|
353
|
+
return typeof error === 'object' && (Object.getPrototypeOf(error) === Object.prototype || Object.getPrototypeOf(error) === null);
|
|
354
|
+
}
|
|
355
|
+
function ensureCustomValidationError(error) {
|
|
356
|
+
if (isPlainError(error)) {
|
|
357
|
+
return customError(error);
|
|
358
|
+
}
|
|
359
|
+
return error;
|
|
360
|
+
}
|
|
361
|
+
function ensureCustomValidationResult(result) {
|
|
362
|
+
if (result === null || result === undefined) {
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
if (isArray(result)) {
|
|
366
|
+
return result.map(ensureCustomValidationError);
|
|
367
|
+
}
|
|
368
|
+
return ensureCustomValidationError(result);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function validate(path, logic) {
|
|
372
|
+
assertPathIsCurrent(path);
|
|
373
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
374
|
+
pathNode.builder.addSyncErrorRule(ctx => {
|
|
375
|
+
return ensureCustomValidationResult(addDefaultField(logic(ctx), ctx.field));
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
462
379
|
const EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
463
380
|
function email(path, config) {
|
|
464
381
|
validate(path, ctx => {
|
|
@@ -479,8 +396,8 @@ function email(path, config) {
|
|
|
479
396
|
}
|
|
480
397
|
|
|
481
398
|
function max(path, maxValue, config) {
|
|
482
|
-
const MAX_MEMO = metadata(path,
|
|
483
|
-
|
|
399
|
+
const MAX_MEMO = metadata(path, createMetadataKey(), ctx => typeof maxValue === 'number' ? maxValue : maxValue(ctx));
|
|
400
|
+
metadata(path, MAX, ({
|
|
484
401
|
state
|
|
485
402
|
}) => state.metadata(MAX_MEMO)());
|
|
486
403
|
validate(path, ctx => {
|
|
@@ -507,8 +424,8 @@ function max(path, maxValue, config) {
|
|
|
507
424
|
}
|
|
508
425
|
|
|
509
426
|
function maxLength(path, maxLength, config) {
|
|
510
|
-
const MAX_LENGTH_MEMO = metadata(path,
|
|
511
|
-
|
|
427
|
+
const MAX_LENGTH_MEMO = metadata(path, createMetadataKey(), ctx => typeof maxLength === 'number' ? maxLength : maxLength(ctx));
|
|
428
|
+
metadata(path, MAX_LENGTH, ({
|
|
512
429
|
state
|
|
513
430
|
}) => state.metadata(MAX_LENGTH_MEMO)());
|
|
514
431
|
validate(path, ctx => {
|
|
@@ -533,8 +450,8 @@ function maxLength(path, maxLength, config) {
|
|
|
533
450
|
}
|
|
534
451
|
|
|
535
452
|
function min(path, minValue, config) {
|
|
536
|
-
const MIN_MEMO = metadata(path,
|
|
537
|
-
|
|
453
|
+
const MIN_MEMO = metadata(path, createMetadataKey(), ctx => typeof minValue === 'number' ? minValue : minValue(ctx));
|
|
454
|
+
metadata(path, MIN, ({
|
|
538
455
|
state
|
|
539
456
|
}) => state.metadata(MIN_MEMO)());
|
|
540
457
|
validate(path, ctx => {
|
|
@@ -561,8 +478,8 @@ function min(path, minValue, config) {
|
|
|
561
478
|
}
|
|
562
479
|
|
|
563
480
|
function minLength(path, minLength, config) {
|
|
564
|
-
const MIN_LENGTH_MEMO = metadata(path,
|
|
565
|
-
|
|
481
|
+
const MIN_LENGTH_MEMO = metadata(path, createMetadataKey(), ctx => typeof minLength === 'number' ? minLength : minLength(ctx));
|
|
482
|
+
metadata(path, MIN_LENGTH, ({
|
|
566
483
|
state
|
|
567
484
|
}) => state.metadata(MIN_LENGTH_MEMO)());
|
|
568
485
|
validate(path, ctx => {
|
|
@@ -587,8 +504,8 @@ function minLength(path, minLength, config) {
|
|
|
587
504
|
}
|
|
588
505
|
|
|
589
506
|
function pattern(path, pattern, config) {
|
|
590
|
-
const PATTERN_MEMO = metadata(path,
|
|
591
|
-
|
|
507
|
+
const PATTERN_MEMO = metadata(path, createMetadataKey(), ctx => pattern instanceof RegExp ? pattern : pattern(ctx));
|
|
508
|
+
metadata(path, PATTERN, ({
|
|
592
509
|
state
|
|
593
510
|
}) => state.metadata(PATTERN_MEMO)());
|
|
594
511
|
validate(path, ctx => {
|
|
@@ -613,8 +530,8 @@ function pattern(path, pattern, config) {
|
|
|
613
530
|
}
|
|
614
531
|
|
|
615
532
|
function required(path, config) {
|
|
616
|
-
const REQUIRED_MEMO = metadata(path,
|
|
617
|
-
|
|
533
|
+
const REQUIRED_MEMO = metadata(path, createMetadataKey(), ctx => config?.when ? config.when(ctx) : true);
|
|
534
|
+
metadata(path, REQUIRED, ({
|
|
618
535
|
state
|
|
619
536
|
}) => state.metadata(REQUIRED_MEMO)());
|
|
620
537
|
validate(path, ctx => {
|
|
@@ -631,11 +548,52 @@ function required(path, config) {
|
|
|
631
548
|
});
|
|
632
549
|
}
|
|
633
550
|
|
|
551
|
+
function validateAsync(path, opts) {
|
|
552
|
+
assertPathIsCurrent(path);
|
|
553
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
554
|
+
const RESOURCE = createManagedMetadataKey(opts.factory);
|
|
555
|
+
metadata(path, RESOURCE, ctx => {
|
|
556
|
+
const node = ctx.stateOf(path);
|
|
557
|
+
const validationState = node.validationState;
|
|
558
|
+
if (validationState.shouldSkipValidation() || !validationState.syncValid()) {
|
|
559
|
+
return undefined;
|
|
560
|
+
}
|
|
561
|
+
return opts.params(ctx);
|
|
562
|
+
});
|
|
563
|
+
pathNode.builder.addAsyncErrorRule(ctx => {
|
|
564
|
+
const res = ctx.state.metadata(RESOURCE);
|
|
565
|
+
let errors;
|
|
566
|
+
switch (res.status()) {
|
|
567
|
+
case 'idle':
|
|
568
|
+
return undefined;
|
|
569
|
+
case 'loading':
|
|
570
|
+
case 'reloading':
|
|
571
|
+
return 'pending';
|
|
572
|
+
case 'resolved':
|
|
573
|
+
case 'local':
|
|
574
|
+
if (!res.hasValue()) {
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
errors = opts.onSuccess(res.value(), ctx);
|
|
578
|
+
return addDefaultField(errors, ctx.field);
|
|
579
|
+
case 'error':
|
|
580
|
+
errors = opts.onError(res.error(), ctx);
|
|
581
|
+
return addDefaultField(errors, ctx.field);
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function validateTree(path, logic) {
|
|
587
|
+
assertPathIsCurrent(path);
|
|
588
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
589
|
+
pathNode.builder.addSyncTreeErrorRule(ctx => addDefaultField(logic(ctx), ctx.field));
|
|
590
|
+
}
|
|
591
|
+
|
|
634
592
|
function validateStandardSchema(path, schema) {
|
|
635
|
-
const VALIDATOR_MEMO = metadata(path, ({
|
|
593
|
+
const VALIDATOR_MEMO = metadata(path, createMetadataKey(), ({
|
|
636
594
|
value
|
|
637
595
|
}) => {
|
|
638
|
-
return
|
|
596
|
+
return schema['~standard'].validate(value());
|
|
639
597
|
});
|
|
640
598
|
validateTree(path, ({
|
|
641
599
|
state,
|
|
@@ -645,7 +603,7 @@ function validateStandardSchema(path, schema) {
|
|
|
645
603
|
if (_isPromise(result)) {
|
|
646
604
|
return [];
|
|
647
605
|
}
|
|
648
|
-
return result
|
|
606
|
+
return result?.issues?.map(issue => standardIssueToFormTreeError(fieldTreeOf(path), issue)) ?? [];
|
|
649
607
|
});
|
|
650
608
|
validateAsync(path, {
|
|
651
609
|
params: ({
|
|
@@ -681,5 +639,30 @@ function standardIssueToFormTreeError(field, issue) {
|
|
|
681
639
|
}), target);
|
|
682
640
|
}
|
|
683
641
|
|
|
684
|
-
|
|
642
|
+
function validateHttp(path, opts) {
|
|
643
|
+
validateAsync(path, {
|
|
644
|
+
params: opts.request,
|
|
645
|
+
factory: request => httpResource(request, opts.options),
|
|
646
|
+
onSuccess: opts.onSuccess,
|
|
647
|
+
onError: opts.onError
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function debounce(path, durationOrDebouncer) {
|
|
652
|
+
assertPathIsCurrent(path);
|
|
653
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
654
|
+
const debouncer = typeof durationOrDebouncer === 'function' ? durationOrDebouncer : durationOrDebouncer > 0 ? debounceForDuration(durationOrDebouncer) : immediate;
|
|
655
|
+
pathNode.builder.addMetadataRule(DEBOUNCER, () => debouncer);
|
|
656
|
+
}
|
|
657
|
+
function debounceForDuration(durationInMilliseconds) {
|
|
658
|
+
return (_context, abortSignal) => {
|
|
659
|
+
return new Promise(resolve => {
|
|
660
|
+
const timeoutId = setTimeout(resolve, durationInMilliseconds);
|
|
661
|
+
abortSignal.addEventListener('abort', () => clearTimeout(timeoutId));
|
|
662
|
+
});
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
function immediate() {}
|
|
666
|
+
|
|
667
|
+
export { CustomValidationError, EmailValidationError, FIELD, Field, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, RequiredValidationError, StandardSchemaValidationError, createManagedMetadataKey, createMetadataKey, customError, debounce, disabled, email, emailError, hidden, max, maxError, maxLength, maxLengthError, metadata, min, minError, minLength, minLengthError, pattern, patternError, provideSignalFormsConfig, readonly, required, requiredError, standardSchemaError, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
|
|
685
668
|
//# sourceMappingURL=signals.mjs.map
|