@sankhyalabs/ezui 5.20.0-dev.1 → 5.20.0-dev.10

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 (89) hide show
  1. package/README.md +4 -5
  2. package/dist/cjs/ez-alert-list.cjs.entry.js +33 -28
  3. package/dist/cjs/ez-card-item_3.cjs.entry.js +182 -0
  4. package/dist/cjs/ez-combo-box.cjs.entry.js +11 -155
  5. package/dist/cjs/ez-form-view.cjs.entry.js +4 -2
  6. package/dist/cjs/ez-grid.cjs.entry.js +20 -21
  7. package/dist/cjs/ez-icon.cjs.entry.js +1 -1
  8. package/dist/cjs/ez-popup.cjs.entry.js +1 -1
  9. package/dist/cjs/ez-search.cjs.entry.js +611 -31
  10. package/dist/cjs/ez-split-item.cjs.entry.js +11 -2
  11. package/dist/cjs/ez-split-panel.cjs.entry.js +11 -9
  12. package/dist/cjs/ezui.cjs.js +1 -1
  13. package/dist/cjs/filter-column.cjs.entry.js +16 -5
  14. package/dist/cjs/index-a7b0c73d.js +2 -6
  15. package/dist/cjs/loader.cjs.js +1 -1
  16. package/dist/collection/collection-manifest.json +3 -3
  17. package/dist/collection/components/ez-alert-list/ez-alert-list.js +33 -28
  18. package/dist/collection/components/ez-card-item/ez-card-item.css +35 -0
  19. package/dist/collection/components/ez-combo-box/ez-combo-box.js +12 -173
  20. package/dist/collection/components/ez-form-view/fieldbuilder/templates/FileInput.tpl.js +4 -2
  21. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +7 -10
  22. package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +12 -1
  23. package/dist/collection/components/ez-grid/controller/ag-grid/components/EzGridCustomHeader.js +1 -3
  24. package/dist/collection/components/ez-grid/ez-grid.css +1 -0
  25. package/dist/collection/components/ez-grid/ez-grid.js +2 -2
  26. package/dist/collection/components/ez-grid/subcomponents/filter-column.js +16 -5
  27. package/dist/collection/components/ez-icon/ez-icon.css +1 -1
  28. package/dist/collection/components/ez-popup/ez-popup.css +0 -1
  29. package/dist/collection/components/ez-search/ez-search.css +331 -0
  30. package/dist/collection/components/ez-search/ez-search.js +689 -55
  31. package/dist/collection/components/ez-split-panel/ez-split-panel.css +7 -7
  32. package/dist/collection/components/ez-split-panel/ez-split-panel.js +30 -10
  33. package/dist/collection/components/ez-split-panel/structure/item/ez-split-item.css +36 -12
  34. package/dist/collection/components/ez-split-panel/structure/item/ez-split-item.js +57 -2
  35. package/dist/collection/utils/form/test/DataBinder.test.js +9 -0
  36. package/dist/custom-elements/index.js +727 -266
  37. package/dist/esm/ez-alert-list.entry.js +33 -28
  38. package/dist/esm/ez-card-item_3.entry.js +176 -0
  39. package/dist/esm/ez-combo-box.entry.js +12 -156
  40. package/dist/esm/ez-form-view.entry.js +4 -2
  41. package/dist/esm/ez-grid.entry.js +20 -21
  42. package/dist/esm/ez-icon.entry.js +1 -1
  43. package/dist/esm/ez-popup.entry.js +1 -1
  44. package/dist/esm/ez-search.entry.js +613 -33
  45. package/dist/esm/ez-split-item.entry.js +12 -3
  46. package/dist/esm/ez-split-panel.entry.js +11 -9
  47. package/dist/esm/ezui.js +1 -1
  48. package/dist/esm/filter-column.entry.js +16 -5
  49. package/dist/esm/index-baa5e267.js +2 -6
  50. package/dist/esm/loader.js +1 -1
  51. package/dist/ezui/ezui.esm.js +1 -1
  52. package/dist/ezui/{p-51c5e071.entry.js → p-02c8831a.entry.js} +1 -1
  53. package/dist/ezui/p-133fae4a.entry.js +1 -0
  54. package/dist/ezui/p-13dbad96.entry.js +1 -0
  55. package/dist/ezui/{p-f56dd1da.entry.js → p-300bf244.entry.js} +1 -1
  56. package/dist/ezui/p-428a05fe.entry.js +1 -0
  57. package/dist/ezui/p-60848ef6.entry.js +1 -0
  58. package/dist/ezui/p-940ed30b.entry.js +1 -0
  59. package/dist/ezui/{p-6e2f8e6b.entry.js → p-ab629244.entry.js} +1 -1
  60. package/dist/ezui/p-baf80b13.entry.js +1 -0
  61. package/dist/ezui/p-cd0499a2.entry.js +1 -0
  62. package/dist/ezui/p-e52cbcc7.entry.js +1 -0
  63. package/dist/types/components/ez-alert-list/ez-alert-list.d.ts +1 -1
  64. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +0 -15
  65. package/dist/types/components/ez-grid/controller/ag-grid/DataSource.d.ts +2 -1
  66. package/dist/types/components/ez-grid/controller/ag-grid/components/EzGridCustomHeader.d.ts +1 -1
  67. package/dist/types/components/ez-grid/subcomponents/filter-column.d.ts +4 -1
  68. package/dist/types/components/ez-search/ez-search.d.ts +100 -10
  69. package/dist/types/components/ez-split-panel/ez-split-panel.d.ts +23 -0
  70. package/dist/types/components/ez-split-panel/structure/item/ez-split-item.d.ts +17 -0
  71. package/dist/types/components.d.ts +47 -14
  72. package/dist/types/utils/form/test/DataBinder.test.d.ts +1 -0
  73. package/dist/types/utils/interfaces/AbstractFieldMetadata.d.ts +2 -1
  74. package/package.json +12 -5
  75. package/dist/cjs/ez-card-item.cjs.entry.js +0 -52
  76. package/dist/cjs/ez-filter-input_2.cjs.entry.js +0 -137
  77. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridUtils.js +0 -8
  78. package/dist/esm/ez-card-item.entry.js +0 -48
  79. package/dist/esm/ez-filter-input_2.entry.js +0 -132
  80. package/dist/ezui/p-05f5a778.entry.js +0 -1
  81. package/dist/ezui/p-4a7f113d.entry.js +0 -1
  82. package/dist/ezui/p-5613fe63.entry.js +0 -1
  83. package/dist/ezui/p-76ba9d67.entry.js +0 -1
  84. package/dist/ezui/p-796c1a88.entry.js +0 -1
  85. package/dist/ezui/p-a32aaac6.entry.js +0 -1
  86. package/dist/ezui/p-a5ac7151.entry.js +0 -1
  87. package/dist/ezui/p-af15c277.entry.js +0 -1
  88. package/dist/ezui/p-d6ffe679.entry.js +0 -1
  89. package/dist/types/components/ez-grid/controller/ag-grid/AgGridUtils.d.ts +0 -1
