| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- diff --git a/dist/DataRenderer.d.ts b/dist/DataRenderer.d.ts
- index 6838d1c3aa8cea1e77534801bf02b9c11ddad1de..3dc8c6568cc4f174126dad32c33a64b0dc25f198 100644
- --- a/dist/DataRenderer.d.ts
- +++ b/dist/DataRenderer.d.ts
- @@ -30,6 +30,8 @@ interface CommonRenderProps {
- clickToExpandNode: boolean;
- outerRef: React.RefObject<HTMLDivElement>;
- beforeExpandChange?: (event: NodeExpandingEvent) => boolean;
- + renderExpandableValue?: (value: Object | Array<any>, expanded: boolean) => React.ReactNode;
- + renderStringValue?: (value: string) => React.ReactNode;
- }
- export interface JsonRenderProps<T> extends CommonRenderProps {
- field?: string;
- diff --git a/dist/index.d.ts b/dist/index.d.ts
- index 23e9bca4586b7ea71e7d016230e33eb444cd1304..c49677664f0f0a10e67be688a0157ef9f0d93d6d 100644
- --- a/dist/index.d.ts
- +++ b/dist/index.d.ts
- @@ -16,10 +16,12 @@ export interface Props extends React.AriaAttributes {
- shouldExpandNode?: (level: number, value: any, field?: string) => boolean;
- clickToExpandNode?: boolean;
- beforeExpandChange?: (event: NodeExpandingEvent) => boolean;
- + renderExpandableValue?: (value: Object | Array<any>, expanded: boolean) => React.ReactNode;
- + renderStringValue?: (value: string) => React.ReactNode;
- compactTopLevel?: boolean;
- }
- export declare const defaultStyles: StyleProps;
- export declare const darkStyles: StyleProps;
- export declare const allExpanded: () => boolean;
- export declare const collapseAllNested: (level: number) => boolean;
- -export declare const JsonView: ({ data, style, shouldExpandNode, clickToExpandNode, beforeExpandChange, compactTopLevel, ...ariaAttrs }: Props) => React.JSX.Element;
- +export declare const JsonView: ({ data, style, shouldExpandNode, clickToExpandNode, beforeExpandChange, renderExpandableValue, renderStringValue, compactTopLevel, ...ariaAttrs }: Props) => React.JSX.Element;
- diff --git a/dist/index.js b/dist/index.js
- index ab8b98c992bd34e00e7c3a0257d6778d7928dde8..669304fbba450c789bf4a4264f0627a8eec9d178 100644
- --- a/dist/index.js
- +++ b/dist/index.js
- @@ -50,7 +50,9 @@ function ExpandableObject(_ref) {
- shouldExpandNode,
- clickToExpandNode,
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- } = _ref;
- const shouldExpandNodeCalledRef = React.useRef(false);
- const [expanded, setExpanded] = React.useState(() => shouldExpandNode(level, value, field));
- @@ -146,7 +148,7 @@ function ExpandableObject(_ref) {
- onKeyDown: onKeyDown
- }, quoteString(field, style.quotesForFieldNames), ":")) : (/*#__PURE__*/React.createElement("span", {
- className: style.label
- - }, quoteString(field, style.quotesForFieldNames), ":"))), /*#__PURE__*/React.createElement("span", {
- + }, quoteString(field, style.quotesForFieldNames), ":"))), renderExpandableValue ? renderExpandableValue(value, expanded) : /*#__PURE__*/React.createElement("span", {
- className: style.punctuation
- }, openBracket), expanded ? (/*#__PURE__*/React.createElement("ul", {
- id: contentsId,
- @@ -162,16 +164,19 @@ function ExpandableObject(_ref) {
- shouldExpandNode: shouldExpandNode,
- clickToExpandNode: clickToExpandNode,
- beforeExpandChange: beforeExpandChange,
- - outerRef: outerRef
- + outerRef: outerRef,
- + renderExpandableValue: renderExpandableValue,
- + renderStringValue: renderStringValue
- }))))) : (
- + renderExpandableValue ? null :
- /*#__PURE__*/
- React.createElement("span", {
- className: style.collapsedContent,
- onClick: onClick,
- onKeyDown: onKeyDown
- - })), /*#__PURE__*/React.createElement("span", {
- + })), renderExpandableValue ? null : /*#__PURE__*/React.createElement("span", {
- className: style.punctuation
- - }, closeBracket), !lastElement && /*#__PURE__*/React.createElement("span", {
- + }, closeBracket), !renderExpandableValue && !lastElement && /*#__PURE__*/React.createElement("span", {
- className: style.punctuation
- }, ","));
- }
- @@ -207,7 +212,9 @@ function JsonObject(_ref3) {
- clickToExpandNode,
- level,
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- } = _ref3;
- return ExpandableObject({
- field,
- @@ -221,7 +228,9 @@ function JsonObject(_ref3) {
- clickToExpandNode,
- data: Object.keys(value).map(key => [key, value[key]]),
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- });
- }
- function JsonArray(_ref4) {
- @@ -234,7 +243,9 @@ function JsonArray(_ref4) {
- shouldExpandNode,
- clickToExpandNode,
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- } = _ref4;
- return ExpandableObject({
- field,
- @@ -246,9 +257,11 @@ function JsonArray(_ref4) {
- style,
- shouldExpandNode,
- clickToExpandNode,
- - data: value.map(element => [undefined, element]),
- + data: value.map((element, index) => [String(index), element]),
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- });
- }
- function JsonPrimitiveValue(_ref5) {
- @@ -256,7 +269,8 @@ function JsonPrimitiveValue(_ref5) {
- field,
- value,
- style,
- - lastElement
- + lastElement,
- + renderStringValue
- } = _ref5;
- let stringValue;
- let valueStyle = style.otherValue;
- @@ -291,7 +305,7 @@ function JsonPrimitiveValue(_ref5) {
- "aria-selected": undefined
- }, (field || field === '') && (/*#__PURE__*/React.createElement("span", {
- className: style.label
- - }, quoteString(field, style.quotesForFieldNames), ":")), /*#__PURE__*/React.createElement("span", {
- + }, quoteString(field, style.quotesForFieldNames), ":")), isString(value) && renderStringValue ? renderStringValue(value) : /*#__PURE__*/React.createElement("span", {
- className: valueStyle
- }, stringValue), !lastElement && /*#__PURE__*/React.createElement("span", {
- className: style.punctuation
- @@ -365,6 +379,8 @@ const JsonView = _ref => {
- shouldExpandNode = allExpanded,
- clickToExpandNode = false,
- beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue,
- compactTopLevel,
- ...ariaAttrs
- } = _ref;
- @@ -390,7 +406,9 @@ const JsonView = _ref => {
- shouldExpandNode: shouldExpandNode,
- clickToExpandNode: clickToExpandNode,
- beforeExpandChange: beforeExpandChange,
- - outerRef: outerRef
- + outerRef: outerRef,
- + renderExpandableValue: renderExpandableValue,
- + renderStringValue: renderStringValue
- });
- }) : (/*#__PURE__*/React.createElement(DataRender, {
- value: data,
- @@ -403,7 +421,9 @@ const JsonView = _ref => {
- shouldExpandNode: shouldExpandNode,
- clickToExpandNode: clickToExpandNode,
- outerRef: outerRef,
- - beforeExpandChange: beforeExpandChange
- + beforeExpandChange: beforeExpandChange,
- + renderExpandableValue: renderExpandableValue,
- + renderStringValue: renderStringValue
- })));
- };
-
- diff --git a/dist/index.modern.js b/dist/index.modern.js
- index e25aea1bc8936b69275b9fbe7011d0466480f99c..f4c509e4459f70080b90695c00f8a17e8f4aac4e 100644
- --- a/dist/index.modern.js
- +++ b/dist/index.modern.js
- @@ -50,7 +50,9 @@ function ExpandableObject(_ref) {
- shouldExpandNode,
- clickToExpandNode,
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- } = _ref;
- const shouldExpandNodeCalledRef = useRef(false);
- const [expanded, setExpanded] = useState(() => shouldExpandNode(level, value, field));
- @@ -146,7 +148,7 @@ function ExpandableObject(_ref) {
- onKeyDown: onKeyDown
- }, quoteString(field, style.quotesForFieldNames), ":")) : (/*#__PURE__*/createElement("span", {
- className: style.label
- - }, quoteString(field, style.quotesForFieldNames), ":"))), /*#__PURE__*/createElement("span", {
- + }, quoteString(field, style.quotesForFieldNames), ":"))), renderExpandableValue ? renderExpandableValue(value, expanded) : /*#__PURE__*/createElement("span", {
- className: style.punctuation
- }, openBracket), expanded ? (/*#__PURE__*/createElement("ul", {
- id: contentsId,
- @@ -162,16 +164,19 @@ function ExpandableObject(_ref) {
- shouldExpandNode: shouldExpandNode,
- clickToExpandNode: clickToExpandNode,
- beforeExpandChange: beforeExpandChange,
- - outerRef: outerRef
- + outerRef: outerRef,
- + renderExpandableValue: renderExpandableValue,
- + renderStringValue: renderStringValue
- }))))) : (
- + renderExpandableValue ? null :
- /*#__PURE__*/
- createElement("span", {
- className: style.collapsedContent,
- onClick: onClick,
- onKeyDown: onKeyDown
- - })), /*#__PURE__*/createElement("span", {
- + })), renderExpandableValue ? null : /*#__PURE__*/createElement("span", {
- className: style.punctuation
- - }, closeBracket), !lastElement && /*#__PURE__*/createElement("span", {
- + }, closeBracket), !renderExpandableValue && !lastElement && /*#__PURE__*/createElement("span", {
- className: style.punctuation
- }, ","));
- }
- @@ -207,7 +212,9 @@ function JsonObject(_ref3) {
- clickToExpandNode,
- level,
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- } = _ref3;
- return ExpandableObject({
- field,
- @@ -221,7 +228,9 @@ function JsonObject(_ref3) {
- clickToExpandNode,
- data: Object.keys(value).map(key => [key, value[key]]),
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- });
- }
- function JsonArray(_ref4) {
- @@ -234,7 +243,9 @@ function JsonArray(_ref4) {
- shouldExpandNode,
- clickToExpandNode,
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- } = _ref4;
- return ExpandableObject({
- field,
- @@ -246,9 +257,11 @@ function JsonArray(_ref4) {
- style,
- shouldExpandNode,
- clickToExpandNode,
- - data: value.map(element => [undefined, element]),
- + data: value.map((element, index) => [String(index), element]),
- outerRef,
- - beforeExpandChange
- + beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue
- });
- }
- function JsonPrimitiveValue(_ref5) {
- @@ -256,7 +269,8 @@ function JsonPrimitiveValue(_ref5) {
- field,
- value,
- style,
- - lastElement
- + lastElement,
- + renderStringValue
- } = _ref5;
- let stringValue;
- let valueStyle = style.otherValue;
- @@ -291,7 +305,7 @@ function JsonPrimitiveValue(_ref5) {
- "aria-selected": undefined
- }, (field || field === '') && (/*#__PURE__*/createElement("span", {
- className: style.label
- - }, quoteString(field, style.quotesForFieldNames), ":")), /*#__PURE__*/createElement("span", {
- + }, quoteString(field, style.quotesForFieldNames), ":")), isString(value) && renderStringValue ? renderStringValue(value) : /*#__PURE__*/createElement("span", {
- className: valueStyle
- }, stringValue), !lastElement && /*#__PURE__*/createElement("span", {
- className: style.punctuation
- @@ -365,6 +379,8 @@ const JsonView = _ref => {
- shouldExpandNode = allExpanded,
- clickToExpandNode = false,
- beforeExpandChange,
- + renderExpandableValue,
- + renderStringValue,
- compactTopLevel,
- ...ariaAttrs
- } = _ref;
- @@ -390,7 +406,9 @@ const JsonView = _ref => {
- shouldExpandNode: shouldExpandNode,
- clickToExpandNode: clickToExpandNode,
- beforeExpandChange: beforeExpandChange,
- - outerRef: outerRef
- + outerRef: outerRef,
- + renderExpandableValue: renderExpandableValue,
- + renderStringValue: renderStringValue
- });
- }) : (/*#__PURE__*/createElement(DataRender, {
- value: data,
- @@ -403,7 +421,9 @@ const JsonView = _ref => {
- shouldExpandNode: shouldExpandNode,
- clickToExpandNode: clickToExpandNode,
- outerRef: outerRef,
- - beforeExpandChange: beforeExpandChange
- + beforeExpandChange: beforeExpandChange,
- + renderExpandableValue: renderExpandableValue,
- + renderStringValue: renderStringValue
- })));
- };
-
|