diff --git a/.changeset/thin-cougars-fly.md b/.changeset/thin-cougars-fly.md new file mode 100644 index 00000000..c2961964 --- /dev/null +++ b/.changeset/thin-cougars-fly.md @@ -0,0 +1,7 @@ +--- +'@tanstack/react-devtools': minor +'@tanstack/solid-devtools': minor +'@tanstack/devtools-ui': minor +--- + +Added json tree to devtools-ui and adjusted the width for the plugin renderers diff --git a/packages/devtools-ui/src/components/tree.tsx b/packages/devtools-ui/src/components/tree.tsx new file mode 100644 index 00000000..ba048d36 --- /dev/null +++ b/packages/devtools-ui/src/components/tree.tsx @@ -0,0 +1,134 @@ +import { For } from 'solid-js' +import { useStyles } from '../styles/use-styles' + +export function JsonTree(props: { value: any }) { + return +} + +function JsonValue(props: { + value: any + keyName?: string + isRoot?: boolean + isLastKey?: boolean +}) { + const { value, keyName, isRoot = false, isLastKey } = props + const styles = useStyles() + + return ( + + {(() => { + if (typeof value === 'string') { + return ( + + {keyName && ( + + "{keyName}":{' '} + + )} + "{value}" + + ) + } + if (typeof value === 'number') { + return ( + + {keyName && ( + + "{keyName}":{' '} + + )} + {value} + + ) + } + if (typeof value === 'boolean') { + return ( + + {keyName && ( + + "{keyName}":{' '} + + )} + {String(value)} + + ) + } + if (value === null) { + return ( + + {keyName && ( + + "{keyName}":{' '} + + )} + null + + ) + } + if (value === undefined) { + return ( + + {keyName && ( + + "{keyName}":{' '} + + )} + undefined + + ) + } + if (Array.isArray(value)) { + return ( + + {keyName && ( + + "{keyName}":{' '} + + )} + [ + + {(item, i) => { + const isLastKey = i() === value.length - 1 + return ( + <> + + + ) + }} + + ] + + ) + } + if (typeof value === 'object') { + const keys = Object.keys(value) + const lastKeyName = keys[keys.length - 1] + return ( + + {keyName && ( + + "{keyName}":{' '} + + )} + {'{'} + + {(k) => ( + <> + + + )} + + {'}'} + + ) + } + return + })()} + {isLastKey || isRoot ? '' : ,} + + ) +} diff --git a/packages/devtools-ui/src/index.ts b/packages/devtools-ui/src/index.ts index dfaa2666..ccbd745c 100644 --- a/packages/devtools-ui/src/index.ts +++ b/packages/devtools-ui/src/index.ts @@ -2,3 +2,4 @@ export { Checkbox } from './components/checkbox' export { Input } from './components/input' export { Select } from './components/select' export { TanStackLogo } from './components/logo' +export { JsonTree } from './components/tree' diff --git a/packages/devtools-ui/src/styles/use-styles.ts b/packages/devtools-ui/src/styles/use-styles.ts index 26926077..919ccf48 100644 --- a/packages/devtools-ui/src/styles/use-styles.ts +++ b/packages/devtools-ui/src/styles/use-styles.ts @@ -186,6 +186,31 @@ const stylesFactory = () => { font-size: 0.8rem; line-height: 1.3; `, + tree: { + valueString: css` + color: ${colors.green[400]}; + `, + valueNumber: css` + color: ${colors.yellow[400]}; + `, + valueBoolean: css` + color: ${colors.pink[400]}; + `, + valueNull: css` + color: ${colors.gray[400]}; + font-style: italic; + `, + valueKey: css` + color: ${colors.blue[300]}; + `, + valueBraces: css` + color: ${colors.gray[500]}; + `, + valueContainer: (isRoot: boolean) => css` + display: block; + margin-left: ${isRoot ? '0' : '1rem'}; + `, + }, } } diff --git a/packages/react-devtools/src/devtools.tsx b/packages/react-devtools/src/devtools.tsx index c988c289..60f4d3d7 100644 --- a/packages/react-devtools/src/devtools.tsx +++ b/packages/react-devtools/src/devtools.tsx @@ -153,7 +153,7 @@ export const TanstackDevtools = ({ return ( <> -
+
{pluginContainer && PluginComponent ? createPortal(<>{PluginComponent}, pluginContainer) : null} diff --git a/packages/solid-devtools/src/devtools.tsx b/packages/solid-devtools/src/devtools.tsx index 795a6943..739aa6e2 100644 --- a/packages/solid-devtools/src/devtools.tsx +++ b/packages/solid-devtools/src/devtools.tsx @@ -126,5 +126,5 @@ export const TanstackDevtools = ({ }) } }) - return
+ return
}