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