Skip to content

Commit c753696

Browse files
alexzhang1030webfansplz
andauthoredJun 27, 2024··
feat(applet): set state tab as default page for custom inspector (#471)
Co-authored-by: arlo <webfansplz@gmail.com>
1 parent b69bd66 commit c753696

File tree

10 files changed

+50
-34
lines changed

10 files changed

+50
-34
lines changed
 

Diff for: ‎packages/applet/src/composables/custom-inspector-state.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type CustomInspectorState = Partial<{
99
timelineLayerIds: string[]
1010
}>
1111

12-
const VueDevToolsStateSymbol: InjectionKey<Ref<CustomInspectorState>> = Symbol('VueDevToolsCustomInspectorStateSymbol')
12+
const VueDevToolsStateSymbol: InjectionKey<Ref<CustomInspectorState>> = Symbol.for('VueDevToolsCustomInspectorStateSymbol')
1313

1414
export function useCustomInspectorState() {
1515
return inject(VueDevToolsStateSymbol)!

Diff for: ‎packages/applet/src/composables/virtual-router.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ export interface VirtualRoute { path: string, component: Component, icon?: strin
66
const VirtualRouteKey: InjectionKey<Ref<{ path: string }>> = Symbol('VirtualRouteKey')
77
const VirtualRoutesKey: InjectionKey<ComputedRef<VirtualRoute[]>> = Symbol('VirtualRoutesKey')
88

9-
export function registerVirtualRouter(routes: MaybeRef<VirtualRoute[]>) {
9+
export function registerVirtualRouter<
10+
const Routes extends VirtualRoute[],
11+
RoutePaths extends Routes[number]['path'] = Routes[number]['path'],
12+
>(
13+
routes: MaybeRef<Routes>,
14+
props?: {
15+
defaultRoutePath?: RoutePaths
16+
},
17+
) {
18+
const defaultRoutePath = props?.defaultRoutePath ?? toValue(routes)[0].path
19+
1020
const route = ref<{ path: string, icon?: string }>({
11-
path: '/',
21+
path: defaultRoutePath,
1222
})
1323

1424
const _routes = computed(() => toValue(routes))
@@ -27,7 +37,7 @@ export function registerVirtualRouter(routes: MaybeRef<VirtualRoute[]>) {
2737
})
2838

2939
function restoreRouter() {
30-
route.value.path = '/'
40+
route.value.path = defaultRoutePath
3141
}
3242

3343
provide(VirtualRouteKey, route)

Diff for: ‎packages/applet/src/modules/custom-inspector/components/state/Index.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DevToolsMessagingEvents, onRpcConnected, rpc } from '@vue/devtools-core
55
import { parse } from '@vue/devtools-kit'
66
import type { CustomInspectorNode, CustomInspectorOptions, CustomInspectorState } from '@vue/devtools-kit'
77
import { vTooltip } from '@vue/devtools-ui'
8+
import { until } from '@vueuse/core'
89
import Navbar from '~/components/basic/Navbar.vue'
910
import DevToolsHeader from '~/components/basic/DevToolsHeader.vue'
1011
import Empty from '~/components/basic/Empty.vue'
@@ -130,7 +131,8 @@ const getInspectorTree = () => {
130131
}
131132
})
132133
}
133-
getInspectorTree()
134+
135+
until(inspectorId).toBeTruthy().then(getInspectorTree)
134136
135137
function onInspectorTreeUpdated(_data: string) {
136138
const data = parse(_data) as {

Diff for: ‎packages/applet/src/modules/custom-inspector/index.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { computed, onUnmounted, ref, watch } from 'vue'
33
import { onRpcConnected, rpc } from '@vue/devtools-core'
44
5-
import Home from './components/Home.vue'
5+
import About from './components/About.vue'
66
import State from './components/state/Index.vue'
77
import Timeline from './components/timeline/Index.vue'
88
import AppConnecting from '~/components/basic/AppConnecting.vue'
@@ -19,12 +19,6 @@ const loading = ref(false)
1919
2020
const routes = computed(() => {
2121
return [
22-
{
23-
path: '/',
24-
name: 'Home',
25-
component: Home,
26-
icon: 'https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.svg',
27-
},
2822
{
2923
path: '/state',
3024
name: 'State',
@@ -37,10 +31,18 @@ const routes = computed(() => {
3731
component: Timeline,
3832
icon: 'i-mdi:timeline-clock-outline',
3933
}),
34+
{
35+
path: '/about',
36+
name: 'About',
37+
component: About,
38+
icon: 'https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.svg',
39+
},
4040
].filter(Boolean) as VirtualRoute[]
4141
})
4242
43-
const { VirtualRouterView, restoreRouter } = registerVirtualRouter(routes)
43+
const { VirtualRouterView, restoreRouter } = registerVirtualRouter(routes, {
44+
defaultRoutePath: '/state',
45+
})
4446
4547
function getInspectorInfo() {
4648
loading.value = true

Diff for: ‎packages/applet/src/modules/pinia/index.vue

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue'
3-
4-
import Home from './components/Home.vue'
2+
import About from './components/About.vue'
53
import Store from './components/store/Index.vue'
64
import Timeline from './components/timeline/Index.vue'
75
import { registerVirtualRouter } from '~/composables/virtual-router'
86
97
const { VirtualRouterView } = registerVirtualRouter([
10-
{
11-
path: '/',
12-
name: 'Home',
13-
component: Home,
14-
icon: 'i-logos-pinia',
15-
},
168
{
179
path: '/store',
1810
name: 'Store',
@@ -25,9 +17,15 @@ const { VirtualRouterView } = registerVirtualRouter([
2517
component: Timeline,
2618
icon: 'i-mdi:timeline-clock-outline',
2719
},
28-
])
29-
30-
const routePath = ref('/')
20+
{
21+
path: '/',
22+
name: 'About',
23+
component: About,
24+
icon: 'i-logos-pinia',
25+
},
26+
], {
27+
defaultRoutePath: '/store',
28+
})
3129
</script>
3230

3331
<template>

Diff for: ‎packages/applet/src/modules/router/components/routes/Index.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Pane, Splitpanes } from 'splitpanes'
44
import { DevToolsMessagingEvents, rpc } from '@vue/devtools-core'
55
import { parse } from '@vue/devtools-kit'
66
import type { CustomInspectorNode, CustomInspectorState } from '@vue/devtools-kit'
7+
import { until } from '@vueuse/core'
78
import Navbar from '~/components/basic/Navbar.vue'
89
import DevToolsHeader from '~/components/basic/DevToolsHeader.vue'
910
import Empty from '~/components/basic/Empty.vue'
@@ -102,7 +103,8 @@ const getRoutesInspectorTree = () => {
102103
}
103104
})
104105
}
105-
getRoutesInspectorTree()
106+
107+
until(inspectorId).toBeTruthy().then(getRoutesInspectorTree)
106108
107109
function onInspectorTreeUpdated(_data: string) {
108110
const data = parse(_data) as {

Diff for: ‎packages/applet/src/modules/router/index.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { ref, watch } from 'vue'
33
import { onRpcConnected, rpc } from '@vue/devtools-core'
4-
import Home from './components/Home.vue'
4+
import About from './components/About.vue'
55
import Routes from './components/routes/Index.vue'
66
import Timeline from './components/timeline/Index.vue'
77
import { registerVirtualRouter } from '~/composables/virtual-router'
@@ -13,12 +13,6 @@ const props = defineProps<{
1313
const inspectorState = createCustomInspectorStateContext()
1414
const loading = ref(false)
1515
const { VirtualRouterView, restoreRouter } = registerVirtualRouter([
16-
{
17-
path: '/',
18-
name: 'Home',
19-
component: Home,
20-
icon: 'i-ri-route-line',
21-
},
2216
{
2317
path: '/routes',
2418
name: 'Routes',
@@ -31,7 +25,15 @@ const { VirtualRouterView, restoreRouter } = registerVirtualRouter([
3125
component: Timeline,
3226
icon: 'i-mdi:timeline-clock-outline',
3327
},
34-
])
28+
{
29+
path: '/about',
30+
name: 'About',
31+
component: About,
32+
icon: 'i-ri-route-line',
33+
},
34+
], {
35+
defaultRoutePath: '/routes',
36+
})
3537
3638
function getInspectorInfo() {
3739
loading.value = true

0 commit comments

Comments
 (0)
Please sign in to comment.