Skip to content

Commit

Permalink
feat: add component inspect button to the sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 8, 2023
1 parent b35ebb0 commit 512d852
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/devtools-kit/src/_types/custom-tabs.ts
Expand Up @@ -114,6 +114,7 @@ export interface ModuleBuiltinTab {
category?: TabCategory
show?: () => any
badge?: () => number | string | undefined
onClick?: () => void
}

export type ModuleTabInfo = ModuleCustomTab | ModuleBuiltinTab
1 change: 1 addition & 0 deletions packages/devtools/client/components/SideNavItem.vue
Expand Up @@ -21,6 +21,7 @@ const isActive = computed(() => route.path.startsWith(tabPath.value))
hover="bg-active" relative
h-10 w-10 select-none items-center justify-center rounded-xl p1 text-secondary
exact-active-class="!text-primary bg-active"
@click="'onClick' in tab && tab.onClick?.()"
>
<TabIcon
text-xl
Expand Down
16 changes: 16 additions & 0 deletions packages/devtools/client/composables/state.ts
Expand Up @@ -87,6 +87,7 @@ export function useAllTabs() {
const customTabs = useCustomTabs()
const settings = useDevToolsSettings()
const router = useRouter()
const client = useClient()

const builtin = computed(() => [
...router.getRoutes()
Expand All @@ -100,6 +101,21 @@ export function useAllTabs() {
...i.meta,
}
}),
{
name: 'builtin-inspector',
title: 'Inspect Vue components',
icon: 'i-carbon-select-window',
category: 'app',
show() {
return !!client.value?.inspector?.instance
},
onClick() {
if (!client.value?.inspector?.instance)
return
client.value.inspector.enable()
router.push('/__inspecting')
},
},
...(customTabs.value || []).filter(i => i.name.startsWith('builtin-')),
])

Expand Down
4 changes: 3 additions & 1 deletion packages/devtools/client/plugins/global.ts
Expand Up @@ -19,8 +19,10 @@ export default defineNuxtPlugin(() => {
client.value = { ...client.value }
})
_client.hooks.hook('host:inspector:close', () => {
if (router.currentRoute.value.path === '/modules/custom-builtin-vscode')
return
if (router.currentRoute.value.path === '/__inspecting')
router.replace('/modules/components')
router.go(-1)
})
_client.hooks.hook('host:inspector:update', (data) => {
inspectorData.value = data
Expand Down

0 comments on commit 512d852

Please sign in to comment.