Skip to content

Commit

Permalink
feat(applet): set state tab as default page for custom inspector (#471)
Browse files Browse the repository at this point in the history
Co-authored-by: arlo <[email protected]>
  • Loading branch information
alexzhang1030 and webfansplz authored Jun 27, 2024
1 parent b69bd66 commit c753696
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/applet/src/composables/custom-inspector-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type CustomInspectorState = Partial<{
timelineLayerIds: string[]
}>

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

export function useCustomInspectorState() {
return inject(VueDevToolsStateSymbol)!
Expand Down
16 changes: 13 additions & 3 deletions packages/applet/src/composables/virtual-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ export interface VirtualRoute { path: string, component: Component, icon?: strin
const VirtualRouteKey: InjectionKey<Ref<{ path: string }>> = Symbol('VirtualRouteKey')
const VirtualRoutesKey: InjectionKey<ComputedRef<VirtualRoute[]>> = Symbol('VirtualRoutesKey')

export function registerVirtualRouter(routes: MaybeRef<VirtualRoute[]>) {
export function registerVirtualRouter<
const Routes extends VirtualRoute[],
RoutePaths extends Routes[number]['path'] = Routes[number]['path'],
>(
routes: MaybeRef<Routes>,
props?: {
defaultRoutePath?: RoutePaths
},
) {
const defaultRoutePath = props?.defaultRoutePath ?? toValue(routes)[0].path

const route = ref<{ path: string, icon?: string }>({
path: '/',
path: defaultRoutePath,
})

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

function restoreRouter() {
route.value.path = '/'
route.value.path = defaultRoutePath
}

provide(VirtualRouteKey, route)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DevToolsMessagingEvents, onRpcConnected, rpc } from '@vue/devtools-core
import { parse } from '@vue/devtools-kit'
import type { CustomInspectorNode, CustomInspectorOptions, CustomInspectorState } from '@vue/devtools-kit'
import { vTooltip } from '@vue/devtools-ui'
import { until } from '@vueuse/core'
import Navbar from '~/components/basic/Navbar.vue'
import DevToolsHeader from '~/components/basic/DevToolsHeader.vue'
import Empty from '~/components/basic/Empty.vue'
Expand Down Expand Up @@ -130,7 +131,8 @@ const getInspectorTree = () => {
}
})
}
getInspectorTree()
until(inspectorId).toBeTruthy().then(getInspectorTree)
function onInspectorTreeUpdated(_data: string) {
const data = parse(_data) as {
Expand Down
18 changes: 10 additions & 8 deletions packages/applet/src/modules/custom-inspector/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { computed, onUnmounted, ref, watch } from 'vue'
import { onRpcConnected, rpc } from '@vue/devtools-core'
import Home from './components/Home.vue'
import About from './components/About.vue'
import State from './components/state/Index.vue'
import Timeline from './components/timeline/Index.vue'
import AppConnecting from '~/components/basic/AppConnecting.vue'
Expand All @@ -19,12 +19,6 @@ const loading = ref(false)
const routes = computed(() => {
return [
{
path: '/',
name: 'Home',
component: Home,
icon: 'https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.svg',
},
{
path: '/state',
name: 'State',
Expand All @@ -37,10 +31,18 @@ const routes = computed(() => {
component: Timeline,
icon: 'i-mdi:timeline-clock-outline',
}),
{
path: '/about',
name: 'About',
component: About,
icon: 'https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.svg',
},
].filter(Boolean) as VirtualRoute[]
})
const { VirtualRouterView, restoreRouter } = registerVirtualRouter(routes)
const { VirtualRouterView, restoreRouter } = registerVirtualRouter(routes, {
defaultRoutePath: '/state',
})
function getInspectorInfo() {
loading.value = true
Expand Down
22 changes: 10 additions & 12 deletions packages/applet/src/modules/pinia/index.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<script setup lang="ts">
import { ref } from 'vue'
import Home from './components/Home.vue'
import About from './components/About.vue'
import Store from './components/store/Index.vue'
import Timeline from './components/timeline/Index.vue'
import { registerVirtualRouter } from '~/composables/virtual-router'
const { VirtualRouterView } = registerVirtualRouter([
{
path: '/',
name: 'Home',
component: Home,
icon: 'i-logos-pinia',
},
{
path: '/store',
name: 'Store',
Expand All @@ -25,9 +17,15 @@ const { VirtualRouterView } = registerVirtualRouter([
component: Timeline,
icon: 'i-mdi:timeline-clock-outline',
},
])
const routePath = ref('/')
{
path: '/',
name: 'About',
component: About,
icon: 'i-logos-pinia',
},
], {
defaultRoutePath: '/store',
})
</script>

<template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Pane, Splitpanes } from 'splitpanes'
import { DevToolsMessagingEvents, rpc } from '@vue/devtools-core'
import { parse } from '@vue/devtools-kit'
import type { CustomInspectorNode, CustomInspectorState } from '@vue/devtools-kit'
import { until } from '@vueuse/core'
import Navbar from '~/components/basic/Navbar.vue'
import DevToolsHeader from '~/components/basic/DevToolsHeader.vue'
import Empty from '~/components/basic/Empty.vue'
Expand Down Expand Up @@ -102,7 +103,8 @@ const getRoutesInspectorTree = () => {
}
})
}
getRoutesInspectorTree()
until(inspectorId).toBeTruthy().then(getRoutesInspectorTree)
function onInspectorTreeUpdated(_data: string) {
const data = parse(_data) as {
Expand Down
18 changes: 10 additions & 8 deletions packages/applet/src/modules/router/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import { onRpcConnected, rpc } from '@vue/devtools-core'
import Home from './components/Home.vue'
import About from './components/About.vue'
import Routes from './components/routes/Index.vue'
import Timeline from './components/timeline/Index.vue'
import { registerVirtualRouter } from '~/composables/virtual-router'
Expand All @@ -13,12 +13,6 @@ const props = defineProps<{
const inspectorState = createCustomInspectorStateContext()
const loading = ref(false)
const { VirtualRouterView, restoreRouter } = registerVirtualRouter([
{
path: '/',
name: 'Home',
component: Home,
icon: 'i-ri-route-line',
},
{
path: '/routes',
name: 'Routes',
Expand All @@ -31,7 +25,15 @@ const { VirtualRouterView, restoreRouter } = registerVirtualRouter([
component: Timeline,
icon: 'i-mdi:timeline-clock-outline',
},
])
{
path: '/about',
name: 'About',
component: About,
icon: 'i-ri-route-line',
},
], {
defaultRoutePath: '/routes',
})
function getInspectorInfo() {
loading.value = true
Expand Down

0 comments on commit c753696

Please sign in to comment.