@tarojs/router 3.6.7-alpha.1 → 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 +135 -58
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +135 -58
- package/dist/index.esm.js.map +1 -1
- package/dist/router/multi-page.d.ts +3 -1
- package/dist/router/multi-page.js +27 -9
- package/dist/router/page.d.ts +3 -1
- package/dist/router/page.js +28 -12
- package/dist/router/spa.js +8 -6
- 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/index.esm.js
CHANGED
|
@@ -430,11 +430,11 @@ function bindPageResize(page) {
|
|
|
430
430
|
|
|
431
431
|
const pageScrollFn = {};
|
|
432
432
|
let pageDOM = window;
|
|
433
|
-
function bindPageScroll(page,
|
|
433
|
+
function bindPageScroll(page, scrollEl, distance = 50) {
|
|
434
434
|
var _a;
|
|
435
435
|
const pagePath = (page ? page === null || page === void 0 ? void 0 : page.path : (_a = Current.router) === null || _a === void 0 ? void 0 : _a.path);
|
|
436
|
-
pageScrollFn[pagePath] &&
|
|
437
|
-
pageDOM =
|
|
436
|
+
pageScrollFn[pagePath] && scrollEl.removeEventListener('scroll', pageScrollFn[pagePath]);
|
|
437
|
+
pageDOM = scrollEl;
|
|
438
438
|
let isReachBottom = false;
|
|
439
439
|
pageScrollFn[pagePath] = function () {
|
|
440
440
|
var _a;
|
|
@@ -462,6 +462,78 @@ function getOffset() {
|
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
+
/**
|
|
466
|
+
* 插入页面动画需要的样式
|
|
467
|
+
*/
|
|
468
|
+
function loadAnimateStyle(ms = 300) {
|
|
469
|
+
const css = `
|
|
470
|
+
.taro_router .taro_page {
|
|
471
|
+
position: absolute;
|
|
472
|
+
left: 0;
|
|
473
|
+
top: 0;
|
|
474
|
+
width: 100%;
|
|
475
|
+
height: 100%;
|
|
476
|
+
background-color: #fff;
|
|
477
|
+
transform: translate(100%, 0);
|
|
478
|
+
transition: transform ${ms}ms;
|
|
479
|
+
z-index: 0;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.taro_router .taro_page.taro_tabbar_page,
|
|
483
|
+
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
484
|
+
transform: none;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
.taro_router .taro_page.taro_page_show {
|
|
488
|
+
transform: translate(0, 0);
|
|
489
|
+
}`;
|
|
490
|
+
addStyle(css);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* 插入路由相关样式
|
|
494
|
+
*/
|
|
495
|
+
function loadRouterStyle(usingWindowScroll) {
|
|
496
|
+
const css = `
|
|
497
|
+
.taro_router {
|
|
498
|
+
overflow: hidden;
|
|
499
|
+
position: relative;
|
|
500
|
+
width: 100%;
|
|
501
|
+
height: 100%;
|
|
502
|
+
min-height: 100vh;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.taro-tabbar__container .taro_router {
|
|
506
|
+
min-height: calc(100vh - 50px);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.taro_page {
|
|
510
|
+
width: 100%;
|
|
511
|
+
height: 100%;
|
|
512
|
+
${usingWindowScroll ? '' : `
|
|
513
|
+
overflow-x: hidden;
|
|
514
|
+
overflow-y: scroll;
|
|
515
|
+
max-height: 100vh;
|
|
516
|
+
`}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.taro-tabbar__container .taro-tabbar__panel {
|
|
520
|
+
overflow: hidden;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
.taro-tabbar__container .taro_page.taro_tabbar_page {
|
|
524
|
+
max-height: calc(100vh - 50px);
|
|
525
|
+
}
|
|
526
|
+
`;
|
|
527
|
+
addStyle(css);
|
|
528
|
+
}
|
|
529
|
+
function addStyle(css) {
|
|
530
|
+
if (!css)
|
|
531
|
+
return;
|
|
532
|
+
const style = document.createElement('style');
|
|
533
|
+
style.innerHTML = css;
|
|
534
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
535
|
+
}
|
|
536
|
+
|
|
465
537
|
// @ts-nocheck
|
|
466
538
|
function initTabbar(config) {
|
|
467
539
|
if (config.tabBar == null) {
|
|
@@ -522,6 +594,17 @@ class MultiPageHandler {
|
|
|
522
594
|
return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath);
|
|
523
595
|
}
|
|
524
596
|
get search() { return location.search.substr(1); }
|
|
597
|
+
get usingWindowScroll() {
|
|
598
|
+
var _a;
|
|
599
|
+
let usingWindowScroll = true;
|
|
600
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
601
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
602
|
+
}
|
|
603
|
+
const win = window;
|
|
604
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
605
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
606
|
+
return usingWindowScroll;
|
|
607
|
+
}
|
|
525
608
|
getQuery(search = '', options = {}) {
|
|
526
609
|
search = search ? `${search}&${this.search}` : this.search;
|
|
527
610
|
const query = search
|
|
@@ -531,6 +614,7 @@ class MultiPageHandler {
|
|
|
531
614
|
}
|
|
532
615
|
mount() {
|
|
533
616
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
617
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
534
618
|
const appId = this.appId;
|
|
535
619
|
let app = document.getElementById(appId);
|
|
536
620
|
let isPosition = true;
|
|
@@ -590,11 +674,13 @@ class MultiPageHandler {
|
|
|
590
674
|
return;
|
|
591
675
|
(_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
|
|
592
676
|
var _a;
|
|
593
|
-
|
|
594
|
-
|
|
677
|
+
if (this.isTabBar) {
|
|
678
|
+
const pageEl = this.getPageContainer(page);
|
|
679
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
|
|
680
|
+
}
|
|
595
681
|
this.onReady(page, true);
|
|
596
682
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
597
|
-
this.bindPageEvents(page,
|
|
683
|
+
this.bindPageEvents(page, pageConfig);
|
|
598
684
|
});
|
|
599
685
|
}
|
|
600
686
|
getPageContainer(page) {
|
|
@@ -608,15 +694,18 @@ class MultiPageHandler {
|
|
|
608
694
|
? document.querySelector(`.taro_page#${id}`)
|
|
609
695
|
: document.querySelector('.taro_page') ||
|
|
610
696
|
document.querySelector('.taro_router'));
|
|
611
|
-
return el
|
|
697
|
+
return el;
|
|
698
|
+
}
|
|
699
|
+
getScrollingElement(page) {
|
|
700
|
+
if (this.usingWindowScroll)
|
|
701
|
+
return window;
|
|
702
|
+
return this.getPageContainer(page) || window;
|
|
612
703
|
}
|
|
613
|
-
bindPageEvents(page,
|
|
704
|
+
bindPageEvents(page, config = {}) {
|
|
614
705
|
var _a;
|
|
615
|
-
|
|
616
|
-
pageEl = this.getPageContainer();
|
|
617
|
-
}
|
|
706
|
+
const scrollEl = this.getScrollingElement(page);
|
|
618
707
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
619
|
-
bindPageScroll(page,
|
|
708
|
+
bindPageScroll(page, scrollEl, distance);
|
|
620
709
|
bindPageResize(page);
|
|
621
710
|
}
|
|
622
711
|
}
|
|
@@ -685,36 +774,6 @@ function createMultiRouter(app, config, framework) {
|
|
|
685
774
|
});
|
|
686
775
|
}
|
|
687
776
|
|
|
688
|
-
/**
|
|
689
|
-
* 插入页面动画需要的样式
|
|
690
|
-
*/
|
|
691
|
-
function loadAnimateStyle(ms = 300) {
|
|
692
|
-
const css = `
|
|
693
|
-
.taro_router .taro_page {
|
|
694
|
-
position: absolute;
|
|
695
|
-
left: 0;
|
|
696
|
-
top: 0;
|
|
697
|
-
width: 100%;
|
|
698
|
-
height: 100%;
|
|
699
|
-
background-color: #fff;
|
|
700
|
-
transform: translate(100%, 0);
|
|
701
|
-
transition: transform ${ms}ms;
|
|
702
|
-
z-index: 0;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
.taro_router .taro_page.taro_tabbar_page,
|
|
706
|
-
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
707
|
-
transform: none;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
.taro_router .taro_page.taro_page_show {
|
|
711
|
-
transform: translate(0, 0);
|
|
712
|
-
}`;
|
|
713
|
-
const style = document.createElement('style');
|
|
714
|
-
style.innerHTML = css;
|
|
715
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
777
|
/* eslint-disable dot-notation */
|
|
719
778
|
function setDisplay(el, type = '') {
|
|
720
779
|
if (el) {
|
|
@@ -800,6 +859,17 @@ class PageHandler {
|
|
|
800
859
|
}
|
|
801
860
|
return search.substring(1);
|
|
802
861
|
}
|
|
862
|
+
get usingWindowScroll() {
|
|
863
|
+
var _a;
|
|
864
|
+
let usingWindowScroll = false;
|
|
865
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
866
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
867
|
+
}
|
|
868
|
+
const win = window;
|
|
869
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
870
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
871
|
+
return usingWindowScroll;
|
|
872
|
+
}
|
|
803
873
|
getQuery(stamp = '', search = '', options = {}) {
|
|
804
874
|
search = search ? `${search}&${this.search}` : this.search;
|
|
805
875
|
const query = search
|
|
@@ -810,7 +880,9 @@ class PageHandler {
|
|
|
810
880
|
}
|
|
811
881
|
mount() {
|
|
812
882
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
883
|
+
this.pathname = history.location.pathname;
|
|
813
884
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
885
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
814
886
|
const appId = this.appId;
|
|
815
887
|
let app = document.getElementById(appId);
|
|
816
888
|
let isPosition = true;
|
|
@@ -877,7 +949,7 @@ class PageHandler {
|
|
|
877
949
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
878
950
|
this.addAnimation(pageEl, pageNo === 0);
|
|
879
951
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
880
|
-
this.bindPageEvents(page,
|
|
952
|
+
this.bindPageEvents(page, pageConfig);
|
|
881
953
|
this.triggerRouterChange();
|
|
882
954
|
}
|
|
883
955
|
else {
|
|
@@ -888,7 +960,7 @@ class PageHandler {
|
|
|
888
960
|
this.addAnimation(pageEl, pageNo === 0);
|
|
889
961
|
this.onReady(page, true);
|
|
890
962
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
891
|
-
this.bindPageEvents(page,
|
|
963
|
+
this.bindPageEvents(page, pageConfig);
|
|
892
964
|
this.triggerRouterChange();
|
|
893
965
|
});
|
|
894
966
|
}
|
|
@@ -937,7 +1009,7 @@ class PageHandler {
|
|
|
937
1009
|
setDisplay(pageEl);
|
|
938
1010
|
this.addAnimation(pageEl, pageNo === 0);
|
|
939
1011
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
940
|
-
this.bindPageEvents(page,
|
|
1012
|
+
this.bindPageEvents(page, pageConfig);
|
|
941
1013
|
this.triggerRouterChange();
|
|
942
1014
|
}
|
|
943
1015
|
else {
|
|
@@ -947,7 +1019,7 @@ class PageHandler {
|
|
|
947
1019
|
this.addAnimation(pageEl, pageNo === 0);
|
|
948
1020
|
this.onReady(page, false);
|
|
949
1021
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
950
|
-
this.bindPageEvents(page,
|
|
1022
|
+
this.bindPageEvents(page, pageConfig);
|
|
951
1023
|
this.triggerRouterChange();
|
|
952
1024
|
});
|
|
953
1025
|
}
|
|
@@ -1002,15 +1074,18 @@ class PageHandler {
|
|
|
1002
1074
|
? document.querySelector(`.taro_page#${id}`)
|
|
1003
1075
|
: document.querySelector('.taro_page') ||
|
|
1004
1076
|
document.querySelector('.taro_router'));
|
|
1005
|
-
return el
|
|
1077
|
+
return el;
|
|
1006
1078
|
}
|
|
1007
|
-
|
|
1079
|
+
getScrollingElement(page) {
|
|
1080
|
+
if (this.usingWindowScroll)
|
|
1081
|
+
return window;
|
|
1082
|
+
return this.getPageContainer(page) || window;
|
|
1083
|
+
}
|
|
1084
|
+
bindPageEvents(page, config = {}) {
|
|
1008
1085
|
var _a;
|
|
1009
|
-
|
|
1010
|
-
pageEl = this.getPageContainer();
|
|
1011
|
-
}
|
|
1086
|
+
const scrollEl = this.getScrollingElement(page);
|
|
1012
1087
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
1013
|
-
bindPageScroll(page,
|
|
1088
|
+
bindPageScroll(page, scrollEl, distance);
|
|
1014
1089
|
bindPageResize(page);
|
|
1015
1090
|
}
|
|
1016
1091
|
triggerRouterChange() {
|
|
@@ -1059,8 +1134,10 @@ function createRouter(app, config, framework) {
|
|
|
1059
1134
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1060
1135
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1061
1136
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
1062
|
-
var _c, _d, _e, _f, _g;
|
|
1137
|
+
var _c, _d, _e, _f, _g, _h;
|
|
1063
1138
|
handler.pathname = decodeURI(location.pathname);
|
|
1139
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1140
|
+
window.scrollTo(0, 0);
|
|
1064
1141
|
eventCenter.trigger('__taroRouterChange', {
|
|
1065
1142
|
toLocation: {
|
|
1066
1143
|
path: handler.pathname
|
|
@@ -1078,7 +1155,7 @@ function createRouter(app, config, framework) {
|
|
|
1078
1155
|
path: handler.pathname,
|
|
1079
1156
|
query: handler.getQuery(createStampId()),
|
|
1080
1157
|
};
|
|
1081
|
-
(
|
|
1158
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
1082
1159
|
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
1083
1160
|
}
|
|
1084
1161
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -1092,16 +1169,16 @@ function createRouter(app, config, framework) {
|
|
|
1092
1169
|
if (!element)
|
|
1093
1170
|
return;
|
|
1094
1171
|
const pageConfig = handler.pageConfig;
|
|
1095
|
-
let enablePullDownRefresh = ((
|
|
1172
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
1096
1173
|
if (pageConfig) {
|
|
1097
|
-
setTitle((
|
|
1174
|
+
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
1098
1175
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1099
1176
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1100
1177
|
}
|
|
1101
1178
|
}
|
|
1102
1179
|
const currentPage = Current.page;
|
|
1103
1180
|
const pathname = handler.pathname;
|
|
1104
|
-
const methodName = (
|
|
1181
|
+
const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
|
|
1105
1182
|
const cacheTabs = stacks.getTabs();
|
|
1106
1183
|
let shouldLoad = false;
|
|
1107
1184
|
stacks.method = '';
|
|
@@ -1165,7 +1242,7 @@ function createRouter(app, config, framework) {
|
|
|
1165
1242
|
shouldLoad = true;
|
|
1166
1243
|
}
|
|
1167
1244
|
if (shouldLoad || stacks.length < 1) {
|
|
1168
|
-
const el = (
|
|
1245
|
+
const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
|
|
1169
1246
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1170
1247
|
const stacksIndex = stacks.length;
|
|
1171
1248
|
delete loadConfig['path'];
|