@sankhyalabs/ezui 1.1.8 → 1.1.9

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-9a4a35ca.js} +415 -371
  3. package/dist/cjs/ez-action-chip.cjs.entry.js +41 -41
  4. package/dist/cjs/ez-button_14.cjs.entry.js +1911 -1911
  5. package/dist/cjs/ez-label-chip.cjs.entry.js +120 -120
  6. package/dist/cjs/ez-modal.cjs.entry.js +104 -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 +368 -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 +251 -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 +224 -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 +3125 -3081
  64. package/dist/esm/{DataUnit-69e518fa.js → DataUnit-d5d4c9a3.js} +415 -371
  65. package/dist/esm/ez-action-chip.entry.js +41 -41
  66. package/dist/esm/ez-button_14.entry.js +1911 -1911
  67. package/dist/esm/ez-label-chip.entry.js +120 -120
  68. package/dist/esm/ez-modal.entry.js +104 -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-b0974f4f.entry.js → p-0fcdfb51.entry.js} +1 -1
  79. package/dist/ezui/p-dac7a6c2.js +1 -0
  80. package/dist/ezui/{p-db11c600.entry.js → p-dbef7060.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 +26 -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 +60 -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,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 = [];
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 = [];
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
+ }