@sankhyalabs/ezui 1.1.8 → 1.1.9

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 (141) hide show
  1. package/README.md +72 -72
  2. package/dist/cjs/{DataUnit-28b290cb.js → DataUnit-9a4a35ca.js} +415 -371
  3. package/dist/cjs/ez-action-chip.cjs.entry.js +41 -41
  4. package/dist/cjs/ez-button_14.cjs.entry.js +1911 -1911
  5. package/dist/cjs/ez-label-chip.cjs.entry.js +120 -120
  6. package/dist/cjs/ez-modal.cjs.entry.js +104 -104
  7. package/dist/cjs/ez-number-input.cjs.entry.js +236 -236
  8. package/dist/cjs/ez-time-input.cjs.entry.js +168 -168
  9. package/dist/cjs/form-metadata.cjs.entry.js +65 -65
  10. package/dist/collection/components/ez-action-chip/ez-action-chip.css +82 -82
  11. package/dist/collection/components/ez-action-chip/ez-action-chip.js +109 -109
  12. package/dist/collection/components/ez-button/ez-button.css +94 -94
  13. package/dist/collection/components/ez-button/ez-button.js +125 -125
  14. package/dist/collection/components/ez-calendar/ez-calendar.css +210 -210
  15. package/dist/collection/components/ez-calendar/ez-calendar.js +215 -215
  16. package/dist/collection/components/ez-check/ez-check.css +265 -265
  17. package/dist/collection/components/ez-check/ez-check.js +168 -168
  18. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.css +67 -67
  19. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.js +108 -108
  20. package/dist/collection/components/ez-combo-box/ez-combo-box-interfaces.js +2 -2
  21. package/dist/collection/components/ez-combo-box/ez-combo-box.css +167 -167
  22. package/dist/collection/components/ez-combo-box/ez-combo-box.js +363 -363
  23. package/dist/collection/components/ez-date-input/ez-date-input.css +38 -38
  24. package/dist/collection/components/ez-date-input/ez-date-input.js +172 -172
  25. package/dist/collection/components/ez-form/ez-form.css +19 -19
  26. package/dist/collection/components/ez-form/ez-form.js +368 -368
  27. package/dist/collection/components/ez-form/store/Form.actions.js +132 -132
  28. package/dist/collection/components/ez-form/store/Form.reducer.js +194 -194
  29. package/dist/collection/components/ez-form/store/Form.selectors.js +44 -44
  30. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +251 -207
  31. package/dist/collection/components/ez-form/subcomponents/FormMetadata.js +16 -16
  32. package/dist/collection/components/ez-form/subcomponents/css/place-holder.css +23 -23
  33. package/dist/collection/components/ez-form/subcomponents/form-metadata.js +173 -173
  34. package/dist/collection/components/ez-form/subcomponents/place-holder.js +14 -14
  35. package/dist/collection/components/ez-form/subcomponents/structure/Field.js +71 -71
  36. package/dist/collection/components/ez-form/subcomponents/structure/FieldSet.js +27 -27
  37. package/dist/collection/components/ez-form/subcomponents/structure/FormSheet.js +40 -40
  38. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +27 -27
  39. package/dist/collection/components/ez-icon/ez-icon.css +36 -36
  40. package/dist/collection/components/ez-icon/ez-icon.js +56 -56
  41. package/dist/collection/components/ez-label-chip/ez-label-chip.css +117 -117
  42. package/dist/collection/components/ez-label-chip/ez-label-chip.js +276 -276
  43. package/dist/collection/components/ez-modal/ez-modal.css +86 -86
  44. package/dist/collection/components/ez-modal/ez-modal.js +224 -224
  45. package/dist/collection/components/ez-number-input/ez-number-input.css +144 -144
  46. package/dist/collection/components/ez-number-input/ez-number-input.js +465 -465
  47. package/dist/collection/components/ez-popover/ez-popover.css +38 -38
  48. package/dist/collection/components/ez-popover/ez-popover.js +323 -323
  49. package/dist/collection/components/ez-search/ez-search.css +295 -295
  50. package/dist/collection/components/ez-search/ez-search.js +527 -527
  51. package/dist/collection/components/ez-tabselector/ez-tabselector.css +125 -125
  52. package/dist/collection/components/ez-tabselector/ez-tabselector.js +283 -283
  53. package/dist/collection/components/ez-text-area/ez-text-area.css +139 -139
  54. package/dist/collection/components/ez-text-area/ez-text-area.js +267 -267
  55. package/dist/collection/components/ez-text-input/ez-text-input.css +169 -169
  56. package/dist/collection/components/ez-text-input/ez-text-input.js +395 -395
  57. package/dist/collection/components/ez-time-input/ez-time-input.css +155 -155
  58. package/dist/collection/components/ez-time-input/ez-time-input.js +326 -326
  59. package/dist/collection/index.js +1 -1
  60. package/dist/collection/servidor.js +100 -100
  61. package/dist/collection/utils/FloatingManager.js +15 -15
  62. package/dist/collection/utils/utils.js +6 -6
  63. package/dist/custom-elements/index.js +3125 -3081
  64. package/dist/esm/{DataUnit-69e518fa.js → DataUnit-d5d4c9a3.js} +415 -371
  65. package/dist/esm/ez-action-chip.entry.js +41 -41
  66. package/dist/esm/ez-button_14.entry.js +1911 -1911
  67. package/dist/esm/ez-label-chip.entry.js +120 -120
  68. package/dist/esm/ez-modal.entry.js +104 -104
  69. package/dist/esm/ez-number-input.entry.js +236 -236
  70. package/dist/esm/ez-time-input.entry.js +168 -168
  71. package/dist/esm/form-metadata.entry.js +65 -65
  72. package/dist/esm/polyfills/core-js.js +0 -0
  73. package/dist/esm/polyfills/dom.js +0 -0
  74. package/dist/esm/polyfills/es5-html-element.js +0 -0
  75. package/dist/esm/polyfills/index.js +0 -0
  76. package/dist/esm/polyfills/system.js +0 -0
  77. package/dist/ezui/ezui.esm.js +1 -1
  78. package/dist/ezui/{p-b0974f4f.entry.js → p-0fcdfb51.entry.js} +1 -1
  79. package/dist/ezui/p-dac7a6c2.js +1 -0
  80. package/dist/ezui/{p-db11c600.entry.js → p-dbef7060.entry.js} +1 -1
  81. package/dist/types/components/ez-action-chip/ez-action-chip.d.ts +16 -16
  82. package/dist/types/components/ez-button/ez-button.d.ts +20 -20
  83. package/dist/types/components/ez-calendar/ez-calendar.d.ts +42 -42
  84. package/dist/types/components/ez-check/ez-check.d.ts +32 -32
  85. package/dist/types/components/ez-collapsable-box/ez-collapsable-box.d.ts +18 -18
  86. package/dist/types/components/ez-combo-box/ez-combo-box-interfaces.d.ts +4 -4
  87. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +68 -68
  88. package/dist/types/components/ez-date-input/ez-date-input.d.ts +31 -31
  89. package/dist/types/components/ez-form/ez-form.d.ts +26 -31
  90. package/dist/types/components/ez-form/store/Form.actions.d.ts +111 -111
  91. package/dist/types/components/ez-form/store/Form.reducer.d.ts +20 -20
  92. package/dist/types/components/ez-form/store/Form.selectors.d.ts +14 -14
  93. package/dist/types/components/ez-form/subcomponents/DataUnit.d.ts +60 -55
  94. package/dist/types/components/ez-form/subcomponents/FormMetadata.d.ts +41 -41
  95. package/dist/types/components/ez-form/subcomponents/form-metadata.d.ts +15 -15
  96. package/dist/types/components/ez-form/subcomponents/place-holder.d.ts +3 -3
  97. package/dist/types/components/ez-form/subcomponents/structure/Field.d.ts +10 -10
  98. package/dist/types/components/ez-form/subcomponents/structure/FieldSet.d.ts +12 -12
  99. package/dist/types/components/ez-form/subcomponents/structure/FormSheet.d.ts +13 -13
  100. package/dist/types/components/ez-form/subcomponents/structure/NavigationBar.d.ts +17 -17
  101. package/dist/types/components/ez-icon/ez-icon.d.ts +5 -5
  102. package/dist/types/components/ez-label-chip/ez-label-chip.d.ts +40 -40
  103. package/dist/types/components/ez-modal/ez-modal.d.ts +32 -32
  104. package/dist/types/components/ez-number-input/ez-number-input.d.ts +73 -73
  105. package/dist/types/components/ez-popover/ez-popover.d.ts +52 -52
  106. package/dist/types/components/ez-search/ez-search.d.ts +95 -95
  107. package/dist/types/components/ez-tabselector/ez-tabselector.d.ts +31 -31
  108. package/dist/types/components/ez-text-area/ez-text-area.d.ts +49 -49
  109. package/dist/types/components/ez-text-input/ez-text-input.d.ts +64 -64
  110. package/dist/types/components/ez-time-input/ez-time-input.d.ts +53 -53
  111. package/dist/types/index.d.ts +1 -1
  112. package/dist/types/utils/utils.d.ts +2 -2
  113. package/package.json +114 -114
  114. package/dist/ezui/p-10ef58b3.js +0 -1
  115. package/react/components.d.ts +0 -22
  116. package/react/components.js +0 -25
  117. package/react/components.js.map +0 -1
  118. package/react/react-component-lib/createComponent.d.ts +0 -10
  119. package/react/react-component-lib/createComponent.js +0 -59
  120. package/react/react-component-lib/createComponent.js.map +0 -1
  121. package/react/react-component-lib/createOverlayComponent.d.ts +0 -20
  122. package/react/react-component-lib/createOverlayComponent.js +0 -89
  123. package/react/react-component-lib/createOverlayComponent.js.map +0 -1
  124. package/react/react-component-lib/index.d.ts +0 -2
  125. package/react/react-component-lib/index.js +0 -3
  126. package/react/react-component-lib/index.js.map +0 -1
  127. package/react/react-component-lib/interfaces.d.ts +0 -29
  128. package/react/react-component-lib/interfaces.js +0 -1
  129. package/react/react-component-lib/interfaces.js.map +0 -1
  130. package/react/react-component-lib/utils/attachProps.d.ts +0 -12
  131. package/react/react-component-lib/utils/attachProps.js +0 -96
  132. package/react/react-component-lib/utils/attachProps.js.map +0 -1
  133. package/react/react-component-lib/utils/case.d.ts +0 -2
  134. package/react/react-component-lib/utils/case.js +0 -7
  135. package/react/react-component-lib/utils/case.js.map +0 -1
  136. package/react/react-component-lib/utils/dev.d.ts +0 -2
  137. package/react/react-component-lib/utils/dev.js +0 -13
  138. package/react/react-component-lib/utils/dev.js.map +0 -1
  139. package/react/react-component-lib/utils/index.d.ts +0 -7
  140. package/react/react-component-lib/utils/index.js +0 -21
  141. package/react/react-component-lib/utils/index.js.map +0 -1
