@cocreate/events 1.27.2 → 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,18 @@
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
+
9
+ ## [1.27.3](https://github.com/CoCreate-app/CoCreate-events/compare/v1.27.2...v1.27.3) (2025-09-07)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * improve event handling and element manipulation in CoCreateEvents ([ae6b58a](https://github.com/CoCreate-app/CoCreate-events/commit/ae6b58a7c0dc313b426a2614b6cb141735dffbbb))
15
+
1
16
  ## [1.27.2](https://github.com/CoCreate-app/CoCreate-events/compare/v1.27.1...v1.27.2) (2025-05-01)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,18 +1,10 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.27.2",
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",
7
- "cocreate",
8
- "low-code-framework",
9
- "no-code-framework",
10
- "cocreatejs",
11
- "cocreatejs-component",
12
- "cocreate-framework",
13
- "no-code",
14
7
  "low-code",
15
- "collaborative-framework",
16
8
  "realtime",
17
9
  "realtime-framework",
18
10
  "collaboration",
package/src/index.js CHANGED
@@ -28,8 +28,9 @@ import "@cocreate/element-prototype";
28
28
  const CoCreateEvents = {
29
29
  elements2: new Map(),
30
30
  init: function (prefix, events) {
31
- if (prefix && events) this.initPrefix(prefix, events);
32
- else {
31
+ if (prefix && events) {
32
+ this.initPrefix(prefix, events);
33
+ } else {
33
34
  this.initPrefix("toggle", ["click"]);
34
35
  this.initPrefix("click", ["click"]);
35
36
  this.initPrefix("hover", ["mouseover", "mouseout"]);
@@ -44,6 +45,7 @@ const CoCreateEvents = {
44
45
  this.initPrefix("resize", ["onload", "resize"]);
45
46
  this.initPrefix("localstorage", ["onload"]);
46
47
  this.initPrefix("focus", ["focus"]);
48
+ this.initPrefix("blur", ["blur"]);
47
49
  }
48
50
 
49
51
  let customEventEls = document.querySelectorAll("[event-name]");
@@ -385,11 +387,9 @@ const CoCreateEvents = {
385
387
  let elements = [el];
386
388
  let targetGroup = el.getAttribute(`${prefix}-group`);
387
389
  if (targetGroup) {
388
- document
389
- .querySelectorAll(`[${prefix}-group="${targetGroup}"]`)
390
- .forEach((element) => {
391
- if (element !== el) elements.push(element);
392
- });
390
+ elements = document.querySelectorAll(
391
+ `[${prefix}-group="${targetGroup}"]`
392
+ );
393
393
  }
394
394
 
395
395
  for (let element of elements) {
@@ -513,6 +513,7 @@ const CoCreateEvents = {
513
513
  }
514
514
 
515
515
  let ifCondition = element.getAttribute(`${prefix}-if`);
516
+ let elseIfCondition = element.getAttribute(`${prefix}-else-if`);
516
517
  let elseCondition = element.getAttribute(`${prefix}-else`);
517
518
 
518
519
  let ifValue = element.getAttribute(`${prefix}-if-value`);
@@ -531,38 +532,16 @@ const CoCreateEvents = {
531
532
  }
532
533
  }
533
534
 
534
- //TODO: improved resize toggling of values
535
- // let hasCondition = this.elements2.get(element)
536
535
  if (ifCondition) {
537
- if (evaluateCondition(ifCondition, ifValue)) {
538
- // Action 1: Condition exists and evaluates true
539
- // console.log("Executing Action 1 for ifCondition:", ifCondition); // Optional debug log
540
- // Replace this comment with your actual code for Path 1
541
- // e.g., this.elements2.set(element, { condition: ifCondition });
542
-
543
- // Assuming we stop processing for this element once a condition is met and actioned
544
- return;
545
- } else {
546
- // Condition existed but evaluated false. Stop processing.
547
- // 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)) {
548
538
  return;
549
539
  }
550
- }
551
-
552
- // If we reach here, ifCondition was falsy (didn't exist)
553
- // Now check the 'else' condition
554
- if (elseCondition) {
555
- if (evaluateCondition(elseCondition, ifValue)) {
556
- // Action 2: Condition exists and evaluates true
557
- // console.log("Executing Action 2 for elseCondition:", elseCondition); // Optional debug log
558
- // Replace this comment with your actual code for Path 2
559
- // e.g., this.elements2.set(element, { condition: elseCondition });
560
-
561
- // Assuming we stop processing for this element once a condition is met and actioned
562
- return;
563
- } else {
564
- // Condition existed but evaluated false. Stop processing.
565
- // 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)) {
566
545
  return;
567
546
  }
568
547
  }
@@ -583,8 +562,11 @@ const CoCreateEvents = {
583
562
  if (el !== element) {
584
563
  deactivate = true;
585
564
  }
586
- // values = values.map(x => x.trim());
565
+ if (events && events.includes("click")) {
566
+ // TODO: handling of attributes that represent states aria-expanded, aria-selected etc.
567
+ }
587
568
 
569
+ // values = values.map(x => x.trim());
588
570
  values = values.map((x) => {
589
571
  if (typeof x === "string") x = x.trim(); // Update x with the trimmed value
590
572
  let prop = element.getAttribute(`${prefix}-property`);
@@ -604,10 +586,14 @@ const CoCreateEvents = {
604
586
  targetElements = [element];
605
587
  }
606
588
 
607
- let action = element.getAttribute(`${prefix}-action`);
589
+ let action =
590
+ element.getAttribute(`${prefix}-action`) ||
591
+ element.getAttribute(`${prefix}-method`);
608
592
  for (let i = 0; i < targetElements.length; i++) {
609
593
  if (action) {
610
- targetElements[i][action]();
594
+ if (targetElements[i][action]) {
595
+ targetElements[i][action]();
596
+ }
611
597
  } else if (
612
598
  !targetAttribute &&
613
599
  targetAttribute !== "" &&
@@ -736,14 +722,18 @@ const CoCreateEvents = {
736
722
  if (deactivate) newValue = "";
737
723
  if (attrName === "class") {
738
724
  if (oldValue) {
739
- element.classList.remove(oldValue);
725
+ oldValue.split(" ").forEach((className) => {
726
+ element.classList.remove(className);
727
+ });
740
728
  if (values.length === 1) {
741
729
  return;
742
730
  }
743
731
  }
744
732
 
745
733
  if (newValue) {
746
- element.classList.add(newValue);
734
+ newValue.split(" ").forEach((className) => {
735
+ element.classList.add(className);
736
+ });
747
737
  }
748
738
  } else if (attrName === "value") {
749
739
  element.setValue(newValue, false);
@@ -755,9 +745,11 @@ const CoCreateEvents = {
755
745
  element[attrName.substring(1)]();
756
746
  } else if (attrName) {
757
747
  // TODO: removeAttribute vs setting empty value, how best to define. operator $remove ???
758
- if (newValue === "" && element.hasAttribute(attrName))
748
+ if (newValue === "" && element.hasAttribute(attrName)) {
759
749
  element.removeAttribute(attrName);
760
- else element.setAttribute(attrName, newValue);
750
+ } else {
751
+ element.setAttribute(attrName, newValue);
752
+ }
761
753
  } else if (targetPosition) {
762
754
  if (domTextEditor) {
763
755
  CoCreate.text.insertAdjacentElement({
@@ -928,7 +920,10 @@ function checkCondition(condition, value) {
928
920
  // TODO: why parse updated conditin to boolean false
929
921
  // if (parse && condition !== "false") condition = parseCondition(condition);
930
922
 
931
- if (typeof value[0] === "number") {
923
+ if (
924
+ typeof condition === "number" ||
925
+ (typeof condition === "string" && /\d/.test(condition))
926
+ ) {
932
927
  condition = parseNumberCondition(condition);
933
928
  } else if (typeof value[0] === "object" && typeof condition === "string") {
934
929
  condition = parseJsonCondition(condition);
@@ -984,9 +979,11 @@ function parseJsonCondition(condition) {
984
979
  }
985
980
  }
986
981
  function parseNumberCondition(condition) {
987
- return !isNaN(condition) && condition.trim() !== ""
988
- ? Number(condition)
989
- : condition;
982
+ if (typeof condition === "string") {
983
+ const num = parseFloat(condition);
984
+ return !isNaN(num) ? num : condition;
985
+ }
986
+ return condition;
990
987
  }
991
988
 
992
989
  // Helper function for delay using Promises