@tarojs/router 4.0.0-alpha.0 → 4.0.0-alpha.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/LICENSE +14 -0
- package/dist/api.d.ts +7 -6
- package/dist/api.js +36 -20
- package/dist/events/resize.d.ts +2 -1
- package/dist/events/resize.js +15 -7
- package/dist/events/scroll.d.ts +2 -1
- package/dist/events/scroll.js +4 -1
- package/dist/history.d.ts +24 -5
- package/dist/history.js +18 -7
- package/dist/index.cjs.d.ts +49 -6
- package/dist/index.cjs.js +551 -229
- package/dist/index.d.ts +10 -4
- package/dist/index.esm.d.ts +49 -6
- package/dist/index.esm.js +510 -199
- package/dist/index.js +52 -4
- package/dist/navigationBar.d.ts +2 -0
- package/dist/navigationBar.js +27 -0
- package/dist/router/index.d.ts +4 -3
- package/dist/router/index.js +5 -2
- package/dist/router/mpa.d.ts +5 -3
- package/dist/router/mpa.js +22 -17
- package/dist/router/multi-page.d.ts +10 -6
- package/dist/router/multi-page.js +27 -43
- package/dist/router/navigation-bar.d.ts +32 -0
- package/dist/router/navigation-bar.js +209 -0
- package/dist/router/page.d.ts +13 -7
- package/dist/router/page.js +36 -45
- package/dist/router/spa.d.ts +5 -3
- package/dist/router/spa.js +40 -26
- package/dist/router/stack.d.ts +1 -1
- package/dist/router/stack.js +2 -1
- package/dist/style.d.ts +8 -2
- package/dist/style.js +65 -5
- package/dist/tabbar.d.ts +3 -1
- package/dist/tabbar.js +4 -3
- package/dist/utils/index.d.ts +3 -9
- package/dist/utils/index.js +5 -20
- package/dist/utils/navigate.d.ts +9 -5
- package/dist/utils/navigate.js +22 -38
- package/package.json +21 -11
- package/types/component.d.ts +5 -0
- package/types/taro.d.ts +8 -0
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
package/dist/router/page.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import { Current, eventCenter, requestAnimationFrame } from '@tarojs/runtime';
|
|
1
|
+
import { getHomePage, getCurrentPage, addLeadingSlash, stripBasename, stripTrailing, requestAnimationFrame, eventCenter, Current } from '@tarojs/runtime';
|
|
3
2
|
import queryString from 'query-string';
|
|
4
|
-
import { bindPageResize } from '../events/resize';
|
|
5
|
-
import { bindPageScroll } from '../events/scroll';
|
|
6
|
-
import {
|
|
7
|
-
import { loadAnimateStyle, loadRouterStyle } from '../style';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import stacks from './stack';
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
import { bindPageResize } from '../events/resize.js';
|
|
4
|
+
import { bindPageScroll } from '../events/scroll.js';
|
|
5
|
+
import { setHistory, history } from '../history.js';
|
|
6
|
+
import { loadAnimateStyle, loadRouterStyle } from '../style.js';
|
|
7
|
+
import { routesAlias } from '../utils/index.js';
|
|
8
|
+
import NavigationBarHandler from './navigation-bar.js';
|
|
9
|
+
import stacks from './stack.js';
|
|
10
|
+
|
|
11
|
+
/* eslint-disable dot-notation */
|
|
12
|
+
class PageHandler {
|
|
13
|
+
constructor(config, history) {
|
|
14
|
+
this.history = history;
|
|
13
15
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
14
16
|
this.config = config;
|
|
15
17
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
16
18
|
this.mount();
|
|
19
|
+
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
17
20
|
}
|
|
18
21
|
get currentPage() {
|
|
19
22
|
const routePath = getCurrentPage(this.routerMode, this.basename);
|
|
@@ -69,6 +72,14 @@ export default class PageHandler {
|
|
|
69
72
|
})) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
|
|
70
73
|
return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
|
|
71
74
|
}
|
|
75
|
+
isDefaultNavigationStyle() {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
78
|
+
if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
79
|
+
style = this.pageConfig.navigationStyle;
|
|
80
|
+
}
|
|
81
|
+
return style !== 'custom';
|
|
82
|
+
}
|
|
72
83
|
isSamePage(page) {
|
|
73
84
|
const routePath = stripBasename(this.pathname, this.basename);
|
|
74
85
|
const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
|
|
@@ -107,40 +118,11 @@ export default class PageHandler {
|
|
|
107
118
|
return Object.assign(Object.assign({}, query), options);
|
|
108
119
|
}
|
|
109
120
|
mount() {
|
|
110
|
-
|
|
121
|
+
setHistory(this.history, this.basename);
|
|
111
122
|
this.pathname = history.location.pathname;
|
|
123
|
+
// Note: 注入页面样式
|
|
112
124
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
113
|
-
loadRouterStyle(this.usingWindowScroll);
|
|
114
|
-
const appId = this.appId;
|
|
115
|
-
let app = document.getElementById(appId);
|
|
116
|
-
let isPosition = true;
|
|
117
|
-
if (!app) {
|
|
118
|
-
app = document.createElement('div');
|
|
119
|
-
app.id = appId;
|
|
120
|
-
isPosition = false;
|
|
121
|
-
}
|
|
122
|
-
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
123
|
-
app.classList.add('taro_router');
|
|
124
|
-
if (this.tabBarList.length > 1) {
|
|
125
|
-
const container = document.createElement('div');
|
|
126
|
-
container.classList.add('taro-tabbar__container');
|
|
127
|
-
container.id = 'container';
|
|
128
|
-
const panel = document.createElement('div');
|
|
129
|
-
panel.classList.add('taro-tabbar__panel');
|
|
130
|
-
panel.appendChild(app.cloneNode(true));
|
|
131
|
-
container.appendChild(panel);
|
|
132
|
-
if (!isPosition) {
|
|
133
|
-
appWrapper.appendChild(container);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
appWrapper.replaceChild(container, app);
|
|
137
|
-
}
|
|
138
|
-
initTabbar(this.config);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
if (!isPosition)
|
|
142
|
-
appWrapper.appendChild(app);
|
|
143
|
-
}
|
|
125
|
+
loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
|
|
144
126
|
}
|
|
145
127
|
onReady(page, onLoad = true) {
|
|
146
128
|
var _a;
|
|
@@ -175,19 +157,24 @@ export default class PageHandler {
|
|
|
175
157
|
if (pageEl) {
|
|
176
158
|
pageEl.classList.remove('taro_page_shade');
|
|
177
159
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
160
|
+
this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
|
|
178
161
|
this.addAnimation(pageEl, pageNo === 0);
|
|
179
162
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
163
|
+
this.navigationBarHandler.load();
|
|
180
164
|
this.bindPageEvents(page, pageConfig);
|
|
181
165
|
this.triggerRouterChange();
|
|
182
166
|
}
|
|
183
167
|
else {
|
|
168
|
+
// FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
|
|
184
169
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
185
170
|
var _a;
|
|
186
171
|
pageEl = this.getPageContainer(page);
|
|
187
172
|
this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
|
|
173
|
+
this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
|
|
188
174
|
this.addAnimation(pageEl, pageNo === 0);
|
|
189
|
-
this.onReady(page, true);
|
|
190
175
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
176
|
+
this.navigationBarHandler.load();
|
|
177
|
+
this.onReady(page, true);
|
|
191
178
|
this.bindPageEvents(page, pageConfig);
|
|
192
179
|
this.triggerRouterChange();
|
|
193
180
|
});
|
|
@@ -241,6 +228,7 @@ export default class PageHandler {
|
|
|
241
228
|
pageEl.classList.remove('taro_page_shade');
|
|
242
229
|
this.addAnimation(pageEl, pageNo === 0);
|
|
243
230
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
231
|
+
this.navigationBarHandler.load();
|
|
244
232
|
this.bindPageEvents(page, pageConfig);
|
|
245
233
|
this.triggerRouterChange();
|
|
246
234
|
}
|
|
@@ -249,8 +237,9 @@ export default class PageHandler {
|
|
|
249
237
|
var _a;
|
|
250
238
|
pageEl = this.getPageContainer(page);
|
|
251
239
|
this.addAnimation(pageEl, pageNo === 0);
|
|
252
|
-
this.onReady(page, false);
|
|
253
240
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
241
|
+
this.navigationBarHandler.load();
|
|
242
|
+
this.onReady(page, false);
|
|
254
243
|
this.bindPageEvents(page, pageConfig);
|
|
255
244
|
this.triggerRouterChange();
|
|
256
245
|
});
|
|
@@ -334,3 +323,5 @@ export default class PageHandler {
|
|
|
334
323
|
}, 0);
|
|
335
324
|
}
|
|
336
325
|
}
|
|
326
|
+
|
|
327
|
+
export { PageHandler as default };
|
package/dist/router/spa.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
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
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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, Current, eventCenter, hooks, incrementId, stringify, } from '@tarojs/runtime';
|
|
12
|
-
import { Action as LocationAction } from 'history';
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { incrementId, addLeadingSlash, eventCenter, stripBasename, Current, createPageConfig, hooks, stringify } from '@tarojs/runtime';
|
|
3
|
+
import { Action } from 'history';
|
|
13
4
|
import UniversalRouter from 'universal-router';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
5
|
+
import { prependBasename } from '../history.js';
|
|
6
|
+
import { routesAlias } from '../utils/index.js';
|
|
7
|
+
import { RouterConfig } from './index.js';
|
|
8
|
+
import PageHandler from './page.js';
|
|
9
|
+
import stacks from './stack.js';
|
|
10
|
+
|
|
20
11
|
const createStampId = incrementId();
|
|
21
12
|
let launchStampId = createStampId();
|
|
22
|
-
|
|
13
|
+
function createRouter(history, app, config, framework) {
|
|
23
14
|
var _a, _b;
|
|
24
15
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
25
16
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
26
17
|
}
|
|
27
18
|
RouterConfig.config = config;
|
|
28
|
-
const handler = new PageHandler(config);
|
|
19
|
+
const handler = new PageHandler(config, history);
|
|
29
20
|
routesAlias.set(handler.router.customRoutes);
|
|
30
21
|
const basename = handler.router.basename;
|
|
31
22
|
const routes = handler.routes.map(route => {
|
|
@@ -48,7 +39,7 @@ export function createRouter(app, config, framework) {
|
|
|
48
39
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
49
40
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
50
41
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
var _c, _d, _e, _f, _g, _h;
|
|
42
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
52
43
|
handler.pathname = decodeURI(location.pathname);
|
|
53
44
|
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
54
45
|
window.scrollTo(0, 0);
|
|
@@ -77,22 +68,34 @@ export function createRouter(app, config, framework) {
|
|
|
77
68
|
window.location.reload();
|
|
78
69
|
}
|
|
79
70
|
else {
|
|
80
|
-
throw
|
|
71
|
+
throw error;
|
|
81
72
|
}
|
|
82
73
|
}
|
|
83
74
|
if (!element)
|
|
84
75
|
return;
|
|
85
76
|
const pageConfig = handler.pageConfig;
|
|
86
77
|
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
78
|
+
let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
|
|
79
|
+
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
80
|
+
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
87
81
|
if (pageConfig) {
|
|
88
|
-
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
89
82
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
90
83
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
91
84
|
}
|
|
85
|
+
if (typeof pageConfig.navigationStyle === 'string') {
|
|
86
|
+
navigationStyle = pageConfig.navigationStyle;
|
|
87
|
+
}
|
|
88
|
+
if (typeof pageConfig.navigationBarTextStyle === 'string') {
|
|
89
|
+
navigationBarTextStyle = pageConfig.navigationBarTextStyle;
|
|
90
|
+
}
|
|
91
|
+
if (typeof pageConfig.navigationBarBackgroundColor === 'string') {
|
|
92
|
+
navigationBarBackgroundColor = pageConfig.navigationBarBackgroundColor;
|
|
93
|
+
}
|
|
92
94
|
}
|
|
95
|
+
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
93
96
|
const currentPage = Current.page;
|
|
94
97
|
const pathname = handler.pathname;
|
|
95
|
-
const methodName = (
|
|
98
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
96
99
|
const cacheTabs = stacks.getTabs();
|
|
97
100
|
let shouldLoad = false;
|
|
98
101
|
stacks.method = '';
|
|
@@ -158,7 +161,7 @@ export function createRouter(app, config, framework) {
|
|
|
158
161
|
shouldLoad = true;
|
|
159
162
|
}
|
|
160
163
|
if (shouldLoad || stacks.length < 1) {
|
|
161
|
-
const el = (
|
|
164
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
162
165
|
const loadConfig = Object.assign({}, pageConfig);
|
|
163
166
|
const stacksIndex = stacks.length;
|
|
164
167
|
delete loadConfig['path'];
|
|
@@ -181,7 +184,18 @@ export function createRouter(app, config, framework) {
|
|
|
181
184
|
if (routePath === '/') {
|
|
182
185
|
history.replace(prependBasename(handler.homePage + history.location.search));
|
|
183
186
|
}
|
|
184
|
-
render({ location: history.location, action:
|
|
187
|
+
render({ location: history.location, action: Action.Push });
|
|
185
188
|
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
189
|
+
window.addEventListener('visibilitychange', () => {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
if (document.visibilityState === 'visible') {
|
|
192
|
+
(_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
(_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
186
198
|
return history.listen(render);
|
|
187
199
|
}
|
|
200
|
+
|
|
201
|
+
export { createRouter };
|
package/dist/router/stack.d.ts
CHANGED
package/dist/router/stack.js
CHANGED
package/dist/style.d.ts
CHANGED
|
@@ -1,8 +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): void;
|
|
9
|
+
/**
|
|
10
|
+
* 插入导航栏相关的样式
|
|
11
|
+
*/
|
|
12
|
+
declare function loadNavigationBarStyle(): void;
|
|
13
|
+
declare function addStyle(css: any): void;
|
|
14
|
+
export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
|
package/dist/style.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 插入页面动画需要的样式
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
function loadAnimateStyle(ms = 300) {
|
|
5
5
|
const css = `
|
|
6
|
+
body {
|
|
7
|
+
overflow: hidden; // 防止 iOS 页面滚动
|
|
8
|
+
}
|
|
6
9
|
.taro_router > .taro_page {
|
|
7
10
|
position: absolute;
|
|
8
11
|
left: 0;
|
|
@@ -29,7 +32,7 @@ export function loadAnimateStyle(ms = 300) {
|
|
|
29
32
|
/**
|
|
30
33
|
* 插入路由相关样式
|
|
31
34
|
*/
|
|
32
|
-
|
|
35
|
+
function loadRouterStyle(enableTabBar, enableWindowScroll) {
|
|
33
36
|
const css = `
|
|
34
37
|
.taro_router {
|
|
35
38
|
position: relative;
|
|
@@ -40,13 +43,13 @@ export function loadRouterStyle(usingWindowScroll) {
|
|
|
40
43
|
.taro_page {
|
|
41
44
|
width: 100%;
|
|
42
45
|
height: 100%;
|
|
43
|
-
|
|
46
|
+
${enableWindowScroll ? '' : `
|
|
44
47
|
overflow-x: hidden;
|
|
45
48
|
overflow-y: scroll;
|
|
46
49
|
max-height: 100vh;
|
|
47
|
-
|
|
50
|
+
`}
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
${enableTabBar ? `
|
|
50
53
|
.taro-tabbar__container > .taro-tabbar__panel {
|
|
51
54
|
overflow: hidden;
|
|
52
55
|
}
|
|
@@ -56,6 +59,7 @@ export function loadRouterStyle(usingWindowScroll) {
|
|
|
56
59
|
max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
` : ''}
|
|
59
63
|
.taro_page_shade,
|
|
60
64
|
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
|
|
61
65
|
display: none;
|
|
@@ -63,6 +67,60 @@ export function loadRouterStyle(usingWindowScroll) {
|
|
|
63
67
|
`;
|
|
64
68
|
addStyle(css);
|
|
65
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* 插入导航栏相关的样式
|
|
72
|
+
*/
|
|
73
|
+
function loadNavigationBarStyle() {
|
|
74
|
+
const css = `
|
|
75
|
+
.taro-navigation-bar-show {
|
|
76
|
+
background: white;
|
|
77
|
+
position: sticky;
|
|
78
|
+
z-index: 500;
|
|
79
|
+
top: 0;
|
|
80
|
+
padding-bottom: 8px;
|
|
81
|
+
padding-top: calc(env(safe-area-inset-top) + 8px);
|
|
82
|
+
display: flex;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
align-items: center;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.taro-navigation-bar-hide {
|
|
88
|
+
display: none;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
taro-navigation-bar-title {
|
|
92
|
+
font-size: 24px;
|
|
93
|
+
height: 24px;
|
|
94
|
+
line-height: 24px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-home {
|
|
98
|
+
display: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-back {
|
|
102
|
+
display: none;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.taro-navigation-bar-home > taro-navigation-bar-home {
|
|
106
|
+
display: block;
|
|
107
|
+
left: 8px;
|
|
108
|
+
position: absolute;
|
|
109
|
+
width: 24px;
|
|
110
|
+
height: 24px;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.taro-navigation-bar-back > taro-navigation-bar-back {
|
|
114
|
+
display: block;
|
|
115
|
+
left: 8px;
|
|
116
|
+
position: absolute;
|
|
117
|
+
width: 24px;
|
|
118
|
+
height: 24px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
`;
|
|
122
|
+
addStyle(css);
|
|
123
|
+
}
|
|
66
124
|
function addStyle(css) {
|
|
67
125
|
if (!css)
|
|
68
126
|
return;
|
|
@@ -70,3 +128,5 @@ function addStyle(css) {
|
|
|
70
128
|
style.innerHTML = css;
|
|
71
129
|
document.getElementsByTagName('head')[0].appendChild(style);
|
|
72
130
|
}
|
|
131
|
+
|
|
132
|
+
export { addStyle, loadAnimateStyle, loadNavigationBarStyle, loadRouterStyle };
|
package/dist/tabbar.d.ts
CHANGED
package/dist/tabbar.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
|
|
3
2
|
import { initTabBarApis } from '@tarojs/taro';
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
|
|
4
|
+
function initTabbar(config, history) {
|
|
6
5
|
if (config.tabBar == null || config.tabBar.custom) {
|
|
7
6
|
return;
|
|
8
7
|
}
|
|
@@ -29,3 +28,5 @@ export function initTabbar(config) {
|
|
|
29
28
|
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
30
29
|
initTabBarApis(config);
|
|
31
30
|
}
|
|
31
|
+
|
|
32
|
+
export { initTabbar };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export declare const addLeadingSlash: (url?: string) => string;
|
|
2
|
-
export declare const hasBasename: (path?: string, prefix?: string) => boolean;
|
|
3
|
-
export declare const stripBasename: (path?: string, prefix?: string) => string;
|
|
4
|
-
export declare const stripTrailing: (str?: string) => string;
|
|
5
|
-
export declare const stripSuffix: (path?: string, suffix?: string) => string;
|
|
6
|
-
export declare const getHomePage: (path?: string, basename?: string, customRoutes?: Record<string, string | string[]>, entryPagePath?: string) => string;
|
|
7
|
-
export declare const getCurrentPage: (routerMode?: string, basename?: string) => string;
|
|
8
1
|
declare class RoutesAlias {
|
|
9
2
|
conf: Array<string[]>;
|
|
10
3
|
set(customRoutes?: Record<string, string | string[]>): void;
|
|
@@ -13,5 +6,6 @@ declare class RoutesAlias {
|
|
|
13
6
|
getAlias: (url?: string) => string;
|
|
14
7
|
getAll: (url?: string) => string[];
|
|
15
8
|
}
|
|
16
|
-
|
|
17
|
-
export {};
|
|
9
|
+
declare const routesAlias: RoutesAlias;
|
|
10
|
+
export { routesAlias };
|
|
11
|
+
export * from "./navigate.js";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
4
|
-
export const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
5
|
-
export const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
6
|
-
export const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
7
|
-
export const stripSuffix = (path = '', suffix = '') => path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path;
|
|
8
|
-
export const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
9
|
-
var _a;
|
|
10
|
-
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
11
|
-
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
12
|
-
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
13
|
-
};
|
|
14
|
-
export const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
15
|
-
const pagePath = routerMode === 'hash'
|
|
16
|
-
? location.hash.slice(1).split('?')[0]
|
|
17
|
-
: location.pathname;
|
|
18
|
-
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
19
|
-
};
|
|
1
|
+
import { addLeadingSlash } from '@tarojs/runtime';
|
|
2
|
+
|
|
20
3
|
class RoutesAlias {
|
|
21
4
|
constructor() {
|
|
22
5
|
this.conf = [];
|
|
@@ -56,4 +39,6 @@ class RoutesAlias {
|
|
|
56
39
|
}
|
|
57
40
|
}
|
|
58
41
|
}
|
|
59
|
-
|
|
42
|
+
const routesAlias = new RoutesAlias();
|
|
43
|
+
|
|
44
|
+
export { routesAlias };
|
package/dist/utils/navigate.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
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
|
+
backgroundColor: string;
|
|
7
|
+
frontColor: string;
|
|
8
|
+
}): void;
|
|
9
|
+
export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle };
|
package/dist/utils/navigate.js
CHANGED
|
@@ -1,44 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
import MobileDetect from 'mobile-detect';
|
|
11
|
-
let md;
|
|
1
|
+
import { eventCenter } from '@tarojs/runtime';
|
|
2
|
+
|
|
3
|
+
const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
|
|
4
|
+
const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
|
|
12
5
|
let preTitle = document.title;
|
|
13
6
|
let isLoadDdEntry = false;
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return title;
|
|
24
|
-
document.title = title;
|
|
25
|
-
preTitle = title;
|
|
26
|
-
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
27
|
-
if (!isLoadDdEntry) {
|
|
28
|
-
isLoadDdEntry = true;
|
|
29
|
-
require('dingtalk-jsapi/platform');
|
|
30
|
-
}
|
|
31
|
-
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
32
|
-
setDingTitle({ title });
|
|
7
|
+
function setMpaTitle(title) {
|
|
8
|
+
if (preTitle === title)
|
|
9
|
+
return;
|
|
10
|
+
document.title = title;
|
|
11
|
+
preTitle = title;
|
|
12
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
13
|
+
if (!isLoadDdEntry) {
|
|
14
|
+
isLoadDdEntry = true;
|
|
15
|
+
require('dingtalk-jsapi/platform');
|
|
33
16
|
}
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
18
|
+
setDingTitle({ title });
|
|
19
|
+
}
|
|
36
20
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return md.match(/MicroMessenger/ig);
|
|
21
|
+
function setTitle(title) {
|
|
22
|
+
eventCenter.trigger('__taroH5SetNavigationTitle', title);
|
|
40
23
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return md.match(/DingTalk/ig);
|
|
24
|
+
function setNavigationBarStyle(option) {
|
|
25
|
+
eventCenter.trigger('__taroH5setNavigationBarColor', option);
|
|
44
26
|
}
|
|
27
|
+
|
|
28
|
+
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarStyle, setTitle };
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
4
|
"description": "Taro-router",
|
|
5
5
|
"browser": "dist/index.js",
|
|
6
6
|
"main:h5": "dist/index.esm.js",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
-
"module": "dist/index.
|
|
9
|
-
"typings": "dist/index.d.ts",
|
|
8
|
+
"module": "dist/index.cjs.js",
|
|
9
|
+
"typings": "dist/index.esm.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"types",
|
|
13
13
|
"index.js"
|
|
14
14
|
],
|
|
15
|
+
"sideEffects": [],
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
17
18
|
"url": "git+https://github.com/NervJS/taro.git"
|
|
@@ -26,29 +27,38 @@
|
|
|
26
27
|
"history": "^5.1.0",
|
|
27
28
|
"mobile-detect": "^1.4.2",
|
|
28
29
|
"query-string": "^7.1.1",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"@tarojs/taro": "4.0.0-alpha.0"
|
|
30
|
+
"tslib": "^2.6.2",
|
|
31
|
+
"universal-router": "^8.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
35
35
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
36
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
36
37
|
"@types/jest": "^29.4.0",
|
|
37
38
|
"jest": "^29.3.1",
|
|
38
39
|
"jest-cli": "^29.3.1",
|
|
39
40
|
"jest-environment-jsdom": "^29.6.4",
|
|
40
41
|
"jsdom": "^21.1.0",
|
|
41
|
-
"rollup": "^
|
|
42
|
+
"rollup": "^3.8.1",
|
|
42
43
|
"rollup-plugin-node-externals": "^5.0.0",
|
|
43
44
|
"rollup-plugin-ts": "^3.0.2",
|
|
44
45
|
"ts-jest": "^29.0.5",
|
|
45
|
-
"typescript": "^4.7.4"
|
|
46
|
+
"typescript": "^4.7.4",
|
|
47
|
+
"@tarojs/runtime": "4.0.0-alpha.2",
|
|
48
|
+
"@tarojs/taro": "4.0.0-alpha.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@tarojs/runtime": "4.0.0-alpha.2",
|
|
52
|
+
"@tarojs/taro": "4.0.0-alpha.2"
|
|
46
53
|
},
|
|
47
54
|
"scripts": {
|
|
48
|
-
"
|
|
49
|
-
"
|
|
55
|
+
"prebuild": "pnpm run clean",
|
|
56
|
+
"build": "pnpm run rollup --environment NODE_ENV:production",
|
|
57
|
+
"clean": "rimraf --impl=move-remove ./dist",
|
|
58
|
+
"dev": "pnpm run rollup --environment NODE_ENV:development -w",
|
|
59
|
+
"rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
|
|
50
60
|
"test": "cross-env NODE_ENV=jest jest",
|
|
51
|
-
"test:ci": "cross-env NODE_ENV=jest jest --ci",
|
|
61
|
+
"test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
|
|
52
62
|
"test:dev": "cross-env NODE_ENV=jest jest --watch"
|
|
53
63
|
}
|
|
54
64
|
}
|
package/types/component.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note: @tarojs/router 不能依赖 @tarojs/components,
|
|
3
|
+
* 因为 @tarojs/components 依赖 @tarojs/router,
|
|
4
|
+
* 且仅通过 peerDependencies 引用依赖会在 pnpm publish 时抛出错误
|
|
5
|
+
*/
|
|
1
6
|
declare module '@tarojs/components/dist/components' {
|
|
2
7
|
export function defineCustomElementTaroTabbar() {}
|
|
3
8
|
|