@uiw/react-json-view 2.0.0-alpha.4 → 2.0.0-alpha.41

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 (227) hide show
  1. package/README.md +280 -39
  2. package/basic.d.ts +4 -0
  3. package/cjs/Container.d.ts +2 -0
  4. package/cjs/Container.js +15 -6
  5. package/cjs/arrow/TriangleArrow.js +1 -1
  6. package/cjs/comps/Copied.d.ts +3 -4
  7. package/cjs/comps/Copied.js +61 -18
  8. package/cjs/comps/KeyValues.d.ts +2 -4
  9. package/cjs/comps/KeyValues.js +73 -28
  10. package/cjs/comps/NestedClose.d.ts +2 -2
  11. package/cjs/comps/NestedClose.js +42 -12
  12. package/cjs/comps/NestedOpen.d.ts +2 -3
  13. package/cjs/comps/NestedOpen.js +42 -20
  14. package/cjs/comps/Value.d.ts +2 -2
  15. package/cjs/comps/Value.js +5 -7
  16. package/cjs/comps/useIdCompat.d.ts +1 -0
  17. package/cjs/comps/useIdCompat.js +14 -0
  18. package/cjs/editor/KeyName.d.ts +2 -0
  19. package/cjs/editor/KeyName.js +82 -0
  20. package/cjs/editor/index.d.ts +18 -0
  21. package/cjs/editor/index.js +44 -0
  22. package/cjs/editor/store.d.ts +27 -0
  23. package/cjs/editor/store.js +23 -0
  24. package/cjs/index.d.ts +26 -4
  25. package/cjs/index.js +17 -7
  26. package/cjs/section/Copied.d.ts +4 -1
  27. package/cjs/section/Copied.js +1 -2
  28. package/cjs/section/CountInfo.d.ts +1 -2
  29. package/cjs/section/CountInfo.js +3 -5
  30. package/cjs/section/CountInfoExtra.d.ts +1 -2
  31. package/cjs/section/CountInfoExtra.js +2 -4
  32. package/cjs/section/Ellipsis.d.ts +0 -1
  33. package/cjs/section/Ellipsis.js +4 -5
  34. package/cjs/section/KeyName.d.ts +7 -6
  35. package/cjs/section/KeyName.js +8 -6
  36. package/cjs/section/Row.d.ts +13 -0
  37. package/cjs/section/Row.js +51 -0
  38. package/cjs/store/Expands.js +2 -4
  39. package/cjs/store/Section.d.ts +12 -6
  40. package/cjs/store/Section.js +6 -4
  41. package/cjs/store/ShowTools.js +2 -4
  42. package/cjs/store/Symbols.d.ts +10 -3
  43. package/cjs/store/Symbols.js +2 -4
  44. package/cjs/store/Types.d.ts +30 -25
  45. package/cjs/store/Types.js +8 -8
  46. package/cjs/store.d.ts +12 -6
  47. package/cjs/store.js +5 -10
  48. package/cjs/symbol/Arrow.d.ts +1 -1
  49. package/cjs/symbol/Arrow.js +1 -2
  50. package/cjs/symbol/BraceLeft.d.ts +1 -1
  51. package/cjs/symbol/BraceLeft.js +1 -2
  52. package/cjs/symbol/BraceRight.d.ts +1 -1
  53. package/cjs/symbol/BraceRight.js +1 -2
  54. package/cjs/symbol/BracketsLeft.d.ts +1 -1
  55. package/cjs/symbol/BracketsLeft.js +1 -2
  56. package/cjs/symbol/BracketsRight.d.ts +1 -1
  57. package/cjs/symbol/BracketsRight.js +1 -2
  58. package/cjs/symbol/Colon.d.ts +1 -1
  59. package/cjs/symbol/Colon.js +1 -2
  60. package/cjs/symbol/Quote.d.ts +1 -1
  61. package/cjs/symbol/Quote.js +1 -2
  62. package/cjs/symbol/ValueQuote.d.ts +1 -1
  63. package/cjs/symbol/ValueQuote.js +1 -2
  64. package/cjs/symbol/index.d.ts +12 -17
  65. package/cjs/symbol/index.js +82 -30
  66. package/cjs/theme/basic.d.ts +2 -2
  67. package/cjs/theme/basic.js +4 -3
  68. package/cjs/theme/dark.d.ts +2 -2
  69. package/cjs/theme/dark.js +2 -3
  70. package/cjs/theme/github.dark.d.ts +2 -2
  71. package/cjs/theme/github.dark.js +2 -3
  72. package/cjs/theme/github.light.d.ts +2 -2
  73. package/cjs/theme/github.light.js +2 -3
  74. package/cjs/theme/gruvbox.d.ts +2 -2
  75. package/cjs/theme/gruvbox.js +2 -3
  76. package/cjs/theme/light.d.ts +2 -2
  77. package/cjs/theme/light.js +2 -3
  78. package/cjs/theme/monokai.d.ts +2 -2
  79. package/cjs/theme/monokai.js +2 -3
  80. package/cjs/theme/nord.d.ts +2 -2
  81. package/cjs/theme/nord.js +2 -3
  82. package/cjs/theme/vscode.d.ts +2 -2
  83. package/cjs/theme/vscode.js +2 -3
  84. package/cjs/types/Bigint.d.ts +1 -1
  85. package/cjs/types/Bigint.js +1 -2
  86. package/cjs/types/Date.d.ts +1 -1
  87. package/cjs/types/Date.js +1 -2
  88. package/cjs/types/False.d.ts +1 -1
  89. package/cjs/types/False.js +1 -2
  90. package/cjs/types/Float.d.ts +1 -1
  91. package/cjs/types/Float.js +1 -2
  92. package/cjs/types/Int.d.ts +1 -1
  93. package/cjs/types/Int.js +1 -2
  94. package/cjs/types/Map.d.ts +1 -1
  95. package/cjs/types/Map.js +1 -2
  96. package/cjs/types/Nan.d.ts +1 -1
  97. package/cjs/types/Nan.js +1 -2
  98. package/cjs/types/Null.d.ts +1 -1
  99. package/cjs/types/Null.js +1 -2
  100. package/cjs/types/Set.d.ts +1 -1
  101. package/cjs/types/Set.js +1 -2
  102. package/cjs/types/String.d.ts +1 -1
  103. package/cjs/types/String.js +1 -2
  104. package/cjs/types/True.d.ts +1 -1
  105. package/cjs/types/True.js +1 -2
  106. package/cjs/types/Undefined.d.ts +1 -1
  107. package/cjs/types/Undefined.js +1 -2
  108. package/cjs/types/Url.d.ts +1 -1
  109. package/cjs/types/Url.js +1 -2
  110. package/cjs/types/index.d.ts +5 -2
  111. package/cjs/types/index.js +174 -166
  112. package/cjs/utils/useHighlight.d.ts +0 -1
  113. package/cjs/utils/useRender.d.ts +1 -1
  114. package/dark.d.ts +2 -1
  115. package/editor.d.ts +22 -20
  116. package/esm/Container.d.ts +2 -0
  117. package/esm/Container.js +21 -11
  118. package/esm/arrow/TriangleArrow.js +1 -1
  119. package/esm/comps/Copied.d.ts +3 -4
  120. package/esm/comps/Copied.js +61 -19
  121. package/esm/comps/KeyValues.d.ts +2 -4
  122. package/esm/comps/KeyValues.js +71 -27
  123. package/esm/comps/NestedClose.d.ts +2 -2
  124. package/esm/comps/NestedClose.js +40 -11
  125. package/esm/comps/NestedOpen.d.ts +2 -3
  126. package/esm/comps/NestedOpen.js +47 -26
  127. package/esm/comps/Value.d.ts +2 -2
  128. package/esm/comps/Value.js +3 -3
  129. package/esm/comps/useIdCompat.d.ts +1 -0
  130. package/esm/comps/useIdCompat.js +8 -0
  131. package/esm/editor/KeyName.d.ts +2 -0
  132. package/esm/editor/KeyName.js +77 -0
  133. package/esm/editor/index.d.ts +18 -0
  134. package/esm/editor/index.js +33 -0
  135. package/esm/editor/store.d.ts +27 -0
  136. package/esm/editor/store.js +13 -0
  137. package/esm/index.d.ts +26 -4
  138. package/esm/index.js +50 -41
  139. package/esm/section/Copied.d.ts +4 -1
  140. package/esm/section/Copied.js +2 -2
  141. package/esm/section/CountInfo.d.ts +1 -2
  142. package/esm/section/CountInfo.js +4 -4
  143. package/esm/section/CountInfoExtra.d.ts +1 -2
  144. package/esm/section/CountInfoExtra.js +2 -2
  145. package/esm/section/Ellipsis.d.ts +0 -1
  146. package/esm/section/Ellipsis.js +3 -3
  147. package/esm/section/KeyName.d.ts +7 -6
  148. package/esm/section/KeyName.js +8 -4
  149. package/esm/section/Row.d.ts +13 -0
  150. package/esm/section/Row.js +47 -0
  151. package/esm/store/Section.d.ts +12 -6
  152. package/esm/store/Section.js +4 -0
  153. package/esm/store/Symbols.d.ts +10 -3
  154. package/esm/store/Symbols.js +1 -1
  155. package/esm/store/Types.d.ts +30 -25
  156. package/esm/store/Types.js +6 -4
  157. package/esm/store.d.ts +12 -6
  158. package/esm/store.js +5 -5
  159. package/esm/symbol/Arrow.d.ts +1 -1
  160. package/esm/symbol/Arrow.js +2 -2
  161. package/esm/symbol/BraceLeft.d.ts +1 -1
  162. package/esm/symbol/BraceLeft.js +2 -2
  163. package/esm/symbol/BraceRight.d.ts +1 -1
  164. package/esm/symbol/BraceRight.js +2 -2
  165. package/esm/symbol/BracketsLeft.d.ts +1 -1
  166. package/esm/symbol/BracketsLeft.js +2 -2
  167. package/esm/symbol/BracketsRight.d.ts +1 -1
  168. package/esm/symbol/BracketsRight.js +2 -2
  169. package/esm/symbol/Colon.d.ts +1 -1
  170. package/esm/symbol/Colon.js +2 -2
  171. package/esm/symbol/Quote.d.ts +1 -1
  172. package/esm/symbol/Quote.js +2 -2
  173. package/esm/symbol/ValueQuote.d.ts +1 -1
  174. package/esm/symbol/ValueQuote.js +2 -2
  175. package/esm/symbol/index.d.ts +12 -17
  176. package/esm/symbol/index.js +85 -25
  177. package/esm/theme/basic.d.ts +2 -2
  178. package/esm/theme/basic.js +2 -0
  179. package/esm/theme/dark.d.ts +2 -2
  180. package/esm/theme/github.dark.d.ts +2 -2
  181. package/esm/theme/github.light.d.ts +2 -2
  182. package/esm/theme/gruvbox.d.ts +2 -2
  183. package/esm/theme/light.d.ts +2 -2
  184. package/esm/theme/monokai.d.ts +2 -2
  185. package/esm/theme/nord.d.ts +2 -2
  186. package/esm/theme/vscode.d.ts +2 -2
  187. package/esm/types/Bigint.d.ts +1 -1
  188. package/esm/types/Bigint.js +2 -2
  189. package/esm/types/Date.d.ts +1 -1
  190. package/esm/types/Date.js +2 -2
  191. package/esm/types/False.d.ts +1 -1
  192. package/esm/types/False.js +2 -2
  193. package/esm/types/Float.d.ts +1 -1
  194. package/esm/types/Float.js +2 -2
  195. package/esm/types/Int.d.ts +1 -1
  196. package/esm/types/Int.js +2 -2
  197. package/esm/types/Map.d.ts +1 -1
  198. package/esm/types/Map.js +2 -2
  199. package/esm/types/Nan.d.ts +1 -1
  200. package/esm/types/Nan.js +2 -2
  201. package/esm/types/Null.d.ts +1 -1
  202. package/esm/types/Null.js +2 -2
  203. package/esm/types/Set.d.ts +1 -1
  204. package/esm/types/Set.js +2 -2
  205. package/esm/types/String.d.ts +1 -1
  206. package/esm/types/String.js +2 -2
  207. package/esm/types/True.d.ts +1 -1
  208. package/esm/types/True.js +2 -2
  209. package/esm/types/Undefined.d.ts +1 -1
  210. package/esm/types/Undefined.js +2 -2
  211. package/esm/types/Url.d.ts +1 -1
  212. package/esm/types/Url.js +2 -2
  213. package/esm/types/index.d.ts +5 -2
  214. package/esm/types/index.js +148 -131
  215. package/esm/utils/useHighlight.d.ts +0 -1
  216. package/esm/utils/useRender.d.ts +1 -1
  217. package/esm/utils/useRender.js +3 -3
  218. package/githubDark.d.ts +4 -0
  219. package/githubLight.d.ts +4 -0
  220. package/gruvbox.d.ts +4 -0
  221. package/light.d.ts +2 -1
  222. package/monokai.d.ts +4 -0
  223. package/nord.d.ts +4 -0
  224. package/package.json +12 -6
  225. package/triangle-arrow.d.ts +2 -2
  226. package/triangle-solid-arrow.d.ts +2 -2
  227. package/vscode.d.ts +4 -0
