Open History to see the last commit
1<script lang="ts">
2 import { onlineManager, useQueryClient } from '@tanstack/svelte-query'
3 import { BROWSER } from 'esm-env'
4 import { onMount } from 'svelte'
5 import type {
6 DevtoolsButtonPosition,
7 DevtoolsErrorType,
8 DevtoolsPosition,
9 TanstackQueryDevtools,
10 Theme,
11 } from '@tanstack/query-devtools'
12 import type { QueryClient } from '@tanstack/svelte-query'
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 * @deprecated The devtools no longer add a `<style>` element, so they need
43 * no nonce. This option does nothing.
44 */
45 styleNonce?: string
46 /**
47 * The shadow root to add the devtools styles to. By default, the styles are
48 * added to the shadow root the devtools render in, or to the document when
49 * they do not render in a shadow root.
50 */
51 shadowDOMTarget?: ShadowRoot
52 /**
53 * The Trusted Types policy the devtools use to create their HTML templates.
54 * Pass one when your page enforces `require-trusted-types-for 'script'`.
55 * The devtools only pass it their own markup.
56 */
57 trustedTypesPolicy?: { createHTML: (html: string) => unknown }
58 /**
59 * Set this to true to hide disabled queries from the devtools panel.
60 */
61 hideDisabledQueries?: boolean
62 /**
63 * Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
64 * This overrides the theme selected in the devtools Settings menu. When omitted, the
65 * selected theme is used, or `'system'` if none is selected.
66 */
67 theme?: Theme
68 }
69β
70 let {
71 initialIsOpen = false,
72 buttonPosition = 'bottom-right',
73 position = 'bottom',
74 client = useQueryClient(),
75 errorTypes = [],
76 shadowDOMTarget = undefined,
77 trustedTypesPolicy = undefined,
78 hideDisabledQueries = false,
79 theme,
80 }: DevtoolsOptions = $props()
81β
82 let ref: HTMLDivElement
83 let devtools = $state<TanstackQueryDevtools | undefined>(undefined)
84β
85 if (BROWSER) {
86 onMount(() => {
87 import('@tanstack/query-devtools').then((m) => {
88 const QueryDevtools = m.TanstackQueryDevtools
89β
90 devtools = new QueryDevtools({
91 client,
92 queryFlavor: 'Svelte Query',
93 version: '5',
94 onlineManager,
95 buttonPosition,
96 position,
97 initialIsOpen,
98 errorTypes,
99 shadowDOMTarget,
100 trustedTypesPolicy,
101 hideDisabledQueries,
102 theme,
103 })
104β
105 devtools.mount(ref)
106 })
107 return () => devtools?.unmount()
108 })
109β
110 $effect(() => {
111 devtools?.setButtonPosition(buttonPosition)
112 })
113β
114 $effect(() => {
115 devtools?.setPosition(position)
116 })
117β
118 $effect(() => {
119 devtools?.setInitialIsOpen(initialIsOpen)
120 })
121β
122 $effect(() => {
123 devtools?.setErrorTypes(errorTypes)
124 })
125β
126 $effect(() => {
127 devtools?.setTheme(theme)
128 })
129 }
130</script>
131β
132<div class="tsqd-parent-container" bind:this={ref}></div>