@tanstack/react-query-devtools 5.0.0-alpha.12 → 5.0.0-alpha.17

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 (73) hide show
  1. package/build/lib/CachePanel/ActiveQuery.d.ts +18 -0
  2. package/build/lib/CachePanel/ActiveQuery.esm.js +271 -0
  3. package/build/lib/CachePanel/ActiveQuery.esm.js.map +1 -0
  4. package/build/lib/CachePanel/ActiveQuery.js +275 -0
  5. package/build/lib/CachePanel/ActiveQuery.js.map +1 -0
  6. package/build/lib/CachePanel/ActiveQuery.mjs +257 -0
  7. package/build/lib/CachePanel/ActiveQuery.mjs.map +1 -0
  8. package/build/lib/CachePanel/CachePanel.d.ts +57 -0
  9. package/build/lib/CachePanel/CachePanel.esm.js +310 -0
  10. package/build/lib/CachePanel/CachePanel.esm.js.map +1 -0
  11. package/build/lib/CachePanel/CachePanel.js +315 -0
  12. package/build/lib/CachePanel/CachePanel.js.map +1 -0
  13. package/build/lib/CachePanel/CachePanel.mjs +310 -0
  14. package/build/lib/CachePanel/CachePanel.mjs.map +1 -0
  15. package/build/lib/CachePanel/Header/QueryStatusCount.d.ts +7 -0
  16. package/build/lib/CachePanel/Header/QueryStatusCount.esm.js +49 -0
  17. package/build/lib/CachePanel/Header/QueryStatusCount.esm.js.map +1 -0
  18. package/build/lib/CachePanel/Header/QueryStatusCount.js +53 -0
  19. package/build/lib/CachePanel/Header/QueryStatusCount.js.map +1 -0
  20. package/build/lib/CachePanel/Header/QueryStatusCount.mjs +49 -0
  21. package/build/lib/CachePanel/Header/QueryStatusCount.mjs.map +1 -0
  22. package/build/lib/CachePanel/QueryRow.d.ts +13 -0
  23. package/build/lib/CachePanel/QueryRow.esm.js +98 -0
  24. package/build/lib/CachePanel/QueryRow.esm.js.map +1 -0
  25. package/build/lib/CachePanel/QueryRow.js +102 -0
  26. package/build/lib/CachePanel/QueryRow.js.map +1 -0
  27. package/build/lib/CachePanel/QueryRow.mjs +82 -0
  28. package/build/lib/CachePanel/QueryRow.mjs.map +1 -0
  29. package/build/lib/devtools.d.ts +3 -64
  30. package/build/lib/devtools.esm.js +2 -669
  31. package/build/lib/devtools.esm.js.map +1 -1
  32. package/build/lib/devtools.js +3 -669
  33. package/build/lib/devtools.js.map +1 -1
  34. package/build/lib/devtools.mjs +2 -639
  35. package/build/lib/devtools.mjs.map +1 -1
  36. package/build/lib/index.esm.js +2 -1
  37. package/build/lib/index.esm.js.map +1 -1
  38. package/build/lib/index.js +2 -1
  39. package/build/lib/index.js.map +1 -1
  40. package/build/lib/index.mjs +2 -1
  41. package/build/lib/index.mjs.map +1 -1
  42. package/build/lib/index.prod.esm.js +754 -713
  43. package/build/lib/index.prod.esm.js.map +1 -1
  44. package/build/lib/index.prod.js +751 -710
  45. package/build/lib/index.prod.js.map +1 -1
  46. package/build/lib/index.prod.mjs +755 -714
  47. package/build/lib/index.prod.mjs.map +1 -1
  48. package/build/lib/styledComponents.esm.js +8 -0
  49. package/build/lib/styledComponents.esm.js.map +1 -1
  50. package/build/lib/styledComponents.js +8 -0
  51. package/build/lib/styledComponents.js.map +1 -1
  52. package/build/lib/styledComponents.mjs +8 -0
  53. package/build/lib/styledComponents.mjs.map +1 -1
  54. package/build/lib/types.d.ts +11 -0
  55. package/build/lib/useSubscribeToQueryCache.d.ts +3 -0
  56. package/build/lib/useSubscribeToQueryCache.esm.js +15 -0
  57. package/build/lib/useSubscribeToQueryCache.esm.js.map +1 -0
  58. package/build/lib/useSubscribeToQueryCache.js +19 -0
  59. package/build/lib/useSubscribeToQueryCache.js.map +1 -0
  60. package/build/lib/useSubscribeToQueryCache.mjs +15 -0
  61. package/build/lib/useSubscribeToQueryCache.mjs.map +1 -0
  62. package/build/umd/index.development.js +2394 -2353
  63. package/build/umd/index.development.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/CachePanel/ActiveQuery.tsx +380 -0
  66. package/src/CachePanel/CachePanel.tsx +439 -0
  67. package/src/CachePanel/Header/QueryStatusCount.tsx +93 -0
  68. package/src/CachePanel/QueryRow.tsx +125 -0
  69. package/src/__tests__/devtools.test.tsx +46 -0
  70. package/src/devtools.tsx +5 -1008
  71. package/src/styledComponents.ts +16 -0
  72. package/src/types.ts +12 -0
  73. package/src/useSubscribeToQueryCache.ts +26 -0
