@uiw/react-json-view 1.12.0 → 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
@@ -688,7 +690,7 @@ export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttr
688
690
  displayDataTypes?: boolean;
689
691
  /** When set to `true`, `objects` and `arrays` are labeled with size @default true */
690
692
  displayObjectSize?: boolean;
691
- /** 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 */
692
694
  shortenTextAfterLength?: number;
693
695
  /** Define the root node name. @default undefined */
694
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.js CHANGED
@@ -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,
package/cjs/value.js CHANGED
@@ -153,9 +153,11 @@ var RenderShortenTextValue = function RenderShortenTextValue(_ref2) {
153
153
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
154
154
  shorten = _useState2[0],
155
155
  setShorten = _useState2[1];
156
+ (0, _react.useEffect)(function () {
157
+ return setShorten(length && childrenStr.length >= length);
158
+ }, [length]);
156
159
  var click = function click() {
157
- if (length && childrenStr.length <= length) return setShorten(false);
158
- setShorten(!shorten);
160
+ return setShorten(!shorten);
159
161
  };
160
162
  var text = shorten ? "".concat(childrenStr.slice(0, length), "...") : childrenStr;
161
163
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(RenderStringValue, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rest), {}, {
@@ -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.js CHANGED
@@ -46,7 +46,7 @@ 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',
package/esm/value.js CHANGED
@@ -5,7 +5,7 @@ var _excluded = ["children", "style"],
5
5
  _excluded3 = ["color", "style", "isURL", "href", "children"],
6
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";
@@ -134,10 +134,8 @@ var RenderShortenTextValue = _ref2 => {
134
134
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
135
135
  var childrenStr = children;
136
136
  var [shorten, setShorten] = useState(length && childrenStr.length >= length);
137
- var click = () => {
138
- if (length && childrenStr.length <= length) return setShorten(false);
139
- setShorten(!shorten);
140
- };
137
+ useEffect(() => setShorten(length && childrenStr.length >= length), [length]);
138
+ var click = () => setShorten(!shorten);
141
139
  var text = shorten ? childrenStr.slice(0, length) + "..." : childrenStr;
142
140
  return /*#__PURE__*/_jsx(RenderStringValue, _extends({}, rest, {
143
141
  style: _extends({}, style, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-json-view",
3
- "version": "1.12.0",
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",