@tanstack/react-query-devtools 5.0.0-alpha.5 → 5.0.0-alpha.50

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 (109) hide show
  1. package/build/lib/__tests__/devtools.test.d.ts +1 -1
  2. package/build/lib/__tests__/devtools.test.d.ts.map +1 -0
  3. package/build/lib/__tests__/utils.d.ts +2 -1
  4. package/build/lib/__tests__/utils.d.ts.map +1 -0
  5. package/build/lib/devtools.d.ts +11 -75
  6. package/build/lib/devtools.d.ts.map +1 -0
  7. package/build/lib/devtools.js +49 -783
  8. package/build/lib/devtools.js.map +1 -1
  9. package/build/lib/devtools.mjs +52 -766
  10. package/build/lib/devtools.mjs.map +1 -1
  11. package/build/lib/index.d.ts +1 -1
  12. package/build/lib/index.d.ts.map +1 -0
  13. package/build/lib/index.js +8 -4
  14. package/build/lib/index.js.map +1 -1
  15. package/build/lib/index.mjs +10 -5
  16. package/build/lib/index.mjs.map +1 -1
  17. package/build/lib/{index.prod.d.ts → index.prod.d.ts/index.d.ts} +1 -1
  18. package/build/lib/index.prod.js +7923 -1389
  19. package/build/lib/index.prod.js.map +1 -1
  20. package/build/lib/index.prod.mjs +7857 -1303
  21. package/build/lib/index.prod.mjs.map +1 -1
  22. package/package.json +17 -16
  23. package/src/__tests__/devtools.test.tsx +1 -861
  24. package/src/devtools.tsx +61 -1164
  25. package/src/index.ts +6 -6
  26. package/build/lib/Explorer.d.ts +0 -50
  27. package/build/lib/Explorer.esm.js +0 -253
  28. package/build/lib/Explorer.esm.js.map +0 -1
  29. package/build/lib/Explorer.js +0 -287
  30. package/build/lib/Explorer.js.map +0 -1
  31. package/build/lib/Explorer.mjs +0 -253
  32. package/build/lib/Explorer.mjs.map +0 -1
  33. package/build/lib/Logo.d.ts +0 -1
  34. package/build/lib/Logo.esm.js +0 -32
  35. package/build/lib/Logo.esm.js.map +0 -1
  36. package/build/lib/Logo.js +0 -55
  37. package/build/lib/Logo.js.map +0 -1
  38. package/build/lib/Logo.mjs +0 -32
  39. package/build/lib/Logo.mjs.map +0 -1
  40. package/build/lib/__tests__/Explorer.test.d.ts +0 -1
  41. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -17
  42. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
  43. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -19
  44. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  45. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -17
  46. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +0 -1
  47. package/build/lib/devtools.esm.js +0 -773
  48. package/build/lib/devtools.esm.js.map +0 -1
  49. package/build/lib/index.esm.js +0 -11
  50. package/build/lib/index.esm.js.map +0 -1
  51. package/build/lib/index.prod.esm.js +0 -1431
  52. package/build/lib/index.prod.esm.js.map +0 -1
  53. package/build/lib/noop.d.ts +0 -2
  54. package/build/lib/screenreader.d.ts +0 -3
  55. package/build/lib/screenreader.esm.js +0 -17
  56. package/build/lib/screenreader.esm.js.map +0 -1
  57. package/build/lib/screenreader.js +0 -40
  58. package/build/lib/screenreader.js.map +0 -1
  59. package/build/lib/screenreader.mjs +0 -17
  60. package/build/lib/screenreader.mjs.map +0 -1
  61. package/build/lib/styledComponents.d.ts +0 -9
  62. package/build/lib/styledComponents.esm.js +0 -93
  63. package/build/lib/styledComponents.esm.js.map +0 -1
  64. package/build/lib/styledComponents.js +0 -102
  65. package/build/lib/styledComponents.js.map +0 -1
  66. package/build/lib/styledComponents.mjs +0 -93
  67. package/build/lib/styledComponents.mjs.map +0 -1
  68. package/build/lib/theme.d.ts +0 -36
  69. package/build/lib/theme.esm.js +0 -32
  70. package/build/lib/theme.esm.js.map +0 -1
  71. package/build/lib/theme.js +0 -55
  72. package/build/lib/theme.js.map +0 -1
  73. package/build/lib/theme.mjs +0 -32
  74. package/build/lib/theme.mjs.map +0 -1
  75. package/build/lib/useLocalStorage.d.ts +0 -1
  76. package/build/lib/useLocalStorage.esm.js +0 -40
  77. package/build/lib/useLocalStorage.esm.js.map +0 -1
  78. package/build/lib/useLocalStorage.js +0 -63
  79. package/build/lib/useLocalStorage.js.map +0 -1
  80. package/build/lib/useLocalStorage.mjs +0 -40
  81. package/build/lib/useLocalStorage.mjs.map +0 -1
  82. package/build/lib/useMediaQuery.d.ts +0 -1
  83. package/build/lib/useMediaQuery.esm.js +0 -36
  84. package/build/lib/useMediaQuery.esm.js.map +0 -1
  85. package/build/lib/useMediaQuery.js +0 -59
  86. package/build/lib/useMediaQuery.js.map +0 -1
  87. package/build/lib/useMediaQuery.mjs +0 -36
  88. package/build/lib/useMediaQuery.mjs.map +0 -1
  89. package/build/lib/utils.d.ts +0 -79
  90. package/build/lib/utils.esm.js +0 -184
  91. package/build/lib/utils.esm.js.map +0 -1
  92. package/build/lib/utils.js +0 -218
  93. package/build/lib/utils.js.map +0 -1
  94. package/build/lib/utils.mjs +0 -184
  95. package/build/lib/utils.mjs.map +0 -1
  96. package/build/umd/index.development.js +0 -3099
  97. package/build/umd/index.development.js.map +0 -1
  98. package/build/umd/index.production.js +0 -2
  99. package/build/umd/index.production.js.map +0 -1
  100. package/src/Explorer.tsx +0 -385
  101. package/src/Logo.tsx +0 -32
  102. package/src/__tests__/Explorer.test.tsx +0 -150
  103. package/src/noop.ts +0 -7
  104. package/src/screenreader.tsx +0 -16
  105. package/src/styledComponents.ts +0 -108
  106. package/src/theme.tsx +0 -33
  107. package/src/useLocalStorage.ts +0 -52
  108. package/src/useMediaQuery.ts +0 -34
  109. package/src/utils.ts +0 -319