@@ -3,15 +3,12 @@
3
3
 
4
4
  var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
5
5
  var React = require('react');
6
- var reactQuery = require('@tanstack/react-query');
7
- var matchSorterUtils = require('@tanstack/match-sorter-utils');
8
6
  var useLocalStorage = require('./useLocalStorage.js');
9
7
  var utils = require('./utils.js');
10
- var styledComponents = require('./styledComponents.js');
11
8
  var screenreader = require('./screenreader.js');
12
9
  var theme = require('./theme.js');
13
- var Explorer = require('./Explorer.js');
14
10
  var Logo = require('./Logo.js');
11
+ var CachePanel = require('./CachePanel/CachePanel.js');
15
12
 
16
13
  function _interopNamespaceDefault(e) {
17
14
  var n = Object.create(null);
@@ -196,7 +193,7 @@ function ReactQueryDevtools({
196
193
  "aria-label": "React Query Devtools"
197
194
  }, /*#__PURE__*/React__namespace.createElement(theme.ThemeProvider, {
198
195
  theme: theme.defaultTheme
199
- }, /*#__PURE__*/React__namespace.createElement(ReactQueryDevtoolsPanel, _rollupPluginBabelHelpers.extends({
196
+ }, /*#__PURE__*/React__namespace.createElement(CachePanel.default, _rollupPluginBabelHelpers.extends({
200
197
  ref: panelRef,
201
198
  queryClient: queryClient,
202
199
  styleNonce: styleNonce,
@@ -253,670 +250,7 @@ function ReactQueryDevtools({
253
250
  text: "Open React Query Devtools"
254
251
  })) : null);
255
252
  }
256
- const useSubscribeToQueryCache = (queryCache, getSnapshot, skip = false) => {
257
- return React__namespace.useSyncExternalStore(React__namespace.useCallback(onStoreChange => {
258
- if (!skip) return queryCache.subscribe(reactQuery.notifyManager.batchCalls(onStoreChange));
259
- return () => {
260
- return;
261
- };
262
- }, [queryCache, skip]), getSnapshot, getSnapshot);
263
- };
264
- const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(function ReactQueryDevtoolsPanel(props, ref) {
265
- const {
266
- isOpen = true,
267
- styleNonce,
268
- setIsOpen,
269
- queryClient,
270
- onDragStart,
271
- onPositionChange,
272
- showCloseButton,
273
- position,
274
- closeButtonProps = {},
275
- errorTypes = [],
276
- ...panelProps
277
- } = props;
278
- const {
279
- onClick: onCloseClick,
280
- ...otherCloseButtonProps
281
- } = closeButtonProps;
282
- const client = reactQuery.useQueryClient(queryClient);
283
- const queryCache = client.getQueryCache();
284
- const [sort, setSort] = useLocalStorage.default('reactQueryDevtoolsSortFn', Object.keys(utils.sortFns)[0]);
285
- const [filter, setFilter] = useLocalStorage.default('reactQueryDevtoolsFilter', '');
286
- const [baseSort, setBaseSort] = useLocalStorage.default('reactQueryDevtoolsBaseSort', 1);
287
- const sortFn = React__namespace.useMemo(() => utils.sortFns[sort], [sort]);
288
- const queriesCount = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().length, !isOpen);
289
- const [activeQueryHash, setActiveQueryHash] = useLocalStorage.default('reactQueryDevtoolsActiveQueryHash', '');
290
- const queries = React__namespace.useMemo(() => {
291
- const unsortedQueries = queryCache.getAll();
292
- if (queriesCount === 0) {
293
- return [];
294
- }
295
- const filtered = filter ? unsortedQueries.filter(item => matchSorterUtils.rankItem(item.queryHash, filter).passed) : [...unsortedQueries];
296
- const sorted = sortFn ? filtered.sort((a, b) => sortFn(a, b) * baseSort) : filtered;
297
- return sorted;
298
- }, [baseSort, sortFn, filter, queriesCount, queryCache]);
299
- const [isMockOffline, setMockOffline] = React__namespace.useState(false);
300
- return /*#__PURE__*/React__namespace.createElement(theme.ThemeProvider, {
301
- theme: theme.defaultTheme
302
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Panel, _rollupPluginBabelHelpers.extends({
303
- ref: ref,
304
- className: "ReactQueryDevtoolsPanel",
305
- "aria-label": "React Query Devtools Panel",
306
- id: "ReactQueryDevtoolsPanel"
307
- }, panelProps, {
308
- style: {
309
- height: utils.defaultPanelSize,
310
- position: 'relative',
311
- ...panelProps.style
312
- }
313
- }), /*#__PURE__*/React__namespace.createElement("style", {
314
- nonce: styleNonce,
315
- dangerouslySetInnerHTML: {
316
- __html: `
317
- .ReactQueryDevtoolsPanel * {
318
- scrollbar-color: ${theme.defaultTheme.backgroundAlt} ${theme.defaultTheme.gray};
319
- }
320
-
321
- .ReactQueryDevtoolsPanel *::-webkit-scrollbar, .ReactQueryDevtoolsPanel scrollbar {
322
- width: 1em;
323
- height: 1em;
324
- }
325
-
326
- .ReactQueryDevtoolsPanel *::-webkit-scrollbar-track, .ReactQueryDevtoolsPanel scrollbar-track {
327
- background: ${theme.defaultTheme.backgroundAlt};
328
- }
329
-
330
- .ReactQueryDevtoolsPanel *::-webkit-scrollbar-thumb, .ReactQueryDevtoolsPanel scrollbar-thumb {
331
- background: ${theme.defaultTheme.gray};
332
- border-radius: .5em;
333
- border: 3px solid ${theme.defaultTheme.backgroundAlt};
334
- }
335
- `
336
- }
337
- }), /*#__PURE__*/React__namespace.createElement("div", {
338
- style: utils.getResizeHandleStyle(position),
339
- onMouseDown: onDragStart
340
- }), isOpen && /*#__PURE__*/React__namespace.createElement("div", {
341
- style: {
342
- flex: '1 1 500px',
343
- minHeight: '40%',
344
- maxHeight: '100%',
345
- overflow: 'auto',
346
- borderRight: `1px solid ${theme.defaultTheme.grayAlt}`,
347
- display: 'flex',
348
- flexDirection: 'column'
349
- }
350
- }, /*#__PURE__*/React__namespace.createElement("div", {
351
- style: {
352
- padding: '.5em',
353
- background: theme.defaultTheme.backgroundAlt,
354
- display: 'flex',
355
- justifyContent: 'space-between',
356
- alignItems: 'center'
357
- }
358
- }, /*#__PURE__*/React__namespace.createElement("button", {
359
- type: "button",
360
- "aria-label": "Close React Query Devtools",
361
- "aria-controls": "ReactQueryDevtoolsPanel",
362
- "aria-haspopup": "true",
363
- "aria-expanded": "true",
364
- onClick: () => setIsOpen(false),
365
- style: {
366
- display: 'inline-flex',
367
- background: 'none',
368
- border: 0,
369
- padding: 0,
370
- marginRight: '.5em',
371
- cursor: 'pointer'
372
- }
373
- }, /*#__PURE__*/React__namespace.createElement(Logo.default, {
374
- "aria-hidden": true
375
- }), /*#__PURE__*/React__namespace.createElement(screenreader.default, {
376
- text: "Close React Query Devtools"
377
- })), /*#__PURE__*/React__namespace.createElement("div", {
378
- style: {
379
- display: 'flex',
380
- flexDirection: 'column'
381
- }
382
- }, /*#__PURE__*/React__namespace.createElement("div", {
383
- style: {
384
- display: 'flex',
385
- justifyContent: 'space-between',
386
- alignItems: 'center',
387
- marginBottom: '.5em'
388
- }
389
- }, /*#__PURE__*/React__namespace.createElement(QueryStatusCount, {
390
- queryCache: queryCache
391
- }), position && onPositionChange ? /*#__PURE__*/React__namespace.createElement(styledComponents.Select, {
392
- "aria-label": "Panel position",
393
- value: position,
394
- style: {
395
- marginInlineStart: '.5em'
396
- },
397
- onChange: e => onPositionChange(e.target.value)
398
- }, /*#__PURE__*/React__namespace.createElement("option", {
399
- value: "left"
400
- }, "Left"), /*#__PURE__*/React__namespace.createElement("option", {
401
- value: "right"
402
- }, "Right"), /*#__PURE__*/React__namespace.createElement("option", {
403
- value: "top"
404
- }, "Top"), /*#__PURE__*/React__namespace.createElement("option", {
405
- value: "bottom"
406
- }, "Bottom")) : null), /*#__PURE__*/React__namespace.createElement("div", {
407
- style: {
408
- display: 'flex',
409
- alignItems: 'center',
410
- flexWrap: 'wrap',
411
- gap: '0.5em'
412
- }
413
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Input, {
414
- placeholder: "Filter",
415
- "aria-label": "Filter by queryhash",
416
- value: filter != null ? filter : '',
417
- onChange: e => setFilter(e.target.value),
418
- onKeyDown: e => {
419
- if (e.key === 'Escape') setFilter('');
420
- },
421
- style: {
422
- flex: '1',
423
- width: '100%'
424
- }
425
- }), /*#__PURE__*/React__namespace.createElement(styledComponents.Select, {
426
- "aria-label": "Sort queries",
427
- value: sort,
428
- onChange: e => setSort(e.target.value),
429
- style: {
430
- flex: '1',
431
- minWidth: 75,
432
- marginRight: '.5em'
433
- }
434
- }, Object.keys(utils.sortFns).map(key => /*#__PURE__*/React__namespace.createElement("option", {
435
- key: key,
436
- value: key
437
- }, "Sort by ", key))), /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
438
- type: "button",
439
- onClick: () => setBaseSort(old => old * -1),
440
- style: {
441
- padding: '.3em .4em',
442
- marginRight: '.5em'
443
- }
444
- }, baseSort === 1 ? '⬆ Asc' : '⬇ Desc'), /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
445
- type: "button",
446
- onClick: () => {
447
- if (isMockOffline) {
448
- reactQuery.onlineManager.setOnline(undefined);
449
- setMockOffline(false);
450
- window.dispatchEvent(new Event('online'));
451
- } else {
452
- reactQuery.onlineManager.setOnline(false);
453
- setMockOffline(true);
454
- window.dispatchEvent(new Event('offline'));
455
- }
456
- },
457
- "aria-label": isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
458
- title: isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
459
- style: {
460
- padding: '0',
461
- height: '2em'
462
- }
463
- }, /*#__PURE__*/React__namespace.createElement("svg", {
464
- xmlns: "http://www.w3.org/2000/svg",
465
- width: "2em",
466
- height: "2em",
467
- viewBox: "0 0 24 24",
468
- stroke: isMockOffline ? theme.defaultTheme.danger : 'currentColor',
469
- fill: "none"
470
- }, isMockOffline ? /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("path", {
471
- stroke: "none",
472
- d: "M0 0h24v24H0z",
473
- fill: "none"
474
- }), /*#__PURE__*/React__namespace.createElement("line", {
475
- x1: "12",
476
- y1: "18",
477
- x2: "12.01",
478
- y2: "18"
479
- }), /*#__PURE__*/React__namespace.createElement("path", {
480
- d: "M9.172 15.172a4 4 0 0 1 5.656 0"
481
- }), /*#__PURE__*/React__namespace.createElement("path", {
482
- 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"
483
- }), /*#__PURE__*/React__namespace.createElement("path", {
484
- d: "M3.515 9.515a12 12 0 0 1 3.544 -2.455m3.101 -.92a12 12 0 0 1 10.325 3.374"
485
- }), /*#__PURE__*/React__namespace.createElement("line", {
486
- x1: "3",
487
- y1: "3",
488
- x2: "21",
489
- y2: "21"
490
- })) : /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("path", {
491
- stroke: "none",
492
- d: "M0 0h24v24H0z",
493
- fill: "none"
494
- }), /*#__PURE__*/React__namespace.createElement("line", {
495
- x1: "12",
496
- y1: "18",
497
- x2: "12.01",
498
- y2: "18"
499
- }), /*#__PURE__*/React__namespace.createElement("path", {
500
- d: "M9.172 15.172a4 4 0 0 1 5.656 0"
501
- }), /*#__PURE__*/React__namespace.createElement("path", {
502
- d: "M6.343 12.343a8 8 0 0 1 11.314 0"
503
- }), /*#__PURE__*/React__namespace.createElement("path", {
504
- d: "M3.515 9.515c4.686 -4.687 12.284 -4.687 17 0"
505
- }))), /*#__PURE__*/React__namespace.createElement(screenreader.default, {
506
- text: isMockOffline ? 'Restore offline mock' : 'Mock offline behavior'
507
- }))))), /*#__PURE__*/React__namespace.createElement("div", {
508
- style: {
509
- overflowY: 'auto',
510
- flex: '1'
511
- }
512
- }, queries.map(query => {
513
- return /*#__PURE__*/React__namespace.createElement(QueryRow, {
514
- queryKey: query.queryKey,
515
- activeQueryHash: activeQueryHash,
516
- setActiveQueryHash: setActiveQueryHash,
517
- key: query.queryHash,
518
- queryCache: queryCache
519
- });
520
- }))), activeQueryHash && isOpen ? /*#__PURE__*/React__namespace.createElement(ActiveQuery, {
521
- activeQueryHash: activeQueryHash,
522
- queryCache: queryCache,
523
- queryClient: client,
524
- errorTypes: errorTypes
525
- }) : null, showCloseButton ? /*#__PURE__*/React__namespace.createElement(styledComponents.Button, _rollupPluginBabelHelpers.extends({
526
- type: "button",
527
- "aria-controls": "ReactQueryDevtoolsPanel",
528
- "aria-haspopup": "true",
529
- "aria-expanded": "true"
530
- }, otherCloseButtonProps, {
531
- style: {
532
- position: 'absolute',
533
- zIndex: 99999,
534
- margin: '.5em',
535
- bottom: 0,
536
- left: 0,
537
- ...otherCloseButtonProps.style
538
- },
539
- onClick: e => {
540
- setIsOpen(false);
541
- onCloseClick == null ? void 0 : onCloseClick(e);
542
- }
543
- }), "Close") : null));
544
- });
545
- const ActiveQuery = ({
546
- queryCache,
547
- activeQueryHash,
548
- queryClient,
549
- errorTypes
550
- }) => {
551
- var _useSubscribeToQueryC, _useSubscribeToQueryC2;
552
- const activeQuery = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash));
553
- const activeQueryState = useSubscribeToQueryCache(queryCache, () => {
554
- var _queryCache$getAll$fi;
555
- return (_queryCache$getAll$fi = queryCache.getAll().find(query => query.queryHash === activeQueryHash)) == null ? void 0 : _queryCache$getAll$fi.state;
556
- });
557
- const isStale = (_useSubscribeToQueryC = useSubscribeToQueryCache(queryCache, () => {
558
- var _queryCache$getAll$fi2;
559
- return (_queryCache$getAll$fi2 = queryCache.getAll().find(query => query.queryHash === activeQueryHash)) == null ? void 0 : _queryCache$getAll$fi2.isStale();
560
- })) != null ? _useSubscribeToQueryC : false;
561
- const observerCount = (_useSubscribeToQueryC2 = useSubscribeToQueryCache(queryCache, () => {
562
- var _queryCache$getAll$fi3;
563
- return (_queryCache$getAll$fi3 = queryCache.getAll().find(query => query.queryHash === activeQueryHash)) == null ? void 0 : _queryCache$getAll$fi3.getObserversCount();
564
- })) != null ? _useSubscribeToQueryC2 : 0;
565
- const handleRefetch = () => {
566
- const promise = activeQuery == null ? void 0 : activeQuery.fetch();
567
- promise == null ? void 0 : promise.catch(noop);
568
- };
569
- const currentErrorTypeName = React.useMemo(() => {
570
- if (activeQuery && activeQueryState != null && activeQueryState.error) {
571
- const errorType = errorTypes.find(type => {
572
- var _activeQueryState$err;
573
- return type.initializer(activeQuery).toString() === ((_activeQueryState$err = activeQueryState.error) == null ? void 0 : _activeQueryState$err.toString());
574
- });
575
- return errorType == null ? void 0 : errorType.name;
576
- }
577
- return undefined;
578
- }, [activeQuery, activeQueryState == null ? void 0 : activeQueryState.error, errorTypes]);
579
- if (!activeQuery || !activeQueryState) {
580
- return null;
581
- }
582
- const triggerError = errorType => {
583
- var _errorType$initialize;
584
- const error = (_errorType$initialize = errorType == null ? void 0 : errorType.initializer(activeQuery)) != null ? _errorType$initialize : new Error('Unknown error from devtools');
585
- const __previousQueryOptions = activeQuery.options;
586
- activeQuery.setState({
587
- status: 'error',
588
- error,
589
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
590
- fetchMeta: {
591
- ...activeQuery.state.fetchMeta,
592
- __previousQueryOptions
593
- }
594
- });
595
- };
596
- const restoreQueryAfterLoadingOrError = () => {
597
- activeQuery.fetch(activeQuery.state.fetchMeta.__previousQueryOptions, {
598
- // Make sure this fetch will cancel the previous one
599
- cancelRefetch: true
600
- });
601
- };
602
- return /*#__PURE__*/React__namespace.createElement(styledComponents.ActiveQueryPanel, null, /*#__PURE__*/React__namespace.createElement("div", {
603
- style: {
604
- padding: '.5em',
605
- background: theme.defaultTheme.backgroundAlt,
606
- position: 'sticky',
607
- top: 0,
608
- zIndex: 1
609
- }
610
- }, "Query Details"), /*#__PURE__*/React__namespace.createElement("div", {
611
- style: {
612
- padding: '.5em'
613
- }
614
- }, /*#__PURE__*/React__namespace.createElement("div", {
615
- style: {
616
- marginBottom: '.5em',
617
- display: 'flex',
618
- alignItems: 'flex-start',
619
- justifyContent: 'space-between'
620
- }
621
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Code, {
622
- style: {
623
- lineHeight: '1.8em'
624
- }
625
- }, /*#__PURE__*/React__namespace.createElement("pre", {
626
- style: {
627
- margin: 0,
628
- padding: 0,
629
- overflow: 'auto'
630
- }
631
- }, utils.displayValue(activeQuery.queryKey, true))), /*#__PURE__*/React__namespace.createElement("span", {
632
- style: {
633
- padding: '0.3em .6em',
634
- borderRadius: '0.4em',
635
- fontWeight: 'bold',
636
- textShadow: '0 2px 10px black',
637
- background: utils.getQueryStatusColor({
638
- queryState: activeQueryState,
639
- isStale: isStale,
640
- observerCount: observerCount,
641
- theme: theme.defaultTheme
642
- }),
643
- flexShrink: 0
644
- }
645
- }, utils.getQueryStatusLabel(activeQuery))), /*#__PURE__*/React__namespace.createElement("div", {
646
- style: {
647
- marginBottom: '.5em',
648
- display: 'flex',
649
- alignItems: 'center',
650
- justifyContent: 'space-between'
651
- }
652
- }, "Observers: ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, observerCount)), /*#__PURE__*/React__namespace.createElement("div", {
653
- style: {
654
- display: 'flex',
655
- alignItems: 'center',
656
- justifyContent: 'space-between'
657
- }
658
- }, "Last Updated:", ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, new Date(activeQueryState.dataUpdatedAt).toLocaleTimeString()))), /*#__PURE__*/React__namespace.createElement("div", {
659
- style: {
660
- background: theme.defaultTheme.backgroundAlt,
661
- padding: '.5em',
662
- position: 'sticky',
663
- top: 0,
664
- zIndex: 1
665
- }
666
- }, "Actions"), /*#__PURE__*/React__namespace.createElement("div", {
667
- style: {
668
- padding: '0.5em',
669
- display: 'flex',
670
- flexWrap: 'wrap',
671
- gap: '0.5em',
672
- alignItems: 'flex-end'
673
- }
674
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
675
- type: "button",
676
- onClick: handleRefetch,
677
- disabled: activeQueryState.fetchStatus === 'fetching',
678
- style: {
679
- background: theme.defaultTheme.active
680
- }
681
- }, "Refetch"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
682
- type: "button",
683
- onClick: () => queryClient.invalidateQueries(activeQuery),
684
- style: {
685
- background: theme.defaultTheme.warning,
686
- color: theme.defaultTheme.inputTextColor
687
- }
688
- }, "Invalidate"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
689
- type: "button",
690
- onClick: () => queryClient.resetQueries(activeQuery),
691
- style: {
692
- background: theme.defaultTheme.gray
693
- }
694
- }, "Reset"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
695
- type: "button",
696
- onClick: () => queryClient.removeQueries(activeQuery),
697
- style: {
698
- background: theme.defaultTheme.danger
699
- }
700
- }, "Remove"), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
701
- type: "button",
702
- onClick: () => {
703
- if (activeQuery.state.data === undefined) {
704
- restoreQueryAfterLoadingOrError();
705
- } else {
706
- const __previousQueryOptions = activeQuery.options;
707
- // Trigger a fetch in order to trigger suspense as well.
708
- activeQuery.fetch({
709
- ...__previousQueryOptions,
710
- queryFn: () => {
711
- return new Promise(() => {
712
- // Never resolve
713
- });
714
- },
715
- gcTime: -1
716
- });
717
- activeQuery.setState({
718
- data: undefined,
719
- status: 'pending',
720
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
721
- fetchMeta: {
722
- ...activeQuery.state.fetchMeta,
723
- __previousQueryOptions
724
- }
725
- });
726
- }
727
- },
728
- style: {
729
- background: theme.defaultTheme.paused
730
- }
731
- }, activeQuery.state.status === 'pending' ? 'Restore' : 'Trigger', ' ', "loading"), ' ', errorTypes.length === 0 || activeQuery.state.status === 'error' ? /*#__PURE__*/React__namespace.createElement(styledComponents.Button, {
732
- type: "button",
733
- onClick: () => {
734
- if (!activeQuery.state.error) {
735
- triggerError();
736
- } else {
737
- queryClient.resetQueries(activeQuery);
738
- }
739
- },
740
- style: {
741
- background: theme.defaultTheme.danger
742
- }
743
- }, activeQuery.state.status === 'error' ? 'Restore' : 'Trigger', " error") : /*#__PURE__*/React__namespace.createElement("label", null, "Trigger error:", /*#__PURE__*/React__namespace.createElement(styledComponents.Select, {
744
- value: currentErrorTypeName != null ? currentErrorTypeName : '',
745
- style: {
746
- marginInlineStart: '.5em'
747
- },
748
- onChange: e => {
749
- const errorType = errorTypes.find(t => t.name === e.target.value);
750
- triggerError(errorType);
751
- }
752
- }, /*#__PURE__*/React__namespace.createElement("option", {
753
- key: "",
754
- value: ""
755
- }), errorTypes.map(errorType => /*#__PURE__*/React__namespace.createElement("option", {
756
- key: errorType.name,
757
- value: errorType.name
758
- }, errorType.name))))), /*#__PURE__*/React__namespace.createElement("div", {
759
- style: {
760
- background: theme.defaultTheme.backgroundAlt,
761
- padding: '.5em',
762
- position: 'sticky',
763
- top: 0,
764
- zIndex: 1
765
- }
766
- }, "Data Explorer"), /*#__PURE__*/React__namespace.createElement("div", {
767
- style: {
768
- padding: '.5em'
769
- }
770
- }, /*#__PURE__*/React__namespace.createElement(Explorer.default, {
771
- label: "Data",
772
- value: activeQueryState.data,
773
- defaultExpanded: {},
774
- copyable: true
775
- })), /*#__PURE__*/React__namespace.createElement("div", {
776
- style: {
777
- background: theme.defaultTheme.backgroundAlt,
778
- padding: '.5em',
779
- position: 'sticky',
780
- top: 0,
781
- zIndex: 1
782
- }
783
- }, "Query Explorer"), /*#__PURE__*/React__namespace.createElement("div", {
784
- style: {
785
- padding: '.5em'
786
- }
787
- }, /*#__PURE__*/React__namespace.createElement(Explorer.default, {
788
- label: "Query",
789
- value: activeQuery,
790
- defaultExpanded: {
791
- queryKey: true
792
- }
793
- })));
794
- };
795
- const QueryStatusCount = ({
796
- queryCache
797
- }) => {
798
- const hasFresh = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'fresh').length);
799
- const hasFetching = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'fetching').length);
800
- const hasPaused = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'paused').length);
801
- const hasStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'stale').length);
802
- const hasInactive = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'inactive').length);
803
- return /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKeys, null, /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
804
- style: {
805
- background: theme.defaultTheme.success,
806
- opacity: hasFresh ? 1 : 0.3
807
- }
808
- }, "fresh ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasFresh, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
809
- style: {
810
- background: theme.defaultTheme.active,
811
- opacity: hasFetching ? 1 : 0.3
812
- }
813
- }, "fetching ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasFetching, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
814
- style: {
815
- background: theme.defaultTheme.paused,
816
- opacity: hasPaused ? 1 : 0.3
817
- }
818
- }, "paused ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasPaused, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
819
- style: {
820
- background: theme.defaultTheme.warning,
821
- color: 'black',
822
- textShadow: '0',
823
- opacity: hasStale ? 1 : 0.3
824
- }
825
- }, "stale ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasStale, ")")), ' ', /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
826
- style: {
827
- background: theme.defaultTheme.gray,
828
- opacity: hasInactive ? 1 : 0.3
829
- }
830
- }, "inactive ", /*#__PURE__*/React__namespace.createElement(styledComponents.Code, null, "(", hasInactive, ")")));
831
- };
832
- const QueryRow = /*#__PURE__*/React__namespace.memo(({
833
- queryKey,
834
- setActiveQueryHash,
835
- activeQueryHash,
836
- queryCache
837
- }) => {
838
- var _useSubscribeToQueryC3, _useSubscribeToQueryC4, _useSubscribeToQueryC5, _useSubscribeToQueryC6;
839
- const queryHash = (_useSubscribeToQueryC3 = useSubscribeToQueryCache(queryCache, () => {
840
- var _queryCache$find;
841
- return (_queryCache$find = queryCache.find({
842
- queryKey
843
- })) == null ? void 0 : _queryCache$find.queryHash;
844
- })) != null ? _useSubscribeToQueryC3 : '';
845
- const queryState = useSubscribeToQueryCache(queryCache, () => {
846
- var _queryCache$find2;
847
- return (_queryCache$find2 = queryCache.find({
848
- queryKey
849
- })) == null ? void 0 : _queryCache$find2.state;
850
- });
851
- const isStale = (_useSubscribeToQueryC4 = useSubscribeToQueryCache(queryCache, () => {
852
- var _queryCache$find3;
853
- return (_queryCache$find3 = queryCache.find({
854
- queryKey
855
- })) == null ? void 0 : _queryCache$find3.isStale();
856
- })) != null ? _useSubscribeToQueryC4 : false;
857
- const isDisabled = (_useSubscribeToQueryC5 = useSubscribeToQueryCache(queryCache, () => {
858
- var _queryCache$find4;
859
- return (_queryCache$find4 = queryCache.find({
860
- queryKey
861
- })) == null ? void 0 : _queryCache$find4.isDisabled();
862
- })) != null ? _useSubscribeToQueryC5 : false;
863
- const observerCount = (_useSubscribeToQueryC6 = useSubscribeToQueryCache(queryCache, () => {
864
- var _queryCache$find5;
865
- return (_queryCache$find5 = queryCache.find({
866
- queryKey
867
- })) == null ? void 0 : _queryCache$find5.getObserversCount();
868
- })) != null ? _useSubscribeToQueryC6 : 0;
869
- if (!queryState) {
870
- return null;
871
- }
872
- return /*#__PURE__*/React__namespace.createElement("div", {
873
- role: "button",
874
- "aria-label": `Open query details for ${queryHash}`,
875
- onClick: () => setActiveQueryHash(activeQueryHash === queryHash ? '' : queryHash),
876
- style: {
877
- display: 'flex',
878
- borderBottom: `solid 1px ${theme.defaultTheme.grayAlt}`,
879
- cursor: 'pointer',
880
- background: queryHash === activeQueryHash ? 'rgba(255,255,255,.1)' : undefined
881
- }
882
- }, /*#__PURE__*/React__namespace.createElement("div", {
883
- style: {
884
- flex: '0 0 auto',
885
- width: '2em',
886
- height: '2em',
887
- background: utils.getQueryStatusColor({
888
- queryState,
889
- isStale,
890
- observerCount,
891
- theme: theme.defaultTheme
892
- }),
893
- display: 'flex',
894
- alignItems: 'center',
895
- justifyContent: 'center',
896
- fontWeight: 'bold',
897
- textShadow: isStale ? '0' : '0 0 10px black',
898
- color: isStale ? 'black' : 'white'
899
- }
900
- }, observerCount), isDisabled ? /*#__PURE__*/React__namespace.createElement("div", {
901
- style: {
902
- flex: '0 0 auto',
903
- height: '2em',
904
- background: theme.defaultTheme.gray,
905
- display: 'flex',
906
- alignItems: 'center',
907
- fontWeight: 'bold',
908
- padding: '0 0.5em'
909
- }
910
- }, "disabled") : null, /*#__PURE__*/React__namespace.createElement(styledComponents.Code, {
911
- style: {
912
- padding: '.5em'
913
- }
914
- }, `${queryHash}`));
915
- });
916
-
917
- // eslint-disable-next-line @typescript-eslint/no-empty-function
918
- function noop() {}
919
253
 
254
+ exports.ReactQueryDevtoolsPanel = CachePanel.default;
920
255
  exports.ReactQueryDevtools = ReactQueryDevtools;
921
- exports.ReactQueryDevtoolsPanel = ReactQueryDevtoolsPanel;
922
256
  //# sourceMappingURL=devtools.js.map