@sankhyalabs/sankhyablocks 1.1.22 → 1.1.25
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.
- package/dist/cjs/ApplicationUtils-05b74ee9.js +39 -0
- package/dist/cjs/AssetsUtils-7e3c38f9.js +24 -0
- package/dist/cjs/CSSVarsUtils-75ca9c64.js +19 -0
- package/dist/cjs/ez-action-chip.cjs.entry.js +27 -0
- package/dist/cjs/ez-application.cjs.entry.js +26 -0
- package/dist/cjs/ez-button_4.cjs.entry.js +660 -0
- package/dist/cjs/ez-calendar.cjs.entry.js +223 -0
- package/dist/cjs/ez-collapsible-box.cjs.entry.js +47 -0
- package/dist/cjs/ez-combo-box.cjs.entry.js +278 -0
- package/dist/cjs/ez-date-input.cjs.entry.js +102 -0
- package/dist/cjs/ez-date-time-input.cjs.entry.js +145 -0
- package/dist/cjs/ez-dialog.cjs.entry.js +89 -0
- package/dist/cjs/ez-form.cjs.entry.js +463 -0
- package/dist/cjs/ez-grid.cjs.entry.js +647 -0
- package/dist/cjs/ez-icon.cjs.entry.js +41 -0
- package/dist/cjs/ez-label-chip.cjs.entry.js +104 -0
- package/dist/cjs/ez-modal_2.cjs.entry.js +316 -0
- package/dist/cjs/ez-number-input.cjs.entry.js +86 -0
- package/dist/cjs/ez-popover.cjs.entry.js +120 -0
- package/dist/cjs/ez-popup.cjs.entry.js +48 -0
- package/dist/cjs/ez-search.cjs.entry.js +64 -0
- package/dist/cjs/ez-tabselector.cjs.entry.js +198 -0
- package/dist/cjs/ez-text-area.cjs.entry.js +114 -0
- package/dist/cjs/ez-text-input.cjs.entry.js +201 -0
- package/dist/cjs/ez-time-input.cjs.entry.js +118 -0
- package/dist/cjs/ez-toast.cjs.entry.js +44 -0
- package/dist/cjs/ez-upload.cjs.entry.js +356 -0
- package/dist/cjs/index-682c98b2.js +1771 -0
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/sankhyablocks.cjs.js +3 -3
- package/dist/cjs/snk-application.cjs.entry.js +319 -1275
- package/dist/cjs/test-du.cjs.entry.js +76 -0
- package/dist/collection/collection-manifest.json +37 -2
- package/dist/collection/components/snk-application/snk-application.js +8 -4
- package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +16 -9
- package/dist/{collection/temp → components}/ApplicationUtils.js +37 -31
- package/dist/components/AssetsUtils.js +22 -0
- package/dist/components/CSSVarsUtils.js +17 -0
- package/dist/components/ez-action-chip.js +44 -0
- package/dist/components/ez-application.js +39 -0
- package/dist/components/ez-button.js +6 -0
- package/dist/components/ez-button2.js +105 -0
- package/dist/components/ez-calendar.js +6 -0
- package/dist/components/ez-calendar2.js +242 -0
- package/dist/components/ez-check.js +6 -0
- package/dist/components/ez-check2.js +94 -0
- package/dist/components/ez-collapsible-box.js +67 -0
- package/dist/components/ez-combo-box.js +6 -0
- package/dist/components/ez-combo-box2.js +311 -0
- package/dist/components/ez-date-input.js +135 -0
- package/dist/components/ez-date-time-input.js +179 -0
- package/dist/components/ez-dialog.js +124 -0
- package/dist/components/ez-form.js +6 -0
- package/dist/components/ez-form2.js +485 -0
- package/dist/components/ez-grid.js +738 -0
- package/dist/components/ez-icon.js +6 -0
- package/dist/components/ez-icon2.js +56 -0
- package/dist/components/ez-label-chip.js +125 -0
- package/dist/components/ez-list.js +6 -0
- package/dist/components/ez-list2.js +523 -0
- package/dist/components/ez-modal.js +6 -0
- package/dist/components/ez-modal2.js +82 -0
- package/dist/components/ez-number-input.js +115 -0
- package/dist/components/ez-popover.js +145 -0
- package/dist/components/ez-popup.js +67 -0
- package/dist/components/ez-search.js +100 -0
- package/dist/components/ez-tabselector.js +6 -0
- package/dist/components/ez-tabselector2.js +213 -0
- package/dist/components/ez-text-area.js +137 -0
- package/dist/components/ez-text-input.js +6 -0
- package/dist/components/ez-text-input2.js +223 -0
- package/dist/components/ez-time-input.js +153 -0
- package/dist/components/ez-toast.js +64 -0
- package/dist/components/ez-upload.js +382 -0
- package/dist/components/grid-config.js +6 -0
- package/dist/components/grid-config2.js +318 -0
- package/dist/components/select-box.js +6 -0
- package/dist/components/select-box2.js +47 -0
- package/dist/components/snk-application.js +310 -1266
- package/dist/components/test-du.js +101 -0
- package/dist/esm/ApplicationUtils-e0b6d857.js +37 -0
- package/dist/esm/AssetsUtils-6e6624dc.js +22 -0
- package/dist/esm/CSSVarsUtils-0787c3f3.js +17 -0
- package/dist/esm/ez-action-chip.entry.js +23 -0
- package/dist/esm/ez-application.entry.js +22 -0
- package/dist/esm/ez-button_4.entry.js +653 -0
- package/dist/esm/ez-calendar.entry.js +219 -0
- package/dist/esm/ez-collapsible-box.entry.js +43 -0
- package/dist/esm/ez-combo-box.entry.js +274 -0
- package/dist/esm/ez-date-input.entry.js +98 -0
- package/dist/esm/ez-date-time-input.entry.js +141 -0
- package/dist/esm/ez-dialog.entry.js +85 -0
- package/dist/esm/ez-form.entry.js +459 -0
- package/dist/esm/ez-grid.entry.js +643 -0
- package/dist/esm/ez-icon.entry.js +37 -0
- package/dist/esm/ez-label-chip.entry.js +100 -0
- package/dist/esm/ez-modal_2.entry.js +311 -0
- package/dist/esm/ez-number-input.entry.js +82 -0
- package/dist/esm/ez-popover.entry.js +116 -0
- package/dist/esm/ez-popup.entry.js +44 -0
- package/dist/esm/ez-search.entry.js +60 -0
- package/dist/esm/ez-tabselector.entry.js +194 -0
- package/dist/esm/ez-text-area.entry.js +110 -0
- package/dist/esm/ez-text-input.entry.js +197 -0
- package/dist/esm/ez-time-input.entry.js +114 -0
- package/dist/esm/ez-toast.entry.js +40 -0
- package/dist/esm/ez-upload.entry.js +352 -0
- package/dist/esm/index-35088a3f.js +1740 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/sankhyablocks.js +3 -3
- package/dist/esm/snk-application.entry.js +311 -1267
- package/dist/esm/test-du.entry.js +72 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-action-chip/ez-action-chip.css +67 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-application/ez-application.css +3 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-button/ez-button.css +180 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-calendar/ez-calendar.css +319 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-check/ez-check.css +327 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-collapsible-box/ez-collapsible-box.css +162 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-combo-box/ez-combo-box.css +217 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-input/ez-date-input.css +49 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-time-input/ez-date-time-input.css +44 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-dialog/ez-dialog.css +527 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-form/ez-form.css +5 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/ez-grid.css +31 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/gridconfig/grid-config.css +129 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/select-box/select-box.css +10 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-icon/ez-icon.css +176 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-label-chip/ez-label-chip.css +139 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-list/ez-list.css +335 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-modal/ez-modal.css +358 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-number-input/ez-number-input.css +4 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popover/ez-popover.css +44 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popup/ez-popup.css +405 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-search/ez-search.css +3 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-tabselector/ez-tabselector.css +138 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-area/ez-text-area.css +165 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-input/ez-text-input.css +196 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-time-input/ez-time-input.css +10 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-toast/ez-toast.css +127 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-upload/ez-upload.css +568 -0
- package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/test-du/test-du.css +3 -0
- package/dist/sankhyablocks/p-0183d259.entry.js +1 -0
- package/dist/sankhyablocks/p-01f23a70.entry.js +1 -0
- package/dist/sankhyablocks/p-07c32f68.entry.js +1 -0
- package/dist/sankhyablocks/p-0f90499d.entry.js +1 -0
- package/dist/sankhyablocks/p-105724a3.entry.js +1 -0
- package/dist/sankhyablocks/p-2ac02d48.entry.js +1 -0
- package/dist/sankhyablocks/p-35364a97.entry.js +1 -0
- package/dist/sankhyablocks/p-3f6aa9a7.entry.js +1 -0
- package/dist/sankhyablocks/p-5f9af495.entry.js +1 -0
- package/dist/sankhyablocks/p-60967cf0.js +1 -0
- package/dist/sankhyablocks/p-6ce33b60.entry.js +57 -0
- package/dist/sankhyablocks/p-70ad6c16.entry.js +1 -0
- package/dist/sankhyablocks/p-710bfffe.entry.js +1 -0
- package/dist/sankhyablocks/p-735440c1.entry.js +1 -0
- package/dist/sankhyablocks/p-811b4b9d.js +1 -0
- package/dist/sankhyablocks/p-813fe4f7.js +1 -0
- package/dist/sankhyablocks/p-85a9446b.js +2 -0
- package/dist/sankhyablocks/p-89a1100f.entry.js +1 -0
- package/dist/sankhyablocks/p-8b543003.entry.js +1 -0
- package/dist/sankhyablocks/p-9750632b.entry.js +1 -0
- package/dist/sankhyablocks/p-a96272f7.entry.js +1 -0
- package/dist/sankhyablocks/p-ac8842e5.entry.js +1 -0
- package/dist/sankhyablocks/p-ba64cc41.entry.js +1 -0
- package/dist/sankhyablocks/p-c1ede043.entry.js +1 -0
- package/dist/sankhyablocks/p-d90ebb85.entry.js +1 -0
- package/dist/sankhyablocks/p-e17dfaae.entry.js +1 -0
- package/dist/sankhyablocks/p-e5355a29.entry.js +1 -0
- package/dist/sankhyablocks/p-ef04b633.entry.js +1 -0
- package/dist/sankhyablocks/p-f6db07fb.entry.js +1 -0
- package/dist/sankhyablocks/p-fcd9bd92.entry.js +1 -0
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/dist/types/components/snk-application/snk-application.d.ts +1 -1
- package/dist/types/components.d.ts +7 -3
- package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +1 -0
- package/package.json +12 -7
- package/react/components.d.ts +29 -0
- package/react/components.js +29 -0
- package/react/components.js.map +1 -1
- package/dist/cjs/index-20a7d705.js +0 -733
- package/dist/esm/index-8d3572c4.js +0 -707
- package/dist/sankhyablocks/p-5fa264b9.js +0 -1
- package/dist/sankhyablocks/p-fe95f2c4.entry.js +0 -57
- package/dist/types/temp/ApplicationUtils.d.ts +0 -7
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { h, r as registerInstance, f as forceUpdate, H as Host, g as getElement } from './index-35088a3f.js';
|
|
2
|
+
import { UserInterface, ApplicationContext, Action, DataUnitAction, DataUnit } from '@sankhyalabs/core';
|
|
3
|
+
import { createStore } from 'redux';
|
|
4
|
+
import { A as ApplicationUtils } from './ApplicationUtils-e0b6d857.js';
|
|
5
|
+
|
|
6
|
+
const buildTextArea = ({ name, label, readOnly }) => {
|
|
7
|
+
return (h("div", { class: "col col--sd-12 padding-horizontal--small", key: name },
|
|
8
|
+
h("ez-text-area", { enabled: !readOnly, label: label, "data-field-name": name })));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const buildTextInput = ({ name, label }) => {
|
|
12
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
13
|
+
h("ez-text-input", { label: label, "data-field-name": name, key: name })));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const buildSwitch = (fieldConfig) => {
|
|
17
|
+
return buildField$1(fieldConfig.name, fieldConfig.label, fieldConfig.readOnly, true);
|
|
18
|
+
};
|
|
19
|
+
const buildCheckBox = (fieldConfig) => {
|
|
20
|
+
return buildField$1(fieldConfig.name, fieldConfig.label, fieldConfig.readOnly, false);
|
|
21
|
+
};
|
|
22
|
+
function buildField$1(fieldName, fieldLabel, readOnly, switchMode = false) {
|
|
23
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 align--middle padding-horizontal--small padding-bottom--large" },
|
|
24
|
+
h("ez-check", { enabled: !readOnly, label: fieldLabel, mode: switchMode ? "switch" : "regular", "data-field-name": fieldName, key: fieldName })));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const buildComboBox = ({ name, label, readOnly }, properties) => {
|
|
28
|
+
const prop = properties === null || properties === void 0 ? void 0 : properties.options;
|
|
29
|
+
let options;
|
|
30
|
+
if (typeof prop === "string") {
|
|
31
|
+
const parsed = JSON.parse(prop);
|
|
32
|
+
options = Object.keys(parsed).map(key => { return { value: key, label: parsed[key] }; });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
options = prop;
|
|
36
|
+
}
|
|
37
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
38
|
+
h("ez-combo-box", { enabled: !readOnly, label: label, "data-field-name": name, key: name, options: options })));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const buildSearch = ({ name, label, readOnly }) => {
|
|
42
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
43
|
+
h("ez-search", { enabled: !readOnly, label: label, "data-field-name": name, key: name })));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const buildFile = ({ name, label, readOnly }) => {
|
|
47
|
+
return (h("div", { class: "col col--sd-12 padding-horizontal--small" },
|
|
48
|
+
h("ez-upload", { enabled: !readOnly, label: label, urlUpload: "", requestHeaders: "", maxFiles: 10, "data-field-name": name, key: name })));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const buildDate = ({ name, label, readOnly }) => {
|
|
52
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
53
|
+
h("ez-date-input", { enabled: !readOnly, label: label, "data-field-name": name, key: name })));
|
|
54
|
+
};
|
|
55
|
+
const buildTime = ({ name, label }) => {
|
|
56
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
57
|
+
h("ez-time-input", { label: label, "data-field-name": name, key: name })));
|
|
58
|
+
};
|
|
59
|
+
const buildTimeDate = ({ name, label }) => {
|
|
60
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
61
|
+
h("ez-date-time-input", { label: label, "data-field-name": name, key: name })));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const buildDecimal = ({ name, label, readOnly }, properties) => {
|
|
65
|
+
const precision = Number((properties === null || properties === void 0 ? void 0 : properties.precision) || 2);
|
|
66
|
+
const prettyPrecision = Number((properties === null || properties === void 0 ? void 0 : properties.prettyPrecision) || precision);
|
|
67
|
+
return buildNumeric(name, label, readOnly, precision, prettyPrecision);
|
|
68
|
+
};
|
|
69
|
+
const buildInteger = ({ name, label, readOnly }) => {
|
|
70
|
+
return buildNumeric(name, label, readOnly, 0, 0);
|
|
71
|
+
};
|
|
72
|
+
function buildNumeric(fieldName, fieldLabel, readOnly, precision, prettyPrecision) {
|
|
73
|
+
return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
74
|
+
h("ez-number-input", { enabled: !readOnly, label: fieldLabel, precision: precision, prettyPrecision: prettyPrecision, "data-field-name": fieldName, key: fieldName })));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const uiBuilders = new Map();
|
|
78
|
+
uiBuilders.set(UserInterface.LONGTEXT, buildTextArea);
|
|
79
|
+
uiBuilders.set(UserInterface.CHECKBOX, buildCheckBox);
|
|
80
|
+
uiBuilders.set(UserInterface.SWITCH, buildSwitch);
|
|
81
|
+
uiBuilders.set(UserInterface.OPTIONSELECTOR, buildComboBox);
|
|
82
|
+
uiBuilders.set(UserInterface.SEARCH, buildSearch);
|
|
83
|
+
uiBuilders.set(UserInterface.FILE, buildFile);
|
|
84
|
+
uiBuilders.set(UserInterface.DATE, buildDate);
|
|
85
|
+
uiBuilders.set(UserInterface.TIME, buildTime);
|
|
86
|
+
uiBuilders.set(UserInterface.DATETIME, buildTimeDate);
|
|
87
|
+
uiBuilders.set(UserInterface.DECIMALNUMBER, buildDecimal);
|
|
88
|
+
uiBuilders.set(UserInterface.INTEGERNUMBER, buildInteger);
|
|
89
|
+
const buildField = (field) => {
|
|
90
|
+
const descriptor = field.descriptor;
|
|
91
|
+
const config = Object.assign({}, field.config);
|
|
92
|
+
let builder;
|
|
93
|
+
let props;
|
|
94
|
+
if (descriptor) {
|
|
95
|
+
if (!config.label) {
|
|
96
|
+
config.label = descriptor.label;
|
|
97
|
+
}
|
|
98
|
+
if (!config.name) {
|
|
99
|
+
config.name = descriptor.name;
|
|
100
|
+
}
|
|
101
|
+
if (config.required === undefined) {
|
|
102
|
+
config.required = descriptor.required;
|
|
103
|
+
}
|
|
104
|
+
if (config.readOnly === undefined) {
|
|
105
|
+
config.readOnly = descriptor.readOnly;
|
|
106
|
+
}
|
|
107
|
+
props = descriptor.properties;
|
|
108
|
+
builder = uiBuilders.get(descriptor.userInterface);
|
|
109
|
+
}
|
|
110
|
+
if (config.required) {
|
|
111
|
+
config.label = `* ${config.label} (obrigatório)`;
|
|
112
|
+
}
|
|
113
|
+
if (!builder) {
|
|
114
|
+
builder = buildTextInput;
|
|
115
|
+
}
|
|
116
|
+
return builder(config, props);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const FormItem = ({ source }) => {
|
|
120
|
+
if ("items" in source) {
|
|
121
|
+
const fieldSet = source;
|
|
122
|
+
return h("ez-collapsible-box", { label: source.label }, fieldSet.items.map(fi => buildField(fi)));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return buildField(source);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const FormSheet = ({ store, source }) => {
|
|
130
|
+
return (h("div", { class: "box__container" },
|
|
131
|
+
h("div", { class: "row padding-vertical--small" }, source.items.map(item => h(FormItem, { store: store, source: item })))));
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
class FormMetadata {
|
|
135
|
+
constructor() {
|
|
136
|
+
this._sheets = new Map();
|
|
137
|
+
this._requiredFields = [];
|
|
138
|
+
this._cleanOnCopyFields = [];
|
|
139
|
+
}
|
|
140
|
+
getSheet(name) {
|
|
141
|
+
return this._sheets.get(name);
|
|
142
|
+
}
|
|
143
|
+
getAllSheets() {
|
|
144
|
+
return this._sheets;
|
|
145
|
+
}
|
|
146
|
+
addSheet(sheet) {
|
|
147
|
+
this._sheets.set(sheet.name, sheet);
|
|
148
|
+
this._requiredFields = this._requiredFields.concat(sheet.requiredFields);
|
|
149
|
+
this._cleanOnCopyFields = this._cleanOnCopyFields.concat(sheet.cleanOnCopyFields);
|
|
150
|
+
}
|
|
151
|
+
getRequiredFields() {
|
|
152
|
+
return this._requiredFields;
|
|
153
|
+
}
|
|
154
|
+
getCleanOnCopyFields() {
|
|
155
|
+
return this._cleanOnCopyFields;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const buildFromDataUnit = (dataUnit) => {
|
|
159
|
+
var _a;
|
|
160
|
+
const unitMD = dataUnit.metadata;
|
|
161
|
+
const metadata = new FormMetadata();
|
|
162
|
+
if (unitMD) {
|
|
163
|
+
const visibleFields = (_a = unitMD.fields) === null || _a === void 0 ? void 0 : _a.filter(descriptor => descriptor.visible !== false);
|
|
164
|
+
metadata.addSheet({
|
|
165
|
+
label: unitMD.label,
|
|
166
|
+
name: unitMD.name,
|
|
167
|
+
items: visibleFields.map(descriptor => { return { descriptor }; }),
|
|
168
|
+
requiredFields: visibleFields
|
|
169
|
+
.filter(descriptor => descriptor.required)
|
|
170
|
+
.map(descriptor => descriptor.name),
|
|
171
|
+
cleanOnCopyFields: visibleFields
|
|
172
|
+
.filter(descriptor => { var _a; return (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy; })
|
|
173
|
+
.map(descriptor => descriptor.name)
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return metadata;
|
|
177
|
+
};
|
|
178
|
+
function getTabConfig(tab, sheets) {
|
|
179
|
+
const tabConfig = (typeof tab === "string" ? Array.from(sheets.keys()).find(t => t.label === tab) : tab);
|
|
180
|
+
return tabConfig || { label: tab, visible: true };
|
|
181
|
+
}
|
|
182
|
+
const buildFromConfig = (fields, dataUnit) => {
|
|
183
|
+
const sheets = new Map();
|
|
184
|
+
const requiredFields = [];
|
|
185
|
+
const cleanOnCopyFields = [];
|
|
186
|
+
fields.forEach(config => {
|
|
187
|
+
var _a;
|
|
188
|
+
if (config.visible !== false) {
|
|
189
|
+
const tabConfig = getTabConfig(config.tab || "Geral", sheets);
|
|
190
|
+
const descriptor = dataUnit.getField(config.name);
|
|
191
|
+
if (descriptor && tabConfig.visible) {
|
|
192
|
+
if (!sheets.has(tabConfig)) {
|
|
193
|
+
sheets.set(tabConfig, new Map());
|
|
194
|
+
}
|
|
195
|
+
const tabItens = sheets.get(tabConfig);
|
|
196
|
+
const isRequired = config.required === undefined ? descriptor.required : config.required;
|
|
197
|
+
if (isRequired) {
|
|
198
|
+
requiredFields.push(config.name);
|
|
199
|
+
}
|
|
200
|
+
const clearOnCopy = config.cleanOnCopy === undefined ? (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy : config.cleanOnCopy;
|
|
201
|
+
if (clearOnCopy) {
|
|
202
|
+
cleanOnCopyFields.push(config.name);
|
|
203
|
+
}
|
|
204
|
+
const fieldMD = { config, descriptor };
|
|
205
|
+
const group = config.group;
|
|
206
|
+
if (group) {
|
|
207
|
+
const key = `group::${group}`;
|
|
208
|
+
if (!tabItens.has(key)) {
|
|
209
|
+
tabItens.set(key, { label: group, items: [fieldMD] });
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
tabItens.get(key).items.push(fieldMD);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
tabItens.set(config.name, fieldMD);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
const metadata = new FormMetadata();
|
|
222
|
+
Array.from(sheets.entries())
|
|
223
|
+
.sort((a, b) => (a[0].order || 10000) - (b[0].order || 10000))
|
|
224
|
+
.forEach(([key, value]) => {
|
|
225
|
+
metadata.addSheet({
|
|
226
|
+
label: key.label,
|
|
227
|
+
name: key.label,
|
|
228
|
+
items: Array.from(value.values()),
|
|
229
|
+
requiredFields,
|
|
230
|
+
cleanOnCopyFields
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
return metadata;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const inicialState = {};
|
|
237
|
+
/////////////////////////////// REDUCERS ///////////////////////////////
|
|
238
|
+
function formReducer(state = inicialState, action) {
|
|
239
|
+
switch (action.type) {
|
|
240
|
+
case FormActions.METADATA_LOADED:
|
|
241
|
+
return Object.assign(Object.assign({}, state), { formMetadata: action.payload });
|
|
242
|
+
case FormActions.CHANGE_TAB:
|
|
243
|
+
return Object.assign(Object.assign({}, state), { currentSheet: action.payload });
|
|
244
|
+
default:
|
|
245
|
+
return state;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/////////////////////////////// ACTION CREATORS ///////////////////////////////
|
|
249
|
+
function loadMetadata(formMetadata) {
|
|
250
|
+
return {
|
|
251
|
+
type: FormActions.METADATA_LOADED,
|
|
252
|
+
payload: formMetadata
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function changeTab(currentSheet) {
|
|
256
|
+
return {
|
|
257
|
+
type: FormActions.CHANGE_TAB,
|
|
258
|
+
payload: currentSheet.tabKey
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/////////////////////////////// SELECTORS ///////////////////////////////
|
|
262
|
+
function selectFormMetadata(state) {
|
|
263
|
+
return state.formMetadata;
|
|
264
|
+
}
|
|
265
|
+
function selectCurrentSheet(state) {
|
|
266
|
+
return state.currentSheet ? state.formMetadata.getSheet(state.currentSheet) : Array.from(state.formMetadata.getAllSheets().values())[0];
|
|
267
|
+
}
|
|
268
|
+
/////////////////////////////// TYPES ///////////////////////////////
|
|
269
|
+
var FormActions;
|
|
270
|
+
(function (FormActions) {
|
|
271
|
+
FormActions["METADATA_LOADED"] = "FORM/METADATA_LOADED";
|
|
272
|
+
FormActions["CHANGE_TAB"] = "FORM/CHANGE_TAB";
|
|
273
|
+
})(FormActions || (FormActions = {}));
|
|
274
|
+
|
|
275
|
+
class DataBinder {
|
|
276
|
+
constructor(dataUnit) {
|
|
277
|
+
this._fields = new Map();
|
|
278
|
+
this._dataUnit = dataUnit;
|
|
279
|
+
this._dataUnit.subscribe(_action => {
|
|
280
|
+
var _a;
|
|
281
|
+
(_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
|
|
282
|
+
this.updateValue(field.fieldName, field.field);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
bind(fields) {
|
|
287
|
+
fields.forEach(fieldElement => {
|
|
288
|
+
const fieldName = fieldElement.dataset.fieldName;
|
|
289
|
+
this.updateBind(fieldName, fieldElement);
|
|
290
|
+
this.updateValue(fieldName, fieldElement);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
updateValue(fieldName, field) {
|
|
294
|
+
field["value"] = this._dataUnit.getFieldValue(fieldName);
|
|
295
|
+
}
|
|
296
|
+
updateBind(fieldName, field) {
|
|
297
|
+
const oldBind = this._fields.get(fieldName);
|
|
298
|
+
if (oldBind) {
|
|
299
|
+
oldBind.destroy();
|
|
300
|
+
}
|
|
301
|
+
this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
|
|
302
|
+
this.bindSearchOptionsLoader(fieldName, field);
|
|
303
|
+
}
|
|
304
|
+
setFieldValue(fieldName, newValue) {
|
|
305
|
+
if (this._dataUnit.records.length === 0) {
|
|
306
|
+
this._dataUnit.addRecord();
|
|
307
|
+
}
|
|
308
|
+
this._dataUnit.setFieldValue(fieldName, newValue);
|
|
309
|
+
}
|
|
310
|
+
bindSearchOptionsLoader(fieldName, field) {
|
|
311
|
+
if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] === undefined) {
|
|
312
|
+
const loader = ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
|
|
313
|
+
if (loader) {
|
|
314
|
+
field["optionLoader"] = (arg) => {
|
|
315
|
+
return loader(arg, fieldName, this._dataUnit);
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
class Bind {
|
|
322
|
+
destroy() {
|
|
323
|
+
this.field.removeEventListener(this.eventName, this.eventListener);
|
|
324
|
+
}
|
|
325
|
+
static create(fieldName, field, callback) {
|
|
326
|
+
const b = new Bind();
|
|
327
|
+
b.fieldName = fieldName;
|
|
328
|
+
b.field = field;
|
|
329
|
+
//FIXME: Verificar se o field é um EzField
|
|
330
|
+
b.eventListener = (evt) => { callback(fieldName, evt.detail); };
|
|
331
|
+
b.eventName = "ezChange";
|
|
332
|
+
b.field.addEventListener(b.eventName, b.eventListener);
|
|
333
|
+
return b;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const ezFormCss = "ez-form{display:flex;flex-direction:column;width:100%}";
|
|
338
|
+
|
|
339
|
+
const EzForm = class {
|
|
340
|
+
constructor(hostRef) {
|
|
341
|
+
registerInstance(this, hostRef);
|
|
342
|
+
}
|
|
343
|
+
submit() {
|
|
344
|
+
return Promise.resolve();
|
|
345
|
+
}
|
|
346
|
+
cancel() {
|
|
347
|
+
return Promise.resolve();
|
|
348
|
+
}
|
|
349
|
+
validate() {
|
|
350
|
+
return new Promise((accept, reject) => {
|
|
351
|
+
const metadata = selectFormMetadata(this._store.getState());
|
|
352
|
+
const requiredFields = this._staticFields
|
|
353
|
+
.filter(f => f.dataset.required)
|
|
354
|
+
.map(f => f.dataset.fieldName)
|
|
355
|
+
.concat(metadata.getRequiredFields());
|
|
356
|
+
const records = this.dataUnit.records;
|
|
357
|
+
for (let i = 0; i < records.length; i++) {
|
|
358
|
+
if (!this.validateRequired(requiredFields, records[i])) {
|
|
359
|
+
reject();
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
accept();
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
configChanged() {
|
|
367
|
+
this.processMetadata();
|
|
368
|
+
}
|
|
369
|
+
validateRequired(requiredFields, record) {
|
|
370
|
+
const invalidFields = [];
|
|
371
|
+
requiredFields.forEach(field => {
|
|
372
|
+
const value = record[field];
|
|
373
|
+
const fieldElem = this._element.querySelector(`[data-field-name=${field}]`);
|
|
374
|
+
if (value === null || value === undefined || value === "") {
|
|
375
|
+
invalidFields.push(field);
|
|
376
|
+
fieldElem["errorMessage"] = "Essa informação é obrigatória";
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
fieldElem["errorMessage"] = "";
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
const isValid = invalidFields.length === 0;
|
|
383
|
+
if (!isValid) {
|
|
384
|
+
ApplicationUtils.info("Há pelo menos um campo obrigatório não preenchido.");
|
|
385
|
+
}
|
|
386
|
+
return isValid;
|
|
387
|
+
}
|
|
388
|
+
getDynamicContent() {
|
|
389
|
+
var _a;
|
|
390
|
+
const formMD = selectFormMetadata(this._store.getState());
|
|
391
|
+
if (!formMD)
|
|
392
|
+
return null;
|
|
393
|
+
const currentSheet = selectCurrentSheet((_a = this._store) === null || _a === void 0 ? void 0 : _a.getState());
|
|
394
|
+
if (!currentSheet) {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
const allSheets = Array.from(formMD.getAllSheets().values());
|
|
398
|
+
const result = [];
|
|
399
|
+
if (allSheets.length > 1) {
|
|
400
|
+
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 }))));
|
|
401
|
+
}
|
|
402
|
+
result.push(h(FormSheet, { store: this._store, source: currentSheet }));
|
|
403
|
+
return result;
|
|
404
|
+
}
|
|
405
|
+
processMetadata() {
|
|
406
|
+
if (!this.isStatic()) {
|
|
407
|
+
const metadata = this.config && this.config.length > 0 ? buildFromConfig(this.config, this.dataUnit) : buildFromDataUnit(this.dataUnit);
|
|
408
|
+
this._store.dispatch(loadMetadata(metadata));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
isStatic() {
|
|
412
|
+
var _a;
|
|
413
|
+
return ((_a = this._staticFields) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
414
|
+
}
|
|
415
|
+
interceptAction(action) {
|
|
416
|
+
if (action.type === Action.RECORDS_COPIED) {
|
|
417
|
+
const metadata = selectFormMetadata(this._store.getState());
|
|
418
|
+
const cleanFields = metadata.getCleanOnCopyFields();
|
|
419
|
+
if (cleanFields) {
|
|
420
|
+
const records = action.payload;
|
|
421
|
+
return new DataUnitAction(Action.RECORDS_COPIED, records.map(record => {
|
|
422
|
+
const newRecord = Object.assign({}, record);
|
|
423
|
+
cleanFields.forEach(fieldName => delete newRecord[fieldName]);
|
|
424
|
+
return newRecord;
|
|
425
|
+
}));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return action;
|
|
429
|
+
}
|
|
430
|
+
componentWillLoad() {
|
|
431
|
+
if (this.dataUnit === undefined) {
|
|
432
|
+
this.dataUnit = new DataUnit("ez-form");
|
|
433
|
+
}
|
|
434
|
+
this.dataUnit.addInterceptor(this);
|
|
435
|
+
this.dataUnit.subscribe(action => {
|
|
436
|
+
if (action.type === Action.METADATA_LOADED) {
|
|
437
|
+
this.processMetadata();
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
this._dataBinder = new DataBinder(this.dataUnit);
|
|
441
|
+
this._store = createStore(formReducer);
|
|
442
|
+
this._store.subscribe(() => forceUpdate(this));
|
|
443
|
+
this._staticFields = Array.from(this._element.querySelectorAll("[data-field-name]"));
|
|
444
|
+
this.processMetadata();
|
|
445
|
+
}
|
|
446
|
+
componentDidRender() {
|
|
447
|
+
this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")));
|
|
448
|
+
}
|
|
449
|
+
render() {
|
|
450
|
+
return (h(Host, null, this.isStatic() ? null : this.getDynamicContent()));
|
|
451
|
+
}
|
|
452
|
+
get _element() { return getElement(this); }
|
|
453
|
+
static get watchers() { return {
|
|
454
|
+
"config": ["configChanged"]
|
|
455
|
+
}; }
|
|
456
|
+
};
|
|
457
|
+
EzForm.style = ezFormCss;
|
|
458
|
+
|
|
459
|
+
export { EzForm as ez_form };
|