@cocreate/events 1.3.0 → 1.4.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.md +7 -0
- package/demo/index.html +7 -1
- package/demo/set-value.html +18 -0
- package/package.json +1 -1
- package/src/index.js +29 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.3.0...v1.4.0) (2023-02-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* debonce ([43748c4](https://github.com/CoCreate-app/CoCreate-events/commit/43748c45b9e76f58aaf1ad11d16964422c028bbc))
|
|
7
|
+
|
|
1
8
|
# [1.3.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.2.0...v1.3.0) (2023-02-11)
|
|
2
9
|
|
|
3
10
|
|
package/demo/index.html
CHANGED
|
@@ -62,7 +62,13 @@
|
|
|
62
62
|
other content
|
|
63
63
|
</div>
|
|
64
64
|
<!-- defining key example -->
|
|
65
|
-
<div click-target="#testing" click-value="hello, bye" click-key="ty">
|
|
65
|
+
<!-- <div click-target="#testing" click-value="hello, bye" click-key="ty">
|
|
66
|
+
<span id="testing" class="{{ty}}">other content</span>
|
|
67
|
+
</div> -->
|
|
68
|
+
|
|
69
|
+
<!-- defining key example -->
|
|
70
|
+
<div >
|
|
71
|
+
<input input-target="#testing" input-value="" input-key="ty">
|
|
66
72
|
<span id="testing" class="{{ty}}">other content</span>
|
|
67
73
|
</div>
|
|
68
74
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Value | CoCreateJS</title>
|
|
5
|
+
|
|
6
|
+
<!-- CoCreate Favicon -->
|
|
7
|
+
<link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div click-target="#testing" click-value="hello, bye" click-key="ty">
|
|
11
|
+
<span id="testing" class="{{ty}}">other content</span>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<script src="../../../CoCreateJS/dist/CoCreate.js"></script>
|
|
15
|
+
<!-- <script src="https://cdn.cocreate.app/latest/CoCreate.min.js" ></script> -->
|
|
16
|
+
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {queryDocumentSelectorAll} from '@cocreate/utils';
|
|
|
2
2
|
import action from '@cocreate/actions';
|
|
3
3
|
|
|
4
4
|
const CoCreateEvents = {
|
|
5
|
-
// ToDo update to support config, ability to add custom prefix, for loop each
|
|
5
|
+
// ToDo update to support config, ability to add custom prefix, for loop each defualt and custom prefix to support action
|
|
6
6
|
init: function(prefix, events) {
|
|
7
7
|
if (prefix && events)
|
|
8
8
|
this.initElement(document, prefix, events);
|
|
@@ -26,28 +26,34 @@ const CoCreateEvents = {
|
|
|
26
26
|
const self = this;
|
|
27
27
|
|
|
28
28
|
events.forEach((eventName) => {
|
|
29
|
+
let debounce;
|
|
29
30
|
element.addEventListener(eventName, function(event) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
// ToDo: apply debounce
|
|
32
|
+
clearTimeout(debounce);
|
|
33
|
+
debounce = setTimeout(function() {
|
|
34
|
+
const target = event.target.closest(`[${prefix}], [${prefix}-value]`);
|
|
35
|
+
if (target) {
|
|
36
|
+
let attribute = target.getAttribute('actions') || ""
|
|
37
|
+
if (attribute.includes(prefix))
|
|
38
|
+
return;
|
|
39
|
+
// if (target.closest(`[actions*="${prefix}"]`))
|
|
40
|
+
// return;
|
|
41
|
+
self.__updateElements(target, prefix);
|
|
42
|
+
|
|
43
|
+
let parentElement = target.parentElement;
|
|
44
|
+
if (parentElement) {
|
|
45
|
+
do {
|
|
46
|
+
parentElement = parentElement.closest(`[${prefix}], [${prefix}-value]`)
|
|
47
|
+
if (parentElement)
|
|
48
|
+
self.__updateElements(parentElement, prefix);
|
|
49
|
+
}
|
|
50
|
+
while (parentElement)
|
|
51
|
+
|
|
45
52
|
}
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
|
|
48
54
|
}
|
|
55
|
+
}, 500);
|
|
49
56
|
|
|
50
|
-
}
|
|
51
57
|
});
|
|
52
58
|
});
|
|
53
59
|
|
|
@@ -64,6 +70,8 @@ const CoCreateEvents = {
|
|
|
64
70
|
__updateElements: function(element, prefix) {
|
|
65
71
|
const self = this;
|
|
66
72
|
let targetValue = element.getAttribute(`${prefix}-value`) || element.getAttribute(prefix);
|
|
73
|
+
if (!targetValue && element.value)
|
|
74
|
+
targetValue = element.getValue()
|
|
67
75
|
if (!targetValue) return
|
|
68
76
|
|
|
69
77
|
let values = targetValue.split(',');
|
|
@@ -198,7 +206,8 @@ const CoCreateEvents = {
|
|
|
198
206
|
|
|
199
207
|
const eventElements = new Map();
|
|
200
208
|
const elementPrefix = new Map();
|
|
201
|
-
function replaceKey(prefix, element, key, values){
|
|
209
|
+
function replaceKey(prefix, element, key, values) {
|
|
210
|
+
// ToDo: improve updating key to prevent unwanted match by storing each attribute that originally had a key to know which attributes to update
|
|
202
211
|
if (eventElements.has(element)) {
|
|
203
212
|
key = eventElements.get(element).get(prefix);
|
|
204
213
|
}
|