@sankhyalabs/ezui 1.1.76 → 1.1.77

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.
Files changed (164) hide show
  1. package/dist/cjs/ApplicationUtils-d1c1db56.js +35 -0
  2. package/dist/cjs/AssetsUtils-dd585fba.js +24 -0
  3. package/dist/cjs/DataUnit-fdd7c70e.js +474 -0
  4. package/dist/cjs/DateUtils-716769e0.js +46 -0
  5. package/dist/cjs/ez-action-chip.cjs.entry.js +1 -1
  6. package/dist/cjs/ez-application.cjs.entry.js +28 -0
  7. package/dist/cjs/ez-button_11.cjs.entry.js +111771 -0
  8. package/dist/cjs/ez-calendar.cjs.entry.js +212 -0
  9. package/dist/cjs/ez-collapsible-box_6.cjs.entry.js +630 -0
  10. package/dist/cjs/ez-combo-box.cjs.entry.js +250 -0
  11. package/dist/cjs/ez-date-time-input.cjs.entry.js +144 -0
  12. package/dist/cjs/ez-dialog.cjs.entry.js +1 -1
  13. package/dist/cjs/ez-form.cjs.entry.js +1838 -0
  14. package/dist/cjs/ez-label-chip.cjs.entry.js +1 -1
  15. package/dist/cjs/ez-number-input.cjs.entry.js +61 -190
  16. package/dist/cjs/ez-popover.cjs.entry.js +3 -3
  17. package/dist/cjs/ez-popup.cjs.entry.js +2 -2
  18. package/dist/cjs/ez-time-input.cjs.entry.js +9 -27
  19. package/dist/cjs/ez-toast.cjs.entry.js +1 -1
  20. package/dist/cjs/ezui.cjs.js +3 -3
  21. package/dist/cjs/form-metadata.cjs.entry.js +129 -0
  22. package/dist/cjs/index-262d703b.js +7442 -0
  23. package/dist/cjs/{index-9431aeeb.js → index-4e4bae01.js} +1 -5
  24. package/dist/cjs/loader.cjs.js +3 -3
  25. package/dist/collection/collection-manifest.json +8 -3
  26. package/dist/collection/components/ez-application/ez-application.css +3 -0
  27. package/dist/collection/components/ez-application/ez-application.js +37 -0
  28. package/dist/collection/components/ez-button/ez-button.css +16 -1
  29. package/dist/collection/components/ez-button/ez-button.js +27 -2
  30. package/dist/collection/components/ez-calendar/ez-calendar.css +70 -3
  31. package/dist/collection/components/ez-calendar/ez-calendar.js +168 -24
  32. package/dist/collection/components/ez-check/ez-check.css +78 -78
  33. package/dist/collection/components/ez-check/ez-check.js +3 -3
  34. package/dist/collection/components/ez-combo-box/ez-combo-box.css +67 -51
  35. package/dist/collection/components/ez-combo-box/ez-combo-box.js +1 -0
  36. package/dist/collection/components/ez-date-time-input/ez-date-time-input.css +49 -0
  37. package/dist/collection/components/ez-date-time-input/ez-date-time-input.js +254 -0
  38. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +4 -4
  39. package/dist/collection/components/ez-form/subcomponents/structure/FormSheet.js +1 -1
  40. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +2 -2
  41. package/dist/collection/components/ez-grid/controller/DataUnitBridge.js +21 -0
  42. package/dist/collection/components/ez-grid/controller/EzGridController.js +1 -0
  43. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +203 -0
  44. package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +41 -0
  45. package/dist/collection/components/ez-grid/controller/ag-grid/i18n/pt-BR.js +75 -0
  46. package/dist/collection/components/ez-grid/controller/ag-grid/mock/Server.js +69 -0
  47. package/dist/collection/components/ez-grid/controller/ag-grid/template/HeaderColumnTemplate.js +12 -0
  48. package/dist/collection/components/ez-grid/ez-grid.css +15 -0
  49. package/dist/collection/components/ez-grid/ez-grid.js +414 -0
  50. package/dist/collection/components/ez-grid/subcomponents/gridconfig/grid-config.css +105 -0
  51. package/dist/collection/components/ez-grid/subcomponents/gridconfig/grid-config.js +354 -0
  52. package/dist/collection/components/ez-grid/subcomponents/select-box/select-box.css +7 -0
  53. package/dist/collection/components/ez-grid/subcomponents/select-box/select-box.js +66 -0
  54. package/dist/collection/components/ez-icon/ez-icon.css +1 -1
  55. package/dist/collection/components/ez-list/ez-list.css +227 -44
  56. package/dist/collection/components/ez-list/ez-list.js +529 -149
  57. package/dist/collection/components/ez-modal/ez-modal.css +4 -4
  58. package/dist/collection/components/ez-modal/ez-modal.js +1 -1
  59. package/dist/collection/components/ez-number-input/ez-number-input.css +7 -162
  60. package/dist/collection/components/ez-number-input/ez-number-input.js +90 -281
  61. package/dist/collection/components/ez-popover/ez-popover.css +10 -6
  62. package/dist/collection/components/ez-popup/ez-popup.css +25 -27
  63. package/dist/collection/components/ez-tabselector/ez-tabselector.css +0 -1
  64. package/dist/collection/components/ez-tabselector/ez-tabselector.js +3 -3
  65. package/dist/collection/components/ez-text-area/ez-text-area.js +1 -0
  66. package/dist/collection/components/ez-text-input/ez-text-input.js +1 -0
  67. package/dist/collection/components/ez-upload/ez-upload.js +3 -3
  68. package/dist/collection/components/test-du/test-du.css +3 -0
  69. package/dist/collection/components/test-du/test-du.js +45 -0
  70. package/dist/collection/servidor.js +94 -94
  71. package/dist/collection/utils/{Application.js → ApplicationUtils.js} +4 -4
  72. package/dist/custom-elements/index.d.ts +36 -6
  73. package/dist/custom-elements/index.js +120975 -3013
  74. package/dist/esm/ApplicationUtils-01280a9d.js +33 -0
  75. package/dist/esm/AssetsUtils-3803e935.js +22 -0
  76. package/dist/esm/DataUnit-1cd45202.js +464 -0
  77. package/dist/esm/DateUtils-0a1bbd7a.js +44 -0
  78. package/dist/esm/ez-action-chip.entry.js +1 -1
  79. package/dist/esm/ez-application.entry.js +24 -0
  80. package/dist/esm/ez-button_11.entry.js +111757 -0
  81. package/dist/esm/ez-calendar.entry.js +208 -0
  82. package/dist/esm/ez-collapsible-box_6.entry.js +621 -0
  83. package/dist/esm/ez-combo-box.entry.js +246 -0
  84. package/dist/esm/ez-date-time-input.entry.js +140 -0
  85. package/dist/esm/ez-dialog.entry.js +1 -1
  86. package/dist/esm/ez-form.entry.js +1834 -0
  87. package/dist/esm/ez-label-chip.entry.js +1 -1
  88. package/dist/esm/ez-number-input.entry.js +61 -190
  89. package/dist/esm/ez-popover.entry.js +3 -3
  90. package/dist/esm/ez-popup.entry.js +2 -2
  91. package/dist/esm/ez-time-input.entry.js +3 -21
  92. package/dist/esm/ez-toast.entry.js +1 -1
  93. package/dist/esm/ezui.js +3 -3
  94. package/dist/esm/form-metadata.entry.js +125 -0
  95. package/dist/esm/{index-fd3c8023.js → index-1dacecd3.js} +1 -5
  96. package/dist/esm/index-cfd5e193.js +7433 -0
  97. package/dist/esm/loader.js +3 -3
  98. package/dist/ezui/ezui.esm.js +1 -1
  99. package/dist/ezui/p-1ea8187e.entry.js +369 -0
  100. package/dist/ezui/p-37a611ea.js +1 -0
  101. package/dist/ezui/p-45689464.entry.js +1 -0
  102. package/dist/ezui/{p-a0b6eee2.entry.js → p-516d0e0f.entry.js} +1 -1
  103. package/dist/ezui/p-57291f97.entry.js +1 -0
  104. package/dist/ezui/{p-66954a04.entry.js → p-5a86e18a.entry.js} +1 -1
  105. package/dist/ezui/{p-823ff0a0.entry.js → p-5da66d3e.entry.js} +1 -1
  106. package/dist/ezui/p-69416bec.entry.js +1 -0
  107. package/dist/ezui/p-7107d7ef.js +1 -0
  108. package/dist/ezui/p-7ef97c5f.entry.js +1 -0
  109. package/dist/ezui/p-88f45a83.entry.js +1 -0
  110. package/dist/ezui/p-8c51a6aa.entry.js +1 -0
  111. package/dist/ezui/{p-e0ab3746.js → p-8f4851a6.js} +1 -1
  112. package/dist/ezui/p-9dfd537e.js +1 -0
  113. package/dist/ezui/{p-d443f020.entry.js → p-a18a2d7b.entry.js} +1 -1
  114. package/dist/ezui/p-a223eed8.entry.js +1 -0
  115. package/dist/ezui/p-b36308e7.js +1 -0
  116. package/dist/ezui/p-c0af195b.entry.js +1 -0
  117. package/dist/ezui/p-c6d469fc.entry.js +1 -0
  118. package/dist/ezui/p-c89629eb.js +1 -0
  119. package/dist/ezui/p-e7ee2836.entry.js +1 -0
  120. package/dist/ezui/p-f7b835cf.entry.js +1 -0
  121. package/dist/types/components/ez-application/ez-application.d.ts +12 -0
  122. package/dist/types/components/ez-button/ez-button.d.ts +5 -0
  123. package/dist/types/components/ez-calendar/ez-calendar.d.ts +21 -0
  124. package/dist/types/components/ez-check/ez-check.d.ts +1 -1
  125. package/dist/types/components/ez-date-time-input/ez-date-time-input.d.ts +42 -0
  126. package/dist/types/components/ez-grid/controller/DataUnitBridge.d.ts +8 -0
  127. package/dist/types/components/ez-grid/controller/EzGridController.d.ts +195 -0
  128. package/dist/types/components/ez-grid/controller/ag-grid/AgGridController.d.ts +34 -0
  129. package/dist/types/components/ez-grid/controller/ag-grid/DataSource.d.ts +11 -0
  130. package/dist/types/components/ez-grid/controller/ag-grid/i18n/pt-BR.d.ts +2 -0
  131. package/dist/types/components/ez-grid/controller/ag-grid/mock/Server.d.ts +8 -0
  132. package/dist/types/components/ez-grid/ez-grid.d.ts +78 -0
  133. package/dist/types/components/ez-grid/subcomponents/gridconfig/grid-config.d.ts +30 -0
  134. package/dist/types/components/ez-grid/subcomponents/select-box/select-box.d.ts +9 -0
  135. package/dist/types/components/ez-list/ez-list.d.ts +70 -17
  136. package/dist/types/components/ez-number-input/ez-number-input.d.ts +33 -50
  137. package/dist/types/components/ez-tabselector/ez-tabselector.d.ts +1 -1
  138. package/dist/types/components/test-du/test-du.d.ts +6 -0
  139. package/dist/types/components.d.ts +283 -117
  140. package/dist/types/stencil-public-runtime.d.ts +6 -4
  141. package/dist/types/utils/{Application.d.ts → ApplicationUtils.d.ts} +1 -1
  142. package/package.json +10 -8
  143. package/react/components.d.ts +6 -1
  144. package/react/components.js +6 -1
  145. package/react/components.js.map +1 -1
  146. package/dist/cjs/RequestMetadata-2cd01e8a.js +0 -531
  147. package/dist/cjs/ez-button_16.cjs.entry.js +0 -4079
  148. package/dist/cjs/ez-list.cjs.entry.js +0 -174
  149. package/dist/cjs/ez-modal.cjs.entry.js +0 -65
  150. package/dist/collection/components/ez-numeric-input/ez-numeric-input.css +0 -13
  151. package/dist/collection/components/ez-numeric-input/ez-numeric-input.js +0 -185
  152. package/dist/esm/RequestMetadata-c265c9d5.js +0 -527
  153. package/dist/esm/ez-button_16.entry.js +0 -4060
  154. package/dist/esm/ez-list.entry.js +0 -170
  155. package/dist/esm/ez-modal.entry.js +0 -61
  156. package/dist/ezui/p-11ae4ae7.entry.js +0 -1
  157. package/dist/ezui/p-47fa3d6c.entry.js +0 -1
  158. package/dist/ezui/p-8ab6168f.entry.js +0 -1
  159. package/dist/ezui/p-9c1fb51c.entry.js +0 -1
  160. package/dist/ezui/p-9d85125b.entry.js +0 -1
  161. package/dist/ezui/p-9dfccb16.js +0 -1
  162. package/dist/ezui/p-a7b546b2.entry.js +0 -1
  163. package/dist/ezui/p-c833c94f.entry.js +0 -1
  164. package/dist/types/components/ez-numeric-input/ez-numeric-input.d.ts +0 -45
