@uiw/react-json-view 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -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 +6 -0
- package/cjs/editor/index.js +5 -2
- package/cjs/editor/objectKey.js +52 -20
- package/cjs/editor/value.d.ts +4 -0
- package/cjs/editor/value.js +42 -12
- package/cjs/node.d.ts +3 -0
- package/cjs/node.js +34 -16
- package/cjs/semicolon.d.ts +1 -0
- package/cjs/semicolon.js +3 -2
- package/cjs/value.d.ts +15 -7
- package/cjs/value.js +8 -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 +6 -0
- package/esm/editor/index.js +6 -3
- package/esm/editor/objectKey.js +34 -20
- package/esm/editor/value.d.ts +4 -0
- package/esm/editor/value.js +35 -12
- package/esm/node.d.ts +3 -0
- package/esm/node.js +26 -10
- package/esm/semicolon.d.ts +1 -0
- package/esm/semicolon.js +3 -2
- package/esm/value.d.ts +15 -7
- package/esm/value.js +8 -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}>
|
|
@@ -526,6 +530,11 @@ export default function Demo() {
|
|
|
526
530
|
}}
|
|
527
531
|
onEdit={(opts) => {
|
|
528
532
|
console.log('opts:', opts)
|
|
533
|
+
// opts.namespace: ['object', 'child', 'last']
|
|
534
|
+
// opts.oldValue: null
|
|
535
|
+
// opts.type: "value"
|
|
536
|
+
// opts.value: "NULL3"
|
|
537
|
+
return true;
|
|
529
538
|
}}
|
|
530
539
|
components={{
|
|
531
540
|
objectKey: ObjectKey
|
|
@@ -752,6 +761,7 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
752
761
|
oldValue: unknown;
|
|
753
762
|
keyName?: string | number;
|
|
754
763
|
parentName?: string | number;
|
|
764
|
+
namespace?: Array<string | number>;
|
|
755
765
|
type?: 'value' | 'key';
|
|
756
766
|
}) => boolean;
|
|
757
767
|
/**
|
|
@@ -759,6 +769,11 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
759
769
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
760
770
|
*/
|
|
761
771
|
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
772
|
+
/**
|
|
773
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
774
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
775
|
+
*/
|
|
776
|
+
onDelete?: CountInfoExtraProps<T>['onDelete'];
|
|
762
777
|
/** Whether enable edit feature. @default true */
|
|
763
778
|
editable?: boolean;
|
|
764
779
|
}
|
|
@@ -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
|
@@ -11,6 +11,7 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
11
11
|
oldValue: unknown;
|
|
12
12
|
keyName?: string | number;
|
|
13
13
|
parentName?: string | number;
|
|
14
|
+
namespace?: Array<string | number>;
|
|
14
15
|
type?: 'value' | 'key';
|
|
15
16
|
}) => boolean;
|
|
16
17
|
/**
|
|
@@ -18,6 +19,11 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
18
19
|
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
19
20
|
*/
|
|
20
21
|
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
22
|
+
/**
|
|
23
|
+
* When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
|
|
24
|
+
* @returns Returning false from onDelete will prevent the change from being made.
|
|
25
|
+
*/
|
|
26
|
+
onDelete?: CountInfoExtraProps<T>['onDelete'];
|
|
21
27
|
/** Whether enable edit feature. @default true */
|
|
22
28
|
editable?: boolean;
|
|
23
29
|
}
|
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/objectKey.js
CHANGED
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.ObjectKey = void 0;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
13
|
var _react = require("react");
|
|
12
14
|
var _semicolon = require("../semicolon");
|
|
13
15
|
var _value = require("../value");
|
|
14
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
-
var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "editableValue", "onEdit", "highlightUpdates", "render"];
|
|
17
|
+
var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "namespace", "editableValue", "onEdit", "highlightUpdates", "render"];
|
|
16
18
|
var ObjectKey = function ObjectKey(props) {
|
|
17
19
|
var className = props.className,
|
|
18
20
|
value = props.value,
|
|
@@ -20,6 +22,7 @@ var ObjectKey = function ObjectKey(props) {
|
|
|
20
22
|
parentName = props.parentName,
|
|
21
23
|
quotes = props.quotes,
|
|
22
24
|
label = props.label,
|
|
25
|
+
namespace = props.namespace,
|
|
23
26
|
editableValue = props.editableValue,
|
|
24
27
|
onEdit = props.onEdit,
|
|
25
28
|
_props$highlightUpdat = props.highlightUpdates,
|
|
@@ -55,22 +58,51 @@ var ObjectKey = function ObjectKey(props) {
|
|
|
55
58
|
(_$edit$current = $edit.current) === null || _$edit$current === void 0 ? void 0 : _$edit$current.focus();
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
|
-
var blur = function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
61
|
+
var blur = /*#__PURE__*/function () {
|
|
62
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
|
|
63
|
+
var _$edit$current2, result;
|
|
64
|
+
return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
|
|
65
|
+
while (1) switch (_context.prev = _context.next) {
|
|
66
|
+
case 0:
|
|
67
|
+
if (!$edit.current) {
|
|
68
|
+
_context.next = 8;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
if (!onEdit) {
|
|
72
|
+
_context.next = 6;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
_context.next = 4;
|
|
76
|
+
return onEdit({
|
|
77
|
+
value: $edit.current.innerText,
|
|
78
|
+
oldValue: curentLabel,
|
|
79
|
+
namespace: namespace,
|
|
80
|
+
keyName: keyName,
|
|
81
|
+
parentName: parentName,
|
|
82
|
+
type: 'key'
|
|
83
|
+
});
|
|
84
|
+
case 4:
|
|
85
|
+
result = _context.sent;
|
|
86
|
+
if (result) {
|
|
87
|
+
setCurentLabel($edit.current.innerText);
|
|
88
|
+
} else {
|
|
89
|
+
$edit.current.innerText = curentLabel;
|
|
90
|
+
}
|
|
91
|
+
case 6:
|
|
92
|
+
$edit.current.contentEditable = 'false';
|
|
93
|
+
(_$edit$current2 = $edit.current) === null || _$edit$current2 === void 0 ? void 0 : _$edit$current2.focus();
|
|
94
|
+
case 8:
|
|
95
|
+
setEditable(false);
|
|
96
|
+
case 9:
|
|
97
|
+
case "end":
|
|
98
|
+
return _context.stop();
|
|
99
|
+
}
|
|
100
|
+
}, _callee);
|
|
101
|
+
}));
|
|
102
|
+
return function blur() {
|
|
103
|
+
return _ref.apply(this, arguments);
|
|
104
|
+
};
|
|
105
|
+
}();
|
|
74
106
|
var focus = function focus() {
|
|
75
107
|
if ($edit.current) {
|
|
76
108
|
var _$edit$current3;
|
|
@@ -87,11 +119,11 @@ var ObjectKey = function ObjectKey(props) {
|
|
|
87
119
|
};
|
|
88
120
|
(0, _react.useEffect)(function () {
|
|
89
121
|
if ($edit.current) {
|
|
90
|
-
$edit.current.addEventListener(
|
|
122
|
+
$edit.current.addEventListener('paste', function (e) {
|
|
91
123
|
e.preventDefault();
|
|
92
124
|
// @ts-ignore
|
|
93
|
-
var text = e.clipboardData.getData(
|
|
94
|
-
document.execCommand(
|
|
125
|
+
var text = e.clipboardData.getData('text/plain');
|
|
126
|
+
document.execCommand('insertHTML', false, text);
|
|
95
127
|
});
|
|
96
128
|
}
|
|
97
129
|
}, [$edit]);
|
package/cjs/editor/value.d.ts
CHANGED
|
@@ -7,8 +7,12 @@ 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;
|
|
12
|
+
namespace?: Array<string | number>;
|
|
11
13
|
editableValue?: boolean;
|
|
12
14
|
displayDataTypes?: boolean;
|
|
15
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
16
|
+
onDelete?: JsonViewEditorProps<T>['onDelete'];
|
|
13
17
|
}
|
|
14
18
|
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", "namespace", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
|
|
18
19
|
var Quotes = function Quotes(_ref) {
|
|
19
20
|
var show = _ref.show,
|
|
20
21
|
style = _ref.style,
|
|
@@ -29,13 +30,17 @@ 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,
|
|
35
38
|
style = props.style,
|
|
36
39
|
children = props.children,
|
|
40
|
+
namespace = props.namespace,
|
|
37
41
|
displayDataTypes = props.displayDataTypes,
|
|
38
42
|
editableValue = props.editableValue,
|
|
43
|
+
onDelete = props.onDelete,
|
|
39
44
|
onEdit = props.onEdit,
|
|
40
45
|
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
41
46
|
var _useState = (0, _react.useState)(false),
|
|
@@ -60,7 +65,7 @@ function ReValue(props) {
|
|
|
60
65
|
if ($edit.current) {
|
|
61
66
|
var _$edit$current;
|
|
62
67
|
setEditable(true);
|
|
63
|
-
$edit.current.contentEditable
|
|
68
|
+
$edit.current.setAttribute('contentEditable', 'true');
|
|
64
69
|
(_$edit$current = $edit.current) === null || _$edit$current === void 0 ? void 0 : _$edit$current.focus();
|
|
65
70
|
}
|
|
66
71
|
};
|
|
@@ -70,7 +75,9 @@ function ReValue(props) {
|
|
|
70
75
|
evn.stopPropagation();
|
|
71
76
|
evn.preventDefault();
|
|
72
77
|
setEditable(false);
|
|
73
|
-
$edit.current
|
|
78
|
+
if ($edit.current) {
|
|
79
|
+
$edit.current.setAttribute('contentEditable', 'false');
|
|
80
|
+
}
|
|
74
81
|
}
|
|
75
82
|
};
|
|
76
83
|
var blur = /*#__PURE__*/function () {
|
|
@@ -90,8 +97,8 @@ function ReValue(props) {
|
|
|
90
97
|
_context.next = 16;
|
|
91
98
|
break;
|
|
92
99
|
}
|
|
93
|
-
$edit.current.contentEditable
|
|
94
|
-
text = $edit.current.
|
|
100
|
+
$edit.current.setAttribute('contentEditable', 'false');
|
|
101
|
+
text = $edit.current.innerHTML;
|
|
95
102
|
_typeStr = curentType;
|
|
96
103
|
if (curentType === 'number' || curentType === 'float') {
|
|
97
104
|
text = Number(text);
|
|
@@ -104,16 +111,16 @@ function ReValue(props) {
|
|
|
104
111
|
if (Number.isNaN(text)) {
|
|
105
112
|
_typeStr = 'number';
|
|
106
113
|
}
|
|
107
|
-
if (typeof text === 'string' && /^(true|false)$/
|
|
108
|
-
text = /^(true)$/
|
|
114
|
+
if (typeof text === 'string' && /^(true|false)$/gi.test(text)) {
|
|
115
|
+
text = /^(true)$/gi.test(text) ? true : false;
|
|
109
116
|
_typeStr = 'boolean';
|
|
110
|
-
} else if (typeof text === 'string' && /^[\d]+n$/
|
|
111
|
-
text = BigInt(text.replace(/n$/
|
|
117
|
+
} else if (typeof text === 'string' && /^[\d]+n$/gi.test(text)) {
|
|
118
|
+
text = BigInt(text.replace(/n$/gi, ''));
|
|
112
119
|
_typeStr = 'bigint';
|
|
113
|
-
} else if (typeof text === 'string' && /^(null)$/
|
|
120
|
+
} else if (typeof text === 'string' && /^(null)$/gi.test(text)) {
|
|
114
121
|
text = null;
|
|
115
122
|
_typeStr = 'null';
|
|
116
|
-
} else if (typeof text === 'string' && /^(undefined)$/
|
|
123
|
+
} else if (typeof text === 'string' && /^(undefined)$/gi.test(text)) {
|
|
117
124
|
text = undefined;
|
|
118
125
|
_typeStr = 'undefined';
|
|
119
126
|
} else if (typeof text === 'string') {
|
|
@@ -133,7 +140,8 @@ function ReValue(props) {
|
|
|
133
140
|
return onEdit({
|
|
134
141
|
type: 'value',
|
|
135
142
|
value: text,
|
|
136
|
-
oldValue: curentChild
|
|
143
|
+
oldValue: curentChild,
|
|
144
|
+
namespace: namespace
|
|
137
145
|
});
|
|
138
146
|
case 14:
|
|
139
147
|
result = _context.sent;
|
|
@@ -180,6 +188,26 @@ function ReValue(props) {
|
|
|
180
188
|
if (typeStr === 'null' || typeStr === 'undefined') {
|
|
181
189
|
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
182
190
|
}
|
|
191
|
+
var deleteHandle = /*#__PURE__*/function () {
|
|
192
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(evn) {
|
|
193
|
+
return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
|
|
194
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
195
|
+
case 0:
|
|
196
|
+
evn.stopPropagation();
|
|
197
|
+
if (data && keyName && keyName in data && setValue) {
|
|
198
|
+
delete data[keyName];
|
|
199
|
+
setValue((0, _objectSpread2["default"])({}, data));
|
|
200
|
+
}
|
|
201
|
+
case 2:
|
|
202
|
+
case "end":
|
|
203
|
+
return _context2.stop();
|
|
204
|
+
}
|
|
205
|
+
}, _callee2);
|
|
206
|
+
}));
|
|
207
|
+
return function deleteHandle(_x) {
|
|
208
|
+
return _ref3.apply(this, arguments);
|
|
209
|
+
};
|
|
210
|
+
}();
|
|
183
211
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
184
212
|
children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
|
|
185
213
|
style: style,
|
|
@@ -195,6 +223,8 @@ function ReValue(props) {
|
|
|
195
223
|
show: typeStr === 'string'
|
|
196
224
|
}), visible && editableValue && onEdit && /*#__PURE__*/(0, _jsxRuntime.jsx)(_edit.EditIcon, {
|
|
197
225
|
onClick: click
|
|
226
|
+
}), visible && editableValue && onDelete && /*#__PURE__*/(0, _jsxRuntime.jsx)(_delete.DeleteIcon, {
|
|
227
|
+
onClick: deleteHandle
|
|
198
228
|
})]
|
|
199
229
|
});
|
|
200
230
|
}
|
package/cjs/node.d.ts
CHANGED
|
@@ -6,5 +6,8 @@ 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
|
+
namespace?: Array<string | number>;
|
|
11
|
+
setParentValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
9
12
|
}
|
|
10
13
|
export declare function RooNode<T extends object>(props: RooNodeProps<T>): import("react/jsx-runtime").JSX.Element;
|