@viewfly/router 1.0.0-alpha.2 → 1.0.0-alpha.22
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 +94 -0
- package/bundles/index.esm.js +6 -2
- package/bundles/index.js +5 -1
- package/package.json +9 -6
- package/rollup-d.config.ts +14 -0
- package/bundles/link.d.ts +0 -11
- package/bundles/providers/_api.d.ts +0 -2
- package/bundles/providers/navigator.d.ts +0 -38
- package/bundles/providers/router.d.ts +0 -29
- package/bundles/public-api.d.ts +0 -4
- package/bundles/router-module.d.ts +0 -9
- package/bundles/router-outlet.d.ts +0 -6
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ComponentSetup, Props, Module, Application } from '@viewfly/core';
|
|
2
|
+
import { Observable } from '@tanbo/stream';
|
|
3
|
+
|
|
4
|
+
interface RouteConfig {
|
|
5
|
+
path: string;
|
|
6
|
+
component?: ComponentSetup;
|
|
7
|
+
asyncComponent?: () => Promise<ComponentSetup>;
|
|
8
|
+
beforeEach?(): boolean | Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
declare class Router {
|
|
11
|
+
private navigator;
|
|
12
|
+
parent: Router | null;
|
|
13
|
+
path: string;
|
|
14
|
+
onRefresh: Observable<void>;
|
|
15
|
+
get pathname(): string;
|
|
16
|
+
get beforePath(): string;
|
|
17
|
+
private refreshEvent;
|
|
18
|
+
constructor(navigator: Navigator, parent: Router | null, path: string);
|
|
19
|
+
navigateTo(path: string, params?: QueryParams, fragment?: string): void;
|
|
20
|
+
replaceTo(path: string, params?: QueryParams): void;
|
|
21
|
+
refresh(path: string): void;
|
|
22
|
+
consumeConfig(routes: RouteConfig[]): {
|
|
23
|
+
remainingPath: string;
|
|
24
|
+
routeConfig: RouteConfig;
|
|
25
|
+
} | null;
|
|
26
|
+
back(): void;
|
|
27
|
+
forward(): void;
|
|
28
|
+
go(offset: number): void;
|
|
29
|
+
private matchRoute;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface QueryParams {
|
|
33
|
+
[key: string]: string | string[];
|
|
34
|
+
}
|
|
35
|
+
declare abstract class Navigator {
|
|
36
|
+
baseUrl: string;
|
|
37
|
+
protected constructor(baseUrl: string);
|
|
38
|
+
abstract onUrlChanged: Observable<void>;
|
|
39
|
+
abstract get pathname(): string;
|
|
40
|
+
abstract to(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
41
|
+
abstract replace(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
42
|
+
abstract join(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): string;
|
|
43
|
+
abstract back(): void;
|
|
44
|
+
abstract forward(): void;
|
|
45
|
+
abstract go(offset: number): void;
|
|
46
|
+
abstract destroy(): void;
|
|
47
|
+
}
|
|
48
|
+
interface UrlFormatParams {
|
|
49
|
+
queryParams?: QueryParams;
|
|
50
|
+
fragment?: string;
|
|
51
|
+
}
|
|
52
|
+
declare function formatUrl(pathname: string, urlFormatParams: UrlFormatParams): string;
|
|
53
|
+
declare function formatQueryParams(queryParams: QueryParams): string;
|
|
54
|
+
declare class BrowserNavigator extends Navigator {
|
|
55
|
+
onUrlChanged: Observable<void>;
|
|
56
|
+
get pathname(): string;
|
|
57
|
+
private urlChangeEvent;
|
|
58
|
+
private subscription;
|
|
59
|
+
constructor(baseUrl: string);
|
|
60
|
+
to(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
61
|
+
replace(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
62
|
+
join(pathname: string, relative: Router, queryParams?: QueryParams, fragment?: string): string;
|
|
63
|
+
back(): void;
|
|
64
|
+
forward(): void;
|
|
65
|
+
go(offset: number): void;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface LinkProps extends Props {
|
|
70
|
+
to: string;
|
|
71
|
+
active?: string;
|
|
72
|
+
exact?: boolean;
|
|
73
|
+
queryParams?: QueryParams;
|
|
74
|
+
fragment?: string;
|
|
75
|
+
tag?: string;
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
}
|
|
78
|
+
declare function Link(props: LinkProps): () => any;
|
|
79
|
+
|
|
80
|
+
interface RouterOutletProps extends Props {
|
|
81
|
+
config: RouteConfig[];
|
|
82
|
+
}
|
|
83
|
+
declare const RouterOutlet: (props: RouterOutletProps) => () => any;
|
|
84
|
+
|
|
85
|
+
declare class RouterModule implements Module {
|
|
86
|
+
baseUrl: string;
|
|
87
|
+
private subscription;
|
|
88
|
+
private navigator;
|
|
89
|
+
constructor(baseUrl?: string);
|
|
90
|
+
setup(app: Application): void;
|
|
91
|
+
onDestroy(): void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { BrowserNavigator, Link, type LinkProps, Navigator, type QueryParams, type RouteConfig, Router, RouterModule, RouterOutlet, type RouterOutletProps, type UrlFormatParams, formatQueryParams, formatUrl };
|
package/bundles/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, Fragment } from '@viewfly/core/jsx-runtime';
|
|
2
|
-
import { Injectable, inject, createSignal, onUnmounted, withAnnotation, SkipSelf, InjectFlags } from '@viewfly/core';
|
|
2
|
+
import { Injectable, inject, createSignal, onUnmounted, makeError, withAnnotation, SkipSelf, InjectFlags } from '@viewfly/core';
|
|
3
3
|
import { Subject, Subscription, fromEvent } from '@tanbo/stream';
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
@@ -268,6 +268,7 @@ function Link(props) {
|
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
const routerErrorFn = makeError('RouterOutlet');
|
|
271
272
|
const RouterOutlet = withAnnotation({
|
|
272
273
|
providers: [{
|
|
273
274
|
provide: Router,
|
|
@@ -281,8 +282,11 @@ const RouterOutlet = withAnnotation({
|
|
|
281
282
|
}]
|
|
282
283
|
}, function RouterOutlet(props) {
|
|
283
284
|
const children = createSignal(null);
|
|
284
|
-
const router = inject(Router, InjectFlags.SkipSelf);
|
|
285
|
+
const router = inject(Router, null, InjectFlags.SkipSelf);
|
|
285
286
|
const childRouter = inject(Router);
|
|
287
|
+
if (router === null) {
|
|
288
|
+
throw routerErrorFn('cannot found parent Router.');
|
|
289
|
+
}
|
|
286
290
|
const subscription = router.onRefresh.subscribe(() => {
|
|
287
291
|
updateChildren();
|
|
288
292
|
});
|
package/bundles/index.js
CHANGED
|
@@ -270,6 +270,7 @@ function Link(props) {
|
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
+
const routerErrorFn = core.makeError('RouterOutlet');
|
|
273
274
|
const RouterOutlet = core.withAnnotation({
|
|
274
275
|
providers: [{
|
|
275
276
|
provide: Router,
|
|
@@ -283,8 +284,11 @@ const RouterOutlet = core.withAnnotation({
|
|
|
283
284
|
}]
|
|
284
285
|
}, function RouterOutlet(props) {
|
|
285
286
|
const children = core.createSignal(null);
|
|
286
|
-
const router = core.inject(Router, core.InjectFlags.SkipSelf);
|
|
287
|
+
const router = core.inject(Router, null, core.InjectFlags.SkipSelf);
|
|
287
288
|
const childRouter = core.inject(Router);
|
|
289
|
+
if (router === null) {
|
|
290
|
+
throw routerErrorFn('cannot found parent Router.');
|
|
291
|
+
}
|
|
288
292
|
const subscription = router.onRefresh.subscribe(() => {
|
|
289
293
|
updateChildren();
|
|
290
294
|
});
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/router",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
4
4
|
"description": "A routing library based on the Viewfly framework that can be run in the browser or Nodejs background.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
7
|
-
"typings": "./bundles/
|
|
7
|
+
"typings": "./bundles/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build:lib": "rimraf bundles &&
|
|
9
|
+
"build:lib": "rimraf bundles && npm run build && npm run build-d",
|
|
10
|
+
"build": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
|
|
11
|
+
"build-d": "rollup --config rollup-d.config.ts --configPlugin @rollup/plugin-typescript",
|
|
10
12
|
"publish:lib": "npm run build:lib && npm publish --access=public"
|
|
11
13
|
},
|
|
12
14
|
"license": "MIT",
|
|
13
15
|
"keywords": [],
|
|
14
16
|
"dependencies": {
|
|
15
|
-
"@tanbo/stream": "^1.2.
|
|
16
|
-
"@viewfly/core": "^1.0.0-alpha.
|
|
17
|
+
"@tanbo/stream": "^1.2.4",
|
|
18
|
+
"@viewfly/core": "^1.0.0-alpha.22",
|
|
17
19
|
"url": "^0.11.1"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
@@ -21,6 +23,7 @@
|
|
|
21
23
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
22
24
|
"rimraf": "^3.0.2",
|
|
23
25
|
"rollup": "^3.26.3",
|
|
26
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
24
27
|
"tslib": "^2.6.0"
|
|
25
28
|
},
|
|
26
29
|
"author": {
|
|
@@ -34,5 +37,5 @@
|
|
|
34
37
|
"bugs": {
|
|
35
38
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
36
39
|
},
|
|
37
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94"
|
|
38
41
|
}
|
package/bundles/link.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Props } from '@viewfly/core';
|
|
2
|
-
import { QueryParams } from './providers/_api';
|
|
3
|
-
export interface LinkProps extends Props {
|
|
4
|
-
to: string;
|
|
5
|
-
active?: string;
|
|
6
|
-
exact?: boolean;
|
|
7
|
-
queryParams?: QueryParams;
|
|
8
|
-
fragment?: string;
|
|
9
|
-
tag?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function Link(props: LinkProps): () => any;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Observable } from '@tanbo/stream';
|
|
2
|
-
import { Router } from './router';
|
|
3
|
-
export interface QueryParams {
|
|
4
|
-
[key: string]: string | string[];
|
|
5
|
-
}
|
|
6
|
-
export declare abstract class Navigator {
|
|
7
|
-
baseUrl: string;
|
|
8
|
-
protected constructor(baseUrl: string);
|
|
9
|
-
abstract onUrlChanged: Observable<void>;
|
|
10
|
-
abstract get pathname(): string;
|
|
11
|
-
abstract to(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
12
|
-
abstract replace(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
13
|
-
abstract join(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): string;
|
|
14
|
-
abstract back(): void;
|
|
15
|
-
abstract forward(): void;
|
|
16
|
-
abstract go(offset: number): void;
|
|
17
|
-
abstract destroy(): void;
|
|
18
|
-
}
|
|
19
|
-
export interface UrlFormatParams {
|
|
20
|
-
queryParams?: QueryParams;
|
|
21
|
-
fragment?: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function formatUrl(pathname: string, urlFormatParams: UrlFormatParams): string;
|
|
24
|
-
export declare function formatQueryParams(queryParams: QueryParams): string;
|
|
25
|
-
export declare class BrowserNavigator extends Navigator {
|
|
26
|
-
onUrlChanged: Observable<void>;
|
|
27
|
-
get pathname(): string;
|
|
28
|
-
private urlChangeEvent;
|
|
29
|
-
private subscription;
|
|
30
|
-
constructor(baseUrl: string);
|
|
31
|
-
to(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
32
|
-
replace(pathName: string, relative: Router, queryParams?: QueryParams, fragment?: string): boolean;
|
|
33
|
-
join(pathname: string, relative: Router, queryParams?: QueryParams, fragment?: string): string;
|
|
34
|
-
back(): void;
|
|
35
|
-
forward(): void;
|
|
36
|
-
go(offset: number): void;
|
|
37
|
-
destroy(): void;
|
|
38
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Observable } from '@tanbo/stream';
|
|
2
|
-
import { Navigator, QueryParams } from './navigator';
|
|
3
|
-
export interface RouteConfig {
|
|
4
|
-
path: string;
|
|
5
|
-
component?: JSXInternal.ComponentSetup;
|
|
6
|
-
asyncComponent?: () => Promise<JSXInternal.ComponentSetup>;
|
|
7
|
-
beforeEach?(): boolean | Promise<boolean>;
|
|
8
|
-
}
|
|
9
|
-
export declare class Router {
|
|
10
|
-
private navigator;
|
|
11
|
-
parent: Router | null;
|
|
12
|
-
path: string;
|
|
13
|
-
onRefresh: Observable<void>;
|
|
14
|
-
get pathname(): string;
|
|
15
|
-
get beforePath(): string;
|
|
16
|
-
private refreshEvent;
|
|
17
|
-
constructor(navigator: Navigator, parent: Router | null, path: string);
|
|
18
|
-
navigateTo(path: string, params?: QueryParams, fragment?: string): void;
|
|
19
|
-
replaceTo(path: string, params?: QueryParams): void;
|
|
20
|
-
refresh(path: string): void;
|
|
21
|
-
consumeConfig(routes: RouteConfig[]): {
|
|
22
|
-
remainingPath: string;
|
|
23
|
-
routeConfig: RouteConfig;
|
|
24
|
-
} | null;
|
|
25
|
-
back(): void;
|
|
26
|
-
forward(): void;
|
|
27
|
-
go(offset: number): void;
|
|
28
|
-
private matchRoute;
|
|
29
|
-
}
|
package/bundles/public-api.d.ts
DELETED