tuain-ng-forms-lib 12.0.33 → 12.0.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.
@@ -1,8 +1,12 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('nanoid'), require('@angular/common'), require('@angular/router'), require('@angular/forms')) :
3
- typeof define === 'function' && define.amd ? define('tuain-ng-forms-lib', ['exports', '@angular/core', 'rxjs', 'nanoid', '@angular/common', '@angular/router', '@angular/forms'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['tuain-ng-forms-lib'] = {}, global.ng.core, global.rxjs, global.nanoid, global.ng.common, global.ng.router, global.ng.forms));
5
- }(this, (function (exports, core, rxjs, nanoid, common, router, forms) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('yn'), require('nanoid'), require('@angular/common'), require('@angular/router'), require('@angular/forms')) :
3
+ typeof define === 'function' && define.amd ? define('tuain-ng-forms-lib', ['exports', '@angular/core', 'rxjs', 'yn', 'nanoid', '@angular/common', '@angular/router', '@angular/forms'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['tuain-ng-forms-lib'] = {}, global.ng.core, global.rxjs, global.yn, global.nanoid, global.ng.common, global.ng.router, global.ng.forms));
5
+ }(this, (function (exports, core, rxjs, yn, nanoid, common, router, forms) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var yn__default = /*#__PURE__*/_interopDefaultLegacy(yn);
6
10
 
7
11
  var ActionComponent = /** @class */ (function () {
8
12
  function ActionComponent() {
@@ -384,7 +388,8 @@
384
388
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
385
389
  }
386
390
 
387
- var VALUE = '';
391
+ var VALUE = 'value';
392
+ var FOCUS = 'focus';
388
393
  var FieldComponent = /** @class */ (function () {
389
394
  function FieldComponent() {
390
395
  }
@@ -396,29 +401,35 @@
396
401
  // Inicialización
397
402
  var mapping = Object.entries(this.formConfig.componentFieldAttrMap);
398
403
  for (var index = 0; index < mapping.length; index++) {
399
- var _c = __read(mapping[index], 2), fieldAttr = _c[0], compAttr1 = _c[1];
404
+ var _c = __read(mapping[index], 2), fieldAttr1 = _c[0], compAttr1 = _c[1];
400
405
  var compAttr = compAttr1.toString();
401
- if (compAttr === VALUE) {
402
- this.updateValue();
403
- }
404
- else {
405
- this[compAttr] = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr.toString()];
406
- }
406
+ var fieldAttr = fieldAttr1.toString();
407
+ var attributeValue = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr];
408
+ this.dafaultProcessFieldChange(compAttr, attributeValue);
409
+ this.processFieldChange(compAttr, attributeValue);
407
410
  }
408
411
  // Subscripción a cambios en atributos
409
412
  this.field.attributeChange.subscribe(function (event) {
410
413
  var fieldAttr = event.name, value = event.value;
411
414
  var compAttr = _this.formConfig.componentFieldAttrMap[fieldAttr];
412
- if (compAttr === VALUE) {
413
- _this.updateValue();
414
- }
415
- else {
416
- _this[compAttr] = value;
417
- }
415
+ _this.dafaultProcessFieldChange(compAttr, value);
416
+ _this.processFieldChange(compAttr, value);
418
417
  });
419
418
  }
420
419
  this.start();
421
420
  };
421
+ FieldComponent.prototype.dafaultProcessFieldChange = function (attribute, value) {
422
+ if (attribute === VALUE) {
423
+ this.updateValue();
424
+ }
425
+ else if (attribute === FOCUS) {
426
+ this.focus();
427
+ }
428
+ else {
429
+ this[attribute] = value;
430
+ }
431
+ };
432
+ FieldComponent.prototype.processFieldChange = function (attribute, value) { };
422
433
  FieldComponent.prototype.start = function () { };
423
434
  FieldComponent.prototype.focus = function () { };
424
435
  FieldComponent.prototype.updateObject = function () {
@@ -656,7 +667,6 @@
656
667
  this._visibleForced = false;
657
668
  this.disabled = (_a = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.disabled) !== null && _a !== void 0 ? _a : false;
658
669
  this.setVisibility((_b = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.visible) !== null && _b !== void 0 ? _b : true);
659
- this.widget = null;
660
670
  this.customAttributes = (_c = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.customAttributes) !== null && _c !== void 0 ? _c : {};
661
671
  }
662
672
  FormElement.prototype.getCustomAttribute = function (name) { var _a, _b; return (_b = (_a = this.customAttributes) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null; };
@@ -1519,7 +1529,6 @@
1519
1529
  this.tableFieldStyles = this.formConfig.tableFieldStyles;
1520
1530
  this.selectable = this.table.selectable;
1521
1531
  this.hasActions = this.table.hasActions;
1522
- this.table.widget = this;
1523
1532
  this.inlineActions = this.table.getActions(this.formConfig.tableActions.inline);
1524
1533
  this.globalActions = this.table.getActions(this.formConfig.tableActions.global);
1525
1534
  this.selectionActions = this.table.getActions(this.formConfig.tableActions.selection);
@@ -1696,6 +1705,7 @@
1696
1705
  maxValue: '_maxValue',
1697
1706
  maxLength: '_maxLength',
1698
1707
  onValidation: '_onValidation',
1708
+ focus: 'focus',
1699
1709
  intrinsicErrorMessage: '_intrinsicErrorMessage',
1700
1710
  code: 'fieldCode',
1701
1711
  info: 'fieldInfo',
@@ -1799,6 +1809,7 @@
1799
1809
  enumerable: false,
1800
1810
  configurable: true
1801
1811
  });
1812
+ FieldDescriptor.prototype.focus = function () { this.setAttr(fldAttr.focus, true); };
1802
1813
  FieldDescriptor.prototype.setIntrinsicErrorMessage = function (message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); };
