@schukai/monster 3.98.3 → 3.99.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.
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Copyright © schukai GmbH and all contributing authors, {{copyRightYear}}. All rights reserved.
3
+ * Node module: @schukai/monster
4
+ *
5
+ * This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
6
+ * The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html
7
+ *
8
+ * For those who do not wish to adhere to the AGPLv3, a commercial license is available.
9
+ * Acquiring a commercial license allows you to use this software without complying with the AGPLv3 terms.
10
+ * For more information about purchasing a commercial license, please contact schukai GmbH.
11
+ *
12
+ * SPDX-License-Identifier: AGPL-3.0
13
+ */
14
+
15
+ import {validateInstance, validateString} from "../types/validate.mjs";
16
+ import {ATTRIBUTE_ERRORMESSAGE} from "./constants.mjs";
17
+
18
+
19
+ export {addErrorAttribute, removeErrorAttribute};
20
+
21
+ /**
22
+ * This method can be used to add an error message to an element.
23
+ *
24
+ * @license AGPLv3
25
+ * @since 3.99.0
26
+ * @copyright schukai GmbH
27
+ * @param {HTMLElement} element
28
+ * @param {string} message
29
+ * @return {HTMLElement}
30
+ */
31
+ function addErrorAttribute(element, message) {
32
+ validateInstance(element, HTMLElement);
33
+
34
+ if(message instanceof Error) {
35
+ message = message.message;
36
+ }
37
+
38
+ if(typeof message !== "string") {
39
+ if(typeof message === "object" && message !== null) {
40
+ if(typeof message.toString === "function") {
41
+ message = message.toString();
42
+ } else {
43
+ message = JSON.stringify(message);
44
+ }
45
+ } else {
46
+ message = String(message);
47
+ }
48
+ }
49
+
50
+ validateString(message);
51
+
52
+ if (!element.hasAttribute(ATTRIBUTE_ERRORMESSAGE)) {
53
+ element.setAttribute(ATTRIBUTE_ERRORMESSAGE, message);
54
+ return element;
55
+ }
56
+
57
+ const current = element.getAttribute(ATTRIBUTE_ERRORMESSAGE);
58
+ const list = current.split("::");
59
+
60
+ for(let i = 0; i < list.length; i++) {
61
+ if(list[i] === message) {
62
+ return element;
63
+ }
64
+ }
65
+
66
+ list.push(message);
67
+
68
+ element.setAttribute(
69
+ ATTRIBUTE_ERRORMESSAGE,
70
+ list.join("::")
71
+ );
72
+
73
+ return element;
74
+ }
75
+
76
+ /**
77
+ * This method can be used to remove an error message from an element.
78
+ * @license AGPLv3
79
+ * @since 3.99.0
80
+ * @param element
81
+ * @param message
82
+ * @param {HTMLElement} element
83
+ * @param {string} message
84
+ * @return {HTMLElement}
85
+ */
86
+ function removeErrorAttribute(element, message) {
87
+ validateInstance(element, HTMLElement);
88
+ validateString(message);
89
+
90
+ if (!element.hasAttribute(ATTRIBUTE_ERRORMESSAGE)) {
91
+ return element;
92
+ }
93
+
94
+ const current = element.getAttribute(ATTRIBUTE_ERRORMESSAGE);
95
+ const list = current.split("::");
96
+ const newList = list.filter(function (token) {
97
+ return token !== message;
98
+ });
99
+
100
+ element.setAttribute(
101
+ ATTRIBUTE_ERRORMESSAGE,
102
+ newList.join("::")
103
+ );
104
+
105
+ return element;
106
+ }
@@ -156,7 +156,7 @@ function getMonsterVersion() {
156
156
  }
157
157
 
158
158
  /** don't touch, replaced by make with package.json version */
159
- monsterVersion = new Version("3.98.1");
159
+ monsterVersion = new Version("3.98.3");
160
160
 
161
161
  return monsterVersion;
162
162
  }
@@ -138,7 +138,7 @@ describe('DOM', function () {
138
138
 
139
139
  expect(document.getElementsByTagName('monster-customcontrol').length).is.equal(1);
140
140
  // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
141
- expect(document.getElementById('test1')).contain.html('<monster-customcontrol data-monster-error="Error: html is not set."></monster-customcontrol>')
141
+ expect(document.getElementById('test1')).contain.html('<monster-customcontrol data-monster-error="html is not set."></monster-customcontrol>')
142
142
  });
143
143
  });
144
144
 
@@ -242,7 +242,7 @@ describe('DOM', function () {
242
242
  expect(document.getElementsByTagName('monster-testclass').length).is.equal(1);
243
243
  // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
244
244
  // but data-monster-error="Error: html is not set."
245
- expect(document.getElementById('test1')).contain.html('<monster-testclass data-monster-error="Error: html is not set."></monster-testclass>');
245
+ expect(document.getElementById('test1')).contain.html('<monster-testclass data-monster-error="html is not set."></monster-testclass>');
246
246
  });
247
247
  });
248
248
 
@@ -402,7 +402,7 @@ describe('DOM', function () {
402
402
  div.append(d);
403
403
 
404
404
 
405
- expect(div).contain.html('data-monster-error="TypeError: value is not an instance of CSSStyleSheet"');
405
+ expect(div).contain.html('data-monster-error="value is not an instance of CSSStyleSheet"');
406
406
  done();
407
407
 
408
408
  })
@@ -637,4 +637,4 @@ describe('DOM', function () {
637
637
  })
638
638
 
639
639
  });
640
- })
640
+ })
@@ -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.98.1")
10
+ monsterVersion = new Version("3.98.3")
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.98.1</h1>
13
- <div id="lastupdate" style='font-size:0.7em'>last update Di 7. Jan 17:53:37 CET 2025</div>
12
+ <h1 style='margin-bottom: 0.1em;'>Monster 3.98.3</h1>
13
+ <div id="lastupdate" style='font-size:0.7em'>last update Di 7. Jan 22:59:33 CET 2025</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>