@uiw/react-json-view 2.0.0-alpha.2 → 2.0.0-alpha.21

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 (186) hide show
  1. package/README.md +146 -21
  2. package/basic.d.ts +3 -0
  3. package/cjs/Container.d.ts +2 -0
  4. package/cjs/Container.js +9 -4
  5. package/cjs/arrow/TriangleArrow.js +1 -1
  6. package/cjs/comps/Copied.d.ts +2 -3
  7. package/cjs/comps/Copied.js +29 -16
  8. package/cjs/comps/KeyValues.d.ts +2 -4
  9. package/cjs/comps/KeyValues.js +49 -24
  10. package/cjs/comps/NestedClose.js +3 -4
  11. package/cjs/comps/NestedOpen.d.ts +2 -3
  12. package/cjs/comps/NestedOpen.js +23 -17
  13. package/cjs/comps/Value.d.ts +1 -2
  14. package/cjs/comps/Value.js +16 -20
  15. package/cjs/editor/KeyName.d.ts +2 -0
  16. package/cjs/editor/KeyName.js +82 -0
  17. package/cjs/editor/index.d.ts +19 -0
  18. package/cjs/editor/index.js +44 -0
  19. package/cjs/editor/store.d.ts +28 -0
  20. package/cjs/editor/store.js +23 -0
  21. package/cjs/index.d.ts +5 -3
  22. package/cjs/index.js +11 -8
  23. package/cjs/section/Copied.d.ts +1 -1
  24. package/cjs/section/Copied.js +1 -2
  25. package/cjs/section/CountInfo.d.ts +10 -1
  26. package/cjs/section/CountInfo.js +42 -4
  27. package/cjs/section/CountInfoExtra.d.ts +10 -1
  28. package/cjs/section/CountInfoExtra.js +32 -4
  29. package/cjs/section/Ellipsis.d.ts +10 -0
  30. package/cjs/section/Ellipsis.js +30 -4
  31. package/cjs/section/KeyName.d.ts +8 -0
  32. package/cjs/section/KeyName.js +40 -4
  33. package/cjs/section/Row.d.ts +14 -0
  34. package/cjs/section/Row.js +51 -0
  35. package/cjs/store/Expands.js +2 -4
  36. package/cjs/store/Section.d.ts +12 -6
  37. package/cjs/store/Section.js +6 -4
  38. package/cjs/store/ShowTools.js +2 -4
  39. package/cjs/store/Symbols.d.ts +2 -2
  40. package/cjs/store/Symbols.js +2 -4
  41. package/cjs/store/Types.d.ts +28 -24
  42. package/cjs/store/Types.js +8 -8
  43. package/cjs/store.d.ts +7 -4
  44. package/cjs/store.js +5 -10
  45. package/cjs/symbol/Arrow.d.ts +1 -1
  46. package/cjs/symbol/Arrow.js +1 -2
  47. package/cjs/symbol/BraceLeft.d.ts +1 -1
  48. package/cjs/symbol/BraceLeft.js +1 -2
  49. package/cjs/symbol/BraceRight.d.ts +1 -1
  50. package/cjs/symbol/BraceRight.js +1 -2
  51. package/cjs/symbol/BracketsLeft.d.ts +1 -1
  52. package/cjs/symbol/BracketsLeft.js +1 -2
  53. package/cjs/symbol/BracketsRight.d.ts +1 -1
  54. package/cjs/symbol/BracketsRight.js +1 -2
  55. package/cjs/symbol/Colon.d.ts +1 -1
  56. package/cjs/symbol/Colon.js +1 -2
  57. package/cjs/symbol/Quote.d.ts +1 -1
  58. package/cjs/symbol/Quote.js +1 -2
  59. package/cjs/symbol/ValueQuote.d.ts +1 -1
  60. package/cjs/symbol/ValueQuote.js +1 -2
  61. package/{esm/comps/ReRender/Symbols.d.ts → cjs/symbol/index.d.ts} +4 -6
  62. package/cjs/{comps/ReRender/Symbols.js → symbol/index.js} +32 -33
  63. package/cjs/theme/basic.js +4 -3
  64. package/cjs/theme/dark.js +2 -3
  65. package/cjs/theme/github.dark.js +2 -3
  66. package/cjs/theme/github.light.js +2 -3
  67. package/cjs/theme/gruvbox.js +2 -3
  68. package/cjs/theme/light.js +2 -3
  69. package/cjs/theme/monokai.js +2 -3
  70. package/cjs/theme/nord.js +2 -3
  71. package/cjs/theme/vscode.js +2 -3
  72. package/cjs/types/Bigint.d.ts +1 -1
  73. package/cjs/types/Bigint.js +1 -2
  74. package/cjs/types/Date.d.ts +1 -1
  75. package/cjs/types/Date.js +1 -2
  76. package/cjs/types/False.d.ts +1 -1
  77. package/cjs/types/False.js +1 -2
  78. package/cjs/types/Float.d.ts +1 -1
  79. package/cjs/types/Float.js +1 -2
  80. package/cjs/types/Int.d.ts +1 -1
  81. package/cjs/types/Int.js +1 -2
  82. package/cjs/types/Map.d.ts +1 -1
  83. package/cjs/types/Map.js +1 -2
  84. package/cjs/types/Nan.d.ts +1 -1
  85. package/cjs/types/Nan.js +1 -2
  86. package/cjs/types/Null.d.ts +1 -1
  87. package/cjs/types/Null.js +1 -2
  88. package/cjs/types/Set.d.ts +1 -1
  89. package/cjs/types/Set.js +1 -2
  90. package/cjs/types/String.d.ts +1 -1
  91. package/cjs/types/String.js +1 -2
  92. package/cjs/types/True.d.ts +1 -1
  93. package/cjs/types/True.js +1 -2
  94. package/cjs/types/Undefined.d.ts +1 -1
  95. package/cjs/types/Undefined.js +1 -2
  96. package/cjs/types/Url.d.ts +1 -1
  97. package/cjs/types/Url.js +1 -2
  98. package/{esm/comps/ReRender/Types.d.ts → cjs/types/index.d.ts} +2 -2
  99. package/cjs/{comps/ReRender/Types.js → types/index.js} +92 -171
  100. package/cjs/utils/useHighlight.js +0 -1
  101. package/cjs/utils/useRender.d.ts +1 -1
  102. package/editor.d.ts +22 -20
  103. package/esm/Container.d.ts +2 -0
  104. package/esm/Container.js +10 -4
  105. package/esm/arrow/TriangleArrow.js +1 -1
  106. package/esm/comps/Copied.d.ts +2 -3
  107. package/esm/comps/Copied.js +27 -15
  108. package/esm/comps/KeyValues.d.ts +2 -4
  109. package/esm/comps/KeyValues.js +37 -15
  110. package/esm/comps/NestedClose.js +1 -1
  111. package/esm/comps/NestedOpen.d.ts +2 -3
  112. package/esm/comps/NestedOpen.js +18 -12
  113. package/esm/comps/Value.d.ts +1 -2
  114. package/esm/comps/Value.js +3 -5
  115. package/esm/editor/KeyName.d.ts +2 -0
  116. package/esm/editor/KeyName.js +77 -0
  117. package/esm/editor/index.d.ts +19 -0
  118. package/esm/editor/index.js +33 -0
  119. package/esm/editor/store.d.ts +28 -0
  120. package/esm/editor/store.js +13 -0
  121. package/esm/index.d.ts +5 -3
  122. package/esm/index.js +9 -6
  123. package/esm/section/Copied.d.ts +1 -1
  124. package/esm/section/CountInfo.d.ts +10 -1
  125. package/esm/section/CountInfo.js +43 -1
  126. package/esm/section/CountInfoExtra.d.ts +10 -1
  127. package/esm/section/CountInfoExtra.js +32 -1
  128. package/esm/section/Ellipsis.d.ts +10 -0
  129. package/esm/section/Ellipsis.js +31 -1
  130. package/esm/section/KeyName.d.ts +8 -0
  131. package/esm/section/KeyName.js +41 -1
  132. package/esm/section/Row.d.ts +14 -0
  133. package/esm/section/Row.js +47 -0
  134. package/esm/store/Section.d.ts +12 -6
  135. package/esm/store/Section.js +4 -0
  136. package/esm/store/Symbols.d.ts +2 -2
  137. package/esm/store/Types.d.ts +28 -24
  138. package/esm/store/Types.js +6 -4
  139. package/esm/store.d.ts +7 -4
  140. package/esm/symbol/Arrow.d.ts +1 -1
  141. package/esm/symbol/BraceLeft.d.ts +1 -1
  142. package/esm/symbol/BraceRight.d.ts +1 -1
  143. package/esm/symbol/BracketsLeft.d.ts +1 -1
  144. package/esm/symbol/BracketsRight.d.ts +1 -1
  145. package/esm/symbol/Colon.d.ts +1 -1
  146. package/esm/symbol/Quote.d.ts +1 -1
  147. package/esm/symbol/ValueQuote.d.ts +1 -1
  148. package/{cjs/comps/ReRender/Symbols.d.ts → esm/symbol/index.d.ts} +4 -6
  149. package/esm/{comps/ReRender/Symbols.js → symbol/index.js} +26 -24
  150. package/esm/theme/basic.js +2 -0
  151. package/esm/types/Bigint.d.ts +1 -1
  152. package/esm/types/Date.d.ts +1 -1
  153. package/esm/types/False.d.ts +1 -1
  154. package/esm/types/Float.d.ts +1 -1
  155. package/esm/types/Int.d.ts +1 -1
  156. package/esm/types/Map.d.ts +1 -1
  157. package/esm/types/Nan.d.ts +1 -1
  158. package/esm/types/Null.d.ts +1 -1
  159. package/esm/types/Set.d.ts +1 -1
  160. package/esm/types/String.d.ts +1 -1
  161. package/esm/types/True.d.ts +1 -1
  162. package/esm/types/Undefined.d.ts +1 -1
  163. package/esm/types/Url.d.ts +1 -1
  164. package/{cjs/comps/ReRender/Types.d.ts → esm/types/index.d.ts} +2 -2
  165. package/esm/{comps/ReRender/Types.js → types/index.js} +76 -148
  166. package/esm/utils/useHighlight.js +0 -1
  167. package/esm/utils/useRender.d.ts +1 -1
  168. package/githubDark.d.ts +3 -0
  169. package/githubLight.d.ts +3 -0
  170. package/gruvbox.d.ts +3 -0
  171. package/monokai.d.ts +3 -0
  172. package/nord.d.ts +3 -0
  173. package/package.json +11 -5
  174. package/vscode.d.ts +3 -0
  175. package/cjs/comps/CountInfo.d.ts +0 -19
  176. package/cjs/comps/CountInfo.js +0 -72
  177. package/cjs/comps/Ellipsis.d.ts +0 -10
  178. package/cjs/comps/Ellipsis.js +0 -35
  179. package/cjs/comps/Key.d.ts +0 -7
  180. package/cjs/comps/Key.js +0 -41
  181. package/esm/comps/CountInfo.d.ts +0 -19
  182. package/esm/comps/CountInfo.js +0 -70
  183. package/esm/comps/Ellipsis.d.ts +0 -10
  184. package/esm/comps/Ellipsis.js +0 -31
  185. package/esm/comps/Key.d.ts +0 -7
  186. package/esm/comps/Key.js +0 -37
