mobx-route 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/index.cjs +565 -17
- package/index.cjs.map +1 -0
- package/index.d.ts +423 -2
- package/index.js +561 -2
- package/index.js.map +1 -0
- package/package.json +20 -63
- package/react.cjs +170 -0
- package/react.cjs.map +1 -0
- package/react.d.ts +71 -0
- package/react.js +170 -0
- package/react.js.map +1 -0
- package/view-model.cjs +56 -0
- package/view-model.cjs.map +1 -0
- package/view-model.d.ts +14 -0
- package/view-model.js +56 -0
- package/view-model.js.map +1 -0
- package/core/config/config.cjs +0 -36
- package/core/config/config.d.cts +0 -7
- package/core/config/config.d.cts.map +0 -1
- package/core/config/config.d.ts +0 -7
- package/core/config/config.d.ts.map +0 -1
- package/core/config/config.js +0 -33
- package/core/config/config.types.cjs +0 -2
- package/core/config/config.types.d.cts +0 -11
- package/core/config/config.types.d.cts.map +0 -1
- package/core/config/config.types.d.ts +0 -11
- package/core/config/config.types.d.ts.map +0 -1
- package/core/config/config.types.js +0 -1
- package/core/config/index.cjs +0 -18
- package/core/config/index.d.cts +0 -3
- package/core/config/index.d.cts.map +0 -1
- package/core/config/index.d.ts +0 -3
- package/core/config/index.d.ts.map +0 -1
- package/core/config/index.js +0 -2
- package/core/index.cjs +0 -21
- package/core/index.d.cts +0 -6
- package/core/index.d.cts.map +0 -1
- package/core/index.d.ts +0 -6
- package/core/index.d.ts.map +0 -1
- package/core/index.js +0 -5
- package/core/route/index.cjs +0 -18
- package/core/route/index.d.cts +0 -3
- package/core/route/index.d.cts.map +0 -1
- package/core/route/index.d.ts +0 -3
- package/core/route/index.d.ts.map +0 -1
- package/core/route/index.js +0 -2
- package/core/route/route.cjs +0 -296
- package/core/route/route.d.cts +0 -107
- package/core/route/route.d.cts.map +0 -1
- package/core/route/route.d.ts +0 -107
- package/core/route/route.d.ts.map +0 -1
- package/core/route/route.js +0 -291
- package/core/route/route.types.cjs +0 -2
- package/core/route/route.types.d.cts +0 -142
- package/core/route/route.types.d.cts.map +0 -1
- package/core/route/route.types.d.ts +0 -142
- package/core/route/route.types.d.ts.map +0 -1
- package/core/route/route.types.js +0 -1
- package/core/route-group/index.cjs +0 -18
- package/core/route-group/index.d.cts +0 -3
- package/core/route-group/index.d.cts.map +0 -1
- package/core/route-group/index.d.ts +0 -3
- package/core/route-group/index.d.ts.map +0 -1
- package/core/route-group/index.js +0 -2
- package/core/route-group/route-group.cjs +0 -67
- package/core/route-group/route-group.d.cts +0 -31
- package/core/route-group/route-group.d.cts.map +0 -1
- package/core/route-group/route-group.d.ts +0 -31
- package/core/route-group/route-group.d.ts.map +0 -1
- package/core/route-group/route-group.js +0 -62
- package/core/route-group/route-group.types.cjs +0 -2
- package/core/route-group/route-group.types.d.cts +0 -15
- package/core/route-group/route-group.types.d.cts.map +0 -1
- package/core/route-group/route-group.types.d.ts +0 -15
- package/core/route-group/route-group.types.d.ts.map +0 -1
- package/core/route-group/route-group.types.js +0 -1
- package/core/router/index.cjs +0 -18
- package/core/router/index.d.cts +0 -3
- package/core/router/index.d.cts.map +0 -1
- package/core/router/index.d.ts +0 -3
- package/core/router/index.d.ts.map +0 -1
- package/core/router/index.js +0 -2
- package/core/router/router.cjs +0 -42
- package/core/router/router.d.cts +0 -18
- package/core/router/router.d.cts.map +0 -1
- package/core/router/router.d.ts +0 -18
- package/core/router/router.d.ts.map +0 -1
- package/core/router/router.js +0 -37
- package/core/router/router.types.cjs +0 -2
- package/core/router/router.types.d.cts +0 -13
- package/core/router/router.types.d.cts.map +0 -1
- package/core/router/router.types.d.ts +0 -13
- package/core/router/router.types.d.ts.map +0 -1
- package/core/router/router.types.js +0 -1
- package/core/utils/is-route-entity.cjs +0 -5
- package/core/utils/is-route-entity.d.cts +0 -3
- package/core/utils/is-route-entity.d.cts.map +0 -1
- package/core/utils/is-route-entity.d.ts +0 -3
- package/core/utils/is-route-entity.d.ts.map +0 -1
- package/core/utils/is-route-entity.js +0 -1
- package/core/virtual-route/index.cjs +0 -18
- package/core/virtual-route/index.d.cts +0 -3
- package/core/virtual-route/index.d.cts.map +0 -1
- package/core/virtual-route/index.d.ts +0 -3
- package/core/virtual-route/index.d.ts.map +0 -1
- package/core/virtual-route/index.js +0 -2
- package/core/virtual-route/virtual-route.cjs +0 -133
- package/core/virtual-route/virtual-route.d.cts +0 -39
- package/core/virtual-route/virtual-route.d.cts.map +0 -1
- package/core/virtual-route/virtual-route.d.ts +0 -39
- package/core/virtual-route/virtual-route.d.ts.map +0 -1
- package/core/virtual-route/virtual-route.js +0 -128
- package/core/virtual-route/virtual-route.types.cjs +0 -2
- package/core/virtual-route/virtual-route.types.d.cts +0 -61
- package/core/virtual-route/virtual-route.types.d.cts.map +0 -1
- package/core/virtual-route/virtual-route.types.d.ts +0 -61
- package/core/virtual-route/virtual-route.types.d.ts.map +0 -1
- package/core/virtual-route/virtual-route.types.js +0 -1
- package/index.d.cts +0 -3
- package/index.d.cts.map +0 -1
- package/index.d.ts.map +0 -1
- package/react/components/index.cjs +0 -21
- package/react/components/index.d.cts +0 -4
- package/react/components/index.d.cts.map +0 -1
- package/react/components/index.d.ts +0 -4
- package/react/components/index.d.ts.map +0 -1
- package/react/components/index.js +0 -5
- package/react/components/link.cjs +0 -79
- package/react/components/link.d.cts +0 -23
- package/react/components/link.d.cts.map +0 -1
- package/react/components/link.d.ts +0 -23
- package/react/components/link.d.ts.map +0 -1
- package/react/components/link.js +0 -76
- package/react/components/route-view-group.cjs +0 -57
- package/react/components/route-view-group.d.cts +0 -26
- package/react/components/route-view-group.d.cts.map +0 -1
- package/react/components/route-view-group.d.ts +0 -26
- package/react/components/route-view-group.d.ts.map +0 -1
- package/react/components/route-view-group.js +0 -54
- package/react/components/route-view.cjs +0 -43
- package/react/components/route-view.d.cts +0 -25
- package/react/components/route-view.d.cts.map +0 -1
- package/react/components/route-view.d.ts +0 -25
- package/react/components/route-view.d.ts.map +0 -1
- package/react/components/route-view.js +0 -40
- package/react/index.cjs +0 -17
- package/react/index.d.cts +0 -2
- package/react/index.d.cts.map +0 -1
- package/react/index.d.ts +0 -2
- package/react/index.d.ts.map +0 -1
- package/react/index.js +0 -1
- package/view-model/index.cjs +0 -17
- package/view-model/index.d.cts +0 -2
- package/view-model/index.d.cts.map +0 -1
- package/view-model/index.d.ts +0 -2
- package/view-model/index.d.ts.map +0 -1
- package/view-model/index.js +0 -1
- package/view-model/route-view-model.cjs +0 -37
- package/view-model/route-view-model.d.cts +0 -13
- package/view-model/route-view-model.d.cts.map +0 -1
- package/view-model/route-view-model.d.ts +0 -13
- package/view-model/route-view-model.d.ts.map +0 -1
- package/view-model/route-view-model.js +0 -33
package/view-model.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyAbstractRouteEntity, RouteParams, IQueryParams } from 'mobx-route';
|
|
2
|
+
import { ViewModelBase, ViewModelParams } from 'mobx-view-model';
|
|
3
|
+
import { EmptyObject } from 'yummies/types';
|
|
4
|
+
|
|
5
|
+
declare abstract class RouteViewModel<TRoute extends AnyAbstractRouteEntity = AnyAbstractRouteEntity> extends ViewModelBase<EmptyObject> {
|
|
6
|
+
abstract readonly route: TRoute;
|
|
7
|
+
constructor(params: ViewModelParams<EmptyObject, any>);
|
|
8
|
+
get payload(): RouteParams<TRoute>;
|
|
9
|
+
get query(): IQueryParams;
|
|
10
|
+
get pathParams(): RouteParams<TRoute>;
|
|
11
|
+
get isMounted(): boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { RouteViewModel };
|
package/view-model.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { computed, when, reaction } from "mobx";
|
|
2
|
+
import { Route, VirtualRoute, routeConfig } from "mobx-route";
|
|
3
|
+
import { ViewModelBase, applyObservable } from "mobx-view-model";
|
|
4
|
+
class RouteViewModel extends ViewModelBase {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
super(params);
|
|
7
|
+
applyObservable(
|
|
8
|
+
this,
|
|
9
|
+
[
|
|
10
|
+
["pathParams", computed.struct],
|
|
11
|
+
["query", computed]
|
|
12
|
+
],
|
|
13
|
+
this.vmConfig.observable.viewModels
|
|
14
|
+
);
|
|
15
|
+
when(
|
|
16
|
+
() => this.isMounted,
|
|
17
|
+
() => {
|
|
18
|
+
reaction(
|
|
19
|
+
() => this.route.isOpened,
|
|
20
|
+
(isOpened) => {
|
|
21
|
+
if (!isOpened && this.isMounted) {
|
|
22
|
+
this.unmount();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{ fireImmediately: true, signal: this.unmountSignal }
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
{ signal: this.unmountSignal }
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
get payload() {
|
|
32
|
+
if (this.route instanceof Route) {
|
|
33
|
+
return this.route.params || {};
|
|
34
|
+
}
|
|
35
|
+
if (this.route instanceof VirtualRoute) {
|
|
36
|
+
return this.route.params;
|
|
37
|
+
}
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
get query() {
|
|
41
|
+
if ("query" in this.route) {
|
|
42
|
+
return this.route.query;
|
|
43
|
+
}
|
|
44
|
+
return routeConfig.get().queryParams;
|
|
45
|
+
}
|
|
46
|
+
get pathParams() {
|
|
47
|
+
return this.payload;
|
|
48
|
+
}
|
|
49
|
+
get isMounted() {
|
|
50
|
+
return super.isMounted && this.route.isOpened;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
RouteViewModel
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=view-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-model.js","sources":["../src/view-model/route-view-model.ts"],"sourcesContent":["import { computed, reaction, when } from 'mobx';\nimport {\n type AnyAbstractRouteEntity,\n type IQueryParams,\n Route,\n type RouteParams,\n routeConfig,\n VirtualRoute,\n} from 'mobx-route';\nimport {\n applyObservable,\n ViewModelBase,\n type ViewModelParams,\n} from 'mobx-view-model';\nimport type { EmptyObject } from 'yummies/types';\n\nexport abstract class RouteViewModel<\n TRoute extends AnyAbstractRouteEntity = AnyAbstractRouteEntity,\n> extends ViewModelBase<EmptyObject> {\n abstract readonly route: TRoute;\n\n constructor(params: ViewModelParams<EmptyObject, any>) {\n super(params);\n\n applyObservable(\n this,\n [\n ['pathParams', computed.struct],\n ['query', computed],\n ],\n this.vmConfig.observable.viewModels,\n );\n\n when(\n () => this.isMounted,\n () => {\n reaction(\n () => this.route.isOpened,\n (isOpened) => {\n if (!isOpened && this.isMounted) {\n this.unmount();\n }\n },\n { fireImmediately: true, signal: this.unmountSignal },\n );\n },\n { signal: this.unmountSignal },\n );\n }\n\n override get payload(): RouteParams<TRoute> {\n if (this.route instanceof Route) {\n return this.route.params || ({} as any);\n }\n\n if (this.route instanceof VirtualRoute) {\n return this.route.params as any;\n }\n\n return {} as EmptyObject as any;\n }\n\n get query(): IQueryParams {\n if ('query' in this.route) {\n return this.route.query as IQueryParams;\n }\n\n return routeConfig.get().queryParams;\n }\n\n get pathParams() {\n return this.payload;\n }\n\n get isMounted() {\n return super.isMounted && this.route.isOpened;\n }\n}\n"],"names":[],"mappings":";;;AAgBO,MAAe,uBAEZ,cAA2B;AAAA,EAGnC,YAAY,QAA2C;AACrD,UAAM,MAAM;AAEZ;AAAA,MACE;AAAA,MACA;AAAA,QACE,CAAC,cAAc,SAAS,MAAM;AAAA,QAC9B,CAAC,SAAS,QAAQ;AAAA,MAAA;AAAA,MAEpB,KAAK,SAAS,WAAW;AAAA,IAAA;AAG3B;AAAA,MACE,MAAM,KAAK;AAAA,MACX,MAAM;AACJ;AAAA,UACE,MAAM,KAAK,MAAM;AAAA,UACjB,CAAC,aAAa;AACZ,gBAAI,CAAC,YAAY,KAAK,WAAW;AAC/B,mBAAK,QAAA;AAAA,YACP;AAAA,UACF;AAAA,UACA,EAAE,iBAAiB,MAAM,QAAQ,KAAK,cAAA;AAAA,QAAc;AAAA,MAExD;AAAA,MACA,EAAE,QAAQ,KAAK,cAAA;AAAA,IAAc;AAAA,EAEjC;AAAA,EAEA,IAAa,UAA+B;AAC1C,QAAI,KAAK,iBAAiB,OAAO;AAC/B,aAAO,KAAK,MAAM,UAAW,CAAA;AAAA,IAC/B;AAEA,QAAI,KAAK,iBAAiB,cAAc;AACtC,aAAO,KAAK,MAAM;AAAA,IACpB;AAEA,WAAO,CAAA;AAAA,EACT;AAAA,EAEA,IAAI,QAAsB;AACxB,QAAI,WAAW,KAAK,OAAO;AACzB,aAAO,KAAK,MAAM;AAAA,IACpB;AAEA,WAAO,YAAY,MAAM;AAAA,EAC3B;AAAA,EAEA,IAAI,aAAa;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAY;AACd,WAAO,MAAM,aAAa,KAAK,MAAM;AAAA,EACvC;AACF;"}
|
package/core/config/config.cjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.routeConfig = void 0;
|
|
4
|
-
const mobx_location_history_1 = require("mobx-location-history");
|
|
5
|
-
const complex_1 = require("yummies/complex");
|
|
6
|
-
let localHistory;
|
|
7
|
-
exports.routeConfig = (0, complex_1.createGlobalDynamicConfig)((update) => {
|
|
8
|
-
if (localHistory && update?.history && (0, mobx_location_history_1.isObservableHistory)(localHistory)) {
|
|
9
|
-
localHistory.destroy();
|
|
10
|
-
}
|
|
11
|
-
let history;
|
|
12
|
-
if (update?.history) {
|
|
13
|
-
history = update.history;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
history = localHistory = (0, mobx_location_history_1.createBrowserHistory)();
|
|
17
|
-
}
|
|
18
|
-
let queryParams;
|
|
19
|
-
if (update?.history && !update.queryParams) {
|
|
20
|
-
queryParams = new mobx_location_history_1.QueryParams({ history });
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
if (update?.queryParams) {
|
|
24
|
-
queryParams = update.queryParams;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
queryParams = new mobx_location_history_1.QueryParams({ history });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
...update,
|
|
32
|
-
history,
|
|
33
|
-
location,
|
|
34
|
-
queryParams,
|
|
35
|
-
};
|
|
36
|
-
});
|
package/core/config/config.d.cts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { RouteGlobalConfig } from "./config.types.cjs";
|
|
2
|
-
export declare const routeConfig: {
|
|
3
|
-
get: () => RouteGlobalConfig;
|
|
4
|
-
set: (value: RouteGlobalConfig | null | undefined) => RouteGlobalConfig | null | undefined;
|
|
5
|
-
update: (value: Partial<RouteGlobalConfig>) => void;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/core/config/config.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAA0B;AAI3D,eAAO,MAAM,WAAW;;;;CAiCvB,CAAC"}
|
package/core/config/config.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { RouteGlobalConfig } from "./config.types.js";
|
|
2
|
-
export declare const routeConfig: {
|
|
3
|
-
get: () => RouteGlobalConfig;
|
|
4
|
-
set: (value: RouteGlobalConfig | null | undefined) => RouteGlobalConfig | null | undefined;
|
|
5
|
-
update: (value: Partial<RouteGlobalConfig>) => void;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/core/config/config.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAA0B;AAI3D,eAAO,MAAM,WAAW;;;;CAiCvB,CAAC"}
|
package/core/config/config.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createBrowserHistory, isObservableHistory, QueryParams, } from 'mobx-location-history';
|
|
2
|
-
import { createGlobalDynamicConfig } from 'yummies/complex';
|
|
3
|
-
let localHistory;
|
|
4
|
-
export const routeConfig = createGlobalDynamicConfig((update) => {
|
|
5
|
-
if (localHistory && update?.history && isObservableHistory(localHistory)) {
|
|
6
|
-
localHistory.destroy();
|
|
7
|
-
}
|
|
8
|
-
let history;
|
|
9
|
-
if (update?.history) {
|
|
10
|
-
history = update.history;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
history = localHistory = createBrowserHistory();
|
|
14
|
-
}
|
|
15
|
-
let queryParams;
|
|
16
|
-
if (update?.history && !update.queryParams) {
|
|
17
|
-
queryParams = new QueryParams({ history });
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
if (update?.queryParams) {
|
|
21
|
-
queryParams = update.queryParams;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
queryParams = new QueryParams({ history });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
...update,
|
|
29
|
-
history,
|
|
30
|
-
location,
|
|
31
|
-
queryParams,
|
|
32
|
-
};
|
|
33
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { History, IQueryParams } from 'mobx-location-history';
|
|
2
|
-
import type { UrlCreateParamsFn } from "../route/index.cjs";
|
|
3
|
-
export interface RouteGlobalConfig {
|
|
4
|
-
history: History;
|
|
5
|
-
queryParams: IQueryParams;
|
|
6
|
-
baseUrl?: string;
|
|
7
|
-
mergeQuery?: boolean;
|
|
8
|
-
createUrl?: UrlCreateParamsFn;
|
|
9
|
-
formatLinkHref?: (href: string) => string;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=config.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.types.d.ts","sourceRoot":"","sources":["../../../src/core/config/config.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAA0B;AAE3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,YAAY,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { History, IQueryParams } from 'mobx-location-history';
|
|
2
|
-
import type { UrlCreateParamsFn } from "../route/index.js";
|
|
3
|
-
export interface RouteGlobalConfig {
|
|
4
|
-
history: History;
|
|
5
|
-
queryParams: IQueryParams;
|
|
6
|
-
baseUrl?: string;
|
|
7
|
-
mergeQuery?: boolean;
|
|
8
|
-
createUrl?: UrlCreateParamsFn;
|
|
9
|
-
formatLinkHref?: (href: string) => string;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=config.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.types.d.ts","sourceRoot":"","sources":["../../../src/core/config/config.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAA0B;AAE3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,YAAY,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/core/config/index.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./config.cjs"), exports);
|
|
18
|
-
__exportStar(require("./config.types.cjs"), exports);
|
package/core/config/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA,6BAA4B;AAC5B,mCAAkC"}
|
package/core/config/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,kCAAkC"}
|
package/core/config/index.js
DELETED
package/core/index.cjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./config/index.cjs"), exports);
|
|
18
|
-
__exportStar(require("./route/index.cjs"), exports);
|
|
19
|
-
__exportStar(require("./route-group/index.cjs"), exports);
|
|
20
|
-
__exportStar(require("./router/index.cjs"), exports);
|
|
21
|
-
__exportStar(require("./virtual-route/index.cjs"), exports);
|
package/core/index.d.cts
DELETED
package/core/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,mCAAkC;AAClC,kCAAiC;AACjC,wCAAuC;AACvC,mCAAkC;AAClC,0CAAyC"}
|
package/core/index.d.ts
DELETED
package/core/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,iCAAiC;AACjC,uCAAuC;AACvC,kCAAkC;AAClC,yCAAyC"}
|
package/core/index.js
DELETED
package/core/route/index.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./route.cjs"), exports);
|
|
18
|
-
__exportStar(require("./route.types.cjs"), exports);
|
package/core/route/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/route/index.ts"],"names":[],"mappings":"AAAA,4BAA2B;AAC3B,kCAAiC"}
|
package/core/route/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/route/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,iCAAiC"}
|
package/core/route/index.js
DELETED
package/core/route/route.cjs
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRoute = exports.Route = void 0;
|
|
4
|
-
const linked_abort_controller_1 = require("linked-abort-controller");
|
|
5
|
-
const mobx_1 = require("mobx");
|
|
6
|
-
const mobx_location_history_1 = require("mobx-location-history");
|
|
7
|
-
const path_to_regexp_1 = require("path-to-regexp");
|
|
8
|
-
const index_js_1 = require("../config/index.cjs");
|
|
9
|
-
/**
|
|
10
|
-
* Class for creating path based route.
|
|
11
|
-
*
|
|
12
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html)
|
|
13
|
-
*/
|
|
14
|
-
class Route {
|
|
15
|
-
path;
|
|
16
|
-
config;
|
|
17
|
-
abortController;
|
|
18
|
-
history;
|
|
19
|
-
parent;
|
|
20
|
-
query;
|
|
21
|
-
_tokenData;
|
|
22
|
-
_matcher;
|
|
23
|
-
_compiler;
|
|
24
|
-
reactionDisposer;
|
|
25
|
-
meta;
|
|
26
|
-
/**
|
|
27
|
-
* Indicates if this route is an index route. Index routes activate when parent route path matches exactly.
|
|
28
|
-
*
|
|
29
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isindex-boolean)
|
|
30
|
-
*/
|
|
31
|
-
isIndex;
|
|
32
|
-
/**
|
|
33
|
-
* Indicates if this route is an hash route.
|
|
34
|
-
*
|
|
35
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#ishash-boolean)
|
|
36
|
-
*/
|
|
37
|
-
isHash;
|
|
38
|
-
children = [];
|
|
39
|
-
constructor(path, config = {}) {
|
|
40
|
-
this.path = path;
|
|
41
|
-
this.config = config;
|
|
42
|
-
this.abortController = new linked_abort_controller_1.LinkedAbortController(config.abortSignal);
|
|
43
|
-
this.history = config.history ?? index_js_1.routeConfig.get().history;
|
|
44
|
-
this.query = config.queryParams ?? index_js_1.routeConfig.get().queryParams;
|
|
45
|
-
this.isIndex = !!this.config.index;
|
|
46
|
-
this.isHash = !!this.config.hash;
|
|
47
|
-
this.meta = this.config.meta;
|
|
48
|
-
this.parent = config.parent ?? null;
|
|
49
|
-
mobx_1.computed.struct(this, 'isOpened');
|
|
50
|
-
mobx_1.computed.struct(this, 'data');
|
|
51
|
-
mobx_1.computed.struct(this, 'params');
|
|
52
|
-
mobx_1.computed.struct(this, 'currentPath');
|
|
53
|
-
mobx_1.computed.struct(this, 'hasOpenedChildren');
|
|
54
|
-
mobx_1.computed.struct(this, 'isAbleToMergeQuery');
|
|
55
|
-
(0, mobx_1.computed)(this, 'baseUrl');
|
|
56
|
-
(0, mobx_1.observable)(this, 'children');
|
|
57
|
-
mobx_1.observable.ref(this, 'parent');
|
|
58
|
-
(0, mobx_1.action)(this, 'addChildren');
|
|
59
|
-
(0, mobx_1.action)(this, 'removeChildren');
|
|
60
|
-
(0, mobx_1.makeObservable)(this);
|
|
61
|
-
(0, mobx_1.onBecomeObserved)(this, 'isOpened', () => {
|
|
62
|
-
if (!config.afterOpen && !config.afterClose) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
this.reactionDisposer = (0, mobx_1.reaction)(() => this.isOpened, this.processOpenedState, {
|
|
66
|
-
signal: this.abortController.signal,
|
|
67
|
-
fireImmediately: true,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
(0, mobx_1.onBecomeUnobserved)(this, 'isOpened', () => {
|
|
71
|
-
this.reactionDisposer?.();
|
|
72
|
-
this.reactionDisposer = undefined;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
get baseUrl() {
|
|
76
|
-
const baseUrl = this.config.baseUrl ?? index_js_1.routeConfig.get().baseUrl;
|
|
77
|
-
return baseUrl?.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
78
|
-
}
|
|
79
|
-
get parsedPathData() {
|
|
80
|
-
let pathnameToCheck;
|
|
81
|
-
if (this.isHash) {
|
|
82
|
-
pathnameToCheck = this.history.location.hash.slice(1);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
pathnameToCheck = this.history.location.pathname;
|
|
86
|
-
}
|
|
87
|
-
if (this.baseUrl) {
|
|
88
|
-
if (!this.history.location.pathname.startsWith(this.baseUrl)) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
pathnameToCheck = pathnameToCheck.replace(this.baseUrl, '');
|
|
92
|
-
}
|
|
93
|
-
if ((this.path === '' || this.path === '/') &&
|
|
94
|
-
(pathnameToCheck === '/' || pathnameToCheck === '')) {
|
|
95
|
-
return { params: {}, path: pathnameToCheck };
|
|
96
|
-
}
|
|
97
|
-
this._matcher ??= (0, path_to_regexp_1.match)(this.tokenData);
|
|
98
|
-
const parsed = this._matcher(pathnameToCheck);
|
|
99
|
-
if (parsed === false) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
return parsed;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Matched path segment for current URL.
|
|
106
|
-
*
|
|
107
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#currentpath-parsedpathname-null)
|
|
108
|
-
*/
|
|
109
|
-
get currentPath() {
|
|
110
|
-
return this.parsedPathData?.path ?? null;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Current parsed path parameters.
|
|
114
|
-
*
|
|
115
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params-parsedpathparams-null)
|
|
116
|
-
*/
|
|
117
|
-
get params() {
|
|
118
|
-
if (!this.parsedPathData?.params) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
let params = this.parsedPathData?.params ?? null;
|
|
122
|
-
if (this.config.params) {
|
|
123
|
-
const result = this.config.params(this.parsedPathData.params, this.config.meta);
|
|
124
|
-
if (result) {
|
|
125
|
-
params = result;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return params;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Defines the "open" state for this route.
|
|
135
|
-
*
|
|
136
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopened-boolean)
|
|
137
|
-
*/
|
|
138
|
-
get isOpened() {
|
|
139
|
-
if (this.params === null || this.parsedPathData === null) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
return (!this.config.checkOpened || this.config.checkOpened(this.parsedPathData));
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Allows to create child route based on this route with merging this route path and extending path.
|
|
146
|
-
*
|
|
147
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend-path-config-route)
|
|
148
|
-
*/
|
|
149
|
-
extend(path, config) {
|
|
150
|
-
// biome-ignore lint/correctness/noUnusedVariables: this is need to extract unused fields
|
|
151
|
-
const { index, params, ...configFromCurrentRoute } = this.config;
|
|
152
|
-
const extendedChild = new Route(`${this.path}${path}`, {
|
|
153
|
-
...configFromCurrentRoute,
|
|
154
|
-
...config,
|
|
155
|
-
parent: this,
|
|
156
|
-
});
|
|
157
|
-
this.addChildren(extendedChild);
|
|
158
|
-
return extendedChild;
|
|
159
|
-
}
|
|
160
|
-
addChildren(...routes) {
|
|
161
|
-
this.children.push(...routes);
|
|
162
|
-
}
|
|
163
|
-
removeChildren(...routes) {
|
|
164
|
-
this.children = this.children.filter((child) => !routes.includes(child));
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren-boolean)
|
|
168
|
-
*/
|
|
169
|
-
get hasOpenedChildren() {
|
|
170
|
-
return this.children.some((child) => child.isOpened || child.hasOpenedChildren);
|
|
171
|
-
}
|
|
172
|
-
processParams(params) {
|
|
173
|
-
if (params == null)
|
|
174
|
-
return undefined;
|
|
175
|
-
return Object.entries(params).reduce((acc, [key, value]) => {
|
|
176
|
-
if (value != null) {
|
|
177
|
-
acc[key] = Array.isArray(value) ? value.map(String) : String(value);
|
|
178
|
-
}
|
|
179
|
-
return acc;
|
|
180
|
-
}, {});
|
|
181
|
-
}
|
|
182
|
-
createUrl(...args) {
|
|
183
|
-
const params = args[0];
|
|
184
|
-
const rawQuery = args[1];
|
|
185
|
-
const mergeQueryOrOutputParams = args[2] ?? this.isAbleToMergeQuery;
|
|
186
|
-
const outputParams = typeof mergeQueryOrOutputParams === 'boolean'
|
|
187
|
-
? { mergeQuery: mergeQueryOrOutputParams }
|
|
188
|
-
: mergeQueryOrOutputParams;
|
|
189
|
-
const query = outputParams?.mergeQuery
|
|
190
|
-
? { ...this.query.data, ...rawQuery }
|
|
191
|
-
: (rawQuery ?? {});
|
|
192
|
-
this._compiler ??= (0, path_to_regexp_1.compile)(this.tokenData);
|
|
193
|
-
const defaultUrlCreateParams = {
|
|
194
|
-
baseUrl: this.baseUrl,
|
|
195
|
-
params: params,
|
|
196
|
-
query,
|
|
197
|
-
};
|
|
198
|
-
const urlCreateParams = this.config.createUrl?.(defaultUrlCreateParams, this.query.data) ??
|
|
199
|
-
index_js_1.routeConfig.get().createUrl?.(defaultUrlCreateParams, this.query.data) ??
|
|
200
|
-
defaultUrlCreateParams;
|
|
201
|
-
const path = this._compiler(this.processParams(urlCreateParams.params));
|
|
202
|
-
const url = [urlCreateParams.baseUrl, this.isHash ? '#' : '', path].join('');
|
|
203
|
-
if (outputParams?.omitQuery) {
|
|
204
|
-
return url;
|
|
205
|
-
}
|
|
206
|
-
return `${url}${(0, mobx_location_history_1.buildSearchString)(urlCreateParams.query)}`;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Navigates to this route.
|
|
210
|
-
*
|
|
211
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open-args)
|
|
212
|
-
*/
|
|
213
|
-
async open(...args) {
|
|
214
|
-
const { replace, state: rawState, query: rawQuery, mergeQuery: rawMergeQuery, } = typeof args[1] === 'boolean' || args.length > 2
|
|
215
|
-
? { replace: args[1], query: args[2] }
|
|
216
|
-
: (args[1] ?? {});
|
|
217
|
-
let url;
|
|
218
|
-
let params;
|
|
219
|
-
const mergeQuery = rawMergeQuery ?? this.isAbleToMergeQuery;
|
|
220
|
-
const query = mergeQuery ? { ...this.query.data, ...rawQuery } : rawQuery;
|
|
221
|
-
if (typeof args[0] === 'string') {
|
|
222
|
-
url = args[0];
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
params = args[0];
|
|
226
|
-
url = this.createUrl(args[0], query);
|
|
227
|
-
}
|
|
228
|
-
const state = rawState ?? null;
|
|
229
|
-
const navigationData = {
|
|
230
|
-
url,
|
|
231
|
-
params: params,
|
|
232
|
-
replace,
|
|
233
|
-
state,
|
|
234
|
-
query,
|
|
235
|
-
};
|
|
236
|
-
const feedback = await this.beforeOpen(navigationData);
|
|
237
|
-
if (feedback === false) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (typeof feedback === 'object') {
|
|
241
|
-
Object.assign(navigationData, feedback);
|
|
242
|
-
}
|
|
243
|
-
if (replace) {
|
|
244
|
-
this.history.replace(url, state);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
this.history.push(url, state);
|
|
248
|
-
}
|
|
249
|
-
if (!this.reactionDisposer && this.isOpened) {
|
|
250
|
-
this.config.afterOpen?.(this.parsedPathData, this);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
beforeOpen(openData) {
|
|
254
|
-
if (this.config.beforeOpen) {
|
|
255
|
-
return this.config.beforeOpen(openData);
|
|
256
|
-
}
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
afterClose() {
|
|
260
|
-
if (this.config.afterClose) {
|
|
261
|
-
return this.config.afterClose();
|
|
262
|
-
}
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
265
|
-
get tokenData() {
|
|
266
|
-
if (!this._tokenData) {
|
|
267
|
-
this._tokenData = (0, path_to_regexp_1.parse)(this.path, this.config.parseOptions);
|
|
268
|
-
}
|
|
269
|
-
return this._tokenData;
|
|
270
|
-
}
|
|
271
|
-
firstOpenedStateCheck = true;
|
|
272
|
-
processOpenedState = (isOpened) => {
|
|
273
|
-
if (this.firstOpenedStateCheck) {
|
|
274
|
-
this.firstOpenedStateCheck = false;
|
|
275
|
-
// ignore first 'afterClose' callback call
|
|
276
|
-
if (!isOpened) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (isOpened) {
|
|
281
|
-
this.config.afterOpen?.(this.parsedPathData, this);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
this.config.afterClose?.();
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
get isAbleToMergeQuery() {
|
|
288
|
-
return this.config.mergeQuery ?? index_js_1.routeConfig.get().mergeQuery;
|
|
289
|
-
}
|
|
290
|
-
destroy() {
|
|
291
|
-
this.abortController.abort();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
exports.Route = Route;
|
|
295
|
-
const createRoute = (path, config) => new Route(path, config);
|
|
296
|
-
exports.createRoute = createRoute;
|