@sankhyalabs/ezui 1.1.78 → 1.1.81

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 (153) 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_14.cjs.entry.js +2598 -0
  6. package/dist/cjs/ez-dialog.cjs.entry.js +1 -1
  7. package/dist/cjs/{ez-button_11.cjs.entry.js → ez-grid.cjs.entry.js} +14 -1410
  8. package/dist/cjs/ez-icon.cjs.entry.js +30 -0
  9. package/dist/cjs/ez-label-chip.cjs.entry.js +1 -1
  10. package/dist/cjs/ez-modal_2.cjs.entry.js +370 -0
  11. package/dist/cjs/ez-popover.cjs.entry.js +2 -2
  12. package/dist/cjs/ez-popup.cjs.entry.js +1 -1
  13. package/dist/cjs/ez-time-input.cjs.entry.js +3 -3
  14. package/dist/cjs/ez-toast.cjs.entry.js +1 -1
  15. package/dist/cjs/ezui.cjs.js +2 -2
  16. package/dist/cjs/{index-4e4bae01.js → index-2003dec4.js} +0 -10
  17. package/dist/cjs/{index-40ebb2be.js → index-4fc4a0a4.js} +86 -63
  18. package/dist/cjs/loader.cjs.js +2 -2
  19. package/dist/collection/collection-manifest.json +0 -2
  20. package/dist/collection/components/ez-form/DataBinder.js +50 -0
  21. package/dist/collection/components/ez-form/ez-form.css +1 -15
  22. package/dist/collection/components/ez-form/ez-form.js +112 -427
  23. package/dist/collection/components/ez-form/fieldbuilder/FieldBuilder.js +46 -0
  24. package/dist/collection/components/ez-form/fieldbuilder/tpl/CheckBox.tpl.js +11 -0
  25. package/dist/collection/components/ez-form/fieldbuilder/tpl/ComboBox.tpl.js +14 -0
  26. package/dist/collection/components/ez-form/fieldbuilder/tpl/DateInput.tpl.js +9 -0
  27. package/dist/collection/components/ez-form/fieldbuilder/tpl/FileInput.tpl.js +5 -0
  28. package/dist/collection/components/ez-form/fieldbuilder/tpl/NumberInput.tpl.js +13 -0
  29. package/dist/collection/components/ez-form/fieldbuilder/tpl/SearchInput.tpl.js +5 -0
  30. package/dist/collection/components/ez-form/fieldbuilder/tpl/TextArea.tpl.js +5 -0
  31. package/dist/collection/components/ez-form/fieldbuilder/tpl/TextInput.tpl.js +5 -0
  32. package/dist/collection/components/ez-form/store/form.slice.js +38 -0
  33. package/dist/collection/components/ez-form/structure/FormItem.js +11 -0
  34. package/dist/collection/components/ez-form/structure/FormSheet.js +5 -0
  35. package/dist/collection/components/ez-form/structure/FormSheetMetadata.js +86 -0
  36. package/dist/collection/components/test-du/test-du.js +65 -23
  37. package/dist/custom-elements/index.d.ts +0 -12
  38. package/dist/custom-elements/index.js +462 -2104
  39. package/dist/esm/{AssetsUtils-3803e935.js → AssetsUtils-76ca41e1.js} +1 -1
  40. package/dist/esm/ez-action-chip.entry.js +1 -1
  41. package/dist/esm/ez-application.entry.js +1 -1
  42. package/dist/esm/ez-button_3.entry.js +514 -0
  43. package/dist/esm/ez-calendar_14.entry.js +2581 -0
  44. package/dist/esm/ez-dialog.entry.js +1 -1
  45. package/dist/esm/{ez-button_11.entry.js → ez-grid.entry.js} +4 -1390
  46. package/dist/esm/ez-icon.entry.js +26 -0
  47. package/dist/esm/ez-label-chip.entry.js +1 -1
  48. package/dist/esm/ez-modal_2.entry.js +365 -0
  49. package/dist/esm/ez-popover.entry.js +2 -2
  50. package/dist/esm/ez-popup.entry.js +1 -1
  51. package/dist/esm/ez-time-input.entry.js +3 -3
  52. package/dist/esm/ez-toast.entry.js +1 -1
  53. package/dist/esm/ezui.js +2 -2
  54. package/dist/esm/{index-1dacecd3.js → index-077c7fcf.js} +0 -10
  55. package/dist/esm/{index-ca8700cb.js → index-e31373d9.js} +85 -61
  56. package/dist/esm/loader.js +2 -2
  57. package/dist/ezui/ezui.esm.js +1 -1
  58. package/dist/ezui/{p-516d0e0f.entry.js → p-0a2056d9.entry.js} +1 -1
  59. package/dist/ezui/{p-74f978db.entry.js → p-1c8d64d0.entry.js} +46 -46
  60. package/dist/ezui/p-1e36e3ff.entry.js +1 -0
  61. package/dist/ezui/p-446ec85b.js +1 -0
  62. package/dist/ezui/{p-a18a2d7b.entry.js → p-57ea4b84.entry.js} +1 -1
  63. package/dist/ezui/{p-5a86e18a.entry.js → p-6d157776.entry.js} +1 -1
  64. package/dist/ezui/p-7de3c95d.js +1 -0
  65. package/dist/ezui/p-8b9ef58b.entry.js +1 -0
  66. package/dist/ezui/{p-c6d469fc.entry.js → p-920bb8c9.entry.js} +1 -1
  67. package/dist/ezui/p-983bd291.js +1 -0
  68. package/dist/ezui/p-9dbf569a.entry.js +1 -0
  69. package/dist/ezui/p-a4a39579.entry.js +1 -0
  70. package/dist/ezui/{p-8d6cdd3e.entry.js → p-aef3394b.entry.js} +1 -1
  71. package/dist/ezui/p-d64a3939.entry.js +1 -0
  72. package/dist/ezui/{p-5da66d3e.entry.js → p-da31cd21.entry.js} +1 -1
  73. package/dist/ezui/{p-f3c5f27e.entry.js → p-da63000f.entry.js} +1 -1
  74. package/dist/types/components/ez-form/DataBinder.d.ts +10 -0
  75. package/dist/types/components/ez-form/ez-form.d.ts +25 -32
  76. package/dist/types/components/ez-form/fieldbuilder/FieldBuilder.d.ts +2 -0
  77. package/dist/types/components/ez-form/fieldbuilder/tpl/CheckBox.tpl.d.ts +3 -0
  78. package/dist/types/components/ez-form/fieldbuilder/tpl/ComboBox.tpl.d.ts +4 -0
  79. package/dist/types/components/ez-form/fieldbuilder/tpl/DateInput.tpl.d.ts +8 -0
  80. package/dist/types/components/ez-form/fieldbuilder/tpl/FileInput.tpl.d.ts +4 -0
  81. package/dist/types/components/ez-form/fieldbuilder/tpl/NumberInput.tpl.d.ts +8 -0
  82. package/dist/types/components/ez-form/fieldbuilder/tpl/SearchInput.tpl.d.ts +4 -0
  83. package/dist/types/components/ez-form/fieldbuilder/tpl/TextArea.tpl.d.ts +4 -0
  84. package/dist/types/components/ez-form/fieldbuilder/tpl/TextInput.tpl.d.ts +4 -0
  85. package/dist/types/components/ez-form/store/form.slice.d.ts +24 -0
  86. package/dist/types/components/ez-form/structure/FormItem.d.ts +9 -0
  87. package/dist/types/components/ez-form/structure/FormSheet.d.ts +9 -0
  88. package/dist/types/components/ez-form/structure/FormSheetMetadata.d.ts +27 -0
  89. package/dist/types/components/test-du/test-du.d.ts +8 -2
  90. package/dist/types/components.d.ts +9 -63
  91. package/package.json +2 -2
  92. package/react/components.d.ts +0 -2
  93. package/react/components.js +0 -2
  94. package/react/components.js.map +1 -1
  95. package/dist/cjs/ApplicationUtils-d1c1db56.js +0 -35
  96. package/dist/cjs/DataUnit-fdd7c70e.js +0 -474
  97. package/dist/cjs/DateUtils-716769e0.js +0 -46
  98. package/dist/cjs/ez-calendar.cjs.entry.js +0 -217
  99. package/dist/cjs/ez-collapsible-box_6.cjs.entry.js +0 -634
  100. package/dist/cjs/ez-combo-box.cjs.entry.js +0 -254
  101. package/dist/cjs/ez-date-time-input.cjs.entry.js +0 -133
  102. package/dist/cjs/ez-form.cjs.entry.js +0 -1838
  103. package/dist/cjs/ez-number-input.cjs.entry.js +0 -74
  104. package/dist/cjs/form-metadata.cjs.entry.js +0 -129
  105. package/dist/collection/components/ez-form/assets/trash-can-outline.svg +0 -3
  106. package/dist/collection/components/ez-form/store/Form.actions.js +0 -132
  107. package/dist/collection/components/ez-form/store/Form.reducer.js +0 -194
  108. package/dist/collection/components/ez-form/store/Form.selectors.js +0 -44
  109. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +0 -301
  110. package/dist/collection/components/ez-form/subcomponents/FormMetadata.js +0 -8
  111. package/dist/collection/components/ez-form/subcomponents/css/place-holder.css +0 -24
  112. package/dist/collection/components/ez-form/subcomponents/form-metadata.js +0 -227
  113. package/dist/collection/components/ez-form/subcomponents/place-holder.js +0 -14
  114. package/dist/collection/components/ez-form/subcomponents/structure/Field.js +0 -95
  115. package/dist/collection/components/ez-form/subcomponents/structure/FieldSet.js +0 -27
  116. package/dist/collection/components/ez-form/subcomponents/structure/FormSheet.js +0 -41
  117. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +0 -37
  118. package/dist/esm/ApplicationUtils-01280a9d.js +0 -33
  119. package/dist/esm/DataUnit-1cd45202.js +0 -464
  120. package/dist/esm/DateUtils-0a1bbd7a.js +0 -44
  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-date-time-input.entry.js +0 -129
  125. package/dist/esm/ez-form.entry.js +0 -1834
  126. package/dist/esm/ez-number-input.entry.js +0 -70
  127. package/dist/esm/form-metadata.entry.js +0 -125
  128. package/dist/ezui/assets/trash-can-outline.svg +0 -3
  129. package/dist/ezui/p-14bee38e.entry.js +0 -1
  130. package/dist/ezui/p-37a611ea.js +0 -1
  131. package/dist/ezui/p-3a09c678.entry.js +0 -1
  132. package/dist/ezui/p-43c15c94.entry.js +0 -1
  133. package/dist/ezui/p-7107d7ef.js +0 -1
  134. package/dist/ezui/p-72ff3c95.entry.js +0 -1
  135. package/dist/ezui/p-88f45a83.entry.js +0 -1
  136. package/dist/ezui/p-8f4851a6.js +0 -1
  137. package/dist/ezui/p-9dfd537e.js +0 -1
  138. package/dist/ezui/p-a0331955.entry.js +0 -1
  139. package/dist/ezui/p-a15093e3.entry.js +0 -1
  140. package/dist/ezui/p-a19f2af3.entry.js +0 -1
  141. package/dist/ezui/p-c89629eb.js +0 -1
  142. package/dist/ezui/p-da929c01.js +0 -1
  143. package/dist/types/components/ez-form/store/Form.actions.d.ts +0 -111
  144. package/dist/types/components/ez-form/store/Form.reducer.d.ts +0 -20
  145. package/dist/types/components/ez-form/store/Form.selectors.d.ts +0 -14
  146. package/dist/types/components/ez-form/subcomponents/DataUnit.d.ts +0 -91
  147. package/dist/types/components/ez-form/subcomponents/FormMetadata.d.ts +0 -24
  148. package/dist/types/components/ez-form/subcomponents/form-metadata.d.ts +0 -16
  149. package/dist/types/components/ez-form/subcomponents/place-holder.d.ts +0 -3
  150. package/dist/types/components/ez-form/subcomponents/structure/Field.d.ts +0 -11
  151. package/dist/types/components/ez-form/subcomponents/structure/FieldSet.d.ts +0 -13
  152. package/dist/types/components/ez-form/subcomponents/structure/FormSheet.d.ts +0 -14
  153. package/dist/types/components/ez-form/subcomponents/structure/NavigationBar.d.ts +0 -19
