@esmx/router 3.0.0-rc.56 → 3.0.0-rc.57
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/matcher.d.ts +3 -2
- package/dist/matcher.mjs +2 -3
- package/dist/options.mjs +4 -2
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/matcher.ts +5 -3
- package/src/options.ts +5 -8
- package/src/types.ts +1 -0
package/dist/matcher.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { RouteConfig, RouteMatcher } from './types';
|
|
2
|
-
export declare function createMatcher(routes: RouteConfig[]): RouteMatcher;
|
|
1
|
+
import type { RouteConfig, RouteMatcher, RouteParsedConfig } from './types';
|
|
2
|
+
export declare function createMatcher(routes: RouteConfig[], compiledRoutes?: RouteParsedConfig[]): RouteMatcher;
|
|
3
|
+
export declare function createRouteMatches(routes: RouteConfig[], base?: string): RouteParsedConfig[];
|
|
3
4
|
export declare function joinPathname(pathname: string, base?: string): string;
|
package/dist/matcher.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { compile, match } from "path-to-regexp";
|
|
2
|
-
export function createMatcher(routes) {
|
|
3
|
-
const compiledRoutes = createRouteMatches(routes);
|
|
2
|
+
export function createMatcher(routes, compiledRoutes = createRouteMatches(routes)) {
|
|
4
3
|
return (toURL, baseURL, cb) => {
|
|
5
4
|
const matchPath = toURL.pathname.substring(baseURL.pathname.length - 1);
|
|
6
5
|
const matches = [];
|
|
@@ -29,7 +28,7 @@ export function createMatcher(routes) {
|
|
|
29
28
|
return { matches: Object.freeze(matches), params };
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
|
-
function createRouteMatches(routes, base = "") {
|
|
31
|
+
export function createRouteMatches(routes, base = "") {
|
|
33
32
|
return routes.map((route) => {
|
|
34
33
|
const compilePath = joinPathname(route.path, base);
|
|
35
34
|
return {
|
package/dist/options.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMatcher } from "./matcher.mjs";
|
|
1
|
+
import { createMatcher, createRouteMatches } from "./matcher.mjs";
|
|
2
2
|
import { RouterMode } from "./types.mjs";
|
|
3
3
|
import { isBrowser } from "./util.mjs";
|
|
4
4
|
function getBaseUrl(options) {
|
|
@@ -33,6 +33,7 @@ export function parsedOptions(options = {}) {
|
|
|
33
33
|
var _a, _b, _c, _d, _e, _f;
|
|
34
34
|
const base = getBaseUrl(options);
|
|
35
35
|
const routes = (_a = options.routes) != null ? _a : [];
|
|
36
|
+
const compiledRoutes = createRouteMatches(routes);
|
|
36
37
|
return Object.freeze({
|
|
37
38
|
rootStyle: options.rootStyle || false,
|
|
38
39
|
root: options.root || "",
|
|
@@ -45,7 +46,8 @@ export function parsedOptions(options = {}) {
|
|
|
45
46
|
mode: isBrowser ? (_b = options.mode) != null ? _b : RouterMode.history : RouterMode.memory,
|
|
46
47
|
routes,
|
|
47
48
|
apps: typeof options.apps === "function" ? options.apps : Object.assign({}, options.apps),
|
|
48
|
-
|
|
49
|
+
compiledRoutes,
|
|
50
|
+
matcher: createMatcher(routes, compiledRoutes),
|
|
49
51
|
normalizeURL: (_c = options.normalizeURL) != null ? _c : (url) => url,
|
|
50
52
|
fallback: (_d = options.fallback) != null ? _d : fallback,
|
|
51
53
|
handleBackBoundary: (_e = options.handleBackBoundary) != null ? _e : () => {
|
package/dist/types.d.ts
CHANGED
|
@@ -201,6 +201,7 @@ export interface RouterOptions {
|
|
|
201
201
|
handleLayerClose?: (router: Router, data?: any) => void;
|
|
202
202
|
}
|
|
203
203
|
export interface RouterParsedOptions extends Readonly<Required<RouterOptions>> {
|
|
204
|
+
readonly compiledRoutes: readonly RouteParsedConfig[];
|
|
204
205
|
readonly matcher: RouteMatcher;
|
|
205
206
|
}
|
|
206
207
|
/**
|
package/package.json
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"unbuild": "3.6.0",
|
|
40
40
|
"vitest": "3.2.4"
|
|
41
41
|
},
|
|
42
|
-
"version": "3.0.0-rc.
|
|
42
|
+
"version": "3.0.0-rc.57",
|
|
43
43
|
"type": "module",
|
|
44
44
|
"private": false,
|
|
45
45
|
"exports": {
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"template",
|
|
59
59
|
"public"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "bb3fbfa6de4906b7e98bc387c3e1d8e0c3164ac7"
|
|
62
62
|
}
|
package/src/matcher.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { compile, match } from 'path-to-regexp';
|
|
2
2
|
import type { RouteConfig, RouteMatcher, RouteParsedConfig } from './types';
|
|
3
3
|
|
|
4
|
-
export function createMatcher(
|
|
5
|
-
|
|
4
|
+
export function createMatcher(
|
|
5
|
+
routes: RouteConfig[],
|
|
6
|
+
compiledRoutes = createRouteMatches(routes)
|
|
7
|
+
): RouteMatcher {
|
|
6
8
|
return (
|
|
7
9
|
toURL: URL,
|
|
8
10
|
baseURL: URL,
|
|
@@ -42,7 +44,7 @@ export function createMatcher(routes: RouteConfig[]): RouteMatcher {
|
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
function createRouteMatches(
|
|
47
|
+
export function createRouteMatches(
|
|
46
48
|
routes: RouteConfig[],
|
|
47
49
|
base = ''
|
|
48
50
|
): RouteParsedConfig[] {
|
package/src/options.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { createMatcher } from './matcher';
|
|
1
|
+
import { createMatcher, createRouteMatches } from './matcher';
|
|
2
2
|
import type { Router } from './router';
|
|
3
3
|
import { RouterMode } from './types';
|
|
4
|
-
import type {
|
|
5
|
-
Route,
|
|
6
|
-
RouteConfig,
|
|
7
|
-
RouterOptions,
|
|
8
|
-
RouterParsedOptions
|
|
9
|
-
} from './types';
|
|
4
|
+
import type { Route, RouterOptions, RouterParsedOptions } from './types';
|
|
10
5
|
import { isBrowser } from './util';
|
|
11
6
|
|
|
12
7
|
/**
|
|
@@ -66,6 +61,7 @@ export function parsedOptions(
|
|
|
66
61
|
): RouterParsedOptions {
|
|
67
62
|
const base = getBaseUrl(options);
|
|
68
63
|
const routes = options.routes ?? [];
|
|
64
|
+
const compiledRoutes = createRouteMatches(routes);
|
|
69
65
|
return Object.freeze<RouterParsedOptions>({
|
|
70
66
|
rootStyle: options.rootStyle || false,
|
|
71
67
|
root: options.root || '',
|
|
@@ -83,7 +79,8 @@ export function parsedOptions(
|
|
|
83
79
|
typeof options.apps === 'function'
|
|
84
80
|
? options.apps
|
|
85
81
|
: Object.assign({}, options.apps),
|
|
86
|
-
|
|
82
|
+
compiledRoutes,
|
|
83
|
+
matcher: createMatcher(routes, compiledRoutes),
|
|
87
84
|
normalizeURL: options.normalizeURL ?? ((url) => url),
|
|
88
85
|
fallback: options.fallback ?? fallback,
|
|
89
86
|
handleBackBoundary: options.handleBackBoundary ?? (() => {}),
|
package/src/types.ts
CHANGED