@uiw/react-json-view 1.11.1 → 1.12.1

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
@@ -5,9 +5,9 @@ react-json-view
5
5
  [![npm version](https://img.shields.io/npm/v/@uiw/react-json-view.svg)](https://www.npmjs.com/package/@uiw/react-json-view)
6
6
  [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-json-view.svg?style=flat&label=)](https://www.npmjs.com/package/@uiw/react-json-view)
7
7
  [![react@^18](https://shields.io/badge/react-^18-green?style=flat&logo=react)](https://github.com/facebook/react/releases)
8
- [![Coverage Status](https://uiwjs.github.io/react-json-view/badges.svg)](https://uiwjs.github.io/react-json-view/lcov-report/)
8
+ [![Coverage Status](https://raw.githack.com/uiwjs/react-json-view/v1-docs/badges.svg)](https://uiwjs.github.io/react-json-view/lcov-report/)
9
9
 
10
- A React component for displaying and editing javascript arrays and JSON objects.
10
+ A React component for displaying and editing javascript arrays and JSON objects. Preview of v1 documentation is available [here](https://raw.githack.com/uiwjs/react-json-view/v1-docs/index.html).
11
11
 
12
12
  <!--rehype:ignore:start-->
13
13
  <a href="https://uiwjs.github.io/react-json-view/" target="_blank">
@@ -26,6 +26,8 @@ A React component for displaying and editing javascript arrays and JSON objects.
26
26
  ✏️ Support editing and adding features
27
27
  ♻️ Whether to highlight updates.
28
28
 
29
+ The new version **[v2](https://github.com/uiwjs/react-json-view/tree/v2)** has redesigned the API to make the code more maintainable and introduced a simpler and more flexible component customization rendering API. Each component can now have custom rendering, and the new API resembles React more closely.
30
+
29
31
  ## Quick Start
30
32
 
31
33
  ```bash
@@ -229,9 +231,11 @@ const customTheme = {
229
231
  '--w-rjv-type-boolean-color': '#559bd4',
230
232
  '--w-rjv-type-date-color': '#586e75',
231
233
  '--w-rjv-type-url-color': '#0969da',
232
- '--w-rjv-type-null-color': '#d33682',
233
234
  '--w-rjv-type-nan-color': '#859900',
234
235
  '--w-rjv-type-undefined-color': '#586e75',
236
+ '--w-rjv-type-null-color': '#d33682',
237
+ '--w-rjv-type-set-color': '#268bd2',
238
+ '--w-rjv-type-map-color': '#268bd2',
235
239
  };
236
240
 
237
241
  export default function Demo() {
@@ -686,7 +690,7 @@ export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttr
686
690
  displayDataTypes?: boolean;
687
691
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
688
692
  displayObjectSize?: boolean;
689
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
693
+ /** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
690
694
  shortenTextAfterLength?: number;
691
695
  /** Define the root node name. @default undefined */
692
696
  keyName?: string | number;
@@ -15,7 +15,6 @@ var _add = require("./icon/add");
15
15
  var _delete = require("./icon/delete");
16
16
  var _jsxRuntime = require("react/jsx-runtime");
17
17
  function CountInfoExtra(props) {
18
- var _ref, _ref2;
19
18
  var visible = props.visible,
20
19
  showTools = props.showTools,
21
20
  editable = props.editable,
@@ -28,8 +27,8 @@ function CountInfoExtra(props) {
28
27
  onAdd = props.onAdd,
29
28
  onDelete = props.onDelete;
30
29
  if (!visible || !showTools) return null;
31
- var click = function click(_x) {
32
- return (_ref = _ref || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee(event) {
30
+ var click = /*#__PURE__*/function () {
31
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee(event) {
33
32
  var keyOrValue, isArray, isAdd, result, maybeAdd;
34
33
  return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
35
34
  while (1) switch (_context.prev = _context.next) {
@@ -55,10 +54,13 @@ function CountInfoExtra(props) {
55
54
  return _context.stop();
56
55
  }
57
56
  }, _callee);
58
- }))).apply(this, arguments);
59
- };
60
- var deleteHandle = function deleteHandle(_x2) {
61
- return (_ref2 = _ref2 || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(event) {
57
+ }));
58
+ return function click(_x) {
59
+ return _ref.apply(this, arguments);
60
+ };
61
+ }();
62
+ var deleteHandle = /*#__PURE__*/function () {
63
+ var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(event) {
62
64
  var maybeDelete;
63
65
  return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
64
66
  while (1) switch (_context2.prev = _context2.next) {
@@ -88,8 +90,11 @@ function CountInfoExtra(props) {
88
90
  return _context2.stop();
89
91
  }
90
92
  }, _callee2);
91
- }))).apply(this, arguments);
92
- };
93
+ }));
94
+ return function deleteHandle(_x2) {
95
+ return _ref2.apply(this, arguments);
96
+ };
97
+ }();
93
98
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
94
99
  children: [editable && onAdd && /*#__PURE__*/(0, _jsxRuntime.jsx)(_add.AddIcon, {
95
100
  onClick: click
@@ -16,7 +16,6 @@ var _value = require("../value");
16
16
  var _jsxRuntime = require("react/jsx-runtime");
17
17
  var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "namespace", "editableValue", "onEdit", "highlightUpdates", "render"];
18
18
  var ObjectKey = function ObjectKey(props) {
19
- var _ref;
20
19
  var className = props.className,
21
20
  value = props.value,
22
21
  keyName = props.keyName,
@@ -59,8 +58,8 @@ var ObjectKey = function ObjectKey(props) {
59
58
  (_$edit$current = $edit.current) === null || _$edit$current === void 0 || _$edit$current.focus();
60
59
  }
61
60
  };
62
- var blur = function blur() {
63
- return (_ref = _ref || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
61
+ var blur = /*#__PURE__*/function () {
62
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
64
63
  var _$edit$current2, result;
65
64
  return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
66
65
  while (1) switch (_context.prev = _context.next) {
@@ -99,8 +98,11 @@ var ObjectKey = function ObjectKey(props) {
99
98
  return _context.stop();
100
99
  }
101
100
  }, _callee);
102
- }))).apply(this, arguments);
103
- };
101
+ }));
102
+ return function blur() {
103
+ return _ref.apply(this, arguments);
104
+ };
105
+ }();
104
106
  var focus = function focus() {
105
107
  if ($edit.current) {
106
108
  var _$edit$current3;
@@ -27,7 +27,7 @@ var Quotes = function Quotes(_ref) {
27
27
  });
28
28
  };
29
29
  function ReValue(props) {
30
- var _ref2, _typeMap$typeStr, _ref3;
30
+ var _typeMap$typeStr;
31
31
  var type = props.type,
32
32
  value = props.value,
33
33
  setValue = props.setValue,
@@ -81,8 +81,8 @@ function ReValue(props) {
81
81
  }
82
82
  }
83
83
  };
84
- var blur = function blur() {
85
- return (_ref2 = _ref2 || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
84
+ var blur = /*#__PURE__*/function () {
85
+ var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
86
86
  var text, _typeStr, dt, result, _getValueString, oldChildStr;
87
87
  return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
88
88
  while (1) switch (_context.prev = _context.next) {
@@ -161,8 +161,11 @@ function ReValue(props) {
161
161
  return _context.stop();
162
162
  }
163
163
  }, _callee);
164
- }))).apply(this, arguments);
165
- };
164
+ }));
165
+ return function blur() {
166
+ return _ref2.apply(this, arguments);
167
+ };
168
+ }();
166
169
  var defaultStyle = {
167
170
  minWidth: 34,
168
171
  minHeight: 18,
@@ -189,8 +192,8 @@ function ReValue(props) {
189
192
  if (typeStr === 'null' || typeStr === 'undefined' || type.toLocaleLowerCase() === 'nan') {
190
193
  typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
191
194
  }
192
- var deleteHandle = function deleteHandle(_x) {
193
- return (_ref3 = _ref3 || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(evn) {
195
+ var deleteHandle = /*#__PURE__*/function () {
196
+ var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(evn) {
194
197
  var maybeDelete;
195
198
  return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
196
199
  while (1) switch (_context2.prev = _context2.next) {
@@ -215,8 +218,11 @@ function ReValue(props) {
215
218
  return _context2.stop();
216
219
  }
217
220
  }, _callee2);
218
- }))).apply(this, arguments);
219
- };
221
+ }));
222
+ return function deleteHandle(_x) {
223
+ return _ref3.apply(this, arguments);
224
+ };
225
+ }();
220
226
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
221
227
  children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
222
228
  style: style,
package/cjs/index.d.ts CHANGED
@@ -33,7 +33,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
33
33
  displayDataTypes?: boolean;
34
34
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
35
35
  displayObjectSize?: boolean;
36
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
36
+ /** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
37
37
  shortenTextAfterLength?: number;
38
38
  /** Define the root node name. @default undefined */
39
39
  keyName?: string | number;
package/cjs/node.d.ts CHANGED
@@ -7,6 +7,8 @@ export interface RootNodeProps<T extends object> extends JsonViewProps<T> {
7
7
  keyid?: string;
8
8
  level?: number;
9
9
  parentValue?: T;
10
+ isSet?: boolean;
11
+ isMap?: boolean;
10
12
  namespace?: Array<string | number>;
11
13
  setParentValue?: React.Dispatch<React.SetStateAction<T>>;
12
14
  }
package/cjs/node.js CHANGED
@@ -19,7 +19,7 @@ var _copied = require("./copied");
19
19
  var _ellipsis = require("./comps/ellipsis");
20
20
  var _meta = require("./comps/meta");
21
21
  var _jsxRuntime = require("react/jsx-runtime");
22
- var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "shortenTextAfterLength", "collapsed", "level", "keyid", "quotes", "namespace", "onCopied", "onExpand", "parentValue", "setParentValue"];
22
+ var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "shortenTextAfterLength", "collapsed", "level", "keyid", "quotes", "namespace", "isSet", "isMap", "onCopied", "onExpand", "parentValue", "setParentValue"];
23
23
  function getLength(obj) {
24
24
  try {
25
25
  return Object.keys(obj).length;
@@ -62,7 +62,7 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
62
62
  _props$indentWidth = props.indentWidth,
63
63
  indentWidth = _props$indentWidth === void 0 ? 15 : _props$indentWidth,
64
64
  _props$shortenTextAft = props.shortenTextAfterLength,
65
- shortenTextAfterLength = _props$shortenTextAft === void 0 ? 20 : _props$shortenTextAft,
65
+ shortenTextAfterLength = _props$shortenTextAft === void 0 ? 30 : _props$shortenTextAft,
66
66
  collapsed = props.collapsed,
67
67
  _props$level = props.level,
68
68
  level = _props$level === void 0 ? 1 : _props$level,
@@ -72,6 +72,10 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
72
72
  quotes = _props$quotes === void 0 ? '"' : _props$quotes,
73
73
  _props$namespace = props.namespace,
74
74
  namespace = _props$namespace === void 0 ? [] : _props$namespace,
75
+ _props$isSet = props.isSet,
76
+ isSet = _props$isSet === void 0 ? false : _props$isSet,
77
+ _props$isMap = props.isMap,
78
+ isMap = _props$isMap === void 0 ? false : _props$isMap,
75
79
  onCopied = props.onCopied,
76
80
  onExpand = props.onExpand,
77
81
  parentValue = props.parentValue,
@@ -220,6 +224,10 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
220
224
  parentName: keyName,
221
225
  color: typeof keyName === 'number' ? _value.typeMap['number'].color : ''
222
226
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Colon, {})]
227
+ }), isSet && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Type, {
228
+ type: "Set"
229
+ }), isMap && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Type, {
230
+ type: "Map"
223
231
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
224
232
  start: true,
225
233
  isArray: isArray,
@@ -250,35 +258,40 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
250
258
  key = _ref11[0],
251
259
  itemVal = _ref11[1];
252
260
  var item = itemVal;
253
- var isEmpty = Array.isArray(item) && item.length === 0 || (0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
254
- if (Array.isArray(item) && !isEmpty) {
261
+ var isMySet = item instanceof Set;
262
+ var isMyMap = item instanceof Map;
263
+ var myValue = isMySet ? Array.from(item) : isMyMap ? Object.fromEntries(item) : item;
264
+ var isEmpty = Array.isArray(myValue) && myValue.length === 0 || (0, _typeof2["default"])(myValue) === 'object' && myValue && !(myValue instanceof Date) && Object.keys(myValue).length === 0;
265
+ if ((Array.isArray(myValue) || isMySet || isMyMap) && !isEmpty) {
255
266
  var label = isArray ? idx : key;
256
267
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
257
268
  className: "w-rjv-wrap",
258
269
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RootNode, (0, _objectSpread2["default"])({
259
- value: item,
270
+ value: myValue,
271
+ isSet: isMySet,
272
+ isMap: isMyMap,
260
273
  namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [label]),
261
274
  keyName: label,
262
275
  keyid: keyid + subkeyid + label
263
276
  }, subNodeProps))
264
277
  }, label + idx);
265
278
  }
266
- if ((0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && !isEmpty) {
279
+ if ((0, _typeof2["default"])(myValue) === 'object' && myValue && !(myValue instanceof Date) && !isEmpty) {
267
280
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
268
281
  className: "w-rjv-wrap",
269
282
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RootNode, (0, _objectSpread2["default"])({
270
- value: item,
283
+ value: myValue,
271
284
  namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
272
285
  keyName: key,
273
286
  keyid: keyid + subkeyid + key
274
287
  }, subNodeProps))
275
288
  }, key + '' + idx);
276
289
  }
277
- if (typeof item === 'function') {
290
+ if (typeof myValue === 'function') {
278
291
  return;
279
292
  }
280
293
  var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
281
- value: item,
294
+ value: myValue,
282
295
  "data-keys": keyid,
283
296
  quotes: quotes,
284
297
  namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
@@ -288,7 +301,7 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
288
301
  color: typeof key === 'number' ? _value.typeMap['number'].color : '',
289
302
  keyName: key
290
303
  });
291
- var length = Array.isArray(item) ? item.length : getLength(item);
304
+ var length = Array.isArray(myValue) ? myValue.length : getLength(myValue);
292
305
  countInfo = /*#__PURE__*/(0, _jsxRuntime.jsx)(CountInfo, {
293
306
  children: length
294
307
  });
@@ -306,7 +319,8 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
306
319
  countInfo: countInfo,
307
320
  renderKey: renderKey,
308
321
  keyName: key,
309
- value: item
322
+ isSet: isSet,
323
+ value: myValue
310
324
  }), idx);
311
325
  })
312
326
  }), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
package/cjs/value.d.ts CHANGED
@@ -35,6 +35,14 @@ export declare const typeMap: {
35
35
  color: string;
36
36
  label: string;
37
37
  };
38
+ Set: {
39
+ color: string;
40
+ label: string;
41
+ };
42
+ Map: {
43
+ color: string;
44
+ label: string;
45
+ };
38
46
  NaN: {
39
47
  color: string;
40
48
  label: string;
@@ -53,6 +61,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
53
61
  displayDataTypes: boolean;
54
62
  displayObjectSize: boolean;
55
63
  enableClipboard: boolean;
64
+ isSet: boolean;
56
65
  indentWidth: number;
57
66
  level?: number;
58
67
  shortenTextAfterLength?: JsonViewProps<T>['shortenTextAfterLength'];
@@ -64,7 +73,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
64
73
  setValue?: React.Dispatch<React.SetStateAction<T>>;
65
74
  }
66
75
  export declare function getValueString<T>(value: T): {
67
- type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
76
+ type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "Set" | "Map" | "NaN";
68
77
  content: string;
69
78
  };
70
79
  export declare function ValueView<T extends object>(props: ValueViewProps<T>): import("react/jsx-runtime").JSX.Element;
package/cjs/value.js CHANGED
@@ -19,7 +19,7 @@ var _jsxRuntime = require("react/jsx-runtime");
19
19
  var _excluded = ["children", "style"],
20
20
  _excluded2 = ["children", "length", "style"],
21
21
  _excluded3 = ["color", "style", "isURL", "href", "children"],
22
- _excluded4 = ["value", "parentValue", "setValue", "countInfo", "data", "keyName", "indentWidth", "namespace", "renderKey", "components", "quotes", "level", "enableClipboard", "displayObjectSize", "displayDataTypes", "shortenTextAfterLength"],
22
+ _excluded4 = ["value", "parentValue", "setValue", "countInfo", "data", "keyName", "indentWidth", "isSet", "namespace", "renderKey", "components", "quotes", "level", "enableClipboard", "displayObjectSize", "displayDataTypes", "shortenTextAfterLength"],
23
23
  _excluded5 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
24
24
  var Line = function Line(props) {
25
25
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
@@ -63,6 +63,14 @@ var typeMap = {
63
63
  color: 'var(--w-rjv-type-null-color, #d33682)',
64
64
  label: 'null'
65
65
  },
66
+ Set: {
67
+ color: 'var(--w-rjv-type-set-color, #268bd2)',
68
+ label: 'Set'
69
+ },
70
+ Map: {
71
+ color: 'var(--w-rjv-type-map-color, #268bd2)',
72
+ label: 'Map'
73
+ },
66
74
  NaN: {
67
75
  color: 'var(--w-rjv-type-nan-color, #859900)',
68
76
  label: 'NaN'
@@ -145,10 +153,11 @@ var RenderShortenTextValue = function RenderShortenTextValue(_ref2) {
145
153
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
146
154
  shorten = _useState2[0],
147
155
  setShorten = _useState2[1];
156
+ (0, _react.useEffect)(function () {
157
+ return setShorten(length && childrenStr.length >= length);
158
+ }, [length]);
148
159
  var click = function click() {
149
- console.log(shorten);
150
- if (length && childrenStr.length <= length) return setShorten(false);
151
- setShorten(!shorten);
160
+ return setShorten(!shorten);
152
161
  };
153
162
  var text = shorten ? "".concat(childrenStr.slice(0, length), "...") : childrenStr;
154
163
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(RenderStringValue, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rest), {}, {
@@ -193,6 +202,7 @@ function ValueView(props) {
193
202
  data = props.data,
194
203
  keyName = props.keyName,
195
204
  indentWidth = props.indentWidth,
205
+ isSet = props.isSet,
196
206
  namespace = props.namespace,
197
207
  renderKey = props.renderKey,
198
208
  _props$components = props.components,
@@ -6,7 +6,6 @@ import { DeleteIcon } from './icon/delete';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
8
  export function CountInfoExtra(props) {
9
- var _ref, _ref2;
10
9
  var {
11
10
  visible,
12
11
  showTools,
@@ -21,8 +20,8 @@ export function CountInfoExtra(props) {
21
20
  onDelete
22
21
  } = props;
23
22
  if (!visible || !showTools) return null;
24
- var click = function click(_x) {
25
- return (_ref = _ref || _asyncToGenerator(function* (event) {
23
+ var click = /*#__PURE__*/function () {
24
+ var _ref = _asyncToGenerator(function* (event) {
26
25
  event.stopPropagation();
27
26
  var keyOrValue = 'AddKeyOrValue';
28
27
  var isArray = Array.isArray(value);
@@ -36,10 +35,13 @@ export function CountInfoExtra(props) {
36
35
  setValue(result);
37
36
  }
38
37
  }
39
- })).apply(this, arguments);
40
- };
41
- var deleteHandle = function deleteHandle(_x2) {
42
- return (_ref2 = _ref2 || _asyncToGenerator(function* (event) {
38
+ });
39
+ return function click(_x) {
40
+ return _ref.apply(this, arguments);
41
+ };
42
+ }();
43
+ var deleteHandle = /*#__PURE__*/function () {
44
+ var _ref2 = _asyncToGenerator(function* (event) {
43
45
  event.stopPropagation();
44
46
  if (onDelete && (keyName || typeof keyName === 'number') && parentValue) {
45
47
  var maybeDelete = yield onDelete(keyName, value, parentValue, {
@@ -55,8 +57,11 @@ export function CountInfoExtra(props) {
55
57
  }
56
58
  }
57
59
  }
58
- })).apply(this, arguments);
59
- };
60
+ });
61
+ return function deleteHandle(_x2) {
62
+ return _ref2.apply(this, arguments);
63
+ };
64
+ }();
60
65
  return /*#__PURE__*/_jsxs(Fragment, {
61
66
  children: [editable && onAdd && /*#__PURE__*/_jsx(AddIcon, {
62
67
  onClick: click
@@ -7,7 +7,6 @@ import { useHighlight } from '../semicolon';
7
7
  import { Label } from '../value';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  export var ObjectKey = props => {
10
- var _ref;
11
10
  var {
12
11
  className,
13
12
  value,
@@ -43,8 +42,8 @@ export var ObjectKey = props => {
43
42
  (_$edit$current = $edit.current) == null || _$edit$current.focus();
44
43
  }
45
44
  };
46
- var blur = function blur() {
47
- return (_ref = _ref || _asyncToGenerator(function* () {
45
+ var blur = /*#__PURE__*/function () {
46
+ var _ref = _asyncToGenerator(function* () {
48
47
  if ($edit.current) {
49
48
  var _$edit$current2;
50
49
  if (onEdit) {
@@ -66,8 +65,11 @@ export var ObjectKey = props => {
66
65
  (_$edit$current2 = $edit.current) == null || _$edit$current2.focus();
67
66
  }
68
67
  setEditable(false);
69
- })).apply(this, arguments);
70
- };
68
+ });
69
+ return function blur() {
70
+ return _ref.apply(this, arguments);
71
+ };
72
+ }();
71
73
  var focus = () => {
72
74
  if ($edit.current) {
73
75
  var _$edit$current3;
@@ -21,7 +21,7 @@ var Quotes = _ref => {
21
21
  });
22
22
  };
23
23
  export function ReValue(props) {
24
- var _ref2, _typeMap$typeStr, _ref3;
24
+ var _typeMap$typeStr;
25
25
  var {
26
26
  type,
27
27
  value,
@@ -65,8 +65,8 @@ export function ReValue(props) {
65
65
  }
66
66
  }
67
67
  };
68
- var blur = function blur() {
69
- return (_ref2 = _ref2 || _asyncToGenerator(function* () {
68
+ var blur = /*#__PURE__*/function () {
69
+ var _ref2 = _asyncToGenerator(function* () {
70
70
  if (!editableValue) return;
71
71
  setEditable(false);
72
72
  if ($edit.current) {
@@ -126,8 +126,11 @@ export function ReValue(props) {
126
126
  }
127
127
  }
128
128
  }
129
- })).apply(this, arguments);
130
- };
129
+ });
130
+ return function blur() {
131
+ return _ref2.apply(this, arguments);
132
+ };
133
+ }();
131
134
  var defaultStyle = {
132
135
  minWidth: 34,
133
136
  minHeight: 18,
@@ -155,8 +158,8 @@ export function ReValue(props) {
155
158
  if (typeStr === 'null' || typeStr === 'undefined' || type.toLocaleLowerCase() === 'nan') {
156
159
  typeView = /*#__PURE__*/_jsx(Fragment, {});
157
160
  }
158
- var deleteHandle = function deleteHandle(_x) {
159
- return (_ref3 = _ref3 || _asyncToGenerator(function* (evn) {
161
+ var deleteHandle = /*#__PURE__*/function () {
162
+ var _ref3 = _asyncToGenerator(function* (evn) {
160
163
  evn.stopPropagation();
161
164
  if (data && keyName && keyName in data && setValue && onDelete) {
162
165
  var maybeDelete = yield onDelete(keyName, value, parentValue, {
@@ -167,8 +170,11 @@ export function ReValue(props) {
167
170
  setValue(_extends({}, data));
168
171
  }
169
172
  }
170
- })).apply(this, arguments);
171
- };
173
+ });
174
+ return function deleteHandle(_x) {
175
+ return _ref3.apply(this, arguments);
176
+ };
177
+ }();
172
178
  return /*#__PURE__*/_jsxs(Fragment, {
173
179
  children: [displayDataTypes && typeView, /*#__PURE__*/_jsx(Quotes, {
174
180
  style: style,
package/esm/index.d.ts CHANGED
@@ -33,7 +33,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
33
33
  displayDataTypes?: boolean;
34
34
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
35
35
  displayObjectSize?: boolean;
36
- /** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
36
+ /** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
37
37
  shortenTextAfterLength?: number;
38
38
  /** Define the root node name. @default undefined */
39
39
  keyName?: string | number;
package/esm/node.d.ts CHANGED
@@ -7,6 +7,8 @@ export interface RootNodeProps<T extends object> extends JsonViewProps<T> {
7
7
  keyid?: string;
8
8
  level?: number;
9
9
  parentValue?: T;
10
+ isSet?: boolean;
11
+ isMap?: boolean;
10
12
  namespace?: Array<string | number>;
11
13
  setParentValue?: React.Dispatch<React.SetStateAction<T>>;
12
14
  }
package/esm/node.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "shortenTextAfterLength", "collapsed", "level", "keyid", "quotes", "namespace", "onCopied", "onExpand", "parentValue", "setParentValue"];
3
+ var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "shortenTextAfterLength", "collapsed", "level", "keyid", "quotes", "namespace", "isSet", "isMap", "onCopied", "onExpand", "parentValue", "setParentValue"];
4
4
  import { Fragment, useId, cloneElement, useState, useEffect, forwardRef } from 'react';
5
- import { ValueView, Colon, Label, Line, typeMap } from './value';
5
+ import { ValueView, Type, Colon, Label, Line, typeMap } from './value';
6
6
  import { TriangleArrow } from './arrow/TriangleArrow';
7
7
  import { useExpandsStatus, store } from './store';
8
8
  import { Semicolon } from './semicolon';
@@ -46,12 +46,14 @@ export var RootNode = /*#__PURE__*/forwardRef((props, ref) => {
46
46
  highlightUpdates = true,
47
47
  objectSortKeys = false,
48
48
  indentWidth = 15,
49
- shortenTextAfterLength = 20,
49
+ shortenTextAfterLength = 30,
50
50
  collapsed,
51
51
  level = 1,
52
52
  keyid = 'root',
53
53
  quotes = '"',
54
54
  namespace = [],
55
+ isSet = false,
56
+ isMap = false,
55
57
  onCopied,
56
58
  onExpand,
57
59
  parentValue,
@@ -181,6 +183,10 @@ export var RootNode = /*#__PURE__*/forwardRef((props, ref) => {
181
183
  parentName: keyName,
182
184
  color: typeof keyName === 'number' ? typeMap['number'].color : ''
183
185
  }), /*#__PURE__*/_jsx(Colon, {})]
186
+ }), isSet && /*#__PURE__*/_jsx(Type, {
187
+ type: "Set"
188
+ }), isMap && /*#__PURE__*/_jsx(Type, {
189
+ type: "Map"
184
190
  }), /*#__PURE__*/_jsx(Meta, {
185
191
  start: true,
186
192
  isArray: isArray,
@@ -209,35 +215,40 @@ export var RootNode = /*#__PURE__*/forwardRef((props, ref) => {
209
215
  children: entries.length > 0 && [...entries].map((_ref6, idx) => {
210
216
  var [key, itemVal] = _ref6;
211
217
  var item = itemVal;
212
- var isEmpty = Array.isArray(item) && item.length === 0 || typeof item === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
213
- if (Array.isArray(item) && !isEmpty) {
218
+ var isMySet = item instanceof Set;
219
+ var isMyMap = item instanceof Map;
220
+ var myValue = isMySet ? Array.from(item) : isMyMap ? Object.fromEntries(item) : item;
221
+ var isEmpty = Array.isArray(myValue) && myValue.length === 0 || typeof myValue === 'object' && myValue && !(myValue instanceof Date) && Object.keys(myValue).length === 0;
222
+ if ((Array.isArray(myValue) || isMySet || isMyMap) && !isEmpty) {
214
223
  var label = isArray ? idx : key;
215
224
  return /*#__PURE__*/_jsx(Line, {
216
225
  className: "w-rjv-wrap",
217
226
  children: /*#__PURE__*/_jsx(RootNode, _extends({
218
- value: item,
227
+ value: myValue,
228
+ isSet: isMySet,
229
+ isMap: isMyMap,
219
230
  namespace: [...namespace, label],
220
231
  keyName: label,
221
232
  keyid: keyid + subkeyid + label
222
233
  }, subNodeProps))
223
234
  }, label + idx);
224
235
  }
225
- if (typeof item === 'object' && item && !(item instanceof Date) && !isEmpty) {
236
+ if (typeof myValue === 'object' && myValue && !(myValue instanceof Date) && !isEmpty) {
226
237
  return /*#__PURE__*/_jsx(Line, {
227
238
  className: "w-rjv-wrap",
228
239
  children: /*#__PURE__*/_jsx(RootNode, _extends({
229
- value: item,
240
+ value: myValue,
230
241
  namespace: [...namespace, key],
231
242
  keyName: key,
232
243
  keyid: keyid + subkeyid + key
233
244
  }, subNodeProps))
234
245
  }, key + '' + idx);
235
246
  }
236
- if (typeof item === 'function') {
247
+ if (typeof myValue === 'function') {
237
248
  return;
238
249
  }
239
250
  var renderKey = /*#__PURE__*/_jsx(Semicolon, {
240
- value: item,
251
+ value: myValue,
241
252
  "data-keys": keyid,
242
253
  quotes: quotes,
243
254
  namespace: [...namespace, key],
@@ -247,7 +258,7 @@ export var RootNode = /*#__PURE__*/forwardRef((props, ref) => {
247
258
  color: typeof key === 'number' ? typeMap['number'].color : '',
248
259
  keyName: key
249
260
  });
250
- var length = Array.isArray(item) ? item.length : getLength(item);
261
+ var length = Array.isArray(myValue) ? myValue.length : getLength(myValue);
251
262
  countInfo = /*#__PURE__*/_jsx(CountInfo, {
252
263
  children: length
253
264
  });
@@ -265,7 +276,8 @@ export var RootNode = /*#__PURE__*/forwardRef((props, ref) => {
265
276
  countInfo: countInfo,
266
277
  renderKey: renderKey,
267
278
  keyName: key,
268
- value: item
279
+ isSet: isSet,
280
+ value: myValue
269
281
  }), idx);
270
282
  })
271
283
  }), expand && /*#__PURE__*/_jsx(Line, {
package/esm/value.d.ts CHANGED
@@ -35,6 +35,14 @@ export declare const typeMap: {
35
35
  color: string;
36
36
  label: string;
37
37
  };
38
+ Set: {
39
+ color: string;
40
+ label: string;
41
+ };
42
+ Map: {
43
+ color: string;
44
+ label: string;
45
+ };
38
46
  NaN: {
39
47
  color: string;
40
48
  label: string;
@@ -53,6 +61,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
53
61
  displayDataTypes: boolean;
54
62
  displayObjectSize: boolean;
55
63
  enableClipboard: boolean;
64
+ isSet: boolean;
56
65
  indentWidth: number;
57
66
  level?: number;
58
67
  shortenTextAfterLength?: JsonViewProps<T>['shortenTextAfterLength'];
@@ -64,7 +73,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
64
73
  setValue?: React.Dispatch<React.SetStateAction<T>>;
65
74
  }
66
75
  export declare function getValueString<T>(value: T): {
67
- type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
76
+ type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "Set" | "Map" | "NaN";
68
77
  content: string;
69
78
  };
70
79
  export declare function ValueView<T extends object>(props: ValueViewProps<T>): import("react/jsx-runtime").JSX.Element;
package/esm/value.js CHANGED
@@ -3,9 +3,9 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  var _excluded = ["children", "style"],
4
4
  _excluded2 = ["children", "length", "style"],
5
5
  _excluded3 = ["color", "style", "isURL", "href", "children"],
6
- _excluded4 = ["value", "parentValue", "setValue", "countInfo", "data", "keyName", "indentWidth", "namespace", "renderKey", "components", "quotes", "level", "enableClipboard", "displayObjectSize", "displayDataTypes", "shortenTextAfterLength"],
6
+ _excluded4 = ["value", "parentValue", "setValue", "countInfo", "data", "keyName", "indentWidth", "isSet", "namespace", "renderKey", "components", "quotes", "level", "enableClipboard", "displayObjectSize", "displayDataTypes", "shortenTextAfterLength"],
7
7
  _excluded5 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
8
- import { Fragment, forwardRef, useMemo, useState } from 'react';
8
+ import { Fragment, forwardRef, useMemo, useEffect, useState } from 'react';
9
9
  import { Meta } from './comps/meta';
10
10
  import { Copied } from './copied';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -46,6 +46,14 @@ export var typeMap = {
46
46
  color: 'var(--w-rjv-type-null-color, #d33682)',
47
47
  label: 'null'
48
48
  },
49
+ Set: {
50
+ color: 'var(--w-rjv-type-set-color, #268bd2)',
51
+ label: 'Set'
52
+ },
53
+ Map: {
54
+ color: 'var(--w-rjv-type-map-color, #268bd2)',
55
+ label: 'Map'
56
+ },
49
57
  NaN: {
50
58
  color: 'var(--w-rjv-type-nan-color, #859900)',
51
59
  label: 'NaN'
@@ -126,11 +134,8 @@ var RenderShortenTextValue = _ref2 => {
126
134
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
127
135
  var childrenStr = children;
128
136
  var [shorten, setShorten] = useState(length && childrenStr.length >= length);
129
- var click = () => {
130
- console.log(shorten);
131
- if (length && childrenStr.length <= length) return setShorten(false);
132
- setShorten(!shorten);
133
- };
137
+ useEffect(() => setShorten(length && childrenStr.length >= length), [length]);
138
+ var click = () => setShorten(!shorten);
134
139
  var text = shorten ? childrenStr.slice(0, length) + "..." : childrenStr;
135
140
  return /*#__PURE__*/_jsx(RenderStringValue, _extends({}, rest, {
136
141
  style: _extends({}, style, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-json-view",
3
- "version": "1.11.1",
3
+ "version": "1.12.1",
4
4
  "description": "JSON viewer for react.",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -93,6 +93,10 @@
93
93
  "cjs",
94
94
  "esm"
95
95
  ],
96
+ "publishConfig": {
97
+ "access": "public",
98
+ "provenance": true
99
+ },
96
100
  "keywords": [
97
101
  "array-viewer",
98
102
  "component",