From 63d3526b7c247d533a550aae9003e22a9982e0d1 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Wed, 8 Oct 2025 15:29:03 +0200 Subject: [PATCH 1/2] fix: issue with responsiveness in jsontree --- .changeset/wicked-cobras-peel.md | 5 + packages/devtools-ui/src/components/tree.tsx | 206 ++++++++----------- 2 files changed, 95 insertions(+), 116 deletions(-) create mode 100644 .changeset/wicked-cobras-peel.md diff --git a/.changeset/wicked-cobras-peel.md b/.changeset/wicked-cobras-peel.md new file mode 100644 index 00000000..02a59266 --- /dev/null +++ b/.changeset/wicked-cobras-peel.md @@ -0,0 +1,5 @@ +--- +'@tanstack/devtools-ui': patch +--- + +fix responsiveness in jsontree diff --git a/packages/devtools-ui/src/components/tree.tsx b/packages/devtools-ui/src/components/tree.tsx index a1291fd3..bb4a6023 100644 --- a/packages/devtools-ui/src/components/tree.tsx +++ b/packages/devtools-ui/src/components/tree.tsx @@ -10,6 +10,7 @@ export function JsonTree>(props: { defaultExpansionDepth?: number collapsePaths?: Array }) { + return ( path: string }) { - const { - value, - keyName, - isRoot = false, - isLastKey, - copyable, - defaultExpansionDepth, - depth, - collapsePaths, - path, - } = props + const styles = useStyles() return ( - - {keyName && typeof value !== 'object' && !Array.isArray(value) && ( - "{keyName}": + + {props.keyName && typeof props.value !== 'object' && !Array.isArray(props.value) && ( + "{props.keyName}": )} {(() => { - if (typeof value === 'string') { + if (typeof props.value === 'string') { return ( - "{value}" + "{props.value}" ) } - if (typeof value === 'number') { - return {value} + if (typeof props.value === 'number') { + return {props.value} } - if (typeof value === 'boolean') { - return {String(value)} + if (typeof props.value === 'boolean') { + return {String(props.value)} } - if (value === null) { + if (props.value === null) { return null } - if (value === undefined) { + if (props.value === undefined) { return undefined } - if (typeof value === 'function') { + if (typeof props.value === 'function') { return ( - {String(value)} + {String(props.value)} ) } - if (Array.isArray(value)) { + if (Array.isArray(props.value)) { return ( ) } - if (typeof value === 'object') { + if (typeof props.value === 'object') { return ( ) } return })()} - {copyable && ( + {props.copyable && (
- +
)} - {isLastKey || isRoot ? '' : ,} + {props.isLastKey || props.isRoot ? '' : ,}
) } -const ArrayValue = ({ - value, - keyName, - copyable, - defaultExpansionDepth, - depth, - collapsePaths, - path, -}: { +const ArrayValue = (props: { value: Array copyable?: boolean keyName?: string @@ -135,15 +118,15 @@ const ArrayValue = ({ const styles = useStyles() const [expanded, setExpanded] = createSignal( - depth <= defaultExpansionDepth && !collapsePaths?.includes(path), + props.depth <= props.defaultExpansionDepth && !props.collapsePaths?.includes(props.path), ) - if (value.length === 0) { + if (props.value.length === 0) { return ( - {keyName && ( + {props.keyName && ( - "{keyName}":{' '} + "{props.keyName}":{' '} )} @@ -158,7 +141,7 @@ const ArrayValue = ({ expanded={expanded()} /> - {keyName && ( + {props.keyName && ( { e.stopPropagation() @@ -167,27 +150,27 @@ const ArrayValue = ({ }} class={clsx(styles().tree.valueKey, styles().tree.collapsible)} > - "{keyName}":{' '} - {value.length} items + "{props.keyName}":{' '} + {props.value.length} items )} [ - - + + {(item, i) => { - const isLastKey = i() === value.length - 1 + const isLastKey = i() === props.value.length - 1 return ( ) }} @@ -212,15 +195,7 @@ const ArrayValue = ({ ) } -const ObjectValue = ({ - value, - keyName, - copyable, - defaultExpansionDepth, - depth, - collapsePaths, - path, -}: { +const ObjectValue = (props: { value: Record keyName?: string copyable?: boolean @@ -232,18 +207,18 @@ const ObjectValue = ({ const styles = useStyles() const [expanded, setExpanded] = createSignal( - depth <= defaultExpansionDepth && !collapsePaths?.includes(path), + props.depth <= props.defaultExpansionDepth && !props.collapsePaths?.includes(props.path), ) - const keys = Object.keys(value) + const keys = Object.keys(props.value) const lastKeyName = keys[keys.length - 1] if (keys.length === 0) { return ( - {keyName && ( + {props.keyName && ( - "{keyName}":{' '} + "{props.keyName}":{' '} )} @@ -254,14 +229,14 @@ const ObjectValue = ({ return ( - {keyName && ( + {props.keyName && ( setExpanded(!expanded())} expanded={expanded()} /> )} - {keyName && ( + {props.keyName && ( { e.stopPropagation() @@ -270,7 +245,7 @@ const ObjectValue = ({ }} class={clsx(styles().tree.valueKey, styles().tree.collapsible)} > - "{keyName}":{' '} + "{props.keyName}":{' '} {keys.length} items )} @@ -278,19 +253,19 @@ const ObjectValue = ({ {'{'} - + {(k) => ( <> )} @@ -326,34 +301,33 @@ const CopyButton = (props: { value: unknown }) => {