@klippa/ngx-enhancy-forms 7.1.6 → 7.3.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.
@@ -32,7 +32,7 @@
32
32
  return s.substring(0, length) + '...';
33
33
  }
34
34
  function arrayIsSetAndFilled(arr) {
35
- return arr !== null && arr !== undefined && arr.length > 0;
35
+ return Array.isArray(arr) && arr !== null && arr !== undefined && arr.length > 0;
36
36
  }
37
37
 
38
38
  var invalidFieldsSymbol = Symbol('Not all fields are valid');
@@ -340,6 +340,7 @@
340
340
  this.controlContainer = controlContainer;
341
341
  this.changed = new Array();
342
342
  this.touched = new Array();
343
+ this.prevValue = null;
343
344
  this.disabled = false;
344
345
  // we support both providing just the formControlName and the full formControl
345
346
  this.formControlName = null;
@@ -390,6 +391,7 @@
390
391
  };
391
392
  ValueAccessorBase.prototype.writeValue = function (value) {
392
393
  this.innerValue = value;
394
+ this.prevValue = value;
393
395
  };
394
396
  ValueAccessorBase.prototype.registerOnChange = function (fn) {
395
397
  this.changed.push(fn);
@@ -398,8 +400,34 @@
398
400
  this.touched.push(fn);
399
401
  };
400
402
  ValueAccessorBase.prototype.setInnerValueAndNotify = function (value) {
401
- this.innerValue = value;
402
- this.changed.forEach(function (fn) { return fn(value); });
403
+ var _this = this;
404
+ var actuallySetValue = function (valueToSet) {
405
+ _this.innerValue = valueToSet;
406
+ _this.prevValue = valueToSet;
407
+ _this.changed.forEach(function (fn) { return fn(valueToSet); });
408
+ };
409
+ if (isValueSet(this.innerValueChangeInterceptor)) {
410
+ this.latestInnerValueChangedInterceptorPromise = this.innerValueChangeInterceptor();
411
+ var myPromise_1 = this.latestInnerValueChangedInterceptorPromise;
412
+ this.latestInnerValueChangedInterceptorPromise.then(function () {
413
+ if (_this.latestInnerValueChangedInterceptorPromise === myPromise_1) {
414
+ actuallySetValue(value);
415
+ }
416
+ else {
417
+ // ignore outdated promises
418
+ }
419
+ }).catch(function () {
420
+ if (_this.latestInnerValueChangedInterceptorPromise === myPromise_1) {
421
+ actuallySetValue(_this.prevValue);
422
+ }
423
+ else {
424
+ // ignore outdated promises
425
+ }
426
+ });
427
+ }
428
+ else {
429
+ actuallySetValue(value);
430
+ }
403
431
  };
404
432
  ValueAccessorBase.prototype.resetToNull = function () {
405
433
  this.setInnerValueAndNotify(null);
@@ -424,6 +452,7 @@
424
452
  ]; };
425
453
  ValueAccessorBase.propDecorators = {
426
454
  disabled: [{ type: core.Input }],
455
+ innerValueChangeInterceptor: [{ type: core.Input }],
427
456
  formControlName: [{ type: core.Input }],
428
457
  formControl: [{ type: core.Input }],
429
458
  onTouch: [{ type: core.Output }]
@@ -1479,8 +1508,8 @@
1479
1508
  if (this.multiple) {
1480
1509
  this.datePickerRef.close = function () {
1481
1510
  };
1482
- if (this.selectedDates.some(function (e) { return e.getTime() === date.getTime(); })) {
1483
- this.selectedDates = this.selectedDates.filter(function (e) { return e.getTime() !== date.getTime(); });
1511
+ if (this.selectedDates.some(function (e) { return dateFns.isSameDay(e, date); })) {
1512
+ this.selectedDates = this.selectedDates.filter(function (e) { return !dateFns.isSameDay(e, date); });
1484
1513
  }
1485
1514
  else {
1486
1515
  this.selectedDates = __spread(this.selectedDates, [date]);
@@ -1720,6 +1749,57 @@
1720
1749
  },] }
1721
1750
  ];
1722
1751
 
