@cocreate/events 1.27.3 → 1.27.4

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,11 @@
1
+ ## [1.27.4](https://github.com/CoCreate-app/CoCreate-events/compare/v1.27.3...v1.27.4) (2025-10-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add support for blur event initialization in CoCreateEvents ([8c2aec3](https://github.com/CoCreate-app/CoCreate-events/commit/8c2aec3cf145fdce8abf65463332c09c6c3c57c5))
7
+ * enhance conditional processing with else-if support and improve number parsing ([053f322](https://github.com/CoCreate-app/CoCreate-events/commit/053f3220fa8f98d20a02e6f3faa32340869b8e49))
8
+
1
9
  ## [1.27.3](https://github.com/CoCreate-app/CoCreate-events/compare/v1.27.2...v1.27.3) (2025-09-07)
2
10
 
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.27.3",
3
+ "version": "1.27.4",
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
@@ -45,6 +45,7 @@ const CoCreateEvents = {
45
45
  this.initPrefix("resize", ["onload", "resize"]);
46
46
  this.initPrefix("localstorage", ["onload"]);
47
47
  this.initPrefix("focus", ["focus"]);
48
+ this.initPrefix("blur", ["blur"]);
48
49
  }
49
50
 
50
51
  let customEventEls = document.querySelectorAll("[event-name]");
@@ -512,6 +513,7 @@ const CoCreateEvents = {
512
513
  }
513
514
 
514
515
  let ifCondition = element.getAttribute(`${prefix}-if`);
516
+ let elseIfCondition = element.getAttribute(`${prefix}-else-if`);
515
517
  let elseCondition = element.getAttribute(`${prefix}-else`);
516
518
 
517
519
  let ifValue = element.getAttribute(`${prefix}-if-value`);
@@ -530,38 +532,16 @@ const CoCreateEvents = {
530
532
  }
531
533
  }
532
534
 
533
- //TODO: improved resize toggling of values
534
- // let hasCondition = this.elements2.get(element)
535
535
  if (ifCondition) {
536
- if (evaluateCondition(ifCondition, ifValue)) {
537
- // Action 1: Condition exists and evaluates true
538
- // console.log("Executing Action 1 for ifCondition:", ifCondition); // Optional debug log
539
- // Replace this comment with your actual code for Path 1
540
- // e.g., this.elements2.set(element, { condition: ifCondition });
541
-
542
- // Assuming we stop processing for this element once a condition is met and actioned
543
- return;
544
- } else {
545
- // Condition existed but evaluated false. Stop processing.
546
- // Corresponds to the original `else if (ifCondition || elseCondition) { return; }` for the ifCondition case
536
+ // If the 'if' condition is not met, stop processing this element.
537
+ if (!evaluateCondition(ifCondition, ifValue)) {
547
538
  return;
548
539
  }
549
- }
550
-
551
- // If we reach here, ifCondition was falsy (didn't exist)
552
- // Now check the 'else' condition
553
- if (elseCondition) {
554
- if (evaluateCondition(elseCondition, ifValue)) {
555
- // Action 2: Condition exists and evaluates true
556
- // console.log("Executing Action 2 for elseCondition:", elseCondition); // Optional debug log
557
- // Replace this comment with your actual code for Path 2
558
- // e.g., this.elements2.set(element, { condition: elseCondition });
559
-
560
- // Assuming we stop processing for this element once a condition is met and actioned
561
- return;
562
- } else {
563
- // Condition existed but evaluated false. Stop processing.
564
- // Corresponds to the original `else if (ifCondition || elseCondition) { return; }` for the elseCondition case
540
+ } else if (elseCondition) {
541
+ // If there's no 'if' condition but there is an 'else' condition,
542
+ // stop processing if the 'else' condition is met.
543
+ // This creates an "execute unless" behavior for the 'else' attribute.
544
+ if (evaluateCondition(elseIfCondition, ifValue)) {
565
545
  return;
566
546
  }
567
547
  }
@@ -940,7 +920,10 @@ function checkCondition(condition, value) {
940
920
  // TODO: why parse updated conditin to boolean false
941
921
  // if (parse && condition !== "false") condition = parseCondition(condition);
942
922
 
943
- if (typeof value[0] === "number") {
923
+ if (
924
+ typeof condition === "number" ||
925
+ (typeof condition === "string" && /\d/.test(condition))
926
+ ) {
944
927
  condition = parseNumberCondition(condition);
945
928
  } else if (typeof value[0] === "object" && typeof condition === "string") {
946
929
  condition = parseJsonCondition(condition);
@@ -996,9 +979,11 @@ function parseJsonCondition(condition) {
996
979
  }
997
980
  }
998
981
  function parseNumberCondition(condition) {
999
- return !isNaN(condition) && condition.trim() !== ""
1000
- ? Number(condition)
1001
- : condition;
982
+ if (typeof condition === "string") {
983
+ const num = parseFloat(condition);
984
+ return !isNaN(num) ? num : condition;
985
+ }
986
+ return condition;
1002
987
  }
1003
988
 
1004
989
  // Helper function for delay using Promises