/** * See `@tdb/ui.test` for UI stories. * See: * https://github.com/xyc/react-inspector */ import { React, css, GlamorValue, value } from '../common'; import { Editor } from './Editor'; import { DEFAULTS } from './constants'; import { ReactInspector, ObjectLabel, ObjectRootLabel, ObjectName, THEME, } from './libs'; export interface IObjectViewProps { data: any; name?: string; expandLevel?: number; showNonenumerable?: boolean; expandPaths?: string | string[]; fontSize?: number; theme?: 'LIGHT' | 'DARK'; style?: GlamorValue; } export interface IObjectViewState { data?: any; isLoading?: boolean; } interface INodeRendererOptions { depth: number; name: string; data: any; isNonenumerable: boolean; expanded: boolean; } /** * Views an Object as a visual tree. */ export class ObjectView extends React.PureComponent< IObjectViewProps, IObjectViewState > { public state: IObjectViewState = {}; private isUnmounted = false; public componentWillMount() { this.loadData(); } public componentDidUpdate( prevProps: IObjectViewProps, prevState: IObjectViewState, ) { if (this.props.data !== prevProps.data && !this.isUnmounted) { this.loadData(); } } public componentWillUnmount() { this.isUnmounted = true; } public render() { let { data } = this.state; const { name, expandLevel = 1, showNonenumerable = false, expandPaths, style, } = this.props; if (this.state.isLoading) { data = 'Loading...'; } return (