@tanstack/react-query-devtools 4.10.4 → 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,68 +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
- direction: 'ltr',
178
- position: 'fixed',
179
- bottom: '0',
180
- right: '0',
181
- zIndex: 99999,
182
- width: '100%',
183
- height: devtoolsHeight != null ? devtoolsHeight : 500,
184
- maxHeight: '90%',
185
- boxShadow: '0 0 20px rgba(0,0,0,.3)',
186
- borderTop: "1px solid " + theme.defaultTheme.gray,
187
- transformOrigin: 'top',
188
- // visibility will be toggled after transitions, but set initial state here
189
- visibility: isOpen ? 'visible' : 'hidden',
190
- ...panelStyle,
191
- ...(isResizing ? {
192
- transition: "none"
193
- } : {
194
- transition: "all .2s ease"
195
- }),
196
- ...(isResolvedOpen ? {
197
- opacity: 1,
198
- pointerEvents: 'all',
199
- transform: "translateY(0) scale(1)"
200
- } : {
201
- opacity: 0,
202
- pointerEvents: 'none',
203
- transform: "translateY(15px) scale(1.02)"
204
- })
205
- },
207
+ style: style,
206
208
  isOpen: isResolvedOpen,
207
209
  setIsOpen: setIsOpen,
208
- handleDragStart: e => handleDragStart(panelRef.current, e)
209
- })), isResolvedOpen ? /*#__PURE__*/React__namespace.createElement(styledComponents.Button, _rollupPluginBabelHelpers["extends"]({
210
- type: "button",
211
- "aria-controls": "ReactQueryDevtoolsPanel",
212
- "aria-haspopup": "true",
213
- "aria-expanded": "true"
214
- }, otherCloseButtonProps, {
215
- onClick: e => {
216
- setIsOpen(false);
217
- onCloseClick == null ? void 0 : onCloseClick(e);
218
- },
219
- style: {
220
- position: 'fixed',
221
- zIndex: 99999,
222
- margin: '.5em',
223
- bottom: 0,
224
- ...(position === 'top-right' ? {
225
- right: '0'
226
- } : position === 'top-left' ? {
227
- left: '0'
228
- } : position === 'bottom-right' ? {
229
- right: '0'
230
- } : {
231
- left: '0'
232
- }),
233
- ...closeButtonStyle
234
- }
235
- }), "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"]({
236
212
  type: "button"
237
213
  }, otherToggleButtonProps, {
238
214
  "aria-label": "Open React Query Devtools",
@@ -290,10 +266,18 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
290
266
  isOpen = true,
291
267
  styleNonce,
292
268
  setIsOpen,
293
- handleDragStart,
294
269
  context,
270
+ onDragStart,
271
+ onPositionChange,
272
+ showCloseButton,
273
+ position,
274
+ closeButtonProps = {},
295
275
  ...panelProps
296
276
  } = props;
277
+ const {
278
+ onClick: onCloseClick,
279
+ ...otherCloseButtonProps
280
+ } = closeButtonProps;
297
281
  const queryClient = reactQuery.useQueryClient({
298
282
  context
299
283
  });
@@ -323,23 +307,20 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
323
307
  className: "ReactQueryDevtoolsPanel",
324
308
  "aria-label": "React Query Devtools Panel",
325
309
  id: "ReactQueryDevtoolsPanel"
326
- }, 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", {
327
317
  nonce: styleNonce,
328
318
  dangerouslySetInnerHTML: {
329
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 "
330
320
  }
331
321
  }), /*#__PURE__*/React__namespace.createElement("div", {
332
- style: {
333
- position: 'absolute',
334
- left: 0,
335
- top: 0,
336
- width: '100%',
337
- height: '4px',
338
- marginBottom: '-4px',
339
- cursor: 'row-resize',
340
- zIndex: 100000
341
- },
342
- onMouseDown: handleDragStart
322
+ style: utils.getResizeHandleStyle(position),
323
+ onMouseDown: onDragStart
343
324
  }), isOpen && /*#__PURE__*/React__namespace.createElement("div", {
344
325
  style: {
345
326
  flex: '1 1 500px',
@@ -382,9 +363,31 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
382
363
  display: 'flex',
383
364
  flexDirection: 'column'
384
365
  }
366
+ }, /*#__PURE__*/React__namespace.createElement("div", {
367
+ style: {
368
+ display: 'flex',
369
+ justifyContent: 'space-between',
370
+ alignItems: 'center',
371
+ marginBottom: '.5em'
372
+ }
385
373
  }, /*#__PURE__*/React__namespace.createElement(QueryStatusCount, {
386
374
  queryCache: queryCache
387
- }), /*#__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", {
388
391
  style: {
389
392
  display: 'flex',
390
393
  alignItems: 'center'
@@ -500,7 +503,25 @@ const ReactQueryDevtoolsPanel = /*#__PURE__*/React__namespace.forwardRef(functio
500
503
  activeQueryHash: activeQueryHash,
501
504
  queryCache: queryCache,
502
505
  queryClient: queryClient
503
- }) : 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));
504
525
  });
505
526
 
506
527
  const ActiveQuery = ({
@@ -675,11 +696,7 @@ const QueryStatusCount = ({
675
696
  const hasPaused = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'paused').length);
676
697
  const hasStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'stale').length);
677
698
  const hasInactive = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().filter(q => utils.getQueryStatusLabel(q) === 'inactive').length);
678
- return /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKeys, {
679
- style: {
680
- marginBottom: '.5em'
681
- }
682
- }, /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
699
+ return /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKeys, null, /*#__PURE__*/React__namespace.createElement(styledComponents.QueryKey, {
683
700
  style: {
684
701
  background: theme.defaultTheme.success,
685
702
  opacity: hasFresh ? 1 : 0.3