@sankhyalabs/ezui 1.1.78 → 1.1.79

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 (150) hide show
  1. package/dist/cjs/{AssetsUtils-dd585fba.js → AssetsUtils-02db4f46.js} +1 -1
  2. package/dist/cjs/ez-action-chip.cjs.entry.js +1 -1
  3. package/dist/cjs/ez-application.cjs.entry.js +1 -1
  4. package/dist/cjs/ez-button_3.cjs.entry.js +520 -0
  5. package/dist/cjs/ez-calendar_13.cjs.entry.js +2417 -0
  6. package/dist/cjs/ez-date-time-input.cjs.entry.js +2 -2
  7. package/dist/cjs/ez-dialog.cjs.entry.js +1 -1
  8. package/dist/cjs/{ez-button_11.cjs.entry.js → ez-grid.cjs.entry.js} +14 -1410
  9. package/dist/cjs/ez-icon.cjs.entry.js +30 -0
  10. package/dist/cjs/ez-label-chip.cjs.entry.js +1 -1
  11. package/dist/cjs/ez-modal_2.cjs.entry.js +370 -0
  12. package/dist/cjs/ez-popover.cjs.entry.js +2 -2
  13. package/dist/cjs/ez-popup.cjs.entry.js +1 -1
  14. package/dist/cjs/ez-time-input.cjs.entry.js +3 -3
  15. package/dist/cjs/ez-toast.cjs.entry.js +1 -1
  16. package/dist/cjs/ezui.cjs.js +2 -2
  17. package/dist/cjs/{index-4e4bae01.js → index-2003dec4.js} +0 -10
  18. package/dist/cjs/{index-40ebb2be.js → index-a2266984.js} +18 -23
  19. package/dist/cjs/loader.cjs.js +2 -2
  20. package/dist/collection/collection-manifest.json +0 -2
  21. package/dist/collection/components/ez-form/DataBinder.js +44 -0
  22. package/dist/collection/components/ez-form/ez-form.css +1 -15
  23. package/dist/collection/components/ez-form/ez-form.js +109 -428
  24. package/dist/collection/components/ez-form/fieldbuilder/FieldBuilder.js +45 -0
  25. package/dist/collection/components/ez-form/fieldbuilder/tpl/CheckBox.tpl.js +11 -0
  26. package/dist/collection/components/ez-form/fieldbuilder/tpl/ComboBox.tpl.js +14 -0
  27. package/dist/collection/components/ez-form/fieldbuilder/tpl/DateInput.tpl.js +5 -0
  28. package/dist/collection/components/ez-form/fieldbuilder/tpl/FileInput.tpl.js +5 -0
  29. package/dist/collection/components/ez-form/fieldbuilder/tpl/NumberInput.tpl.js +13 -0
  30. package/dist/collection/components/ez-form/fieldbuilder/tpl/SearchInput.tpl.js +5 -0
  31. package/dist/collection/components/ez-form/fieldbuilder/tpl/TextArea.tpl.js +5 -0
  32. package/dist/collection/components/ez-form/fieldbuilder/tpl/TextInput.tpl.js +5 -0
  33. package/dist/collection/components/ez-form/store/form.slice.js +38 -0
  34. package/dist/collection/components/ez-form/structure/FormItem.js +11 -0
  35. package/dist/collection/components/ez-form/structure/FormSheet.js +5 -0
  36. package/dist/collection/components/ez-form/structure/FormSheetMetadata.js +86 -0
  37. package/dist/collection/components/test-du/test-du.js +65 -23
  38. package/dist/custom-elements/index.d.ts +0 -12
  39. package/dist/custom-elements/index.js +380 -2065
  40. package/dist/esm/{AssetsUtils-3803e935.js → AssetsUtils-76ca41e1.js} +1 -1
  41. package/dist/esm/ez-action-chip.entry.js +1 -1
  42. package/dist/esm/ez-application.entry.js +1 -1
  43. package/dist/esm/ez-button_3.entry.js +514 -0
  44. package/dist/esm/ez-calendar_13.entry.js +2401 -0
  45. package/dist/esm/ez-date-time-input.entry.js +2 -2
  46. package/dist/esm/ez-dialog.entry.js +1 -1
  47. package/dist/esm/{ez-button_11.entry.js → ez-grid.entry.js} +4 -1390
  48. package/dist/esm/ez-icon.entry.js +26 -0
  49. package/dist/esm/ez-label-chip.entry.js +1 -1
  50. package/dist/esm/ez-modal_2.entry.js +365 -0
  51. package/dist/esm/ez-popover.entry.js +2 -2
  52. package/dist/esm/ez-popup.entry.js +1 -1
  53. package/dist/esm/ez-time-input.entry.js +3 -3
  54. package/dist/esm/ez-toast.entry.js +1 -1
  55. package/dist/esm/ezui.js +2 -2
  56. package/dist/esm/{index-1dacecd3.js → index-077c7fcf.js} +0 -10
  57. package/dist/esm/{index-ca8700cb.js → index-afe19542.js} +17 -21
  58. package/dist/esm/loader.js +2 -2
  59. package/dist/ezui/ezui.esm.js +1 -1
  60. package/dist/ezui/p-00b837e2.js +1 -0
  61. package/dist/ezui/{p-516d0e0f.entry.js → p-0a2056d9.entry.js} +1 -1
  62. package/dist/ezui/{p-a15093e3.entry.js → p-0d8368fc.entry.js} +1 -1
  63. package/dist/ezui/p-1e36e3ff.entry.js +1 -0
  64. package/dist/ezui/p-446ec85b.js +1 -0
  65. package/dist/ezui/{p-74f978db.entry.js → p-5509ee41.entry.js} +46 -46
  66. package/dist/ezui/{p-a18a2d7b.entry.js → p-57ea4b84.entry.js} +1 -1
  67. package/dist/ezui/{p-5a86e18a.entry.js → p-6d157776.entry.js} +1 -1
  68. package/dist/ezui/{p-f3c5f27e.entry.js → p-7a1f2e0e.entry.js} +1 -1
  69. package/dist/ezui/p-7de3c95d.js +1 -0
  70. package/dist/ezui/{p-8d6cdd3e.entry.js → p-857ead8e.entry.js} +1 -1
  71. package/dist/ezui/{p-c6d469fc.entry.js → p-920bb8c9.entry.js} +1 -1
  72. package/dist/ezui/p-9be02ecf.entry.js +1 -0
  73. package/dist/ezui/p-a4a39579.entry.js +1 -0
  74. package/dist/ezui/p-d5699f29.entry.js +1 -0
  75. package/dist/ezui/p-d64a3939.entry.js +1 -0
  76. package/dist/ezui/{p-5da66d3e.entry.js → p-da31cd21.entry.js} +1 -1
  77. package/dist/types/components/ez-form/DataBinder.d.ts +10 -0
  78. package/dist/types/components/ez-form/ez-form.d.ts +24 -32
  79. package/dist/types/components/ez-form/fieldbuilder/FieldBuilder.d.ts +2 -0
  80. package/dist/types/components/ez-form/fieldbuilder/tpl/CheckBox.tpl.d.ts +3 -0
  81. package/dist/types/components/ez-form/fieldbuilder/tpl/ComboBox.tpl.d.ts +4 -0
  82. package/dist/types/components/ez-form/fieldbuilder/tpl/DateInput.tpl.d.ts +4 -0
  83. package/dist/types/components/ez-form/fieldbuilder/tpl/FileInput.tpl.d.ts +4 -0
  84. package/dist/types/components/ez-form/fieldbuilder/tpl/NumberInput.tpl.d.ts +8 -0
  85. package/dist/types/components/ez-form/fieldbuilder/tpl/SearchInput.tpl.d.ts +4 -0
  86. package/dist/types/components/ez-form/fieldbuilder/tpl/TextArea.tpl.d.ts +4 -0
  87. package/dist/types/components/ez-form/fieldbuilder/tpl/TextInput.tpl.d.ts +4 -0
  88. package/dist/types/components/ez-form/store/form.slice.d.ts +24 -0
  89. package/dist/types/components/ez-form/structure/FormItem.d.ts +9 -0
  90. package/dist/types/components/ez-form/structure/FormSheet.d.ts +9 -0
  91. package/dist/types/components/ez-form/structure/FormSheetMetadata.d.ts +27 -0
  92. package/dist/types/components/test-du/test-du.d.ts +8 -2
  93. package/dist/types/components.d.ts +9 -63
  94. package/package.json +1 -1
  95. package/react/components.d.ts +0 -2
  96. package/react/components.js +0 -2
  97. package/react/components.js.map +1 -1
  98. package/dist/cjs/ApplicationUtils-d1c1db56.js +0 -35
  99. package/dist/cjs/DataUnit-fdd7c70e.js +0 -474
  100. package/dist/cjs/ez-calendar.cjs.entry.js +0 -217
  101. package/dist/cjs/ez-collapsible-box_6.cjs.entry.js +0 -634
  102. package/dist/cjs/ez-combo-box.cjs.entry.js +0 -254
  103. package/dist/cjs/ez-form.cjs.entry.js +0 -1838
  104. package/dist/cjs/ez-number-input.cjs.entry.js +0 -74
  105. package/dist/cjs/form-metadata.cjs.entry.js +0 -129
  106. package/dist/collection/components/ez-form/assets/trash-can-outline.svg +0 -3
  107. package/dist/collection/components/ez-form/store/Form.actions.js +0 -132
  108. package/dist/collection/components/ez-form/store/Form.reducer.js +0 -194
  109. package/dist/collection/components/ez-form/store/Form.selectors.js +0 -44
  110. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +0 -301
  111. package/dist/collection/components/ez-form/subcomponents/FormMetadata.js +0 -8
  112. package/dist/collection/components/ez-form/subcomponents/css/place-holder.css +0 -24
  113. package/dist/collection/components/ez-form/subcomponents/form-metadata.js +0 -227
  114. package/dist/collection/components/ez-form/subcomponents/place-holder.js +0 -14
  115. package/dist/collection/components/ez-form/subcomponents/structure/Field.js +0 -95
  116. package/dist/collection/components/ez-form/subcomponents/structure/FieldSet.js +0 -27
  117. package/dist/collection/components/ez-form/subcomponents/structure/FormSheet.js +0 -41
  118. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +0 -37
  119. package/dist/esm/ApplicationUtils-01280a9d.js +0 -33
  120. package/dist/esm/DataUnit-1cd45202.js +0 -464
  121. package/dist/esm/ez-calendar.entry.js +0 -213
  122. package/dist/esm/ez-collapsible-box_6.entry.js +0 -625
  123. package/dist/esm/ez-combo-box.entry.js +0 -250
  124. package/dist/esm/ez-form.entry.js +0 -1834
  125. package/dist/esm/ez-number-input.entry.js +0 -70
  126. package/dist/esm/form-metadata.entry.js +0 -125
  127. package/dist/ezui/assets/trash-can-outline.svg +0 -3
  128. package/dist/ezui/p-14bee38e.entry.js +0 -1
  129. package/dist/ezui/p-37a611ea.js +0 -1
  130. package/dist/ezui/p-3a09c678.entry.js +0 -1
  131. package/dist/ezui/p-43c15c94.entry.js +0 -1
  132. package/dist/ezui/p-7107d7ef.js +0 -1
  133. package/dist/ezui/p-72ff3c95.entry.js +0 -1
  134. package/dist/ezui/p-88f45a83.entry.js +0 -1
  135. package/dist/ezui/p-8f4851a6.js +0 -1
  136. package/dist/ezui/p-9dfd537e.js +0 -1
  137. package/dist/ezui/p-a0331955.entry.js +0 -1
  138. package/dist/ezui/p-a19f2af3.entry.js +0 -1
  139. package/dist/ezui/p-da929c01.js +0 -1
  140. package/dist/types/components/ez-form/store/Form.actions.d.ts +0 -111
  141. package/dist/types/components/ez-form/store/Form.reducer.d.ts +0 -20
  142. package/dist/types/components/ez-form/store/Form.selectors.d.ts +0 -14
  143. package/dist/types/components/ez-form/subcomponents/DataUnit.d.ts +0 -91
  144. package/dist/types/components/ez-form/subcomponents/FormMetadata.d.ts +0 -24
  145. package/dist/types/components/ez-form/subcomponents/form-metadata.d.ts +0 -16
  146. package/dist/types/components/ez-form/subcomponents/place-holder.d.ts +0 -3
  147. package/dist/types/components/ez-form/subcomponents/structure/Field.d.ts +0 -11
  148. package/dist/types/components/ez-form/subcomponents/structure/FieldSet.d.ts +0 -13
  149. package/dist/types/components/ez-form/subcomponents/structure/FormSheet.d.ts +0 -14
  150. package/dist/types/components/ez-form/subcomponents/structure/NavigationBar.d.ts +0 -19
