@uiw/react-json-view 1.8.2 → 1.8.4
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 +15 -45
- package/cjs/editor/countInfoExtra.d.ts +4 -1
- package/cjs/editor/countInfoExtra.js +4 -1
- package/cjs/editor/value.d.ts +1 -0
- package/cjs/editor/value.js +15 -3
- package/cjs/index.d.ts +13 -2
- package/cjs/index.js +1 -1
- package/cjs/node.d.ts +2 -2
- package/cjs/node.js +61 -36
- package/cjs/value.d.ts +3 -14
- package/cjs/value.js +17 -15
- package/esm/editor/countInfoExtra.d.ts +4 -1
- package/esm/editor/countInfoExtra.js +4 -1
- package/esm/editor/value.d.ts +1 -0
- package/esm/editor/value.js +10 -4
- package/esm/index.d.ts +13 -2
- package/esm/index.js +2 -2
- package/esm/node.d.ts +2 -2
- package/esm/node.js +61 -36
- package/esm/value.d.ts +3 -14
- package/esm/value.js +13 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -280,47 +280,6 @@ export default function Demo() {
|
|
|
280
280
|
|
|
281
281
|
## Render
|
|
282
282
|
|
|
283
|
-
```tsx mdx:preview
|
|
284
|
-
import React from 'react';
|
|
285
|
-
import JsonView from '@uiw/react-json-view';
|
|
286
|
-
|
|
287
|
-
const object = {
|
|
288
|
-
string: 'Lorem ipsum dolor sit amet',
|
|
289
|
-
integer: 42,
|
|
290
|
-
float: 114.514,
|
|
291
|
-
object: {
|
|
292
|
-
'first-child': true,
|
|
293
|
-
'second-child': false,
|
|
294
|
-
'last-child': null,
|
|
295
|
-
},
|
|
296
|
-
}
|
|
297
|
-
export default function Demo() {
|
|
298
|
-
return (
|
|
299
|
-
<JsonView
|
|
300
|
-
value={object}
|
|
301
|
-
keyName="root"
|
|
302
|
-
quotes=""
|
|
303
|
-
displayObjectSize={false}
|
|
304
|
-
displayDataTypes={false}
|
|
305
|
-
style={{
|
|
306
|
-
'--w-rjv-background-color': '#ffffff',
|
|
307
|
-
'--w-rjv-border-left-width': '0',
|
|
308
|
-
}}
|
|
309
|
-
components={{
|
|
310
|
-
braces: () => <span />,
|
|
311
|
-
ellipsis: () => <React.Fragment />,
|
|
312
|
-
objectKey: ({ value, keyName, parentName, ...props}) => {
|
|
313
|
-
if (keyName === 'integer' && typeof value === 'number' && value > 40) {
|
|
314
|
-
return <del {...props} />
|
|
315
|
-
}
|
|
316
|
-
return <span {...props} />
|
|
317
|
-
}
|
|
318
|
-
}}
|
|
319
|
-
/>
|
|
320
|
-
)
|
|
321
|
-
}
|
|
322
|
-
```
|
|
323
|
-
|
|
324
283
|
**Preview Picture**
|
|
325
284
|
|
|
326
285
|
```tsx mdx:preview
|
|
@@ -333,7 +292,7 @@ const object = {
|
|
|
333
292
|
integer: 42,
|
|
334
293
|
}
|
|
335
294
|
|
|
336
|
-
function value({ type, children, value, setValue, keyName, visible, ...props }) {
|
|
295
|
+
function value({ type, children, value, setValue, keyName, parentValue, visible, ...props }) {
|
|
337
296
|
if (type === 'string' && /\.(jpg)$/.test(value)) {
|
|
338
297
|
return (
|
|
339
298
|
<span {...props}>
|
|
@@ -386,7 +345,7 @@ export default function Demo() {
|
|
|
386
345
|
import React from 'react';
|
|
387
346
|
import JsonView from '@uiw/react-json-view';
|
|
388
347
|
|
|
389
|
-
function value({ type, children, visible, keyName, value, setValue, ...props }) {
|
|
348
|
+
function value({ type, children, visible, keyName, parentValue, value, setValue, ...props }) {
|
|
390
349
|
if (value instanceof URL) {
|
|
391
350
|
return (
|
|
392
351
|
<span {...props}>
|
|
@@ -513,7 +472,7 @@ const object = {
|
|
|
513
472
|
nestedArray: [ [1, 2], [3, 4], { a: 1} ],
|
|
514
473
|
}
|
|
515
474
|
|
|
516
|
-
const ObjectKey = ({ value, keyName, parentName, ...reset }) => {
|
|
475
|
+
const ObjectKey = ({ value, keyName, parentName, parentValue, ...reset }) => {
|
|
517
476
|
if (keyName === 'integer' && typeof value === 'number' && value > 40) {
|
|
518
477
|
return <del {...reset} />
|
|
519
478
|
}
|
|
@@ -731,12 +690,23 @@ export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttr
|
|
|
731
690
|
ellipsis?: EllipsisProps['render'];
|
|
732
691
|
arrow?: JSX.Element;
|
|
733
692
|
objectKey?: SemicolonProps['render'];
|
|
734
|
-
value?:
|
|
693
|
+
value?: (props: RenderValueProps<T>) => JSX.Element;
|
|
735
694
|
copied?: CopiedProps<T>['render'];
|
|
736
695
|
countInfo?: (props: CountInfoProps) => JSX.Element;
|
|
737
696
|
countInfoExtra?: (props: Omit<CountInfoExtraProps<T>, 'editable'>) => JSX.Element;
|
|
738
697
|
};
|
|
739
698
|
}
|
|
699
|
+
interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
|
|
700
|
+
type: TypeProps['type'];
|
|
701
|
+
value?: unknown;
|
|
702
|
+
parentValue?: T;
|
|
703
|
+
data?: T;
|
|
704
|
+
visible?: boolean;
|
|
705
|
+
quotes?: JsonViewProps<T>['quotes'];
|
|
706
|
+
namespace?: Array<string | number>;
|
|
707
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
708
|
+
keyName?: ValueViewProps<T>['keyName'];
|
|
709
|
+
}
|
|
740
710
|
declare const JsonView: React.ForwardRefExoticComponent<Omit<JsonViewProps<object>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
741
711
|
export default JsonView;
|
|
742
712
|
export interface CountInfoProps {
|
|
@@ -6,6 +6,7 @@ export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
|
6
6
|
value: T;
|
|
7
7
|
parentValue?: T;
|
|
8
8
|
keyName?: string | number;
|
|
9
|
+
namespace?: Array<string | number>;
|
|
9
10
|
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
10
11
|
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
11
12
|
/**
|
|
@@ -17,6 +18,8 @@ export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
|
17
18
|
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
18
19
|
* @returns Returning false from onDelete will prevent the change from being made.
|
|
19
20
|
*/
|
|
20
|
-
onDelete?: (keyName: string | number, value: T, parentValue: T
|
|
21
|
+
onDelete?: (keyName: string | number, value: T, parentValue: T | null, opt: {
|
|
22
|
+
namespace?: Array<string | number>;
|
|
23
|
+
}) => boolean;
|
|
21
24
|
}
|
|
22
25
|
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -20,6 +20,7 @@ function CountInfoExtra(props) {
|
|
|
20
20
|
editable = props.editable,
|
|
21
21
|
keyName = props.keyName,
|
|
22
22
|
value = props.value,
|
|
23
|
+
namespace = props.namespace,
|
|
23
24
|
parentValue = props.parentValue,
|
|
24
25
|
setValue = props.setValue,
|
|
25
26
|
setParentValue = props.setParentValue,
|
|
@@ -70,7 +71,9 @@ function CountInfoExtra(props) {
|
|
|
70
71
|
break;
|
|
71
72
|
}
|
|
72
73
|
_context2.next = 4;
|
|
73
|
-
return onDelete(keyName, value, parentValue
|
|
74
|
+
return onDelete(keyName, value, parentValue, {
|
|
75
|
+
namespace: namespace
|
|
76
|
+
});
|
|
74
77
|
case 4:
|
|
75
78
|
maybeDelete = _context2.sent;
|
|
76
79
|
if (maybeDelete && setParentValue) {
|
package/cjs/editor/value.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ReValueProps<T extends object> extends React.HTMLAttributes<HTM
|
|
|
7
7
|
keyName?: JsonViewEditorProps<T>['keyName'];
|
|
8
8
|
type: TypeProps['type'];
|
|
9
9
|
value?: unknown;
|
|
10
|
+
parentValue?: T;
|
|
10
11
|
data?: T;
|
|
11
12
|
visible?: boolean;
|
|
12
13
|
namespace?: Array<string | number>;
|
package/cjs/editor/value.js
CHANGED
|
@@ -15,7 +15,7 @@ var _value = require("../value");
|
|
|
15
15
|
var _edit = require("./icon/edit");
|
|
16
16
|
var _delete = require("./icon/delete");
|
|
17
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "namespace", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
|
|
18
|
+
var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "namespace", "displayDataTypes", "editableValue", "parentValue", "onDelete", "onEdit"];
|
|
19
19
|
var Quotes = function Quotes(_ref) {
|
|
20
20
|
var show = _ref.show,
|
|
21
21
|
style = _ref.style,
|
|
@@ -40,6 +40,7 @@ function ReValue(props) {
|
|
|
40
40
|
namespace = props.namespace,
|
|
41
41
|
displayDataTypes = props.displayDataTypes,
|
|
42
42
|
editableValue = props.editableValue,
|
|
43
|
+
parentValue = props.parentValue,
|
|
43
44
|
onDelete = props.onDelete,
|
|
44
45
|
onEdit = props.onEdit,
|
|
45
46
|
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
@@ -190,15 +191,26 @@ function ReValue(props) {
|
|
|
190
191
|
}
|
|
191
192
|
var deleteHandle = /*#__PURE__*/function () {
|
|
192
193
|
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(evn) {
|
|
194
|
+
var maybeDelete;
|
|
193
195
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
|
|
194
196
|
while (1) switch (_context2.prev = _context2.next) {
|
|
195
197
|
case 0:
|
|
196
198
|
evn.stopPropagation();
|
|
197
|
-
if (data && keyName && keyName in data && setValue) {
|
|
199
|
+
if (!(data && keyName && keyName in data && setValue && onDelete)) {
|
|
200
|
+
_context2.next = 6;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
_context2.next = 4;
|
|
204
|
+
return onDelete(keyName, value, parentValue, {
|
|
205
|
+
namespace: namespace
|
|
206
|
+
});
|
|
207
|
+
case 4:
|
|
208
|
+
maybeDelete = _context2.sent;
|
|
209
|
+
if (maybeDelete) {
|
|
198
210
|
delete data[keyName];
|
|
199
211
|
setValue((0, _objectSpread2["default"])({}, data));
|
|
200
212
|
}
|
|
201
|
-
case
|
|
213
|
+
case 6:
|
|
202
214
|
case "end":
|
|
203
215
|
return _context2.stop();
|
|
204
216
|
}
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { SemicolonProps } from './semicolon';
|
|
3
|
-
import type { ValueViewProps } from './value';
|
|
3
|
+
import type { ValueViewProps, TypeProps } from './value';
|
|
4
4
|
import type { CopiedProps } from './copied';
|
|
5
5
|
import type { EllipsisProps } from './comps/ellipsis';
|
|
6
6
|
import type { MetaProps } from './comps/meta';
|
|
@@ -12,6 +12,17 @@ export interface CountInfoProps {
|
|
|
12
12
|
level: number;
|
|
13
13
|
visible: boolean;
|
|
14
14
|
}
|
|
15
|
+
interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
|
|
16
|
+
type: TypeProps['type'];
|
|
17
|
+
value?: unknown;
|
|
18
|
+
parentValue?: T;
|
|
19
|
+
data?: T;
|
|
20
|
+
visible?: boolean;
|
|
21
|
+
quotes?: JsonViewProps<T>['quotes'];
|
|
22
|
+
namespace?: Array<string | number>;
|
|
23
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
24
|
+
keyName?: ValueViewProps<T>['keyName'];
|
|
25
|
+
}
|
|
15
26
|
export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
16
27
|
/** This property contains your input JSON */
|
|
17
28
|
value?: T;
|
|
@@ -48,7 +59,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
48
59
|
ellipsis?: EllipsisProps['render'];
|
|
49
60
|
arrow?: JSX.Element;
|
|
50
61
|
objectKey?: SemicolonProps['render'];
|
|
51
|
-
value?:
|
|
62
|
+
value?: (props: RenderValueProps<T>) => JSX.Element;
|
|
52
63
|
copied?: CopiedProps<T>['render'];
|
|
53
64
|
countInfo?: (props: CountInfoProps) => JSX.Element;
|
|
54
65
|
countInfoExtra?: (props: Omit<CountInfoExtraProps<T>, 'editable'>) => JSX.Element;
|
package/cjs/index.js
CHANGED
|
@@ -49,7 +49,7 @@ var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
49
49
|
}, style);
|
|
50
50
|
var cls = "w-json-view-container w-rjv ".concat(className || '');
|
|
51
51
|
var keyid = (0, _react.useId)();
|
|
52
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_node.
|
|
52
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_node.RootNode, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
53
53
|
className: cls,
|
|
54
54
|
value: value
|
|
55
55
|
}, reset), {}, {
|
package/cjs/node.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FC, PropsWithChildren } from 'react';
|
|
|
2
2
|
import { LabelProps } from './value';
|
|
3
3
|
import { JsonViewProps } from './';
|
|
4
4
|
export declare const CountInfo: FC<PropsWithChildren<LabelProps>>;
|
|
5
|
-
export interface
|
|
5
|
+
export interface RootNodeProps<T extends object> extends JsonViewProps<T> {
|
|
6
6
|
keyName?: string | number;
|
|
7
7
|
keyid?: string;
|
|
8
8
|
level?: number;
|
|
@@ -10,4 +10,4 @@ export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
|
|
|
10
10
|
namespace?: Array<string | number>;
|
|
11
11
|
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
12
12
|
}
|
|
13
|
-
export declare
|
|
13
|
+
export declare const RootNode: import("react").ForwardRefExoticComponent<Omit<RootNodeProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
package/cjs/node.js
CHANGED
|
@@ -4,8 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.CountInfo = void 0;
|
|
8
|
-
exports.RooNode = RooNode;
|
|
7
|
+
exports.RootNode = exports.CountInfo = void 0;
|
|
9
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
@@ -21,20 +20,27 @@ var _ellipsis = require("./comps/ellipsis");
|
|
|
21
20
|
var _meta = require("./comps/meta");
|
|
22
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
22
|
var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "namespace", "onCopied", "onExpand", "parentValue", "setParentValue"];
|
|
23
|
+
function getLength(obj) {
|
|
24
|
+
try {
|
|
25
|
+
return Object.keys(obj).length;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
24
30
|
var CountInfo = function CountInfo(_ref) {
|
|
25
31
|
var children = _ref.children;
|
|
26
|
-
return /*#__PURE__*/(0, _jsxRuntime.
|
|
32
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_value.Label, {
|
|
27
33
|
style: {
|
|
28
34
|
paddingLeft: 4,
|
|
29
35
|
fontStyle: 'italic'
|
|
30
36
|
},
|
|
31
37
|
color: "var(--w-rjv-info-color, #0000004d)",
|
|
32
38
|
className: "w-rjv-object-size",
|
|
33
|
-
children: children
|
|
39
|
+
children: [children, " items"]
|
|
34
40
|
});
|
|
35
41
|
};
|
|
36
42
|
exports.CountInfo = CountInfo;
|
|
37
|
-
function
|
|
43
|
+
var RootNode = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
38
44
|
var _expands$keyid;
|
|
39
45
|
var _props$value = props.value,
|
|
40
46
|
value = _props$value === void 0 ? {} : _props$value,
|
|
@@ -107,12 +113,12 @@ function RooNode(props) {
|
|
|
107
113
|
displayDataTypes: displayDataTypes,
|
|
108
114
|
displayObjectSize: displayObjectSize,
|
|
109
115
|
enableClipboard: enableClipboard,
|
|
116
|
+
level: level + 1,
|
|
117
|
+
parentValue: value,
|
|
110
118
|
indentWidth: indentWidth,
|
|
111
119
|
data: valueData,
|
|
112
120
|
quotes: quotes,
|
|
113
|
-
setValue: setValueData
|
|
114
|
-
renderBraces: components.braces,
|
|
115
|
-
renderValue: components.value
|
|
121
|
+
setValue: setValueData
|
|
116
122
|
};
|
|
117
123
|
var arrowStyle = {
|
|
118
124
|
transform: "rotate(".concat(expand ? '0' : '-90', "deg)"),
|
|
@@ -165,8 +171,8 @@ function RooNode(props) {
|
|
|
165
171
|
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
166
172
|
});
|
|
167
173
|
}
|
|
168
|
-
var countInfo = /*#__PURE__*/(0, _jsxRuntime.
|
|
169
|
-
children:
|
|
174
|
+
var countInfo = /*#__PURE__*/(0, _jsxRuntime.jsx)(CountInfo, {
|
|
175
|
+
children: nameKeys.length
|
|
170
176
|
});
|
|
171
177
|
if (components.countInfo) {
|
|
172
178
|
countInfo = components.countInfo({
|
|
@@ -175,7 +181,22 @@ function RooNode(props) {
|
|
|
175
181
|
visible: expand
|
|
176
182
|
}) || countInfo;
|
|
177
183
|
}
|
|
178
|
-
|
|
184
|
+
if (!displayObjectSize) countInfo = null;
|
|
185
|
+
var countInfoExtra = components.countInfoExtra && components.countInfoExtra({
|
|
186
|
+
count: nameKeys.length,
|
|
187
|
+
level: level,
|
|
188
|
+
showTools: showTools,
|
|
189
|
+
keyName: keyName,
|
|
190
|
+
visible: expand,
|
|
191
|
+
value: valueData,
|
|
192
|
+
namespace: (0, _toConsumableArray2["default"])(namespace),
|
|
193
|
+
parentValue: parentValue,
|
|
194
|
+
setParentValue: setParentValue,
|
|
195
|
+
setValue: setValueData
|
|
196
|
+
});
|
|
197
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
198
|
+
ref: ref
|
|
199
|
+
}, reset), {}, {
|
|
179
200
|
className: "".concat(className, " w-rjv-inner")
|
|
180
201
|
}, eventProps), {}, {
|
|
181
202
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_value.Line, {
|
|
@@ -208,17 +229,7 @@ function RooNode(props) {
|
|
|
208
229
|
isArray: isArray,
|
|
209
230
|
level: level,
|
|
210
231
|
render: components.braces
|
|
211
|
-
}),
|
|
212
|
-
count: nameKeys.length,
|
|
213
|
-
level: level,
|
|
214
|
-
showTools: showTools,
|
|
215
|
-
keyName: keyName,
|
|
216
|
-
visible: expand,
|
|
217
|
-
value: valueData,
|
|
218
|
-
parentValue: parentValue,
|
|
219
|
-
setParentValue: setParentValue,
|
|
220
|
-
setValue: setValueData
|
|
221
|
-
}), enableClipboard && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
232
|
+
}), countInfo, countInfoExtra, enableClipboard && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
222
233
|
show: showTools,
|
|
223
234
|
text: valueData,
|
|
224
235
|
onCopied: onCopied,
|
|
@@ -235,23 +246,12 @@ function RooNode(props) {
|
|
|
235
246
|
key = _ref11[0],
|
|
236
247
|
itemVal = _ref11[1];
|
|
237
248
|
var item = itemVal;
|
|
238
|
-
var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
|
|
239
|
-
value: item,
|
|
240
|
-
"data-keys": keyid,
|
|
241
|
-
quotes: quotes,
|
|
242
|
-
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
|
|
243
|
-
parentName: keyName,
|
|
244
|
-
highlightUpdates: highlightUpdates,
|
|
245
|
-
render: components.objectKey,
|
|
246
|
-
color: typeof key === 'number' ? _value.typeMap['number'].color : '',
|
|
247
|
-
keyName: key
|
|
248
|
-
});
|
|
249
249
|
var isEmpty = Array.isArray(item) && item.length === 0 || (0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
|
|
250
250
|
if (Array.isArray(item) && !isEmpty) {
|
|
251
251
|
var label = isArray ? idx : key;
|
|
252
252
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
253
253
|
className: "w-rjv-wrap",
|
|
254
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
254
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RootNode, (0, _objectSpread2["default"])({
|
|
255
255
|
value: item,
|
|
256
256
|
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [label]),
|
|
257
257
|
keyName: label,
|
|
@@ -262,7 +262,7 @@ function RooNode(props) {
|
|
|
262
262
|
if ((0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && !isEmpty) {
|
|
263
263
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
264
264
|
className: "w-rjv-wrap",
|
|
265
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
265
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RootNode, (0, _objectSpread2["default"])({
|
|
266
266
|
value: item,
|
|
267
267
|
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
|
|
268
268
|
keyName: key,
|
|
@@ -273,9 +273,33 @@ function RooNode(props) {
|
|
|
273
273
|
if (typeof item === 'function') {
|
|
274
274
|
return;
|
|
275
275
|
}
|
|
276
|
+
var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
|
|
277
|
+
value: item,
|
|
278
|
+
"data-keys": keyid,
|
|
279
|
+
quotes: quotes,
|
|
280
|
+
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
|
|
281
|
+
parentName: keyName,
|
|
282
|
+
highlightUpdates: highlightUpdates,
|
|
283
|
+
render: components.objectKey,
|
|
284
|
+
color: typeof key === 'number' ? _value.typeMap['number'].color : '',
|
|
285
|
+
keyName: key
|
|
286
|
+
});
|
|
287
|
+
var length = Array.isArray(item) ? item.length : getLength(item);
|
|
288
|
+
countInfo = /*#__PURE__*/(0, _jsxRuntime.jsx)(CountInfo, {
|
|
289
|
+
children: length
|
|
290
|
+
});
|
|
291
|
+
if (components.countInfo) {
|
|
292
|
+
countInfo = components.countInfo({
|
|
293
|
+
count: length,
|
|
294
|
+
level: level,
|
|
295
|
+
visible: expand
|
|
296
|
+
}) || countInfo;
|
|
297
|
+
}
|
|
276
298
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
299
|
+
components: components,
|
|
277
300
|
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key])
|
|
278
301
|
}, valueViewProps), {}, {
|
|
302
|
+
countInfo: countInfo,
|
|
279
303
|
renderKey: renderKey,
|
|
280
304
|
keyName: key,
|
|
281
305
|
value: item
|
|
@@ -296,4 +320,5 @@ function RooNode(props) {
|
|
|
296
320
|
})
|
|
297
321
|
})]
|
|
298
322
|
}));
|
|
299
|
-
}
|
|
323
|
+
});
|
|
324
|
+
exports.RootNode = RootNode;
|
package/cjs/value.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import type { MetaProps } from './comps/meta';
|
|
3
2
|
import type { JsonViewProps } from './';
|
|
4
3
|
export declare const Line: FC<PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>>;
|
|
5
4
|
export declare const isFloat: (n: number) => boolean;
|
|
@@ -46,19 +45,10 @@ export declare const typeMap: {
|
|
|
46
45
|
};
|
|
47
46
|
};
|
|
48
47
|
export declare const Colon: FC<PropsWithChildren<React.HTMLAttributes<HTMLSpanElement>>>;
|
|
49
|
-
interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
|
|
50
|
-
type: TypeProps['type'];
|
|
51
|
-
value?: unknown;
|
|
52
|
-
data?: T;
|
|
53
|
-
visible?: boolean;
|
|
54
|
-
quotes?: JsonViewProps<T>['quotes'];
|
|
55
|
-
namespace?: Array<string | number>;
|
|
56
|
-
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
57
|
-
keyName?: ValueViewProps<T>['keyName'];
|
|
58
|
-
}
|
|
59
48
|
export interface ValueViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
60
49
|
keyName?: string | number;
|
|
61
50
|
value?: unknown;
|
|
51
|
+
parentValue?: T;
|
|
62
52
|
data?: T;
|
|
63
53
|
displayDataTypes: boolean;
|
|
64
54
|
displayObjectSize: boolean;
|
|
@@ -67,10 +57,10 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
67
57
|
level?: number;
|
|
68
58
|
namespace?: Array<string | number>;
|
|
69
59
|
quotes?: JsonViewProps<T>['quotes'];
|
|
60
|
+
components?: JsonViewProps<T>['components'];
|
|
70
61
|
renderKey?: JSX.Element;
|
|
71
|
-
|
|
62
|
+
countInfo?: JSX.Element;
|
|
72
63
|
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
73
|
-
renderValue?: (props: RenderValueProps<T>) => JSX.Element;
|
|
74
64
|
}
|
|
75
65
|
export declare function getValueString<T>(value: T): {
|
|
76
66
|
type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
|
|
@@ -88,4 +78,3 @@ export interface TypeProps extends React.DetailedHTMLProps<React.HTMLAttributes<
|
|
|
88
78
|
type: keyof typeof typeMap;
|
|
89
79
|
}
|
|
90
80
|
export declare const Type: FC<PropsWithChildren<TypeProps>>;
|
|
91
|
-
export {};
|
package/cjs/value.js
CHANGED
|
@@ -13,12 +13,11 @@ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
|
13
13
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
14
14
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
15
15
|
var _react = require("react");
|
|
16
|
-
var _node = require("./node");
|
|
17
16
|
var _meta = require("./comps/meta");
|
|
18
17
|
var _copied = require("./copied");
|
|
19
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
19
|
var _excluded = ["children", "style"],
|
|
21
|
-
_excluded2 = ["value", "setValue", "data", "keyName", "indentWidth", "namespace", "renderKey", "
|
|
20
|
+
_excluded2 = ["value", "parentValue", "setValue", "countInfo", "data", "keyName", "indentWidth", "namespace", "renderKey", "components", "quotes", "level", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
22
21
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
23
22
|
var Line = function Line(props) {
|
|
24
23
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
@@ -129,16 +128,18 @@ function getValueString(value) {
|
|
|
129
128
|
function ValueView(props) {
|
|
130
129
|
var _typeMap$type;
|
|
131
130
|
var value = props.value,
|
|
131
|
+
parentValue = props.parentValue,
|
|
132
132
|
setValue = props.setValue,
|
|
133
|
+
countInfo = props.countInfo,
|
|
133
134
|
data = props.data,
|
|
134
135
|
keyName = props.keyName,
|
|
135
136
|
indentWidth = props.indentWidth,
|
|
136
137
|
namespace = props.namespace,
|
|
137
138
|
renderKey = props.renderKey,
|
|
139
|
+
_props$components = props.components,
|
|
140
|
+
components = _props$components === void 0 ? {} : _props$components,
|
|
138
141
|
quotes = props.quotes,
|
|
139
142
|
level = props.level,
|
|
140
|
-
renderValue = props.renderValue,
|
|
141
|
-
renderBraces = props.renderBraces,
|
|
142
143
|
enableClipboard = props.enableClipboard,
|
|
143
144
|
displayObjectSize = props.displayObjectSize,
|
|
144
145
|
displayDataTypes = props.displayDataTypes,
|
|
@@ -169,10 +170,13 @@ function ValueView(props) {
|
|
|
169
170
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
170
171
|
showTools = _useState2[0],
|
|
171
172
|
setShowTools = _useState2[1];
|
|
172
|
-
var tools =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
var tools = (0, _react.useMemo)(function () {
|
|
174
|
+
return enableClipboard && showTools && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
175
|
+
show: showTools,
|
|
176
|
+
text: value
|
|
177
|
+
});
|
|
178
|
+
}, [enableClipboard, showTools, value]);
|
|
179
|
+
// const tools = enableClipboard ? <Copied show={showTools} text={value} /> : undefined;
|
|
176
180
|
var eventProps = {
|
|
177
181
|
className: 'w-rjv-line',
|
|
178
182
|
style: {
|
|
@@ -188,7 +192,7 @@ function ValueView(props) {
|
|
|
188
192
|
};
|
|
189
193
|
}
|
|
190
194
|
if (content && typeof content === 'string') {
|
|
191
|
-
var reView =
|
|
195
|
+
var reView = components.value && components.value({
|
|
192
196
|
className: 'w-rjv-value',
|
|
193
197
|
style: (0, _objectSpread2["default"])({
|
|
194
198
|
color: color
|
|
@@ -197,6 +201,7 @@ function ValueView(props) {
|
|
|
197
201
|
value: value,
|
|
198
202
|
setValue: setValue,
|
|
199
203
|
data: data,
|
|
204
|
+
parentValue: parentValue,
|
|
200
205
|
quotes: quotes,
|
|
201
206
|
keyName: keyName,
|
|
202
207
|
namespace: namespace,
|
|
@@ -225,18 +230,15 @@ function ValueView(props) {
|
|
|
225
230
|
}))
|
|
226
231
|
}));
|
|
227
232
|
}
|
|
228
|
-
var length = Array.isArray(value) ? value.length : Object.keys(value).length;
|
|
229
233
|
var empty = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
230
234
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
231
|
-
render:
|
|
235
|
+
render: components.braces,
|
|
232
236
|
start: true,
|
|
233
237
|
isArray: Array.isArray(value)
|
|
234
238
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
235
|
-
render:
|
|
239
|
+
render: components.braces,
|
|
236
240
|
isArray: Array.isArray(value)
|
|
237
|
-
}),
|
|
238
|
-
children: [length, " items"]
|
|
239
|
-
})]
|
|
241
|
+
}), countInfo]
|
|
240
242
|
});
|
|
241
243
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, eventProps), {}, {
|
|
242
244
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
@@ -6,6 +6,7 @@ export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
|
6
6
|
value: T;
|
|
7
7
|
parentValue?: T;
|
|
8
8
|
keyName?: string | number;
|
|
9
|
+
namespace?: Array<string | number>;
|
|
9
10
|
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
10
11
|
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
11
12
|
/**
|
|
@@ -17,6 +18,8 @@ export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
|
17
18
|
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
18
19
|
* @returns Returning false from onDelete will prevent the change from being made.
|
|
19
20
|
*/
|
|
20
|
-
onDelete?: (keyName: string | number, value: T, parentValue: T
|
|
21
|
+
onDelete?: (keyName: string | number, value: T, parentValue: T | null, opt: {
|
|
22
|
+
namespace?: Array<string | number>;
|
|
23
|
+
}) => boolean;
|
|
21
24
|
}
|
|
22
25
|
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -12,6 +12,7 @@ export function CountInfoExtra(props) {
|
|
|
12
12
|
editable,
|
|
13
13
|
keyName,
|
|
14
14
|
value,
|
|
15
|
+
namespace,
|
|
15
16
|
parentValue,
|
|
16
17
|
setValue,
|
|
17
18
|
setParentValue,
|
|
@@ -43,7 +44,9 @@ export function CountInfoExtra(props) {
|
|
|
43
44
|
var _ref2 = _asyncToGenerator(function* (event) {
|
|
44
45
|
event.stopPropagation();
|
|
45
46
|
if (onDelete && (keyName || typeof keyName === 'number') && parentValue) {
|
|
46
|
-
var maybeDelete = yield onDelete(keyName, value, parentValue
|
|
47
|
+
var maybeDelete = yield onDelete(keyName, value, parentValue, {
|
|
48
|
+
namespace
|
|
49
|
+
});
|
|
47
50
|
if (maybeDelete && setParentValue) {
|
|
48
51
|
if (Array.isArray(parentValue)) {
|
|
49
52
|
parentValue.splice(keyName, 1);
|
package/esm/editor/value.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ReValueProps<T extends object> extends React.HTMLAttributes<HTM
|
|
|
7
7
|
keyName?: JsonViewEditorProps<T>['keyName'];
|
|
8
8
|
type: TypeProps['type'];
|
|
9
9
|
value?: unknown;
|
|
10
|
+
parentValue?: T;
|
|
10
11
|
data?: T;
|
|
11
12
|
visible?: boolean;
|
|
12
13
|
namespace?: Array<string | number>;
|
package/esm/editor/value.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
4
|
-
var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "namespace", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
|
|
4
|
+
var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "namespace", "displayDataTypes", "editableValue", "parentValue", "onDelete", "onEdit"];
|
|
5
5
|
import { Fragment, useEffect, useRef, useState } from 'react';
|
|
6
6
|
import { getValueString, isFloat, Type, typeMap } from '../value';
|
|
7
7
|
import { EditIcon } from './icon/edit';
|
|
@@ -34,6 +34,7 @@ export function ReValue(props) {
|
|
|
34
34
|
namespace,
|
|
35
35
|
displayDataTypes,
|
|
36
36
|
editableValue,
|
|
37
|
+
parentValue,
|
|
37
38
|
onDelete,
|
|
38
39
|
onEdit
|
|
39
40
|
} = props,
|
|
@@ -157,9 +158,14 @@ export function ReValue(props) {
|
|
|
157
158
|
var deleteHandle = /*#__PURE__*/function () {
|
|
158
159
|
var _ref3 = _asyncToGenerator(function* (evn) {
|
|
159
160
|
evn.stopPropagation();
|
|
160
|
-
if (data && keyName && keyName in data && setValue) {
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
if (data && keyName && keyName in data && setValue && onDelete) {
|
|
162
|
+
var maybeDelete = yield onDelete(keyName, value, parentValue, {
|
|
163
|
+
namespace
|
|
164
|
+
});
|
|
165
|
+
if (maybeDelete) {
|
|
166
|
+
delete data[keyName];
|
|
167
|
+
setValue(_extends({}, data));
|
|
168
|
+
}
|
|
163
169
|
}
|
|
164
170
|
});
|
|
165
171
|
return function deleteHandle(_x) {
|
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { SemicolonProps } from './semicolon';
|
|
3
|
-
import type { ValueViewProps } from './value';
|
|
3
|
+
import type { ValueViewProps, TypeProps } from './value';
|
|
4
4
|
import type { CopiedProps } from './copied';
|
|
5
5
|
import type { EllipsisProps } from './comps/ellipsis';
|
|
6
6
|
import type { MetaProps } from './comps/meta';
|
|
@@ -12,6 +12,17 @@ export interface CountInfoProps {
|
|
|
12
12
|
level: number;
|
|
13
13
|
visible: boolean;
|
|
14
14
|
}
|
|
15
|
+
interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
|
|
16
|
+
type: TypeProps['type'];
|
|
17
|
+
value?: unknown;
|
|
18
|
+
parentValue?: T;
|
|
19
|
+
data?: T;
|
|
20
|
+
visible?: boolean;
|
|
21
|
+
quotes?: JsonViewProps<T>['quotes'];
|
|
22
|
+
namespace?: Array<string | number>;
|
|
23
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
24
|
+
keyName?: ValueViewProps<T>['keyName'];
|
|
25
|
+
}
|
|
15
26
|
export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
16
27
|
/** This property contains your input JSON */
|
|
17
28
|
value?: T;
|
|
@@ -48,7 +59,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
48
59
|
ellipsis?: EllipsisProps['render'];
|
|
49
60
|
arrow?: JSX.Element;
|
|
50
61
|
objectKey?: SemicolonProps['render'];
|
|
51
|
-
value?:
|
|
62
|
+
value?: (props: RenderValueProps<T>) => JSX.Element;
|
|
52
63
|
copied?: CopiedProps<T>['render'];
|
|
53
64
|
countInfo?: (props: CountInfoProps) => JSX.Element;
|
|
54
65
|
countInfoExtra?: (props: Omit<CountInfoExtraProps<T>, 'editable'>) => JSX.Element;
|
package/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutP
|
|
|
3
3
|
var _excluded = ["value", "style", "className"];
|
|
4
4
|
import React, { useId } from 'react';
|
|
5
5
|
import { forwardRef } from 'react';
|
|
6
|
-
import {
|
|
6
|
+
import { RootNode } from './node';
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
8
|
export * from './node';
|
|
9
9
|
export * from './value';
|
|
@@ -22,7 +22,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
22
22
|
}, style);
|
|
23
23
|
var cls = "w-json-view-container w-rjv " + (className || '');
|
|
24
24
|
var keyid = useId();
|
|
25
|
-
return /*#__PURE__*/_jsx(
|
|
25
|
+
return /*#__PURE__*/_jsx(RootNode, _extends({
|
|
26
26
|
className: cls,
|
|
27
27
|
value: value
|
|
28
28
|
}, reset, {
|
package/esm/node.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FC, PropsWithChildren } from 'react';
|
|
|
2
2
|
import { LabelProps } from './value';
|
|
3
3
|
import { JsonViewProps } from './';
|
|
4
4
|
export declare const CountInfo: FC<PropsWithChildren<LabelProps>>;
|
|
5
|
-
export interface
|
|
5
|
+
export interface RootNodeProps<T extends object> extends JsonViewProps<T> {
|
|
6
6
|
keyName?: string | number;
|
|
7
7
|
keyid?: string;
|
|
8
8
|
level?: number;
|
|
@@ -10,4 +10,4 @@ export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
|
|
|
10
10
|
namespace?: Array<string | number>;
|
|
11
11
|
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
12
12
|
}
|
|
13
|
-
export declare
|
|
13
|
+
export declare const RootNode: import("react").ForwardRefExoticComponent<Omit<RootNodeProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
package/esm/node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
3
|
var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "namespace", "onCopied", "onExpand", "parentValue", "setParentValue"];
|
|
4
|
-
import { Fragment, useId, cloneElement, useState, useEffect } from 'react';
|
|
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';
|
|
7
7
|
import { useExpandsStatus, store } from './store';
|
|
@@ -9,23 +9,30 @@ import { Semicolon } from './semicolon';
|
|
|
9
9
|
import { Copied } from './copied';
|
|
10
10
|
import { Ellipsis } from './comps/ellipsis';
|
|
11
11
|
import { Meta } from './comps/meta';
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
12
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
function getLength(obj) {
|
|
15
|
+
try {
|
|
16
|
+
return Object.keys(obj).length;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return -1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
14
21
|
export var CountInfo = _ref => {
|
|
15
22
|
var {
|
|
16
23
|
children
|
|
17
24
|
} = _ref;
|
|
18
|
-
return /*#__PURE__*/
|
|
25
|
+
return /*#__PURE__*/_jsxs(Label, {
|
|
19
26
|
style: {
|
|
20
27
|
paddingLeft: 4,
|
|
21
28
|
fontStyle: 'italic'
|
|
22
29
|
},
|
|
23
30
|
color: "var(--w-rjv-info-color, #0000004d)",
|
|
24
31
|
className: "w-rjv-object-size",
|
|
25
|
-
children: children
|
|
32
|
+
children: [children, " items"]
|
|
26
33
|
});
|
|
27
34
|
};
|
|
28
|
-
export
|
|
35
|
+
export var RootNode = /*#__PURE__*/forwardRef((props, ref) => {
|
|
29
36
|
var _expands$keyid;
|
|
30
37
|
var {
|
|
31
38
|
value = {},
|
|
@@ -85,12 +92,12 @@ export function RooNode(props) {
|
|
|
85
92
|
displayDataTypes,
|
|
86
93
|
displayObjectSize,
|
|
87
94
|
enableClipboard,
|
|
95
|
+
level: level + 1,
|
|
96
|
+
parentValue: value,
|
|
88
97
|
indentWidth,
|
|
89
98
|
data: valueData,
|
|
90
99
|
quotes,
|
|
91
|
-
setValue: setValueData
|
|
92
|
-
renderBraces: components.braces,
|
|
93
|
-
renderValue: components.value
|
|
100
|
+
setValue: setValueData
|
|
94
101
|
};
|
|
95
102
|
var arrowStyle = {
|
|
96
103
|
transform: "rotate(" + (expand ? '0' : '-90') + "deg)",
|
|
@@ -126,8 +133,8 @@ export function RooNode(props) {
|
|
|
126
133
|
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
|
-
var countInfo = /*#__PURE__*/
|
|
130
|
-
children:
|
|
136
|
+
var countInfo = /*#__PURE__*/_jsx(CountInfo, {
|
|
137
|
+
children: nameKeys.length
|
|
131
138
|
});
|
|
132
139
|
if (components.countInfo) {
|
|
133
140
|
countInfo = components.countInfo({
|
|
@@ -136,7 +143,22 @@ export function RooNode(props) {
|
|
|
136
143
|
visible: expand
|
|
137
144
|
}) || countInfo;
|
|
138
145
|
}
|
|
139
|
-
|
|
146
|
+
if (!displayObjectSize) countInfo = null;
|
|
147
|
+
var countInfoExtra = components.countInfoExtra && components.countInfoExtra({
|
|
148
|
+
count: nameKeys.length,
|
|
149
|
+
level,
|
|
150
|
+
showTools,
|
|
151
|
+
keyName,
|
|
152
|
+
visible: expand,
|
|
153
|
+
value: valueData,
|
|
154
|
+
namespace: [...namespace],
|
|
155
|
+
parentValue,
|
|
156
|
+
setParentValue,
|
|
157
|
+
setValue: setValueData
|
|
158
|
+
});
|
|
159
|
+
return /*#__PURE__*/_jsxs("div", _extends({
|
|
160
|
+
ref: ref
|
|
161
|
+
}, reset, {
|
|
140
162
|
className: className + " w-rjv-inner"
|
|
141
163
|
}, eventProps, {
|
|
142
164
|
children: [/*#__PURE__*/_jsxs(Line, {
|
|
@@ -169,17 +191,7 @@ export function RooNode(props) {
|
|
|
169
191
|
isArray: isArray,
|
|
170
192
|
level: level,
|
|
171
193
|
render: components.braces
|
|
172
|
-
}),
|
|
173
|
-
count: nameKeys.length,
|
|
174
|
-
level,
|
|
175
|
-
showTools,
|
|
176
|
-
keyName,
|
|
177
|
-
visible: expand,
|
|
178
|
-
value: valueData,
|
|
179
|
-
parentValue,
|
|
180
|
-
setParentValue,
|
|
181
|
-
setValue: setValueData
|
|
182
|
-
}), enableClipboard && /*#__PURE__*/_jsx(Copied, {
|
|
194
|
+
}), countInfo, countInfoExtra, enableClipboard && /*#__PURE__*/_jsx(Copied, {
|
|
183
195
|
show: showTools,
|
|
184
196
|
text: valueData,
|
|
185
197
|
onCopied: onCopied,
|
|
@@ -194,23 +206,12 @@ export function RooNode(props) {
|
|
|
194
206
|
children: entries.length > 0 && [...entries].map((_ref6, idx) => {
|
|
195
207
|
var [key, itemVal] = _ref6;
|
|
196
208
|
var item = itemVal;
|
|
197
|
-
var renderKey = /*#__PURE__*/_jsx(Semicolon, {
|
|
198
|
-
value: item,
|
|
199
|
-
"data-keys": keyid,
|
|
200
|
-
quotes: quotes,
|
|
201
|
-
namespace: [...namespace, key],
|
|
202
|
-
parentName: keyName,
|
|
203
|
-
highlightUpdates: highlightUpdates,
|
|
204
|
-
render: components.objectKey,
|
|
205
|
-
color: typeof key === 'number' ? typeMap['number'].color : '',
|
|
206
|
-
keyName: key
|
|
207
|
-
});
|
|
208
209
|
var isEmpty = Array.isArray(item) && item.length === 0 || typeof item === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
|
|
209
210
|
if (Array.isArray(item) && !isEmpty) {
|
|
210
211
|
var label = isArray ? idx : key;
|
|
211
212
|
return /*#__PURE__*/_jsx(Line, {
|
|
212
213
|
className: "w-rjv-wrap",
|
|
213
|
-
children: /*#__PURE__*/_jsx(
|
|
214
|
+
children: /*#__PURE__*/_jsx(RootNode, _extends({
|
|
214
215
|
value: item,
|
|
215
216
|
namespace: [...namespace, label],
|
|
216
217
|
keyName: label,
|
|
@@ -221,7 +222,7 @@ export function RooNode(props) {
|
|
|
221
222
|
if (typeof item === 'object' && item && !(item instanceof Date) && !isEmpty) {
|
|
222
223
|
return /*#__PURE__*/_jsx(Line, {
|
|
223
224
|
className: "w-rjv-wrap",
|
|
224
|
-
children: /*#__PURE__*/_jsx(
|
|
225
|
+
children: /*#__PURE__*/_jsx(RootNode, _extends({
|
|
225
226
|
value: item,
|
|
226
227
|
namespace: [...namespace, key],
|
|
227
228
|
keyName: key,
|
|
@@ -232,9 +233,33 @@ export function RooNode(props) {
|
|
|
232
233
|
if (typeof item === 'function') {
|
|
233
234
|
return;
|
|
234
235
|
}
|
|
236
|
+
var renderKey = /*#__PURE__*/_jsx(Semicolon, {
|
|
237
|
+
value: item,
|
|
238
|
+
"data-keys": keyid,
|
|
239
|
+
quotes: quotes,
|
|
240
|
+
namespace: [...namespace, key],
|
|
241
|
+
parentName: keyName,
|
|
242
|
+
highlightUpdates: highlightUpdates,
|
|
243
|
+
render: components.objectKey,
|
|
244
|
+
color: typeof key === 'number' ? typeMap['number'].color : '',
|
|
245
|
+
keyName: key
|
|
246
|
+
});
|
|
247
|
+
var length = Array.isArray(item) ? item.length : getLength(item);
|
|
248
|
+
countInfo = /*#__PURE__*/_jsx(CountInfo, {
|
|
249
|
+
children: length
|
|
250
|
+
});
|
|
251
|
+
if (components.countInfo) {
|
|
252
|
+
countInfo = components.countInfo({
|
|
253
|
+
count: length,
|
|
254
|
+
level,
|
|
255
|
+
visible: expand
|
|
256
|
+
}) || countInfo;
|
|
257
|
+
}
|
|
235
258
|
return /*#__PURE__*/_jsx(ValueView, _extends({
|
|
259
|
+
components: components,
|
|
236
260
|
namespace: [...namespace, key]
|
|
237
261
|
}, valueViewProps, {
|
|
262
|
+
countInfo: countInfo,
|
|
238
263
|
renderKey: renderKey,
|
|
239
264
|
keyName: key,
|
|
240
265
|
value: item
|
|
@@ -255,4 +280,4 @@ export function RooNode(props) {
|
|
|
255
280
|
})
|
|
256
281
|
})]
|
|
257
282
|
}));
|
|
258
|
-
}
|
|
283
|
+
});
|
package/esm/value.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import type { MetaProps } from './comps/meta';
|
|
3
2
|
import type { JsonViewProps } from './';
|
|
4
3
|
export declare const Line: FC<PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>>;
|
|
5
4
|
export declare const isFloat: (n: number) => boolean;
|
|
@@ -46,19 +45,10 @@ export declare const typeMap: {
|
|
|
46
45
|
};
|
|
47
46
|
};
|
|
48
47
|
export declare const Colon: FC<PropsWithChildren<React.HTMLAttributes<HTMLSpanElement>>>;
|
|
49
|
-
interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
|
|
50
|
-
type: TypeProps['type'];
|
|
51
|
-
value?: unknown;
|
|
52
|
-
data?: T;
|
|
53
|
-
visible?: boolean;
|
|
54
|
-
quotes?: JsonViewProps<T>['quotes'];
|
|
55
|
-
namespace?: Array<string | number>;
|
|
56
|
-
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
57
|
-
keyName?: ValueViewProps<T>['keyName'];
|
|
58
|
-
}
|
|
59
48
|
export interface ValueViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
60
49
|
keyName?: string | number;
|
|
61
50
|
value?: unknown;
|
|
51
|
+
parentValue?: T;
|
|
62
52
|
data?: T;
|
|
63
53
|
displayDataTypes: boolean;
|
|
64
54
|
displayObjectSize: boolean;
|
|
@@ -67,10 +57,10 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
67
57
|
level?: number;
|
|
68
58
|
namespace?: Array<string | number>;
|
|
69
59
|
quotes?: JsonViewProps<T>['quotes'];
|
|
60
|
+
components?: JsonViewProps<T>['components'];
|
|
70
61
|
renderKey?: JSX.Element;
|
|
71
|
-
|
|
62
|
+
countInfo?: JSX.Element;
|
|
72
63
|
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
73
|
-
renderValue?: (props: RenderValueProps<T>) => JSX.Element;
|
|
74
64
|
}
|
|
75
65
|
export declare function getValueString<T>(value: T): {
|
|
76
66
|
type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
|
|
@@ -88,4 +78,3 @@ export interface TypeProps extends React.DetailedHTMLProps<React.HTMLAttributes<
|
|
|
88
78
|
type: keyof typeof typeMap;
|
|
89
79
|
}
|
|
90
80
|
export declare const Type: FC<PropsWithChildren<TypeProps>>;
|
|
91
|
-
export {};
|
package/esm/value.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
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 = ["value", "setValue", "data", "keyName", "indentWidth", "namespace", "renderKey", "
|
|
4
|
+
_excluded2 = ["value", "parentValue", "setValue", "countInfo", "data", "keyName", "indentWidth", "namespace", "renderKey", "components", "quotes", "level", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
5
5
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
6
|
-
import { Fragment, forwardRef, useState } from 'react';
|
|
7
|
-
import { CountInfo } from './node';
|
|
6
|
+
import { Fragment, forwardRef, useMemo, useState } from 'react';
|
|
8
7
|
import { Meta } from './comps/meta';
|
|
9
8
|
import { Copied } from './copied';
|
|
10
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -112,17 +111,17 @@ export function ValueView(props) {
|
|
|
112
111
|
var _typeMap$type;
|
|
113
112
|
var {
|
|
114
113
|
value,
|
|
114
|
+
parentValue,
|
|
115
115
|
setValue,
|
|
116
|
+
countInfo,
|
|
116
117
|
data,
|
|
117
118
|
keyName,
|
|
118
119
|
indentWidth,
|
|
119
120
|
namespace,
|
|
120
121
|
renderKey,
|
|
122
|
+
components = {},
|
|
121
123
|
quotes,
|
|
122
|
-
renderValue,
|
|
123
|
-
renderBraces,
|
|
124
124
|
enableClipboard,
|
|
125
|
-
displayObjectSize,
|
|
126
125
|
displayDataTypes
|
|
127
126
|
} = props,
|
|
128
127
|
reset = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
@@ -150,10 +149,11 @@ export function ValueView(props) {
|
|
|
150
149
|
}
|
|
151
150
|
color = ((_typeMap$type = typeMap[type]) == null ? void 0 : _typeMap$type.color) || '';
|
|
152
151
|
var [showTools, setShowTools] = useState(false);
|
|
153
|
-
var tools = enableClipboard
|
|
152
|
+
var tools = useMemo(() => enableClipboard && showTools && /*#__PURE__*/_jsx(Copied, {
|
|
154
153
|
show: showTools,
|
|
155
154
|
text: value
|
|
156
|
-
})
|
|
155
|
+
}), [enableClipboard, showTools, value]);
|
|
156
|
+
// const tools = enableClipboard ? <Copied show={showTools} text={value} /> : undefined;
|
|
157
157
|
var eventProps = {
|
|
158
158
|
className: 'w-rjv-line',
|
|
159
159
|
style: {
|
|
@@ -165,7 +165,7 @@ export function ValueView(props) {
|
|
|
165
165
|
eventProps.onMouseLeave = () => setShowTools(false);
|
|
166
166
|
}
|
|
167
167
|
if (content && typeof content === 'string') {
|
|
168
|
-
var reView =
|
|
168
|
+
var reView = components.value && components.value({
|
|
169
169
|
className: 'w-rjv-value',
|
|
170
170
|
style: _extends({
|
|
171
171
|
color
|
|
@@ -174,6 +174,7 @@ export function ValueView(props) {
|
|
|
174
174
|
value,
|
|
175
175
|
setValue,
|
|
176
176
|
data,
|
|
177
|
+
parentValue,
|
|
177
178
|
quotes,
|
|
178
179
|
keyName,
|
|
179
180
|
namespace,
|
|
@@ -202,18 +203,15 @@ export function ValueView(props) {
|
|
|
202
203
|
}))
|
|
203
204
|
}));
|
|
204
205
|
}
|
|
205
|
-
var length = Array.isArray(value) ? value.length : Object.keys(value).length;
|
|
206
206
|
var empty = /*#__PURE__*/_jsxs(Fragment, {
|
|
207
207
|
children: [/*#__PURE__*/_jsx(Meta, {
|
|
208
|
-
render:
|
|
208
|
+
render: components.braces,
|
|
209
209
|
start: true,
|
|
210
210
|
isArray: Array.isArray(value)
|
|
211
211
|
}), /*#__PURE__*/_jsx(Meta, {
|
|
212
|
-
render:
|
|
212
|
+
render: components.braces,
|
|
213
213
|
isArray: Array.isArray(value)
|
|
214
|
-
}),
|
|
215
|
-
children: [length, " items"]
|
|
216
|
-
})]
|
|
214
|
+
}), countInfo]
|
|
217
215
|
});
|
|
218
216
|
return /*#__PURE__*/_jsx(Line, _extends({}, eventProps, {
|
|
219
217
|
children: /*#__PURE__*/_jsxs(Label, _extends({}, reset, {
|