@angular/forms 21.0.4 → 21.1.0-next.1
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 +385 -453
- 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 +6 -9
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +293 -276
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/types/_structure-chunk.d.ts +708 -788
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +1 -1
- package/types/signals.d.ts +225 -191
package/fesm2022/signals.mjs
CHANGED
|
@@ -1,17 +1,280 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.0.
|
|
2
|
+
* @license Angular v21.1.0-next.1
|
|
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';
|
|
7
8
|
import * as i0 from '@angular/core';
|
|
8
|
-
import { InjectionToken, inject,
|
|
9
|
+
import { computed, InjectionToken, inject, Injector, input, ɵCONTROL as _CONTROL, effect, Directive, ɵɵcontrolCreate as __controlCreate, ɵcontrolUpdate as _controlUpdate, ɵisPromise as _isPromise, resource } from '@angular/core';
|
|
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';
|
|
9
12
|
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
|
+
|
|
15
278
|
const SIGNAL_FORMS_CONFIG = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'SIGNAL_FORMS_CONFIG' : '');
|
|
16
279
|
|
|
17
280
|
function provideSignalFormsConfig(config) {
|
|
@@ -86,21 +349,24 @@ class InteropNgControl {
|
|
|
86
349
|
valueAccessor = null;
|
|
87
350
|
hasValidator(validator) {
|
|
88
351
|
if (validator === Validators.required) {
|
|
89
|
-
return this.field().
|
|
352
|
+
return this.field().metadata(REQUIRED)();
|
|
90
353
|
}
|
|
91
354
|
return false;
|
|
92
355
|
}
|
|
93
356
|
updateValueAndValidity() {}
|
|
94
357
|
}
|
|
95
358
|
|
|
96
|
-
const FIELD = new InjectionToken(typeof ngDevMode !==
|
|
359
|
+
const FIELD = new InjectionToken(typeof ngDevMode !== undefined && ngDevMode ? 'FIELD' : '');
|
|
97
360
|
const controlInstructions = {
|
|
98
361
|
create: __controlCreate,
|
|
99
362
|
update: _controlUpdate
|
|
100
363
|
};
|
|
101
364
|
class Field {
|
|
102
|
-
element = inject(ElementRef).nativeElement;
|
|
103
365
|
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()))]);
|
|
104
370
|
field = input.required(...(ngDevMode ? [{
|
|
105
371
|
debugName: "field"
|
|
106
372
|
}] : []));
|
|
@@ -108,10 +374,6 @@ class Field {
|
|
|
108
374
|
debugName: "state"
|
|
109
375
|
}] : []));
|
|
110
376
|
[_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()))]);
|
|
115
377
|
controlValueAccessors = inject(NG_VALUE_ACCESSOR, {
|
|
116
378
|
optional: true,
|
|
117
379
|
self: true
|
|
@@ -136,7 +398,7 @@ class Field {
|
|
|
136
398
|
}
|
|
137
399
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
138
400
|
minVersion: "12.0.0",
|
|
139
|
-
version: "21.0.
|
|
401
|
+
version: "21.1.0-next.1",
|
|
140
402
|
ngImport: i0,
|
|
141
403
|
type: Field,
|
|
142
404
|
deps: [],
|
|
@@ -144,7 +406,7 @@ class Field {
|
|
|
144
406
|
});
|
|
145
407
|
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
146
408
|
minVersion: "17.1.0",
|
|
147
|
-
version: "21.0.
|
|
409
|
+
version: "21.1.0-next.1",
|
|
148
410
|
type: Field,
|
|
149
411
|
isStandalone: true,
|
|
150
412
|
selector: "[field]",
|
|
@@ -169,7 +431,7 @@ class Field {
|
|
|
169
431
|
}
|
|
170
432
|
i0.ɵɵngDeclareClassMetadata({
|
|
171
433
|
minVersion: "12.0.0",
|
|
172
|
-
version: "21.0.
|
|
434
|
+
version: "21.1.0-next.1",
|
|
173
435
|
ngImport: i0,
|
|
174
436
|
type: Field,
|
|
175
437
|
decorators: [{
|
|
@@ -197,185 +459,6 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
197
459
|
}
|
|
198
460
|
});
|
|
199
461
|
|
|
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
|
-
|
|
379
462
|
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])?)*$/;
|
|
380
463
|
function email(path, config) {
|
|
381
464
|
validate(path, ctx => {
|
|
@@ -396,8 +479,8 @@ function email(path, config) {
|
|
|
396
479
|
}
|
|
397
480
|
|
|
398
481
|
function max(path, maxValue, config) {
|
|
399
|
-
const MAX_MEMO = metadata(path,
|
|
400
|
-
|
|
482
|
+
const MAX_MEMO = metadata(path, ctx => computed(() => typeof maxValue === 'number' ? maxValue : maxValue(ctx)));
|
|
483
|
+
aggregateMetadata(path, MAX, ({
|
|
401
484
|
state
|
|
402
485
|
}) => state.metadata(MAX_MEMO)());
|
|
403
486
|
validate(path, ctx => {
|
|
@@ -424,8 +507,8 @@ function max(path, maxValue, config) {
|
|
|
424
507
|
}
|
|
425
508
|
|
|
426
509
|
function maxLength(path, maxLength, config) {
|
|
427
|
-
const MAX_LENGTH_MEMO = metadata(path,
|
|
428
|
-
|
|
510
|
+
const MAX_LENGTH_MEMO = metadata(path, ctx => computed(() => typeof maxLength === 'number' ? maxLength : maxLength(ctx)));
|
|
511
|
+
aggregateMetadata(path, MAX_LENGTH, ({
|
|
429
512
|
state
|
|
430
513
|
}) => state.metadata(MAX_LENGTH_MEMO)());
|
|
431
514
|
validate(path, ctx => {
|
|
@@ -450,8 +533,8 @@ function maxLength(path, maxLength, config) {
|
|
|
450
533
|
}
|
|
451
534
|
|
|
452
535
|
function min(path, minValue, config) {
|
|
453
|
-
const MIN_MEMO = metadata(path,
|
|
454
|
-
|
|
536
|
+
const MIN_MEMO = metadata(path, ctx => computed(() => typeof minValue === 'number' ? minValue : minValue(ctx)));
|
|
537
|
+
aggregateMetadata(path, MIN, ({
|
|
455
538
|
state
|
|
456
539
|
}) => state.metadata(MIN_MEMO)());
|
|
457
540
|
validate(path, ctx => {
|
|
@@ -478,8 +561,8 @@ function min(path, minValue, config) {
|
|
|
478
561
|
}
|
|
479
562
|
|
|
480
563
|
function minLength(path, minLength, config) {
|
|
481
|
-
const MIN_LENGTH_MEMO = metadata(path,
|
|
482
|
-
|
|
564
|
+
const MIN_LENGTH_MEMO = metadata(path, ctx => computed(() => typeof minLength === 'number' ? minLength : minLength(ctx)));
|
|
565
|
+
aggregateMetadata(path, MIN_LENGTH, ({
|
|
483
566
|
state
|
|
484
567
|
}) => state.metadata(MIN_LENGTH_MEMO)());
|
|
485
568
|
validate(path, ctx => {
|
|
@@ -504,8 +587,8 @@ function minLength(path, minLength, config) {
|
|
|
504
587
|
}
|
|
505
588
|
|
|
506
589
|
function pattern(path, pattern, config) {
|
|
507
|
-
const PATTERN_MEMO = metadata(path,
|
|
508
|
-
|
|
590
|
+
const PATTERN_MEMO = metadata(path, ctx => computed(() => pattern instanceof RegExp ? pattern : pattern(ctx)));
|
|
591
|
+
aggregateMetadata(path, PATTERN, ({
|
|
509
592
|
state
|
|
510
593
|
}) => state.metadata(PATTERN_MEMO)());
|
|
511
594
|
validate(path, ctx => {
|
|
@@ -530,8 +613,8 @@ function pattern(path, pattern, config) {
|
|
|
530
613
|
}
|
|
531
614
|
|
|
532
615
|
function required(path, config) {
|
|
533
|
-
const REQUIRED_MEMO = metadata(path,
|
|
534
|
-
|
|
616
|
+
const REQUIRED_MEMO = metadata(path, ctx => computed(() => config?.when ? config.when(ctx) : true));
|
|
617
|
+
aggregateMetadata(path, REQUIRED, ({
|
|
535
618
|
state
|
|
536
619
|
}) => state.metadata(REQUIRED_MEMO)());
|
|
537
620
|
validate(path, ctx => {
|
|
@@ -548,52 +631,11 @@ function required(path, config) {
|
|
|
548
631
|
});
|
|
549
632
|
}
|
|
550
633
|
|
|
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
|
-
|
|
592
634
|
function validateStandardSchema(path, schema) {
|
|
593
|
-
const VALIDATOR_MEMO = metadata(path,
|
|
635
|
+
const VALIDATOR_MEMO = metadata(path, ({
|
|
594
636
|
value
|
|
595
637
|
}) => {
|
|
596
|
-
return schema['~standard'].validate(value());
|
|
638
|
+
return computed(() => schema['~standard'].validate(value()));
|
|
597
639
|
});
|
|
598
640
|
validateTree(path, ({
|
|
599
641
|
state,
|
|
@@ -603,7 +645,7 @@ function validateStandardSchema(path, schema) {
|
|
|
603
645
|
if (_isPromise(result)) {
|
|
604
646
|
return [];
|
|
605
647
|
}
|
|
606
|
-
return result
|
|
648
|
+
return result.issues?.map(issue => standardIssueToFormTreeError(fieldTreeOf(path), issue)) ?? [];
|
|
607
649
|
});
|
|
608
650
|
validateAsync(path, {
|
|
609
651
|
params: ({
|
|
@@ -639,30 +681,5 @@ function standardIssueToFormTreeError(field, issue) {
|
|
|
639
681
|
}), target);
|
|
640
682
|
}
|
|
641
683
|
|
|
642
|
-
|
|
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 };
|
|
684
|
+
export { CustomValidationError, EmailValidationError, FIELD, Field, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, RequiredValidationError, StandardSchemaValidationError, aggregateMetadata, 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 };
|
|
668
685
|
//# sourceMappingURL=signals.mjs.map
|