@schukai/monster 1.23.0 → 1.26.1
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 +53 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -2
- package/dist/modules/data/datasource/storage/localstorage.js +2 -2
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
- package/dist/modules/data/datasource/storage.js +2 -2
- package/dist/modules/data/datasource.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -2
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +2 -0
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +2 -2
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +2 -2
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +1 -1
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +2 -2
- package/dist/modules/util/trimspaces.js +2 -0
- package/dist/monster.dev.js +1684 -696
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constants.js +16 -7
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +27 -11
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +87 -20
- package/source/data/datasource/storage/localstorage.js +4 -10
- package/source/data/datasource/storage/sessionstorage.js +4 -12
- package/source/data/datasource/storage.js +7 -14
- package/source/data/datasource.js +55 -17
- package/source/data/diff.js +8 -8
- package/source/data/extend.js +5 -5
- package/source/data/pathfinder.js +12 -6
- package/source/data/pipe.js +6 -5
- package/source/data/transformer.js +131 -24
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +305 -12
- package/source/dom/customcontrol.js +40 -19
- package/source/dom/customelement.js +121 -92
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +250 -0
- package/source/dom/locale.js +10 -5
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +52 -12
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +47 -33
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +10 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +24 -14
- package/source/i18n/translations.js +20 -10
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +4 -4
- package/source/math/random.js +11 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +244 -27
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +10 -15
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +6 -6
- package/source/types/global.js +9 -7
- package/source/types/id.js +6 -3
- package/source/types/is.js +103 -85
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +3 -3
- package/source/types/proxyobserver.js +24 -7
- package/source/types/queue.js +6 -6
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +8 -9
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +4 -4
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +4 -5
- package/source/util/comparator.js +5 -5
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +33 -36
- package/source/util/trimspaces.js +85 -0
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/datasource.js +4 -4
- package/test/cases/data/diff.js +4 -4
- package/test/cases/data/pathfinder.js +18 -9
- package/test/cases/data/pipe.js +26 -2
- package/test/cases/data/transformer.js +41 -10
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/customcontrol.js +6 -5
- package/test/cases/dom/customelement.js +14 -16
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/updater.js +28 -4
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +71 -8
- package/test/cases/types/node.js +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -0
- package/test/cases/types/proxyobserver.js +55 -11
- package/test/cases/types/regex.js +32 -0
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/cases/util/trimspaces.js +24 -0
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +22 -9
- package/test/web/import.js +15 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +7 -7
package/source/dom/template.js
CHANGED
|
@@ -14,8 +14,8 @@ import {getDocumentTheme} from "./theme.js";
|
|
|
14
14
|
*
|
|
15
15
|
* ```
|
|
16
16
|
* <script type="module">
|
|
17
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
18
|
-
*
|
|
17
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
18
|
+
* new Monster.DOM.Template()
|
|
19
19
|
* </script>
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
@@ -23,8 +23,8 @@ import {getDocumentTheme} from "./theme.js";
|
|
|
23
23
|
*
|
|
24
24
|
* ```
|
|
25
25
|
* <script type="module">
|
|
26
|
-
* import {Template} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
27
|
-
*
|
|
26
|
+
* import {Template} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/template.js';
|
|
27
|
+
* new Template()
|
|
28
28
|
* </script>
|
|
29
29
|
* ```
|
|
30
30
|
*
|
|
@@ -70,7 +70,7 @@ class Template extends Base {
|
|
|
70
70
|
/**
|
|
71
71
|
* This method loads a template with the given ID and returns it.
|
|
72
72
|
*
|
|
73
|
-
* To do this, it first
|
|
73
|
+
* To do this, it first reads the theme of the document and looks for the `data-monster-theme-name` attribute in the HTML tag.
|
|
74
74
|
*
|
|
75
75
|
* ```
|
|
76
76
|
* <html data-monster-theme-name="my-theme">
|
|
@@ -78,15 +78,15 @@ class Template extends Base {
|
|
|
78
78
|
*
|
|
79
79
|
* If no theme was specified, the default theme is `monster`.
|
|
80
80
|
*
|
|
81
|
-
* Now it is looked if there is a template with the given ID and theme `id-theme` and if yes it is returned.
|
|
81
|
+
* Now it is looked if there is a template with the given ID and theme `id-theme` and if yes it is returned.
|
|
82
82
|
* If there is no template a search for a template with the given ID `id` is done. If this is also not found, an error is thrown.
|
|
83
83
|
*
|
|
84
84
|
* You can call the method via the monster namespace `Monster.DOM.findDocumentTemplate()`.
|
|
85
85
|
*
|
|
86
86
|
* ```
|
|
87
87
|
* <script type="module">
|
|
88
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
89
|
-
*
|
|
88
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
89
|
+
* Monster.DOM.findDocumentTemplate()
|
|
90
90
|
* </script>
|
|
91
91
|
* ```
|
|
92
92
|
*
|
|
@@ -94,11 +94,41 @@ class Template extends Base {
|
|
|
94
94
|
*
|
|
95
95
|
* ```
|
|
96
96
|
* <script type="module">
|
|
97
|
-
* import {findTemplate} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
98
|
-
*
|
|
97
|
+
* import {findTemplate} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/template.js';
|
|
98
|
+
* findDocumentTemplate()
|
|
99
99
|
* </script>
|
|
100
100
|
* ```
|
|
101
101
|
*
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* import { findDocumentTemplate } from "https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/template.js";
|
|
105
|
+
*
|
|
106
|
+
* const template = document.createElement("template");
|
|
107
|
+
* template.id = "myTemplate";
|
|
108
|
+
* template.innerHTML = "<p>my default template</p>";
|
|
109
|
+
* document.body.appendChild(template);
|
|
110
|
+
*
|
|
111
|
+
* const themedTemplate = document.createElement("template");
|
|
112
|
+
* themedTemplate.id = "myTemplate-myTheme";
|
|
113
|
+
* themedTemplate.innerHTML = "<p>my themed template</p>";
|
|
114
|
+
* document.body.appendChild(themedTemplate);
|
|
115
|
+
*
|
|
116
|
+
* // loads the temple and since no theme is set the default template
|
|
117
|
+
* const template1 = findDocumentTemplate("myTemplate");
|
|
118
|
+
* console.log(template1.createDocumentFragment());
|
|
119
|
+
* // ↦ '<p>my default template</p>'
|
|
120
|
+
*
|
|
121
|
+
* // now we set our own theme
|
|
122
|
+
* document
|
|
123
|
+
* .querySelector("html")
|
|
124
|
+
* .setAttribute("data-monster-theme-name", "myTheme");
|
|
125
|
+
*
|
|
126
|
+
* // now we don't get the default template,
|
|
127
|
+
* // but the template with the theme in the id
|
|
128
|
+
* const template2 = findDocumentTemplate("myTemplate");
|
|
129
|
+
* console.log(template2.createDocumentFragment());
|
|
130
|
+
* // ↦ '<p>my themed template</p>'
|
|
131
|
+
*
|
|
102
132
|
* @param {string} id
|
|
103
133
|
* @param {Node} currentNode
|
|
104
134
|
* @return {Monster.DOM.Template}
|
|
@@ -132,18 +162,28 @@ function findDocumentTemplate(id, currentNode) {
|
|
|
132
162
|
let theme = getDocumentTheme()
|
|
133
163
|
let themedID = id + '-' + theme.getName();
|
|
134
164
|
|
|
165
|
+
// current + themedID
|
|
135
166
|
let template = currentNode.getElementById(themedID);
|
|
136
167
|
if (template instanceof HTMLTemplateElement) {
|
|
137
168
|
return new Template(template);
|
|
138
169
|
}
|
|
139
170
|
|
|
171
|
+
// document + themedID
|
|
172
|
+
template = getGlobalObject('document').getElementById(themedID);
|
|
173
|
+
if (template instanceof HTMLTemplateElement) {
|
|
174
|
+
return new Template(template);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// current + ID
|
|
140
178
|
template = currentNode.getElementById(id);
|
|
141
179
|
if (template instanceof HTMLTemplateElement) {
|
|
142
180
|
return new Template(template);
|
|
143
181
|
}
|
|
144
182
|
|
|
145
|
-
|
|
146
|
-
|
|
183
|
+
// document + ID
|
|
184
|
+
template = getGlobalObject('document').getElementById(id);
|
|
185
|
+
if (template instanceof HTMLTemplateElement) {
|
|
186
|
+
return new Template(template);
|
|
147
187
|
}
|
|
148
188
|
|
|
149
189
|
throw new Error("template " + id + " not found.")
|
package/source/dom/theme.js
CHANGED
|
@@ -15,7 +15,7 @@ import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.js";
|
|
|
15
15
|
*
|
|
16
16
|
* ```
|
|
17
17
|
* <script type="module">
|
|
18
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
19
19
|
* console.log(new Monster.DOM.Theme())
|
|
20
20
|
* </script>
|
|
21
21
|
* ```
|
|
@@ -24,14 +24,14 @@ import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.js";
|
|
|
24
24
|
*
|
|
25
25
|
* ```
|
|
26
26
|
* <script type="module">
|
|
27
|
-
* import {Theme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
27
|
+
* import {Theme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/theme.js';
|
|
28
28
|
* console.log(new Theme())
|
|
29
29
|
* </script>
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
*
|
|
34
|
-
* import {getDocumentTheme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
34
|
+
* import {getDocumentTheme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/theme.js';
|
|
35
35
|
*
|
|
36
36
|
* const theme = getDocumentTheme();
|
|
37
37
|
* console.log(theme.getName());
|
package/source/dom/updater.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {diff} from "../data/diff.js";
|
|
8
8
|
import {Pathfinder} from "../data/pathfinder.js";
|
|
9
9
|
import {Pipe} from "../data/pipe.js";
|
|
10
10
|
import {
|
|
11
|
+
ATTRIBUTE_ERRORMESSAGE,
|
|
11
12
|
ATTRIBUTE_UPDATER_ATTRIBUTES,
|
|
12
13
|
ATTRIBUTE_UPDATER_BIND,
|
|
13
14
|
ATTRIBUTE_UPDATER_INSERT,
|
|
14
15
|
ATTRIBUTE_UPDATER_INSERT_REFERENCE,
|
|
15
16
|
ATTRIBUTE_UPDATER_REMOVE,
|
|
16
|
-
ATTRIBUTE_UPDATER_REPLACE
|
|
17
|
-
OBJECTLINK_KEY_UPDATER
|
|
17
|
+
ATTRIBUTE_UPDATER_REPLACE
|
|
18
18
|
} from "../dom/constants.js";
|
|
19
19
|
import {assignToNamespace, Monster} from '../namespace.js';
|
|
20
20
|
import {Base} from "../types/base.js";
|
|
@@ -23,16 +23,11 @@ import {Observer} from "../types/observer.js";
|
|
|
23
23
|
import {ProxyObserver} from "../types/proxyobserver.js";
|
|
24
24
|
import {validateArray, validateInstance} from "../types/validate.js";
|
|
25
25
|
import {clone} from "../util/clone.js";
|
|
26
|
+
import {trimSpaces} from "../util/trimspaces.js";
|
|
26
27
|
import {findDocumentTemplate} from "./template.js";
|
|
27
28
|
import {getDocument} from "./util.js";
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
/**
|
|
31
|
-
* @private
|
|
32
|
-
* @type {symbol}
|
|
33
|
-
*/
|
|
34
|
-
const objectLinkSymbol = Symbol.for(OBJECTLINK_KEY_UPDATER);
|
|
35
|
-
|
|
36
31
|
/**
|
|
37
32
|
* The updater class connects an object with the dom. In this way, structures and contents in the DOM can be programmatically adapted via attributes.
|
|
38
33
|
*
|
|
@@ -43,7 +38,7 @@ const objectLinkSymbol = Symbol.for(OBJECTLINK_KEY_UPDATER);
|
|
|
43
38
|
*
|
|
44
39
|
* ```
|
|
45
40
|
* <script type="module">
|
|
46
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
41
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
47
42
|
* new Monster.DOM.Updater()
|
|
48
43
|
* </script>
|
|
49
44
|
* ```
|
|
@@ -52,14 +47,14 @@ const objectLinkSymbol = Symbol.for(OBJECTLINK_KEY_UPDATER);
|
|
|
52
47
|
*
|
|
53
48
|
* ```
|
|
54
49
|
* <script type="module">
|
|
55
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
50
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/updater.js';
|
|
56
51
|
* new Updater()
|
|
57
52
|
* </script>
|
|
58
53
|
* ```
|
|
59
54
|
*
|
|
60
55
|
* @example
|
|
61
56
|
*
|
|
62
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
57
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/updater.js';
|
|
63
58
|
*
|
|
64
59
|
* // First we prepare the html document.
|
|
65
60
|
* // This is done here via script, but can also be inserted into the document as pure html.
|
|
@@ -73,7 +68,7 @@ const objectLinkSymbol = Symbol.for(OBJECTLINK_KEY_UPDATER);
|
|
|
73
68
|
* let obj = {
|
|
74
69
|
* headline: "Hello World",
|
|
75
70
|
* };
|
|
76
|
-
*
|
|
71
|
+
*
|
|
77
72
|
* // Now comes the real magic. we pass the updater the parent HTMLElement
|
|
78
73
|
* // and the desired data structure.
|
|
79
74
|
* const updater = new Updater(body, obj);
|
|
@@ -129,10 +124,10 @@ class Updater extends Base {
|
|
|
129
124
|
|
|
130
125
|
const s = this.subject.getRealSubject();
|
|
131
126
|
|
|
132
|
-
const
|
|
127
|
+
const diffResult = diff(this.last, s)
|
|
133
128
|
this.last = clone(s);
|
|
134
129
|
|
|
135
|
-
for (const [, change] of Object.entries(
|
|
130
|
+
for (const [, change] of Object.entries(diffResult)) {
|
|
136
131
|
removeElement.call(this, change);
|
|
137
132
|
insertElement.call(this, change);
|
|
138
133
|
updateContent.call(this, change);
|
|
@@ -217,13 +212,13 @@ class Updater extends Base {
|
|
|
217
212
|
}
|
|
218
213
|
|
|
219
214
|
/**
|
|
220
|
-
* If you have passed a ProxyObserver in the constructor, you will get the
|
|
221
|
-
* However, if you
|
|
215
|
+
* If you have passed a ProxyObserver in the constructor, you will get the object that the ProxyObserver manages here.
|
|
216
|
+
* However, if you passed a simple object, here you will get a proxy for that object.
|
|
222
217
|
*
|
|
223
218
|
* For changes the ProxyObserver must be used.
|
|
224
219
|
*
|
|
225
220
|
* @since 1.8.0
|
|
226
|
-
* @return {
|
|
221
|
+
* @return {Proxy}
|
|
227
222
|
*/
|
|
228
223
|
getSubject() {
|
|
229
224
|
return this.subject.getSubject();
|
|
@@ -358,9 +353,9 @@ function getControlEventHandler() {
|
|
|
358
353
|
const pf = new Pathfinder(copy);
|
|
359
354
|
pf.setVia(path, value);
|
|
360
355
|
|
|
361
|
-
const
|
|
356
|
+
const diffResult = diff(copy, self.subject.getRealSubject());
|
|
362
357
|
|
|
363
|
-
if (
|
|
358
|
+
if (diffResult.length > 0) {
|
|
364
359
|
pathfinder.setVia(path, value);
|
|
365
360
|
}
|
|
366
361
|
|
|
@@ -422,11 +417,11 @@ function insertElement(change) {
|
|
|
422
417
|
found = true;
|
|
423
418
|
|
|
424
419
|
const attributes = containerElement.getAttribute(ATTRIBUTE_UPDATER_INSERT);
|
|
425
|
-
let def = attributes
|
|
420
|
+
let def = trimSpaces(attributes);
|
|
426
421
|
let i = def.indexOf(' ');
|
|
427
|
-
let key = def.substr(0, i)
|
|
422
|
+
let key = trimSpaces(def.substr(0, i));
|
|
428
423
|
let refPrefix = key + '-';
|
|
429
|
-
let cmd = def.substr(i)
|
|
424
|
+
let cmd = trimSpaces(def.substr(i));
|
|
430
425
|
|
|
431
426
|
// this case is actually excluded by the query but is nevertheless checked again here
|
|
432
427
|
if (cmd.indexOf('|') > 0) {
|
|
@@ -438,7 +433,14 @@ function insertElement(change) {
|
|
|
438
433
|
pipe.setCallback(n, f);
|
|
439
434
|
})
|
|
440
435
|
|
|
441
|
-
let value
|
|
436
|
+
let value
|
|
437
|
+
try {
|
|
438
|
+
containerElement.removeAttribute(ATTRIBUTE_ERRORMESSAGE);
|
|
439
|
+
value = pipe.run(subject)
|
|
440
|
+
} catch (e) {
|
|
441
|
+
containerElement.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.message);
|
|
442
|
+
}
|
|
443
|
+
|
|
442
444
|
let dataPath = cmd.split(':').pop();
|
|
443
445
|
|
|
444
446
|
let insertPoint;
|
|
@@ -528,12 +530,12 @@ function applyRecursive(node, key, path) {
|
|
|
528
530
|
|
|
529
531
|
if (node.hasAttribute(ATTRIBUTE_UPDATER_REPLACE)) {
|
|
530
532
|
let value = node.getAttribute(ATTRIBUTE_UPDATER_REPLACE);
|
|
531
|
-
node.setAttribute(ATTRIBUTE_UPDATER_REPLACE, value.
|
|
533
|
+
node.setAttribute(ATTRIBUTE_UPDATER_REPLACE, value.replaceAll("path:" + key, "path:" + path));
|
|
532
534
|
}
|
|
533
535
|
|
|
534
536
|
if (node.hasAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES)) {
|
|
535
537
|
let value = node.getAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES);
|
|
536
|
-
node.setAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES, value.
|
|
538
|
+
node.setAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES, value.replaceAll("path:" + key, "path:" + path));
|
|
537
539
|
}
|
|
538
540
|
|
|
539
541
|
for (const [, child] of Object.entries(node.childNodes)) {
|
|
@@ -605,14 +607,20 @@ function runUpdateContent(container, parts, subject) {
|
|
|
605
607
|
mem.add(element)
|
|
606
608
|
|
|
607
609
|
const attributes = element.getAttribute(ATTRIBUTE_UPDATER_REPLACE)
|
|
608
|
-
let cmd = attributes
|
|
610
|
+
let cmd = trimSpaces(attributes);
|
|
609
611
|
|
|
610
612
|
let pipe = new Pipe(cmd);
|
|
611
613
|
this.callbacks.forEach((f, n) => {
|
|
612
614
|
pipe.setCallback(n, f);
|
|
613
615
|
})
|
|
614
616
|
|
|
615
|
-
let value
|
|
617
|
+
let value
|
|
618
|
+
try {
|
|
619
|
+
element.removeAttribute(ATTRIBUTE_ERRORMESSAGE);
|
|
620
|
+
value = pipe.run(subject)
|
|
621
|
+
} catch (e) {
|
|
622
|
+
element.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.message);
|
|
623
|
+
}
|
|
616
624
|
|
|
617
625
|
if (value instanceof HTMLElement) {
|
|
618
626
|
while (element.firstChild) {
|
|
@@ -687,10 +695,10 @@ function runUpdateAttributes(container, parts, subject) {
|
|
|
687
695
|
const attributes = element.getAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES)
|
|
688
696
|
|
|
689
697
|
for (let [, def] of Object.entries(attributes.split(','))) {
|
|
690
|
-
def = def
|
|
698
|
+
def = trimSpaces(def);
|
|
691
699
|
let i = def.indexOf(' ');
|
|
692
|
-
let name = def.substr(0, i)
|
|
693
|
-
let cmd = def.substr(i)
|
|
700
|
+
let name = trimSpaces(def.substr(0, i));
|
|
701
|
+
let cmd = trimSpaces(def.substr(i));
|
|
694
702
|
|
|
695
703
|
let pipe = new Pipe(cmd);
|
|
696
704
|
|
|
@@ -698,7 +706,14 @@ function runUpdateAttributes(container, parts, subject) {
|
|
|
698
706
|
pipe.setCallback(n, f, element);
|
|
699
707
|
})
|
|
700
708
|
|
|
701
|
-
let value
|
|
709
|
+
let value
|
|
710
|
+
try {
|
|
711
|
+
element.removeAttribute(ATTRIBUTE_ERRORMESSAGE);
|
|
712
|
+
value = pipe.run(subject)
|
|
713
|
+
} catch (e) {
|
|
714
|
+
element.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.message);
|
|
715
|
+
}
|
|
716
|
+
|
|
702
717
|
|
|
703
718
|
if (value === undefined) {
|
|
704
719
|
element.removeAttribute(name)
|
|
@@ -709,7 +724,6 @@ function runUpdateAttributes(container, parts, subject) {
|
|
|
709
724
|
|
|
710
725
|
handleInputControlAttributeUpdate.call(this, element, name, value);
|
|
711
726
|
|
|
712
|
-
|
|
713
727
|
}
|
|
714
728
|
});
|
|
715
729
|
|
package/source/dom/util.js
CHANGED
|
@@ -13,7 +13,7 @@ import {validateString} from "../types/validate.js";
|
|
|
13
13
|
*
|
|
14
14
|
* ```
|
|
15
15
|
* <script type="module">
|
|
16
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
17
17
|
* console.log(Monster.DOM.getDocument())
|
|
18
18
|
* </script>
|
|
19
19
|
* ```
|
|
@@ -22,7 +22,7 @@ import {validateString} from "../types/validate.js";
|
|
|
22
22
|
*
|
|
23
23
|
* ```
|
|
24
24
|
* <script type="module">
|
|
25
|
-
* import {getDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
25
|
+
* import {getDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/util.js';
|
|
26
26
|
* console.log(getDocument())
|
|
27
27
|
* </script>
|
|
28
28
|
* ```
|
|
@@ -74,7 +74,7 @@ function getDocument() {
|
|
|
74
74
|
*
|
|
75
75
|
* ```
|
|
76
76
|
* <script type="module">
|
|
77
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
77
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
78
78
|
* console.log(Monster.DOM.getWindow())
|
|
79
79
|
* </script>
|
|
80
80
|
* ```
|
|
@@ -83,7 +83,7 @@ function getDocument() {
|
|
|
83
83
|
*
|
|
84
84
|
* ```
|
|
85
85
|
* <script type="module">
|
|
86
|
-
* import {getWindow} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
86
|
+
* import {getWindow} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/util.js';
|
|
87
87
|
* console.log(getWindow(null))
|
|
88
88
|
* </script>
|
|
89
89
|
* ```
|
|
@@ -140,7 +140,7 @@ function getWindow() {
|
|
|
140
140
|
*
|
|
141
141
|
* ```
|
|
142
142
|
* <script type="module">
|
|
143
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
143
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
144
144
|
* console.log(Monster.DOM.getDocumentFragmentFromString())
|
|
145
145
|
* </script>
|
|
146
146
|
* ```
|
|
@@ -149,7 +149,7 @@ function getWindow() {
|
|
|
149
149
|
*
|
|
150
150
|
* ```
|
|
151
151
|
* <script type="module">
|
|
152
|
-
* import {getDocumentFragmentFromString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
152
|
+
* import {getDocumentFragmentFromString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/util.js';
|
|
153
153
|
* console.log(getDocumentFragmentFromString('<div></div>'))
|
|
154
154
|
* </script>
|
|
155
155
|
* ```
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @author schukai GmbH
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import {internalSymbol} from "../../constants.js";
|
|
10
|
+
import {assignToNamespace, Monster} from "../../namespace.js";
|
|
11
|
+
import {Base} from "../../types/base.js";
|
|
12
|
+
import {getGlobal, getGlobalFunction} from "../../types/global.js";
|
|
13
|
+
import {isFunction} from "../../types/is.js";
|
|
14
|
+
import {validateInstance, validateString} from "../../types/validate.js";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* You can call the function via the monster namespace `new Monster.DOM.Worker.getLocaleOfDocument()`.
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
* <script type="module">
|
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
24
|
+
* console.log(new Monster.DOM.Worker.Factory())
|
|
25
|
+
* </script>
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Alternatively, you can also integrate this function individually.
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
* <script type="module">
|
|
32
|
+
* import {Factory} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/worker/factory.js';
|
|
33
|
+
* console.log(new Factory())
|
|
34
|
+
* </script>
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @since 1.25.0
|
|
38
|
+
* @copyright schukai GmbH
|
|
39
|
+
* @memberOf Monster.DOM.Worker
|
|
40
|
+
* @summary A small factory to create worker
|
|
41
|
+
*/
|
|
42
|
+
class Factory extends Base {
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
constructor() {
|
|
49
|
+
super();
|
|
50
|
+
this[internalSymbol] = {
|
|
51
|
+
worker: new WeakMap
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates a worker from a URL
|
|
57
|
+
*
|
|
58
|
+
* @param {string|URL} url
|
|
59
|
+
* @param {function} messageHandler
|
|
60
|
+
* @param {function} errorHandler
|
|
61
|
+
* @return {Worker}
|
|
62
|
+
*/
|
|
63
|
+
createFromURL = function (url, messageHandler, errorHandler) {
|
|
64
|
+
|
|
65
|
+
if (url instanceof URL) {
|
|
66
|
+
url = url.toString();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const workerClass = getGlobalFunction('Worker');
|
|
70
|
+
var worker = new workerClass(validateString(url));
|
|
71
|
+
|
|
72
|
+
if (isFunction(messageHandler)) {
|
|
73
|
+
worker.onmessage = (event) => {
|
|
74
|
+
messageHandler.call(worker, event);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (isFunction(errorHandler)) {
|
|
79
|
+
worker.onerror = (event) => {
|
|
80
|
+
errorHandler.call(worker, event);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return worker;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates a worker from a script
|
|
89
|
+
*
|
|
90
|
+
* @param {string} content
|
|
91
|
+
* @param {function} messageHandler
|
|
92
|
+
* @param {function} errorHandler
|
|
93
|
+
* @return {Worker}
|
|
94
|
+
* @see https://developer.mozilla.org/de/docs/Web/API/URL/createObjectURL
|
|
95
|
+
*/
|
|
96
|
+
createFromScript = function (content, messageHandler, errorHandler) {
|
|
97
|
+
const blobFunction = new getGlobalFunction('Blob')
|
|
98
|
+
const blob = new blobFunction([validateString(content)], {type: 'script/javascript'});
|
|
99
|
+
|
|
100
|
+
const url = getGlobalFunction('URL').createObjectURL(blob);
|
|
101
|
+
const worker = this.createFromURL(url, messageHandler, errorHandler);
|
|
102
|
+
|
|
103
|
+
this[internalSymbol]['worker'].set(worker, url);
|
|
104
|
+
|
|
105
|
+
return worker;
|
|
106
|
+
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Terminate the worker and call revokeObjectURL if necessary.
|
|
111
|
+
*
|
|
112
|
+
* @param worker
|
|
113
|
+
* @return {Monster.DOM.Worker.Factory}
|
|
114
|
+
*/
|
|
115
|
+
terminate(worker) {
|
|
116
|
+
|
|
117
|
+
const workerClass = getGlobalFunction('Worker');
|
|
118
|
+
validateInstance(worker, workerClass);
|
|
119
|
+
|
|
120
|
+
worker.terminate();
|
|
121
|
+
|
|
122
|
+
if (this[internalSymbol]['worker'].has(worker)) {
|
|
123
|
+
const url = this[internalSymbol]['worker'].get(worker);
|
|
124
|
+
URL.revokeObjectURL(url);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
assignToNamespace('Monster.DOM.Worker', Factory);
|
|
134
|
+
export {Monster, Factory}
|