@uiw/react-json-view 1.12.0 → 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 -265
  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 -15
  233. package/cjs/node.js +0 -343
  234. package/cjs/semicolon.d.ts +0 -22
  235. package/cjs/semicolon.js +0 -115
  236. package/cjs/value.d.ts +0 -93
  237. package/cjs/value.js +0 -356
  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 -15
  258. package/esm/node.js +0 -299
  259. package/esm/semicolon.d.ts +0 -22
  260. package/esm/value.d.ts +0 -93
  261. package/esm/value.js +0 -331
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,33 +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',
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',
232
242
  '--w-rjv-type-nan-color': '#859900',
233
- '--w-rjv-type-undefined-color': '#586e75',
234
- '--w-rjv-type-null-color': '#d33682',
235
- '--w-rjv-type-set-color': '#268bd2',
236
- '--w-rjv-type-map-color': '#268bd2',
243
+ '--w-rjv-type-undefined-color': '#569cd6',
237
244
  };
238
245
 
239
246
  export default function Demo() {
@@ -261,20 +268,11 @@ export default function Demo() {
261
268
  const changeEditable = (evn) => setEditable(evn.target.checked);
262
269
  return (
263
270
  <React.Fragment>
264
- <label>
265
- <input type="checkbox" checked={editable} onChange={changeEditable} /> Editable
266
- </label>
267
271
  <div style={{ display: 'flex', gap: '1rem', alignItems: 'flex-start' }}>
268
272
  <JsonView
269
- editable={editable}
273
+ // editable={editable}
270
274
  value={src}
271
275
  keyName="root"
272
- onAdd={(keyOrValue, newValue, value, isAdd) => {
273
- return isAdd;
274
- }}
275
- onEdit={(opts) => {
276
- return true;
277
- }}
278
276
  style={{ flex: 1, overflow: 'auto', ...theme }}
279
277
  />
280
278
  <div>
@@ -291,18 +289,18 @@ export default function Demo() {
291
289
  </div>
292
290
  </div>
293
291
  </div>
294
- Copy the theme configuration below into your project.
295
- <pre>
296
- {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} />
297
295
  </pre>
298
296
  </React.Fragment>
299
- )
297
+ );
300
298
  }
301
299
  ```
302
300
 
303
301
  ## Render
304
302
 
305
- **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 />`.
306
304
 
307
305
  ```tsx mdx:preview
308
306
  import React from 'react';
@@ -314,29 +312,29 @@ const object = {
314
312
  integer: 42,
315
313
  }
316
314
 
317
- function value({ type, children, value, setValue, keyName, parentValue, visible, ...props }) {
318
- if (type === 'string' && /\.(jpg)$/.test(value)) {
319
- return (
320
- <span {...props}>
321
- <img src={value} height="36" />
322
- </span>
323
- );
324
- }
325
- }
326
-
327
315
  export default function Demo() {
328
316
  return (
329
317
  <JsonView
330
318
  value={object}
331
319
  keyName="root"
332
- // quotes=""
333
320
  displayObjectSize={false}
334
- displayDataTypes={false}
335
321
  style={{
336
322
  '--w-rjv-background-color': '#ffffff',
337
323
  }}
338
- components={{ value }}
339
- />
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>
340
338
  )
341
339
  }
342
340
  ```
@@ -363,23 +361,13 @@ export default function Demo() {
363
361
  }
364
362
  ```
365
363
 
364
+ Supports certain partial customizations such as: `<Copied />`, `<CountInfo />`, `<CountInfoExtra />`, `<Ellipsis />`, `<KeyName />`
365
+
366
366
  ```tsx mdx:preview
367
- import React from 'react';
368
- import JsonView from '@uiw/react-json-view';
367
+ import React, { Fragment } from 'react';
368
+ import JsonView, { ValueQuote } from '@uiw/react-json-view';
369
369
 
370
- function value({ type, children, visible, keyName, parentValue, value, setValue, ...props }) {
371
- if (value instanceof URL) {
372
- return (
373
- <span {...props}>
374
- <a href={value.href} target="_blank" rel="noopener noreferrer">
375
- {children}
376
- </a>
377
- &nbsp;Open URL
378
- {visible && <del>Button</del>}
379
- </span>
380
- );
381
- }
382
- }
370
+ const Copied = JsonView.Copied;
383
371
 
384
372
  export default function Demo() {
385
373
  return (
@@ -389,11 +377,39 @@ export default function Demo() {
389
377
  urlStr: "https://example.com",
390
378
  github: "https://example.com",
391
379
  }}
392
- components={{ value }}
393
380
  style={{
394
381
  '--w-rjv-background-color': '#ffffff',
395
382
  }}
396
- />
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>
397
413
  )
398
414
  }