package/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  react-json-view
2
2
  ===
3
3
 
4
+ [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor)
4
5
  [![CI](https://github.com/uiwjs/react-json-view/actions/workflows/ci.yml/badge.svg)](https://github.com/uiwjs/react-json-view/actions/workflows/ci.yml)
5
6
  [![npm version](https://img.shields.io/npm/v/@uiw/react-json-view.svg)](https://www.npmjs.com/package/@uiw/react-json-view)
6
7
  [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-json-view.svg?style=flat&label=)](https://www.npmjs.com/package/@uiw/react-json-view)
7
8
  [![react@^18](https://shields.io/badge/react-^18-green?style=flat&logo=react)](https://github.com/facebook/react/releases)
8
9
  [![Coverage Status](https://uiwjs.github.io/react-json-view/badges.svg)](https://uiwjs.github.io/react-json-view/lcov-report/)
9
10
 
10
- A React component for displaying and editing javascript arrays and JSON objects.
11
+ A React component for displaying and editing javascript arrays and JSON objects. Preview of [**v1 documentation**](https://raw.githack.com/uiwjs/react-json-view/v1-docs/index.html) is available [here](https://raw.githack.com/uiwjs/react-json-view/v1-docs/index.html).
11
12
 
12
13
  <!--rehype:ignore:start-->
13
14
  <a href="https://uiwjs.github.io/react-json-view/" target="_blank">
@@ -26,12 +27,13 @@ A React component for displaying and editing javascript arrays and JSON objects.
26
27
  ✏️ Support editing and adding features
27
28
  ♻️ Whether to highlight updates.
28
29
 
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
+ The new version [**v2**](https://uiwjs.github.io/react-json-view/) 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://uiwjs.github.io/react-json-view/) and [examples](https://uiwjs.github.io/react-json-view/).
30
31
 
31
32
  - [x] Complete all features of displaying JSON in v1.
32
33
  - [ ] Add editing functionality to v2.
33
34
  - [x] Add test cases to v2.
34
35
 
36
+
35
37
  ## Quick Start
36
38
 
37
39
  ```bash
@@ -145,6 +147,7 @@ const object = {
145
147
  const customTheme = {
146
148
  '--w-rjv-font-family': 'monospace',
147
149
  '--w-rjv-color': '#9cdcfe',
150
+ '--w-rjv-key-number': '#268bd2',
148
151
  '--w-rjv-key-string': '#9cdcfe',
149
152
  '--w-rjv-background-color': '#1e1e1e',
150
153
  '--w-rjv-line-color': '#36334280',
@@ -158,6 +161,7 @@ const customTheme = {
158
161
  '--w-rjv-curlybraces-color': '#d4d4d4',
159
162
  '--w-rjv-colon-color': '#d4d4d4',
160
163
  '--w-rjv-brackets-color': '#d4d4d4',
164
+ '--w-rjv-ellipsis-color': '#cb4b16',
161
165
  '--w-rjv-quotes-color': 'var(--w-rjv-key-string)',
162
166
  '--w-rjv-quotes-string-color': 'var(--w-rjv-type-string-color)',
163
167
 
@@ -215,6 +219,7 @@ const object = {
215
219
  }
216
220
  const customTheme = {
217
221
  '--w-rjv-color': '#9cdcfe',
222
+ '--w-rjv-key-number': '#268bd2',
218
223
  '--w-rjv-key-string': '#9cdcfe',
219
224
  '--w-rjv-background-color': '#1e1e1e',
220
225
  '--w-rjv-line-color': '#36334280',
@@ -228,6 +233,7 @@ const customTheme = {
228
233
  '--w-rjv-curlybraces-color': '#d4d4d4',
229
234
  '--w-rjv-colon-color': '#d4d4d4',
230
235
  '--w-rjv-brackets-color': '#d4d4d4',
236
+ '--w-rjv-ellipsis-color': '#cb4b16',
231
237
  '--w-rjv-quotes-color': '#9cdcfe',
232
238
  '--w-rjv-quotes-string-color': '#ce9178',
233
239
 
@@ -277,21 +283,31 @@ export default function Demo() {
277
283
  />
278
284
  <div>
279
285
  <Colorful color={hex} onChange={onChange} />
280
- <div style={{ display: 'flex', gap: '0.4rem', flexDirection: 'column' }}>
286
+ <div style={{ display: 'flex', gap: '0.4rem', flexDirection: 'column', ...customTheme }}>
281
287
  {Object.keys(customTheme).map((varname, idx) => {
282
288
  const click = () => {
283
289
  setCssvar(varname);
284
290
  setHex(customTheme[varname]);
285
291
  };
286
292
  const active = cssvar === varname ? '#a8a8a8' : '';
287
- return <button key={idx} style={{ background: active, border: 0,boxShadow: 'inset 0px 0px 1px #000', textAlign: 'left' }} onClick={click}>{varname}</button>
293
+ return (
294
+ <button key={idx}
295
+ style={{ background: active, border: 0,boxShadow: 'inset 0px 0px 1px #000', display: 'flex', alignItems: 'center', gap: 5, padding: '1px 3px' }}
296
+ onClick={click}
297
+ >
298
+ <span style={{ display: 'inline-block', width: 12, height: 12, background: `var(${varname})` }}></span>
299
+ {varname}
300
+ </button>
301
+ )
288
302
  })}
289
303
  </div>
290
304
  </div>
291
305
  </div>
292
- <pre style={{ padding: 10 }}>
306
+ <div>
293
307
  Copy the theme configuration below into your project.
294
- <JsonView value={theme} displayDataTypes={false} />
308
+ </div>
309
+ <pre style={{ padding: 10 }}>
310
+ {JSON.stringify(theme, null, 2)}
295
311
  </pre>
296
312
  </React.Fragment>
297
313
  );
@@ -323,13 +339,13 @@ export default function Demo() {
323
339
  }}
324
340
  >
325
341
  <JsonView.String
326
- render={({ children, ...reset }, { type }) => {
327
- const isImg = /^https?.*\.(jpg|png)$/i.test(children)
342
+ render={({ children, ...reset }, { type, value, keyName }) => {
343
+ const isImg = /^https?.*\.(jpg|png)$/i.test(value)
328
344
  if (type === 'type' && isImg) {
329
345
  return <span />
330
346
  }
331
347
  if (type === 'value' && isImg) {
332
- return <img {...reset} height="26" src={children} />
348
+ return <img {...reset} height="26" src={value} />
333
349
  }
334
350
  }}
335
351
  />
@@ -361,7 +377,7 @@ export default function Demo() {
361
377
  }
362
378
  ```
363
379
 
364
- Supports certain partial customizations such as: `<Copied />`, `<CountInfo />`, `<CountInfoExtra />`, `<Ellipsis />`, `<KeyName />`
380
+ Supports certain partial customizations such as: `<Copied />`, `<CountInfo />`, `<CountInfoExtra />`, `<Ellipsis />`, `<KeyName />`, `<Row />`
365
381
 
366
382
  ```tsx mdx:preview
367
383
  import React, { Fragment } from 'react';
@@ -414,6 +430,59 @@ export default function Demo() {
414
430
  }
415
431
  ```
416
432
 
433
+ More in-depth customization ([#19](https://github.com/uiwjs/react-json-view/issues/19))
434
+
435
+ ```tsx mdx:preview
436
+ import React from 'react';
437
+ import JsonView from '@uiw/react-json-view';
438
+
439
+ const object = {
440
+ _id: "ObjectId('13212hakjdhajksd')",
441
+ uid: "test1",
442
+ attival_time: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'),
443
+ __v: 0
444
+ }
445
+
446
+ export default function Demo() {
447
+ return (
448
+ <JsonView
449
+ value={object}
450
+ // keyName="root"
451
+ displayObjectSize={false}
452
+ style={{
453
+ '--w-rjv-background-color': '#ffffff',
454
+ }}
455
+ >
456
+ <JsonView.Quote render={() => <span />}/>
457
+ <JsonView.String
458
+ render={({ children, ...reset }, { type, value, keyName }) => {
459
+ if (type === 'type') {
460
+ return <span />
461
+ }
462
+ if (type === 'value' && /ObjectId\(['"](.*?)['"]\)/.test(value)) {
463
+ return <span {...reset}>{children}</span>
464
+ }
465
+ }}
466
+ />
467
+ <JsonView.Date
468
+ render={({ children, ...reset }, { type, value, keyName }) => {
469
+ if (type === 'type') {
470
+ return <span />
471
+ }
472
+ }}
473
+ />
474
+ <JsonView.Int
475
+ render={({ children, ...reset }, { type, value, keyName }) => {
476
+ if (type === 'type') {
477
+ return <span />
478
+ }
479
+ }}
480
+ />
481
+ </JsonView>
482
+ )
483
+ }
484
+ ```
485
+
417
486
  Inspector
418
487
 
419
488
  ```tsx mdx:preview
@@ -525,6 +594,52 @@ Passing **as="tagName"** will automatically infer the type.
525
594
  />
526
595
  ```
527
596
 
597
+ Add a click event on the data row
598
+
599
+ ```tsx mdx:preview
600
+ import React from 'react';
601
+ import JsonView from '@uiw/react-json-view';
602
+
603
+ export default function Demo() {
604
+ return (
605
+ <JsonView
606
+ style={{
607
+ '--w-rjv-background-color': '#ffffff',
608
+ }}
609
+ value={{
610
+ name: 'John',
611
+ age: 30,
612
+ hobbies: ['reading', 'coding', 'swimming'],
613
+ address: {
614
+ street: '123 Main St',
615
+ city: 'New York',
616
+ country: {
617
+ name: 'Main ',
618
+ codex: '123'
619
+ }
620
+ }
621
+ }}
622
+ >
623
+ <JsonView.Row
624
+ as="div"
625
+ render={(props, { keyName, value, parentValue }) => {
626
+ return (
627
+ <div
628
+ {...props}
629
+ onClick={() => {
630
+ console.log("keyName", keyName)
631
+ console.log("value", value)
632
+ console.log("parentValue", parentValue)
633
+ }}
634
+ />
635
+ )
636
+ }}
637
+ />
638
+ </JsonView>
639
+ )
640
+ }
641
+ ```
642
+
528
643
  ## Highlight Updates
529
644
 
530
645
  ```tsx mdx:preview
@@ -670,7 +785,7 @@ export default function Demo() {
670
785
 
671
786
  ## Props
672
787
 
673
- Migrate from kkt v1 to v2. The new v2 version has removed the ~~`quotes`~~ and ~~`components`~~ props.
788
+ Migrate from JSON View v1 to v2. The new v2 version has removed the ~~`quotes`~~ and ~~`components`~~ props.
674
789
 
675
790
  ```diff
676
791
  export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
@@ -686,7 +801,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
686
801
  /** Define the root node name. @default undefined */
687
802
  keyName?: string | number;
688
803
  /** Whether sort keys through `String.prototype.localeCompare()` @default false */
689
- objectSortKeys?: boolean | ((a: string, b: string) => number);
804
+ objectSortKeys?: boolean | ((keyA: string, keyB: string, valueA: T, valueB: T) => number);
690
805
  /** Set the indent-width for nested objects @default 15 */
691
806
  indentWidth?: number;
692
807
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
@@ -695,8 +810,12 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
695
810
  displayDataTypes?: boolean;
696
811
  /** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
697
812
  enableClipboard?: boolean;
813
+ /** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
814
+ collapsed?: boolean | number;
698
815
  /** Whether to highlight updates. @default true */
699
816
  highlightUpdates?: boolean;
817
+ /** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
818
+ shortenTextAfterLength?: number;
700
819
  /** Callback function for when a treeNode is expanded or collapsed */
701
820
  onExpand?: (props: {
702
821
  expand: boolean;
@@ -718,6 +837,7 @@ import { Arrow } from './symbol/Arrow';
718
837
  import { Colon } from './symbol/Colon';
719
838
  import { Quote } from './symbol/Quote';
720
839
  import { ValueQuote } from './symbol/ValueQuote';
840
+
721
841
  import { Bigint } from './types/Bigint';
722
842
  import { Date } from './types/Date';
723
843
  import { False } from './types/False';
@@ -731,13 +851,24 @@ import { StringText } from './types/String';
731
851
  import { True } from './types/True';
732
852
  import { Undefined } from './types/Undefined';
733
853
  import { Url } from './types/Url';
854
+
734
855
  import { Copied } from './section/Copied';
735
856
  import { CountInfo } from './section/CountInfo';
736
857
  import { CountInfoExtra } from './section/CountInfoExtra';
737
858
  import { Ellipsis } from './section/Ellipsis';
738
859
  import { KeyName } from './section/KeyName';
860
+ import { Row } from './section/Row';
739
861
 
740
862
  type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
863
+ BraceLeft: typeof BraceLeft;
864
+ BraceRight: typeof BraceRight;
865
+ BracketsLeft: typeof BracketsLeft;
866
+ BracketsRight: typeof BracketsRight;
867
+ Arrow: typeof Arrow;
868
+ Colon: typeof Colon;
869
+ Quote: typeof Quote;
870
+ ValueQuote: typeof ValueQuote;
871
+
741
872
  Bigint: typeof Bigint;
742
873
  Date: typeof Date;
743
874
  False: typeof False;
@@ -751,19 +882,13 @@ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
751
882
  True: typeof True;
752
883
  Undefined: typeof Undefined;
753
884
  Url: typeof Url;
754
- BraceLeft: typeof BraceLeft;
755
- BraceRight: typeof BraceRight;
756
- BracketsLeft: typeof BracketsLeft;
757
- BracketsRight: typeof BracketsRight;
758
- Colon: typeof Colon;
759
- Ellipsis: typeof Ellipsis;
760
- Quote: typeof Quote;
761
- ValueQuote: typeof ValueQuote;
762
- Arrow: typeof Arrow;
885
+
763
886
  Copied: typeof Copied;
764
887
  CountInfo: typeof CountInfo;
765
888
  CountInfoExtra: typeof CountInfoExtra;
889
+ Ellipsis: typeof Ellipsis;
766
890
  KeyName: typeof KeyName;
891
+ Row: typeof Row;
767
892
  };
768
893
  declare const JsonView: JsonViewComponent;
769
894
  export default JsonView;
package/basic.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare module '@uiw/react-json-view/basic' {
2
+ export const basicTheme: import('react').CSSProperties;
3
+ }
@@ -6,5 +6,7 @@ export interface ContainerProps<T extends object> extends React.HTMLAttributes<H
6
6
  level?: number;
7
7
  value?: T;
8
8
  initialValue?: T;
9
+ /** Index of the parent `keyName` */
10
+ keys?: (string | number)[];
9
11
  }
10
12
  export declare const Container: React.ForwardRefExoticComponent<ContainerProps<object> & React.RefAttributes<HTMLDivElement>>;
package/cjs/Container.js CHANGED
@@ -15,8 +15,8 @@ var _NestedOpen = require("./comps/NestedOpen");
15
15
  var _KeyValues = require("./comps/KeyValues");
16
16
  var _ShowTools = require("./store/ShowTools");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
- var _excluded = ["className", "children", "parentValue", "keyid", "level", "value", "initialValue", "keyName"];
19
- var Container = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
18
+ var _excluded = ["className", "children", "parentValue", "keyid", "level", "value", "initialValue", "keys", "keyName"];
19
+ var Container = exports.Container = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
20
20
  var _props$className = props.className,
21
21
  className = _props$className === void 0 ? '' : _props$className,
22
22
  children = props.children,
@@ -26,6 +26,7 @@ var Container = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
26
26
  level = _props$level === void 0 ? 1 : _props$level,
27
27
  value = props.value,
28
28
  initialValue = props.initialValue,
29
+ keys = props.keys,
29
30
  keyName = props.keyName,
30
31
  elmProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
31
32
  var dispatch = (0, _ShowTools.useShowToolsDispatch)();
@@ -47,12 +48,17 @@ var Container = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
47
48
  expandKey: subkeyid,
48
49
  value: value,
49
50
  level: level,
51
+ keys: keys,
52
+ parentValue: parentValue,
50
53
  keyName: keyName,
51
54
  initialValue: initialValue
52
55
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_KeyValues.KeyValues, {
53
56
  expandKey: subkeyid,
54
57
  value: value,
55
- level: level
58
+ level: level,
59
+ keys: keys,
60
+ parentValue: parentValue,
61
+ keyName: keyName
56
62
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_NestedClose.NestedClose, {
57
63
  expandKey: subkeyid,
58
64
  value: value,
@@ -60,5 +66,4 @@ var Container = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
60
66
  })]
61
67
  }));
62
68
  });
63
- exports.Container = Container;
64
69
  Container.displayName = 'JVR.Container';
@@ -18,7 +18,7 @@ function TriangleArrow(props) {
18
18
  height: '1em',
19
19
  width: '1em',
20
20
  userSelect: 'none',
21
- display: 'flex'
21
+ display: 'inline-flex'
22
22
  }, style);
23
23
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
24
24
  viewBox: "0 0 24 24",
@@ -1,13 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { type TagType } from '../store/Types';
3
+ import { type SectionElementResult } from '../store/Section';
3
4
  export type CopiedOption<T extends object> = {
4
5
  value?: T;
5
6
  copied: boolean;
6
7
  setCopied: React.Dispatch<React.SetStateAction<boolean>>;
7
8
  };
8
- export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement> {
9
- value?: T;
10
- keyName: string | number;
9
+ export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement>, SectionElementResult<T> {
11
10
  expandKey: string;
12
11
  }
13
12
  export declare const Copied: {
@@ -13,12 +13,14 @@ var _store = require("../store");
13
13
  var _ShowTools = require("../store/ShowTools");
14
14
  var _Section = require("../store/Section");
15
15
  var _jsxRuntime = require("react/jsx-runtime");
16
- var _excluded = ["keyName", "value", "expandKey"],
16
+ var _excluded = ["keyName", "value", "parentValue", "expandKey", "keys"],
17
17
  _excluded2 = ["as", "render"];
18
- var Copied = function Copied(props) {
18
+ var Copied = exports.Copied = function Copied(props) {
19
19
  var keyName = props.keyName,
20
20
  value = props.value,
21
+ parentValue = props.parentValue,
21
22
  expandKey = props.expandKey,
23
+ keys = props.keys,
22
24
  other = (0, _objectWithoutProperties2["default"])(props, _excluded);
23
25
  var _useStore = (0, _store.useStore)(),
24
26
  onCopied = _useStore.onCopied,
@@ -35,18 +37,23 @@ var Copied = function Copied(props) {
35
37
  if (enableClipboard === false || !isShowTools) return null;
36
38
  var click = function click(event) {
37
39
  event.stopPropagation();
38
- var copyText = JSON.stringify(value, function (key, value) {
39
- if (typeof value === 'bigint') {
40
- return value.toString();
41
- }
42
- return value;
43
- }, 2);
44
- if (typeof value === 'number' && value === Infinity) copyText = 'Infinity';
45
- if (typeof value === 'number' && isNaN(value)) copyText = 'NaN';
46
- if (typeof value === 'bigint') copyText = value + 'n';
40
+ var copyText = '';
41
+ if (typeof value === 'number' && value === Infinity) {
42
+ copyText = 'Infinity';
43
+ } else if (typeof value === 'number' && isNaN(value)) {
44
+ copyText = 'NaN';
45
+ } else if (typeof value === 'bigint') {
46
+ copyText = value + 'n';
47
+ } else if (value instanceof Date) {
48
+ copyText = value.toLocaleString();
49
+ } else {
50
+ copyText = JSON.stringify(value, function (_, v) {
51
+ return typeof v === 'bigint' ? v + 'n' : v;
52
+ }, 2);
53
+ }
54
+ onCopied && onCopied(copyText, value);
55
+ setCopied(true);
47
56
  navigator.clipboard.writeText(copyText).then(function () {
48
- onCopied && onCopied(copyText, value);
49
- setCopied(true);
50
57
  var timer = setTimeout(function () {
51
58
  setCopied(false);
52
59
  clearTimeout(timer);
@@ -54,19 +61,26 @@ var Copied = function Copied(props) {
54
61
  })["catch"](function (error) {});
55
62
  };
56
63
  var svgProps = {
64
+ style: {
65
+ display: 'inline-flex'
66
+ },
57
67
  fill: copied ? 'var(--w-rjv-copied-success-color, #28a745)' : 'var(--w-rjv-copied-color, currentColor)',
58
68
  onClick: click
59
69
  };
60
70
  var as = Comp.as,
61
71
  render = Comp.render,
62
72
  reset = (0, _objectWithoutProperties2["default"])(Comp, _excluded2);
63
- var elmProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), other), svgProps);
73
+ var elmProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), other), svgProps), {}, {
74
+ style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset.style), other.style), svgProps.style)
75
+ });
64
76
  var isRender = render && typeof render === 'function';
65
77
  var child = isRender && render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, elmProps), {}, {
66
78
  'data-copied': copied
67
79
  }), {
68
80
  value: value,
69
- keyName: keyName
81
+ keyName: keyName,
82
+ keys: keys,
83
+ parentValue: parentValue
70
84
  });
