@uiw/react-json-view 1.11.1 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/README.md +249 -263
  2. package/cjs/Container.d.ts +10 -0
  3. package/cjs/Container.js +67 -0
  4. package/cjs/arrow/TriangleArrow.js +3 -1
  5. package/cjs/arrow/TriangleSolidArrow.js +7 -3
  6. package/cjs/comps/Copied.d.ts +16 -0
  7. package/cjs/{copied.js → comps/Copied.js} +44 -32
  8. package/cjs/comps/CountInfo.d.ts +19 -0
  9. package/cjs/comps/CountInfo.js +72 -0
  10. package/cjs/comps/Ellipsis.d.ts +10 -0
  11. package/cjs/comps/Ellipsis.js +35 -0
  12. package/cjs/comps/Key.d.ts +7 -0
  13. package/cjs/comps/Key.js +39 -0
  14. package/cjs/comps/KeyValues.d.ts +22 -0
  15. package/cjs/comps/KeyValues.js +156 -0
  16. package/cjs/comps/NestedClose.d.ts +10 -0
  17. package/cjs/comps/NestedClose.js +38 -0
  18. package/cjs/comps/NestedOpen.d.ts +11 -0
  19. package/cjs/comps/NestedOpen.js +95 -0
  20. package/cjs/comps/ReRender/Symbols.d.ts +44 -0
  21. package/cjs/comps/ReRender/Symbols.js +144 -0
  22. package/cjs/comps/ReRender/Types.d.ts +36 -0
  23. package/cjs/comps/ReRender/Types.js +590 -0
  24. package/cjs/comps/Value.d.ts +11 -0
  25. package/cjs/comps/Value.js +78 -0
  26. package/cjs/index.d.ts +72 -52
  27. package/cjs/index.js +147 -27
  28. package/cjs/section/Copied.d.ts +6 -0
  29. package/cjs/section/Copied.js +17 -0
  30. package/cjs/section/CountInfo.d.ts +6 -0
  31. package/cjs/section/CountInfo.js +17 -0
  32. package/cjs/section/CountInfoExtra.d.ts +6 -0
  33. package/cjs/section/CountInfoExtra.js +17 -0
  34. package/cjs/section/Ellipsis.d.ts +6 -0
  35. package/cjs/section/Ellipsis.js +17 -0
  36. package/cjs/section/KeyName.d.ts +6 -0
  37. package/cjs/section/KeyName.js +17 -0
  38. package/cjs/store/Expands.d.ts +16 -0
  39. package/cjs/store/Expands.js +44 -0
  40. package/cjs/store/Section.d.ts +33 -0
  41. package/cjs/store/Section.js +86 -0
  42. package/cjs/store/ShowTools.d.ts +14 -0
  43. package/cjs/store/ShowTools.js +44 -0
  44. package/cjs/store/Symbols.d.ts +37 -0
  45. package/cjs/store/Symbols.js +112 -0
  46. package/cjs/store/Types.d.ts +52 -0
  47. package/cjs/store/Types.js +162 -0
  48. package/cjs/store.d.ts +29 -5
  49. package/cjs/store.js +96 -46
  50. package/cjs/symbol/Arrow.d.ts +6 -0
  51. package/cjs/symbol/Arrow.js +17 -0
  52. package/cjs/symbol/BraceLeft.d.ts +6 -0
  53. package/cjs/symbol/BraceLeft.js +17 -0
  54. package/cjs/symbol/BraceRight.d.ts +6 -0
  55. package/cjs/symbol/BraceRight.js +17 -0
  56. package/cjs/symbol/BracketsLeft.d.ts +6 -0
  57. package/cjs/symbol/BracketsLeft.js +17 -0
  58. package/cjs/symbol/BracketsRight.d.ts +6 -0
  59. package/cjs/symbol/BracketsRight.js +17 -0
  60. package/cjs/symbol/Colon.d.ts +6 -0
  61. package/cjs/symbol/Colon.js +17 -0
  62. package/cjs/symbol/Quote.d.ts +6 -0
  63. package/cjs/symbol/Quote.js +17 -0
  64. package/cjs/symbol/ValueQuote.d.ts +6 -0
  65. package/cjs/symbol/ValueQuote.js +17 -0
  66. package/cjs/theme/basic.js +3 -0
  67. package/cjs/theme/dark.js +3 -0
  68. package/cjs/theme/github.dark.js +3 -0
  69. package/cjs/theme/github.light.js +3 -0
  70. package/cjs/theme/gruvbox.js +3 -0
  71. package/cjs/theme/light.js +3 -0
  72. package/cjs/theme/monokai.js +3 -0
  73. package/cjs/theme/nord.js +3 -0
  74. package/cjs/theme/vscode.js +3 -0
  75. package/cjs/type.d.ts +50 -0
  76. package/cjs/type.js +57 -0
  77. package/cjs/types/Bigint.d.ts +5 -0
  78. package/cjs/types/Bigint.js +17 -0
  79. package/cjs/types/Date.d.ts +5 -0
  80. package/cjs/types/Date.js +17 -0
  81. package/cjs/types/False.d.ts +5 -0
  82. package/cjs/types/False.js +17 -0
  83. package/cjs/types/Float.d.ts +5 -0
  84. package/cjs/types/Float.js +17 -0
  85. package/cjs/types/Int.d.ts +5 -0
  86. package/cjs/types/Int.js +17 -0
  87. package/cjs/types/Map.d.ts +5 -0
  88. package/cjs/types/Map.js +17 -0
  89. package/cjs/types/Nan.d.ts +5 -0
  90. package/cjs/types/Nan.js +17 -0
  91. package/cjs/types/Null.d.ts +5 -0
  92. package/cjs/types/Null.js +17 -0
  93. package/cjs/types/Set.d.ts +5 -0
  94. package/cjs/types/Set.js +17 -0
  95. package/cjs/types/String.d.ts +5 -0
  96. package/cjs/types/String.js +17 -0
  97. package/cjs/types/True.d.ts +5 -0
  98. package/cjs/types/True.js +17 -0
  99. package/cjs/types/Undefined.d.ts +5 -0
  100. package/cjs/types/Undefined.js +17 -0
  101. package/cjs/types/Url.d.ts +5 -0
  102. package/cjs/types/Url.js +17 -0
  103. package/cjs/utils/useHighlight.d.ts +9 -0
  104. package/cjs/utils/useHighlight.js +62 -0
  105. package/cjs/utils/useRender.d.ts +6 -0
  106. package/cjs/utils/useRender.js +51 -0
  107. package/esm/Container.d.ts +10 -0
  108. package/esm/Container.js +53 -0
  109. package/esm/arrow/TriangleArrow.js +3 -1
  110. package/esm/arrow/TriangleSolidArrow.js +7 -3
  111. package/esm/comps/Copied.d.ts +16 -0
  112. package/esm/{copied.js → comps/Copied.js} +44 -29
  113. package/esm/comps/CountInfo.d.ts +19 -0
  114. package/esm/comps/CountInfo.js +70 -0
  115. package/esm/comps/Ellipsis.d.ts +10 -0
  116. package/esm/comps/Ellipsis.js +31 -0
  117. package/esm/comps/Key.d.ts +7 -0
  118. package/esm/comps/Key.js +35 -0
  119. package/esm/comps/KeyValues.d.ts +22 -0
  120. package/esm/comps/KeyValues.js +142 -0
  121. package/esm/comps/NestedClose.d.ts +10 -0
  122. package/esm/comps/NestedClose.js +34 -0
  123. package/esm/comps/NestedOpen.d.ts +11 -0
  124. package/esm/comps/NestedOpen.js +91 -0
  125. package/esm/comps/ReRender/Symbols.d.ts +44 -0
  126. package/esm/comps/ReRender/Symbols.js +155 -0
  127. package/esm/comps/ReRender/Types.d.ts +36 -0
  128. package/esm/comps/ReRender/Types.js +621 -0
  129. package/esm/comps/Value.d.ts +11 -0
  130. package/esm/comps/Value.js +69 -0
  131. package/esm/index.d.ts +72 -52
  132. package/esm/index.js +98 -18
  133. package/esm/section/Copied.d.ts +6 -0
  134. package/esm/section/Copied.js +10 -0
  135. package/esm/section/CountInfo.d.ts +6 -0
  136. package/esm/section/CountInfo.js +10 -0
  137. package/esm/section/CountInfoExtra.d.ts +6 -0
  138. package/esm/section/CountInfoExtra.js +10 -0
  139. package/esm/section/Ellipsis.d.ts +6 -0
  140. package/esm/section/Ellipsis.js +10 -0
  141. package/esm/section/KeyName.d.ts +6 -0
  142. package/esm/section/KeyName.js +10 -0
  143. package/esm/store/Expands.d.ts +16 -0
  144. package/esm/store/Expands.js +32 -0
  145. package/esm/store/Section.d.ts +33 -0
  146. package/esm/store/Section.js +73 -0
  147. package/esm/store/ShowTools.d.ts +14 -0
  148. package/esm/store/ShowTools.js +32 -0
  149. package/esm/store/Symbols.d.ts +37 -0
  150. package/esm/store/Symbols.js +100 -0
  151. package/esm/store/Types.d.ts +52 -0
  152. package/esm/store/Types.js +150 -0
  153. package/esm/store.d.ts +29 -5
  154. package/esm/store.js +66 -32
  155. package/esm/symbol/Arrow.d.ts +6 -0
  156. package/esm/symbol/Arrow.js +10 -0
  157. package/esm/symbol/BraceLeft.d.ts +6 -0
  158. package/esm/symbol/BraceLeft.js +10 -0
  159. package/esm/symbol/BraceRight.d.ts +6 -0
  160. package/esm/symbol/BraceRight.js +10 -0
  161. package/esm/symbol/BracketsLeft.d.ts +6 -0
  162. package/esm/symbol/BracketsLeft.js +10 -0
  163. package/esm/symbol/BracketsRight.d.ts +6 -0
  164. package/esm/symbol/BracketsRight.js +10 -0
  165. package/esm/symbol/Colon.d.ts +6 -0
  166. package/esm/symbol/Colon.js +10 -0
  167. package/esm/symbol/Quote.d.ts +6 -0
  168. package/esm/symbol/Quote.js +10 -0
  169. package/esm/symbol/ValueQuote.d.ts +6 -0
  170. package/esm/symbol/ValueQuote.js +10 -0
  171. package/esm/theme/basic.js +3 -0
  172. package/esm/theme/dark.js +3 -0
  173. package/esm/theme/github.dark.js +3 -0
  174. package/esm/theme/github.light.js +3 -0
  175. package/esm/theme/gruvbox.js +3 -0
  176. package/esm/theme/light.js +3 -0
  177. package/esm/theme/monokai.js +3 -0
  178. package/esm/theme/nord.js +3 -0
  179. package/esm/theme/vscode.js +3 -0
  180. package/esm/type.d.ts +50 -0
  181. package/esm/type.js +50 -0
  182. package/esm/types/Bigint.d.ts +5 -0
  183. package/esm/types/Bigint.js +10 -0
  184. package/esm/types/Date.d.ts +5 -0
  185. package/esm/types/Date.js +10 -0
  186. package/esm/types/False.d.ts +5 -0
  187. package/esm/types/False.js +10 -0
  188. package/esm/types/Float.d.ts +5 -0
  189. package/esm/types/Float.js +10 -0
  190. package/esm/types/Int.d.ts +5 -0
  191. package/esm/types/Int.js +10 -0
  192. package/esm/types/Map.d.ts +5 -0
  193. package/esm/types/Map.js +10 -0
  194. package/esm/types/Nan.d.ts +5 -0
  195. package/esm/types/Nan.js +10 -0
  196. package/esm/types/Null.d.ts +5 -0
  197. package/esm/types/Null.js +10 -0
  198. package/esm/types/Set.d.ts +5 -0
  199. package/esm/types/Set.js +10 -0
  200. package/esm/types/String.d.ts +5 -0
  201. package/esm/types/String.js +10 -0
  202. package/esm/types/True.d.ts +5 -0
  203. package/esm/types/True.js +10 -0
  204. package/esm/types/Undefined.d.ts +5 -0
  205. package/esm/types/Undefined.js +10 -0
  206. package/esm/types/Url.d.ts +5 -0
  207. package/esm/types/Url.js +10 -0
  208. package/esm/utils/useHighlight.d.ts +9 -0
  209. package/esm/{semicolon.js → utils/useHighlight.js} +1 -52
  210. package/esm/utils/useRender.d.ts +6 -0
  211. package/esm/utils/useRender.js +41 -0
  212. package/package.json +1 -1
  213. package/cjs/comps/ellipsis.d.ts +0 -7
  214. package/cjs/comps/ellipsis.js +0 -37
  215. package/cjs/comps/meta.d.ts +0 -12
  216. package/cjs/comps/meta.js +0 -46
  217. package/cjs/copied.d.ts +0 -11
  218. package/cjs/editor/countInfoExtra.d.ts +0 -28
  219. package/cjs/editor/countInfoExtra.js +0 -101
  220. package/cjs/editor/icon/add.d.ts +0 -4
  221. package/cjs/editor/icon/add.js +0 -30
  222. package/cjs/editor/icon/delete.d.ts +0 -4
  223. package/cjs/editor/icon/delete.js +0 -30
  224. package/cjs/editor/icon/edit.d.ts +0 -4
  225. package/cjs/editor/icon/edit.js +0 -30
  226. package/cjs/editor/index.d.ts +0 -31
  227. package/cjs/editor/index.js +0 -60
  228. package/cjs/editor/objectKey.d.ts +0 -11
  229. package/cjs/editor/objectKey.js +0 -169
  230. package/cjs/editor/value.d.ts +0 -22
  231. package/cjs/editor/value.js +0 -240
  232. package/cjs/node.d.ts +0 -13
  233. package/cjs/node.js +0 -329
  234. package/cjs/semicolon.d.ts +0 -22
  235. package/cjs/semicolon.js +0 -115
  236. package/cjs/value.d.ts +0 -84
  237. package/cjs/value.js +0 -348
  238. package/esm/comps/ellipsis.d.ts +0 -7
  239. package/esm/comps/ellipsis.js +0 -31
  240. package/esm/comps/meta.d.ts +0 -12
  241. package/esm/comps/meta.js +0 -39
  242. package/esm/copied.d.ts +0 -11
  243. package/esm/editor/countInfoExtra.d.ts +0 -28
  244. package/esm/editor/countInfoExtra.js +0 -68
  245. package/esm/editor/icon/add.d.ts +0 -4
  246. package/esm/editor/icon/add.js +0 -24
  247. package/esm/editor/icon/delete.d.ts +0 -4
  248. package/esm/editor/icon/delete.js +0 -24
  249. package/esm/editor/icon/edit.d.ts +0 -4
  250. package/esm/editor/icon/edit.js +0 -24
  251. package/esm/editor/index.d.ts +0 -31
  252. package/esm/editor/index.js +0 -47
  253. package/esm/editor/objectKey.d.ts +0 -11
  254. package/esm/editor/objectKey.js +0 -135
  255. package/esm/editor/value.d.ts +0 -22
  256. package/esm/editor/value.js +0 -192
  257. package/esm/node.d.ts +0 -13
  258. package/esm/node.js +0 -287
  259. package/esm/semicolon.d.ts +0 -22
  260. package/esm/value.d.ts +0 -84
  261. package/esm/value.js +0 -324
