@ngx-formly/core 5.10.29 → 5.10.33

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.
@@ -1,15 +1,30 @@
1
1
  import { DOCUMENT, CommonModule } from '@angular/common';
2
- import { TemplateRef, Injectable, InjectionToken, NgModule, ANALYZE_FOR_ENTRY_COMPONENTS, Inject, Optional, Component, Input, ChangeDetectionStrategy, ComponentFactoryResolver, Injector, ChangeDetectorRef, Directive, EventEmitter, NgZone, Attribute, Output, ViewChild, Renderer2, ElementRef, ViewContainerRef, defineInjectable, inject, INJECTOR } from '@angular/core';
2
+ import { TemplateRef, Injectable, InjectionToken, NgModule, ANALYZE_FOR_ENTRY_COMPONENTS, Inject, Optional, Component, Input, ChangeDetectionStrategy, ComponentFactoryResolver, Injector, ChangeDetectorRef, Directive, EventEmitter, Renderer2, ElementRef, Attribute, Output, ViewChild, ViewContainerRef, NgZone, defineInjectable, inject, INJECTOR } from '@angular/core';
3
3
  import { DomSanitizer } from '@angular/platform-browser';
4
4
  import { debounceTime, switchMap, distinctUntilChanged, take, startWith, filter, map } from 'rxjs/operators';
5
5
  import { AbstractControl, FormArray, FormGroup, FormControl, FormGroupDirective, Validators } from '@angular/forms';
6
6
  import { isObservable, Subject, of, merge, Observable } from 'rxjs';
7
- import { __extends, __assign, __spread, __rest, __values, __read } from 'tslib';
7
+ import { __extends, __assign, __spread, __rest, __read, __values } from 'tslib';
8
8
 
9
9
  /**
10
10
  * @fileoverview added by tsickle
11
11
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
12
12
  */
13
+ /**
14
+ * @param {?} form
15
+ * @param {?} callback
16
+ * @return {?}
17
+ */
18
+ function disableTreeValidityCall(form, callback) {
19
+ /** @type {?} */
20
+ var _updateTreeValidity = form._updateTreeValidity.bind(form);
21
+ form._updateTreeValidity = (/**
22
+ * @return {?}
23
+ */
24
+ function () { });
25
+ callback();
26
+ form._updateTreeValidity = _updateTreeValidity;
27
+ }
13
28
  /**
14
29
  * @param {?} formId
15
30
  * @param {?} field
@@ -21,8 +36,12 @@ function getFieldId(formId, field, index) {
21
36
  return field.id;
22
37
  /** @type {?} */
23
38
  var type = field.type;
24
- if (!type && field.template)
39
+ if (!type && field.template) {
25
40
  type = 'template';
41
+ }
42
+ if (isFunction(type)) {
43
+ type = ((/** @type {?} */ (type))).prototype.constructor.name;
44
+ }
26
45
  return [formId, type, field.key, index].join('_');
27
46
  }
28
47
  /**
@@ -331,28 +350,6 @@ function wrapProperty(o, prop, setFn) {
331
350
  */
332
351
  function () { return fns.splice(fns.indexOf(setFn), 1); });
333
352
  }
334
- /**
335
- * @param {?} form
336
- * @param {?} action
337
- * @return {?}
338
- */
339
- function reduceFormUpdateValidityCalls(form, action) {
340
- /** @type {?} */
341
- var updateValidity = form._updateTreeValidity.bind(form);
342
- /** @type {?} */
343
- var updateValidityArgs = { called: false, emitEvent: false };
344
- form._updateTreeValidity = (/**
345
- * @param {?=} __0
346
- * @return {?}
347
- */
348
- function (_a) {
349
- var emitEvent = (_a === void 0 ? { emitEvent: true } : _a).emitEvent;
350
- return updateValidityArgs = { called: true, emitEvent: emitEvent || updateValidityArgs.emitEvent };
351
- });
352
- action();
353
- updateValidityArgs.called && updateValidity({ emitEvent: updateValidityArgs.emitEvent });
354
- form._updateTreeValidity = updateValidity;
355
- }
356
353
 
