@sankhyalabs/ezui 1.1.158 → 1.1.160
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.
- package/dist/cjs/ez-combo-box.cjs.entry.js +109 -29
- package/dist/cjs/ez-date-input.cjs.entry.js +71 -25
- package/dist/cjs/ez-date-time-input.cjs.entry.js +94 -31
- package/dist/cjs/ez-filter-input.cjs.entry.js +10 -4
- package/dist/cjs/ez-form.cjs.entry.js +54 -9
- package/dist/cjs/ez-grid.cjs.entry.js +9 -6
- package/dist/cjs/ez-number-input.cjs.entry.js +69 -25
- package/dist/cjs/ez-search.cjs.entry.js +20 -5
- package/dist/cjs/ez-text-area.cjs.entry.js +8 -2
- package/dist/cjs/ez-text-input.cjs.entry.js +38 -21
- package/dist/cjs/ez-time-input.cjs.entry.js +75 -40
- package/dist/cjs/ezui.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/ez-combo-box/ez-combo-box.css +15 -17
- package/dist/collection/components/ez-combo-box/ez-combo-box.js +132 -33
- package/dist/collection/components/ez-date-input/ez-date-input.js +87 -25
- package/dist/collection/components/ez-date-time-input/ez-date-time-input.js +108 -31
- package/dist/collection/components/ez-filter-input/ez-filter-input.js +26 -4
- package/dist/collection/components/ez-form/DataBinder.js +12 -3
- package/dist/collection/components/ez-form/ez-form.js +43 -6
- package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +1 -1
- package/dist/collection/components/ez-grid/ez-grid.js +14 -7
- package/dist/collection/components/ez-number-input/ez-number-input.js +83 -25
- package/dist/collection/components/ez-search/ez-search.js +38 -5
- package/dist/collection/components/ez-text-area/ez-text-area.css +1 -1
- package/dist/collection/components/ez-text-area/ez-text-area.js +23 -1
- package/dist/collection/components/ez-text-input/ez-text-input.css +2 -2
- package/dist/collection/components/ez-text-input/ez-text-input.js +53 -38
- package/dist/collection/components/ez-time-input/ez-time-input.js +95 -59
- package/dist/custom-elements/index.js +598 -239
- package/dist/esm/ez-combo-box.entry.js +109 -29
- package/dist/esm/ez-date-input.entry.js +71 -25
- package/dist/esm/ez-date-time-input.entry.js +94 -31
- package/dist/esm/ez-filter-input.entry.js +10 -4
- package/dist/esm/ez-form.entry.js +54 -9
- package/dist/esm/ez-grid.entry.js +9 -6
- package/dist/esm/ez-number-input.entry.js +69 -25
- package/dist/esm/ez-search.entry.js +20 -5
- package/dist/esm/ez-text-area.entry.js +8 -2
- package/dist/esm/ez-text-input.entry.js +38 -21
- package/dist/esm/ez-time-input.entry.js +76 -41
- package/dist/esm/ezui.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/ezui/ezui.esm.js +1 -1
- package/dist/ezui/p-003d53b1.entry.js +1 -0
- package/dist/ezui/p-267fa515.entry.js +1 -0
- package/dist/ezui/p-2acf7d59.entry.js +1 -0
- package/dist/ezui/p-403de0a4.entry.js +1 -0
- package/dist/ezui/p-4c3d136c.entry.js +1 -0
- package/dist/ezui/p-53bbba8e.entry.js +1 -0
- package/dist/ezui/p-6668c3b0.entry.js +1 -0
- package/dist/ezui/p-7fd6deec.entry.js +1 -0
- package/dist/ezui/p-ad6cc559.entry.js +1 -0
- package/dist/ezui/{p-be87ac5e.entry.js → p-ae2fea4c.entry.js} +1 -1
- package/dist/ezui/p-ff7b4b13.entry.js +1 -0
- package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +22 -8
- package/dist/types/components/ez-date-input/ez-date-input.d.ts +10 -3
- package/dist/types/components/ez-date-time-input/ez-date-time-input.d.ts +15 -7
- package/dist/types/components/ez-filter-input/ez-filter-input.d.ts +5 -1
- package/dist/types/components/ez-form/DataBinder.d.ts +1 -1
- package/dist/types/components/ez-form/ez-form.d.ts +1 -0
- package/dist/types/components/ez-grid/ez-grid.d.ts +4 -1
- package/dist/types/components/ez-number-input/ez-number-input.d.ts +14 -5
- package/dist/types/components/ez-search/ez-search.d.ts +6 -1
- package/dist/types/components/ez-text-area/ez-text-area.d.ts +4 -0
- package/dist/types/components/ez-text-input/ez-text-input.d.ts +9 -6
- package/dist/types/components/ez-time-input/ez-time-input.d.ts +17 -13
- package/dist/types/components.d.ts +49 -20
- package/package.json +1 -1
- package/dist/ezui/p-140f7085.entry.js +0 -1
- package/dist/ezui/p-49fdfa4b.entry.js +0 -1
- package/dist/ezui/p-4fdceb7d.entry.js +0 -1
- package/dist/ezui/p-6d4b1628.entry.js +0 -1
- package/dist/ezui/p-8f4fac31.entry.js +0 -1
- package/dist/ezui/p-91377c65.entry.js +0 -1
- package/dist/ezui/p-991ce464.entry.js +0 -1
- package/dist/ezui/p-b524dfca.entry.js +0 -1
- package/dist/ezui/p-ec21ecce.entry.js +0 -1
- package/dist/ezui/p-fc9b9487.entry.js +0 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { FloatingManager } from "@sankhyalabs/core";
|
|
2
2
|
import { Component, h, Host, Prop, State, Event, Element, Watch, Method } from "@stencil/core";
|
|
3
|
-
import CSSVarsUtils from "../../utils
|
|
3
|
+
import { ApplicationUtils, CSSVarsUtils } from "../../utils";
|
|
4
4
|
export class EzComboBox {
|
|
5
5
|
constructor() {
|
|
6
|
+
this._changeDeboucingTimeout = null;
|
|
6
7
|
this._limitCharsToSearch = 3;
|
|
7
8
|
this._deboucingTime = 300;
|
|
8
9
|
this._maxWidthValue = 0;
|
|
10
|
+
this._tabPressed = false;
|
|
11
|
+
this._textEmptyList = "Nenhum resultado encontrado";
|
|
9
12
|
this._startLoading = false;
|
|
10
13
|
this._showLoading = true;
|
|
11
14
|
/**
|
|
@@ -37,40 +40,66 @@ export class EzComboBox {
|
|
|
37
40
|
*/
|
|
38
41
|
this.mode = "regular";
|
|
39
42
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
observeErrorMessage() {
|
|
44
|
+
var _a;
|
|
45
|
+
if (this._textInput) {
|
|
46
|
+
this._textInput.errorMessage = this.errorMessage;
|
|
47
|
+
if (!((_a = this.errorMessage) === null || _a === void 0 ? void 0 : _a.trim())) {
|
|
48
|
+
this.setInputValue();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
observeValue(newValue, oldValue) {
|
|
53
|
+
var _a, _b, _c, _d;
|
|
54
|
+
if (this._textInput && newValue != oldValue) {
|
|
55
|
+
const newValueSelected = this.getSelectedOption(newValue);
|
|
56
|
+
const oldValueSelected = this.getSelectedOption(oldValue);
|
|
57
|
+
const currentValue = this.getSelectedOption(this.value);
|
|
58
|
+
if (((_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.value) === null || _a === void 0 ? void 0 : _a.toString()) != ((_b = newValueSelected === null || newValueSelected === void 0 ? void 0 : newValueSelected.value) === null || _b === void 0 ? void 0 : _b.toString())) {
|
|
59
|
+
this.value = newValueSelected;
|
|
60
|
+
}
|
|
61
|
+
if (((_c = newValueSelected === null || newValueSelected === void 0 ? void 0 : newValueSelected.value) === null || _c === void 0 ? void 0 : _c.toString()) !== ((_d = oldValueSelected === null || oldValueSelected === void 0 ? void 0 : oldValueSelected.value) === null || _d === void 0 ? void 0 : _d.toString())) {
|
|
62
|
+
this.setInputValue();
|
|
63
|
+
const valueEmitted = newValueSelected === null ? undefined : newValueSelected;
|
|
64
|
+
this.ezChange.emit(valueEmitted);
|
|
65
|
+
}
|
|
66
|
+
this.hideOptions();
|
|
67
|
+
this._criteria = undefined;
|
|
68
|
+
this._preSelection = undefined;
|
|
69
|
+
this.updateVisibleOptions();
|
|
43
70
|
}
|
|
44
|
-
this.hideOptions();
|
|
45
|
-
this._criteria = undefined;
|
|
46
|
-
this._preSelection = undefined;
|
|
47
|
-
this.updateVisibleOptions();
|
|
48
71
|
}
|
|
49
72
|
/**
|
|
50
73
|
* Realiza o foco no componente de seleção
|
|
51
74
|
*/
|
|
52
75
|
async setFocus() {
|
|
53
|
-
this.
|
|
76
|
+
this._textInput.setFocus();
|
|
54
77
|
}
|
|
55
78
|
/**
|
|
56
79
|
* Remove o foco no componente de seleção
|
|
57
80
|
*/
|
|
58
81
|
async setBlur() {
|
|
59
|
-
this.
|
|
82
|
+
this._textInput.setBlur();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Retorna informando se o campo está inválido (true | false)
|
|
86
|
+
*/
|
|
87
|
+
async isInvalid() {
|
|
88
|
+
return typeof this.errorMessage === "string" && this.errorMessage.trim() !== "";
|
|
60
89
|
}
|
|
61
90
|
getText() {
|
|
62
91
|
let text = "";
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
text = this.showSelectedValue ? `${
|
|
92
|
+
const currentValue = this.getSelectedOption(this.value);
|
|
93
|
+
if (currentValue) {
|
|
94
|
+
text = this.showSelectedValue ? `${currentValue.value} - ${currentValue.label}` : currentValue.label;
|
|
66
95
|
}
|
|
67
96
|
return text;
|
|
68
97
|
}
|
|
69
|
-
getSelectedOption() {
|
|
70
|
-
if (typeof
|
|
71
|
-
return this._visibleOptions.find(o => o.value ===
|
|
98
|
+
getSelectedOption(value) {
|
|
99
|
+
if (typeof value === "string" || value instanceof String) {
|
|
100
|
+
return this._visibleOptions.find(o => o.value === value);
|
|
72
101
|
}
|
|
73
|
-
return
|
|
102
|
+
return value;
|
|
74
103
|
}
|
|
75
104
|
updateVisibleOptions() {
|
|
76
105
|
let opts = this._source || [];
|
|
@@ -127,7 +156,7 @@ export class EzComboBox {
|
|
|
127
156
|
//FIXME: Provavelmente isso fará com que o popup abra em uma
|
|
128
157
|
//posição errada no futuro. Preferi fazer simples no começo,
|
|
129
158
|
//porque não quis onerar o text input com essa funcionalidade...
|
|
130
|
-
const top = (this.errorMessage || !this.canShowError || this.mode
|
|
159
|
+
const top = (this.errorMessage || !this.canShowError || this.mode === "slim") ? "0px" : "-19px";
|
|
131
160
|
this._floatingID = FloatingManager.float(this._listWrapper, this._listContainer, { autoClose: true, top });
|
|
132
161
|
window.requestAnimationFrame(() => {
|
|
133
162
|
this._listWrapper.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
|
|
@@ -175,6 +204,9 @@ export class EzComboBox {
|
|
|
175
204
|
this.selectOption(this._visibleOptions[this._preSelection]);
|
|
176
205
|
this._preSelection = undefined;
|
|
177
206
|
}
|
|
207
|
+
else {
|
|
208
|
+
this.controlListWithOnlyOne();
|
|
209
|
+
}
|
|
178
210
|
}
|
|
179
211
|
updateSource(source) {
|
|
180
212
|
this._startLoading = false;
|
|
@@ -191,6 +223,10 @@ export class EzComboBox {
|
|
|
191
223
|
if (Array.isArray(source)) {
|
|
192
224
|
this._source = source;
|
|
193
225
|
this.updateVisibleOptions();
|
|
226
|
+
if (this._tabPressed) {
|
|
227
|
+
this._tabPressed = false;
|
|
228
|
+
this.controlEmptySearch();
|
|
229
|
+
}
|
|
194
230
|
}
|
|
195
231
|
else {
|
|
196
232
|
this.selectOption(source);
|
|
@@ -203,15 +239,16 @@ export class EzComboBox {
|
|
|
203
239
|
}
|
|
204
240
|
selectOption(newOption) {
|
|
205
241
|
var _a, _b;
|
|
206
|
-
const
|
|
207
|
-
if (((_a =
|
|
242
|
+
const currentValue = this.getSelectedOption(this.value);
|
|
243
|
+
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())) {
|
|
208
244
|
const adjustedOpt = !(newOption === null || newOption === void 0 ? void 0 : newOption.value) ? undefined : newOption;
|
|
209
245
|
this.value = adjustedOpt;
|
|
210
|
-
this.errorMessage = "";
|
|
211
|
-
this.ezChange.emit(this.value);
|
|
212
246
|
}
|
|
213
247
|
else {
|
|
214
|
-
this.
|
|
248
|
+
this.setInputValue();
|
|
249
|
+
}
|
|
250
|
+
if (this.searchMode) {
|
|
251
|
+
this._visibleOptions = [];
|
|
215
252
|
}
|
|
216
253
|
}
|
|
217
254
|
loadOptions(mode, argument = "") {
|
|
@@ -225,11 +262,43 @@ export class EzComboBox {
|
|
|
225
262
|
}
|
|
226
263
|
}
|
|
227
264
|
cancelPreselection() {
|
|
228
|
-
if (!this.
|
|
265
|
+
if (!this._textInput.value && this.value) {
|
|
229
266
|
this.selectOption(undefined);
|
|
230
267
|
}
|
|
231
268
|
else {
|
|
232
|
-
this.
|
|
269
|
+
this.setInputValue();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
setInputValue(clearError = true) {
|
|
273
|
+
const textValue = this.getText();
|
|
274
|
+
if ((this._textInput.value || '') !== textValue) {
|
|
275
|
+
this._textInput.value = textValue;
|
|
276
|
+
if (clearError) {
|
|
277
|
+
this.errorMessage = "";
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
clearSearch() {
|
|
282
|
+
this.value = null;
|
|
283
|
+
}
|
|
284
|
+
controlListWithOnlyOne() {
|
|
285
|
+
if (this.searchMode) {
|
|
286
|
+
const source = this._visibleOptions;
|
|
287
|
+
if ((source === null || source === void 0 ? void 0 : source.length) === 1) {
|
|
288
|
+
this.selectOption(source[0]);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
controlEmptySearch() {
|
|
293
|
+
var _a;
|
|
294
|
+
if (this.searchMode) {
|
|
295
|
+
if (!((_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
296
|
+
this.clearSearch();
|
|
297
|
+
ApplicationUtils.info(this._textEmptyList);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
this.controlListWithOnlyOne();
|
|
301
|
+
}
|
|
233
302
|
}
|
|
234
303
|
}
|
|
235
304
|
//---------------------------------------------
|
|
@@ -264,7 +333,8 @@ export class EzComboBox {
|
|
|
264
333
|
}
|
|
265
334
|
}
|
|
266
335
|
componentDidLoad() {
|
|
267
|
-
CSSVarsUtils.applyVarsTextInput(this.el, this.
|
|
336
|
+
CSSVarsUtils.applyVarsTextInput(this.el, this._textInput);
|
|
337
|
+
this.setInputValue(false);
|
|
268
338
|
}
|
|
269
339
|
//---------------------------------------------
|
|
270
340
|
// Event handlers
|
|
@@ -284,7 +354,7 @@ export class EzComboBox {
|
|
|
284
354
|
const argument = (_a = event.target.value) === null || _a === void 0 ? void 0 : _a.trim();
|
|
285
355
|
const argumentNumber = Number(argument || undefined);
|
|
286
356
|
if (!this._criteria) {
|
|
287
|
-
this.
|
|
357
|
+
this._textInput.value = event.data || argument;
|
|
288
358
|
}
|
|
289
359
|
this._criteria = argument;
|
|
290
360
|
if (argument && (!isNaN(argumentNumber) || argument.length >= this._limitCharsToSearch)) {
|
|
@@ -316,6 +386,7 @@ export class EzComboBox {
|
|
|
316
386
|
}
|
|
317
387
|
}
|
|
318
388
|
keyDownHandler(event) {
|
|
389
|
+
this._tabPressed = false;
|
|
319
390
|
switch (event.key) {
|
|
320
391
|
case "ArrowDown":
|
|
321
392
|
this.nextOption();
|
|
@@ -329,6 +400,10 @@ export class EzComboBox {
|
|
|
329
400
|
case "Escape":
|
|
330
401
|
this.cancelPreselection();
|
|
331
402
|
break;
|
|
403
|
+
case "Tab":
|
|
404
|
+
this._tabPressed = true;
|
|
405
|
+
this.controlListWithOnlyOne();
|
|
406
|
+
break;
|
|
332
407
|
}
|
|
333
408
|
event.stopPropagation();
|
|
334
409
|
}
|
|
@@ -336,16 +411,21 @@ export class EzComboBox {
|
|
|
336
411
|
this.cancelPreselection();
|
|
337
412
|
}
|
|
338
413
|
render() {
|
|
414
|
+
var _a;
|
|
339
415
|
return (h(Host, null,
|
|
340
|
-
h("ez-text-input", { class: this.suppressSearch ? "suppressed-search-input" : "", ref: elem => this.
|
|
416
|
+
h("ez-text-input", { 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), onClick: () => this.onTextInputClickHandler(), onFocusout: () => this.onTextInputFocusOutHandler(), onKeyDown: event => this.keyDownHandler(event), label: this.label, canShowError: this.canShowError, errorMessage: this.errorMessage, mode: this.mode },
|
|
341
417
|
h("button", { class: "btn", slot: this.searchMode ? "leftIcon" : "rightIcon", disabled: !this.enabled, tabindex: -1, onClick: () => this.handlerIconClick() },
|
|
342
|
-
h("ez-icon", {
|
|
418
|
+
h("ez-icon", { iconName: this.searchMode ? "search" : "chevron-down" })),
|
|
419
|
+
this.searchMode && ((_a = this._textInput) === null || _a === void 0 ? void 0 : _a.value) && (this._criteria || this.value)
|
|
420
|
+
? h("button", { class: "btn", slot: "rightIcon", disabled: !this.enabled, tabindex: -1, onClick: () => this.clearSearch() },
|
|
421
|
+
h("ez-icon", { iconName: "close" }))
|
|
422
|
+
: undefined),
|
|
343
423
|
h("section", { class: "list-container", ref: elem => this._listContainer = elem },
|
|
344
424
|
h("div", { class: "list-wrapper", ref: elem => this._listWrapper = elem },
|
|
345
425
|
h("div", { class: "list-options", ref: elem => this._optionsList = elem },
|
|
346
426
|
this._visibleOptions.length === 0
|
|
347
427
|
&& h("div", { class: "message" },
|
|
348
|
-
!this._showLoading && h("span", { class: "message__no-result" },
|
|
428
|
+
!this._showLoading && h("span", { class: "message__no-result" }, this._textEmptyList),
|
|
349
429
|
this._showLoading && h("div", { class: "message__loading" })),
|
|
350
430
|
this.showOptionValue
|
|
351
431
|
? h("span", { class: "item__value item__value--hidden", ref: elem => this._itemValueBasis = elem })
|
|
@@ -468,7 +548,7 @@ export class EzComboBox {
|
|
|
468
548
|
"optional": false,
|
|
469
549
|
"docs": {
|
|
470
550
|
"tags": [],
|
|
471
|
-
"text": ""
|
|
551
|
+
"text": "Ativa o modo pesquisa do combobox"
|
|
472
552
|
},
|
|
473
553
|
"attribute": "search-mode",
|
|
474
554
|
"reflect": false
|
|
@@ -605,7 +685,8 @@ export class EzComboBox {
|
|
|
605
685
|
"_preSelection": {},
|
|
606
686
|
"_visibleOptions": {},
|
|
607
687
|
"_startLoading": {},
|
|
608
|
-
"_showLoading": {}
|
|
688
|
+
"_showLoading": {},
|
|
689
|
+
"_criteria": {}
|
|
609
690
|
}; }
|
|
610
691
|
static get events() { return [{
|
|
611
692
|
"method": "ezChange",
|
|
@@ -659,12 +740,30 @@ export class EzComboBox {
|
|
|
659
740
|
"text": "Remove o foco no componente de sele\u00E7\u00E3o",
|
|
660
741
|
"tags": []
|
|
661
742
|
}
|
|
743
|
+
},
|
|
744
|
+
"isInvalid": {
|
|
745
|
+
"complexType": {
|
|
746
|
+
"signature": "() => Promise<boolean>",
|
|
747
|
+
"parameters": [],
|
|
748
|
+
"references": {
|
|
749
|
+
"Promise": {
|
|
750
|
+
"location": "global"
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
"return": "Promise<boolean>"
|
|
754
|
+
},
|
|
755
|
+
"docs": {
|
|
756
|
+
"text": "Retorna informando se o campo est\u00E1 inv\u00E1lido (true | false)",
|
|
757
|
+
"tags": []
|
|
758
|
+
}
|
|
662
759
|
}
|
|
663
760
|
}; }
|
|
664
761
|
static get elementRef() { return "el"; }
|
|
665
762
|
static get watchers() { return [{
|
|
763
|
+
"propName": "errorMessage",
|
|
764
|
+
"methodName": "observeErrorMessage"
|
|
765
|
+
}, {
|
|
666
766
|
"propName": "value",
|
|
667
767
|
"methodName": "observeValue"
|
|
668
768
|
}]; }
|
|
669
769
|
}
|
|
670
|
-
;
|
|
@@ -3,6 +3,7 @@ import { DateUtils } from '@sankhyalabs/core';
|
|
|
3
3
|
import CSSVarsUtils from '../../utils/CSSVarsUtils';
|
|
4
4
|
export class EzDateInput {
|
|
5
5
|
constructor() {
|
|
6
|
+
this._focused = false;
|
|
6
7
|
/**
|
|
7
8
|
* Deixa o campo disponível ou não para uso.
|
|
8
9
|
*/
|
|
@@ -13,18 +14,33 @@ export class EzDateInput {
|
|
|
13
14
|
this.mode = "regular";
|
|
14
15
|
}
|
|
15
16
|
observeLabel() {
|
|
16
|
-
this._textInput
|
|
17
|
+
if (this._textInput) {
|
|
18
|
+
this._textInput.label = this.label;
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
21
|
observeErrorMessage() {
|
|
22
|
+
var _a;
|
|
19
23
|
if (this._textInput) {
|
|
20
24
|
this._textInput.errorMessage = this.errorMessage;
|
|
25
|
+
if (!((_a = this.errorMessage) === null || _a === void 0 ? void 0 : _a.trim())) {
|
|
26
|
+
this.setInputValue();
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
observeValue(newValue, oldValue) {
|
|
24
|
-
if (newValue != oldValue) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
if (this._textInput && newValue != oldValue) {
|
|
32
|
+
const newValueValidated = this.validateValue(newValue);
|
|
33
|
+
const oldValueValidated = this.validateValue(oldValue);
|
|
34
|
+
if ((newValueValidated === null || newValueValidated === void 0 ? void 0 : newValueValidated.getTime()) !== (oldValueValidated === null || oldValueValidated === void 0 ? void 0 : oldValueValidated.getTime())) {
|
|
35
|
+
const textValue = this.getTextValue(newValueValidated) || '';
|
|
36
|
+
const parsedDate = DateUtils.strToDate(textValue);
|
|
37
|
+
if ((parsedDate || !this._focused) && (this._textInput.value || '') !== textValue) {
|
|
38
|
+
this._textInput.value = textValue;
|
|
39
|
+
this._focused = false;
|
|
40
|
+
this.errorMessage = "";
|
|
41
|
+
}
|
|
42
|
+
const valueEmitted = newValueValidated === null ? undefined : newValueValidated;
|
|
43
|
+
this.ezChange.emit(valueEmitted);
|
|
28
44
|
}
|
|
29
45
|
}
|
|
30
46
|
}
|
|
@@ -40,58 +56,88 @@ export class EzDateInput {
|
|
|
40
56
|
async setBlur() {
|
|
41
57
|
this._textInput.setBlur();
|
|
42
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Retorna informando se o campo está inválido (true | false)
|
|
61
|
+
*/
|
|
62
|
+
async isInvalid() {
|
|
63
|
+
return typeof this.errorMessage === "string" && this.errorMessage.trim() !== "";
|
|
64
|
+
}
|
|
43
65
|
changeValue(newValue) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if ((newValue === null || newValue === void 0 ? void 0 : newValue.toString()) !== ((_a = this.value) === null || _a === void 0 ? void 0 : _a.toString())) {
|
|
49
|
-
this.value = newValue;
|
|
50
|
-
this.ezChange.emit(this.value);
|
|
66
|
+
const currentValue = this.validateValue(this.value);
|
|
67
|
+
const newValueValidated = this.validateValue(newValue);
|
|
68
|
+
if ((currentValue === null || currentValue === void 0 ? void 0 : currentValue.getTime()) !== (newValueValidated === null || newValueValidated === void 0 ? void 0 : newValueValidated.getTime())) {
|
|
69
|
+
this.value = newValueValidated;
|
|
51
70
|
}
|
|
52
71
|
}
|
|
53
72
|
showCalendar() {
|
|
54
|
-
this.
|
|
73
|
+
this.handleBlur();
|
|
55
74
|
this._calendar.value = this.value;
|
|
56
75
|
//FIXME: Provavelmente isso fará com que o popup abra em uma
|
|
57
76
|
//posição errada no futuro. Preferi fazer simples no começo,
|
|
58
77
|
//porque não quis onerar o text input com essa funcionalidade...
|
|
59
|
-
const top = this.
|
|
78
|
+
const top = this.errorMessage || this.mode === "slim" ? 0 : -19;
|
|
60
79
|
this._calendar.fitVertical(top, this._elem.clientHeight);
|
|
61
80
|
}
|
|
62
81
|
hideCalendar() {
|
|
63
82
|
this.changeValue(this._calendar.value);
|
|
64
83
|
this._calendar.hide();
|
|
65
84
|
}
|
|
66
|
-
|
|
85
|
+
handleBlur() {
|
|
67
86
|
const strValue = this._textInput.value;
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
const newValue = DateUtils.strToDate(strValue);
|
|
88
|
+
if (newValue || !strValue) {
|
|
89
|
+
this.errorMessage = "";
|
|
90
|
+
const currentValue = this.validateValue(this.value);
|
|
91
|
+
const newValueValidated = this.validateValue(newValue);
|
|
92
|
+
if ((currentValue === null || currentValue === void 0 ? void 0 : currentValue.getTime()) === (newValueValidated === null || newValueValidated === void 0 ? void 0 : newValueValidated.getTime())) {
|
|
93
|
+
if (newValueValidated) {
|
|
94
|
+
this._textInput.value = this.getTextValue(newValueValidated) || '';
|
|
95
|
+
this._focused = false;
|
|
96
|
+
}
|
|
97
|
+
this.ezCancelWaitingChange.emit();
|
|
72
98
|
}
|
|
73
99
|
else {
|
|
74
|
-
this.changeValue(
|
|
100
|
+
this.changeValue(newValueValidated);
|
|
75
101
|
}
|
|
76
102
|
}
|
|
77
103
|
else {
|
|
104
|
+
this.changeValue(undefined);
|
|
78
105
|
this.ezCancelWaitingChange.emit();
|
|
79
|
-
this.
|
|
106
|
+
this.errorMessage = "O valor digitado não é uma data válida";
|
|
80
107
|
}
|
|
81
108
|
}
|
|
82
109
|
getTextValue(d) {
|
|
83
110
|
return d ? new Intl.DateTimeFormat("pt-BR").format(d) : undefined;
|
|
84
111
|
}
|
|
85
|
-
|
|
86
|
-
this.
|
|
112
|
+
handleInput() {
|
|
113
|
+
const strValue = this._textInput.value;
|
|
114
|
+
const newValue = DateUtils.strToDate(strValue);
|
|
115
|
+
const currentValue = this.validateValue(this.value);
|
|
116
|
+
const newValueValidated = this.validateValue(newValue);
|
|
117
|
+
if ((currentValue === null || currentValue === void 0 ? void 0 : currentValue.getTime()) !== (newValueValidated === null || newValueValidated === void 0 ? void 0 : newValueValidated.getTime())) {
|
|
118
|
+
this._focused = true;
|
|
119
|
+
this.ezStartChange.emit({ waitmessage: "", blocking: false });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
validateValue(value) {
|
|
123
|
+
return value instanceof Date && !isNaN(value.valueOf())
|
|
124
|
+
? DateUtils.clearTime(value)
|
|
125
|
+
: undefined;
|
|
126
|
+
}
|
|
127
|
+
setInputValue() {
|
|
128
|
+
const textValue = this.getTextValue(this.value) || '';
|
|
129
|
+
if ((this._textInput.value || '') !== textValue) {
|
|
130
|
+
this._textInput.value = textValue;
|
|
131
|
+
}
|
|
87
132
|
}
|
|
88
133
|
componentDidLoad() {
|
|
89
134
|
CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
|
|
135
|
+
this.setInputValue();
|
|
90
136
|
}
|
|
91
137
|
render() {
|
|
92
138
|
return (h(Host, null,
|
|
93
|
-
h("ez-text-input", { ref: elem => this._textInput = elem,
|
|
94
|
-
this.changeValue(new Date()); }, label: this.label,
|
|
139
|
+
h("ez-text-input", { ref: elem => this._textInput = elem, "data-slave-mode": "true", onKeyDown: event => { if (event.key === "H" || event.key === "h")
|
|
140
|
+
this.changeValue(new Date()); }, label: this.label, onBlur: () => this.handleBlur(), onInput: () => this.handleInput(), restrict: "0123456789/", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode },
|
|
95
141
|
h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })),
|
|
96
142
|
h("ez-calendar", { onEzChange: (event) => { this.hideCalendar(); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem })));
|
|
97
143
|
}
|
|
@@ -281,6 +327,22 @@ export class EzDateInput {
|
|
|
281
327
|
"text": "Remove o foco no componente de data",
|
|
282
328
|
"tags": []
|
|
283
329
|
}
|
|
330
|
+
},
|
|
331
|
+
"isInvalid": {
|
|
332
|
+
"complexType": {
|
|
333
|
+
"signature": "() => Promise<boolean>",
|
|
334
|
+
"parameters": [],
|
|
335
|
+
"references": {
|
|
336
|
+
"Promise": {
|
|
337
|
+
"location": "global"
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
"return": "Promise<boolean>"
|
|
341
|
+
},
|
|
342
|
+
"docs": {
|
|
343
|
+
"text": "Retorna informando se o campo est\u00E1 inv\u00E1lido (true | false)",
|
|
344
|
+
"tags": []
|
|
345
|
+
}
|
|
284
346
|
}
|
|
285
347
|
}; }
|
|
286
348
|
static get elementRef() { return "_elem"; }
|