@esmx/router 3.0.0-rc.51 → 3.0.0-rc.52

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.
@@ -270,14 +270,14 @@ export class RouteTransition {
270
270
  this._controller = null;
271
271
  }
272
272
  async to(toType, toInput) {
273
- var _a, _b, _c;
274
- const from = (_b = (_a = this.route) == null ? void 0 : _a.clone()) != null ? _b : null;
273
+ var _a;
274
+ const from = this.route;
275
275
  const to = await this._runTask(
276
276
  new Route({
277
277
  options: this.router.parsedOptions,
278
278
  toType,
279
279
  toInput,
280
- from: (_c = from == null ? void 0 : from.url) != null ? _c : null
280
+ from: (_a = from == null ? void 0 : from.url) != null ? _a : null
281
281
  }),
282
282
  from
283
283
  );
package/dist/route.d.ts CHANGED
@@ -36,7 +36,8 @@ export declare class Route {
36
36
  readonly path: string;
37
37
  readonly fullPath: string;
38
38
  readonly hash: string;
39
- readonly params: Record<string, string>;
39
+ readonly params: Record<string, string | undefined>;
40
+ readonly paramsArray: Record<string, string[] | undefined>;
40
41
  readonly query: Record<string, string | undefined>;
41
42
  readonly queryArray: Record<string, string[] | undefined>;
42
43
  readonly meta: RouteMeta;
package/dist/route.mjs CHANGED
@@ -6,7 +6,7 @@ import { parsedOptions } from "./options.mjs";
6
6
  import {
7
7
  RouteType
8
8
  } from "./types.mjs";
9
- import { isNonEmptyPlainObject, isPlainObject } from "./util.mjs";
9
+ import { decodeParams, isNonEmptyPlainObject, isPlainObject } from "./util.mjs";
10
10
  export const NON_ENUMERABLE_PROPERTIES = [
11
11
  // Private fields - internal implementation details
12
12
  "_handled",
@@ -66,6 +66,7 @@ export class Route {
66
66
  __publicField(this, "fullPath");
67
67
  __publicField(this, "hash");
68
68
  __publicField(this, "params", {});
69
+ __publicField(this, "paramsArray", {});
69
70
  __publicField(this, "query", {});
70
71
  __publicField(this, "queryArray", {});
71
72
  __publicField(this, "meta");
@@ -97,7 +98,17 @@ export class Route {
97
98
  }
98
99
  if (match) {
99
100
  applyRouteParams(match, toInput, base, to);
100
- Object.assign(this.params, match.params);
101
+ const decodedParams = decodeParams(match.params);
102
+ for (const key in decodedParams) {
103
+ const value = decodedParams[key];
104
+ if (Array.isArray(value)) {
105
+ this.params[key] = value[0] || "";
106
+ this.paramsArray[key] = value;
107
+ } else {
108
+ this.params[key] = value;
109
+ this.paramsArray[key] = [value];
110
+ }
111
+ }
101
112
  }
102
113
  this.url = to;
103
114
  this.path = match ? to.pathname.substring(base.pathname.length - 1) : to.pathname;
package/dist/types.d.ts CHANGED
@@ -91,7 +91,7 @@ export interface RouteParsedConfig extends RouteConfig {
91
91
  }
92
92
  export interface RouteMatchResult {
93
93
  readonly matches: readonly RouteParsedConfig[];
94
- readonly params: Record<string, string | string[] | undefined>;
94
+ readonly params: Record<string, string | string[]>;
95
95
  }
96
96
  export type RouteMatcher = (to: URL, base: URL, cb?: (item: RouteParsedConfig) => boolean) => RouteMatchResult;
97
97
  /**
package/dist/util.d.ts CHANGED
@@ -24,3 +24,4 @@ export declare function isUrlEqual(url1: URL, url2?: URL | null): boolean;
24
24
  * @returns Whether they match
25
25
  */
26
26
  export declare function isRouteMatched(fromRoute: Route, toRoute: Route | null, matchType: RouteMatchType): boolean;
27
+ export declare function decodeParams<T extends Record<string, string | string[]>>(params: T): T;
package/dist/util.mjs CHANGED
@@ -51,3 +51,17 @@ export function isRouteMatched(fromRoute, toRoute, matchType) {
51
51
  return false;
52
52
  }
53
53
  }
54
+ export function decodeParams(params) {
55
+ const result = {};
56
+ for (const key in params) {
57
+ const value = params[key];
58
+ if (Array.isArray(value)) {
59
+ result[key] = value.map(
60
+ (item) => decodeURIComponent(item)
61
+ );
62
+ } else {
63
+ result[key] = decodeURIComponent(value);
64
+ }
65
+ }
66
+ return result;
67
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "template": "library",
4
4
  "scripts": {
5
5
  "lint:js": "biome check --write --no-errors-on-unmatched",
6
- "lint:css": "stylelint '**/*.{css,vue}' --fix --aei",
6
+ "lint:css": "npm run lint:js",
7
7
  "lint:type": "tsc --noEmit",
8
8
  "test": "vitest run --pass-with-no-tests",
9
9
  "coverage": "vitest run --coverage --pass-with-no-tests",
@@ -32,16 +32,14 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@biomejs/biome": "1.9.4",
35
- "@esmx/lint": "3.0.0-rc.51",
36
35
  "@types/node": "^24.0.0",
37
36
  "@vitest/coverage-v8": "3.2.4",
38
37
  "happy-dom": "^18.0.1",
39
- "stylelint": "16.21.0",
40
38
  "typescript": "5.8.3",
41
39
  "unbuild": "3.5.0",
42
40
  "vitest": "3.2.4"
43
41
  },
44
- "version": "3.0.0-rc.51",
42
+ "version": "3.0.0-rc.52",
45
43
  "type": "module",
46
44
  "private": false,
47
45
  "exports": {
@@ -60,5 +58,5 @@
60
58
  "template",
61
59
  "public"
62
60
  ],
63
- "gitHead": "5556ca6bbaf29a673861c685a19414d5853b9166"
61
+ "gitHead": "6cb46d99223f82c65b7913514950497ce34860ae"
64
62
  }
@@ -380,7 +380,7 @@ export class RouteTransition {
380
380
  toType: RouteType,
381
381
  toInput: RouteLocationInput
382
382
  ): Promise<Route> {
383
- const from = this.route?.clone() ?? null;
383
+ const from = this.route;
384
384
  const to = await this._runTask(
385
385
  new Route({
386
386
  options: this.router.parsedOptions,
package/src/route.ts CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  RouteType,
18
18
  type RouterParsedOptions
19
19
  } from './types';
20
- import { isNonEmptyPlainObject, isPlainObject } from './util';
20
+ import { decodeParams, isNonEmptyPlainObject, isPlainObject } from './util';
21
21
 
22
22
  /**
23
23
  * Configuration for non-enumerable properties in Route class
@@ -120,7 +120,8 @@ export class Route {
120
120
  public readonly path: string;
121
121
  public readonly fullPath: string;
122
122
  public readonly hash: string;
123
- public readonly params: Record<string, string> = {};
123
+ public readonly params: Record<string, string | undefined> = {};
124
+ public readonly paramsArray: Record<string, string[] | undefined> = {};
124
125
  public readonly query: Record<string, string | undefined> = {};
125
126
  public readonly queryArray: Record<string, string[] | undefined> = {};
126
127
  public readonly meta: RouteMeta;
@@ -172,7 +173,20 @@ export class Route {
172
173
 
173
174
  if (match) {
174
175
  applyRouteParams(match, toInput, base, to);
175
- Object.assign(this.params, match.params);
176
+
177
+ const decodedParams = decodeParams(match.params);
178
+
179
+ for (const key in decodedParams) {
180
+ const value = decodedParams[key];
181
+
182
+ if (Array.isArray(value)) {
183
+ this.params[key] = value[0] || '';
184
+ this.paramsArray[key] = value;
185
+ } else {
186
+ this.params[key] = value;
187
+ this.paramsArray[key] = [value];
188
+ }
189
+ }
176
190
  }
177
191
 
178
192
  this.url = to;
package/src/types.ts CHANGED
@@ -143,7 +143,7 @@ export interface RouteParsedConfig extends RouteConfig {
143
143
 
144
144
  export interface RouteMatchResult {
145
145
  readonly matches: readonly RouteParsedConfig[];
146
- readonly params: Record<string, string | string[] | undefined>;
146
+ readonly params: Record<string, string | string[]>;
147
147
  }
148
148
 
149
149
  export type RouteMatcher = (
package/src/util.ts CHANGED
@@ -114,3 +114,22 @@ export function isRouteMatched(
114
114
  return false;
115
115
  }
116
116
  }
117
+
118
+ export function decodeParams<T extends Record<string, string | string[]>>(
119
+ params: T
120
+ ): T {
121
+ const result = {} as T;
122
+
123
+ for (const key in params) {
124
+ const value = params[key];
125
+ if (Array.isArray(value)) {
126
+ result[key] = value.map((item) =>
127
+ decodeURIComponent(item)
128
+ ) as T[typeof key];
129
+ } else {
130
+ result[key] = decodeURIComponent(value) as T[typeof key];
131
+ }
132
+ }
133
+
134
+ return result;
135
+ }