@sankhyalabs/ezui 1.1.11 → 1.1.12

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 (140) hide show
  1. package/README.md +72 -72
  2. package/dist/cjs/{DataUnit-74f074a7.js → DataUnit-79f69df9.js} +421 -421
  3. package/dist/cjs/ez-action-chip.cjs.entry.js +41 -41
  4. package/dist/cjs/ez-button_14.cjs.entry.js +1943 -1934
  5. package/dist/cjs/ez-label-chip.cjs.entry.js +120 -120
  6. package/dist/cjs/ez-modal.cjs.entry.js +102 -102
  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 +400 -391
  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 +257 -257
  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 +222 -222
  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 +3161 -3152
  64. package/dist/esm/{DataUnit-ab1a3a4d.js → DataUnit-bce6b190.js} +421 -421
  65. package/dist/esm/ez-action-chip.entry.js +41 -41
  66. package/dist/esm/ez-button_14.entry.js +1943 -1934
  67. package/dist/esm/ez-label-chip.entry.js +120 -120
  68. package/dist/esm/ez-modal.entry.js +102 -102
  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-b02e731e.entry.js → p-039054b7.entry.js} +1 -1
  79. package/dist/ezui/{p-9f97450c.js → p-10ac6d78.js} +0 -0
  80. package/dist/ezui/{p-83f1d308.entry.js → p-419c9a35.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 +27 -27
  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 +61 -61
  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/react/components.d.ts +0 -22
  115. package/react/components.js +0 -25
  116. package/react/components.js.map +0 -1
  117. package/react/react-component-lib/createComponent.d.ts +0 -10
  118. package/react/react-component-lib/createComponent.js +0 -59
  119. package/react/react-component-lib/createComponent.js.map +0 -1
  120. package/react/react-component-lib/createOverlayComponent.d.ts +0 -20
  121. package/react/react-component-lib/createOverlayComponent.js +0 -89
  122. package/react/react-component-lib/createOverlayComponent.js.map +0 -1
  123. package/react/react-component-lib/index.d.ts +0 -2
  124. package/react/react-component-lib/index.js +0 -3
  125. package/react/react-component-lib/index.js.map +0 -1
  126. package/react/react-component-lib/interfaces.d.ts +0 -29
  127. package/react/react-component-lib/interfaces.js +0 -1
  128. package/react/react-component-lib/interfaces.js.map +0 -1
  129. package/react/react-component-lib/utils/attachProps.d.ts +0 -12
  130. package/react/react-component-lib/utils/attachProps.js +0 -96
  131. package/react/react-component-lib/utils/attachProps.js.map +0 -1
  132. package/react/react-component-lib/utils/case.d.ts +0 -2
  133. package/react/react-component-lib/utils/case.js +0 -7
  134. package/react/react-component-lib/utils/case.js.map +0 -1
  135. package/react/react-component-lib/utils/dev.d.ts +0 -2
  136. package/react/react-component-lib/utils/dev.js +0 -13
  137. package/react/react-component-lib/utils/dev.js.map +0 -1
  138. package/react/react-component-lib/utils/index.d.ts +0 -7
  139. package/react/react-component-lib/utils/index.js +0 -21
  140. package/react/react-component-lib/utils/index.js.map +0 -1
@@ -1,391 +1,400 @@
1
- import { Component, h, Element, forceUpdate, Prop, Method } from '@stencil/core';
2
- import { createStore, applyMiddleware, combineReducers } from 'redux';
3
- import thunk from 'redux-thunk';
4
- import { formLoad, invalidField, showHideNavigationButtons } from './store/Form.actions';
5
- import undoable from 'redux-undo';
6
- import formReducer, { formNonHistoricReducer } from './store/Form.reducer';
7
- import { FormSheet } from './subcomponents/structure/FormSheet';
8
- import DataUnit from './subcomponents/DataUnit';
9
- export class EzForm {
10
- constructor() {
11
- this._dataUnits = new Map();
12
- this._duSources = new Map();
13
- this._requiredFieldsByDU = {};
14
- }
15
- async validate() {
16
- for (let i = 0; i < this._duSources.size; i++) {
17
- const duName = Array.from(this._duSources.keys())[i];
18
- let du = this._dataUnits.get(duName);
19
- if (du === undefined) {
20
- const source = this._duSources.get(duName);
21
- du = this.buildDataUnit(source, source.parentDUName);
22
- }
23
- if (!du.validateRecords()) {
24
- return false;
25
- }
26
- }
27
- return true;
28
- }
29
- async getChanges() {
30
- debugger;
31
- let allChanges = [];
32
- for (let i = 0; i < this._dataUnits.size; i++) {
33
- const du = Array.from(this._dataUnits.values())[i];
34
- //Só devemos buscar as alterações de DU raiz, pois os sub DUs serão enviados junto.
35
- if (!du.parentDU) {
36
- const duChanges = du.getChangesToSave();
37
- if (duChanges) {
38
- allChanges = allChanges.concat(duChanges);
39
- }
40
- }
41
- }
42
- return allChanges;
43
- }
44
- validateRecords(dataUnit, records) {
45
- const result = { isValid: true, message: '' };
46
- const reqFields = this._requiredFieldsByDU[dataUnit.name];
47
- const recordValidator = record => {
48
- reqFields.forEach(field => {
49
- const recordIndex = record["record__index"];
50
- const fieldName = field.name;
51
- const fieldValue = record[fieldName];
52
- if (fieldValue === null || fieldValue === undefined || fieldValue === '') {
53
- this._store.dispatch(invalidField(field.tabControler, field.tabIndex, dataUnit.name, recordIndex, record.record__id, field.name, "Essa informação é obrigatória"));
54
- result.isValid = false;
55
- result.message = "Há pelo menos um campo obrigatório não preenchido.";
56
- }
57
- });
58
- };
59
- if (dataUnit.records.length == 0) {
60
- recordValidator({});
61
- }
62
- else {
63
- records.forEach(recordValidator);
64
- }
65
- return result;
66
- }
67
- componentWillRender() {
68
- if (this._store === undefined) {
69
- const rootReducer = combineReducers({
70
- "hist": undoable(formReducer),
71
- "nonhist": formNonHistoricReducer
72
- });
73
- this._store = createStore(rootReducer, applyMiddleware(thunk));
74
- this._store.subscribe(() => { forceUpdate(this); });
75
- if (this.slavemode) {
76
- this._store.dispatch(showHideNavigationButtons("saveVisible", false));
77
- this._store.dispatch(showHideNavigationButtons("cancelVisible", false));
78
- this._store.dispatch(showHideNavigationButtons("reloadVisible", false));
79
- }
80
- }
81
- }
82
- loadMDFromExecutor(callBack) {
83
- const loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
84
- if (loadMetadataFunction) {
85
- const result = loadMetadataFunction();
86
- if (result) {
87
- if (result instanceof Promise) {
88
- result.then(md => {
89
- callBack(md);
90
- });
91
- }
92
- else {
93
- callBack(result);
94
- }
95
- }
96
- }
97
- }
98
- loadMDFromElement(callBack) {
99
- const metadata = [];
100
- Array.from(this._host.children).forEach(elem => {
101
- if (elem.tagName === "FORM-METADATA") {
102
- const formMetadata = elem;
103
- metadata.push(formMetadata.metadata);
104
- }
105
- });
106
- callBack(metadata.length > 0 ? metadata : null);
107
- }
108
- updateMetadata(metadata) {
109
- if (metadata) {
110
- const processFields = (duName, form, tabController, tabIndex) => {
111
- var _a;
112
- let requiredFields = this._requiredFieldsByDU[duName];
113
- if (requiredFields === undefined) {
114
- requiredFields = [];
115
- this._requiredFieldsByDU[duName] = requiredFields;
116
- }
117
- form.items.forEach(item => {
118
- if ("fields" in item) {
119
- const fSet = item;
120
- fSet.fields.forEach(f => {
121
- f.tabControler = tabController;
122
- f.tabIndex = tabIndex;
123
- if (f.required) {
124
- requiredFields.push(f);
125
- }
126
- });
127
- }
128
- else {
129
- const f = item;
130
- f.tabControler = tabController;
131
- f.tabIndex = tabIndex;
132
- if (f.required) {
133
- requiredFields.push(f);
134
- }
135
- }
136
- });
137
- (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
138
- const subDu = subForm.dataUnit;
139
- if (subDu) {
140
- this._duSources.set(subDu.name, subDu);
141
- subDu.parentDUName = duName;
142
- }
143
- processFields(subDu ? subDu.name : duName, subForm, form.name, index);
144
- });
145
- };
146
- this.metadata = metadata;
147
- metadata.map((form, index) => {
148
- const du = form.dataUnit;
149
- const duName = du.name;
150
- this._duSources.set(duName, du);
151
- processFields(duName, form, "__MAIN__FORM__", index);
152
- });
153
- this._store.dispatch(formLoad());
154
- }
155
- }
156
- parseExecutor(executor) {
157
- if (executor) {
158
- return executor instanceof Function ? executor : eval(executor);
159
- }
160
- return null;
161
- }
162
- componentDidLoad() {
163
- if (this.metadata) {
164
- this.updateMetadata(this.metadata);
165
- }
166
- else {
167
- this.loadMDFromElement((md) => this.updateMetadata(md));
168
- if (!this.metadata) {
169
- this.loadMDFromExecutor((md) => this.updateMetadata(md));
170
- }
171
- }
172
- }
173
- buildDataUnit(dataUnit, parentDataUnit) {
174
- if (dataUnit) {
175
- const { name, unitLabel, records, cardinality } = dataUnit;
176
- if (!(dataUnit instanceof DataUnit)) {
177
- let parent;
178
- if (parentDataUnit instanceof DataUnit) {
179
- parent = parentDataUnit;
180
- }
181
- else {
182
- parent = this._dataUnits.get(parentDataUnit);
183
- }
184
- dataUnit = new DataUnit(name, unitLabel, cardinality, parent);
185
- this._dataUnits.set(dataUnit.name, dataUnit);
186
- if (records) {
187
- dataUnit.records = records;
188
- }
189
- dataUnit.store = this._store;
190
- dataUnit.loadExecutor = this.parseExecutor(this.loadexecutor);
191
- dataUnit.saveExecutor = this.parseExecutor(this.saveexecutor);
192
- dataUnit.removeExecutor = this.parseExecutor(this.removeexecutor);
193
- dataUnit.recordsValidator = this;
194
- dataUnit.fieldSearchExecutor = this.parseExecutor(this.fieldsearchexecutor);
195
- }
196
- }
197
- return dataUnit;
198
- }
199
- render() {
200
- return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
201
- }
202
- static get is() { return "ez-form"; }
203
- static get originalStyleUrls() { return {
204
- "$": ["ez-form.css"]
205
- }; }
206
- static get styleUrls() { return {
207
- "$": ["ez-form.css"]
208
- }; }
209
- static get properties() { return {
210
- "metadataexecutor": {
211
- "type": "string",
212
- "mutable": false,
213
- "complexType": {
214
- "original": "string | Function",
215
- "resolved": "Function | string",
216
- "references": {
217
- "Function": {
218
- "location": "global"
219
- }
220
- }
221
- },
222
- "required": false,
223
- "optional": false,
224
- "docs": {
225
- "tags": [],
226
- "text": ""
227
- },
228
- "attribute": "metadataexecutor",
229
- "reflect": false
230
- },
231
- "loadexecutor": {
232
- "type": "string",
233
- "mutable": false,
234
- "complexType": {
235
- "original": "string | Function",
236
- "resolved": "Function | string",
237
- "references": {
238
- "Function": {
239
- "location": "global"
240
- }
241
- }
242
- },
243
- "required": false,
244
- "optional": false,
245
- "docs": {
246
- "tags": [],
247
- "text": ""
248
- },
249
- "attribute": "loadexecutor",
250
- "reflect": false
251
- },
252
- "saveexecutor": {
253
- "type": "string",
254
- "mutable": false,
255
- "complexType": {
256
- "original": "string | Function",
257
- "resolved": "Function | string",
258
- "references": {
259
- "Function": {
260
- "location": "global"
261
- }
262
- }
263
- },
264
- "required": false,
265
- "optional": false,
266
- "docs": {
267
- "tags": [],
268
- "text": ""
269
- },
270
- "attribute": "saveexecutor",
271
- "reflect": false
272
- },
273
- "removeexecutor": {
274
- "type": "string",
275
- "mutable": false,
276
- "complexType": {
277
- "original": "string | Function",
278
- "resolved": "Function | string",
279
- "references": {
280
- "Function": {
281
- "location": "global"
282
- }
283
- }
284
- },
285
- "required": false,
286
- "optional": false,
287
- "docs": {
288
- "tags": [],
289
- "text": ""
290
- },
291
- "attribute": "removeexecutor",
292
- "reflect": false
293
- },
294
- "fieldsearchexecutor": {
295
- "type": "string",
296
- "mutable": false,
297
- "complexType": {
298
- "original": "string | Function",
299
- "resolved": "Function | string",
300
- "references": {
301
- "Function": {
302
- "location": "global"
303
- }
304
- }
305
- },
306
- "required": false,
307
- "optional": false,
308
- "docs": {
309
- "tags": [],
310
- "text": ""
311
- },
312
- "attribute": "fieldsearchexecutor",
313
- "reflect": false
314
- },
315
- "metadata": {
316
- "type": "unknown",
317
- "mutable": true,
318
- "complexType": {
319
- "original": "Array<Form>",
320
- "resolved": "Form[]",
321
- "references": {
322
- "Array": {
323
- "location": "global"
324
- },
325
- "Form": {
326
- "location": "import",
327
- "path": "./subcomponents/FormMetadata"
328
- }
329
- }
330
- },
331
- "required": false,
332
- "optional": false,
333
- "docs": {
334
- "tags": [],
335
- "text": ""
336
- }
337
- },
338
- "slavemode": {
339
- "type": "boolean",
340
- "mutable": false,
341
- "complexType": {
342
- "original": "boolean",
343
- "resolved": "boolean",
344
- "references": {}
345
- },
346
- "required": false,
347
- "optional": false,
348
- "docs": {
349
- "tags": [],
350
- "text": ""
351
- },
352
- "attribute": "slavemode",
353
- "reflect": false
354
- }
355
- }; }
356
- static get methods() { return {
357
- "validate": {
358
- "complexType": {
359
- "signature": "() => Promise<boolean>",
360
- "parameters": [],
361
- "references": {
362
- "Promise": {
363
- "location": "global"
364
- }
365
- },
366
- "return": "Promise<boolean>"
367
- },
368
- "docs": {
369
- "text": "",
370
- "tags": []
371
- }
372
- },
373
- "getChanges": {
374
- "complexType": {
375
- "signature": "() => Promise<any[]>",
376
- "parameters": [],
377
- "references": {
378
- "Promise": {
379
- "location": "global"
380
- }
381
- },
382
- "return": "Promise<any[]>"
383
- },
384
- "docs": {
385
- "text": "",
386
- "tags": []
387
- }
388
- }
389
- }; }
390
- static get elementRef() { return "_host"; }
391
- }
1
+ import { Component, h, Element, forceUpdate, Prop, Method } from '@stencil/core';
2
+ import { createStore, applyMiddleware, combineReducers } from 'redux';
3
+ import thunk from 'redux-thunk';
4
+ import { formLoad, invalidField, showHideNavigationButtons } from './store/Form.actions';
5
+ import undoable from 'redux-undo';
6
+ import formReducer, { formNonHistoricReducer } from './store/Form.reducer';
7
+ import { FormSheet } from './subcomponents/structure/FormSheet';
8
+ import DataUnit from './subcomponents/DataUnit';
9
+ export class EzForm {
10
+ constructor() {
11
+ this._dataUnits = new Map();
12
+ this._duSources = new Map();
13
+ this._requiredFieldsByDU = {};
14
+ }
15
+ async validate() {
16
+ for (let i = 0; i < this._duSources.size; i++) {
17
+ const duName = Array.from(this._duSources.keys())[i];
18
+ let du = this._dataUnits.get(duName);
19
+ if (du === undefined) {
20
+ const source = this._duSources.get(duName);
21
+ du = this.buildDataUnit(source, source.parentDUName);
22
+ }
23
+ if (!du.validateRecords()) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }
29
+ async getChanges() {
30
+ debugger;
31
+ let allChanges = [];
32
+ for (let i = 0; i < this._dataUnits.size; i++) {
33
+ const du = Array.from(this._dataUnits.values())[i];
34
+ //Só devemos buscar as alterações de DU raiz, pois os sub DUs serão enviados junto.
35
+ if (!du.parentDU) {
36
+ const duChanges = du.getChangesToSave();
37
+ if (duChanges) {
38
+ allChanges = allChanges.concat(duChanges);
39
+ }
40
+ }
41
+ }
42
+ return allChanges;
43
+ }
44
+ validateRecords(dataUnit, records) {
45
+ const result = { isValid: true, message: '' };
46
+ const reqFields = this._requiredFieldsByDU[dataUnit.name];
47
+ const recordValidator = record => {
48
+ reqFields.forEach(field => {
49
+ const recordIndex = record["record__index"];
50
+ const fieldName = field.name;
51
+ const fieldValue = record[fieldName];
52
+ if (fieldValue === null || fieldValue === undefined || fieldValue === '') {
53
+ this._store.dispatch(invalidField(field.tabControler, field.tabIndex, dataUnit.name, recordIndex, record.record__id, field.name, "Essa informação é obrigatória"));
54
+ result.isValid = false;
55
+ result.message = "Há pelo menos um campo obrigatório não preenchido.";
56
+ }
57
+ });
58
+ };
59
+ if (dataUnit.records.length === 0) {
60
+ recordValidator({});
61
+ }
62
+ else {
63
+ let validatedRecords = {};
64
+ records.forEach(r => {
65
+ recordValidator(r);
66
+ validatedRecords[r.record__id] = true;
67
+ });
68
+ dataUnit.records.forEach(r => {
69
+ if (!validatedRecords[r.record__id]) {
70
+ recordValidator(r);
71
+ }
72
+ });
73
+ }
74
+ return result;
75
+ }
76
+ componentWillRender() {
77
+ if (this._store === undefined) {
78
+ const rootReducer = combineReducers({
79
+ "hist": undoable(formReducer),
80
+ "nonhist": formNonHistoricReducer
81
+ });
82
+ this._store = createStore(rootReducer, applyMiddleware(thunk));
83
+ this._store.subscribe(() => { forceUpdate(this); });
84
+ if (this.slavemode) {
85
+ this._store.dispatch(showHideNavigationButtons("saveVisible", false));
86
+ this._store.dispatch(showHideNavigationButtons("cancelVisible", false));
87
+ this._store.dispatch(showHideNavigationButtons("reloadVisible", false));
88
+ }
89
+ }
90
+ }
91
+ loadMDFromExecutor(callBack) {
92
+ const loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
93
+ if (loadMetadataFunction) {
94
+ const result = loadMetadataFunction();
95
+ if (result) {
96
+ if (result instanceof Promise) {
97
+ result.then(md => {
98
+ callBack(md);
99
+ });
100
+ }
101
+ else {
102
+ callBack(result);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ loadMDFromElement(callBack) {
108
+ const metadata = [];
109
+ Array.from(this._host.children).forEach(elem => {
110
+ if (elem.tagName === "FORM-METADATA") {
111
+ const formMetadata = elem;
112
+ metadata.push(formMetadata.metadata);
113
+ }
114
+ });
115
+ callBack(metadata.length > 0 ? metadata : null);
116
+ }
117
+ updateMetadata(metadata) {
118
+ if (metadata) {
119
+ const processFields = (duName, form, tabController, tabIndex) => {
120
+ var _a;
121
+ let requiredFields = this._requiredFieldsByDU[duName];
122
+ if (requiredFields === undefined) {
123
+ requiredFields = [];
124
+ this._requiredFieldsByDU[duName] = requiredFields;
125
+ }
126
+ form.items.forEach(item => {
127
+ if ("fields" in item) {
128
+ const fSet = item;
129
+ fSet.fields.forEach(f => {
130
+ f.tabControler = tabController;
131
+ f.tabIndex = tabIndex;
132
+ if (f.required) {
133
+ requiredFields.push(f);
134
+ }
135
+ });
136
+ }
137
+ else {
138
+ const f = item;
139
+ f.tabControler = tabController;
140
+ f.tabIndex = tabIndex;
141
+ if (f.required) {
142
+ requiredFields.push(f);
143
+ }
144
+ }
145
+ });
146
+ (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
147
+ const subDu = subForm.dataUnit;
148
+ if (subDu) {
149
+ this._duSources.set(subDu.name, subDu);
150
+ subDu.parentDUName = duName;
151
+ }
152
+ processFields(subDu ? subDu.name : duName, subForm, form.name, index);
153
+ });
154
+ };
155
+ this.metadata = metadata;
156
+ metadata.map((form, index) => {
157
+ const du = form.dataUnit;
158
+ const duName = du.name;
159
+ this._duSources.set(duName, du);
160
+ processFields(duName, form, "__MAIN__FORM__", index);
161
+ });
162
+ this._store.dispatch(formLoad());
163
+ }
164
+ }
165
+ parseExecutor(executor) {
166
+ if (executor) {
167
+ return executor instanceof Function ? executor : eval(executor);
168
+ }
169
+ return null;
170
+ }
171
+ componentDidLoad() {
172
+ if (this.metadata) {
173
+ this.updateMetadata(this.metadata);
174
+ }
175
+ else {
176
+ this.loadMDFromElement((md) => this.updateMetadata(md));
177
+ if (!this.metadata) {
178
+ this.loadMDFromExecutor((md) => this.updateMetadata(md));
179
+ }
180
+ }
181
+ }
182
+ buildDataUnit(dataUnit, parentDataUnit) {
183
+ if (dataUnit) {
184
+ const { name, unitLabel, records, cardinality } = dataUnit;
185
+ if (!(dataUnit instanceof DataUnit)) {
186
+ let parent;
187
+ if (parentDataUnit instanceof DataUnit) {
188
+ parent = parentDataUnit;
189
+ }
190
+ else {
191
+ parent = this._dataUnits.get(parentDataUnit);
192
+ }
193
+ dataUnit = new DataUnit(name, unitLabel, cardinality, parent);
194
+ this._dataUnits.set(dataUnit.name, dataUnit);
195
+ if (records) {
196
+ dataUnit.records = records;
197
+ }
198
+ dataUnit.store = this._store;
199
+ dataUnit.loadExecutor = this.parseExecutor(this.loadexecutor);
200
+ dataUnit.saveExecutor = this.parseExecutor(this.saveexecutor);
201
+ dataUnit.removeExecutor = this.parseExecutor(this.removeexecutor);
202
+ dataUnit.recordsValidator = this;
203
+ dataUnit.fieldSearchExecutor = this.parseExecutor(this.fieldsearchexecutor);
204
+ }
205
+ }
206
+ return dataUnit;
207
+ }
208
+ render() {
209
+ return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
210
+ }
211
+ static get is() { return "ez-form"; }
212
+ static get originalStyleUrls() { return {
213
+ "$": ["ez-form.css"]
214
+ }; }
215
+ static get styleUrls() { return {
216
+ "$": ["ez-form.css"]
217
+ }; }
218
+ static get properties() { return {
219
+ "metadataexecutor": {
220
+ "type": "string",
221
+ "mutable": false,
222
+ "complexType": {
223
+ "original": "string | Function",
224
+ "resolved": "Function | string",
225
+ "references": {
226
+ "Function": {
227
+ "location": "global"
228
+ }
229
+ }
230
+ },
231
+ "required": false,
232
+ "optional": false,
233
+ "docs": {
234
+ "tags": [],
235
+ "text": ""
236
+ },
237
+ "attribute": "metadataexecutor",
238
+ "reflect": false
239
+ },
240
+ "loadexecutor": {
241
+ "type": "string",
242
+ "mutable": false,
243
+ "complexType": {
244
+ "original": "string | Function",
245
+ "resolved": "Function | string",
246
+ "references": {
247
+ "Function": {
248
+ "location": "global"
249
+ }
250
+ }
251
+ },
252
+ "required": false,
253
+ "optional": false,
254
+ "docs": {
255
+ "tags": [],
256
+ "text": ""
257
+ },
258
+ "attribute": "loadexecutor",
259
+ "reflect": false
260
+ },
261
+ "saveexecutor": {
262
+ "type": "string",
263
+ "mutable": false,
264
+ "complexType": {
265
+ "original": "string | Function",
266
+ "resolved": "Function | string",
267
+ "references": {
268
+ "Function": {
269
+ "location": "global"
270
+ }
271
+ }
272
+ },
273
+ "required": false,
274
+ "optional": false,
275
+ "docs": {
276
+ "tags": [],
277
+ "text": ""
278
+ },
279
+ "attribute": "saveexecutor",
280
+ "reflect": false
281
+ },
282
+ "removeexecutor": {
283
+ "type": "string",
284
+ "mutable": false,
285
+ "complexType": {
286
+ "original": "string | Function",
287
+ "resolved": "Function | string",
288
+ "references": {
289
+ "Function": {
290
+ "location": "global"
291
+ }
292
+ }
293
+ },
294
+ "required": false,
295
+ "optional": false,
296
+ "docs": {
297
+ "tags": [],
298
+ "text": ""
299
+ },
300
+ "attribute": "removeexecutor",
301
+ "reflect": false
302
+ },
303
+ "fieldsearchexecutor": {
304
+ "type": "string",
305
+ "mutable": false,
306
+ "complexType": {
307
+ "original": "string | Function",
308
+ "resolved": "Function | string",
309
+ "references": {
310
+ "Function": {
311
+ "location": "global"
312
+ }
313
+ }
314
+ },
315
+ "required": false,
316
+ "optional": false,
317
+ "docs": {
318
+ "tags": [],
319
+ "text": ""
320
+ },
321
+ "attribute": "fieldsearchexecutor",
322
+ "reflect": false
323
+ },
324
+ "metadata": {
325
+ "type": "unknown",
326
+ "mutable": true,
327
+ "complexType": {
328
+ "original": "Array<Form>",
329
+ "resolved": "Form[]",
330
+ "references": {
331
+ "Array": {
332
+ "location": "global"
333
+ },
334
+ "Form": {
335
+ "location": "import",
336
+ "path": "./subcomponents/FormMetadata"
337
+ }
338
+ }
339
+ },
340
+ "required": false,
341
+ "optional": false,
342
+ "docs": {
343
+ "tags": [],
344
+ "text": ""
345
+ }
346
+ },
347
+ "slavemode": {
348
+ "type": "boolean",
349
+ "mutable": false,
350
+ "complexType": {
351
+ "original": "boolean",
352
+ "resolved": "boolean",
353
+ "references": {}
354
+ },
355
+ "required": false,
356
+ "optional": false,
357
+ "docs": {
358
+ "tags": [],
359
+ "text": ""
360
+ },
361
+ "attribute": "slavemode",
362
+ "reflect": false
363
+ }
364
+ }; }
365
+ static get methods() { return {
366
+ "validate": {
367
+ "complexType": {
368
+ "signature": "() => Promise<boolean>",
369
+ "parameters": [],
370
+ "references": {
371
+ "Promise": {
372
+ "location": "global"
373
+ }
374
+ },
375
+ "return": "Promise<boolean>"
376
+ },
377
+ "docs": {
378
+ "text": "",
379
+ "tags": []
380
+ }
381
+ },
382
+ "getChanges": {
383
+ "complexType": {
384
+ "signature": "() => Promise<any[]>",
385
+ "parameters": [],
386
+ "references": {
387
+ "Promise": {
388
+ "location": "global"
389
+ }
390
+ },
391
+ "return": "Promise<any[]>"
392
+ },
393
+ "docs": {
394
+ "text": "",
395
+ "tags": []
396
+ }
397
+ }
398
+ }; }
399
+ static get elementRef() { return "_host"; }
400
+ }