399
415
  ```
@@ -440,92 +456,73 @@ const customTheme = {
440
456
  '--w-rjv-border-left-width': 0,
441
457
  '--w-rjv-color': '#881391',
442
458
  '--w-rjv-type-int-color': '#881391',
459
+ '--w-rjv-key-number': '#881391',
460
+ '--w-rjv-key-string': '#881391',
443
461
  };
444
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
+
445
470
  export default function Demo() {
446
471
  return (
447
472
  <JsonView
448
473
  value={object}
449
474
  style={customTheme}
450
- quotes=""
451
475
  enableClipboard={false}
452
476
  displayDataTypes={false}
453
- components={{
454
- braces: ({ level }) => level !== 1 && <span />,
455
- countInfo: ({ level, count, visible }) => {
456
- if (level === 1) {
457
- return <span />;
458
- //return visible ? <span>{Array.from({ length: 3 }, () => 'Object').join(', ')}</span> : <span />
459
- }
460
- return <span style={{ color: '#222' }}>Object</span>;
461
- },
462
- ellipsis: ({ level, count }) => {
463
- if (level === 1) {
464
- 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
+ )
465
487
  }
466
488
  return <span />;
467
- },
468
- }}
469
- />
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>
470
510
  );
471
511
  }
472
512
  ```
473
513
 
474
- ## Editor JSON
475
-
476
- ```tsx mdx:preview
477
- import React, { useRef } from 'react';
478
- import JsonViewEditor from '@uiw/react-json-view/editor';
479
- import { type SemicolonProps, useHighlight } from '@uiw/react-json-view';
480
-
481
- const object = {
482
- string: 'Lorem ipsum dolor sit amet',
483
- integer: 42,
484
- float: 114.514,
485
- object: {
486
- 'first-child': true,
487
- 'second-child': false,
488
- 'last-child': null,
489
- 'child': {
490
- 'first': true,
491
- 'second': false,
492
- 'last': null,
493
- },
494
- },
495
- nestedArray: [ [1, 2], [3, 4], { a: 1} ],
496
- }
497
-
498
- const ObjectKey: SemicolonProps['render'] = ({ value, keyName, parentName, ...props }) => {
499
- const $edit = useRef<HTMLSpanElement & HTMLModElement>(null);
500
- useHighlight({ value, highlightUpdates: true, highlightContainer: $edit });
501
- if (keyName === 'integer' && typeof value === 'number' && value > 40) {
502
- return <del {...props} ref={$edit} />;
503
- }
504
- return <span {...props} ref={$edit} />;
505
- }
514
+ Passing **as="tagName"** will automatically infer the type.
506
515
 
507
- export default function Demo() {
508
- return (
509
- <JsonViewEditor
510
- value={object}
511
- keyName="root"
512
- style={{
513
- '--w-rjv-background-color': '#ffffff',
514
- }}
515
- onEdit={(opts) => {
516
- console.log('opts:', opts)
517
- // opts.namespace: ['object', 'child', 'last']
518
- // opts.oldValue: null
519
- // opts.type: "value"
520
- // opts.value: "NULL3"
521
- return true;
522
- }}
523
- components={{
524
- objectKey: ObjectKey
525
- }}
526
- />
527
- );
528
- }
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
+ />
529
526
  ```
530
527
 
531
528
  ## Highlight Updates
@@ -603,10 +600,11 @@ export default function Demo() {
603
600
  '--w-rjv-background-color': '#ffffff',
604
601
  '--w-rjv-border-left': '1px dashed #ebebeb',
605
602
  }}
606
- components={{
607
- arrow: <TriangleSolidArrow />
608
- }}
609
- />
603
+ >
604
+ <JsonView.Arrow>
605
+ <TriangleSolidArrow />
606
+ </JsonView.Arrow>
607
+ </JsonView>
610
608
  )
611
609
  }
612
610
  ```
@@ -616,6 +614,8 @@ Display of custom **svg** `icon` components
616
614
  ```tsx mdx:preview
617
615
  import React from 'react';
618
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';
619
619
 
620
620
  const object = {
621
621
  string: 'Lorem ipsum dolor sit amet',
@@ -631,29 +631,6 @@ const object = {
631
631
  [3, 4],
632
632
  ],
633
633
  }
634
-
635
- const Arrow = (props) => {
636
- const { style, 'data-expand': expand, ...reset } = props;
637
- const svgProps = {
638
- style: { cursor: 'pointer', height: '1em', width: '1em' },
639
- viewBox: '0 0 24 24',
640
- fill: 'var(--w-rjv-arrow-color, currentColor)',
641
- ...reset
642
- }
643
- if (!expand) {
644
- return (
645
- <svg {...svgProps}>
646
- <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" />
647
- </svg>
648
- );
649
- }
650
- return (
651
- <svg {...svgProps}>
652
- <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" />
653
- </svg>
654
- );
655
- }
656
-
657
634
  export default function Demo() {
658
635
  return (
659
636
  <JsonView
@@ -663,119 +640,126 @@ export default function Demo() {
663
640
  '--w-rjv-background-color': '#ffffff',
664
641
  '--w-rjv-border-left': '1px dashed #ebebeb',
665
642
  }}
666
- components={{
667
- arrow: <Arrow />
668
- }}
669
- />
670
- )
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
+ );
671
668
  }
