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