package/README.md CHANGED
@@ -26,6 +26,12 @@ A React component for displaying and editing javascript arrays and JSON objects.
26
26
  ✏️ Support editing and adding features
27
27
  ♻️ Whether to highlight updates.
28
28
 
29
+ The new version [**v2**](https://raw.githack.com/uiwjs/react-json-view/v2-docs/index.html) has redesigned the API to make the code more maintainable and introduced a simpler and more flexible component customization rendering API. Each component can now have custom rendering, and the new API resembles React more closely. Preview [v2 documentation](https://raw.githack.com/uiwjs/react-json-view/v2-docs/index.html) and [examples](https://raw.githack.com/uiwjs/react-json-view/v2-docs/index.html).
30
+
31
+ - [x] Complete all features of displaying JSON in v1.
32
+ - [ ] Add editing functionality to v2.
33
+ - [ ] Add test cases to v2.
34
+
29
35
  ## Quick Start
30
36
 
31
37
  ```bash
@@ -119,6 +125,7 @@ export default function Demo() {
119
125
  }
120
126
  ```
121
127
 
128
+
122
129
  Example of custom `vscode` theme styles:
123
130
 
124
131
  ```tsx mdx:preview
@@ -138,31 +145,32 @@ const object = {
138
145
  const customTheme = {
139
146
  '--w-rjv-font-family': 'monospace',
140
147
  '--w-rjv-color': '#9cdcfe',
148
+ '--w-rjv-key-string': '#9cdcfe',
141
149
  '--w-rjv-background-color': '#1e1e1e',
142
- '--w-rjv-line-color': '#323232',
143
- '--w-rjv-arrow-color': 'var(--w-rjv-color)',
150
+ '--w-rjv-line-color': '#36334280',
151
+ '--w-rjv-arrow-color': '#838383',
144
152
  '--w-rjv-edit-color': 'var(--w-rjv-color)',
145
- '--w-rjv-add-color': 'var(--w-rjv-color)',
146
- '--w-rjv-delete-color': '#dc3545',
147
- '--w-rjv-info-color': '#656565',
148
- '--w-rjv-update-color': '#ebcb8b',
153
+ '--w-rjv-info-color': '#9c9c9c7a',
154
+ '--w-rjv-update-color': '#9cdcfe',
149
155
  '--w-rjv-copied-color': '#9cdcfe',
150
156
  '--w-rjv-copied-success-color': '#28a745',
151
157
 
152
158
  '--w-rjv-curlybraces-color': '#d4d4d4',
153
159
  '--w-rjv-colon-color': '#d4d4d4',
154
160
  '--w-rjv-brackets-color': '#d4d4d4',
161
+ '--w-rjv-quotes-color': 'var(--w-rjv-key-string)',
162
+ '--w-rjv-quotes-string-color': 'var(--w-rjv-type-string-color)',
155
163
 
156
164
  '--w-rjv-type-string-color': '#ce9178',
157
- '--w-rjv-type-int-color': '#268bd2',
158
- '--w-rjv-type-float-color': '#859900',
159
- '--w-rjv-type-bigint-color': '#268bd2',
160
- '--w-rjv-type-boolean-color': '#559bd4',
161
- '--w-rjv-type-date-color': '#586e75',
162
- '--w-rjv-type-url-color': '#649bd8',
163
- '--w-rjv-type-null-color': '#d33682',
165
+ '--w-rjv-type-int-color': '#b5cea8',
166
+ '--w-rjv-type-float-color': '#b5cea8',
167
+ '--w-rjv-type-bigint-color': '#b5cea8',
168
+ '--w-rjv-type-boolean-color': '#569cd6',
169
+ '--w-rjv-type-date-color': '#b5cea8',
170
+ '--w-rjv-type-url-color': '#3b89cf',
171
+ '--w-rjv-type-null-color': '#569cd6',
164
172
  '--w-rjv-type-nan-color': '#859900',
165
- '--w-rjv-type-undefined-color': '#586e75',
173
+ '--w-rjv-type-undefined-color': '#569cd6',
166
174
  };
167
175
 
168
176
  export default function Demo() {
@@ -179,7 +187,7 @@ Online custom style example, please check in the [documentation website](https:/
179
187
  ```tsx mdx:preview:&title=Online Editing Theme
180
188
  import React, { useState, useEffect } from 'react';
181
189
  import Colorful from '@uiw/react-color-colorful';
182
- import JsonView from '@uiw/react-json-view/editor';
190
+ import JsonView from '@uiw/react-json-view';
183
191
 
184
192
  const object = {
185
193
  avatar: 'https://i.imgur.com/MK3eW3As.jpg',
@@ -207,31 +215,32 @@ const object = {
207
215
  }
208
216
  const customTheme = {
209
217
  '--w-rjv-color': '#9cdcfe',
218
+ '--w-rjv-key-string': '#9cdcfe',
210
219
  '--w-rjv-background-color': '#1e1e1e',
211
- '--w-rjv-line-color': '#323232',
212
- '--w-rjv-arrow-color': '#9cdcfe',
213
- '--w-rjv-edit-color': '#0184a6',
214
- '--w-rjv-add-color': '#0184a6',
215
- '--w-rjv-delete-color': '#dc3545',
216
- '--w-rjv-info-color': '#656565',
217
- '--w-rjv-update-color': '#ebcb8b',
218
- '--w-rjv-copied-color': '#0184a6',
220
+ '--w-rjv-line-color': '#36334280',
221
+ '--w-rjv-arrow-color': '#838383',
222
+ '--w-rjv-edit-color': '#9cdcfe',
223
+ '--w-rjv-info-color': '#9c9c9c7a',
224
+ '--w-rjv-update-color': '#9cdcfe',
225
+ '--w-rjv-copied-color': '#9cdcfe',
219
226
  '--w-rjv-copied-success-color': '#28a745',
220
227
 
221
228
  '--w-rjv-curlybraces-color': '#d4d4d4',
222
- '--w-rjv-colon-color': '#f8f8f2',
229
+ '--w-rjv-colon-color': '#d4d4d4',
223
230
  '--w-rjv-brackets-color': '#d4d4d4',
231
+ '--w-rjv-quotes-color': '#9cdcfe',
232
+ '--w-rjv-quotes-string-color': '#ce9178',
224
233
 
225
234
  '--w-rjv-type-string-color': '#ce9178',
226
- '--w-rjv-type-int-color': '#268bd2',
227
- '--w-rjv-type-float-color': '#859900',
228
- '--w-rjv-type-bigint-color': '#268bd2',
229
- '--w-rjv-type-boolean-color': '#559bd4',
230
- '--w-rjv-type-date-color': '#586e75',
231
- '--w-rjv-type-url-color': '#0969da',
232
- '--w-rjv-type-null-color': '#d33682',
235
+ '--w-rjv-type-int-color': '#b5cea8',
236
+ '--w-rjv-type-float-color': '#b5cea8',
237
+ '--w-rjv-type-bigint-color': '#b5cea8',
238
+ '--w-rjv-type-boolean-color': '#569cd6',
239
+ '--w-rjv-type-date-color': '#b5cea8',
240
+ '--w-rjv-type-url-color': '#3b89cf',
241
+ '--w-rjv-type-null-color': '#569cd6',
233
242
  '--w-rjv-type-nan-color': '#859900',
234
- '--w-rjv-type-undefined-color': '#586e75',
243
+ '--w-rjv-type-undefined-color': '#569cd6',
235
244
  };
236
245
 
237
246
  export default function Demo() {
@@ -259,20 +268,11 @@ export default function Demo() {
259
268
  const changeEditable = (evn) => setEditable(evn.target.checked);
260
269
  return (
261
270
  <React.Fragment>
262
- <label>
263
- <input type="checkbox" checked={editable} onChange={changeEditable} /> Editable
264
- </label>
265
271
  <div style={{ display: 'flex', gap: '1rem', alignItems: 'flex-start' }}>
266
272
  <JsonView
267
- editable={editable}
273
+ // editable={editable}
268
274
  value={src}
269
275
  keyName="root"
270
- onAdd={(keyOrValue, newValue, value, isAdd) => {
271
- return isAdd;
272
- }}
273
- onEdit={(opts) => {
274
- return true;
275
- }}
276
276
  style={{ flex: 1, overflow: 'auto', ...theme }}
277
277
  />
278
278
  <div>
@@ -289,18 +289,18 @@ export default function Demo() {
289
289
  </div>
290
290
  </div>
291
291
  </div>
292
- Copy the theme configuration below into your project.
293
- <pre>
294
- {JSON.stringify(theme, null, 2)}
292
+ <pre style={{ padding: 10 }}>
293
+ Copy the theme configuration below into your project.
294
+ <JsonView value={theme} displayDataTypes={false} />
295
295
  </pre>
296
296
  </React.Fragment>
297
- )
297
+ );
298
298
  }
299
299
  ```
300
300
 
301
301
  ## Render
302
302
 
303
- **Preview Picture**
303
+ **`v2`** version allows flexible customization of each "part" by providing small sub-components for customization, including value and type components: `<Bigint />`, `<Date />`, `<False />`, `<Float />`, `<Int />`, `<Map />`, `<Nan />`, `<Null />`, `<Set />`, `<String />`, `<True />`, `<Undefined />`, `<Url />`, and symbol components: `<ValueQuote />`, `<Arrow />`, `<Colon />`, `<Quote />`, `<BraceLeft />`, `<BraceRight />`, `<BracketsLeft />`, `<BracketsRight />`.
304
304
 
305
305
  ```tsx mdx:preview
306
306
  import React from 'react';
@@ -312,29 +312,29 @@ const object = {
312
312
  integer: 42,
313
313
  }
314
314
 
315
- function value({ type, children, value, setValue, keyName, parentValue, visible, ...props }) {
316
- if (type === 'string' && /\.(jpg)$/.test(value)) {
317
- return (
318
- <span {...props}>
319
- <img src={value} height="36" />
320
- </span>
321
- );
322
- }
323
- }
324
-
325
315
  export default function Demo() {
326
316
  return (
327
317
  <JsonView
328
318
  value={object}
329
319
  keyName="root"
330
- // quotes=""
331
320
  displayObjectSize={false}
332
- displayDataTypes={false}
333
321
  style={{
334
322
  '--w-rjv-background-color': '#ffffff',
335
323
  }}
336
- components={{ value }}
337
- />
324
+ >
325
+ <JsonView.String
326
+ render={({ children, ...reset }, { type }) => {
327
+ const isImg = /^https?.*\.(jpg|png)$/i.test(children)
328
+ if (type === 'type' && isImg) {
329
+ return <span />
330
+ }
331
+ if (type === 'value' && isImg) {
332
+ return <img {...reset} height="26" src={children} />
333
+ }
334
+ }}
335
+ />
336
+ <JsonView.Colon> -&gt; </JsonView.Colon>
337
+ </JsonView>
338
338
  )
339
339
  }
340
340
  ```
@@ -361,23 +361,13 @@ export default function Demo() {
361
361
  }
362
362
  ```
363
363
 
364
+ Supports certain partial customizations such as: `<Copied />`, `<CountInfo />`, `<CountInfoExtra />`, `<Ellipsis />`, `<KeyName />`
365
+
364
366
  ```tsx mdx:preview
365
- import React from 'react';
366
- import JsonView from '@uiw/react-json-view';
367
+ import React, { Fragment } from 'react';
368
+ import JsonView, { ValueQuote } from '@uiw/react-json-view';
367
369
 
368
- function value({ type, children, visible, keyName, parentValue, value, setValue, ...props }) {
369
- if (value instanceof URL) {
370
- return (
371
- <span {...props}>
372
- <a href={value.href} target="_blank" rel="noopener noreferrer">
373
- {children}
374
- </a>
375
- &nbsp;Open URL
376
- {visible && <del>Button</del>}
377
- </span>
378
- );
379
- }
380
- }
370
+ const Copied = JsonView.Copied;
381
371
 
382
372
  export default function Demo() {
383
373
  return (
@@ -387,11 +377,39 @@ export default function Demo() {
387
377
  urlStr: "https://example.com",
388
378
  github: "https://example.com",
389
379
  }}
390
- components={{ value }}
391
380
  style={{
392
381
  '--w-rjv-background-color': '#ffffff',
393
382
  }}
394
- />
383
+ >
384
+ <Copied
385
+ render={({ 'data-copied': copied, style, onClick, ...props }, { value }) => {
386
+ const styl = { whiteSpace: 'nowrap' }
387
+ if (copied) {
388
+ return <span style={{ ...style, ...styl }}>复制成功</span>
389
+ }
390
+ return <span style={{ ...style, ...styl }} onClick={onClick}>复制</span>
391
+ }}
392
+ />
393
+ <JsonView.Url
394
+ render={(props, { type, value }) => {
395
+ if (type === 'type' && value instanceof URL) {
396
+ return <span />
397
+ }
398
+ if (type === 'value' && value instanceof URL) {
399
+ return (
400
+ <Fragment>
401
+ <a href={value.href} target="_blank" {...props}>
402
+ <ValueQuote />
403
+ {value.href}
404
+ <ValueQuote />
405
+ </a>
406
+ Open URL
407
+ </Fragment>
408
+ );
409
+ }
410
+ }}
411
+ />
412
+ </JsonView>
395
413
  )
396
414
  }
397
415
  ```
@@ -438,92 +456,73 @@ const customTheme = {
438
456
  '--w-rjv-border-left-width': 0,
439
457
  '--w-rjv-color': '#881391',
440
458
  '--w-rjv-type-int-color': '#881391',
459
+ '--w-rjv-key-number': '#881391',
460
+ '--w-rjv-key-string': '#881391',
441
461
  };
442
462
 
463
+ const Quote = JsonView.Quote;
464
+ const BraceLeft = JsonView.BraceLeft;
465
+ const BraceRight = JsonView.BraceRight;
466
+ const CountInfo = JsonView.CountInfo;
467
+ const Ellipsis = JsonView.Ellipsis;
468
+ const CountInfoExtra = JsonView.CountInfoExtra;
469
+
443
470
  export default function Demo() {
444
471
  return (
445
472
  <JsonView
446
473
  value={object}
447
474
  style={customTheme}
448
- quotes=""
449
475
  enableClipboard={false}
450
476
  displayDataTypes={false}
451
- components={{
452
- braces: ({ level }) => level !== 1 && <span />,
453
- countInfo: ({ level, count, visible }) => {
454
- if (level === 1) {
455
- return <span />;
456
- //return visible ? <span>{Array.from({ length: 3 }, () => 'Object').join(', ')}</span> : <span />
457
- }
458
- return <span style={{ color: '#222' }}>Object</span>;
459
- },
460
- ellipsis: ({ level, count }) => {
461
- if (level === 1) {
462
- return <span>{Array.from({ length: 3 }, () => 'Object').join(', ')}</span>;
477
+ >
478
+ <Ellipsis
479
+ render={({ 'data-expanded': isExpanded, className, ...props }, { value }) => {
480
+ if (Array.isArray(value) && isExpanded) {
481
+ console.log('props:',value, isExpanded, props)
482
+ return (
483
+ <span className={className}>
484
+ {Array.from({ length: value.length }, () => 'Object').join(', ')}
485
+ </span>
486
+ )
463
487
  }
464
488
  return <span />;
465
- },
466
- }}
467
- />
489
+ }}
490
+ />
491
+ <Quote>
492
+ <span />
493
+ </Quote>
494
+ <BraceLeft>
495
+ <span />
496
+ </BraceLeft>
497
+ <BraceRight>
498
+ <span />
499
+ </BraceRight>
500
+ <CountInfo
501
+ render={({ 'data-length': length, ...props }, { value }) => {
502
+ const isArray = Array.isArray(value);
503
+ if (isArray) return <span />;
504
+ return (
505
+ <span {...props}>Object</span>
506
+ );
507
+ }}
508
+ />
509
+ </JsonView>
468
510
  );
469
511
  }
470
512
  ```
471
513
 
472
- ## Editor JSON
473
-
474
- ```tsx mdx:preview
475
- import React, { useRef } from 'react';
476
- import JsonViewEditor from '@uiw/react-json-view/editor';
477
- import { type SemicolonProps, useHighlight } from '@uiw/react-json-view';
478
-
479
- const object = {
480
- string: 'Lorem ipsum dolor sit amet',
481
- integer: 42,
482
- float: 114.514,
483
- object: {
484
- 'first-child': true,
485
- 'second-child': false,
486
- 'last-child': null,
487
- 'child': {
488
- 'first': true,
489
- 'second': false,
490
- 'last': null,
491
- },
492
- },
493
- nestedArray: [ [1, 2], [3, 4], { a: 1} ],
494
- }
495
-
496
- const ObjectKey: SemicolonProps['render'] = ({ value, keyName, parentName, ...props }) => {
497
- const $edit = useRef<HTMLSpanElement & HTMLModElement>(null);
498
- useHighlight({ value, highlightUpdates: true, highlightContainer: $edit });
499
- if (keyName === 'integer' && typeof value === 'number' && value > 40) {
500
- return <del {...props} ref={$edit} />;
501
- }
502
- return <span {...props} ref={$edit} />;
503
- }
514
+ Passing **as="tagName"** will automatically infer the type.
504
515
 
505
- export default function Demo() {
506
- return (
507
- <JsonViewEditor
508
- value={object}
509
- keyName="root"
510
- style={{
511
- '--w-rjv-background-color': '#ffffff',
512
- }}
513
- onEdit={(opts) => {
514
- console.log('opts:', opts)
515
- // opts.namespace: ['object', 'child', 'last']
516
- // opts.oldValue: null
517
- // opts.type: "value"
518
- // opts.value: "NULL3"
519
- return true;
520
- }}
521
- components={{
522
- objectKey: ObjectKey
523
- }}
524
- />
525
- );
526
- }
516
+ ```tsx
517
+ <JsonView.CountInfo
518
+ as="del"
519
+ render={(props, { value, keyName }) => {
520
+ if (keyName === 'integer' && typeof value === 'number' && value > 10) {
521
+ console.log('value:', value, props)
522
+ return <del {...props}>{keyName}</del>;
523
+ }
524
+ }}
525
+ />
527
526
  ```
528
527
 
529
528
  ## Highlight Updates
@@ -601,10 +600,11 @@ export default function Demo() {
601
600
  '--w-rjv-background-color': '#ffffff',
602
601
  '--w-rjv-border-left': '1px dashed #ebebeb',
603
602
  }}
604
- components={{
605
- arrow: <TriangleSolidArrow />
606
- }}
607
- />
603
+ >
604
+ <JsonView.Arrow>
605
+ <TriangleSolidArrow />
606
+ </JsonView.Arrow>
607
+ </JsonView>
608
608
  )
609
609
  }
610
610
  ```
@@ -614,6 +614,8 @@ Display of custom **svg** `icon` components
614
614
  ```tsx mdx:preview
615
615
  import React from 'react';
616
616
  import JsonView from '@uiw/react-json-view';
617
+ import { TriangleArrow } from '@uiw/react-json-view/triangle-arrow';
618
+ import { TriangleSolidArrow } from '@uiw/react-json-view/triangle-solid-arrow';
617
619
 
618
620
  const object = {
619
621
  string: 'Lorem ipsum dolor sit amet',
@@ -629,29 +631,6 @@ const object = {
629
631
  [3, 4],
630
632
  ],
631
633
  }
632
-
633
- const Arrow = (props) => {
634
- const { style, 'data-expand': expand, ...reset } = props;
635
- const svgProps = {
636
- style: { cursor: 'pointer', height: '1em', width: '1em' },
637
- viewBox: '0 0 24 24',
638
- fill: 'var(--w-rjv-arrow-color, currentColor)',
639
- ...reset
640
- }
641
- if (!expand) {
642
- return (
643
- <svg {...svgProps}>
644
- <path d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M13,7H11V11H7V13H11V17H13V13H17V11H13V7Z" />
645
- </svg>
646
- );
647
- }
648
- return (
649
- <svg {...svgProps}>
650
- <path d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M7,13H17V11H7" />
651
- </svg>
652
- );
653
- }
654
-
655
634
  export default function Demo() {
656
635
  return (
657
636
  <JsonView
@@ -661,119 +640,126 @@ export default function Demo() {
661
640
  '--w-rjv-background-color': '#ffffff',
662
641
  '--w-rjv-border-left': '1px dashed #ebebeb',
663
642
  }}
664
- components={{
665
- arrow: <Arrow />
666
- }}
667
- />
668
- )
643
+ >
644
+ <JsonView.Arrow
645
+ render={({ 'data-expanded': isExpanded, ...props }) => {
646
+ const svgProps = {
647
+ style: {
648
+ cursor: 'pointer', height: '1em', width: '1em', marginRight: 5, userSelect: 'none'
649
+ },
650
+ fill: "var(--w-rjv-arrow-color, currentColor)"
651
+ }
652
+ if (!isExpanded) {
653
+ return (
654
+ <svg viewBox="0 0 24 24" {...svgProps}>
655
+ <path d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M13,7H11V11H7V13H11V17H13V13H17V11H13V7Z" />
656
+ </svg>
657
+ );
658
+ }
659
+ return (
660
+ <svg viewBox="0 0 24 24" {...svgProps}>
661
+ <path d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M7,13H17V11H7" />
662
+ </svg>
663
+ );
664
+ }}
665
+ />
666
+ </JsonView>
667
+ );
669
668
  }
