@sankhyalabs/ezui 1.1.6 → 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 (149) hide show
  1. package/README.md +72 -72
  2. package/dist/cjs/{DataUnit-09a6e7be.js → DataUnit-95368a67.js} +418 -361
  3. package/dist/cjs/ez-action-chip.cjs.entry.js +41 -41
  4. package/dist/cjs/ez-button_14.cjs.entry.js +1933 -1847
  5. package/dist/cjs/ez-label-chip.cjs.entry.js +120 -120
  6. package/dist/cjs/ez-modal.cjs.entry.js +102 -95
  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/ezui.cjs.js +1 -1
  10. package/dist/cjs/form-metadata.cjs.entry.js +65 -65
  11. package/dist/cjs/loader.cjs.js +1 -1
  12. package/dist/collection/components/ez-action-chip/ez-action-chip.css +82 -82
  13. package/dist/collection/components/ez-action-chip/ez-action-chip.js +109 -109
  14. package/dist/collection/components/ez-button/ez-button.css +94 -94
  15. package/dist/collection/components/ez-button/ez-button.js +125 -125
  16. package/dist/collection/components/ez-calendar/ez-calendar.css +210 -210
  17. package/dist/collection/components/ez-calendar/ez-calendar.js +215 -215
  18. package/dist/collection/components/ez-check/ez-check.css +265 -265
  19. package/dist/collection/components/ez-check/ez-check.js +168 -168
  20. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.css +67 -67
  21. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.js +108 -108
  22. package/dist/collection/components/ez-combo-box/ez-combo-box-interfaces.js +2 -2
  23. package/dist/collection/components/ez-combo-box/ez-combo-box.css +167 -167
  24. package/dist/collection/components/ez-combo-box/ez-combo-box.js +363 -363
  25. package/dist/collection/components/ez-date-input/ez-date-input.css +38 -38
  26. package/dist/collection/components/ez-date-input/ez-date-input.js +172 -172
  27. package/dist/collection/components/ez-form/ez-form.css +19 -19
  28. package/dist/collection/components/ez-form/ez-form.js +390 -289
  29. package/dist/collection/components/ez-form/store/Form.actions.js +132 -123
  30. package/dist/collection/components/ez-form/store/Form.reducer.js +194 -174
  31. package/dist/collection/components/ez-form/store/Form.selectors.js +44 -43
  32. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +252 -207
  33. package/dist/collection/components/ez-form/subcomponents/FormMetadata.js +16 -16
  34. package/dist/collection/components/ez-form/subcomponents/css/place-holder.css +23 -23
  35. package/dist/collection/components/ez-form/subcomponents/form-metadata.js +173 -173
  36. package/dist/collection/components/ez-form/subcomponents/place-holder.js +14 -14
  37. package/dist/collection/components/ez-form/subcomponents/structure/Field.js +71 -71
  38. package/dist/collection/components/ez-form/subcomponents/structure/FieldSet.js +27 -27
  39. package/dist/collection/components/ez-form/subcomponents/structure/FormSheet.js +40 -33
  40. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +27 -18
  41. package/dist/collection/components/ez-icon/ez-icon.css +36 -36
  42. package/dist/collection/components/ez-icon/ez-icon.js +56 -56
  43. package/dist/collection/components/ez-label-chip/ez-label-chip.css +117 -117
  44. package/dist/collection/components/ez-label-chip/ez-label-chip.js +276 -276
  45. package/dist/collection/components/ez-modal/ez-modal.css +86 -86
  46. package/dist/collection/components/ez-modal/ez-modal.js +222 -200
  47. package/dist/collection/components/ez-number-input/ez-number-input.css +144 -144
  48. package/dist/collection/components/ez-number-input/ez-number-input.js +465 -465
  49. package/dist/collection/components/ez-popover/ez-popover.css +38 -38
  50. package/dist/collection/components/ez-popover/ez-popover.js +323 -323
  51. package/dist/collection/components/ez-search/ez-search.css +295 -295
  52. package/dist/collection/components/ez-search/ez-search.js +527 -527
  53. package/dist/collection/components/ez-tabselector/ez-tabselector.css +125 -125
  54. package/dist/collection/components/ez-tabselector/ez-tabselector.js +283 -283
  55. package/dist/collection/components/ez-text-area/ez-text-area.css +139 -139
  56. package/dist/collection/components/ez-text-area/ez-text-area.js +267 -267
  57. package/dist/collection/components/ez-text-input/ez-text-input.css +169 -169
  58. package/dist/collection/components/ez-text-input/ez-text-input.js +395 -395
  59. package/dist/collection/components/ez-time-input/ez-time-input.css +155 -155
  60. package/dist/collection/components/ez-time-input/ez-time-input.js +326 -326
  61. package/dist/collection/index.js +1 -1
  62. package/dist/collection/servidor.js +100 -100
  63. package/dist/collection/utils/FloatingManager.js +15 -15
  64. package/dist/collection/utils/utils.js +6 -6
  65. package/dist/custom-elements/index.js +3146 -2998
  66. package/dist/esm/{DataUnit-7a983910.js → DataUnit-4bb6a396.js} +417 -362
  67. package/dist/esm/ez-action-chip.entry.js +41 -41
  68. package/dist/esm/ez-button_14.entry.js +1933 -1847
  69. package/dist/esm/ez-label-chip.entry.js +120 -120
  70. package/dist/esm/ez-modal.entry.js +103 -96
  71. package/dist/esm/ez-number-input.entry.js +236 -236
  72. package/dist/esm/ez-time-input.entry.js +168 -168
  73. package/dist/esm/ezui.js +1 -1
  74. package/dist/esm/form-metadata.entry.js +65 -65
  75. package/dist/esm/loader.js +1 -1
  76. package/dist/esm/polyfills/core-js.js +0 -0
  77. package/dist/esm/polyfills/dom.js +0 -0
  78. package/dist/esm/polyfills/es5-html-element.js +0 -0
  79. package/dist/esm/polyfills/index.js +0 -0
  80. package/dist/esm/polyfills/system.js +0 -0
  81. package/dist/ezui/ezui.esm.js +1 -1
  82. package/dist/ezui/p-11d20338.js +1 -0
  83. package/dist/ezui/{p-3c3a43aa.entry.js → p-5d30e51c.entry.js} +1 -1
  84. package/dist/ezui/p-77fdb4fd.entry.js +1 -0
  85. package/dist/ezui/p-e056fb23.entry.js +1 -0
  86. package/dist/types/components/ez-action-chip/ez-action-chip.d.ts +16 -16
  87. package/dist/types/components/ez-button/ez-button.d.ts +20 -20
  88. package/dist/types/components/ez-calendar/ez-calendar.d.ts +42 -42
  89. package/dist/types/components/ez-check/ez-check.d.ts +32 -32
  90. package/dist/types/components/ez-collapsable-box/ez-collapsable-box.d.ts +18 -18
  91. package/dist/types/components/ez-combo-box/ez-combo-box-interfaces.d.ts +4 -4
  92. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +68 -68
  93. package/dist/types/components/ez-date-input/ez-date-input.d.ts +31 -31
  94. package/dist/types/components/ez-form/ez-form.d.ts +27 -27
  95. package/dist/types/components/ez-form/store/Form.actions.d.ts +111 -104
  96. package/dist/types/components/ez-form/store/Form.reducer.d.ts +20 -11
  97. package/dist/types/components/ez-form/store/Form.selectors.d.ts +14 -13
  98. package/dist/types/components/ez-form/subcomponents/DataUnit.d.ts +61 -48
  99. package/dist/types/components/ez-form/subcomponents/FormMetadata.d.ts +41 -41
  100. package/dist/types/components/ez-form/subcomponents/form-metadata.d.ts +15 -15
  101. package/dist/types/components/ez-form/subcomponents/place-holder.d.ts +3 -3
  102. package/dist/types/components/ez-form/subcomponents/structure/Field.d.ts +10 -10
  103. package/dist/types/components/ez-form/subcomponents/structure/FieldSet.d.ts +12 -12
  104. package/dist/types/components/ez-form/subcomponents/structure/FormSheet.d.ts +13 -13
  105. package/dist/types/components/ez-form/subcomponents/structure/NavigationBar.d.ts +17 -7
  106. package/dist/types/components/ez-icon/ez-icon.d.ts +5 -5
  107. package/dist/types/components/ez-label-chip/ez-label-chip.d.ts +40 -40
  108. package/dist/types/components/ez-modal/ez-modal.d.ts +32 -26
  109. package/dist/types/components/ez-number-input/ez-number-input.d.ts +73 -73
  110. package/dist/types/components/ez-popover/ez-popover.d.ts +52 -52
  111. package/dist/types/components/ez-search/ez-search.d.ts +95 -95
  112. package/dist/types/components/ez-tabselector/ez-tabselector.d.ts +31 -31
  113. package/dist/types/components/ez-text-area/ez-text-area.d.ts +49 -49
  114. package/dist/types/components/ez-text-input/ez-text-input.d.ts +64 -64
  115. package/dist/types/components/ez-time-input/ez-time-input.d.ts +53 -53
  116. package/dist/types/components.d.ts +8 -0
  117. package/dist/types/index.d.ts +1 -1
  118. package/dist/types/utils/utils.d.ts +2 -2
  119. package/package.json +114 -114
  120. package/react/components.d.ts +22 -0
  121. package/react/components.js +25 -0
  122. package/react/components.js.map +1 -0
  123. package/react/react-component-lib/createComponent.d.ts +10 -0
  124. package/react/react-component-lib/createComponent.js +59 -0
  125. package/react/react-component-lib/createComponent.js.map +1 -0
  126. package/react/react-component-lib/createOverlayComponent.d.ts +20 -0
  127. package/react/react-component-lib/createOverlayComponent.js +89 -0
  128. package/react/react-component-lib/createOverlayComponent.js.map +1 -0
  129. package/react/react-component-lib/index.d.ts +2 -0
  130. package/react/react-component-lib/index.js +3 -0
  131. package/react/react-component-lib/index.js.map +1 -0
  132. package/react/react-component-lib/interfaces.d.ts +29 -0
  133. package/react/react-component-lib/interfaces.js +1 -0
  134. package/react/react-component-lib/interfaces.js.map +1 -0
  135. package/react/react-component-lib/utils/attachProps.d.ts +12 -0
  136. package/react/react-component-lib/utils/attachProps.js +96 -0
  137. package/react/react-component-lib/utils/attachProps.js.map +1 -0
  138. package/react/react-component-lib/utils/case.d.ts +2 -0
  139. package/react/react-component-lib/utils/case.js +7 -0
  140. package/react/react-component-lib/utils/case.js.map +1 -0
  141. package/react/react-component-lib/utils/dev.d.ts +2 -0
  142. package/react/react-component-lib/utils/dev.js +13 -0
  143. package/react/react-component-lib/utils/dev.js.map +1 -0
  144. package/react/react-component-lib/utils/index.d.ts +7 -0
  145. package/react/react-component-lib/utils/index.js +21 -0
  146. package/react/react-component-lib/utils/index.js.map +1 -0
  147. package/dist/ezui/p-5185cbf1.entry.js +0 -1
  148. package/dist/ezui/p-5d600057.entry.js +0 -1
  149. package/dist/ezui/p-9f819174.js +0 -1
