@sankhyalabs/ezui 5.19.1 → 5.20.0-dev.2

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 (174) hide show
  1. package/dist/cjs/ez-actions-button.cjs.entry.js +1 -1
  2. package/dist/cjs/ez-alert-list.cjs.entry.js +79 -23
  3. package/dist/cjs/ez-alert.cjs.entry.js +1 -1
  4. package/dist/cjs/ez-application.cjs.entry.js +1 -1
  5. package/dist/cjs/ez-badge.cjs.entry.js +1 -1
  6. package/dist/cjs/ez-breadcrumb.cjs.entry.js +1 -1
  7. package/dist/cjs/ez-button.cjs.entry.js +1 -1
  8. package/dist/cjs/ez-calendar.cjs.entry.js +1 -1
  9. package/dist/cjs/ez-card-item_3.cjs.entry.js +182 -0
  10. package/dist/cjs/ez-check.cjs.entry.js +1 -1
  11. package/dist/cjs/ez-chip.cjs.entry.js +1 -1
  12. package/dist/cjs/ez-collapsible-box.cjs.entry.js +1 -1
  13. package/dist/cjs/ez-combo-box.cjs.entry.js +12 -156
  14. package/dist/cjs/ez-date-input.cjs.entry.js +1 -1
  15. package/dist/cjs/ez-date-time-input.cjs.entry.js +1 -1
  16. package/dist/cjs/ez-dialog.cjs.entry.js +1 -1
  17. package/dist/cjs/ez-dropdown.cjs.entry.js +10 -4
  18. package/dist/cjs/ez-file-item.cjs.entry.js +1 -1
  19. package/dist/cjs/ez-form-view.cjs.entry.js +1 -1
  20. package/dist/cjs/ez-form.cjs.entry.js +1 -1
  21. package/dist/cjs/ez-grid.cjs.entry.js +1 -1
  22. package/dist/cjs/ez-guide-navigator.cjs.entry.js +1 -1
  23. package/dist/cjs/ez-icon.cjs.entry.js +1 -1
  24. package/dist/cjs/ez-list.cjs.entry.js +1 -1
  25. package/dist/cjs/ez-loading-bar.cjs.entry.js +1 -1
  26. package/dist/cjs/ez-modal-container.cjs.entry.js +1 -1
  27. package/dist/cjs/ez-modal.cjs.entry.js +1 -1
  28. package/dist/cjs/ez-multi-selection-list.cjs.entry.js +1 -1
  29. package/dist/cjs/ez-number-input.cjs.entry.js +1 -1
  30. package/dist/cjs/ez-popover.cjs.entry.js +1 -1
  31. package/dist/cjs/ez-popup.cjs.entry.js +1 -1
  32. package/dist/cjs/ez-radio-button.cjs.entry.js +1 -1
  33. package/dist/cjs/ez-scroller_3.cjs.entry.js +1 -1
  34. package/dist/cjs/ez-search.cjs.entry.js +612 -32
  35. package/dist/cjs/ez-skeleton.cjs.entry.js +1 -1
  36. package/dist/cjs/ez-split-item.cjs.entry.js +1 -1
  37. package/dist/cjs/ez-split-panel.cjs.entry.js +1 -1
  38. package/dist/cjs/ez-tabselector.cjs.entry.js +1 -1
  39. package/dist/cjs/ez-text-area.cjs.entry.js +1 -1
  40. package/dist/cjs/ez-text-edit.cjs.entry.js +1 -1
  41. package/dist/cjs/ez-text-input.cjs.entry.js +1 -1
  42. package/dist/cjs/ez-time-input.cjs.entry.js +1 -1
  43. package/dist/cjs/ez-toast.cjs.entry.js +1 -1
  44. package/dist/cjs/ez-upload.cjs.entry.js +1 -1
  45. package/dist/cjs/ez-view-stack.cjs.entry.js +1 -1
  46. package/dist/cjs/ezui.cjs.js +2 -2
  47. package/dist/cjs/filter-column.cjs.entry.js +1 -1
  48. package/dist/cjs/{index-1064511f.js → index-a7b0c73d.js} +4 -6
  49. package/dist/cjs/loader.cjs.js +2 -2
  50. package/dist/collection/collection-manifest.json +2 -2
  51. package/dist/collection/components/ez-alert-list/ez-alert-list.css +15 -1
  52. package/dist/collection/components/ez-alert-list/ez-alert-list.js +80 -22
  53. package/dist/collection/components/ez-card-item/ez-card-item.css +16 -0
  54. package/dist/collection/components/ez-combo-box/ez-combo-box.js +12 -173
  55. package/dist/collection/components/ez-dropdown/ez-dropdown.js +32 -3
  56. package/dist/collection/components/ez-search/ez-search.css +330 -0
  57. package/dist/collection/components/ez-search/ez-search.js +689 -55
  58. package/dist/custom-elements/index.js +716 -221
  59. package/dist/esm/ez-actions-button.entry.js +1 -1
  60. package/dist/esm/ez-alert-list.entry.js +79 -23
  61. package/dist/esm/ez-alert.entry.js +1 -1
  62. package/dist/esm/ez-application.entry.js +1 -1
  63. package/dist/esm/ez-badge.entry.js +1 -1
  64. package/dist/esm/ez-breadcrumb.entry.js +1 -1
  65. package/dist/esm/ez-button.entry.js +1 -1
  66. package/dist/esm/ez-calendar.entry.js +1 -1
  67. package/dist/esm/ez-card-item_3.entry.js +176 -0
  68. package/dist/esm/ez-check.entry.js +1 -1
  69. package/dist/esm/ez-chip.entry.js +1 -1
  70. package/dist/esm/ez-collapsible-box.entry.js +1 -1
  71. package/dist/esm/ez-combo-box.entry.js +13 -157
  72. package/dist/esm/ez-date-input.entry.js +1 -1
  73. package/dist/esm/ez-date-time-input.entry.js +1 -1
  74. package/dist/esm/ez-dialog.entry.js +1 -1
  75. package/dist/esm/ez-dropdown.entry.js +10 -4
  76. package/dist/esm/ez-file-item.entry.js +1 -1
  77. package/dist/esm/ez-form-view.entry.js +1 -1
  78. package/dist/esm/ez-form.entry.js +1 -1
  79. package/dist/esm/ez-grid.entry.js +1 -1
  80. package/dist/esm/ez-guide-navigator.entry.js +1 -1
  81. package/dist/esm/ez-icon.entry.js +1 -1
  82. package/dist/esm/ez-list.entry.js +1 -1
  83. package/dist/esm/ez-loading-bar.entry.js +1 -1
  84. package/dist/esm/ez-modal-container.entry.js +1 -1
  85. package/dist/esm/ez-modal.entry.js +1 -1
  86. package/dist/esm/ez-multi-selection-list.entry.js +1 -1
  87. package/dist/esm/ez-number-input.entry.js +1 -1
  88. package/dist/esm/ez-popover.entry.js +1 -1
  89. package/dist/esm/ez-popup.entry.js +1 -1
  90. package/dist/esm/ez-radio-button.entry.js +1 -1
  91. package/dist/esm/ez-scroller_3.entry.js +1 -1
  92. package/dist/esm/ez-search.entry.js +613 -33
  93. package/dist/esm/ez-skeleton.entry.js +1 -1
  94. package/dist/esm/ez-split-item.entry.js +1 -1
  95. package/dist/esm/ez-split-panel.entry.js +1 -1
  96. package/dist/esm/ez-tabselector.entry.js +1 -1
  97. package/dist/esm/ez-text-area.entry.js +1 -1
  98. package/dist/esm/ez-text-edit.entry.js +1 -1
  99. package/dist/esm/ez-text-input.entry.js +1 -1
  100. package/dist/esm/ez-time-input.entry.js +1 -1
  101. package/dist/esm/ez-toast.entry.js +1 -1
  102. package/dist/esm/ez-upload.entry.js +1 -1
  103. package/dist/esm/ez-view-stack.entry.js +1 -1
  104. package/dist/esm/ezui.js +3 -3
  105. package/dist/esm/filter-column.entry.js +1 -1
  106. package/dist/esm/{index-296b8458.js → index-baa5e267.js} +4 -6
  107. package/dist/esm/loader.js +3 -3
  108. package/dist/ezui/ezui.esm.js +1 -1
  109. package/dist/ezui/{p-5cef0264.entry.js → p-0306dff7.entry.js} +1 -1
  110. package/dist/ezui/{p-871c1a07.entry.js → p-0447d17c.entry.js} +1 -1
  111. package/dist/ezui/p-072e6347.entry.js +1 -0
  112. package/dist/ezui/p-133fae4a.entry.js +1 -0
  113. package/dist/ezui/{p-f4208819.entry.js → p-17be134a.entry.js} +1 -1
  114. package/dist/ezui/{p-cd19a6f8.entry.js → p-1e7a8633.entry.js} +1 -1
  115. package/dist/ezui/{p-60ba28ea.entry.js → p-1f50fa05.entry.js} +1 -1
  116. package/dist/ezui/{p-245a44ed.entry.js → p-20ec22c0.entry.js} +1 -1
  117. package/dist/ezui/{p-e318d280.js → p-23a36bb6.js} +1 -1
  118. package/dist/ezui/{p-ce035beb.entry.js → p-24d3fede.entry.js} +1 -1
  119. package/dist/ezui/{p-8252d9b5.entry.js → p-2a1a0e04.entry.js} +1 -1
  120. package/dist/ezui/{p-22208198.entry.js → p-40f72de4.entry.js} +1 -1
  121. package/dist/ezui/p-43b03119.entry.js +1 -0
  122. package/dist/ezui/{p-9b347f04.entry.js → p-44caad9a.entry.js} +1 -1
  123. package/dist/ezui/{p-7319c253.entry.js → p-49456b34.entry.js} +1 -1
  124. package/dist/ezui/{p-7fd54841.entry.js → p-4a7f113d.entry.js} +1 -1
  125. package/dist/ezui/{p-99692afa.entry.js → p-51c5e071.entry.js} +1 -1
  126. package/dist/ezui/{p-ccb4ccd9.entry.js → p-555c9018.entry.js} +1 -1
  127. package/dist/ezui/{p-d43b22f3.entry.js → p-596634e9.entry.js} +1 -1
  128. package/dist/ezui/{p-52dd8b4c.entry.js → p-5bd5e68f.entry.js} +1 -1
  129. package/dist/ezui/{p-a01068e1.entry.js → p-5d692ed1.entry.js} +1 -1
  130. package/dist/ezui/{p-95426f93.entry.js → p-5d86cca9.entry.js} +1 -1
  131. package/dist/ezui/{p-62304715.entry.js → p-5e1d036e.entry.js} +1 -1
  132. package/dist/ezui/{p-7525e604.entry.js → p-5ed81457.entry.js} +1 -1
  133. package/dist/ezui/{p-c49dbf23.entry.js → p-650e4b6d.entry.js} +1 -1
  134. package/dist/ezui/{p-4b988ee7.entry.js → p-6e2f8e6b.entry.js} +1 -1
  135. package/dist/ezui/{p-f55d75e7.entry.js → p-6e429cff.entry.js} +1 -1
  136. package/dist/ezui/p-76ba9d67.entry.js +1 -0
  137. package/dist/ezui/{p-0b902469.entry.js → p-77a4bd35.entry.js} +1 -1
  138. package/dist/ezui/{p-b6867f19.entry.js → p-796c1a88.entry.js} +1 -1
  139. package/dist/ezui/{p-5d6f2550.entry.js → p-85c8baae.entry.js} +1 -1
  140. package/dist/ezui/{p-fa571a4e.entry.js → p-8becebf8.entry.js} +1 -1
  141. package/dist/ezui/{p-d3b5228e.entry.js → p-8defa6d3.entry.js} +1 -1
  142. package/dist/ezui/{p-391de0e4.entry.js → p-9050d2cd.entry.js} +1 -1
  143. package/dist/ezui/{p-028f264f.entry.js → p-9cad9b6e.entry.js} +1 -1
  144. package/dist/ezui/{p-b11f035c.entry.js → p-9f5fa3f9.entry.js} +1 -1
  145. package/dist/ezui/{p-d81917fd.entry.js → p-a08b309b.entry.js} +1 -1
  146. package/dist/ezui/{p-2da09f70.entry.js → p-a80b1287.entry.js} +1 -1
  147. package/dist/ezui/{p-a42fe2ce.entry.js → p-af15c277.entry.js} +1 -1
  148. package/dist/ezui/{p-32b4163f.entry.js → p-b041333c.entry.js} +1 -1
  149. package/dist/ezui/p-ba875f37.entry.js +1 -0
  150. package/dist/ezui/p-bc2f844e.entry.js +1 -0
  151. package/dist/ezui/{p-e2dfd935.entry.js → p-c0f1715f.entry.js} +1 -1
  152. package/dist/ezui/{p-83885b21.entry.js → p-cc2dc4f4.entry.js} +1 -1
  153. package/dist/ezui/{p-76d16a24.entry.js → p-d6ffe679.entry.js} +1 -1
  154. package/dist/ezui/{p-3e7cc8a4.entry.js → p-eb36f072.entry.js} +1 -1
  155. package/dist/ezui/{p-d20ed286.entry.js → p-f56dd1da.entry.js} +1 -1
  156. package/dist/types/components/ez-alert-list/ez-alert-list.d.ts +32 -3
  157. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +0 -15
  158. package/dist/types/components/ez-dropdown/ez-dropdown.d.ts +5 -0
  159. package/dist/types/components/ez-search/ez-search.d.ts +100 -10
  160. package/dist/types/components.d.ts +27 -14
  161. package/dist/types/utils/interfaces/AbstractFieldMetadata.d.ts +2 -1
  162. package/dist/types/utils/interfaces/IAction.d.ts +1 -1
  163. package/package.json +1 -1
  164. package/dist/cjs/ez-card-item.cjs.entry.js +0 -52
  165. package/dist/cjs/ez-filter-input_2.cjs.entry.js +0 -137
  166. package/dist/esm/ez-card-item.entry.js +0 -48
  167. package/dist/esm/ez-filter-input_2.entry.js +0 -132
  168. package/dist/ezui/p-47afb974.entry.js +0 -1
  169. package/dist/ezui/p-59bcb27c.entry.js +0 -1
  170. package/dist/ezui/p-74049254.entry.js +0 -1
  171. package/dist/ezui/p-87e85160.entry.js +0 -1
  172. package/dist/ezui/p-d51aa09b.entry.js +0 -1
  173. package/dist/ezui/p-f8653522.entry.js +0 -1
  174. package/dist/ezui/p-ffa8ec98.entry.js +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%" }, 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(`li#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 = {}));