@uiw/react-json-view 1.8.5 → 1.9.0
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 +11 -6
- package/cjs/editor/countInfoExtra.js +9 -14
- package/cjs/editor/index.d.ts +1 -1
- package/cjs/editor/objectKey.js +5 -7
- package/cjs/editor/value.js +9 -15
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +12 -0
- package/cjs/node.js +4 -1
- package/cjs/value.d.ts +1 -0
- package/cjs/value.js +79 -27
- package/esm/editor/countInfoExtra.js +9 -14
- package/esm/editor/index.d.ts +1 -1
- package/esm/editor/objectKey.js +5 -7
- package/esm/editor/value.js +9 -15
- package/esm/index.d.ts +3 -0
- package/esm/index.js +1 -0
- package/esm/node.js +3 -1
- package/esm/value.d.ts +1 -0
- package/esm/value.js +72 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -452,8 +452,9 @@ export default function Demo() {
|
|
|
452
452
|
## Editor JSON
|
|
453
453
|
|
|
454
454
|
```tsx mdx:preview
|
|
455
|
-
import React from 'react';
|
|
455
|
+
import React, { useRef } from 'react';
|
|
456
456
|
import JsonViewEditor from '@uiw/react-json-view/editor';
|
|
457
|
+
import { type SemicolonProps, useHighlight } from '@uiw/react-json-view';
|
|
457
458
|
|
|
458
459
|
const object = {
|
|
459
460
|
string: 'Lorem ipsum dolor sit amet',
|
|
@@ -472,12 +473,14 @@ const object = {
|
|
|
472
473
|
nestedArray: [ [1, 2], [3, 4], { a: 1} ],
|
|
473
474
|
}
|
|
474
475
|
|
|
475
|
-
const ObjectKey = ({ value, keyName, parentName,
|
|
476
|
+
const ObjectKey: SemicolonProps['render'] = ({ value, keyName, parentName, ...props }) => {
|
|
477
|
+
const $edit = useRef<HTMLSpanElement & HTMLModElement>(null);
|
|
478
|
+
useHighlight({ value, highlightUpdates: true, highlightContainer: $edit });
|
|
476
479
|
if (keyName === 'integer' && typeof value === 'number' && value > 40) {
|
|
477
|
-
return <del {...
|
|
480
|
+
return <del {...props} ref={$edit} />;
|
|
478
481
|
}
|
|
479
|
-
return <span {...
|
|
480
|
-
}
|
|
482
|
+
return <span {...props} ref={$edit} />;
|
|
483
|
+
}
|
|
481
484
|
|
|
482
485
|
export default function Demo() {
|
|
483
486
|
return (
|
|
@@ -663,6 +666,8 @@ export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttr
|
|
|
663
666
|
displayDataTypes?: boolean;
|
|
664
667
|
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
|
|
665
668
|
displayObjectSize?: boolean;
|
|
669
|
+
/** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
|
|
670
|
+
shortenTextAfterLength?: number;
|
|
666
671
|
/** Define the root node name. @default undefined */
|
|
667
672
|
keyName?: string | number;
|
|
668
673
|
/** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
|
|
@@ -721,7 +726,7 @@ export interface CountInfoProps {
|
|
|
721
726
|
```ts
|
|
722
727
|
import { JsonViewProps } from '@uiw/react-json-view';
|
|
723
728
|
import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
|
|
724
|
-
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
729
|
+
export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
|
|
725
730
|
/**
|
|
726
731
|
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
727
732
|
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
@@ -15,6 +15,7 @@ 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;
|
|
18
19
|
var visible = props.visible,
|
|
19
20
|
showTools = props.showTools,
|
|
20
21
|
editable = props.editable,
|
|
@@ -27,8 +28,8 @@ function CountInfoExtra(props) {
|
|
|
27
28
|
onAdd = props.onAdd,
|
|
28
29
|
onDelete = props.onDelete;
|
|
29
30
|
if (!visible || !showTools) return null;
|
|
30
|
-
var click =
|
|
31
|
-
|
|
31
|
+
var click = function click(_x) {
|
|
32
|
+
return (_ref = _ref || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee(event) {
|
|
32
33
|
var keyOrValue, isArray, isAdd, result, maybeAdd;
|
|
33
34
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
|
|
34
35
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -54,13 +55,10 @@ function CountInfoExtra(props) {
|
|
|
54
55
|
return _context.stop();
|
|
55
56
|
}
|
|
56
57
|
}, _callee);
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}();
|
|
62
|
-
var deleteHandle = /*#__PURE__*/function () {
|
|
63
|
-
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(event) {
|
|
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) {
|
|
64
62
|
var maybeDelete;
|
|
65
63
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
|
|
66
64
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -90,11 +88,8 @@ function CountInfoExtra(props) {
|
|
|
90
88
|
return _context2.stop();
|
|
91
89
|
}
|
|
92
90
|
}, _callee2);
|
|
93
|
-
}));
|
|
94
|
-
|
|
95
|
-
return _ref2.apply(this, arguments);
|
|
96
|
-
};
|
|
97
|
-
}();
|
|
91
|
+
}))).apply(this, arguments);
|
|
92
|
+
};
|
|
98
93
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
99
94
|
children: [editable && onAdd && /*#__PURE__*/(0, _jsxRuntime.jsx)(_add.AddIcon, {
|
|
100
95
|
onClick: click
|
package/cjs/editor/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { JsonViewProps } from '../';
|
|
3
3
|
import type { CountInfoExtraProps } from './countInfoExtra';
|
|
4
|
-
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
4
|
+
export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
|
|
5
5
|
/**
|
|
6
6
|
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
7
7
|
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
package/cjs/editor/objectKey.js
CHANGED
|
@@ -16,6 +16,7 @@ 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;
|
|
19
20
|
var className = props.className,
|
|
20
21
|
value = props.value,
|
|
21
22
|
keyName = props.keyName,
|
|
@@ -58,8 +59,8 @@ var ObjectKey = function ObjectKey(props) {
|
|
|
58
59
|
(_$edit$current = $edit.current) === null || _$edit$current === void 0 || _$edit$current.focus();
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
|
-
var blur =
|
|
62
|
-
|
|
62
|
+
var blur = function blur() {
|
|
63
|
+
return (_ref = _ref || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
|
|
63
64
|
var _$edit$current2, result;
|
|
64
65
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
|
|
65
66
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -98,11 +99,8 @@ var ObjectKey = function ObjectKey(props) {
|
|
|
98
99
|
return _context.stop();
|
|
99
100
|
}
|
|
100
101
|
}, _callee);
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
return _ref.apply(this, arguments);
|
|
104
|
-
};
|
|
105
|
-
}();
|
|
102
|
+
}))).apply(this, arguments);
|
|
103
|
+
};
|
|
106
104
|
var focus = function focus() {
|
|
107
105
|
if ($edit.current) {
|
|
108
106
|
var _$edit$current3;
|
package/cjs/editor/value.js
CHANGED
|
@@ -27,7 +27,7 @@ var Quotes = function Quotes(_ref) {
|
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
function ReValue(props) {
|
|
30
|
-
var _typeMap$typeStr;
|
|
30
|
+
var _ref2, _typeMap$typeStr, _ref3;
|
|
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 =
|
|
85
|
-
|
|
84
|
+
var blur = function blur() {
|
|
85
|
+
return (_ref2 = _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) {
|
|
@@ -158,11 +158,8 @@ function ReValue(props) {
|
|
|
158
158
|
return _context.stop();
|
|
159
159
|
}
|
|
160
160
|
}, _callee);
|
|
161
|
-
}));
|
|
162
|
-
|
|
163
|
-
return _ref2.apply(this, arguments);
|
|
164
|
-
};
|
|
165
|
-
}();
|
|
161
|
+
}))).apply(this, arguments);
|
|
162
|
+
};
|
|
166
163
|
var defaultStyle = {
|
|
167
164
|
minWidth: 34,
|
|
168
165
|
minHeight: 18,
|
|
@@ -189,8 +186,8 @@ function ReValue(props) {
|
|
|
189
186
|
if (typeStr === 'null' || typeStr === 'undefined') {
|
|
190
187
|
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
191
188
|
}
|
|
192
|
-
var deleteHandle =
|
|
193
|
-
|
|
189
|
+
var deleteHandle = function deleteHandle(_x) {
|
|
190
|
+
return (_ref3 = _ref3 || (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(evn) {
|
|
194
191
|
var maybeDelete;
|
|
195
192
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
|
|
196
193
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -215,11 +212,8 @@ function ReValue(props) {
|
|
|
215
212
|
return _context2.stop();
|
|
216
213
|
}
|
|
217
214
|
}, _callee2);
|
|
218
|
-
}));
|
|
219
|
-
|
|
220
|
-
return _ref3.apply(this, arguments);
|
|
221
|
-
};
|
|
222
|
-
}();
|
|
215
|
+
}))).apply(this, arguments);
|
|
216
|
+
};
|
|
223
217
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
224
218
|
children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
|
|
225
219
|
style: style,
|
package/cjs/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { MetaProps } from './comps/meta';
|
|
|
7
7
|
import type { CountInfoExtraProps } from './editor/countInfoExtra';
|
|
8
8
|
export * from './node';
|
|
9
9
|
export * from './value';
|
|
10
|
+
export * from './semicolon';
|
|
10
11
|
export interface CountInfoProps {
|
|
11
12
|
count: number;
|
|
12
13
|
level: number;
|
|
@@ -32,6 +33,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
32
33
|
displayDataTypes?: boolean;
|
|
33
34
|
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
|
|
34
35
|
displayObjectSize?: boolean;
|
|
36
|
+
/** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
|
|
37
|
+
shortenTextAfterLength?: number;
|
|
35
38
|
/** Define the root node name. @default undefined */
|
|
36
39
|
keyName?: string | number;
|
|
37
40
|
/** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
|
package/cjs/index.js
CHANGED
|
@@ -35,6 +35,18 @@ Object.keys(_value).forEach(function (key) {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
|
+
var _semicolon = require("./semicolon");
|
|
39
|
+
Object.keys(_semicolon).forEach(function (key) {
|
|
40
|
+
if (key === "default" || key === "__esModule") return;
|
|
41
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
42
|
+
if (key in exports && exports[key] === _semicolon[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _semicolon[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
38
50
|
var _excluded = ["value", "style", "className"];
|
|
39
51
|
var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
40
52
|
var value = props.value,
|
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", "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", "onCopied", "onExpand", "parentValue", "setParentValue"];
|
|
23
23
|
function getLength(obj) {
|
|
24
24
|
try {
|
|
25
25
|
return Object.keys(obj).length;
|
|
@@ -61,6 +61,8 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
61
61
|
objectSortKeys = _props$objectSortKeys === void 0 ? false : _props$objectSortKeys,
|
|
62
62
|
_props$indentWidth = props.indentWidth,
|
|
63
63
|
indentWidth = _props$indentWidth === void 0 ? 15 : _props$indentWidth,
|
|
64
|
+
_props$shortenTextAft = props.shortenTextAfterLength,
|
|
65
|
+
shortenTextAfterLength = _props$shortenTextAft === void 0 ? 20 : _props$shortenTextAft,
|
|
64
66
|
collapsed = props.collapsed,
|
|
65
67
|
_props$level = props.level,
|
|
66
68
|
level = _props$level === void 0 ? 1 : _props$level,
|
|
@@ -114,6 +116,7 @@ var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
114
116
|
displayDataTypes: displayDataTypes,
|
|
115
117
|
displayObjectSize: displayObjectSize,
|
|
116
118
|
enableClipboard: enableClipboard,
|
|
119
|
+
shortenTextAfterLength: shortenTextAfterLength,
|
|
117
120
|
level: level + 1,
|
|
118
121
|
parentValue: value,
|
|
119
122
|
indentWidth: indentWidth,
|
package/cjs/value.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
55
55
|
enableClipboard: boolean;
|
|
56
56
|
indentWidth: number;
|
|
57
57
|
level?: number;
|
|
58
|
+
shortenTextAfterLength?: JsonViewProps<T>['shortenTextAfterLength'];
|
|
58
59
|
namespace?: Array<string | number>;
|
|
59
60
|
quotes?: JsonViewProps<T>['quotes'];
|
|
60
61
|
components?: JsonViewProps<T>['components'];
|
package/cjs/value.js
CHANGED
|
@@ -17,8 +17,10 @@ var _meta = require("./comps/meta");
|
|
|
17
17
|
var _copied = require("./copied");
|
|
18
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
19
|
var _excluded = ["children", "style"],
|
|
20
|
-
_excluded2 = ["
|
|
21
|
-
_excluded3 = ["
|
|
20
|
+
_excluded2 = ["children", "length", "style"],
|
|
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"],
|
|
23
|
+
_excluded5 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
22
24
|
var Line = function Line(props) {
|
|
23
25
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
24
26
|
};
|
|
@@ -127,6 +129,55 @@ function getValueString(value) {
|
|
|
127
129
|
content: content
|
|
128
130
|
};
|
|
129
131
|
}
|
|
132
|
+
var RenderShortenTextValue = function RenderShortenTextValue(_ref2) {
|
|
133
|
+
var children = _ref2.children,
|
|
134
|
+
length = _ref2.length,
|
|
135
|
+
style = _ref2.style,
|
|
136
|
+
rest = (0, _objectWithoutProperties2["default"])(_ref2, _excluded2);
|
|
137
|
+
var childrenStr = children;
|
|
138
|
+
var _useState = (0, _react.useState)(length && childrenStr.length >= length),
|
|
139
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
140
|
+
shorten = _useState2[0],
|
|
141
|
+
setShorten = _useState2[1];
|
|
142
|
+
var click = function click() {
|
|
143
|
+
console.log(shorten);
|
|
144
|
+
if (length && childrenStr.length <= length) return setShorten(false);
|
|
145
|
+
setShorten(!shorten);
|
|
146
|
+
};
|
|
147
|
+
var text = shorten ? "".concat(childrenStr.slice(0, length), "...") : childrenStr;
|
|
148
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(RenderStringValue, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rest), {}, {
|
|
149
|
+
style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
|
|
150
|
+
cursor: 'pointer'
|
|
151
|
+
}),
|
|
152
|
+
onClick: click,
|
|
153
|
+
children: text
|
|
154
|
+
}));
|
|
155
|
+
};
|
|
156
|
+
RenderShortenTextValue.displayName = 'JVR.RenderShortenTextValue';
|
|
157
|
+
var RenderStringValue = function RenderStringValue(_ref3) {
|
|
158
|
+
var color = _ref3.color,
|
|
159
|
+
style = _ref3.style,
|
|
160
|
+
isURL = _ref3.isURL,
|
|
161
|
+
href = _ref3.href,
|
|
162
|
+
children = _ref3.children,
|
|
163
|
+
rest = (0, _objectWithoutProperties2["default"])(_ref3, _excluded3);
|
|
164
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
165
|
+
color: color,
|
|
166
|
+
style: style
|
|
167
|
+
}, rest), {}, {
|
|
168
|
+
className: "w-rjv-value",
|
|
169
|
+
children: [isURL && /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
170
|
+
href: href,
|
|
171
|
+
style: {
|
|
172
|
+
color: color
|
|
173
|
+
},
|
|
174
|
+
target: "_blank",
|
|
175
|
+
rel: "noopener noreferrer",
|
|
176
|
+
children: children
|
|
177
|
+
}), !isURL && children]
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
180
|
+
RenderStringValue.displayName = 'JVR.RenderStringValue';
|
|
130
181
|
function ValueView(props) {
|
|
131
182
|
var _typeMap$type;
|
|
132
183
|
var value = props.value,
|
|
@@ -145,7 +196,8 @@ function ValueView(props) {
|
|
|
145
196
|
enableClipboard = props.enableClipboard,
|
|
146
197
|
displayObjectSize = props.displayObjectSize,
|
|
147
198
|
displayDataTypes = props.displayDataTypes,
|
|
148
|
-
|
|
199
|
+
shortenTextAfterLength = props.shortenTextAfterLength,
|
|
200
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded4);
|
|
149
201
|
var color = '';
|
|
150
202
|
var style = {};
|
|
151
203
|
var _getValueString = getValueString(value),
|
|
@@ -168,10 +220,10 @@ function ValueView(props) {
|
|
|
168
220
|
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
169
221
|
}
|
|
170
222
|
color = ((_typeMap$type = typeMap[type]) === null || _typeMap$type === void 0 ? void 0 : _typeMap$type.color) || '';
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
showTools =
|
|
174
|
-
setShowTools =
|
|
223
|
+
var _useState3 = (0, _react.useState)(false),
|
|
224
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
225
|
+
showTools = _useState4[0],
|
|
226
|
+
setShowTools = _useState4[1];
|
|
175
227
|
var tools = (0, _react.useMemo)(function () {
|
|
176
228
|
return enableClipboard && showTools && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
177
229
|
show: showTools,
|
|
@@ -211,24 +263,24 @@ function ValueView(props) {
|
|
|
211
263
|
content: content,
|
|
212
264
|
children: content
|
|
213
265
|
});
|
|
214
|
-
var valueView =
|
|
266
|
+
var valueView = shortenTextAfterLength && type === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(RenderShortenTextValue, {
|
|
267
|
+
color: color,
|
|
268
|
+
href: isURL ? value.href : '',
|
|
269
|
+
style: style,
|
|
270
|
+
isURL: isURL,
|
|
271
|
+
length: shortenTextAfterLength,
|
|
272
|
+
children: content
|
|
273
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(RenderStringValue, {
|
|
215
274
|
color: color,
|
|
275
|
+
href: isURL ? value.href : '',
|
|
216
276
|
style: style,
|
|
217
|
-
|
|
218
|
-
children:
|
|
219
|
-
href: value.href,
|
|
220
|
-
style: {
|
|
221
|
-
color: color
|
|
222
|
-
},
|
|
223
|
-
target: "_blank",
|
|
224
|
-
rel: "noopener noreferrer",
|
|
225
|
-
children: content
|
|
226
|
-
}) : content
|
|
277
|
+
isURL: isURL,
|
|
278
|
+
children: content
|
|
227
279
|
});
|
|
228
280
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, eventProps), {}, {
|
|
229
281
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
230
282
|
ref: null,
|
|
231
|
-
children: [renderKey, /*#__PURE__*/(0, _jsxRuntime.jsx)(Colon, {}), typeView, valueView, tools]
|
|
283
|
+
children: [renderKey, /*#__PURE__*/(0, _jsxRuntime.jsx)(Colon, {}), typeView, reView ? reView : valueView, tools]
|
|
232
284
|
}))
|
|
233
285
|
}));
|
|
234
286
|
}
|
|
@@ -250,14 +302,14 @@ function ValueView(props) {
|
|
|
250
302
|
}));
|
|
251
303
|
}
|
|
252
304
|
ValueView.displayName = 'JVR.ValueView';
|
|
253
|
-
var Label = /*#__PURE__*/(0, _react.forwardRef)(function (
|
|
254
|
-
var children =
|
|
255
|
-
color =
|
|
256
|
-
fontSize =
|
|
257
|
-
opacity =
|
|
258
|
-
paddingRight =
|
|
259
|
-
style =
|
|
260
|
-
reset = (0, _objectWithoutProperties2["default"])(
|
|
305
|
+
var Label = /*#__PURE__*/(0, _react.forwardRef)(function (_ref4, ref) {
|
|
306
|
+
var children = _ref4.children,
|
|
307
|
+
color = _ref4.color,
|
|
308
|
+
fontSize = _ref4.fontSize,
|
|
309
|
+
opacity = _ref4.opacity,
|
|
310
|
+
paddingRight = _ref4.paddingRight,
|
|
311
|
+
style = _ref4.style,
|
|
312
|
+
reset = (0, _objectWithoutProperties2["default"])(_ref4, _excluded5);
|
|
261
313
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
262
314
|
style: (0, _objectSpread2["default"])({
|
|
263
315
|
color: color,
|
|
@@ -6,6 +6,7 @@ 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;
|
|
9
10
|
var {
|
|
10
11
|
visible,
|
|
11
12
|
showTools,
|
|
@@ -20,8 +21,8 @@ export function CountInfoExtra(props) {
|
|
|
20
21
|
onDelete
|
|
21
22
|
} = props;
|
|
22
23
|
if (!visible || !showTools) return null;
|
|
23
|
-
var click =
|
|
24
|
-
|
|
24
|
+
var click = function click(_x) {
|
|
25
|
+
return (_ref = _ref || _asyncToGenerator(function* (event) {
|
|
25
26
|
event.stopPropagation();
|
|
26
27
|
var keyOrValue = 'AddKeyOrValue';
|
|
27
28
|
var isArray = Array.isArray(value);
|
|
@@ -35,13 +36,10 @@ export function CountInfoExtra(props) {
|
|
|
35
36
|
setValue(result);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}();
|
|
43
|
-
var deleteHandle = /*#__PURE__*/function () {
|
|
44
|
-
var _ref2 = _asyncToGenerator(function* (event) {
|
|
39
|
+
})).apply(this, arguments);
|
|
40
|
+
};
|
|
41
|
+
var deleteHandle = function deleteHandle(_x2) {
|
|
42
|
+
return (_ref2 = _ref2 || _asyncToGenerator(function* (event) {
|
|
45
43
|
event.stopPropagation();
|
|
46
44
|
if (onDelete && (keyName || typeof keyName === 'number') && parentValue) {
|
|
47
45
|
var maybeDelete = yield onDelete(keyName, value, parentValue, {
|
|
@@ -57,11 +55,8 @@ export function CountInfoExtra(props) {
|
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
return _ref2.apply(this, arguments);
|
|
63
|
-
};
|
|
64
|
-
}();
|
|
58
|
+
})).apply(this, arguments);
|
|
59
|
+
};
|
|
65
60
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
66
61
|
children: [editable && onAdd && /*#__PURE__*/_jsx(AddIcon, {
|
|
67
62
|
onClick: click
|
package/esm/editor/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { JsonViewProps } from '../';
|
|
3
3
|
import type { CountInfoExtraProps } from './countInfoExtra';
|
|
4
|
-
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
4
|
+
export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
|
|
5
5
|
/**
|
|
6
6
|
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
7
7
|
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
package/esm/editor/objectKey.js
CHANGED
|
@@ -7,6 +7,7 @@ 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;
|
|
10
11
|
var {
|
|
11
12
|
className,
|
|
12
13
|
value,
|
|
@@ -42,8 +43,8 @@ export var ObjectKey = props => {
|
|
|
42
43
|
(_$edit$current = $edit.current) == null || _$edit$current.focus();
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
|
-
var blur =
|
|
46
|
-
|
|
46
|
+
var blur = function blur() {
|
|
47
|
+
return (_ref = _ref || _asyncToGenerator(function* () {
|
|
47
48
|
if ($edit.current) {
|
|
48
49
|
var _$edit$current2;
|
|
49
50
|
if (onEdit) {
|
|
@@ -65,11 +66,8 @@ export var ObjectKey = props => {
|
|
|
65
66
|
(_$edit$current2 = $edit.current) == null || _$edit$current2.focus();
|
|
66
67
|
}
|
|
67
68
|
setEditable(false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return _ref.apply(this, arguments);
|
|
71
|
-
};
|
|
72
|
-
}();
|
|
69
|
+
})).apply(this, arguments);
|
|
70
|
+
};
|
|
73
71
|
var focus = () => {
|
|
74
72
|
if ($edit.current) {
|
|
75
73
|
var _$edit$current3;
|
package/esm/editor/value.js
CHANGED
|
@@ -21,7 +21,7 @@ var Quotes = _ref => {
|
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
23
|
export function ReValue(props) {
|
|
24
|
-
var _typeMap$typeStr;
|
|
24
|
+
var _ref2, _typeMap$typeStr, _ref3;
|
|
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 =
|
|
69
|
-
|
|
68
|
+
var blur = function blur() {
|
|
69
|
+
return (_ref2 = _ref2 || _asyncToGenerator(function* () {
|
|
70
70
|
if (!editableValue) return;
|
|
71
71
|
setEditable(false);
|
|
72
72
|
if ($edit.current) {
|
|
@@ -123,11 +123,8 @@ export function ReValue(props) {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return _ref2.apply(this, arguments);
|
|
129
|
-
};
|
|
130
|
-
}();
|
|
126
|
+
})).apply(this, arguments);
|
|
127
|
+
};
|
|
131
128
|
var defaultStyle = {
|
|
132
129
|
minWidth: 34,
|
|
133
130
|
minHeight: 18,
|
|
@@ -155,8 +152,8 @@ export function ReValue(props) {
|
|
|
155
152
|
if (typeStr === 'null' || typeStr === 'undefined') {
|
|
156
153
|
typeView = /*#__PURE__*/_jsx(Fragment, {});
|
|
157
154
|
}
|
|
158
|
-
var deleteHandle =
|
|
159
|
-
|
|
155
|
+
var deleteHandle = function deleteHandle(_x) {
|
|
156
|
+
return (_ref3 = _ref3 || _asyncToGenerator(function* (evn) {
|
|
160
157
|
evn.stopPropagation();
|
|
161
158
|
if (data && keyName && keyName in data && setValue && onDelete) {
|
|
162
159
|
var maybeDelete = yield onDelete(keyName, value, parentValue, {
|
|
@@ -167,11 +164,8 @@ export function ReValue(props) {
|
|
|
167
164
|
setValue(_extends({}, data));
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
return _ref3.apply(this, arguments);
|
|
173
|
-
};
|
|
174
|
-
}();
|
|
167
|
+
})).apply(this, arguments);
|
|
168
|
+
};
|
|
175
169
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
176
170
|
children: [displayDataTypes && typeView, /*#__PURE__*/_jsx(Quotes, {
|
|
177
171
|
style: style,
|
package/esm/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { MetaProps } from './comps/meta';
|
|
|
7
7
|
import type { CountInfoExtraProps } from './editor/countInfoExtra';
|
|
8
8
|
export * from './node';
|
|
9
9
|
export * from './value';
|
|
10
|
+
export * from './semicolon';
|
|
10
11
|
export interface CountInfoProps {
|
|
11
12
|
count: number;
|
|
12
13
|
level: number;
|
|
@@ -32,6 +33,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
32
33
|
displayDataTypes?: boolean;
|
|
33
34
|
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
|
|
34
35
|
displayObjectSize?: boolean;
|
|
36
|
+
/** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
|
|
37
|
+
shortenTextAfterLength?: number;
|
|
35
38
|
/** Define the root node name. @default undefined */
|
|
36
39
|
keyName?: string | number;
|
|
37
40
|
/** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
|
package/esm/index.js
CHANGED
package/esm/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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", "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", "onCopied", "onExpand", "parentValue", "setParentValue"];
|
|
4
4
|
import { Fragment, useId, cloneElement, useState, useEffect, forwardRef } from 'react';
|
|
5
5
|
import { ValueView, Colon, Label, Line, typeMap } from './value';
|
|
6
6
|
import { TriangleArrow } from './arrow/TriangleArrow';
|
|
@@ -46,6 +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
50
|
collapsed,
|
|
50
51
|
level = 1,
|
|
51
52
|
keyid = 'root',
|
|
@@ -93,6 +94,7 @@ export var RootNode = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
93
94
|
displayDataTypes,
|
|
94
95
|
displayObjectSize,
|
|
95
96
|
enableClipboard,
|
|
97
|
+
shortenTextAfterLength,
|
|
96
98
|
level: level + 1,
|
|
97
99
|
parentValue: value,
|
|
98
100
|
indentWidth,
|
package/esm/value.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
55
55
|
enableClipboard: boolean;
|
|
56
56
|
indentWidth: number;
|
|
57
57
|
level?: number;
|
|
58
|
+
shortenTextAfterLength?: JsonViewProps<T>['shortenTextAfterLength'];
|
|
58
59
|
namespace?: Array<string | number>;
|
|
59
60
|
quotes?: JsonViewProps<T>['quotes'];
|
|
60
61
|
components?: JsonViewProps<T>['components'];
|
package/esm/value.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
3
|
var _excluded = ["children", "style"],
|
|
4
|
-
_excluded2 = ["
|
|
5
|
-
_excluded3 = ["
|
|
4
|
+
_excluded2 = ["children", "length", "style"],
|
|
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"],
|
|
7
|
+
_excluded5 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
6
8
|
import { Fragment, forwardRef, useMemo, useState } from 'react';
|
|
7
9
|
import { Meta } from './comps/meta';
|
|
8
10
|
import { Copied } from './copied';
|
|
@@ -109,6 +111,56 @@ export function getValueString(value) {
|
|
|
109
111
|
content
|
|
110
112
|
};
|
|
111
113
|
}
|
|
114
|
+
var RenderShortenTextValue = _ref2 => {
|
|
115
|
+
var {
|
|
116
|
+
children,
|
|
117
|
+
length,
|
|
118
|
+
style
|
|
119
|
+
} = _ref2,
|
|
120
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
121
|
+
var childrenStr = children;
|
|
122
|
+
var [shorten, setShorten] = useState(length && childrenStr.length >= length);
|
|
123
|
+
var click = () => {
|
|
124
|
+
console.log(shorten);
|
|
125
|
+
if (length && childrenStr.length <= length) return setShorten(false);
|
|
126
|
+
setShorten(!shorten);
|
|
127
|
+
};
|
|
128
|
+
var text = shorten ? childrenStr.slice(0, length) + "..." : childrenStr;
|
|
129
|
+
return /*#__PURE__*/_jsx(RenderStringValue, _extends({}, rest, {
|
|
130
|
+
style: _extends({}, style, {
|
|
131
|
+
cursor: 'pointer'
|
|
132
|
+
}),
|
|
133
|
+
onClick: click,
|
|
134
|
+
children: text
|
|
135
|
+
}));
|
|
136
|
+
};
|
|
137
|
+
RenderShortenTextValue.displayName = 'JVR.RenderShortenTextValue';
|
|
138
|
+
var RenderStringValue = _ref3 => {
|
|
139
|
+
var {
|
|
140
|
+
color,
|
|
141
|
+
style,
|
|
142
|
+
isURL,
|
|
143
|
+
href,
|
|
144
|
+
children
|
|
145
|
+
} = _ref3,
|
|
146
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded3);
|
|
147
|
+
return /*#__PURE__*/_jsxs(Label, _extends({
|
|
148
|
+
color: color,
|
|
149
|
+
style: style
|
|
150
|
+
}, rest, {
|
|
151
|
+
className: "w-rjv-value",
|
|
152
|
+
children: [isURL && /*#__PURE__*/_jsx("a", {
|
|
153
|
+
href: href,
|
|
154
|
+
style: {
|
|
155
|
+
color
|
|
156
|
+
},
|
|
157
|
+
target: "_blank",
|
|
158
|
+
rel: "noopener noreferrer",
|
|
159
|
+
children: children
|
|
160
|
+
}), !isURL && children]
|
|
161
|
+
}));
|
|
162
|
+
};
|
|
163
|
+
RenderStringValue.displayName = 'JVR.RenderStringValue';
|
|
112
164
|
export function ValueView(props) {
|
|
113
165
|
var _typeMap$type;
|
|
114
166
|
var {
|
|
@@ -124,9 +176,10 @@ export function ValueView(props) {
|
|
|
124
176
|
components = {},
|
|
125
177
|
quotes,
|
|
126
178
|
enableClipboard,
|
|
127
|
-
displayDataTypes
|
|
179
|
+
displayDataTypes,
|
|
180
|
+
shortenTextAfterLength
|
|
128
181
|
} = props,
|
|
129
|
-
reset = _objectWithoutPropertiesLoose(props,
|
|
182
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded4);
|
|
130
183
|
var color = '';
|
|
131
184
|
var style = {};
|
|
132
185
|
var {
|
|
@@ -184,24 +237,24 @@ export function ValueView(props) {
|
|
|
184
237
|
content,
|
|
185
238
|
children: content
|
|
186
239
|
});
|
|
187
|
-
var valueView =
|
|
240
|
+
var valueView = shortenTextAfterLength && type === 'string' ? /*#__PURE__*/_jsx(RenderShortenTextValue, {
|
|
241
|
+
color: color,
|
|
242
|
+
href: isURL ? value.href : '',
|
|
243
|
+
style: style,
|
|
244
|
+
isURL: isURL,
|
|
245
|
+
length: shortenTextAfterLength,
|
|
246
|
+
children: content
|
|
247
|
+
}) : /*#__PURE__*/_jsx(RenderStringValue, {
|
|
188
248
|
color: color,
|
|
249
|
+
href: isURL ? value.href : '',
|
|
189
250
|
style: style,
|
|
190
|
-
|
|
191
|
-
children:
|
|
192
|
-
href: value.href,
|
|
193
|
-
style: {
|
|
194
|
-
color
|
|
195
|
-
},
|
|
196
|
-
target: "_blank",
|
|
197
|
-
rel: "noopener noreferrer",
|
|
198
|
-
children: content
|
|
199
|
-
}) : content
|
|
251
|
+
isURL: isURL,
|
|
252
|
+
children: content
|
|
200
253
|
});
|
|
201
254
|
return /*#__PURE__*/_jsx(Line, _extends({}, eventProps, {
|
|
202
255
|
children: /*#__PURE__*/_jsxs(Label, _extends({}, reset, {
|
|
203
256
|
ref: null,
|
|
204
|
-
children: [renderKey, /*#__PURE__*/_jsx(Colon, {}), typeView, valueView, tools]
|
|
257
|
+
children: [renderKey, /*#__PURE__*/_jsx(Colon, {}), typeView, reView ? reView : valueView, tools]
|
|
205
258
|
}))
|
|
206
259
|
}));
|
|
207
260
|
}
|
|
@@ -223,7 +276,7 @@ export function ValueView(props) {
|
|
|
223
276
|
}));
|
|
224
277
|
}
|
|
225
278
|
ValueView.displayName = 'JVR.ValueView';
|
|
226
|
-
export var Label = /*#__PURE__*/forwardRef((
|
|
279
|
+
export var Label = /*#__PURE__*/forwardRef((_ref4, ref) => {
|
|
227
280
|
var {
|
|
228
281
|
children,
|
|
229
282
|
color,
|
|
@@ -231,8 +284,8 @@ export var Label = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
231
284
|
opacity,
|
|
232
285
|
paddingRight,
|
|
233
286
|
style
|
|
234
|
-
} =
|
|
235
|
-
reset = _objectWithoutPropertiesLoose(
|
|
287
|
+
} = _ref4,
|
|
288
|
+
reset = _objectWithoutPropertiesLoose(_ref4, _excluded5);
|
|
236
289
|
return /*#__PURE__*/_jsx("span", _extends({
|
|
237
290
|
style: _extends({
|
|
238
291
|
color,
|