11import { DataFrame , stringify } from 'hightable'
2- import { useEffect , useState } from 'react'
2+ import { ReactNode , useEffect , useState } from 'react'
33import { useConfig } from '../../hooks/useConfig.js'
44import { cn } from '../../lib/utils.js'
55import ContentWrapper from '../ContentWrapper/ContentWrapper.js'
6+ import Json from '../Json/Json.js'
67import SlideCloseButton from '../SlideCloseButton/SlideCloseButton.js'
78import styles from '../TextView/TextView.module.css'
9+ import jsonStyles from '../Json/Json.module.css'
810
911interface ViewerProps {
1012 df : DataFrame
@@ -19,7 +21,7 @@ interface ViewerProps {
1921 * Cell viewer displays a single cell from a table.
2022 */
2123export default function CellPanel ( { df, row, col, setProgress, setError, onClose } : ViewerProps ) {
22- const [ text , setText ] = useState < string | undefined > ( )
24+ const [ content , setContent ] = useState < ReactNode > ( )
2325 const { customClass } = useConfig ( )
2426
2527 // Load cell data
@@ -41,8 +43,20 @@ export default function CellPanel({ df, row, col, setProgress, setError, onClose
4143 if ( asyncCell === undefined ) {
4244 throw new Error ( `Cell missing at column ${ columnName } ` )
4345 }
44- const text = await asyncCell . then ( stringify )
45- setText ( text )
46+ const value = await asyncCell
47+ if ( value instanceof Object && ! ( value instanceof Date ) && value !== null ) {
48+ setContent (
49+ < code className = { cn ( jsonStyles . jsonView , customClass ?. jsonView ) } >
50+ < Json json = { value } />
51+ </ code >
52+ )
53+ } else {
54+ setContent (
55+ < code className = { cn ( styles . textView , customClass ?. textView ) } >
56+ { stringify ( value ) }
57+ </ code >
58+ )
59+ }
4660 } catch ( error ) {
4761 setError ( error as Error )
4862 } finally {
@@ -60,6 +74,6 @@ export default function CellPanel({ df, row, col, setProgress, setError, onClose
6074 </ >
6175
6276 return < ContentWrapper headers = { headers } >
63- < code className = { cn ( styles . textView , customClass ?. textView ) } > { text } </ code >
77+ { content }
6478 </ ContentWrapper >
6579}
0 commit comments