@uiw/react-json-view 2.0.0-alpha.3 → 2.0.0-alpha.30

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 (197) hide show
  1. package/README.md +217 -26
  2. package/basic.d.ts +3 -0
  3. package/cjs/Container.d.ts +2 -0
  4. package/cjs/Container.js +13 -6
  5. package/cjs/arrow/TriangleArrow.js +1 -1
  6. package/cjs/comps/Copied.d.ts +2 -4
  7. package/cjs/comps/Copied.js +50 -17
  8. package/cjs/comps/KeyValues.d.ts +2 -4
  9. package/cjs/comps/KeyValues.js +62 -27
  10. package/cjs/comps/NestedClose.d.ts +1 -0
  11. package/cjs/comps/NestedClose.js +15 -5
  12. package/cjs/comps/NestedOpen.d.ts +2 -3
  13. package/cjs/comps/NestedOpen.js +34 -14
  14. package/cjs/comps/Value.d.ts +1 -2
  15. package/cjs/comps/Value.js +4 -8
  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 +10 -3
  25. package/cjs/index.js +9 -4
  26. package/cjs/section/Copied.d.ts +1 -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 +29 -25
  45. package/cjs/store/Types.js +8 -8
  46. package/cjs/store.d.ts +8 -4
  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 +11 -16
  65. package/cjs/symbol/index.js +75 -30
  66. package/cjs/theme/basic.d.ts +1 -2
  67. package/cjs/theme/basic.js +4 -3
  68. package/cjs/theme/dark.d.ts +1 -2
  69. package/cjs/theme/dark.js +2 -3
  70. package/cjs/theme/github.dark.d.ts +1 -2
  71. package/cjs/theme/github.dark.js +2 -3
  72. package/cjs/theme/github.light.d.ts +1 -2
  73. package/cjs/theme/github.light.js +2 -3
  74. package/cjs/theme/gruvbox.d.ts +1 -2
  75. package/cjs/theme/gruvbox.js +2 -3
  76. package/cjs/theme/light.d.ts +1 -2
  77. package/cjs/theme/light.js +2 -3
  78. package/cjs/theme/monokai.d.ts +1 -2
  79. package/cjs/theme/monokai.js +2 -3
  80. package/cjs/theme/nord.d.ts +1 -2
  81. package/cjs/theme/nord.js +2 -3
  82. package/cjs/theme/vscode.d.ts +1 -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 +3 -1
  111. package/cjs/types/index.js +96 -124
  112. package/cjs/utils/useHighlight.d.ts +0 -1
  113. package/cjs/utils/useRender.d.ts +1 -1
  114. package/editor.d.ts +22 -20
  115. package/esm/Container.d.ts +2 -0
  116. package/esm/Container.js +15 -7
  117. package/esm/arrow/TriangleArrow.js +1 -1
  118. package/esm/comps/Copied.d.ts +2 -4
  119. package/esm/comps/Copied.js +48 -16
  120. package/esm/comps/KeyValues.d.ts +2 -4
  121. package/esm/comps/KeyValues.js +53 -21
  122. package/esm/comps/NestedClose.d.ts +1 -0
  123. package/esm/comps/NestedClose.js +13 -3
  124. package/esm/comps/NestedOpen.d.ts +2 -3
  125. package/esm/comps/NestedOpen.js +33 -14
  126. package/esm/comps/Value.d.ts +1 -2
  127. package/esm/comps/Value.js +2 -4
  128. package/esm/comps/useIdCompat.d.ts +1 -0
  129. package/esm/comps/useIdCompat.js +8 -0
  130. package/esm/editor/KeyName.d.ts +2 -0
  131. package/esm/editor/KeyName.js +77 -0
  132. package/esm/editor/index.d.ts +18 -0
  133. package/esm/editor/index.js +33 -0
  134. package/esm/editor/store.d.ts +27 -0
  135. package/esm/editor/store.js +13 -0
  136. package/esm/index.d.ts +10 -3
  137. package/esm/index.js +10 -5
  138. package/esm/section/Copied.d.ts +1 -1
  139. package/esm/section/CountInfo.d.ts +1 -2
  140. package/esm/section/CountInfo.js +1 -1
  141. package/esm/section/CountInfoExtra.d.ts +1 -2
  142. package/esm/section/Ellipsis.d.ts +0 -1
  143. package/esm/section/Ellipsis.js +1 -1
  144. package/esm/section/KeyName.d.ts +7 -6
  145. package/esm/section/KeyName.js +6 -2
  146. package/esm/section/Row.d.ts +13 -0
  147. package/esm/section/Row.js +47 -0
  148. package/esm/store/Section.d.ts +12 -6
  149. package/esm/store/Section.js +4 -0
  150. package/esm/store/Symbols.d.ts +10 -3
  151. package/esm/store/Types.d.ts +29 -25
  152. package/esm/store/Types.js +6 -4
  153. package/esm/store.d.ts +8 -4
  154. package/esm/symbol/Arrow.d.ts +1 -1
  155. package/esm/symbol/BraceLeft.d.ts +1 -1
  156. package/esm/symbol/BraceRight.d.ts +1 -1
  157. package/esm/symbol/BracketsLeft.d.ts +1 -1
  158. package/esm/symbol/BracketsRight.d.ts +1 -1
  159. package/esm/symbol/Colon.d.ts +1 -1
  160. package/esm/symbol/Quote.d.ts +1 -1
  161. package/esm/symbol/ValueQuote.d.ts +1 -1
  162. package/esm/symbol/index.d.ts +11 -16
  163. package/esm/symbol/index.js +76 -23
  164. package/esm/theme/basic.d.ts +1 -2
  165. package/esm/theme/basic.js +2 -0
  166. package/esm/theme/dark.d.ts +1 -2
  167. package/esm/theme/github.dark.d.ts +1 -2
  168. package/esm/theme/github.light.d.ts +1 -2
  169. package/esm/theme/gruvbox.d.ts +1 -2
  170. package/esm/theme/light.d.ts +1 -2
  171. package/esm/theme/monokai.d.ts +1 -2
  172. package/esm/theme/nord.d.ts +1 -2
  173. package/esm/theme/vscode.d.ts +1 -2
  174. package/esm/types/Bigint.d.ts +1 -1
  175. package/esm/types/Date.d.ts +1 -1
  176. package/esm/types/False.d.ts +1 -1
  177. package/esm/types/Float.d.ts +1 -1
  178. package/esm/types/Int.d.ts +1 -1
  179. package/esm/types/Map.d.ts +1 -1
  180. package/esm/types/Nan.d.ts +1 -1
  181. package/esm/types/Null.d.ts +1 -1
  182. package/esm/types/Set.d.ts +1 -1
  183. package/esm/types/String.d.ts +1 -1
  184. package/esm/types/True.d.ts +1 -1
  185. package/esm/types/Undefined.d.ts +1 -1
  186. package/esm/types/Url.d.ts +1 -1
  187. package/esm/types/index.d.ts +3 -1
  188. package/esm/types/index.js +82 -100
  189. package/esm/utils/useHighlight.d.ts +0 -1
  190. package/esm/utils/useRender.d.ts +1 -1
  191. package/githubDark.d.ts +3 -0
  192. package/githubLight.d.ts +3 -0
  193. package/gruvbox.d.ts +3 -0
  194. package/monokai.d.ts +3 -0
  195. package/nord.d.ts +3 -0
  196. package/package.json +11 -5
  197. package/vscode.d.ts +3 -0
