@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.
@@ -8,8 +8,8 @@ var reactQuery = require('@tanstack/react-query');
8
8
  var matchSorterUtils = require('@tanstack/match-sorter-utils');
9
9
  var useLocalStorage = require('./useLocalStorage.js');
10
10
  var utils = require('./utils.js');
11
- var screenreader = require('./screenreader.js');
12
11
  var styledComponents = require('./styledComponents.js');
12
+ var screenreader = require('./screenreader.js');
13
13
  var theme = require('./theme.js');
14
14
  var Explorer = require('./Explorer.js');
15
15
  var Logo = require('./Logo.js');
@@ -43,33 +43,47 @@ function ReactQueryDevtools({
43
43
  position = 'bottom-left',
44
44
  containerElement: Container = 'aside',
45
45
  context,
46
- styleNonce
46
+ styleNonce,
47
+ panelPosition: initialPanelPosition = 'bottom'
47
48
  }) {
48
49
  const rootRef = React__namespace.useRef(null);
49
50
  const panelRef = React__namespace.useRef(null);
50
51
  const [isOpen, setIsOpen] = useLocalStorage["default"]('reactQueryDevtoolsOpen', initialIsOpen);
51
- const [devtoolsHeight, setDevtoolsHeight] = useLocalStorage["default"]('reactQueryDevtoolsHeight', null);
52
+ const [devtoolsHeight, setDevtoolsHeight] = useLocalStorage["default"]('reactQueryDevtoolsHeight', utils.defaultPanelSize);
53
+ const [devtoolsWidth, setDevtoolsWidth] = useLocalStorage["default"]('reactQueryDevtoolsWidth', utils.defaultPanelSize);
54
+ const [panelPosition = 'bottom', setPanelPosition] = useLocalStorage["default"]('reactQueryDevtoolsPanelPosition', initialPanelPosition);
52
55
  const [isResolvedOpen, setIsResolvedOpen] = React__namespace.useState(false);
53
56
  const [isResizing, setIsResizing] = React__namespace.useState(false);
54
57
  const isMounted = utils.useIsMounted();
55
58
 
56
59
  const handleDragStart = (panelElement, startEvent) => {
57
- var _panelElement$getBoun;
58
-
60
+ if (!panelElement) return;
59
61
  if (startEvent.button !== 0) return; // Only allow left click for drag
60
62
 
63
+ const isVertical = utils.isVerticalSide(panelPosition);
61
64
  setIsResizing(true);
62
- const dragInfo = {
63
- originalHeight: (_panelElement$getBoun = panelElement == null ? void 0 : panelElement.getBoundingClientRect().height) != null ? _panelElement$getBoun : 0,
64
- pageY: startEvent.pageY
65
- };
65
+ const {
66
+ height,
67
+ width
68
+ } = panelElement.getBoundingClientRect();
69
+ const startX = startEvent.clientX;
70
+ const startY = startEvent.clientY;
71
+ let newSize = 0;
66
72
 
67
73
  const run = moveEvent => {
68
- const delta = dragInfo.pageY - moveEvent.pageY;
69
- const newHeight = dragInfo.originalHeight + delta;
70
- setDevtoolsHeight(newHeight);
74
+ // prevent mouse selecting stuff with mouse drag
75
+ moveEvent.preventDefault(); // calculate the correct size based on mouse position and current panel position
76
+ // hint: it is different formula for the opposite sides
77
+
78
+ if (isVertical) {
79
+ newSize = width + (panelPosition === 'right' ? startX - moveEvent.clientX : moveEvent.clientX - startX);
80
+ setDevtoolsWidth(newSize);
81
+ } else {
82
+ newSize = height + (panelPosition === 'bottom' ? startY - moveEvent.clientY : moveEvent.clientY - startY);
83
+ setDevtoolsHeight(newSize);
84
+ }
71
85
 
72
- if (newHeight < 70) {
86
+ if (newSize < utils.minPanelSize) {
73
87
  setIsOpen(false);
74
88
  } else {
75
89
  setIsOpen(true);
@@ -77,13 +91,16 @@ function ReactQueryDevtools({
77
91
  };
78
92
 
79
93
  const unsub = () => {
80
- setIsResizing(false);
81
- document.removeEventListener('mousemove', run);
82
- document.removeEventListener('mouseUp', unsub);
94
+ if (isResizing) {
95
+ setIsResizing(false);
96
+ }
97
+
98
+ document.removeEventListener('mousemove', run, false);
99
+ document.removeEventListener('mouseUp', unsub, false);
83
100
  };
84
101
 
85
- document.addEventListener('mousemove', run);
86
- document.addEventListener('mouseup', unsub);
102
+ document.addEventListener('mousemove', run, false);
103
+ document.addEventListener('mouseup', unsub, false);
87
104
  };
88
105
 
89
106
  React__namespace.useEffect(() => {
@@ -120,15 +137,20 @@ function ReactQueryDevtools({
120
137
  var _root$parentElement;
121
138
 
122
139
  const root = rootRef.current;
123
- const previousValue = root == null ? void 0 : (_root$parentElement = root.parentElement) == null ? void 0 : _root$parentElement.style.paddingBottom;
140
+ const styleProp = utils.getSidedProp('padding', panelPosition);
141
+ const isVertical = utils.isVerticalSide(panelPosition);
142
+ const previousValue = root == null ? void 0 : (_root$parentElement = root.parentElement) == null ? void 0 : _root$parentElement.style[styleProp];
124
143
 
125
144
  const run = () => {
126
- var _panelRef$current;
127
-
128
- const containerHeight = (_panelRef$current = panelRef.current) == null ? void 0 : _panelRef$current.getBoundingClientRect().height;
129
-
130
145
  if (root != null && root.parentElement) {
131
- root.parentElement.style.paddingBottom = containerHeight + "px";
146
+ // reset the padding
147
+ root.parentElement.style.padding = '0px';
148
+ root.parentElement.style.paddingTop = '0px';
149
+ root.parentElement.style.paddingBottom = '0px';
150
+ root.parentElement.style.paddingLeft = '0px';
151
+ root.parentElement.style.paddingRight = '0px'; // set the new padding based on the new panel position
152
+
153
+ root.parentElement.style[styleProp] = (isVertical ? devtoolsWidth : devtoolsHeight) + "px";
132
154
  }
133
155
  };
134
156
 
@@ -140,26 +162,31 @@ function ReactQueryDevtools({
140
162
  window.removeEventListener('resize', run);
141
163
 
142
164
  if (root != null && root.parentElement && typeof previousValue === 'string') {
143
- root.parentElement.style.paddingBottom = previousValue;
165
+ root.parentElement.style[styleProp] = previousValue;
144
166
  }
145
167
  };
146
168
  }
147
169
  }
148
- }, [isResolvedOpen]);
170
+ }, [isResolvedOpen, panelPosition, devtoolsHeight, devtoolsWidth]);
149
171
  const {
150
172
  style: panelStyle = {},
151
173
  ...otherPanelProps
152
174
  } = panelProps;
153
- const {
154
- style: closeButtonStyle = {},
155
- onClick: onCloseClick,
156
- ...otherCloseButtonProps
157
- } = closeButtonProps;
158
175
  const {
159
176
  style: toggleButtonStyle = {},
160
177
  onClick: onToggleClick,
161
178
  ...otherToggleButtonProps
162
- } = toggleButtonProps; // Do not render on the server
179
+ } = toggleButtonProps; // get computed style based on panel position
180
+
181
+ const style = utils.getSidePanelStyle({
182
+ position: panelPosition,
183
+ devtoolsTheme: theme.defaultTheme,
184
+ isOpen: isResolvedOpen,
185
+ height: devtoolsHeight,
186
+ width: devtoolsWidth,
187
+ isResizing,
188
+ panelStyle
189
+ }); // Do not render on the server
163
190
 
164
191
  if (!isMounted()) return null;
165
192
  return /*#__PURE__*/React__namespace.createElement(Container, {
@@ -171,67 +198,17 @@ function ReactQueryDevtools({
171
198
  }, /*#__PURE__*/React__namespace.createElement(ReactQueryDevtoolsPanel, _rollupPluginBabelHelpers["extends"]({
172
199
  ref: panelRef,
173
200
  context: context,
174
- styleNonce: styleNonce
201
+ styleNonce: styleNonce,
202
+ position: panelPosition,
203
+ onPositionChange: setPanelPosition,
204
+ showCloseButton: true,
205
+ closeButtonProps: closeButtonProps
175
206
  }, otherPanelProps, {
176
- style: {
177
- position: 'fixed',
178
- bottom: '0',
179
- right: '0',
180
- zIndex: 99999,
181
- width: '100%',
182
- height: devtoolsHeight != null ? devtoolsHeight : 500,
183
- maxHeight: '90%',
184
- boxShadow: '0 0 20px rgba(0,0,0,.3)',
185
- borderTop: "1px solid " + theme.defaultTheme.gray,
186
- transformOrigin: 'top',
187
- // visibility will be toggled after transitions, but set initial state here
188
- visibility: isOpen ? 'visible' : 'hidden',
189
- ...panelStyle,
190
- ...(isResizing ? {
191
- transition: "none"
192
- } : {
193
- transition: "all .2s ease"
194
- }),
195
- ...(isResolvedOpen ? {
196
- opacity: 1,
197
- pointerEvents: 'all',
198
- transform: "translateY(0) scale(1)"
199
- } : {
200
- opacity: 0,
201
- pointerEvents: 'none',
202
- transform: "translateY(15px) scale(1.02)"
203
- })
204
- },
207
+ style: style,
205
208
  isOpen: isResolvedOpen,
206
209
  setIsOpen: setIsOpen,
207
- handleDragStart: e => handleDragStart(panelRef.current, e)
208
- })), isResolvedOpen ? /*#__PURE__*/React__namespace.createElement(styledComponents.Button, _rollupPluginBabelHelpers["extends"]({
209
- type: "button",
210
- "aria-controls": "ReactQueryDevtoolsPanel",
211
- "aria-haspopup": "true",
212
- "aria-expanded": "true"
213
- }, otherCloseButtonProps, {
214
- onClick: e => {
215
- setIsOpen(false);
216
- onCloseClick == null ? void 0 : onCloseClick(e);
217
- },
218
- style: {
219
- position: 'fixed',
220
- zIndex: 99999,
221
- margin: '.5em',
222
- bottom: 0,
223
- ...(position === 'top-right' ? {
224
- right: '0'
225
- } : position === 'top-left' ? {
226
- left: '0'
227
- } : position === 'bottom-right' ? {
228
- right: '0'
229
- } : {
230
- left: '0'
231
- }),
232
- ...closeButtonStyle
233
- }
234
- }), "Close") : null), !isResolvedOpen ? /*#__PURE__*/React__namespace.createElement("button", _rollupPluginBabelHelpers["extends"]({
210
+ onDragStart: e => handleDragStart(panelRef.current, e)
211
+ }))), !isResolvedOpen ? /*#__PURE__*/React__namespace.createElement("button", _rollupPluginBabelHelpers["extends"]({
235
212
  type: "button"
236
213
  }, otherToggleButtonProps, {
237
214
  "aria-label": "Open React Query Devtools",
@@ -289,10 +266,18 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
289
266
  isOpen = true,
290
267
  styleNonce,
291
268
  setIsOpen,
292
- handleDragStart,
293
269
  context,
270
+ onDragStart,
271
+ onPositionChange,
272
+ showCloseButton,
273
+ position,
274
+ closeButtonProps = {},
294
275
  ...panelProps
295
276
  } = props;
277
+ const {
278
+ onClick: onCloseClick,
279
+ ...otherCloseButtonProps
280
+ } = closeButtonProps;
296
281
  const queryClient = reactQuery.useQueryClient({
297
282
  context
298
283
  });
@@ -322,23 +307,20 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
322
307
  className: "ReactQueryDevtoolsPanel",
323
308
  "aria-label": "React Query Devtools Panel",
324
309
  id: "ReactQueryDevtoolsPanel"
325
- }, panelProps), /*#__PURE__*/React__namespace.createElement("style", {
310
+ }, panelProps, {
311
+ style: {
312
+ height: utils.defaultPanelSize,
313
+ position: 'relative',
314
+ ...panelProps.style
315
+ }
316
+ }), /*#__PURE__*/React__namespace.createElement("style", {
326
317
  nonce: styleNonce,
327
318
  dangerouslySetInnerHTML: {
328
319
  __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 "
329
320
  }
330
321
  }), /*#__PURE__*/React__namespace.createElement("div", {
331
- style: {
332
- position: 'absolute',
333
- left: 0,
334
- top: 0,
335
- width: '100%',
336
- height: '4px',
337
- marginBottom: '-4px',
338
- cursor: 'row-resize',
339
- zIndex: 100000
340
- },
341
- onMouseDown: handleDragStart
322
+ style: utils.getResizeHandleStyle(position),
323
+ onMouseDown: onDragStart
342
324
  }), isOpen && /*#__PURE__*/React__namespace.createElement("div", {
343
325
  style: {
344
326
  flex: '1 1 500px',
@@ -381,9 +363,31 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
381
363
  display: 'flex',
382
364
  flexDirection: 'column'
383
365
  }
366
+ }, /*#__PURE__*/React__namespace.createElement("div", {
367
+ style: {
368
+ display: 'flex',
369
+ justifyContent: 'space-between',
370
+ alignItems: 'center',
371
+ marginBottom: '.5em'
372
+ }
384
373
  }, /*#__PURE__*/React__namespace.createElement(QueryStatusCount, {
385
374
  queryCache: queryCache
386
- }), /*#__PURE__*/React__namespace.createElement("div", {
375
+ }), position && onPositionChange ? /*#__PURE__*/React__namespace.createElement(styledComponents.Select, {
376
+ "aria-label": "Panel position",
377
+ value: position,
378
+ style: {
379
+ marginInlineStart: '.5em'
380
+ },
381
+ onChange: e => onPositionChange(e.target.value)
382
+ }, /*#__PURE__*/React__namespace.createElement("option", {
383
+ value: "left"
384
+ }, "Left"), /*#__PURE__*/React__namespace.createElement("option", {
385
+ value: "right"
386
+ }, "Right"), /*#__PURE__*/React__namespace.createElement("option", {
387
+ value: "top"
388
+ }, "Top"), /*#__PURE__*/React__namespace.createElement("option", {
389
+ value: "bottom"
390
+ }, "Bottom")) : null), /*#__PURE__*/React__namespace.createElement("div", {
387
391
  style: {
388
392
  display: 'flex',
389
393
  alignItems: 'center'
@@ -499,7 +503,25 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
499
503
  activeQueryHash: activeQueryHash,
500
504
  queryCache: queryCache,
501
505
  queryClient: queryClient
502
- }) : null));
506
+ }) : null, showCloseButton ? /*#__PURE__*/React__namespace.createElement(styledComponents.Button, _rollupPluginBabelHelpers["extends"]({
507
+ type: "button",
508
+ "aria-controls": "ReactQueryDevtoolsPanel",
509
+ "aria-haspopup": "true",
510
+ "aria-expanded": "true"
511
+ }, otherCloseButtonProps, {
512
+ style: {
513
+ position: 'absolute',
514
+ zIndex: 99999,
515
+ margin: '.5em',
516
+ bottom: 0,
517
+ left: 0,
518
+ ...otherCloseButtonProps.style
519
+ },
520
+ onClick: e => {
521
+ setIsOpen(false);
522
+ onCloseClick == null ? void 0 : onCloseClick(e);
523
+ }
524
+ }), "Close") : null));
503
525
  });
504
526
 
505
527
  const ActiveQuery = ({
@@ -674,11 +696,7 @@ const QueryStatusCount = ({
674
696
  const hasPaused = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'paused').length);
675
697
  const hasStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'stale').length);
676
698
  const hasInactive = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'inactive').length);
677
- return /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKeys, {
678
- style: {
679
- marginBottom: '.5em'
680
- }
681
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
699
+ return /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKeys, null, /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
682
700
  style: {
683
701
  background: theme.defaultTheme.success,
684
702
  opacity: hasFresh ? 1 : 0.3