-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue-query-devtools): Add VueQueryDevtoolsPanel support
- Loading branch information
Showing
21 changed files
with
333 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
package-lock.json | ||
yarn.lock | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Basic example | ||
|
||
To run this example: | ||
|
||
- `npm install` or `yarn` or `pnpm i` or `bun i` | ||
- `npm run dev` or `yarn dev` or `pnpm dev` or `bun dev` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>TanStack Query Vue Devtools Panel Example App</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@tanstack/query-example-vue-devtools-panel", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@tanstack/vue-query": "^5.54.1", | ||
"@tanstack/vue-query-devtools": "^5.54.1", | ||
"vue": "^3.4.27", | ||
"vue-demi": "^0.14.10" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "^5.1.1", | ||
"typescript": "5.3.3", | ||
"vite": "^5.3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import { useQuery } from '@tanstack/vue-query' | ||
import { VueQueryDevtoolsPanel } from '@tanstack/vue-query-devtools' | ||
export default defineComponent({ | ||
name: 'App', | ||
components: { VueQueryDevtoolsPanel }, | ||
setup() { | ||
const { data, error, isFetching, isPending } = useQuery({ | ||
queryKey: ['repoData'], | ||
async queryFn() { | ||
return await fetch('https://api.github.com/repos/Tanstack/query').then( | ||
(response) => response.json(), | ||
) | ||
}, | ||
}) | ||
return { | ||
data, | ||
error, | ||
isFetching, | ||
isPending, | ||
} | ||
}, | ||
}) | ||
</script> | ||
|
||
// @todo: add button to switch between open & close devtools panel | ||
|
||
<template> | ||
<template v-if="isPending"> Loading... </template> | ||
<template v-else-if="error"> | ||
'An error has occurred: {{ error.message }} | ||
</template> | ||
<template v-else> | ||
<h1>{{ data.name }}</h1> | ||
<p>{{ data.description }}</p> | ||
<strong>👀 {{ data.subscribers_count }}</strong> | ||
<strong>✨ {{ data.stargazers_count }}</strong> | ||
<strong>🍴 {{ data.forks_count }}</strong> | ||
<div>{{ isFetching ? 'Updating...' : '' }}</div> | ||
</template> | ||
<VueQueryDevtoolsPanel /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createApp } from 'vue' | ||
import { VueQueryPlugin } from '@tanstack/vue-query' | ||
|
||
import App from './App.vue' | ||
|
||
createApp(App).use(VueQueryPlugin).mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module '*.vue' { | ||
import { DefineComponent } from 'vue' | ||
const component: DefineComponent<{}, {}, any> | ||
export default component | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface Post { | ||
userId: number | ||
id: number | ||
title: string | ||
body: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"jsx": "preserve", | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"lib": ["esnext", "dom"], | ||
"types": ["vite/client"] | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
plugins: [vue()], | ||
optimizeDeps: { | ||
exclude: ['@tanstack/vue-query', 'vue-demi'], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<script setup lang="ts"> | ||
import { onlineManager, useQueryClient } from '@tanstack/vue-query' | ||
import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools' | ||
import { onMounted, onScopeDispose, ref, watchEffect } from 'vue' | ||
import { reactive } from 'vue-demi' | ||
import type { DevtoolsPanelOptions } from './types' | ||
const props = defineProps<DevtoolsPanelOptions>() | ||
const styleObject = reactive({ | ||
height: '500px', | ||
...props.style, | ||
}) | ||
const div = ref<HTMLElement>() | ||
const client = props.client || useQueryClient() | ||
const devtools = new TanstackQueryDevtoolsPanel({ | ||
client, | ||
queryFlavor: 'Vue Query', | ||
version: '5', | ||
onlineManager, | ||
buttonPosition: 'bottom-left', | ||
position: 'bottom', | ||
initialIsOpen: true, | ||
errorTypes: props.errorTypes, | ||
styleNonce: props.styleNonce, | ||
shadowDOMTarget: props.shadowDOMTarget, | ||
onClose: props.onClose, | ||
}) | ||
watchEffect(() => { | ||
devtools.setOnClose(props.onClose ?? (() => {})) | ||
devtools.setErrorTypes(props.errorTypes || []) | ||
}) | ||
onMounted(() => { | ||
devtools.mount(div.value as HTMLElement) | ||
}) | ||
onScopeDispose(() => { | ||
devtools.unmount() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div :style="styleObject" className="tsqd-parent-container" ref="div"></div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import devtools from './devtools.vue' | ||
import Devtools from './VueQueryDevtools.vue' | ||
import DevtoolsPanel from './VueQueryDevtoolsPanel.vue' | ||
import type { DefineComponent } from 'vue' | ||
import type { DevtoolsOptions } from './types' | ||
import type { DevtoolsOptions, DevtoolsPanelOptions } from './types' | ||
|
||
export const VueQueryDevtools = ( | ||
process.env.NODE_ENV !== 'development' | ||
? function () { | ||
return null | ||
} | ||
: devtools | ||
: Devtools | ||
) as DefineComponent<DevtoolsOptions, {}, unknown> | ||
|
||
export const VueQueryDevtoolsPanel = ( | ||
process.env.NODE_ENV !== 'development' | ||
? function () { | ||
return null | ||
} | ||
: DevtoolsPanel | ||
) as DefineComponent<DevtoolsPanelOptions, {}, unknown> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import devtools from './devtools.vue' | ||
import Devtools from './VueQueryDevtools.vue' | ||
import DevtoolsPanel from './VueQueryDevtoolsPanel.vue' | ||
|
||
export default devtools | ||
export const VueQueryDevtools = Devtools | ||
export const VueQueryDevtoolsPanel = DevtoolsPanel |
Oops, something went wrong.