1803
1814
  Object.defineProperty(FieldDescriptor.prototype, "intrinsicErrorMessage", {
1804
1815
  set: function (message) { this.setIntrinsicErrorMessage(message); },
@@ -1853,6 +1864,14 @@
1853
1864
  this.setError('99', this._intrinsicErrorMessage);
1854
1865
  }
1855
1866
  }
1867
+ if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
1868
+ intrinsicValidation = false;
1869
+ this.setError('99', 'Campo con valor inferior al mínimo');
1870
+ }
1871
+ if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
1872
+ intrinsicValidation = false;
1873
+ this.setError('99', 'Campo con valor superior al máximo');
1874
+ }
1856
1875
  this._editionFinish.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
1857
1876
  };
1858
1877
  FieldDescriptor.prototype.setAttr = function (name, value) {
@@ -1919,7 +1938,7 @@
1919
1938
  FieldDescriptor.prototype.getValue = function () {
1920
1939
  if (this.fieldType === this._formConfig.fieldTypes.boolean
1921
1940
  || this.fieldType === this._formConfig.fieldTypes.check) {
1922
- return !!this._value;
1941
+ return yn__default['default'](this._value);
1923
1942
  }
1924
1943
  return this._value;
1925
1944
  };
@@ -1948,40 +1967,26 @@
1948
1967
  FieldDescriptor.prototype.setFieldType = function (inputFieldType) {
1949
1968
  this.setAttr(fldAttr.type, inputFieldType);
1950
1969
  };
1951
- FieldDescriptor.prototype.setMinValue = function (minValue) {
1952
- var _a, _b, _c;
1953
- if (this.fieldType === this._formConfig.fieldTypes.date
1954
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMinValue)) {
1955
- this.setAttr(fldAttr.minValue, minValue);
1956
- if (!minValue) {
1957
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
1958
- }
1959
- else {
1960
- var minDate = new Date(minValue);
1961
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMinValue(minDate);
1962
- }
1970
+ FieldDescriptor.prototype.setMinValue = function (inputMinValue) {
1971
+ var minValue = inputMinValue;
1972
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1973
+ minValue = new Date(minValue);
1963
1974
  }
1975
+ this.setAttr(fldAttr.minValue, minValue);
1964
1976
  };
1965
- FieldDescriptor.prototype.setMaxValue = function (maxValue) {
1966
- var _a, _b, _c;
1967
- if (this.fieldType === this._formConfig.fieldTypes.date
1968
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMaxValue)) {
1969
- this.setAttr(fldAttr.maxValue, maxValue);
1970
- if (!maxValue) {
1971
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
1972
- }
1973
- else {
1974
- var maxDate = new Date(maxValue);
1975
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMaxValue(maxDate);
1976
- }
1977
+ FieldDescriptor.prototype.setMaxValue = function (inputMaxValue) {
1978
+ var maxValue = inputMaxValue;
1979
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1980
+ maxValue = new Date(maxValue);
1977
1981
  }
1982
+ this.setAttr(fldAttr.maxValue, maxValue);
1978
1983
  };
1979
1984
  FieldDescriptor.prototype.getFieldOptions = function () {
1980
1985
  return JSON.parse(JSON.stringify(this.fieldOptions));
1981
1986
  };
1982
1987
  FieldDescriptor.prototype.setFieldOptions = function (newOptions) {
1983
1988
  var _this = this;
1984
- var _a, _b, _c, _d;
1989
+ var _a;
1985
1990
  if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
1986
1991
  || typeof newOptions === UNDEFINED || !newOptions
1987
1992
  || !Array.isArray(newOptions)) {
@@ -1997,12 +2002,9 @@
1997
2002
  fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
1998
2003
  && fieldOptions.length > 0) ? fieldOptions : [];
1999
2004
  this.setAttr(fldAttr.options, fieldOptions);
2000
- if (this.fieldType === this._formConfig.fieldTypes.array && this.widget) {
2001
- return (_a = this.widget) === null || _a === void 0 ? void 0 : _a.refereshContent();
2002
- }
2003
2005
  if (this._value) {
2004
2006
  if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
2005
- var fieldValue = (_b = this._value) === null || _b === void 0 ? void 0 : _b.filter(function (item) { return _this.fieldOptions.find(function (opt) { return opt.fieldOptionId === item; }); });
2007
+ var fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return _this.fieldOptions.find(function (opt) { return opt.fieldOptionId === item; }); });
2006
2008
  this.setAttr(fldAttr.value, fieldValue);
