@tanstack/react-query-devtools 5.0.0-alpha.26 → 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.
Files changed (159) hide show
  1. package/build/lib/__tests__/devtools.test.d.ts +0 -1
  2. package/build/lib/__tests__/devtools.test.d.ts.map +1 -1
  3. package/build/lib/devtools.d.ts +8 -30
  4. package/build/lib/devtools.d.ts.map +1 -1
  5. package/build/lib/devtools.esm.js +47 -226
  6. package/build/lib/devtools.esm.js.map +1 -1
  7. package/build/lib/devtools.js +45 -244
  8. package/build/lib/devtools.js.map +1 -1
  9. package/build/lib/devtools.mjs +47 -225
  10. package/build/lib/devtools.mjs.map +1 -1
  11. package/build/lib/index.d.ts +0 -1
  12. package/build/lib/index.d.ts.map +1 -1
  13. package/build/lib/index.esm.js +8 -5
  14. package/build/lib/index.esm.js.map +1 -1
  15. package/build/lib/index.js +7 -5
  16. package/build/lib/index.js.map +1 -1
  17. package/build/lib/index.mjs +8 -5
  18. package/build/lib/index.mjs.map +1 -1
  19. package/build/lib/index.prod.d.ts +0 -1
  20. package/build/lib/index.prod.esm.js +7901 -1501
  21. package/build/lib/index.prod.esm.js.map +1 -1
  22. package/build/lib/index.prod.js +7909 -1528
  23. package/build/lib/index.prod.js.map +1 -1
  24. package/build/lib/index.prod.mjs +7922 -1489
  25. package/build/lib/index.prod.mjs.map +1 -1
  26. package/build/umd/index.development.js +7146 -2375
  27. package/build/umd/index.development.js.map +1 -1
  28. package/build/umd/index.production.js +1 -1
  29. package/build/umd/index.production.js.map +1 -1
  30. package/package.json +2 -3
  31. package/src/__tests__/devtools.test.tsx +1 -1135
  32. package/src/devtools.tsx +52 -306
  33. package/src/index.ts +6 -6
  34. package/build/lib/CachePanel/ActiveQuery.d.ts +0 -19
  35. package/build/lib/CachePanel/ActiveQuery.d.ts.map +0 -1
  36. package/build/lib/CachePanel/ActiveQuery.esm.js +0 -277
  37. package/build/lib/CachePanel/ActiveQuery.esm.js.map +0 -1
  38. package/build/lib/CachePanel/ActiveQuery.js +0 -281
  39. package/build/lib/CachePanel/ActiveQuery.js.map +0 -1
  40. package/build/lib/CachePanel/ActiveQuery.mjs +0 -261
  41. package/build/lib/CachePanel/ActiveQuery.mjs.map +0 -1
  42. package/build/lib/CachePanel/CachePanel.d.ts +0 -58
  43. package/build/lib/CachePanel/CachePanel.d.ts.map +0 -1
  44. package/build/lib/CachePanel/CachePanel.esm.js +0 -310
  45. package/build/lib/CachePanel/CachePanel.esm.js.map +0 -1
  46. package/build/lib/CachePanel/CachePanel.js +0 -315
  47. package/build/lib/CachePanel/CachePanel.js.map +0 -1
  48. package/build/lib/CachePanel/CachePanel.mjs +0 -310
  49. package/build/lib/CachePanel/CachePanel.mjs.map +0 -1
  50. package/build/lib/CachePanel/Header/QueryStatusCount.d.ts +0 -8
  51. package/build/lib/CachePanel/Header/QueryStatusCount.d.ts.map +0 -1
  52. package/build/lib/CachePanel/Header/QueryStatusCount.esm.js +0 -49
  53. package/build/lib/CachePanel/Header/QueryStatusCount.esm.js.map +0 -1
  54. package/build/lib/CachePanel/Header/QueryStatusCount.js +0 -53
  55. package/build/lib/CachePanel/Header/QueryStatusCount.js.map +0 -1
  56. package/build/lib/CachePanel/Header/QueryStatusCount.mjs +0 -49
  57. package/build/lib/CachePanel/Header/QueryStatusCount.mjs.map +0 -1
  58. package/build/lib/CachePanel/QueryRow.d.ts +0 -14
  59. package/build/lib/CachePanel/QueryRow.d.ts.map +0 -1
  60. package/build/lib/CachePanel/QueryRow.esm.js +0 -98
  61. package/build/lib/CachePanel/QueryRow.esm.js.map +0 -1
  62. package/build/lib/CachePanel/QueryRow.js +0 -102
  63. package/build/lib/CachePanel/QueryRow.js.map +0 -1
  64. package/build/lib/CachePanel/QueryRow.mjs +0 -82
  65. package/build/lib/CachePanel/QueryRow.mjs.map +0 -1
  66. package/build/lib/Explorer.d.ts +0 -51
  67. package/build/lib/Explorer.d.ts.map +0 -1
  68. package/build/lib/Explorer.esm.js +0 -254
  69. package/build/lib/Explorer.esm.js.map +0 -1
  70. package/build/lib/Explorer.js +0 -288
  71. package/build/lib/Explorer.js.map +0 -1
  72. package/build/lib/Explorer.mjs +0 -254
  73. package/build/lib/Explorer.mjs.map +0 -1
  74. package/build/lib/Logo.d.ts +0 -2
  75. package/build/lib/Logo.esm.js +0 -32
  76. package/build/lib/Logo.esm.js.map +0 -1
  77. package/build/lib/Logo.js +0 -55
  78. package/build/lib/Logo.js.map +0 -1
  79. package/build/lib/Logo.mjs +0 -32
  80. package/build/lib/Logo.mjs.map +0 -1
  81. package/build/lib/__tests__/Explorer.test.d.ts +0 -2
  82. package/build/lib/__tests__/Explorer.test.d.ts.map +0 -1
  83. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -17
  84. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
  85. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -19
  86. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  87. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -17
  88. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +0 -1
  89. package/build/lib/noop.d.ts +0 -3
  90. package/build/lib/screenreader.d.ts +0 -4
  91. package/build/lib/screenreader.esm.js +0 -17
  92. package/build/lib/screenreader.esm.js.map +0 -1
  93. package/build/lib/screenreader.js +0 -40
  94. package/build/lib/screenreader.js.map +0 -1
  95. package/build/lib/screenreader.mjs +0 -17
  96. package/build/lib/screenreader.mjs.map +0 -1
  97. package/build/lib/styledComponents.d.ts +0 -9
  98. package/build/lib/styledComponents.d.ts.map +0 -1
  99. package/build/lib/styledComponents.esm.js +0 -103
  100. package/build/lib/styledComponents.esm.js.map +0 -1
  101. package/build/lib/styledComponents.js +0 -112
  102. package/build/lib/styledComponents.js.map +0 -1
  103. package/build/lib/styledComponents.mjs +0 -103
  104. package/build/lib/styledComponents.mjs.map +0 -1
  105. package/build/lib/theme.d.ts +0 -37
  106. package/build/lib/theme.esm.js +0 -33
  107. package/build/lib/theme.esm.js.map +0 -1
  108. package/build/lib/theme.js +0 -56
  109. package/build/lib/theme.js.map +0 -1
  110. package/build/lib/theme.mjs +0 -33
  111. package/build/lib/theme.mjs.map +0 -1
  112. package/build/lib/types.d.ts +0 -12
  113. package/build/lib/types.d.ts.map +0 -1
  114. package/build/lib/useLocalStorage.d.ts +0 -2
  115. package/build/lib/useLocalStorage.esm.js +0 -40
  116. package/build/lib/useLocalStorage.esm.js.map +0 -1
  117. package/build/lib/useLocalStorage.js +0 -63
  118. package/build/lib/useLocalStorage.js.map +0 -1
  119. package/build/lib/useLocalStorage.mjs +0 -40
  120. package/build/lib/useLocalStorage.mjs.map +0 -1
  121. package/build/lib/useMediaQuery.d.ts +0 -2
  122. package/build/lib/useMediaQuery.esm.js +0 -36
  123. package/build/lib/useMediaQuery.esm.js.map +0 -1
  124. package/build/lib/useMediaQuery.js +0 -59
  125. package/build/lib/useMediaQuery.js.map +0 -1
  126. package/build/lib/useMediaQuery.mjs +0 -36
  127. package/build/lib/useMediaQuery.mjs.map +0 -1
  128. package/build/lib/useSubscribeToQueryCache.d.ts +0 -4
  129. package/build/lib/useSubscribeToQueryCache.d.ts.map +0 -1
  130. package/build/lib/useSubscribeToQueryCache.esm.js +0 -15
  131. package/build/lib/useSubscribeToQueryCache.esm.js.map +0 -1
  132. package/build/lib/useSubscribeToQueryCache.js +0 -19
  133. package/build/lib/useSubscribeToQueryCache.js.map +0 -1
  134. package/build/lib/useSubscribeToQueryCache.mjs +0 -15
  135. package/build/lib/useSubscribeToQueryCache.mjs.map +0 -1
  136. package/build/lib/utils.d.ts +0 -80
  137. package/build/lib/utils.d.ts.map +0 -1
  138. package/build/lib/utils.esm.js +0 -184
  139. package/build/lib/utils.esm.js.map +0 -1
  140. package/build/lib/utils.js +0 -218
  141. package/build/lib/utils.js.map +0 -1
  142. package/build/lib/utils.mjs +0 -184
  143. package/build/lib/utils.mjs.map +0 -1
  144. package/src/CachePanel/ActiveQuery.tsx +0 -388
  145. package/src/CachePanel/CachePanel.tsx +0 -439
  146. package/src/CachePanel/Header/QueryStatusCount.tsx +0 -93
  147. package/src/CachePanel/QueryRow.tsx +0 -125
  148. package/src/Explorer.tsx +0 -385
  149. package/src/Logo.tsx +0 -32
  150. package/src/__tests__/Explorer.test.tsx +0 -150
  151. package/src/noop.ts +0 -7
  152. package/src/screenreader.tsx +0 -16
  153. package/src/styledComponents.ts +0 -126
  154. package/src/theme.tsx +0 -33
  155. package/src/types.ts +0 -12
  156. package/src/useLocalStorage.ts +0 -52
  157. package/src/useMediaQuery.ts +0 -34
  158. package/src/useSubscribeToQueryCache.ts +0 -26
  159. package/src/utils.ts +0 -319
