@tanstack/react-query-devtools 5.0.0-alpha.25 → 5.0.0-alpha.27
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.
- package/build/lib/__tests__/devtools.test.d.ts +0 -1
- package/build/lib/__tests__/devtools.test.d.ts.map +1 -0
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/devtools.d.ts +8 -30
- package/build/lib/devtools.d.ts.map +1 -0
- package/build/lib/devtools.esm.js +47 -226
- package/build/lib/devtools.esm.js.map +1 -1
- package/build/lib/devtools.js +45 -244
- package/build/lib/devtools.js.map +1 -1
- package/build/lib/devtools.mjs +47 -225
- package/build/lib/devtools.mjs.map +1 -1
- package/build/lib/index.d.ts +0 -1
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.esm.js +8 -5
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +7 -5
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +8 -5
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/index.prod.d.ts +0 -1
- package/build/lib/index.prod.esm.js +7901 -1501
- package/build/lib/index.prod.esm.js.map +1 -1
- package/build/lib/index.prod.js +7909 -1528
- package/build/lib/index.prod.js.map +1 -1
- package/build/lib/index.prod.mjs +7922 -1489
- package/build/lib/index.prod.mjs.map +1 -1
- package/build/umd/index.development.js +7146 -2375
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +4 -5
- package/src/__tests__/devtools.test.tsx +1 -1135
- package/src/devtools.tsx +52 -306
- package/src/index.ts +6 -6
- package/build/lib/CachePanel/ActiveQuery.d.ts +0 -19
- package/build/lib/CachePanel/ActiveQuery.esm.js +0 -277
- package/build/lib/CachePanel/ActiveQuery.esm.js.map +0 -1
- package/build/lib/CachePanel/ActiveQuery.js +0 -281
- package/build/lib/CachePanel/ActiveQuery.js.map +0 -1
- package/build/lib/CachePanel/ActiveQuery.mjs +0 -261
- package/build/lib/CachePanel/ActiveQuery.mjs.map +0 -1
- package/build/lib/CachePanel/CachePanel.d.ts +0 -58
- package/build/lib/CachePanel/CachePanel.esm.js +0 -310
- package/build/lib/CachePanel/CachePanel.esm.js.map +0 -1
- package/build/lib/CachePanel/CachePanel.js +0 -315
- package/build/lib/CachePanel/CachePanel.js.map +0 -1
- package/build/lib/CachePanel/CachePanel.mjs +0 -310
- package/build/lib/CachePanel/CachePanel.mjs.map +0 -1
- package/build/lib/CachePanel/Header/QueryStatusCount.d.ts +0 -8
- package/build/lib/CachePanel/Header/QueryStatusCount.esm.js +0 -49
- package/build/lib/CachePanel/Header/QueryStatusCount.esm.js.map +0 -1
- package/build/lib/CachePanel/Header/QueryStatusCount.js +0 -53
- package/build/lib/CachePanel/Header/QueryStatusCount.js.map +0 -1
- package/build/lib/CachePanel/Header/QueryStatusCount.mjs +0 -49
- package/build/lib/CachePanel/Header/QueryStatusCount.mjs.map +0 -1
- package/build/lib/CachePanel/QueryRow.d.ts +0 -14
- package/build/lib/CachePanel/QueryRow.esm.js +0 -98
- package/build/lib/CachePanel/QueryRow.esm.js.map +0 -1
- package/build/lib/CachePanel/QueryRow.js +0 -102
- package/build/lib/CachePanel/QueryRow.js.map +0 -1
- package/build/lib/CachePanel/QueryRow.mjs +0 -82
- package/build/lib/CachePanel/QueryRow.mjs.map +0 -1
- package/build/lib/Explorer.d.ts +0 -51
- package/build/lib/Explorer.esm.js +0 -254
- package/build/lib/Explorer.esm.js.map +0 -1
- package/build/lib/Explorer.js +0 -288
- package/build/lib/Explorer.js.map +0 -1
- package/build/lib/Explorer.mjs +0 -254
- package/build/lib/Explorer.mjs.map +0 -1
- package/build/lib/Logo.d.ts +0 -2
- package/build/lib/Logo.esm.js +0 -32
- package/build/lib/Logo.esm.js.map +0 -1
- package/build/lib/Logo.js +0 -55
- package/build/lib/Logo.js.map +0 -1
- package/build/lib/Logo.mjs +0 -32
- package/build/lib/Logo.mjs.map +0 -1
- package/build/lib/__tests__/Explorer.test.d.ts +0 -2
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -17
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -19
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -17
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +0 -1
- package/build/lib/noop.d.ts +0 -3
- package/build/lib/screenreader.d.ts +0 -4
- package/build/lib/screenreader.esm.js +0 -17
- package/build/lib/screenreader.esm.js.map +0 -1
- package/build/lib/screenreader.js +0 -40
- package/build/lib/screenreader.js.map +0 -1
- package/build/lib/screenreader.mjs +0 -17
- package/build/lib/screenreader.mjs.map +0 -1
- package/build/lib/styledComponents.d.ts +0 -9
- package/build/lib/styledComponents.esm.js +0 -103
- package/build/lib/styledComponents.esm.js.map +0 -1
- package/build/lib/styledComponents.js +0 -112
- package/build/lib/styledComponents.js.map +0 -1
- package/build/lib/styledComponents.mjs +0 -103
- package/build/lib/styledComponents.mjs.map +0 -1
- package/build/lib/theme.d.ts +0 -37
- package/build/lib/theme.esm.js +0 -33
- package/build/lib/theme.esm.js.map +0 -1
- package/build/lib/theme.js +0 -56
- package/build/lib/theme.js.map +0 -1
- package/build/lib/theme.mjs +0 -33
- package/build/lib/theme.mjs.map +0 -1
- package/build/lib/types.d.ts +0 -12
- package/build/lib/useLocalStorage.d.ts +0 -2
- package/build/lib/useLocalStorage.esm.js +0 -40
- package/build/lib/useLocalStorage.esm.js.map +0 -1
- package/build/lib/useLocalStorage.js +0 -63
- package/build/lib/useLocalStorage.js.map +0 -1
- package/build/lib/useLocalStorage.mjs +0 -40
- package/build/lib/useLocalStorage.mjs.map +0 -1
- package/build/lib/useMediaQuery.d.ts +0 -2
- package/build/lib/useMediaQuery.esm.js +0 -36
- package/build/lib/useMediaQuery.esm.js.map +0 -1
- package/build/lib/useMediaQuery.js +0 -59
- package/build/lib/useMediaQuery.js.map +0 -1
- package/build/lib/useMediaQuery.mjs +0 -36
- package/build/lib/useMediaQuery.mjs.map +0 -1
- package/build/lib/useSubscribeToQueryCache.d.ts +0 -4
- package/build/lib/useSubscribeToQueryCache.esm.js +0 -15
- package/build/lib/useSubscribeToQueryCache.esm.js.map +0 -1
- package/build/lib/useSubscribeToQueryCache.js +0 -19
- package/build/lib/useSubscribeToQueryCache.js.map +0 -1
- package/build/lib/useSubscribeToQueryCache.mjs +0 -15
- package/build/lib/useSubscribeToQueryCache.mjs.map +0 -1
- package/build/lib/utils.d.ts +0 -80
- package/build/lib/utils.esm.js +0 -184
- package/build/lib/utils.esm.js.map +0 -1
- package/build/lib/utils.js +0 -218
- package/build/lib/utils.js.map +0 -1
- package/build/lib/utils.mjs +0 -184
- package/build/lib/utils.mjs.map +0 -1
- package/src/CachePanel/ActiveQuery.tsx +0 -388
- package/src/CachePanel/CachePanel.tsx +0 -439
- package/src/CachePanel/Header/QueryStatusCount.tsx +0 -93
- package/src/CachePanel/QueryRow.tsx +0 -125
- package/src/Explorer.tsx +0 -385
- package/src/Logo.tsx +0 -32
- package/src/__tests__/Explorer.test.tsx +0 -150
- package/src/noop.ts +0 -7
- package/src/screenreader.tsx +0 -16
- package/src/styledComponents.ts +0 -126
- package/src/theme.tsx +0 -33
- package/src/types.ts +0 -12
- package/src/useLocalStorage.ts +0 -52
- package/src/useMediaQuery.ts +0 -34
- package/src/useSubscribeToQueryCache.ts +0 -26
- package/src/utils.ts +0 -319
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/devtools.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACnE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,OAAO,EACL,WAAW,EAEX,UAAU,EACX,MAAM,uBAAuB,CAAA;AAE9B,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,KAAK,CAAC,YAAY,EACtB,eAAe,GAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAM,EACnE,aAAa,CAAC,EAAE,aAAa,GAC5B,UAAU,CAAC,OAAO,MAAM,CAAC,CAkB3B;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD;AAED;;;;;;;GAOG;AAEH,aAAK,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,OAAO,CAAA;AAE5E,eAAO,MAAM,gBAAgB,gBACb,MAAM,KAAG,eAatB,CAAA;AAEH,UAAU,yBAAyB;IACjC,WAAW,EAAE,WAAW,CAAA;IACxB,UAAU,EAAE,UAAU,CAAA;CACvB;AAED,eAAO,MAAM,iBAAiB,QAAO,yBAWpC,CAAA"}
|
package/build/lib/devtools.d.ts
CHANGED
|
@@ -1,53 +1,31 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import type { QueryClient } from '@tanstack/react-query';
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
export { default as ReactQueryDevtoolsPanel } from './CachePanel/CachePanel';
|
|
2
|
+
import type { DevtoolsButtonPosition, DevtoolsPosition, DevToolsErrorType } from '@tanstack/query-devtools';
|
|
3
|
+
import React from 'react';
|
|
6
4
|
export interface DevtoolsOptions {
|
|
7
5
|
/**
|
|
8
6
|
* Set this true if you want the dev tools to default to being open
|
|
9
7
|
*/
|
|
10
8
|
initialIsOpen?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Use this to add props to the panel. For example, you can add className, style (merge and override default style), etc.
|
|
13
|
-
*/
|
|
14
|
-
panelProps?: React.ComponentPropsWithoutRef<'div'>;
|
|
15
|
-
/**
|
|
16
|
-
* Use this to add props to the close button. For example, you can add className, style (merge and override default style), onClick (extend default handler), etc.
|
|
17
|
-
*/
|
|
18
|
-
closeButtonProps?: React.ComponentPropsWithoutRef<'button'>;
|
|
19
|
-
/**
|
|
20
|
-
* Use this to add props to the toggle button. For example, you can add className, style (merge and override default style), onClick (extend default handler), etc.
|
|
21
|
-
*/
|
|
22
|
-
toggleButtonProps?: React.ComponentPropsWithoutRef<'button'>;
|
|
23
9
|
/**
|
|
24
10
|
* The position of the React Query logo to open and close the devtools panel.
|
|
11
|
+
* 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
|
25
12
|
* Defaults to 'bottom-left'.
|
|
26
13
|
*/
|
|
27
|
-
|
|
14
|
+
buttonPosition?: DevtoolsButtonPosition;
|
|
28
15
|
/**
|
|
29
16
|
* The position of the React Query devtools panel.
|
|
17
|
+
* 'top' | 'bottom' | 'left' | 'right'
|
|
30
18
|
* Defaults to 'bottom'.
|
|
31
19
|
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Use this to render the devtools inside a different type of container element for a11y purposes.
|
|
35
|
-
* Any string which corresponds to a valid intrinsic JSX element is allowed.
|
|
36
|
-
* Defaults to 'aside'.
|
|
37
|
-
*/
|
|
38
|
-
containerElement?: string | any;
|
|
39
|
-
/**
|
|
40
|
-
* nonce for style element for CSP
|
|
41
|
-
*/
|
|
42
|
-
styleNonce?: string;
|
|
20
|
+
position?: DevtoolsPosition;
|
|
43
21
|
/**
|
|
44
22
|
* Custom instance of QueryClient
|
|
45
23
|
*/
|
|
46
|
-
|
|
24
|
+
client?: QueryClient;
|
|
47
25
|
/**
|
|
48
26
|
* Use this so you can define custom errors that can be shown in the devtools.
|
|
49
27
|
*/
|
|
50
28
|
errorTypes?: DevToolsErrorType[];
|
|
51
29
|
}
|
|
52
|
-
export declare function ReactQueryDevtools(
|
|
30
|
+
export declare function ReactQueryDevtools(props: DevtoolsOptions): React.ReactElement | null;
|
|
53
31
|
//# sourceMappingURL=devtools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../../src/devtools.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;OAIG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAA;IACvC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;OAEG;IACH,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAA;CACjC;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,eAAe,GACrB,KAAK,CAAC,YAAY,GAAG,IAAI,CAgD3B"}
|
|
@@ -1,234 +1,55 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { defaultPanelSize, useIsMounted, getSidedProp, getSidePanelStyle, isVerticalSide, minPanelSize } from './utils.esm.js';
|
|
6
|
-
import ScreenReader from './screenreader.esm.js';
|
|
7
|
-
import { defaultTheme, ThemeProvider } from './theme.esm.js';
|
|
8
|
-
import Logo from './Logo.esm.js';
|
|
9
|
-
import ReactQueryDevtoolsPanel from './CachePanel/CachePanel.esm.js';
|
|
2
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
3
|
+
import { useQueryClient, onlineManager } from '@tanstack/react-query';
|
|
4
|
+
import { TanstackQueryDevtools } from '@tanstack/query-devtools';
|
|
10
5
|
|
|
11
|
-
function ReactQueryDevtools({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!panelElement) return;
|
|
34
|
-
if (startEvent.button !== 0) return; // Only allow left click for drag
|
|
35
|
-
const isVertical = isVerticalSide(panelPosition);
|
|
36
|
-
setIsResizing(true);
|
|
37
|
-
const {
|
|
38
|
-
height,
|
|
39
|
-
width
|
|
40
|
-
} = panelElement.getBoundingClientRect();
|
|
41
|
-
const startX = startEvent.clientX;
|
|
42
|
-
const startY = startEvent.clientY;
|
|
43
|
-
let newSize = 0;
|
|
44
|
-
const run = moveEvent => {
|
|
45
|
-
// prevent mouse selecting stuff with mouse drag
|
|
46
|
-
moveEvent.preventDefault();
|
|
47
|
-
|
|
48
|
-
// calculate the correct size based on mouse position and current panel position
|
|
49
|
-
// hint: it is different formula for the opposite sides
|
|
50
|
-
if (isVertical) {
|
|
51
|
-
newSize = width + (panelPosition === 'right' ? startX - moveEvent.clientX : moveEvent.clientX - startX);
|
|
52
|
-
setDevtoolsWidth(newSize);
|
|
53
|
-
} else {
|
|
54
|
-
newSize = height + (panelPosition === 'bottom' ? startY - moveEvent.clientY : moveEvent.clientY - startY);
|
|
55
|
-
setDevtoolsHeight(newSize);
|
|
56
|
-
}
|
|
57
|
-
if (newSize < minPanelSize) {
|
|
58
|
-
setIsOpen(false);
|
|
59
|
-
} else {
|
|
60
|
-
setIsOpen(true);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const unsub = () => {
|
|
64
|
-
if (isResizing) {
|
|
65
|
-
setIsResizing(false);
|
|
66
|
-
}
|
|
67
|
-
document.removeEventListener('mousemove', run, false);
|
|
68
|
-
document.removeEventListener('mouseUp', unsub, false);
|
|
69
|
-
};
|
|
70
|
-
document.addEventListener('mousemove', run, false);
|
|
71
|
-
document.addEventListener('mouseup', unsub, false);
|
|
72
|
-
};
|
|
73
|
-
React.useEffect(() => {
|
|
74
|
-
setIsResolvedOpen(isOpen != null ? isOpen : false);
|
|
75
|
-
}, [isOpen, isResolvedOpen, setIsResolvedOpen]);
|
|
76
|
-
|
|
77
|
-
// Toggle panel visibility before/after transition (depending on direction).
|
|
78
|
-
// Prevents focusing in a closed panel.
|
|
79
|
-
React.useEffect(() => {
|
|
80
|
-
const ref = panelRef.current;
|
|
81
|
-
if (ref) {
|
|
82
|
-
const handlePanelTransitionStart = () => {
|
|
83
|
-
if (isResolvedOpen) {
|
|
84
|
-
ref.style.visibility = 'visible';
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const handlePanelTransitionEnd = () => {
|
|
88
|
-
if (!isResolvedOpen) {
|
|
89
|
-
ref.style.visibility = 'hidden';
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
ref.addEventListener('transitionstart', handlePanelTransitionStart);
|
|
93
|
-
ref.addEventListener('transitionend', handlePanelTransitionEnd);
|
|
94
|
-
return () => {
|
|
95
|
-
ref.removeEventListener('transitionstart', handlePanelTransitionStart);
|
|
96
|
-
ref.removeEventListener('transitionend', handlePanelTransitionEnd);
|
|
97
|
-
};
|
|
6
|
+
function ReactQueryDevtools(props) {
|
|
7
|
+
const queryClient = useQueryClient();
|
|
8
|
+
const ref = useRef(null);
|
|
9
|
+
const {
|
|
10
|
+
buttonPosition,
|
|
11
|
+
position,
|
|
12
|
+
initialIsOpen,
|
|
13
|
+
errorTypes
|
|
14
|
+
} = props;
|
|
15
|
+
const [devtools] = useState(new TanstackQueryDevtools({
|
|
16
|
+
client: props.client || queryClient,
|
|
17
|
+
queryFlavor: 'React Query',
|
|
18
|
+
version: '5',
|
|
19
|
+
onlineManager,
|
|
20
|
+
buttonPosition,
|
|
21
|
+
position,
|
|
22
|
+
initialIsOpen,
|
|
23
|
+
errorTypes
|
|
24
|
+
}));
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (buttonPosition) {
|
|
27
|
+
devtools.setButtonPosition(buttonPosition);
|
|
98
28
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (isResolvedOpen && (_rootRef$current = rootRef.current) != null && _rootRef$current.parentElement) {
|
|
104
|
-
const {
|
|
105
|
-
parentElement
|
|
106
|
-
} = rootRef.current;
|
|
107
|
-
const styleProp = getSidedProp('padding', panelPosition);
|
|
108
|
-
const isVertical = isVerticalSide(panelPosition);
|
|
109
|
-
const previousPaddings = (({
|
|
110
|
-
padding,
|
|
111
|
-
paddingTop,
|
|
112
|
-
paddingBottom,
|
|
113
|
-
paddingLeft,
|
|
114
|
-
paddingRight
|
|
115
|
-
}) => ({
|
|
116
|
-
padding,
|
|
117
|
-
paddingTop,
|
|
118
|
-
paddingBottom,
|
|
119
|
-
paddingLeft,
|
|
120
|
-
paddingRight
|
|
121
|
-
}))(parentElement.style);
|
|
122
|
-
const run = () => {
|
|
123
|
-
// reset the padding
|
|
124
|
-
parentElement.style.padding = '0px';
|
|
125
|
-
parentElement.style.paddingTop = '0px';
|
|
126
|
-
parentElement.style.paddingBottom = '0px';
|
|
127
|
-
parentElement.style.paddingLeft = '0px';
|
|
128
|
-
parentElement.style.paddingRight = '0px';
|
|
129
|
-
// set the new padding based on the new panel position
|
|
130
|
-
|
|
131
|
-
parentElement.style[styleProp] = `${isVertical ? devtoolsWidth : devtoolsHeight}px`;
|
|
132
|
-
};
|
|
133
|
-
run();
|
|
134
|
-
if (typeof window !== 'undefined') {
|
|
135
|
-
window.addEventListener('resize', run);
|
|
136
|
-
return () => {
|
|
137
|
-
window.removeEventListener('resize', run);
|
|
138
|
-
Object.entries(previousPaddings).forEach(([property, previousValue]) => {
|
|
139
|
-
parentElement.style[property] = previousValue;
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
}
|
|
29
|
+
}, [buttonPosition, devtools]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (position) {
|
|
32
|
+
devtools.setPosition(position);
|
|
143
33
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} = toggleButtonProps;
|
|
155
|
-
|
|
156
|
-
// get computed style based on panel position
|
|
157
|
-
const style = getSidePanelStyle({
|
|
158
|
-
position: panelPosition,
|
|
159
|
-
devtoolsTheme: defaultTheme,
|
|
160
|
-
isOpen: isResolvedOpen,
|
|
161
|
-
height: devtoolsHeight,
|
|
162
|
-
width: devtoolsWidth,
|
|
163
|
-
isResizing,
|
|
164
|
-
panelStyle
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Do not render on the server
|
|
168
|
-
if (!isMounted()) return null;
|
|
169
|
-
return /*#__PURE__*/React.createElement(Container, {
|
|
170
|
-
ref: rootRef,
|
|
171
|
-
className: "ReactQueryDevtools",
|
|
172
|
-
"aria-label": "React Query Devtools"
|
|
173
|
-
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
174
|
-
theme: defaultTheme
|
|
175
|
-
}, /*#__PURE__*/React.createElement(ReactQueryDevtoolsPanel, _extends({
|
|
176
|
-
ref: panelRef,
|
|
177
|
-
queryClient: queryClient,
|
|
178
|
-
styleNonce: styleNonce,
|
|
179
|
-
position: panelPosition,
|
|
180
|
-
onPositionChange: setPanelPosition,
|
|
181
|
-
showCloseButton: true,
|
|
182
|
-
closeButtonProps: closeButtonProps
|
|
183
|
-
}, otherPanelProps, {
|
|
184
|
-
style: style,
|
|
185
|
-
isOpen: isResolvedOpen,
|
|
186
|
-
setIsOpen: setIsOpen,
|
|
187
|
-
onDragStart: e => handleDragStart(panelRef.current, e),
|
|
188
|
-
errorTypes: errorTypes
|
|
189
|
-
}))), !isResolvedOpen ? /*#__PURE__*/React.createElement("button", _extends({
|
|
190
|
-
type: "button"
|
|
191
|
-
}, otherToggleButtonProps, {
|
|
192
|
-
"aria-label": "Open React Query Devtools",
|
|
193
|
-
"aria-controls": "ReactQueryDevtoolsPanel",
|
|
194
|
-
"aria-haspopup": "true",
|
|
195
|
-
"aria-expanded": "false",
|
|
196
|
-
onClick: e => {
|
|
197
|
-
setIsOpen(true);
|
|
198
|
-
onToggleClick == null ? void 0 : onToggleClick(e);
|
|
199
|
-
},
|
|
200
|
-
style: {
|
|
201
|
-
background: 'none',
|
|
202
|
-
border: 0,
|
|
203
|
-
padding: 0,
|
|
204
|
-
position: 'fixed',
|
|
205
|
-
zIndex: 99999,
|
|
206
|
-
display: 'inline-flex',
|
|
207
|
-
fontSize: '1.5em',
|
|
208
|
-
margin: '.5em',
|
|
209
|
-
cursor: 'pointer',
|
|
210
|
-
width: 'fit-content',
|
|
211
|
-
...(position === 'top-right' ? {
|
|
212
|
-
top: '0',
|
|
213
|
-
right: '0'
|
|
214
|
-
} : position === 'top-left' ? {
|
|
215
|
-
top: '0',
|
|
216
|
-
left: '0'
|
|
217
|
-
} : position === 'bottom-right' ? {
|
|
218
|
-
bottom: '0',
|
|
219
|
-
right: '0'
|
|
220
|
-
} : {
|
|
221
|
-
bottom: '0',
|
|
222
|
-
left: '0'
|
|
223
|
-
}),
|
|
224
|
-
...toggleButtonStyle
|
|
34
|
+
}, [position, devtools]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
devtools.setInitialIsOpen(initialIsOpen || false);
|
|
37
|
+
}, [initialIsOpen, devtools]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
devtools.setErrorTypes(errorTypes || []);
|
|
40
|
+
}, [errorTypes, devtools]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (ref.current) {
|
|
43
|
+
devtools.mount(ref.current);
|
|
225
44
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
45
|
+
return () => {
|
|
46
|
+
devtools.unmount();
|
|
47
|
+
};
|
|
48
|
+
}, [devtools]);
|
|
49
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
50
|
+
ref: ref
|
|
51
|
+
});
|
|
231
52
|
}
|
|
232
53
|
|
|
233
|
-
export { ReactQueryDevtools
|
|
54
|
+
export { ReactQueryDevtools };
|
|
234
55
|
//# sourceMappingURL=devtools.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.esm.js","sources":["../../src/devtools.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport type { QueryClient } from '@tanstack/react-query'\nimport useLocalStorage from './useLocalStorage'\nimport {\n isVerticalSide,\n useIsMounted,\n getSidePanelStyle,\n minPanelSize,\n getSidedProp,\n defaultPanelSize,\n} from './utils'\nimport type { Corner, Side } from './utils'\nimport ScreenReader from './screenreader'\nimport { ThemeProvider, defaultTheme as theme } from './theme'\nimport Logo from './Logo'\n\nimport type { DevToolsErrorType } from './types'\nimport ReactQueryDevtoolsPanel from './CachePanel/CachePanel'\n\nexport { default as ReactQueryDevtoolsPanel } from './CachePanel/CachePanel'\n\nexport interface DevtoolsOptions {\n /**\n * Set this true if you want the dev tools to default to being open\n */\n initialIsOpen?: boolean\n /**\n * Use this to add props to the panel. For example, you can add className, style (merge and override default style), etc.\n */\n panelProps?: React.ComponentPropsWithoutRef<'div'>\n /**\n * Use this to add props to the close button. For example, you can add className, style (merge and override default style), onClick (extend default handler), etc.\n */\n closeButtonProps?: React.ComponentPropsWithoutRef<'button'>\n /**\n * Use this to add props to the toggle button. For example, you can add className, style (merge and override default style), onClick (extend default handler), etc.\n */\n toggleButtonProps?: React.ComponentPropsWithoutRef<'button'>\n /**\n * The position of the React Query logo to open and close the devtools panel.\n * Defaults to 'bottom-left'.\n */\n position?: Corner\n /**\n * The position of the React Query devtools panel.\n * Defaults to 'bottom'.\n */\n panelPosition?: Side\n /**\n * Use this to render the devtools inside a different type of container element for a11y purposes.\n * Any string which corresponds to a valid intrinsic JSX element is allowed.\n * Defaults to 'aside'.\n */\n containerElement?: string | any\n /**\n * nonce for style element for CSP\n */\n styleNonce?: string\n /**\n * Custom instance of QueryClient\n */\n queryClient?: QueryClient\n /**\n * Use this so you can define custom errors that can be shown in the devtools.\n */\n errorTypes?: DevToolsErrorType[]\n}\n\nexport function ReactQueryDevtools({\n initialIsOpen,\n panelProps = {},\n closeButtonProps = {},\n toggleButtonProps = {},\n position = 'bottom-left',\n containerElement: Container = 'aside',\n queryClient,\n styleNonce,\n panelPosition: initialPanelPosition = 'bottom',\n errorTypes = [],\n}: DevtoolsOptions): React.ReactElement | null {\n const rootRef = React.useRef<HTMLDivElement>(null)\n const panelRef = React.useRef<HTMLDivElement>(null)\n const [isOpen, setIsOpen] = useLocalStorage(\n 'reactQueryDevtoolsOpen',\n initialIsOpen,\n )\n const [devtoolsHeight, setDevtoolsHeight] = useLocalStorage<number>(\n 'reactQueryDevtoolsHeight',\n defaultPanelSize,\n )\n const [devtoolsWidth, setDevtoolsWidth] = useLocalStorage<number>(\n 'reactQueryDevtoolsWidth',\n defaultPanelSize,\n )\n\n const [panelPosition = 'bottom', setPanelPosition] = useLocalStorage<Side>(\n 'reactQueryDevtoolsPanelPosition',\n initialPanelPosition,\n )\n\n const [isResolvedOpen, setIsResolvedOpen] = React.useState(false)\n const [isResizing, setIsResizing] = React.useState(false)\n const isMounted = useIsMounted()\n\n const handleDragStart = (\n panelElement: HTMLDivElement | null,\n startEvent: React.MouseEvent<HTMLDivElement, MouseEvent>,\n ) => {\n if (!panelElement) return\n if (startEvent.button !== 0) return // Only allow left click for drag\n const isVertical = isVerticalSide(panelPosition)\n setIsResizing(true)\n\n const { height, width } = panelElement.getBoundingClientRect()\n const startX = startEvent.clientX\n const startY = startEvent.clientY\n let newSize = 0\n\n const run = (moveEvent: MouseEvent) => {\n // prevent mouse selecting stuff with mouse drag\n moveEvent.preventDefault()\n\n // calculate the correct size based on mouse position and current panel position\n // hint: it is different formula for the opposite sides\n if (isVertical) {\n newSize =\n width +\n (panelPosition === 'right'\n ? startX - moveEvent.clientX\n : moveEvent.clientX - startX)\n setDevtoolsWidth(newSize)\n } else {\n newSize =\n height +\n (panelPosition === 'bottom'\n ? startY - moveEvent.clientY\n : moveEvent.clientY - startY)\n setDevtoolsHeight(newSize)\n }\n\n if (newSize < minPanelSize) {\n setIsOpen(false)\n } else {\n setIsOpen(true)\n }\n }\n\n const unsub = () => {\n if (isResizing) {\n setIsResizing(false)\n }\n\n document.removeEventListener('mousemove', run, false)\n document.removeEventListener('mouseUp', unsub, false)\n }\n\n document.addEventListener('mousemove', run, false)\n document.addEventListener('mouseup', unsub, false)\n }\n\n React.useEffect(() => {\n setIsResolvedOpen(isOpen ?? false)\n }, [isOpen, isResolvedOpen, setIsResolvedOpen])\n\n // Toggle panel visibility before/after transition (depending on direction).\n // Prevents focusing in a closed panel.\n React.useEffect(() => {\n const ref = panelRef.current\n if (ref) {\n const handlePanelTransitionStart = () => {\n if (isResolvedOpen) {\n ref.style.visibility = 'visible'\n }\n }\n\n const handlePanelTransitionEnd = () => {\n if (!isResolvedOpen) {\n ref.style.visibility = 'hidden'\n }\n }\n\n ref.addEventListener('transitionstart', handlePanelTransitionStart)\n ref.addEventListener('transitionend', handlePanelTransitionEnd)\n\n return () => {\n ref.removeEventListener('transitionstart', handlePanelTransitionStart)\n ref.removeEventListener('transitionend', handlePanelTransitionEnd)\n }\n }\n return\n }, [isResolvedOpen])\n\n React.useEffect(() => {\n if (isResolvedOpen && rootRef.current?.parentElement) {\n const { parentElement } = rootRef.current\n const styleProp = getSidedProp('padding', panelPosition)\n const isVertical = isVerticalSide(panelPosition)\n\n const previousPaddings = (({\n padding,\n paddingTop,\n paddingBottom,\n paddingLeft,\n paddingRight,\n }) => ({\n padding,\n paddingTop,\n paddingBottom,\n paddingLeft,\n paddingRight,\n }))(parentElement.style)\n\n const run = () => {\n // reset the padding\n parentElement.style.padding = '0px'\n parentElement.style.paddingTop = '0px'\n parentElement.style.paddingBottom = '0px'\n parentElement.style.paddingLeft = '0px'\n parentElement.style.paddingRight = '0px'\n // set the new padding based on the new panel position\n\n parentElement.style[styleProp] = `${\n isVertical ? devtoolsWidth : devtoolsHeight\n }px`\n }\n\n run()\n\n if (typeof window !== 'undefined') {\n window.addEventListener('resize', run)\n\n return () => {\n window.removeEventListener('resize', run)\n Object.entries(previousPaddings).forEach(\n ([property, previousValue]) => {\n parentElement.style[property as keyof typeof previousPaddings] =\n previousValue\n },\n )\n }\n }\n }\n return\n }, [isResolvedOpen, panelPosition, devtoolsHeight, devtoolsWidth])\n\n const { style: panelStyle = {}, ...otherPanelProps } = panelProps\n\n const {\n style: toggleButtonStyle = {},\n onClick: onToggleClick,\n ...otherToggleButtonProps\n } = toggleButtonProps\n\n // get computed style based on panel position\n const style = getSidePanelStyle({\n position: panelPosition,\n devtoolsTheme: theme,\n isOpen: isResolvedOpen,\n height: devtoolsHeight,\n width: devtoolsWidth,\n isResizing,\n panelStyle,\n })\n\n // Do not render on the server\n if (!isMounted()) return null\n\n return (\n <Container\n ref={rootRef}\n className=\"ReactQueryDevtools\"\n aria-label=\"React Query Devtools\"\n >\n <ThemeProvider theme={theme}>\n <ReactQueryDevtoolsPanel\n ref={panelRef as any}\n queryClient={queryClient}\n styleNonce={styleNonce}\n position={panelPosition}\n onPositionChange={setPanelPosition}\n showCloseButton\n closeButtonProps={closeButtonProps}\n {...otherPanelProps}\n style={style}\n isOpen={isResolvedOpen}\n setIsOpen={setIsOpen}\n onDragStart={(e) => handleDragStart(panelRef.current, e)}\n errorTypes={errorTypes}\n />\n </ThemeProvider>\n {!isResolvedOpen ? (\n <button\n type=\"button\"\n {...otherToggleButtonProps}\n aria-label=\"Open React Query Devtools\"\n aria-controls=\"ReactQueryDevtoolsPanel\"\n aria-haspopup=\"true\"\n aria-expanded=\"false\"\n onClick={(e) => {\n setIsOpen(true)\n onToggleClick?.(e)\n }}\n style={{\n background: 'none',\n border: 0,\n padding: 0,\n position: 'fixed',\n zIndex: 99999,\n display: 'inline-flex',\n fontSize: '1.5em',\n margin: '.5em',\n cursor: 'pointer',\n width: 'fit-content',\n ...(position === 'top-right'\n ? {\n top: '0',\n right: '0',\n }\n : position === 'top-left'\n ? {\n top: '0',\n left: '0',\n }\n : position === 'bottom-right'\n ? {\n bottom: '0',\n right: '0',\n }\n : {\n bottom: '0',\n left: '0',\n }),\n ...toggleButtonStyle,\n }}\n >\n <Logo aria-hidden />\n <ScreenReader text=\"Open React Query Devtools\" />\n </button>\n ) : null}\n </Container>\n )\n}\n"],"names":["position","errorTypes","width","newSize","setIsResolvedOpen","ref","parentElement","paddingRight","run","window","Object","style","onClick","devtoolsTheme","isOpen","height","panelStyle","onToggleClick","background","border","padding","zIndex","display","fontSize","margin","cursor","top","right","left","bottom"],"mappings":";;;;;;;;;;AAqEO;;;;;AAKLA;;;;;AAKAC;AACe;AACf;AACA;;;;AAcA;;;;AASA;;AAKE;AACA;;;;AAGgBC;AAAM;AACtB;AACA;;;AAIE;;;AAGA;AACA;AACA;AACEC;;AAMF;AACEA;;AAMF;;;AAIA;;AAEA;;;AAIA;;AAEA;;;;;;;;AAWFC;;;AAGF;AACA;;AAEE;AACA;;AAEI;AACEC;AACF;;;;AAKEA;AACF;;AAGFA;AACAA;AAEA;AACEA;AACAA;;AAEJ;AACA;AACF;;AAEsB;;;AAEVC;;AACR;AACA;;;;;;AAOEC;AACF;;;;;AAKEA;AACF;;AAGE;AACAD;AACAA;AACAA;AACAA;AACAA;AACA;;AAEAA;;AAKFE;AAEA;AACEC;AAEA;AACEA;AACAC;AAEIJ;AAEF;;AAGN;AACF;AACA;;;AAGMK;;AAA2C;;AAGjDA;AACAC;;AAEF;;AAEA;;AAEEZ;AACAa;AACAC;AACAC;AACAb;;AAEAc;AACF;;AAEA;AACA;AAEA;AAEI;AACA;;AACiC;AAElB;AAAa;AAExB;AACA;AACA;AACA;AACA;;AAEA;AAAmC;AAEnC;AACA;AACA;;AAEA;AAAuB;AAKvB;AAAa;AAEb;AACA;AACA;AACA;;;AAGEC;;AAEF;AACEC;AACAC;AACAC;AACApB;AACAqB;AACAC;AACAC;AACAC;AACAC;AACAvB;;AAGMwB;AACAC;AACF;AAGED;AACAE;AACF;AAGEC;AACAF;AACF;AAEEE;AACAD;AACF;;AAEN;AAAE;AAEI;;AACQ;;AAKxB;;"}
|
|
1
|
+
{"version":3,"file":"devtools.esm.js","sources":["../../src/devtools.tsx"],"sourcesContent":["'use client'\nimport { useRef, useState, useEffect } from 'react'\nimport type { QueryClient } from '@tanstack/react-query'\nimport { useQueryClient, onlineManager } from '@tanstack/react-query'\nimport type {\n DevtoolsButtonPosition,\n DevtoolsPosition,\n DevToolsErrorType,\n} from '@tanstack/query-devtools'\nimport { TanstackQueryDevtools } from '@tanstack/query-devtools'\nimport React from 'react'\nexport interface DevtoolsOptions {\n /**\n * Set this true if you want the dev tools to default to being open\n */\n initialIsOpen?: boolean\n /**\n * The position of the React Query logo to open and close the devtools panel.\n * 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n * Defaults to 'bottom-left'.\n */\n buttonPosition?: DevtoolsButtonPosition\n /**\n * The position of the React Query devtools panel.\n * 'top' | 'bottom' | 'left' | 'right'\n * Defaults to 'bottom'.\n */\n position?: DevtoolsPosition\n /**\n * Custom instance of QueryClient\n */\n client?: QueryClient\n /**\n * Use this so you can define custom errors that can be shown in the devtools.\n */\n errorTypes?: DevToolsErrorType[]\n}\n\nexport function ReactQueryDevtools(\n props: DevtoolsOptions,\n): React.ReactElement | null {\n const queryClient = useQueryClient()\n const ref = useRef<HTMLDivElement>(null)\n const { buttonPosition, position, initialIsOpen, errorTypes } = props\n const [devtools] = useState(\n new TanstackQueryDevtools({\n client: props.client || queryClient,\n queryFlavor: 'React Query',\n version: '5',\n onlineManager,\n buttonPosition,\n position,\n initialIsOpen,\n errorTypes,\n }),\n )\n\n useEffect(() => {\n if (buttonPosition) {\n devtools.setButtonPosition(buttonPosition)\n }\n }, [buttonPosition, devtools])\n\n useEffect(() => {\n if (position) {\n devtools.setPosition(position)\n }\n }, [position, devtools])\n\n useEffect(() => {\n devtools.setInitialIsOpen(initialIsOpen || false)\n }, [initialIsOpen, devtools])\n\n useEffect(() => {\n devtools.setErrorTypes(errorTypes || [])\n }, [errorTypes, devtools])\n\n useEffect(() => {\n if (ref.current) {\n devtools.mount(ref.current)\n }\n\n return () => {\n devtools.unmount()\n }\n }, [devtools])\n\n return <div ref={ref}></div>\n}\n"],"names":["errorTypes","client","queryFlavor","version","useEffect","devtools"],"mappings":";;;;;AAsCO;;AAIL;;;;;AACiDA;AAAW;;AAGxDC;AACAC;AACAC;;;;;AAKAH;AACF;AAGFI;AACE;AACEC;AACF;AACF;AAEAD;AACE;AACEC;AACF;AACF;AAEAD;AACEC;AACF;AAEAD;AACEC;AACF;AAEAD;;AAEIC;AACF;AAEA;;;AAGF;;AAEY;;AACd;;"}
|