71
85
  if (child) return child;
72
86
  if (copied) {
@@ -86,5 +100,4 @@ var Copied = function Copied(props) {
86
100
  })
87
101
  }));
88
102
  };
89
- exports.Copied = Copied;
90
103
  Copied.displayName = 'JVR.Copied';
@@ -1,7 +1,5 @@
1
- interface KeyValuesProps<T extends object> {
2
- keyName?: string | number;
3
- value?: T;
4
- parentValue?: T;
1
+ import { type SectionElementResult } from '../store/Section';
2
+ interface KeyValuesProps<T extends object> extends SectionElementResult<T> {
5
3
  expandKey?: string;
6
4
  level: number;
7
5
  }
@@ -8,23 +8,28 @@ exports.KeyValuesItem = exports.KeyValues = exports.KayName = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
12
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
13
  var _react = require("react");
13
14
  var _store = require("../store");
14
15
  var _Expands = require("../store/Expands");
15
16
  var _ShowTools = require("../store/ShowTools");
16
17
  var _Value = require("./Value");
17
- var _Key = require("./Key");
18
+ var _KeyName = require("../section/KeyName");
19
+ var _Row = require("../section/Row");
18
20
  var _Container = require("../Container");
19
- var _Symbols = require("./ReRender/Symbols");
21
+ var _symbol = require("../symbol");
20
22
  var _useHighlight = require("../utils/useHighlight");
23
+ var _Copied = require("../comps/Copied");
21
24
  var _jsxRuntime = require("react/jsx-runtime");
22
- var KeyValues = function KeyValues(props) {
25
+ var KeyValues = exports.KeyValues = function KeyValues(props) {
23
26
  var _expands$expandKey;
24
27
  var value = props.value,
25
28
  _props$expandKey = props.expandKey,
26
29
  expandKey = _props$expandKey === void 0 ? '' : _props$expandKey,
27
- level = props.level;
30
+ level = props.level,
31
+ _props$keys = props.keys,
32
+ keys = _props$keys === void 0 ? [] : _props$keys;
28
33
  var expands = (0, _Expands.useExpandsStore)();
29
34
  var _useStore = (0, _store.useStore)(),
30
35
  objectSortKeys = _useStore.objectSortKeys,
@@ -47,11 +52,13 @@ var KeyValues = function KeyValues(props) {
47
52
  b = _ref4[0];
48
53
  return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
49
54
  }) : entries.sort(function (_ref5, _ref6) {
50
- var _ref7 = (0, _slicedToArray2["default"])(_ref5, 1),
51
- a = _ref7[0];
52
- var _ref8 = (0, _slicedToArray2["default"])(_ref6, 1),
53
- b = _ref8[0];
54
- return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
55
+ var _ref7 = (0, _slicedToArray2["default"])(_ref5, 2),
56
+ a = _ref7[0],
57
+ valA = _ref7[1];
58
+ var _ref8 = (0, _slicedToArray2["default"])(_ref6, 2),
59
+ b = _ref8[0],
60
+ valB = _ref8[1];
61
+ return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b, valA, valB) : 0;
55
62
  });
56
63
  }
