@cocreate/utils 1.39.1 → 1.40.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,18 @@
1
+ # [1.40.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.39.2...v1.40.0) (2025-10-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * add getRelativePath function to compute relative paths based on current location ([786ed1b](https://github.com/CoCreate-app/CoCreate-utils/commit/786ed1b642febad9c5fda1c9f5534e829f5fd6c6))
7
+ * enhance getRelativePath function to handle default path and localhost scenarios ([cd0b369](https://github.com/CoCreate-app/CoCreate-utils/commit/cd0b3692b1753d06805670c59d832a00e7b85a64))
8
+
9
+ ## [1.39.2](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.39.1...v1.39.2) (2025-09-01)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * improve media query handling in checkMediaQueries function ([cab86d6](https://github.com/CoCreate-app/CoCreate-utils/commit/cab86d6b43bb1739a0b62e28a826b5bdebab5e03))
15
+
1
16
  ## [1.39.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.39.0...v1.39.1) (2025-05-01)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,18 +1,10 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.39.1",
3
+ "version": "1.40.0",
4
4
  "description": "A simple utils component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "utils",
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
@@ -40,6 +40,31 @@
40
40
  }
41
41
  }
42
42
 
43
+ function getRelativePath(path) {
44
+ // If no path provided, use window.location.pathname
45
+ if (!path && isBrowser) {
46
+ path = window.location.pathname.replace(/\/[^\/]*$/, ""); // Remove file from path
47
+ }
48
+
49
+ // For localhost/127.0.0.1, trim everything after '/src'
50
+ if (
51
+ isBrowser &&
52
+ (location.hostname === "localhost" ||
53
+ location.hostname === "127.0.0.1")
54
+ ) {
55
+ const srcIndex = path.indexOf("/src");
56
+ if (srcIndex !== -1) {
57
+ path = path.substring(0, srcIndex + 4); // keep '/src'
58
+ }
59
+ }
60
+
61
+ if (!path.endsWith("/")) {
62
+ path += "/";
63
+ }
64
+ let depth = path.split("/").filter(Boolean).length;
65
+ return depth > 0 ? "../".repeat(depth) : "./";
66
+ }
67
+
43
68
  /**
44
69
  * Generates an ObjectId
45
70
  */
@@ -836,12 +861,13 @@
836
861
 
837
862
  function checkMediaQueries(selector) {
838
863
  if (selector && selector.includes("@")) {
864
+ const viewportWidth = window.innerWidth;
865
+ let mediaViewport = false;
866
+
839
867
  let screenSizes = selector.split("@");
840
868
  selector = screenSizes.shift();
841
- for (let screenSize of screenSizes) {
842
- const viewportWidth = window.innerWidth;
843
- let mediaViewport = false;
844
869
 
870
+ for (let screenSize of screenSizes) {
845
871
  // Check if screenSize is a valid range in the 'ranges' object
846
872
  if (mediaRanges.hasOwnProperty(screenSize)) {
847
873
  const [minWidth, maxWidth] = mediaRanges[screenSize];
@@ -853,9 +879,8 @@
853
879
  break;
854
880
  }
855
881
  }
856
-
857
- if (!mediaViewport) return false;
858
882
  }
883
+ if (!mediaViewport) return false;
859
884
  }
860
885
 
861
886
  return selector;
@@ -1248,6 +1273,7 @@
1248
1273
  if (isBrowser) clickedElement();
1249
1274
 
1250
1275
  return {
1276
+ getRelativePath,
1251
1277
  ObjectId,
1252
1278
  checkValue,
1253
1279
  isValidDate,
@@ -1269,4 +1295,4 @@
1269
1295
  setAttributeNames,
1270
1296
  getAttributeNames
1271
1297
  };
1272
- });
1298
+ });