1 |
|
2 |
|
3 |
|
4 |
|
5 | import React, { useMemo } from 'react';
|
6 | import { invertTheme } from 'react-base16-styling';
|
7 | import JSONNode from './JSONNode.js';
|
8 | import createStylingFromTheme from './createStylingFromTheme.js';
|
9 | const identity = (value) => value;
|
10 | const expandRootNode = (keyPath, data, level) => level === 0;
|
11 | const defaultItemString = (type, data, itemType, itemString) => (React.createElement("span", null,
|
12 | itemType,
|
13 | " ",
|
14 | itemString));
|
15 | const defaultLabelRenderer = ([label]) => React.createElement("span", null,
|
16 | label,
|
17 | ":");
|
18 | const noCustomNode = () => false;
|
19 | 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, }) {
|
20 | const styling = useMemo(() => createStylingFromTheme(shouldInvertTheme ? invertTheme(theme) : theme), [theme, shouldInvertTheme]);
|
21 | return (React.createElement("ul", { ...styling('tree') },
|
22 | React.createElement(JSONNode, { keyPath: hideRoot ? [] : keyPath, value: postprocessValue(value), isCustomNode: isCustomNode, styling: styling, labelRenderer: labelRenderer, valueRenderer: valueRenderer, shouldExpandNodeInitially: shouldExpandNodeInitially, hideRoot: hideRoot, getItemString: getItemString, postprocessValue: postprocessValue, collectionLimit: collectionLimit, sortObjectKeys: sortObjectKeys })));
|
23 | }
|