670
669
  ```
671
670
 
672
671
  ## Props
673
672
 
674
- ### JsonView Props
675
-
676
673
  ```ts
677
- import React from 'react';
678
- import { MetaProps, SemicolonProps, EllipsisProps, ValueViewProps } from '@uiw/react-json-view';
679
- import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
680
- export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
674
+ import { BraceLeft } from './symbol/BraceLeft';
675
+ import { BraceRight } from './symbol/BraceRight';
676
+ import { BracketsLeft } from './symbol/BracketsLeft';
677
+ import { BracketsRight } from './symbol/BracketsRight';
678
+ import { Arrow } from './symbol/Arrow';
679
+ import { Colon } from './symbol/Colon';
680
+ import { Ellipsis } from './symbol/Ellipsis';
681
+ import { Quote } from './symbol/Quote';
682
+ import { ValueQuote } from './symbol/ValueQuote';
683
+ import { Bigint } from './types/Bigint';
684
+ import { Date } from './types/Date';
685
+ import { False } from './types/False';
686
+ import { Float } from './types/Float';
687
+ import { Int } from './types/Int';
688
+ import { Map } from './types/Map';
689
+ import { Nan } from './types/Nan';
690
+ import { Null } from './types/Null';
691
+ import { Set } from './types/Set';
692
+ import { StringText } from './types/String';
693
+ import { True } from './types/True';
694
+ import { Undefined } from './types/Undefined';
695
+ import { Url } from './types/Url';
696
+ import { Copied } from './section/Copied';
697
+ import { CountInfo } from './section/CountInfo';
698
+ import { CountInfoExtra } from './section/CountInfoExtra';
699
+ import { KeyName } from './section/KeyName';
700
+ import { type CountInfoProps } from "./comps/CountInfo";
701
+ import { type CopiedOption } from "./comps/Copied";
702
+ import { type NestedOpenProps } from "./comps/NestedOpen";
703
+ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
681
704
  /** This property contains your input JSON */
