@tanstack/router-devtools 1.22.5 → 1.22.6
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/Explorer.cjs +1 -1
- package/dist/cjs/Explorer.cjs.map +1 -1
- package/dist/cjs/Explorer.d.cts +4 -4
- package/dist/cjs/devtools.cjs +37 -35
- package/dist/cjs/devtools.cjs.map +1 -1
- package/dist/cjs/devtools.d.cts +1 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +4 -4
- package/dist/esm/Explorer.d.ts +4 -4
- package/dist/esm/Explorer.js +1 -1
- package/dist/esm/Explorer.js.map +1 -1
- package/dist/esm/devtools.d.ts +1 -2
- package/dist/esm/devtools.js +37 -35
- package/dist/esm/devtools.js.map +1 -1
- package/dist/esm/utils.d.ts +4 -4
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/Explorer.tsx +8 -8
- package/src/devtools.tsx +46 -45
- package/src/useMediaQuery.ts +2 -0
- package/src/utils.ts +12 -7
package/src/devtools.tsx
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import {
|
|
3
3
|
invariant,
|
|
4
|
-
|
|
5
|
-
Route,
|
|
6
|
-
AnyRoute,
|
|
7
|
-
AnyRootRoute,
|
|
4
|
+
rootRouteId,
|
|
8
5
|
trimPath,
|
|
9
6
|
useRouter,
|
|
10
7
|
useRouterState,
|
|
11
|
-
AnyRouteMatch,
|
|
12
|
-
rootRouteId,
|
|
13
8
|
} from '@tanstack/react-router'
|
|
14
9
|
|
|
10
|
+
import { css } from 'goober'
|
|
11
|
+
import { clsx as cx } from 'clsx'
|
|
15
12
|
import useLocalStorage from './useLocalStorage'
|
|
16
13
|
import {
|
|
17
14
|
getRouteStatusColor,
|
|
@@ -20,13 +17,16 @@ import {
|
|
|
20
17
|
useIsMounted,
|
|
21
18
|
useSafeState,
|
|
22
19
|
} from './utils'
|
|
23
|
-
import { css } from 'goober'
|
|
24
|
-
import { clsx as cx } from 'clsx'
|
|
25
20
|
import Explorer from './Explorer'
|
|
26
21
|
import { tokens } from './tokens'
|
|
27
22
|
import { TanStackLogo } from './logo'
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
import type {
|
|
24
|
+
AnyRootRoute,
|
|
25
|
+
AnyRoute,
|
|
26
|
+
AnyRouteMatch,
|
|
27
|
+
AnyRouter,
|
|
28
|
+
Route,
|
|
29
|
+
} from '@tanstack/react-router'
|
|
30
30
|
|
|
31
31
|
interface DevtoolsOptions {
|
|
32
32
|
/**
|
|
@@ -136,7 +136,7 @@ export function TanStackRouterDevtools({
|
|
|
136
136
|
containerElement: Container = 'footer',
|
|
137
137
|
router,
|
|
138
138
|
}: DevtoolsOptions): React.ReactElement | null {
|
|
139
|
-
const [rootEl, setRootEl] = React.useState<HTMLDivElement>(
|
|
139
|
+
const [rootEl, setRootEl] = React.useState<HTMLDivElement>()
|
|
140
140
|
const panelRef = React.useRef<HTMLDivElement>(null)
|
|
141
141
|
const [isOpen, setIsOpen] = useLocalStorage(
|
|
142
142
|
'tanstackRouterDevtoolsOpen',
|
|
@@ -165,7 +165,7 @@ export function TanStackRouterDevtools({
|
|
|
165
165
|
|
|
166
166
|
const run = (moveEvent: MouseEvent) => {
|
|
167
167
|
const delta = dragInfo.pageY - moveEvent.pageY
|
|
168
|
-
const newHeight = dragInfo
|
|
168
|
+
const newHeight = dragInfo.originalHeight + delta
|
|
169
169
|
|
|
170
170
|
setDevtoolsHeight(newHeight)
|
|
171
171
|
|
|
@@ -217,7 +217,7 @@ export function TanStackRouterDevtools({
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
return
|
|
220
|
-
}, [isResolvedOpen])
|
|
220
|
+
}, [isResolvedOpen, rootEl?.parentElement])
|
|
221
221
|
|
|
222
222
|
React.useEffect(() => {
|
|
223
223
|
if (rootEl) {
|
|
@@ -390,9 +390,9 @@ function RouteComp({
|
|
|
390
390
|
<AgeTicker match={match} router={router} />
|
|
391
391
|
</div>
|
|
392
392
|
</div>
|
|
393
|
-
{
|
|
393
|
+
{route.children?.length ? (
|
|
394
394
|
<div className={getStyles().nestedRouteRow(!!isRoot)}>
|
|
395
|
-
{[...(route.children as Route
|
|
395
|
+
{[...(route.children as Array<Route>)]
|
|
396
396
|
.sort((a, b) => {
|
|
397
397
|
return a.rank - b.rank
|
|
398
398
|
})
|
|
@@ -432,12 +432,6 @@ const BaseTanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
432
432
|
router,
|
|
433
433
|
} as any)
|
|
434
434
|
|
|
435
|
-
const matches = [
|
|
436
|
-
...(routerState.pendingMatches ?? []),
|
|
437
|
-
...routerState.matches,
|
|
438
|
-
...routerState.cachedMatches,
|
|
439
|
-
]
|
|
440
|
-
|
|
441
435
|
invariant(
|
|
442
436
|
router,
|
|
443
437
|
'No router was found for the TanStack Router Devtools. Please place the devtools in the <RouterProvider> component tree or pass the router instance to the devtools manually.',
|
|
@@ -455,12 +449,21 @@ const BaseTanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
455
449
|
'',
|
|
456
450
|
)
|
|
457
451
|
|
|
458
|
-
const activeMatch = React.useMemo(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
452
|
+
const activeMatch = React.useMemo(() => {
|
|
453
|
+
const matches = [
|
|
454
|
+
...(routerState.pendingMatches ?? []),
|
|
455
|
+
...routerState.matches,
|
|
456
|
+
...routerState.cachedMatches,
|
|
457
|
+
]
|
|
458
|
+
return matches.find((d) => d.routeId === activeId || d.id === activeId)
|
|
459
|
+
}, [
|
|
460
|
+
activeId,
|
|
461
|
+
routerState.cachedMatches,
|
|
462
|
+
routerState.matches,
|
|
463
|
+
routerState.pendingMatches,
|
|
464
|
+
])
|
|
465
|
+
|
|
466
|
+
const hasSearch = Object.keys(routerState.location.search).length
|
|
464
467
|
|
|
465
468
|
const explorerState = {
|
|
466
469
|
...router,
|
|
@@ -658,7 +661,7 @@ const BaseTanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
658
661
|
)}
|
|
659
662
|
</div>
|
|
660
663
|
</div>
|
|
661
|
-
{routerState.cachedMatches
|
|
664
|
+
{routerState.cachedMatches.length ? (
|
|
662
665
|
<div className={getStyles().cachedMatchesContainer}>
|
|
663
666
|
<div className={getStyles().detailsHeader}>
|
|
664
667
|
<div>Cached Matches</div>
|
|
@@ -724,7 +727,7 @@ const BaseTanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
724
727
|
(d) => d.id === activeMatch.id,
|
|
725
728
|
)
|
|
726
729
|
? 'Pending'
|
|
727
|
-
: routerState.matches
|
|
730
|
+
: routerState.matches.find((d) => d.id === activeMatch.id)
|
|
728
731
|
? 'Active'
|
|
729
732
|
: 'Cached'}
|
|
730
733
|
</div>
|
|
@@ -733,9 +736,7 @@ const BaseTanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
733
736
|
<div>Last Updated:</div>
|
|
734
737
|
<div className={getStyles().matchDetailsInfo}>
|
|
735
738
|
{activeMatch.updatedAt
|
|
736
|
-
? new Date(
|
|
737
|
-
activeMatch.updatedAt as number,
|
|
738
|
-
).toLocaleTimeString()
|
|
739
|
+
? new Date(activeMatch.updatedAt).toLocaleTimeString()
|
|
739
740
|
: 'N/A'}
|
|
740
741
|
</div>
|
|
741
742
|
</div>
|
|
@@ -764,13 +765,14 @@ const BaseTanStackRouterDevtoolsPanel = React.forwardRef<
|
|
|
764
765
|
<div className={getStyles().detailsHeader}>Search Params</div>
|
|
765
766
|
<div className={getStyles().detailsContent}>
|
|
766
767
|
<Explorer
|
|
767
|
-
value={routerState.location.search
|
|
768
|
-
defaultExpanded={Object.keys(
|
|
769
|
-
(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
768
|
+
value={routerState.location.search}
|
|
769
|
+
defaultExpanded={Object.keys(routerState.location.search).reduce(
|
|
770
|
+
(obj: any, next) => {
|
|
771
|
+
obj[next] = {}
|
|
772
|
+
return obj
|
|
773
|
+
},
|
|
774
|
+
{},
|
|
775
|
+
)}
|
|
774
776
|
/>
|
|
775
777
|
</div>
|
|
776
778
|
</div>
|
|
@@ -799,19 +801,19 @@ function AgeTicker({
|
|
|
799
801
|
return () => {
|
|
800
802
|
clearInterval(interval)
|
|
801
803
|
}
|
|
802
|
-
}, [])
|
|
804
|
+
}, [rerender])
|
|
803
805
|
|
|
804
806
|
if (!match) {
|
|
805
807
|
return null
|
|
806
808
|
}
|
|
807
809
|
|
|
808
|
-
const route = router.looseRoutesById[match
|
|
810
|
+
const route = router.looseRoutesById[match.routeId]!
|
|
809
811
|
|
|
810
812
|
if (!route.options.loader) {
|
|
811
813
|
return null
|
|
812
814
|
}
|
|
813
815
|
|
|
814
|
-
const age = Date.now() - match
|
|
816
|
+
const age = Date.now() - match.updatedAt
|
|
815
817
|
const staleTime =
|
|
816
818
|
route.options.staleTime ?? router.options.defaultStaleTime ?? 0
|
|
817
819
|
const gcTime =
|
|
@@ -1045,10 +1047,9 @@ const stylesFactory = () => {
|
|
|
1045
1047
|
}
|
|
1046
1048
|
|
|
1047
1049
|
if (showBorder) {
|
|
1048
|
-
|
|
1050
|
+
classes.push(css`
|
|
1049
1051
|
border-right: 1px solid ${tokens.colors.gray[500]};
|
|
1050
|
-
`
|
|
1051
|
-
classes.push(border)
|
|
1052
|
+
`)
|
|
1052
1053
|
}
|
|
1053
1054
|
|
|
1054
1055
|
return classes
|
package/src/useMediaQuery.ts
CHANGED
|
@@ -4,6 +4,7 @@ export default function useMediaQuery(query: string): boolean | undefined {
|
|
|
4
4
|
// Keep track of the preference in state, start with the current match
|
|
5
5
|
const [isMatch, setIsMatch] = React.useState(() => {
|
|
6
6
|
if (typeof window !== 'undefined') {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
7
8
|
return window.matchMedia && window.matchMedia(query).matches
|
|
8
9
|
}
|
|
9
10
|
return
|
|
@@ -12,6 +13,7 @@ export default function useMediaQuery(query: string): boolean | undefined {
|
|
|
12
13
|
// Watch for changes
|
|
13
14
|
React.useEffect(() => {
|
|
14
15
|
if (typeof window !== 'undefined') {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
15
17
|
if (!window.matchMedia) {
|
|
16
18
|
return
|
|
17
19
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { Theme, useTheme } from './theme'
|
|
2
|
+
import { useTheme } from './theme'
|
|
5
3
|
import useMediaQuery from './useMediaQuery'
|
|
4
|
+
import type {
|
|
5
|
+
AnyRootRoute,
|
|
6
|
+
AnyRoute,
|
|
7
|
+
AnyRouteMatch,
|
|
8
|
+
} from '@tanstack/react-router'
|
|
9
|
+
|
|
10
|
+
import type { Theme } from './theme'
|
|
6
11
|
|
|
7
12
|
export const isServer = typeof window === 'undefined'
|
|
8
13
|
|
|
@@ -38,7 +43,7 @@ export function getStatusColor(match: AnyRouteMatch) {
|
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
export function getRouteStatusColor(
|
|
41
|
-
matches: AnyRouteMatch
|
|
46
|
+
matches: Array<AnyRouteMatch>,
|
|
42
47
|
route: AnyRoute | AnyRootRoute,
|
|
43
48
|
) {
|
|
44
49
|
const found = matches.find((d) => d.routeId === route.id)
|
|
@@ -153,9 +158,9 @@ function scheduleMicrotask(callback: () => void) {
|
|
|
153
158
|
}
|
|
154
159
|
|
|
155
160
|
export function multiSortBy<T>(
|
|
156
|
-
arr: T
|
|
157
|
-
accessors: (
|
|
158
|
-
): T
|
|
161
|
+
arr: Array<T>,
|
|
162
|
+
accessors: Array<(item: T) => any> = [(d) => d],
|
|
163
|
+
): Array<T> {
|
|
159
164
|
return arr
|
|
160
165
|
.map((d, i) => [d, i] as const)
|
|
161
166
|
.sort(([a, ai], [b, bi]) => {
|