@viewfly/router 2.0.0-alpha.1 → 2.0.0-alpha.4
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/bundles/index.d.ts +74 -20
- package/bundles/index.esm.js +442 -195
- package/bundles/index.js +442 -193
- package/package.json +3 -3
package/bundles/index.d.ts
CHANGED
|
@@ -1,29 +1,68 @@
|
|
|
1
|
-
import * as _viewfly_core_jsx_runtime from '@viewfly/core/jsx-runtime';
|
|
2
|
-
import { ComponentSetup, Props, Module, Application } from '@viewfly/core';
|
|
3
1
|
import { Observable } from '@tanbo/stream';
|
|
2
|
+
import { ComponentSetup, Props, Module, Application } from '@viewfly/core';
|
|
3
|
+
import * as _viewfly_core_jsx_runtime from '@viewfly/core/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
interface UrlRelativePath {
|
|
6
|
+
type: 'toParent';
|
|
7
|
+
}
|
|
8
|
+
interface UrlChildPath {
|
|
9
|
+
type: 'toChild';
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
interface UrlQuery {
|
|
13
|
+
type: 'query';
|
|
14
|
+
params: UrlQueryParams;
|
|
15
|
+
}
|
|
16
|
+
interface UrlQueryParams {
|
|
17
|
+
[key: string]: string | string[];
|
|
18
|
+
}
|
|
19
|
+
interface UrlHash {
|
|
20
|
+
type: 'hash';
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
type UrlToken = UrlRelativePath | UrlChildPath | UrlQuery | UrlHash;
|
|
24
|
+
interface UrlTree {
|
|
25
|
+
paths: string[];
|
|
26
|
+
queryParams: UrlQueryParams;
|
|
27
|
+
hash: string | null;
|
|
28
|
+
}
|
|
29
|
+
declare class UrlParser {
|
|
30
|
+
private index;
|
|
31
|
+
private url;
|
|
32
|
+
private tokens;
|
|
33
|
+
parse(url: string): UrlTree;
|
|
34
|
+
private readHash;
|
|
35
|
+
private readQuery;
|
|
36
|
+
private readQueryValue;
|
|
37
|
+
private readQueryKey;
|
|
38
|
+
private readPath;
|
|
39
|
+
private not;
|
|
40
|
+
private peek;
|
|
41
|
+
private ignore;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare function useQueryParams<T extends UrlQueryParams>(): T;
|
|
4
45
|
|
|
5
46
|
interface RouteConfig {
|
|
6
47
|
path: string;
|
|
7
48
|
component?: ComponentSetup;
|
|
8
49
|
asyncComponent?: () => Promise<ComponentSetup>;
|
|
9
50
|
beforeEach?(): boolean | Promise<boolean>;
|
|
51
|
+
afterEach?(): void;
|
|
52
|
+
redirectTo?: string | ((path: string) => string | NavigatorParams);
|
|
10
53
|
}
|
|
11
54
|
declare class Router {
|
|
12
55
|
private navigator;
|
|
13
56
|
parent: Router | null;
|
|
14
|
-
path: string;
|
|
15
57
|
onRefresh: Observable<void>;
|
|
16
|
-
get
|
|
17
|
-
get
|
|
58
|
+
get deep(): number;
|
|
59
|
+
get path(): string;
|
|
18
60
|
private refreshEvent;
|
|
19
|
-
constructor(navigator: Navigator, parent: Router | null
|
|
20
|
-
navigateTo(path: string, params?: QueryParams, fragment?: string): void;
|
|
61
|
+
constructor(navigator: Navigator, parent: Router | null);
|
|
62
|
+
navigateTo(path: string, params?: QueryParams, fragment?: string | null): void;
|
|
21
63
|
replaceTo(path: string, params?: QueryParams): void;
|
|
22
|
-
refresh(
|
|
23
|
-
consumeConfig(routes: RouteConfig[]):
|
|
24
|
-
remainingPath: string;
|
|
25
|
-
routeConfig: RouteConfig;
|
|
26
|
-
} | null;
|
|
64
|
+
refresh(): void;
|
|
65
|
+
consumeConfig(routes: RouteConfig[]): RouteConfig | null;
|
|
27
66
|
back(): void;
|
|
28
67
|
forward(): void;
|
|
29
68
|
go(offset: number): void;
|
|
@@ -35,6 +74,7 @@ interface QueryParams {
|
|
|
35
74
|
}
|
|
36
75
|
declare abstract class Navigator {
|
|
37
76
|
baseUrl: string;
|
|
77
|
+
abstract urlTree: UrlTree;
|
|
38
78
|
protected constructor(baseUrl: string);
|
|
39
79
|
abstract onUrlChanged: Observable<void>;
|
|
40
80
|
abstract get pathname(): string;
|
|
@@ -52,12 +92,24 @@ interface UrlFormatParams {
|
|
|
52
92
|
}
|
|
53
93
|
declare function formatUrl(pathname: string, urlFormatParams: UrlFormatParams): string;
|
|
54
94
|
declare function formatQueryParams(queryParams: QueryParams): string;
|
|
95
|
+
interface NavigatorParams {
|
|
96
|
+
pathname: string;
|
|
97
|
+
queryParams: QueryParams;
|
|
98
|
+
fragment: string | null;
|
|
99
|
+
}
|
|
100
|
+
interface NavigatorHooks {
|
|
101
|
+
beforeEach?(currentParams: NavigatorParams, nextParams: NavigatorParams, next: () => void): void;
|
|
102
|
+
afterEach?(params: NavigatorParams): void;
|
|
103
|
+
}
|
|
55
104
|
declare class BrowserNavigator extends Navigator {
|
|
105
|
+
private hooks;
|
|
56
106
|
onUrlChanged: Observable<void>;
|
|
57
107
|
get pathname(): string;
|
|
108
|
+
private urlParser;
|
|
109
|
+
urlTree: UrlTree;
|
|
58
110
|
private urlChangeEvent;
|
|
59
111
|
private subscription;
|
|
60
|
-
constructor(baseUrl: string);
|
|
112
|
+
constructor(baseUrl: string, hooks?: NavigatorHooks);
|
|
61
113
|
to(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
62
114
|
replace(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
63
115
|
join(pathname: string, relative: Router, queryParams?: QueryParams, fragment?: string): string;
|
|
@@ -65,6 +117,8 @@ declare class BrowserNavigator extends Navigator {
|
|
|
65
117
|
forward(): void;
|
|
66
118
|
go(offset: number): void;
|
|
67
119
|
destroy(): void;
|
|
120
|
+
private runHooks;
|
|
121
|
+
private getUrlTree;
|
|
68
122
|
}
|
|
69
123
|
|
|
70
124
|
interface LinkProps extends Props {
|
|
@@ -78,18 +132,18 @@ interface LinkProps extends Props {
|
|
|
78
132
|
}
|
|
79
133
|
declare function Link(props: LinkProps): () => _viewfly_core_jsx_runtime.JSX.Element;
|
|
80
134
|
|
|
81
|
-
interface RouterOutletProps extends Props {
|
|
82
|
-
config: RouteConfig[];
|
|
83
|
-
}
|
|
84
|
-
declare function RouterOutlet(props: RouterOutletProps): () => _viewfly_core_jsx_runtime.JSX.Element;
|
|
85
|
-
|
|
86
135
|
declare class RouterModule implements Module {
|
|
87
136
|
baseUrl: string;
|
|
88
137
|
private subscription;
|
|
89
138
|
private navigator;
|
|
90
|
-
constructor(baseUrl?: string);
|
|
139
|
+
constructor(baseUrl?: string, hooks?: NavigatorHooks);
|
|
91
140
|
setup(app: Application): void;
|
|
92
141
|
onDestroy(): void;
|
|
93
142
|
}
|
|
94
143
|
|
|
95
|
-
|
|
144
|
+
interface RouterOutletProps extends Props {
|
|
145
|
+
config: RouteConfig[];
|
|
146
|
+
}
|
|
147
|
+
declare function RouterOutlet(props: RouterOutletProps): () => _viewfly_core_jsx_runtime.JSX.Element;
|
|
148
|
+
|
|
149
|
+
export { BrowserNavigator, Link, type LinkProps, Navigator, type NavigatorHooks, type NavigatorParams, type QueryParams, type RouteConfig, Router, RouterModule, RouterOutlet, type RouterOutletProps, type UrlChildPath, type UrlFormatParams, type UrlHash, UrlParser, type UrlQuery, type UrlQueryParams, type UrlRelativePath, type UrlToken, type UrlTree, formatQueryParams, formatUrl, useQueryParams };
|