@tanstack/vue-devtools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +47 -0
- package/dist/esm/vue-devtools.vue.d.ts +4 -0
- package/dist/esm/vue-devtools.vue.js +96 -0
- package/dist/esm/vue-devtools.vue.js.map +1 -0
- package/dist/esm/vue-devtools.vue2.js +5 -0
- package/dist/esm/vue-devtools.vue2.js.map +1 -0
- package/package.json +58 -0
- package/src/index.ts +8 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/types.ts +53 -0
- package/src/vue-devtools.vue +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 TanStack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @tanstack/vue-devtools
|
|
2
|
+
|
|
3
|
+
This package is still under active development and might have breaking changes in the future. Please use it with caution.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```vue
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { TanStackDevtools } from '@tanstack/vue-devtools'
|
|
10
|
+
import { VueQueryDevtoolsPanel } from '@tanstack/vue-query-devtools'
|
|
11
|
+
|
|
12
|
+
const plugins = [{ name: 'Vue Query', component: VueQueryDevtoolsPanel }]
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<TanStackDevtools
|
|
17
|
+
:eventBusConfig="{ connectToServerBus: true }"
|
|
18
|
+
:plugins="plugins"
|
|
19
|
+
/>
|
|
20
|
+
</template>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Creating plugins
|
|
24
|
+
|
|
25
|
+
In order to create a plugin for TanStack Devtools, you can use the `plugins` prop of the `TanStackDevtools` component. Here's an example of how to create a simple plugin:
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { TanStackDevtools } from '@tanstack/vue-devtools'
|
|
30
|
+
|
|
31
|
+
const plugins = [
|
|
32
|
+
{
|
|
33
|
+
id: 'your-plugin-id',
|
|
34
|
+
name: 'Your Plugin',
|
|
35
|
+
component: CustomPluginComponent,
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<TanStackDevtools
|
|
42
|
+
:eventBusConfig="{ connectToServerBus: true }"
|
|
43
|
+
:plugins="plugins"
|
|
44
|
+
/>
|
|
45
|
+
</template>
|
|
46
|
+
```
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const TanStackDevtools: import('vue').DefineComponent<import('./types.js').TanStackDevtoolsVueInit, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('./types.js').TanStackDevtoolsVueInit> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
2
|
+
export type { TanStackDevtoolsVuePlugin, TanStackDevtoolsVueInit, } from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import Devtools from './vue-devtools.vue'\n\nexport const TanStackDevtools = Devtools\n\nexport type {\n TanStackDevtoolsVuePlugin,\n TanStackDevtoolsVueInit,\n} from './types'\n"],"names":["Devtools"],"mappings":";AAEO,MAAM,mBAAmBA;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Component } from 'vue';
|
|
2
|
+
import { ClientEventBusConfig, TanStackDevtoolsConfig } from '@tanstack/devtools';
|
|
3
|
+
export type TanStackDevtoolsVuePlugin = {
|
|
4
|
+
id?: string;
|
|
5
|
+
component: Component;
|
|
6
|
+
name: string | Component;
|
|
7
|
+
props?: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
export interface TanStackDevtoolsVueInit {
|
|
10
|
+
/**
|
|
11
|
+
* Array of plugins to be used in the devtools.
|
|
12
|
+
* Each plugin should have a `render` prop that returns a Vue component
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
* ```vue
|
|
16
|
+
* <script setup lang="ts">
|
|
17
|
+
* import { TanStackDevtools } from '@tanstack/vue-devtools'
|
|
18
|
+
* import { VueQueryDevtoolsPanel } from '@tanstack/vue-query-devtools'
|
|
19
|
+
*
|
|
20
|
+
* const plugins = [{ name: 'Vue Query', component: VueQueryDevtoolsPanel }]
|
|
21
|
+
* </script>
|
|
22
|
+
*
|
|
23
|
+
* <template>
|
|
24
|
+
* <TanStackDevtools
|
|
25
|
+
* :eventBusConfig="{ connectToServerBus: true }"
|
|
26
|
+
* :plugins="plugins"
|
|
27
|
+
* />
|
|
28
|
+
* </template>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
plugins?: Array<TanStackDevtoolsVuePlugin>;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for the devtools shell. These configuration options are used to set the
|
|
34
|
+
* initial state of the devtools when it is started for the first time. Afterwards,
|
|
35
|
+
* the settings are persisted in local storage and changed through the settings panel.
|
|
36
|
+
*/
|
|
37
|
+
config?: Partial<TanStackDevtoolsConfig>;
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for the TanStack Devtools client event bus.
|
|
40
|
+
*/
|
|
41
|
+
eventBusConfig?: ClientEventBusConfig;
|
|
42
|
+
}
|
|
43
|
+
export type RenderArray = Array<{
|
|
44
|
+
id: string;
|
|
45
|
+
component: Component;
|
|
46
|
+
props: Record<string, unknown>;
|
|
47
|
+
}>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DefineComponent } from 'vue';
|
|
2
|
+
import { TanStackDevtoolsVueInit } from './types.js';
|
|
3
|
+
declare const _default: DefineComponent<TanStackDevtoolsVueInit, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<TanStackDevtoolsVueInit> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
4
|
+
export default _default;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { defineComponent, shallowRef, ref, watchEffect, onMounted, onScopeDispose, createElementBlock, openBlock, Fragment, createElementVNode, renderList, createBlock, Teleport, resolveDynamicComponent, mergeProps } from "vue";
|
|
2
|
+
import { TanStackDevtoolsCore, PLUGIN_CONTAINER_ID } from "@tanstack/devtools";
|
|
3
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
4
|
+
__name: "vue-devtools",
|
|
5
|
+
props: {
|
|
6
|
+
plugins: {},
|
|
7
|
+
config: {},
|
|
8
|
+
eventBusConfig: {}
|
|
9
|
+
},
|
|
10
|
+
setup(__props) {
|
|
11
|
+
const props = __props;
|
|
12
|
+
const titlesToRender = shallowRef([]);
|
|
13
|
+
const pluginsToRender = shallowRef([]);
|
|
14
|
+
const div = ref();
|
|
15
|
+
function getPlugin(plugin) {
|
|
16
|
+
return {
|
|
17
|
+
id: plugin.id,
|
|
18
|
+
name: typeof plugin.name === "string" ? plugin.name : (e, theme) => {
|
|
19
|
+
const id = e.getAttribute("id");
|
|
20
|
+
titlesToRender.value = [
|
|
21
|
+
...titlesToRender.value,
|
|
22
|
+
{
|
|
23
|
+
id,
|
|
24
|
+
component: plugin.name,
|
|
25
|
+
props: {
|
|
26
|
+
theme
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
render: (e, theme) => {
|
|
32
|
+
const id = e.getAttribute("id");
|
|
33
|
+
pluginsToRender.value = [
|
|
34
|
+
...pluginsToRender.value,
|
|
35
|
+
{ id, component: plugin.component, props: { theme, ...plugin.props } }
|
|
36
|
+
];
|
|
37
|
+
},
|
|
38
|
+
destroy: (pluginId) => {
|
|
39
|
+
pluginsToRender.value = pluginsToRender.value.filter(
|
|
40
|
+
(plugin2) => plugin2.id !== `${PLUGIN_CONTAINER_ID}-${pluginId}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const devtools = new TanStackDevtoolsCore({
|
|
46
|
+
config: props.config,
|
|
47
|
+
eventBusConfig: props.eventBusConfig,
|
|
48
|
+
plugins: props.plugins?.map(getPlugin)
|
|
49
|
+
});
|
|
50
|
+
watchEffect(() => {
|
|
51
|
+
devtools.setConfig({
|
|
52
|
+
config: props.config,
|
|
53
|
+
eventBusConfig: props.eventBusConfig,
|
|
54
|
+
plugins: props.plugins?.map(getPlugin)
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
onMounted(() => {
|
|
58
|
+
if (div.value) {
|
|
59
|
+
devtools.mount(div.value);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
onScopeDispose(() => {
|
|
63
|
+
devtools.unmount();
|
|
64
|
+
});
|
|
65
|
+
return (_ctx, _cache) => {
|
|
66
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
67
|
+
createElementVNode("div", {
|
|
68
|
+
ref_key: "div",
|
|
69
|
+
ref: div
|
|
70
|
+
}, null, 512),
|
|
71
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(titlesToRender.value, (title) => {
|
|
72
|
+
return openBlock(), createBlock(Teleport, {
|
|
73
|
+
key: title.id,
|
|
74
|
+
to: "#" + title.id
|
|
75
|
+
}, [
|
|
76
|
+
(openBlock(), createBlock(resolveDynamicComponent(title.component), mergeProps({ ref_for: true }, title.props), null, 16))
|
|
77
|
+
], 8, ["to"]);
|
|
78
|
+
}), 128)),
|
|
79
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(pluginsToRender.value, (plugin) => {
|
|
80
|
+
return openBlock(), createBlock(Teleport, {
|
|
81
|
+
key: plugin.id,
|
|
82
|
+
to: "#" + plugin.id
|
|
83
|
+
}, [
|
|
84
|
+
(openBlock(), createBlock(resolveDynamicComponent(plugin.component), mergeProps({
|
|
85
|
+
"devtools-props": plugin.props
|
|
86
|
+
}, { ref_for: true }, plugin.props), null, 16, ["devtools-props"]))
|
|
87
|
+
], 8, ["to"]);
|
|
88
|
+
}), 128))
|
|
89
|
+
], 64);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
export {
|
|
94
|
+
_sfc_main as default
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=vue-devtools.vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-devtools.vue.js","sources":["../../src/vue-devtools.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { onMounted, onScopeDispose, ref, shallowRef, watchEffect } from 'vue'\nimport { PLUGIN_CONTAINER_ID, TanStackDevtoolsCore } from '@tanstack/devtools'\nimport type { DefineComponent } from 'vue'\nimport type { TanStackDevtoolsPlugin } from '@tanstack/devtools'\nimport type {\n RenderArray,\n TanStackDevtoolsVueInit,\n TanStackDevtoolsVuePlugin,\n} from './types'\n\nconst props = defineProps<TanStackDevtoolsVueInit>()\n\nconst titlesToRender = shallowRef<RenderArray>([])\nconst pluginsToRender = shallowRef<RenderArray>([])\nconst div = ref<HTMLElement>()\n\nfunction getPlugin(plugin: TanStackDevtoolsVuePlugin): TanStackDevtoolsPlugin {\n return {\n id: plugin.id,\n name:\n typeof plugin.name === 'string'\n ? plugin.name\n : (e, theme) => {\n const id = e.getAttribute('id')!\n titlesToRender.value = [\n ...titlesToRender.value,\n {\n id,\n component: plugin.name as DefineComponent<any>,\n props: {\n theme,\n },\n },\n ]\n },\n render: (e, theme) => {\n const id = e.getAttribute('id')!\n pluginsToRender.value = [\n ...pluginsToRender.value,\n { id, component: plugin.component, props: { theme, ...plugin.props } },\n ]\n },\n destroy: (pluginId) => {\n pluginsToRender.value = pluginsToRender.value.filter(\n (plugin) => plugin.id !== `${PLUGIN_CONTAINER_ID}-${pluginId}`,\n )\n },\n }\n}\n\nconst devtools = new TanStackDevtoolsCore({\n config: props.config,\n eventBusConfig: props.eventBusConfig,\n plugins: props.plugins?.map(getPlugin),\n})\n\nwatchEffect(() => {\n devtools.setConfig({\n config: props.config,\n eventBusConfig: props.eventBusConfig,\n plugins: props.plugins?.map(getPlugin),\n })\n})\n\nonMounted(() => {\n if (div.value) {\n devtools.mount(div.value)\n }\n})\n\nonScopeDispose(() => {\n devtools.unmount()\n})\n</script>\n\n<template>\n <div ref=\"div\" />\n <Teleport\n v-for=\"title in titlesToRender\"\n :key=\"title.id\"\n :to=\"'#' + title.id\"\n >\n <component :is=\"title.component\" v-bind=\"title.props\" />\n </Teleport>\n <Teleport\n v-for=\"plugin in pluginsToRender\"\n :key=\"plugin.id\"\n :to=\"'#' + plugin.id\"\n >\n <component\n :is=\"plugin.component\"\n :devtools-props=\"plugin.props\"\n v-bind=\"plugin.props\"\n />\n </Teleport>\n</template>\n"],"names":["plugin","_createElementVNode","_createElementBlock","_Fragment","_renderList","_createBlock","_Teleport","_resolveDynamicComponent","_mergeProps","_openBlock"],"mappings":";;;;;;;;;;AAWA,UAAM,QAAQ;AAEd,UAAM,iBAAiB,WAAwB,EAAE;AACjD,UAAM,kBAAkB,WAAwB,EAAE;AAClD,UAAM,MAAM,IAAA;AAEZ,aAAS,UAAU,QAA2D;AAC5E,aAAO;AAAA,QACL,IAAI,OAAO;AAAA,QACX,MACE,OAAO,OAAO,SAAS,WACnB,OAAO,OACP,CAAC,GAAG,UAAU;AACZ,gBAAM,KAAK,EAAE,aAAa,IAAI;AAC9B,yBAAe,QAAQ;AAAA,YACrB,GAAG,eAAe;AAAA,YAClB;AAAA,cACE;AAAA,cACA,WAAW,OAAO;AAAA,cAClB,OAAO;AAAA,gBACL;AAAA,cAAA;AAAA,YACF;AAAA,UACF;AAAA,QAEJ;AAAA,QACN,QAAQ,CAAC,GAAG,UAAU;AACpB,gBAAM,KAAK,EAAE,aAAa,IAAI;AAC9B,0BAAgB,QAAQ;AAAA,YACtB,GAAG,gBAAgB;AAAA,YACnB,EAAE,IAAI,WAAW,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,OAAO,MAAA,EAAM;AAAA,UAAE;AAAA,QAEzE;AAAA,QACA,SAAS,CAAC,aAAa;AACrB,0BAAgB,QAAQ,gBAAgB,MAAM;AAAA,YAC5C,CAACA,YAAWA,QAAO,OAAO,GAAG,mBAAmB,IAAI,QAAQ;AAAA,UAAA;AAAA,QAEhE;AAAA,MAAA;AAAA,IAEJ;AAEA,UAAM,WAAW,IAAI,qBAAqB;AAAA,MACxC,QAAQ,MAAM;AAAA,MACd,gBAAgB,MAAM;AAAA,MACtB,SAAS,MAAM,SAAS,IAAI,SAAS;AAAA,IAAA,CACtC;AAED,gBAAY,MAAM;AAChB,eAAS,UAAU;AAAA,QACjB,QAAQ,MAAM;AAAA,QACd,gBAAgB,MAAM;AAAA,QACtB,SAAS,MAAM,SAAS,IAAI,SAAS;AAAA,MAAA,CACtC;AAAA,IACH,CAAC;AAED,cAAU,MAAM;AACd,UAAI,IAAI,OAAO;AACb,iBAAS,MAAM,IAAI,KAAK;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,mBAAe,MAAM;AACnB,eAAS,QAAA;AAAA,IACX,CAAC;;;QAICC,mBAAiB,OAAA;AAAA,mBAAR;AAAA,UAAJ,KAAI;AAAA,QAAA;0BACTC,mBAMWC,UAAA,MAAAC,WALO,eAAA,OAAc,CAAvB,UAAK;8BADdC,YAMWC,UAAA;AAAA,YAJR,KAAK,MAAM;AAAA,YACX,IAAE,MAAQ,MAAM;AAAA,UAAA;0BAEjBD,YAAwDE,wBAAxC,MAAM,SAAS,GAA/BC,WAAwD,EAAA,SAAA,QAAf,MAAM,KAAK,GAAA,MAAA,EAAA;AAAA,UAAA;;0BAEtDN,mBAUWC,UAAA,MAAAC,WATQ,gBAAA,OAAe,CAAzB,WAAM;8BADfC,YAUWC,UAAA;AAAA,YARR,KAAK,OAAO;AAAA,YACZ,IAAE,MAAQ,OAAO;AAAA,UAAA;aAElBG,aAAAJ,YAIEE,wBAHK,OAAO,SAAS,GADvBC,WAIE;AAAA,cAFC,kBAAgB,OAAO;AAAA,YAAA,GAChB,EAAA,SAAA,KAAA,GAAA,OAAO,KAAK,GAAA,MAAA,IAAA,CAAA,gBAAA,CAAA;AAAA,UAAA;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-devtools.vue2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/vue-devtools",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TanStack Devtools is a set of tools for building advanced devtools for your Vue application.",
|
|
5
|
+
"author": "Damian Osipiuk",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/devtools.git",
|
|
10
|
+
"directory": "packages/vue-devtools"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://tanstack.com/devtools",
|
|
13
|
+
"funding": {
|
|
14
|
+
"type": "github",
|
|
15
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"vue",
|
|
19
|
+
"devtools"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "dist/esm/index.d.ts",
|
|
23
|
+
"module": "dist/esm/index.js",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/esm/index.d.ts",
|
|
28
|
+
"default": "./dist/esm/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"src"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@tanstack/devtools": "0.8.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
46
|
+
"eslint-plugin-vue": "^10.5.1",
|
|
47
|
+
"vue": "^3.5.22"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"clean": "premove ./build ./dist",
|
|
51
|
+
"test:eslint": "eslint ./src",
|
|
52
|
+
"test:lib": "vitest --passWithNoTests",
|
|
53
|
+
"test:lib:dev": "pnpm test:lib --watch",
|
|
54
|
+
"test:types": "tsc",
|
|
55
|
+
"test:build": "publint --strict",
|
|
56
|
+
"build": "vite build"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Component } from 'vue'
|
|
2
|
+
import type {
|
|
3
|
+
ClientEventBusConfig,
|
|
4
|
+
TanStackDevtoolsConfig,
|
|
5
|
+
} from '@tanstack/devtools'
|
|
6
|
+
|
|
7
|
+
export type TanStackDevtoolsVuePlugin = {
|
|
8
|
+
id?: string
|
|
9
|
+
component: Component
|
|
10
|
+
name: string | Component
|
|
11
|
+
props?: Record<string, any>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TanStackDevtoolsVueInit {
|
|
15
|
+
/**
|
|
16
|
+
* Array of plugins to be used in the devtools.
|
|
17
|
+
* Each plugin should have a `render` prop that returns a Vue component
|
|
18
|
+
*
|
|
19
|
+
* Example:
|
|
20
|
+
* ```vue
|
|
21
|
+
* <script setup lang="ts">
|
|
22
|
+
* import { TanStackDevtools } from '@tanstack/vue-devtools'
|
|
23
|
+
* import { VueQueryDevtoolsPanel } from '@tanstack/vue-query-devtools'
|
|
24
|
+
*
|
|
25
|
+
* const plugins = [{ name: 'Vue Query', component: VueQueryDevtoolsPanel }]
|
|
26
|
+
* </script>
|
|
27
|
+
*
|
|
28
|
+
* <template>
|
|
29
|
+
* <TanStackDevtools
|
|
30
|
+
* :eventBusConfig="{ connectToServerBus: true }"
|
|
31
|
+
* :plugins="plugins"
|
|
32
|
+
* />
|
|
33
|
+
* </template>
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
plugins?: Array<TanStackDevtoolsVuePlugin>
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for the devtools shell. These configuration options are used to set the
|
|
39
|
+
* initial state of the devtools when it is started for the first time. Afterwards,
|
|
40
|
+
* the settings are persisted in local storage and changed through the settings panel.
|
|
41
|
+
*/
|
|
42
|
+
config?: Partial<TanStackDevtoolsConfig>
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for the TanStack Devtools client event bus.
|
|
45
|
+
*/
|
|
46
|
+
eventBusConfig?: ClientEventBusConfig
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type RenderArray = Array<{
|
|
50
|
+
id: string
|
|
51
|
+
component: Component
|
|
52
|
+
props: Record<string, unknown>
|
|
53
|
+
}>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, onScopeDispose, ref, shallowRef, watchEffect } from 'vue'
|
|
3
|
+
import { PLUGIN_CONTAINER_ID, TanStackDevtoolsCore } from '@tanstack/devtools'
|
|
4
|
+
import type { DefineComponent } from 'vue'
|
|
5
|
+
import type { TanStackDevtoolsPlugin } from '@tanstack/devtools'
|
|
6
|
+
import type {
|
|
7
|
+
RenderArray,
|
|
8
|
+
TanStackDevtoolsVueInit,
|
|
9
|
+
TanStackDevtoolsVuePlugin,
|
|
10
|
+
} from './types'
|
|
11
|
+
|
|
12
|
+
const props = defineProps<TanStackDevtoolsVueInit>()
|
|
13
|
+
|
|
14
|
+
const titlesToRender = shallowRef<RenderArray>([])
|
|
15
|
+
const pluginsToRender = shallowRef<RenderArray>([])
|
|
16
|
+
const div = ref<HTMLElement>()
|
|
17
|
+
|
|
18
|
+
function getPlugin(plugin: TanStackDevtoolsVuePlugin): TanStackDevtoolsPlugin {
|
|
19
|
+
return {
|
|
20
|
+
id: plugin.id,
|
|
21
|
+
name:
|
|
22
|
+
typeof plugin.name === 'string'
|
|
23
|
+
? plugin.name
|
|
24
|
+
: (e, theme) => {
|
|
25
|
+
const id = e.getAttribute('id')!
|
|
26
|
+
titlesToRender.value = [
|
|
27
|
+
...titlesToRender.value,
|
|
28
|
+
{
|
|
29
|
+
id,
|
|
30
|
+
component: plugin.name as DefineComponent<any>,
|
|
31
|
+
props: {
|
|
32
|
+
theme,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
render: (e, theme) => {
|
|
38
|
+
const id = e.getAttribute('id')!
|
|
39
|
+
pluginsToRender.value = [
|
|
40
|
+
...pluginsToRender.value,
|
|
41
|
+
{ id, component: plugin.component, props: { theme, ...plugin.props } },
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
destroy: (pluginId) => {
|
|
45
|
+
pluginsToRender.value = pluginsToRender.value.filter(
|
|
46
|
+
(plugin) => plugin.id !== `${PLUGIN_CONTAINER_ID}-${pluginId}`,
|
|
47
|
+
)
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const devtools = new TanStackDevtoolsCore({
|
|
53
|
+
config: props.config,
|
|
54
|
+
eventBusConfig: props.eventBusConfig,
|
|
55
|
+
plugins: props.plugins?.map(getPlugin),
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
watchEffect(() => {
|
|
59
|
+
devtools.setConfig({
|
|
60
|
+
config: props.config,
|
|
61
|
+
eventBusConfig: props.eventBusConfig,
|
|
62
|
+
plugins: props.plugins?.map(getPlugin),
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
onMounted(() => {
|
|
67
|
+
if (div.value) {
|
|
68
|
+
devtools.mount(div.value)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
onScopeDispose(() => {
|
|
73
|
+
devtools.unmount()
|
|
74
|
+
})
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<template>
|
|
78
|
+
<div ref="div" />
|
|
79
|
+
<Teleport
|
|
80
|
+
v-for="title in titlesToRender"
|
|
81
|
+
:key="title.id"
|
|
82
|
+
:to="'#' + title.id"
|
|
83
|
+
>
|
|
84
|
+
<component :is="title.component" v-bind="title.props" />
|
|
85
|
+
</Teleport>
|
|
86
|
+
<Teleport
|
|
87
|
+
v-for="plugin in pluginsToRender"
|
|
88
|
+
:key="plugin.id"
|
|
89
|
+
:to="'#' + plugin.id"
|
|
90
|
+
>
|
|
91
|
+
<component
|
|
92
|
+
:is="plugin.component"
|
|
93
|
+
:devtools-props="plugin.props"
|
|
94
|
+
v-bind="plugin.props"
|
|
95
|
+
/>
|
|
96
|
+
</Teleport>
|
|
97
|
+
</template>
|