@angular/forms 21.0.0-rc.1 → 21.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/fesm2022/_structure-chunk.mjs +1509 -0
- package/fesm2022/_structure-chunk.mjs.map +1 -0
- package/fesm2022/forms.mjs +133 -134
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +297 -0
- package/fesm2022/signals-compat.mjs.map +1 -0
- package/fesm2022/signals.mjs +42 -1436
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +8 -4
- package/types/_structure-chunk.d.ts +2240 -0
- package/types/forms.d.ts +28 -3
- package/types/signals-compat.d.ts +134 -0
- package/types/signals.d.ts +282 -2409
package/fesm2022/signals.mjs
CHANGED
|
@@ -1,711 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.0.0-rc.
|
|
2
|
+
* @license Angular v21.0.0-rc.3
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { httpResource } from '@angular/common/http';
|
|
8
8
|
import * as i0 from '@angular/core';
|
|
9
|
-
import { computed,
|
|
9
|
+
import { computed, InjectionToken, inject, Injector, input, ɵCONTROL as _CONTROL, effect, Directive, ɵ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';
|
|
10
12
|
import { Validators, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
function isArray(value) {
|
|
14
|
-
return Array.isArray(value);
|
|
15
|
-
}
|
|
16
|
-
function isObject(value) {
|
|
17
|
-
return (typeof value === 'object' || typeof value === 'function') && value != null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function reduceChildren(node, initialValue, fn, shortCircuit) {
|
|
21
|
-
const childrenMap = node.structure.childrenMap();
|
|
22
|
-
if (!childrenMap) {
|
|
23
|
-
return initialValue;
|
|
24
|
-
}
|
|
25
|
-
let value = initialValue;
|
|
26
|
-
for (const child of childrenMap.values()) {
|
|
27
|
-
if (shortCircuit?.(value)) {
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
value = fn(child, value);
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
function shortCircuitFalse(value) {
|
|
35
|
-
return !value;
|
|
36
|
-
}
|
|
37
|
-
function shortCircuitTrue(value) {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function calculateValidationSelfStatus(state) {
|
|
42
|
-
if (state.errors().length > 0) {
|
|
43
|
-
return 'invalid';
|
|
44
|
-
}
|
|
45
|
-
if (state.pending()) {
|
|
46
|
-
return 'unknown';
|
|
47
|
-
}
|
|
48
|
-
return 'valid';
|
|
49
|
-
}
|
|
50
|
-
class FieldValidationState {
|
|
51
|
-
node;
|
|
52
|
-
constructor(node) {
|
|
53
|
-
this.node = node;
|
|
54
|
-
}
|
|
55
|
-
rawSyncTreeErrors = computed(() => {
|
|
56
|
-
if (this.shouldSkipValidation()) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
return [...this.node.logicNode.logic.syncTreeErrors.compute(this.node.context), ...(this.node.structure.parent?.validationState.rawSyncTreeErrors() ?? [])];
|
|
60
|
-
}, ...(ngDevMode ? [{
|
|
61
|
-
debugName: "rawSyncTreeErrors"
|
|
62
|
-
}] : []));
|
|
63
|
-
syncErrors = computed(() => {
|
|
64
|
-
if (this.shouldSkipValidation()) {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
return [...this.node.logicNode.logic.syncErrors.compute(this.node.context), ...this.syncTreeErrors(), ...normalizeErrors(this.node.submitState.serverErrors())];
|
|
68
|
-
}, ...(ngDevMode ? [{
|
|
69
|
-
debugName: "syncErrors"
|
|
70
|
-
}] : []));
|
|
71
|
-
syncValid = computed(() => {
|
|
72
|
-
if (this.shouldSkipValidation()) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
return reduceChildren(this.node, this.syncErrors().length === 0, (child, value) => value && child.validationState.syncValid(), shortCircuitFalse);
|
|
76
|
-
}, ...(ngDevMode ? [{
|
|
77
|
-
debugName: "syncValid"
|
|
78
|
-
}] : []));
|
|
79
|
-
syncTreeErrors = computed(() => this.rawSyncTreeErrors().filter(err => err.field === this.node.fieldProxy), ...(ngDevMode ? [{
|
|
80
|
-
debugName: "syncTreeErrors"
|
|
81
|
-
}] : []));
|
|
82
|
-
rawAsyncErrors = computed(() => {
|
|
83
|
-
if (this.shouldSkipValidation()) {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
return [...this.node.logicNode.logic.asyncErrors.compute(this.node.context), ...(this.node.structure.parent?.validationState.rawAsyncErrors() ?? [])];
|
|
87
|
-
}, ...(ngDevMode ? [{
|
|
88
|
-
debugName: "rawAsyncErrors"
|
|
89
|
-
}] : []));
|
|
90
|
-
asyncErrors = computed(() => {
|
|
91
|
-
if (this.shouldSkipValidation()) {
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
return this.rawAsyncErrors().filter(err => err === 'pending' || err.field === this.node.fieldProxy);
|
|
95
|
-
}, ...(ngDevMode ? [{
|
|
96
|
-
debugName: "asyncErrors"
|
|
97
|
-
}] : []));
|
|
98
|
-
errors = computed(() => [...this.syncErrors(), ...this.asyncErrors().filter(err => err !== 'pending')], ...(ngDevMode ? [{
|
|
99
|
-
debugName: "errors"
|
|
100
|
-
}] : []));
|
|
101
|
-
errorSummary = computed(() => reduceChildren(this.node, this.errors(), (child, result) => [...result, ...child.errorSummary()]), ...(ngDevMode ? [{
|
|
102
|
-
debugName: "errorSummary"
|
|
103
|
-
}] : []));
|
|
104
|
-
pending = computed(() => reduceChildren(this.node, this.asyncErrors().includes('pending'), (child, value) => value || child.validationState.asyncErrors().includes('pending')), ...(ngDevMode ? [{
|
|
105
|
-
debugName: "pending"
|
|
106
|
-
}] : []));
|
|
107
|
-
status = computed(() => {
|
|
108
|
-
if (this.shouldSkipValidation()) {
|
|
109
|
-
return 'valid';
|
|
110
|
-
}
|
|
111
|
-
let ownStatus = calculateValidationSelfStatus(this);
|
|
112
|
-
return reduceChildren(this.node, ownStatus, (child, value) => {
|
|
113
|
-
if (value === 'invalid' || child.validationState.status() === 'invalid') {
|
|
114
|
-
return 'invalid';
|
|
115
|
-
} else if (value === 'unknown' || child.validationState.status() === 'unknown') {
|
|
116
|
-
return 'unknown';
|
|
117
|
-
}
|
|
118
|
-
return 'valid';
|
|
119
|
-
}, v => v === 'invalid');
|
|
120
|
-
}, ...(ngDevMode ? [{
|
|
121
|
-
debugName: "status"
|
|
122
|
-
}] : []));
|
|
123
|
-
valid = computed(() => this.status() === 'valid', ...(ngDevMode ? [{
|
|
124
|
-
debugName: "valid"
|
|
125
|
-
}] : []));
|
|
126
|
-
invalid = computed(() => this.status() === 'invalid', ...(ngDevMode ? [{
|
|
127
|
-
debugName: "invalid"
|
|
128
|
-
}] : []));
|
|
129
|
-
shouldSkipValidation = computed(() => this.node.hidden() || this.node.disabled() || this.node.readonly(), ...(ngDevMode ? [{
|
|
130
|
-
debugName: "shouldSkipValidation"
|
|
131
|
-
}] : []));
|
|
132
|
-
}
|
|
133
|
-
function normalizeErrors(error) {
|
|
134
|
-
if (error === undefined) {
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
|
-
if (isArray(error)) {
|
|
138
|
-
return error;
|
|
139
|
-
}
|
|
140
|
-
return [error];
|
|
141
|
-
}
|
|
142
|
-
function addDefaultField(errors, field) {
|
|
143
|
-
if (isArray(errors)) {
|
|
144
|
-
for (const error of errors) {
|
|
145
|
-
error.field ??= field;
|
|
146
|
-
}
|
|
147
|
-
} else if (errors) {
|
|
148
|
-
errors.field ??= field;
|
|
149
|
-
}
|
|
150
|
-
return errors;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const DYNAMIC = Symbol();
|
|
154
|
-
const IGNORED = Symbol();
|
|
155
|
-
class AbstractLogic {
|
|
156
|
-
predicates;
|
|
157
|
-
fns = [];
|
|
158
|
-
constructor(predicates) {
|
|
159
|
-
this.predicates = predicates;
|
|
160
|
-
}
|
|
161
|
-
push(logicFn) {
|
|
162
|
-
this.fns.push(wrapWithPredicates(this.predicates, logicFn));
|
|
163
|
-
}
|
|
164
|
-
mergeIn(other) {
|
|
165
|
-
const fns = this.predicates ? other.fns.map(fn => wrapWithPredicates(this.predicates, fn)) : other.fns;
|
|
166
|
-
this.fns.push(...fns);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
class BooleanOrLogic extends AbstractLogic {
|
|
170
|
-
get defaultValue() {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
compute(arg) {
|
|
174
|
-
return this.fns.some(f => {
|
|
175
|
-
const result = f(arg);
|
|
176
|
-
return result && result !== IGNORED;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
class ArrayMergeIgnoreLogic extends AbstractLogic {
|
|
181
|
-
ignore;
|
|
182
|
-
static ignoreNull(predicates) {
|
|
183
|
-
return new ArrayMergeIgnoreLogic(predicates, e => e === null);
|
|
184
|
-
}
|
|
185
|
-
constructor(predicates, ignore) {
|
|
186
|
-
super(predicates);
|
|
187
|
-
this.ignore = ignore;
|
|
188
|
-
}
|
|
189
|
-
get defaultValue() {
|
|
190
|
-
return [];
|
|
191
|
-
}
|
|
192
|
-
compute(arg) {
|
|
193
|
-
return this.fns.reduce((prev, f) => {
|
|
194
|
-
const value = f(arg);
|
|
195
|
-
if (value === undefined || value === IGNORED) {
|
|
196
|
-
return prev;
|
|
197
|
-
} else if (isArray(value)) {
|
|
198
|
-
return [...prev, ...(this.ignore ? value.filter(e => !this.ignore(e)) : value)];
|
|
199
|
-
} else {
|
|
200
|
-
if (this.ignore && this.ignore(value)) {
|
|
201
|
-
return prev;
|
|
202
|
-
}
|
|
203
|
-
return [...prev, value];
|
|
204
|
-
}
|
|
205
|
-
}, []);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
class ArrayMergeLogic extends ArrayMergeIgnoreLogic {
|
|
209
|
-
constructor(predicates) {
|
|
210
|
-
super(predicates, undefined);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
class AggregateMetadataMergeLogic extends AbstractLogic {
|
|
214
|
-
key;
|
|
215
|
-
get defaultValue() {
|
|
216
|
-
return this.key.getInitial();
|
|
217
|
-
}
|
|
218
|
-
constructor(predicates, key) {
|
|
219
|
-
super(predicates);
|
|
220
|
-
this.key = key;
|
|
221
|
-
}
|
|
222
|
-
compute(ctx) {
|
|
223
|
-
if (this.fns.length === 0) {
|
|
224
|
-
return this.key.getInitial();
|
|
225
|
-
}
|
|
226
|
-
let acc = this.key.getInitial();
|
|
227
|
-
for (let i = 0; i < this.fns.length; i++) {
|
|
228
|
-
const item = this.fns[i](ctx);
|
|
229
|
-
if (item !== IGNORED) {
|
|
230
|
-
acc = this.key.reduce(acc, item);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return acc;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function wrapWithPredicates(predicates, logicFn) {
|
|
237
|
-
if (predicates.length === 0) {
|
|
238
|
-
return logicFn;
|
|
239
|
-
}
|
|
240
|
-
return arg => {
|
|
241
|
-
for (const predicate of predicates) {
|
|
242
|
-
let predicateField = arg.stateOf(predicate.path);
|
|
243
|
-
const depthDiff = untracked(predicateField.structure.pathKeys).length - predicate.depth;
|
|
244
|
-
for (let i = 0; i < depthDiff; i++) {
|
|
245
|
-
predicateField = predicateField.structure.parent;
|
|
246
|
-
}
|
|
247
|
-
if (!predicate.fn(predicateField.context)) {
|
|
248
|
-
return IGNORED;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return logicFn(arg);
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
class LogicContainer {
|
|
255
|
-
predicates;
|
|
256
|
-
hidden;
|
|
257
|
-
disabledReasons;
|
|
258
|
-
readonly;
|
|
259
|
-
syncErrors;
|
|
260
|
-
syncTreeErrors;
|
|
261
|
-
asyncErrors;
|
|
262
|
-
aggregateMetadataKeys = new Map();
|
|
263
|
-
metadataFactories = new Map();
|
|
264
|
-
constructor(predicates) {
|
|
265
|
-
this.predicates = predicates;
|
|
266
|
-
this.hidden = new BooleanOrLogic(predicates);
|
|
267
|
-
this.disabledReasons = new ArrayMergeLogic(predicates);
|
|
268
|
-
this.readonly = new BooleanOrLogic(predicates);
|
|
269
|
-
this.syncErrors = ArrayMergeIgnoreLogic.ignoreNull(predicates);
|
|
270
|
-
this.syncTreeErrors = ArrayMergeIgnoreLogic.ignoreNull(predicates);
|
|
271
|
-
this.asyncErrors = ArrayMergeIgnoreLogic.ignoreNull(predicates);
|
|
272
|
-
}
|
|
273
|
-
hasAggregateMetadata(key) {
|
|
274
|
-
return this.aggregateMetadataKeys.has(key);
|
|
275
|
-
}
|
|
276
|
-
getAggregateMetadataEntries() {
|
|
277
|
-
return this.aggregateMetadataKeys.entries();
|
|
278
|
-
}
|
|
279
|
-
getMetadataFactoryEntries() {
|
|
280
|
-
return this.metadataFactories.entries();
|
|
281
|
-
}
|
|
282
|
-
getAggregateMetadata(key) {
|
|
283
|
-
if (!this.aggregateMetadataKeys.has(key)) {
|
|
284
|
-
this.aggregateMetadataKeys.set(key, new AggregateMetadataMergeLogic(this.predicates, key));
|
|
285
|
-
}
|
|
286
|
-
return this.aggregateMetadataKeys.get(key);
|
|
287
|
-
}
|
|
288
|
-
addMetadataFactory(key, factory) {
|
|
289
|
-
if (this.metadataFactories.has(key)) {
|
|
290
|
-
throw new Error(`Can't define value twice for the same MetadataKey`);
|
|
291
|
-
}
|
|
292
|
-
this.metadataFactories.set(key, factory);
|
|
293
|
-
}
|
|
294
|
-
mergeIn(other) {
|
|
295
|
-
this.hidden.mergeIn(other.hidden);
|
|
296
|
-
this.disabledReasons.mergeIn(other.disabledReasons);
|
|
297
|
-
this.readonly.mergeIn(other.readonly);
|
|
298
|
-
this.syncErrors.mergeIn(other.syncErrors);
|
|
299
|
-
this.syncTreeErrors.mergeIn(other.syncTreeErrors);
|
|
300
|
-
this.asyncErrors.mergeIn(other.asyncErrors);
|
|
301
|
-
for (const [key, metadataLogic] of other.getAggregateMetadataEntries()) {
|
|
302
|
-
this.getAggregateMetadata(key).mergeIn(metadataLogic);
|
|
303
|
-
}
|
|
304
|
-
for (const [key, metadataFactory] of other.getMetadataFactoryEntries()) {
|
|
305
|
-
this.addMetadataFactory(key, metadataFactory);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
let boundPathDepth = 0;
|
|
311
|
-
function getBoundPathDepth() {
|
|
312
|
-
return boundPathDepth;
|
|
313
|
-
}
|
|
314
|
-
function setBoundPathDepthForResolution(fn, depth) {
|
|
315
|
-
return (...args) => {
|
|
316
|
-
try {
|
|
317
|
-
boundPathDepth = depth;
|
|
318
|
-
return fn(...args);
|
|
319
|
-
} finally {
|
|
320
|
-
boundPathDepth = 0;
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
class AbstractLogicNodeBuilder {
|
|
326
|
-
depth;
|
|
327
|
-
constructor(depth) {
|
|
328
|
-
this.depth = depth;
|
|
329
|
-
}
|
|
330
|
-
build() {
|
|
331
|
-
return new LeafLogicNode(this, [], 0);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
class LogicNodeBuilder extends AbstractLogicNodeBuilder {
|
|
335
|
-
constructor(depth) {
|
|
336
|
-
super(depth);
|
|
337
|
-
}
|
|
338
|
-
current;
|
|
339
|
-
all = [];
|
|
340
|
-
addHiddenRule(logic) {
|
|
341
|
-
this.getCurrent().addHiddenRule(logic);
|
|
342
|
-
}
|
|
343
|
-
addDisabledReasonRule(logic) {
|
|
344
|
-
this.getCurrent().addDisabledReasonRule(logic);
|
|
345
|
-
}
|
|
346
|
-
addReadonlyRule(logic) {
|
|
347
|
-
this.getCurrent().addReadonlyRule(logic);
|
|
348
|
-
}
|
|
349
|
-
addSyncErrorRule(logic) {
|
|
350
|
-
this.getCurrent().addSyncErrorRule(logic);
|
|
351
|
-
}
|
|
352
|
-
addSyncTreeErrorRule(logic) {
|
|
353
|
-
this.getCurrent().addSyncTreeErrorRule(logic);
|
|
354
|
-
}
|
|
355
|
-
addAsyncErrorRule(logic) {
|
|
356
|
-
this.getCurrent().addAsyncErrorRule(logic);
|
|
357
|
-
}
|
|
358
|
-
addAggregateMetadataRule(key, logic) {
|
|
359
|
-
this.getCurrent().addAggregateMetadataRule(key, logic);
|
|
360
|
-
}
|
|
361
|
-
addMetadataFactory(key, factory) {
|
|
362
|
-
this.getCurrent().addMetadataFactory(key, factory);
|
|
363
|
-
}
|
|
364
|
-
getChild(key) {
|
|
365
|
-
return this.getCurrent().getChild(key);
|
|
366
|
-
}
|
|
367
|
-
hasLogic(builder) {
|
|
368
|
-
if (this === builder) {
|
|
369
|
-
return true;
|
|
370
|
-
}
|
|
371
|
-
return this.all.some(({
|
|
372
|
-
builder: subBuilder
|
|
373
|
-
}) => subBuilder.hasLogic(builder));
|
|
374
|
-
}
|
|
375
|
-
mergeIn(other, predicate) {
|
|
376
|
-
if (predicate) {
|
|
377
|
-
this.all.push({
|
|
378
|
-
builder: other,
|
|
379
|
-
predicate: {
|
|
380
|
-
fn: setBoundPathDepthForResolution(predicate.fn, this.depth),
|
|
381
|
-
path: predicate.path
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
} else {
|
|
385
|
-
this.all.push({
|
|
386
|
-
builder: other
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
this.current = undefined;
|
|
390
|
-
}
|
|
391
|
-
getCurrent() {
|
|
392
|
-
if (this.current === undefined) {
|
|
393
|
-
this.current = new NonMergeableLogicNodeBuilder(this.depth);
|
|
394
|
-
this.all.push({
|
|
395
|
-
builder: this.current
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
return this.current;
|
|
399
|
-
}
|
|
400
|
-
static newRoot() {
|
|
401
|
-
return new LogicNodeBuilder(0);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
class NonMergeableLogicNodeBuilder extends AbstractLogicNodeBuilder {
|
|
405
|
-
logic = new LogicContainer([]);
|
|
406
|
-
children = new Map();
|
|
407
|
-
constructor(depth) {
|
|
408
|
-
super(depth);
|
|
409
|
-
}
|
|
410
|
-
addHiddenRule(logic) {
|
|
411
|
-
this.logic.hidden.push(setBoundPathDepthForResolution(logic, this.depth));
|
|
412
|
-
}
|
|
413
|
-
addDisabledReasonRule(logic) {
|
|
414
|
-
this.logic.disabledReasons.push(setBoundPathDepthForResolution(logic, this.depth));
|
|
415
|
-
}
|
|
416
|
-
addReadonlyRule(logic) {
|
|
417
|
-
this.logic.readonly.push(setBoundPathDepthForResolution(logic, this.depth));
|
|
418
|
-
}
|
|
419
|
-
addSyncErrorRule(logic) {
|
|
420
|
-
this.logic.syncErrors.push(setBoundPathDepthForResolution(logic, this.depth));
|
|
421
|
-
}
|
|
422
|
-
addSyncTreeErrorRule(logic) {
|
|
423
|
-
this.logic.syncTreeErrors.push(setBoundPathDepthForResolution(logic, this.depth));
|
|
424
|
-
}
|
|
425
|
-
addAsyncErrorRule(logic) {
|
|
426
|
-
this.logic.asyncErrors.push(setBoundPathDepthForResolution(logic, this.depth));
|
|
427
|
-
}
|
|
428
|
-
addAggregateMetadataRule(key, logic) {
|
|
429
|
-
this.logic.getAggregateMetadata(key).push(setBoundPathDepthForResolution(logic, this.depth));
|
|
430
|
-
}
|
|
431
|
-
addMetadataFactory(key, factory) {
|
|
432
|
-
this.logic.addMetadataFactory(key, setBoundPathDepthForResolution(factory, this.depth));
|
|
433
|
-
}
|
|
434
|
-
getChild(key) {
|
|
435
|
-
if (!this.children.has(key)) {
|
|
436
|
-
this.children.set(key, new LogicNodeBuilder(this.depth + 1));
|
|
437
|
-
}
|
|
438
|
-
return this.children.get(key);
|
|
439
|
-
}
|
|
440
|
-
hasLogic(builder) {
|
|
441
|
-
return this === builder;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
class LeafLogicNode {
|
|
445
|
-
builder;
|
|
446
|
-
predicates;
|
|
447
|
-
depth;
|
|
448
|
-
logic;
|
|
449
|
-
constructor(builder, predicates, depth) {
|
|
450
|
-
this.builder = builder;
|
|
451
|
-
this.predicates = predicates;
|
|
452
|
-
this.depth = depth;
|
|
453
|
-
this.logic = builder ? createLogic(builder, predicates, depth) : new LogicContainer([]);
|
|
454
|
-
}
|
|
455
|
-
getChild(key) {
|
|
456
|
-
const childBuilders = this.builder ? getAllChildBuilders(this.builder, key) : [];
|
|
457
|
-
if (childBuilders.length === 0) {
|
|
458
|
-
return new LeafLogicNode(undefined, [], this.depth + 1);
|
|
459
|
-
} else if (childBuilders.length === 1) {
|
|
460
|
-
const {
|
|
461
|
-
builder,
|
|
462
|
-
predicates
|
|
463
|
-
} = childBuilders[0];
|
|
464
|
-
return new LeafLogicNode(builder, [...this.predicates, ...predicates.map(p => bindLevel(p, this.depth))], this.depth + 1);
|
|
465
|
-
} else {
|
|
466
|
-
const builtNodes = childBuilders.map(({
|
|
467
|
-
builder,
|
|
468
|
-
predicates
|
|
469
|
-
}) => new LeafLogicNode(builder, [...this.predicates, ...predicates.map(p => bindLevel(p, this.depth))], this.depth + 1));
|
|
470
|
-
return new CompositeLogicNode(builtNodes);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
hasLogic(builder) {
|
|
474
|
-
return this.builder?.hasLogic(builder) ?? false;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
class CompositeLogicNode {
|
|
478
|
-
all;
|
|
479
|
-
logic;
|
|
480
|
-
constructor(all) {
|
|
481
|
-
this.all = all;
|
|
482
|
-
this.logic = new LogicContainer([]);
|
|
483
|
-
for (const node of all) {
|
|
484
|
-
this.logic.mergeIn(node.logic);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
getChild(key) {
|
|
488
|
-
return new CompositeLogicNode(this.all.flatMap(child => child.getChild(key)));
|
|
489
|
-
}
|
|
490
|
-
hasLogic(builder) {
|
|
491
|
-
return this.all.some(node => node.hasLogic(builder));
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function getAllChildBuilders(builder, key) {
|
|
495
|
-
if (builder instanceof LogicNodeBuilder) {
|
|
496
|
-
return builder.all.flatMap(({
|
|
497
|
-
builder,
|
|
498
|
-
predicate
|
|
499
|
-
}) => {
|
|
500
|
-
const children = getAllChildBuilders(builder, key);
|
|
501
|
-
if (predicate) {
|
|
502
|
-
return children.map(({
|
|
503
|
-
builder,
|
|
504
|
-
predicates
|
|
505
|
-
}) => ({
|
|
506
|
-
builder,
|
|
507
|
-
predicates: [...predicates, predicate]
|
|
508
|
-
}));
|
|
509
|
-
}
|
|
510
|
-
return children;
|
|
511
|
-
});
|
|
512
|
-
} else if (builder instanceof NonMergeableLogicNodeBuilder) {
|
|
513
|
-
if (builder.children.has(key)) {
|
|
514
|
-
return [{
|
|
515
|
-
builder: builder.children.get(key),
|
|
516
|
-
predicates: []
|
|
517
|
-
}];
|
|
518
|
-
}
|
|
519
|
-
} else {
|
|
520
|
-
throw new Error('Unknown LogicNodeBuilder type');
|
|
521
|
-
}
|
|
522
|
-
return [];
|
|
523
|
-
}
|
|
524
|
-
function createLogic(builder, predicates, depth) {
|
|
525
|
-
const logic = new LogicContainer(predicates);
|
|
526
|
-
if (builder instanceof LogicNodeBuilder) {
|
|
527
|
-
const builtNodes = builder.all.map(({
|
|
528
|
-
builder,
|
|
529
|
-
predicate
|
|
530
|
-
}) => new LeafLogicNode(builder, predicate ? [...predicates, bindLevel(predicate, depth)] : predicates, depth));
|
|
531
|
-
for (const node of builtNodes) {
|
|
532
|
-
logic.mergeIn(node.logic);
|
|
533
|
-
}
|
|
534
|
-
} else if (builder instanceof NonMergeableLogicNodeBuilder) {
|
|
535
|
-
logic.mergeIn(builder.logic);
|
|
536
|
-
} else {
|
|
537
|
-
throw new Error('Unknown LogicNodeBuilder type');
|
|
538
|
-
}
|
|
539
|
-
return logic;
|
|
540
|
-
}
|
|
541
|
-
function bindLevel(predicate, depth) {
|
|
542
|
-
return {
|
|
543
|
-
...predicate,
|
|
544
|
-
depth: depth
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
const PATH = Symbol('PATH');
|
|
549
|
-
class FieldPathNode {
|
|
550
|
-
keys;
|
|
551
|
-
parent;
|
|
552
|
-
keyInParent;
|
|
553
|
-
root;
|
|
554
|
-
children = new Map();
|
|
555
|
-
fieldPathProxy = new Proxy(this, FIELD_PATH_PROXY_HANDLER);
|
|
556
|
-
logicBuilder;
|
|
557
|
-
constructor(keys, root, parent, keyInParent) {
|
|
558
|
-
this.keys = keys;
|
|
559
|
-
this.parent = parent;
|
|
560
|
-
this.keyInParent = keyInParent;
|
|
561
|
-
this.root = root ?? this;
|
|
562
|
-
if (!parent) {
|
|
563
|
-
this.logicBuilder = LogicNodeBuilder.newRoot();
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
get builder() {
|
|
567
|
-
if (this.logicBuilder) {
|
|
568
|
-
return this.logicBuilder;
|
|
569
|
-
}
|
|
570
|
-
return this.parent.builder.getChild(this.keyInParent);
|
|
571
|
-
}
|
|
572
|
-
get element() {
|
|
573
|
-
return this.getChild(DYNAMIC);
|
|
574
|
-
}
|
|
575
|
-
getChild(key) {
|
|
576
|
-
if (!this.children.has(key)) {
|
|
577
|
-
this.children.set(key, new FieldPathNode([...this.keys, key], this.root, this, key));
|
|
578
|
-
}
|
|
579
|
-
return this.children.get(key);
|
|
580
|
-
}
|
|
581
|
-
mergeIn(other, predicate) {
|
|
582
|
-
const path = other.compile();
|
|
583
|
-
this.builder.mergeIn(path.builder, predicate);
|
|
584
|
-
}
|
|
585
|
-
static unwrapFieldPath(formPath) {
|
|
586
|
-
return formPath[PATH];
|
|
587
|
-
}
|
|
588
|
-
static newRoot() {
|
|
589
|
-
return new FieldPathNode([], undefined, undefined, undefined);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
const FIELD_PATH_PROXY_HANDLER = {
|
|
593
|
-
get(node, property) {
|
|
594
|
-
if (property === PATH) {
|
|
595
|
-
return node;
|
|
596
|
-
}
|
|
597
|
-
return node.getChild(property).fieldPathProxy;
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
let currentCompilingNode = undefined;
|
|
602
|
-
const compiledSchemas = new Map();
|
|
603
|
-
class SchemaImpl {
|
|
604
|
-
schemaFn;
|
|
605
|
-
constructor(schemaFn) {
|
|
606
|
-
this.schemaFn = schemaFn;
|
|
607
|
-
}
|
|
608
|
-
compile() {
|
|
609
|
-
if (compiledSchemas.has(this)) {
|
|
610
|
-
return compiledSchemas.get(this);
|
|
611
|
-
}
|
|
612
|
-
const path = FieldPathNode.newRoot();
|
|
613
|
-
compiledSchemas.set(this, path);
|
|
614
|
-
let prevCompilingNode = currentCompilingNode;
|
|
615
|
-
try {
|
|
616
|
-
currentCompilingNode = path;
|
|
617
|
-
this.schemaFn(path.fieldPathProxy);
|
|
618
|
-
} finally {
|
|
619
|
-
currentCompilingNode = prevCompilingNode;
|
|
620
|
-
}
|
|
621
|
-
return path;
|
|
622
|
-
}
|
|
623
|
-
static create(schema) {
|
|
624
|
-
if (schema instanceof SchemaImpl) {
|
|
625
|
-
return schema;
|
|
626
|
-
}
|
|
627
|
-
return new SchemaImpl(schema);
|
|
628
|
-
}
|
|
629
|
-
static rootCompile(schema) {
|
|
630
|
-
try {
|
|
631
|
-
compiledSchemas.clear();
|
|
632
|
-
if (schema === undefined) {
|
|
633
|
-
return FieldPathNode.newRoot();
|
|
634
|
-
}
|
|
635
|
-
if (schema instanceof SchemaImpl) {
|
|
636
|
-
return schema.compile();
|
|
637
|
-
}
|
|
638
|
-
return new SchemaImpl(schema).compile();
|
|
639
|
-
} finally {
|
|
640
|
-
compiledSchemas.clear();
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
function isSchemaOrSchemaFn(value) {
|
|
645
|
-
return value instanceof SchemaImpl || typeof value === 'function';
|
|
646
|
-
}
|
|
647
|
-
function assertPathIsCurrent(path) {
|
|
648
|
-
if (currentCompilingNode !== FieldPathNode.unwrapFieldPath(path).root) {
|
|
649
|
-
throw new Error(`A FieldPath can only be used directly within the Schema that owns it,` + ` **not** outside of it or within a sub-schema.`);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
class MetadataKey {
|
|
654
|
-
brand;
|
|
655
|
-
constructor() {}
|
|
656
|
-
}
|
|
657
|
-
function createMetadataKey() {
|
|
658
|
-
return new MetadataKey();
|
|
659
|
-
}
|
|
660
|
-
class AggregateMetadataKey {
|
|
661
|
-
reduce;
|
|
662
|
-
getInitial;
|
|
663
|
-
brand;
|
|
664
|
-
constructor(reduce, getInitial) {
|
|
665
|
-
this.reduce = reduce;
|
|
666
|
-
this.getInitial = getInitial;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
function reducedMetadataKey(reduce, getInitial) {
|
|
670
|
-
return new AggregateMetadataKey(reduce, getInitial);
|
|
671
|
-
}
|
|
672
|
-
function listMetadataKey() {
|
|
673
|
-
return reducedMetadataKey((acc, item) => item === undefined ? acc : [...acc, item], () => []);
|
|
674
|
-
}
|
|
675
|
-
function minMetadataKey() {
|
|
676
|
-
return reducedMetadataKey((prev, next) => {
|
|
677
|
-
if (prev === undefined) {
|
|
678
|
-
return next;
|
|
679
|
-
}
|
|
680
|
-
if (next === undefined) {
|
|
681
|
-
return prev;
|
|
682
|
-
}
|
|
683
|
-
return Math.min(prev, next);
|
|
684
|
-
}, () => undefined);
|
|
685
|
-
}
|
|
686
|
-
function maxMetadataKey() {
|
|
687
|
-
return reducedMetadataKey((prev, next) => {
|
|
688
|
-
if (prev === undefined) {
|
|
689
|
-
return next;
|
|
690
|
-
}
|
|
691
|
-
if (next === undefined) {
|
|
692
|
-
return prev;
|
|
693
|
-
}
|
|
694
|
-
return Math.max(prev, next);
|
|
695
|
-
}, () => undefined);
|
|
696
|
-
}
|
|
697
|
-
function orMetadataKey() {
|
|
698
|
-
return reducedMetadataKey((prev, next) => prev || next, () => false);
|
|
699
|
-
}
|
|
700
|
-
function andMetadataKey() {
|
|
701
|
-
return reducedMetadataKey((prev, next) => prev && next, () => true);
|
|
702
|
-
}
|
|
703
|
-
const REQUIRED = orMetadataKey();
|
|
704
|
-
const MIN = maxMetadataKey();
|
|
705
|
-
const MAX = minMetadataKey();
|
|
706
|
-
const MIN_LENGTH = maxMetadataKey();
|
|
707
|
-
const MAX_LENGTH = minMetadataKey();
|
|
708
|
-
const PATTERN = listMetadataKey();
|
|
13
|
+
import '@angular/core/primitives/signals';
|
|
709
14
|
|
|
710
15
|
function requiredError(options) {
|
|
711
16
|
return new RequiredValidationError(options);
|
|
@@ -954,6 +259,22 @@ function validateHttp(path, opts) {
|
|
|
954
259
|
});
|
|
955
260
|
}
|
|
956
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
|
+
|
|
957
278
|
class InteropNgControl {
|
|
958
279
|
field;
|
|
959
280
|
constructor(field) {
|
|
@@ -1041,33 +362,12 @@ class Field {
|
|
|
1041
362
|
self: true
|
|
1042
363
|
});
|
|
1043
364
|
interopNgControl;
|
|
1044
|
-
get
|
|
365
|
+
get ɵinteropControl() {
|
|
1045
366
|
return this.controlValueAccessors?.[0] ?? this.interopNgControl?.valueAccessor ?? undefined;
|
|
1046
367
|
}
|
|
1047
|
-
|
|
1048
|
-
return this.controlValueAccessor !== undefined;
|
|
1049
|
-
}
|
|
1050
|
-
ɵgetOrCreateNgControl() {
|
|
368
|
+
getOrCreateNgControl() {
|
|
1051
369
|
return this.interopNgControl ??= new InteropNgControl(this.state);
|
|
1052
370
|
}
|
|
1053
|
-
ɵinteropControlCreate() {
|
|
1054
|
-
const controlValueAccessor = this.controlValueAccessor;
|
|
1055
|
-
controlValueAccessor.registerOnChange(value => {
|
|
1056
|
-
const state = this.state();
|
|
1057
|
-
state.value.set(value);
|
|
1058
|
-
state.markAsDirty();
|
|
1059
|
-
});
|
|
1060
|
-
controlValueAccessor.registerOnTouched(() => this.state().markAsTouched());
|
|
1061
|
-
}
|
|
1062
|
-
ɵinteropControlUpdate() {
|
|
1063
|
-
const controlValueAccessor = this.controlValueAccessor;
|
|
1064
|
-
const value = this.state().value();
|
|
1065
|
-
const disabled = this.state().disabled();
|
|
1066
|
-
untracked(() => {
|
|
1067
|
-
controlValueAccessor.writeValue(value);
|
|
1068
|
-
controlValueAccessor.setDisabledState?.(disabled);
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
371
|
ɵregister() {
|
|
1072
372
|
effect(onCleanup => {
|
|
1073
373
|
const fieldNode = this.state();
|
|
@@ -1081,7 +381,7 @@ class Field {
|
|
|
1081
381
|
}
|
|
1082
382
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1083
383
|
minVersion: "12.0.0",
|
|
1084
|
-
version: "21.0.0-rc.
|
|
384
|
+
version: "21.0.0-rc.3",
|
|
1085
385
|
ngImport: i0,
|
|
1086
386
|
type: Field,
|
|
1087
387
|
deps: [],
|
|
@@ -1089,7 +389,7 @@ class Field {
|
|
|
1089
389
|
});
|
|
1090
390
|
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
1091
391
|
minVersion: "17.1.0",
|
|
1092
|
-
version: "21.0.0-rc.
|
|
392
|
+
version: "21.0.0-rc.3",
|
|
1093
393
|
type: Field,
|
|
1094
394
|
isStandalone: true,
|
|
1095
395
|
selector: "[field]",
|
|
@@ -1107,14 +407,14 @@ class Field {
|
|
|
1107
407
|
useExisting: Field
|
|
1108
408
|
}, {
|
|
1109
409
|
provide: NgControl,
|
|
1110
|
-
useFactory: () => inject(Field)
|
|
410
|
+
useFactory: () => inject(Field).getOrCreateNgControl()
|
|
1111
411
|
}],
|
|
1112
412
|
ngImport: i0
|
|
1113
413
|
});
|
|
1114
414
|
}
|
|
1115
415
|
i0.ɵɵngDeclareClassMetadata({
|
|
1116
416
|
minVersion: "12.0.0",
|
|
1117
|
-
version: "21.0.0-rc.
|
|
417
|
+
version: "21.0.0-rc.3",
|
|
1118
418
|
ngImport: i0,
|
|
1119
419
|
type: Field,
|
|
1120
420
|
decorators: [{
|
|
@@ -1126,7 +426,7 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1126
426
|
useExisting: Field
|
|
1127
427
|
}, {
|
|
1128
428
|
provide: NgControl,
|
|
1129
|
-
useFactory: () => inject(Field)
|
|
429
|
+
useFactory: () => inject(Field).getOrCreateNgControl()
|
|
1130
430
|
}]
|
|
1131
431
|
}]
|
|
1132
432
|
}],
|
|
@@ -1142,706 +442,6 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1142
442
|
}
|
|
1143
443
|
});
|
|
1144
444
|
|
|
1145
|
-
class FieldNodeContext {
|
|
1146
|
-
node;
|
|
1147
|
-
cache = new WeakMap();
|
|
1148
|
-
constructor(node) {
|
|
1149
|
-
this.node = node;
|
|
1150
|
-
}
|
|
1151
|
-
resolve(target) {
|
|
1152
|
-
if (!this.cache.has(target)) {
|
|
1153
|
-
const resolver = computed(() => {
|
|
1154
|
-
const targetPathNode = FieldPathNode.unwrapFieldPath(target);
|
|
1155
|
-
let field = this.node;
|
|
1156
|
-
let stepsRemaining = getBoundPathDepth();
|
|
1157
|
-
while (stepsRemaining > 0 || !field.structure.logic.hasLogic(targetPathNode.root.builder)) {
|
|
1158
|
-
stepsRemaining--;
|
|
1159
|
-
field = field.structure.parent;
|
|
1160
|
-
if (field === undefined) {
|
|
1161
|
-
throw new Error('Path is not part of this field tree.');
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
for (let key of targetPathNode.keys) {
|
|
1165
|
-
field = field.structure.getChild(key);
|
|
1166
|
-
if (field === undefined) {
|
|
1167
|
-
throw new Error(`Cannot resolve path .${targetPathNode.keys.join('.')} relative to field ${['<root>', ...this.node.structure.pathKeys()].join('.')}.`);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
return field.fieldProxy;
|
|
1171
|
-
}, ...(ngDevMode ? [{
|
|
1172
|
-
debugName: "resolver"
|
|
1173
|
-
}] : []));
|
|
1174
|
-
this.cache.set(target, resolver);
|
|
1175
|
-
}
|
|
1176
|
-
return this.cache.get(target)();
|
|
1177
|
-
}
|
|
1178
|
-
get field() {
|
|
1179
|
-
return this.node.fieldProxy;
|
|
1180
|
-
}
|
|
1181
|
-
get state() {
|
|
1182
|
-
return this.node;
|
|
1183
|
-
}
|
|
1184
|
-
get value() {
|
|
1185
|
-
return this.node.structure.value;
|
|
1186
|
-
}
|
|
1187
|
-
get key() {
|
|
1188
|
-
return this.node.structure.keyInParent;
|
|
1189
|
-
}
|
|
1190
|
-
index = computed(() => {
|
|
1191
|
-
const key = this.key();
|
|
1192
|
-
if (!isArray(untracked(this.node.structure.parent.value))) {
|
|
1193
|
-
throw new Error(`RuntimeError: cannot access index, parent field is not an array`);
|
|
1194
|
-
}
|
|
1195
|
-
return Number(key);
|
|
1196
|
-
}, ...(ngDevMode ? [{
|
|
1197
|
-
debugName: "index"
|
|
1198
|
-
}] : []));
|
|
1199
|
-
fieldOf = p => this.resolve(p);
|
|
1200
|
-
stateOf = p => this.resolve(p)();
|
|
1201
|
-
valueOf = p => this.resolve(p)().value();
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
class FieldMetadataState {
|
|
1205
|
-
node;
|
|
1206
|
-
metadata = new Map();
|
|
1207
|
-
constructor(node) {
|
|
1208
|
-
this.node = node;
|
|
1209
|
-
untracked(() => runInInjectionContext(this.node.structure.injector, () => {
|
|
1210
|
-
for (const [key, factory] of this.node.logicNode.logic.getMetadataFactoryEntries()) {
|
|
1211
|
-
this.metadata.set(key, factory(this.node.context));
|
|
1212
|
-
}
|
|
1213
|
-
}));
|
|
1214
|
-
}
|
|
1215
|
-
get(key) {
|
|
1216
|
-
if (key instanceof MetadataKey) {
|
|
1217
|
-
return this.metadata.get(key);
|
|
1218
|
-
}
|
|
1219
|
-
if (!this.metadata.has(key)) {
|
|
1220
|
-
const logic = this.node.logicNode.logic.getAggregateMetadata(key);
|
|
1221
|
-
const result = computed(() => logic.compute(this.node.context), ...(ngDevMode ? [{
|
|
1222
|
-
debugName: "result"
|
|
1223
|
-
}] : []));
|
|
1224
|
-
this.metadata.set(key, result);
|
|
1225
|
-
}
|
|
1226
|
-
return this.metadata.get(key);
|
|
1227
|
-
}
|
|
1228
|
-
has(key) {
|
|
1229
|
-
if (key instanceof AggregateMetadataKey) {
|
|
1230
|
-
return this.node.logicNode.logic.hasAggregateMetadata(key);
|
|
1231
|
-
} else {
|
|
1232
|
-
return this.metadata.has(key);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
const FIELD_PROXY_HANDLER = {
|
|
1238
|
-
get(getTgt, p) {
|
|
1239
|
-
const tgt = getTgt();
|
|
1240
|
-
const child = tgt.structure.getChild(p);
|
|
1241
|
-
if (child !== undefined) {
|
|
1242
|
-
return child.fieldProxy;
|
|
1243
|
-
}
|
|
1244
|
-
const value = untracked(tgt.value);
|
|
1245
|
-
if (isArray(value)) {
|
|
1246
|
-
if (p === 'length') {
|
|
1247
|
-
return tgt.value().length;
|
|
1248
|
-
}
|
|
1249
|
-
if (p === Symbol.iterator) {
|
|
1250
|
-
return Array.prototype[p];
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
return undefined;
|
|
1254
|
-
}
|
|
1255
|
-
};
|
|
1256
|
-
|
|
1257
|
-
function deepSignal(source, prop) {
|
|
1258
|
-
const read = computed(() => source()[prop()]);
|
|
1259
|
-
read[SIGNAL] = source[SIGNAL];
|
|
1260
|
-
read.set = value => {
|
|
1261
|
-
source.update(current => valueForWrite(current, value, prop()));
|
|
1262
|
-
};
|
|
1263
|
-
read.update = fn => {
|
|
1264
|
-
read.set(fn(untracked(read)));
|
|
1265
|
-
};
|
|
1266
|
-
read.asReadonly = () => read;
|
|
1267
|
-
return read;
|
|
1268
|
-
}
|
|
1269
|
-
function valueForWrite(sourceValue, newPropValue, prop) {
|
|
1270
|
-
if (isArray(sourceValue)) {
|
|
1271
|
-
const newValue = [...sourceValue];
|
|
1272
|
-
newValue[prop] = newPropValue;
|
|
1273
|
-
return newValue;
|
|
1274
|
-
} else {
|
|
1275
|
-
return {
|
|
1276
|
-
...sourceValue,
|
|
1277
|
-
[prop]: newPropValue
|
|
1278
|
-
};
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
class FieldNodeStructure {
|
|
1283
|
-
logic;
|
|
1284
|
-
identitySymbol = Symbol();
|
|
1285
|
-
_injector = undefined;
|
|
1286
|
-
get injector() {
|
|
1287
|
-
this._injector ??= Injector.create({
|
|
1288
|
-
providers: [],
|
|
1289
|
-
parent: this.fieldManager.injector
|
|
1290
|
-
});
|
|
1291
|
-
return this._injector;
|
|
1292
|
-
}
|
|
1293
|
-
constructor(logic) {
|
|
1294
|
-
this.logic = logic;
|
|
1295
|
-
}
|
|
1296
|
-
children() {
|
|
1297
|
-
return this.childrenMap()?.values() ?? [];
|
|
1298
|
-
}
|
|
1299
|
-
getChild(key) {
|
|
1300
|
-
const map = this.childrenMap();
|
|
1301
|
-
const value = this.value();
|
|
1302
|
-
if (!map || !isObject(value)) {
|
|
1303
|
-
return undefined;
|
|
1304
|
-
}
|
|
1305
|
-
if (isArray(value)) {
|
|
1306
|
-
const childValue = value[key];
|
|
1307
|
-
if (isObject(childValue) && childValue.hasOwnProperty(this.identitySymbol)) {
|
|
1308
|
-
key = childValue[this.identitySymbol];
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
return map.get(typeof key === 'number' ? key.toString() : key);
|
|
1312
|
-
}
|
|
1313
|
-
destroy() {
|
|
1314
|
-
this.injector.destroy();
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
class RootFieldNodeStructure extends FieldNodeStructure {
|
|
1318
|
-
node;
|
|
1319
|
-
fieldManager;
|
|
1320
|
-
value;
|
|
1321
|
-
get parent() {
|
|
1322
|
-
return undefined;
|
|
1323
|
-
}
|
|
1324
|
-
get root() {
|
|
1325
|
-
return this.node;
|
|
1326
|
-
}
|
|
1327
|
-
get pathKeys() {
|
|
1328
|
-
return ROOT_PATH_KEYS;
|
|
1329
|
-
}
|
|
1330
|
-
get keyInParent() {
|
|
1331
|
-
return ROOT_KEY_IN_PARENT;
|
|
1332
|
-
}
|
|
1333
|
-
childrenMap;
|
|
1334
|
-
constructor(node, pathNode, logic, fieldManager, value, adapter, createChildNode) {
|
|
1335
|
-
super(logic);
|
|
1336
|
-
this.node = node;
|
|
1337
|
-
this.fieldManager = fieldManager;
|
|
1338
|
-
this.value = value;
|
|
1339
|
-
this.childrenMap = makeChildrenMapSignal(node, value, this.identitySymbol, pathNode, logic, adapter, createChildNode);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
class ChildFieldNodeStructure extends FieldNodeStructure {
|
|
1343
|
-
parent;
|
|
1344
|
-
root;
|
|
1345
|
-
pathKeys;
|
|
1346
|
-
keyInParent;
|
|
1347
|
-
value;
|
|
1348
|
-
childrenMap;
|
|
1349
|
-
get fieldManager() {
|
|
1350
|
-
return this.root.structure.fieldManager;
|
|
1351
|
-
}
|
|
1352
|
-
constructor(node, pathNode, logic, parent, identityInParent, initialKeyInParent, adapter, createChildNode) {
|
|
1353
|
-
super(logic);
|
|
1354
|
-
this.parent = parent;
|
|
1355
|
-
this.root = this.parent.structure.root;
|
|
1356
|
-
this.pathKeys = computed(() => [...parent.structure.pathKeys(), this.keyInParent()], ...(ngDevMode ? [{
|
|
1357
|
-
debugName: "pathKeys"
|
|
1358
|
-
}] : []));
|
|
1359
|
-
if (identityInParent === undefined) {
|
|
1360
|
-
const key = initialKeyInParent;
|
|
1361
|
-
this.keyInParent = computed(() => {
|
|
1362
|
-
if (parent.structure.childrenMap()?.get(key) !== node) {
|
|
1363
|
-
throw new Error(`RuntimeError: orphan field, looking for property '${key}' of ${getDebugName(parent)}`);
|
|
1364
|
-
}
|
|
1365
|
-
return key;
|
|
1366
|
-
}, ...(ngDevMode ? [{
|
|
1367
|
-
debugName: "keyInParent"
|
|
1368
|
-
}] : []));
|
|
1369
|
-
} else {
|
|
1370
|
-
let lastKnownKey = initialKeyInParent;
|
|
1371
|
-
this.keyInParent = computed(() => {
|
|
1372
|
-
const parentValue = parent.structure.value();
|
|
1373
|
-
if (!isArray(parentValue)) {
|
|
1374
|
-
throw new Error(`RuntimeError: orphan field, expected ${getDebugName(parent)} to be an array`);
|
|
1375
|
-
}
|
|
1376
|
-
const data = parentValue[lastKnownKey];
|
|
1377
|
-
if (isObject(data) && data.hasOwnProperty(parent.structure.identitySymbol) && data[parent.structure.identitySymbol] === identityInParent) {
|
|
1378
|
-
return lastKnownKey;
|
|
1379
|
-
}
|
|
1380
|
-
for (let i = 0; i < parentValue.length; i++) {
|
|
1381
|
-
const data = parentValue[i];
|
|
1382
|
-
if (isObject(data) && data.hasOwnProperty(parent.structure.identitySymbol) && data[parent.structure.identitySymbol] === identityInParent) {
|
|
1383
|
-
return lastKnownKey = i.toString();
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
throw new Error(`RuntimeError: orphan field, can't find element in array ${getDebugName(parent)}`);
|
|
1387
|
-
}, ...(ngDevMode ? [{
|
|
1388
|
-
debugName: "keyInParent"
|
|
1389
|
-
}] : []));
|
|
1390
|
-
}
|
|
1391
|
-
this.value = deepSignal(this.parent.structure.value, this.keyInParent);
|
|
1392
|
-
this.childrenMap = makeChildrenMapSignal(node, this.value, this.identitySymbol, pathNode, logic, adapter, createChildNode);
|
|
1393
|
-
this.fieldManager.structures.add(this);
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
let globalId = 0;
|
|
1397
|
-
const ROOT_PATH_KEYS = computed(() => [], ...(ngDevMode ? [{
|
|
1398
|
-
debugName: "ROOT_PATH_KEYS"
|
|
1399
|
-
}] : []));
|
|
1400
|
-
const ROOT_KEY_IN_PARENT = computed(() => {
|
|
1401
|
-
throw new Error(`RuntimeError: the top-level field in the form has no parent`);
|
|
1402
|
-
}, ...(ngDevMode ? [{
|
|
1403
|
-
debugName: "ROOT_KEY_IN_PARENT"
|
|
1404
|
-
}] : []));
|
|
1405
|
-
function makeChildrenMapSignal(node, valueSignal, identitySymbol, pathNode, logic, adapter, createChildNode) {
|
|
1406
|
-
return linkedSignal({
|
|
1407
|
-
source: valueSignal,
|
|
1408
|
-
computation: (value, previous) => {
|
|
1409
|
-
let childrenMap = previous?.value;
|
|
1410
|
-
if (!isObject(value)) {
|
|
1411
|
-
return undefined;
|
|
1412
|
-
}
|
|
1413
|
-
const isValueArray = isArray(value);
|
|
1414
|
-
if (childrenMap !== undefined) {
|
|
1415
|
-
let oldKeys = undefined;
|
|
1416
|
-
if (isValueArray) {
|
|
1417
|
-
oldKeys = new Set(childrenMap.keys());
|
|
1418
|
-
for (let i = 0; i < value.length; i++) {
|
|
1419
|
-
const childValue = value[i];
|
|
1420
|
-
if (isObject(childValue) && childValue.hasOwnProperty(identitySymbol)) {
|
|
1421
|
-
oldKeys.delete(childValue[identitySymbol]);
|
|
1422
|
-
} else {
|
|
1423
|
-
oldKeys.delete(i.toString());
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
for (const key of oldKeys) {
|
|
1427
|
-
childrenMap.delete(key);
|
|
1428
|
-
}
|
|
1429
|
-
} else {
|
|
1430
|
-
for (let key of childrenMap.keys()) {
|
|
1431
|
-
if (!value.hasOwnProperty(key)) {
|
|
1432
|
-
childrenMap.delete(key);
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
for (let key of Object.keys(value)) {
|
|
1438
|
-
let trackingId = undefined;
|
|
1439
|
-
const childValue = value[key];
|
|
1440
|
-
if (childValue === undefined) {
|
|
1441
|
-
childrenMap?.delete(key);
|
|
1442
|
-
continue;
|
|
1443
|
-
}
|
|
1444
|
-
if (isValueArray && isObject(childValue) && !isArray(childValue)) {
|
|
1445
|
-
trackingId = childValue[identitySymbol] ??= Symbol(ngDevMode ? `id:${globalId++}` : '');
|
|
1446
|
-
}
|
|
1447
|
-
const identity = trackingId ?? key;
|
|
1448
|
-
if (childrenMap?.has(identity)) {
|
|
1449
|
-
continue;
|
|
1450
|
-
}
|
|
1451
|
-
let childPath;
|
|
1452
|
-
let childLogic;
|
|
1453
|
-
if (isValueArray) {
|
|
1454
|
-
childPath = pathNode.getChild(DYNAMIC);
|
|
1455
|
-
childLogic = logic.getChild(DYNAMIC);
|
|
1456
|
-
} else {
|
|
1457
|
-
childPath = pathNode.getChild(key);
|
|
1458
|
-
childLogic = logic.getChild(key);
|
|
1459
|
-
}
|
|
1460
|
-
childrenMap ??= new Map();
|
|
1461
|
-
childrenMap.set(identity, createChildNode({
|
|
1462
|
-
kind: 'child',
|
|
1463
|
-
parent: node,
|
|
1464
|
-
pathNode: childPath,
|
|
1465
|
-
logic: childLogic,
|
|
1466
|
-
initialKeyInParent: key,
|
|
1467
|
-
identityInParent: trackingId,
|
|
1468
|
-
fieldAdapter: adapter
|
|
1469
|
-
}));
|
|
1470
|
-
}
|
|
1471
|
-
return childrenMap;
|
|
1472
|
-
},
|
|
1473
|
-
equal: () => false
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
function getDebugName(node) {
|
|
1477
|
-
return `<root>.${node.structure.pathKeys().join('.')}`;
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
class FieldSubmitState {
|
|
1481
|
-
node;
|
|
1482
|
-
selfSubmitting = signal(false, ...(ngDevMode ? [{
|
|
1483
|
-
debugName: "selfSubmitting"
|
|
1484
|
-
}] : []));
|
|
1485
|
-
serverErrors;
|
|
1486
|
-
constructor(node) {
|
|
1487
|
-
this.node = node;
|
|
1488
|
-
this.serverErrors = linkedSignal(...(ngDevMode ? [{
|
|
1489
|
-
debugName: "serverErrors",
|
|
1490
|
-
source: this.node.structure.value,
|
|
1491
|
-
computation: () => []
|
|
1492
|
-
}] : [{
|
|
1493
|
-
source: this.node.structure.value,
|
|
1494
|
-
computation: () => []
|
|
1495
|
-
}]));
|
|
1496
|
-
}
|
|
1497
|
-
submitting = computed(() => {
|
|
1498
|
-
return this.selfSubmitting() || (this.node.structure.parent?.submitting() ?? false);
|
|
1499
|
-
}, ...(ngDevMode ? [{
|
|
1500
|
-
debugName: "submitting"
|
|
1501
|
-
}] : []));
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
class FieldNode {
|
|
1505
|
-
structure;
|
|
1506
|
-
validationState;
|
|
1507
|
-
metadataState;
|
|
1508
|
-
nodeState;
|
|
1509
|
-
submitState;
|
|
1510
|
-
_context = undefined;
|
|
1511
|
-
fieldAdapter;
|
|
1512
|
-
get context() {
|
|
1513
|
-
return this._context ??= new FieldNodeContext(this);
|
|
1514
|
-
}
|
|
1515
|
-
fieldProxy = new Proxy(() => this, FIELD_PROXY_HANDLER);
|
|
1516
|
-
constructor(options) {
|
|
1517
|
-
this.fieldAdapter = options.fieldAdapter;
|
|
1518
|
-
this.structure = this.fieldAdapter.createStructure(this, options);
|
|
1519
|
-
this.validationState = this.fieldAdapter.createValidationState(this, options);
|
|
1520
|
-
this.nodeState = this.fieldAdapter.createNodeState(this, options);
|
|
1521
|
-
this.metadataState = new FieldMetadataState(this);
|
|
1522
|
-
this.submitState = new FieldSubmitState(this);
|
|
1523
|
-
}
|
|
1524
|
-
get logicNode() {
|
|
1525
|
-
return this.structure.logic;
|
|
1526
|
-
}
|
|
1527
|
-
get value() {
|
|
1528
|
-
return this.structure.value;
|
|
1529
|
-
}
|
|
1530
|
-
get keyInParent() {
|
|
1531
|
-
return this.structure.keyInParent;
|
|
1532
|
-
}
|
|
1533
|
-
get errors() {
|
|
1534
|
-
return this.validationState.errors;
|
|
1535
|
-
}
|
|
1536
|
-
get errorSummary() {
|
|
1537
|
-
return this.validationState.errorSummary;
|
|
1538
|
-
}
|
|
1539
|
-
get pending() {
|
|
1540
|
-
return this.validationState.pending;
|
|
1541
|
-
}
|
|
1542
|
-
get valid() {
|
|
1543
|
-
return this.validationState.valid;
|
|
1544
|
-
}
|
|
1545
|
-
get invalid() {
|
|
1546
|
-
return this.validationState.invalid;
|
|
1547
|
-
}
|
|
1548
|
-
get dirty() {
|
|
1549
|
-
return this.nodeState.dirty;
|
|
1550
|
-
}
|
|
1551
|
-
get touched() {
|
|
1552
|
-
return this.nodeState.touched;
|
|
1553
|
-
}
|
|
1554
|
-
get disabled() {
|
|
1555
|
-
return this.nodeState.disabled;
|
|
1556
|
-
}
|
|
1557
|
-
get disabledReasons() {
|
|
1558
|
-
return this.nodeState.disabledReasons;
|
|
1559
|
-
}
|
|
1560
|
-
get hidden() {
|
|
1561
|
-
return this.nodeState.hidden;
|
|
1562
|
-
}
|
|
1563
|
-
get readonly() {
|
|
1564
|
-
return this.nodeState.readonly;
|
|
1565
|
-
}
|
|
1566
|
-
get fieldBindings() {
|
|
1567
|
-
return this.nodeState.fieldBindings;
|
|
1568
|
-
}
|
|
1569
|
-
get submitting() {
|
|
1570
|
-
return this.submitState.submitting;
|
|
1571
|
-
}
|
|
1572
|
-
get name() {
|
|
1573
|
-
return this.nodeState.name;
|
|
1574
|
-
}
|
|
1575
|
-
metadataOrUndefined(key) {
|
|
1576
|
-
return this.hasMetadata(key) ? this.metadata(key) : undefined;
|
|
1577
|
-
}
|
|
1578
|
-
get max() {
|
|
1579
|
-
return this.metadataOrUndefined(MAX);
|
|
1580
|
-
}
|
|
1581
|
-
get maxLength() {
|
|
1582
|
-
return this.metadataOrUndefined(MAX_LENGTH);
|
|
1583
|
-
}
|
|
1584
|
-
get min() {
|
|
1585
|
-
return this.metadataOrUndefined(MIN);
|
|
1586
|
-
}
|
|
1587
|
-
get minLength() {
|
|
1588
|
-
return this.metadataOrUndefined(MIN_LENGTH);
|
|
1589
|
-
}
|
|
1590
|
-
get pattern() {
|
|
1591
|
-
return this.metadataOrUndefined(PATTERN) ?? EMPTY;
|
|
1592
|
-
}
|
|
1593
|
-
get required() {
|
|
1594
|
-
return this.metadataOrUndefined(REQUIRED) ?? FALSE;
|
|
1595
|
-
}
|
|
1596
|
-
metadata(key) {
|
|
1597
|
-
return this.metadataState.get(key);
|
|
1598
|
-
}
|
|
1599
|
-
hasMetadata(key) {
|
|
1600
|
-
return this.metadataState.has(key);
|
|
1601
|
-
}
|
|
1602
|
-
markAsTouched() {
|
|
1603
|
-
this.nodeState.markAsTouched();
|
|
1604
|
-
}
|
|
1605
|
-
markAsDirty() {
|
|
1606
|
-
this.nodeState.markAsDirty();
|
|
1607
|
-
}
|
|
1608
|
-
reset() {
|
|
1609
|
-
this.nodeState.markAsUntouched();
|
|
1610
|
-
this.nodeState.markAsPristine();
|
|
1611
|
-
for (const child of this.structure.children()) {
|
|
1612
|
-
child.reset();
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
static newRoot(fieldManager, value, pathNode, adapter) {
|
|
1616
|
-
return adapter.newRoot(fieldManager, value, pathNode, adapter);
|
|
1617
|
-
}
|
|
1618
|
-
static newChild(options) {
|
|
1619
|
-
return options.fieldAdapter.newChild(options);
|
|
1620
|
-
}
|
|
1621
|
-
createStructure(options) {
|
|
1622
|
-
return options.kind === 'root' ? new RootFieldNodeStructure(this, options.pathNode, options.logic, options.fieldManager, options.value, options.fieldAdapter, FieldNode.newChild) : new ChildFieldNodeStructure(this, options.pathNode, options.logic, options.parent, options.identityInParent, options.initialKeyInParent, options.fieldAdapter, FieldNode.newChild);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
const EMPTY = computed(() => [], ...(ngDevMode ? [{
|
|
1626
|
-
debugName: "EMPTY"
|
|
1627
|
-
}] : []));
|
|
1628
|
-
const FALSE = computed(() => false, ...(ngDevMode ? [{
|
|
1629
|
-
debugName: "FALSE"
|
|
1630
|
-
}] : []));
|
|
1631
|
-
|
|
1632
|
-
class FieldNodeState {
|
|
1633
|
-
node;
|
|
1634
|
-
selfTouched = signal(false, ...(ngDevMode ? [{
|
|
1635
|
-
debugName: "selfTouched"
|
|
1636
|
-
}] : []));
|
|
1637
|
-
selfDirty = signal(false, ...(ngDevMode ? [{
|
|
1638
|
-
debugName: "selfDirty"
|
|
1639
|
-
}] : []));
|
|
1640
|
-
markAsTouched() {
|
|
1641
|
-
this.selfTouched.set(true);
|
|
1642
|
-
}
|
|
1643
|
-
markAsDirty() {
|
|
1644
|
-
this.selfDirty.set(true);
|
|
1645
|
-
}
|
|
1646
|
-
markAsPristine() {
|
|
1647
|
-
this.selfDirty.set(false);
|
|
1648
|
-
}
|
|
1649
|
-
markAsUntouched() {
|
|
1650
|
-
this.selfTouched.set(false);
|
|
1651
|
-
}
|
|
1652
|
-
fieldBindings = signal([], ...(ngDevMode ? [{
|
|
1653
|
-
debugName: "fieldBindings"
|
|
1654
|
-
}] : []));
|
|
1655
|
-
constructor(node) {
|
|
1656
|
-
this.node = node;
|
|
1657
|
-
}
|
|
1658
|
-
dirty = computed(() => {
|
|
1659
|
-
const selfDirtyValue = this.selfDirty() && !this.isNonInteractive();
|
|
1660
|
-
return reduceChildren(this.node, selfDirtyValue, (child, value) => value || child.nodeState.dirty(), shortCircuitTrue);
|
|
1661
|
-
}, ...(ngDevMode ? [{
|
|
1662
|
-
debugName: "dirty"
|
|
1663
|
-
}] : []));
|
|
1664
|
-
touched = computed(() => {
|
|
1665
|
-
const selfTouchedValue = this.selfTouched() && !this.isNonInteractive();
|
|
1666
|
-
return reduceChildren(this.node, selfTouchedValue, (child, value) => value || child.nodeState.touched(), shortCircuitTrue);
|
|
1667
|
-
}, ...(ngDevMode ? [{
|
|
1668
|
-
debugName: "touched"
|
|
1669
|
-
}] : []));
|
|
1670
|
-
disabledReasons = computed(() => [...(this.node.structure.parent?.nodeState.disabledReasons() ?? []), ...this.node.logicNode.logic.disabledReasons.compute(this.node.context)], ...(ngDevMode ? [{
|
|
1671
|
-
debugName: "disabledReasons"
|
|
1672
|
-
}] : []));
|
|
1673
|
-
disabled = computed(() => !!this.disabledReasons().length, ...(ngDevMode ? [{
|
|
1674
|
-
debugName: "disabled"
|
|
1675
|
-
}] : []));
|
|
1676
|
-
readonly = computed(() => (this.node.structure.parent?.nodeState.readonly() || this.node.logicNode.logic.readonly.compute(this.node.context)) ?? false, ...(ngDevMode ? [{
|
|
1677
|
-
debugName: "readonly"
|
|
1678
|
-
}] : []));
|
|
1679
|
-
hidden = computed(() => (this.node.structure.parent?.nodeState.hidden() || this.node.logicNode.logic.hidden.compute(this.node.context)) ?? false, ...(ngDevMode ? [{
|
|
1680
|
-
debugName: "hidden"
|
|
1681
|
-
}] : []));
|
|
1682
|
-
name = computed(() => {
|
|
1683
|
-
const parent = this.node.structure.parent;
|
|
1684
|
-
if (!parent) {
|
|
1685
|
-
return this.node.structure.fieldManager.rootName;
|
|
1686
|
-
}
|
|
1687
|
-
return `${parent.name()}.${this.node.structure.keyInParent()}`;
|
|
1688
|
-
}, ...(ngDevMode ? [{
|
|
1689
|
-
debugName: "name"
|
|
1690
|
-
}] : []));
|
|
1691
|
-
isNonInteractive = computed(() => this.hidden() || this.disabled() || this.readonly(), ...(ngDevMode ? [{
|
|
1692
|
-
debugName: "isNonInteractive"
|
|
1693
|
-
}] : []));
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
class BasicFieldAdapter {
|
|
1697
|
-
newRoot(fieldManager, value, pathNode, adapter) {
|
|
1698
|
-
return new FieldNode({
|
|
1699
|
-
kind: 'root',
|
|
1700
|
-
fieldManager,
|
|
1701
|
-
value,
|
|
1702
|
-
pathNode,
|
|
1703
|
-
logic: pathNode.builder.build(),
|
|
1704
|
-
fieldAdapter: adapter
|
|
1705
|
-
});
|
|
1706
|
-
}
|
|
1707
|
-
newChild(options) {
|
|
1708
|
-
return new FieldNode(options);
|
|
1709
|
-
}
|
|
1710
|
-
createNodeState(node) {
|
|
1711
|
-
return new FieldNodeState(node);
|
|
1712
|
-
}
|
|
1713
|
-
createValidationState(node) {
|
|
1714
|
-
return new FieldValidationState(node);
|
|
1715
|
-
}
|
|
1716
|
-
createStructure(node, options) {
|
|
1717
|
-
return node.createStructure(options);
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
class FormFieldManager {
|
|
1722
|
-
injector;
|
|
1723
|
-
rootName;
|
|
1724
|
-
constructor(injector, rootName) {
|
|
1725
|
-
this.injector = injector;
|
|
1726
|
-
this.rootName = rootName ?? `${this.injector.get(APP_ID)}.form${nextFormId++}`;
|
|
1727
|
-
}
|
|
1728
|
-
structures = new Set();
|
|
1729
|
-
createFieldManagementEffect(root) {
|
|
1730
|
-
effect(() => {
|
|
1731
|
-
const liveStructures = new Set();
|
|
1732
|
-
this.markStructuresLive(root, liveStructures);
|
|
1733
|
-
for (const structure of this.structures) {
|
|
1734
|
-
if (!liveStructures.has(structure)) {
|
|
1735
|
-
this.structures.delete(structure);
|
|
1736
|
-
untracked(() => structure.destroy());
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
}, {
|
|
1740
|
-
injector: this.injector
|
|
1741
|
-
});
|
|
1742
|
-
}
|
|
1743
|
-
markStructuresLive(structure, liveStructures) {
|
|
1744
|
-
liveStructures.add(structure);
|
|
1745
|
-
for (const child of structure.children()) {
|
|
1746
|
-
this.markStructuresLive(child.structure, liveStructures);
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
let nextFormId = 0;
|
|
1751
|
-
|
|
1752
|
-
function normalizeFormArgs(args) {
|
|
1753
|
-
let model;
|
|
1754
|
-
let schema;
|
|
1755
|
-
let options;
|
|
1756
|
-
if (args.length === 3) {
|
|
1757
|
-
[model, schema, options] = args;
|
|
1758
|
-
} else if (args.length === 2) {
|
|
1759
|
-
if (isSchemaOrSchemaFn(args[1])) {
|
|
1760
|
-
[model, schema] = args;
|
|
1761
|
-
} else {
|
|
1762
|
-
[model, options] = args;
|
|
1763
|
-
}
|
|
1764
|
-
} else {
|
|
1765
|
-
[model] = args;
|
|
1766
|
-
}
|
|
1767
|
-
return [model, schema, options];
|
|
1768
|
-
}
|
|
1769
|
-
function form(...args) {
|
|
1770
|
-
const [model, schema, options] = normalizeFormArgs(args);
|
|
1771
|
-
const injector = options?.injector ?? inject(Injector);
|
|
1772
|
-
const pathNode = runInInjectionContext(injector, () => SchemaImpl.rootCompile(schema));
|
|
1773
|
-
const fieldManager = new FormFieldManager(injector, options?.name);
|
|
1774
|
-
const adapter = options?.adapter ?? new BasicFieldAdapter();
|
|
1775
|
-
const fieldRoot = FieldNode.newRoot(fieldManager, model, pathNode, adapter);
|
|
1776
|
-
fieldManager.createFieldManagementEffect(fieldRoot.structure);
|
|
1777
|
-
return fieldRoot.fieldProxy;
|
|
1778
|
-
}
|
|
1779
|
-
function applyEach(path, schema) {
|
|
1780
|
-
assertPathIsCurrent(path);
|
|
1781
|
-
const elementPath = FieldPathNode.unwrapFieldPath(path).element.fieldPathProxy;
|
|
1782
|
-
apply(elementPath, schema);
|
|
1783
|
-
}
|
|
1784
|
-
function apply(path, schema) {
|
|
1785
|
-
assertPathIsCurrent(path);
|
|
1786
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
1787
|
-
pathNode.mergeIn(SchemaImpl.create(schema));
|
|
1788
|
-
}
|
|
1789
|
-
function applyWhen(path, logic, schema) {
|
|
1790
|
-
assertPathIsCurrent(path);
|
|
1791
|
-
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
1792
|
-
pathNode.mergeIn(SchemaImpl.create(schema), {
|
|
1793
|
-
fn: logic,
|
|
1794
|
-
path
|
|
1795
|
-
});
|
|
1796
|
-
}
|
|
1797
|
-
function applyWhenValue(path, predicate, schema) {
|
|
1798
|
-
applyWhen(path, ({
|
|
1799
|
-
value
|
|
1800
|
-
}) => predicate(value()), schema);
|
|
1801
|
-
}
|
|
1802
|
-
async function submit(form, action) {
|
|
1803
|
-
const node = form();
|
|
1804
|
-
markAllAsTouched(node);
|
|
1805
|
-
if (node.invalid()) {
|
|
1806
|
-
return;
|
|
1807
|
-
}
|
|
1808
|
-
node.submitState.selfSubmitting.set(true);
|
|
1809
|
-
try {
|
|
1810
|
-
const errors = await action(form);
|
|
1811
|
-
errors && setServerErrors(node, errors);
|
|
1812
|
-
} finally {
|
|
1813
|
-
node.submitState.selfSubmitting.set(false);
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
function setServerErrors(submittedField, errors) {
|
|
1817
|
-
if (!isArray(errors)) {
|
|
1818
|
-
errors = [errors];
|
|
1819
|
-
}
|
|
1820
|
-
const errorsByField = new Map();
|
|
1821
|
-
for (const error of errors) {
|
|
1822
|
-
const errorWithField = addDefaultField(error, submittedField.fieldProxy);
|
|
1823
|
-
const field = errorWithField.field();
|
|
1824
|
-
let fieldErrors = errorsByField.get(field);
|
|
1825
|
-
if (!fieldErrors) {
|
|
1826
|
-
fieldErrors = [];
|
|
1827
|
-
errorsByField.set(field, fieldErrors);
|
|
1828
|
-
}
|
|
1829
|
-
fieldErrors.push(errorWithField);
|
|
1830
|
-
}
|
|
1831
|
-
for (const [field, fieldErrors] of errorsByField) {
|
|
1832
|
-
field.submitState.serverErrors.set(fieldErrors);
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
function schema(fn) {
|
|
1836
|
-
return SchemaImpl.create(fn);
|
|
1837
|
-
}
|
|
1838
|
-
function markAllAsTouched(node) {
|
|
1839
|
-
node.markAsTouched();
|
|
1840
|
-
for (const child of node.structure.children()) {
|
|
1841
|
-
markAllAsTouched(child);
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
445
|
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])?)*$/;
|
|
1846
446
|
function email(path, config) {
|
|
1847
447
|
validate(path, ctx => {
|
|
@@ -1874,7 +474,9 @@ function max(path, maxValue, config) {
|
|
|
1874
474
|
if (max === undefined || Number.isNaN(max)) {
|
|
1875
475
|
return undefined;
|
|
1876
476
|
}
|
|
1877
|
-
|
|
477
|
+
const value = ctx.value();
|
|
478
|
+
const numValue = !value && value !== 0 ? NaN : Number(value);
|
|
479
|
+
if (numValue > max) {
|
|
1878
480
|
if (config?.error) {
|
|
1879
481
|
return getOption(config.error, ctx);
|
|
1880
482
|
} else {
|
|
@@ -1926,7 +528,9 @@ function min(path, minValue, config) {
|
|
|
1926
528
|
if (min === undefined || Number.isNaN(min)) {
|
|
1927
529
|
return undefined;
|
|
1928
530
|
}
|
|
1929
|
-
|
|
531
|
+
const value = ctx.value();
|
|
532
|
+
const numValue = !value && value !== 0 ? NaN : Number(value);
|
|
533
|
+
if (numValue < min) {
|
|
1930
534
|
if (config?.error) {
|
|
1931
535
|
return getOption(config.error, ctx);
|
|
1932
536
|
} else {
|
|
@@ -2018,13 +622,13 @@ function validateStandardSchema(path, schema) {
|
|
|
2018
622
|
});
|
|
2019
623
|
validateTree(path, ({
|
|
2020
624
|
state,
|
|
2021
|
-
|
|
625
|
+
fieldTreeOf
|
|
2022
626
|
}) => {
|
|
2023
627
|
const result = state.metadata(VALIDATOR_MEMO)();
|
|
2024
628
|
if (_isPromise(result)) {
|
|
2025
629
|
return [];
|
|
2026
630
|
}
|
|
2027
|
-
return result.issues?.map(issue => standardIssueToFormTreeError(
|
|
631
|
+
return result.issues?.map(issue => standardIssueToFormTreeError(fieldTreeOf(path), issue)) ?? [];
|
|
2028
632
|
});
|
|
2029
633
|
validateAsync(path, {
|
|
2030
634
|
params: ({
|
|
@@ -2042,9 +646,9 @@ function validateStandardSchema(path, schema) {
|
|
|
2042
646
|
});
|
|
2043
647
|
},
|
|
2044
648
|
onSuccess: (issues, {
|
|
2045
|
-
|
|
649
|
+
fieldTreeOf
|
|
2046
650
|
}) => {
|
|
2047
|
-
return issues.map(issue => standardIssueToFormTreeError(
|
|
651
|
+
return issues.map(issue => standardIssueToFormTreeError(fieldTreeOf(path), issue));
|
|
2048
652
|
},
|
|
2049
653
|
onError: () => {}
|
|
2050
654
|
});
|
|
@@ -2055,8 +659,10 @@ function standardIssueToFormTreeError(field, issue) {
|
|
|
2055
659
|
const pathKey = typeof pathPart === 'object' ? pathPart.key : pathPart;
|
|
2056
660
|
target = target[pathKey];
|
|
2057
661
|
}
|
|
2058
|
-
return addDefaultField(standardSchemaError(issue
|
|
662
|
+
return addDefaultField(standardSchemaError(issue, {
|
|
663
|
+
message: issue.message
|
|
664
|
+
}), target);
|
|
2059
665
|
}
|
|
2060
666
|
|
|
2061
|
-
export {
|
|
667
|
+
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, readonly, required, requiredError, standardSchemaError, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
|
|
2062
668
|
//# sourceMappingURL=signals.mjs.map
|