@studiolambda/router 1.0.0 → 2.1.0

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.
@@ -28,12 +28,12 @@ var p = /* @__PURE__ */ u(((e) => {
28
28
  })();
29
29
  })), h = (/* @__PURE__ */ u(((e, t) => {
30
30
  process.env.NODE_ENV === "production" ? t.exports = p() : t.exports = m();
31
- })))(), g = r({}), _ = r(null), v = r(null), y = r(null);
31
+ })))(), g = r(null), _ = r(null), v = r(void 0), y = r(void 0);
32
32
  //#endregion
33
33
  //#region src/react/components/NotFound.tsx
34
34
  function b() {
35
35
  let e = (0, h.c)(1), n;
36
- return e[0] === Symbol.for("react.memo_cache_sentinel") ? (n = /* @__PURE__ */ t("div", { children: "Not Found" }), e[0] = n) : n = e[0], n;
36
+ return e[0] === Symbol.for("react.memo_cache_sentinel") ? (n = /* @__PURE__ */ t("h1", { children: "Not Found" }), e[0] = n) : n = e[0], n;
37
37
  }
38
38
  //#endregion
39
39
  //#region src/react/context/TransitionContext.ts
@@ -106,11 +106,11 @@ function T(e, t) {
106
106
  }
107
107
  //#endregion
108
108
  //#region src/react/context/PathnameContext.ts
109
- var E = r("/"), D = r(null);
109
+ var E = r(null), D = r(null);
110
110
  //#endregion
111
111
  //#region src/react/extractPathname.ts
112
112
  function O(e) {
113
- return e ? new URL(e, "http://localhost").pathname : "/";
113
+ return e == null ? "/" : new URL(e, "http://localhost").pathname;
114
114
  }
115
115
  //#endregion
116
116
  //#region src/react/components/Router.tsx
