@schukai/monster 3.48.0 → 3.50.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 {Pathfinder} from '../../data/pathfinder.mjs';
9
- import {isFunction} from '../../types/is.mjs';
10
- import {attributeObserverSymbol} from "../customelement.mjs";
11
- import {extractKeys} from "./extract-keys.mjs";
8
+ import { Pathfinder } from "../../data/pathfinder.mjs";
9
+ import { isFunction } from "../../types/is.mjs";
10
+ import { attributeObserverSymbol } from "../customelement.mjs";
11
+ import { extractKeys } from "./extract-keys.mjs";
12
12
 
13
- export {initOptionsFromAttributes};
13
+ export { initOptionsFromAttributes };
14
14
 
15
15
  /**
16
16
  * Initializes the given options object based on the attributes of the current DOM element.
@@ -29,7 +29,7 @@ export {initOptionsFromAttributes};
29
29
  * // e.g. <div data-monster-option-foo="foo"></div>
30
30
  * 'bar.baz': (value) => value + 'bar'
31
31
  * // the value of the attribute 'data-monster-option-bar-baz' is appended with 'bar'
32
- * // and assigned to the 'bar.baz' property in the options object.
32
+ * // and assigned to the 'bar.baz' property in the options object.
33
33
  * // e.g. <div data-monster-option-bar-baz="foo"></div>
34
34
  * }
35
35
  *
@@ -41,7 +41,7 @@ export {initOptionsFromAttributes};
41
41
  * @returns {Object} - The initialized options object.
42
42
  * @this HTMLElement - The context of the DOM element.
43
43
  */
44
- function initOptionsFromAttributes(element, options, mapping = {}, prefix = 'data-monster-option-') {
44
+ function initOptionsFromAttributes(element, options, mapping = {}, prefix = "data-monster-option-") {
45
45
  if (!(element instanceof HTMLElement)) return options;
46
46
  if (!element.hasAttributes()) return options;
47
47
 
@@ -52,7 +52,7 @@ function initOptionsFromAttributes(element, options, mapping = {}, prefix = 'dat
52
52
  element.getAttributeNames().forEach((name) => {
53
53
  if (!name.startsWith(prefix)) return;
54
54
 
55
- // check if the attribute name is a valid option.
55
+ // check if the attribute name is a valid option.
56
56
  // the mapping between the attribute is simple. The dash is replaced by a dot.
57
57
  // e.g. data-monster-url => url
58
58
  const optionName = keyMap.get(name.substring(prefix.length).toLowerCase());
@@ -65,21 +65,19 @@ function initOptionsFromAttributes(element, options, mapping = {}, prefix = 'dat
65
65
  }
66
66
 
67
67
  const typeOfOptionValue = typeof finder.getVia(optionName);
68
- if (typeOfOptionValue === 'boolean') {
69
- value = value === 'true';
70
- } else if (typeOfOptionValue === 'number') {
68
+ if (typeOfOptionValue === "boolean") {
69
+ value = value === "true";
70
+ } else if (typeOfOptionValue === "number") {
71
71
  value = Number(value);
72
- } else if (typeOfOptionValue === 'string') {
72
+ } else if (typeOfOptionValue === "string") {
73
73
  value = String(value);
74
- } else if (typeOfOptionValue === 'object') {
74
+ } else if (typeOfOptionValue === "object") {
75
75
  value = JSON.parse(value);
76
76
  }
77
77
 
78
78
  finder.setVia(optionName, value);
79
79
  }
80
- })
80
+ });
81
81
 
82
82
  return options;
83
83
  }
84
-
85
-
@@ -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 {Pathfinder} from '../../data/pathfinder.mjs';
9
- import {isFunction} from '../../types/is.mjs';
10
- import {attributeObserverSymbol} from "../customelement.mjs";
11
- import {extractKeys} from "./extract-keys.mjs";
8
+ import { Pathfinder } from "../../data/pathfinder.mjs";
9
+ import { isFunction } from "../../types/is.mjs";
10
+ import { attributeObserverSymbol } from "../customelement.mjs";
11
+ import { extractKeys } from "./extract-keys.mjs";
12
12
 
13
- export {setOptionFromAttribute};
13
+ export { setOptionFromAttribute };
14
14
 
