// ES6 + inline style port of JSONViewer https://bitbucket.org/davevedder/react-json-viewer/ // all credits and original code to the author // Dave Vedder http://www.eskimospy.com/ // port by Daniele Zannotti http://www.github.com/dzannotti import React, { useMemo } from 'react'; import JSONNode from './JSONNode'; import createStylingFromTheme from './createStylingFromTheme'; import { invertTheme } from 'react-base16-styling'; import type { StylingValue, Theme } from 'react-base16-styling'; import type { CommonExternalProps, GetItemString, IsCustomNode, LabelRenderer, ShouldExpandNodeInitially, } from './types'; interface Props extends Partial { data: unknown; theme?: Theme; invertTheme?: boolean; } const identity = (value: any) => value; const expandRootNode: ShouldExpandNodeInitially = (keyPath, data, level) => level === 0; const defaultItemString: GetItemString = (type, data, itemType, itemString) => ( {itemType} {itemString} ); const defaultLabelRenderer: LabelRenderer = ([label]) => {label}:; const noCustomNode: IsCustomNode = () => false; export function JSONTree({ data: value, theme, invertTheme: shouldInvertTheme, keyPath = ['root'], labelRenderer = defaultLabelRenderer, valueRenderer = identity, shouldExpandNodeInitially = expandRootNode, hideRoot = false, getItemString = defaultItemString, postprocessValue = identity, isCustomNode = noCustomNode, collectionLimit = 50, sortObjectKeys = false, }: Props) { const styling = useMemo( () => createStylingFromTheme(shouldInvertTheme ? invertTheme(theme) : theme), [theme, shouldInvertTheme], ); return (
); } export type { Key, KeyPath, GetItemString, LabelRenderer, ValueRenderer, ShouldExpandNodeInitially, PostprocessValue, IsCustomNode, SortObjectKeys, Styling, CommonExternalProps, } from './types'; export type { StylingValue };