@viewfly/router 2.1.0 → 3.0.0-alpha.0
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/README.md +58 -112
- package/dist/hooks/_api.d.ts +1 -0
- package/dist/hooks/use-query-params.d.ts +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +479 -0
- package/dist/index.js +494 -0
- package/dist/link.d.ts +12 -0
- package/dist/providers/_api.d.ts +3 -0
- package/dist/providers/navigator.d.ts +56 -0
- package/dist/providers/router.d.ts +28 -0
- package/dist/providers/url-parser.d.ts +38 -0
- package/dist/router-module.d.ts +10 -0
- package/dist/router-outlet.d.ts +6 -0
- package/package.json +27 -20
- package/bundles/index.d.ts +0 -151
- package/bundles/index.esm.js +0 -674
- package/bundles/index.js +0 -684
- package/rollup-d.config.ts +0 -14
package/package.json
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"description": "A routing library based on the Viewfly framework that can be run in the browser or Nodejs background.",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
7
|
-
"typings": "./
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.esm.js",
|
|
7
|
+
"typings": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.esm.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
13
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/**/*"
|
|
17
|
+
],
|
|
14
18
|
"license": "MIT",
|
|
15
19
|
"keywords": [],
|
|
16
20
|
"dependencies": {
|
|
17
21
|
"@tanbo/stream": "^1.2.4",
|
|
18
|
-
"@viewfly/core": "^
|
|
19
|
-
"url": "^0.11.
|
|
22
|
+
"@viewfly/core": "^3.0.0-alpha.0",
|
|
23
|
+
"url": "^0.11.4"
|
|
20
24
|
},
|
|
21
25
|
"devDependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"tslib": "^2.6.0"
|
|
26
|
+
"rimraf": "^6.0.1",
|
|
27
|
+
"tslib": "^2.8.1",
|
|
28
|
+
"typescript": "~5.8.3",
|
|
29
|
+
"vite": "^8.0.9",
|
|
30
|
+
"vite-plugin-dts": "^4.5.4"
|
|
28
31
|
},
|
|
29
32
|
"author": {
|
|
30
33
|
"name": "Tanbo",
|
|
@@ -35,7 +38,11 @@
|
|
|
35
38
|
"url": "git+https://github.com/viewfly/viewfly.git"
|
|
36
39
|
},
|
|
37
40
|
"bugs": {
|
|
38
|
-
"url": "https://github.com/viewfly/viewfly
|
|
41
|
+
"url": "https://github.com/viewfly/viewfly/issues"
|
|
39
42
|
},
|
|
40
|
-
"
|
|
41
|
-
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build:lib": "rimraf dist && pnpm run build && rimraf dist/router",
|
|
45
|
+
"build": "vite build --config vite.config.ts",
|
|
46
|
+
"publish:lib": "npm run build:lib && npm publish --access=public"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/bundles/index.d.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
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;
|
|
45
|
-
|
|
46
|
-
interface RouteConfig {
|
|
47
|
-
path: string;
|
|
48
|
-
component?: ComponentSetup;
|
|
49
|
-
asyncComponent?: () => Promise<ComponentSetup>;
|
|
50
|
-
beforeEach?(): boolean | Promise<boolean>;
|
|
51
|
-
afterEach?(): void;
|
|
52
|
-
redirectTo?: string | ((path: string) => string | NavigatorParams);
|
|
53
|
-
}
|
|
54
|
-
declare class Router {
|
|
55
|
-
private navigator;
|
|
56
|
-
parent: Router | null;
|
|
57
|
-
onRefresh: Observable<void>;
|
|
58
|
-
get deep(): number;
|
|
59
|
-
get path(): string;
|
|
60
|
-
private refreshEvent;
|
|
61
|
-
constructor(navigator: Navigator, parent: Router | null);
|
|
62
|
-
navigateTo(path: string, params?: QueryParams, fragment?: string | null): void;
|
|
63
|
-
replaceTo(path: string, params?: QueryParams): void;
|
|
64
|
-
refresh(): void;
|
|
65
|
-
consumeConfig(routes: RouteConfig[]): RouteConfig | null;
|
|
66
|
-
back(): void;
|
|
67
|
-
forward(): void;
|
|
68
|
-
go(offset: number): void;
|
|
69
|
-
private matchRoute;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
interface QueryParams {
|
|
73
|
-
[key: string]: string | string[];
|
|
74
|
-
}
|
|
75
|
-
declare abstract class Navigator {
|
|
76
|
-
baseUrl: string;
|
|
77
|
-
abstract urlTree: UrlTree;
|
|
78
|
-
protected constructor(baseUrl: string);
|
|
79
|
-
abstract onUrlChanged: Observable<void>;
|
|
80
|
-
abstract get pathname(): string;
|
|
81
|
-
abstract to(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
82
|
-
abstract replace(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
83
|
-
abstract join(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): string;
|
|
84
|
-
abstract back(): void;
|
|
85
|
-
abstract forward(): void;
|
|
86
|
-
abstract go(offset: number): void;
|
|
87
|
-
abstract destroy(): void;
|
|
88
|
-
}
|
|
89
|
-
interface UrlFormatParams {
|
|
90
|
-
queryParams?: QueryParams;
|
|
91
|
-
fragment?: string;
|
|
92
|
-
}
|
|
93
|
-
declare function formatUrl(pathname: string, urlFormatParams: UrlFormatParams): string;
|
|
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
|
-
}
|
|
104
|
-
declare class BrowserNavigator extends Navigator {
|
|
105
|
-
private hooks;
|
|
106
|
-
onUrlChanged: Observable<void>;
|
|
107
|
-
/** 挂载在 location 上的路径前缀;'' 或 '/' 表示站点根,不做剥离 */
|
|
108
|
-
private get basePathPrefix();
|
|
109
|
-
get pathname(): string;
|
|
110
|
-
private urlParser;
|
|
111
|
-
urlTree: UrlTree;
|
|
112
|
-
private urlChangeEvent;
|
|
113
|
-
private subscription;
|
|
114
|
-
constructor(baseUrl: string, hooks?: NavigatorHooks);
|
|
115
|
-
to(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
116
|
-
replace(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
117
|
-
join(pathname: string, relative: Router, queryParams?: QueryParams, fragment?: string): string;
|
|
118
|
-
back(): void;
|
|
119
|
-
forward(): void;
|
|
120
|
-
go(offset: number): void;
|
|
121
|
-
destroy(): void;
|
|
122
|
-
private runHooks;
|
|
123
|
-
private getUrlTree;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
interface LinkProps extends Props {
|
|
127
|
-
to: string;
|
|
128
|
-
active?: string;
|
|
129
|
-
exact?: boolean;
|
|
130
|
-
queryParams?: QueryParams;
|
|
131
|
-
fragment?: string;
|
|
132
|
-
tag?: string;
|
|
133
|
-
[key: string]: any;
|
|
134
|
-
}
|
|
135
|
-
declare function Link(props: LinkProps): () => _viewfly_core_jsx_runtime.JSX.Element;
|
|
136
|
-
|
|
137
|
-
declare class RouterModule implements Module {
|
|
138
|
-
baseUrl: string;
|
|
139
|
-
private subscription;
|
|
140
|
-
private navigator;
|
|
141
|
-
constructor(baseUrl?: string, hooks?: NavigatorHooks);
|
|
142
|
-
setup(app: Application): void;
|
|
143
|
-
onDestroy(): void;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
interface RouterOutletProps extends Props {
|
|
147
|
-
config: RouteConfig[];
|
|
148
|
-
}
|
|
149
|
-
declare function RouterOutlet(props: RouterOutletProps): () => _viewfly_core_jsx_runtime.JSX.Element;
|
|
150
|
-
|
|
151
|
-
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 };
|