@uiw/react-json-view 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +29 -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 +10 -4
- 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 +37 -15
- package/esm/comps/NestedClose.js +1 -1
- package/esm/comps/NestedOpen.d.ts +2 -3
- package/esm/comps/NestedOpen.js +18 -12
- 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 +33 -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 +9 -6
- 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} +76 -148
- 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,19 +1,20 @@
|
|
|
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';
|
|
7
7
|
import { KeyValues } from './comps/KeyValues';
|
|
8
8
|
import { useShowToolsDispatch } from './store/ShowTools';
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
10
|
export var Container = /*#__PURE__*/forwardRef((props, ref) => {
|
|
12
11
|
var {
|
|
13
12
|
className = '',
|
|
13
|
+
parentValue,
|
|
14
14
|
level = 1,
|
|
15
15
|
value,
|
|
16
16
|
initialValue,
|
|
17
|
+
keys,
|
|
17
18
|
keyName
|
|
18
19
|
} = props,
|
|
19
20
|
elmProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
@@ -36,12 +37,17 @@ export var Container = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
36
37
|
expandKey: subkeyid,
|
|
37
38
|
value: value,
|
|
38
39
|
level: level,
|
|
40
|
+
keys: keys,
|
|
41
|
+
parentValue: parentValue,
|
|
39
42
|
keyName: keyName,
|
|
40
43
|
initialValue: initialValue
|
|
41
44
|
}), /*#__PURE__*/_jsx(KeyValues, {
|
|
42
45
|
expandKey: subkeyid,
|
|
43
46
|
value: value,
|
|
44
|
-
level: level
|
|
47
|
+
level: level,
|
|
48
|
+
keys: keys,
|
|
49
|
+
parentValue: parentValue,
|
|
50
|
+
keyName: keyName
|
|
45
51
|
}), /*#__PURE__*/_jsx(NestedClose, {
|
|
46
52
|
expandKey: subkeyid,
|
|
47
53
|
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, (_, v) => typeof v === 'bigint' ? v + 'n' : v, 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,18 +4,20 @@ 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';
|
|
11
|
-
import {
|
|
12
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { Copied } from '../comps/Copied';
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
14
|
export var KeyValues = props => {
|
|
14
15
|
var _expands$expandKey;
|
|
15
16
|
var {
|
|
16
17
|
value,
|
|
17
18
|
expandKey = '',
|
|
18
|
-
level
|
|
19
|
+
level,
|
|
20
|
+
keys = []
|
|
19
21
|
} = props;
|
|
20
22
|
var expands = useExpandsStore();
|
|
21
23
|
var {
|
|
@@ -36,9 +38,9 @@ export var KeyValues = props => {
|
|
|
36
38
|
var [b] = _ref2;
|
|
37
39
|
return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
|
|
38
40
|
}) : entries.sort((_ref3, _ref4) => {
|
|
39
|
-
var [a] = _ref3;
|
|
40
|
-
var [b] = _ref4;
|
|
41
|
-
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
41
|
+
var [a, valA] = _ref3;
|
|
42
|
+
var [b, valB] = _ref4;
|
|
43
|
+
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b, valA, valB) : 0;
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
var style = {
|
|
@@ -54,6 +56,7 @@ export var KeyValues = props => {
|
|
|
54
56
|
return /*#__PURE__*/_jsx(KeyValuesItem, {
|
|
55
57
|
parentValue: value,
|
|
56
58
|
keyName: key,
|
|
59
|
+
keys: [...keys, key],
|
|
57
60
|
value: val,
|
|
58
61
|
level: level
|
|
59
62
|
}, idx);
|
|
@@ -64,6 +67,8 @@ KeyValues.displayName = 'JVR.KeyValues';
|
|
|
64
67
|
export var KayName = props => {
|
|
65
68
|
var {
|
|
66
69
|
keyName,
|
|
70
|
+
parentValue,
|
|
71
|
+
keys,
|
|
67
72
|
value
|
|
68
73
|
} = props;
|
|
69
74
|
var {
|
|
@@ -80,13 +85,17 @@ export var KayName = props => {
|
|
|
80
85
|
children: [/*#__PURE__*/_jsxs("span", {
|
|
81
86
|
ref: highlightContainer,
|
|
82
87
|
children: [/*#__PURE__*/_jsx(Quote, {
|
|
83
|
-
isNumber: isNumber
|
|
84
|
-
|
|
88
|
+
isNumber: isNumber,
|
|
89
|
+
"data-placement": "left"
|
|
90
|
+
}), /*#__PURE__*/_jsx(KeyNameComp, {
|
|
85
91
|
keyName: keyName,
|
|
86
92
|
value: value,
|
|
93
|
+
keys: keys,
|
|
94
|
+
parentValue: parentValue,
|
|
87
95
|
children: keyName
|
|
88
96
|
}), /*#__PURE__*/_jsx(Quote, {
|
|
89
|
-
isNumber: isNumber
|
|
97
|
+
isNumber: isNumber,
|
|
98
|
+
"data-placement": "right"
|
|
90
99
|
})]
|
|
91
100
|
}), /*#__PURE__*/_jsx(Colon, {})]
|
|
92
101
|
});
|
|
@@ -97,7 +106,8 @@ export var KeyValuesItem = props => {
|
|
|
97
106
|
keyName,
|
|
98
107
|
value,
|
|
99
108
|
parentValue,
|
|
100
|
-
level = 0
|
|
109
|
+
level = 0,
|
|
110
|
+
keys = []
|
|
101
111
|
} = props;
|
|
102
112
|
var dispatch = useShowToolsDispatch();
|
|
103
113
|
var subkeyid = useId();
|
|
@@ -115,6 +125,7 @@ export var KeyValuesItem = props => {
|
|
|
115
125
|
value: myValue,
|
|
116
126
|
parentValue: parentValue,
|
|
117
127
|
initialValue: value,
|
|
128
|
+
keys: keys,
|
|
118
129
|
level: level + 1
|
|
119
130
|
});
|
|
120
131
|
}
|
|
@@ -126,15 +137,26 @@ export var KeyValuesItem = props => {
|
|
|
126
137
|
[subkeyid]: false
|
|
127
138
|
})
|
|
128
139
|
};
|
|
129
|
-
return /*#__PURE__*/_jsxs(
|
|
130
|
-
className: "w-rjv-line"
|
|
140
|
+
return /*#__PURE__*/_jsxs(RowComp, _extends({
|
|
141
|
+
className: "w-rjv-line",
|
|
142
|
+
value: value,
|
|
143
|
+
keyName: keyName,
|
|
144
|
+
keys: keys,
|
|
145
|
+
parentValue: parentValue
|
|
131
146
|
}, reset, {
|
|
132
147
|
children: [/*#__PURE__*/_jsx(KayName, {
|
|
133
148
|
keyName: keyName,
|
|
134
|
-
value: value
|
|
149
|
+
value: value,
|
|
150
|
+
keys: keys,
|
|
151
|
+
parentValue: parentValue
|
|
135
152
|
}), /*#__PURE__*/_jsx(Value, {
|
|
153
|
+
keyName: keyName,
|
|
154
|
+
value: value
|
|
155
|
+
}), /*#__PURE__*/_jsx(Copied, {
|
|
136
156
|
keyName: keyName,
|
|
137
157
|
value: value,
|
|
158
|
+
keys: keys,
|
|
159
|
+
parentValue: parentValue,
|
|
138
160
|
expandKey: subkeyid
|
|
139
161
|
})]
|
|
140
162
|
}));
|
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,19 +3,21 @@ 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 {
|
|
10
|
-
import {
|
|
11
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
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';
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
12
|
export var NestedOpen = props => {
|
|
13
13
|
var _expands$expandKey;
|
|
14
14
|
var {
|
|
15
15
|
keyName,
|
|
16
16
|
expandKey,
|
|
17
|
+
keys,
|
|
17
18
|
initialValue,
|
|
18
19
|
value,
|
|
20
|
+
parentValue,
|
|
19
21
|
level
|
|
20
22
|
} = props;
|
|
21
23
|
var expands = useExpandsStore();
|
|
@@ -63,28 +65,32 @@ export var NestedOpen = props => {
|
|
|
63
65
|
}), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, {
|
|
64
66
|
keyName: keyName
|
|
65
67
|
}), /*#__PURE__*/_jsx(SetComp, {
|
|
66
|
-
value: initialValue
|
|
68
|
+
value: initialValue,
|
|
69
|
+
keyName: keyName
|
|
67
70
|
}), /*#__PURE__*/_jsx(MapComp, {
|
|
68
|
-
value: initialValue
|
|
71
|
+
value: initialValue,
|
|
72
|
+
keyName: keyName
|
|
69
73
|
}), /*#__PURE__*/_jsx(BracketsOpen, {
|
|
70
74
|
isBrackets: isArray || isMySet
|
|
71
|
-
}), /*#__PURE__*/_jsx(
|
|
75
|
+
}), /*#__PURE__*/_jsx(EllipsisComp, {
|
|
72
76
|
keyName: keyName,
|
|
73
77
|
value: value,
|
|
74
78
|
isExpanded: isExpanded
|
|
75
79
|
}), /*#__PURE__*/_jsx(BracketsClose, {
|
|
76
80
|
isVisiable: isExpanded || !showArrow,
|
|
77
81
|
isBrackets: isArray || isMySet
|
|
78
|
-
}), /*#__PURE__*/_jsx(
|
|
82
|
+
}), /*#__PURE__*/_jsx(CountInfoComp, {
|
|
79
83
|
value: value,
|
|
80
84
|
keyName: keyName
|
|
81
|
-
}), /*#__PURE__*/_jsx(
|
|
85
|
+
}), /*#__PURE__*/_jsx(CountInfoExtraComps, {
|
|
82
86
|
value: value,
|
|
83
87
|
keyName: keyName
|
|
84
88
|
}), /*#__PURE__*/_jsx(Copied, {
|
|
85
89
|
keyName: keyName,
|
|
86
90
|
value: value,
|
|
87
|
-
expandKey: expandKey
|
|
91
|
+
expandKey: expandKey,
|
|
92
|
+
parentValue: parentValue,
|
|
93
|
+
keys: keys
|
|
88
94
|
})]
|
|
89
95
|
}));
|
|
90
96
|
};
|
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,33 @@
|
|
|
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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
10
|
+
var {
|
|
11
|
+
children,
|
|
12
|
+
onEdit,
|
|
13
|
+
editable = true
|
|
14
|
+
} = props,
|
|
15
|
+
reset = _objectWithoutPropertiesLoose(props, _excluded);
|
|
16
|
+
var [state, dispatch] = useStoreReducer({
|
|
17
|
+
onEdit
|
|
18
|
+
});
|
|
19
|
+
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
20
|
+
value: state,
|
|
21
|
+
children: /*#__PURE__*/_jsx(Dispatch.Provider, {
|
|
22
|
+
value: dispatch,
|
|
23
|
+
children: /*#__PURE__*/_jsxs(JsonView, _extends({}, reset, {
|
|
24
|
+
shortenTextAfterLength: 0,
|
|
25
|
+
ref: ref,
|
|
26
|
+
children: [editable && /*#__PURE__*/_jsx(JsonView.KeyName, {
|
|
27
|
+
render: KeyNameRender
|
|
28
|
+
}), children]
|
|
29
|
+
}))
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
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;
|