682
705
  value?: T;
706
+ /** Whether sort keys through `String.prototype.localeCompare()` @default false */
707
+ objectSortKeys?: boolean | ((a: string, b: string) => number);
683
708
  /** Set the indent-width for nested objects @default 15 */
684
709
  indentWidth?: number;
685
- /** When set to `true`, data type labels prefix values @default true */
686
- displayDataTypes?: boolean;
687
710
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
688
711
  displayObjectSize?: boolean;
689
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
690
- shortenTextAfterLength?: number;
691
- /** Define the root node name. @default undefined */
692
- keyName?: string | number;
712
+ /** When set to `true`, data type labels prefix values @default true */
713
+ displayDataTypes?: boolean;
693
714
  /** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
694
715
  enableClipboard?: boolean;
695
716
  /** Whether to highlight updates. @default true */
696
717
  highlightUpdates?: boolean;
697
- /** Whether sort keys through `String.prototype.localeCompare()` @default false */
698
- objectSortKeys?: boolean | ((a: string, b: string) => number);
699
- /** Display for quotes in object-key @default " */
700
- quotes?: "'" | '"' | '';
701
- /** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
702
- collapsed?: boolean | number;
703
718
  /** Callback function for when a treeNode is expanded or collapsed */
704
719
  onExpand?: (props: {
705
- expand: boolean;
706
- value: T;
707
- keyid: string;
708
- keyName?: string | number;
720
+ expand: boolean;
721
+ value?: T;
722
+ keyid: string;
723
+ keyName?: string | number;
709
724
  }) => void;
