@esmx/router 3.0.0-rc.56 → 3.0.0-rc.58

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 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
- matcher: createMatcher(routes),
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/router.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare class Router {
12
12
  readonly microApp: MicroApp;
13
13
  readonly transition: RouteTransition;
14
14
  get route(): Route;
15
+ get context(): Record<string | symbol, unknown>;
15
16
  get root(): string | HTMLElement;
16
17
  get mode(): RouterMode;
17
18
  get base(): URL;
package/dist/router.mjs CHANGED
@@ -41,6 +41,9 @@ export class Router {
41
41
  }
42
42
  return route;
43
43
  }
44
+ get context() {
45
+ return this.parsedOptions.context;
46
+ }
44
47
  get root() {
45
48
  return this.parsedOptions.root;
46
49
  }
@@ -226,6 +229,7 @@ export class Router {
226
229
  justifyContent: "center"
227
230
  },
228
231
  ...this.options,
232
+ context: this.parsedOptions.context,
229
233
  mode: RouterMode.memory,
230
234
  root: void 0,
231
235
  ...layerOptions.routerOptions,
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.56",
42
+ "version": "3.0.0-rc.58",
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": "fe85a36d5b60665eb2a0e970b20071f581fc7bdc"
61
+ "gitHead": "3155bf0f560b5395d476d1f446d59bc8c3729cb9"
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(routes: RouteConfig[]): RouteMatcher {
5
- const compiledRoutes = createRouteMatches(routes);
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
- matcher: createMatcher(routes),
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/router.ts CHANGED
@@ -40,6 +40,10 @@ export class Router {
40
40
  return route;
41
41
  }
42
42
 
43
+ public get context() {
44
+ return this.parsedOptions.context;
45
+ }
46
+
43
47
  public get root() {
44
48
  return this.parsedOptions.root;
45
49
  }
@@ -257,6 +261,7 @@ export class Router {
257
261
  justifyContent: 'center'
258
262
  },
259
263
  ...this.options,
264
+ context: this.parsedOptions.context,
260
265
  mode: RouterMode.memory,
261
266
  root: undefined,
262
267
  ...layerOptions.routerOptions,
package/src/types.ts CHANGED
@@ -275,6 +275,7 @@ export interface RouterOptions {
275
275
  }
276
276
 
277
277
  export interface RouterParsedOptions extends Readonly<Required<RouterOptions>> {
278
+ readonly compiledRoutes: readonly RouteParsedConfig[];
278
279
  readonly matcher: RouteMatcher;
279
280
  }
280
281