@ray-js/router 0.6.21 → 0.6.22-beta-2
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/Router.d.ts +1 -1
- package/lib/Router.js +27 -53
- package/lib/RouterScheduler.d.ts +1 -1
- package/lib/RouterScheduler.js +9 -25
- package/lib/history/index.js +0 -1
- package/lib/index.js +1 -4
- package/package.json +5 -5
package/lib/Router.d.ts
CHANGED
package/lib/Router.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
3
|
import "core-js/modules/es.string.starts-with.js";
|
|
4
|
+
import "core-js/modules/es.object.to-string.js";
|
|
5
|
+
import "core-js/modules/es.promise.js";
|
|
6
6
|
import "core-js/modules/es.regexp.exec.js";
|
|
7
7
|
import "core-js/modules/es.string.search.js";
|
|
8
8
|
import "core-js/modules/es.string.replace.js";
|
|
@@ -19,66 +19,40 @@ export var Router = /*#__PURE__*/function () {
|
|
|
19
19
|
function Router(options) {
|
|
20
20
|
_classCallCheck(this, Router);
|
|
21
21
|
|
|
22
|
-
this.scheduler = options.scheduler;
|
|
22
|
+
this.scheduler = options.scheduler; // window.router = this
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
_createClass(Router, [{
|
|
26
26
|
key: "normalizeRoute",
|
|
27
|
-
value: function () {
|
|
28
|
-
var
|
|
29
|
-
var to, _url$parse, pathname, search, hash;
|
|
27
|
+
value: function normalizeRoute(params) {
|
|
28
|
+
var to = params.to; // FIXME: 绝对路径是否需要支持?
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!(to.startsWith('//') || to.startsWith('http'))) {
|
|
38
|
-
_context.next = 3;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return _context.abrupt("return", {
|
|
43
|
-
to: to
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
case 3:
|
|
47
|
-
if (this.scheduler.basename) {
|
|
48
|
-
to = this.scheduler.basename + to;
|
|
49
|
-
} // TODO: Web 应用下重复进入一个路由
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (this.$href) {
|
|
53
|
-
_url$parse = url.parse(this.$href), pathname = _url$parse.pathname, search = _url$parse.search, hash = _url$parse.hash;
|
|
54
|
-
|
|
55
|
-
if (url.format({
|
|
56
|
-
pathname: pathname,
|
|
57
|
-
search: search,
|
|
58
|
-
hash: hash
|
|
59
|
-
}) === to) {
|
|
60
|
-
console.warn('duplicate route to:', to);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
30
|
+
if (to.startsWith('//') || to.startsWith('http')) {
|
|
31
|
+
return Promise.resolve({
|
|
32
|
+
to: to
|
|
33
|
+
});
|
|
34
|
+
} // TODO: Web 应用下重复进入一个路由
|
|
63
35
|
|
|
64
|
-
return _context.abrupt("return", {
|
|
65
|
-
to: to
|
|
66
|
-
});
|
|
67
36
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, _callee, this);
|
|
74
|
-
}));
|
|
37
|
+
if (this.$href) {
|
|
38
|
+
var _url$parse = url.parse(this.$href),
|
|
39
|
+
pathname = _url$parse.pathname,
|
|
40
|
+
search = _url$parse.search,
|
|
41
|
+
hash = _url$parse.hash;
|
|
75
42
|
|
|
76
|
-
|
|
77
|
-
|
|
43
|
+
if (url.format({
|
|
44
|
+
pathname: pathname,
|
|
45
|
+
search: search,
|
|
46
|
+
hash: hash
|
|
47
|
+
}) === to) {
|
|
48
|
+
console.warn('duplicate route to:', to);
|
|
49
|
+
}
|
|
78
50
|
}
|
|
79
51
|
|
|
80
|
-
return
|
|
81
|
-
|
|
52
|
+
return Promise.resolve({
|
|
53
|
+
to: to
|
|
54
|
+
});
|
|
55
|
+
}
|
|
82
56
|
}, {
|
|
83
57
|
key: "push",
|
|
84
58
|
value: function push(to) {
|
|
@@ -125,7 +99,7 @@ export var Router = /*#__PURE__*/function () {
|
|
|
125
99
|
}
|
|
126
100
|
}
|
|
127
101
|
}, {
|
|
128
|
-
key: "
|
|
102
|
+
key: "href",
|
|
129
103
|
get: function get() {
|
|
130
104
|
return window.location.href;
|
|
131
105
|
}
|
package/lib/RouterScheduler.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare type EventMembers = 'routeChange';
|
|
|
6
6
|
export declare class RouterScheduler extends IRouterScheduler<Page> {
|
|
7
7
|
private $currentRoute;
|
|
8
8
|
private $listeners;
|
|
9
|
-
$entityMap:
|
|
9
|
+
$entityMap: Page[];
|
|
10
10
|
basename: string;
|
|
11
11
|
/**
|
|
12
12
|
* 当前调度器的 route 地址
|
package/lib/RouterScheduler.js
CHANGED
|
@@ -6,6 +6,8 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
|
6
6
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
7
7
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
8
8
|
import "core-js/modules/es.array.concat.js";
|
|
9
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
10
|
+
import "core-js/modules/es.string.replace.js";
|
|
9
11
|
import "core-js/modules/es.array.splice.js";
|
|
10
12
|
import "core-js/modules/es.array.index-of.js";
|
|
11
13
|
import "core-js/modules/es.object.to-string.js";
|
|
@@ -35,9 +37,9 @@ export var RouterScheduler = /*#__PURE__*/function (_IRouterScheduler) {
|
|
|
35
37
|
|
|
36
38
|
_defineProperty(_assertThisInitialized(_this), "$listeners", {});
|
|
37
39
|
|
|
38
|
-
_defineProperty(_assertThisInitialized(_this), "$entityMap",
|
|
40
|
+
_defineProperty(_assertThisInitialized(_this), "$entityMap", []);
|
|
39
41
|
|
|
40
|
-
_defineProperty(_assertThisInitialized(_this), "basename", '');
|
|
42
|
+
_defineProperty(_assertThisInitialized(_this), "basename", '/');
|
|
41
43
|
|
|
42
44
|
return _this;
|
|
43
45
|
}
|
|
@@ -53,7 +55,7 @@ export var RouterScheduler = /*#__PURE__*/function (_IRouterScheduler) {
|
|
|
53
55
|
},
|
|
54
56
|
set: function set(val) {
|
|
55
57
|
if (val !== this.currentRoute) {
|
|
56
|
-
this.$currentRoute = val;
|
|
58
|
+
this.$currentRoute = val.replace(/\/$/, '');
|
|
57
59
|
this.emit('routeChange', this.currentRoute);
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -97,18 +99,12 @@ export var RouterScheduler = /*#__PURE__*/function (_IRouterScheduler) {
|
|
|
97
99
|
|
|
98
100
|
var pages = params.pages,
|
|
99
101
|
tabBar = params.tabBar;
|
|
100
|
-
var tabBarList = tabBar.list || [];
|
|
102
|
+
var tabBarList = (tabBar === null || tabBar === void 0 ? void 0 : tabBar.list) || [];
|
|
101
103
|
pages.forEach(function (page) {
|
|
102
104
|
var isTabBar = tabBarList.some(function (item) {
|
|
103
|
-
|
|
104
|
-
return page.route === item.route;
|
|
105
|
-
} else if (item.id) {
|
|
106
|
-
return page.id === item.id;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return false;
|
|
105
|
+
return page.path === item.pagePath;
|
|
110
106
|
});
|
|
111
|
-
page.route =
|
|
107
|
+
page.route = page.route || page.path;
|
|
112
108
|
page.originalRoute = page.route;
|
|
113
109
|
|
|
114
110
|
_this2.addPage(_objectSpread(_objectSpread({}, page), {}, {
|
|
@@ -119,25 +115,13 @@ export var RouterScheduler = /*#__PURE__*/function (_IRouterScheduler) {
|
|
|
119
115
|
}, {
|
|
120
116
|
key: "getMatchedPage",
|
|
121
117
|
value: function getMatchedPage(pathname) {
|
|
122
|
-
// 适配 `domain.com/basename/` & `domain.com/basename`
|
|
123
|
-
// 注册首页使用的是 `/` 需预处理
|
|
124
|
-
if (this.basename === pathname) {
|
|
125
|
-
pathname = pathname + '/';
|
|
126
|
-
}
|
|
127
|
-
|
|
128
118
|
this.currentRoute = pathname;
|
|
129
119
|
return this.matchPageByPathname(pathname);
|
|
130
120
|
}
|
|
131
121
|
}, {
|
|
132
122
|
key: "addPage",
|
|
133
123
|
value: function addPage(page) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (!this.$entityMap[depth]) {
|
|
137
|
-
this.$entityMap[depth] = [];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
this.$entityMap[depth].push(page);
|
|
124
|
+
this.$entityMap.push(page);
|
|
141
125
|
}
|
|
142
126
|
}]);
|
|
143
127
|
|
package/lib/history/index.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -24,10 +24,7 @@ export function createRouter(options) {
|
|
|
24
24
|
}
|
|
25
25
|
}); // 设置路由基准路径
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
router.scheduler.basename = basename;
|
|
29
|
-
} // 调度器注册页面
|
|
30
|
-
|
|
27
|
+
router.scheduler.basename = basename || '/'; // 调度器注册页面
|
|
31
28
|
|
|
32
29
|
router.scheduler.registryPages({
|
|
33
30
|
routes: routes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/router",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.22-beta-2",
|
|
4
4
|
"description": "Ray Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ray-js/library": "^0.6.
|
|
24
|
-
"@ray-js/types": "^0.6.
|
|
23
|
+
"@ray-js/library": "^0.6.22-beta-2",
|
|
24
|
+
"@ray-js/types": "^0.6.22-beta-2",
|
|
25
25
|
"history": "4.x"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@ray-js/cli": "^0.6.
|
|
28
|
+
"@ray-js/cli": "^0.6.22-beta-2",
|
|
29
29
|
"@types/history": "^4.7.9"
|
|
30
30
|
},
|
|
31
31
|
"maintainers": [
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"email": "tuyafe@tuya.com"
|
|
35
35
|
}
|
|
36
36
|
],
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "5d621bf1561047175b967cdf3aa35446f7d7198a",
|
|
38
38
|
"repository": {}
|
|
39
39
|
}
|