710
725
  /** Fires event when you copy */
711
- onCopied?: CopiedProps<T>['onCopied'];
726
+ onCopied?: (text: string, value?: T) => void;
712
727
  /** Redefine interface elements to re-render. */
713
728
  components?: {
714
- braces?: MetaProps['render'];
715
- ellipsis?: EllipsisProps['render'];
716
- arrow?: JSX.Element;
717
- objectKey?: SemicolonProps['render'];
718
- value?: (props: RenderValueProps<T>) => JSX.Element;
719
- copied?: CopiedProps<T>['render'];
720
- countInfo?: (props: CountInfoProps) => JSX.Element;
721
- countInfoExtra?: (props: Omit<CountInfoExtraProps<T>, 'editable'>) => JSX.Element;
729
+ copied?: (props: React.SVGProps<SVGSVGElement>, opts: CopiedOption<T>) => React.ReactNode;
730
+ countInfoExtra?: (props: NestedOpenProps<T>) => React.ReactNode;
722
731
  };
723
732
  }
724
- interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
725
- type: TypeProps['type'];
726
- value?: unknown;
727
- parentValue?: T;
728
- data?: T;
729
- visible?: boolean;
730
- quotes?: JsonViewProps<T>['quotes'];
731
- namespace?: Array<string | number>;
732
- setValue?: React.Dispatch<React.SetStateAction<T>>;
733
- keyName?: ValueViewProps<T>['keyName'];
734
- }
735
- declare const JsonView: React.ForwardRefExoticComponent<Omit<JsonViewProps<object>, "ref"> & React.RefAttributes<HTMLDivElement>>;
733
+ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
734
+ Bigint: typeof Bigint;
735
+ Date: typeof Date;
736
+ False: typeof False;
737
+ Float: typeof Float;
738
+ Int: typeof Int;
739
+ Map: typeof Map;
740
+ Nan: typeof Nan;
741
+ Null: typeof Null;
742
+ Set: typeof Set;
743
+ String: typeof StringText;
744
+ True: typeof True;
745
+ Undefined: typeof Undefined;
746
+ Url: typeof Url;
747
+ BraceLeft: typeof BraceLeft;
748
+ BraceRight: typeof BraceRight;
749
+ BracketsLeft: typeof BracketsLeft;
750
+ BracketsRight: typeof BracketsRight;
751
+ Colon: typeof Colon;
752
+ Ellipsis: typeof Ellipsis;
753
+ Quote: typeof Quote;
754
+ ValueQuote: typeof ValueQuote;
755
+ Arrow: typeof Arrow;
756
+ Copied: typeof Copied;
757
+ CountInfo: typeof CountInfo;
758
+ CountInfoExtra: typeof CountInfoExtra;
759
+ KeyName: typeof KeyName;
760
+ };
761
+ declare const JsonView: JsonViewComponent;
736
762
  export default JsonView;