@@ -1,253 +1,101 @@
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);
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;
128
68
  }
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());
69
+ processMetadata() {
70
+ if (!this.isStatic()) {
71
+ const metadata = this.config && this.config.length > 0 ? buildFromConfig(this.config, this.dataUnit) : buildFromDataUnit(this.dataUnit);
72
+ this._store.dispatch(loadMetadata(metadata));
168
73
  }
169
74
  }
170
- parseExecutor(executor) {
171
- if (executor) {
172
- return executor instanceof Function ? executor : eval(executor);
173
- }
174
- return null;
75
+ isStatic() {
76
+ var _a;
77
+ return ((_a = this._staticFields) === null || _a === void 0 ? void 0 : _a.length) > 0;
175
78
  }
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
- }
79
+ componentWillLoad() {
80
+ if (this.dataUnit === undefined) {
81
+ this.dataUnit = new DataUnit("ez-form");
189
82
  }
190
- if (this._preparedMetadata === undefined) {
191
- if (this.metadata) {
192
- this.updateMetadata(this.metadata);
83
+ this.dataUnit.subscribe(action => {
84
+ if (action.type === Action.METADATA_LOADED) {
85
+ this.processMetadata();
193
86
  }
194
- else {
195
- this.loadMDFromElement((md) => this.updateMetadata(md));
196
- if (!this._preparedMetadata) {
197
- this.loadMDFromExecutor((md) => this.updateMetadata(md));
198
- }
199
- }
200
- }
87
+ });
88
+ this._dataBinder = new DataBinder(this.dataUnit);
89
+ this._store = createStore(formReducer);
90
+ this._store.subscribe(() => forceUpdate(this));
91
+ this._staticFields = Array.from(this._element.querySelectorAll("[data-field-name]"));
92
+ this.processMetadata();
201
93
  }
202
94
  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;
95
+ this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")));
243
96
  }