@@ -1,527 +0,0 @@
1
- const NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS = /^([+-])?(\d+).?(\d*)[eE]([-+]?\d+)$/;
2
- /**
3
- * `NumberUtils` é uma biblioteca para manipulação de números
4
- *
5
- * `Métodos`:
6
- *
7
- * @stringToNumber: converte um número em formato de string em um valor numérico nativo do javascript
8
- * @format: arredonda um número em formato de string baseado nos parâmetros "presision" e "prettyPrecision";
9
- */
10
- class NumberUtils {
11
- }
12
- /**
13
- * @stringToNumber: converte um numero em formato de string em numero
14
- *
15
- * @param value numero em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico: ######.##)
16
- *
17
- * @returns string based number
18
- *
19
- * @Exemples
20
- * @"100,12" | 100.12
21
- * @"100.12" | 100.12
22
- * @"-100,12" | -100.12
23
- * @"R$100,12" | 100.12
24
- * @"-R$100,12" | -100.12
25
- * @"string" | NaN
26
- */
27
- NumberUtils.stringToNumber = (value) => {
28
- if (value === '' || value === null || value === undefined) {
29
- return NaN;
30
- }
31
- if (value) {
32
- value = value.toString();
33
- var negative = (value.charAt(0) === '-');
34
- if (!NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS.test(value)) {
35
- value = value.replace(/[^\d.,]/g, '');
36
- }
37
- else {
38
- value = value.replace(/^-/g, '');
39
- }
40
- //In case of simple string such as: "@@@@@@@"
41
- if (value === '') {
42
- return Number(NaN);
43
- }
44
- var indexV = value.indexOf(',');
45
- var indexP = value.indexOf('.');
46
- if (indexP > indexV) {
47
- value = value.replace(',', '');
48
- }
49
- else if (indexP < indexV) {
50
- value = value.replace(/\./g, '@').replace(',', '.').replace(/@/g, '');
51
- }
52
- if (negative) {
53
- value = '-' + value;
54
- }
55
- }
56
- return Number(value);
57
- };
58
- /**
59
- * @format: converte um numero em formato de string em um numero em formato de string formatado de acordo com os parametros de "precision" e "prettyPrecision"
60
- *
61
- * @param value numero em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico<sem separadors de milhares>: ######.##)
62
- * @param precision (numero de decimais)
63
- * @param prettyPrecision (numero de zeros nos decimais)
64
- *
65
- * @returns numero em formato de string formatado em PT-BR
66
- */
67
- NumberUtils.format = (value, precision, prettyPrecision = NaN) => {
68
- if (value === '' || value === undefined || value === "NaN") {
69
- return NaN.toString();
70
- }
71
- let newValue = NumberUtils.stringToNumber(value);
72
- if (newValue === NaN) {
73
- return NaN.toString();
74
- }
75
- //Validation "precision":
76
- // Case1: precision < 0 => does not use precision
77
- // Case2: presicion not int => does not use precision
78
- if (precision < 0 || Math.abs(Math.round(precision * 1) / 1) !== precision) {
79
- //Once stringToNumber returns number format, we need to change to pt-br
80
- return NumberUtils.changeFormat(newValue.toString());
81
- }
82
- //Validation "prettyPrecision"
83
- let prettyPrecisionInternal = 0;
84
- // Case1: prettyPrecision < 0 => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
85
- // Case2: prettyPrecision not int => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
86
- if (prettyPrecision === NaN || Math.abs(Math.round(prettyPrecision * 1) / 1) !== prettyPrecision) {
87
- prettyPrecisionInternal = precision;
88
- }
89
- else {
90
- prettyPrecisionInternal = prettyPrecision;
91
- }
92
- let newValueStr;
93
- newValueStr = (Math.round(newValue * Math.pow(10, precision)) / Math.pow(10, precision)).toLocaleString('pt-br', { minimumFractionDigits: precision });
94
- //prettyPrecision
95
- const varSettingPP = precision - prettyPrecisionInternal;
96
- if (varSettingPP > 0) {
97
- for (let i = 0; i < varSettingPP; i++) {
98
- if (newValueStr.substring(newValueStr.length - 1) == "0" && precision > 0) {
99
- newValueStr = newValueStr.substring(0, newValueStr.length - 1);
100
- }
101
- }
102
- }
103
- //in Case "." or "," in the end of the string
104
- if (newValueStr.substring(newValueStr.length - 1) == "." || newValueStr.substring(newValueStr.length - 1) == ",") {
105
- newValueStr = newValueStr.substring(0, newValueStr.length - 1);
106
- }
107
- return newValueStr;
108
- };
109
- /**
110
- * @keepOnlyDecimalSeparator: retira os separadores de milhar de um número em formato de string
111
- *
112
- * @param value numero em formato de string a ser convertido
113
- * @param formatnumber (formatação de ENTRADA e SAÍDA do utilitário: pt-BR="###.###,##" en-US="###,###.##"; Default: "pt-BR")
114
- *
115
- * @returns numero em formato de string formatado apenas com separador decimal
116
- */
117
- NumberUtils.keepOnlyDecimalSeparator = (value, formatnumber = 'pt-BR') => {
118
- //Formatting formatnumber to be able to get lowercases
119
- formatnumber = formatnumber.toUpperCase();
120
- //Formatting value following formatnumber parameter
121
- //keep only decimal character in order to correct format the string
122
- //This transformation is due the "stringtoNumber" method is a general method that tries to convert all formated strings
123
- if (formatnumber === 'EN-US') {
124
- value = value.replace(/\,/g, '');
125
- }
126
- else {
127
- value = value.replace(/\./g, '');
128
- }
129
- return value;
130
- };
131
- /**
132
- * @changeFormat: troca o formato do numero string de "PT-BR" para "EN-US" e vice-versa
133
- *
134
- * @param value numero em formato de string a ser convertido
135
- *
136
- * @returns numero em formato de string formatado de "PT-BR" para "EN-US" e vice-versa
137
- */
138
- NumberUtils.changeFormat = (value) => {
139
- //Formatting output following formatnumber
140
- return value.replace(/\./g, '_').replace(/\,/g, '.').replace(/\_/g, ',');
141
- };
142
-
143
- /**
144
- * `MaskFormatter` é usado para formatar strings. Seu comportamento
145
- * é controlado pela formato do atributo `mask` que especifica quais
146
- * caracteres são válidos e onde devem estar posicionados, intercalando-os
147
- * com eventuais caracteres literais expressados no padrão informado.
148
- * Sua implementação é inspirada pela implementação em Java do [MaskFormatter](https://docs.oracle.com/javase/7/docs/api/javax/swing/text/MaskFormatter.html).
149
- *
150
- * Para o padrão da máscara podem ser usados os seguintes caracteres especiais:
151
- *
152
- * | Caractere | Comportamento |
153
- * |:---------:|-------------------------------------------------------------------------------------------------------------|
154
- * | # | Qualquer número |
155
- * | ' | "Escapa" o caractere que vem na sequência. Útil quando desejamos converter um caractere especial em literal.|
156
- * | U | Qualquer letra. Transforma letras maiúsculas em maiúsculas. |
157
- * | L | Qualquer letra. Transforma letras maiúsculas em minúsculas. |
158
- * | A | Qualquer letra ou número. |
159
- * | ? | Qualquer letra. Preserva maiúsculas e minúsculas. |
160
- * | * | Qualquer caractere. |
161
- *
162
- * Os demais caracteres presentes no padrão serão tratados como literais, isto é,
163
- * serão apenas inseridos naquela posição.
164
- *
165
- * Quando o o valor a ser formatado é menor que a máscara um 'placeHolder'
166
- * será inserido em cada posição ausente, completando a formatação.
167
- * Por padrão será usado um espaço em branco como 'placeHolder' mas
168
- * esse valor pode ser alterado.
169
- *
170
- * For por exemplo:
171
- * '''
172
- * const formatter: MaskFormatter = new MaskFormatter("###-####");
173
- * formatter.placeholder = '_';
174
- * console.log(formatter.format("123"));
175
- * '''
176
- * resultaria na string '123-____'.
177
- *
178
- * ##Veja mais alguns exemplos:
179
- * |Padrão |Máscara |Entrada |Saída |
180
- * |----------------|------------------|--------------|------------------|
181
- * |Telefone |(##) ####-#### |3432192515 |(34) 3219-2515 |
182
- * |CPF |###.###.###-## |12345678901 |123.456.789-01 |
183
- * |CNPJ |##.###.###/####-##|12345678901234|12.345.678/9012-34|
184
- * |CEP |##.###-### |12345678 |12.345-678 |
185
- * |PLACA (veículo) |UUU-#### |abc1234 |ABC-1234 |
186
- * |Cor RGB |'#AAAAAA |00000F0 |#0000F0 |
187
- *
188
- */
189
- class MaskFormatter {
190
- constructor(mask) {
191
- this._mask = '';
192
- this._maskChars = new Array();
193
- /**
194
- * Determina qual caractere será usado dos caracteres não presentes no valor
195
- * ou seja, aqueles que o usuário ainda não informou. Por padrão usamos um espaço
196
- */
197
- this.placeholder = ' ';
198
- this.mask = mask;
199
- }
200
- /**
201
- * Setter para mask. Trata-se do padrão que se espera ao formatar o texto.
202
- */
203
- set mask(mask) {
204
- this._mask = mask;
205
- this.updateInternalMask();
206
- }
207
- /**
208
- * Getter para mask
209
- *
210
- * @return A última máscara informada.
211
- */
212
- get mask() {
213
- return this._mask;
214
- }
215
- /**
216
- * Formata a string passada baseada na máscara definda pelo atributo mask.
217
- *
218
- * @param value Valor a ser formatado
219
- * @return O valor processado de acordo com o padrão
220
- */
221
- format(value) {
222
- let result = '';
223
- const index = [0];
224
- let counter = 0;
225
- const maxCounter = this._maskChars.length;
226
- while (counter < maxCounter) {
227
- result = this._maskChars[counter].append(result, value, index);
228
- counter++;
229
- }
230
- return result;
231
- }
232
- /**
233
- * Preparamos a formatação internamente de acordo com o padrão.
234
- */
235
- updateInternalMask() {
236
- this._maskChars.length = 0;
237
- if (this.mask != null) {
238
- let counter = 0;
239
- const maxCounter = this.mask.length;
240
- while (counter < maxCounter) {
241
- let maskChar = this.mask.charAt(counter);
242
- switch (maskChar) {
243
- case MaskFormatter.DIGIT_KEY:
244
- this._maskChars.push(new MaskFormatter.DigitMaskCharacter(this, maskChar));
245
- break;
246
- case MaskFormatter.LITERAL_KEY:
247
- if (++counter < maxCounter) {
248
- maskChar = this.mask.charAt(counter);
249
- this._maskChars.push(new MaskFormatter.LiteralCharacter(this, maskChar));
250
- }
251
- break;
252
- case MaskFormatter.UPPERCASE_KEY:
253
- this._maskChars.push(new MaskFormatter.UpperCaseCharacter(this, maskChar));
254
- break;
255
- case MaskFormatter.LOWERCASE_KEY:
256
- this._maskChars.push(new MaskFormatter.LowerCaseCharacter(this, maskChar));
257
- break;
258
- case MaskFormatter.ALPHA_NUMERIC_KEY:
259
- this._maskChars.push(new MaskFormatter.AlphaNumericCharacter(this, maskChar));
260
- break;
261
- case MaskFormatter.CHARACTER_KEY:
262
- this._maskChars.push(new MaskFormatter.CharCharacter(this, maskChar));
263
- break;
264
- case MaskFormatter.ANYTHING_KEY:
265
- this._maskChars.push(new MaskFormatter.MaskCharacter(this, maskChar));
266
- break;
267
- default:
268
- this._maskChars.push(new MaskFormatter.LiteralCharacter(this, maskChar));
269
- break;
270
- }
271
- counter++;
272
- }
273
- }
274
- }
275
- }
276
- MaskFormatter.DIGIT_KEY = "#";
277
- MaskFormatter.LITERAL_KEY = "'";
278
- MaskFormatter.UPPERCASE_KEY = "U";
279
- MaskFormatter.LOWERCASE_KEY = "L";
280
- MaskFormatter.ALPHA_NUMERIC_KEY = "A";
281
- MaskFormatter.CHARACTER_KEY = "?";
282
- MaskFormatter.ANYTHING_KEY = "*";
283
- //
284
- // Classes internas usadas para representar a máscara.
285
- //
286
- MaskFormatter.MaskCharacter = class {
287
- constructor(maskFormatter, type) {
288
- this.maskFormatter = maskFormatter;
289
- this.type = type;
290
- }
291
- /**
292
- * Cada subclasse deve sobrescrever o retornando true, caso represente
293
- * um caractere literal. Por padrão o retorno é false.
294
- */
295
- isLiteral() {
296
- return false;
297
- }
298
- /**
299
- * Returns true if <code>aChar</code> is a valid reprensentation of
300
- * the receiver. The default implementation returns true if the
301
- * receiver represents a literal character and <code>getChar</code>
302
- * == aChar. Otherwise, this will return true is <code>aChar</code>
303
- * is contained in the valid characters and not contained
304
- * in the invalid characters.
305
- */
306
- isValidCharacter(aChar) {
307
- if (this.isLiteral()) {
308
- return (this.getChar(aChar) == aChar);
309
- }
310
- aChar = this.getChar(aChar);
311
- return true;
312
- }
313
- /**
314
- * Returns the character to insert for <code>aChar</code>. The
315
- * default implementation returns <code>aChar</code>. Subclasses
316
- * that wish to do some sort of mapping, perhaps lower case to upper
317
- * case should override this and do the necessary mapping.
318
- */
319
- getChar(aChar) {
320
- return aChar;
321
- }
322
- /**
323
- * Appends the necessary character in <code>formatting</code> at
324
- * <code>index</code> to <code>buff</code>.
325
- */
326
- append(result, formatting, index) {
327
- const inString = index[0] < formatting.length;
328
- const aChar = inString ? formatting.charAt(index[0]) : '';
329
- if (this.isLiteral()) {
330
- const literal = this.getChar(aChar);
331
- result += literal;
332
- if (literal === aChar) {
333
- index[0] = index[0] + 1;
334
- }
335
- }
336
- else if (index[0] >= formatting.length) {
337
- result += this.maskFormatter.placeholder;
338
- index[0] = index[0] + 1;
339
- }
340
- else if (this.isValidCharacter(aChar)) {
341
- result += this.getChar(aChar);
342
- index[0] = index[0] + 1;
343
- }
344
- else {
345
- throw new Error(`Valor inválido: "${aChar}". Na posição ${index[0] + 1} espera-se ${this.getFormatMessage()}.`);
346
- }
347
- return result;
348
- }
349
- getFormatMessage() {
350
- let message;
351
- switch (this.type) {
352
- case MaskFormatter.UPPERCASE_KEY:
353
- case MaskFormatter.LOWERCASE_KEY:
354
- case MaskFormatter.CHARACTER_KEY:
355
- message = 'uma letra';
356
- break;
357
- case MaskFormatter.DIGIT_KEY:
358
- message = 'um número';
359
- break;
360
- case MaskFormatter.ALPHA_NUMERIC_KEY:
361
- message = 'uma letra ou um número';
362
- break;
363
- default:
364
- message = '';
365
- }
366
- return message;
367
- }
368
- };
369
- MaskFormatter.LiteralCharacter = class extends MaskFormatter.MaskCharacter {
370
- constructor(maskFormatter, fixedChar) {
371
- super(maskFormatter, fixedChar);
372
- this._fixedChar = fixedChar;
373
- }
374
- isLiteral() {
375
- return true;
376
- }
377
- getChar(aChar) {
378
- return this._fixedChar;
379
- }
380
- };
381
- MaskFormatter.DigitMaskCharacter = class extends MaskFormatter.MaskCharacter {
382
- isValidCharacter(aChar) {
383
- return (this.isDigit(aChar) && super.isValidCharacter(aChar));
384
- }
385
- isDigit(char) {
386
- return char >= '0' && char <= '9';
387
- }
388
- };
389
- MaskFormatter.UpperCaseCharacter = class extends MaskFormatter.MaskCharacter {
390
- isValidCharacter(aChar) {
391
- return (/[a-z]/i.test(aChar) && super.isValidCharacter(aChar));
392
- }
393
- getChar(aChar) {
394
- return aChar.toUpperCase();
395
- }
396
- };
397
- MaskFormatter.LowerCaseCharacter = class extends MaskFormatter.MaskCharacter {
398
- isValidCharacter(aChar) {
399
- return (/[a-z]/i.test(aChar) && super.isValidCharacter(aChar));
400
- }
401
- getChar(aChar) {
402
- return aChar.toLocaleLowerCase();
403
- }
404
- };
405
- MaskFormatter.AlphaNumericCharacter = class extends MaskFormatter.MaskCharacter {
406
- isValidCharacter(aChar) {
407
- //FIXME: talvez seja problema usar regex aqui... avaliar se existe forma mais barata
408
- return (/[a-z0-9]/i.test(aChar)) && super.isValidCharacter(aChar);
409
- }
410
- };
411
- MaskFormatter.CharCharacter = class extends MaskFormatter.MaskCharacter {
412
- isValidCharacter(aChar) {
413
- //FIXME: talvez seja problema usar regex aqui... avaliar se existe forma mais barata
414
- return (/[a-z]/i.test(aChar) && super.isValidCharacter(aChar));
415
- }
416
- };
417
-
418
- /**
419
- * `TimeFormatter` é um utilitário para formatação de strings desformatadas em strings válidas de horários
420
- */
421
- class TimeFormatter {
422
- /**
423
- * @prepareValue: converts an unformated time string into a formatted time.
424
- *
425
- * @param value unformated time string to convert
426
- *
427
- * @returns formatted time string
428
- *
429
- * @Exemples
430
- * @"1012" | "10:12"
431
- * @"10:12" | "10:12:00"
432
- * @"100112" | "10:01:12"
433
- */
434
- static prepareValue(value, showSeconds) {
435
- if (value && value.length > 0 && value != "NaN") {
436
- let validationValue = value.replace(/:/g, "");
437
- if (showSeconds) {
438
- this._maskFormatter.mask = "##:##:##";
439
- if (validationValue.length < 6) {
440
- while (validationValue.length < 6) {
441
- validationValue = "0".concat(validationValue);
442
- }
443
- }
444
- }
445
- else {
446
- this._maskFormatter.mask = "##:##";
447
- if (validationValue.length < 4) {
448
- while (validationValue.length < 4) {
449
- validationValue = "0".concat(validationValue);
450
- }
451
- }
452
- }
453
- if (this._maskFormatter) {
454
- try {
455
- value = this._maskFormatter.format(validationValue);
456
- return value;
457
- }
458
- catch (e) {
459
- throw new Error(e.message);
460
- }
461
- }
462
- }
463
- return '';
464
- }
465
- /**
466
- * @validateTime: validates if an input string has the corect time format.
467
- *
468
- * @param value input string to validate
469
- *
470
- * @returns true or false
471
- *
472
- * @Exemples
473
- * @"1012" | true
474
- * @"14e4" | false
475
- * @"2624" | false
476
- */
477
- static validateTime(value, showSeconds) {
478
- let isValid = true;
479
- if (value) {
480
- let validationValue = value.replace(/:/g, "");
481
- if (showSeconds) {
482
- if (!["1", "2", "0"].includes(validationValue[0])) {
483
- isValid = false;
484
- }
485
- if (!["0", "1", "2", "3", "4", "5"].includes(validationValue[2])) {
486
- isValid = false;
487
- }
488
- if (!["0", "1", "2", "3", "4", "5"].includes(validationValue[4])) {
489
- isValid = false;
490
- }
491
- if (validationValue[0] == "2" && !["0", "1", "2", "3"].includes(validationValue[1])) {
492
- isValid = false;
493
- }
494
- }
495
- else {
496
- if (!["1", "2", "0"].includes(validationValue[0])) {
497
- isValid = false;
498
- }
499
- if (!["0", "1", "2", "3", "4", "5"].includes(validationValue[2])) {
500
- isValid = false;
501
- }
502
- if (validationValue[0] == "2" && !["0", "1", "2", "3"].includes(validationValue[1])) {
503
- isValid = false;
504
- }
505
- }
506
- }
507
- else {
508
- isValid = false;
509
- }
510
- return isValid;
511
- }
512
- }
513
- TimeFormatter._maskFormatter = new MaskFormatter("##:##");
514
-
515
- /**
516
- * Representa as propriedades necessárias para se executar uma requisição.
517
- */
518
- /** Representa os verbos HTTP suportados */
519
- var Method;
520
- (function (Method) {
521
- Method[Method["GET"] = 0] = "GET";
522
- Method[Method["PUT"] = 1] = "PUT";
523
- Method[Method["POST"] = 2] = "POST";
524
- Method[Method["DELETE"] = 3] = "DELETE";
525
- })(Method || (Method = {}));
526
-
527
- export { MaskFormatter as M, NumberUtils as N, TimeFormatter as T };