737
- export interface CountInfoProps {
738
- count: number;
739
- level: number;
740
- visible: boolean;
741
- }
742
- ```
743
-
744
- ### JsonView Editor Props
745
-
746
- ```ts
747
- import { JsonViewProps } from '@uiw/react-json-view';
748
- import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
749
- export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
750
- /**
751
- * When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
752
- * @returns {boolean} Returning false from onEdit will prevent the change from being made.
753
- */
754
- onEdit?: (option: {
755
- value: unknown;
756
- oldValue: unknown;
757
- keyName?: string | number;
758
- parentName?: string | number;
759
- namespace?: Array<string | number>;
760
- type?: 'value' | 'key';
761
- }) => boolean;
762
- /**
763
- * When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
764
- * @returns {boolean} Returning false from onAdd will prevent the change from being made.
765
- */
766
- onAdd?: CountInfoExtraProps<T>['onAdd'];
767
- /**
768
- * When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
769
- * @returns Returning false from onDelete will prevent the change from being made.
770
- */
771
- onDelete?: CountInfoExtraProps<T>['onDelete'];
772
- /** Whether enable edit feature. @default true */
773
- editable?: boolean;
774
- }
775
- declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
776
- export default JsonViewEditor;
777
763
  ```
778
764
 
779
765
  ## Size and dependencies