@tarojs/router 4.0.0-alpha.0 → 4.0.0-alpha.3

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.
Files changed (44) hide show
  1. package/LICENSE +14 -0
  2. package/dist/api.d.ts +7 -6
  3. package/dist/api.js +36 -20
  4. package/dist/events/resize.d.ts +2 -1
  5. package/dist/events/resize.js +15 -7
  6. package/dist/events/scroll.d.ts +2 -1
  7. package/dist/events/scroll.js +4 -1
  8. package/dist/history.d.ts +24 -5
  9. package/dist/history.js +18 -7
  10. package/dist/index.cjs.d.ts +49 -6
  11. package/dist/index.cjs.js +551 -229
  12. package/dist/index.d.ts +10 -4
  13. package/dist/index.esm.d.ts +49 -6
  14. package/dist/index.esm.js +510 -199
  15. package/dist/index.js +52 -4
  16. package/dist/navigationBar.d.ts +2 -0
  17. package/dist/navigationBar.js +27 -0
  18. package/dist/router/index.d.ts +4 -3
  19. package/dist/router/index.js +5 -2
  20. package/dist/router/mpa.d.ts +5 -3
  21. package/dist/router/mpa.js +22 -17
  22. package/dist/router/multi-page.d.ts +10 -6
  23. package/dist/router/multi-page.js +27 -43
  24. package/dist/router/navigation-bar.d.ts +32 -0
  25. package/dist/router/navigation-bar.js +209 -0
  26. package/dist/router/page.d.ts +13 -7
  27. package/dist/router/page.js +36 -45
  28. package/dist/router/spa.d.ts +5 -3
  29. package/dist/router/spa.js +40 -26
  30. package/dist/router/stack.d.ts +1 -1
  31. package/dist/router/stack.js +2 -1
  32. package/dist/style.d.ts +8 -2
  33. package/dist/style.js +65 -5
  34. package/dist/tabbar.d.ts +3 -1
  35. package/dist/tabbar.js +4 -3
  36. package/dist/utils/index.d.ts +3 -9
  37. package/dist/utils/index.js +5 -20
  38. package/dist/utils/navigate.d.ts +9 -5
  39. package/dist/utils/navigate.js +22 -38
  40. package/package.json +21 -11
  41. package/types/component.d.ts +5 -0
  42. package/types/taro.d.ts +8 -0
  43. package/dist/index.cjs.js.map +0 -1
  44. package/dist/index.esm.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,4 +1,52 @@