@@ -1,8 +1,25 @@
1
- import { h } from "@stencil/core";
1
+ import { h, Host } from "@stencil/core";
2
2
  import CSSVarsUtils from "../../utils/CSSVarsUtils";
3
- import { ElementIDUtils } from "@sankhyalabs/core";
3
+ import { ElementIDUtils, FloatingManager, ObjectUtils, StringUtils } from "@sankhyalabs/core";
4
+ import { ApplicationUtils } from "../../utils";
5
+ import { REQUIRED_INFO } from "../../utils/constants";
4
6
  export class EzSearch {
5
7
  constructor() {
8
+ this._changeDeboucingTimeout = null;
9
+ this._limitCharsToSearch = 3;
10
+ this._deboucingTime = 300;
11
+ this._maxWidthValue = 0;
12
+ this._tabPressed = false;
13
+ this._textEmptyList = "Nenhum resultado encontrado";
14
+ this._textEmptySearch = "Nenhum resultado de {0} encontrado";
15
+ this._lookupMode = false;
16
+ this._startHighlightTag = "<span class='card-item__highlight'>";
17
+ this._endHighlightTag = "</span>";
18
+ this._preSelection = undefined;
19
+ this._visibleOptions = undefined;
20
+ this._startLoading = false;
21
+ this._showLoading = true;
22
+ this._criteria = undefined;
6
23
  this.value = undefined;
7
24
  this.label = undefined;
8
25
  this.enabled = true;
@@ -17,28 +34,82 @@ export class EzSearch {
17
34
  this.listOptionsPosition = undefined;
18
35
  this.isTextSearch = false;
19
36
  this.ignoreLimitCharsToSearch = false;
37
+ this.options = undefined;
38
+ this.suppressSearch = false;
20
39
  }
21
40
  observeErrorMessage() {
22
- if (this._comboElement) {
23
- this._comboElement.errorMessage = this.errorMessage;
41
+ var _a;
42
+ if (this._textInput) {
43
+ this._textInput.errorMessage = this.errorMessage;
44
+ if (!((_a = this.errorMessage) === null || _a === void 0 ? void 0 : _a.trim())) {
45
+ this.setInputValue();
46
+ }
24
47
  }
25
48
  }
26
- observeValue() {
27
- if (this._comboElement) {
28
- this._comboElement.value = this.value;
49
+ observeValue(newValue, oldValue) {
50
+ if (this._textInput && newValue != oldValue) {
51
+ try {
52
+ if (newValue === "string") {
53
+ this.setInputValue();
54
+ return;
55
+ }
56
+ const newValueSelected = this.getSelectedOption(newValue);
57
+ const oldValueSelected = this.getSelectedOption(oldValue);
58
+ const currentValue = this.getSelectedOption(this.value);
59
+ if (this.isDifferentValues(currentValue, newValueSelected)) {
60
+ this.value = newValueSelected;
61
+ }
62
+ if (this.isDifferentValues(newValueSelected, oldValueSelected)) {
63
+ this.setInputValue();
64
+ const valueEmitted = newValueSelected === null ? undefined : newValueSelected;
65
+ if (!this._lookupMode) {
66
+ this.ezChange.emit(valueEmitted);
67
+ }
68
+ }
69
+ this.resetOptions();
70
+ }
71
+ finally {
72
+ this._lookupMode = false;
73
+ }
29
74
  }
30
75
  }
76
+ observeOptions(newOptions, oldOptions) {
77
+ if ((newOptions === null || newOptions === void 0 ? void 0 : newOptions.join('')) === (oldOptions === null || oldOptions === void 0 ? void 0 : oldOptions.join('')))
78
+ return;
79
+ this.loadOptions(SearchMode.PRELOAD);
80
+ }
81
+ /*
82
+ * Retorna uma promise com o valor da opção selecionada,
83
+ * que será resolvida quando o backend devolver este dado.
84
+ */
85
+ async getValueAsync() {
86
+ if (!this._showLoading) {
87
+ return new Promise(resolve => resolve(this.value));
88
+ }
89
+ return new Promise(resolve => {
90
+ let id = setInterval(() => {
91
+ if (!this._showLoading) {
92
+ clearInterval(id);
93
+ resolve(this.value);
94
+ }
95
+ }, 100);
96
+ });
97
+ }
31
98
  /**
32
- * Aplica o foco no campo.
33
- */
99
+ * Aplica o foco no campo.
100
+ */
34
101
  async setFocus() {
35
- this._comboElement.setFocus();
102
+ if (this._textInput) {
103
+ this._textInput.setFocus();
104
+ }
36
105
  }
37
106
  /**
38
- * Remove o foco do campo.
39
- */
107
+ * Remove o foco do campo.
108
+ */
40
109
  async setBlur() {
41
- this._comboElement.setBlur();
110
+ if (this._textInput) {
111
+ this._textInput.setBlur();
112
+ }
42
113
  }
43
114
  /**
44
115
  * Retorna se o conteúdo é inválido.
@@ -50,33 +121,533 @@ export class EzSearch {
50
121
  * Limpa o valor do campo de pesquisa
51
122
  */
52
123
  async clearValue() {
124
+ this.clearSearch();
125
+ }
126
+ scrollListener() {
127
+ var _a;
128
+ if (this._floatingID == undefined) {
129
+ return;
130
+ }
131
+ if ((_a = this.listOptionsPosition) === null || _a === void 0 ? void 0 : _a.hardPosition) {
132
+ this.hideOptions();
133
+ }
134
+ else {
135
+ window.requestAnimationFrame(() => {
136
+ this.updateListPosition();
137
+ });
138
+ }
139
+ }
140
+ updateListPosition() {
141
+ let { verticalPosition, horizontalPosition, fromBottom, fromRight, bottomLimit, hardPosition } = this.getListPosition();
142
+ const elementRect = this._listWrapper.getBoundingClientRect();
143
+ const containerRect = this._listContainer.getBoundingClientRect();
144
+ const textInputRect = this._textInput.getBoundingClientRect();
145
+ const limitHeight = bottomLimit || window.innerHeight;
146
+ const neededHeight = containerRect.bottom + elementRect.height;
147
+ if (!fromBottom && (elementRect.top < 0 || neededHeight > limitHeight)) {
148
+ fromBottom = true;
149
+ }
150
+ if (!hardPosition) {
151
+ verticalPosition = verticalPosition || 0;
152
+ horizontalPosition = horizontalPosition || 0;
153
+ if (fromBottom) {
154
+ verticalPosition = window.innerHeight - textInputRect.top + verticalPosition;
155
+ }
156
+ else {
157
+ verticalPosition += containerRect.top;
158
+ }
159
+ if (fromRight) {
160
+ horizontalPosition = window.innerWidth - textInputRect.right + horizontalPosition;
161
+ }
162
+ else {
163
+ horizontalPosition += containerRect.left;
164
+ }
165
+ }
166
+ if (verticalPosition != undefined) {
167
+ this._listWrapper.style[fromBottom ? "bottom" : "top"] = `${verticalPosition}px`;
168
+ this._listWrapper.style[fromBottom ? "top" : "bottom"] = "";
169
+ }
170
+ if (horizontalPosition != undefined) {
171
+ this._listWrapper.style[fromRight ? "right" : "left"] = `${horizontalPosition}px`;
172
+ this._listWrapper.style[fromRight ? "left" : "right"] = "";
173
+ }
174
+ }
175
+ getListPosition() {
176
+ if (this.listOptionsPosition) {
177
+ return this.listOptionsPosition;
178
+ }
179
+ return {
180
+ verticalPosition: (this.errorMessage || !this.canShowError || this.mode === "slim") ? 6 : -13
181
+ };
182
+ }
183
+ isDifferentValues(firstValue, secondValue) {
184
+ return ObjectUtils.objectToString(firstValue || {}) !== ObjectUtils.objectToString(secondValue || {});
185
+ }
186
+ getFormattedText(currentValue) {
187
+ if (currentValue == undefined) {
188
+ return;
189
+ }
190
+ if (!this.showSelectedValue || currentValue.value == undefined) {
191
+ return currentValue.label;
192
+ }
193
+ return currentValue.label ? `${currentValue.value} - ${currentValue.label}` : currentValue.value;
194
+ }
195
+ getText() {
196
+ const currentValue = this.getSelectedOption(this.value);
197
+ const text = this.getFormattedText(currentValue);
198
+ if (text == undefined) {
199
+ return;
200
+ }
201
+ return String(text)
202
+ .replace(/&amp;/g, '&')
203
+ .replace(/&lt;/g, '<')
204
+ .replace(/&gt;/g, '>')
205
+ .replace(/&quot;/g, '"');
206
+ }
207
+ getSelectedOption(value) {
208
+ if (typeof value === "string" || value instanceof String) {
209
+ return this._visibleOptions.find(o => o.value === value);
210
+ }
211
+ return value;
212
+ }
213
+ updateVisibleOptions() {
214
+ let opts = this._source || [];
215
+ if (this.suppressEmptyOption) {
216
+ this._visibleOptions = opts;
217
+ }
218
+ else {
219
+ this._visibleOptions = [{ value: undefined, label: "" }].concat(opts);
220
+ }
221
+ this._maxWidthValue = this.getMaxWidthValue();
222
+ }
223
+ getMaxWidthValue() {
224
+ var _a;
225
+ const arrValues = [];
226
+ (_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.forEach(opt => {
227
+ const widthValue = this.getWidthValue(opt.value);
228
+ if (!arrValues.includes(widthValue)) {
229
+ arrValues.push(widthValue);
230
+ }
231
+ });
232
+ return arrValues.length > 1 ? Math.max(...arrValues) : 0;
233
+ }
234
+ getWidthValue(value) {
235
+ if (this._itemValueBasis != undefined) {
236
+ const span = this._itemValueBasis;
237
+ if (value != undefined) {
238
+ span.innerHTML = value;
239
+ return span.clientWidth > 0 ? (span.clientWidth + 2) : 0;
240
+ }
241
+ else {
242
+ span.innerHTML = "";
243
+ }
244
+ }
245
+ return 0;
246
+ }
247
+ createOption(detail) {
248
+ let { key, title } = detail;
249
+ const startHighlight = new RegExp(this._startHighlightTag, 'g');
250
+ const endHighlight = new RegExp(this._endHighlightTag, 'g');
251
+ title = StringUtils.decodeHtmlEntities(title);
252
+ const option = {
253
+ value: key === null || key === void 0 ? void 0 : key.replace(startHighlight, '').replace(endHighlight, ''),
254
+ label: title === null || title === void 0 ? void 0 : title.replace(startHighlight, '').replace(endHighlight, '')
255
+ };
256
+ this.selectOption(option);
257
+ }
258
+ buildItem(opt, index) {
259
+ opt.label = opt.label || opt.value;
260
+ const card = {
261
+ key: opt.value,
262
+ title: opt.label,
263
+ details: opt.details
264
+ };
265
+ return h("div", { style: { "height": "100%" }, class: index === this._preSelection ? "item preselected" : "item", id: `item_${opt.value}`, onMouseDown: () => this.createOption(card), onMouseOver: () => this._preSelection = index }, h("ez-card-item", { item: card }));
266
+ }
267
+ showOptions() {
268
+ if (!this.enabled)
269
+ return;
270
+ if (this.isOptionsVisible()) {
271
+ return;
272
+ }
273
+ if (!!this._resizeObserver)
274
+ this._resizeObserver.observe(this._textInput);
275
+ this._floatingID = FloatingManager.float(this._listWrapper, this._listContainer, { autoClose: false, isFixed: true, backClickListener: () => this.hideOptions() });
276
+ this.setFocus();
277
+ window.requestAnimationFrame(() => {
278
+ this.updateListPosition();
279
+ if (!this.listOptionsPosition) {
280
+ this._listWrapper.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
281
+ }
282
+ });
283
+ }
284
+ hideOptions() {
285
+ if (this._floatingID !== undefined) {
286
+ FloatingManager.close(this._floatingID);
287
+ }
288
+ this._floatingID = undefined;
289
+ if (!!this._resizeObserver)
290
+ this._resizeObserver.unobserve(this._textInput);
291
+ }
292
+ isOptionsVisible() {
293
+ return this._floatingID !== undefined && FloatingManager.isFloating(this._floatingID);
294
+ }
295
+ nextOption() {
296
+ if (!this.isOptionsVisible()) {
297
+ return;
298
+ }
299
+ this.showOptions();
300
+ this._preSelection = this._preSelection === undefined ? 0 : Math.min(this._preSelection + 1, this._visibleOptions.length - 1);
301
+ this.scrollToOption(this._visibleOptions[this._preSelection]);
302
+ }
303
+ previousOption() {
304
+ this._preSelection = this._preSelection === undefined ? 0 : Math.max(this._preSelection - 1, 0);
305
+ this.scrollToOption(this._visibleOptions[this._preSelection]);
306
+ }
307
+ scrollToOption(opt) {
308
+ window.requestAnimationFrame(() => {
309
+ const liElem = (opt === null || opt === void 0 ? void 0 : opt.value) ? this._optionsList.querySelector(`div#item_${opt.value.replace(/[<>\[\]#=]/g, '\\$&').replace(/:/g, '\\:')}`) : undefined;
310
+ if (liElem)
311
+ liElem.scrollIntoView({ behavior: "smooth", block: "nearest" });
312
+ });
313
+ }
314
+ selectCurrentOption() {
315
+ if (this._preSelection !== undefined) {
316
+ this.selectOption(this._visibleOptions[this._preSelection]);
317
+ this._preSelection = undefined;
318
+ }
319
+ else {
320
+ this.controlListWithOnlyOne();
321
+ }
322
+ }
323
+ updateSource(source) {
324
+ this._startLoading = false;
325
+ if (source instanceof Promise) {
326
+ this._showLoading = true;
327
+ source.then(result => {
328
+ this._showLoading = false;
329
+ this.updateSource(result);
330
+ }).catch(() => this._showLoading = false);
331
+ this.updateVisibleOptions();
332
+ }
333
+ else {
334
+ this._showLoading = false;
335
+ if (Array.isArray(source)) {
336
+ this._source = source;
337
+ this.updateVisibleOptions();
338
+ if (this._tabPressed) {
339
+ this._tabPressed = false;
340
+ this.controlEmptySearch();
341
+ }
342
+ }
343
+ else {
344
+ this.selectOption(source);
345
+ }
346
+ }
347
+ }
348
+ clearSource() {
349
+ this._source = [];
350
+ this.updateVisibleOptions();
351
+ }
352
+ selectOption(newOption) {
53
353
  var _a, _b;
54
- (_b = (_a = this._comboElement) === null || _a === void 0 ? void 0 : _a['clearValue']) === null || _b === void 0 ? void 0 : _b.call(_a);
354
+ const currentValue = this.getSelectedOption(this.value);
355
+ if ((((_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.value) === null || _a === void 0 ? void 0 : _a.toString()) !== ((_b = newOption === null || newOption === void 0 ? void 0 : newOption.value) === null || _b === void 0 ? void 0 : _b.toString()))
356
+ || (currentValue == undefined && newOption != undefined && "value" in newOption)) {
357
+ const adjustedOpt = !(newOption === null || newOption === void 0 ? void 0 : newOption.value) ? undefined : newOption;
358
+ this.value = adjustedOpt;
359
+ }
360
+ else {
361
+ this.resetOptions();
362
+ }
363
+ this._visibleOptions = [];
364
+ this.clearSource();
55
365
  }
56
- /*
57
- * Retorna uma promise com o valor da opção selecionada,
58
- * que será resolvida quando o backend devolver este dado.
59
- */
60
- async getValueAsync() {
366
+ loadOptions(mode, argument = "") {
367
+ this._criteria = argument;
368
+ this._startLoading = true;
369
+ if (this.optionLoader) {
370
+ const searchArgument = { mode, argument };
371
+ this.updateSource(this.optionLoader(searchArgument));
372
+ }
373
+ else {
374
+ this.updateSource(this.options);
375
+ }
376
+ }
377
+ cancelPreselection() {
378
+ if (!this._textInput.value && this.value) {
379
+ this.selectOption(undefined);
380
+ }
381
+ else {
382
+ window.setTimeout(() => {
383
+ this.setInputValue();
384
+ }, this._deboucingTime);
385
+ }
386
+ this.resetOptions();
387
+ }
388
+ setInputValue(clearError = true) {
389
+ const textValue = this.getText();
390
+ if ((this._textInput.value || '') !== textValue) {
391
+ this._textInput.value = textValue;
392
+ if (clearError) {
393
+ this.errorMessage = null;
394
+ }
395
+ }
396
+ }
397
+ clearSearch() {
398
+ this.value = null;
399
+ }
400
+ controlListWithOnlyOne() {
401
+ var _a, _b;
402
+ const source = (_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.filter((opt) => opt.label !== "" && opt.value != undefined);
403
+ if ((source === null || source === void 0 ? void 0 : source.length) > 0) {
404
+ const startHighlight = new RegExp(this._startHighlightTag, 'g');
405
+ const endHighlight = new RegExp(this._endHighlightTag, 'g');
406
+ let title = StringUtils.decodeHtmlEntities(source[0].label);
407
+ const option = {
408
+ value: (_b = source[0].value) === null || _b === void 0 ? void 0 : _b.replace(startHighlight, '').replace(endHighlight, ''),
409
+ label: title === null || title === void 0 ? void 0 : title.replace(startHighlight, '').replace(endHighlight, '')
410
+ };
411
+ this.selectOption(option);
412
+ }
413
+ }
414
+ controlEmptySearch() {
61
415
  var _a;
62
- return (_a = this._comboElement) === null || _a === void 0 ? void 0 : _a.getValueAsync();
416
+ if (!((_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.length)) {
417
+ this.clearSearch();
418
+ ApplicationUtils.info(this._textEmptyList);
419
+ }
420
+ else {
421
+ this.controlListWithOnlyOne();
422
+ }
423
+ }
424
+ validateDescriptionValue() {
425
+ if (StringUtils.isEmpty(this.value)) {
426
+ return;
427
+ }
428
+ let value = this.value;
429
+ if (typeof value === "object") {
430
+ return;
431
+ }
432
+ if (StringUtils.isEmpty(value)) {
433
+ return;
434
+ }
435
+ this.loadDescriptionValue(value);
436
+ }
437
+ async loadDescriptionValue(argument) {
438
+ var _a, _b;
439
+ if (argument == undefined) {
440
+ return;
441
+ }
442
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.length) > 0) {
443
+ this.loadOptionValue(argument);
444
+ return;
445
+ }
446
+ const searchArgument = {
447
+ mode: SearchMode.PREDICTIVE,
448
+ argument
449
+ };
450
+ const source = await ((_b = this.optionLoader) === null || _b === void 0 ? void 0 : _b.call(this, searchArgument));
451
+ if (source == undefined) {
452
+ return;
453
+ }
454
+ if (source instanceof Promise) {
455
+ source.then((result) => {
456
+ this.setDescriptionValue(result);
457
+ });
458
+ }
459
+ else {
460
+ this.setDescriptionValue(source);
461
+ }
63
462
  }
64
- onComboChange(event) {
65
- event.stopPropagation();
66
- this.value = event.detail;
67
- this.ezChange.emit(event.detail);
68
- if (this.errorMessage !== this._comboElement.errorMessage) {
69
- this.errorMessage = this._comboElement.errorMessage;
463
+ setDescriptionValue(source) {
464
+ const value = (source === null || source === void 0 ? void 0 : source[0]) || source;
465
+ if (value == undefined || !Object.keys(value).length) {
466
+ this.showNoResultMessage();
467
+ return;
70
468
  }
469
+ this._lookupMode = true;
470
+ this.value = value;
471
+ }
472
+ loadOptionValue(argument) {
473
+ var _a;
474
+ const source = (_a = this.options) === null || _a === void 0 ? void 0 : _a.find((opt) => opt.value === argument);
475
+ if (source != undefined) {
476
+ this.selectOption(source);
477
+ }
478
+ else {
479
+ this.showNoResultMessage();
480
+ }
481
+ }
482
+ async showNoResultMessage() {
483
+ this.clearSearch();
484
+ ApplicationUtils.info(this._textEmptySearch.replace("{0}", this.getFieldLabel()));
485
+ }
486
+ getFieldLabel() {
487
+ var _a;
488
+ return (_a = this.label) === null || _a === void 0 ? void 0 : _a.replace(REQUIRED_INFO, "").toUpperCase();
489
+ }
490
+ resetOptions() {
491
+ this.hideOptions();
492
+ this._criteria = undefined;
493
+ this._preSelection = undefined;
494
+ this.updateVisibleOptions();
495
+ }
496
+ //---------------------------------------------
497
+ // Lifecycle web component
498
+ //---------------------------------------------
499
+ componentWillLoad() {
500
+ if (this.options === undefined) {
501
+ this.options = [];
502
+ const optionsTags = this.el.querySelectorAll("option");
503
+ if (optionsTags) {
504
+ optionsTags.forEach(e => {
505
+ let label = e.innerText;
506
+ let value = e.getAttribute("value");
507
+ let details = e.getAttribute("details");
508
+ if (!value) {
509
+ value = label;
510
+ }
511
+ this.options.push({ label, value, details });
512
+ e.hidden = true;
513
+ });
514
+ }
515
+ }
516
+ this.updateSource([]);
517
+ }
518
+ componentDidRender() {
519
+ var _a;
520
+ if (this._floatingID === undefined) {
521
+ this._listWrapper.remove();
522
+ }
523
+ (_a = this._optionsList) === null || _a === void 0 ? void 0 : _a.querySelectorAll(".item").forEach((elem) => {
524
+ ElementIDUtils.addIDInfoIfNotExists(elem, "itemSearch");
525
+ });
526
+ this.validateDescriptionValue();
71
527
  }
72
528
  componentDidLoad() {
73
- CSSVarsUtils.applyVarsTextInput(this._elem, this._comboElement);
529
+ CSSVarsUtils.applyVarsTextInput(this.el, this._textInput);
530
+ this.setInputValue(false);
531
+ this._resizeObserver = new ResizeObserver((entries) => {
532
+ window.requestAnimationFrame(() => {
533
+ if (!Array.isArray(entries) || !entries.length)
534
+ return;
535
+ const { clientWidth } = this._listContainer;
536
+ if (clientWidth > 0 && !!this._listWrapper) {
537
+ this._listWrapper.style.width = `${clientWidth}px`;
538
+ }
539
+ });
540
+ });
541
+ }
542
+ //---------------------------------------------
543
+ // Event handlers
544
+ //---------------------------------------------
545
+ handlerIconClick() {
546
+ this.loadOptions(SearchMode.ADVANCED);
547
+ }
548
+ buildNumberArgument(argument) {
549
+ if (this.isTextSearch) {
550
+ return NaN;
551
+ }
552
+ return Number(argument || undefined);
553
+ }
554
+ onTextInputChangeHandler(event) {
555
+ var _a;
556
+ this.clearDeboucingTimeout();
557
+ if (this._startLoading) {
558
+ this._changeDeboucingTimeout = window.setTimeout(() => {
559
+ this.onTextInputChangeHandler(event);
560
+ }, this._deboucingTime);
561
+ return;
562
+ }
563
+ const argument = (_a = event.target.value) === null || _a === void 0 ? void 0 : _a.trim();
564
+ const argumentNumber = this.buildNumberArgument(argument);
565
+ if (!this._criteria) {
566
+ this._textInput.value = event.data || argument;
567
+ }
568
+ this._criteria = argument;
569
+ if (argument) {
570
+ this._showLoading = false;
571
+ this.clearSource();
572
+ if (!isNaN(argumentNumber) || argument.length >= this._limitCharsToSearch) {
573
+ this._showLoading = true;
574
+ this._changeDeboucingTimeout = window.setTimeout(() => {
575
+ this.loadOptions(SearchMode.PREDICTIVE, isNaN(argumentNumber) ? argument : argumentNumber.toString());
576
+ }, this._deboucingTime);
577
+ this.showOptions();
578
+ }
579
+ else {
580
+ this.hideOptions();
581
+ }
582
+ }
583
+ else {
584
+ this.hideOptions();
585
+ this._showLoading = false;
586
+ this.clearSource();
587
+ }
588
+ }
589
+ clearDeboucingTimeout() {
590
+ if (this._changeDeboucingTimeout) {
591
+ window.clearTimeout(this._changeDeboucingTimeout);
592
+ this._changeDeboucingTimeout = null;
593
+ }
594
+ }
595
+ keyDownHandler(event) {
596
+ this._tabPressed = false;
597
+ if (event.ctrlKey) {
598
+ if (event.key === "f" || event.key === "F") {
599
+ this.loadOptions(SearchMode.ADVANCED);
600
+ //ATENÇÃO: Ctrl + F tem ação específica nos browsers
601
+ //nesse caso, como vamos abrir o popup de busca avançada,
602
+ //não é interessante deixar o evento propagar;
603
+ event.stopPropagation();
604
+ event.stopImmediatePropagation();
605
+ event.preventDefault();
606
+ }
607
+ }
608
+ switch (event.key) {
609
+ case "ArrowDown":
610
+ this.nextOption();
611
+ event.stopPropagation();
612
+ break;
613
+ case "ArrowUp":
614
+ this.previousOption();
615
+ event.stopPropagation();
616
+ break;
617
+ case "Enter":
618
+ this.selectCurrentOption();
619
+ break;
620
+ case "Escape":
621
+ this.cancelPreselection();
622
+ break;
623
+ case "Tab":
624
+ this._tabPressed = true;
625
+ this.controlListWithOnlyOne();
626
+ break;
627
+ }
628
+ //ATENÇÃO: Existe a necessidade de propagar o evento de teclado.
629
+ //Por exemplo, quando o usuário dá um Enter, além de selecionar
630
+ //um valor, também significa que a ateração finalizou,
631
+ //e o contexto pode reagir (fechar um popup por exemplo).
632
+ //event.stopPropagation();
633
+ }
634
+ onTextInputFocusOutHandler() {
635
+ if (this.hideErrorOnFocusOut)
636
+ this.cancelPreselection();
637
+ }
638
+ canShowListOptions() {
639
+ return !this._showLoading && this._visibleOptions.length > 0;
74
640
  }
75
641
  render() {
76
- ElementIDUtils.addIDInfoIfNotExists(this._elem, 'input');
77
- return (h("ez-combo-box", { "data-element-id": ElementIDUtils.getInternalIDInfo("combo"), ref: elem => this._comboElement = elem, value: this.value, label: this.label, enabled: this.enabled, errorMessage: this.errorMessage, hideErrorOnFocusOut: this.hideErrorOnFocusOut, optionLoader: this.optionLoader, searchMode: true, onEzChange: event => this.onComboChange(event), showSelectedValue: this.showSelectedValue, showOptionValue: this.showOptionValue, suppressEmptyOption: this.suppressEmptyOption, mode: this.mode, canShowError: this.canShowError, listOptionsPosition: this.listOptionsPosition, isTextSearch: this.isTextSearch, limitCharsToSearch: this.ignoreLimitCharsToSearch ? 0 : 3 }));
642
+ var _a;
643
+ ElementIDUtils.addIDInfoIfNotExists(this.el, 'input');
644
+ return (h(Host, null, h("ez-text-input", { "data-element-id": ElementIDUtils.getInternalIDInfo("textInput"), class: this.suppressSearch ? "suppressed-search-input" : "", ref: elem => this._textInput = elem, "data-slave-mode": "true", enabled: this.enabled && !this.suppressSearch, onInput: event => this.onTextInputChangeHandler(event), onFocusout: () => this.onTextInputFocusOutHandler(), onKeyDown: event => this.keyDownHandler(event), label: this.label, canShowError: this.canShowError, errorMessage: this.errorMessage, mode: this.mode }, h("button", { class: "btn", slot: "leftIcon", disabled: !this.enabled, tabindex: -1, onClick: () => this.handlerIconClick() }, h("ez-icon", { iconName: "search" })), ((_a = this._textInput) === null || _a === void 0 ? void 0 : _a.value) && (this._criteria || this.value)
645
+ ? h("button", { class: "btn btn__close", slot: "rightIcon", disabled: !this.enabled, tabindex: -1, onClick: () => this.clearSearch() }, h("ez-icon", { iconName: "close" }))
646
+ : undefined), h("section", { class: "list-container", ref: elem => this._listContainer = elem }, h("div", { class: "list-wrapper", ref: elem => this._listWrapper = elem }, h("ul", { class: "list-options", ref: elem => this._optionsList = elem }, !this._showLoading
647
+ && this._visibleOptions.length === 0
648
+ && h("div", { class: "message" }, h("span", { class: "message__no-result" }, this._textEmptyList)), this._showLoading
649
+ && h("div", { class: "message" }, h("div", { class: "message__loading" })), h("span", { class: "item__value item__value--hidden", ref: elem => this._itemValueBasis = elem }), this.canShowListOptions() && this._visibleOptions.map((opt, index) => this.buildItem(opt, index)))))));
78
650
  }
79
- ;
80
651
  static get is() { return "ez-search"; }
81
652
  static get encapsulation() { return "shadow"; }
82
653
  static get originalStyleUrls() {
@@ -99,8 +670,7 @@ export class EzSearch {
99
670
  "resolved": "IOption | string",
100
671
  "references": {
101
672
  "IOption": {
102
- "location": "import",
103
- "path": "../ez-combo-box/ez-combo-box"
673
+ "location": "local"
104
674
  }
105
675
  }
106
676
  },
@@ -173,8 +743,7 @@ export class EzSearch {
173
743
  "resolved": "(argument: ISearchArgument) => IOption | IOption[] | Promise<IOption[]>",
174
744
  "references": {
175
745
  "ISearchArgument": {
176
- "location": "import",
177
- "path": "../ez-combo-box/ez-combo-box"
746
+ "location": "local"
178
747
  },
179
748
  "Promise": {
180
749
  "location": "global"
@@ -183,8 +752,7 @@ export class EzSearch {
183
752
  "location": "global"
184
753
  },
185
754
  "IOption": {
186
- "location": "import",
187
- "path": "../ez-combo-box/ez-combo-box"
755
+ "location": "local"
188
756
  }
189
757
  }
190
758
  },
@@ -358,9 +926,58 @@ export class EzSearch {
358
926
  "attribute": "ignore-limit-chars-to-search",
359
927
  "reflect": false,
360
928
  "defaultValue": "false"
929
+ },
930
+ "options": {
931
+ "type": "unknown",
932
+ "mutable": true,
933
+ "complexType": {
934
+ "original": "Array<IOption>",
935
+ "resolved": "IOption[]",
936
+ "references": {
937
+ "Array": {
938
+ "location": "global"
939
+ },
940
+ "IOption": {
941
+ "location": "local"
942
+ }
943
+ }
944
+ },
945
+ "required": false,
946
+ "optional": false,
947
+ "docs": {
948
+ "tags": [],
949
+ "text": "Array com as op\u00E7\u00F5es do ez-combo-box. Os elementos devem obedecer\no formato: `{value: string, label: string}`."
950
+ }
951
+ },
952
+ "suppressSearch": {
953
+ "type": "boolean",
954
+ "mutable": false,
955
+ "complexType": {
956
+ "original": "boolean",
957
+ "resolved": "boolean",
958
+ "references": {}
959
+ },
960
+ "required": false,
961
+ "optional": false,
962
+ "docs": {
963
+ "tags": [],
964
+ "text": "Se true desabilita a digita\u00E7\u00E3o dentro do componente."
965
+ },
966
+ "attribute": "suppress-search",
967
+ "reflect": false,
968
+ "defaultValue": "false"
361
969
  }
362
970
  };
363
971
  }
972
+ static get states() {
973
+ return {
974
+ "_preSelection": {},
975
+ "_visibleOptions": {},
976
+ "_startLoading": {},
977
+ "_showLoading": {},
978
+ "_criteria": {}
979
+ };
980
+ }
364
981
  static get events() {
365
982
  return [{
366
983
  "method": "ezChange",
@@ -377,8 +994,7 @@ export class EzSearch {
377
994
  "resolved": "IOption",
378
995
  "references": {
379
996
  "IOption": {
380
- "location": "import",
381
- "path": "../ez-combo-box/ez-combo-box"
997
+ "location": "local"
382
998
  }
383
999
  }
384
1000
  }
@@ -386,6 +1002,22 @@ export class EzSearch {
386
1002
  }
387
1003
  static get methods() {
388
1004
  return {
1005
+ "getValueAsync": {
1006
+ "complexType": {
1007
+ "signature": "() => Promise<unknown>",
1008
+ "parameters": [],
1009
+ "references": {
1010
+ "Promise": {
1011
+ "location": "global"
1012
+ }
1013
+ },
1014
+ "return": "Promise<unknown>"
1015
+ },
1016
+ "docs": {
1017
+ "text": "",
1018
+ "tags": []
1019
+ }
1020
+ },
389
1021
  "setFocus": {
390
1022
  "complexType": {
391
1023
  "signature": "() => Promise<void>",
@@ -449,26 +1081,10 @@ export class EzSearch {
449
1081
  "text": "Limpa o valor do campo de pesquisa",
450
1082
  "tags": []
451
1083
  }
452
- },
453
- "getValueAsync": {
454
- "complexType": {
455
- "signature": "() => Promise<unknown>",
456
- "parameters": [],
457
- "references": {
458
- "Promise": {
459
- "location": "global"
460
- }
461
- },
462
- "return": "Promise<unknown>"
463
- },
464
- "docs": {
465
- "text": "",
466
- "tags": []
467
- }
468
1084
  }
469
1085
  };
470
1086
  }
471
- static get elementRef() { return "_elem"; }
1087
+ static get elementRef() { return "el"; }
472
1088
  static get watchers() {
473
1089
  return [{
474
1090
  "propName": "errorMessage",
@@ -476,6 +1092,24 @@ export class EzSearch {
476
1092
  }, {
477
1093
  "propName": "value",
478
1094
  "methodName": "observeValue"
1095
+ }, {
1096
+ "propName": "options",
1097
+ "methodName": "observeOptions"
1098
+ }];
1099
+ }
1100
+ static get listeners() {
1101
+ return [{
1102
+ "name": "scroll",
1103
+ "method": "scrollListener",
1104
+ "target": "window",
1105
+ "capture": true,
1106
+ "passive": true
479
1107
  }];
480
1108
  }
481
1109
  }
1110
+ var SearchMode;
1111
+ (function (SearchMode) {
1112
+ SearchMode["ADVANCED"] = "ADVANCED";
1113
+ SearchMode["PRELOAD"] = "PRELOAD";
1114
+ SearchMode["PREDICTIVE"] = "PREDICTIVE";
1115
+ })(SearchMode || (SearchMode = {}));