@sankhyalabs/ezui 5.20.0-dev.2 → 5.20.0-dev.4

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 (62) 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.cjs.entry.js +52 -0
  4. package/dist/cjs/ez-combo-box.cjs.entry.js +155 -11
  5. package/dist/cjs/ez-filter-input_2.cjs.entry.js +137 -0
  6. package/dist/cjs/ez-form-view.cjs.entry.js +4 -2
  7. package/dist/cjs/ez-grid.cjs.entry.js +3 -3
  8. package/dist/cjs/ez-icon.cjs.entry.js +1 -1
  9. package/dist/cjs/ez-search.cjs.entry.js +31 -611
  10. package/dist/cjs/ez-split-panel.cjs.entry.js +3 -2
  11. package/dist/cjs/ezui.cjs.js +1 -1
  12. package/dist/cjs/index-a7b0c73d.js +6 -2
  13. package/dist/cjs/loader.cjs.js +1 -1
  14. package/dist/collection/collection-manifest.json +2 -2
  15. package/dist/collection/components/ez-alert-list/ez-alert-list.js +33 -28
  16. package/dist/collection/components/ez-card-item/ez-card-item.css +0 -16
  17. package/dist/collection/components/ez-combo-box/ez-combo-box.js +173 -12
  18. package/dist/collection/components/ez-form-view/fieldbuilder/templates/FileInput.tpl.js +4 -2
  19. package/dist/collection/components/ez-grid/ez-grid.css +1 -0
  20. package/dist/collection/components/ez-grid/ez-grid.js +2 -2
  21. package/dist/collection/components/ez-icon/ez-icon.css +1 -1
  22. package/dist/collection/components/ez-search/ez-search.css +0 -330
  23. package/dist/collection/components/ez-search/ez-search.js +55 -689
  24. package/dist/collection/components/ez-split-panel/ez-split-panel.css +7 -0
  25. package/dist/collection/components/ez-split-panel/ez-split-panel.js +19 -1
  26. package/dist/custom-elements/index.js +240 -665
  27. package/dist/esm/ez-alert-list.entry.js +33 -28
  28. package/dist/esm/ez-card-item.entry.js +48 -0
  29. package/dist/esm/ez-combo-box.entry.js +156 -12
  30. package/dist/esm/ez-filter-input_2.entry.js +132 -0
  31. package/dist/esm/ez-form-view.entry.js +4 -2
  32. package/dist/esm/ez-grid.entry.js +3 -3
  33. package/dist/esm/ez-icon.entry.js +1 -1
  34. package/dist/esm/ez-search.entry.js +33 -613
  35. package/dist/esm/ez-split-panel.entry.js +3 -2
  36. package/dist/esm/ezui.js +1 -1
  37. package/dist/esm/index-baa5e267.js +6 -2
  38. package/dist/esm/loader.js +1 -1
  39. package/dist/ezui/ezui.esm.js +1 -1
  40. package/dist/ezui/p-05f5a778.entry.js +1 -0
  41. package/dist/ezui/p-13dbad96.entry.js +1 -0
  42. package/dist/ezui/p-5613fe63.entry.js +1 -0
  43. package/dist/ezui/p-60848ef6.entry.js +1 -0
  44. package/dist/ezui/{p-6e2f8e6b.entry.js → p-844ee673.entry.js} +1 -1
  45. package/dist/ezui/{p-f56dd1da.entry.js → p-93c3df4f.entry.js} +1 -1
  46. package/dist/ezui/p-940ed30b.entry.js +1 -0
  47. package/dist/ezui/p-a32aaac6.entry.js +1 -0
  48. package/dist/ezui/p-a5ac7151.entry.js +1 -0
  49. package/dist/types/components/ez-alert-list/ez-alert-list.d.ts +1 -1
  50. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +15 -0
  51. package/dist/types/components/ez-search/ez-search.d.ts +10 -100
  52. package/dist/types/components.d.ts +22 -23
  53. package/dist/types/utils/interfaces/AbstractFieldMetadata.d.ts +1 -2
  54. package/package.json +16 -8
  55. package/dist/cjs/ez-card-item_3.cjs.entry.js +0 -182
  56. package/dist/esm/ez-card-item_3.entry.js +0 -176
  57. package/dist/ezui/p-133fae4a.entry.js +0 -1
  58. package/dist/ezui/p-43b03119.entry.js +0 -1
  59. package/dist/ezui/p-4a7f113d.entry.js +0 -1
  60. package/dist/ezui/p-76ba9d67.entry.js +0 -1
  61. package/dist/ezui/p-796c1a88.entry.js +0 -1
  62. package/dist/ezui/p-ba875f37.entry.js +0 -1