2007
2009
  }
2008
2010
  else {
@@ -2015,57 +2017,41 @@
2015
2017
  }
2016
2018
  if (this.fieldRequired && this.fieldOptions.length === 1) {
2017
2019
  this.setValue(this.fieldOptions[0].fieldOptionId);
2018
- if ((_c = this.widget) === null || _c === void 0 ? void 0 : _c.onChangeContent) {
2019
- (_d = this.widget) === null || _d === void 0 ? void 0 : _d.onChangeContent();
2020
- }
2021
2020
  }
2022
2021
  };
2023
2022
  FieldDescriptor.prototype.setValue = function (newValue, widgetUpdate) {
2024
2023
  if (widgetUpdate === void 0) { widgetUpdate = true; }
2025
- var _a;
2026
2024
  if (typeof newValue === UNDEFINED || newValue === null) {
2027
2025
  return true;
2028
2026
  }
2029
2027
  var newFinalValue;
2030
- switch (this.fieldType) {
2031
- case 'BOOLEAN':
2032
- newFinalValue = !!newValue;
2033
- break;
2034
- case this._formConfig.fieldTypes.boolean:
2035
- newFinalValue = !!newValue;
2036
- break;
2037
- case this._formConfig.fieldTypes.check:
2038
- newFinalValue = !!newValue;
2039
- break;
2040
- case this._formConfig.fieldTypes.array:
2041
- if (newValue === null || newValue === '') {
2042
- newFinalValue = [];
2043
- }
2044
- else if (!Array.isArray(newValue)) {
2045
- if (typeof (newValue) !== 'string') {
2046
- newValue = newValue.toString();
2047
- }
2048
- newFinalValue = newValue.split(',');
2049
- }
2050
- else {
2051
- newFinalValue = newValue;
2052
- }
2053
- break;
2054
- case this._formConfig.fieldTypes.map:
2055
- newFinalValue = newValue;
2056
- if (newFinalValue && this.widget && widgetUpdate) {
2057
- var latitude = parseFloat(newFinalValue[0]);
2058
- var longitude = parseFloat(newFinalValue[1]);
2059
- (_a = this.widget) === null || _a === void 0 ? void 0 : _a.setLocation(latitude, longitude);
2060
- }
2061
- break;
2062
- default:
2028
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
2029
+ || this.fieldType === this._formConfig.fieldTypes.check) {
2030
+ newFinalValue = yn__default['default'](newValue);
2031
+ }
2032
+ else if (this.fieldType === this._formConfig.fieldTypes.array
2033
+ || this.fieldType === this._formConfig.fieldTypes.map) {
2034
+ if (newValue === null || newValue === '') {
2035
+ newFinalValue = [];
2036
+ }
2037
+ else if (Array.isArray(newValue)) {
2063
2038
  newFinalValue = newValue;
2064
- break;
2039
+ }
2040
+ else {
2041
+ newFinalValue = newValue.toString().split(',');
2042
+ }
2043
+ }
2044
+ else {
2045
+ newFinalValue = newValue;
2065
2046
  }
2066
2047
  if (this._value !== newFinalValue) {
2067
2048
  this.setChanged(true);
2068
- this.setAttr(fldAttr.value, newFinalValue);
2049
+ if (widgetUpdate) {
2050
+ this.setAttr(fldAttr.value, newFinalValue);
2051
+ }
2052
+ else {
2053
+ this._value = newFinalValue;
2054
+ }
2069
2055
  }
2070
2056
  return true;
2071
2057
  };
