@uiw/react-json-view 0.0.1 → 1.0.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 +110 -6
- package/cjs/copied.d.ts +6 -0
- package/cjs/copied.js +72 -0
- package/cjs/index.d.ts +7 -4
- package/cjs/node.d.ts +0 -1
- package/cjs/node.js +48 -53
- package/cjs/theme/dark.d.ts +3 -1
- package/cjs/theme/dark.js +3 -1
- package/cjs/theme/light.d.ts +3 -1
- package/cjs/theme/light.js +3 -1
- package/cjs/value.d.ts +8 -2
- package/cjs/value.js +61 -9
- package/dark.d.ts +19 -0
- package/esm/copied.d.ts +6 -0
- package/esm/copied.js +61 -0
- package/esm/index.d.ts +7 -4
- package/esm/node.d.ts +0 -1
- package/esm/node.js +35 -46
- package/esm/theme/dark.d.ts +3 -1
- package/esm/theme/dark.js +3 -1
- package/esm/theme/light.d.ts +3 -1
- package/esm/theme/light.js +3 -1
- package/esm/value.d.ts +8 -2
- package/esm/value.js +50 -9
- package/light.d.ts +19 -0
- package/package.json +6 -3
- package/triangle-arrow.d.ts +5 -0
- package/triangle-solid-arrow.d.ts +5 -0
- package/src/arrow/TriangleArrow.tsx +0 -17
- package/src/arrow/TriangleSolidArrow.tsx +0 -17
- package/src/index.tsx +0 -43
- package/src/node.tsx +0 -201
- package/src/store.tsx +0 -37
- package/src/theme/dark.ts +0 -21
- package/src/theme/light.ts +0 -21
- package/src/value.tsx +0 -172
package/README.md
CHANGED
|
@@ -3,13 +3,24 @@ react-json-view
|
|
|
3
3
|
|
|
4
4
|
[](https://github.com/uiwjs/react-json-view/actions/workflows/ci.yml)
|
|
5
5
|
[](https://www.npmjs.com/package/@uiw/react-json-view)
|
|
6
|
+
[](https://github.com/facebook/react/releases)
|
|
6
7
|
|
|
7
8
|
A React component for displaying and editing javascript arrays and JSON objects.
|
|
8
9
|
|
|
10
|
+
<!--rehype:ignore:start-->
|
|
11
|
+
<a href="https://uiwjs.github.io/react-json-view/" target="_blank">
|
|
12
|
+
<img width="360" alt="react-json-view" src="https://github.com/uiwjs/react-json-view/assets/1680273/b8b8300b-2a43-4173-878b-73e50cfac19c" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://uiwjs.github.io/react-json-view/" target="_blank">
|
|
15
|
+
<img width="360" alt="react-json-view" src="https://github.com/uiwjs/react-code-preview-layout/assets/1680273/da8e8499-6de3-4d4f-8316-8b2a3b616170" />
|
|
16
|
+
</a>
|
|
17
|
+
|
|
18
|
+
<!--rehype:ignore:end-->
|
|
19
|
+
|
|
9
20
|
## Features
|
|
10
21
|
|
|
11
22
|
📚 Use Typescript to write, better code hints.
|
|
12
|
-
🎨 Support theme customization
|
|
23
|
+
🎨 Support theme customization & [`online editing`](https://uiwjs.github.io/react-json-view/#online-editing-theme) theme
|
|
13
24
|
🌒 Support dark/light mode
|
|
14
25
|
|
|
15
26
|
## Quick Start
|
|
@@ -96,9 +107,11 @@ const customTheme = {
|
|
|
96
107
|
'--w-rjv-font-family': 'monospace',
|
|
97
108
|
'--w-rjv-color': '#9cdcfe',
|
|
98
109
|
'--w-rjv-background-color': '#1e1e1e',
|
|
99
|
-
'--w-rjv-
|
|
110
|
+
'--w-rjv-line-color': '#323232',
|
|
100
111
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
101
112
|
'--w-rjv-info-color': '#656565',
|
|
113
|
+
'--w-rjv-copied-color': '#9cdcfe',
|
|
114
|
+
'--w-rjv-copied-success-color': '#28a745',
|
|
102
115
|
|
|
103
116
|
'--w-rjv-curlybraces-color': '#d4d4d4',
|
|
104
117
|
'--w-rjv-brackets-color': '#d4d4d4',
|
|
@@ -121,6 +134,94 @@ export default function Demo() {
|
|
|
121
134
|
}
|
|
122
135
|
```
|
|
123
136
|
|
|
137
|
+
## Online Editing Theme
|
|
138
|
+
|
|
139
|
+
Online custom style example, please check in the [documentation website](https://uiwjs.github.io/react-json-view/)
|
|
140
|
+
|
|
141
|
+
```tsx mdx:preview:&title=Online Editing Theme
|
|
142
|
+
import React, { useState, useRef } from 'react';
|
|
143
|
+
import Colorful from '@uiw/react-color-colorful';
|
|
144
|
+
import JsonView from '@uiw/react-json-view';
|
|
145
|
+
|
|
146
|
+
const object = {
|
|
147
|
+
avatar: 'https://i.imgur.com/MK3eW3As.jpg',
|
|
148
|
+
string: 'Lorem ipsum dolor sit amet',
|
|
149
|
+
integer: 42,
|
|
150
|
+
float: 114.514,
|
|
151
|
+
bigint: 10086n,
|
|
152
|
+
null: null,
|
|
153
|
+
undefined,
|
|
154
|
+
timer: 0,
|
|
155
|
+
date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'),
|
|
156
|
+
array: [19, 100.86, 'test', NaN, Infinity],
|
|
157
|
+
nestedArray: [
|
|
158
|
+
[1, 2],
|
|
159
|
+
[3, 4],
|
|
160
|
+
],
|
|
161
|
+
object: {
|
|
162
|
+
'first-child': true,
|
|
163
|
+
'second-child': false,
|
|
164
|
+
'last-child': null,
|
|
165
|
+
},
|
|
166
|
+
string_number: '1234',
|
|
167
|
+
}
|
|
168
|
+
const customTheme = {
|
|
169
|
+
'--w-rjv-color': '#9cdcfe',
|
|
170
|
+
'--w-rjv-background-color': '#1e1e1e',
|
|
171
|
+
'--w-rjv-line-color': '#323232',
|
|
172
|
+
'--w-rjv-arrow-color': '#9cdcfe',
|
|
173
|
+
'--w-rjv-info-color': '#656565',
|
|
174
|
+
'--w-rjv-copied-color': '#0184a6',
|
|
175
|
+
'--w-rjv-copied-success-color': '#28a745',
|
|
176
|
+
|
|
177
|
+
'--w-rjv-curlybraces-color': '#d4d4d4',
|
|
178
|
+
'--w-rjv-brackets-color': '#d4d4d4',
|
|
179
|
+
|
|
180
|
+
'--w-rjv-type-string-color': '#ce9178',
|
|
181
|
+
'--w-rjv-type-int-color': '#268bd2',
|
|
182
|
+
'--w-rjv-type-float-color': '#859900',
|
|
183
|
+
'--w-rjv-type-bigint-color': '#268bd2',
|
|
184
|
+
'--w-rjv-type-boolean-color': '#559bd4',
|
|
185
|
+
'--w-rjv-type-date-color': '#586e75',
|
|
186
|
+
'--w-rjv-type-null-color': '#d33682',
|
|
187
|
+
'--w-rjv-type-nan-color': '#859900',
|
|
188
|
+
'--w-rjv-type-undefined-color': '#586e75',
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export default function Demo() {
|
|
192
|
+
const [cssvar, setCssvar] = useState('--w-rjv-background-color');
|
|
193
|
+
const [hex, setHex] = useState("#1e1e1e");
|
|
194
|
+
const [theme, setTheme] = useState(customTheme);
|
|
195
|
+
const onChange = ({ hexa }) => {
|
|
196
|
+
setHex(hexa);
|
|
197
|
+
setTheme({ ...theme, [cssvar]: hexa });
|
|
198
|
+
};
|
|
199
|
+
return (
|
|
200
|
+
<React.Fragment>
|
|
201
|
+
<div style={{ display: 'flex', gap: '1rem' }}>
|
|
202
|
+
<JsonView value={object} keyName="root" style={{ flex: 1, ...theme }} />
|
|
203
|
+
<div>
|
|
204
|
+
<Colorful color={hex} onChange={onChange} />
|
|
205
|
+
<div style={{ display: 'flex', gap: '0.4rem', flexWrap: 'wrap' }}>
|
|
206
|
+
{Object.keys(customTheme).map((varname, idx) => {
|
|
207
|
+
const click = () => {
|
|
208
|
+
setCssvar(varname);
|
|
209
|
+
setHex(customTheme[varname]);
|
|
210
|
+
};
|
|
211
|
+
const active = cssvar === varname ? '#a8a8a8' : '';
|
|
212
|
+
return <button key={idx} style={{ background: active }} onClick={click}>{varname}</button>
|
|
213
|
+
})}
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
</div>
|
|
217
|
+
Copy the theme configuration below into your project.
|
|
218
|
+
<pre>
|
|
219
|
+
{JSON.stringify(theme, null, 2)}
|
|
220
|
+
</pre>
|
|
221
|
+
</React.Fragment>
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
```
|
|
124
225
|
## Render
|
|
125
226
|
|
|
126
227
|
```tsx mdx:preview
|
|
@@ -281,14 +382,17 @@ import { MetaProps, SemicolonProps, EllipsisProps, ValueViewProps } from '@uiw/r
|
|
|
281
382
|
export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
282
383
|
/** This property contains your input JSON */
|
|
283
384
|
value?: T;
|
|
284
|
-
/** Set the indent-width for nested objects @default
|
|
385
|
+
/** Set the indent-width for nested objects @default 15 */
|
|
285
386
|
indentWidth?: number;
|
|
286
|
-
/** When set to `true`, data type labels prefix values @default
|
|
387
|
+
/** When set to `true`, data type labels prefix values @default true */
|
|
287
388
|
displayDataTypes?: boolean;
|
|
288
|
-
/** When set to `true`, `objects` and `arrays` are labeled with size @default
|
|
389
|
+
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
|
|
289
390
|
displayObjectSize?: boolean;
|
|
290
|
-
/** Define the root node name. @default
|
|
391
|
+
/** Define the root node name. @default undefined */
|
|
291
392
|
keyName?: string | number;
|
|
393
|
+
/** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
|
|
394
|
+
enableClipboard?: boolean;
|
|
395
|
+
/** Redefine interface elements to re-render. */
|
|
292
396
|
components?: {
|
|
293
397
|
braces?: MetaProps['render'];
|
|
294
398
|
ellipsis?: EllipsisProps['render'];
|
package/cjs/copied.d.ts
ADDED
package/cjs/copied.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Copied = Copied;
|
|
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 _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
var _excluded = ["children", "style", "text", "show"];
|
|
14
|
+
function Copied(props) {
|
|
15
|
+
var children = props.children,
|
|
16
|
+
style = props.style,
|
|
17
|
+
_props$text = props.text,
|
|
18
|
+
text = _props$text === void 0 ? '' : _props$text,
|
|
19
|
+
show = props.show,
|
|
20
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
21
|
+
if (!show) return null;
|
|
22
|
+
var _useState = (0, _react.useState)(false),
|
|
23
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
24
|
+
copied = _useState2[0],
|
|
25
|
+
setCopied = _useState2[1];
|
|
26
|
+
var click = function click(event) {
|
|
27
|
+
event.stopPropagation();
|
|
28
|
+
var copyText = JSON.stringify(text, function (key, value) {
|
|
29
|
+
if (typeof value === 'bigint') {
|
|
30
|
+
return value.toString();
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}, 2);
|
|
34
|
+
if (text === Infinity) copyText = Infinity;
|
|
35
|
+
navigator.clipboard.writeText(copyText).then(function () {
|
|
36
|
+
setCopied(true);
|
|
37
|
+
var timer = setTimeout(function () {
|
|
38
|
+
setCopied(false);
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
}, 3000);
|
|
41
|
+
})["catch"](function (error) {});
|
|
42
|
+
};
|
|
43
|
+
var defalutStyle = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
|
|
44
|
+
cursor: 'pointer',
|
|
45
|
+
marginLeft: 5
|
|
46
|
+
});
|
|
47
|
+
var svgProps = (0, _objectSpread2["default"])({
|
|
48
|
+
height: "1em",
|
|
49
|
+
width: "1em",
|
|
50
|
+
fill: "var(--w-rjv-copied-color, currentColor)",
|
|
51
|
+
onClick: click,
|
|
52
|
+
style: defalutStyle,
|
|
53
|
+
className: 'w-rjv-copied'
|
|
54
|
+
}, reset);
|
|
55
|
+
if (copied) {
|
|
56
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
57
|
+
viewBox: "0 0 38 38"
|
|
58
|
+
}, svgProps), {}, {
|
|
59
|
+
fill: "var(--w-rjv-copied-success-color, #28a745)",
|
|
60
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
|
61
|
+
d: "M27.5,35 L2.5,35 L2.5,12.5 L27.5,12.5 L27.5,15.2249049 C29.1403264,13.8627542 29.9736597,13.1778155 30,13.1700887 C30,11.9705278 30,10.0804982 30,7.5 C30,6.1 28.9,5 27.5,5 L20,5 C20,2.2 17.8,0 15,0 C12.2,0 10,2.2 10,5 L2.5,5 C1.1,5 0,6.1 0,7.5 L0,35 C0,36.4 1.1,37.5 2.5,37.5 L27.5,37.5 C28.9,37.5 30,36.4 30,35 L30,30 L27.5,30 L27.5,35 Z M7.5,7.5 L10,7.5 C10,7.5 12.5,6.4 12.5,5 C12.5,3.6 13.6,2.5 15,2.5 C16.4,2.5 17.5,3.6 17.5,5 C17.5,6.4 18.8,7.5 20,7.5 L22.5,7.5 C22.5,7.5 25,8.6 25,10 L5,10 C5,8.5 6.1,7.5 7.5,7.5 Z M5,27.5 L10,27.5 L10,25 L5,25 L5,27.5 Z M31.5589286,15 L35.1589286,18.6 L21.0160714,33 L12.5303571,24.2571429 L16.1303571,20.6571429 L21.0160714,25.5428571 L31.5589286,15 Z M12.5,30 L12.5,32.5 L5,32.5 L5,30 L12.5,30 Z M17.5,15 L5,15 L5,17.5 L17.5,17.5 L17.5,15 Z M10,20 L5,20 L5,22.5 L10,22.5 L10,20 Z"
|
|
62
|
+
})
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
66
|
+
viewBox: "0 0 38 38"
|
|
67
|
+
}, svgProps), {}, {
|
|
68
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
|
|
69
|
+
d: "M27.5,35 L2.5,35 L2.5,12.5 L27.5,12.5 L27.5,20 L30,20 L30,7.5 C30,6.1 28.9,5 27.5,5 L20,5 C20,2.2 17.8,0 15,0 C12.2,0 10,2.2 10,5 L2.5,5 C1.1,5 0,6.1 0,7.5 L0,35 C0,36.4 1.1,37.5 2.5,37.5 L27.5,37.5 C28.9,37.5 30,36.4 30,35 L30,30 L27.5,30 L27.5,35 Z M7.5,7.5 L10,7.5 C10,7.5 12.5,6.4 12.5,5 C12.5,3.6 13.6,2.5 15,2.5 C16.4,2.5 17.5,3.6 17.5,5 C17.5,6.4 18.8,7.5 20,7.5 L22.5,7.5 C22.5,7.5 25,8.6 25,10 L5,10 C5,8.5 6.1,7.5 7.5,7.5 Z M5,27.5 L10,27.5 L10,25 L5,25 L5,27.5 Z M22.5,22.5 L22.5,17.5 L12.5,25 L22.5,32.5 L22.5,27.5 L35,27.5 L35,22.5 L22.5,22.5 Z M5,32.5 L12.5,32.5 L12.5,30 L5,30 L5,32.5 Z M17.5,15 L5,15 L5,17.5 L17.5,17.5 L17.5,15 Z M10,20 L5,20 L5,22.5 L10,22.5 L10,20 Z"
|
|
70
|
+
})
|
|
71
|
+
}));
|
|
72
|
+
}
|
package/cjs/index.d.ts
CHANGED
|
@@ -6,14 +6,17 @@ export * from './value';
|
|
|
6
6
|
export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
7
7
|
/** This property contains your input JSON */
|
|
8
8
|
value?: T;
|
|
9
|
-
/** Set the indent-width for nested objects @default
|
|
9
|
+
/** Set the indent-width for nested objects @default 15 */
|
|
10
10
|
indentWidth?: number;
|
|
11
|
-
/** When set to `true`, data type labels prefix values @default
|
|
11
|
+
/** When set to `true`, data type labels prefix values @default true */
|
|
12
12
|
displayDataTypes?: boolean;
|
|
13
|
-
/** When set to `true`, `objects` and `arrays` are labeled with size @default
|
|
13
|
+
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
|
|
14
14
|
displayObjectSize?: boolean;
|
|
15
|
-
/** Define the root node name. @default
|
|
15
|
+
/** Define the root node name. @default undefined */
|
|
16
16
|
keyName?: string | number;
|
|
17
|
+
/** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
|
|
18
|
+
enableClipboard?: boolean;
|
|
19
|
+
/** Redefine interface elements to re-render. */
|
|
17
20
|
components?: {
|
|
18
21
|
braces?: MetaProps['render'];
|
|
19
22
|
ellipsis?: EllipsisProps['render'];
|
package/cjs/node.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export interface MetaProps extends LabelProps {
|
|
|
7
7
|
render?: (props: Pick<MetaProps, 'start' | 'isArray' | 'className' | 'children'>) => JSX.Element;
|
|
8
8
|
}
|
|
9
9
|
export declare function Meta(props: MetaProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export declare const Line: FC<PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>>;
|
|
11
10
|
export interface EllipsisProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
12
11
|
render?: (props: EllipsisProps) => JSX.Element;
|
|
13
12
|
}
|
package/cjs/node.js
CHANGED
|
@@ -4,22 +4,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.Ellipsis = exports.CountInfo = void 0;
|
|
8
8
|
exports.Meta = Meta;
|
|
9
9
|
exports.RooNode = RooNode;
|
|
10
10
|
exports.Semicolon = void 0;
|
|
11
11
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
13
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
14
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
14
15
|
var _react = require("react");
|
|
15
16
|
var _value = require("./value");
|
|
16
17
|
var _TriangleArrow = require("./arrow/TriangleArrow");
|
|
17
18
|
var _store = require("./store");
|
|
19
|
+
var _copied = require("./copied");
|
|
18
20
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
21
|
var _excluded = ["isArray", "start", "className", "render"],
|
|
20
22
|
_excluded2 = ["style", "render"],
|
|
21
23
|
_excluded3 = ["children", "render", "color", "value", "className", "show"],
|
|
22
|
-
_excluded4 = ["value", "keyName", "displayDataTypes", "components", "displayObjectSize", "indentWidth", "keyid"];
|
|
24
|
+
_excluded4 = ["value", "keyName", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "indentWidth", "keyid"];
|
|
23
25
|
function Meta(props) {
|
|
24
26
|
var _props$isArray = props.isArray,
|
|
25
27
|
isArray = _props$isArray === void 0 ? false : _props$isArray,
|
|
@@ -46,10 +48,6 @@ function Meta(props) {
|
|
|
46
48
|
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
47
49
|
}));
|
|
48
50
|
}
|
|
49
|
-
var Line = function Line(props) {
|
|
50
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
51
|
-
};
|
|
52
|
-
exports.Line = Line;
|
|
53
51
|
var Ellipsis = function Ellipsis(_ref) {
|
|
54
52
|
var style = _ref.style,
|
|
55
53
|
render = _ref.render,
|
|
@@ -122,6 +120,8 @@ function RooNode(props) {
|
|
|
122
120
|
components = _props$components === void 0 ? {} : _props$components,
|
|
123
121
|
_props$displayObjectS = props.displayObjectSize,
|
|
124
122
|
displayObjectSize = _props$displayObjectS === void 0 ? true : _props$displayObjectS,
|
|
123
|
+
_props$enableClipboar = props.enableClipboard,
|
|
124
|
+
enableClipboard = _props$enableClipboar === void 0 ? true : _props$enableClipboar,
|
|
125
125
|
_props$indentWidth = props.indentWidth,
|
|
126
126
|
indentWidth = _props$indentWidth === void 0 ? 15 : _props$indentWidth,
|
|
127
127
|
_props$keyid = props.keyid,
|
|
@@ -152,6 +152,9 @@ function RooNode(props) {
|
|
|
152
152
|
};
|
|
153
153
|
var valueViewProps = {
|
|
154
154
|
displayDataTypes: displayDataTypes,
|
|
155
|
+
displayObjectSize: displayObjectSize,
|
|
156
|
+
enableClipboard: enableClipboard,
|
|
157
|
+
indentWidth: indentWidth,
|
|
155
158
|
renderValue: components.value
|
|
156
159
|
};
|
|
157
160
|
var arrowView = components.arrow ? /*#__PURE__*/(0, _react.cloneElement)(components.arrow, {
|
|
@@ -160,8 +163,24 @@ function RooNode(props) {
|
|
|
160
163
|
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_TriangleArrow.TriangleArrow, {
|
|
161
164
|
style: arrowStyle
|
|
162
165
|
});
|
|
166
|
+
var _useState = (0, _react.useState)(false),
|
|
167
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
168
|
+
showTools = _useState2[0],
|
|
169
|
+
setShowTools = _useState2[1];
|
|
170
|
+
var tools = enableClipboard ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
171
|
+
show: showTools,
|
|
172
|
+
text: value
|
|
173
|
+
}) : undefined;
|
|
174
|
+
var mouseEnter = function mouseEnter() {
|
|
175
|
+
return setShowTools(true);
|
|
176
|
+
};
|
|
177
|
+
var mouseLeave = function mouseLeave() {
|
|
178
|
+
return setShowTools(false);
|
|
179
|
+
};
|
|
163
180
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
164
|
-
|
|
181
|
+
onMouseEnter: mouseEnter,
|
|
182
|
+
onMouseLeave: mouseLeave,
|
|
183
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_value.Line, {
|
|
165
184
|
style: {
|
|
166
185
|
display: 'inline-flex',
|
|
167
186
|
alignItems: 'center'
|
|
@@ -186,17 +205,25 @@ function RooNode(props) {
|
|
|
186
205
|
render: components.braces
|
|
187
206
|
}), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(CountInfo, {
|
|
188
207
|
children: [nameKeys.length, " items"]
|
|
189
|
-
})]
|
|
190
|
-
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
208
|
+
}), tools]
|
|
209
|
+
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
191
210
|
style: {
|
|
192
|
-
borderLeft: 'var(--w-rjv-
|
|
211
|
+
borderLeft: '1px solid var(--w-rjv-line-color, #ebebeb)',
|
|
193
212
|
marginLeft: 6
|
|
194
213
|
},
|
|
195
214
|
children: nameKeys.length > 0 && nameKeys.map(function (key, idx) {
|
|
196
215
|
var item = value[key];
|
|
197
|
-
|
|
216
|
+
var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(Semicolon, {
|
|
217
|
+
value: item,
|
|
218
|
+
render: components.objectKey,
|
|
219
|
+
color: typeof key === 'number' ? _value.typeMap['number'].color : '',
|
|
220
|
+
show: typeof key === 'string',
|
|
221
|
+
children: key
|
|
222
|
+
});
|
|
223
|
+
var isEmpty = Array.isArray(item) && item.length === 0 || (0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
|
|
224
|
+
if (Array.isArray(item) && !isEmpty) {
|
|
198
225
|
var label = isArray ? idx : key;
|
|
199
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
226
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
200
227
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
201
228
|
value: item,
|
|
202
229
|
keyid: keyid + subkeyid + label,
|
|
@@ -204,36 +231,8 @@ function RooNode(props) {
|
|
|
204
231
|
}, subNodeProps))
|
|
205
232
|
}, label + idx);
|
|
206
233
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
render: components.objectKey,
|
|
210
|
-
color: typeof key === 'number' ? _value.typeMap['number'].color : '',
|
|
211
|
-
show: typeof key === 'string',
|
|
212
|
-
children: key
|
|
213
|
-
});
|
|
214
|
-
if ((0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date)) {
|
|
215
|
-
if (Object.keys(item).length === 0) {
|
|
216
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
|
|
217
|
-
style: {
|
|
218
|
-
paddingLeft: indentWidth
|
|
219
|
-
},
|
|
220
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, valueViewProps), {}, {
|
|
221
|
-
renderKey: renderKey,
|
|
222
|
-
keyName: key,
|
|
223
|
-
value: item
|
|
224
|
-
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
225
|
-
render: components.braces,
|
|
226
|
-
start: true,
|
|
227
|
-
isArray: isArray
|
|
228
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
|
|
229
|
-
render: components.braces,
|
|
230
|
-
isArray: isArray
|
|
231
|
-
}), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(CountInfo, {
|
|
232
|
-
children: [Object.keys(item).length, " items"]
|
|
233
|
-
})]
|
|
234
|
-
}, key + idx);
|
|
235
|
-
}
|
|
236
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
234
|
+
if ((0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && !isEmpty) {
|
|
235
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
237
236
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
|
|
238
237
|
keyid: keyid + subkeyid + key,
|
|
239
238
|
value: item,
|
|
@@ -244,18 +243,14 @@ function RooNode(props) {
|
|
|
244
243
|
if (typeof item === 'function') {
|
|
245
244
|
return;
|
|
246
245
|
}
|
|
247
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
keyName: key,
|
|
254
|
-
value: item
|
|
255
|
-
}))
|
|
256
|
-
}, idx);
|
|
246
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, valueViewProps), {}, {
|
|
247
|
+
renderBraces: components.braces,
|
|
248
|
+
renderKey: renderKey,
|
|
249
|
+
keyName: key,
|
|
250
|
+
value: item
|
|
251
|
+
}), idx);
|
|
257
252
|
})
|
|
258
|
-
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
253
|
+
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
259
254
|
style: {
|
|
260
255
|
paddingLeft: 2
|
|
261
256
|
},
|
package/cjs/theme/dark.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ export declare const darkTheme: {
|
|
|
2
2
|
'--w-rjv-font-family': string;
|
|
3
3
|
'--w-rjv-color': string;
|
|
4
4
|
'--w-rjv-background-color': string;
|
|
5
|
-
'--w-rjv-
|
|
5
|
+
'--w-rjv-line-color': string;
|
|
6
6
|
'--w-rjv-arrow-color': string;
|
|
7
7
|
'--w-rjv-info-color': string;
|
|
8
|
+
'--w-rjv-copied-color': string;
|
|
9
|
+
'--w-rjv-copied-success-color': string;
|
|
8
10
|
'--w-rjv-curlybraces-color': string;
|
|
9
11
|
'--w-rjv-brackets-color': string;
|
|
10
12
|
'--w-rjv-type-string-color': string;
|
package/cjs/theme/dark.js
CHANGED
|
@@ -8,9 +8,11 @@ var darkTheme = {
|
|
|
8
8
|
'--w-rjv-font-family': 'monospace',
|
|
9
9
|
'--w-rjv-color': '#0184a6',
|
|
10
10
|
'--w-rjv-background-color': '#202020',
|
|
11
|
-
'--w-rjv-
|
|
11
|
+
'--w-rjv-line-color': '#323232',
|
|
12
12
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
13
|
'--w-rjv-info-color': '#656565',
|
|
14
|
+
'--w-rjv-copied-color': '#0184a6',
|
|
15
|
+
'--w-rjv-copied-success-color': '#28a745',
|
|
14
16
|
'--w-rjv-curlybraces-color': '#1896b6',
|
|
15
17
|
'--w-rjv-brackets-color': '#1896b6',
|
|
16
18
|
'--w-rjv-type-string-color': '#cb4b16',
|
package/cjs/theme/light.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ export declare const lightTheme: {
|
|
|
2
2
|
'--w-rjv-font-family': string;
|
|
3
3
|
'--w-rjv-color': string;
|
|
4
4
|
'--w-rjv-background-color': string;
|
|
5
|
-
'--w-rjv-
|
|
5
|
+
'--w-rjv-line-color': string;
|
|
6
6
|
'--w-rjv-arrow-color': string;
|
|
7
7
|
'--w-rjv-info-color': string;
|
|
8
|
+
'--w-rjv-copied-color': string;
|
|
9
|
+
'--w-rjv-copied-success-color': string;
|
|
8
10
|
'--w-rjv-curlybraces-color': string;
|
|
9
11
|
'--w-rjv-brackets-color': string;
|
|
10
12
|
'--w-rjv-type-string-color': string;
|
package/cjs/theme/light.js
CHANGED
|
@@ -8,9 +8,11 @@ var lightTheme = {
|
|
|
8
8
|
'--w-rjv-font-family': 'monospace',
|
|
9
9
|
'--w-rjv-color': '#002b36',
|
|
10
10
|
'--w-rjv-background-color': '#ffffff',
|
|
11
|
-
'--w-rjv-
|
|
11
|
+
'--w-rjv-line-color': '#ebebeb',
|
|
12
12
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
13
|
'--w-rjv-info-color': '#0000004d',
|
|
14
|
+
'--w-rjv-copied-color': '#002b36',
|
|
15
|
+
'--w-rjv-copied-success-color': '#28a745',
|
|
14
16
|
'--w-rjv-curlybraces-color': '#236a7c',
|
|
15
17
|
'--w-rjv-brackets-color': '#236a7c',
|
|
16
18
|
'--w-rjv-type-string-color': '#cb4b16',
|
package/cjs/value.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { MetaProps } from './node';
|
|
3
|
+
export declare const Line: FC<PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>>;
|
|
2
4
|
export declare const typeMap: {
|
|
3
5
|
string: {
|
|
4
6
|
color: string;
|
|
@@ -40,14 +42,18 @@ export declare const typeMap: {
|
|
|
40
42
|
export declare const Colon: FC<PropsWithChildren<React.HTMLAttributes<HTMLSpanElement>>>;
|
|
41
43
|
export interface ValueViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
42
44
|
keyName?: string;
|
|
43
|
-
value
|
|
45
|
+
value?: T;
|
|
44
46
|
displayDataTypes: boolean;
|
|
47
|
+
displayObjectSize: boolean;
|
|
48
|
+
enableClipboard: boolean;
|
|
49
|
+
indentWidth: number;
|
|
45
50
|
renderKey?: JSX.Element;
|
|
51
|
+
renderBraces?: MetaProps['render'];
|
|
46
52
|
renderValue?: (props: React.HTMLAttributes<HTMLSpanElement> & {
|
|
47
53
|
type: TypeProps['type'];
|
|
48
54
|
}) => JSX.Element;
|
|
49
55
|
}
|
|
50
|
-
export declare function ValueView<T>(props: ValueViewProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
56
|
+
export declare function ValueView<T = object>(props: ValueViewProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
51
57
|
export interface LabelProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
52
58
|
color?: string;
|
|
53
59
|
fontSize?: number;
|
package/cjs/value.js
CHANGED
|
@@ -4,17 +4,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.Type = exports.Label = exports.Colon = void 0;
|
|
7
|
+
exports.Type = exports.Line = exports.Label = exports.Colon = void 0;
|
|
8
8
|
exports.ValueView = ValueView;
|
|
9
9
|
exports.typeMap = void 0;
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
11
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
14
|
var _react = require("react");
|
|
15
|
+
var _node = require("./node");
|
|
16
|
+
var _copied = require("./copied");
|
|
14
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
18
|
var _excluded = ["children", "style"],
|
|
16
|
-
_excluded2 = ["value", "keyName", "renderKey", "renderValue", "displayDataTypes"],
|
|
19
|
+
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
17
20
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
21
|
+
var Line = function Line(props) {
|
|
22
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
23
|
+
};
|
|
24
|
+
exports.Line = Line;
|
|
18
25
|
var isFloat = function isFloat(n) {
|
|
19
26
|
return Number(n) === n && n % 1 !== 0 || isNaN(n);
|
|
20
27
|
};
|
|
@@ -76,8 +83,12 @@ function ValueView(props) {
|
|
|
76
83
|
var _typeMap$type;
|
|
77
84
|
var value = props.value,
|
|
78
85
|
keyName = props.keyName,
|
|
86
|
+
indentWidth = props.indentWidth,
|
|
79
87
|
renderKey = props.renderKey,
|
|
80
88
|
renderValue = props.renderValue,
|
|
89
|
+
renderBraces = props.renderBraces,
|
|
90
|
+
enableClipboard = props.enableClipboard,
|
|
91
|
+
displayObjectSize = props.displayObjectSize,
|
|
81
92
|
displayDataTypes = props.displayDataTypes,
|
|
82
93
|
reset = (0, _objectWithoutProperties2["default"])(props, _excluded2);
|
|
83
94
|
var type = (0, _typeof2["default"])(value);
|
|
@@ -123,6 +134,20 @@ function ValueView(props) {
|
|
|
123
134
|
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
124
135
|
}
|
|
125
136
|
color = ((_typeMap$type = typeMap[type]) === null || _typeMap$type === void 0 ? void 0 : _typeMap$type.color) || '';
|
|
137
|
+
var _useState = (0, _react.useState)(false),
|
|
138
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
139
|
+
showTools = _useState2[0],
|
|
140
|
+
setShowTools = _useState2[1];
|
|
141
|
+
var tools = enableClipboard ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
142
|
+
show: showTools,
|
|
143
|
+
text: value
|
|
144
|
+
}) : undefined;
|
|
145
|
+
var mouseEnter = function mouseEnter() {
|
|
146
|
+
return setShowTools(true);
|
|
147
|
+
};
|
|
148
|
+
var mouseLeave = function mouseLeave() {
|
|
149
|
+
return setShowTools(false);
|
|
150
|
+
};
|
|
126
151
|
if (content && typeof content === 'string') {
|
|
127
152
|
var valueView = renderValue ? renderValue({
|
|
128
153
|
className: 'w-rjv-value',
|
|
@@ -137,13 +162,40 @@ function ValueView(props) {
|
|
|
137
162
|
className: "w-rjv-value",
|
|
138
163
|
children: content
|
|
139
164
|
});
|
|
140
|
-
return /*#__PURE__*/(0, _jsxRuntime.
|
|
141
|
-
|
|
142
|
-
|
|
165
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
166
|
+
style: {
|
|
167
|
+
paddingLeft: indentWidth
|
|
168
|
+
},
|
|
169
|
+
onMouseEnter: mouseEnter,
|
|
170
|
+
onMouseLeave: mouseLeave,
|
|
171
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
172
|
+
children: [renderKey, /*#__PURE__*/(0, _jsxRuntime.jsx)(Colon, {}), typeView, valueView, tools]
|
|
173
|
+
}))
|
|
174
|
+
});
|
|
143
175
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
176
|
+
var length = Array.isArray(value) ? value.length : Object.keys(value).length;
|
|
177
|
+
var empty = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
178
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_node.Meta, {
|
|
179
|
+
render: renderBraces,
|
|
180
|
+
start: true,
|
|
181
|
+
isArray: Array.isArray(value)
|
|
182
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_node.Meta, {
|
|
183
|
+
render: renderBraces,
|
|
184
|
+
isArray: Array.isArray(value)
|
|
185
|
+
}), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_node.CountInfo, {
|
|
186
|
+
children: [length, " items"]
|
|
187
|
+
})]
|
|
188
|
+
});
|
|
189
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, {
|
|
190
|
+
style: {
|
|
191
|
+
paddingLeft: indentWidth
|
|
192
|
+
},
|
|
193
|
+
onMouseEnter: mouseEnter,
|
|
194
|
+
onMouseLeave: mouseLeave,
|
|
195
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
196
|
+
children: [renderKey, /*#__PURE__*/(0, _jsxRuntime.jsx)(Colon, {}), typeView, empty, tools]
|
|
197
|
+
}))
|
|
198
|
+
});
|
|
147
199
|
}
|
|
148
200
|
var Label = function Label(_ref2) {
|
|
149
201
|
var children = _ref2.children,
|
package/dark.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module '@uiw/react-json-view/dark' {
|
|
2
|
+
export const darkTheme: {
|
|
3
|
+
'--w-rjv-font-family': string;
|
|
4
|
+
'--w-rjv-color': string;
|
|
5
|
+
'--w-rjv-background-color': string;
|
|
6
|
+
'--w-rjv-border-left': string;
|
|
7
|
+
'--w-rjv-arrow-color': string;
|
|
8
|
+
'--w-rjv-info-color': string;
|
|
9
|
+
'--w-rjv-type-string-color': string;
|
|
10
|
+
'--w-rjv-type-int-color': string;
|
|
11
|
+
'--w-rjv-type-float-color': string;
|
|
12
|
+
'--w-rjv-type-bigint-color': string;
|
|
13
|
+
'--w-rjv-type-boolean-color': string;
|
|
14
|
+
'--w-rjv-type-date-color': string;
|
|
15
|
+
'--w-rjv-type-null-color': string;
|
|
16
|
+
'--w-rjv-type-nan-color': string;
|
|
17
|
+
'--w-rjv-type-undefined-color': string;
|
|
18
|
+
};
|
|
19
|
+
}
|