@@ -1,32 +1,13 @@
1
- import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-baa5e267.js';
1
+ import { r as registerInstance, c as createEvent, h, g as getElement } from './index-baa5e267.js';
2
2
  import { C as CSSVarsUtils } from './CSSVarsUtils-a97cfa29.js';
3
- import { ObjectUtils, StringUtils, FloatingManager, ElementIDUtils } from '@sankhyalabs/core';
4
- import { A as ApplicationUtils } from './ApplicationUtils-eaf91331.js';
5
- import './DialogType-54a62731.js';
6
- import './CheckMode-bdb2ec19.js';
7
- import { R as REQUIRED_INFO } from './constants-4e0d35b7.js';
3
+ import { ElementIDUtils } from '@sankhyalabs/core';
8
4
 
9
- const ezSearchCss = ":host{--ez-search--height:42px;--ez-search--width:100%;--ez-search__icon--width:48px;--ez-search--border-radius:var(--border--radius-medium, 12px);--ez-search--border-radius-small:var(--border--radius-small, 6px);--ez-search--font-size:var(--text--medium, 14px);--ez-search--font-family:var(--font-pattern, Arial);--ez-search--font-weight--large:var(--text-weight--large, 500);--ez-search--font-weight--medium:var(--text-weight--medium, 400);--ez-search--background-color--xlight:var(--background--xlight, #fff);--ez-search--background-medium:var(--background--medium, #f0f3f7);--ez-search--line-height:calc(var(--text--medium, 14px) + 4px);--ez-search__input--background-color:var(--background--medium, #e0e0e0);--ez-search__input--border:var(--border--medium, 2px solid);--ez-search__input--border-color:var(--ez-search__input--background-color);--ez-search__input--focus--border-color:var(--color--primary, #008561);--ez-search__input--disabled--background-color:var(--color--disable-secondary, #F2F5F8);--ez-search__input--disabled--color:var(--text--disable, #AFB6C0);--ez-search__input--error--border-color:#CC2936;--ez-search__btn--color:var(--title--primary, #2B3A54);--ez-search__btn-disabled--color:var(--text--disable, #AFB6C0);--ez-search__btn-hover--color:var(--color--primary, #4e4e4e);--ez-search__label--color:var(--title--primary, #2B3A54);--ez-search__list-title--primary:var(--title--primary, #2B3A54);--ez-search__list-text--primary:var(--text--primary, #626e82);--ez-search__list-height:calc(var(--ez-search--font-size) + var(--ez-search--space--medium) + 4px);--ez-search__list-min-width:64px;--ez-search--space--medium:var(--space--medium, 12px);--ez-search--space--small:var(--space--small, 6px);--ez-search__scrollbar--color-default:var(--scrollbar--default, #626e82);--ez-search__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--ez-search__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--ez-search__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--ez-search__scrollbar--border-radius:var(--border--radius-small, 6px);--ez-search__scrollbar--width:var(--space--medium, 12px);display:flex;flex-wrap:wrap;position:relative;width:var(--ez-search--width)}ez-icon{--ez-icon--color:inherit;font-weight:var(--text-weight--large, 600)}.suppressed-search-input{--ez-text-input__input--border-color:var(--color--strokes, #dce0e8);--ez-text-input__input--disabled--background-color:var(--background--xlight, #fff);--ez-text-input__input--disabled--color:var(--title--primary, #2B3A54)}.list-container{min-width:var(--ez-search__list-min-width);position:relative;width:100%}.list-wrapper{display:flex;flex-direction:column;box-sizing:border-box;width:0;z-index:var(--more-visible, 2);max-height:350px;background-color:var(--ez-search--background-color--xlight);border-radius:var(--ez-search--border-radius);box-shadow:var(--shadow, 0px 0px 16px 0px #000);padding:var(--ez-search--space--small)}.list-options{box-sizing:border-box;width:100%;height:100%;padding:0;display:flex;flex-direction:column;scroll-behavior:smooth;overflow:auto;scrollbar-width:thin;gap:3px;scrollbar-color:var(--ez-search__scrollbar--color-clicked) var(--ez-search__scrollbar--color-background)}.list-options::-webkit-scrollbar{background-color:var(--ez-search__scrollbar--color-background);width:var(--ez-search__scrollbar--width);max-width:var(--ez-search__scrollbar--width);min-width:var(--ez-search__scrollbar--width)}.list-options::-webkit-scrollbar-track{background-color:var(--ez-search__scrollbar--color-background);border-radius:var(--ez-search__scrollbar--border-radius)}.list-options::-webkit-scrollbar-thumb{background-color:var(--ez-search__scrollbar--color-default);border-radius:var(--ez-search__scrollbar--border-radius)}.list-options::-webkit-scrollbar-thumb:vertical:hover,.list-options::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--ez-search__scrollbar--color-hover)}.list-options::-webkit-scrollbar-thumb:vertical:active,.list-options::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--ez-search__scrollbar--color-clicked)}.item{display:flex;align-items:center;width:100%;box-sizing:border-box;list-style-type:none;cursor:pointer;border-radius:var(--ez-search--border-radius-small);padding:var(--ez-search--space--small);min-height:var(--ez-search__list-height);gap:var(--space--small, 6px)}.item__value,.item__label{flex-basis:auto;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--ez-search__list-title--primary);font-family:var(--ez-search--font-family);font-size:var(--ez-search--font-size);line-height:var(--ez-search--line-height)}.item__label{font-weight:var(--ez-search--font-weight--medium)}.item__label--bold{font-weight:var(--ez-search--font-weight--large)}.item__value{text-align:center;color:var(--ez-search__list-text--primary);font-weight:var(--ez-search--font-weight--large)}.item__value--hidden{visibility:hidden;position:absolute;white-space:nowrap;z-index:-1;top:0;left:0}.item__label{text-align:left}.message{text-align:center;display:flex;justify-content:center;align-items:center;list-style-type:none;min-height:var(--ez-search__list-height)}.message__no-result{color:var(--ez-search__list-title--primary);font-family:var(--ez-search--font-family);font-size:var(--ez-search--font-size)}.message__loading{border-radius:50%;width:14px;height:14px;-webkit-animation:spin 1s linear infinite;animation:spin 1s linear infinite;border:3px solid var(--ez-search__list-title--primary);border-top:3px solid transparent}.item__list>li:hover{background-color:var(--ez-search--background-medium)}.preselected{background-color:var(--background--medium)}.btn{outline:none;border:none;background:none;cursor:pointer;color:var(--ez-search__btn--color)}.btn:disabled{cursor:unset;color:var(--ez-search__btn-disabled--color)}.btn:disabled:hover{cursor:unset;color:var(--ez-search__btn-disabled--color)}.btn:hover{color:var(--ez-search__btn-hover--color)}.btn__close{visibility:hidden}ez-text-input:hover .btn__close,ez-text-input:focus .btn__close{visibility:visible}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}";
5
+ const ezSearchCss = ":host{width:100%}";
10
6
 
