@tanstack/router-devtools 0.0.1-beta.119 → 0.0.1-beta.121
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/build/cjs/Explorer.js +4 -1
- package/build/cjs/Explorer.js.map +1 -1
- package/build/cjs/devtools.js +33 -16
- package/build/cjs/devtools.js.map +1 -1
- package/build/cjs/utils.js +3 -3
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +41 -21
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +132 -126
- package/build/types/Explorer.d.ts +7 -1
- package/build/umd/index.development.js +93 -30
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +3 -3
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Explorer.tsx +5 -0
- package/src/devtools.tsx +36 -19
- package/src/utils.ts +8 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-devtools",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.121",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router/",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@babel/runtime": "^7.16.7",
|
|
44
44
|
"date-fns": "^2.29.1",
|
|
45
|
-
"@tanstack/router": "0.0.1-beta.
|
|
45
|
+
"@tanstack/router": "0.0.1-beta.121"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rollup --config rollup.config.js"
|
package/src/Explorer.tsx
CHANGED
|
@@ -77,6 +77,7 @@ type RendererProps = {
|
|
|
77
77
|
toggleExpanded: () => void
|
|
78
78
|
pageSize: number
|
|
79
79
|
renderer?: Renderer
|
|
80
|
+
filterSubEntries?: (subEntries: Property[]) => Property[]
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
/**
|
|
@@ -216,6 +217,7 @@ export default function Explorer({
|
|
|
216
217
|
defaultExpanded,
|
|
217
218
|
renderer = DefaultRenderer,
|
|
218
219
|
pageSize = 100,
|
|
220
|
+
filterSubEntries,
|
|
219
221
|
...rest
|
|
220
222
|
}: ExplorerProps) {
|
|
221
223
|
const [expanded, setExpanded] = React.useState(Boolean(defaultExpanded))
|
|
@@ -266,6 +268,8 @@ export default function Explorer({
|
|
|
266
268
|
)
|
|
267
269
|
}
|
|
268
270
|
|
|
271
|
+
subEntries = filterSubEntries ? filterSubEntries(subEntries) : subEntries
|
|
272
|
+
|
|
269
273
|
const subEntryPages = chunkArray(subEntries, pageSize)
|
|
270
274
|
|
|
271
275
|
return renderer({
|
|
@@ -274,6 +278,7 @@ export default function Explorer({
|
|
|
274
278
|
key={entry.label}
|
|
275
279
|
value={value}
|
|
276
280
|
renderer={renderer}
|
|
281
|
+
filterSubEntries={filterSubEntries}
|
|
277
282
|
{...rest}
|
|
278
283
|
{...entry}
|
|
279
284
|
/>
|
package/src/devtools.tsx
CHANGED
|
@@ -10,13 +10,13 @@ import {
|
|
|
10
10
|
AnyRootRoute,
|
|
11
11
|
RouteMatch,
|
|
12
12
|
trimPath,
|
|
13
|
+
useRouterState,
|
|
13
14
|
} from '@tanstack/router'
|
|
14
15
|
|
|
15
16
|
import useLocalStorage from './useLocalStorage'
|
|
16
17
|
import {
|
|
17
18
|
getRouteStatusColor,
|
|
18
19
|
getStatusColor,
|
|
19
|
-
multiSortBy,
|
|
20
20
|
useIsMounted,
|
|
21
21
|
useSafeState,
|
|
22
22
|
} from './utils'
|
|
@@ -422,7 +422,8 @@ function RouteComp({
|
|
|
422
422
|
activeRouteId: string | undefined
|
|
423
423
|
setActiveRouteId: (id: string) => void
|
|
424
424
|
}) {
|
|
425
|
-
const isActive = matches.find((d) => d.
|
|
425
|
+
const isActive = matches.find((d) => d.routeId === route.id)
|
|
426
|
+
|
|
426
427
|
return (
|
|
427
428
|
<div>
|
|
428
429
|
<div
|
|
@@ -505,7 +506,8 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
505
506
|
} = props
|
|
506
507
|
|
|
507
508
|
const routerContextValue = React.useContext(routerContext)
|
|
508
|
-
const router = userRouter ?? routerContextValue
|
|
509
|
+
const router = userRouter ?? routerContextValue
|
|
510
|
+
const routerState = useRouterState()
|
|
509
511
|
|
|
510
512
|
invariant(
|
|
511
513
|
router,
|
|
@@ -525,15 +527,13 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
525
527
|
)
|
|
526
528
|
|
|
527
529
|
const allMatches: RouteMatch[] = React.useMemo(
|
|
528
|
-
() => [...Object.values(
|
|
529
|
-
[
|
|
530
|
+
() => [...Object.values(routerState.matches)],
|
|
531
|
+
[routerState.matches],
|
|
530
532
|
)
|
|
531
533
|
|
|
532
|
-
const activeMatch = allMatches?.find((d) => d.
|
|
534
|
+
const activeMatch = allMatches?.find((d) => d.routeId === activeRouteId)
|
|
533
535
|
|
|
534
|
-
const hasSearch = Object.keys(
|
|
535
|
-
last(router.state.matches)?.state.search || {},
|
|
536
|
-
).length
|
|
536
|
+
const hasSearch = Object.keys(routerState.location.search || {}).length
|
|
537
537
|
|
|
538
538
|
return (
|
|
539
539
|
<ThemeProvider theme={theme}>
|
|
@@ -646,7 +646,14 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
646
646
|
padding: '.5em',
|
|
647
647
|
}}
|
|
648
648
|
>
|
|
649
|
-
<Explorer
|
|
649
|
+
<Explorer
|
|
650
|
+
label="Router"
|
|
651
|
+
value={router}
|
|
652
|
+
defaultExpanded={{ state: {} as any, context: {} as any }}
|
|
653
|
+
filterSubEntries={(subEntries) => {
|
|
654
|
+
return subEntries.filter((d) => typeof d.value !== 'function')
|
|
655
|
+
}}
|
|
656
|
+
/>
|
|
650
657
|
</div>
|
|
651
658
|
</div>
|
|
652
659
|
</div>
|
|
@@ -680,7 +687,12 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
680
687
|
}}
|
|
681
688
|
disabled={!showMatches}
|
|
682
689
|
style={{
|
|
690
|
+
appearance: 'none',
|
|
683
691
|
opacity: showMatches ? 0.5 : 1,
|
|
692
|
+
border: 0,
|
|
693
|
+
background: 'transparent',
|
|
694
|
+
color: 'inherit',
|
|
695
|
+
cursor: 'pointer',
|
|
684
696
|
}}
|
|
685
697
|
>
|
|
686
698
|
Routes
|
|
@@ -693,7 +705,12 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
693
705
|
}}
|
|
694
706
|
disabled={showMatches}
|
|
695
707
|
style={{
|
|
708
|
+
appearance: 'none',
|
|
696
709
|
opacity: !showMatches ? 0.5 : 1,
|
|
710
|
+
border: 0,
|
|
711
|
+
background: 'transparent',
|
|
712
|
+
color: 'inherit',
|
|
713
|
+
cursor: 'pointer',
|
|
697
714
|
}}
|
|
698
715
|
>
|
|
699
716
|
Matches
|
|
@@ -709,15 +726,15 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
709
726
|
/>
|
|
710
727
|
) : (
|
|
711
728
|
<div>
|
|
712
|
-
{
|
|
729
|
+
{routerState.matches.map((match, i) => {
|
|
713
730
|
return (
|
|
714
731
|
<div
|
|
715
|
-
key={match.
|
|
732
|
+
key={match.routeId || i}
|
|
716
733
|
role="button"
|
|
717
|
-
aria-label={`Open match details for ${match.
|
|
734
|
+
aria-label={`Open match details for ${match.routeId}`}
|
|
718
735
|
onClick={() =>
|
|
719
736
|
setActiveRouteId(
|
|
720
|
-
activeRouteId === match.
|
|
737
|
+
activeRouteId === match.routeId ? '' : match.routeId,
|
|
721
738
|
)
|
|
722
739
|
}
|
|
723
740
|
style={{
|
|
@@ -790,7 +807,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
790
807
|
</tr>
|
|
791
808
|
<tr>
|
|
792
809
|
<td style={{ opacity: '.5' }}>Status</td>
|
|
793
|
-
<td>{activeMatch.
|
|
810
|
+
<td>{activeMatch.status}</td>
|
|
794
811
|
</tr>
|
|
795
812
|
{/* <tr>
|
|
796
813
|
<td style={{ opacity: '.5' }}>Invalid</td>
|
|
@@ -799,9 +816,9 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
799
816
|
<tr>
|
|
800
817
|
<td style={{ opacity: '.5' }}>Last Updated</td>
|
|
801
818
|
<td>
|
|
802
|
-
{activeMatch.
|
|
819
|
+
{activeMatch.updatedAt
|
|
803
820
|
? new Date(
|
|
804
|
-
activeMatch.
|
|
821
|
+
activeMatch.updatedAt as number,
|
|
805
822
|
).toLocaleTimeString()
|
|
806
823
|
: 'N/A'}
|
|
807
824
|
</td>
|
|
@@ -891,9 +908,9 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
891
908
|
}}
|
|
892
909
|
>
|
|
893
910
|
<Explorer
|
|
894
|
-
value={
|
|
911
|
+
value={routerState.location.search || {}}
|
|
895
912
|
defaultExpanded={Object.keys(
|
|
896
|
-
(
|
|
913
|
+
(routerState.location.search as {}) || {},
|
|
897
914
|
).reduce((obj: any, next) => {
|
|
898
915
|
obj[next] = {}
|
|
899
916
|
return obj
|
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
AnyRootRoute,
|
|
4
|
-
AnyRoute,
|
|
5
|
-
AnyRouteMatch,
|
|
6
|
-
RouteMatch,
|
|
7
|
-
} from '@tanstack/router'
|
|
2
|
+
import { AnyRootRoute, AnyRoute, AnyRouteMatch } from '@tanstack/router'
|
|
8
3
|
|
|
9
4
|
import { Theme, useTheme } from './theme'
|
|
10
5
|
import useMediaQuery from './useMediaQuery'
|
|
@@ -31,11 +26,11 @@ type StyledComponent<T> = T extends 'button'
|
|
|
31
26
|
: never
|
|
32
27
|
|
|
33
28
|
export function getStatusColor(match: AnyRouteMatch, theme: Theme) {
|
|
34
|
-
return match.
|
|
29
|
+
return match.status === 'pending'
|
|
35
30
|
? theme.active
|
|
36
|
-
: match.
|
|
31
|
+
: match.status === 'error'
|
|
37
32
|
? theme.danger
|
|
38
|
-
: match.
|
|
33
|
+
: match.status === 'success'
|
|
39
34
|
? theme.success
|
|
40
35
|
: theme.gray
|
|
41
36
|
}
|
|
@@ -45,14 +40,14 @@ export function getRouteStatusColor(
|
|
|
45
40
|
route: AnyRoute | AnyRootRoute,
|
|
46
41
|
theme: Theme,
|
|
47
42
|
) {
|
|
48
|
-
const found = matches.find((d) => d.
|
|
43
|
+
const found = matches.find((d) => d.routeId === route.id)
|
|
49
44
|
|
|
50
45
|
return found
|
|
51
|
-
? found.
|
|
46
|
+
? found.status === 'pending'
|
|
52
47
|
? theme.active
|
|
53
|
-
: found.
|
|
48
|
+
: found.status === 'error'
|
|
54
49
|
? theme.danger
|
|
55
|
-
: found.
|
|
50
|
+
: found.status === 'success'
|
|
56
51
|
? theme.success
|
|
57
52
|
: theme.gray
|
|
58
53
|
: theme.gray
|