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

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 (166) hide show
  1. package/README.md +121 -54
  2. package/cjs/Container.js +4 -8
  3. package/cjs/comps/Copied.js +15 -13
  4. package/cjs/comps/KeyValues.js +24 -20
  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 +7 -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/store/Expands.js +2 -4
  27. package/cjs/store/Section.d.ts +3 -2
  28. package/cjs/store/Section.js +2 -4
  29. package/cjs/store/ShowTools.js +2 -4
  30. package/cjs/store/Symbols.d.ts +2 -2
  31. package/cjs/store/Symbols.js +3 -4
  32. package/cjs/store/Types.d.ts +28 -24
  33. package/cjs/store/Types.js +8 -8
  34. package/cjs/store.d.ts +7 -4
  35. package/cjs/store.js +5 -10
  36. package/cjs/symbol/Arrow.d.ts +1 -1
  37. package/cjs/symbol/Arrow.js +1 -2
  38. package/cjs/symbol/BraceLeft.d.ts +1 -1
  39. package/cjs/symbol/BraceLeft.js +1 -2
  40. package/cjs/symbol/BraceRight.d.ts +1 -1
  41. package/cjs/symbol/BraceRight.js +1 -2
  42. package/cjs/symbol/BracketsLeft.d.ts +1 -1
  43. package/cjs/symbol/BracketsLeft.js +1 -2
  44. package/cjs/symbol/BracketsRight.d.ts +1 -1
  45. package/cjs/symbol/BracketsRight.js +1 -2
  46. package/cjs/symbol/Colon.d.ts +1 -1
  47. package/cjs/symbol/Colon.js +1 -2
  48. package/cjs/symbol/Quote.d.ts +1 -1
  49. package/cjs/symbol/Quote.js +1 -2
  50. package/cjs/symbol/ValueQuote.d.ts +1 -1
  51. package/cjs/symbol/ValueQuote.js +1 -2
  52. package/{esm/comps/ReRender/Symbols.d.ts → cjs/symbol/index.d.ts} +4 -6
  53. package/cjs/{comps/ReRender/Symbols.js → symbol/index.js} +32 -33
  54. package/cjs/theme/basic.js +2 -3
  55. package/cjs/theme/dark.js +2 -3
  56. package/cjs/theme/github.dark.js +2 -3
  57. package/cjs/theme/github.light.js +2 -3
  58. package/cjs/theme/gruvbox.js +2 -3
  59. package/cjs/theme/light.js +2 -3
  60. package/cjs/theme/monokai.js +2 -3
  61. package/cjs/theme/nord.js +2 -3
  62. package/cjs/theme/vscode.js +2 -3
  63. package/cjs/types/Bigint.d.ts +1 -1
  64. package/cjs/types/Bigint.js +1 -2
  65. package/cjs/types/Date.d.ts +1 -1
  66. package/cjs/types/Date.js +1 -2
  67. package/cjs/types/False.d.ts +1 -1
  68. package/cjs/types/False.js +1 -2
  69. package/cjs/types/Float.d.ts +1 -1
  70. package/cjs/types/Float.js +1 -2
  71. package/cjs/types/Int.d.ts +1 -1
  72. package/cjs/types/Int.js +1 -2
  73. package/cjs/types/Map.d.ts +1 -1
  74. package/cjs/types/Map.js +1 -2
  75. package/cjs/types/Nan.d.ts +1 -1
  76. package/cjs/types/Nan.js +1 -2
  77. package/cjs/types/Null.d.ts +1 -1
  78. package/cjs/types/Null.js +1 -2
  79. package/cjs/types/Set.d.ts +1 -1
  80. package/cjs/types/Set.js +1 -2
  81. package/cjs/types/String.d.ts +1 -1
  82. package/cjs/types/String.js +1 -2
  83. package/cjs/types/True.d.ts +1 -1
  84. package/cjs/types/True.js +1 -2
  85. package/cjs/types/Undefined.d.ts +1 -1
  86. package/cjs/types/Undefined.js +1 -2
  87. package/cjs/types/Url.d.ts +1 -1
  88. package/cjs/types/Url.js +1 -2
  89. package/{esm/comps/ReRender/Types.d.ts → cjs/types/index.d.ts} +8 -13
  90. package/cjs/{comps/ReRender/Types.js → types/index.js} +103 -121
  91. package/cjs/utils/useHighlight.js +0 -1
  92. package/cjs/utils/useRender.d.ts +1 -1
  93. package/editor.d.ts +22 -20
  94. package/esm/Container.js +4 -5
  95. package/esm/comps/Copied.js +14 -11
  96. package/esm/comps/KeyValues.js +14 -9
  97. package/esm/comps/NestedClose.js +1 -1
  98. package/esm/comps/NestedOpen.js +12 -9
  99. package/esm/comps/Value.js +1 -1
  100. package/esm/editor/KeyName.d.ts +2 -0
  101. package/esm/editor/KeyName.js +77 -0
  102. package/esm/editor/index.d.ts +19 -0
  103. package/esm/editor/index.js +34 -0
  104. package/esm/editor/store.d.ts +28 -0
  105. package/esm/editor/store.js +13 -0
  106. package/esm/index.d.ts +5 -3
  107. package/esm/index.js +3 -3
  108. package/esm/section/Copied.d.ts +1 -1
  109. package/esm/section/CountInfo.d.ts +10 -1
  110. package/esm/section/CountInfo.js +43 -1
  111. package/esm/section/CountInfoExtra.d.ts +10 -1
  112. package/esm/section/CountInfoExtra.js +32 -1
  113. package/esm/section/Ellipsis.d.ts +10 -0
  114. package/esm/section/Ellipsis.js +31 -1
  115. package/esm/section/KeyName.d.ts +8 -0
  116. package/esm/section/KeyName.js +39 -1
  117. package/esm/store/Section.d.ts +3 -2
  118. package/esm/store/Symbols.d.ts +2 -2
  119. package/esm/store/Symbols.js +1 -0
  120. package/esm/store/Types.d.ts +28 -24
  121. package/esm/store/Types.js +6 -4
  122. package/esm/store.d.ts +7 -4
  123. package/esm/symbol/Arrow.d.ts +1 -1
  124. package/esm/symbol/BraceLeft.d.ts +1 -1
  125. package/esm/symbol/BraceRight.d.ts +1 -1
  126. package/esm/symbol/BracketsLeft.d.ts +1 -1
  127. package/esm/symbol/BracketsRight.d.ts +1 -1
  128. package/esm/symbol/Colon.d.ts +1 -1
  129. package/esm/symbol/Quote.d.ts +1 -1
  130. package/esm/symbol/ValueQuote.d.ts +1 -1
  131. package/{cjs/comps/ReRender/Symbols.d.ts → esm/symbol/index.d.ts} +4 -6
  132. package/esm/{comps/ReRender/Symbols.js → symbol/index.js} +26 -24
  133. package/esm/types/Bigint.d.ts +1 -1
  134. package/esm/types/Date.d.ts +1 -1
  135. package/esm/types/False.d.ts +1 -1
  136. package/esm/types/Float.d.ts +1 -1
  137. package/esm/types/Int.d.ts +1 -1
  138. package/esm/types/Map.d.ts +1 -1
  139. package/esm/types/Nan.d.ts +1 -1
  140. package/esm/types/Null.d.ts +1 -1
  141. package/esm/types/Set.d.ts +1 -1
  142. package/esm/types/String.d.ts +1 -1
  143. package/esm/types/True.d.ts +1 -1
  144. package/esm/types/Undefined.d.ts +1 -1
  145. package/esm/types/Url.d.ts +1 -1
  146. package/{cjs/comps/ReRender/Types.d.ts → esm/types/index.d.ts} +8 -13
  147. package/esm/{comps/ReRender/Types.js → types/index.js} +84 -94
  148. package/esm/utils/useHighlight.js +0 -1
  149. package/esm/utils/useRender.d.ts +1 -1
  150. package/package.json +3 -4
  151. package/cjs/comps/CountInfo.d.ts +0 -19
  152. package/cjs/comps/CountInfo.js +0 -72
  153. package/cjs/comps/Ellipsis.d.ts +0 -10
  154. package/cjs/comps/Ellipsis.js +0 -35
  155. package/cjs/comps/Key.d.ts +0 -7
  156. package/cjs/comps/Key.js +0 -39
  157. package/cjs/type.d.ts +0 -50
  158. package/cjs/type.js +0 -57
  159. package/esm/comps/CountInfo.d.ts +0 -19
  160. package/esm/comps/CountInfo.js +0 -70
  161. package/esm/comps/Ellipsis.d.ts +0 -10
  162. package/esm/comps/Ellipsis.js +0 -31
  163. package/esm/comps/Key.d.ts +0 -7
  164. package/esm/comps/Key.js +0 -35
  165. package/esm/type.d.ts +0 -50
  166. package/esm/type.js +0 -50