57
64
  var style = {
@@ -69,16 +76,18 @@ var KeyValues = function KeyValues(props) {
69
76
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(KeyValuesItem, {
70
77
  parentValue: value,
71
78
  keyName: key,
79
+ keys: [].concat((0, _toConsumableArray2["default"])(keys), [key]),
72
80
  value: val,
73
81
  level: level
74
82
  }, idx);
75
83
  })
76
84
  });
77
85
  };
78
- exports.KeyValues = KeyValues;
79
86
  KeyValues.displayName = 'JVR.KeyValues';
80
- var KayName = function KayName(props) {
87
+ var KayName = exports.KayName = function KayName(props) {
81
88
  var keyName = props.keyName,
89
+ parentValue = props.parentValue,
90
+ keys = props.keys,
82
91
  value = props.value;
83
92
  var _useStore2 = (0, _store.useStore)(),
84
93
  highlightUpdates = _useStore2.highlightUpdates;
@@ -92,26 +101,31 @@ var KayName = function KayName(props) {
92
101
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
93
102
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
94
103
  ref: highlightContainer,
95
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Symbols.Quote, {
96
- isNumber: isNumber
97
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Key.Key, {
104
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_symbol.Quote, {
105
+ isNumber: isNumber,
106
+ "data-placement": "left"
107
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_KeyName.KeyNameComp, {
98
108
  keyName: keyName,
99
109
  value: value,
110
+ keys: keys,
111
+ parentValue: parentValue,
100
112
  children: keyName
101
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Symbols.Quote, {
102
- isNumber: isNumber
113
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_symbol.Quote, {
114
+ isNumber: isNumber,
115
+ "data-placement": "right"
103
116
  })]
104
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Symbols.Colon, {})]
117
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_symbol.Colon, {})]
105
118
  });
