@sumaris-net/ngx-components 2.4.115 → 2.4.116

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.
@@ -75,7 +75,6 @@ import * as i10 from '@angular/material/datepicker';
75
75
  import { MatDatepickerModule } from '@angular/material/datepicker';
76
76
  import * as i12$1 from 'ngx-material-timepicker';
77
77
  import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
78
- import { isMoment as isMoment$1 } from 'moment/moment';
79
78
  import { trigger, state, style, transition, animate } from '@angular/animations';
80
79
  import * as i18 from '@angular/material/divider';
81
80
  import { MatDividerModule } from '@angular/material/divider';
@@ -4114,34 +4113,46 @@ function adaptValueToControl(source, control, path) {
4114
4113
  source = source.split('|');
4115
4114
  }
4116
4115
  // Skip if value is not an array
4117
- if (!Array.isArray(source) || control.length === 0) {
4118
- if (isNotEmptyArray(source))
4119
- console.warn(`WARN: please resize the FormArray '${path}' to the same length of the input array`);
4116
+ if (!Array.isArray(source)) {
4120
4117
  return [];
4121
4118
  }
4122
- // Use the first form group, as model
4123
- const firstItemControl = control.at(0);
4124
- let result = source.map((item, index) => adaptValueToControl(item, firstItemControl, pathPrefix + '#' + index));
4125
- // Truncate if too many values
4126
- if (result.length > control.length) {
4127
- if (firstItemControl instanceof UntypedFormControl) {
4128
- for (let i = control.length; i < result.length; i++) {
4129
- control.push(new UntypedFormControl(null, firstItemControl.validator));
4119
+ // Resizable array
4120
+ if (control instanceof AppFormArray) {
4121
+ const exampleControl = control.createControl();
4122
+ return source.map((item, index) => adaptValueToControl(item, exampleControl, pathPrefix + '#' + index));
4123
+ }
4124
+ // Legacy array
4125
+ else if (control.length > 0) {
4126
+ const firstControl = control.at(0);
4127
+ // Use the first form group, as model
4128
+ let result = source.map((item, index) => adaptValueToControl(item, firstControl, pathPrefix + '#' + index));
4129
+ // Truncate if too many values
4130
+ if (result.length > control.length) {
4131
+ if (firstControl instanceof UntypedFormControl) {
4132
+ for (let i = control.length; i < result.length; i++) {
4133
+ control.push(new UntypedFormControl(null, firstControl.validator));
4134
+ }
4135
+ }
4136
+ else {
4137
+ console.warn(`WARN: please resize the FormArray '${path || ''}' to the same length of the input array`);
4138
+ result = result.slice(0, control.length);
4130
4139
  }
4131
4140
  }
4132
- else {
4133
- console.warn(`WARN: please resize the FormArray '${path || ''}' to the same length of the input array`);
4134
- result = result.slice(0, control.length);
4141
+ // Add values if not enought
4142
+ else if (result.length < control.length) {
4143
+ //console.warn(`WARN: Adding null value to array values`);
4144
+ for (let i = result.length; i < control.length; i++) {
4145
+ result.push(null);
4146
+ }
4135
4147
  }
4148
+ return result;
4136
4149
  }
4137
- // Add values if not enought
4138
- else if (result.length < control.length) {
4139
- //console.warn(`WARN: Adding null value to array values`);
4140
- for (let i = result.length; i < control.length; i++) {
4141
- result.push(null);
4142
- }
4150
+ // Skip if unable to find a control in the array
4151
+ else {
4152
+ if (isNotEmptyArray(source))
4153
+ console.warn(`WARN: please resize the FormArray '${path}' to the same length of the input array`);
4154
+ return [];
4143
4155
  }
4144
- return result;
4145
4156
  }
4146
4157
  // Form control
4147
4158
  if (control instanceof UntypedFormControl) {
@@ -4309,7 +4320,8 @@ function addValueInArray(arrayControl, createControl, equals, isEmpty, value, op
4309
4320
  * Set an array using given default values. Each default value will be pass to the 'createControl()' function
4310
4321
  * @param arrayControl
4311
4322
  * @param createControl
4312
- * @param values
4323
+ * @param defaultValues
4324
+ * @param options
4313
4325
  */
4314
4326
  function initArrayControlsFromValues(arrayControl, createControl, defaultValues, options) {
4315
4327
  if (arrayControl.length === 0 && (!defaultValues || defaultValues.length === 0))
@@ -7051,7 +7063,7 @@ class MatDateShort {
7051
7063
  //console.debug("[mat-date] writeValue() with:", value);
7052
7064
  // Convert into date
7053
7065
  // Important: clone, because startOf will update the existing date
7054
- const date = isMoment$1(value) ? value.clone() : fromDateISOString(value);
7066
+ const date = isMoment(value) ? value.clone() : fromDateISOString(value);
7055
7067
  if (!date || !date.isValid()) {
7056
7068
  this.textControl.patchValue(null, { emitEvent: false });
7057
7069
  if (this.formControl.value) {
@@ -7118,7 +7130,7 @@ class MatDateShort {
7118
7130
  /* -- protected methods -- */
7119
7131
  _onDatePickerChange(event) {
7120
7132
  // Make sure event is valid
7121
- if (!event || (event.value !== null && !isMoment$1(event.value))) {
7133
+ if (!event || (event.value !== null && !isMoment(event.value))) {
7122
7134
  console.warn('Invalid MatDatepicker event. Skipping', event);
7123
7135
  return; // Skip
7124
7136
  }