@schukai/monster 1.12.0 → 1.15.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 +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/data/pipe.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {Monster} from '../namespace.js';
|
|
7
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
|
8
8
|
import {Transformer} from './transformer.js';
|
|
9
9
|
import {Base} from '../types/base.js';
|
|
10
10
|
import {validateFunction, validateString} from '../types/validate.js';
|
|
@@ -19,7 +19,7 @@ const DELIMITER = '|';
|
|
|
19
19
|
*
|
|
20
20
|
* ```
|
|
21
21
|
* <script type="module">
|
|
22
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
22
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/pipe.js';
|
|
23
23
|
* console.log(new Monster.Data.Pipe())
|
|
24
24
|
* </script>
|
|
25
25
|
* ```
|
|
@@ -28,7 +28,7 @@ const DELIMITER = '|';
|
|
|
28
28
|
*
|
|
29
29
|
* ```
|
|
30
30
|
* <script type="module">
|
|
31
|
-
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
31
|
+
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/pipe.js';
|
|
32
32
|
* console.log(new Pipe())
|
|
33
33
|
* </script>
|
|
34
34
|
* ```
|
|
@@ -39,7 +39,7 @@ const DELIMITER = '|';
|
|
|
39
39
|
* the word is then converted to uppercase letters and a prefix Hello is added. the two backslash safe the space char.
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
|
-
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
42
|
+
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/pipe.js';
|
|
43
43
|
*
|
|
44
44
|
* let obj = {
|
|
45
45
|
* a: {
|
|
@@ -106,5 +106,5 @@ class Pipe extends Base {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
assignToNamespace('Monster.Data', Pipe);
|
|
110
110
|
export {Monster, Pipe}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
import {Monster} from '../namespace.js';
|
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
|
8
7
|
import {Base} from '../types/base.js';
|
|
9
8
|
import {getGlobal} from "../types/global.js";
|
|
10
9
|
import {
|
|
@@ -26,7 +25,7 @@ import {Pathfinder} from "./pathfinder.js";
|
|
|
26
25
|
*
|
|
27
26
|
* ```
|
|
28
27
|
* <script type="module">
|
|
29
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
28
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/transformer.js';
|
|
30
29
|
* console.log(new Monster.Data.Transformer())
|
|
31
30
|
* </script>
|
|
32
31
|
* ```
|
|
@@ -35,7 +34,7 @@ import {Pathfinder} from "./pathfinder.js";
|
|
|
35
34
|
*
|
|
36
35
|
* ```
|
|
37
36
|
* <script type="module">
|
|
38
|
-
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
37
|
+
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/transformer.js';
|
|
39
38
|
* console.log(new Transformer())
|
|
40
39
|
* </script>
|
|
41
40
|
* ```
|
|
@@ -114,7 +113,7 @@ import {Pathfinder} from "./pathfinder.js";
|
|
|
114
113
|
*
|
|
115
114
|
* @example
|
|
116
115
|
*
|
|
117
|
-
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
116
|
+
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/transformer.js';
|
|
118
117
|
*
|
|
119
118
|
* const transformer = new Transformer("tolower")
|
|
120
119
|
*
|
|
@@ -181,7 +180,7 @@ class Transformer extends Base {
|
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
|
|
184
|
-
|
|
183
|
+
assignToNamespace('Monster.Data', Transformer);
|
|
185
184
|
export {Monster, Transformer}
|
|
186
185
|
|
|
187
186
|
/**
|
|
@@ -465,3 +464,4 @@ function transform(value) {
|
|
|
465
464
|
|
|
466
465
|
return value;
|
|
467
466
|
}
|
|
467
|
+
|
package/source/dom/assembler.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 {validateInstance, validateString} from "../types/validate.js";
|
|
9
9
|
import {getGlobalFunction} from "../types/global.js";
|
|
10
10
|
import {ProxyObserver} from "../types/proxyobserver.js";
|
|
@@ -23,7 +23,7 @@ const ATTRIBUTEPREFIX = "data-monster-";
|
|
|
23
23
|
*
|
|
24
24
|
* ```
|
|
25
25
|
* <script type="module">
|
|
26
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
26
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/assembler.js';
|
|
27
27
|
* console.log(new Monster.DOM.Assembler())
|
|
28
28
|
* </script>
|
|
29
29
|
* ```
|
|
@@ -32,7 +32,7 @@ const ATTRIBUTEPREFIX = "data-monster-";
|
|
|
32
32
|
*
|
|
33
33
|
* ```
|
|
34
34
|
* <script type="module">
|
|
35
|
-
* import {Assembler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
35
|
+
* import {Assembler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/assembler.js';
|
|
36
36
|
* console.log(new Assembler())
|
|
37
37
|
* </script>
|
|
38
38
|
* ```
|
|
@@ -95,5 +95,5 @@ class Assembler extends Base {
|
|
|
95
95
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
assignToNamespace('Monster.DOM', Assembler);
|
|
99
99
|
export {Monster, ATTRIBUTEPREFIX, Assembler}
|
package/source/dom/attributes.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {Monster} from '../namespace.js';
|
|
7
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
|
8
8
|
import {getGlobalFunction} from "../types/global.js";
|
|
9
9
|
import {isInstance} from "../types/is.js";
|
|
10
10
|
import {TokenList} from "../types/tokenlist.js";
|
|
@@ -21,7 +21,7 @@ import {ATTRIBUTE_OBJECTLINK} from "./constants.js";
|
|
|
21
21
|
*
|
|
22
22
|
* ```
|
|
23
23
|
* <script type="module">
|
|
24
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
24
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/updater.js';
|
|
25
25
|
* console.log(Monster.DOM.findClosestObjectLink())
|
|
26
26
|
* </script>
|
|
27
27
|
* ```
|
|
@@ -30,30 +30,20 @@ import {ATTRIBUTE_OBJECTLINK} from "./constants.js";
|
|
|
30
30
|
*
|
|
31
31
|
* ```
|
|
32
32
|
* <script type="module">
|
|
33
|
-
* import {getUpdaterFromNode} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
33
|
+
* import {getUpdaterFromNode} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/updater.js';
|
|
34
34
|
* console.log(findClosestObjectLink())
|
|
35
35
|
* </script>
|
|
36
36
|
* ```
|
|
37
37
|
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @return {
|
|
38
|
+
* @param {HTMLElement} element
|
|
39
|
+
* @return {HTMLElement|undefined}
|
|
40
40
|
* @since 1.10.0
|
|
41
41
|
* @copyright schukai GmbH
|
|
42
42
|
* @memberOf Monster/DOM
|
|
43
|
-
* @throws {TypeError} value is not an instance of
|
|
43
|
+
* @throws {TypeError} value is not an instance of HTMLElement
|
|
44
44
|
*/
|
|
45
|
-
function findClosestObjectLink(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
let attribute = node.hasAttribute(ATTRIBUTE_OBJECTLINK);
|
|
49
|
-
if (attribute === false) {
|
|
50
|
-
let parentNode = node?.['parentNode'];
|
|
51
|
-
if (isInstance(parentNode, getGlobalFunction('Node'))) {
|
|
52
|
-
return findClosestObjectLink(parentNode)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return node;
|
|
45
|
+
function findClosestObjectLink(element) {
|
|
46
|
+
return findClosestByAttribute(element, ATTRIBUTE_OBJECTLINK);
|
|
57
47
|
}
|
|
58
48
|
|
|
59
49
|
/**
|
|
@@ -61,7 +51,7 @@ function findClosestObjectLink(node) {
|
|
|
61
51
|
*
|
|
62
52
|
* ```
|
|
63
53
|
* <script type="module">
|
|
64
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
54
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
65
55
|
* Monster.DOM.addToObjectLink();
|
|
66
56
|
* </script>
|
|
67
57
|
* ```
|
|
@@ -70,7 +60,7 @@ function findClosestObjectLink(node) {
|
|
|
70
60
|
*
|
|
71
61
|
* ```
|
|
72
62
|
* <script type="module">
|
|
73
|
-
* import {addToObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
63
|
+
* import {addToObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
74
64
|
* addToObjectLink();
|
|
75
65
|
* </script>
|
|
76
66
|
* ```
|
|
@@ -103,7 +93,7 @@ function addToObjectLink(element, symbol, object) {
|
|
|
103
93
|
*
|
|
104
94
|
* ```
|
|
105
95
|
* <script type="module">
|
|
106
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
96
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
107
97
|
* Monster.DOM.removeObjectLink();
|
|
108
98
|
* </script>
|
|
109
99
|
* ```
|
|
@@ -112,7 +102,7 @@ function addToObjectLink(element, symbol, object) {
|
|
|
112
102
|
*
|
|
113
103
|
* ```
|
|
114
104
|
* <script type="module">
|
|
115
|
-
* import {removeObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
105
|
+
* import {removeObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
116
106
|
* removeObjectLink();
|
|
117
107
|
* </script>
|
|
118
108
|
* ```
|
|
@@ -145,7 +135,7 @@ function removeObjectLink(element, symbol) {
|
|
|
145
135
|
*
|
|
146
136
|
* ```
|
|
147
137
|
* <script type="module">
|
|
148
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
138
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
149
139
|
* Monster.DOM.hasObjectLink();
|
|
150
140
|
* </script>
|
|
151
141
|
* ```
|
|
@@ -154,7 +144,7 @@ function removeObjectLink(element, symbol) {
|
|
|
154
144
|
*
|
|
155
145
|
* ```
|
|
156
146
|
* <script type="module">
|
|
157
|
-
* import {hasObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
147
|
+
* import {hasObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
158
148
|
* hasObjectLink();
|
|
159
149
|
* </script>
|
|
160
150
|
* ```
|
|
@@ -180,18 +170,18 @@ function hasObjectLink(element, symbol) {
|
|
|
180
170
|
}
|
|
181
171
|
|
|
182
172
|
/**
|
|
183
|
-
* The ObjectLink can be used to attach objects to HTMLElements. The elements are kept in a set under a unique
|
|
184
|
-
* symbol and can be read via an iterator {@see getLinkedObjects}.
|
|
185
|
-
*
|
|
173
|
+
* The ObjectLink can be used to attach objects to HTMLElements. The elements are kept in a set under a unique
|
|
174
|
+
* symbol and can be read via an iterator {@see getLinkedObjects}.
|
|
175
|
+
*
|
|
186
176
|
* In addition, elements with an objectLink receive the attribute `data-monster-objectlink`.
|
|
187
|
-
*
|
|
177
|
+
*
|
|
188
178
|
* With the method {@see addToObjectLink} the objects can be added.
|
|
189
|
-
*
|
|
179
|
+
*
|
|
190
180
|
* You can call the method via the monster namespace `new Monster.DOM.getLinkedObjects()`.
|
|
191
181
|
*
|
|
192
182
|
* ```
|
|
193
183
|
* <script type="module">
|
|
194
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
184
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
195
185
|
* Monster.DOM.getLinkedObjects();
|
|
196
186
|
* </script>
|
|
197
187
|
* ```
|
|
@@ -200,7 +190,7 @@ function hasObjectLink(element, symbol) {
|
|
|
200
190
|
*
|
|
201
191
|
* ```
|
|
202
192
|
* <script type="module">
|
|
203
|
-
* import {getLinkedObjects} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
193
|
+
* import {getLinkedObjects} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
204
194
|
* getLinkedObjects();
|
|
205
195
|
* </script>
|
|
206
196
|
* ```
|
|
@@ -236,7 +226,7 @@ function getLinkedObjects(element, symbol) {
|
|
|
236
226
|
*
|
|
237
227
|
* ```
|
|
238
228
|
* <script type="module">
|
|
239
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
229
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
240
230
|
* Monster.DOM.toggleAttributeToken();
|
|
241
231
|
* </script>
|
|
242
232
|
* ```
|
|
@@ -245,7 +235,7 @@ function getLinkedObjects(element, symbol) {
|
|
|
245
235
|
*
|
|
246
236
|
* ```
|
|
247
237
|
* <script type="module">
|
|
248
|
-
* import {toggleAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
238
|
+
* import {toggleAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
249
239
|
* toggleAttributeToken();
|
|
250
240
|
* </script>
|
|
251
241
|
* ```
|
|
@@ -280,7 +270,7 @@ function toggleAttributeToken(element, key, token) {
|
|
|
280
270
|
*
|
|
281
271
|
* ```
|
|
282
272
|
* <script type="module">
|
|
283
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
273
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
284
274
|
* Monster.DOM.addAttributeToken();
|
|
285
275
|
* </script>
|
|
286
276
|
* ```
|
|
@@ -289,7 +279,7 @@ function toggleAttributeToken(element, key, token) {
|
|
|
289
279
|
*
|
|
290
280
|
* ```
|
|
291
281
|
* <script type="module">
|
|
292
|
-
* import {addAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
282
|
+
* import {addAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
293
283
|
* addAttributeToken();
|
|
294
284
|
* </script>
|
|
295
285
|
* ```
|
|
@@ -326,7 +316,7 @@ function addAttributeToken(element, key, token) {
|
|
|
326
316
|
*
|
|
327
317
|
* ```
|
|
328
318
|
* <script type="module">
|
|
329
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
319
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
330
320
|
* Monster.DOM.removeAttributeToken();
|
|
331
321
|
* </script>
|
|
332
322
|
* ```
|
|
@@ -335,7 +325,7 @@ function addAttributeToken(element, key, token) {
|
|
|
335
325
|
*
|
|
336
326
|
* ```
|
|
337
327
|
* <script type="module">
|
|
338
|
-
* import {removeAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
328
|
+
* import {removeAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
339
329
|
* removeAttributeToken();
|
|
340
330
|
* </script>
|
|
341
331
|
* ```
|
|
@@ -371,7 +361,7 @@ function removeAttributeToken(element, key, token) {
|
|
|
371
361
|
*
|
|
372
362
|
* ```
|
|
373
363
|
* <script type="module">
|
|
374
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
364
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
375
365
|
* Monster.DOM.containsAttributeToken();
|
|
376
366
|
* </script>
|
|
377
367
|
* ```
|
|
@@ -380,7 +370,7 @@ function removeAttributeToken(element, key, token) {
|
|
|
380
370
|
*
|
|
381
371
|
* ```
|
|
382
372
|
* <script type="module">
|
|
383
|
-
* import {containsAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
373
|
+
* import {containsAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
384
374
|
* containsAttributeToken();
|
|
385
375
|
* </script>
|
|
386
376
|
* ```
|
|
@@ -413,7 +403,7 @@ function containsAttributeToken(element, key, token) {
|
|
|
413
403
|
*
|
|
414
404
|
* ```
|
|
415
405
|
* <script type="module">
|
|
416
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
406
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
417
407
|
* Monster.DOM.replaceAttributeToken();
|
|
418
408
|
* </script>
|
|
419
409
|
* ```
|
|
@@ -422,7 +412,7 @@ function containsAttributeToken(element, key, token) {
|
|
|
422
412
|
*
|
|
423
413
|
* ```
|
|
424
414
|
* <script type="module">
|
|
425
|
-
* import {replaceAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
415
|
+
* import {replaceAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
426
416
|
* replaceAttributeToken();
|
|
427
417
|
* </script>
|
|
428
418
|
* ```
|
|
@@ -458,7 +448,7 @@ function replaceAttributeToken(element, key, from, to) {
|
|
|
458
448
|
*
|
|
459
449
|
* ```
|
|
460
450
|
* <script type="module">
|
|
461
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
451
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
462
452
|
* Monster.DOM.clearAttributeTokens();
|
|
463
453
|
* </script>
|
|
464
454
|
* ```
|
|
@@ -467,13 +457,13 @@ function replaceAttributeToken(element, key, from, to) {
|
|
|
467
457
|
*
|
|
468
458
|
* ```
|
|
469
459
|
* <script type="module">
|
|
470
|
-
* import {clearAttributeTokens} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
460
|
+
* import {clearAttributeTokens} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
471
461
|
* clearAttributeTokens();
|
|
472
462
|
* </script>
|
|
473
463
|
* ```
|
|
474
464
|
*
|
|
475
465
|
* @since 1.9.0
|
|
476
|
-
* @copyright schukai GmbH
|
|
466
|
+
* @copyright schukai GmbH
|
|
477
467
|
* @memberOf Monster/DOM
|
|
478
468
|
* @param {HTMLElement} element
|
|
479
469
|
* @param {string} key
|
|
@@ -492,13 +482,67 @@ function clearAttributeTokens(element, key) {
|
|
|
492
482
|
return element
|
|
493
483
|
}
|
|
494
484
|
|
|
485
|
+
/**
|
|
486
|
+
* You can call the method via the monster namespace `new Monster.DOM.findClosestByAttribute()`.
|
|
487
|
+
*
|
|
488
|
+
* ```
|
|
489
|
+
* <script type="module">
|
|
490
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
491
|
+
* Monster.DOM.findClosestByAttribute();
|
|
492
|
+
* </script>
|
|
493
|
+
* ```
|
|
494
|
+
*
|
|
495
|
+
* Alternatively, you can also integrate this function individually.
|
|
496
|
+
*
|
|
497
|
+
* ```
|
|
498
|
+
* <script type="module">
|
|
499
|
+
* import {clearAttributeTokens} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/dom/attributes.js';
|
|
500
|
+
* findClosestByAttribute();
|
|
501
|
+
* </script>
|
|
502
|
+
* ```
|
|
503
|
+
*
|
|
504
|
+
* @since 1.14.0
|
|
505
|
+
* @copyright schukai GmbH
|
|
506
|
+
* @memberOf Monster/DOM
|
|
507
|
+
* @param {HTMLElement} element
|
|
508
|
+
* @param {string} key
|
|
509
|
+
* @return {HTMLElement|undefined}
|
|
510
|
+
* @throws {TypeError} value is not a string
|
|
511
|
+
* @throws {TypeError} value is not an instance of HTMLElement
|
|
512
|
+
*/
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
*
|
|
516
|
+
* @since 1.14.0
|
|
517
|
+
* @param {HTMLElement} element
|
|
518
|
+
* @param {string} key
|
|
519
|
+
* @param {string|undefined} value
|
|
520
|
+
* @return {HTMLElement|undefined}
|
|
521
|
+
*/
|
|
522
|
+
function findClosestByAttribute(element, key, value) {
|
|
523
|
+
validateInstance(element, getGlobalFunction('HTMLElement'));
|
|
524
|
+
|
|
525
|
+
if (element.hasAttribute(key) && element.getAttribute(key) === value) {
|
|
526
|
+
return element;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
let selector = validateString(key);
|
|
530
|
+
if (value !== undefined) selector += "=" + validateString(value);
|
|
531
|
+
let result = element.closest('[' + selector + ']');
|
|
532
|
+
if (result instanceof HTMLElement) {
|
|
533
|
+
return result;
|
|
534
|
+
}
|
|
535
|
+
return undefined;
|
|
536
|
+
}
|
|
495
537
|
|
|
496
|
-
|
|
538
|
+
// exports
|
|
539
|
+
assignToNamespace('Monster.DOM', getLinkedObjects, addToObjectLink, removeObjectLink, findClosestByAttribute, hasObjectLink, clearAttributeTokens, replaceAttributeToken, containsAttributeToken, removeAttributeToken, addAttributeToken, toggleAttributeToken);
|
|
497
540
|
export {
|
|
498
541
|
Monster,
|
|
499
542
|
addToObjectLink,
|
|
500
543
|
removeObjectLink,
|
|
501
544
|
hasObjectLink,
|
|
545
|
+
findClosestByAttribute,
|
|
502
546
|
clearAttributeTokens,
|
|
503
547
|
replaceAttributeToken,
|
|
504
548
|
containsAttributeToken,
|
package/source/dom/constants.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import {Monster} from
|
|
4
|
-
|
|
3
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
|
5
4
|
/**
|
|
6
5
|
* @author schukai GmbH
|
|
7
6
|
*/
|
|
@@ -86,23 +85,23 @@ const ATTRIBUTE_UPDATER_BIND = ATTRIBUTE_PREFIX + 'bind';
|
|
|
86
85
|
/**
|
|
87
86
|
* @memberOf Monster/DOM
|
|
88
87
|
* @type {string}
|
|
89
|
-
* @since 1.
|
|
88
|
+
* @since 1.14.0
|
|
90
89
|
*/
|
|
91
|
-
const
|
|
90
|
+
const ATTRIBUTE_ROLE = ATTRIBUTE_PREFIX + 'role';
|
|
92
91
|
|
|
93
92
|
/**
|
|
94
93
|
* @memberOf Monster/DOM
|
|
95
94
|
* @type {string}
|
|
96
|
-
* @since 1.
|
|
95
|
+
* @since 1.9.0
|
|
97
96
|
*/
|
|
98
|
-
const
|
|
97
|
+
const ATTRIBUTE_OBJECTLINK = ATTRIBUTE_PREFIX + 'objectlink';
|
|
99
98
|
|
|
100
99
|
/**
|
|
101
100
|
* @memberOf Monster/DOM
|
|
102
101
|
* @type {string}
|
|
103
102
|
* @since 1.10.0
|
|
104
103
|
*/
|
|
105
|
-
const
|
|
104
|
+
const OBJECTLINK_KEY_UPDATER = 'monsterUpdater';
|
|
106
105
|
|
|
107
106
|
|
|
108
107
|
export {
|
|
@@ -111,6 +110,7 @@ export {
|
|
|
111
110
|
ATTRIBUTE_OPTIONS,
|
|
112
111
|
DEFAULT_THEME,
|
|
113
112
|
ATTRIBUTE_THEME_PREFIX,
|
|
113
|
+
ATTRIBUTE_ROLE,
|
|
114
114
|
ATTRIBUTE_THEME_NAME,
|
|
115
115
|
ATTRIBUTE_UPDATER_ATTRIBUTES,
|
|
116
116
|
ATTRIBUTE_UPDATER_REPLACE,
|
|
@@ -119,6 +119,5 @@ export {
|
|
|
119
119
|
ATTRIBUTE_UPDATER_REMOVE,
|
|
120
120
|
ATTRIBUTE_UPDATER_BIND,
|
|
121
121
|
ATTRIBUTE_OBJECTLINK,
|
|
122
|
-
OBJECTLINK_KEY_UPDATER
|
|
123
|
-
OBJECTLINK_KEY_OPTIONS
|
|
122
|
+
OBJECTLINK_KEY_UPDATER
|
|
124
123
|
}
|