@tarojs/router 3.5.0-alpha.13 → 3.5.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation.d.ts +4 -0
- package/dist/api.d.ts +7 -0
- package/dist/api.js +2 -2
- package/dist/events/resize.d.ts +2 -0
- package/dist/events/scroll.d.ts +2 -0
- package/dist/events/scroll.js +2 -1
- package/dist/history.d.ts +5 -0
- package/dist/index.cjs.d.ts +23 -0
- package/dist/index.cjs.js +264 -221
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.d.ts +23 -0
- package/dist/index.esm.js +263 -221
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/router/index.d.ts +11 -0
- package/dist/router/mpa.d.ts +10 -0
- package/dist/router/mpa.js +8 -6
- package/dist/router/multi-page.d.ts +27 -0
- package/dist/router/multi-page.js +2 -1
- package/dist/router/page.d.ts +42 -0
- package/dist/router/page.js +5 -4
- package/dist/router/spa.d.ts +3 -0
- package/dist/router/spa.js +18 -12
- package/dist/router/stack.d.ts +18 -0
- package/dist/tabbar.d.ts +2 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/{utils.js → utils/index.js} +5 -1
- package/dist/utils/navigate.d.ts +5 -0
- package/dist/utils/navigate.js +44 -0
- package/package.json +13 -12
- package/types/api.d.ts +10 -12
- package/types/history.d.ts +5 -7
- package/types/router.d.ts +25 -27
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
+
declare class Stacks {
|
|
3
|
+
stacks: PageInstance[];
|
|
4
|
+
backDelta: number;
|
|
5
|
+
set delta(delta: number);
|
|
6
|
+
get delta(): number;
|
|
7
|
+
get length(): number;
|
|
8
|
+
get last(): PageInstance;
|
|
9
|
+
get(): PageInstance[];
|
|
10
|
+
getItem(index: number): PageInstance;
|
|
11
|
+
getLastIndex(pathname: string, stateWith?: number): number;
|
|
12
|
+
getDelta(pathname: string): number;
|
|
13
|
+
getPrevIndex(pathname: string, stateWith?: number): number;
|
|
14
|
+
pop(): PageInstance | undefined;
|
|
15
|
+
push(page: PageInstance): number;
|
|
16
|
+
}
|
|
17
|
+
declare const stacks: Stacks;
|
|
18
|
+
export default stacks;
|
package/dist/tabbar.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
declare class RoutesAlias {
|
|
7
|
+
conf: Array<string[]>;
|
|
8
|
+
set(customRoutes?: Record<string, string | string[]>): void;
|
|
9
|
+
getConfig: (url?: string) => string[];
|
|
10
|
+
getOrigin: (url?: string) => string;
|
|
11
|
+
getAlias: (url?: string) => string;
|
|
12
|
+
getAll: (url?: string) => string[];
|
|
13
|
+
}
|
|
14
|
+
export declare const routesAlias: RoutesAlias;
|
|
15
|
+
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
2
|
+
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
1
3
|
export const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
2
4
|
export const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
3
|
-
export const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.
|
|
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;
|
|
4
8
|
class RoutesAlias {
|
|
5
9
|
constructor() {
|
|
6
10
|
this.conf = [];
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
import MobileDetect from 'mobile-detect';
|
|
11
|
+
let md;
|
|
12
|
+
let preTitle = document.title;
|
|
13
|
+
let isLoadDdEntry = false;
|
|
14
|
+
export function getMobileDetect() {
|
|
15
|
+
if (!md) {
|
|
16
|
+
md = new MobileDetect(navigator.userAgent);
|
|
17
|
+
}
|
|
18
|
+
return md;
|
|
19
|
+
}
|
|
20
|
+
export function setTitle(title) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (preTitle === title)
|
|
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 });
|
|
33
|
+
}
|
|
34
|
+
return title;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function isWeixin() {
|
|
38
|
+
const md = getMobileDetect();
|
|
39
|
+
return md.match(/MicroMessenger/ig);
|
|
40
|
+
}
|
|
41
|
+
export function isDingTalk() {
|
|
42
|
+
const md = getMobileDetect();
|
|
43
|
+
return md.match(/DingTalk/ig);
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "3.5.0-alpha.
|
|
3
|
+
"version": "3.5.0-alpha.16",
|
|
4
4
|
"description": "Taro-router",
|
|
5
5
|
"browser": "dist/index.esm.js",
|
|
6
6
|
"main:h5": "dist/index.js",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist/index.cjs.js",
|
|
9
|
-
"typings": "
|
|
9
|
+
"typings": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"types",
|
|
13
13
|
"index.js"
|
|
14
14
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "rimraf ./dist && tsc && rollup -c",
|
|
17
|
-
"dev": "tsc -w",
|
|
18
|
-
"test": "jest",
|
|
19
|
-
"test:dev": "jest --watch"
|
|
20
|
-
},
|
|
21
15
|
"repository": {
|
|
22
16
|
"type": "git",
|
|
23
17
|
"url": "git+https://github.com/NervJS/taro.git"
|
|
@@ -28,11 +22,18 @@
|
|
|
28
22
|
"author": "O2Team",
|
|
29
23
|
"license": "MIT",
|
|
30
24
|
"dependencies": {
|
|
31
|
-
"@tarojs/runtime": "3.5.0-alpha.
|
|
32
|
-
"@tarojs/taro": "3.5.0-alpha.
|
|
25
|
+
"@tarojs/runtime": "3.5.0-alpha.16",
|
|
26
|
+
"@tarojs/taro": "3.5.0-alpha.16",
|
|
27
|
+
"dingtalk-jsapi": "~2.15.2",
|
|
33
28
|
"history": "^5.1.0",
|
|
29
|
+
"mobile-detect": "^1.4.2",
|
|
34
30
|
"query-string": "^7.1.1",
|
|
35
31
|
"universal-router": "^8.3.0"
|
|
36
32
|
},
|
|
37
|
-
"
|
|
38
|
-
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "rimraf ./dist && tsc && rollup -c",
|
|
35
|
+
"dev": "tsc -w",
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"test:dev": "jest --watch"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/types/api.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
export interface Base {
|
|
2
|
+
success?: (...args: any[]) => void
|
|
3
|
+
fail?: (...args: any[]) => void
|
|
4
|
+
complete?: (...args: any[]) => void
|
|
5
|
+
}
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export interface Option extends Base {
|
|
8
|
+
url: string
|
|
9
|
+
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
11
|
+
export interface NavigateBackOption extends Base {
|
|
12
|
+
delta: number
|
|
15
13
|
}
|
package/types/history.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
url?: string | URL | null
|
|
7
|
-
}
|
|
1
|
+
export interface StateEvent extends Event {
|
|
2
|
+
action?: 'pushState' | 'replaceState' | 'popState'
|
|
3
|
+
state?: any
|
|
4
|
+
unused?: string
|
|
5
|
+
url?: string | URL | null
|
|
8
6
|
}
|
package/types/router.d.ts
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IH5RouterConfig } from '@tarojs/taro/types/compile'
|
|
1
|
+
import type { AppConfig, PageConfig } from '@tarojs/taro'
|
|
2
|
+
import type { IH5RouterConfig } from '@tarojs/taro/types/compile'
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export interface Route extends PageConfig {
|
|
5
|
+
path?: string
|
|
6
|
+
load?: () => Promise<any>
|
|
7
|
+
}
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
export interface Router {
|
|
10
|
+
mode: IH5RouterConfig['mode']
|
|
11
|
+
basename: string
|
|
12
|
+
customRoutes?: Record<string, string | string[]>
|
|
13
|
+
pathname: string
|
|
14
|
+
forcePath?: string
|
|
15
|
+
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
export interface SpaRouterConfig extends AppConfig {
|
|
18
|
+
routes: Route[]
|
|
19
|
+
router: Router
|
|
20
|
+
// 下拉刷新组件
|
|
21
|
+
PullDownRefresh?: any
|
|
22
|
+
}
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
24
|
+
export interface MpaRouterConfig extends AppConfig {
|
|
25
|
+
route: Route,
|
|
26
|
+
pageName: string
|
|
27
|
+
router: Router
|
|
28
|
+
// 下拉刷新组件
|
|
29
|
+
PullDownRefresh?: any
|
|
32
30
|
}
|