@angular/forms 21.1.0-next.0 → 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 +519 -527
- package/fesm2022/_structure-chunk.mjs.map +1 -1
- package/fesm2022/forms.mjs +163 -183
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +29 -40
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +283 -302
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/types/_structure-chunk.d.ts +802 -719
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +5 -4
- package/types/signals.d.ts +207 -241
package/fesm2022/signals.mjs
CHANGED
|
@@ -1,282 +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
|
-
}, {
|
|
227
|
-
...(ngDevMode ? {
|
|
228
|
-
debugName: "params"
|
|
229
|
-
} : {})
|
|
230
|
-
});
|
|
231
|
-
return opts.factory(params);
|
|
232
|
-
});
|
|
233
|
-
pathNode.builder.addAsyncErrorRule(ctx => {
|
|
234
|
-
const res = ctx.state.metadata(RESOURCE);
|
|
235
|
-
let errors;
|
|
236
|
-
switch (res.status()) {
|
|
237
|
-
case 'idle':
|
|
238
|
-
return undefined;
|
|
239
|
-
case 'loading':
|
|
240
|
-
case 'reloading':
|
|
241
|
-
return 'pending';
|
|
242
|
-
case 'resolved':
|
|
243
|
-
case 'local':
|
|
244
|
-
if (!res.hasValue()) {
|
|
245
|
-
return undefined;
|
|
246
|
-
}
|
|
247
|
-
errors = opts.onSuccess(res.value(), ctx);
|
|
248
|
-
return addDefaultField(errors, ctx.field);
|
|
249
|
-
case 'error':
|
|
250
|
-
errors = opts.onError(res.error(), ctx);
|
|
251
|
-
return addDefaultField(errors, ctx.field);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
function validateHttp(path, opts) {
|
|
256
|
-
validateAsync(path, {
|
|
257
|
-
params: opts.request,
|
|
258
|
-
factory: request => httpResource(request, opts.options),
|
|
259
|
-
onSuccess: opts.onSuccess,
|
|
260
|
-
onError: opts.onError
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function debounce(path, durationOrDebouncer) {
|
|
265
|
-
assertPathIsCurrent(path);
|
|
266
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
267
|
-
const debouncer = typeof durationOrDebouncer === 'function' ? durationOrDebouncer : durationOrDebouncer > 0 ? debounceForDuration(durationOrDebouncer) : immediate;
|
|
268
|
-
pathNode.builder.addAggregateMetadataRule(DEBOUNCER, () => debouncer);
|
|
269
|
-
}
|
|
270
|
-
function debounceForDuration(durationInMilliseconds) {
|
|
271
|
-
return (_context, abortSignal) => {
|
|
272
|
-
return new Promise(resolve => {
|
|
273
|
-
const timeoutId = setTimeout(resolve, durationInMilliseconds);
|
|
274
|
-
abortSignal.addEventListener('abort', () => clearTimeout(timeoutId));
|
|
275
|
-
});
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
function immediate() {}
|
|
279
|
-
|
|
280
15
|
const SIGNAL_FORMS_CONFIG = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'SIGNAL_FORMS_CONFIG' : '');
|
|
281
16
|
|
|
282
17
|
function provideSignalFormsConfig(config) {
|
|
@@ -351,31 +86,32 @@ class InteropNgControl {
|
|
|
351
86
|
valueAccessor = null;
|
|
352
87
|
hasValidator(validator) {
|
|
353
88
|
if (validator === Validators.required) {
|
|
354
|
-
return this.field().
|
|
89
|
+
return this.field().required();
|
|
355
90
|
}
|
|
356
91
|
return false;
|
|
357
92
|
}
|
|
358
93
|
updateValueAndValidity() {}
|
|
359
94
|
}
|
|
360
95
|
|
|
361
|
-
const FIELD = new InjectionToken(typeof ngDevMode !== undefined && ngDevMode ? 'FIELD' : '');
|
|
96
|
+
const FIELD = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FIELD' : '');
|
|
97
|
+
const controlInstructions = {
|
|
98
|
+
create: __controlCreate,
|
|
99
|
+
update: _controlUpdate
|
|
100
|
+
};
|
|
362
101
|
class Field {
|
|
102
|
+
element = inject(ElementRef).nativeElement;
|
|
363
103
|
injector = inject(Injector);
|
|
104
|
+
field = input.required(...(ngDevMode ? [{
|
|
105
|
+
debugName: "field"
|
|
106
|
+
}] : []));
|
|
107
|
+
state = computed(() => this.field()(), ...(ngDevMode ? [{
|
|
108
|
+
debugName: "state"
|
|
109
|
+
}] : []));
|
|
110
|
+
[_CONTROL] = controlInstructions;
|
|
364
111
|
config = inject(SIGNAL_FORMS_CONFIG, {
|
|
365
112
|
optional: true
|
|
366
113
|
});
|
|
367
114
|
classes = Object.entries(this.config?.classes ?? {}).map(([className, computation]) => [className, computed(() => computation(this.state()))]);
|
|
368
|
-
field = input.required({
|
|
369
|
-
...(ngDevMode ? {
|
|
370
|
-
debugName: "field"
|
|
371
|
-
} : {})
|
|
372
|
-
});
|
|
373
|
-
state = computed(() => this.field()(), {
|
|
374
|
-
...(ngDevMode ? {
|
|
375
|
-
debugName: "state"
|
|
376
|
-
} : {})
|
|
377
|
-
});
|
|
378
|
-
[_CONTROL] = undefined;
|
|
379
115
|
controlValueAccessors = inject(NG_VALUE_ACCESSOR, {
|
|
380
116
|
optional: true,
|
|
381
117
|
self: true
|
|
@@ -400,7 +136,7 @@ class Field {
|
|
|
400
136
|
}
|
|
401
137
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
402
138
|
minVersion: "12.0.0",
|
|
403
|
-
version: "21.1.0-next.
|
|
139
|
+
version: "21.1.0-next.2",
|
|
404
140
|
ngImport: i0,
|
|
405
141
|
type: Field,
|
|
406
142
|
deps: [],
|
|
@@ -408,7 +144,7 @@ class Field {
|
|
|
408
144
|
});
|
|
409
145
|
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
410
146
|
minVersion: "17.1.0",
|
|
411
|
-
version: "21.1.0-next.
|
|
147
|
+
version: "21.1.0-next.2",
|
|
412
148
|
type: Field,
|
|
413
149
|
isStandalone: true,
|
|
414
150
|
selector: "[field]",
|
|
@@ -433,7 +169,7 @@ class Field {
|
|
|
433
169
|
}
|
|
434
170
|
i0.ɵɵngDeclareClassMetadata({
|
|
435
171
|
minVersion: "12.0.0",
|
|
436
|
-
version: "21.1.0-next.
|
|
172
|
+
version: "21.1.0-next.2",
|
|
437
173
|
ngImport: i0,
|
|
438
174
|
type: Field,
|
|
439
175
|
decorators: [{
|
|
@@ -461,6 +197,185 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
461
197
|
}
|
|
462
198
|
});
|
|
463
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
|
+
|
|
464
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])?)*$/;
|
|
465
380
|
function email(path, config) {
|
|
466
381
|
validate(path, ctx => {
|
|
@@ -481,8 +396,8 @@ function email(path, config) {
|
|
|
481
396
|
}
|
|
482
397
|
|
|
483
398
|
function max(path, maxValue, config) {
|
|
484
|
-
const MAX_MEMO = metadata(path,
|
|
485
|
-
|
|
399
|
+
const MAX_MEMO = metadata(path, createMetadataKey(), ctx => typeof maxValue === 'number' ? maxValue : maxValue(ctx));
|
|
400
|
+
metadata(path, MAX, ({
|
|
486
401
|
state
|
|
487
402
|
}) => state.metadata(MAX_MEMO)());
|
|
488
403
|
validate(path, ctx => {
|
|
@@ -509,8 +424,8 @@ function max(path, maxValue, config) {
|
|
|
509
424
|
}
|
|
510
425
|
|
|
511
426
|
function maxLength(path, maxLength, config) {
|
|
512
|
-
const MAX_LENGTH_MEMO = metadata(path,
|
|
513
|
-
|
|
427
|
+
const MAX_LENGTH_MEMO = metadata(path, createMetadataKey(), ctx => typeof maxLength === 'number' ? maxLength : maxLength(ctx));
|
|
428
|
+
metadata(path, MAX_LENGTH, ({
|
|
514
429
|
state
|
|
515
430
|
}) => state.metadata(MAX_LENGTH_MEMO)());
|
|
516
431
|
validate(path, ctx => {
|
|
@@ -535,8 +450,8 @@ function maxLength(path, maxLength, config) {
|
|
|
535
450
|
}
|
|
536
451
|
|
|
537
452
|
function min(path, minValue, config) {
|
|
538
|
-
const MIN_MEMO = metadata(path,
|
|
539
|
-
|
|
453
|
+
const MIN_MEMO = metadata(path, createMetadataKey(), ctx => typeof minValue === 'number' ? minValue : minValue(ctx));
|
|
454
|
+
metadata(path, MIN, ({
|
|
540
455
|
state
|
|
541
456
|
}) => state.metadata(MIN_MEMO)());
|
|
542
457
|
validate(path, ctx => {
|
|
@@ -563,8 +478,8 @@ function min(path, minValue, config) {
|
|
|
563
478
|
}
|
|
564
479
|
|
|
565
480
|
function minLength(path, minLength, config) {
|
|
566
|
-
const MIN_LENGTH_MEMO = metadata(path,
|
|
567
|
-
|
|
481
|
+
const MIN_LENGTH_MEMO = metadata(path, createMetadataKey(), ctx => typeof minLength === 'number' ? minLength : minLength(ctx));
|
|
482
|
+
metadata(path, MIN_LENGTH, ({
|
|
568
483
|
state
|
|
569
484
|
}) => state.metadata(MIN_LENGTH_MEMO)());
|
|
570
485
|
validate(path, ctx => {
|
|
@@ -589,8 +504,8 @@ function minLength(path, minLength, config) {
|
|
|
589
504
|
}
|
|
590
505
|
|
|
591
506
|
function pattern(path, pattern, config) {
|
|
592
|
-
const PATTERN_MEMO = metadata(path,
|
|
593
|
-
|
|
507
|
+
const PATTERN_MEMO = metadata(path, createMetadataKey(), ctx => pattern instanceof RegExp ? pattern : pattern(ctx));
|
|
508
|
+
metadata(path, PATTERN, ({
|
|
594
509
|
state
|
|
595
510
|
}) => state.metadata(PATTERN_MEMO)());
|
|
596
511
|
validate(path, ctx => {
|
|
@@ -615,8 +530,8 @@ function pattern(path, pattern, config) {
|
|
|
615
530
|
}
|
|
616
531
|
|
|
617
532
|
function required(path, config) {
|
|
618
|
-
const REQUIRED_MEMO = metadata(path,
|
|
619
|
-
|
|
533
|
+
const REQUIRED_MEMO = metadata(path, createMetadataKey(), ctx => config?.when ? config.when(ctx) : true);
|
|
534
|
+
metadata(path, REQUIRED, ({
|
|
620
535
|
state
|
|
621
536
|
}) => state.metadata(REQUIRED_MEMO)());
|
|
622
537
|
validate(path, ctx => {
|
|
@@ -633,11 +548,52 @@ function required(path, config) {
|
|
|
633
548
|
});
|
|
634
549
|
}
|
|
635
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
|
+
|
|
636
592
|
function validateStandardSchema(path, schema) {
|
|
637
|
-
const VALIDATOR_MEMO = metadata(path, ({
|
|
593
|
+
const VALIDATOR_MEMO = metadata(path, createMetadataKey(), ({
|
|
638
594
|
value
|
|
639
595
|
}) => {
|
|
640
|
-
return
|
|
596
|
+
return schema['~standard'].validate(value());
|
|
641
597
|
});
|
|
642
598
|
validateTree(path, ({
|
|
643
599
|
state,
|
|
@@ -647,7 +603,7 @@ function validateStandardSchema(path, schema) {
|
|
|
647
603
|
if (_isPromise(result)) {
|
|
648
604
|
return [];
|
|
649
605
|
}
|
|
650
|
-
return result
|
|
606
|
+
return result?.issues?.map(issue => standardIssueToFormTreeError(fieldTreeOf(path), issue)) ?? [];
|
|
651
607
|
});
|
|
652
608
|
validateAsync(path, {
|
|
653
609
|
params: ({
|
|
@@ -683,5 +639,30 @@ function standardIssueToFormTreeError(field, issue) {
|
|
|
683
639
|
}), target);
|
|
684
640
|
}
|
|
685
641
|
|
|
686
|
-
|
|
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 };
|
|
687
668
|
//# sourceMappingURL=signals.mjs.map
|