@uiw/react-json-view 1.7.1 → 1.8.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 +12 -3
- package/cjs/editor/countInfoExtra.d.ts +9 -1
- package/cjs/editor/countInfoExtra.js +49 -7
- package/cjs/editor/icon/add.js +2 -2
- package/cjs/editor/icon/delete.d.ts +4 -0
- package/cjs/editor/icon/delete.js +30 -0
- package/cjs/editor/index.d.ts +5 -0
- package/cjs/editor/index.js +5 -2
- package/cjs/editor/value.d.ts +3 -0
- package/cjs/editor/value.js +27 -1
- package/cjs/node.d.ts +2 -0
- package/cjs/node.js +20 -10
- package/cjs/value.d.ts +13 -7
- package/cjs/value.js +6 -2
- package/editor.d.ts +5 -0
- package/esm/editor/countInfoExtra.d.ts +9 -1
- package/esm/editor/countInfoExtra.js +36 -7
- package/esm/editor/icon/add.js +2 -2
- package/esm/editor/icon/delete.d.ts +4 -0
- package/esm/editor/icon/delete.js +24 -0
- package/esm/editor/index.d.ts +5 -0
- package/esm/editor/index.js +6 -3
- package/esm/editor/value.d.ts +3 -0
- package/esm/editor/value.js +20 -1
- package/esm/node.d.ts +2 -0
- package/esm/node.js +13 -4
- package/esm/value.d.ts +13 -7
- package/esm/value.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,8 @@ A React component for displaying and editing javascript arrays and JSON objects.
|
|
|
25
25
|
🎨 Support theme customization & [`online editing`](https://uiwjs.github.io/react-json-view/#online-editing-theme) theme
|
|
26
26
|
🌒 Support dark/light mode
|
|
27
27
|
📦 Zero dependencies
|
|
28
|
+
📋 Copy to Clipboard
|
|
29
|
+
✏️ Support editing and adding features
|
|
28
30
|
♻️ Whether to highlight updates.
|
|
29
31
|
|
|
30
32
|
## Quick Start
|
|
@@ -124,6 +126,7 @@ const customTheme = {
|
|
|
124
126
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
125
127
|
'--w-rjv-edit-color': 'var(--w-rjv-color)',
|
|
126
128
|
'--w-rjv-add-color': 'var(--w-rjv-color)',
|
|
129
|
+
'--w-rjv-delete-color': '#dc3545',
|
|
127
130
|
'--w-rjv-info-color': '#656565',
|
|
128
131
|
'--w-rjv-update-color': '#ebcb8b',
|
|
129
132
|
'--w-rjv-copied-color': '#9cdcfe',
|
|
@@ -190,6 +193,7 @@ const customTheme = {
|
|
|
190
193
|
'--w-rjv-arrow-color': '#9cdcfe',
|
|
191
194
|
'--w-rjv-edit-color': '#0184a6',
|
|
192
195
|
'--w-rjv-add-color': '#0184a6',
|
|
196
|
+
'--w-rjv-delete-color': '#dc3545',
|
|
193
197
|
'--w-rjv-info-color': '#656565',
|
|
194
198
|
'--w-rjv-update-color': '#ebcb8b',
|
|
195
199
|
'--w-rjv-copied-color': '#0184a6',
|
|
@@ -260,7 +264,7 @@ export default function Demo() {
|
|
|
260
264
|
setHex(customTheme[varname]);
|
|
261
265
|
};
|
|
262
266
|
const active = cssvar === varname ? '#a8a8a8' : '';
|
|
263
|
-
return <button key={idx} style={{ background: active, border: 0,boxShadow: 'inset 0px 0px 1px #000' }} onClick={click}>{varname}</button>
|
|
267
|
+
return <button key={idx} style={{ background: active, border: 0,boxShadow: 'inset 0px 0px 1px #000', textAlign: 'left' }} onClick={click}>{varname}</button>
|
|
264
268
|
})}
|
|
265
269
|
</div>
|
|
266
270
|
</div>
|
|
@@ -329,7 +333,7 @@ const object = {
|
|
|
329
333
|
integer: 42,
|
|
330
334
|
}
|
|
331
335
|
|
|
332
|
-
function value({ type, children, value, keyName, visible, ...props }) {
|
|
336
|
+
function value({ type, children, value, setValue, keyName, visible, ...props }) {
|
|
333
337
|
if (type === 'string' && /\.(jpg)$/.test(value)) {
|
|
334
338
|
return (
|
|
335
339
|
<span {...props}>
|
|
@@ -382,7 +386,7 @@ export default function Demo() {
|
|
|
382
386
|
import React from 'react';
|
|
383
387
|
import JsonView from '@uiw/react-json-view';
|
|
384
388
|
|
|
385
|
-
function value({ type, children, visible, keyName, value, ...props }) {
|
|
389
|
+
function value({ type, children, visible, keyName, value, setValue, ...props }) {
|
|
386
390
|
if (value instanceof URL) {
|
|
387
391
|
return (
|
|
388
392
|
<span {...props}>
|
|
@@ -759,6 +763,11 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
759
763
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
760
764
|
*/
|
|
761
765
|
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
766
|
+
/**
|
|
767
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
768
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
769
|
+
*/
|
|
770
|
+
onDelete?: CountInfoExtraProps<T>['onDelete'];
|
|
762
771
|
/** Whether enable edit feature. @default true */
|
|
763
772
|
editable?: boolean;
|
|
764
773
|
}
|
|
@@ -4,11 +4,19 @@ export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
|
4
4
|
editable: boolean;
|
|
5
5
|
showTools: boolean;
|
|
6
6
|
value: T;
|
|
7
|
+
parentValue?: T;
|
|
8
|
+
keyName?: string | number;
|
|
7
9
|
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
10
|
+
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
8
11
|
/**
|
|
9
12
|
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
10
13
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
11
14
|
*/
|
|
12
15
|
onAdd?: (keyOrValue: string, newValue: T, value: T, isAdd: boolean) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
18
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
19
|
+
*/
|
|
20
|
+
onDelete?: (keyName: string | number, value: T, parentValue: T) => boolean;
|
|
13
21
|
}
|
|
14
|
-
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null
|
|
22
|
+
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -10,15 +10,21 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
10
10
|
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
var _react = require("react");
|
|
13
14
|
var _add = require("./icon/add");
|
|
15
|
+
var _delete = require("./icon/delete");
|
|
14
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
17
|
function CountInfoExtra(props) {
|
|
16
18
|
var visible = props.visible,
|
|
17
19
|
showTools = props.showTools,
|
|
18
20
|
editable = props.editable,
|
|
21
|
+
keyName = props.keyName,
|
|
19
22
|
value = props.value,
|
|
23
|
+
parentValue = props.parentValue,
|
|
20
24
|
setValue = props.setValue,
|
|
21
|
-
|
|
25
|
+
setParentValue = props.setParentValue,
|
|
26
|
+
onAdd = props.onAdd,
|
|
27
|
+
onDelete = props.onDelete;
|
|
22
28
|
if (!visible || !showTools) return null;
|
|
23
29
|
var click = /*#__PURE__*/function () {
|
|
24
30
|
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee(event) {
|
|
@@ -31,7 +37,7 @@ function CountInfoExtra(props) {
|
|
|
31
37
|
isArray = Array.isArray(value);
|
|
32
38
|
isAdd = isArray ? true : !(keyOrValue in value);
|
|
33
39
|
result = isArray ? [].concat((0, _toConsumableArray2["default"])(value), [keyOrValue]) : (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, value), {}, (0, _defineProperty2["default"])({}, keyOrValue, undefined));
|
|
34
|
-
if (!onAdd) {
|
|
40
|
+
if (!(onAdd && setValue)) {
|
|
35
41
|
_context.next = 10;
|
|
36
42
|
break;
|
|
37
43
|
}
|
|
@@ -52,9 +58,45 @@ function CountInfoExtra(props) {
|
|
|
52
58
|
return _ref.apply(this, arguments);
|
|
53
59
|
};
|
|
54
60
|
}();
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
var deleteHandle = /*#__PURE__*/function () {
|
|
62
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(event) {
|
|
63
|
+
var maybeDelete;
|
|
64
|
+
return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
|
|
65
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
66
|
+
case 0:
|
|
67
|
+
event.stopPropagation();
|
|
68
|
+
if (!(onDelete && (keyName || typeof keyName === 'number') && parentValue)) {
|
|
69
|
+
_context2.next = 6;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
_context2.next = 4;
|
|
73
|
+
return onDelete(keyName, value, parentValue);
|
|
74
|
+
case 4:
|
|
75
|
+
maybeDelete = _context2.sent;
|
|
76
|
+
if (maybeDelete && setParentValue) {
|
|
77
|
+
if (Array.isArray(parentValue)) {
|
|
78
|
+
parentValue.splice(keyName, 1);
|
|
79
|
+
setParentValue((0, _toConsumableArray2["default"])(parentValue));
|
|
80
|
+
} else if (keyName in parentValue) {
|
|
81
|
+
delete parentValue[keyName];
|
|
82
|
+
setParentValue((0, _objectSpread3["default"])({}, parentValue));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
case 6:
|
|
86
|
+
case "end":
|
|
87
|
+
return _context2.stop();
|
|
88
|
+
}
|
|
89
|
+
}, _callee2);
|
|
90
|
+
}));
|
|
91
|
+
return function deleteHandle(_x2) {
|
|
92
|
+
return _ref2.apply(this, arguments);
|
|
93
|
+
};
|
|
94
|
+
}();
|
|
95
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
96
|
+
children: [editable && onAdd && /*#__PURE__*/(0, _jsxRuntime.jsx)(_add.AddIcon, {
|
|
97
|
+
onClick: click
|
|
98
|
+
}), editable && onDelete && parentValue && /*#__PURE__*/(0, _jsxRuntime.jsx)(_delete.DeleteIcon, {
|
|
99
|
+
onClick: deleteHandle
|
|
100
|
+
})]
|
|
101
|
+
});
|
|
60
102
|
}
|
package/cjs/editor/icon/add.js
CHANGED
|
@@ -18,12 +18,12 @@ var AddIcon = function AddIcon(props) {
|
|
|
18
18
|
width: '1em'
|
|
19
19
|
};
|
|
20
20
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
21
|
-
viewBox: "0 0
|
|
21
|
+
viewBox: "0 0 40 40",
|
|
22
22
|
fill: "var(--w-rjv-add-color, currentColor)"
|
|
23
23
|
}, props), {}, {
|
|
24
24
|
style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), defaultStyle),
|
|
25
25
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
|
26
|
-
d: "
|
|
26
|
+
d: "M28.3940997,0 L11.625773,0 C4.34215619,0 0,4.34 0,11.62 L0,28.36 C0,35.66 4.34215619,40 11.625773,40 L28.3740897,40 C35.6577066,40 39.9999316,35.66 39.9999316,28.38 L39.9999316,11.62 C40.0198727,4.34 35.6777165,0 28.3940997,0 Z M30.12022,21.8947368 L21.9056145,21.8947368 L21.9056145,30.1052632 C21.9056145,31.1410526 21.0462404,32 20.0099363,32 C18.9736323,32 18.1142582,31.1410526 18.1142582,30.1052632 L18.1142582,21.8947368 L9.89965272,21.8947368 C8.86334865,21.8947368 8.00397454,21.0357895 8.00397454,20 C8.00397454,18.9642105 8.86334865,18.1052632 9.89965272,18.1052632 L18.1142582,18.1052632 L18.1142582,9.89473684 C18.1142582,8.85894737 18.9736323,8 20.0099363,8 C21.0462404,8 21.9056145,8.85894737 21.9056145,9.89473684 L21.9056145,18.1052632 L30.12022,18.1052632 C31.156524,18.1052632 32.0158982,18.9642105 32.0158982,20 C32.0158982,21.0357895 31.156524,21.8947368 30.12022,21.8947368 Z"
|
|
27
27
|
})
|
|
28
28
|
}));
|
|
29
29
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.DeleteIcon = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
var DeleteIcon = function DeleteIcon(props) {
|
|
11
|
+
var style = props.style;
|
|
12
|
+
var defaultStyle = {
|
|
13
|
+
verticalAlign: 'middle',
|
|
14
|
+
display: 'inline-block',
|
|
15
|
+
cursor: 'pointer',
|
|
16
|
+
marginLeft: 5,
|
|
17
|
+
height: '1em',
|
|
18
|
+
width: '1em'
|
|
19
|
+
};
|
|
20
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
21
|
+
viewBox: "0 0 40 40",
|
|
22
|
+
fill: "var(--w-rjv-delete-color, #dc3545)"
|
|
23
|
+
}, props), {}, {
|
|
24
|
+
style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), defaultStyle),
|
|
25
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
|
26
|
+
d: "M28.3940997,0 L11.625773,0 C4.34215619,0 0,4.34 0,11.62 L0,28.36 C0,35.66 4.34215619,40 11.625773,40 L28.3740897,40 C35.6577066,40 39.9999316,35.66 39.9999316,28.38 L39.9999316,11.62 C40.0198727,4.34 35.6777165,0 28.3940997,0 Z M30.3428039,27.0681654 C31.2346195,27.9595381 31.2346195,29.4349136 30.3428039,30.3262862 C29.88152,30.7873411 29.2972271,31.0025 28.7129341,31.0025 C28.1286412,31.0025 27.5443483,30.7873411 27.0830644,30.3262862 L20.0100446,23.2567787 L12.9370249,30.3262862 C12.475741,30.7873411 11.891448,31.0025 11.3071551,31.0025 C10.7228621,31.0025 10.1385692,30.7873411 9.67728531,30.3262862 C8.78464325,29.4234847 8.78464325,27.9709669 9.67728531,27.0681654 L16.7503051,19.9986579 L9.67728531,12.9291504 C8.78464325,12.0263488 8.78464325,10.573831 9.67728531,9.67102951 C10.5691008,8.77965683 12.0452093,8.77965683 12.9370249,9.67102951 L20.0100446,16.740537 L27.0830644,9.67102951 C27.9748799,8.77965683 29.4509884,8.77965683 30.3428039,9.67102951 C31.2346195,10.5624022 31.2346195,12.0377777 30.3428039,12.9291504 L23.2697842,19.9986579 L30.3428039,27.0681654 L30.3428039,27.0681654 Z"
|
|
27
|
+
})
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
exports.DeleteIcon = DeleteIcon;
|
package/cjs/editor/index.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
18
18
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
19
19
|
*/
|
|
20
20
|
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
21
|
+
/**
|
|
22
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
23
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
24
|
+
*/
|
|
25
|
+
onDelete?: CountInfoExtraProps<T>['onDelete'];
|
|
21
26
|
/** Whether enable edit feature. @default true */
|
|
22
27
|
editable?: boolean;
|
|
23
28
|
}
|
package/cjs/editor/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var _objectKey = require("./objectKey");
|
|
|
13
13
|
var _value = require("./value");
|
|
14
14
|
var _countInfoExtra = require("./countInfoExtra");
|
|
15
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
-
var _excluded = ["onEdit", "components", "editable", "displayDataTypes", "onAdd"];
|
|
16
|
+
var _excluded = ["onEdit", "components", "editable", "displayDataTypes", "onAdd", "onDelete"];
|
|
17
17
|
var JsonViewEditor = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
18
18
|
var onEdit = props.onEdit,
|
|
19
19
|
components = props.components,
|
|
@@ -22,12 +22,14 @@ var JsonViewEditor = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
22
22
|
_props$displayDataTyp = props.displayDataTypes,
|
|
23
23
|
displayDataTypes = _props$displayDataTyp === void 0 ? true : _props$displayDataTyp,
|
|
24
24
|
onAdd = props.onAdd,
|
|
25
|
+
onDelete = props.onDelete,
|
|
25
26
|
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
26
27
|
var comps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, components), {}, {
|
|
27
28
|
countInfoExtra: function countInfoExtra(reprops) {
|
|
28
29
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_countInfoExtra.CountInfoExtra, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reprops), {}, {
|
|
29
30
|
editable: editable,
|
|
30
|
-
onAdd: onAdd
|
|
31
|
+
onAdd: onAdd,
|
|
32
|
+
onDelete: onDelete
|
|
31
33
|
}));
|
|
32
34
|
},
|
|
33
35
|
objectKey: function objectKey(reprops) {
|
|
@@ -41,6 +43,7 @@ var JsonViewEditor = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
41
43
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ReValue, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reprops), {}, {
|
|
42
44
|
editableValue: editable,
|
|
43
45
|
displayDataTypes: displayDataTypes,
|
|
46
|
+
onDelete: onDelete,
|
|
44
47
|
onEdit: onEdit
|
|
45
48
|
}));
|
|
46
49
|
}
|
package/cjs/editor/value.d.ts
CHANGED
|
@@ -7,8 +7,11 @@ 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
|
+
data?: T;
|
|
10
11
|
visible?: boolean;
|
|
11
12
|
editableValue?: boolean;
|
|
12
13
|
displayDataTypes?: boolean;
|
|
14
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
15
|
+
onDelete?: JsonViewEditorProps<T>['onDelete'];
|
|
13
16
|
}
|
|
14
17
|
export declare function ReValue<T extends object>(props: ReValueProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/cjs/editor/value.js
CHANGED
|
@@ -13,8 +13,9 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
13
13
|
var _react = require("react");
|
|
14
14
|
var _value = require("../value");
|
|
15
15
|
var _edit = require("./icon/edit");
|
|
16
|
+
var _delete = require("./icon/delete");
|
|
16
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
-
var _excluded = ["type", "value", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onEdit"];
|
|
18
|
+
var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
|
|
18
19
|
var Quotes = function Quotes(_ref) {
|
|
19
20
|
var show = _ref.show,
|
|
20
21
|
style = _ref.style,
|
|
@@ -29,6 +30,8 @@ function ReValue(props) {
|
|
|
29
30
|
var _typeMap$typeStr;
|
|
30
31
|
var type = props.type,
|
|
31
32
|
value = props.value,
|
|
33
|
+
setValue = props.setValue,
|
|
34
|
+
data = props.data,
|
|
32
35
|
keyName = props.keyName,
|
|
33
36
|
visible = props.visible,
|
|
34
37
|
quotes = props.quotes,
|
|
@@ -36,6 +39,7 @@ function ReValue(props) {
|
|
|
36
39
|
children = props.children,
|
|
37
40
|
displayDataTypes = props.displayDataTypes,
|
|
38
41
|
editableValue = props.editableValue,
|
|
42
|
+
onDelete = props.onDelete,
|
|
39
43
|
onEdit = props.onEdit,
|
|
40
44
|
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
41
45
|
var _useState = (0, _react.useState)(false),
|
|
@@ -180,6 +184,26 @@ function ReValue(props) {
|
|
|
180
184
|
if (typeStr === 'null' || typeStr === 'undefined') {
|
|
181
185
|
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
182
186
|
}
|
|
187
|
+
var deleteHandle = /*#__PURE__*/function () {
|
|
188
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(evn) {
|
|
189
|
+
return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
|
|
190
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
191
|
+
case 0:
|
|
192
|
+
evn.stopPropagation();
|
|
193
|
+
if (data && keyName && keyName in data && setValue) {
|
|
194
|
+
delete data[keyName];
|
|
195
|
+
setValue((0, _objectSpread2["default"])({}, data));
|
|
196
|
+
}
|
|
197
|
+
case 2:
|
|
198
|
+
case "end":
|
|
199
|
+
return _context2.stop();
|
|
200
|
+
}
|
|
201
|
+
}, _callee2);
|
|
202
|
+
}));
|
|
203
|
+
return function deleteHandle(_x) {
|
|
204
|
+
return _ref3.apply(this, arguments);
|
|
205
|
+
};
|
|
206
|
+
}();
|
|
183
207
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
184
208
|
children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
|
|
185
209
|
style: style,
|
|
@@ -195,6 +219,8 @@ function ReValue(props) {
|
|
|
195
219
|
show: typeStr === 'string'
|
|
196
220
|
}), visible && editableValue && onEdit && /*#__PURE__*/(0, _jsxRuntime.jsx)(_edit.EditIcon, {
|
|
197
221
|
onClick: click
|
|
222
|
+
}), visible && editableValue && onDelete && /*#__PURE__*/(0, _jsxRuntime.jsx)(_delete.DeleteIcon, {
|
|
223
|
+
onClick: deleteHandle
|
|
198
224
|
})]
|
|
199
225
|
});
|
|
200
226
|
}
|
package/cjs/node.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
|
|
|
6
6
|
keyName?: string | number;
|
|
7
7
|
keyid?: string;
|
|
8
8
|
level?: number;
|
|
9
|
+
parentValue?: T;
|
|
10
|
+
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
9
11
|
}
|
|
10
12
|
export declare function RooNode<T extends object>(props: RooNodeProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/cjs/node.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.CountInfo = void 0;
|
|
|
8
8
|
exports.RooNode = RooNode;
|
|
9
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
10
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
12
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
13
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
14
|
var _react = require("react");
|
|
@@ -19,7 +20,7 @@ var _copied = require("./copied");
|
|
|
19
20
|
var _ellipsis = require("./comps/ellipsis");
|
|
20
21
|
var _meta = require("./comps/meta");
|
|
21
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand"];
|
|
23
|
+
var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand", "parentValue", "setParentValue"];
|
|
23
24
|
var CountInfo = function CountInfo(_ref) {
|
|
24
25
|
var children = _ref.children;
|
|
25
26
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, {
|
|
@@ -62,6 +63,8 @@ function RooNode(props) {
|
|
|
62
63
|
quotes = _props$quotes === void 0 ? '"' : _props$quotes,
|
|
63
64
|
onCopied = props.onCopied,
|
|
64
65
|
onExpand = props.onExpand,
|
|
66
|
+
parentValue = props.parentValue,
|
|
67
|
+
setParentValue = props.setParentValue,
|
|
65
68
|
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
66
69
|
var isArray = Array.isArray(value);
|
|
67
70
|
var subkeyid = (0, _react.useId)();
|
|
@@ -80,6 +83,10 @@ function RooNode(props) {
|
|
|
80
83
|
});
|
|
81
84
|
!expand ? _store.store.expand(keyid) : _store.store.collapse(keyid);
|
|
82
85
|
};
|
|
86
|
+
var _useState = (0, _react.useState)(value),
|
|
87
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
88
|
+
valueData = _useState2[0],
|
|
89
|
+
setValueData = _useState2[1];
|
|
83
90
|
var subNodeProps = {
|
|
84
91
|
components: components,
|
|
85
92
|
indentWidth: indentWidth,
|
|
@@ -90,6 +97,8 @@ function RooNode(props) {
|
|
|
90
97
|
onCopied: onCopied,
|
|
91
98
|
onExpand: onExpand,
|
|
92
99
|
collapsed: collapsed,
|
|
100
|
+
parentValue: value,
|
|
101
|
+
setParentValue: setValueData,
|
|
93
102
|
quotes: quotes,
|
|
94
103
|
level: level + 1,
|
|
95
104
|
style: {
|
|
@@ -101,7 +110,9 @@ function RooNode(props) {
|
|
|
101
110
|
displayObjectSize: displayObjectSize,
|
|
102
111
|
enableClipboard: enableClipboard,
|
|
103
112
|
indentWidth: indentWidth,
|
|
113
|
+
data: valueData,
|
|
104
114
|
quotes: quotes,
|
|
115
|
+
setValue: setValueData,
|
|
105
116
|
renderBraces: components.braces,
|
|
106
117
|
renderValue: components.value
|
|
107
118
|
};
|
|
@@ -113,10 +124,10 @@ function RooNode(props) {
|
|
|
113
124
|
style: arrowStyle,
|
|
114
125
|
className: "w-rjv-arrow"
|
|
115
126
|
});
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
showTools =
|
|
119
|
-
setShowTools =
|
|
127
|
+
var _useState3 = (0, _react.useState)(false),
|
|
128
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
129
|
+
showTools = _useState4[0],
|
|
130
|
+
setShowTools = _useState4[1];
|
|
120
131
|
var eventProps = {};
|
|
121
132
|
if (enableClipboard) {
|
|
122
133
|
eventProps.onMouseEnter = function () {
|
|
@@ -126,10 +137,6 @@ function RooNode(props) {
|
|
|
126
137
|
return setShowTools(false);
|
|
127
138
|
};
|
|
128
139
|
}
|
|
129
|
-
var _useState3 = (0, _react.useState)(value),
|
|
130
|
-
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
131
|
-
valueData = _useState4[0],
|
|
132
|
-
setValueData = _useState4[1];
|
|
133
140
|
(0, _react.useEffect)(function () {
|
|
134
141
|
return setValueData(value);
|
|
135
142
|
}, [value]);
|
|
@@ -202,8 +209,11 @@ function RooNode(props) {
|
|
|
202
209
|
count: nameKeys.length,
|
|
203
210
|
level: level,
|
|
204
211
|
showTools: showTools,
|
|
212
|
+
keyName: keyName,
|
|
205
213
|
visible: expand,
|
|
206
214
|
value: valueData,
|
|
215
|
+
parentValue: parentValue,
|
|
216
|
+
setParentValue: setParentValue,
|
|
207
217
|
setValue: setValueData
|
|
208
218
|
}), enableClipboard && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
209
219
|
show: showTools,
|
|
@@ -217,7 +227,7 @@ function RooNode(props) {
|
|
|
217
227
|
borderLeft: 'var(--w-rjv-border-left-width, 1px) var(--w-rjv-line-style, solid) var(--w-rjv-line-color, #ebebeb)',
|
|
218
228
|
marginLeft: 6
|
|
219
229
|
},
|
|
220
|
-
children: entries.length > 0 && entries.map(function (_ref10, idx) {
|
|
230
|
+
children: entries.length > 0 && (0, _toConsumableArray2["default"])(entries).map(function (_ref10, idx) {
|
|
221
231
|
var _ref11 = (0, _slicedToArray2["default"])(_ref10, 2),
|
|
222
232
|
key = _ref11[0],
|
|
223
233
|
itemVal = _ref11[1];
|
package/cjs/value.d.ts
CHANGED
|
@@ -46,9 +46,19 @@ export declare const typeMap: {
|
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
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
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
56
|
+
keyName?: ValueViewProps<T>['keyName'];
|
|
57
|
+
}
|
|
49
58
|
export interface ValueViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
50
59
|
keyName?: string | number;
|
|
51
60
|
value?: unknown;
|
|
61
|
+
data?: T;
|
|
52
62
|
displayDataTypes: boolean;
|
|
53
63
|
displayObjectSize: boolean;
|
|
54
64
|
enableClipboard: boolean;
|
|
@@ -57,13 +67,8 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
57
67
|
quotes?: JsonViewProps<T>['quotes'];
|
|
58
68
|
renderKey?: JSX.Element;
|
|
59
69
|
renderBraces?: MetaProps['render'];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
value?: unknown;
|
|
63
|
-
visible?: boolean;
|
|
64
|
-
quotes?: JsonViewProps<T>['quotes'];
|
|
65
|
-
keyName?: ValueViewProps<T>['keyName'];
|
|
66
|
-
}) => JSX.Element;
|
|
70
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
71
|
+
renderValue?: (props: RenderValueProps<T>) => JSX.Element;
|
|
67
72
|
}
|
|
68
73
|
export declare function getValueString<T>(value: T): {
|
|
69
74
|
type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
|
|
@@ -81,3 +86,4 @@ export interface TypeProps extends React.DetailedHTMLProps<React.HTMLAttributes<
|
|
|
81
86
|
type: keyof typeof typeMap;
|
|
82
87
|
}
|
|
83
88
|
export declare const Type: FC<PropsWithChildren<TypeProps>>;
|
|
89
|
+
export {};
|
package/cjs/value.js
CHANGED
|
@@ -18,7 +18,7 @@ var _meta = require("./comps/meta");
|
|
|
18
18
|
var _copied = require("./copied");
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
20
|
var _excluded = ["children", "style"],
|
|
21
|
-
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
21
|
+
_excluded2 = ["value", "setValue", "data", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
22
22
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
23
23
|
var Line = function Line(props) {
|
|
24
24
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
@@ -55,7 +55,7 @@ var typeMap = {
|
|
|
55
55
|
},
|
|
56
56
|
url: {
|
|
57
57
|
color: 'var(--w-rjv-type-url-color, #0969da)',
|
|
58
|
-
label: '
|
|
58
|
+
label: 'url'
|
|
59
59
|
},
|
|
60
60
|
"null": {
|
|
61
61
|
color: 'var(--w-rjv-type-null-color, #d33682)',
|
|
@@ -129,6 +129,8 @@ function getValueString(value) {
|
|
|
129
129
|
function ValueView(props) {
|
|
130
130
|
var _typeMap$type;
|
|
131
131
|
var value = props.value,
|
|
132
|
+
setValue = props.setValue,
|
|
133
|
+
data = props.data,
|
|
132
134
|
keyName = props.keyName,
|
|
133
135
|
indentWidth = props.indentWidth,
|
|
134
136
|
renderKey = props.renderKey,
|
|
@@ -192,6 +194,8 @@ function ValueView(props) {
|
|
|
192
194
|
}, style),
|
|
193
195
|
type: type,
|
|
194
196
|
value: value,
|
|
197
|
+
setValue: setValue,
|
|
198
|
+
data: data,
|
|
195
199
|
quotes: quotes,
|
|
196
200
|
keyName: keyName,
|
|
197
201
|
visible: showTools,
|
package/editor.d.ts
CHANGED
|
@@ -23,6 +23,11 @@ declare module '@uiw/react-json-view/editor' {
|
|
|
23
23
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
24
24
|
*/
|
|
25
25
|
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
26
|
+
/**
|
|
27
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
28
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
29
|
+
*/
|
|
30
|
+
onDelete?: CountInfoExtraProps<T>['onDelete'];
|
|
26
31
|
/** Whether enable edit feature. @default true */
|
|
27
32
|
editable?: boolean;
|
|
28
33
|
}
|
|
@@ -4,11 +4,19 @@ export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
|
4
4
|
editable: boolean;
|
|
5
5
|
showTools: boolean;
|
|
6
6
|
value: T;
|
|
7
|
+
parentValue?: T;
|
|
8
|
+
keyName?: string | number;
|
|
7
9
|
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
10
|
+
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
8
11
|
/**
|
|
9
12
|
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
10
13
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
11
14
|
*/
|
|
12
15
|
onAdd?: (keyOrValue: string, newValue: T, value: T, isAdd: boolean) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
18
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
19
|
+
*/
|
|
20
|
+
onDelete?: (keyName: string | number, value: T, parentValue: T) => boolean;
|
|
13
21
|
}
|
|
14
|
-
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null
|
|
22
|
+
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { Fragment } from 'react';
|
|
3
4
|
import { AddIcon } from './icon/add';
|
|
5
|
+
import { DeleteIcon } from './icon/delete';
|
|
4
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
8
|
export function CountInfoExtra(props) {
|
|
6
9
|
var {
|
|
7
10
|
visible,
|
|
8
11
|
showTools,
|
|
9
12
|
editable,
|
|
13
|
+
keyName,
|
|
10
14
|
value,
|
|
15
|
+
parentValue,
|
|
11
16
|
setValue,
|
|
12
|
-
|
|
17
|
+
setParentValue,
|
|
18
|
+
onAdd,
|
|
19
|
+
onDelete
|
|
13
20
|
} = props;
|
|
14
21
|
if (!visible || !showTools) return null;
|
|
15
22
|
var click = /*#__PURE__*/function () {
|
|
@@ -21,7 +28,7 @@ export function CountInfoExtra(props) {
|
|
|
21
28
|
var result = isArray ? [...value, keyOrValue] : _extends({}, value, {
|
|
22
29
|
[keyOrValue]: undefined
|
|
23
30
|
});
|
|
24
|
-
if (onAdd) {
|
|
31
|
+
if (onAdd && setValue) {
|
|
25
32
|
var maybeAdd = yield onAdd(keyOrValue, result, props.value, isAdd);
|
|
26
33
|
if (maybeAdd) {
|
|
27
34
|
setValue(result);
|
|
@@ -32,9 +39,31 @@ export function CountInfoExtra(props) {
|
|
|
32
39
|
return _ref.apply(this, arguments);
|
|
33
40
|
};
|
|
34
41
|
}();
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
var deleteHandle = /*#__PURE__*/function () {
|
|
43
|
+
var _ref2 = _asyncToGenerator(function* (event) {
|
|
44
|
+
event.stopPropagation();
|
|
45
|
+
if (onDelete && (keyName || typeof keyName === 'number') && parentValue) {
|
|
46
|
+
var maybeDelete = yield onDelete(keyName, value, parentValue);
|
|
47
|
+
if (maybeDelete && setParentValue) {
|
|
48
|
+
if (Array.isArray(parentValue)) {
|
|
49
|
+
parentValue.splice(keyName, 1);
|
|
50
|
+
setParentValue([...parentValue]);
|
|
51
|
+
} else if (keyName in parentValue) {
|
|
52
|
+
delete parentValue[keyName];
|
|
53
|
+
setParentValue(_extends({}, parentValue));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return function deleteHandle(_x2) {
|
|
59
|
+
return _ref2.apply(this, arguments);
|
|
60
|
+
};
|
|
61
|
+
}();
|
|
62
|
+
return /*#__PURE__*/_jsxs(Fragment, {
|
|
63
|
+
children: [editable && onAdd && /*#__PURE__*/_jsx(AddIcon, {
|
|
64
|
+
onClick: click
|
|
65
|
+
}), editable && onDelete && parentValue && /*#__PURE__*/_jsx(DeleteIcon, {
|
|
66
|
+
onClick: deleteHandle
|
|
67
|
+
})]
|
|
68
|
+
});
|
|
40
69
|
}
|
package/esm/editor/icon/add.js
CHANGED
|
@@ -13,12 +13,12 @@ export var AddIcon = props => {
|
|
|
13
13
|
width: '1em'
|
|
14
14
|
};
|
|
15
15
|
return /*#__PURE__*/_jsx("svg", _extends({
|
|
16
|
-
viewBox: "0 0
|
|
16
|
+
viewBox: "0 0 40 40",
|
|
17
17
|
fill: "var(--w-rjv-add-color, currentColor)"
|
|
18
18
|
}, props, {
|
|
19
19
|
style: _extends({}, style, defaultStyle),
|
|
20
20
|
children: /*#__PURE__*/_jsx("path", {
|
|
21
|
-
d: "
|
|
21
|
+
d: "M28.3940997,0 L11.625773,0 C4.34215619,0 0,4.34 0,11.62 L0,28.36 C0,35.66 4.34215619,40 11.625773,40 L28.3740897,40 C35.6577066,40 39.9999316,35.66 39.9999316,28.38 L39.9999316,11.62 C40.0198727,4.34 35.6777165,0 28.3940997,0 Z M30.12022,21.8947368 L21.9056145,21.8947368 L21.9056145,30.1052632 C21.9056145,31.1410526 21.0462404,32 20.0099363,32 C18.9736323,32 18.1142582,31.1410526 18.1142582,30.1052632 L18.1142582,21.8947368 L9.89965272,21.8947368 C8.86334865,21.8947368 8.00397454,21.0357895 8.00397454,20 C8.00397454,18.9642105 8.86334865,18.1052632 9.89965272,18.1052632 L18.1142582,18.1052632 L18.1142582,9.89473684 C18.1142582,8.85894737 18.9736323,8 20.0099363,8 C21.0462404,8 21.9056145,8.85894737 21.9056145,9.89473684 L21.9056145,18.1052632 L30.12022,18.1052632 C31.156524,18.1052632 32.0158982,18.9642105 32.0158982,20 C32.0158982,21.0357895 31.156524,21.8947368 30.12022,21.8947368 Z"
|
|
22
22
|
})
|
|
23
23
|
}));
|
|
24
24
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export var DeleteIcon = props => {
|
|
4
|
+
var {
|
|
5
|
+
style
|
|
6
|
+
} = props;
|
|
7
|
+
var defaultStyle = {
|
|
8
|
+
verticalAlign: 'middle',
|
|
9
|
+
display: 'inline-block',
|
|
10
|
+
cursor: 'pointer',
|
|
11
|
+
marginLeft: 5,
|
|
12
|
+
height: '1em',
|
|
13
|
+
width: '1em'
|
|
14
|
+
};
|
|
15
|
+
return /*#__PURE__*/_jsx("svg", _extends({
|
|
16
|
+
viewBox: "0 0 40 40",
|
|
17
|
+
fill: "var(--w-rjv-delete-color, #dc3545)"
|
|
18
|
+
}, props, {
|
|
19
|
+
style: _extends({}, style, defaultStyle),
|
|
20
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
21
|
+
d: "M28.3940997,0 L11.625773,0 C4.34215619,0 0,4.34 0,11.62 L0,28.36 C0,35.66 4.34215619,40 11.625773,40 L28.3740897,40 C35.6577066,40 39.9999316,35.66 39.9999316,28.38 L39.9999316,11.62 C40.0198727,4.34 35.6777165,0 28.3940997,0 Z M30.3428039,27.0681654 C31.2346195,27.9595381 31.2346195,29.4349136 30.3428039,30.3262862 C29.88152,30.7873411 29.2972271,31.0025 28.7129341,31.0025 C28.1286412,31.0025 27.5443483,30.7873411 27.0830644,30.3262862 L20.0100446,23.2567787 L12.9370249,30.3262862 C12.475741,30.7873411 11.891448,31.0025 11.3071551,31.0025 C10.7228621,31.0025 10.1385692,30.7873411 9.67728531,30.3262862 C8.78464325,29.4234847 8.78464325,27.9709669 9.67728531,27.0681654 L16.7503051,19.9986579 L9.67728531,12.9291504 C8.78464325,12.0263488 8.78464325,10.573831 9.67728531,9.67102951 C10.5691008,8.77965683 12.0452093,8.77965683 12.9370249,9.67102951 L20.0100446,16.740537 L27.0830644,9.67102951 C27.9748799,8.77965683 29.4509884,8.77965683 30.3428039,9.67102951 C31.2346195,10.5624022 31.2346195,12.0377777 30.3428039,12.9291504 L23.2697842,19.9986579 L30.3428039,27.0681654 L30.3428039,27.0681654 Z"
|
|
22
|
+
})
|
|
23
|
+
}));
|
|
24
|
+
};
|
package/esm/editor/index.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
18
18
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
19
19
|
*/
|
|
20
20
|
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
21
|
+
/**
|
|
22
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
23
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
24
|
+
*/
|
|
25
|
+
onDelete?: CountInfoExtraProps<T>['onDelete'];
|
|
21
26
|
/** Whether enable edit feature. @default true */
|
|
22
27
|
editable?: boolean;
|
|
23
28
|
}
|
package/esm/editor/index.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 = ["onEdit", "components", "editable", "displayDataTypes", "onAdd"];
|
|
3
|
+
var _excluded = ["onEdit", "components", "editable", "displayDataTypes", "onAdd", "onDelete"];
|
|
4
4
|
import { forwardRef } from 'react';
|
|
5
5
|
import JsonView from '../';
|
|
6
6
|
import { ObjectKey } from './objectKey';
|
|
@@ -13,13 +13,15 @@ var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
13
13
|
components,
|
|
14
14
|
editable = true,
|
|
15
15
|
displayDataTypes = true,
|
|
16
|
-
onAdd
|
|
16
|
+
onAdd,
|
|
17
|
+
onDelete
|
|
17
18
|
} = props,
|
|
18
19
|
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
19
20
|
var comps = _extends({}, components, {
|
|
20
21
|
countInfoExtra: reprops => /*#__PURE__*/_jsx(CountInfoExtra, _extends({}, reprops, {
|
|
21
22
|
editable: editable,
|
|
22
|
-
onAdd: onAdd
|
|
23
|
+
onAdd: onAdd,
|
|
24
|
+
onDelete: onDelete
|
|
23
25
|
})),
|
|
24
26
|
objectKey: reprops => /*#__PURE__*/_jsx(ObjectKey, _extends({}, reprops, {
|
|
25
27
|
editableValue: editable,
|
|
@@ -30,6 +32,7 @@ var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
30
32
|
return /*#__PURE__*/_jsx(ReValue, _extends({}, reprops, {
|
|
31
33
|
editableValue: editable,
|
|
32
34
|
displayDataTypes: displayDataTypes,
|
|
35
|
+
onDelete: onDelete,
|
|
33
36
|
onEdit: onEdit
|
|
34
37
|
}));
|
|
35
38
|
}
|
package/esm/editor/value.d.ts
CHANGED
|
@@ -7,8 +7,11 @@ 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
|
+
data?: T;
|
|
10
11
|
visible?: boolean;
|
|
11
12
|
editableValue?: boolean;
|
|
12
13
|
displayDataTypes?: boolean;
|
|
14
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
15
|
+
onDelete?: JsonViewEditorProps<T>['onDelete'];
|
|
13
16
|
}
|
|
14
17
|
export declare function ReValue<T extends object>(props: ReValueProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/esm/editor/value.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onEdit"];
|
|
4
|
+
var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "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';
|
|
8
|
+
import { DeleteIcon } from './icon/delete';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
11
|
var Quotes = _ref => {
|
|
@@ -24,11 +25,15 @@ export function ReValue(props) {
|
|
|
24
25
|
var {
|
|
25
26
|
type,
|
|
26
27
|
value,
|
|
28
|
+
setValue,
|
|
29
|
+
data,
|
|
30
|
+
keyName,
|
|
27
31
|
visible,
|
|
28
32
|
quotes,
|
|
29
33
|
style,
|
|
30
34
|
displayDataTypes,
|
|
31
35
|
editableValue,
|
|
36
|
+
onDelete,
|
|
32
37
|
onEdit
|
|
33
38
|
} = props,
|
|
34
39
|
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
@@ -145,6 +150,18 @@ export function ReValue(props) {
|
|
|
145
150
|
if (typeStr === 'null' || typeStr === 'undefined') {
|
|
146
151
|
typeView = /*#__PURE__*/_jsx(Fragment, {});
|
|
147
152
|
}
|
|
153
|
+
var deleteHandle = /*#__PURE__*/function () {
|
|
154
|
+
var _ref3 = _asyncToGenerator(function* (evn) {
|
|
155
|
+
evn.stopPropagation();
|
|
156
|
+
if (data && keyName && keyName in data && setValue) {
|
|
157
|
+
delete data[keyName];
|
|
158
|
+
setValue(_extends({}, data));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return function deleteHandle(_x) {
|
|
162
|
+
return _ref3.apply(this, arguments);
|
|
163
|
+
};
|
|
164
|
+
}();
|
|
148
165
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
149
166
|
children: [displayDataTypes && typeView, /*#__PURE__*/_jsx(Quotes, {
|
|
150
167
|
style: style,
|
|
@@ -160,6 +177,8 @@ export function ReValue(props) {
|
|
|
160
177
|
show: typeStr === 'string'
|
|
161
178
|
}), visible && editableValue && onEdit && /*#__PURE__*/_jsx(EditIcon, {
|
|
162
179
|
onClick: click
|
|
180
|
+
}), visible && editableValue && onDelete && /*#__PURE__*/_jsx(DeleteIcon, {
|
|
181
|
+
onClick: deleteHandle
|
|
163
182
|
})]
|
|
164
183
|
});
|
|
165
184
|
}
|
package/esm/node.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
|
|
|
6
6
|
keyName?: string | number;
|
|
7
7
|
keyid?: string;
|
|
8
8
|
level?: number;
|
|
9
|
+
parentValue?: T;
|
|
10
|
+
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
9
11
|
}
|
|
10
12
|
export declare function RooNode<T extends object>(props: RooNodeProps<T>): import("react/jsx-runtime").JSX.Element;
|
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", "onCopied", "onExpand"];
|
|
3
|
+
var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand", "parentValue", "setParentValue"];
|
|
4
4
|
import { Fragment, useId, cloneElement, useState, useEffect } from 'react';
|
|
5
5
|
import { ValueView, Colon, Label, Line, typeMap } from './value';
|
|
6
6
|
import { TriangleArrow } from './arrow/TriangleArrow';
|
|
@@ -43,7 +43,9 @@ export function RooNode(props) {
|
|
|
43
43
|
keyid = 'root',
|
|
44
44
|
quotes = '"',
|
|
45
45
|
onCopied,
|
|
46
|
-
onExpand
|
|
46
|
+
onExpand,
|
|
47
|
+
parentValue,
|
|
48
|
+
setParentValue
|
|
47
49
|
} = props,
|
|
48
50
|
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
49
51
|
var isArray = Array.isArray(value);
|
|
@@ -63,6 +65,7 @@ export function RooNode(props) {
|
|
|
63
65
|
});
|
|
64
66
|
!expand ? store.expand(keyid) : store.collapse(keyid);
|
|
65
67
|
};
|
|
68
|
+
var [valueData, setValueData] = useState(value);
|
|
66
69
|
var subNodeProps = {
|
|
67
70
|
components,
|
|
68
71
|
indentWidth,
|
|
@@ -73,6 +76,8 @@ export function RooNode(props) {
|
|
|
73
76
|
onCopied,
|
|
74
77
|
onExpand,
|
|
75
78
|
collapsed,
|
|
79
|
+
parentValue: value,
|
|
80
|
+
setParentValue: setValueData,
|
|
76
81
|
quotes,
|
|
77
82
|
level: level + 1,
|
|
78
83
|
style: {
|
|
@@ -84,7 +89,9 @@ export function RooNode(props) {
|
|
|
84
89
|
displayObjectSize,
|
|
85
90
|
enableClipboard,
|
|
86
91
|
indentWidth,
|
|
92
|
+
data: valueData,
|
|
87
93
|
quotes,
|
|
94
|
+
setValue: setValueData,
|
|
88
95
|
renderBraces: components.braces,
|
|
89
96
|
renderValue: components.value
|
|
90
97
|
};
|
|
@@ -102,7 +109,6 @@ export function RooNode(props) {
|
|
|
102
109
|
eventProps.onMouseEnter = () => setShowTools(true);
|
|
103
110
|
eventProps.onMouseLeave = () => setShowTools(false);
|
|
104
111
|
}
|
|
105
|
-
var [valueData, setValueData] = useState(value);
|
|
106
112
|
useEffect(() => setValueData(value), [value]);
|
|
107
113
|
var nameKeys = isArray ? Object.keys(valueData).map(m => Number(m)) : Object.keys(valueData);
|
|
108
114
|
|
|
@@ -165,8 +171,11 @@ export function RooNode(props) {
|
|
|
165
171
|
count: nameKeys.length,
|
|
166
172
|
level,
|
|
167
173
|
showTools,
|
|
174
|
+
keyName,
|
|
168
175
|
visible: expand,
|
|
169
176
|
value: valueData,
|
|
177
|
+
parentValue,
|
|
178
|
+
setParentValue,
|
|
170
179
|
setValue: setValueData
|
|
171
180
|
}), enableClipboard && /*#__PURE__*/_jsx(Copied, {
|
|
172
181
|
show: showTools,
|
|
@@ -180,7 +189,7 @@ export function RooNode(props) {
|
|
|
180
189
|
borderLeft: 'var(--w-rjv-border-left-width, 1px) var(--w-rjv-line-style, solid) var(--w-rjv-line-color, #ebebeb)',
|
|
181
190
|
marginLeft: 6
|
|
182
191
|
},
|
|
183
|
-
children: entries.length > 0 && entries.map((_ref6, idx) => {
|
|
192
|
+
children: entries.length > 0 && [...entries].map((_ref6, idx) => {
|
|
184
193
|
var [key, itemVal] = _ref6;
|
|
185
194
|
var item = itemVal;
|
|
186
195
|
var renderKey = /*#__PURE__*/_jsx(Semicolon, {
|
package/esm/value.d.ts
CHANGED
|
@@ -46,9 +46,19 @@ export declare const typeMap: {
|
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
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
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
56
|
+
keyName?: ValueViewProps<T>['keyName'];
|
|
57
|
+
}
|
|
49
58
|
export interface ValueViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
50
59
|
keyName?: string | number;
|
|
51
60
|
value?: unknown;
|
|
61
|
+
data?: T;
|
|
52
62
|
displayDataTypes: boolean;
|
|
53
63
|
displayObjectSize: boolean;
|
|
54
64
|
enableClipboard: boolean;
|
|
@@ -57,13 +67,8 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
57
67
|
quotes?: JsonViewProps<T>['quotes'];
|
|
58
68
|
renderKey?: JSX.Element;
|
|
59
69
|
renderBraces?: MetaProps['render'];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
value?: unknown;
|
|
63
|
-
visible?: boolean;
|
|
64
|
-
quotes?: JsonViewProps<T>['quotes'];
|
|
65
|
-
keyName?: ValueViewProps<T>['keyName'];
|
|
66
|
-
}) => JSX.Element;
|
|
70
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
71
|
+
renderValue?: (props: RenderValueProps<T>) => JSX.Element;
|
|
67
72
|
}
|
|
68
73
|
export declare function getValueString<T>(value: T): {
|
|
69
74
|
type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
|
|
@@ -81,3 +86,4 @@ export interface TypeProps extends React.DetailedHTMLProps<React.HTMLAttributes<
|
|
|
81
86
|
type: keyof typeof typeMap;
|
|
82
87
|
}
|
|
83
88
|
export declare const Type: FC<PropsWithChildren<TypeProps>>;
|
|
89
|
+
export {};
|
package/esm/value.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
4
|
+
_excluded2 = ["value", "setValue", "data", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
5
5
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
6
6
|
import { Fragment, forwardRef, useState } from 'react';
|
|
7
7
|
import { CountInfo } from './node';
|
|
@@ -38,7 +38,7 @@ export var typeMap = {
|
|
|
38
38
|
},
|
|
39
39
|
url: {
|
|
40
40
|
color: 'var(--w-rjv-type-url-color, #0969da)',
|
|
41
|
-
label: '
|
|
41
|
+
label: 'url'
|
|
42
42
|
},
|
|
43
43
|
null: {
|
|
44
44
|
color: 'var(--w-rjv-type-null-color, #d33682)',
|
|
@@ -112,6 +112,8 @@ export function ValueView(props) {
|
|
|
112
112
|
var _typeMap$type;
|
|
113
113
|
var {
|
|
114
114
|
value,
|
|
115
|
+
setValue,
|
|
116
|
+
data,
|
|
115
117
|
keyName,
|
|
116
118
|
indentWidth,
|
|
117
119
|
renderKey,
|
|
@@ -169,6 +171,8 @@ export function ValueView(props) {
|
|
|
169
171
|
}, style),
|
|
170
172
|
type,
|
|
171
173
|
value,
|
|
174
|
+
setValue,
|
|
175
|
+
data,
|
|
172
176
|
quotes,
|
|
173
177
|
keyName,
|
|
174
178
|
visible: showTools,
|