@senior-agronegocio/angular-components 0.0.70-origination → 0.0.72-origination

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,4 +1,4 @@
1
- import { __read, __values, __awaiter, __generator, __spread, __decorate, __extends, __assign } from 'tslib';
1
+ import { __assign, __values, __read, __awaiter, __generator, __spread, __decorate, __extends } from 'tslib';
2
2
  import moment from 'moment';
3
3
  import { Subject, BehaviorSubject, of, throwError } from 'rxjs';
4
4
  import sockjsClient from 'sockjs-client';
@@ -175,6 +175,16 @@ var AGRO_REGEX = {
175
175
  * Validação se todos os dígitos são iguais
176
176
  */
177
177
  isAllDigitsEqual: /^(.)\1+$/,
178
+ /**
179
+ * Validação de Placa de Veículo do Mercosul
180
+ * Formato: ABC1D23
181
+ */
182
+ isMercosulLicensePlate: /^[A-Z]{3}[0-9]{1}[A-Z]{1}[0-9]{2}$/,
183
+ /**
184
+ * Validação de Placa de Veículo Antiga
185
+ * Formato: AAA-0000
186
+ */
187
+ isOldLicensePlate: /^[A-Z]{3}[0-9]{4}$/
178
188
  };
179
189
 
180
190
  var NumberComparisonType;
