@ray-js/framework-shared 1.6.25 → 1.6.26

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.
@@ -1,2 +1,2 @@
1
- import { Routes, TabBar } from '@ray-js/types';
1
+ import type { Routes, TabBar } from '@ray-js/types';
2
2
  export declare function normalizeTabBar(tabBar: TabBar, routes: Routes): TabBar;
@@ -4,6 +4,22 @@ import "core-js/modules/esnext.iterator.filter.js";
4
4
  import "core-js/modules/esnext.iterator.find.js";
5
5
  import "core-js/modules/esnext.iterator.map.js";
6
6
  import { match, parse } from 'path-to-regexp';
7
+ const locals = {
8
+ tabBarPagePathMustBeInRoutes: 'tabBar.list[{index}].pagePath: {pagePath} must be in route configuration: {routes}',
9
+ tabBarRouteShouldBeMatched: 'tabBar.list[{index}]\n.route: {route}\n.pagePath: {pagePath}\nshould be matched by route: \n{routeInfo}',
10
+ tabBarRouteMatchedByOthers: 'tabBar.list[{index}]\n.route: {route}\n.pagePath: {pagePath}\nis matched by other routes:\n{unusable}'
11
+ };
12
+ const i18n = {
13
+ __: (key, data) => {
14
+ const txt = locals[key] || key;
15
+ if (data) {
16
+ return txt.replace(/\{(\w+)}/g, (_, k) => {
17
+ return String(data[k] || '');
18
+ });
19
+ }
20
+ return txt;
21
+ }
22
+ };
7
23
  export function normalizeTabBar(tabBar, routes) {
8
24
  let list = tabBar.list;
9
25
  if (Array.isArray(list)) {
@@ -12,7 +28,7 @@ export function normalizeTabBar(tabBar, routes) {
12
28
  return tab;
13
29
  }
14
30
  for (const r of routes) {
15
- // 兼容老项目,将老数据格式到新数据
31
+ // Compatible with older projects, converting old data format to new
16
32
  if (tab.id === r.id) {
17
33
  return _objectSpread(_objectSpread({}, tab), {}, {
18
34
  pagePath: r.path
@@ -21,36 +37,50 @@ export function normalizeTabBar(tabBar, routes) {
21
37
  }
22
38
  return tab;
23
39
  });
24
- // tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
25
- // tabBar.list[number].route 可不配置
26
- // tabBar.list[number].route 若未配置,则设置 tabBar.list[number].route = routes[number].page(非模式匹配)或tabBar.list[number].pagePath
27
- // tabBar.list[number].route 不能用模式,如不能用/xxx/:id等,必须是明确的 如/xxx/123
28
- // tabBar.list[number].route 必须要能命中对应routes[number].route 路由规则,规则详见 path-to-regexp 模块
40
+ // tabBar.list[number].pagePath must be in routes[number].page, i.e., tab.pagePath === routes[number].page
41
+ // tabBar.list[number].route is optional
42
+ // If tabBar.list[number].route is not configured, set tabBar.list[number].route = routes[number].page (non-pattern matching) or tabBar.list[number].pagePath
43
+ // tabBar.list[number].route cannot use patterns like /xxx/:id, must be specific like /xxx/123
44
+ // tabBar.list[number].route must match the corresponding routes[number].route routing rule, see path-to-regexp module for details
29
45
  tabBar.list = list.map((tab, index) => {
30
46
  var _m$route;
31
47
  tab = _objectSpread({}, tab);
32
48
  const m = routes.find(i => tab.pagePath === i.path);
33
49
  if (!m) {
34
- throw new Error(`tabBar.list[${index}].pagePath: ${tab.pagePath} 需要在路由配置中: ${JSON.stringify(routes, null, 2)}`);
50
+ throw new Error(i18n.__('tabBarPagePathMustBeInRoutes', {
51
+ index,
52
+ pagePath: tab.pagePath,
53
+ routes: JSON.stringify(routes, null, 2)
54
+ }));
35
55
  }
36
56
  if (!tab.route) {
37
- // 判断 routes[number].route 是否为模式匹配规则
57
+ // Check if routes[number].route is a pattern matching rule
38
58
  tab.route = m.route && parse(m.route).length === 1 ? m.route : m.path;
39
59
  }
40
- // 判断是否能被路由命中
60
+ // Check if it can be matched by the route
41
61
  const matched = match((_m$route = m.route) !== null && _m$route !== void 0 ? _m$route : m.path)(tab.route);
42
62
  if (!matched) {
43
- console.warn(`tabBar.list[${index}]\n.route: ${tab.route}\n.pagePath: ${tab.pagePath}\n应被路由命中: \n${JSON.stringify(m, null, 2)}`);
63
+ console.warn(i18n.__('tabBarRouteShouldBeMatched', {
64
+ index,
65
+ route: tab.route,
66
+ pagePath: tab.pagePath,
67
+ routeInfo: JSON.stringify(m, null, 2)
68
+ }));
44
69
  return;
45
70
  }
46
- // 判断是否还被其他路由命中
71
+ // Check if it is matched by other routes
47
72
  const otherMatched = routes.filter(r => tab.pagePath !== r.path).filter(r => {
48
73
  var _r$route;
49
74
  return match((_r$route = r.route) !== null && _r$route !== void 0 ? _r$route : r.path)(tab.route);
50
75
  });
51
76
  const unusable = otherMatched.filter(r => r.path !== tab.pagePath);
52
77
  if (unusable.length) {
53
- console.warn(`tabBar.list[${index}]\n.route: ${tab.route}\n%c.pagePath: ${tab.pagePath}\n%c被其它路由命中:\n${JSON.stringify(unusable, null, 2)}`, 'background:#290000;color:green', 'background:#290000;color:green', 'color:red');
78
+ console.warn(i18n.__('tabBarRouteMatchedByOthers', {
79
+ index,
80
+ route: tab.route,
81
+ pagePath: tab.pagePath,
82
+ unusable: JSON.stringify(unusable, null, 2)
83
+ }), 'background:#290000;color:green', 'background:#290000;color:green', 'color:red');
54
84
  return;
55
85
  }
56
86
  return tab;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/framework-shared",
3
- "version": "1.6.25",
3
+ "version": "1.6.26",
4
4
  "description": "Ray shared for framework",
5
5
  "keywords": [
6
6
  "ray"
@@ -24,16 +24,16 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@ray-core/wechat": "^0.4.8",
27
- "@ray-js/env": "1.6.25",
28
- "@ray-js/types": "1.6.25",
27
+ "@ray-js/env": "1.6.26",
28
+ "@ray-js/types": "1.6.26",
29
29
  "path-to-regexp": "^6.3.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@ray-js/cli": "1.6.25"
32
+ "@ray-js/cli": "1.6.26"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public",
36
36
  "registry": "https://registry.npmjs.com"
37
37
  },
38
- "gitHead": "a2c08384889bbc2b1812c4a37490126c18aa1803"
38
+ "gitHead": "d842231dd15303495069483a809a71dbc640ebaf"
39
39
  }