@schukai/monster 3.106.1 → 3.108.0
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/CHANGELOG.md +19 -0
- package/package.json +1 -1
- package/source/components/datatable/filter.mjs +21 -10
- package/source/components/datatable/save-button.mjs +8 -10
- package/source/components/form/select.mjs +2236 -2217
- package/source/components/form/tree-select.mjs +45 -5
- package/source/data/buildmap.mjs +1 -1
- package/source/data/datasource/server/restapi.mjs +3 -3
- package/source/data/transformer.mjs +34 -1
- package/source/dom/updater.mjs +858 -854
- package/source/i18n/internal.mjs +103 -109
- package/source/i18n/map/languages.mjs +1 -3
- package/source/monster.mjs +1 -0
- package/source/types/global.mjs +45 -46
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +478 -149
@@ -41,6 +41,7 @@ import { ATTRIBUTE_FORM_URL, ATTRIBUTE_INTEND } from "./constants.mjs";
|
|
41
41
|
import { Select } from "./select.mjs";
|
42
42
|
import { SelectStyleSheet } from "./stylesheet/select.mjs";
|
43
43
|
import { TreeSelectStyleSheet } from "./stylesheet/tree-select.mjs";
|
44
|
+
import { addErrorAttribute } from "../../dom/error.mjs";
|
44
45
|
|
45
46
|
export { TreeSelect, formatHierarchicalSelection };
|
46
47
|
|
@@ -92,6 +93,9 @@ class TreeSelect extends Select {
|
|
92
93
|
* @property {String} mapping.idTemplate=id
|
93
94
|
* @property {String} mapping.parentTemplate=parent
|
94
95
|
* @property {String} mapping.selection
|
96
|
+
* @property {String} mapping.labelTemplate
|
97
|
+
* @property {String} mapping.valueTemplate
|
98
|
+
* @property {String} mapping.filter The filter function to apply to each node, you can use run: syntax to execute a function, or use call:filterValueOfAttribute:data-my-attribute.
|
95
99
|
* @property {Object} formatter
|
96
100
|
* @property {String} formatter.separator=" / "
|
97
101
|
*/
|
@@ -108,6 +112,8 @@ class TreeSelect extends Select {
|
|
108
112
|
selector: "*",
|
109
113
|
labelTemplate: "",
|
110
114
|
valueTemplate: "",
|
115
|
+
|
116
|
+
filter: null,
|
111
117
|
},
|
112
118
|
formatter: {
|
113
119
|
selection: formatHierarchicalSelection,
|
@@ -146,15 +152,49 @@ class TreeSelect extends Select {
|
|
146
152
|
* @throws {Error} map is not iterable
|
147
153
|
*/
|
148
154
|
importOptions(data) {
|
155
|
+
const self = this;
|
156
|
+
|
149
157
|
this[internalNodesSymbol] = new Map();
|
150
158
|
|
159
|
+
const id = this.getOption("mapping.id", "id");
|
160
|
+
const parentID = this.getOption("mapping.parent", "parent");
|
161
|
+
|
151
162
|
const mappingOptions = this.getOption("mapping", {});
|
152
163
|
|
153
|
-
|
154
|
-
|
164
|
+
let filter = mappingOptions?.["filter"];
|
165
|
+
|
166
|
+
if (isString(filter)) {
|
167
|
+
if (0 === filter.indexOf("run:")) {
|
168
|
+
const code = filter.replace("run:", "");
|
169
|
+
filter = (m, v, k) => {
|
170
|
+
const fkt = new Function("m", "v", "k", "control", code);
|
171
|
+
return fkt(m, v, k, self);
|
172
|
+
};
|
173
|
+
} else if (0 === filter.indexOf("call:")) {
|
174
|
+
const parts = filter.split(":");
|
175
|
+
parts.shift(); // remove prefix
|
176
|
+
const fkt = parts.shift();
|
177
|
+
|
178
|
+
switch (fkt) {
|
179
|
+
case "filterValueOfAttribute":
|
180
|
+
const attribute = parts.shift();
|
181
|
+
const attrValue = self.getAttribute(attribute);
|
182
|
+
|
183
|
+
filter = (m, v, k) => {
|
184
|
+
return m?.[id] != attrValue; // no type check, no !==
|
185
|
+
};
|
186
|
+
break;
|
187
|
+
|
188
|
+
default:
|
189
|
+
addErrorAttribute(
|
190
|
+
this,
|
191
|
+
new Error(`Unknown filter function ${fkt}`),
|
192
|
+
);
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
155
196
|
|
156
|
-
const
|
157
|
-
const parentID = this.getOption("mapping.parent", "parent");
|
197
|
+
const rootReferences = mappingOptions?.["rootReferences"];
|
158
198
|
|
159
199
|
const selector = mappingOptions?.["selector"];
|
160
200
|
const options = [];
|
@@ -196,7 +236,7 @@ class TreeSelect extends Select {
|
|
196
236
|
options,
|
197
237
|
});
|
198
238
|
} catch (e) {
|
199
|
-
|
239
|
+
addErrorAttribute(this, e);
|
200
240
|
}
|
201
241
|
|
202
242
|
return this;
|
package/source/data/buildmap.mjs
CHANGED
@@ -361,7 +361,7 @@ function buildFlatMap(subject, selector, key, parentMap) {
|
|
361
361
|
* @param {*} defaultValue
|
362
362
|
* @return {*}
|
363
363
|
*/
|
364
|
-
function build(subject, definition, defaultValue) {
|
364
|
+
export function build(subject, definition, defaultValue) {
|
365
365
|
if (definition === undefined) return defaultValue ? defaultValue : subject;
|
366
366
|
validateString(definition);
|
367
367
|
|
@@ -19,7 +19,7 @@ import { Server } from "../server.mjs";
|
|
19
19
|
import { WriteError } from "./restapi/writeerror.mjs";
|
20
20
|
import { DataFetchError } from "./restapi/data-fetch-error.mjs";
|
21
21
|
import { clone } from "../../../util/clone.mjs";
|
22
|
-
import {getInternalLocalizationMessage} from "../../../i18n/internal.mjs";
|
22
|
+
import { getInternalLocalizationMessage } from "../../../i18n/internal.mjs";
|
23
23
|
|
24
24
|
export { RestAPI };
|
25
25
|
|
@@ -226,7 +226,7 @@ function fetchData(init, key, callback) {
|
|
226
226
|
if (acceptedStatus.indexOf(resp.status) === -1) {
|
227
227
|
throw new DataFetchError(
|
228
228
|
getInternalLocalizationMessage(
|
229
|
-
|
229
|
+
`i18n{the-response-does-not-contain-an-accepted-status::status=${resp.status}}`,
|
230
230
|
),
|
231
231
|
response,
|
232
232
|
);
|
@@ -248,7 +248,7 @@ function fetchData(init, key, callback) {
|
|
248
248
|
|
249
249
|
throw new DataFetchError(
|
250
250
|
getInternalLocalizationMessage(
|
251
|
-
`i18n{the-response-does-not-contain-a-valid-json::actual=${body}}
|
251
|
+
`i18n{the-response-does-not-contain-a-valid-json::actual=${body}}`,
|
252
252
|
),
|
253
253
|
response,
|
254
254
|
);
|
@@ -23,6 +23,7 @@ import {
|
|
23
23
|
} from "../i18n/translations.mjs";
|
24
24
|
import {
|
25
25
|
validateFunction,
|
26
|
+
validateArray,
|
26
27
|
validateInteger,
|
27
28
|
validateObject,
|
28
29
|
validatePrimitive,
|
@@ -286,6 +287,30 @@ function transform(value) {
|
|
286
287
|
validateInteger(n);
|
287
288
|
return n;
|
288
289
|
|
290
|
+
case "to-array":
|
291
|
+
case "toarray":
|
292
|
+
if (isArray(value)) {
|
293
|
+
return value;
|
294
|
+
}
|
295
|
+
|
296
|
+
if (isObject(value)) {
|
297
|
+
return Object.values(value);
|
298
|
+
}
|
299
|
+
|
300
|
+
return [value];
|
301
|
+
|
302
|
+
case "listtoarray":
|
303
|
+
case "list-to-array":
|
304
|
+
validateString(value);
|
305
|
+
const listDel = args.shift() || ",";
|
306
|
+
return value.split(listDel);
|
307
|
+
|
308
|
+
case "arraytolist":
|
309
|
+
case "array-to-list":
|
310
|
+
validateArray(value);
|
311
|
+
const listDel2 = args.shift() || ",";
|
312
|
+
return value.join(listDel2);
|
313
|
+
|
289
314
|
case "to-json":
|
290
315
|
case "tojson":
|
291
316
|
return JSON.stringify(value);
|
@@ -398,7 +423,10 @@ function transform(value) {
|
|
398
423
|
|
399
424
|
case "debug":
|
400
425
|
if (isObject(console)) {
|
401
|
-
console.
|
426
|
+
console.groupCollapsed("Transformer Debug");
|
427
|
+
console.log("Value", value);
|
428
|
+
console.log("Transformer", this);
|
429
|
+
console.groupEnd();
|
402
430
|
}
|
403
431
|
|
404
432
|
return value;
|
@@ -581,6 +609,11 @@ function transform(value) {
|
|
581
609
|
defaultValue === "true" ||
|
582
610
|
defaultValue === "true"
|
583
611
|
);
|
612
|
+
case "array":
|
613
|
+
if (defaultValue === "") {
|
614
|
+
return [];
|
615
|
+
}
|
616
|
+
return defaultValue.split(",");
|
584
617
|
case "string":
|
585
618
|
return `${defaultValue}`;
|
586
619
|
case "object":
|