@tarojs/router 3.6.24-nightly.0 → 3.6.24-nightly.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +21 -1
- package/dist/events/resize.js +12 -6
- package/dist/history.js +1 -1
- package/dist/index.cjs.d.ts +7 -2
- package/dist/index.cjs.js +367 -30
- package/dist/index.esm.d.ts +7 -2
- package/dist/index.esm.js +367 -32
- package/dist/index.js +4 -1
- package/dist/navigationBar.d.ts +2 -0
- package/dist/navigationBar.js +27 -0
- package/dist/router/mpa.js +13 -2
- package/dist/router/navigation-bar.d.ts +32 -0
- package/dist/router/navigation-bar.js +209 -0
- package/dist/router/page.d.ts +3 -1
- package/dist/router/page.js +6 -0
- package/dist/router/spa.js +12 -5
- package/dist/style.d.ts +5 -1
- package/dist/style.js +55 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/navigate.d.ts +7 -2
- package/dist/utils/navigate.js +22 -19
- package/package.json +5 -5
package/dist/api.js
CHANGED
|
@@ -46,6 +46,21 @@ function navigate(option, method) {
|
|
|
46
46
|
if ('url' in option) {
|
|
47
47
|
const pathPieces = processNavigateUrl(option);
|
|
48
48
|
const state = { timestamp: Date.now() };
|
|
49
|
+
if (pathPieces.pathname) {
|
|
50
|
+
const originPath = routesAlias.getOrigin(pathPieces.pathname);
|
|
51
|
+
const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath;
|
|
52
|
+
if (!RouterConfig.pages.includes(pagePath)) {
|
|
53
|
+
const res = { errMsg: `${method}:fail page ${pagePath} is not found` };
|
|
54
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
55
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
56
|
+
if (fail || complete) {
|
|
57
|
+
return resolve(res);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return reject(res);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
49
64
|
if (method === 'navigateTo') {
|
|
50
65
|
history.push(pathPieces, state);
|
|
51
66
|
}
|
|
@@ -71,7 +86,12 @@ function navigate(option, method) {
|
|
|
71
86
|
const res = { errMsg: `${method}:fail ${error.message || error}` };
|
|
72
87
|
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
73
88
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
74
|
-
|
|
89
|
+
if (fail || complete) {
|
|
90
|
+
return resolve(res);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return reject(res);
|
|
94
|
+
}
|
|
75
95
|
}
|
|
76
96
|
});
|
|
77
97
|
});
|
package/dist/events/resize.js
CHANGED
|
@@ -2,12 +2,18 @@ let pageResizeFn;
|
|
|
2
2
|
function bindPageResize(page) {
|
|
3
3
|
pageResizeFn && window.removeEventListener('resize', pageResizeFn);
|
|
4
4
|
pageResizeFn = function () {
|
|
5
|
-
page.onResize
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
if (page.onResize) {
|
|
6
|
+
const mediaQuery = window.matchMedia('(orientation: portrait)');
|
|
7
|
+
page.onResize({
|
|
8
|
+
deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
|
|
9
|
+
size: {
|
|
10
|
+
windowHeight: window.innerHeight,
|
|
11
|
+
windowWidth: window.innerWidth,
|
|
12
|
+
screenHeight: window.screen.height,
|
|
13
|
+
screenWidth: window.screen.width,
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
11
17
|
};
|
|
12
18
|
window.addEventListener('resize', pageResizeFn, false);
|
|
13
19
|
}
|
package/dist/history.js
CHANGED
package/dist/index.cjs.d.ts
CHANGED
|
@@ -54,7 +54,12 @@ declare class RoutesAlias {
|
|
|
54
54
|
declare const routesAlias: RoutesAlias;
|
|
55
55
|
declare const isWeixin: () => boolean;
|
|
56
56
|
declare const isDingTalk: () => boolean;
|
|
57
|
-
declare function
|
|
57
|
+
declare function setMpaTitle(title: string): void;
|
|
58
|
+
declare function setTitle(title: string): void;
|
|
59
|
+
declare function setNavigationBarStyle(option: {
|
|
60
|
+
backgroundColor: string;
|
|
61
|
+
frontColor: string;
|
|
62
|
+
}): void;
|
|
58
63
|
declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
59
64
|
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
60
|
-
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setTitle, handleAppMount, handleAppMountWithTabbar };
|
|
65
|
+
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, handleAppMount, handleAppMountWithTabbar };
|
package/dist/index.cjs.js
CHANGED
|
@@ -8,6 +8,32 @@ var history = require('history');
|
|
|
8
8
|
var queryString = require('query-string');
|
|
9
9
|
var UniversalRouter = require('universal-router');
|
|
10
10
|
|
|
11
|
+
const home_svg_str = `
|
|
12
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
13
|
+
<path d="M23.8899 12.2737C23.8232 12.3584 23.7237 12.3997 23.6198 12.3974H20.7994V23.5996C20.7994 23.8194 20.6213 24 20.4001 24H14.7994C14.5791 24 14.4002 23.8194 14.4002 23.5996V15.6H9.59963V23.5996C9.59963 23.8194 9.42075 24 9.20033 24H3.59968C3.48981 24 3.38964 23.954 3.31764 23.8811C3.24495 23.8091 3.2004 23.7087 3.2004 23.5996V12.3975H0.398546V12.3967C0.296893 12.396 0.194446 12.3544 0.11579 12.2738C-0.0371146 12.114 -0.0400714 11.864 0.11579 11.7076L11.7201 0.117284C11.8767 -0.0390948 12.1298 -0.0390948 12.2863 0.117284L23.8899 11.7076C24.0465 11.864 24.0265 12.0995 23.8899 12.2737ZM12.0029 0.964625L1.37086 11.5854L3.59968 11.5839V11.5999C3.65537 11.5999 3.70804 11.611 3.75557 11.6307C3.89952 11.692 4.00046 11.8339 4.00046 11.9996V23.1991H8.79955V15.2003C8.79955 14.9789 8.97917 14.8002 9.20033 14.8002H14.7995C15.0207 14.8002 15.2003 14.9789 15.2003 15.2003V23.1991H20.0001V11.9996C20.0001 11.8339 20.1003 11.692 20.2443 11.6307C20.2918 11.611 20.3453 11.5999 20.4001 11.5999V11.5713L22.6193 11.5691L12.0029 0.964625Z" fill="currentColor"/>
|
|
14
|
+
</svg>
|
|
15
|
+
`;
|
|
16
|
+
const back_svg_str = `
|
|
17
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
18
|
+
<path d="M17.8206 22.9016L7.45515 11.8756L17.8206 1.09845C18.0598 0.849741 18.0598 0.435233 17.8206 0.186528C17.5814 -0.0621762 17.1827 -0.0621762 16.9435 0.186528L6.1794 11.4611C5.9402 11.7098 5.9402 12.1244 6.1794 12.3731L16.9435 23.8135C17.1827 24.0622 17.5814 24.0622 17.8206 23.8135C18.0598 23.5648 18.0598 23.1503 17.8206 22.9016Z" fill="currentColor"/>
|
|
19
|
+
</svg>
|
|
20
|
+
|
|
21
|
+
`;
|
|
22
|
+
function initNavigationBar(container) {
|
|
23
|
+
const navigationBar = document.createElement('taro-navigation-bar-wrap');
|
|
24
|
+
navigationBar.classList.add('taro-navigation-bar-no-icon');
|
|
25
|
+
const navigationBarBackBtn = document.createElement('taro-navigation-bar-back');
|
|
26
|
+
const navigationBarHomeBtn = document.createElement('taro-navigation-bar-home');
|
|
27
|
+
navigationBarBackBtn.innerHTML = back_svg_str;
|
|
28
|
+
navigationBarHomeBtn.innerHTML = home_svg_str;
|
|
29
|
+
const navigationBarTitle = document.createElement('taro-navigation-bar-title');
|
|
30
|
+
navigationBar.appendChild(navigationBarHomeBtn);
|
|
31
|
+
navigationBar.appendChild(navigationBarBackBtn);
|
|
32
|
+
navigationBar.appendChild(navigationBarTitle);
|
|
33
|
+
navigationBar.id = 'taro-navigation-bar';
|
|
34
|
+
container.prepend(navigationBar);
|
|
35
|
+
}
|
|
36
|
+
|
|
11
37
|
function initTabbar(config, history) {
|
|
12
38
|
if (config.tabBar == null) {
|
|
13
39
|
return;
|
|
@@ -88,7 +114,7 @@ class MpaHistory {
|
|
|
88
114
|
url += `?${to.search}`;
|
|
89
115
|
}
|
|
90
116
|
if (to.hash) {
|
|
91
|
-
url += `#${to.hash}`;
|
|
117
|
+
url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
|
|
92
118
|
}
|
|
93
119
|
return url;
|
|
94
120
|
}
|
|
@@ -245,26 +271,29 @@ class Stacks {
|
|
|
245
271
|
}
|
|
246
272
|
const stacks = new Stacks();
|
|
247
273
|
|
|
248
|
-
let preTitle = document.title;
|
|
249
|
-
let isLoadDdEntry = false;
|
|
250
274
|
const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
|
|
251
275
|
const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
264
|
-
setDingTitle({ title });
|
|
276
|
+
let preTitle = document.title;
|
|
277
|
+
let isLoadDdEntry = false;
|
|
278
|
+
function setMpaTitle(title) {
|
|
279
|
+
if (preTitle === title)
|
|
280
|
+
return;
|
|
281
|
+
document.title = title;
|
|
282
|
+
preTitle = title;
|
|
283
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
284
|
+
if (!isLoadDdEntry) {
|
|
285
|
+
isLoadDdEntry = true;
|
|
286
|
+
require('dingtalk-jsapi/platform');
|
|
265
287
|
}
|
|
266
|
-
|
|
267
|
-
|
|
288
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
289
|
+
setDingTitle({ title });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function setTitle(title) {
|
|
293
|
+
runtime.eventCenter.trigger('__taroH5SetNavigationTitle', title);
|
|
294
|
+
}
|
|
295
|
+
function setNavigationBarStyle(option) {
|
|
296
|
+
runtime.eventCenter.trigger('__taroH5setNavigationBarColor', option);
|
|
268
297
|
}
|
|
269
298
|
|
|
270
299
|
class RoutesAlias {
|
|
@@ -348,6 +377,21 @@ function navigate(option, method) {
|
|
|
348
377
|
if ('url' in option) {
|
|
349
378
|
const pathPieces = processNavigateUrl(option);
|
|
350
379
|
const state = { timestamp: Date.now() };
|
|
380
|
+
if (pathPieces.pathname) {
|
|
381
|
+
const originPath = routesAlias.getOrigin(pathPieces.pathname);
|
|
382
|
+
const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath;
|
|
383
|
+
if (!RouterConfig.pages.includes(pagePath)) {
|
|
384
|
+
const res = { errMsg: `${method}:fail page ${pagePath} is not found` };
|
|
385
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
386
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
387
|
+
if (fail || complete) {
|
|
388
|
+
return resolve(res);
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
return reject(res);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
351
395
|
if (method === 'navigateTo') {
|
|
352
396
|
exports.history.push(pathPieces, state);
|
|
353
397
|
}
|
|
@@ -373,7 +417,12 @@ function navigate(option, method) {
|
|
|
373
417
|
const res = { errMsg: `${method}:fail ${error.message || error}` };
|
|
374
418
|
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
375
419
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
376
|
-
|
|
420
|
+
if (fail || complete) {
|
|
421
|
+
return resolve(res);
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
return reject(res);
|
|
425
|
+
}
|
|
377
426
|
}
|
|
378
427
|
});
|
|
379
428
|
});
|
|
@@ -408,12 +457,18 @@ let pageResizeFn;
|
|
|
408
457
|
function bindPageResize(page) {
|
|
409
458
|
pageResizeFn && window.removeEventListener('resize', pageResizeFn);
|
|
410
459
|
pageResizeFn = function () {
|
|
411
|
-
page.onResize
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
460
|
+
if (page.onResize) {
|
|
461
|
+
const mediaQuery = window.matchMedia('(orientation: portrait)');
|
|
462
|
+
page.onResize({
|
|
463
|
+
deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
|
|
464
|
+
size: {
|
|
465
|
+
windowHeight: window.innerHeight,
|
|
466
|
+
windowWidth: window.innerWidth,
|
|
467
|
+
screenHeight: window.screen.height,
|
|
468
|
+
screenWidth: window.screen.width,
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
417
472
|
};
|
|
418
473
|
window.addEventListener('resize', pageResizeFn, false);
|
|
419
474
|
}
|
|
@@ -521,6 +576,60 @@ ${enableTabBar ? `
|
|
|
521
576
|
`;
|
|
522
577
|
addStyle(css);
|
|
523
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* 插入导航栏相关的样式
|
|
581
|
+
*/
|
|
582
|
+
function loadNavigationBarStyle() {
|
|
583
|
+
const css = `
|
|
584
|
+
.taro-navigation-bar-show {
|
|
585
|
+
background: white;
|
|
586
|
+
position: sticky;
|
|
587
|
+
z-index: 500;
|
|
588
|
+
top: 0;
|
|
589
|
+
padding-bottom: 8px;
|
|
590
|
+
padding-top: calc(env(safe-area-inset-top) + 8px);
|
|
591
|
+
display: flex;
|
|
592
|
+
justify-content: center;
|
|
593
|
+
align-items: center;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
.taro-navigation-bar-hide {
|
|
597
|
+
display: none;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
taro-navigation-bar-title {
|
|
601
|
+
font-size: 24px;
|
|
602
|
+
height: 24px;
|
|
603
|
+
line-height: 24px;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-home {
|
|
607
|
+
display: none;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-back {
|
|
611
|
+
display: none;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
.taro-navigation-bar-home > taro-navigation-bar-home {
|
|
615
|
+
display: block;
|
|
616
|
+
left: 8px;
|
|
617
|
+
position: absolute;
|
|
618
|
+
width: 24px;
|
|
619
|
+
height: 24px;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
.taro-navigation-bar-back > taro-navigation-bar-back {
|
|
623
|
+
display: block;
|
|
624
|
+
left: 8px;
|
|
625
|
+
position: absolute;
|
|
626
|
+
width: 24px;
|
|
627
|
+
height: 24px;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
`;
|
|
631
|
+
addStyle(css);
|
|
632
|
+
}
|
|
524
633
|
function addStyle(css) {
|
|
525
634
|
if (!css)
|
|
526
635
|
return;
|
|
@@ -675,6 +784,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
675
784
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
676
785
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
677
786
|
}
|
|
787
|
+
runtime.eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
|
|
678
788
|
RouterConfig.config = config;
|
|
679
789
|
const handler = new MultiPageHandler(config, history);
|
|
680
790
|
const launchParam = {
|
|
@@ -708,7 +818,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
708
818
|
return;
|
|
709
819
|
let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
|
|
710
820
|
if (pageConfig) {
|
|
711
|
-
|
|
821
|
+
setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
|
|
712
822
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
713
823
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
714
824
|
}
|
|
@@ -720,9 +830,219 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
720
830
|
const page = runtime.createPageConfig(enablePullDownRefresh ? runtime.hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + runtime.stringify(launchParam), {}, loadConfig);
|
|
721
831
|
handler.load(page, pageConfig);
|
|
722
832
|
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
|
|
833
|
+
window.addEventListener('visibilitychange', () => {
|
|
834
|
+
var _a, _b;
|
|
835
|
+
if (document.visibilityState === 'visible') {
|
|
836
|
+
(_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
837
|
+
}
|
|
838
|
+
else {
|
|
839
|
+
(_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
723
842
|
});
|
|
724
843
|
}
|
|
725
844
|
|
|
845
|
+
class NavigationBarHandler {
|
|
846
|
+
constructor(pageContext) {
|
|
847
|
+
this.isLoadDdEntry = false;
|
|
848
|
+
this.cache = {};
|
|
849
|
+
this.pageContext = pageContext;
|
|
850
|
+
this.init();
|
|
851
|
+
loadNavigationBarStyle();
|
|
852
|
+
runtime.eventCenter.on('__taroH5SetNavigationTitle', (title) => {
|
|
853
|
+
this.setTitle(title);
|
|
854
|
+
});
|
|
855
|
+
runtime.eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
|
|
856
|
+
if (typeof backgroundColor === 'string')
|
|
857
|
+
this.setNavigationBarBackground(backgroundColor);
|
|
858
|
+
if (typeof frontColor === 'string')
|
|
859
|
+
this.setNavigationBarTextStyle(frontColor);
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
toHomeFn() {
|
|
863
|
+
reLaunch({ url: this.pageContext.homePage });
|
|
864
|
+
}
|
|
865
|
+
backFn() {
|
|
866
|
+
navigateBack();
|
|
867
|
+
}
|
|
868
|
+
get homeBtnElement() {
|
|
869
|
+
var _a;
|
|
870
|
+
if (!this.navigationBarElement)
|
|
871
|
+
return null;
|
|
872
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
|
|
873
|
+
}
|
|
874
|
+
get backBtnElement() {
|
|
875
|
+
var _a;
|
|
876
|
+
if (!this.navigationBarElement)
|
|
877
|
+
return null;
|
|
878
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
|
|
879
|
+
}
|
|
880
|
+
get titleElement() {
|
|
881
|
+
var _a;
|
|
882
|
+
if (!this.navigationBarElement)
|
|
883
|
+
return null;
|
|
884
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
|
|
885
|
+
}
|
|
886
|
+
init() {
|
|
887
|
+
var _a, _b;
|
|
888
|
+
this.setNavigationBarElement();
|
|
889
|
+
if (!this.navigationBarElement)
|
|
890
|
+
return;
|
|
891
|
+
(_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
|
|
892
|
+
(_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
|
|
893
|
+
}
|
|
894
|
+
setNavigationBarElement() {
|
|
895
|
+
var _a;
|
|
896
|
+
this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
|
|
897
|
+
}
|
|
898
|
+
load() {
|
|
899
|
+
this.setCacheValue();
|
|
900
|
+
this.setTitle();
|
|
901
|
+
this.setNavigationBarVisible();
|
|
902
|
+
this.setFnBtnState();
|
|
903
|
+
this.setNavigationBarBackground();
|
|
904
|
+
this.setNavigationBarTextStyle();
|
|
905
|
+
}
|
|
906
|
+
setCacheValue() {
|
|
907
|
+
const currentPage = this.pageContext.currentPage;
|
|
908
|
+
if (typeof this.cache[currentPage] !== 'object') {
|
|
909
|
+
this.cache[currentPage] = {};
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
setFnBtnState() {
|
|
913
|
+
const currentRouter = this.pageContext.currentPage;
|
|
914
|
+
if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
|
|
915
|
+
this.fnBtnToggleToNone();
|
|
916
|
+
}
|
|
917
|
+
else if (stacks.length > 1) {
|
|
918
|
+
this.fnBtnToggleToBack();
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
this.fnBtnToggleToHome();
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
setNavigationBarBackground(backgroundColor) {
|
|
925
|
+
var _a, _b, _c;
|
|
926
|
+
if (!this.navigationBarElement)
|
|
927
|
+
return;
|
|
928
|
+
const currentPage = this.pageContext.currentPage;
|
|
929
|
+
let color;
|
|
930
|
+
if (typeof backgroundColor === 'string') {
|
|
931
|
+
color = backgroundColor;
|
|
932
|
+
this.cache[currentPage] &&
|
|
933
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
934
|
+
}
|
|
935
|
+
else {
|
|
936
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
|
|
937
|
+
if (typeof cacheValue === 'string') {
|
|
938
|
+
color = cacheValue;
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
|
|
942
|
+
this.cache[currentPage] &&
|
|
943
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
this.navigationBarElement.style.background = color;
|
|
947
|
+
}
|
|
948
|
+
setNavigationBarTextStyle(fontColor) {
|
|
949
|
+
var _a, _b, _c;
|
|
950
|
+
if (!this.navigationBarElement)
|
|
951
|
+
return;
|
|
952
|
+
const currentPage = this.pageContext.currentPage;
|
|
953
|
+
let color;
|
|
954
|
+
if (typeof fontColor === 'string') {
|
|
955
|
+
color = fontColor;
|
|
956
|
+
this.cache[currentPage] &&
|
|
957
|
+
(this.cache[currentPage].fontColor = color);
|
|
958
|
+
}
|
|
959
|
+
else {
|
|
960
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
|
|
961
|
+
if (typeof cacheValue === 'string') {
|
|
962
|
+
color = cacheValue;
|
|
963
|
+
}
|
|
964
|
+
else {
|
|
965
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
|
|
966
|
+
this.cache[currentPage] &&
|
|
967
|
+
(this.cache[currentPage].fontColor = color);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
this.navigationBarElement.style.color = color;
|
|
971
|
+
}
|
|
972
|
+
setTitle(title) {
|
|
973
|
+
var _a, _b, _c;
|
|
974
|
+
const currentPage = this.pageContext.currentPage;
|
|
975
|
+
let proceedTitle;
|
|
976
|
+
if (typeof title === 'string') {
|
|
977
|
+
proceedTitle = title;
|
|
978
|
+
this.cache[currentPage] &&
|
|
979
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
|
|
983
|
+
if (typeof cacheValue === 'string') {
|
|
984
|
+
proceedTitle = cacheValue;
|
|
985
|
+
}
|
|
986
|
+
else {
|
|
987
|
+
proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
|
|
988
|
+
this.cache[currentPage] &&
|
|
989
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
993
|
+
if (!this.isLoadDdEntry) {
|
|
994
|
+
this.isLoadDdEntry = true;
|
|
995
|
+
require('dingtalk-jsapi/platform');
|
|
996
|
+
}
|
|
997
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
998
|
+
setDingTitle({ proceedTitle });
|
|
999
|
+
}
|
|
1000
|
+
document.title = proceedTitle;
|
|
1001
|
+
if (!this.titleElement)
|
|
1002
|
+
return;
|
|
1003
|
+
this.titleElement.innerHTML = proceedTitle;
|
|
1004
|
+
}
|
|
1005
|
+
fnBtnToggleToHome() {
|
|
1006
|
+
if (!this.navigationBarElement)
|
|
1007
|
+
return;
|
|
1008
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-home');
|
|
1009
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
1010
|
+
}
|
|
1011
|
+
fnBtnToggleToBack() {
|
|
1012
|
+
if (!this.navigationBarElement)
|
|
1013
|
+
return;
|
|
1014
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
1015
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-back');
|
|
1016
|
+
}
|
|
1017
|
+
fnBtnToggleToNone() {
|
|
1018
|
+
if (!this.navigationBarElement)
|
|
1019
|
+
return;
|
|
1020
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
1021
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
1022
|
+
}
|
|
1023
|
+
setNavigationBarVisible(show) {
|
|
1024
|
+
var _a, _b;
|
|
1025
|
+
let shouldShow;
|
|
1026
|
+
if (typeof show === 'boolean') {
|
|
1027
|
+
shouldShow = show;
|
|
1028
|
+
}
|
|
1029
|
+
else {
|
|
1030
|
+
shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
1031
|
+
if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
1032
|
+
shouldShow = this.pageContext.pageConfig.navigationStyle;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
if (shouldShow === 'default') {
|
|
1036
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-show');
|
|
1037
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-hide');
|
|
1041
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-show');
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
726
1046
|
/* eslint-disable dot-notation */
|
|
727
1047
|
class PageHandler {
|
|
728
1048
|
constructor(config, history) {
|
|
@@ -731,6 +1051,7 @@ class PageHandler {
|
|
|
731
1051
|
this.config = config;
|
|
732
1052
|
this.homePage = runtime.getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
733
1053
|
this.mount();
|
|
1054
|
+
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
734
1055
|
}
|
|
735
1056
|
get currentPage() {
|
|
736
1057
|
const routePath = runtime.getCurrentPage(this.routerMode, this.basename);
|
|
@@ -874,6 +1195,7 @@ class PageHandler {
|
|
|
874
1195
|
this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
|
|
875
1196
|
this.addAnimation(pageEl, pageNo === 0);
|
|
876
1197
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1198
|
+
this.navigationBarHandler.load();
|
|
877
1199
|
this.bindPageEvents(page, pageConfig);
|
|
878
1200
|
this.triggerRouterChange();
|
|
879
1201
|
}
|
|
@@ -886,6 +1208,7 @@ class PageHandler {
|
|
|
886
1208
|
this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
|
|
887
1209
|
this.addAnimation(pageEl, pageNo === 0);
|
|
888
1210
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1211
|
+
this.navigationBarHandler.load();
|
|
889
1212
|
this.onReady(page, true);
|
|
890
1213
|
this.bindPageEvents(page, pageConfig);
|
|
891
1214
|
this.triggerRouterChange();
|
|
@@ -940,6 +1263,7 @@ class PageHandler {
|
|
|
940
1263
|
pageEl.classList.remove('taro_page_shade');
|
|
941
1264
|
this.addAnimation(pageEl, pageNo === 0);
|
|
942
1265
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1266
|
+
this.navigationBarHandler.load();
|
|
943
1267
|
this.bindPageEvents(page, pageConfig);
|
|
944
1268
|
this.triggerRouterChange();
|
|
945
1269
|
}
|
|
@@ -949,6 +1273,7 @@ class PageHandler {
|
|
|
949
1273
|
pageEl = this.getPageContainer(page);
|
|
950
1274
|
this.addAnimation(pageEl, pageNo === 0);
|
|
951
1275
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1276
|
+
this.navigationBarHandler.load();
|
|
952
1277
|
this.onReady(page, false);
|
|
953
1278
|
this.bindPageEvents(page, pageConfig);
|
|
954
1279
|
this.triggerRouterChange();
|
|
@@ -1065,7 +1390,7 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1065
1390
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1066
1391
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1067
1392
|
const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1068
|
-
var _c, _d, _e, _f, _g, _h, _j, _k
|
|
1393
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1069
1394
|
handler.pathname = decodeURI(location.pathname);
|
|
1070
1395
|
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1071
1396
|
window.scrollTo(0, 0);
|
|
@@ -1105,7 +1430,6 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1105
1430
|
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
1106
1431
|
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
1107
1432
|
if (pageConfig) {
|
|
1108
|
-
setTitle((_j = pageConfig.navigationBarTitleText) !== null && _j !== void 0 ? _j : document.title);
|
|
1109
1433
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1110
1434
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1111
1435
|
}
|
|
@@ -1122,7 +1446,7 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1122
1446
|
runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
1123
1447
|
const currentPage = runtime.Current.page;
|
|
1124
1448
|
const pathname = handler.pathname;
|
|
1125
|
-
const methodName = (
|
|
1449
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
1126
1450
|
const cacheTabs = stacks.getTabs();
|
|
1127
1451
|
let shouldLoad = false;
|
|
1128
1452
|
stacks.method = '';
|
|
@@ -1188,7 +1512,7 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1188
1512
|
shouldLoad = true;
|
|
1189
1513
|
}
|
|
1190
1514
|
if (shouldLoad || stacks.length < 1) {
|
|
1191
|
-
const el = (
|
|
1515
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
1192
1516
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1193
1517
|
const stacksIndex = stacks.length;
|
|
1194
1518
|
delete loadConfig['path'];
|
|
@@ -1213,6 +1537,15 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1213
1537
|
}
|
|
1214
1538
|
render({ location: history$1.location, action: history.Action.Push });
|
|
1215
1539
|
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
1540
|
+
window.addEventListener('visibilitychange', () => {
|
|
1541
|
+
var _a, _b;
|
|
1542
|
+
if (document.visibilityState === 'visible') {
|
|
1543
|
+
(_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1544
|
+
}
|
|
1545
|
+
else {
|
|
1546
|
+
(_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1216
1549
|
return history$1.listen(render);
|
|
1217
1550
|
}
|
|
1218
1551
|
|
|
@@ -1228,6 +1561,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
|
1228
1561
|
app.classList.add('taro_router');
|
|
1229
1562
|
if (!isPosition)
|
|
1230
1563
|
appWrapper.appendChild(app);
|
|
1564
|
+
initNavigationBar(appWrapper);
|
|
1231
1565
|
}
|
|
1232
1566
|
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
1233
1567
|
let app = document.getElementById(appId);
|
|
@@ -1253,6 +1587,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
1253
1587
|
appWrapper.replaceChild(container, app);
|
|
1254
1588
|
}
|
|
1255
1589
|
initTabbar(config, history);
|
|
1590
|
+
initNavigationBar(container);
|
|
1256
1591
|
}
|
|
1257
1592
|
|
|
1258
1593
|
Object.defineProperty(exports, 'createBrowserHistory', {
|
|
@@ -1279,5 +1614,7 @@ exports.redirectTo = redirectTo;
|
|
|
1279
1614
|
exports.routesAlias = routesAlias;
|
|
1280
1615
|
exports.setHistory = setHistory;
|
|
1281
1616
|
exports.setHistoryMode = setHistoryMode;
|
|
1617
|
+
exports.setMpaTitle = setMpaTitle;
|
|
1618
|
+
exports.setNavigationBarStyle = setNavigationBarStyle;
|
|
1282
1619
|
exports.setTitle = setTitle;
|
|
1283
1620
|
exports.switchTab = switchTab;
|
package/dist/index.esm.d.ts
CHANGED
|
@@ -54,7 +54,12 @@ declare class RoutesAlias {
|
|
|
54
54
|
declare const routesAlias: RoutesAlias;
|
|
55
55
|
declare const isWeixin: () => boolean;
|
|
56
56
|
declare const isDingTalk: () => boolean;
|
|
57
|
-
declare function
|
|
57
|
+
declare function setMpaTitle(title: string): void;
|
|
58
|
+
declare function setTitle(title: string): void;
|
|
59
|
+
declare function setNavigationBarStyle(option: {
|
|
60
|
+
backgroundColor: string;
|
|
61
|
+
frontColor: string;
|
|
62
|
+
}): void;
|
|
58
63
|
declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
59
64
|
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
60
|
-
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setTitle, handleAppMount, handleAppMountWithTabbar };
|
|
65
|
+
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, handleAppMount, handleAppMountWithTabbar };
|