@uiw/react-json-view 1.3.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 +155 -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 +5 -1
- package/cjs/node.d.ts +0 -19
- package/cjs/node.js +68 -168
- package/cjs/semicolon.d.ts +21 -0
- package/cjs/semicolon.js +113 -0
- 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 +20 -5
- 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 +5 -1
- package/esm/node.d.ts +0 -19
- package/esm/node.js +49 -156
- package/esm/semicolon.d.ts +21 -0
- package/esm/semicolon.js +104 -0
- 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 +20 -5
- package/esm/value.js +67 -28
- package/package.json +7 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["onEdit", "components", "editable", "displayDataTypes"];
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import JsonView from '../';
|
|
6
|
+
import { ObjectKey } from './objectKey';
|
|
7
|
+
import { ReValue } from './value';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
10
|
+
var {
|
|
11
|
+
onEdit,
|
|
12
|
+
components,
|
|
13
|
+
editable = true,
|
|
14
|
+
displayDataTypes = true
|
|
15
|
+
} = props,
|
|
16
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
17
|
+
var comps = _extends({}, components, {
|
|
18
|
+
objectKey: reprops => /*#__PURE__*/_jsx(ObjectKey, _extends({}, reprops, {
|
|
19
|
+
editableValue: editable,
|
|
20
|
+
onEdit: onEdit,
|
|
21
|
+
render: components == null ? void 0 : components.objectKey
|
|
22
|
+
})),
|
|
23
|
+
value: reprops => {
|
|
24
|
+
return /*#__PURE__*/_jsx(ReValue, _extends({}, reprops, {
|
|
25
|
+
editableValue: editable,
|
|
26
|
+
displayDataTypes: displayDataTypes,
|
|
27
|
+
onEdit: onEdit
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return /*#__PURE__*/_jsx(JsonView, _extends({}, reset, {
|
|
32
|
+
displayDataTypes: false,
|
|
33
|
+
components: comps,
|
|
34
|
+
ref: ref
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
37
|
+
export default JsonViewEditor;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { SemicolonProps } from '../semicolon';
|
|
3
|
+
import { JsonViewEditorProps } from './';
|
|
4
|
+
export interface ObjectKeyProps<T extends object> extends SemicolonProps {
|
|
5
|
+
onEdit?: JsonViewEditorProps<T>['onEdit'];
|
|
6
|
+
render?: (props: SemicolonProps & {
|
|
7
|
+
ref?: React.RefObject<HTMLElement>;
|
|
8
|
+
}) => React.ReactNode;
|
|
9
|
+
editableValue?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const ObjectKey: FC<ObjectKeyProps<object>>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "editableValue", "onEdit", "highlightUpdates", "render"];
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { useHighlight } from '../semicolon';
|
|
6
|
+
import { Label } from '../value';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export var ObjectKey = props => {
|
|
9
|
+
var {
|
|
10
|
+
className,
|
|
11
|
+
value,
|
|
12
|
+
keyName,
|
|
13
|
+
parentName,
|
|
14
|
+
quotes,
|
|
15
|
+
label,
|
|
16
|
+
editableValue,
|
|
17
|
+
onEdit,
|
|
18
|
+
highlightUpdates = true,
|
|
19
|
+
render
|
|
20
|
+
} = props,
|
|
21
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
22
|
+
var [editable, setEditable] = useState(false);
|
|
23
|
+
var [curentLabel, setCurentLabel] = useState(label);
|
|
24
|
+
useEffect(() => setCurentLabel(label), [label]);
|
|
25
|
+
var $edit = useRef(null);
|
|
26
|
+
useHighlight({
|
|
27
|
+
value,
|
|
28
|
+
highlightUpdates: highlightUpdates,
|
|
29
|
+
highlightContainer: $edit
|
|
30
|
+
});
|
|
31
|
+
var click = evn => {
|
|
32
|
+
evn.stopPropagation();
|
|
33
|
+
if (!editableValue) return;
|
|
34
|
+
if (typeof keyName !== 'string') return;
|
|
35
|
+
if (editable) return;
|
|
36
|
+
setEditable(true);
|
|
37
|
+
if ($edit.current) {
|
|
38
|
+
var _$edit$current;
|
|
39
|
+
$edit.current.contentEditable = 'true';
|
|
40
|
+
(_$edit$current = $edit.current) == null ? void 0 : _$edit$current.focus();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var blur = () => {
|
|
44
|
+
setEditable(false);
|
|
45
|
+
if ($edit.current) {
|
|
46
|
+
var _$edit$current2;
|
|
47
|
+
$edit.current.contentEditable = 'false';
|
|
48
|
+
(_$edit$current2 = $edit.current) == null ? void 0 : _$edit$current2.focus();
|
|
49
|
+
setCurentLabel($edit.current.innerText);
|
|
50
|
+
onEdit && onEdit({
|
|
51
|
+
value: $edit.current.innerText,
|
|
52
|
+
oldValue: curentLabel,
|
|
53
|
+
keyName,
|
|
54
|
+
parentName,
|
|
55
|
+
type: 'key'
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var focus = () => {
|
|
60
|
+
if ($edit.current) {
|
|
61
|
+
var _$edit$current3;
|
|
62
|
+
$edit.current.contentEditable = 'true';
|
|
63
|
+
(_$edit$current3 = $edit.current) == null ? void 0 : _$edit$current3.focus();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var keyDown = evn => {
|
|
67
|
+
if (evn.key === 'Enter') {
|
|
68
|
+
evn.stopPropagation();
|
|
69
|
+
evn.preventDefault();
|
|
70
|
+
$edit.current.contentEditable = 'false';
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if ($edit.current) {
|
|
75
|
+
$edit.current.addEventListener("paste", e => {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
var text = e.clipboardData.getData("text/plain");
|
|
79
|
+
document.execCommand("insertHTML", false, text);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, [$edit]);
|
|
83
|
+
var style = {
|
|
84
|
+
minWidth: 34,
|
|
85
|
+
minHeight: 18,
|
|
86
|
+
paddingInline: 3,
|
|
87
|
+
display: 'inline-block'
|
|
88
|
+
};
|
|
89
|
+
var content = typeof keyName === 'string' ? "" + quotes + curentLabel + quotes : curentLabel;
|
|
90
|
+
var spanProps = {
|
|
91
|
+
onClick: click,
|
|
92
|
+
onFocus: focus,
|
|
93
|
+
onBlur: blur,
|
|
94
|
+
onKeyDown: keyDown,
|
|
95
|
+
style: editable ? style : {},
|
|
96
|
+
contentEditable: editable,
|
|
97
|
+
spellCheck: false,
|
|
98
|
+
autoFocus: editable,
|
|
99
|
+
suppressContentEditableWarning: true,
|
|
100
|
+
children: editable ? curentLabel : content
|
|
101
|
+
};
|
|
102
|
+
if (render) {
|
|
103
|
+
spanProps.value = value;
|
|
104
|
+
spanProps.keyName = keyName;
|
|
105
|
+
spanProps.parentName = parentName;
|
|
106
|
+
return render(_extends({
|
|
107
|
+
className
|
|
108
|
+
}, reset, spanProps, {
|
|
109
|
+
parentName,
|
|
110
|
+
label: curentLabel,
|
|
111
|
+
children: editable ? curentLabel : content,
|
|
112
|
+
ref: $edit
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
return /*#__PURE__*/_jsx(Label, _extends({
|
|
116
|
+
className: className
|
|
117
|
+
}, reset, {
|
|
118
|
+
autoFocus: editable
|
|
119
|
+
}, spanProps, {
|
|
120
|
+
ref: $edit
|
|
121
|
+
}));
|
|
122
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TypeProps } from '../value';
|
|
3
|
+
import { JsonViewEditorProps } from './';
|
|
4
|
+
export interface ReValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
|
|
5
|
+
onEdit?: JsonViewEditorProps<T>['onEdit'];
|
|
6
|
+
quotes?: JsonViewEditorProps<T>['quotes'];
|
|
7
|
+
keyName?: JsonViewEditorProps<T>['keyName'];
|
|
8
|
+
type: TypeProps['type'];
|
|
9
|
+
value?: unknown;
|
|
10
|
+
visible?: boolean;
|
|
11
|
+
editableValue?: boolean;
|
|
12
|
+
displayDataTypes?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function ReValue<T extends object>(props: ReValueProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -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,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SemicolonProps } from './semicolon';
|
|
3
3
|
import { ValueViewProps } from './value';
|
|
4
4
|
import { CopiedProps } from './copied';
|
|
5
|
+
import { EllipsisProps } from './comps/ellipsis';
|
|
6
|
+
import { MetaProps } from './comps/meta';
|
|
5
7
|
export * from './node';
|
|
6
8
|
export * from './value';
|
|
7
9
|
export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
@@ -19,6 +21,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
19
21
|
enableClipboard?: boolean;
|
|
20
22
|
/** Whether to highlight updates. @default true */
|
|
21
23
|
highlightUpdates?: boolean;
|
|
24
|
+
/** Whether sort keys through `String.prototype.localeCompare()` @default false */
|
|
25
|
+
objectSortKeys?: boolean | ((a: string, b: string) => number);
|
|
22
26
|
/** Display for quotes in object-key @default " */
|
|
23
27
|
quotes?: "'" | '"' | '';
|
|
24
28
|
/** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
|
package/esm/node.d.ts
CHANGED
|
@@ -1,25 +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 usePrevious<T>(value: T): T | undefined;
|
|
10
|
-
export declare function Meta(props: MetaProps): JSX.Element;
|
|
11
|
-
export interface EllipsisProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
12
|
-
render?: (props: EllipsisProps) => JSX.Element;
|
|
13
|
-
}
|
|
14
|
-
export declare const Ellipsis: FC<PropsWithChildren<EllipsisProps>>;
|
|
15
|
-
export interface SemicolonProps extends LabelProps {
|
|
16
|
-
show?: boolean;
|
|
17
|
-
highlightUpdates?: boolean;
|
|
18
|
-
quotes?: JsonViewProps<object>['quotes'];
|
|
19
|
-
value?: object;
|
|
20
|
-
render?: (props: Omit<SemicolonProps, 'show'> & {}) => JSX.Element;
|
|
21
|
-
}
|
|
22
|
-
export declare const Semicolon: FC<PropsWithChildren<SemicolonProps>>;
|
|
23
4
|
export declare const CountInfo: FC<PropsWithChildren<LabelProps>>;
|
|
24
5
|
export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
|
|
25
6
|
keyName?: string | number;
|
package/esm/node.js
CHANGED
|
@@ -1,146 +1,20 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["
|
|
4
|
-
|
|
5
|
-
_excluded3 = ["children", "render", "color", "value", "className", "show", "highlightUpdates", "quotes"],
|
|
6
|
-
_excluded4 = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand"];
|
|
7
|
-
import { Fragment, useId, cloneElement, useState, useMemo, useRef, useEffect } from 'react';
|
|
3
|
+
var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand"];
|
|
4
|
+
import { Fragment, useId, cloneElement, useState } from 'react';
|
|
8
5
|
import { ValueView, Colon, Label, Line, typeMap } from './value';
|
|
9
6
|
import { TriangleArrow } from './arrow/TriangleArrow';
|
|
10
7
|
import { useExpandsStatus, store } from './store';
|
|
11
|
-
import {
|
|
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 ref = useRef();
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
ref.current = value;
|
|
18
|
-
});
|
|
19
|
-
return ref.current;
|
|
20
|
-
}
|
|
21
|
-
export function Meta(props) {
|
|
22
|
-
var {
|
|
23
|
-
isArray = false,
|
|
24
|
-
start = false,
|
|
25
|
-
className,
|
|
26
|
-
render
|
|
27
|
-
} = props,
|
|
28
|
-
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
29
|
-
var mark = isArray ? '[]' : '{}';
|
|
30
|
-
var cls = "w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-" + (start ? 'start' : 'end') + " " + (className || '');
|
|
31
|
-
var color = "var(--w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-color, #236a7c)";
|
|
32
|
-
if (render) return render(_extends({
|
|
33
|
-
isArray,
|
|
34
|
-
className: cls,
|
|
35
|
-
style: {
|
|
36
|
-
color
|
|
37
|
-
},
|
|
38
|
-
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
39
|
-
}, reset));
|
|
40
|
-
return /*#__PURE__*/_jsx(Label, _extends({
|
|
41
|
-
color: color,
|
|
42
|
-
className: cls
|
|
43
|
-
}, reset, {
|
|
44
|
-
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
export var Ellipsis = _ref => {
|
|
48
|
-
var {
|
|
49
|
-
style,
|
|
50
|
-
render
|
|
51
|
-
} = _ref,
|
|
52
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
53
|
-
var styl = _extends({
|
|
54
|
-
cursor: 'pointer'
|
|
55
|
-
}, style);
|
|
56
|
-
var className = "w-rjv-ellipsis " + (props.className || '');
|
|
57
|
-
if (render) return render(_extends({
|
|
58
|
-
style: styl
|
|
59
|
-
}, props, {
|
|
60
|
-
className
|
|
61
|
-
}));
|
|
62
|
-
return /*#__PURE__*/_jsx("span", _extends({
|
|
63
|
-
className: className,
|
|
64
|
-
style: styl
|
|
65
|
-
}, props, {
|
|
66
|
-
children: "..."
|
|
67
|
-
}));
|
|
68
|
-
};
|
|
69
|
-
export var Semicolon = _ref2 => {
|
|
70
|
-
var {
|
|
71
|
-
children,
|
|
72
|
-
render,
|
|
73
|
-
color,
|
|
74
|
-
value,
|
|
75
|
-
className = 'w-rjv-object-key',
|
|
76
|
-
show,
|
|
77
|
-
highlightUpdates,
|
|
78
|
-
quotes
|
|
79
|
-
} = _ref2,
|
|
80
|
-
props = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
81
|
-
var prevValue = usePrevious(value);
|
|
82
|
-
var highlightContainer = useRef(null);
|
|
83
|
-
var isHighlight = useMemo(() => {
|
|
84
|
-
if (!highlightUpdates || prevValue === undefined) return false;
|
|
85
|
-
// highlight if value type changed
|
|
86
|
-
if (typeof value !== typeof prevValue) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
if (typeof value === 'number') {
|
|
90
|
-
// notice: NaN !== NaN
|
|
91
|
-
if (isNaN(value) && isNaN(prevValue)) return false;
|
|
92
|
-
return value !== prevValue;
|
|
93
|
-
}
|
|
94
|
-
// highlight if isArray changed
|
|
95
|
-
if (Array.isArray(value) !== Array.isArray(prevValue)) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
// not highlight object/function
|
|
99
|
-
// deep compare they will be slow
|
|
100
|
-
if (typeof value === 'object' || typeof value === 'function') {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// highlight if not equal
|
|
105
|
-
if (value !== prevValue) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}, [highlightUpdates, value]);
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
if (highlightContainer.current && isHighlight && 'animate' in highlightContainer.current) {
|
|
112
|
-
highlightContainer.current.animate([{
|
|
113
|
-
backgroundColor: 'var(--w-rjv-update-color, #ebcb8b)'
|
|
114
|
-
}, {
|
|
115
|
-
backgroundColor: ''
|
|
116
|
-
}], {
|
|
117
|
-
duration: 1000,
|
|
118
|
-
easing: 'ease-in'
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}, [isHighlight, value]);
|
|
122
|
-
var content = show ? "" + quotes + children + quotes : children;
|
|
123
|
-
if (render) return render(_extends({
|
|
124
|
-
className
|
|
125
|
-
}, props, {
|
|
126
|
-
value,
|
|
127
|
-
style: {
|
|
128
|
-
color
|
|
129
|
-
},
|
|
130
|
-
children: content
|
|
131
|
-
}));
|
|
132
|
-
return /*#__PURE__*/_jsx(Label, _extends({
|
|
133
|
-
className: className,
|
|
134
|
-
color: color
|
|
135
|
-
}, props, {
|
|
136
|
-
ref: highlightContainer,
|
|
137
|
-
children: content
|
|
138
|
-
}));
|
|
139
|
-
};
|
|
140
|
-
export var CountInfo = _ref3 => {
|
|
14
|
+
export var CountInfo = _ref => {
|
|
141
15
|
var {
|
|
142
16
|
children
|
|
143
|
-
} =
|
|
17
|
+
} = _ref;
|
|
144
18
|
return /*#__PURE__*/_jsx(Label, {
|
|
145
19
|
style: {
|
|
146
20
|
paddingLeft: 4,
|
|
@@ -162,6 +36,7 @@ export function RooNode(props) {
|
|
|
162
36
|
displayObjectSize = true,
|
|
163
37
|
enableClipboard = true,
|
|
164
38
|
highlightUpdates = true,
|
|
39
|
+
objectSortKeys = false,
|
|
165
40
|
indentWidth = 15,
|
|
166
41
|
collapsed,
|
|
167
42
|
level = 1,
|
|
@@ -170,9 +45,8 @@ export function RooNode(props) {
|
|
|
170
45
|
onCopied,
|
|
171
46
|
onExpand
|
|
172
47
|
} = props,
|
|
173
|
-
reset = _objectWithoutPropertiesLoose(props,
|
|
48
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
174
49
|
var isArray = Array.isArray(value);
|
|
175
|
-
var nameKeys = isArray ? Object.keys(value).map(m => Number(m)) : Object.keys(value);
|
|
176
50
|
var subkeyid = useId();
|
|
177
51
|
var expands = useExpandsStatus();
|
|
178
52
|
var expand = (_expands$keyid = expands[keyid]) != null ? _expands$keyid : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level <= collapsed : true;
|
|
@@ -210,6 +84,7 @@ export function RooNode(props) {
|
|
|
210
84
|
displayObjectSize,
|
|
211
85
|
enableClipboard,
|
|
212
86
|
indentWidth,
|
|
87
|
+
quotes,
|
|
213
88
|
renderBraces: components.braces,
|
|
214
89
|
renderValue: components.value
|
|
215
90
|
};
|
|
@@ -222,17 +97,26 @@ export function RooNode(props) {
|
|
|
222
97
|
className: "w-rjv-arrow"
|
|
223
98
|
});
|
|
224
99
|
var [showTools, setShowTools] = useState(false);
|
|
225
|
-
var tools = enableClipboard ? /*#__PURE__*/_jsx(Copied, {
|
|
226
|
-
show: showTools,
|
|
227
|
-
text: value,
|
|
228
|
-
onCopied: onCopied,
|
|
229
|
-
render: components.copied
|
|
230
|
-
}) : undefined;
|
|
231
100
|
var eventProps = {};
|
|
232
101
|
if (enableClipboard) {
|
|
233
102
|
eventProps.onMouseEnter = () => setShowTools(true);
|
|
234
103
|
eventProps.onMouseLeave = () => setShowTools(false);
|
|
235
104
|
}
|
|
105
|
+
var nameKeys = isArray ? Object.keys(value).map(m => Number(m)) : Object.keys(value);
|
|
106
|
+
|
|
107
|
+
// object
|
|
108
|
+
var entries = isArray ? Object.entries(value).map(m => [Number(m[0]), m[1]]) : Object.entries(value);
|
|
109
|
+
if (objectSortKeys) {
|
|
110
|
+
entries = objectSortKeys === true ? entries.sort((_ref2, _ref3) => {
|
|
111
|
+
var [a] = _ref2;
|
|
112
|
+
var [b] = _ref3;
|
|
113
|
+
return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
|
|
114
|
+
}) : entries.sort((_ref4, _ref5) => {
|
|
115
|
+
var [a] = _ref4;
|
|
116
|
+
var [b] = _ref5;
|
|
117
|
+
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
236
120
|
return /*#__PURE__*/_jsxs("div", _extends({}, reset, {
|
|
237
121
|
className: className + " w-rjv-inner"
|
|
238
122
|
}, eventProps, {
|
|
@@ -246,10 +130,11 @@ export function RooNode(props) {
|
|
|
246
130
|
children: [/*#__PURE__*/_jsx(Semicolon, {
|
|
247
131
|
value: value,
|
|
248
132
|
quotes: quotes,
|
|
133
|
+
"data-keys": keyid,
|
|
249
134
|
render: components.objectKey,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
135
|
+
keyName: keyName,
|
|
136
|
+
parentName: keyName,
|
|
137
|
+
color: typeof keyName === 'number' ? typeMap['number'].color : ''
|
|
253
138
|
}), /*#__PURE__*/_jsx(Colon, {})]
|
|
254
139
|
}), /*#__PURE__*/_jsx(Meta, {
|
|
255
140
|
start: true,
|
|
@@ -262,23 +147,31 @@ export function RooNode(props) {
|
|
|
262
147
|
render: components.braces
|
|
263
148
|
}), displayObjectSize && /*#__PURE__*/_jsxs(CountInfo, {
|
|
264
149
|
children: [nameKeys.length, " items"]
|
|
265
|
-
}),
|
|
150
|
+
}), /*#__PURE__*/_jsx(Tools, {
|
|
151
|
+
value: value,
|
|
152
|
+
enableClipboard: enableClipboard,
|
|
153
|
+
onCopied: onCopied,
|
|
154
|
+
components: components,
|
|
155
|
+
showTools: showTools
|
|
156
|
+
})]
|
|
266
157
|
}), expand && /*#__PURE__*/_jsx(Line, {
|
|
267
158
|
className: "w-rjv-content",
|
|
268
159
|
style: {
|
|
269
|
-
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)',
|
|
270
161
|
marginLeft: 6
|
|
271
162
|
},
|
|
272
|
-
children:
|
|
273
|
-
var
|
|
163
|
+
children: entries.length > 0 && entries.map((_ref6, idx) => {
|
|
164
|
+
var [key, itemVal] = _ref6;
|
|
165
|
+
var item = itemVal;
|
|
274
166
|
var renderKey = /*#__PURE__*/_jsx(Semicolon, {
|
|
275
167
|
value: item,
|
|
168
|
+
"data-keys": keyid,
|
|
276
169
|
quotes: quotes,
|
|
170
|
+
parentName: keyName,
|
|
277
171
|
highlightUpdates: highlightUpdates,
|
|
278
172
|
render: components.objectKey,
|
|
279
173
|
color: typeof key === 'number' ? typeMap['number'].color : '',
|
|
280
|
-
|
|
281
|
-
children: key
|
|
174
|
+
keyName: key
|
|
282
175
|
});
|
|
283
176
|
var isEmpty = Array.isArray(item) && item.length === 0 || typeof item === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
|
|
284
177
|
if (Array.isArray(item) && !isEmpty) {
|
|
@@ -287,8 +180,8 @@ export function RooNode(props) {
|
|
|
287
180
|
className: "w-rjv-wrap",
|
|
288
181
|
children: /*#__PURE__*/_jsx(RooNode, _extends({
|
|
289
182
|
value: item,
|
|
290
|
-
|
|
291
|
-
|
|
183
|
+
keyName: label,
|
|
184
|
+
keyid: keyid + subkeyid + label
|
|
292
185
|
}, subNodeProps))
|
|
293
186
|
}, label + idx);
|
|
294
187
|
}
|
|
@@ -296,11 +189,11 @@ export function RooNode(props) {
|
|
|
296
189
|
return /*#__PURE__*/_jsx(Line, {
|
|
297
190
|
className: "w-rjv-wrap",
|
|
298
191
|
children: /*#__PURE__*/_jsx(RooNode, _extends({
|
|
299
|
-
keyid: keyid + subkeyid + key,
|
|
300
192
|
value: item,
|
|
301
|
-
keyName: key
|
|
193
|
+
keyName: key,
|
|
194
|
+
keyid: keyid + subkeyid + key
|
|
302
195
|
}, subNodeProps))
|
|
303
|
-
}, key + idx);
|
|
196
|
+
}, key + '' + idx);
|
|
304
197
|
}
|
|
305
198
|
if (typeof item === 'function') {
|
|
306
199
|
return;
|