@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.
@@ -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;
@@ -0,0 +1,2 @@
1
+ import { AppConfig } from '@tarojs/taro';
2
+ export declare function initTabbar(config: AppConfig): void;
@@ -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.substr(prefix.length) : 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,5 @@
1
+ import MobileDetect from 'mobile-detect';
2
+ export declare function getMobileDetect(): MobileDetect;
3
+ export declare function setTitle(title: string): Promise<string>;
4
+ export declare function isWeixin(): boolean;
5
+ export declare function isDingTalk(): boolean;
@@ -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.13",
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": "src/index.ts",
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.13",
32
- "@tarojs/taro": "3.5.0-alpha.13",
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
- "gitHead": "1e201315913fbeb3a71f14c93a5e7a2fa490e4c4"
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
- declare module '@tarojs/router/types/api' {
2
- interface Base {
3
- success?: (...args: any[]) => void
4
- fail?: (...args: any[]) => void
5
- complete?: (...args: any[]) => void
6
- }
1
+ export interface Base {
2
+ success?: (...args: any[]) => void
3
+ fail?: (...args: any[]) => void
4
+ complete?: (...args: any[]) => void
5
+ }
7
6
 
8
- interface Option extends Base {
9
- url: string
10
- }
7
+ export interface Option extends Base {
8
+ url: string
9
+ }
11
10
 
12
- interface NavigateBackOption extends Base {
13
- delta: number
14
- }
11
+ export interface NavigateBackOption extends Base {
12
+ delta: number
15
13
  }
@@ -1,8 +1,6 @@
1
- declare module '@tarojs/router/types/history' {
2
- interface StateEvent extends Event {
3
- action?: 'pushState' | 'replaceState' | 'popState'
4
- state?: any
5
- unused?: string
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
- declare module '@tarojs/router/types/router' {
2
- import { AppConfig, PageConfig } from '@tarojs/taro'
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
- interface Route extends PageConfig {
6
- path?: string
7
- load?: () => Promise<any>
8
- }
4
+ export interface Route extends PageConfig {
5
+ path?: string
6
+ load?: () => Promise<any>
7
+ }
9
8
 
10
- interface Router {
11
- mode: IH5RouterConfig['mode']
12
- basename: string
13
- customRoutes?: Record<string, string | string[]>
14
- pathname: string
15
- forcePath?: string
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
- interface SpaRouterConfig extends AppConfig {
19
- routes: Route[]
20
- router: Router
21
- // 下拉刷新组件
22
- PullDownRefresh?: any
23
- }
17
+ export interface SpaRouterConfig extends AppConfig {
18
+ routes: Route[]
19
+ router: Router
20
+ // 下拉刷新组件
21
+ PullDownRefresh?: any
22
+ }
24
23
 
25
- interface MpaRouterConfig extends AppConfig {
26
- route: Route,
27
- pageName: string
28
- router: Router
29
- // 下拉刷新组件
30
- PullDownRefresh?: any
31
- }
24
+ export interface MpaRouterConfig extends AppConfig {
25
+ route: Route,
26
+ pageName: string
27
+ router: Router
28
+ // 下拉刷新组件
29
+ PullDownRefresh?: any
32
30
  }