@@ -1,126 +0,0 @@
1
- import { styled } from './utils'
2
-
3
- export const Panel = styled(
4
- 'div',
5
- (_props, theme) => ({
6
- fontSize: 'clamp(12px, 1.5vw, 14px)',
7
- fontFamily: `sans-serif`,
8
- display: 'flex',
9
- backgroundColor: theme.background,
10
- color: theme.foreground,
11
- }),
12
- {
13
- '(max-width: 700px)': {
14
- flexDirection: 'column',
15
- },
16
- '(max-width: 600px)': {
17
- fontSize: '.9em',
18
- // flexDirection: 'column',
19
- },
20
- },
21
- )
22
-
23
- Panel.displayName = 'Panel'
24
-
25
- export const ActiveQueryPanel = styled(
26
- 'div',
27
- () => ({
28
- flex: '1 1 500px',
29
- display: 'flex',
30
- flexDirection: 'column',
31
- overflow: 'auto',
32
- height: '100%',
33
- }),
34
- {
35
- '(max-width: 700px)': (_props, theme) => ({
36
- borderTop: `2px solid ${theme.gray}`,
37
- }),
38
- },
39
- )
40
-
41
- ActiveQueryPanel.displayName = 'ActiveQueryPanel'
42
-
43
- export const Button = styled('button', (props, theme) => ({
44
- appearance: 'none',
45
- fontSize: '.9em',
46
- fontWeight: 'bold',
47
- background: theme.gray,
48
- border: '0',
49
- borderRadius: '.3em',
50
- color: 'white',
51
- padding: '.5em',
52
- opacity: props.disabled ? '.5' : undefined,
53
- cursor: 'pointer',
54
- }))
55
-
56
- Button.displayName = 'Button'
57
-
58
- export const QueryKeys = styled('span', {
59
- display: 'flex',
60
- flexWrap: 'wrap',
61
- gap: '0.5em',
62
- fontSize: '0.9em',
63
- })
64
-
65
- QueryKeys.displayName = 'QueryKeys'
66
-
67
- export const QueryKey = styled('span', {
68
- display: 'inline-flex',
69
- alignItems: 'center',
70
- padding: '.2em .4em',
71
- fontWeight: 'bold',
72
- textShadow: '0 0 10px black',
73
- borderRadius: '.2em',
74
- })
75
-
76
- QueryKey.displayName = 'QueryKey'
77
-
78
- export const Code = styled('code', {
79
- fontSize: '.9em',
80
- color: 'inherit',
81
- background: 'inherit',
82
- })
83
-
84
- Code.displayName = 'Code'
85
-
86
- export const Input = styled('input', (_props, theme) => ({
87
- backgroundColor: theme.inputBackgroundColor,
88
- border: 0,
89
- borderRadius: '.2em',
90
- color: theme.inputTextColor,
91
- fontSize: '.9em',
92
- lineHeight: `1.3`,
93
- padding: '.3em .4em',
94
- }))
95
-
96
- Input.displayName = 'Input'
97
-
98
- export const Select = styled(
99
- 'select',
100
- (_props, theme) => ({
101
- display: `inline-block`,
102
- fontSize: `.9em`,
103
- fontFamily: `sans-serif`,
104
- fontWeight: 'normal',
105
- lineHeight: `1.3`,
106
- padding: `.3em 1.5em .3em .5em`,
107
- height: 'auto',
108
- border: 0,
109
- borderRadius: `.2em`,
110
- appearance: `none`,
111
- WebkitAppearance: 'none',
112
- backgroundColor: theme.inputBackgroundColor,
113
- backgroundImage: `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='%23444444'><polygon points='0,25 100,25 50,75'/></svg>")`,
114
- backgroundRepeat: `no-repeat`,
115
- backgroundPosition: `right .55em center`,
116
- backgroundSize: `.65em auto, 100%`,
117
- color: theme.inputTextColor,
118
- }),
119
- {
120
- '(max-width: 500px)': {
121
- display: 'none',
122
- },
123
- },
124
- )
125
-
126
- Select.displayName = 'Select'
package/src/theme.tsx DELETED
@@ -1,33 +0,0 @@
1
- 'use client'
2
- import * as React from 'react'
3
-
4
- export const defaultTheme = {
5
- background: '#0b1521',
6
- backgroundAlt: '#132337',
7
- foreground: 'white',
8
- gray: '#3f4e60',
9
- grayAlt: '#222e3e',
10
- inputBackgroundColor: '#fff',
11
- inputTextColor: '#000',
12
- success: '#00ab52',
13
- danger: '#ff0085',
14
- active: '#006bff',
15
- paused: '#8c49eb',
16
- warning: '#ffb200',
17
- } as const
18
-
19
- export type Theme = typeof defaultTheme
20
- interface ProviderProps {
21
- theme: Theme
22
- children?: React.ReactNode
23
- }
24
-
25
- const ThemeContext = React.createContext(defaultTheme)
26
-
27
- export function ThemeProvider({ theme, ...rest }: ProviderProps) {
28
- return <ThemeContext.Provider value={theme} {...rest} />
29
- }
30
-
31
- export function useTheme() {
32
- return React.useContext(ThemeContext)
33
- }
package/src/types.ts DELETED
@@ -1,12 +0,0 @@
1
- import type { Query, DefaultError } from '@tanstack/react-query'
2
-
3
- export interface DevToolsErrorType {
4
- /**
5
- * The name of the error.
6
- */
7
- name: string
8
- /**
9
- * How the error is initialized.
10
- */
11
- initializer: (query: Query) => DefaultError
12
- }
@@ -1,52 +0,0 @@
1
- import * as React from 'react'
2
-
3
- const getItem = (key: string): unknown => {
4
- try {
5
- const itemValue = localStorage.getItem(key)
6
- if (typeof itemValue === 'string') {
7
- return JSON.parse(itemValue)
8
- }
9
- return undefined
10
- } catch {
11
- return undefined
12
- }
13
- }
14
-
15
- export default function useLocalStorage<T>(
16
- key: string,
17
- defaultValue: T | undefined,
18
- ): [T | undefined, (newVal: T | ((prevVal: T) => T)) => void] {
19
- const [value, setValue] = React.useState<T>()
20
-
21
- React.useEffect(() => {
22
- const initialValue = getItem(key) as T | undefined
23
-
24
- if (typeof initialValue === 'undefined' || initialValue === null) {
25
- setValue(
26
- typeof defaultValue === 'function' ? defaultValue() : defaultValue,
27
- )
28
- } else {
29
- setValue(initialValue)
30
- }
31
- }, [defaultValue, key])
32
-
33
- const setter = React.useCallback(
34
- (updater: any) => {
35
- setValue((old) => {
36
- let newVal = updater
37
-
38
- if (typeof updater == 'function') {
39
- newVal = updater(old)
40
- }
41
- try {
42
- localStorage.setItem(key, JSON.stringify(newVal))
43
- } catch {}
44
-
45
- return newVal
46
- })
47
- },
48
- [key],
49
- )
50
-
51
- return [value, setter]
52
- }
@@ -1,34 +0,0 @@
1
- import * as React from 'react'
2
-
3
- export default function useMediaQuery(query: string): boolean | undefined {
4
- // Keep track of the preference in state, start with the current match
5
- const [isMatch, setIsMatch] = React.useState(() => {
6
- if (typeof window !== 'undefined') {
7
- return window.matchMedia(query).matches
8
- }
9
- return
10
- })
11
-
12
- // Watch for changes
13
- React.useEffect(() => {
14
- if (typeof window !== 'undefined') {
15
- // Create a matcher
16
- const matcher = window.matchMedia(query)
17
-
18
- // Create our handler
19
- const onChange = ({ matches }: { matches: boolean }) =>
20
- setIsMatch(matches)
21
-
22
- // Listen for changes
23
- matcher.addListener(onChange)
24
-
25
- return () => {
26
- // Stop listening for changes
27
- matcher.removeListener(onChange)
28
- }
29
- }
30
- return
31
- }, [isMatch, query, setIsMatch])
32
-
33
- return isMatch
34
- }
@@ -1,26 +0,0 @@
1
- import React from 'react'
2
- import type { QueryCache } from '@tanstack/react-query'
3
- import { notifyManager } from '@tanstack/react-query'
4
-
5
- const useSubscribeToQueryCache = <T>(
6
- queryCache: QueryCache,
7
- getSnapshot: () => T,
8
- skip: boolean = false,
9
- ): T => {
10
- return React.useSyncExternalStore(
11
- React.useCallback(
12
- (onStoreChange) => {
13
- if (!skip)
14
- return queryCache.subscribe(notifyManager.batchCalls(onStoreChange))
15
- return () => {
16
- return
17
- }
18
- },
19
- [queryCache, skip],
20
- ),
21
- getSnapshot,
22
- getSnapshot,
23
- )
24
- }
25
-
26
- export default useSubscribeToQueryCache
package/src/utils.ts DELETED
@@ -1,319 +0,0 @@
1
- import * as React from 'react'
2
- import type { Query } from '@tanstack/react-query'
3
- import SuperJSON from 'superjson'
4
-
5
- import type { Theme } from './theme'
6
- import { useTheme } from './theme'
7
- import useMediaQuery from './useMediaQuery'
8
-
9
- type StyledComponent<T> = T extends 'button'
10
- ? React.DetailedHTMLProps<
11
- React.ButtonHTMLAttributes<HTMLButtonElement>,
12
- HTMLButtonElement
13
- >
14
- : T extends 'input'
15
- ? React.DetailedHTMLProps<
16
- React.InputHTMLAttributes<HTMLInputElement>,
17
- HTMLInputElement
18
- >
19
- : T extends 'select'
20
- ? React.DetailedHTMLProps<
21
- React.SelectHTMLAttributes<HTMLSelectElement>,
22
- HTMLSelectElement
23
- >
24
- : T extends keyof HTMLElementTagNameMap
25
- ? React.HTMLAttributes<HTMLElementTagNameMap[T]>
26
- : never
27
-
28
- export function getQueryStatusColor({
29
- queryState,
30
- observerCount,
31
- isStale,
32
- theme,
33
- }: {
34
- queryState: Query['state']
35
- observerCount: number
36
- isStale: boolean
37
- theme: Theme
38
- }) {
39
- return queryState.fetchStatus === 'fetching'
40
- ? theme.active
41
- : !observerCount
42
- ? theme.gray
43
- : queryState.fetchStatus === 'paused'
44
- ? theme.paused
45
- : isStale
46
- ? theme.warning
47
- : theme.success
48
- }
49
-
50
- export function getQueryStatusLabel(query: Query) {
51
- return query.state.fetchStatus === 'fetching'
52
- ? 'fetching'
53
- : !query.getObserversCount()
54
- ? 'inactive'
55
- : query.state.fetchStatus === 'paused'
56
- ? 'paused'
57
- : query.isStale()
58
- ? 'stale'
59
- : 'fresh'
60
- }
61
-
62
- type Styles =
63
- | React.CSSProperties
64
- | ((props: Record<string, any>, theme: Theme) => React.CSSProperties)
65
-
66
- export function styled<T extends keyof HTMLElementTagNameMap>(
67
- type: T,
68
- newStyles: Styles,
69
- queries: Record<string, Styles> = {},
70
- ) {
71
- return React.forwardRef<HTMLElementTagNameMap[T], StyledComponent<T>>(
72
- ({ style, ...rest }, ref) => {
73
- const theme = useTheme()
74
-
75
- const mediaStyles = Object.entries(queries).reduce(
76
- (current, [key, value]) => {
77
- // eslint-disable-next-line react-hooks/rules-of-hooks
78
- return useMediaQuery(key)
79
- ? {
80
- ...current,
81
- ...(typeof value === 'function' ? value(rest, theme) : value),
82
- }
83
- : current
84
- },
85
- {},
86
- )
87
-
88
- return React.createElement(type, {
89
- ...rest,
90
- style: {
91
- ...(typeof newStyles === 'function'
92
- ? newStyles(rest, theme)
93
- : newStyles),
94
- ...style,
95
- ...mediaStyles,
96
- },
97
- ref,
98
- })
99
- },
100
- )
101
- }
102
-
103
- export function useIsMounted() {
104
- const mountedRef = React.useRef(false)
105
- const isMounted = React.useCallback(() => mountedRef.current, [])
106
-
107
- React.useEffect(() => {
108
- mountedRef.current = true
109
- return () => {
110
- mountedRef.current = false
111
- }
112
- }, [])
113
-
114
- return isMounted
115
- }
116
-
117
- /**
118
- * Displays a string regardless the type of the data
119
- * @param {unknown} value Value to be stringified
120
- * @param {boolean} beautify Formats json to multiline
121
- */
122
- export const displayValue = (value: unknown, beautify: boolean = false) => {
123
- const { json } = SuperJSON.serialize(value)
124
-
125
- return JSON.stringify(json, null, beautify ? 2 : undefined)
126
- }
127
-
128
- // Sorting functions
129
- type SortFn = (a: Query, b: Query) => number
130
-
131
- const getStatusRank = (q: Query) =>
132
- q.state.fetchStatus !== 'idle'
133
- ? 0
134
- : !q.getObserversCount()
135
- ? 3
136
- : q.isStale()
137
- ? 2
138
- : 1
139
-
140
- const queryHashSort: SortFn = (a, b) => a.queryHash.localeCompare(b.queryHash)
141
-
142
- const dateSort: SortFn = (a, b) =>
143
- a.state.dataUpdatedAt < b.state.dataUpdatedAt ? 1 : -1
144
-
145
- const statusAndDateSort: SortFn = (a, b) => {
146
- if (getStatusRank(a) === getStatusRank(b)) {
147
- return dateSort(a, b)
148
- }
149
-
150
- return getStatusRank(a) > getStatusRank(b) ? 1 : -1
151
- }
152
-
153
- export const sortFns: Record<string, SortFn> = {
154
- 'Status > Last Updated': statusAndDateSort,
155
- 'Query Hash': queryHashSort,
156
- 'Last Updated': dateSort,
157
- }
158
-
159
- export const minPanelSize = 70
160
- export const defaultPanelSize = 500
161
- export const sides: Record<Side, Side> = {
162
- top: 'bottom',
163
- bottom: 'top',
164
- left: 'right',
165
- right: 'left',
166
- }
167
-
168
- export type Corner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
169
- export type Side = 'left' | 'right' | 'top' | 'bottom'
170
- /**
171
- * Check if the given side is vertical (left/right)
172
- */
173
- export function isVerticalSide(side: Side) {
174
- return ['left', 'right'].includes(side)
175
- }
176
- /**
177
- * Get the opposite side, eg 'left' => 'right'. 'top' => 'bottom', etc
178
- */
179
- export function getOppositeSide(side: Side): Side {
180
- return sides[side]
181
- }
182
- /**
183
- * Given as css prop it will return a sided css prop based on a given side
184
- * Example given `border` and `right` it return `borderRight`
185
- */
186
- export function getSidedProp<T extends string>(prop: T, side: Side) {
187
- return `${prop}${
188
- side.charAt(0).toUpperCase() + side.slice(1)
189
- }` as `${T}${Capitalize<Side>}`
190
- }
191
-
192
- export interface SidePanelStyleOptions {
193
- /**
194
- * Position of the panel
195
- * Defaults to 'bottom'
196
- */
197
- position?: Side
198
- /**
199
- * Staring height for the panel, it is set if the position is horizontal eg 'top' or 'bottom'
200
- * Defaults to 500
201
- */
202
- height?: number
203
- /**
204
- * Staring width for the panel, it is set if the position is vertical eg 'left' or 'right'
205
- * Defaults to 500
206
- */
207
- width?: number
208
- /**
209
- * RQ devtools theme
210
- */
211
- devtoolsTheme: Theme
212
- /**
213
- * Sets the correct transition and visibility styles
214
- */
215
- isOpen?: boolean
216
- /**
217
- * If the panel is resizing set to true to apply the correct transition styles
218
- */
219
- isResizing?: boolean
220
- /**
221
- * Extra panel style passed by the user
222
- */
223
- panelStyle?: React.CSSProperties
224
- }
225
-
226
- export function getSidePanelStyle({
227
- position = 'bottom',
228
- height,
229
- width,
230
- devtoolsTheme,
231
- isOpen,
232
- isResizing,
233
- panelStyle,
234
- }: SidePanelStyleOptions): React.CSSProperties {
235
- const oppositeSide = getOppositeSide(position)
236
- const borderSide = getSidedProp('border', oppositeSide)
237
- const isVertical = isVerticalSide(position)
238
-
239
- return {
240
- ...panelStyle,
241
- direction: 'ltr',
242
- position: 'fixed',
243
- [position]: 0,
244
- [borderSide]: `1px solid ${devtoolsTheme.gray}`,
245
- transformOrigin: oppositeSide,
246
- boxShadow: '0 0 20px rgba(0,0,0,.3)',
247
- zIndex: 99999,
248
- // visibility will be toggled after transitions, but set initial state here
249
- visibility: isOpen ? 'visible' : 'hidden',
250
- ...(isResizing
251
- ? {
252
- transition: `none`,
253
- }
254
- : { transition: `all .2s ease` }),
255
- ...(isOpen
256
- ? {
257
- opacity: 1,
258
- pointerEvents: 'all',
259
- transform: isVertical
260
- ? `translateX(0) scale(1)`
261
- : `translateY(0) scale(1)`,
262
- }
263
- : {
264
- opacity: 0,
265
- pointerEvents: 'none',
266
- transform: isVertical
267
- ? `translateX(15px) scale(1.02)`
268
- : `translateY(15px) scale(1.02)`,
269
- }),
270
- ...(isVertical
271
- ? {
272
- top: 0,
273
- height: '100vh',
274
- maxWidth: '90%',
275
- width:
276
- typeof width === 'number' && width >= minPanelSize
277
- ? width
278
- : defaultPanelSize,
279
- }
280
- : {
281
- left: 0,
282
- width: '100%',
283
- maxHeight: '90%',
284
- height:
285
- typeof height === 'number' && height >= minPanelSize
286
- ? height
287
- : defaultPanelSize,
288
- }),
289
- }
290
- }
291
-
292
- /**
293
- * Get resize handle style based on a given side
294
- */
295
- export function getResizeHandleStyle(
296
- position: Side = 'bottom',
297
- ): React.CSSProperties {
298
- const isVertical = isVerticalSide(position)
299
- const oppositeSide = getOppositeSide(position)
300
- const marginSide = getSidedProp('margin', oppositeSide)
301
-
302
- return {
303
- position: 'absolute',
304
- cursor: isVertical ? 'col-resize' : 'row-resize',
305
- zIndex: 100000,
306
- [oppositeSide]: 0,
307
- [marginSide]: `-4px`,
308
- ...(isVertical
309
- ? {
310
- top: 0,
311
- height: '100%',
312
- width: '4px',
313
- }
314
- : {
315
- width: '100%',
316
- height: '4px',
317
- }),
318
- }
319
- }