@tanstack/query-devtools 5.104.0 → 5.104.2

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.
Files changed (60) hide show
  1. package/build/Devtools-BTIH1dw_.js +1238 -0
  2. package/build/Devtools-BTIH1dw_.js.map +1 -0
  3. package/build/{Devtools-XuAvSfeN.cjs → Devtools-CJHY2Wx-.cjs} +388 -66
  4. package/build/{Devtools-xfqOl5Dl.js → Devtools-DBqcRO2f.js} +371 -67
  5. package/build/Devtools-DE6wfpC3.cjs +1237 -0
  6. package/build/DevtoolsComponent-B-JX7seJ.js +2 -0
  7. package/build/DevtoolsComponent-B-JX7seJ.js.map +1 -0
  8. package/build/DevtoolsComponent-BdsgosNO.js +40 -0
  9. package/build/DevtoolsComponent-BjB9B9oL.cjs +40 -0
  10. package/build/DevtoolsComponent-u_hbjcma.cjs +1 -0
  11. package/build/DevtoolsPanelComponent-CdrNDWsc.js +2 -0
  12. package/build/DevtoolsPanelComponent-CdrNDWsc.js.map +1 -0
  13. package/build/DevtoolsPanelComponent-Co1Z91vW.cjs +47 -0
  14. package/build/DevtoolsPanelComponent-DyNlv9xD.cjs +1 -0
  15. package/build/DevtoolsPanelComponent-Jyh8juKn.js +47 -0
  16. package/build/dev.cjs +3 -3
  17. package/build/dev.js +3 -3
  18. package/build/index.cjs +1 -1
  19. package/build/index.d.cts +82 -0
  20. package/build/index.d.cts.map +1 -1
  21. package/build/index.d.ts +82 -0
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +1 -1
  24. package/build/index.js.map +1 -1
  25. package/build/{utils-BSq_mRvI.cjs → utils-C0KLuaCQ.cjs} +57 -12
  26. package/build/{utils-Fz9uQv9N.js → utils-DPVWL709.js} +57 -12
  27. package/build/utils-po3vZo_N.js.map +1 -1
  28. package/package.json +9 -9
  29. package/src/Devtools.tsx +87 -82
  30. package/src/DevtoolsComponent.tsx +17 -5
  31. package/src/DevtoolsPanelComponent.tsx +23 -14
  32. package/src/Explorer.tsx +18 -4
  33. package/src/TanstackQueryDevtools.tsx +11 -0
  34. package/src/TanstackQueryDevtoolsPanel.tsx +14 -0
  35. package/src/contexts/DevtoolsOfflineContext.ts +15 -0
  36. package/src/contexts/DevtoolsStateContext.ts +15 -0
  37. package/src/contexts/DevtoolsSubscriptionsContext.ts +16 -0
  38. package/src/contexts/PiPContext.tsx +13 -0
  39. package/src/contexts/QueryDevtoolsContext.ts +4 -0
  40. package/src/contexts/ThemeContext.ts +4 -0
  41. package/src/contexts/types.ts +133 -1
  42. package/src/createCacheSubscriptionRegistry.ts +58 -0
  43. package/src/icons/index.tsx +102 -0
  44. package/src/providers/DevtoolsOfflineProvider.tsx +37 -0
  45. package/src/providers/DevtoolsStateProvider.tsx +33 -0
  46. package/src/providers/DevtoolsSubscriptionsProvider.tsx +35 -0
  47. package/src/utils.tsx +59 -15
  48. package/build/Devtools-DP9QP4ya.cjs +0 -1237
  49. package/build/Devtools-DpIxfOum.js +0 -1238
  50. package/build/Devtools-DpIxfOum.js.map +0 -1
  51. package/build/DevtoolsComponent-BEFw32kp.js +0 -2
  52. package/build/DevtoolsComponent-BEFw32kp.js.map +0 -1
  53. package/build/DevtoolsComponent-DRjJuLRU.js +0 -34
  54. package/build/DevtoolsComponent-DjkCvfLf.cjs +0 -34
  55. package/build/DevtoolsComponent-bl_b_SFT.cjs +0 -1
  56. package/build/DevtoolsPanelComponent-BE6hbJd6.js +0 -2
  57. package/build/DevtoolsPanelComponent-BE6hbJd6.js.map +0 -1
  58. package/build/DevtoolsPanelComponent-BTfH8T_h.cjs +0 -41
  59. package/build/DevtoolsPanelComponent-CkmpODyJ.js +0 -41
  60. package/build/DevtoolsPanelComponent-DfaRC3RE.cjs +0 -1
package/src/utils.tsx CHANGED
@@ -3,6 +3,12 @@ import { createSignal, onCleanup, onMount } from 'solid-js'
3
3
  import type { Mutation, Query } from '@tanstack/query-core'
4
4
  import type { DevtoolsPosition } from './contexts'
5
5
 
