@tarojs/router 3.3.15 → 3.4.0-beta.0
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 +1639 -1083
- package/dist/index.js.map +1 -1
- package/dist/router.esm.js +1644 -1064
- package/dist/router.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,257 +2,717 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _extends = require('@babel/runtime/helpers/esm/extends');
|
|
6
|
+
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
|
+
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
8
|
+
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
9
|
+
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
10
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
11
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
12
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
5
13
|
var runtime = require('@tarojs/runtime');
|
|
14
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
15
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
16
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
21
|
+
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
22
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
23
|
+
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
24
|
+
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
25
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
26
|
+
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
27
|
+
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
28
|
+
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
29
|
+
var _createForOfIteratorHelper__default = /*#__PURE__*/_interopDefaultLegacy(_createForOfIteratorHelper);
|
|
30
|
+
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
31
|
+
|
|
32
|
+
var r,
|
|
33
|
+
B = r || (r = {});
|
|
34
|
+
B.Pop = "POP";
|
|
35
|
+
B.Push = "PUSH";
|
|
36
|
+
B.Replace = "REPLACE";
|
|
37
|
+
var C = "production" !== process.env.NODE_ENV ? function (b) {
|
|
38
|
+
return Object.freeze(b);
|
|
39
|
+
} : function (b) {
|
|
40
|
+
return b;
|
|
41
|
+
};
|
|
6
42
|
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
43
|
+
function D(b, h) {
|
|
44
|
+
if (!b) {
|
|
45
|
+
"undefined" !== typeof console && console.warn(h);
|
|
10
46
|
|
|
11
|
-
|
|
12
|
-
|
|
47
|
+
try {
|
|
48
|
+
throw Error(h);
|
|
49
|
+
} catch (k) {}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
13
52
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
53
|
+
function E(b) {
|
|
54
|
+
b.preventDefault();
|
|
55
|
+
b.returnValue = "";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function F() {
|
|
59
|
+
var b = [];
|
|
60
|
+
return {
|
|
61
|
+
get length() {
|
|
62
|
+
return b.length;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
push: function push(h) {
|
|
66
|
+
b.push(h);
|
|
67
|
+
return function () {
|
|
68
|
+
b = b.filter(function (k) {
|
|
69
|
+
return k !== h;
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
call: function call(h) {
|
|
74
|
+
b.forEach(function (k) {
|
|
75
|
+
return k && k(h);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function H() {
|
|
82
|
+
return Math.random().toString(36).substr(2, 8);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function I(b) {
|
|
86
|
+
var h = b.pathname,
|
|
87
|
+
k = b.search;
|
|
88
|
+
b = b.hash;
|
|
89
|
+
return (void 0 === h ? "/" : h) + (void 0 === k ? "" : k) + (void 0 === b ? "" : b);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function J(b) {
|
|
93
|
+
var h = {};
|
|
94
|
+
|
|
95
|
+
if (b) {
|
|
96
|
+
var k = b.indexOf("#");
|
|
97
|
+
0 <= k && (h.hash = b.substr(k), b = b.substr(0, k));
|
|
98
|
+
k = b.indexOf("?");
|
|
99
|
+
0 <= k && (h.search = b.substr(k), b = b.substr(0, k));
|
|
100
|
+
b && (h.pathname = b);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return h;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function createBrowserHistory(b) {
|
|
107
|
+
function h() {
|
|
108
|
+
var c = p.location,
|
|
109
|
+
a = m.state || {};
|
|
110
|
+
return [a.idx, C({
|
|
111
|
+
pathname: c.pathname,
|
|
112
|
+
search: c.search,
|
|
113
|
+
hash: c.hash,
|
|
114
|
+
state: a.usr || null,
|
|
115
|
+
key: a.key || "default"
|
|
116
|
+
})];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function k(c) {
|
|
120
|
+
return "string" === typeof c ? c : I(c);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function x(c, a) {
|
|
124
|
+
void 0 === a && (a = null);
|
|
125
|
+
return C(_extends__default['default']({
|
|
126
|
+
pathname: q.pathname,
|
|
127
|
+
hash: "",
|
|
128
|
+
search: ""
|
|
129
|
+
}, "string" === typeof c ? J(c) : c, {
|
|
130
|
+
state: a,
|
|
131
|
+
key: H()
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function z(c) {
|
|
136
|
+
t = c;
|
|
137
|
+
c = h();
|
|
138
|
+
v = c[0];
|
|
139
|
+
q = c[1];
|
|
140
|
+
d.call({
|
|
141
|
+
action: t,
|
|
142
|
+
location: q
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function A(c, a) {
|
|
147
|
+
function e() {
|
|
148
|
+
A(c, a);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var l = r.Push,
|
|
152
|
+
g = x(c, a);
|
|
153
|
+
|
|
154
|
+
if (!f.length || (f.call({
|
|
155
|
+
action: l,
|
|
156
|
+
location: g,
|
|
157
|
+
retry: e
|
|
158
|
+
}), !1)) {
|
|
159
|
+
var n = [{
|
|
160
|
+
usr: g.state,
|
|
161
|
+
key: g.key,
|
|
162
|
+
idx: v + 1
|
|
163
|
+
}, k(g)];
|
|
164
|
+
g = n[0];
|
|
165
|
+
n = n[1];
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
m.pushState(g, "", n);
|
|
169
|
+
} catch (G) {
|
|
170
|
+
p.location.assign(n);
|
|
18
171
|
}
|
|
172
|
+
|
|
173
|
+
z(l);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function y(c, a) {
|
|
178
|
+
function e() {
|
|
179
|
+
y(c, a);
|
|
19
180
|
}
|
|
20
181
|
|
|
21
|
-
|
|
182
|
+
var l = r.Replace,
|
|
183
|
+
g = x(c, a);
|
|
184
|
+
f.length && (f.call({
|
|
185
|
+
action: l,
|
|
186
|
+
location: g,
|
|
187
|
+
retry: e
|
|
188
|
+
}), 1) || (g = [{
|
|
189
|
+
usr: g.state,
|
|
190
|
+
key: g.key,
|
|
191
|
+
idx: v
|
|
192
|
+
}, k(g)], m.replaceState(g[0], "", g[1]), z(l));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function w(c) {
|
|
196
|
+
m.go(c);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
void 0 === b && (b = {});
|
|
200
|
+
b = b.window;
|
|
201
|
+
var p = void 0 === b ? document.defaultView : b,
|
|
202
|
+
m = p.history,
|
|
203
|
+
u = null;
|
|
204
|
+
p.addEventListener("popstate", function () {
|
|
205
|
+
if (u) f.call(u), u = null;else {
|
|
206
|
+
var c = r.Pop,
|
|
207
|
+
a = h(),
|
|
208
|
+
e = a[0];
|
|
209
|
+
a = a[1];
|
|
210
|
+
if (f.length) {
|
|
211
|
+
if (null != e) {
|
|
212
|
+
var l = v - e;
|
|
213
|
+
l && (u = {
|
|
214
|
+
action: c,
|
|
215
|
+
location: a,
|
|
216
|
+
retry: function retry() {
|
|
217
|
+
w(-1 * l);
|
|
218
|
+
}
|
|
219
|
+
}, w(l));
|
|
220
|
+
} 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.") : void 0;
|
|
221
|
+
} else z(c);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
var t = r.Pop;
|
|
225
|
+
b = h();
|
|
226
|
+
var v = b[0],
|
|
227
|
+
q = b[1],
|
|
228
|
+
d = F(),
|
|
229
|
+
f = F();
|
|
230
|
+
null == v && (v = 0, m.replaceState(_extends__default['default']({}, m.state, {
|
|
231
|
+
idx: v
|
|
232
|
+
}), ""));
|
|
233
|
+
return {
|
|
234
|
+
get action() {
|
|
235
|
+
return t;
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
get location() {
|
|
239
|
+
return q;
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
createHref: k,
|
|
243
|
+
push: A,
|
|
244
|
+
replace: y,
|
|
245
|
+
go: w,
|
|
246
|
+
back: function back() {
|
|
247
|
+
w(-1);
|
|
248
|
+
},
|
|
249
|
+
forward: function forward() {
|
|
250
|
+
w(1);
|
|
251
|
+
},
|
|
252
|
+
listen: function listen(c) {
|
|
253
|
+
return d.push(c);
|
|
254
|
+
},
|
|
255
|
+
block: function block(c) {
|
|
256
|
+
var a = f.push(c);
|
|
257
|
+
1 === f.length && p.addEventListener("beforeunload", E);
|
|
258
|
+
return function () {
|
|
259
|
+
a();
|
|
260
|
+
f.length || p.removeEventListener("beforeunload", E);
|
|
261
|
+
};
|
|
262
|
+
}
|
|
22
263
|
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function createHashHistory(b) {
|
|
267
|
+
function h() {
|
|
268
|
+
var a = J(m.location.hash.substr(1)),
|
|
269
|
+
e = a.pathname,
|
|
270
|
+
l = a.search;
|
|
271
|
+
a = a.hash;
|
|
272
|
+
var g = u.state || {};
|
|
273
|
+
return [g.idx, C({
|
|
274
|
+
pathname: void 0 === e ? "/" : e,
|
|
275
|
+
search: void 0 === l ? "" : l,
|
|
276
|
+
hash: void 0 === a ? "" : a,
|
|
277
|
+
state: g.usr || null,
|
|
278
|
+
key: g.key || "default"
|
|
279
|
+
})];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function k() {
|
|
283
|
+
if (t) c.call(t), t = null;else {
|
|
284
|
+
var a = r.Pop,
|
|
285
|
+
e = h(),
|
|
286
|
+
l = e[0];
|
|
287
|
+
e = e[1];
|
|
288
|
+
if (c.length) {
|
|
289
|
+
if (null != l) {
|
|
290
|
+
var g = q - l;
|
|
291
|
+
g && (t = {
|
|
292
|
+
action: a,
|
|
293
|
+
location: e,
|
|
294
|
+
retry: function retry() {
|
|
295
|
+
p(-1 * g);
|
|
296
|
+
}
|
|
297
|
+
}, p(g));
|
|
298
|
+
} 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.") : void 0;
|
|
299
|
+
} else A(a);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function x(a) {
|
|
304
|
+
var e = document.querySelector("base"),
|
|
305
|
+
l = "";
|
|
306
|
+
e && e.getAttribute("href") && (e = m.location.href, l = e.indexOf("#"), l = -1 === l ? e : e.slice(0, l));
|
|
307
|
+
return l + "#" + ("string" === typeof a ? a : I(a));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function z(a, e) {
|
|
311
|
+
void 0 === e && (e = null);
|
|
312
|
+
return C(_extends__default['default']({
|
|
313
|
+
pathname: d.pathname,
|
|
314
|
+
hash: "",
|
|
315
|
+
search: ""
|
|
316
|
+
}, "string" === typeof a ? J(a) : a, {
|
|
317
|
+
state: e,
|
|
318
|
+
key: H()
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function A(a) {
|
|
323
|
+
v = a;
|
|
324
|
+
a = h();
|
|
325
|
+
q = a[0];
|
|
326
|
+
d = a[1];
|
|
327
|
+
f.call({
|
|
328
|
+
action: v,
|
|
329
|
+
location: d
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function y(a, e) {
|
|
334
|
+
function l() {
|
|
335
|
+
y(a, e);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
var g = r.Push,
|
|
339
|
+
n = z(a, e);
|
|
340
|
+
"production" !== process.env.NODE_ENV ? D("/" === n.pathname.charAt(0), "Relative pathnames are not supported in hash history.push(" + JSON.stringify(a) + ")") : void 0;
|
|
341
|
+
|
|
342
|
+
if (!c.length || (c.call({
|
|
343
|
+
action: g,
|
|
344
|
+
location: n,
|
|
345
|
+
retry: l
|
|
346
|
+
}), !1)) {
|
|
347
|
+
var G = [{
|
|
348
|
+
usr: n.state,
|
|
349
|
+
key: n.key,
|
|
350
|
+
idx: q + 1
|
|
351
|
+
}, x(n)];
|
|
352
|
+
n = G[0];
|
|
353
|
+
G = G[1];
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
u.pushState(n, "", G);
|
|
357
|
+
} catch (K) {
|
|
358
|
+
m.location.assign(G);
|
|
359
|
+
}
|
|
23
360
|
|
|
24
|
-
|
|
361
|
+
A(g);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function w(a, e) {
|
|
366
|
+
function l() {
|
|
367
|
+
w(a, e);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
var g = r.Replace,
|
|
371
|
+
n = z(a, e);
|
|
372
|
+
"production" !== process.env.NODE_ENV ? D("/" === n.pathname.charAt(0), "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(a) + ")") : void 0;
|
|
373
|
+
c.length && (c.call({
|
|
374
|
+
action: g,
|
|
375
|
+
location: n,
|
|
376
|
+
retry: l
|
|
377
|
+
}), 1) || (n = [{
|
|
378
|
+
usr: n.state,
|
|
379
|
+
key: n.key,
|
|
380
|
+
idx: q
|
|
381
|
+
}, x(n)], u.replaceState(n[0], "", n[1]), A(g));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function p(a) {
|
|
385
|
+
u.go(a);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
void 0 === b && (b = {});
|
|
389
|
+
b = b.window;
|
|
390
|
+
var m = void 0 === b ? document.defaultView : b,
|
|
391
|
+
u = m.history,
|
|
392
|
+
t = null;
|
|
393
|
+
m.addEventListener("popstate", k);
|
|
394
|
+
m.addEventListener("hashchange", function () {
|
|
395
|
+
var a = h()[1];
|
|
396
|
+
I(a) !== I(d) && k();
|
|
397
|
+
});
|
|
398
|
+
var v = r.Pop;
|
|
399
|
+
b = h();
|
|
400
|
+
var q = b[0],
|
|
401
|
+
d = b[1],
|
|
402
|
+
f = F(),
|
|
403
|
+
c = F();
|
|
404
|
+
null == q && (q = 0, u.replaceState(_extends__default['default']({}, u.state, {
|
|
405
|
+
idx: q
|
|
406
|
+
}), ""));
|
|
407
|
+
return {
|
|
408
|
+
get action() {
|
|
409
|
+
return v;
|
|
410
|
+
},
|
|
411
|
+
|
|
412
|
+
get location() {
|
|
413
|
+
return d;
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
createHref: x,
|
|
417
|
+
push: y,
|
|
418
|
+
replace: w,
|
|
419
|
+
go: p,
|
|
420
|
+
back: function back() {
|
|
421
|
+
p(-1);
|
|
422
|
+
},
|
|
423
|
+
forward: function forward() {
|
|
424
|
+
p(1);
|
|
425
|
+
},
|
|
426
|
+
listen: function listen(a) {
|
|
427
|
+
return f.push(a);
|
|
428
|
+
},
|
|
429
|
+
block: function block(a) {
|
|
430
|
+
var e = c.push(a);
|
|
431
|
+
1 === c.length && m.addEventListener("beforeunload", E);
|
|
432
|
+
return function () {
|
|
433
|
+
e();
|
|
434
|
+
c.length || m.removeEventListener("beforeunload", E);
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
};
|
|
25
438
|
}
|
|
26
439
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
-
var basename = '/';
|
|
40
|
-
function setHistoryMode(mode, base) {
|
|
41
|
-
if ( base === void 0 ) base = '/';
|
|
42
|
-
|
|
43
|
-
var options = {
|
|
44
|
-
window: window
|
|
45
|
-
};
|
|
46
|
-
basename = base;
|
|
47
|
-
if (mode === 'browser') {
|
|
48
|
-
exports.history = createBrowserHistory(options);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
// default is hash
|
|
52
|
-
exports.history = createHashHistory(options);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function prependBasename(url) {
|
|
56
|
-
if ( url === void 0 ) url = '';
|
|
57
|
-
|
|
58
|
-
return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
|
|
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
|
-
};
|
|
440
|
+
exports.history = void 0;
|
|
441
|
+
var basename = '/';
|
|
442
|
+
function setHistoryMode(mode) {
|
|
443
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '/';
|
|
444
|
+
var options = {
|
|
445
|
+
window: window
|
|
446
|
+
};
|
|
447
|
+
basename = base;
|
|
67
448
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return this.stacks;
|
|
85
|
-
};
|
|
86
|
-
Stacks.prototype.getItem = function getItem (index) {
|
|
87
|
-
return this.stacks[index];
|
|
88
|
-
};
|
|
89
|
-
Stacks.prototype.getDelta = function getDelta (pathname) {
|
|
90
|
-
if (this.backDelta >= 1) {
|
|
91
|
-
return this.backDelta;
|
|
92
|
-
}
|
|
93
|
-
// NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
|
|
94
|
-
var prevIndex = this.stacks.findIndex(function (r) { var _a; return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname; });
|
|
95
|
-
return this.length - 1 - prevIndex;
|
|
96
|
-
};
|
|
97
|
-
Stacks.prototype.getPrevIndex = function getPrevIndex (pathname) {
|
|
98
|
-
return this.length - 1 - this.getDelta(pathname);
|
|
99
|
-
};
|
|
100
|
-
Stacks.prototype.pop = function pop () {
|
|
101
|
-
return this.stacks.pop();
|
|
102
|
-
};
|
|
103
|
-
Stacks.prototype.push = function push (page) {
|
|
104
|
-
return this.stacks.push(page);
|
|
449
|
+
if (mode === 'browser') {
|
|
450
|
+
exports.history = createBrowserHistory(options);
|
|
451
|
+
} else {
|
|
452
|
+
// default is hash
|
|
453
|
+
exports.history = createHashHistory(options);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function prependBasename() {
|
|
457
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
458
|
+
return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
|
|
459
|
+
}
|
|
460
|
+
var hasBasename = function hasBasename(path, prefix) {
|
|
461
|
+
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
|
|
462
|
+
};
|
|
463
|
+
var stripBasename = function stripBasename(path, prefix) {
|
|
464
|
+
return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
|
|
105
465
|
};
|
|
106
466
|
|
|
107
|
-
|
|
467
|
+
var Stacks = /*#__PURE__*/function () {
|
|
468
|
+
function Stacks() {
|
|
469
|
+
_classCallCheck__default['default'](this, Stacks);
|
|
470
|
+
|
|
471
|
+
_defineProperty__default['default'](this, "stacks", []);
|
|
472
|
+
|
|
473
|
+
_defineProperty__default['default'](this, "backDelta", 0);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
_createClass__default['default'](Stacks, [{
|
|
477
|
+
key: "delta",
|
|
478
|
+
set: function set(delta) {
|
|
479
|
+
if (delta > 0) {
|
|
480
|
+
this.backDelta = delta;
|
|
481
|
+
} else {
|
|
482
|
+
--this.backDelta;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}, {
|
|
486
|
+
key: "length",
|
|
487
|
+
get: function get() {
|
|
488
|
+
return this.stacks.length;
|
|
489
|
+
}
|
|
490
|
+
}, {
|
|
491
|
+
key: "last",
|
|
492
|
+
get: function get() {
|
|
493
|
+
return this.stacks[this.length - 1];
|
|
494
|
+
}
|
|
495
|
+
}, {
|
|
496
|
+
key: "get",
|
|
497
|
+
value: function get() {
|
|
498
|
+
return this.stacks;
|
|
499
|
+
}
|
|
500
|
+
}, {
|
|
501
|
+
key: "getItem",
|
|
502
|
+
value: function getItem(index) {
|
|
503
|
+
return this.stacks[index];
|
|
504
|
+
}
|
|
505
|
+
}, {
|
|
506
|
+
key: "getDelta",
|
|
507
|
+
value: function getDelta(pathname) {
|
|
508
|
+
if (this.backDelta >= 1) {
|
|
509
|
+
return this.backDelta;
|
|
510
|
+
} // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
var prevIndex = this.stacks.findIndex(function (r) {
|
|
514
|
+
var _r$path;
|
|
515
|
+
|
|
516
|
+
return ((_r$path = r.path) === null || _r$path === void 0 ? void 0 : _r$path.replace(/\?.*/g, '')) === pathname;
|
|
517
|
+
});
|
|
518
|
+
return this.length - 1 - prevIndex;
|
|
519
|
+
}
|
|
520
|
+
}, {
|
|
521
|
+
key: "getPrevIndex",
|
|
522
|
+
value: function getPrevIndex(pathname) {
|
|
523
|
+
return this.length - 1 - this.getDelta(pathname);
|
|
524
|
+
}
|
|
525
|
+
}, {
|
|
526
|
+
key: "pop",
|
|
527
|
+
value: function pop() {
|
|
528
|
+
return this.stacks.pop();
|
|
529
|
+
}
|
|
530
|
+
}, {
|
|
531
|
+
key: "push",
|
|
532
|
+
value: function push(page) {
|
|
533
|
+
return this.stacks.push(page);
|
|
534
|
+
}
|
|
535
|
+
}]);
|
|
536
|
+
|
|
537
|
+
return Stacks;
|
|
538
|
+
}();
|
|
539
|
+
|
|
108
540
|
var stacks = new Stacks();
|
|
109
541
|
|
|
110
|
-
var routesAlias = {};
|
|
111
|
-
function setRoutesAlias(alias) {
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
function addLeadingSlash(path) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
542
|
+
var routesAlias = {};
|
|
543
|
+
function setRoutesAlias(alias) {
|
|
544
|
+
routesAlias = alias;
|
|
545
|
+
}
|
|
546
|
+
function addLeadingSlash(path) {
|
|
547
|
+
if (path == null) {
|
|
548
|
+
return '';
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
return path.charAt(0) === '/' ? path : '/' + path;
|
|
552
|
+
} // eslint-disable-next-line @typescript-eslint/ban-types
|
|
553
|
+
var isTabBar = function isTabBar(config) {
|
|
554
|
+
var _Object$entries$find, _config$tabBar;
|
|
555
|
+
|
|
556
|
+
var _config$router = config.router,
|
|
557
|
+
_config$router$custom = _config$router.customRoutes,
|
|
558
|
+
customRoutes = _config$router$custom === void 0 ? {} : _config$router$custom,
|
|
559
|
+
_config$router$basena = _config$router.basename,
|
|
560
|
+
basename = _config$router$basena === void 0 ? '' : _config$router$basena,
|
|
561
|
+
pathname = _config$router.pathname;
|
|
562
|
+
var routePath = stripBasename(pathname, basename);
|
|
563
|
+
var pagePath = ((_Object$entries$find = Object.entries(customRoutes).find(function (_ref) {
|
|
564
|
+
var _ref2 = _slicedToArray__default['default'](_ref, 2),
|
|
565
|
+
target = _ref2[1];
|
|
566
|
+
|
|
567
|
+
return target === routePath;
|
|
568
|
+
})) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0]) || routePath;
|
|
569
|
+
return !!pagePath && (((_config$tabBar = config.tabBar) === null || _config$tabBar === void 0 ? void 0 : _config$tabBar.list) || []).some(function (t) {
|
|
570
|
+
return t.pagePath === pagePath;
|
|
571
|
+
});
|
|
133
572
|
};
|
|
134
573
|
|
|
135
|
-
function processNavigateUrl(option) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return new Promise(function (resolve, reject) {
|
|
165
|
-
var success = option.success;
|
|
166
|
-
var complete = option.complete;
|
|
167
|
-
var fail = option.fail;
|
|
168
|
-
var unListen = exports.history.listen(function () {
|
|
169
|
-
success === null || success === void 0 ? void 0 : success();
|
|
170
|
-
complete === null || complete === void 0 ? void 0 : complete();
|
|
171
|
-
resolve();
|
|
172
|
-
unListen();
|
|
173
|
-
});
|
|
174
|
-
try {
|
|
175
|
-
if ('url' in option) {
|
|
176
|
-
var pathPieces = processNavigateUrl(option);
|
|
177
|
-
var state = { timestamp: Date.now() };
|
|
178
|
-
if (method === 'navigateTo') {
|
|
179
|
-
exports.history.push(pathPieces, state);
|
|
180
|
-
}
|
|
181
|
-
else if (method === 'redirectTo') {
|
|
182
|
-
exports.history.replace(pathPieces, state);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
else if (method === 'navigateBack') {
|
|
186
|
-
stacks.delta = option.delta;
|
|
187
|
-
exports.history.go(-option.delta);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
fail === null || fail === void 0 ? void 0 : fail(error);
|
|
192
|
-
complete === null || complete === void 0 ? void 0 : complete();
|
|
193
|
-
reject(error);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
function navigateTo(option) {
|
|
198
|
-
return navigate(option, 'navigateTo');
|
|
199
|
-
}
|
|
200
|
-
function redirectTo(option) {
|
|
201
|
-
return navigate(option, 'redirectTo');
|
|
202
|
-
}
|
|
203
|
-
function navigateBack(options) {
|
|
204
|
-
if ( options === void 0 ) options = { delta: 1 };
|
|
205
|
-
|
|
206
|
-
if (!options.delta || options.delta < 1) {
|
|
207
|
-
options.delta = 1;
|
|
208
|
-
}
|
|
209
|
-
return navigate(options, 'navigateBack');
|
|
210
|
-
}
|
|
211
|
-
function switchTab(option) {
|
|
212
|
-
// TODO: 清除掉所有的栈去目标页面
|
|
213
|
-
return redirectTo(option);
|
|
214
|
-
}
|
|
215
|
-
function reLaunch(option) {
|
|
216
|
-
// TODO: 清除掉所有的栈去目标页面
|
|
217
|
-
return redirectTo(option);
|
|
218
|
-
}
|
|
219
|
-
function getCurrentPages() {
|
|
220
|
-
return stacks.get();
|
|
574
|
+
function processNavigateUrl(option) {
|
|
575
|
+
var _pathPieces$pathname;
|
|
576
|
+
|
|
577
|
+
var pathPieces = J(option.url); // 处理自定义路由
|
|
578
|
+
|
|
579
|
+
Object.keys(routesAlias).forEach(function (key) {
|
|
580
|
+
if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
|
|
581
|
+
pathPieces.pathname = routesAlias[key];
|
|
582
|
+
}
|
|
583
|
+
}); // 处理相对路径
|
|
584
|
+
|
|
585
|
+
if (pathPieces !== null && pathPieces !== void 0 && (_pathPieces$pathname = pathPieces.pathname) !== null && _pathPieces$pathname !== void 0 && _pathPieces$pathname.includes('./')) {
|
|
586
|
+
var parts = exports.history.location.pathname.split('/');
|
|
587
|
+
parts.pop();
|
|
588
|
+
pathPieces.pathname.split('/').forEach(function (item) {
|
|
589
|
+
if (item === '.') {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
item === '..' ? parts.pop() : parts.push(item);
|
|
594
|
+
});
|
|
595
|
+
pathPieces.pathname = parts.join('/');
|
|
596
|
+
} // 处理 basename
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
pathPieces.pathname = prependBasename(pathPieces.pathname); // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
|
|
600
|
+
|
|
601
|
+
if (!pathPieces.search) pathPieces.search = '';
|
|
602
|
+
return pathPieces;
|
|
221
603
|
}
|
|
222
604
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
605
|
+
function navigate(_x, _x2) {
|
|
606
|
+
return _navigate.apply(this, arguments);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function _navigate() {
|
|
610
|
+
_navigate = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(option, method) {
|
|
611
|
+
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
612
|
+
while (1) {
|
|
613
|
+
switch (_context.prev = _context.next) {
|
|
614
|
+
case 0:
|
|
615
|
+
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
616
|
+
var success = option.success,
|
|
617
|
+
complete = option.complete,
|
|
618
|
+
fail = option.fail;
|
|
619
|
+
var unListen = exports.history.listen(function () {
|
|
620
|
+
success === null || success === void 0 ? void 0 : success();
|
|
621
|
+
complete === null || complete === void 0 ? void 0 : complete();
|
|
622
|
+
resolve();
|
|
623
|
+
unListen();
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
try {
|
|
627
|
+
if ('url' in option) {
|
|
628
|
+
var pathPieces = processNavigateUrl(option);
|
|
629
|
+
var state = {
|
|
630
|
+
timestamp: Date.now()
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
if (method === 'navigateTo') {
|
|
634
|
+
exports.history.push(pathPieces, state);
|
|
635
|
+
} else if (method === 'redirectTo') {
|
|
636
|
+
exports.history.replace(pathPieces, state);
|
|
637
|
+
}
|
|
638
|
+
} else if (method === 'navigateBack') {
|
|
639
|
+
stacks.delta = option.delta;
|
|
640
|
+
exports.history.go(-option.delta);
|
|
641
|
+
}
|
|
642
|
+
} catch (error) {
|
|
643
|
+
fail === null || fail === void 0 ? void 0 : fail(error);
|
|
644
|
+
complete === null || complete === void 0 ? void 0 : complete();
|
|
645
|
+
reject(error);
|
|
646
|
+
}
|
|
647
|
+
}));
|
|
648
|
+
|
|
649
|
+
case 1:
|
|
650
|
+
case "end":
|
|
651
|
+
return _context.stop();
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}, _callee);
|
|
655
|
+
}));
|
|
656
|
+
return _navigate.apply(this, arguments);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function navigateTo(option) {
|
|
660
|
+
return navigate(option, 'navigateTo');
|
|
661
|
+
}
|
|
662
|
+
function redirectTo(option) {
|
|
663
|
+
return navigate(option, 'redirectTo');
|
|
664
|
+
}
|
|
665
|
+
function navigateBack() {
|
|
666
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
667
|
+
delta: 1
|
|
668
|
+
};
|
|
233
669
|
|
|
670
|
+
if (!options.delta || options.delta < 1) {
|
|
671
|
+
options.delta = 1;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
return navigate(options, 'navigateBack');
|
|
675
|
+
}
|
|
676
|
+
function switchTab(option) {
|
|
677
|
+
// TODO: 清除掉所有的栈去目标页面
|
|
678
|
+
return redirectTo(option);
|
|
679
|
+
}
|
|
680
|
+
function reLaunch(option) {
|
|
681
|
+
// TODO: 清除掉所有的栈去目标页面
|
|
682
|
+
return redirectTo(option);
|
|
683
|
+
}
|
|
684
|
+
function getCurrentPages() {
|
|
685
|
+
return stacks.get();
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
var pathToRegexp$2 = {exports: {}};
|
|
689
|
+
|
|
690
|
+
pathToRegexp$2.exports = pathToRegexp;
|
|
691
|
+
pathToRegexp$2.exports.match = match;
|
|
692
|
+
pathToRegexp$2.exports.regexpToFunction = regexpToFunction;
|
|
693
|
+
pathToRegexp$2.exports.parse = parse;
|
|
694
|
+
pathToRegexp$2.exports.compile = compile;
|
|
695
|
+
pathToRegexp$2.exports.tokensToFunction = tokensToFunction;
|
|
696
|
+
pathToRegexp$2.exports.tokensToRegExp = tokensToRegExp;
|
|
234
697
|
/**
|
|
235
698
|
* Default configs.
|
|
236
699
|
*/
|
|
237
|
-
var DEFAULT_DELIMITER = '/';
|
|
238
700
|
|
|
701
|
+
var DEFAULT_DELIMITER = '/';
|
|
239
702
|
/**
|
|
240
703
|
* The main path matching regexp utility.
|
|
241
704
|
*
|
|
242
705
|
* @type {RegExp}
|
|
243
706
|
*/
|
|
244
|
-
var PATH_REGEXP = new RegExp([
|
|
245
|
-
// Match escaped characters that would otherwise appear in future matches.
|
|
246
|
-
// This allows the user to escape special characters that won't transform.
|
|
247
|
-
'(\\\\.)',
|
|
248
|
-
// Match Express-style parameters and un-named parameters with a prefix
|
|
249
|
-
// and optional suffixes. Matches appear as:
|
|
250
|
-
//
|
|
251
|
-
// ":test(\\d+)?" => ["test", "\d+", undefined, "?"]
|
|
252
|
-
// "(\\d+)" => [undefined, undefined, "\d+", undefined]
|
|
253
|
-
'(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'
|
|
254
|
-
].join('|'), 'g');
|
|
255
707
|
|
|
708
|
+
var PATH_REGEXP = new RegExp([// Match escaped characters that would otherwise appear in future matches.
|
|
709
|
+
// This allows the user to escape special characters that won't transform.
|
|
710
|
+
'(\\\\.)', // Match Express-style parameters and un-named parameters with a prefix
|
|
711
|
+
// and optional suffixes. Matches appear as:
|
|
712
|
+
//
|
|
713
|
+
// ":test(\\d+)?" => ["test", "\d+", undefined, "?"]
|
|
714
|
+
// "(\\d+)" => [undefined, undefined, "\d+", undefined]
|
|
715
|
+
'(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'].join('|'), 'g');
|
|
256
716
|
/**
|
|
257
717
|
* Parse a string for the raw tokens.
|
|
258
718
|
*
|
|
@@ -260,13 +720,14 @@ var PATH_REGEXP = new RegExp([
|
|
|
260
720
|
* @param {Object=} options
|
|
261
721
|
* @return {!Array}
|
|
262
722
|
*/
|
|
263
|
-
|
|
723
|
+
|
|
724
|
+
function parse(str, options) {
|
|
264
725
|
var tokens = [];
|
|
265
726
|
var key = 0;
|
|
266
727
|
var index = 0;
|
|
267
728
|
var path = '';
|
|
268
|
-
var defaultDelimiter =
|
|
269
|
-
var whitelist =
|
|
729
|
+
var defaultDelimiter = options && options.delimiter || DEFAULT_DELIMITER;
|
|
730
|
+
var whitelist = options && options.whitelist || undefined;
|
|
270
731
|
var pathEscaped = false;
|
|
271
732
|
var res;
|
|
272
733
|
|
|
@@ -275,13 +736,12 @@ function parse (str, options) {
|
|
|
275
736
|
var escaped = res[1];
|
|
276
737
|
var offset = res.index;
|
|
277
738
|
path += str.slice(index, offset);
|
|
278
|
-
index = offset + m.length;
|
|
739
|
+
index = offset + m.length; // Ignore already escaped sequences.
|
|
279
740
|
|
|
280
|
-
// Ignore already escaped sequences.
|
|
281
741
|
if (escaped) {
|
|
282
742
|
path += escaped[1];
|
|
283
743
|
pathEscaped = true;
|
|
284
|
-
continue
|
|
744
|
+
continue;
|
|
285
745
|
}
|
|
286
746
|
|
|
287
747
|
var prev = '';
|
|
@@ -299,9 +759,9 @@ function parse (str, options) {
|
|
|
299
759
|
prev = c;
|
|
300
760
|
path = path.slice(0, k);
|
|
301
761
|
}
|
|
302
|
-
}
|
|
762
|
+
} // Push the current path onto the tokens.
|
|
763
|
+
|
|
303
764
|
|
|
304
|
-
// Push the current path onto the tokens.
|
|
305
765
|
if (path) {
|
|
306
766
|
tokens.push(path);
|
|
307
767
|
path = '';
|
|
@@ -312,27 +772,23 @@ function parse (str, options) {
|
|
|
312
772
|
var optional = modifier === '?' || modifier === '*';
|
|
313
773
|
var pattern = capture || group;
|
|
314
774
|
var delimiter = prev || defaultDelimiter;
|
|
315
|
-
|
|
316
775
|
tokens.push({
|
|
317
776
|
name: name || key++,
|
|
318
777
|
prefix: prev,
|
|
319
778
|
delimiter: delimiter,
|
|
320
779
|
optional: optional,
|
|
321
780
|
repeat: repeat,
|
|
322
|
-
pattern: pattern
|
|
323
|
-
? escapeGroup(pattern)
|
|
324
|
-
: '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : (delimiter + defaultDelimiter)) + ']+?'
|
|
781
|
+
pattern: pattern ? escapeGroup(pattern) : '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : delimiter + defaultDelimiter) + ']+?'
|
|
325
782
|
});
|
|
326
|
-
}
|
|
783
|
+
} // Push any remaining characters.
|
|
784
|
+
|
|
327
785
|
|
|
328
|
-
// Push any remaining characters.
|
|
329
786
|
if (path || index < str.length) {
|
|
330
787
|
tokens.push(path + str.substr(index));
|
|
331
788
|
}
|
|
332
789
|
|
|
333
|
-
return tokens
|
|
790
|
+
return tokens;
|
|
334
791
|
}
|
|
335
|
-
|
|
336
792
|
/**
|
|
337
793
|
* Compile a string to a template function for the path.
|
|
338
794
|
*
|
|
@@ -340,67 +796,73 @@ function parse (str, options) {
|
|
|
340
796
|
* @param {Object=} options
|
|
341
797
|
* @return {!function(Object=, Object=)}
|
|
342
798
|
*/
|
|
343
|
-
function compile (str, options) {
|
|
344
|
-
return tokensToFunction(parse(str, options), options)
|
|
345
|
-
}
|
|
346
799
|
|
|
800
|
+
|
|
801
|
+
function compile(str, options) {
|
|
802
|
+
return tokensToFunction(parse(str, options), options);
|
|
803
|
+
}
|
|
347
804
|
/**
|
|
348
805
|
* Create path match function from `path-to-regexp` spec.
|
|
349
806
|
*/
|
|
350
|
-
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
function match(str, options) {
|
|
351
810
|
var keys = [];
|
|
352
811
|
var re = pathToRegexp(str, keys, options);
|
|
353
|
-
return regexpToFunction(re, keys)
|
|
812
|
+
return regexpToFunction(re, keys);
|
|
354
813
|
}
|
|
355
|
-
|
|
356
814
|
/**
|
|
357
815
|
* Create a path match function from `path-to-regexp` output.
|
|
358
816
|
*/
|
|
359
|
-
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
function regexpToFunction(re, keys) {
|
|
360
820
|
return function (pathname, options) {
|
|
361
821
|
var m = re.exec(pathname);
|
|
362
|
-
if (!m)
|
|
363
|
-
|
|
822
|
+
if (!m) return false;
|
|
364
823
|
var path = m[0];
|
|
365
824
|
var index = m.index;
|
|
366
825
|
var params = {};
|
|
367
|
-
var decode =
|
|
826
|
+
var decode = options && options.decode || decodeURIComponent;
|
|
368
827
|
|
|
369
828
|
for (var i = 1; i < m.length; i++) {
|
|
370
|
-
if (m[i] === undefined)
|
|
371
|
-
|
|
829
|
+
if (m[i] === undefined) continue;
|
|
372
830
|
var key = keys[i - 1];
|
|
373
831
|
|
|
374
832
|
if (key.repeat) {
|
|
375
833
|
params[key.name] = m[i].split(key.delimiter).map(function (value) {
|
|
376
|
-
return decode(value, key)
|
|
834
|
+
return decode(value, key);
|
|
377
835
|
});
|
|
378
836
|
} else {
|
|
379
837
|
params[key.name] = decode(m[i], key);
|
|
380
838
|
}
|
|
381
839
|
}
|
|
382
840
|
|
|
383
|
-
return {
|
|
384
|
-
|
|
841
|
+
return {
|
|
842
|
+
path: path,
|
|
843
|
+
index: index,
|
|
844
|
+
params: params
|
|
845
|
+
};
|
|
846
|
+
};
|
|
385
847
|
}
|
|
386
|
-
|
|
387
848
|
/**
|
|
388
849
|
* Expose a method for transforming tokens into the path function.
|
|
389
850
|
*/
|
|
390
|
-
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
function tokensToFunction(tokens, options) {
|
|
391
854
|
// Compile all the tokens into regexps.
|
|
392
|
-
var matches = new Array(tokens.length);
|
|
855
|
+
var matches = new Array(tokens.length); // Compile all the patterns before compilation.
|
|
393
856
|
|
|
394
|
-
// Compile all the patterns before compilation.
|
|
395
857
|
for (var i = 0; i < tokens.length; i++) {
|
|
396
|
-
if (
|
|
858
|
+
if (_typeof__default['default'](tokens[i]) === 'object') {
|
|
397
859
|
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options));
|
|
398
860
|
}
|
|
399
861
|
}
|
|
400
862
|
|
|
401
863
|
return function (data, options) {
|
|
402
864
|
var path = '';
|
|
403
|
-
var encode =
|
|
865
|
+
var encode = options && options.encode || encodeURIComponent;
|
|
404
866
|
var validate = options ? options.validate !== false : true;
|
|
405
867
|
|
|
406
868
|
for (var i = 0; i < tokens.length; i++) {
|
|
@@ -408,7 +870,7 @@ function tokensToFunction (tokens, options) {
|
|
|
408
870
|
|
|
409
871
|
if (typeof token === 'string') {
|
|
410
872
|
path += token;
|
|
411
|
-
continue
|
|
873
|
+
continue;
|
|
412
874
|
}
|
|
413
875
|
|
|
414
876
|
var value = data ? data[token.name] : undefined;
|
|
@@ -416,78 +878,78 @@ function tokensToFunction (tokens, options) {
|
|
|
416
878
|
|
|
417
879
|
if (Array.isArray(value)) {
|
|
418
880
|
if (!token.repeat) {
|
|
419
|
-
throw new TypeError('Expected "' + token.name + '" to not repeat, but got array')
|
|
881
|
+
throw new TypeError('Expected "' + token.name + '" to not repeat, but got array');
|
|
420
882
|
}
|
|
421
883
|
|
|
422
884
|
if (value.length === 0) {
|
|
423
|
-
if (token.optional)
|
|
424
|
-
|
|
425
|
-
throw new TypeError('Expected "' + token.name + '" to not be empty')
|
|
885
|
+
if (token.optional) continue;
|
|
886
|
+
throw new TypeError('Expected "' + token.name + '" to not be empty');
|
|
426
887
|
}
|
|
427
888
|
|
|
428
889
|
for (var j = 0; j < value.length; j++) {
|
|
429
890
|
segment = encode(value[j], token);
|
|
430
891
|
|
|
431
892
|
if (validate && !matches[i].test(segment)) {
|
|
432
|
-
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"')
|
|
893
|
+
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"');
|
|
433
894
|
}
|
|
434
895
|
|
|
435
896
|
path += (j === 0 ? token.prefix : token.delimiter) + segment;
|
|
436
897
|
}
|
|
437
898
|
|
|
438
|
-
continue
|
|
899
|
+
continue;
|
|
439
900
|
}
|
|
440
901
|
|
|
441
902
|
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
442
903
|
segment = encode(String(value), token);
|
|
443
904
|
|
|
444
905
|
if (validate && !matches[i].test(segment)) {
|
|
445
|
-
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"')
|
|
906
|
+
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"');
|
|
446
907
|
}
|
|
447
908
|
|
|
448
909
|
path += token.prefix + segment;
|
|
449
|
-
continue
|
|
910
|
+
continue;
|
|
450
911
|
}
|
|
451
912
|
|
|
452
|
-
if (token.optional)
|
|
453
|
-
|
|
454
|
-
throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string'))
|
|
913
|
+
if (token.optional) continue;
|
|
914
|
+
throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string'));
|
|
455
915
|
}
|
|
456
916
|
|
|
457
|
-
return path
|
|
458
|
-
}
|
|
917
|
+
return path;
|
|
918
|
+
};
|
|
459
919
|
}
|
|
460
|
-
|
|
461
920
|
/**
|
|
462
921
|
* Escape a regular expression string.
|
|
463
922
|
*
|
|
464
923
|
* @param {string} str
|
|
465
924
|
* @return {string}
|
|
466
925
|
*/
|
|
467
|
-
function escapeString (str) {
|
|
468
|
-
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
|
|
469
|
-
}
|
|
470
926
|
|
|
927
|
+
|
|
928
|
+
function escapeString(str) {
|
|
929
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1');
|
|
930
|
+
}
|
|
471
931
|
/**
|
|
472
932
|
* Escape the capturing group by escaping special characters and meaning.
|
|
473
933
|
*
|
|
474
934
|
* @param {string} group
|
|
475
935
|
* @return {string}
|
|
476
936
|
*/
|
|
477
|
-
function escapeGroup (group) {
|
|
478
|
-
return group.replace(/([=!:$/()])/g, '\\$1')
|
|
479
|
-
}
|
|
480
937
|
|
|
938
|
+
|
|
939
|
+
function escapeGroup(group) {
|
|
940
|
+
return group.replace(/([=!:$/()])/g, '\\$1');
|
|
941
|
+
}
|
|
481
942
|
/**
|
|
482
943
|
* Get the flags for a regexp from the options.
|
|
483
944
|
*
|
|
484
945
|
* @param {Object} options
|
|
485
946
|
* @return {string}
|
|
486
947
|
*/
|
|
487
|
-
function flags (options) {
|
|
488
|
-
return options && options.sensitive ? '' : 'i'
|
|
489
|
-
}
|
|
490
948
|
|
|
949
|
+
|
|
950
|
+
function flags(options) {
|
|
951
|
+
return options && options.sensitive ? '' : 'i';
|
|
952
|
+
}
|
|
491
953
|
/**
|
|
492
954
|
* Pull out keys from a regexp.
|
|
493
955
|
*
|
|
@@ -495,10 +957,11 @@ function flags (options) {
|
|
|
495
957
|
* @param {Array=} keys
|
|
496
958
|
* @return {!RegExp}
|
|
497
959
|
*/
|
|
498
|
-
function regexpToRegexp (path, keys) {
|
|
499
|
-
if (!keys) { return path }
|
|
500
960
|
|
|
501
|
-
|
|
961
|
+
|
|
962
|
+
function regexpToRegexp(path, keys) {
|
|
963
|
+
if (!keys) return path; // Use a negative lookahead to match only capturing groups.
|
|
964
|
+
|
|
502
965
|
var groups = path.source.match(/\((?!\?)/g);
|
|
503
966
|
|
|
504
967
|
if (groups) {
|
|
@@ -514,9 +977,8 @@ function regexpToRegexp (path, keys) {
|
|
|
514
977
|
}
|
|
515
978
|
}
|
|
516
979
|
|
|
517
|
-
return path
|
|
980
|
+
return path;
|
|
518
981
|
}
|
|
519
|
-
|
|
520
982
|
/**
|
|
521
983
|
* Transform an array into a regexp.
|
|
522
984
|
*
|
|
@@ -525,16 +987,17 @@ function regexpToRegexp (path, keys) {
|
|
|
525
987
|
* @param {Object=} options
|
|
526
988
|
* @return {!RegExp}
|
|
527
989
|
*/
|
|
528
|
-
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
function arrayToRegexp(path, keys, options) {
|
|
529
993
|
var parts = [];
|
|
530
994
|
|
|
531
995
|
for (var i = 0; i < path.length; i++) {
|
|
532
996
|
parts.push(pathToRegexp(path[i], keys, options).source);
|
|
533
997
|
}
|
|
534
998
|
|
|
535
|
-
return new RegExp('(?:' + parts.join('|') + ')', flags(options))
|
|
999
|
+
return new RegExp('(?:' + parts.join('|') + ')', flags(options));
|
|
536
1000
|
}
|
|
537
|
-
|
|
538
1001
|
/**
|
|
539
1002
|
* Create a path regexp from string input.
|
|
540
1003
|
*
|
|
@@ -543,10 +1006,11 @@ function arrayToRegexp (path, keys, options) {
|
|
|
543
1006
|
* @param {Object=} options
|
|
544
1007
|
* @return {!RegExp}
|
|
545
1008
|
*/
|
|
546
|
-
function stringToRegexp (path, keys, options) {
|
|
547
|
-
return tokensToRegExp(parse(path, options), keys, options)
|
|
548
|
-
}
|
|
549
1009
|
|
|
1010
|
+
|
|
1011
|
+
function stringToRegexp(path, keys, options) {
|
|
1012
|
+
return tokensToRegExp(parse(path, options), keys, options);
|
|
1013
|
+
}
|
|
550
1014
|
/**
|
|
551
1015
|
* Expose a function for taking tokens and returning a RegExp.
|
|
552
1016
|
*
|
|
@@ -555,28 +1019,25 @@ function stringToRegexp (path, keys, options) {
|
|
|
555
1019
|
* @param {Object=} options
|
|
556
1020
|
* @return {!RegExp}
|
|
557
1021
|
*/
|
|
558
|
-
function tokensToRegExp (tokens, keys, options) {
|
|
559
|
-
options = options || {};
|
|
560
1022
|
|
|
1023
|
+
|
|
1024
|
+
function tokensToRegExp(tokens, keys, options) {
|
|
1025
|
+
options = options || {};
|
|
561
1026
|
var strict = options.strict;
|
|
562
1027
|
var start = options.start !== false;
|
|
563
1028
|
var end = options.end !== false;
|
|
564
1029
|
var delimiter = options.delimiter || DEFAULT_DELIMITER;
|
|
565
1030
|
var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|');
|
|
566
|
-
var route = start ? '^' : '';
|
|
1031
|
+
var route = start ? '^' : ''; // Iterate over the tokens and create our regexp string.
|
|
567
1032
|
|
|
568
|
-
// Iterate over the tokens and create our regexp string.
|
|
569
1033
|
for (var i = 0; i < tokens.length; i++) {
|
|
570
1034
|
var token = tokens[i];
|
|
571
1035
|
|
|
572
1036
|
if (typeof token === 'string') {
|
|
573
1037
|
route += escapeString(token);
|
|
574
1038
|
} else {
|
|
575
|
-
var capture = token.repeat
|
|
576
|
-
|
|
577
|
-
: token.pattern;
|
|
578
|
-
|
|
579
|
-
if (keys) { keys.push(token); }
|
|
1039
|
+
var capture = token.repeat ? '(?:' + token.pattern + ')(?:' + escapeString(token.delimiter) + '(?:' + token.pattern + '))*' : token.pattern;
|
|
1040
|
+
if (keys) keys.push(token);
|
|
580
1041
|
|
|
581
1042
|
if (token.optional) {
|
|
582
1043
|
if (!token.prefix) {
|
|
@@ -591,22 +1052,17 @@ function tokensToRegExp (tokens, keys, options) {
|
|
|
591
1052
|
}
|
|
592
1053
|
|
|
593
1054
|
if (end) {
|
|
594
|
-
if (!strict)
|
|
595
|
-
|
|
1055
|
+
if (!strict) route += '(?:' + escapeString(delimiter) + ')?';
|
|
596
1056
|
route += endsWith === '$' ? '$' : '(?=' + endsWith + ')';
|
|
597
1057
|
} else {
|
|
598
1058
|
var endToken = tokens[tokens.length - 1];
|
|
599
|
-
var isEndDelimited = typeof endToken === 'string'
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
if (!strict) { route += '(?:' + escapeString(delimiter) + '(?=' + endsWith + '))?'; }
|
|
604
|
-
if (!isEndDelimited) { route += '(?=' + escapeString(delimiter) + '|' + endsWith + ')'; }
|
|
1059
|
+
var isEndDelimited = typeof endToken === 'string' ? endToken[endToken.length - 1] === delimiter : endToken === undefined;
|
|
1060
|
+
if (!strict) route += '(?:' + escapeString(delimiter) + '(?=' + endsWith + '))?';
|
|
1061
|
+
if (!isEndDelimited) route += '(?=' + escapeString(delimiter) + '|' + endsWith + ')';
|
|
605
1062
|
}
|
|
606
1063
|
|
|
607
|
-
return new RegExp(route, flags(options))
|
|
1064
|
+
return new RegExp(route, flags(options));
|
|
608
1065
|
}
|
|
609
|
-
|
|
610
1066
|
/**
|
|
611
1067
|
* Normalize the given path string, returning a regular expression.
|
|
612
1068
|
*
|
|
@@ -619,25 +1075,21 @@ function tokensToRegExp (tokens, keys, options) {
|
|
|
619
1075
|
* @param {Object=} options
|
|
620
1076
|
* @return {!RegExp}
|
|
621
1077
|
*/
|
|
622
|
-
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
function pathToRegexp(path, keys, options) {
|
|
623
1081
|
if (path instanceof RegExp) {
|
|
624
|
-
return regexpToRegexp(path, keys)
|
|
1082
|
+
return regexpToRegexp(path, keys);
|
|
625
1083
|
}
|
|
626
1084
|
|
|
627
1085
|
if (Array.isArray(path)) {
|
|
628
|
-
return arrayToRegexp(
|
|
1086
|
+
return arrayToRegexp(path, keys, options);
|
|
629
1087
|
}
|
|
630
1088
|
|
|
631
|
-
return stringToRegexp(
|
|
1089
|
+
return stringToRegexp(path, keys, options);
|
|
632
1090
|
}
|
|
633
|
-
pathToRegexp_1.match = match_1;
|
|
634
|
-
pathToRegexp_1.regexpToFunction = regexpToFunction_1;
|
|
635
|
-
pathToRegexp_1.parse = parse_1;
|
|
636
|
-
pathToRegexp_1.compile = compile_1;
|
|
637
|
-
pathToRegexp_1.tokensToFunction = tokensToFunction_1;
|
|
638
|
-
pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
|
|
639
1091
|
|
|
640
|
-
|
|
1092
|
+
var pathToRegexp$1 = pathToRegexp$2.exports;
|
|
641
1093
|
|
|
642
1094
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
643
1095
|
var cache = new Map();
|
|
@@ -659,7 +1111,7 @@ function matchPath(route, pathname, parentKeys, parentParams) {
|
|
|
659
1111
|
var keys = [];
|
|
660
1112
|
regexp = {
|
|
661
1113
|
keys: keys,
|
|
662
|
-
pattern:
|
|
1114
|
+
pattern: pathToRegexp$1(route.path || '', keys, {
|
|
663
1115
|
end: end
|
|
664
1116
|
})
|
|
665
1117
|
};
|
|
@@ -782,7 +1234,7 @@ var UniversalRouter = function () {
|
|
|
782
1234
|
options = {};
|
|
783
1235
|
}
|
|
784
1236
|
|
|
785
|
-
if (!routes ||
|
|
1237
|
+
if (!routes || _typeof__default['default'](routes) !== 'object') {
|
|
786
1238
|
throw new TypeError('Invalid routes');
|
|
787
1239
|
}
|
|
788
1240
|
|
|
@@ -861,871 +1313,975 @@ var UniversalRouter = function () {
|
|
|
861
1313
|
return UniversalRouter;
|
|
862
1314
|
}();
|
|
863
1315
|
|
|
864
|
-
UniversalRouter.pathToRegexp =
|
|
865
|
-
|
|
866
|
-
var Taro = require('@tarojs/taro-h5');
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1316
|
+
UniversalRouter.pathToRegexp = pathToRegexp$1;
|
|
1317
|
+
|
|
1318
|
+
var Taro = require('@tarojs/taro-h5');
|
|
1319
|
+
|
|
1320
|
+
function initTabbar(config) {
|
|
1321
|
+
if (config.tabBar == null) {
|
|
1322
|
+
return;
|
|
1323
|
+
} // TODO: 找到 tabbar 的类型
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
var tabbar = document.createElement('taro-tabbar');
|
|
1327
|
+
var homePage = config.pages ? config.pages[0] : '';
|
|
1328
|
+
tabbar.conf = config.tabBar;
|
|
1329
|
+
tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
|
|
1330
|
+
var routerConfig = config.router;
|
|
1331
|
+
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
1332
|
+
|
|
1333
|
+
if (routerConfig.customRoutes) {
|
|
1334
|
+
tabbar.conf.custom = true;
|
|
1335
|
+
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
1336
|
+
} else {
|
|
1337
|
+
tabbar.conf.custom = false;
|
|
1338
|
+
tabbar.conf.customRoutes = {};
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
if (typeof routerConfig.basename !== 'undefined') {
|
|
1342
|
+
tabbar.conf.basename = routerConfig.basename;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
var container = document.getElementById('container'); // eslint-disable-next-line no-unused-expressions
|
|
1346
|
+
|
|
1347
|
+
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
1348
|
+
Taro.initTabBarApis(config);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
var routerConfig = Object.create(null);
|
|
1352
|
+
function init(config) {
|
|
1353
|
+
var _document$getElementB;
|
|
1354
|
+
|
|
1355
|
+
config.router.mode = config.router.mode || 'hash';
|
|
1356
|
+
setHistoryMode(config.router.mode, config.router.basename);
|
|
1357
|
+
Object.assign(routerConfig, config);
|
|
1358
|
+
(_document$getElementB = document.getElementById('app')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
1359
|
+
var container = document.createElement('div');
|
|
1360
|
+
container.classList.add('taro-tabbar__container');
|
|
1361
|
+
container.id = 'container';
|
|
1362
|
+
var panel = document.createElement('div');
|
|
1363
|
+
panel.classList.add('taro-tabbar__panel');
|
|
1364
|
+
var app = document.createElement('div');
|
|
1365
|
+
app.id = 'app';
|
|
1366
|
+
app.classList.add('taro_router');
|
|
1367
|
+
panel.appendChild(app);
|
|
1368
|
+
container.appendChild(panel);
|
|
1369
|
+
document.body.appendChild(container);
|
|
1370
|
+
initTabbar(config);
|
|
893
1371
|
}
|
|
894
1372
|
|
|
895
|
-
var
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1373
|
+
var pageScrollFn;
|
|
1374
|
+
var pageDOM = window;
|
|
1375
|
+
function bindPageScroll(page, config) {
|
|
1376
|
+
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
1377
|
+
pageDOM = getScrollContainer();
|
|
1378
|
+
var distance = config.onReachBottomDistance || 50;
|
|
1379
|
+
var isReachBottom = false;
|
|
1380
|
+
|
|
1381
|
+
pageScrollFn = function pageScrollFn() {
|
|
1382
|
+
page.onPageScroll && page.onPageScroll({
|
|
1383
|
+
scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
if (isReachBottom && getOffset() > distance) {
|
|
1387
|
+
isReachBottom = false;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
if (page.onReachBottom && !isReachBottom && getOffset() < distance) {
|
|
1391
|
+
isReachBottom = true;
|
|
1392
|
+
page.onReachBottom();
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
914
1397
|
}
|
|
1398
|
+
window.addEventListener('DOMSubtreeModified', function (e) {
|
|
1399
|
+
var _e$target;
|
|
1400
|
+
|
|
1401
|
+
// @ts-ignore
|
|
1402
|
+
var className = (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.className;
|
|
1403
|
+
|
|
1404
|
+
if (className && /taro-tabbar__/.test(className)) {
|
|
1405
|
+
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
1406
|
+
pageDOM = getScrollContainer();
|
|
1407
|
+
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
1408
|
+
}
|
|
1409
|
+
}, false);
|
|
915
1410
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
page.onPageScroll && page.onPageScroll({
|
|
925
|
-
scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
|
|
926
|
-
});
|
|
927
|
-
if (isReachBottom && getOffset() > distance) {
|
|
928
|
-
isReachBottom = false;
|
|
929
|
-
}
|
|
930
|
-
if (page.onReachBottom &&
|
|
931
|
-
!isReachBottom &&
|
|
932
|
-
getOffset() < distance) {
|
|
933
|
-
isReachBottom = true;
|
|
934
|
-
page.onReachBottom();
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
938
|
-
}
|
|
939
|
-
window.addEventListener('DOMSubtreeModified', function (e) {
|
|
940
|
-
var _a;
|
|
941
|
-
// @ts-ignore
|
|
942
|
-
var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
|
|
943
|
-
if (className && /taro-tabbar__/.test(className)) {
|
|
944
|
-
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
945
|
-
pageDOM = getScrollContainer();
|
|
946
|
-
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
947
|
-
}
|
|
948
|
-
}, false);
|
|
949
|
-
function getScrollContainer() {
|
|
950
|
-
if (document.querySelector('.taro-tabbar__tabbar') === null) {
|
|
951
|
-
// 没设置tabbar
|
|
952
|
-
return window;
|
|
953
|
-
}
|
|
954
|
-
else {
|
|
955
|
-
// 有设置tabbar
|
|
956
|
-
return document.querySelector('.taro-tabbar__panel') || window;
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
function getOffset() {
|
|
960
|
-
if (pageDOM instanceof Window) {
|
|
961
|
-
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
|
|
962
|
-
}
|
|
963
|
-
else {
|
|
964
|
-
return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
|
|
965
|
-
}
|
|
1411
|
+
function getScrollContainer() {
|
|
1412
|
+
if (document.querySelector('.taro-tabbar__tabbar') === null) {
|
|
1413
|
+
// 没设置tabbar
|
|
1414
|
+
return window;
|
|
1415
|
+
} else {
|
|
1416
|
+
// 有设置tabbar
|
|
1417
|
+
return document.querySelector('.taro-tabbar__panel') || window;
|
|
1418
|
+
}
|
|
966
1419
|
}
|
|
967
1420
|
|
|
968
|
-
function
|
|
969
|
-
|
|
1421
|
+
function getOffset() {
|
|
1422
|
+
if (pageDOM instanceof Window) {
|
|
1423
|
+
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
|
|
1424
|
+
} else {
|
|
1425
|
+
return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
|
|
1426
|
+
}
|
|
970
1427
|
}
|
|
971
1428
|
|
|
972
|
-
var
|
|
1429
|
+
var queryString = {};
|
|
1430
|
+
|
|
1431
|
+
var strictUriEncode = function strictUriEncode(str) {
|
|
1432
|
+
return encodeURIComponent(str).replace(/[!'()*]/g, function (x) {
|
|
1433
|
+
return "%".concat(x.charCodeAt(0).toString(16).toUpperCase());
|
|
1434
|
+
});
|
|
1435
|
+
};
|
|
973
1436
|
|
|
974
1437
|
var token = '%[a-f0-9]{2}';
|
|
975
1438
|
var singleMatcher = new RegExp(token, 'gi');
|
|
976
1439
|
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
|
977
1440
|
|
|
978
1441
|
function decodeComponents(components, split) {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
if (components.length === 1) {
|
|
987
|
-
return components;
|
|
988
|
-
}
|
|
1442
|
+
try {
|
|
1443
|
+
// Try to decode the entire string first
|
|
1444
|
+
return decodeURIComponent(components.join(''));
|
|
1445
|
+
} catch (err) {// Do nothing
|
|
1446
|
+
}
|
|
989
1447
|
|
|
990
|
-
|
|
1448
|
+
if (components.length === 1) {
|
|
1449
|
+
return components;
|
|
1450
|
+
}
|
|
991
1451
|
|
|
992
|
-
|
|
993
|
-
var left = components.slice(0, split);
|
|
994
|
-
var right = components.slice(split);
|
|
1452
|
+
split = split || 1; // Split the array in 2 parts
|
|
995
1453
|
|
|
996
|
-
|
|
1454
|
+
var left = components.slice(0, split);
|
|
1455
|
+
var right = components.slice(split);
|
|
1456
|
+
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
|
|
997
1457
|
}
|
|
998
1458
|
|
|
999
1459
|
function decode(input) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
for (var i = 1; i < tokens.length; i++) {
|
|
1006
|
-
input = decodeComponents(tokens, i).join('');
|
|
1460
|
+
try {
|
|
1461
|
+
return decodeURIComponent(input);
|
|
1462
|
+
} catch (err) {
|
|
1463
|
+
var tokens = input.match(singleMatcher);
|
|
1007
1464
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1465
|
+
for (var i = 1; i < tokens.length; i++) {
|
|
1466
|
+
input = decodeComponents(tokens, i).join('');
|
|
1467
|
+
tokens = input.match(singleMatcher);
|
|
1468
|
+
}
|
|
1010
1469
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1470
|
+
return input;
|
|
1471
|
+
}
|
|
1013
1472
|
}
|
|
1014
1473
|
|
|
1015
1474
|
function customDecodeURIComponent(input) {
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
return input;
|
|
1475
|
+
// Keep track of all the replacements and prefill the map with the `BOM`
|
|
1476
|
+
var replaceMap = {
|
|
1477
|
+
'%FE%FF': "\uFFFD\uFFFD",
|
|
1478
|
+
'%FF%FE': "\uFFFD\uFFFD"
|
|
1479
|
+
};
|
|
1480
|
+
var match = multiMatcher.exec(input);
|
|
1481
|
+
|
|
1482
|
+
while (match) {
|
|
1483
|
+
try {
|
|
1484
|
+
// Decode as big chunks as possible
|
|
1485
|
+
replaceMap[match[0]] = decodeURIComponent(match[0]);
|
|
1486
|
+
} catch (err) {
|
|
1487
|
+
var result = decode(match[0]);
|
|
1488
|
+
|
|
1489
|
+
if (result !== match[0]) {
|
|
1490
|
+
replaceMap[match[0]] = result;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
match = multiMatcher.exec(input);
|
|
1495
|
+
} // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
replaceMap['%C2'] = "\uFFFD";
|
|
1499
|
+
var entries = Object.keys(replaceMap);
|
|
1500
|
+
|
|
1501
|
+
for (var i = 0; i < entries.length; i++) {
|
|
1502
|
+
// Replace all decoded components
|
|
1503
|
+
var key = entries[i];
|
|
1504
|
+
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
return input;
|
|
1050
1508
|
}
|
|
1051
1509
|
|
|
1052
|
-
var decodeUriComponent = function (encodedURI) {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1510
|
+
var decodeUriComponent = function decodeUriComponent(encodedURI) {
|
|
1511
|
+
if (typeof encodedURI !== 'string') {
|
|
1512
|
+
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + _typeof__default['default'](encodedURI) + '`');
|
|
1513
|
+
}
|
|
1056
1514
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1515
|
+
try {
|
|
1516
|
+
encodedURI = encodedURI.replace(/\+/g, ' '); // Try the built in decoder first
|
|
1059
1517
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
}
|
|
1518
|
+
return decodeURIComponent(encodedURI);
|
|
1519
|
+
} catch (err) {
|
|
1520
|
+
// Fallback to a more advanced decoder
|
|
1521
|
+
return customDecodeURIComponent(encodedURI);
|
|
1522
|
+
}
|
|
1066
1523
|
};
|
|
1067
1524
|
|
|
1068
|
-
var splitOnFirst = function (string, separator) {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1525
|
+
var splitOnFirst = function splitOnFirst(string, separator) {
|
|
1526
|
+
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
|
1527
|
+
throw new TypeError('Expected the arguments to be of type `string`');
|
|
1528
|
+
}
|
|
1072
1529
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1530
|
+
if (separator === '') {
|
|
1531
|
+
return [string];
|
|
1532
|
+
}
|
|
1076
1533
|
|
|
1077
|
-
|
|
1534
|
+
var separatorIndex = string.indexOf(separator);
|
|
1078
1535
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1536
|
+
if (separatorIndex === -1) {
|
|
1537
|
+
return [string];
|
|
1538
|
+
}
|
|
1082
1539
|
|
|
1083
|
-
|
|
1084
|
-
string.slice(0, separatorIndex),
|
|
1085
|
-
string.slice(separatorIndex + separator.length)
|
|
1086
|
-
];
|
|
1540
|
+
return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
|
|
1087
1541
|
};
|
|
1088
1542
|
|
|
1089
|
-
var filterObj = function (obj, predicate) {
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1543
|
+
var filterObj = function filterObj(obj, predicate) {
|
|
1544
|
+
var ret = {};
|
|
1545
|
+
var keys = Object.keys(obj);
|
|
1546
|
+
var isArr = Array.isArray(predicate);
|
|
1093
1547
|
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1548
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1549
|
+
var key = keys[i];
|
|
1550
|
+
var val = obj[key];
|
|
1097
1551
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1552
|
+
if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
|
|
1553
|
+
ret[key] = val;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1102
1556
|
|
|
1103
|
-
|
|
1557
|
+
return ret;
|
|
1104
1558
|
};
|
|
1105
1559
|
|
|
1106
|
-
|
|
1560
|
+
(function (exports) {
|
|
1107
1561
|
|
|
1562
|
+
var strictUriEncode$1 = strictUriEncode;
|
|
1563
|
+
var decodeComponent = decodeUriComponent;
|
|
1564
|
+
var splitOnFirst$1 = splitOnFirst;
|
|
1565
|
+
var filterObject = filterObj;
|
|
1108
1566
|
|
|
1567
|
+
var isNullOrUndefined = function isNullOrUndefined(value) {
|
|
1568
|
+
return value === null || value === undefined;
|
|
1569
|
+
};
|
|
1109
1570
|
|
|
1571
|
+
function encoderForArrayFormat(options) {
|
|
1572
|
+
switch (options.arrayFormat) {
|
|
1573
|
+
case 'index':
|
|
1574
|
+
return function (key) {
|
|
1575
|
+
return function (result, value) {
|
|
1576
|
+
var index = result.length;
|
|
1110
1577
|
|
|
1578
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
1579
|
+
return result;
|
|
1580
|
+
}
|
|
1111
1581
|
|
|
1112
|
-
|
|
1582
|
+
if (value === null) {
|
|
1583
|
+
return [].concat(_toConsumableArray__default['default'](result), [[encode(key, options), '[', index, ']'].join('')]);
|
|
1584
|
+
}
|
|
1113
1585
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
return function (key) { return function (result, value) {
|
|
1118
|
-
var index = result.length;
|
|
1586
|
+
return [].concat(_toConsumableArray__default['default'](result), [[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')]);
|
|
1587
|
+
};
|
|
1588
|
+
};
|
|
1119
1589
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1590
|
+
case 'bracket':
|
|
1591
|
+
return function (key) {
|
|
1592
|
+
return function (result, value) {
|
|
1593
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
1594
|
+
return result;
|
|
1595
|
+
}
|
|
1127
1596
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1597
|
+
if (value === null) {
|
|
1598
|
+
return [].concat(_toConsumableArray__default['default'](result), [[encode(key, options), '[]'].join('')]);
|
|
1599
|
+
}
|
|
1131
1600
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1601
|
+
return [].concat(_toConsumableArray__default['default'](result), [[encode(key, options), '[]=', encode(value, options)].join('')]);
|
|
1602
|
+
};
|
|
1603
|
+
};
|
|
1135
1604
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
return result;
|
|
1144
|
-
}
|
|
1605
|
+
case 'comma':
|
|
1606
|
+
case 'separator':
|
|
1607
|
+
return function (key) {
|
|
1608
|
+
return function (result, value) {
|
|
1609
|
+
if (value === null || value === undefined || value.length === 0) {
|
|
1610
|
+
return result;
|
|
1611
|
+
}
|
|
1145
1612
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1613
|
+
if (result.length === 0) {
|
|
1614
|
+
return [[encode(key, options), '=', encode(value, options)].join('')];
|
|
1615
|
+
}
|
|
1149
1616
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1617
|
+
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
|
|
1618
|
+
};
|
|
1619
|
+
};
|
|
1152
1620
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1621
|
+
default:
|
|
1622
|
+
return function (key) {
|
|
1623
|
+
return function (result, value) {
|
|
1624
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
1625
|
+
return result;
|
|
1626
|
+
}
|
|
1159
1627
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1628
|
+
if (value === null) {
|
|
1629
|
+
return [].concat(_toConsumableArray__default['default'](result), [encode(key, options)]);
|
|
1630
|
+
}
|
|
1163
1631
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1632
|
+
return [].concat(_toConsumableArray__default['default'](result), [[encode(key, options), '=', encode(value, options)].join('')]);
|
|
1633
|
+
};
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1166
1637
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
if (
|
|
1170
|
-
value === undefined ||
|
|
1171
|
-
(options.skipNull && value === null) ||
|
|
1172
|
-
(options.skipEmptyString && value === '')
|
|
1173
|
-
) {
|
|
1174
|
-
return result;
|
|
1175
|
-
}
|
|
1638
|
+
function parserForArrayFormat(options) {
|
|
1639
|
+
var result;
|
|
1176
1640
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1641
|
+
switch (options.arrayFormat) {
|
|
1642
|
+
case 'index':
|
|
1643
|
+
return function (key, value, accumulator) {
|
|
1644
|
+
result = /\[(\d*)\]$/.exec(key);
|
|
1645
|
+
key = key.replace(/\[\d*\]$/, '');
|
|
1180
1646
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
}
|
|
1647
|
+
if (!result) {
|
|
1648
|
+
accumulator[key] = value;
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1185
1651
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
switch (options.arrayFormat) {
|
|
1190
|
-
case 'index':
|
|
1191
|
-
return function (key, value, accumulator) {
|
|
1192
|
-
result = /\[(\d*)\]$/.exec(key);
|
|
1193
|
-
|
|
1194
|
-
key = key.replace(/\[\d*\]$/, '');
|
|
1195
|
-
|
|
1196
|
-
if (!result) {
|
|
1197
|
-
accumulator[key] = value;
|
|
1198
|
-
return;
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
if (accumulator[key] === undefined) {
|
|
1202
|
-
accumulator[key] = {};
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
accumulator[key][result[1]] = value;
|
|
1206
|
-
};
|
|
1207
|
-
|
|
1208
|
-
case 'bracket':
|
|
1209
|
-
return function (key, value, accumulator) {
|
|
1210
|
-
result = /(\[\])$/.exec(key);
|
|
1211
|
-
key = key.replace(/\[\]$/, '');
|
|
1212
|
-
|
|
1213
|
-
if (!result) {
|
|
1214
|
-
accumulator[key] = value;
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
if (accumulator[key] === undefined) {
|
|
1219
|
-
accumulator[key] = [value];
|
|
1220
|
-
return;
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
accumulator[key] = [].concat(accumulator[key], value);
|
|
1224
|
-
};
|
|
1225
|
-
|
|
1226
|
-
case 'comma':
|
|
1227
|
-
case 'separator':
|
|
1228
|
-
return function (key, value, accumulator) {
|
|
1229
|
-
var isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
|
|
1230
|
-
var isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
|
|
1231
|
-
value = isEncodedArray ? decode(value, options) : value;
|
|
1232
|
-
var newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(function (item) { return decode(item, options); }) : value === null ? value : decode(value, options);
|
|
1233
|
-
accumulator[key] = newValue;
|
|
1234
|
-
};
|
|
1235
|
-
|
|
1236
|
-
default:
|
|
1237
|
-
return function (key, value, accumulator) {
|
|
1238
|
-
if (accumulator[key] === undefined) {
|
|
1239
|
-
accumulator[key] = value;
|
|
1240
|
-
return;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
accumulator[key] = [].concat(accumulator[key], value);
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1652
|
+
if (accumulator[key] === undefined) {
|
|
1653
|
+
accumulator[key] = {};
|
|
1654
|
+
}
|
|
1247
1655
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
throw new TypeError('arrayFormatSeparator must be single character string');
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1656
|
+
accumulator[key][result[1]] = value;
|
|
1657
|
+
};
|
|
1253
1658
|
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1659
|
+
case 'bracket':
|
|
1660
|
+
return function (key, value, accumulator) {
|
|
1661
|
+
result = /(\[\])$/.exec(key);
|
|
1662
|
+
key = key.replace(/\[\]$/, '');
|
|
1258
1663
|
|
|
1259
|
-
|
|
1260
|
-
|
|
1664
|
+
if (!result) {
|
|
1665
|
+
accumulator[key] = value;
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1261
1668
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1669
|
+
if (accumulator[key] === undefined) {
|
|
1670
|
+
accumulator[key] = [value];
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1266
1673
|
|
|
1267
|
-
|
|
1268
|
-
}
|
|
1674
|
+
accumulator[key] = [].concat(accumulator[key], value);
|
|
1675
|
+
};
|
|
1269
1676
|
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1677
|
+
case 'comma':
|
|
1678
|
+
case 'separator':
|
|
1679
|
+
return function (key, value, accumulator) {
|
|
1680
|
+
var isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
|
|
1681
|
+
var isEncodedArray = typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator);
|
|
1682
|
+
value = isEncodedArray ? decode(value, options) : value;
|
|
1683
|
+
var newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(function (item) {
|
|
1684
|
+
return decode(item, options);
|
|
1685
|
+
}) : value === null ? value : decode(value, options);
|
|
1686
|
+
accumulator[key] = newValue;
|
|
1687
|
+
};
|
|
1274
1688
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1689
|
+
default:
|
|
1690
|
+
return function (key, value, accumulator) {
|
|
1691
|
+
if (accumulator[key] === undefined) {
|
|
1692
|
+
accumulator[key] = value;
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1280
1695
|
|
|
1281
|
-
|
|
1282
|
-
}
|
|
1696
|
+
accumulator[key] = [].concat(accumulator[key], value);
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1283
1700
|
|
|
1284
|
-
function
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1701
|
+
function validateArrayFormatSeparator(value) {
|
|
1702
|
+
if (typeof value !== 'string' || value.length !== 1) {
|
|
1703
|
+
throw new TypeError('arrayFormatSeparator must be single character string');
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1289
1706
|
|
|
1290
|
-
|
|
1291
|
-
|
|
1707
|
+
function encode(value, options) {
|
|
1708
|
+
if (options.encode) {
|
|
1709
|
+
return options.strict ? strictUriEncode$1(value) : encodeURIComponent(value);
|
|
1710
|
+
}
|
|
1292
1711
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
var hashStart = url.indexOf('#');
|
|
1296
|
-
if (hashStart !== -1) {
|
|
1297
|
-
hash = url.slice(hashStart);
|
|
1298
|
-
}
|
|
1712
|
+
return value;
|
|
1713
|
+
}
|
|
1299
1714
|
|
|
1300
|
-
|
|
1301
|
-
|
|
1715
|
+
function decode(value, options) {
|
|
1716
|
+
if (options.decode) {
|
|
1717
|
+
return decodeComponent(value);
|
|
1718
|
+
}
|
|
1302
1719
|
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
var queryStart = input.indexOf('?');
|
|
1306
|
-
if (queryStart === -1) {
|
|
1307
|
-
return '';
|
|
1308
|
-
}
|
|
1720
|
+
return value;
|
|
1721
|
+
}
|
|
1309
1722
|
|
|
1310
|
-
|
|
1311
|
-
|
|
1723
|
+
function keysSorter(input) {
|
|
1724
|
+
if (Array.isArray(input)) {
|
|
1725
|
+
return input.sort();
|
|
1726
|
+
}
|
|
1312
1727
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1728
|
+
if (_typeof__default['default'](input) === 'object') {
|
|
1729
|
+
return keysSorter(Object.keys(input)).sort(function (a, b) {
|
|
1730
|
+
return Number(a) - Number(b);
|
|
1731
|
+
}).map(function (key) {
|
|
1732
|
+
return input[key];
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1319
1735
|
|
|
1320
|
-
|
|
1321
|
-
}
|
|
1736
|
+
return input;
|
|
1737
|
+
}
|
|
1322
1738
|
|
|
1323
|
-
function
|
|
1324
|
-
|
|
1325
|
-
decode: true,
|
|
1326
|
-
sort: true,
|
|
1327
|
-
arrayFormat: 'none',
|
|
1328
|
-
arrayFormatSeparator: ',',
|
|
1329
|
-
parseNumbers: false,
|
|
1330
|
-
parseBooleans: false
|
|
1331
|
-
}, options);
|
|
1332
|
-
|
|
1333
|
-
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
1334
|
-
|
|
1335
|
-
var formatter = parserForArrayFormat(options);
|
|
1336
|
-
|
|
1337
|
-
// Create an object with no prototype
|
|
1338
|
-
var ret = Object.create(null);
|
|
1339
|
-
|
|
1340
|
-
if (typeof query !== 'string') {
|
|
1341
|
-
return ret;
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
query = query.trim().replace(/^[?#&]/, '');
|
|
1345
|
-
|
|
1346
|
-
if (!query) {
|
|
1347
|
-
return ret;
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
for (var param of query.split('&')) {
|
|
1351
|
-
if (param === '') {
|
|
1352
|
-
continue;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
var ref = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');
|
|
1356
|
-
var key = ref[0];
|
|
1357
|
-
var value = ref[1];
|
|
1358
|
-
|
|
1359
|
-
// Missing `=` should be `null`:
|
|
1360
|
-
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
1361
|
-
value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options);
|
|
1362
|
-
formatter(decode(key, options), value, ret);
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
for (var key$1 of Object.keys(ret)) {
|
|
1366
|
-
var value$1 = ret[key$1];
|
|
1367
|
-
if (typeof value$1 === 'object' && value$1 !== null) {
|
|
1368
|
-
for (var k of Object.keys(value$1)) {
|
|
1369
|
-
value$1[k] = parseValue(value$1[k], options);
|
|
1370
|
-
}
|
|
1371
|
-
} else {
|
|
1372
|
-
ret[key$1] = parseValue(value$1, options);
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
if (options.sort === false) {
|
|
1377
|
-
return ret;
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce(function (result, key) {
|
|
1381
|
-
var value = ret[key];
|
|
1382
|
-
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) {
|
|
1383
|
-
// Sort object keys, not values
|
|
1384
|
-
result[key] = keysSorter(value);
|
|
1385
|
-
} else {
|
|
1386
|
-
result[key] = value;
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
return result;
|
|
1390
|
-
}, Object.create(null));
|
|
1391
|
-
}
|
|
1739
|
+
function removeHash(input) {
|
|
1740
|
+
var hashStart = input.indexOf('#');
|
|
1392
1741
|
|
|
1393
|
-
|
|
1394
|
-
|
|
1742
|
+
if (hashStart !== -1) {
|
|
1743
|
+
input = input.slice(0, hashStart);
|
|
1744
|
+
}
|
|
1395
1745
|
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
return '';
|
|
1399
|
-
}
|
|
1746
|
+
return input;
|
|
1747
|
+
}
|
|
1400
1748
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
arrayFormat: 'none',
|
|
1405
|
-
arrayFormatSeparator: ','
|
|
1406
|
-
}, options);
|
|
1749
|
+
function getHash(url) {
|
|
1750
|
+
var hash = '';
|
|
1751
|
+
var hashStart = url.indexOf('#');
|
|
1407
1752
|
|
|
1408
|
-
|
|
1753
|
+
if (hashStart !== -1) {
|
|
1754
|
+
hash = url.slice(hashStart);
|
|
1755
|
+
}
|
|
1409
1756
|
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
(options.skipEmptyString && object[key] === '')
|
|
1413
|
-
); };
|
|
1757
|
+
return hash;
|
|
1758
|
+
}
|
|
1414
1759
|
|
|
1415
|
-
|
|
1760
|
+
function extract(input) {
|
|
1761
|
+
input = removeHash(input);
|
|
1762
|
+
var queryStart = input.indexOf('?');
|
|
1416
1763
|
|
|
1417
|
-
|
|
1764
|
+
if (queryStart === -1) {
|
|
1765
|
+
return '';
|
|
1766
|
+
}
|
|
1418
1767
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
objectCopy[key] = object[key];
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1768
|
+
return input.slice(queryStart + 1);
|
|
1769
|
+
}
|
|
1424
1770
|
|
|
1425
|
-
|
|
1771
|
+
function parseValue(value, options) {
|
|
1772
|
+
if (options.parseNumbers && !Number.isNaN(Number(value)) && typeof value === 'string' && value.trim() !== '') {
|
|
1773
|
+
value = Number(value);
|
|
1774
|
+
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
1775
|
+
value = value.toLowerCase() === 'true';
|
|
1776
|
+
}
|
|
1426
1777
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
}
|
|
1778
|
+
return value;
|
|
1779
|
+
}
|
|
1430
1780
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1781
|
+
function parse(query, options) {
|
|
1782
|
+
options = Object.assign({
|
|
1783
|
+
decode: true,
|
|
1784
|
+
sort: true,
|
|
1785
|
+
arrayFormat: 'none',
|
|
1786
|
+
arrayFormatSeparator: ',',
|
|
1787
|
+
parseNumbers: false,
|
|
1788
|
+
parseBooleans: false
|
|
1789
|
+
}, options);
|
|
1790
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
1791
|
+
var formatter = parserForArrayFormat(options); // Create an object with no prototype
|
|
1792
|
+
|
|
1793
|
+
var ret = Object.create(null);
|
|
1794
|
+
|
|
1795
|
+
if (typeof query !== 'string') {
|
|
1796
|
+
return ret;
|
|
1797
|
+
}
|
|
1433
1798
|
|
|
1434
|
-
|
|
1435
|
-
return '';
|
|
1436
|
-
}
|
|
1799
|
+
query = query.trim().replace(/^[?#&]/, '');
|
|
1437
1800
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1801
|
+
if (!query) {
|
|
1802
|
+
return ret;
|
|
1803
|
+
}
|
|
1441
1804
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
.reduce(formatter(key), [])
|
|
1445
|
-
.join('&');
|
|
1446
|
-
}
|
|
1805
|
+
var _iterator = _createForOfIteratorHelper__default['default'](query.split('&')),
|
|
1806
|
+
_step;
|
|
1447
1807
|
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1808
|
+
try {
|
|
1809
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1810
|
+
var param = _step.value;
|
|
1451
1811
|
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
}, options);
|
|
1456
|
-
|
|
1457
|
-
var ref = splitOnFirst(url, '#');
|
|
1458
|
-
var url_ = ref[0];
|
|
1459
|
-
var hash = ref[1];
|
|
1460
|
-
|
|
1461
|
-
return Object.assign(
|
|
1462
|
-
{
|
|
1463
|
-
url: url_.split('?')[0] || '',
|
|
1464
|
-
query: parse(extract(url), options)
|
|
1465
|
-
},
|
|
1466
|
-
options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
|
|
1467
|
-
);
|
|
1468
|
-
};
|
|
1812
|
+
if (param === '') {
|
|
1813
|
+
continue;
|
|
1814
|
+
}
|
|
1469
1815
|
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1816
|
+
var _splitOnFirst = splitOnFirst$1(options.decode ? param.replace(/\+/g, ' ') : param, '='),
|
|
1817
|
+
_splitOnFirst2 = _slicedToArray__default['default'](_splitOnFirst, 2),
|
|
1818
|
+
_key = _splitOnFirst2[0],
|
|
1819
|
+
_value = _splitOnFirst2[1]; // Missing `=` should be `null`:
|
|
1820
|
+
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
1475
1821
|
|
|
1476
|
-
var url = removeHash(object.url).split('?')[0] || '';
|
|
1477
|
-
var queryFromUrl = exports.extract(object.url);
|
|
1478
|
-
var parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false});
|
|
1479
1822
|
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1823
|
+
_value = _value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? _value : decode(_value, options);
|
|
1824
|
+
formatter(decode(_key, options), _value, ret);
|
|
1825
|
+
}
|
|
1826
|
+
} catch (err) {
|
|
1827
|
+
_iterator.e(err);
|
|
1828
|
+
} finally {
|
|
1829
|
+
_iterator.f();
|
|
1830
|
+
}
|
|
1485
1831
|
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
}
|
|
1832
|
+
for (var _i = 0, _Object$keys = Object.keys(ret); _i < _Object$keys.length; _i++) {
|
|
1833
|
+
var key = _Object$keys[_i];
|
|
1834
|
+
var value = ret[key];
|
|
1490
1835
|
|
|
1491
|
-
|
|
1492
|
-
|
|
1836
|
+
if (_typeof__default['default'](value) === 'object' && value !== null) {
|
|
1837
|
+
for (var _i2 = 0, _Object$keys2 = Object.keys(value); _i2 < _Object$keys2.length; _i2++) {
|
|
1838
|
+
var k = _Object$keys2[_i2];
|
|
1839
|
+
value[k] = parseValue(value[k], options);
|
|
1840
|
+
}
|
|
1841
|
+
} else {
|
|
1842
|
+
ret[key] = parseValue(value, options);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1493
1845
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
}, options);
|
|
1498
|
-
|
|
1499
|
-
var ref = exports.parseUrl(input, options);
|
|
1500
|
-
var url = ref.url;
|
|
1501
|
-
var query = ref.query;
|
|
1502
|
-
var fragmentIdentifier = ref.fragmentIdentifier;
|
|
1503
|
-
return exports.stringifyUrl({
|
|
1504
|
-
url: url,
|
|
1505
|
-
query: filterObj(query, filter),
|
|
1506
|
-
fragmentIdentifier: fragmentIdentifier
|
|
1507
|
-
}, options);
|
|
1508
|
-
};
|
|
1846
|
+
if (options.sort === false) {
|
|
1847
|
+
return ret;
|
|
1848
|
+
}
|
|
1509
1849
|
|
|
1510
|
-
|
|
1511
|
-
|
|
1850
|
+
return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce(function (result, key) {
|
|
1851
|
+
var value = ret[key];
|
|
1512
1852
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
var
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1853
|
+
if (Boolean(value) && _typeof__default['default'](value) === 'object' && !Array.isArray(value)) {
|
|
1854
|
+
// Sort object keys, not values
|
|
1855
|
+
result[key] = keysSorter(value);
|
|
1856
|
+
} else {
|
|
1857
|
+
result[key] = value;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
return result;
|
|
1861
|
+
}, Object.create(null));
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
exports.extract = extract;
|
|
1865
|
+
exports.parse = parse;
|
|
1866
|
+
|
|
1867
|
+
exports.stringify = function (object, options) {
|
|
1868
|
+
if (!object) {
|
|
1869
|
+
return '';
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
options = Object.assign({
|
|
1873
|
+
encode: true,
|
|
1874
|
+
strict: true,
|
|
1875
|
+
arrayFormat: 'none',
|
|
1876
|
+
arrayFormatSeparator: ','
|
|
1877
|
+
}, options);
|
|
1878
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
1879
|
+
|
|
1880
|
+
var shouldFilter = function shouldFilter(key) {
|
|
1881
|
+
return options.skipNull && isNullOrUndefined(object[key]) || options.skipEmptyString && object[key] === '';
|
|
1882
|
+
};
|
|
1883
|
+
|
|
1884
|
+
var formatter = encoderForArrayFormat(options);
|
|
1885
|
+
var objectCopy = {};
|
|
1886
|
+
|
|
1887
|
+
for (var _i3 = 0, _Object$keys3 = Object.keys(object); _i3 < _Object$keys3.length; _i3++) {
|
|
1888
|
+
var key = _Object$keys3[_i3];
|
|
1889
|
+
|
|
1890
|
+
if (!shouldFilter(key)) {
|
|
1891
|
+
objectCopy[key] = object[key];
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
var keys = Object.keys(objectCopy);
|
|
1896
|
+
|
|
1897
|
+
if (options.sort !== false) {
|
|
1898
|
+
keys.sort(options.sort);
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
return keys.map(function (key) {
|
|
1902
|
+
var value = object[key];
|
|
1903
|
+
|
|
1904
|
+
if (value === undefined) {
|
|
1905
|
+
return '';
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
if (value === null) {
|
|
1909
|
+
return encode(key, options);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
if (Array.isArray(value)) {
|
|
1913
|
+
return value.reduce(formatter(key), []).join('&');
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
return encode(key, options) + '=' + encode(value, options);
|
|
1917
|
+
}).filter(function (x) {
|
|
1918
|
+
return x.length > 0;
|
|
1919
|
+
}).join('&');
|
|
1920
|
+
};
|
|
1921
|
+
|
|
1922
|
+
exports.parseUrl = function (url, options) {
|
|
1923
|
+
options = Object.assign({
|
|
1924
|
+
decode: true
|
|
1925
|
+
}, options);
|
|
1926
|
+
|
|
1927
|
+
var _splitOnFirst3 = splitOnFirst$1(url, '#'),
|
|
1928
|
+
_splitOnFirst4 = _slicedToArray__default['default'](_splitOnFirst3, 2),
|
|
1929
|
+
url_ = _splitOnFirst4[0],
|
|
1930
|
+
hash = _splitOnFirst4[1];
|
|
1931
|
+
|
|
1932
|
+
return Object.assign({
|
|
1933
|
+
url: url_.split('?')[0] || '',
|
|
1934
|
+
query: parse(extract(url), options)
|
|
1935
|
+
}, options && options.parseFragmentIdentifier && hash ? {
|
|
1936
|
+
fragmentIdentifier: decode(hash, options)
|
|
1937
|
+
} : {});
|
|
1938
|
+
};
|
|
1939
|
+
|
|
1940
|
+
exports.stringifyUrl = function (object, options) {
|
|
1941
|
+
options = Object.assign({
|
|
1942
|
+
encode: true,
|
|
1943
|
+
strict: true
|
|
1944
|
+
}, options);
|
|
1945
|
+
var url = removeHash(object.url).split('?')[0] || '';
|
|
1946
|
+
var queryFromUrl = exports.extract(object.url);
|
|
1947
|
+
var parsedQueryFromUrl = exports.parse(queryFromUrl, {
|
|
1948
|
+
sort: false
|
|
1949
|
+
});
|
|
1950
|
+
var query = Object.assign(parsedQueryFromUrl, object.query);
|
|
1951
|
+
var queryString = exports.stringify(query, options);
|
|
1952
|
+
|
|
1953
|
+
if (queryString) {
|
|
1954
|
+
queryString = "?".concat(queryString);
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
var hash = getHash(object.url);
|
|
1958
|
+
|
|
1959
|
+
if (object.fragmentIdentifier) {
|
|
1960
|
+
hash = "#".concat(encode(object.fragmentIdentifier, options));
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
return "".concat(url).concat(queryString).concat(hash);
|
|
1964
|
+
};
|
|
1965
|
+
|
|
1966
|
+
exports.pick = function (input, filter, options) {
|
|
1967
|
+
options = Object.assign({
|
|
1968
|
+
parseFragmentIdentifier: true
|
|
1969
|
+
}, options);
|
|
1970
|
+
|
|
1971
|
+
var _exports$parseUrl = exports.parseUrl(input, options),
|
|
1972
|
+
url = _exports$parseUrl.url,
|
|
1973
|
+
query = _exports$parseUrl.query,
|
|
1974
|
+
fragmentIdentifier = _exports$parseUrl.fragmentIdentifier;
|
|
1975
|
+
|
|
1976
|
+
return exports.stringifyUrl({
|
|
1977
|
+
url: url,
|
|
1978
|
+
query: filterObject(query, filter),
|
|
1979
|
+
fragmentIdentifier: fragmentIdentifier
|
|
1980
|
+
}, options);
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1983
|
+
exports.exclude = function (input, filter, options) {
|
|
1984
|
+
var exclusionFilter = Array.isArray(filter) ? function (key) {
|
|
1985
|
+
return !filter.includes(key);
|
|
1986
|
+
} : function (key, value) {
|
|
1987
|
+
return !filter(key, value);
|
|
1988
|
+
};
|
|
1989
|
+
return exports.pick(input, exclusionFilter, options);
|
|
1990
|
+
};
|
|
1991
|
+
})(queryString);
|
|
1992
|
+
|
|
1993
|
+
function getSearch() {
|
|
1994
|
+
var search = '?';
|
|
1995
|
+
|
|
1996
|
+
if (routerConfig.router.mode === 'hash') {
|
|
1997
|
+
var idx = location.hash.indexOf('?');
|
|
1998
|
+
|
|
1999
|
+
if (idx > -1) {
|
|
2000
|
+
search = location.hash.slice(idx);
|
|
2001
|
+
}
|
|
2002
|
+
} else {
|
|
2003
|
+
search = location.search;
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
return search.substr(1);
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
var qs = function qs() {
|
|
2010
|
+
var stamp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
2011
|
+
var search = getSearch();
|
|
2012
|
+
var query = search ? queryString.parse(search) : {};
|
|
2013
|
+
|
|
2014
|
+
if (stamp) {
|
|
2015
|
+
query.stamp = stamp.toString();
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
return query;
|
|
1548
2019
|
};
|
|
1549
2020
|
|
|
1550
|
-
/* eslint-disable dot-notation */
|
|
1551
|
-
function pageOnReady(page
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
}
|
|
1567
|
-
function loadPage(page, pageConfig, stacksIndex) {
|
|
1568
|
-
if ( pageConfig === void 0 ) pageConfig = {};
|
|
1569
|
-
if ( stacksIndex === void 0 ) stacksIndex = 0;
|
|
1570
|
-
|
|
1571
|
-
if (!page)
|
|
1572
|
-
{ return; }
|
|
1573
|
-
var pageEl = document.getElementById(page.path);
|
|
1574
|
-
if (pageEl) {
|
|
1575
|
-
pageEl.style.display = 'block';
|
|
1576
|
-
}
|
|
1577
|
-
else {
|
|
1578
|
-
page.onLoad(qs(stacksIndex), function () { return pageOnReady(page, true); });
|
|
1579
|
-
}
|
|
1580
|
-
stacks.push(page);
|
|
1581
|
-
page.onShow();
|
|
1582
|
-
bindPageScroll(page, pageConfig);
|
|
1583
|
-
}
|
|
1584
|
-
function unloadPage(page, delta) {
|
|
1585
|
-
if ( delta === void 0 ) delta = 1;
|
|
1586
|
-
|
|
1587
|
-
if (!page)
|
|
1588
|
-
{ return; }
|
|
1589
|
-
stacks.delta = --delta;
|
|
1590
|
-
stacks.pop();
|
|
1591
|
-
page.onUnload();
|
|
1592
|
-
if (delta >= 1)
|
|
1593
|
-
{ unloadPage(stacks.last, delta); }
|
|
1594
|
-
}
|
|
1595
|
-
function showPage(page, pageConfig, stacksIndex) {
|
|
1596
|
-
if ( pageConfig === void 0 ) pageConfig = {};
|
|
1597
|
-
if ( stacksIndex === void 0 ) stacksIndex = 0;
|
|
1598
|
-
|
|
1599
|
-
if (!page)
|
|
1600
|
-
{ return; }
|
|
1601
|
-
page.onShow();
|
|
1602
|
-
var pageEl = document.getElementById(page.path);
|
|
1603
|
-
if (pageEl) {
|
|
1604
|
-
pageEl.style.display = 'block';
|
|
1605
|
-
}
|
|
1606
|
-
else {
|
|
1607
|
-
page.onLoad(qs(stacksIndex), function () { return pageOnReady(page, false); });
|
|
1608
|
-
}
|
|
1609
|
-
bindPageScroll(page, pageConfig);
|
|
1610
|
-
}
|
|
1611
|
-
function hidePage(page) {
|
|
1612
|
-
if (!page)
|
|
1613
|
-
{ return; }
|
|
1614
|
-
// NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
1615
|
-
var pageEl = document.getElementById(page.path);
|
|
1616
|
-
if (pageEl) {
|
|
1617
|
-
pageEl.style.display = 'none';
|
|
1618
|
-
page.onHide();
|
|
1619
|
-
}
|
|
1620
|
-
else {
|
|
1621
|
-
setTimeout(function () { return hidePage(page); }, 0);
|
|
1622
|
-
}
|
|
2021
|
+
/* eslint-disable dot-notation */
|
|
2022
|
+
function pageOnReady(page) {
|
|
2023
|
+
var onLoad = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
2024
|
+
var pageEl = document.getElementById(page.path);
|
|
2025
|
+
|
|
2026
|
+
if (pageEl && !(pageEl !== null && pageEl !== void 0 && pageEl['__isReady'])) {
|
|
2027
|
+
var _el$componentOnReady;
|
|
2028
|
+
|
|
2029
|
+
var el = pageEl.firstElementChild;
|
|
2030
|
+
el === null || el === void 0 ? void 0 : (_el$componentOnReady = el['componentOnReady']) === null || _el$componentOnReady === void 0 ? void 0 : _el$componentOnReady.call(el).then(function () {
|
|
2031
|
+
runtime.requestAnimationFrame(function () {
|
|
2032
|
+
page.onReady();
|
|
2033
|
+
pageEl['__isReady'] = true;
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
onLoad && (pageEl['__page'] = page);
|
|
2037
|
+
}
|
|
1623
2038
|
}
|
|
2039
|
+
function loadPage(page) {
|
|
2040
|
+
var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2041
|
+
var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
2042
|
+
if (!page) return;
|
|
2043
|
+
var pageEl = document.getElementById(page.path);
|
|
2044
|
+
|
|
2045
|
+
if (pageEl) {
|
|
2046
|
+
pageEl.style.display = 'block';
|
|
2047
|
+
} else {
|
|
2048
|
+
page.onLoad(qs(stacksIndex), function () {
|
|
2049
|
+
return pageOnReady(page, true);
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
stacks.push(page);
|
|
2054
|
+
page.onShow();
|
|
2055
|
+
bindPageScroll(page, pageConfig);
|
|
2056
|
+
}
|
|
2057
|
+
function unloadPage(page) {
|
|
2058
|
+
var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
2059
|
+
if (!page) return;
|
|
2060
|
+
stacks.delta = --delta;
|
|
2061
|
+
stacks.pop();
|
|
2062
|
+
page.onUnload();
|
|
2063
|
+
if (delta >= 1) unloadPage(stacks.last, delta);
|
|
2064
|
+
}
|
|
2065
|
+
function showPage(page) {
|
|
2066
|
+
var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2067
|
+
var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
2068
|
+
if (!page) return;
|
|
2069
|
+
page.onShow();
|
|
2070
|
+
var pageEl = document.getElementById(page.path);
|
|
2071
|
+
|
|
2072
|
+
if (pageEl) {
|
|
2073
|
+
pageEl.style.display = 'block';
|
|
2074
|
+
} else {
|
|
2075
|
+
page.onLoad(qs(stacksIndex), function () {
|
|
2076
|
+
return pageOnReady(page, false);
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
bindPageScroll(page, pageConfig);
|
|
2081
|
+
}
|
|
2082
|
+
function hidePage(page) {
|
|
2083
|
+
if (!page) return; // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
2084
|
+
|
|
2085
|
+
var pageEl = document.getElementById(page.path);
|
|
2086
|
+
|
|
2087
|
+
if (pageEl) {
|
|
2088
|
+
pageEl.style.display = 'none';
|
|
2089
|
+
page.onHide();
|
|
2090
|
+
} else {
|
|
2091
|
+
setTimeout(function () {
|
|
2092
|
+
return hidePage(page);
|
|
2093
|
+
}, 0);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
function createRouter(app, config, framework) {
|
|
2098
|
+
var _config$router$custom;
|
|
2099
|
+
|
|
2100
|
+
init(config);
|
|
2101
|
+
var routes = [];
|
|
2102
|
+
var alias = (_config$router$custom = config.router.customRoutes) !== null && _config$router$custom !== void 0 ? _config$router$custom : {};
|
|
2103
|
+
var runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
|
|
2104
|
+
setRoutesAlias(alias);
|
|
2105
|
+
|
|
2106
|
+
for (var i = 0; i < config.routes.length; i++) {
|
|
2107
|
+
var route = config.routes[i];
|
|
2108
|
+
var path = addLeadingSlash(route.path);
|
|
2109
|
+
routes.push({
|
|
2110
|
+
path: alias[path] || path,
|
|
2111
|
+
action: route.load
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
var basename = config.router.basename;
|
|
2116
|
+
var router = new UniversalRouter(routes, {
|
|
2117
|
+
baseUrl: basename || ''
|
|
2118
|
+
});
|
|
2119
|
+
app.onLaunch();
|
|
2120
|
+
|
|
2121
|
+
var render = /*#__PURE__*/function () {
|
|
2122
|
+
var _ref2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(_ref) {
|
|
2123
|
+
var location, action, element, _app$onPageNotFound, pageConfig, enablePullDownRefresh, _pageConfig$navigatio, currentPage, pathname, shouldLoad, prevIndex, delta, _prevIndex, _element$default, _runtimeHooks$createP, el, loadConfig, stacksIndex, page;
|
|
2124
|
+
|
|
2125
|
+
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
2126
|
+
while (1) {
|
|
2127
|
+
switch (_context.prev = _context.next) {
|
|
2128
|
+
case 0:
|
|
2129
|
+
location = _ref.location, action = _ref.action;
|
|
2130
|
+
routerConfig.router.pathname = location.pathname;
|
|
2131
|
+
_context.prev = 2;
|
|
2132
|
+
_context.next = 5;
|
|
2133
|
+
return router.resolve(config.router.forcePath || location.pathname);
|
|
2134
|
+
|
|
2135
|
+
case 5:
|
|
2136
|
+
element = _context.sent;
|
|
2137
|
+
_context.next = 15;
|
|
2138
|
+
break;
|
|
2139
|
+
|
|
2140
|
+
case 8:
|
|
2141
|
+
_context.prev = 8;
|
|
2142
|
+
_context.t0 = _context["catch"](2);
|
|
2143
|
+
|
|
2144
|
+
if (!(_context.t0.status === 404)) {
|
|
2145
|
+
_context.next = 14;
|
|
2146
|
+
break;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
(_app$onPageNotFound = app.onPageNotFound) === null || _app$onPageNotFound === void 0 ? void 0 : _app$onPageNotFound.call(app, {
|
|
2150
|
+
path: location.pathname
|
|
2151
|
+
});
|
|
2152
|
+
_context.next = 15;
|
|
2153
|
+
break;
|
|
2154
|
+
|
|
2155
|
+
case 14:
|
|
2156
|
+
throw new Error(_context.t0);
|
|
2157
|
+
|
|
2158
|
+
case 15:
|
|
2159
|
+
if (element) {
|
|
2160
|
+
_context.next = 17;
|
|
2161
|
+
break;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
return _context.abrupt("return");
|
|
2165
|
+
|
|
2166
|
+
case 17:
|
|
2167
|
+
pageConfig = config.routes.find(function (r) {
|
|
2168
|
+
var path = addLeadingSlash(r.path);
|
|
2169
|
+
return path === location.pathname || alias[path] === location.pathname;
|
|
2170
|
+
});
|
|
2171
|
+
enablePullDownRefresh = false;
|
|
2172
|
+
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
2173
|
+
toLocation: {
|
|
2174
|
+
path: location.pathname
|
|
2175
|
+
}
|
|
2176
|
+
});
|
|
2177
|
+
|
|
2178
|
+
if (pageConfig) {
|
|
2179
|
+
document.title = (_pageConfig$navigatio = pageConfig.navigationBarTitleText) !== null && _pageConfig$navigatio !== void 0 ? _pageConfig$navigatio : document.title;
|
|
2180
|
+
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
currentPage = runtime.Current.page;
|
|
2184
|
+
pathname = location.pathname;
|
|
2185
|
+
shouldLoad = false;
|
|
2186
|
+
|
|
2187
|
+
if (!(action === 'POP')) {
|
|
2188
|
+
_context.next = 31;
|
|
2189
|
+
break;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
// NOTE: 浏览器事件退后多次时,该事件只会被触发一次
|
|
2193
|
+
prevIndex = stacks.getPrevIndex(pathname);
|
|
2194
|
+
delta = stacks.getDelta(pathname);
|
|
2195
|
+
unloadPage(currentPage, delta);
|
|
2196
|
+
|
|
2197
|
+
if (prevIndex > -1) {
|
|
2198
|
+
showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
2199
|
+
} else {
|
|
2200
|
+
shouldLoad = true;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
_context.next = 46;
|
|
2204
|
+
break;
|
|
2205
|
+
|
|
2206
|
+
case 31:
|
|
2207
|
+
if (!(action === 'PUSH')) {
|
|
2208
|
+
_context.next = 36;
|
|
2209
|
+
break;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
hidePage(currentPage);
|
|
2213
|
+
shouldLoad = true;
|
|
2214
|
+
_context.next = 46;
|
|
2215
|
+
break;
|
|
2216
|
+
|
|
2217
|
+
case 36:
|
|
2218
|
+
if (!(action === 'REPLACE')) {
|
|
2219
|
+
_context.next = 46;
|
|
2220
|
+
break;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
if (!isTabBar(config)) {
|
|
2224
|
+
_context.next = 44;
|
|
2225
|
+
break;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
hidePage(currentPage);
|
|
2229
|
+
_prevIndex = stacks.getPrevIndex(pathname);
|
|
2230
|
+
|
|
2231
|
+
if (!(_prevIndex > -1)) {
|
|
2232
|
+
_context.next = 42;
|
|
2233
|
+
break;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
return _context.abrupt("return", showPage(stacks.getItem(_prevIndex), pageConfig, _prevIndex));
|
|
2237
|
+
|
|
2238
|
+
case 42:
|
|
2239
|
+
_context.next = 45;
|
|
2240
|
+
break;
|
|
2241
|
+
|
|
2242
|
+
case 44:
|
|
2243
|
+
unloadPage(currentPage);
|
|
2244
|
+
|
|
2245
|
+
case 45:
|
|
2246
|
+
shouldLoad = true;
|
|
2247
|
+
|
|
2248
|
+
case 46:
|
|
2249
|
+
if (!shouldLoad) {
|
|
2250
|
+
_context.next = 54;
|
|
2251
|
+
break;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
el = (_element$default = element.default) !== null && _element$default !== void 0 ? _element$default : element;
|
|
2255
|
+
loadConfig = _objectSpread__default['default']({}, pageConfig);
|
|
2256
|
+
stacksIndex = stacks.length;
|
|
2257
|
+
delete loadConfig['path'];
|
|
2258
|
+
delete loadConfig['load'];
|
|
2259
|
+
page = runtime.createPageConfig(enablePullDownRefresh ? (_runtimeHooks$createP = runtimeHooks.createPullDownComponent) === null || _runtimeHooks$createP === void 0 ? void 0 : _runtimeHooks$createP.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + runtime.stringify(qs(stacksIndex)), {}, loadConfig);
|
|
2260
|
+
return _context.abrupt("return", loadPage(page, pageConfig, stacksIndex));
|
|
2261
|
+
|
|
2262
|
+
case 54:
|
|
2263
|
+
case "end":
|
|
2264
|
+
return _context.stop();
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
}, _callee, null, [[2, 8]]);
|
|
2268
|
+
}));
|
|
2269
|
+
|
|
2270
|
+
return function render(_x) {
|
|
2271
|
+
return _ref2.apply(this, arguments);
|
|
2272
|
+
};
|
|
2273
|
+
}();
|
|
2274
|
+
|
|
2275
|
+
if (exports.history.location.pathname === '/') {
|
|
2276
|
+
exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
|
|
2277
|
+
}
|
|
1624
2278
|
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
var runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
|
|
1632
|
-
setRoutesAlias(alias);
|
|
1633
|
-
for (var i = 0; i < config.routes.length; i++) {
|
|
1634
|
-
var route = config.routes[i];
|
|
1635
|
-
var path = addLeadingSlash(route.path);
|
|
1636
|
-
routes.push({
|
|
1637
|
-
path: alias[path] || path,
|
|
1638
|
-
action: route.load
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
var basename = config.router.basename;
|
|
1642
|
-
var router = new UniversalRouter(routes, { baseUrl: basename || '' });
|
|
1643
|
-
app.onLaunch();
|
|
1644
|
-
var render = async function (ref) {
|
|
1645
|
-
var location = ref.location;
|
|
1646
|
-
var action = ref.action;
|
|
1647
|
-
|
|
1648
|
-
var _a, _b, _c, _d;
|
|
1649
|
-
routerConfig.router.pathname = location.pathname;
|
|
1650
|
-
var element;
|
|
1651
|
-
try {
|
|
1652
|
-
element = await router.resolve(config.router.forcePath || location.pathname);
|
|
1653
|
-
}
|
|
1654
|
-
catch (error) {
|
|
1655
|
-
if (error.status === 404) {
|
|
1656
|
-
(_a = app.onPageNotFound) === null || _a === void 0 ? void 0 : _a.call(app, {
|
|
1657
|
-
path: location.pathname
|
|
1658
|
-
});
|
|
1659
|
-
}
|
|
1660
|
-
else {
|
|
1661
|
-
throw new Error(error);
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
if (!element)
|
|
1665
|
-
{ return; }
|
|
1666
|
-
var pageConfig = config.routes.find(function (r) {
|
|
1667
|
-
var path = addLeadingSlash(r.path);
|
|
1668
|
-
return path === location.pathname || alias[path] === location.pathname;
|
|
1669
|
-
});
|
|
1670
|
-
var enablePullDownRefresh = false;
|
|
1671
|
-
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
1672
|
-
toLocation: {
|
|
1673
|
-
path: location.pathname
|
|
1674
|
-
}
|
|
1675
|
-
});
|
|
1676
|
-
if (pageConfig) {
|
|
1677
|
-
document.title = (_b = pageConfig.navigationBarTitleText) !== null && _b !== void 0 ? _b : document.title;
|
|
1678
|
-
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1679
|
-
}
|
|
1680
|
-
var currentPage = runtime.Current.page;
|
|
1681
|
-
var pathname = location.pathname;
|
|
1682
|
-
var shouldLoad = false;
|
|
1683
|
-
if (action === 'POP') {
|
|
1684
|
-
// NOTE: 浏览器事件退后多次时,该事件只会被触发一次
|
|
1685
|
-
var prevIndex = stacks.getPrevIndex(pathname);
|
|
1686
|
-
var delta = stacks.getDelta(pathname);
|
|
1687
|
-
unloadPage(currentPage, delta);
|
|
1688
|
-
if (prevIndex > -1) {
|
|
1689
|
-
showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
1690
|
-
}
|
|
1691
|
-
else {
|
|
1692
|
-
shouldLoad = true;
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
else if (action === 'PUSH') {
|
|
1696
|
-
hidePage(currentPage);
|
|
1697
|
-
shouldLoad = true;
|
|
1698
|
-
}
|
|
1699
|
-
else if (action === 'REPLACE') {
|
|
1700
|
-
if (isTabBar(config)) {
|
|
1701
|
-
hidePage(currentPage);
|
|
1702
|
-
var prevIndex$1 = stacks.getPrevIndex(pathname);
|
|
1703
|
-
if (prevIndex$1 > -1) {
|
|
1704
|
-
// NOTE: tabbar 页且之前出现过,直接复用
|
|
1705
|
-
return showPage(stacks.getItem(prevIndex$1), pageConfig, prevIndex$1);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
else {
|
|
1709
|
-
unloadPage(currentPage);
|
|
1710
|
-
}
|
|
1711
|
-
shouldLoad = true;
|
|
1712
|
-
}
|
|
1713
|
-
if (shouldLoad) {
|
|
1714
|
-
var el = (_c = element.default) !== null && _c !== void 0 ? _c : element;
|
|
1715
|
-
var loadConfig = Object.assign({}, pageConfig);
|
|
1716
|
-
var stacksIndex = stacks.length;
|
|
1717
|
-
delete loadConfig['path'];
|
|
1718
|
-
delete loadConfig['load'];
|
|
1719
|
-
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);
|
|
1720
|
-
return loadPage(page, pageConfig, stacksIndex);
|
|
1721
|
-
}
|
|
1722
|
-
};
|
|
1723
|
-
if (exports.history.location.pathname === '/') {
|
|
1724
|
-
exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
|
|
1725
|
-
}
|
|
1726
|
-
render({ location: exports.history.location, action: r.Push });
|
|
1727
|
-
app.onShow(qs(stacks.length));
|
|
1728
|
-
return exports.history.listen(render);
|
|
2279
|
+
render({
|
|
2280
|
+
location: exports.history.location,
|
|
2281
|
+
action: r.Push
|
|
2282
|
+
});
|
|
2283
|
+
app.onShow(qs(stacks.length));
|
|
2284
|
+
return exports.history.listen(render);
|
|
1729
2285
|
}
|
|
1730
2286
|
|
|
1731
2287
|
exports.createRouter = createRouter;
|