@@ -13,7 +13,7 @@ export function TriangleArrow(props) {
13
13
  height: '1em',
14
14
  width: '1em',
15
15
  userSelect: 'none',
16
- display: 'flex'
16
+ display: 'inline-flex'
17
17
  }, style);
18
18
  return /*#__PURE__*/_jsx("svg", _extends({
19
19
  viewBox: "0 0 24 24",
@@ -1,13 +1,11 @@
1
- /// <reference types="react" />
1
+ import { type SectionElementResult } from '../store/Section';
2
2
  import { type TagType } from '../store/Types';
3
3
  export type CopiedOption<T extends object> = {
4
4
  value?: T;
5
5
  copied: boolean;
6
6
  setCopied: React.Dispatch<React.SetStateAction<boolean>>;
7
7
  };
8
- export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement> {
9
- value?: T;
10
- keyName: string | number;
8
+ export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement>, SectionElementResult<T> {
11
9
  expandKey: string;
12
10
  }
13
11
  export declare const Copied: {
@@ -1,17 +1,20 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["keyName", "value", "expandKey"],
3
+ var _excluded = ["keyName", "value", "parentValue", "expandKey", "keys"],
4
4
  _excluded2 = ["as", "render"];
5
5
  import { useState } from 'react';
6
6
  import { useStore } from '../store';
7
- import { useShowToolsStore } from '../store/ShowTools';
8
7
  import { useSectionStore } from '../store/Section';
8
+ import { useShowToolsStore } from '../store/ShowTools';
9
+ import { bigIntToString } from '../types';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
11
  export var Copied = props => {
11
12
  var {
12
13
  keyName,
13
14
  value,
14
- expandKey
15
+ parentValue,
16
+ expandKey,
17
+ keys
15
18
  } = props,
16
19
  other = _objectWithoutPropertiesLoose(props, _excluded);
17
20
  var {
@@ -27,18 +30,40 @@ export var Copied = props => {
27
30
  if (enableClipboard === false || !isShowTools) return null;
28
31
  var click = event => {
29
32
  event.stopPropagation();
30
- var copyText = JSON.stringify(value, (key, value) => {
31
- if (typeof value === 'bigint') {
32
- return value.toString();
33
+ var copyText = '';
34
+ if (typeof value === 'number' && value === Infinity) {
35
+ copyText = 'Infinity';
36
+ } else if (typeof value === 'number' && isNaN(value)) {
37
+ copyText = 'NaN';
38
+ } else if (typeof value === 'bigint') {
39
+ copyText = bigIntToString(value);
40
+ } else if (value instanceof Date) {
41
+ copyText = value.toLocaleString();
42
+ } else {
43
+ copyText = JSON.stringify(value, (_, v) => typeof v === 'bigint' ? bigIntToString(v) : v, 2);
44
+ }
45
+ onCopied && onCopied(copyText, value);
46
+ setCopied(true);
47
+ var _clipboard = navigator.clipboard || {
48
+ writeText(text) {
49
+ return new Promise((reslove, reject) => {
50
+ var textarea = document.createElement('textarea');
51
+ textarea.style.position = 'absolute';
52
+ textarea.style.opacity = '0';
53
+ textarea.style.left = '-99999999px';
54
+ textarea.value = text;
55
+ document.body.appendChild(textarea);
56
+ textarea.select();
57
+ if (!document.execCommand('copy')) {
58
+ reject();
59
+ } else {
60
+ reslove();
61
+ }
62
+ textarea.remove();
63
+ });
33
64
  }
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';
39
- navigator.clipboard.writeText(copyText).then(() => {
40
- onCopied && onCopied(copyText, value);
41
- setCopied(true);
65
+ };
66
+ _clipboard.writeText(copyText).then(() => {
42
67
  var timer = setTimeout(() => {
43
68
  setCopied(false);
44
69
  clearTimeout(timer);
@@ -46,6 +71,9 @@ export var Copied = props => {
46
71
  }).catch(error => {});
47
72
  };
48
73
  var svgProps = {
74
+ style: {
75
+ display: 'inline-flex'
76
+ },
49
77
  fill: copied ? 'var(--w-rjv-copied-success-color, #28a745)' : 'var(--w-rjv-copied-color, currentColor)',
50
78
  onClick: click
51
79
  };
@@ -53,13 +81,17 @@ export var Copied = props => {
53
81
  render
54
82
  } = Comp,
55
83
  reset = _objectWithoutPropertiesLoose(Comp, _excluded2);
56
- var elmProps = _extends({}, reset, other, svgProps);
84
+ var elmProps = _extends({}, reset, other, svgProps, {
85
+ style: _extends({}, reset.style, other.style, svgProps.style)
86
+ });
57
87
  var isRender = render && typeof render === 'function';
58
88
  var child = isRender && render(_extends({}, elmProps, {
59
89
  'data-copied': copied
60
90
  }), {
61
91
  value,
62
- keyName
92
+ keyName,
93
+ keys,
94
+ parentValue
63
95
  });
64
96
  if (child) return child;
65
97
  if (copied) {
@@ -1,7 +1,5 @@
1
- interface KeyValuesProps<T extends object> {
2
- keyName?: string | number;
3
- value?: T;
4
- parentValue?: T;
1
+ import { type SectionElementResult } from '../store/Section';
2
+ interface KeyValuesProps<T extends object> extends SectionElementResult<T> {
5
3
  expandKey?: string;
6
4
  level: number;
7
5
  }
@@ -1,30 +1,42 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import { Fragment, useId, useRef } from 'react';
2
+ import { Fragment, useRef } from 'react';
3
3
  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
7
  import { KeyNameComp } from '../section/KeyName';
8
+ import { RowComp } from '../section/Row';
8
9
  import { Container } from '../Container';
9
10
  import { Quote, Colon } from '../symbol';
10
11
  import { useHighlight } from '../utils/useHighlight';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ import { Copied } from '../comps/Copied';
13
+ import { useIdCompat } from '../comps/useIdCompat';
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
15
  export var KeyValues = props => {
14
16
  var _expands$expandKey;
15
17
  var {
16
18
  value,
17
19
  expandKey = '',
18
- level
20
+ level,
21
+ keys = []
19
22
  } = props;
20
23
  var expands = useExpandsStore();
21
24
  var {
22
25
  objectSortKeys,
23
26
  indentWidth,
24
- collapsed
27
+ collapsed,
28
+ shouldExpandNodeInitially
25
29
  } = useStore();
26
30
  var isMyArray = Array.isArray(value);
27
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
31
+ var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
32
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
33
+ if (expands[expandKey] === undefined && shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
34
+ value,
35
+ keys,
36
+ level
37
+ })) {
38
+ return null;
39
+ }
28
40
  if (isExpanded) {
29
41
  return null;
30
42
  }
@@ -36,9 +48,9 @@ export var KeyValues = props => {
36
48
  var [b] = _ref2;
37
49
  return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
38
50
  }) : entries.sort((_ref3, _ref4) => {
39
- var [a] = _ref3;
40
- var [b] = _ref4;
41
- return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
51
+ var [a, valA] = _ref3;
52
+ var [b, valB] = _ref4;
53
+ return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b, valA, valB) : 0;
42
54
  });
43
55
  }
44
56
  var style = {
@@ -54,6 +66,7 @@ export var KeyValues = props => {
54
66
  return /*#__PURE__*/_jsx(KeyValuesItem, {
55
67
  parentValue: value,
56
68
  keyName: key,
69
+ keys: [...keys, key],
57
70
  value: val,
58
71
  level: level
59
72
  }, idx);
@@ -64,6 +77,8 @@ KeyValues.displayName = 'JVR.KeyValues';
64
77
  export var KayName = props => {
65
78
  var {
66
79
  keyName,
80
+ parentValue,
81
+ keys,
67
82
  value
68
83
  } = props;
69
84
  var {
@@ -76,21 +91,25 @@ export var KayName = props => {
76
91
  highlightUpdates,
77
92
  highlightContainer
78
93
  });
94
+ var compProps = {
95
+ keyName,
96
+ value,
97
+ keys,
98
+ parentValue
99
+ };
79
100
  return /*#__PURE__*/_jsxs(Fragment, {
80
101
  children: [/*#__PURE__*/_jsxs("span", {
81
102
  ref: highlightContainer,
82
- children: [/*#__PURE__*/_jsx(Quote, {
103
+ children: [/*#__PURE__*/_jsx(Quote, _extends({
83
104
  isNumber: isNumber,
84
105
  "data-placement": "left"
85
- }), /*#__PURE__*/_jsx(KeyNameComp, {
86
- keyName: keyName,
87
- value: value,
106
+ }, compProps)), /*#__PURE__*/_jsx(KeyNameComp, _extends({}, compProps, {
88
107
  children: keyName
89
- }), /*#__PURE__*/_jsx(Quote, {
108
+ })), /*#__PURE__*/_jsx(Quote, _extends({
90
109
  isNumber: isNumber,
91
110
  "data-placement": "right"
92
- })]
93
- }), /*#__PURE__*/_jsx(Colon, {})]
111
+ }, compProps))]
112
+ }), /*#__PURE__*/_jsx(Colon, _extends({}, compProps))]
94
113
  });
95
114
  };
96
115
  KayName.displayName = 'JVR.KayName';
@@ -99,10 +118,11 @@ export var KeyValuesItem = props => {
99
118
  keyName,
100
119
  value,
101
120
  parentValue,
102
- level = 0
121
+ level = 0,
122
+ keys = []
103
123
  } = props;
104
124
  var dispatch = useShowToolsDispatch();
105
- var subkeyid = useId();
125
+ var subkeyid = useIdCompat();
106
126
  var isMyArray = Array.isArray(value);
107
127
  var isMySet = value instanceof Set;
108
128
  var isMyMap = value instanceof Map;
@@ -117,6 +137,7 @@ export var KeyValuesItem = props => {
117
137
  value: myValue,
118
138
  parentValue: parentValue,
119
139
  initialValue: value,
140
+ keys: keys,
120
141
  level: level + 1
121
142
  });
122
143
  }
@@ -128,15 +149,26 @@ export var KeyValuesItem = props => {
128
149
  [subkeyid]: false
129
150
  })
130
151
  };
131
- return /*#__PURE__*/_jsxs("div", _extends({
132
- className: "w-rjv-line"
152
+ return /*#__PURE__*/_jsxs(RowComp, _extends({
153
+ className: "w-rjv-line",
154
+ value: value,
155
+ keyName: keyName,
156
+ keys: keys,
157
+ parentValue: parentValue
133
158
  }, reset, {
134
159
  children: [/*#__PURE__*/_jsx(KayName, {
135
160
  keyName: keyName,
136
- value: value
161
+ value: value,
162
+ keys: keys,
163
+ parentValue: parentValue
137
164
  }), /*#__PURE__*/_jsx(Value, {
165
+ keyName: keyName,
166
+ value: value
167
+ }), /*#__PURE__*/_jsx(Copied, {
138
168
  keyName: keyName,
139
169
  value: value,
170
+ keys: keys,
171
+ parentValue: parentValue,
140
172
  expandKey: subkeyid
141
173
  })]
142
174
  }));
@@ -2,6 +2,7 @@ interface NestedCloseProps<T extends object> {
2
2
  value?: T;
3
3
  expandKey: string;
4
4
  level: number;
5
+ keys?: (string | number)[];
5
6
  }
6
7
  export declare const NestedClose: {
7
8
  <T extends object>(props: NestedCloseProps<T>): import("react/jsx-runtime").JSX.Element | null;
@@ -7,16 +7,26 @@ export var NestedClose = props => {
7
7
  var {
8
8
  value,
9
9
  expandKey,
10
- level
10
+ level,
11
+ keys = []
11
12
  } = props;
12
13
  var expands = useExpandsStore();
13
14
  var isArray = Array.isArray(value);
14
15
  var {
15
- collapsed
16
+ collapsed,
17
+ shouldExpandNodeInitially
16
18
  } = useStore();
17
19
  var isMySet = value instanceof Set;
18
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
20
+ var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
21
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
19
22
  var len = Object.keys(value).length;
23
+ if (expands[expandKey] === undefined && shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
24
+ value,
25
+ keys,
26
+ level
27
+ })) {
28
+ return null;
29
+ }
20
30
  if (isExpanded || len === 0) {
21
31
  return null;
22
32
  }
@@ -1,6 +1,5 @@
1
- export interface NestedOpenProps<T extends object> {
2
- keyName?: string | number;
3
- value?: T;
1
+ import { type SectionElementResult } from '../store/Section';
2
+ export interface NestedOpenProps<T extends object> extends SectionElementResult<T> {
4
3
  initialValue?: T;
5
4
  expandKey: string;
6
5
  level: number;
@@ -8,27 +8,38 @@ import { CountInfoComp } from '../section/CountInfo';
8
8
  import { Arrow, BracketsOpen, BracketsClose } from '../symbol';
9
9
  import { EllipsisComp } from '../section/Ellipsis';
10
10
  import { SetComp, MapComp } from '../types';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- import { jsxs as _jsxs } from "react/jsx-runtime";
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
30
  var isArray = Array.isArray(value);
29
31
  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;
32
+ var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
31
33
  var isObject = typeof value === 'object';
34
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
35
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
36
+ value,
37
+ keys,
38
+ level
39
+ });
40
+ if (expands[expandKey] === undefined && shouldExpand !== undefined) {
41
+ isExpanded = shouldExpand;
42
+ }
32
43
  var click = () => {
33
44
  var opt = {
34
45
  expand: !isExpanded,
@@ -57,26 +68,32 @@ export var NestedOpen = props => {
57
68
  if (showArrow) {
58
69
  reset.onClick = click;
59
70
  }
71
+ var compProps = {
72
+ keyName,
73
+ value,
74
+ keys,
75
+ parentValue
76
+ };
60
77
  return /*#__PURE__*/_jsxs("span", _extends({}, reset, {
61
- children: [showArrow && /*#__PURE__*/_jsx(Arrow, {
78
+ children: [showArrow && /*#__PURE__*/_jsx(Arrow, _extends({
62
79
  style: arrowStyle,
63
80
  expandKey: expandKey
64
- }), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, {
81
+ }, compProps)), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, _extends({}, compProps)), /*#__PURE__*/_jsx(SetComp, {
82
+ value: initialValue,
65
83
  keyName: keyName
66
- }), /*#__PURE__*/_jsx(SetComp, {
67
- value: initialValue
68
84
  }), /*#__PURE__*/_jsx(MapComp, {
69
- value: initialValue
70
- }), /*#__PURE__*/_jsx(BracketsOpen, {
85
+ value: initialValue,
86
+ keyName: keyName
87
+ }), /*#__PURE__*/_jsx(BracketsOpen, _extends({
71
88
  isBrackets: isArray || isMySet
72
- }), /*#__PURE__*/_jsx(EllipsisComp, {
89
+ }, compProps)), /*#__PURE__*/_jsx(EllipsisComp, {
73
90
  keyName: keyName,
74
91
  value: value,
75
92
  isExpanded: isExpanded
76
- }), /*#__PURE__*/_jsx(BracketsClose, {
93
+ }), /*#__PURE__*/_jsx(BracketsClose, _extends({
77
94
  isVisiable: isExpanded || !showArrow,
78
95
  isBrackets: isArray || isMySet
79
- }), /*#__PURE__*/_jsx(CountInfoComp, {
96
+ }, compProps)), /*#__PURE__*/_jsx(CountInfoComp, {
80
97
  value: value,
81
98
  keyName: keyName
82
99
  }), /*#__PURE__*/_jsx(CountInfoExtraComps, {
@@ -85,7 +102,9 @@ export var NestedOpen = props => {
85
102
  }), /*#__PURE__*/_jsx(Copied, {
86
103
  keyName: keyName,
87
104
  value: value,
88
- expandKey: expandKey
105
+ expandKey: expandKey,
106
+ parentValue: parentValue,
107
+ keys: keys
89
108
  })]
90
109
  }));
91
110
  };
@@ -1,8 +1,7 @@
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;
6
5
  }
7
6
  export declare const Value: {
8
7
  (props: ValueProps): import("react/jsx-runtime").JSX.Element | null;
@@ -5,12 +5,10 @@ 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
- keyName,
9
- expandKey
8
+ keyName
10
9
  } = props;
11
10
  var reset = {
12
- keyName,
13
- expandKey
11
+ keyName
14
12
  };
15
13
  if (value instanceof URL) {
16
14
  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';
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 '../';
6
+ import { KeyNameRender } from './KeyName';
7
+ import { Context, Dispatch, useStoreReducer } from './store';
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
+ }