@sankhyalabs/ezui 5.10.8 → 5.11.0-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/README.md +8 -11
  2. package/dist/cjs/{CSSVarsUtils-af809e73.js → CSSVarsUtils-b136a156.js} +5 -0
  3. package/dist/cjs/RecordValidationProcessor-edd23705.js +102 -0
  4. package/dist/cjs/ez-actions-button.cjs.entry.js +1 -1
  5. package/dist/cjs/ez-calendar.cjs.entry.js +34 -5
  6. package/dist/cjs/ez-card-item.cjs.entry.js +1 -1
  7. package/dist/cjs/ez-combo-box.cjs.entry.js +99 -16
  8. package/dist/cjs/ez-date-input.cjs.entry.js +53 -22
  9. package/dist/cjs/ez-date-time-input.cjs.entry.js +53 -19
  10. package/dist/cjs/ez-filter-input_2.cjs.entry.js +1 -1
  11. package/dist/cjs/ez-form-view.cjs.entry.js +42 -1
  12. package/dist/cjs/ez-form.cjs.entry.js +11 -84
  13. package/dist/cjs/ez-grid.cjs.entry.js +575 -44
  14. package/dist/cjs/ez-multi-selection-list.cjs.entry.js +3 -1
  15. package/dist/cjs/ez-number-input.cjs.entry.js +39 -15
  16. package/dist/cjs/ez-search.cjs.entry.js +13 -2
  17. package/dist/cjs/ez-text-area.cjs.entry.js +6 -2
  18. package/dist/cjs/ez-text-input.cjs.entry.js +7 -4
  19. package/dist/cjs/ez-time-input.cjs.entry.js +11 -7
  20. package/dist/cjs/ezui.cjs.js +1 -1
  21. package/dist/cjs/filter-column.cjs.entry.js +30 -7
  22. package/dist/cjs/loader.cjs.js +1 -1
  23. package/dist/collection/collection-manifest.json +2 -2
  24. package/dist/collection/components/ez-calendar/ez-calendar.js +63 -6
  25. package/dist/collection/components/ez-card-item/ez-card-item.css +1 -0
  26. package/dist/collection/components/ez-combo-box/ez-combo-box.css +6 -0
  27. package/dist/collection/components/ez-combo-box/ez-combo-box.js +168 -14
  28. package/dist/collection/components/ez-date-input/ez-date-input.js +71 -21
  29. package/dist/collection/components/ez-date-time-input/ez-date-time-input.js +71 -18
  30. package/dist/collection/components/ez-form/ez-form.js +20 -0
  31. package/dist/collection/components/ez-form-view/ez-form-view.js +23 -0
  32. package/dist/collection/components/ez-form-view/fieldbuilder/FieldBuilder.js +4 -1
  33. package/dist/collection/components/ez-form-view/structure/index.js +34 -0
  34. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +41 -8
  35. package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +1 -0
  36. package/dist/collection/components/ez-grid/controller/ag-grid/GridEditionManager.js +230 -0
  37. package/dist/collection/components/ez-grid/controller/ag-grid/components/EzGridCustomHeader.js +1 -1
  38. package/dist/collection/components/ez-grid/controller/ag-grid/editor/EzCellEditor.js +49 -0
  39. package/dist/collection/components/ez-grid/controller/ag-grid/editor/GridEditorUtils.js +10 -0
  40. package/dist/collection/components/ez-grid/controller/ag-grid/editor/IEditorMetadata.js +4 -0
  41. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/ComboBox.tpl.js +38 -0
  42. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/DateInput.tpl.js +40 -0
  43. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/NumberInput.tpl.js +20 -0
  44. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/Search.tpl.js +15 -0
  45. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/TextInput.tpl.js +41 -0
  46. package/dist/collection/components/ez-grid/ez-grid.js +78 -39
  47. package/dist/collection/components/ez-grid/subcomponents/filter-column.js +50 -8
  48. package/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource.js +78 -0
  49. package/dist/collection/components/ez-multi-selection-list/ez-multi-selection-list.js +21 -1
  50. package/dist/collection/components/ez-number-input/ez-number-input.css +4 -0
  51. package/dist/collection/components/ez-number-input/ez-number-input.js +62 -15
  52. package/dist/collection/components/ez-search/ez-search.css +1 -1
  53. package/dist/collection/components/ez-search/ez-search.js +84 -1
  54. package/dist/collection/components/ez-text-area/ez-text-area.css +4 -0
  55. package/dist/collection/components/ez-text-area/ez-text-area.js +23 -1
  56. package/dist/collection/components/ez-text-input/ez-text-input.css +8 -1
  57. package/dist/collection/components/ez-text-input/ez-text-input.js +14 -5
  58. package/dist/collection/components/ez-time-input/ez-time-input.css +4 -0
  59. package/dist/collection/components/ez-time-input/ez-time-input.js +18 -7
  60. package/dist/collection/utils/CSSVarsUtils.js +5 -0
  61. package/dist/collection/utils/form/DataBinder.js +8 -63
  62. package/dist/collection/utils/form/FormMetadata.js +3 -22
  63. package/dist/collection/utils/interfaces/AbstractFieldMetadata.js +21 -0
  64. package/dist/collection/utils/validators/recordvalidator/IValidationResult.js +1 -0
  65. package/dist/collection/utils/validators/recordvalidator/IValidationSource.js +1 -0
  66. package/dist/collection/utils/validators/recordvalidator/RecordValidationProcessor.js +74 -0
  67. package/dist/custom-elements/index.js +1101 -256
  68. package/dist/esm/{CSSVarsUtils-00f67f32.js → CSSVarsUtils-a97cfa29.js} +5 -0
  69. package/dist/esm/RecordValidationProcessor-abc814af.js +99 -0
  70. package/dist/esm/ez-actions-button.entry.js +1 -1
  71. package/dist/esm/ez-calendar.entry.js +35 -6
  72. package/dist/esm/ez-card-item.entry.js +1 -1
  73. package/dist/esm/ez-combo-box.entry.js +99 -16
  74. package/dist/esm/ez-date-input.entry.js +53 -22
  75. package/dist/esm/ez-date-time-input.entry.js +53 -19
  76. package/dist/esm/ez-filter-input_2.entry.js +1 -1
  77. package/dist/esm/ez-form-view.entry.js +42 -1
  78. package/dist/esm/ez-form.entry.js +12 -85
  79. package/dist/esm/ez-grid.entry.js +576 -45
  80. package/dist/esm/ez-multi-selection-list.entry.js +3 -1
  81. package/dist/esm/ez-number-input.entry.js +39 -15
  82. package/dist/esm/ez-search.entry.js +13 -2
  83. package/dist/esm/ez-text-area.entry.js +6 -2
  84. package/dist/esm/ez-text-input.entry.js +7 -4
  85. package/dist/esm/ez-time-input.entry.js +11 -7
  86. package/dist/esm/ezui.js +1 -1
  87. package/dist/esm/filter-column.entry.js +30 -7
  88. package/dist/esm/loader.js +1 -1
  89. package/dist/ezui/ezui.esm.js +1 -1
  90. package/dist/ezui/p-028f264f.entry.js +1 -0
  91. package/dist/ezui/p-061f4d73.entry.js +1 -0
  92. package/dist/ezui/p-25562cf8.entry.js +1 -0
  93. package/dist/ezui/p-3078d25c.entry.js +1 -0
  94. package/dist/ezui/p-391de0e4.entry.js +1 -0
  95. package/dist/ezui/{p-68352e41.entry.js → p-47afb974.entry.js} +1 -1
  96. package/dist/ezui/p-5cef0264.entry.js +1 -0
  97. package/dist/ezui/p-5e55a42b.entry.js +1 -0
  98. package/dist/ezui/p-7526f2b6.entry.js +1 -0
  99. package/dist/ezui/p-7eb3e1a5.js +1 -0
  100. package/dist/ezui/p-86a2036d.js +1 -0
  101. package/dist/ezui/{p-12303d2e.entry.js → p-87e85160.entry.js} +1 -1
  102. package/dist/ezui/{p-c7a23be9.entry.js → p-964e5571.entry.js} +2 -2
  103. package/dist/ezui/p-ce035beb.entry.js +1 -0
  104. package/dist/ezui/p-d43b22f3.entry.js +1 -0
  105. package/dist/ezui/p-df93558d.entry.js +1 -0
  106. package/dist/ezui/p-e2dfd935.entry.js +1 -0
  107. package/dist/ezui/p-e67d0bd5.entry.js +1 -0
  108. package/dist/ezui/{p-f1a537e3.entry.js → p-ff82b176.entry.js} +1 -1
  109. package/dist/types/components/ez-calendar/ez-calendar.d.ts +9 -1
  110. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +23 -0
  111. package/dist/types/components/ez-date-input/ez-date-input.d.ts +4 -0
  112. package/dist/types/components/ez-date-time-input/ez-date-time-input.d.ts +4 -0
  113. package/dist/types/components/ez-form/ez-form.d.ts +5 -0
  114. package/dist/types/components/ez-form-view/ez-form-view.d.ts +5 -0
  115. package/dist/types/components/ez-form-view/interfaces/IFormViewField.d.ts +2 -14
  116. package/dist/types/components/ez-form-view/structure/index.d.ts +15 -0
  117. package/dist/types/components/ez-grid/controller/EzGridController.d.ts +18 -0
  118. package/dist/types/components/ez-grid/controller/ag-grid/AgGridController.d.ts +4 -0
  119. package/dist/types/components/ez-grid/controller/ag-grid/GridEditionManager.d.ts +38 -0
  120. package/dist/types/components/ez-grid/controller/ag-grid/components/EzGridCustomHeader.d.ts +1 -1
  121. package/dist/types/components/ez-grid/controller/ag-grid/editor/EzCellEditor.d.ts +10 -0
  122. package/dist/types/components/ez-grid/controller/ag-grid/editor/GridEditorUtils.d.ts +1 -0
  123. package/dist/types/components/ez-grid/controller/ag-grid/editor/IEditorMetadata.d.ts +9 -0
  124. package/dist/types/components/ez-grid/controller/ag-grid/editor/IUICellEditor.d.ts +10 -0
  125. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/ComboBox.tpl.d.ts +4 -0
  126. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/DateInput.tpl.d.ts +5 -0
  127. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/NumberInput.tpl.d.ts +4 -0
  128. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/Search.tpl.d.ts +3 -0
  129. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/TextInput.tpl.d.ts +4 -0
  130. package/dist/types/components/ez-grid/ez-grid.d.ts +16 -5
  131. package/dist/types/components/ez-grid/subcomponents/filter-column.d.ts +8 -0
  132. package/dist/types/components/ez-grid/utils/InMemoryFilterColumnDataSource.d.ts +16 -0
  133. package/dist/types/components/ez-multi-selection-list/ez-multi-selection-list.d.ts +4 -0
  134. package/dist/types/components/ez-number-input/ez-number-input.d.ts +5 -1
  135. package/dist/types/components/ez-search/ez-search.d.ts +14 -1
  136. package/dist/types/components/ez-text-area/ez-text-area.d.ts +4 -0
  137. package/dist/types/components/ez-text-input/ez-text-input.d.ts +4 -1
  138. package/dist/types/components/ez-time-input/ez-time-input.d.ts +2 -1
  139. package/dist/types/components.d.ts +116 -6
  140. package/dist/types/utils/form/DataBinder.d.ts +1 -3
  141. package/dist/types/utils/form/interfaces/IFormConfig.d.ts +1 -1
  142. package/dist/types/utils/form/interfaces/index.d.ts +4 -4
  143. package/dist/types/utils/interfaces/AbstractFieldMetadata.d.ts +17 -0
  144. package/dist/types/utils/{form/interfaces → interfaces}/IFieldConfig.d.ts +2 -2
  145. package/dist/types/utils/validators/recordvalidator/IValidationSource.d.ts +6 -0
  146. package/dist/types/utils/validators/recordvalidator/RecordValidationProcessor.d.ts +13 -0
  147. package/package.json +3 -3
  148. package/dist/ezui/p-00c7c25d.entry.js +0 -1
  149. package/dist/ezui/p-0b160fec.entry.js +0 -1
  150. package/dist/ezui/p-0bd54a6f.entry.js +0 -1
  151. package/dist/ezui/p-2a0e1679.entry.js +0 -1
  152. package/dist/ezui/p-39153935.entry.js +0 -1
  153. package/dist/ezui/p-4a5e37a7.js +0 -1
  154. package/dist/ezui/p-4c8b029b.entry.js +0 -1
  155. package/dist/ezui/p-4e31b69b.entry.js +0 -1
  156. package/dist/ezui/p-5782443e.entry.js +0 -1
  157. package/dist/ezui/p-5d45e384.entry.js +0 -1
  158. package/dist/ezui/p-70ea4beb.entry.js +0 -1
  159. package/dist/ezui/p-78a6e049.entry.js +0 -1
  160. package/dist/ezui/p-8bcb197f.entry.js +0 -1
  161. package/dist/ezui/p-a4c9f3c4.entry.js +0 -1
  162. /package/dist/collection/{utils/form/interfaces/IFieldConfig.js → components/ez-grid/controller/ag-grid/editor/IUICellEditor.js} +0 -0
  163. /package/dist/collection/utils/{form/interfaces/IInvalidField.js → interfaces/IFieldConfig.js} +0 -0
  164. /package/dist/collection/utils/{form/interfaces/IRecordValidator.js → validators/recordvalidator/IInvalidField.js} +0 -0
  165. /package/dist/collection/utils/{form/interfaces/IValidationResult.js → validators/recordvalidator/IRecordValidator.js} +0 -0
  166. /package/dist/types/utils/{form/interfaces → validators/recordvalidator}/IInvalidField.d.ts +0 -0
  167. /package/dist/types/utils/{form/interfaces → validators/recordvalidator}/IRecordValidator.d.ts +0 -0
  168. /package/dist/types/utils/{form/interfaces → validators/recordvalidator}/IValidationResult.d.ts +0 -0
