@uiw/react-json-view 1.4.0 → 1.5.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 +150 -13
- package/cjs/comps/ellipsis.d.ts +5 -0
- package/cjs/comps/ellipsis.js +32 -0
- package/cjs/comps/meta.d.ts +8 -0
- package/cjs/comps/meta.js +38 -0
- package/cjs/copied.js +5 -4
- package/cjs/editor/icon/edit.d.ts +4 -0
- package/cjs/editor/icon/edit.js +30 -0
- package/cjs/editor/index.d.ts +16 -0
- package/cjs/editor/index.js +48 -0
- package/cjs/editor/objectKey.d.ts +11 -0
- package/cjs/editor/objectKey.js +138 -0
- package/cjs/editor/value.d.ts +14 -0
- package/cjs/editor/value.js +165 -0
- package/cjs/index.d.ts +2 -1
- package/cjs/node.d.ts +0 -10
- package/cjs/node.js +45 -90
- package/cjs/semicolon.d.ts +11 -2
- package/cjs/semicolon.js +44 -25
- package/cjs/theme/dark.d.ts +2 -0
- package/cjs/theme/dark.js +2 -0
- package/cjs/theme/light.d.ts +2 -0
- package/cjs/theme/light.js +2 -0
- package/cjs/tools.d.ts +10 -0
- package/cjs/tools.js +24 -0
- package/cjs/value.d.ts +19 -4
- package/cjs/value.js +67 -28
- package/editor.d.ts +16 -0
- package/esm/comps/ellipsis.d.ts +5 -0
- package/esm/comps/ellipsis.js +26 -0
- package/esm/comps/meta.d.ts +8 -0
- package/esm/comps/meta.js +31 -0
- package/esm/copied.js +5 -4
- package/esm/editor/icon/edit.d.ts +4 -0
- package/esm/editor/icon/edit.js +24 -0
- package/esm/editor/index.d.ts +16 -0
- package/esm/editor/index.js +37 -0
- package/esm/editor/objectKey.d.ts +11 -0
- package/esm/editor/objectKey.js +122 -0
- package/esm/editor/value.d.ts +14 -0
- package/esm/editor/value.js +150 -0
- package/esm/index.d.ts +2 -1
- package/esm/node.d.ts +0 -10
- package/esm/node.js +35 -80
- package/esm/semicolon.d.ts +11 -2
- package/esm/semicolon.js +44 -25
- package/esm/theme/dark.d.ts +2 -0
- package/esm/theme/dark.js +2 -0
- package/esm/theme/light.d.ts +2 -0
- package/esm/theme/light.js +2 -0
- package/esm/tools.d.ts +10 -0
- package/esm/tools.js +20 -0
- package/esm/value.d.ts +19 -4
- package/esm/value.js +67 -28
- package/package.json +7 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ReValue = ReValue;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _value = require("../value");
|
|
13
|
+
var _edit = require("./icon/edit");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
var _excluded = ["type", "value", "keyName", "visible", "quotes", "style", "content", "children", "displayDataTypes", "editableValue", "onEdit"];
|
|
16
|
+
var Quotes = function Quotes(_ref) {
|
|
17
|
+
var show = _ref.show,
|
|
18
|
+
style = _ref.style,
|
|
19
|
+
quotes = _ref.quotes;
|
|
20
|
+
if (!quotes || !show) return;
|
|
21
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
22
|
+
style: style,
|
|
23
|
+
children: quotes
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
function ReValue(props) {
|
|
27
|
+
var _typeMap$typeStr;
|
|
28
|
+
var type = props.type,
|
|
29
|
+
value = props.value,
|
|
30
|
+
keyName = props.keyName,
|
|
31
|
+
visible = props.visible,
|
|
32
|
+
quotes = props.quotes,
|
|
33
|
+
style = props.style,
|
|
34
|
+
content = props.content,
|
|
35
|
+
children = props.children,
|
|
36
|
+
displayDataTypes = props.displayDataTypes,
|
|
37
|
+
editableValue = props.editableValue,
|
|
38
|
+
onEdit = props.onEdit,
|
|
39
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
40
|
+
var _useState = (0, _react.useState)(false),
|
|
41
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
42
|
+
editable = _useState2[0],
|
|
43
|
+
setEditable = _useState2[1];
|
|
44
|
+
var $edit = (0, _react.useRef)(null);
|
|
45
|
+
var _useState3 = (0, _react.useState)(type),
|
|
46
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
47
|
+
curentType = _useState4[0],
|
|
48
|
+
setCurentType = _useState4[1];
|
|
49
|
+
var _useState5 = (0, _react.useState)(value),
|
|
50
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
51
|
+
curentChild = _useState6[0],
|
|
52
|
+
setCurentChild = _useState6[1];
|
|
53
|
+
(0, _react.useEffect)(function () {
|
|
54
|
+
return setCurentChild(value);
|
|
55
|
+
}, [value]);
|
|
56
|
+
var click = function click(evn) {
|
|
57
|
+
evn.stopPropagation();
|
|
58
|
+
if (!editableValue) return;
|
|
59
|
+
if ($edit.current) {
|
|
60
|
+
var _$edit$current;
|
|
61
|
+
setEditable(true);
|
|
62
|
+
$edit.current.contentEditable = 'true';
|
|
63
|
+
(_$edit$current = $edit.current) === null || _$edit$current === void 0 ? void 0 : _$edit$current.focus();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var keyDown = function keyDown(evn) {
|
|
67
|
+
if (!editableValue) return;
|
|
68
|
+
if (evn.key === 'Enter') {
|
|
69
|
+
evn.stopPropagation();
|
|
70
|
+
evn.preventDefault();
|
|
71
|
+
setEditable(false);
|
|
72
|
+
$edit.current.contentEditable = 'false';
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var blur = function blur() {
|
|
76
|
+
if (!editableValue) return;
|
|
77
|
+
setEditable(false);
|
|
78
|
+
if ($edit.current) {
|
|
79
|
+
$edit.current.contentEditable = 'false';
|
|
80
|
+
var text = $edit.current.innerText;
|
|
81
|
+
if (curentType === 'number' || curentType === 'float') {
|
|
82
|
+
text = Number(text);
|
|
83
|
+
setCurentType((0, _value.isFloat)(text) ? 'float' : 'number');
|
|
84
|
+
}
|
|
85
|
+
if (curentType === 'url' && typeof text === 'string') {
|
|
86
|
+
text = new URL(text);
|
|
87
|
+
}
|
|
88
|
+
if (Number.isNaN(text)) {
|
|
89
|
+
setCurentType('number');
|
|
90
|
+
}
|
|
91
|
+
if (typeof text === 'string' && /^(true|false)$/ig.test(text)) {
|
|
92
|
+
text = /^(true)$/ig.test(text) ? true : false;
|
|
93
|
+
setCurentType('boolean');
|
|
94
|
+
} else if (typeof text === 'string' && /^[\d]+n$/ig.test(text)) {
|
|
95
|
+
text = BigInt(text.replace(/n$/ig, ''));
|
|
96
|
+
setCurentType('bigint');
|
|
97
|
+
} else if (typeof text === 'string' && /^(null)$/ig.test(text)) {
|
|
98
|
+
text = null;
|
|
99
|
+
setCurentType('null');
|
|
100
|
+
} else if (typeof text === 'string' && /^(undefined)$/ig.test(text)) {
|
|
101
|
+
text = undefined;
|
|
102
|
+
setCurentType('undefined');
|
|
103
|
+
} else if (typeof text === 'string') {
|
|
104
|
+
try {
|
|
105
|
+
var dt = new Date(text);
|
|
106
|
+
if (dt.toString() !== 'Invalid Date') {
|
|
107
|
+
text = dt;
|
|
108
|
+
setCurentType('date');
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {}
|
|
111
|
+
}
|
|
112
|
+
setCurentChild(text);
|
|
113
|
+
onEdit && onEdit({
|
|
114
|
+
type: 'value',
|
|
115
|
+
value: text,
|
|
116
|
+
oldValue: curentChild
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var defaultStyle = {
|
|
121
|
+
minWidth: 34,
|
|
122
|
+
minHeight: 18,
|
|
123
|
+
paddingInline: 3,
|
|
124
|
+
display: 'inline-block'
|
|
125
|
+
};
|
|
126
|
+
var _getValueString = (0, _value.getValueString)(curentChild),
|
|
127
|
+
typeStr = _getValueString.type,
|
|
128
|
+
childStr = _getValueString.content;
|
|
129
|
+
var color = ((_typeMap$typeStr = _value.typeMap[typeStr]) === null || _typeMap$typeStr === void 0 ? void 0 : _typeMap$typeStr.color) || '';
|
|
130
|
+
var spanProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
131
|
+
onBlur: blur,
|
|
132
|
+
onKeyDown: keyDown,
|
|
133
|
+
spellCheck: false,
|
|
134
|
+
style: editable ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), defaultStyle), {}, {
|
|
135
|
+
color: color
|
|
136
|
+
}) : (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
|
|
137
|
+
color: color
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
var typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Type, {
|
|
141
|
+
type: typeStr
|
|
142
|
+
});
|
|
143
|
+
if (typeStr === 'null' || typeStr === 'undefined') {
|
|
144
|
+
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
145
|
+
}
|
|
146
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
147
|
+
children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
148
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
|
|
149
|
+
style: style,
|
|
150
|
+
quotes: quotes,
|
|
151
|
+
show: typeStr === 'string'
|
|
152
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spanProps), {}, {
|
|
153
|
+
ref: $edit,
|
|
154
|
+
"data-value": content,
|
|
155
|
+
children: typeof curentChild === 'string' ? curentChild : childStr
|
|
156
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
|
|
157
|
+
style: style,
|
|
158
|
+
quotes: quotes,
|
|
159
|
+
show: typeStr === 'string'
|
|
160
|
+
})]
|
|
161
|
+
}), visible && editableValue && /*#__PURE__*/(0, _jsxRuntime.jsx)(_edit.EditIcon, {
|
|
162
|
+
onClick: click
|
|
163
|
+
})]
|
|
164
|
+
});
|
|
165
|
+
}
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { MetaProps, EllipsisProps } from './node';
|
|
3
2
|
import { SemicolonProps } from './semicolon';
|
|
4
3
|
import { ValueViewProps } from './value';
|
|
5
4
|
import { CopiedProps } from './copied';
|
|
5
|
+
import { EllipsisProps } from './comps/ellipsis';
|
|
6
|
+
import { MetaProps } from './comps/meta';
|
|
6
7
|
export * from './node';
|
|
7
8
|
export * from './value';
|
|
8
9
|
export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
package/cjs/node.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
2
|
import { LabelProps } from './value';
|
|
3
3
|
import { JsonViewProps } from './';
|
|
4
|
-
export interface MetaProps extends LabelProps {
|
|
5
|
-
isArray?: boolean;
|
|
6
|
-
start?: boolean;
|
|
7
|
-
render?: (props: Pick<MetaProps, 'start' | 'isArray' | 'className' | 'children'>) => JSX.Element;
|
|
8
|
-
}
|
|
9
|
-
export declare function Meta(props: MetaProps): JSX.Element;
|
|
10
|
-
export interface EllipsisProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
11
|
-
render?: (props: EllipsisProps) => JSX.Element;
|
|
12
|
-
}
|
|
13
|
-
export declare const Ellipsis: FC<PropsWithChildren<EllipsisProps>>;
|
|
14
4
|
export declare const CountInfo: FC<PropsWithChildren<LabelProps>>;
|
|
15
5
|
export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
|
|
16
6
|
keyName?: string | number;
|
package/cjs/node.js
CHANGED
|
@@ -4,72 +4,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
8
|
-
exports.Meta = Meta;
|
|
7
|
+
exports.CountInfo = void 0;
|
|
9
8
|
exports.RooNode = RooNode;
|
|
9
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
10
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
14
13
|
var _react = require("react");
|
|
15
14
|
var _value = require("./value");
|
|
16
15
|
var _TriangleArrow = require("./arrow/TriangleArrow");
|
|
17
16
|
var _store = require("./store");
|
|
18
|
-
var _copied = require("./copied");
|
|
19
17
|
var _semicolon = require("./semicolon");
|
|
18
|
+
var _tools = require("./tools");
|
|
19
|
+
var _ellipsis = require("./comps/ellipsis");
|
|
20
|
+
var _meta = require("./comps/meta");
|
|
20
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
-
var _excluded = ["
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function Meta(props) {
|
|
25
|
-
var _props$isArray = props.isArray,
|
|
26
|
-
isArray = _props$isArray === void 0 ? false : _props$isArray,
|
|
27
|
-
_props$start = props.start,
|
|
28
|
-
start = _props$start === void 0 ? false : _props$start,
|
|
29
|
-
className = props.className,
|
|
30
|
-
render = props.render,
|
|
31
|
-
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
32
|
-
var mark = isArray ? '[]' : '{}';
|
|
33
|
-
var cls = "w-rjv-".concat(isArray ? 'brackets' : 'curlybraces', "-").concat(start ? 'start' : 'end', " ").concat(className || '');
|
|
34
|
-
var color = "var(--w-rjv-".concat(isArray ? 'brackets' : 'curlybraces', "-color, #236a7c)");
|
|
35
|
-
if (render) return render((0, _objectSpread2["default"])({
|
|
36
|
-
isArray: isArray,
|
|
37
|
-
className: cls,
|
|
38
|
-
style: {
|
|
39
|
-
color: color
|
|
40
|
-
},
|
|
41
|
-
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
42
|
-
}, reset));
|
|
43
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
44
|
-
color: color,
|
|
45
|
-
className: cls
|
|
46
|
-
}, reset), {}, {
|
|
47
|
-
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
var Ellipsis = function Ellipsis(_ref) {
|
|
51
|
-
var style = _ref.style,
|
|
52
|
-
render = _ref.render,
|
|
53
|
-
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded2);
|
|
54
|
-
var styl = (0, _objectSpread2["default"])({
|
|
55
|
-
cursor: 'pointer'
|
|
56
|
-
}, style);
|
|
57
|
-
var className = "w-rjv-ellipsis ".concat(props.className || '');
|
|
58
|
-
if (render) return render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
59
|
-
style: styl
|
|
60
|
-
}, props), {}, {
|
|
61
|
-
className: className
|
|
62
|
-
}));
|
|
63
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
64
|
-
className: className,
|
|
65
|
-
style: styl
|
|
66
|
-
}, props), {}, {
|
|
67
|
-
children: "..."
|
|
68
|
-
}));
|
|
69
|
-
};
|
|
70
|
-
exports.Ellipsis = Ellipsis;
|
|
71
|
-
var CountInfo = function CountInfo(_ref2) {
|
|
72
|
-
var children = _ref2.children;
|
|
22
|
+
var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand"];
|
|
23
|
+
var CountInfo = function CountInfo(_ref) {
|
|
24
|
+
var children = _ref.children;
|
|
73
25
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, {
|
|
74
26
|
style: {
|
|
75
27
|
paddingLeft: 4,
|
|
@@ -110,7 +62,7 @@ function RooNode(props) {
|
|
|
110
62
|
quotes = _props$quotes === void 0 ? '"' : _props$quotes,
|
|
111
63
|
onCopied = props.onCopied,
|
|
112
64
|
onExpand = props.onExpand,
|
|
113
|
-
reset = (0, _objectWithoutProperties2["default"])(props,
|
|
65
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
114
66
|
var isArray = Array.isArray(value);
|
|
115
67
|
var subkeyid = (0, _react.useId)();
|
|
116
68
|
var expands = (0, _store.useExpandsStatus)();
|
|
@@ -149,6 +101,7 @@ function RooNode(props) {
|
|
|
149
101
|
displayObjectSize: displayObjectSize,
|
|
150
102
|
enableClipboard: enableClipboard,
|
|
151
103
|
indentWidth: indentWidth,
|
|
104
|
+
quotes: quotes,
|
|
152
105
|
renderBraces: components.braces,
|
|
153
106
|
renderValue: components.value
|
|
154
107
|
};
|
|
@@ -164,12 +117,6 @@ function RooNode(props) {
|
|
|
164
117
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
165
118
|
showTools = _useState2[0],
|
|
166
119
|
setShowTools = _useState2[1];
|
|
167
|
-
var tools = enableClipboard ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
168
|
-
show: showTools,
|
|
169
|
-
text: value,
|
|
170
|
-
onCopied: onCopied,
|
|
171
|
-
render: components.copied
|
|
172
|
-
}) : undefined;
|
|
173
120
|
var eventProps = {};
|
|
174
121
|
if (enableClipboard) {
|
|
175
122
|
eventProps.onMouseEnter = function () {
|
|
@@ -188,17 +135,17 @@ function RooNode(props) {
|
|
|
188
135
|
return [Number(m[0]), m[1]];
|
|
189
136
|
}) : Object.entries(value);
|
|
190
137
|
if (objectSortKeys) {
|
|
191
|
-
entries = objectSortKeys === true ? entries.sort(function (
|
|
138
|
+
entries = objectSortKeys === true ? entries.sort(function (_ref2, _ref3) {
|
|
139
|
+
var _ref4 = (0, _slicedToArray2["default"])(_ref2, 1),
|
|
140
|
+
a = _ref4[0];
|
|
192
141
|
var _ref5 = (0, _slicedToArray2["default"])(_ref3, 1),
|
|
193
|
-
|
|
194
|
-
var _ref6 = (0, _slicedToArray2["default"])(_ref4, 1),
|
|
195
|
-
b = _ref6[0];
|
|
142
|
+
b = _ref5[0];
|
|
196
143
|
return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
|
|
197
|
-
}) : entries.sort(function (
|
|
144
|
+
}) : entries.sort(function (_ref6, _ref7) {
|
|
145
|
+
var _ref8 = (0, _slicedToArray2["default"])(_ref6, 1),
|
|
146
|
+
a = _ref8[0];
|
|
198
147
|
var _ref9 = (0, _slicedToArray2["default"])(_ref7, 1),
|
|
199
|
-
|
|
200
|
-
var _ref10 = (0, _slicedToArray2["default"])(_ref8, 1),
|
|
201
|
-
b = _ref10[0];
|
|
148
|
+
b = _ref9[0];
|
|
202
149
|
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
203
150
|
});
|
|
204
151
|
}
|
|
@@ -215,42 +162,50 @@ function RooNode(props) {
|
|
|
215
162
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
|
|
216
163
|
value: value,
|
|
217
164
|
quotes: quotes,
|
|
165
|
+
"data-keys": keyid,
|
|
218
166
|
render: components.objectKey,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
167
|
+
keyName: keyName,
|
|
168
|
+
parentName: keyName,
|
|
169
|
+
color: typeof keyName === 'number' ? _value.typeMap['number'].color : ''
|
|
222
170
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Colon, {})]
|
|
223
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
171
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
224
172
|
start: true,
|
|
225
173
|
isArray: isArray,
|
|
226
174
|
render: components.braces
|
|
227
|
-
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Ellipsis, {
|
|
175
|
+
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ellipsis.Ellipsis, {
|
|
228
176
|
render: components.ellipsis
|
|
229
|
-
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
177
|
+
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
230
178
|
isArray: isArray,
|
|
231
179
|
render: components.braces
|
|
232
180
|
}), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(CountInfo, {
|
|
233
181
|
children: [nameKeys.length, " items"]
|
|
234
|
-
}),
|
|
182
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_tools.Tools, {
|
|
183
|
+
value: value,
|
|
184
|
+
enableClipboard: enableClipboard,
|
|
185
|
+
onCopied: onCopied,
|
|
186
|
+
components: components,
|
|
187
|
+
showTools: showTools
|
|
188
|
+
})]
|
|
235
189
|
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
236
190
|
className: "w-rjv-content",
|
|
237
191
|
style: {
|
|
238
|
-
borderLeft: 'var(--w-rjv-border-left-width, 1px) solid var(--w-rjv-line-color, #ebebeb)',
|
|
192
|
+
borderLeft: 'var(--w-rjv-border-left-width, 1px) var(--w-rjv-line-style, solid) var(--w-rjv-line-color, #ebebeb)',
|
|
239
193
|
marginLeft: 6
|
|
240
194
|
},
|
|
241
|
-
children: entries.length > 0 && entries.map(function (
|
|
242
|
-
var
|
|
243
|
-
key =
|
|
244
|
-
itemVal =
|
|
195
|
+
children: entries.length > 0 && entries.map(function (_ref10, idx) {
|
|
196
|
+
var _ref11 = (0, _slicedToArray2["default"])(_ref10, 2),
|
|
197
|
+
key = _ref11[0],
|
|
198
|
+
itemVal = _ref11[1];
|
|
245
199
|
var item = itemVal;
|
|
246
200
|
var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
|
|
247
201
|
value: item,
|
|
202
|
+
"data-keys": keyid,
|
|
248
203
|
quotes: quotes,
|
|
204
|
+
parentName: keyName,
|
|
249
205
|
highlightUpdates: highlightUpdates,
|
|
250
206
|
render: components.objectKey,
|
|
251
207
|
color: typeof key === 'number' ? _value.typeMap['number'].color : '',
|
|
252
|
-
|
|
253
|
-
children: key
|
|
208
|
+
keyName: key
|
|
254
209
|
});
|
|
255
210
|
var isEmpty = Array.isArray(item) && item.length === 0 || (0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
|
|
256
211
|
if (Array.isArray(item) && !isEmpty) {
|
|
@@ -259,8 +214,8 @@ function RooNode(props) {
|
|
|
259
214
|
className: "w-rjv-wrap",
|
|
260
215
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
261
216
|
value: item,
|
|
262
|
-
|
|
263
|
-
|
|
217
|
+
keyName: label,
|
|
218
|
+
keyid: keyid + subkeyid + label
|
|
264
219
|
}, subNodeProps))
|
|
265
220
|
}, label + idx);
|
|
266
221
|
}
|
|
@@ -268,9 +223,9 @@ function RooNode(props) {
|
|
|
268
223
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
269
224
|
className: "w-rjv-wrap",
|
|
270
225
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
271
|
-
keyid: keyid + subkeyid + key,
|
|
272
226
|
value: item,
|
|
273
|
-
keyName: key
|
|
227
|
+
keyName: key,
|
|
228
|
+
keyid: keyid + subkeyid + key
|
|
274
229
|
}, subNodeProps))
|
|
275
230
|
}, key + '' + idx);
|
|
276
231
|
}
|
|
@@ -287,7 +242,7 @@ function RooNode(props) {
|
|
|
287
242
|
style: {
|
|
288
243
|
paddingLeft: 2
|
|
289
244
|
},
|
|
290
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
245
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
291
246
|
render: components.braces,
|
|
292
247
|
isArray: isArray,
|
|
293
248
|
style: {
|
package/cjs/semicolon.d.ts
CHANGED
|
@@ -2,11 +2,20 @@ import { FC, PropsWithChildren } from 'react';
|
|
|
2
2
|
import { LabelProps } from './value';
|
|
3
3
|
import { JsonViewProps } from './';
|
|
4
4
|
export declare function usePrevious<T>(value: T): T | undefined;
|
|
5
|
+
interface UseHighlight {
|
|
6
|
+
value: any;
|
|
7
|
+
highlightUpdates?: boolean;
|
|
8
|
+
highlightContainer: React.MutableRefObject<HTMLSpanElement | null>;
|
|
9
|
+
}
|
|
10
|
+
export declare function useHighlight({ value, highlightUpdates, highlightContainer }: UseHighlight): void;
|
|
5
11
|
export interface SemicolonProps extends LabelProps {
|
|
6
|
-
show?: boolean;
|
|
7
12
|
highlightUpdates?: boolean;
|
|
13
|
+
keyName?: string | number;
|
|
14
|
+
parentName?: string | number;
|
|
8
15
|
quotes?: JsonViewProps<object>['quotes'];
|
|
9
16
|
value?: object;
|
|
10
|
-
|
|
17
|
+
label?: string;
|
|
18
|
+
render?: (props: SemicolonProps) => React.ReactNode;
|
|
11
19
|
}
|
|
12
20
|
export declare const Semicolon: FC<PropsWithChildren<SemicolonProps>>;
|
|
21
|
+
export {};
|
package/cjs/semicolon.js
CHANGED
|
@@ -5,14 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.Semicolon = void 0;
|
|
8
|
+
exports.useHighlight = useHighlight;
|
|
8
9
|
exports.usePrevious = usePrevious;
|
|
9
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
11
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
13
|
var _react = require("react");
|
|
13
14
|
var _value = require("./value");
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
-
var _excluded = ["children", "render", "color", "value", "className", "
|
|
16
|
+
var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "parentName"];
|
|
16
17
|
function usePrevious(value) {
|
|
17
18
|
var ref = (0, _react.useRef)();
|
|
18
19
|
(0, _react.useEffect)(function () {
|
|
@@ -20,20 +21,11 @@ function usePrevious(value) {
|
|
|
20
21
|
});
|
|
21
22
|
return ref.current;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
render = _ref.render,
|
|
26
|
-
color = _ref.color,
|
|
27
|
-
value = _ref.value,
|
|
28
|
-
_ref$className = _ref.className,
|
|
29
|
-
className = _ref$className === void 0 ? 'w-rjv-object-key' : _ref$className,
|
|
30
|
-
show = _ref.show,
|
|
24
|
+
function useHighlight(_ref) {
|
|
25
|
+
var value = _ref.value,
|
|
31
26
|
highlightUpdates = _ref.highlightUpdates,
|
|
32
|
-
|
|
33
|
-
style = _ref.style,
|
|
34
|
-
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
27
|
+
highlightContainer = _ref.highlightContainer;
|
|
35
28
|
var prevValue = usePrevious(value);
|
|
36
|
-
var highlightContainer = (0, _react.useRef)(null);
|
|
37
29
|
var isHighlight = (0, _react.useMemo)(function () {
|
|
38
30
|
if (!highlightUpdates || prevValue === undefined) return false;
|
|
39
31
|
// highlight if value type changed
|
|
@@ -62,7 +54,7 @@ var Semicolon = function Semicolon(_ref) {
|
|
|
62
54
|
return false;
|
|
63
55
|
}, [highlightUpdates, value]);
|
|
64
56
|
(0, _react.useEffect)(function () {
|
|
65
|
-
if (highlightContainer.current && isHighlight && 'animate' in highlightContainer.current) {
|
|
57
|
+
if (highlightContainer && highlightContainer.current && isHighlight && 'animate' in highlightContainer.current) {
|
|
66
58
|
highlightContainer.current.animate([{
|
|
67
59
|
backgroundColor: 'var(--w-rjv-update-color, #ebcb8b)'
|
|
68
60
|
}, {
|
|
@@ -72,17 +64,44 @@ var Semicolon = function Semicolon(_ref) {
|
|
|
72
64
|
easing: 'ease-in'
|
|
73
65
|
});
|
|
74
66
|
}
|
|
75
|
-
}, [isHighlight, value]);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
}, [isHighlight, value, highlightContainer]);
|
|
68
|
+
}
|
|
69
|
+
var Semicolon = function Semicolon(_ref2) {
|
|
70
|
+
var children = _ref2.children,
|
|
71
|
+
render = _ref2.render,
|
|
72
|
+
color = _ref2.color,
|
|
73
|
+
value = _ref2.value,
|
|
74
|
+
_ref2$className = _ref2.className,
|
|
75
|
+
className = _ref2$className === void 0 ? 'w-rjv-object-key' : _ref2$className,
|
|
76
|
+
keyName = _ref2.keyName,
|
|
77
|
+
highlightUpdates = _ref2.highlightUpdates,
|
|
78
|
+
quotes = _ref2.quotes,
|
|
79
|
+
style = _ref2.style,
|
|
80
|
+
parentName = _ref2.parentName,
|
|
81
|
+
props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
|
|
82
|
+
var highlightContainer = (0, _react.useRef)(null);
|
|
83
|
+
var content = typeof keyName === 'string' ? "".concat(quotes).concat(keyName).concat(quotes) : keyName;
|
|
84
|
+
if (render) {
|
|
85
|
+
return render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
86
|
+
className: className
|
|
87
|
+
}, props), {}, {
|
|
88
|
+
value: value,
|
|
89
|
+
style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
|
|
90
|
+
color: color
|
|
91
|
+
}),
|
|
92
|
+
parentName: parentName,
|
|
93
|
+
keyName: keyName,
|
|
94
|
+
quotes: quotes,
|
|
95
|
+
label: keyName,
|
|
96
|
+
children: content
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
;
|
|
100
|
+
useHighlight({
|
|
80
101
|
value: value,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
children: content
|
|
85
|
-
}));
|
|
102
|
+
highlightUpdates: highlightUpdates,
|
|
103
|
+
highlightContainer: highlightContainer
|
|
104
|
+
});
|
|
86
105
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
87
106
|
className: className,
|
|
88
107
|
color: color
|
package/cjs/theme/dark.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const darkTheme: {
|
|
|
4
4
|
'--w-rjv-background-color': string;
|
|
5
5
|
'--w-rjv-line-color': string;
|
|
6
6
|
'--w-rjv-arrow-color': string;
|
|
7
|
+
'--w-rjv-edit-color': string;
|
|
7
8
|
'--w-rjv-info-color': string;
|
|
8
9
|
'--w-rjv-update-color': string;
|
|
9
10
|
'--w-rjv-copied-color': string;
|
|
@@ -16,6 +17,7 @@ export declare const darkTheme: {
|
|
|
16
17
|
'--w-rjv-type-bigint-color': string;
|
|
17
18
|
'--w-rjv-type-boolean-color': string;
|
|
18
19
|
'--w-rjv-type-date-color': string;
|
|
20
|
+
'--w-rjv-type-url-color': string;
|
|
19
21
|
'--w-rjv-type-null-color': string;
|
|
20
22
|
'--w-rjv-type-nan-color': string;
|
|
21
23
|
'--w-rjv-type-undefined-color': string;
|
package/cjs/theme/dark.js
CHANGED
|
@@ -10,6 +10,7 @@ var darkTheme = {
|
|
|
10
10
|
'--w-rjv-background-color': '#202020',
|
|
11
11
|
'--w-rjv-line-color': '#323232',
|
|
12
12
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
|
+
'--w-rjv-edit-color': 'var(--w-rjv-color)',
|
|
13
14
|
'--w-rjv-info-color': '#656565',
|
|
14
15
|
'--w-rjv-update-color': '#ebcb8b',
|
|
15
16
|
'--w-rjv-copied-color': '#0184a6',
|
|
@@ -22,6 +23,7 @@ var darkTheme = {
|
|
|
22
23
|
'--w-rjv-type-bigint-color': '#268bd2',
|
|
23
24
|
'--w-rjv-type-boolean-color': '#2aa198',
|
|
24
25
|
'--w-rjv-type-date-color': '#586e75',
|
|
26
|
+
'--w-rjv-type-url-color': '#649bd8',
|
|
25
27
|
'--w-rjv-type-null-color': '#d33682',
|
|
26
28
|
'--w-rjv-type-nan-color': '#859900',
|
|
27
29
|
'--w-rjv-type-undefined-color': '#586e75'
|
package/cjs/theme/light.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const lightTheme: {
|
|
|
4
4
|
'--w-rjv-background-color': string;
|
|
5
5
|
'--w-rjv-line-color': string;
|
|
6
6
|
'--w-rjv-arrow-color': string;
|
|
7
|
+
'--w-rjv-edit-color': string;
|
|
7
8
|
'--w-rjv-info-color': string;
|
|
8
9
|
'--w-rjv-update-color': string;
|
|
9
10
|
'--w-rjv-copied-color': string;
|
|
@@ -16,6 +17,7 @@ export declare const lightTheme: {
|
|
|
16
17
|
'--w-rjv-type-bigint-color': string;
|
|
17
18
|
'--w-rjv-type-boolean-color': string;
|
|
18
19
|
'--w-rjv-type-date-color': string;
|
|
20
|
+
'--w-rjv-type-url-color': string;
|
|
19
21
|
'--w-rjv-type-null-color': string;
|
|
20
22
|
'--w-rjv-type-nan-color': string;
|
|
21
23
|
'--w-rjv-type-undefined-color': string;
|
package/cjs/theme/light.js
CHANGED
|
@@ -10,6 +10,7 @@ var lightTheme = {
|
|
|
10
10
|
'--w-rjv-background-color': '#ffffff',
|
|
11
11
|
'--w-rjv-line-color': '#ebebeb',
|
|
12
12
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
|
+
'--w-rjv-edit-color': 'var(--w-rjv-color)',
|
|
13
14
|
'--w-rjv-info-color': '#0000004d',
|
|
14
15
|
'--w-rjv-update-color': '#ebcb8b',
|
|
15
16
|
'--w-rjv-copied-color': '#002b36',
|
|
@@ -22,6 +23,7 @@ var lightTheme = {
|
|
|
22
23
|
'--w-rjv-type-bigint-color': '#268bd2',
|
|
23
24
|
'--w-rjv-type-boolean-color': '#2aa198',
|
|
24
25
|
'--w-rjv-type-date-color': '#586e75',
|
|
26
|
+
'--w-rjv-type-url-color': '#0969da',
|
|
25
27
|
'--w-rjv-type-null-color': '#d33682',
|
|
26
28
|
'--w-rjv-type-nan-color': '#859900',
|
|
27
29
|
'--w-rjv-type-undefined-color': '#586e75'
|
package/cjs/tools.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JsonViewProps } from './';
|
|
2
|
+
interface ToolsProps<T extends object> {
|
|
3
|
+
enableClipboard?: boolean;
|
|
4
|
+
value?: T | {};
|
|
5
|
+
onCopied?: JsonViewProps<T>['onCopied'];
|
|
6
|
+
components?: JsonViewProps<T>['components'];
|
|
7
|
+
showTools?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function Tools<T extends object>(props: ToolsProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
package/cjs/tools.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Tools = Tools;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _copied = require("./copied");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
function Tools(props) {
|
|
11
|
+
var enableClipboard = props.enableClipboard,
|
|
12
|
+
value = props.value,
|
|
13
|
+
showTools = props.showTools,
|
|
14
|
+
components = props.components,
|
|
15
|
+
onCopied = props.onCopied;
|
|
16
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
|
|
17
|
+
children: enableClipboard && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
18
|
+
show: showTools,
|
|
19
|
+
text: value,
|
|
20
|
+
onCopied: onCopied,
|
|
21
|
+
render: components === null || components === void 0 ? void 0 : components.copied
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
}
|