import React from 'react';
import PropTypes from 'prop-types';
import objType from './objType';
import JSONObjectNode from './JSONObjectNode';
import JSONArrayNode from './JSONArrayNode';
import JSONIterableNode from './JSONIterableNode';
import JSONValueNode from './JSONValueNode';
const JSONNode = ({
getItemString,
keyPath,
labelRenderer,
styling,
value,
valueRenderer,
isCustomNode,
...rest
}) => {
const nodeType = isCustomNode(value) ? 'Custom' : objType(value);
const simpleNodeProps = {
getItemString,
key: keyPath[0],
keyPath,
labelRenderer,
nodeType,
styling,
value,
valueRenderer
};
const nestedNodeProps = {
...rest,
...simpleNodeProps,
data: value,
isCustomNode
};
switch (nodeType) {
case 'Object':
case 'Error':
case 'WeakMap':
case 'WeakSet':
return ;
case 'Array':
return ;
case 'Iterable':
case 'Map':
case 'Set':
return ;
case 'String':
return (
`"${raw}"`} />
);
case 'Number':
return ;
case 'Boolean':
return (
(raw ? 'true' : 'false')}
/>
);
case 'Date':
return (
raw.toISOString()}
/>
);
case 'Null':
return 'null'} />;
case 'Undefined':
return (
'undefined'} />
);
case 'Function':
case 'Symbol':
return (
raw.toString()}
/>
);
case 'Custom':
return ;
default:
return (
`<${nodeType}>`} />
);
}
};
JSONNode.propTypes = {
getItemString: PropTypes.func.isRequired,
keyPath: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
).isRequired,
labelRenderer: PropTypes.func.isRequired,
styling: PropTypes.func.isRequired,
value: PropTypes.any,
valueRenderer: PropTypes.func.isRequired,
isCustomNode: PropTypes.func.isRequired
};
export default JSONNode;