@@ -4922,11 +4908,8 @@
4922
4908
  for (var requiredEmptyFields_1 = __values(requiredEmptyFields), requiredEmptyFields_1_1 = requiredEmptyFields_1.next(); !requiredEmptyFields_1_1.done; requiredEmptyFields_1_1 = requiredEmptyFields_1.next()) {
4923
4909
  var fieldCode = requiredEmptyFields_1_1.value;
4924
4910
  var requiredEmptyField = this.getField(fieldCode);
4925
- if (requiredEmptyField && requiredEmptyField.widget
4926
- && requiredEmptyField.widget.focus) {
4927
- requiredEmptyField.widget.focus();
4928
- break;
4929
- }
4911
+ requiredEmptyField === null || requiredEmptyField === void 0 ? void 0 : requiredEmptyField.focus();
4912
+ break;
4930
4913
  }
4931
4914
  }
4932
4915
  catch (e_21_1) { e_21 = { error: e_21_1 }; }
@@ -4945,11 +4928,8 @@
4945
4928
  for (var validationIssueFields_1 = __values(validationIssueFields), validationIssueFields_1_1 = validationIssueFields_1.next(); !validationIssueFields_1_1.done; validationIssueFields_1_1 = validationIssueFields_1.next()) {
4946
4929
  var fieldCode = validationIssueFields_1_1.value;
4947
4930
  var validationIssueField = this.getField(fieldCode);
4948
- if (validationIssueField && validationIssueField.widget
4949
- && validationIssueField.widget.focus) {
4950
- validationIssueField.widget.focus();
4951
- break;
4952
- }
4931
+ validationIssueField.focus();
4932
+ break;
4953
4933
  }
4954
4934
  }
4955
4935
  catch (e_22_1) { e_22 = { error: e_22_1 }; }