@@ -1709,13 +1719,14 @@ var AgroFormValidator = /** @class */ (function () {
1709
1719
  AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
1710
1720
  var checkValue = function (control) {
1711
1721
  var _a, _b;
1712
- var _c, _d, _e, _f;
1722
+ var _c, _d, _e;
1713
1723
  var formGroup = control;
1714
1724
  var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
1715
1725
  var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
1716
1726
  var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
1717
1727
  var methodName = 'checkValueBetween';
1718
- if (valueA && valueB && valueC) {
1728
+ var areNumbers = [valueA, valueB, valueC].every(function (v) { return v !== null && v !== undefined; });
1729
+ if (areNumbers) {
1719
1730
  if (valueB < valueA || valueB > valueC) {
1720
1731
  var targetControl = formGroup.get(targetFormControl);
1721
1732
  if (targetControl) {
@@ -1723,10 +1734,12 @@ var AgroFormValidator = /** @class */ (function () {
1723
1734
  }
1724
1735
  return _b = {}, _b[methodName] = true, _b;
1725
1736
  }
1726
- else if ((_f = formGroup.get(targetFormControl)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
1737
+ else {
1727
1738
  var targetControl = formGroup.get(targetFormControl);
1728
- if (targetControl) {
1729
- targetControl.setErrors(null);
1739
+ if (targetControl === null || targetControl === void 0 ? void 0 : targetControl.hasError(methodName)) {
1740
+ var errors = __assign({}, targetControl.errors);
1741
+ delete errors[methodName];
1742
+ targetControl.setErrors(Object.keys(errors).length ? errors : null);
1730
1743
  }
1731
1744
  }
1732
1745
  }
@@ -1757,6 +1770,104 @@ var AgroFormValidator = /** @class */ (function () {
1757
1770
  };
1758
1771
  return objectProperty;
1759
1772
  };
1773
+ /**
1774
+ * Valida se o campo é um CPF (Cadastro de Pessoa Física) válido.
1775
+ */
1776
+ AgroFormValidator.CPFValidator = function () {
1777
+ var cpfVal = function (control) {
1778
+ var cpf = (control.value || '').replace(/[^\d]/g, '');
1779
+ if (!cpf) {
1780
+ return null; // Não valida campo vazio, use Validators.required junto se quiser obrigatoriedade
1781
+ }
1782
+ if (cpf.length !== 11) {
1783
+ return { cpfValidator: true };
1784
+ }
1785
+ // Verifica se todos os dígitos são iguais (ex.: 11111111111)
1786
+ if (/^(\d)\1{10}$/.test(cpf)) {
1787
+ return { cpfValidator: true };
1788
+ }
1789
+ // Validação dos dígitos verificadores
1790
+ var calcCheckDigit = function (cpfSlice, factor) {
1791
+ var e_1, _a;
1792
+ var total = 0;
1793
+ try {
1794
+ for (var cpfSlice_1 = __values(cpfSlice), cpfSlice_1_1 = cpfSlice_1.next(); !cpfSlice_1_1.done; cpfSlice_1_1 = cpfSlice_1.next()) {
1795
+ var digit = cpfSlice_1_1.value;
1796
+ total += parseInt(digit, 10) * factor--;
1797
+ }
1798
+ }
1799
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1800
+ finally {
1801
+ try {
1802
+ if (cpfSlice_1_1 && !cpfSlice_1_1.done && (_a = cpfSlice_1.return)) _a.call(cpfSlice_1);
1803
+ }
1804
+ finally { if (e_1) throw e_1.error; }
1805
+ }
1806
+ var remainder = total % 11;
1807
+ return remainder < 2 ? 0 : 11 - remainder;
1808
+ };
1809
+ var digit1 = calcCheckDigit(cpf.substring(0, 9), 10);
1810
+ var digit2 = calcCheckDigit(cpf.substring(0, 9) + digit1, 11);
1811
+ var isValid = digit1 === parseInt(cpf.charAt(9), 10) &&
1812
+ digit2 === parseInt(cpf.charAt(10), 10);
1813
+ return isValid ? null : { cpfValidator: true };
1814
+ };
1815
+ return cpfVal;
1816
+ };
1817
+ /**
1818
+ * Validator de CNPJ (Cadastro Nacional da Pessoa Jurídica).
1819
+ * @returns
1820
+ */
1821
+ AgroFormValidator.CNPJValidator = function () {
1822
+ var cnpjVal = function (control) {
1823
+ var _a;
1824
+ var value = (_a = control.value) === null || _a === void 0 ? void 0 : _a.replace(/\D/g, '');
1825
+ if (!value || value.length !== 14) {
1826
+ return { cnpjValidator: true };
1827
+ }
1828
+ // Verifica CNPJs com todos os dígitos iguais (inválidos)
1829
+ if (/^(\d)\1{13}$/.test(value)) {
1830
+ return { cnpjValidator: true };
1831
+ }
1832
+ var validateCheckDigit = function (cnpj, length) {
1833
+ var weights = length === 12
1834
+ ? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
1835
+ : [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
1836
+ var sum = cnpj
1837
+ .slice(0, length)
1838
+ .split('')
1839
+ .reduce(function (acc, digit, index) {
1840
+ return acc + parseInt(digit, 10) * weights[index];
1841
+ }, 0);
1842
+ var remainder = sum % 11;
1843
+ return remainder < 2 ? 0 : 11 - remainder;
1844
+ };
1845
+ var firstCheckDigit = validateCheckDigit(value, 12);
1846
+ var secondCheckDigit = validateCheckDigit(value, 13);
1847
+ if (firstCheckDigit !== parseInt(value.charAt(12), 10) ||
1848
+ secondCheckDigit !== parseInt(value.charAt(13), 10)) {
1849
+ return { cnpjValidator: true };
1850
+ }
1851
+ return null; // válido
1852
+ };
1853
+ return cnpjVal;
1854
+ };
1855
+ /**
1856
+ * Valida se a placa do veículo é válida.
1857
+ * @returns
1858
+ */
1859
+ AgroFormValidator.licensePlateValidator = function () {
1860
+ var licensePlateVal = function (control) {
1861
+ var value = (control.value || '').toUpperCase().trim().replace(/-/g, '');
1862
+ if (!value) {
1863
+ return null; // Campo vazio não é responsabilidade desse validador
1864
+ }
1865
+ var isValid = AGRO_REGEX.isMercosulLicensePlate.test(value) ||
1866
+ AGRO_REGEX.isOldLicensePlate.test(value);
1867
+ return isValid ? null : { licensePlateInvalid: true };
1868
+ };
1869
+ return licensePlateVal;
1870
+ };
1760
1871
  return AgroFormValidator;
1761
1872
  }());
1762
1873