@@ -1,527 +1,527 @@
1
- import { Component, Element, Event, h, Host, Method, Prop, State, Watch } from '@stencil/core';
2
- ;
3
- ;
4
- export class EzSearch {
5
- constructor() {
6
- this._options = [];
7
- this._classSelect = 'list-container--4row';
8
- /**
9
- * Deixa o campo disponível ou não para digitação.
10
- */
11
- this.enabled = true;
12
- /**
13
- * Quantidade máxima de itens guardados no localstorage
14
- */
15
- this.qtdHotItems = 6;
16
- /**
17
- * Ajusta a opção de mostrar o "value" para cada "label". Como default "value" não está presente (showvalue = false)
18
- */
19
- this.showvalue = false;
20
- ///// HOTSEARCH /////
21
- this.buildId = () => {
22
- return btoa(`${this.hotsearchid}:${location.pathname}`);
23
- };
24
- this.getStorageItems = (key) => {
25
- let storageValueStr = localStorage.getItem('hotSearch-ez-search:' + key);
26
- let storageItems = [];
27
- if (storageValueStr !== null) {
28
- storageItems = JSON.parse(storageValueStr);
29
- }
30
- return storageItems;
31
- };
32
- this.orderHotList = (list) => {
33
- return list.sort((a, b) => {
34
- let time1 = new Date(a.dtRecent).getTime();
35
- let time2 = new Date(b.dtRecent).getTime();
36
- let qtd1 = a.qtd;
37
- let qtd2 = b.qtd;
38
- if (time1 < time2)
39
- return -1;
40
- if (time1 > time2)
41
- return 1;
42
- if (qtd1 > qtd2)
43
- return -1;
44
- if (qtd1 < qtd2)
45
- return 1;
46
- return 0;
47
- });
48
- };
49
- this.saveStorageItem = (key, value) => {
50
- if (value == '' || value == undefined)
51
- return;
52
- let storageItem = this.getStorageItems(key);
53
- let element = this.getElement(storageItem, value);
54
- if (element) {
55
- element.qtd++;
56
- element.dtRecent = this.getOnlyDate();
57
- }
58
- else {
59
- if (storageItem.length >= this.qtdHotItems) {
60
- storageItem = this.orderHotList(storageItem);
61
- storageItem.splice(-1, 1);
62
- }
63
- storageItem.push({
64
- description: value,
65
- qtd: 1,
66
- dtRecent: this.getOnlyDate()
67
- });
68
- }
69
- localStorage.setItem('hotSearch-ez-search:' + key, JSON.stringify(storageItem));
70
- return storageItem;
71
- };
72
- this.adjustOptions = (arrayOptions) => {
73
- let optionsTemp = [];
74
- arrayOptions.map(el => {
75
- optionsTemp.push({
76
- value: el.value,
77
- label: el.label,
78
- ajustedValue: el.value === null || el.value === undefined || el.value === '' ? el.label : el.value,
79
- });
80
- });
81
- return optionsTemp;
82
- };
83
- this.sortArrayOptions = (array, propname) => {
84
- const sortedArray = array.sort(function (a, b) {
85
- if (a[propname] < b[propname]) {
86
- return -1;
87
- }
88
- if (a[propname] > b[propname]) {
89
- return 1;
90
- }
91
- return 0;
92
- });
93
- return sortedArray;
94
- };
95
- }
96
- valueChanged() {
97
- var _a;
98
- if (this.value) {
99
- this.ezChange.emit({ value: this.value, label: (_a = this._inputElem) === null || _a === void 0 ? void 0 : _a.value });
100
- let key = this.buildId();
101
- this.saveStorageItem(key, this.value);
102
- }
103
- }
104
- //ajustar ao fim do teste
105
- onInputTeste() {
106
- if (this._inputElem) {
107
- this.handleChange();
108
- }
109
- }
110
- getElement(storageItem, value) {
111
- return storageItem.find(e => e.description === value);
112
- }
113
- getOnlyDate() {
114
- let dt = new Date();
115
- dt.setHours(0);
116
- dt.setMinutes(0);
117
- dt.setSeconds(0);
118
- dt.setUTCMilliseconds(0);
119
- return dt.toString();
120
- }
121
- onInputChange(ev) {
122
- const el = ev.target;
123
- let key = this.buildId();
124
- this.saveStorageItem(key, el.value);
125
- }
126
- buildDataList() {
127
- try {
128
- if (this.hotsearchid === undefined) {
129
- return;
130
- }
131
- let key = this.buildId();
132
- let optionsArray = [];
133
- this._options = [];
134
- if (this.getStorageItems(key).length > 0) {
135
- this.orderHotList(this.getStorageItems(key))
136
- .forEach((el) => {
137
- optionsArray.push({
138
- value: el.description,
139
- label: el.description,
140
- });
141
- });
142
- this._options = [{ value: '', label: '' }].concat(optionsArray);
143
- this.buildOptions();
144
- }
145
- }
146
- catch (err) {
147
- this.errormessage = err;
148
- }
149
- }
150
- ///// EVENT HANDLERS
151
- buildItem(opt, index) {
152
- const className = index === this._preSelection ? "--li--preselected" : "";
153
- return h("li", { class: className, key: opt.ajustedValue, accessKey: opt.label.toString(), id: 'item_' + opt.ajustedValue, onMouseDown: (ev) => this.handleSetValueByOption(ev) },
154
- this.highlightMatch(opt.label),
155
- this.showvalue ? h("span", { title: opt.ajustedValue, class: '--li__spanvalue' }, opt.ajustedValue) : null);
156
- }
157
- highlightMatch(label) {
158
- var _a;
159
- const spanClassName = this.showvalue ? '--li__spanlabel' : '--li__spanlabel--full-width';
160
- if ((_a = this._inputElem) === null || _a === void 0 ? void 0 : _a.value) {
161
- const criteriaLength = this._inputElem.value.length;
162
- const matchStart = label.toUpperCase().indexOf(this._inputElem.value);
163
- if (matchStart > -1) {
164
- const strLabelStart = label.substr(0, matchStart);
165
- const strLabelEnd = label.substr(matchStart + criteriaLength);
166
- const strMatch = label.substr(matchStart, criteriaLength);
167
- return (h("span", { class: spanClassName },
168
- strLabelStart,
169
- h("strong", null, strMatch),
170
- strLabelEnd));
171
- }
172
- }
173
- return (h("span", { class: spanClassName }, label));
174
- }
175
- showOptions() {
176
- if (this.enabled) {
177
- const top = this._inputElem.errormessage ? '0px' : '-17px';
178
- this._popover.show(top);
179
- }
180
- }
181
- nextOption() {
182
- this.showOptions();
183
- this._preSelection = this._preSelection === undefined ? 0 : Math.min(this._preSelection + 1, this._visibleOptions.length - 1);
184
- this.scrollToOption(this._visibleOptions[this._preSelection]);
185
- }
186
- previousOption() {
187
- this._preSelection = this._preSelection === undefined ? 0 : Math.max(this._preSelection - 1, 0);
188
- this.scrollToOption(this._visibleOptions[this._preSelection]);
189
- }
190
- scrollToOption(opt) {
191
- const liElem = this.el.shadowRoot.querySelector(`li#item_${opt.value}`);
192
- if (liElem) {
193
- const parent = liElem.parentElement;
194
- const parentRect = parent.getBoundingClientRect();
195
- const itemRect = liElem.getBoundingClientRect();
196
- if (itemRect.bottom > parentRect.bottom || itemRect.top < parentRect.top) {
197
- liElem.scrollIntoView();
198
- }
199
- }
200
- }
201
- selectCurrentOption() {
202
- if (this._preSelection !== undefined) {
203
- this.selectOption(this._visibleOptions[this._preSelection]);
204
- this._preSelection = undefined;
205
- }
206
- }
207
- selectOption(opt) {
208
- this._popover.hide();
209
- this.value = opt === null || opt === void 0 ? void 0 : opt.ajustedValue;
210
- this._inputElem.value = opt.value;
211
- //Definir com a equipe de design se vai ser utilizado dessa forma.
212
- // this._inputElem.value = opt.value? opt.value + " - "+ opt?.label: '';
213
- }
214
- keyDownHandler(event) {
215
- switch (event.key) {
216
- case "ArrowDown":
217
- this.nextOption();
218
- break;
219
- case "ArrowUp":
220
- this.previousOption();
221
- break;
222
- case "Enter":
223
- this.selectCurrentOption();
224
- break;
225
- }
226
- event.stopPropagation();
227
- }
228
- handleSetValueByOption(ev) {
229
- this._popover.hide();
230
- const spanEl = ev.target;
231
- const sourceElement = ev.composedPath()[0];
232
- let li;
233
- if (sourceElement.tagName === 'SPAN') {
234
- li = spanEl.parentNode;
235
- }
236
- else {
237
- li = spanEl.parentNode.parentNode;
238
- }
239
- this.value = li.id.split('_')[1];
240
- this._inputElem.value = li.accessKey;
241
- this.ezChange.emit();
242
- }
243
- handleChange() {
244
- if (this._changeDeboucing) {
245
- window.clearTimeout(this._changeDeboucing);
246
- }
247
- this._changeDeboucing = window.setTimeout(() => {
248
- var _a, _b;
249
- if (((_b = (_a = this._inputElem) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.length) <= 0) {
250
- return;
251
- }
252
- /* save tip on localStorage */
253
- let key = this.buildId();
254
- this.saveStorageItem(key, this._inputElem.value);
255
- /* load data */
256
- if (this.loadexecutor) {
257
- this._loadDataFunction(this._inputElem.value, (serverData) => { this.populateOptions(serverData); });
258
- }
259
- }, 200);
260
- }
261
- normalizeResult(data) {
262
- let options = [];
263
- if (data instanceof Array) {
264
- options = data;
265
- }
266
- else {
267
- if (data instanceof Object) {
268
- for (var key in data) {
269
- let newOption = { value: '', label: '' };
270
- newOption.value = key;
271
- newOption.label = data[key];
272
- options.push(newOption);
273
- }
274
- }
275
- }
276
- this._options = [{ value: '', label: '' }].concat(options);
277
- this.buildOptions();
278
- }
279
- populateOptions(serverData) {
280
- if (serverData instanceof Promise) {
281
- serverData.then(this.normalizeResult);
282
- }
283
- else {
284
- this.normalizeResult(serverData);
285
- }
286
- }
287
- buildOptions() {
288
- var _a;
289
- this._visibleOptions = [];
290
- this._visibleOptions = this.adjustOptions(this._options);
291
- this._visibleOptions = this.sortArrayOptions(this._visibleOptions, 'label');
292
- if (this._visibleOptions.length > 0) {
293
- (_a = this._divElem) === null || _a === void 0 ? void 0 : _a.classList.add(this._classSelect);
294
- this.showOptions();
295
- }
296
- }
297
- setClassForSpanLabel() {
298
- if (!this.showvalue) {
299
- return '--li__spanlabel--full-width';
300
- }
301
- else {
302
- return '--li__spanlabel';
303
- }
304
- }
305
- handleFocus() {
306
- if (this._inputElem && (!this._inputElem.value || this._inputElem.value.length === 0)) {
307
- this.buildDataList();
308
- }
309
- }
310
- parseExecutor(executor) {
311
- if (executor) {
312
- return executor instanceof Function ? executor : eval(executor);
313
- }
314
- return null;
315
- }
316
- componentDidLoad() {
317
- if (this.value && this.value.length > 0) {
318
- this._inputElem.value = this.value;
319
- }
320
- this._loadDataFunction = this.parseExecutor(this.loadexecutor);
321
- }
322
- render() {
323
- var _a;
324
- return (h(Host, null,
325
- h("ez-text-input", { ref: (el) => { this._inputElem = el; }, label: this.label, enabled: this.enabled, onFocus: () => { this.handleFocus(); }, onInput: () => { this.handleChange(); }, onKeyDown: event => this.keyDownHandler(event), errormessage: this.errormessage },
326
- h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-search", onClick: () => { alert("Esta ação irá abrir o PopUp!"); }, slot: "leftIcon" })),
327
- h("ez-popover", { boxwidth: '100%', ref: el => this._popover = el },
328
- h("div", { class: 'list-container', ref: (el) => this._divElem = el }, (_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.map((opt, index) => this.buildItem(opt, index))))));
329
- }
330
- ;
331
- static get is() { return "ez-search"; }
332
- static get encapsulation() { return "shadow"; }
333
- static get originalStyleUrls() { return {
334
- "$": ["ez-search.css"]
335
- }; }
336
- static get styleUrls() { return {
337
- "$": ["ez-search.css"]
338
- }; }
339
- static get properties() { return {
340
- "value": {
341
- "type": "string",
342
- "mutable": true,
343
- "complexType": {
344
- "original": "string",
345
- "resolved": "string",
346
- "references": {}
347
- },
348
- "required": false,
349
- "optional": false,
350
- "docs": {
351
- "tags": [],
352
- "text": "C\u00F3digo do registro selecionado"
353
- },
354
- "attribute": "value",
355
- "reflect": true
356
- },
357
- "label": {
358
- "type": "string",
359
- "mutable": true,
360
- "complexType": {
361
- "original": "string",
362
- "resolved": "string",
363
- "references": {}
364
- },
365
- "required": false,
366
- "optional": false,
367
- "docs": {
368
- "tags": [],
369
- "text": "Label \u00E9 o t\u00EDtulo do campo"
370
- },
371
- "attribute": "label",
372
- "reflect": true
373
- },
374
- "enabled": {
375
- "type": "boolean",
376
- "mutable": true,
377
- "complexType": {
378
- "original": "boolean",
379
- "resolved": "boolean",
380
- "references": {}
381
- },
382
- "required": false,
383
- "optional": false,
384
- "docs": {
385
- "tags": [],
386
- "text": "Deixa o campo dispon\u00EDvel ou n\u00E3o para digita\u00E7\u00E3o."
387
- },
388
- "attribute": "enabled",
389
- "reflect": true,
390
- "defaultValue": "true"
391
- },
392
- "qtdHotItems": {
393
- "type": "number",
394
- "mutable": false,
395
- "complexType": {
396
- "original": "number",
397
- "resolved": "number",
398
- "references": {}
399
- },
400
- "required": false,
401
- "optional": false,
402
- "docs": {
403
- "tags": [],
404
- "text": "Quantidade m\u00E1xima de itens guardados no localstorage"
405
- },
406
- "attribute": "qtd-hot-items",
407
- "reflect": true,
408
- "defaultValue": "6"
409
- },
410
- "showvalue": {
411
- "type": "boolean",
412
- "mutable": false,
413
- "complexType": {
414
- "original": "boolean",
415
- "resolved": "boolean",
416
- "references": {}
417
- },
418
- "required": false,
419
- "optional": false,
420
- "docs": {
421
- "tags": [],
422
- "text": "Ajusta a op\u00E7\u00E3o de mostrar o \"value\" para cada \"label\". Como default \"value\" n\u00E3o est\u00E1 presente (showvalue = false)"
423
- },
424
- "attribute": "showvalue",
425
- "reflect": true,
426
- "defaultValue": "false"
427
- },
428
- "errormessage": {
429
- "type": "string",
430
- "mutable": true,
431
- "complexType": {
432
- "original": "string",
433
- "resolved": "string",
434
- "references": {}
435
- },
436
- "required": false,
437
- "optional": false,
438
- "docs": {
439
- "tags": [],
440
- "text": "Quando h\u00E1 um problema de valida\u00E7\u00E3o, serve como orienta\u00E7\u00E3o ao usu\u00E1rio"
441
- },
442
- "attribute": "errormessage",
443
- "reflect": true
444
- },
445
- "loadexecutor": {
446
- "type": "string",
447
- "mutable": false,
448
- "complexType": {
449
- "original": "string | Function",
450
- "resolved": "Function | string",
451
- "references": {
452
- "Function": {
453
- "location": "global"
454
- }
455
- }
456
- },
457
- "required": false,
458
- "optional": false,
459
- "docs": {
460
- "tags": [],
461
- "text": "Quando h\u00E1 um problema de valida\u00E7\u00E3o, serve como orienta\u00E7\u00E3o ao usu\u00E1rio"
462
- },
463
- "attribute": "loadexecutor",
464
- "reflect": false
465
- },
466
- "hotsearchid": {
467
- "type": "string",
468
- "mutable": false,
469
- "complexType": {
470
- "original": "string",
471
- "resolved": "string",
472
- "references": {}
473
- },
474
- "required": false,
475
- "optional": false,
476
- "docs": {
477
- "tags": [],
478
- "text": "Define o identificador \u00FAnico do hotSearch, caso esta propriedade n\u00E3o seja preenchida, o hotSearch n\u00E3o funcionar\u00E1."
479
- },
480
- "attribute": "hotsearchid",
481
- "reflect": false
482
- }
483
- }; }
484
- static get states() { return {
485
- "_preSelection": {},
486
- "_visibleOptions": {}
487
- }; }
488
- static get events() { return [{
489
- "method": "ezChange",
490
- "name": "ezChange",
491
- "bubbles": true,
492
- "cancelable": true,
493
- "composed": true,
494
- "docs": {
495
- "tags": [],
496
- "text": "Este evento emite o c\u00F3digo do registro selecionado"
497
- },
498
- "complexType": {
499
- "original": "OptionsPesquisa",
500
- "resolved": "OptionsPesquisa",
501
- "references": {
502
- "OptionsPesquisa": {
503
- "location": "local"
504
- }
505
- }
506
- }
507
- }]; }
508
- static get methods() { return {
509
- "onInputTeste": {
510
- "complexType": {
511
- "signature": "() => Promise<void>",
512
- "parameters": [],
513
- "references": {},
514
- "return": "Promise<void>"
515
- },
516
- "docs": {
517
- "text": "",
518
- "tags": []
519
- }
520
- }
521
- }; }
522
- static get elementRef() { return "el"; }
523
- static get watchers() { return [{
524
- "propName": "value",
525
- "methodName": "valueChanged"
526
- }]; }
527
- }
1
+ import { Component, Element, Event, h, Host, Method, Prop, State, Watch } from '@stencil/core';
2
+ ;
3
+ ;
4
+ export class EzSearch {
5
+ constructor() {
6
+ this._options = [];
7
+ this._classSelect = 'list-container--4row';
8
+ /**
9
+ * Deixa o campo disponível ou não para digitação.
10
+ */
11
+ this.enabled = true;
12
+ /**
13
+ * Quantidade máxima de itens guardados no localstorage
14
+ */
15
+ this.qtdHotItems = 6;
16
+ /**
17
+ * Ajusta a opção de mostrar o "value" para cada "label". Como default "value" não está presente (showvalue = false)
18
+ */
19
+ this.showvalue = false;
20
+ ///// HOTSEARCH /////
21
+ this.buildId = () => {
22
+ return btoa(`${this.hotsearchid}:${location.pathname}`);
23
+ };
24
+ this.getStorageItems = (key) => {
25
+ let storageValueStr = localStorage.getItem('hotSearch-ez-search:' + key);
26
+ let storageItems = [];
27
+ if (storageValueStr !== null) {
28
+ storageItems = JSON.parse(storageValueStr);
29
+ }
30
+ return storageItems;
31
+ };
32
+ this.orderHotList = (list) => {
33
+ return list.sort((a, b) => {
34
+ let time1 = new Date(a.dtRecent).getTime();
35
+ let time2 = new Date(b.dtRecent).getTime();
36
+ let qtd1 = a.qtd;
37
+ let qtd2 = b.qtd;
38
+ if (time1 < time2)
39
+ return -1;
40
+ if (time1 > time2)
41
+ return 1;
42
+ if (qtd1 > qtd2)
43
+ return -1;
44
+ if (qtd1 < qtd2)
45
+ return 1;
46
+ return 0;
47
+ });
48
+ };
49
+ this.saveStorageItem = (key, value) => {
50
+ if (value == '' || value == undefined)
51
+ return;
52
+ let storageItem = this.getStorageItems(key);
53
+ let element = this.getElement(storageItem, value);
54
+ if (element) {
55
+ element.qtd++;
56
+ element.dtRecent = this.getOnlyDate();
57
+ }
58
+ else {
59
+ if (storageItem.length >= this.qtdHotItems) {
60
+ storageItem = this.orderHotList(storageItem);
61
+ storageItem.splice(-1, 1);
62
+ }
63
+ storageItem.push({
64
+ description: value,
65
+ qtd: 1,
66
+ dtRecent: this.getOnlyDate()
67
+ });
68
+ }
69
+ localStorage.setItem('hotSearch-ez-search:' + key, JSON.stringify(storageItem));
70
+ return storageItem;
71
+ };
72
+ this.adjustOptions = (arrayOptions) => {
73
+ let optionsTemp = [];
74
+ arrayOptions.map(el => {
75
+ optionsTemp.push({
76
+ value: el.value,
77
+ label: el.label,
78
+ ajustedValue: el.value === null || el.value === undefined || el.value === '' ? el.label : el.value,
79
+ });
80
+ });
81
+ return optionsTemp;
82
+ };
83
+ this.sortArrayOptions = (array, propname) => {
84
+ const sortedArray = array.sort(function (a, b) {
85
+ if (a[propname] < b[propname]) {
86
+ return -1;
87
+ }
88
+ if (a[propname] > b[propname]) {
89
+ return 1;
90
+ }
91
+ return 0;
92
+ });
93
+ return sortedArray;
94
+ };
95
+ }
96
+ valueChanged() {
97
+ var _a;
98
+ if (this.value) {
99
+ this.ezChange.emit({ value: this.value, label: (_a = this._inputElem) === null || _a === void 0 ? void 0 : _a.value });
100
+ let key = this.buildId();
101
+ this.saveStorageItem(key, this.value);
102
+ }
103
+ }
104
+ //ajustar ao fim do teste
105
+ onInputTeste() {
106
+ if (this._inputElem) {
107
+ this.handleChange();
108
+ }
109
+ }
110
+ getElement(storageItem, value) {
111
+ return storageItem.find(e => e.description === value);
112
+ }
113
+ getOnlyDate() {
114
+ let dt = new Date();
115
+ dt.setHours(0);
116
+ dt.setMinutes(0);
117
+ dt.setSeconds(0);
118
+ dt.setUTCMilliseconds(0);
119
+ return dt.toString();
120
+ }
121
+ onInputChange(ev) {
122
+ const el = ev.target;
123
+ let key = this.buildId();
124
+ this.saveStorageItem(key, el.value);
125
+ }
126
+ buildDataList() {
127
+ try {
128
+ if (this.hotsearchid === undefined) {
129
+ return;
130
+ }
131
+ let key = this.buildId();
132
+ let optionsArray = [];
133
+ this._options = [];
134
+ if (this.getStorageItems(key).length > 0) {
135
+ this.orderHotList(this.getStorageItems(key))
136
+ .forEach((el) => {
137
+ optionsArray.push({
138
+ value: el.description,
139
+ label: el.description,
140
+ });
141
+ });
142
+ this._options = [{ value: '', label: '' }].concat(optionsArray);
143
+ this.buildOptions();
144
+ }
145
+ }
146
+ catch (err) {
147
+ this.errormessage = err;
148
+ }
149
+ }
150
+ ///// EVENT HANDLERS
151
+ buildItem(opt, index) {
152
+ const className = index === this._preSelection ? "--li--preselected" : "";
153
+ return h("li", { class: className, key: opt.ajustedValue, accessKey: opt.label.toString(), id: 'item_' + opt.ajustedValue, onMouseDown: (ev) => this.handleSetValueByOption(ev) },
154
+ this.highlightMatch(opt.label),
155
+ this.showvalue ? h("span", { title: opt.ajustedValue, class: '--li__spanvalue' }, opt.ajustedValue) : null);
156
+ }
157
+ highlightMatch(label) {
158
+ var _a;
159
+ const spanClassName = this.showvalue ? '--li__spanlabel' : '--li__spanlabel--full-width';
160
+ if ((_a = this._inputElem) === null || _a === void 0 ? void 0 : _a.value) {
161
+ const criteriaLength = this._inputElem.value.length;
162
+ const matchStart = label.toUpperCase().indexOf(this._inputElem.value);
163
+ if (matchStart > -1) {
164
+ const strLabelStart = label.substr(0, matchStart);
165
+ const strLabelEnd = label.substr(matchStart + criteriaLength);
166
+ const strMatch = label.substr(matchStart, criteriaLength);
167
+ return (h("span", { class: spanClassName },
168
+ strLabelStart,
169
+ h("strong", null, strMatch),
170
+ strLabelEnd));
171
+ }
172
+ }
173
+ return (h("span", { class: spanClassName }, label));
174
+ }
175
+ showOptions() {
176
+ if (this.enabled) {
177
+ const top = this._inputElem.errormessage ? '0px' : '-17px';
178
+ this._popover.show(top);
179
+ }
180
+ }
181
+ nextOption() {
182
+ this.showOptions();
183
+ this._preSelection = this._preSelection === undefined ? 0 : Math.min(this._preSelection + 1, this._visibleOptions.length - 1);
184
+ this.scrollToOption(this._visibleOptions[this._preSelection]);
185
+ }
186
+ previousOption() {
187
+ this._preSelection = this._preSelection === undefined ? 0 : Math.max(this._preSelection - 1, 0);
188
+ this.scrollToOption(this._visibleOptions[this._preSelection]);
189
+ }
190
+ scrollToOption(opt) {
191
+ const liElem = this.el.shadowRoot.querySelector(`li#item_${opt.value}`);
192
+ if (liElem) {
193
+ const parent = liElem.parentElement;
194
+ const parentRect = parent.getBoundingClientRect();
195
+ const itemRect = liElem.getBoundingClientRect();
196
+ if (itemRect.bottom > parentRect.bottom || itemRect.top < parentRect.top) {
197
+ liElem.scrollIntoView();
198
+ }
199
+ }
200
+ }
201
+ selectCurrentOption() {
202
+ if (this._preSelection !== undefined) {
203
+ this.selectOption(this._visibleOptions[this._preSelection]);
204
+ this._preSelection = undefined;
205
+ }
206
+ }
207
+ selectOption(opt) {
208
+ this._popover.hide();
209
+ this.value = opt === null || opt === void 0 ? void 0 : opt.ajustedValue;
210
+ this._inputElem.value = opt.value;
211
+ //Definir com a equipe de design se vai ser utilizado dessa forma.
212
+ // this._inputElem.value = opt.value? opt.value + " - "+ opt?.label: '';
213
+ }
214
+ keyDownHandler(event) {
215
+ switch (event.key) {
216
+ case "ArrowDown":
217
+ this.nextOption();
218
+ break;
219
+ case "ArrowUp":
220
+ this.previousOption();
221
+ break;
222
+ case "Enter":
223
+ this.selectCurrentOption();
224
+ break;
225
+ }
226
+ event.stopPropagation();
227
+ }
228
+ handleSetValueByOption(ev) {
229
+ this._popover.hide();
230
+ const spanEl = ev.target;
231
+ const sourceElement = ev.composedPath()[0];
232
+ let li;
233
+ if (sourceElement.tagName === 'SPAN') {
234
+ li = spanEl.parentNode;
235
+ }
236
+ else {
237
+ li = spanEl.parentNode.parentNode;
238
+ }
239
+ this.value = li.id.split('_')[1];
240
+ this._inputElem.value = li.accessKey;
241
+ this.ezChange.emit();
242
+ }
243
+ handleChange() {
244
+ if (this._changeDeboucing) {
245
+ window.clearTimeout(this._changeDeboucing);
246
+ }
247
+ this._changeDeboucing = window.setTimeout(() => {
248
+ var _a, _b;
249
+ if (((_b = (_a = this._inputElem) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.length) <= 0) {
250
+ return;
251
+ }
252
+ /* save tip on localStorage */
253
+ let key = this.buildId();
254
+ this.saveStorageItem(key, this._inputElem.value);
255
+ /* load data */
256
+ if (this.loadexecutor) {
257
+ this._loadDataFunction(this._inputElem.value, (serverData) => { this.populateOptions(serverData); });
258
+ }
259
+ }, 200);
260
+ }
261
+ normalizeResult(data) {
262
+ let options = [];
263
+ if (data instanceof Array) {
264
+ options = data;
265
+ }
266
+ else {
267
+ if (data instanceof Object) {
268
+ for (var key in data) {
269
+ let newOption = { value: '', label: '' };
270
+ newOption.value = key;
271
+ newOption.label = data[key];
272
+ options.push(newOption);
273
+ }
274
+ }
275
+ }
276
+ this._options = [{ value: '', label: '' }].concat(options);
277
+ this.buildOptions();
278
+ }
279
+ populateOptions(serverData) {
280
+ if (serverData instanceof Promise) {
281
+ serverData.then(this.normalizeResult);
282
+ }
283
+ else {
284
+ this.normalizeResult(serverData);
285
+ }
286
+ }
287
+ buildOptions() {
288
+ var _a;
289
+ this._visibleOptions = [];
290
+ this._visibleOptions = this.adjustOptions(this._options);
291
+ this._visibleOptions = this.sortArrayOptions(this._visibleOptions, 'label');
292
+ if (this._visibleOptions.length > 0) {
293
+ (_a = this._divElem) === null || _a === void 0 ? void 0 : _a.classList.add(this._classSelect);
294
+ this.showOptions();
295
+ }
296
+ }
297
+ setClassForSpanLabel() {
298
+ if (!this.showvalue) {
299
+ return '--li__spanlabel--full-width';
300
+ }
301
+ else {
302
+ return '--li__spanlabel';
303
+ }
304
+ }
305
+ handleFocus() {
306
+ if (this._inputElem && (!this._inputElem.value || this._inputElem.value.length === 0)) {
307
+ this.buildDataList();
308
+ }
309
+ }
310
+ parseExecutor(executor) {
311
+ if (executor) {
312
+ return executor instanceof Function ? executor : eval(executor);
313
+ }
314
+ return null;
315
+ }
316
+ componentDidLoad() {
317
+ if (this.value && this.value.length > 0) {
318
+ this._inputElem.value = this.value;
319
+ }
320
+ this._loadDataFunction = this.parseExecutor(this.loadexecutor);
321
+ }
322
+ render() {
323
+ var _a;
324
+ return (h(Host, null,
325
+ h("ez-text-input", { ref: (el) => { this._inputElem = el; }, label: this.label, enabled: this.enabled, onFocus: () => { this.handleFocus(); }, onInput: () => { this.handleChange(); }, onKeyDown: event => this.keyDownHandler(event), errormessage: this.errormessage },
326
+ h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-search", onClick: () => { alert("Esta ação irá abrir o PopUp!"); }, slot: "leftIcon" })),
327
+ h("ez-popover", { boxwidth: '100%', ref: el => this._popover = el },
328
+ h("div", { class: 'list-container', ref: (el) => this._divElem = el }, (_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.map((opt, index) => this.buildItem(opt, index))))));
329
+ }
330
+ ;
331
+ static get is() { return "ez-search"; }
332
+ static get encapsulation() { return "shadow"; }
333
+ static get originalStyleUrls() { return {
334
+ "$": ["ez-search.css"]
335
+ }; }
336
+ static get styleUrls() { return {
337
+ "$": ["ez-search.css"]
338
+ }; }
339
+ static get properties() { return {
340
+ "value": {
341
+ "type": "string",
342
+ "mutable": true,
343
+ "complexType": {
344
+ "original": "string",
345
+ "resolved": "string",
346
+ "references": {}
347
+ },
348
+ "required": false,
349
+ "optional": false,
350
+ "docs": {
351
+ "tags": [],
352
+ "text": "C\u00F3digo do registro selecionado"
353
+ },
354
+ "attribute": "value",
355
+ "reflect": true
356
+ },
357
+ "label": {
358
+ "type": "string",
359
+ "mutable": true,
360
+ "complexType": {
361
+ "original": "string",
362
+ "resolved": "string",
363
+ "references": {}
364
+ },
365
+ "required": false,
366
+ "optional": false,
367
+ "docs": {
368
+ "tags": [],
369
+ "text": "Label \u00E9 o t\u00EDtulo do campo"
370
+ },
371
+ "attribute": "label",
372
+ "reflect": true
373
+ },
374
+ "enabled": {
375
+ "type": "boolean",
376
+ "mutable": true,
377
+ "complexType": {
378
+ "original": "boolean",
379
+ "resolved": "boolean",
380
+ "references": {}
381
+ },
382
+ "required": false,
383
+ "optional": false,
384
+ "docs": {
385
+ "tags": [],
386
+ "text": "Deixa o campo dispon\u00EDvel ou n\u00E3o para digita\u00E7\u00E3o."
387
+ },
388
+ "attribute": "enabled",
389
+ "reflect": true,
390
+ "defaultValue": "true"
391
+ },
392
+ "qtdHotItems": {
393
+ "type": "number",
394
+ "mutable": false,
395
+ "complexType": {
396
+ "original": "number",
397
+ "resolved": "number",
398
+ "references": {}
399
+ },
400
+ "required": false,
401
+ "optional": false,
402
+ "docs": {
403
+ "tags": [],
404
+ "text": "Quantidade m\u00E1xima de itens guardados no localstorage"
405
+ },
406
+ "attribute": "qtd-hot-items",
407
+ "reflect": true,
408
+ "defaultValue": "6"
409
+ },
410
+ "showvalue": {
411
+ "type": "boolean",
412
+ "mutable": false,
413
+ "complexType": {
414
+ "original": "boolean",
415
+ "resolved": "boolean",
416
+ "references": {}
417
+ },
418
+ "required": false,
419
+ "optional": false,
420
+ "docs": {
421
+ "tags": [],
422
+ "text": "Ajusta a op\u00E7\u00E3o de mostrar o \"value\" para cada \"label\". Como default \"value\" n\u00E3o est\u00E1 presente (showvalue = false)"
423
+ },
424
+ "attribute": "showvalue",
425
+ "reflect": true,
426
+ "defaultValue": "false"
427
+ },
428
+ "errormessage": {
429
+ "type": "string",
430
+ "mutable": true,
431
+ "complexType": {
432
+ "original": "string",
433
+ "resolved": "string",
434
+ "references": {}
435
+ },
436
+ "required": false,
437
+ "optional": false,
438
+ "docs": {
439
+ "tags": [],
440
+ "text": "Quando h\u00E1 um problema de valida\u00E7\u00E3o, serve como orienta\u00E7\u00E3o ao usu\u00E1rio"
441
+ },
442
+ "attribute": "errormessage",
443
+ "reflect": true
444
+ },
445
+ "loadexecutor": {
446
+ "type": "string",
447
+ "mutable": false,
448
+ "complexType": {
449
+ "original": "string | Function",
450
+ "resolved": "Function | string",
451
+ "references": {
452
+ "Function": {
453
+ "location": "global"
454
+ }
455
+ }
456
+ },
457
+ "required": false,
458
+ "optional": false,
459
+ "docs": {
460
+ "tags": [],
461
+ "text": "Quando h\u00E1 um problema de valida\u00E7\u00E3o, serve como orienta\u00E7\u00E3o ao usu\u00E1rio"
462
+ },
463
+ "attribute": "loadexecutor",
464
+ "reflect": false
465
+ },
466
+ "hotsearchid": {
467
+ "type": "string",
468
+ "mutable": false,
469
+ "complexType": {
470
+ "original": "string",
471
+ "resolved": "string",
472
+ "references": {}
473
+ },
474
+ "required": false,
475
+ "optional": false,
476
+ "docs": {
477
+ "tags": [],
478
+ "text": "Define o identificador \u00FAnico do hotSearch, caso esta propriedade n\u00E3o seja preenchida, o hotSearch n\u00E3o funcionar\u00E1."
479
+ },
480
+ "attribute": "hotsearchid",
481
+ "reflect": false
482
+ }
483
+ }; }
484
+ static get states() { return {
485
+ "_preSelection": {},
486
+ "_visibleOptions": {}
487
+ }; }
488
+ static get events() { return [{
489
+ "method": "ezChange",
490
+ "name": "ezChange",
491
+ "bubbles": true,
492
+ "cancelable": true,
493
+ "composed": true,
494
+ "docs": {
495
+ "tags": [],
496
+ "text": "Este evento emite o c\u00F3digo do registro selecionado"
497
+ },
498
+ "complexType": {
499
+ "original": "OptionsPesquisa",
500
+ "resolved": "OptionsPesquisa",
501
+ "references": {
502
+ "OptionsPesquisa": {
503
+ "location": "local"
504
+ }
505
+ }
506
+ }
507
+ }]; }
508
+ static get methods() { return {
509
+ "onInputTeste": {
510
+ "complexType": {
511
+ "signature": "() => Promise<void>",
512
+ "parameters": [],
513
+ "references": {},
514
+ "return": "Promise<void>"
515
+ },
516
+ "docs": {
517
+ "text": "",
518
+ "tags": []
519
+ }
520
+ }
521
+ }; }
522
+ static get elementRef() { return "el"; }
523
+ static get watchers() { return [{
524
+ "propName": "value",
525
+ "methodName": "valueChanged"
526
+ }]; }
527
+ }