@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,818 @@
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 shim = require('use-sync-external-store/shim');
18
+ var reactQuery = require('@tanstack/react-query');
19
+ var index = require('../../../node_modules/@tanstack/match-sorter-utils/build/esm/index.js');
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 shim.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
+ const queriesCount = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().length);
321
+ const [activeQueryHash, setActiveQueryHash] = useLocalStorage["default"]('reactQueryDevtoolsActiveQueryHash', '');
322
+ const queries = React__namespace.useMemo(() => {
323
+ const unsortedQueries = queryCache.getAll();
324
+ const sorted = queriesCount > 0 ? [...unsortedQueries].sort(sortFn) : [];
325
+
326
+ if (sortDesc) {
327
+ sorted.reverse();
328
+ }
329
+
330
+ if (!filter) {
331
+ return sorted;
332
+ }
333
+
334
+ let ranked = sorted.map(item => [item, index.rankItem(item.queryHash, filter)]);
335
+ ranked = ranked.filter(d => d[1].passed);
336
+ ranked = ranked.sort((a, b) => index.compareItems(a[1], b[1]));
337
+ return ranked.map(d => d[0]);
338
+ }, [sortDesc, sortFn, filter, queriesCount, queryCache]);
339
+ const [isMockOffline, setMockOffline] = React__namespace.useState(false);
340
+ return /*#__PURE__*/React__namespace.createElement(theme.ThemeProvider, {
341
+ theme: theme.defaultTheme
342
+ }, /*#__PURE__*/React__namespace.createElement(styledComponents.Panel, _rollupPluginBabelHelpers["extends"]({
343
+ ref: ref,
344
+ className: "ReactQueryDevtoolsPanel",
345
+ "aria-label": "React Query Devtools Panel",
346
+ id: "ReactQueryDevtoolsPanel"
347
+ }, panelProps), /*#__PURE__*/React__namespace.createElement("style", {
348
+ nonce: styleNonce,
349
+ dangerouslySetInnerHTML: {
350
+ __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 "
351
+ }
352
+ }), /*#__PURE__*/React__namespace.createElement("div", {
353
+ style: {
354
+ position: 'absolute',
355
+ left: 0,
356
+ top: 0,
357
+ width: '100%',
358
+ height: '4px',
359
+ marginBottom: '-4px',
360
+ cursor: 'row-resize',
361
+ zIndex: 100000
362
+ },
363
+ onMouseDown: handleDragStart
364
+ }), /*#__PURE__*/React__namespace.createElement("div", {
365
+ style: {
366
+ flex: '1 1 500px',
367
+ minHeight: '40%',
368
+ maxHeight: '100%',
369
+ overflow: 'auto',
370
+ borderRight: "1px solid " + theme.defaultTheme.grayAlt,
371
+ display: isOpen ? 'flex' : 'none',
372
+ flexDirection: 'column'
373
+ }
374
+ }, /*#__PURE__*/React__namespace.createElement("div", {
375
+ style: {
376
+ padding: '.5em',
377
+ background: theme.defaultTheme.backgroundAlt,
378
+ display: 'flex',
379
+ justifyContent: 'space-between',
380
+ alignItems: 'center'
381
+ }
382
+ }, /*#__PURE__*/React__namespace.createElement("button", {
383
+ type: "button",
384
+ "aria-label": "Close React Query Devtools",
385
+ "aria-controls": "ReactQueryDevtoolsPanel",
386
+ "aria-haspopup": "true",
387
+ "aria-expanded": "true",
388
+ onClick: () => setIsOpen(false),
389
+ style: {
390
+ display: 'inline-flex',
391
+ background: 'none',
392
+ border: 0,
393
+ padding: 0,
394
+ marginRight: '.5em',
395
+ cursor: 'pointer'
396
+ }
397
+ }, /*#__PURE__*/React__namespace.createElement(Logo["default"], {
398
+ "aria-hidden": true
399
+ })), /*#__PURE__*/React__namespace.createElement("div", {
400
+ style: {
401
+ display: 'flex',
402
+ flexDirection: 'column'
403
+ }
404
+ }, /*#__PURE__*/React__namespace.createElement(QueryStatusCount, {
405
+ queryCache: queryCache
406
+ }), /*#__PURE__*/React__namespace.createElement("div", {
407
+ style: {
408
+ display: 'flex',
409
+ alignItems: 'center'
410
+ }
411
+ }, /*#__PURE__*/React__namespace.createElement(styledComponents.Input, {
412
+ placeholder: "Filter",
413
+ "aria-label": "Filter by queryhash",
414
+ value: filter != null ? filter : '',
415
+ onChange: e => setFilter(e.target.value),
416
+ onKeyDown: e => {
417
+ if (e.key === 'Escape') setFilter('');
418
+ },
419
+ style: {
420
+ flex: '1',
421
+ marginRight: '.5em',
422
+ width: '100%'
423
+ }
424
+ }), !filter ? /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(styledComponents.Select, {
425
+ "aria-label": "Sort queries",
426
+ value: sort,
427
+ onChange: e => setSort(e.target.value),
428
+ style: {
429
+ flex: '1',
430
+ minWidth: 75,
431
+ marginRight: '.5em'
432
+ }
433
+ }, Object.keys(sortFns).map(key => /*#__PURE__*/React__namespace.createElement("option", {
434
+ key: key,
435
+ value: key
436
+ }, "Sort by ", key))), /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
437
+ type: "button",
438
+ onClick: () => setSortDesc(old => !old),
439
+ style: {
440
+ padding: '.3em .4em',
441
+ marginRight: '.5em'
442
+ }
443
+ }, sortDesc ? '⬇ Desc' : '⬆ Asc'), /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
444
+ type: "button",
445
+ onClick: () => {
446
+ if (isMockOffline) {
447
+ reactQuery.onlineManager.setOnline(undefined);
448
+ setMockOffline(false);
449
+ window.dispatchEvent(new Event('online'));
450
+ } else {
451
+ reactQuery.onlineManager.setOnline(false);
452
+ setMockOffline(true);
453
+ }
454
+ },
455
+ "aria-label": isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
456
+ title: isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
457
+ style: {
458
+ padding: '0',
459
+ height: '2em'
460
+ }
461
+ }, /*#__PURE__*/React__namespace.createElement("svg", {
462
+ xmlns: "http://www.w3.org/2000/svg",
463
+ width: "2em",
464
+ height: "2em",
465
+ viewBox: "0 0 24 24",
466
+ stroke: isMockOffline ? theme.defaultTheme.danger : 'currentColor',
467
+ fill: "none"
468
+ }, isMockOffline ? /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("path", {
469
+ stroke: "none",
470
+ d: "M0 0h24v24H0z",
471
+ fill: "none"
472
+ }), /*#__PURE__*/React__namespace.createElement("line", {
473
+ x1: "12",
474
+ y1: "18",
475
+ x2: "12.01",
476
+ y2: "18"
477
+ }), /*#__PURE__*/React__namespace.createElement("path", {
478
+ d: "M9.172 15.172a4 4 0 0 1 5.656 0"
479
+ }), /*#__PURE__*/React__namespace.createElement("path", {
480
+ 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"
481
+ }), /*#__PURE__*/React__namespace.createElement("path", {
482
+ d: "M3.515 9.515a12 12 0 0 1 3.544 -2.455m3.101 -.92a12 12 0 0 1 10.325 3.374"
483
+ }), /*#__PURE__*/React__namespace.createElement("line", {
484
+ x1: "3",
485
+ y1: "3",
486
+ x2: "21",
487
+ y2: "21"
488
+ })) : /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("path", {
489
+ stroke: "none",
490
+ d: "M0 0h24v24H0z",
491
+ fill: "none"
492
+ }), /*#__PURE__*/React__namespace.createElement("line", {
493
+ x1: "12",
494
+ y1: "18",
495
+ x2: "12.01",
496
+ y2: "18"
497
+ }), /*#__PURE__*/React__namespace.createElement("path", {
498
+ d: "M9.172 15.172a4 4 0 0 1 5.656 0"
499
+ }), /*#__PURE__*/React__namespace.createElement("path", {
500
+ d: "M6.343 12.343a8 8 0 0 1 11.314 0"
501
+ }), /*#__PURE__*/React__namespace.createElement("path", {
502
+ d: "M3.515 9.515c4.686 -4.687 12.284 -4.687 17 0"
503
+ }))))) : null))), /*#__PURE__*/React__namespace.createElement("div", {
504
+ style: {
505
+ overflowY: 'auto',
506
+ flex: '1'
507
+ }
508
+ }, queries.map(query => {
509
+ return /*#__PURE__*/React__namespace.createElement(QueryRow, {
510
+ queryKey: query.queryKey,
511
+ activeQueryHash: activeQueryHash,
512
+ setActiveQueryHash: setActiveQueryHash,
513
+ key: query.queryHash,
514
+ queryCache: queryCache
515
+ });
516
+ }))), activeQueryHash ? /*#__PURE__*/React__namespace.createElement(ActiveQuery, {
517
+ activeQueryHash: activeQueryHash,
518
+ queryCache: queryCache,
519
+ queryClient: queryClient
520
+ }) : null));
521
+ });
522
+
523
+ const ActiveQuery = ({
524
+ queryCache,
525
+ activeQueryHash,
526
+ queryClient
527
+ }) => {
528
+ var _useSubscribeToQueryC, _useSubscribeToQueryC2;
529
+
530
+ const activeQuery = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash));
531
+ const activeQueryState = useSubscribeToQueryCache(queryCache, () => {
532
+ var _queryCache$getAll$fi;
533
+
534
+ return (_queryCache$getAll$fi = queryCache.getAll().find(query => query.queryHash === activeQueryHash)) == null ? void 0 : _queryCache$getAll$fi.state;
535
+ });
536
+ const isStale = (_useSubscribeToQueryC = useSubscribeToQueryCache(queryCache, () => {
537
+ var _queryCache$getAll$fi2;
538
+
539
+ return (_queryCache$getAll$fi2 = queryCache.getAll().find(query => query.queryHash === activeQueryHash)) == null ? void 0 : _queryCache$getAll$fi2.isStale();
540
+ })) != null ? _useSubscribeToQueryC : false;
541
+ const observerCount = (_useSubscribeToQueryC2 = useSubscribeToQueryCache(queryCache, () => {
542
+ var _queryCache$getAll$fi3;
543
+
544
+ return (_queryCache$getAll$fi3 = queryCache.getAll().find(query => query.queryHash === activeQueryHash)) == null ? void 0 : _queryCache$getAll$fi3.getObserversCount();
545
+ })) != null ? _useSubscribeToQueryC2 : 0;
546
+
547
+ const handleRefetch = () => {
548
+ const promise = activeQuery == null ? void 0 : activeQuery.fetch();
549
+ promise == null ? void 0 : promise.catch(noop);
550
+ };
551
+
552
+ if (!activeQuery || !activeQueryState) {
553
+ return null;
554
+ }
555
+
556
+ return /*#__PURE__*/React__namespace.createElement(styledComponents.ActiveQueryPanel, null, /*#__PURE__*/React__namespace.createElement("div", {
557
+ style: {
558
+ padding: '.5em',
559
+ background: theme.defaultTheme.backgroundAlt,
560
+ position: 'sticky',
561
+ top: 0,
562
+ zIndex: 1
563
+ }
564
+ }, "Query Details"), /*#__PURE__*/React__namespace.createElement("div", {
565
+ style: {
566
+ padding: '.5em'
567
+ }
568
+ }, /*#__PURE__*/React__namespace.createElement("div", {
569
+ style: {
570
+ marginBottom: '.5em',
571
+ display: 'flex',
572
+ alignItems: 'stretch',
573
+ justifyContent: 'space-between'
574
+ }
575
+ }, /*#__PURE__*/React__namespace.createElement(styledComponents.Code, {
576
+ style: {
577
+ lineHeight: '1.8em'
578
+ }
579
+ }, /*#__PURE__*/React__namespace.createElement("pre", {
580
+ style: {
581
+ margin: 0,
582
+ padding: 0,
583
+ overflow: 'auto'
584
+ }
585
+ }, JSON.stringify(activeQuery.queryKey, null, 2))), /*#__PURE__*/React__namespace.createElement("span", {
586
+ style: {
587
+ padding: '0.3em .6em',
588
+ borderRadius: '0.4em',
589
+ fontWeight: 'bold',
590
+ textShadow: '0 2px 10px black',
591
+ background: utils.getQueryStatusColor({
592
+ queryState: activeQueryState,
593
+ isStale: isStale,
594
+ observerCount: observerCount,
595
+ theme: theme.defaultTheme
596
+ }),
597
+ flexShrink: 0
598
+ }
599
+ }, utils.getQueryStatusLabel(activeQuery))), /*#__PURE__*/React__namespace.createElement("div", {
600
+ style: {
601
+ marginBottom: '.5em',
602
+ display: 'flex',
603
+ alignItems: 'center',
604
+ justifyContent: 'space-between'
605
+ }
606
+ }, "Observers: ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, observerCount)), /*#__PURE__*/React__namespace.createElement("div", {
607
+ style: {
608
+ display: 'flex',
609
+ alignItems: 'center',
610
+ justifyContent: 'space-between'
611
+ }
612
+ }, "Last Updated:", ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, new Date(activeQueryState.dataUpdatedAt).toLocaleTimeString()))), /*#__PURE__*/React__namespace.createElement("div", {
613
+ style: {
614
+ background: theme.defaultTheme.backgroundAlt,
615
+ padding: '.5em',
616
+ position: 'sticky',
617
+ top: 0,
618
+ zIndex: 1
619
+ }
620
+ }, "Actions"), /*#__PURE__*/React__namespace.createElement("div", {
621
+ style: {
622
+ padding: '0.5em'
623
+ }
624
+ }, /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
625
+ type: "button",
626
+ onClick: handleRefetch,
627
+ disabled: activeQueryState.fetchStatus === 'fetching',
628
+ style: {
629
+ background: theme.defaultTheme.active
630
+ }
631
+ }, "Refetch"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
632
+ type: "button",
633
+ onClick: () => queryClient.invalidateQueries(activeQuery),
634
+ style: {
635
+ background: theme.defaultTheme.warning,
636
+ color: theme.defaultTheme.inputTextColor
637
+ }
638
+ }, "Invalidate"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
639
+ type: "button",
640
+ onClick: () => queryClient.resetQueries(activeQuery),
641
+ style: {
642
+ background: theme.defaultTheme.gray
643
+ }
644
+ }, "Reset"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
645
+ type: "button",
646
+ onClick: () => queryClient.removeQueries(activeQuery),
647
+ style: {
648
+ background: theme.defaultTheme.danger
649
+ }
650
+ }, "Remove")), /*#__PURE__*/React__namespace.createElement("div", {
651
+ style: {
652
+ background: theme.defaultTheme.backgroundAlt,
653
+ padding: '.5em',
654
+ position: 'sticky',
655
+ top: 0,
656
+ zIndex: 1
657
+ }
658
+ }, "Data Explorer"), /*#__PURE__*/React__namespace.createElement("div", {
659
+ style: {
660
+ padding: '.5em'
661
+ }
662
+ }, /*#__PURE__*/React__namespace.createElement(Explorer["default"], {
663
+ label: "Data",
664
+ value: activeQueryState.data,
665
+ defaultExpanded: {}
666
+ })), /*#__PURE__*/React__namespace.createElement("div", {
667
+ style: {
668
+ background: theme.defaultTheme.backgroundAlt,
669
+ padding: '.5em',
670
+ position: 'sticky',
671
+ top: 0,
672
+ zIndex: 1
673
+ }
674
+ }, "Query Explorer"), /*#__PURE__*/React__namespace.createElement("div", {
675
+ style: {
676
+ padding: '.5em'
677
+ }
678
+ }, /*#__PURE__*/React__namespace.createElement(Explorer["default"], {
679
+ label: "Query",
680
+ value: activeQuery,
681
+ defaultExpanded: {
682
+ queryKey: true
683
+ }
684
+ })));
685
+ };
686
+
687
+ const QueryStatusCount = ({
688
+ queryCache
689
+ }) => {
690
+ const hasFresh = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'fresh').length);
691
+ const hasFetching = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'fetching').length);
692
+ const hasPaused = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'paused').length);
693
+ const hasStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'stale').length);
694
+ const hasInactive = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'inactive').length);
695
+ return /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKeys, {
696
+ style: {
697
+ marginBottom: '.5em'
698
+ }
699
+ }, /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
700
+ style: {
701
+ background: theme.defaultTheme.success,
702
+ opacity: hasFresh ? 1 : 0.3
703
+ }
704
+ }, "fresh ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasFresh, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
705
+ style: {
706
+ background: theme.defaultTheme.active,
707
+ opacity: hasFetching ? 1 : 0.3
708
+ }
709
+ }, "fetching ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasFetching, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
710
+ style: {
711
+ background: theme.defaultTheme.paused,
712
+ opacity: hasPaused ? 1 : 0.3
713
+ }
714
+ }, "paused ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasPaused, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
715
+ style: {
716
+ background: theme.defaultTheme.warning,
717
+ color: 'black',
718
+ textShadow: '0',
719
+ opacity: hasStale ? 1 : 0.3
720
+ }
721
+ }, "stale ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasStale, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
722
+ style: {
723
+ background: theme.defaultTheme.gray,
724
+ opacity: hasInactive ? 1 : 0.3
725
+ }
726
+ }, "inactive ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasInactive, ")")));
727
+ };
728
+
729
+ const QueryRow = ({
730
+ queryKey,
731
+ setActiveQueryHash,
732
+ activeQueryHash,
733
+ queryCache
734
+ }) => {
735
+ var _useSubscribeToQueryC3, _useSubscribeToQueryC4, _useSubscribeToQueryC5, _useSubscribeToQueryC6;
736
+
737
+ const queryHash = (_useSubscribeToQueryC3 = useSubscribeToQueryCache(queryCache, () => {
738
+ var _queryCache$find;
739
+
740
+ return (_queryCache$find = queryCache.find(queryKey)) == null ? void 0 : _queryCache$find.queryHash;
741
+ })) != null ? _useSubscribeToQueryC3 : '';
742
+ const queryState = useSubscribeToQueryCache(queryCache, () => {
743
+ var _queryCache$find2;
744
+
745
+ return (_queryCache$find2 = queryCache.find(queryKey)) == null ? void 0 : _queryCache$find2.state;
746
+ });
747
+ const isStale = (_useSubscribeToQueryC4 = useSubscribeToQueryCache(queryCache, () => {
748
+ var _queryCache$find3;
749
+
750
+ return (_queryCache$find3 = queryCache.find(queryKey)) == null ? void 0 : _queryCache$find3.isStale();
751
+ })) != null ? _useSubscribeToQueryC4 : false;
752
+ const isDisabled = (_useSubscribeToQueryC5 = useSubscribeToQueryCache(queryCache, () => {
753
+ var _queryCache$find4;
754
+
755
+ return (_queryCache$find4 = queryCache.find(queryKey)) == null ? void 0 : _queryCache$find4.isDisabled();
756
+ })) != null ? _useSubscribeToQueryC5 : false;
757
+ const observerCount = (_useSubscribeToQueryC6 = useSubscribeToQueryCache(queryCache, () => {
758
+ var _queryCache$find5;
759
+
760
+ return (_queryCache$find5 = queryCache.find(queryKey)) == null ? void 0 : _queryCache$find5.getObserversCount();
761
+ })) != null ? _useSubscribeToQueryC6 : 0;
762
+
763
+ if (!queryState) {
764
+ return null;
765
+ }
766
+
767
+ return /*#__PURE__*/React__namespace.createElement("div", {
768
+ role: "button",
769
+ "aria-label": "Open query details for " + queryHash,
770
+ onClick: () => setActiveQueryHash(activeQueryHash === queryHash ? '' : queryHash),
771
+ style: {
772
+ display: 'flex',
773
+ borderBottom: "solid 1px " + theme.defaultTheme.grayAlt,
774
+ cursor: 'pointer',
775
+ background: queryHash === activeQueryHash ? 'rgba(255,255,255,.1)' : undefined
776
+ }
777
+ }, /*#__PURE__*/React__namespace.createElement("div", {
778
+ style: {
779
+ flex: '0 0 auto',
780
+ width: '2em',
781
+ height: '2em',
782
+ background: utils.getQueryStatusColor({
783
+ queryState,
784
+ isStale,
785
+ observerCount,
786
+ theme: theme.defaultTheme
787
+ }),
788
+ display: 'flex',
789
+ alignItems: 'center',
790
+ justifyContent: 'center',
791
+ fontWeight: 'bold',
792
+ textShadow: isStale ? '0' : '0 0 10px black',
793
+ color: isStale ? 'black' : 'white'
794
+ }
795
+ }, observerCount), isDisabled ? /*#__PURE__*/React__namespace.createElement("div", {
796
+ style: {
797
+ flex: '0 0 auto',
798
+ height: '2em',
799
+ background: theme.defaultTheme.gray,
800
+ display: 'flex',
801
+ alignItems: 'center',
802
+ fontWeight: 'bold',
803
+ padding: '0 0.5em'
804
+ }
805
+ }, "disabled") : null, /*#__PURE__*/React__namespace.createElement(styledComponents.Code, {
806
+ style: {
807
+ padding: '.5em'
808
+ }
809
+ }, "" + queryHash));
810
+ }; // eslint-disable-next-line @typescript-eslint/no-empty-function
811
+
812
+
813
+ function noop() {}
814
+
815
+ exports.ReactQueryDevtools = ReactQueryDevtools;
816
+ exports.ReactQueryDevtoolsPanel = ReactQueryDevtoolsPanel;
817
+ exports.sortFns = sortFns;
818
+ //# sourceMappingURL=devtools.js.map