@cocreate/events 1.0.0 → 1.2.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 +14 -0
- package/demo/click.html +2 -2
- package/package.json +2 -1
- package/src/index.js +37 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.2.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.1.0...v1.2.0) (2023-02-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add @cocreate/actions, events bubble up and triggers parent events ([9946b30](https://github.com/CoCreate-app/CoCreate-events/commit/9946b302b5ed19e3f20d850f0734dde6e28852fe))
|
|
7
|
+
|
|
8
|
+
# [1.1.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.0.0...v1.1.0) (2023-02-02)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* supports actions for defined events ([08e9a47](https://github.com/CoCreate-app/CoCreate-events/commit/08e9a4721660a3ba5f508fe3dbf840ec8f1a4a01))
|
|
14
|
+
|
|
1
15
|
# 1.0.0 (2023-02-01)
|
|
2
16
|
|
|
3
17
|
|
package/demo/click.html
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
<!-- <script src="../dist/CoCreate-events.js"></script> -->
|
|
66
|
-
|
|
67
|
-
<script src="../../../CoCreateJS/dist/CoCreate.js" ></script>
|
|
66
|
+
<script src="https://cdn.cocreate.app/latest/CoCreate.min.js" ></script>
|
|
67
|
+
<!-- <script src="../../../CoCreateJS/dist/CoCreate.js" ></script> -->
|
|
68
68
|
</body>
|
|
69
69
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/events",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A simple events component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"events",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"webpack-log": "^3.0.1"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
+
"@cocreate/actions": "^1.5.59",
|
|
63
64
|
"@cocreate/docs": "^1.5.12",
|
|
64
65
|
"@cocreate/utils": "^1.18.0"
|
|
65
66
|
}
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {queryDocumentSelectorAll} from '@cocreate/utils';
|
|
2
|
+
import action from '@cocreate/actions';
|
|
2
3
|
|
|
3
4
|
const CoCreateEvents = {
|
|
4
|
-
|
|
5
|
+
// ToDo update to support config, ability to add custom prefix, for loop each deafualt and custom prefix to support action
|
|
5
6
|
init: function() {
|
|
6
7
|
this.initElement(document, 'events');
|
|
7
8
|
this.initElement(document, 'click');
|
|
@@ -32,19 +33,48 @@ const CoCreateEvents = {
|
|
|
32
33
|
mainContainer.addEventListener(event_name, function(event) {
|
|
33
34
|
const target = event.target.closest(`[${prefix}], [${prefix}-value]`);
|
|
34
35
|
if (target) {
|
|
36
|
+
let attribute = target.getAttribute('actions') || ""
|
|
37
|
+
if (attribute.includes(prefix))
|
|
38
|
+
return;
|
|
39
|
+
// if (target.closest(`[actions*="${prefix}"]`))
|
|
40
|
+
// return;
|
|
35
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
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
}
|
|
37
55
|
});
|
|
38
56
|
});
|
|
57
|
+
|
|
58
|
+
action.init({
|
|
59
|
+
name: prefix,
|
|
60
|
+
endEvent: `${prefix}End`,
|
|
61
|
+
callback: (btn, data) => {
|
|
62
|
+
this.__updateElements(btn, prefix)
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
39
66
|
},
|
|
40
67
|
|
|
41
68
|
__updateElements: function(element, prefix) {
|
|
42
69
|
const self = this;
|
|
43
70
|
let targetValue = element.getAttribute(`${prefix}-value`) || element.getAttribute(prefix);
|
|
71
|
+
if (!targetValue) return
|
|
72
|
+
|
|
44
73
|
let values = targetValue.split(',');
|
|
45
74
|
if (!values || values.length == 0) {
|
|
46
75
|
return;
|
|
47
76
|
}
|
|
77
|
+
|
|
48
78
|
|
|
49
79
|
let targetAttribute = element.getAttribute(`${prefix}-attribute`) || 'class';
|
|
50
80
|
let targetSelector = element.getAttribute(`${prefix}-target`);
|
|
@@ -88,6 +118,11 @@ const CoCreateEvents = {
|
|
|
88
118
|
targetElements.forEach((el) => self.setValue(el, targetAttribute, values));
|
|
89
119
|
} else
|
|
90
120
|
self.setValue(element, targetAttribute, values);
|
|
121
|
+
|
|
122
|
+
document.dispatchEvent(new CustomEvent(`${prefix}End`, {
|
|
123
|
+
detail: {}
|
|
124
|
+
}))
|
|
125
|
+
|
|
91
126
|
},
|
|
92
127
|
|
|
93
128
|
setValue: function(element, attrName, values, deactivate) {
|
|
@@ -155,6 +190,7 @@ const CoCreateEvents = {
|
|
|
155
190
|
}
|
|
156
191
|
};
|
|
157
192
|
|
|
193
|
+
|
|
158
194
|
CoCreateEvents.init();
|
|
159
195
|
|
|
160
196
|
export default CoCreateEvents;
|