@tarojs/router 3.3.12 → 3.3.16
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/index.js +253 -206
- package/dist/index.js.map +1 -1
- package/dist/router.esm.js +245 -204
- package/dist/router.esm.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -27,14 +27,14 @@ function _extends() {
|
|
|
27
27
|
var r,B=r||(r={});B.Pop="POP";B.Push="PUSH";B.Replace="REPLACE";var C="production"!==process.env.NODE_ENV?function(b){return Object.freeze(b)}:function(b){return b};function D(b,h){if(!b){"undefined"!==typeof console&&console.warn(h);try{throw Error(h);}catch(k){}}}function E(b){b.preventDefault();b.returnValue="";}
|
|
28
28
|
function F(){var b=[];return {get length(){return b.length},push:function(h){b.push(h);return function(){b=b.filter(function(k){return k!==h});}},call:function(h){b.forEach(function(k){return k&&k(h)});}}}function H(){return Math.random().toString(36).substr(2,8)}function I(b){var h=b.pathname,k=b.search;b=b.hash;return (void 0===h?"/":h)+(void 0===k?"":k)+(void 0===b?"":b)}
|
|
29
29
|
function J(b){var h={};if(b){var k=b.indexOf("#");0<=k&&(h.hash=b.substr(k),b=b.substr(0,k));k=b.indexOf("?");0<=k&&(h.search=b.substr(k),b=b.substr(0,k));b&&(h.pathname=b);}return h}
|
|
30
|
-
function createBrowserHistory(b){function h(){var c=p.location,a=m.state||{};return [a.idx,C({pathname:c.pathname,search:c.search,hash:c.hash,state:a.usr||null,key:a.key||"default"})]}function k(c){return "string"===typeof c?c:I(c)}function x(c,a){void 0===a&&(a=null);return C(_extends({
|
|
31
|
-
location:g,retry:e}),!1)){var n=[{usr:g.state,key:g.key,idx:v+1},k(g)];g=n[0];n=n[1];try{m.pushState(g,"",n);}catch(G){p.location.assign(n);}z(l);}}function y(c,a){function e(){y(c,a);}var l=r.Replace,g=x(c,a);f.length&&(f.call({action:l,location:g,retry:e}),1)||(g=[{usr:g.state,key:g.key,idx:v},k(g)],m.replaceState(g[0],"",g[1]),z(l));}function w(c){m.go(c);}void 0===b&&(b={});b=b.window;var p=void 0===b?document.defaultView:b,m=p.history,u=null;p.addEventListener("popstate",
|
|
32
|
-
u=null; }else {var c=r.Pop,a=h(),e=a[0];a=a[1];if(f.length){ if(null!=e){var l=v-e;l&&(u={action:c,location:a,retry:function(){w(-1*l);}},w(l));}else { "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
|
|
33
|
-
r.Pop;b=h();var v=b[0],q=b[1],d=F(),f=F();null==v&&(v=0,m.replaceState(_extends({},m.state,{idx:v}),""));return {get action(){return t},get location(){return q},createHref:k,push:A,replace:y,go:w,back:function(){w(-1);},forward:function(){w(1);},listen:function(c){return d.push(c)},block:function(c){var a=f.push(c);1===f.length&&p.addEventListener("beforeunload",E);return function(){a();f.length||p.removeEventListener("beforeunload",E);}}}}function createHashHistory(b){function h(){var a=J(m.location.hash.substr(1)),e=a.pathname,l=a.search;a=a.hash;var g=u.state||{};return [g.idx,C({pathname:void 0===e?"/":e,search:void 0===l?"":l,hash:void 0===a?"":a,state:g.usr||null,key:g.key||"default"})]}function k(){if(t){ c.call(t),t=null; }else {var a=r.Pop,e=h(),l=e[0];e=e[1];if(c.length){ if(null!=l){var g=q-l;g&&(t={action:a,location:e,retry:function(){p(-1*g);}},p(g));}else { "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
|
|
34
|
-
void 0; } }else { A(a); }}}function x(a){var e=document.querySelector("base"),l="";e&&e.getAttribute("href")&&(e=m.location.href,l=e.indexOf("#"),l=-1===l?e:e.slice(0,l));return l+"#"+("string"===typeof a?a:I(a))}function z(a,e){void 0===e&&(e=null);return C(_extends({
|
|
35
|
-
"Relative pathnames are not supported in hash history.push("+JSON.stringify(a)+")"):void 0;if(!c.length||(c.call({action:g,location:n,retry:l}),!1)){var G=[{usr:n.state,key:n.key,idx:q+1},x(n)];n=G[0];G=G[1];try{u.pushState(n,"",G);}catch(K){m.location.assign(G);}A(g);}}function w(a,e){function l(){w(a,e);}var g=r.Replace,n=z(a,e);"production"!==process.env.NODE_ENV?D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.replace("+JSON.stringify(a)+
|
|
36
|
-
location:n,retry:l}),1)||(n=[{usr:n.state,key:n.key,idx:q},x(n)],u.replaceState(n[0],"",n[1]),A(g));}function p(a){u.go(a);}void 0===b&&(b={});b=b.window;var m=void 0===b?document.defaultView:b,u=m.history,t=null;m.addEventListener("popstate",k);m.addEventListener("hashchange",function(){var a=h()[1];I(a)!==I(d)&&k();});var v=r.Pop;b=h();var q=b[0],d=b[1],f=F(),c=F();null==q&&(q=0,u.replaceState(_extends({},u.state,{idx:q}),""));return {get action(){return v},get location(){return d},
|
|
37
|
-
replace:w,go:p,back:function(){p(-1);},forward:function(){p(1);},listen:function(a){return f.push(a)},block:function(a){var e=c.push(a);1===c.length&&m.addEventListener("beforeunload",E);return function(){e();c.length||m.removeEventListener("beforeunload",E);}}}}
|
|
30
|
+
function createBrowserHistory(b){function h(){var c=p.location,a=m.state||{};return [a.idx,C({pathname:c.pathname,search:c.search,hash:c.hash,state:a.usr||null,key:a.key||"default"})]}function k(c){return "string"===typeof c?c:I(c)}function x(c,a){void 0===a&&(a=null);return C(_extends({pathname:q.pathname,hash:"",search:""},"string"===typeof c?J(c):c,{state:a,key:H()}))}function z(c){t=c;c=h();v=c[0];q=c[1];d.call({action:t,location:q});}function A(c,a){function e(){A(c,a);}var l=r.Push,g=x(c,
|
|
31
|
+
a);if(!f.length||(f.call({action:l,location:g,retry:e}),!1)){var n=[{usr:g.state,key:g.key,idx:v+1},k(g)];g=n[0];n=n[1];try{m.pushState(g,"",n);}catch(G){p.location.assign(n);}z(l);}}function y(c,a){function e(){y(c,a);}var l=r.Replace,g=x(c,a);f.length&&(f.call({action:l,location:g,retry:e}),1)||(g=[{usr:g.state,key:g.key,idx:v},k(g)],m.replaceState(g[0],"",g[1]),z(l));}function w(c){m.go(c);}void 0===b&&(b={});b=b.window;var p=void 0===b?document.defaultView:b,m=p.history,u=null;p.addEventListener("popstate",
|
|
32
|
+
function(){if(u){ f.call(u),u=null; }else {var c=r.Pop,a=h(),e=a[0];a=a[1];if(f.length){ if(null!=e){var l=v-e;l&&(u={action:c,location:a,retry:function(){w(-1*l);}},w(l));}else { "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
|
|
33
|
+
void 0; } }else { z(c); }}});var t=r.Pop;b=h();var v=b[0],q=b[1],d=F(),f=F();null==v&&(v=0,m.replaceState(_extends({},m.state,{idx:v}),""));return {get action(){return t},get location(){return q},createHref:k,push:A,replace:y,go:w,back:function(){w(-1);},forward:function(){w(1);},listen:function(c){return d.push(c)},block:function(c){var a=f.push(c);1===f.length&&p.addEventListener("beforeunload",E);return function(){a();f.length||p.removeEventListener("beforeunload",E);}}}}function createHashHistory(b){function h(){var a=J(m.location.hash.substr(1)),e=a.pathname,l=a.search;a=a.hash;var g=u.state||{};return [g.idx,C({pathname:void 0===e?"/":e,search:void 0===l?"":l,hash:void 0===a?"":a,state:g.usr||null,key:g.key||"default"})]}function k(){if(t){ c.call(t),t=null; }else {var a=r.Pop,e=h(),l=e[0];e=e[1];if(c.length){ if(null!=l){var g=q-l;g&&(t={action:a,location:e,retry:function(){p(-1*g);}},p(g));}else { "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
|
|
34
|
+
void 0; } }else { A(a); }}}function x(a){var e=document.querySelector("base"),l="";e&&e.getAttribute("href")&&(e=m.location.href,l=e.indexOf("#"),l=-1===l?e:e.slice(0,l));return l+"#"+("string"===typeof a?a:I(a))}function z(a,e){void 0===e&&(e=null);return C(_extends({pathname:d.pathname,hash:"",search:""},"string"===typeof a?J(a):a,{state:e,key:H()}))}function A(a){v=a;a=h();q=a[0];d=a[1];f.call({action:v,location:d});}function y(a,e){function l(){y(a,e);}var g=r.Push,n=z(a,e);"production"!==process.env.NODE_ENV?
|
|
35
|
+
D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.push("+JSON.stringify(a)+")"):void 0;if(!c.length||(c.call({action:g,location:n,retry:l}),!1)){var G=[{usr:n.state,key:n.key,idx:q+1},x(n)];n=G[0];G=G[1];try{u.pushState(n,"",G);}catch(K){m.location.assign(G);}A(g);}}function w(a,e){function l(){w(a,e);}var g=r.Replace,n=z(a,e);"production"!==process.env.NODE_ENV?D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.replace("+JSON.stringify(a)+
|
|
36
|
+
")"):void 0;c.length&&(c.call({action:g,location:n,retry:l}),1)||(n=[{usr:n.state,key:n.key,idx:q},x(n)],u.replaceState(n[0],"",n[1]),A(g));}function p(a){u.go(a);}void 0===b&&(b={});b=b.window;var m=void 0===b?document.defaultView:b,u=m.history,t=null;m.addEventListener("popstate",k);m.addEventListener("hashchange",function(){var a=h()[1];I(a)!==I(d)&&k();});var v=r.Pop;b=h();var q=b[0],d=b[1],f=F(),c=F();null==q&&(q=0,u.replaceState(_extends({},u.state,{idx:q}),""));return {get action(){return v},get location(){return d},
|
|
37
|
+
createHref:x,push:y,replace:w,go:p,back:function(){p(-1);},forward:function(){p(1);},listen:function(a){return f.push(a)},block:function(a){var e=c.push(a);1===c.length&&m.addEventListener("beforeunload",E);return function(){e();c.length||m.removeEventListener("beforeunload",E);}}}}
|
|
38
38
|
|
|
39
39
|
var basename = '/';
|
|
40
40
|
function setHistoryMode(mode, base) {
|
|
@@ -56,9 +56,63 @@ function prependBasename(url) {
|
|
|
56
56
|
if ( url === void 0 ) url = '';
|
|
57
57
|
|
|
58
58
|
return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
|
|
59
|
-
}
|
|
59
|
+
}
|
|
60
|
+
var hasBasename = function (path, prefix) { return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path); };
|
|
61
|
+
var stripBasename = function (path, prefix) { return hasBasename(path, prefix) ? path.substr(prefix.length) : path; };
|
|
62
|
+
|
|
63
|
+
var Stacks = function Stacks() {
|
|
64
|
+
this.stacks = [];
|
|
65
|
+
this.backDelta = 0;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var prototypeAccessors = { delta: { configurable: true },length: { configurable: true },last: { configurable: true } };
|
|
69
|
+
prototypeAccessors.delta.set = function (delta) {
|
|
70
|
+
if (delta > 0) {
|
|
71
|
+
this.backDelta = delta;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
--this.backDelta;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
prototypeAccessors.length.get = function () {
|
|
78
|
+
return this.stacks.length;
|
|
79
|
+
};
|
|
80
|
+
prototypeAccessors.last.get = function () {
|
|
81
|
+
return this.stacks[this.length - 1];
|
|
82
|
+
};
|
|
83
|
+
Stacks.prototype.get = function get () {
|
|
84
|
+
return this.stacks;
|
|
85
|
+
};
|
|
86
|
+
Stacks.prototype.getItem = function getItem (index) {
|
|
87
|
+
return this.stacks[index];
|
|
88
|
+
};
|
|
89
|
+
Stacks.prototype.getLastIndex = function getLastIndex (pathname) {
|
|
90
|
+
var list = [].concat( this.stacks ).reverse();
|
|
91
|
+
return list.findIndex(function (page) { var _a; return ((_a = page.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname; });
|
|
92
|
+
};
|
|
93
|
+
Stacks.prototype.getDelta = function getDelta (pathname) {
|
|
94
|
+
if (this.backDelta >= 1) {
|
|
95
|
+
return this.backDelta;
|
|
96
|
+
}
|
|
97
|
+
// NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
|
|
98
|
+
return this.getLastIndex(pathname) || 1;
|
|
99
|
+
};
|
|
100
|
+
Stacks.prototype.getPrevIndex = function getPrevIndex (pathname) {
|
|
101
|
+
var lastIndex = this.getLastIndex(pathname);
|
|
102
|
+
if (lastIndex < 0) {
|
|
103
|
+
return -1;
|
|
104
|
+
}
|
|
105
|
+
return this.length - 1 - lastIndex;
|
|
106
|
+
};
|
|
107
|
+
Stacks.prototype.pop = function pop () {
|
|
108
|
+
return this.stacks.pop();
|
|
109
|
+
};
|
|
110
|
+
Stacks.prototype.push = function push (page) {
|
|
111
|
+
return this.stacks.push(page);
|
|
112
|
+
};
|
|
60
113
|
|
|
61
|
-
|
|
114
|
+
Object.defineProperties( Stacks.prototype, prototypeAccessors );
|
|
115
|
+
var stacks = new Stacks();
|
|
62
116
|
|
|
63
117
|
var routesAlias = {};
|
|
64
118
|
function setRoutesAlias(alias) {
|
|
@@ -70,25 +124,6 @@ function addLeadingSlash(path) {
|
|
|
70
124
|
}
|
|
71
125
|
return path.charAt(0) === '/' ? path : '/' + path;
|
|
72
126
|
}
|
|
73
|
-
// 解决navigateBack调用delta>1时,路由栈异常问题
|
|
74
|
-
// 比如:A->B->C,navigateBack({delta: 2}),此时路由栈中还存在B页面
|
|
75
|
-
// 原因:主要是由于一次性退出多层级页面时,此action只会执行一次,此处进行手动处理
|
|
76
|
-
var historyBackDelta = 1;
|
|
77
|
-
function setHistoryBackDelta(delta) {
|
|
78
|
-
historyBackDelta = delta;
|
|
79
|
-
}
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
81
|
-
var throttle = function (fn, threshold) {
|
|
82
|
-
var lastTime = 0;
|
|
83
|
-
return function () {
|
|
84
|
-
var now = Date.now();
|
|
85
|
-
if (now - lastTime > threshold) {
|
|
86
|
-
fn.apply(this, arguments);
|
|
87
|
-
lastTime = now;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
var stripBasename = function (path, basename) { return path.startsWith(basename) ? path.replace(basename, '') : path; };
|
|
92
127
|
var isTabBar = function (config) {
|
|
93
128
|
var _a, _b;
|
|
94
129
|
var ref = config.router;
|
|
@@ -105,6 +140,7 @@ var isTabBar = function (config) {
|
|
|
105
140
|
};
|
|
106
141
|
|
|
107
142
|
function processNavigateUrl(option) {
|
|
143
|
+
var _a;
|
|
108
144
|
var pathPieces = J(option.url);
|
|
109
145
|
// 处理自定义路由
|
|
110
146
|
Object.keys(routesAlias).forEach(function (key) {
|
|
@@ -112,6 +148,18 @@ function processNavigateUrl(option) {
|
|
|
112
148
|
pathPieces.pathname = routesAlias[key];
|
|
113
149
|
}
|
|
114
150
|
});
|
|
151
|
+
// 处理相对路径
|
|
152
|
+
if ((_a = pathPieces === null || pathPieces === void 0 ? void 0 : pathPieces.pathname) === null || _a === void 0 ? void 0 : _a.includes('./')) {
|
|
153
|
+
var parts = exports.history.location.pathname.split('/');
|
|
154
|
+
parts.pop();
|
|
155
|
+
pathPieces.pathname.split('/').forEach(function (item) {
|
|
156
|
+
if (item === '.') {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
item === '..' ? parts.pop() : parts.push(item);
|
|
160
|
+
});
|
|
161
|
+
pathPieces.pathname = parts.join('/');
|
|
162
|
+
}
|
|
115
163
|
// 处理 basename
|
|
116
164
|
pathPieces.pathname = prependBasename(pathPieces.pathname);
|
|
117
165
|
// hack fix history v5 bug: https://github.com/remix-run/history/issues/814
|
|
@@ -119,43 +167,38 @@ function processNavigateUrl(option) {
|
|
|
119
167
|
{ pathPieces.search = ''; }
|
|
120
168
|
return pathPieces;
|
|
121
169
|
}
|
|
122
|
-
function navigate(option, method) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
170
|
+
async function navigate(option, method) {
|
|
171
|
+
return new Promise(function (resolve, reject) {
|
|
172
|
+
var success = option.success;
|
|
173
|
+
var complete = option.complete;
|
|
174
|
+
var fail = option.fail;
|
|
175
|
+
var unListen = exports.history.listen(function () {
|
|
176
|
+
success === null || success === void 0 ? void 0 : success();
|
|
177
|
+
complete === null || complete === void 0 ? void 0 : complete();
|
|
178
|
+
resolve();
|
|
179
|
+
unListen();
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
if ('url' in option) {
|
|
183
|
+
var pathPieces = processNavigateUrl(option);
|
|
184
|
+
var state = { timestamp: Date.now() };
|
|
185
|
+
if (method === 'navigateTo') {
|
|
186
|
+
exports.history.push(pathPieces, state);
|
|
187
|
+
}
|
|
188
|
+
else if (method === 'redirectTo') {
|
|
189
|
+
exports.history.replace(pathPieces, state);
|
|
190
|
+
}
|
|
133
191
|
}
|
|
134
|
-
else if (method === '
|
|
135
|
-
|
|
192
|
+
else if (method === 'navigateBack') {
|
|
193
|
+
stacks.delta = option.delta;
|
|
194
|
+
exports.history.go(-option.delta);
|
|
136
195
|
}
|
|
137
196
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
failReason = error;
|
|
145
|
-
}
|
|
146
|
-
return new Promise(function (resolve, reject) {
|
|
147
|
-
if (failReason) {
|
|
148
|
-
fail && fail(failReason);
|
|
149
|
-
complete && complete();
|
|
150
|
-
reject(failReason);
|
|
151
|
-
return;
|
|
197
|
+
catch (error) {
|
|
198
|
+
fail === null || fail === void 0 ? void 0 : fail(error);
|
|
199
|
+
complete === null || complete === void 0 ? void 0 : complete();
|
|
200
|
+
reject(error);
|
|
152
201
|
}
|
|
153
|
-
var unlisten = exports.history.listen(function () {
|
|
154
|
-
success && success();
|
|
155
|
-
complete && complete();
|
|
156
|
-
resolve();
|
|
157
|
-
unlisten();
|
|
158
|
-
});
|
|
159
202
|
});
|
|
160
203
|
}
|
|
161
204
|
function navigateTo(option) {
|
|
@@ -181,7 +224,7 @@ function reLaunch(option) {
|
|
|
181
224
|
return redirectTo(option);
|
|
182
225
|
}
|
|
183
226
|
function getCurrentPages() {
|
|
184
|
-
return stacks;
|
|
227
|
+
return stacks.get();
|
|
185
228
|
}
|
|
186
229
|
|
|
187
230
|
/**
|
|
@@ -827,6 +870,7 @@ var UniversalRouter = function () {
|
|
|
827
870
|
|
|
828
871
|
UniversalRouter.pathToRegexp = pathToRegexp_1;
|
|
829
872
|
|
|
873
|
+
var Taro = require('@tarojs/taro-h5');
|
|
830
874
|
function initTabbar(config) {
|
|
831
875
|
if (config.tabBar == null) {
|
|
832
876
|
return;
|
|
@@ -838,7 +882,6 @@ function initTabbar(config) {
|
|
|
838
882
|
tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
|
|
839
883
|
var routerConfig = config.router;
|
|
840
884
|
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
841
|
-
tabbar.conf.custom = !!routerConfig.customRoutes;
|
|
842
885
|
if (routerConfig.customRoutes) {
|
|
843
886
|
tabbar.conf.custom = true;
|
|
844
887
|
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
@@ -853,6 +896,7 @@ function initTabbar(config) {
|
|
|
853
896
|
var container = document.getElementById('container');
|
|
854
897
|
// eslint-disable-next-line no-unused-expressions
|
|
855
898
|
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
899
|
+
Taro.initTabBarApis(config);
|
|
856
900
|
}
|
|
857
901
|
|
|
858
902
|
var routerConfig = Object.create(null);
|
|
@@ -876,6 +920,58 @@ function init(config) {
|
|
|
876
920
|
initTabbar(config);
|
|
877
921
|
}
|
|
878
922
|
|
|
923
|
+
var pageScrollFn;
|
|
924
|
+
var pageDOM = window;
|
|
925
|
+
function bindPageScroll(page, config) {
|
|
926
|
+
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
927
|
+
pageDOM = getScrollContainer();
|
|
928
|
+
var distance = config.onReachBottomDistance || 50;
|
|
929
|
+
var isReachBottom = false;
|
|
930
|
+
pageScrollFn = function () {
|
|
931
|
+
page.onPageScroll && page.onPageScroll({
|
|
932
|
+
scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
|
|
933
|
+
});
|
|
934
|
+
if (isReachBottom && getOffset() > distance) {
|
|
935
|
+
isReachBottom = false;
|
|
936
|
+
}
|
|
937
|
+
if (page.onReachBottom &&
|
|
938
|
+
!isReachBottom &&
|
|
939
|
+
getOffset() < distance) {
|
|
940
|
+
isReachBottom = true;
|
|
941
|
+
page.onReachBottom();
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
945
|
+
}
|
|
946
|
+
window.addEventListener('DOMSubtreeModified', function (e) {
|
|
947
|
+
var _a;
|
|
948
|
+
// @ts-ignore
|
|
949
|
+
var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
|
|
950
|
+
if (className && /taro-tabbar__/.test(className)) {
|
|
951
|
+
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
952
|
+
pageDOM = getScrollContainer();
|
|
953
|
+
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
954
|
+
}
|
|
955
|
+
}, false);
|
|
956
|
+
function getScrollContainer() {
|
|
957
|
+
if (document.querySelector('.taro-tabbar__tabbar') === null) {
|
|
958
|
+
// 没设置tabbar
|
|
959
|
+
return window;
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
// 有设置tabbar
|
|
963
|
+
return document.querySelector('.taro-tabbar__panel') || window;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
function getOffset() {
|
|
967
|
+
if (pageDOM instanceof Window) {
|
|
968
|
+
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
879
975
|
function createCommonjsModule(fn, module) {
|
|
880
976
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
881
977
|
}
|
|
@@ -1432,14 +1528,25 @@ var queryString_5 = queryString.stringifyUrl;
|
|
|
1432
1528
|
var queryString_6 = queryString.pick;
|
|
1433
1529
|
var queryString_7 = queryString.exclude;
|
|
1434
1530
|
|
|
1531
|
+
function getSearch() {
|
|
1532
|
+
var search = '?';
|
|
1533
|
+
if (routerConfig.router.mode === 'hash') {
|
|
1534
|
+
var idx = location.hash.indexOf('?');
|
|
1535
|
+
if (idx > -1) {
|
|
1536
|
+
search = location.hash.slice(idx);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
else {
|
|
1540
|
+
search = location.search;
|
|
1541
|
+
}
|
|
1542
|
+
return search.substr(1);
|
|
1543
|
+
}
|
|
1435
1544
|
var qs = function (stamp) {
|
|
1436
1545
|
if ( stamp === void 0 ) stamp = 0;
|
|
1437
1546
|
|
|
1438
|
-
var search =
|
|
1439
|
-
? location.hash.slice(routerConfig.router.pathname.length + 1)
|
|
1440
|
-
: location.search;
|
|
1547
|
+
var search = getSearch();
|
|
1441
1548
|
var query = search
|
|
1442
|
-
? queryString.parse(search
|
|
1549
|
+
? queryString.parse(search)
|
|
1443
1550
|
: {};
|
|
1444
1551
|
if (stamp) {
|
|
1445
1552
|
query.stamp = stamp.toString();
|
|
@@ -1447,99 +1554,15 @@ var qs = function (stamp) {
|
|
|
1447
1554
|
return query;
|
|
1448
1555
|
};
|
|
1449
1556
|
|
|
1450
|
-
var pageScrollFn;
|
|
1451
|
-
var pageDOM = window;
|
|
1452
|
-
function bindPageScroll(page, config) {
|
|
1453
|
-
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
1454
|
-
pageDOM = getScrollContainer();
|
|
1455
|
-
var distance = config.onReachBottomDistance || 50;
|
|
1456
|
-
var isReachBottom = false;
|
|
1457
|
-
pageScrollFn = function () {
|
|
1458
|
-
page.onPageScroll && page.onPageScroll({
|
|
1459
|
-
scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
|
|
1460
|
-
});
|
|
1461
|
-
if (isReachBottom && getOffset() > distance) {
|
|
1462
|
-
isReachBottom = false;
|
|
1463
|
-
}
|
|
1464
|
-
if (page.onReachBottom &&
|
|
1465
|
-
!isReachBottom &&
|
|
1466
|
-
getOffset() < distance) {
|
|
1467
|
-
isReachBottom = true;
|
|
1468
|
-
page.onReachBottom();
|
|
1469
|
-
}
|
|
1470
|
-
};
|
|
1471
|
-
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
1472
|
-
}
|
|
1473
|
-
window.addEventListener('DOMSubtreeModified', function (e) {
|
|
1474
|
-
var _a;
|
|
1475
|
-
// @ts-ignore
|
|
1476
|
-
var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
|
|
1477
|
-
if (className && /taro-tabbar__/.test(className)) {
|
|
1478
|
-
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
1479
|
-
pageDOM = getScrollContainer();
|
|
1480
|
-
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
1481
|
-
}
|
|
1482
|
-
}, false);
|
|
1483
|
-
function getScrollContainer() {
|
|
1484
|
-
if (document.querySelector('.taro-tabbar__tabbar') === null) {
|
|
1485
|
-
// 没设置tabbar
|
|
1486
|
-
return window;
|
|
1487
|
-
}
|
|
1488
|
-
else {
|
|
1489
|
-
// 有设置tabbar
|
|
1490
|
-
return document.querySelector('.taro-tabbar__panel') || window;
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
function getOffset() {
|
|
1494
|
-
if (pageDOM instanceof Window) {
|
|
1495
|
-
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
|
|
1496
|
-
}
|
|
1497
|
-
else {
|
|
1498
|
-
return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
1557
|
/* eslint-disable dot-notation */
|
|
1503
|
-
function
|
|
1504
|
-
if (page != null) {
|
|
1505
|
-
page.onHide();
|
|
1506
|
-
var pageEl = document.getElementById(page.path);
|
|
1507
|
-
if (pageEl) {
|
|
1508
|
-
pageEl.style.display = 'none';
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
function showPage(page, pageConfig, stacksIndex) {
|
|
1513
|
-
if ( stacksIndex === void 0 ) stacksIndex = 0;
|
|
1514
|
-
|
|
1515
|
-
if (page != null) {
|
|
1516
|
-
page.onShow();
|
|
1517
|
-
var pageEl = document.getElementById(page.path);
|
|
1518
|
-
if (pageEl) {
|
|
1519
|
-
pageEl.style.display = 'block';
|
|
1520
|
-
}
|
|
1521
|
-
else {
|
|
1522
|
-
page.onLoad(qs(stacksIndex));
|
|
1523
|
-
pageEl = document.getElementById(page.path);
|
|
1524
|
-
pageOnReady(pageEl, page, false);
|
|
1525
|
-
}
|
|
1526
|
-
bindPageScroll(page, pageConfig || {});
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
function unloadPage(page) {
|
|
1530
|
-
if (page != null) {
|
|
1531
|
-
stacks.pop();
|
|
1532
|
-
page.onUnload();
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
function pageOnReady(pageEl, page, onLoad) {
|
|
1558
|
+
function pageOnReady(page, onLoad) {
|
|
1536
1559
|
if ( onLoad === void 0 ) onLoad = true;
|
|
1537
1560
|
|
|
1538
|
-
var _a;
|
|
1561
|
+
var _a, _b;
|
|
1562
|
+
var pageEl = document.getElementById(page.path);
|
|
1539
1563
|
if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
|
|
1540
1564
|
var el = pageEl.firstElementChild;
|
|
1541
|
-
|
|
1542
|
-
(_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el).then(function () {
|
|
1565
|
+
(_b = (_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el)) === null || _b === void 0 ? void 0 : _b.then(function () {
|
|
1543
1566
|
runtime.requestAnimationFrame(function () {
|
|
1544
1567
|
page.onReady();
|
|
1545
1568
|
pageEl['__isReady'] = true;
|
|
@@ -1549,24 +1572,64 @@ function pageOnReady(pageEl, page, onLoad) {
|
|
|
1549
1572
|
}
|
|
1550
1573
|
}
|
|
1551
1574
|
function loadPage(page, pageConfig, stacksIndex) {
|
|
1575
|
+
if ( pageConfig === void 0 ) pageConfig = {};
|
|
1552
1576
|
if ( stacksIndex === void 0 ) stacksIndex = 0;
|
|
1553
1577
|
|
|
1554
|
-
if (page
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1578
|
+
if (!page)
|
|
1579
|
+
{ return; }
|
|
1580
|
+
var pageEl = document.getElementById(page.path);
|
|
1581
|
+
if (pageEl) {
|
|
1582
|
+
pageEl.style.display = 'block';
|
|
1583
|
+
}
|
|
1584
|
+
else {
|
|
1585
|
+
page.onLoad(qs(stacksIndex), function () { return pageOnReady(page, true); });
|
|
1586
|
+
}
|
|
1587
|
+
stacks.push(page);
|
|
1588
|
+
page.onShow();
|
|
1589
|
+
bindPageScroll(page, pageConfig);
|
|
1590
|
+
}
|
|
1591
|
+
function unloadPage(page, delta) {
|
|
1592
|
+
if ( delta === void 0 ) delta = 1;
|
|
1593
|
+
|
|
1594
|
+
if (!page)
|
|
1595
|
+
{ return; }
|
|
1596
|
+
stacks.delta = --delta;
|
|
1597
|
+
stacks.pop();
|
|
1598
|
+
page.onUnload();
|
|
1599
|
+
if (delta >= 1)
|
|
1600
|
+
{ unloadPage(stacks.last, delta); }
|
|
1601
|
+
}
|
|
1602
|
+
function showPage(page, pageConfig, stacksIndex) {
|
|
1603
|
+
if ( pageConfig === void 0 ) pageConfig = {};
|
|
1604
|
+
if ( stacksIndex === void 0 ) stacksIndex = 0;
|
|
1605
|
+
|
|
1606
|
+
if (!page)
|
|
1607
|
+
{ return; }
|
|
1608
|
+
page.onShow();
|
|
1609
|
+
var pageEl = document.getElementById(page.path);
|
|
1610
|
+
if (pageEl) {
|
|
1611
|
+
pageEl.style.display = 'block';
|
|
1612
|
+
}
|
|
1613
|
+
else {
|
|
1614
|
+
page.onLoad(qs(stacksIndex), function () { return pageOnReady(page, false); });
|
|
1568
1615
|
}
|
|
1616
|
+
bindPageScroll(page, pageConfig);
|
|
1569
1617
|
}
|
|
1618
|
+
function hidePage(page) {
|
|
1619
|
+
if (!page)
|
|
1620
|
+
{ return; }
|
|
1621
|
+
// NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
1622
|
+
var pageEl = document.getElementById(page.path);
|
|
1623
|
+
if (pageEl) {
|
|
1624
|
+
pageEl.style.display = 'none';
|
|
1625
|
+
page.onHide();
|
|
1626
|
+
}
|
|
1627
|
+
else {
|
|
1628
|
+
setTimeout(function () { return hidePage(page); }, 0);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/* eslint-disable dot-notation */
|
|
1570
1633
|
function createRouter(app, config, framework) {
|
|
1571
1634
|
var _a;
|
|
1572
1635
|
init(config);
|
|
@@ -1585,7 +1648,7 @@ function createRouter(app, config, framework) {
|
|
|
1585
1648
|
var basename = config.router.basename;
|
|
1586
1649
|
var router = new UniversalRouter(routes, { baseUrl: basename || '' });
|
|
1587
1650
|
app.onLaunch();
|
|
1588
|
-
var render =
|
|
1651
|
+
var render = async function (ref) {
|
|
1589
1652
|
var location = ref.location;
|
|
1590
1653
|
var action = ref.action;
|
|
1591
1654
|
|
|
@@ -1621,65 +1684,49 @@ function createRouter(app, config, framework) {
|
|
|
1621
1684
|
document.title = (_b = pageConfig.navigationBarTitleText) !== null && _b !== void 0 ? _b : document.title;
|
|
1622
1685
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1623
1686
|
}
|
|
1687
|
+
var currentPage = runtime.Current.page;
|
|
1688
|
+
var pathname = location.pathname;
|
|
1624
1689
|
var shouldLoad = false;
|
|
1625
1690
|
if (action === 'POP') {
|
|
1626
|
-
|
|
1627
|
-
var
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
setHistoryBackDelta(1);
|
|
1633
|
-
var prevIndex = stacks.reduceRight(function (p, s, i) {
|
|
1634
|
-
if (p !== 0)
|
|
1635
|
-
{ return p; }
|
|
1636
|
-
else if (s.path === location.pathname + runtime.stringify(qs(i)))
|
|
1637
|
-
{ return i; }
|
|
1638
|
-
else
|
|
1639
|
-
{ return 0; }
|
|
1640
|
-
}, 0);
|
|
1641
|
-
var prev = stacks[prevIndex];
|
|
1642
|
-
if (prev) {
|
|
1643
|
-
showPage(prev, pageConfig, prevIndex);
|
|
1691
|
+
// NOTE: 浏览器事件退后多次时,该事件只会被触发一次
|
|
1692
|
+
var prevIndex = stacks.getPrevIndex(pathname);
|
|
1693
|
+
var delta = stacks.getDelta(pathname);
|
|
1694
|
+
unloadPage(currentPage, delta);
|
|
1695
|
+
if (prevIndex > -1) {
|
|
1696
|
+
showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
1644
1697
|
}
|
|
1645
1698
|
else {
|
|
1646
1699
|
shouldLoad = true;
|
|
1647
1700
|
}
|
|
1648
1701
|
}
|
|
1649
1702
|
else if (action === 'PUSH') {
|
|
1650
|
-
hidePage(
|
|
1703
|
+
hidePage(currentPage);
|
|
1651
1704
|
shouldLoad = true;
|
|
1652
1705
|
}
|
|
1653
1706
|
else if (action === 'REPLACE') {
|
|
1654
1707
|
if (isTabBar(config)) {
|
|
1655
|
-
hidePage(
|
|
1656
|
-
var
|
|
1657
|
-
var prevIndex$1 = stacks.findIndex(function (r) {
|
|
1658
|
-
var _a;
|
|
1659
|
-
return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
|
|
1660
|
-
});
|
|
1708
|
+
hidePage(currentPage);
|
|
1709
|
+
var prevIndex$1 = stacks.getPrevIndex(pathname);
|
|
1661
1710
|
if (prevIndex$1 > -1) {
|
|
1662
|
-
// tabbar 页且之前出现过,直接复用
|
|
1663
|
-
|
|
1664
|
-
return showPage(prev$1, pageConfig, prevIndex$1);
|
|
1711
|
+
// NOTE: tabbar 页且之前出现过,直接复用
|
|
1712
|
+
return showPage(stacks.getItem(prevIndex$1), pageConfig, prevIndex$1);
|
|
1665
1713
|
}
|
|
1666
1714
|
}
|
|
1667
1715
|
else {
|
|
1668
|
-
unloadPage(
|
|
1716
|
+
unloadPage(currentPage);
|
|
1669
1717
|
}
|
|
1670
1718
|
shouldLoad = true;
|
|
1671
1719
|
}
|
|
1672
|
-
if (shouldLoad) {
|
|
1720
|
+
if (shouldLoad || stacks.length < 1) {
|
|
1673
1721
|
var el = (_c = element.default) !== null && _c !== void 0 ? _c : element;
|
|
1674
1722
|
var loadConfig = Object.assign({}, pageConfig);
|
|
1723
|
+
var stacksIndex = stacks.length;
|
|
1675
1724
|
delete loadConfig['path'];
|
|
1676
1725
|
delete loadConfig['load'];
|
|
1677
|
-
var
|
|
1678
|
-
|
|
1679
|
-
var page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname$1 + runtime.stringify(qs(routerIndex)), {}, loadConfig);
|
|
1680
|
-
loadPage(page, pageConfig, routerIndex);
|
|
1726
|
+
var page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + runtime.stringify(qs(stacksIndex)), {}, loadConfig);
|
|
1727
|
+
return loadPage(page, pageConfig, stacksIndex);
|
|
1681
1728
|
}
|
|
1682
|
-
}
|
|
1729
|
+
};
|
|
1683
1730
|
if (exports.history.location.pathname === '/') {
|
|
1684
1731
|
exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
|
|
1685
1732
|
}
|