@blocklet/ui-react 2.1.27 → 2.1.28

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/utils.js CHANGED
@@ -56,7 +56,7 @@ const matchPath = path => {
56
56
 
57
57
  const pathname = ensureTrailingSlash(window.location.pathname);
58
58
  const normalizedPath = ensureTrailingSlash(new URL(path, window.location.origin).pathname);
59
- return normalizedPath.startsWith(pathname);
59
+ return pathname.startsWith(normalizedPath);
60
60
  };
61
61
  /**
62
62
  * 从一组 paths 中, 找到匹配当前 location 的 path, 返回序号
@@ -74,13 +74,13 @@ const matchPaths = function matchPaths() {
74
74
 
75
75
  if (!(matched !== null && matched !== void 0 && matched.length)) {
76
76
  return -1;
77
- } // 多个 path 都匹配时, 取一个最短的 path
77
+ } // 多个 path 都匹配时, 取一个最具体 (最长的) path
78
78
 
79
79
 
80
- const shortest = matched.slice(1).reduce((prev, cur) => {
81
- return prev.path.length <= cur.path.length ? prev : cur;
80
+ const mostSpecific = matched.slice(1).reduce((prev, cur) => {
81
+ return prev.path.length >= cur.path.length ? prev : cur;
82
82
  }, matched[0]);
83
- return shortest.index;
83
+ return mostSpecific.index;
84
84
  };
85
85
 
86
86
  exports.matchPaths = matchPaths;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.1.27",
3
+ "version": "2.1.28",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -34,8 +34,8 @@
34
34
  "url": "https://github.com/ArcBlock/ux/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@arcblock/did-connect": "^2.1.27",
38
- "@arcblock/ux": "^2.1.27",
37
+ "@arcblock/did-connect": "^2.1.28",
38
+ "@arcblock/ux": "^2.1.28",
39
39
  "@iconify/iconify": "^2.2.1",
40
40
  "@mui/material": "^5.6.4",
41
41
  "core-js": "^3.6.4",
@@ -57,5 +57,5 @@
57
57
  "eslint-plugin-react-hooks": "^4.2.0",
58
58
  "jest": "^24.1.0"
59
59
  },
60
- "gitHead": "a5f51b0432dbdfe806276bdb10b68df19575687e"
60
+ "gitHead": "725aea0efca877ff15c93d5eab829fca3fe8da25"
61
61
  }
package/src/utils.js CHANGED
@@ -32,7 +32,7 @@ export const matchPath = (path) => {
32
32
  const ensureTrailingSlash = (str) => (str.endsWith('/') ? str : `${str}/`);
33
33
  const pathname = ensureTrailingSlash(window.location.pathname);
34
34
  const normalizedPath = ensureTrailingSlash(new URL(path, window.location.origin).pathname);
35
- return normalizedPath.startsWith(pathname);
35
+ return pathname.startsWith(normalizedPath);
36
36
  };
37
37
 
38
38
  /**
@@ -43,9 +43,9 @@ export const matchPaths = (paths = []) => {
43
43
  if (!matched?.length) {
44
44
  return -1;
45
45
  }
46
- // 多个 path 都匹配时, 取一个最短的 path
47
- const shortest = matched.slice(1).reduce((prev, cur) => {
48
- return prev.path.length <= cur.path.length ? prev : cur;
46
+ // 多个 path 都匹配时, 取一个最具体 (最长的) path
47
+ const mostSpecific = matched.slice(1).reduce((prev, cur) => {
48
+ return prev.path.length >= cur.path.length ? prev : cur;
49
49
  }, matched[0]);
50
- return shortest.index;
50
+ return mostSpecific.index;
51
51
  };