@uiw/react-json-view 1.6.0 → 1.7.1
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 +51 -21
- package/cjs/editor/countInfoExtra.d.ts +14 -0
- package/cjs/editor/countInfoExtra.js +60 -0
- package/cjs/editor/icon/add.d.ts +4 -0
- package/cjs/editor/icon/add.js +30 -0
- package/cjs/editor/index.d.ts +12 -3
- package/cjs/editor/index.js +9 -1
- package/cjs/editor/objectKey.d.ts +2 -2
- package/cjs/editor/value.d.ts +1 -1
- package/cjs/editor/value.js +99 -63
- package/cjs/index.d.ts +13 -10
- package/cjs/node.js +24 -11
- package/cjs/semicolon.d.ts +3 -3
- package/cjs/value.d.ts +3 -3
- package/editor.d.ts +16 -1
- package/esm/editor/countInfoExtra.d.ts +14 -0
- package/esm/editor/countInfoExtra.js +40 -0
- package/esm/editor/icon/add.d.ts +4 -0
- package/esm/editor/icon/add.js +24 -0
- package/esm/editor/index.d.ts +12 -3
- package/esm/editor/index.js +8 -2
- package/esm/editor/objectKey.d.ts +2 -2
- package/esm/editor/value.d.ts +1 -1
- package/esm/editor/value.js +74 -58
- package/esm/index.d.ts +13 -10
- package/esm/node.js +18 -10
- package/esm/semicolon.d.ts +3 -3
- package/esm/value.d.ts +3 -3
- package/package.json +1 -1
- package/cjs/tools.d.ts +0 -10
- package/cjs/tools.js +0 -24
- package/esm/tools.d.ts +0 -10
- package/esm/tools.js +0 -20
package/cjs/node.js
CHANGED
|
@@ -15,7 +15,7 @@ var _value = require("./value");
|
|
|
15
15
|
var _TriangleArrow = require("./arrow/TriangleArrow");
|
|
16
16
|
var _store = require("./store");
|
|
17
17
|
var _semicolon = require("./semicolon");
|
|
18
|
-
var
|
|
18
|
+
var _copied = require("./copied");
|
|
19
19
|
var _ellipsis = require("./comps/ellipsis");
|
|
20
20
|
var _meta = require("./comps/meta");
|
|
21
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -126,14 +126,21 @@ function RooNode(props) {
|
|
|
126
126
|
return setShowTools(false);
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
var
|
|
129
|
+
var _useState3 = (0, _react.useState)(value),
|
|
130
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
131
|
+
valueData = _useState4[0],
|
|
132
|
+
setValueData = _useState4[1];
|
|
133
|
+
(0, _react.useEffect)(function () {
|
|
134
|
+
return setValueData(value);
|
|
135
|
+
}, [value]);
|
|
136
|
+
var nameKeys = isArray ? Object.keys(valueData).map(function (m) {
|
|
130
137
|
return Number(m);
|
|
131
|
-
}) : Object.keys(
|
|
138
|
+
}) : Object.keys(valueData);
|
|
132
139
|
|
|
133
140
|
// object
|
|
134
|
-
var entries = isArray ? Object.entries(
|
|
141
|
+
var entries = isArray ? Object.entries(valueData).map(function (m) {
|
|
135
142
|
return [Number(m[0]), m[1]];
|
|
136
|
-
}) : Object.entries(
|
|
143
|
+
}) : Object.entries(valueData);
|
|
137
144
|
if (objectSortKeys) {
|
|
138
145
|
entries = objectSortKeys === true ? entries.sort(function (_ref2, _ref3) {
|
|
139
146
|
var _ref4 = (0, _slicedToArray2["default"])(_ref2, 1),
|
|
@@ -170,7 +177,7 @@ function RooNode(props) {
|
|
|
170
177
|
onClick: handle,
|
|
171
178
|
children: [arrowView, (typeof keyName === 'string' || typeof keyName === 'number') && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
172
179
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
|
|
173
|
-
value:
|
|
180
|
+
value: valueData,
|
|
174
181
|
quotes: quotes,
|
|
175
182
|
"data-keys": keyid,
|
|
176
183
|
render: components.objectKey,
|
|
@@ -191,12 +198,18 @@ function RooNode(props) {
|
|
|
191
198
|
isArray: isArray,
|
|
192
199
|
level: level,
|
|
193
200
|
render: components.braces
|
|
194
|
-
}), displayObjectSize && countInfo,
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
}), displayObjectSize && countInfo, components.countInfoExtra && components.countInfoExtra({
|
|
202
|
+
count: nameKeys.length,
|
|
203
|
+
level: level,
|
|
204
|
+
showTools: showTools,
|
|
205
|
+
visible: expand,
|
|
206
|
+
value: valueData,
|
|
207
|
+
setValue: setValueData
|
|
208
|
+
}), enableClipboard && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
|
|
209
|
+
show: showTools,
|
|
210
|
+
text: valueData,
|
|
197
211
|
onCopied: onCopied,
|
|
198
|
-
components: components
|
|
199
|
-
showTools: showTools
|
|
212
|
+
render: components === null || components === void 0 ? void 0 : components.copied
|
|
200
213
|
})]
|
|
201
214
|
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
202
215
|
className: "w-rjv-content",
|
package/cjs/semicolon.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import { LabelProps } from './value';
|
|
3
|
-
import { JsonViewProps } from './';
|
|
1
|
+
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import type { LabelProps } from './value';
|
|
3
|
+
import type { JsonViewProps } from './';
|
|
4
4
|
export declare function usePrevious<T>(value: T): T | undefined;
|
|
5
5
|
interface UseHighlight {
|
|
6
6
|
value: any;
|
package/cjs/value.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import { MetaProps } from './comps/meta';
|
|
3
|
-
import { JsonViewProps } from './';
|
|
1
|
+
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import type { MetaProps } from './comps/meta';
|
|
3
|
+
import type { JsonViewProps } from './';
|
|
4
4
|
export declare const Line: FC<PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>>;
|
|
5
5
|
export declare const isFloat: (n: number) => boolean;
|
|
6
6
|
export declare const typeMap: {
|
package/editor.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
declare module '@uiw/react-json-view/editor' {
|
|
4
4
|
import { JsonViewProps } from '@uiw/react-json-view';
|
|
5
|
+
import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
|
|
5
6
|
type Option = {
|
|
6
7
|
value: string;
|
|
7
8
|
prevValue: string;
|
|
@@ -9,7 +10,21 @@ declare module '@uiw/react-json-view/editor' {
|
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
12
|
-
|
|
13
|
+
/** Callback when value edit functionality */
|
|
14
|
+
onEdit?: (option: {
|
|
15
|
+
value: unknown;
|
|
16
|
+
oldValue: unknown;
|
|
17
|
+
keyName?: string | number;
|
|
18
|
+
parentName?: string | number;
|
|
19
|
+
type?: 'value' | 'key';
|
|
20
|
+
}) => void;
|
|
21
|
+
/**
|
|
22
|
+
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
23
|
+
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
24
|
+
*/
|
|
25
|
+
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
26
|
+
/** Whether enable edit feature. @default true */
|
|
27
|
+
editable?: boolean;
|
|
13
28
|
}
|
|
14
29
|
const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
15
30
|
export default JsonViewEditor;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { CountInfoProps } from '../';
|
|
3
|
+
export interface CountInfoExtraProps<T> extends Partial<CountInfoProps> {
|
|
4
|
+
editable: boolean;
|
|
5
|
+
showTools: boolean;
|
|
6
|
+
value: T;
|
|
7
|
+
setValue?: React.Dispatch<React.SetStateAction<T>>;
|
|
8
|
+
/**
|
|
9
|
+
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
10
|
+
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
11
|
+
*/
|
|
12
|
+
onAdd?: (keyOrValue: string, newValue: T, value: T, isAdd: boolean) => boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function CountInfoExtra<T extends object>(props: CountInfoExtraProps<T>): import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { AddIcon } from './icon/add';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
export function CountInfoExtra(props) {
|
|
6
|
+
var {
|
|
7
|
+
visible,
|
|
8
|
+
showTools,
|
|
9
|
+
editable,
|
|
10
|
+
value,
|
|
11
|
+
setValue,
|
|
12
|
+
onAdd
|
|
13
|
+
} = props;
|
|
14
|
+
if (!visible || !showTools) return null;
|
|
15
|
+
var click = /*#__PURE__*/function () {
|
|
16
|
+
var _ref = _asyncToGenerator(function* (event) {
|
|
17
|
+
event.stopPropagation();
|
|
18
|
+
var keyOrValue = 'AddKeyOrValue';
|
|
19
|
+
var isArray = Array.isArray(value);
|
|
20
|
+
var isAdd = isArray ? true : !(keyOrValue in value);
|
|
21
|
+
var result = isArray ? [...value, keyOrValue] : _extends({}, value, {
|
|
22
|
+
[keyOrValue]: undefined
|
|
23
|
+
});
|
|
24
|
+
if (onAdd) {
|
|
25
|
+
var maybeAdd = yield onAdd(keyOrValue, result, props.value, isAdd);
|
|
26
|
+
if (maybeAdd) {
|
|
27
|
+
setValue(result);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return function click(_x) {
|
|
32
|
+
return _ref.apply(this, arguments);
|
|
33
|
+
};
|
|
34
|
+
}();
|
|
35
|
+
var svgProps = {
|
|
36
|
+
onClick: click
|
|
37
|
+
};
|
|
38
|
+
if (!editable || !onAdd) return;
|
|
39
|
+
return /*#__PURE__*/_jsx(AddIcon, _extends({}, svgProps));
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export var AddIcon = 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 20 20",
|
|
17
|
+
fill: "var(--w-rjv-add-color, currentColor)"
|
|
18
|
+
}, props, {
|
|
19
|
+
style: _extends({}, style, defaultStyle),
|
|
20
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
21
|
+
d: "M14.1970498,0 L5.81288651,0 C2.17107809,0 0,2.17 0,5.81 L0,14.18 C0,17.83 2.17107809,20 5.81288651,20 L14.1870449,20 C17.8288533,20 19.9999658,17.83 19.9999658,14.19 L19.9999658,5.81 C20.0099363,2.17 17.8388583,0 14.1970498,0 Z M16.0079491,10.75 L10.7553408,10.75 L10.7553408,16 C10.7553408,16.41 10.4151719,16.75 10.0049682,16.75 C9.59476448,16.75 9.25459556,16.41 9.25459556,16 L9.25459556,10.75 L4.00198727,10.75 C3.59178357,10.75 3.25161466,10.41 3.25161466,10 C3.25161466,9.59 3.59178357,9.25 4.00198727,9.25 L9.25459556,9.25 L9.25459556,4 C9.25459556,3.59 9.59476448,3.25 10.0049682,3.25 C10.4151719,3.25 10.7553408,3.59 10.7553408,4 L10.7553408,9.25 L16.0079491,9.25 C16.4181528,9.25 16.7583217,9.59 16.7583217,10 C16.7583217,10.41 16.4181528,10.75 16.0079491,10.75 Z"
|
|
22
|
+
})
|
|
23
|
+
}));
|
|
24
|
+
};
|
package/esm/editor/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { JsonViewProps } from '../';
|
|
2
|
+
import type { JsonViewProps } from '../';
|
|
3
|
+
import type { CountInfoExtraProps } from './countInfoExtra';
|
|
3
4
|
export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
|
|
4
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
7
|
+
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
8
|
+
*/
|
|
5
9
|
onEdit?: (option: {
|
|
6
10
|
value: unknown;
|
|
7
11
|
oldValue: unknown;
|
|
8
12
|
keyName?: string | number;
|
|
9
13
|
parentName?: string | number;
|
|
10
14
|
type?: 'value' | 'key';
|
|
11
|
-
}) =>
|
|
15
|
+
}) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
18
|
+
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
19
|
+
*/
|
|
20
|
+
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
12
21
|
/** Whether enable edit feature. @default true */
|
|
13
22
|
editable?: boolean;
|
|
14
23
|
}
|
package/esm/editor/index.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["onEdit", "components", "editable", "displayDataTypes"];
|
|
3
|
+
var _excluded = ["onEdit", "components", "editable", "displayDataTypes", "onAdd"];
|
|
4
4
|
import { forwardRef } from 'react';
|
|
5
5
|
import JsonView from '../';
|
|
6
6
|
import { ObjectKey } from './objectKey';
|
|
7
7
|
import { ReValue } from './value';
|
|
8
|
+
import { CountInfoExtra } from './countInfoExtra';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
10
11
|
var {
|
|
11
12
|
onEdit,
|
|
12
13
|
components,
|
|
13
14
|
editable = true,
|
|
14
|
-
displayDataTypes = true
|
|
15
|
+
displayDataTypes = true,
|
|
16
|
+
onAdd
|
|
15
17
|
} = props,
|
|
16
18
|
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
17
19
|
var comps = _extends({}, components, {
|
|
20
|
+
countInfoExtra: reprops => /*#__PURE__*/_jsx(CountInfoExtra, _extends({}, reprops, {
|
|
21
|
+
editable: editable,
|
|
22
|
+
onAdd: onAdd
|
|
23
|
+
})),
|
|
18
24
|
objectKey: reprops => /*#__PURE__*/_jsx(ObjectKey, _extends({}, reprops, {
|
|
19
25
|
editableValue: editable,
|
|
20
26
|
onEdit: onEdit,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { SemicolonProps } from '../semicolon';
|
|
3
|
-
import { JsonViewEditorProps } from './';
|
|
2
|
+
import type { SemicolonProps } from '../semicolon';
|
|
3
|
+
import type { JsonViewEditorProps } from './';
|
|
4
4
|
export interface ObjectKeyProps<T extends object> extends SemicolonProps {
|
|
5
5
|
onEdit?: JsonViewEditorProps<T>['onEdit'];
|
|
6
6
|
render?: (props: SemicolonProps & {
|
package/esm/editor/value.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { TypeProps } from '../value';
|
|
3
|
-
import { JsonViewEditorProps } from './';
|
|
3
|
+
import type { JsonViewEditorProps } from './';
|
|
4
4
|
export interface ReValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
|
|
5
5
|
onEdit?: JsonViewEditorProps<T>['onEdit'];
|
|
6
6
|
quotes?: JsonViewEditorProps<T>['quotes'];
|
package/esm/editor/value.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
4
|
var _excluded = ["type", "value", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onEdit"];
|
|
4
5
|
import { Fragment, useEffect, useRef, useState } from 'react';
|
|
@@ -55,51 +56,68 @@ export function ReValue(props) {
|
|
|
55
56
|
$edit.current.contentEditable = 'false';
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
|
-
var blur = ()
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
$edit.current
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
59
|
+
var blur = /*#__PURE__*/function () {
|
|
60
|
+
var _ref2 = _asyncToGenerator(function* () {
|
|
61
|
+
if (!editableValue) return;
|
|
62
|
+
setEditable(false);
|
|
63
|
+
if ($edit.current) {
|
|
64
|
+
$edit.current.contentEditable = 'false';
|
|
65
|
+
var text = $edit.current.innerText;
|
|
66
|
+
var _typeStr = curentType;
|
|
67
|
+
if (curentType === 'number' || curentType === 'float') {
|
|
68
|
+
text = Number(text);
|
|
69
|
+
_typeStr = isFloat(text) ? 'float' : 'number';
|
|
70
|
+
}
|
|
71
|
+
if (curentType === 'url' && typeof text === 'string') {
|
|
72
|
+
text = new URL(text);
|
|
73
|
+
_typeStr = 'url';
|
|
74
|
+
}
|
|
75
|
+
if (Number.isNaN(text)) {
|
|
76
|
+
_typeStr = 'number';
|
|
77
|
+
}
|
|
78
|
+
if (typeof text === 'string' && /^(true|false)$/ig.test(text)) {
|
|
79
|
+
text = /^(true)$/ig.test(text) ? true : false;
|
|
80
|
+
_typeStr = 'boolean';
|
|
81
|
+
} else if (typeof text === 'string' && /^[\d]+n$/ig.test(text)) {
|
|
82
|
+
text = BigInt(text.replace(/n$/ig, ''));
|
|
83
|
+
_typeStr = 'bigint';
|
|
84
|
+
} else if (typeof text === 'string' && /^(null)$/ig.test(text)) {
|
|
85
|
+
text = null;
|
|
86
|
+
_typeStr = 'null';
|
|
87
|
+
} else if (typeof text === 'string' && /^(undefined)$/ig.test(text)) {
|
|
88
|
+
text = undefined;
|
|
89
|
+
_typeStr = 'undefined';
|
|
90
|
+
} else if (typeof text === 'string') {
|
|
91
|
+
try {
|
|
92
|
+
if (text && text.length > 10 && !isNaN(Date.parse(text))) {
|
|
93
|
+
var dt = new Date(text);
|
|
94
|
+
text = dt;
|
|
95
|
+
_typeStr = 'date';
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {}
|
|
98
|
+
}
|
|
99
|
+
if (onEdit) {
|
|
100
|
+
var result = yield onEdit({
|
|
101
|
+
type: 'value',
|
|
102
|
+
value: text,
|
|
103
|
+
oldValue: curentChild
|
|
104
|
+
});
|
|
105
|
+
if (result) {
|
|
106
|
+
setCurentType(_typeStr);
|
|
107
|
+
setCurentChild(text);
|
|
108
|
+
} else {
|
|
109
|
+
var {
|
|
110
|
+
content: oldChildStr
|
|
111
|
+
} = getValueString(curentChild);
|
|
112
|
+
$edit.current.innerHTML = String(oldChildStr);
|
|
92
113
|
}
|
|
93
|
-
}
|
|
114
|
+
}
|
|
94
115
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
};
|
|
116
|
+
});
|
|
117
|
+
return function blur() {
|
|
118
|
+
return _ref2.apply(this, arguments);
|
|
119
|
+
};
|
|
120
|
+
}();
|
|
103
121
|
var defaultStyle = {
|
|
104
122
|
minWidth: 34,
|
|
105
123
|
minHeight: 18,
|
|
@@ -128,21 +146,19 @@ export function ReValue(props) {
|
|
|
128
146
|
typeView = /*#__PURE__*/_jsx(Fragment, {});
|
|
129
147
|
}
|
|
130
148
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
131
|
-
children: [displayDataTypes && typeView, /*#__PURE__*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
})]
|
|
145
|
-
}), visible && editableValue && /*#__PURE__*/_jsx(EditIcon, {
|
|
149
|
+
children: [displayDataTypes && typeView, /*#__PURE__*/_jsx(Quotes, {
|
|
150
|
+
style: style,
|
|
151
|
+
quotes: quotes,
|
|
152
|
+
show: typeStr === 'string'
|
|
153
|
+
}), /*#__PURE__*/_jsx("span", _extends({}, spanProps, {
|
|
154
|
+
ref: $edit,
|
|
155
|
+
"data-value": childStr,
|
|
156
|
+
children: typeof curentChild === 'string' ? curentChild : childStr
|
|
157
|
+
})), /*#__PURE__*/_jsx(Quotes, {
|
|
158
|
+
style: style,
|
|
159
|
+
quotes: quotes,
|
|
160
|
+
show: typeStr === 'string'
|
|
161
|
+
}), visible && editableValue && onEdit && /*#__PURE__*/_jsx(EditIcon, {
|
|
146
162
|
onClick: click
|
|
147
163
|
})]
|
|
148
164
|
});
|
package/esm/index.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SemicolonProps } from './semicolon';
|
|
3
|
-
import { ValueViewProps } from './value';
|
|
4
|
-
import { CopiedProps } from './copied';
|
|
5
|
-
import { EllipsisProps } from './comps/ellipsis';
|
|
6
|
-
import { MetaProps } from './comps/meta';
|
|
2
|
+
import type { SemicolonProps } from './semicolon';
|
|
3
|
+
import type { ValueViewProps } from './value';
|
|
4
|
+
import type { CopiedProps } from './copied';
|
|
5
|
+
import type { EllipsisProps } from './comps/ellipsis';
|
|
6
|
+
import type { MetaProps } from './comps/meta';
|
|
7
|
+
import type { CountInfoExtraProps } from './editor/countInfoExtra';
|
|
7
8
|
export * from './node';
|
|
8
9
|
export * from './value';
|
|
10
|
+
export interface CountInfoProps {
|
|
11
|
+
count: number;
|
|
12
|
+
level: number;
|
|
13
|
+
visible: boolean;
|
|
14
|
+
}
|
|
9
15
|
export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
10
16
|
/** This property contains your input JSON */
|
|
11
17
|
value?: T;
|
|
@@ -44,11 +50,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
44
50
|
objectKey?: SemicolonProps['render'];
|
|
45
51
|
value?: ValueViewProps<T>['renderValue'];
|
|
46
52
|
copied?: CopiedProps<T>['render'];
|
|
47
|
-
countInfo?: (props:
|
|
48
|
-
|
|
49
|
-
level: number;
|
|
50
|
-
visible: boolean;
|
|
51
|
-
}) => JSX.Element;
|
|
53
|
+
countInfo?: (props: CountInfoProps) => JSX.Element;
|
|
54
|
+
countInfoExtra?: (props: Omit<CountInfoExtraProps<T>, 'editable'>) => JSX.Element;
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
57
|
declare const JsonView: React.ForwardRefExoticComponent<Omit<JsonViewProps<object>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
package/esm/node.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
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';
|
|
4
|
+
import { Fragment, useId, cloneElement, useState, useEffect } from 'react';
|
|
5
5
|
import { ValueView, Colon, Label, Line, typeMap } from './value';
|
|
6
6
|
import { TriangleArrow } from './arrow/TriangleArrow';
|
|
7
7
|
import { useExpandsStatus, store } from './store';
|
|
8
8
|
import { Semicolon } from './semicolon';
|
|
9
|
-
import {
|
|
9
|
+
import { Copied } from './copied';
|
|
10
10
|
import { Ellipsis } from './comps/ellipsis';
|
|
11
11
|
import { Meta } from './comps/meta';
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -102,10 +102,12 @@ export function RooNode(props) {
|
|
|
102
102
|
eventProps.onMouseEnter = () => setShowTools(true);
|
|
103
103
|
eventProps.onMouseLeave = () => setShowTools(false);
|
|
104
104
|
}
|
|
105
|
-
var
|
|
105
|
+
var [valueData, setValueData] = useState(value);
|
|
106
|
+
useEffect(() => setValueData(value), [value]);
|
|
107
|
+
var nameKeys = isArray ? Object.keys(valueData).map(m => Number(m)) : Object.keys(valueData);
|
|
106
108
|
|
|
107
109
|
// object
|
|
108
|
-
var entries = isArray ? Object.entries(
|
|
110
|
+
var entries = isArray ? Object.entries(valueData).map(m => [Number(m[0]), m[1]]) : Object.entries(valueData);
|
|
109
111
|
if (objectSortKeys) {
|
|
110
112
|
entries = objectSortKeys === true ? entries.sort((_ref2, _ref3) => {
|
|
111
113
|
var [a] = _ref2;
|
|
@@ -138,7 +140,7 @@ export function RooNode(props) {
|
|
|
138
140
|
onClick: handle,
|
|
139
141
|
children: [arrowView, (typeof keyName === 'string' || typeof keyName === 'number') && /*#__PURE__*/_jsxs(Fragment, {
|
|
140
142
|
children: [/*#__PURE__*/_jsx(Semicolon, {
|
|
141
|
-
value:
|
|
143
|
+
value: valueData,
|
|
142
144
|
quotes: quotes,
|
|
143
145
|
"data-keys": keyid,
|
|
144
146
|
render: components.objectKey,
|
|
@@ -159,12 +161,18 @@ export function RooNode(props) {
|
|
|
159
161
|
isArray: isArray,
|
|
160
162
|
level: level,
|
|
161
163
|
render: components.braces
|
|
162
|
-
}), displayObjectSize && countInfo,
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
}), displayObjectSize && countInfo, components.countInfoExtra && components.countInfoExtra({
|
|
165
|
+
count: nameKeys.length,
|
|
166
|
+
level,
|
|
167
|
+
showTools,
|
|
168
|
+
visible: expand,
|
|
169
|
+
value: valueData,
|
|
170
|
+
setValue: setValueData
|
|
171
|
+
}), enableClipboard && /*#__PURE__*/_jsx(Copied, {
|
|
172
|
+
show: showTools,
|
|
173
|
+
text: valueData,
|
|
165
174
|
onCopied: onCopied,
|
|
166
|
-
components: components
|
|
167
|
-
showTools: showTools
|
|
175
|
+
render: components == null ? void 0 : components.copied
|
|
168
176
|
})]
|
|
169
177
|
}), expand && /*#__PURE__*/_jsx(Line, {
|
|
170
178
|
className: "w-rjv-content",
|
package/esm/semicolon.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import { LabelProps } from './value';
|
|
3
|
-
import { JsonViewProps } from './';
|
|
1
|
+
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import type { LabelProps } from './value';
|
|
3
|
+
import type { JsonViewProps } from './';
|
|
4
4
|
export declare function usePrevious<T>(value: T): T | undefined;
|
|
5
5
|
interface UseHighlight {
|
|
6
6
|
value: any;
|
package/esm/value.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import { MetaProps } from './comps/meta';
|
|
3
|
-
import { JsonViewProps } from './';
|
|
1
|
+
import type { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import type { MetaProps } from './comps/meta';
|
|
3
|
+
import type { JsonViewProps } from './';
|
|
4
4
|
export declare const Line: FC<PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>>;
|
|
5
5
|
export declare const isFloat: (n: number) => boolean;
|
|
6
6
|
export declare const typeMap: {
|
package/package.json
CHANGED
package/cjs/tools.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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/esm/tools.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|