@@ -1,795 +1,61 @@
1
+ 'use client';
1
2
  'use strict';
2
3
 
3
- var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
4
4
  var React = require('react');
5
5
  var reactQuery = require('@tanstack/react-query');
6
- var matchSorterUtils = require('@tanstack/match-sorter-utils');
7
- var useLocalStorage = require('./useLocalStorage.js');
8
- var utils = require('./utils.js');
9
- var styledComponents = require('./styledComponents.js');
10
- var screenreader = require('./screenreader.js');
11
- var theme = require('./theme.js');
12
- var Explorer = require('./Explorer.js');
13
- var Logo = require('./Logo.js');
6
+ var queryDevtools = require('@tanstack/query-devtools');
14
7
 
15
- function _interopNamespaceDefault(e) {
16
- var n = Object.create(null);
17
- if (e) {
18
- Object.keys(e).forEach(function (k) {
19
- if (k !== 'default') {
20
- var d = Object.getOwnPropertyDescriptor(e, k);
21
- Object.defineProperty(n, k, d.get ? d : {
22
- enumerable: true,
23
- get: function () { return e[k]; }
24
- });
25
- }
26
- });
27
- }
28
- n.default = e;
29
- return Object.freeze(n);
30
- }
31
-
32
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
33
-
34
- function ReactQueryDevtools({
35
- initialIsOpen,
36
- panelProps = {},
37
- closeButtonProps = {},
38
- toggleButtonProps = {},
39
- position = 'bottom-left',
40
- containerElement: Container = 'aside',
41
- queryClient,
42
- styleNonce,
43
- panelPosition: initialPanelPosition = 'bottom'
44
- }) {
45
- const rootRef = React__namespace.useRef(null);
46
- const panelRef = React__namespace.useRef(null);
47
- const [isOpen, setIsOpen] = useLocalStorage.default('reactQueryDevtoolsOpen', initialIsOpen);
48
- const [devtoolsHeight, setDevtoolsHeight] = useLocalStorage.default('reactQueryDevtoolsHeight', utils.defaultPanelSize);
49
- const [devtoolsWidth, setDevtoolsWidth] = useLocalStorage.default('reactQueryDevtoolsWidth', utils.defaultPanelSize);
50
- const [panelPosition = 'bottom', setPanelPosition] = useLocalStorage.default('reactQueryDevtoolsPanelPosition', initialPanelPosition);
51
- const [isResolvedOpen, setIsResolvedOpen] = React__namespace.useState(false);
52
- const [isResizing, setIsResizing] = React__namespace.useState(false);
53
- const isMounted = utils.useIsMounted();
54
- const handleDragStart = (panelElement, startEvent) => {
55
- if (!panelElement) return;
56
- if (startEvent.button !== 0) return; // Only allow left click for drag
57
- const isVertical = utils.isVerticalSide(panelPosition);
58
- setIsResizing(true);
59
- const {
60
- height,
61
- width
62
- } = panelElement.getBoundingClientRect();
63
- const startX = startEvent.clientX;
64
- const startY = startEvent.clientY;
65
- let newSize = 0;
66
- const run = moveEvent => {
67
- // prevent mouse selecting stuff with mouse drag
68
- moveEvent.preventDefault();
69
-
70
- // calculate the correct size based on mouse position and current panel position
71
- // hint: it is different formula for the opposite sides
72
- if (isVertical) {
73
- newSize = width + (panelPosition === 'right' ? startX - moveEvent.clientX : moveEvent.clientX - startX);
74
- setDevtoolsWidth(newSize);
75
- } else {
76
- newSize = height + (panelPosition === 'bottom' ? startY - moveEvent.clientY : moveEvent.clientY - startY);
77
- setDevtoolsHeight(newSize);
78
- }
79
- if (newSize < utils.minPanelSize) {
80
- setIsOpen(false);
81
- } else {
82
- setIsOpen(true);
83
- }
84
- };
85
- const unsub = () => {
86
- if (isResizing) {
87
- setIsResizing(false);
88
- }
89
- document.removeEventListener('mousemove', run, false);
90
- document.removeEventListener('mouseUp', unsub, false);
91
- };
92
- document.addEventListener('mousemove', run, false);
93
- document.addEventListener('mouseup', unsub, false);
94
- };
95
- React__namespace.useEffect(() => {
96
- setIsResolvedOpen(isOpen ?? false);
97
- }, [isOpen, isResolvedOpen, setIsResolvedOpen]);
98
-
99
- // Toggle panel visibility before/after transition (depending on direction).
100
- // Prevents focusing in a closed panel.
101
- React__namespace.useEffect(() => {
102
- const ref = panelRef.current;
103
- if (ref) {
104
- const handlePanelTransitionStart = () => {
105
- if (isResolvedOpen) {
106
- ref.style.visibility = 'visible';
107
- }
108
- };
109
- const handlePanelTransitionEnd = () => {
110
- if (!isResolvedOpen) {
111
- ref.style.visibility = 'hidden';
112
- }
113
- };
114
- ref.addEventListener('transitionstart', handlePanelTransitionStart);
115
- ref.addEventListener('transitionend', handlePanelTransitionEnd);
116
- return () => {
117
- ref.removeEventListener('transitionstart', handlePanelTransitionStart);
118
- ref.removeEventListener('transitionend', handlePanelTransitionEnd);
119
- };
120
- }
121
- return;
122
- }, [isResolvedOpen]);
123
- React__namespace.useEffect(() => {
124
- if (isResolvedOpen && rootRef.current?.parentElement) {
125
- const {
126
- parentElement
127
- } = rootRef.current;
128
- const styleProp = utils.getSidedProp('padding', panelPosition);
129
- const isVertical = utils.isVerticalSide(panelPosition);
130
- const previousPaddings = (({
131
- padding,
132
- paddingTop,
133
- paddingBottom,
134
- paddingLeft,
135
- paddingRight
136
- }) => ({
137
- padding,
138
- paddingTop,
139
- paddingBottom,
140
- paddingLeft,
141
- paddingRight
142
- }))(parentElement.style);
143
- const run = () => {
144
- // reset the padding
145
- parentElement.style.padding = '0px';
146
- parentElement.style.paddingTop = '0px';
147
- parentElement.style.paddingBottom = '0px';
148
- parentElement.style.paddingLeft = '0px';
149
- parentElement.style.paddingRight = '0px';
150
- // set the new padding based on the new panel position
151
-
152
- parentElement.style[styleProp] = `${isVertical ? devtoolsWidth : devtoolsHeight}px`;
153
- };
154
- run();
155
- if (typeof window !== 'undefined') {
156
- window.addEventListener('resize', run);
157
- return () => {
158
- window.removeEventListener('resize', run);
159
- Object.entries(previousPaddings).forEach(([property, previousValue]) => {
160
- parentElement.style[property] = previousValue;
161
- });
162
- };
163
- }
164
- }
165
- return;
166
- }, [isResolvedOpen, panelPosition, devtoolsHeight, devtoolsWidth]);
167
- const {
168
- style: panelStyle = {},
169
- ...otherPanelProps
170
- } = panelProps;
171
- const {
172
- style: toggleButtonStyle = {},
173
- onClick: onToggleClick,
174
- ...otherToggleButtonProps
175
- } = toggleButtonProps;
176
-
177
- // get computed style based on panel position
178
- const style = utils.getSidePanelStyle({
179
- position: panelPosition,
180
- devtoolsTheme: theme.defaultTheme,
181
- isOpen: isResolvedOpen,
182
- height: devtoolsHeight,
183
- width: devtoolsWidth,
184
- isResizing,
185
- panelStyle
186
- });
187
-
188
- // Do not render on the server
189
- if (!isMounted()) return null;
190
- return /*#__PURE__*/React__namespace.createElement(Container, {
191
- ref: rootRef,
192
- className: "ReactQueryDevtools",
193
- "aria-label": "React Query Devtools"
194
- }, /*#__PURE__*/React__namespace.createElement(theme.ThemeProvider, {
195
- theme: theme.defaultTheme
196
- }, /*#__PURE__*/React__namespace.createElement(ReactQueryDevtoolsPanel, _rollupPluginBabelHelpers.extends({
197
- ref: panelRef,
198
- queryClient: queryClient,
199
- styleNonce: styleNonce,
200
- position: panelPosition,
201
- onPositionChange: setPanelPosition,
202
- showCloseButton: true,
203
- closeButtonProps: closeButtonProps
204
- }, otherPanelProps, {
205
- style: style,
206
- isOpen: isResolvedOpen,
207
- setIsOpen: setIsOpen,
208
- onDragStart: e => handleDragStart(panelRef.current, e)
209
- }))), !isResolvedOpen ? /*#__PURE__*/React__namespace.createElement("button", _rollupPluginBabelHelpers.extends({
210
- type: "button"
211
- }, otherToggleButtonProps, {
212
- "aria-label": "Open React Query Devtools",
213
- "aria-controls": "ReactQueryDevtoolsPanel",
214
- "aria-haspopup": "true",
215
- "aria-expanded": "false",
216
- onClick: e => {
217
- setIsOpen(true);
218
- onToggleClick?.(e);
219
- },
220
- style: {
221
- background: 'none',
222
- border: 0,
223
- padding: 0,
224
- position: 'fixed',
225
- zIndex: 99999,
226
- display: 'inline-flex',
227
- fontSize: '1.5em',
228
- margin: '.5em',
229
- cursor: 'pointer',
230
- width: 'fit-content',
231
- ...(position === 'top-right' ? {
232
- top: '0',
233
- right: '0'
234
- } : position === 'top-left' ? {
235
- top: '0',
236
- left: '0'
237
- } : position === 'bottom-right' ? {
238
- bottom: '0',
239
- right: '0'
240
- } : {
241
- bottom: '0',
242
- left: '0'
243
- }),
244
- ...toggleButtonStyle
245
- }
246
- }), /*#__PURE__*/React__namespace.createElement(Logo.default, {
247
- "aria-hidden": true
248
- }), /*#__PURE__*/React__namespace.createElement(screenreader.default, {
249
- text: "Open React Query Devtools"
250
- })) : null);
251
- }
252
- const useSubscribeToQueryCache = (queryCache, getSnapshot, skip = false) => {
253
- return React__namespace.useSyncExternalStore(React__namespace.useCallback(onStoreChange => {
254
- if (!skip) return queryCache.subscribe(reactQuery.notifyManager.batchCalls(onStoreChange));
255
- return () => {
256
- return;
257
- };
258
- }, [queryCache, skip]), getSnapshot, getSnapshot);
259
- };
260
- const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(function ReactQueryDevtoolsPanel(props, ref) {
8
+ function ReactQueryDevtools(props) {
9
+ const queryClient = reactQuery.useQueryClient();
10
+ const client = props.client || queryClient;
11
+ const ref = React.useRef(null);
261
12
  const {
262
- isOpen = true,
263
- styleNonce,
264
- setIsOpen,
265
- queryClient,
266
- onDragStart,
267
- onPositionChange,
268
- showCloseButton,
13
+ buttonPosition,
269
14
  position,
270
- closeButtonProps = {},
271
- ...panelProps
15
+ initialIsOpen,
16
+ errorTypes
272
17
  } = props;
273
- const {
274
- onClick: onCloseClick,
275
- ...otherCloseButtonProps
276
- } = closeButtonProps;
277
- const client = reactQuery.useQueryClient(queryClient);
278
- const queryCache = client.getQueryCache();
279
- const [sort, setSort] = useLocalStorage.default('reactQueryDevtoolsSortFn', Object.keys(utils.sortFns)[0]);
280
- const [filter, setFilter] = useLocalStorage.default('reactQueryDevtoolsFilter', '');
281
- const [baseSort, setBaseSort] = useLocalStorage.default('reactQueryDevtoolsBaseSort', 1);
282
- const sortFn = React__namespace.useMemo(() => utils.sortFns[sort], [sort]);
283
- const queriesCount = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().length, !isOpen);
284
- const [activeQueryHash, setActiveQueryHash] = useLocalStorage.default('reactQueryDevtoolsActiveQueryHash', '');
285
- const queries = React__namespace.useMemo(() => {
286
- const unsortedQueries = queryCache.getAll();
287
- if (queriesCount === 0) {
288
- return [];
289
- }
290
- const filtered = filter ? unsortedQueries.filter(item => matchSorterUtils.rankItem(item.queryHash, filter).passed) : [...unsortedQueries];
291
- const sorted = sortFn ? filtered.sort((a, b) => sortFn(a, b) * baseSort) : filtered;
292
- return sorted;
293
- }, [baseSort, sortFn, filter, queriesCount, queryCache]);
294
- const [isMockOffline, setMockOffline] = React__namespace.useState(false);
295
- return /*#__PURE__*/React__namespace.createElement(theme.ThemeProvider, {
296
- theme: theme.defaultTheme
297
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Panel, _rollupPluginBabelHelpers.extends({
298
- ref: ref,
299
- className: "ReactQueryDevtoolsPanel",
300
- "aria-label": "React Query Devtools Panel",
301
- id: "ReactQueryDevtoolsPanel"
302
- }, panelProps, {
303
- style: {
304
- height: utils.defaultPanelSize,
305
- position: 'relative',
306
- ...panelProps.style
307
- }
308
- }), /*#__PURE__*/React__namespace.createElement("style", {
309
- nonce: styleNonce,
310
- dangerouslySetInnerHTML: {
311
- __html: `
312
- .ReactQueryDevtoolsPanel * {
313
- scrollbar-color: ${theme.defaultTheme.backgroundAlt} ${theme.defaultTheme.gray};
314
- }
315
-
316
- .ReactQueryDevtoolsPanel *::-webkit-scrollbar, .ReactQueryDevtoolsPanel scrollbar {
317
- width: 1em;
318
- height: 1em;
319
- }
320
-
321
- .ReactQueryDevtoolsPanel *::-webkit-scrollbar-track, .ReactQueryDevtoolsPanel scrollbar-track {
322
- background: ${theme.defaultTheme.backgroundAlt};
323
- }
324
-
325
- .ReactQueryDevtoolsPanel *::-webkit-scrollbar-thumb, .ReactQueryDevtoolsPanel scrollbar-thumb {
326
- background: ${theme.defaultTheme.gray};
327
- border-radius: .5em;
328
- border: 3px solid ${theme.defaultTheme.backgroundAlt};
329
- }
330
- `
331
- }
332
- }), /*#__PURE__*/React__namespace.createElement("div", {
333
- style: utils.getResizeHandleStyle(position),
334
- onMouseDown: onDragStart
335
- }), isOpen && /*#__PURE__*/React__namespace.createElement("div", {
336
- style: {
337
- flex: '1 1 500px',
338
- minHeight: '40%',
339
- maxHeight: '100%',
340
- overflow: 'auto',
341
- borderRight: `1px solid ${theme.defaultTheme.grayAlt}`,
342
- display: 'flex',
343
- flexDirection: 'column'
344
- }
345
- }, /*#__PURE__*/React__namespace.createElement("div", {
346
- style: {
347
- padding: '.5em',
348
- background: theme.defaultTheme.backgroundAlt,
349
- display: 'flex',
350
- justifyContent: 'space-between',
351
- alignItems: 'center'
352
- }
353
- }, /*#__PURE__*/React__namespace.createElement("button", {
354
- type: "button",
355
- "aria-label": "Close React Query Devtools",
356
- "aria-controls": "ReactQueryDevtoolsPanel",
357
- "aria-haspopup": "true",
358
- "aria-expanded": "true",
359
- onClick: () => setIsOpen(false),
360
- style: {
361
- display: 'inline-flex',
362
- background: 'none',
363
- border: 0,
364
- padding: 0,
365
- marginRight: '.5em',
366
- cursor: 'pointer'
367
- }
368
- }, /*#__PURE__*/React__namespace.createElement(Logo.default, {
369
- "aria-hidden": true
370
- }), /*#__PURE__*/React__namespace.createElement(screenreader.default, {
371
- text: "Close React Query Devtools"
372
- })), /*#__PURE__*/React__namespace.createElement("div", {
373
- style: {
374
- display: 'flex',
375
- flexDirection: 'column'
376
- }
377
- }, /*#__PURE__*/React__namespace.createElement("div", {
378
- style: {
379
- display: 'flex',
380
- justifyContent: 'space-between',
381
- alignItems: 'center',
382
- marginBottom: '.5em'
383
- }
384
- }, /*#__PURE__*/React__namespace.createElement(QueryStatusCount, {
385
- queryCache: queryCache
386
- }), position && onPositionChange ? /*#__PURE__*/React__namespace.createElement(styledComponents.Select, {
387
- "aria-label": "Panel position",
388
- value: position,
389
- style: {
390
- marginInlineStart: '.5em'
391
- },
392
- onChange: e => onPositionChange(e.target.value)
393
- }, /*#__PURE__*/React__namespace.createElement("option", {
394
- value: "left"
395
- }, "Left"), /*#__PURE__*/React__namespace.createElement("option", {
396
- value: "right"
397
- }, "Right"), /*#__PURE__*/React__namespace.createElement("option", {
398
- value: "top"
399
- }, "Top"), /*#__PURE__*/React__namespace.createElement("option", {
400
- value: "bottom"
401
- }, "Bottom")) : null), /*#__PURE__*/React__namespace.createElement("div", {
402
- style: {
403
- display: 'flex',
404
- alignItems: 'center'
405
- }
406
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Input, {
407
- placeholder: "Filter",
408
- "aria-label": "Filter by queryhash",
409
- value: filter ?? '',
410
- onChange: e => setFilter(e.target.value),
411
- onKeyDown: e => {
412
- if (e.key === 'Escape') setFilter('');
413
- },
414
- style: {
415
- flex: '1',
416
- marginRight: '.5em',
417
- width: '100%'
418
- }
419
- }), /*#__PURE__*/React__namespace.createElement(styledComponents.Select, {
420
- "aria-label": "Sort queries",
421
- value: sort,
422
- onChange: e => setSort(e.target.value),
423
- style: {
424
- flex: '1',
425
- minWidth: 75,
426
- marginRight: '.5em'
427
- }
428
- }, Object.keys(utils.sortFns).map(key => /*#__PURE__*/React__namespace.createElement("option", {
429
- key: key,
430
- value: key
431
- }, "Sort by ", key))), /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
432
- type: "button",
433
- onClick: () => setBaseSort(old => old * -1),
434
- style: {
435
- padding: '.3em .4em',
436
- marginRight: '.5em'
437
- }
438
- }, baseSort === 1 ? '⬆ Asc' : '⬇ Desc'), /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
439
- type: "button",
440
- onClick: () => {
441
- if (isMockOffline) {
442
- reactQuery.onlineManager.setOnline(undefined);
443
- setMockOffline(false);
444
- window.dispatchEvent(new Event('online'));
445
- } else {
446
- reactQuery.onlineManager.setOnline(false);
447
- setMockOffline(true);
448
- }
449
- },
450
- "aria-label": isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
451
- title: isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
452
- style: {
453
- padding: '0',
454
- height: '2em'
455
- }
456
- }, /*#__PURE__*/React__namespace.createElement("svg", {
457
- xmlns: "http://www.w3.org/2000/svg",
458
- width: "2em",
459
- height: "2em",
460
- viewBox: "0 0 24 24",
461
- stroke: isMockOffline ? theme.defaultTheme.danger : 'currentColor',
462
- fill: "none"
463
- }, isMockOffline ? /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("path", {
464
- stroke: "none",
465
- d: "M0 0h24v24H0z",
466
- fill: "none"
467
- }), /*#__PURE__*/React__namespace.createElement("line", {
468
- x1: "12",
469
- y1: "18",
470
- x2: "12.01",
471
- y2: "18"
472
- }), /*#__PURE__*/React__namespace.createElement("path", {
473
- d: "M9.172 15.172a4 4 0 0 1 5.656 0"
474
- }), /*#__PURE__*/React__namespace.createElement("path", {
475
- d: "M6.343 12.343a7.963 7.963 0 0 1 3.864 -2.14m4.163 .155a7.965 7.965 0 0 1 3.287 2"
476
- }), /*#__PURE__*/React__namespace.createElement("path", {
477
- d: "M3.515 9.515a12 12 0 0 1 3.544 -2.455m3.101 -.92a12 12 0 0 1 10.325 3.374"
478
- }), /*#__PURE__*/React__namespace.createElement("line", {
479
- x1: "3",
480
- y1: "3",
481
- x2: "21",
482
- y2: "21"
483
- })) : /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("path", {
484
- stroke: "none",
485
- d: "M0 0h24v24H0z",
486
- fill: "none"
487
- }), /*#__PURE__*/React__namespace.createElement("line", {
488
- x1: "12",
489
- y1: "18",
490
- x2: "12.01",
491
- y2: "18"
492
- }), /*#__PURE__*/React__namespace.createElement("path", {
493
- d: "M9.172 15.172a4 4 0 0 1 5.656 0"
494
- }), /*#__PURE__*/React__namespace.createElement("path", {
495
- d: "M6.343 12.343a8 8 0 0 1 11.314 0"
496
- }), /*#__PURE__*/React__namespace.createElement("path", {
497
- d: "M3.515 9.515c4.686 -4.687 12.284 -4.687 17 0"
498
- }))), /*#__PURE__*/React__namespace.createElement(screenreader.default, {
499
- text: isMockOffline ? 'Restore offline mock' : 'Mock offline behavior'
500
- }))))), /*#__PURE__*/React__namespace.createElement("div", {
501
- style: {
502
- overflowY: 'auto',
503
- flex: '1'
504
- }
505
- }, queries.map(query => {
506
- return /*#__PURE__*/React__namespace.createElement(QueryRow, {
507
- queryKey: query.queryKey,
508
- activeQueryHash: activeQueryHash,
509
- setActiveQueryHash: setActiveQueryHash,
510
- key: query.queryHash,
511
- queryCache: queryCache
512
- });
513
- }))), activeQueryHash && isOpen ? /*#__PURE__*/React__namespace.createElement(ActiveQuery, {
514
- activeQueryHash: activeQueryHash,
515
- queryCache: queryCache,
516
- queryClient: client
517
- }) : null, showCloseButton ? /*#__PURE__*/React__namespace.createElement(styledComponents.Button, _rollupPluginBabelHelpers.extends({
518
- type: "button",
519
- "aria-controls": "ReactQueryDevtoolsPanel",
520
- "aria-haspopup": "true",
521
- "aria-expanded": "true"
522
- }, otherCloseButtonProps, {
523
- style: {
524
- position: 'absolute',
525
- zIndex: 99999,
526
- margin: '.5em',
527
- bottom: 0,
528
- left: 0,
529
- ...otherCloseButtonProps.style
530
- },
531
- onClick: e => {
532
- setIsOpen(false);
533
- onCloseClick?.(e);
534
- }
535
- }), "Close") : null));
536
- });
537
- const ActiveQuery = ({
538
- queryCache,
539
- activeQueryHash,
540
- queryClient
541
- }) => {
542
- const activeQuery = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash));
543
- const activeQueryState = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.state);
544
- const isStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.isStale()) ?? false;
545
- const observerCount = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.getObserversCount()) ?? 0;
546
- const handleRefetch = () => {
547
- const promise = activeQuery?.fetch();
548
- promise?.catch(noop);
549
- };
550
- if (!activeQuery || !activeQueryState) {
551
- return null;
552
- }
553
- return /*#__PURE__*/React__namespace.createElement(styledComponents.ActiveQueryPanel, null, /*#__PURE__*/React__namespace.createElement("div", {
554
- style: {
555
- padding: '.5em',
556
- background: theme.defaultTheme.backgroundAlt,
557
- position: 'sticky',
558
- top: 0,
559
- zIndex: 1
560
- }
561
- }, "Query Details"), /*#__PURE__*/React__namespace.createElement("div", {
562
- style: {
563
- padding: '.5em'
564
- }
565
- }, /*#__PURE__*/React__namespace.createElement("div", {
566
- style: {
567
- marginBottom: '.5em',
568
- display: 'flex',
569
- alignItems: 'flex-start',
570
- justifyContent: 'space-between'
571
- }
572
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Code, {
573
- style: {
574
- lineHeight: '1.8em'
575
- }
576
- }, /*#__PURE__*/React__namespace.createElement("pre", {
577
- style: {
578
- margin: 0,
579
- padding: 0,
580
- overflow: 'auto'
581
- }
582
- }, utils.displayValue(activeQuery.queryKey, true))), /*#__PURE__*/React__namespace.createElement("span", {
583
- style: {
584
- padding: '0.3em .6em',
585
- borderRadius: '0.4em',
586
- fontWeight: 'bold',
587
- textShadow: '0 2px 10px black',
588
- background: utils.getQueryStatusColor({
589
- queryState: activeQueryState,
590
- isStale: isStale,
591
- observerCount: observerCount,
592
- theme: theme.defaultTheme
593
- }),
594
- flexShrink: 0
595
- }
596
- }, utils.getQueryStatusLabel(activeQuery))), /*#__PURE__*/React__namespace.createElement("div", {
597
- style: {
598
- marginBottom: '.5em',
599
- display: 'flex',
600
- alignItems: 'center',
601
- justifyContent: 'space-between'
602
- }
603
- }, "Observers: ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, observerCount)), /*#__PURE__*/React__namespace.createElement("div", {
604
- style: {
605
- display: 'flex',
606
- alignItems: 'center',
607
- justifyContent: 'space-between'
608
- }
609
- }, "Last Updated:", ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, new Date(activeQueryState.dataUpdatedAt).toLocaleTimeString()))), /*#__PURE__*/React__namespace.createElement("div", {
610
- style: {
611
- background: theme.defaultTheme.backgroundAlt,
612
- padding: '.5em',
613
- position: 'sticky',
614
- top: 0,
615
- zIndex: 1
616
- }
617
- }, "Actions"), /*#__PURE__*/React__namespace.createElement("div", {
618
- style: {
619
- padding: '0.5em'
620
- }
621
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
622
- type: "button",
623
- onClick: handleRefetch,
624
- disabled: activeQueryState.fetchStatus === 'fetching',
625
- style: {
626
- background: theme.defaultTheme.active
627
- }
628
- }, "Refetch"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
629
- type: "button",
630
- onClick: () => queryClient.invalidateQueries(activeQuery),
631
- style: {
632
- background: theme.defaultTheme.warning,
633
- color: theme.defaultTheme.inputTextColor
634
- }
635
- }, "Invalidate"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
636
- type: "button",
637
- onClick: () => queryClient.resetQueries(activeQuery),
638
- style: {
639
- background: theme.defaultTheme.gray
640
- }
641
- }, "Reset"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
642
- type: "button",
643
- onClick: () => queryClient.removeQueries(activeQuery),
644
- style: {
645
- background: theme.defaultTheme.danger
646
- }
647
- }, "Remove")), /*#__PURE__*/React__namespace.createElement("div", {
648
- style: {
649
- background: theme.defaultTheme.backgroundAlt,
650
- padding: '.5em',
651
- position: 'sticky',
652
- top: 0,
653
- zIndex: 1
654
- }
655
- }, "Data Explorer"), /*#__PURE__*/React__namespace.createElement("div", {
656
- style: {
657
- padding: '.5em'
658
- }
659
- }, /*#__PURE__*/React__namespace.createElement(Explorer.default, {
660
- label: "Data",
661
- value: activeQueryState.data,
662
- defaultExpanded: {},
663
- copyable: true
664
- })), /*#__PURE__*/React__namespace.createElement("div", {
665
- style: {
666
- background: theme.defaultTheme.backgroundAlt,
667
- padding: '.5em',
668
- position: 'sticky',
669
- top: 0,
670
- zIndex: 1
671
- }
672
- }, "Query Explorer"), /*#__PURE__*/React__namespace.createElement("div", {
673
- style: {
674
- padding: '.5em'
675
- }
676
- }, /*#__PURE__*/React__namespace.createElement(Explorer.default, {
677
- label: "Query",
678
- value: activeQuery,
679
- defaultExpanded: {
680
- queryKey: true
681
- }
682
- })));
683
- };
684
- const QueryStatusCount = ({
685
- queryCache
686
- }) => {
687
- const hasFresh = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'fresh').length);
688
- const hasFetching = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'fetching').length);
689
- const hasPaused = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'paused').length);
690
- const hasStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'stale').length);
691
- const hasInactive = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'inactive').length);
692
- return /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKeys, null, /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
693
- style: {
694
- background: theme.defaultTheme.success,
695
- opacity: hasFresh ? 1 : 0.3
696
- }
697
- }, "fresh ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasFresh, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
698
- style: {
699
- background: theme.defaultTheme.active,
700
- opacity: hasFetching ? 1 : 0.3
701
- }
702
- }, "fetching ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasFetching, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
703
- style: {
704
- background: theme.defaultTheme.paused,
705
- opacity: hasPaused ? 1 : 0.3
706
- }
707
- }, "paused ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasPaused, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
708
- style: {
709
- background: theme.defaultTheme.warning,
710
- color: 'black',
711
- textShadow: '0',
712
- opacity: hasStale ? 1 : 0.3
713
- }
714
- }, "stale ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasStale, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
715
- style: {
716
- background: theme.defaultTheme.gray,
717
- opacity: hasInactive ? 1 : 0.3
718
- }
719
- }, "inactive ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasInactive, ")")));
720
- };
721
- const QueryRow = /*#__PURE__*/React__namespace.memo(({
722
- queryKey,
723
- setActiveQueryHash,
724
- activeQueryHash,
725
- queryCache
726
- }) => {
727
- const queryHash = useSubscribeToQueryCache(queryCache, () => queryCache.find({
728
- queryKey
729
- })?.queryHash) ?? '';
730
- const queryState = useSubscribeToQueryCache(queryCache, () => queryCache.find({
731
- queryKey
732
- })?.state);
733
- const isStale = useSubscribeToQueryCache(queryCache, () => queryCache.find({
734
- queryKey
735
- })?.isStale()) ?? false;
736
- const isDisabled = useSubscribeToQueryCache(queryCache, () => queryCache.find({
737
- queryKey
738
- })?.isDisabled()) ?? false;
739
- const observerCount = useSubscribeToQueryCache(queryCache, () => queryCache.find({
740
- queryKey
741
- })?.getObserversCount()) ?? 0;
742
- if (!queryState) {
743
- return null;
744
- }
745
- return /*#__PURE__*/React__namespace.createElement("div", {
746
- role: "button",
747
- "aria-label": `Open query details for ${queryHash}`,
748
- onClick: () => setActiveQueryHash(activeQueryHash === queryHash ? '' : queryHash),
749
- style: {
750
- display: 'flex',
751
- borderBottom: `solid 1px ${theme.defaultTheme.grayAlt}`,
752
- cursor: 'pointer',
753
- background: queryHash === activeQueryHash ? 'rgba(255,255,255,.1)' : undefined
754
- }
755
- }, /*#__PURE__*/React__namespace.createElement("div", {
756
- style: {
757
- flex: '0 0 auto',
758
- width: '2em',
759
- height: '2em',
760
- background: utils.getQueryStatusColor({
761
- queryState,
762
- isStale,
763
- observerCount,
764
- theme: theme.defaultTheme
765
- }),
766
- display: 'flex',
767
- alignItems: 'center',
768
- justifyContent: 'center',
769
- fontWeight: 'bold',
770
- textShadow: isStale ? '0' : '0 0 10px black',
771
- color: isStale ? 'black' : 'white'
772
- }
773
- }, observerCount), isDisabled ? /*#__PURE__*/React__namespace.createElement("div", {
774
- style: {
775
- flex: '0 0 auto',
776
- height: '2em',
777
- background: theme.defaultTheme.gray,
778
- display: 'flex',
779
- alignItems: 'center',
780
- fontWeight: 'bold',
781
- padding: '0 0.5em'
782
- }
783
- }, "disabled") : null, /*#__PURE__*/React__namespace.createElement(styledComponents.Code, {
784
- style: {
785
- padding: '.5em'
18
+ const [devtools] = React.useState(new queryDevtools.TanstackQueryDevtools({
19
+ client: client,
20
+ queryFlavor: 'React Query',
21
+ version: '5',
22
+ onlineManager: reactQuery.onlineManager,
23
+ buttonPosition,
24
+ position,
25
+ initialIsOpen,
26
+ errorTypes
27
+ }));
28
+ React.useEffect(() => {
29
+ devtools.setClient(client);
30
+ }, [client, devtools]);
31
+ React.useEffect(() => {
32
+ if (buttonPosition) {
33
+ devtools.setButtonPosition(buttonPosition);
34
+ }
35
+ }, [buttonPosition, devtools]);
36
+ React.useEffect(() => {
37
+ if (position) {
38
+ devtools.setPosition(position);
39
+ }
40
+ }, [position, devtools]);
41
+ React.useEffect(() => {
42
+ devtools.setInitialIsOpen(initialIsOpen || false);
43
+ }, [initialIsOpen, devtools]);
44
+ React.useEffect(() => {
45
+ devtools.setErrorTypes(errorTypes || []);
46
+ }, [errorTypes, devtools]);
47
+ React.useEffect(() => {
48
+ if (ref.current) {
49
+ devtools.mount(ref.current);
786
50
  }
787
- }, `${queryHash}`));
788
- });
789
-
790
- // eslint-disable-next-line @typescript-eslint/no-empty-function
791
- function noop() {}
51
+ return () => {
52
+ devtools.unmount();
53
+ };
54
+ }, [devtools]);
55
+ return /*#__PURE__*/React.createElement("div", {
56
+ ref: ref
57
+ });
58
+ }
792
59
 
793
60
  exports.ReactQueryDevtools = ReactQueryDevtools;
794
- exports.ReactQueryDevtoolsPanel = ReactQueryDevtoolsPanel;
795
61
  //# sourceMappingURL=devtools.js.map