@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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.3.0",
3
+ "version": "1.4.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
@@ -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 deafualt and custom prefix to support action
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
- const target = event.target.closest(`[${prefix}], [${prefix}-value]`);
31
- if (target) {
32
- let attribute = target.getAttribute('actions') || ""
33
- if (attribute.includes(prefix))
34
- return;
35
- // if (target.closest(`[actions*="${prefix}"]`))
36
- // return;
37
- self.__updateElements(target, prefix);
38
-
39
- let parentElement = target.parentElement;
40
- if (parentElement) {
41
- do {
42
- parentElement = parentElement.closest(`[${prefix}], [${prefix}-value]`)
43
- if (parentElement)
44
- self.__updateElements(parentElement, prefix);
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
- while (parentElement)
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
  }