@ngx-formly/core 6.0.2 → 6.0.4
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/esm2020/lib/components/formly.field.mjs +18 -1
- package/esm2020/lib/extensions/field-expression/field-expression.mjs +8 -18
- package/esm2020/lib/models/fieldconfig.cache.mjs +1 -1
- package/esm2020/lib/services/formly.config.mjs +7 -2
- package/esm2020/lib/templates/field-array.type.mjs +3 -2
- package/fesm2015/ngx-formly-core.mjs +36 -22
- package/fesm2015/ngx-formly-core.mjs.map +1 -1
- package/fesm2020/ngx-formly-core.mjs +32 -20
- package/fesm2020/ngx-formly-core.mjs.map +1 -1
- package/lib/models/fieldconfig.cache.d.ts +4 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { Type, TemplateRef, ComponentRef, ChangeDetectorRef, InjectionToken, Inj
|
|
|
3
3
|
import * as i2 from '@angular/forms';
|
|
4
4
|
import { AbstractControl, FormGroup, FormArray, FormControl, Validators } from '@angular/forms';
|
|
5
5
|
import { isObservable, merge, of, Observable, Subject } from 'rxjs';
|
|
6
|
-
import { distinctUntilChanged, startWith, debounceTime, filter, switchMap, take, map } from 'rxjs/operators';
|
|
6
|
+
import { distinctUntilChanged, startWith, debounceTime, filter, switchMap, take, tap, map } from 'rxjs/operators';
|
|
7
7
|
import * as i2$1 from '@angular/common';
|
|
8
8
|
import { DOCUMENT, CommonModule } from '@angular/common';
|
|
9
9
|
import * as i1 from '@angular/platform-browser';
|
|
@@ -412,7 +412,12 @@ class FormlyConfig {
|
|
|
412
412
|
}
|
|
413
413
|
const componentRef = _viewContainerRef.createComponent(type.component, { injector: _injector });
|
|
414
414
|
defineHiddenProp(type, '_componentRef', componentRef);
|
|
415
|
-
|
|
415
|
+
try {
|
|
416
|
+
componentRef.destroy();
|
|
417
|
+
}
|
|
418
|
+
catch (e) {
|
|
419
|
+
console.error(`An error occurred while destroying the Formly component type "${field.type}"`, e);
|
|
420
|
+
}
|
|
416
421
|
return type._componentRef;
|
|
417
422
|
}
|
|
418
423
|
setWrapper(options) {
|
|
@@ -894,6 +899,24 @@ class FormlyField {
|
|
|
894
899
|
observeDeep(field, ['props'], () => field.options.detectChanges(field)),
|
|
895
900
|
observeDeep(field.options, ['formState'], () => field.options.detectChanges(field)),
|
|
896
901
|
];
|
|
902
|
+
for (const key of Object.keys(field._expressions)) {
|
|
903
|
+
const expressionObserver = observe(field, ['_expressions', key], ({ currentValue, previousValue }) => {
|
|
904
|
+
if (previousValue === null || previousValue === void 0 ? void 0 : previousValue.subscription) {
|
|
905
|
+
previousValue.subscription.unsubscribe();
|
|
906
|
+
previousValue.subscription = null;
|
|
907
|
+
}
|
|
908
|
+
if (isObservable(currentValue.value$)) {
|
|
909
|
+
currentValue.subscription = currentValue.value$.subscribe();
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
subscribes.push(() => {
|
|
913
|
+
var _a;
|
|
914
|
+
if ((_a = field._expressions[key]) === null || _a === void 0 ? void 0 : _a.subscription) {
|
|
915
|
+
field._expressions[key].subscription.unsubscribe();
|
|
916
|
+
}
|
|
917
|
+
expressionObserver.unsubscribe();
|
|
918
|
+
});
|
|
919
|
+
}
|
|
897
920
|
for (const path of [['template'], ['fieldGroupClassName'], ['validation', 'show']]) {
|
|
898
921
|
const fieldObserver = observe(field, path, ({ firstChange }) => !firstChange && field.options.detectChanges(field));
|
|
899
922
|
subscribes.push(() => fieldObserver.unsubscribe());
|
|
@@ -1425,7 +1448,9 @@ class FieldArrayType extends FieldType {
|
|
|
1425
1448
|
markAsDirty && this.formControl.markAsDirty();
|
|
1426
1449
|
}
|
|
1427
1450
|
_build() {
|
|
1428
|
-
|
|
1451
|
+
var _a;
|
|
1452
|
+
const fields = (_a = this.field.formControl._fields) !== null && _a !== void 0 ? _a : [this.field];
|
|
1453
|
+
fields.forEach((f) => this.options.build(f));
|
|
1429
1454
|
this.options.fieldChanges.next({
|
|
1430
1455
|
field: this.field,
|
|
1431
1456
|
value: getFieldValue(this.field),
|
|
@@ -1527,22 +1552,11 @@ class FieldExpressionExtension {
|
|
|
1527
1552
|
field._expressions[key] = this.parseExpressions(field, key, expr);
|
|
1528
1553
|
}
|
|
1529
1554
|
else if (expr instanceof Observable) {
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
field.hooks.onInit = () => {
|
|
1536
|
-
if (subscription === null) {
|
|
1537
|
-
subscription = subscribe();
|
|
1538
|
-
}
|
|
1539
|
-
return onInit === null || onInit === void 0 ? void 0 : onInit(field);
|
|
1540
|
-
};
|
|
1541
|
-
const onDestroy = field.hooks.onDestroy;
|
|
1542
|
-
field.hooks.onDestroy = () => {
|
|
1543
|
-
onDestroy === null || onDestroy === void 0 ? void 0 : onDestroy(field);
|
|
1544
|
-
subscription.unsubscribe();
|
|
1545
|
-
subscription = null;
|
|
1555
|
+
field._expressions[key] = {
|
|
1556
|
+
value$: expr.pipe(tap((v) => {
|
|
1557
|
+
this.evalExpr(field, key, v);
|
|
1558
|
+
field.options.detectChanges(field);
|
|
1559
|
+
})),
|
|
1546
1560
|
};
|
|
1547
1561
|
}
|
|
1548
1562
|
};
|
|
@@ -1630,17 +1644,17 @@ class FieldExpressionExtension {
|
|
|
1630
1644
|
};
|
|
1631
1645
|
}
|
|
1632
1646
|
checkExpressions(field, ignoreCache = false) {
|
|
1633
|
-
var _a;
|
|
1647
|
+
var _a, _b, _c;
|
|
1634
1648
|
if (!field) {
|
|
1635
1649
|
return false;
|
|
1636
1650
|
}
|
|
1637
1651
|
let fieldChanged = false;
|
|
1638
1652
|
if (field._expressions) {
|
|
1639
1653
|
for (const key of Object.keys(field._expressions)) {
|
|
1640
|
-
field._expressions[key].callback(ignoreCache) && (fieldChanged = true);
|
|
1654
|
+
((_b = (_a = field._expressions[key]).callback) === null || _b === void 0 ? void 0 : _b.call(_a, ignoreCache)) && (fieldChanged = true);
|
|
1641
1655
|
}
|
|
1642
1656
|
}
|
|
1643
|
-
(
|
|
1657
|
+
(_c = field.fieldGroup) === null || _c === void 0 ? void 0 : _c.forEach((f) => this.checkExpressions(f, ignoreCache) && (fieldChanged = true));
|
|
1644
1658
|
return fieldChanged;
|
|
1645
1659
|
}
|
|
1646
1660
|
changeDisabledState(field, value) {
|