@sumaris-net/ngx-components 1.23.37 → 1.23.40

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.
@@ -4174,7 +4174,7 @@
4174
4174
  control.disable(opts);
4175
4175
  });
4176
4176
  }
4177
- function addValueInArray(arrayControl, createControl, equals, isEmpty, value, options) {
4177
+ function pushValueInArray(arrayControl, createControl, equals, isEmpty, value, options) {
4178
4178
  options = options || { emitEvent: true };
4179
4179
  var hasChanged = false;
4180
4180
  var index = -1;
@@ -4208,6 +4208,25 @@
4208
4208
  }
4209
4209
  return hasChanged;
4210
4210
  }
4211
+ /**
4212
+ * Patch an array using given default values. Each default value will be pass to the 'createControl()' function
4213
+ * @param arrayControl
4214
+ * @param createControl
4215
+ * @param values
4216
+ */
4217
+ function patchValueInArray(arrayControl, createControl, defaultValues) {
4218
+ var hasChanged = false;
4219
+ while (arrayControl.length > 0) {
4220
+ arrayControl.removeAt(arrayControl.length - 1);
4221
+ hasChanged = true;
4222
+ }
4223
+ (defaultValues || []).forEach(function (value) {
4224
+ var control = createControl(value);
4225
+ arrayControl.push(control);
4226
+ hasChanged = true;
4227
+ });
4228
+ return hasChanged;
4229
+ }
4211
4230
  function resizeArray(arrayControl, createControl, length) {
4212
4231
  var hasChanged = arrayControl.length !== length;
4213
4232
  // Increase size
@@ -4524,6 +4543,10 @@
4524
4543
  this.equals = equals;
4525
4544
  this.isEmpty = isEmpty;
4526
4545
  this._validators = options && options.validators;
4546
+ // Register into the form array
4547
+ if (options === null || options === void 0 ? void 0 : options.helperProperty) {
4548
+ _formArray[FormArrayHelper.FORMA_HELPER_PROPERTY] = this;
4549
+ }
4527
4550
  // empty array not allow by default
4528
4551
  this.setAllowEmptyArray(toBoolean(options && options.allowEmptyArray, false));
4529
4552
  }
@@ -4535,6 +4558,9 @@
4535
4558
  }
4536
4559
  return arrayControl;
4537
4560
  };
4561
+ FormArrayHelper.hasHelper = function (formArray) {
4562
+ return formArray && !!formArray[this.FORMA_HELPER_PROPERTY];
4563
+ };
4538
4564
  Object.defineProperty(FormArrayHelper.prototype, "allowEmptyArray", {
4539
4565
  get: function () {
4540
4566
  return this._allowEmptyArray;
@@ -4552,9 +4578,17 @@
4552
4578
  enumerable: false,
4553
4579
  configurable: true
4554
4580
  });
4581
+ /**
4582
+ * @param value
4583
+ * @param options
4584
+ * @deprecated Use push() instead
4585
+ */
4555
4586
  FormArrayHelper.prototype.add = function (value, options) {
4587
+ return pushValueInArray(this._formArray, this.createControl, this.equals, this.isEmpty, value, options);
4588
+ };
4589
+ FormArrayHelper.prototype.push = function (value, options) {
4556
4590
  var _this = this;
4557
- return addValueInArray(this._formArray, function () { return _this.createControl(value); }, this.equals, this.isEmpty, value, options);
4591
+ return pushValueInArray(this._formArray, function () { return _this.createControl(value); }, this.equals, this.isEmpty, value, options);
4558
4592
  };
4559
4593
  FormArrayHelper.prototype.removeAt = function (index) {
4560
4594
  // Do not remove if last criterion
@@ -4589,27 +4623,13 @@
4589
4623
  return this._formArray.at(index);
4590
4624
  };
4591
4625
  /**
4592
- * Resize the FormArray, then set values
4593
- * @param values
4594
- * @param opts
4595
- */
4596
- FormArrayHelper.prototype.setValue = function (values, opts) {
4597
- var _this = this;
4598
- this.resize(0);
4599
- var emitEvent = (!opts || (opts === null || opts === void 0 ? void 0 : opts.emitEvent) !== false);
4600
- (values || []).forEach(function (value, i) {
4601
- var last = (i === values.length - 1);
4602
- _this.add(value, { emitEvent: last && emitEvent });
4603
- });
4604
- };
4605
- /**
4606
- * Resize the FormArray, then patch values
4607
- * @param data
4626
+ * Patch a FormArray, using default values
4627
+ * @param values default values to apply.
4608
4628
  * @param opts
4629
+ * @return true if form arry has been changed
4609
4630
  */
4610
- FormArrayHelper.prototype.patchValue = function (data, opts) {
4611
- this.resize((data === null || data === void 0 ? void 0 : data.length) || 0);
4612
- this._formArray.patchValue(data, opts);
4631
+ FormArrayHelper.prototype.patchValue = function (values) {
4632
+ return patchValueInArray(this._formArray, this.createControl, values);
4613
4633
  };
4614
4634
  FormArrayHelper.prototype.disable = function (opts) {
4615
4635
  this._formArray.controls.forEach(function (c) { return c.disable(opts); });
@@ -4640,6 +4660,7 @@
4640
4660
  };
4641
4661
  return FormArrayHelper;
4642
4662
  }());
4663
+ FormArrayHelper.FORMA_HELPER_PROPERTY = '_helper';
4643
4664
  // TODO continue to use this kind of declaration ?
4644
4665
  var AppFormUtils = /** @class */ (function () {
4645
4666
  function AppFormUtils() {
@@ -4673,7 +4694,7 @@
4673
4694
  AppFormUtils.updateValueAndValidity = updateValueAndValidity;
4674
4695
  AppFormUtils.getFormErrors = getFormErrors;
4675
4696
  // ArrayForm
4676
- AppFormUtils.addValueInArray = addValueInArray;
4697
+ AppFormUtils.addValueInArray = pushValueInArray;
4677
4698
  AppFormUtils.removeValueInArray = removeValueInArray;
4678
4699
  AppFormUtils.resizeArray = resizeArray;
4679
4700
  AppFormUtils.clearValueInArray = clearValueInArray;
@@ -35603,7 +35624,6 @@
35603
35624
  exports.UsersPage = UsersPage;
35604
35625
  exports.accountToString = accountToString;
35605
35626
  exports.adaptValueToControl = adaptValueToControl;
35606
- exports.addValueInArray = addValueInArray;
35607
35627
  exports.arrayDistinct = arrayDistinct;
35608
35628
  exports.arrayGroupBy = arrayGroupBy;
35609
35629
  exports.arraySize = arraySize;
@@ -35703,9 +35723,11 @@
35703
35723
  exports.notNilOrDefault = notNilOrDefault;
35704
35724
  exports.nullIfUndefined = nullIfUndefined;
35705
35725
  exports.parseLatitudeOrLongitude = parseLatitudeOrLongitude;
35726
+ exports.patchValueInArray = patchValueInArray;
35706
35727
  exports.propertiesPathComparator = propertiesPathComparator;
35707
35728
  exports.propertyComparator = propertyComparator;
35708
35729
  exports.propertyPathComparator = propertyPathComparator;
35730
+ exports.pushValueInArray = pushValueInArray;
35709
35731
  exports.referentialToString = referentialToString;
35710
35732
  exports.referentialsToString = referentialsToString;
35711
35733
  exports.remove = remove;