@schukai/monster 3.5.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/source/constants.mjs +4 -9
- package/source/constraints/abstract.mjs +4 -6
- package/source/constraints/abstractoperator.mjs +6 -12
- package/source/constraints/andoperator.mjs +3 -6
- package/source/constraints/invalid.mjs +3 -6
- package/source/constraints/isarray.mjs +6 -9
- package/source/constraints/isobject.mjs +4 -7
- package/source/constraints/namespace.mjs +1 -3
- package/source/constraints/oroperator.mjs +26 -25
- package/source/constraints/valid.mjs +3 -6
- package/source/data/buildmap.mjs +20 -36
- package/source/data/buildtree.mjs +29 -29
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
- package/source/data/datasource/server/restapi.mjs +51 -65
- package/source/data/datasource/server/webconnect.mjs +26 -35
- package/source/data/datasource/server.mjs +16 -20
- package/source/data/datasource/storage/localstorage.mjs +8 -11
- package/source/data/datasource/storage/sessionstorage.mjs +8 -10
- package/source/data/datasource/storage.mjs +18 -22
- package/source/data/datasource.mjs +27 -43
- package/source/data/diff.mjs +20 -32
- package/source/data/extend.mjs +20 -14
- package/source/data/namespace.mjs +1 -3
- package/source/data/pathfinder.mjs +105 -87
- package/source/data/pipe.mjs +6 -10
- package/source/data/transformer.mjs +141 -157
- package/source/dom/assembler.mjs +6 -9
- package/source/dom/attributes.mjs +36 -48
- package/source/dom/constants.mjs +55 -71
- package/source/dom/customcontrol.mjs +16 -21
- package/source/dom/customelement.mjs +140 -164
- package/source/dom/events.mjs +17 -24
- package/source/dom/focusmanager.mjs +31 -49
- package/source/dom/locale.mjs +18 -20
- package/source/dom/namespace.mjs +1 -1
- package/source/dom/ready.mjs +7 -10
- package/source/dom/resource/data.mjs +38 -46
- package/source/dom/resource/link/namespace.mjs +1 -3
- package/source/dom/resource/link/stylesheet.mjs +7 -11
- package/source/dom/resource/link.mjs +36 -17
- package/source/dom/resource/namespace.mjs +1 -1
- package/source/dom/resource/script.mjs +23 -13
- package/source/dom/resource.mjs +47 -60
- package/source/dom/resourcemanager.mjs +36 -43
- package/source/dom/template.mjs +17 -24
- package/source/dom/theme.mjs +8 -12
- package/source/dom/updater.mjs +150 -196
- package/source/dom/util.mjs +11 -12
- package/source/dom/worker/factory.mjs +21 -25
- package/source/dom/worker/namespace.mjs +1 -1
- package/source/i18n/formatter.mjs +20 -24
- package/source/i18n/locale.mjs +42 -55
- package/source/i18n/namespace.mjs +1 -1
- package/source/i18n/provider.mjs +4 -7
- package/source/i18n/providers/embed.mjs +16 -26
- package/source/i18n/providers/fetch.mjs +30 -36
- package/source/i18n/translations.mjs +17 -24
- package/source/logging/handler/console.mjs +6 -10
- package/source/logging/handler.mjs +15 -18
- package/source/logging/logentry.mjs +8 -9
- package/source/logging/logger.mjs +73 -55
- package/source/logging/namespace.mjs +1 -1
- package/source/math/namespace.mjs +1 -1
- package/source/math/random.mjs +13 -14
- package/source/monster.mjs +132 -100
- package/source/net/namespace.mjs +1 -3
- package/source/net/webconnect/message.mjs +6 -8
- package/source/net/webconnect/namespace.mjs +1 -3
- package/source/net/webconnect.mjs +28 -39
- package/source/text/formatter.mjs +44 -55
- package/source/types/base.mjs +16 -26
- package/source/types/basewithoptions.mjs +8 -14
- package/source/types/binary.mjs +4 -5
- package/source/types/dataurl.mjs +19 -27
- package/source/types/global.mjs +14 -26
- package/source/types/id.mjs +4 -6
- package/source/types/is.mjs +11 -16
- package/source/types/mediatype.mjs +29 -44
- package/source/types/namespace.mjs +0 -1
- package/source/types/node.mjs +16 -22
- package/source/types/nodelist.mjs +10 -14
- package/source/types/noderecursiveiterator.mjs +11 -14
- package/source/types/observablequeue.mjs +13 -16
- package/source/types/observer.mjs +16 -23
- package/source/types/observerlist.mjs +18 -21
- package/source/types/proxyobserver.mjs +24 -37
- package/source/types/queue.mjs +8 -13
- package/source/types/randomid.mjs +10 -10
- package/source/types/regex.mjs +3 -5
- package/source/types/stack.mjs +4 -8
- package/source/types/tokenlist.mjs +24 -31
- package/source/types/typeof.mjs +5 -7
- package/source/types/uniquequeue.mjs +8 -13
- package/source/types/uuid.mjs +18 -25
- package/source/types/validate.mjs +26 -27
- package/source/types/version.mjs +17 -25
- package/source/util/clone.mjs +23 -32
- package/source/util/comparator.mjs +7 -15
- package/source/util/deadmansswitch.mjs +16 -23
- package/source/util/freeze.mjs +5 -7
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +33 -39
- package/source/util/trimspaces.mjs +17 -24
- package/test/cases/monster.mjs +1 -1
package/source/dom/events.mjs
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {isArray, isObject} from "../types/is.mjs";
|
9
|
-
import {validateInstance, validateString} from "../types/validate.mjs";
|
10
|
-
import {getDocument} from "./util.mjs";
|
8
|
+
import { isArray, isObject } from "../types/is.mjs";
|
9
|
+
import { validateInstance, validateString } from "../types/validate.mjs";
|
10
|
+
import { getDocument } from "./util.mjs";
|
11
11
|
|
12
|
-
export {fireEvent, fireCustomEvent, findTargetElementFromEvent}
|
12
|
+
export { fireEvent, fireCustomEvent, findTargetElementFromEvent };
|
13
13
|
|
14
14
|
/**
|
15
15
|
* The function sends an event
|
@@ -25,12 +25,10 @@ export {fireEvent, fireCustomEvent, findTargetElementFromEvent}
|
|
25
25
|
* @summary Construct and send and event
|
26
26
|
*/
|
27
27
|
function fireEvent(element, type) {
|
28
|
-
|
29
28
|
const document = getDocument();
|
30
29
|
|
31
30
|
if (element instanceof HTMLElement) {
|
32
|
-
|
33
|
-
if (type === 'click') {
|
31
|
+
if (type === "click") {
|
34
32
|
element.click();
|
35
33
|
return;
|
36
34
|
}
|
@@ -41,15 +39,13 @@ function fireEvent(element, type) {
|
|
41
39
|
});
|
42
40
|
|
43
41
|
element.dispatchEvent(event);
|
44
|
-
|
45
42
|
} else if (element instanceof HTMLCollection || element instanceof NodeList) {
|
46
43
|
for (let e of element) {
|
47
44
|
fireEvent(e, type);
|
48
45
|
}
|
49
46
|
} else {
|
50
|
-
throw new TypeError(
|
47
|
+
throw new TypeError("value is not an instance of HTMLElement or HTMLCollection");
|
51
48
|
}
|
52
|
-
|
53
49
|
}
|
54
50
|
|
55
51
|
/**
|
@@ -66,38 +62,34 @@ function fireEvent(element, type) {
|
|
66
62
|
* @summary Construct and send and event
|
67
63
|
*/
|
68
64
|
function fireCustomEvent(element, type, detail) {
|
69
|
-
|
70
65
|
const document = getDocument();
|
71
66
|
|
72
67
|
if (element instanceof HTMLElement) {
|
73
|
-
|
74
68
|
if (!isObject(detail)) {
|
75
|
-
detail = {detail};
|
69
|
+
detail = { detail };
|
76
70
|
}
|
77
71
|
|
78
72
|
let event = new CustomEvent(validateString(type), {
|
79
73
|
bubbles: true,
|
80
74
|
cancelable: true,
|
81
|
-
detail
|
75
|
+
detail,
|
82
76
|
});
|
83
77
|
|
84
78
|
element.dispatchEvent(event);
|
85
|
-
|
86
79
|
} else if (element instanceof HTMLCollection || element instanceof NodeList) {
|
87
80
|
for (let e of element) {
|
88
81
|
fireCustomEvent(e, type, detail);
|
89
82
|
}
|
90
83
|
} else {
|
91
|
-
throw new TypeError(
|
84
|
+
throw new TypeError("value is not an instance of HTMLElement or HTMLCollection");
|
92
85
|
}
|
93
|
-
|
94
86
|
}
|
95
87
|
|
96
88
|
/**
|
97
89
|
* This function gets the path `Event.composedPath()` from an event and tries to find the next element
|
98
90
|
* up the tree `element.closest()` with the attribute and value. If no value, or a value that is undefined or null,
|
99
91
|
* is specified, only the attribute is searched.
|
100
|
-
*
|
92
|
+
*
|
101
93
|
* @license AGPLv3
|
102
94
|
* @since 1.14.0
|
103
95
|
* @param {Event} event
|
@@ -112,8 +104,8 @@ function fireCustomEvent(element, type, detail) {
|
|
112
104
|
function findTargetElementFromEvent(event, attributeName, attributeValue) {
|
113
105
|
validateInstance(event, Event);
|
114
106
|
|
115
|
-
if (typeof event.composedPath !==
|
116
|
-
throw new Error(
|
107
|
+
if (typeof event.composedPath !== "function") {
|
108
|
+
throw new Error("unsupported event");
|
117
109
|
}
|
118
110
|
|
119
111
|
const path = event.composedPath();
|
@@ -123,14 +115,15 @@ function findTargetElementFromEvent(event, attributeName, attributeValue) {
|
|
123
115
|
for (let i = 0; i < path.length; i++) {
|
124
116
|
const o = path[i];
|
125
117
|
|
126
|
-
if (
|
127
|
-
o
|
128
|
-
|
118
|
+
if (
|
119
|
+
o instanceof HTMLElement &&
|
120
|
+
o.hasAttribute(attributeName) &&
|
121
|
+
(attributeValue === undefined || o.getAttribute(attributeName) === attributeValue)
|
122
|
+
) {
|
129
123
|
return o;
|
130
124
|
}
|
131
125
|
}
|
132
126
|
}
|
133
127
|
|
134
128
|
return undefined;
|
135
|
-
|
136
129
|
}
|
@@ -5,37 +5,35 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {extend} from "../data/extend.mjs";
|
9
|
-
import {BaseWithOptions} from "../types/basewithoptions.mjs";
|
10
|
-
import {getGlobalObject} from "../types/global.mjs";
|
11
|
-
import {isArray} from "../types/is.mjs";
|
12
|
-
import {Stack} from "../types/stack.mjs";
|
13
|
-
import {validateInstance, validateString} from "../types/validate.mjs";
|
14
|
-
import {instanceSymbol} from
|
15
|
-
export {FocusManager}
|
8
|
+
import { extend } from "../data/extend.mjs";
|
9
|
+
import { BaseWithOptions } from "../types/basewithoptions.mjs";
|
10
|
+
import { getGlobalObject } from "../types/global.mjs";
|
11
|
+
import { isArray } from "../types/is.mjs";
|
12
|
+
import { Stack } from "../types/stack.mjs";
|
13
|
+
import { validateInstance, validateString } from "../types/validate.mjs";
|
14
|
+
import { instanceSymbol } from "../constants.mjs";
|
15
|
+
export { FocusManager };
|
16
16
|
|
17
17
|
/**
|
18
18
|
* @private
|
19
19
|
* @type {string}
|
20
20
|
*/
|
21
|
-
const KEY_DOCUMENT =
|
21
|
+
const KEY_DOCUMENT = "document";
|
22
22
|
|
23
23
|
/**
|
24
24
|
* @private
|
25
25
|
* @type {string}
|
26
26
|
*/
|
27
|
-
const KEY_CONTEXT =
|
28
|
-
|
27
|
+
const KEY_CONTEXT = "context";
|
29
28
|
|
30
29
|
/**
|
31
30
|
* @private
|
32
31
|
* @type {Symbol}
|
33
32
|
*/
|
34
|
-
const stackSymbol = Symbol(
|
35
|
-
|
33
|
+
const stackSymbol = Symbol("stack");
|
36
34
|
|
37
35
|
/**
|
38
|
-
* With the
|
36
|
+
* With the focus manager the focus can be stored in a document, recalled and moved.
|
39
37
|
*
|
40
38
|
* @license AGPLv3
|
41
39
|
* @since 1.25.0
|
@@ -44,8 +42,7 @@ const stackSymbol = Symbol('stack');
|
|
44
42
|
* @throws {Error} unsupported locale
|
45
43
|
* @summary Handle the focus
|
46
44
|
*/
|
47
|
-
|
48
|
-
|
45
|
+
class FocusManager extends BaseWithOptions {
|
49
46
|
/**
|
50
47
|
*
|
51
48
|
* @param {Object|undefined} options
|
@@ -66,15 +63,14 @@ const stackSymbol = Symbol('stack');
|
|
66
63
|
return Symbol.for("@schukai/monster/dom/focusmanager");
|
67
64
|
}
|
68
65
|
|
69
|
-
|
70
66
|
/**
|
71
67
|
* @property {HTMLDocument} document the document object into which the node is to be appended
|
72
68
|
*/
|
73
69
|
get defaults() {
|
74
70
|
return extend({}, super.defaults, {
|
75
|
-
[KEY_DOCUMENT]: getGlobalObject(
|
71
|
+
[KEY_DOCUMENT]: getGlobalObject("document"),
|
76
72
|
[KEY_CONTEXT]: undefined,
|
77
|
-
})
|
73
|
+
});
|
78
74
|
}
|
79
75
|
|
80
76
|
/**
|
@@ -84,10 +80,9 @@ const stackSymbol = Symbol('stack');
|
|
84
80
|
* @return {Monster.DOM.FocusManager}
|
85
81
|
*/
|
86
82
|
storeFocus() {
|
87
|
-
|
88
83
|
const active = this.getActive();
|
89
84
|
if (active instanceof Node) {
|
90
|
-
this[stackSymbol].push(active)
|
85
|
+
this[stackSymbol].push(active);
|
91
86
|
}
|
92
87
|
return this;
|
93
88
|
}
|
@@ -98,7 +93,6 @@ const stackSymbol = Symbol('stack');
|
|
98
93
|
* @return {Monster.DOM.FocusManager}
|
99
94
|
*/
|
100
95
|
restoreFocus() {
|
101
|
-
|
102
96
|
const last = this[stackSymbol].pop();
|
103
97
|
if (last instanceof Node) {
|
104
98
|
this.focus(last);
|
@@ -115,12 +109,11 @@ const stackSymbol = Symbol('stack');
|
|
115
109
|
* @return {Monster.DOM.FocusManager}
|
116
110
|
*/
|
117
111
|
focus(element, preventScroll) {
|
118
|
-
|
119
|
-
validateInstance(element, Node)
|
112
|
+
validateInstance(element, Node);
|
120
113
|
|
121
114
|
element.focus({
|
122
|
-
preventScroll: preventScroll ?? false
|
123
|
-
})
|
115
|
+
preventScroll: preventScroll ?? false,
|
116
|
+
});
|
124
117
|
|
125
118
|
return this;
|
126
119
|
}
|
@@ -141,32 +134,32 @@ const stackSymbol = Symbol('stack');
|
|
141
134
|
* @throws {TypeError} value is not an instance of
|
142
135
|
*/
|
143
136
|
getFocusable(query) {
|
144
|
-
|
145
137
|
let contextElement = this.getOption(KEY_CONTEXT);
|
146
138
|
if (contextElement === undefined) {
|
147
139
|
contextElement = this.getOption(KEY_DOCUMENT);
|
148
140
|
}
|
149
141
|
|
150
|
-
validateInstance(contextElement, Node)
|
142
|
+
validateInstance(contextElement, Node);
|
151
143
|
|
152
144
|
if (query !== undefined) {
|
153
145
|
validateString(query);
|
154
146
|
}
|
155
147
|
|
156
|
-
return [
|
157
|
-
|
158
|
-
|
159
|
-
|
148
|
+
return [
|
149
|
+
...contextElement.querySelectorAll(
|
150
|
+
'details, button, input, [tabindex]:not([tabindex="-1"]), select, textarea, a[href], body',
|
151
|
+
),
|
152
|
+
].filter((element) => {
|
160
153
|
if (query !== undefined && !element.matches(query)) {
|
161
154
|
return false;
|
162
155
|
}
|
163
156
|
|
164
|
-
if (element.hasAttribute(
|
165
|
-
if (element.getAttribute("aria-hidden") ===
|
157
|
+
if (element.hasAttribute("disabled")) return false;
|
158
|
+
if (element.getAttribute("aria-hidden") === "true") return false;
|
166
159
|
|
167
160
|
const rect = element.getBoundingClientRect();
|
168
|
-
if(rect.width===0) return false;
|
169
|
-
if(rect.height===0) return false;
|
161
|
+
if (rect.width === 0) return false;
|
162
|
+
if (rect.height === 0) return false;
|
170
163
|
|
171
164
|
return true;
|
172
165
|
});
|
@@ -177,7 +170,6 @@ const stackSymbol = Symbol('stack');
|
|
177
170
|
* @return {Monster.DOM.FocusManager}
|
178
171
|
*/
|
179
172
|
focusNext(query) {
|
180
|
-
|
181
173
|
const current = this.getActive();
|
182
174
|
const focusable = this.getFocusable(query);
|
183
175
|
|
@@ -194,7 +186,7 @@ const stackSymbol = Symbol('stack');
|
|
194
186
|
this.focus(focusable[0]);
|
195
187
|
}
|
196
188
|
} else {
|
197
|
-
this.focus(focusable[0])
|
189
|
+
this.focus(focusable[0]);
|
198
190
|
}
|
199
191
|
|
200
192
|
return this;
|
@@ -205,7 +197,6 @@ const stackSymbol = Symbol('stack');
|
|
205
197
|
* @return {Monster.DOM.FocusManager}
|
206
198
|
*/
|
207
199
|
focusPrev(query) {
|
208
|
-
|
209
200
|
const current = this.getActive();
|
210
201
|
const focusable = this.getFocusable(query);
|
211
202
|
|
@@ -222,18 +213,9 @@ const stackSymbol = Symbol('stack');
|
|
222
213
|
this.focus(focusable[focusable.length - 1]);
|
223
214
|
}
|
224
215
|
} else {
|
225
|
-
this.focus(focusable[focusable.length - 1])
|
216
|
+
this.focus(focusable[focusable.length - 1]);
|
226
217
|
}
|
227
218
|
|
228
219
|
return this;
|
229
220
|
}
|
230
|
-
|
231
|
-
|
232
221
|
}
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
package/source/dom/locale.mjs
CHANGED
@@ -5,27 +5,28 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {parseLocale} from "../i18n/locale.mjs";
|
9
|
-
import {getDocument} from "./util.mjs";
|
10
|
-
import {getGlobalObject} from "../types/global.mjs";
|
8
|
+
import { parseLocale } from "../i18n/locale.mjs";
|
9
|
+
import { getDocument } from "./util.mjs";
|
10
|
+
import { getGlobalObject } from "../types/global.mjs";
|
11
11
|
|
12
|
-
export {getLocaleOfDocument}
|
12
|
+
export { getLocaleOfDocument };
|
13
13
|
|
14
14
|
/**
|
15
15
|
* @private
|
16
16
|
* @type {string}
|
17
17
|
*/
|
18
|
-
const DEFAULT_LANGUAGE =
|
18
|
+
const DEFAULT_LANGUAGE = "en";
|
19
19
|
|
20
20
|
/**
|
21
21
|
* With this function you can read the language version set by the document.
|
22
22
|
* For this the attribute `lang` in the html tag is read. If no attribute is set, `en` is used as default.
|
23
|
+
* Alternatively, the language version of the browser is used.
|
23
24
|
*
|
24
25
|
* ```html
|
25
26
|
* <html lang="en">
|
26
27
|
* ```
|
27
28
|
*
|
28
|
-
* You can call the function via
|
29
|
+
* You can call the function via `getLocaleOfDocument()`.
|
29
30
|
*
|
30
31
|
* @license AGPLv3
|
31
32
|
* @since 1.13.0
|
@@ -36,17 +37,16 @@ const DEFAULT_LANGUAGE = 'en';
|
|
36
37
|
* @summary Tries to determine the locale used
|
37
38
|
*/
|
38
39
|
function getLocaleOfDocument() {
|
39
|
-
|
40
40
|
const document = getDocument();
|
41
41
|
|
42
|
-
let html = document.querySelector(
|
43
|
-
if (html instanceof HTMLElement && html.hasAttribute(
|
44
|
-
let locale = html.getAttribute(
|
42
|
+
let html = document.querySelector("html");
|
43
|
+
if (html instanceof HTMLElement && html.hasAttribute("lang")) {
|
44
|
+
let locale = html.getAttribute("lang");
|
45
45
|
if (locale) {
|
46
|
-
return new parseLocale(locale)
|
46
|
+
return new parseLocale(locale);
|
47
47
|
}
|
48
48
|
}
|
49
|
-
|
49
|
+
|
50
50
|
let navigatorLanguage = getNavigatorLanguage();
|
51
51
|
if (navigatorLanguage) {
|
52
52
|
return parseLocale(navigatorLanguage);
|
@@ -62,24 +62,22 @@ function getLocaleOfDocument() {
|
|
62
62
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages
|
63
63
|
*/
|
64
64
|
const getNavigatorLanguage = () => {
|
65
|
-
const navigator = getGlobalObject(
|
65
|
+
const navigator = getGlobalObject("navigator");
|
66
66
|
if (navigator === undefined) {
|
67
67
|
return undefined;
|
68
68
|
}
|
69
69
|
|
70
|
-
if (navigator.hasOwnProperty(
|
70
|
+
if (navigator.hasOwnProperty("language")) {
|
71
71
|
const language = navigator.language;
|
72
|
-
if (typeof language ===
|
72
|
+
if (typeof language === "string" && language.length > 0) {
|
73
73
|
return language;
|
74
74
|
}
|
75
|
-
|
76
75
|
}
|
77
76
|
|
78
77
|
const languages = navigator?.languages;
|
79
|
-
if (Array.isArray(languages) && languages.length>0) {
|
78
|
+
if (Array.isArray(languages) && languages.length > 0) {
|
80
79
|
return languages[0];
|
81
80
|
}
|
82
|
-
|
83
|
-
return undefined;
|
84
81
|
|
85
|
-
|
82
|
+
return undefined;
|
83
|
+
};
|
package/source/dom/namespace.mjs
CHANGED
package/source/dom/ready.mjs
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {getDocument, getWindow} from "./util.mjs";
|
8
|
+
import { getDocument, getWindow } from "./util.mjs";
|
9
9
|
|
10
|
-
export {domReady, windowReady}
|
10
|
+
export { domReady, windowReady };
|
11
11
|
|
12
12
|
/**
|
13
13
|
* This variable is a promise that is fulfilled as soon as the dom is available.
|
@@ -28,18 +28,16 @@ export {domReady, windowReady}
|
|
28
28
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event
|
29
29
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
|
30
30
|
*/
|
31
|
-
const domReady = new Promise(resolve => {
|
32
|
-
|
31
|
+
const domReady = new Promise((resolve) => {
|
33
32
|
const document = getDocument();
|
34
33
|
|
35
34
|
if (document.readyState === "loading") {
|
36
|
-
document.addEventListener(
|
35
|
+
document.addEventListener("DOMContentLoaded", resolve);
|
37
36
|
} else {
|
38
37
|
resolve();
|
39
38
|
}
|
40
39
|
});
|
41
40
|
|
42
|
-
|
43
41
|
/**
|
44
42
|
* This variable is a promise that is fulfilled as soon as the windows is available.
|
45
43
|
*
|
@@ -55,14 +53,13 @@ const domReady = new Promise(resolve => {
|
|
55
53
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event
|
56
54
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
|
57
55
|
*/
|
58
|
-
const windowReady = new Promise(resolve => {
|
59
|
-
|
56
|
+
const windowReady = new Promise((resolve) => {
|
60
57
|
const document = getDocument();
|
61
58
|
const window = getWindow();
|
62
59
|
|
63
|
-
if (document.readyState ===
|
60
|
+
if (document.readyState === "complete") {
|
64
61
|
resolve();
|
65
62
|
} else {
|
66
|
-
window.addEventListener(
|
63
|
+
window.addEventListener("load", resolve);
|
67
64
|
}
|
68
65
|
});
|
@@ -5,9 +5,9 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {internalStateSymbol} from "../../constants.mjs";
|
9
|
-
import {extend} from "../../data/extend.mjs";
|
10
|
-
import {getGlobalFunction} from "../../types/global.mjs";
|
8
|
+
import { internalStateSymbol } from "../../constants.mjs";
|
9
|
+
import { extend } from "../../data/extend.mjs";
|
10
|
+
import { getGlobalFunction } from "../../types/global.mjs";
|
11
11
|
import {
|
12
12
|
ATTRIBUTE_CLASS,
|
13
13
|
ATTRIBUTE_ERRORMESSAGE,
|
@@ -15,11 +15,11 @@ import {
|
|
15
15
|
ATTRIBUTE_SRC,
|
16
16
|
ATTRIBUTE_TITLE,
|
17
17
|
ATTRIBUTE_TYPE,
|
18
|
-
TAG_SCRIPT
|
18
|
+
TAG_SCRIPT,
|
19
19
|
} from "../constants.mjs";
|
20
|
-
import {KEY_DOCUMENT, KEY_QUERY, referenceSymbol, Resource} from "../resource.mjs";
|
21
|
-
import {instanceSymbol} from
|
22
|
-
export {Data}
|
20
|
+
import { KEY_DOCUMENT, KEY_QUERY, referenceSymbol, Resource } from "../resource.mjs";
|
21
|
+
import { instanceSymbol } from "../../constants.mjs";
|
22
|
+
export { Data };
|
23
23
|
|
24
24
|
/**
|
25
25
|
* This class is used by the resource manager to embed data.
|
@@ -31,7 +31,6 @@ export {Data}
|
|
31
31
|
* @summary A Data Resource class
|
32
32
|
*/
|
33
33
|
class Data extends Resource {
|
34
|
-
|
35
34
|
/**
|
36
35
|
* @property {string} mode=cors https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
37
36
|
* @property {string} credentials=same-origin https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
@@ -39,10 +38,10 @@ class Data extends Resource {
|
|
39
38
|
*/
|
40
39
|
get defaults() {
|
41
40
|
return extend({}, super.defaults, {
|
42
|
-
mode:
|
43
|
-
credentials:
|
44
|
-
type:
|
45
|
-
})
|
41
|
+
mode: "cors",
|
42
|
+
credentials: "same-origin",
|
43
|
+
type: "application/json",
|
44
|
+
});
|
46
45
|
}
|
47
46
|
|
48
47
|
/**
|
@@ -61,7 +60,6 @@ class Data extends Resource {
|
|
61
60
|
* @return {Monster.DOM.Resource}
|
62
61
|
*/
|
63
62
|
connect() {
|
64
|
-
|
65
63
|
if (!(this[referenceSymbol] instanceof HTMLElement)) {
|
66
64
|
this.create();
|
67
65
|
}
|
@@ -79,14 +77,12 @@ class Data extends Resource {
|
|
79
77
|
return Symbol.for("@schukai/monster/dom/resource/data");
|
80
78
|
}
|
81
79
|
|
82
|
-
|
83
80
|
/**
|
84
81
|
* @return {string}
|
85
82
|
*/
|
86
83
|
static getURLAttribute() {
|
87
|
-
return ATTRIBUTE_SRC
|
84
|
+
return ATTRIBUTE_SRC;
|
88
85
|
}
|
89
|
-
|
90
86
|
}
|
91
87
|
|
92
88
|
/**
|
@@ -108,7 +104,6 @@ function createElement() {
|
|
108
104
|
return self;
|
109
105
|
}
|
110
106
|
|
111
|
-
|
112
107
|
/**
|
113
108
|
* @private
|
114
109
|
* @return {Promise}
|
@@ -117,44 +112,41 @@ function createElement() {
|
|
117
112
|
function appendToDocument() {
|
118
113
|
const self = this;
|
119
114
|
|
120
|
-
const targetNode = document.querySelector(self.getOption(KEY_QUERY,
|
115
|
+
const targetNode = document.querySelector(self.getOption(KEY_QUERY, "head"));
|
121
116
|
if (!(targetNode instanceof HTMLElement)) {
|
122
|
-
throw new Error(
|
117
|
+
throw new Error("target not found");
|
123
118
|
}
|
124
119
|
|
125
120
|
targetNode.appendChild(self[referenceSymbol]);
|
126
121
|
|
127
|
-
getGlobalFunction(
|
128
|
-
method:
|
129
|
-
mode: self.getOption(
|
130
|
-
cache:
|
131
|
-
credentials: self.getOption(
|
122
|
+
getGlobalFunction("fetch")(self.getOption(ATTRIBUTE_SRC), {
|
123
|
+
method: "GET", // *GET, POST, PUT, DELETE, etc.
|
124
|
+
mode: self.getOption("mode", "cors"), // no-cors, *cors, same-origin
|
125
|
+
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
126
|
+
credentials: self.getOption("credentials", "same-origin"), // include, *same-origin, omit
|
132
127
|
headers: {
|
133
|
-
|
128
|
+
Accept: self.getOption("type", "application/json"),
|
134
129
|
},
|
135
|
-
redirect:
|
136
|
-
referrerPolicy:
|
137
|
-
})
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
}).then(text => {
|
143
|
-
|
144
|
-
const textNode = document.createTextNode(text);
|
145
|
-
self[referenceSymbol].appendChild(textNode);
|
146
|
-
|
147
|
-
self[internalStateSymbol].getSubject()['loaded'] = true;
|
148
|
-
|
149
|
-
|
150
|
-
}).catch(e => {
|
151
|
-
self[internalStateSymbol].setSubject({
|
152
|
-
loaded: true,
|
153
|
-
error: e.toString(),
|
130
|
+
redirect: "follow", // manual, *follow, error
|
131
|
+
referrerPolicy: "no-referrer", // no-referrer,
|
132
|
+
})
|
133
|
+
.then((response) => {
|
134
|
+
return response.text();
|
154
135
|
})
|
136
|
+
.then((text) => {
|
137
|
+
const textNode = document.createTextNode(text);
|
138
|
+
self[referenceSymbol].appendChild(textNode);
|
155
139
|
|
156
|
-
|
157
|
-
|
140
|
+
self[internalStateSymbol].getSubject()["loaded"] = true;
|
141
|
+
})
|
142
|
+
.catch((e) => {
|
143
|
+
self[internalStateSymbol].setSubject({
|
144
|
+
loaded: true,
|
145
|
+
error: e.toString(),
|
146
|
+
});
|
147
|
+
|
148
|
+
targetNode.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.toString());
|
149
|
+
});
|
158
150
|
|
159
151
|
return self;
|
160
152
|
}
|
@@ -5,10 +5,10 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {extend} from "../../../data/extend.mjs";
|
9
|
-
import {Link} from "../link.mjs";
|
10
|
-
import {instanceSymbol} from
|
11
|
-
export {Stylesheet}
|
8
|
+
import { extend } from "../../../data/extend.mjs";
|
9
|
+
import { Link } from "../link.mjs";
|
10
|
+
import { instanceSymbol } from "../../../constants.mjs";
|
11
|
+
export { Stylesheet };
|
12
12
|
|
13
13
|
/**
|
14
14
|
* This class is used by the resource manager to embed external resources.
|
@@ -21,14 +21,13 @@ export {Stylesheet}
|
|
21
21
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
|
22
22
|
*/
|
23
23
|
class Stylesheet extends Link {
|
24
|
-
|
25
24
|
/**
|
26
25
|
* @property {string} rel {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-rel}
|
27
26
|
*/
|
28
27
|
get defaults() {
|
29
28
|
return extend({}, super.defaults, {
|
30
|
-
rel:
|
31
|
-
})
|
29
|
+
rel: "stylesheet",
|
30
|
+
});
|
32
31
|
}
|
33
32
|
|
34
33
|
/**
|
@@ -37,9 +36,6 @@ class Stylesheet extends Link {
|
|
37
36
|
* @since 2.1.0
|
38
37
|
*/
|
39
38
|
static get [instanceSymbol]() {
|
40
|
-
return Symbol.for("@schukai/monster/dom/resource/link/stylesheet")
|
39
|
+
return Symbol.for("@schukai/monster/dom/resource/link/stylesheet");
|
41
40
|
}
|
42
|
-
|
43
|
-
|
44
41
|
}
|
45
|
-
|