@cocreate/events 1.0.0 → 1.1.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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.1.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.0.0...v1.1.0) (2023-02-02)
2
+
3
+
4
+ ### Features
5
+
6
+ * supports actions for defined events ([08e9a47](https://github.com/CoCreate-app/CoCreate-events/commit/08e9a4721660a3ba5f508fe3dbf840ec8f1a4a01))
7
+
1
8
  # 1.0.0 (2023-02-01)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.0.0",
3
+ "version": "1.1.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",
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,10 +33,20 @@ 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
+ if (target.closest(`[actions=*"${prefix}"]`)) return;
35
37
  self.__updateElements(target, prefix);
36
38
  }
37
39
  });
38
40
  });
41
+
42
+ action.init({
43
+ name: prefix,
44
+ endEvent: `${prefix}End`,
45
+ callback: (btn, data) => {
46
+ this.__updateElements(btn, prefix)
47
+ }
48
+ });
49
+
39
50
  },
40
51
 
41
52
  __updateElements: function(element, prefix) {
@@ -88,6 +99,11 @@ const CoCreateEvents = {
88
99
  targetElements.forEach((el) => self.setValue(el, targetAttribute, values));
89
100
  } else
90
101
  self.setValue(element, targetAttribute, values);
102
+
103
+ document.dispatchEvent(new CustomEvent(`${prefix}End`, {
104
+ detail: {}
105
+ }))
106
+
91
107
  },
92
108
 
93
109
  setValue: function(element, attrName, values, deactivate) {
@@ -155,6 +171,7 @@ const CoCreateEvents = {
155
171
  }
156
172
  };
157
173
 
174
+
158
175
  CoCreateEvents.init();
159
176
 
160
177
  export default CoCreateEvents;