mobx-route 0.18.0 → 0.19.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/index.cjs +536 -17
- package/index.cjs.map +1 -0
- package/index.d.ts +420 -2
- package/index.js +532 -2
- package/index.js.map +1 -0
- package/package.json +20 -63
- package/react.cjs +170 -0
- package/react.cjs.map +1 -0
- package/react.d.ts +71 -0
- package/react.js +170 -0
- package/react.js.map +1 -0
- package/view-model.cjs +56 -0
- package/view-model.cjs.map +1 -0
- package/view-model.d.ts +14 -0
- package/view-model.js +56 -0
- package/view-model.js.map +1 -0
- package/core/config/config.cjs +0 -36
- package/core/config/config.d.cts +0 -7
- package/core/config/config.d.cts.map +0 -1
- package/core/config/config.d.ts +0 -7
- package/core/config/config.d.ts.map +0 -1
- package/core/config/config.js +0 -33
- package/core/config/config.types.cjs +0 -2
- package/core/config/config.types.d.cts +0 -11
- package/core/config/config.types.d.cts.map +0 -1
- package/core/config/config.types.d.ts +0 -11
- package/core/config/config.types.d.ts.map +0 -1
- package/core/config/config.types.js +0 -1
- package/core/config/index.cjs +0 -18
- package/core/config/index.d.cts +0 -3
- package/core/config/index.d.cts.map +0 -1
- package/core/config/index.d.ts +0 -3
- package/core/config/index.d.ts.map +0 -1
- package/core/config/index.js +0 -2
- package/core/index.cjs +0 -21
- package/core/index.d.cts +0 -6
- package/core/index.d.cts.map +0 -1
- package/core/index.d.ts +0 -6
- package/core/index.d.ts.map +0 -1
- package/core/index.js +0 -5
- package/core/route/index.cjs +0 -18
- package/core/route/index.d.cts +0 -3
- package/core/route/index.d.cts.map +0 -1
- package/core/route/index.d.ts +0 -3
- package/core/route/index.d.ts.map +0 -1
- package/core/route/index.js +0 -2
- package/core/route/route.cjs +0 -296
- package/core/route/route.d.cts +0 -107
- package/core/route/route.d.cts.map +0 -1
- package/core/route/route.d.ts +0 -107
- package/core/route/route.d.ts.map +0 -1
- package/core/route/route.js +0 -291
- package/core/route/route.types.cjs +0 -2
- package/core/route/route.types.d.cts +0 -142
- package/core/route/route.types.d.cts.map +0 -1
- package/core/route/route.types.d.ts +0 -142
- package/core/route/route.types.d.ts.map +0 -1
- package/core/route/route.types.js +0 -1
- package/core/route-group/index.cjs +0 -18
- package/core/route-group/index.d.cts +0 -3
- package/core/route-group/index.d.cts.map +0 -1
- package/core/route-group/index.d.ts +0 -3
- package/core/route-group/index.d.ts.map +0 -1
- package/core/route-group/index.js +0 -2
- package/core/route-group/route-group.cjs +0 -67
- package/core/route-group/route-group.d.cts +0 -31
- package/core/route-group/route-group.d.cts.map +0 -1
- package/core/route-group/route-group.d.ts +0 -31
- package/core/route-group/route-group.d.ts.map +0 -1
- package/core/route-group/route-group.js +0 -62
- package/core/route-group/route-group.types.cjs +0 -2
- package/core/route-group/route-group.types.d.cts +0 -15
- package/core/route-group/route-group.types.d.cts.map +0 -1
- package/core/route-group/route-group.types.d.ts +0 -15
- package/core/route-group/route-group.types.d.ts.map +0 -1
- package/core/route-group/route-group.types.js +0 -1
- package/core/router/index.cjs +0 -18
- package/core/router/index.d.cts +0 -3
- package/core/router/index.d.cts.map +0 -1
- package/core/router/index.d.ts +0 -3
- package/core/router/index.d.ts.map +0 -1
- package/core/router/index.js +0 -2
- package/core/router/router.cjs +0 -42
- package/core/router/router.d.cts +0 -18
- package/core/router/router.d.cts.map +0 -1
- package/core/router/router.d.ts +0 -18
- package/core/router/router.d.ts.map +0 -1
- package/core/router/router.js +0 -37
- package/core/router/router.types.cjs +0 -2
- package/core/router/router.types.d.cts +0 -13
- package/core/router/router.types.d.cts.map +0 -1
- package/core/router/router.types.d.ts +0 -13
- package/core/router/router.types.d.ts.map +0 -1
- package/core/router/router.types.js +0 -1
- package/core/utils/is-route-entity.cjs +0 -5
- package/core/utils/is-route-entity.d.cts +0 -3
- package/core/utils/is-route-entity.d.cts.map +0 -1
- package/core/utils/is-route-entity.d.ts +0 -3
- package/core/utils/is-route-entity.d.ts.map +0 -1
- package/core/utils/is-route-entity.js +0 -1
- package/core/virtual-route/index.cjs +0 -18
- package/core/virtual-route/index.d.cts +0 -3
- package/core/virtual-route/index.d.cts.map +0 -1
- package/core/virtual-route/index.d.ts +0 -3
- package/core/virtual-route/index.d.ts.map +0 -1
- package/core/virtual-route/index.js +0 -2
- package/core/virtual-route/virtual-route.cjs +0 -133
- package/core/virtual-route/virtual-route.d.cts +0 -39
- package/core/virtual-route/virtual-route.d.cts.map +0 -1
- package/core/virtual-route/virtual-route.d.ts +0 -39
- package/core/virtual-route/virtual-route.d.ts.map +0 -1
- package/core/virtual-route/virtual-route.js +0 -128
- package/core/virtual-route/virtual-route.types.cjs +0 -2
- package/core/virtual-route/virtual-route.types.d.cts +0 -61
- package/core/virtual-route/virtual-route.types.d.cts.map +0 -1
- package/core/virtual-route/virtual-route.types.d.ts +0 -61
- package/core/virtual-route/virtual-route.types.d.ts.map +0 -1
- package/core/virtual-route/virtual-route.types.js +0 -1
- package/index.d.cts +0 -3
- package/index.d.cts.map +0 -1
- package/index.d.ts.map +0 -1
- package/react/components/index.cjs +0 -21
- package/react/components/index.d.cts +0 -4
- package/react/components/index.d.cts.map +0 -1
- package/react/components/index.d.ts +0 -4
- package/react/components/index.d.ts.map +0 -1
- package/react/components/index.js +0 -5
- package/react/components/link.cjs +0 -79
- package/react/components/link.d.cts +0 -23
- package/react/components/link.d.cts.map +0 -1
- package/react/components/link.d.ts +0 -23
- package/react/components/link.d.ts.map +0 -1
- package/react/components/link.js +0 -76
- package/react/components/route-view-group.cjs +0 -57
- package/react/components/route-view-group.d.cts +0 -26
- package/react/components/route-view-group.d.cts.map +0 -1
- package/react/components/route-view-group.d.ts +0 -26
- package/react/components/route-view-group.d.ts.map +0 -1
- package/react/components/route-view-group.js +0 -54
- package/react/components/route-view.cjs +0 -43
- package/react/components/route-view.d.cts +0 -25
- package/react/components/route-view.d.cts.map +0 -1
- package/react/components/route-view.d.ts +0 -25
- package/react/components/route-view.d.ts.map +0 -1
- package/react/components/route-view.js +0 -40
- package/react/index.cjs +0 -17
- package/react/index.d.cts +0 -2
- package/react/index.d.cts.map +0 -1
- package/react/index.d.ts +0 -2
- package/react/index.d.ts.map +0 -1
- package/react/index.js +0 -1
- package/view-model/index.cjs +0 -17
- package/view-model/index.d.cts +0 -2
- package/view-model/index.d.cts.map +0 -1
- package/view-model/index.d.ts +0 -2
- package/view-model/index.d.ts.map +0 -1
- package/view-model/index.js +0 -1
- package/view-model/route-view-model.cjs +0 -37
- package/view-model/route-view-model.d.cts +0 -13
- package/view-model/route-view-model.d.cts.map +0 -1
- package/view-model/route-view-model.d.ts +0 -13
- package/view-model/route-view-model.d.ts.map +0 -1
- package/view-model/route-view-model.js +0 -33
package/core/route/route.d.cts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { type History, type IQueryParams } from 'mobx-location-history';
|
|
2
|
-
import { type ParamData, type TokenData } from 'path-to-regexp';
|
|
3
|
-
import type { AnyObject, IsPartial, Maybe, MaybePromise } from 'yummies/types';
|
|
4
|
-
import type { AnyRoute, BeforeOpenFeedback, CreatedUrlOutputParams, InputPathParams, IRoute, ParsedPathData, ParsedPathParams, PreparedNavigationData, RouteConfiguration, RouteNavigateParams } from "./route.types.cjs";
|
|
5
|
-
/**
|
|
6
|
-
* Class for creating path based route.
|
|
7
|
-
*
|
|
8
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html)
|
|
9
|
-
*/
|
|
10
|
-
export declare class Route<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<any, any, any, any> | null = null> implements IRoute<TPath, TInputParams, TOutputParams> {
|
|
11
|
-
path: TPath;
|
|
12
|
-
protected config: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>;
|
|
13
|
-
protected abortController: AbortController;
|
|
14
|
-
protected history: History;
|
|
15
|
-
parent: TParentRoute;
|
|
16
|
-
query: IQueryParams;
|
|
17
|
-
private _tokenData;
|
|
18
|
-
private _matcher?;
|
|
19
|
-
private _compiler?;
|
|
20
|
-
private reactionDisposer;
|
|
21
|
-
meta?: AnyObject;
|
|
22
|
-
/**
|
|
23
|
-
* Indicates if this route is an index route. Index routes activate when parent route path matches exactly.
|
|
24
|
-
*
|
|
25
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isindex-boolean)
|
|
26
|
-
*/
|
|
27
|
-
isIndex: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Indicates if this route is an hash route.
|
|
30
|
-
*
|
|
31
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#ishash-boolean)
|
|
32
|
-
*/
|
|
33
|
-
isHash: boolean;
|
|
34
|
-
children: AnyRoute[];
|
|
35
|
-
constructor(path: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>);
|
|
36
|
-
protected get baseUrl(): string | undefined;
|
|
37
|
-
protected get parsedPathData(): ParsedPathData<TPath> | null;
|
|
38
|
-
/**
|
|
39
|
-
* Matched path segment for current URL.
|
|
40
|
-
*
|
|
41
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#currentpath-parsedpathname-null)
|
|
42
|
-
*/
|
|
43
|
-
get currentPath(): string | null;
|
|
44
|
-
/**
|
|
45
|
-
* Current parsed path parameters.
|
|
46
|
-
*
|
|
47
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params-parsedpathparams-null)
|
|
48
|
-
*/
|
|
49
|
-
get params(): TOutputParams | null;
|
|
50
|
-
/**
|
|
51
|
-
* Defines the "open" state for this route.
|
|
52
|
-
*
|
|
53
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopened-boolean)
|
|
54
|
-
*/
|
|
55
|
-
get isOpened(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Allows to create child route based on this route with merging this route path and extending path.
|
|
58
|
-
*
|
|
59
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend-path-config-route)
|
|
60
|
-
*/
|
|
61
|
-
extend<TExtendedPath extends string, TExtendedInputParams extends InputPathParams<`${TPath}${TExtendedPath}`> = InputPathParams<`${TPath}${TExtendedPath}`>, TExtendedOutputParams extends AnyObject = TInputParams & ParsedPathParams<`${TPath}${TExtendedPath}`>>(path: TExtendedPath, config?: Omit<RouteConfiguration<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, any>, 'parent'>): Route<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, this>;
|
|
62
|
-
addChildren(...routes: AnyRoute[]): void;
|
|
63
|
-
removeChildren(...routes: AnyRoute[]): void;
|
|
64
|
-
/**
|
|
65
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren-boolean)
|
|
66
|
-
*/
|
|
67
|
-
get hasOpenedChildren(): boolean;
|
|
68
|
-
protected processParams(params?: TInputParams | null | undefined): ParamData | undefined;
|
|
69
|
-
createUrl(...args: IsPartial<TInputParams> extends true ? [
|
|
70
|
-
params?: Maybe<TInputParams>,
|
|
71
|
-
query?: Maybe<AnyObject>,
|
|
72
|
-
mergeQueryOrParams?: boolean | CreatedUrlOutputParams
|
|
73
|
-
] : [
|
|
74
|
-
params: TInputParams,
|
|
75
|
-
query?: Maybe<AnyObject>,
|
|
76
|
-
mergeQueryOrParams?: boolean | CreatedUrlOutputParams
|
|
77
|
-
]): string;
|
|
78
|
-
/**
|
|
79
|
-
* Navigates to this route.
|
|
80
|
-
*
|
|
81
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open-args)
|
|
82
|
-
*/
|
|
83
|
-
open(...args: IsPartial<TInputParams> extends true ? [
|
|
84
|
-
params?: TInputParams | null | undefined,
|
|
85
|
-
navigateParams?: RouteNavigateParams
|
|
86
|
-
] : [params: TInputParams, navigateParams?: RouteNavigateParams]): Promise<void>;
|
|
87
|
-
open(...args: IsPartial<TInputParams> extends true ? [
|
|
88
|
-
params?: TInputParams | null | undefined,
|
|
89
|
-
replace?: RouteNavigateParams['replace'],
|
|
90
|
-
query?: RouteNavigateParams['query']
|
|
91
|
-
] : [
|
|
92
|
-
params: TInputParams,
|
|
93
|
-
replace?: RouteNavigateParams['replace'],
|
|
94
|
-
query?: RouteNavigateParams['query']
|
|
95
|
-
]): Promise<void>;
|
|
96
|
-
open(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
|
|
97
|
-
open(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
|
|
98
|
-
protected beforeOpen(openData: PreparedNavigationData<TInputParams>): MaybePromise<BeforeOpenFeedback>;
|
|
99
|
-
protected afterClose(): true | void;
|
|
100
|
-
protected get tokenData(): TokenData;
|
|
101
|
-
private firstOpenedStateCheck;
|
|
102
|
-
private processOpenedState;
|
|
103
|
-
private get isAbleToMergeQuery();
|
|
104
|
-
destroy(): void;
|
|
105
|
-
}
|
|
106
|
-
export declare const createRoute: <TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<any, any, any, any> | null = null>(path: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>) => Route<TPath, TInputParams, TOutputParams, TParentRoute>;
|
|
107
|
-
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/core/route/route.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI/E,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,sBAAsB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GR;AAED,eAAO,MAAM,WAAW,GACtB,KAAK,SAAS,MAAM,EACpB,YAAY,SAAS,eAAe,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,EACpE,aAAa,SAAS,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,EACzD,YAAY,SAAS,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,EAE5D,MAAM,KAAK,EACX,SAAS,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,CAAC,4DACD,CAAC"}
|
package/core/route/route.d.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { type History, type IQueryParams } from 'mobx-location-history';
|
|
2
|
-
import { type ParamData, type TokenData } from 'path-to-regexp';
|
|
3
|
-
import type { AnyObject, IsPartial, Maybe, MaybePromise } from 'yummies/types';
|
|
4
|
-
import type { AnyRoute, BeforeOpenFeedback, CreatedUrlOutputParams, InputPathParams, IRoute, ParsedPathData, ParsedPathParams, PreparedNavigationData, RouteConfiguration, RouteNavigateParams } from "./route.types.js";
|
|
5
|
-
/**
|
|
6
|
-
* Class for creating path based route.
|
|
7
|
-
*
|
|
8
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html)
|
|
9
|
-
*/
|
|
10
|
-
export declare class Route<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<any, any, any, any> | null = null> implements IRoute<TPath, TInputParams, TOutputParams> {
|
|
11
|
-
path: TPath;
|
|
12
|
-
protected config: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>;
|
|
13
|
-
protected abortController: AbortController;
|
|
14
|
-
protected history: History;
|
|
15
|
-
parent: TParentRoute;
|
|
16
|
-
query: IQueryParams;
|
|
17
|
-
private _tokenData;
|
|
18
|
-
private _matcher?;
|
|
19
|
-
private _compiler?;
|
|
20
|
-
private reactionDisposer;
|
|
21
|
-
meta?: AnyObject;
|
|
22
|
-
/**
|
|
23
|
-
* Indicates if this route is an index route. Index routes activate when parent route path matches exactly.
|
|
24
|
-
*
|
|
25
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isindex-boolean)
|
|
26
|
-
*/
|
|
27
|
-
isIndex: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Indicates if this route is an hash route.
|
|
30
|
-
*
|
|
31
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#ishash-boolean)
|
|
32
|
-
*/
|
|
33
|
-
isHash: boolean;
|
|
34
|
-
children: AnyRoute[];
|
|
35
|
-
constructor(path: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>);
|
|
36
|
-
protected get baseUrl(): string | undefined;
|
|
37
|
-
protected get parsedPathData(): ParsedPathData<TPath> | null;
|
|
38
|
-
/**
|
|
39
|
-
* Matched path segment for current URL.
|
|
40
|
-
*
|
|
41
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#currentpath-parsedpathname-null)
|
|
42
|
-
*/
|
|
43
|
-
get currentPath(): string | null;
|
|
44
|
-
/**
|
|
45
|
-
* Current parsed path parameters.
|
|
46
|
-
*
|
|
47
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params-parsedpathparams-null)
|
|
48
|
-
*/
|
|
49
|
-
get params(): TOutputParams | null;
|
|
50
|
-
/**
|
|
51
|
-
* Defines the "open" state for this route.
|
|
52
|
-
*
|
|
53
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopened-boolean)
|
|
54
|
-
*/
|
|
55
|
-
get isOpened(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Allows to create child route based on this route with merging this route path and extending path.
|
|
58
|
-
*
|
|
59
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend-path-config-route)
|
|
60
|
-
*/
|
|
61
|
-
extend<TExtendedPath extends string, TExtendedInputParams extends InputPathParams<`${TPath}${TExtendedPath}`> = InputPathParams<`${TPath}${TExtendedPath}`>, TExtendedOutputParams extends AnyObject = TInputParams & ParsedPathParams<`${TPath}${TExtendedPath}`>>(path: TExtendedPath, config?: Omit<RouteConfiguration<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, any>, 'parent'>): Route<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, this>;
|
|
62
|
-
addChildren(...routes: AnyRoute[]): void;
|
|
63
|
-
removeChildren(...routes: AnyRoute[]): void;
|
|
64
|
-
/**
|
|
65
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren-boolean)
|
|
66
|
-
*/
|
|
67
|
-
get hasOpenedChildren(): boolean;
|
|
68
|
-
protected processParams(params?: TInputParams | null | undefined): ParamData | undefined;
|
|
69
|
-
createUrl(...args: IsPartial<TInputParams> extends true ? [
|
|
70
|
-
params?: Maybe<TInputParams>,
|
|
71
|
-
query?: Maybe<AnyObject>,
|
|
72
|
-
mergeQueryOrParams?: boolean | CreatedUrlOutputParams
|
|
73
|
-
] : [
|
|
74
|
-
params: TInputParams,
|
|
75
|
-
query?: Maybe<AnyObject>,
|
|
76
|
-
mergeQueryOrParams?: boolean | CreatedUrlOutputParams
|
|
77
|
-
]): string;
|
|
78
|
-
/**
|
|
79
|
-
* Navigates to this route.
|
|
80
|
-
*
|
|
81
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open-args)
|
|
82
|
-
*/
|
|
83
|
-
open(...args: IsPartial<TInputParams> extends true ? [
|
|
84
|
-
params?: TInputParams | null | undefined,
|
|
85
|
-
navigateParams?: RouteNavigateParams
|
|
86
|
-
] : [params: TInputParams, navigateParams?: RouteNavigateParams]): Promise<void>;
|
|
87
|
-
open(...args: IsPartial<TInputParams> extends true ? [
|
|
88
|
-
params?: TInputParams | null | undefined,
|
|
89
|
-
replace?: RouteNavigateParams['replace'],
|
|
90
|
-
query?: RouteNavigateParams['query']
|
|
91
|
-
] : [
|
|
92
|
-
params: TInputParams,
|
|
93
|
-
replace?: RouteNavigateParams['replace'],
|
|
94
|
-
query?: RouteNavigateParams['query']
|
|
95
|
-
]): Promise<void>;
|
|
96
|
-
open(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
|
|
97
|
-
open(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
|
|
98
|
-
protected beforeOpen(openData: PreparedNavigationData<TInputParams>): MaybePromise<BeforeOpenFeedback>;
|
|
99
|
-
protected afterClose(): true | void;
|
|
100
|
-
protected get tokenData(): TokenData;
|
|
101
|
-
private firstOpenedStateCheck;
|
|
102
|
-
private processOpenedState;
|
|
103
|
-
private get isAbleToMergeQuery();
|
|
104
|
-
destroy(): void;
|
|
105
|
-
}
|
|
106
|
-
export declare const createRoute: <TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<any, any, any, any> | null = null>(path: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>) => Route<TPath, TInputParams, TOutputParams, TParentRoute>;
|
|
107
|
-
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/core/route/route.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI/E,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,MAAM,EACN,cA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,KAAK,SAAS,MAAM,EACpB,YAAY,SAAS,eAAe,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,EACpE,aAAa,SAAS,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,EACzD,YAAY,SAAS,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,EAE5D,MAAM,KAAK,EACX,SAAS,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,CAAC,4DACD,CAAC"}
|
package/core/route/route.js
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { LinkedAbortController } from 'linked-abort-controller';
|
|
2
|
-
import { action, computed, makeObservable, observable, onBecomeObserved, onBecomeUnobserved, reaction, } from 'mobx';
|
|
3
|
-
import { buildSearchString, } from 'mobx-location-history';
|
|
4
|
-
import { compile, match, parse, } from 'path-to-regexp';
|
|
5
|
-
import { routeConfig } from "../config/index.js";
|
|
6
|
-
/**
|
|
7
|
-
* Class for creating path based route.
|
|
8
|
-
*
|
|
9
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html)
|
|
10
|
-
*/
|
|
11
|
-
export class Route {
|
|
12
|
-
path;
|
|
13
|
-
config;
|
|
14
|
-
abortController;
|
|
15
|
-
history;
|
|
16
|
-
parent;
|
|
17
|
-
query;
|
|
18
|
-
_tokenData;
|
|
19
|
-
_matcher;
|
|
20
|
-
_compiler;
|
|
21
|
-
reactionDisposer;
|
|
22
|
-
meta;
|
|
23
|
-
/**
|
|
24
|
-
* Indicates if this route is an index route. Index routes activate when parent route path matches exactly.
|
|
25
|
-
*
|
|
26
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isindex-boolean)
|
|
27
|
-
*/
|
|
28
|
-
isIndex;
|
|
29
|
-
/**
|
|
30
|
-
* Indicates if this route is an hash route.
|
|
31
|
-
*
|
|
32
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#ishash-boolean)
|
|
33
|
-
*/
|
|
34
|
-
isHash;
|
|
35
|
-
children = [];
|
|
36
|
-
constructor(path, config = {}) {
|
|
37
|
-
this.path = path;
|
|
38
|
-
this.config = config;
|
|
39
|
-
this.abortController = new LinkedAbortController(config.abortSignal);
|
|
40
|
-
this.history = config.history ?? routeConfig.get().history;
|
|
41
|
-
this.query = config.queryParams ?? routeConfig.get().queryParams;
|
|
42
|
-
this.isIndex = !!this.config.index;
|
|
43
|
-
this.isHash = !!this.config.hash;
|
|
44
|
-
this.meta = this.config.meta;
|
|
45
|
-
this.parent = config.parent ?? null;
|
|
46
|
-
computed.struct(this, 'isOpened');
|
|
47
|
-
computed.struct(this, 'data');
|
|
48
|
-
computed.struct(this, 'params');
|
|
49
|
-
computed.struct(this, 'currentPath');
|
|
50
|
-
computed.struct(this, 'hasOpenedChildren');
|
|
51
|
-
computed.struct(this, 'isAbleToMergeQuery');
|
|
52
|
-
computed(this, 'baseUrl');
|
|
53
|
-
observable(this, 'children');
|
|
54
|
-
observable.ref(this, 'parent');
|
|
55
|
-
action(this, 'addChildren');
|
|
56
|
-
action(this, 'removeChildren');
|
|
57
|
-
makeObservable(this);
|
|
58
|
-
onBecomeObserved(this, 'isOpened', () => {
|
|
59
|
-
if (!config.afterOpen && !config.afterClose) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
this.reactionDisposer = reaction(() => this.isOpened, this.processOpenedState, {
|
|
63
|
-
signal: this.abortController.signal,
|
|
64
|
-
fireImmediately: true,
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
onBecomeUnobserved(this, 'isOpened', () => {
|
|
68
|
-
this.reactionDisposer?.();
|
|
69
|
-
this.reactionDisposer = undefined;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
get baseUrl() {
|
|
73
|
-
const baseUrl = this.config.baseUrl ?? routeConfig.get().baseUrl;
|
|
74
|
-
return baseUrl?.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
75
|
-
}
|
|
76
|
-
get parsedPathData() {
|
|
77
|
-
let pathnameToCheck;
|
|
78
|
-
if (this.isHash) {
|
|
79
|
-
pathnameToCheck = this.history.location.hash.slice(1);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
pathnameToCheck = this.history.location.pathname;
|
|
83
|
-
}
|
|
84
|
-
if (this.baseUrl) {
|
|
85
|
-
if (!this.history.location.pathname.startsWith(this.baseUrl)) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
pathnameToCheck = pathnameToCheck.replace(this.baseUrl, '');
|
|
89
|
-
}
|
|
90
|
-
if ((this.path === '' || this.path === '/') &&
|
|
91
|
-
(pathnameToCheck === '/' || pathnameToCheck === '')) {
|
|
92
|
-
return { params: {}, path: pathnameToCheck };
|
|
93
|
-
}
|
|
94
|
-
this._matcher ??= match(this.tokenData);
|
|
95
|
-
const parsed = this._matcher(pathnameToCheck);
|
|
96
|
-
if (parsed === false) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
return parsed;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Matched path segment for current URL.
|
|
103
|
-
*
|
|
104
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#currentpath-parsedpathname-null)
|
|
105
|
-
*/
|
|
106
|
-
get currentPath() {
|
|
107
|
-
return this.parsedPathData?.path ?? null;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Current parsed path parameters.
|
|
111
|
-
*
|
|
112
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params-parsedpathparams-null)
|
|
113
|
-
*/
|
|
114
|
-
get params() {
|
|
115
|
-
if (!this.parsedPathData?.params) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
let params = this.parsedPathData?.params ?? null;
|
|
119
|
-
if (this.config.params) {
|
|
120
|
-
const result = this.config.params(this.parsedPathData.params, this.config.meta);
|
|
121
|
-
if (result) {
|
|
122
|
-
params = result;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return params;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Defines the "open" state for this route.
|
|
132
|
-
*
|
|
133
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopened-boolean)
|
|
134
|
-
*/
|
|
135
|
-
get isOpened() {
|
|
136
|
-
if (this.params === null || this.parsedPathData === null) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
return (!this.config.checkOpened || this.config.checkOpened(this.parsedPathData));
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Allows to create child route based on this route with merging this route path and extending path.
|
|
143
|
-
*
|
|
144
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend-path-config-route)
|
|
145
|
-
*/
|
|
146
|
-
extend(path, config) {
|
|
147
|
-
// biome-ignore lint/correctness/noUnusedVariables: this is need to extract unused fields
|
|
148
|
-
const { index, params, ...configFromCurrentRoute } = this.config;
|
|
149
|
-
const extendedChild = new Route(`${this.path}${path}`, {
|
|
150
|
-
...configFromCurrentRoute,
|
|
151
|
-
...config,
|
|
152
|
-
parent: this,
|
|
153
|
-
});
|
|
154
|
-
this.addChildren(extendedChild);
|
|
155
|
-
return extendedChild;
|
|
156
|
-
}
|
|
157
|
-
addChildren(...routes) {
|
|
158
|
-
this.children.push(...routes);
|
|
159
|
-
}
|
|
160
|
-
removeChildren(...routes) {
|
|
161
|
-
this.children = this.children.filter((child) => !routes.includes(child));
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren-boolean)
|
|
165
|
-
*/
|
|
166
|
-
get hasOpenedChildren() {
|
|
167
|
-
return this.children.some((child) => child.isOpened || child.hasOpenedChildren);
|
|
168
|
-
}
|
|
169
|
-
processParams(params) {
|
|
170
|
-
if (params == null)
|
|
171
|
-
return undefined;
|
|
172
|
-
return Object.entries(params).reduce((acc, [key, value]) => {
|
|
173
|
-
if (value != null) {
|
|
174
|
-
acc[key] = Array.isArray(value) ? value.map(String) : String(value);
|
|
175
|
-
}
|
|
176
|
-
return acc;
|
|
177
|
-
}, {});
|
|
178
|
-
}
|
|
179
|
-
createUrl(...args) {
|
|
180
|
-
const params = args[0];
|
|
181
|
-
const rawQuery = args[1];
|
|
182
|
-
const mergeQueryOrOutputParams = args[2] ?? this.isAbleToMergeQuery;
|
|
183
|
-
const outputParams = typeof mergeQueryOrOutputParams === 'boolean'
|
|
184
|
-
? { mergeQuery: mergeQueryOrOutputParams }
|
|
185
|
-
: mergeQueryOrOutputParams;
|
|
186
|
-
const query = outputParams?.mergeQuery
|
|
187
|
-
? { ...this.query.data, ...rawQuery }
|
|
188
|
-
: (rawQuery ?? {});
|
|
189
|
-
this._compiler ??= compile(this.tokenData);
|
|
190
|
-
const defaultUrlCreateParams = {
|
|
191
|
-
baseUrl: this.baseUrl,
|
|
192
|
-
params: params,
|
|
193
|
-
query,
|
|
194
|
-
};
|
|
195
|
-
const urlCreateParams = this.config.createUrl?.(defaultUrlCreateParams, this.query.data) ??
|
|
196
|
-
routeConfig.get().createUrl?.(defaultUrlCreateParams, this.query.data) ??
|
|
197
|
-
defaultUrlCreateParams;
|
|
198
|
-
const path = this._compiler(this.processParams(urlCreateParams.params));
|
|
199
|
-
const url = [urlCreateParams.baseUrl, this.isHash ? '#' : '', path].join('');
|
|
200
|
-
if (outputParams?.omitQuery) {
|
|
201
|
-
return url;
|
|
202
|
-
}
|
|
203
|
-
return `${url}${buildSearchString(urlCreateParams.query)}`;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Navigates to this route.
|
|
207
|
-
*
|
|
208
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open-args)
|
|
209
|
-
*/
|
|
210
|
-
async open(...args) {
|
|
211
|
-
const { replace, state: rawState, query: rawQuery, mergeQuery: rawMergeQuery, } = typeof args[1] === 'boolean' || args.length > 2
|
|
212
|
-
? { replace: args[1], query: args[2] }
|
|
213
|
-
: (args[1] ?? {});
|
|
214
|
-
let url;
|
|
215
|
-
let params;
|
|
216
|
-
const mergeQuery = rawMergeQuery ?? this.isAbleToMergeQuery;
|
|
217
|
-
const query = mergeQuery ? { ...this.query.data, ...rawQuery } : rawQuery;
|
|
218
|
-
if (typeof args[0] === 'string') {
|
|
219
|
-
url = args[0];
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
params = args[0];
|
|
223
|
-
url = this.createUrl(args[0], query);
|
|
224
|
-
}
|
|
225
|
-
const state = rawState ?? null;
|
|
226
|
-
const navigationData = {
|
|
227
|
-
url,
|
|
228
|
-
params: params,
|
|
229
|
-
replace,
|
|
230
|
-
state,
|
|
231
|
-
query,
|
|
232
|
-
};
|
|
233
|
-
const feedback = await this.beforeOpen(navigationData);
|
|
234
|
-
if (feedback === false) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if (typeof feedback === 'object') {
|
|
238
|
-
Object.assign(navigationData, feedback);
|
|
239
|
-
}
|
|
240
|
-
if (replace) {
|
|
241
|
-
this.history.replace(url, state);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
this.history.push(url, state);
|
|
245
|
-
}
|
|
246
|
-
if (!this.reactionDisposer && this.isOpened) {
|
|
247
|
-
this.config.afterOpen?.(this.parsedPathData, this);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
beforeOpen(openData) {
|
|
251
|
-
if (this.config.beforeOpen) {
|
|
252
|
-
return this.config.beforeOpen(openData);
|
|
253
|
-
}
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
afterClose() {
|
|
257
|
-
if (this.config.afterClose) {
|
|
258
|
-
return this.config.afterClose();
|
|
259
|
-
}
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
get tokenData() {
|
|
263
|
-
if (!this._tokenData) {
|
|
264
|
-
this._tokenData = parse(this.path, this.config.parseOptions);
|
|
265
|
-
}
|
|
266
|
-
return this._tokenData;
|
|
267
|
-
}
|
|
268
|
-
firstOpenedStateCheck = true;
|
|
269
|
-
processOpenedState = (isOpened) => {
|
|
270
|
-
if (this.firstOpenedStateCheck) {
|
|
271
|
-
this.firstOpenedStateCheck = false;
|
|
272
|
-
// ignore first 'afterClose' callback call
|
|
273
|
-
if (!isOpened) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (isOpened) {
|
|
278
|
-
this.config.afterOpen?.(this.parsedPathData, this);
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
this.config.afterClose?.();
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
get isAbleToMergeQuery() {
|
|
285
|
-
return this.config.mergeQuery ?? routeConfig.get().mergeQuery;
|
|
286
|
-
}
|
|
287
|
-
destroy() {
|
|
288
|
-
this.abortController.abort();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
export const createRoute = (path, config) => new Route(path, config);
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type { RawQueryParamsData } from 'mobx-location-history';
|
|
2
|
-
import type { ParseOptions } from 'path-to-regexp';
|
|
3
|
-
import type { AnyObject, IsPartial, Maybe, MaybePromise } from 'yummies/types';
|
|
4
|
-
import type { RouteGlobalConfig } from "../config/index.cjs";
|
|
5
|
-
import type { AnyAbstractRouteEntity } from "../route-group/index.cjs";
|
|
6
|
-
import type { VirtualRoute } from "../virtual-route/index.cjs";
|
|
7
|
-
import type { Route } from "./route.cjs";
|
|
8
|
-
export type PreparedNavigationData<TParams extends AnyObject = AnyObject> = {
|
|
9
|
-
state?: any;
|
|
10
|
-
/**
|
|
11
|
-
* path parameters
|
|
12
|
-
*
|
|
13
|
-
* can be received from extended routes
|
|
14
|
-
*/
|
|
15
|
-
params?: TParams;
|
|
16
|
-
url: string;
|
|
17
|
-
replace?: boolean;
|
|
18
|
-
query?: AnyObject;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Returning `false` means ignore navigation
|
|
22
|
-
*/
|
|
23
|
-
export type BeforeOpenFeedback = void | boolean | {
|
|
24
|
-
url: string;
|
|
25
|
-
state?: any;
|
|
26
|
-
replace?: boolean;
|
|
27
|
-
};
|
|
28
|
-
export interface UrlCreateParams<TInputParams> {
|
|
29
|
-
baseUrl?: string | undefined;
|
|
30
|
-
params: TInputParams;
|
|
31
|
-
query: AnyObject;
|
|
32
|
-
}
|
|
33
|
-
export type UrlCreateParamsFn<TInputParams = any> = (params: UrlCreateParams<TInputParams>, currentQueryData: RawQueryParamsData) => Maybe<UrlCreateParams<TInputParams>>;
|
|
34
|
-
export interface CreatedUrlOutputParams {
|
|
35
|
-
mergeQuery?: boolean;
|
|
36
|
-
omitQuery?: boolean;
|
|
37
|
-
}
|
|
38
|
-
export interface RouteConfiguration<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<string, any, any, any> | null = null> extends Omit<Partial<RouteGlobalConfig>, 'createUrl'> {
|
|
39
|
-
/**
|
|
40
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#abortsignal)
|
|
41
|
-
*/
|
|
42
|
-
abortSignal?: AbortSignal;
|
|
43
|
-
index?: boolean;
|
|
44
|
-
hash?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#meta)
|
|
47
|
-
*/
|
|
48
|
-
meta?: AnyObject;
|
|
49
|
-
parseOptions?: ParseOptions;
|
|
50
|
-
parent?: TParentRoute;
|
|
51
|
-
children?: AnyRoute[];
|
|
52
|
-
/**
|
|
53
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params)
|
|
54
|
-
*/
|
|
55
|
-
params?: (params: ParsedPathParams<TPath>, meta: AnyObject | undefined) => TOutputParams | null | false;
|
|
56
|
-
/**
|
|
57
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#checkopened)
|
|
58
|
-
*/
|
|
59
|
-
checkOpened?: (parsedPathData: ParsedPathData<NoInfer<TPath>>) => boolean;
|
|
60
|
-
/**
|
|
61
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#beforeopen)
|
|
62
|
-
*/
|
|
63
|
-
beforeOpen?: (preparedNavigationData: PreparedNavigationData<NoInfer<TInputParams>>) => MaybePromise<BeforeOpenFeedback>;
|
|
64
|
-
/**
|
|
65
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afterclose)
|
|
66
|
-
*/
|
|
67
|
-
afterClose?: () => void;
|
|
68
|
-
/**
|
|
69
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afteropen)
|
|
70
|
-
*/
|
|
71
|
-
afterOpen?: (data: ParsedPathData<NoInfer<TPath>>, route: Route<NoInfer<TPath>, NoInfer<TInputParams>, NoInfer<TOutputParams>, NoInfer<TParentRoute>>) => void;
|
|
72
|
-
/**
|
|
73
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl)
|
|
74
|
-
*/
|
|
75
|
-
createUrl?: UrlCreateParamsFn<TInputParams>;
|
|
76
|
-
}
|
|
77
|
-
export type AnyRoute = IRoute;
|
|
78
|
-
export interface IRoute<TPath extends string = string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>> {
|
|
79
|
-
isOpened: boolean;
|
|
80
|
-
path: TPath;
|
|
81
|
-
/**
|
|
82
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren-boolean)
|
|
83
|
-
*/
|
|
84
|
-
hasOpenedChildren: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Navigates to this route.
|
|
87
|
-
*
|
|
88
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open-args)
|
|
89
|
-
*/
|
|
90
|
-
open(...args: IsPartial<TInputParams> extends true ? [
|
|
91
|
-
params?: TInputParams | null | undefined,
|
|
92
|
-
navigateParams?: RouteNavigateParams
|
|
93
|
-
] : [params: TInputParams, navigateParams?: RouteNavigateParams]): Promise<void>;
|
|
94
|
-
open(...args: IsPartial<TInputParams> extends true ? [
|
|
95
|
-
params?: TInputParams | null | undefined,
|
|
96
|
-
replace?: RouteNavigateParams['replace'],
|
|
97
|
-
query?: RouteNavigateParams['query']
|
|
98
|
-
] : [
|
|
99
|
-
params: TInputParams,
|
|
100
|
-
replace?: RouteNavigateParams['replace'],
|
|
101
|
-
query?: RouteNavigateParams['query']
|
|
102
|
-
]): Promise<void>;
|
|
103
|
-
open(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
|
|
104
|
-
open(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
|
|
105
|
-
createUrl(...args: IsPartial<TInputParams> extends true ? [params?: Maybe<TInputParams>, query?: AnyObject, mergeQuery?: boolean] : [params: TInputParams, query?: AnyObject, mergeQuery?: boolean]): string;
|
|
106
|
-
destroy(): void;
|
|
107
|
-
readonly params: TOutputParams | null;
|
|
108
|
-
}
|
|
109
|
-
export type InputPathParam = string | number | boolean | null;
|
|
110
|
-
export type ParsedPathParam = string;
|
|
111
|
-
type Simplify<T> = T extends infer U ? {
|
|
112
|
-
[K in keyof U]: U[K];
|
|
113
|
-
} : never;
|
|
114
|
-
export type RouteParams<TRoute extends AnyAbstractRouteEntity> = TRoute extends {
|
|
115
|
-
path: string;
|
|
116
|
-
} ? ParsedPathParams<TRoute['path']> : TRoute extends {
|
|
117
|
-
params: infer TParams;
|
|
118
|
-
} ? Exclude<TParams, null> : AnyObject;
|
|
119
|
-
export type PathToObject<Path extends string, PropertyValue = string> = Simplify<Path extends `${infer Prefix}{${infer Optional}}${infer Suffix}` ? PathToObject<`${Prefix}${Suffix}`, PropertyValue> & Partial<PathToObject<Optional, PropertyValue>> : Path extends `${infer PartA}/${infer PartB}` ? PathToObject<PartA, PropertyValue> & PathToObject<PartB, PropertyValue> : Path extends `:${infer Param}?` ? {
|
|
120
|
-
[K in Param]?: PropertyValue;
|
|
121
|
-
} : Path extends `:${infer Param}` ? {
|
|
122
|
-
[K in Param]: PropertyValue;
|
|
123
|
-
} : Path extends `*${infer Wildcard}` ? {
|
|
124
|
-
[K in Wildcard]: PropertyValue[];
|
|
125
|
-
} : {}>;
|
|
126
|
-
export type ParsedPathParams<Path extends string> = PathToObject<Path, ParsedPathParam>;
|
|
127
|
-
export type InputPathParams<Path extends string> = PathToObject<Path, InputPathParam>;
|
|
128
|
-
export interface RouteNavigateParams {
|
|
129
|
-
replace?: boolean;
|
|
130
|
-
state?: any;
|
|
131
|
-
query?: AnyObject;
|
|
132
|
-
mergeQuery?: boolean;
|
|
133
|
-
}
|
|
134
|
-
export interface ParsedPathData<TPath extends string> {
|
|
135
|
-
path: string;
|
|
136
|
-
params: ParsedPathParams<TPath>;
|
|
137
|
-
}
|
|
138
|
-
export type InferPath<T extends AnyRoute> = T extends IRoute<infer TPath, any, any> ? TPath : never;
|
|
139
|
-
export type InferInputParams<T extends AnyRoute> = T extends VirtualRoute<infer TParams> ? TParams : T extends IRoute<any, infer TInputParams, any> ? TInputParams : never;
|
|
140
|
-
export type InferParams<T extends AnyRoute> = T extends VirtualRoute<infer TParams> ? TParams : T extends IRoute<any, any, infer TParams> ? TParams : never;
|
|
141
|
-
export {};
|
|
142
|
-
//# sourceMappingURL=route.types.d.ts.map
|