@tanstack/react-query-devtools 4.10.3 → 4.11.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.
@@ -2146,18 +2146,108 @@
2146
2146
  'Query Hash': queryHashSort,
2147
2147
  'Last Updated': dateSort
2148
2148
  };
2149
+ const minPanelSize = 70;
2150
+ const defaultPanelSize = 500;
2151
+ const sides = {
2152
+ top: 'bottom',
2153
+ bottom: 'top',
2154
+ left: 'right',
2155
+ right: 'left'
2156
+ };
2149
2157
 
2150
- function ScreenReader({
2151
- text
2158
+ /**
2159
+ * Check if the given side is vertical (left/right)
2160
+ */
2161
+ function isVerticalSide(side) {
2162
+ return ['left', 'right'].includes(side);
2163
+ }
2164
+ /**
2165
+ * Get the opposite side, eg 'left' => 'right'. 'top' => 'bottom', etc
2166
+ */
2167
+
2168
+ function getOppositeSide(side) {
2169
+ return sides[side];
2170
+ }
2171
+ /**
2172
+ * Given as css prop it will return a sided css prop based on a given side
2173
+ * Example given `border` and `right` it return `borderRight`
2174
+ */
2175
+
2176
+ function getSidedProp(prop, side) {
2177
+ return "" + prop + (side.charAt(0).toUpperCase() + side.slice(1));
2178
+ }
2179
+ function getSidePanelStyle({
2180
+ position = 'bottom',
2181
+ height,
2182
+ width,
2183
+ devtoolsTheme,
2184
+ isOpen,
2185
+ isResizing,
2186
+ panelStyle
2152
2187
  }) {
2153
- return /*#__PURE__*/React__namespace.createElement("span", {
2154
- style: {
2155
- position: 'absolute',
2156
- width: '0.1px',
2157
- height: '0.1px',
2158
- overflow: 'hidden'
2159
- }
2160
- }, text);
2188
+ const oppositeSide = getOppositeSide(position);
2189
+ const borderSide = getSidedProp('border', oppositeSide);
2190
+ const isVertical = isVerticalSide(position);
2191
+ return { ...panelStyle,
2192
+ direction: 'ltr',
2193
+ position: 'fixed',
2194
+ [position]: 0,
2195
+ [borderSide]: "1px solid " + devtoolsTheme.gray,
2196
+ transformOrigin: oppositeSide,
2197
+ boxShadow: '0 0 20px rgba(0,0,0,.3)',
2198
+ zIndex: 99999,
2199
+ // visibility will be toggled after transitions, but set initial state here
2200
+ visibility: isOpen ? 'visible' : 'hidden',
2201
+ ...(isResizing ? {
2202
+ transition: "none"
2203
+ } : {
2204
+ transition: "all .2s ease"
2205
+ }),
2206
+ ...(isOpen ? {
2207
+ opacity: 1,
2208
+ pointerEvents: 'all',
2209
+ transform: isVertical ? "translateX(0) scale(1)" : "translateY(0) scale(1)"
2210
+ } : {
2211
+ opacity: 0,
2212
+ pointerEvents: 'none',
2213
+ transform: isVertical ? "translateX(15px) scale(1.02)" : "translateY(15px) scale(1.02)"
2214
+ }),
2215
+ ...(isVertical ? {
2216
+ top: 0,
2217
+ height: '100vh',
2218
+ maxWidth: '90%',
2219
+ width: typeof width === 'number' && width >= minPanelSize ? width : defaultPanelSize
2220
+ } : {
2221
+ left: 0,
2222
+ width: '100%',
2223
+ maxHeight: '90%',
2224
+ height: typeof height === 'number' && height >= minPanelSize ? height : defaultPanelSize
2225
+ })
2226
+ };
2227
+ }
2228
+ /**
2229
+ * Get resize handle style based on a given side
2230
+ */
2231
+
2232
+ function getResizeHandleStyle(position = 'bottom') {
2233
+ const isVertical = isVerticalSide(position);
2234
+ const oppositeSide = getOppositeSide(position);
2235
+ const marginSide = getSidedProp('margin', oppositeSide);
2236
+ return {
2237
+ position: 'absolute',
2238
+ cursor: isVertical ? 'col-resize' : 'row-resize',
2239
+ zIndex: 100000,
2240
+ [oppositeSide]: 0,
2241
+ [marginSide]: "-4px",
2242
+ ...(isVertical ? {
2243
+ top: 0,
2244
+ height: '100%',
2245
+ width: '4px'
2246
+ } : {
2247
+ width: '100%',
2248
+ height: '4px'
2249
+ })
2250
+ };
2161
2251
  }
2162
2252
 
2163
2253
  const Panel = styled('div', (_props, theme) => ({
@@ -2248,6 +2338,19 @@
2248
2338
  }
2249
2339
  });
2250
2340
 
2341
+ function ScreenReader({
2342
+ text
2343
+ }) {
2344
+ return /*#__PURE__*/React__namespace.createElement("span", {
2345
+ style: {
2346
+ position: 'absolute',
2347
+ width: '0.1px',
2348
+ height: '0.1px',
2349
+ overflow: 'hidden'
2350
+ }
2351
+ }, text);
2352
+ }
2353
+
2251
2354
  const Entry = styled('div', {
2252
2355
  fontFamily: 'Menlo, monospace',
2253
2356
  fontSize: '1em',
@@ -2441,33 +2544,47 @@
2441
2544
  position = 'bottom-left',
2442
2545
  containerElement: Container = 'aside',
2443
2546
  context,
2444
- styleNonce
2547
+ styleNonce,
2548
+ panelPosition: initialPanelPosition = 'bottom'
2445
2549
  }) {
2446
2550
  const rootRef = React__namespace.useRef(null);
2447
2551
  const panelRef = React__namespace.useRef(null);
2448
2552
  const [isOpen, setIsOpen] = useLocalStorage('reactQueryDevtoolsOpen', initialIsOpen);
2449
- const [devtoolsHeight, setDevtoolsHeight] = useLocalStorage('reactQueryDevtoolsHeight', null);
2553
+ const [devtoolsHeight, setDevtoolsHeight] = useLocalStorage('reactQueryDevtoolsHeight', defaultPanelSize);
2554
+ const [devtoolsWidth, setDevtoolsWidth] = useLocalStorage('reactQueryDevtoolsWidth', defaultPanelSize);
2555
+ const [panelPosition = 'bottom', setPanelPosition] = useLocalStorage('reactQueryDevtoolsPanelPosition', initialPanelPosition);
2450
2556
  const [isResolvedOpen, setIsResolvedOpen] = React__namespace.useState(false);
2451
2557
  const [isResizing, setIsResizing] = React__namespace.useState(false);
2452
2558
  const isMounted = useIsMounted();
2453
2559
 
2454
2560
  const handleDragStart = (panelElement, startEvent) => {
2455
- var _panelElement$getBoun;
2456
-
2561
+ if (!panelElement) return;
2457
2562
  if (startEvent.button !== 0) return; // Only allow left click for drag
2458
2563
 
2564
+ const isVertical = isVerticalSide(panelPosition);
2459
2565
  setIsResizing(true);
2460
- const dragInfo = {
2461
- originalHeight: (_panelElement$getBoun = panelElement == null ? void 0 : panelElement.getBoundingClientRect().height) != null ? _panelElement$getBoun : 0,
2462
- pageY: startEvent.pageY
2463
- };
2566
+ const {
2567
+ height,
2568
+ width
2569
+ } = panelElement.getBoundingClientRect();
2570
+ const startX = startEvent.clientX;
2571
+ const startY = startEvent.clientY;
2572
+ let newSize = 0;
2464
2573
 
2465
2574
  const run = moveEvent => {
2466
- const delta = dragInfo.pageY - moveEvent.pageY;
2467
- const newHeight = dragInfo.originalHeight + delta;
2468
- setDevtoolsHeight(newHeight);
2575
+ // prevent mouse selecting stuff with mouse drag
2576
+ moveEvent.preventDefault(); // calculate the correct size based on mouse position and current panel position
2577
+ // hint: it is different formula for the opposite sides
2469
2578
 
2470
- if (newHeight < 70) {
2579
+ if (isVertical) {
2580
+ newSize = width + (panelPosition === 'right' ? startX - moveEvent.clientX : moveEvent.clientX - startX);
2581
+ setDevtoolsWidth(newSize);
2582
+ } else {
2583
+ newSize = height + (panelPosition === 'bottom' ? startY - moveEvent.clientY : moveEvent.clientY - startY);
2584
+ setDevtoolsHeight(newSize);
2585
+ }
2586
+
2587
+ if (newSize < minPanelSize) {
2471
2588
  setIsOpen(false);
2472
2589
  } else {
2473
2590
  setIsOpen(true);
@@ -2475,13 +2592,16 @@
2475
2592
  };
2476
2593
 
2477
2594
  const unsub = () => {
2478
- setIsResizing(false);
2479
- document.removeEventListener('mousemove', run);
2480
- document.removeEventListener('mouseUp', unsub);
2595
+ if (isResizing) {
2596
+ setIsResizing(false);
2597
+ }
2598
+
2599
+ document.removeEventListener('mousemove', run, false);
2600
+ document.removeEventListener('mouseUp', unsub, false);
2481
2601
  };
2482
2602
 
2483
- document.addEventListener('mousemove', run);
2484
- document.addEventListener('mouseup', unsub);
2603
+ document.addEventListener('mousemove', run, false);
2604
+ document.addEventListener('mouseup', unsub, false);
2485
2605
  };
2486
2606
 
2487
2607
  React__namespace.useEffect(() => {
@@ -2518,15 +2638,20 @@
2518
2638
  var _root$parentElement;
2519
2639
 
2520
2640
  const root = rootRef.current;
2521
- const previousValue = root == null ? void 0 : (_root$parentElement = root.parentElement) == null ? void 0 : _root$parentElement.style.paddingBottom;
2641
+ const styleProp = getSidedProp('padding', panelPosition);
2642
+ const isVertical = isVerticalSide(panelPosition);
2643
+ const previousValue = root == null ? void 0 : (_root$parentElement = root.parentElement) == null ? void 0 : _root$parentElement.style[styleProp];
2522
2644
 
2523
2645
  const run = () => {
2524
- var _panelRef$current;
2525
-
2526
- const containerHeight = (_panelRef$current = panelRef.current) == null ? void 0 : _panelRef$current.getBoundingClientRect().height;
2527
-
2528
2646
  if (root != null && root.parentElement) {
2529
- root.parentElement.style.paddingBottom = containerHeight + "px";
2647
+ // reset the padding
2648
+ root.parentElement.style.padding = '0px';
2649
+ root.parentElement.style.paddingTop = '0px';
2650
+ root.parentElement.style.paddingBottom = '0px';
2651
+ root.parentElement.style.paddingLeft = '0px';
2652
+ root.parentElement.style.paddingRight = '0px'; // set the new padding based on the new panel position
2653
+
2654
+ root.parentElement.style[styleProp] = (isVertical ? devtoolsWidth : devtoolsHeight) + "px";
2530
2655
  }
2531
2656
  };
2532
2657
 
@@ -2538,26 +2663,31 @@
2538
2663
  window.removeEventListener('resize', run);
2539
2664
 
2540
2665
  if (root != null && root.parentElement && typeof previousValue === 'string') {
2541
- root.parentElement.style.paddingBottom = previousValue;
2666
+ root.parentElement.style[styleProp] = previousValue;
2542
2667
  }
2543
2668
  };
2544
2669
  }
2545
2670
  }
2546
- }, [isResolvedOpen]);
2671
+ }, [isResolvedOpen, panelPosition, devtoolsHeight, devtoolsWidth]);
2547
2672
  const {
2548
2673
  style: panelStyle = {},
2549
2674
  ...otherPanelProps
2550
2675
  } = panelProps;
