@tarojs/router 4.0.0-beta.1 → 4.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -158,3 +158,17 @@ MIT (stencil-vue2-output-target):
158
158
  The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
159
159
  `/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
160
160
  See `/LICENSE` for details of the license.
161
+
162
+ ==================
163
+
164
+ MIT (weui):
165
+ The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
166
+ `/packages/taro-components/src/components/*.scss`
167
+ See `/LICENSE.txt` for details of the license.
168
+
169
+ ==================
170
+
171
+ Apache-2.0 (intersection-observer):
172
+ The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
173
+ `/packages/taro-api/src/polyfill/intersection-observer.ts`
174
+ See `/LICENSE.txt` for details of the license.
package/dist/api.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import Taro from '@tarojs/taro';
2
- export declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
3
- export declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
4
- export declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
5
- export declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
6
- export declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
7
- export declare function getCurrentPages(): Taro.Page[];
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/api.js CHANGED
@@ -1,17 +1,11 @@
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
- };
1
+ import { __awaiter } from 'tslib';
2
+ import { addLeadingSlash } from '@tarojs/runtime';
10
3
  import { parsePath } from 'history';
11
- import { history, prependBasename } from './history';
12
- import { RouterConfig } from './router';
13
- import stacks from './router/stack';
14
- import { addLeadingSlash, routesAlias } from './utils';
4
+ import { history, prependBasename } from './history.js';
5
+ import { RouterConfig } from './router/index.js';
6
+ import stacks from './router/stack.js';
7
+ import { routesAlias } from './utils/index.js';
8
+
15
9
  function processNavigateUrl(option) {
16
10
  var _a;
17
11
  const pathPieces = parsePath(option.url);
@@ -82,28 +76,30 @@ function navigate(option, method) {
82
76
  });
83
77
  });
84
78
  }
85
- export function navigateTo(option) {
79
+ function navigateTo(option) {
86
80
  return navigate(option, 'navigateTo');
87
81
  }
88
- export function redirectTo(option) {
82
+ function redirectTo(option) {
89
83
  return navigate(option, 'redirectTo');
90
84
  }
91
- export function navigateBack(option = { delta: 1 }) {
85
+ function navigateBack(option = { delta: 1 }) {
92
86
  if (!option.delta || option.delta < 1) {
93
87
  option.delta = 1;
94
88
  }
95
89
  return navigate(option, 'navigateBack');
96
90
  }
97
- export function switchTab(option) {
91
+ function switchTab(option) {
98
92
  return navigate(option, 'switchTab');
99
93
  }
100
- export function reLaunch(option) {
94
+ function reLaunch(option) {
101
95
  return navigate(option, 'reLaunch');
102
96
  }
103
- export function getCurrentPages() {
97
+ function getCurrentPages() {
104
98
  if (process.env.NODE_ENV !== 'production' && RouterConfig.mode === 'multi') {
105
99
  console.warn('多页面路由模式不支持使用 getCurrentPages 方法!');
106
100
  }
107
101
  const pages = stacks.get();
108
102
  return pages.map(e => { var _a; return (Object.assign(Object.assign({}, e), { route: ((_a = e.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) || '' })); });
109
103
  }
104
+
105
+ export { getCurrentPages, navigateBack, navigateTo, reLaunch, redirectTo, switchTab };
@@ -1,2 +1,3 @@
1
1
  import { PageInstance } from '@tarojs/runtime';
2
- export declare function bindPageResize(page: PageInstance): void;
2
+ declare function bindPageResize(page: PageInstance): void;
3
+ export { bindPageResize };
@@ -1,5 +1,5 @@
1
1
  let pageResizeFn;
2
- export function bindPageResize(page) {
2
+ function bindPageResize(page) {
3
3
  pageResizeFn && window.removeEventListener('resize', pageResizeFn);
4
4
  pageResizeFn = function () {
5
5
  page.onResize && page.onResize({
@@ -11,3 +11,5 @@ export function bindPageResize(page) {
11
11
  };
12
12
  window.addEventListener('resize', pageResizeFn, false);
13
13
  }
14
+
15
+ export { bindPageResize };
@@ -1,2 +1,3 @@
1
1
  import { PageInstance } from '@tarojs/runtime';
2
- export declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
2
+ declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
3
+ export { bindPageScroll };
@@ -1,7 +1,8 @@
1
1
  import { Current } from '@tarojs/runtime';
2
+
2
3
  const pageScrollFn = {};
3
4
  let pageDOM = window;
4
- export function bindPageScroll(page, scrollEl, distance = 50) {
5
+ function bindPageScroll(page, scrollEl, distance = 50) {
5
6
  var _a;
6
7
  const pagePath = (page ? page === null || page === void 0 ? void 0 : page.path : (_a = Current.router) === null || _a === void 0 ? void 0 : _a.path);
7
8
  pageScrollFn[pagePath] && scrollEl.removeEventListener('scroll', pageScrollFn[pagePath]);
@@ -32,3 +33,5 @@ function getOffset() {
32
33
  return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
33
34
  }
34
35
  }
36
+
37
+ export { bindPageScroll };
package/dist/history.d.ts CHANGED
@@ -1,5 +1,24 @@
1
- import type { IH5RouterConfig } from '@tarojs/taro/types/compile';
2
- import type { History } from 'history';
3
- export declare let history: History;
4
- export declare function setHistoryMode(mode?: IH5RouterConfig['mode'], base?: string): void;
5
- export declare function prependBasename(url?: string): string;
1
+ import { IH5RouterConfig } from '@tarojs/taro/types/compile';
2
+ import { StateEvent } from '../types/history';
3
+ declare let history: History;
4
+ declare class MpaHistory implements History {
5
+ action: Action;
6
+ get location(): Location;
7
+ createHref(_to: To): string;
8
+ parseUrl(to: Partial<Path>): string;
9
+ push(to: Partial<Path>, _state?: Record<string, unknown>): void;
10
+ replace(to: Partial<Path>, _state?: Record<string, unknown>): void;
11
+ go(delta: number): void;
12
+ back: () => void;
13
+ forward: () => void;
14
+ listen(listener: Listener): () => void;
15
+ block(_blocker: Blocker): () => void;
16
+ pushState: globalThis.History['pushState'];
17
+ replaceState: globalThis.History['replaceState'];
18
+ eventState(action: Required<StateEvent>['action']): (data: any, unused: string, url?: string | URL | null) => any;
19
+ }
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 };
package/dist/history.js CHANGED
@@ -1,6 +1,8 @@
1
- import { Action, createBrowserHistory, createHashHistory } from 'history';
2
- import { RouterConfig } from './router';
3
- export let history;
1
+ import { createBrowserHistory, createHashHistory, Action } from 'history';
2
+ export { createBrowserHistory, createHashHistory } from 'history';
3
+ import { RouterConfig } from './router/index.js';
4
+
5
+ let history;
4
6
  let basename = '/';
5
7
  class MpaHistory {
6
8
  constructor() {
@@ -79,7 +81,14 @@ class MpaHistory {
79
81
  };
80
82
  }
81
83
  }
82
- export function setHistoryMode(mode, base = '/') {
84
+ function setHistory(h, base = '/') {
85
+ history = h;
86
+ basename = base;
87
+ }
88
+ function createMpaHistory(_) {
89
+ return new MpaHistory();
90
+ }
91
+ function setHistoryMode(mode, base = '/') {
83
92
  const options = {
84
93
  window
85
94
  };
@@ -88,13 +97,15 @@ export function setHistoryMode(mode, base = '/') {
88
97
  history = createBrowserHistory(options);
89
98
  }
90
99
  else if (mode === 'multi') {
91
- history = new MpaHistory();
100
+ history = createMpaHistory();
92
101
  }
93
102
  else {
94
103
  // default is hash
95
104
  history = createHashHistory(options);
96
105
  }
97
106
  }
98
- export function prependBasename(url = '') {
107
+ function prependBasename(url = '') {
99
108
  return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
100
109
  }
110
+
111
+ export { createMpaHistory, history, prependBasename, setHistory, setHistoryMode };
@@ -1,14 +1,38 @@
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';
1
5
  import Taro from "@tarojs/taro";
2
- import { History } from "history";
3
6
  import { AppInstance } from "@tarojs/runtime";
4
- import { MpaRouterConfig, SpaRouterConfig } from "../../types/router";
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;
5
30
  declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
6
31
  declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
7
32
  declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
8
33
  declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
9
34
  declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
10
35
  declare function getCurrentPages(): Taro.Page[];
11
- declare let history: History;
12
36
  // TODO 支持多路由 (APP 生命周期仅触发一次)
13
37
  /** Note: 关于多页面应用
14
38
  * - 需要配置路由映射(根目录跳转、404 页面……)
@@ -17,6 +41,20 @@ declare let history: History;
17
41
  * - TabBar 会多次加载
18
42
  * - 不支持路由动画
19
43
  */
20
- declare function createMultiRouter(app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
21
- declare function createRouter(app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
22
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, createMultiRouter, createRouter };
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 setTitle(title: string): Promise<string>;
58
+ declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
59
+ declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
60
+ export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setTitle, handleAppMount, handleAppMountWithTabbar };