vitarx-router 1.0.0-beta.3 → 1.0.0-beta.4

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.
@@ -361,7 +361,7 @@ export declare interface Route<WIDGET extends AllowedRouteWidget = AllowedRouteW
361
361
  /**
362
362
  * 路由索引
363
363
  */
364
- export declare type RouteIndex = RoutePath | RouteName | VitarxRouterRouteIndexTyped;
364
+ export declare type RouteIndex = VitarxRouterRouteIndexTyped;
365
365
 
366
366
  /**
367
367
  * 路由匹配的详情数据
@@ -5,12 +5,30 @@ var H = (e) => {
5
5
  var K = (e, t, i) => t in e ? q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
6
6
  var u = (e, t, i) => K(e, typeof t != "symbol" ? t + "" : t, i), I = (e, t, i) => t.has(e) || H("Cannot " + i);
7
7
  var f = (e, t, i) => (I(e, t, "read from private field"), i ? i.call(e) : t.get(e)), _ = (e, t, i) => t.has(e) ? H("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, i), v = (e, t, i, n) => (I(e, t, "write to private field"), n ? n.call(e, i) : t.set(e, i), i);
8
- import { reactive as J, shallowReactive as Q, markRaw as k, createElement as V, LazyWidget as X, deepClone as Z, deepEqual as S, Widget as M, shallowRef as N, inject as tt, provide as et, watch as it, Fragment as nt, Computed as L, isString as st } from "vitarx";
8
+ import { reactive as J, shallowReactive as Q, markRaw as k, createElement as V, LazyWidget as X, deepClone as Z, isDeepEqual as S, Widget as M, shallowRef as N, inject as tt, provide as et, watch as it, Fragment as nt, Computed as L, isString as st } from "vitarx";
9
9
  var p = /* @__PURE__ */ ((e) => (e[e.success = 0] = "success", e[e.aborted = 1] = "aborted", e[e.cancelled = 2] = "cancelled", e[e.duplicated = 3] = "duplicated", e[e.not_matched = 4] = "not_matched", e[e.exception = 5] = "exception", e))(p || {});
10
+ const rt = ["path", "hash", "index", "fullPath"];
11
+ function ot(e, t) {
12
+ at(e.matched, t.matched), j(e.params, t.params), j(e.query, t.query), j(e.meta, t.meta);
13
+ for (const i of rt)
14
+ e[i] !== t[i] && (e[i] = t[i]);
15
+ }
16
+ function at(e, t) {
17
+ for (let i = 0; i < t.length; i++)
18
+ e[i] !== t[i] && (e[i] = t[i]);
19
+ e.length > t.length && (e.length = t.length);
20
+ }
21
+ function j(e, t) {
22
+ const i = Object.keys(e), n = Object.keys(t);
23
+ for (const s of n)
24
+ Object.prototype.hasOwnProperty.call(t, s) && (e[s] = t[s]);
25
+ for (const s in i)
26
+ s in t || delete e[s];
27
+ }
10
28
  function B(e) {
11
29
  return typeof e == "boolean" || typeof e == "function" || typeof e == "object" && e !== null;
12
30
  }