@@ -1,289 +1,390 @@
1
- import { Component, h, Element, forceUpdate, Prop } from '@stencil/core';
2
- import { createStore, applyMiddleware, combineReducers } from 'redux';
3
- import thunk from 'redux-thunk';
4
- import { formLoad, invalidField } 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._requiredFieldsByDU = {};
12
- }
13
- validateRecords(dataUnit, records) {
14
- const result = { isValid: true, message: '' };
15
- const reqFields = this._requiredFieldsByDU[dataUnit.name];
16
- records.forEach(record => {
17
- reqFields.forEach(field => {
18
- const recordIndex = record["record__index"];
19
- const fieldName = field.name;
20
- const fieldValue = record[fieldName];
21
- if (fieldValue === null || fieldValue === undefined || fieldValue === '') {
22
- this._store.dispatch(invalidField(field.tabControler, field.tabIndex, dataUnit.name, recordIndex, record.record__id, field.name, "Essa informação é obrigatória"));
23
- result.isValid = false;
24
- }
25
- });
26
- });
27
- if (!result.isValid) {
28
- result.message = "Há pelo menos um campo obrigatório não preenchido.";
29
- }
30
- return result;
31
- }
32
- componentWillRender() {
33
- if (this._store === undefined) {
34
- const rootReducer = combineReducers({
35
- "hist": undoable(formReducer),
36
- "nonhist": formNonHistoricReducer
37
- });
38
- this._store = createStore(rootReducer, applyMiddleware(thunk));
39
- this._store.subscribe(() => { forceUpdate(this); });
40
- }
41
- }
42
- loadMDFromExecutor(callBack) {
43
- if (this._loadMetadataFunction) {
44
- const result = this._loadMetadataFunction();
45
- if (result) {
46
- if (result instanceof Promise) {
47
- result.then(md => {
48
- callBack(md);
49
- });
50
- }
51
- else {
52
- callBack(result);
53
- }
54
- }
55
- }
56
- }
57
- loadMDFromElement(callBack) {
58
- const metadata = [];
59
- Array.from(this._host.children).forEach(elem => {
60
- if (elem.tagName === "FORM-METADATA") {
61
- const formMetadata = elem;
62
- metadata.push(formMetadata.metadata);
63
- }
64
- });
65
- callBack(metadata.length > 0 ? metadata : null);
66
- }
67
- updateMetadata(metadata) {
68
- if (metadata) {
69
- const processFields = (duName, form, tabController, tabIndex) => {
70
- var _a;
71
- let requiredFields = this._requiredFieldsByDU[duName];
72
- if (requiredFields === undefined) {
73
- requiredFields = [];
74
- this._requiredFieldsByDU[duName] = requiredFields;
75
- }
76
- form.items.forEach(item => {
77
- if ("fields" in item) {
78
- const fSet = item;
79
- fSet.fields.forEach(f => {
80
- f.tabControler = tabController;
81
- f.tabIndex = tabIndex;
82
- if (f.required) {
83
- requiredFields.push(f);
84
- }
85
- });
86
- }
87
- else {
88
- const f = item;
89
- f.tabControler = tabController;
90
- f.tabIndex = tabIndex;
91
- if (f.required) {
92
- requiredFields.push(f);
93
- }
94
- }
95
- });
96
- (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
97
- const subDU = subForm.dataUnit ? subForm.dataUnit.name : duName;
98
- processFields(subDU, subForm, form.name, index);
99
- });
100
- };
101
- this.metadata = metadata;
102
- metadata.map((form, index) => {
103
- processFields(form.dataUnit.name, form, "__MAIN__FORM__", index);
104
- });
105
- this._store.dispatch(formLoad());
106
- }
107
- }
108
- parseExecutor(executor) {
109
- if (executor) {
110
- return executor instanceof Function ? executor : eval(executor);
111
- }
112
- return null;
113
- }
114
- componentDidLoad() {
115
- this._loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
116
- this._loadDataFunction = this.parseExecutor(this.loadexecutor);
117
- this._saveFunction = this.parseExecutor(this.saveexecutor);
118
- this._removeFunction = this.parseExecutor(this.removeexecutor);
119
- this._fieldSearchFunction = this.parseExecutor(this.fieldsearchexecutor);
120
- if (this.metadata) {
121
- this.updateMetadata(this.metadata);
122
- }
123
- else {
124
- this.loadMDFromElement((md) => this.updateMetadata(md));
125
- if (!this.metadata) {
126
- this.loadMDFromExecutor((md) => this.updateMetadata(md));
127
- }
128
- }
129
- }
130
- buildDataUnit(dataUnit) {
131
- if (dataUnit) {
132
- const { name, records, cardinality } = dataUnit;
133
- if (!(dataUnit instanceof DataUnit)) {
134
- dataUnit = new DataUnit(name, cardinality);
135
- if (records) {
136
- dataUnit.records = records;
137
- }
138
- dataUnit.store = this._store;
139
- dataUnit.loadExecutor = this._loadDataFunction;
140
- dataUnit.saveExecutor = this._saveFunction;
141
- dataUnit.removeExecutor = this._removeFunction;
142
- dataUnit.recordsValidator = this;
143
- dataUnit.fieldSearchExecutor = this._fieldSearchFunction;
144
- }
145
- }
146
- return dataUnit;
147
- }
148
- render() {
149
- return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du) => this.buildDataUnit(du) }) : null;
150
- }
151
- static get is() { return "ez-form"; }
152
- static get originalStyleUrls() { return {
153
- "$": ["ez-form.css"]
154
- }; }
155
- static get styleUrls() { return {
156
- "$": ["ez-form.css"]
157
- }; }
158
- static get properties() { return {
159
- "metadataexecutor": {
160
- "type": "string",
161
- "mutable": false,
162
- "complexType": {
163
- "original": "string | Function",
164
- "resolved": "Function | string",
165
- "references": {
166
- "Function": {
167
- "location": "global"
168
- }
169
- }
170
- },
171
- "required": false,
172
- "optional": false,
173
- "docs": {
174
- "tags": [],
175
- "text": ""
176
- },
177
- "attribute": "metadataexecutor",
178
- "reflect": false
179
- },
180
- "loadexecutor": {
181
- "type": "string",
182
- "mutable": false,
183
- "complexType": {
184
- "original": "string | Function",
185
- "resolved": "Function | string",
186
- "references": {
187
- "Function": {
188
- "location": "global"
189
- }
190
- }
191
- },
192
- "required": false,
193
- "optional": false,
194
- "docs": {
195
- "tags": [],
196
- "text": ""
197
- },
198
- "attribute": "loadexecutor",
199
- "reflect": false
200
- },
201
- "saveexecutor": {
202
- "type": "string",
203
- "mutable": false,
204
- "complexType": {
205
- "original": "string | Function",
206
- "resolved": "Function | string",
207
- "references": {
208
- "Function": {
209
- "location": "global"
210
- }
211
- }
212
- },
213
- "required": false,
214
- "optional": false,
215
- "docs": {
216
- "tags": [],
217
- "text": ""
218
- },
219
- "attribute": "saveexecutor",
220
- "reflect": false
221
- },
222
- "removeexecutor": {
223
- "type": "string",
224
- "mutable": false,
225
- "complexType": {
226
- "original": "string | Function",
227
- "resolved": "Function | string",
228
- "references": {
229
- "Function": {
230
- "location": "global"
231
- }
232
- }
233
- },
234
- "required": false,
235
- "optional": false,
236
- "docs": {
237
- "tags": [],
238
- "text": ""
239
- },
240
- "attribute": "removeexecutor",
241
- "reflect": false
242
- },
243
- "fieldsearchexecutor": {
244
- "type": "string",
245
- "mutable": false,
246
- "complexType": {
247
- "original": "string | Function",
248
- "resolved": "Function | string",
249
- "references": {
250
- "Function": {
251
- "location": "global"
252
- }
253
- }
254
- },
255
- "required": false,
256
- "optional": false,
257
- "docs": {
258
- "tags": [],
259
- "text": ""
260
- },
261
- "attribute": "fieldsearchexecutor",
262
- "reflect": false
263
- },
264
- "metadata": {
265
- "type": "unknown",
266
- "mutable": true,
267
- "complexType": {
268
- "original": "Array<Form>",
269
- "resolved": "Form[]",
270
- "references": {
271
- "Array": {
272
- "location": "global"
273
- },
274
- "Form": {
275
- "location": "import",
276
- "path": "./subcomponents/FormMetadata"
277
- }
278
- }
279
- },
280
- "required": false,
281
- "optional": false,
282
- "docs": {
283
- "tags": [],
284
- "text": ""
285
- }
286
- }
287
- }; }
288
- static get elementRef() { return "_host"; }
289
- }
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
+ }