@real-router/solid 0.4.0 → 0.4.1
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/cjs/index.js +11 -65
- package/dist/esm/index.mjs +12 -66
- package/dist/types/components/Link.d.ts.map +1 -1
- package/dist/types/components/RouterErrorBoundary.d.ts.map +1 -1
- package/dist/types/hooks/useRouteNode.d.ts.map +1 -1
- package/dist/types/hooks/useRouteNodeStore.d.ts.map +1 -1
- package/dist/types/hooks/useRouterTransition.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/Link.tsx +5 -45
- package/src/components/RouterErrorBoundary.tsx +8 -14
- package/src/hooks/useRouteNode.tsx +3 -2
- package/src/hooks/useRouteNodeStore.tsx +3 -2
- package/src/hooks/useRouterTransition.tsx +3 -15
- package/dist/types/hooks/sharedNodeSource.d.ts +0 -4
- package/dist/types/hooks/sharedNodeSource.d.ts.map +0 -1
- package/dist/types/hooks/useRouterError.d.ts +0 -4
- package/dist/types/hooks/useRouterError.d.ts.map +0 -1
- package/src/hooks/sharedNodeSource.ts +0 -30
- package/src/hooks/useRouterError.tsx +0 -23
package/dist/cjs/index.js
CHANGED
|
@@ -121,21 +121,6 @@ function createSignalFromSource(source) {
|
|
|
121
121
|
return value;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const cache$2 = new WeakMap();
|
|
125
|
-
function getOrCreateNodeSource(router, nodeName) {
|
|
126
|
-
let perRouter = cache$2.get(router);
|
|
127
|
-
if (!perRouter) {
|
|
128
|
-
perRouter = new Map();
|
|
129
|
-
cache$2.set(router, perRouter);
|
|
130
|
-
}
|
|
131
|
-
let source = perRouter.get(nodeName);
|
|
132
|
-
if (!source) {
|
|
133
|
-
source = sources.createRouteNodeSource(router, nodeName);
|
|
134
|
-
perRouter.set(nodeName, source);
|
|
135
|
-
}
|
|
136
|
-
return source;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
124
|
const RouterContext = solidJs.createContext(null);
|
|
140
125
|
const RouteContext = solidJs.createContext(null);
|
|
141
126
|
|
|
@@ -149,7 +134,7 @@ const useRouter = () => {
|
|
|
149
134
|
|
|
150
135
|
function useRouteNode(nodeName) {
|
|
151
136
|
const router = useRouter();
|
|
152
|
-
return createSignalFromSource(
|
|
137
|
+
return createSignalFromSource(sources.createRouteNodeSource(router, nodeName));
|
|
153
138
|
}
|
|
154
139
|
|
|
155
140
|
function RouteViewRoot(props) {
|
|
@@ -357,27 +342,6 @@ function applyLinkA11y(element) {
|
|
|
357
342
|
}
|
|
358
343
|
|
|
359
344
|
var _tmpl$ = /*#__PURE__*/web.template(`<a>`);
|
|
360
|
-
// Slow-path source cache: shared per-router, keyed by routeName + params + flags.
|
|
361
|
-
// Captured slow-path values are stable per Link (props captured at init), so the
|
|
362
|
-
// cache key is guaranteed stable for the lifetime of any consumer.
|
|
363
|
-
const activeSourceCache = new WeakMap();
|
|
364
|
-
function getOrCreateActiveSource(router, routeName, routeParams, activeStrict, ignoreQueryParams) {
|
|
365
|
-
let perRouter = activeSourceCache.get(router);
|
|
366
|
-
if (!perRouter) {
|
|
367
|
-
perRouter = new Map();
|
|
368
|
-
activeSourceCache.set(router, perRouter);
|
|
369
|
-
}
|
|
370
|
-
const key = `${routeName}|${JSON.stringify(routeParams)}|${activeStrict}|${ignoreQueryParams}`;
|
|
371
|
-
let source = perRouter.get(key);
|
|
372
|
-
if (!source) {
|
|
373
|
-
source = sources.createActiveRouteSource(router, routeName, routeParams, {
|
|
374
|
-
strict: activeStrict,
|
|
375
|
-
ignoreQueryParams
|
|
376
|
-
});
|
|
377
|
-
perRouter.set(key, source);
|
|
378
|
-
}
|
|
379
|
-
return source;
|
|
380
|
-
}
|
|
381
345
|
function Link(props) {
|
|
382
346
|
const merged = solidJs.mergeProps({
|
|
383
347
|
routeParams: EMPTY_PARAMS,
|
|
@@ -393,7 +357,10 @@ function Link(props) {
|
|
|
393
357
|
}
|
|
394
358
|
const router = ctx.router;
|
|
395
359
|
const useFastPath = !local.activeStrict && local.ignoreQueryParams && local.routeParams === EMPTY_PARAMS;
|
|
396
|
-
const isActive = useFastPath ? () => ctx.routeSelector(local.routeName) : createSignalFromSource(
|
|
360
|
+
const isActive = useFastPath ? () => ctx.routeSelector(local.routeName) : createSignalFromSource(sources.createActiveRouteSource(router, local.routeName, local.routeParams, {
|
|
361
|
+
strict: local.activeStrict,
|
|
362
|
+
ignoreQueryParams: local.ignoreQueryParams
|
|
363
|
+
}));
|
|
397
364
|
const href = solidJs.createMemo(() => buildHref(router, local.routeName, local.routeParams));
|
|
398
365
|
const handleClick = evt => {
|
|
399
366
|
if (local.onClick) {
|
|
@@ -425,36 +392,20 @@ function Link(props) {
|
|
|
425
392
|
})();
|
|
426
393
|
}
|
|
427
394
|
|
|
428
|
-
const cache$1 = new WeakMap();
|
|
429
|
-
function useRouterError() {
|
|
430
|
-
const router = useRouter();
|
|
431
|
-
let source = cache$1.get(router);
|
|
432
|
-
if (!source) {
|
|
433
|
-
source = sources.createErrorSource(router);
|
|
434
|
-
cache$1.set(router, source);
|
|
435
|
-
}
|
|
436
|
-
return createSignalFromSource(source);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
395
|
function RouterErrorBoundary(props) {
|
|
440
|
-
const
|
|
441
|
-
const
|
|
396
|
+
const router = useRouter();
|
|
397
|
+
const snapshot = createSignalFromSource(sources.createDismissableError(router));
|
|
442
398
|
solidJs.createEffect(() => {
|
|
443
399
|
const snap = snapshot();
|
|
444
400
|
if (snap.error) {
|
|
445
401
|
props.onError?.(snap.error, snap.toRoute, snap.fromRoute);
|
|
446
402
|
}
|
|
447
403
|
});
|
|
448
|
-
const visibleError = solidJs.createMemo(() => {
|
|
449
|
-
const snap = snapshot();
|
|
450
|
-
return snap.version > dismissedVersion() ? snap.error : null;
|
|
451
|
-
});
|
|
452
|
-
const resetError = () => setDismissedVersion(snapshot().version);
|
|
453
404
|
return [web.memo(() => props.children), web.createComponent(solidJs.Show, {
|
|
454
405
|
get when() {
|
|
455
|
-
return
|
|
406
|
+
return snapshot().error;
|
|
456
407
|
},
|
|
457
|
-
children: error => props.fallback(error(), resetError)
|
|
408
|
+
children: error => props.fallback(error(), snapshot().resetError)
|
|
458
409
|
})];
|
|
459
410
|
}
|
|
460
411
|
|
|
@@ -541,17 +492,12 @@ function useRouteStore() {
|
|
|
541
492
|
|
|
542
493
|
function useRouteNodeStore(nodeName) {
|
|
543
494
|
const router = useRouter();
|
|
544
|
-
return createStoreFromSource(
|
|
495
|
+
return createStoreFromSource(sources.createRouteNodeSource(router, nodeName));
|
|
545
496
|
}
|
|
546
497
|
|
|
547
|
-
const cache = new WeakMap();
|
|
548
498
|
function useRouterTransition() {
|
|
549
499
|
const router = useRouter();
|
|
550
|
-
|
|
551
|
-
if (!source) {
|
|
552
|
-
source = sources.createTransitionSource(router);
|
|
553
|
-
cache.set(router, source);
|
|
554
|
-
}
|
|
500
|
+
const source = sources.getTransitionSource(router);
|
|
555
501
|
return createSignalFromSource(source);
|
|
556
502
|
}
|
|
557
503
|
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent, memo, spread, mergeProps as mergeProps$1, insert, template } from 'solid-js/web';
|
|
2
|
-
import { createRouteNodeSource, createActiveRouteSource,
|
|
2
|
+
import { createRouteNodeSource, createActiveRouteSource, createDismissableError, createRouteSource, getTransitionSource } from '@real-router/sources';
|
|
3
3
|
import { Suspense, createSignal, onCleanup, createContext, useContext, children, createMemo, mergeProps, splitProps, createEffect, Show, onMount, createSelector } from 'solid-js';
|
|
4
4
|
import { getPluginApi } from '@real-router/core/api';
|
|
5
5
|
import { startsWithSegment, getRouteUtils } from '@real-router/route-utils';
|
|
@@ -119,21 +119,6 @@ function createSignalFromSource(source) {
|
|
|
119
119
|
return value;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
const cache$2 = new WeakMap();
|
|
123
|
-
function getOrCreateNodeSource(router, nodeName) {
|
|
124
|
-
let perRouter = cache$2.get(router);
|
|
125
|
-
if (!perRouter) {
|
|
126
|
-
perRouter = new Map();
|
|
127
|
-
cache$2.set(router, perRouter);
|
|
128
|
-
}
|
|
129
|
-
let source = perRouter.get(nodeName);
|
|
130
|
-
if (!source) {
|
|
131
|
-
source = createRouteNodeSource(router, nodeName);
|
|
132
|
-
perRouter.set(nodeName, source);
|
|
133
|
-
}
|
|
134
|
-
return source;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
122
|
const RouterContext = createContext(null);
|
|
138
123
|
const RouteContext = createContext(null);
|
|
139
124
|
|
|
@@ -147,7 +132,7 @@ const useRouter = () => {
|
|
|
147
132
|
|
|
148
133
|
function useRouteNode(nodeName) {
|
|
149
134
|
const router = useRouter();
|
|
150
|
-
return createSignalFromSource(
|
|
135
|
+
return createSignalFromSource(createRouteNodeSource(router, nodeName));
|
|
151
136
|
}
|
|
152
137
|
|
|
153
138
|
function RouteViewRoot(props) {
|
|
@@ -355,27 +340,6 @@ function applyLinkA11y(element) {
|
|
|
355
340
|
}
|
|
356
341
|
|
|
357
342
|
var _tmpl$ = /*#__PURE__*/template(`<a>`);
|
|
358
|
-
// Slow-path source cache: shared per-router, keyed by routeName + params + flags.
|
|
359
|
-
// Captured slow-path values are stable per Link (props captured at init), so the
|
|
360
|
-
// cache key is guaranteed stable for the lifetime of any consumer.
|
|
361
|
-
const activeSourceCache = new WeakMap();
|
|
362
|
-
function getOrCreateActiveSource(router, routeName, routeParams, activeStrict, ignoreQueryParams) {
|
|
363
|
-
let perRouter = activeSourceCache.get(router);
|
|
364
|
-
if (!perRouter) {
|
|
365
|
-
perRouter = new Map();
|
|
366
|
-
activeSourceCache.set(router, perRouter);
|
|
367
|
-
}
|
|
368
|
-
const key = `${routeName}|${JSON.stringify(routeParams)}|${activeStrict}|${ignoreQueryParams}`;
|
|
369
|
-
let source = perRouter.get(key);
|
|
370
|
-
if (!source) {
|
|
371
|
-
source = createActiveRouteSource(router, routeName, routeParams, {
|
|
372
|
-
strict: activeStrict,
|
|
373
|
-
ignoreQueryParams
|
|
374
|
-
});
|
|
375
|
-
perRouter.set(key, source);
|
|
376
|
-
}
|
|
377
|
-
return source;
|
|
378
|
-
}
|
|
379
343
|
function Link(props) {
|
|
380
344
|
const merged = mergeProps({
|
|
381
345
|
routeParams: EMPTY_PARAMS,
|
|
@@ -391,7 +355,10 @@ function Link(props) {
|
|
|
391
355
|
}
|
|
392
356
|
const router = ctx.router;
|
|
393
357
|
const useFastPath = !local.activeStrict && local.ignoreQueryParams && local.routeParams === EMPTY_PARAMS;
|
|
394
|
-
const isActive = useFastPath ? () => ctx.routeSelector(local.routeName) : createSignalFromSource(
|
|
358
|
+
const isActive = useFastPath ? () => ctx.routeSelector(local.routeName) : createSignalFromSource(createActiveRouteSource(router, local.routeName, local.routeParams, {
|
|
359
|
+
strict: local.activeStrict,
|
|
360
|
+
ignoreQueryParams: local.ignoreQueryParams
|
|
361
|
+
}));
|
|
395
362
|
const href = createMemo(() => buildHref(router, local.routeName, local.routeParams));
|
|
396
363
|
const handleClick = evt => {
|
|
397
364
|
if (local.onClick) {
|
|
@@ -423,36 +390,20 @@ function Link(props) {
|
|
|
423
390
|
})();
|
|
424
391
|
}
|
|
425
392
|
|
|
426
|
-
const cache$1 = new WeakMap();
|
|
427
|
-
function useRouterError() {
|
|
428
|
-
const router = useRouter();
|
|
429
|
-
let source = cache$1.get(router);
|
|
430
|
-
if (!source) {
|
|
431
|
-
source = createErrorSource(router);
|
|
432
|
-
cache$1.set(router, source);
|
|
433
|
-
}
|
|
434
|
-
return createSignalFromSource(source);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
393
|
function RouterErrorBoundary(props) {
|
|
438
|
-
const
|
|
439
|
-
const
|
|
394
|
+
const router = useRouter();
|
|
395
|
+
const snapshot = createSignalFromSource(createDismissableError(router));
|
|
440
396
|
createEffect(() => {
|
|
441
397
|
const snap = snapshot();
|
|
442
398
|
if (snap.error) {
|
|
443
399
|
props.onError?.(snap.error, snap.toRoute, snap.fromRoute);
|
|
444
400
|
}
|
|
445
401
|
});
|
|
446
|
-
const visibleError = createMemo(() => {
|
|
447
|
-
const snap = snapshot();
|
|
448
|
-
return snap.version > dismissedVersion() ? snap.error : null;
|
|
449
|
-
});
|
|
450
|
-
const resetError = () => setDismissedVersion(snapshot().version);
|
|
451
402
|
return [memo(() => props.children), createComponent(Show, {
|
|
452
403
|
get when() {
|
|
453
|
-
return
|
|
404
|
+
return snapshot().error;
|
|
454
405
|
},
|
|
455
|
-
children: error => props.fallback(error(), resetError)
|
|
406
|
+
children: error => props.fallback(error(), snapshot().resetError)
|
|
456
407
|
})];
|
|
457
408
|
}
|
|
458
409
|
|
|
@@ -539,17 +490,12 @@ function useRouteStore() {
|
|
|
539
490
|
|
|
540
491
|
function useRouteNodeStore(nodeName) {
|
|
541
492
|
const router = useRouter();
|
|
542
|
-
return createStoreFromSource(
|
|
493
|
+
return createStoreFromSource(createRouteNodeSource(router, nodeName));
|
|
543
494
|
}
|
|
544
495
|
|
|
545
|
-
const cache = new WeakMap();
|
|
546
496
|
function useRouterTransition() {
|
|
547
497
|
const router = useRouter();
|
|
548
|
-
|
|
549
|
-
if (!source) {
|
|
550
|
-
source = createTransitionSource(router);
|
|
551
|
-
cache.set(router, source);
|
|
552
|
-
}
|
|
498
|
+
const source = getTransitionSource(router);
|
|
553
499
|
return createSignalFromSource(source);
|
|
554
500
|
}
|
|
555
501
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/components/Link.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/components/Link.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC5C,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAC5B,GAAG,CAAC,OAAO,CAoFb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/RouterErrorBoundary.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RouterErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/RouterErrorBoundary.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,IAAI,KACnB,GAAG,CAAC,OAAO,CAAC;IACjB,QAAQ,CAAC,OAAO,CAAC,EAAE,CACjB,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,KAAK,GAAG,IAAI,EACrB,SAAS,EAAE,KAAK,GAAG,IAAI,KACpB,IAAI,CAAC;CACX;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,wBAAwB,GAC9B,GAAG,CAAC,OAAO,CAoBb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRouteNode.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRouteNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRouteNode.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAInE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteNodeStore.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRouteNodeStore.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRouteNodeStore.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRouteNodeStore.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAI9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouterTransition.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRouterTransition.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRouterTransition.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRouterTransition.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,mBAAmB,IAAI,QAAQ,CAAC,wBAAwB,CAAC,CAKxE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/solid",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "Solid.js integration for Real-Router",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@real-router/core": "^0.48.0",
|
|
55
55
|
"@real-router/route-utils": "^0.2.1",
|
|
56
|
-
"@real-router/sources": "^0.
|
|
56
|
+
"@real-router/sources": "^0.6.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@babel/core": "7.29.0",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"solid-js": "1.9.12",
|
|
72
72
|
"vite-plugin-solid": "2.11.11",
|
|
73
73
|
"vitest": "4.1.0",
|
|
74
|
-
"@real-router/browser-plugin": "^0.
|
|
74
|
+
"@real-router/browser-plugin": "^0.13.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"solid-js": ">=1.7.0"
|
package/src/components/Link.tsx
CHANGED
|
@@ -11,46 +11,9 @@ import {
|
|
|
11
11
|
} from "../dom-utils/index.js";
|
|
12
12
|
|
|
13
13
|
import type { LinkProps } from "../types";
|
|
14
|
-
import type { Params
|
|
15
|
-
import type { RouterSource } from "@real-router/sources";
|
|
14
|
+
import type { Params } from "@real-router/core";
|
|
16
15
|
import type { JSX } from "solid-js";
|
|
17
16
|
|
|
18
|
-
// Slow-path source cache: shared per-router, keyed by routeName + params + flags.
|
|
19
|
-
// Captured slow-path values are stable per Link (props captured at init), so the
|
|
20
|
-
// cache key is guaranteed stable for the lifetime of any consumer.
|
|
21
|
-
const activeSourceCache = new WeakMap<
|
|
22
|
-
Router,
|
|
23
|
-
Map<string, RouterSource<boolean>>
|
|
24
|
-
>();
|
|
25
|
-
|
|
26
|
-
function getOrCreateActiveSource(
|
|
27
|
-
router: Router,
|
|
28
|
-
routeName: string,
|
|
29
|
-
routeParams: Params,
|
|
30
|
-
activeStrict: boolean,
|
|
31
|
-
ignoreQueryParams: boolean,
|
|
32
|
-
): RouterSource<boolean> {
|
|
33
|
-
let perRouter = activeSourceCache.get(router);
|
|
34
|
-
|
|
35
|
-
if (!perRouter) {
|
|
36
|
-
perRouter = new Map();
|
|
37
|
-
activeSourceCache.set(router, perRouter);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const key = `${routeName}|${JSON.stringify(routeParams)}|${activeStrict}|${ignoreQueryParams}`;
|
|
41
|
-
let source = perRouter.get(key);
|
|
42
|
-
|
|
43
|
-
if (!source) {
|
|
44
|
-
source = createActiveRouteSource(router, routeName, routeParams, {
|
|
45
|
-
strict: activeStrict,
|
|
46
|
-
ignoreQueryParams,
|
|
47
|
-
});
|
|
48
|
-
perRouter.set(key, source);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return source;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
17
|
export function Link<P extends Params = Params>(
|
|
55
18
|
props: Readonly<LinkProps<P>>,
|
|
56
19
|
): JSX.Element {
|
|
@@ -94,13 +57,10 @@ export function Link<P extends Params = Params>(
|
|
|
94
57
|
const isActive = useFastPath
|
|
95
58
|
? () => ctx.routeSelector(local.routeName)
|
|
96
59
|
: createSignalFromSource(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
local.
|
|
100
|
-
|
|
101
|
-
local.activeStrict,
|
|
102
|
-
local.ignoreQueryParams,
|
|
103
|
-
),
|
|
60
|
+
createActiveRouteSource(router, local.routeName, local.routeParams, {
|
|
61
|
+
strict: local.activeStrict,
|
|
62
|
+
ignoreQueryParams: local.ignoreQueryParams,
|
|
63
|
+
}),
|
|
104
64
|
);
|
|
105
65
|
|
|
106
66
|
const href = createMemo(() =>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createDismissableError } from "@real-router/sources";
|
|
2
|
+
import { createEffect, Show } from "solid-js";
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import { createSignalFromSource } from "../createSignalFromSource";
|
|
5
|
+
import { useRouter } from "../hooks/useRouter";
|
|
4
6
|
|
|
5
7
|
import type { RouterError, State } from "@real-router/core";
|
|
6
8
|
import type { JSX } from "solid-js";
|
|
@@ -21,8 +23,8 @@ export interface RouterErrorBoundaryProps {
|
|
|
21
23
|
export function RouterErrorBoundary(
|
|
22
24
|
props: RouterErrorBoundaryProps,
|
|
23
25
|
): JSX.Element {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
+
const router = useRouter();
|
|
27
|
+
const snapshot = createSignalFromSource(createDismissableError(router));
|
|
26
28
|
|
|
27
29
|
createEffect(() => {
|
|
28
30
|
const snap = snapshot();
|
|
@@ -32,19 +34,11 @@ export function RouterErrorBoundary(
|
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
|
|
35
|
-
const visibleError = createMemo(() => {
|
|
36
|
-
const snap = snapshot();
|
|
37
|
-
|
|
38
|
-
return snap.version > dismissedVersion() ? snap.error : null;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const resetError = () => setDismissedVersion(snapshot().version);
|
|
42
|
-
|
|
43
37
|
return (
|
|
44
38
|
<>
|
|
45
39
|
{props.children}
|
|
46
|
-
<Show when={
|
|
47
|
-
{(error) => props.fallback(error(), resetError)}
|
|
40
|
+
<Show when={snapshot().error}>
|
|
41
|
+
{(error) => props.fallback(error(), snapshot().resetError)}
|
|
48
42
|
</Show>
|
|
49
43
|
</>
|
|
50
44
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createRouteNodeSource } from "@real-router/sources";
|
|
2
|
+
|
|
1
3
|
import { createSignalFromSource } from "../createSignalFromSource";
|
|
2
|
-
import { getOrCreateNodeSource } from "./sharedNodeSource";
|
|
3
4
|
import { useRouter } from "./useRouter";
|
|
4
5
|
|
|
5
6
|
import type { RouteState } from "../types";
|
|
@@ -8,5 +9,5 @@ import type { Accessor } from "solid-js";
|
|
|
8
9
|
export function useRouteNode(nodeName: string): Accessor<RouteState> {
|
|
9
10
|
const router = useRouter();
|
|
10
11
|
|
|
11
|
-
return createSignalFromSource(
|
|
12
|
+
return createSignalFromSource(createRouteNodeSource(router, nodeName));
|
|
12
13
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createRouteNodeSource } from "@real-router/sources";
|
|
2
|
+
|
|
1
3
|
import { createStoreFromSource } from "../createStoreFromSource";
|
|
2
|
-
import { getOrCreateNodeSource } from "./sharedNodeSource";
|
|
3
4
|
import { useRouter } from "./useRouter";
|
|
4
5
|
|
|
5
6
|
import type { RouteState } from "../types";
|
|
@@ -7,5 +8,5 @@ import type { RouteState } from "../types";
|
|
|
7
8
|
export function useRouteNodeStore(nodeName: string): RouteState {
|
|
8
9
|
const router = useRouter();
|
|
9
10
|
|
|
10
|
-
return createStoreFromSource(
|
|
11
|
+
return createStoreFromSource(createRouteNodeSource(router, nodeName));
|
|
11
12
|
}
|
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getTransitionSource } from "@real-router/sources";
|
|
2
2
|
|
|
3
3
|
import { createSignalFromSource } from "../createSignalFromSource";
|
|
4
4
|
import { useRouter } from "./useRouter";
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
RouterSource,
|
|
9
|
-
RouterTransitionSnapshot,
|
|
10
|
-
} from "@real-router/sources";
|
|
6
|
+
import type { RouterTransitionSnapshot } from "@real-router/sources";
|
|
11
7
|
import type { Accessor } from "solid-js";
|
|
12
8
|
|
|
13
|
-
const cache = new WeakMap<Router, RouterSource<RouterTransitionSnapshot>>();
|
|
14
|
-
|
|
15
9
|
export function useRouterTransition(): Accessor<RouterTransitionSnapshot> {
|
|
16
10
|
const router = useRouter();
|
|
17
|
-
|
|
18
|
-
let source = cache.get(router);
|
|
19
|
-
|
|
20
|
-
if (!source) {
|
|
21
|
-
source = createTransitionSource(router);
|
|
22
|
-
cache.set(router, source);
|
|
23
|
-
}
|
|
11
|
+
const source = getTransitionSource(router);
|
|
24
12
|
|
|
25
13
|
return createSignalFromSource(source);
|
|
26
14
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Router } from "@real-router/core";
|
|
2
|
-
import type { RouteNodeSnapshot, RouterSource } from "@real-router/sources";
|
|
3
|
-
export declare function getOrCreateNodeSource(router: Router, nodeName: string): RouterSource<RouteNodeSnapshot>;
|
|
4
|
-
//# sourceMappingURL=sharedNodeSource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sharedNodeSource.d.ts","sourceRoot":"","sources":["../../../src/hooks/sharedNodeSource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAO5E,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,YAAY,CAAC,iBAAiB,CAAC,CAgBjC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRouterError.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRouterError.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIzC,wBAAgB,cAAc,IAAI,QAAQ,CAAC,mBAAmB,CAAC,CAW9D"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createRouteNodeSource } from "@real-router/sources";
|
|
2
|
-
|
|
3
|
-
import type { Router } from "@real-router/core";
|
|
4
|
-
import type { RouteNodeSnapshot, RouterSource } from "@real-router/sources";
|
|
5
|
-
|
|
6
|
-
const cache = new WeakMap<
|
|
7
|
-
Router,
|
|
8
|
-
Map<string, RouterSource<RouteNodeSnapshot>>
|
|
9
|
-
>();
|
|
10
|
-
|
|
11
|
-
export function getOrCreateNodeSource(
|
|
12
|
-
router: Router,
|
|
13
|
-
nodeName: string,
|
|
14
|
-
): RouterSource<RouteNodeSnapshot> {
|
|
15
|
-
let perRouter = cache.get(router);
|
|
16
|
-
|
|
17
|
-
if (!perRouter) {
|
|
18
|
-
perRouter = new Map();
|
|
19
|
-
cache.set(router, perRouter);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let source = perRouter.get(nodeName);
|
|
23
|
-
|
|
24
|
-
if (!source) {
|
|
25
|
-
source = createRouteNodeSource(router, nodeName);
|
|
26
|
-
perRouter.set(nodeName, source);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return source;
|
|
30
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { createErrorSource } from "@real-router/sources";
|
|
2
|
-
|
|
3
|
-
import { createSignalFromSource } from "../createSignalFromSource";
|
|
4
|
-
import { useRouter } from "./useRouter";
|
|
5
|
-
|
|
6
|
-
import type { Router } from "@real-router/core";
|
|
7
|
-
import type { RouterErrorSnapshot, RouterSource } from "@real-router/sources";
|
|
8
|
-
import type { Accessor } from "solid-js";
|
|
9
|
-
|
|
10
|
-
const cache = new WeakMap<Router, RouterSource<RouterErrorSnapshot>>();
|
|
11
|
-
|
|
12
|
-
export function useRouterError(): Accessor<RouterErrorSnapshot> {
|
|
13
|
-
const router = useRouter();
|
|
14
|
-
|
|
15
|
-
let source = cache.get(router);
|
|
16
|
-
|
|
17
|
-
if (!source) {
|
|
18
|
-
source = createErrorSource(router);
|
|
19
|
-
cache.set(router, source);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return createSignalFromSource(source);
|
|
23
|
-
}
|