@tanstack/react-query-devtools 4.0.0

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