@tanstack/router-devtools 1.112.17 → 1.114.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.
- package/dist/cjs/index.cjs +12 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +6 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -3
- package/src/index.tsx +6 -2
- package/dist/cjs/AgeTicker.cjs +0 -58
- package/dist/cjs/AgeTicker.cjs.map +0 -1
- package/dist/cjs/AgeTicker.d.cts +0 -5
- package/dist/cjs/BaseTanStackRouterDevtoolsPanel.cjs +0 -421
- package/dist/cjs/BaseTanStackRouterDevtoolsPanel.cjs.map +0 -1
- package/dist/cjs/BaseTanStackRouterDevtoolsPanel.d.cts +0 -3
- package/dist/cjs/Explorer.cjs +0 -310
- package/dist/cjs/Explorer.cjs.map +0 -1
- package/dist/cjs/Explorer.d.cts +0 -46
- package/dist/cjs/TanStackRouterDevtools.cjs +0 -177
- package/dist/cjs/TanStackRouterDevtools.cjs.map +0 -1
- package/dist/cjs/TanStackRouterDevtools.d.cts +0 -41
- package/dist/cjs/TanStackRouterDevtoolsPanel.cjs +0 -21
- package/dist/cjs/TanStackRouterDevtoolsPanel.cjs.map +0 -1
- package/dist/cjs/TanStackRouterDevtoolsPanel.d.cts +0 -33
- package/dist/cjs/context.cjs +0 -18
- package/dist/cjs/context.cjs.map +0 -1
- package/dist/cjs/context.d.cts +0 -8
- package/dist/cjs/logo.cjs +0 -1012
- package/dist/cjs/logo.cjs.map +0 -1
- package/dist/cjs/logo.d.cts +0 -1
- package/dist/cjs/theme.d.cts +0 -34
- package/dist/cjs/tokens.cjs +0 -201
- package/dist/cjs/tokens.cjs.map +0 -1
- package/dist/cjs/tokens.d.cts +0 -298
- package/dist/cjs/useLocalStorage.cjs +0 -45
- package/dist/cjs/useLocalStorage.cjs.map +0 -1
- package/dist/cjs/useLocalStorage.d.cts +0 -1
- package/dist/cjs/useMediaQuery.d.cts +0 -1
- package/dist/cjs/useStyles.cjs +0 -570
- package/dist/cjs/useStyles.cjs.map +0 -1
- package/dist/cjs/useStyles.d.cts +0 -52
- package/dist/cjs/utils.cjs +0 -84
- package/dist/cjs/utils.cjs.map +0 -1
- package/dist/cjs/utils.d.cts +0 -23
- package/dist/esm/AgeTicker.d.ts +0 -5
- package/dist/esm/AgeTicker.js +0 -58
- package/dist/esm/AgeTicker.js.map +0 -1
- package/dist/esm/BaseTanStackRouterDevtoolsPanel.d.ts +0 -3
- package/dist/esm/BaseTanStackRouterDevtoolsPanel.js +0 -421
- package/dist/esm/BaseTanStackRouterDevtoolsPanel.js.map +0 -1
- package/dist/esm/Explorer.d.ts +0 -46
- package/dist/esm/Explorer.js +0 -292
- package/dist/esm/Explorer.js.map +0 -1
- package/dist/esm/TanStackRouterDevtools.d.ts +0 -41
- package/dist/esm/TanStackRouterDevtools.js +0 -177
- package/dist/esm/TanStackRouterDevtools.js.map +0 -1
- package/dist/esm/TanStackRouterDevtoolsPanel.d.ts +0 -33
- package/dist/esm/TanStackRouterDevtoolsPanel.js +0 -21
- package/dist/esm/TanStackRouterDevtoolsPanel.js.map +0 -1
- package/dist/esm/context.d.ts +0 -8
- package/dist/esm/context.js +0 -18
- package/dist/esm/context.js.map +0 -1
- package/dist/esm/logo.d.ts +0 -1
- package/dist/esm/logo.js +0 -1012
- package/dist/esm/logo.js.map +0 -1
- package/dist/esm/theme.d.ts +0 -34
- package/dist/esm/tokens.d.ts +0 -298
- package/dist/esm/tokens.js +0 -201
- package/dist/esm/tokens.js.map +0 -1
- package/dist/esm/useLocalStorage.d.ts +0 -1
- package/dist/esm/useLocalStorage.js +0 -46
- package/dist/esm/useLocalStorage.js.map +0 -1
- package/dist/esm/useMediaQuery.d.ts +0 -1
- package/dist/esm/useStyles.d.ts +0 -52
- package/dist/esm/useStyles.js +0 -553
- package/dist/esm/useStyles.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -23
- package/dist/esm/utils.js +0 -84
- package/dist/esm/utils.js.map +0 -1
- package/src/AgeTicker.tsx +0 -73
- package/src/BaseTanStackRouterDevtoolsPanel.tsx +0 -488
- package/src/Explorer.tsx +0 -362
- package/src/TanStackRouterDevtools.tsx +0 -250
- package/src/TanStackRouterDevtoolsPanel.tsx +0 -54
- package/src/context.ts +0 -22
- package/src/logo.tsx +0 -817
- package/src/theme.tsx +0 -31
- package/src/tokens.ts +0 -305
- package/src/useLocalStorage.ts +0 -52
- package/src/useMediaQuery.ts +0 -41
- package/src/useStyles.tsx +0 -589
- package/src/utils.ts +0 -188
package/src/Explorer.tsx
DELETED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
import { clsx as cx } from 'clsx'
|
|
3
|
-
import * as goober from 'goober'
|
|
4
|
-
import { tokens } from './tokens'
|
|
5
|
-
import { displayValue } from './utils'
|
|
6
|
-
import { ShadowDomTargetContext } from './context'
|
|
7
|
-
|
|
8
|
-
type ExpanderProps = {
|
|
9
|
-
expanded: boolean
|
|
10
|
-
style?: React.CSSProperties
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const Expander = ({ expanded, style = {} }: ExpanderProps) => {
|
|
14
|
-
const styles = useStyles()
|
|
15
|
-
return (
|
|
16
|
-
<span className={styles.expander}>
|
|
17
|
-
<svg
|
|
18
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
19
|
-
width="12"
|
|
20
|
-
height="12"
|
|
21
|
-
fill="none"
|
|
22
|
-
viewBox="0 0 24 24"
|
|
23
|
-
className={cx(styles.expanderIcon(expanded))}
|
|
24
|
-
>
|
|
25
|
-
<path
|
|
26
|
-
stroke="currentColor"
|
|
27
|
-
strokeLinecap="round"
|
|
28
|
-
strokeLinejoin="round"
|
|
29
|
-
strokeWidth="2"
|
|
30
|
-
d="M9 18l6-6-6-6"
|
|
31
|
-
></path>
|
|
32
|
-
</svg>
|
|
33
|
-
</span>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type Entry = {
|
|
38
|
-
label: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type RendererProps = {
|
|
42
|
-
handleEntry: HandleEntryFn
|
|
43
|
-
label?: React.ReactNode
|
|
44
|
-
value: unknown
|
|
45
|
-
subEntries: Array<Entry>
|
|
46
|
-
subEntryPages: Array<Array<Entry>>
|
|
47
|
-
type: string
|
|
48
|
-
expanded: boolean
|
|
49
|
-
toggleExpanded: () => void
|
|
50
|
-
pageSize: number
|
|
51
|
-
renderer?: Renderer
|
|
52
|
-
filterSubEntries?: (subEntries: Array<Property>) => Array<Property>
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Chunk elements in the array by size
|
|
57
|
-
*
|
|
58
|
-
* when the array cannot be chunked evenly by size, the last chunk will be
|
|
59
|
-
* filled with the remaining elements
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* chunkArray(['a','b', 'c', 'd', 'e'], 2) // returns [['a','b'], ['c', 'd'], ['e']]
|
|
63
|
-
*/
|
|
64
|
-
export function chunkArray<T>(array: Array<T>, size: number): Array<Array<T>> {
|
|
65
|
-
if (size < 1) return []
|
|
66
|
-
let i = 0
|
|
67
|
-
const result: Array<Array<T>> = []
|
|
68
|
-
while (i < array.length) {
|
|
69
|
-
result.push(array.slice(i, i + size))
|
|
70
|
-
i = i + size
|
|
71
|
-
}
|
|
72
|
-
return result
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
type Renderer = (props: RendererProps) => React.JSX.Element
|
|
76
|
-
|
|
77
|
-
export const DefaultRenderer: Renderer = ({
|
|
78
|
-
handleEntry,
|
|
79
|
-
label,
|
|
80
|
-
value,
|
|
81
|
-
subEntries = [],
|
|
82
|
-
subEntryPages = [],
|
|
83
|
-
type,
|
|
84
|
-
expanded = false,
|
|
85
|
-
toggleExpanded,
|
|
86
|
-
pageSize,
|
|
87
|
-
renderer,
|
|
88
|
-
}) => {
|
|
89
|
-
const [expandedPages, setExpandedPages] = React.useState<Array<number>>([])
|
|
90
|
-
const [valueSnapshot, setValueSnapshot] = React.useState(undefined)
|
|
91
|
-
const styles = useStyles()
|
|
92
|
-
|
|
93
|
-
const refreshValueSnapshot = () => {
|
|
94
|
-
setValueSnapshot((value as () => any)())
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<div className={styles.entry}>
|
|
99
|
-
{subEntryPages.length ? (
|
|
100
|
-
<>
|
|
101
|
-
<button
|
|
102
|
-
className={styles.expandButton}
|
|
103
|
-
onClick={() => toggleExpanded()}
|
|
104
|
-
>
|
|
105
|
-
<Expander expanded={expanded} />
|
|
106
|
-
{label}
|
|
107
|
-
<span className={styles.info}>
|
|
108
|
-
{String(type).toLowerCase() === 'iterable' ? '(Iterable) ' : ''}
|
|
109
|
-
{subEntries.length} {subEntries.length > 1 ? `items` : `item`}
|
|
110
|
-
</span>
|
|
111
|
-
</button>
|
|
112
|
-
{expanded ? (
|
|
113
|
-
subEntryPages.length === 1 ? (
|
|
114
|
-
<div className={styles.subEntries}>
|
|
115
|
-
{subEntries.map((entry, index) => handleEntry(entry))}
|
|
116
|
-
</div>
|
|
117
|
-
) : (
|
|
118
|
-
<div className={styles.subEntries}>
|
|
119
|
-
{subEntryPages.map((entries, index) => {
|
|
120
|
-
return (
|
|
121
|
-
<div key={index}>
|
|
122
|
-
<div className={styles.entry}>
|
|
123
|
-
<button
|
|
124
|
-
className={cx(styles.labelButton, 'labelButton')}
|
|
125
|
-
onClick={() =>
|
|
126
|
-
setExpandedPages((old) =>
|
|
127
|
-
old.includes(index)
|
|
128
|
-
? old.filter((d) => d !== index)
|
|
129
|
-
: [...old, index],
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
>
|
|
133
|
-
<Expander expanded={expandedPages.includes(index)} />{' '}
|
|
134
|
-
[{index * pageSize} ...{' '}
|
|
135
|
-
{index * pageSize + pageSize - 1}]
|
|
136
|
-
</button>
|
|
137
|
-
{expandedPages.includes(index) ? (
|
|
138
|
-
<div className={styles.subEntries}>
|
|
139
|
-
{entries.map((entry) => handleEntry(entry))}
|
|
140
|
-
</div>
|
|
141
|
-
) : null}
|
|
142
|
-
</div>
|
|
143
|
-
</div>
|
|
144
|
-
)
|
|
145
|
-
})}
|
|
146
|
-
</div>
|
|
147
|
-
)
|
|
148
|
-
) : null}
|
|
149
|
-
</>
|
|
150
|
-
) : type === 'function' ? (
|
|
151
|
-
<>
|
|
152
|
-
<Explorer
|
|
153
|
-
renderer={renderer}
|
|
154
|
-
label={
|
|
155
|
-
<button
|
|
156
|
-
onClick={refreshValueSnapshot}
|
|
157
|
-
className={styles.refreshValueBtn}
|
|
158
|
-
>
|
|
159
|
-
<span>{label}</span> 🔄{' '}
|
|
160
|
-
</button>
|
|
161
|
-
}
|
|
162
|
-
value={valueSnapshot}
|
|
163
|
-
defaultExpanded={{}}
|
|
164
|
-
/>
|
|
165
|
-
</>
|
|
166
|
-
) : (
|
|
167
|
-
<>
|
|
168
|
-
<span>{label}:</span>{' '}
|
|
169
|
-
<span className={styles.value}>{displayValue(value)}</span>
|
|
170
|
-
</>
|
|
171
|
-
)}
|
|
172
|
-
</div>
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
type HandleEntryFn = (entry: Entry) => React.ReactNode
|
|
177
|
-
|
|
178
|
-
type ExplorerProps = Partial<RendererProps> & {
|
|
179
|
-
renderer?: Renderer
|
|
180
|
-
defaultExpanded?: true | Record<string, boolean>
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
type Property = {
|
|
184
|
-
defaultExpanded?: boolean | Record<string, boolean>
|
|
185
|
-
label: string
|
|
186
|
-
value: unknown
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function isIterable(x: any): x is Iterable<unknown> {
|
|
190
|
-
return Symbol.iterator in x
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export default function Explorer({
|
|
194
|
-
value,
|
|
195
|
-
defaultExpanded,
|
|
196
|
-
renderer = DefaultRenderer,
|
|
197
|
-
pageSize = 100,
|
|
198
|
-
filterSubEntries,
|
|
199
|
-
...rest
|
|
200
|
-
}: ExplorerProps) {
|
|
201
|
-
const [expanded, setExpanded] = React.useState(Boolean(defaultExpanded))
|
|
202
|
-
const toggleExpanded = React.useCallback(() => setExpanded((old) => !old), [])
|
|
203
|
-
|
|
204
|
-
let type: string = typeof value
|
|
205
|
-
let subEntries: Array<Property> = []
|
|
206
|
-
|
|
207
|
-
const makeProperty = (sub: { label: string; value: unknown }): Property => {
|
|
208
|
-
const subDefaultExpanded =
|
|
209
|
-
defaultExpanded === true
|
|
210
|
-
? { [sub.label]: true }
|
|
211
|
-
: defaultExpanded?.[sub.label]
|
|
212
|
-
return {
|
|
213
|
-
...sub,
|
|
214
|
-
defaultExpanded: subDefaultExpanded,
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (Array.isArray(value)) {
|
|
219
|
-
type = 'array'
|
|
220
|
-
subEntries = value.map((d, i) =>
|
|
221
|
-
makeProperty({
|
|
222
|
-
label: i.toString(),
|
|
223
|
-
value: d,
|
|
224
|
-
}),
|
|
225
|
-
)
|
|
226
|
-
} else if (
|
|
227
|
-
value !== null &&
|
|
228
|
-
typeof value === 'object' &&
|
|
229
|
-
isIterable(value) &&
|
|
230
|
-
typeof value[Symbol.iterator] === 'function'
|
|
231
|
-
) {
|
|
232
|
-
type = 'Iterable'
|
|
233
|
-
subEntries = Array.from(value, (val, i) =>
|
|
234
|
-
makeProperty({
|
|
235
|
-
label: i.toString(),
|
|
236
|
-
value: val,
|
|
237
|
-
}),
|
|
238
|
-
)
|
|
239
|
-
} else if (typeof value === 'object' && value !== null) {
|
|
240
|
-
type = 'object'
|
|
241
|
-
subEntries = Object.entries(value).map(([key, val]) =>
|
|
242
|
-
makeProperty({
|
|
243
|
-
label: key,
|
|
244
|
-
value: val,
|
|
245
|
-
}),
|
|
246
|
-
)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
subEntries = filterSubEntries ? filterSubEntries(subEntries) : subEntries
|
|
250
|
-
|
|
251
|
-
const subEntryPages = chunkArray(subEntries, pageSize)
|
|
252
|
-
|
|
253
|
-
return renderer({
|
|
254
|
-
handleEntry: (entry) => (
|
|
255
|
-
<Explorer
|
|
256
|
-
key={entry.label}
|
|
257
|
-
value={value}
|
|
258
|
-
renderer={renderer}
|
|
259
|
-
filterSubEntries={filterSubEntries}
|
|
260
|
-
{...rest}
|
|
261
|
-
{...entry}
|
|
262
|
-
/>
|
|
263
|
-
),
|
|
264
|
-
type,
|
|
265
|
-
subEntries,
|
|
266
|
-
subEntryPages,
|
|
267
|
-
value,
|
|
268
|
-
expanded,
|
|
269
|
-
toggleExpanded,
|
|
270
|
-
pageSize,
|
|
271
|
-
...rest,
|
|
272
|
-
})
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const stylesFactory = (shadowDOMTarget?: ShadowRoot) => {
|
|
276
|
-
const { colors, font, size, alpha, shadow, border } = tokens
|
|
277
|
-
const { fontFamily, lineHeight, size: fontSize } = font
|
|
278
|
-
const css = shadowDOMTarget
|
|
279
|
-
? goober.css.bind({ target: shadowDOMTarget })
|
|
280
|
-
: goober.css
|
|
281
|
-
|
|
282
|
-
return {
|
|
283
|
-
entry: css`
|
|
284
|
-
font-family: ${fontFamily.mono};
|
|
285
|
-
font-size: ${fontSize.xs};
|
|
286
|
-
line-height: ${lineHeight.sm};
|
|
287
|
-
outline: none;
|
|
288
|
-
word-break: break-word;
|
|
289
|
-
`,
|
|
290
|
-
labelButton: css`
|
|
291
|
-
cursor: pointer;
|
|
292
|
-
color: inherit;
|
|
293
|
-
font: inherit;
|
|
294
|
-
outline: inherit;
|
|
295
|
-
background: transparent;
|
|
296
|
-
border: none;
|
|
297
|
-
padding: 0;
|
|
298
|
-
`,
|
|
299
|
-
expander: css`
|
|
300
|
-
display: inline-flex;
|
|
301
|
-
align-items: center;
|
|
302
|
-
justify-content: center;
|
|
303
|
-
width: ${size[3]};
|
|
304
|
-
height: ${size[3]};
|
|
305
|
-
padding-left: 3px;
|
|
306
|
-
box-sizing: content-box;
|
|
307
|
-
`,
|
|
308
|
-
expanderIcon: (expanded: boolean) => {
|
|
309
|
-
if (expanded) {
|
|
310
|
-
return css`
|
|
311
|
-
transform: rotate(90deg);
|
|
312
|
-
transition: transform 0.1s ease;
|
|
313
|
-
`
|
|
314
|
-
}
|
|
315
|
-
return css`
|
|
316
|
-
transform: rotate(0deg);
|
|
317
|
-
transition: transform 0.1s ease;
|
|
318
|
-
`
|
|
319
|
-
},
|
|
320
|
-
expandButton: css`
|
|
321
|
-
display: flex;
|
|
322
|
-
gap: ${size[1]};
|
|
323
|
-
align-items: center;
|
|
324
|
-
cursor: pointer;
|
|
325
|
-
color: inherit;
|
|
326
|
-
font: inherit;
|
|
327
|
-
outline: inherit;
|
|
328
|
-
background: transparent;
|
|
329
|
-
border: none;
|
|
330
|
-
padding: 0;
|
|
331
|
-
`,
|
|
332
|
-
value: css`
|
|
333
|
-
color: ${colors.purple[400]};
|
|
334
|
-
`,
|
|
335
|
-
subEntries: css`
|
|
336
|
-
margin-left: ${size[2]};
|
|
337
|
-
padding-left: ${size[2]};
|
|
338
|
-
border-left: 2px solid ${colors.darkGray[400]};
|
|
339
|
-
`,
|
|
340
|
-
info: css`
|
|
341
|
-
color: ${colors.gray[500]};
|
|
342
|
-
font-size: ${fontSize['2xs']};
|
|
343
|
-
padding-left: ${size[1]};
|
|
344
|
-
`,
|
|
345
|
-
refreshValueBtn: css`
|
|
346
|
-
appearance: none;
|
|
347
|
-
border: 0;
|
|
348
|
-
cursor: pointer;
|
|
349
|
-
background: transparent;
|
|
350
|
-
color: inherit;
|
|
351
|
-
padding: 0;
|
|
352
|
-
font-family: ${fontFamily.mono};
|
|
353
|
-
font-size: ${fontSize.xs};
|
|
354
|
-
`,
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function useStyles() {
|
|
359
|
-
const shadowDomTarget = React.useContext(ShadowDomTargetContext)
|
|
360
|
-
const [_styles] = React.useState(() => stylesFactory(shadowDomTarget))
|
|
361
|
-
return _styles
|
|
362
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { clsx as cx } from 'clsx'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import { DevtoolsOnCloseContext, ShadowDomTargetContext } from './context'
|
|
4
|
-
import { useIsMounted, useSafeState } from './utils'
|
|
5
|
-
import { BaseTanStackRouterDevtoolsPanel } from './BaseTanStackRouterDevtoolsPanel'
|
|
6
|
-
import useLocalStorage from './useLocalStorage'
|
|
7
|
-
import { TanStackLogo } from './logo'
|
|
8
|
-
import { useStyles } from './useStyles'
|
|
9
|
-
import type { AnyRouter } from '@tanstack/react-router'
|
|
10
|
-
|
|
11
|
-
interface DevtoolsOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Set this true if you want the dev tools to default to being open
|
|
14
|
-
*/
|
|
15
|
-
initialIsOpen?: boolean
|
|
16
|
-
/**
|
|
17
|
-
* Use this to add props to the panel. For example, you can add className, style (merge and override default style), etc.
|
|
18
|
-
*/
|
|
19
|
-
panelProps?: React.DetailedHTMLProps<
|
|
20
|
-
React.HTMLAttributes<HTMLDivElement>,
|
|
21
|
-
HTMLDivElement
|
|
22
|
-
>
|
|
23
|
-
/**
|
|
24
|
-
* 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.
|
|
25
|
-
*/
|
|
26
|
-
closeButtonProps?: React.DetailedHTMLProps<
|
|
27
|
-
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
28
|
-
HTMLButtonElement
|
|
29
|
-
>
|
|
30
|
-
/**
|
|
31
|
-
* 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.
|
|
32
|
-
*/
|
|
33
|
-
toggleButtonProps?: React.DetailedHTMLProps<
|
|
34
|
-
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
35
|
-
HTMLButtonElement
|
|
36
|
-
>
|
|
37
|
-
/**
|
|
38
|
-
* The position of the TanStack Router logo to open and close the devtools panel.
|
|
39
|
-
* Defaults to 'bottom-left'.
|
|
40
|
-
*/
|
|
41
|
-
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
|
42
|
-
/**
|
|
43
|
-
* Use this to render the devtools inside a different type of container element for a11y purposes.
|
|
44
|
-
* Any string which corresponds to a valid intrinsic JSX element is allowed.
|
|
45
|
-
* Defaults to 'footer'.
|
|
46
|
-
*/
|
|
47
|
-
containerElement?: string | any
|
|
48
|
-
/**
|
|
49
|
-
* A boolean variable indicating if the "lite" version of the library is being used
|
|
50
|
-
*/
|
|
51
|
-
router?: AnyRouter
|
|
52
|
-
/**
|
|
53
|
-
* Use this to attach the devtool's styles to specific element in the DOM.
|
|
54
|
-
*/
|
|
55
|
-
shadowDOMTarget?: ShadowRoot
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function TanStackRouterDevtools(
|
|
59
|
-
props: DevtoolsOptions,
|
|
60
|
-
): React.ReactElement | null {
|
|
61
|
-
const { shadowDOMTarget } = props
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<ShadowDomTargetContext.Provider value={shadowDOMTarget}>
|
|
65
|
-
<FloatingTanStackRouterDevtools {...props} />
|
|
66
|
-
</ShadowDomTargetContext.Provider>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function FloatingTanStackRouterDevtools({
|
|
71
|
-
initialIsOpen,
|
|
72
|
-
panelProps = {},
|
|
73
|
-
closeButtonProps = {},
|
|
74
|
-
toggleButtonProps = {},
|
|
75
|
-
position = 'bottom-left',
|
|
76
|
-
containerElement: Container = 'footer',
|
|
77
|
-
router,
|
|
78
|
-
shadowDOMTarget,
|
|
79
|
-
}: DevtoolsOptions): React.ReactElement | null {
|
|
80
|
-
const [rootEl, setRootEl] = React.useState<HTMLDivElement>()
|
|
81
|
-
const panelRef = React.useRef<HTMLDivElement>(null)
|
|
82
|
-
const [isOpen, setIsOpen] = useLocalStorage(
|
|
83
|
-
'tanstackRouterDevtoolsOpen',
|
|
84
|
-
initialIsOpen,
|
|
85
|
-
)
|
|
86
|
-
const [devtoolsHeight, setDevtoolsHeight] = useLocalStorage<number | null>(
|
|
87
|
-
'tanstackRouterDevtoolsHeight',
|
|
88
|
-
null,
|
|
89
|
-
)
|
|
90
|
-
const [isResolvedOpen, setIsResolvedOpen] = useSafeState(false)
|
|
91
|
-
const [isResizing, setIsResizing] = useSafeState(false)
|
|
92
|
-
const isMounted = useIsMounted()
|
|
93
|
-
const styles = useStyles()
|
|
94
|
-
|
|
95
|
-
const handleDragStart = (
|
|
96
|
-
panelElement: HTMLDivElement | null,
|
|
97
|
-
startEvent: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
98
|
-
) => {
|
|
99
|
-
if (startEvent.button !== 0) return // Only allow left click for drag
|
|
100
|
-
|
|
101
|
-
setIsResizing(true)
|
|
102
|
-
|
|
103
|
-
const dragInfo = {
|
|
104
|
-
originalHeight: panelElement?.getBoundingClientRect().height ?? 0,
|
|
105
|
-
pageY: startEvent.pageY,
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const run = (moveEvent: MouseEvent) => {
|
|
109
|
-
const delta = dragInfo.pageY - moveEvent.pageY
|
|
110
|
-
const newHeight = dragInfo.originalHeight + delta
|
|
111
|
-
|
|
112
|
-
setDevtoolsHeight(newHeight)
|
|
113
|
-
|
|
114
|
-
if (newHeight < 70) {
|
|
115
|
-
setIsOpen(false)
|
|
116
|
-
} else {
|
|
117
|
-
setIsOpen(true)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const unsub = () => {
|
|
122
|
-
setIsResizing(false)
|
|
123
|
-
document.removeEventListener('mousemove', run)
|
|
124
|
-
document.removeEventListener('mouseUp', unsub)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
document.addEventListener('mousemove', run)
|
|
128
|
-
document.addEventListener('mouseup', unsub)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const isButtonClosed = isOpen ?? false
|
|
132
|
-
|
|
133
|
-
React.useEffect(() => {
|
|
134
|
-
setIsResolvedOpen(isOpen ?? false)
|
|
135
|
-
}, [isOpen, isResolvedOpen, setIsResolvedOpen])
|
|
136
|
-
|
|
137
|
-
React.useEffect(() => {
|
|
138
|
-
if (isResolvedOpen) {
|
|
139
|
-
const previousValue = rootEl?.parentElement?.style.paddingBottom
|
|
140
|
-
|
|
141
|
-
const run = () => {
|
|
142
|
-
const containerHeight = panelRef.current?.getBoundingClientRect().height
|
|
143
|
-
if (rootEl?.parentElement) {
|
|
144
|
-
rootEl.parentElement.style.paddingBottom = `${containerHeight}px`
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
run()
|
|
149
|
-
|
|
150
|
-
if (typeof window !== 'undefined') {
|
|
151
|
-
window.addEventListener('resize', run)
|
|
152
|
-
|
|
153
|
-
return () => {
|
|
154
|
-
window.removeEventListener('resize', run)
|
|
155
|
-
if (rootEl?.parentElement && typeof previousValue === 'string') {
|
|
156
|
-
rootEl.parentElement.style.paddingBottom = previousValue
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return
|
|
162
|
-
}, [isResolvedOpen, rootEl?.parentElement])
|
|
163
|
-
|
|
164
|
-
React.useEffect(() => {
|
|
165
|
-
if (rootEl) {
|
|
166
|
-
const el = rootEl
|
|
167
|
-
const fontSize = getComputedStyle(el).fontSize
|
|
168
|
-
el.style.setProperty('--tsrd-font-size', fontSize)
|
|
169
|
-
}
|
|
170
|
-
}, [rootEl])
|
|
171
|
-
|
|
172
|
-
const { style: panelStyle = {}, ...otherPanelProps } = panelProps
|
|
173
|
-
|
|
174
|
-
const {
|
|
175
|
-
style: closeButtonStyle = {},
|
|
176
|
-
onClick: onCloseClick,
|
|
177
|
-
...otherCloseButtonProps
|
|
178
|
-
} = closeButtonProps
|
|
179
|
-
|
|
180
|
-
const {
|
|
181
|
-
onClick: onToggleClick,
|
|
182
|
-
className: toggleButtonClassName,
|
|
183
|
-
...otherToggleButtonProps
|
|
184
|
-
} = toggleButtonProps
|
|
185
|
-
|
|
186
|
-
// Do not render on the server
|
|
187
|
-
if (!isMounted) return null
|
|
188
|
-
|
|
189
|
-
const resolvedHeight = devtoolsHeight ?? 500
|
|
190
|
-
|
|
191
|
-
return (
|
|
192
|
-
<Container ref={setRootEl} className="TanStackRouterDevtools">
|
|
193
|
-
<DevtoolsOnCloseContext.Provider
|
|
194
|
-
value={{
|
|
195
|
-
onCloseClick: onCloseClick ?? (() => {}),
|
|
196
|
-
}}
|
|
197
|
-
>
|
|
198
|
-
<BaseTanStackRouterDevtoolsPanel
|
|
199
|
-
ref={panelRef as any}
|
|
200
|
-
{...otherPanelProps}
|
|
201
|
-
router={router}
|
|
202
|
-
className={cx(
|
|
203
|
-
styles.devtoolsPanelContainer,
|
|
204
|
-
styles.devtoolsPanelContainerVisibility(!!isOpen),
|
|
205
|
-
styles.devtoolsPanelContainerResizing(isResizing),
|
|
206
|
-
styles.devtoolsPanelContainerAnimation(
|
|
207
|
-
isResolvedOpen,
|
|
208
|
-
resolvedHeight + 16,
|
|
209
|
-
),
|
|
210
|
-
)}
|
|
211
|
-
style={{
|
|
212
|
-
height: resolvedHeight,
|
|
213
|
-
...panelStyle,
|
|
214
|
-
}}
|
|
215
|
-
isOpen={isResolvedOpen}
|
|
216
|
-
setIsOpen={setIsOpen}
|
|
217
|
-
handleDragStart={(e) => handleDragStart(panelRef.current, e)}
|
|
218
|
-
shadowDOMTarget={shadowDOMTarget}
|
|
219
|
-
/>
|
|
220
|
-
</DevtoolsOnCloseContext.Provider>
|
|
221
|
-
|
|
222
|
-
<button
|
|
223
|
-
type="button"
|
|
224
|
-
{...otherToggleButtonProps}
|
|
225
|
-
aria-label="Open TanStack Router Devtools"
|
|
226
|
-
onClick={(e) => {
|
|
227
|
-
setIsOpen(true)
|
|
228
|
-
onToggleClick && onToggleClick(e)
|
|
229
|
-
}}
|
|
230
|
-
className={cx(
|
|
231
|
-
styles.mainCloseBtn,
|
|
232
|
-
styles.mainCloseBtnPosition(position),
|
|
233
|
-
styles.mainCloseBtnAnimation(!isButtonClosed),
|
|
234
|
-
toggleButtonClassName,
|
|
235
|
-
)}
|
|
236
|
-
>
|
|
237
|
-
<div className={styles.mainCloseBtnIconContainer}>
|
|
238
|
-
<div className={styles.mainCloseBtnIconOuter}>
|
|
239
|
-
<TanStackLogo />
|
|
240
|
-
</div>
|
|
241
|
-
<div className={styles.mainCloseBtnIconInner}>
|
|
242
|
-
<TanStackLogo />
|
|
243
|
-
</div>
|
|
244
|
-
</div>
|
|
245
|
-
<div className={styles.mainCloseBtnDivider}>-</div>
|
|
246
|
-
<div className={styles.routerLogoCloseButton}>TanStack Router</div>
|
|
247
|
-
</button>
|
|
248
|
-
</Container>
|
|
249
|
-
)
|
|
250
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { DevtoolsOnCloseContext, ShadowDomTargetContext } from './context'
|
|
3
|
-
import { BaseTanStackRouterDevtoolsPanel } from './BaseTanStackRouterDevtoolsPanel'
|
|
4
|
-
import type { AnyRouter } from '@tanstack/react-router'
|
|
5
|
-
|
|
6
|
-
export interface DevtoolsPanelOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The standard React style object used to style a component with inline styles
|
|
9
|
-
*/
|
|
10
|
-
style?: React.CSSProperties
|
|
11
|
-
/**
|
|
12
|
-
* The standard React className property used to style a component with classes
|
|
13
|
-
*/
|
|
14
|
-
className?: string
|
|
15
|
-
/**
|
|
16
|
-
* A boolean variable indicating whether the panel is open or closed
|
|
17
|
-
*/
|
|
18
|
-
isOpen?: boolean
|
|
19
|
-
/**
|
|
20
|
-
* A function that toggles the open and close state of the panel
|
|
21
|
-
*/
|
|
22
|
-
setIsOpen: (isOpen: boolean) => void
|
|
23
|
-
/**
|
|
24
|
-
* Handles the opening and closing the devtools panel
|
|
25
|
-
*/
|
|
26
|
-
handleDragStart?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
|
|
27
|
-
/**
|
|
28
|
-
* A boolean variable indicating if the "lite" version of the library is being used
|
|
29
|
-
*/
|
|
30
|
-
router?: AnyRouter
|
|
31
|
-
/**
|
|
32
|
-
* Use this to attach the devtool's styles to specific element in the DOM.
|
|
33
|
-
*/
|
|
34
|
-
shadowDOMTarget?: ShadowRoot
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const TanStackRouterDevtoolsPanel = React.forwardRef<
|
|
38
|
-
HTMLDivElement,
|
|
39
|
-
DevtoolsPanelOptions
|
|
40
|
-
>(function TanStackRouterDevtoolsPanel(props, ref) {
|
|
41
|
-
const { shadowDOMTarget } = props
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<ShadowDomTargetContext.Provider value={shadowDOMTarget}>
|
|
45
|
-
<DevtoolsOnCloseContext.Provider
|
|
46
|
-
value={{
|
|
47
|
-
onCloseClick: () => {},
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
<BaseTanStackRouterDevtoolsPanel ref={ref} {...props} />
|
|
51
|
-
</DevtoolsOnCloseContext.Provider>
|
|
52
|
-
</ShadowDomTargetContext.Provider>
|
|
53
|
-
)
|
|
54
|
-
})
|
package/src/context.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
export const ShadowDomTargetContext = React.createContext<
|
|
4
|
-
ShadowRoot | undefined
|
|
5
|
-
>(undefined)
|
|
6
|
-
|
|
7
|
-
export const DevtoolsOnCloseContext = React.createContext<
|
|
8
|
-
| {
|
|
9
|
-
onCloseClick: (e: React.MouseEvent<HTMLButtonElement>) => void
|
|
10
|
-
}
|
|
11
|
-
| undefined
|
|
12
|
-
>(undefined)
|
|
13
|
-
|
|
14
|
-
export const useDevtoolsOnClose = () => {
|
|
15
|
-
const context = React.useContext(DevtoolsOnCloseContext)
|
|
16
|
-
if (!context) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
'useDevtoolsOnClose must be used within a TanStackRouterDevtools component',
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
return context
|
|
22
|
-
}
|