import { useState } from 'react' import classNames from 'classnames' import { dateTimeFormatter } from '~/utils/formatters' // Pseudo element contents are defined in CSS because Tailwind arbitrary values // don't seem to support square brackets, and have poor performance in this case import './object-viewer.css' function ValueRenderer({ data }: { data: any }) { if (data instanceof Date) { return ( {dateTimeFormatter.format(data)} ) } if (typeof data === 'bigint') { return {`${data.toString()}n`} } if (data === null) { return null } if (data === true || data === false || typeof data === 'number') { return {JSON.stringify(data)} } return {JSON.stringify(data)} } export default function ObjectViewer({ data, name, expanded = true, collapsible = false, }: { data: any name?: string expanded?: boolean collapsible?: boolean }) { const [isOpen, setIsOpen] = useState(expanded) const isExpandable = !!data && typeof data === 'object' && !(data instanceof Date) if (data instanceof Map) { const newData: { [key: string]: any } = {} for (const [key, val] of data.entries()) { newData[key] = val } data = newData } if (data instanceof Set) { data = [...data] } if (!isExpandable) { return (