1752
+ var FileInputComponent = /** @class */ (function (_super) {
1753
+ __extends(FileInputComponent, _super);
1754
+ function FileInputComponent() {
1755
+ var _this = _super.apply(this, __spread(arguments)) || this;
1756
+ _this.isLoading = false;
1757
+ _this.clearable = false;
1758
+ return _this;
1759
+ }
1760
+ FileInputComponent.prototype.onChange = function (files) {
1761
+ var result = [];
1762
+ for (var i = 0; i < files.length; i++) {
1763
+ result.push(files.item(i));
1764
+ }
1765
+ this.setInnerValueAndNotify(result);
1766
+ };
1767
+ FileInputComponent.prototype.getFileNames = function () {
1768
+ if (Array.isArray(this.innerValue)) {
1769
+ return this.innerValue.map(function (e) { return e.name; }).join(', ');
1770
+ }
1771
+ else if (this.innerValue instanceof File) {
1772
+ return this.innerValue.name;
1773
+ }
1774
+ return null;
1775
+ };
1776
+ FileInputComponent.prototype.shouldShowClearButton = function () {
1777
+ if (this.multiple) {
1778
+ if (arrayIsSetAndFilled(this.innerValue)) {
1779
+ return true;
1780
+ }
1781
+ return false;
1782
+ }
1783
+ if (isValueSet(this.innerValue)) {
1784
+ return true;
1785
+ }
1786
+ return false;
1787
+ };
1788
+ return FileInputComponent;
1789
+ }(MultipleValueAccessorBase));
1790
+ FileInputComponent.decorators = [
1791
+ { type: core.Component, args: [{
1792
+ selector: 'klp-form-file-input',
1793
+ template: "<div class=\"componentContainer\">\n\t<klp-form-button class=\"uploadButton\" [isLoading]=\"isLoading\">\n\t\tUpload a file\n\t\t<input type=\"file\" (change)=\"onChange($event.target.files)\" [multiple]=\"multiple\">\n\t</klp-form-button>\n\t<div class=\"fileName\">\n\t\t{{getFileNames()}}\n\t</div>\n\t<klp-form-button class=\"clearButton\" variant=\"white\" *ngIf=\"shouldShowClearButton()\" (click)=\"resetToNull()\">X</klp-form-button>\n</div>\n",
1794
+ providers: [{ provide: forms.NG_VALUE_ACCESSOR, useExisting: FileInputComponent, multi: true }],
1795
+ styles: [":host{display:block}:host input:disabled{cursor:not-allowed}.componentContainer{align-items:center;display:flex}.uploadButton{flex:0 0 auto;position:relative}.uploadButton input{bottom:0;cursor:pointer;left:0;opacity:0;position:absolute;right:0;top:0}.fileName{color:#515365;flex:1 1 0px;margin-left:.625rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.clearButton{flex:0 0 auto}"]
1796
+ },] }
1797
+ ];
1798
+ FileInputComponent.propDecorators = {
1799
+ isLoading: [{ type: core.Input }],
1800
+ clearable: [{ type: core.Input }]
1801
+ };
1802
+
1723
1803
  var NgxEnhancyFormsModule = /** @class */ (function () {
1724
1804
  function NgxEnhancyFormsModule() {
1725
1805
  }
@@ -1750,6 +1830,7 @@
1750
1830
  SortableItemsComponent,
1751
1831
  TextInputComponent,
1752
1832
  ToggleComponent,
1833
+ FileInputComponent,
1753
1834
  FormCaptionComponent,
1754
1835
  FormElementComponent,
1755
1836
  FormErrorComponent,
@@ -1773,6 +1854,7 @@
1773
1854
  SortableItemsComponent,
1774
1855
  TextInputComponent,
1775
1856
  ToggleComponent,
1857
+ FileInputComponent,
1776
1858
  FormCaptionComponent,
1777
1859
  FormElementComponent,
1778
1860
  FormErrorComponent,
@@ -1801,6 +1883,7 @@
1801
1883
  exports.DateTimePickerComponent = DateTimePickerComponent;
1802
1884
  exports.EmailInputComponent = EmailInputComponent;
1803
1885
  exports.FORM_ERROR_MESSAGES = FORM_ERROR_MESSAGES;
1886
+ exports.FileInputComponent = FileInputComponent;
1804
1887
  exports.FormCaptionComponent = FormCaptionComponent;
1805
1888
  exports.FormComponent = FormComponent;
1806
1889
  exports.FormElementComponent = FormElementComponent;