Open History to see the last commit
1<script lang="ts">
2 import { onMount } from 'svelte'
3 import { BROWSER, DEV } from 'esm-env'
4 import { onlineManager, useQueryClient } from '@tanstack/svelte-query'
5 import type { QueryClient } from '@tanstack/svelte-query'
6 import type {
7 DevtoolsButtonPosition,
8 DevtoolsErrorType,
9 DevtoolsPosition,
10 TanstackQueryDevtools,
11 Theme,
12 } from '@tanstack/query-devtools'
13β
14 interface DevtoolsOptions {
15 /**
16 * Set this true if you want the dev tools to default to being open
17 */
18 initialIsOpen?: boolean
19 /**
20 * The position of the TanStack logo to open and close the devtools panel.
21 * 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'relative'
22 *
23 * @defaultValue bottom-right
24 */
25 buttonPosition?: DevtoolsButtonPosition
26 /**
27 * The position of the Svelte Query devtools panel.
28 * 'top' | 'bottom' | 'left' | 'right'
29 *
30 * @defaultValue bottom
31 */
32 position?: DevtoolsPosition
33 /**
34 * Custom instance of QueryClient
35 */
36 client?: QueryClient
37 /**
38 * Use this so you can define custom errors that can be shown in the devtools.
39 */
40 errorTypes?: Array<DevtoolsErrorType>
41 /**
42 * Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
43 */
44 styleNonce?: string
45 /**
46 * Use this so you can attach the devtool's styles to specific element in the DOM.
47 */
48 shadowDOMTarget?: ShadowRoot
49 /**
50 * Set this to true to hide disabled queries from the devtools panel.
51 */
52 hideDisabledQueries?: boolean
53 /**
54 * Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
55 * Defaults to 'system'.
56 */
57 theme?: Theme
58 }
59β
60 let {
61 initialIsOpen = false,
62 buttonPosition = 'bottom-right',
63 position = 'bottom',
64 client = useQueryClient(),
65 errorTypes = [],
66 styleNonce = undefined,
67 shadowDOMTarget = undefined,
68 hideDisabledQueries = false,
69 theme = 'system',
70 }: DevtoolsOptions = $props()
71β
72 let ref: HTMLDivElement
73 let devtools = $state<TanstackQueryDevtools | undefined>(undefined)
74β
75 if (DEV && BROWSER) {
76 onMount(() => {
77 import('@tanstack/query-devtools').then((m) => {
78 const QueryDevtools = m.TanstackQueryDevtools
79β
80 devtools = new QueryDevtools({
81 client,
82 queryFlavor: 'Svelte Query',
83 version: '5',
84 onlineManager,
85 buttonPosition,
86 position,
87 initialIsOpen,
88 errorTypes,
89 styleNonce,
90 shadowDOMTarget,
91 hideDisabledQueries,
92 theme,
93 })
94β
95 devtools.mount(ref)
96 })
97 return () => devtools?.unmount()
98 })
99β
100 $effect(() => {
101 devtools?.setButtonPosition(buttonPosition)
102 })
103β
104 $effect(() => {
105 devtools?.setPosition(position)
106 })
107β
108 $effect(() => {
109 devtools?.setInitialIsOpen(initialIsOpen)
110 })
111β
112 $effect(() => {
113 devtools?.setErrorTypes(errorTypes)
114 })
115β
116 $effect(() => {
117 devtools?.setTheme(theme)
118 })
119 }
120</script>
121β
122<div class="tsqd-parent-container" bind:this={ref}></div>