@@ -4,9 +4,9 @@ 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
8
  import { Container } from '../Container';
9
- import { Quote, Colon } from './ReRender/Symbols';
9
+ import { Quote, Colon } from '../symbol';
10
10
  import { useHighlight } from '../utils/useHighlight';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -36,9 +36,9 @@ export var KeyValues = props => {
36
36
  var [b] = _ref2;
37
37
  return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
38
38
  }) : entries.sort((_ref3, _ref4) => {
39
- var [a] = _ref3;
40
- var [b] = _ref4;
41
- return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
39
+ var [a, valA] = _ref3;
40
+ var [b, valB] = _ref4;
41
+ return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b, valA, valB) : 0;
42
42
  });
43
43
  }
44
44
  var style = {
@@ -64,6 +64,7 @@ KeyValues.displayName = 'JVR.KeyValues';
64
64
  export var KayName = props => {
65
65
  var {
66
66
  keyName,
67
+ parentValue,
67
68
  value
68
69
  } = props;
69
70
  var {
@@ -80,13 +81,16 @@ export var KayName = props => {
80
81
  children: [/*#__PURE__*/_jsxs("span", {
81
82
  ref: highlightContainer,
82
83
  children: [/*#__PURE__*/_jsx(Quote, {
83
- isNumber: isNumber
84
- }), /*#__PURE__*/_jsx(Key, {
84
+ isNumber: isNumber,
85
+ "data-placement": "left"
86
+ }), /*#__PURE__*/_jsx(KeyNameComp, {
85
87
  keyName: keyName,
86
88
  value: value,
89
+ parentValue: parentValue,
87
90
  children: keyName
88
91
  }), /*#__PURE__*/_jsx(Quote, {
89
- isNumber: isNumber
92
+ isNumber: isNumber,
93
+ "data-placement": "right"
90
94
  })]
91
95
  }), /*#__PURE__*/_jsx(Colon, {})]
92
96
  });
@@ -131,7 +135,8 @@ export var KeyValuesItem = props => {
131
135
  }, reset, {
132
136
  children: [/*#__PURE__*/_jsx(KayName, {
133
137
  keyName: keyName,
134
- value: value
138
+ value: value,
139
+ parentValue: parentValue
135
140
  }), /*#__PURE__*/_jsx(Value, {
136
141
  keyName: keyName,
137
142
  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
@@ -30,12 +30,14 @@ 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 './comps/ReRender/Symbols';
33
+ export * from './symbol';
34
34
  export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
35
35
  /** This property contains your input JSON */
36
36
  value?: T;
37
+ /** Define the root node name. @default undefined */
38
+ keyName?: string | number;
37
39
  /** Whether sort keys through `String.prototype.localeCompare()` @default false */
38
- objectSortKeys?: boolean | ((a: string, b: string) => number);
40
+ objectSortKeys?: boolean | ((keyA: string, keyB: string, valueA: T, valueB: T) => number);
39
41
  /** Set the indent-width for nested objects @default 15 */
40
42
  indentWidth?: number;
41
43
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
@@ -48,7 +50,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
48
50
  collapsed?: boolean | number;
49
51
  /** Whether to highlight updates. @default true */
50
52
  highlightUpdates?: boolean;
51
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
53
+ /** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
52
54
  shortenTextAfterLength?: number;
53
55
  /** Callback function for when a treeNode is expanded or collapsed */
54
56
  onExpand?: (props: {
package/esm/index.js CHANGED
@@ -37,7 +37,7 @@ export * from './store/Expands';
37
37
  export * from './store/ShowTools';
38
38
  export * from './store/Symbols';
39
39
  export * from './store/Types';
40
- export * from './comps/ReRender/Symbols';
40
+ export * from './symbol';
41
41
  var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
42
42
  var {
43
43
  className = '',
@@ -47,7 +47,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
47
47
  collapsed,
48
48
  indentWidth = 15,
49
49
  displayObjectSize = true,
50
- shortenTextAfterLength = 20,
50
+ shortenTextAfterLength = 30,
51
51
  highlightUpdates = true,
52
52
  enableClipboard = true,
53
53
  displayDataTypes = true,
@@ -62,7 +62,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
62
62
  backgroundColor: 'var(--w-rjv-background-color, #00000000)',
63
63
  fontSize: 13
64
64
  }, style);
65
- var cls = "w-json-view-container w-rjv " + (className || '');
65
+ var cls = ['w-json-view-container', 'w-rjv', className].filter(Boolean).join(' ');
66
66
  return /*#__PURE__*/_jsxs(Provider, {
67
67
  initialState: {
68
68
  value,
@@ -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
+ };
@@ -1,5 +1,9 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["as", "render"];
1
4
  import { useSectionStore } from '../store/Section';
2
5
  import { useSectionRender } from '../utils/useRender';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
3
7
  export var Ellipsis = props => {
4
8
  var {
5
9
  Ellipsis: Comp = {}
@@ -7,4 +11,30 @@ export var Ellipsis = props => {
7
11
  useSectionRender(Comp, props, 'Ellipsis');
8
12
  return null;
9
13
  };
10
- Ellipsis.displayName = 'JVR.Ellipsis';
14
+ Ellipsis.displayName = 'JVR.Ellipsis';
15
+ export var EllipsisComp = _ref => {
16
+ var {
17
+ isExpanded,
18
+ value,
19
+ keyName
20
+ } = _ref;
21
+ var {
22
+ Ellipsis: Comp = {}
23
+ } = useSectionStore();
24
+ var {
25
+ as,
26
+ render
27
+ } = Comp,
28
+ reset = _objectWithoutPropertiesLoose(Comp, _excluded);
29
+ var Elm = as || 'span';
30
+ var child = render && typeof render === 'function' && render(_extends({}, reset, {
31
+ 'data-expanded': isExpanded
32
+ }), {
33
+ value,
34
+ keyName
35
+ });
36
+ if (child) return child;
37
+ if (!isExpanded) return null;
38
+ return /*#__PURE__*/_jsx(Elm, _extends({}, reset));
39
+ };
40
+ EllipsisComp.displayName = 'JVR.EllipsisComp';
@@ -1,6 +1,14 @@
1
+ import { type FC, type PropsWithChildren } from 'react';
1
2
  import { type TagType } from '../store/Types';
2
3
  import { type SectionElement } from '../store/Section';
3
4
  export declare const KeyName: {
4
5
  <K extends TagType>(props: SectionElement<K>): null;
5
6
  displayName: string;
6
7
  };
8
+ type KeyNameCompProps = {
9
+ keyName: string | number;
10
+ value?: unknown;
11
+ parentValue?: unknown;
12
+ };
13
+ export declare const KeyNameComp: FC<PropsWithChildren<KeyNameCompProps>>;
14
+ export {};
@@ -1,5 +1,9 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["as", "render"];
1
4
  import { useSectionStore } from '../store/Section';
2
5
  import { useSectionRender } from '../utils/useRender';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
3
7
  export var KeyName = props => {
4
8
  var {
5
9
  KeyName: Comp = {}
@@ -7,4 +11,38 @@ export var KeyName = props => {
7
11
  useSectionRender(Comp, props, 'KeyName');
8
12
  return null;
9
13
  };
10
- KeyName.displayName = 'JVR.KeyName';
14
+ KeyName.displayName = 'JVR.KeyName';
15
+ export var KeyNameComp = props => {
16
+ var {
17
+ children,
18
+ value,
19
+ parentValue,
20
+ keyName
21
+ } = props;
22
+ var isNumber = typeof children === 'number';
23
+ var style = {
24
+ color: isNumber ? 'var(--w-rjv-key-number, #268bd2)' : 'var(--w-rjv-key-string, #002b36)'
25
+ };
26
+ var {
27
+ KeyName: Comp = {}
28
+ } = useSectionStore();
29
+ var {
30
+ as,
31
+ render
32
+ } = Comp,
33
+ reset = _objectWithoutPropertiesLoose(Comp, _excluded);
34
+ reset.style = _extends({}, reset.style, style);
35
+ var Elm = as || 'span';
36
+ var child = render && typeof render === 'function' && render(_extends({}, reset, {
37
+ children
38
+ }), {
39
+ value,
40
+ parentValue,
41
+ keyName
42
+ });
43
+ if (child) return child;
44
+ return /*#__PURE__*/_jsx(Elm, _extends({}, reset, {
45
+ children: children
46
+ }));
47
+ };
48
+ KeyNameComp.displayName = 'JVR.KeyNameComp';
@@ -1,13 +1,14 @@
1
1
  import React, { FC, PropsWithChildren, ComponentPropsWithoutRef } from 'react';
2
2
  import { type TagType } from './Types';
3
- export type SectionElementProps<T extends TagType> = {
3
+ export type SectionElementProps<T extends TagType = 'span'> = {
4
4
  as?: T;
5
5
  render?: (props: SectionElement<T>, result: {
6
6
  value: unknown;
7
+ parentValue?: unknown;
7
8
  keyName: string | number;
8
9
  }) => React.ReactNode;
9
10
  };
10
- export type SectionElement<T extends TagType> = SectionElementProps<T> & ComponentPropsWithoutRef<T>;
11
+ export type SectionElement<T extends TagType = 'span'> = SectionElementProps<T> & ComponentPropsWithoutRef<T>;
11
12
  type InitialState<T extends TagType> = {
12
13
  Copied?: SectionElement<T>;
13
14
  CountInfo?: SectionElement<T>;
@@ -1,11 +1,11 @@
1
1
  import { FC, PropsWithChildren, ElementType, ComponentPropsWithoutRef } from 'react';
2
2
  import { type TagType } from './Types';
3
- type SymbolsElementProps<T extends TagType> = {
3
+ type SymbolsElementProps<T extends TagType = 'span'> = {
4
4
  as?: T;
5
5
  render?: (props: SymbolsElement<T>) => React.ReactNode;
6
6
  'data-type'?: string;
7
7
  };
8
- export type SymbolsElement<T extends TagType> = SymbolsElementProps<T> & ComponentPropsWithoutRef<T>;
8
+ export type SymbolsElement<T extends TagType = 'span'> = SymbolsElementProps<T> & ComponentPropsWithoutRef<T>;
9
9
  type InitialState<T extends ElementType = 'span'> = {
10
10
  Arrow?: SymbolsElement<T>;
11
11
  Colon?: SymbolsElement<T>;