@uiw/react-json-view 2.0.0-alpha.1 → 2.0.0-alpha.11

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 (171) hide show
  1. package/README.md +145 -36
  2. package/cjs/Container.js +4 -8
  3. package/cjs/comps/Copied.js +15 -13
  4. package/cjs/comps/KeyValues.js +30 -22
  5. package/cjs/comps/NestedClose.js +3 -4
  6. package/cjs/comps/NestedOpen.js +18 -16
  7. package/cjs/comps/Value.js +14 -16
  8. package/cjs/editor/KeyName.d.ts +2 -0
  9. package/cjs/editor/KeyName.js +82 -0
  10. package/cjs/editor/index.d.ts +19 -0
  11. package/cjs/editor/index.js +44 -0
  12. package/cjs/editor/store.d.ts +28 -0
  13. package/cjs/editor/store.js +23 -0
  14. package/cjs/index.d.ts +5 -3
  15. package/cjs/index.js +9 -8
  16. package/cjs/section/Copied.d.ts +1 -1
  17. package/cjs/section/Copied.js +1 -2
  18. package/cjs/section/CountInfo.d.ts +10 -1
  19. package/cjs/section/CountInfo.js +42 -4
  20. package/cjs/section/CountInfoExtra.d.ts +10 -1
  21. package/cjs/section/CountInfoExtra.js +32 -4
  22. package/cjs/section/Ellipsis.d.ts +10 -0
  23. package/cjs/section/Ellipsis.js +30 -4
  24. package/cjs/section/KeyName.d.ts +8 -0
  25. package/cjs/section/KeyName.js +38 -4
  26. package/cjs/section/Row.d.ts +16 -0
  27. package/cjs/section/Row.js +50 -0
  28. package/cjs/store/Expands.js +2 -4
  29. package/cjs/store/Section.d.ts +5 -2
  30. package/cjs/store/Section.js +6 -4
  31. package/cjs/store/ShowTools.js +2 -4
  32. package/cjs/store/Symbols.d.ts +2 -2
  33. package/cjs/store/Symbols.js +3 -4
  34. package/cjs/store/Types.d.ts +28 -24
  35. package/cjs/store/Types.js +8 -8
  36. package/cjs/store.d.ts +7 -4
  37. package/cjs/store.js +5 -10
  38. package/cjs/symbol/Arrow.d.ts +1 -1
  39. package/cjs/symbol/Arrow.js +1 -2
  40. package/cjs/symbol/BraceLeft.d.ts +1 -1
  41. package/cjs/symbol/BraceLeft.js +1 -2
  42. package/cjs/symbol/BraceRight.d.ts +1 -1
  43. package/cjs/symbol/BraceRight.js +1 -2
  44. package/cjs/symbol/BracketsLeft.d.ts +1 -1
  45. package/cjs/symbol/BracketsLeft.js +1 -2
  46. package/cjs/symbol/BracketsRight.d.ts +1 -1
  47. package/cjs/symbol/BracketsRight.js +1 -2
  48. package/cjs/symbol/Colon.d.ts +1 -1
  49. package/cjs/symbol/Colon.js +1 -2
  50. package/cjs/symbol/Quote.d.ts +1 -1
  51. package/cjs/symbol/Quote.js +1 -2
  52. package/cjs/symbol/ValueQuote.d.ts +1 -1
  53. package/cjs/symbol/ValueQuote.js +1 -2
  54. package/{esm/comps/ReRender/Symbols.d.ts → cjs/symbol/index.d.ts} +4 -6
  55. package/cjs/{comps/ReRender/Symbols.js → symbol/index.js} +32 -33
  56. package/cjs/theme/basic.js +2 -3
  57. package/cjs/theme/dark.js +2 -3
  58. package/cjs/theme/github.dark.js +2 -3
  59. package/cjs/theme/github.light.js +2 -3
  60. package/cjs/theme/gruvbox.js +2 -3
  61. package/cjs/theme/light.js +2 -3
  62. package/cjs/theme/monokai.js +2 -3
  63. package/cjs/theme/nord.js +2 -3
  64. package/cjs/theme/vscode.js +2 -3
  65. package/cjs/types/Bigint.d.ts +1 -1
  66. package/cjs/types/Bigint.js +1 -2
  67. package/cjs/types/Date.d.ts +1 -1
  68. package/cjs/types/Date.js +1 -2
  69. package/cjs/types/False.d.ts +1 -1
  70. package/cjs/types/False.js +1 -2
  71. package/cjs/types/Float.d.ts +1 -1
  72. package/cjs/types/Float.js +1 -2
  73. package/cjs/types/Int.d.ts +1 -1
  74. package/cjs/types/Int.js +1 -2
  75. package/cjs/types/Map.d.ts +1 -1
  76. package/cjs/types/Map.js +1 -2
  77. package/cjs/types/Nan.d.ts +1 -1
  78. package/cjs/types/Nan.js +1 -2
  79. package/cjs/types/Null.d.ts +1 -1
  80. package/cjs/types/Null.js +1 -2
  81. package/cjs/types/Set.d.ts +1 -1
  82. package/cjs/types/Set.js +1 -2
  83. package/cjs/types/String.d.ts +1 -1
  84. package/cjs/types/String.js +1 -2
  85. package/cjs/types/True.d.ts +1 -1
  86. package/cjs/types/True.js +1 -2
  87. package/cjs/types/Undefined.d.ts +1 -1
  88. package/cjs/types/Undefined.js +1 -2
  89. package/cjs/types/Url.d.ts +1 -1
  90. package/cjs/types/Url.js +1 -2
  91. package/{esm/comps/ReRender/Types.d.ts → cjs/types/index.d.ts} +8 -13
  92. package/cjs/{comps/ReRender/Types.js → types/index.js} +103 -121
  93. package/cjs/utils/useHighlight.js +0 -1
  94. package/cjs/utils/useRender.d.ts +1 -1
  95. package/editor.d.ts +22 -20
  96. package/esm/Container.js +4 -5
  97. package/esm/comps/Copied.js +14 -11
  98. package/esm/comps/KeyValues.js +20 -11
  99. package/esm/comps/NestedClose.js +1 -1
  100. package/esm/comps/NestedOpen.js +12 -9
  101. package/esm/comps/Value.js +1 -1
  102. package/esm/editor/KeyName.d.ts +2 -0
  103. package/esm/editor/KeyName.js +77 -0
  104. package/esm/editor/index.d.ts +19 -0
  105. package/esm/editor/index.js +34 -0
  106. package/esm/editor/store.d.ts +28 -0
  107. package/esm/editor/store.js +13 -0
  108. package/esm/index.d.ts +5 -3
  109. package/esm/index.js +5 -3
  110. package/esm/section/Copied.d.ts +1 -1
  111. package/esm/section/CountInfo.d.ts +10 -1
  112. package/esm/section/CountInfo.js +43 -1
  113. package/esm/section/CountInfoExtra.d.ts +10 -1
  114. package/esm/section/CountInfoExtra.js +32 -1
  115. package/esm/section/Ellipsis.d.ts +10 -0
  116. package/esm/section/Ellipsis.js +31 -1
  117. package/esm/section/KeyName.d.ts +8 -0
  118. package/esm/section/KeyName.js +39 -1
  119. package/esm/section/Row.d.ts +16 -0
  120. package/esm/section/Row.js +45 -0
  121. package/esm/store/Section.d.ts +5 -2
  122. package/esm/store/Section.js +4 -0
  123. package/esm/store/Symbols.d.ts +2 -2
  124. package/esm/store/Symbols.js +1 -0
  125. package/esm/store/Types.d.ts +28 -24
  126. package/esm/store/Types.js +6 -4
  127. package/esm/store.d.ts +7 -4
  128. package/esm/symbol/Arrow.d.ts +1 -1
  129. package/esm/symbol/BraceLeft.d.ts +1 -1
  130. package/esm/symbol/BraceRight.d.ts +1 -1
  131. package/esm/symbol/BracketsLeft.d.ts +1 -1
  132. package/esm/symbol/BracketsRight.d.ts +1 -1
  133. package/esm/symbol/Colon.d.ts +1 -1
  134. package/esm/symbol/Quote.d.ts +1 -1
  135. package/esm/symbol/ValueQuote.d.ts +1 -1
  136. package/{cjs/comps/ReRender/Symbols.d.ts → esm/symbol/index.d.ts} +4 -6
  137. package/esm/{comps/ReRender/Symbols.js → symbol/index.js} +26 -24
  138. package/esm/types/Bigint.d.ts +1 -1
  139. package/esm/types/Date.d.ts +1 -1
  140. package/esm/types/False.d.ts +1 -1
  141. package/esm/types/Float.d.ts +1 -1
  142. package/esm/types/Int.d.ts +1 -1
  143. package/esm/types/Map.d.ts +1 -1
  144. package/esm/types/Nan.d.ts +1 -1
  145. package/esm/types/Null.d.ts +1 -1
  146. package/esm/types/Set.d.ts +1 -1
  147. package/esm/types/String.d.ts +1 -1
  148. package/esm/types/True.d.ts +1 -1
  149. package/esm/types/Undefined.d.ts +1 -1
  150. package/esm/types/Url.d.ts +1 -1
  151. package/{cjs/comps/ReRender/Types.d.ts → esm/types/index.d.ts} +8 -13
  152. package/esm/{comps/ReRender/Types.js → types/index.js} +84 -94
  153. package/esm/utils/useHighlight.js +0 -1
  154. package/esm/utils/useRender.d.ts +1 -1
  155. package/package.json +3 -4
  156. package/cjs/comps/CountInfo.d.ts +0 -19
  157. package/cjs/comps/CountInfo.js +0 -72
  158. package/cjs/comps/Ellipsis.d.ts +0 -10
  159. package/cjs/comps/Ellipsis.js +0 -35
  160. package/cjs/comps/Key.d.ts +0 -7
  161. package/cjs/comps/Key.js +0 -39
  162. package/cjs/type.d.ts +0 -50
  163. package/cjs/type.js +0 -57
  164. package/esm/comps/CountInfo.d.ts +0 -19
  165. package/esm/comps/CountInfo.js +0 -70
  166. package/esm/comps/Ellipsis.d.ts +0 -10
  167. package/esm/comps/Ellipsis.js +0 -31
  168. package/esm/comps/Key.d.ts +0 -7
  169. package/esm/comps/Key.js +0 -35
  170. package/esm/type.d.ts +0 -50
  171. package/esm/type.js +0 -50
