@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
package/cjs/semicolon.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Semicolon = void 0;
|
|
8
|
+
exports.useHighlight = useHighlight;
|
|
9
|
+
exports.usePrevious = usePrevious;
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
+
var _react = require("react");
|
|
14
|
+
var _value = require("./value");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "parentName"];
|
|
17
|
+
function usePrevious(value) {
|
|
18
|
+
var ref = (0, _react.useRef)();
|
|
19
|
+
(0, _react.useEffect)(function () {
|
|
20
|
+
ref.current = value;
|
|
21
|
+
});
|
|
22
|
+
return ref.current;
|
|
23
|
+
}
|
|
24
|
+
function useHighlight(_ref) {
|
|
25
|
+
var value = _ref.value,
|
|
26
|
+
highlightUpdates = _ref.highlightUpdates,
|
|
27
|
+
highlightContainer = _ref.highlightContainer;
|
|
28
|
+
var prevValue = usePrevious(value);
|
|
29
|
+
var isHighlight = (0, _react.useMemo)(function () {
|
|
30
|
+
if (!highlightUpdates || prevValue === undefined) return false;
|
|
31
|
+
// highlight if value type changed
|
|
32
|
+
if ((0, _typeof2["default"])(value) !== (0, _typeof2["default"])(prevValue)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === 'number') {
|
|
36
|
+
// notice: NaN !== NaN
|
|
37
|
+
if (isNaN(value) && isNaN(prevValue)) return false;
|
|
38
|
+
return value !== prevValue;
|
|
39
|
+
}
|
|
40
|
+
// highlight if isArray changed
|
|
41
|
+
if (Array.isArray(value) !== Array.isArray(prevValue)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
// not highlight object/function
|
|
45
|
+
// deep compare they will be slow
|
|
46
|
+
if ((0, _typeof2["default"])(value) === 'object' || typeof value === 'function') {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// highlight if not equal
|
|
51
|
+
if (value !== prevValue) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}, [highlightUpdates, value]);
|
|
56
|
+
(0, _react.useEffect)(function () {
|
|
57
|
+
if (highlightContainer && highlightContainer.current && isHighlight && 'animate' in highlightContainer.current) {
|
|
58
|
+
highlightContainer.current.animate([{
|
|
59
|
+
backgroundColor: 'var(--w-rjv-update-color, #ebcb8b)'
|
|
60
|
+
}, {
|
|
61
|
+
backgroundColor: ''
|
|
62
|
+
}], {
|
|
63
|
+
duration: 1000,
|
|
64
|
+
easing: 'ease-in'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}, [isHighlight, value, highlightContainer]);
|
|
68
|
+
}
|
|
69
|
+
var Semicolon = function Semicolon(_ref2) {
|
|
70
|
+
var children = _ref2.children,
|
|
71
|
+
render = _ref2.render,
|
|
72
|
+
color = _ref2.color,
|
|
73
|
+
value = _ref2.value,
|
|
74
|
+
_ref2$className = _ref2.className,
|
|
75
|
+
className = _ref2$className === void 0 ? 'w-rjv-object-key' : _ref2$className,
|
|
76
|
+
keyName = _ref2.keyName,
|
|
77
|
+
highlightUpdates = _ref2.highlightUpdates,
|
|
78
|
+
quotes = _ref2.quotes,
|
|
79
|
+
style = _ref2.style,
|
|
80
|
+
parentName = _ref2.parentName,
|
|
81
|
+
props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
|
|
82
|
+
var highlightContainer = (0, _react.useRef)(null);
|
|
83
|
+
var content = typeof keyName === 'string' ? "".concat(quotes).concat(keyName).concat(quotes) : keyName;
|
|
84
|
+
if (render) {
|
|
85
|
+
return render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
86
|
+
className: className
|
|
87
|
+
}, props), {}, {
|
|
88
|
+
value: value,
|
|
89
|
+
style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
|
|
90
|
+
color: color
|
|
91
|
+
}),
|
|
92
|
+
parentName: parentName,
|
|
93
|
+
keyName: keyName,
|
|
94
|
+
quotes: quotes,
|
|
95
|
+
label: keyName,
|
|
96
|
+
children: content
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
;
|
|
100
|
+
useHighlight({
|
|
101
|
+
value: value,
|
|
102
|
+
highlightUpdates: highlightUpdates,
|
|
103
|
+
highlightContainer: highlightContainer
|
|
104
|
+
});
|
|
105
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
|
|
106
|
+
className: className,
|
|
107
|
+
color: color
|
|
108
|
+
}, props), {}, {
|
|
109
|
+
ref: highlightContainer,
|
|
110
|
+
children: content
|
|
111
|
+
}));
|
|
112
|
+
};
|
|
113
|
+
exports.Semicolon = Semicolon;
|
package/cjs/theme/dark.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const darkTheme: {
|
|
|
4
4
|
'--w-rjv-background-color': string;
|
|
5
5
|
'--w-rjv-line-color': string;
|
|
6
6
|
'--w-rjv-arrow-color': string;
|
|
7
|
+
'--w-rjv-edit-color': string;
|
|
7
8
|
'--w-rjv-info-color': string;
|
|
8
9
|
'--w-rjv-update-color': string;
|
|
9
10
|
'--w-rjv-copied-color': string;
|
|
@@ -16,6 +17,7 @@ export declare const darkTheme: {
|
|
|
16
17
|
'--w-rjv-type-bigint-color': string;
|
|
17
18
|
'--w-rjv-type-boolean-color': string;
|
|
18
19
|
'--w-rjv-type-date-color': string;
|
|
20
|
+
'--w-rjv-type-url-color': string;
|
|
19
21
|
'--w-rjv-type-null-color': string;
|
|
20
22
|
'--w-rjv-type-nan-color': string;
|
|
21
23
|
'--w-rjv-type-undefined-color': string;
|
package/cjs/theme/dark.js
CHANGED
|
@@ -10,6 +10,7 @@ var darkTheme = {
|
|
|
10
10
|
'--w-rjv-background-color': '#202020',
|
|
11
11
|
'--w-rjv-line-color': '#323232',
|
|
12
12
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
|
+
'--w-rjv-edit-color': 'var(--w-rjv-color)',
|
|
13
14
|
'--w-rjv-info-color': '#656565',
|
|
14
15
|
'--w-rjv-update-color': '#ebcb8b',
|
|
15
16
|
'--w-rjv-copied-color': '#0184a6',
|
|
@@ -22,6 +23,7 @@ var darkTheme = {
|
|
|
22
23
|
'--w-rjv-type-bigint-color': '#268bd2',
|
|
23
24
|
'--w-rjv-type-boolean-color': '#2aa198',
|
|
24
25
|
'--w-rjv-type-date-color': '#586e75',
|
|
26
|
+
'--w-rjv-type-url-color': '#649bd8',
|
|
25
27
|
'--w-rjv-type-null-color': '#d33682',
|
|
26
28
|
'--w-rjv-type-nan-color': '#859900',
|
|
27
29
|
'--w-rjv-type-undefined-color': '#586e75'
|
package/cjs/theme/light.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const lightTheme: {
|
|
|
4
4
|
'--w-rjv-background-color': string;
|
|
5
5
|
'--w-rjv-line-color': string;
|
|
6
6
|
'--w-rjv-arrow-color': string;
|
|
7
|
+
'--w-rjv-edit-color': string;
|
|
7
8
|
'--w-rjv-info-color': string;
|
|
8
9
|
'--w-rjv-update-color': string;
|
|
9
10
|
'--w-rjv-copied-color': string;
|
|
@@ -16,6 +17,7 @@ export declare const lightTheme: {
|
|
|
16
17
|
'--w-rjv-type-bigint-color': string;
|
|
17
18
|
'--w-rjv-type-boolean-color': string;
|
|
18
19
|
'--w-rjv-type-date-color': string;
|
|
20
|
+
'--w-rjv-type-url-color': string;
|
|
19
21
|
'--w-rjv-type-null-color': string;
|
|
20
22
|
'--w-rjv-type-nan-color': string;
|
|
21
23
|
'--w-rjv-type-undefined-color': string;
|
package/cjs/theme/light.js
CHANGED
|
@@ -10,6 +10,7 @@ var lightTheme = {
|
|
|
10
10
|
'--w-rjv-background-color': '#ffffff',
|
|
11
11
|
'--w-rjv-line-color': '#ebebeb',
|
|
12
12
|
'--w-rjv-arrow-color': 'var(--w-rjv-color)',
|
|
13
|
+
'--w-rjv-edit-color': 'var(--w-rjv-color)',
|
|
13
14
|
'--w-rjv-info-color': '#0000004d',
|
|
14
15
|
'--w-rjv-update-color': '#ebcb8b',
|
|
15
16
|
'--w-rjv-copied-color': '#002b36',
|
|
@@ -22,6 +23,7 @@ var lightTheme = {
|
|
|
22
23
|
'--w-rjv-type-bigint-color': '#268bd2',
|
|
23
24
|
'--w-rjv-type-boolean-color': '#2aa198',
|
|
24
25
|
'--w-rjv-type-date-color': '#586e75',
|
|
26
|
+
'--w-rjv-type-url-color': '#0969da',
|
|
25
27
|
'--w-rjv-type-null-color': '#d33682',
|
|
26
28
|
'--w-rjv-type-nan-color': '#859900',
|
|
27
29
|
'--w-rjv-type-undefined-color': '#586e75'
|
package/cjs/tools.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JsonViewProps } from './';
|
|
2
|
+
interface ToolsProps<T extends object> {
|
|
3
|
+
enableClipboard?: boolean;
|
|
4
|
+
value?: T | {};
|
|
5
|
+
onCopied?: JsonViewProps<T>['onCopied'];
|
|
6
|
+
components?: JsonViewProps<T>['components'];
|
|
7
|
+
showTools?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function Tools<T extends object>(props: ToolsProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
package/cjs/tools.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Tools = Tools;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _copied = require("./copied");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
function Tools(props) {
|
|
11
|
+
var enableClipboard = props.enableClipboard,
|
|
12
|
+
value = props.value,
|
|
13
|
+
showTools = props.showTools,
|
|
14
|
+
components = props.components,
|
|
15
|
+
onCopied = props.onCopied;
|
|
16
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
|
|
17
|
+
children: enableClipboard && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
18
|
+
show: showTools,
|
|
19
|
+
text: value,
|
|
20
|
+
onCopied: onCopied,
|
|
21
|
+
render: components === null || components === void 0 ? void 0 : components.copied
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
}
|
package/cjs/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> {
|
|
44
|
-
keyName?: string;
|
|
45
|
-
value?:
|
|
49
|
+
export interface ValueViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
|
|
50
|
+
keyName?: string | number;
|
|
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;
|
package/cjs/value.js
CHANGED
|
@@ -6,17 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.Type = exports.Line = exports.Label = exports.Colon = void 0;
|
|
8
8
|
exports.ValueView = ValueView;
|
|
9
|
-
exports.
|
|
9
|
+
exports.getValueString = getValueString;
|
|
10
|
+
exports.typeMap = exports.isFloat = void 0;
|
|
10
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
12
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
13
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
14
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
15
|
var _react = require("react");
|
|
15
16
|
var _node = require("./node");
|
|
17
|
+
var _meta = require("./comps/meta");
|
|
16
18
|
var _copied = require("./copied");
|
|
17
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
20
|
var _excluded = ["children", "style"],
|
|
19
|
-
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
21
|
+
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "quotes", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
20
22
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
21
23
|
var Line = function Line(props) {
|
|
22
24
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
@@ -25,6 +27,7 @@ exports.Line = Line;
|
|
|
25
27
|
var isFloat = function isFloat(n) {
|
|
26
28
|
return Number(n) === n && n % 1 !== 0 || isNaN(n);
|
|
27
29
|
};
|
|
30
|
+
exports.isFloat = isFloat;
|
|
28
31
|
var typeMap = {
|
|
29
32
|
string: {
|
|
30
33
|
color: 'var(--w-rjv-type-string-color, #cb4b16)',
|
|
@@ -50,6 +53,10 @@ var typeMap = {
|
|
|
50
53
|
color: 'var(--w-rjv-type-date-color, #586e75)',
|
|
51
54
|
label: 'date'
|
|
52
55
|
},
|
|
56
|
+
url: {
|
|
57
|
+
color: 'var(--w-rjv-type-url-color, #0969da)',
|
|
58
|
+
label: 'URL'
|
|
59
|
+
},
|
|
53
60
|
"null": {
|
|
54
61
|
color: 'var(--w-rjv-type-null-color, #d33682)',
|
|
55
62
|
label: 'null'
|
|
@@ -79,22 +86,9 @@ var Colon = function Colon(_ref) {
|
|
|
79
86
|
}));
|
|
80
87
|
};
|
|
81
88
|
exports.Colon = Colon;
|
|
82
|
-
function
|
|
83
|
-
var _typeMap$type;
|
|
84
|
-
var value = props.value,
|
|
85
|
-
keyName = props.keyName,
|
|
86
|
-
indentWidth = props.indentWidth,
|
|
87
|
-
renderKey = props.renderKey,
|
|
88
|
-
renderValue = props.renderValue,
|
|
89
|
-
renderBraces = props.renderBraces,
|
|
90
|
-
enableClipboard = props.enableClipboard,
|
|
91
|
-
displayObjectSize = props.displayObjectSize,
|
|
92
|
-
displayDataTypes = props.displayDataTypes,
|
|
93
|
-
reset = (0, _objectWithoutProperties2["default"])(props, _excluded2);
|
|
89
|
+
function getValueString(value) {
|
|
94
90
|
var type = (0, _typeof2["default"])(value);
|
|
95
91
|
var content = '';
|
|
96
|
-
var color = '';
|
|
97
|
-
var style = {};
|
|
98
92
|
if (typeof value === 'number') {
|
|
99
93
|
type = isFloat(value) ? 'float' : 'number';
|
|
100
94
|
content = value.toString();
|
|
@@ -107,29 +101,62 @@ function ValueView(props) {
|
|
|
107
101
|
type = 'date';
|
|
108
102
|
content = value.toString();
|
|
109
103
|
}
|
|
110
|
-
var typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
|
|
111
|
-
type: type
|
|
112
|
-
});
|
|
113
104
|
if (value === null) {
|
|
114
105
|
type = 'null';
|
|
115
106
|
content = "".concat(value).toLocaleUpperCase();
|
|
116
|
-
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
117
|
-
style = {
|
|
118
|
-
fontWeight: 'bold'
|
|
119
|
-
};
|
|
120
107
|
}
|
|
121
108
|
if (value === undefined) {
|
|
122
109
|
type = 'undefined';
|
|
123
110
|
content = String(value);
|
|
124
|
-
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
125
111
|
}
|
|
126
112
|
if (typeof value === 'bigint') {
|
|
127
113
|
type = 'bigint';
|
|
128
114
|
content = "".concat(value, "n");
|
|
129
115
|
}
|
|
116
|
+
var isURL = value instanceof URL;
|
|
117
|
+
if (isURL) {
|
|
118
|
+
type = 'url';
|
|
119
|
+
content = "\"".concat(value.href, "\"");
|
|
120
|
+
}
|
|
130
121
|
if (typeof value === 'string') {
|
|
131
122
|
content = "\"".concat(value, "\"");
|
|
132
123
|
}
|
|
124
|
+
return {
|
|
125
|
+
type: type,
|
|
126
|
+
content: content
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function ValueView(props) {
|
|
130
|
+
var _typeMap$type;
|
|
131
|
+
var value = props.value,
|
|
132
|
+
keyName = props.keyName,
|
|
133
|
+
indentWidth = props.indentWidth,
|
|
134
|
+
renderKey = props.renderKey,
|
|
135
|
+
quotes = props.quotes,
|
|
136
|
+
renderValue = props.renderValue,
|
|
137
|
+
renderBraces = props.renderBraces,
|
|
138
|
+
enableClipboard = props.enableClipboard,
|
|
139
|
+
displayObjectSize = props.displayObjectSize,
|
|
140
|
+
displayDataTypes = props.displayDataTypes,
|
|
141
|
+
reset = (0, _objectWithoutProperties2["default"])(props, _excluded2);
|
|
142
|
+
var color = '';
|
|
143
|
+
var style = {};
|
|
144
|
+
var _getValueString = getValueString(value),
|
|
145
|
+
type = _getValueString.type,
|
|
146
|
+
content = _getValueString.content;
|
|
147
|
+
var typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
|
|
148
|
+
type: type
|
|
149
|
+
});
|
|
150
|
+
if (value === null) {
|
|
151
|
+
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
152
|
+
style = {
|
|
153
|
+
fontWeight: 'bold'
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (value === undefined) {
|
|
157
|
+
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
158
|
+
}
|
|
159
|
+
var isURL = value instanceof URL;
|
|
133
160
|
if (!displayDataTypes) {
|
|
134
161
|
typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
|
|
135
162
|
}
|
|
@@ -163,14 +190,26 @@ function ValueView(props) {
|
|
|
163
190
|
color: color
|
|
164
191
|
}, style),
|
|
165
192
|
type: type,
|
|
193
|
+
value: value,
|
|
194
|
+
quotes: quotes,
|
|
195
|
+
keyName: keyName,
|
|
196
|
+
visible: showTools,
|
|
166
197
|
content: content,
|
|
167
|
-
children:
|
|
198
|
+
children: content
|
|
168
199
|
});
|
|
169
200
|
var valueView = reView ? reView : /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, {
|
|
170
201
|
color: color,
|
|
171
202
|
style: style,
|
|
172
203
|
className: "w-rjv-value",
|
|
173
|
-
children:
|
|
204
|
+
children: isURL ? /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
205
|
+
href: value.href,
|
|
206
|
+
style: {
|
|
207
|
+
color: color
|
|
208
|
+
},
|
|
209
|
+
target: "_blank",
|
|
210
|
+
rel: "noopener noreferrer",
|
|
211
|
+
children: content
|
|
212
|
+
}) : content
|
|
174
213
|
});
|
|
175
214
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, eventProps), {}, {
|
|
176
215
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
@@ -181,11 +220,11 @@ function ValueView(props) {
|
|
|
181
220
|
}
|
|
182
221
|
var length = Array.isArray(value) ? value.length : Object.keys(value).length;
|
|
183
222
|
var empty = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
184
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
223
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
185
224
|
render: renderBraces,
|
|
186
225
|
start: true,
|
|
187
226
|
isArray: Array.isArray(value)
|
|
188
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
227
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
189
228
|
render: renderBraces,
|
|
190
229
|
isArray: Array.isArray(value)
|
|
191
230
|
}), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_node.CountInfo, {
|
package/editor.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
3
|
+
declare module '@uiw/react-json-view/editor' {
|
|
4
|
+
import { JsonViewProps } from '@uiw/react-json-view';
|
|
5
|
+
type Option = {
|
|
6
|
+
value: string;
|
|
7
|
+
prevValue: string;
|
|
8
|
+
keyName: string | number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
12
|
+
onEdit?: (option: Option) => void;
|
|
13
|
+
}
|
|
14
|
+
const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
15
|
+
export default JsonViewEditor;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["style", "render"];
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
export var Ellipsis = _ref => {
|
|
6
|
+
var {
|
|
7
|
+
style,
|
|
8
|
+
render
|
|
9
|
+
} = _ref,
|
|
10
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
11
|
+
var styl = _extends({
|
|
12
|
+
cursor: 'pointer'
|
|
13
|
+
}, style);
|
|
14
|
+
var className = "w-rjv-ellipsis " + (props.className || '');
|
|
15
|
+
if (render) return render(_extends({
|
|
16
|
+
style: styl
|
|
17
|
+
}, props, {
|
|
18
|
+
className
|
|
19
|
+
}));
|
|
20
|
+
return /*#__PURE__*/_jsx("span", _extends({
|
|
21
|
+
className: className,
|
|
22
|
+
style: styl
|
|
23
|
+
}, props, {
|
|
24
|
+
children: "..."
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LabelProps } from '../value';
|
|
3
|
+
export interface MetaProps extends LabelProps {
|
|
4
|
+
isArray?: boolean;
|
|
5
|
+
start?: boolean;
|
|
6
|
+
render?: (props: Pick<MetaProps, 'start' | 'isArray' | 'className' | 'children'>) => JSX.Element;
|
|
7
|
+
}
|
|
8
|
+
export declare function Meta(props: MetaProps): JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["isArray", "start", "className", "render"];
|
|
4
|
+
import { Label } from '../value';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export function Meta(props) {
|
|
7
|
+
var {
|
|
8
|
+
isArray = false,
|
|
9
|
+
start = false,
|
|
10
|
+
className,
|
|
11
|
+
render
|
|
12
|
+
} = props,
|
|
13
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
14
|
+
var mark = isArray ? '[]' : '{}';
|
|
15
|
+
var cls = "w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-" + (start ? 'start' : 'end') + " " + (className || '');
|
|
16
|
+
var color = "var(--w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-color, #236a7c)";
|
|
17
|
+
if (render) return render(_extends({
|
|
18
|
+
isArray,
|
|
19
|
+
className: cls,
|
|
20
|
+
style: {
|
|
21
|
+
color
|
|
22
|
+
},
|
|
23
|
+
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
24
|
+
}, reset));
|
|
25
|
+
return /*#__PURE__*/_jsx(Label, _extends({
|
|
26
|
+
color: color,
|
|
27
|
+
className: cls
|
|
28
|
+
}, reset, {
|
|
29
|
+
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
30
|
+
}));
|
|
31
|
+
}
|
package/esm/copied.js
CHANGED
|
@@ -34,6 +34,7 @@ export function Copied(props) {
|
|
|
34
34
|
};
|
|
35
35
|
var defalutStyle = _extends({}, style, {
|
|
36
36
|
cursor: 'pointer',
|
|
37
|
+
verticalAlign: 'middle',
|
|
37
38
|
marginLeft: 5
|
|
38
39
|
});
|
|
39
40
|
var svgProps = _extends({
|
|
@@ -47,19 +48,19 @@ export function Copied(props) {
|
|
|
47
48
|
if (render) return render(_extends({}, props, svgProps));
|
|
48
49
|
if (copied) {
|
|
49
50
|
return /*#__PURE__*/_jsx("svg", _extends({
|
|
50
|
-
viewBox: "0 0
|
|
51
|
+
viewBox: "0 0 32 36"
|
|
51
52
|
}, svgProps, {
|
|
52
53
|
fill: "var(--w-rjv-copied-success-color, #28a745)",
|
|
53
54
|
children: /*#__PURE__*/_jsx("path", {
|
|
54
|
-
d: "M27.5,
|
|
55
|
+
d: "M27.5,33 L2.5,33 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,33 C0,34.4 1.1,36 2.5,36 L27.5,36 C28.9,36 30,34.4 30,33 L30,26.1114493 L27.5,28.4926435 L27.5,33 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 M28.5589286,16 L32,19.6 L21.0160714,30.5382252 L13.5303571,24.2571429 L17.1303571,20.6571429 L21.0160714,24.5428571 L28.5589286,16 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"
|
|
55
56
|
})
|
|
56
57
|
}));
|
|
57
58
|
}
|
|
58
59
|
return /*#__PURE__*/_jsx("svg", _extends({
|
|
59
|
-
viewBox: "0 0
|
|
60
|
+
viewBox: "0 0 32 36"
|
|
60
61
|
}, svgProps, {
|
|
61
62
|
children: /*#__PURE__*/_jsx("path", {
|
|
62
|
-
d: "M27.5,
|
|
63
|
+
d: "M27.5,33 L2.5,33 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,33 C0,34.4 1.1,36 2.5,36 L27.5,36 C28.9,36 30,34.4 30,33 L30,29 L27.5,29 L27.5,33 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,21.5 L22.5,16.5 L12.5,24 L22.5,31.5 L22.5,26.5 L32,26.5 L32,21.5 L22.5,21.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"
|
|
63
64
|
})
|
|
64
65
|
}));
|
|
65
66
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export var EditIcon = props => {
|
|
4
|
+
var {
|
|
5
|
+
style
|
|
6
|
+
} = props;
|
|
7
|
+
var defaultStyle = {
|
|
8
|
+
verticalAlign: 'middle',
|
|
9
|
+
display: 'inline-block',
|
|
10
|
+
cursor: 'pointer',
|
|
11
|
+
marginLeft: 5,
|
|
12
|
+
height: '1em',
|
|
13
|
+
width: '1em'
|
|
14
|
+
};
|
|
15
|
+
return /*#__PURE__*/_jsx("svg", _extends({
|
|
16
|
+
viewBox: "0 0 26 26",
|
|
17
|
+
fill: "var(--w-rjv-edit-color, currentColor)"
|
|
18
|
+
}, props, {
|
|
19
|
+
style: _extends({}, style, defaultStyle),
|
|
20
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
21
|
+
d: "M18,0 L7.74666667,0 C2.89333333,0 0,2.89333333 0,7.74666667 L0,17.9066667 C0,22.7733333 2.89333333,26 7.74666667,26 L18,26 C22.8533333,26 26.0001422,22.7733333 26.0001422,17.92 L26.0001422,7.74666667 C26.0133333,2.89333333 22.8533333,0 18,0 Z M11.9333333,20.68 C11.5466667,21.0666667 10.8133333,21.44 10.28,21.52 L7,21.9866667 C6.88,22 6.76,22.0133333 6.64,22.0133333 C6.09333333,22.0133333 5.58666667,21.8266667 5.22666667,21.4666667 C4.78666667,21.0266667 4.6,20.3866667 4.70666667,19.68 L5.17333333,16.4 C5.25333333,15.8533333 5.61333333,15.1333333 6.01333333,14.7466667 L11.96,8.8 C12.1719034,9.3972484 12.4397602,9.97314063 12.76,10.52 C12.8933333,10.7466667 13.04,10.96 13.16,11.12 C13.3066667,11.3466667 13.48,11.56 13.5866667,11.68 C13.6533333,11.7733333 13.7066667,11.84 13.7333333,11.8666667 C14.0666667,12.2666667 14.4533333,12.64 14.7866667,12.92 C14.88,13.0133333 14.9333333,13.0666667 14.96,13.08 C15.16,13.24 15.36,13.4 15.5333333,13.52 C15.7466667,13.68 15.96,13.8266667 16.1866667,13.9466667 C16.4533333,14.1066667 16.7466667,14.2533333 17.04,14.4 C17.3466667,14.5333333 17.6266667,14.6533333 17.9066667,14.7466667 L11.9333333,20.68 L11.9333333,20.68 Z M20.4933333,12.12 L19.2666667,13.36 C19.1887174,13.4373865 19.0831716,13.4805643 18.9733333,13.4800055 C18.9333333,13.4800055 18.88,13.4800055 18.8533333,13.4666667 C16.1309823,12.6775025 14.0024975,10.5490177 13.2133333,7.82666667 C13.1733333,7.68 13.2133333,7.52 13.32,7.42666667 L14.56,6.18666667 C16.5866667,4.16 18.52,4.2 20.5066667,6.18666667 C21.52,7.2 22.0133333,8.17333333 22.0133333,9.18666667 C22,10.1466667 21.5066667,11.1066667 20.4933333,12.12 L20.4933333,12.12 Z"
|
|
22
|
+
})
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { JsonViewProps } from '../';
|
|
3
|
+
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
4
|
+
/** Callback when value edit functionality */
|
|
5
|
+
onEdit?: (option: {
|
|
6
|
+
value: unknown;
|
|
7
|
+
oldValue: unknown;
|
|
8
|
+
keyName?: string | number;
|
|
9
|
+
parentName?: string | number;
|
|
10
|
+
type?: 'value' | 'key';
|
|
11
|
+
}) => void;
|
|
12
|
+
/** Whether enable edit feature. @default true */
|
|
13
|
+
editable?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
16
|
+
export default JsonViewEditor;
|