106
119
  };
107
- exports.KayName = KayName;
108
120
  KayName.displayName = 'JVR.KayName';
109
- var KeyValuesItem = function KeyValuesItem(props) {
121
+ var KeyValuesItem = exports.KeyValuesItem = function KeyValuesItem(props) {
110
122
  var keyName = props.keyName,
111
123
  value = props.value,
112
124
  parentValue = props.parentValue,
113
125
  _props$level = props.level,
114
- level = _props$level === void 0 ? 0 : _props$level;
126
+ level = _props$level === void 0 ? 0 : _props$level,
127
+ _props$keys2 = props.keys,
128
+ keys = _props$keys2 === void 0 ? [] : _props$keys2;
115
129
  var dispatch = (0, _ShowTools.useShowToolsDispatch)();
116
130
  var subkeyid = (0, _react.useId)();
117
131
  var isMyArray = Array.isArray(value);
@@ -128,6 +142,7 @@ var KeyValuesItem = function KeyValuesItem(props) {
128
142
  value: myValue,
129
143
  parentValue: parentValue,
130
144
  initialValue: value,
145
+ keys: keys,
131
146
  level: level + 1
132
147
  });
133
148
  }
@@ -139,18 +154,28 @@ var KeyValuesItem = function KeyValuesItem(props) {
139
154
  return dispatch((0, _defineProperty2["default"])({}, subkeyid, false));
140
155
  }
141
156
  };
142
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
143
- className: "w-rjv-line"
157
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Row.RowComp, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
158
+ className: "w-rjv-line",
159
+ value: value,
160
+ keyName: keyName,
161
+ keys: keys,
162
+ parentValue: parentValue
144
163
  }, reset), {}, {
145
164
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(KayName, {
146
165
  keyName: keyName,
147
- value: value
166
+ value: value,
167
+ keys: keys,
168
+ parentValue: parentValue
148
169
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Value.Value, {
170
+ keyName: keyName,
171
+ value: value
172
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Copied.Copied, {
149
173
  keyName: keyName,
150
174
  value: value,
175
+ keys: keys,
176
+ parentValue: parentValue,
151
177
  expandKey: subkeyid
152
178
  })]
153
179
  }));
154
180
  };
155
- exports.KeyValuesItem = KeyValuesItem;
156
181
  KeyValuesItem.displayName = 'JVR.KeyValuesItem';