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