@angular/forms 21.1.0-next.4 → 21.1.0
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/LICENSE +1 -1
- package/fesm2022/_structure-chunk.mjs +29 -15
- package/fesm2022/_structure-chunk.mjs.map +1 -1
- package/fesm2022/forms.mjs +133 -132
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +2 -2
- package/fesm2022/signals.mjs +63 -86
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +10 -4
- package/resources/code-examples.db +0 -0
- package/types/_structure-chunk.d.ts +57 -74
- package/types/forms.d.ts +26 -9
- package/types/signals-compat.d.ts +2 -2
- package/types/signals.d.ts +155 -145
package/fesm2022/signals.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.1.0
|
|
3
|
-
* (c) 2010-
|
|
2
|
+
* @license Angular v21.1.0
|
|
3
|
+
* (c) 2010-2026 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as i0 from '@angular/core';
|
|
8
8
|
import { InjectionToken, ɵRuntimeError as _RuntimeError, inject, ElementRef, Injector, input, computed, ɵCONTROL as _CONTROL, effect, Directive, ɵɵcontrolCreate as __controlCreate, ɵcontrolUpdate as _controlUpdate, ɵisPromise as _isPromise, resource } from '@angular/core';
|
|
9
9
|
import { Validators, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
|
|
10
|
-
import { assertPathIsCurrent, FieldPathNode,
|
|
10
|
+
import { assertPathIsCurrent, FieldPathNode, addDefaultField, metadata, createMetadataKey, MAX, MAX_LENGTH, MIN, MIN_LENGTH, PATTERN, REQUIRED, createManagedMetadataKey, DEBOUNCER } from './_structure-chunk.mjs';
|
|
11
11
|
export { MetadataKey, MetadataReducer, apply, applyEach, applyWhen, applyWhenValue, form, schema, submit } from './_structure-chunk.mjs';
|
|
12
12
|
import { httpResource } from '@angular/common/http';
|
|
13
13
|
import '@angular/core/primitives/signals';
|
|
@@ -93,18 +93,18 @@ class InteropNgControl {
|
|
|
93
93
|
updateValueAndValidity() {}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const
|
|
96
|
+
const FORM_FIELD = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FORM_FIELD' : '');
|
|
97
97
|
const controlInstructions = {
|
|
98
98
|
create: __controlCreate,
|
|
99
99
|
update: _controlUpdate
|
|
100
100
|
};
|
|
101
|
-
class
|
|
101
|
+
class FormField {
|
|
102
102
|
element = inject(ElementRef).nativeElement;
|
|
103
103
|
injector = inject(Injector);
|
|
104
|
-
|
|
105
|
-
debugName: "
|
|
104
|
+
formField = input.required(...(ngDevMode ? [{
|
|
105
|
+
debugName: "formField"
|
|
106
106
|
}] : []));
|
|
107
|
-
state = computed(() => this.
|
|
107
|
+
state = computed(() => this.formField()(), ...(ngDevMode ? [{
|
|
108
108
|
debugName: "state"
|
|
109
109
|
}] : []));
|
|
110
110
|
[_CONTROL] = controlInstructions;
|
|
@@ -126,9 +126,9 @@ class Field {
|
|
|
126
126
|
ɵregister() {
|
|
127
127
|
effect(onCleanup => {
|
|
128
128
|
const fieldNode = this.state();
|
|
129
|
-
fieldNode.nodeState.
|
|
129
|
+
fieldNode.nodeState.formFieldBindings.update(controls => [...controls, this]);
|
|
130
130
|
onCleanup(() => {
|
|
131
|
-
fieldNode.nodeState.
|
|
131
|
+
fieldNode.nodeState.formFieldBindings.update(controls => controls.filter(c => c !== this));
|
|
132
132
|
});
|
|
133
133
|
}, {
|
|
134
134
|
injector: this.injector
|
|
@@ -136,61 +136,61 @@ class Field {
|
|
|
136
136
|
}
|
|
137
137
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
138
138
|
minVersion: "12.0.0",
|
|
139
|
-
version: "21.1.0
|
|
139
|
+
version: "21.1.0",
|
|
140
140
|
ngImport: i0,
|
|
141
|
-
type:
|
|
141
|
+
type: FormField,
|
|
142
142
|
deps: [],
|
|
143
143
|
target: i0.ɵɵFactoryTarget.Directive
|
|
144
144
|
});
|
|
145
145
|
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
146
146
|
minVersion: "17.1.0",
|
|
147
|
-
version: "21.1.0
|
|
148
|
-
type:
|
|
147
|
+
version: "21.1.0",
|
|
148
|
+
type: FormField,
|
|
149
149
|
isStandalone: true,
|
|
150
|
-
selector: "[
|
|
150
|
+
selector: "[formField]",
|
|
151
151
|
inputs: {
|
|
152
|
-
|
|
153
|
-
classPropertyName: "
|
|
154
|
-
publicName: "
|
|
152
|
+
formField: {
|
|
153
|
+
classPropertyName: "formField",
|
|
154
|
+
publicName: "formField",
|
|
155
155
|
isSignal: true,
|
|
156
156
|
isRequired: true,
|
|
157
157
|
transformFunction: null
|
|
158
158
|
}
|
|
159
159
|
},
|
|
160
160
|
providers: [{
|
|
161
|
-
provide:
|
|
162
|
-
useExisting:
|
|
161
|
+
provide: FORM_FIELD,
|
|
162
|
+
useExisting: FormField
|
|
163
163
|
}, {
|
|
164
164
|
provide: NgControl,
|
|
165
|
-
useFactory: () => inject(
|
|
165
|
+
useFactory: () => inject(FormField).getOrCreateNgControl()
|
|
166
166
|
}],
|
|
167
167
|
ngImport: i0
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
i0.ɵɵngDeclareClassMetadata({
|
|
171
171
|
minVersion: "12.0.0",
|
|
172
|
-
version: "21.1.0
|
|
172
|
+
version: "21.1.0",
|
|
173
173
|
ngImport: i0,
|
|
174
|
-
type:
|
|
174
|
+
type: FormField,
|
|
175
175
|
decorators: [{
|
|
176
176
|
type: Directive,
|
|
177
177
|
args: [{
|
|
178
|
-
selector: '[
|
|
178
|
+
selector: '[formField]',
|
|
179
179
|
providers: [{
|
|
180
|
-
provide:
|
|
181
|
-
useExisting:
|
|
180
|
+
provide: FORM_FIELD,
|
|
181
|
+
useExisting: FormField
|
|
182
182
|
}, {
|
|
183
183
|
provide: NgControl,
|
|
184
|
-
useFactory: () => inject(
|
|
184
|
+
useFactory: () => inject(FormField).getOrCreateNgControl()
|
|
185
185
|
}]
|
|
186
186
|
}]
|
|
187
187
|
}],
|
|
188
188
|
propDecorators: {
|
|
189
|
-
|
|
189
|
+
formField: [{
|
|
190
190
|
type: i0.Input,
|
|
191
191
|
args: [{
|
|
192
192
|
isSignal: true,
|
|
193
|
-
alias: "
|
|
193
|
+
alias: "formField",
|
|
194
194
|
required: true
|
|
195
195
|
}]
|
|
196
196
|
}]
|
|
@@ -231,6 +231,28 @@ function readonly(path, logic = () => true) {
|
|
|
231
231
|
pathNode.builder.addReadonlyRule(logic);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
function getLengthOrSize(value) {
|
|
235
|
+
const v = value;
|
|
236
|
+
return typeof v.length === 'number' ? v.length : v.size;
|
|
237
|
+
}
|
|
238
|
+
function getOption(opt, ctx) {
|
|
239
|
+
return opt instanceof Function ? opt(ctx) : opt;
|
|
240
|
+
}
|
|
241
|
+
function isEmpty(value) {
|
|
242
|
+
if (typeof value === 'number') {
|
|
243
|
+
return isNaN(value);
|
|
244
|
+
}
|
|
245
|
+
return value === '' || value === false || value == null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function validate(path, logic) {
|
|
249
|
+
assertPathIsCurrent(path);
|
|
250
|
+
const pathNode = FieldPathNode.unwrapFieldPath(path);
|
|
251
|
+
pathNode.builder.addSyncErrorRule(ctx => {
|
|
252
|
+
return addDefaultField(logic(ctx), ctx.fieldTree);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
234
256
|
function requiredError(options) {
|
|
235
257
|
return new RequiredValidationError(options);
|
|
236
258
|
}
|
|
@@ -255,20 +277,6 @@ function emailError(options) {
|
|
|
255
277
|
function standardSchemaError(issue, options) {
|
|
256
278
|
return new StandardSchemaValidationError(issue, options);
|
|
257
279
|
}
|
|
258
|
-
function customError(obj) {
|
|
259
|
-
return new CustomValidationError(obj);
|
|
260
|
-
}
|
|
261
|
-
class CustomValidationError {
|
|
262
|
-
__brand = undefined;
|
|
263
|
-
kind = '';
|
|
264
|
-
fieldTree;
|
|
265
|
-
message;
|
|
266
|
-
constructor(options) {
|
|
267
|
-
if (options) {
|
|
268
|
-
Object.assign(this, options);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
280
|
class _NgValidationError {
|
|
273
281
|
__brand = undefined;
|
|
274
282
|
kind = '';
|
|
@@ -336,46 +344,6 @@ class StandardSchemaValidationError extends _NgValidationError {
|
|
|
336
344
|
}
|
|
337
345
|
const NgValidationError = _NgValidationError;
|
|
338
346
|
|
|
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.fieldTree));
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
|
|
379
347
|
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
348
|
function email(path, config) {
|
|
381
349
|
validate(path, ctx => {
|
|
@@ -657,12 +625,21 @@ function debounce(path, durationOrDebouncer) {
|
|
|
657
625
|
function debounceForDuration(durationInMilliseconds) {
|
|
658
626
|
return (_context, abortSignal) => {
|
|
659
627
|
return new Promise(resolve => {
|
|
660
|
-
|
|
661
|
-
|
|
628
|
+
let timeoutId;
|
|
629
|
+
const onAbort = () => {
|
|
630
|
+
clearTimeout(timeoutId);
|
|
631
|
+
};
|
|
632
|
+
timeoutId = setTimeout(() => {
|
|
633
|
+
abortSignal.removeEventListener('abort', onAbort);
|
|
634
|
+
resolve();
|
|
635
|
+
}, durationInMilliseconds);
|
|
636
|
+
abortSignal.addEventListener('abort', onAbort, {
|
|
637
|
+
once: true
|
|
638
|
+
});
|
|
662
639
|
});
|
|
663
640
|
};
|
|
664
641
|
}
|
|
665
642
|
function immediate() {}
|
|
666
643
|
|
|
667
|
-
export {
|
|
644
|
+
export { EmailValidationError, FORM_FIELD, FormField, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, RequiredValidationError, StandardSchemaValidationError, createManagedMetadataKey, createMetadataKey, 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
645
|
//# sourceMappingURL=signals.mjs.map
|