react-json-view-lite@2.5.0.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. diff --git a/dist/DataRenderer.d.ts b/dist/DataRenderer.d.ts
  2. index 6838d1c3aa8cea1e77534801bf02b9c11ddad1de..3dc8c6568cc4f174126dad32c33a64b0dc25f198 100644
  3. --- a/dist/DataRenderer.d.ts
  4. +++ b/dist/DataRenderer.d.ts
  5. @@ -30,6 +30,8 @@ interface CommonRenderProps {
  6. clickToExpandNode: boolean;
  7. outerRef: React.RefObject<HTMLDivElement>;
  8. beforeExpandChange?: (event: NodeExpandingEvent) => boolean;
  9. + renderExpandableValue?: (value: Object | Array<any>, expanded: boolean) => React.ReactNode;
  10. + renderStringValue?: (value: string) => React.ReactNode;
  11. }
  12. export interface JsonRenderProps<T> extends CommonRenderProps {
  13. field?: string;
  14. diff --git a/dist/index.d.ts b/dist/index.d.ts
  15. index 23e9bca4586b7ea71e7d016230e33eb444cd1304..c49677664f0f0a10e67be688a0157ef9f0d93d6d 100644
  16. --- a/dist/index.d.ts
  17. +++ b/dist/index.d.ts
  18. @@ -16,10 +16,12 @@ export interface Props extends React.AriaAttributes {
  19. shouldExpandNode?: (level: number, value: any, field?: string) => boolean;
  20. clickToExpandNode?: boolean;
  21. beforeExpandChange?: (event: NodeExpandingEvent) => boolean;
  22. + renderExpandableValue?: (value: Object | Array<any>, expanded: boolean) => React.ReactNode;
  23. + renderStringValue?: (value: string) => React.ReactNode;
  24. compactTopLevel?: boolean;
  25. }
  26. export declare const defaultStyles: StyleProps;
  27. export declare const darkStyles: StyleProps;
  28. export declare const allExpanded: () => boolean;
  29. export declare const collapseAllNested: (level: number) => boolean;
  30. -export declare const JsonView: ({ data, style, shouldExpandNode, clickToExpandNode, beforeExpandChange, compactTopLevel, ...ariaAttrs }: Props) => React.JSX.Element;
  31. +export declare const JsonView: ({ data, style, shouldExpandNode, clickToExpandNode, beforeExpandChange, renderExpandableValue, renderStringValue, compactTopLevel, ...ariaAttrs }: Props) => React.JSX.Element;
  32. diff --git a/dist/index.js b/dist/index.js
  33. index ab8b98c992bd34e00e7c3a0257d6778d7928dde8..669304fbba450c789bf4a4264f0627a8eec9d178 100644
  34. --- a/dist/index.js
  35. +++ b/dist/index.js
  36. @@ -50,7 +50,9 @@ function ExpandableObject(_ref) {
  37. shouldExpandNode,
  38. clickToExpandNode,
  39. outerRef,
  40. - beforeExpandChange
  41. + beforeExpandChange,
  42. + renderExpandableValue,
  43. + renderStringValue
  44. } = _ref;
  45. const shouldExpandNodeCalledRef = React.useRef(false);
  46. const [expanded, setExpanded] = React.useState(() => shouldExpandNode(level, value, field));
  47. @@ -146,7 +148,7 @@ function ExpandableObject(_ref) {
  48. onKeyDown: onKeyDown
  49. }, quoteString(field, style.quotesForFieldNames), ":")) : (/*#__PURE__*/React.createElement("span", {
  50. className: style.label
  51. - }, quoteString(field, style.quotesForFieldNames), ":"))), /*#__PURE__*/React.createElement("span", {
  52. + }, quoteString(field, style.quotesForFieldNames), ":"))), renderExpandableValue ? renderExpandableValue(value, expanded) : /*#__PURE__*/React.createElement("span", {
  53. className: style.punctuation
  54. }, openBracket), expanded ? (/*#__PURE__*/React.createElement("ul", {
  55. id: contentsId,
  56. @@ -162,16 +164,19 @@ function ExpandableObject(_ref) {
  57. shouldExpandNode: shouldExpandNode,
  58. clickToExpandNode: clickToExpandNode,
  59. beforeExpandChange: beforeExpandChange,
  60. - outerRef: outerRef
  61. + outerRef: outerRef,
  62. + renderExpandableValue: renderExpandableValue,
  63. + renderStringValue: renderStringValue
  64. }))))) : (
  65. + renderExpandableValue ? null :
  66. /*#__PURE__*/
  67. React.createElement("span", {
  68. className: style.collapsedContent,
  69. onClick: onClick,
  70. onKeyDown: onKeyDown
  71. - })), /*#__PURE__*/React.createElement("span", {
  72. + })), renderExpandableValue ? null : /*#__PURE__*/React.createElement("span", {
  73. className: style.punctuation
  74. - }, closeBracket), !lastElement && /*#__PURE__*/React.createElement("span", {
  75. + }, closeBracket), !renderExpandableValue && !lastElement && /*#__PURE__*/React.createElement("span", {
  76. className: style.punctuation
  77. }, ","));
  78. }
  79. @@ -207,7 +212,9 @@ function JsonObject(_ref3) {
  80. clickToExpandNode,
  81. level,
  82. outerRef,
  83. - beforeExpandChange
  84. + beforeExpandChange,
  85. + renderExpandableValue,
  86. + renderStringValue
  87. } = _ref3;
  88. return ExpandableObject({
  89. field,
  90. @@ -221,7 +228,9 @@ function JsonObject(_ref3) {
  91. clickToExpandNode,
  92. data: Object.keys(value).map(key => [key, value[key]]),
  93. outerRef,
  94. - beforeExpandChange
  95. + beforeExpandChange,
  96. + renderExpandableValue,
  97. + renderStringValue
  98. });
  99. }
  100. function JsonArray(_ref4) {
  101. @@ -234,7 +243,9 @@ function JsonArray(_ref4) {
  102. shouldExpandNode,
  103. clickToExpandNode,
  104. outerRef,
  105. - beforeExpandChange
  106. + beforeExpandChange,
  107. + renderExpandableValue,
  108. + renderStringValue
  109. } = _ref4;
  110. return ExpandableObject({
  111. field,
  112. @@ -246,9 +257,11 @@ function JsonArray(_ref4) {
  113. style,
  114. shouldExpandNode,
  115. clickToExpandNode,
  116. - data: value.map(element => [undefined, element]),
  117. + data: value.map((element, index) => [String(index), element]),
  118. outerRef,
  119. - beforeExpandChange
  120. + beforeExpandChange,
  121. + renderExpandableValue,
  122. + renderStringValue
  123. });
  124. }
  125. function JsonPrimitiveValue(_ref5) {
  126. @@ -256,7 +269,8 @@ function JsonPrimitiveValue(_ref5) {
  127. field,
  128. value,
  129. style,
  130. - lastElement
  131. + lastElement,
  132. + renderStringValue
  133. } = _ref5;
  134. let stringValue;
  135. let valueStyle = style.otherValue;
  136. @@ -291,7 +305,7 @@ function JsonPrimitiveValue(_ref5) {
  137. "aria-selected": undefined
  138. }, (field || field === '') && (/*#__PURE__*/React.createElement("span", {
  139. className: style.label
  140. - }, quoteString(field, style.quotesForFieldNames), ":")), /*#__PURE__*/React.createElement("span", {
  141. + }, quoteString(field, style.quotesForFieldNames), ":")), isString(value) && renderStringValue ? renderStringValue(value) : /*#__PURE__*/React.createElement("span", {
  142. className: valueStyle
  143. }, stringValue), !lastElement && /*#__PURE__*/React.createElement("span", {
  144. className: style.punctuation
  145. @@ -365,6 +379,8 @@ const JsonView = _ref => {
  146. shouldExpandNode = allExpanded,
  147. clickToExpandNode = false,
  148. beforeExpandChange,
  149. + renderExpandableValue,
  150. + renderStringValue,
  151. compactTopLevel,
  152. ...ariaAttrs
  153. } = _ref;
  154. @@ -390,7 +406,9 @@ const JsonView = _ref => {
  155. shouldExpandNode: shouldExpandNode,
  156. clickToExpandNode: clickToExpandNode,
  157. beforeExpandChange: beforeExpandChange,
  158. - outerRef: outerRef
  159. + outerRef: outerRef,
  160. + renderExpandableValue: renderExpandableValue,
  161. + renderStringValue: renderStringValue
  162. });
  163. }) : (/*#__PURE__*/React.createElement(DataRender, {
  164. value: data,
  165. @@ -403,7 +421,9 @@ const JsonView = _ref => {
  166. shouldExpandNode: shouldExpandNode,
  167. clickToExpandNode: clickToExpandNode,
  168. outerRef: outerRef,
  169. - beforeExpandChange: beforeExpandChange
  170. + beforeExpandChange: beforeExpandChange,
  171. + renderExpandableValue: renderExpandableValue,
  172. + renderStringValue: renderStringValue
  173. })));
  174. };
  175. diff --git a/dist/index.modern.js b/dist/index.modern.js
  176. index e25aea1bc8936b69275b9fbe7011d0466480f99c..f4c509e4459f70080b90695c00f8a17e8f4aac4e 100644
  177. --- a/dist/index.modern.js
  178. +++ b/dist/index.modern.js
  179. @@ -50,7 +50,9 @@ function ExpandableObject(_ref) {
  180. shouldExpandNode,
  181. clickToExpandNode,
  182. outerRef,
  183. - beforeExpandChange
  184. + beforeExpandChange,
  185. + renderExpandableValue,
  186. + renderStringValue
  187. } = _ref;
  188. const shouldExpandNodeCalledRef = useRef(false);
  189. const [expanded, setExpanded] = useState(() => shouldExpandNode(level, value, field));
  190. @@ -146,7 +148,7 @@ function ExpandableObject(_ref) {
  191. onKeyDown: onKeyDown
  192. }, quoteString(field, style.quotesForFieldNames), ":")) : (/*#__PURE__*/createElement("span", {
  193. className: style.label
  194. - }, quoteString(field, style.quotesForFieldNames), ":"))), /*#__PURE__*/createElement("span", {
  195. + }, quoteString(field, style.quotesForFieldNames), ":"))), renderExpandableValue ? renderExpandableValue(value, expanded) : /*#__PURE__*/createElement("span", {
  196. className: style.punctuation
  197. }, openBracket), expanded ? (/*#__PURE__*/createElement("ul", {
  198. id: contentsId,
  199. @@ -162,16 +164,19 @@ function ExpandableObject(_ref) {
  200. shouldExpandNode: shouldExpandNode,
  201. clickToExpandNode: clickToExpandNode,
  202. beforeExpandChange: beforeExpandChange,
  203. - outerRef: outerRef
  204. + outerRef: outerRef,
  205. + renderExpandableValue: renderExpandableValue,
  206. + renderStringValue: renderStringValue
  207. }))))) : (
  208. + renderExpandableValue ? null :
  209. /*#__PURE__*/
  210. createElement("span", {
  211. className: style.collapsedContent,
  212. onClick: onClick,
  213. onKeyDown: onKeyDown
  214. - })), /*#__PURE__*/createElement("span", {
  215. + })), renderExpandableValue ? null : /*#__PURE__*/createElement("span", {
  216. className: style.punctuation
  217. - }, closeBracket), !lastElement && /*#__PURE__*/createElement("span", {
  218. + }, closeBracket), !renderExpandableValue && !lastElement && /*#__PURE__*/createElement("span", {
  219. className: style.punctuation
  220. }, ","));
  221. }
  222. @@ -207,7 +212,9 @@ function JsonObject(_ref3) {
  223. clickToExpandNode,
  224. level,
  225. outerRef,
  226. - beforeExpandChange
  227. + beforeExpandChange,
  228. + renderExpandableValue,
  229. + renderStringValue
  230. } = _ref3;
  231. return ExpandableObject({
  232. field,
  233. @@ -221,7 +228,9 @@ function JsonObject(_ref3) {
  234. clickToExpandNode,
  235. data: Object.keys(value).map(key => [key, value[key]]),
  236. outerRef,
  237. - beforeExpandChange
  238. + beforeExpandChange,
  239. + renderExpandableValue,
  240. + renderStringValue
  241. });
  242. }
  243. function JsonArray(_ref4) {
  244. @@ -234,7 +243,9 @@ function JsonArray(_ref4) {
  245. shouldExpandNode,
  246. clickToExpandNode,
  247. outerRef,
  248. - beforeExpandChange
  249. + beforeExpandChange,
  250. + renderExpandableValue,
  251. + renderStringValue
  252. } = _ref4;
  253. return ExpandableObject({
  254. field,
  255. @@ -246,9 +257,11 @@ function JsonArray(_ref4) {
  256. style,
  257. shouldExpandNode,
  258. clickToExpandNode,
  259. - data: value.map(element => [undefined, element]),
  260. + data: value.map((element, index) => [String(index), element]),
  261. outerRef,
  262. - beforeExpandChange
  263. + beforeExpandChange,
  264. + renderExpandableValue,
  265. + renderStringValue
  266. });
  267. }
  268. function JsonPrimitiveValue(_ref5) {
  269. @@ -256,7 +269,8 @@ function JsonPrimitiveValue(_ref5) {
  270. field,
  271. value,
  272. style,
  273. - lastElement
  274. + lastElement,
  275. + renderStringValue
  276. } = _ref5;
  277. let stringValue;
  278. let valueStyle = style.otherValue;
  279. @@ -291,7 +305,7 @@ function JsonPrimitiveValue(_ref5) {
  280. "aria-selected": undefined
  281. }, (field || field === '') && (/*#__PURE__*/createElement("span", {
  282. className: style.label
  283. - }, quoteString(field, style.quotesForFieldNames), ":")), /*#__PURE__*/createElement("span", {
  284. + }, quoteString(field, style.quotesForFieldNames), ":")), isString(value) && renderStringValue ? renderStringValue(value) : /*#__PURE__*/createElement("span", {
  285. className: valueStyle
  286. }, stringValue), !lastElement && /*#__PURE__*/createElement("span", {
  287. className: style.punctuation
  288. @@ -365,6 +379,8 @@ const JsonView = _ref => {
  289. shouldExpandNode = allExpanded,
  290. clickToExpandNode = false,
  291. beforeExpandChange,
  292. + renderExpandableValue,
  293. + renderStringValue,
  294. compactTopLevel,
  295. ...ariaAttrs
  296. } = _ref;
  297. @@ -390,7 +406,9 @@ const JsonView = _ref => {
  298. shouldExpandNode: shouldExpandNode,
  299. clickToExpandNode: clickToExpandNode,
  300. beforeExpandChange: beforeExpandChange,
  301. - outerRef: outerRef
  302. + outerRef: outerRef,
  303. + renderExpandableValue: renderExpandableValue,
  304. + renderStringValue: renderStringValue
  305. });
  306. }) : (/*#__PURE__*/createElement(DataRender, {
  307. value: data,
  308. @@ -403,7 +421,9 @@ const JsonView = _ref => {
  309. shouldExpandNode: shouldExpandNode,
  310. clickToExpandNode: clickToExpandNode,
  311. outerRef: outerRef,
  312. - beforeExpandChange: beforeExpandChange
  313. + beforeExpandChange: beforeExpandChange,
  314. + renderExpandableValue: renderExpandableValue,
  315. + renderStringValue: renderStringValue
  316. })));
  317. };