11
7
  const EzSearch = class {
12
8
  constructor(hostRef) {
13
9
  registerInstance(this, hostRef);
14
10
  this.ezChange = createEvent(this, "ezChange", 7);
15
- this._changeDeboucingTimeout = null;
16
- this._limitCharsToSearch = 3;
17
- this._deboucingTime = 300;
18
- this._maxWidthValue = 0;
19
- this._tabPressed = false;
20
- this._textEmptyList = "Nenhum resultado encontrado";
21
- this._textEmptySearch = "Nenhum resultado de {0} encontrado";
22
- this._lookupMode = false;
23
- this._startHighlightTag = "<span class='card-item__highlight'>";
24
- this._endHighlightTag = "</span>";
25
- this._preSelection = undefined;
26
- this._visibleOptions = undefined;
27
- this._startLoading = false;
28
- this._showLoading = true;
29
- this._criteria = undefined;
30
11
  this.value = undefined;
31
12
  this.label = undefined;
32
13
  this.enabled = true;
@@ -41,82 +22,28 @@ const EzSearch = class {
41
22
  this.listOptionsPosition = undefined;
42
23
  this.isTextSearch = false;
43
24
  this.ignoreLimitCharsToSearch = false;
44
- this.options = undefined;
45
- this.suppressSearch = false;
46
25
  }
47
26
  observeErrorMessage() {
48
- var _a;
49
- if (this._textInput) {
50
- this._textInput.errorMessage = this.errorMessage;
51
- if (!((_a = this.errorMessage) === null || _a === void 0 ? void 0 : _a.trim())) {
52
- this.setInputValue();
53
- }
54
- }
55
- }
56
- observeValue(newValue, oldValue) {
57
- if (this._textInput && newValue != oldValue) {
58
- try {
59
- if (newValue === "string") {
60
- this.setInputValue();
61
- return;
62
- }
63
- const newValueSelected = this.getSelectedOption(newValue);
64
- const oldValueSelected = this.getSelectedOption(oldValue);
65
- const currentValue = this.getSelectedOption(this.value);
66
- if (this.isDifferentValues(currentValue, newValueSelected)) {
67
- this.value = newValueSelected;
68
- }
69
- if (this.isDifferentValues(newValueSelected, oldValueSelected)) {
70
- this.setInputValue();
71
- const valueEmitted = newValueSelected === null ? undefined : newValueSelected;
72
- if (!this._lookupMode) {
73
- this.ezChange.emit(valueEmitted);
74
- }
75
- }
76
- this.resetOptions();
77
- }
78
- finally {
79
- this._lookupMode = false;
80
- }
27
+ if (this._comboElement) {
28
+ this._comboElement.errorMessage = this.errorMessage;
81
29
  }
82
30
  }
83
- observeOptions(newOptions, oldOptions) {
84
- if ((newOptions === null || newOptions === void 0 ? void 0 : newOptions.join('')) === (oldOptions === null || oldOptions === void 0 ? void 0 : oldOptions.join('')))
85
- return;
86
- this.loadOptions(SearchMode.PRELOAD);
87
- }
88
- /*
89
- * Retorna uma promise com o valor da opção selecionada,
90
- * que será resolvida quando o backend devolver este dado.
91
- */
92
- async getValueAsync() {
93
- if (!this._showLoading) {
94
- return new Promise(resolve => resolve(this.value));
31
+ observeValue() {
32
+ if (this._comboElement) {
33
+ this._comboElement.value = this.value;
95
34
  }
96
- return new Promise(resolve => {
97
- let id = setInterval(() => {
98
- if (!this._showLoading) {
99
- clearInterval(id);
100
- resolve(this.value);
101
- }
102
- }, 100);
103
- });
104
35
  }
105
36
  /**
106
- * Aplica o foco no campo.
107
- */
37
+ * Aplica o foco no campo.
38
+ */
108
39
  async setFocus() {
109
- if (this._textInput) {
110
- this._textInput.setFocus();
111
- }
40
+ this._comboElement.setFocus();
112
41
  }
113
42
  /**
114
- * Remove o foco do campo.
115
- */
43
+ * Remove o foco do campo.
44
+ */
116
45
  async setBlur() {
117
- if (this._textInput) {
118
- this._textInput.setBlur();
119
- }
46
+ this._comboElement.setBlur();
120
47
  }
121
48
  /**
122
49
  * Retorna se o conteúdo é inválido.
@@ -128,546 +55,39 @@ const EzSearch = class {
128
55
  * Limpa o valor do campo de pesquisa
129
56
  */
130
57
  async clearValue() {
131
- this.clearSearch();
132
- }
133
- scrollListener() {
134
- var _a;
135
- if (this._floatingID == undefined) {
136
- return;
137
- }
138
- if ((_a = this.listOptionsPosition) === null || _a === void 0 ? void 0 : _a.hardPosition) {
139
- this.hideOptions();
140
- }
141
- else {
142
- window.requestAnimationFrame(() => {
143
- this.updateListPosition();
144
- });
145
- }
146
- }
147
- updateListPosition() {
148
- let { verticalPosition, horizontalPosition, fromBottom, fromRight, bottomLimit, hardPosition } = this.getListPosition();
149
- const elementRect = this._listWrapper.getBoundingClientRect();
150
- const containerRect = this._listContainer.getBoundingClientRect();
151
- const textInputRect = this._textInput.getBoundingClientRect();
152
- const limitHeight = bottomLimit || window.innerHeight;
153
- const neededHeight = containerRect.bottom + elementRect.height;
154
- if (!fromBottom && (elementRect.top < 0 || neededHeight > limitHeight)) {
155
- fromBottom = true;
156
- }
157
- if (!hardPosition) {
158
- verticalPosition = verticalPosition || 0;
159
- horizontalPosition = horizontalPosition || 0;
160
- if (fromBottom) {
161
- verticalPosition = window.innerHeight - textInputRect.top + verticalPosition;
162
- }
163
- else {
164
- verticalPosition += containerRect.top;
165
- }
166
- if (fromRight) {
167
- horizontalPosition = window.innerWidth - textInputRect.right + horizontalPosition;
168
- }
169
- else {
170
- horizontalPosition += containerRect.left;
171
- }
172
- }
173
- if (verticalPosition != undefined) {
174
- this._listWrapper.style[fromBottom ? "bottom" : "top"] = `${verticalPosition}px`;
175
- this._listWrapper.style[fromBottom ? "top" : "bottom"] = "";
176
- }
177
- if (horizontalPosition != undefined) {
178
- this._listWrapper.style[fromRight ? "right" : "left"] = `${horizontalPosition}px`;
179
- this._listWrapper.style[fromRight ? "left" : "right"] = "";
180
- }
181
- }
182
- getListPosition() {
183
- if (this.listOptionsPosition) {
184
- return this.listOptionsPosition;
185
- }
186
- return {
187
- verticalPosition: (this.errorMessage || !this.canShowError || this.mode === "slim") ? 6 : -13
188
- };
189
- }
190
- isDifferentValues(firstValue, secondValue) {
191
- return ObjectUtils.objectToString(firstValue || {}) !== ObjectUtils.objectToString(secondValue || {});
192
- }
193
- getFormattedText(currentValue) {
194
- if (currentValue == undefined) {
195
- return;
196
- }
197
- if (!this.showSelectedValue || currentValue.value == undefined) {
198
- return currentValue.label;
199
- }
200
- return currentValue.label ? `${currentValue.value} - ${currentValue.label}` : currentValue.value;
201
- }
202
- getText() {
203
- const currentValue = this.getSelectedOption(this.value);
204
- const text = this.getFormattedText(currentValue);
205
- if (text == undefined) {
206
- return;
207
- }
208
- return String(text)
209
- .replace(/&amp;/g, '&')
210
- .replace(/&lt;/g, '<')
211
- .replace(/&gt;/g, '>')
212
- .replace(/&quot;/g, '"');
213
- }
214
- getSelectedOption(value) {
215
- if (typeof value === "string" || value instanceof String) {
216
- return this._visibleOptions.find(o => o.value === value);
217
- }
218
- return value;
219
- }
220
- updateVisibleOptions() {
221
- let opts = this._source || [];
222
- if (this.suppressEmptyOption) {
223
- this._visibleOptions = opts;
224
- }
225
- else {
226
- this._visibleOptions = [{ value: undefined, label: "" }].concat(opts);
227
- }
228
- this._maxWidthValue = this.getMaxWidthValue();
229
- }
230
- getMaxWidthValue() {
231
- var _a;
232
- const arrValues = [];
233
- (_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.forEach(opt => {
234
- const widthValue = this.getWidthValue(opt.value);
235
- if (!arrValues.includes(widthValue)) {
236
- arrValues.push(widthValue);
237
- }
238
- });
239
- return arrValues.length > 1 ? Math.max(...arrValues) : 0;
240
- }
241
- getWidthValue(value) {
242
- if (this._itemValueBasis != undefined) {
243
- const span = this._itemValueBasis;
244
- if (value != undefined) {
245
- span.innerHTML = value;
246
- return span.clientWidth > 0 ? (span.clientWidth + 2) : 0;
247
- }
248
- else {
249
- span.innerHTML = "";
250
- }
251
- }
252
- return 0;
253
- }
254
- createOption(detail) {
255
- let { key, title } = detail;
256
- const startHighlight = new RegExp(this._startHighlightTag, 'g');
257
- const endHighlight = new RegExp(this._endHighlightTag, 'g');
258
- title = StringUtils.decodeHtmlEntities(title);
259
- const option = {
260
- value: key === null || key === void 0 ? void 0 : key.replace(startHighlight, '').replace(endHighlight, ''),
261
- label: title === null || title === void 0 ? void 0 : title.replace(startHighlight, '').replace(endHighlight, '')
262
- };
263
- this.selectOption(option);
264
- }
265
- buildItem(opt, index) {
266
- opt.label = opt.label || opt.value;
267
- const card = {
268
- key: opt.value,
269
- title: opt.label,
270
- details: opt.details
271
- };
272
- return h("div", { style: { "height": "100%" }, onMouseDown: () => this.createOption(card), onMouseOver: () => this._preSelection = index }, h("ez-card-item", { item: card }));
273
- }
274
- showOptions() {
275
- if (!this.enabled)
276
- return;
277
- if (this.isOptionsVisible()) {
278
- return;
279
- }
280
- if (!!this._resizeObserver)
281
- this._resizeObserver.observe(this._textInput);
282
- this._floatingID = FloatingManager.float(this._listWrapper, this._listContainer, { autoClose: false, isFixed: true, backClickListener: () => this.hideOptions() });
283
- this.setFocus();
284
- window.requestAnimationFrame(() => {
285
- this.updateListPosition();
286
- if (!this.listOptionsPosition) {
287
- this._listWrapper.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
288
- }
289
- });
290
- }
291
- hideOptions() {
292
- if (this._floatingID !== undefined) {
293
- FloatingManager.close(this._floatingID);
294
- }
295
- this._floatingID = undefined;
296
- if (!!this._resizeObserver)
297
- this._resizeObserver.unobserve(this._textInput);
298
- }
299
- isOptionsVisible() {
300
- return this._floatingID !== undefined && FloatingManager.isFloating(this._floatingID);
301
- }
302
- nextOption() {
303
- if (!this.isOptionsVisible()) {
304
- return;
305
- }
306
- this.showOptions();
307
- this._preSelection = this._preSelection === undefined ? 0 : Math.min(this._preSelection + 1, this._visibleOptions.length - 1);
308
- this.scrollToOption(this._visibleOptions[this._preSelection]);
309
- }
310
- previousOption() {
311
- this._preSelection = this._preSelection === undefined ? 0 : Math.max(this._preSelection - 1, 0);
312
- this.scrollToOption(this._visibleOptions[this._preSelection]);
313
- }
314
- scrollToOption(opt) {
315
- window.requestAnimationFrame(() => {
316
- const liElem = (opt === null || opt === void 0 ? void 0 : opt.value) ? this._optionsList.querySelector(`li#item_${opt.value.replace(/[<>\[\]#=]/g, '\\$&').replace(/:/g, '\\:')}`) : undefined;
317
- if (liElem)
318
- liElem.scrollIntoView({ behavior: "smooth", block: "nearest" });
319
- });
320
- }
321
- selectCurrentOption() {
322
- if (this._preSelection !== undefined) {
323
- this.selectOption(this._visibleOptions[this._preSelection]);
324
- this._preSelection = undefined;
325
- }
326
- else {
327
- this.controlListWithOnlyOne();
328
- }
329
- }
330
- updateSource(source) {
331
- this._startLoading = false;
332
- if (source instanceof Promise) {
333
- this._showLoading = true;
334
- source.then(result => {
335
- this._showLoading = false;
336
- this.updateSource(result);
337
- }).catch(() => this._showLoading = false);
338
- this.updateVisibleOptions();
339
- }
340
- else {
341
- this._showLoading = false;
342
- if (Array.isArray(source)) {
343
- this._source = source;
344
- this.updateVisibleOptions();
345
- if (this._tabPressed) {
346
- this._tabPressed = false;
347
- this.controlEmptySearch();
348
- }
349
- }
350
- else {
351
- this.selectOption(source);
352
- }
353
- }
354
- }
355
- clearSource() {
356
- this._source = [];
357
- this.updateVisibleOptions();
358
- }
359
- selectOption(newOption) {
360
58
  var _a, _b;
361
- const currentValue = this.getSelectedOption(this.value);
362
- 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()))
363
- || (currentValue == undefined && newOption != undefined && "value" in newOption)) {
364
- const adjustedOpt = !(newOption === null || newOption === void 0 ? void 0 : newOption.value) ? undefined : newOption;
365
- this.value = adjustedOpt;
366
- }
367
- else {
368
- this.resetOptions();
369
- }
370
- this._visibleOptions = [];
371
- this.clearSource();
59
+ (_b = (_a = this._comboElement) === null || _a === void 0 ? void 0 : _a['clearValue']) === null || _b === void 0 ? void 0 : _b.call(_a);
372
60
  }
373
- loadOptions(mode, argument = "") {
374
- this._criteria = argument;
375
- this._startLoading = true;
376
- if (this.optionLoader) {
377
- const searchArgument = { mode, argument };
378
- this.updateSource(this.optionLoader(searchArgument));
379
- }
380
- else {
381
- this.updateSource(this.options);
382
- }
383
- }
384
- cancelPreselection() {
385
- if (!this._textInput.value && this.value) {
386
- this.selectOption(undefined);
387
- }
388
- else {
389
- window.setTimeout(() => {
390
- this.setInputValue();
391
- }, this._deboucingTime);
392
- }
393
- this.resetOptions();
394
- }
395
- setInputValue(clearError = true) {
396
- const textValue = this.getText();
397
- if ((this._textInput.value || '') !== textValue) {
398
- this._textInput.value = textValue;
399
- if (clearError) {
400
- this.errorMessage = null;
401
- }
402
- }
403
- }
404
- clearSearch() {
405
- this.value = null;
406
- }
407
- controlListWithOnlyOne() {
408
- var _a, _b;
409
- const source = (_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.filter((opt) => opt.label !== "" && opt.value != undefined);
410
- if ((source === null || source === void 0 ? void 0 : source.length) > 0) {
411
- const startHighlight = new RegExp(this._startHighlightTag, 'g');
412
- const endHighlight = new RegExp(this._endHighlightTag, 'g');
413
- let title = StringUtils.decodeHtmlEntities(source[0].label);
414
- const option = {
415
- value: (_b = source[0].value) === null || _b === void 0 ? void 0 : _b.replace(startHighlight, '').replace(endHighlight, ''),
416
- label: title === null || title === void 0 ? void 0 : title.replace(startHighlight, '').replace(endHighlight, '')
417
- };
418
- this.selectOption(option);
419
- }
420
- }
421
- controlEmptySearch() {
422
- var _a;
423
- if (!((_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.length)) {
424
- this.clearSearch();
425
- ApplicationUtils.info(this._textEmptyList);
426
- }
427
- else {
428
- this.controlListWithOnlyOne();
429
- }
430
- }
431
- validateDescriptionValue() {
432
- if (StringUtils.isEmpty(this.value)) {
433
- return;
434
- }
435
- let value = this.value;
436
- if (typeof value === "object") {
437
- return;
438
- }
439
- if (StringUtils.isEmpty(value)) {
440
- return;
441
- }
442
- this.loadDescriptionValue(value);
443
- }
444
- async loadDescriptionValue(argument) {
445
- var _a, _b;
446
- if (argument == undefined) {
447
- return;
448
- }
449
- if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.length) > 0) {
450
- this.loadOptionValue(argument);
451
- return;
452
- }
453
- const searchArgument = {
454
- mode: SearchMode.PREDICTIVE,
455
- argument
456
- };
457
- const source = await ((_b = this.optionLoader) === null || _b === void 0 ? void 0 : _b.call(this, searchArgument));
458
- if (source == undefined) {
459
- return;
460
- }
461
- if (source instanceof Promise) {
462
- source.then((result) => {
463
- this.setDescriptionValue(result);
464
- });
465
- }
466
- else {
467
- this.setDescriptionValue(source);
468
- }
469
- }
470
- setDescriptionValue(source) {
471
- const value = (source === null || source === void 0 ? void 0 : source[0]) || source;
472
- if (value == undefined || !Object.keys(value).length) {
473
- this.showNoResultMessage();
474
- return;
475
- }
476
- this._lookupMode = true;
477
- this.value = value;
478
- }
479
- loadOptionValue(argument) {
480
- var _a;
481
- const source = (_a = this.options) === null || _a === void 0 ? void 0 : _a.find((opt) => opt.value === argument);
482
- if (source != undefined) {
483
- this.selectOption(source);
484
- }
485
- else {
486
- this.showNoResultMessage();
487
- }
488
- }
489
- async showNoResultMessage() {
490
- this.clearSearch();
491
- ApplicationUtils.info(this._textEmptySearch.replace("{0}", this.getFieldLabel()));
492
- }
493
- getFieldLabel() {
61
+ /*
62
+ * Retorna uma promise com o valor da opção selecionada,
63
+ * que será resolvida quando o backend devolver este dado.
64
+ */
65
+ async getValueAsync() {
494
66
  var _a;
495
- return (_a = this.label) === null || _a === void 0 ? void 0 : _a.replace(REQUIRED_INFO, "").toUpperCase();
496
- }
497
- resetOptions() {
498
- this.hideOptions();
499
- this._criteria = undefined;
500
- this._preSelection = undefined;
501
- this.updateVisibleOptions();
67
+ return (_a = this._comboElement) === null || _a === void 0 ? void 0 : _a.getValueAsync();
502
68
  }
503
- //---------------------------------------------
504
- // Lifecycle web component
505
- //---------------------------------------------
506
- componentWillLoad() {
507
- if (this.options === undefined) {
508
- this.options = [];
509
- const optionsTags = this.el.querySelectorAll("option");
510
- if (optionsTags) {
511
- optionsTags.forEach(e => {
512
- let label = e.innerText;
513
- let value = e.getAttribute("value");
514
- let details = e.getAttribute("details");
515
- if (!value) {
516
- value = label;
517
- }
518
- this.options.push({ label, value, details });
519
- e.hidden = true;
520
- });
521
- }
69
+ onComboChange(event) {
70
+ event.stopPropagation();
71
+ this.value = event.detail;
72
+ this.ezChange.emit(event.detail);
73
+ if (this.errorMessage !== this._comboElement.errorMessage) {
74
+ this.errorMessage = this._comboElement.errorMessage;
522
75
  }
523
- this.updateSource([]);
524
- }
525
- componentDidRender() {
526
- var _a;
527
- if (this._floatingID === undefined) {
528
- this._listWrapper.remove();
529
- }
530
- (_a = this._optionsList) === null || _a === void 0 ? void 0 : _a.querySelectorAll(".item").forEach((elem) => {
531
- ElementIDUtils.addIDInfoIfNotExists(elem, "itemSearch");
532
- });
533
- this.validateDescriptionValue();
534
76
  }
535
77
  componentDidLoad() {
536
- CSSVarsUtils.applyVarsTextInput(this.el, this._textInput);
537
- this.setInputValue(false);
538
- this._resizeObserver = new ResizeObserver((entries) => {
539
- window.requestAnimationFrame(() => {
540
- if (!Array.isArray(entries) || !entries.length)
541
- return;
542
- const { clientWidth } = this._listContainer;
543
- if (clientWidth > 0 && !!this._listWrapper) {
544
- this._listWrapper.style.width = `${clientWidth}px`;
545
- }
546
- });
547
- });
548
- }
549
- //---------------------------------------------
550
- // Event handlers
551
- //---------------------------------------------
552
- handlerIconClick() {
553
- this.loadOptions(SearchMode.ADVANCED);
554
- }
555
- buildNumberArgument(argument) {
556
- if (this.isTextSearch) {
557
- return NaN;
558
- }
559
- return Number(argument || undefined);
560
- }
561
- onTextInputChangeHandler(event) {
562
- var _a;
563
- this.clearDeboucingTimeout();
564
- if (this._startLoading) {
565
- this._changeDeboucingTimeout = window.setTimeout(() => {
566
- this.onTextInputChangeHandler(event);
567
- }, this._deboucingTime);
568
- return;
569
- }
570
- const argument = (_a = event.target.value) === null || _a === void 0 ? void 0 : _a.trim();
571
- const argumentNumber = this.buildNumberArgument(argument);
572
- if (!this._criteria) {
573
- this._textInput.value = event.data || argument;
574
- }
575
- this._criteria = argument;
576
- if (argument) {
577
- this._showLoading = false;
578
- this.clearSource();
579
- if (!isNaN(argumentNumber) || argument.length >= this._limitCharsToSearch) {
580
- this._showLoading = true;
581
- this._changeDeboucingTimeout = window.setTimeout(() => {
582
- this.loadOptions(SearchMode.PREDICTIVE, isNaN(argumentNumber) ? argument : argumentNumber.toString());
583
- }, this._deboucingTime);
584
- this.showOptions();
585
- }
586
- else {
587
- this.hideOptions();
588
- }
589
- }
590
- else {
591
- this.hideOptions();
592
- this._showLoading = false;
593
- this.clearSource();
594
- }
595
- }
596
- clearDeboucingTimeout() {
597
- if (this._changeDeboucingTimeout) {
598
- window.clearTimeout(this._changeDeboucingTimeout);
599
- this._changeDeboucingTimeout = null;
600
- }
601
- }
602
- keyDownHandler(event) {
603
- this._tabPressed = false;
604
- if (event.ctrlKey) {
605
- if (event.key === "f" || event.key === "F") {
606
- this.loadOptions(SearchMode.ADVANCED);
607
- //ATENÇÃO: Ctrl + F tem ação específica nos browsers
608
- //nesse caso, como vamos abrir o popup de busca avançada,
609
- //não é interessante deixar o evento propagar;
610
- event.stopPropagation();
611
- event.stopImmediatePropagation();
612
- event.preventDefault();
613
- }
614
- }
615
- switch (event.key) {
616
- case "ArrowDown":
617
- this.nextOption();
618
- event.stopPropagation();
619
- break;
620
- case "ArrowUp":
621
- this.previousOption();
622
- event.stopPropagation();
623
- break;
624
- case "Enter":
625
- this.selectCurrentOption();
626
- break;
627
- case "Escape":
628
- this.cancelPreselection();
629
- break;
630
- case "Tab":
631
- this._tabPressed = true;
632
- this.controlListWithOnlyOne();
633
- break;
634
- }
635
- //ATENÇÃO: Existe a necessidade de propagar o evento de teclado.
636
- //Por exemplo, quando o usuário dá um Enter, além de selecionar
637
- //um valor, também significa que a ateração finalizou,
638
- //e o contexto pode reagir (fechar um popup por exemplo).
639
- //event.stopPropagation();
640
- }
641
- onTextInputFocusOutHandler() {
642
- if (this.hideErrorOnFocusOut)
643
- this.cancelPreselection();
644
- }
645
- canShowListOptions() {
646
- return !this._showLoading && this._visibleOptions.length > 0;
78
+ CSSVarsUtils.applyVarsTextInput(this._elem, this._comboElement);
647
79
  }
648
80
  render() {
649
- var _a;
650
- ElementIDUtils.addIDInfoIfNotExists(this.el, 'input');
651
- 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)
652
- ? h("button", { class: "btn btn__close", slot: "rightIcon", disabled: !this.enabled, tabindex: -1, onClick: () => this.clearSearch() }, h("ez-icon", { iconName: "close" }))
653
- : 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
654
- && this._visibleOptions.length === 0
655
- && h("div", { class: "message" }, h("span", { class: "message__no-result" }, this._textEmptyList)), this._showLoading
656
- && 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)))))));
81
+ ElementIDUtils.addIDInfoIfNotExists(this._elem, 'input');
82
+ 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 }));
657
83
  }
658
- get el() { return getElement(this); }
84
+ ;
85
+ get _elem() { return getElement(this); }
659
86
  static get watchers() { return {
660
87
  "errorMessage": ["observeErrorMessage"],
661
- "value": ["observeValue"],
662
- "options": ["observeOptions"]
88
+ "value": ["observeValue"]
663
89
  }; }
664
90
  };
665
- var SearchMode;
666
- (function (SearchMode) {
667
- SearchMode["ADVANCED"] = "ADVANCED";
668
- SearchMode["PRELOAD"] = "PRELOAD";
669
- SearchMode["PREDICTIVE"] = "PREDICTIVE";
670
- })(SearchMode || (SearchMode = {}));
671
91
  EzSearch.style = ezSearchCss;
672
92
 
673
93
  export { EzSearch as ez_search };