@uiw/react-json-view 2.0.0-alpha.37 → 2.0.0-alpha.39

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.
package/README.md CHANGED
@@ -1,32 +1,33 @@
1
1
  <div markdown="1">
2
2
  <sup>Using <a href="https://wangchujiang.com/#/app" target="_blank">my app</a> is also a way to <a href="https://wangchujiang.com/#/sponsor" target="_blank">support</a> me:</sup>
3
3
  <br>
4
- <a target="_blank" href="https://apps.apple.com/app/Vidwall/6747587746" title="Vidwall for macOS"><img align="center" alt="Vidwall" height="52" width="52" src="https://github.com/user-attachments/assets/7b5df70a-ed91-4d4b-85be-f00e60a09ce9"></a>
5
- <a target="_blank" href="https://wangchujiang.com/mousio-hint/" title="Mousio Hint for macOS"><img align="center" alt="Mousio Hint" height="52" width="52" src="https://github.com/user-attachments/assets/3c0af128-0cef-44e5-a8db-4741dc5a6690"></a>
6
- <a target="_blank" href="https://apps.apple.com/app/6746747327" title="Mousio for macOS"><img align="center" alt="Mousio" height="52" width="52" src="https://github.com/user-attachments/assets/9edf61ff-5a6c-4676-9cc2-8fd3c1ad0dfb"></a>
7
- <a target="_blank" href="https://apps.apple.com/app/6745227444" title="Musicer for macOS"><img align="center" alt="Musicer" height="52" width="52" src="https://github.com/user-attachments/assets/b7abfba8-88ff-4c86-a125-43073d5aef22"></a>
8
- <a target="_blank" href="https://apps.apple.com/app/6743841447" title="Audioer for macOS"><img align="center" alt="Audioer" height="52" width="52" src="https://github.com/user-attachments/assets/7a836865-8c90-4119-87bc-19e06a76c957"></a>
9
- <a target="_blank" href="https://apps.apple.com/app/6744690194" title="FileSentinel for macOS"><img align="center" alt="FileSentinel" height="52" width="52" src="https://github.com/user-attachments/assets/28bce2cc-290e-45bf-9068-585ff6ecafe9"></a>
10
- <a target="_blank" href="https://apps.apple.com/app/6743495172" title="FocusCursor for macOS"><img align="center" alt="FocusCursor" height="52" width="52" src="https://github.com/user-attachments/assets/d543668a-737b-4853-a6bb-eaa269e69836"></a>
11
- <a target="_blank" href="https://apps.apple.com/app/6742680573" title="Videoer for macOS"><img align="center" alt="Videoer" height="52" width="52" src="https://github.com/user-attachments/assets/10ffb0f1-0625-40d6-93f1-2c2496592595"></a>
12
- <a target="_blank" href="https://apps.apple.com/app/6740425504" title="KeyClicker for macOS"><img align="center" alt="KeyClicker" height="52" width="52" src="https://github.com/user-attachments/assets/5a19fcb9-cb81-4855-b4ea-31c604d9612a"></a>
13
- <a target="_blank" href="https://apps.apple.com/app/6739052447" title="DayBar for macOS"><img align="center" alt="DayBar" height="52" width="52" src="https://github.com/user-attachments/assets/771b608d-594c-492d-8532-d9231e383f5b"></a>
14
- <a target="_blank" href="https://apps.apple.com/app/6739444407" title="Iconed for macOS"><img align="center" alt="Iconed" height="52" width="52" src="https://github.com/user-attachments/assets/8a35dc7b-4faf-4e2a-9311-f66d6844a896"></a>
15
- <a target="_blank" href="https://apps.apple.com/app/6737160756" title="RightMenu Master for macOS"><img align="center" alt="RightMenu Master" height="52" width="52" src="https://github.com/user-attachments/assets/39a76541-71bf-4de7-a01c-c62f0557dff5"></a>
16
- <a target="_blank" href="https://apps.apple.com/app/6723903021" title="Paste Quick for macOS"><img align="center" alt="Quick RSS" height="52" width="52" src="https://github.com/user-attachments/assets/bdaad5b7-9810-44ce-8f17-8410864465d2"></a>
17
- <a target="_blank" href="https://apps.apple.com/app/6670696072" title="Quick RSS for macOS/iOS"><img align="center" alt="Quick RSS" height="52" width="52" src="https://github.com/user-attachments/assets/374106b5-a448-4d1d-9ccb-b04b6bc681ed"></a>
18
- <a target="_blank" href="https://apps.apple.com/app/6670167443" title="Web Serve for macOS"><img align="center" alt="Web Serve" height="52" width="52" src="https://github.com/user-attachments/assets/e1d9f76f-0f3d-4ba5-8a15-253ee173bb1c"></a>
19
- <a target="_blank" href="https://apps.apple.com/app/6503953628" title="Copybook Generator for macOS/iOS"><img align="center" alt="Copybook Generator" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/b90e42ff-158b-4534-82ca-5898fd0e8d73"></a>
20
- <a target="_blank" href="https://apps.apple.com/app/6471227008" title="DevTutor for macOS/iOS"><img align="center" alt="DevTutor for SwiftUI" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/f15c154d-0192-48eb-8e0e-9e245ffd974a"></a>
21
- <a target="_blank" href="https://apps.apple.com/app/6479819388" title="RegexMate for macOS/iOS"><img align="center" alt="RegexMate" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/aabe5aa9-9a96-4390-8bed-c3e4023d0dea"></a>
22
- <a target="_blank" href="https://apps.apple.com/app/6479194014" title="Time Passage for macOS/iOS"><img align="center" alt="Time Passage" height="52" width="52" src="https://github.com/jaywcjlove/time-passage/assets/1680273/6f30e429-e6f3-4dbe-9921-a5effe2a05e9"></a>
23
- <a target="_blank" href="https://apps.apple.com/app/6478772538" title="IconizeFolder for macOS"><img align="center" alt="Iconize Folder" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/fa9d8b9c-1e51-4ded-877c-fa5b21c47220"></a>
24
- <a target="_blank" href="https://apps.apple.com/app/6478511402" title="Textsound Saver for macOS/iOS"><img align="center" alt="Textsound Saver" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/0595e842-980b-4574-8891-a8ba853a08be"></a>
25
- <a target="_blank" href="https://apps.apple.com/app/6476924627" title="Create Custom Symbols for macOS"><img align="center" alt="Create Custom Symbols" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/8cd022ce-a3f1-4e89-b7c6-6fbd0d4db77c"></a>
26
- <a target="_blank" href="https://apps.apple.com/app/6476452351" title="DevHub for macOS"><img align="center" alt="DevHub" height="52" width="52" src="https://github.com/user-attachments/assets/4a44a4fd-67ce-430b-af0a-72f18feaa47d"></a>
27
- <a target="_blank" href="https://apps.apple.com/app/6476400184" title="Resume Revise for macOS"><img align="center" alt="Resume Revise" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c9954a20-1905-48de-bdf8-d71837974aa2"></a>
28
- <a target="_blank" href="https://apps.apple.com/app/6472593276" title="Palette Genius for macOS"><img align="center" alt="Palette Genius" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/27340413-d355-45b2-8f6f-6ac37682d957"></a>
29
- <a target="_blank" href="https://apps.apple.com/app/6470879005" title="Symbol Scribe for macOS"><img align="center" alt="Symbol Scribe" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c7249f05-fa70-4def-a1e9-571d5f171fc9"></a>
4
+ <a target="_blank" href="https://apps.apple.com/app/VidCrop/6752624705" title="VidCrop for macOS"><img align="center" alt="VidCrop" height="52" width="52" src="https://github.com/user-attachments/assets/91d2b281-271a-4107-9ef6-f3b11bd6dbac"></a>
5
+ <a target="_blank" href="https://apps.apple.com/app/Vidwall/6747587746" title="Vidwall for macOS"><img align="center" alt="Vidwall" height="52" width="52" src="https://github.com/user-attachments/assets/7b5df70a-ed91-4d4b-85be-f00e60a09ce9"></a>
6
+ <a target="_blank" href="https://wangchujiang.com/mousio-hint/" title="Mousio Hint for macOS"><img align="center" alt="Mousio Hint" height="52" width="52" src="https://github.com/user-attachments/assets/3c0af128-0cef-44e5-a8db-4741dc5a6690"></a>
7
+ <a target="_blank" href="https://apps.apple.com/app/6746747327" title="Mousio for macOS"><img align="center" alt="Mousio" height="52" width="52" src="https://github.com/user-attachments/assets/9edf61ff-5a6c-4676-9cc2-8fd3c1ad0dfb"></a>
8
+ <a target="_blank" href="https://apps.apple.com/app/6745227444" title="Musicer for macOS"><img align="center" alt="Musicer" height="52" width="52" src="https://github.com/user-attachments/assets/b7abfba8-88ff-4c86-a125-43073d5aef22"></a>
9
+ <a target="_blank" href="https://apps.apple.com/app/6743841447" title="Audioer for macOS"><img align="center" alt="Audioer" height="52" width="52" src="https://github.com/user-attachments/assets/7a836865-8c90-4119-87bc-19e06a76c957"></a>
10
+ <a target="_blank" href="https://apps.apple.com/app/6744690194" title="FileSentinel for macOS"><img align="center" alt="FileSentinel" height="52" width="52" src="https://github.com/user-attachments/assets/28bce2cc-290e-45bf-9068-585ff6ecafe9"></a>
11
+ <a target="_blank" href="https://apps.apple.com/app/6743495172" title="FocusCursor for macOS"><img align="center" alt="FocusCursor" height="52" width="52" src="https://github.com/user-attachments/assets/d543668a-737b-4853-a6bb-eaa269e69836"></a>
12
+ <a target="_blank" href="https://apps.apple.com/app/6742680573" title="Videoer for macOS"><img align="center" alt="Videoer" height="52" width="52" src="https://github.com/user-attachments/assets/10ffb0f1-0625-40d6-93f1-2c2496592595"></a>
13
+ <a target="_blank" href="https://apps.apple.com/app/6740425504" title="KeyClicker for macOS"><img align="center" alt="KeyClicker" height="52" width="52" src="https://github.com/user-attachments/assets/5a19fcb9-cb81-4855-b4ea-31c604d9612a"></a>
14
+ <a target="_blank" href="https://apps.apple.com/app/6739052447" title="DayBar for macOS"><img align="center" alt="DayBar" height="52" width="52" src="https://github.com/user-attachments/assets/771b608d-594c-492d-8532-d9231e383f5b"></a>
15
+ <a target="_blank" href="https://apps.apple.com/app/6739444407" title="Iconed for macOS"><img align="center" alt="Iconed" height="52" width="52" src="https://github.com/user-attachments/assets/8a35dc7b-4faf-4e2a-9311-f66d6844a896"></a>
16
+ <a target="_blank" href="https://apps.apple.com/app/6737160756" title="RightMenu Master for macOS"><img align="center" alt="RightMenu Master" height="52" width="52" src="https://github.com/user-attachments/assets/39a76541-71bf-4de7-a01c-c62f0557dff5"></a>
17
+ <a target="_blank" href="https://apps.apple.com/app/6723903021" title="Paste Quick for macOS"><img align="center" alt="Quick RSS" height="52" width="52" src="https://github.com/user-attachments/assets/bdaad5b7-9810-44ce-8f17-8410864465d2"></a>
18
+ <a target="_blank" href="https://apps.apple.com/app/6670696072" title="Quick RSS for macOS/iOS"><img align="center" alt="Quick RSS" height="52" width="52" src="https://github.com/user-attachments/assets/374106b5-a448-4d1d-9ccb-b04b6bc681ed"></a>
19
+ <a target="_blank" href="https://apps.apple.com/app/6670167443" title="Web Serve for macOS"><img align="center" alt="Web Serve" height="52" width="52" src="https://github.com/user-attachments/assets/e1d9f76f-0f3d-4ba5-8a15-253ee173bb1c"></a>
20
+ <a target="_blank" href="https://apps.apple.com/app/6503953628" title="Copybook Generator for macOS/iOS"><img align="center" alt="Copybook Generator" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/b90e42ff-158b-4534-82ca-5898fd0e8d73"></a>
21
+ <a target="_blank" href="https://apps.apple.com/app/6471227008" title="DevTutor for macOS/iOS"><img align="center" alt="DevTutor for SwiftUI" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/f15c154d-0192-48eb-8e0e-9e245ffd974a"></a>
22
+ <a target="_blank" href="https://apps.apple.com/app/6479819388" title="RegexMate for macOS/iOS"><img align="center" alt="RegexMate" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/aabe5aa9-9a96-4390-8bed-c3e4023d0dea"></a>
23
+ <a target="_blank" href="https://apps.apple.com/app/6479194014" title="Time Passage for macOS/iOS"><img align="center" alt="Time Passage" height="52" width="52" src="https://github.com/jaywcjlove/time-passage/assets/1680273/6f30e429-e6f3-4dbe-9921-a5effe2a05e9"></a>
24
+ <a target="_blank" href="https://apps.apple.com/app/6478772538" title="IconizeFolder for macOS"><img align="center" alt="Iconize Folder" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/fa9d8b9c-1e51-4ded-877c-fa5b21c47220"></a>
25
+ <a target="_blank" href="https://apps.apple.com/app/6478511402" title="Textsound Saver for macOS/iOS"><img align="center" alt="Textsound Saver" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/0595e842-980b-4574-8891-a8ba853a08be"></a>
26
+ <a target="_blank" href="https://apps.apple.com/app/6476924627" title="Create Custom Symbols for macOS"><img align="center" alt="Create Custom Symbols" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/8cd022ce-a3f1-4e89-b7c6-6fbd0d4db77c"></a>
27
+ <a target="_blank" href="https://apps.apple.com/app/6476452351" title="DevHub for macOS"><img align="center" alt="DevHub" height="52" width="52" src="https://github.com/user-attachments/assets/4a44a4fd-67ce-430b-af0a-72f18feaa47d"></a>
28
+ <a target="_blank" href="https://apps.apple.com/app/6476400184" title="Resume Revise for macOS"><img align="center" alt="Resume Revise" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c9954a20-1905-48de-bdf8-d71837974aa2"></a>
29
+ <a target="_blank" href="https://apps.apple.com/app/6472593276" title="Palette Genius for macOS"><img align="center" alt="Palette Genius" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/27340413-d355-45b2-8f6f-6ac37682d957"></a>
30
+ <a target="_blank" href="https://apps.apple.com/app/6470879005" title="Symbol Scribe for macOS"><img align="center" alt="Symbol Scribe" height="52" width="52" src="https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c7249f05-fa70-4def-a1e9-571d5f171fc9"></a>
30
31
  </div>