1
- export * from './api';
2
- export { history } from './history';
3
- export { createMultiRouter } from './router/mpa';
4
- export { createRouter } from './router/spa';
1
+ import { initNavigationBar } from './navigationBar.js';
2
+ import { initTabbar } from './tabbar.js';
3
+ export { getCurrentPages, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from './api.js';
4
+ export { createMpaHistory, history, prependBasename, setHistory, setHistoryMode } from './history.js';
5
+ export { createMultiRouter } from './router/mpa.js';
6
+ export { createRouter } from './router/spa.js';
7
+ export { routesAlias } from './utils/index.js';
8
+ export { createBrowserHistory, createHashHistory } from 'history';
9
+ export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarStyle, setTitle } from './utils/navigate.js';
10
+
11
+ function handleAppMount(config, _, appId = config.appId || 'app') {
12
+ let app = document.getElementById(appId);
13
+ let isPosition = true;
14
+ if (!app) {
15
+ app = document.createElement('div');
16
+ app.id = appId;
17
+ isPosition = false;
18
+ }
19
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
20
+ app.classList.add('taro_router');
21
+ if (!isPosition)
22
+ appWrapper.appendChild(app);
23
+ initNavigationBar(appWrapper);
24
+ }
25
+ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
26
+ let app = document.getElementById(appId);
27
+ let isPosition = true;
28
+ if (!app) {
29
+ app = document.createElement('div');
30
+ app.id = appId;
31
+ isPosition = false;
32
+ }
33
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
34
+ app.classList.add('taro_router');
35
+ const container = document.createElement('div');
36
+ container.classList.add('taro-tabbar__container');
37
+ container.id = 'container';
38
+ const panel = document.createElement('div');
39
+ panel.classList.add('taro-tabbar__panel');
40
+ panel.appendChild(app.cloneNode(true));
41
+ container.appendChild(panel);
42
+ if (!isPosition) {
43
+ appWrapper.appendChild(container);
44
+ }
45
+ else {
46
+ appWrapper.replaceChild(container, app);
47
+ }
48
+ initTabbar(config, history);
49
+ initNavigationBar(container);
50
+ }
51
+
52
+ export { handleAppMount, handleAppMountWithTabbar };
@@ -0,0 +1,2 @@
1
+ declare function initNavigationBar(container: HTMLElement): void;
2
+ export { initNavigationBar };
@@ -0,0 +1,27 @@
1
+ const home_svg_str = `
2
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <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"/>
4
+ </svg>
5
+ `;
6
+ const back_svg_str = `
7
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
8
+ <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"/>
9
+ </svg>
10
+
11
+ `;
12
+ function initNavigationBar(container) {
13
+ const navigationBar = document.createElement('taro-navigation-bar-wrap');
14
+ navigationBar.classList.add('taro-navigation-bar-no-icon');
15
+ const navigationBarBackBtn = document.createElement('taro-navigation-bar-back');
16
+ const navigationBarHomeBtn = document.createElement('taro-navigation-bar-home');
17
+ navigationBarBackBtn.innerHTML = back_svg_str;
18
+ navigationBarHomeBtn.innerHTML = home_svg_str;
19
+ const navigationBarTitle = document.createElement('taro-navigation-bar-title');
20
+ navigationBar.appendChild(navigationBarHomeBtn);
21
+ navigationBar.appendChild(navigationBarBackBtn);
22
+ navigationBar.appendChild(navigationBarTitle);
23
+ navigationBar.id = 'taro-navigation-bar';
24
+ container.prepend(navigationBar);
25
+ }
26
+
27
+ export { initNavigationBar };
@@ -1,11 +1,12 @@
1
- import type { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
2
- export declare class RouterConfig {
1
+ import { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
2
+ declare class RouterConfig {
3
3
  private static __config;
4
4
  static set config(e: SpaRouterConfig | MpaRouterConfig);
5
5
  static get config(): SpaRouterConfig | MpaRouterConfig;
6
6
  static get pages(): string[];
7
- static get router(): import("../../types/router").Router;
7
+ static get router(): import("../types/router").Router;
8
8
  static get mode(): "hash" | "browser" | "multi";
9
9
  static get customRoutes(): Record<string, string | string[]>;
10
10
  static isPage(url?: string): boolean;
11
11
  }
12
+ export { RouterConfig };
@@ -1,5 +1,6 @@
1
- import { prependBasename } from '../history';
2
- export class RouterConfig {
1
+ import { prependBasename } from '../history.js';
2
+
3
+ class RouterConfig {
3
4
  static set config(e) {
4
5
  this.__config = e;
5
6
  }
@@ -20,3 +21,5 @@ export class RouterConfig {
20
21
  return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
21
22
  }
22
23
  }
24
+
25
+ export { RouterConfig };
@@ -1,5 +1,6 @@
1
- import type { AppInstance } from '@tarojs/runtime';
2
- import type { MpaRouterConfig } from '../../types/router';
1
+ import { AppInstance } from '@tarojs/runtime';
2
+ import { History } from "../history.js";
3
+ import { MpaRouterConfig } from '../../types/router';
3
4
  /** Note: 关于多页面应用
4
5
  * - 需要配置路由映射(根目录跳转、404 页面……)
5
6
  * - app.onPageNotFound 事件不支持
@@ -7,4 +8,5 @@ import type { MpaRouterConfig } from '../../types/router';
7
8
  * - TabBar 会多次加载
8
9
  * - 不支持路由动画
9
10
  */
10
- export declare function createMultiRouter(app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
11
+ declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
12
+ export { createMultiRouter };
@@ -1,17 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /* eslint-disable dot-notation */
11
- import { createPageConfig, eventCenter, hooks, incrementId, stringify, } from '@tarojs/runtime';
12
- import { setTitle } from '../utils/navigate';
13
- import { RouterConfig } from '.';
14
- import MultiPageHandler from './multi-page';
1
+ import { __awaiter } from 'tslib';
2
+ import { incrementId, eventCenter, createPageConfig, hooks, stringify } from '@tarojs/runtime';
3
+ import '../utils/index.js';
4
+ import { RouterConfig } from './index.js';
5
+ import MultiPageHandler from './multi-page.js';
6
+ import { setMpaTitle } from '../utils/navigate.js';
7
+
15
8
  const createStampId = incrementId();
16
9
  const launchStampId = createStampId();
17
10
  // TODO 支持多路由 (APP 生命周期仅触发一次)
@@ -22,14 +15,15 @@ const launchStampId = createStampId();
22
15
  * - TabBar 会多次加载
23
16
  * - 不支持路由动画
24
17
  */
25
- export function createMultiRouter(app, config, framework) {
18
+ function createMultiRouter(history, app, config, framework) {
26
19
  var _a, _b, _c, _d, _e, _f;
27
20
  return __awaiter(this, void 0, void 0, function* () {
28
21
  if (typeof app.onUnhandledRejection === 'function') {
29
22
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
30
23
  }
24
+ eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
31
25
  RouterConfig.config = config;
32
- const handler = new MultiPageHandler(config);
26
+ const handler = new MultiPageHandler(config, history);
33
27
  const launchParam = {
34
28
  path: config.pageName,
35
29
  query: handler.getQuery(launchStampId),
@@ -61,7 +55,7 @@ export function createMultiRouter(app, config, framework) {
61
55
  return;
62
56
  let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
63
57
  if (pageConfig) {
64
- setTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
58
+ setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
65
59
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
66
60
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
67
61
  }
@@ -73,5 +67,16 @@ export function createMultiRouter(app, config, framework) {
73
67
  const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + stringify(launchParam), {}, loadConfig);
74
68
  handler.load(page, pageConfig);
75
69
  (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
70
+ window.addEventListener('visibilitychange', () => {
71
+ var _a, _b;
72
+ if (document.visibilityState === 'visible') {
73
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
74
+ }
75
+ else {
76
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
77
+ }
78
+ });
76
79
  });
77
80
  }
81
+
82
+ export { createMultiRouter };
@@ -1,11 +1,13 @@
1
1
  import { PageInstance } from '@tarojs/runtime';
2
- import type { PageConfig } from '@tarojs/taro';
3
- import type { MpaRouterConfig, Route } from '../../types/router';
4
- export default class MultiPageHandler {
2
+ import { PageConfig } from '@tarojs/taro';
3
+ import { History } from "../history.js";
4
+ import { MpaRouterConfig, Route } from '../../types/router';
5
+ declare class MultiPageHandler {
6
+ history: History;
5
7
  protected config: MpaRouterConfig;
6
- constructor(config: MpaRouterConfig);
8
+ constructor(config: MpaRouterConfig, history: History);
7
9
  get appId(): string;
8
- get router(): import("../../types/router").Router;
10
+ get router(): import("../types/router").Router;
9
11
  get routerMode(): "hash" | "browser" | "multi";
10
12
  get customRoutes(): Record<string, string | string[]>;
11
13
  get tabBarList(): import("@tarojs/taro").TabBarItem[];
@@ -20,11 +22,13 @@ export default class MultiPageHandler {
20
22
  getQuery(search?: string, options?: Record<string, unknown>): {
21
23
  [x: string]: unknown;
22
24
  };
25
+ isDefaultNavigationStyle(): boolean;
23
26
  mount(): void;
24
27
  onReady(page: PageInstance, onLoad?: boolean): void;
25
28
  load(page: PageInstance, pageConfig?: Route): void;
26
29
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
27
- getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
30
+ getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
28
31
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
29
32
  triggerRouterChange(): void;
30
33
  }
34
+ export { MultiPageHandler as default };
@@ -1,14 +1,14 @@
1
- /* eslint-disable dot-notation */
2
- import { Current, eventCenter } from '@tarojs/runtime';
1
+ import { addLeadingSlash, stripBasename, Current, eventCenter } from '@tarojs/runtime';
3
2
  import queryString from 'query-string';
4
- import { bindPageResize } from '../events/resize';
5
- import { bindPageScroll } from '../events/scroll';
6
- import { setHistoryMode } from '../history';
7
- import { loadRouterStyle } from '../style';
8
- import { initTabbar } from '../tabbar';
9
- import { addLeadingSlash, stripBasename } from '../utils';
10
- export default class MultiPageHandler {
11
- constructor(config) {
3
+ import { bindPageResize } from '../events/resize.js';
4
+ import { bindPageScroll } from '../events/scroll.js';
5
+ import { setHistory } from '../history.js';
6
+ import { loadRouterStyle } from '../style.js';
7
+
8
+ /* eslint-disable dot-notation */
9
+ class MultiPageHandler {
10
+ constructor(config, history) {
11
+ this.history = history;
12
12
  this.config = config;
13
13
  this.mount();
14
14
  }
@@ -55,39 +55,18 @@ export default class MultiPageHandler {
55
55
  : {};
56
56
  return Object.assign(Object.assign({}, query), options);
57
57
  }
58
- mount() {
59
- setHistoryMode(this.routerMode, this.router.basename);
60
- loadRouterStyle(this.usingWindowScroll);
61
- const appId = this.appId;
62
- let app = document.getElementById(appId);
63
- let isPosition = true;
64
- if (!app) {
65
- app = document.createElement('div');
66
- app.id = appId;
67
- isPosition = false;
68
- }
69
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
70
- app.classList.add('taro_router');
71
- if (this.tabBarList.length > 1) {
72
- const container = document.createElement('div');
73
- container.classList.add('taro-tabbar__container');
74
- container.id = 'container';
75
- const panel = document.createElement('div');
76
- panel.classList.add('taro-tabbar__panel');
77
- panel.appendChild(app.cloneNode(true));
78
- container.appendChild(panel);
79
- if (!isPosition) {
80
- appWrapper.appendChild(container);
81
- }
82
- else {
83
- appWrapper.replaceChild(container, app);
84
- }
85
- initTabbar(this.config);
86
- }
87
- else {
88
- if (!isPosition)
89
- appWrapper.appendChild(app);
58
+ isDefaultNavigationStyle() {
59
+ var _a, _b;
60
+ let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
61
+ if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
62
+ style = this.pageConfig.navigationStyle;
90
63
  }
64
+ return style !== 'custom';
65
+ }
66
+ mount() {
67
+ setHistory(this.history, this.basename);
68
+ // Note: 注入页面样式
69
+ loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
91
70
  }
92
71
  onReady(page, onLoad = true) {
93
72
  var _a;
@@ -117,10 +96,13 @@ export default class MultiPageHandler {
117
96
  return;
118
97
  (_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
119
98
  var _a;
99
+ const pageEl = this.getPageContainer(page);
120
100
  if (this.isTabBar) {
121
- const pageEl = this.getPageContainer(page);
122
101
  pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
123
102
  }
103
+ if (this.isDefaultNavigationStyle()) {
104
+ pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page');
105
+ }
124
106
  this.onReady(page, true);
125
107
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
126
108
  this.bindPageEvents(page, pageConfig);
@@ -166,3 +148,5 @@ export default class MultiPageHandler {
166
148
  }, 0);
167
149
  }
168
150
  }
151
+
152
+ export { MultiPageHandler as default };
@@ -0,0 +1,32 @@
1
+ import PageHandler from "./page.js";
2
+ interface NavigationBarCache {
3
+ backgroundColor?: string;
4
+ fontColor?: string;
5
+ title?: string;
6
+ show?: boolean;
7
+ }
8
+ declare class NavigationBarHandler {
9
+ pageContext: PageHandler;
10
+ navigationBarElement: Element;
11
+ cache: Record<string, NavigationBarCache>;
12
+ isLoadDdEntry: boolean;
13
+ constructor(pageContext: PageHandler);
14
+ private toHomeFn;
15
+ private backFn;
16
+ get homeBtnElement(): Element | null;
17
+ get backBtnElement(): Element | null;
18
+ get titleElement(): Element | null;
19
+ init(): void;
20
+ setNavigationBarElement(): void;
21
+ load(): void;
22
+ setCacheValue(): void;
23
+ setFnBtnState(): void;
24
+ setNavigationBarBackground(backgroundColor?: string): void;
25
+ setNavigationBarTextStyle(fontColor?: string): void;
26
+ setTitle(title?: any): void;
27
+ fnBtnToggleToHome(): void;
28
+ fnBtnToggleToBack(): void;
29
+ fnBtnToggleToNone(): void;
30
+ setNavigationBarVisible(show?: any): void;
31
+ }
32
+ export { NavigationBarHandler as default };
@@ -0,0 +1,209 @@
1
+ import { eventCenter } from '@tarojs/runtime';
2
+ import { reLaunch, navigateBack } from '../api.js';
3
+ import { loadNavigationBarStyle } from '../style.js';
4
+ import '../utils/index.js';
5
+ import stacks from './stack.js';
6
+ import { isDingTalk } from '../utils/navigate.js';
7
+
8
+ class NavigationBarHandler {
9
+ constructor(pageContext) {
10
+ this.isLoadDdEntry = false;
11
+ this.cache = {};
12
+ this.pageContext = pageContext;
13
+ this.init();
14
+ loadNavigationBarStyle();
15
+ eventCenter.on('__taroH5SetNavigationTitle', (title) => {
16
+ this.setTitle(title);
17
+ });
18
+ eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
19
+ if (typeof backgroundColor === 'string')
20
+ this.setNavigationBarBackground(backgroundColor);
21
+ if (typeof frontColor === 'string')
22
+ this.setNavigationBarTextStyle(frontColor);
23
+ });
24
+ }
25
+ toHomeFn() {
26
+ reLaunch({ url: this.pageContext.homePage });
27
+ }
28
+ backFn() {
29
+ navigateBack();
30
+ }
31
+ get homeBtnElement() {
32
+ var _a;
33
+ if (!this.navigationBarElement)
34
+ return null;
35
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
36
+ }
37
+ get backBtnElement() {
38
+ var _a;
39
+ if (!this.navigationBarElement)
40
+ return null;
41
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
42
+ }
43
+ get titleElement() {
44
+ var _a;
45
+ if (!this.navigationBarElement)
46
+ return null;
47
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
48
+ }
49
+ init() {
50
+ var _a, _b;
51
+ this.setNavigationBarElement();
52
+ if (!this.navigationBarElement)
53
+ return;
54
+ (_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
55
+ (_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
56
+ }
57
+ setNavigationBarElement() {
58
+ var _a;
59
+ this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
60
+ }
61
+ load() {
62
+ this.setCacheValue();
63
+ this.setTitle();
64
+ this.setNavigationBarVisible();
65
+ this.setFnBtnState();
66
+ this.setNavigationBarBackground();
67
+ this.setNavigationBarTextStyle();
68
+ }
69
+ setCacheValue() {
70
+ const currentPage = this.pageContext.currentPage;
71
+ if (typeof this.cache[currentPage] !== 'object') {
72
+ this.cache[currentPage] = {};
73
+ }
74
+ }
75
+ setFnBtnState() {
76
+ const currentRouter = this.pageContext.currentPage;
77
+ if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
78
+ this.fnBtnToggleToNone();
79
+ }
80
+ else if (stacks.length > 1) {
81
+ this.fnBtnToggleToBack();
82
+ }
83
+ else {
84
+ this.fnBtnToggleToHome();
85
+ }
86
+ }
87
+ setNavigationBarBackground(backgroundColor) {
88
+ var _a, _b, _c;
89
+ if (!this.navigationBarElement)
90
+ return;
91
+ const currentPage = this.pageContext.currentPage;
92
+ let color;
93
+ if (typeof backgroundColor === 'string') {
94
+ color = backgroundColor;
95
+ this.cache[currentPage] &&
96
+ (this.cache[currentPage].backgroundColor = color);
97
+ }
98
+ else {
99
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
100
+ if (typeof cacheValue === 'string') {
101
+ color = cacheValue;
102
+ }
103
+ else {
104
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
105
+ this.cache[currentPage] &&
106
+ (this.cache[currentPage].backgroundColor = color);
107
+ }
108
+ }
109
+ this.navigationBarElement.style.background = color;
110
+ }
111
+ setNavigationBarTextStyle(fontColor) {
112
+ var _a, _b, _c;
113
+ if (!this.navigationBarElement)
114
+ return;
115
+ const currentPage = this.pageContext.currentPage;
116
+ let color;
117
+ if (typeof fontColor === 'string') {
118
+ color = fontColor;
119
+ this.cache[currentPage] &&
120
+ (this.cache[currentPage].fontColor = color);
121
+ }
122
+ else {
123
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
124
+ if (typeof cacheValue === 'string') {
125
+ color = cacheValue;
126
+ }
127
+ else {
128
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
129
+ this.cache[currentPage] &&
130
+ (this.cache[currentPage].fontColor = color);
131
+ }
132
+ }
133
+ this.navigationBarElement.style.color = color;
134
+ }
135
+ setTitle(title) {
136
+ var _a, _b, _c;
137
+ const currentPage = this.pageContext.currentPage;
138
+ let proceedTitle;
139
+ if (typeof title === 'string') {
140
+ proceedTitle = title;
141
+ this.cache[currentPage] &&
142
+ (this.cache[currentPage].title = proceedTitle);
143
+ }
144
+ else {
145
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
146
+ if (typeof cacheValue === 'string') {
147
+ proceedTitle = cacheValue;
148
+ }
149
+ else {
150
+ proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
151
+ this.cache[currentPage] &&
152
+ (this.cache[currentPage].title = proceedTitle);
153
+ }
154
+ }
155
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
156
+ if (!this.isLoadDdEntry) {
157
+ this.isLoadDdEntry = true;
158
+ require('dingtalk-jsapi/platform');
159
+ }
160
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
161
+ setDingTitle({ proceedTitle });
162
+ }
163
+ document.title = proceedTitle;
164
+ if (!this.titleElement)
165
+ return;
166
+ this.titleElement.innerHTML = proceedTitle;
167
+ }
168
+ fnBtnToggleToHome() {
169
+ if (!this.navigationBarElement)
170
+ return;
171
+ this.navigationBarElement.classList.add('taro-navigation-bar-home');
172
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
173
+ }
174
+ fnBtnToggleToBack() {
175
+ if (!this.navigationBarElement)
176
+ return;
177
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
178
+ this.navigationBarElement.classList.add('taro-navigation-bar-back');
179
+ }
180
+ fnBtnToggleToNone() {
181
+ if (!this.navigationBarElement)
182
+ return;
183
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
184
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
185
+ }
186
+ setNavigationBarVisible(show) {
187
+ var _a, _b;
188
+ let shouldShow;
189
+ if (typeof show === 'boolean') {
190
+ shouldShow = show;
191
+ }
192
+ else {
193
+ shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
194
+ if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
195
+ shouldShow = this.pageContext.pageConfig.navigationStyle;
196
+ }
197
+ }
198
+ if (shouldShow === 'default') {
199
+ this.navigationBarElement.classList.add('taro-navigation-bar-show');
200
+ this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
201
+ }
202
+ else {
203
+ this.navigationBarElement.classList.add('taro-navigation-bar-hide');
204
+ this.navigationBarElement.classList.remove('taro-navigation-bar-show');
205
+ }
206
+ }
207
+ }
208
+
209
+ export { NavigationBarHandler as default };
@@ -1,18 +1,22 @@
1
+ import NavigationBarHandler from "./navigation-bar.js";
1
2
  import { PageInstance } from '@tarojs/runtime';
2
- import type { PageConfig, RouterAnimate } from '@tarojs/taro';
3
- import type { Route, SpaRouterConfig } from '../../types/router';
4
- export default class PageHandler {
5
- protected config: SpaRouterConfig;
3
+ import { PageConfig, RouterAnimate } from '@tarojs/taro';
4
+ import { History } from "../history.js";
5
+ import { Route, SpaRouterConfig } from '../../types/router';
6
+ declare class PageHandler {
7
+ history: History;
8
+ config: SpaRouterConfig;
6
9
  protected readonly defaultAnimation: RouterAnimate;
7
10
  protected unloadTimer: ReturnType<typeof setTimeout> | null;
8
11
  protected hideTimer: ReturnType<typeof setTimeout> | null;
9
12
  protected lastHidePage: HTMLElement | null;
10
13
  protected lastUnloadPage: PageInstance | null;
14
+ protected navigationBarHandler: NavigationBarHandler;
11
15
  homePage: string;
12
- constructor(config: SpaRouterConfig);
16
+ constructor(config: SpaRouterConfig, history: History);
13
17
  get currentPage(): string;
14
18
  get appId(): string;
15
- get router(): import("../../types/router").Router;
19
+ get router(): import("../types/router").Router;
16
20
  get routerMode(): "hash" | "browser" | "multi";
17
21
  get customRoutes(): Record<string, string | string[]>;
18
22
  get routes(): Route[];
@@ -26,6 +30,7 @@ export default class PageHandler {
26
30
  get basename(): string;
27
31
  get pageConfig(): Route | undefined;
28
32
  isTabBar(pathname: string): boolean;
33
+ isDefaultNavigationStyle(): boolean;
29
34
  isSamePage(page?: PageInstance | null): boolean;
30
35
  get search(): string;
31
36
  get usingWindowScroll(): boolean;
@@ -40,7 +45,8 @@ export default class PageHandler {
40
45
  hide(page?: PageInstance | null): void;
41
46
  addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
42
47
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
43
- getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
48
+ getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
44
49
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
45
50
  triggerRouterChange(): void;
46
51
  }
52
+ export { PageHandler as default };