@tanstack/react-query-devtools 4.3.5 → 4.3.7

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