@cocreate/events 1.19.5 → 1.20.1

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,23 @@
1
+ ## [1.20.1](https://github.com/CoCreate-app/CoCreate-events/compare/v1.20.0...v1.20.1) (2024-05-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * getValue from element else fallback to value ([c8e06af](https://github.com/CoCreate-app/CoCreate-events/commit/c8e06afb6d88ab382cead8065dea88cdec3300ca))
7
+
8
+ # [1.20.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.19.5...v1.20.0) (2024-05-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * onEvent must liten at the document level, if no value allow comaparion of if esle conditions ([57d1f91](https://github.com/CoCreate-app/CoCreate-events/commit/57d1f91123d598b720030503412dd23fb6e38e51))
14
+
15
+
16
+ ### Features
17
+
18
+ * attribute *-on to apply an event name. The operation will pause and await the event to resolve before continuing ([0d8db13](https://github.com/CoCreate-app/CoCreate-events/commit/0d8db13ed1ee63d9b2e67d8ebdd50e60408303d7))
19
+ * support condition tur or false ([6a9f6fc](https://github.com/CoCreate-app/CoCreate-events/commit/6a9f6fcffe65028f4e6bb66fc1afd9f160297743))
20
+
1
21
  ## [1.19.5](https://github.com/CoCreate-app/CoCreate-events/compare/v1.19.4...v1.19.5) (2024-04-29)
2
22
 
3
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.19.5",
3
+ "version": "1.20.1",
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
@@ -229,6 +229,17 @@ const CoCreateEvents = {
229
229
  // if (targetAttribute === false)
230
230
  // return
231
231
 
232
+ let onEvent = element.getAttribute(`${prefix}-on`)
233
+ if (onEvent) {
234
+ await new Promise((resolve, reject) => {
235
+ const handleEvent = () => {
236
+ document.removeEventListener(onEvent, handleEvent);
237
+ resolve();
238
+ };
239
+ document.addEventListener(onEvent, handleEvent);
240
+ });
241
+ }
242
+
232
243
  let values
233
244
  if (prefix === 'localstorage') {
234
245
  let key = element.getAttribute('localstorage-get')
@@ -239,7 +250,9 @@ const CoCreateEvents = {
239
250
  if (values)
240
251
  localStorage.setItem(key, values)
241
252
  }
242
- if (!key || !values)
253
+
254
+ // if (!key || !values)
255
+ if (!key)
243
256
  return
244
257
  } else {
245
258
  values = element.getAttribute(`${prefix}-value`) || element.getAttribute(`${prefix}-if-value`) || element.getAttribute(prefix);
@@ -264,7 +277,7 @@ const CoCreateEvents = {
264
277
 
265
278
  let ifValue = element.getAttribute(`${prefix}-if-value`)
266
279
  if (!ifValue && ifValue !== "")
267
- ifValue = await element.getValue()
280
+ ifValue = await element.getValue() || values //values // await element.getValue()
268
281
  else if (ifValue || ifValue === "")
269
282
  ifValue = [ifValue]
270
283
  else
@@ -555,6 +568,12 @@ function checkCondition(condition, value) {
555
568
  if (operatorMatch)
556
569
  condition = operatorMatch[2].trim()
557
570
 
571
+ if (condition === 'true') {
572
+ return !!value[0];
573
+ } else if (condition === 'false') {
574
+ return !value[0];
575
+ }
576
+
558
577
  // TODO: why parse updated conditin to boolean false
559
578
  if (condition !== 'false')
560
579
  condition = parseCondition(condition);