mobx-route 0.1.2 → 0.3.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/core/route/route.d.ts +4 -4
- package/core/route/route.d.ts.map +1 -1
- package/core/route/route.types.d.ts +4 -4
- package/core/route/route.types.d.ts.map +1 -1
- package/core/virtual-route/virtual-route.d.ts +2 -2
- package/core/virtual-route/virtual-route.d.ts.map +1 -1
- package/core/virtual-route/virtual-route.types.d.ts +3 -3
- package/core/virtual-route/virtual-route.types.d.ts.map +1 -1
- package/package.json +20 -15
- package/react/components/index.d.ts +2 -1
- package/react/components/index.d.ts.map +1 -1
- package/react/components/index.js +2 -1
- package/react/components/link.d.ts +2 -2
- package/react/components/link.d.ts.map +1 -1
- package/react/components/route-switch.d.ts +25 -0
- package/react/components/route-switch.d.ts.map +1 -0
- package/react/components/route-switch.js +103 -0
- package/react/components/route-switch.test.d.ts +2 -0
- package/react/components/route-switch.test.d.ts.map +1 -0
- package/react/components/route-switch.test.js +146 -0
- package/react/components/route-view-group.d.ts +23 -0
- package/react/components/route-view-group.d.ts.map +1 -0
- package/react/components/route-view-group.js +58 -0
- package/react/components/route-view-group.test.d.ts +2 -0
- package/react/components/route-view-group.test.d.ts.map +1 -0
- package/react/components/route-view-group.test.js +120 -0
- package/react/components/route-view.d.ts +5 -10
- package/react/components/route-view.d.ts.map +1 -1
- package/react/components/route-view.js +3 -3
- package/react/components/route-group-view.d.ts +0 -20
- package/react/components/route-group-view.d.ts.map +0 -1
- package/react/components/route-group-view.js +0 -40
- package/react/components/route-view-map.d.ts +0 -19
- package/react/components/route-view-map.d.ts.map +0 -1
- package/react/components/route-view-map.js +0 -35
- package/react/components/switch.d.ts +0 -22
- package/react/components/switch.d.ts.map +0 -1
- package/react/components/switch.js +0 -50
package/core/route/route.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { History, IQueryParams } from 'mobx-location-history';
|
|
2
2
|
import { ParamData, TokenData } from 'path-to-regexp';
|
|
3
|
-
import {
|
|
3
|
+
import { IsPartial, AnyObject, Maybe, MaybePromise } from 'yummies/utils/types';
|
|
4
4
|
import { AnyRoute, BeforeOpenFeedback, PreparedNavigationData, ExtractPathParams, RouteConfiguration, ParsedPathData, RouteNavigateParams, IRoute } from './route.types.js';
|
|
5
5
|
/**
|
|
6
6
|
* Class for creating path based route.
|
|
@@ -64,17 +64,17 @@ export declare class Route<TPath extends string, TParams extends AnyObject = Ext
|
|
|
64
64
|
*/
|
|
65
65
|
get hasOpenedChildren(): boolean;
|
|
66
66
|
protected processParams(params?: ExtractPathParams<TPath> | null | undefined): ParamData | undefined;
|
|
67
|
-
createUrl(...args:
|
|
67
|
+
createUrl(...args: IsPartial<ExtractPathParams<TPath>> extends true ? [params?: Maybe<ExtractPathParams<TPath>>, query?: AnyObject] : [params: ExtractPathParams<TPath>, query?: AnyObject]): string;
|
|
68
68
|
/**
|
|
69
69
|
* Navigates to this route.
|
|
70
70
|
*
|
|
71
71
|
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open-args)
|
|
72
72
|
*/
|
|
73
|
-
open(...args:
|
|
73
|
+
open(...args: IsPartial<ExtractPathParams<TPath>> extends true ? [
|
|
74
74
|
params?: ExtractPathParams<TPath> | null | undefined,
|
|
75
75
|
navigateParams?: RouteNavigateParams
|
|
76
76
|
] : [params: ExtractPathParams<TPath>, navigateParams?: RouteNavigateParams]): Promise<void>;
|
|
77
|
-
open(...args:
|
|
77
|
+
open(...args: IsPartial<ExtractPathParams<TPath>> extends true ? [
|
|
78
78
|
params?: ExtractPathParams<TPath> | null | undefined,
|
|
79
79
|
replace?: RouteNavigateParams['replace'],
|
|
80
80
|
query?: RouteNavigateParams['query']
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/core/route/route.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,OAAO,EACP,YAAY,EACb,MAAM,uBAAuB,CA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IAED,OAAO;CAGR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParseOptions } from 'path-to-regexp';
|
|
2
|
-
import {
|
|
2
|
+
import { IsPartial, AnyObject, Maybe, MaybePromise } from 'yummies/utils/types';
|
|
3
3
|
import { RouteGlobalConfig } from '../config/config.types.js';
|
|
4
4
|
import { AnyAbstractRouteEntity } from '../route-group/route-group.types.js';
|
|
5
5
|
import { Route } from './route.js';
|
|
@@ -54,11 +54,11 @@ export interface IRoute<TPath extends string = string> {
|
|
|
54
54
|
*
|
|
55
55
|
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open-args)
|
|
56
56
|
*/
|
|
57
|
-
open(...args:
|
|
57
|
+
open(...args: IsPartial<ExtractPathParams<TPath>> extends true ? [
|
|
58
58
|
params?: ExtractPathParams<TPath> | null | undefined,
|
|
59
59
|
navigateParams?: RouteNavigateParams
|
|
60
60
|
] : [params: ExtractPathParams<TPath>, navigateParams?: RouteNavigateParams]): Promise<void>;
|
|
61
|
-
open(...args:
|
|
61
|
+
open(...args: IsPartial<ExtractPathParams<TPath>> extends true ? [
|
|
62
62
|
params?: ExtractPathParams<TPath> | null | undefined,
|
|
63
63
|
replace?: RouteNavigateParams['replace'],
|
|
64
64
|
query?: RouteNavigateParams['query']
|
|
@@ -69,7 +69,7 @@ export interface IRoute<TPath extends string = string> {
|
|
|
69
69
|
]): Promise<void>;
|
|
70
70
|
open(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
|
|
71
71
|
open(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
|
|
72
|
-
createUrl(...args:
|
|
72
|
+
createUrl(...args: IsPartial<ExtractPathParams<TPath>> extends true ? [params?: Maybe<ExtractPathParams<TPath>>, query?: AnyObject] : [params: ExtractPathParams<TPath>, query?: AnyObject]): string;
|
|
73
73
|
destroy(): void;
|
|
74
74
|
params: any;
|
|
75
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.types.d.ts","sourceRoot":"","sources":["../../../src/core/route/route.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"route.types.d.ts","sourceRoot":"","sources":["../../../src/core/route/route.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,sBAAsB,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,IAAI;IAC1E,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,GAAG,EAAE,MAAM,CAAC;IAEZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,IAAI,GACJ,OAAO,GACP;IACE,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEN,MAAM,WAAW,iBAAiB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IAC9D,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,KAAK,CAAC;CACb;AAED,MAAM,WAAW,kBAAkB,CACjC,KAAK,SAAS,MAAM,EACpB,OAAO,SAAS,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,EACnD,YAAY,SAAS,KAAK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IQueryParams } from 'mobx-location-history';
|
|
2
|
-
import {
|
|
2
|
+
import { IsPartial, AnyObject, EmptyObject, Maybe } from 'yummies/utils/types';
|
|
3
3
|
import { AbstractVirtualRoute, VirtualOpenExtraParams, VirtualRouteConfiguration } from './virtual-route.types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Class for creating routes with custom activation logic
|
|
@@ -25,7 +25,7 @@ export declare class VirtualRoute<TParams extends AnyObject | EmptyObject = Empt
|
|
|
25
25
|
/**
|
|
26
26
|
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#open-params-extraparams-query-replace-promise-void)
|
|
27
27
|
*/
|
|
28
|
-
open(...args:
|
|
28
|
+
open(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>, extraParams?: VirtualOpenExtraParams] : [params: TParams, extraParams?: VirtualOpenExtraParams]): Promise<void>;
|
|
29
29
|
/**
|
|
30
30
|
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#close-void)
|
|
31
31
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-route.d.ts","sourceRoot":"","sources":["../../../src/core/virtual-route/virtual-route.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,
|
|
1
|
+
{"version":3,"file":"virtual-route.d.ts","sourceRoot":"","sources":["../../../src/core/virtual-route/virtual-route.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI/E,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAElC;;;;GAIG;AACH,qBAAa,YAAY,CAAC,OAAO,SAAS,SAAS,GAAG,WAAW,GAAG,WAAW,CAC7E,YAAW,oBAAoB,CAAC,OAAO,CAAC;IAU5B,SAAS,CAAC,MAAM,EAAE,yBAAyB,CAAC,OAAO,CAAC;IARhE,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAC3C,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvB,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,WAAW,CAA2D;gBAExD,MAAM,GAAE,yBAAyB,CAAC,OAAO,CAAM;IA2CrE;;OAEG;IACH,IAAI,QAAQ,YAGX;IAED;;OAEG;IACH,cAAc,CACZ,WAAW,EAAE,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC;IAKvE;;OAEG;IACH,IAAI,CACF,GAAG,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS,IAAI,GACpC,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,sBAAsB,CAAC,GAC/D,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,sBAAsB,CAAC,GAC1D,OAAO,CAAC,IAAI,CAAC;IAiChB;;OAEG;IACH,KAAK;IAcL,OAAO;CAGR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IQueryParams } from 'mobx-location-history';
|
|
2
|
-
import {
|
|
2
|
+
import { IsPartial, AnyObject, EmptyObject, Maybe, MaybeFn, MaybePromise } from 'yummies/utils/types';
|
|
3
3
|
import type { VirtualRoute } from './virtual-route.js';
|
|
4
4
|
export type AnyVirtualRoute = VirtualRoute<any>;
|
|
5
5
|
export interface VirtualOpenExtraParams {
|
|
@@ -14,10 +14,10 @@ export interface VirtualRouteConfiguration<TParams extends AnyObject | EmptyObje
|
|
|
14
14
|
abortSignal?: AbortSignal;
|
|
15
15
|
queryParams?: IQueryParams;
|
|
16
16
|
initialParams?: MaybeFn<Maybe<TParams>, [route: VirtualRoute<TParams>]>;
|
|
17
|
-
open?: (...args:
|
|
17
|
+
open?: (...args: IsPartial<TParams> extends true ? [params: Maybe<TParams>, route: VirtualRoute<TParams>] : [params: TParams, route: VirtualRoute<TParams>]) => MaybePromise<boolean | void>;
|
|
18
18
|
close?: (route: VirtualRoute<TParams>) => boolean | void;
|
|
19
19
|
checkOpened?: (route: VirtualRoute<TParams>) => boolean;
|
|
20
|
-
beforeOpen?: (...args:
|
|
20
|
+
beforeOpen?: (...args: IsPartial<TParams> extends true ? [params: Maybe<TParams>, route: VirtualRoute<TParams>] : [params: TParams, route: VirtualRoute<TParams>]) => MaybePromise<void | boolean>;
|
|
21
21
|
afterClose?: () => void;
|
|
22
22
|
afterOpen?: (params: NoInfer<TParams>, route: VirtualRoute<NoInfer<TParams>>) => void;
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-route.types.d.ts","sourceRoot":"","sources":["../../../src/core/virtual-route/virtual-route.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"virtual-route.types.d.ts","sourceRoot":"","sources":["../../../src/core/virtual-route/virtual-route.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,KAAK,EACL,OAAO,EACP,YAAY,EACb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB,CACnC,OAAO,SAAS,SAAS,GAAG,WAAW,GAAG,WAAW;IAErD,Q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AAC,OAAO,CAAC,EACxB,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAClC,IAAI,CAAC;CACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-route",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"mobx",
|
|
6
6
|
"react",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"mobx-location-history": "^7.1.1",
|
|
27
27
|
"path-to-regexp": "^8.2.0",
|
|
28
28
|
"react-simple-loadable": "^2.3.8",
|
|
29
|
-
"yummies": "^4.
|
|
29
|
+
"yummies": "^4.5.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"mobx": "^6.12.4",
|
|
@@ -144,26 +144,31 @@
|
|
|
144
144
|
"default": "./react/components/link.js",
|
|
145
145
|
"types": "./react/components/link.d.ts"
|
|
146
146
|
},
|
|
147
|
-
"./react/components/route-
|
|
148
|
-
"import": "./react/components/route-
|
|
149
|
-
"default": "./react/components/route-
|
|
150
|
-
"types": "./react/components/route-
|
|
147
|
+
"./react/components/route-switch.test": {
|
|
148
|
+
"import": "./react/components/route-switch.test.js",
|
|
149
|
+
"default": "./react/components/route-switch.test.js",
|
|
150
|
+
"types": "./react/components/route-switch.test.d.ts"
|
|
151
151
|
},
|
|
152
|
-
"./react/components/route-
|
|
153
|
-
"import": "./react/components/route-
|
|
154
|
-
"default": "./react/components/route-
|
|
155
|
-
"types": "./react/components/route-
|
|
152
|
+
"./react/components/route-switch": {
|
|
153
|
+
"import": "./react/components/route-switch.js",
|
|
154
|
+
"default": "./react/components/route-switch.js",
|
|
155
|
+
"types": "./react/components/route-switch.d.ts"
|
|
156
|
+
},
|
|
157
|
+
"./react/components/route-view-group.test": {
|
|
158
|
+
"import": "./react/components/route-view-group.test.js",
|
|
159
|
+
"default": "./react/components/route-view-group.test.js",
|
|
160
|
+
"types": "./react/components/route-view-group.test.d.ts"
|
|
161
|
+
},
|
|
162
|
+
"./react/components/route-view-group": {
|
|
163
|
+
"import": "./react/components/route-view-group.js",
|
|
164
|
+
"default": "./react/components/route-view-group.js",
|
|
165
|
+
"types": "./react/components/route-view-group.d.ts"
|
|
156
166
|
},
|
|
157
167
|
"./react/components/route-view": {
|
|
158
168
|
"import": "./react/components/route-view.js",
|
|
159
169
|
"default": "./react/components/route-view.js",
|
|
160
170
|
"types": "./react/components/route-view.d.ts"
|
|
161
171
|
},
|
|
162
|
-
"./react/components/switch": {
|
|
163
|
-
"import": "./react/components/switch.js",
|
|
164
|
-
"default": "./react/components/switch.js",
|
|
165
|
-
"types": "./react/components/switch.d.ts"
|
|
166
|
-
},
|
|
167
172
|
"./react": {
|
|
168
173
|
"import": "./react/index.js",
|
|
169
174
|
"default": "./react/index.js",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AnchorHTMLAttributes, ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { IsPartial } from 'yummies/utils/types';
|
|
3
3
|
import { AnyRoute, ExtractPathParams, RouteNavigateParams } from '../../core/index.js';
|
|
4
4
|
interface LinkAnchorProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
|
5
5
|
asChild?: boolean;
|
|
6
6
|
}
|
|
7
7
|
type LinkPathRouteProps<TRoute extends AnyRoute> = {
|
|
8
8
|
to: TRoute;
|
|
9
|
-
} & (
|
|
9
|
+
} & (IsPartial<ExtractPathParams<TRoute['path']>> extends true ? {
|
|
10
10
|
params?: ExtractPathParams<TRoute['path']> | null | undefined;
|
|
11
11
|
} : {
|
|
12
12
|
params: ExtractPathParams<TRoute['path']>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/react/components/link.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,oBAAoB,EAKpB,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/react/components/link.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,oBAAoB,EAKpB,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,SAAS,EAAa,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EACL,QAAQ,EACR,iBAAiB,EAEjB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAE7B,UAAU,eACR,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,kBAAkB,CAAC,MAAM,SAAS,QAAQ,IAAI;IACjD,EAAE,EAAE,MAAM,CAAC;CACZ,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,GAC1D;IAEE,MAAM,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC/D,GACD;IAAE,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC,CAAC;AAEnD,KAAK,oBAAoB,GACrB;IACE,EAAE,EAAE,MAAM,CAAC;CACZ,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,QAAQ,IAAI,eAAe,GAC9D,mBAAmB,GACnB,CAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC;AAEtD,KAAK,iBAAiB,GAAG,CAAC,MAAM,SAAS,QAAQ,EAC/C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KACrB,SAAS,CAAC;AAEf,eAAO,MAAM,IAAI,EAkED,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { IsPartial, Maybe } from 'yummies/utils/types';
|
|
3
|
+
import { AnyRouteEntity, RouteNavigateParams, RouteParams } from '../../core/index.js';
|
|
4
|
+
interface BaseProps extends RouteNavigateParams {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
type PropsWithDefaultRoute<TRoute extends AnyRouteEntity> = BaseProps & {
|
|
8
|
+
default?: TRoute;
|
|
9
|
+
} & (IsPartial<RouteParams<TRoute>> extends true ? {
|
|
10
|
+
params?: Maybe<RouteParams<TRoute>>;
|
|
11
|
+
} : {
|
|
12
|
+
params: RouteParams<TRoute>;
|
|
13
|
+
});
|
|
14
|
+
type PropsWithDefaultUrl = BaseProps & {
|
|
15
|
+
default?: string;
|
|
16
|
+
};
|
|
17
|
+
export type SwitchProps<TRoute extends AnyRouteEntity> = PropsWithDefaultRoute<TRoute> | PropsWithDefaultUrl;
|
|
18
|
+
/**
|
|
19
|
+
* WIP
|
|
20
|
+
*/
|
|
21
|
+
export declare const Switch: (<TRoute extends AnyRouteEntity>({ children, default: defaultNavigation, params, ...navigateParams }: SwitchProps<TRoute>) => string | number | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null) & {
|
|
22
|
+
displayName: string;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=route-switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-switch.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-switch.tsx"],"names":[],"mappings":"AAKA,OAAO,EAA4B,SAAS,EAAa,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EACL,cAAc,EAEd,mBAAmB,EACnB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAG7B,UAAU,SAAU,SAAQ,mBAAmB;IAC7C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,KAAK,qBAAqB,CAAC,MAAM,SAAS,cAAc,IAAI,SAAS,GAAG;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,IAAI,GAC1C;IACE,MAAM,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACrC,GACD;IACE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC,CAAC;AAET,KAAK,mBAAmB,GAAG,SAAS,GAAG;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,cAAc,IACjD,qBAAqB,CAAC,MAAM,CAAC,GAC7B,mBAAmB,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,MAAM,IAAsB,MAAM,SAAS,cAAc,uEAMnE,WAAW,CAAC,MAAM,CAAC;;CAsGpB,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* eslint-disable sonarjs/no-nested-conditional */
|
|
2
|
+
/* eslint-disable unicorn/no-nested-ternary */
|
|
3
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
4
|
+
import { buildSearchString } from 'mobx-location-history';
|
|
5
|
+
import { observer } from 'mobx-react-lite';
|
|
6
|
+
import { Fragment, isValidElement, useEffect } from 'react';
|
|
7
|
+
import { routeConfig, } from '../../core/index.js';
|
|
8
|
+
import { isRouteEntity } from '../../core/utils/is-route-entity.js';
|
|
9
|
+
/**
|
|
10
|
+
* WIP
|
|
11
|
+
*/
|
|
12
|
+
export const Switch = observer(function ({ children, default: defaultNavigation,
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
params, ...navigateParams }) {
|
|
15
|
+
let activeElement = null;
|
|
16
|
+
let lastInactiveElement = null;
|
|
17
|
+
let foundActive = false;
|
|
18
|
+
const stack = Array.isArray(children)
|
|
19
|
+
? [...children].reverse()
|
|
20
|
+
: children
|
|
21
|
+
? [children]
|
|
22
|
+
: [];
|
|
23
|
+
while (stack.length > 0) {
|
|
24
|
+
const node = stack.pop();
|
|
25
|
+
if (node == null || typeof node === 'boolean') {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(node)) {
|
|
29
|
+
for (let i = node.length - 1; i >= 0; i--) {
|
|
30
|
+
stack.push(node[i]);
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (isValidElement(node) && node.type === Fragment) {
|
|
35
|
+
const fragmentChildren = node.props.children;
|
|
36
|
+
if (fragmentChildren) {
|
|
37
|
+
if (Array.isArray(fragmentChildren)) {
|
|
38
|
+
for (let i = fragmentChildren.length - 1; i >= 0; i--) {
|
|
39
|
+
stack.push(fragmentChildren[i]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
stack.push(fragmentChildren);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
let isActive = false;
|
|
49
|
+
const checkStack = [node];
|
|
50
|
+
while (checkStack.length > 0) {
|
|
51
|
+
const checkNode = checkStack.pop();
|
|
52
|
+
if (checkNode == null || typeof checkNode === 'boolean') {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(checkNode)) {
|
|
56
|
+
for (const element of checkNode) {
|
|
57
|
+
checkStack.push(element);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (isValidElement(checkNode)) {
|
|
61
|
+
if (isRouteEntity(checkNode.props?.route) &&
|
|
62
|
+
checkNode.props.route.isOpened) {
|
|
63
|
+
isActive = true;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (checkNode.props.children) {
|
|
67
|
+
checkStack.push(checkNode.props.children);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (isActive) {
|
|
72
|
+
activeElement = node;
|
|
73
|
+
foundActive = true;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
lastInactiveElement = node;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!foundActive && defaultNavigation) {
|
|
81
|
+
if (typeof defaultNavigation === 'string') {
|
|
82
|
+
const history = routeConfig.get().history;
|
|
83
|
+
const url = `${defaultNavigation}${buildSearchString(navigateParams.query || {})}`;
|
|
84
|
+
if (navigateParams.replace) {
|
|
85
|
+
history.replace(url, navigateParams.state);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
history.push(url, navigateParams.state);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (!defaultNavigation.isOpened) {
|
|
92
|
+
defaultNavigation.open(params, navigateParams);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, [foundActive, defaultNavigation]);
|
|
96
|
+
if (foundActive) {
|
|
97
|
+
return activeElement;
|
|
98
|
+
}
|
|
99
|
+
if (defaultNavigation) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return lastInactiveElement ?? null;
|
|
103
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-switch.test.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-switch.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { act, render } from '@testing-library/react';
|
|
3
|
+
import { createBrowserHistory } from 'mobx-location-history';
|
|
4
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { Route, routeConfig } from '../../core/index.js';
|
|
6
|
+
import { mockHistory } from '../../core/route/route.test.js';
|
|
7
|
+
import { Switch } from './route-switch.js';
|
|
8
|
+
import { RouteView } from './route-view.js';
|
|
9
|
+
describe('<RouteSwitch/>', () => {
|
|
10
|
+
it('Should render nothing when no one route is opened', async () => {
|
|
11
|
+
const history = mockHistory(createBrowserHistory());
|
|
12
|
+
routeConfig.update({
|
|
13
|
+
history,
|
|
14
|
+
});
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
history.clearMocks();
|
|
17
|
+
});
|
|
18
|
+
const route1 = new Route('/test1');
|
|
19
|
+
const route2 = new Route('/test2');
|
|
20
|
+
const route3 = new Route('/test3');
|
|
21
|
+
const App = () => {
|
|
22
|
+
return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) })] }));
|
|
23
|
+
};
|
|
24
|
+
const { container } = await act(async () => render(_jsx(App, {})));
|
|
25
|
+
expect(container.firstChild).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
it('Should render last non active element when no one route is opened', async () => {
|
|
28
|
+
const history = mockHistory(createBrowserHistory());
|
|
29
|
+
routeConfig.update({
|
|
30
|
+
history,
|
|
31
|
+
});
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
history.clearMocks();
|
|
34
|
+
});
|
|
35
|
+
const route1 = new Route('/test1');
|
|
36
|
+
const route2 = new Route('/test2');
|
|
37
|
+
const route3 = new Route('/test3');
|
|
38
|
+
const App1 = () => {
|
|
39
|
+
return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
40
|
+
};
|
|
41
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
42
|
+
expect(screen1.getByText('not_found1')).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
it('Should render active element when 1-order route is opened', async () => {
|
|
45
|
+
const history = mockHistory(createBrowserHistory());
|
|
46
|
+
routeConfig.update({
|
|
47
|
+
history,
|
|
48
|
+
});
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
history.clearMocks();
|
|
51
|
+
});
|
|
52
|
+
const route1 = new Route('/test1');
|
|
53
|
+
const route2 = new Route('/test2');
|
|
54
|
+
const route3 = new Route('/test3');
|
|
55
|
+
const App1 = () => {
|
|
56
|
+
return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
57
|
+
};
|
|
58
|
+
await route1.open();
|
|
59
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
60
|
+
expect(screen1.getByText('route1')).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
it('Should render active element when 2-order route is opened', async () => {
|
|
63
|
+
const history = mockHistory(createBrowserHistory());
|
|
64
|
+
routeConfig.update({
|
|
65
|
+
history,
|
|
66
|
+
});
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
history.clearMocks();
|
|
69
|
+
});
|
|
70
|
+
const route1 = new Route('/test1');
|
|
71
|
+
const route2 = new Route('/test2');
|
|
72
|
+
const route3 = new Route('/test3');
|
|
73
|
+
const App1 = () => {
|
|
74
|
+
return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
75
|
+
};
|
|
76
|
+
await route2.open();
|
|
77
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
78
|
+
expect(screen1.getByText('route2')).toBeDefined();
|
|
79
|
+
});
|
|
80
|
+
it('Should render active element when 3-order route is opened', async () => {
|
|
81
|
+
const history = mockHistory(createBrowserHistory());
|
|
82
|
+
routeConfig.update({
|
|
83
|
+
history,
|
|
84
|
+
});
|
|
85
|
+
beforeEach(() => {
|
|
86
|
+
history.clearMocks();
|
|
87
|
+
});
|
|
88
|
+
const route1 = new Route('/test1');
|
|
89
|
+
const route2 = new Route('/test2');
|
|
90
|
+
const route3 = new Route('/test3');
|
|
91
|
+
const App1 = () => {
|
|
92
|
+
return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
93
|
+
};
|
|
94
|
+
await route3.open();
|
|
95
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
96
|
+
expect(screen1.getByText('route3')).toBeDefined();
|
|
97
|
+
});
|
|
98
|
+
it('Should render element of LAST OPENED route', async () => {
|
|
99
|
+
const history = mockHistory(createBrowserHistory());
|
|
100
|
+
routeConfig.update({
|
|
101
|
+
history,
|
|
102
|
+
});
|
|
103
|
+
beforeEach(() => {
|
|
104
|
+
history.clearMocks();
|
|
105
|
+
});
|
|
106
|
+
const route1 = new Route('/test');
|
|
107
|
+
const route2 = new Route('/test');
|
|
108
|
+
const route3 = new Route('/test');
|
|
109
|
+
const App1 = () => {
|
|
110
|
+
return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
111
|
+
};
|
|
112
|
+
await route3.open();
|
|
113
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
114
|
+
expect(screen1.getByText('route3')).toBeDefined();
|
|
115
|
+
expect(() => screen1.getByText('route2')).toThrowError();
|
|
116
|
+
expect(() => screen1.getByText('route1')).toThrowError();
|
|
117
|
+
expect(() => screen1.getByText('not_found1')).toThrowError();
|
|
118
|
+
});
|
|
119
|
+
it('Should render element with wrapper component if it is opened', async () => {
|
|
120
|
+
const history = mockHistory(createBrowserHistory());
|
|
121
|
+
routeConfig.update({
|
|
122
|
+
history,
|
|
123
|
+
});
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
history.clearMocks();
|
|
126
|
+
});
|
|
127
|
+
const route1 = new Route('/route-1-test');
|
|
128
|
+
const route2 = new Route('/route-2-test');
|
|
129
|
+
const route3 = new Route('/route-3-test');
|
|
130
|
+
const Wrapper = ({ children, text, }) => {
|
|
131
|
+
return (_jsxs("div", { className: "wrapper", children: [_jsx("label", { children: text }), children] }));
|
|
132
|
+
};
|
|
133
|
+
const App1 = () => {
|
|
134
|
+
return (_jsxs(Switch, { children: [_jsx(Wrapper, { text: "wrapper1", children: _jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }) }), _jsx(Wrapper, { text: "wrapper2", children: _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }) }), _jsx(Wrapper, { text: "wrapper3", children: _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }) }), _jsx("div", { children: "not_found1" })] }));
|
|
135
|
+
};
|
|
136
|
+
await route2.open();
|
|
137
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
138
|
+
expect(screen1.getByText('route2')).toBeDefined();
|
|
139
|
+
expect(screen1.getByText('wrapper2')).toBeDefined();
|
|
140
|
+
expect(() => screen1.getByText('route1')).toThrowError();
|
|
141
|
+
expect(() => screen1.getByText('wrapper1')).toThrowError();
|
|
142
|
+
expect(() => screen1.getByText('route3')).toThrowError();
|
|
143
|
+
expect(() => screen1.getByText('wrapper3')).toThrowError();
|
|
144
|
+
expect(() => screen1.getByText('not_found1')).toThrowError();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import { IsPartial, PartialIf } from 'yummies/utils/types';
|
|
3
|
+
import { AnyRouteEntity, RouteNavigateParams, RouteParams } from '../../core/index.js';
|
|
4
|
+
interface BaseProps extends RouteNavigateParams {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
layout?: ComponentType<{
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
type PropsWithDefaultRoute<TRoute extends AnyRouteEntity> = BaseProps & {
|
|
11
|
+
otherwise?: TRoute;
|
|
12
|
+
} & PartialIf<IsPartial<RouteParams<TRoute>>, {
|
|
13
|
+
params: RouteParams<TRoute>;
|
|
14
|
+
}>;
|
|
15
|
+
type PropsWithDefaultUrl = BaseProps & {
|
|
16
|
+
otherwise?: string;
|
|
17
|
+
};
|
|
18
|
+
export type RouteViewGroupProps<TRoute extends AnyRouteEntity> = PropsWithDefaultRoute<TRoute> | PropsWithDefaultUrl;
|
|
19
|
+
export declare const RouteViewGroup: (<TRoute extends AnyRouteEntity>({ children, layout: Layout, otherwise: otherwiseNavigation, params, ...navigateParams }: RouteViewGroupProps<TRoute>) => string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null) & {
|
|
20
|
+
displayName: string;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=route-view-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-view-group.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view-group.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAkB,SAAS,EAAa,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EACL,cAAc,EAEd,mBAAmB,EACnB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAG7B,UAAU,SAAU,SAAQ,mBAAmB;IAC7C,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CAClD;AAED,KAAK,qBAAqB,CAAC,MAAM,SAAS,cAAc,IAAI,SAAS,GAAG;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,SAAS,CACT,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAC9B;IACE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7B,CACF,CAAC;AAEJ,KAAK,mBAAmB,GAAG,SAAS,GAAG;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,cAAc,IACzD,qBAAqB,CAAC,MAAM,CAAC,GAC7B,mBAAmB,CAAC;AAExB,eAAO,MAAM,cAAc,IACzB,MAAM,SAAS,cAAc,2FAQ5B,mBAAmB,CAAC,MAAM,CAAC;;CAuD5B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable sonarjs/no-nested-conditional */
|
|
3
|
+
/* eslint-disable unicorn/no-nested-ternary */
|
|
4
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
5
|
+
import { buildSearchString } from 'mobx-location-history';
|
|
6
|
+
import { observer } from 'mobx-react-lite';
|
|
7
|
+
import { isValidElement, useEffect } from 'react';
|
|
8
|
+
import { routeConfig, } from '../../core/index.js';
|
|
9
|
+
import { isRouteEntity } from '../../core/utils/is-route-entity.js';
|
|
10
|
+
export const RouteViewGroup = observer(function ({ children, layout: Layout, otherwise: otherwiseNavigation,
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
params, ...navigateParams }) {
|
|
13
|
+
let activeChildNode = null;
|
|
14
|
+
let lastInactiveChildNode = null;
|
|
15
|
+
const childNodes = Array.isArray(children)
|
|
16
|
+
? children
|
|
17
|
+
: [children];
|
|
18
|
+
for (const childNode of childNodes) {
|
|
19
|
+
if (isValidElement(childNode) &&
|
|
20
|
+
isRouteEntity(childNode.props?.route) &&
|
|
21
|
+
childNode.props.route.isOpened) {
|
|
22
|
+
activeChildNode = childNode;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
lastInactiveChildNode = childNode;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const hasActiveChildNode = !!activeChildNode;
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!hasActiveChildNode && otherwiseNavigation) {
|
|
32
|
+
if (typeof otherwiseNavigation === 'string') {
|
|
33
|
+
const history = routeConfig.get().history;
|
|
34
|
+
const url = `${otherwiseNavigation}${buildSearchString(navigateParams.query || {})}`;
|
|
35
|
+
if (navigateParams.replace) {
|
|
36
|
+
history.replace(url, navigateParams.state);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
history.push(url, navigateParams.state);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (!otherwiseNavigation.isOpened) {
|
|
43
|
+
otherwiseNavigation.open(params, navigateParams);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, [hasActiveChildNode, otherwiseNavigation]);
|
|
47
|
+
if (hasActiveChildNode) {
|
|
48
|
+
return activeChildNode;
|
|
49
|
+
}
|
|
50
|
+
if (otherwiseNavigation) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const resultNodeToRender = activeChildNode ?? lastInactiveChildNode ?? null;
|
|
54
|
+
if (Layout) {
|
|
55
|
+
return _jsx(Layout, { children: resultNodeToRender });
|
|
56
|
+
}
|
|
57
|
+
return resultNodeToRender;
|
|
58
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-view-group.test.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view-group.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable sonarjs/no-unstable-nested-components */
|
|
3
|
+
import { act, render } from '@testing-library/react';
|
|
4
|
+
import { createBrowserHistory } from 'mobx-location-history';
|
|
5
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
6
|
+
import { Route, routeConfig } from '../../core/index.js';
|
|
7
|
+
import { mockHistory } from '../../core/route/route.test.js';
|
|
8
|
+
import { RouteViewGroup } from './route-view-group.js';
|
|
9
|
+
import { RouteView } from './route-view.js';
|
|
10
|
+
describe('<RouteViewGroup />', () => {
|
|
11
|
+
it('Should render nothing when no one route is opened', async () => {
|
|
12
|
+
const history = mockHistory(createBrowserHistory());
|
|
13
|
+
routeConfig.update({
|
|
14
|
+
history,
|
|
15
|
+
});
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
history.clearMocks();
|
|
18
|
+
});
|
|
19
|
+
const route1 = new Route('/test1');
|
|
20
|
+
const route2 = new Route('/test2');
|
|
21
|
+
const route3 = new Route('/test3');
|
|
22
|
+
const App = () => {
|
|
23
|
+
return (_jsxs(RouteViewGroup, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) })] }));
|
|
24
|
+
};
|
|
25
|
+
const { container } = await act(async () => render(_jsx(App, {})));
|
|
26
|
+
expect(container.firstChild).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
it('Should render last non active element when no one route is opened', async () => {
|
|
29
|
+
const history = mockHistory(createBrowserHistory());
|
|
30
|
+
routeConfig.update({
|
|
31
|
+
history,
|
|
32
|
+
});
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
history.clearMocks();
|
|
35
|
+
});
|
|
36
|
+
const route1 = new Route('/test1');
|
|
37
|
+
const route2 = new Route('/test2');
|
|
38
|
+
const route3 = new Route('/test3');
|
|
39
|
+
const App1 = () => {
|
|
40
|
+
return (_jsxs(RouteViewGroup, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
41
|
+
};
|
|
42
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
43
|
+
expect(screen1.getByText('not_found1')).toBeDefined();
|
|
44
|
+
});
|
|
45
|
+
it('Should render active element when 1-order route is opened', async () => {
|
|
46
|
+
const history = mockHistory(createBrowserHistory());
|
|
47
|
+
routeConfig.update({
|
|
48
|
+
history,
|
|
49
|
+
});
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
history.clearMocks();
|
|
52
|
+
});
|
|
53
|
+
const route1 = new Route('/test1');
|
|
54
|
+
const route2 = new Route('/test2');
|
|
55
|
+
const route3 = new Route('/test3');
|
|
56
|
+
const App1 = () => {
|
|
57
|
+
return (_jsxs(RouteViewGroup, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
58
|
+
};
|
|
59
|
+
await route1.open();
|
|
60
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
61
|
+
expect(screen1.getByText('route1')).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
it('Should render active element when 2-order route is opened', async () => {
|
|
64
|
+
const history = mockHistory(createBrowserHistory());
|
|
65
|
+
routeConfig.update({
|
|
66
|
+
history,
|
|
67
|
+
});
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
history.clearMocks();
|
|
70
|
+
});
|
|
71
|
+
const route1 = new Route('/test1');
|
|
72
|
+
const route2 = new Route('/test2');
|
|
73
|
+
const route3 = new Route('/test3');
|
|
74
|
+
const App1 = () => {
|
|
75
|
+
return (_jsxs(RouteViewGroup, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
76
|
+
};
|
|
77
|
+
await route2.open();
|
|
78
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
79
|
+
expect(screen1.getByText('route2')).toBeDefined();
|
|
80
|
+
});
|
|
81
|
+
it('Should render active element when 3-order route is opened', async () => {
|
|
82
|
+
const history = mockHistory(createBrowserHistory());
|
|
83
|
+
routeConfig.update({
|
|
84
|
+
history,
|
|
85
|
+
});
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
history.clearMocks();
|
|
88
|
+
});
|
|
89
|
+
const route1 = new Route('/test1');
|
|
90
|
+
const route2 = new Route('/test2');
|
|
91
|
+
const route3 = new Route('/test3');
|
|
92
|
+
const App1 = () => {
|
|
93
|
+
return (_jsxs(RouteViewGroup, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
94
|
+
};
|
|
95
|
+
await route3.open();
|
|
96
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
97
|
+
expect(screen1.getByText('route3')).toBeDefined();
|
|
98
|
+
});
|
|
99
|
+
it('Should render element of LAST OPENED route', async () => {
|
|
100
|
+
const history = mockHistory(createBrowserHistory());
|
|
101
|
+
routeConfig.update({
|
|
102
|
+
history,
|
|
103
|
+
});
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
history.clearMocks();
|
|
106
|
+
});
|
|
107
|
+
const route1 = new Route('/test');
|
|
108
|
+
const route2 = new Route('/test');
|
|
109
|
+
const route3 = new Route('/test');
|
|
110
|
+
const App1 = () => {
|
|
111
|
+
return (_jsxs(RouteViewGroup, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
|
|
112
|
+
};
|
|
113
|
+
await route3.open();
|
|
114
|
+
const screen1 = await act(async () => render(_jsx(App1, {})));
|
|
115
|
+
expect(screen1.getByText('route1')).toBeDefined();
|
|
116
|
+
expect(() => screen1.getByText('route2')).toThrowError();
|
|
117
|
+
expect(() => screen1.getByText('route3')).toThrowError();
|
|
118
|
+
expect(() => screen1.getByText('not_found1')).toThrowError();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -2,22 +2,17 @@ import { ComponentType, ReactNode } from 'react';
|
|
|
2
2
|
import { LoadableConfig } from 'react-simple-loadable';
|
|
3
3
|
import { AnyAbstractRouteEntity, type AnyRoute, type AnyVirtualRoute } from '../../core/index.js';
|
|
4
4
|
export type RouteViewComponent<TRoute extends AnyAbstractRouteEntity> = ComponentType<RouteViewProps<TRoute>>;
|
|
5
|
-
export interface RouteViewConfigProps<TRoute extends AnyAbstractRouteEntity> {
|
|
6
|
-
route: TRoute;
|
|
7
|
-
view?: RouteViewComponent<TRoute>;
|
|
8
|
-
lazyView?: (route: TRoute) => Promise<ComponentType<RouteViewProps<TRoute>>>;
|
|
9
|
-
loader?: ComponentType;
|
|
10
|
-
fallbackView?: ReactNode;
|
|
11
|
-
children?: ReactNode | ((params: RouteViewProps<TRoute>['params'], route: TRoute) => ReactNode);
|
|
12
|
-
}
|
|
13
5
|
interface RouteViewConfigWithoutRoute {
|
|
14
6
|
children?: ReactNode | (() => ReactNode);
|
|
15
7
|
}
|
|
16
8
|
export interface RouteViewConfigWithRoute<TRoute extends AnyAbstractRouteEntity> extends Pick<LoadableConfig, 'loading' | 'preload' | 'throwOnError'> {
|
|
17
9
|
route: TRoute;
|
|
18
10
|
view?: RouteViewComponent<TRoute>;
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
loadView?: (route: TRoute) => Promise<RouteViewComponent<TRoute>>;
|
|
12
|
+
/**
|
|
13
|
+
* Case when route is not opened
|
|
14
|
+
*/
|
|
15
|
+
fallback?: ReactNode;
|
|
21
16
|
children?: ReactNode | ((params: RouteViewProps<TRoute>['params'], route: TRoute) => ReactNode);
|
|
22
17
|
}
|
|
23
18
|
export type RouteViewConfig<TRoute extends AnyAbstractRouteEntity> = RouteViewConfigWithRoute<TRoute> | RouteViewConfigWithoutRoute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-view.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAU,MAAM,OAAO,CAAC;AACzD,OAAO,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EACL,sBAAsB,EACtB,KAAK,QAAQ,EACb,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,sBAAsB,IAClE,aAAa,CAAC,cAAc,CAAC,M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S,CAAC;IACrB,MAAM,EAAE,MAAM,SAAS,QAAQ,GAC3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,GAC3C,MAAM,SAAS,eAAe,GAC5B,MAAM,CAAC,QAAQ,CAAC,GAChB,KAAK,CAAC;CACb,CAAC;AAEF,iBAAS,aAAa,CAAC,MAAM,SAAS,sBAAsB,EAC1D,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,GACvC,SAAS,CAwCX;AAED,eAAO,MAAM,SAAS;;CAA0B,CAAC"}
|
|
@@ -11,12 +11,12 @@ function RouteViewBase(props) {
|
|
|
11
11
|
: props.children;
|
|
12
12
|
}
|
|
13
13
|
if (!props.route.isOpened) {
|
|
14
|
-
return props.
|
|
14
|
+
return props.fallback ?? null;
|
|
15
15
|
}
|
|
16
|
-
if (props.
|
|
16
|
+
if (props.loadView) {
|
|
17
17
|
if (!lazyViewComponentRef.current) {
|
|
18
18
|
lazyViewComponentRef.current = loadable({
|
|
19
|
-
load: () => props.
|
|
19
|
+
load: () => props.loadView(props.route),
|
|
20
20
|
loading: props.loading,
|
|
21
21
|
preload: props.preload,
|
|
22
22
|
throwOnError: props.throwOnError,
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { EmptyObject } from 'yummies/utils/types';
|
|
3
|
-
import { AnyAbstractRouteEntity, AnyRouteGroup, RoutesArrayCollection, RoutesCollection, RoutesObjectCollection } from '../../core/index.js';
|
|
4
|
-
import { RouteViewComponent, RouteViewConfigWithRoute } from './route-view.js';
|
|
5
|
-
export type RouteGroupView<TRouteEntity extends AnyAbstractRouteEntity> = Omit<RouteViewConfigWithRoute<TRouteEntity>, 'route'> | RouteViewComponent<TRouteEntity>;
|
|
6
|
-
export type RouteGroupViews<TRoutes extends RoutesCollection> = TRoutes extends RoutesArrayCollection ? {
|
|
7
|
-
[K in keyof TRoutes]: TRoutes[K] extends AnyAbstractRouteEntity ? RouteGroupView<TRoutes[K]> : never;
|
|
8
|
-
} : TRoutes extends RoutesObjectCollection ? {
|
|
9
|
-
[K in keyof TRoutes]: TRoutes[K] extends AnyAbstractRouteEntity ? RouteGroupView<TRoutes[K]> : never;
|
|
10
|
-
} : EmptyObject;
|
|
11
|
-
export interface RouteGroupViewProps<TRouteGroup extends AnyRouteGroup> {
|
|
12
|
-
group: TRouteGroup;
|
|
13
|
-
views: Partial<RouteGroupViews<TRouteGroup['routes']>>;
|
|
14
|
-
onFallback?: VoidFunction;
|
|
15
|
-
fallbackView?: ReactNode;
|
|
16
|
-
}
|
|
17
|
-
export declare const RouteGroupView: (<TRouteGroup extends AnyRouteGroup>({ group, views, fallbackView, onFallback, }: RouteGroupViewProps<TRouteGroup>) => string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null) & {
|
|
18
|
-
displayName: string;
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=route-group-view.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-group-view.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-group-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA4B,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EACL,sBAAsB,EAEtB,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAEL,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,sBAAsB,IAElE,IAAI,CAAC,wBAAwB,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,GAErD,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAErC,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,gBAAgB,IAC1D,OAAO,SAAS,qBAAqB,GACjC;KACG,CAAC,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,sBAAsB,GAC3D,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAC1B,KAAK;CACV,GACD,OAAO,SAAS,sBAAsB,GACpC;KACG,CAAC,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,sBAAsB,GAC3D,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAC1B,KAAK;CACV,GACD,WAAW,CAAC;AAEpB,MAAM,WAAW,mBAAmB,CAAC,WAAW,SAAS,aAAa;IACpE,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvD,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AAmDD,eAAO,MAAM,cAAc,IAjDC,WAAW,SAAS,aAAa,+CAK1D,mBAAmB,CAAC,WAAW,CAAC;;CA4CuB,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { observer } from 'mobx-react-lite';
|
|
3
|
-
import { useLayoutEffect, useMemo } from 'react';
|
|
4
|
-
import { RouteView, } from './route-view.js';
|
|
5
|
-
const RouteGroupViewBase = ({ group, views, fallbackView, onFallback, }) => {
|
|
6
|
-
const viewEntries = useMemo(() => Object.entries(views), []);
|
|
7
|
-
const openedRouteEntry = viewEntries.find(([routeName]) => {
|
|
8
|
-
// @ts-expect-error Object.entries is not accept types for arrays
|
|
9
|
-
const route = group.routes[routeName];
|
|
10
|
-
return route.isOpened;
|
|
11
|
-
});
|
|
12
|
-
const openedRouteName = openedRouteEntry?.[0];
|
|
13
|
-
const openedRoutePropsOrView = openedRouteEntry?.[1];
|
|
14
|
-
const openedRoute = openedRouteName && openedRouteName in group.routes
|
|
15
|
-
? // @ts-expect-error Object.entries is not accept types for arrays
|
|
16
|
-
group.routes[openedRouteName]
|
|
17
|
-
: undefined;
|
|
18
|
-
useLayoutEffect(() => {
|
|
19
|
-
if (!openedRoute) {
|
|
20
|
-
onFallback?.();
|
|
21
|
-
}
|
|
22
|
-
}, [openedRoute]);
|
|
23
|
-
if (!openedRoute) {
|
|
24
|
-
return fallbackView ?? null;
|
|
25
|
-
}
|
|
26
|
-
const openedRouteViewProps = openedRoutePropsOrView &&
|
|
27
|
-
(typeof openedRoutePropsOrView === 'function' ||
|
|
28
|
-
'contextTypes' in openedRoutePropsOrView ||
|
|
29
|
-
'$$typeof' in openedRoutePropsOrView)
|
|
30
|
-
? {
|
|
31
|
-
view: openedRoutePropsOrView,
|
|
32
|
-
fallbackView,
|
|
33
|
-
}
|
|
34
|
-
: {
|
|
35
|
-
...openedRoutePropsOrView,
|
|
36
|
-
fallbackView: openedRoutePropsOrView?.fallbackView ?? fallbackView,
|
|
37
|
-
};
|
|
38
|
-
return _jsx(RouteView, { route: openedRoute, ...openedRouteViewProps });
|
|
39
|
-
};
|
|
40
|
-
export const RouteGroupView = observer(RouteGroupViewBase);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { AnyAbstractRouteEntity } from '../../core/index.js';
|
|
3
|
-
import { RouteViewComponent, RouteViewConfigWithRoute } from './route-view.js';
|
|
4
|
-
export type MappedRouteView<TRouteEntity extends AnyAbstractRouteEntity> = Omit<RouteViewConfigWithRoute<TRouteEntity>, 'route'> | RouteViewComponent<TRouteEntity>;
|
|
5
|
-
type RouteViewMapArrayType = [
|
|
6
|
-
AnyAbstractRouteEntity,
|
|
7
|
-
MappedRouteView<AnyAbstractRouteEntity>
|
|
8
|
-
][];
|
|
9
|
-
export type RouteViewMapType = RouteViewMapArrayType;
|
|
10
|
-
export interface RouteViewMapProps<TMap extends RouteViewMapType> {
|
|
11
|
-
map: TMap;
|
|
12
|
-
onFallback?: VoidFunction;
|
|
13
|
-
fallbackView?: ReactNode;
|
|
14
|
-
}
|
|
15
|
-
export declare const RouteViewMap: (<TMap extends RouteViewMapType>({ map, onFallback, fallbackView, }: RouteViewMapProps<TMap>) => string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null) & {
|
|
16
|
-
displayName: string;
|
|
17
|
-
};
|
|
18
|
-
export {};
|
|
19
|
-
//# sourceMappingURL=route-view-map.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-view-map.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view-map.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA4B,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAEL,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,eAAe,CAAC,YAAY,SAAS,sBAAsB,IAEnE,IAAI,CAAC,wBAAwB,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,GAErD,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAErC,KAAK,qBAAqB,GAAG;IAC3B,sBAAsB;IACtB,eAAe,CAAC,sBAAsB,CAAC;CACxC,EAAE,CAAC;AAGJ,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAErD,MAAM,WAAW,iBAAiB,CAAC,IAAI,SAAS,gBAAgB;IAC9D,GAAG,EAAE,IAAI,CAAC;IACV,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AA2CD,eAAO,MAAM,YAAY,IAzCC,IAAI,SAAS,gBAAgB,sCAIpD,iBAAiB,CAAC,IAAI,CAAC;;CAqC4B,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { observer } from 'mobx-react-lite';
|
|
3
|
-
import { useLayoutEffect, useMemo } from 'react';
|
|
4
|
-
import { RouteView, } from './route-view.js';
|
|
5
|
-
const RouteViewMapBase = ({ map, onFallback, fallbackView, }) => {
|
|
6
|
-
const viewEntries = useMemo(() => Object.entries(map), []);
|
|
7
|
-
const openedRouteEntry = viewEntries.find(([, data]) => {
|
|
8
|
-
const route = data[0];
|
|
9
|
-
return route.isOpened;
|
|
10
|
-
});
|
|
11
|
-
const openedRoute = openedRouteEntry?.[1]?.[0];
|
|
12
|
-
const openedRoutePropsOrView = openedRouteEntry?.[1]?.[1];
|
|
13
|
-
useLayoutEffect(() => {
|
|
14
|
-
if (!openedRoute) {
|
|
15
|
-
onFallback?.();
|
|
16
|
-
}
|
|
17
|
-
}, [openedRoute]);
|
|
18
|
-
if (!openedRoute) {
|
|
19
|
-
return fallbackView ?? null;
|
|
20
|
-
}
|
|
21
|
-
const openedRouteViewProps = openedRoutePropsOrView &&
|
|
22
|
-
(typeof openedRoutePropsOrView === 'function' ||
|
|
23
|
-
'contextTypes' in openedRoutePropsOrView ||
|
|
24
|
-
'$$typeof' in openedRoutePropsOrView)
|
|
25
|
-
? {
|
|
26
|
-
view: openedRoutePropsOrView,
|
|
27
|
-
fallbackView,
|
|
28
|
-
}
|
|
29
|
-
: {
|
|
30
|
-
...openedRoutePropsOrView,
|
|
31
|
-
fallbackView: openedRoutePropsOrView?.fallbackView ?? fallbackView,
|
|
32
|
-
};
|
|
33
|
-
return _jsx(RouteView, { route: openedRoute, ...openedRouteViewProps });
|
|
34
|
-
};
|
|
35
|
-
export const RouteViewMap = observer(RouteViewMapBase);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { AllPropertiesOptional, Maybe } from 'yummies/utils/types';
|
|
3
|
-
import { AnyRouteEntity, RouteNavigateParams, RouteParams } from '../../core/index.js';
|
|
4
|
-
type SwitchBaseProps = {
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
};
|
|
7
|
-
type SwitchPropsWithDefaultRoute<TRoute extends AnyRouteEntity> = {
|
|
8
|
-
default?: TRoute;
|
|
9
|
-
} & (AllPropertiesOptional<RouteParams<TRoute>> extends true ? {
|
|
10
|
-
params?: Maybe<RouteParams<TRoute>>;
|
|
11
|
-
} : {
|
|
12
|
-
params: RouteParams<TRoute>;
|
|
13
|
-
}) & SwitchBaseProps & RouteNavigateParams;
|
|
14
|
-
type SwitchPropsWithDefaultUrl = {
|
|
15
|
-
default?: string;
|
|
16
|
-
} & SwitchBaseProps & RouteNavigateParams;
|
|
17
|
-
export type SwitchProps<TRoute extends AnyRouteEntity> = SwitchPropsWithDefaultRoute<TRoute> | SwitchPropsWithDefaultUrl;
|
|
18
|
-
export declare const Switch: (<TRoute extends AnyRouteEntity>({ children, default: defaultNavigation, params, ...navigateParams }: SwitchProps<TRoute>) => ReactNode) & {
|
|
19
|
-
displayName: string;
|
|
20
|
-
};
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../../src/react/components/switch.tsx"],"names":[],"mappings":"AAGA,OAAO,EAIL,SAAS,EAEV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EACL,cAAc,EAEd,mBAAmB,EACnB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAG7B,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,KAAK,2BAA2B,CAAC,MAAM,SAAS,cAAc,IAAI;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,CAAC,qBAAqB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,IAAI,GACxD;IACE,MAAM,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACrC,GACD;IACE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC,GACJ,eAAe,GACf,mBAAmB,CAAC;AAEtB,KAAK,yBAAyB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,eAAe,GACjB,mBAAmB,CAAC;AAEtB,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,cAAc,IACjD,2BAA2B,CAAC,MAAM,CAAC,GACnC,yBAAyB,CAAC;AAsB9B,eAAO,MAAM,MAAM,IAAsB,MAAM,SAAS,cAAc,uEAMnE,WAAW,CAAC,MAAM,CAAC;;CAiCpB,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { buildSearchString } from 'mobx-location-history';
|
|
3
|
-
import { observer } from 'mobx-react-lite';
|
|
4
|
-
import { Fragment, isValidElement, useEffect, } from 'react';
|
|
5
|
-
import { flatMapDeep } from 'yummies/data';
|
|
6
|
-
import { routeConfig, } from '../../core/index.js';
|
|
7
|
-
import { isRouteEntity } from '../../core/utils/is-route-entity.js';
|
|
8
|
-
const flattenChildren = (children) => flatMapDeep(children, (c) =>
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
c && c.type === Fragment ? c.props.children : c);
|
|
12
|
-
const isValidRouteElement = (element) => {
|
|
13
|
-
return (isValidElement(element) &&
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
isRouteEntity(element.props?.route));
|
|
16
|
-
};
|
|
17
|
-
export const Switch = observer(function ({ children, default: defaultNavigation,
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
params, ...navigateParams }) {
|
|
20
|
-
let resultElement = null;
|
|
21
|
-
let defaultElement = null;
|
|
22
|
-
for (const element of flattenChildren(children)) {
|
|
23
|
-
if (isValidRouteElement(element) && element.props.route.isOpened) {
|
|
24
|
-
resultElement = element;
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
defaultElement = element;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const isResultElementFound = !!resultElement;
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!isResultElementFound && defaultNavigation) {
|
|
34
|
-
if (typeof defaultNavigation === 'string') {
|
|
35
|
-
const history = routeConfig.get().history;
|
|
36
|
-
const url = `${defaultNavigation}${buildSearchString(navigateParams.query || {})}`;
|
|
37
|
-
if (navigateParams.replace) {
|
|
38
|
-
history.replace(url, navigateParams.state);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
history.push(url, navigateParams.state);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else if (!defaultNavigation.isOpened) {
|
|
45
|
-
defaultNavigation.open(params, navigateParams);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}, [isResultElementFound, defaultNavigation]);
|
|
49
|
-
return resultElement ?? defaultElement;
|
|
50
|
-
});
|