@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/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", "namespace", "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, {
|
|
@@ -60,17 +61,17 @@ function RooNode(props) {
|
|
|
60
61
|
keyid = _props$keyid === void 0 ? 'root' : _props$keyid,
|
|
61
62
|
_props$quotes = props.quotes,
|
|
62
63
|
quotes = _props$quotes === void 0 ? '"' : _props$quotes,
|
|
64
|
+
_props$namespace = props.namespace,
|
|
65
|
+
namespace = _props$namespace === void 0 ? [] : _props$namespace,
|
|
63
66
|
onCopied = props.onCopied,
|
|
64
67
|
onExpand = props.onExpand,
|
|
68
|
+
parentValue = props.parentValue,
|
|
69
|
+
setParentValue = props.setParentValue,
|
|
65
70
|
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
66
71
|
var isArray = Array.isArray(value);
|
|
67
72
|
var subkeyid = (0, _react.useId)();
|
|
68
73
|
var expands = (0, _store.useExpandsStatus)();
|
|
69
74
|
var expand = (_expands$keyid = expands[keyid]) !== null && _expands$keyid !== void 0 ? _expands$keyid : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level <= collapsed : true;
|
|
70
|
-
var arrowStyle = {
|
|
71
|
-
transform: "rotate(".concat(expand ? '0' : '-90', "deg)"),
|
|
72
|
-
transition: 'all 0.3s'
|
|
73
|
-
};
|
|
74
75
|
var handle = function handle() {
|
|
75
76
|
onExpand && typeof onExpand === 'function' && onExpand({
|
|
76
77
|
expand: !expand,
|
|
@@ -80,6 +81,10 @@ function RooNode(props) {
|
|
|
80
81
|
});
|
|
81
82
|
!expand ? _store.store.expand(keyid) : _store.store.collapse(keyid);
|
|
82
83
|
};
|
|
84
|
+
var _useState = (0, _react.useState)(value),
|
|
85
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
86
|
+
valueData = _useState2[0],
|
|
87
|
+
setValueData = _useState2[1];
|
|
83
88
|
var subNodeProps = {
|
|
84
89
|
components: components,
|
|
85
90
|
indentWidth: indentWidth,
|
|
@@ -90,6 +95,8 @@ function RooNode(props) {
|
|
|
90
95
|
onCopied: onCopied,
|
|
91
96
|
onExpand: onExpand,
|
|
92
97
|
collapsed: collapsed,
|
|
98
|
+
parentValue: value,
|
|
99
|
+
setParentValue: setValueData,
|
|
93
100
|
quotes: quotes,
|
|
94
101
|
level: level + 1,
|
|
95
102
|
style: {
|
|
@@ -101,22 +108,28 @@ function RooNode(props) {
|
|
|
101
108
|
displayObjectSize: displayObjectSize,
|
|
102
109
|
enableClipboard: enableClipboard,
|
|
103
110
|
indentWidth: indentWidth,
|
|
111
|
+
data: valueData,
|
|
104
112
|
quotes: quotes,
|
|
113
|
+
setValue: setValueData,
|
|
105
114
|
renderBraces: components.braces,
|
|
106
115
|
renderValue: components.value
|
|
107
116
|
};
|
|
117
|
+
var arrowStyle = {
|
|
118
|
+
transform: "rotate(".concat(expand ? '0' : '-90', "deg)"),
|
|
119
|
+
transition: 'all 0.3s'
|
|
120
|
+
};
|
|
108
121
|
var arrowView = components.arrow ? /*#__PURE__*/(0, _react.cloneElement)(components.arrow, {
|
|
109
122
|
style: arrowStyle,
|
|
110
123
|
'data-expand': expand,
|
|
111
|
-
className:
|
|
124
|
+
className: 'w-rjv-arrow'
|
|
112
125
|
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_TriangleArrow.TriangleArrow, {
|
|
113
126
|
style: arrowStyle,
|
|
114
127
|
className: "w-rjv-arrow"
|
|
115
128
|
});
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
showTools =
|
|
119
|
-
setShowTools =
|
|
129
|
+
var _useState3 = (0, _react.useState)(false),
|
|
130
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
131
|
+
showTools = _useState4[0],
|
|
132
|
+
setShowTools = _useState4[1];
|
|
120
133
|
var eventProps = {};
|
|
121
134
|
if (enableClipboard) {
|
|
122
135
|
eventProps.onMouseEnter = function () {
|
|
@@ -126,10 +139,6 @@ function RooNode(props) {
|
|
|
126
139
|
return setShowTools(false);
|
|
127
140
|
};
|
|
128
141
|
}
|
|
129
|
-
var _useState3 = (0, _react.useState)(value),
|
|
130
|
-
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
131
|
-
valueData = _useState4[0],
|
|
132
|
-
setValueData = _useState4[1];
|
|
133
142
|
(0, _react.useEffect)(function () {
|
|
134
143
|
return setValueData(value);
|
|
135
144
|
}, [value]);
|
|
@@ -180,6 +189,7 @@ function RooNode(props) {
|
|
|
180
189
|
value: valueData,
|
|
181
190
|
quotes: quotes,
|
|
182
191
|
"data-keys": keyid,
|
|
192
|
+
namespace: (0, _toConsumableArray2["default"])(namespace),
|
|
183
193
|
render: components.objectKey,
|
|
184
194
|
keyName: keyName,
|
|
185
195
|
parentName: keyName,
|
|
@@ -202,8 +212,11 @@ function RooNode(props) {
|
|
|
202
212
|
count: nameKeys.length,
|
|
203
213
|
level: level,
|
|
204
214
|
showTools: showTools,
|
|
215
|
+
keyName: keyName,
|
|
205
216
|
visible: expand,
|
|
206
217
|
value: valueData,
|
|
218
|
+
parentValue: parentValue,
|
|
219
|
+
setParentValue: setParentValue,
|
|
207
220
|
setValue: setValueData
|
|
208
221
|
}), enableClipboard && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
209
222
|
show: showTools,
|
|
@@ -217,7 +230,7 @@ function RooNode(props) {
|
|
|
217
230
|
borderLeft: 'var(--w-rjv-border-left-width, 1px) var(--w-rjv-line-style, solid) var(--w-rjv-line-color, #ebebeb)',
|
|
218
231
|
marginLeft: 6
|
|
219
232
|
},
|
|
220
|
-
children: entries.length > 0 && entries.map(function (_ref10, idx) {
|
|
233
|
+
children: entries.length > 0 && (0, _toConsumableArray2["default"])(entries).map(function (_ref10, idx) {
|
|
221
234
|
var _ref11 = (0, _slicedToArray2["default"])(_ref10, 2),
|
|
222
235
|
key = _ref11[0],
|
|
223
236
|
itemVal = _ref11[1];
|
|
@@ -226,6 +239,7 @@ function RooNode(props) {
|
|
|
226
239
|
value: item,
|
|
227
240
|
"data-keys": keyid,
|
|
228
241
|
quotes: quotes,
|
|
242
|
+
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
|
|
229
243
|
parentName: keyName,
|
|
230
244
|
highlightUpdates: highlightUpdates,
|
|
231
245
|
render: components.objectKey,
|
|
@@ -239,6 +253,7 @@ function RooNode(props) {
|
|
|
239
253
|
className: "w-rjv-wrap",
|
|
240
254
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
241
255
|
value: item,
|
|
256
|
+
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [label]),
|
|
242
257
|
keyName: label,
|
|
243
258
|
keyid: keyid + subkeyid + label
|
|
244
259
|
}, subNodeProps))
|
|
@@ -249,6 +264,7 @@ function RooNode(props) {
|
|
|
249
264
|
className: "w-rjv-wrap",
|
|
250
265
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
251
266
|
value: item,
|
|
267
|
+
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
|
|
252
268
|
keyName: key,
|
|
253
269
|
keyid: keyid + subkeyid + key
|
|
254
270
|
}, subNodeProps))
|
|
@@ -257,7 +273,9 @@ function RooNode(props) {
|
|
|
257
273
|
if (typeof item === 'function') {
|
|
258
274
|
return;
|
|
259
275
|
}
|
|
260
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
276
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
277
|
+
namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key])
|
|
278
|
+
}, valueViewProps), {}, {
|
|
261
279
|
renderKey: renderKey,
|
|
262
280
|
keyName: key,
|
|
263
281
|
value: item
|
package/cjs/semicolon.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface SemicolonProps extends LabelProps {
|
|
|
15
15
|
quotes?: JsonViewProps<object>['quotes'];
|
|
16
16
|
value?: object;
|
|
17
17
|
label?: string;
|
|
18
|
+
namespace?: Array<string | number>;
|
|
18
19
|
render?: (props: SemicolonProps) => React.ReactNode;
|
|
19
20
|
}
|
|
20
21
|
export declare const Semicolon: FC<PropsWithChildren<SemicolonProps>>;
|
package/cjs/semicolon.js
CHANGED
|
@@ -13,7 +13,7 @@ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
|
13
13
|
var _react = require("react");
|
|
14
14
|
var _value = require("./value");
|
|
15
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
-
var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "parentName"];
|
|
16
|
+
var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "namespace", "parentName"];
|
|
17
17
|
function usePrevious(value) {
|
|
18
18
|
var ref = (0, _react.useRef)();
|
|
19
19
|
(0, _react.useEffect)(function () {
|
|
@@ -77,6 +77,7 @@ var Semicolon = function Semicolon(_ref2) {
|
|
|
77
77
|
highlightUpdates = _ref2.highlightUpdates,
|
|
78
78
|
quotes = _ref2.quotes,
|
|
79
79
|
style = _ref2.style,
|
|
80
|
+
namespace = _ref2.namespace,
|
|
80
81
|
parentName = _ref2.parentName,
|
|
81
82
|
props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
|
|
82
83
|
var highlightContainer = (0, _react.useRef)(null);
|
|
@@ -86,6 +87,7 @@ var Semicolon = function Semicolon(_ref2) {
|
|
|
86
87
|
className: className
|
|
87
88
|
}, props), {}, {
|
|
88
89
|
value: value,
|
|
90
|
+
namespace: namespace,
|
|
89
91
|
style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
|
|
90
92
|
color: color
|
|
91
93
|
}),
|
|
@@ -96,7 +98,6 @@ var Semicolon = function Semicolon(_ref2) {
|
|
|
96
98
|
children: content
|
|
97
99
|
}));
|
|
98
100
|
}
|
|
99
|
-
;
|
|
100
101
|
useHighlight({
|
|
101
102
|
value: value,
|
|
102
103
|
highlightUpdates: highlightUpdates,
|
package/cjs/value.d.ts
CHANGED
|
@@ -46,24 +46,31 @@ 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
|
+
namespace?: Array<string | number>;
|
|
56
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
57
|
+
keyName?: ValueViewProps<T>['keyName'];
|
|
58
|
+
}
|
|
49
59
|
export interface ValueViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
50
60
|
keyName?: string | number;
|
|
51
61
|
value?: unknown;
|
|
62
|
+
data?: T;
|
|
52
63
|
displayDataTypes: boolean;
|
|
53
64
|
displayObjectSize: boolean;
|
|
54
65
|
enableClipboard: boolean;
|
|
55
66
|
indentWidth: number;
|
|
56
67
|
level?: number;
|
|
68
|
+
namespace?: Array<string | number>;
|
|
57
69
|
quotes?: JsonViewProps<T>['quotes'];
|
|
58
70
|
renderKey?: JSX.Element;
|
|
59
71
|
renderBraces?: MetaProps['render'];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
value?: unknown;
|
|
63
|
-
visible?: boolean;
|
|
64
|
-
quotes?: JsonViewProps<T>['quotes'];
|
|
65
|
-
keyName?: ValueViewProps<T>['keyName'];
|
|
66
|
-
}) => JSX.Element;
|
|
72
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
73
|
+
renderValue?: (props: RenderValueProps<T>) => JSX.Element;
|
|
67
74
|
}
|
|
68
75
|
export declare function getValueString<T>(value: T): {
|
|
69
76
|
type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
|
|
@@ -81,3 +88,4 @@ export interface TypeProps extends React.DetailedHTMLProps<React.HTMLAttributes<
|
|
|
81
88
|
type: keyof typeof typeMap;
|
|
82
89
|
}
|
|
83
90
|
export declare const Type: FC<PropsWithChildren<TypeProps>>;
|
|
91
|
+
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", "namespace", "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,8 +129,11 @@ 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,
|
|
136
|
+
namespace = props.namespace,
|
|
134
137
|
renderKey = props.renderKey,
|
|
135
138
|
quotes = props.quotes,
|
|
136
139
|
level = props.level,
|
|
@@ -192,8 +195,11 @@ function ValueView(props) {
|
|
|
192
195
|
}, style),
|
|
193
196
|
type: type,
|
|
194
197
|
value: value,
|
|
198
|
+
setValue: setValue,
|
|
199
|
+
data: data,
|
|
195
200
|
quotes: quotes,
|
|
196
201
|
keyName: keyName,
|
|
202
|
+
namespace: namespace,
|
|
197
203
|
visible: showTools,
|
|
198
204
|
content: content,
|
|
199
205
|
children: content
|
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
|
@@ -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/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/objectKey.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "editableValue", "onEdit", "highlightUpdates", "render"];
|
|
4
|
+
var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "namespace", "editableValue", "onEdit", "highlightUpdates", "render"];
|
|
4
5
|
import { useEffect, useRef, useState } from 'react';
|
|
5
6
|
import { useHighlight } from '../semicolon';
|
|
6
7
|
import { Label } from '../value';
|
|
@@ -13,6 +14,7 @@ export var ObjectKey = props => {
|
|
|
13
14
|
parentName,
|
|
14
15
|
quotes,
|
|
15
16
|
label,
|
|
17
|
+
namespace,
|
|
16
18
|
editableValue,
|
|
17
19
|
onEdit,
|
|
18
20
|
highlightUpdates = true,
|
|
@@ -40,22 +42,34 @@ export var ObjectKey = props => {
|
|
|
40
42
|
(_$edit$current = $edit.current) == null ? void 0 : _$edit$current.focus();
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
|
-
var blur = ()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
var blur = /*#__PURE__*/function () {
|
|
46
|
+
var _ref = _asyncToGenerator(function* () {
|
|
47
|
+
if ($edit.current) {
|
|
48
|
+
var _$edit$current2;
|
|
49
|
+
if (onEdit) {
|
|
50
|
+
var result = yield onEdit({
|
|
51
|
+
value: $edit.current.innerText,
|
|
52
|
+
oldValue: curentLabel,
|
|
53
|
+
namespace,
|
|
54
|
+
keyName,
|
|
55
|
+
parentName,
|
|
56
|
+
type: 'key'
|
|
57
|
+
});
|
|
58
|
+
if (result) {
|
|
59
|
+
setCurentLabel($edit.current.innerText);
|
|
60
|
+
} else {
|
|
61
|
+
$edit.current.innerText = curentLabel;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
$edit.current.contentEditable = 'false';
|
|
65
|
+
(_$edit$current2 = $edit.current) == null ? void 0 : _$edit$current2.focus();
|
|
66
|
+
}
|
|
67
|
+
setEditable(false);
|
|
68
|
+
});
|
|
69
|
+
return function blur() {
|
|
70
|
+
return _ref.apply(this, arguments);
|
|
71
|
+
};
|
|
72
|
+
}();
|
|
59
73
|
var focus = () => {
|
|
60
74
|
if ($edit.current) {
|
|
61
75
|
var _$edit$current3;
|
|
@@ -72,11 +86,11 @@ export var ObjectKey = props => {
|
|
|
72
86
|
};
|
|
73
87
|
useEffect(() => {
|
|
74
88
|
if ($edit.current) {
|
|
75
|
-
$edit.current.addEventListener(
|
|
89
|
+
$edit.current.addEventListener('paste', e => {
|
|
76
90
|
e.preventDefault();
|
|
77
91
|
// @ts-ignore
|
|
78
|
-
var text = e.clipboardData.getData(
|
|
79
|
-
document.execCommand(
|
|
92
|
+
var text = e.clipboardData.getData('text/plain');
|
|
93
|
+
document.execCommand('insertHTML', false, text);
|
|
80
94
|
});
|
|
81
95
|
}
|
|
82
96
|
}, [$edit]);
|
package/esm/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;
|