@tarojs/router 3.6.7 → 3.6.8
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/dist/events/scroll.d.ts +1 -1
- package/dist/events/scroll.js +3 -3
- package/dist/index.cjs.js +166 -64
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +168 -66
- package/dist/index.esm.js.map +1 -1
- package/dist/router/multi-page.d.ts +3 -1
- package/dist/router/multi-page.js +41 -10
- package/dist/router/page.d.ts +4 -1
- package/dist/router/page.js +46 -13
- package/dist/router/spa.js +8 -11
- package/dist/style.d.ts +8 -0
- package/dist/style.js +71 -0
- package/package.json +3 -3
- package/dist/animation.d.ts +0 -4
- package/dist/animation.js +0 -29
package/dist/router/page.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable dot-notation */
|
|
2
|
-
import { Current, requestAnimationFrame } from '@tarojs/runtime';
|
|
2
|
+
import { Current, eventCenter, requestAnimationFrame } from '@tarojs/runtime';
|
|
3
3
|
import queryString from 'query-string';
|
|
4
|
-
import { loadAnimateStyle } from '../animation';
|
|
5
4
|
import { bindPageResize } from '../events/resize';
|
|
6
5
|
import { bindPageScroll } from '../events/scroll';
|
|
7
|
-
import { setHistoryMode } from '../history';
|
|
6
|
+
import { history, setHistoryMode } from '../history';
|
|
7
|
+
import { loadAnimateStyle, loadRouterStyle } from '../style';
|
|
8
8
|
import { initTabbar } from '../tabbar';
|
|
9
9
|
import { addLeadingSlash, getCurrentPage, getHomePage, routesAlias, stripBasename, stripTrailing } from '../utils';
|
|
10
10
|
import stacks from './stack';
|
|
@@ -92,6 +92,17 @@ export default class PageHandler {
|
|
|
92
92
|
}
|
|
93
93
|
return search.substring(1);
|
|
94
94
|
}
|
|
95
|
+
get usingWindowScroll() {
|
|
96
|
+
var _a;
|
|
97
|
+
let usingWindowScroll = false;
|
|
98
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
99
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
100
|
+
}
|
|
101
|
+
const win = window;
|
|
102
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
103
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
104
|
+
return usingWindowScroll;
|
|
105
|
+
}
|
|
95
106
|
getQuery(stamp = '', search = '', options = {}) {
|
|
96
107
|
search = search ? `${search}&${this.search}` : this.search;
|
|
97
108
|
const query = search
|
|
@@ -102,7 +113,9 @@ export default class PageHandler {
|
|
|
102
113
|
}
|
|
103
114
|
mount() {
|
|
104
115
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
116
|
+
this.pathname = history.location.pathname;
|
|
105
117
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
118
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
106
119
|
const appId = this.appId;
|
|
107
120
|
let app = document.getElementById(appId);
|
|
108
121
|
let isPosition = true;
|
|
@@ -169,7 +182,8 @@ export default class PageHandler {
|
|
|
169
182
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
170
183
|
this.addAnimation(pageEl, pageNo === 0);
|
|
171
184
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
172
|
-
this.bindPageEvents(page,
|
|
185
|
+
this.bindPageEvents(page, pageConfig);
|
|
186
|
+
this.triggerRouterChange();
|
|
173
187
|
}
|
|
174
188
|
else {
|
|
175
189
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -179,7 +193,8 @@ export default class PageHandler {
|
|
|
179
193
|
this.addAnimation(pageEl, pageNo === 0);
|
|
180
194
|
this.onReady(page, true);
|
|
181
195
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
182
|
-
this.bindPageEvents(page,
|
|
196
|
+
this.bindPageEvents(page, pageConfig);
|
|
197
|
+
this.triggerRouterChange();
|
|
183
198
|
});
|
|
184
199
|
}
|
|
185
200
|
}
|
|
@@ -227,7 +242,8 @@ export default class PageHandler {
|
|
|
227
242
|
setDisplay(pageEl);
|
|
228
243
|
this.addAnimation(pageEl, pageNo === 0);
|
|
229
244
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
230
|
-
this.bindPageEvents(page,
|
|
245
|
+
this.bindPageEvents(page, pageConfig);
|
|
246
|
+
this.triggerRouterChange();
|
|
231
247
|
}
|
|
232
248
|
else {
|
|
233
249
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -236,7 +252,8 @@ export default class PageHandler {
|
|
|
236
252
|
this.addAnimation(pageEl, pageNo === 0);
|
|
237
253
|
this.onReady(page, false);
|
|
238
254
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
239
|
-
this.bindPageEvents(page,
|
|
255
|
+
this.bindPageEvents(page, pageConfig);
|
|
256
|
+
this.triggerRouterChange();
|
|
240
257
|
});
|
|
241
258
|
}
|
|
242
259
|
}
|
|
@@ -290,15 +307,31 @@ export default class PageHandler {
|
|
|
290
307
|
? document.querySelector(`.taro_page#${id}`)
|
|
291
308
|
: document.querySelector('.taro_page') ||
|
|
292
309
|
document.querySelector('.taro_router'));
|
|
293
|
-
return el
|
|
310
|
+
return el;
|
|
311
|
+
}
|
|
312
|
+
getScrollingElement(page) {
|
|
313
|
+
if (this.usingWindowScroll)
|
|
314
|
+
return window;
|
|
315
|
+
return this.getPageContainer(page) || window;
|
|
294
316
|
}
|
|
295
|
-
bindPageEvents(page,
|
|
317
|
+
bindPageEvents(page, config = {}) {
|
|
296
318
|
var _a;
|
|
297
|
-
|
|
298
|
-
pageEl = this.getPageContainer();
|
|
299
|
-
}
|
|
319
|
+
const scrollEl = this.getScrollingElement(page);
|
|
300
320
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
301
|
-
bindPageScroll(page,
|
|
321
|
+
bindPageScroll(page, scrollEl, distance);
|
|
302
322
|
bindPageResize(page);
|
|
303
323
|
}
|
|
324
|
+
triggerRouterChange() {
|
|
325
|
+
/**
|
|
326
|
+
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
327
|
+
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
328
|
+
*/
|
|
329
|
+
setTimeout(() => {
|
|
330
|
+
eventCenter.trigger('__afterTaroRouterChange', {
|
|
331
|
+
toLocation: {
|
|
332
|
+
path: this.pathname
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}, 0);
|
|
336
|
+
}
|
|
304
337
|
}
|
package/dist/router/spa.js
CHANGED
|
@@ -48,8 +48,10 @@ export function createRouter(app, config, framework) {
|
|
|
48
48
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
49
49
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
50
50
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
var _c, _d, _e, _f, _g;
|
|
51
|
+
var _c, _d, _e, _f, _g, _h;
|
|
52
52
|
handler.pathname = decodeURI(location.pathname);
|
|
53
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
54
|
+
window.scrollTo(0, 0);
|
|
53
55
|
eventCenter.trigger('__taroRouterChange', {
|
|
54
56
|
toLocation: {
|
|
55
57
|
path: handler.pathname
|
|
@@ -67,7 +69,7 @@ export function createRouter(app, config, framework) {
|
|
|
67
69
|
path: handler.pathname,
|
|
68
70
|
query: handler.getQuery(createStampId()),
|
|
69
71
|
};
|
|
70
|
-
(
|
|
72
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
71
73
|
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
72
74
|
}
|
|
73
75
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -81,16 +83,16 @@ export function createRouter(app, config, framework) {
|
|
|
81
83
|
if (!element)
|
|
82
84
|
return;
|
|
83
85
|
const pageConfig = handler.pageConfig;
|
|
84
|
-
let enablePullDownRefresh = ((
|
|
86
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
85
87
|
if (pageConfig) {
|
|
86
|
-
setTitle((
|
|
88
|
+
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
87
89
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
88
90
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
const currentPage = Current.page;
|
|
92
94
|
const pathname = handler.pathname;
|
|
93
|
-
const methodName = (
|
|
95
|
+
const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
|
|
94
96
|
const cacheTabs = stacks.getTabs();
|
|
95
97
|
let shouldLoad = false;
|
|
96
98
|
stacks.method = '';
|
|
@@ -154,7 +156,7 @@ export function createRouter(app, config, framework) {
|
|
|
154
156
|
shouldLoad = true;
|
|
155
157
|
}
|
|
156
158
|
if (shouldLoad || stacks.length < 1) {
|
|
157
|
-
const el = (
|
|
159
|
+
const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
|
|
158
160
|
const loadConfig = Object.assign({}, pageConfig);
|
|
159
161
|
const stacksIndex = stacks.length;
|
|
160
162
|
delete loadConfig['path'];
|
|
@@ -172,11 +174,6 @@ export function createRouter(app, config, framework) {
|
|
|
172
174
|
page.options = params;
|
|
173
175
|
handler.load(page, pageConfig, pageStampId, stacksIndex);
|
|
174
176
|
}
|
|
175
|
-
eventCenter.trigger('__afterTaroRouterChange', {
|
|
176
|
-
toLocation: {
|
|
177
|
-
path: handler.pathname
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
177
|
});
|
|
181
178
|
const routePath = addLeadingSlash(stripBasename(history.location.pathname, handler.basename));
|
|
182
179
|
if (routePath === '/') {
|
package/dist/style.d.ts
ADDED
package/dist/style.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插入页面动画需要的样式
|
|
3
|
+
*/
|
|
4
|
+
export function loadAnimateStyle(ms = 300) {
|
|
5
|
+
const css = `
|
|
6
|
+
.taro_router .taro_page {
|
|
7
|
+
position: absolute;
|
|
8
|
+
left: 0;
|
|
9
|
+
top: 0;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
background-color: #fff;
|
|
13
|
+
transform: translate(100%, 0);
|
|
14
|
+
transition: transform ${ms}ms;
|
|
15
|
+
z-index: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.taro_router .taro_page.taro_tabbar_page,
|
|
19
|
+
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
20
|
+
transform: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.taro_router .taro_page.taro_page_show {
|
|
24
|
+
transform: translate(0, 0);
|
|
25
|
+
}`;
|
|
26
|
+
addStyle(css);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 插入路由相关样式
|
|
30
|
+
*/
|
|
31
|
+
export function loadRouterStyle(usingWindowScroll) {
|
|
32
|
+
const css = `
|
|
33
|
+
.taro_router {
|
|
34
|
+
overflow: hidden;
|
|
35
|
+
position: relative;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
min-height: 100vh;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.taro-tabbar__container .taro_router {
|
|
42
|
+
min-height: calc(100vh - 50px);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.taro_page {
|
|
46
|
+
width: 100%;
|
|
47
|
+
height: 100%;
|
|
48
|
+
${usingWindowScroll ? '' : `
|
|
49
|
+
overflow-x: hidden;
|
|
50
|
+
overflow-y: scroll;
|
|
51
|
+
max-height: 100vh;
|
|
52
|
+
`}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.taro-tabbar__container .taro-tabbar__panel {
|
|
56
|
+
overflow: hidden;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.taro-tabbar__container .taro_page.taro_tabbar_page {
|
|
60
|
+
max-height: calc(100vh - 50px);
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
addStyle(css);
|
|
64
|
+
}
|
|
65
|
+
function addStyle(css) {
|
|
66
|
+
if (!css)
|
|
67
|
+
return;
|
|
68
|
+
const style = document.createElement('style');
|
|
69
|
+
style.innerHTML = css;
|
|
70
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.8",
|
|
4
4
|
"description": "Taro-router",
|
|
5
5
|
"browser": "dist/index.esm.js",
|
|
6
6
|
"main:h5": "dist/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"mobile-detect": "^1.4.2",
|
|
28
28
|
"query-string": "^7.1.1",
|
|
29
29
|
"universal-router": "^8.3.0",
|
|
30
|
-
"@tarojs/runtime": "3.6.
|
|
31
|
-
"@tarojs/taro": "3.6.
|
|
30
|
+
"@tarojs/runtime": "3.6.8",
|
|
31
|
+
"@tarojs/taro": "3.6.8"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@rollup/plugin-commonjs": "^20.0.0",
|
package/dist/animation.d.ts
DELETED
package/dist/animation.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插入页面动画需要的样式
|
|
3
|
-
*/
|
|
4
|
-
export function loadAnimateStyle(ms = 300) {
|
|
5
|
-
const css = `
|
|
6
|
-
.taro_router .taro_page {
|
|
7
|
-
position: absolute;
|
|
8
|
-
left: 0;
|
|
9
|
-
top: 0;
|
|
10
|
-
width: 100%;
|
|
11
|
-
height: 100%;
|
|
12
|
-
background-color: #fff;
|
|
13
|
-
transform: translate(100%, 0);
|
|
14
|
-
transition: transform ${ms}ms;
|
|
15
|
-
z-index: 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.taro_router .taro_page.taro_tabbar_page,
|
|
19
|
-
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
20
|
-
transform: none;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.taro_router .taro_page.taro_page_show {
|
|
24
|
-
transform: translate(0, 0);
|
|
25
|
-
}`;
|
|
26
|
-
const style = document.createElement('style');
|
|
27
|
-
style.innerHTML = css;
|
|
28
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
29
|
-
}
|