@esmx/router 3.0.0-rc.48 → 3.0.0-rc.50
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/options.mjs +13 -1
- package/dist/route.mjs +4 -4
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
- package/src/options.ts +23 -2
- package/src/route.ts +5 -9
- package/src/types.ts +2 -0
package/dist/options.mjs
CHANGED
|
@@ -29,10 +29,22 @@ function getBaseUrl(options) {
|
|
|
29
29
|
base.search = base.hash = "";
|
|
30
30
|
return base;
|
|
31
31
|
}
|
|
32
|
+
function filterRoutesByLayer(routes, layerMode) {
|
|
33
|
+
return routes.filter((route) => {
|
|
34
|
+
if (layerMode && route.layer !== true) return false;
|
|
35
|
+
if (!layerMode && route.layer === true) return false;
|
|
36
|
+
if (route.children)
|
|
37
|
+
route.children = filterRoutesByLayer(route.children, layerMode);
|
|
38
|
+
return true;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
32
41
|
export function parsedOptions(options = {}) {
|
|
33
42
|
var _a, _b, _c, _d, _e, _f;
|
|
34
43
|
const base = getBaseUrl(options);
|
|
35
|
-
const routes =
|
|
44
|
+
const routes = filterRoutesByLayer(
|
|
45
|
+
(_a = options.routes) != null ? _a : [],
|
|
46
|
+
options.layer || false
|
|
47
|
+
);
|
|
36
48
|
return Object.freeze({
|
|
37
49
|
rootStyle: options.rootStyle || false,
|
|
38
50
|
root: options.root || "",
|
package/dist/route.mjs
CHANGED
|
@@ -88,6 +88,10 @@ export class Route {
|
|
|
88
88
|
const isSameOrigin = to.origin === base.origin;
|
|
89
89
|
const isSameBase = to.pathname.startsWith(base.pathname);
|
|
90
90
|
const match = isSameOrigin && isSameBase ? options.matcher(to, base) : null;
|
|
91
|
+
if (match) {
|
|
92
|
+
applyRouteParams(match, toInput, base, to);
|
|
93
|
+
Object.assign(this.params, match.params);
|
|
94
|
+
}
|
|
91
95
|
this.url = to;
|
|
92
96
|
this.path = match ? to.pathname.substring(base.pathname.length - 1) : to.pathname;
|
|
93
97
|
this.fullPath = (match ? this.path : to.pathname) + to.search + to.hash;
|
|
@@ -107,10 +111,6 @@ export class Route {
|
|
|
107
111
|
this.queryArray[key] = to.searchParams.getAll(key);
|
|
108
112
|
}
|
|
109
113
|
this.hash = to.hash;
|
|
110
|
-
if (match) {
|
|
111
|
-
applyRouteParams(match, toInput, base, to);
|
|
112
|
-
Object.assign(this.params, match.params);
|
|
113
|
-
}
|
|
114
114
|
if (typeof toInput.statusCode === "number") {
|
|
115
115
|
this.statusCode = toInput.statusCode;
|
|
116
116
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -61,6 +61,8 @@ export interface RouteConfig {
|
|
|
61
61
|
beforeEnter?: RouteConfirmHook;
|
|
62
62
|
beforeUpdate?: RouteConfirmHook;
|
|
63
63
|
beforeLeave?: RouteConfirmHook;
|
|
64
|
+
/** Mark this route as only effective in layer mode */
|
|
65
|
+
layer?: boolean;
|
|
64
66
|
/**
|
|
65
67
|
* Route override function for hybrid app development
|
|
66
68
|
*
|
package/package.json
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@biomejs/biome": "1.9.4",
|
|
35
|
-
"@esmx/lint": "3.0.0-rc.
|
|
35
|
+
"@esmx/lint": "3.0.0-rc.50",
|
|
36
36
|
"@types/node": "^24.0.0",
|
|
37
37
|
"@vitest/coverage-v8": "3.2.4",
|
|
38
38
|
"happy-dom": "^18.0.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"unbuild": "3.5.0",
|
|
42
42
|
"vitest": "3.2.4"
|
|
43
43
|
},
|
|
44
|
-
"version": "3.0.0-rc.
|
|
44
|
+
"version": "3.0.0-rc.50",
|
|
45
45
|
"type": "module",
|
|
46
46
|
"private": false,
|
|
47
47
|
"exports": {
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"template",
|
|
61
61
|
"public"
|
|
62
62
|
],
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "7ec8747f78f4626941cb4da548b6df47df4df825"
|
|
64
64
|
}
|
package/src/options.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { createMatcher } from './matcher';
|
|
2
2
|
import type { Router } from './router';
|
|
3
3
|
import { RouterMode } from './types';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
Route,
|
|
6
|
+
RouteConfig,
|
|
7
|
+
RouterOptions,
|
|
8
|
+
RouterParsedOptions
|
|
9
|
+
} from './types';
|
|
5
10
|
import { isBrowser } from './util';
|
|
6
11
|
|
|
7
12
|
/**
|
|
@@ -56,11 +61,27 @@ function getBaseUrl(options: RouterOptions): URL {
|
|
|
56
61
|
return base;
|
|
57
62
|
}
|
|
58
63
|
|
|
64
|
+
function filterRoutesByLayer(
|
|
65
|
+
routes: RouteConfig[],
|
|
66
|
+
layerMode: boolean
|
|
67
|
+
): RouteConfig[] {
|
|
68
|
+
return routes.filter((route) => {
|
|
69
|
+
if (layerMode && route.layer !== true) return false;
|
|
70
|
+
if (!layerMode && route.layer === true) return false;
|
|
71
|
+
if (route.children)
|
|
72
|
+
route.children = filterRoutesByLayer(route.children, layerMode);
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
59
77
|
export function parsedOptions(
|
|
60
78
|
options: RouterOptions = {}
|
|
61
79
|
): RouterParsedOptions {
|
|
62
80
|
const base = getBaseUrl(options);
|
|
63
|
-
const routes =
|
|
81
|
+
const routes = filterRoutesByLayer(
|
|
82
|
+
options.routes ?? [],
|
|
83
|
+
options.layer || false
|
|
84
|
+
);
|
|
64
85
|
return Object.freeze<RouterParsedOptions>({
|
|
65
86
|
rootStyle: options.rootStyle || false,
|
|
66
87
|
root: options.root || '',
|
package/src/route.ts
CHANGED
|
@@ -158,6 +158,11 @@ export class Route {
|
|
|
158
158
|
const match =
|
|
159
159
|
isSameOrigin && isSameBase ? options.matcher(to, base) : null;
|
|
160
160
|
|
|
161
|
+
if (match) {
|
|
162
|
+
applyRouteParams(match, toInput, base, to);
|
|
163
|
+
Object.assign(this.params, match.params);
|
|
164
|
+
}
|
|
165
|
+
|
|
161
166
|
this.url = to;
|
|
162
167
|
this.path = match
|
|
163
168
|
? to.pathname.substring(base.pathname.length - 1)
|
|
@@ -176,27 +181,18 @@ export class Route {
|
|
|
176
181
|
: null;
|
|
177
182
|
this.meta = this.config?.meta || {};
|
|
178
183
|
|
|
179
|
-
// Initialize state object - create new local object, merge externally passed state
|
|
180
184
|
const state: RouteState = {};
|
|
181
185
|
if (toInput.state) {
|
|
182
186
|
Object.assign(state, toInput.state);
|
|
183
187
|
}
|
|
184
188
|
this.state = state;
|
|
185
189
|
|
|
186
|
-
// Process query parameters
|
|
187
190
|
for (const key of new Set(to.searchParams.keys())) {
|
|
188
191
|
this.query[key] = to.searchParams.get(key)!;
|
|
189
192
|
this.queryArray[key] = to.searchParams.getAll(key);
|
|
190
193
|
}
|
|
191
194
|
this.hash = to.hash;
|
|
192
195
|
|
|
193
|
-
// Apply user-provided route parameters (if match is successful)
|
|
194
|
-
if (match) {
|
|
195
|
-
applyRouteParams(match, toInput, base, to);
|
|
196
|
-
// Assign matched parameters to route object
|
|
197
|
-
Object.assign(this.params, match.params);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
196
|
// Set status code
|
|
201
197
|
// Prioritize user-provided statusCode
|
|
202
198
|
if (typeof toInput.statusCode === 'number') {
|
package/src/types.ts
CHANGED
|
@@ -110,6 +110,8 @@ export interface RouteConfig {
|
|
|
110
110
|
beforeEnter?: RouteConfirmHook;
|
|
111
111
|
beforeUpdate?: RouteConfirmHook;
|
|
112
112
|
beforeLeave?: RouteConfirmHook;
|
|
113
|
+
/** Mark this route as only effective in layer mode */
|
|
114
|
+
layer?: boolean;
|
|
113
115
|
|
|
114
116
|
/**
|
|
115
117
|
* Route override function for hybrid app development
|