@@ -3,7 +3,9 @@ import { DateUtils, ElementIDUtils, TimeFormatter } from '@sankhyalabs/core';
3
3
  import CSSVarsUtils from '../../utils/CSSVarsUtils';
4
4
  export class EzDateTimeInput {
5
5
  constructor() {
6
+ this._changePending = false;
6
7
  this._focused = false;
8
+ this._valuePromiseCallbacks = [];
7
9
  this.label = undefined;
8
10
  this.value = undefined;
9
11
  this.enabled = true;
@@ -42,6 +44,7 @@ export class EzDateTimeInput {
42
44
  this.ezChange.emit(valueEmitted);
43
45
  }
44
46
  }
47
+ this._changePending = false;
45
48
  }
46
49
  /**
47
50
  * Aplica o foco no campo.
@@ -61,6 +64,18 @@ export class EzDateTimeInput {
61
64
  async isInvalid() {
62
65
  return typeof this.errorMessage === "string" && this.errorMessage.trim() !== "";
63
66
  }
67
+ /*
68
+ * Retorna uma promise com o valor da opção selecionada,
69
+ * que será resolvida quando o backend devolver este dado.
70
+ */
71
+ async getValueAsync() {
72
+ if (this._changePending) {
73
+ return new Promise(accept => {
74
+ this._valuePromiseCallbacks.push(accept);
75
+ });
76
+ }
77
+ return Promise.resolve(this.value);
78
+ }
64
79
  handleKeyDown(event) {
65
80
  const input = this._textInput.shadowRoot.querySelector('input');
66
81
  if (event.shiftKey && event.key === "Tab") {
@@ -105,7 +120,14 @@ export class EzDateTimeInput {
105
120
  }
106
121
  }
107
122
  showCalendar() {
108
- const top = this.errorMessage || this.mode === "slim" ? 6 : -13;
123
+ let top;
124
+ if (this.isFixed()) {
125
+ top = 29;
126
+ this._calendar.fitHorizontal(0);
127
+ }
128
+ else {
129
+ top = this.errorMessage || this.mode === "slim" ? 6 : -13;
130
+ }
109
131
  this._calendar.fitVertical(top, this._elem.clientHeight);
110
132
  this._calendar.style.visibility = 'inherit';
111
133
  }
@@ -130,27 +152,35 @@ export class EzDateTimeInput {
130
152
  }
131
153
  handleBlur() {
132
154
  var _a, _b;
133
- const strValue = ((_b = (_a = this._textInput) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.trim()) || "";
134
- const newValue = this.getParsedDateTime();
135
- if (newValue || !strValue) {
136
- this.errorMessage = "";
137
- const currentValue = DateUtils.validateDate(this.value, true);
138
- const newValueValidated = DateUtils.validateDate(newValue, true);
139
- if ((currentValue === null || currentValue === void 0 ? void 0 : currentValue.getTime()) === (newValueValidated === null || newValueValidated === void 0 ? void 0 : newValueValidated.getTime())) {
140
- if (newValueValidated) {
141
- this._textInput.value = this.getTextValue(newValueValidated) || '';
142
- this._focused = false;
155
+ try {
156
+ const strValue = ((_b = (_a = this._textInput) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.trim()) || "";
157
+ const newValue = this.getParsedDateTime();
158
+ if (newValue || !strValue) {
159
+ this.errorMessage = "";
160
+ const currentValue = DateUtils.validateDate(this.value, true);
161
+ const newValueValidated = DateUtils.validateDate(newValue, true);
162
+ if ((currentValue === null || currentValue === void 0 ? void 0 : currentValue.getTime()) === (newValueValidated === null || newValueValidated === void 0 ? void 0 : newValueValidated.getTime())) {
163
+ if (newValueValidated) {
164
+ this._textInput.value = this.getTextValue(newValueValidated) || '';
165
+ this._focused = false;
166
+ }
167
+ this.ezCancelWaitingChange.emit();
168
+ }
169
+ else {
170
+ this.changeValue(newValueValidated);
143
171
  }
144
- this.ezCancelWaitingChange.emit();
145
172
  }
146
173
  else {
147
- this.changeValue(newValueValidated);
174
+ this.changeValue(undefined);
175
+ this.ezCancelWaitingChange.emit();
176
+ this.errorMessage = "O valor digitado não é uma data válida";
148
177
  }
149
178
  }
150
- else {
151
- this.changeValue(undefined);
152
- this.ezCancelWaitingChange.emit();
153
- this.errorMessage = "O valor digitado não é uma data válida";
179
+ finally {
180
+ for (const callback of this._valuePromiseCallbacks) {
181
+ callback(this.value);
182
+ }
183
+ this._valuePromiseCallbacks = [];
154
184
  }
155
185
  }
156
186
  getTextValue(date) {
@@ -164,6 +194,7 @@ export class EzDateTimeInput {
164
194
  const currentValue = DateUtils.validateDate(this.value, true);
165
195
  const newValueValidated = DateUtils.validateDate(newValue, true);
166
196
  if ((currentValue === null || currentValue === void 0 ? void 0 : currentValue.getTime()) !== (newValueValidated === null || newValueValidated === void 0 ? void 0 : newValueValidated.getTime())) {
197
+ this._changePending = true;
167
198
  this._focused = true;
168
199
  this.ezStartChange.emit({ waitmessage: "", blocking: false });
169
200
  }
@@ -177,13 +208,16 @@ export class EzDateTimeInput {
177
208
  this._textInput.value = textValue;
178
209
  }
179
210
  }
211
+ isFixed() {
212
+ return this._elem.dataset.isFixed === "true";
213
+ }
180
214
  componentDidLoad() {
181
215
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
182
216
  this.setInputValue();
183
217
  }
184
218
  render() {
185
219
  ElementIDUtils.addIDInfoIfNotExists(this._elem, 'input');
186
- return (h(Host, null, h("ez-text-input", { "data-element-id": ElementIDUtils.getInternalIDInfo("textInput"), ref: elem => this._textInput = elem, "data-slave-mode": "true", label: this.label, restrict: "0123456789/: ", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, onKeyDown: event => { this.handleKeyDown(event); }, onBlur: () => this.handleBlur(), onInput: (evt) => this.handleInput(evt), onFocus: () => this.handleFocus(), onClick: () => this.handleClick(), canShowError: this.canShowError }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { "data-element-id": ElementIDUtils.getInternalIDInfo("calendar"), onEzChange: (event) => { this.hideCalendar(); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem, time: true, showSeconds: this.showSeconds })));
220
+ return (h(Host, null, h("ez-text-input", { "data-element-id": ElementIDUtils.getInternalIDInfo("textInput"), ref: elem => this._textInput = elem, "data-slave-mode": "true", label: this.label, restrict: "0123456789/: ", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, onKeyDown: event => { this.handleKeyDown(event); }, onBlur: () => this.handleBlur(), onInput: (evt) => this.handleInput(evt), onFocus: () => this.handleFocus(), onClick: () => this.handleClick(), canShowError: this.canShowError }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { ref: elem => this._calendar = elem, "data-element-id": ElementIDUtils.getInternalIDInfo("calendar"), onEzChange: (event) => { this.hideCalendar(); event.stopPropagation(); }, floating: true, time: true, showSeconds: this.showSeconds, "data-is-fixed": this._elem.dataset.isFixed })));
187
221
  }
188
222
  static get is() { return "ez-date-time-input"; }
189
223
  static get encapsulation() { return "shadow"; }
@@ -432,6 +466,25 @@ export class EzDateTimeInput {
432
466
  "text": "Retorna se o conte\u00FAdo \u00E9 inv\u00E1lido.",
433
467
  "tags": []
434
468
  }
469
+ },
470
+ "getValueAsync": {
471
+ "complexType": {
472
+ "signature": "() => Promise<Date>",
473
+ "parameters": [],
474
+ "references": {
475
+ "Promise": {
476
+ "location": "global"
477
+ },
478
+ "Date": {
479
+ "location": "global"
480
+ }
481
+ },
482
+ "return": "Promise<Date>"
483
+ },
484
+ "docs": {
485
+ "text": "",
486
+ "tags": []
487
+ }
435
488
  }
436
489
  };
437
490
  }
@@ -185,6 +185,26 @@ export class EzForm {
185
185
  "resolved": "void",
186
186
  "references": {}
187
187
  }
188
+ }, {
189
+ "method": "formItemsReady",
190
+ "name": "formItemsReady",
191
+ "bubbles": true,
192
+ "cancelable": true,
193
+ "composed": true,
194
+ "docs": {
195
+ "tags": [],
196
+ "text": "Respons\u00E1vel por notificar quando ocorrer a renderiza\u00E7\u00E3o de itens do formul\u00E1rio."
197
+ },
198
+ "complexType": {
199
+ "original": "FormItems",
200
+ "resolved": "FormItems",
201
+ "references": {
202
+ "FormItems": {
203
+ "location": "import",
204
+ "path": "../ez-form-view/structure"
205
+ }
206
+ }
207
+ }
188
208
  }];
189
209
  }
190
210
  static get methods() {
@@ -1,6 +1,7 @@
1
1
  import { Host, h } from '@stencil/core';
2
2
  import { fieldBuilder } from './fieldbuilder/FieldBuilder';
3
3
  import { ElementIDUtils } from '@sankhyalabs/core';
4
+ import { FormItems } from './structure';
4
5
  export class EzFormView {
5
6
  constructor() {
6
7
  this.fields = undefined;
@@ -28,6 +29,8 @@ export class EzFormView {
28
29
  }
29
30
  componentDidRender() {
30
31
  this.ezContentReady.emit(Array.from(this._element.querySelectorAll("[data-field-name]")));
32
+ const formItems = new FormItems(Array.from(this._element.querySelectorAll("[data-form-item]")));
33
+ this.formItemsReady.emit(formItems);
31
34
  }
32
35
  render() {
33
36
  ElementIDUtils.addIDInfoIfNotExists(this._element, 'ezFormView');
@@ -105,6 +108,26 @@ export class EzFormView {
105
108
  }
106
109
  }
107
110
  }
111
+ }, {
112
+ "method": "formItemsReady",
113
+ "name": "formItemsReady",
114
+ "bubbles": true,
115
+ "cancelable": true,
116
+ "composed": true,
117
+ "docs": {
118
+ "tags": [],
119
+ "text": "Respons\u00E1vel por notificar quando ocorrer a renderiza\u00E7\u00E3o de itens do formul\u00E1rio."
120
+ },
121
+ "complexType": {
122
+ "original": "FormItems",
123
+ "resolved": "FormItems",
124
+ "references": {
125
+ "FormItems": {
126
+ "location": "import",
127
+ "path": "./structure"
128
+ }
129
+ }
130
+ }
108
131
  }];
109
132
  }
110
133
  static get methods() {
@@ -23,5 +23,8 @@ uiBuilders.set(UserInterface.LONGTEXT, buildTextArea);
23
23
  export const fieldBuilder = (field) => {
24
24
  const builder = uiBuilders.get(field.userInterface) || buildTextInput;
25
25
  const label = field.required ? `${field.label}${REQUIRED_INFO}` : field.label;
26
- return builder(Object.assign(Object.assign({}, field), { label }));
26
+ const builtElement = builder(Object.assign(Object.assign({}, field), { label }));
27
+ //@ts-ignore
28
+ builtElement.$attrs$['data-form-item'] = field.name;
29
+ return builtElement;
27
30
  };
@@ -0,0 +1,34 @@
1
+ class FormItem {
2
+ constructor(elem) {
3
+ this.elem = elem;
4
+ }
5
+ addRightElement(el) {
6
+ this.removeRightElement();
7
+ el.classList.add('ez-padding-left--small');
8
+ el.setAttribute('data-custom-item', 'true');
9
+ this.elem.classList.add('ez-col--nowrap');
10
+ this.elem.appendChild(el);
11
+ }
12
+ removeRightElement() {
13
+ Array.from(this.elem.querySelectorAll('[data-custom-item="true"]')).forEach(item => item.remove());
14
+ }
15
+ get fieldName() {
16
+ return this.elem.getAttribute('data-form-item');
17
+ }
18
+ }
19
+ export class FormItems {
20
+ constructor(items, formId) {
21
+ this.items = new Map();
22
+ this.formId = formId;
23
+ items.forEach(item => {
24
+ const formItem = new FormItem(item);
25
+ this.items.set(formItem.fieldName, formItem);
26
+ });
27
+ }
28
+ getItem(name) {
29
+ return this.items.get(name);
30
+ }
31
+ get formName() {
32
+ return this.formId;
33
+ }
34
+ }
@@ -1,4 +1,4 @@
1
- import { ApplicationContext, DataType, NumberUtils, SortMode, StringUtils, UserInterface } from '@sankhyalabs/core';
1
+ import { ApplicationContext, DataType, MaskFormatter, NumberUtils, SortMode, StringUtils, UserInterface } from '@sankhyalabs/core';
2
2
  import { Grid, } from 'ag-grid-community';
3
3
  import { Grid as EnterpriseGrid, LicenseManager } from 'ag-grid-enterprise';
4
4
  import DataSource from './DataSource';
@@ -8,6 +8,7 @@ import SelectionHeader from './components/selectionHeader';
8
8
  import gridTerms from './i18n/pt-BR.js';
9
9
  import { DISTINCT_FILTER_NAME_PREFIX } from '../../../../utils/constants';
10
10
  import { calcFilterColumnLeftPosition } from './AgGridUtils';
11
+ import GridEditionManager from './GridEditionManager';
11
12
  export default class AgGridController {
12
13
  configFilterColumn(filterColumn) {
13
14
  this._filterColumn = filterColumn;
@@ -43,6 +44,9 @@ export default class AgGridController {
43
44
  getGridConfig() {
44
45
  return this._gridConfig;
45
46
  }
47
+ getGridApi() {
48
+ return this._gridOptions.api;
49
+ }
46
50
  getSort() {
47
51
  const sortedColumns = [];
48
52
  this._gridOptions.columnApi
@@ -103,6 +107,7 @@ export default class AgGridController {
103
107
  this._doubleClickCallBack = options.onDoubleClick;
104
108
  this._multipleSelection = options.allowMultipleSelection;
105
109
  this._dataUnit = options.dataUnit;
110
+ this._editionManager = new GridEditionManager(this._dataUnit, options.useEnterLikeTab, options.recordsValidator, options.editionIsDisabled);
106
111
  this._statusResolver = options.statusResolver;
107
112
  if (this._dataUnit) {
108
113
  this._dataUnit.sortingProvider = this;
@@ -122,12 +127,14 @@ export default class AgGridController {
122
127
  defaultColDef: {
123
128
  headerClass: 'ez-grid__cell-header',
124
129
  cellClass: 'ez-grid__cell-body',
130
+ cellStyle: {
131
+ height: '100%'
132
+ }
125
133
  },
126
- components: {
127
- ezGridHeaderComponent: SelectionHeader,
128
- ezGridCustomHeader: EzGridCustomHeader,
129
- },
134
+ components: Object.assign({ ezGridHeaderComponent: SelectionHeader, ezGridCustomHeader: EzGridCustomHeader }, this._editionManager.getComponents()),
130
135
  context: {
136
+ editionManager: this._editionManager,
137
+ dataUnit: this._dataUnit,
131
138
  headerCheckStatusGetter: () => this.getSelectionHeaderStatus(),
132
139
  headerCheckStatusSetter: (selectAll) => this.updateSelectionForAll(selectAll),
133
140
  },
@@ -135,6 +142,7 @@ export default class AgGridController {
135
142
  this.defineRowModelType(this._gridOptions, options);
136
143
  this.setOptionsEvents(this._gridOptions);
137
144
  this.setOptionsSupress(this._gridOptions);
145
+ this._gridOptions = this._editionManager.configureGrid(this._gridOptions);
138
146
  if (this._enterprise) {
139
147
  this._grid = new EnterpriseGrid(container, this._gridOptions);
140
148
  }
@@ -281,6 +289,7 @@ export default class AgGridController {
281
289
  opt.onSelectionChanged = e => this.onSelectionChange(e);
282
290
  opt.onRowDoubleClicked = evt => this.onRowDoubleClick(evt);
283
291
  opt.onDragStopped = evt => this.onCallStateChange('columnMovedEnd', evt);
292
+ opt.onCellClicked = evt => this.onCellClicked(evt);
284
293
  }
285
294
  setOptionsSupress(opt) {
286
295
  opt.suppressDragLeaveHidesColumns = true;
@@ -584,7 +593,7 @@ export default class AgGridController {
584
593
  else if (propSortable === false) {
585
594
  tooltip = 'Coluna não pode ser ordenada';
586
595
  }
587
- return {
596
+ return this._editionManager.configureColumn({
588
597
  headerName: source.label,
589
598
  field: source.name,
590
599
  sortable: propSortable,
@@ -594,13 +603,22 @@ export default class AgGridController {
594
603
  tooltip: tooltip,
595
604
  isSortable: propSortable,
596
605
  hasFilter: () => this.hasFilterColumn(source.name),
597
- showColumnFilter: (leftPosition) => this.showFilterColumn({ columnName: source.name, columnLabel: source.label, leftPosition, filteredOptions: this._filteredColumns.get(source.name) }),
606
+ showColumnFilter: (leftPosition, fromIcon) => this.showFilterColumn({ columnName: source.name, columnLabel: source.label, leftPosition, filteredOptions: this._filteredColumns.get(source.name), fromIcon }),
598
607
  },
599
608
  valueFormatter: params => {
609
+ if (params.value == undefined) {
610
+ return "";
611
+ }
612
+ if (params.value instanceof Promise) {
613
+ return "Carregando...";
614
+ }
615
+ if (this._dataUnit) {
616
+ return this._dataUnit.getFormattedValue(source.name, params.value);
617
+ }
600
618
  return this.getFormatterByColumn(params, source);
601
619
  },
602
620
  cellStyle: this.getStyleByColumn(source),
603
- };
621
+ });
604
622
  }
605
623
  getInitCellStyle() {
606
624
  return {
@@ -673,6 +691,13 @@ export default class AgGridController {
673
691
  return params.value.toLocaleDateString();
674
692
  }
675
693
  }
694
+ if ((source === null || source === void 0 ? void 0 : source.userInterface) === UserInterface.ELAPSEDTIME || (source === null || source === void 0 ? void 0 : source.userInterface) === UserInterface.TIME) {
695
+ if (!!params.value) {
696
+ const maskFormatter = new MaskFormatter("##:##");
697
+ const formattedValue = String(params.value).padStart(4, '0');
698
+ return maskFormatter.format(formattedValue);
699
+ }
700
+ }
676
701
  }
677
702
  onCallStateChange(type, e) {
678
703
  const finished = !('finished' in e) || e['finished'];
@@ -687,6 +712,13 @@ export default class AgGridController {
687
712
  this._columnStateChangeCallback(type, this.getColumnsState(), info);
688
713
  }
689
714
  }
715
+ onCellClicked(event) {
716
+ this._editionManager.verifyClickToEdition(event.api, {
717
+ rowIndex: event.rowIndex,
718
+ column: event.column,
719
+ rowPinned: undefined
720
+ });
721
+ }
690
722
  isElementResize(e) {
691
723
  return e['target'] && e['target'].getAttribute('ref') === 'eResize';
692
724
  }
@@ -704,6 +736,7 @@ export default class AgGridController {
704
736
  if (this._selectionChangeCallback) {
705
737
  clearTimeout(this._selectionChangeDeboucing);
706
738
  this._selectionChangeDeboucing = window.setTimeout(() => {
739
+ this._editionManager.proceedAutoSave();
707
740
  if (this._dataUnit) {
708
741
  if (event.context.selectionChangeQuietly) {
709
742
  const selectionInfo = this._dataUnit;
@@ -23,6 +23,7 @@ export default class DataSource {
23
23
  case Action.DATA_SAVED:
24
24
  case Action.EDITION_CANCELED:
25
25
  case Action.DATA_CHANGED:
26
+ case Action.DATA_RESOLVED:
26
27
  this._controller.refresh();
27
28
  break;
28
29
  case Action.SELECTION_CHANGED:
@@ -0,0 +1,230 @@
1
+ import { UserInterface } from "@sankhyalabs/core";
2
+ import { KeyCode } from "ag-grid-community";
3
+ import { RecordValidationProcessor } from "../../../../utils/validators/recordvalidator/RecordValidationProcessor";
4
+ import EzCellEditor from "./editor/EzCellEditor";
5
+ export default class GridEditionManager {
6
+ constructor(dataUnit, useEnterLikeTab, recordsValidator, editionIsDisabled) {
7
+ this._dataUnit = dataUnit;
8
+ this._recordValidationProcessor = new RecordValidationProcessor(this._dataUnit, {
9
+ getRequiredFields: () => this.getRequiredFields(),
10
+ markAsInvalid: () => { },
11
+ getMessageForField: () => null
12
+ }, recordsValidator);
13
+ this._useEnterLikeTab = useEnterLikeTab;
14
+ this._editionIsDisabled = editionIsDisabled;
15
+ }
16
+ configureGrid(options) {
17
+ this._gridOptions = options;
18
+ options.readOnlyEdit = true;
19
+ options.onCellEditRequest = evt => this.onCellEditRequest(evt);
20
+ options.onCellKeyDown = evt => {
21
+ if (evt.event && evt["column"]) {
22
+ this.onCellKeyDown(evt);
23
+ }
24
+ };
25
+ return options;
26
+ }
27
+ proceedAutoSave() {
28
+ if (!this._dataUnit.isDirty()) {
29
+ this.saveSuccess();
30
+ return;
31
+ }
32
+ if (!this._isGridEdition) {
33
+ return;
34
+ }
35
+ const currentRercord = this._dataUnit.getSelectedRecord();
36
+ if (currentRercord == undefined) {
37
+ return;
38
+ }
39
+ this._recordValidationProcessor
40
+ .validate()
41
+ .then(() => {
42
+ this._dataUnit.saveData()
43
+ .then(() => this.saveSuccess())
44
+ .catch(reason => this.saveFail(reason));
45
+ })
46
+ .catch(reason => this.saveFail(reason));
47
+ }
48
+ navigateByEnterKey(keyboardEvent) {
49
+ const backwards = keyboardEvent.shiftKey;
50
+ if (this._useEnterLikeTab) {
51
+ if (backwards) {
52
+ this._gridOptions.api.tabToPreviousCell(keyboardEvent);
53
+ }
54
+ else {
55
+ this._gridOptions.api.tabToNextCell(keyboardEvent);
56
+ }
57
+ }
58
+ else {
59
+ const editionCell = this._gridOptions.api.getEditingCells()[0];
60
+ if (editionCell) {
61
+ let { rowIndex } = editionCell;
62
+ this.nextEditionRow(rowIndex, editionCell.column, backwards);
63
+ }
64
+ }
65
+ }
66
+ getComponents() {
67
+ return { ezCellEditor: EzCellEditor };
68
+ }
69
+ verifyClickToEdition(api, cellClicked) {
70
+ if (this.isSecondClick(cellClicked)) {
71
+ api.startEditingCell({ rowIndex: cellClicked.rowIndex, colKey: cellClicked.column.getColId() });
72
+ }
73
+ this._lastCellClicked = cellClicked;
74
+ }
75
+ configureColumn(col) {
76
+ col.cellEditor = 'ezCellEditor';
77
+ col.editable = params => this.canEdit(params);
78
+ col.suppressKeyboardEvent = (params) => {
79
+ return params.event.key === KeyCode.ENTER;
80
+ };
81
+ return col;
82
+ }
83
+ getRequiredFields() {
84
+ return this._gridOptions.columnApi.getAllDisplayedColumns().filter(c => {
85
+ const fieldDefinition = this._dataUnit.getField(c.getColId());
86
+ return fieldDefinition && fieldDefinition.required;
87
+ }).map(c => c.getColId());
88
+ }
89
+ saveSuccess() {
90
+ this.focusOnCell(this._targetEditionCell);
91
+ this._lastCellEdited = undefined;
92
+ this._targetEditionCell = undefined;
93
+ this._isGridEdition = false;
94
+ }
95
+ saveFail(reason) {
96
+ this.focusOnCell(this._lastCellEdited);
97
+ this._isGridEdition = false;
98
+ if (reason) {
99
+ Promise.reject(reason);
100
+ }
101
+ }
102
+ focusOnCell(cell) {
103
+ if (cell == undefined) {
104
+ return;
105
+ }
106
+ const { rowIndex, column } = cell;
107
+ this._gridOptions.api.getDisplayedRowAtIndex(rowIndex).setSelected(true, true);
108
+ this._gridOptions.api.clearRangeSelection();
109
+ this._gridOptions.api.addCellRange({ rowStartIndex: rowIndex, rowEndIndex: rowIndex, columns: [column] });
110
+ this._gridOptions.api.startEditingCell({ colKey: column.getColId(), rowIndex });
111
+ this._gridOptions.api.setFocusedCell(rowIndex, column.getColId());
112
+ const cellEditor = this._gridOptions.api.getCellEditorInstances()[0];
113
+ if (cellEditor) {
114
+ cellEditor.focusIn();
115
+ }
116
+ }
117
+ onCellKeyDown(event) {
118
+ const keyboardEvent = event.event;
119
+ switch (keyboardEvent.key) {
120
+ case KeyCode.ENTER:
121
+ this.processEnterKey(keyboardEvent, event);
122
+ break;
123
+ case KeyCode.UP:
124
+ this.editPreviousRow(event.api);
125
+ break;
126
+ case KeyCode.DOWN:
127
+ this.editNextRow(event.api);
128
+ break;
129
+ }
130
+ }
131
+ processEnterKey(keyboardEvent, event) {
132
+ const editionCell = event.api.getEditingCells()[0];
133
+ if (!editionCell) {
134
+ event.api.startEditingCell({ colKey: event.column.getColId(), rowIndex: event.rowIndex });
135
+ return;
136
+ }
137
+ this.navigateByEnterKey(keyboardEvent);
138
+ }
139
+ nextEditionRow(rowIndex, column, backwards) {
140
+ if (backwards) {
141
+ rowIndex = rowIndex - 1;
142
+ if (rowIndex < 0) {
143
+ rowIndex = this._dataUnit.records.length - 1;
144
+ }
145
+ }
146
+ else {
147
+ rowIndex = rowIndex + 1;
148
+ if (rowIndex >= this._dataUnit.records.length) {
149
+ rowIndex = 0;
150
+ }
151
+ }
152
+ this._targetEditionCell = new TargetEdition(rowIndex, column, true);
153
+ this.finishEdition();
154
+ }
155
+ editPreviousRow(api) {
156
+ this.moveEditionVertically(api, -1);
157
+ }
158
+ editNextRow(api) {
159
+ this.moveEditionVertically(api, 1);
160
+ }
161
+ moveEditionVertically(api, offset) {
162
+ const editionCell = api.getEditingCells()[0];
163
+ if (!editionCell) {
164
+ return;
165
+ }
166
+ const rowIndex = editionCell.rowIndex + offset;
167
+ if (api.getDisplayedRowAtIndex(rowIndex)) {
168
+ this._targetEditionCell = new TargetEdition(rowIndex, editionCell.column, offset < 0);
169
+ this.finishEdition();
170
+ }
171
+ }
172
+ finishEdition() {
173
+ this._gridOptions.api.stopEditing();
174
+ setTimeout(() => {
175
+ //O Timeout foi inserido para permitir que o ciclo de finalização prossiga
176
+ //pois precisamos aguardar o fim da edição para executar o autosave.
177
+ this.proceedAutoSave();
178
+ }, 0);
179
+ }
180
+ canEdit(params) {
181
+ if (this._editionIsDisabled()) {
182
+ return false;
183
+ }
184
+ return this.isColEditable(params.colDef.field);
185
+ }
186
+ isColEditable(fieldName) {
187
+ const fieldDefinition = this._dataUnit.getField(fieldName);
188
+ if (fieldDefinition) {
189
+ return !fieldDefinition.readOnly;
190
+ }
191
+ return false;
192
+ }
193
+ isSecondClick(cellClicked) {
194
+ if (!this._lastCellClicked) {
195
+ return false;
196
+ }
197
+ if (this._lastCellClicked.column != cellClicked.column) {
198
+ return false;
199
+ }
200
+ if (this._lastCellClicked.rowIndex != cellClicked.rowIndex) {
201
+ return false;
202
+ }
203
+ return true;
204
+ }
205
+ onCellEditRequest(event) {
206
+ const fieldName = event.colDef.field;
207
+ const value = event.newValue;
208
+ if (event.oldValue != value) {
209
+ if (value instanceof Promise) {
210
+ const fieldDescriptor = this._dataUnit.getField(event.colDef.colId);
211
+ event.node.setData(Object.assign(Object.assign({}, event.data), { [fieldName]: (fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.userInterface) === UserInterface.SEARCH ? value : event.oldValue }));
212
+ value.then(resolved => event.node.setData(Object.assign(Object.assign({}, event.data), { [fieldName]: resolved })));
213
+ }
214
+ else {
215
+ event.node.setData(Object.assign(Object.assign({}, event.data), { [fieldName]: value }));
216
+ }
217
+ this._isGridEdition = true;
218
+ this._dataUnit.setFieldValue(fieldName, value, [event.data.__record__id__]);
219
+ this._lastCellEdited = { rowIndex: event.rowIndex, column: event.column, rowPinned: undefined };
220
+ }
221
+ }
222
+ }
223
+ class TargetEdition {
224
+ constructor(rowIndex, column, backwards) {
225
+ this.rowPinned = null;
226
+ this.rowIndex = rowIndex;
227
+ this.column = column;
228
+ this.backwards = backwards;
229
+ }
230
+ }
@@ -36,7 +36,7 @@ export class EzGridCustomHeader {
36
36
  onClickFilter() {
37
37
  var _a;
38
38
  const iconLeft = (_a = this.filterButton) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().left;
39
- this.params.showColumnFilter(`${calcFilterColumnLeftPosition(iconLeft)}px`);
39
+ this.params.showColumnFilter(`${calcFilterColumnLeftPosition(iconLeft)}px`, true);
40
40
  }
41
41
  configSortIcon() {
42
42
  this.sortDownIcon.style.display = this.params.column.isSortDescending() ? 'flex' : 'none';