@schukai/monster 1.12.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +40 -1
- package/README.md +5 -5
- package/dist/modules/constants.js +2 -0
- package/dist/modules/constraints/abstract.js +2 -2
- package/dist/modules/constraints/abstractoperator.js +2 -2
- package/dist/modules/constraints/andoperator.js +2 -2
- package/dist/modules/constraints/invalid.js +2 -2
- package/dist/modules/constraints/isarray.js +2 -2
- package/dist/modules/constraints/isobject.js +2 -2
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +2 -2
- package/dist/modules/constraints/valid.js +2 -2
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +2 -2
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +2 -2
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +2 -2
- package/dist/modules/dom/attributes.js +2 -2
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -0
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +2 -2
- package/dist/modules/dom/locale.js +2 -0
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +2 -2
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +2 -2
- package/dist/modules/i18n/locale.js +2 -0
- package/dist/modules/i18n/namespace.js +2 -0
- package/dist/modules/i18n/provider.js +2 -0
- package/dist/modules/i18n/providers/fetch.js +2 -0
- package/dist/modules/i18n/providers/namespace.js +2 -0
- package/dist/modules/i18n/translations.js +2 -0
- package/dist/modules/logging/handler/console.js +2 -2
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +2 -2
- package/dist/modules/logging/logentry.js +2 -2
- package/dist/modules/logging/logger.js +2 -2
- 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 +2 -2
- 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 +2 -2
- package/dist/modules/types/basewithoptions.js +2 -0
- package/dist/modules/types/global.js +2 -2
- package/dist/modules/types/id.js +2 -2
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/observer.js +2 -2
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +2 -2
- package/dist/modules/types/randomid.js +2 -2
- package/dist/modules/types/stack.js +2 -2
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +2 -2
- package/dist/modules/types/uniquequeue.js +2 -2
- package/dist/modules/types/validate.js +2 -2
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +2 -2
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +2 -2
- package/dist/modules/util/namespace.js +1 -1
- package/dist/monster.dev.js +8692 -6669
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +3 -3
- package/package.json +1 -1
- package/source/constants.js +22 -0
- package/source/constraints/abstract.js +2 -2
- package/source/constraints/abstractoperator.js +3 -3
- package/source/constraints/andoperator.js +7 -7
- package/source/constraints/invalid.js +6 -6
- package/source/constraints/isarray.js +6 -6
- package/source/constraints/isobject.js +6 -6
- package/source/constraints/namespace.js +2 -0
- package/source/constraints/oroperator.js +8 -8
- package/source/constraints/valid.js +6 -6
- package/source/data/buildmap.js +15 -15
- package/source/data/diff.js +6 -6
- package/source/data/extend.js +55 -13
- package/source/data/namespace.js +2 -0
- package/source/data/pathfinder.js +6 -7
- package/source/data/pipe.js +5 -5
- package/source/data/transformer.js +6 -6
- package/source/dom/assembler.js +5 -5
- package/source/dom/attributes.js +89 -45
- package/source/dom/constants.js +8 -9
- package/source/dom/customcontrol.js +301 -0
- package/source/dom/customelement.js +149 -31
- package/source/dom/events.js +58 -8
- package/source/dom/locale.js +59 -0
- package/source/dom/namespace.js +2 -0
- package/source/dom/template.js +7 -7
- package/source/dom/theme.js +6 -6
- package/source/dom/updater.js +38 -11
- package/source/dom/util.js +10 -10
- package/source/i18n/locale.js +322 -0
- package/source/i18n/namespace.js +15 -0
- package/source/i18n/provider.js +58 -0
- package/source/i18n/providers/fetch.js +121 -0
- package/source/i18n/providers/namespace.js +15 -0
- package/source/i18n/translations.js +209 -0
- package/source/logging/handler/console.js +4 -4
- package/source/logging/handler.js +4 -4
- package/source/logging/logentry.js +4 -4
- package/source/logging/logger.js +4 -4
- package/source/logging/namespace.js +2 -0
- package/source/math/namespace.js +2 -0
- package/source/math/random.js +5 -5
- package/source/monster.js +26 -16
- package/source/namespace.js +10 -8
- package/source/text/formatter.js +4 -5
- package/source/text/namespace.js +1 -1
- package/source/types/base.js +4 -7
- package/source/types/basewithoptions.js +97 -0
- package/source/types/global.js +6 -6
- package/source/types/id.js +6 -6
- package/source/types/is.js +22 -22
- package/source/types/namespace.js +3 -1
- package/source/types/observer.js +5 -5
- package/source/types/observerlist.js +4 -4
- package/source/types/proxyobserver.js +32 -26
- package/source/types/queue.js +13 -7
- package/source/types/randomid.js +5 -5
- package/source/types/stack.js +11 -4
- package/source/types/tokenlist.js +4 -4
- package/source/types/typeof.js +5 -5
- package/source/types/uniquequeue.js +11 -4
- package/source/types/validate.js +22 -22
- package/source/types/version.js +9 -9
- package/source/util/clone.js +4 -4
- package/source/util/comparator.js +6 -6
- package/source/util/freeze.js +4 -4
- package/source/util/namespace.js +2 -0
- package/test/cases/data/extend.js +66 -13
- package/test/cases/dom/attributes.js +56 -1
- package/test/cases/dom/customcontrol.js +264 -0
- package/test/cases/dom/customelement.js +112 -51
- package/test/cases/dom/events.js +32 -14
- package/test/cases/dom/locale.js +44 -0
- package/test/cases/i18n/locale.js +80 -0
- package/test/cases/i18n/provider.js +15 -0
- package/test/cases/i18n/providers/fetch.js +65 -0
- package/test/cases/i18n/translations.js +57 -0
- package/test/cases/monster.js +3 -1
- package/test/cases/{util → text}/formatter.js +2 -0
- package/test/cases/types/basewithoptions.js +25 -0
- package/test/cases/types/proxyobserver.js +9 -0
- package/test/cases/{text → util}/clone.js +0 -0
- package/test/cases/{text → util}/comparator.js +0 -0
- package/test/util/jsdom.js +4 -0
- package/test/web/import.js +10 -3
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +3 -3
- package/test/web/test.html +3 -3
- package/test/web/tests.js +3 -3
package/source/dom/events.js
CHANGED
@@ -3,16 +3,17 @@
|
|
3
3
|
/**
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
|
-
|
7
|
-
import {
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import {validateInstance, validateString} from "../types/validate.js";
|
8
|
+
import {findClosestByAttribute} from "./attributes.js";
|
8
9
|
import {getDocument} from "./util.js";
|
9
10
|
|
10
11
|
/**
|
11
|
-
* You can call the
|
12
|
+
* You can call the function via the monster namespace `new Monster.DOM.fireEvent()`.
|
12
13
|
*
|
13
14
|
* ```
|
14
15
|
* <script type="module">
|
15
|
-
* import {
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/events.js';
|
16
17
|
* console.log(new Monster.DOM.fireEvent())
|
17
18
|
* </script>
|
18
19
|
* ```
|
@@ -21,7 +22,7 @@ import {getDocument} from "./util.js";
|
|
21
22
|
*
|
22
23
|
* ```
|
23
24
|
* <script type="module">
|
24
|
-
* import {
|
25
|
+
* import {fireEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/events.js';
|
25
26
|
* console.log(fireEvent())
|
26
27
|
* </script>
|
27
28
|
* ```
|
@@ -49,7 +50,7 @@ function fireEvent(element, type) {
|
|
49
50
|
bubbles: true,
|
50
51
|
cancelable: true,
|
51
52
|
});
|
52
|
-
|
53
|
+
|
53
54
|
element.dispatchEvent(event);
|
54
55
|
|
55
56
|
} else if (element instanceof HTMLCollection || element instanceof NodeList) {
|
@@ -62,6 +63,55 @@ function fireEvent(element, type) {
|
|
62
63
|
|
63
64
|
}
|
64
65
|
|
66
|
+
/**
|
67
|
+
* This function gets the path `Event.composedPath()` from an event and tries to find the next element
|
68
|
+
* up the tree `element.closest()` with the attribute and value. If no value is specified, only the attribute is searched.
|
69
|
+
*
|
70
|
+
* You can call the function via the monster namespace `new Monster.DOM.findTargetElementFromEvent()`.
|
71
|
+
*
|
72
|
+
* ```
|
73
|
+
* <script type="module">
|
74
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/events.js';
|
75
|
+
* console.log(new Monster.DOM.findTargetElementFromEvent())
|
76
|
+
* </script>
|
77
|
+
* ```
|
78
|
+
*
|
79
|
+
* Alternatively, you can also integrate this function individually.
|
80
|
+
*
|
81
|
+
* ```
|
82
|
+
* <script type="module">
|
83
|
+
* import {findTargetElementFromEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/events.js';
|
84
|
+
* console.log(findTargetElementFromEvent())
|
85
|
+
* </script>
|
86
|
+
* ```
|
87
|
+
*
|
88
|
+
* @since 1.14.0
|
89
|
+
* @param {Event} event
|
90
|
+
* @param {string} attributeName
|
91
|
+
* @param {string|null} attributeValue
|
92
|
+
* @throws {Error} unsupported event
|
93
|
+
* @memberOf Monster/DOM
|
94
|
+
* @throws {TypeError} value is not a string
|
95
|
+
* @throws {TypeError} value is not an instance of HTMLElement
|
96
|
+
*/
|
97
|
+
function findTargetElementFromEvent(event, attributeName, attributeValue) {
|
98
|
+
validateInstance(event, Event);
|
99
|
+
|
100
|
+
if (typeof event.composedPath !== 'function') {
|
101
|
+
throw new Error('unsupported event');
|
102
|
+
}
|
103
|
+
|
104
|
+
const path = event.composedPath();
|
105
|
+
const element = path?.[0];
|
106
|
+
|
107
|
+
if (element instanceof HTMLElement) {
|
108
|
+
return findClosestByAttribute(element, attributeName, attributeValue);
|
109
|
+
}
|
110
|
+
|
111
|
+
return undefined;
|
112
|
+
|
113
|
+
}
|
114
|
+
|
65
115
|
|
66
|
-
|
67
|
-
export {Monster, fireEvent}
|
116
|
+
assignToNamespace('Monster.DOM', findTargetElementFromEvent, fireEvent);
|
117
|
+
export {Monster, findTargetElementFromEvent, fireEvent}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import { parseLocale} from "../i18n/locale.js";
|
8
|
+
import {getDocument} from "./util.js";
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @type {string}
|
12
|
+
*/
|
13
|
+
const DEFAULT_LANGUAGE = 'en';
|
14
|
+
|
15
|
+
/**
|
16
|
+
* With this function you can read the language version set by the document.
|
17
|
+
* For this the attibute `lang` in the html tag is read. If no attribute is set, `en` is used as default.
|
18
|
+
*
|
19
|
+
* You can call the function via the monster namespace `new Monster.DOM.getLocaleOfDocument()`.
|
20
|
+
*
|
21
|
+
* ```
|
22
|
+
* <script type="module">
|
23
|
+
* import {getLocaleOfDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/locale.js';
|
24
|
+
* console.log(new Monster.DOM.getLocaleOfDocument())
|
25
|
+
* </script>
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
* Alternatively, you can also integrate this function individually.
|
29
|
+
*
|
30
|
+
* ```
|
31
|
+
* <script type="module">
|
32
|
+
* import {getLocaleOfDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/locale.js';
|
33
|
+
* console.log(new getLocaleOfDocument())
|
34
|
+
* </script>
|
35
|
+
* ```
|
36
|
+
*
|
37
|
+
* @since 1.13.0
|
38
|
+
* @copyright schukai GmbH
|
39
|
+
* @memberOf Monster/DOM
|
40
|
+
* @throws {TypeError} value is not a string
|
41
|
+
* @throws {Error} unsupported locale
|
42
|
+
*/
|
43
|
+
function getLocaleOfDocument() {
|
44
|
+
|
45
|
+
const document = getDocument();
|
46
|
+
|
47
|
+
let html = document.querySelector('html')
|
48
|
+
if (html instanceof HTMLElement && html.hasAttribute('lang')) {
|
49
|
+
let locale = html.getAttribute('lang');
|
50
|
+
if (locale) {
|
51
|
+
return new parseLocale(locale)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
return parseLocale(DEFAULT_LANGUAGE);
|
56
|
+
}
|
57
|
+
|
58
|
+
assignToNamespace('Monster.DOM', getLocaleOfDocument);
|
59
|
+
export {Monster, getLocaleOfDocument}
|
package/source/dom/namespace.js
CHANGED
package/source/dom/template.js
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
/**
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
|
-
|
7
|
-
import {
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import { Base} from '../types/base.js';
|
8
8
|
import {validateString} from "../types/validate.js";
|
9
9
|
import {getGlobalFunction, getGlobalObject} from '../types/global.js';
|
10
10
|
import {validateInstance} from "../types/validate.js";
|
@@ -15,7 +15,7 @@ import {getDocumentTheme} from "./theme.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.15.0/dist/modules/dom/template.js';
|
19
19
|
* console.log(new Monster.DOM.Template())
|
20
20
|
* </script>
|
21
21
|
* ```
|
@@ -24,7 +24,7 @@ import {getDocumentTheme} from "./theme.js";
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {Template} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {Template} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/template.js';
|
28
28
|
* console.log(new Template())
|
29
29
|
* </script>
|
30
30
|
* ```
|
@@ -74,7 +74,7 @@ class Template extends Base {
|
|
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.15.0/dist/modules/dom/template.js';
|
78
78
|
* console.log(Monster.DOM.findDocumentTemplate())
|
79
79
|
* </script>
|
80
80
|
* ```
|
@@ -83,7 +83,7 @@ class Template extends Base {
|
|
83
83
|
*
|
84
84
|
* ```
|
85
85
|
* <script type="module">
|
86
|
-
* import {findTemplate} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
86
|
+
* import {findTemplate} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/template.js';
|
87
87
|
* console.log(findDocumentTemplate())
|
88
88
|
* </script>
|
89
89
|
* ```
|
@@ -127,7 +127,7 @@ function findDocumentTemplate(id, root) {
|
|
127
127
|
}
|
128
128
|
|
129
129
|
|
130
|
-
|
130
|
+
assignToNamespace('Monster.DOM', Template, findDocumentTemplate);
|
131
131
|
export {Monster, Template, findDocumentTemplate}
|
132
132
|
|
133
133
|
|
package/source/dom/theme.js
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
/**
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
|
-
|
7
|
-
import {
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import { Base} from '../types/base.js';
|
8
8
|
import {validateString} from "../types/validate.js";
|
9
9
|
import {getGlobalObject} from '../types/global.js';
|
10
10
|
import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.js";
|
@@ -16,7 +16,7 @@ import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.js";
|
|
16
16
|
*
|
17
17
|
* ```
|
18
18
|
* <script type="module">
|
19
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
19
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/theme.js';
|
20
20
|
* console.log(new Monster.DOM.Theme())
|
21
21
|
* </script>
|
22
22
|
* ```
|
@@ -25,14 +25,14 @@ import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.js";
|
|
25
25
|
*
|
26
26
|
* ```
|
27
27
|
* <script type="module">
|
28
|
-
* import {Theme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
28
|
+
* import {Theme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/theme.js';
|
29
29
|
* console.log(new Theme())
|
30
30
|
* </script>
|
31
31
|
* ```
|
32
32
|
*
|
33
33
|
* @example
|
34
34
|
*
|
35
|
-
* import {getDocumentTheme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
35
|
+
* import {getDocumentTheme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/theme.js';
|
36
36
|
*
|
37
37
|
* const theme = getDocumentTheme();
|
38
38
|
* console.log(theme.getName());
|
@@ -96,5 +96,5 @@ function getDocumentTheme() {
|
|
96
96
|
|
97
97
|
}
|
98
98
|
|
99
|
-
|
99
|
+
assignToNamespace('Monster.DOM', Theme, getDocumentTheme);
|
100
100
|
export {Monster, Theme, getDocumentTheme}
|
package/source/dom/updater.js
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
3
7
|
import {Pathfinder} from "../data/pathfinder.js";
|
4
8
|
import {Pipe} from "../data/pipe.js";
|
5
|
-
import {Base
|
6
|
-
import {isInstance, isArray} from "../types/is.js";
|
9
|
+
import {Base} from "../types/base.js";
|
10
|
+
import {isInstance, isArray, isIterable} from "../types/is.js";
|
7
11
|
import {Observer} from "../types/observer.js";
|
8
12
|
import {ProxyObserver} from "../types/proxyobserver.js";
|
9
13
|
import {validateInstance, validateArray} from "../types/validate.js";
|
@@ -20,10 +24,6 @@ import {
|
|
20
24
|
import {findDocumentTemplate} from "./template.js";
|
21
25
|
import {getDocument} from "./util.js";
|
22
26
|
|
23
|
-
/**
|
24
|
-
* @author schukai GmbH
|
25
|
-
*/
|
26
|
-
|
27
27
|
|
28
28
|
/**
|
29
29
|
* The updater class connects an object with the dom. in this way, structures and contents in the DOM can be programmatically adapted via attributes.
|
@@ -34,7 +34,7 @@ import {getDocument} from "./util.js";
|
|
34
34
|
*
|
35
35
|
* ```
|
36
36
|
* <script type="module">
|
37
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
37
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/updater.js';
|
38
38
|
* console.log(new Monster.DOM.Updater())
|
39
39
|
* </script>
|
40
40
|
* ```
|
@@ -43,14 +43,14 @@ import {getDocument} from "./util.js";
|
|
43
43
|
*
|
44
44
|
* ```
|
45
45
|
* <script type="module">
|
46
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
46
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/updater.js';
|
47
47
|
* console.log(new Updater())
|
48
48
|
* </script>
|
49
49
|
* ```
|
50
50
|
*
|
51
51
|
* @example
|
52
52
|
*
|
53
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
53
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/updater.js';
|
54
54
|
*
|
55
55
|
* // First we prepare the html document.
|
56
56
|
* // This is done here via script, but can also be inserted into the document as pure html.
|
@@ -102,6 +102,7 @@ class Updater extends Base {
|
|
102
102
|
this.element = validateInstance(element, HTMLElement);
|
103
103
|
|
104
104
|
if (subject === undefined) subject = {}
|
105
|
+
let a = subject;
|
105
106
|
if (!isInstance(subject, ProxyObserver)) {
|
106
107
|
subject = new ProxyObserver(subject);
|
107
108
|
}
|
@@ -114,7 +115,9 @@ class Updater extends Base {
|
|
114
115
|
* @type {object}
|
115
116
|
*/
|
116
117
|
this.subject = subject.attachObserver(new Observer(() => {
|
118
|
+
|
117
119
|
const s = this.subject.getRealSubject();
|
120
|
+
|
118
121
|
const diff = Diff(this.last, s)
|
119
122
|
this.last = clone(s);
|
120
123
|
|
@@ -174,6 +177,26 @@ class Updater extends Base {
|
|
174
177
|
|
175
178
|
}
|
176
179
|
|
180
|
+
// /**
|
181
|
+
// *
|
182
|
+
// * @param {string} path
|
183
|
+
// * @param {*} value
|
184
|
+
// * @param {boolean} notifyAnyway
|
185
|
+
// * @return {Updater}
|
186
|
+
// * @since 1.15.0
|
187
|
+
// */
|
188
|
+
// setVia(path, value, notifyAnyway) {
|
189
|
+
// if(isBoolean(notifyAnyway)&¬ifyAnyway===true) {
|
190
|
+
// // the key __init__has no further meaning and is only
|
191
|
+
// // used to create the diff for empty objects.
|
192
|
+
// new Pathfinder(this.last).setVia(path, {'__init__': true});
|
193
|
+
//
|
194
|
+
// }
|
195
|
+
//
|
196
|
+
// new Pathfinder(this.subject.getSubject()).setVia(path, value);
|
197
|
+
// return this;
|
198
|
+
// }
|
199
|
+
|
177
200
|
/**
|
178
201
|
* Let the magic begin
|
179
202
|
*
|
@@ -284,6 +307,7 @@ function getControlEventHandler() {
|
|
284
307
|
path = path.substr(5);
|
285
308
|
|
286
309
|
let value;
|
310
|
+
|
287
311
|
if (element instanceof HTMLInputElement) {
|
288
312
|
switch (element.type) {
|
289
313
|
|
@@ -316,6 +340,9 @@ function getControlEventHandler() {
|
|
316
340
|
}
|
317
341
|
|
318
342
|
|
343
|
+
// values from customelements
|
344
|
+
} else if ((element?.constructor?.prototype && !!Object.getOwnPropertyDescriptor(element.constructor.prototype, 'value')?.['get']) || element.hasOwnProperty('value')) {
|
345
|
+
value = element?.['value'];
|
319
346
|
} else {
|
320
347
|
throw new Error("unsupported object");
|
321
348
|
}
|
@@ -411,7 +438,7 @@ function insertElement(change) {
|
|
411
438
|
insertPoint = containerElement.lastChild;
|
412
439
|
}
|
413
440
|
|
414
|
-
if (!
|
441
|
+
if (!isIterable(value)) {
|
415
442
|
throw new Error('the value is not iterable');
|
416
443
|
}
|
417
444
|
|
@@ -723,5 +750,5 @@ function handleInputControlAttributeUpdate(element, name, value) {
|
|
723
750
|
|
724
751
|
}
|
725
752
|
|
726
|
-
|
753
|
+
assignToNamespace('Monster.DOM', Updater);
|
727
754
|
export {Monster, Updater}
|
package/source/dom/util.js
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
/**
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
|
-
|
7
|
-
import {
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import { getGlobal} from "../types/global.js";
|
8
8
|
import {validateString} from "../types/validate.js";
|
9
9
|
|
10
10
|
|
@@ -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.15.0/dist/modules/dom/util.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.15.0/dist/modules/dom/util.js';
|
26
26
|
* console.log(getDocument())
|
27
27
|
* </script>
|
28
28
|
* ```
|
@@ -62,7 +62,7 @@ import {validateString} from "../types/validate.js";
|
|
62
62
|
*/
|
63
63
|
function getDocument() {
|
64
64
|
let document = getGlobal()?.['document'];
|
65
|
-
if (typeof document !== 'object') {
|
65
|
+
if (typeof document !== 'object') {
|
66
66
|
throw new Error("not supported environment")
|
67
67
|
}
|
68
68
|
|
@@ -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.15.0/dist/modules/dom/util.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.15.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.15.0/dist/modules/dom/util.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.15.0/dist/modules/dom/util.js';
|
153
153
|
* console.log(getDocumentFragmentFromString('<div></div>'))
|
154
154
|
* </script>
|
155
155
|
* ```
|
@@ -199,5 +199,5 @@ function getDocumentFragmentFromString(html) {
|
|
199
199
|
}
|
200
200
|
|
201
201
|
|
202
|
-
|
202
|
+
assignToNamespace('Monster.DOM', getWindow, getDocument, getDocumentFragmentFromString);
|
203
203
|
export {Monster, getWindow, getDocument, getDocumentFragmentFromString}
|