@sankhyalabs/ezui 4.0.4 → 4.2.0

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 (46) hide show
  1. package/dist/cjs/{constants-5a75e2f3.js → constants-5d588e38.js} +2 -0
  2. package/dist/cjs/ez-check.cjs.entry.js +12 -1
  3. package/dist/cjs/ez-combo-box.cjs.entry.js +1 -1
  4. package/dist/cjs/ez-form-view.cjs.entry.js +1 -1
  5. package/dist/cjs/ez-form.cjs.entry.js +64 -36
  6. package/dist/cjs/ez-grid.cjs.entry.js +331 -72
  7. package/dist/cjs/ezui.cjs.js +1 -1
  8. package/dist/cjs/loader.cjs.js +1 -1
  9. package/dist/collection/components/ez-check/ez-check.js +14 -1
  10. package/dist/collection/components/ez-grid/controller/DataUnitBridge.js +16 -1
  11. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +72 -15
  12. package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +9 -1
  13. package/dist/collection/components/ez-grid/ez-grid.css +52 -7
  14. package/dist/collection/components/ez-grid/ez-grid.js +226 -57
  15. package/dist/collection/components/ez-grid/subcomponents/selection-counter.js +23 -0
  16. package/dist/collection/utils/constants.js +1 -0
  17. package/dist/collection/utils/form/DataBinder.js +47 -30
  18. package/dist/collection/utils/form/FormMetadata.js +17 -6
  19. package/dist/custom-elements/index.js +409 -111
  20. package/dist/esm/constants-76d2e931.js +4 -0
  21. package/dist/esm/ez-check.entry.js +12 -1
  22. package/dist/esm/ez-combo-box.entry.js +1 -1
  23. package/dist/esm/ez-form-view.entry.js +1 -1
  24. package/dist/esm/ez-form.entry.js +64 -36
  25. package/dist/esm/ez-grid.entry.js +333 -74
  26. package/dist/esm/ezui.js +1 -1
  27. package/dist/esm/loader.js +1 -1
  28. package/dist/ezui/ezui.esm.js +1 -1
  29. package/dist/ezui/p-1f841f3c.entry.js +1 -0
  30. package/dist/ezui/{p-dc15b6d1.entry.js → p-8105c967.entry.js} +2 -2
  31. package/dist/ezui/{p-50883460.entry.js → p-878646a0.entry.js} +1 -1
  32. package/dist/ezui/p-a3ce3710.entry.js +1 -0
  33. package/dist/ezui/p-b01e3085.js +1 -0
  34. package/dist/ezui/{p-e748b5d3.entry.js → p-b7ea9791.entry.js} +1 -1
  35. package/dist/types/components/ez-check/ez-check.d.ts +1 -0
  36. package/dist/types/components/ez-grid/controller/EzGridController.d.ts +10 -2
  37. package/dist/types/components/ez-grid/controller/ag-grid/AgGridController.d.ts +5 -2
  38. package/dist/types/components/ez-grid/ez-grid.d.ts +32 -11
  39. package/dist/types/components/ez-grid/subcomponents/selection-counter.d.ts +13 -0
  40. package/dist/types/utils/constants.d.ts +1 -0
  41. package/dist/types/utils/form/DataBinder.d.ts +3 -2
  42. package/package.json +1 -1
  43. package/dist/esm/constants-ca136201.js +0 -3
  44. package/dist/ezui/p-08f4a048.entry.js +0 -1
  45. package/dist/ezui/p-3f4ae3a3.js +0 -1
  46. package/dist/ezui/p-a323b415.entry.js +0 -1
@@ -1,11 +1,18 @@
1
- import { ElementIDUtils } from "@sankhyalabs/core";
1
+ import { ElementIDUtils, JSUtils } from "@sankhyalabs/core";
2
2
  import { h, Host } from "@stencil/core";
3
3
  import AgGridController from "./controller/ag-grid/AgGridController";
