@tanstack/router-devtools 1.111.11 → 1.112.4

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 (48) hide show
  1. package/dist/cjs/AgeTicker.cjs +58 -0
  2. package/dist/cjs/AgeTicker.cjs.map +1 -0
  3. package/dist/cjs/AgeTicker.d.cts +5 -0
  4. package/dist/cjs/BaseTanStackRouterDevtoolsPanel.cjs +421 -0
  5. package/dist/cjs/BaseTanStackRouterDevtoolsPanel.cjs.map +1 -0
  6. package/dist/cjs/BaseTanStackRouterDevtoolsPanel.d.cts +3 -0
  7. package/dist/cjs/TanStackRouterDevtools.cjs +177 -0
  8. package/dist/cjs/TanStackRouterDevtools.cjs.map +1 -0
  9. package/dist/cjs/{devtools.d.cts → TanStackRouterDevtools.d.cts} +0 -31
  10. package/dist/cjs/TanStackRouterDevtoolsPanel.cjs +21 -0
  11. package/dist/cjs/TanStackRouterDevtoolsPanel.cjs.map +1 -0
  12. package/dist/cjs/TanStackRouterDevtoolsPanel.d.cts +33 -0
  13. package/dist/cjs/index.cjs +4 -3
  14. package/dist/cjs/index.cjs.map +1 -1
  15. package/dist/cjs/index.d.cts +2 -1
  16. package/dist/cjs/useStyles.cjs +570 -0
  17. package/dist/cjs/useStyles.cjs.map +1 -0
  18. package/dist/cjs/useStyles.d.cts +52 -0
  19. package/dist/esm/AgeTicker.d.ts +5 -0
  20. package/dist/esm/AgeTicker.js +58 -0
  21. package/dist/esm/AgeTicker.js.map +1 -0
  22. package/dist/esm/BaseTanStackRouterDevtoolsPanel.d.ts +3 -0
  23. package/dist/esm/BaseTanStackRouterDevtoolsPanel.js +421 -0
  24. package/dist/esm/BaseTanStackRouterDevtoolsPanel.js.map +1 -0
  25. package/dist/esm/{devtools.d.ts → TanStackRouterDevtools.d.ts} +0 -31
  26. package/dist/esm/TanStackRouterDevtools.js +177 -0
  27. package/dist/esm/TanStackRouterDevtools.js.map +1 -0
  28. package/dist/esm/TanStackRouterDevtoolsPanel.d.ts +33 -0
  29. package/dist/esm/TanStackRouterDevtoolsPanel.js +21 -0
  30. package/dist/esm/TanStackRouterDevtoolsPanel.js.map +1 -0
  31. package/dist/esm/index.d.ts +2 -1
  32. package/dist/esm/index.js +2 -1
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/useStyles.d.ts +52 -0
  35. package/dist/esm/useStyles.js +553 -0
  36. package/dist/esm/useStyles.js.map +1 -0
  37. package/package.json +2 -2
  38. package/src/AgeTicker.tsx +73 -0
  39. package/src/BaseTanStackRouterDevtoolsPanel.tsx +488 -0
  40. package/src/TanStackRouterDevtools.tsx +250 -0
  41. package/src/TanStackRouterDevtoolsPanel.tsx +54 -0
  42. package/src/index.tsx +2 -1
  43. package/src/useStyles.tsx +589 -0
  44. package/dist/cjs/devtools.cjs +0 -1212
  45. package/dist/cjs/devtools.cjs.map +0 -1
  46. package/dist/esm/devtools.js +0 -1195
  47. package/dist/esm/devtools.js.map +0 -1
  48. package/src/devtools.tsx +0 -1443
@@ -0,0 +1,250 @@
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
+ }
@@ -0,0 +1,54 @@
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/index.tsx CHANGED
@@ -1 +1,2 @@
1
- export { TanStackRouterDevtools, TanStackRouterDevtoolsPanel } from './devtools'
1
+ export { TanStackRouterDevtools } from './TanStackRouterDevtools'
2
+ export { TanStackRouterDevtoolsPanel } from './TanStackRouterDevtoolsPanel'