@sankhyalabs/sankhyablocks 1.1.24 → 1.1.28
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/_commonjsHelpers-537d719a.js +20 -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 +785 -0
- package/dist/cjs/ez-grid.cjs.entry.js +110485 -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 +2 -2
- package/dist/cjs/sankhyablocks.cjs.js +2 -2
- package/dist/cjs/snk-application.cjs.entry.js +49 -99
- package/dist/cjs/test-du.cjs.entry.js +76 -0
- package/dist/collection/collection-manifest.json +36 -1
- package/dist/collection/components/snk-application/snk-application.js +1 -3
- package/dist/{collection/temp → components}/ApplicationUtils.js +37 -36
- package/dist/components/AssetsUtils.js +22 -0
- package/dist/components/CSSVarsUtils.js +17 -0
- package/dist/components/_commonjsHelpers.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 +807 -0
- package/dist/components/ez-grid.js +110576 -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 +2 -52
- 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/_commonjsHelpers-9943807e.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 +781 -0
- package/dist/esm/ez-grid.entry.js +110481 -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 +2 -2
- package/dist/esm/sankhyablocks.js +2 -2
- package/dist/esm/snk-application.entry.js +3 -53
- 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-112455b1.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-4811bc0a.entry.js +369 -0
- package/dist/sankhyablocks/p-5f9af495.entry.js +1 -0
- package/dist/sankhyablocks/p-60967cf0.js +1 -0
- package/dist/sankhyablocks/p-70ad6c16.entry.js +1 -0
- package/dist/sankhyablocks/p-710bfffe.entry.js +1 -0
- package/dist/sankhyablocks/p-73397a0f.entry.js +57 -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-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-f80cabc7.entry.js +1 -0
- package/dist/sankhyablocks/p-fcd9bd92.entry.js +1 -0
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/package.json +7 -4
- package/react/components.d.ts +29 -0
- package/react/components.js +29 -0
- package/react/components.js.map +1 -1
- package/dist/cjs/index-4720dab8.js +0 -735
- package/dist/esm/index-72d4e2e0.js +0 -709
- package/dist/sankhyablocks/p-45635e4f.entry.js +0 -57
- package/dist/sankhyablocks/p-a33afc3b.js +0 -2
- package/dist/types/temp/ApplicationUtils.d.ts +0 -11
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const index = require('./index-682c98b2.js');
|
|
6
|
+
const core = require('@sankhyalabs/core');
|
|
7
|
+
const ApplicationUtils = require('./ApplicationUtils-05b74ee9.js');
|
|
8
|
+
|
|
9
|
+
const buildTextArea = ({ name, label, readOnly }) => {
|
|
10
|
+
return (index.h("div", { class: "col col--sd-12 padding-horizontal--small", key: name },
|
|
11
|
+
index.h("ez-text-area", { enabled: !readOnly, label: label, "data-field-name": name })));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const buildTextInput = ({ name, label }) => {
|
|
15
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
16
|
+
index.h("ez-text-input", { label: label, "data-field-name": name, key: name })));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const buildSwitch = (fieldConfig) => {
|
|
20
|
+
return buildField$1(fieldConfig.name, fieldConfig.label, fieldConfig.readOnly, true);
|
|
21
|
+
};
|
|
22
|
+
const buildCheckBox = (fieldConfig) => {
|
|
23
|
+
return buildField$1(fieldConfig.name, fieldConfig.label, fieldConfig.readOnly, false);
|
|
24
|
+
};
|
|
25
|
+
function buildField$1(fieldName, fieldLabel, readOnly, switchMode = false) {
|
|
26
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 align--middle padding-horizontal--small padding-bottom--large" },
|
|
27
|
+
index.h("ez-check", { enabled: !readOnly, label: fieldLabel, mode: switchMode ? "switch" : "regular", "data-field-name": fieldName, key: fieldName })));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const buildComboBox = ({ name, label, readOnly }, properties) => {
|
|
31
|
+
const prop = properties === null || properties === void 0 ? void 0 : properties.options;
|
|
32
|
+
let options;
|
|
33
|
+
if (typeof prop === "string") {
|
|
34
|
+
const parsed = JSON.parse(prop);
|
|
35
|
+
options = Object.keys(parsed).map(key => { return { value: key, label: parsed[key] }; });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
options = prop;
|
|
39
|
+
}
|
|
40
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
41
|
+
index.h("ez-combo-box", { enabled: !readOnly, label: label, "data-field-name": name, key: name, options: options })));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const buildSearch = ({ name, label, readOnly }) => {
|
|
45
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
46
|
+
index.h("ez-search", { enabled: !readOnly, label: label, "data-field-name": name, key: name })));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const buildFile = ({ name, label, readOnly }) => {
|
|
50
|
+
return (index.h("div", { class: "col col--sd-12 padding-horizontal--small" },
|
|
51
|
+
index.h("ez-upload", { enabled: !readOnly, label: label, urlUpload: "", requestHeaders: "", maxFiles: 10, "data-field-name": name, key: name })));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const buildDate = ({ name, label, readOnly }) => {
|
|
55
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
56
|
+
index.h("ez-date-input", { enabled: !readOnly, label: label, "data-field-name": name, key: name })));
|
|
57
|
+
};
|
|
58
|
+
const buildTime = ({ name, label }) => {
|
|
59
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
60
|
+
index.h("ez-time-input", { label: label, "data-field-name": name, key: name })));
|
|
61
|
+
};
|
|
62
|
+
const buildTimeDate = ({ name, label }) => {
|
|
63
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
64
|
+
index.h("ez-date-time-input", { label: label, "data-field-name": name, key: name })));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const buildDecimal = ({ name, label, readOnly }, properties) => {
|
|
68
|
+
const precision = Number((properties === null || properties === void 0 ? void 0 : properties.precision) || 2);
|
|
69
|
+
const prettyPrecision = Number((properties === null || properties === void 0 ? void 0 : properties.prettyPrecision) || precision);
|
|
70
|
+
return buildNumeric(name, label, readOnly, precision, prettyPrecision);
|
|
71
|
+
};
|
|
72
|
+
const buildInteger = ({ name, label, readOnly }) => {
|
|
73
|
+
return buildNumeric(name, label, readOnly, 0, 0);
|
|
74
|
+
};
|
|
75
|
+
function buildNumeric(fieldName, fieldLabel, readOnly, precision, prettyPrecision) {
|
|
76
|
+
return (index.h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
|
|
77
|
+
index.h("ez-number-input", { enabled: !readOnly, label: fieldLabel, precision: precision, prettyPrecision: prettyPrecision, "data-field-name": fieldName, key: fieldName })));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const uiBuilders = new Map();
|
|
81
|
+
uiBuilders.set(core.UserInterface.LONGTEXT, buildTextArea);
|
|
82
|
+
uiBuilders.set(core.UserInterface.CHECKBOX, buildCheckBox);
|
|
83
|
+
uiBuilders.set(core.UserInterface.SWITCH, buildSwitch);
|
|
84
|
+
uiBuilders.set(core.UserInterface.OPTIONSELECTOR, buildComboBox);
|
|
85
|
+
uiBuilders.set(core.UserInterface.SEARCH, buildSearch);
|
|
86
|
+
uiBuilders.set(core.UserInterface.FILE, buildFile);
|
|
87
|
+
uiBuilders.set(core.UserInterface.DATE, buildDate);
|
|
88
|
+
uiBuilders.set(core.UserInterface.TIME, buildTime);
|
|
89
|
+
uiBuilders.set(core.UserInterface.DATETIME, buildTimeDate);
|
|
90
|
+
uiBuilders.set(core.UserInterface.DECIMALNUMBER, buildDecimal);
|
|
91
|
+
uiBuilders.set(core.UserInterface.INTEGERNUMBER, buildInteger);
|
|
92
|
+
const buildField = (field) => {
|
|
93
|
+
const descriptor = field.descriptor;
|
|
94
|
+
const config = Object.assign({}, field.config);
|
|
95
|
+
let builder;
|
|
96
|
+
let props;
|
|
97
|
+
if (descriptor) {
|
|
98
|
+
if (!config.label) {
|
|
99
|
+
config.label = descriptor.label;
|
|
100
|
+
}
|
|
101
|
+
if (!config.name) {
|
|
102
|
+
config.name = descriptor.name;
|
|
103
|
+
}
|
|
104
|
+
if (config.required === undefined) {
|
|
105
|
+
config.required = descriptor.required;
|
|
106
|
+
}
|
|
107
|
+
if (config.readOnly === undefined) {
|
|
108
|
+
config.readOnly = descriptor.readOnly;
|
|
109
|
+
}
|
|
110
|
+
props = descriptor.properties;
|
|
111
|
+
builder = uiBuilders.get(descriptor.userInterface);
|
|
112
|
+
}
|
|
113
|
+
if (config.required) {
|
|
114
|
+
config.label = `* ${config.label} (obrigatório)`;
|
|
115
|
+
}
|
|
116
|
+
if (!builder) {
|
|
117
|
+
builder = buildTextInput;
|
|
118
|
+
}
|
|
119
|
+
return builder(config, props);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const FormItem = ({ source }) => {
|
|
123
|
+
if ("items" in source) {
|
|
124
|
+
const fieldSet = source;
|
|
125
|
+
return index.h("ez-collapsible-box", { label: source.label }, fieldSet.items.map(fi => buildField(fi)));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return buildField(source);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const FormSheet = ({ store, source }) => {
|
|
133
|
+
return (index.h("div", { class: "box__container" },
|
|
134
|
+
index.h("div", { class: "row padding-vertical--small" }, source.items.map(item => index.h(FormItem, { store: store, source: item })))));
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
class FormMetadata {
|
|
138
|
+
constructor() {
|
|
139
|
+
this._sheets = new Map();
|
|
140
|
+
this._requiredFields = [];
|
|
141
|
+
this._cleanOnCopyFields = [];
|
|
142
|
+
}
|
|
143
|
+
getSheet(name) {
|
|
144
|
+
return this._sheets.get(name);
|
|
145
|
+
}
|
|
146
|
+
getAllSheets() {
|
|
147
|
+
return this._sheets;
|
|
148
|
+
}
|
|
149
|
+
addSheet(sheet) {
|
|
150
|
+
this._sheets.set(sheet.name, sheet);
|
|
151
|
+
this._requiredFields = this._requiredFields.concat(sheet.requiredFields);
|
|
152
|
+
this._cleanOnCopyFields = this._cleanOnCopyFields.concat(sheet.cleanOnCopyFields);
|
|
153
|
+
}
|
|
154
|
+
getRequiredFields() {
|
|
155
|
+
return this._requiredFields;
|
|
156
|
+
}
|
|
157
|
+
getCleanOnCopyFields() {
|
|
158
|
+
return this._cleanOnCopyFields;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const buildFromDataUnit = (dataUnit) => {
|
|
162
|
+
var _a;
|
|
163
|
+
const unitMD = dataUnit.metadata;
|
|
164
|
+
const metadata = new FormMetadata();
|
|
165
|
+
if (unitMD) {
|
|
166
|
+
const visibleFields = (_a = unitMD.fields) === null || _a === void 0 ? void 0 : _a.filter(descriptor => descriptor.visible !== false);
|
|
167
|
+
metadata.addSheet({
|
|
168
|
+
label: unitMD.label,
|
|
169
|
+
name: unitMD.name,
|
|
170
|
+
items: visibleFields.map(descriptor => { return { descriptor }; }),
|
|
171
|
+
requiredFields: visibleFields
|
|
172
|
+
.filter(descriptor => descriptor.required)
|
|
173
|
+
.map(descriptor => descriptor.name),
|
|
174
|
+
cleanOnCopyFields: visibleFields
|
|
175
|
+
.filter(descriptor => { var _a; return (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy; })
|
|
176
|
+
.map(descriptor => descriptor.name)
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return metadata;
|
|
180
|
+
};
|
|
181
|
+
function getTabConfig(tab, sheets) {
|
|
182
|
+
const tabConfig = (typeof tab === "string" ? Array.from(sheets.keys()).find(t => t.label === tab) : tab);
|
|
183
|
+
return tabConfig || { label: tab, visible: true };
|
|
184
|
+
}
|
|
185
|
+
const buildFromConfig = (fields, dataUnit) => {
|
|
186
|
+
const sheets = new Map();
|
|
187
|
+
const requiredFields = [];
|
|
188
|
+
const cleanOnCopyFields = [];
|
|
189
|
+
fields.forEach(config => {
|
|
190
|
+
var _a;
|
|
191
|
+
if (config.visible !== false) {
|
|
192
|
+
const tabConfig = getTabConfig(config.tab || "Geral", sheets);
|
|
193
|
+
const descriptor = dataUnit.getField(config.name);
|
|
194
|
+
if (descriptor && tabConfig.visible) {
|
|
195
|
+
if (!sheets.has(tabConfig)) {
|
|
196
|
+
sheets.set(tabConfig, new Map());
|
|
197
|
+
}
|
|
198
|
+
const tabItens = sheets.get(tabConfig);
|
|
199
|
+
const isRequired = config.required === undefined ? descriptor.required : config.required;
|
|
200
|
+
if (isRequired) {
|
|
201
|
+
requiredFields.push(config.name);
|
|
202
|
+
}
|
|
203
|
+
const clearOnCopy = config.cleanOnCopy === undefined ? (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy : config.cleanOnCopy;
|
|
204
|
+
if (clearOnCopy) {
|
|
205
|
+
cleanOnCopyFields.push(config.name);
|
|
206
|
+
}
|
|
207
|
+
const fieldMD = { config, descriptor };
|
|
208
|
+
const group = config.group;
|
|
209
|
+
if (group) {
|
|
210
|
+
const key = `group::${group}`;
|
|
211
|
+
if (!tabItens.has(key)) {
|
|
212
|
+
tabItens.set(key, { label: group, items: [fieldMD] });
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
tabItens.get(key).items.push(fieldMD);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
tabItens.set(config.name, fieldMD);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const metadata = new FormMetadata();
|
|
225
|
+
Array.from(sheets.entries())
|
|
226
|
+
.sort((a, b) => (a[0].order || 10000) - (b[0].order || 10000))
|
|
227
|
+
.forEach(([key, value]) => {
|
|
228
|
+
metadata.addSheet({
|
|
229
|
+
label: key.label,
|
|
230
|
+
name: key.label,
|
|
231
|
+
items: Array.from(value.values()),
|
|
232
|
+
requiredFields,
|
|
233
|
+
cleanOnCopyFields
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
return metadata;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
|
|
241
|
+
*
|
|
242
|
+
* Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
|
|
243
|
+
* during build.
|
|
244
|
+
* @param {number} code
|
|
245
|
+
*/
|
|
246
|
+
function formatProdErrorMessage(code) {
|
|
247
|
+
return "Minified Redux error #" + code + "; visit https://redux.js.org/Errors?code=" + code + " for the full message or " + 'use the non-minified dev environment for full errors. ';
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Inlined version of the `symbol-observable` polyfill
|
|
251
|
+
var $$observable = (function () {
|
|
252
|
+
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
253
|
+
})();
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* These are private action types reserved by Redux.
|
|
257
|
+
* For any unknown actions, you must return the current state.
|
|
258
|
+
* If the current state is undefined, you must return the initial state.
|
|
259
|
+
* Do not reference these action types directly in your code.
|
|
260
|
+
*/
|
|
261
|
+
var randomString = function randomString() {
|
|
262
|
+
return Math.random().toString(36).substring(7).split('').join('.');
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
var ActionTypes = {
|
|
266
|
+
INIT: "@@redux/INIT" + randomString(),
|
|
267
|
+
REPLACE: "@@redux/REPLACE" + randomString(),
|
|
268
|
+
PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
|
|
269
|
+
return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @param {any} obj The object to inspect.
|
|
275
|
+
* @returns {boolean} True if the argument appears to be a plain object.
|
|
276
|
+
*/
|
|
277
|
+
function isPlainObject(obj) {
|
|
278
|
+
if (typeof obj !== 'object' || obj === null) return false;
|
|
279
|
+
var proto = obj;
|
|
280
|
+
|
|
281
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
282
|
+
proto = Object.getPrototypeOf(proto);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return Object.getPrototypeOf(obj) === proto;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* @deprecated
|
|
290
|
+
*
|
|
291
|
+
* **We recommend using the `configureStore` method
|
|
292
|
+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
|
|
293
|
+
*
|
|
294
|
+
* Redux Toolkit is our recommended approach for writing Redux logic today,
|
|
295
|
+
* including store setup, reducers, data fetching, and more.
|
|
296
|
+
*
|
|
297
|
+
* **For more details, please read this Redux docs page:**
|
|
298
|
+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
|
|
299
|
+
*
|
|
300
|
+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
|
|
301
|
+
* simplifies setup and helps avoid common bugs.
|
|
302
|
+
*
|
|
303
|
+
* You should not be using the `redux` core package by itself today, except for learning purposes.
|
|
304
|
+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
|
|
305
|
+
* all users to migrate to using Redux Toolkit for all Redux code.
|
|
306
|
+
*
|
|
307
|
+
* If you want to use `createStore` without this visual deprecation warning, use
|
|
308
|
+
* the `legacy_createStore` import instead:
|
|
309
|
+
*
|
|
310
|
+
* `import { legacy_createStore as createStore} from 'redux'`
|
|
311
|
+
*
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
function createStore(reducer, preloadedState, enhancer) {
|
|
315
|
+
var _ref2;
|
|
316
|
+
|
|
317
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
|
|
318
|
+
throw new Error(formatProdErrorMessage(0) );
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
|
|
322
|
+
enhancer = preloadedState;
|
|
323
|
+
preloadedState = undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (typeof enhancer !== 'undefined') {
|
|
327
|
+
if (typeof enhancer !== 'function') {
|
|
328
|
+
throw new Error(formatProdErrorMessage(1) );
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return enhancer(createStore)(reducer, preloadedState);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (typeof reducer !== 'function') {
|
|
335
|
+
throw new Error(formatProdErrorMessage(2) );
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
var currentReducer = reducer;
|
|
339
|
+
var currentState = preloadedState;
|
|
340
|
+
var currentListeners = [];
|
|
341
|
+
var nextListeners = currentListeners;
|
|
342
|
+
var isDispatching = false;
|
|
343
|
+
/**
|
|
344
|
+
* This makes a shallow copy of currentListeners so we can use
|
|
345
|
+
* nextListeners as a temporary list while dispatching.
|
|
346
|
+
*
|
|
347
|
+
* This prevents any bugs around consumers calling
|
|
348
|
+
* subscribe/unsubscribe in the middle of a dispatch.
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
function ensureCanMutateNextListeners() {
|
|
352
|
+
if (nextListeners === currentListeners) {
|
|
353
|
+
nextListeners = currentListeners.slice();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Reads the state tree managed by the store.
|
|
358
|
+
*
|
|
359
|
+
* @returns {any} The current state tree of your application.
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
function getState() {
|
|
364
|
+
if (isDispatching) {
|
|
365
|
+
throw new Error(formatProdErrorMessage(3) );
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return currentState;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Adds a change listener. It will be called any time an action is dispatched,
|
|
372
|
+
* and some part of the state tree may potentially have changed. You may then
|
|
373
|
+
* call `getState()` to read the current state tree inside the callback.
|
|
374
|
+
*
|
|
375
|
+
* You may call `dispatch()` from a change listener, with the following
|
|
376
|
+
* caveats:
|
|
377
|
+
*
|
|
378
|
+
* 1. The subscriptions are snapshotted just before every `dispatch()` call.
|
|
379
|
+
* If you subscribe or unsubscribe while the listeners are being invoked, this
|
|
380
|
+
* will not have any effect on the `dispatch()` that is currently in progress.
|
|
381
|
+
* However, the next `dispatch()` call, whether nested or not, will use a more
|
|
382
|
+
* recent snapshot of the subscription list.
|
|
383
|
+
*
|
|
384
|
+
* 2. The listener should not expect to see all state changes, as the state
|
|
385
|
+
* might have been updated multiple times during a nested `dispatch()` before
|
|
386
|
+
* the listener is called. It is, however, guaranteed that all subscribers
|
|
387
|
+
* registered before the `dispatch()` started will be called with the latest
|
|
388
|
+
* state by the time it exits.
|
|
389
|
+
*
|
|
390
|
+
* @param {Function} listener A callback to be invoked on every dispatch.
|
|
391
|
+
* @returns {Function} A function to remove this change listener.
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
function subscribe(listener) {
|
|
396
|
+
if (typeof listener !== 'function') {
|
|
397
|
+
throw new Error(formatProdErrorMessage(4) );
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (isDispatching) {
|
|
401
|
+
throw new Error(formatProdErrorMessage(5) );
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
var isSubscribed = true;
|
|
405
|
+
ensureCanMutateNextListeners();
|
|
406
|
+
nextListeners.push(listener);
|
|
407
|
+
return function unsubscribe() {
|
|
408
|
+
if (!isSubscribed) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (isDispatching) {
|
|
413
|
+
throw new Error(formatProdErrorMessage(6) );
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
isSubscribed = false;
|
|
417
|
+
ensureCanMutateNextListeners();
|
|
418
|
+
var index = nextListeners.indexOf(listener);
|
|
419
|
+
nextListeners.splice(index, 1);
|
|
420
|
+
currentListeners = null;
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Dispatches an action. It is the only way to trigger a state change.
|
|
425
|
+
*
|
|
426
|
+
* The `reducer` function, used to create the store, will be called with the
|
|
427
|
+
* current state tree and the given `action`. Its return value will
|
|
428
|
+
* be considered the **next** state of the tree, and the change listeners
|
|
429
|
+
* will be notified.
|
|
430
|
+
*
|
|
431
|
+
* The base implementation only supports plain object actions. If you want to
|
|
432
|
+
* dispatch a Promise, an Observable, a thunk, or something else, you need to
|
|
433
|
+
* wrap your store creating function into the corresponding middleware. For
|
|
434
|
+
* example, see the documentation for the `redux-thunk` package. Even the
|
|
435
|
+
* middleware will eventually dispatch plain object actions using this method.
|
|
436
|
+
*
|
|
437
|
+
* @param {Object} action A plain object representing “what changed”. It is
|
|
438
|
+
* a good idea to keep actions serializable so you can record and replay user
|
|
439
|
+
* sessions, or use the time travelling `redux-devtools`. An action must have
|
|
440
|
+
* a `type` property which may not be `undefined`. It is a good idea to use
|
|
441
|
+
* string constants for action types.
|
|
442
|
+
*
|
|
443
|
+
* @returns {Object} For convenience, the same action object you dispatched.
|
|
444
|
+
*
|
|
445
|
+
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
|
|
446
|
+
* return something else (for example, a Promise you can await).
|
|
447
|
+
*/
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
function dispatch(action) {
|
|
451
|
+
if (!isPlainObject(action)) {
|
|
452
|
+
throw new Error(formatProdErrorMessage(7) );
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (typeof action.type === 'undefined') {
|
|
456
|
+
throw new Error(formatProdErrorMessage(8) );
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (isDispatching) {
|
|
460
|
+
throw new Error(formatProdErrorMessage(9) );
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
try {
|
|
464
|
+
isDispatching = true;
|
|
465
|
+
currentState = currentReducer(currentState, action);
|
|
466
|
+
} finally {
|
|
467
|
+
isDispatching = false;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
var listeners = currentListeners = nextListeners;
|
|
471
|
+
|
|
472
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
473
|
+
var listener = listeners[i];
|
|
474
|
+
listener();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return action;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Replaces the reducer currently used by the store to calculate the state.
|
|
481
|
+
*
|
|
482
|
+
* You might need this if your app implements code splitting and you want to
|
|
483
|
+
* load some of the reducers dynamically. You might also need this if you
|
|
484
|
+
* implement a hot reloading mechanism for Redux.
|
|
485
|
+
*
|
|
486
|
+
* @param {Function} nextReducer The reducer for the store to use instead.
|
|
487
|
+
* @returns {void}
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
function replaceReducer(nextReducer) {
|
|
492
|
+
if (typeof nextReducer !== 'function') {
|
|
493
|
+
throw new Error(formatProdErrorMessage(10) );
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
|
|
497
|
+
// Any reducers that existed in both the new and old rootReducer
|
|
498
|
+
// will receive the previous state. This effectively populates
|
|
499
|
+
// the new state tree with any relevant data from the old one.
|
|
500
|
+
|
|
501
|
+
dispatch({
|
|
502
|
+
type: ActionTypes.REPLACE
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Interoperability point for observable/reactive libraries.
|
|
507
|
+
* @returns {observable} A minimal observable of state changes.
|
|
508
|
+
* For more information, see the observable proposal:
|
|
509
|
+
* https://github.com/tc39/proposal-observable
|
|
510
|
+
*/
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
function observable() {
|
|
514
|
+
var _ref;
|
|
515
|
+
|
|
516
|
+
var outerSubscribe = subscribe;
|
|
517
|
+
return _ref = {
|
|
518
|
+
/**
|
|
519
|
+
* The minimal observable subscription method.
|
|
520
|
+
* @param {Object} observer Any object that can be used as an observer.
|
|
521
|
+
* The observer object should have a `next` method.
|
|
522
|
+
* @returns {subscription} An object with an `unsubscribe` method that can
|
|
523
|
+
* be used to unsubscribe the observable from the store, and prevent further
|
|
524
|
+
* emission of values from the observable.
|
|
525
|
+
*/
|
|
526
|
+
subscribe: function subscribe(observer) {
|
|
527
|
+
if (typeof observer !== 'object' || observer === null) {
|
|
528
|
+
throw new Error(formatProdErrorMessage(11) );
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function observeState() {
|
|
532
|
+
if (observer.next) {
|
|
533
|
+
observer.next(getState());
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
observeState();
|
|
538
|
+
var unsubscribe = outerSubscribe(observeState);
|
|
539
|
+
return {
|
|
540
|
+
unsubscribe: unsubscribe
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
}, _ref[$$observable] = function () {
|
|
544
|
+
return this;
|
|
545
|
+
}, _ref;
|
|
546
|
+
} // When a store is created, an "INIT" action is dispatched so that every
|
|
547
|
+
// reducer returns their initial state. This effectively populates
|
|
548
|
+
// the initial state tree.
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
dispatch({
|
|
552
|
+
type: ActionTypes.INIT
|
|
553
|
+
});
|
|
554
|
+
return _ref2 = {
|
|
555
|
+
dispatch: dispatch,
|
|
556
|
+
subscribe: subscribe,
|
|
557
|
+
getState: getState,
|
|
558
|
+
replaceReducer: replaceReducer
|
|
559
|
+
}, _ref2[$$observable] = observable, _ref2;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const inicialState = {};
|
|
563
|
+
/////////////////////////////// REDUCERS ///////////////////////////////
|
|
564
|
+
function formReducer(state = inicialState, action) {
|
|
565
|
+
switch (action.type) {
|
|
566
|
+
case FormActions.METADATA_LOADED:
|
|
567
|
+
return Object.assign(Object.assign({}, state), { formMetadata: action.payload });
|
|
568
|
+
case FormActions.CHANGE_TAB:
|
|
569
|
+
return Object.assign(Object.assign({}, state), { currentSheet: action.payload });
|
|
570
|
+
default:
|
|
571
|
+
return state;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
/////////////////////////////// ACTION CREATORS ///////////////////////////////
|
|
575
|
+
function loadMetadata(formMetadata) {
|
|
576
|
+
return {
|
|
577
|
+
type: FormActions.METADATA_LOADED,
|
|
578
|
+
payload: formMetadata
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function changeTab(currentSheet) {
|
|
582
|
+
return {
|
|
583
|
+
type: FormActions.CHANGE_TAB,
|
|
584
|
+
payload: currentSheet.tabKey
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
/////////////////////////////// SELECTORS ///////////////////////////////
|
|
588
|
+
function selectFormMetadata(state) {
|
|
589
|
+
return state.formMetadata;
|
|
590
|
+
}
|
|
591
|
+
function selectCurrentSheet(state) {
|
|
592
|
+
return state.currentSheet ? state.formMetadata.getSheet(state.currentSheet) : Array.from(state.formMetadata.getAllSheets().values())[0];
|
|
593
|
+
}
|
|
594
|
+
/////////////////////////////// TYPES ///////////////////////////////
|
|
595
|
+
var FormActions;
|
|
596
|
+
(function (FormActions) {
|
|
597
|
+
FormActions["METADATA_LOADED"] = "FORM/METADATA_LOADED";
|
|
598
|
+
FormActions["CHANGE_TAB"] = "FORM/CHANGE_TAB";
|
|
599
|
+
})(FormActions || (FormActions = {}));
|
|
600
|
+
|
|
601
|
+
class DataBinder {
|
|
602
|
+
constructor(dataUnit) {
|
|
603
|
+
this._fields = new Map();
|
|
604
|
+
this._dataUnit = dataUnit;
|
|
605
|
+
this._dataUnit.subscribe(_action => {
|
|
606
|
+
var _a;
|
|
607
|
+
(_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
|
|
608
|
+
this.updateValue(field.fieldName, field.field);
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
bind(fields) {
|
|
613
|
+
fields.forEach(fieldElement => {
|
|
614
|
+
const fieldName = fieldElement.dataset.fieldName;
|
|
615
|
+
this.updateBind(fieldName, fieldElement);
|
|
616
|
+
this.updateValue(fieldName, fieldElement);
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
updateValue(fieldName, field) {
|
|
620
|
+
field["value"] = this._dataUnit.getFieldValue(fieldName);
|
|
621
|
+
}
|
|
622
|
+
updateBind(fieldName, field) {
|
|
623
|
+
const oldBind = this._fields.get(fieldName);
|
|
624
|
+
if (oldBind) {
|
|
625
|
+
oldBind.destroy();
|
|
626
|
+
}
|
|
627
|
+
this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
|
|
628
|
+
this.bindSearchOptionsLoader(fieldName, field);
|
|
629
|
+
}
|
|
630
|
+
setFieldValue(fieldName, newValue) {
|
|
631
|
+
if (this._dataUnit.records.length === 0) {
|
|
632
|
+
this._dataUnit.addRecord();
|
|
633
|
+
}
|
|
634
|
+
this._dataUnit.setFieldValue(fieldName, newValue);
|
|
635
|
+
}
|
|
636
|
+
bindSearchOptionsLoader(fieldName, field) {
|
|
637
|
+
if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] === undefined) {
|
|
638
|
+
const loader = core.ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
|
|
639
|
+
if (loader) {
|
|
640
|
+
field["optionLoader"] = (arg) => {
|
|
641
|
+
return loader(arg, fieldName, this._dataUnit);
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
class Bind {
|
|
648
|
+
destroy() {
|
|
649
|
+
this.field.removeEventListener(this.eventName, this.eventListener);
|
|
650
|
+
}
|
|
651
|
+
static create(fieldName, field, callback) {
|
|
652
|
+
const b = new Bind();
|
|
653
|
+
b.fieldName = fieldName;
|
|
654
|
+
b.field = field;
|
|
655
|
+
//FIXME: Verificar se o field é um EzField
|
|
656
|
+
b.eventListener = (evt) => { callback(fieldName, evt.detail); };
|
|
657
|
+
b.eventName = "ezChange";
|
|
658
|
+
b.field.addEventListener(b.eventName, b.eventListener);
|
|
659
|
+
return b;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const ezFormCss = "ez-form{display:flex;flex-direction:column;width:100%}";
|
|
664
|
+
|
|
665
|
+
const EzForm = class {
|
|
666
|
+
constructor(hostRef) {
|
|
667
|
+
index.registerInstance(this, hostRef);
|
|
668
|
+
}
|
|
669
|
+
submit() {
|
|
670
|
+
return Promise.resolve();
|
|
671
|
+
}
|
|
672
|
+
cancel() {
|
|
673
|
+
return Promise.resolve();
|
|
674
|
+
}
|
|
675
|
+
validate() {
|
|
676
|
+
return new Promise((accept, reject) => {
|
|
677
|
+
const metadata = selectFormMetadata(this._store.getState());
|
|
678
|
+
const requiredFields = this._staticFields
|
|
679
|
+
.filter(f => f.dataset.required)
|
|
680
|
+
.map(f => f.dataset.fieldName)
|
|
681
|
+
.concat(metadata.getRequiredFields());
|
|
682
|
+
const records = this.dataUnit.records;
|
|
683
|
+
for (let i = 0; i < records.length; i++) {
|
|
684
|
+
if (!this.validateRequired(requiredFields, records[i])) {
|
|
685
|
+
reject();
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
accept();
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
configChanged() {
|
|
693
|
+
this.processMetadata();
|
|
694
|
+
}
|
|
695
|
+
validateRequired(requiredFields, record) {
|
|
696
|
+
const invalidFields = [];
|
|
697
|
+
requiredFields.forEach(field => {
|
|
698
|
+
const value = record[field];
|
|
699
|
+
const fieldElem = this._element.querySelector(`[data-field-name=${field}]`);
|
|
700
|
+
if (value === null || value === undefined || value === "") {
|
|
701
|
+
invalidFields.push(field);
|
|
702
|
+
fieldElem["errorMessage"] = "Essa informação é obrigatória";
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
fieldElem["errorMessage"] = "";
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
const isValid = invalidFields.length === 0;
|
|
709
|
+
if (!isValid) {
|
|
710
|
+
ApplicationUtils.ApplicationUtils.info("Há pelo menos um campo obrigatório não preenchido.");
|
|
711
|
+
}
|
|
712
|
+
return isValid;
|
|
713
|
+
}
|
|
714
|
+
getDynamicContent() {
|
|
715
|
+
var _a;
|
|
716
|
+
const formMD = selectFormMetadata(this._store.getState());
|
|
717
|
+
if (!formMD)
|
|
718
|
+
return null;
|
|
719
|
+
const currentSheet = selectCurrentSheet((_a = this._store) === null || _a === void 0 ? void 0 : _a.getState());
|
|
720
|
+
if (!currentSheet) {
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
const allSheets = Array.from(formMD.getAllSheets().values());
|
|
724
|
+
const result = [];
|
|
725
|
+
if (allSheets.length > 1) {
|
|
726
|
+
result.push(index.h("ez-tabselector", { onEzChange: (evt) => this._store.dispatch(changeTab(evt.detail)), selectedTab: currentSheet.name }, allSheets.map(s => index.h("ez-tab", { tabKey: s.name, label: s.label }))));
|
|
727
|
+
}
|
|
728
|
+
result.push(index.h(FormSheet, { store: this._store, source: currentSheet }));
|
|
729
|
+
return result;
|
|
730
|
+
}
|
|
731
|
+
processMetadata() {
|
|
732
|
+
if (!this.isStatic()) {
|
|
733
|
+
const metadata = this.config && this.config.length > 0 ? buildFromConfig(this.config, this.dataUnit) : buildFromDataUnit(this.dataUnit);
|
|
734
|
+
this._store.dispatch(loadMetadata(metadata));
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
isStatic() {
|
|
738
|
+
var _a;
|
|
739
|
+
return ((_a = this._staticFields) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
740
|
+
}
|
|
741
|
+
interceptAction(action) {
|
|
742
|
+
if (action.type === core.Action.RECORDS_COPIED) {
|
|
743
|
+
const metadata = selectFormMetadata(this._store.getState());
|
|
744
|
+
const cleanFields = metadata.getCleanOnCopyFields();
|
|
745
|
+
if (cleanFields) {
|
|
746
|
+
const records = action.payload;
|
|
747
|
+
return new core.DataUnitAction(core.Action.RECORDS_COPIED, records.map(record => {
|
|
748
|
+
const newRecord = Object.assign({}, record);
|
|
749
|
+
cleanFields.forEach(fieldName => delete newRecord[fieldName]);
|
|
750
|
+
return newRecord;
|
|
751
|
+
}));
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return action;
|
|
755
|
+
}
|
|
756
|
+
componentWillLoad() {
|
|
757
|
+
if (this.dataUnit === undefined) {
|
|
758
|
+
this.dataUnit = new core.DataUnit("ez-form");
|
|
759
|
+
}
|
|
760
|
+
this.dataUnit.addInterceptor(this);
|
|
761
|
+
this.dataUnit.subscribe(action => {
|
|
762
|
+
if (action.type === core.Action.METADATA_LOADED) {
|
|
763
|
+
this.processMetadata();
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
this._dataBinder = new DataBinder(this.dataUnit);
|
|
767
|
+
this._store = createStore(formReducer);
|
|
768
|
+
this._store.subscribe(() => index.forceUpdate(this));
|
|
769
|
+
this._staticFields = Array.from(this._element.querySelectorAll("[data-field-name]"));
|
|
770
|
+
this.processMetadata();
|
|
771
|
+
}
|
|
772
|
+
componentDidRender() {
|
|
773
|
+
this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")));
|
|
774
|
+
}
|
|
775
|
+
render() {
|
|
776
|
+
return (index.h(index.Host, null, this.isStatic() ? null : this.getDynamicContent()));
|
|
777
|
+
}
|
|
778
|
+
get _element() { return index.getElement(this); }
|
|
779
|
+
static get watchers() { return {
|
|
780
|
+
"config": ["configChanged"]
|
|
781
|
+
}; }
|
|
782
|
+
};
|
|
783
|
+
EzForm.style = ezFormCss;
|
|
784
|
+
|
|
785
|
+
exports.ez_form = EzForm;
|