4
+ import { SelectionCounter } from "./subcomponents/selection-counter";
5
+ import { ALL_RECORD } from "../../utils/constants";
4
6
  export class EzGrid {
5
7
  constructor() {
6
8
  this._gridController = new AgGridController(false);
9
+ this._debounceTimer = 500;
10
+ this._selectionAll = false;
7
11
  this._paginationInfo = undefined;
8
12
  this._paginationChangedByKeyboard = true;
13
+ this._showSelectionCounter = false;
14
+ this._selectionCount = 0;
15
+ this._selectionPageCount = 0;
9
16
  this.multipleSelection = undefined;
10
17
  this.config = undefined;
11
18
  this.serverUrl = undefined;
@@ -60,10 +67,185 @@ export class EzGrid {
60
67
  async quickFilter(term) {
61
68
  this._gridController.quickFilter(term);
62
69
  }
70
+ observeConfig(config) {
71
+ this._gridController.setColumnsState(config.columns);
72
+ }
63
73
  onSelectionChange(evt) {
64
- if (this.dataUnit) {
65
- this.dataUnit.setSelection(evt.detail.selection.map((r) => r.__record__id__));
74
+ const { selection } = evt === null || evt === void 0 ? void 0 : evt.detail;
75
+ if (selection == undefined || this.dataUnit == undefined) {
76
+ return;
77
+ }
78
+ if (this.isAllRecordSetted()) {
79
+ this.updateSelectionPage(selection);
80
+ return;
81
+ }
82
+ this.setSelection(selection);
83
+ }
84
+ updateSelectionPage(selection) {
85
+ if (this._selectionAll) {
86
+ this._selectionAll = false;
87
+ }
88
+ else {
89
+ this.dataUnit.clearSelection()
90
+ .then(() => {
91
+ const records = this.dataUnit.records;
92
+ const selectionPage = selection.filter((selectedRecord) => {
93
+ return records.some((record) => {
94
+ return record.__record__id__ === selectedRecord.__record__id__;
95
+ });
96
+ });
97
+ this._gridController.selectRows(selectionPage);
98
+ });
99
+ }
100
+ }
101
+ isAllRecordSetted() {
102
+ var _a;
103
+ const allSelection = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getAllSelection();
104
+ return allSelection === null || allSelection === void 0 ? void 0 : allSelection.some((selectedRecord) => {
105
+ return selectedRecord.__record__id__ === ALL_RECORD;
106
+ });
107
+ }
108
+ setSelection(selection) {
109
+ if ((selection === null || selection === void 0 ? void 0 : selection.length) > 0) {
110
+ this.dataUnit.setSelection(selection)
111
+ .then(this.controlSelectionCounter.bind(this));
112
+ }
113
+ else {
114
+ this.dataUnit.clearSelection()
115
+ .then(this.controlSelectionCounter.bind(this));
116
+ }
117
+ }
118
+ setAutoSelectAll() {
119
+ var _a, _b, _c, _d;
120
+ const { total } = (_a = this._paginationInfo) !== null && _a !== void 0 ? _a : {};
121
+ if (total == undefined) {
122
+ return;
123
+ }
124
+ this._selectionCount = total;
125
+ this._selectionAll = true;
126
+ this._showSelectionCounter = true;
127
+ (_b = this._gridController) === null || _b === void 0 ? void 0 : _b.selectRows((_d = (_c = this.dataUnit) === null || _c === void 0 ? void 0 : _c.records) !== null && _d !== void 0 ? _d : []);
128
+ }
129
+ controlSelectionCounter() {
130
+ var _a, _b;
131
+ const allSelection = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getAllSelection();
132
+ const counter = (_b = allSelection === null || allSelection === void 0 ? void 0 : allSelection.length) !== null && _b !== void 0 ? _b : 0;
133
+ if (this.isAllRecordSetted()) {
134
+ this.setAutoSelectAll();
135
+ return;
136
+ }
137
+ if (!this.multipleSelection || !this.isPaginationActived()) {
138
+ this._showSelectionCounter = false;
139
+ setTimeout(this.setSelectionCount.bind(this), this._debounceTimer);
140
+ return;
141
+ }
142
+ if (counter > 1) {
143
+ setTimeout(() => {
144
+ this.setSelectionCount(counter);
145
+ this._showSelectionCounter = true;
146
+ }, this._debounceTimer);
147
+ }
148
+ else {
149
+ this._showSelectionCounter = false;
150
+ setTimeout(this.setSelectionCount.bind(this, counter), this._debounceTimer);
151
+ }
152
+ }
153
+ setSelectionCount(value = 0) {
154
+ var _a, _b;
155
+ this._selectionCount = value;
156
+ const selectPageRecords = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getSelectedRecords();
157
+ this._selectionPageCount = (_b = selectPageRecords === null || selectPageRecords === void 0 ? void 0 : selectPageRecords.length) !== null && _b !== void 0 ? _b : 0;
158
+ }
159
+ isPaginationActived() {
160
+ var _a;
161
+ const { total, lastRecord, firstRecord } = (_a = this._paginationInfo) !== null && _a !== void 0 ? _a : {};
162
+ if (total == undefined || lastRecord == undefined || firstRecord == undefined) {
163
+ return false;
164
+ }
165
+ return Math.ceil(total / (lastRecord - firstRecord + 1)) > 1;
166
+ }
167
+ onSelectAllRecords() {
168
+ const allRecord = {
169
+ __record__id__: ALL_RECORD,
170
+ filter: this.dataUnit.getFilters(),
171
+ sort: this.dataUnit.getSort()
172
+ };
173
+ this.setSelection([allRecord]);
174
+ }
175
+ onSelectPageRecords() {
176
+ var _a;
177
+ (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.clearSelection().then(() => {
178
+ var _a, _b, _c;
179
+ (_a = this._gridController) === null || _a === void 0 ? void 0 : _a.selectRows((_c = (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.records) !== null && _c !== void 0 ? _c : []);
180
+ });
181
+ }
182
+ onClearSelectedRecords() {
183
+ var _a;
184
+ (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.clearSelection();
185
+ }
186
+ createConfigFromState(state) {
187
+ let newConfig = { columns: [] };
188
+ state.forEach(columnState => {
189
+ if (!columnState.hidden) {
190
+ let newConfigColumn = { name: columnState.name };
191
+ if (columnState.width) {
192
+ newConfigColumn['width'] = columnState.width;
193
+ }
194
+ if (columnState.sort) {
195
+ newConfigColumn['ascending'] = (columnState.sort.toUpperCase() === 'ASC');
196
+ newConfigColumn['orderIndex'] = columnState.sortIndex;
197
+ }
198
+ else {
199
+ newConfigColumn['orderIndex'] = 0;
200
+ }
201
+ if (newConfigColumn) {
202
+ newConfig.columns.push(newConfigColumn);
203
+ }
204
+ }
205
+ });
206
+ return newConfig;
207
+ }
208
+ positionSelectionCounter() {
209
+ var _a;
210
+ if (this._gridSelectionCounter == undefined) {
211
+ return;
212
+ }
213
+ if (this._showSelectionCounter) {
214
+ const boundingContainer = (_a = this._container) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
215
+ if (boundingContainer == undefined) {
216
+ return;
217
+ }
218
+ const limitBottom = boundingContainer.bottom - 30;
219
+ this._gridSelectionCounter.style.bottom = (document.body.clientHeight - limitBottom) + 'px';
220
+ }
221
+ else {
222
+ this._gridSelectionCounter.style.bottom = "";
223
+ }
224
+ }
225
+ setEvents() {
226
+ window.removeEventListener("scroll", this.positionSelectionCounter.bind(this));
227
+ window.addEventListener("scroll", this.positionSelectionCounter.bind(this));
228
+ }
229
+ resizeSelectionCounter() {
230
+ if (this._gridSelectionCounter == undefined) {
231
+ return;
232
+ }
233
+ this._gridSelectionCounter.style.width = "";
234
+ if (this._gridSelectionCounter.clientHeight > 42) {
235
+ this._gridSelectionCounter.style.width = "min-content";
66
236
  }
237
+ this.positionSelectionCounter();
238
+ }
239
+ configSelectionCounter() {
240
+ if (this._element == undefined) {
241
+ return;
242
+ }
243
+ if (this._resizeObserver != undefined) {
244
+ this._resizeObserver.unobserve(this._element);
245
+ }
246
+ this._resizeObserver = new ResizeObserver(JSUtils.debounce(this.resizeSelectionCounter.bind(this), 200));
247
+ this._resizeObserver.observe(this._element);
248
+ this.resizeSelectionCounter();
67
249
  }
68
250
  onColumnStateChange(type, state, info) {
69
251
  var _a;
@@ -106,56 +288,6 @@ export class EzGrid {
106
288
  }
107
289
  }
108
290
  }
109
- createConfigFromState(state) {
110
- let newConfig = { columns: [] };
111
- state.forEach(columnState => {
112
- if (!columnState.hidden) {
113
- let newConfigColumn = { name: columnState.name };
114
- if (columnState.width) {
115
- newConfigColumn['width'] = columnState.width;
116
- }
117
- if (columnState.sort) {
118
- newConfigColumn['ascending'] = (columnState.sort.toUpperCase() === 'ASC');
119
- newConfigColumn['orderIndex'] = columnState.sortIndex;
120
- }
121
- else {
122
- newConfigColumn['orderIndex'] = 0;
123
- }
124
- if (newConfigColumn) {
125
- newConfig.columns.push(newConfigColumn);
126
- }
127
- }
128
- });
129
- return newConfig;
130
- }
131
- componentDidLoad() {
132
- this._gridController.initDatagrid(this._container, {
133
- onColumnStateChange: (type, state, info) => this.onColumnStateChange(type, state, info),
134
- onSelectionChange: (selection) => this.ezSelectionChange.emit(selection),
135
- onPaginationChange: (paginationInfo) => {
136
- var _a;
137
- if (((_a = this._paginationInfo) === null || _a === void 0 ? void 0 : _a.currentPage) > (paginationInfo === null || paginationInfo === void 0 ? void 0 : paginationInfo.currentPage) && this._paginationChangedByKeyboard) {
138
- this._gridController.setFocusLastRow();
139
- }
140
- else {
141
- this._gridController.setFocusFirstRow();
142
- this._paginationChangedByKeyboard = true;
143
- }
144
- this._paginationInfo = paginationInfo;
145
- },
146
- onDoubleClick: (row) => {
147
- this.ezDoubleClick.emit(row);
148
- },
149
- allowMultipleSelection: this.multipleSelection,
150
- serverURL: this.serverUrl,
151
- dataUnit: this.dataUnit,
152
- statusResolver: this.statusResolver
153
- });
154
- if (this.config) {
155
- this.observeConfig(this.config);
156
- }
157
- this.buildDataElementId();
158
- }
159
291
  buildDataElementId() {
160
292
  const dataInfo = { dataUnit: this.dataUnit };
161
293
  ElementIDUtils.addIDInfo(this._element, null, dataInfo);
@@ -185,11 +317,45 @@ export class EzGrid {
185
317
  }
186
318
  return null;
187
319
  }
188
- observeConfig(config) {
189
- this._gridController.setColumnsState(config.columns);
320
+ componentDidLoad() {
321
+ this._gridController.initDatagrid(this._container, {
322
+ onColumnStateChange: (type, state, info) => this.onColumnStateChange(type, state, info),
323
+ onSelectionChange: (selection) => this.ezSelectionChange.emit(selection),
324
+ onPaginationChange: (paginationInfo) => {
325
+ var _a;
326
+ if (((_a = this._paginationInfo) === null || _a === void 0 ? void 0 : _a.currentPage) > (paginationInfo === null || paginationInfo === void 0 ? void 0 : paginationInfo.currentPage) && this._paginationChangedByKeyboard) {
327
+ this._gridController.setFocusLastRow();
328
+ }
329
+ else {
330
+ this._gridController.setFocusFirstRow();
331
+ this._paginationChangedByKeyboard = true;
332
+ }
333
+ this._paginationInfo = paginationInfo;
334
+ this._gridController.updateCheckbox();
335
+ this.controlSelectionCounter();
336
+ },
337
+ onDoubleClick: (row) => {
338
+ this.ezDoubleClick.emit(row);
339
+ },
340
+ allowMultipleSelection: this.multipleSelection,
341
+ serverURL: this.serverUrl,
342
+ dataUnit: this.dataUnit,
343
+ statusResolver: this.statusResolver
344
+ });
345
+ if (this.config) {
346
+ this.observeConfig(this.config);
347
+ }
348
+ this.buildDataElementId();
349
+ this.setEvents();
350
+ }
351
+ componentWillRender() {
352
+ this.configSelectionCounter();
190
353
  }
191
354
  render() {
192
- return (h(Host, null, h("div", { class: "ez-box ez-box--shadow ez-padding--medium grid-header" }, h("div", { class: "grid-header__container" }, h("slot", { name: "leftButtons" })), h("div", { class: "grid-header__container", ref: ref => this._refPaginationControl = ref }, this.getPaginationControl())), h("div", { class: "grid__container ez-grid", ref: elem => this._container = elem }), h("div", { class: "grid__footer" })));
355
+ var _a, _b, _c;
356
+ return (h(Host, null, h("div", { class: "ez-box ez-box--shadow ez-padding--medium grid-header" }, h("div", { class: "grid-header__container" }, h("slot", { name: "leftButtons" })), h("div", { class: "grid-header__container", ref: ref => this._refPaginationControl = ref }, this.getPaginationControl())), h("div", { ref: (ref) => this._gridSelectionCounter = ref, class: `grid__selection-counter
357
+ ${this._showSelectionCounter ? "grid__selection-counter--opened" : ""}
358
+ ` }, h(SelectionCounter, { selectionCount: this._selectionCount, selectionPageCount: this._selectionPageCount, total: (_a = this._paginationInfo) === null || _a === void 0 ? void 0 : _a.total, recordsLength: (_c = (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.records) === null || _c === void 0 ? void 0 : _c.length, onSelectAll: this.onSelectAllRecords.bind(this), onSelectPage: this.onSelectPageRecords.bind(this), onClearAll: this.onClearSelectedRecords.bind(this), onClose: () => this._showSelectionCounter = false })), h("div", { class: "grid__container ez-grid", ref: elem => this._container = elem }), h("div", { class: "grid__footer" })));
193
359
  }
194
360
  static get is() { return "ez-grid"; }
195
361
  static get encapsulation() { return "scoped"; }
@@ -305,7 +471,10 @@ export class EzGrid {
305
471
  static get states() {
306
472
  return {
307
473
  "_paginationInfo": {},
308
- "_paginationChangedByKeyboard": {}
474
+ "_paginationChangedByKeyboard": {},
475
+ "_showSelectionCounter": {},
476
+ "_selectionCount": {},
477
+ "_selectionPageCount": {}
309
478
  };
310
479
  }
311
480
  static get events() {
@@ -0,0 +1,23 @@
1
+ import { ElementIDUtils } from "@sankhyalabs/core";
2
+ import { h } from "@stencil/core";
3
+ export const SelectionCounter = (props) => {
4
+ const { selectionCount, selectionPageCount, total, recordsLength, onSelectAll, onSelectPage, onClearAll, onClose } = props;
5
+ const pageSelectedRecords = selectionPageCount === recordsLength;
6
+ const allSelectedRecords = selectionCount === total;
7
+ return (h("div", Object.assign({ class: "ez-box ez-box--shadow-small" }, getElementID("ezGridSelectionCounter")), h("div", { class: "ez-flex ez-flex--align-items-center ez-size-width--full ez-padding-horizontal--medium" }, h("div", { class: "ez-flex ez-flex--wrap ez-flex--align-items-baseline ez-flex--justify-center" }, h("label", Object.assign({ innerHTML: getText(selectionCount, allSelectedRecords), class: "ez-text ez-text--primary ez-text--medium ez-margin-right--medium ez-margin-top--medium" }, getElementID("ezGridSelectionCounter_label"))), h("div", { class: "ez-flex ez-margin-right--medium" }, (pageSelectedRecords || allSelectedRecords) &&
8
+ h("ez-button", Object.assign({ class: "ez-margin-right--medium", label: `Selecionar ${allSelectedRecords ? "apenas a página atual" : `todos os ${total} registros`}`, mode: "link", onClick: allSelectedRecords ? onSelectPage : onSelectAll }, getElementID(`ezGridSelectionCounter_select${allSelectedRecords ? "Page" : "All"}`))), h("ez-button", Object.assign({ class: "grid__btn-clear", label: "Limpar", mode: "link", onClick: onClearAll }, getElementID("ezGridSelectionCounter_clearAll"))))), h("button", Object.assign({ class: "grid__btn-close", title: "Fechar", onClick: onClose }, getElementID("ezGridSelectionCounter_close")), h("ez-icon", { iconName: "close" })))));
9
+ };
10
+ function getText(selectionCount, allSelectedRecords) {
11
+ if (allSelectedRecords) {
12
+ return `Todos os <strong>${selectionCount} registros</strong> da grade estão selecionados.`;
13
+ }
14
+ else {
15
+ const pluralChar = selectionCount > 1 ? "s" : "";
16
+ return `Há <strong>${selectionCount} registro${pluralChar}</strong> selecionado${pluralChar}.`;
17
+ }
18
+ }
19
+ function getElementID(sufix) {
20
+ return {
21
+ [ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: ElementIDUtils.getInternalIDInfo(sufix)
22
+ };
23
+ }
@@ -1 +1,2 @@
1
1
  export const REQUIRED_INFO = " (obrigatório) *";
2
+ export const ALL_RECORD = "ALL_RECORD";
@@ -2,9 +2,8 @@ import { ApplicationContext, Action, WaitingChangeException, DataUnitAction } fr
2
2
  import ApplicationUtils from "../ApplicationUtils";
3
3
  export default class DataBinder {
4
4
  constructor(dataUnit) {
5
- this._invalidFields = new Map();
6
5
  this.onDataUnitEvent = (action) => {
7
- var _a;
6
+ var _a, _b;
8
7
  switch (action.type) {
9
8
  case Action.DATA_LOADED:
10
9
  case Action.DATA_SAVED:
@@ -13,6 +12,7 @@ export default class DataBinder {
13
12
  case Action.RECORDS_COPIED:
14
13
  case Action.EDITION_CANCELED:
15
14
  case Action.SELECTION_CHANGED:
15
+ case Action.SELECTION_REMOVED:
16
16
  case Action.NEXT_SELECTED:
17
17
  case Action.PREVIOUS_SELECTED:
18
18
  this.clearInvalid();
@@ -24,13 +24,30 @@ export default class DataBinder {
24
24
  this.updateValue(field.fieldName, field.field);
25
25
  });
26
26
  break;
27
+ case Action.FIELD_INVALIDATED:
28
+ (_b = this._fields) === null || _b === void 0 ? void 0 : _b.forEach(field => {
29
+ this.updateErrorMessage(field.fieldName, field.field);
30
+ });
31
+ break;
27
32
  }
28
33
  };
29
34
  this._fields = new Map();
30
35
  this._dataUnit = dataUnit;
36
+ this.applyDefaultValues();
31
37
  this._dataUnit.subscribe(this.onDataUnitEvent);
32
38
  this._dataUnit.addInterceptor(this);
33
39
  }
40
+ applyDefaultValues() {
41
+ const recordIds = (this._dataUnit.getAddedRecords() || []).map(r => r.__record__id__);
42
+ if (recordIds.length > 0) {
43
+ const defaultValues = this.getDefaultValues();
44
+ if (defaultValues) {
45
+ Object.keys(defaultValues).forEach(field => {
46
+ this._dataUnit.setFieldValue(field, defaultValues[field], recordIds);
47
+ });
48
+ }
49
+ }
50
+ }
34
51
  bind(fields, currentContextName, formMetadata, recordsValidator) {
35
52
  fields.forEach(fieldElement => {
36
53
  const { fieldName, contextName } = fieldElement.dataset;
@@ -45,17 +62,19 @@ export default class DataBinder {
45
62
  this._dataUnit.unsubscribe(this.onDataUnitEvent);
46
63
  this._dataUnit.removeInterceptor(this);
47
64
  }
65
+ getCurrentRecordId() {
66
+ const record = this._dataUnit.getSelectedRecord();
67
+ return record === null || record === void 0 ? void 0 : record.__record__id__;
68
+ }
48
69
  markInvalid(field) {
49
- this._invalidFields.set(field.name, field);
70
+ this._dataUnit.setInvalidField(field.name, field.message, this.getCurrentRecordId());
50
71
  if (this._fields.has(field.name)) {
51
72
  const fieldElement = this._fields.get(field.name).field;
52
- if (!fieldElement["errorMessage"]) {
53
- this.updateErrorMessage(field.name, fieldElement);
54
- }
73
+ this.updateErrorMessage(field.name, fieldElement, field.message);
55
74
  }
56
75
  }
57
- clearInvalid() {
58
- this._invalidFields.clear();
76
+ clearInvalid(recordId) {
77
+ this._dataUnit.clearInvalid(recordId);
59
78
  this._fields.forEach(fieldBinder => {
60
79
  const fieldElement = fieldBinder.field;
61
80
  fieldElement["errorMessage"] = "";
@@ -137,16 +156,18 @@ export default class DataBinder {
137
156
  }
138
157
  });
139
158
  }
140
- updateErrorMessage(fieldName, field) {
141
- const invalidField = this._invalidFields.get(fieldName);
142
- if (invalidField) {
143
- field["errorMessage"] = invalidField.message;
159
+ updateErrorMessage(fieldName, field, message) {
160
+ if (message == undefined) {
161
+ message = this._dataUnit.getInvalidMessage(this.getCurrentRecordId(), fieldName);
162
+ }
163
+ if (!field["errorMessage"]) {
164
+ field["errorMessage"] = message;
144
165
  }
145
166
  }
146
167
  getErrorMessage(fieldName) {
147
168
  if (this._fields.has(fieldName)) {
148
169
  const fieldElement = this._fields.get(fieldName).field;
149
- return fieldElement["errorMessage"] || null;
170
+ return fieldElement["errorMessage"];
150
171
  }
151
172
  return undefined;
152
173
  }
@@ -197,7 +218,7 @@ export default class DataBinder {
197
218
  if (this._dataUnit.records.length === 0) {
198
219
  this._dataUnit.addRecord();
199
220
  }
200
- this._invalidFields.delete(fieldName);
221
+ this._dataUnit.clearInvalid(this.getCurrentRecordId(), fieldName);
201
222
  this._dataUnit.setFieldValue(fieldName, newValue);
202
223
  if (this._dataUnit.waitingForChange(fieldName)) {
203
224
  const bind = this._fields.get(fieldName);
@@ -230,7 +251,6 @@ export default class DataBinder {
230
251
  }
231
252
  }
232
253
  interceptAction(action) {
233
- var _a;
234
254
  if (action.type === Action.RECORDS_COPIED) {
235
255
  const cleanFields = this._formMetadata.getCleanOnCopyFields();
236
256
  if (cleanFields) {
@@ -250,30 +270,27 @@ export default class DataBinder {
250
270
  });
251
271
  }
252
272
  if (action.type === Action.RECORDS_ADDED) {
253
- const defaultValues = (_a = this._formMetadata) === null || _a === void 0 ? void 0 : _a.getDefaultValues();
273
+ const defaultValues = this.getDefaultValues();
254
274
  if (defaultValues) {
255
275
  const records = action.payload;
256
276
  return new DataUnitAction(Action.RECORDS_ADDED, records.map(record => {
257
- const newRecord = Object.assign({}, record);
258
- for (const field in defaultValues) {
259
- const defaultValue = this.getFormattedValue(defaultValues[field]);
260
- const recordValue = typeof defaultValue === "function" ? defaultValue() : defaultValue;
261
- newRecord[field] = this._dataUnit.valueFromString(field, recordValue);
262
- }
263
- return newRecord;
277
+ return Object.assign(Object.assign({}, record), defaultValues);
264
278
  }));
265
279
  }
266
280
  }
267
281
  return action;
268
282
  }
269
- getFormattedValue(defaultValue) {
270
- if (defaultValue == undefined || typeof defaultValue !== "object") {
271
- return defaultValue;
272
- }
273
- if ("formattedValue" in defaultValue) {
274
- return defaultValue.formattedValue;
283
+ getDefaultValues() {
284
+ var _a;
285
+ const rawDefaultValues = (_a = this._formMetadata) === null || _a === void 0 ? void 0 : _a.getDefaultValues();
286
+ if (rawDefaultValues) {
287
+ const defaultValues = {};
288
+ for (const field in rawDefaultValues) {
289
+ defaultValues[field] = this._dataUnit.valueFromString(field, rawDefaultValues[field]);
290
+ }
291
+ return defaultValues;
275
292
  }
276
- return defaultValue.value;
293
+ return undefined;
277
294
  }
278
295
  }
279
296
  class Bind {
@@ -111,12 +111,23 @@ export const buildFormMetadata = (config, dataUnit, includeDetails = false) => {
111
111
  }
112
112
  let defaultValue = field.defaultValue == undefined ? (_c = descriptor.properties) === null || _c === void 0 ? void 0 : _c.defaultValue : field.defaultValue;
113
113
  if (defaultValue) {
114
- if ((typeof defaultValue === "object") && defaultValue["type"] === "V") {
115
- // Atualmente a configuração do formulário eventualmente deposita um objeto
116
- // prototipado como {type: "V", value: "${nome.de.variavel}"} para campos com
117
- // valor padrão do tipo variável. Dessa forma precisamos "desenvelopar" o valor
118
- // para que a variável chegue corretamente a seu destino.
119
- defaultValue = defaultValue["value"];
114
+ const { type, value } = defaultValue;
115
+ if (type) {
116
+ if (type === "V") {
117
+ defaultValue = value;
118
+ }
119
+ else {
120
+ try {
121
+ const parsed = JSON.parse(value);
122
+ if (parsed && "value" in parsed) {
123
+ defaultValue = parsed;
124
+ }
125
+ else {
126
+ defaultValue = value;
127
+ }
128
+ }
129
+ catch (_d) { }
130
+ }
120
131
  }
121
132
  defaultValues[field.name] = defaultValue;
122
133
  }