mobx-route 1.2.3 → 1.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/index.cjs +10 -737
- package/index.cjs.map +1 -1
- package/index.d.ts +34 -0
- package/index.js +10 -738
- package/index.js.map +1 -1
- package/package.json +9 -1
- package/view-model.cjs +58 -43
- package/view-model.cjs.map +1 -1
- package/view-model.d.ts +383 -21
- package/view-model.js +59 -44
- package/view-model.js.map +1 -1
- package/virtual-route-CFGwOGHi.cjs +832 -0
- package/virtual-route-CFGwOGHi.cjs.map +1 -0
- package/virtual-route-fZzKp_7K.js +833 -0
- package/virtual-route-fZzKp_7K.js.map +1 -0
package/view-model.d.ts
CHANGED
|
@@ -1,39 +1,401 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ViewModelBase,
|
|
3
|
-
import
|
|
1
|
+
import * as mobx_view_model from 'mobx-view-model';
|
|
2
|
+
import { ViewModelBase, ViewModel } from 'mobx-view-model';
|
|
3
|
+
import * as yummies_types from 'yummies/types';
|
|
4
|
+
import { AnyObject, EmptyObject, IsPartial, Maybe, MaybePromise, Class } from 'yummies/types';
|
|
5
|
+
import { RawQueryParamsData, History, IQueryParams } from 'mobx-location-history';
|
|
6
|
+
import { ParseOptions, MatchOptions, ParamData, TokenData } from 'path-to-regexp';
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
interface VirtualOpenExtraParams extends Omit<RouteNavigateParams, 'state' | 'mergeQuery'> {
|
|
9
|
+
}
|
|
10
|
+
interface AbstractVirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject> {
|
|
11
|
+
isOpened: boolean;
|
|
12
|
+
isOpening: boolean;
|
|
13
|
+
params: TParams | null;
|
|
6
14
|
/**
|
|
7
|
-
*
|
|
15
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#open)
|
|
16
|
+
*/
|
|
17
|
+
open(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>, extraParams?: VirtualOpenExtraParams] : [params: TParams, extraParams?: VirtualOpenExtraParams]): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface AbstractRouteGroup<TRoutesCollection extends RoutesCollection = RoutesCollection> {
|
|
21
|
+
routes: TRoutesCollection;
|
|
22
|
+
isOpened: boolean;
|
|
23
|
+
}
|
|
24
|
+
type AnyAbstractRoute = AnyRoute | AbstractVirtualRoute<any>;
|
|
25
|
+
type AnyAbstractRouteEntity = AnyAbstractRoute | AbstractRouteGroup;
|
|
26
|
+
type RoutesArrayCollection = AnyAbstractRouteEntity[];
|
|
27
|
+
type RoutesObjectCollection = Record<string, AnyAbstractRouteEntity>;
|
|
28
|
+
type RoutesCollection = RoutesArrayCollection | RoutesObjectCollection;
|
|
29
|
+
|
|
30
|
+
type NavigationTrx<TParams extends AnyObject = AnyObject> = {
|
|
31
|
+
state?: any;
|
|
32
|
+
/**
|
|
33
|
+
* path parameters
|
|
8
34
|
*
|
|
9
|
-
*
|
|
35
|
+
* can be received from extended routes
|
|
10
36
|
*/
|
|
11
|
-
|
|
37
|
+
params?: TParams;
|
|
38
|
+
url: string;
|
|
39
|
+
replace?: boolean;
|
|
40
|
+
query?: AnyObject;
|
|
41
|
+
preferSkipHistoryUpdate?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Returning `false` means ignore navigation
|
|
45
|
+
*/
|
|
46
|
+
type BeforeOpenFeedback = void | boolean | Pick<NavigationTrx, 'url' | 'state' | 'replace'>;
|
|
47
|
+
interface UrlCreateParams<TInputParams> {
|
|
48
|
+
baseUrl?: string | undefined;
|
|
49
|
+
params: TInputParams;
|
|
50
|
+
query: AnyObject;
|
|
51
|
+
}
|
|
52
|
+
type UrlCreateParamsFn<TInputParams = any> = (params: UrlCreateParams<TInputParams>, currentQueryData: RawQueryParamsData) => Maybe<UrlCreateParams<TInputParams>>;
|
|
53
|
+
/**
|
|
54
|
+
* Output options for `createUrl()` (third argument).
|
|
55
|
+
* @see [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl)
|
|
56
|
+
*/
|
|
57
|
+
interface CreatedUrlOutputParams {
|
|
58
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl) */
|
|
59
|
+
mergeQuery?: boolean;
|
|
60
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl) */
|
|
61
|
+
omitQuery?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface RouteConfiguration<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<string, any, any, any> | null = null> extends Omit<Partial<RouteGlobalConfig>, 'createUrl'> {
|
|
64
|
+
/**
|
|
65
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#abortsignal)
|
|
66
|
+
*/
|
|
67
|
+
abortSignal?: AbortSignal;
|
|
68
|
+
index?: boolean;
|
|
69
|
+
hash?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Exact match for the path
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
exact?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#meta)
|
|
77
|
+
*/
|
|
78
|
+
meta?: AnyObject;
|
|
79
|
+
parseOptions?: ParseOptions;
|
|
80
|
+
matchOptions?: MatchOptions & ParseOptions;
|
|
81
|
+
parent?: TParentRoute;
|
|
82
|
+
children?: AnyRoute[];
|
|
83
|
+
/**
|
|
84
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params)
|
|
85
|
+
*/
|
|
86
|
+
params?: (params: ParsedPathParams<TPath>, meta: AnyObject | undefined) => TOutputParams | null | false;
|
|
87
|
+
/**
|
|
88
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#checkopened)
|
|
89
|
+
*/
|
|
90
|
+
checkOpened?: (parsedPathData: ParsedPathData<NoInfer<TPath>>) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#beforeopen)
|
|
93
|
+
*/
|
|
94
|
+
beforeOpen?: (navigationTransaction: NavigationTrx<NoInfer<TInputParams>>) => MaybePromise<BeforeOpenFeedback>;
|
|
95
|
+
/**
|
|
96
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afterclose)
|
|
97
|
+
*/
|
|
98
|
+
afterClose?: () => void;
|
|
12
99
|
/**
|
|
13
|
-
*
|
|
100
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afteropen)
|
|
14
101
|
*/
|
|
15
|
-
|
|
16
|
-
constructor(params: ViewModelParams<EmptyObject, any>);
|
|
102
|
+
afterOpen?: (data: ParsedPathData<NoInfer<TPath>>, route: Route<NoInfer<TPath>, NoInfer<TInputParams>, NoInfer<TOutputParams>, NoInfer<TParentRoute>>) => void;
|
|
17
103
|
/**
|
|
18
|
-
*
|
|
104
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afterupdate)
|
|
19
105
|
*/
|
|
20
|
-
|
|
106
|
+
afterUpdate?: (data: ParsedPathData<NoInfer<TPath>>, route: Route<NoInfer<TPath>, NoInfer<TInputParams>, NoInfer<TOutputParams>, NoInfer<TParentRoute>>) => void;
|
|
21
107
|
/**
|
|
22
|
-
*
|
|
108
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl)
|
|
109
|
+
*/
|
|
110
|
+
createUrl?: UrlCreateParamsFn<TInputParams>;
|
|
111
|
+
}
|
|
112
|
+
type AnyRoute = Route<any, any, any, any>;
|
|
113
|
+
type InputPathParam = string | number | boolean | null;
|
|
114
|
+
type ParsedPathParam = string;
|
|
115
|
+
type Simplify<T> = T extends infer U ? {
|
|
116
|
+
[K in keyof U]: U[K];
|
|
117
|
+
} : never;
|
|
118
|
+
type RouteParams<TRoute extends AnyAbstractRouteEntity> = TRoute extends {
|
|
119
|
+
pathDeclaration: string;
|
|
120
|
+
} ? ParsedPathParams<TRoute['pathDeclaration']> : TRoute extends {
|
|
121
|
+
params: infer TParams;
|
|
122
|
+
} ? Exclude<TParams, null> : AnyObject;
|
|
123
|
+
type PathToObject<Path extends string, PropertyValue = string> = Simplify<Path extends `${infer Prefix}{${infer Optional}}${infer Suffix}` ? PathToObject<`${Prefix}${Suffix}`, PropertyValue> & Partial<PathToObject<Optional, PropertyValue>> : Path extends `${infer PartA}/${infer PartB}` ? PathToObject<PartA, PropertyValue> & PathToObject<PartB, PropertyValue> : Path extends `:${infer Param}?` ? {
|
|
124
|
+
[K in Param]?: PropertyValue;
|
|
125
|
+
} : Path extends `:${infer Param}` ? {
|
|
126
|
+
[K in Param]: PropertyValue;
|
|
127
|
+
} : Path extends `*${infer Wildcard}` ? {
|
|
128
|
+
[K in Wildcard]: PropertyValue[];
|
|
129
|
+
} : {}>;
|
|
130
|
+
type ParsedPathParams<Path extends string> = PathToObject<Path, ParsedPathParam>;
|
|
131
|
+
type InputPathParams<Path extends string> = PathToObject<Path, InputPathParam>;
|
|
132
|
+
interface RouteNavigateParams {
|
|
133
|
+
replace?: boolean;
|
|
134
|
+
state?: any;
|
|
135
|
+
query?: AnyObject;
|
|
136
|
+
mergeQuery?: boolean;
|
|
137
|
+
}
|
|
138
|
+
interface ParsedPathData<TPath extends string> {
|
|
139
|
+
path: string;
|
|
140
|
+
params: ParsedPathParams<TPath>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Class for creating path based route.
|
|
145
|
+
*
|
|
146
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html)
|
|
147
|
+
*/
|
|
148
|
+
declare class Route<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<any, any, any, any> | null = null> {
|
|
149
|
+
protected config: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>;
|
|
150
|
+
private isDestroyed?;
|
|
151
|
+
private disposer?;
|
|
152
|
+
protected history: History;
|
|
153
|
+
/**
|
|
154
|
+
* Parent route.
|
|
23
155
|
*
|
|
24
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/
|
|
156
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#parent)
|
|
25
157
|
*/
|
|
26
|
-
|
|
158
|
+
parent: TParentRoute;
|
|
159
|
+
query: IQueryParams;
|
|
160
|
+
private _tokenData;
|
|
161
|
+
private _matcher?;
|
|
162
|
+
private _compiler?;
|
|
163
|
+
private ignoreOpenByPathMatch;
|
|
164
|
+
private isUpdate;
|
|
165
|
+
private updateDisposer?;
|
|
166
|
+
protected status: 'opening' | 'closed' | 'open-rejected' | 'open-confirmed' | 'unknown';
|
|
167
|
+
meta?: AnyObject;
|
|
27
168
|
/**
|
|
28
|
-
*
|
|
169
|
+
* Route path pattern declaration.
|
|
29
170
|
*
|
|
30
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/
|
|
171
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#pathdeclaration)
|
|
31
172
|
*/
|
|
32
|
-
|
|
173
|
+
pathDeclaration: TPath;
|
|
33
174
|
/**
|
|
34
|
-
*
|
|
175
|
+
* Indicates if this route is an index route. Index routes activate when parent route path matches exactly.
|
|
176
|
+
*
|
|
177
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isindex)
|
|
35
178
|
*/
|
|
36
|
-
|
|
179
|
+
isIndex: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Indicates if this route is an hash route.
|
|
182
|
+
*
|
|
183
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#ishash)
|
|
184
|
+
*/
|
|
185
|
+
isHash: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Array of child routes.
|
|
188
|
+
*
|
|
189
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#children)
|
|
190
|
+
*/
|
|
191
|
+
children: AnyRoute[];
|
|
192
|
+
constructor(pathDeclaration: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>);
|
|
193
|
+
protected get baseUrl(): string | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Checks whether current route matches provided path.
|
|
196
|
+
*
|
|
197
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#matchpath)
|
|
198
|
+
*/
|
|
199
|
+
matchPath(path?: Maybe<string>): ParsedPathData<TPath> | null;
|
|
200
|
+
protected get parsedPathData(): ParsedPathData<TPath> | null;
|
|
201
|
+
/**
|
|
202
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopening)
|
|
203
|
+
*
|
|
204
|
+
* Also true in the short gap after history already matches this route but
|
|
205
|
+
* `confirmOpening` has not started yet (e.g. browser Back) — otherwise every
|
|
206
|
+
* route looks closed for one tick and RouteViewGroup unmounts the page.
|
|
207
|
+
*/
|
|
208
|
+
get isOpening(): boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Matched path segment for current URL.
|
|
211
|
+
*
|
|
212
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#path)
|
|
213
|
+
*/
|
|
214
|
+
get path(): string | null;
|
|
215
|
+
/**
|
|
216
|
+
* Matched path segment for current URL with base URL.
|
|
217
|
+
*
|
|
218
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#absolutepath)
|
|
219
|
+
*/
|
|
220
|
+
get absolutePath(): string | null;
|
|
221
|
+
/**
|
|
222
|
+
* Current parsed path parameters.
|
|
223
|
+
*
|
|
224
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params)
|
|
225
|
+
*/
|
|
226
|
+
get params(): TOutputParams | null;
|
|
227
|
+
protected get isPathMatched(): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Defines the "open" state for this route.
|
|
230
|
+
*
|
|
231
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopened)
|
|
232
|
+
*/
|
|
233
|
+
get isOpened(): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Allows to create child route based on this route with merging this route path and extending path.
|
|
236
|
+
*
|
|
237
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend)
|
|
238
|
+
*/
|
|
239
|
+
extend<TExtendedPath extends string, TExtendedInputParams extends InputPathParams<`${TPath}${TExtendedPath}`> = InputPathParams<`${TPath}${TExtendedPath}`>, TExtendedOutputParams extends AnyObject = TInputParams & ParsedPathParams<`${TPath}${TExtendedPath}`>>(pathDeclaration: TExtendedPath, config?: Omit<RouteConfiguration<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, any>, 'parent'>): Route<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, this>;
|
|
240
|
+
/**
|
|
241
|
+
* Manually add child routes.
|
|
242
|
+
*
|
|
243
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#addchildren)
|
|
244
|
+
*/
|
|
245
|
+
addChildren(...routes: AnyRoute[]): void;
|
|
246
|
+
/**
|
|
247
|
+
* Remove specified routes from children.
|
|
248
|
+
*
|
|
249
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#removechildren)
|
|
250
|
+
*/
|
|
251
|
+
removeChildren(...routes: AnyRoute[]): void;
|
|
252
|
+
/**
|
|
253
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren)
|
|
254
|
+
*/
|
|
255
|
+
get hasOpenedChildren(): boolean;
|
|
256
|
+
protected processParams(params?: TInputParams | null | undefined): ParamData | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Generates full route URL.
|
|
259
|
+
*
|
|
260
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl)
|
|
261
|
+
*/
|
|
262
|
+
createUrl(...args: IsPartial<TInputParams> extends true ? [
|
|
263
|
+
params?: Maybe<TInputParams>,
|
|
264
|
+
query?: Maybe<AnyObject>,
|
|
265
|
+
mergeQueryOrParams?: boolean | CreatedUrlOutputParams
|
|
266
|
+
] : [
|
|
267
|
+
params: TInputParams,
|
|
268
|
+
query?: Maybe<AnyObject>,
|
|
269
|
+
mergeQueryOrParams?: boolean | CreatedUrlOutputParams
|
|
270
|
+
]): string;
|
|
271
|
+
/**
|
|
272
|
+
* Navigates to this route.
|
|
273
|
+
*
|
|
274
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open)
|
|
275
|
+
*/
|
|
276
|
+
open(...args: IsPartial<TInputParams> extends true ? [
|
|
277
|
+
params?: TInputParams | null | undefined,
|
|
278
|
+
navigateParams?: RouteNavigateParams
|
|
279
|
+
] : [params: TInputParams, navigateParams?: RouteNavigateParams]): Promise<void>;
|
|
280
|
+
open(...args: IsPartial<TInputParams> extends true ? [
|
|
281
|
+
params?: TInputParams | null | undefined,
|
|
282
|
+
replace?: RouteNavigateParams['replace'],
|
|
283
|
+
query?: RouteNavigateParams['query']
|
|
284
|
+
] : [
|
|
285
|
+
params: TInputParams,
|
|
286
|
+
replace?: RouteNavigateParams['replace'],
|
|
287
|
+
query?: RouteNavigateParams['query']
|
|
288
|
+
]): Promise<void>;
|
|
289
|
+
open(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
|
|
290
|
+
open(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* Updates the current route if it is already open.
|
|
293
|
+
* Unlike `open`, this is a no-op if the route is not open,
|
|
294
|
+
* and defaults to `replace: true` instead of push.
|
|
295
|
+
*
|
|
296
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#update)
|
|
297
|
+
*/
|
|
298
|
+
update(...args: IsPartial<TInputParams> extends true ? [
|
|
299
|
+
params?: TInputParams | null | undefined,
|
|
300
|
+
navigateParams?: RouteNavigateParams
|
|
301
|
+
] : [params: TInputParams, navigateParams?: RouteNavigateParams]): Promise<void>;
|
|
302
|
+
update(...args: IsPartial<TInputParams> extends true ? [
|
|
303
|
+
params?: TInputParams | null | undefined,
|
|
304
|
+
replace?: RouteNavigateParams['replace'],
|
|
305
|
+
query?: RouteNavigateParams['query']
|
|
306
|
+
] : [
|
|
307
|
+
params: TInputParams,
|
|
308
|
+
replace?: RouteNavigateParams['replace'],
|
|
309
|
+
query?: RouteNavigateParams['query']
|
|
310
|
+
]): Promise<void>;
|
|
311
|
+
update(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
|
|
312
|
+
update(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
|
|
313
|
+
protected get tokenData(): TokenData;
|
|
314
|
+
protected confirmOpening(trx: NavigationTrx<TInputParams>): Promise<true | undefined>;
|
|
315
|
+
protected confirmClosing(): boolean;
|
|
316
|
+
private firstPathMatchingRun;
|
|
317
|
+
private checkPathMatch;
|
|
318
|
+
private get isAbleToMergeQuery();
|
|
319
|
+
/**
|
|
320
|
+
* Destroys route subscriptions and reactions.
|
|
321
|
+
*
|
|
322
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#destroy)
|
|
323
|
+
*/
|
|
324
|
+
destroy(): void;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Global configuration for routes and router.
|
|
329
|
+
* @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html)
|
|
330
|
+
*/
|
|
331
|
+
interface RouteGlobalConfig {
|
|
332
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html#history) */
|
|
333
|
+
history: History;
|
|
334
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html#queryparams) */
|
|
335
|
+
queryParams: IQueryParams;
|
|
336
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html#baseurl) */
|
|
337
|
+
baseUrl?: string;
|
|
338
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html#mergequery) */
|
|
339
|
+
mergeQuery?: boolean;
|
|
340
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html#createurl) */
|
|
341
|
+
createUrl?: UrlCreateParamsFn;
|
|
342
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html#formatlinkhref) */
|
|
343
|
+
formatLinkHref?: (href: string) => string;
|
|
344
|
+
/** @see [**Documentation**](https://js2me.github.io/mobx-route/core/routeConfig.html#fallbackpath) */
|
|
345
|
+
fallbackPath?: string;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Public interface added by `withRouteViewModel` mixin.
|
|
350
|
+
*/
|
|
351
|
+
type RouteViewModelMixinPublic<TRoute extends AnyAbstractRouteEntity> = {
|
|
352
|
+
readonly route: TRoute;
|
|
353
|
+
_lastPayload: RouteParams<TRoute>;
|
|
354
|
+
payload: RouteParams<TRoute>;
|
|
355
|
+
query: IQueryParams;
|
|
356
|
+
pathParams: RouteParams<TRoute>;
|
|
357
|
+
isMounted: boolean;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Mixin function that enhances any `ViewModelBase` subclass with route-related properties.
|
|
361
|
+
*
|
|
362
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)
|
|
363
|
+
*
|
|
364
|
+
* @param route - Route entity to bind to the view model.
|
|
365
|
+
* @returns A class enhancer that takes a base class and returns a new class with route properties.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```ts
|
|
369
|
+
* // With ViewModelBase directly
|
|
370
|
+
* class MyVM extends withRoute(someRoute)(ViewModelBase) {}
|
|
371
|
+
*
|
|
372
|
+
* // With a custom base class
|
|
373
|
+
* class ProductPageVM extends withRoute(productRoute)(AppVM) {}
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
declare function withRoute<TRoute extends AnyAbstractRouteEntity>(route: TRoute): <TBase extends Class<ViewModel<any, any>>>(Base: TBase) => TBase & Class<InstanceType<TBase> & RouteViewModelMixinPublic<TRoute>>;
|
|
377
|
+
/**
|
|
378
|
+
* Base class created by the mixin with a dummy route.
|
|
379
|
+
* Used internally by `RouteViewModel` to avoid duplicating the mixin logic.
|
|
380
|
+
*/
|
|
381
|
+
declare const _RouteViewModelBase: typeof ViewModelBase & Class<ViewModelBase<yummies_types.AnyObject, mobx_view_model.AnyViewModel | mobx_view_model.AnyViewModelSimple | null, yummies_types.AnyObject> & RouteViewModelMixinPublic<any>>;
|
|
382
|
+
/**
|
|
383
|
+
* Abstract route-aware view model that extends `ViewModelBase<EmptyObject>`.
|
|
384
|
+
*
|
|
385
|
+
* Provides `route`, `payload`, `pathParams`, `query`, and `isMounted` properties.
|
|
386
|
+
* Subclasses must declare `route = someRoute`.
|
|
387
|
+
*
|
|
388
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* class MyVM extends RouteViewModel<typeof myRoute> {
|
|
393
|
+
* route = myRoute;
|
|
394
|
+
* }
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
declare abstract class RouteViewModel<TRoute extends AnyAbstractRouteEntity = AnyAbstractRouteEntity> extends _RouteViewModelBase {
|
|
398
|
+
abstract readonly route: TRoute;
|
|
37
399
|
}
|
|
38
400
|
|
|
39
|
-
export { RouteViewModel };
|
|
401
|
+
export { RouteViewModel, withRoute };
|
package/view-model.js
CHANGED
|
@@ -1,55 +1,70 @@
|
|
|
1
1
|
import { computed } from "mobx";
|
|
2
|
-
import { routeConfig } from "mobx-route";
|
|
3
2
|
import { ViewModelBase, applyObservable } from "mobx-view-model";
|
|
3
|
+
import { r as routeConfig } from "./virtual-route-fZzKp_7K.js";
|
|
4
4
|
const annotations = [
|
|
5
5
|
[computed.struct, "pathParams"],
|
|
6
6
|
[computed, "query"]
|
|
7
7
|
];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
function withRoute(route) {
|
|
9
|
+
return (Base) => {
|
|
10
|
+
class RouteViewModelMixin extends Base {
|
|
11
|
+
/**
|
|
12
|
+
* Route entity bound to this view model.
|
|
13
|
+
*
|
|
14
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#route)
|
|
15
|
+
*/
|
|
16
|
+
route = route;
|
|
17
|
+
/**
|
|
18
|
+
* Caches the latest known route params.
|
|
19
|
+
*/
|
|
20
|
+
_lastPayload = {};
|
|
21
|
+
constructor(...args) {
|
|
22
|
+
super(...args);
|
|
23
|
+
applyObservable(this, annotations, this.vmConfig.observable.viewModels);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Current route params with fallback to the last cached value.
|
|
27
|
+
*/
|
|
28
|
+
get payload() {
|
|
29
|
+
if ("params" in this.route && this.route.params != null) {
|
|
30
|
+
this._lastPayload = this.route.params;
|
|
31
|
+
}
|
|
32
|
+
return this._lastPayload;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Current query params from route or global route config.
|
|
36
|
+
*
|
|
37
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#query)
|
|
38
|
+
*/
|
|
39
|
+
get query() {
|
|
40
|
+
if ("query" in this.route) {
|
|
41
|
+
return this.route.query;
|
|
42
|
+
}
|
|
43
|
+
return routeConfig.get().queryParams;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Alias for `payload`.
|
|
47
|
+
*
|
|
48
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#pathparams)
|
|
49
|
+
*/
|
|
50
|
+
get pathParams() {
|
|
51
|
+
return this.payload;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Mounted state including the route opened status.
|
|
55
|
+
*/
|
|
56
|
+
get isMounted() {
|
|
57
|
+
return super.isMounted && this.route.isOpened;
|
|
58
|
+
}
|
|
23
59
|
}
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#query)
|
|
30
|
-
*/
|
|
31
|
-
get query() {
|
|
32
|
-
if ("query" in this.route) {
|
|
33
|
-
return this.route.query;
|
|
34
|
-
}
|
|
35
|
-
return routeConfig.get().queryParams;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Alias for `payload`.
|
|
39
|
-
*
|
|
40
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#pathparams)
|
|
41
|
-
*/
|
|
42
|
-
get pathParams() {
|
|
43
|
-
return this.payload;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Mounted state including the route opened status.
|
|
47
|
-
*/
|
|
48
|
-
get isMounted() {
|
|
49
|
-
return super.isMounted && this.route.isOpened;
|
|
50
|
-
}
|
|
60
|
+
return RouteViewModelMixin;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const _RouteViewModelBase = withRoute({})(ViewModelBase);
|
|
64
|
+
class RouteViewModel extends _RouteViewModelBase {
|
|
51
65
|
}
|
|
52
66
|
export {
|
|
53
|
-
RouteViewModel
|
|
67
|
+
RouteViewModel,
|
|
68
|
+
withRoute
|
|
54
69
|
};
|
|
55
70
|
//# sourceMappingURL=view-model.js.map
|
package/view-model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-model.js","sources":["../src/view-model/route-view-model.ts"],"sourcesContent":["import { computed } from 'mobx';\nimport
|
|
1
|
+
{"version":3,"file":"view-model.js","sources":["../src/view-model/route-view-model.ts"],"sourcesContent":["import { computed } from 'mobx';\nimport type { IQueryParams } from 'mobx-location-history';\nimport {\n applyObservable,\n type ViewModel,\n ViewModelBase,\n} from 'mobx-view-model';\nimport type { ObservableAnnotationsArray } from 'yummies/mobx';\nimport type { Class } from 'yummies/types';\nimport {\n type AnyAbstractRouteEntity,\n type RouteParams,\n routeConfig,\n} from '../core/index.js';\n\nconst annotations: ObservableAnnotationsArray<any> = [\n [computed.struct, 'pathParams'],\n [computed, 'query'],\n];\n\n/**\n * Public interface added by `withRouteViewModel` mixin.\n */\ntype RouteViewModelMixinPublic<TRoute extends AnyAbstractRouteEntity> = {\n readonly route: TRoute;\n _lastPayload: RouteParams<TRoute>;\n payload: RouteParams<TRoute>;\n query: IQueryParams;\n pathParams: RouteParams<TRoute>;\n isMounted: boolean;\n};\n\n/**\n * Mixin function that enhances any `ViewModelBase` subclass with route-related properties.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @param route - Route entity to bind to the view model.\n * @returns A class enhancer that takes a base class and returns a new class with route properties.\n *\n * @example\n * ```ts\n * // With ViewModelBase directly\n * class MyVM extends withRoute(someRoute)(ViewModelBase) {}\n *\n * // With a custom base class\n * class ProductPageVM extends withRoute(productRoute)(AppVM) {}\n * ```\n */\nexport function withRoute<TRoute extends AnyAbstractRouteEntity>(\n route: TRoute,\n) {\n return <TBase extends Class<ViewModel<any, any>>>(\n Base: TBase,\n ): TBase & Class<InstanceType<TBase> & RouteViewModelMixinPublic<TRoute>> => {\n class RouteViewModelMixin extends Base {\n /**\n * Route entity bound to this view model.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#route)\n */\n readonly route: TRoute = route;\n\n /**\n * Caches the latest known route params.\n */\n _lastPayload: RouteParams<TRoute> = {} as RouteParams<TRoute>;\n\n constructor(...args: any[]) {\n super(...args);\n\n applyObservable(this, annotations, this.vmConfig.observable.viewModels);\n }\n\n /**\n * Current route params with fallback to the last cached value.\n */\n override get payload(): RouteParams<TRoute> {\n if ('params' in this.route && this.route.params != null) {\n this._lastPayload = this.route.params as RouteParams<TRoute>;\n }\n\n return this._lastPayload;\n }\n\n /**\n * Current query params from route or global route config.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#query)\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 /**\n * Alias for `payload`.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#pathparams)\n */\n get pathParams() {\n return this.payload;\n }\n\n /**\n * Mounted state including the route opened status.\n */\n override get isMounted() {\n return super.isMounted && this.route.isOpened;\n }\n }\n\n return RouteViewModelMixin as any;\n };\n}\n\n/**\n * Base class created by the mixin with a dummy route.\n * Used internally by `RouteViewModel` to avoid duplicating the mixin logic.\n */\nconst _RouteViewModelBase = withRoute({} as any)(ViewModelBase);\n\n/**\n * Abstract route-aware view model that extends `ViewModelBase<EmptyObject>`.\n *\n * Provides `route`, `payload`, `pathParams`, `query`, and `isMounted` properties.\n * Subclasses must declare `route = someRoute`.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @example\n * ```ts\n * class MyVM extends RouteViewModel<typeof myRoute> {\n * route = myRoute;\n * }\n * ```\n */\nexport abstract class RouteViewModel<\n TRoute extends AnyAbstractRouteEntity = AnyAbstractRouteEntity,\n> extends _RouteViewModelBase {\n abstract override readonly route: TRoute;\n}\n"],"names":[],"mappings":";;;AAeA,MAAM,cAA+C;AAAA,EACnD,CAAC,SAAS,QAAQ,YAAY;AAAA,EAC9B,CAAC,UAAU,OAAO;AACpB;AA+BO,SAAS,UACd,OACA;AACA,SAAO,CACL,SAC2E;AAAA,IAC3E,MAAM,4BAA4B,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5B,QAAgB;AAAA;AAAA;AAAA;AAAA,MAKzB,eAAoC,CAAA;AAAA,MAEpC,eAAe,MAAa;AAC1B,cAAM,GAAG,IAAI;AAEb,wBAAgB,MAAM,aAAa,KAAK,SAAS,WAAW,UAAU;AAAA,MACxE;AAAA;AAAA;AAAA;AAAA,MAKA,IAAa,UAA+B;AAC1C,YAAI,YAAY,KAAK,SAAS,KAAK,MAAM,UAAU,MAAM;AACvD,eAAK,eAAe,KAAK,MAAM;AAAA,QACjC;AAEA,eAAO,KAAK;AAAA,MACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,IAAI,QAAsB;AACxB,YAAI,WAAW,KAAK,OAAO;AACzB,iBAAO,KAAK,MAAM;AAAA,QACpB;AAEA,eAAO,YAAY,MAAM;AAAA,MAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,IAAI,aAAa;AACf,eAAO,KAAK;AAAA,MACd;AAAA;AAAA;AAAA;AAAA,MAKA,IAAa,YAAY;AACvB,eAAO,MAAM,aAAa,KAAK,MAAM;AAAA,MACvC;AAAA,IAAA;AAGF,WAAO;AAAA,EACT;AACF;AAMA,MAAM,sBAAsB,UAAU,EAAS,EAAE,aAAa;AAiBvD,MAAe,uBAEZ,oBAAoB;AAE9B;"}
|