@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/events/scroll.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
-
export declare function bindPageScroll(page: PageInstance,
|
|
2
|
+
export declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
|
package/dist/events/scroll.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Current } from '@tarojs/runtime';
|
|
2
2
|
const pageScrollFn = {};
|
|
3
3
|
let pageDOM = window;
|
|
4
|
-
export function bindPageScroll(page,
|
|
4
|
+
export function bindPageScroll(page, scrollEl, distance = 50) {
|
|
5
5
|
var _a;
|
|
6
6
|
const pagePath = (page ? page === null || page === void 0 ? void 0 : page.path : (_a = Current.router) === null || _a === void 0 ? void 0 : _a.path);
|
|
7
|
-
pageScrollFn[pagePath] &&
|
|
8
|
-
pageDOM =
|
|
7
|
+
pageScrollFn[pagePath] && scrollEl.removeEventListener('scroll', pageScrollFn[pagePath]);
|
|
8
|
+
pageDOM = scrollEl;
|
|
9
9
|
let isReachBottom = false;
|
|
10
10
|
pageScrollFn[pagePath] = function () {
|
|
11
11
|
var _a;
|
package/dist/index.cjs.js
CHANGED
|
@@ -440,11 +440,11 @@ function bindPageResize(page) {
|
|
|
440
440
|
|
|
441
441
|
const pageScrollFn = {};
|
|
442
442
|
let pageDOM = window;
|
|
443
|
-
function bindPageScroll(page,
|
|
443
|
+
function bindPageScroll(page, scrollEl, distance = 50) {
|
|
444
444
|
var _a;
|
|
445
445
|
const pagePath = (page ? page === null || page === void 0 ? void 0 : page.path : (_a = runtime.Current.router) === null || _a === void 0 ? void 0 : _a.path);
|
|
446
|
-
pageScrollFn[pagePath] &&
|
|
447
|
-
pageDOM =
|
|
446
|
+
pageScrollFn[pagePath] && scrollEl.removeEventListener('scroll', pageScrollFn[pagePath]);
|
|
447
|
+
pageDOM = scrollEl;
|
|
448
448
|
let isReachBottom = false;
|
|
449
449
|
pageScrollFn[pagePath] = function () {
|
|
450
450
|
var _a;
|
|
@@ -472,6 +472,78 @@ function getOffset() {
|
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
/**
|
|
476
|
+
* 插入页面动画需要的样式
|
|
477
|
+
*/
|
|
478
|
+
function loadAnimateStyle(ms = 300) {
|
|
479
|
+
const css = `
|
|
480
|
+
.taro_router .taro_page {
|
|
481
|
+
position: absolute;
|
|
482
|
+
left: 0;
|
|
483
|
+
top: 0;
|
|
484
|
+
width: 100%;
|
|
485
|
+
height: 100%;
|
|
486
|
+
background-color: #fff;
|
|
487
|
+
transform: translate(100%, 0);
|
|
488
|
+
transition: transform ${ms}ms;
|
|
489
|
+
z-index: 0;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
.taro_router .taro_page.taro_tabbar_page,
|
|
493
|
+
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
494
|
+
transform: none;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.taro_router .taro_page.taro_page_show {
|
|
498
|
+
transform: translate(0, 0);
|
|
499
|
+
}`;
|
|
500
|
+
addStyle(css);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* 插入路由相关样式
|
|
504
|
+
*/
|
|
505
|
+
function loadRouterStyle(usingWindowScroll) {
|
|
506
|
+
const css = `
|
|
507
|
+
.taro_router {
|
|
508
|
+
overflow: hidden;
|
|
509
|
+
position: relative;
|
|
510
|
+
width: 100%;
|
|
511
|
+
height: 100%;
|
|
512
|
+
min-height: 100vh;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.taro-tabbar__container .taro_router {
|
|
516
|
+
min-height: calc(100vh - 50px);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.taro_page {
|
|
520
|
+
width: 100%;
|
|
521
|
+
height: 100%;
|
|
522
|
+
${usingWindowScroll ? '' : `
|
|
523
|
+
overflow-x: hidden;
|
|
524
|
+
overflow-y: scroll;
|
|
525
|
+
max-height: 100vh;
|
|
526
|
+
`}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.taro-tabbar__container .taro-tabbar__panel {
|
|
530
|
+
overflow: hidden;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
.taro-tabbar__container .taro_page.taro_tabbar_page {
|
|
534
|
+
max-height: calc(100vh - 50px);
|
|
535
|
+
}
|
|
536
|
+
`;
|
|
537
|
+
addStyle(css);
|
|
538
|
+
}
|
|
539
|
+
function addStyle(css) {
|
|
540
|
+
if (!css)
|
|
541
|
+
return;
|
|
542
|
+
const style = document.createElement('style');
|
|
543
|
+
style.innerHTML = css;
|
|
544
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
545
|
+
}
|
|
546
|
+
|
|
475
547
|
// @ts-nocheck
|
|
476
548
|
function initTabbar(config) {
|
|
477
549
|
if (config.tabBar == null) {
|
|
@@ -532,6 +604,17 @@ class MultiPageHandler {
|
|
|
532
604
|
return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath);
|
|
533
605
|
}
|
|
534
606
|
get search() { return location.search.substr(1); }
|
|
607
|
+
get usingWindowScroll() {
|
|
608
|
+
var _a;
|
|
609
|
+
let usingWindowScroll = true;
|
|
610
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
611
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
612
|
+
}
|
|
613
|
+
const win = window;
|
|
614
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
615
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
616
|
+
return usingWindowScroll;
|
|
617
|
+
}
|
|
535
618
|
getQuery(search = '', options = {}) {
|
|
536
619
|
search = search ? `${search}&${this.search}` : this.search;
|
|
537
620
|
const query = search
|
|
@@ -541,6 +624,7 @@ class MultiPageHandler {
|
|
|
541
624
|
}
|
|
542
625
|
mount() {
|
|
543
626
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
627
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
544
628
|
const appId = this.appId;
|
|
545
629
|
let app = document.getElementById(appId);
|
|
546
630
|
let isPosition = true;
|
|
@@ -600,11 +684,13 @@ class MultiPageHandler {
|
|
|
600
684
|
return;
|
|
601
685
|
(_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
|
|
602
686
|
var _a;
|
|
603
|
-
|
|
604
|
-
|
|
687
|
+
if (this.isTabBar) {
|
|
688
|
+
const pageEl = this.getPageContainer(page);
|
|
689
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
|
|
690
|
+
}
|
|
605
691
|
this.onReady(page, true);
|
|
606
692
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
607
|
-
this.bindPageEvents(page,
|
|
693
|
+
this.bindPageEvents(page, pageConfig);
|
|
608
694
|
});
|
|
609
695
|
}
|
|
610
696
|
getPageContainer(page) {
|
|
@@ -618,15 +704,18 @@ class MultiPageHandler {
|
|
|
618
704
|
? document.querySelector(`.taro_page#${id}`)
|
|
619
705
|
: document.querySelector('.taro_page') ||
|
|
620
706
|
document.querySelector('.taro_router'));
|
|
621
|
-
return el
|
|
707
|
+
return el;
|
|
708
|
+
}
|
|
709
|
+
getScrollingElement(page) {
|
|
710
|
+
if (this.usingWindowScroll)
|
|
711
|
+
return window;
|
|
712
|
+
return this.getPageContainer(page) || window;
|
|
622
713
|
}
|
|
623
|
-
bindPageEvents(page,
|
|
714
|
+
bindPageEvents(page, config = {}) {
|
|
624
715
|
var _a;
|
|
625
|
-
|
|
626
|
-
pageEl = this.getPageContainer();
|
|
627
|
-
}
|
|
716
|
+
const scrollEl = this.getScrollingElement(page);
|
|
628
717
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
629
|
-
bindPageScroll(page,
|
|
718
|
+
bindPageScroll(page, scrollEl, distance);
|
|
630
719
|
bindPageResize(page);
|
|
631
720
|
}
|
|
632
721
|
}
|
|
@@ -695,36 +784,6 @@ function createMultiRouter(app, config, framework) {
|
|
|
695
784
|
});
|
|
696
785
|
}
|
|
697
786
|
|
|
698
|
-
/**
|
|
699
|
-
* 插入页面动画需要的样式
|
|
700
|
-
*/
|
|
701
|
-
function loadAnimateStyle(ms = 300) {
|
|
702
|
-
const css = `
|
|
703
|
-
.taro_router .taro_page {
|
|
704
|
-
position: absolute;
|
|
705
|
-
left: 0;
|
|
706
|
-
top: 0;
|
|
707
|
-
width: 100%;
|
|
708
|
-
height: 100%;
|
|
709
|
-
background-color: #fff;
|
|
710
|
-
transform: translate(100%, 0);
|
|
711
|
-
transition: transform ${ms}ms;
|
|
712
|
-
z-index: 0;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
.taro_router .taro_page.taro_tabbar_page,
|
|
716
|
-
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
717
|
-
transform: none;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
.taro_router .taro_page.taro_page_show {
|
|
721
|
-
transform: translate(0, 0);
|
|
722
|
-
}`;
|
|
723
|
-
const style = document.createElement('style');
|
|
724
|
-
style.innerHTML = css;
|
|
725
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
787
|
/* eslint-disable dot-notation */
|
|
729
788
|
function setDisplay(el, type = '') {
|
|
730
789
|
if (el) {
|
|
@@ -810,6 +869,17 @@ class PageHandler {
|
|
|
810
869
|
}
|
|
811
870
|
return search.substring(1);
|
|
812
871
|
}
|
|
872
|
+
get usingWindowScroll() {
|
|
873
|
+
var _a;
|
|
874
|
+
let usingWindowScroll = false;
|
|
875
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
876
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
877
|
+
}
|
|
878
|
+
const win = window;
|
|
879
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
880
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
881
|
+
return usingWindowScroll;
|
|
882
|
+
}
|
|
813
883
|
getQuery(stamp = '', search = '', options = {}) {
|
|
814
884
|
search = search ? `${search}&${this.search}` : this.search;
|
|
815
885
|
const query = search
|
|
@@ -820,7 +890,9 @@ class PageHandler {
|
|
|
820
890
|
}
|
|
821
891
|
mount() {
|
|
822
892
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
893
|
+
this.pathname = exports.history.location.pathname;
|
|
823
894
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
895
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
824
896
|
const appId = this.appId;
|
|
825
897
|
let app = document.getElementById(appId);
|
|
826
898
|
let isPosition = true;
|
|
@@ -887,7 +959,7 @@ class PageHandler {
|
|
|
887
959
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
888
960
|
this.addAnimation(pageEl, pageNo === 0);
|
|
889
961
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
890
|
-
this.bindPageEvents(page,
|
|
962
|
+
this.bindPageEvents(page, pageConfig);
|
|
891
963
|
this.triggerRouterChange();
|
|
892
964
|
}
|
|
893
965
|
else {
|
|
@@ -898,7 +970,7 @@ class PageHandler {
|
|
|
898
970
|
this.addAnimation(pageEl, pageNo === 0);
|
|
899
971
|
this.onReady(page, true);
|
|
900
972
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
901
|
-
this.bindPageEvents(page,
|
|
973
|
+
this.bindPageEvents(page, pageConfig);
|
|
902
974
|
this.triggerRouterChange();
|
|
903
975
|
});
|
|
904
976
|
}
|
|
@@ -947,7 +1019,7 @@ class PageHandler {
|
|
|
947
1019
|
setDisplay(pageEl);
|
|
948
1020
|
this.addAnimation(pageEl, pageNo === 0);
|
|
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
|
else {
|
|
@@ -957,7 +1029,7 @@ class PageHandler {
|
|
|
957
1029
|
this.addAnimation(pageEl, pageNo === 0);
|
|
958
1030
|
this.onReady(page, false);
|
|
959
1031
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
960
|
-
this.bindPageEvents(page,
|
|
1032
|
+
this.bindPageEvents(page, pageConfig);
|
|
961
1033
|
this.triggerRouterChange();
|
|
962
1034
|
});
|
|
963
1035
|
}
|
|
@@ -1012,15 +1084,18 @@ class PageHandler {
|
|
|
1012
1084
|
? document.querySelector(`.taro_page#${id}`)
|
|
1013
1085
|
: document.querySelector('.taro_page') ||
|
|
1014
1086
|
document.querySelector('.taro_router'));
|
|
1015
|
-
return el
|
|
1087
|
+
return el;
|
|
1016
1088
|
}
|
|
1017
|
-
|
|
1089
|
+
getScrollingElement(page) {
|
|
1090
|
+
if (this.usingWindowScroll)
|
|
1091
|
+
return window;
|
|
1092
|
+
return this.getPageContainer(page) || window;
|
|
1093
|
+
}
|
|
1094
|
+
bindPageEvents(page, config = {}) {
|
|
1018
1095
|
var _a;
|
|
1019
|
-
|
|
1020
|
-
pageEl = this.getPageContainer();
|
|
1021
|
-
}
|
|
1096
|
+
const scrollEl = this.getScrollingElement(page);
|
|
1022
1097
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
1023
|
-
bindPageScroll(page,
|
|
1098
|
+
bindPageScroll(page, scrollEl, distance);
|
|
1024
1099
|
bindPageResize(page);
|
|
1025
1100
|
}
|
|
1026
1101
|
triggerRouterChange() {
|
|
@@ -1069,8 +1144,10 @@ function createRouter(app, config, framework) {
|
|
|
1069
1144
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1070
1145
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1071
1146
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
1072
|
-
var _c, _d, _e, _f, _g;
|
|
1147
|
+
var _c, _d, _e, _f, _g, _h;
|
|
1073
1148
|
handler.pathname = decodeURI(location.pathname);
|
|
1149
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1150
|
+
window.scrollTo(0, 0);
|
|
1074
1151
|
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
1075
1152
|
toLocation: {
|
|
1076
1153
|
path: handler.pathname
|
|
@@ -1088,7 +1165,7 @@ function createRouter(app, config, framework) {
|
|
|
1088
1165
|
path: handler.pathname,
|
|
1089
1166
|
query: handler.getQuery(createStampId()),
|
|
1090
1167
|
};
|
|
1091
|
-
(
|
|
1168
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
1092
1169
|
runtime.eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
1093
1170
|
}
|
|
1094
1171
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -1102,16 +1179,16 @@ function createRouter(app, config, framework) {
|
|
|
1102
1179
|
if (!element)
|
|
1103
1180
|
return;
|
|
1104
1181
|
const pageConfig = handler.pageConfig;
|
|
1105
|
-
let enablePullDownRefresh = ((
|
|
1182
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
1106
1183
|
if (pageConfig) {
|
|
1107
|
-
setTitle((
|
|
1184
|
+
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
1108
1185
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1109
1186
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1110
1187
|
}
|
|
1111
1188
|
}
|
|
1112
1189
|
const currentPage = runtime.Current.page;
|
|
1113
1190
|
const pathname = handler.pathname;
|
|
1114
|
-
const methodName = (
|
|
1191
|
+
const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
|
|
1115
1192
|
const cacheTabs = stacks.getTabs();
|
|
1116
1193
|
let shouldLoad = false;
|
|
1117
1194
|
stacks.method = '';
|
|
@@ -1175,7 +1252,7 @@ function createRouter(app, config, framework) {
|
|
|
1175
1252
|
shouldLoad = true;
|
|
1176
1253
|
}
|
|
1177
1254
|
if (shouldLoad || stacks.length < 1) {
|
|
1178
|
-
const el = (
|
|
1255
|
+
const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
|
|
1179
1256
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1180
1257
|
const stacksIndex = stacks.length;
|
|
1181
1258
|
delete loadConfig['path'];
|