13
- function rt(e) {
31
+ function ct(e) {
14
32
  if (e.widget === void 0) return;
15
33
  if (!("injectProps" in e)) {
16
34
  e.injectProps = W(e, !0);
@@ -18,7 +36,7 @@ function rt(e) {
18
36
  }
19
37
  const t = e.injectProps;
20
38
  if (typeof t == "object")
21
- ot(t) ? at(e, t) : ct(e, t);
39
+ ht(t) ? ut(e, t) : lt(e, t);
22
40
  else if (B(t))
23
41
  e.injectProps = W(e, t);
24
42
  else
@@ -26,16 +44,16 @@ function rt(e) {
26
44
  `[Vitarx.Router][TYPE_ERROR]:${e.path} 路由线路配置的 injectProps 类型有误,它可以是布尔值、函数,亦或是一个{string:any}类型的对象。`
27
45
  );
28
46
  }
29
- function ot(e) {
47
+ function ht(e) {
30
48
  return Object.keys(e).length === 1 && "default" in e;
31
49
  }
32
- function at(e, t) {
50
+ function ut(e, t) {
33
51
  if (!B(t.default))
34
52
  throw new TypeError(
35
53
  `[Vitarx.Router][TYPE_ERROR]:${e.path} 路由线路配置的 injectProps.default 类型有误,它可以是布尔值、函数,亦或是一个{string:any}类型的对象。`
36
54
  );
37
55
  }
38
- function ct(e, t) {
56
+ function lt(e, t) {
39
57
  for (const i of Object.keys(e.widget))
40
58
  if (i in t) {
41
59
  if (!B(t[i]))
@@ -51,7 +69,7 @@ function W(e, t) {
51
69
  i[n] = t;
52
70
  return i;
53
71
  }
54
- function ht(e) {
72
+ function ft(e) {
55
73
  if (!("widget" in e)) {
56
74
  if (e.children.length === 0)
57
75
  throw new TypeError(
@@ -80,14 +98,14 @@ const U = Symbol("LazyLoader");
80
98
  function T(e) {
81
99
  return /\{[^}]+}/.test(e);
82
100
  }
83
- function ut(e) {
101
+ function dt(e) {
84
102
  const t = e.replace(/\s+/g, ""), i = /\{[\w-]+\?}/g, n = t.match(i);
85
103
  return n ? n.length : 0;
86
104
  }
87
105
  function A(e) {
88
106
  return "children" in e && e.children !== void 0 && e.children.length > 0;
89
107
  }
90
- function lt(e, t, i, n) {
108
+ function pt(e, t, i, n) {
91
109
  let s = 0;
92
110
  const r = (h, a) => {
93
111
  const $ = t[h];
@@ -124,7 +142,7 @@ function C(e, t) {
124
142
  return String(t[s]).replace(/\s+/g, "_");
125
143
  }), m(e);
126
144
  }
127
- function ft(e) {
145
+ function Rt(e) {
128
146
  return typeof e == "function" && e[U];
129
147
  }
130
148
  function D(e, t) {
@@ -137,11 +155,11 @@ function z(e) {
137
155
  ), i = {};
138
156
  return t.forEach((n, s) => i[s] = n), i;
139
157
  }
140
- function dt(e) {
158
+ function gt(e) {
141
159
  const t = new URLSearchParams(e).toString();
142
160
  return t ? `?${t}` : "";
143
161
  }
144
- function pt(e, t, i) {
162
+ function mt(e, t, i) {
145
163
  let n = decodeURIComponent(e.pathname), s = decodeURIComponent(e.hash), r = z(e.search);
146
164
  if (n = m(n.startsWith(i) ? n.slice(i.length) : n), t === "hash" && s.includes("#/")) {
147
165
  const o = s.slice(1), [l, c] = o.split("#"), [h, a] = l.split("?");
@@ -149,7 +167,7 @@ function pt(e, t, i) {
149
167
  }
150
168
  return { index: n, hash: s, query: r };
151
169
  }
152
- function Rt(e) {
170
+ function wt(e) {
153
171
  const t = G(e);
154
172
  return t && (e = e.slice(0, -t.length)), {
155
173
  path: e,
@@ -160,7 +178,7 @@ function G(e) {
160
178
  const t = e.match(/^(.*?)(\.[a-zA-Z0-9]+)$/);
161
179
  return t ? t[2] : "";
162
180
  }
163
- function gt(e) {
181
+ function yt(e) {
164
182
  if (typeof e != "object" || e === null) return !1;
165
183
  const t = [
166
184
  "index",
@@ -176,32 +194,14 @@ function gt(e) {
176
194
  if (!Object.prototype.hasOwnProperty.call(e, i)) return !1;
177
195
  return !0;
178
196
  }
179
- function mt(e) {
197
+ function _t(e) {
180
198
  if (e.meta = e.meta || {}, e.pattern = e.pattern || {}, e.children = e.children || [], !Array.isArray(e.children))
181
199
  throw new TypeError(
182
200
  `[Vitarx.Router][TYPE_ERROR]:${e.path} 路由线路配置 children 类型错误,它必须是数组类型。`
183
201
  );
184
202
  if (!e.path.trim())
185
203
  throw new TypeError("[Vitarx.Router][TYPE_ERROR]:路由线路配置 path 不能为空");
186
- return e.path = m(e.path), ht(e), rt(e), e;
187
- }
188
- const wt = ["path", "hash", "index", "fullPath"];
189
- function yt(e, t) {
190
- _t(e.matched, t.matched), j(e.params, t.params), j(e.query, t.query), j(e.meta, t.meta);
191
- for (const i of wt)
192
- e[i] !== t[i] && (e[i] = t[i]);
193
- }
194
- function _t(e, t) {
195
- for (let i = 0; i < t.length; i++)
196
- e[i] !== t[i] && (e[i] = t[i]);
197
- e.length > t.length && (e.length = t.length);
198
- }
199
- function j(e, t) {
200
- const i = Object.keys(e), n = Object.keys(t);
201
- for (const s of n)
202
- Object.prototype.hasOwnProperty.call(t, s) && (e[s] = t[s]);
203
- for (const s in i)
204
- s in t || delete e[s];
204
+ return e.path = m(e.path), ft(e), ct(e), e;
205
205
  }
206
206
  var g;
207
207
  const R = class R {
@@ -409,7 +409,7 @@ const R = class R {
409
409
  const n = t.widget;
410
410
  if (!Object.prototype.hasOwnProperty.call(n, i)) return;
411
411
  const s = n[i];
412
- return ft(s) ? V(X, { children: s, key: t.path }) : V(s);
412
+ return Rt(s) ? V(X, { children: s, key: t.path }) : V(s);
413
413
  }
414
414
  /**
415
415
  * 后退到上一个历史记录
@@ -546,7 +546,7 @@ const R = class R {
546
546
  * @param {RouteTarget} target - 路由目标
547
547
  */
548
548
  createRouteLocation(t) {
549
- if (gt(t)) return t;
549
+ if (yt(t)) return t;
550
550
  const i = this.findRoute(t), { index: n, query: s = {}, params: r = {}, hash: o = "" } = t;
551
551
  let l;
552
552
  const c = [];
@@ -682,7 +682,7 @@ const R = class R {
682
682
  */
683
683
  matchRoute(t) {
684
684
  if (t = m(t), this._options.strict || (t = t.toLowerCase()), this.suffix) {
685
- const { path: s, suffix: r } = Rt(t);
685
+ const { path: s, suffix: r } = wt(t);
686
686
  if (!this.isAllowedSuffix(r))
687
687
  return;
688
688
  t = s;
@@ -713,7 +713,7 @@ const R = class R {
713
713
  * @return {string}
714
714
  */
715
715
  makeFullPath(t, i, n) {
716
- return n && !n.startsWith("#") && (n = `#${n}`), typeof i == "object" && (i = dt(i)), this.mode === "hash" ? m(`${this.basePath}/#${t}${i}${n}`) : m(`${this.basePath}${t}${i}${n}`);
716
+ return n && !n.startsWith("#") && (n = `#${n}`), typeof i == "object" && (i = gt(i)), this.mode === "hash" ? m(`${this.basePath}/#${t}${i}${n}`) : m(`${this.basePath}${t}${i}${n}`);
717
717
  }
718
718
  /**
719
719
  * 判断是否相同的导航请求
@@ -753,7 +753,7 @@ const R = class R {
753
753
  * @param {RouteLocation} newLocation - 新的路由数据对象
754
754
  */
755
755
  updateRouteLocation(t) {
756
- yt(this._currentRouteLocation, t);
756
+ ot(this._currentRouteLocation, t);
757
757
  }
758
758
  /**
759
759
  * 判断是否为允许的后缀
@@ -818,7 +818,7 @@ const R = class R {
818
818
  }
819
819
  };
820
820
  s(n);
821
- const r = ut(t);
821
+ const r = dt(t);
822
822
  if (r > 0)
823
823
  for (let o = 1; o <= r; o++)
824
824
  s(n - o);
@@ -840,7 +840,7 @@ const R = class R {
840
840
  * @protected
841
841
  */
842
842
  registerRoute(t, i) {
843
- const n = mt(t);
843
+ const n = _t(t);
844
844
  if (i && (n.path = m(`${i.path}${n.path}`), this._parentRoute.set(n, i)), A(n)) {
845
845
  t.widget && this.recordRoute(n);
846
846
  for (const s of n.children)
@@ -881,7 +881,7 @@ const R = class R {
881
881
  * @param route
882
882
  */
883
883
  recordDynamicRoute(t) {
884
- const { regex: i, length: n, optional: s } = lt(
884
+ const { regex: i, length: n, optional: s } = pt(
885
885
  t.path,
886
886
  t.pattern,
887
887
  this.options.strict,
@@ -909,7 +909,7 @@ class xt extends d {
909
909
  * @returns {RouteTarget} - 包含 index、hash 和 query 的对象
910
910
  */
911
911
  get currentRouteTarget() {
912
- return pt(window.location, this.mode, this.basePath);
912
+ return mt(window.location, this.mode, this.basePath);
913
913
  }
914
914
  /**
915
915
  * window.history
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitarx-router",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "type": "module",
5
5
  "main": "dist/vitarx-router.js",
6
6
  "types": "dist/vitarx-router.d.ts",
@@ -13,7 +13,7 @@
13
13
  "push": "npm publish --access=public"
14
14
  },
15
15
  "peerDependencies": {
16
- "vitarx": "^1.0.0-beta.20"
16
+ "vitarx": "^1.0.0-beta.21"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^22.10.0",