@uiw/react-json-view 1.5.1 → 1.7.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 +113 -15
- package/cjs/comps/ellipsis.d.ts +2 -0
- package/cjs/comps/ellipsis.js +6 -2
- package/cjs/comps/meta.d.ts +2 -1
- package/cjs/comps/meta.js +16 -9
- package/cjs/editor/countInfoExtra.d.ts +14 -0
- package/cjs/editor/countInfoExtra.js +58 -0
- package/cjs/editor/icon/add.d.ts +4 -0
- package/cjs/editor/icon/add.js +30 -0
- package/cjs/editor/index.d.ts +7 -1
- 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 +2 -3
- package/cjs/index.d.ts +13 -5
- package/cjs/index.js +1 -1
- package/cjs/node.js +40 -14
- package/cjs/semicolon.d.ts +3 -3
- package/cjs/value.d.ts +4 -3
- package/cjs/value.js +2 -1
- package/editor.d.ts +16 -1
- package/esm/comps/ellipsis.d.ts +2 -0
- package/esm/comps/ellipsis.js +7 -3
- package/esm/comps/meta.d.ts +2 -1
- package/esm/comps/meta.js +16 -9
- package/esm/editor/countInfoExtra.d.ts +14 -0
- package/esm/editor/countInfoExtra.js +38 -0
- package/esm/editor/icon/add.d.ts +4 -0
- package/esm/editor/icon/add.js +24 -0
- package/esm/editor/index.d.ts +7 -1
- 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 +2 -3
- package/esm/index.d.ts +13 -5
- package/esm/index.js +1 -1
- package/esm/node.js +34 -13
- package/esm/semicolon.d.ts +3 -3
- package/esm/value.d.ts +4 -3
- package/esm/value.js +1 -1
- 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),
|
|
@@ -149,6 +156,16 @@ function RooNode(props) {
|
|
|
149
156
|
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
150
157
|
});
|
|
151
158
|
}
|
|
159
|
+
var countInfo = /*#__PURE__*/(0, _jsxRuntime.jsxs)(CountInfo, {
|
|
160
|
+
children: [nameKeys.length, " items"]
|
|
161
|
+
});
|
|
162
|
+
if (components.countInfo) {
|
|
163
|
+
countInfo = components.countInfo({
|
|
164
|
+
count: nameKeys.length,
|
|
165
|
+
level: level,
|
|
166
|
+
visible: expand
|
|
167
|
+
}) || countInfo;
|
|
168
|
+
}
|
|
152
169
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
153
170
|
className: "".concat(className, " w-rjv-inner")
|
|
154
171
|
}, eventProps), {}, {
|
|
@@ -160,7 +177,7 @@ function RooNode(props) {
|
|
|
160
177
|
onClick: handle,
|
|
161
178
|
children: [arrowView, (typeof keyName === 'string' || typeof keyName === 'number') && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
162
179
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
|
|
163
|
-
value:
|
|
180
|
+
value: valueData,
|
|
164
181
|
quotes: quotes,
|
|
165
182
|
"data-keys": keyid,
|
|
166
183
|
render: components.objectKey,
|
|
@@ -171,20 +188,28 @@ function RooNode(props) {
|
|
|
171
188
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
172
189
|
start: true,
|
|
173
190
|
isArray: isArray,
|
|
191
|
+
level: level,
|
|
174
192
|
render: components.braces
|
|
175
193
|
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ellipsis.Ellipsis, {
|
|
176
|
-
render: components.ellipsis
|
|
194
|
+
render: components.ellipsis,
|
|
195
|
+
count: nameKeys.length,
|
|
196
|
+
level: level
|
|
177
197
|
}), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
178
198
|
isArray: isArray,
|
|
199
|
+
level: level,
|
|
179
200
|
render: components.braces
|
|
180
|
-
}), displayObjectSize &&
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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,
|
|
185
211
|
onCopied: onCopied,
|
|
186
|
-
components: components
|
|
187
|
-
showTools: showTools
|
|
212
|
+
render: components === null || components === void 0 ? void 0 : components.copied
|
|
188
213
|
})]
|
|
189
214
|
}), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
|
|
190
215
|
className: "w-rjv-content",
|
|
@@ -245,6 +270,7 @@ function RooNode(props) {
|
|
|
245
270
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
|
|
246
271
|
render: components.braces,
|
|
247
272
|
isArray: isArray,
|
|
273
|
+
level: level,
|
|
248
274
|
style: {
|
|
249
275
|
paddingLeft: 2,
|
|
250
276
|
display: 'inline-block'
|
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: {
|
|
@@ -53,6 +53,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
53
53
|
displayObjectSize: boolean;
|
|
54
54
|
enableClipboard: boolean;
|
|
55
55
|
indentWidth: number;
|
|
56
|
+
level?: number;
|
|
56
57
|
quotes?: JsonViewProps<T>['quotes'];
|
|
57
58
|
renderKey?: JSX.Element;
|
|
58
59
|
renderBraces?: MetaProps['render'];
|
package/cjs/value.js
CHANGED
|
@@ -18,7 +18,7 @@ var _meta = require("./comps/meta");
|
|
|
18
18
|
var _copied = require("./copied");
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
20
|
var _excluded = ["children", "style"],
|
|
21
|
-
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "quotes", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
21
|
+
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
22
22
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
23
23
|
var Line = function Line(props) {
|
|
24
24
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
|
|
@@ -133,6 +133,7 @@ function ValueView(props) {
|
|
|
133
133
|
indentWidth = props.indentWidth,
|
|
134
134
|
renderKey = props.renderKey,
|
|
135
135
|
quotes = props.quotes,
|
|
136
|
+
level = props.level,
|
|
136
137
|
renderValue = props.renderValue,
|
|
137
138
|
renderBraces = props.renderBraces,
|
|
138
139
|
enableClipboard = props.enableClipboard,
|
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;
|
package/esm/comps/ellipsis.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
2
|
export interface EllipsisProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
count: number;
|
|
4
|
+
level: number;
|
|
3
5
|
render?: (props: EllipsisProps) => JSX.Element;
|
|
4
6
|
}
|
|
5
7
|
export declare const Ellipsis: FC<PropsWithChildren<EllipsisProps>>;
|
package/esm/comps/ellipsis.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["style", "render"];
|
|
3
|
+
var _excluded = ["style", "render", "count", "level"];
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
export var Ellipsis = _ref => {
|
|
6
6
|
var {
|
|
7
7
|
style,
|
|
8
|
-
render
|
|
8
|
+
render,
|
|
9
|
+
count,
|
|
10
|
+
level
|
|
9
11
|
} = _ref,
|
|
10
12
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
11
13
|
var styl = _extends({
|
|
@@ -13,7 +15,9 @@ export var Ellipsis = _ref => {
|
|
|
13
15
|
}, style);
|
|
14
16
|
var className = "w-rjv-ellipsis " + (props.className || '');
|
|
15
17
|
if (render) return render(_extends({
|
|
16
|
-
style: styl
|
|
18
|
+
style: styl,
|
|
19
|
+
count,
|
|
20
|
+
level
|
|
17
21
|
}, props, {
|
|
18
22
|
className
|
|
19
23
|
}));
|
package/esm/comps/meta.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { LabelProps } from '../value';
|
|
|
3
3
|
export interface MetaProps extends LabelProps {
|
|
4
4
|
isArray?: boolean;
|
|
5
5
|
start?: boolean;
|
|
6
|
-
|
|
6
|
+
level?: number;
|
|
7
|
+
render?: (props: Pick<MetaProps, 'start' | 'level' | 'isArray' | 'className' | 'children'>) => JSX.Element;
|
|
7
8
|
}
|
|
8
9
|
export declare function Meta(props: MetaProps): JSX.Element;
|
package/esm/comps/meta.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["isArray", "start", "className", "render"];
|
|
3
|
+
var _excluded = ["isArray", "start", "level", "className", "render"];
|
|
4
4
|
import { Label } from '../value';
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
export function Meta(props) {
|
|
7
7
|
var {
|
|
8
8
|
isArray = false,
|
|
9
9
|
start = false,
|
|
10
|
+
level,
|
|
10
11
|
className,
|
|
11
12
|
render
|
|
12
13
|
} = props,
|
|
@@ -14,14 +15,20 @@ export function Meta(props) {
|
|
|
14
15
|
var mark = isArray ? '[]' : '{}';
|
|
15
16
|
var cls = "w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-" + (start ? 'start' : 'end') + " " + (className || '');
|
|
16
17
|
var color = "var(--w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-color, #236a7c)";
|
|
17
|
-
if (render)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
if (render) {
|
|
19
|
+
var viev = render(_extends({
|
|
20
|
+
isArray,
|
|
21
|
+
level,
|
|
22
|
+
className: cls,
|
|
23
|
+
style: {
|
|
24
|
+
color
|
|
25
|
+
},
|
|
26
|
+
children: start ? mark.charAt(0) : mark.charAt(1)
|
|
27
|
+
}, reset));
|
|
28
|
+
if (viev) {
|
|
29
|
+
return viev;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
25
32
|
return /*#__PURE__*/_jsx(Label, _extends({
|
|
26
33
|
color: color,
|
|
27
34
|
className: cls
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { CountInfoProps } from '../';
|
|
3
|
+
export interface CountInfoExtraProps<T> extends 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;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
value,
|
|
10
|
+
setValue,
|
|
11
|
+
onAdd
|
|
12
|
+
} = props;
|
|
13
|
+
if (!visible || !showTools) return null;
|
|
14
|
+
var click = /*#__PURE__*/function () {
|
|
15
|
+
var _ref = _asyncToGenerator(function* (event) {
|
|
16
|
+
event.stopPropagation();
|
|
17
|
+
var keyOrValue = 'AddKeyOrValue';
|
|
18
|
+
var isArray = Array.isArray(value);
|
|
19
|
+
var isAdd = isArray ? true : !(keyOrValue in value);
|
|
20
|
+
var result = isArray ? [...value, keyOrValue] : _extends({}, value, {
|
|
21
|
+
[keyOrValue]: undefined
|
|
22
|
+
});
|
|
23
|
+
if (onAdd) {
|
|
24
|
+
var maybeAdd = yield onAdd(keyOrValue, result, props.value, isAdd);
|
|
25
|
+
if (maybeAdd) {
|
|
26
|
+
setValue(result);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return function click(_x) {
|
|
31
|
+
return _ref.apply(this, arguments);
|
|
32
|
+
};
|
|
33
|
+
}();
|
|
34
|
+
var svgProps = {
|
|
35
|
+
onClick: click
|
|
36
|
+
};
|
|
37
|
+
return /*#__PURE__*/_jsx(AddIcon, _extends({}, svgProps));
|
|
38
|
+
}
|
|
@@ -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-edit-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,5 +1,6 @@
|
|
|
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
|
/** Callback when value edit functionality */
|
|
5
6
|
onEdit?: (option: {
|
|
@@ -9,6 +10,11 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
|
|
|
9
10
|
parentName?: string | number;
|
|
10
11
|
type?: 'value' | 'key';
|
|
11
12
|
}) => void;
|
|
13
|
+
/**
|
|
14
|
+
* When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
|
|
15
|
+
* @returns {boolean} Returning false from onAdd will prevent the change from being made.
|
|
16
|
+
*/
|
|
17
|
+
onAdd?: CountInfoExtraProps<T>['onAdd'];
|
|
12
18
|
/** Whether enable edit feature. @default true */
|
|
13
19
|
editable?: boolean;
|
|
14
20
|
}
|
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,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["type", "value", "keyName", "visible", "quotes", "style", "
|
|
3
|
+
var _excluded = ["type", "value", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onEdit"];
|
|
4
4
|
import { Fragment, useEffect, useRef, useState } from 'react';
|
|
5
5
|
import { getValueString, isFloat, Type, typeMap } from '../value';
|
|
6
6
|
import { EditIcon } from './icon/edit';
|
|
@@ -26,7 +26,6 @@ export function ReValue(props) {
|
|
|
26
26
|
visible,
|
|
27
27
|
quotes,
|
|
28
28
|
style,
|
|
29
|
-
content,
|
|
30
29
|
displayDataTypes,
|
|
31
30
|
editableValue,
|
|
32
31
|
onEdit
|
|
@@ -136,7 +135,7 @@ export function ReValue(props) {
|
|
|
136
135
|
show: typeStr === 'string'
|
|
137
136
|
}), /*#__PURE__*/_jsx("span", _extends({}, spanProps, {
|
|
138
137
|
ref: $edit,
|
|
139
|
-
"data-value":
|
|
138
|
+
"data-value": childStr,
|
|
140
139
|
children: typeof curentChild === 'string' ? curentChild : childStr
|
|
141
140
|
})), /*#__PURE__*/_jsx(Quotes, {
|
|
142
141
|
style: style,
|
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,6 +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'];
|
|
53
|
+
countInfo?: (props: CountInfoProps) => JSX.Element;
|
|
54
|
+
countInfoExtra?: (props: Omit<CountInfoExtraProps<T>, 'editable'>) => JSX.Element;
|
|
47
55
|
};
|
|
48
56
|
}
|
|
49
57
|
declare const JsonView: React.ForwardRefExoticComponent<Omit<JsonViewProps<object>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
package/esm/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
16
16
|
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
17
17
|
var defaultStyle = _extends({
|
|
18
18
|
lineHeight: 1.4,
|
|
19
|
-
fontFamily: 'monospace',
|
|
19
|
+
fontFamily: 'var(--w-rjv-font-family, Menlo, monospace)',
|
|
20
20
|
color: 'var(--w-rjv-color, #002b36)',
|
|
21
21
|
backgroundColor: 'var(--w-rjv-background-color, #00000000)'
|
|
22
22
|
}, style);
|
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;
|
|
@@ -117,6 +119,16 @@ export function RooNode(props) {
|
|
|
117
119
|
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
118
120
|
});
|
|
119
121
|
}
|
|
122
|
+
var countInfo = /*#__PURE__*/_jsxs(CountInfo, {
|
|
123
|
+
children: [nameKeys.length, " items"]
|
|
124
|
+
});
|
|
125
|
+
if (components.countInfo) {
|
|
126
|
+
countInfo = components.countInfo({
|
|
127
|
+
count: nameKeys.length,
|
|
128
|
+
level,
|
|
129
|
+
visible: expand
|
|
130
|
+
}) || countInfo;
|
|
131
|
+
}
|
|
120
132
|
return /*#__PURE__*/_jsxs("div", _extends({}, reset, {
|
|
121
133
|
className: className + " w-rjv-inner"
|
|
122
134
|
}, eventProps, {
|
|
@@ -128,7 +140,7 @@ export function RooNode(props) {
|
|
|
128
140
|
onClick: handle,
|
|
129
141
|
children: [arrowView, (typeof keyName === 'string' || typeof keyName === 'number') && /*#__PURE__*/_jsxs(Fragment, {
|
|
130
142
|
children: [/*#__PURE__*/_jsx(Semicolon, {
|
|
131
|
-
value:
|
|
143
|
+
value: valueData,
|
|
132
144
|
quotes: quotes,
|
|
133
145
|
"data-keys": keyid,
|
|
134
146
|
render: components.objectKey,
|
|
@@ -139,20 +151,28 @@ export function RooNode(props) {
|
|
|
139
151
|
}), /*#__PURE__*/_jsx(Meta, {
|
|
140
152
|
start: true,
|
|
141
153
|
isArray: isArray,
|
|
154
|
+
level: level,
|
|
142
155
|
render: components.braces
|
|
143
156
|
}), !expand && /*#__PURE__*/_jsx(Ellipsis, {
|
|
144
|
-
render: components.ellipsis
|
|
157
|
+
render: components.ellipsis,
|
|
158
|
+
count: nameKeys.length,
|
|
159
|
+
level: level
|
|
145
160
|
}), !expand && /*#__PURE__*/_jsx(Meta, {
|
|
146
161
|
isArray: isArray,
|
|
162
|
+
level: level,
|
|
147
163
|
render: components.braces
|
|
148
|
-
}), displayObjectSize &&
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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,
|
|
153
174
|
onCopied: onCopied,
|
|
154
|
-
components: components
|
|
155
|
-
showTools: showTools
|
|
175
|
+
render: components == null ? void 0 : components.copied
|
|
156
176
|
})]
|
|
157
177
|
}), expand && /*#__PURE__*/_jsx(Line, {
|
|
158
178
|
className: "w-rjv-content",
|
|
@@ -211,6 +231,7 @@ export function RooNode(props) {
|
|
|
211
231
|
children: /*#__PURE__*/_jsx(Meta, {
|
|
212
232
|
render: components.braces,
|
|
213
233
|
isArray: isArray,
|
|
234
|
+
level: level,
|
|
214
235
|
style: {
|
|
215
236
|
paddingLeft: 2,
|
|
216
237
|
display: 'inline-block'
|
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: {
|
|
@@ -53,6 +53,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
|
|
|
53
53
|
displayObjectSize: boolean;
|
|
54
54
|
enableClipboard: boolean;
|
|
55
55
|
indentWidth: number;
|
|
56
|
+
level?: number;
|
|
56
57
|
quotes?: JsonViewProps<T>['quotes'];
|
|
57
58
|
renderKey?: JSX.Element;
|
|
58
59
|
renderBraces?: MetaProps['render'];
|
package/esm/value.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
3
|
var _excluded = ["children", "style"],
|
|
4
|
-
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "quotes", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
4
|
+
_excluded2 = ["value", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
|
|
5
5
|
_excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
|
|
6
6
|
import { Fragment, forwardRef, useState } from 'react';
|
|
7
7
|
import { CountInfo } from './node';
|