@blocklet/ui-react 2.4.6 → 2.4.7
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/lib/blocklets.js +24 -1
- package/lib/utils.js +2 -2
- package/package.json +4 -4
- package/src/blocklets.js +20 -1
- package/src/utils.js +2 -2
package/lib/blocklets.js
CHANGED
|
@@ -68,11 +68,34 @@ const getLocalizedNavigation = function getLocalizedNavigation(navigation) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
return title;
|
|
71
|
+
}; // eslint-disable-next-line no-shadow
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const getLink = (link, locale) => {
|
|
75
|
+
if (typeof link === 'string') {
|
|
76
|
+
// http[s] 开头的 url
|
|
77
|
+
if ((0, _utils.isUrl)(link)) {
|
|
78
|
+
const url = new URL(link);
|
|
79
|
+
url.searchParams.set('locale', locale);
|
|
80
|
+
return url.href;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const url = new URL(link, window.location.origin);
|
|
84
|
+
url.searchParams.set('locale', locale);
|
|
85
|
+
return url.pathname + url.search;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (typeof link === 'object') {
|
|
89
|
+
return link[locale] || (link === null || link === void 0 ? void 0 : link.en) || (link === null || link === void 0 ? void 0 : link.zh);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return link;
|
|
71
93
|
};
|
|
72
94
|
|
|
73
95
|
return (0, _utils.mapRecursive)(navigation, item => {
|
|
74
96
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
75
|
-
title: getTitle(item.title, locale)
|
|
97
|
+
title: getTitle(item.title, locale),
|
|
98
|
+
link: getLink(item.link, locale)
|
|
76
99
|
});
|
|
77
100
|
}, 'items');
|
|
78
101
|
};
|
package/lib/utils.js
CHANGED
|
@@ -42,13 +42,13 @@ const countRecursive = function countRecursive(array) {
|
|
|
42
42
|
let counter = 0;
|
|
43
43
|
mapRecursive(array, () => counter++, childrenKey);
|
|
44
44
|
return counter;
|
|
45
|
-
}; // "http://", "https://"
|
|
45
|
+
}; // "http://", "https://" 2 种情况
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
exports.countRecursive = countRecursive;
|
|
49
49
|
|
|
50
50
|
const isUrl = str => {
|
|
51
|
-
return /^
|
|
51
|
+
return /^https?:\/\//.test(str);
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
54
|
* 检测 path 是否匹配当前 location, path 只考虑 "/" 开头的相对路径
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.7",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@arcblock/did-connect": "^2.4.
|
|
34
|
-
"@arcblock/ux": "^2.4.
|
|
33
|
+
"@arcblock/did-connect": "^2.4.7",
|
|
34
|
+
"@arcblock/ux": "^2.4.7",
|
|
35
35
|
"@emotion/react": "^11.10.0",
|
|
36
36
|
"@emotion/styled": "^11.10.0",
|
|
37
37
|
"@iconify/iconify": "^2.2.1",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
54
54
|
"jest": "^24.9.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "bf9bb3c3501333a9e218f6a78892431769530e41"
|
|
57
57
|
}
|
package/src/blocklets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mapRecursive } from './utils';
|
|
1
|
+
import { mapRecursive, isUrl } from './utils';
|
|
2
2
|
|
|
3
3
|
export const publicPath = window?.blocklet?.groupPrefix || window?.blocklet?.prefix || '/';
|
|
4
4
|
|
|
@@ -37,12 +37,31 @@ export const getLocalizedNavigation = (navigation, locale = 'en') => {
|
|
|
37
37
|
}
|
|
38
38
|
return title;
|
|
39
39
|
};
|
|
40
|
+
// eslint-disable-next-line no-shadow
|
|
41
|
+
const getLink = (link, locale) => {
|
|
42
|
+
if (typeof link === 'string') {
|
|
43
|
+
// http[s] 开头的 url
|
|
44
|
+
if (isUrl(link)) {
|
|
45
|
+
const url = new URL(link);
|
|
46
|
+
url.searchParams.set('locale', locale);
|
|
47
|
+
return url.href;
|
|
48
|
+
}
|
|
49
|
+
const url = new URL(link, window.location.origin);
|
|
50
|
+
url.searchParams.set('locale', locale);
|
|
51
|
+
return url.pathname + url.search;
|
|
52
|
+
}
|
|
53
|
+
if (typeof link === 'object') {
|
|
54
|
+
return link[locale] || link?.en || link?.zh;
|
|
55
|
+
}
|
|
56
|
+
return link;
|
|
57
|
+
};
|
|
40
58
|
return mapRecursive(
|
|
41
59
|
navigation,
|
|
42
60
|
(item) => {
|
|
43
61
|
return {
|
|
44
62
|
...item,
|
|
45
63
|
title: getTitle(item.title, locale),
|
|
64
|
+
link: getLink(item.link, locale),
|
|
46
65
|
};
|
|
47
66
|
},
|
|
48
67
|
'items'
|
package/src/utils.js
CHANGED
|
@@ -24,9 +24,9 @@ export const countRecursive = (array, childrenKey = 'children') => {
|
|
|
24
24
|
return counter;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// "http://", "https://"
|
|
27
|
+
// "http://", "https://" 2 种情况
|
|
28
28
|
export const isUrl = (str) => {
|
|
29
|
-
return /^
|
|
29
|
+
return /^https?:\/\//.test(str);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|