31
32
  <hr>
32
33
 
@@ -40,15 +40,15 @@ var KeyValues = exports.KeyValues = function KeyValues(props) {
40
40
  collapsed = _useStore.collapsed,
41
41
  shouldExpandNodeInitially = _useStore.shouldExpandNodeInitially;
42
42
  var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
43
- var isExpanded = (_expands$expandKey = expands[expandKey]) !== null && _expands$expandKey !== void 0 ? _expands$expandKey : defaultExpanded;
44
- var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
43
+ var isExpanded = (_expands$expandKey = expands[expandKey]) !== null && _expands$expandKey !== void 0 ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
44
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
45
45
  value: value,
46
46
  keys: keys,
47
47
  level: level,
48
48
  keyName: keyName,
49
49
  parentValue: parentValue
50
50
  });
51
- if (expands[expandKey] === undefined && !!shouldExpand) {
51
+ if (expands[expandKey] === undefined && !shouldExpand) {
52
52
  return null;
53
53
  }
54
54
  if (isExpanded) {
@@ -24,15 +24,15 @@ var NestedClose = exports.NestedClose = function NestedClose(props) {
24
24
  collapsed = _useStore.collapsed,
25
25
  shouldExpandNodeInitially = _useStore.shouldExpandNodeInitially;
26
26
  var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
27
- var isExpanded = (_expands$expandKey = expands[expandKey]) !== null && _expands$expandKey !== void 0 ? _expands$expandKey : defaultExpanded;
28
- var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
27
+ var isExpanded = (_expands$expandKey = expands[expandKey]) !== null && _expands$expandKey !== void 0 ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
28
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
29
29
  value: value,
30
30
  keys: keys,
31
31
  level: level,
32
32
  keyName: keyName,
33
33
  parentValue: parentValue
34
34
  });
35
- if (expands[expandKey] === undefined && !!shouldExpand) {
35
+ if (expands[expandKey] === undefined && !shouldExpand) {
36
36
  return null;
37
37
  }
38
38
  var len = Object.keys(value).length;
@@ -35,8 +35,8 @@ var NestedOpen = exports.NestedOpen = function NestedOpen(props) {
35
35
  collapsed = _useStore.collapsed,
36
36
  shouldExpandNodeInitially = _useStore.shouldExpandNodeInitially;
37
37
  var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
38
- var isExpanded = (_expands$expandKey = expands[expandKey]) !== null && _expands$expandKey !== void 0 ? _expands$expandKey : defaultExpanded;
39
- var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
38
+ var isExpanded = (_expands$expandKey = expands[expandKey]) !== null && _expands$expandKey !== void 0 ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
39
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
40
40
  value: value,
41
41
  keys: keys,
42
42
  level: level,
@@ -44,7 +44,7 @@ var NestedOpen = exports.NestedOpen = function NestedOpen(props) {
44
44
  parentValue: parentValue
45
45
  });
46
46
  if (expands[expandKey] === undefined && shouldExpandNodeInitially) {
47
- isExpanded = !!shouldExpand;
47
+ isExpanded = !shouldExpand;
48
48
  }
49
49
  var click = function click() {
50
50
  var opt = {
package/cjs/index.d.ts CHANGED
@@ -53,9 +53,17 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
53
53
  displayDataTypes?: boolean;
54
54
  /** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
55
55
  enableClipboard?: boolean;
56
- /** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
56
+ /**
57
+ * When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a specific depth. @default false
58
+ * collapsed takes precedence over shouldExpandNodeInitially.
59
+ * @see {@link shouldExpandNodeInitially} for more details on how the initial expansion works.
60
+ */
57
61
  collapsed?: boolean | number;
58
- /** Determine whether the node should be expanded on the first render, or you can use collapsed to control the level of expansion (by default, the root is expanded). */
62
+ /**
63
+ * Determines whether the node should be expanded on the first render, or you can use collapsed to control the level of expansion (by default, the root is expanded).
64
+ * If both collapsed and shouldExpandNodeInitially are set, the value of collapsed takes precedence.
65
+ * @see {@link collapsed} for more details on how this works.
66
+ */
59
67
  shouldExpandNodeInitially?: ShouldExpandNodeInitially<T>;
60
68
  /** Whether to highlight updates. @default true */
61
69
  highlightUpdates?: boolean;
package/cjs/index.js CHANGED
@@ -117,8 +117,12 @@ var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
117
117
  style = props.style,
118
118
  value = props.value,
119
119
  children = props.children,
120
- collapsed = props.collapsed,
121
- shouldExpandNodeInitially = props.shouldExpandNodeInitially,
120
+ _props$collapsed = props.collapsed,
121
+ collapsed = _props$collapsed === void 0 ? false : _props$collapsed,
122
+ _props$shouldExpandNo = props.shouldExpandNodeInitially,
123
+ shouldExpandNodeInitially = _props$shouldExpandNo === void 0 ? function () {
124
+ return true;
125
+ } : _props$shouldExpandNo,
122
126
  _props$indentWidth = props.indentWidth,
123
127
  indentWidth = _props$indentWidth === void 0 ? 15 : _props$indentWidth,
124
128
  _props$displayObjectS = props.displayObjectSize,
@@ -151,7 +155,9 @@ var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
151
155
  value: value,
152
156
  objectSortKeys: objectSortKeys,
153
157
  indentWidth: indentWidth,
154
- shouldExpandNodeInitially: shouldExpandNodeInitially,
158
+ shouldExpandNodeInitially: collapsed === false ? shouldExpandNodeInitially : function () {
159
+ return false;
160
+ },
155
161
  displayObjectSize: displayObjectSize,
156
162
  collapsed: collapsed,
157
163
  enableClipboard: enableClipboard,
@@ -30,15 +30,15 @@ export var KeyValues = props => {
30
30
  shouldExpandNodeInitially
31
31
  } = useStore();
32
32
  var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
33
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
34
- var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
33
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
34
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
35
35
  value,
36
36
  keys,
37
37
  level,
38
38
  keyName,
39
39
  parentValue
40
40
  });
41
- if (expands[expandKey] === undefined && !!shouldExpand) {
41
+ if (expands[expandKey] === undefined && !shouldExpand) {
42
42
  return null;
43
43
  }
44
44
  if (isExpanded) {
@@ -19,15 +19,15 @@ export var NestedClose = props => {
19
19
  shouldExpandNodeInitially
20
20
  } = useStore();
21
21
  var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
22
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
23
- var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
22
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
23
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
24
24
  value,
25
25
  keys,
26
26
  level,
27
27
  keyName,
28
28
  parentValue
29
29
  });
30
- if (expands[expandKey] === undefined && !!shouldExpand) {
30
+ if (expands[expandKey] === undefined && !shouldExpand) {
31
31
  return null;
32
32
  }
33
33
  var len = Object.keys(value).length;
@@ -28,8 +28,8 @@ export var NestedOpen = props => {
28
28
  shouldExpandNodeInitially
29
29
  } = useStore();
30
30
  var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
31
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
32
- var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
31
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
32
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
33
33
  value,
34
34
  keys,
35
35
  level,
@@ -37,7 +37,7 @@ export var NestedOpen = props => {
37
37
  parentValue
38
38
  });
39
39
  if (expands[expandKey] === undefined && shouldExpandNodeInitially) {
40
- isExpanded = !!shouldExpand;
40
+ isExpanded = !shouldExpand;
41
41
  }
42
42
  var click = () => {
43
43
  var opt = {
package/esm/index.d.ts CHANGED
@@ -53,9 +53,17 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
53
53
  displayDataTypes?: boolean;
54
54
  /** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
55
55
  enableClipboard?: boolean;
56
- /** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
56
+ /**
57
+ * When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a specific depth. @default false
58
+ * collapsed takes precedence over shouldExpandNodeInitially.
59
+ * @see {@link shouldExpandNodeInitially} for more details on how the initial expansion works.
60
+ */
57
61
  collapsed?: boolean | number;
58
- /** Determine whether the node should be expanded on the first render, or you can use collapsed to control the level of expansion (by default, the root is expanded). */
62
+ /**
63
+ * Determines whether the node should be expanded on the first render, or you can use collapsed to control the level of expansion (by default, the root is expanded).
64
+ * If both collapsed and shouldExpandNodeInitially are set, the value of collapsed takes precedence.
65
+ * @see {@link collapsed} for more details on how this works.
66
+ */
59
67
  shouldExpandNodeInitially?: ShouldExpandNodeInitially<T>;
60
68
  /** Whether to highlight updates. @default true */
61
69
  highlightUpdates?: boolean;
package/esm/index.js CHANGED
@@ -44,8 +44,8 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
44
44
  style,
45
45
  value,
46
46
  children,
47
- collapsed,
48
- shouldExpandNodeInitially,
47
+ collapsed = false,
48
+ shouldExpandNodeInitially = () => true,
49
49
  indentWidth = 15,
50
50
  displayObjectSize = true,
51
51
  shortenTextAfterLength = 30,
@@ -72,7 +72,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
72
72
  value,
73
73
  objectSortKeys,
74
74
  indentWidth,
75
- shouldExpandNodeInitially,
75
+ shouldExpandNodeInitially: collapsed === false ? shouldExpandNodeInitially : () => false,
76
76
  displayObjectSize,
77
77
  collapsed,
78
78
  enableClipboard,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-json-view",
3
- "version": "2.0.0-alpha.37",
3
+ "version": "2.0.0-alpha.39",
4
4
  "description": "JSON viewer for react.",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",