@uiw/react-json-view 2.0.0-alpha.2 → 2.0.0-alpha.20
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 +146 -21
- package/basic.d.ts +3 -0
- package/cjs/Container.d.ts +2 -0
- package/cjs/Container.js +9 -4
- package/cjs/arrow/TriangleArrow.js +1 -1
- package/cjs/comps/Copied.d.ts +2 -3
- package/cjs/comps/Copied.js +27 -16
- package/cjs/comps/KeyValues.d.ts +2 -4
- package/cjs/comps/KeyValues.js +49 -24
- package/cjs/comps/NestedClose.js +3 -4
- package/cjs/comps/NestedOpen.d.ts +2 -3
- package/cjs/comps/NestedOpen.js +23 -17
- package/cjs/comps/Value.d.ts +1 -2
- package/cjs/comps/Value.js +16 -20
- package/cjs/editor/KeyName.d.ts +2 -0
- package/cjs/editor/KeyName.js +82 -0
- package/cjs/editor/index.d.ts +19 -0
- package/cjs/editor/index.js +44 -0
- package/cjs/editor/store.d.ts +28 -0
- package/cjs/editor/store.js +23 -0
- package/cjs/index.d.ts +5 -3
- package/cjs/index.js +11 -8
- package/cjs/section/Copied.d.ts +1 -1
- package/cjs/section/Copied.js +1 -2
- package/cjs/section/CountInfo.d.ts +10 -1
- package/cjs/section/CountInfo.js +42 -4
- package/cjs/section/CountInfoExtra.d.ts +10 -1
- package/cjs/section/CountInfoExtra.js +32 -4
- package/cjs/section/Ellipsis.d.ts +10 -0
- package/cjs/section/Ellipsis.js +30 -4
- package/cjs/section/KeyName.d.ts +8 -0
- package/cjs/section/KeyName.js +40 -4
- package/cjs/section/Row.d.ts +14 -0
- package/cjs/section/Row.js +51 -0
- package/cjs/store/Expands.js +2 -4
- package/cjs/store/Section.d.ts +12 -6
- package/cjs/store/Section.js +6 -4
- package/cjs/store/ShowTools.js +2 -4
- package/cjs/store/Symbols.d.ts +2 -2
- package/cjs/store/Symbols.js +2 -4
- package/cjs/store/Types.d.ts +28 -24
- package/cjs/store/Types.js +8 -8
- package/cjs/store.d.ts +7 -4
- package/cjs/store.js +5 -10
- package/cjs/symbol/Arrow.d.ts +1 -1
- package/cjs/symbol/Arrow.js +1 -2
- package/cjs/symbol/BraceLeft.d.ts +1 -1
- package/cjs/symbol/BraceLeft.js +1 -2
- package/cjs/symbol/BraceRight.d.ts +1 -1
- package/cjs/symbol/BraceRight.js +1 -2
- package/cjs/symbol/BracketsLeft.d.ts +1 -1
- package/cjs/symbol/BracketsLeft.js +1 -2
- package/cjs/symbol/BracketsRight.d.ts +1 -1
- package/cjs/symbol/BracketsRight.js +1 -2
- package/cjs/symbol/Colon.d.ts +1 -1
- package/cjs/symbol/Colon.js +1 -2
- package/cjs/symbol/Quote.d.ts +1 -1
- package/cjs/symbol/Quote.js +1 -2
- package/cjs/symbol/ValueQuote.d.ts +1 -1
- package/cjs/symbol/ValueQuote.js +1 -2
- package/{esm/comps/ReRender/Symbols.d.ts → cjs/symbol/index.d.ts} +4 -6
- package/cjs/{comps/ReRender/Symbols.js → symbol/index.js} +32 -33
- package/cjs/theme/basic.js +4 -3
- package/cjs/theme/dark.js +2 -3
- package/cjs/theme/github.dark.js +2 -3
- package/cjs/theme/github.light.js +2 -3
- package/cjs/theme/gruvbox.js +2 -3
- package/cjs/theme/light.js +2 -3
- package/cjs/theme/monokai.js +2 -3
- package/cjs/theme/nord.js +2 -3
- package/cjs/theme/vscode.js +2 -3
- package/cjs/types/Bigint.d.ts +1 -1
- package/cjs/types/Bigint.js +1 -2
- package/cjs/types/Date.d.ts +1 -1
- package/cjs/types/Date.js +1 -2
- package/cjs/types/False.d.ts +1 -1
- package/cjs/types/False.js +1 -2
- package/cjs/types/Float.d.ts +1 -1
- package/cjs/types/Float.js +1 -2
- package/cjs/types/Int.d.ts +1 -1
- package/cjs/types/Int.js +1 -2
- package/cjs/types/Map.d.ts +1 -1
- package/cjs/types/Map.js +1 -2
- package/cjs/types/Nan.d.ts +1 -1
- package/cjs/types/Nan.js +1 -2
- package/cjs/types/Null.d.ts +1 -1
- package/cjs/types/Null.js +1 -2
- package/cjs/types/Set.d.ts +1 -1
- package/cjs/types/Set.js +1 -2
- package/cjs/types/String.d.ts +1 -1
- package/cjs/types/String.js +1 -2
- package/cjs/types/True.d.ts +1 -1
- package/cjs/types/True.js +1 -2
- package/cjs/types/Undefined.d.ts +1 -1
- package/cjs/types/Undefined.js +1 -2
- package/cjs/types/Url.d.ts +1 -1
- package/cjs/types/Url.js +1 -2
- package/{esm/comps/ReRender/Types.d.ts → cjs/types/index.d.ts} +2 -2
- package/cjs/{comps/ReRender/Types.js → types/index.js} +92 -171
- package/cjs/utils/useHighlight.js +0 -1
- package/cjs/utils/useRender.d.ts +1 -1
- package/editor.d.ts +22 -20
- package/esm/Container.d.ts +2 -0
- package/esm/Container.js +9 -2
- package/esm/arrow/TriangleArrow.js +1 -1
- package/esm/comps/Copied.d.ts +2 -3
- package/esm/comps/Copied.js +27 -15
- package/esm/comps/KeyValues.d.ts +2 -4
- package/esm/comps/KeyValues.js +36 -13
- package/esm/comps/NestedClose.js +1 -1
- package/esm/comps/NestedOpen.d.ts +2 -3
- package/esm/comps/NestedOpen.js +17 -10
- package/esm/comps/Value.d.ts +1 -2
- package/esm/comps/Value.js +3 -5
- package/esm/editor/KeyName.d.ts +2 -0
- package/esm/editor/KeyName.js +77 -0
- package/esm/editor/index.d.ts +19 -0
- package/esm/editor/index.js +34 -0
- package/esm/editor/store.d.ts +28 -0
- package/esm/editor/store.js +13 -0
- package/esm/index.d.ts +5 -3
- package/esm/index.js +8 -4
- package/esm/section/Copied.d.ts +1 -1
- package/esm/section/CountInfo.d.ts +10 -1
- package/esm/section/CountInfo.js +43 -1
- package/esm/section/CountInfoExtra.d.ts +10 -1
- package/esm/section/CountInfoExtra.js +32 -1
- package/esm/section/Ellipsis.d.ts +10 -0
- package/esm/section/Ellipsis.js +31 -1
- package/esm/section/KeyName.d.ts +8 -0
- package/esm/section/KeyName.js +41 -1
- package/esm/section/Row.d.ts +14 -0
- package/esm/section/Row.js +47 -0
- package/esm/store/Section.d.ts +12 -6
- package/esm/store/Section.js +4 -0
- package/esm/store/Symbols.d.ts +2 -2
- package/esm/store/Types.d.ts +28 -24
- package/esm/store/Types.js +6 -4
- package/esm/store.d.ts +7 -4
- package/esm/symbol/Arrow.d.ts +1 -1
- package/esm/symbol/BraceLeft.d.ts +1 -1
- package/esm/symbol/BraceRight.d.ts +1 -1
- package/esm/symbol/BracketsLeft.d.ts +1 -1
- package/esm/symbol/BracketsRight.d.ts +1 -1
- package/esm/symbol/Colon.d.ts +1 -1
- package/esm/symbol/Quote.d.ts +1 -1
- package/esm/symbol/ValueQuote.d.ts +1 -1
- package/{cjs/comps/ReRender/Symbols.d.ts → esm/symbol/index.d.ts} +4 -6
- package/esm/{comps/ReRender/Symbols.js → symbol/index.js} +26 -24
- package/esm/theme/basic.js +2 -0
- package/esm/types/Bigint.d.ts +1 -1
- package/esm/types/Date.d.ts +1 -1
- package/esm/types/False.d.ts +1 -1
- package/esm/types/Float.d.ts +1 -1
- package/esm/types/Int.d.ts +1 -1
- package/esm/types/Map.d.ts +1 -1
- package/esm/types/Nan.d.ts +1 -1
- package/esm/types/Null.d.ts +1 -1
- package/esm/types/Set.d.ts +1 -1
- package/esm/types/String.d.ts +1 -1
- package/esm/types/True.d.ts +1 -1
- package/esm/types/Undefined.d.ts +1 -1
- package/esm/types/Url.d.ts +1 -1
- package/{cjs/comps/ReRender/Types.d.ts → esm/types/index.d.ts} +2 -2
- package/esm/{comps/ReRender/Types.js → types/index.js} +75 -146
- package/esm/utils/useHighlight.js +0 -1
- package/esm/utils/useRender.d.ts +1 -1
- package/githubDark.d.ts +3 -0
- package/githubLight.d.ts +3 -0
- package/gruvbox.d.ts +3 -0
- package/monokai.d.ts +3 -0
- package/nord.d.ts +3 -0
- package/package.json +11 -5
- package/vscode.d.ts +3 -0
- package/cjs/comps/CountInfo.d.ts +0 -19
- package/cjs/comps/CountInfo.js +0 -72
- package/cjs/comps/Ellipsis.d.ts +0 -10
- package/cjs/comps/Ellipsis.js +0 -35
- package/cjs/comps/Key.d.ts +0 -7
- package/cjs/comps/Key.js +0 -41
- package/esm/comps/CountInfo.d.ts +0 -19
- package/esm/comps/CountInfo.js +0 -70
- package/esm/comps/Ellipsis.d.ts +0 -10
- package/esm/comps/Ellipsis.js +0 -31
- package/esm/comps/Key.d.ts +0 -7
- package/esm/comps/Key.js +0 -37
package/esm/Container.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 = ["className", "children", "parentValue", "keyid", "level", "value", "initialValue", "keyName"];
|
|
3
|
+
var _excluded = ["className", "children", "parentValue", "keyid", "level", "value", "initialValue", "keys", "keyName"];
|
|
4
4
|
import React, { forwardRef, useId } from 'react';
|
|
5
5
|
import { NestedClose } from './comps/NestedClose';
|
|
6
6
|
import { NestedOpen } from './comps/NestedOpen';
|
|
@@ -11,9 +11,11 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
export var Container = /*#__PURE__*/forwardRef((props, ref) => {
|
|
12
12
|
var {
|
|
13
13
|
className = '',
|
|
14
|
+
parentValue,
|
|
14
15
|
level = 1,
|
|
15
16
|
value,
|
|
16
17
|
initialValue,
|
|
18
|
+
keys,
|
|
17
19
|
keyName
|
|
18
20
|
} = props,
|
|
19
21
|
elmProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
@@ -36,12 +38,17 @@ export var Container = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
36
38
|
expandKey: subkeyid,
|
|
37
39
|
value: value,
|
|
38
40
|
level: level,
|
|
41
|
+
keys: keys,
|
|
42
|
+
parentValue: parentValue,
|
|
39
43
|
keyName: keyName,
|
|
40
44
|
initialValue: initialValue
|
|
41
45
|
}), /*#__PURE__*/_jsx(KeyValues, {
|
|
42
46
|
expandKey: subkeyid,
|
|
43
47
|
value: value,
|
|
44
|
-
level: level
|
|
48
|
+
level: level,
|
|
49
|
+
keys: keys,
|
|
50
|
+
parentValue: parentValue,
|
|
51
|
+
keyName: keyName
|
|
45
52
|
}), /*#__PURE__*/_jsx(NestedClose, {
|
|
46
53
|
expandKey: subkeyid,
|
|
47
54
|
value: value,
|
package/esm/comps/Copied.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type TagType } from '../store/Types';
|
|
3
|
+
import { type SectionElementResult } from '../store/Section';
|
|
3
4
|
export type CopiedOption<T extends object> = {
|
|
4
5
|
value?: T;
|
|
5
6
|
copied: boolean;
|
|
6
7
|
setCopied: React.Dispatch<React.SetStateAction<boolean>>;
|
|
7
8
|
};
|
|
8
|
-
export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement> {
|
|
9
|
-
value?: T;
|
|
10
|
-
keyName: string | number;
|
|
9
|
+
export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement>, SectionElementResult<T> {
|
|
11
10
|
expandKey: string;
|
|
12
11
|
}
|
|
13
12
|
export declare const Copied: {
|
package/esm/comps/Copied.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 = ["keyName", "value", "expandKey"],
|
|
3
|
+
var _excluded = ["keyName", "value", "parentValue", "expandKey", "keys"],
|
|
4
4
|
_excluded2 = ["as", "render"];
|
|
5
5
|
import { useState } from 'react';
|
|
6
6
|
import { useStore } from '../store';
|
|
@@ -11,7 +11,9 @@ export var Copied = props => {
|
|
|
11
11
|
var {
|
|
12
12
|
keyName,
|
|
13
13
|
value,
|
|
14
|
-
|
|
14
|
+
parentValue,
|
|
15
|
+
expandKey,
|
|
16
|
+
keys
|
|
15
17
|
} = props,
|
|
16
18
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
17
19
|
var {
|
|
@@ -27,18 +29,21 @@ export var Copied = props => {
|
|
|
27
29
|
if (enableClipboard === false || !isShowTools) return null;
|
|
28
30
|
var click = event => {
|
|
29
31
|
event.stopPropagation();
|
|
30
|
-
var copyText =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
32
|
+
var copyText = '';
|
|
33
|
+
if (typeof value === 'number' && value === Infinity) {
|
|
34
|
+
copyText = 'Infinity';
|
|
35
|
+
} else if (typeof value === 'number' && isNaN(value)) {
|
|
36
|
+
copyText = 'NaN';
|
|
37
|
+
} else if (typeof value === 'bigint') {
|
|
38
|
+
copyText = value + 'n';
|
|
39
|
+
} else if (value instanceof Date) {
|
|
40
|
+
copyText = value.toLocaleString();
|
|
41
|
+
} else {
|
|
42
|
+
copyText = JSON.stringify(value, null, 2);
|
|
43
|
+
}
|
|
44
|
+
onCopied && onCopied(copyText, value);
|
|
45
|
+
setCopied(true);
|
|
39
46
|
navigator.clipboard.writeText(copyText).then(() => {
|
|
40
|
-
onCopied && onCopied(copyText, value);
|
|
41
|
-
setCopied(true);
|
|
42
47
|
var timer = setTimeout(() => {
|
|
43
48
|
setCopied(false);
|
|
44
49
|
clearTimeout(timer);
|
|
@@ -46,6 +51,9 @@ export var Copied = props => {
|
|
|
46
51
|
}).catch(error => {});
|
|
47
52
|
};
|
|
48
53
|
var svgProps = {
|
|
54
|
+
style: {
|
|
55
|
+
display: 'inline-flex'
|
|
56
|
+
},
|
|
49
57
|
fill: copied ? 'var(--w-rjv-copied-success-color, #28a745)' : 'var(--w-rjv-copied-color, currentColor)',
|
|
50
58
|
onClick: click
|
|
51
59
|
};
|
|
@@ -53,13 +61,17 @@ export var Copied = props => {
|
|
|
53
61
|
render
|
|
54
62
|
} = Comp,
|
|
55
63
|
reset = _objectWithoutPropertiesLoose(Comp, _excluded2);
|
|
56
|
-
var elmProps = _extends({}, reset, other, svgProps
|
|
64
|
+
var elmProps = _extends({}, reset, other, svgProps, {
|
|
65
|
+
style: _extends({}, reset.style, other.style, svgProps.style)
|
|
66
|
+
});
|
|
57
67
|
var isRender = render && typeof render === 'function';
|
|
58
68
|
var child = isRender && render(_extends({}, elmProps, {
|
|
59
69
|
'data-copied': copied
|
|
60
70
|
}), {
|
|
61
71
|
value,
|
|
62
|
-
keyName
|
|
72
|
+
keyName,
|
|
73
|
+
keys,
|
|
74
|
+
parentValue
|
|
63
75
|
});
|
|
64
76
|
if (child) return child;
|
|
65
77
|
if (copied) {
|
package/esm/comps/KeyValues.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value?: T;
|
|
4
|
-
parentValue?: T;
|
|
1
|
+
import { type SectionElementResult } from '../store/Section';
|
|
2
|
+
interface KeyValuesProps<T extends object> extends SectionElementResult<T> {
|
|
5
3
|
expandKey?: string;
|
|
6
4
|
level: number;
|
|
7
5
|
}
|
package/esm/comps/KeyValues.js
CHANGED
|
@@ -4,10 +4,12 @@ import { useStore } from '../store';
|
|
|
4
4
|
import { useExpandsStore } from '../store/Expands';
|
|
5
5
|
import { useShowToolsDispatch } from '../store/ShowTools';
|
|
6
6
|
import { Value } from './Value';
|
|
7
|
-
import {
|
|
7
|
+
import { KeyNameComp } from '../section/KeyName';
|
|
8
|
+
import { RowComp } from '../section/Row';
|
|
8
9
|
import { Container } from '../Container';
|
|
9
|
-
import { Quote, Colon } from '
|
|
10
|
+
import { Quote, Colon } from '../symbol';
|
|
10
11
|
import { useHighlight } from '../utils/useHighlight';
|
|
12
|
+
import { Copied } from '../comps/Copied';
|
|
11
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
15
|
export var KeyValues = props => {
|
|
@@ -15,7 +17,8 @@ export var KeyValues = props => {
|
|
|
15
17
|
var {
|
|
16
18
|
value,
|
|
17
19
|
expandKey = '',
|
|
18
|
-
level
|
|
20
|
+
level,
|
|
21
|
+
keys = []
|
|
19
22
|
} = props;
|
|
20
23
|
var expands = useExpandsStore();
|
|
21
24
|
var {
|
|
@@ -36,9 +39,9 @@ export var KeyValues = props => {
|
|
|
36
39
|
var [b] = _ref2;
|
|
37
40
|
return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
|
|
38
41
|
}) : entries.sort((_ref3, _ref4) => {
|
|
39
|
-
var [a] = _ref3;
|
|
40
|
-
var [b] = _ref4;
|
|
41
|
-
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
42
|
+
var [a, valA] = _ref3;
|
|
43
|
+
var [b, valB] = _ref4;
|
|
44
|
+
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b, valA, valB) : 0;
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
var style = {
|
|
@@ -54,6 +57,7 @@ export var KeyValues = props => {
|
|
|
54
57
|
return /*#__PURE__*/_jsx(KeyValuesItem, {
|
|
55
58
|
parentValue: value,
|
|
56
59
|
keyName: key,
|
|
60
|
+
keys: [...keys, key],
|
|
57
61
|
value: val,
|
|
58
62
|
level: level
|
|
59
63
|
}, idx);
|
|
@@ -64,6 +68,8 @@ KeyValues.displayName = 'JVR.KeyValues';
|
|
|
64
68
|
export var KayName = props => {
|
|
65
69
|
var {
|
|
66
70
|
keyName,
|
|
71
|
+
parentValue,
|
|
72
|
+
keys,
|
|
67
73
|
value
|
|
68
74
|
} = props;
|
|
69
75
|
var {
|
|
@@ -80,13 +86,17 @@ export var KayName = props => {
|
|
|
80
86
|
children: [/*#__PURE__*/_jsxs("span", {
|
|
81
87
|
ref: highlightContainer,
|
|
82
88
|
children: [/*#__PURE__*/_jsx(Quote, {
|
|
83
|
-
isNumber: isNumber
|
|
84
|
-
|
|
89
|
+
isNumber: isNumber,
|
|
90
|
+
"data-placement": "left"
|
|
91
|
+
}), /*#__PURE__*/_jsx(KeyNameComp, {
|
|
85
92
|
keyName: keyName,
|
|
86
93
|
value: value,
|
|
94
|
+
keys: keys,
|
|
95
|
+
parentValue: parentValue,
|
|
87
96
|
children: keyName
|
|
88
97
|
}), /*#__PURE__*/_jsx(Quote, {
|
|
89
|
-
isNumber: isNumber
|
|
98
|
+
isNumber: isNumber,
|
|
99
|
+
"data-placement": "right"
|
|
90
100
|
})]
|
|
91
101
|
}), /*#__PURE__*/_jsx(Colon, {})]
|
|
92
102
|
});
|
|
@@ -97,7 +107,8 @@ export var KeyValuesItem = props => {
|
|
|
97
107
|
keyName,
|
|
98
108
|
value,
|
|
99
109
|
parentValue,
|
|
100
|
-
level = 0
|
|
110
|
+
level = 0,
|
|
111
|
+
keys = []
|
|
101
112
|
} = props;
|
|
102
113
|
var dispatch = useShowToolsDispatch();
|
|
103
114
|
var subkeyid = useId();
|
|
@@ -115,6 +126,7 @@ export var KeyValuesItem = props => {
|
|
|
115
126
|
value: myValue,
|
|
116
127
|
parentValue: parentValue,
|
|
117
128
|
initialValue: value,
|
|
129
|
+
keys: keys,
|
|
118
130
|
level: level + 1
|
|
119
131
|
});
|
|
120
132
|
}
|
|
@@ -126,15 +138,26 @@ export var KeyValuesItem = props => {
|
|
|
126
138
|
[subkeyid]: false
|
|
127
139
|
})
|
|
128
140
|
};
|
|
129
|
-
return /*#__PURE__*/_jsxs(
|
|
130
|
-
className: "w-rjv-line"
|
|
141
|
+
return /*#__PURE__*/_jsxs(RowComp, _extends({
|
|
142
|
+
className: "w-rjv-line",
|
|
143
|
+
value: value,
|
|
144
|
+
keyName: keyName,
|
|
145
|
+
keys: keys,
|
|
146
|
+
parentValue: parentValue
|
|
131
147
|
}, reset, {
|
|
132
148
|
children: [/*#__PURE__*/_jsx(KayName, {
|
|
133
149
|
keyName: keyName,
|
|
134
|
-
value: value
|
|
150
|
+
value: value,
|
|
151
|
+
keys: keys,
|
|
152
|
+
parentValue: parentValue
|
|
135
153
|
}), /*#__PURE__*/_jsx(Value, {
|
|
154
|
+
keyName: keyName,
|
|
155
|
+
value: value
|
|
156
|
+
}), /*#__PURE__*/_jsx(Copied, {
|
|
136
157
|
keyName: keyName,
|
|
137
158
|
value: value,
|
|
159
|
+
keys: keys,
|
|
160
|
+
parentValue: parentValue,
|
|
138
161
|
expandKey: subkeyid
|
|
139
162
|
})]
|
|
140
163
|
}));
|
package/esm/comps/NestedClose.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useStore } from '../store';
|
|
2
2
|
import { useExpandsStore } from '../store/Expands';
|
|
3
|
-
import { BracketsClose } from '
|
|
3
|
+
import { BracketsClose } from '../symbol';
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
export var NestedClose = props => {
|
|
6
6
|
var _expands$expandKey;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value?: T;
|
|
1
|
+
import { type SectionElementResult } from '../store/Section';
|
|
2
|
+
export interface NestedOpenProps<T extends object> extends SectionElementResult<T> {
|
|
4
3
|
initialValue?: T;
|
|
5
4
|
expandKey: string;
|
|
6
5
|
level: number;
|
package/esm/comps/NestedOpen.js
CHANGED
|
@@ -3,10 +3,11 @@ import { KayName } from './KeyValues';
|
|
|
3
3
|
import { useExpandsStore, useExpandsDispatch } from '../store/Expands';
|
|
4
4
|
import { useStore } from '../store';
|
|
5
5
|
import { Copied } from './Copied';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { CountInfoExtraComps } from '../section/CountInfoExtra';
|
|
7
|
+
import { CountInfoComp } from '../section/CountInfo';
|
|
8
|
+
import { Arrow, BracketsOpen, BracketsClose } from '../symbol';
|
|
9
|
+
import { EllipsisComp } from '../section/Ellipsis';
|
|
10
|
+
import { SetComp, MapComp } from '../types';
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
13
|
export var NestedOpen = props => {
|
|
@@ -14,8 +15,10 @@ export var NestedOpen = props => {
|
|
|
14
15
|
var {
|
|
15
16
|
keyName,
|
|
16
17
|
expandKey,
|
|
18
|
+
keys,
|
|
17
19
|
initialValue,
|
|
18
20
|
value,
|
|
21
|
+
parentValue,
|
|
19
22
|
level
|
|
20
23
|
} = props;
|
|
21
24
|
var expands = useExpandsStore();
|
|
@@ -63,28 +66,32 @@ export var NestedOpen = props => {
|
|
|
63
66
|
}), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, {
|
|
64
67
|
keyName: keyName
|
|
65
68
|
}), /*#__PURE__*/_jsx(SetComp, {
|
|
66
|
-
value: initialValue
|
|
69
|
+
value: initialValue,
|
|
70
|
+
keyName: keyName
|
|
67
71
|
}), /*#__PURE__*/_jsx(MapComp, {
|
|
68
|
-
value: initialValue
|
|
72
|
+
value: initialValue,
|
|
73
|
+
keyName: keyName
|
|
69
74
|
}), /*#__PURE__*/_jsx(BracketsOpen, {
|
|
70
75
|
isBrackets: isArray || isMySet
|
|
71
|
-
}), /*#__PURE__*/_jsx(
|
|
76
|
+
}), /*#__PURE__*/_jsx(EllipsisComp, {
|
|
72
77
|
keyName: keyName,
|
|
73
78
|
value: value,
|
|
74
79
|
isExpanded: isExpanded
|
|
75
80
|
}), /*#__PURE__*/_jsx(BracketsClose, {
|
|
76
81
|
isVisiable: isExpanded || !showArrow,
|
|
77
82
|
isBrackets: isArray || isMySet
|
|
78
|
-
}), /*#__PURE__*/_jsx(
|
|
83
|
+
}), /*#__PURE__*/_jsx(CountInfoComp, {
|
|
79
84
|
value: value,
|
|
80
85
|
keyName: keyName
|
|
81
|
-
}), /*#__PURE__*/_jsx(
|
|
86
|
+
}), /*#__PURE__*/_jsx(CountInfoExtraComps, {
|
|
82
87
|
value: value,
|
|
83
88
|
keyName: keyName
|
|
84
89
|
}), /*#__PURE__*/_jsx(Copied, {
|
|
85
90
|
keyName: keyName,
|
|
86
91
|
value: value,
|
|
87
|
-
expandKey: expandKey
|
|
92
|
+
expandKey: expandKey,
|
|
93
|
+
parentValue: parentValue,
|
|
94
|
+
keys: keys
|
|
88
95
|
})]
|
|
89
96
|
}));
|
|
90
97
|
};
|
package/esm/comps/Value.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export declare const isFloat: (n: number) => boolean;
|
|
2
2
|
interface ValueProps {
|
|
3
|
-
value
|
|
3
|
+
value: unknown;
|
|
4
4
|
keyName: string | number;
|
|
5
|
-
expandKey: string;
|
|
6
5
|
}
|
|
7
6
|
export declare const Value: {
|
|
8
7
|
(props: ValueProps): import("react/jsx-runtime").JSX.Element | null;
|
package/esm/comps/Value.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import { TypeString, TypeTrue, TypeNull, TypeFalse, TypeFloat, TypeBigint, TypeInt, TypeDate, TypeUndefined, TypeNan, TypeUrl } from '
|
|
2
|
+
import { TypeString, TypeTrue, TypeNull, TypeFalse, TypeFloat, TypeBigint, TypeInt, TypeDate, TypeUndefined, TypeNan, TypeUrl } from '../types';
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
export var isFloat = n => Number(n) === n && n % 1 !== 0 || isNaN(n);
|
|
5
5
|
export var Value = props => {
|
|
6
6
|
var {
|
|
7
7
|
value,
|
|
8
|
-
keyName
|
|
9
|
-
expandKey
|
|
8
|
+
keyName
|
|
10
9
|
} = props;
|
|
11
10
|
var reset = {
|
|
12
|
-
keyName
|
|
13
|
-
expandKey
|
|
11
|
+
keyName
|
|
14
12
|
};
|
|
15
13
|
if (value instanceof URL) {
|
|
16
14
|
return /*#__PURE__*/_jsx(TypeUrl, _extends({}, reset, {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["children"],
|
|
4
|
+
_excluded2 = ["value", "parentValue", "keyName"];
|
|
5
|
+
import { useRef, useState } from 'react';
|
|
6
|
+
import { useStore } from './store';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export var KeyNameRender = (_ref, _ref2) => {
|
|
9
|
+
var {
|
|
10
|
+
children
|
|
11
|
+
} = _ref,
|
|
12
|
+
reset = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
+
var {
|
|
14
|
+
value,
|
|
15
|
+
parentValue,
|
|
16
|
+
keyName
|
|
17
|
+
} = _ref2;
|
|
18
|
+
if (typeof children === 'number') {
|
|
19
|
+
return /*#__PURE__*/_jsx("span", _extends({}, reset, {
|
|
20
|
+
children: children
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
return /*#__PURE__*/_jsx(Child, _extends({}, reset, {
|
|
24
|
+
value: value,
|
|
25
|
+
parentValue: parentValue,
|
|
26
|
+
keyName: keyName,
|
|
27
|
+
children: children
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
var Child = props => {
|
|
31
|
+
var {
|
|
32
|
+
value,
|
|
33
|
+
keyName
|
|
34
|
+
} = props,
|
|
35
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
36
|
+
var $dom = useRef(null);
|
|
37
|
+
var [currentValue, setCurrentValue] = useState(props.children);
|
|
38
|
+
var {
|
|
39
|
+
onEdit
|
|
40
|
+
} = useStore();
|
|
41
|
+
var onKeyDown = evn => {
|
|
42
|
+
if (evn.key === 'Enter') {
|
|
43
|
+
var _$dom$current;
|
|
44
|
+
(_$dom$current = $dom.current) == null || _$dom$current.setAttribute('contentEditable', 'false');
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var onClick = evn => {
|
|
48
|
+
var _$dom$current2, _$dom$current3;
|
|
49
|
+
evn.stopPropagation();
|
|
50
|
+
(_$dom$current2 = $dom.current) == null || _$dom$current2.setAttribute('contentEditable', 'true');
|
|
51
|
+
(_$dom$current3 = $dom.current) == null || _$dom$current3.focus();
|
|
52
|
+
};
|
|
53
|
+
var onBlur = evn => {
|
|
54
|
+
var _$dom$current4;
|
|
55
|
+
(_$dom$current4 = $dom.current) == null || _$dom$current4.setAttribute('contentEditable', 'false');
|
|
56
|
+
var callback = onEdit && onEdit({
|
|
57
|
+
value: evn.target.textContent,
|
|
58
|
+
oldValue: value,
|
|
59
|
+
keyName
|
|
60
|
+
});
|
|
61
|
+
if (callback) {
|
|
62
|
+
setCurrentValue(evn.target.textContent);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var spanProps = _extends({}, reset, {
|
|
66
|
+
onKeyDown,
|
|
67
|
+
onClick,
|
|
68
|
+
onBlur,
|
|
69
|
+
spellCheck: false,
|
|
70
|
+
contentEditable: 'false',
|
|
71
|
+
suppressContentEditableWarning: true,
|
|
72
|
+
children: currentValue
|
|
73
|
+
});
|
|
74
|
+
return /*#__PURE__*/_jsx("span", _extends({}, spanProps, {
|
|
75
|
+
ref: $dom
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type JsonViewProps } from '../';
|
|
3
|
+
export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
|
|
4
|
+
/**
|
|
5
|
+
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
6
|
+
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
7
|
+
*/
|
|
8
|
+
onEdit?: (option: {
|
|
9
|
+
value: unknown;
|
|
10
|
+
oldValue: unknown;
|
|
11
|
+
keyName?: string | number;
|
|
12
|
+
parentName?: string | number;
|
|
13
|
+
type?: 'value' | 'key';
|
|
14
|
+
}) => boolean;
|
|
15
|
+
/** Whether enable edit feature. @default true */
|
|
16
|
+
editable?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
19
|
+
export default JsonViewEditor;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["children", "onEdit", "editable"];
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import JsonView from '../';
|
|
6
|
+
import { KeyNameRender } from './KeyName';
|
|
7
|
+
import { Context, Dispatch, useStoreReducer } from './store';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
11
|
+
var {
|
|
12
|
+
children,
|
|
13
|
+
onEdit,
|
|
14
|
+
editable = true
|
|
15
|
+
} = props,
|
|
16
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
17
|
+
var [state, dispatch] = useStoreReducer({
|
|
18
|
+
onEdit
|
|
19
|
+
});
|
|
20
|
+
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
21
|
+
value: state,
|
|
22
|
+
children: /*#__PURE__*/_jsx(Dispatch.Provider, {
|
|
23
|
+
value: dispatch,
|
|
24
|
+
children: /*#__PURE__*/_jsxs(JsonView, _extends({}, reset, {
|
|
25
|
+
shortenTextAfterLength: 0,
|
|
26
|
+
ref: ref,
|
|
27
|
+
children: [editable && /*#__PURE__*/_jsx(JsonView.KeyName, {
|
|
28
|
+
render: KeyNameRender
|
|
29
|
+
}), children]
|
|
30
|
+
}))
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
export default JsonViewEditor;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
type InitialState = {
|
|
3
|
+
/**
|
|
4
|
+
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
5
|
+
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
6
|
+
*/
|
|
7
|
+
onEdit?: (option: {
|
|
8
|
+
value: unknown;
|
|
9
|
+
oldValue: unknown;
|
|
10
|
+
keyName?: string | number;
|
|
11
|
+
parentName?: string | number;
|
|
12
|
+
type?: 'value' | 'key';
|
|
13
|
+
}) => boolean;
|
|
14
|
+
};
|
|
15
|
+
type Dispatch = React.Dispatch<InitialState>;
|
|
16
|
+
export declare const Context: import("react").Context<InitialState>;
|
|
17
|
+
export declare const Dispatch: import("react").Context<Dispatch>;
|
|
18
|
+
export declare const useStore: () => InitialState;
|
|
19
|
+
export declare function useStoreReducer(initialState: InitialState): [{
|
|
20
|
+
onEdit?: ((option: {
|
|
21
|
+
value: unknown;
|
|
22
|
+
oldValue: unknown;
|
|
23
|
+
keyName?: string | number | undefined;
|
|
24
|
+
parentName?: string | number | undefined;
|
|
25
|
+
type?: "value" | "key" | undefined;
|
|
26
|
+
}) => boolean) | undefined;
|
|
27
|
+
}, import("react").Dispatch<InitialState>];
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import { createContext, useContext, useReducer } from 'react';
|
|
3
|
+
var initialState = {};
|
|
4
|
+
export var Context = /*#__PURE__*/createContext(initialState);
|
|
5
|
+
var reducer = (state, action) => _extends({}, state, action);
|
|
6
|
+
export var Dispatch = /*#__PURE__*/createContext(() => {});
|
|
7
|
+
Dispatch.displayName = 'JVR.Editor.Dispatch';
|
|
8
|
+
export var useStore = () => {
|
|
9
|
+
return useContext(Context);
|
|
10
|
+
};
|
|
11
|
+
export function useStoreReducer(initialState) {
|
|
12
|
+
return useReducer(reducer, initialState);
|
|
13
|
+
}
|
package/esm/index.d.ts
CHANGED
|
@@ -25,19 +25,20 @@ import { CountInfo } from './section/CountInfo';
|
|
|
25
25
|
import { CountInfoExtra } from './section/CountInfoExtra';
|
|
26
26
|
import { Ellipsis } from './section/Ellipsis';
|
|
27
27
|
import { KeyName } from './section/KeyName';
|
|
28
|
+
import { Row } from './section/Row';
|
|
28
29
|
export * from './store';
|
|
29
30
|
export * from './store/Expands';
|
|
30
31
|
export * from './store/ShowTools';
|
|
31
32
|
export * from './store/Symbols';
|
|
32
33
|
export * from './store/Types';
|
|
33
|
-
export * from './
|
|
34
|
+
export * from './symbol';
|
|
34
35
|
export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
35
36
|
/** This property contains your input JSON */
|
|
36
37
|
value?: T;
|
|
37
38
|
/** Define the root node name. @default undefined */
|
|
38
39
|
keyName?: string | number;
|
|
39
40
|
/** Whether sort keys through `String.prototype.localeCompare()` @default false */
|
|
40
|
-
objectSortKeys?: boolean | ((
|
|
41
|
+
objectSortKeys?: boolean | ((keyA: string, keyB: string, valueA: T, valueB: T) => number);
|
|
41
42
|
/** Set the indent-width for nested objects @default 15 */
|
|
42
43
|
indentWidth?: number;
|
|
43
44
|
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
|
|
@@ -50,7 +51,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
50
51
|
collapsed?: boolean | number;
|
|
51
52
|
/** Whether to highlight updates. @default true */
|
|
52
53
|
highlightUpdates?: boolean;
|
|
53
|
-
/** Shorten long JSON strings, Set to `0` to disable this feature @default
|
|
54
|
+
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
|
|
54
55
|
shortenTextAfterLength?: number;
|
|
55
56
|
/** Callback function for when a treeNode is expanded or collapsed */
|
|
56
57
|
onExpand?: (props: {
|
|
@@ -89,6 +90,7 @@ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
|
|
|
89
90
|
CountInfo: typeof CountInfo;
|
|
90
91
|
CountInfoExtra: typeof CountInfoExtra;
|
|
91
92
|
KeyName: typeof KeyName;
|
|
93
|
+
Row: typeof Row;
|
|
92
94
|
};
|
|
93
95
|
declare const JsonView: JsonViewComponent;
|
|
94
96
|
export default JsonView;
|