2551
- const {
2552
- style: closeButtonStyle = {},
2553
- onClick: onCloseClick,
2554
- ...otherCloseButtonProps
2555
- } = closeButtonProps;
2556
2676
  const {
2557
2677
  style: toggleButtonStyle = {},
2558
2678
  onClick: onToggleClick,
2559
2679
  ...otherToggleButtonProps
2560
- } = toggleButtonProps; // Do not render on the server
2680
+ } = toggleButtonProps; // get computed style based on panel position
2681
+
2682
+ const style = getSidePanelStyle({
2683
+ position: panelPosition,
2684
+ devtoolsTheme: defaultTheme,
2685
+ isOpen: isResolvedOpen,
2686
+ height: devtoolsHeight,
2687
+ width: devtoolsWidth,
2688
+ isResizing,
2689
+ panelStyle
2690
+ }); // Do not render on the server
2561
2691
 
2562
2692
  if (!isMounted()) return null;
2563
2693
  return /*#__PURE__*/React__namespace.createElement(Container, {
@@ -2569,67 +2699,17 @@
2569
2699
  }, /*#__PURE__*/React__namespace.createElement(ReactQueryDevtoolsPanel$1, _extends({
2570
2700
  ref: panelRef,
2571
2701
  context: context,
2572
- styleNonce: styleNonce
2702
+ styleNonce: styleNonce,
2703
+ position: panelPosition,
2704
+ onPositionChange: setPanelPosition,
2705
+ showCloseButton: true,
2706
+ closeButtonProps: closeButtonProps
2573
2707
  }, otherPanelProps, {
2574
- style: {
2575
- position: 'fixed',
2576
- bottom: '0',
2577
- right: '0',
2578
- zIndex: 99999,
2579
- width: '100%',
2580
- height: devtoolsHeight != null ? devtoolsHeight : 500,
2581
- maxHeight: '90%',
2582
- boxShadow: '0 0 20px rgba(0,0,0,.3)',
2583
- borderTop: "1px solid " + defaultTheme.gray,
2584
- transformOrigin: 'top',
2585
- // visibility will be toggled after transitions, but set initial state here
2586
- visibility: isOpen ? 'visible' : 'hidden',
2587
- ...panelStyle,
2588
- ...(isResizing ? {
2589
- transition: "none"
2590
- } : {
2591
- transition: "all .2s ease"
2592
- }),
2593
- ...(isResolvedOpen ? {
2594
- opacity: 1,
2595
- pointerEvents: 'all',
2596
- transform: "translateY(0) scale(1)"
2597
- } : {
2598
- opacity: 0,
2599
- pointerEvents: 'none',
2600
- transform: "translateY(15px) scale(1.02)"
2601
- })
2602
- },
2708
+ style: style,
2603
2709
  isOpen: isResolvedOpen,
2604
2710
  setIsOpen: setIsOpen,
2605
- handleDragStart: e => handleDragStart(panelRef.current, e)
2606
- })), isResolvedOpen ? /*#__PURE__*/React__namespace.createElement(Button, _extends({
2607
- type: "button",
2608
- "aria-controls": "ReactQueryDevtoolsPanel",
2609
- "aria-haspopup": "true",
2610
- "aria-expanded": "true"
2611
- }, otherCloseButtonProps, {
2612
- onClick: e => {
2613
- setIsOpen(false);
2614
- onCloseClick == null ? void 0 : onCloseClick(e);
2615
- },
2616
- style: {
2617
- position: 'fixed',
2618
- zIndex: 99999,
2619
- margin: '.5em',
2620
- bottom: 0,
2621
- ...(position === 'top-right' ? {
2622
- right: '0'
2623
- } : position === 'top-left' ? {
2624
- left: '0'
2625
- } : position === 'bottom-right' ? {
2626
- right: '0'
2627
- } : {
2628
- left: '0'
2629
- }),
2630
- ...closeButtonStyle
2631
- }
2632
- }), "Close") : null), !isResolvedOpen ? /*#__PURE__*/React__namespace.createElement("button", _extends({
2711
+ onDragStart: e => handleDragStart(panelRef.current, e)
2712
+ }))), !isResolvedOpen ? /*#__PURE__*/React__namespace.createElement("button", _extends({
2633
2713
  type: "button"
2634
2714
  }, otherToggleButtonProps, {
2635
2715
  "aria-label": "Open React Query Devtools",
@@ -2687,10 +2767,18 @@
2687
2767
  isOpen = true,
2688
2768
  styleNonce,
2689
2769
  setIsOpen,
2690
- handleDragStart,
2691
2770
  context,
2771
+ onDragStart,
2772
+ onPositionChange,
2773
+ showCloseButton,
2774
+ position,
2775
+ closeButtonProps = {},
2692
2776
  ...panelProps
2693
2777
  } = props;
2778
+ const {
2779
+ onClick: onCloseClick,
2780
+ ...otherCloseButtonProps
2781
+ } = closeButtonProps;
2694
2782
  const queryClient = reactQuery.useQueryClient({
2695
2783
  context
2696
2784
  });
@@ -2720,23 +2808,20 @@
2720
2808
  className: "ReactQueryDevtoolsPanel",
2721
2809
  "aria-label": "React Query Devtools Panel",
2722
2810
  id: "ReactQueryDevtoolsPanel"
2723
- }, panelProps), /*#__PURE__*/React__namespace.createElement("style", {
2811
+ }, panelProps, {
2812
+ style: {
2813
+ height: defaultPanelSize,
2814
+ position: 'relative',
2815
+ ...panelProps.style
2816
+ }
2817
+ }), /*#__PURE__*/React__namespace.createElement("style", {
2724
2818
  nonce: styleNonce,
2725
2819
  dangerouslySetInnerHTML: {
2726
2820
  __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 "
2727
2821
  }
2728
2822
  }), /*#__PURE__*/React__namespace.createElement("div", {
2729
- style: {
2730
- position: 'absolute',
2731
- left: 0,
2732
- top: 0,
2733
- width: '100%',
2734
- height: '4px',
2735
- marginBottom: '-4px',
2736
- cursor: 'row-resize',
2737
- zIndex: 100000
2738
- },
2739
- onMouseDown: handleDragStart
2823
+ style: getResizeHandleStyle(position),
2824
+ onMouseDown: onDragStart
2740
2825
  }), isOpen && /*#__PURE__*/React__namespace.createElement("div", {
2741
2826
  style: {
2742
2827
  flex: '1 1 500px',
@@ -2779,9 +2864,31 @@
2779
2864
  display: 'flex',
2780
2865
  flexDirection: 'column'
2781
2866
  }
2867
+ }, /*#__PURE__*/React__namespace.createElement("div", {
2868
+ style: {
2869
+ display: 'flex',
2870
+ justifyContent: 'space-between',
2871
+ alignItems: 'center',
2872
+ marginBottom: '.5em'
2873
+ }
2782
2874
  }, /*#__PURE__*/React__namespace.createElement(QueryStatusCount, {
2783
2875
  queryCache: queryCache
2784
- }), /*#__PURE__*/React__namespace.createElement("div", {
2876
+ }), position && onPositionChange ? /*#__PURE__*/React__namespace.createElement(Select, {
2877
+ "aria-label": "Panel position",
2878
+ value: position,
2879
+ style: {
2880
+ marginInlineStart: '.5em'
2881
+ },
2882
+ onChange: e => onPositionChange(e.target.value)
2883
+ }, /*#__PURE__*/React__namespace.createElement("option", {
2884
+ value: "left"
2885
+ }, "Left"), /*#__PURE__*/React__namespace.createElement("option", {
2886
+ value: "right"
2887
+ }, "Right"), /*#__PURE__*/React__namespace.createElement("option", {
2888
+ value: "top"
2889
+ }, "Top"), /*#__PURE__*/React__namespace.createElement("option", {
2890
+ value: "bottom"
2891
+ }, "Bottom")) : null), /*#__PURE__*/React__namespace.createElement("div", {
2785
2892
  style: {
2786
2893
  display: 'flex',
2787
2894
  alignItems: 'center'
@@ -2897,7 +3004,25 @@
2897
3004
  activeQueryHash: activeQueryHash,
2898
3005
  queryCache: queryCache,
2899
3006
  queryClient: queryClient
2900
- }) : null));
3007
+ }) : null, showCloseButton ? /*#__PURE__*/React__namespace.createElement(Button, _extends({
3008
+ type: "button",
3009
+ "aria-controls": "ReactQueryDevtoolsPanel",
3010
+ "aria-haspopup": "true",
3011
+ "aria-expanded": "true"
3012
+ }, otherCloseButtonProps, {
3013
+ style: {
3014
+ position: 'absolute',
3015
+ zIndex: 99999,
3016
+ margin: '.5em',
3017
+ bottom: 0,
3018
+ left: 0,
3019
+ ...otherCloseButtonProps.style
3020
+ },
3021
+ onClick: e => {
3022
+ setIsOpen(false);
3023
+ onCloseClick == null ? void 0 : onCloseClick(e);
3024
+ }
3025
+ }), "Close") : null));
2901
3026
  });
2902
3027
 
2903
3028
  const ActiveQuery = ({
@@ -3072,11 +3197,7 @@
3072
3197
  const hasPaused = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => getQueryStatusLabel(q) === 'paused').length);
3073
3198
  const hasStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => getQueryStatusLabel(q) === 'stale').length);
3074
3199
  const hasInactive = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => getQueryStatusLabel(q) === 'inactive').length);
3075
- return /*#__PURE__*/React__namespace.createElement(QueryKeys, {
3076
- style: {
3077
- marginBottom: '.5em'
3078
- }
3079
- }, /*#__PURE__*/React__namespace.createElement(QueryKey, {
3200
+ return /*#__PURE__*/React__namespace.createElement(QueryKeys, null, /*#__PURE__*/React__namespace.createElement(QueryKey, {
3080
3201
  style: {
3081
3202
  background: defaultTheme.success,
3082
3203
  opacity: hasFresh ? 1 : 0.3