@schukai/monster 1.26.1 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +11 -0
- package/README.md +3 -3
- package/dist/modules/constants.js +1 -1
- 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 +1 -1
- package/dist/modules/data/buildtree.js +1 -1
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +1 -1
- package/dist/modules/data/datasource/restapi.js +1 -1
- package/dist/modules/data/datasource/storage/localstorage.js +1 -1
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
- package/dist/modules/data/datasource/storage.js +1 -1
- package/dist/modules/data/datasource.js +1 -1
- package/dist/modules/data/diff.js +1 -1
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +1 -1
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +1 -1
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +2 -2
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +1 -1
- package/dist/modules/dom/customelement.js +1 -1
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +1 -1
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +1 -1
- package/dist/modules/dom/resource/link/stylesheet.js +1 -1
- package/dist/modules/dom/resource/link.js +1 -1
- package/dist/modules/dom/resource/script.js +1 -1
- package/dist/modules/dom/resource.js +1 -1
- package/dist/modules/dom/resourcemanager.js +1 -1
- 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 +1 -1
- package/dist/modules/i18n/formatter.js +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +1 -1
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +1 -1
- 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 +1 -1
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +1 -1
- package/dist/modules/types/nodelist.js +1 -1
- package/dist/modules/types/noderecursiveiterator.js +1 -1
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +1 -1
- package/dist/modules/types/proxyobserver.js +1 -1
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +1 -1
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +1 -1
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +1 -1
- 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 +1 -1
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +1 -1
- package/dist/modules/util/trimspaces.js +1 -1
- package/dist/monster.dev.js +731 -544
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +1 -1
- package/source/constraints/andoperator.js +5 -5
- package/source/constraints/invalid.js +3 -3
- package/source/constraints/isarray.js +3 -3
- package/source/constraints/isobject.js +3 -3
- package/source/constraints/oroperator.js +5 -5
- package/source/constraints/valid.js +3 -3
- package/source/data/buildmap.js +4 -4
- package/source/data/buildtree.js +2 -2
- package/source/data/datasource/restapi.js +3 -3
- package/source/data/datasource/storage/localstorage.js +2 -2
- package/source/data/datasource/storage/sessionstorage.js +2 -2
- package/source/data/datasource/storage.js +3 -3
- package/source/data/datasource.js +3 -3
- package/source/data/diff.js +3 -3
- package/source/data/extend.js +2 -2
- package/source/data/pathfinder.js +4 -4
- package/source/data/pipe.js +3 -3
- package/source/data/transformer.js +3 -3
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +111 -28
- package/source/dom/constants.js +9 -1
- package/source/dom/customcontrol.js +1 -1
- package/source/dom/customelement.js +1 -1
- package/source/dom/events.js +6 -7
- package/source/dom/focusmanager.js +2 -2
- package/source/dom/locale.js +2 -2
- package/source/dom/resource/data.js +2 -2
- package/source/dom/resource/link/stylesheet.js +2 -2
- package/source/dom/resource/link.js +2 -2
- package/source/dom/resource/script.js +2 -2
- package/source/dom/resource.js +2 -2
- package/source/dom/resourcemanager.js +2 -2
- package/source/dom/template.js +41 -11
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +134 -86
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +2 -2
- package/source/i18n/formatter.js +4 -4
- package/source/i18n/locale.js +4 -4
- package/source/i18n/provider.js +2 -2
- package/source/i18n/providers/fetch.js +3 -3
- package/source/i18n/translations.js +4 -4
- 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 +2 -2
- package/source/math/random.js +2 -2
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +3 -3
- package/source/types/base.js +2 -2
- package/source/types/basewithoptions.js +2 -2
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +4 -4
- package/source/types/global.js +4 -4
- package/source/types/id.js +2 -2
- package/source/types/is.js +20 -20
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +2 -2
- package/source/types/nodelist.js +2 -2
- package/source/types/noderecursiveiterator.js +4 -4
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +2 -2
- package/source/types/proxyobserver.js +5 -5
- package/source/types/queue.js +3 -3
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +2 -2
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +2 -2
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +2 -2
- package/source/types/uuid.js +2 -2
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +2 -2
- package/source/util/comparator.js +3 -3
- package/source/util/freeze.js +2 -2
- package/source/util/processing.js +3 -3
- package/source/util/trimspaces.js +2 -2
- package/test/cases/dom/attributes.js +29 -6
- package/test/cases/dom/template.js +72 -14
- package/test/cases/dom/updater.js +102 -75
- package/test/cases/monster.js +1 -1
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +2 -2
- package/test/web/tests.js +2 -2
package/source/dom/template.js
CHANGED
|
@@ -7,6 +7,7 @@ import {assignToNamespace, Monster} from '../namespace.js';
|
|
|
7
7
|
import {Base} from '../types/base.js';
|
|
8
8
|
import {getGlobalFunction, getGlobalObject} from '../types/global.js';
|
|
9
9
|
import {validateInstance, validateString} from "../types/validate.js";
|
|
10
|
+
import {ATTRIBUTE_TEMPLATE_PREFIX} from "./constants.js";
|
|
10
11
|
import {getDocumentTheme} from "./theme.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -14,7 +15,7 @@ import {getDocumentTheme} from "./theme.js";
|
|
|
14
15
|
*
|
|
15
16
|
* ```
|
|
16
17
|
* <script type="module">
|
|
17
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
|
|
18
19
|
* new Monster.DOM.Template()
|
|
19
20
|
* </script>
|
|
20
21
|
* ```
|
|
@@ -23,7 +24,7 @@ import {getDocumentTheme} from "./theme.js";
|
|
|
23
24
|
*
|
|
24
25
|
* ```
|
|
25
26
|
* <script type="module">
|
|
26
|
-
* import {Template} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
27
|
+
* import {Template} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/template.js';
|
|
27
28
|
* new Template()
|
|
28
29
|
* </script>
|
|
29
30
|
* ```
|
|
@@ -85,7 +86,7 @@ class Template extends Base {
|
|
|
85
86
|
*
|
|
86
87
|
* ```
|
|
87
88
|
* <script type="module">
|
|
88
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
89
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
|
|
89
90
|
* Monster.DOM.findDocumentTemplate()
|
|
90
91
|
* </script>
|
|
91
92
|
* ```
|
|
@@ -94,14 +95,14 @@ class Template extends Base {
|
|
|
94
95
|
*
|
|
95
96
|
* ```
|
|
96
97
|
* <script type="module">
|
|
97
|
-
* import {findTemplate} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
98
|
+
* import {findTemplate} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/template.js';
|
|
98
99
|
* findDocumentTemplate()
|
|
99
100
|
* </script>
|
|
100
101
|
* ```
|
|
101
102
|
*
|
|
102
103
|
* @example
|
|
103
104
|
*
|
|
104
|
-
* import { findDocumentTemplate } from "https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
105
|
+
* import { findDocumentTemplate } from "https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/template.js";
|
|
105
106
|
*
|
|
106
107
|
* const template = document.createElement("template");
|
|
107
108
|
* template.id = "myTemplate";
|
|
@@ -141,9 +142,22 @@ class Template extends Base {
|
|
|
141
142
|
function findDocumentTemplate(id, currentNode) {
|
|
142
143
|
validateString(id);
|
|
143
144
|
|
|
145
|
+
const document = getGlobalObject('document');
|
|
146
|
+
const HTMLTemplateElement = getGlobalFunction('HTMLTemplateElement');
|
|
147
|
+
const DocumentFragment = getGlobalFunction('DocumentFragment');
|
|
148
|
+
const Document = getGlobalFunction('Document');
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
let prefixID;
|
|
152
|
+
|
|
144
153
|
if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) {
|
|
145
154
|
|
|
146
155
|
if (currentNode instanceof Node) {
|
|
156
|
+
|
|
157
|
+
if (currentNode.hasAttribute(ATTRIBUTE_TEMPLATE_PREFIX)) {
|
|
158
|
+
prefixID = currentNode.getAttribute(ATTRIBUTE_TEMPLATE_PREFIX)
|
|
159
|
+
}
|
|
160
|
+
|
|
147
161
|
currentNode = currentNode.getRootNode();
|
|
148
162
|
|
|
149
163
|
if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) {
|
|
@@ -153,23 +167,39 @@ function findDocumentTemplate(id, currentNode) {
|
|
|
153
167
|
}
|
|
154
168
|
|
|
155
169
|
if (!(currentNode instanceof Document || currentNode instanceof DocumentFragment)) {
|
|
156
|
-
currentNode =
|
|
170
|
+
currentNode = document;
|
|
157
171
|
}
|
|
158
172
|
}
|
|
159
173
|
|
|
160
|
-
|
|
161
|
-
|
|
174
|
+
let template;
|
|
162
175
|
let theme = getDocumentTheme()
|
|
176
|
+
|
|
177
|
+
if (prefixID) {
|
|
178
|
+
let themedPrefixID = prefixID + '-' + id + '-' + theme.getName();
|
|
179
|
+
|
|
180
|
+
// current + themedPrefixID
|
|
181
|
+
template = currentNode.getElementById(themedPrefixID);
|
|
182
|
+
if (template instanceof HTMLTemplateElement) {
|
|
183
|
+
return new Template(template);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// document + themedPrefixID
|
|
187
|
+
template = document.getElementById(themedPrefixID);
|
|
188
|
+
if (template instanceof HTMLTemplateElement) {
|
|
189
|
+
return new Template(template);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
163
193
|
let themedID = id + '-' + theme.getName();
|
|
164
194
|
|
|
165
195
|
// current + themedID
|
|
166
|
-
|
|
196
|
+
template = currentNode.getElementById(themedID);
|
|
167
197
|
if (template instanceof HTMLTemplateElement) {
|
|
168
198
|
return new Template(template);
|
|
169
199
|
}
|
|
170
200
|
|
|
171
201
|
// document + themedID
|
|
172
|
-
template =
|
|
202
|
+
template = document.getElementById(themedID);
|
|
173
203
|
if (template instanceof HTMLTemplateElement) {
|
|
174
204
|
return new Template(template);
|
|
175
205
|
}
|
|
@@ -181,7 +211,7 @@ function findDocumentTemplate(id, currentNode) {
|
|
|
181
211
|
}
|
|
182
212
|
|
|
183
213
|
// document + ID
|
|
184
|
-
template =
|
|
214
|
+
template = document.getElementById(id);
|
|
185
215
|
if (template instanceof HTMLTemplateElement) {
|
|
186
216
|
return new Template(template);
|
|
187
217
|
}
|
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.27.0/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.27.0/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.27.0/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,6 +4,7 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import {internalSymbol} from "../constants.js";
|
|
7
8
|
import {diff} from "../data/diff.js";
|
|
8
9
|
import {Pathfinder} from "../data/pathfinder.js";
|
|
9
10
|
import {Pipe} from "../data/pipe.js";
|
|
@@ -24,6 +25,7 @@ import {ProxyObserver} from "../types/proxyobserver.js";
|
|
|
24
25
|
import {validateArray, validateInstance} from "../types/validate.js";
|
|
25
26
|
import {clone} from "../util/clone.js";
|
|
26
27
|
import {trimSpaces} from "../util/trimspaces.js";
|
|
28
|
+
import {findTargetElementFromEvent} from "./events.js";
|
|
27
29
|
import {findDocumentTemplate} from "./template.js";
|
|
28
30
|
import {getDocument} from "./util.js";
|
|
29
31
|
|
|
@@ -38,7 +40,7 @@ import {getDocument} from "./util.js";
|
|
|
38
40
|
*
|
|
39
41
|
* ```
|
|
40
42
|
* <script type="module">
|
|
41
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
43
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
|
|
42
44
|
* new Monster.DOM.Updater()
|
|
43
45
|
* </script>
|
|
44
46
|
* ```
|
|
@@ -47,14 +49,14 @@ import {getDocument} from "./util.js";
|
|
|
47
49
|
*
|
|
48
50
|
* ```
|
|
49
51
|
* <script type="module">
|
|
50
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
52
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/updater.js';
|
|
51
53
|
* new Updater()
|
|
52
54
|
* </script>
|
|
53
55
|
* ```
|
|
54
56
|
*
|
|
55
57
|
* @example
|
|
56
58
|
*
|
|
57
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
59
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/updater.js';
|
|
58
60
|
*
|
|
59
61
|
* // First we prepare the html document.
|
|
60
62
|
* // This is done here via script, but can also be inserted into the document as pure html.
|
|
@@ -68,7 +70,7 @@ import {getDocument} from "./util.js";
|
|
|
68
70
|
* let obj = {
|
|
69
71
|
* headline: "Hello World",
|
|
70
72
|
* };
|
|
71
|
-
*
|
|
73
|
+
*
|
|
72
74
|
* // Now comes the real magic. we pass the updater the parent HTMLElement
|
|
73
75
|
* // and the desired data structure.
|
|
74
76
|
* const updater = new Updater(body, obj);
|
|
@@ -105,27 +107,27 @@ class Updater extends Base {
|
|
|
105
107
|
/**
|
|
106
108
|
* @type {HTMLElement}
|
|
107
109
|
*/
|
|
108
|
-
this.element = validateInstance(element, HTMLElement);
|
|
109
|
-
|
|
110
110
|
if (subject === undefined) subject = {}
|
|
111
|
-
let a = subject;
|
|
112
111
|
if (!isInstance(subject, ProxyObserver)) {
|
|
113
112
|
subject = new ProxyObserver(subject);
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
this
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
this[internalSymbol] = {
|
|
116
|
+
element: validateInstance(element, HTMLElement),
|
|
117
|
+
last: {},
|
|
118
|
+
callbacks: new Map(),
|
|
119
|
+
eventTypes: ['keyup', 'click', 'change', 'drop', 'touchend', 'input'],
|
|
120
|
+
subject: subject
|
|
121
|
+
}
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
this.subject = subject.attachObserver(new Observer(() => {
|
|
123
|
+
this[internalSymbol].callbacks.set('checkstate', getCheckStateCallback.call(this));
|
|
124
|
+
|
|
125
|
+
this[internalSymbol].subject.attachObserver(new Observer(() => {
|
|
124
126
|
|
|
125
|
-
const s = this.subject.getRealSubject();
|
|
127
|
+
const s = this[internalSymbol].subject.getRealSubject();
|
|
126
128
|
|
|
127
|
-
const diffResult = diff(this.last, s)
|
|
128
|
-
this.last = clone(s);
|
|
129
|
+
const diffResult = diff(this[internalSymbol].last, s)
|
|
130
|
+
this[internalSymbol].last = clone(s);
|
|
129
131
|
|
|
130
132
|
for (const [, change] of Object.entries(diffResult)) {
|
|
131
133
|
removeElement.call(this, change);
|
|
@@ -135,8 +137,6 @@ class Updater extends Base {
|
|
|
135
137
|
}
|
|
136
138
|
}));
|
|
137
139
|
|
|
138
|
-
this.eventTypes = ['keyup', 'click', 'change', 'drop', 'touchend', 'input'];
|
|
139
|
-
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -148,7 +148,7 @@ class Updater extends Base {
|
|
|
148
148
|
* @return {Updater}
|
|
149
149
|
*/
|
|
150
150
|
setEventTypes(types) {
|
|
151
|
-
this.eventTypes = validateArray(types);
|
|
151
|
+
this[internalSymbol].eventTypes = validateArray(types);
|
|
152
152
|
return this;
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -163,12 +163,17 @@ class Updater extends Base {
|
|
|
163
163
|
*
|
|
164
164
|
* @since 1.9.0
|
|
165
165
|
* @return {Updater}
|
|
166
|
+
* @throws {Error} the bind argument must start as a value with a path
|
|
166
167
|
*/
|
|
167
168
|
enableEventProcessing() {
|
|
168
169
|
this.disableEventProcessing();
|
|
169
170
|
|
|
170
|
-
for (const type of this.eventTypes) {
|
|
171
|
-
|
|
171
|
+
for (const type of this[internalSymbol].eventTypes) {
|
|
172
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
|
173
|
+
this[internalSymbol].element.addEventListener(type, getControlEventHandler.call(this), {
|
|
174
|
+
capture: true,
|
|
175
|
+
passive: true
|
|
176
|
+
});
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
return this;
|
|
@@ -183,8 +188,8 @@ class Updater extends Base {
|
|
|
183
188
|
*/
|
|
184
189
|
disableEventProcessing() {
|
|
185
190
|
|
|
186
|
-
for (const type of this.eventTypes) {
|
|
187
|
-
this.element.removeEventListener(type, getControlEventHandler.call(this));
|
|
191
|
+
for (const type of this[internalSymbol].eventTypes) {
|
|
192
|
+
this[internalSymbol].element.removeEventListener(type, getControlEventHandler.call(this));
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
return this;
|
|
@@ -207,8 +212,19 @@ class Updater extends Base {
|
|
|
207
212
|
run() {
|
|
208
213
|
// the key __init__has no further meaning and is only
|
|
209
214
|
// used to create the diff for empty objects.
|
|
210
|
-
this.last = {'__init__': true};
|
|
211
|
-
return this.subject.notifyObservers();
|
|
215
|
+
this[internalSymbol].last = {'__init__': true};
|
|
216
|
+
return this[internalSymbol].subject.notifyObservers();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Gets the values of bound elements and changes them in subject
|
|
221
|
+
*
|
|
222
|
+
* @since 1.27.0
|
|
223
|
+
* @return {Monster.DOM.Updater}
|
|
224
|
+
*/
|
|
225
|
+
retrieve() {
|
|
226
|
+
retrieveFromBindings.call(this);
|
|
227
|
+
return this;
|
|
212
228
|
}
|
|
213
229
|
|
|
214
230
|
/**
|
|
@@ -221,7 +237,7 @@ class Updater extends Base {
|
|
|
221
237
|
* @return {Proxy}
|
|
222
238
|
*/
|
|
223
239
|
getSubject() {
|
|
224
|
-
return this.subject.getSubject();
|
|
240
|
+
return this[internalSymbol].subject.getSubject();
|
|
225
241
|
}
|
|
226
242
|
|
|
227
243
|
/**
|
|
@@ -235,7 +251,7 @@ class Updater extends Base {
|
|
|
235
251
|
* @throws {TypeError} value is not a function
|
|
236
252
|
*/
|
|
237
253
|
setCallback(name, callback) {
|
|
238
|
-
this.callbacks.set(name, callback);
|
|
254
|
+
this[internalSymbol].callbacks.set(name, callback);
|
|
239
255
|
return this;
|
|
240
256
|
}
|
|
241
257
|
|
|
@@ -252,6 +268,7 @@ function getCheckStateCallback() {
|
|
|
252
268
|
|
|
253
269
|
return function (current) {
|
|
254
270
|
|
|
271
|
+
// this is a reference to the current object (therefore no array function here)
|
|
255
272
|
if (this instanceof HTMLInputElement) {
|
|
256
273
|
if (['radio', 'checkbox'].indexOf(this.type) !== -1) {
|
|
257
274
|
return (this.value + "" === current + "") ? 'true' : undefined
|
|
@@ -261,9 +278,8 @@ function getCheckStateCallback() {
|
|
|
261
278
|
if (isArray(current) && current.indexOf(this.value) !== -1) {
|
|
262
279
|
return 'true'
|
|
263
280
|
}
|
|
264
|
-
return undefined;
|
|
265
|
-
|
|
266
281
|
|
|
282
|
+
return undefined;
|
|
267
283
|
}
|
|
268
284
|
}
|
|
269
285
|
}
|
|
@@ -277,6 +293,7 @@ const symbol = Symbol('EventHandler');
|
|
|
277
293
|
* @private
|
|
278
294
|
* @return {function}
|
|
279
295
|
* @this Updater
|
|
296
|
+
* @throws {Error} the bind argument must start as a value with a path
|
|
280
297
|
*/
|
|
281
298
|
function getControlEventHandler() {
|
|
282
299
|
|
|
@@ -286,83 +303,112 @@ function getControlEventHandler() {
|
|
|
286
303
|
return self[symbol];
|
|
287
304
|
}
|
|
288
305
|
|
|
289
|
-
const pathfinder = new Pathfinder(this.subject.getSubject());
|
|
290
|
-
|
|
291
306
|
/**
|
|
292
307
|
* @throws {Error} the bind argument must start as a value with a path.
|
|
293
308
|
* @throws {Error} unsupported object
|
|
294
309
|
* @param {Event} event
|
|
295
310
|
*/
|
|
296
311
|
self[symbol] = (event) => {
|
|
297
|
-
const element = event
|
|
312
|
+
const element = findTargetElementFromEvent(event, ATTRIBUTE_UPDATER_BIND);
|
|
298
313
|
|
|
299
|
-
if (
|
|
314
|
+
if (element === undefined) {
|
|
300
315
|
return;
|
|
301
316
|
}
|
|
302
317
|
|
|
303
|
-
|
|
318
|
+
retrieveAndSetValue.call(self, element);
|
|
304
319
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return self[symbol];
|
|
308
323
|
|
|
309
|
-
path = path.substr(5);
|
|
310
324
|
|
|
311
|
-
|
|
325
|
+
}
|
|
312
326
|
|
|
313
|
-
|
|
314
|
-
|
|
327
|
+
/**
|
|
328
|
+
* @throws {Error} the bind argument must start as a value with a path
|
|
329
|
+
* @param {HTMLElement} element
|
|
330
|
+
* @return void
|
|
331
|
+
*/
|
|
332
|
+
function retrieveAndSetValue(element) {
|
|
315
333
|
|
|
316
|
-
|
|
317
|
-
value = element.checked ? element.value : undefined;
|
|
318
|
-
break;
|
|
319
|
-
default:
|
|
320
|
-
value = element.value;
|
|
321
|
-
break;
|
|
334
|
+
const self = this;
|
|
322
335
|
|
|
336
|
+
const pathfinder = new Pathfinder(self[internalSymbol].subject.getSubject());
|
|
323
337
|
|
|
324
|
-
|
|
325
|
-
} else if (element instanceof HTMLTextAreaElement) {
|
|
326
|
-
value = element.value;
|
|
338
|
+
let path = element.getAttribute(ATTRIBUTE_UPDATER_BIND);
|
|
327
339
|
|
|
328
|
-
|
|
340
|
+
if (path.indexOf('path:') !== 0) {
|
|
341
|
+
throw new Error('the bind argument must start as a value with a path');
|
|
342
|
+
}
|
|
329
343
|
|
|
330
|
-
|
|
331
|
-
case 'select-one':
|
|
332
|
-
value = element.value;
|
|
333
|
-
break;
|
|
334
|
-
case 'select-multiple':
|
|
335
|
-
value = element.value;
|
|
344
|
+
path = path.substr(5);
|
|
336
345
|
|
|
337
|
-
|
|
338
|
-
if (options === undefined) options = element.querySelectorAll(":scope option:checked");
|
|
339
|
-
value = Array.from(options).map(({value}) => value);
|
|
346
|
+
let value;
|
|
340
347
|
|
|
341
|
-
|
|
342
|
-
|
|
348
|
+
if (element instanceof HTMLInputElement) {
|
|
349
|
+
switch (element.type) {
|
|
350
|
+
|
|
351
|
+
case 'checkbox':
|
|
352
|
+
value = element.checked ? element.value : undefined;
|
|
353
|
+
break;
|
|
354
|
+
default:
|
|
355
|
+
value = element.value;
|
|
356
|
+
break;
|
|
343
357
|
|
|
344
358
|
|
|
345
|
-
// values from customelements
|
|
346
|
-
} else if ((element?.constructor?.prototype && !!Object.getOwnPropertyDescriptor(element.constructor.prototype, 'value')?.['get']) || element.hasOwnProperty('value')) {
|
|
347
|
-
value = element?.['value'];
|
|
348
|
-
} else {
|
|
349
|
-
throw new Error("unsupported object");
|
|
350
359
|
}
|
|
360
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
|
361
|
+
value = element.value;
|
|
351
362
|
|
|
352
|
-
|
|
353
|
-
const pf = new Pathfinder(copy);
|
|
354
|
-
pf.setVia(path, value);
|
|
363
|
+
} else if (element instanceof HTMLSelectElement) {
|
|
355
364
|
|
|
356
|
-
|
|
365
|
+
switch (element.type) {
|
|
366
|
+
case 'select-one':
|
|
367
|
+
value = element.value;
|
|
368
|
+
break;
|
|
369
|
+
case 'select-multiple':
|
|
370
|
+
value = element.value;
|
|
357
371
|
|
|
358
|
-
|
|
359
|
-
|
|
372
|
+
let options = element?.selectedOptions;
|
|
373
|
+
if (options === undefined) options = element.querySelectorAll(":scope option:checked");
|
|
374
|
+
value = Array.from(options).map(({value}) => value);
|
|
375
|
+
|
|
376
|
+
break;
|
|
360
377
|
}
|
|
361
378
|
|
|
379
|
+
|
|
380
|
+
// values from customelements
|
|
381
|
+
} else if ((element?.constructor?.prototype && !!Object.getOwnPropertyDescriptor(element.constructor.prototype, 'value')?.['get']) || element.hasOwnProperty('value')) {
|
|
382
|
+
value = element?.['value'];
|
|
383
|
+
} else {
|
|
384
|
+
throw new Error("unsupported object");
|
|
362
385
|
}
|
|
363
386
|
|
|
364
|
-
|
|
387
|
+
const copy = clone(self[internalSymbol].subject.getRealSubject());
|
|
388
|
+
const pf = new Pathfinder(copy);
|
|
389
|
+
pf.setVia(path, value);
|
|
390
|
+
|
|
391
|
+
const diffResult = diff(copy, self[internalSymbol].subject.getRealSubject());
|
|
392
|
+
|
|
393
|
+
if (diffResult.length > 0) {
|
|
394
|
+
pathfinder.setVia(path, value);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @since 1.27.0
|
|
400
|
+
* @return void
|
|
401
|
+
*/
|
|
402
|
+
function retrieveFromBindings() {
|
|
403
|
+
const self = this;
|
|
365
404
|
|
|
405
|
+
if (self[internalSymbol].element.matches('[' + ATTRIBUTE_UPDATER_BIND + ']')) {
|
|
406
|
+
retrieveAndSetValue.call(self, element)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
for (const [, element] of self[internalSymbol].element.querySelectorAll('[' + ATTRIBUTE_UPDATER_BIND + ']').entries()) {
|
|
410
|
+
retrieveAndSetValue.call(self, element)
|
|
411
|
+
}
|
|
366
412
|
|
|
367
413
|
}
|
|
368
414
|
|
|
@@ -373,7 +419,9 @@ function getControlEventHandler() {
|
|
|
373
419
|
* @return {void}
|
|
374
420
|
*/
|
|
375
421
|
function removeElement(change) {
|
|
376
|
-
|
|
422
|
+
const self = this;
|
|
423
|
+
|
|
424
|
+
for (const [, element] of self[internalSymbol].element.querySelectorAll(':scope [' + ATTRIBUTE_UPDATER_REMOVE + ']').entries()) {
|
|
377
425
|
element.parentNode.removeChild(element);
|
|
378
426
|
}
|
|
379
427
|
}
|
|
@@ -391,7 +439,7 @@ function removeElement(change) {
|
|
|
391
439
|
*/
|
|
392
440
|
function insertElement(change) {
|
|
393
441
|
const self = this;
|
|
394
|
-
const subject = self.subject.getRealSubject();
|
|
442
|
+
const subject = self[internalSymbol].subject.getRealSubject();
|
|
395
443
|
const document = getDocument();
|
|
396
444
|
|
|
397
445
|
let mem = new WeakSet;
|
|
@@ -407,7 +455,7 @@ function insertElement(change) {
|
|
|
407
455
|
|
|
408
456
|
while (p.length > 0) {
|
|
409
457
|
const current = p.join('.');
|
|
410
|
-
const list = this.element.querySelectorAll(':scope [' + ATTRIBUTE_UPDATER_INSERT + '*="path:' + current + '"]').entries()
|
|
458
|
+
const list = this[internalSymbol].element.querySelectorAll(':scope [' + ATTRIBUTE_UPDATER_INSERT + '*="path:' + current + '"]').entries()
|
|
411
459
|
|
|
412
460
|
for (const [, containerElement] of list) {
|
|
413
461
|
|
|
@@ -429,7 +477,7 @@ function insertElement(change) {
|
|
|
429
477
|
}
|
|
430
478
|
|
|
431
479
|
let pipe = new Pipe(cmd);
|
|
432
|
-
this.callbacks.forEach((f, n) => {
|
|
480
|
+
this[internalSymbol].callbacks.forEach((f, n) => {
|
|
433
481
|
pipe.setCallback(n, f);
|
|
434
482
|
})
|
|
435
483
|
|
|
@@ -553,12 +601,12 @@ function applyRecursive(node, key, path) {
|
|
|
553
601
|
*/
|
|
554
602
|
function updateContent(change) {
|
|
555
603
|
const self = this;
|
|
556
|
-
const subject = self.subject.getRealSubject();
|
|
604
|
+
const subject = self[internalSymbol].subject.getRealSubject();
|
|
557
605
|
|
|
558
606
|
let p = clone(change?.['path']);
|
|
559
|
-
runUpdateContent.call(this, this.element, p, subject);
|
|
607
|
+
runUpdateContent.call(this, this[internalSymbol].element, p, subject);
|
|
560
608
|
|
|
561
|
-
const slots = this.element.querySelectorAll('slot');
|
|
609
|
+
const slots = this[internalSymbol].element.querySelectorAll('slot');
|
|
562
610
|
if (slots.length > 0) {
|
|
563
611
|
for (const [, slot] of Object.entries(slots)) {
|
|
564
612
|
for (const [, element] of Object.entries(slot.assignedNodes())) {
|
|
@@ -610,7 +658,7 @@ function runUpdateContent(container, parts, subject) {
|
|
|
610
658
|
let cmd = trimSpaces(attributes);
|
|
611
659
|
|
|
612
660
|
let pipe = new Pipe(cmd);
|
|
613
|
-
this.callbacks.forEach((f, n) => {
|
|
661
|
+
this[internalSymbol].callbacks.forEach((f, n) => {
|
|
614
662
|
pipe.setCallback(n, f);
|
|
615
663
|
})
|
|
616
664
|
|
|
@@ -646,9 +694,9 @@ function runUpdateContent(container, parts, subject) {
|
|
|
646
694
|
* @return {void}
|
|
647
695
|
*/
|
|
648
696
|
function updateAttributes(change) {
|
|
649
|
-
const subject = this.subject.getRealSubject();
|
|
697
|
+
const subject = this[internalSymbol].subject.getRealSubject();
|
|
650
698
|
let p = clone(change?.['path']);
|
|
651
|
-
runUpdateAttributes.call(this, this.element, p, subject);
|
|
699
|
+
runUpdateAttributes.call(this, this[internalSymbol].element, p, subject);
|
|
652
700
|
}
|
|
653
701
|
|
|
654
702
|
/**
|
|
@@ -702,7 +750,7 @@ function runUpdateAttributes(container, parts, subject) {
|
|
|
702
750
|
|
|
703
751
|
let pipe = new Pipe(cmd);
|
|
704
752
|
|
|
705
|
-
self.callbacks.forEach((f, n) => {
|
|
753
|
+
self[internalSymbol].callbacks.forEach((f, n) => {
|
|
706
754
|
pipe.setCallback(n, f, element);
|
|
707
755
|
})
|
|
708
756
|
|
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.27.0/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.27.0/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.27.0/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.27.0/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.27.0/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.27.0/dist/modules/dom/util.js';
|
|
153
153
|
* console.log(getDocumentFragmentFromString('<div></div>'))
|
|
154
154
|
* </script>
|
|
155
155
|
* ```
|
|
@@ -20,7 +20,7 @@ import {validateInstance, validateString} from "../../types/validate.js";
|
|
|
20
20
|
*
|
|
21
21
|
* ```
|
|
22
22
|
* <script type="module">
|
|
23
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/monster.js';
|
|
24
24
|
* console.log(new Monster.DOM.Worker.Factory())
|
|
25
25
|
* </script>
|
|
26
26
|
* ```
|
|
@@ -29,7 +29,7 @@ import {validateInstance, validateString} from "../../types/validate.js";
|
|
|
29
29
|
*
|
|
30
30
|
* ```
|
|
31
31
|
* <script type="module">
|
|
32
|
-
* import {Factory} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
32
|
+
* import {Factory} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/dom/worker/factory.js';
|
|
33
33
|
* console.log(new Factory())
|
|
34
34
|
* </script>
|
|
35
35
|
* ```
|