reactive-route 0.0.1-alpha.0 → 0.0.1-alpha.2
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/dist/cjs/index.js +225 -41
- package/dist/cjs/react/index.js +14 -13
- package/dist/cjs/solid/index.js +10 -40
- package/dist/esm/index.js +225 -41
- package/dist/esm/react/index.js +15 -14
- package/dist/esm/solid/index.js +9 -39
- package/dist/types/core/createRouterConfig.d.ts +2 -6
- package/dist/types/core/createRouterConfig.d.ts.map +1 -1
- package/dist/types/core/createRouterStore.d.ts +2 -11
- package/dist/types/core/createRouterStore.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +2 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/types/InterfaceRouterStore.d.ts +13 -0
- package/dist/types/core/types/InterfaceRouterStore.d.ts.map +1 -1
- package/dist/types/core/types/TypeLifecycleConfig.d.ts +13 -0
- package/dist/types/core/types/TypeLifecycleConfig.d.ts.map +1 -0
- package/dist/types/core/types/TypePropsRouter.d.ts +10 -0
- package/dist/types/core/types/TypePropsRouter.d.ts.map +1 -0
- package/dist/types/core/types/TypeRouteRaw.d.ts +3 -24
- package/dist/types/core/types/TypeRouteRaw.d.ts.map +1 -1
- package/dist/types/react/Router.d.ts +2 -10
- package/dist/types/react/Router.d.ts.map +1 -1
- package/dist/types/solid/Router.d.ts +2 -10
- package/dist/types/solid/Router.d.ts.map +1 -1
- package/dist/types/solid/useStore.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/dist/types/solid/replaceObject.d.ts +0 -2
- package/dist/types/solid/replaceObject.d.ts.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var core_exports = {};
|
|
32
32
|
__export(core_exports, {
|
|
33
33
|
createRouterConfig: () => createRouterConfig,
|
|
34
|
+
createRouterStore: () => createRouterStore,
|
|
34
35
|
findRouteByPathname: () => findRouteByPathname,
|
|
35
36
|
getInitialRoute: () => getInitialRoute,
|
|
36
37
|
history: () => history,
|
|
@@ -53,6 +54,9 @@ function createRouterConfig(config) {
|
|
|
53
54
|
return addNames(config);
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
// packages/core/createRouterStore.ts
|
|
58
|
+
var import_query_string2 = __toESM(require("query-string"));
|
|
59
|
+
|
|
56
60
|
// packages/core/utils/constants.ts
|
|
57
61
|
var constants = {
|
|
58
62
|
dynamicSeparator: ":",
|
|
@@ -73,37 +77,6 @@ function isDynamicRoute(route) {
|
|
|
73
77
|
return "params" in route;
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
// packages/core/utils/findRouteByPathname.ts
|
|
77
|
-
function completeStaticMatch(pathname, path) {
|
|
78
|
-
return !path.includes(constants.dynamicSeparator) && (pathname === path || pathname === `${path}${constants.pathPartSeparator}`);
|
|
79
|
-
}
|
|
80
|
-
function findRouteByPathname({
|
|
81
|
-
pathname,
|
|
82
|
-
routes
|
|
83
|
-
}) {
|
|
84
|
-
let dynamicRouteMatch;
|
|
85
|
-
const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean);
|
|
86
|
-
for (const routeName in routes) {
|
|
87
|
-
if (!Object.hasOwn(routes, routeName)) continue;
|
|
88
|
-
const route = routes[routeName];
|
|
89
|
-
if (completeStaticMatch(pathname, route.path)) return route;
|
|
90
|
-
if (dynamicRouteMatch) continue;
|
|
91
|
-
const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
|
|
92
|
-
if (routePathnameArray.length !== pathnameArray.length) continue;
|
|
93
|
-
const someParamInvalid = routePathnameArray.some((paramName, i) => {
|
|
94
|
-
const paramFromUrl = pathnameArray[i];
|
|
95
|
-
if (!isDynamic(paramName)) return paramName !== paramFromUrl;
|
|
96
|
-
const validator = route.params?.[clearDynamic(paramName)];
|
|
97
|
-
if (typeof validator !== "function") {
|
|
98
|
-
throw new Error(`findRoute: missing validator for param "${paramName}"`);
|
|
99
|
-
}
|
|
100
|
-
return !validator(paramFromUrl);
|
|
101
|
-
});
|
|
102
|
-
if (!someParamInvalid) dynamicRouteMatch = route;
|
|
103
|
-
}
|
|
104
|
-
return dynamicRouteMatch;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
80
|
// packages/core/utils/getDynamicValues.ts
|
|
108
81
|
function getDynamicValues(params) {
|
|
109
82
|
const { route, pathname } = params;
|
|
@@ -138,16 +111,6 @@ function getQueryValues(params) {
|
|
|
138
111
|
return query;
|
|
139
112
|
}
|
|
140
113
|
|
|
141
|
-
// packages/core/utils/getInitialRoute.ts
|
|
142
|
-
function getInitialRoute(params) {
|
|
143
|
-
const route = findRouteByPathname({ pathname: params.pathname, routes: params.routes }) || params.routes[params.fallback];
|
|
144
|
-
return {
|
|
145
|
-
route: route.name,
|
|
146
|
-
query: getQueryValues({ route, pathname: params.pathname }),
|
|
147
|
-
params: getDynamicValues({ route, pathname: params.pathname })
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
114
|
// packages/core/utils/history.ts
|
|
152
115
|
var import_history = require("history");
|
|
153
116
|
var history = constants.isClient ? (0, import_history.createBrowserHistory)() : null;
|
|
@@ -184,3 +147,224 @@ function replaceDynamicValues({
|
|
|
184
147
|
return encodeURIComponent(value);
|
|
185
148
|
});
|
|
186
149
|
}
|
|
150
|
+
|
|
151
|
+
// packages/core/createRouterStore.ts
|
|
152
|
+
function createRouterStore({
|
|
153
|
+
batch,
|
|
154
|
+
routes,
|
|
155
|
+
autorun,
|
|
156
|
+
replaceObject,
|
|
157
|
+
routeError500,
|
|
158
|
+
makeObservable,
|
|
159
|
+
lifecycleParams
|
|
160
|
+
}) {
|
|
161
|
+
const routerStore = makeObservable({
|
|
162
|
+
routesHistory: [],
|
|
163
|
+
currentRoute: {},
|
|
164
|
+
isRedirecting: false,
|
|
165
|
+
redirectTo: void 0,
|
|
166
|
+
utils: {
|
|
167
|
+
batch,
|
|
168
|
+
autorun,
|
|
169
|
+
replaceObject,
|
|
170
|
+
makeObservable
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
routerStore.redirectTo = async function redirectTo(config) {
|
|
174
|
+
const { route: routeName, noHistoryPush, asClient } = config;
|
|
175
|
+
const isClient = typeof asClient === "boolean" ? asClient : constants.isClient;
|
|
176
|
+
let currentRoute;
|
|
177
|
+
let currentPathname;
|
|
178
|
+
let currentUrl;
|
|
179
|
+
let currentSearch;
|
|
180
|
+
let currentQuery;
|
|
181
|
+
if (routerStore.currentRoute?.name) {
|
|
182
|
+
currentRoute = routes[routerStore.currentRoute.name];
|
|
183
|
+
currentPathname = replaceDynamicValues({
|
|
184
|
+
route: currentRoute,
|
|
185
|
+
params: routerStore.currentRoute.params
|
|
186
|
+
});
|
|
187
|
+
currentUrl = import_query_string2.default.stringifyUrl({
|
|
188
|
+
url: currentPathname,
|
|
189
|
+
query: routerStore.currentRoute.query
|
|
190
|
+
});
|
|
191
|
+
currentQuery = routerStore.currentRoute.query;
|
|
192
|
+
currentSearch = import_query_string2.default.stringify(routerStore.currentRoute.query);
|
|
193
|
+
}
|
|
194
|
+
const nextRoute = routes[routeName];
|
|
195
|
+
const nextPathname = replaceDynamicValues({
|
|
196
|
+
route: nextRoute,
|
|
197
|
+
params: "params" in config ? config.params : void 0
|
|
198
|
+
});
|
|
199
|
+
let nextQuery;
|
|
200
|
+
let nextUrl = nextPathname;
|
|
201
|
+
let nextSearch;
|
|
202
|
+
if ("query" in config && config.query) {
|
|
203
|
+
const clearedQuery = getQueryValues({
|
|
204
|
+
route: nextRoute,
|
|
205
|
+
pathname: `${nextPathname}?${import_query_string2.default.stringify(config.query)}`
|
|
206
|
+
});
|
|
207
|
+
if (Object.keys(clearedQuery).length > 0) {
|
|
208
|
+
nextQuery = clearedQuery;
|
|
209
|
+
nextSearch = import_query_string2.default.stringify(clearedQuery);
|
|
210
|
+
nextUrl = import_query_string2.default.stringifyUrl({ url: nextPathname, query: clearedQuery });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (currentUrl === nextUrl) return Promise.resolve();
|
|
214
|
+
if (currentPathname === nextPathname) {
|
|
215
|
+
if (currentSearch !== nextSearch) {
|
|
216
|
+
batch(() => {
|
|
217
|
+
replaceObject(routerStore.currentRoute.query, nextQuery || {});
|
|
218
|
+
routerStore.routesHistory.push(nextUrl);
|
|
219
|
+
});
|
|
220
|
+
if (history && !noHistoryPush) {
|
|
221
|
+
history.push({
|
|
222
|
+
hash: history.location.hash,
|
|
223
|
+
search: nextSearch,
|
|
224
|
+
pathname: nextPathname
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return Promise.resolve();
|
|
229
|
+
}
|
|
230
|
+
batch(() => {
|
|
231
|
+
routerStore.isRedirecting = true;
|
|
232
|
+
});
|
|
233
|
+
try {
|
|
234
|
+
await currentRoute?.beforeLeave?.(
|
|
235
|
+
{
|
|
236
|
+
nextUrl,
|
|
237
|
+
nextRoute,
|
|
238
|
+
nextQuery,
|
|
239
|
+
nextSearch,
|
|
240
|
+
nextPathname,
|
|
241
|
+
currentUrl,
|
|
242
|
+
currentQuery,
|
|
243
|
+
currentRoute,
|
|
244
|
+
currentSearch,
|
|
245
|
+
currentPathname
|
|
246
|
+
},
|
|
247
|
+
...lifecycleParams || []
|
|
248
|
+
);
|
|
249
|
+
const redirectConfig = await nextRoute.beforeEnter?.(
|
|
250
|
+
{
|
|
251
|
+
nextUrl,
|
|
252
|
+
nextRoute,
|
|
253
|
+
nextQuery,
|
|
254
|
+
nextSearch,
|
|
255
|
+
nextPathname,
|
|
256
|
+
currentUrl,
|
|
257
|
+
currentQuery,
|
|
258
|
+
currentRoute,
|
|
259
|
+
currentSearch,
|
|
260
|
+
currentPathname
|
|
261
|
+
},
|
|
262
|
+
...lifecycleParams || []
|
|
263
|
+
);
|
|
264
|
+
if (typeof redirectConfig === "object") {
|
|
265
|
+
if (isClient) return redirectTo({ ...redirectConfig, asClient });
|
|
266
|
+
const redirectRoute = routes[redirectConfig.route];
|
|
267
|
+
const redirectParams = "params" in redirectConfig && redirectConfig.params ? redirectConfig.params : void 0;
|
|
268
|
+
let redirectUrl = replaceDynamicValues({
|
|
269
|
+
params: redirectParams,
|
|
270
|
+
route: redirectRoute
|
|
271
|
+
});
|
|
272
|
+
if ("query" in redirectConfig && redirectConfig.query) {
|
|
273
|
+
const clearedQuery = getQueryValues({
|
|
274
|
+
route: nextRoute,
|
|
275
|
+
pathname: `${nextPathname}?${import_query_string2.default.stringify(redirectConfig.query)}`
|
|
276
|
+
});
|
|
277
|
+
if (Object.keys(clearedQuery).length > 0) {
|
|
278
|
+
redirectUrl = import_query_string2.default.stringifyUrl({ url: redirectUrl, query: clearedQuery });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
throw Object.assign(new Error(redirectUrl), { name: constants.errorRedirect });
|
|
282
|
+
}
|
|
283
|
+
await loadComponentToConfig({ route: routes[nextRoute.name] });
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (error?.name === constants.errorPrevent) return Promise.resolve();
|
|
286
|
+
if (error?.name === constants.errorRedirect) {
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
console.error(error);
|
|
290
|
+
await loadComponentToConfig({ route: routeError500 });
|
|
291
|
+
batch(() => {
|
|
292
|
+
replaceObject(routerStore.currentRoute, {
|
|
293
|
+
name: routeError500.name,
|
|
294
|
+
path: routeError500.path,
|
|
295
|
+
props: routes[routeError500.name].props,
|
|
296
|
+
query: {},
|
|
297
|
+
params: {},
|
|
298
|
+
pageName: routes[routeError500.name].pageName
|
|
299
|
+
});
|
|
300
|
+
routerStore.isRedirecting = false;
|
|
301
|
+
});
|
|
302
|
+
return Promise.resolve();
|
|
303
|
+
}
|
|
304
|
+
batch(() => {
|
|
305
|
+
replaceObject(routerStore.currentRoute, {
|
|
306
|
+
name: nextRoute.name,
|
|
307
|
+
path: nextRoute.path,
|
|
308
|
+
props: routes[nextRoute.name].props,
|
|
309
|
+
query: getQueryValues({ route: nextRoute, pathname: nextUrl }),
|
|
310
|
+
params: getDynamicValues({ route: nextRoute, pathname: nextUrl }),
|
|
311
|
+
pageName: routes[nextRoute.name].pageName
|
|
312
|
+
});
|
|
313
|
+
const lastUrl = routerStore.routesHistory[routerStore.routesHistory.length - 1];
|
|
314
|
+
if (lastUrl !== nextUrl) {
|
|
315
|
+
routerStore.routesHistory.push(nextUrl);
|
|
316
|
+
}
|
|
317
|
+
if (history && !noHistoryPush) {
|
|
318
|
+
history.push({
|
|
319
|
+
hash: history.location.hash,
|
|
320
|
+
search: "query" in config ? `?${import_query_string2.default.stringify(config.query)}` : "",
|
|
321
|
+
pathname: nextPathname
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
routerStore.isRedirecting = false;
|
|
325
|
+
});
|
|
326
|
+
return Promise.resolve();
|
|
327
|
+
};
|
|
328
|
+
return routerStore;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// packages/core/utils/findRouteByPathname.ts
|
|
332
|
+
function completeStaticMatch(pathname, path) {
|
|
333
|
+
return !path.includes(constants.dynamicSeparator) && (pathname === path || pathname === `${path}${constants.pathPartSeparator}`);
|
|
334
|
+
}
|
|
335
|
+
function findRouteByPathname({
|
|
336
|
+
pathname,
|
|
337
|
+
routes
|
|
338
|
+
}) {
|
|
339
|
+
let dynamicRouteMatch;
|
|
340
|
+
const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean);
|
|
341
|
+
for (const routeName in routes) {
|
|
342
|
+
if (!Object.hasOwn(routes, routeName)) continue;
|
|
343
|
+
const route = routes[routeName];
|
|
344
|
+
if (completeStaticMatch(pathname, route.path)) return route;
|
|
345
|
+
if (dynamicRouteMatch) continue;
|
|
346
|
+
const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
|
|
347
|
+
if (routePathnameArray.length !== pathnameArray.length) continue;
|
|
348
|
+
const someParamInvalid = routePathnameArray.some((paramName, i) => {
|
|
349
|
+
const paramFromUrl = pathnameArray[i];
|
|
350
|
+
if (!isDynamic(paramName)) return paramName !== paramFromUrl;
|
|
351
|
+
const validator = route.params?.[clearDynamic(paramName)];
|
|
352
|
+
if (typeof validator !== "function") {
|
|
353
|
+
throw new Error(`findRoute: missing validator for param "${paramName}"`);
|
|
354
|
+
}
|
|
355
|
+
return !validator(paramFromUrl);
|
|
356
|
+
});
|
|
357
|
+
if (!someParamInvalid) dynamicRouteMatch = route;
|
|
358
|
+
}
|
|
359
|
+
return dynamicRouteMatch;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// packages/core/utils/getInitialRoute.ts
|
|
363
|
+
function getInitialRoute(params) {
|
|
364
|
+
const route = findRouteByPathname({ pathname: params.pathname, routes: params.routes }) || params.routes[params.fallback];
|
|
365
|
+
return {
|
|
366
|
+
route: route.name,
|
|
367
|
+
query: getQueryValues({ route, pathname: params.pathname }),
|
|
368
|
+
params: getDynamicValues({ route, pathname: params.pathname })
|
|
369
|
+
};
|
|
370
|
+
}
|
package/dist/cjs/react/index.js
CHANGED
|
@@ -75,11 +75,14 @@ var VM = class {
|
|
|
75
75
|
loadedComponentPage = void 0;
|
|
76
76
|
loadedComponent;
|
|
77
77
|
currentProps = {};
|
|
78
|
+
get utils() {
|
|
79
|
+
return this.props.routerStore.utils;
|
|
80
|
+
}
|
|
78
81
|
beforeMount() {
|
|
79
82
|
this.props.beforeMount?.();
|
|
80
83
|
this.redirectOnHistoryPop();
|
|
81
84
|
this.setLoadedComponent();
|
|
82
|
-
this.autorunDisposers.push(
|
|
85
|
+
this.autorunDisposers.push(this.utils.autorun(this.setLoadedComponent));
|
|
83
86
|
}
|
|
84
87
|
redirectOnHistoryPop() {
|
|
85
88
|
if (!import_reactive_route.history) return;
|
|
@@ -87,7 +90,7 @@ var VM = class {
|
|
|
87
90
|
if (params.action !== "POP") return;
|
|
88
91
|
const previousRoutePathname = this.props.routerStore.routesHistory[this.props.routerStore.routesHistory.length - 2];
|
|
89
92
|
if (previousRoutePathname === params.location.pathname) {
|
|
90
|
-
|
|
93
|
+
this.utils.batch(() => this.props.routerStore.routesHistory.pop());
|
|
91
94
|
}
|
|
92
95
|
void this.props.routerStore.redirectTo({
|
|
93
96
|
noHistoryPush: true,
|
|
@@ -110,14 +113,14 @@ var VM = class {
|
|
|
110
113
|
else if (loadedComponentPage != null && currentRouteName != null) {
|
|
111
114
|
if (loadedComponentPage === currentRoutePage) {
|
|
112
115
|
const componentConfig = this.props.routes[currentRouteName];
|
|
113
|
-
|
|
116
|
+
this.utils.batch(() => {
|
|
114
117
|
this.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
115
118
|
});
|
|
116
119
|
preventRedirect = true;
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
if (preventRedirect) return;
|
|
120
|
-
|
|
123
|
+
this.utils.batch(() => {
|
|
121
124
|
if (!loadedComponentName) {
|
|
122
125
|
this.setComponent(currentRouteName);
|
|
123
126
|
} else {
|
|
@@ -127,15 +130,13 @@ var VM = class {
|
|
|
127
130
|
});
|
|
128
131
|
};
|
|
129
132
|
setComponent(currentRouteName) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.loadedComponent = RouteComponent;
|
|
138
|
-
});
|
|
133
|
+
const componentConfig = this.props.routes[currentRouteName];
|
|
134
|
+
const RouteComponent = componentConfig.component;
|
|
135
|
+
this.props.beforeSetPageComponent?.(componentConfig);
|
|
136
|
+
this.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
137
|
+
this.loadedComponentName = currentRouteName;
|
|
138
|
+
this.loadedComponentPage = componentConfig.pageName;
|
|
139
|
+
this.loadedComponent = RouteComponent;
|
|
139
140
|
}
|
|
140
141
|
};
|
|
141
142
|
var Router = (0, import_mobx_react_lite.observer)(
|
package/dist/cjs/solid/index.js
CHANGED
|
@@ -29,46 +29,13 @@ var import_web = require("solid-js/web");
|
|
|
29
29
|
var import_web2 = require("solid-js/web");
|
|
30
30
|
var import_reactive_route = require("reactive-route");
|
|
31
31
|
var import_solid_js2 = require("solid-js");
|
|
32
|
-
var import_store2 = require("solid-js/store");
|
|
33
|
-
var import_web3 = require("solid-js/web");
|
|
34
|
-
|
|
35
|
-
// packages/solid/replaceObject.ts
|
|
36
32
|
var import_store = require("solid-js/store");
|
|
37
|
-
|
|
38
|
-
(0, import_store.modifyMutable)(obj, (0, import_store.produce)((state) => {
|
|
39
|
-
if (typeof state === "object" && state != null) {
|
|
40
|
-
for (const variableKey in state) {
|
|
41
|
-
delete state[variableKey];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
Object.assign(state || {}, newObj);
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
33
|
+
var import_web3 = require("solid-js/web");
|
|
47
34
|
|
|
48
35
|
// packages/solid/useStore.ts
|
|
49
36
|
var import_solid_js = require("solid-js");
|
|
50
|
-
var getAllProperties = (object) => {
|
|
51
|
-
const properties = /* @__PURE__ */ new Set();
|
|
52
|
-
do {
|
|
53
|
-
for (const key of Reflect.ownKeys(object)) {
|
|
54
|
-
properties.add([object, key]);
|
|
55
|
-
}
|
|
56
|
-
} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
|
|
57
|
-
return properties;
|
|
58
|
-
};
|
|
59
|
-
function autoBind(self) {
|
|
60
|
-
for (const [object, key] of getAllProperties(self.constructor.prototype)) {
|
|
61
|
-
if (key === "constructor") continue;
|
|
62
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
63
|
-
if (descriptor && typeof descriptor.value === "function") {
|
|
64
|
-
self[key] = self[key].bind(self);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return self;
|
|
68
|
-
}
|
|
69
37
|
function useStore(ViewModel, props) {
|
|
70
38
|
const vm = new ViewModel(props);
|
|
71
|
-
autoBind(vm);
|
|
72
39
|
vm.beforeMount?.();
|
|
73
40
|
(0, import_solid_js.onMount)(() => {
|
|
74
41
|
vm.afterMount?.();
|
|
@@ -80,15 +47,18 @@ function useStore(ViewModel, props) {
|
|
|
80
47
|
var VM = class {
|
|
81
48
|
constructor(props) {
|
|
82
49
|
this.props = props;
|
|
83
|
-
return (0,
|
|
50
|
+
return (0, import_store.createMutable)(this);
|
|
84
51
|
}
|
|
85
52
|
loadedComponentName = void 0;
|
|
86
53
|
loadedComponentPage = void 0;
|
|
87
54
|
currentProps = {};
|
|
55
|
+
get utils() {
|
|
56
|
+
return this.props.routerStore.utils;
|
|
57
|
+
}
|
|
88
58
|
beforeMount() {
|
|
89
59
|
this.props.beforeMount?.();
|
|
90
60
|
this.redirectOnHistoryPop();
|
|
91
|
-
|
|
61
|
+
this.utils.autorun(() => this.setLoadedComponent());
|
|
92
62
|
}
|
|
93
63
|
redirectOnHistoryPop() {
|
|
94
64
|
if (!import_reactive_route.history) return;
|
|
@@ -118,12 +88,12 @@ var VM = class {
|
|
|
118
88
|
} else if (this.loadedComponentPage != null && currentRouteName != null) {
|
|
119
89
|
if (this.loadedComponentPage === currentRoutePage) {
|
|
120
90
|
const componentConfig = this.props.routes[currentRouteName];
|
|
121
|
-
replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
91
|
+
this.utils.replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
122
92
|
preventRedirect = true;
|
|
123
93
|
}
|
|
124
94
|
}
|
|
125
95
|
if (preventRedirect) return;
|
|
126
|
-
|
|
96
|
+
this.utils.batch(() => {
|
|
127
97
|
if (!this.loadedComponentName) {
|
|
128
98
|
this.setComponent();
|
|
129
99
|
} else {
|
|
@@ -136,8 +106,8 @@ var VM = class {
|
|
|
136
106
|
const currentRouteName = this.props.routerStore.currentRoute.name;
|
|
137
107
|
const componentConfig = this.props.routes[currentRouteName];
|
|
138
108
|
this.props.beforeSetPageComponent?.(componentConfig);
|
|
139
|
-
|
|
140
|
-
replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
109
|
+
this.utils.batch(() => {
|
|
110
|
+
this.utils.replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
141
111
|
this.loadedComponentName = currentRouteName;
|
|
142
112
|
this.loadedComponentPage = componentConfig.pageName;
|
|
143
113
|
});
|
package/dist/esm/index.js
CHANGED
|
@@ -11,6 +11,9 @@ function createRouterConfig(config) {
|
|
|
11
11
|
return addNames(config);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// packages/core/createRouterStore.ts
|
|
15
|
+
import queryString2 from "query-string";
|
|
16
|
+
|
|
14
17
|
// packages/core/utils/constants.ts
|
|
15
18
|
var constants = {
|
|
16
19
|
dynamicSeparator: ":",
|
|
@@ -31,37 +34,6 @@ function isDynamicRoute(route) {
|
|
|
31
34
|
return "params" in route;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
// packages/core/utils/findRouteByPathname.ts
|
|
35
|
-
function completeStaticMatch(pathname, path) {
|
|
36
|
-
return !path.includes(constants.dynamicSeparator) && (pathname === path || pathname === `${path}${constants.pathPartSeparator}`);
|
|
37
|
-
}
|
|
38
|
-
function findRouteByPathname({
|
|
39
|
-
pathname,
|
|
40
|
-
routes
|
|
41
|
-
}) {
|
|
42
|
-
let dynamicRouteMatch;
|
|
43
|
-
const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean);
|
|
44
|
-
for (const routeName in routes) {
|
|
45
|
-
if (!Object.hasOwn(routes, routeName)) continue;
|
|
46
|
-
const route = routes[routeName];
|
|
47
|
-
if (completeStaticMatch(pathname, route.path)) return route;
|
|
48
|
-
if (dynamicRouteMatch) continue;
|
|
49
|
-
const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
|
|
50
|
-
if (routePathnameArray.length !== pathnameArray.length) continue;
|
|
51
|
-
const someParamInvalid = routePathnameArray.some((paramName, i) => {
|
|
52
|
-
const paramFromUrl = pathnameArray[i];
|
|
53
|
-
if (!isDynamic(paramName)) return paramName !== paramFromUrl;
|
|
54
|
-
const validator = route.params?.[clearDynamic(paramName)];
|
|
55
|
-
if (typeof validator !== "function") {
|
|
56
|
-
throw new Error(`findRoute: missing validator for param "${paramName}"`);
|
|
57
|
-
}
|
|
58
|
-
return !validator(paramFromUrl);
|
|
59
|
-
});
|
|
60
|
-
if (!someParamInvalid) dynamicRouteMatch = route;
|
|
61
|
-
}
|
|
62
|
-
return dynamicRouteMatch;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
37
|
// packages/core/utils/getDynamicValues.ts
|
|
66
38
|
function getDynamicValues(params) {
|
|
67
39
|
const { route, pathname } = params;
|
|
@@ -96,16 +68,6 @@ function getQueryValues(params) {
|
|
|
96
68
|
return query;
|
|
97
69
|
}
|
|
98
70
|
|
|
99
|
-
// packages/core/utils/getInitialRoute.ts
|
|
100
|
-
function getInitialRoute(params) {
|
|
101
|
-
const route = findRouteByPathname({ pathname: params.pathname, routes: params.routes }) || params.routes[params.fallback];
|
|
102
|
-
return {
|
|
103
|
-
route: route.name,
|
|
104
|
-
query: getQueryValues({ route, pathname: params.pathname }),
|
|
105
|
-
params: getDynamicValues({ route, pathname: params.pathname })
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
71
|
// packages/core/utils/history.ts
|
|
110
72
|
import { createBrowserHistory } from "history";
|
|
111
73
|
var history = constants.isClient ? createBrowserHistory() : null;
|
|
@@ -142,8 +104,230 @@ function replaceDynamicValues({
|
|
|
142
104
|
return encodeURIComponent(value);
|
|
143
105
|
});
|
|
144
106
|
}
|
|
107
|
+
|
|
108
|
+
// packages/core/createRouterStore.ts
|
|
109
|
+
function createRouterStore({
|
|
110
|
+
batch,
|
|
111
|
+
routes,
|
|
112
|
+
autorun,
|
|
113
|
+
replaceObject,
|
|
114
|
+
routeError500,
|
|
115
|
+
makeObservable,
|
|
116
|
+
lifecycleParams
|
|
117
|
+
}) {
|
|
118
|
+
const routerStore = makeObservable({
|
|
119
|
+
routesHistory: [],
|
|
120
|
+
currentRoute: {},
|
|
121
|
+
isRedirecting: false,
|
|
122
|
+
redirectTo: void 0,
|
|
123
|
+
utils: {
|
|
124
|
+
batch,
|
|
125
|
+
autorun,
|
|
126
|
+
replaceObject,
|
|
127
|
+
makeObservable
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
routerStore.redirectTo = async function redirectTo(config) {
|
|
131
|
+
const { route: routeName, noHistoryPush, asClient } = config;
|
|
132
|
+
const isClient = typeof asClient === "boolean" ? asClient : constants.isClient;
|
|
133
|
+
let currentRoute;
|
|
134
|
+
let currentPathname;
|
|
135
|
+
let currentUrl;
|
|
136
|
+
let currentSearch;
|
|
137
|
+
let currentQuery;
|
|
138
|
+
if (routerStore.currentRoute?.name) {
|
|
139
|
+
currentRoute = routes[routerStore.currentRoute.name];
|
|
140
|
+
currentPathname = replaceDynamicValues({
|
|
141
|
+
route: currentRoute,
|
|
142
|
+
params: routerStore.currentRoute.params
|
|
143
|
+
});
|
|
144
|
+
currentUrl = queryString2.stringifyUrl({
|
|
145
|
+
url: currentPathname,
|
|
146
|
+
query: routerStore.currentRoute.query
|
|
147
|
+
});
|
|
148
|
+
currentQuery = routerStore.currentRoute.query;
|
|
149
|
+
currentSearch = queryString2.stringify(routerStore.currentRoute.query);
|
|
150
|
+
}
|
|
151
|
+
const nextRoute = routes[routeName];
|
|
152
|
+
const nextPathname = replaceDynamicValues({
|
|
153
|
+
route: nextRoute,
|
|
154
|
+
params: "params" in config ? config.params : void 0
|
|
155
|
+
});
|
|
156
|
+
let nextQuery;
|
|
157
|
+
let nextUrl = nextPathname;
|
|
158
|
+
let nextSearch;
|
|
159
|
+
if ("query" in config && config.query) {
|
|
160
|
+
const clearedQuery = getQueryValues({
|
|
161
|
+
route: nextRoute,
|
|
162
|
+
pathname: `${nextPathname}?${queryString2.stringify(config.query)}`
|
|
163
|
+
});
|
|
164
|
+
if (Object.keys(clearedQuery).length > 0) {
|
|
165
|
+
nextQuery = clearedQuery;
|
|
166
|
+
nextSearch = queryString2.stringify(clearedQuery);
|
|
167
|
+
nextUrl = queryString2.stringifyUrl({ url: nextPathname, query: clearedQuery });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (currentUrl === nextUrl) return Promise.resolve();
|
|
171
|
+
if (currentPathname === nextPathname) {
|
|
172
|
+
if (currentSearch !== nextSearch) {
|
|
173
|
+
batch(() => {
|
|
174
|
+
replaceObject(routerStore.currentRoute.query, nextQuery || {});
|
|
175
|
+
routerStore.routesHistory.push(nextUrl);
|
|
176
|
+
});
|
|
177
|
+
if (history && !noHistoryPush) {
|
|
178
|
+
history.push({
|
|
179
|
+
hash: history.location.hash,
|
|
180
|
+
search: nextSearch,
|
|
181
|
+
pathname: nextPathname
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return Promise.resolve();
|
|
186
|
+
}
|
|
187
|
+
batch(() => {
|
|
188
|
+
routerStore.isRedirecting = true;
|
|
189
|
+
});
|
|
190
|
+
try {
|
|
191
|
+
await currentRoute?.beforeLeave?.(
|
|
192
|
+
{
|
|
193
|
+
nextUrl,
|
|
194
|
+
nextRoute,
|
|
195
|
+
nextQuery,
|
|
196
|
+
nextSearch,
|
|
197
|
+
nextPathname,
|
|
198
|
+
currentUrl,
|
|
199
|
+
currentQuery,
|
|
200
|
+
currentRoute,
|
|
201
|
+
currentSearch,
|
|
202
|
+
currentPathname
|
|
203
|
+
},
|
|
204
|
+
...lifecycleParams || []
|
|
205
|
+
);
|
|
206
|
+
const redirectConfig = await nextRoute.beforeEnter?.(
|
|
207
|
+
{
|
|
208
|
+
nextUrl,
|
|
209
|
+
nextRoute,
|
|
210
|
+
nextQuery,
|
|
211
|
+
nextSearch,
|
|
212
|
+
nextPathname,
|
|
213
|
+
currentUrl,
|
|
214
|
+
currentQuery,
|
|
215
|
+
currentRoute,
|
|
216
|
+
currentSearch,
|
|
217
|
+
currentPathname
|
|
218
|
+
},
|
|
219
|
+
...lifecycleParams || []
|
|
220
|
+
);
|
|
221
|
+
if (typeof redirectConfig === "object") {
|
|
222
|
+
if (isClient) return redirectTo({ ...redirectConfig, asClient });
|
|
223
|
+
const redirectRoute = routes[redirectConfig.route];
|
|
224
|
+
const redirectParams = "params" in redirectConfig && redirectConfig.params ? redirectConfig.params : void 0;
|
|
225
|
+
let redirectUrl = replaceDynamicValues({
|
|
226
|
+
params: redirectParams,
|
|
227
|
+
route: redirectRoute
|
|
228
|
+
});
|
|
229
|
+
if ("query" in redirectConfig && redirectConfig.query) {
|
|
230
|
+
const clearedQuery = getQueryValues({
|
|
231
|
+
route: nextRoute,
|
|
232
|
+
pathname: `${nextPathname}?${queryString2.stringify(redirectConfig.query)}`
|
|
233
|
+
});
|
|
234
|
+
if (Object.keys(clearedQuery).length > 0) {
|
|
235
|
+
redirectUrl = queryString2.stringifyUrl({ url: redirectUrl, query: clearedQuery });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
throw Object.assign(new Error(redirectUrl), { name: constants.errorRedirect });
|
|
239
|
+
}
|
|
240
|
+
await loadComponentToConfig({ route: routes[nextRoute.name] });
|
|
241
|
+
} catch (error) {
|
|
242
|
+
if (error?.name === constants.errorPrevent) return Promise.resolve();
|
|
243
|
+
if (error?.name === constants.errorRedirect) {
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
console.error(error);
|
|
247
|
+
await loadComponentToConfig({ route: routeError500 });
|
|
248
|
+
batch(() => {
|
|
249
|
+
replaceObject(routerStore.currentRoute, {
|
|
250
|
+
name: routeError500.name,
|
|
251
|
+
path: routeError500.path,
|
|
252
|
+
props: routes[routeError500.name].props,
|
|
253
|
+
query: {},
|
|
254
|
+
params: {},
|
|
255
|
+
pageName: routes[routeError500.name].pageName
|
|
256
|
+
});
|
|
257
|
+
routerStore.isRedirecting = false;
|
|
258
|
+
});
|
|
259
|
+
return Promise.resolve();
|
|
260
|
+
}
|
|
261
|
+
batch(() => {
|
|
262
|
+
replaceObject(routerStore.currentRoute, {
|
|
263
|
+
name: nextRoute.name,
|
|
264
|
+
path: nextRoute.path,
|
|
265
|
+
props: routes[nextRoute.name].props,
|
|
266
|
+
query: getQueryValues({ route: nextRoute, pathname: nextUrl }),
|
|
267
|
+
params: getDynamicValues({ route: nextRoute, pathname: nextUrl }),
|
|
268
|
+
pageName: routes[nextRoute.name].pageName
|
|
269
|
+
});
|
|
270
|
+
const lastUrl = routerStore.routesHistory[routerStore.routesHistory.length - 1];
|
|
271
|
+
if (lastUrl !== nextUrl) {
|
|
272
|
+
routerStore.routesHistory.push(nextUrl);
|
|
273
|
+
}
|
|
274
|
+
if (history && !noHistoryPush) {
|
|
275
|
+
history.push({
|
|
276
|
+
hash: history.location.hash,
|
|
277
|
+
search: "query" in config ? `?${queryString2.stringify(config.query)}` : "",
|
|
278
|
+
pathname: nextPathname
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
routerStore.isRedirecting = false;
|
|
282
|
+
});
|
|
283
|
+
return Promise.resolve();
|
|
284
|
+
};
|
|
285
|
+
return routerStore;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// packages/core/utils/findRouteByPathname.ts
|
|
289
|
+
function completeStaticMatch(pathname, path) {
|
|
290
|
+
return !path.includes(constants.dynamicSeparator) && (pathname === path || pathname === `${path}${constants.pathPartSeparator}`);
|
|
291
|
+
}
|
|
292
|
+
function findRouteByPathname({
|
|
293
|
+
pathname,
|
|
294
|
+
routes
|
|
295
|
+
}) {
|
|
296
|
+
let dynamicRouteMatch;
|
|
297
|
+
const pathnameArray = pathname.replace(/\?.+$/, "").split(constants.pathPartSeparator).filter(Boolean);
|
|
298
|
+
for (const routeName in routes) {
|
|
299
|
+
if (!Object.hasOwn(routes, routeName)) continue;
|
|
300
|
+
const route = routes[routeName];
|
|
301
|
+
if (completeStaticMatch(pathname, route.path)) return route;
|
|
302
|
+
if (dynamicRouteMatch) continue;
|
|
303
|
+
const routePathnameArray = route.path.split(constants.pathPartSeparator).filter(Boolean);
|
|
304
|
+
if (routePathnameArray.length !== pathnameArray.length) continue;
|
|
305
|
+
const someParamInvalid = routePathnameArray.some((paramName, i) => {
|
|
306
|
+
const paramFromUrl = pathnameArray[i];
|
|
307
|
+
if (!isDynamic(paramName)) return paramName !== paramFromUrl;
|
|
308
|
+
const validator = route.params?.[clearDynamic(paramName)];
|
|
309
|
+
if (typeof validator !== "function") {
|
|
310
|
+
throw new Error(`findRoute: missing validator for param "${paramName}"`);
|
|
311
|
+
}
|
|
312
|
+
return !validator(paramFromUrl);
|
|
313
|
+
});
|
|
314
|
+
if (!someParamInvalid) dynamicRouteMatch = route;
|
|
315
|
+
}
|
|
316
|
+
return dynamicRouteMatch;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// packages/core/utils/getInitialRoute.ts
|
|
320
|
+
function getInitialRoute(params) {
|
|
321
|
+
const route = findRouteByPathname({ pathname: params.pathname, routes: params.routes }) || params.routes[params.fallback];
|
|
322
|
+
return {
|
|
323
|
+
route: route.name,
|
|
324
|
+
query: getQueryValues({ route, pathname: params.pathname }),
|
|
325
|
+
params: getDynamicValues({ route, pathname: params.pathname })
|
|
326
|
+
};
|
|
327
|
+
}
|
|
145
328
|
export {
|
|
146
329
|
createRouterConfig,
|
|
330
|
+
createRouterStore,
|
|
147
331
|
findRouteByPathname,
|
|
148
332
|
getInitialRoute,
|
|
149
333
|
history,
|
package/dist/esm/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/react/Router.tsx
|
|
2
|
-
import {
|
|
2
|
+
import { makeAutoObservable } from "mobx";
|
|
3
3
|
import { observer } from "mobx-react-lite";
|
|
4
4
|
import { getInitialRoute, history } from "reactive-route";
|
|
5
5
|
|
|
@@ -49,11 +49,14 @@ var VM = class {
|
|
|
49
49
|
loadedComponentPage = void 0;
|
|
50
50
|
loadedComponent;
|
|
51
51
|
currentProps = {};
|
|
52
|
+
get utils() {
|
|
53
|
+
return this.props.routerStore.utils;
|
|
54
|
+
}
|
|
52
55
|
beforeMount() {
|
|
53
56
|
this.props.beforeMount?.();
|
|
54
57
|
this.redirectOnHistoryPop();
|
|
55
58
|
this.setLoadedComponent();
|
|
56
|
-
this.autorunDisposers.push(autorun(this.setLoadedComponent));
|
|
59
|
+
this.autorunDisposers.push(this.utils.autorun(this.setLoadedComponent));
|
|
57
60
|
}
|
|
58
61
|
redirectOnHistoryPop() {
|
|
59
62
|
if (!history) return;
|
|
@@ -61,7 +64,7 @@ var VM = class {
|
|
|
61
64
|
if (params.action !== "POP") return;
|
|
62
65
|
const previousRoutePathname = this.props.routerStore.routesHistory[this.props.routerStore.routesHistory.length - 2];
|
|
63
66
|
if (previousRoutePathname === params.location.pathname) {
|
|
64
|
-
|
|
67
|
+
this.utils.batch(() => this.props.routerStore.routesHistory.pop());
|
|
65
68
|
}
|
|
66
69
|
void this.props.routerStore.redirectTo({
|
|
67
70
|
noHistoryPush: true,
|
|
@@ -84,14 +87,14 @@ var VM = class {
|
|
|
84
87
|
else if (loadedComponentPage != null && currentRouteName != null) {
|
|
85
88
|
if (loadedComponentPage === currentRoutePage) {
|
|
86
89
|
const componentConfig = this.props.routes[currentRouteName];
|
|
87
|
-
|
|
90
|
+
this.utils.batch(() => {
|
|
88
91
|
this.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
89
92
|
});
|
|
90
93
|
preventRedirect = true;
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
if (preventRedirect) return;
|
|
94
|
-
|
|
97
|
+
this.utils.batch(() => {
|
|
95
98
|
if (!loadedComponentName) {
|
|
96
99
|
this.setComponent(currentRouteName);
|
|
97
100
|
} else {
|
|
@@ -101,15 +104,13 @@ var VM = class {
|
|
|
101
104
|
});
|
|
102
105
|
};
|
|
103
106
|
setComponent(currentRouteName) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.loadedComponent = RouteComponent;
|
|
112
|
-
});
|
|
107
|
+
const componentConfig = this.props.routes[currentRouteName];
|
|
108
|
+
const RouteComponent = componentConfig.component;
|
|
109
|
+
this.props.beforeSetPageComponent?.(componentConfig);
|
|
110
|
+
this.currentProps = "props" in componentConfig ? componentConfig.props || {} : {};
|
|
111
|
+
this.loadedComponentName = currentRouteName;
|
|
112
|
+
this.loadedComponentPage = componentConfig.pageName;
|
|
113
|
+
this.loadedComponent = RouteComponent;
|
|
113
114
|
}
|
|
114
115
|
};
|
|
115
116
|
var Router = observer(
|
package/dist/esm/solid/index.js
CHANGED
|
@@ -2,47 +2,14 @@
|
|
|
2
2
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
3
|
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
4
4
|
import { getInitialRoute, history } from "reactive-route";
|
|
5
|
-
import {
|
|
5
|
+
import { Show } from "solid-js";
|
|
6
6
|
import { createMutable } from "solid-js/store";
|
|
7
7
|
import { Dynamic } from "solid-js/web";
|
|
8
8
|
|
|
9
|
-
// packages/solid/replaceObject.ts
|
|
10
|
-
import { modifyMutable, produce } from "solid-js/store";
|
|
11
|
-
function replaceObject(obj, newObj) {
|
|
12
|
-
modifyMutable(obj, produce((state) => {
|
|
13
|
-
if (typeof state === "object" && state != null) {
|
|
14
|
-
for (const variableKey in state) {
|
|
15
|
-
delete state[variableKey];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
Object.assign(state || {}, newObj);
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
9
|
// packages/solid/useStore.ts
|
|
23
10
|
import { onMount } from "solid-js";
|
|
24
|
-
var getAllProperties = (object) => {
|
|
25
|
-
const properties = /* @__PURE__ */ new Set();
|
|
26
|
-
do {
|
|
27
|
-
for (const key of Reflect.ownKeys(object)) {
|
|
28
|
-
properties.add([object, key]);
|
|
29
|
-
}
|
|
30
|
-
} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
|
|
31
|
-
return properties;
|
|
32
|
-
};
|
|
33
|
-
function autoBind(self) {
|
|
34
|
-
for (const [object, key] of getAllProperties(self.constructor.prototype)) {
|
|
35
|
-
if (key === "constructor") continue;
|
|
36
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
37
|
-
if (descriptor && typeof descriptor.value === "function") {
|
|
38
|
-
self[key] = self[key].bind(self);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return self;
|
|
42
|
-
}
|
|
43
11
|
function useStore(ViewModel, props) {
|
|
44
12
|
const vm = new ViewModel(props);
|
|
45
|
-
autoBind(vm);
|
|
46
13
|
vm.beforeMount?.();
|
|
47
14
|
onMount(() => {
|
|
48
15
|
vm.afterMount?.();
|
|
@@ -59,10 +26,13 @@ var VM = class {
|
|
|
59
26
|
loadedComponentName = void 0;
|
|
60
27
|
loadedComponentPage = void 0;
|
|
61
28
|
currentProps = {};
|
|
29
|
+
get utils() {
|
|
30
|
+
return this.props.routerStore.utils;
|
|
31
|
+
}
|
|
62
32
|
beforeMount() {
|
|
63
33
|
this.props.beforeMount?.();
|
|
64
34
|
this.redirectOnHistoryPop();
|
|
65
|
-
|
|
35
|
+
this.utils.autorun(() => this.setLoadedComponent());
|
|
66
36
|
}
|
|
67
37
|
redirectOnHistoryPop() {
|
|
68
38
|
if (!history) return;
|
|
@@ -92,12 +62,12 @@ var VM = class {
|
|
|
92
62
|
} else if (this.loadedComponentPage != null && currentRouteName != null) {
|
|
93
63
|
if (this.loadedComponentPage === currentRoutePage) {
|
|
94
64
|
const componentConfig = this.props.routes[currentRouteName];
|
|
95
|
-
replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
65
|
+
this.utils.replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
96
66
|
preventRedirect = true;
|
|
97
67
|
}
|
|
98
68
|
}
|
|
99
69
|
if (preventRedirect) return;
|
|
100
|
-
batch(() => {
|
|
70
|
+
this.utils.batch(() => {
|
|
101
71
|
if (!this.loadedComponentName) {
|
|
102
72
|
this.setComponent();
|
|
103
73
|
} else {
|
|
@@ -110,8 +80,8 @@ var VM = class {
|
|
|
110
80
|
const currentRouteName = this.props.routerStore.currentRoute.name;
|
|
111
81
|
const componentConfig = this.props.routes[currentRouteName];
|
|
112
82
|
this.props.beforeSetPageComponent?.(componentConfig);
|
|
113
|
-
batch(() => {
|
|
114
|
-
replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
83
|
+
this.utils.batch(() => {
|
|
84
|
+
this.utils.replaceObject(this.currentProps, "props" in componentConfig ? componentConfig.props : {});
|
|
115
85
|
this.loadedComponentName = currentRouteName;
|
|
116
86
|
this.loadedComponentPage = componentConfig.pageName;
|
|
117
87
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypeRouteRaw } from './types/TypeRouteRaw';
|
|
2
|
-
|
|
2
|
+
export declare function createRouterConfig<TConfig extends {
|
|
3
3
|
[Key in keyof TConfig]: TypeRouteRaw;
|
|
4
|
-
}>
|
|
4
|
+
}>(config: TConfig): {
|
|
5
5
|
[Key in keyof TConfig]: TConfig[Key] & {
|
|
6
6
|
name: Key;
|
|
7
7
|
pageName?: string;
|
|
@@ -9,8 +9,4 @@ type TypeRouteItemFinalGeneric<TConfig extends {
|
|
|
9
9
|
otherExports?: Record<string, any>;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export declare function createRouterConfig<TConfig extends {
|
|
13
|
-
[Key in keyof TConfig]: TypeRouteRaw;
|
|
14
|
-
}>(config: TConfig): TypeRouteItemFinalGeneric<TConfig>;
|
|
15
|
-
export {};
|
|
16
12
|
//# sourceMappingURL=createRouterConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRouterConfig.d.ts","sourceRoot":"","sources":["../../../packages/core/createRouterConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,
|
|
1
|
+
{"version":3,"file":"createRouterConfig.d.ts","sourceRoot":"","sources":["../../../packages/core/createRouterConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,wBAAgB,kBAAkB,CAAC,OAAO,SAAS;KAAG,GAAG,IAAI,MAAM,OAAO,GAAG,YAAY;CAAE,EACzF,MAAM,EAAE,OAAO,GACd;KACA,GAAG,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG;QACrC,IAAI,EAAE,GAAG,CAAC;QACV,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,GAAG,CAAC;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACpC;CACF,CAEA"}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import { InterfaceRouterStore } from './types/InterfaceRouterStore';
|
|
1
|
+
import { InterfaceRouterStore, TypeCreateRouterStore } from './types/InterfaceRouterStore';
|
|
2
2
|
import { TypeRoute } from './types/TypeRoute';
|
|
3
|
-
|
|
4
|
-
routes: TRoutes;
|
|
5
|
-
routeError500: TRoutes[keyof TRoutes];
|
|
6
|
-
lifecycleParams?: Array<any>;
|
|
7
|
-
batch: (cb: () => void) => void;
|
|
8
|
-
makeObservable: <TObj extends Record<string, any>>(obj: TObj) => TObj;
|
|
9
|
-
replaceObject: <TObj extends Record<string, any>>(obj: TObj, newObj: TObj) => void;
|
|
10
|
-
};
|
|
11
|
-
export declare function createRouterStore<TRoutes extends Record<string, TypeRoute>>({ batch, routes, routeError500, makeObservable, lifecycleParams, replaceObject, }: TypeCreateRouterStore<TRoutes>): InterfaceRouterStore<TRoutes>;
|
|
12
|
-
export {};
|
|
3
|
+
export declare function createRouterStore<TRoutes extends Record<string, TypeRoute>>({ batch, routes, autorun, replaceObject, routeError500, makeObservable, lifecycleParams, }: TypeCreateRouterStore<TRoutes>): InterfaceRouterStore<TRoutes>;
|
|
13
4
|
//# sourceMappingURL=createRouterStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRouterStore.d.ts","sourceRoot":"","sources":["../../../packages/core/createRouterStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"createRouterStore.d.ts","sourceRoot":"","sources":["../../../packages/core/createRouterStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE3F,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQ9C,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,EAC3E,KAAK,EACL,MAAM,EACN,OAAO,EACP,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,GAChB,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,oBAAoB,CAAC,OAAO,CAAC,CA4OhE"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { createRouterConfig } from './createRouterConfig';
|
|
2
|
+
export { createRouterStore } from './createRouterStore';
|
|
2
3
|
export type { InterfaceRouterStore } from './types/InterfaceRouterStore';
|
|
3
4
|
export type { TypeCurrentRoute } from './types/TypeCurrentRoute';
|
|
5
|
+
export type { TypePropsRouter } from './types/TypePropsRouter';
|
|
4
6
|
export type { TypeRedirectToParams } from './types/TypeRedirectToParams';
|
|
5
7
|
export type { TypeRoute } from './types/TypeRoute';
|
|
6
8
|
export { isDynamicRoute } from './utils/dynamic';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { TypeCurrentRoute } from './TypeCurrentRoute';
|
|
2
2
|
import { TypeRedirectToParams } from './TypeRedirectToParams';
|
|
3
3
|
import { TypeRoute } from './TypeRoute';
|
|
4
|
+
type TypeUtils = {
|
|
5
|
+
batch: (cb: () => void) => void;
|
|
6
|
+
autorun: (cb: () => void) => any;
|
|
7
|
+
replaceObject: <TObj extends Record<string, any>>(obj: TObj, newObj: TObj) => void;
|
|
8
|
+
makeObservable: <TObj extends Record<string, any>>(obj: TObj) => TObj;
|
|
9
|
+
};
|
|
10
|
+
export type TypeCreateRouterStore<TRoutes extends Record<string, TypeRoute>> = TypeUtils & {
|
|
11
|
+
routes: TRoutes;
|
|
12
|
+
routeError500: TRoutes[keyof TRoutes];
|
|
13
|
+
lifecycleParams?: Array<any>;
|
|
14
|
+
};
|
|
4
15
|
export type InterfaceRouterStore<TRoutes extends Record<string, TypeRoute>> = {
|
|
5
16
|
routesHistory: Array<string>;
|
|
6
17
|
currentRoute: TypeCurrentRoute<TRoutes[keyof TRoutes]>;
|
|
7
18
|
isRedirecting: boolean;
|
|
8
19
|
redirectTo<TRouteName extends keyof TRoutes>(config: TypeRedirectToParams<TRoutes, TRouteName>): Promise<void>;
|
|
20
|
+
utils: TypeUtils;
|
|
9
21
|
};
|
|
22
|
+
export {};
|
|
10
23
|
//# sourceMappingURL=InterfaceRouterStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InterfaceRouterStore.d.ts","sourceRoot":"","sources":["../../../../packages/core/types/InterfaceRouterStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI;IAC5E,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;IACvD,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,UAAU,SAAS,MAAM,OAAO,EACzC,MAAM,EAAE,oBAAoB,CAAC,OAAO,EAAE,UAAU,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC"}
|
|
1
|
+
{"version":3,"file":"InterfaceRouterStore.d.ts","sourceRoot":"","sources":["../../../../packages/core/types/InterfaceRouterStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,KAAK,SAAS,GAAG;IACf,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAChC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC;IACjC,aAAa,EAAE,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,KAAK,IAAI,CAAC;IACnF,cAAc,EAAE,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,CAAC;CACvE,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,SAAS,GAAG;IACzF,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI;IAC5E,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC;IACvD,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,UAAU,SAAS,MAAM,OAAO,EACzC,MAAM,EAAE,oBAAoB,CAAC,OAAO,EAAE,UAAU,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type TypeLifecycleConfig = {
|
|
2
|
+
nextUrl: string;
|
|
3
|
+
nextRoute: any;
|
|
4
|
+
nextPathname: string;
|
|
5
|
+
nextQuery?: any;
|
|
6
|
+
nextSearch?: string;
|
|
7
|
+
currentUrl?: string;
|
|
8
|
+
currentQuery?: any;
|
|
9
|
+
currentRoute?: any;
|
|
10
|
+
currentSearch?: string;
|
|
11
|
+
currentPathname?: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=TypeLifecycleConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeLifecycleConfig.d.ts","sourceRoot":"","sources":["../../../../packages/core/types/TypeLifecycleConfig.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,GAAG,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InterfaceRouterStore } from './InterfaceRouterStore';
|
|
2
|
+
import { TypeRoute } from './TypeRoute';
|
|
3
|
+
export type TypePropsRouter<TRoutes extends Record<string, TypeRoute>> = {
|
|
4
|
+
routes: TRoutes;
|
|
5
|
+
routerStore: InterfaceRouterStore<TRoutes>;
|
|
6
|
+
beforeMount?: () => void;
|
|
7
|
+
beforeSetPageComponent?: (componentConfig: TRoutes[keyof TRoutes]) => void;
|
|
8
|
+
beforeUpdatePageComponent?: () => void;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=TypePropsRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypePropsRouter.d.ts","sourceRoot":"","sources":["../../../../packages/core/types/TypePropsRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI;IACvE,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,sBAAsB,CAAC,EAAE,CAAC,eAAe,EAAE,OAAO,CAAC,MAAM,OAAO,CAAC,KAAK,IAAI,CAAC;IAC3E,yBAAyB,CAAC,EAAE,MAAM,IAAI,CAAC;CACxC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypeLifecycleConfig } from './TypeLifecycleConfig';
|
|
1
2
|
import { TypeValidator } from './TypeValidator';
|
|
2
3
|
export type TypeRouteRaw = {
|
|
3
4
|
path: string;
|
|
@@ -7,29 +8,7 @@ export type TypeRouteRaw = {
|
|
|
7
8
|
props?: Record<string, any>;
|
|
8
9
|
query?: Record<string, TypeValidator>;
|
|
9
10
|
params?: Record<string, TypeValidator>;
|
|
10
|
-
beforeEnter?: (config:
|
|
11
|
-
|
|
12
|
-
nextRoute: any;
|
|
13
|
-
nextPathname: string;
|
|
14
|
-
nextQuery?: any;
|
|
15
|
-
nextSearch?: string;
|
|
16
|
-
currentUrl?: string;
|
|
17
|
-
currentQuery?: any;
|
|
18
|
-
currentRoute?: any;
|
|
19
|
-
currentSearch?: string;
|
|
20
|
-
currentPathname?: string;
|
|
21
|
-
}, ...args: Array<any>) => Promise<any>;
|
|
22
|
-
beforeLeave?: (config: {
|
|
23
|
-
nextUrl: string;
|
|
24
|
-
nextRoute: any;
|
|
25
|
-
nextPathname: string;
|
|
26
|
-
nextQuery?: any;
|
|
27
|
-
nextSearch?: string;
|
|
28
|
-
currentUrl?: string;
|
|
29
|
-
currentQuery?: any;
|
|
30
|
-
currentRoute?: any;
|
|
31
|
-
currentSearch?: string;
|
|
32
|
-
currentPathname?: string;
|
|
33
|
-
}, ...args: Array<any>) => Promise<any> | null;
|
|
11
|
+
beforeEnter?: (config: TypeLifecycleConfig, ...args: Array<any>) => Promise<any>;
|
|
12
|
+
beforeLeave?: (config: TypeLifecycleConfig, ...args: Array<any>) => Promise<any> | null;
|
|
34
13
|
};
|
|
35
14
|
//# sourceMappingURL=TypeRouteRaw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeRouteRaw.d.ts","sourceRoot":"","sources":["../../../../packages/core/types/TypeRouteRaw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvC,WAAW,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"TypeRouteRaw.d.ts","sourceRoot":"","sources":["../../../../packages/core/types/TypeRouteRaw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACjF,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;CACzF,CAAC"}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
routes: TRoutes;
|
|
4
|
-
routerStore: InterfaceRouterStore<TRoutes>;
|
|
5
|
-
beforeMount?: () => void;
|
|
6
|
-
beforeSetPageComponent?: (componentConfig: TRoutes[keyof TRoutes]) => void;
|
|
7
|
-
beforeUpdatePageComponent?: () => void;
|
|
8
|
-
};
|
|
9
|
-
export declare const Router: (<TRoutes extends Record<string, TypeRoute>>(props: TypeProps<TRoutes>) => any) & {
|
|
1
|
+
import { TypePropsRouter, TypeRoute } from 'reactive-route';
|
|
2
|
+
export declare const Router: (<TRoutes extends Record<string, TypeRoute>>(props: TypePropsRouter<TRoutes>) => any) & {
|
|
10
3
|
displayName: string;
|
|
11
4
|
};
|
|
12
|
-
export {};
|
|
13
5
|
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../packages/react/Router.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA4B,
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../packages/react/Router.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAsGtF,eAAO,MAAM,MAAM,IAChB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,SAAS,eAAe,CAAC,OAAO,CAAC;;CAS5E,CAAC"}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
routes: TRoutes;
|
|
4
|
-
routerStore: InterfaceRouterStore<TRoutes>;
|
|
5
|
-
beforeMount?: () => void;
|
|
6
|
-
beforeSetPageComponent?: (componentConfig: TRoutes[keyof TRoutes]) => void;
|
|
7
|
-
beforeUpdatePageComponent?: () => void;
|
|
8
|
-
};
|
|
9
|
-
export declare function Router<TRoutes extends Record<string, TypeRoute>>(props: TypeProps<TRoutes>): import("solid-js").JSX.Element;
|
|
10
|
-
export {};
|
|
1
|
+
import { TypePropsRouter, TypeRoute } from 'reactive-route';
|
|
2
|
+
export declare function Router<TRoutes extends Record<string, TypeRoute>>(props: TypePropsRouter<TRoutes>): import("solid-js").JSX.Element;
|
|
11
3
|
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../packages/solid/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../packages/solid/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAoGtF,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,kCAWhG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../../packages/solid/useStore.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../../packages/solid/useStore.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,wBAAgB,QAAQ,CACtB,UAAU,SAAS,KACjB,KAAK,EAAE,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KACxC,oBAAoB,EACzB,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAU9F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../packages/core/createRouterConfig.ts","../../packages/core/createRouterStore.ts","../../packages/core/index.ts","../../packages/core/types/InterfaceRouterStore.ts","../../packages/core/types/TypeCurrentRoute.ts","../../packages/core/types/TypeRedirectToParams.ts","../../packages/core/types/TypeRoute.ts","../../packages/core/types/TypeRouteRaw.ts","../../packages/core/types/TypeRouteWithParams.ts","../../packages/core/types/TypeValidator.ts","../../packages/core/utils/addNames.ts","../../packages/core/utils/constants.ts","../../packages/core/utils/dynamic.ts","../../packages/core/utils/findRouteByPathname.ts","../../packages/core/utils/getDynamicValues.ts","../../packages/core/utils/getInitialRoute.ts","../../packages/core/utils/getQueryValues.ts","../../packages/core/utils/getTypedEntries.ts","../../packages/core/utils/history.ts","../../packages/core/utils/loadComponentToConfig.ts","../../packages/core/utils/replaceDynamicValues.ts","../../packages/react/Router.tsx","../../packages/react/index.ts","../../packages/react/useStore.ts","../../packages/solid/Router.tsx","../../packages/solid/index.ts","../../packages/solid/
|
|
1
|
+
{"root":["../../packages/core/createRouterConfig.ts","../../packages/core/createRouterStore.ts","../../packages/core/index.ts","../../packages/core/types/InterfaceRouterStore.ts","../../packages/core/types/TypeCurrentRoute.ts","../../packages/core/types/TypeLifecycleConfig.ts","../../packages/core/types/TypePropsRouter.ts","../../packages/core/types/TypeRedirectToParams.ts","../../packages/core/types/TypeRoute.ts","../../packages/core/types/TypeRouteRaw.ts","../../packages/core/types/TypeRouteWithParams.ts","../../packages/core/types/TypeValidator.ts","../../packages/core/utils/addNames.ts","../../packages/core/utils/constants.ts","../../packages/core/utils/dynamic.ts","../../packages/core/utils/findRouteByPathname.ts","../../packages/core/utils/getDynamicValues.ts","../../packages/core/utils/getInitialRoute.ts","../../packages/core/utils/getQueryValues.ts","../../packages/core/utils/getTypedEntries.ts","../../packages/core/utils/history.ts","../../packages/core/utils/loadComponentToConfig.ts","../../packages/core/utils/replaceDynamicValues.ts","../../packages/react/Router.tsx","../../packages/react/index.ts","../../packages/react/useStore.ts","../../packages/solid/Router.tsx","../../packages/solid/index.ts","../../packages/solid/useStore.ts"],"version":"5.9.2"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "reactive-route",
|
|
3
3
|
"author": "Dmitry Kazakov",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.1-alpha.
|
|
5
|
+
"version": "0.0.1-alpha.2",
|
|
6
6
|
"description": "Reactive Router for different frameworks",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
"analyze:js": "biome check --no-errors-on-unmatched .",
|
|
18
18
|
"format:js": "biome check --no-errors-on-unmatched --write",
|
|
19
19
|
"check-types": "tsc --project tsconfig.json",
|
|
20
|
+
"check-types-example": "tsc --project ./examples/simple_ssr/tsconfig.json",
|
|
20
21
|
"prepare": "husky"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"history": "5.3.0",
|
|
24
|
-
"query-string": "
|
|
25
|
+
"query-string": "7.1.3"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@types/node": "22.14.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replaceObject.d.ts","sourceRoot":"","sources":["../../../packages/solid/replaceObject.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,QActF"}
|