Skip to content

Commit

Permalink
feat: support vnode type for custom tab view
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Dec 20, 2023
1 parent 4cd24f2 commit 1463761
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions packages/client/src/pages/custom-tab-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ watch(() => route.params.name, () => {
<template v-else-if="tab?.view?.type === 'iframe'">
<IframeView v-if="iframeViewVisible" :src="tab.view.src" />
</template>
<template v-else-if="tab?.view?.type === 'vnode'">
<Component :is="tab.view.vnode" />
</template>
<template v-else>
<PanelGrids>
<NCard flex="~ col" h-full items-center justify-center>
Expand Down
15 changes: 14 additions & 1 deletion packages/devtools-kit/src/core/custom-tab/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { VNode } from 'vue'

type TabCategory =
| 'pinned'
| 'app'
| 'modules'
| 'advanced'

export type ModuleView = ModuleIframeView
export type ModuleView = ModuleIframeView | ModuleVNodeView

export interface ModuleIframeView {
/**
Expand All @@ -23,6 +25,17 @@ export interface ModuleIframeView {
persistent?: boolean
}

export interface ModuleVNodeView {
/**
* Vue's VNode view
*/
type: 'vnode'
/**
* Send vnode to the client, they must be static and serializable
*/
vnode: VNode
}

export interface CustomTab {
/**
* The name of the tab, must be unique
Expand Down
23 changes: 10 additions & 13 deletions packages/playground/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { createApp } from 'vue'
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router'

import { addCustomTab } from '@vue/devtools-next-api'

// import { devtools } from '@vue/devtools-next'
import App2 from './App.vue'
import App from './App.preview.vue'
Expand Down Expand Up @@ -52,17 +50,16 @@ const router2 = createRouter({
routes,
})

addCustomTab({
name: 'vueuse',
// @unocss-include
icon: 'i-logos-vueuse',
title: 'VueUse',
view: {
type: 'iframe',
src: 'https://vueuse.org/',
},
category: 'app',
})
// addCustomTab({
// name: 'vueuse',
// icon: 'i-logos-vueuse',
// title: 'VueUse',
// view: {
// type: 'iframe',
// src: 'https://vueuse.org/',
// },
// category: 'app',
// })

app.use(router)
app.use(pinia)
Expand Down

0 comments on commit 1463761

Please sign in to comment.