@studiolambda/router 1.0.0 → 2.0.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.
- package/dist/router_react.cjs +1 -1
- package/dist/router_react.cjs.map +1 -1
- package/dist/router_react.js +92 -59
- package/dist/router_react.js.map +1 -1
- package/dist/src/react/components/NotFound.d.ts +5 -2
- package/dist/src/react/components/Router.d.ts +1 -1
- package/dist/src/react/context/NavigationSignalContext.d.ts +6 -1
- package/dist/src/react/context/NavigationTypeContext.d.ts +6 -1
- package/dist/src/react/context/ParamsContext.d.ts +10 -0
- package/dist/src/react/context/PathnameContext.d.ts +5 -4
- package/dist/src/react/context/TransitionContext.d.ts +0 -6
- package/dist/src/react/extractPathname.d.ts +1 -2
- package/dist/src/react/hooks/useNavigate.d.ts +15 -0
- package/dist/src/react/hooks/useNavigation.d.ts +10 -0
- package/dist/src/react/hooks/useNavigationEvents.d.ts +18 -0
- package/dist/src/react/hooks/useNavigationHandlers.d.ts +9 -0
- package/dist/src/react/hooks/useNavigationSignal.d.ts +15 -0
- package/dist/src/react/hooks/useNavigationType.d.ts +18 -0
- package/dist/src/react/hooks/useNextMatch.d.ts +11 -0
- package/dist/src/react/hooks/useParams.d.ts +1 -0
- package/dist/src/react/hooks/usePathname.d.ts +1 -0
- package/dist/src/react/hooks/usePrefetch.d.ts +52 -0
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/navigation/createMemoryNavigation.d.ts +5 -1
- package/package.json +1 -1
- package/dist/src/react/context/PropsContext.d.ts +0 -10
package/dist/router_react.js
CHANGED
|
@@ -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(
|
|
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("
|
|
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(
|
|
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 =
|
|
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:
|
|
239
|
+
isActive: r,
|
|
232
240
|
props: {
|
|
233
|
-
"data-active":
|
|
234
|
-
"aria-current":
|
|
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
|
|
268
|
-
let { href: n, on: r, once: i = !0, matcher: s } = t, c =
|
|
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
|
|
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],
|
|
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
|
|
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
|
|
330
|
-
let e =
|
|
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
|
|
338
|
-
|
|
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
|
|
343
|
-
|
|
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
|
|
348
|
-
|
|
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
|
|
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
|
|
360
|
-
|
|
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
|
|
365
|
-
let e =
|
|
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
|
|
375
|
-
let e =
|
|
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
|
|
395
|
-
let e =
|
|
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
|
|
415
|
-
let t = { url: e.url }
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
|
425
|
-
|
|
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:
|
|
433
|
-
removeEventListener:
|
|
434
|
-
navigate:
|
|
435
|
-
|
|
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
|
|
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
|
|
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
|
|
481
|
+
function X() {
|
|
449
482
|
return null;
|
|
450
483
|
}
|
|
451
|
-
function
|
|
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 =
|
|
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
|
|
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:
|
|
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,
|
|
519
|
-
prefix:
|
|
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
|
|
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
|
|
573
|
+
function $(t) {
|
|
541
574
|
let n = e(), r = /* @__PURE__ */ new Map();
|
|
542
|
-
return t(
|
|
575
|
+
return t(Z(n, {
|
|
543
576
|
prefix: "",
|
|
544
577
|
middlewares: [],
|
|
545
578
|
prefetches: []
|
|
546
|
-
}, r)),
|
|
579
|
+
}, r)), Q(r), n;
|
|
547
580
|
}
|
|
548
581
|
//#endregion
|
|
549
|
-
export {
|
|
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
|