tuain-ng-forms-lib 12.0.31 → 12.0.37

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() {
@@ -36,7 +40,7 @@
36
40
  Object.defineProperty(ActionComponent.prototype, "visible", {
37
41
  get: function () {
38
42
  var _a;
39
- return ((_a = this.action) === null || _a === void 0 ? void 0 : _a.visibleOn(this.currentState)) && this.visibleOnRestriction();
43
+ return ((_a = this.action) === null || _a === void 0 ? void 0 : _a.visibleOn(this.state)) && this.visibleOnRestriction();
40
44
  },
41
45
  enumerable: false,
42
46
  configurable: true
@@ -44,7 +48,7 @@
44
48
  Object.defineProperty(ActionComponent.prototype, "disabled", {
45
49
  get: function () {
46
50
  var _a;
47
- return !((_a = this.action) === null || _a === void 0 ? void 0 : _a.enabledOn(this.currentState));
51
+ return !((_a = this.action) === null || _a === void 0 ? void 0 : _a.enabledOn(this.state));
48
52
  },
49
53
  enumerable: false,
50
54
  configurable: true
@@ -61,7 +65,7 @@
61
65
  action: [{ type: core.Input }],
62
66
  busy: [{ type: core.Input }],
63
67
  relatedField: [{ type: core.Input }],
64
- currentState: [{ type: core.Input }],
68
+ state: [{ type: core.Input }],
65
69
  style: [{ type: core.Input }],
66
70
  showLabel: [{ type: core.Input }]
67
71
  };
@@ -390,50 +394,52 @@
390
394
  }
391
395
  FieldComponent.prototype.ngOnInit = function () {
392
396
  var _this = this;
393
- var _a, _b;
397
+ var _a, _b, _c;
394
398
  if (this.field) {
395
399
  this.formConfig = (_a = this.field) === null || _a === void 0 ? void 0 : _a._formConfig;
396
400
  // Inicialización
397
401
  var mapping = Object.entries(this.formConfig.componentFieldAttrMap);
398
402
  for (var index = 0; index < mapping.length; index++) {
399
- var _c = __read(mapping[index], 2), fieldAttr = _c[0], compAttr1 = _c[1];
403
+ var _d = __read(mapping[index], 2), fieldAttr1 = _d[0], compAttr1 = _d[1];
400
404
  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
- }
405
+ var fieldAttr = fieldAttr1.toString();
406
+ this.dafaultProcessFieldChange(compAttr, (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr]);
407
+ this.processFieldChange(compAttr, (_c = this.field) === null || _c === void 0 ? void 0 : _c[fieldAttr]);
407
408
  }
408
409
  // Subscripción a cambios en atributos
409
410
  this.field.attributeChange.subscribe(function (event) {
410
411
  var fieldAttr = event.name, value = event.value;
411
412
  var compAttr = _this.formConfig.componentFieldAttrMap[fieldAttr];
412
- if (compAttr === VALUE) {
413
- _this.updateValue();
414
- }
415
- else {
416
- _this[compAttr] = value;
417
- }
413
+ _this.dafaultProcessFieldChange(compAttr, value);
414
+ _this.processFieldChange(compAttr, value);
418
415
  });
419
416
  }
420
417
  this.start();
421
418
  };
419
+ FieldComponent.prototype.dafaultProcessFieldChange = function (attribute, value) {
420
+ if (attribute === VALUE) {
421
+ this.updateValue();
422
+ }
423
+ else {
424
+ this[attribute] = value;
425
+ }
426
+ };
427
+ FieldComponent.prototype.processFieldChange = function (attribute, value) { };
422
428
  FieldComponent.prototype.start = function () { };
423
429
  FieldComponent.prototype.focus = function () { };
424
430
  FieldComponent.prototype.updateObject = function () {
425
- this.field._fieldValue = this.value;
431
+ this.field.setValue(this.value);
426
432
  };
427
433
  FieldComponent.prototype.inputChanged = function () {
428
- this.field._fieldValue = this.value;
434
+ this.field.setValue(this.value);
429
435
  this.onChangeContent();
430
436
  };
431
437
  FieldComponent.prototype.inputTyped = function () {
432
- this.field._fieldValue = this.value;
438
+ this.field.setValue(this.value);
433
439
  this.onInputChange();
434
440
  };
435
441
  FieldComponent.prototype.updateValue = function () {
436
- this.value = this.field._fieldValue;
442
+ this.value = this.field.getValue();
437
443
  };
438
444
  FieldComponent.prototype.onInputChange = function () {
439
445
  var _this = this;
@@ -454,7 +460,7 @@
454
460
  Object.defineProperty(FieldComponent.prototype, "visible", {
455
461
  get: function () {
456
462
  var _a;
457
- return (_a = this.field) === null || _a === void 0 ? void 0 : _a.visibleOn(this.currentState);
463
+ return (_a = this.field) === null || _a === void 0 ? void 0 : _a.visibleOn(this.state);
458
464
  },
459
465
  enumerable: false,
460
466
  configurable: true
@@ -462,7 +468,7 @@
462
468
  Object.defineProperty(FieldComponent.prototype, "disabled", {
463
469
  get: function () {
464
470
  var _a;
465
- return !((_a = this.field) === null || _a === void 0 ? void 0 : _a.enabledOn(this.currentState));
471
+ return !((_a = this.field) === null || _a === void 0 ? void 0 : _a.enabledOn(this.state));
466
472
  },
467
473
  enumerable: false,
468
474
  configurable: true
@@ -477,7 +483,7 @@
477
483
  ];
478
484
  FieldComponent.propDecorators = {
479
485
  field: [{ type: core.Input }],
480
- currentState: [{ type: core.Input }]
486
+ state: [{ type: core.Input }]
481
487
  };
482
488
 
483
489
  var ElementComponent = /** @class */ (function () {
@@ -492,7 +498,7 @@
492
498
  Object.defineProperty(ElementComponent.prototype, "visible", {
493
499
  get: function () {
494
500
  var _a;
495
- return (_a = this.element) === null || _a === void 0 ? void 0 : _a.visibleOn(this.currentState);
501
+ return (_a = this.element) === null || _a === void 0 ? void 0 : _a.visibleOn(this.state);
496
502
  },
497
503
  enumerable: false,
498
504
  configurable: true
@@ -500,7 +506,7 @@
500
506
  Object.defineProperty(ElementComponent.prototype, "disabled", {
501
507
  get: function () {
502
508
  var _a;
503
- return !((_a = this.element) === null || _a === void 0 ? void 0 : _a.enabledOn(this.currentState));
509
+ return !((_a = this.element) === null || _a === void 0 ? void 0 : _a.enabledOn(this.state));
504
510
  },
505
511
  enumerable: false,
506
512
  configurable: true
@@ -516,7 +522,7 @@
516
522
  ElementComponent.propDecorators = {
517
523
  element: [{ type: core.Input }],
518
524
  form: [{ type: core.Input }],
519
- currentState: [{ type: core.Input }]
525
+ state: [{ type: core.Input }]
520
526
  };
521
527
 
522
528
  var FormErrorComponent = /** @class */ (function () {
@@ -1638,7 +1644,7 @@
1638
1644
  table: [{ type: core.Input }],
1639
1645
  tableRecords: [{ type: core.Input }],
1640
1646
  disabled: [{ type: core.Input }],
1641
- currentState: [{ type: core.Input }],
1647
+ state: [{ type: core.Input }],
1642
1648
  waiting: [{ type: core.Input }]
1643
1649
  };
1644
1650
 
@@ -1691,7 +1697,7 @@
1691
1697
  var BIG_MAX_LENGTH = 500;
1692
1698
  var fldAttr = {
1693
1699
  validateOnServer: 'validateOnServer',
1694
- value: '_fieldValue',
1700
+ value: '_value',
1695
1701
  minValue: '_minValue',
1696
1702
  maxValue: '_maxValue',
1697
1703
  maxLength: '_maxLength',
@@ -1869,7 +1875,6 @@
1869
1875
  FieldDescriptor.prototype.hideLabel = function () { this.setVisibleLabel(false); };
1870
1876
  FieldDescriptor.prototype.setChanged = function (hasChanged) { this.setAttr(fldAttr.hasChanged, hasChanged); };
1871
1877
  FieldDescriptor.prototype.changed = function () { this.setChanged(true); };
1872
- FieldDescriptor.prototype.getRawValue = function () { return this._fieldValue; };
1873
1878
  FieldDescriptor.prototype.setLabel = function (label) { this.setAttr(fldAttr.title, label); };
1874
1879
  FieldDescriptor.prototype.clean = function () { this.setValue(this.defaultValue || ''); this.resetError(); };
1875
1880
  Object.defineProperty(FieldDescriptor.prototype, "backend", {
@@ -1918,22 +1923,11 @@
1918
1923
  return fieldCurrentValue === '';
1919
1924
  };
1920
1925
  FieldDescriptor.prototype.getValue = function () {
1921
- var _a, _b;
1922
- switch (this.fieldType) {
1923
- case this._formConfig.fieldTypes.boolean:
1924
- return (_a = this._fieldValue) !== null && _a !== void 0 ? _a : false;
1925
- break;
1926
- case this._formConfig.fieldTypes.check:
1927
- return (_b = this._fieldValue) !== null && _b !== void 0 ? _b : false;
1928
- break;
1929
- case this._formConfig.fieldTypes.currency:
1930
- return (typeof this._fieldValue === 'string')
1931
- ? this._fieldValue.replace(',', '') : this._fieldValue;
1932
- break;
1933
- default:
1934
- return this._fieldValue;
1935
- break;
1926
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
1927
+ || this.fieldType === this._formConfig.fieldTypes.check) {
1928
+ return yn__default['default'](this._value);
1936
1929
  }
1930
+ return this._value;
1937
1931
  };
1938
1932
  FieldDescriptor.prototype.updateFromServer = function (fld) {
1939
1933
  var _a;
@@ -1960,40 +1954,26 @@
1960
1954
  FieldDescriptor.prototype.setFieldType = function (inputFieldType) {
1961
1955
  this.setAttr(fldAttr.type, inputFieldType);
1962
1956
  };
1963
- FieldDescriptor.prototype.setMinValue = function (minValue) {
1964
- var _a, _b, _c;
1965
- if (this.fieldType === this._formConfig.fieldTypes.date
1966
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMinValue)) {
1967
- this.setAttr(fldAttr.minValue, minValue);
1968
- if (!minValue) {
1969
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
1970
- }
1971
- else {
1972
- var minDate = new Date(minValue);
1973
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMinValue(minDate);
1974
- }
1957
+ FieldDescriptor.prototype.setMinValue = function (inputMinValue) {
1958
+ var minValue = inputMinValue;
1959
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1960
+ minValue = new Date(minValue);
1975
1961
  }
1962
+ this.setAttr(fldAttr.minValue, minValue);
1976
1963
  };
1977
- FieldDescriptor.prototype.setMaxValue = function (maxValue) {
1978
- var _a, _b, _c;
1979
- if (this.fieldType === this._formConfig.fieldTypes.date
1980
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMaxValue)) {
1981
- this.setAttr(fldAttr.maxValue, maxValue);
1982
- if (!maxValue) {
1983
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
1984
- }
1985
- else {
1986
- var maxDate = new Date(maxValue);
1987
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMaxValue(maxDate);
1988
- }
1964
+ FieldDescriptor.prototype.setMaxValue = function (inputMaxValue) {
1965
+ var maxValue = inputMaxValue;
1966
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1967
+ maxValue = new Date(maxValue);
1989
1968
  }
1969
+ this.setAttr(fldAttr.maxValue, maxValue);
1990
1970
  };
1991
1971
  FieldDescriptor.prototype.getFieldOptions = function () {
1992
1972
  return JSON.parse(JSON.stringify(this.fieldOptions));
1993
1973
  };
1994
1974
  FieldDescriptor.prototype.setFieldOptions = function (newOptions) {
1995
1975
  var _this = this;
1996
- var _a, _b, _c, _d;
1976
+ var _a;
1997
1977
  if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
1998
1978
  || typeof newOptions === UNDEFINED || !newOptions
1999
1979
  || !Array.isArray(newOptions)) {
@@ -2009,17 +1989,14 @@
2009
1989
  fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
2010
1990
  && fieldOptions.length > 0) ? fieldOptions : [];
2011
1991
  this.setAttr(fldAttr.options, fieldOptions);
2012
- if (this.fieldType === this._formConfig.fieldTypes.array && this.widget) {
2013
- return (_a = this.widget) === null || _a === void 0 ? void 0 : _a.refereshContent();
2014
- }
2015
- if (this._fieldValue) {
2016
- if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._fieldValue)) {
2017
- var fieldValue = (_b = this._fieldValue) === null || _b === void 0 ? void 0 : _b.filter(function (item) { return _this.fieldOptions.find(function (opt) { return opt.fieldOptionId === item; }); });
1992
+ if (this._value) {
1993
+ if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
1994
+ 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; }); });
2018
1995
  this.setAttr(fldAttr.value, fieldValue);
2019
1996
  }
2020
1997
  else {
2021
1998
  var valInOptions = this.fieldOptions
2022
- .find(function (item) { return item.fieldOptionId === _this._fieldValue; });
1999
+ .find(function (item) { return item.fieldOptionId === _this._value; });
2023
2000
  if (!valInOptions) {
2024
2001
  this.setValue('');
2025
2002
  }
@@ -2027,57 +2004,41 @@
2027
2004
  }
2028
2005
  if (this.fieldRequired && this.fieldOptions.length === 1) {
2029
2006
  this.setValue(this.fieldOptions[0].fieldOptionId);
2030
- if ((_c = this.widget) === null || _c === void 0 ? void 0 : _c.onChangeContent) {
2031
- (_d = this.widget) === null || _d === void 0 ? void 0 : _d.onChangeContent();
2032
- }
2033
2007
  }
2034
2008
  };
2035
2009
  FieldDescriptor.prototype.setValue = function (newValue, widgetUpdate) {
2036
2010
  if (widgetUpdate === void 0) { widgetUpdate = true; }
2037
- var _a;
2038
2011
  if (typeof newValue === UNDEFINED || newValue === null) {
2039
2012
  return true;
2040
2013
  }
2041
2014
  var newFinalValue;
2042
- switch (this.fieldType) {
2043
- case 'BOOLEAN':
2044
- newFinalValue = !!newValue;
2045
- break;
2046
- case this._formConfig.fieldTypes.boolean:
2047
- newFinalValue = !!newValue;
2048
- break;
2049
- case this._formConfig.fieldTypes.check:
2050
- newFinalValue = !!newValue;
2051
- break;
2052
- case this._formConfig.fieldTypes.array:
2053
- if (newValue === null || newValue === '') {
2054
- newFinalValue = [];
2055
- }
2056
- else if (!Array.isArray(newValue)) {
2057
- if (typeof (newValue) !== 'string') {
2058
- newValue = newValue.toString();
2059
- }
2060
- newFinalValue = newValue.split(',');
2061
- }
2062
- else {
2063
- newFinalValue = newValue;
2064
- }
2065
- break;
2066
- case this._formConfig.fieldTypes.map:
2067
- newFinalValue = newValue;
2068
- if (newFinalValue && this.widget && widgetUpdate) {
2069
- var latitude = parseFloat(newFinalValue[0]);
2070
- var longitude = parseFloat(newFinalValue[1]);
2071
- (_a = this.widget) === null || _a === void 0 ? void 0 : _a.setLocation(latitude, longitude);
2072
- }
2073
- break;
2074
- default:
2015
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
2016
+ || this.fieldType === this._formConfig.fieldTypes.check) {
2017
+ newFinalValue = yn__default['default'](newValue);
2018
+ }
2019
+ else if (this.fieldType === this._formConfig.fieldTypes.array
2020
+ || this.fieldType === this._formConfig.fieldTypes.map) {
2021
+ if (newValue === null || newValue === '') {
2022
+ newFinalValue = [];
2023
+ }
2024
+ else if (Array.isArray(newValue)) {
2075
2025
  newFinalValue = newValue;
2076
- break;
2026
+ }
2027
+ else {
2028
+ newFinalValue = newValue.toString().split(',');
2029
+ }
2030
+ }
2031
+ else {
2032
+ newFinalValue = newValue;
2077
2033
  }
2078
- if (this._fieldValue !== newFinalValue) {
2034
+ if (this._value !== newFinalValue) {
2079
2035
  this.setChanged(true);
2080
- this.setAttr(fldAttr.value, newFinalValue);
2036
+ if (widgetUpdate) {
2037
+ this.setAttr(fldAttr.value, newFinalValue);
2038
+ }
2039
+ else {
2040
+ this._value = newFinalValue;
2041
+ }
2081
2042
  }
2082
2043
  return true;
2083
2044
  };
@@ -3406,7 +3367,7 @@
3406
3367
  configurable: true
3407
3368
  });
3408
3369
  Object.defineProperty(BasicFormComponent.prototype, "state", {
3409
- get: function () { return this.getCurrentState(); },
3370
+ get: function () { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.state; },
3410
3371
  enumerable: false,
3411
3372
  configurable: true
3412
3373
  });
@@ -3416,11 +3377,6 @@
3416
3377
  enumerable: false,
3417
3378
  configurable: true
3418
3379
  });
3419
- Object.defineProperty(BasicFormComponent.prototype, "currentMode", {
3420
- get: function () { return this.currentState; },
3421
- enumerable: false,
3422
- configurable: true
3423
- });
3424
3380
  Object.defineProperty(BasicFormComponent.prototype, "immutableData", {
3425
3381
  get: function () { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.immutableData; },
3426
3382
  enumerable: false,
@@ -3505,7 +3461,7 @@
3505
3461
  if (!cleanStack) {
3506
3462
  origin = Object.assign(Object.assign({}, backData), { name: this.name, url: this._formRoute, token: this._controlToken });
3507
3463
  origin.subject = (_a = origin === null || origin === void 0 ? void 0 : origin.subject) !== null && _a !== void 0 ? _a : this.formSubject;
3508
- origin.state = (_b = origin === null || origin === void 0 ? void 0 : origin.state) !== null && _b !== void 0 ? _b : this.currentState;
3464
+ origin.state = (_b = origin === null || origin === void 0 ? void 0 : origin.state) !== null && _b !== void 0 ? _b : this.state;
3509
3465
  origin.fields = (_c = origin === null || origin === void 0 ? void 0 : origin.fields) !== null && _c !== void 0 ? _c : {};
3510
3466
  origin.extra = (_d = origin === null || origin === void 0 ? void 0 : origin.extra) !== null && _d !== void 0 ? _d : {};
3511
3467
  }