672
669
  ```
673
670
 
674
671
  ## Props
675
672
 
676
- ### JsonView Props
677
-
678
673
  ```ts
679
- import React from 'react';
680
- import { MetaProps, SemicolonProps, EllipsisProps, ValueViewProps } from '@uiw/react-json-view';
681
- import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
682
- 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> {
683
704
  /** This property contains your input JSON */
684
705
  value?: T;
706
+ /** Whether sort keys through `String.prototype.localeCompare()` @default false */
707
+ objectSortKeys?: boolean | ((a: string, b: string) => number);
685
708
  /** Set the indent-width for nested objects @default 15 */
686
709
  indentWidth?: number;
687
- /** When set to `true`, data type labels prefix values @default true */
688
- displayDataTypes?: boolean;
689
710
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
690
711
  displayObjectSize?: boolean;
691
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
692
- shortenTextAfterLength?: number;
693
- /** Define the root node name. @default undefined */
694
- keyName?: string | number;
712
+ /** When set to `true`, data type labels prefix values @default true */
713
+ displayDataTypes?: boolean;
695
714
  /** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
696
715
  enableClipboard?: boolean;
697
716
  /** Whether to highlight updates. @default true */
698
717
  highlightUpdates?: boolean;
699
- /** Whether sort keys through `String.prototype.localeCompare()` @default false */
700
- objectSortKeys?: boolean | ((a: string, b: string) => number);
701
- /** Display for quotes in object-key @default " */
702
- quotes?: "'" | '"' | '';
703
- /** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
704
- collapsed?: boolean | number;
705
718
  /** Callback function for when a treeNode is expanded or collapsed */
706
719
  onExpand?: (props: {
707
- expand: boolean;
708
- value: T;
709
- keyid: string;
710
- keyName?: string | number;
720
+ expand: boolean;
721
+ value?: T;
722
+ keyid: string;
723
+ keyName?: string | number;
711
724
  }) => void;
712
725
  /** Fires event when you copy */
713
- onCopied?: CopiedProps<T>['onCopied'];
726
+ onCopied?: (text: string, value?: T) => void;
714
727
  /** Redefine interface elements to re-render. */
715
728
  components?: {
716
- braces?: MetaProps['render'];
717
- ellipsis?: EllipsisProps['render'];
718
- arrow?: JSX.Element;
719
- objectKey?: SemicolonProps['render'];
720
- value?: (props: RenderValueProps<T>) => JSX.Element;
721
- copied?: CopiedProps<T>['render'];
722
- countInfo?: (props: CountInfoProps) => JSX.Element;
723
- 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;
724
731
  };
725
732
  }
726
- interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
727
- type: TypeProps['type'];
728
- value?: unknown;
729
- parentValue?: T;
730
- data?: T;
731
- visible?: boolean;
732
- quotes?: JsonViewProps<T>['quotes'];
733
- namespace?: Array<string | number>;
734
- setValue?: React.Dispatch<React.SetStateAction<T>>;
735
- keyName?: ValueViewProps<T>['keyName'];
736
- }
737
- 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;
738
762
  export default JsonView;
739
- export interface CountInfoProps {
740
- count: number;
741
- level: number;
742
- visible: boolean;
743
- }
744
- ```
745
-
746
- ### JsonView Editor Props
747
-
748
- ```ts
749
- import { JsonViewProps } from '@uiw/react-json-view';
750
- import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
751
- export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
752
- /**
753
- * When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
754
- * @returns {boolean} Returning false from onEdit will prevent the change from being made.
755
- */
756
- onEdit?: (option: {
757
- value: unknown;
758
- oldValue: unknown;
759
- keyName?: string | number;
760
- parentName?: string | number;
761
- namespace?: Array<string | number>;
762
- type?: 'value' | 'key';
763
- }) => boolean;
764
- /**
765
- * When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
766
- * @returns {boolean} Returning false from onAdd will prevent the change from being made.
767
- */
768
- onAdd?: CountInfoExtraProps<T>['onAdd'];
769
- /**
770
- * When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
771
- * @returns Returning false from onDelete will prevent the change from being made.
772
- */
773
- onDelete?: CountInfoExtraProps<T>['onDelete'];
774
- /** Whether enable edit feature. @default true */
775
- editable?: boolean;
776
- }
777
- declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
778
- export default JsonViewEditor;
779
763
  ```
780
764
 
781
765
  ## Size and dependencies