@tarojs/router 3.7.0-alpha.8 → 3.7.0-beta.3
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/api.js +6 -1
- package/dist/index.cjs.js +85 -84
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +85 -84
- package/dist/index.esm.js.map +1 -1
- package/dist/router/index.js +2 -2
- package/dist/router/page.js +4 -9
- package/dist/style.d.ts +1 -1
- package/dist/style.js +15 -14
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -31,65 +31,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
35
|
-
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
36
|
-
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
37
|
-
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
38
|
-
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
39
|
-
const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
40
|
-
const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
41
|
-
var _a;
|
|
42
|
-
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
43
|
-
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
44
|
-
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
45
|
-
};
|
|
46
|
-
const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
47
|
-
const pagePath = routerMode === 'hash'
|
|
48
|
-
? location.hash.slice(1).split('?')[0]
|
|
49
|
-
: location.pathname;
|
|
50
|
-
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
51
|
-
};
|
|
52
|
-
class RoutesAlias {
|
|
53
|
-
constructor() {
|
|
54
|
-
this.conf = [];
|
|
55
|
-
this.getConfig = (url = '') => {
|
|
56
|
-
const customRoute = this.conf.filter((arr) => {
|
|
57
|
-
return arr.includes(url);
|
|
58
|
-
});
|
|
59
|
-
return customRoute[0];
|
|
60
|
-
};
|
|
61
|
-
this.getOrigin = (url = '') => {
|
|
62
|
-
var _a;
|
|
63
|
-
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
|
|
64
|
-
};
|
|
65
|
-
this.getAlias = (url = '') => {
|
|
66
|
-
var _a;
|
|
67
|
-
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
|
|
68
|
-
};
|
|
69
|
-
this.getAll = (url = '') => {
|
|
70
|
-
return this.conf
|
|
71
|
-
.filter((arr) => arr.includes(url))
|
|
72
|
-
.reduceRight((p, a) => {
|
|
73
|
-
p.unshift(a[1]);
|
|
74
|
-
return p;
|
|
75
|
-
}, []);
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
set(customRoutes = {}) {
|
|
79
|
-
for (let key in customRoutes) {
|
|
80
|
-
const path = customRoutes[key];
|
|
81
|
-
key = addLeadingSlash(key);
|
|
82
|
-
if (typeof path === 'string') {
|
|
83
|
-
this.conf.push([key, addLeadingSlash(path)]);
|
|
84
|
-
}
|
|
85
|
-
else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
|
|
86
|
-
this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const routesAlias = new RoutesAlias();
|
|
92
|
-
|
|
93
34
|
class RouterConfig {
|
|
94
35
|
static set config(e) {
|
|
95
36
|
this.__config = e;
|
|
@@ -108,7 +49,7 @@ class RouterConfig {
|
|
|
108
49
|
}
|
|
109
50
|
static get customRoutes() { return this.router.customRoutes || {}; }
|
|
110
51
|
static isPage(url = '') {
|
|
111
|
-
return this.pages.findIndex(e =>
|
|
52
|
+
return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
|
|
112
53
|
}
|
|
113
54
|
}
|
|
114
55
|
|
|
@@ -292,6 +233,65 @@ class Stacks {
|
|
|
292
233
|
}
|
|
293
234
|
const stacks = new Stacks();
|
|
294
235
|
|
|
236
|
+
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
237
|
+
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
238
|
+
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
239
|
+
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
240
|
+
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
241
|
+
const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
242
|
+
const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
243
|
+
var _a;
|
|
244
|
+
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
245
|
+
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
246
|
+
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
247
|
+
};
|
|
248
|
+
const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
249
|
+
const pagePath = routerMode === 'hash'
|
|
250
|
+
? location.hash.slice(1).split('?')[0]
|
|
251
|
+
: location.pathname;
|
|
252
|
+
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
253
|
+
};
|
|
254
|
+
class RoutesAlias {
|
|
255
|
+
constructor() {
|
|
256
|
+
this.conf = [];
|
|
257
|
+
this.getConfig = (url = '') => {
|
|
258
|
+
const customRoute = this.conf.filter((arr) => {
|
|
259
|
+
return arr.includes(url);
|
|
260
|
+
});
|
|
261
|
+
return customRoute[0];
|
|
262
|
+
};
|
|
263
|
+
this.getOrigin = (url = '') => {
|
|
264
|
+
var _a;
|
|
265
|
+
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
|
|
266
|
+
};
|
|
267
|
+
this.getAlias = (url = '') => {
|
|
268
|
+
var _a;
|
|
269
|
+
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
|
|
270
|
+
};
|
|
271
|
+
this.getAll = (url = '') => {
|
|
272
|
+
return this.conf
|
|
273
|
+
.filter((arr) => arr.includes(url))
|
|
274
|
+
.reduceRight((p, a) => {
|
|
275
|
+
p.unshift(a[1]);
|
|
276
|
+
return p;
|
|
277
|
+
}, []);
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
set(customRoutes = {}) {
|
|
281
|
+
for (let key in customRoutes) {
|
|
282
|
+
const path = customRoutes[key];
|
|
283
|
+
key = addLeadingSlash(key);
|
|
284
|
+
if (typeof path === 'string') {
|
|
285
|
+
this.conf.push([key, addLeadingSlash(path)]);
|
|
286
|
+
}
|
|
287
|
+
else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
|
|
288
|
+
this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const routesAlias = new RoutesAlias();
|
|
294
|
+
|
|
295
295
|
function processNavigateUrl(option) {
|
|
296
296
|
var _a;
|
|
297
297
|
const pathPieces = parsePath(option.url);
|
|
@@ -345,7 +345,12 @@ function navigate(option, method) {
|
|
|
345
345
|
}
|
|
346
346
|
else if (method === 'navigateBack') {
|
|
347
347
|
stacks.delta = option.delta;
|
|
348
|
-
|
|
348
|
+
if (stacks.length > option.delta) {
|
|
349
|
+
history.go(-option.delta);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
history.go(1 - stacks.length);
|
|
353
|
+
}
|
|
349
354
|
}
|
|
350
355
|
}
|
|
351
356
|
catch (error) {
|
|
@@ -467,7 +472,7 @@ function getOffset() {
|
|
|
467
472
|
*/
|
|
468
473
|
function loadAnimateStyle(ms = 300) {
|
|
469
474
|
const css = `
|
|
470
|
-
.taro_router .taro_page {
|
|
475
|
+
.taro_router > .taro_page {
|
|
471
476
|
position: absolute;
|
|
472
477
|
left: 0;
|
|
473
478
|
top: 0;
|
|
@@ -479,14 +484,15 @@ function loadAnimateStyle(ms = 300) {
|
|
|
479
484
|
z-index: 0;
|
|
480
485
|
}
|
|
481
486
|
|
|
482
|
-
.taro_router .taro_page.taro_tabbar_page,
|
|
483
|
-
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
487
|
+
.taro_router > .taro_page.taro_tabbar_page,
|
|
488
|
+
.taro_router > .taro_page.taro_page_show.taro_page_stationed {
|
|
484
489
|
transform: none;
|
|
485
490
|
}
|
|
486
491
|
|
|
487
|
-
.taro_router .taro_page.taro_page_show {
|
|
492
|
+
.taro_router > .taro_page.taro_page_show {
|
|
488
493
|
transform: translate(0, 0);
|
|
489
|
-
}
|
|
494
|
+
}
|
|
495
|
+
`;
|
|
490
496
|
addStyle(css);
|
|
491
497
|
}
|
|
492
498
|
/**
|
|
@@ -495,15 +501,9 @@ function loadAnimateStyle(ms = 300) {
|
|
|
495
501
|
function loadRouterStyle(usingWindowScroll) {
|
|
496
502
|
const css = `
|
|
497
503
|
.taro_router {
|
|
498
|
-
overflow: hidden;
|
|
499
504
|
position: relative;
|
|
500
505
|
width: 100%;
|
|
501
506
|
height: 100%;
|
|
502
|
-
min-height: 100vh;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
.taro-tabbar__container .taro_router {
|
|
506
|
-
min-height: calc(100vh - 50px);
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
.taro_page {
|
|
@@ -516,12 +516,18 @@ function loadRouterStyle(usingWindowScroll) {
|
|
|
516
516
|
`}
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
-
.taro-tabbar__container .taro-tabbar__panel {
|
|
519
|
+
.taro-tabbar__container > .taro-tabbar__panel {
|
|
520
520
|
overflow: hidden;
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
.taro-tabbar__container .taro_page.taro_tabbar_page {
|
|
524
|
-
max-height: calc(100vh -
|
|
523
|
+
.taro-tabbar__container > .taro-tabbar__panel > .taro_page.taro_tabbar_page {
|
|
524
|
+
max-height: calc(100vh - var(--taro-tabbar-height) - constant(safe-area-inset-bottom));
|
|
525
|
+
max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
.taro_page_shade,
|
|
529
|
+
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
|
|
530
|
+
display: none;
|
|
525
531
|
}
|
|
526
532
|
`;
|
|
527
533
|
addStyle(css);
|
|
@@ -789,11 +795,6 @@ function createMultiRouter(app, config, framework) {
|
|
|
789
795
|
}
|
|
790
796
|
|
|
791
797
|
/* eslint-disable dot-notation */
|
|
792
|
-
function setDisplay(el, type = '') {
|
|
793
|
-
if (el) {
|
|
794
|
-
el.style.display = type;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
798
|
class PageHandler {
|
|
798
799
|
constructor(config) {
|
|
799
800
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
@@ -959,7 +960,7 @@ class PageHandler {
|
|
|
959
960
|
const param = this.getQuery(stampId, '', page.options);
|
|
960
961
|
let pageEl = this.getPageContainer(page);
|
|
961
962
|
if (pageEl) {
|
|
962
|
-
|
|
963
|
+
pageEl.classList.remove('taro_page_shade');
|
|
963
964
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
964
965
|
this.addAnimation(pageEl, pageNo === 0);
|
|
965
966
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
@@ -1024,7 +1025,7 @@ class PageHandler {
|
|
|
1024
1025
|
const param = this.getQuery(page['$taroParams']['stamp'], '', page.options);
|
|
1025
1026
|
let pageEl = this.getPageContainer(page);
|
|
1026
1027
|
if (pageEl) {
|
|
1027
|
-
|
|
1028
|
+
pageEl.classList.remove('taro_page_shade');
|
|
1028
1029
|
this.addAnimation(pageEl, pageNo === 0);
|
|
1029
1030
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1030
1031
|
this.bindPageEvents(page, pageConfig);
|
|
@@ -1052,12 +1053,12 @@ class PageHandler {
|
|
|
1052
1053
|
if (this.hideTimer) {
|
|
1053
1054
|
clearTimeout(this.hideTimer);
|
|
1054
1055
|
this.hideTimer = null;
|
|
1055
|
-
|
|
1056
|
+
pageEl.classList.add('taro_page_shade');
|
|
1056
1057
|
}
|
|
1057
1058
|
this.lastHidePage = pageEl;
|
|
1058
1059
|
this.hideTimer = setTimeout(() => {
|
|
1059
1060
|
this.hideTimer = null;
|
|
1060
|
-
|
|
1061
|
+
pageEl.classList.add('taro_page_shade');
|
|
1061
1062
|
}, this.animationDuration + this.animationDelay);
|
|
1062
1063
|
(_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1063
1064
|
}
|