|
1 | 1 | <script setup lang="ts"> |
| 2 | +import type { CustomInspectorTab, ModuleBuiltinTab } from '~/types' |
2 | 3 | import { CustomInspector as CustomInspectorComponent } from '@vue/devtools-applet' |
3 | 4 | import { CustomTab } from '@vue/devtools-kit' |
4 | 5 | import { vTooltip, VueButton, VueCard, VueDropdown } from '@vue/devtools-ui' |
5 | | -import { ModuleBuiltinTab } from '~/types' |
6 | 6 |
|
7 | 7 | function close() { |
8 | 8 | devtoolsClientState.value.splitScreen.enabled = false |
@@ -46,26 +46,33 @@ function getRouteTabName() { |
46 | 46 | return route.path |
47 | 47 | } |
48 | 48 |
|
| 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 | +
|
49 | 57 | watch( |
50 | 58 | () => currentTab.value, |
51 | 59 | (tab) => { |
52 | 60 | if (!tab) |
53 | 61 | return |
54 | | - // check if is a custom tab |
55 | | - if ((tab as CustomTab).view) { |
| 62 | + if (isCustomTab(tab)) { |
56 | 63 | customTabName.value = tab.name |
57 | 64 | customTabType.value = 'custom-tab' |
58 | 65 | return |
59 | 66 | } |
60 | | - if ((tab as ModuleBuiltinTab).path.startsWith(CUSTOM_INSPECTOR_TAB_VIEW)) { |
| 67 | + if (isCustomInspectorTab(tab)) { |
61 | 68 | customTabName.value = tab.name |
62 | 69 | customPluginId.value = tab.pluginId |
63 | 70 | customTabType.value = 'custom-inspector' |
64 | 71 | return |
65 | 72 | } |
66 | 73 | customTabName.value = null |
67 | 74 | 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}`) |
69 | 76 | const component = matched?.components?.default |
70 | 77 | if (typeof component === 'function') |
71 | 78 | PageComponent.value = defineAsyncComponent(component as any) |
|
0 commit comments