15
15
  /**
16
16
  * Set the given options object based on the attributes of the current DOM element.
@@ -29,7 +29,7 @@ export {setOptionFromAttribute};
29
29
  * // e.g. <div data-monster-option-foo="foo"></div>
30
30
  * 'bar.baz': (value) => value + 'bar'
31
31
  * // the value of the attribute 'data-monster-option-bar-baz' is appended with 'bar'
32
- * // and assigned to the 'bar.baz' property in the options object.
32
+ * // and assigned to the 'bar.baz' property in the options object.
33
33
  * // e.g. <div data-monster-option-bar-baz="foo"></div>
34
34
  * }
35
35
  *
@@ -42,14 +42,14 @@ export {setOptionFromAttribute};
42
42
  * @returns {Object} - The initialized options object.
43
43
  * @this HTMLElement - The context of the DOM element.
44
44
  */
45
- function setOptionFromAttribute(element, name, options, mapping = {}, prefix = 'data-monster-option-') {
45
+ function setOptionFromAttribute(element, name, options, mapping = {}, prefix = "data-monster-option-") {
46
46
  if (!(element instanceof HTMLElement)) return options;
47
47
  if (!element.hasAttributes()) return options;
48
-
48
+
49
49
  const keyMap = extractKeys(options);
50
50
  const finder = new Pathfinder(options);
51
51
 
52
- // check if the attribute name is a valid option.
52
+ // check if the attribute name is a valid option.
53
53
  // the mapping between the attribute is simple. The dash is replaced by a dot.
54
54
  // e.g. data-monster-url => url
55
55
  const optionName = keyMap.get(name.substring(prefix.length).toLowerCase());
@@ -65,13 +65,13 @@ function setOptionFromAttribute(element, name, options, mapping = {}, prefix = '
65
65
  }
66
66
 
67
67
  const typeOfOptionValue = typeof finder.getVia(optionName);
68
- if (typeOfOptionValue === 'boolean') {
69
- value = value === 'true';
70
- } else if (typeOfOptionValue === 'number') {
68
+ if (typeOfOptionValue === "boolean") {
69
+ value = value === "true";
70
+ } else if (typeOfOptionValue === "number") {
71
71
  value = Number(value);
72
- } else if (typeOfOptionValue === 'string') {
72
+ } else if (typeOfOptionValue === "string") {
73
73
  value = String(value);
74
- } else if (typeOfOptionValue === 'object') {
74
+ } else if (typeOfOptionValue === "object") {
75
75
  value = JSON.parse(value);
76
76
  }
77
77
 
@@ -79,5 +79,3 @@ function setOptionFromAttribute(element, name, options, mapping = {}, prefix = '
79
79
 
80
80
  return options;
81
81
  }
82
-
83
-
@@ -8,7 +8,7 @@
8
8
  import { getGlobal } from "../types/global.mjs";
9
9
  import { validateString } from "../types/validate.mjs";
10
10
 
11
- export { getDocument, getWindow, getDocumentFragmentFromString, findElementWithIdUpwards,getContainingDocument };
11
+ export { getDocument, getWindow, getDocumentFragmentFromString, findElementWithIdUpwards, getContainingDocument };
12
12
 
13
13
  /**
14
14
  * This method fetches the document object
@@ -209,7 +209,11 @@ function traverseShadowRoots(element) {
209
209
  let currentRoot = element.shadowRoot;
210
210
  let currentParent = element.parentNode;
211
211
 
212
- while (currentParent && currentParent.nodeType !== Node.DOCUMENT_NODE && currentParent.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
212
+ while (
213
+ currentParent &&
214
+ currentParent.nodeType !== Node.DOCUMENT_NODE &&
215
+ currentParent.nodeType !== Node.DOCUMENT_FRAGMENT_NODE
216
+ ) {
213
217
  if (currentRoot && currentRoot.parentNode) {
214
218
  currentParent = currentRoot.parentNode;
215
219
  currentRoot = currentParent.shadowRoot;
@@ -238,8 +242,11 @@ function traverseShadowRoots(element) {
238
242
  * @since 3.36.0
239
243
  */
240
244
  function getContainingDocument(element) {
241
- if (!element || !(element instanceof HTMLElement || element instanceof element.ownerDocument.defaultView.HTMLElement)) {
242
- throw new Error('Invalid argument. Expected an HTMLElement.');
245
+ if (
246
+ !element ||
247
+ !(element instanceof HTMLElement || element instanceof element.ownerDocument.defaultView.HTMLElement)
248
+ ) {
249
+ throw new Error("Invalid argument. Expected an HTMLElement.");
243
250
  }
244
251
 
245
252
  return traverseShadowRoots(element) || null;
@@ -21,10 +21,6 @@ export { ConsoleHandler };
21
21
  * @memberOf Monster.Logging.Handler
22
22
  */
23
23
  class ConsoleHandler extends Handler {
24
- constructor() {
25
- super();
26
- }
27
-
28
24
  /**
29
25
  * This is the central log function. this method must be
30
26
  * overwritten by derived handlers with their own logic.
@@ -5,7 +5,7 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- export {parseBracketedKeyValueHash, createBracketedKeyValueHash}
8
+ export { parseBracketedKeyValueHash, createBracketedKeyValueHash };
9
9
 
10
10
  /**
11
11
  * Parses a string containing bracketed key-value pairs and returns an object representing the parsed result.
@@ -49,8 +49,7 @@ function parseBracketedKeyValueHash(hashString) {
49
49
  //const keyValueStack = [];
50
50
 
51
51
  const trimmedHashString = hashString.trim();
52
- const cleanedHashString = trimmedHashString.charAt(0) === '#' ? trimmedHashString.slice(1) : trimmedHashString;
53
-
52
+ const cleanedHashString = trimmedHashString.charAt(0) === "#" ? trimmedHashString.slice(1) : trimmedHashString;
54
53
 
55
54
  //const selectors = (keyValueStack.length > 0) ? result[selectorStack[selectorStack.length - 1]] : result;
56
55
  let currentSelector = "";
@@ -65,20 +64,20 @@ function parseBracketedKeyValueHash(hashString) {
65
64
  }
66
65
  }
67
66
 
68
- let currentKey = '';
69
- let currentValue = '';
67
+ let currentKey = "";
68
+ let currentValue = "";
70
69
  let inKey = true;
71
70
  let inValue = false;
72
71
  let inQuotedValue = false;
73
72
  let inSelector = true;
74
73
  let escaped = false;
75
- let quotedValueStartChar = '';
74
+ let quotedValueStartChar = "";
76
75
 
77
76
  for (let i = 0; i < cleanedHashString.length; i++) {
78
77
  const c = cleanedHashString[i];
79
78
  const nextChar = cleanedHashString?.[i + 1];
80
79
 
81
- if (c === '\\' && !escaped) {
80
+ if (c === "\\" && !escaped) {
82
81
  escaped = true;
83
82
  continue;
84
83
  }
@@ -96,7 +95,6 @@ function parseBracketedKeyValueHash(hashString) {
96
95
  }
97
96
 
98
97
  if (inQuotedValue && quotedValueStartChar !== c) {
99
-
100
98
  if (inSelector) {
101
99
  currentSelector += c;
102
100
  } else if (inKey) {
@@ -108,19 +106,18 @@ function parseBracketedKeyValueHash(hashString) {
108
106
  continue;
109
107
  }
110
108
 
111
- if (c === ';' && inSelector) {
109
+ if (c === ";" && inSelector) {
112
110
  inSelector = true;
113
111
  currentSelector = "";
114
112
  continue;
115
113
  }
116
114
 
117
-
118
- if (inSelector === true && c !== '(') {
115
+ if (inSelector === true && c !== "(") {
119
116
  currentSelector += c;
120
117
  continue;
121
118
  }
122
119
 
123
- if (c === '(' && inSelector) {
120
+ if (c === "(" && inSelector) {
124
121
  inSelector = false;
125
122
  inKey = true;
126
123
 
@@ -128,13 +125,12 @@ function parseBracketedKeyValueHash(hashString) {
128
125
  continue;
129
126
  }
130
127
 
131
- if (inKey === true && c !== '=') {
128
+ if (inKey === true && c !== "=") {
132
129
  currentKey += c;
133
130
  continue;
134
131
  }
135
132
 
136
- if (c === '=' && inKey) {
137
-
133
+ if (c === "=" && inKey) {
138
134
  inKey = false;
139
135
  inValue = true;
140
136
 
@@ -160,7 +156,7 @@ function parseBracketedKeyValueHash(hashString) {
160
156
  continue;
161
157
  }
162
158
 
163
- if (c === ',') {
159
+ if (c === ",") {
164
160
  inValue = false;
165
161
  inKey = true;
166
162
  const decodedCurrentValue = decodeURIComponent(currentValue);
@@ -170,7 +166,7 @@ function parseBracketedKeyValueHash(hashString) {
170
166
  continue;
171
167
  }
172
168
 
173
- if (c === ')') {
169
+ if (c === ")") {
174
170
  inValue = false;
175
171
  //inKey = true;
176
172
  inSelector = true;
@@ -189,14 +185,11 @@ function parseBracketedKeyValueHash(hashString) {
189
185
  }
190
186
  }
191
187
 
192
-
193
188
  if (inSelector) {
194
189
  return selectors;
195
190
  }
196
191
 
197
-
198
192
  return {};
199
-
200
193
  }
201
194
 
202
195
  /**
@@ -208,38 +201,37 @@ function parseBracketedKeyValueHash(hashString) {
208
201
  * @since 3.37.0
209
202
  */
210
203
  function createBracketedKeyValueHash(object, addHashPrefix = true) {
211
-
212
204
  if (!object) {
213
- return addHashPrefix ? '#' : '';
205
+ return addHashPrefix ? "#" : "";
214
206
  }
215
-
216
- let hashString = '';
207
+
208
+ let hashString = "";
217
209
 
218
210
  function encodeKeyValue(key, value) {
219
- return encodeURIComponent(key) + '=' + encodeURIComponent(value);
211
+ return encodeURIComponent(key) + "=" + encodeURIComponent(value);
220
212
  }
221
213
 
222
214
  for (const selector in object) {
223
215
  if (object.hasOwnProperty(selector)) {
224
216
  const keyValuePairs = object[selector];
225
217
  let selectorString = selector;
226
- let keyValueString = '';
218
+ let keyValueString = "";
227
219
 
228
220
  for (const key in keyValuePairs) {
229
221
  if (keyValuePairs.hasOwnProperty(key)) {
230
222
  const value = keyValuePairs[key];
231
- keyValueString += keyValueString.length === 0 ? '' : ',';
223
+ keyValueString += keyValueString.length === 0 ? "" : ",";
232
224
  keyValueString += encodeKeyValue(key, value);
233
225
  }
234
226
  }
235
227
 
236
228
  if (keyValueString.length > 0) {
237
- selectorString += '(' + keyValueString + ')';
238
- hashString += hashString.length === 0 ? '' : ';';
229
+ selectorString += "(" + keyValueString + ")";
230
+ hashString += hashString.length === 0 ? "" : ";";
239
231
  hashString += selectorString;
240
232
  }
241
233
  }
242
234
  }
243
235
 
244
- return addHashPrefix ? '#' + hashString : hashString;
245
- }
236
+ return addHashPrefix ? "#" + hashString : hashString;
237
+ }
@@ -1,2 +1 @@
1
- export { generateRangeComparisonExpression } from "./generate-range-comparison-expression.mjs"
2
-
1
+ export { generateRangeComparisonExpression } from "./generate-range-comparison-expression.mjs";
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.48.0");
145
+ monsterVersion = new Version("3.50.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -28,6 +28,9 @@ describe('Transformer', function () {
28
28
  describe('Transformer.run()', function () {
29
29
 
30
30
  [
31
+ ['datetimeformat', "2023-02-04 08:02:01", "04.02.2023, 08:02:01"],
32
+ ['datetimeformat:long:short', "2023-02-04 08:02:01","4. Februar 2023 um 08:02"],
33
+ ['datetimeformat:short:short', "2023-02-04 08:02:01", "04.02.23, 08:02"],
31
34
  ['equals:a', "a", true],
32
35
  ['equals:a', "b", false],
33
36
  ['equals:3', 3, true],
@@ -22,6 +22,10 @@ describe('DOM', function () {
22
22
  before(function (done) {
23
23
  initJSDOM().then(() => {
24
24
 
25
+ import("element-internals-polyfill").then((m) => {
26
+ m.polyfill();
27
+ });
28
+
25
29
  // jsdom does not support ElementInternals
26
30
  jsdomFlag = navigator.userAgent.includes("jsdom");
27
31
 
@@ -72,8 +76,13 @@ describe('DOM', function () {
72
76
 
73
77
  describe('create', function () {
74
78
  it('should return custom-element object', function () {
75
- let d = new TestComponent();
76
- expect(typeof d).is.equal('object');
79
+ try {
80
+ let d = new TestComponent();
81
+ } catch (e) {
82
+ expect(e).to.be.not.null;
83
+ }
84
+
85
+ expect(typeof d).is.equal('undefined');
77
86
  });
78
87
  });
79
88
 
@@ -84,7 +93,7 @@ describe('DOM', function () {
84
93
  document.getElementById('test1').appendChild(d);
85
94
  expect(document.getElementsByTagName('monster-customcontrol').length).is.equal(1);
86
95
  // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
87
- expect(document.getElementById('test1')).contain.html('<monster-customcontrol></monster-customcontrol>');
96
+ expect(document.getElementById('test1')).contain.html('<monster-customcontrol data-monster-error="Error: html is not set."></monster-customcontrol>')
88
97
  });
89
98
  });
90
99
 
@@ -129,11 +138,13 @@ describe('DOM', function () {
129
138
  let d = document.createElement('monster-customcontrol');
130
139
  form.appendChild(d);
131
140
 
132
- if (jsdomFlag) {
133
- expect(() => d.form).to.throw(Error);
134
- } else {
135
- expect(d.form).to.be.instanceof(HTMLFormElement)
136
- }
141
+ expect(d.form).to.be.instanceof(HTMLFormElement)
142
+
143
+ // if (jsdomFlag) {
144
+ // expect(() => d.form).to.throw(Error);
145
+ // } else {
146
+ // expect(d.form).to.be.instanceof(HTMLFormElement)
147
+ // }
137
148
 
138
149
 
139
150
  });
@@ -160,13 +171,7 @@ describe('DOM', function () {
160
171
 
161
172
  let d = document.createElement('monster-customcontrol');
162
173
  form.appendChild(d);
163
-
164
- if (jsdomFlag) {
165
- expect(() => d.setFormValue()).to.throw(Error);
166
- } else {
167
-
168
- }
169
-
174
+
170
175
  });
171
176
 
172
177
  it('name getter', function () {
@@ -191,11 +196,6 @@ describe('DOM', function () {
191
196
 
192
197
  let d = document.createElement('monster-customcontrol');
193
198
  form.appendChild(d);
194
- if (jsdomFlag) {
195
- expect(() => d.validity).to.throw(Error);
196
- } else {
197
-
198
- }
199
199
 
200
200
  });
201
201
 
@@ -204,11 +204,6 @@ describe('DOM', function () {
204
204
  let d = document.createElement('monster-customcontrol');
205
205
  form.appendChild(d);
206
206
 
207
- if (jsdomFlag) {
208
- expect(() => d.validity).to.throw(Error);
209
- } else {
210
-
211
- }
212
207
 
213
208
  });
214
209
 
@@ -217,11 +212,6 @@ describe('DOM', function () {
217
212
  let d = document.createElement('monster-customcontrol');
218
213
  form.appendChild(d);
219
214
 
220
- if (jsdomFlag) {
221
- expect(() => d.willValidate).to.throw(Error);
222
- } else {
223
-
224
- }
225
215
 
226
216
  });
227
217
  it('checkValidity()', function () {
@@ -229,11 +219,6 @@ describe('DOM', function () {
229
219
  let d = document.createElement('monster-customcontrol');
230
220
  form.appendChild(d);
231
221
 
232
- if (jsdomFlag) {
233
- expect(() => d.checkValidity()).to.throw(Error);
234
- } else {
235
-
236
- }
237
222
 
238
223
  });
239
224
 
@@ -242,11 +227,6 @@ describe('DOM', function () {
242
227
  let d = document.createElement('monster-customcontrol');
243
228
  form.appendChild(d);
244
229
 
245
- if (jsdomFlag) {
246
- expect(() => d.reportValidity()).to.throw(Error);
247
- } else {
248
-
249
- }
250
230
 
251
231
  });
252
232
 
@@ -255,11 +235,7 @@ describe('DOM', function () {
255
235
 
256
236
  let d = document.createElement('monster-customcontrol');
257
237
  form.appendChild(d);
258
- if (jsdomFlag) {
259
- expect(() => d.setValidity()).to.throw(Error);
260
- } else {
261
- expect(d.setValidity({'valueMissing': true}, "my message")).to.be.undefined;
262
- }
238
+ expect(d.setValidity({'valueMissing': true}, "my message")).to.be.undefined;
263
239
 
264
240
  });
265
241
 
@@ -239,7 +239,8 @@ describe('DOM', function () {
239
239
  document.getElementById('test1').appendChild(d);
240
240
  expect(document.getElementsByTagName('monster-testclass').length).is.equal(1);
241
241
  // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
242
- expect(document.getElementById('test1')).contain.html('<monster-testclass></monster-testclass>');
242
+ // but data-monster-error="Error: html is not set."
243
+ expect(document.getElementById('test1')).contain.html('<monster-testclass data-monster-error="Error: html is not set."></monster-testclass>');
243
244
  });
244
245
  });
245
246
 
@@ -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.48.0")
10
+ monsterVersion = new Version("3.50.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13