6
+ /**
7
+ * Returns the status label of a query: fetching, inactive (no observers), paused, stale, or fresh,
8
+ * checked in that order.
9
+ * @param query - The query to label.
10
+ * @returns One of `'fetching'`, `'inactive'`, `'paused'`, `'stale'`, or `'fresh'`.
11
+ */
6
12
  export function getQueryStatusLabel(query: Query) {
7
13
  return query.state.fetchStatus === 'fetching'
8
14
  ? 'fetching'
@@ -17,6 +23,12 @@ export function getQueryStatusLabel(query: Query) {
17
23
 
18
24
  type QueryStatusLabel = 'fresh' | 'stale' | 'paused' | 'inactive' | 'fetching'
19
25
 
26
+ /**
27
+ * Appends a capitalized side to a CSS property name, e.g. `border` and `left` to `borderLeft`.
28
+ * @param prop - The property name.
29
+ * @param side - The side to append.
30
+ * @returns The sided property name.
31
+ */
20
32
  export function getSidedProp<T extends string>(
21
33
  prop: T,
22
34
  side: DevtoolsPosition,
@@ -26,6 +38,12 @@ export function getSidedProp<T extends string>(
26
38
  }` as `${T}${Capitalize<DevtoolsPosition>}`
27
39
  }
28
40
 
41
+ /**
42
+ * Returns the color of a query's status: blue while fetching, gray without observers, purple while
43
+ * paused, yellow when stale, otherwise green.
44
+ * @param params - The query's `queryState`, `observerCount`, and `isStale`.
45
+ * @returns The color name.
46
+ */
29
47
  export function getQueryStatusColor({
30
48
  queryState,
31
49
  observerCount,
@@ -46,6 +64,12 @@ export function getQueryStatusColor({
46
64
  : 'green'
47
65
  }
48
66
 
67
+ /**
68
+ * Returns the color of a mutation's status: purple while paused, red on error, yellow while pending,
69
+ * green on success, otherwise gray.
70
+ * @param params - The mutation's `status` and `isPaused`.
71
+ * @returns The color name.
72
+ */
49
73
  export function getMutationStatusColor({
50
74
  status,
51
75
  isPaused,
@@ -64,6 +88,11 @@ export function getMutationStatusColor({
64
88
  : 'gray'
65
89
  }
66
90
 
91
+ /**
92
+ * Returns the color of a query status label.
93
+ * @param label - A label returned by {@link getQueryStatusLabel}.
94
+ * @returns The color name.
95
+ */
67
96
  export function getQueryStatusColorByLabel(label: QueryStatusLabel) {
68
97
  return label === 'fresh'
69
98
  ? 'green'
@@ -77,9 +106,10 @@ export function getQueryStatusColorByLabel(label: QueryStatusLabel) {
77
106
  }
78
107
 
79
108
  /**
80
- * Displays a string regardless of the type of the data
81
- * @param {unknown} value Value to be stringified
82
- * @param {boolean} beautify Formats json to multiline
109
+ * Displays a string regardless of the type of the data.
110
+ * @param value - Value to be stringified
111
+ * @param beautify - Formats json to multiline
112
+ * @returns The value serialized with `superjson`, as a JSON string.
83
113
  */
84
114
  export const displayValue = (value: unknown, beautify: boolean = false) => {
85
115
  const { json } = serialize(value)
@@ -147,10 +177,20 @@ export const mutationSortFns: Record<string, MutationSortFn> = {
147
177
  'last updated': mutationDateSort,
148
178
  }
149
179
 
180
+ /**
181
+ * Converts a length in `rem` to pixels, using the root element's font size.
182
+ * @param rem - The length in `rem`.
183
+ * @returns The length in pixels.
184
+ */
150
185
  export const convertRemToPixels = (rem: number) => {
151
186
  return rem * parseFloat(getComputedStyle(document.documentElement).fontSize)
152
187
  }
153
188
 
189
+ /**
190
+ * Tracks the user's `prefers-color-scheme` setting.
191
+ * @returns An accessor of `'light'` or `'dark'`, updated when the setting
192
+ * changes.
193
+ */
154
194
  export const getPreferredColorScheme = () => {
155
195
  const [colorScheme, setColorScheme] = createSignal<'light' | 'dark'>('dark')
156
196
 
@@ -168,11 +208,11 @@ export const getPreferredColorScheme = () => {
168
208
  }
169
209
 
170
210
  /**
171
- * updates nested data by path
172
- *
173
- * @param {unknown} oldData Data to be updated
174
- * @param {Array<string>} updatePath Path to the data to be updated
175
- * @param {unknown} value New value
211
+ * Updates nested data by path.
212
+ * @param oldData - Data to be updated
213
+ * @param updatePath - Path to the data to be updated
214
+ * @param value - New value
215
+ * @returns A copy of `oldData` with the value at `updatePath` replaced.
176
216
  */
177
217
  export const updateNestedDataByPath = (
178
218
  oldData: unknown,
@@ -242,10 +282,9 @@ export const updateNestedDataByPath = (
242
282
  }
243
283
 
244
284
  /**
245
- * Deletes nested data by path
246
- *
247
- * @param {unknown} oldData Data to be updated
248
- * @param {Array<string>} deletePath Path to the data to be deleted
285
+ * Deletes nested data by path.
286
+ * @param oldData - Data to be updated
287
+ * @param deletePath - Path to the data to be deleted
249
288
  * @returns newData without the deleted items by path
250
289
  */
251
290
  export const deleteNestedDataByPath = (
@@ -304,10 +343,15 @@ export const deleteNestedDataByPath = (
304
343
  return oldData
305
344
  }
306
345
 
307
- // Sets up the goober stylesheet
308
- // Adds a nonce to the style tag if needed
346
+ /**
347
+ * Sets up the goober stylesheet with a `nonce`, for pages with a Content Security Policy. Without a
348
+ * `nonce`, it does nothing and goober creates the stylesheet itself.
349
+ * @param nonce - The nonce to set on the style tag.
350
+ * @param target - The shadow root to add the style tag to, instead of `document.head`.
351
+ */
309
352
  export const setupStyleSheet = (nonce?: string, target?: ShadowRoot) => {
310
- if (!nonce) return // Goober reads window.__nonce__ every time it creates or accesses its style
353
+ if (!nonce)
354
+ return // Goober reads window.__nonce__ every time it creates or accesses its style
311
355
  // element (el.nonce = window.__nonce__). Without this, goober overwrites the
312
356
  // nonce we set on the pre-created element with undefined, clearing it.
313
357
  ;(window as any).__nonce__ = nonce