@cocreate/utils 1.39.2 → 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 +8 -0
- package/package.json +1 -1
- package/src/index.js +27 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
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
|
+
|
|
1
9
|
## [1.39.2](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.39.1...v1.39.2) (2025-09-01)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
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
|
*/
|
|
@@ -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
|
+
});
|