mobx-route 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/assets/logo.png +0 -0
- package/assets/logo.pxz +0 -0
- package/components/index.d.ts +1 -0
- package/components/index.d.ts.map +1 -1
- package/components/index.js +1 -0
- package/components/link.d.ts.map +1 -1
- package/components/route-view.d.ts +17 -0
- package/components/route-view.d.ts.map +1 -0
- package/components/route-view.js +22 -0
- package/package.json +36 -4
- package/route/config.d.ts +7 -0
- package/route/config.d.ts.map +1 -0
- package/route/config.js +44 -0
- package/route/index.d.ts +2 -0
- package/route/index.d.ts.map +1 -1
- package/route/index.js +2 -0
- package/route/route-group.d.ts +4 -6
- package/route/route-group.d.ts.map +1 -1
- package/route/route-group.types.d.ts +5 -1
- package/route/route-group.types.d.ts.map +1 -1
- package/route/route.d.ts +3 -9
- package/route/route.d.ts.map +1 -1
- package/route/route.js +7 -23
- package/route/route.test.js +2 -1
- package/route/route.types.d.ts +6 -3
- package/route/route.types.d.ts.map +1 -1
- package/route/router.d.ts +12 -0
- package/route/router.d.ts.map +1 -0
- package/route/router.js +23 -0
- package/route/router.types.d.ts +16 -0
- package/route/router.types.d.ts.map +1 -0
- package/route/router.types.js +1 -0
- package/route/view-model/index.d.ts +2 -0
- package/route/view-model/index.d.ts.map +1 -0
- package/route/view-model/index.js +1 -0
- package/route/view-model/route-view-model.d.ts +14 -0
- package/route/view-model/route-view-model.d.ts.map +1 -0
- package/route/view-model/route-view-model.js +31 -0
- package/route/virtual-route.d.ts +9 -3
- package/route/virtual-route.d.ts.map +1 -1
- package/route/virtual-route.js +22 -3
- package/route/virtual-route.types.d.ts +5 -0
- package/route/virtual-route.types.d.ts.map +1 -0
- package/route/virtual-route.types.js +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<img src="assets/logo.png" align="right" height="156" alt="logo" />
|
|
2
|
+
|
|
1
3
|
# mobx-route
|
|
2
4
|
|
|
3
5
|
[![NPM version][npm-image]][npm-url] [![test status][github-test-actions-image]][github-actions-url] [![build status][github-build-actions-image]][github-actions-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
|
package/assets/logo.png
ADDED
|
Binary file
|
package/assets/logo.pxz
ADDED
|
Binary file
|
package/components/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
|
package/components/index.js
CHANGED
package/components/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/components/link.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EAKpB,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/components/link.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EAKpB,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAa,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,QAAQ,IAAI,IAAI,CACnD,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,MAAM,CACP,GAAG;IACF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,mBAAmB,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,GACtE;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;AAErD,KAAK,iBAAiB,GAAG,CAAC,MAAM,SAAS,QAAQ,EAC/C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KACrB,SAAS,CAAC;AAEf,eAAO,MAAM,IAAI,EA6CD,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { AnyRouteGroup } from '../route/route-group.types.js';
|
|
3
|
+
import { AnyRoute } from '../route/route.types.js';
|
|
4
|
+
import type { VirtualRoute } from '../route/virtual-route.js';
|
|
5
|
+
type RouteKind = AnyRouteGroup | AnyRoute | VirtualRoute;
|
|
6
|
+
export interface RouteViewProps<TRouteKind extends RouteKind> {
|
|
7
|
+
route: TRouteKind;
|
|
8
|
+
view?: ComponentType<any>;
|
|
9
|
+
lazyView?: () => Promise<ComponentType<any>>;
|
|
10
|
+
loader?: ComponentType;
|
|
11
|
+
}
|
|
12
|
+
declare function RouteViewBase<TRouteKind extends RouteKind>(props: RouteViewProps<TRouteKind>): import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
13
|
+
export declare const RouteView: typeof RouteViewBase & {
|
|
14
|
+
displayName: string;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=route-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-view.d.ts","sourceRoot":"","sources":["../../src/components/route-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAU,MAAM,OAAO,CAAC;AAG9C,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,KAAK,SAAS,GAAG,aAAa,GAAG,QAAQ,GAAG,YAAY,CAAC;AAEzD,MAAM,WAAW,cAAc,CAAC,UAAU,SAAS,SAAS;IAC1D,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,iBAAS,aAAa,CAAC,UAAU,SAAS,SAAS,EACjD,KAAK,EAAE,cAAc,CAAC,UAAU,CAAC,8DAoBlC;AAED,eAAO,MAAM,SAAS;;CAA0B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { observer } from 'mobx-react-lite';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
import { loadable } from 'react-simple-loadable';
|
|
5
|
+
function RouteViewBase(props) {
|
|
6
|
+
const lazyViewComponentRef = useRef();
|
|
7
|
+
let Component;
|
|
8
|
+
if (!props.route.isOpened) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (props.lazyView) {
|
|
12
|
+
lazyViewComponentRef.current = loadable(props.lazyView, {
|
|
13
|
+
loader: props.loader,
|
|
14
|
+
});
|
|
15
|
+
Component = lazyViewComponentRef.current;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
Component = props.view;
|
|
19
|
+
}
|
|
20
|
+
return Component && _jsx(Component, {});
|
|
21
|
+
}
|
|
22
|
+
export const RouteView = observer(RouteViewBase);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-route",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"mobx",
|
|
6
6
|
"react",
|
|
@@ -20,14 +20,21 @@
|
|
|
20
20
|
"url": "git://github.com/js2me/mobx-route"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"mobx-location-history": "^2.0
|
|
23
|
+
"mobx-location-history": "^2.1.0",
|
|
24
24
|
"path-to-regexp": "^8.2.0",
|
|
25
|
-
"
|
|
25
|
+
"react-simple-loadable": "^2.1.0",
|
|
26
|
+
"yummies": "^3.1.7"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"mobx": "^6.12.4",
|
|
29
30
|
"mobx-react-lite": "^4.0.7",
|
|
30
|
-
"react": "^18.3.1"
|
|
31
|
+
"react": "^18.3.1",
|
|
32
|
+
"mobx-view-model": "^6.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"mobx-view-model": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
31
38
|
},
|
|
32
39
|
"devDependencies": {
|
|
33
40
|
"@testing-library/react": "^16.3.0",
|
|
@@ -55,11 +62,21 @@
|
|
|
55
62
|
"default": "./components/link.js",
|
|
56
63
|
"types": "./components/link.d.ts"
|
|
57
64
|
},
|
|
65
|
+
"./components/route-view": {
|
|
66
|
+
"import": "./components/route-view.js",
|
|
67
|
+
"default": "./components/route-view.js",
|
|
68
|
+
"types": "./components/route-view.d.ts"
|
|
69
|
+
},
|
|
58
70
|
".": {
|
|
59
71
|
"import": "./index.js",
|
|
60
72
|
"default": "./index.js",
|
|
61
73
|
"types": "./index.d.ts"
|
|
62
74
|
},
|
|
75
|
+
"./route/config": {
|
|
76
|
+
"import": "./route/config.js",
|
|
77
|
+
"default": "./route/config.js",
|
|
78
|
+
"types": "./route/config.d.ts"
|
|
79
|
+
},
|
|
63
80
|
"./route": {
|
|
64
81
|
"import": "./route/index.js",
|
|
65
82
|
"default": "./route/index.js",
|
|
@@ -80,6 +97,21 @@
|
|
|
80
97
|
"default": "./route/route.js",
|
|
81
98
|
"types": "./route/route.d.ts"
|
|
82
99
|
},
|
|
100
|
+
"./route/router": {
|
|
101
|
+
"import": "./route/router.js",
|
|
102
|
+
"default": "./route/router.js",
|
|
103
|
+
"types": "./route/router.d.ts"
|
|
104
|
+
},
|
|
105
|
+
"./route/view-model": {
|
|
106
|
+
"import": "./route/view-model/index.js",
|
|
107
|
+
"default": "./route/view-model/index.js",
|
|
108
|
+
"types": "./route/view-model/index.d.ts"
|
|
109
|
+
},
|
|
110
|
+
"./route/view-model/route-view-model": {
|
|
111
|
+
"import": "./route/view-model/route-view-model.js",
|
|
112
|
+
"default": "./route/view-model/route-view-model.js",
|
|
113
|
+
"types": "./route/view-model/route-view-model.d.ts"
|
|
114
|
+
},
|
|
83
115
|
"./route/virtual-route": {
|
|
84
116
|
"import": "./route/virtual-route.js",
|
|
85
117
|
"default": "./route/virtual-route.js",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RouteGlobalConfiguration } from './route.types.js';
|
|
2
|
+
export declare const routeConfig: {
|
|
3
|
+
get: () => RouteGlobalConfiguration;
|
|
4
|
+
set: (value: RouteGlobalConfiguration | null | undefined) => RouteGlobalConfiguration | null | undefined;
|
|
5
|
+
update: (value: Partial<RouteGlobalConfiguration>) => void;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/route/config.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAM5D,eAAO,MAAM,WAAW;;;;CA+CvB,CAAC"}
|
package/route/config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MobxHistory, MobxLocation, QueryParams, } from 'mobx-location-history';
|
|
2
|
+
import { createGlobalDynamicConfig } from 'yummies/complex';
|
|
3
|
+
let localHistory;
|
|
4
|
+
let localLocation;
|
|
5
|
+
let localQueryParams;
|
|
6
|
+
export const routeConfig = createGlobalDynamicConfig((update) => {
|
|
7
|
+
if (update?.router) {
|
|
8
|
+
localHistory?.destroy();
|
|
9
|
+
localLocation?.destroy();
|
|
10
|
+
localQueryParams?.destroy();
|
|
11
|
+
return {
|
|
12
|
+
...update,
|
|
13
|
+
history: update.router.history,
|
|
14
|
+
location: update.router.location,
|
|
15
|
+
queryParams: update.router.query,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (localHistory && update?.history) {
|
|
19
|
+
localHistory.destroy();
|
|
20
|
+
}
|
|
21
|
+
const history = update?.history ?? (localHistory = new MobxHistory());
|
|
22
|
+
if (localLocation && update?.location) {
|
|
23
|
+
localLocation.destroy();
|
|
24
|
+
}
|
|
25
|
+
const location = update?.location ?? (localLocation = new MobxLocation(history));
|
|
26
|
+
let queryParams;
|
|
27
|
+
if ((update?.history || update?.location) && !update.queryParams) {
|
|
28
|
+
queryParams = localQueryParams = new QueryParams(location, history);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (localQueryParams && update?.queryParams) {
|
|
32
|
+
localQueryParams.destroy();
|
|
33
|
+
}
|
|
34
|
+
queryParams =
|
|
35
|
+
update?.queryParams ??
|
|
36
|
+
(localQueryParams = new QueryParams(location, history));
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
...update,
|
|
40
|
+
history,
|
|
41
|
+
location,
|
|
42
|
+
queryParams,
|
|
43
|
+
};
|
|
44
|
+
});
|
package/route/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export * from './config.js';
|
|
1
2
|
export * from './route.types.js';
|
|
2
3
|
export * from './route.js';
|
|
3
4
|
export * from './route-group.js';
|
|
4
5
|
export * from './route-group.types.js';
|
|
5
6
|
export * from './virtual-route.js';
|
|
7
|
+
export * from './virtual-route.types.js';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/route/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|
package/route/index.js
CHANGED
package/route/route-group.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
routes: TGrouppedRoutes;
|
|
6
|
-
constructor(routes: TGrouppedRoutes);
|
|
1
|
+
import { RoutesCollection } from './route-group.types.js';
|
|
2
|
+
export declare class RouteGroup<TRoutesCollection extends RoutesCollection> {
|
|
3
|
+
routes: TRoutesCollection;
|
|
4
|
+
constructor(routes: TRoutesCollection);
|
|
7
5
|
get isOpened(): boolean;
|
|
8
6
|
open(...args: any[]): void;
|
|
9
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-group.d.ts","sourceRoot":"","sources":["../../src/route/route-group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"route-group.d.ts","sourceRoot":"","sources":["../../src/route/route-group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,qBAAa,UAAU,CAAC,iBAAiB,SAAS,gBAAgB;IAC7C,MAAM,EAAE,iBAAiB;gBAAzB,MAAM,EAAE,iBAAiB;IAM5C,IAAI,QAAQ,IAAI,OAAO,CAGtB;IAED,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAiBpB"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { RouteGroup } from './route-group.js';
|
|
2
|
-
|
|
2
|
+
import { AnyRoute } from './route.types.js';
|
|
3
|
+
import { VirtualRoute } from './virtual-route.js';
|
|
4
|
+
export type AnyRouteGroup = RouteGroup<RoutesCollection>;
|
|
5
|
+
export type RouteCollectionItem = AnyRoute | AnyRouteGroup | VirtualRoute;
|
|
6
|
+
export type RoutesCollection = Record<string, RouteCollectionItem>;
|
|
3
7
|
//# sourceMappingURL=route-group.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-group.types.d.ts","sourceRoot":"","sources":["../../src/route/route-group.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"route-group.types.d.ts","sourceRoot":"","sources":["../../src/route/route-group.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAEzD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,aAAa,GAAG,YAAY,CAAC;AAE1E,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC"}
|
package/route/route.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IMobxHistory, IMobxLocation, IQueryParams } from 'mobx-location-history';
|
|
2
2
|
import { ParamData, TokenData } from 'path-to-regexp';
|
|
3
|
-
import { AllPropertiesOptional } from 'yummies/utils/types';
|
|
4
|
-
import { AnyRoute, ExtractPathParams, RouteConfiguration,
|
|
3
|
+
import { AllPropertiesOptional, AnyObject, Maybe } from 'yummies/utils/types';
|
|
4
|
+
import { AnyRoute, ExtractPathParams, RouteConfiguration, RouteMatchesData, RouteNavigateParams } from './route.types.js';
|
|
5
5
|
export declare class Route<TPath extends string, TParentRoute extends Route<any, any> | null = null> {
|
|
6
6
|
path: TPath;
|
|
7
7
|
protected config: RouteConfiguration<TParentRoute>;
|
|
@@ -20,18 +20,12 @@ export declare class Route<TPath extends string, TParentRoute extends Route<any,
|
|
|
20
20
|
get hasChildrenMatches(): boolean;
|
|
21
21
|
protected processParams(params?: ExtractPathParams<TPath> | null | undefined): ParamData | undefined;
|
|
22
22
|
protected get baseUrl(): string;
|
|
23
|
-
createUrl(...args: AllPropertiesOptional<ExtractPathParams<TPath>> extends true ? [
|
|
24
|
-
params?: ExtractPathParams<TPath> | null | undefined,
|
|
25
|
-
query?: Record<string, any>
|
|
26
|
-
] : [params: ExtractPathParams<TPath>, query?: Record<string, any>]): string;
|
|
23
|
+
createUrl(...args: AllPropertiesOptional<ExtractPathParams<TPath>> extends true ? [params?: Maybe<ExtractPathParams<TPath>>, query?: AnyObject] : [params: ExtractPathParams<TPath>, query?: AnyObject]): string;
|
|
27
24
|
open(...args: AllPropertiesOptional<ExtractPathParams<TPath>> extends true ? [
|
|
28
25
|
params?: ExtractPathParams<TPath> | null | undefined,
|
|
29
26
|
navigateParams?: RouteNavigateParams
|
|
30
27
|
] : [params: ExtractPathParams<TPath>, navigateParams?: RouteNavigateParams]): void;
|
|
31
28
|
open(url: string, navigateParams?: RouteNavigateParams): void;
|
|
32
29
|
protected get tokenData(): TokenData;
|
|
33
|
-
private static _globalConfiguration;
|
|
34
|
-
static setGlobalConfiguration(globalConfiguration: Partial<RouteGlobalConfiguration>): void;
|
|
35
|
-
static get globalConfiguration(): RouteGlobalConfiguration;
|
|
36
30
|
}
|
|
37
31
|
//# sourceMappingURL=route.d.ts.map
|
package/route/route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/route/route.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,YAAY,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/route/route.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAkB,SAAS,EAAS,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG9E,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,KAAK,CAChB,KAAK,SAAS,MAAM,EACpB,YAAY,SAAS,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI;IAYzC,IAAI,EAAE,KAAK;IAClB,SAAS,CAAC,MAAM,EAAE,kBAAkB,CAAC,YAAY,CAAC;IAXpD,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;IAChC,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC;IAElC,KAAK,EAAE,YAAY,CAAC;IAEpB,OAAO,CAAC,UAAU,CAAwB;IAE1C,QAAQ,EAAE,QAAQ,EAAE,CAAM;gBAGjB,IAAI,EAAE,KAAK,EACR,MAAM,GAAE,kBAAkB,CAAC,YAAY,CAAM;IAiBzD,IAAI,IAAI,IAAI,gBAAgB,CAAC,KAAK,CAAC,GAAG,IAAI,CAsBzC;IAED,IAAI,Q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|
|
1
1
|
import { action, computed, makeObservable, observable } from 'mobx';
|
|
2
|
-
import { buildSearchString,
|
|
2
|
+
import { buildSearchString, } from 'mobx-location-history';
|
|
3
3
|
import { compile, match, parse } from 'path-to-regexp';
|
|
4
|
+
import { routeConfig } from './config.js';
|
|
4
5
|
export class Route {
|
|
5
6
|
path;
|
|
6
7
|
config;
|
|
@@ -12,9 +13,10 @@ export class Route {
|
|
|
12
13
|
constructor(path, config = {}) {
|
|
13
14
|
this.path = path;
|
|
14
15
|
this.config = config;
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
16
|
+
const defaults = routeConfig.get();
|
|
17
|
+
this.history = config.history ?? defaults.history;
|
|
18
|
+
this.location = config.location ?? defaults.location;
|
|
19
|
+
this.query = config.queryParams ?? defaults.queryParams;
|
|
18
20
|
computed.struct(this, 'isMatches');
|
|
19
21
|
computed.struct(this, 'matchData');
|
|
20
22
|
computed.struct(this, 'hasChildrenMatches');
|
|
@@ -75,7 +77,7 @@ export class Route {
|
|
|
75
77
|
}, {});
|
|
76
78
|
}
|
|
77
79
|
get baseUrl() {
|
|
78
|
-
const usedBaseUrl = this.config.baseUrl ??
|
|
80
|
+
const usedBaseUrl = this.config.baseUrl ?? routeConfig.get().baseUrl;
|
|
79
81
|
return !usedBaseUrl || usedBaseUrl === '/' ? '' : usedBaseUrl;
|
|
80
82
|
}
|
|
81
83
|
createUrl(...args) {
|
|
@@ -106,22 +108,4 @@ export class Route {
|
|
|
106
108
|
}
|
|
107
109
|
return this._tokenData;
|
|
108
110
|
}
|
|
109
|
-
static _globalConfiguration;
|
|
110
|
-
static setGlobalConfiguration(globalConfiguration) {
|
|
111
|
-
const history = globalConfiguration.history ?? new MobxHistory();
|
|
112
|
-
const location = globalConfiguration.location ?? new MobxLocation(history);
|
|
113
|
-
const queryParams = globalConfiguration.queryParams ?? new QueryParams(location, history);
|
|
114
|
-
const config = {
|
|
115
|
-
history,
|
|
116
|
-
location,
|
|
117
|
-
queryParams,
|
|
118
|
-
};
|
|
119
|
-
this._globalConfiguration = config;
|
|
120
|
-
}
|
|
121
|
-
static get globalConfiguration() {
|
|
122
|
-
if (!this._globalConfiguration) {
|
|
123
|
-
this.setGlobalConfiguration({});
|
|
124
|
-
}
|
|
125
|
-
return this._globalConfiguration;
|
|
126
|
-
}
|
|
127
111
|
}
|
package/route/route.test.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
4
|
import { MobxHistory, MobxLocation } from 'mobx-location-history';
|
|
5
5
|
import { beforeEach, describe, expect, expectTypeOf, it, vi } from 'vitest';
|
|
6
|
+
import { routeConfig } from './config.js';
|
|
6
7
|
import { RouteGroup } from './route-group.js';
|
|
7
8
|
import { Route } from './route.js';
|
|
8
9
|
class MobxHistoryMock extends MobxHistory {
|
|
@@ -24,7 +25,7 @@ class MobxHistoryMock extends MobxHistory {
|
|
|
24
25
|
describe('route', () => {
|
|
25
26
|
const history = new MobxHistoryMock();
|
|
26
27
|
const location = new MobxLocation(history);
|
|
27
|
-
|
|
28
|
+
routeConfig.update({
|
|
28
29
|
history,
|
|
29
30
|
location,
|
|
30
31
|
});
|
package/route/route.types.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { IMobxHistory, IMobxLocation, IQueryParams } from 'mobx-location-history';
|
|
2
2
|
import { ParseOptions } from 'path-to-regexp';
|
|
3
|
+
import { AnyObject } from 'yummies/utils/types';
|
|
3
4
|
import type { Route } from './route.js';
|
|
5
|
+
import type { AnyRouter } from './router.types.js';
|
|
4
6
|
export interface RouteGlobalConfiguration {
|
|
5
7
|
history: IMobxHistory;
|
|
6
8
|
location: IMobxLocation;
|
|
7
9
|
queryParams: IQueryParams;
|
|
10
|
+
router?: AnyRouter;
|
|
8
11
|
baseUrl?: string;
|
|
9
12
|
}
|
|
10
13
|
export interface RouteConfiguration<TParentRoute extends AnyRoute | null = null> extends Partial<RouteGlobalConfiguration> {
|
|
11
14
|
index?: boolean;
|
|
12
|
-
meta?:
|
|
15
|
+
meta?: AnyObject;
|
|
13
16
|
parseOptions?: ParseOptions;
|
|
14
17
|
parent?: TParentRoute;
|
|
15
18
|
children?: AnyRoute[];
|
|
16
19
|
}
|
|
17
|
-
export type AnyRoute = Route<
|
|
20
|
+
export type AnyRoute = Route<string, any>;
|
|
18
21
|
export type PathParam = string | number | boolean | null;
|
|
19
22
|
export type PathParsedParam = string;
|
|
20
23
|
type Simplify<T> = T extends infer U ? {
|
|
@@ -36,7 +39,7 @@ export type ExtractPathParams<Path extends string> = Simplify<Path extends `${in
|
|
|
36
39
|
} : {}>;
|
|
37
40
|
export interface RouteNavigateParams {
|
|
38
41
|
replace?: boolean;
|
|
39
|
-
query?:
|
|
42
|
+
query?: AnyObject;
|
|
40
43
|
}
|
|
41
44
|
export interface RouteMatchesData<TPath extends string> {
|
|
42
45
|
path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.types.d.ts","sourceRoot":"","sources":["../../src/route/route.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"route.types.d.ts","sourceRoot":"","sources":["../../src/route/route.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ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|
+
import { IMobxHistory, IMobxLocation, IQueryParams } from 'mobx-location-history';
|
|
2
|
+
import { RoutesCollection } from './route-group.types.js';
|
|
3
|
+
import { RouterConfiguration, RouterNavigateOptions } from './router.types.js';
|
|
4
|
+
export declare class Router<TRoutesCollection extends RoutesCollection> {
|
|
5
|
+
routes: TRoutesCollection;
|
|
6
|
+
history: IMobxHistory;
|
|
7
|
+
location: IMobxLocation;
|
|
8
|
+
query: IQueryParams;
|
|
9
|
+
constructor(config: RouterConfiguration<TRoutesCollection>);
|
|
10
|
+
navigate(url: string, options?: RouterNavigateOptions): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/route/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE/E,qBAAa,MAAM,CAAC,iBAAiB,SAAS,gBAAgB;IAC5D,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,aAAa,CAAC;IACxB,KAAK,EAAE,YAAY,CAAC;gBAER,MAAM,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;IAO1D,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;CAWtD"}
|
package/route/router.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { buildSearchString, } from 'mobx-location-history';
|
|
2
|
+
import { routeConfig } from './config.js';
|
|
3
|
+
export class Router {
|
|
4
|
+
routes;
|
|
5
|
+
history;
|
|
6
|
+
location;
|
|
7
|
+
query;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.routes = config.routes;
|
|
10
|
+
this.history = config.history ?? routeConfig.get().history;
|
|
11
|
+
this.location = config.location ?? routeConfig.get().location;
|
|
12
|
+
this.query = config.queryParams ?? routeConfig.get().queryParams;
|
|
13
|
+
}
|
|
14
|
+
navigate(url, options) {
|
|
15
|
+
const navigationUrl = [url, buildSearchString(options?.query || {})].join('');
|
|
16
|
+
if (options?.replace) {
|
|
17
|
+
this.history.replaceState(null, '', navigationUrl);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.history.pushState(null, '', navigationUrl);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IMobxHistory, IMobxLocation, IQueryParams } from 'mobx-location-history';
|
|
2
|
+
import { AnyObject } from 'yummies/utils/types';
|
|
3
|
+
import type { RoutesCollection } from './route-group.types.js';
|
|
4
|
+
import { Router } from './router.js';
|
|
5
|
+
export interface RouterConfiguration<TRoutesStruct extends RoutesCollection> {
|
|
6
|
+
routes: TRoutesStruct;
|
|
7
|
+
history?: IMobxHistory;
|
|
8
|
+
location?: IMobxLocation;
|
|
9
|
+
queryParams?: IQueryParams;
|
|
10
|
+
}
|
|
11
|
+
export interface RouterNavigateOptions {
|
|
12
|
+
replace?: boolean;
|
|
13
|
+
query?: AnyObject;
|
|
14
|
+
}
|
|
15
|
+
export type AnyRouter = Router<RoutesCollection>;
|
|
16
|
+
//# sourceMappingURL=router.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.types.d.ts","sourceRoot":"","sources":["../../src/route/router.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,WAAW,mBAAmB,CAAC,aAAa,SAAS,gBAAgB;IACzE,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/route/view-model/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './route-view-model.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ViewModelBase, ViewModelParams } from 'mobx-view-model';
|
|
2
|
+
import { AnyObject, EmptyObject } from 'yummies/utils/types';
|
|
3
|
+
import { RouteCollectionItem } from '../route-group.types.js';
|
|
4
|
+
import { Route } from '../route.js';
|
|
5
|
+
import { ParsedPathParams } from '../route.types.js';
|
|
6
|
+
import { VirtualRoute } from '../virtual-route.js';
|
|
7
|
+
export declare abstract class RouteViewModel<TRoute extends RouteCollectionItem = RouteCollectionItem> extends ViewModelBase<AnyObject> {
|
|
8
|
+
abstract readonly route: TRoute;
|
|
9
|
+
constructor(params: ViewModelParams<any, any>);
|
|
10
|
+
get payload(): TRoute extends Route<string, any> ? ParsedPathParams<TRoute['path']> : TRoute extends VirtualRoute<infer Params> ? Params : EmptyObject;
|
|
11
|
+
get query(): import("mobx-location-history").IQueryParams;
|
|
12
|
+
get pathParams(): TRoute extends Route<string, any> ? ParsedPathParams<TRoute["path"]> : TRoute extends VirtualRoute<infer Params extends AnyObject | EmptyObject> ? Params : EmptyObject;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=route-view-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-view-model.d.ts","sourceRoot":"","sources":["../../../src/route/view-model/route-view-model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,8BAAsB,cAAc,CAClC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CACxD,SAAQ,aAAa,CAAC,SAAS,CAAC;IAChC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAEpB,MAAM,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC;IAS7C,IAAa,OAAO,IAAI,MAAM,SAAS,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,GACrD,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAChC,MAAM,SAAS,YAAY,CAAC,MAAM,MAAM,CAAC,GACvC,MAAM,GACN,WAAW,CAUhB;IAED,IAAI,KAAK,iDAMR;IAED,IAAI,UAAU,6GAtBwB,MAAM,yDAwB3C;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { computed, makeObservable } from 'mobx';
|
|
2
|
+
import { ViewModelBase } from 'mobx-view-model';
|
|
3
|
+
import { routeConfig } from '../config.js';
|
|
4
|
+
import { Route } from '../route.js';
|
|
5
|
+
import { VirtualRoute } from '../virtual-route.js';
|
|
6
|
+
export class RouteViewModel extends ViewModelBase {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
super(params);
|
|
9
|
+
computed.struct(this, 'pathParams');
|
|
10
|
+
computed(this, 'query');
|
|
11
|
+
makeObservable(this);
|
|
12
|
+
}
|
|
13
|
+
get payload() {
|
|
14
|
+
if (this.route instanceof Route) {
|
|
15
|
+
return this.route.data?.params || {};
|
|
16
|
+
}
|
|
17
|
+
if (this.route instanceof VirtualRoute) {
|
|
18
|
+
return this.route.params;
|
|
19
|
+
}
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
get query() {
|
|
23
|
+
if ('query' in this.route) {
|
|
24
|
+
return this.route.query;
|
|
25
|
+
}
|
|
26
|
+
return routeConfig.get().queryParams;
|
|
27
|
+
}
|
|
28
|
+
get pathParams() {
|
|
29
|
+
return this.payload;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/route/virtual-route.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import { IQueryParams } from 'mobx-location-history';
|
|
1
2
|
import { FnValue } from 'yummies/common';
|
|
2
|
-
|
|
3
|
+
import { AllPropertiesOptional, AnyObject, EmptyObject, Maybe } from 'yummies/utils/types';
|
|
4
|
+
import { VirtualRouteConfiguration } from './virtual-route.types.js';
|
|
5
|
+
export declare class VirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject> {
|
|
3
6
|
private isOpenedResolver?;
|
|
4
|
-
|
|
7
|
+
protected config: VirtualRouteConfiguration;
|
|
8
|
+
query: IQueryParams;
|
|
9
|
+
params: TParams;
|
|
10
|
+
constructor(isOpenedResolver?: FnValue<boolean, [query: IQueryParams["data"]]> | undefined, config?: VirtualRouteConfiguration);
|
|
5
11
|
get isOpened(): boolean;
|
|
6
12
|
setResolver(isOpenedResolver: FnValue<boolean>): void;
|
|
7
|
-
open(): void;
|
|
13
|
+
open(...args: AllPropertiesOptional<TParams> extends true ? [params?: Maybe<TParams>, query?: AnyObject] : [params: TParams, query?: AnyObject]): void;
|
|
8
14
|
close(): void;
|
|
9
15
|
}
|
|
10
16
|
//# sourceMappingURL=virtual-route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-route.d.ts","sourceRoot":"","sources":["../../src/route/virtual-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"virtual-route.d.ts","sourceRoot":"","sources":["../../src/route/virtual-route.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAkB,MAAM,gBAAgB,CAAC;AACzD,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,WAAW,EACX,KAAK,EACN,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,qBAAa,YAAY,CACvB,OAAO,SAAS,SAAS,GAAG,WAAW,GAAG,WAAW;IAMnD,OAAO,CAAC,gBAAgB,CAAC;IACzB,SAAS,CAAC,MAAM,EAAE,yBAAyB;IAL7C,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;gBAGN,gBAAgB,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,YAAA,EAChE,MAAM,GAAE,yBAA8B;IAalD,IAAI,QAAQ,YAKX;IAED,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC;IAI9C,IAAI,CACF,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,CAAC,SAAS,IAAI,GAChD,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,GAC5C,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,GACvC,IAAI;IASP,KAAK;CAGN"}
|
package/route/virtual-route.js
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
+
import { action, computed, makeObservable, observable } from 'mobx';
|
|
1
2
|
import { resolveFnValue } from 'yummies/common';
|
|
3
|
+
import { routeConfig } from './config.js';
|
|
2
4
|
export class VirtualRoute {
|
|
3
5
|
isOpenedResolver;
|
|
4
|
-
|
|
6
|
+
config;
|
|
7
|
+
query;
|
|
8
|
+
params;
|
|
9
|
+
constructor(isOpenedResolver, config = {}) {
|
|
5
10
|
this.isOpenedResolver = isOpenedResolver;
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.query = config.queryParams ?? routeConfig.get().queryParams;
|
|
13
|
+
this.params = {};
|
|
14
|
+
observable(this, 'params');
|
|
15
|
+
observable.ref(this, 'isOpenedResolver');
|
|
16
|
+
computed.struct(this, 'isOpened');
|
|
17
|
+
action(this, 'open');
|
|
18
|
+
action(this, 'close');
|
|
19
|
+
makeObservable(this);
|
|
6
20
|
}
|
|
7
21
|
get isOpened() {
|
|
8
|
-
return (this.isOpenedResolver != null &&
|
|
22
|
+
return (this.isOpenedResolver != null &&
|
|
23
|
+
resolveFnValue(this.isOpenedResolver, this.query.data));
|
|
9
24
|
}
|
|
10
25
|
setResolver(isOpenedResolver) {
|
|
11
26
|
this.isOpenedResolver = isOpenedResolver;
|
|
12
27
|
}
|
|
13
|
-
open() {
|
|
28
|
+
open(...args) {
|
|
29
|
+
this.params = args[0] ?? {};
|
|
30
|
+
if (args[1] != null) {
|
|
31
|
+
this.query.update(args[1]);
|
|
32
|
+
}
|
|
14
33
|
this.isOpenedResolver = true;
|
|
15
34
|
}
|
|
16
35
|
close() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-route.types.d.ts","sourceRoot":"","sources":["../../src/route/virtual-route.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,WAAW,yBAAyB;IACxC,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|