|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { onMounted, onScopeDispose, ref, shallowRef, watchEffect } from 'vue' |
3 | 3 | import { PLUGIN_CONTAINER_ID, TanStackDevtoolsCore } from '@tanstack/devtools' |
| 4 | +import type { DefineComponent } from 'vue' |
4 | 5 | import type { TanStackDevtoolsPlugin } from '@tanstack/devtools' |
5 | 6 | import type { |
| 7 | + RenderArray, |
6 | 8 | TanStackDevtoolsVueInit, |
7 | 9 | TanStackDevtoolsVuePlugin, |
8 | 10 | } from './types' |
9 | 11 |
|
10 | 12 | const props = defineProps<TanStackDevtoolsVueInit>() |
11 | 13 |
|
12 | | -const titlesToRender = shallowRef<Array<{ id: string; component: any }>>([]) |
13 | | -const pluginsToRender = shallowRef< |
14 | | - Array<{ id: string; component: any; props: any }> |
15 | | ->([]) |
| 14 | +const titlesToRender = shallowRef<RenderArray>([]) |
| 15 | +const pluginsToRender = shallowRef<RenderArray>([]) |
16 | 16 | const div = ref<HTMLElement>() |
17 | 17 |
|
18 | 18 | function getPlugin(plugin: TanStackDevtoolsVuePlugin): TanStackDevtoolsPlugin { |
19 | 19 | return { |
20 | | - ...plugin, |
| 20 | + id: plugin.id, |
21 | 21 | name: |
22 | 22 | typeof plugin.name === 'string' |
23 | 23 | ? plugin.name |
24 | | - : (e, _theme) => { |
| 24 | + : (e, theme) => { |
25 | 25 | const id = e.getAttribute('id')! |
26 | 26 | titlesToRender.value = [ |
27 | 27 | ...titlesToRender.value, |
28 | 28 | { |
29 | 29 | id, |
30 | | - component: plugin.name, |
| 30 | + component: plugin.name as DefineComponent<any>, |
| 31 | + props: { |
| 32 | + theme, |
| 33 | + }, |
31 | 34 | }, |
32 | 35 | ] |
33 | 36 | }, |
34 | | - render: (e, _theme) => { |
| 37 | + render: (e, theme) => { |
35 | 38 | const id = e.getAttribute('id')! |
36 | 39 | pluginsToRender.value = [ |
37 | 40 | ...pluginsToRender.value, |
38 | | - { id, component: plugin.component, props: plugin.props }, |
| 41 | + { id, component: plugin.component, props: { theme, ...plugin.props } }, |
39 | 42 | ] |
40 | 43 | }, |
41 | 44 | destroy: (pluginId) => { |
@@ -78,13 +81,17 @@ onScopeDispose(() => { |
78 | 81 | :key="title.id" |
79 | 82 | :to="'#' + title.id" |
80 | 83 | > |
81 | | - <component :is="title.component" /> |
| 84 | + <component :is="title.component" v-bind="title.props" /> |
82 | 85 | </Teleport> |
83 | 86 | <Teleport |
84 | 87 | v-for="plugin in pluginsToRender" |
85 | 88 | :key="plugin.id" |
86 | 89 | :to="'#' + plugin.id" |
87 | 90 | > |
88 | | - <component :is="plugin.component" v-bind="plugin.props" /> |
| 91 | + <component |
| 92 | + :is="plugin.component" |
| 93 | + :devtools-props="plugin.props" |
| 94 | + v-bind="plugin.props" |
| 95 | + /> |
89 | 96 | </Teleport> |
90 | 97 | </template> |
0 commit comments