@@ -1,253 +1,97 @@
1
- import { Component, h, Element, forceUpdate, Prop, Method, Watch } 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";
1
+ import { Component, h, Host, Prop, Element, forceUpdate, Method } from "@stencil/core";
2
+ import { DataUnit, Action } from "@sankhyalabs/core";
3
+ import { FormSheet } from "./structure/FormSheet";
4
+ import { buildFromConfig, buildFromDataUnit } from "./structure/FormSheetMetadata";
5
+ import { createStore } from "redux";
6
+ import { formReducer, selectCurrentSheet, selectFormMetadata, loadMetadata, changeTab } from "./store/form.slice";
7
+ import DataBinder from "./DataBinder";
8
+ import ApplicationUtils from "../../utils/ApplicationUtils";
9
9
  export class EzForm {
10
- constructor() {
11
- this.enabled = true;
12
- this.loading = false;
13
- this._dataUnits = new Map();
14
- this._duSources = new Map();
15
- this._tabPositionByField = new Map();
16
- this._duToLoad = [];
17
- }
18
- cleanPreparedMetadata() {
19
- this._preparedMetadata = undefined;
20
- }
21
- async validate() {
22
- const duSourcesNames = Array.from(this._duSources.keys());
23
- for (let i = 0; i < this._duSources.size; i++) {
24
- const duName = duSourcesNames[i];
25
- let du = this._dataUnits.get(duName);
26
- if (du === undefined) {
27
- const source = this._duSources.get(duName);
28
- du = this.buildDataUnit(source, source.parentDUName);
29
- }
30
- if (!du.validateRecords()) {
31
- return false;
32
- }
33
- }
34
- return true;
35
- }
36
- async getChanges() {
37
- let allChanges = [];
38
- const dataUnits = Array.from(this._dataUnits.values());
39
- for (let i = 0; i < this._dataUnits.size; i++) {
40
- const du = dataUnits[i];
41
- //Só devemos buscar as alterações de DU raiz, pois os sub DUs serão enviados junto.
42
- if (!du.parentDU) {
43
- const duChanges = du.getChangesToSave();
44
- if (duChanges) {
45
- allChanges = allChanges.concat(duChanges);
10
+ submit() {
11
+ return Promise.resolve();
12
+ }
13
+ cancel() {
14
+ return Promise.resolve();
15
+ }
16
+ validate() {
17
+ return new Promise((accept, reject) => {
18
+ const metadata = selectFormMetadata(this._store.getState());
19
+ const requiredFields = this._staticFields
20
+ .filter(f => f.dataset.required)
21
+ .map(f => f.dataset.fieldName)
22
+ .concat(metadata.getRequiredFields());
23
+ const records = this.dataUnit.records;
24
+ for (let i = 0; i < records.length; i++) {
25
+ if (!this.validateRequired(requiredFields, records[i])) {
26
+ reject();
27
+ break;
46
28
  }
47
29
  }
48
- }
49
- return allChanges;
50
- }
51
- async changeFieldValue(dataUnit, fieldName, value) {
52
- const du = this._dataUnits.get(dataUnit);
53
- if (du) {
54
- du.changeValue(fieldName, value);
55
- }
30
+ accept();
31
+ });
56
32
  }
57
- validateRecords(dataUnit, records, triggedBy) {
58
- const result = { isValid: true, message: "" };
59
- if (this.ignoreSaveValidation && triggedBy === "SAVE") {
60
- return result;
61
- }
62
- const validateField = (field) => {
63
- if (field.readOnly) {
64
- return false;
33
+ validateRequired(requiredFields, record) {
34
+ const invalidFields = [];
35
+ requiredFields.forEach(field => {
36
+ const value = record[field];
37
+ const fieldElem = this._element.querySelector(`[data-field-name=${field}]`);
38
+ if (value === null || value === undefined || value === "") {
39
+ invalidFields.push(field);
40
+ fieldElem["errorMessage"] = "Essa informação é obrigatória";
65
41
  }
66
- if (field.userInterface === "SWITCH" || field.userInterface === "CHECKBOX") {
67
- return false;
68
- }
69
- return true;
70
- };
71
- const recordValidator = record => {
72
- dataUnit.requiredFields.forEach(field => {
73
- if (validateField(field)) {
74
- const recordIndex = record["record__index"];
75
- const fieldName = field.name;
76
- const fieldValue = record[fieldName];
77
- if (fieldValue === null || fieldValue === undefined || fieldValue === "") {
78
- const tabPosition = this._tabPositionByField.get(dataUnit.name + field.name);
79
- this._store.dispatch(invalidField(tabPosition.tabName, tabPosition.index, dataUnit.name, recordIndex, record.record__id, field.name, "Essa informação é obrigatória"));
80
- result.isValid = false;
81
- result.message = "Há pelo menos um campo obrigatório não preenchido.";
82
- }
83
- }
84
- });
85
- };
86
- if (dataUnit.records.length === 0) {
87
- recordValidator({});
88
- }
89
- else {
90
- let validatedRecords = {};
91
- records.forEach(r => {
92
- recordValidator(r);
93
- validatedRecords[r.record__id] = true;
94
- });
95
- dataUnit.records.forEach(r => {
96
- if (!validatedRecords[r.record__id]) {
97
- recordValidator(r);
98
- }
99
- });
100
- }
101
- return result;
102
- }
103
- loadMDFromExecutor(callBack) {
104
- const loadMetadataFunction = this.parseExecutor(this.metadataExecutor);
105
- if (loadMetadataFunction) {
106
- const result = loadMetadataFunction();
107
- if (result) {
108
- if (result instanceof Promise) {
109
- result.then(md => {
110
- callBack(md);
111
- });
112
- }
113
- else {
114
- callBack(result);
115
- }
116
- }
117
- }
118
- }
119
- loadMDFromElement(callBack) {
120
- const metadata = [];
121
- Array.from(this._host.children).forEach(elem => {
122
- if (elem.tagName === "FORM-METADATA") {
123
- const formMetadata = elem;
124
- metadata.push(formMetadata.metadata);
42
+ else {
43
+ fieldElem["errorMessage"] = "";
125
44
  }
126
45
  });
127
- callBack(metadata.length > 0 ? metadata : null);
128
- }
129
- updateMetadata(metadata) {
130
- if (metadata) {
131
- const processFields = (duName, form, tabController, tabIndex) => {
132
- var _a;
133
- form.items.forEach(item => {
134
- if ("fields" in item) {
135
- const fSet = item;
136
- fSet.fields.forEach(f => {
137
- f.form = this;
138
- this._tabPositionByField.set(duName + f.name, { tabName: tabController, index: tabIndex });
139
- });
140
- }
141
- else {
142
- const f = item;
143
- f.form = this;
144
- this._tabPositionByField.set(duName + f.name, { tabName: tabController, index: tabIndex });
145
- }
146
- });
147
- (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
148
- const subDu = subForm.dataUnit;
149
- if (subDu) {
150
- this._duSources.set(subDu.name, subDu);
151
- subDu.parentDUName = duName;
152
- }
153
- processFields(subDu ? subDu.name : duName, subForm, form.name, index);
154
- });
155
- };
156
- this._preparedMetadata = metadata.map((form, index) => {
157
- const du = form.dataUnit;
158
- if (form.autoLoad) {
159
- this._duToLoad.push(du);
160
- }
161
- this.decorateDU(du);
162
- const duName = du.name;
163
- this._duSources.set(duName, du);
164
- processFields(duName, form, "__MAIN__FORM__", index);
165
- return form;
166
- });
167
- this._store.dispatch(formLoad());
168
- }
46
+ const isValid = invalidFields.length === 0;
47
+ if (!isValid) {
48
+ ApplicationUtils.info("Há pelo menos um campo obrigatório não preenchido.");
49
+ }
50
+ return isValid;
51
+ }
52
+ getDynamicContent() {
53
+ var _a;
54
+ const formMD = selectFormMetadata(this._store.getState());
55
+ if (!formMD)
56
+ return null;
57
+ const currentSheet = selectCurrentSheet((_a = this._store) === null || _a === void 0 ? void 0 : _a.getState());
58
+ if (!currentSheet) {
59
+ return null;
60
+ }
61
+ const allSheets = Array.from(formMD.getAllSheets().values());
62
+ const result = [];
63
+ if (allSheets.length > 1) {
64
+ result.push(h("ez-tabselector", { onEzChange: (evt) => this._store.dispatch(changeTab(evt.detail)), selectedTab: currentSheet.name }, allSheets.map(s => h("ez-tab", { tabKey: s.name, label: s.label }))));
65
+ }
66
+ result.push(h(FormSheet, { store: this._store, source: currentSheet }));
67
+ return result;
169
68
  }
170
- parseExecutor(executor) {
171
- if (executor) {
172
- return executor instanceof Function ? executor : eval(executor);
69
+ processMetadata() {
70
+ if (!this._staticFields || this._staticFields.length === 0) {
71
+ const metadata = this.config && this.config.length > 0 ? buildFromConfig(this.config, this.dataUnit) : buildFromDataUnit(this.dataUnit);
72
+ this._store.dispatch(loadMetadata(metadata));
173
73
  }
174
- return null;
175
74
  }
176
- componentWillRender() {
177
- if (this._store === undefined) {
178
- const rootReducer = combineReducers({
179
- "hist": undoable(formReducer),
180
- "nonhist": formNonHistoricReducer
181
- });
182
- this._store = createStore(rootReducer, applyMiddleware(thunk));
183
- this._store.subscribe(() => { forceUpdate(this); });
184
- if (this.slaveMode) {
185
- this._store.dispatch(showHideNavigationButtons("saveVisible", false));
186
- this._store.dispatch(showHideNavigationButtons("cancelVisible", false));
187
- this._store.dispatch(showHideNavigationButtons("reloadVisible", false));
188
- }
75
+ componentWillLoad() {
76
+ if (this.dataUnit === undefined) {
77
+ this.dataUnit = new DataUnit("ez-form");
189
78
  }
190
- if (this._preparedMetadata === undefined) {
191
- if (this.metadata) {
192
- this.updateMetadata(this.metadata);
193
- }
194
- else {
195
- this.loadMDFromElement((md) => this.updateMetadata(md));
196
- if (!this._preparedMetadata) {
197
- this.loadMDFromExecutor((md) => this.updateMetadata(md));
198
- }
79
+ this.dataUnit.subscribe(action => {
80
+ if (action.type === Action.METADATA_LOADED) {
81
+ this.processMetadata();
199
82
  }
200
- }
83
+ });
84
+ this._dataBinder = new DataBinder(this.dataUnit);
85
+ this._store = createStore(formReducer);
86
+ this._store.subscribe(() => forceUpdate(this));
87
+ this._staticFields = Array.from(this._element.querySelectorAll("[data-field-name]"));
88
+ this.processMetadata();
201
89
  }
202
90
  componentDidRender() {
203
- this._duToLoad.forEach(du => du.load());
204
- this._duToLoad = [];
205
- }
206
- loadSearch(argument, context) {
207
- const fieldSearchExecutor = this.parseExecutor(this.fieldSearchExecutor);
208
- if (fieldSearchExecutor) {
209
- return fieldSearchExecutor(argument, context);
210
- }
211
- else {
212
- return [{ value: 0, label: "Sem resultados" }];
213
- }
214
- }
215
- buildDataUnit(dataUnit, parentDataUnit) {
216
- if (dataUnit) {
217
- const { name, unitLabel, records, cardinality, fields } = dataUnit;
218
- if (!(dataUnit instanceof DataUnit)) {
219
- let parent;
220
- if (parentDataUnit instanceof DataUnit) {
221
- parent = parentDataUnit;
222
- }
223
- else {
224
- parent = this._dataUnits.get(parentDataUnit);
225
- }
226
- dataUnit = new DataUnit(name, unitLabel, cardinality, parent);
227
- dataUnit.fields = fields;
228
- this._dataUnits.set(dataUnit.name, dataUnit);
229
- if (records) {
230
- dataUnit.records = records;
231
- }
232
- }
233
- this.decorateDU(dataUnit);
234
- }
235
- return dataUnit;
236
- }
237
- decorateDU(dataUnit) {
238
- dataUnit.store = this._store;
239
- dataUnit.loadExecutor = this.parseExecutor(this.loadExecutor);
240
- dataUnit.saveExecutor = this.parseExecutor(this.saveExecutor);
241
- dataUnit.removeExecutor = this.parseExecutor(this.removeExecutor);
242
- dataUnit.recordsValidator = this;
91
+ this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")));
243
92
  }
244
93
  render() {
245
- if (this.loading) {
246
- return h("place-holder", null);
247
- }
248
- else {
249
- return this._preparedMetadata ? h(FormSheet, { enabled: this.enabled, store: this._store, source: this._preparedMetadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
250
- }
94
+ return (h(Host, null, this._staticFields.length > 0 ? null : this.getDynamicContent()));
251
95
  }
252
96
  static get is() { return "ez-form"; }
253
97
  static get originalStyleUrls() { return {
@@ -256,101 +100,17 @@ export class EzForm {
256
100
  static get styleUrls() { return {
257
101
  "$": ["ez-form.css"]
258
102
  }; }
259
- static get assetsDirs() { return ["assets"]; }
260
103
  static get properties() { return {
261
- "metadataExecutor": {
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": "metadata-executor",
280
- "reflect": false
281
- },
282
- "loadExecutor": {
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": "load-executor",
301
- "reflect": false
302
- },
303
- "saveExecutor": {
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": "save-executor",
322
- "reflect": false
323
- },
324
- "removeExecutor": {
325
- "type": "string",
326
- "mutable": false,
327
- "complexType": {
328
- "original": "string | Function",
329
- "resolved": "Function | string",
330
- "references": {
331
- "Function": {
332
- "location": "global"
333
- }
334
- }
335
- },
336
- "required": false,
337
- "optional": false,
338
- "docs": {
339
- "tags": [],
340
- "text": ""
341
- },
342
- "attribute": "remove-executor",
343
- "reflect": false
344
- },
345
- "fieldSearchExecutor": {
346
- "type": "string",
347
- "mutable": false,
104
+ "dataUnit": {
105
+ "type": "unknown",
106
+ "mutable": true,
348
107
  "complexType": {
349
- "original": "string | Function",
350
- "resolved": "Function | string",
108
+ "original": "DataUnit",
109
+ "resolved": "DataUnit",
351
110
  "references": {
352
- "Function": {
353
- "location": "global"
111
+ "DataUnit": {
112
+ "location": "import",
113
+ "path": "@sankhyalabs/core"
354
114
  }
355
115
  }
356
116
  },
@@ -359,40 +119,20 @@ export class EzForm {
359
119
  "docs": {
360
120
  "tags": [],
361
121
  "text": ""
362
- },
363
- "attribute": "field-search-executor",
364
- "reflect": false
365
- },
366
- "ignoreSaveValidation": {
367
- "type": "boolean",
368
- "mutable": false,
369
- "complexType": {
370
- "original": "boolean",
371
- "resolved": "boolean",
372
- "references": {}
373
- },
374
- "required": false,
375
- "optional": false,
376
- "docs": {
377
- "tags": [],
378
- "text": ""
379
- },
380
- "attribute": "ignore-save-validation",
381
- "reflect": false
122
+ }
382
123
  },
383
- "metadata": {
124
+ "config": {
384
125
  "type": "unknown",
385
126
  "mutable": false,
386
127
  "complexType": {
387
- "original": "Array<Form>",
388
- "resolved": "Form[]",
128
+ "original": "Array<FieldConfig>",
129
+ "resolved": "FieldConfig[]",
389
130
  "references": {
390
131
  "Array": {
391
132
  "location": "global"
392
133
  },
393
- "Form": {
394
- "location": "import",
395
- "path": "./subcomponents/FormMetadata"
134
+ "FieldConfig": {
135
+ "location": "local"
396
136
  }
397
137
  }
398
138
  },
@@ -402,110 +142,55 @@ export class EzForm {
402
142
  "tags": [],
403
143
  "text": ""
404
144
  }
405
- },
406
- "slaveMode": {
407
- "type": "boolean",
408
- "mutable": false,
409
- "complexType": {
410
- "original": "boolean",
411
- "resolved": "boolean",
412
- "references": {}
413
- },
414
- "required": false,
415
- "optional": false,
416
- "docs": {
417
- "tags": [],
418
- "text": ""
419
- },
420
- "attribute": "slave-mode",
421
- "reflect": false
422
- },
423
- "enabled": {
424
- "type": "boolean",
425
- "mutable": false,
426
- "complexType": {
427
- "original": "boolean",
428
- "resolved": "boolean",
429
- "references": {}
430
- },
431
- "required": false,
432
- "optional": false,
433
- "docs": {
434
- "tags": [],
435
- "text": ""
436
- },
437
- "attribute": "enabled",
438
- "reflect": false,
439
- "defaultValue": "true"
440
- },
441
- "loading": {
442
- "type": "boolean",
443
- "mutable": true,
444
- "complexType": {
445
- "original": "boolean",
446
- "resolved": "boolean",
447
- "references": {}
448
- },
449
- "required": false,
450
- "optional": false,
451
- "docs": {
452
- "tags": [],
453
- "text": ""
454
- },
455
- "attribute": "loading",
456
- "reflect": true,
457
- "defaultValue": "false"
458
145
  }
459
146
  }; }
460
147
  static get methods() { return {
461
- "validate": {
148
+ "submit": {
462
149
  "complexType": {
463
- "signature": "() => Promise<boolean>",
150
+ "signature": "() => Promise<void>",
464
151
  "parameters": [],
465
152
  "references": {
466
153
  "Promise": {
467
154
  "location": "global"
468
155
  }
469
156
  },
470
- "return": "Promise<boolean>"
157
+ "return": "Promise<void>"
471
158
  },
472
159
  "docs": {
473
160
  "text": "",
474
161
  "tags": []
475
162
  }
476
163
  },
477
- "getChanges": {
164
+ "cancel": {
478
165
  "complexType": {
479
- "signature": "() => Promise<any[]>",
166
+ "signature": "() => Promise<void>",
480
167
  "parameters": [],
481
168
  "references": {
482
169
  "Promise": {
483
170
  "location": "global"
484
171
  }
485
172
  },
486
- "return": "Promise<any[]>"
173
+ "return": "Promise<void>"
487
174
  },
488
175
  "docs": {
489
176
  "text": "",
490
177
  "tags": []
491
178
  }
492
179
  },
493
- "changeFieldValue": {
180
+ "validate": {
494
181
  "complexType": {
495
- "signature": "(dataUnit: string, fieldName: string, value: any) => Promise<void>",
496
- "parameters": [{
497
- "tags": [],
498
- "text": ""
499
- }, {
500
- "tags": [],
501
- "text": ""
502
- }, {
503
- "tags": [],
504
- "text": ""
505
- }],
182
+ "signature": "() => Promise<void>",
183
+ "parameters": [],
506
184
  "references": {
507
185
  "Promise": {
508
186
  "location": "global"
187
+ },
188
+ "Array": {
189
+ "location": "global"
190
+ },
191
+ "Record": {
192
+ "location": "import",
193
+ "path": "@sankhyalabs/core"
509
194
  }
510
195
  },
511
196
  "return": "Promise<void>"
@@ -516,9 +201,5 @@ export class EzForm {
516
201
  }
517
202
  }
518
203
  }; }
519
- static get elementRef() { return "_host"; }
520
- static get watchers() { return [{
521
- "propName": "metadata",
522
- "methodName": "cleanPreparedMetadata"
523
- }]; }
204
+ static get elementRef() { return "_element"; }
524
205
  }
@@ -0,0 +1,45 @@
1
+ import { UserInterface } from "@sankhyalabs/core";
2
+ import { buildTextArea } from "./tpl/TextArea.tpl";
3
+ import { buildTextInput } from "./tpl/TextInput.tpl";
4
+ import { buildCheckBox, buildSwitch } from "./tpl/CheckBox.tpl";
5
+ import { buildComboBox } from "./tpl/ComboBox.tpl";
6
+ import { buildSearch } from "./tpl/SearchInput.tpl";
7
+ import { buildFile } from "./tpl/FileInput.tpl";
8
+ import { buildDate } from "./tpl/DateInput.tpl";
9
+ import { buildInteger, buildDecimal } from "./tpl/NumberInput.tpl";
10
+ const uiBuilders = new Map();
11
+ uiBuilders.set(UserInterface.LONGTEXT, buildTextArea);
12
+ uiBuilders.set(UserInterface.CHECKBOX, buildCheckBox);
13
+ uiBuilders.set(UserInterface.SWITCH, buildSwitch);
14
+ uiBuilders.set(UserInterface.OPTIONSELECTOR, buildComboBox);
15
+ uiBuilders.set(UserInterface.SEARCH, buildSearch);
16
+ uiBuilders.set(UserInterface.FILE, buildFile);
17
+ uiBuilders.set(UserInterface.DATE, buildDate);
18
+ uiBuilders.set(UserInterface.DECIMALNUMBER, buildDecimal);
19
+ uiBuilders.set(UserInterface.INTEGERNUMBER, buildInteger);
20
+ export const buildField = (field) => {
21
+ const descriptor = field.descriptor;
22
+ const config = Object.assign({}, field.config);
23
+ let builder;
24
+ let props;
25
+ if (descriptor) {
26
+ builder = uiBuilders.get(descriptor.userInterface);
27
+ if (!config.label) {
28
+ config.label = descriptor.label;
29
+ }
30
+ if (!config.name) {
31
+ config.name = descriptor.name;
32
+ }
33
+ if (config.required === undefined) {
34
+ config.required = descriptor.required;
35
+ }
36
+ props = descriptor.properties;
37
+ }
38
+ if (config.required) {
39
+ config.label = `* ${config.label} (obrigatório)`;
40
+ }
41
+ if (!builder) {
42
+ builder = buildTextInput;
43
+ }
44
+ return builder(config, props);
45
+ };
@@ -0,0 +1,11 @@
1
+ import { h } from "@stencil/core";
2
+ export const buildSwitch = (fieldConfig) => {
3
+ return buildField(fieldConfig.name, fieldConfig.label, true);
4
+ };
5
+ export const buildCheckBox = (fieldConfig) => {
6
+ return buildField(fieldConfig.name, fieldConfig.label, false);
7
+ };
8
+ function buildField(fieldName, fieldLabel, switchMode = false) {
9
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding--small align--middle padding-bottom--large" },
10
+ h("ez-check", { label: fieldLabel, mode: switchMode ? "switch" : "regular", "data-field-name": fieldName, key: fieldName })));
11
+ }