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..590c8dc8 100644 --- a/packages/devtools-ui/src/components/tree.tsx +++ b/packages/devtools-ui/src/components/tree.tsx @@ -36,94 +36,87 @@ function JsonValue(props: { collapsePaths?: Array 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 +128,16 @@ 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 +152,7 @@ const ArrayValue = ({ expanded={expanded()} /> - {keyName && ( + {props.keyName && ( { e.stopPropagation() @@ -167,27 +161,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 +206,7 @@ const ArrayValue = ({ ) } -const ObjectValue = ({ - value, - keyName, - copyable, - defaultExpansionDepth, - depth, - collapsePaths, - path, -}: { +const ObjectValue = (props: { value: Record keyName?: string copyable?: boolean @@ -232,18 +218,19 @@ 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 +241,14 @@ const ObjectValue = ({ return ( - {keyName && ( + {props.keyName && ( setExpanded(!expanded())} expanded={expanded()} /> )} - {keyName && ( + {props.keyName && ( { e.stopPropagation() @@ -270,7 +257,7 @@ const ObjectValue = ({ }} class={clsx(styles().tree.valueKey, styles().tree.collapsible)} > - "{keyName}":{' '} + "{props.keyName}":{' '} {keys.length} items )} @@ -278,19 +265,19 @@ const ObjectValue = ({ {'{'} - + {(k) => ( <> )}