@@ -226,12 +226,20 @@ function k(e) {
226
226
  //#endregion
227
227
  //#region src/react/hooks/useActiveLinkProps.ts
228
228
  function A(e, t) {
229
- let n = j(e, i(E), t?.exact ?? !0);
229
+ let n = i(E);
230
+ if (n === null) return {
231
+ isActive: !1,
232
+ props: {
233
+ "data-active": void 0,
234
+ "aria-current": void 0
235
+ }
236
+ };
237
+ let r = j(e, n, t?.exact ?? !0);
230
238
  return {
231
- isActive: n,
239
+ isActive: r,
232
240
  props: {
233
- "data-active": n || void 0,
234
- "aria-current": n ? "page" : void 0
241
+ "data-active": r || void 0,
242
+ "aria-current": r ? "page" : void 0
235
243
  }
236
244
  };
237
245
  }
@@ -244,6 +252,9 @@ function j(e, t, n) {
244
252
  //#region src/react/hooks/usePrefetch.ts
245
253
  var M = /* @__PURE__ */ new WeakMap();
246
254
  function N(e) {
255
+ M.delete(e);
256
+ }
257
+ function P(e) {
247
258
  let t = e?.matcher ?? i(C);
248
259
  return function(e) {
249
260
  let n = new URL(e, "http://localhost"), r = t.match(n.pathname);
@@ -264,8 +275,8 @@ function N(e) {
264
275
  }
265
276
  //#endregion
266
277
  //#region src/react/hooks/usePrefetchEffect.ts
267
- function P(e, t) {
268
- let { href: n, on: r, once: i = !0, matcher: s } = t, c = N({ matcher: s }), l = o(function(e, t) {
278
+ function F(e, t) {
279
+ let { href: n, on: r, once: i = !0, matcher: s } = t, c = P({ matcher: s }), l = o(function(e, t) {
269
280
  for (let t of e) t.isIntersecting && n !== void 0 && c(n);
270
281
  i && t.disconnect();
271
282
  }), u = o(function() {
@@ -294,7 +305,7 @@ function P(e, t) {
294
305
  }
295
306
  //#endregion
296
307
  //#region src/react/components/Link.tsx
297
- function F(e) {
308
+ function I(e) {
298
309
  let n = (0, h.c)(23), r, i, a, o, c, l, u;
299
310
  n[0] === e ? (r = n[1], i = n[2], a = n[3], o = n[4], c = n[5], l = n[6], u = n[7]) : ({prefetch: o, once: l, href: i, matcher: a, className: r, activeExact: u, ...c} = e, n[0] = e, n[1] = r, n[2] = i, n[3] = a, n[4] = o, n[5] = c, n[6] = l, n[7] = u);
300
311
  let d = l === void 0 ? !0 : l, f = u === void 0 ? !0 : u, p = s(null), m;
@@ -305,7 +316,7 @@ function F(e) {
305
316
  on: o,
306
317
  once: d,
307
318
  matcher: a
308
- }, n[10] = i, n[11] = a, n[12] = d, n[13] = o, n[14] = v) : v = n[14], P(p, v);
319
+ }, n[10] = i, n[11] = a, n[12] = d, n[13] = o, n[14] = v) : v = n[14], F(p, v);
309
320
  let y;
310
321
  n[15] !== r || n[16] !== g ? (y = typeof r == "function" ? r({ isActive: g }) : r, n[15] = r, n[16] = g, n[17] = y) : y = n[17];
311
322
  let b = y, x;
@@ -319,50 +330,58 @@ function F(e) {
319
330
  }
320
331
  //#endregion
321
332
  //#region src/react/hooks/useNavigation.ts
322
- function I() {
333
+ function L() {
323
334
  let e = i(_);
324
335
  if (e === null) throw Error("useNavigation requires a <Router> or <NavigationContext> provider");
325
336
  return e;
326
337
  }
327
338
  //#endregion
328
339
  //#region src/react/hooks/useNavigate.ts
329
- function L() {
330
- let e = I();
340
+ function R() {
341
+ let e = L();
331
342
  return function(t, n) {
332
343
  return e.navigate(t, n);
333
344
  };
334
345
  }
335
346
  //#endregion
336
347
  //#region src/react/hooks/useNavigationSignal.ts
337
- function R() {
338
- return i(v);
348
+ function z() {
349
+ let e = i(v);
350
+ if (e === void 0) throw Error("useNavigationSignal requires a <Router> or <NavigationSignalContext> provider");
351
+ return e;
339
352
  }
340
353
  //#endregion
341
354
  //#region src/react/hooks/useNavigationType.ts
342
- function z() {
343
- return i(y);
355
+ function B() {
356
+ let e = i(y);
357
+ if (e === void 0) throw Error("useNavigationType requires a <Router> or <NavigationTypeContext> provider");
358
+ return e;
344
359
  }
345
360
  //#endregion
346
361
  //#region src/react/hooks/useParams.ts
347
- function B() {
348
- return i(g);
362
+ function V() {
363
+ let e = i(g);
364
+ if (e === null) throw Error("useParams requires a <Router> or <ParamsContext> provider");
365
+ return e;
349
366
  }
350
367
  //#endregion
351
368
  //#region src/react/hooks/useIsPending.ts
352
- function V() {
369
+ function H() {
353
370
  let e = i(x);
354
371
  if (e === null) throw Error("useIsPending requires a <Router> or <TransitionContext> provider");
355
372
  return e[0];
356
373
  }
357
374
  //#endregion
358
375
  //#region src/react/hooks/usePathname.ts
359
- function H() {
360
- return i(E);
376
+ function U() {
377
+ let e = i(E);
378
+ if (e === null) throw Error("usePathname requires a <Router> or <PathnameContext> provider");
379
+ return e;
361
380
  }
362
381
  //#endregion
363
382
  //#region src/react/hooks/useSearchParams.ts
364
- function U() {
365
- let e = I(), t = i(D), n = t ? new URL(t, "http://localhost").searchParams : new URLSearchParams();
383
+ function W() {
384
+ let e = L(), t = i(D), n = t ? new URL(t, "http://localhost").searchParams : new URLSearchParams();
366
385
  function r(n, r) {
367
386
  let i = new URL(t ?? "/", "http://localhost"), a = typeof n == "function" ? n(i.searchParams) : n, o = (a instanceof URLSearchParams ? a : new URLSearchParams(a)).toString(), s = i.pathname + (o ? "?" + o : "") + i.hash;
368
387
  return e.navigate(s, { history: r?.history ?? "replace" });
@@ -371,8 +390,8 @@ function U() {
371
390
  }
372
391
  //#endregion
373
392
  //#region src/react/hooks/useBack.ts
374
- function W() {
375
- let e = I(), [t, n] = c(e.canGoBack);
393
+ function G() {
394
+ let e = L(), [t, n] = c(e.canGoBack);
376
395
  a(function() {
377
396
  function t() {
378
397
  n(e.canGoBack);
@@ -391,8 +410,8 @@ function W() {
391
410
  }
392
411
  //#endregion
393
412
  //#region src/react/hooks/useForward.ts
394
- function G() {
395
- let e = I(), [t, n] = c(e.canGoForward);
413
+ function K() {
414
+ let e = L(), [t, n] = c(e.canGoForward);
396
415
  a(function() {
397
416
  function t() {
398
417
  n(e.canGoForward);
@@ -411,44 +430,58 @@ function G() {
411
430
  }
412
431
  //#endregion
413
432
  //#region src/react/navigation/createMemoryNavigation.ts
414
- function K(e) {
415
- let t = { url: e.url };
416
- function n() {}
417
- function r() {}
418
- function i() {
419
- return {
420
- committed: Promise.resolve(t),
421
- finished: Promise.resolve(t)
422
- };
433
+ function q(e) {
434
+ let t = { url: e.url }, n = t, r = {
435
+ committed: Promise.resolve(n),
436
+ finished: Promise.resolve(n)
437
+ };
438
+ function i() {}
439
+ function a() {}
440
+ function o() {
441
+ return r;
442
+ }
443
+ function s() {
444
+ return r;
445
+ }
446
+ function c() {
447
+ return r;
448
+ }
449
+ function l() {
450
+ return r;
423
451
  }
424
- function a() {
425
- return [t];
452
+ function u() {}
453
+ function d() {
454
+ return [n];
426
455
  }
427
456
  return {
428
457
  currentEntry: t,
429
458
  canGoBack: !1,
430
459
  canGoForward: !1,
431
460
  transition: null,
432
- addEventListener: n,
433
- removeEventListener: r,
434
- navigate: i,
435
- entries: a
461
+ addEventListener: i,
462
+ removeEventListener: a,
463
+ navigate: o,
464
+ back: s,
465
+ forward: c,
466
+ traverseTo: l,
467
+ updateCurrentEntry: u,
468
+ entries: d
436
469
  };
437
470
  }
438
471
  //#endregion
439
472
  //#region src/react/createRouter.ts
440
- function q(e, t) {
473
+ function J(e, t) {
441
474
  return e === "" && t === "" ? "" : e === "" ? t : t === "" || t === "/" ? e : (e.endsWith("/") ? e.slice(0, -1) : e) + (t.startsWith("/") ? t : "/" + t);
442
475
  }
443
- function J(e) {
476
+ function Y(e) {
444
477
  if (e.length !== 0) return e.length === 1 ? e[0] : async function(t) {
445
478
  for (let n of e) await n(t);
446
479
  };
447
480
  }
448
- function Y() {
481
+ function X() {
449
482
  return null;
450
483
  }
451
- function X(e, t, n) {
484
+ function Z(e, t, n) {
452
485
  return function(r) {
453
486
  let i = {
454
487
  path: r,
@@ -462,7 +495,7 @@ function X(e, t, n) {
462
495
  if (a) throw Error(`cannot call .${e}() on a route builder that has already been consumed by .render(), .redirect(), or .group()`);
463
496
  }
464
497
  function s() {
465
- let e = q(t.prefix, i.path ?? "");
498
+ let e = J(t.prefix, i.path ?? "");
466
499
  if (e === "") throw Error("cannot register a route without a path or group prefix");
467
500
  return e;
468
501
  }
@@ -471,7 +504,7 @@ function X(e, t, n) {
471
504
  return e.length > 0 ? e : void 0;
472
505
  }
473
506
  function l() {
474
- return J([...t.prefetches, ...i.prefetches]);
507
+ return Y([...t.prefetches, ...i.prefetches]);
475
508
  }
476
509
  let u = {
477
510
  middleware(e) {
@@ -506,7 +539,7 @@ function X(e, t, n) {
506
539
  let r = s();
507
540
  typeof t == "string" && n.set(r, t);
508
541
  let i = {
509
- component: Y,
542
+ component: X,
510
543
  prefetch: function(e) {
511
544
  let n = typeof t == "function" ? t(e) : t;
512
545
  e.controller.redirect(n);
@@ -515,8 +548,8 @@ function X(e, t, n) {
515
548
  e.register(r, i);
516
549
  },
517
550
  group() {
518
- return o("group"), a = !0, X(e, {
519
- prefix: q(t.prefix, i.path ?? ""),
551
+ return o("group"), a = !0, Z(e, {
552
+ prefix: J(t.prefix, i.path ?? ""),
520
553
  middlewares: [...t.middlewares, ...i.middlewares],
521
554
  prefetches: [...t.prefetches, ...i.prefetches]
522
555
  }, n);
@@ -525,7 +558,7 @@ function X(e, t, n) {
525
558
  return u;
526
559
  };
527
560
  }
528
- function Z(e) {
561
+ function Q(e) {
529
562
  for (let [t] of e) {
530
563
  let n = /* @__PURE__ */ new Set(), r = t;
531
564
  for (; e.has(r);) {
@@ -537,15 +570,15 @@ function Z(e) {
537
570
  }
538
571
  }
539
572
  }
540
- function Q(t) {
573
+ function $(t) {
541
574
  let n = e(), r = /* @__PURE__ */ new Map();
542
- return t(X(n, {
575
+ return t(Z(n, {
543
576
  prefix: "",
544
577
  middlewares: [],
545
578
  prefetches: []
546
- }, r)), Z(r), n;
579
+ }, r)), Q(r), n;
547
580
  }
548
581
  //#endregion
549
- export { F as Link, C as MatcherContext, f as Middlewares, _ as NavigationContext, v as NavigationSignalContext, y as NavigationTypeContext, b as NotFound, g as ParamsContext, E as PathnameContext, k as Router, x as TransitionContext, D as UrlContext, K as createMemoryNavigation, Q as createRouter, O as extractPathname, A as useActiveLinkProps, W as useBack, G as useForward, V as useIsPending, L as useNavigate, I as useNavigation, T as useNavigationEvents, S as useNavigationHandlers, R as useNavigationSignal, z as useNavigationType, w as useNextMatch, B as useParams, H as usePathname, N as usePrefetch, P as usePrefetchEffect, U as useSearchParams };
582
+ export { I as Link, C as MatcherContext, f as Middlewares, _ as NavigationContext, v as NavigationSignalContext, y as NavigationTypeContext, b as NotFound, g as ParamsContext, E as PathnameContext, k as Router, x as TransitionContext, D as UrlContext, N as clearPrefetchCache, q as createMemoryNavigation, $ as createRouter, O as extractPathname, A as useActiveLinkProps, G as useBack, K as useForward, H as useIsPending, R as useNavigate, L as useNavigation, T as useNavigationEvents, S as useNavigationHandlers, z as useNavigationSignal, B as useNavigationType, w as useNextMatch, V as useParams, U as usePathname, P as usePrefetch, F as usePrefetchEffect, W as useSearchParams };
550
583
 
551
584
  //# sourceMappingURL=router_react.js.map