@schukai/monster 3.34.0 → 3.35.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/source/data/buildmap.mjs +72 -20
- package/source/data/buildtree.mjs +95 -12
- package/source/data/datasource/dom.mjs +7 -14
- package/source/data/datasource/server/restapi.mjs +8 -8
- package/source/data/transformer.mjs +13 -20
- package/source/dom/customelement.mjs +27 -36
- package/source/dom/dimension.mjs +23 -23
- package/source/dom/resourcemanager.mjs +11 -8
- package/source/dom/slotted.mjs +4 -5
- package/source/dom/updater.mjs +21 -21
- package/source/dom/util.mjs +1 -2
- package/source/i18n/formatter.mjs +6 -6
- package/source/i18n/locale.mjs +1 -1
- package/source/i18n/provider.mjs +11 -19
- package/source/i18n/providers/embed.mjs +11 -14
- package/source/i18n/translations.mjs +14 -18
- package/source/text/util.mjs +47 -18
- package/source/types/base.mjs +1 -1
- package/source/types/internal.mjs +27 -32
- package/source/types/version.mjs +1 -1
- package/source/util/runtime.mjs +55 -32
- package/test/cases/monster.mjs +1 -1
package/package.json
CHANGED
package/source/data/buildmap.mjs
CHANGED
@@ -19,27 +19,26 @@ export { buildMap, PARENT, assembleParts };
|
|
19
19
|
const PARENT = "^";
|
20
20
|
|
21
21
|
/**
|
22
|
-
*
|
22
|
+
* Maps can be easily created from data objects with the help of the function `buildMap()`.
|
23
23
|
*
|
24
|
-
*
|
24
|
+
* The path can be specified as either a simple definition a.b.c or a template ${a.b.c}.
|
25
25
|
* Key and value can be either a definition or a template. The key does not have to be defined.
|
26
|
-
*
|
27
26
|
* The templates determine the appearance of the keys and the value of the map. Either a single value
|
28
|
-
*
|
27
|
+
* id can be taken or a composite key ${id} ${name} can be used.
|
29
28
|
*
|
30
|
-
* If you want to access values of the parent data set, you have to use the
|
29
|
+
* If you want to access values of the parent data set, you have to use the ^ character, for example ${id} ${^.name}.
|
31
30
|
*
|
32
31
|
* @externalExample ../../example/data/buildmap.mjs
|
33
|
-
* @param {*} subject
|
34
|
-
* @param {string|Monster.Data~exampleSelectorCallback} selector
|
35
|
-
* @param {string} [valueTemplate]
|
36
|
-
* @param {string} [keyTemplate]
|
37
|
-
* @param {Monster.Data~exampleFilterCallback} [filter]
|
38
|
-
* @return {*}
|
32
|
+
* @param {*} subject - The data object from which the map will be created
|
33
|
+
* @param {string|Monster.Data~exampleSelectorCallback} selector - The path to the data object, or a callback that returns a map.
|
34
|
+
* @param {string} [valueTemplate] - A template for the value of the map.
|
35
|
+
* @param {string} [keyTemplate] - A template for the key of the map.
|
36
|
+
* @param {Monster.Data~exampleFilterCallback} [filter] - A callback function to filter out values.
|
37
|
+
* @return {*} - The created map.
|
39
38
|
* @memberOf Monster.Data
|
40
|
-
* @throws {TypeError} value is neither a string nor a function
|
41
|
-
* @throws {TypeError} the selector callback
|
42
|
-
|
39
|
+
* @throws {TypeError} - If the value is neither a string nor a function.
|
40
|
+
* @throws {TypeError} - If the selector callback does not return a map.
|
41
|
+
**/
|
43
42
|
function buildMap(subject, selector, valueTemplate, keyTemplate, filter) {
|
44
43
|
return assembleParts(subject, selector, filter, function (v, k, m) {
|
45
44
|
k = build(v, keyTemplate, k);
|
@@ -49,13 +48,66 @@ function buildMap(subject, selector, valueTemplate, keyTemplate, filter) {
|
|
49
48
|
}
|
50
49
|
|
51
50
|
/**
|
51
|
+
* The assembleParts function is a private function that helps in building a map from a subject object based on a provided
|
52
|
+
* selector. The selector can either be a string or a callback function. This function is meant to be used as a
|
53
|
+
* helper function by other functions in the module.
|
54
|
+
*
|
55
|
+
* The function takes four parameters:
|
56
|
+
*
|
57
|
+
* subject: The subject object from which the map is to be built
|
58
|
+
* selector: The selector to determine the structure of the map. It can be a string or a callback function.
|
59
|
+
* filter (optional): A callback function that can be used to filter values based on some criteria.
|
60
|
+
* callback: A function to be called for each element in the map.
|
61
|
+
* If the selector parameter is a callback function, it is executed passing the subject as its argument,
|
62
|
+
* and the resulting value must be an instance of Map. Otherwise, if the selector parameter is a string,
|
63
|
+
* buildFlatMap is called to build a flat map with keys and values extracted from the subject object based on the selector.
|
64
|
+
*
|
65
|
+
* If the filter parameter is provided, it will be used to filter out certain elements from the map, based on some
|
66
|
+
* criteria. The callback will be passed the value, key, and map object, and if it returns false, the element will be skipped.
|
67
|
+
*
|
68
|
+
* For each element in the map, the callback function is called with the following parameters:
|
69
|
+
*
|
70
|
+
* v: The value of the element
|
71
|
+
* k: The key of the element
|
72
|
+
* m: The map object
|
73
|
+
* The function returns a new map with the processed values. If map is not an instance of Map, an empty map will be returned.
|
74
|
+
*
|
75
|
+
* Example Usage:
|
76
|
+
*
|
77
|
+
* ```javascript
|
78
|
+
* const obj = {
|
79
|
+
* name: "John",
|
80
|
+
* age: 30,
|
81
|
+
* address: {
|
82
|
+
* city: "New York",
|
83
|
+
* state: "NY",
|
84
|
+
* country: "USA",
|
85
|
+
* },
|
86
|
+
* };
|
87
|
+
*
|
88
|
+
* const selector = "address";
|
89
|
+
*
|
90
|
+
* const map = assembleParts(obj, selector, null, function (v, k, m) {
|
91
|
+
* this.set(k, v);
|
92
|
+
* });
|
93
|
+
*
|
94
|
+
* console.log(map);
|
95
|
+
* // Output: Map(3) {
|
96
|
+
* // "address.city" => "New York",
|
97
|
+
* // "address.state" => "NY",
|
98
|
+
* // "address.country" => "USA"
|
99
|
+
* // }
|
100
|
+
* ```
|
101
|
+
*
|
102
|
+
*
|
52
103
|
* @private
|
53
|
-
* @param {*} subject
|
54
|
-
* @param {string|Monster.Data~exampleSelectorCallback} selector
|
55
|
-
* @param {Monster.Data~exampleFilterCallback} [filter]
|
56
|
-
* @param {function} callback
|
57
|
-
* @return {Map}
|
58
|
-
* @throws {TypeError} selector is neither a string nor a function
|
104
|
+
* @param {*} subject - The subject object from which the map is to be built.
|
105
|
+
* @param {string|Monster.Data~exampleSelectorCallback} selector - The selector to determine the structure of the map. It can be a string or a callback function.
|
106
|
+
* @param {Monster.Data~exampleFilterCallback} [filter] - A callback function that can be used to filter values based on some criteria.
|
107
|
+
* @param {function} callback - A function to be called for each element in the map.
|
108
|
+
* @return {Map} - A new map with the processed values.
|
109
|
+
* @throws {TypeError} - When selector is neither a string nor a function.
|
110
|
+
* @memberOf Monster.Data
|
59
111
|
*/
|
60
112
|
function assembleParts(subject, selector, filter, callback) {
|
61
113
|
const result = new Map();
|
@@ -33,19 +33,102 @@ const rootSymbol = Symbol("root");
|
|
33
33
|
*/
|
34
34
|
|
35
35
|
/**
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
43
|
-
*
|
44
|
-
*
|
45
|
-
*
|
46
|
-
*
|
47
|
-
*
|
36
|
+
* Creates a tree structure from a given subject using a selector and specified ID and parent ID keys.
|
37
|
+
*
|
38
|
+
* The buildTree function is a powerful tool for creating tree-like data structures from plain JavaScript
|
39
|
+
* objects. It takes in four required parameters: the subject object that you want to turn into a tree, a
|
40
|
+
* selector that identifies which parts of the subject to use when building the tree, and two keys
|
41
|
+
* (idKey and parentIDKey) that specify which properties in the subject represent the unique identifiers
|
42
|
+
* and parent-child relationships between nodes in the tree.
|
43
|
+
*
|
44
|
+
* Optionally, you can also pass in an options object to further configure the behavior of the function,
|
45
|
+
* such as specifying which values should be treated as roots of the tree, or providing a custom filter
|
46
|
+
* function to only include certain nodes in the final output.
|
47
|
+
*
|
48
|
+
* The buildTree function works by first using the assembleParts helper function to extract the relevant
|
49
|
+
* parts of the subject based on the selector, and then iterates over the resulting map to create Node
|
50
|
+
* objects and organize them into parent-child relationships based on the values of the idKey and parentIDKey properties.
|
51
|
+
*
|
52
|
+
* The resulting NodeList represents the tree structure, with each Node object containing the original
|
53
|
+
* object data as well as additional metadata about its position in the tree. You can then use the childNodes
|
54
|
+
* property of each Node to access its children, or the parent property to access its parent.
|
55
|
+
*
|
56
|
+
* Overall, the buildTree function is a flexible and powerful way to transform flat data into hierarchical
|
57
|
+
* structures, and can be especially useful in scenarios such as displaying folder structures or
|
58
|
+
* visualizing complex data relationships.
|
59
|
+
*
|
60
|
+
* Let's say you have an array of data objects representing a file system directory structure, and you want
|
61
|
+
* to turn it into a tree-like structure where each node represents a folder or file, and child nodes
|
62
|
+
* represent the contents of the folder:
|
63
|
+
*
|
64
|
+
* ```javascript
|
65
|
+
* const fileSystem = [
|
66
|
+
* { id: 'folder1', name: 'Folder 1', type: 'folder', parent: null },
|
67
|
+
* { id: 'file1', name: 'File 1', type: 'file', parent: 'folder1' },
|
68
|
+
* { id: 'file2', name: 'File 2', type: 'file', parent: 'folder1' },
|
69
|
+
* { id: 'subfolder1', name: 'Subfolder 1', type: 'folder', parent: 'folder1' },
|
70
|
+
* { id: 'file3', name: 'File 3', type: 'file', parent: 'subfolder1' },
|
71
|
+
* { id: 'file4', name: 'File 4', type: 'file', parent: 'subfolder1' },
|
72
|
+
* { id: 'subfolder2', name: 'Subfolder 2', type: 'folder', parent: 'folder1' },
|
73
|
+
* { id: 'file5', name: 'File 5', type: 'file', parent: 'subfolder2' },
|
74
|
+
* { id: 'file6', name: 'File 6', type: 'file', parent: 'subfolder2' },
|
75
|
+
* { id: 'folder2', name: 'Folder 2', type: 'folder', parent: null },
|
76
|
+
* { id: 'file7', name: 'File 7', type: 'file', parent: 'folder2' },
|
77
|
+
* { id: 'file8', name: 'File 8', type: 'file', parent: 'folder2' },
|
78
|
+
* { id: 'subfolder3', name: 'Subfolder 3', type: 'folder', parent: 'folder2' },
|
79
|
+
* { id: 'file9', name: 'File 9', type: 'file', parent: 'subfolder3' },
|
80
|
+
* { id: 'file10', name: 'File 10', type: 'file', parent: 'subfolder3' },
|
81
|
+
* ];
|
82
|
+
*
|
83
|
+
* const tree = buildTree(fileSystem, 'id', 'id', 'parent', { rootReferences: [null] });
|
84
|
+
*
|
85
|
+
* console.log(tree.toString());
|
86
|
+
* ```
|
87
|
+
*
|
88
|
+
* The buildTree function takes in the array of data objects, as well as some configuration options specifying
|
89
|
+
* the keys to use for identifying nodes and their parent-child relationships. In this example, we use the id
|
90
|
+
* key to identify nodes, and the parent key to specify the parent of each node.
|
91
|
+
*
|
92
|
+
* The resulting tree object is a nested tree structure, where each node is an object representing a file or
|
93
|
+
* folder, and has child nodes representing its contents. The toString method of the tree object
|
94
|
+
* can be used to print out the tree in a readable format:
|
95
|
+
*
|
96
|
+
* ```markdown
|
97
|
+
* - Folder 1
|
98
|
+
* - File 1
|
99
|
+
* - File 2
|
100
|
+
* - Subfolder 1
|
101
|
+
* - File 3
|
102
|
+
* - File 4
|
103
|
+
* - Subfolder 2
|
104
|
+
* - File 5
|
105
|
+
* - File 6
|
106
|
+
* - Folder 2
|
107
|
+
* - File 7
|
108
|
+
* - File 8
|
109
|
+
* - Subfolder 3
|
110
|
+
* - File 9
|
111
|
+
* - File 10
|
112
|
+
* ```
|
113
|
+
*
|
114
|
+
* @memberof Monster.Data
|
115
|
+
*
|
116
|
+
* @param {*} subject - The object or array to build the tree from.
|
117
|
+
* @param {string|Monster.Data~exampleSelectorCallback} selector - Either a string to specify a property of each object to use as a selector, or a selector function to generate a map of objects.
|
118
|
+
* @param {string} idKey - The property key to use as the unique ID of each node.
|
119
|
+
* @param {string} parentIDKey - The property key to use as the parent ID of each node.
|
120
|
+
* @param {object} [options] - Additional options to modify the function behavior.
|
121
|
+
* @param {Array<*>} [options.rootReferences=[null, undefined]] - An array of values to treat as root references when creating the tree.
|
122
|
+
* @param {function} [options.filter] - A filter function to apply to each node.
|
123
|
+
*
|
124
|
+
* @return {*} The resulting tree structure as a NodeList.
|
125
|
+
*
|
126
|
+
* @throws {TypeError} selector is neither a string nor a function.
|
127
|
+
* @throws {TypeError} the selector callback must return a map.
|
128
|
+
* @throws {Error} the object has no value for the specified id.
|
129
|
+
*
|
48
130
|
* @license AGPLv3
|
131
|
+
*
|
49
132
|
* @since 1.26.0
|
50
133
|
*/
|
51
134
|
function buildTree(subject, selector, idKey, parentIDKey, options) {
|
@@ -5,12 +5,11 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {
|
9
|
-
import {
|
8
|
+
import { instanceSymbol } from "../../constants.mjs";
|
9
|
+
import { isObject } from "../../types/is.mjs";
|
10
10
|
import { Datasource } from "../datasource.mjs";
|
11
11
|
|
12
|
-
export {DomStorage};
|
13
|
-
|
12
|
+
export { DomStorage };
|
14
13
|
|
15
14
|
/**
|
16
15
|
* The DomStorage is a class that stores data in memory.
|
@@ -53,7 +52,7 @@ class DomStorage extends Datasource {
|
|
53
52
|
},
|
54
53
|
write: {
|
55
54
|
selector: undefined,
|
56
|
-
}
|
55
|
+
},
|
57
56
|
});
|
58
57
|
}
|
59
58
|
|
@@ -78,13 +77,12 @@ class DomStorage extends Datasource {
|
|
78
77
|
return new Promise((resolve, reject) => {
|
79
78
|
try {
|
80
79
|
let data = JSON.parse(storage.innerHTML);
|
81
|
-
self.set(data)
|
80
|
+
self.set(data);
|
82
81
|
resolve(data);
|
83
82
|
} catch (e) {
|
84
83
|
reject(e);
|
85
84
|
}
|
86
|
-
|
87
|
-
})
|
85
|
+
});
|
88
86
|
}
|
89
87
|
|
90
88
|
/**
|
@@ -93,7 +91,6 @@ class DomStorage extends Datasource {
|
|
93
91
|
* @throws {Error} There are no storage element
|
94
92
|
*/
|
95
93
|
write() {
|
96
|
-
|
97
94
|
const self = this;
|
98
95
|
|
99
96
|
let selector = self.getOption("write.selector");
|
@@ -113,10 +110,6 @@ class DomStorage extends Datasource {
|
|
113
110
|
} catch (e) {
|
114
111
|
reject(e);
|
115
112
|
}
|
116
|
-
})
|
117
|
-
|
118
|
-
|
113
|
+
});
|
119
114
|
}
|
120
|
-
|
121
115
|
}
|
122
|
-
|
@@ -6,7 +6,7 @@
|
|
6
6
|
*/
|
7
7
|
|
8
8
|
import { internalSymbol, instanceSymbol } from "../../../constants.mjs";
|
9
|
-
import { isObject,isFunction } from "../../../types/is.mjs";
|
9
|
+
import { isObject, isFunction } from "../../../types/is.mjs";
|
10
10
|
import { Server } from "../server.mjs";
|
11
11
|
import { WriteError } from "./restapi/writeerror.mjs";
|
12
12
|
|
@@ -127,11 +127,12 @@ class RestAPI extends Server {
|
|
127
127
|
if (!init["method"]) init["method"] = "GET";
|
128
128
|
|
129
129
|
let callback = self.getOption("read.responseCallback");
|
130
|
-
if(!callback)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
130
|
+
if (!callback)
|
131
|
+
callback = (obj) => {
|
132
|
+
self.set(self.transformServerPayload.call(self, obj));
|
133
|
+
};
|
134
|
+
|
135
|
+
return fetchData.call(this, init, "read", callback);
|
135
136
|
}
|
136
137
|
|
137
138
|
/**
|
@@ -199,7 +200,6 @@ function fetchData(init, key, callback) {
|
|
199
200
|
obj = JSON.parse(body);
|
200
201
|
|
201
202
|
response[rawDataSymbol] = obj;
|
202
|
-
|
203
203
|
} catch (e) {
|
204
204
|
if (body.length > 100) {
|
205
205
|
body = `${body.substring(0, 97)}...`;
|
@@ -211,7 +211,7 @@ function fetchData(init, key, callback) {
|
|
211
211
|
if (callback && isFunction(callback)) {
|
212
212
|
callback(obj);
|
213
213
|
}
|
214
|
-
|
214
|
+
|
215
215
|
return response;
|
216
216
|
});
|
217
217
|
}
|
@@ -5,12 +5,12 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {getLocaleOfDocument} from "../dom/locale.mjs";
|
9
|
-
import {Base} from "../types/base.mjs";
|
10
|
-
import {getGlobal, getGlobalObject} from "../types/global.mjs";
|
11
|
-
import {ID} from "../types/id.mjs";
|
12
|
-
import {isArray, isObject, isString, isPrimitive} from "../types/is.mjs";
|
13
|
-
import {getDocumentTranslations, Translations} from "../i18n/translations.mjs";
|
8
|
+
import { getLocaleOfDocument } from "../dom/locale.mjs";
|
9
|
+
import { Base } from "../types/base.mjs";
|
10
|
+
import { getGlobal, getGlobalObject } from "../types/global.mjs";
|
11
|
+
import { ID } from "../types/id.mjs";
|
12
|
+
import { isArray, isObject, isString, isPrimitive } from "../types/is.mjs";
|
13
|
+
import { getDocumentTranslations, Translations } from "../i18n/translations.mjs";
|
14
14
|
import {
|
15
15
|
validateFunction,
|
16
16
|
validateInteger,
|
@@ -19,10 +19,10 @@ import {
|
|
19
19
|
validateString,
|
20
20
|
validateBoolean,
|
21
21
|
} from "../types/validate.mjs";
|
22
|
-
import {clone} from "../util/clone.mjs";
|
23
|
-
import {Pathfinder} from "./pathfinder.mjs";
|
22
|
+
import { clone } from "../util/clone.mjs";
|
23
|
+
import { Pathfinder } from "./pathfinder.mjs";
|
24
24
|
|
25
|
-
export {Transformer};
|
25
|
+
export { Transformer };
|
26
26
|
|
27
27
|
/**
|
28
28
|
* The transformer class is a swiss army knife for manipulating values. especially in combination with the pipe, processing chains can be built up.
|
@@ -576,7 +576,6 @@ function transform(value) {
|
|
576
576
|
|
577
577
|
throw new Error("type not supported");
|
578
578
|
|
579
|
-
|
580
579
|
case "map":
|
581
580
|
map = new Map();
|
582
581
|
while (args.length > 0) {
|
@@ -592,7 +591,6 @@ function transform(value) {
|
|
592
591
|
return map.get(value);
|
593
592
|
|
594
593
|
case "equals":
|
595
|
-
|
596
594
|
if (args.length === 0) {
|
597
595
|
throw new Error("missing value parameter");
|
598
596
|
}
|
@@ -631,11 +629,10 @@ function transform(value) {
|
|
631
629
|
|
632
630
|
case "money":
|
633
631
|
case "currency":
|
634
|
-
|
635
632
|
try {
|
636
633
|
locale = getLocaleOfDocument();
|
637
634
|
} catch (e) {
|
638
|
-
throw new Error(
|
635
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
639
636
|
}
|
640
637
|
|
641
638
|
const currency = value.substring(0, 3);
|
@@ -672,9 +669,8 @@ function transform(value) {
|
|
672
669
|
try {
|
673
670
|
locale = getLocaleOfDocument();
|
674
671
|
return date.toLocaleTimeString(locale);
|
675
|
-
|
676
672
|
} catch (e) {
|
677
|
-
throw new Error(
|
673
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
678
674
|
}
|
679
675
|
|
680
676
|
case "datetime":
|
@@ -686,9 +682,8 @@ function transform(value) {
|
|
686
682
|
try {
|
687
683
|
locale = getLocaleOfDocument();
|
688
684
|
return date.toLocaleString(locale);
|
689
|
-
|
690
685
|
} catch (e) {
|
691
|
-
throw new Error(
|
686
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
692
687
|
}
|
693
688
|
|
694
689
|
case "date":
|
@@ -700,12 +695,10 @@ function transform(value) {
|
|
700
695
|
try {
|
701
696
|
locale = getLocaleOfDocument();
|
702
697
|
return date.toLocaleDateString(locale);
|
703
|
-
|
704
698
|
} catch (e) {
|
705
|
-
throw new Error(
|
699
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
706
700
|
}
|
707
701
|
|
708
|
-
|
709
702
|
case "year":
|
710
703
|
date = new Date(value);
|
711
704
|
if (isNaN(date.getTime())) {
|
@@ -5,19 +5,19 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {internalSymbol} from "../constants.mjs";
|
9
|
-
import {extend} from "../data/extend.mjs";
|
10
|
-
import {Pathfinder} from "../data/pathfinder.mjs";
|
11
|
-
import {Formatter} from "../text/formatter.mjs";
|
12
|
-
|
13
|
-
import {parseDataURL} from "../types/dataurl.mjs";
|
14
|
-
import {getGlobalObject} from "../types/global.mjs";
|
15
|
-
import {isArray, isFunction, isIterable, isObject, isString} from "../types/is.mjs";
|
16
|
-
import {Observer} from "../types/observer.mjs";
|
17
|
-
import {ProxyObserver} from "../types/proxyobserver.mjs";
|
18
|
-
import {validateFunction, validateInstance, validateObject, validateString} from "../types/validate.mjs";
|
19
|
-
import {clone} from "../util/clone.mjs";
|
20
|
-
import {addAttributeToken, getLinkedObjects, hasObjectLink} from "./attributes.mjs";
|
8
|
+
import { internalSymbol } from "../constants.mjs";
|
9
|
+
import { extend } from "../data/extend.mjs";
|
10
|
+
import { Pathfinder } from "../data/pathfinder.mjs";
|
11
|
+
import { Formatter } from "../text/formatter.mjs";
|
12
|
+
|
13
|
+
import { parseDataURL } from "../types/dataurl.mjs";
|
14
|
+
import { getGlobalObject } from "../types/global.mjs";
|
15
|
+
import { isArray, isFunction, isIterable, isObject, isString } from "../types/is.mjs";
|
16
|
+
import { Observer } from "../types/observer.mjs";
|
17
|
+
import { ProxyObserver } from "../types/proxyobserver.mjs";
|
18
|
+
import { validateFunction, validateInstance, validateObject, validateString } from "../types/validate.mjs";
|
19
|
+
import { clone } from "../util/clone.mjs";
|
20
|
+
import { addAttributeToken, getLinkedObjects, hasObjectLink } from "./attributes.mjs";
|
21
21
|
import {
|
22
22
|
ATTRIBUTE_DISABLED,
|
23
23
|
ATTRIBUTE_ERRORMESSAGE,
|
@@ -25,11 +25,11 @@ import {
|
|
25
25
|
ATTRIBUTE_OPTIONS_SELECTOR,
|
26
26
|
customElementUpdaterLinkSymbol,
|
27
27
|
} from "./constants.mjs";
|
28
|
-
import {findDocumentTemplate, Template} from "./template.mjs";
|
29
|
-
import {addObjectWithUpdaterToElement} from "./updater.mjs";
|
30
|
-
import {instanceSymbol} from "../constants.mjs";
|
31
|
-
import {getDocumentTranslations, Translations} from "../i18n/translations.mjs";
|
32
|
-
import {getSlottedElements} from "./slotted.mjs";
|
28
|
+
import { findDocumentTemplate, Template } from "./template.mjs";
|
29
|
+
import { addObjectWithUpdaterToElement } from "./updater.mjs";
|
30
|
+
import { instanceSymbol } from "../constants.mjs";
|
31
|
+
import { getDocumentTranslations, Translations } from "../i18n/translations.mjs";
|
32
|
+
import { getSlottedElements } from "./slotted.mjs";
|
33
33
|
|
34
34
|
export {
|
35
35
|
CustomElement,
|
@@ -286,7 +286,6 @@ class CustomElement extends HTMLElement {
|
|
286
286
|
};
|
287
287
|
}
|
288
288
|
|
289
|
-
|
290
289
|
/**
|
291
290
|
* This method updates the labels of the element.
|
292
291
|
* The labels are defined in the options object.
|
@@ -315,26 +314,25 @@ class CustomElement extends HTMLElement {
|
|
315
314
|
if (isString(def)) {
|
316
315
|
const text = translations.getText(key, def);
|
317
316
|
if (text !== def) {
|
318
|
-
this.setOption(
|
317
|
+
this.setOption(`labels.${key}`, text);
|
319
318
|
}
|
320
319
|
continue;
|
321
320
|
} else if (isObject(def)) {
|
322
321
|
for (const k in def) {
|
323
322
|
const d = def[k];
|
324
|
-
|
323
|
+
|
325
324
|
const text = translations.getPluralRuleText(key, k, d);
|
326
325
|
if (!isString(text)) {
|
327
326
|
throw new Error("Invalid labels definition");
|
328
327
|
}
|
329
328
|
if (text !== d) {
|
330
|
-
this.setOption(
|
329
|
+
this.setOption(`labels.${key}.${k}`, text);
|
331
330
|
}
|
332
331
|
}
|
333
332
|
continue;
|
334
333
|
}
|
335
334
|
|
336
335
|
throw new Error("Invalid labels definition");
|
337
|
-
|
338
336
|
}
|
339
337
|
return this;
|
340
338
|
}
|
@@ -352,7 +350,6 @@ class CustomElement extends HTMLElement {
|
|
352
350
|
throw new Error("the method getTag must be overwritten by the derived class.");
|
353
351
|
}
|
354
352
|
|
355
|
-
|
356
353
|
/**
|
357
354
|
* At this point a `CSSStyleSheet` object can be returned. If the environment does not
|
358
355
|
* support a constructor, then an object can also be built using the following detour.
|
@@ -422,8 +419,7 @@ class CustomElement extends HTMLElement {
|
|
422
419
|
|
423
420
|
try {
|
424
421
|
value = new Pathfinder(this[internalSymbol].getRealSubject()["options"]).getVia(path);
|
425
|
-
} catch (e) {
|
426
|
-
}
|
422
|
+
} catch (e) {}
|
427
423
|
|
428
424
|
if (value === undefined) return defaultValue;
|
429
425
|
return value;
|
@@ -493,8 +489,7 @@ class CustomElement extends HTMLElement {
|
|
493
489
|
try {
|
494
490
|
initShadowRoot.call(self);
|
495
491
|
elements = self.shadowRoot.childNodes;
|
496
|
-
} catch (e) {
|
497
|
-
}
|
492
|
+
} catch (e) {}
|
498
493
|
|
499
494
|
try {
|
500
495
|
initCSSStylesheet.call(this);
|
@@ -545,8 +540,7 @@ class CustomElement extends HTMLElement {
|
|
545
540
|
* @return {void}
|
546
541
|
* @since 1.7.0
|
547
542
|
*/
|
548
|
-
disconnectedCallback() {
|
549
|
-
}
|
543
|
+
disconnectedCallback() {}
|
550
544
|
|
551
545
|
/**
|
552
546
|
* The custom element has been moved into a new document (e.g. someone called document.adoptNode(el)).
|
@@ -554,8 +548,7 @@ class CustomElement extends HTMLElement {
|
|
554
548
|
* @return {void}
|
555
549
|
* @since 1.7.0
|
556
550
|
*/
|
557
|
-
adoptedCallback() {
|
558
|
-
}
|
551
|
+
adoptedCallback() {}
|
559
552
|
|
560
553
|
/**
|
561
554
|
* Called when an observed attribute has been added, removed, updated, or replaced. Also called for initial
|
@@ -792,8 +785,7 @@ function parseOptionsJSON(data) {
|
|
792
785
|
try {
|
793
786
|
let dataUrl = parseDataURL(data);
|
794
787
|
data = dataUrl.content;
|
795
|
-
} catch (e) {
|
796
|
-
}
|
788
|
+
} catch (e) {}
|
797
789
|
|
798
790
|
try {
|
799
791
|
obj = JSON.parse(data);
|
@@ -815,7 +807,6 @@ function initHtmlContent() {
|
|
815
807
|
} catch (e) {
|
816
808
|
let html = this.getOption("templates.main", "");
|
817
809
|
if (isString(html) && html.length > 0) {
|
818
|
-
|
819
810
|
const mapping = this.getOption("templateMapping", {});
|
820
811
|
if (isObject(mapping)) {
|
821
812
|
html = new Formatter(mapping).format(html);
|
@@ -938,7 +929,7 @@ function initShadowRoot() {
|
|
938
929
|
*/
|
939
930
|
function registerCustomElement(element) {
|
940
931
|
validateFunction(element);
|
941
|
-
const customElements = getGlobalObject("customElements")
|
932
|
+
const customElements = getGlobalObject("customElements");
|
942
933
|
if (customElements === undefined) {
|
943
934
|
throw new Error("customElements is not supported.");
|
944
935
|
}
|