@sankhyalabs/ezui 4.1.0 → 4.2.1
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/{constants-5a75e2f3.js → constants-5d588e38.js} +2 -0
- package/dist/cjs/ez-check.cjs.entry.js +12 -1
- package/dist/cjs/ez-combo-box.cjs.entry.js +1 -1
- package/dist/cjs/ez-form-view.cjs.entry.js +1 -1
- package/dist/cjs/ez-form.cjs.entry.js +64 -36
- package/dist/cjs/ez-grid.cjs.entry.js +242 -110
- package/dist/cjs/ezui.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/ez-check/ez-check.js +14 -1
- package/dist/collection/components/ez-grid/controller/DataUnitBridge.js +15 -0
- package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +71 -14
- package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +9 -1
- package/dist/collection/components/ez-grid/ez-grid.js +163 -94
- package/dist/collection/components/ez-grid/subcomponents/selection-counter.js +2 -2
- package/dist/collection/utils/constants.js +1 -0
- package/dist/collection/utils/form/DataBinder.js +47 -30
- package/dist/collection/utils/form/FormMetadata.js +17 -6
- package/dist/custom-elements/index.js +320 -149
- package/dist/esm/constants-76d2e931.js +4 -0
- package/dist/esm/ez-check.entry.js +12 -1
- package/dist/esm/ez-combo-box.entry.js +1 -1
- package/dist/esm/ez-form-view.entry.js +1 -1
- package/dist/esm/ez-form.entry.js +64 -36
- package/dist/esm/ez-grid.entry.js +242 -110
- package/dist/esm/ezui.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/ezui/ezui.esm.js +1 -1
- package/dist/ezui/p-1f841f3c.entry.js +1 -0
- package/dist/ezui/{p-50883460.entry.js → p-878646a0.entry.js} +1 -1
- package/dist/ezui/{p-468799e1.entry.js → p-96df1a0e.entry.js} +2 -2
- package/dist/ezui/p-a3ce3710.entry.js +1 -0
- package/dist/ezui/p-b01e3085.js +1 -0
- package/dist/ezui/{p-e748b5d3.entry.js → p-b7ea9791.entry.js} +1 -1
- package/dist/types/components/ez-check/ez-check.d.ts +1 -0
- package/dist/types/components/ez-grid/controller/EzGridController.d.ts +10 -2
- package/dist/types/components/ez-grid/controller/ag-grid/AgGridController.d.ts +5 -2
- package/dist/types/components/ez-grid/ez-grid.d.ts +20 -15
- package/dist/types/components/ez-grid/subcomponents/selection-counter.d.ts +2 -1
- package/dist/types/utils/constants.d.ts +1 -0
- package/dist/types/utils/form/DataBinder.d.ts +3 -2
- package/package.json +1 -1
- package/dist/esm/constants-ca136201.js +0 -3
- package/dist/ezui/p-08f4a048.entry.js +0 -1
- package/dist/ezui/p-3f4ae3a3.js +0 -1
- package/dist/ezui/p-a323b415.entry.js +0 -1
|
@@ -2,9 +2,8 @@ import { ApplicationContext, Action, WaitingChangeException, DataUnitAction } fr
|
|
|
2
2
|
import ApplicationUtils from "../ApplicationUtils";
|
|
3
3
|
export default class DataBinder {
|
|
4
4
|
constructor(dataUnit) {
|
|
5
|
-
this._invalidFields = new Map();
|
|
6
5
|
this.onDataUnitEvent = (action) => {
|
|
7
|
-
var _a;
|
|
6
|
+
var _a, _b;
|
|
8
7
|
switch (action.type) {
|
|
9
8
|
case Action.DATA_LOADED:
|
|
10
9
|
case Action.DATA_SAVED:
|
|
@@ -13,6 +12,7 @@ export default class DataBinder {
|
|
|
13
12
|
case Action.RECORDS_COPIED:
|
|
14
13
|
case Action.EDITION_CANCELED:
|
|
15
14
|
case Action.SELECTION_CHANGED:
|
|
15
|
+
case Action.SELECTION_REMOVED:
|
|
16
16
|
case Action.NEXT_SELECTED:
|
|
17
17
|
case Action.PREVIOUS_SELECTED:
|
|
18
18
|
this.clearInvalid();
|
|
@@ -24,13 +24,30 @@ export default class DataBinder {
|
|
|
24
24
|
this.updateValue(field.fieldName, field.field);
|
|
25
25
|
});
|
|
26
26
|
break;
|
|
27
|
+
case Action.FIELD_INVALIDATED:
|
|
28
|
+
(_b = this._fields) === null || _b === void 0 ? void 0 : _b.forEach(field => {
|
|
29
|
+
this.updateErrorMessage(field.fieldName, field.field);
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
27
32
|
}
|
|
28
33
|
};
|
|
29
34
|
this._fields = new Map();
|
|
30
35
|
this._dataUnit = dataUnit;
|
|
36
|
+
this.applyDefaultValues();
|
|
31
37
|
this._dataUnit.subscribe(this.onDataUnitEvent);
|
|
32
38
|
this._dataUnit.addInterceptor(this);
|
|
33
39
|
}
|
|
40
|
+
applyDefaultValues() {
|
|
41
|
+
const recordIds = (this._dataUnit.getAddedRecords() || []).map(r => r.__record__id__);
|
|
42
|
+
if (recordIds.length > 0) {
|
|
43
|
+
const defaultValues = this.getDefaultValues();
|
|
44
|
+
if (defaultValues) {
|
|
45
|
+
Object.keys(defaultValues).forEach(field => {
|
|
46
|
+
this._dataUnit.setFieldValue(field, defaultValues[field], recordIds);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
34
51
|
bind(fields, currentContextName, formMetadata, recordsValidator) {
|
|
35
52
|
fields.forEach(fieldElement => {
|
|
36
53
|
const { fieldName, contextName } = fieldElement.dataset;
|
|
@@ -45,17 +62,19 @@ export default class DataBinder {
|
|
|
45
62
|
this._dataUnit.unsubscribe(this.onDataUnitEvent);
|
|
46
63
|
this._dataUnit.removeInterceptor(this);
|
|
47
64
|
}
|
|
65
|
+
getCurrentRecordId() {
|
|
66
|
+
const record = this._dataUnit.getSelectedRecord();
|
|
67
|
+
return record === null || record === void 0 ? void 0 : record.__record__id__;
|
|
68
|
+
}
|
|
48
69
|
markInvalid(field) {
|
|
49
|
-
this.
|
|
70
|
+
this._dataUnit.setInvalidField(field.name, field.message, this.getCurrentRecordId());
|
|
50
71
|
if (this._fields.has(field.name)) {
|
|
51
72
|
const fieldElement = this._fields.get(field.name).field;
|
|
52
|
-
|
|
53
|
-
this.updateErrorMessage(field.name, fieldElement);
|
|
54
|
-
}
|
|
73
|
+
this.updateErrorMessage(field.name, fieldElement, field.message);
|
|
55
74
|
}
|
|
56
75
|
}
|
|
57
|
-
clearInvalid() {
|
|
58
|
-
this.
|
|
76
|
+
clearInvalid(recordId) {
|
|
77
|
+
this._dataUnit.clearInvalid(recordId);
|
|
59
78
|
this._fields.forEach(fieldBinder => {
|
|
60
79
|
const fieldElement = fieldBinder.field;
|
|
61
80
|
fieldElement["errorMessage"] = "";
|
|
@@ -137,16 +156,18 @@ export default class DataBinder {
|
|
|
137
156
|
}
|
|
138
157
|
});
|
|
139
158
|
}
|
|
140
|
-
updateErrorMessage(fieldName, field) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
159
|
+
updateErrorMessage(fieldName, field, message) {
|
|
160
|
+
if (message == undefined) {
|
|
161
|
+
message = this._dataUnit.getInvalidMessage(this.getCurrentRecordId(), fieldName);
|
|
162
|
+
}
|
|
163
|
+
if (!field["errorMessage"]) {
|
|
164
|
+
field["errorMessage"] = message;
|
|
144
165
|
}
|
|
145
166
|
}
|
|
146
167
|
getErrorMessage(fieldName) {
|
|
147
168
|
if (this._fields.has(fieldName)) {
|
|
148
169
|
const fieldElement = this._fields.get(fieldName).field;
|
|
149
|
-
return fieldElement["errorMessage"]
|
|
170
|
+
return fieldElement["errorMessage"];
|
|
150
171
|
}
|
|
151
172
|
return undefined;
|
|
152
173
|
}
|
|
@@ -197,7 +218,7 @@ export default class DataBinder {
|
|
|
197
218
|
if (this._dataUnit.records.length === 0) {
|
|
198
219
|
this._dataUnit.addRecord();
|
|
199
220
|
}
|
|
200
|
-
this.
|
|
221
|
+
this._dataUnit.clearInvalid(this.getCurrentRecordId(), fieldName);
|
|
201
222
|
this._dataUnit.setFieldValue(fieldName, newValue);
|
|
202
223
|
if (this._dataUnit.waitingForChange(fieldName)) {
|
|
203
224
|
const bind = this._fields.get(fieldName);
|
|
@@ -230,7 +251,6 @@ export default class DataBinder {
|
|
|
230
251
|
}
|
|
231
252
|
}
|
|
232
253
|
interceptAction(action) {
|
|
233
|
-
var _a;
|
|
234
254
|
if (action.type === Action.RECORDS_COPIED) {
|
|
235
255
|
const cleanFields = this._formMetadata.getCleanOnCopyFields();
|
|
236
256
|
if (cleanFields) {
|
|
@@ -250,30 +270,27 @@ export default class DataBinder {
|
|
|
250
270
|
});
|
|
251
271
|
}
|
|
252
272
|
if (action.type === Action.RECORDS_ADDED) {
|
|
253
|
-
const defaultValues =
|
|
273
|
+
const defaultValues = this.getDefaultValues();
|
|
254
274
|
if (defaultValues) {
|
|
255
275
|
const records = action.payload;
|
|
256
276
|
return new DataUnitAction(Action.RECORDS_ADDED, records.map(record => {
|
|
257
|
-
|
|
258
|
-
for (const field in defaultValues) {
|
|
259
|
-
const defaultValue = this.getFormattedValue(defaultValues[field]);
|
|
260
|
-
const recordValue = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
261
|
-
newRecord[field] = this._dataUnit.valueFromString(field, recordValue);
|
|
262
|
-
}
|
|
263
|
-
return newRecord;
|
|
277
|
+
return Object.assign(Object.assign({}, record), defaultValues);
|
|
264
278
|
}));
|
|
265
279
|
}
|
|
266
280
|
}
|
|
267
281
|
return action;
|
|
268
282
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
283
|
+
getDefaultValues() {
|
|
284
|
+
var _a;
|
|
285
|
+
const rawDefaultValues = (_a = this._formMetadata) === null || _a === void 0 ? void 0 : _a.getDefaultValues();
|
|
286
|
+
if (rawDefaultValues) {
|
|
287
|
+
const defaultValues = {};
|
|
288
|
+
for (const field in rawDefaultValues) {
|
|
289
|
+
defaultValues[field] = this._dataUnit.valueFromString(field, rawDefaultValues[field]);
|
|
290
|
+
}
|
|
291
|
+
return defaultValues;
|
|
275
292
|
}
|
|
276
|
-
return
|
|
293
|
+
return undefined;
|
|
277
294
|
}
|
|
278
295
|
}
|
|
279
296
|
class Bind {
|
|
@@ -111,12 +111,23 @@ export const buildFormMetadata = (config, dataUnit, includeDetails = false) => {
|
|
|
111
111
|
}
|
|
112
112
|
let defaultValue = field.defaultValue == undefined ? (_c = descriptor.properties) === null || _c === void 0 ? void 0 : _c.defaultValue : field.defaultValue;
|
|
113
113
|
if (defaultValue) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
const { type, value } = defaultValue;
|
|
115
|
+
if (type) {
|
|
116
|
+
if (type === "V") {
|
|
117
|
+
defaultValue = value;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
try {
|
|
121
|
+
const parsed = JSON.parse(value);
|
|
122
|
+
if (parsed && "value" in parsed) {
|
|
123
|
+
defaultValue = parsed;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
defaultValue = value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (_d) { }
|
|
130
|
+
}
|
|
120
131
|
}
|
|
121
132
|
defaultValues[field.name] = defaultValue;
|
|
122
133
|
}
|