244
97
  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
- }
98
+ return (h(Host, null, this.isStatic() ? null : this.getDynamicContent()));
251
99
  }
252
100
  static get is() { return "ez-form"; }
253
101
  static get originalStyleUrls() { return {
@@ -256,101 +104,17 @@ export class EzForm {
256
104
  static get styleUrls() { return {
257
105
  "$": ["ez-form.css"]
258
106
  }; }
259
- static get assetsDirs() { return ["assets"]; }
260
107
  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,
108
+ "dataUnit": {
109
+ "type": "unknown",
110
+ "mutable": true,
348
111
  "complexType": {
349
- "original": "string | Function",
350
- "resolved": "Function | string",
112
+ "original": "DataUnit",
113
+ "resolved": "DataUnit",
351
114
  "references": {
352
- "Function": {
353
- "location": "global"
115
+ "DataUnit": {
116
+ "location": "import",
117
+ "path": "@sankhyalabs/core"
354
118
  }
355
119
  }
356
120
  },
@@ -359,40 +123,20 @@ export class EzForm {
359
123
  "docs": {
360
124
  "tags": [],
361
125
  "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
126
+ }
382
127
  },
383
- "metadata": {
128
+ "config": {
384
129
  "type": "unknown",
385
130
  "mutable": false,
386
131
  "complexType": {
387
- "original": "Array<Form>",
388
- "resolved": "Form[]",
132
+ "original": "Array<FieldConfig>",
133
+ "resolved": "FieldConfig[]",
389
134
  "references": {
390
135
  "Array": {
391
136
  "location": "global"
392
137
  },
393
- "Form": {
394
- "location": "import",
395
- "path": "./subcomponents/FormMetadata"
138
+ "FieldConfig": {
139
+ "location": "local"
396
140
  }
397
141
  }
398
142
  },
@@ -402,110 +146,55 @@ export class EzForm {
402
146
  "tags": [],
403
147
  "text": ""
404
148
  }
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
149
  }
459
150
  }; }
460
151
  static get methods() { return {
461
- "validate": {
152
+ "submit": {
462
153
  "complexType": {
463
- "signature": "() => Promise<boolean>",
154
+ "signature": "() => Promise<void>",
464
155
  "parameters": [],
465
156
  "references": {
466
157
  "Promise": {
467
158
  "location": "global"
468
159
  }
469
160
  },
470
- "return": "Promise<boolean>"
161
+ "return": "Promise<void>"
471
162
  },
472
163
  "docs": {
473
164
  "text": "",
474
165
  "tags": []
475
166
  }
476
167
  },
477
- "getChanges": {
168
+ "cancel": {
478
169
  "complexType": {
479
- "signature": "() => Promise<any[]>",
170
+ "signature": "() => Promise<void>",
480
171
  "parameters": [],
481
172
  "references": {
482
173
  "Promise": {
483
174
  "location": "global"
484
175
  }
485
176
  },
486
- "return": "Promise<any[]>"
177
+ "return": "Promise<void>"
487
178
  },
488
179
  "docs": {
489
180
  "text": "",
490
181
  "tags": []
491
182
  }
492
183
  },
493
- "changeFieldValue": {
184
+ "validate": {
494
185
  "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
- }],
186
+ "signature": "() => Promise<void>",
187
+ "parameters": [],
506
188
  "references": {
507
189
  "Promise": {
508
190
  "location": "global"
191
+ },
192
+ "Array": {
193
+ "location": "global"
194
+ },
195
+ "Record": {
196
+ "location": "import",
197
+ "path": "@sankhyalabs/core"
509
198
  }
510
199
  },
511
200
  "return": "Promise<void>"
@@ -516,9 +205,5 @@ export class EzForm {
516
205
  }
517
206
  }
518
207
  }; }
519
- static get elementRef() { return "_host"; }
520
- static get watchers() { return [{
521
- "propName": "metadata",
522
- "methodName": "cleanPreparedMetadata"
523
- }]; }
208
+ static get elementRef() { return "_element"; }
524
209
  }
@@ -0,0 +1,46 @@
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, buildTimeDate } 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.DATETIME, buildTimeDate);
19
+ uiBuilders.set(UserInterface.DECIMALNUMBER, buildDecimal);
20
+ uiBuilders.set(UserInterface.INTEGERNUMBER, buildInteger);
21
+ export const buildField = (field) => {
22
+ const descriptor = field.descriptor;
23
+ const config = Object.assign({}, field.config);
24
+ let builder;
25
+ let props;
26
+ if (descriptor) {
27
+ builder = uiBuilders.get(descriptor.userInterface);
28
+ if (!config.label) {
29
+ config.label = descriptor.label;
30
+ }
31
+ if (!config.name) {
32
+ config.name = descriptor.name;
33
+ }
34
+ if (config.required === undefined) {
35
+ config.required = descriptor.required;
36
+ }
37
+ props = descriptor.properties;
38
+ }
39
+ if (config.required) {
40
+ config.label = `* ${config.label} (obrigatório)`;
41
+ }
42
+ if (!builder) {
43
+ builder = buildTextInput;
44
+ }
45
+ return builder(config, props);
46
+ };
@@ -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
+ }