Skip to content

Commit bc6ceea

Browse files
committed
refactor(client): add type CustomInspectorTab
1 parent 6f09e8d commit bc6ceea

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

packages/client/src/components/common/SplitScreen.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
2+
import type { CustomInspectorTab, ModuleBuiltinTab } from '~/types'
23
import { CustomInspector as CustomInspectorComponent } from '@vue/devtools-applet'
34
import { CustomTab } from '@vue/devtools-kit'
45
import { vTooltip, VueButton, VueCard, VueDropdown } from '@vue/devtools-ui'
5-
import { ModuleBuiltinTab } from '~/types'
66
77
function close() {
88
devtoolsClientState.value.splitScreen.enabled = false
@@ -46,26 +46,33 @@ function getRouteTabName() {
4646
return route.path
4747
}
4848
49+
function isCustomTab(tab: ModuleBuiltinTab | CustomTab): tab is CustomTab {
50+
return !!(tab as CustomTab).view
51+
}
52+
53+
function isCustomInspectorTab(tab: ModuleBuiltinTab): tab is CustomInspectorTab {
54+
return tab.path.startsWith(CUSTOM_INSPECTOR_TAB_VIEW)
55+
}
56+
4957
watch(
5058
() => currentTab.value,
5159
(tab) => {
5260
if (!tab)
5361
return
54-
// check if is a custom tab
55-
if ((tab as CustomTab).view) {
62+
if (isCustomTab(tab)) {
5663
customTabName.value = tab.name
5764
customTabType.value = 'custom-tab'
5865
return
5966
}
60-
if ((tab as ModuleBuiltinTab).path.startsWith(CUSTOM_INSPECTOR_TAB_VIEW)) {
67+
if (isCustomInspectorTab(tab)) {
6168
customTabName.value = tab.name
6269
customPluginId.value = tab.pluginId
6370
customTabType.value = 'custom-inspector'
6471
return
6572
}
6673
customTabName.value = null
6774
const routes = router.getRoutes()
68-
const matched = routes.find(route => route.path === `/${(tab as ModuleBuiltinTab).path}`)
75+
const matched = routes.find(route => route.path === `/${tab.path}`)
6976
const component = matched?.components?.default
7077
if (typeof component === 'function')
7178
PageComponent.value = defineAsyncComponent(component as any)

packages/client/src/composables/custom-inspector-tabs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { CustomInspectorType } from '@vue/devtools-applet'
2-
import type { ModuleBuiltinTab } from '~/types/tab'
2+
import type { CustomInspectorTab } from '~/types/tab'
33

44
import { useCustomInspector } from '@vue/devtools-applet'
55

66
export function useCustomInspectorTabs() {
77
const { registeredInspector } = useCustomInspector()
88

9-
const customInspectorTabs = computed<ModuleBuiltinTab[]>(() => {
10-
return registeredInspector.value.map((inspector: CustomInspectorType, index) => {
9+
const customInspectorTabs = computed(() => {
10+
return registeredInspector.value.map((inspector: CustomInspectorType, index): CustomInspectorTab => {
1111
return {
1212
order: index,
1313
name: inspector.id,

packages/client/src/pages/custom-inspector-tab-view.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const route = useRoute()
66
const router = useRouter()
77
const loadError = ref(false)
88
const customInspectorTabs = useCustomInspectorTabs()
9-
// @ts-expect-error skip type check
109
const pluginId = computed(() => customInspectorTabs.value.find(tab => tab.name === route.params.name)?.pluginId)
1110
function onLoadError() {
1211
loadError.value = true

packages/client/src/types/tab.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ export interface ModuleBuiltinTab extends Pick<CustomTab, 'name' | 'icon' | 'tit
99
badge?: () => MaybeRefOrGetter<number | string | undefined>
1010
onClick?: () => void
1111
}
12+
13+
export interface CustomInspectorTab extends ModuleBuiltinTab {
14+
pluginId: string
15+
}

0 commit comments

Comments
 (0)