@schukai/monster 4.46.3 → 4.46.4
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.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/source/dom/util/init-options-from-attributes.mjs +56 -53
- package/source/types/is.mjs +82 -64
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.46.
|
|
1
|
+
{"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.46.4"}
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
import { Pathfinder } from "../../data/pathfinder.mjs";
|
|
16
16
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
isBoolean,
|
|
18
|
+
isString,
|
|
19
|
+
isObject,
|
|
20
|
+
isNumber,
|
|
21
|
+
isArray,
|
|
22
|
+
isFunction,
|
|
23
|
+
isInteger,
|
|
23
24
|
} from "../../types/is.mjs";
|
|
24
25
|
import { extractKeys } from "./extract-keys.mjs";
|
|
25
26
|
|
|
@@ -58,60 +59,62 @@ export { initOptionsFromAttributes };
|
|
|
58
59
|
* @this HTMLElement - The context of the DOM element.
|
|
59
60
|
*/
|
|
60
61
|
function initOptionsFromAttributes(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
element,
|
|
63
|
+
options,
|
|
64
|
+
mapping = {},
|
|
65
|
+
prefix = "data-monster-option-",
|
|
65
66
|
) {
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
if (!(element instanceof HTMLElement)) return options;
|
|
68
|
+
if (!element.hasAttributes()) return options;
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const keyMap = extractKeys(options);
|
|
71
|
+
const finder = new Pathfinder(options);
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
element.getAttributeNames().forEach((name) => {
|
|
74
|
+
if (!name.startsWith(prefix)) return;
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
// check if the attribute name is a valid option.
|
|
77
|
+
// the mapping between the attribute is simple. The dash is replaced by a dot.
|
|
78
|
+
// e.g. data-monster-url => url
|
|
79
|
+
const optionName = keyMap.get(name.substring(prefix.length).toLowerCase());
|
|
80
|
+
if (!finder.exists(optionName)) return;
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
if (element.hasAttribute(name)) {
|
|
83
|
+
let value = element.getAttribute(name);
|
|
84
|
+
if (
|
|
85
|
+
mapping.hasOwnProperty(optionName) &&
|
|
86
|
+
isFunction(mapping[optionName])
|
|
87
|
+
) {
|
|
88
|
+
value = mapping[optionName](value);
|
|
89
|
+
}
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
let optionValue = finder.getVia(optionName);
|
|
92
|
+
if (optionValue === null || optionValue === undefined) {
|
|
93
|
+
optionValue = value;
|
|
94
|
+
}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
96
|
+
//const typeOfOptionValue = typeof optionValue;
|
|
97
|
+
if (optionValue === null || optionValue === undefined) {
|
|
98
|
+
value = null;
|
|
99
|
+
} else if (isBoolean(optionValue)) {
|
|
100
|
+
value = value === "true";
|
|
101
|
+
} else if (isInteger(optionValue)) {
|
|
102
|
+
value = Number(value);
|
|
103
|
+
} else if (isNumber(optionValue)) {
|
|
104
|
+
value = Number(value);
|
|
105
|
+
} else if (isString(optionValue)) {
|
|
106
|
+
value = String(value);
|
|
107
|
+
} else if (isObject(optionValue)) {
|
|
108
|
+
value = JSON.parse(value);
|
|
109
|
+
} else if (isArray(optionValue)) {
|
|
110
|
+
value = value.split("::");
|
|
111
|
+
} else {
|
|
112
|
+
value = optionValue;
|
|
113
|
+
}
|
|
111
114
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
finder.setVia(optionName, value);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
return options;
|
|
117
120
|
}
|
package/source/types/is.mjs
CHANGED
|
@@ -15,18 +15,19 @@
|
|
|
15
15
|
import { proxyInstanceMarker } from "../constants.mjs";
|
|
16
16
|
|
|
17
17
|
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
isIterable,
|
|
19
|
+
isPrimitive,
|
|
20
|
+
isSymbol,
|
|
21
|
+
isBoolean,
|
|
22
|
+
isString,
|
|
23
|
+
isObject,
|
|
24
|
+
isInstance,
|
|
25
|
+
isArray,
|
|
26
|
+
isFunction,
|
|
27
|
+
isInteger,
|
|
28
|
+
isNumber,
|
|
29
|
+
isProxy,
|
|
30
|
+
isElement,
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -35,7 +36,7 @@ export {
|
|
|
35
36
|
* @returns {boolean}
|
|
36
37
|
*/
|
|
37
38
|
function isElement(value) {
|
|
38
|
-
|
|
39
|
+
return value instanceof Element;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
|
@@ -45,7 +46,7 @@ function isElement(value) {
|
|
|
45
46
|
* @returns {boolean}
|
|
46
47
|
*/
|
|
47
48
|
function isProxy(value) {
|
|
48
|
-
|
|
49
|
+
return value?.[proxyInstanceMarker] === proxyInstanceMarker;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
@@ -63,9 +64,9 @@ function isProxy(value) {
|
|
|
63
64
|
* @copyright schukai GmbH
|
|
64
65
|
*/
|
|
65
66
|
function isIterable(value) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
if (value === undefined) return false;
|
|
68
|
+
if (value === null) return false;
|
|
69
|
+
return typeof value?.[Symbol.iterator] === "function";
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
/**
|
|
@@ -81,24 +82,24 @@ function isIterable(value) {
|
|
|
81
82
|
* @copyright schukai GmbH
|
|
82
83
|
*/
|
|
83
84
|
function isPrimitive(value) {
|
|
84
|
-
|
|
85
|
+
var type;
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if (value === undefined || value === null) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
89
90
|
|
|
90
|
-
|
|
91
|
+
type = typeof value;
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
if (
|
|
94
|
+
type === "string" ||
|
|
95
|
+
type === "number" ||
|
|
96
|
+
type === "boolean" ||
|
|
97
|
+
type === "symbol"
|
|
98
|
+
) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
return false;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
/**
|
|
@@ -114,7 +115,7 @@ function isPrimitive(value) {
|
|
|
114
115
|
* @copyright schukai GmbH
|
|
115
116
|
*/
|
|
116
117
|
function isSymbol(value) {
|
|
117
|
-
|
|
118
|
+
return "symbol" === typeof value ? true : false;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
/**
|
|
@@ -130,11 +131,11 @@ function isSymbol(value) {
|
|
|
130
131
|
* @copyright schukai GmbH
|
|
131
132
|
*/
|
|
132
133
|
function isBoolean(value) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
if (value === true || value === false) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
return false;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
/**
|
|
@@ -150,10 +151,10 @@ function isBoolean(value) {
|
|
|
150
151
|
* @copyright schukai GmbH
|
|
151
152
|
*/
|
|
152
153
|
function isString(value) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
if (value === undefined || typeof value !== "string") {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
/**
|
|
@@ -169,14 +170,14 @@ function isString(value) {
|
|
|
169
170
|
* @copyright schukai GmbH
|
|
170
171
|
*/
|
|
171
172
|
function isObject(value) {
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
if (isArray(value)) return false;
|
|
174
|
+
if (isPrimitive(value)) return false;
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
if (typeof value === "object") {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
178
179
|
|
|
179
|
-
|
|
180
|
+
return false;
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
/**
|
|
@@ -193,18 +194,18 @@ function isObject(value) {
|
|
|
193
194
|
* @copyright schukai GmbH
|
|
194
195
|
*/
|
|
195
196
|
function isInstance(value, instance) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
if (!isObject(value)) return false;
|
|
198
|
+
if (!isFunction(instance)) return false;
|
|
199
|
+
if (!instance.hasOwnProperty("prototype")) return false;
|
|
200
|
+
if (value instanceof instance) return true;
|
|
200
201
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
let proto = Object.getPrototypeOf(value);
|
|
203
|
+
while (proto != null) {
|
|
204
|
+
if (proto === instance.prototype) return true;
|
|
205
|
+
proto = Object.getPrototypeOf(proto);
|
|
206
|
+
}
|
|
206
207
|
|
|
207
|
-
|
|
208
|
+
return false;
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
/**
|
|
@@ -221,7 +222,7 @@ function isInstance(value, instance) {
|
|
|
221
222
|
* @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
|
|
222
223
|
*/
|
|
223
224
|
function isArray(value) {
|
|
224
|
-
|
|
225
|
+
return Array.isArray(value);
|
|
225
226
|
}
|
|
226
227
|
|
|
227
228
|
/**
|
|
@@ -237,14 +238,31 @@ function isArray(value) {
|
|
|
237
238
|
* @copyright schukai GmbH
|
|
238
239
|
*/
|
|
239
240
|
function isFunction(value) {
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
if (isArray(value)) return false;
|
|
242
|
+
if (isPrimitive(value)) return false;
|
|
242
243
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
if (typeof value === "function") {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
246
247
|
|
|
247
|
-
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Cechs whether the value passed is a number.
|
|
253
|
+
*
|
|
254
|
+
* This method is used in the library to have consistent names.
|
|
255
|
+
*
|
|
256
|
+
* @externalExample ../../example/types/is-number.mjs
|
|
257
|
+
*
|
|
258
|
+
* @param {*} value
|
|
259
|
+
* @return {boolean}
|
|
260
|
+
*
|
|
261
|
+
* @license AGPLv3
|
|
262
|
+
* @since 4.47.0
|
|
263
|
+
*/
|
|
264
|
+
function isNumber(value) {
|
|
265
|
+
return typeof value === "number" && !isNaN(value);
|
|
248
266
|
}
|
|
249
267
|
|
|
250
268
|
/**
|
|
@@ -260,5 +278,5 @@ function isFunction(value) {
|
|
|
260
278
|
* @copyright schukai GmbH
|
|
261
279
|
*/
|
|
262
280
|
function isInteger(value) {
|
|
263
|
-
|
|
281
|
+
return Number.isInteger(value);
|
|
264
282
|
}
|