@cocreate/events 1.27.3 → 1.28.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.
@@ -22,13 +22,13 @@ jobs:
22
22
  runs-on: ubuntu-latest
23
23
  steps:
24
24
  - name: Checkout
25
- uses: actions/checkout@v3
25
+ uses: actions/checkout@v4
26
26
  - name: Setup Node.js
27
- uses: actions/setup-node@v3
27
+ uses: actions/setup-node@v4
28
28
  with:
29
- node-version: 14
29
+ node-version: 22 # Required for the latest semantic-release plugins
30
30
  - name: Semantic Release
31
- uses: cycjimmy/semantic-release-action@v3
31
+ uses: cycjimmy/semantic-release-action@v4 # Update to v4 for better Node 20+ support
32
32
  id: semantic
33
33
  with:
34
34
  extra_plugins: |
@@ -36,9 +36,8 @@ jobs:
36
36
  @semantic-release/git
37
37
  @semantic-release/github
38
38
  env:
39
- GITHUB_TOKEN: "${{ secrets.GITHUB }}"
39
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # Use the built-in token if possible
40
40
  NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
41
41
  outputs:
42
42
  new_release_published: "${{ steps.semantic.outputs.new_release_published }}"
43
43
  new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
44
-
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # [1.28.0](https://github.com/CoCreate-app/CoCreate-events/compare/v1.27.4...v1.28.0) (2026-01-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update worklow ([e8f4c2d](https://github.com/CoCreate-app/CoCreate-events/commit/e8f4c2dc8c3a799adf0be238bab5a4ed9ac08915))
7
+
8
+
9
+ ### Features
10
+
11
+ * once attribute for intersectionObserver ([e58bfee](https://github.com/CoCreate-app/CoCreate-events/commit/e58bfeec8122a176179ec1b9a03557dbe80765d8))
12
+
13
+ ## [1.27.4](https://github.com/CoCreate-app/CoCreate-events/compare/v1.27.3...v1.27.4) (2025-10-11)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * add support for blur event initialization in CoCreateEvents ([8c2aec3](https://github.com/CoCreate-app/CoCreate-events/commit/8c2aec3cf145fdce8abf65463332c09c6c3c57c5))
19
+ * enhance conditional processing with else-if support and improve number parsing ([053f322](https://github.com/CoCreate-app/CoCreate-events/commit/053f3220fa8f98d20a02e6f3faa32340869b8e49))
20
+
1
21
  ## [1.27.3](https://github.com/CoCreate-app/CoCreate-events/compare/v1.27.2...v1.27.3) (2025-09-07)
2
22
 
3
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.27.3",
3
+ "version": "1.28.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
@@ -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]");
@@ -244,6 +245,10 @@ const CoCreateEvents = {
244
245
  ? threshold.filter((value) => value >= 0 && value <= 1)
245
246
  : [0];
246
247
 
248
+ // Returns true if attribute is present AND does not equal "false"
249
+ const onceAttr = el.getAttribute(`${prefix}-once`);
250
+ const once = onceAttr !== null && onceAttr !== "false";
251
+
247
252
  // Create IntersectionObserver
248
253
  const intersectionObserver = new IntersectionObserver(
249
254
  (entries) => {
@@ -273,6 +278,10 @@ const CoCreateEvents = {
273
278
  // entry.intersectionRatio
274
279
  // }
275
280
  );
281
+ // Disconnect if once is true
282
+ if (once) {
283
+ intersectionObserver.unobserve(entry.target);
284
+ }
276
285
  }
277
286
  });
278
287
  },
@@ -512,6 +521,7 @@ const CoCreateEvents = {
512
521
  }
513
522
 
514
523
  let ifCondition = element.getAttribute(`${prefix}-if`);
524
+ let elseIfCondition = element.getAttribute(`${prefix}-else-if`);
515
525
  let elseCondition = element.getAttribute(`${prefix}-else`);
516
526
 
517
527
  let ifValue = element.getAttribute(`${prefix}-if-value`);
@@ -530,38 +540,16 @@ const CoCreateEvents = {
530
540
  }
531
541
  }
532
542
 
533
- //TODO: improved resize toggling of values
534
- // let hasCondition = this.elements2.get(element)
535
543
  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
544
+ // If the 'if' condition is not met, stop processing this element.
545
+ if (!evaluateCondition(ifCondition, ifValue)) {
547
546
  return;
548
547
  }
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
548
+ } else if (elseCondition) {
549
+ // If there's no 'if' condition but there is an 'else' condition,
550
+ // stop processing if the 'else' condition is met.
551
+ // This creates an "execute unless" behavior for the 'else' attribute.
552
+ if (evaluateCondition(elseIfCondition, ifValue)) {
565
553
  return;
566
554
  }
567
555
  }
@@ -940,7 +928,10 @@ function checkCondition(condition, value) {
940
928
  // TODO: why parse updated conditin to boolean false
941
929
  // if (parse && condition !== "false") condition = parseCondition(condition);
942
930
 
943
- if (typeof value[0] === "number") {
931
+ if (
932
+ typeof condition === "number" ||
933
+ (typeof condition === "string" && /\d/.test(condition))
934
+ ) {
944
935
  condition = parseNumberCondition(condition);
945
936
  } else if (typeof value[0] === "object" && typeof condition === "string") {
946
937
  condition = parseJsonCondition(condition);
@@ -996,9 +987,11 @@ function parseJsonCondition(condition) {
996
987
  }
997
988
  }
998
989
  function parseNumberCondition(condition) {
999
- return !isNaN(condition) && condition.trim() !== ""
1000
- ? Number(condition)
1001
- : condition;
990
+ if (typeof condition === "string") {
991
+ const num = parseFloat(condition);
992
+ return !isNaN(num) ? num : condition;
993
+ }
994
+ return condition;
1002
995
  }
1003
996
 
1004
997
  // Helper function for delay using Promises