357
354
  /**
358
355
  * @fileoverview added by tsickle
@@ -741,7 +738,7 @@ var FormlyFormBuilder = /** @class */ (function () {
741
738
  }
742
739
  /** @type {?} */
743
740
  var field = { fieldGroup: fieldGroup, model: model, formControl: formControl, options: this._setOptions(options) };
744
- reduceFormUpdateValidityCalls(formControl, (/**
741
+ disableTreeValidityCall(formControl, (/**
745
742
  * @return {?}
746
743
  */
747
744
  function () { return _this._buildForm(field); }));
@@ -1028,15 +1025,22 @@ function registerControl(field, control, emitEvent) {
1028
1025
  }
1029
1026
  /**
1030
1027
  * @param {?} c
1028
+ * @param {?=} onlySelf
1031
1029
  * @return {?}
1032
1030
  */
1033
- function updateValidity(c) {
1031
+ function updateValidity(c, onlySelf) {
1032
+ if (onlySelf === void 0) { onlySelf = false; }
1034
1033
  /** @type {?} */
1035
1034
  var status = c.status;
1036
- c.updateValueAndValidity({ emitEvent: false });
1035
+ /** @type {?} */
1036
+ var value = c.value;
1037
+ c.updateValueAndValidity({ emitEvent: false, onlySelf: onlySelf });
1037
1038
  if (status !== c.status) {
1038
1039
  ((/** @type {?} */ (c.statusChanges))).emit(c.status);
1039
1040
  }
1041
+ if (value !== c.value) {
1042
+ ((/** @type {?} */ (c.valueChanges))).emit(c.value);
1043
+ }
1040
1044
  }
1041
1045
  /**
1042
1046
  * @param {?} form
@@ -1860,16 +1864,11 @@ var FormlyField = /** @class */ (function () {
1860
1864
  */
1861
1865
  var FormlyAttributes = /** @class */ (function () {
1862
1866
  function FormlyAttributes(renderer, elementRef, _document) {
1867
+ var _this = this;
1863
1868
  this.renderer = renderer;
1864
1869
  this.elementRef = elementRef;
1865
1870
  this.uiAttributesCache = {};
1866
- this.uiAttributes = __spread(FORMLY_VALIDATORS, [
1867
- 'tabindex',
1868
- 'placeholder',
1869
- 'readonly',
1870
- 'disabled',
1871
- 'step',
1872
- ]);
1871
+ this.uiAttributes = null;
1873
1872
  /**
1874
1873
  * HostBinding doesn't register listeners conditionally which may produce some perf issues.
1875
1874
  *
@@ -1877,12 +1876,24 @@ var FormlyAttributes = /** @class */ (function () {
1877
1876
  */
1878
1877
  this.uiEvents = {
1879
1878
  listeners: [],
1880
- events: [
1881
- 'click',
1882
- 'keyup',
1883
- 'keydown',
1884
- 'keypress',
1885
- ],
1879
+ events: ['click', 'keyup', 'keydown', 'keypress', 'focus', 'blur', 'change'],
1880
+ callback: (/**
1881
+ * @param {?} eventName
1882
+ * @param {?} $event
1883
+ * @return {?}
1884
+ */
1885
+ function (eventName, $event) {
1886
+ switch (eventName) {
1887
+ case 'focus':
1888
+ return _this.onFocus($event);
1889
+ case 'blur':
1890
+ return _this.onBlur($event);
1891
+ case 'change':
1892
+ return _this.onChange($event);
1893
+ default:
1894
+ return _this.to[eventName](_this.field, $event);
1895
+ }
1896
+ }),
1886
1897
  };
1887
1898
  this.document = _document;
1888
1899
  }
@@ -1925,12 +1936,12 @@ var FormlyAttributes = /** @class */ (function () {
1925
1936
  * @return {?}
1926
1937
  */
1927
1938
  function (eventName) {
1928
- if (_this.to && _this.to[eventName]) {
1939
+ if ((_this.to && _this.to[eventName]) || ['focus', 'blur', 'change'].indexOf(eventName) !== -1) {
1929
1940
  _this.uiEvents.listeners.push(_this.renderer.listen(_this.elementRef.nativeElement, eventName, (/**
1930
1941
  * @param {?} e
1931
1942
  * @return {?}
1932
1943
  */
1933
- function (e) { return _this.to[eventName](_this.field, e); })));
1944
+ function (e) { return _this.uiEvents.callback(eventName, e); })));
1934
1945
  }
1935
1946
  }));
1936
1947
  if (this.to && this.to.attributes) {
@@ -2006,6 +2017,15 @@ var FormlyAttributes = /** @class */ (function () {
2006
2017
  */
2007
2018
  function () {
2008
2019
  var _this = this;
2020
+ if (!this.uiAttributes) {
2021
+ /** @type {?} */
2022
+ var element_1 = (/** @type {?} */ (this.elementRef.nativeElement));
2023
+ this.uiAttributes = __spread(FORMLY_VALIDATORS, ['tabindex', 'placeholder', 'readonly', 'disabled', 'step']).filter((/**
2024
+ * @param {?} attr
2025
+ * @return {?}
2026
+ */
2027
+ function (attr) { return !element_1.hasAttribute || !element_1.hasAttribute(attr); }));
2028
+ }
2009
2029
  this.uiAttributes.forEach((/**
2010
2030
  * @param {?} attr
2011
2031
  * @return {?}
@@ -2100,6 +2120,24 @@ var FormlyAttributes = /** @class */ (function () {
2100
2120
  this.to.blur(this.field, $event);
2101
2121
  }
2102
2122
  };
2123
+ // handle custom `change` event, for regular ones rely on DOM listener
2124
+ // handle custom `change` event, for regular ones rely on DOM listener
2125
+ /**
2126
+ * @param {?} $event
2127
+ * @return {?}
2128
+ */
2129
+ FormlyAttributes.prototype.onHostChange =
2130
+ // handle custom `change` event, for regular ones rely on DOM listener
2131
+ /**
2132
+ * @param {?} $event
2133
+ * @return {?}
2134
+ */
2135
+ function ($event) {
2136
+ if ($event instanceof Event) {
2137
+ return;
2138
+ }
2139
+ this.onChange($event);
2140
+ };
2103
2141
  /**
2104
2142
  * @param {?} $event
2105
2143
  * @return {?}
@@ -2186,9 +2224,7 @@ var FormlyAttributes = /** @class */ (function () {
2186
2224
  { type: Directive, args: [{
2187
2225
  selector: '[formlyAttributes]',
2188
2226
  host: {
2189
- '(focus)': 'onFocus($event)',
2190
- '(blur)': 'onBlur($event)',
2191
- '(change)': 'onChange($event)',
2227
+ '(change)': 'onHostChange($event)',
2192
2228
  },
2193
2229
  },] }
2194
2230
  ];
@@ -2693,10 +2729,7 @@ FieldExpressionExtension = /** @class */ (function () {
2693
2729
  function (f, ignoreCache) {
2694
2730
  if (!checkLocked) {
2695
2731
  checkLocked = true;
2696
- reduceFormUpdateValidityCalls(f.formControl, (/**
2697
- * @return {?}
2698
- */
2699
- function () { return _this.checkField(f, ignoreCache); }));
2732
+ _this.checkField(f, ignoreCache);
2700
2733
  checkLocked = false;
2701
2734
  }
2702
2735
  });
@@ -3498,22 +3531,7 @@ FieldFormExtension = /** @class */ (function () {
3498
3531
  if (field.parent) {
3499
3532
  return;
3500
3533
  }
3501
- /** @type {?} */
3502
- var fieldsToUpdate = this.setValidators(field);
3503
- if (fieldsToUpdate.length === 0) {
3504
- return;
3505
- }
3506
- if (fieldsToUpdate.length === 1) {
3507
- /** @type {?} */
3508
- var control = fieldsToUpdate[0].formControl;
3509
- while (control) {
3510
- ((/** @type {?} */ (control)))._updateTreeValidity({ onlySelf: true });
3511
- control = control.parent;
3512
- }
3513
- }
3514
- else {
3515
- ((/** @type {?} */ (field.formControl)))._updateTreeValidity();
3516
- }
3534
+ this.setValidators(field);
3517
3535
  };
3518
3536
  /**
3519
3537
  * @private
@@ -3554,39 +3572,39 @@ FieldFormExtension = /** @class */ (function () {
3554
3572
  /**
3555
3573
  * @private
3556
3574
  * @param {?} field
3575
+ * @param {?=} disabled
3557
3576
  * @return {?}
3558
3577
  */
3559
3578
  FieldFormExtension.prototype.setValidators = /**
3560
3579
  * @private
3561
3580
  * @param {?} field
3581
+ * @param {?=} disabled
3562
3582
  * @return {?}
3563
3583
  */
3564
- function (field) {
3584
+ function (field, disabled) {
3565
3585
  var _this = this;
3586
+ if (disabled === void 0) { disabled = false; }
3566
3587
  /** @type {?} */
3567
- var updateValidity$$1 = false;
3588
+ var markForCheck = false;
3589
+ if (disabled === false && field.key && field.templateOptions && field.templateOptions.disabled) {
3590
+ disabled = true;
3591
+ }
3592
+ (field.fieldGroup || []).forEach((/**
3593
+ * @param {?} f
3594
+ * @return {?}
3595
+ */
3596
+ function (f) { return _this.setValidators(f, disabled) && (markForCheck = true); }));
3568
3597
  if (field.key || !field.parent || (!field.key && !field.fieldGroup)) {
3569
3598
  var c_1 = field.formControl;
3570
- /** @type {?} */
3571
- var disabled = field.templateOptions ? field.templateOptions.disabled : false;
3572
- if (field.key && c_1) {
3599
+ field.templateOptions = field.templateOptions || {};
3600
+ if (field.key && c_1 && c_1 instanceof FormControl) {
3573
3601
  if (disabled && c_1.enabled) {
3574
3602
  c_1.disable({ emitEvent: false, onlySelf: true });
3575
- if (!c_1.parent) {
3576
- updateValidity(c_1);
3577
- }
3578
- else {
3579
- updateValidity$$1 = true;
3580
- }
3603
+ markForCheck = true;
3581
3604
  }
3582
3605
  if (!disabled && c_1.disabled) {
3583
3606
  c_1.enable({ emitEvent: false, onlySelf: true });
3584
- if (!c_1.parent) {
3585
- updateValidity(c_1);
3586
- }
3587
- else {
3588
- updateValidity$$1 = true;
3589
- }
3607
+ markForCheck = true;
3590
3608
  }
3591
3609
  }
3592
3610
  if (c_1 && (null === c_1.validator || null === c_1.asyncValidator)) {
@@ -3606,28 +3624,13 @@ FieldFormExtension = /** @class */ (function () {
3606
3624
  var v = Validators.composeAsync(_this.mergeValidators(field, '_asyncValidators'));
3607
3625
  return v ? v(c_1) : of(null);
3608
3626
  }));
3609
- if (!c_1.parent) {
3610
- updateValidity(c_1);
3611
- }
3612
- else {
3613
- updateValidity$$1 = true;
3614
- }
3627
+ markForCheck = true;
3615
3628
  }
3616
- }
3617
- /** @type {?} */
3618
- var fieldsToUpdate = updateValidity$$1 ? [field] : [];
3619
- (field.fieldGroup || []).forEach((/**
3620
- * @param {?} f
3621
- * @return {?}
3622
- */
3623
- function (f) {
3624
- /** @type {?} */
3625
- var childrenToUpdate = _this.setValidators(f);
3626
- if (!updateValidity$$1) {
3627
- fieldsToUpdate.push.apply(fieldsToUpdate, __spread(childrenToUpdate));
3629
+ if (markForCheck) {
3630
+ updateValidity(c_1, true);
3628
3631
  }
3629
- }));
3630
- return fieldsToUpdate;
3632
+ }
3633
+ return markForCheck;
3631
3634
  };
3632
3635
  /**
3633
3636
  * @private