@tarojs/router 4.0.1-alpha.0 → 4.0.1
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/LICENSE +8 -8
- package/README.md +1 -1
- package/dist/api.d.ts +7 -6
- package/dist/events/resize.d.ts +3 -2
- package/dist/events/scroll.d.ts +3 -2
- package/dist/history.d.ts +8 -10
- package/dist/index.cjs.d.ts +66 -0
- package/dist/index.cjs.js +17 -31
- package/dist/index.d.ts +10 -9
- package/dist/index.esm.d.ts +66 -0
- package/dist/index.esm.js +15 -29
- package/dist/index.js +2 -2
- package/dist/navigationBar.d.ts +3 -2
- package/dist/router/index.d.ts +5 -3
- package/dist/router/mpa.d.ts +5 -4
- package/dist/router/mpa.js +2 -2
- package/dist/router/multi-page.d.ts +8 -8
- package/dist/router/multi-page.js +1 -15
- package/dist/router/navigation-bar.d.ts +3 -3
- package/dist/router/page.d.ts +9 -8
- package/dist/router/spa.d.ts +5 -4
- package/dist/router/spa.js +10 -10
- package/dist/router/stack.d.ts +2 -2
- package/dist/style.d.ts +5 -4
- package/dist/tabbar.d.ts +3 -2
- package/dist/tabbar.js +1 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/navigate.d.ts +7 -6
- package/package.json +30 -19
package/LICENSE
CHANGED
|
@@ -154,8 +154,15 @@ See `/LICENSE` for details of the license.
|
|
|
154
154
|
|
|
155
155
|
==================
|
|
156
156
|
|
|
157
|
+
MIT (stencil-vue2-output-target):
|
|
158
|
+
The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
|
|
159
|
+
`/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
|
|
160
|
+
See `/LICENSE` for details of the license.
|
|
161
|
+
|
|
162
|
+
==================
|
|
163
|
+
|
|
157
164
|
MIT (weui):
|
|
158
|
-
The following files embed [
|
|
165
|
+
The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
|
|
159
166
|
`/packages/taro-components/src/components/*.scss`
|
|
160
167
|
See `/LICENSE.txt` for details of the license.
|
|
161
168
|
|
|
@@ -165,10 +172,3 @@ Apache-2.0 (intersection-observer):
|
|
|
165
172
|
The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
|
|
166
173
|
`/packages/taro-api/src/polyfill/intersection-observer.ts`
|
|
167
174
|
See `/LICENSE.txt` for details of the license.
|
|
168
|
-
|
|
169
|
-
==================
|
|
170
|
-
|
|
171
|
-
MIT (babel-plugin-jsx-dom-expressions):
|
|
172
|
-
The following files embed [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/blob/main/packages/babel-plugin-jsx-dom-expressions) MIT:
|
|
173
|
-
`/packages/babel-plugin-transform-solid-jsx/src/*`
|
|
174
|
-
See `/LICENSE` for details of the license.
|
package/README.md
CHANGED
package/dist/api.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Taro from '@tarojs/taro';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
|
|
3
|
+
declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
|
|
4
|
+
declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
|
|
5
|
+
declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
|
|
6
|
+
declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
|
|
7
|
+
declare function getCurrentPages(): Taro.Page[];
|
|
8
|
+
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages };
|
package/dist/events/resize.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
+
declare function bindPageResize(page: PageInstance): void;
|
|
3
|
+
export { bindPageResize };
|
package/dist/events/scroll.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
+
declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
|
|
3
|
+
export { bindPageScroll };
|
package/dist/history.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import type { StateEvent } from '../types/history';
|
|
5
|
-
export declare let history: History;
|
|
1
|
+
import { IH5RouterConfig } from '@tarojs/taro/types/compile';
|
|
2
|
+
import { StateEvent } from '../types/history';
|
|
3
|
+
declare let history: History;
|
|
6
4
|
declare class MpaHistory implements History {
|
|
7
5
|
action: Action;
|
|
8
6
|
get location(): Location;
|
|
@@ -19,8 +17,8 @@ declare class MpaHistory implements History {
|
|
|
19
17
|
replaceState: globalThis.History['replaceState'];
|
|
20
18
|
eventState(action: Required<StateEvent>['action']): (data: any, unused: string, url?: string | URL | null) => any;
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export
|
|
20
|
+
declare function setHistory(h: History, base?: string): void;
|
|
21
|
+
declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
|
|
22
|
+
declare function setHistoryMode(mode?: IH5RouterConfig['mode'], base?: string): void;
|
|
23
|
+
declare function prependBasename(url?: string): string;
|
|
24
|
+
export { history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Action, createBrowserHistory, createHashHistory, Blocker, BrowserHistoryOptions, HashHistoryOptions, History, Listener, Location, Path, To } from "history";
|
|
2
|
+
import { IH5RouterConfig } from "@tarojs/taro/types/compile";
|
|
3
|
+
import { StateEvent } from "../types/history";
|
|
4
|
+
import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
|
|
5
|
+
import Taro from "@tarojs/taro";
|
|
6
|
+
import { AppInstance } from "@tarojs/runtime";
|
|
7
|
+
import { MpaRouterConfig as MpaRouterConfig$0 } from "../../types/router";
|
|
8
|
+
import { SpaRouterConfig as SpaRouterConfig$0 } from "../../types/router";
|
|
9
|
+
declare let history: History;
|
|
10
|
+
declare class MpaHistory implements History {
|
|
11
|
+
action: Action;
|
|
12
|
+
get location(): Location;
|
|
13
|
+
createHref(_to: To): string;
|
|
14
|
+
parseUrl(to: Partial<Path>): string;
|
|
15
|
+
push(to: Partial<Path>, _state?: Record<string, unknown>): void;
|
|
16
|
+
replace(to: Partial<Path>, _state?: Record<string, unknown>): void;
|
|
17
|
+
go(delta: number): void;
|
|
18
|
+
back: () => void;
|
|
19
|
+
forward: () => void;
|
|
20
|
+
listen(listener: Listener): () => void;
|
|
21
|
+
block(_blocker: Blocker): () => void;
|
|
22
|
+
pushState: globalThis.History["pushState"];
|
|
23
|
+
replaceState: globalThis.History["replaceState"];
|
|
24
|
+
eventState(action: Required<StateEvent>["action"]): (data: any, unused: string, url?: string | URL | null) => any;
|
|
25
|
+
}
|
|
26
|
+
declare function setHistory(h: History, base?: string): void;
|
|
27
|
+
declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
|
|
28
|
+
declare function setHistoryMode(mode?: IH5RouterConfig["mode"], base?: string): void;
|
|
29
|
+
declare function prependBasename(url?: string): string;
|
|
30
|
+
declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
|
|
31
|
+
declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
|
|
32
|
+
declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
|
|
33
|
+
declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
|
|
34
|
+
declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
|
|
35
|
+
declare function getCurrentPages(): Taro.Page[];
|
|
36
|
+
// TODO 支持多路由 (APP 生命周期仅触发一次)
|
|
37
|
+
/** Note: 关于多页面应用
|
|
38
|
+
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
39
|
+
* - app.onPageNotFound 事件不支持
|
|
40
|
+
* - 应用生命周期可能多次触发
|
|
41
|
+
* - TabBar 会多次加载
|
|
42
|
+
* - 不支持路由动画
|
|
43
|
+
*/
|
|
44
|
+
declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig$0, framework?: string): Promise<void>;
|
|
45
|
+
declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig$0, framework?: string): () => void;
|
|
46
|
+
declare class RoutesAlias {
|
|
47
|
+
conf: Array<string[]>;
|
|
48
|
+
set(customRoutes?: Record<string, string | string[]>): void;
|
|
49
|
+
getConfig: (url?: string) => string[];
|
|
50
|
+
getOrigin: (url?: string) => string;
|
|
51
|
+
getAlias: (url?: string) => string;
|
|
52
|
+
getAll: (url?: string) => string[];
|
|
53
|
+
}
|
|
54
|
+
declare const routesAlias: RoutesAlias;
|
|
55
|
+
declare const isWeixin: () => boolean;
|
|
56
|
+
declare const isDingTalk: () => boolean;
|
|
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;
|
|
63
|
+
declare function setNavigationBarLoading(loading: boolean): void;
|
|
64
|
+
declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
65
|
+
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
66
|
+
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading, handleAppMount, handleAppMountWithTabbar };
|
package/dist/index.cjs.js
CHANGED
|
@@ -225,7 +225,7 @@ function initNavigationBar(config, container) {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
function initTabbar(config, history) {
|
|
228
|
-
if (config.tabBar == null
|
|
228
|
+
if (config.tabBar == null) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
// TODO: custom-tab-bar
|
|
@@ -794,7 +794,6 @@ class MultiPageHandler {
|
|
|
794
794
|
this.onReady(page, true);
|
|
795
795
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
796
796
|
this.bindPageEvents(page, pageConfig);
|
|
797
|
-
this.triggerRouterChange();
|
|
798
797
|
});
|
|
799
798
|
}
|
|
800
799
|
getPageContainer(page) {
|
|
@@ -822,19 +821,6 @@ class MultiPageHandler {
|
|
|
822
821
|
bindPageScroll(page, scrollEl, distance);
|
|
823
822
|
bindPageResize(page);
|
|
824
823
|
}
|
|
825
|
-
triggerRouterChange() {
|
|
826
|
-
/**
|
|
827
|
-
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
828
|
-
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
829
|
-
*/
|
|
830
|
-
setTimeout(() => {
|
|
831
|
-
runtime.eventCenter.trigger('__afterTaroRouterChange', {
|
|
832
|
-
toLocation: {
|
|
833
|
-
path: this.pathname
|
|
834
|
-
}
|
|
835
|
-
});
|
|
836
|
-
}, 0);
|
|
837
|
-
}
|
|
838
824
|
}
|
|
839
825
|
|
|
840
826
|
const createStampId$1 = runtime.incrementId();
|
|
@@ -848,8 +834,8 @@ const launchStampId$1 = createStampId$1();
|
|
|
848
834
|
* - 不支持路由动画
|
|
849
835
|
*/
|
|
850
836
|
function createMultiRouter(history, app, config, framework) {
|
|
837
|
+
var _a, _b, _c, _d, _e, _f;
|
|
851
838
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
852
|
-
var _a, _b, _c, _d, _e, _f;
|
|
853
839
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
854
840
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
855
841
|
}
|
|
@@ -857,7 +843,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
857
843
|
RouterConfig.config = config;
|
|
858
844
|
const handler = new MultiPageHandler(config, history);
|
|
859
845
|
const launchParam = {
|
|
860
|
-
path: config.pageName,
|
|
846
|
+
path: config.pageName,
|
|
861
847
|
query: handler.getQuery(launchStampId$1),
|
|
862
848
|
scene: 0,
|
|
863
849
|
shareTicket: '',
|
|
@@ -1524,11 +1510,11 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1524
1510
|
runtime.eventCenter.trigger('__taroRouterLaunch', launchParam);
|
|
1525
1511
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1526
1512
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1527
|
-
const render = (
|
|
1528
|
-
var _d, _e, _f, _g, _h, _j, _k
|
|
1513
|
+
const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1514
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1529
1515
|
// Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
|
|
1530
1516
|
const currentPathname = decodeURI(location.pathname);
|
|
1531
|
-
if ((
|
|
1517
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1532
1518
|
window.scrollTo(0, 0);
|
|
1533
1519
|
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
1534
1520
|
toLocation: {
|
|
@@ -1552,7 +1538,7 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1552
1538
|
path: currentPathname,
|
|
1553
1539
|
query: handler.getQuery(createStampId()),
|
|
1554
1540
|
};
|
|
1555
|
-
(
|
|
1541
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
1556
1542
|
runtime.eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
1557
1543
|
}
|
|
1558
1544
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -1569,10 +1555,10 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1569
1555
|
// context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
|
|
1570
1556
|
handler.pathname = context.pathname;
|
|
1571
1557
|
const { pathname, pageConfig } = handler;
|
|
1572
|
-
let enablePullDownRefresh = ((
|
|
1573
|
-
let navigationStyle = ((
|
|
1574
|
-
let navigationBarTextStyle = ((
|
|
1575
|
-
let navigationBarBackgroundColor = ((
|
|
1558
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
1559
|
+
let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
|
|
1560
|
+
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
1561
|
+
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
1576
1562
|
if (pageConfig) {
|
|
1577
1563
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1578
1564
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
@@ -1589,7 +1575,7 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1589
1575
|
}
|
|
1590
1576
|
runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
1591
1577
|
const currentPage = runtime.Current.page;
|
|
1592
|
-
const methodName = (
|
|
1578
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
1593
1579
|
const cacheTabs = stacks.getTabs();
|
|
1594
1580
|
let shouldLoad = false;
|
|
1595
1581
|
stacks.method = '';
|
|
@@ -1656,7 +1642,7 @@ function createRouter(history$1, app, config, framework) {
|
|
|
1656
1642
|
shouldLoad = true;
|
|
1657
1643
|
}
|
|
1658
1644
|
if (shouldLoad || stacks.length < 1) {
|
|
1659
|
-
const el = (
|
|
1645
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
1660
1646
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1661
1647
|
const stacksIndex = stacks.length;
|
|
1662
1648
|
delete loadConfig['path'];
|
|
@@ -1712,7 +1698,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
|
1712
1698
|
app.id = appId;
|
|
1713
1699
|
isPosition = false;
|
|
1714
1700
|
}
|
|
1715
|
-
const appWrapper = (
|
|
1701
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1716
1702
|
app.classList.add('taro_router');
|
|
1717
1703
|
if (!isPosition)
|
|
1718
1704
|
appWrapper.appendChild(app);
|
|
@@ -1726,7 +1712,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
1726
1712
|
app.id = appId;
|
|
1727
1713
|
isPosition = false;
|
|
1728
1714
|
}
|
|
1729
|
-
const appWrapper = (
|
|
1715
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1730
1716
|
app.classList.add('taro_router');
|
|
1731
1717
|
const container = document.createElement('div');
|
|
1732
1718
|
container.classList.add('taro-tabbar__container');
|
|
@@ -1745,11 +1731,11 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
1745
1731
|
initNavigationBar(config, container);
|
|
1746
1732
|
}
|
|
1747
1733
|
|
|
1748
|
-
Object.defineProperty(exports,
|
|
1734
|
+
Object.defineProperty(exports, 'createBrowserHistory', {
|
|
1749
1735
|
enumerable: true,
|
|
1750
1736
|
get: function () { return history.createBrowserHistory; }
|
|
1751
1737
|
});
|
|
1752
|
-
Object.defineProperty(exports,
|
|
1738
|
+
Object.defineProperty(exports, 'createHashHistory', {
|
|
1753
1739
|
enumerable: true,
|
|
1754
1740
|
get: function () { return history.createHashHistory; }
|
|
1755
1741
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
1
|
+
import { History } from "./history.js";
|
|
2
|
+
import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
|
|
3
|
+
declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
4
|
+
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
5
|
+
export * from "./api.js";
|
|
6
|
+
export * from "./history.js";
|
|
7
|
+
export { createMultiRouter } from "./router/mpa.js";
|
|
8
|
+
export { createRouter } from "./router/spa.js";
|
|
9
|
+
export * from "./utils/index.js";
|
|
10
|
+
export { handleAppMount, handleAppMountWithTabbar };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Action, createBrowserHistory, createHashHistory, Blocker, BrowserHistoryOptions, HashHistoryOptions, History, Listener, Location, Path, To } from "history";
|
|
2
|
+
import { IH5RouterConfig } from "@tarojs/taro/types/compile";
|
|
3
|
+
import { StateEvent } from "../types/history";
|
|
4
|
+
import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
|
|
5
|
+
import Taro from "@tarojs/taro";
|
|
6
|
+
import { AppInstance } from "@tarojs/runtime";
|
|
7
|
+
import { MpaRouterConfig as MpaRouterConfig$0 } from "../../types/router";
|
|
8
|
+
import { SpaRouterConfig as SpaRouterConfig$0 } from "../../types/router";
|
|
9
|
+
declare let history: History;
|
|
10
|
+
declare class MpaHistory implements History {
|
|
11
|
+
action: Action;
|
|
12
|
+
get location(): Location;
|
|
13
|
+
createHref(_to: To): string;
|
|
14
|
+
parseUrl(to: Partial<Path>): string;
|
|
15
|
+
push(to: Partial<Path>, _state?: Record<string, unknown>): void;
|
|
16
|
+
replace(to: Partial<Path>, _state?: Record<string, unknown>): void;
|
|
17
|
+
go(delta: number): void;
|
|
18
|
+
back: () => void;
|
|
19
|
+
forward: () => void;
|
|
20
|
+
listen(listener: Listener): () => void;
|
|
21
|
+
block(_blocker: Blocker): () => void;
|
|
22
|
+
pushState: globalThis.History["pushState"];
|
|
23
|
+
replaceState: globalThis.History["replaceState"];
|
|
24
|
+
eventState(action: Required<StateEvent>["action"]): (data: any, unused: string, url?: string | URL | null) => any;
|
|
25
|
+
}
|
|
26
|
+
declare function setHistory(h: History, base?: string): void;
|
|
27
|
+
declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
|
|
28
|
+
declare function setHistoryMode(mode?: IH5RouterConfig["mode"], base?: string): void;
|
|
29
|
+
declare function prependBasename(url?: string): string;
|
|
30
|
+
declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
|
|
31
|
+
declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
|
|
32
|
+
declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
|
|
33
|
+
declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
|
|
34
|
+
declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
|
|
35
|
+
declare function getCurrentPages(): Taro.Page[];
|
|
36
|
+
// TODO 支持多路由 (APP 生命周期仅触发一次)
|
|
37
|
+
/** Note: 关于多页面应用
|
|
38
|
+
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
39
|
+
* - app.onPageNotFound 事件不支持
|
|
40
|
+
* - 应用生命周期可能多次触发
|
|
41
|
+
* - TabBar 会多次加载
|
|
42
|
+
* - 不支持路由动画
|
|
43
|
+
*/
|
|
44
|
+
declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig$0, framework?: string): Promise<void>;
|
|
45
|
+
declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig$0, framework?: string): () => void;
|
|
46
|
+
declare class RoutesAlias {
|
|
47
|
+
conf: Array<string[]>;
|
|
48
|
+
set(customRoutes?: Record<string, string | string[]>): void;
|
|
49
|
+
getConfig: (url?: string) => string[];
|
|
50
|
+
getOrigin: (url?: string) => string;
|
|
51
|
+
getAlias: (url?: string) => string;
|
|
52
|
+
getAll: (url?: string) => string[];
|
|
53
|
+
}
|
|
54
|
+
declare const routesAlias: RoutesAlias;
|
|
55
|
+
declare const isWeixin: () => boolean;
|
|
56
|
+
declare const isDingTalk: () => boolean;
|
|
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;
|
|
63
|
+
declare function setNavigationBarLoading(loading: boolean): void;
|
|
64
|
+
declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
65
|
+
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
66
|
+
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading, handleAppMount, handleAppMountWithTabbar };
|
package/dist/index.esm.js
CHANGED
|
@@ -224,7 +224,7 @@ function initNavigationBar(config, container) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
function initTabbar(config, history) {
|
|
227
|
-
if (config.tabBar == null
|
|
227
|
+
if (config.tabBar == null) {
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
230
|
// TODO: custom-tab-bar
|
|
@@ -793,7 +793,6 @@ class MultiPageHandler {
|
|
|
793
793
|
this.onReady(page, true);
|
|
794
794
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
795
795
|
this.bindPageEvents(page, pageConfig);
|
|
796
|
-
this.triggerRouterChange();
|
|
797
796
|
});
|
|
798
797
|
}
|
|
799
798
|
getPageContainer(page) {
|
|
@@ -821,19 +820,6 @@ class MultiPageHandler {
|
|
|
821
820
|
bindPageScroll(page, scrollEl, distance);
|
|
822
821
|
bindPageResize(page);
|
|
823
822
|
}
|
|
824
|
-
triggerRouterChange() {
|
|
825
|
-
/**
|
|
826
|
-
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
827
|
-
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
828
|
-
*/
|
|
829
|
-
setTimeout(() => {
|
|
830
|
-
eventCenter.trigger('__afterTaroRouterChange', {
|
|
831
|
-
toLocation: {
|
|
832
|
-
path: this.pathname
|
|
833
|
-
}
|
|
834
|
-
});
|
|
835
|
-
}, 0);
|
|
836
|
-
}
|
|
837
823
|
}
|
|
838
824
|
|
|
839
825
|
const createStampId$1 = incrementId();
|
|
@@ -847,8 +833,8 @@ const launchStampId$1 = createStampId$1();
|
|
|
847
833
|
* - 不支持路由动画
|
|
848
834
|
*/
|
|
849
835
|
function createMultiRouter(history, app, config, framework) {
|
|
836
|
+
var _a, _b, _c, _d, _e, _f;
|
|
850
837
|
return __awaiter(this, void 0, void 0, function* () {
|
|
851
|
-
var _a, _b, _c, _d, _e, _f;
|
|
852
838
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
853
839
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
854
840
|
}
|
|
@@ -856,7 +842,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
856
842
|
RouterConfig.config = config;
|
|
857
843
|
const handler = new MultiPageHandler(config, history);
|
|
858
844
|
const launchParam = {
|
|
859
|
-
path: config.pageName,
|
|
845
|
+
path: config.pageName,
|
|
860
846
|
query: handler.getQuery(launchStampId$1),
|
|
861
847
|
scene: 0,
|
|
862
848
|
shareTicket: '',
|
|
@@ -1523,11 +1509,11 @@ function createRouter(history, app, config, framework) {
|
|
|
1523
1509
|
eventCenter.trigger('__taroRouterLaunch', launchParam);
|
|
1524
1510
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1525
1511
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1526
|
-
const render = (
|
|
1527
|
-
var _d, _e, _f, _g, _h, _j, _k
|
|
1512
|
+
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
1513
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1528
1514
|
// Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
|
|
1529
1515
|
const currentPathname = decodeURI(location.pathname);
|
|
1530
|
-
if ((
|
|
1516
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1531
1517
|
window.scrollTo(0, 0);
|
|
1532
1518
|
eventCenter.trigger('__taroRouterChange', {
|
|
1533
1519
|
toLocation: {
|
|
@@ -1551,7 +1537,7 @@ function createRouter(history, app, config, framework) {
|
|
|
1551
1537
|
path: currentPathname,
|
|
1552
1538
|
query: handler.getQuery(createStampId()),
|
|
1553
1539
|
};
|
|
1554
|
-
(
|
|
1540
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
1555
1541
|
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
1556
1542
|
}
|
|
1557
1543
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -1568,10 +1554,10 @@ function createRouter(history, app, config, framework) {
|
|
|
1568
1554
|
// context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
|
|
1569
1555
|
handler.pathname = context.pathname;
|
|
1570
1556
|
const { pathname, pageConfig } = handler;
|
|
1571
|
-
let enablePullDownRefresh = ((
|
|
1572
|
-
let navigationStyle = ((
|
|
1573
|
-
let navigationBarTextStyle = ((
|
|
1574
|
-
let navigationBarBackgroundColor = ((
|
|
1557
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
1558
|
+
let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
|
|
1559
|
+
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
1560
|
+
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
1575
1561
|
if (pageConfig) {
|
|
1576
1562
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1577
1563
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
@@ -1588,7 +1574,7 @@ function createRouter(history, app, config, framework) {
|
|
|
1588
1574
|
}
|
|
1589
1575
|
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
1590
1576
|
const currentPage = Current.page;
|
|
1591
|
-
const methodName = (
|
|
1577
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
1592
1578
|
const cacheTabs = stacks.getTabs();
|
|
1593
1579
|
let shouldLoad = false;
|
|
1594
1580
|
stacks.method = '';
|
|
@@ -1655,7 +1641,7 @@ function createRouter(history, app, config, framework) {
|
|
|
1655
1641
|
shouldLoad = true;
|
|
1656
1642
|
}
|
|
1657
1643
|
if (shouldLoad || stacks.length < 1) {
|
|
1658
|
-
const el = (
|
|
1644
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
1659
1645
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1660
1646
|
const stacksIndex = stacks.length;
|
|
1661
1647
|
delete loadConfig['path'];
|
|
@@ -1711,7 +1697,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
|
1711
1697
|
app.id = appId;
|
|
1712
1698
|
isPosition = false;
|
|
1713
1699
|
}
|
|
1714
|
-
const appWrapper = (
|
|
1700
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1715
1701
|
app.classList.add('taro_router');
|
|
1716
1702
|
if (!isPosition)
|
|
1717
1703
|
appWrapper.appendChild(app);
|
|
@@ -1725,7 +1711,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
1725
1711
|
app.id = appId;
|
|
1726
1712
|
isPosition = false;
|
|
1727
1713
|
}
|
|
1728
|
-
const appWrapper = (
|
|
1714
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1729
1715
|
app.classList.add('taro_router');
|
|
1730
1716
|
const container = document.createElement('div');
|
|
1731
1717
|
container.classList.add('taro-tabbar__container');
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
|
16
16
|
app.id = appId;
|
|
17
17
|
isPosition = false;
|
|
18
18
|
}
|
|
19
|
-
const appWrapper = (
|
|
19
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
20
20
|
app.classList.add('taro_router');
|
|
21
21
|
if (!isPosition)
|
|
22
22
|
appWrapper.appendChild(app);
|
|
@@ -30,7 +30,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
30
30
|
app.id = appId;
|
|
31
31
|
isPosition = false;
|
|
32
32
|
}
|
|
33
|
-
const appWrapper = (
|
|
33
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
34
34
|
app.classList.add('taro_router');
|
|
35
35
|
const container = document.createElement('div');
|
|
36
36
|
container.classList.add('taro-tabbar__container');
|
package/dist/navigationBar.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
|
|
2
|
+
declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
|
|
3
|
+
export { initNavigationBar };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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("
|
|
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
|
+
// 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
|
|
10
11
|
static isPage(url?: string): boolean;
|
|
11
12
|
}
|
|
13
|
+
export { RouterConfig };
|
package/dist/router/mpa.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import { History } from "../history.js";
|
|
3
|
+
import { MpaRouterConfig } from '../../types/router';
|
|
4
4
|
/** Note: 关于多页面应用
|
|
5
5
|
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
6
6
|
* - app.onPageNotFound 事件不支持
|
|
@@ -8,4 +8,5 @@ import type { MpaRouterConfig } from '../../types/router';
|
|
|
8
8
|
* - TabBar 会多次加载
|
|
9
9
|
* - 不支持路由动画
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
|
12
|
+
export { createMultiRouter };
|
package/dist/router/mpa.js
CHANGED
|
@@ -16,8 +16,8 @@ const launchStampId = createStampId();
|
|
|
16
16
|
* - 不支持路由动画
|
|
17
17
|
*/
|
|
18
18
|
function createMultiRouter(history, app, config, framework) {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f;
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f;
|
|
21
21
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
22
22
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
25
25
|
RouterConfig.config = config;
|
|
26
26
|
const handler = new MultiPageHandler(config, history);
|
|
27
27
|
const launchParam = {
|
|
28
|
-
path: config.pageName,
|
|
28
|
+
path: config.pageName,
|
|
29
29
|
query: handler.getQuery(launchStampId),
|
|
30
30
|
scene: 0,
|
|
31
31
|
shareTicket: '',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
1
|
+
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
+
import { PageConfig } from '@tarojs/taro';
|
|
3
|
+
import { History } from "../history.js";
|
|
4
|
+
import { MpaRouterConfig, Route } from '../../types/router';
|
|
5
|
+
declare class MultiPageHandler {
|
|
6
6
|
history: History;
|
|
7
7
|
protected config: MpaRouterConfig;
|
|
8
8
|
constructor(config: MpaRouterConfig, history: History);
|
|
9
9
|
get appId(): string;
|
|
10
|
-
get router(): import("
|
|
10
|
+
get router(): import("../types/router").Router;
|
|
11
11
|
get routerMode(): "hash" | "browser" | "multi";
|
|
12
12
|
get customRoutes(): Record<string, string | string[]>;
|
|
13
13
|
get tabBarList(): import("@tarojs/taro").TabBarItem[];
|
|
@@ -27,7 +27,7 @@ export default class MultiPageHandler {
|
|
|
27
27
|
onReady(page: PageInstance, onLoad?: boolean): void;
|
|
28
28
|
load(page: PageInstance, pageConfig?: Route): void;
|
|
29
29
|
getPageContainer(page?: PageInstance | null): HTMLElement | null;
|
|
30
|
-
getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis)
|
|
30
|
+
getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
|
|
31
31
|
bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
|
|
32
|
-
triggerRouterChange(): void;
|
|
33
32
|
}
|
|
33
|
+
export { MultiPageHandler as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addLeadingSlash, stripBasename, Current
|
|
1
|
+
import { addLeadingSlash, stripBasename, Current } from '@tarojs/runtime';
|
|
2
2
|
import queryString from 'query-string';
|
|
3
3
|
import { bindPageResize } from '../events/resize.js';
|
|
4
4
|
import { bindPageScroll } from '../events/scroll.js';
|
|
@@ -106,7 +106,6 @@ class MultiPageHandler {
|
|
|
106
106
|
this.onReady(page, true);
|
|
107
107
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
108
108
|
this.bindPageEvents(page, pageConfig);
|
|
109
|
-
this.triggerRouterChange();
|
|
110
109
|
});
|
|
111
110
|
}
|
|
112
111
|
getPageContainer(page) {
|
|
@@ -134,19 +133,6 @@ class MultiPageHandler {
|
|
|
134
133
|
bindPageScroll(page, scrollEl, distance);
|
|
135
134
|
bindPageResize(page);
|
|
136
135
|
}
|
|
137
|
-
triggerRouterChange() {
|
|
138
|
-
/**
|
|
139
|
-
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
140
|
-
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
141
|
-
*/
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
eventCenter.trigger('__afterTaroRouterChange', {
|
|
144
|
-
toLocation: {
|
|
145
|
-
path: this.pathname
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}, 0);
|
|
149
|
-
}
|
|
150
136
|
}
|
|
151
137
|
|
|
152
138
|
export { MultiPageHandler as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PageHandler from "./page.js";
|
|
2
2
|
interface NavigationBarCache {
|
|
3
3
|
backgroundColor?: string;
|
|
4
4
|
fontColor?: string;
|
|
@@ -6,7 +6,7 @@ interface NavigationBarCache {
|
|
|
6
6
|
show?: boolean;
|
|
7
7
|
loading?: boolean;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
declare class NavigationBarHandler {
|
|
10
10
|
pageContext: PageHandler;
|
|
11
11
|
navigationBarElement: HTMLElement;
|
|
12
12
|
cache: Record<string, NavigationBarCache>;
|
|
@@ -33,4 +33,4 @@ export default class NavigationBarHandler {
|
|
|
33
33
|
fnBtnToggleToNone(): void;
|
|
34
34
|
setNavigationBarVisible(show?: any): void;
|
|
35
35
|
}
|
|
36
|
-
export {};
|
|
36
|
+
export { NavigationBarHandler as default };
|
package/dist/router/page.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import NavigationBarHandler from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
import NavigationBarHandler from "./navigation-bar.js";
|
|
2
|
+
import { PageInstance } from '@tarojs/runtime';
|
|
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
7
|
history: History;
|
|
8
8
|
config: SpaRouterConfig;
|
|
9
9
|
protected readonly defaultAnimation: RouterAnimate;
|
|
@@ -17,7 +17,7 @@ export default class PageHandler {
|
|
|
17
17
|
constructor(config: SpaRouterConfig, history: History);
|
|
18
18
|
get currentPage(): string;
|
|
19
19
|
get appId(): string;
|
|
20
|
-
get router(): import("
|
|
20
|
+
get router(): import("../types/router").Router;
|
|
21
21
|
get routerMode(): "hash" | "browser" | "multi";
|
|
22
22
|
get customRoutes(): Record<string, string | string[]>;
|
|
23
23
|
get routes(): Route[];
|
|
@@ -47,7 +47,8 @@ export default class PageHandler {
|
|
|
47
47
|
hide(page?: PageInstance | null, animation?: boolean): void;
|
|
48
48
|
addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
|
|
49
49
|
getPageContainer(page?: PageInstance | null): HTMLElement | null;
|
|
50
|
-
getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis)
|
|
50
|
+
getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
|
|
51
51
|
bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
|
|
52
52
|
triggerRouterChange(): void;
|
|
53
53
|
}
|
|
54
|
+
export { PageHandler as default };
|
package/dist/router/spa.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import { History } from "../history.js";
|
|
3
|
+
import { SpaRouterConfig } from '../../types/router';
|
|
4
|
+
declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
|
|
5
|
+
export { createRouter };
|
package/dist/router/spa.js
CHANGED
|
@@ -42,11 +42,11 @@ function createRouter(history, app, config, framework) {
|
|
|
42
42
|
eventCenter.trigger('__taroRouterLaunch', launchParam);
|
|
43
43
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
44
44
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
45
|
-
const render = (
|
|
46
|
-
var _d, _e, _f, _g, _h, _j, _k
|
|
45
|
+
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
47
47
|
// Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
|
|
48
48
|
const currentPathname = decodeURI(location.pathname);
|
|
49
|
-
if ((
|
|
49
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
50
50
|
window.scrollTo(0, 0);
|
|
51
51
|
eventCenter.trigger('__taroRouterChange', {
|
|
52
52
|
toLocation: {
|
|
@@ -70,7 +70,7 @@ function createRouter(history, app, config, framework) {
|
|
|
70
70
|
path: currentPathname,
|
|
71
71
|
query: handler.getQuery(createStampId()),
|
|
72
72
|
};
|
|
73
|
-
(
|
|
73
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
74
74
|
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
75
75
|
}
|
|
76
76
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -87,10 +87,10 @@ function createRouter(history, app, config, framework) {
|
|
|
87
87
|
// context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
|
|
88
88
|
handler.pathname = context.pathname;
|
|
89
89
|
const { pathname, pageConfig } = handler;
|
|
90
|
-
let enablePullDownRefresh = ((
|
|
91
|
-
let navigationStyle = ((
|
|
92
|
-
let navigationBarTextStyle = ((
|
|
93
|
-
let navigationBarBackgroundColor = ((
|
|
90
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
91
|
+
let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
|
|
92
|
+
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
93
|
+
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
94
94
|
if (pageConfig) {
|
|
95
95
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
96
96
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
@@ -107,7 +107,7 @@ function createRouter(history, app, config, framework) {
|
|
|
107
107
|
}
|
|
108
108
|
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
109
109
|
const currentPage = Current.page;
|
|
110
|
-
const methodName = (
|
|
110
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
111
111
|
const cacheTabs = stacks.getTabs();
|
|
112
112
|
let shouldLoad = false;
|
|
113
113
|
stacks.method = '';
|
|
@@ -174,7 +174,7 @@ function createRouter(history, app, config, framework) {
|
|
|
174
174
|
shouldLoad = true;
|
|
175
175
|
}
|
|
176
176
|
if (shouldLoad || stacks.length < 1) {
|
|
177
|
-
const el = (
|
|
177
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
178
178
|
const loadConfig = Object.assign({}, pageConfig);
|
|
179
179
|
const stacksIndex = stacks.length;
|
|
180
180
|
delete loadConfig['path'];
|
package/dist/router/stack.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PageInstance } from '@tarojs/runtime';
|
|
2
2
|
declare class Stacks {
|
|
3
3
|
stacks: PageInstance[];
|
|
4
4
|
backDelta: number;
|
|
@@ -23,4 +23,4 @@ declare class Stacks {
|
|
|
23
23
|
removeTab(path: string): void;
|
|
24
24
|
}
|
|
25
25
|
declare const stacks: Stacks;
|
|
26
|
-
export default
|
|
26
|
+
export { stacks as default };
|
package/dist/style.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 插入页面动画需要的样式
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
declare function loadAnimateStyle(ms?: number): void;
|
|
5
5
|
/**
|
|
6
6
|
* 插入路由相关样式
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean, enhanceAnimation?: boolean): void;
|
|
9
9
|
/**
|
|
10
10
|
* 插入导航栏相关的样式
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
declare function loadNavigationBarStyle(): void;
|
|
13
|
+
declare function addStyle(css: any): void;
|
|
14
|
+
export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
|
package/dist/tabbar.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { AppConfig } from '@tarojs/taro';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { History } from "./history.js";
|
|
3
|
+
declare function initTabbar(config: AppConfig, history: History): void;
|
|
4
|
+
export { initTabbar };
|
package/dist/tabbar.js
CHANGED
|
@@ -2,7 +2,7 @@ import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/component
|
|
|
2
2
|
import { initTabBarApis } from '@tarojs/taro';
|
|
3
3
|
|
|
4
4
|
function initTabbar(config, history) {
|
|
5
|
-
if (config.tabBar == null
|
|
5
|
+
if (config.tabBar == null) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
// TODO: custom-tab-bar
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ declare class RoutesAlias {
|
|
|
6
6
|
getAlias: (url?: string) => string;
|
|
7
7
|
getAll: (url?: string) => string[];
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
export
|
|
9
|
+
declare const routesAlias: RoutesAlias;
|
|
10
|
+
export { routesAlias };
|
|
11
|
+
export * from "./navigate.js";
|
package/dist/utils/navigate.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
declare const isWeixin: () => boolean;
|
|
2
|
+
declare const isDingTalk: () => boolean;
|
|
3
|
+
declare function setMpaTitle(title: string): void;
|
|
4
|
+
declare function setTitle(title: string): void;
|
|
5
|
+
declare function setNavigationBarStyle(option: {
|
|
6
6
|
backgroundColor: string;
|
|
7
7
|
frontColor: string;
|
|
8
8
|
}): void;
|
|
9
|
-
|
|
9
|
+
declare function setNavigationBarLoading(loading: boolean): void;
|
|
10
|
+
export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading };
|
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "4.0.1
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Taro-router",
|
|
5
|
-
"author": "O2Team",
|
|
6
|
-
"license": "MIT",
|
|
7
5
|
"browser": "dist/index.js",
|
|
8
6
|
"main:h5": "dist/index.esm.js",
|
|
9
7
|
"main": "dist/index.js",
|
|
@@ -22,34 +20,47 @@
|
|
|
22
20
|
"keywords": [
|
|
23
21
|
"router"
|
|
24
22
|
],
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
},
|
|
23
|
+
"author": "O2Team",
|
|
24
|
+
"license": "MIT",
|
|
28
25
|
"dependencies": {
|
|
29
26
|
"dingtalk-jsapi": "~2.15.2",
|
|
30
|
-
"history": "^5.
|
|
27
|
+
"history": "^5.1.0",
|
|
31
28
|
"mobile-detect": "^1.4.2",
|
|
32
|
-
"query-string": "^
|
|
29
|
+
"query-string": "^7.1.1",
|
|
33
30
|
"tslib": "^2.6.2",
|
|
34
|
-
"universal-router": "^
|
|
31
|
+
"universal-router": "^8.3.0"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
34
|
+
"@rollup/plugin-commonjs": "^24.0.0",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
36
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
37
|
+
"@types/jest": "^29.4.0",
|
|
38
|
+
"jest": "^29.3.1",
|
|
39
|
+
"jest-cli": "^29.3.1",
|
|
40
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
41
|
+
"jsdom": "^21.1.0",
|
|
42
|
+
"rollup": "^3.8.1",
|
|
43
|
+
"rollup-plugin-node-externals": "^5.0.0",
|
|
44
|
+
"rollup-plugin-ts": "^3.0.2",
|
|
45
|
+
"ts-jest": "^29.0.5",
|
|
46
|
+
"typescript": "^4.7.4",
|
|
47
|
+
"@tarojs/taro": "4.0.1",
|
|
48
|
+
"@tarojs/shared": "4.0.1",
|
|
49
|
+
"@tarojs/runtime": "4.0.1"
|
|
41
50
|
},
|
|
42
51
|
"peerDependencies": {
|
|
43
|
-
"@tarojs/runtime": "4.0.1
|
|
44
|
-
"@tarojs/taro": "4.0.1
|
|
45
|
-
"@tarojs/shared": "4.0.1
|
|
52
|
+
"@tarojs/runtime": "4.0.1",
|
|
53
|
+
"@tarojs/taro": "4.0.1",
|
|
54
|
+
"@tarojs/shared": "4.0.1"
|
|
46
55
|
},
|
|
47
56
|
"scripts": {
|
|
48
|
-
"prod": "pnpm run build",
|
|
49
57
|
"prebuild": "pnpm run clean",
|
|
50
58
|
"build": "pnpm run rollup --environment NODE_ENV:production",
|
|
51
|
-
"clean": "rimraf
|
|
59
|
+
"clean": "rimraf ./dist",
|
|
52
60
|
"dev": "pnpm run rollup --environment NODE_ENV:development -w",
|
|
53
|
-
"rollup": "rollup --config rollup.config.
|
|
61
|
+
"rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
|
|
62
|
+
"test": "cross-env NODE_ENV=jest jest",
|
|
63
|
+
"test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
|
|
64
|
+
"test:dev": "cross-env NODE_ENV=jest jest --watch"
|
|
54
65
|
}
|
|
55
66
|
}
|