@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/esm/copied.d.ts
ADDED
package/esm/copied.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["children", "style", "text", "show"];
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export function Copied(props) {
|
|
7
|
+
var {
|
|
8
|
+
style,
|
|
9
|
+
text = '',
|
|
10
|
+
show
|
|
11
|
+
} = props,
|
|
12
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
13
|
+
if (!show) return null;
|
|
14
|
+
var [copied, setCopied] = useState(false);
|
|
15
|
+
var click = event => {
|
|
16
|
+
event.stopPropagation();
|
|
17
|
+
var copyText = JSON.stringify(text, (key, value) => {
|
|
18
|
+
if (typeof value === 'bigint') {
|
|
19
|
+
return value.toString();
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}, 2);
|
|
23
|
+
if (text === Infinity) copyText = Infinity;
|
|
24
|
+
navigator.clipboard.writeText(copyText).then(() => {
|
|
25
|
+
setCopied(true);
|
|
26
|
+
var timer = setTimeout(() => {
|
|
27
|
+
setCopied(false);
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
}, 3000);
|
|
30
|
+
}).catch(error => {});
|
|
31
|
+
};
|
|
32
|
+
var defalutStyle = _extends({}, style, {
|
|
33
|
+
cursor: 'pointer',
|
|
34
|
+
marginLeft: 5
|
|
35
|
+
});
|
|
36
|
+
var svgProps = _extends({
|
|
37
|
+
height: "1em",
|
|
38
|
+
width: "1em",
|
|
39
|
+
fill: "var(--w-rjv-copied-color, currentColor)",
|
|
40
|
+
onClick: click,
|
|
41
|
+
style: defalutStyle,
|
|
42
|
+
className: 'w-rjv-copied'
|
|
43
|
+
}, reset);
|
|
44
|
+
if (copied) {
|
|
45
|
+
return /*#__PURE__*/_jsx("svg", _extends({
|
|
46
|
+
viewBox: "0 0 38 38"
|
|
47
|
+
}, svgProps, {
|
|
48
|
+
fill: "var(--w-rjv-copied-success-color, #28a745)",
|
|
49
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
50
|
+
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"
|
|
51
|
+
})
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
return /*#__PURE__*/_jsx("svg", _extends({
|
|
55
|
+
viewBox: "0 0 38 38"
|
|
56
|
+
}, svgProps, {
|
|
57
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
58
|
+
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"
|
|
59
|
+
})
|
|
60
|
+
}));
|
|
61
|
+
}
|
package/esm/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/esm/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/esm/node.js
CHANGED
|
@@ -3,11 +3,12 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutP
|
|
|
3
3
|
var _excluded = ["isArray", "start", "className", "render"],
|
|
4
4
|
_excluded2 = ["style", "render"],
|
|
5
5
|
_excluded3 = ["children", "render", "color", "value", "className", "show"],
|
|
6
|
-
_excluded4 = ["value", "keyName", "displayDataTypes", "components", "displayObjectSize", "indentWidth", "keyid"];
|
|
7
|
-
import { Fragment, useId, cloneElement } from 'react';
|
|
8
|
-
import { ValueView, Colon, Label, typeMap } from './value';
|
|
6
|
+
_excluded4 = ["value", "keyName", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "indentWidth", "keyid"];
|
|
7
|
+
import { Fragment, useId, cloneElement, useState } from 'react';
|
|
8
|
+
import { ValueView, Colon, Label, Line, typeMap } from './value';
|
|
9
9
|
import { TriangleArrow } from './arrow/TriangleArrow';
|
|
10
10
|
import { useExpandsStatus, store } from './store';
|
|
11
|
+
import { Copied } from './copied';
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
13
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
14
|
export function Meta(props) {
|
|
@@ -36,7 +37,6 @@ export function Meta(props) {
|
|
|
36
37
|
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
37
38
|
}));
|
|
38
39
|
}
|
|
39
|
-
export var Line = props => /*#__PURE__*/_jsx("div", _extends({}, props));
|
|
40
40
|
export var Ellipsis = _ref => {
|
|
41
41
|
var {
|
|
42
42
|
style,
|
|
@@ -108,6 +108,7 @@ export function RooNode(props) {
|
|
|
108
108
|
displayDataTypes = true,
|
|
109
109
|
components = {},
|
|
110
110
|
displayObjectSize = true,
|
|
111
|
+
enableClipboard = true,
|
|
111
112
|
indentWidth = 15,
|
|
112
113
|
keyid = 'root'
|
|
113
114
|
} = props,
|
|
@@ -135,6 +136,9 @@ export function RooNode(props) {
|
|
|
135
136
|
};
|
|
136
137
|
var valueViewProps = {
|
|
137
138
|
displayDataTypes,
|
|
139
|
+
displayObjectSize,
|
|
140
|
+
enableClipboard,
|
|
141
|
+
indentWidth,
|
|
138
142
|
renderValue: components.value
|
|
139
143
|
};
|
|
140
144
|
var arrowView = components.arrow ? /*#__PURE__*/cloneElement(components.arrow, {
|
|
@@ -143,7 +147,16 @@ export function RooNode(props) {
|
|
|
143
147
|
}) : /*#__PURE__*/_jsx(TriangleArrow, {
|
|
144
148
|
style: arrowStyle
|
|
145
149
|
});
|
|
150
|
+
var [showTools, setShowTools] = useState(false);
|
|
151
|
+
var tools = enableClipboard ? /*#__PURE__*/_jsx(Copied, {
|
|
152
|
+
show: showTools,
|
|
153
|
+
text: value
|
|
154
|
+
}) : undefined;
|
|
155
|
+
var mouseEnter = () => setShowTools(true);
|
|
156
|
+
var mouseLeave = () => setShowTools(false);
|
|
146
157
|
return /*#__PURE__*/_jsxs("div", _extends({}, reset, {
|
|
158
|
+
onMouseEnter: mouseEnter,
|
|
159
|
+
onMouseLeave: mouseLeave,
|
|
147
160
|
children: [/*#__PURE__*/_jsxs(Line, {
|
|
148
161
|
style: {
|
|
149
162
|
display: 'inline-flex',
|
|
@@ -169,15 +182,23 @@ export function RooNode(props) {
|
|
|
169
182
|
render: components.braces
|
|
170
183
|
}), displayObjectSize && /*#__PURE__*/_jsxs(CountInfo, {
|
|
171
184
|
children: [nameKeys.length, " items"]
|
|
172
|
-
})]
|
|
185
|
+
}), tools]
|
|
173
186
|
}), expand && /*#__PURE__*/_jsx(Line, {
|
|
174
187
|
style: {
|
|
175
|
-
borderLeft: 'var(--w-rjv-
|
|
188
|
+
borderLeft: '1px solid var(--w-rjv-line-color, #ebebeb)',
|
|
176
189
|
marginLeft: 6
|
|
177
190
|
},
|
|
178
191
|
children: nameKeys.length > 0 && nameKeys.map((key, idx) => {
|
|
179
192
|
var item = value[key];
|
|
180
|
-
|
|
193
|
+
var renderKey = /*#__PURE__*/_jsx(Semicolon, {
|
|
194
|
+
value: item,
|
|
195
|
+
render: components.objectKey,
|
|
196
|
+
color: typeof key === 'number' ? typeMap['number'].color : '',
|
|
197
|
+
show: typeof key === 'string',
|
|
198
|
+
children: key
|
|
199
|
+
});
|
|
200
|
+
var isEmpty = Array.isArray(item) && item.length === 0 || typeof item === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
|
|
201
|
+
if (Array.isArray(item) && !isEmpty) {
|
|
181
202
|
var label = isArray ? idx : key;
|
|
182
203
|
return /*#__PURE__*/_jsx(Line, {
|
|
183
204
|
children: /*#__PURE__*/_jsx(RooNode, _extends({
|
|
@@ -187,35 +208,7 @@ export function RooNode(props) {
|
|
|
187
208
|
}, subNodeProps))
|
|
188
209
|
}, label + idx);
|
|
189
210
|
}
|
|
190
|
-
|
|
191
|
-
value: item,
|
|
192
|
-
render: components.objectKey,
|
|
193
|
-
color: typeof key === 'number' ? typeMap['number'].color : '',
|
|
194
|
-
show: typeof key === 'string',
|
|
195
|
-
children: key
|
|
196
|
-
});
|
|
197
|
-
if (typeof item === 'object' && item && !(item instanceof Date)) {
|
|
198
|
-
if (Object.keys(item).length === 0) {
|
|
199
|
-
return /*#__PURE__*/_jsxs(Line, {
|
|
200
|
-
style: {
|
|
201
|
-
paddingLeft: indentWidth
|
|
202
|
-
},
|
|
203
|
-
children: [/*#__PURE__*/_jsx(ValueView, _extends({}, valueViewProps, {
|
|
204
|
-
renderKey: renderKey,
|
|
205
|
-
keyName: key,
|
|
206
|
-
value: item
|
|
207
|
-
})), /*#__PURE__*/_jsx(Meta, {
|
|
208
|
-
render: components.braces,
|
|
209
|
-
start: true,
|
|
210
|
-
isArray: isArray
|
|
211
|
-
}), /*#__PURE__*/_jsx(Meta, {
|
|
212
|
-
render: components.braces,
|
|
213
|
-
isArray: isArray
|
|
214
|
-
}), displayObjectSize && /*#__PURE__*/_jsxs(CountInfo, {
|
|
215
|
-
children: [Object.keys(item).length, " items"]
|
|
216
|
-
})]
|
|
217
|
-
}, key + idx);
|
|
218
|
-
}
|
|
211
|
+
if (typeof item === 'object' && item && !(item instanceof Date) && !isEmpty) {
|
|
219
212
|
return /*#__PURE__*/_jsx(Line, {
|
|
220
213
|
children: /*#__PURE__*/_jsx(RooNode, _extends({
|
|
221
214
|
keyid: keyid + subkeyid + key,
|
|
@@ -227,16 +220,12 @@ export function RooNode(props) {
|
|
|
227
220
|
if (typeof item === 'function') {
|
|
228
221
|
return;
|
|
229
222
|
}
|
|
230
|
-
return /*#__PURE__*/_jsx(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
keyName: key,
|
|
237
|
-
value: item
|
|
238
|
-
}))
|
|
239
|
-
}, idx);
|
|
223
|
+
return /*#__PURE__*/_jsx(ValueView, _extends({}, valueViewProps, {
|
|
224
|
+
renderBraces: components.braces,
|
|
225
|
+
renderKey: renderKey,
|
|
226
|
+
keyName: key,
|
|
227
|
+
value: item
|
|
228
|
+
}), idx);
|
|
240
229
|
})
|
|
241
230
|
}), expand && /*#__PURE__*/_jsx(Line, {
|
|
242
231
|
style: {
|
package/esm/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/esm/theme/dark.js
CHANGED
|
@@ -2,9 +2,11 @@ export var darkTheme = {
|
|
|
2
2
|
'--w-rjv-font-family': 'monospace',
|
|
3
3
|
'--w-rjv-color': '#0184a6',
|
|
4
4
|
'--w-rjv-background-color': '#202020',
|
|
5
|
-
'--w-rjv-
|
|
5
|
+
'--w-rjv-line-color': '#323232',
|
|
6
6
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
7
7
|
'--w-rjv-info-color': '#656565',
|
|
8
|
+
'--w-rjv-copied-color': '#0184a6',
|
|
9
|
+
'--w-rjv-copied-success-color': '#28a745',
|
|
8
10
|
'--w-rjv-curlybraces-color': '#1896b6',
|
|
9
11
|
'--w-rjv-brackets-color': '#1896b6',
|
|
10
12
|
'--w-rjv-type-string-color': '#cb4b16',
|
package/esm/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/esm/theme/light.js
CHANGED
|
@@ -2,9 +2,11 @@ export var lightTheme = {
|
|
|
2
2
|
'--w-rjv-font-family': 'monospace',
|
|
3
3
|
'--w-rjv-color': '#002b36',
|
|
4
4
|
'--w-rjv-background-color': '#ffffff',
|
|
5
|
-
'--w-rjv-
|
|
5
|
+
'--w-rjv-line-color': '#ebebeb',
|
|
6
6
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
7
7
|
'--w-rjv-info-color': '#0000004d',
|
|
8
|
+
'--w-rjv-copied-color': '#002b36',
|
|
9
|
+
'--w-rjv-copied-success-color': '#28a745',
|
|
8
10
|
'--w-rjv-curlybraces-color': '#236a7c',
|
|
9
11
|
'--w-rjv-brackets-color': '#236a7c',
|
|
10
12
|
'--w-rjv-type-string-color': '#cb4b16',
|
package/esm/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/esm/value.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
3
|
var _excluded = ["children", "style"],
|
|
4
|
-
_excluded2 = ["value", "keyName", "renderKey", "renderValue", "displayDataTypes"],
|
|
4
|
+
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
5
5
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
6
|
-
import { Fragment } from 'react';
|
|
6
|
+
import { Fragment, useState } from 'react';
|
|
7
|
+
import { Meta, CountInfo } from './node';
|
|
8
|
+
import { Copied } from './copied';
|
|
7
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
export var Line = props => /*#__PURE__*/_jsx("div", _extends({}, props));
|
|
9
12
|
var isFloat = n => Number(n) === n && n % 1 !== 0 || isNaN(n);
|
|
10
13
|
export var typeMap = {
|
|
11
14
|
string: {
|
|
@@ -64,8 +67,12 @@ export function ValueView(props) {
|
|
|
64
67
|
var _typeMap$type;
|
|
65
68
|
var {
|
|
66
69
|
value,
|
|
70
|
+
indentWidth,
|
|
67
71
|
renderKey,
|
|
68
72
|
renderValue,
|
|
73
|
+
renderBraces,
|
|
74
|
+
enableClipboard,
|
|
75
|
+
displayObjectSize,
|
|
69
76
|
displayDataTypes
|
|
70
77
|
} = props,
|
|
71
78
|
reset = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
@@ -112,6 +119,13 @@ export function ValueView(props) {
|
|
|
112
119
|
typeView = /*#__PURE__*/_jsx(Fragment, {});
|
|
113
120
|
}
|
|
114
121
|
color = ((_typeMap$type = typeMap[type]) == null ? void 0 : _typeMap$type.color) || '';
|
|
122
|
+
var [showTools, setShowTools] = useState(false);
|
|
123
|
+
var tools = enableClipboard ? /*#__PURE__*/_jsx(Copied, {
|
|
124
|
+
show: showTools,
|
|
125
|
+
text: value
|
|
126
|
+
}) : undefined;
|
|
127
|
+
var mouseEnter = () => setShowTools(true);
|
|
128
|
+
var mouseLeave = () => setShowTools(false);
|
|
115
129
|
if (content && typeof content === 'string') {
|
|
116
130
|
var valueView = renderValue ? renderValue({
|
|
117
131
|
className: 'w-rjv-value',
|
|
@@ -126,13 +140,40 @@ export function ValueView(props) {
|
|
|
126
140
|
className: "w-rjv-value",
|
|
127
141
|
children: content
|
|
128
142
|
});
|
|
129
|
-
return /*#__PURE__*/
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
return /*#__PURE__*/_jsx(Line, {
|
|
144
|
+
style: {
|
|
145
|
+
paddingLeft: indentWidth
|
|
146
|
+
},
|
|
147
|
+
onMouseEnter: mouseEnter,
|
|
148
|
+
onMouseLeave: mouseLeave,
|
|
149
|
+
children: /*#__PURE__*/_jsxs(Label, _extends({}, reset, {
|
|
150
|
+
children: [renderKey, /*#__PURE__*/_jsx(Colon, {}), typeView, valueView, tools]
|
|
151
|
+
}))
|
|
152
|
+
});
|
|
132
153
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
154
|
+
var length = Array.isArray(value) ? value.length : Object.keys(value).length;
|
|
155
|
+
var empty = /*#__PURE__*/_jsxs(Fragment, {
|
|
156
|
+
children: [/*#__PURE__*/_jsx(Meta, {
|
|
157
|
+
render: renderBraces,
|
|
158
|
+
start: true,
|
|
159
|
+
isArray: Array.isArray(value)
|
|
160
|
+
}), /*#__PURE__*/_jsx(Meta, {
|
|
161
|
+
render: renderBraces,
|
|
162
|
+
isArray: Array.isArray(value)
|
|
163
|
+
}), displayObjectSize && /*#__PURE__*/_jsxs(CountInfo, {
|
|
164
|
+
children: [length, " items"]
|
|
165
|
+
})]
|
|
166
|
+
});
|
|
167
|
+
return /*#__PURE__*/_jsx(Line, {
|
|
168
|
+
style: {
|
|
169
|
+
paddingLeft: indentWidth
|
|
170
|
+
},
|
|
171
|
+
onMouseEnter: mouseEnter,
|
|
172
|
+
onMouseLeave: mouseLeave,
|
|
173
|
+
children: /*#__PURE__*/_jsxs(Label, _extends({}, reset, {
|
|
174
|
+
children: [renderKey, /*#__PURE__*/_jsx(Colon, {}), typeView, empty, tools]
|
|
175
|
+
}))
|
|
176
|
+
});
|
|
136
177
|
}
|
|
137
178
|
export var Label = _ref2 => {
|
|
138
179
|
var {
|
package/light.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module '@uiw/react-json-view/light' {
|
|
2
|
+
export const lightTheme: {
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-json-view",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "JSON viewer for react.",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -45,9 +45,12 @@
|
|
|
45
45
|
"react-dom": ">=18.0.0"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
|
+
"dark.d.ts",
|
|
49
|
+
"light.d.ts",
|
|
50
|
+
"triangle-arrow.d.ts",
|
|
51
|
+
"triangle-solid-arrow.d.ts",
|
|
48
52
|
"cjs",
|
|
49
|
-
"esm"
|
|
50
|
-
"src"
|
|
53
|
+
"esm"
|
|
51
54
|
],
|
|
52
55
|
"keywords": [
|
|
53
56
|
"monaco-editor",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare module '@uiw/react-json-view/triangle-solid-arrow' {
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface TriangleSolidArrowProps extends React.SVGProps<SVGSVGElement> { }
|
|
4
|
+
export function TriangleSolidArrow(props: TriangleSolidArrowProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface TriangleArrowProps extends React.SVGProps<SVGSVGElement> {}
|
|
4
|
-
export function TriangleArrow(props: TriangleArrowProps) {
|
|
5
|
-
const { style, ...reset } = props;
|
|
6
|
-
const defaultStyle: React.CSSProperties = {
|
|
7
|
-
cursor: 'pointer',
|
|
8
|
-
height: '1em',
|
|
9
|
-
width: '1em',
|
|
10
|
-
...style,
|
|
11
|
-
};
|
|
12
|
-
return (
|
|
13
|
-
<svg viewBox="0 0 24 24" fill="var(--w-rjv-arrow-color, currentColor)" style={defaultStyle} {...reset}>
|
|
14
|
-
<path d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"></path>
|
|
15
|
-
</svg>
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface TriangleSolidArrowProps extends React.SVGProps<SVGSVGElement> {}
|
|
4
|
-
export function TriangleSolidArrow(props: TriangleSolidArrowProps) {
|
|
5
|
-
const { style, ...reset } = props;
|
|
6
|
-
const defaultStyle: React.CSSProperties = {
|
|
7
|
-
cursor: 'pointer',
|
|
8
|
-
height: '1em',
|
|
9
|
-
width: '1em',
|
|
10
|
-
...style,
|
|
11
|
-
};
|
|
12
|
-
return (
|
|
13
|
-
<svg viewBox="0 0 15 15" fill="var(--w-rjv-arrow-color, currentColor)" style={defaultStyle} {...reset}>
|
|
14
|
-
<path d="M0 5l6 6 6-6z"></path>
|
|
15
|
-
</svg>
|
|
16
|
-
);
|
|
17
|
-
}
|
package/src/index.tsx
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React, { useId } from 'react';
|
|
2
|
-
import { forwardRef } from 'react';
|
|
3
|
-
import { RooNode, MetaProps, SemicolonProps, EllipsisProps } from './node';
|
|
4
|
-
import { ValueViewProps } from './value';
|
|
5
|
-
|
|
6
|
-
export * from './node';
|
|
7
|
-
export * from './value';
|
|
8
|
-
export interface JsonViewProps<T>
|
|
9
|
-
extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
10
|
-
/** This property contains your input JSON */
|
|
11
|
-
value?: T;
|
|
12
|
-
/** Set the indent-width for nested objects @default `15`*/
|
|
13
|
-
indentWidth?: number;
|
|
14
|
-
/** When set to `true`, data type labels prefix values @default `true` */
|
|
15
|
-
displayDataTypes?: boolean;
|
|
16
|
-
/** When set to `true`, `objects` and `arrays` are labeled with size @default `true` */
|
|
17
|
-
displayObjectSize?: boolean;
|
|
18
|
-
/** Define the root node name. @default `undefined` */
|
|
19
|
-
keyName?: string | number;
|
|
20
|
-
components?: {
|
|
21
|
-
braces?: MetaProps['render'];
|
|
22
|
-
ellipsis?: EllipsisProps['render'];
|
|
23
|
-
arrow?: JSX.Element;
|
|
24
|
-
objectKey?: SemicolonProps['render'];
|
|
25
|
-
value?: ValueViewProps<T>['renderValue'];
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const JsonView = forwardRef<HTMLDivElement, JsonViewProps<object>>((props, ref) => {
|
|
30
|
-
const { value, style, className, ...reset } = props;
|
|
31
|
-
const defaultStyle = {
|
|
32
|
-
lineHeight: 1.4,
|
|
33
|
-
fontFamily: 'monospace',
|
|
34
|
-
color: 'var(--w-rjv-color, #002b36)',
|
|
35
|
-
backgroundColor: 'var(--w-rjv-background-color, #00000000)',
|
|
36
|
-
...style,
|
|
37
|
-
} as React.CSSProperties;
|
|
38
|
-
const cls = `w-json-view-container w-rjv ${className || ''}`;
|
|
39
|
-
const keyid = useId();
|
|
40
|
-
return <RooNode className={cls} value={value} {...reset} ref={ref} keyid={keyid} style={defaultStyle} />;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
export default JsonView;
|