@blocklet/editor 2.5.58 → 2.5.60
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.
|
@@ -25,6 +25,29 @@ function isSameOrigin(url) {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
const PHONE_NUMBER_REGEX = /^\+?[0-9\s()-]{5,}$/;
|
|
29
|
+
function formatUrl(url) {
|
|
30
|
+
// Check if URL already has a protocol
|
|
31
|
+
if (url.match(/^[a-z][a-z0-9+.-]*:/i)) {
|
|
32
|
+
// URL already has a protocol, leave it as is
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
35
|
+
// Check if it's a relative path (starting with '/', '.', or '#')
|
|
36
|
+
if (url.match(/^[/#.]/)) {
|
|
37
|
+
// Relative path, leave it as is
|
|
38
|
+
return url;
|
|
39
|
+
}
|
|
40
|
+
// Check for email address
|
|
41
|
+
if (url.includes('@')) {
|
|
42
|
+
return `mailto:${url}`;
|
|
43
|
+
}
|
|
44
|
+
// Check for phone number
|
|
45
|
+
if (PHONE_NUMBER_REGEX.test(url)) {
|
|
46
|
+
return `tel:${url}`;
|
|
47
|
+
}
|
|
48
|
+
// For everything else, return with "./" prefix
|
|
49
|
+
return `./${url}`;
|
|
50
|
+
}
|
|
28
51
|
/**
|
|
29
52
|
* 代码复制自 @lexical/react/LexicalClickableLinkPlugin, 逻辑改动:
|
|
30
53
|
* - url origin 与 window.location.origin 相同时, 避免 newTab 方式跳转
|
|
@@ -52,7 +75,7 @@ export default function LexicalClickableLinkPlugin({ newTab = true }) {
|
|
|
52
75
|
if (clickedNode !== null) {
|
|
53
76
|
const maybeLinkNode = $findMatchingParent(clickedNode, $isElementNode);
|
|
54
77
|
if ($isLinkNode(maybeLinkNode)) {
|
|
55
|
-
url = maybeLinkNode.sanitizeUrl(maybeLinkNode.getURL());
|
|
78
|
+
url = maybeLinkNode.sanitizeUrl(formatUrl(maybeLinkNode.getURL()));
|
|
56
79
|
urlTarget = maybeLinkNode.getTarget();
|
|
57
80
|
}
|
|
58
81
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.60",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"ufo": "^1.5.4",
|
|
74
74
|
"url-join": "^4.0.1",
|
|
75
75
|
"zustand": "^4.5.5",
|
|
76
|
-
"@blocklet/pdf": "2.5.
|
|
76
|
+
"@blocklet/pdf": "2.5.60"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@babel/core": "^7.25.2",
|