package/esm/Container.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
3
  var _excluded = ["className", "children", "parentValue", "keyid", "level", "value", "initialValue", "keyName"];
4
- import React, { forwardRef, useId, useImperativeHandle, useRef } from 'react';
4
+ import React, { forwardRef, useId } from 'react';
5
5
  import { NestedClose } from './comps/NestedClose';
6
6
  import { NestedOpen } from './comps/NestedOpen';
7
7
  import { KeyValues } from './comps/KeyValues';
@@ -17,11 +17,9 @@ export var Container = /*#__PURE__*/forwardRef((props, ref) => {
17
17
  keyName
18
18
  } = props,
19
19
  elmProps = _objectWithoutPropertiesLoose(props, _excluded);
20
- var $ref = useRef(null);
21
20
  var dispatch = useShowToolsDispatch();
22
- useImperativeHandle(ref, () => $ref.current, [$ref]);
23
21
  var subkeyid = useId();
24
- var defaultClassNames = "w-rjv-inner " + className;
22
+ var defaultClassNames = [className, 'w-rjv-inner'].filter(Boolean).join(' ');
25
23
  var reset = {
26
24
  onMouseEnter: () => dispatch({
27
25
  [subkeyid]: true
@@ -31,7 +29,8 @@ export var Container = /*#__PURE__*/forwardRef((props, ref) => {
31
29
  })
32
30
  };
33
31
  return /*#__PURE__*/_jsxs("div", _extends({
34
- className: defaultClassNames
32
+ className: defaultClassNames,
33
+ ref: ref
35
34
  }, elmProps, reset, {
36
35
  children: [/*#__PURE__*/_jsx(NestedOpen, {
37
36
  expandKey: subkeyid,
@@ -27,18 +27,21 @@ export var Copied = props => {
27
27
  if (enableClipboard === false || !isShowTools) return null;
28
28
  var click = event => {
29
29
  event.stopPropagation();
30
- var copyText = JSON.stringify(value, (key, value) => {
31
- if (typeof value === 'bigint') {
32
- return value.toString();
33
- }
34
- return value;
35
- }, 2);
36
- if (typeof value === 'number' && value === Infinity) copyText = 'Infinity';
37
- if (typeof value === 'number' && isNaN(value)) copyText = 'NaN';
38
- if (typeof value === 'bigint') copyText = value + 'n';
30
+ var copyText = '';
31
+ if (typeof value === 'number' && value === Infinity) {
32
+ copyText = 'Infinity';
33
+ } else if (typeof value === 'number' && isNaN(value)) {
34
+ copyText = 'NaN';
35
+ } else if (typeof value === 'bigint') {
36
+ copyText = value + 'n';
37
+ } else if (value instanceof Date) {
38
+ copyText = value.toLocaleString();
39
+ } else {
40
+ copyText = JSON.stringify(value, null, 2);
41
+ }
42
+ onCopied && onCopied(copyText, value);
43
+ setCopied(true);
39
44
  navigator.clipboard.writeText(copyText).then(() => {
40
- onCopied && onCopied(copyText, value);
41
- setCopied(true);
42
45
  var timer = setTimeout(() => {
43
46
  setCopied(false);
44
47
  clearTimeout(timer);
@@ -4,9 +4,10 @@ import { useStore } from '../store';
4
4
  import { useExpandsStore } from '../store/Expands';
5
5
  import { useShowToolsDispatch } from '../store/ShowTools';
6
6
  import { Value } from './Value';
7
- import { Key } from './Key';
7
+ import { KeyNameComp } from '../section/KeyName';
8
+ import { RowComp } from '../section/Row';
8
9
  import { Container } from '../Container';
9
- import { Quote, Colon } from './ReRender/Symbols';
10
+ import { Quote, Colon } from '../symbol';
10
11
  import { useHighlight } from '../utils/useHighlight';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -36,9 +37,9 @@ export var KeyValues = props => {
36
37
  var [b] = _ref2;
37
38
  return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
38
39
  }) : entries.sort((_ref3, _ref4) => {
39
- var [a] = _ref3;
40
- var [b] = _ref4;
41
- return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
40
+ var [a, valA] = _ref3;
41
+ var [b, valB] = _ref4;
42
+ return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b, valA, valB) : 0;
42
43
  });
43
44
  }
44
45
  var style = {
@@ -64,6 +65,7 @@ KeyValues.displayName = 'JVR.KeyValues';
64
65
  export var KayName = props => {
65
66
  var {
66
67
  keyName,
68
+ parentValue,
67
69
  value
68
70
  } = props;
69
71
  var {
@@ -80,13 +82,16 @@ export var KayName = props => {
80
82
  children: [/*#__PURE__*/_jsxs("span", {
81
83
  ref: highlightContainer,
82
84
  children: [/*#__PURE__*/_jsx(Quote, {
83
- isNumber: isNumber
84
- }), /*#__PURE__*/_jsx(Key, {
85
+ isNumber: isNumber,
86
+ "data-placement": "left"
87
+ }), /*#__PURE__*/_jsx(KeyNameComp, {
85
88
  keyName: keyName,
86
89
  value: value,
90
+ parentValue: parentValue,
87
91
  children: keyName
88
92
  }), /*#__PURE__*/_jsx(Quote, {
89
- isNumber: isNumber
93
+ isNumber: isNumber,
94
+ "data-placement": "right"
90
95
  })]
91
96
  }), /*#__PURE__*/_jsx(Colon, {})]
92
97
  });
@@ -126,12 +131,16 @@ export var KeyValuesItem = props => {
126
131
  [subkeyid]: false
127
132
  })
128
133
  };
129
- return /*#__PURE__*/_jsxs("div", _extends({
130
- className: "w-rjv-line"
134
+ return /*#__PURE__*/_jsxs(RowComp, _extends({
135
+ className: "w-rjv-line",
136
+ value: value,
137
+ keyName: keyName,
138
+ parentValue: parentValue
131
139
  }, reset, {
132
140
  children: [/*#__PURE__*/_jsx(KayName, {
133
141
  keyName: keyName,
134
- value: value
142
+ value: value,
143
+ parentValue: parentValue
135
144
  }), /*#__PURE__*/_jsx(Value, {
136
145
  keyName: keyName,
137
146
  value: value,
@@ -1,6 +1,6 @@
1
1
  import { useStore } from '../store';
2
2
  import { useExpandsStore } from '../store/Expands';
3
- import { BracketsClose } from './ReRender/Symbols';
3
+ import { BracketsClose } from '../symbol';
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
5
  export var NestedClose = props => {
6
6
  var _expands$expandKey;
@@ -3,10 +3,11 @@ import { KayName } from './KeyValues';
3
3
  import { useExpandsStore, useExpandsDispatch } from '../store/Expands';
4
4
  import { useStore } from '../store';
5
5
  import { Copied } from './Copied';
6
- import { CountInfo, CountInfoExtra } from './CountInfo';
7
- import { Arrow, BracketsOpen, BracketsClose } from './ReRender/Symbols';
8
- import { Ellipsis } from './Ellipsis';
9
- import { SetComp, MapComp } from './ReRender/Types';
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';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
13
  export var NestedOpen = props => {
@@ -63,22 +64,24 @@ export var NestedOpen = props => {
63
64
  }), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, {
64
65
  keyName: keyName
65
66
  }), /*#__PURE__*/_jsx(SetComp, {
66
- isSet: initialValue instanceof Set
67
+ value: initialValue,
68
+ keyName: keyName
67
69
  }), /*#__PURE__*/_jsx(MapComp, {
68
- isMap: initialValue instanceof Map
70
+ value: initialValue,
71
+ keyName: keyName
69
72
  }), /*#__PURE__*/_jsx(BracketsOpen, {
70
73
  isBrackets: isArray || isMySet
71
- }), /*#__PURE__*/_jsx(Ellipsis, {
74
+ }), /*#__PURE__*/_jsx(EllipsisComp, {
72
75
  keyName: keyName,
73
76
  value: value,
74
77
  isExpanded: isExpanded
75
78
  }), /*#__PURE__*/_jsx(BracketsClose, {
76
79
  isVisiable: isExpanded || !showArrow,
77
80
  isBrackets: isArray || isMySet
78
- }), /*#__PURE__*/_jsx(CountInfo, {
81
+ }), /*#__PURE__*/_jsx(CountInfoComp, {
79
82
  value: value,
80
83
  keyName: keyName
81
- }), /*#__PURE__*/_jsx(CountInfoExtra, {
84
+ }), /*#__PURE__*/_jsx(CountInfoExtraComps, {
82
85
  value: value,
83
86
  keyName: keyName
84
87
  }), /*#__PURE__*/_jsx(Copied, {
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import { TypeString, TypeTrue, TypeNull, TypeFalse, TypeFloat, TypeBigint, TypeInt, TypeDate, TypeUndefined, TypeNan, TypeUrl } from './ReRender/Types';
2
+ import { TypeString, TypeTrue, TypeNull, TypeFalse, TypeFloat, TypeBigint, TypeInt, TypeDate, TypeUndefined, TypeNan, TypeUrl } from '../types';
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 => {
@@ -0,0 +1,2 @@
1
+ import { 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';
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,19 @@
1
+ /// <reference types="react" />
2
+ import { type JsonViewProps } from '../';
3
+ export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
4
+ /**
5
+ * When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
6
+ * @returns {boolean} Returning false from onEdit will prevent the change from being made.
7
+ */
8
+ onEdit?: (option: {
9
+ value: unknown;
10
+ oldValue: unknown;
11
+ keyName?: string | number;
12
+ parentName?: string | number;
13
+ type?: 'value' | 'key';
14
+ }) => boolean;
15
+ /** Whether enable edit feature. @default true */
16
+ editable?: boolean;
17
+ }
18
+ declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
19
+ export default JsonViewEditor;
@@ -0,0 +1,34 @@
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 '../';
6
+ import { KeyNameRender } from './KeyName';
7
+ import { Context, Dispatch, useStoreReducer } from './store';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
11
+ var {
12
+ children,
13
+ onEdit,
14
+ editable = true
15
+ } = props,
16
+ reset = _objectWithoutPropertiesLoose(props, _excluded);
17
+ var [state, dispatch] = useStoreReducer({
18
+ onEdit
19
+ });
20
+ return /*#__PURE__*/_jsx(Context.Provider, {
21
+ value: state,
22
+ children: /*#__PURE__*/_jsx(Dispatch.Provider, {
23
+ value: dispatch,
24
+ children: /*#__PURE__*/_jsxs(JsonView, _extends({}, reset, {
25
+ shortenTextAfterLength: 0,
26
+ ref: ref,
27
+ children: [editable && /*#__PURE__*/_jsx(JsonView.KeyName, {
28
+ render: KeyNameRender
29
+ }), children]
30
+ }))
31
+ })
32
+ });
33
+ });
34
+ export default JsonViewEditor;
@@ -0,0 +1,28 @@
1
+ /// <reference types="react" />
2
+ type InitialState = {
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
+ };
15
+ type Dispatch = React.Dispatch<InitialState>;
16
+ export declare const Context: import("react").Context<InitialState>;
17
+ export declare const Dispatch: import("react").Context<Dispatch>;
18
+ export declare const useStore: () => InitialState;
19
+ export declare function useStoreReducer(initialState: InitialState): [{
20
+ onEdit?: ((option: {
21
+ value: unknown;
22
+ oldValue: unknown;
23
+ keyName?: string | number | undefined;
24
+ parentName?: string | number | undefined;
25
+ type?: "value" | "key" | undefined;
26
+ }) => boolean) | undefined;
27
+ }, import("react").Dispatch<InitialState>];
28
+ 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
@@ -25,19 +25,20 @@ import { CountInfo } from './section/CountInfo';
25
25
  import { CountInfoExtra } from './section/CountInfoExtra';
26
26
  import { Ellipsis } from './section/Ellipsis';
27
27
  import { KeyName } from './section/KeyName';
28
+ import { Row } from './section/Row';
28
29
  export * from './store';
29
30
  export * from './store/Expands';
30
31
  export * from './store/ShowTools';
31
32
  export * from './store/Symbols';
32
33
  export * from './store/Types';
33
- export * from './comps/ReRender/Symbols';
34
+ export * from './symbol';
34
35
  export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
35
36
  /** This property contains your input JSON */
36
37
  value?: T;
37
38
  /** Define the root node name. @default undefined */
38
39
  keyName?: string | number;
39
40
  /** Whether sort keys through `String.prototype.localeCompare()` @default false */
40
- objectSortKeys?: boolean | ((a: string, b: string) => number);
41
+ objectSortKeys?: boolean | ((keyA: string, keyB: string, valueA: T, valueB: T) => number);
41
42
  /** Set the indent-width for nested objects @default 15 */
42
43
  indentWidth?: number;
43
44
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
@@ -50,7 +51,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
50
51
  collapsed?: boolean | number;
51
52
  /** Whether to highlight updates. @default true */
52
53
  highlightUpdates?: boolean;
53
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
54
+ /** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
54
55
  shortenTextAfterLength?: number;
55
56
  /** Callback function for when a treeNode is expanded or collapsed */
56
57
  onExpand?: (props: {
@@ -89,6 +90,7 @@ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
89
90
  CountInfo: typeof CountInfo;
90
91
  CountInfoExtra: typeof CountInfoExtra;
91
92
  KeyName: typeof KeyName;
93
+ Row: typeof Row;
92
94
  };
93
95
  declare const JsonView: JsonViewComponent;
94
96
  export default JsonView;
package/esm/index.js CHANGED
@@ -30,6 +30,7 @@ import { CountInfo } from './section/CountInfo';
30
30
  import { CountInfoExtra } from './section/CountInfoExtra';
31
31
  import { Ellipsis } from './section/Ellipsis';
32
32
  import { KeyName } from './section/KeyName';
33
+ import { Row } from './section/Row';
33
34
  import { jsx as _jsx } from "react/jsx-runtime";
34
35
  import { jsxs as _jsxs } from "react/jsx-runtime";
35
36
  export * from './store';
@@ -37,7 +38,7 @@ export * from './store/Expands';
37
38
  export * from './store/ShowTools';
38
39
  export * from './store/Symbols';
39
40
  export * from './store/Types';
40
- export * from './comps/ReRender/Symbols';
41
+ export * from './symbol';
41
42
  var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
42
43
  var {
43
44
  className = '',
@@ -47,7 +48,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
47
48
  collapsed,
48
49
  indentWidth = 15,
49
50
  displayObjectSize = true,
50
- shortenTextAfterLength = 20,
51
+ shortenTextAfterLength = 30,
51
52
  highlightUpdates = true,
52
53
  enableClipboard = true,
53
54
  displayDataTypes = true,
@@ -62,7 +63,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
62
63
  backgroundColor: 'var(--w-rjv-background-color, #00000000)',
63
64
  fontSize: 13
64
65
  }, style);
65
- var cls = "w-json-view-container w-rjv " + (className || '');
66
+ var cls = ['w-json-view-container', 'w-rjv', className].filter(Boolean).join(' ');
66
67
  return /*#__PURE__*/_jsxs(Provider, {
67
68
  initialState: {
68
69
  value,
@@ -113,5 +114,6 @@ JsonView.Copied = Copied;
113
114
  JsonView.CountInfo = CountInfo;
114
115
  JsonView.CountInfoExtra = CountInfoExtra;
115
116
  JsonView.KeyName = KeyName;
117
+ JsonView.Row = Row;
116
118
  JsonView.displayName = 'JVR.JsonView';
117
119
  export default JsonView;
@@ -1,6 +1,6 @@
1
1
  import { type TagType } from '../store/Types';
2
2
  import { type SectionElement } from '../store/Section';
3
3
  export declare const Copied: {
4
- (props: SectionElement<TagType>): null;
4
+ <K extends TagType = "svg">(props: SectionElement<K>): null;
5
5
  displayName: string;
6
6
  };
@@ -1,6 +1,15 @@
1
+ /// <reference types="react" />
1
2
  import { type TagType } from '../store/Types';
2
- import { type SectionElement } from '../store/Section';
3
+ import { type SectionElement, type SectionElementProps } from '../store/Section';
3
4
  export declare const CountInfo: {
4
5
  <K extends TagType>(props: SectionElement<K>): null;
5
6
  displayName: string;
6
7
  };
8
+ export interface CountInfoCompProps<T extends object> {
9
+ value?: T;
10
+ keyName: string | number;
11
+ }
12
+ export declare const CountInfoComp: {
13
+ <K extends TagType, T extends object>(props: SectionElementProps<K> & CountInfoCompProps<T> & import("react").HTMLAttributes<HTMLElement>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
14
+ displayName: string;
15
+ };
@@ -1,5 +1,11 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["value", "keyName"],
4
+ _excluded2 = ["as", "render"];
1
5
  import { useSectionStore } from '../store/Section';
2
6
  import { useSectionRender } from '../utils/useRender';
7
+ import { useStore } from '../store';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
3
9
  export var CountInfo = props => {
4
10
  var {
5
11
  CountInfo: Comp = {}
@@ -7,4 +13,40 @@ export var CountInfo = props => {
7
13
  useSectionRender(Comp, props, 'CountInfo');
8
14
  return null;
9
15
  };
10
- CountInfo.displayName = 'JVR.CountInfo';
16
+ CountInfo.displayName = 'JVR.CountInfo';
17
+ export var CountInfoComp = props => {
18
+ var {
19
+ value = {},
20
+ keyName
21
+ } = props,
22
+ other = _objectWithoutPropertiesLoose(props, _excluded);
23
+ var {
24
+ displayObjectSize
25
+ } = useStore();
26
+ var {
27
+ CountInfo: Comp = {}
28
+ } = useSectionStore();
29
+ if (!displayObjectSize) return null;
30
+ var {
31
+ as,
32
+ render
33
+ } = Comp,
34
+ reset = _objectWithoutPropertiesLoose(Comp, _excluded2);
35
+ var Elm = as || 'span';
36
+ reset.style = _extends({}, reset.style, props.style);
37
+ var len = Object.keys(value).length;
38
+ if (!reset.children) {
39
+ reset.children = len + " items";
40
+ }
41
+ var elmProps = _extends({}, reset, other);
42
+ var isRender = render && typeof render === 'function';
43
+ var child = isRender && render(_extends({}, elmProps, {
44
+ 'data-length': len
45
+ }), {
46
+ value,
47
+ keyName
48
+ });
49
+ if (child) return child;
50
+ return /*#__PURE__*/_jsx(Elm, _extends({}, elmProps));
51
+ };
52
+ CountInfoComp.displayName = 'JVR.CountInfoComp';
@@ -1,6 +1,15 @@
1
+ /// <reference types="react" />
1
2
  import { type TagType } from '../store/Types';
2
- import { type SectionElement } from '../store/Section';
3
+ import { type SectionElement, type SectionElementProps } from '../store/Section';
3
4
  export declare const CountInfoExtra: {
4
5
  <K extends TagType>(props: SectionElement<K>): null;
5
6
  displayName: string;
6
7
  };
8
+ export interface CountInfoExtraCompsProps<T extends object> {
9
+ value?: T;
10
+ keyName: string | number;
11
+ }
12
+ export declare const CountInfoExtraComps: {
13
+ <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
+ displayName: string;
15
+ };
@@ -1,5 +1,10 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["value", "keyName"],
4
+ _excluded2 = ["as", "render"];
1
5
  import { useSectionStore } from '../store/Section';
2
6
  import { useSectionRender } from '../utils/useRender';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
3
8
  export var CountInfoExtra = props => {
4
9
  var {
5
10
  CountInfoExtra: Comp = {}
@@ -7,4 +12,30 @@ export var CountInfoExtra = props => {
7
12
  useSectionRender(Comp, props, 'CountInfoExtra');
8
13
  return null;
9
14
  };
10
- CountInfoExtra.displayName = 'JVR.CountInfoExtra';
15
+ CountInfoExtra.displayName = 'JVR.CountInfoExtra';
16
+ export var CountInfoExtraComps = props => {
17
+ var {
18
+ value = {},
19
+ keyName
20
+ } = props,
21
+ other = _objectWithoutPropertiesLoose(props, _excluded);
22
+ var {
23
+ CountInfoExtra: Comp = {}
24
+ } = useSectionStore();
25
+ var {
26
+ as,
27
+ render
28
+ } = Comp,
29
+ reset = _objectWithoutPropertiesLoose(Comp, _excluded2);
30
+ if (!render && !reset.children) return null;
31
+ var Elm = as || 'span';
32
+ var isRender = render && typeof render === 'function';
33
+ var elmProps = _extends({}, reset, other);
34
+ var child = isRender && render(elmProps, {
35
+ value,
36
+ keyName
37
+ });
38
+ if (child) return child;
39
+ return /*#__PURE__*/_jsx(Elm, _extends({}, elmProps));
40
+ };
41
+ CountInfoExtraComps.displayName = 'JVR.CountInfoExtraComps';
@@ -1,6 +1,16 @@
1
+ /// <reference types="react" />
1
2
  import { type TagType } from '../store/Types';
2
3
  import { type SectionElement } from '../store/Section';
3
4
  export declare const Ellipsis: {
4
5
  <K extends TagType>(props: SectionElement<K>): null;
5
6
  displayName: string;
6
7
  };
8
+ export interface EllipsisCompProps<T extends object> {
9
+ value?: T;
10
+ keyName: string | number;
11
+ isExpanded: boolean;
12
+ }
13
+ export declare const EllipsisComp: {
14
+ <T extends object>({ isExpanded, value, keyName }: EllipsisCompProps<T>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
15
+ displayName: string;
16
+ };