@schukai/monster 3.73.5 → 3.73.6
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +9 -1
- package/package.json +1 -1
- package/source/components/datatable/save-button.mjs +264 -262
- package/source/components/form/button.mjs +0 -1
- package/source/components/form/select.mjs +33 -83
- package/source/components/tree-menu/tree-menu.mjs +2 -2
- package/source/data/buildtree.mjs +64 -57
- package/source/types/node.mjs +144 -134
- package/source/types/version.mjs +1 -1
- package/test/cases/data/buildtree.mjs +49 -0
- package/test/cases/dom/resource/data.mjs +1 -1
- package/test/cases/dom/resource/link/stylesheet.mjs +1 -1
- package/test/cases/dom/resource/link.mjs +1 -1
- package/test/cases/dom/resource/script.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +63 -16
package/source/types/node.mjs
CHANGED
@@ -12,13 +12,13 @@
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
13
13
|
*/
|
14
14
|
|
15
|
-
import {
|
16
|
-
import {
|
17
|
-
import {
|
18
|
-
import {
|
19
|
-
import {
|
15
|
+
import {Base} from "./base.mjs";
|
16
|
+
import {isPrimitive} from "./is.mjs";
|
17
|
+
import {NodeList} from "./nodelist.mjs";
|
18
|
+
import {validateInstance} from "./validate.mjs";
|
19
|
+
import {instanceSymbol} from "../constants.mjs";
|
20
20
|
|
21
|
-
export {
|
21
|
+
export {Node};
|
22
22
|
|
23
23
|
/**
|
24
24
|
* @private
|
@@ -43,120 +43,120 @@ const treeStructureSymbol = Symbol("treeStructure");
|
|
43
43
|
* @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Iteration_protocols
|
44
44
|
*/
|
45
45
|
class Node extends Base {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
46
|
+
/**
|
47
|
+
* @param {*} [value]
|
48
|
+
*/
|
49
|
+
constructor(value) {
|
50
|
+
super();
|
51
|
+
this[internalValueSymbol] = value;
|
52
|
+
|
53
|
+
this[treeStructureSymbol] = {
|
54
|
+
parent: null,
|
55
|
+
childNodes: new NodeList(),
|
56
|
+
level: 0,
|
57
|
+
};
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* This method is called by the `instanceof` operator.
|
62
|
+
* @returns {symbol}
|
63
|
+
* @since 2.1.0
|
64
|
+
*/
|
65
|
+
static get [instanceSymbol]() {
|
66
|
+
return Symbol.for("@schukai/monster/types/node");
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @property {*}
|
71
|
+
*/
|
72
|
+
get value() {
|
73
|
+
return this[internalValueSymbol];
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @property {*}
|
78
|
+
*/
|
79
|
+
set value(value) {
|
80
|
+
this[internalValueSymbol] = value;
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @property {Monster.Types.Node|null}
|
85
|
+
*/
|
86
|
+
get parent() {
|
87
|
+
return this[treeStructureSymbol].parent;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* @property {integer}
|
92
|
+
*/
|
93
|
+
get level() {
|
94
|
+
return this[treeStructureSymbol].level;
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
*
|
99
|
+
* @property {NodeList}
|
100
|
+
*/
|
101
|
+
get childNodes() {
|
102
|
+
return this[treeStructureSymbol].childNodes;
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
*
|
107
|
+
* @property {NodeList}
|
108
|
+
*/
|
109
|
+
set childNodes(childNodes) {
|
110
|
+
this[treeStructureSymbol].childNodes = validateInstance(
|
111
|
+
childNodes,
|
112
|
+
NodeList,
|
113
|
+
);
|
114
|
+
setChildLevelAndParent.call(this, this, 1, new Set());
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* @return {Monster.Types.Node}
|
119
|
+
* @param {Node} node
|
120
|
+
*/
|
121
|
+
appendChild(node) {
|
122
|
+
this[treeStructureSymbol].childNodes.add(validateInstance(node, Node));
|
123
|
+
node[treeStructureSymbol].parent = this;
|
124
|
+
|
125
|
+
node[treeStructureSymbol].level = this.level + 1;
|
126
|
+
setChildLevelAndParent.call(this, node, 1, new Set());
|
127
|
+
return this;
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* @return {Monster.Types.Node}
|
132
|
+
* @param {Node} node
|
133
|
+
*/
|
134
|
+
removeChild(node) {
|
135
|
+
this[treeStructureSymbol].childNodes.remove(validateInstance(node, Node));
|
136
|
+
node[treeStructureSymbol].parent = null;
|
137
|
+
|
138
|
+
node[treeStructureSymbol].level = 0;
|
139
|
+
setChildLevelAndParent.call(this, node, -1, new Set());
|
140
|
+
return this;
|
141
|
+
}
|
142
|
+
|
143
|
+
/**
|
144
|
+
*
|
145
|
+
* @return {boolean}
|
146
|
+
*/
|
147
|
+
hasChildNodes() {
|
148
|
+
return this[treeStructureSymbol].childNodes.length > 0;
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* @return {Monster.Types.Node}
|
153
|
+
* @param {Node} node
|
154
|
+
*/
|
155
|
+
hasChild(node) {
|
156
|
+
return this[treeStructureSymbol].childNodes.has(
|
157
|
+
validateInstance(node, Node),
|
158
|
+
);
|
159
|
+
}
|
160
160
|
|
161
161
|
/**
|
162
162
|
* @since 1.28.0
|
@@ -192,24 +192,34 @@ class Node extends Base {
|
|
192
192
|
}
|
193
193
|
}
|
194
194
|
|
195
|
+
|
195
196
|
/**
|
196
197
|
* @private
|
197
198
|
* @param {Node} node
|
198
199
|
* @param {int} operand
|
200
|
+
* @param {Set} visitedNodes
|
199
201
|
* @return {setChildLevelAndParent}
|
200
202
|
*/
|
201
|
-
function setChildLevelAndParent(node, operand) {
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
203
|
+
function setChildLevelAndParent(node, operand, visitedNodes) {
|
204
|
+
const self = this;
|
205
|
+
|
206
|
+
if (visitedNodes.has(node)) {
|
207
|
+
throw new Error(
|
208
|
+
"the node has already been visited and cannot be traversed again",
|
209
|
+
)
|
210
|
+
}
|
211
|
+
|
212
|
+
visitedNodes.add(node);
|
213
|
+
|
214
|
+
if (node !== this) {
|
215
|
+
node[treeStructureSymbol].parent = this;
|
216
|
+
}
|
217
|
+
|
218
|
+
node[treeStructureSymbol].childNodes.forEach(function (child) {
|
219
|
+
child[treeStructureSymbol].parent = node;
|
220
|
+
child[treeStructureSymbol].level =
|
221
|
+
node[treeStructureSymbol].level + operand;
|
222
|
+
setChildLevelAndParent.call(self, child, operand, visitedNodes);
|
223
|
+
});
|
224
|
+
return this;
|
215
225
|
}
|
package/source/types/version.mjs
CHANGED
@@ -7,6 +7,52 @@ import {NodeList} from "../../../source/types/nodelist.mjs";
|
|
7
7
|
|
8
8
|
describe('buildTree', function () {
|
9
9
|
|
10
|
+
|
11
|
+
describe('legacy navigation example (issue #230)', function () {
|
12
|
+
|
13
|
+
it('should run example', function () {
|
14
|
+
|
15
|
+
const objects = JSON.parse(`{
|
16
|
+
"dataset": [
|
17
|
+
{
|
18
|
+
"id": 100001,
|
19
|
+
"parent_id": 200001,
|
20
|
+
"title": "eBay",
|
21
|
+
"url": "/",
|
22
|
+
"weight": 1,
|
23
|
+
"css_styles": "",
|
24
|
+
"css_classes": ""
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"id": 200001,
|
28
|
+
"parent_id": 200001,
|
29
|
+
"title": "alvineconsole",
|
30
|
+
"url": "",
|
31
|
+
"weight": 1,
|
32
|
+
"css_styles": "",
|
33
|
+
"css_classes": ""
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"sys": {
|
37
|
+
"code": 200,
|
38
|
+
"result": {},
|
39
|
+
"api_version": "1"
|
40
|
+
}
|
41
|
+
}`);
|
42
|
+
|
43
|
+
try {
|
44
|
+
buildTree(objects, 'dataset.*', 'id', 'parent_id');
|
45
|
+
} catch (error) {
|
46
|
+
expect(error).to.be.instanceOf(Error);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
})
|
53
|
+
})
|
54
|
+
|
55
|
+
|
10
56
|
describe('example', function () {
|
11
57
|
|
12
58
|
it('should run example', function () {
|
@@ -207,6 +253,9 @@ describe('buildTree', function () {
|
|
207
253
|
|
208
254
|
|
209
255
|
});
|
256
|
+
|
257
|
+
|
258
|
+
|
210
259
|
|
211
260
|
|
212
261
|
});
|
@@ -76,7 +76,7 @@ describe('Data', function () {
|
|
76
76
|
describe('External Data', () => {
|
77
77
|
|
78
78
|
let id = new ID('data').toString();
|
79
|
-
let server, data, url = 'https://
|
79
|
+
let server, data, url = 'https://cdnjs.cloudflare.com/ajax/libs/layzr.js/2.2.2/layzr.min.js';
|
80
80
|
|
81
81
|
beforeEach(() => {
|
82
82
|
|
@@ -54,7 +54,7 @@ describe('Stylesheet', function () {
|
|
54
54
|
describe('External Stylesheet', () => {
|
55
55
|
|
56
56
|
let id = new ID('Stylesheet').toString();
|
57
|
-
let stylesheet, url = 'https://
|
57
|
+
let stylesheet, url = 'https://alvine.io/main.min.css';
|
58
58
|
|
59
59
|
beforeEach(() => {
|
60
60
|
|
@@ -60,7 +60,7 @@ describe('Script', function () {
|
|
60
60
|
describe('External JS', () => {
|
61
61
|
|
62
62
|
let id = new ID('script').toString();
|
63
|
-
let server, script, url = 'https://
|
63
|
+
let server, script, url = 'https://cdnjs.cloudflare.com/ajax/libs/layzr.js/2.2.2/layzr.min.js';
|
64
64
|
|
65
65
|
beforeEach(() => {
|
66
66
|
|
package/test/cases/monster.mjs
CHANGED
package/test/web/test.html
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
</head>
|
10
10
|
<body>
|
11
11
|
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
|
12
|
-
<h1 style='margin-bottom: 0.1em;'>Monster 3.73.
|
13
|
-
<div id="lastupdate" style='font-size:0.7em'>last update
|
12
|
+
<h1 style='margin-bottom: 0.1em;'>Monster 3.73.5</h1>
|
13
|
+
<div id="lastupdate" style='font-size:0.7em'>last update Mi 31. Jul 23:19:18 CEST 2024</div>
|
14
14
|
</div>
|
15
15
|
<div id="mocha-errors"
|
16
16
|
style="color: red;font-weight: bold;display: flex;align-items: center;justify-content: center;flex-direction: column;margin:20px;"></div>
|