@@ -1,34 +1,44 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import { KayName } from './KeyValues';
3
- import { useExpandsStore, useExpandsDispatch } from '../store/Expands';
4
- import { useStore } from '../store';
5
- import { Copied } from './Copied';
6
- import { CountInfoExtraComps } from '../section/CountInfoExtra';
7
- import { CountInfoComp } from '../section/CountInfo';
8
- import { Arrow, BracketsOpen, BracketsClose } from '../symbol';
9
- import { EllipsisComp } from '../section/Ellipsis';
10
- import { SetComp, MapComp } from '../types';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { KayName } from "./KeyValues.js";
3
+ import { useExpandsStore, useExpandsDispatch } from "../store/Expands.js";
4
+ import { useStore } from "../store.js";
5
+ import { Copied } from "./Copied.js";
6
+ import { CountInfoExtraComps } from "../section/CountInfoExtra.js";
7
+ import { CountInfoComp } from "../section/CountInfo.js";
8
+ import { Arrow, BracketsOpen, BracketsClose } from "../symbol/index.js";
9
+ import { EllipsisComp } from "../section/Ellipsis.js";
10
+ import { SetComp, MapComp } from "../types/index.js";
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
12
  export var NestedOpen = props => {
14
13
  var _expands$expandKey;
15
14
  var {
16
15
  keyName,
17
16
  expandKey,
17
+ keys = [],
18
18
  initialValue,
19
19
  value,
20
+ parentValue,
20
21
  level
21
22
  } = props;
22
23
  var expands = useExpandsStore();
23
24
  var dispatchExpands = useExpandsDispatch();
24
25
  var {
25
26
  onExpand,
26
- collapsed
27
+ collapsed,
28
+ shouldExpandNodeInitially
27
29
  } = useStore();
28
- var isArray = Array.isArray(value);
29
- var isMySet = value instanceof Set;
30
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
31
- var isObject = typeof value === 'object';
30
+ var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
31
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
32
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
33
+ value,
34
+ keys,
35
+ level,
36
+ keyName,
37
+ parentValue
38
+ });
39
+ if (expands[expandKey] === undefined && shouldExpandNodeInitially) {
40
+ isExpanded = !shouldExpand;
41
+ }
32
42
  var click = () => {
33
43
  var opt = {
34
44
  expand: !isExpanded,
@@ -50,6 +60,9 @@ export var NestedOpen = props => {
50
60
  transition: 'all 0.3s'
51
61
  };
52
62
  var len = Object.keys(value).length;
63
+ var isObject = typeof value === 'object';
64
+ var isArray = Array.isArray(value);
65
+ var isMySet = value instanceof Set;
53
66
  var showArrow = len !== 0 && (isArray || isMySet || isObject);
54
67
  var reset = {
55
68
  style
@@ -57,26 +70,32 @@ export var NestedOpen = props => {
57
70
  if (showArrow) {
58
71
  reset.onClick = click;
59
72
  }
73
+ var compProps = {
74
+ keyName,
75
+ value,
76
+ keys,
77
+ parentValue
78
+ };
60
79
  return /*#__PURE__*/_jsxs("span", _extends({}, reset, {
61
- children: [showArrow && /*#__PURE__*/_jsx(Arrow, {
80
+ children: [showArrow && /*#__PURE__*/_jsx(Arrow, _extends({
62
81
  style: arrowStyle,
63
82
  expandKey: expandKey
64
- }), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, {
83
+ }, compProps)), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, _extends({}, compProps)), /*#__PURE__*/_jsx(SetComp, {
84
+ value: initialValue,
65
85
  keyName: keyName
66
- }), /*#__PURE__*/_jsx(SetComp, {
67
- value: initialValue
68
86
  }), /*#__PURE__*/_jsx(MapComp, {
69
- value: initialValue
70
- }), /*#__PURE__*/_jsx(BracketsOpen, {
87
+ value: initialValue,
88
+ keyName: keyName
89
+ }), /*#__PURE__*/_jsx(BracketsOpen, _extends({
71
90
  isBrackets: isArray || isMySet
72
- }), /*#__PURE__*/_jsx(EllipsisComp, {
91
+ }, compProps)), /*#__PURE__*/_jsx(EllipsisComp, {
73
92
  keyName: keyName,
74
93
  value: value,
75
94
  isExpanded: isExpanded
76
- }), /*#__PURE__*/_jsx(BracketsClose, {
95
+ }), /*#__PURE__*/_jsx(BracketsClose, _extends({
77
96
  isVisiable: isExpanded || !showArrow,
78
97
  isBrackets: isArray || isMySet
79
- }), /*#__PURE__*/_jsx(CountInfoComp, {
98
+ }, compProps)), /*#__PURE__*/_jsx(CountInfoComp, {
80
99
  value: value,
81
100
  keyName: keyName
82
101
  }), /*#__PURE__*/_jsx(CountInfoExtraComps, {
@@ -85,7 +104,9 @@ export var NestedOpen = props => {
85
104
  }), /*#__PURE__*/_jsx(Copied, {
86
105
  keyName: keyName,
87
106
  value: value,
88
- expandKey: expandKey
107
+ expandKey: expandKey,
108
+ parentValue: parentValue,
109
+ keys: keys
89
110
  })]
90
111
  }));
91
112
  };
@@ -1,8 +1,8 @@
1
1
  export declare const isFloat: (n: number) => boolean;
2
2
  interface ValueProps {
3
- value?: unknown;
3
+ value: unknown;
4
4
  keyName: string | number;
5
- expandKey: string;
5
+ keys?: (string | number)[];
6
6
  }
7
7
  export declare const Value: {
8
8
  (props: ValueProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,16 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import { TypeString, TypeTrue, TypeNull, TypeFalse, TypeFloat, TypeBigint, TypeInt, TypeDate, TypeUndefined, TypeNan, TypeUrl } from '../types';
2
+ import { TypeString, TypeTrue, TypeNull, TypeFalse, TypeFloat, TypeBigint, TypeInt, TypeDate, TypeUndefined, TypeNan, TypeUrl } from "../types/index.js";
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  export var isFloat = n => Number(n) === n && n % 1 !== 0 || isNaN(n);
5
5
  export var Value = props => {
6
6
  var {
7
7
  value,
8
8
  keyName,
9
- expandKey
9
+ keys
10
10
  } = props;
11
11
  var reset = {
12
12
  keyName,
13
- expandKey
13
+ keys
14
14
  };
15
15
  if (value instanceof URL) {
16
16
  return /*#__PURE__*/_jsx(TypeUrl, _extends({}, reset, {
@@ -0,0 +1 @@
1
+ export declare function useIdCompat(): string;
@@ -0,0 +1,8 @@
1
+ import { useRef } from 'react';
2
+ export function useIdCompat() {
3
+ var idRef = useRef(null);
4
+ if (idRef.current === null) {
5
+ idRef.current = 'custom-id-' + Math.random().toString(36).substr(2, 9);
6
+ }
7
+ return idRef.current;
8
+ }
@@ -0,0 +1,2 @@
1
+ import { type SectionElementProps } from '../store/Section';
2
+ export declare const KeyNameRender: SectionElementProps['render'];
@@ -0,0 +1,77 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["children"],
4
+ _excluded2 = ["value", "parentValue", "keyName"];
5
+ import { useRef, useState } from 'react';
6
+ import { useStore } from "./store.js";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export var KeyNameRender = (_ref, _ref2) => {
9
+ var {
10
+ children
11
+ } = _ref,
12
+ reset = _objectWithoutPropertiesLoose(_ref, _excluded);
13
+ var {
14
+ value,
15
+ parentValue,
16
+ keyName
17
+ } = _ref2;
18
+ if (typeof children === 'number') {
19
+ return /*#__PURE__*/_jsx("span", _extends({}, reset, {
20
+ children: children
21
+ }));
22
+ }
23
+ return /*#__PURE__*/_jsx(Child, _extends({}, reset, {
24
+ value: value,
25
+ parentValue: parentValue,
26
+ keyName: keyName,
27
+ children: children
28
+ }));
29
+ };
30
+ var Child = props => {
31
+ var {
32
+ value,
33
+ keyName
34
+ } = props,
35
+ reset = _objectWithoutPropertiesLoose(props, _excluded2);
36
+ var $dom = useRef(null);
37
+ var [currentValue, setCurrentValue] = useState(props.children);
38
+ var {
39
+ onEdit
40
+ } = useStore();
41
+ var onKeyDown = evn => {
42
+ if (evn.key === 'Enter') {
43
+ var _$dom$current;
44
+ (_$dom$current = $dom.current) == null || _$dom$current.setAttribute('contentEditable', 'false');
45
+ }
46
+ };
47
+ var onClick = evn => {
48
+ var _$dom$current2, _$dom$current3;
49
+ evn.stopPropagation();
50
+ (_$dom$current2 = $dom.current) == null || _$dom$current2.setAttribute('contentEditable', 'true');
51
+ (_$dom$current3 = $dom.current) == null || _$dom$current3.focus();
52
+ };
53
+ var onBlur = evn => {
54
+ var _$dom$current4;
55
+ (_$dom$current4 = $dom.current) == null || _$dom$current4.setAttribute('contentEditable', 'false');
56
+ var callback = onEdit && onEdit({
57
+ value: evn.target.textContent,
58
+ oldValue: value,
59
+ keyName
60
+ });
61
+ if (callback) {
62
+ setCurrentValue(evn.target.textContent);
63
+ }
64
+ };
65
+ var spanProps = _extends({}, reset, {
66
+ onKeyDown,
67
+ onClick,
68
+ onBlur,
69
+ spellCheck: false,
70
+ contentEditable: 'false',
71
+ suppressContentEditableWarning: true,
72
+ children: currentValue
73
+ });
74
+ return /*#__PURE__*/_jsx("span", _extends({}, spanProps, {
75
+ ref: $dom
76
+ }));
77
+ };
@@ -0,0 +1,18 @@
1
+ import { type JsonViewProps } from '../';
2
+ export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
3
+ /**
4
+ * When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
5
+ * @returns {boolean} Returning false from onEdit will prevent the change from being made.
6
+ */
7
+ onEdit?: (option: {
8
+ value: unknown;
9
+ oldValue: unknown;
10
+ keyName?: string | number;
11
+ parentName?: string | number;
12
+ type?: 'value' | 'key';
13
+ }) => boolean;
14
+ /** Whether enable edit feature. @default true */
15
+ editable?: boolean;
16
+ }
17
+ declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
18
+ export default JsonViewEditor;
@@ -0,0 +1,33 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["children", "onEdit", "editable"];
4
+ import { forwardRef } from 'react';
5
+ import JsonView from "../index.js";
6
+ import { KeyNameRender } from "./KeyName.js";
7
+ import { Context, Dispatch, useStoreReducer } from "./store.js";
8
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
+ var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
10
+ var {
11
+ children,
12
+ onEdit,
13
+ editable = true
14
+ } = props,
15
+ reset = _objectWithoutPropertiesLoose(props, _excluded);
16
+ var [state, dispatch] = useStoreReducer({
17
+ onEdit
18
+ });
19
+ return /*#__PURE__*/_jsx(Context.Provider, {
20
+ value: state,
21
+ children: /*#__PURE__*/_jsx(Dispatch.Provider, {
22
+ value: dispatch,
23
+ children: /*#__PURE__*/_jsxs(JsonView, _extends({}, reset, {
24
+ shortenTextAfterLength: 0,
25
+ ref: ref,
26
+ children: [editable && /*#__PURE__*/_jsx(JsonView.KeyName, {
27
+ render: KeyNameRender
28
+ }), children]
29
+ }))
30
+ })
31
+ });
32
+ });
33
+ export default JsonViewEditor;
@@ -0,0 +1,27 @@
1
+ type InitialState = {
2
+ /**
3
+ * When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
4
+ * @returns {boolean} Returning false from onEdit will prevent the change from being made.
5
+ */
6
+ onEdit?: (option: {
7
+ value: unknown;
8
+ oldValue: unknown;
9
+ keyName?: string | number;
10
+ parentName?: string | number;
11
+ type?: 'value' | 'key';
12
+ }) => boolean;
13
+ };
14
+ type Dispatch = React.Dispatch<InitialState>;
15
+ export declare const Context: import("react").Context<InitialState>;
16
+ export declare const Dispatch: import("react").Context<Dispatch>;
17
+ export declare const useStore: () => InitialState;
18
+ export declare function useStoreReducer(initialState: InitialState): [{
19
+ onEdit?: (option: {
20
+ value: unknown;
21
+ oldValue: unknown;
22
+ keyName?: string | number;
23
+ parentName?: string | number;
24
+ type?: "value" | "key";
25
+ }) => boolean;
26
+ }, import("react").Dispatch<InitialState>];
27
+ export {};
@@ -0,0 +1,13 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import { createContext, useContext, useReducer } from 'react';
3
+ var initialState = {};
4
+ export var Context = /*#__PURE__*/createContext(initialState);
5
+ var reducer = (state, action) => _extends({}, state, action);
6
+ export var Dispatch = /*#__PURE__*/createContext(() => {});
7
+ Dispatch.displayName = 'JVR.Editor.Dispatch';
8
+ export var useStore = () => {
9
+ return useContext(Context);
10
+ };
11
+ export function useStoreReducer(initialState) {
12
+ return useReducer(reducer, initialState);
13
+ }
package/esm/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { BraceLeft } from './symbol/BraceLeft';
3
2
  import { BraceRight } from './symbol/BraceRight';
4
3
  import { BracketsLeft } from './symbol/BracketsLeft';
@@ -25,12 +24,20 @@ import { CountInfo } from './section/CountInfo';
25
24
  import { CountInfoExtra } from './section/CountInfoExtra';
26
25
  import { Ellipsis } from './section/Ellipsis';
27
26
  import { KeyName } from './section/KeyName';
27
+ import { Row } from './section/Row';
28
28
  export * from './store';
29
29
  export * from './store/Expands';
30
30
  export * from './store/ShowTools';
31
31
  export * from './store/Symbols';
32
32
  export * from './store/Types';
33
- export * from './symbol';
33
+ export * from './symbol/';
34
+ export type ShouldExpandNodeInitially<T extends object> = (isExpanded: boolean, props: {
35
+ keyName?: string | number;
36
+ value?: T;
37
+ parentValue?: T;
38
+ keys: (number | string)[];
39
+ level: number;
40
+ }) => boolean;
34
41
  export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
35
42
  /** This property contains your input JSON */
36
43
  value?: T;
@@ -46,12 +53,24 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
46
53
  displayDataTypes?: boolean;
47
54
  /** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
48
55
  enableClipboard?: boolean;
49
- /** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
56
+ /**
57
+ * When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a specific depth. @default false
58
+ * collapsed takes precedence over shouldExpandNodeInitially.
59
+ * @see {@link shouldExpandNodeInitially} for more details on how the initial expansion works.
60
+ */
50
61
  collapsed?: boolean | number;
62
+ /**
63
+ * Determines whether the node should be expanded on the first render, or you can use collapsed to control the level of expansion (by default, the root is expanded).
64
+ * If both collapsed and shouldExpandNodeInitially are set, the value of collapsed takes precedence.
65
+ * @see {@link collapsed} for more details on how this works.
66
+ */
67
+ shouldExpandNodeInitially?: ShouldExpandNodeInitially<T>;
51
68
  /** Whether to highlight updates. @default true */
52
69
  highlightUpdates?: boolean;
53
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
70
+ /** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
54
71
  shortenTextAfterLength?: number;
72
+ /** When the text exceeds the length, `...` will be displayed. Currently, this `...` can be customized. @default "..." */
73
+ stringEllipsis?: number;
55
74
  /** Callback function for when a treeNode is expanded or collapsed */
56
75
  onExpand?: (props: {
57
76
  expand: boolean;
@@ -61,6 +80,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
61
80
  }) => void;
62
81
  /** Fires event when you copy */
63
82
  onCopied?: (text: string, value?: T) => void;
83
+ /** Transform the text before copying to clipboard */
84
+ beforeCopy?: (copyText: string, keyName?: string | number, value?: T, parentValue?: T, expandKey?: string, keys?: (number | string)[]) => string;
64
85
  }
65
86
  type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
66
87
  Bigint: typeof Bigint;
@@ -89,6 +110,7 @@ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
89
110
  CountInfo: typeof CountInfo;
90
111
  CountInfoExtra: typeof CountInfoExtra;
91
112
  KeyName: typeof KeyName;
113
+ Row: typeof Row;
92
114
  };
93
115
  declare const JsonView: JsonViewComponent;
94
116
  export default JsonView;
package/esm/index.js CHANGED
@@ -1,58 +1,62 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["className", "style", "value", "children", "collapsed", "indentWidth", "displayObjectSize", "shortenTextAfterLength", "highlightUpdates", "enableClipboard", "displayDataTypes", "objectSortKeys", "onExpand"];
3
+ var _excluded = ["className", "style", "value", "children", "collapsed", "shouldExpandNodeInitially", "indentWidth", "displayObjectSize", "shortenTextAfterLength", "stringEllipsis", "highlightUpdates", "enableClipboard", "displayDataTypes", "objectSortKeys", "onExpand", "onCopied", "beforeCopy"];
4
4
  import { forwardRef } from 'react';
5
- import { Provider } from './store';
6
- import { Container } from './Container';
7
- import { BraceLeft } from './symbol/BraceLeft';
8
- import { BraceRight } from './symbol/BraceRight';
9
- import { BracketsLeft } from './symbol/BracketsLeft';
10
- import { BracketsRight } from './symbol/BracketsRight';
11
- import { Arrow } from './symbol/Arrow';
12
- import { Colon } from './symbol/Colon';
13
- import { Quote } from './symbol/Quote';
14
- import { ValueQuote } from './symbol/ValueQuote';
15
- import { Bigint } from './types/Bigint';
16
- import { Date } from './types/Date';
17
- import { False } from './types/False';
18
- import { Float } from './types/Float';
19
- import { Int } from './types/Int';
20
- import { Map } from './types/Map';
21
- import { Nan } from './types/Nan';
22
- import { Null } from './types/Null';
23
- import { Set } from './types/Set';
24
- import { StringText } from './types/String';
25
- import { True } from './types/True';
26
- import { Undefined } from './types/Undefined';
27
- import { Url } from './types/Url';
28
- import { Copied } from './section/Copied';
29
- import { CountInfo } from './section/CountInfo';
30
- import { CountInfoExtra } from './section/CountInfoExtra';
31
- import { Ellipsis } from './section/Ellipsis';
32
- import { KeyName } from './section/KeyName';
33
- import { jsx as _jsx } from "react/jsx-runtime";
34
- import { jsxs as _jsxs } from "react/jsx-runtime";
35
- export * from './store';
36
- export * from './store/Expands';
37
- export * from './store/ShowTools';
38
- export * from './store/Symbols';
39
- export * from './store/Types';
40
- export * from './symbol';
5
+ import { Provider } from "./store.js";
6
+ import { Container } from "./Container.js";
7
+ import { BraceLeft } from "./symbol/BraceLeft.js";
8
+ import { BraceRight } from "./symbol/BraceRight.js";
9
+ import { BracketsLeft } from "./symbol/BracketsLeft.js";
10
+ import { BracketsRight } from "./symbol/BracketsRight.js";
11
+ import { Arrow } from "./symbol/Arrow.js";
12
+ import { Colon } from "./symbol/Colon.js";
13
+ import { Quote } from "./symbol/Quote.js";
14
+ import { ValueQuote } from "./symbol/ValueQuote.js";
15
+ import { Bigint } from "./types/Bigint.js";
16
+ import { Date } from "./types/Date.js";
17
+ import { False } from "./types/False.js";
18
+ import { Float } from "./types/Float.js";
19
+ import { Int } from "./types/Int.js";
20
+ import { Map } from "./types/Map.js";
21
+ import { Nan } from "./types/Nan.js";
22
+ import { Null } from "./types/Null.js";
23
+ import { Set } from "./types/Set.js";
24
+ import { StringText } from "./types/String.js";
25
+ import { True } from "./types/True.js";
26
+ import { Undefined } from "./types/Undefined.js";
27
+ import { Url } from "./types/Url.js";
28
+ import { Copied } from "./section/Copied.js";
29
+ import { CountInfo } from "./section/CountInfo.js";
30
+ import { CountInfoExtra } from "./section/CountInfoExtra.js";
31
+ import { Ellipsis } from "./section/Ellipsis.js";
32
+ import { KeyName } from "./section/KeyName.js";
33
+ import { Row } from "./section/Row.js";
34
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
35
+ export * from "./store.js";
36
+ export * from "./store/Expands.js";
37
+ export * from "./store/ShowTools.js";
38
+ export * from "./store/Symbols.js";
39
+ export * from "./store/Types.js";
40
+ export * from "./symbol/index.js";
41
41
  var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
42
42
  var {
43
43
  className = '',
44
44
  style,
45
45
  value,
46
46
  children,
47
- collapsed,
47
+ collapsed = false,
48
+ shouldExpandNodeInitially,
48
49
  indentWidth = 15,
49
50
  displayObjectSize = true,
50
- shortenTextAfterLength = 20,
51
+ shortenTextAfterLength = 30,
52
+ stringEllipsis,
51
53
  highlightUpdates = true,
52
54
  enableClipboard = true,
53
55
  displayDataTypes = true,
54
56
  objectSortKeys = false,
55
- onExpand
57
+ onExpand,
58
+ onCopied,
59
+ beforeCopy
56
60
  } = props,
57
61
  elmProps = _objectWithoutPropertiesLoose(props, _excluded);
58
62
  var defaultStyle = _extends({
@@ -68,12 +72,16 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
68
72
  value,
69
73
  objectSortKeys,
70
74
  indentWidth,
75
+ shouldExpandNodeInitially: collapsed === false ? shouldExpandNodeInitially : undefined,
71
76
  displayObjectSize,
72
77
  collapsed,
73
78
  enableClipboard,
74
79
  shortenTextAfterLength,
80
+ stringEllipsis,
75
81
  highlightUpdates,
76
- onExpand
82
+ onCopied,
83
+ onExpand,
84
+ beforeCopy
77
85
  },
78
86
  initialTypes: {
79
87
  displayDataTypes
@@ -113,5 +121,6 @@ JsonView.Copied = Copied;
113
121
  JsonView.CountInfo = CountInfo;
114
122
  JsonView.CountInfoExtra = CountInfoExtra;
115
123
  JsonView.KeyName = KeyName;
124
+ JsonView.Row = Row;
116
125
  JsonView.displayName = 'JVR.JsonView';
117
126
  export default JsonView;
@@ -1,6 +1,9 @@
1
1
  import { type TagType } from '../store/Types';
2
2
  import { type SectionElement } from '../store/Section';
3
+ export type CopiedSectionElement<T extends TagType = 'svg'> = SectionElement<T> & {
4
+ beforeCopy?: (copyText: string, keyName?: string | number, value?: object, parentValue?: object, expandKey?: string, keys?: (number | string)[]) => string;
5
+ };
3
6
  export declare const Copied: {
4
- (props: SectionElement<TagType>): null;
7
+ <K extends TagType = "svg">(props: CopiedSectionElement<K>): null;
5
8
  displayName: string;
6
9
  };
@@ -1,5 +1,5 @@
1
- import { useSectionStore } from '../store/Section';
2
- import { useSectionRender } from '../utils/useRender';
1
+ import { useSectionStore } from "../store/Section.js";
2
+ import { useSectionRender } from "../utils/useRender.js";
3
3
  export var Copied = props => {
4
4
  var {
5
5
  Copied: Comp = {}
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type TagType } from '../store/Types';
3
2
  import { type SectionElement, type SectionElementProps } from '../store/Section';
4
3
  export declare const CountInfo: {
@@ -10,6 +9,6 @@ export interface CountInfoCompProps<T extends object> {
10
9
  keyName: string | number;
11
10
  }
12
11
  export declare const CountInfoComp: {
13
- <T extends object>(props: SectionElementProps<TagType> & CountInfoCompProps<T> & import("react").HTMLAttributes<HTMLElement>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
12
+ <K extends TagType, T extends object>(props: SectionElementProps<K> & CountInfoCompProps<T> & React.HTMLAttributes<HTMLElement>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
14
13
  displayName: string;
15
14
  };
@@ -2,9 +2,9 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
3
  var _excluded = ["value", "keyName"],
4
4
  _excluded2 = ["as", "render"];
5
- import { useSectionStore } from '../store/Section';
6
- import { useSectionRender } from '../utils/useRender';
7
- import { useStore } from '../store';
5
+ import { useSectionStore } from "../store/Section.js";
6
+ import { useSectionRender } from "../utils/useRender.js";
7
+ import { useStore } from "../store.js";
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  export var CountInfo = props => {
10
10
  var {
@@ -36,7 +36,7 @@ export var CountInfoComp = props => {
36
36
  reset.style = _extends({}, reset.style, props.style);
37
37
  var len = Object.keys(value).length;
38
38
  if (!reset.children) {
39
- reset.children = len + " items";
39
+ reset.children = len + " item" + (len === 1 ? '' : 's');
40
40
  }
41
41
  var elmProps = _extends({}, reset, other);
42
42
  var isRender = render && typeof render === 'function';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type TagType } from '../store/Types';
3
2
  import { type SectionElement, type SectionElementProps } from '../store/Section';
4
3
  export declare const CountInfoExtra: {
@@ -10,6 +9,6 @@ export interface CountInfoExtraCompsProps<T extends object> {
10
9
  keyName: string | number;
11
10
  }
12
11
  export declare const CountInfoExtraComps: {
13
- <T extends object>(props: SectionElementProps<TagType> & CountInfoExtraCompsProps<T>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
12
+ <T extends object, K extends TagType>(props: SectionElementProps<K> & CountInfoExtraCompsProps<T>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
14
13
  displayName: string;
15
14
  };
@@ -2,8 +2,8 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
3
  var _excluded = ["value", "keyName"],
4
4
  _excluded2 = ["as", "render"];
5
- import { useSectionStore } from '../store/Section';
6
- import { useSectionRender } from '../utils/useRender';
5
+ import { useSectionStore } from "../store/Section.js";
6
+ import { useSectionRender } from "../utils/useRender.js";
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  export var CountInfoExtra = props => {
9
9
  var {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type TagType } from '../store/Types';
3
2
  import { type SectionElement } from '../store/Section';
4
3
  export declare const Ellipsis: {