@tarojs/router 4.0.0-beta.86 → 4.0.0-beta.88
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/LICENSE +8 -8
- package/dist/api.d.ts +7 -6
- package/dist/api.js +16 -4
- package/dist/events/resize.d.ts +3 -2
- package/dist/events/scroll.d.ts +3 -2
- package/dist/history.d.ts +8 -10
- package/dist/index.cjs.d.ts +66 -0
- package/dist/index.cjs.js +68 -84
- package/dist/index.d.ts +10 -9
- package/dist/index.esm.d.ts +66 -0
- package/dist/index.esm.js +66 -82
- package/dist/navigationBar.d.ts +3 -2
- package/dist/router/index.d.ts +4 -3
- package/dist/router/index.js +2 -3
- package/dist/router/mpa.d.ts +5 -4
- package/dist/router/mpa.js +2 -2
- package/dist/router/multi-page.d.ts +8 -7
- package/dist/router/navigation-bar.d.ts +3 -3
- package/dist/router/navigation-bar.js +6 -6
- package/dist/router/page.d.ts +10 -11
- package/dist/router/page.js +14 -26
- package/dist/router/spa.d.ts +5 -4
- package/dist/router/spa.js +23 -36
- package/dist/router/stack.d.ts +2 -2
- package/dist/style.d.ts +5 -4
- package/dist/style.js +4 -6
- package/dist/tabbar.d.ts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/navigate.d.ts +7 -6
- package/package.json +29 -18
package/dist/router/spa.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import { History } from "../history.js";
|
|
3
|
+
import { SpaRouterConfig } from '../../types/router';
|
|
4
|
+
declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
|
|
5
|
+
export { createRouter };
|
package/dist/router/spa.js
CHANGED
|
@@ -17,10 +17,6 @@ function createRouter(history, app, config, framework) {
|
|
|
17
17
|
}
|
|
18
18
|
RouterConfig.config = config;
|
|
19
19
|
const handler = new PageHandler(config, history);
|
|
20
|
-
// Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
|
|
21
|
-
// 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
|
|
22
|
-
// 所以需要加一个锁来应对这个情况
|
|
23
|
-
const pageLock = {};
|
|
24
20
|
routesAlias.set(handler.router.customRoutes);
|
|
25
21
|
const basename = handler.router.basename;
|
|
26
22
|
const routes = handler.routes.map(route => {
|
|
@@ -42,35 +38,29 @@ function createRouter(history, app, config, framework) {
|
|
|
42
38
|
eventCenter.trigger('__taroRouterLaunch', launchParam);
|
|
43
39
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
44
40
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
45
|
-
const render = (
|
|
46
|
-
var _d, _e, _f, _g, _h, _j, _k
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
|
|
41
|
+
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
43
|
+
handler.pathname = decodeURI(location.pathname);
|
|
44
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
50
45
|
window.scrollTo(0, 0);
|
|
51
46
|
eventCenter.trigger('__taroRouterChange', {
|
|
52
47
|
toLocation: {
|
|
53
|
-
path:
|
|
48
|
+
path: handler.pathname
|
|
54
49
|
}
|
|
55
50
|
});
|
|
56
|
-
let element,
|
|
57
|
-
const routerPath = handler.router.forcePath || currentPathname;
|
|
58
|
-
pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
|
|
59
|
-
const currentLock = pageLock[routerPath];
|
|
60
|
-
let postLock;
|
|
51
|
+
let element, params;
|
|
61
52
|
try {
|
|
62
|
-
const result = yield router.resolve(
|
|
63
|
-
[element,
|
|
64
|
-
postLock = pageLock[routerPath];
|
|
53
|
+
const result = yield router.resolve(handler.router.forcePath || handler.pathname);
|
|
54
|
+
[element, , params] = yield Promise.all(result);
|
|
65
55
|
}
|
|
66
56
|
catch (error) {
|
|
67
57
|
if (error.status === 404) {
|
|
68
58
|
const notFoundEvent = {
|
|
69
59
|
isEntryPage: stacks.length === 0,
|
|
70
|
-
path:
|
|
60
|
+
path: handler.pathname,
|
|
71
61
|
query: handler.getQuery(createStampId()),
|
|
72
62
|
};
|
|
73
|
-
(
|
|
63
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
74
64
|
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
75
65
|
}
|
|
76
66
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -81,16 +71,13 @@ function createRouter(history, app, config, framework) {
|
|
|
81
71
|
throw error;
|
|
82
72
|
}
|
|
83
73
|
}
|
|
84
|
-
if (!element
|
|
74
|
+
if (!element)
|
|
85
75
|
return;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let
|
|
91
|
-
let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
|
|
92
|
-
let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
|
|
93
|
-
let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
|
|
76
|
+
const pageConfig = handler.pageConfig;
|
|
77
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
78
|
+
let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
|
|
79
|
+
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
80
|
+
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
94
81
|
if (pageConfig) {
|
|
95
82
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
96
83
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
@@ -107,7 +94,8 @@ function createRouter(history, app, config, framework) {
|
|
|
107
94
|
}
|
|
108
95
|
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
109
96
|
const currentPage = Current.page;
|
|
110
|
-
const
|
|
97
|
+
const pathname = handler.pathname;
|
|
98
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
111
99
|
const cacheTabs = stacks.getTabs();
|
|
112
100
|
let shouldLoad = false;
|
|
113
101
|
stacks.method = '';
|
|
@@ -122,11 +110,10 @@ function createRouter(history, app, config, framework) {
|
|
|
122
110
|
}
|
|
123
111
|
shouldLoad = true;
|
|
124
112
|
}
|
|
125
|
-
else if (currentPage && handler.isTabBar(pathname)) {
|
|
113
|
+
else if (currentPage && handler.isTabBar(handler.pathname)) {
|
|
126
114
|
if (handler.isSamePage(currentPage))
|
|
127
115
|
return;
|
|
128
116
|
if (handler.isTabBar(currentPage.path)) {
|
|
129
|
-
// NOTE: 从 tabBar 页面切换到 tabBar 页面
|
|
130
117
|
handler.hide(currentPage);
|
|
131
118
|
stacks.pushTab(currentPage.path.split('?')[0]);
|
|
132
119
|
}
|
|
@@ -140,8 +127,8 @@ function createRouter(history, app, config, framework) {
|
|
|
140
127
|
handler.unload(currentPage, stacks.length, true);
|
|
141
128
|
}
|
|
142
129
|
}
|
|
143
|
-
if (cacheTabs[pathname]) {
|
|
144
|
-
stacks.popTab(pathname);
|
|
130
|
+
if (cacheTabs[handler.pathname]) {
|
|
131
|
+
stacks.popTab(handler.pathname);
|
|
145
132
|
return handler.show(stacks.getItem(0), pageConfig, 0);
|
|
146
133
|
}
|
|
147
134
|
shouldLoad = true;
|
|
@@ -170,11 +157,11 @@ function createRouter(history, app, config, framework) {
|
|
|
170
157
|
shouldLoad = true;
|
|
171
158
|
}
|
|
172
159
|
else if (action === 'PUSH') {
|
|
173
|
-
handler.hide(currentPage
|
|
160
|
+
handler.hide(currentPage);
|
|
174
161
|
shouldLoad = true;
|
|
175
162
|
}
|
|
176
163
|
if (shouldLoad || stacks.length < 1) {
|
|
177
|
-
const el = (
|
|
164
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
178
165
|
const loadConfig = Object.assign({}, pageConfig);
|
|
179
166
|
const stacksIndex = stacks.length;
|
|
180
167
|
delete loadConfig['path'];
|
package/dist/router/stack.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PageInstance } from '@tarojs/runtime';
|
|
2
2
|
declare class Stacks {
|
|
3
3
|
stacks: PageInstance[];
|
|
4
4
|
backDelta: number;
|
|
@@ -23,4 +23,4 @@ declare class Stacks {
|
|
|
23
23
|
removeTab(path: string): void;
|
|
24
24
|
}
|
|
25
25
|
declare const stacks: Stacks;
|
|
26
|
-
export default
|
|
26
|
+
export { stacks as default };
|
package/dist/style.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 插入页面动画需要的样式
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
declare function loadAnimateStyle(ms?: number): void;
|
|
5
5
|
/**
|
|
6
6
|
* 插入路由相关样式
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
|
|
9
9
|
/**
|
|
10
10
|
* 插入导航栏相关的样式
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
declare function loadNavigationBarStyle(): void;
|
|
13
|
+
declare function addStyle(css: any): void;
|
|
14
|
+
export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
|
package/dist/style.js
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
function loadAnimateStyle(ms = 300) {
|
|
5
5
|
const css = `
|
|
6
6
|
body {
|
|
7
|
-
|
|
8
|
-
overflow: hidden;
|
|
7
|
+
overflow: hidden; // 防止 iOS 页面滚动
|
|
9
8
|
}
|
|
10
9
|
.taro_router > .taro_page {
|
|
11
10
|
position: absolute;
|
|
@@ -62,9 +61,8 @@ ${enableTabBar ? `
|
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
` : ''}
|
|
65
|
-
.taro_page_shade
|
|
66
|
-
.taro_page_shade.taro_tabbar_page
|
|
67
|
-
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child):has(+.taro_page_stationed) {
|
|
64
|
+
.taro_page_shade,
|
|
65
|
+
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
|
|
68
66
|
display: none;
|
|
69
67
|
}
|
|
70
68
|
`;
|
|
@@ -132,7 +130,7 @@ function loadNavigationBarStyle() {
|
|
|
132
130
|
to {
|
|
133
131
|
transform: rotate(360deg);
|
|
134
132
|
}
|
|
135
|
-
}
|
|
133
|
+
}
|
|
136
134
|
|
|
137
135
|
.taro-navigation-bar-no-icon > .taro-navigation-bar-home {
|
|
138
136
|
display: none;
|
package/dist/tabbar.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { AppConfig } from '@tarojs/taro';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { History } from "./history.js";
|
|
3
|
+
declare function initTabbar(config: AppConfig, history: History): void;
|
|
4
|
+
export { initTabbar };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ declare class RoutesAlias {
|
|
|
6
6
|
getAlias: (url?: string) => string;
|
|
7
7
|
getAll: (url?: string) => string[];
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
export
|
|
9
|
+
declare const routesAlias: RoutesAlias;
|
|
10
|
+
export { routesAlias };
|
|
11
|
+
export * from "./navigate.js";
|
package/dist/utils/navigate.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
declare const isWeixin: () => boolean;
|
|
2
|
+
declare const isDingTalk: () => boolean;
|
|
3
|
+
declare function setMpaTitle(title: string): void;
|
|
4
|
+
declare function setTitle(title: string): void;
|
|
5
|
+
declare function setNavigationBarStyle(option: {
|
|
6
6
|
backgroundColor: string;
|
|
7
7
|
frontColor: string;
|
|
8
8
|
}): void;
|
|
9
|
-
|
|
9
|
+
declare function setNavigationBarLoading(loading: boolean): void;
|
|
10
|
+
export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading };
|
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.88",
|
|
4
4
|
"description": "Taro-router",
|
|
5
|
-
"author": "O2Team",
|
|
6
|
-
"license": "MIT",
|
|
7
5
|
"browser": "dist/index.js",
|
|
8
6
|
"main:h5": "dist/index.esm.js",
|
|
9
7
|
"main": "dist/index.js",
|
|
@@ -22,34 +20,47 @@
|
|
|
22
20
|
"keywords": [
|
|
23
21
|
"router"
|
|
24
22
|
],
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
},
|
|
23
|
+
"author": "O2Team",
|
|
24
|
+
"license": "MIT",
|
|
28
25
|
"dependencies": {
|
|
29
26
|
"dingtalk-jsapi": "~2.15.2",
|
|
30
|
-
"history": "^5.
|
|
27
|
+
"history": "^5.1.0",
|
|
31
28
|
"mobile-detect": "^1.4.2",
|
|
32
|
-
"query-string": "^
|
|
29
|
+
"query-string": "^7.1.1",
|
|
33
30
|
"tslib": "^2.6.2",
|
|
34
|
-
"universal-router": "^
|
|
31
|
+
"universal-router": "^8.3.0"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
34
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
36
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
37
|
+
"@types/jest": "^29.4.0",
|
|
38
|
+
"jest": "^29.3.1",
|
|
39
|
+
"jest-cli": "^29.3.1",
|
|
40
|
+
"jest-environment-jsdom": "^29.6.4",
|
|
41
|
+
"jsdom": "^21.1.0",
|
|
42
|
+
"rollup": "^3.8.1",
|
|
43
|
+
"rollup-plugin-node-externals": "^5.0.0",
|
|
44
|
+
"rollup-plugin-ts": "^3.0.2",
|
|
45
|
+
"ts-jest": "^29.0.5",
|
|
46
|
+
"typescript": "^4.7.4",
|
|
47
|
+
"@tarojs/runtime": "4.0.0-beta.88",
|
|
48
|
+
"@tarojs/taro": "4.0.0-beta.88",
|
|
49
|
+
"@tarojs/shared": "4.0.0-beta.88"
|
|
41
50
|
},
|
|
42
51
|
"peerDependencies": {
|
|
43
|
-
"@tarojs/runtime": "4.0.0-beta.
|
|
44
|
-
"@tarojs/taro": "4.0.0-beta.
|
|
45
|
-
"@tarojs/shared": "4.0.0-beta.
|
|
52
|
+
"@tarojs/runtime": "4.0.0-beta.88",
|
|
53
|
+
"@tarojs/taro": "4.0.0-beta.88",
|
|
54
|
+
"@tarojs/shared": "4.0.0-beta.88"
|
|
46
55
|
},
|
|
47
56
|
"scripts": {
|
|
48
|
-
"prod": "pnpm run build",
|
|
49
57
|
"prebuild": "pnpm run clean",
|
|
50
58
|
"build": "pnpm run rollup --environment NODE_ENV:production",
|
|
51
59
|
"clean": "rimraf --impl=move-remove ./dist",
|
|
52
60
|
"dev": "pnpm run rollup --environment NODE_ENV:development -w",
|
|
53
|
-
"rollup": "rollup --config rollup.config.
|
|
61
|
+
"rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
|
|
62
|
+
"test": "cross-env NODE_ENV=jest jest",
|
|
63
|
+
"test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
|
|
64
|
+
"test:dev": "cross-env NODE_ENV=jest jest --watch"
|
|
54
65
|
}
|
|
55
66
|
}
|