@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.
@@ -12,13 +12,13 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
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";
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 { Node };
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
- * @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);
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);
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);
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
- }
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
- const self = this;
203
-
204
- if (node !== this) {
205
- node[treeStructureSymbol].parent = this;
206
- }
207
-
208
- node[treeStructureSymbol].childNodes.forEach(function (child) {
209
- child[treeStructureSymbol].parent = node;
210
- child[treeStructureSymbol].level =
211
- node[treeStructureSymbol].level + operand;
212
- setChildLevelAndParent.call(self, child, operand);
213
- });
214
- return this;
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
  }
@@ -159,7 +159,7 @@ function getMonsterVersion() {
159
159
  }
160
160
 
161
161
  /** don't touch, replaced by make with package.json version */
162
- monsterVersion = new Version("3.73.2");
162
+ monsterVersion = new Version("3.73.5");
163
163
 
164
164
  return monsterVersion;
165
165
  }
@@ -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://monsterjs.org/assets/empty.js?' + id;
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://monsterjs.org/assets/empty.css?' + id;
57
+ let stylesheet, url = 'https://alvine.io/main.min.css';
58
58
 
59
59
  beforeEach(() => {
60
60
 
@@ -51,7 +51,7 @@ describe('Link', function () {
51
51
  this.timeout(5000);
52
52
 
53
53
  let id = new ID('link').toString();
54
- let link, url = 'https://monsterjs.org/assets/empty.css?' + id;
54
+ let link, url = 'https://alvine.io/main.min.css';
55
55
 
56
56
  beforeEach(() => {
57
57
 
@@ -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://monsterjs.org/assets/empty.js?' + id;
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
 
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.73.2")
10
+ monsterVersion = new Version("3.73.5")
11
11
 
12
12
  let m = getMonsterVersion();
13
13
 
@@ -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.2</h1>
13
- <div id="lastupdate" style='font-size:0.7em'>last update Di 2. Jul 20:16:21 CEST 2024</div>
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>