@uiw/react-json-view 2.0.0-alpha.3 → 2.0.0-alpha.30
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 +217 -26
- package/basic.d.ts +3 -0
- package/cjs/Container.d.ts +2 -0
- package/cjs/Container.js +13 -6
- package/cjs/arrow/TriangleArrow.js +1 -1
- package/cjs/comps/Copied.d.ts +2 -4
- package/cjs/comps/Copied.js +50 -17
- package/cjs/comps/KeyValues.d.ts +2 -4
- package/cjs/comps/KeyValues.js +62 -27
- package/cjs/comps/NestedClose.d.ts +1 -0
- package/cjs/comps/NestedClose.js +15 -5
- package/cjs/comps/NestedOpen.d.ts +2 -3
- package/cjs/comps/NestedOpen.js +34 -14
- package/cjs/comps/Value.d.ts +1 -2
- package/cjs/comps/Value.js +4 -8
- package/cjs/comps/useIdCompat.d.ts +1 -0
- package/cjs/comps/useIdCompat.js +14 -0
- package/cjs/editor/KeyName.d.ts +2 -0
- package/cjs/editor/KeyName.js +82 -0
- package/cjs/editor/index.d.ts +18 -0
- package/cjs/editor/index.js +44 -0
- package/cjs/editor/store.d.ts +27 -0
- package/cjs/editor/store.js +23 -0
- package/cjs/index.d.ts +10 -3
- package/cjs/index.js +9 -4
- package/cjs/section/Copied.d.ts +1 -1
- package/cjs/section/Copied.js +1 -2
- package/cjs/section/CountInfo.d.ts +1 -2
- package/cjs/section/CountInfo.js +3 -5
- package/cjs/section/CountInfoExtra.d.ts +1 -2
- package/cjs/section/CountInfoExtra.js +2 -4
- package/cjs/section/Ellipsis.d.ts +0 -1
- package/cjs/section/Ellipsis.js +4 -5
- package/cjs/section/KeyName.d.ts +7 -6
- package/cjs/section/KeyName.js +8 -6
- package/cjs/section/Row.d.ts +13 -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 +10 -3
- package/cjs/store/Symbols.js +2 -4
- package/cjs/store/Types.d.ts +29 -25
- package/cjs/store/Types.js +8 -8
- package/cjs/store.d.ts +8 -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/cjs/symbol/index.d.ts +11 -16
- package/cjs/symbol/index.js +75 -30
- package/cjs/theme/basic.d.ts +1 -2
- package/cjs/theme/basic.js +4 -3
- package/cjs/theme/dark.d.ts +1 -2
- package/cjs/theme/dark.js +2 -3
- package/cjs/theme/github.dark.d.ts +1 -2
- package/cjs/theme/github.dark.js +2 -3
- package/cjs/theme/github.light.d.ts +1 -2
- package/cjs/theme/github.light.js +2 -3
- package/cjs/theme/gruvbox.d.ts +1 -2
- package/cjs/theme/gruvbox.js +2 -3
- package/cjs/theme/light.d.ts +1 -2
- package/cjs/theme/light.js +2 -3
- package/cjs/theme/monokai.d.ts +1 -2
- package/cjs/theme/monokai.js +2 -3
- package/cjs/theme/nord.d.ts +1 -2
- package/cjs/theme/nord.js +2 -3
- package/cjs/theme/vscode.d.ts +1 -2
- 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/cjs/types/index.d.ts +3 -1
- package/cjs/types/index.js +96 -124
- package/cjs/utils/useHighlight.d.ts +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 +15 -7
- package/esm/arrow/TriangleArrow.js +1 -1
- package/esm/comps/Copied.d.ts +2 -4
- package/esm/comps/Copied.js +48 -16
- package/esm/comps/KeyValues.d.ts +2 -4
- package/esm/comps/KeyValues.js +53 -21
- package/esm/comps/NestedClose.d.ts +1 -0
- package/esm/comps/NestedClose.js +13 -3
- package/esm/comps/NestedOpen.d.ts +2 -3
- package/esm/comps/NestedOpen.js +33 -14
- package/esm/comps/Value.d.ts +1 -2
- package/esm/comps/Value.js +2 -4
- package/esm/comps/useIdCompat.d.ts +1 -0
- package/esm/comps/useIdCompat.js +8 -0
- package/esm/editor/KeyName.d.ts +2 -0
- package/esm/editor/KeyName.js +77 -0
- package/esm/editor/index.d.ts +18 -0
- package/esm/editor/index.js +33 -0
- package/esm/editor/store.d.ts +27 -0
- package/esm/editor/store.js +13 -0
- package/esm/index.d.ts +10 -3
- package/esm/index.js +10 -5
- package/esm/section/Copied.d.ts +1 -1
- package/esm/section/CountInfo.d.ts +1 -2
- package/esm/section/CountInfo.js +1 -1
- package/esm/section/CountInfoExtra.d.ts +1 -2
- package/esm/section/Ellipsis.d.ts +0 -1
- package/esm/section/Ellipsis.js +1 -1
- package/esm/section/KeyName.d.ts +7 -6
- package/esm/section/KeyName.js +6 -2
- package/esm/section/Row.d.ts +13 -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 +10 -3
- package/esm/store/Types.d.ts +29 -25
- package/esm/store/Types.js +6 -4
- package/esm/store.d.ts +8 -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/esm/symbol/index.d.ts +11 -16
- package/esm/symbol/index.js +76 -23
- package/esm/theme/basic.d.ts +1 -2
- package/esm/theme/basic.js +2 -0
- package/esm/theme/dark.d.ts +1 -2
- package/esm/theme/github.dark.d.ts +1 -2
- package/esm/theme/github.light.d.ts +1 -2
- package/esm/theme/gruvbox.d.ts +1 -2
- package/esm/theme/light.d.ts +1 -2
- package/esm/theme/monokai.d.ts +1 -2
- package/esm/theme/nord.d.ts +1 -2
- package/esm/theme/vscode.d.ts +1 -2
- 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/esm/types/index.d.ts +3 -1
- package/esm/types/index.js +82 -100
- package/esm/utils/useHighlight.d.ts +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/esm/comps/Copied.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { type SectionElementResult } from '../store/Section';
|
|
2
2
|
import { type TagType } from '../store/Types';
|
|
3
3
|
export type CopiedOption<T extends object> = {
|
|
4
4
|
value?: T;
|
|
5
5
|
copied: boolean;
|
|
6
6
|
setCopied: React.Dispatch<React.SetStateAction<boolean>>;
|
|
7
7
|
};
|
|
8
|
-
export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement> {
|
|
9
|
-
value?: T;
|
|
10
|
-
keyName: string | number;
|
|
8
|
+
export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement>, SectionElementResult<T> {
|
|
11
9
|
expandKey: string;
|
|
12
10
|
}
|
|
13
11
|
export declare const Copied: {
|
package/esm/comps/Copied.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
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';
|
|
7
|
-
import { useShowToolsStore } from '../store/ShowTools';
|
|
8
7
|
import { useSectionStore } from '../store/Section';
|
|
8
|
+
import { useShowToolsStore } from '../store/ShowTools';
|
|
9
|
+
import { bigIntToString } from '../types';
|
|
9
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
11
|
export var Copied = props => {
|
|
11
12
|
var {
|
|
12
13
|
keyName,
|
|
13
14
|
value,
|
|
14
|
-
|
|
15
|
+
parentValue,
|
|
16
|
+
expandKey,
|
|
17
|
+
keys
|
|
15
18
|
} = props,
|
|
16
19
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
17
20
|
var {
|
|
@@ -27,18 +30,40 @@ export var Copied = props => {
|
|
|
27
30
|
if (enableClipboard === false || !isShowTools) return null;
|
|
28
31
|
var click = event => {
|
|
29
32
|
event.stopPropagation();
|
|
30
|
-
var copyText =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
var copyText = '';
|
|
34
|
+
if (typeof value === 'number' && value === Infinity) {
|
|
35
|
+
copyText = 'Infinity';
|
|
36
|
+
} else if (typeof value === 'number' && isNaN(value)) {
|
|
37
|
+
copyText = 'NaN';
|
|
38
|
+
} else if (typeof value === 'bigint') {
|
|
39
|
+
copyText = bigIntToString(value);
|
|
40
|
+
} else if (value instanceof Date) {
|
|
41
|
+
copyText = value.toLocaleString();
|
|
42
|
+
} else {
|
|
43
|
+
copyText = JSON.stringify(value, (_, v) => typeof v === 'bigint' ? bigIntToString(v) : v, 2);
|
|
44
|
+
}
|
|
45
|
+
onCopied && onCopied(copyText, value);
|
|
46
|
+
setCopied(true);
|
|
47
|
+
var _clipboard = navigator.clipboard || {
|
|
48
|
+
writeText(text) {
|
|
49
|
+
return new Promise((reslove, reject) => {
|
|
50
|
+
var textarea = document.createElement('textarea');
|
|
51
|
+
textarea.style.position = 'absolute';
|
|
52
|
+
textarea.style.opacity = '0';
|
|
53
|
+
textarea.style.left = '-99999999px';
|
|
54
|
+
textarea.value = text;
|
|
55
|
+
document.body.appendChild(textarea);
|
|
56
|
+
textarea.select();
|
|
57
|
+
if (!document.execCommand('copy')) {
|
|
58
|
+
reject();
|
|
59
|
+
} else {
|
|
60
|
+
reslove();
|
|
61
|
+
}
|
|
62
|
+
textarea.remove();
|
|
63
|
+
});
|
|
33
64
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (typeof value === 'number' && value === Infinity) copyText = 'Infinity';
|
|
37
|
-
if (typeof value === 'number' && isNaN(value)) copyText = 'NaN';
|
|
38
|
-
if (typeof value === 'bigint') copyText = value + 'n';
|
|
39
|
-
navigator.clipboard.writeText(copyText).then(() => {
|
|
40
|
-
onCopied && onCopied(copyText, value);
|
|
41
|
-
setCopied(true);
|
|
65
|
+
};
|
|
66
|
+
_clipboard.writeText(copyText).then(() => {
|
|
42
67
|
var timer = setTimeout(() => {
|
|
43
68
|
setCopied(false);
|
|
44
69
|
clearTimeout(timer);
|
|
@@ -46,6 +71,9 @@ export var Copied = props => {
|
|
|
46
71
|
}).catch(error => {});
|
|
47
72
|
};
|
|
48
73
|
var svgProps = {
|
|
74
|
+
style: {
|
|
75
|
+
display: 'inline-flex'
|
|
76
|
+
},
|
|
49
77
|
fill: copied ? 'var(--w-rjv-copied-success-color, #28a745)' : 'var(--w-rjv-copied-color, currentColor)',
|
|
50
78
|
onClick: click
|
|
51
79
|
};
|
|
@@ -53,13 +81,17 @@ export var Copied = props => {
|
|
|
53
81
|
render
|
|
54
82
|
} = Comp,
|
|
55
83
|
reset = _objectWithoutPropertiesLoose(Comp, _excluded2);
|
|
56
|
-
var elmProps = _extends({}, reset, other, svgProps
|
|
84
|
+
var elmProps = _extends({}, reset, other, svgProps, {
|
|
85
|
+
style: _extends({}, reset.style, other.style, svgProps.style)
|
|
86
|
+
});
|
|
57
87
|
var isRender = render && typeof render === 'function';
|
|
58
88
|
var child = isRender && render(_extends({}, elmProps, {
|
|
59
89
|
'data-copied': copied
|
|
60
90
|
}), {
|
|
61
91
|
value,
|
|
62
|
-
keyName
|
|
92
|
+
keyName,
|
|
93
|
+
keys,
|
|
94
|
+
parentValue
|
|
63
95
|
});
|
|
64
96
|
if (child) return child;
|
|
65
97
|
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
|
@@ -1,30 +1,42 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import { Fragment,
|
|
2
|
+
import { Fragment, useRef } from 'react';
|
|
3
3
|
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
7
|
import { KeyNameComp } from '../section/KeyName';
|
|
8
|
+
import { RowComp } from '../section/Row';
|
|
8
9
|
import { Container } from '../Container';
|
|
9
10
|
import { Quote, Colon } from '../symbol';
|
|
10
11
|
import { useHighlight } from '../utils/useHighlight';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { Copied } from '../comps/Copied';
|
|
13
|
+
import { useIdCompat } from '../comps/useIdCompat';
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
15
|
export var KeyValues = props => {
|
|
14
16
|
var _expands$expandKey;
|
|
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 {
|
|
22
25
|
objectSortKeys,
|
|
23
26
|
indentWidth,
|
|
24
|
-
collapsed
|
|
27
|
+
collapsed,
|
|
28
|
+
shouldExpandNodeInitially
|
|
25
29
|
} = useStore();
|
|
26
30
|
var isMyArray = Array.isArray(value);
|
|
27
|
-
var
|
|
31
|
+
var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
|
|
32
|
+
var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
|
|
33
|
+
if (expands[expandKey] === undefined && shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
|
|
34
|
+
value,
|
|
35
|
+
keys,
|
|
36
|
+
level
|
|
37
|
+
})) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
28
40
|
if (isExpanded) {
|
|
29
41
|
return null;
|
|
30
42
|
}
|
|
@@ -36,9 +48,9 @@ export var KeyValues = props => {
|
|
|
36
48
|
var [b] = _ref2;
|
|
37
49
|
return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
|
|
38
50
|
}) : entries.sort((_ref3, _ref4) => {
|
|
39
|
-
var [a] = _ref3;
|
|
40
|
-
var [b] = _ref4;
|
|
41
|
-
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
|
|
51
|
+
var [a, valA] = _ref3;
|
|
52
|
+
var [b, valB] = _ref4;
|
|
53
|
+
return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b, valA, valB) : 0;
|
|
42
54
|
});
|
|
43
55
|
}
|
|
44
56
|
var style = {
|
|
@@ -54,6 +66,7 @@ export var KeyValues = props => {
|
|
|
54
66
|
return /*#__PURE__*/_jsx(KeyValuesItem, {
|
|
55
67
|
parentValue: value,
|
|
56
68
|
keyName: key,
|
|
69
|
+
keys: [...keys, key],
|
|
57
70
|
value: val,
|
|
58
71
|
level: level
|
|
59
72
|
}, idx);
|
|
@@ -64,6 +77,8 @@ KeyValues.displayName = 'JVR.KeyValues';
|
|
|
64
77
|
export var KayName = props => {
|
|
65
78
|
var {
|
|
66
79
|
keyName,
|
|
80
|
+
parentValue,
|
|
81
|
+
keys,
|
|
67
82
|
value
|
|
68
83
|
} = props;
|
|
69
84
|
var {
|
|
@@ -76,21 +91,25 @@ export var KayName = props => {
|
|
|
76
91
|
highlightUpdates,
|
|
77
92
|
highlightContainer
|
|
78
93
|
});
|
|
94
|
+
var compProps = {
|
|
95
|
+
keyName,
|
|
96
|
+
value,
|
|
97
|
+
keys,
|
|
98
|
+
parentValue
|
|
99
|
+
};
|
|
79
100
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
80
101
|
children: [/*#__PURE__*/_jsxs("span", {
|
|
81
102
|
ref: highlightContainer,
|
|
82
|
-
children: [/*#__PURE__*/_jsx(Quote, {
|
|
103
|
+
children: [/*#__PURE__*/_jsx(Quote, _extends({
|
|
83
104
|
isNumber: isNumber,
|
|
84
105
|
"data-placement": "left"
|
|
85
|
-
}), /*#__PURE__*/_jsx(KeyNameComp, {
|
|
86
|
-
keyName: keyName,
|
|
87
|
-
value: value,
|
|
106
|
+
}, compProps)), /*#__PURE__*/_jsx(KeyNameComp, _extends({}, compProps, {
|
|
88
107
|
children: keyName
|
|
89
|
-
}), /*#__PURE__*/_jsx(Quote, {
|
|
108
|
+
})), /*#__PURE__*/_jsx(Quote, _extends({
|
|
90
109
|
isNumber: isNumber,
|
|
91
110
|
"data-placement": "right"
|
|
92
|
-
})]
|
|
93
|
-
}), /*#__PURE__*/_jsx(Colon, {})]
|
|
111
|
+
}, compProps))]
|
|
112
|
+
}), /*#__PURE__*/_jsx(Colon, _extends({}, compProps))]
|
|
94
113
|
});
|
|
95
114
|
};
|
|
96
115
|
KayName.displayName = 'JVR.KayName';
|
|
@@ -99,10 +118,11 @@ export var KeyValuesItem = props => {
|
|
|
99
118
|
keyName,
|
|
100
119
|
value,
|
|
101
120
|
parentValue,
|
|
102
|
-
level = 0
|
|
121
|
+
level = 0,
|
|
122
|
+
keys = []
|
|
103
123
|
} = props;
|
|
104
124
|
var dispatch = useShowToolsDispatch();
|
|
105
|
-
var subkeyid =
|
|
125
|
+
var subkeyid = useIdCompat();
|
|
106
126
|
var isMyArray = Array.isArray(value);
|
|
107
127
|
var isMySet = value instanceof Set;
|
|
108
128
|
var isMyMap = value instanceof Map;
|
|
@@ -117,6 +137,7 @@ export var KeyValuesItem = props => {
|
|
|
117
137
|
value: myValue,
|
|
118
138
|
parentValue: parentValue,
|
|
119
139
|
initialValue: value,
|
|
140
|
+
keys: keys,
|
|
120
141
|
level: level + 1
|
|
121
142
|
});
|
|
122
143
|
}
|
|
@@ -128,15 +149,26 @@ export var KeyValuesItem = props => {
|
|
|
128
149
|
[subkeyid]: false
|
|
129
150
|
})
|
|
130
151
|
};
|
|
131
|
-
return /*#__PURE__*/_jsxs(
|
|
132
|
-
className: "w-rjv-line"
|
|
152
|
+
return /*#__PURE__*/_jsxs(RowComp, _extends({
|
|
153
|
+
className: "w-rjv-line",
|
|
154
|
+
value: value,
|
|
155
|
+
keyName: keyName,
|
|
156
|
+
keys: keys,
|
|
157
|
+
parentValue: parentValue
|
|
133
158
|
}, reset, {
|
|
134
159
|
children: [/*#__PURE__*/_jsx(KayName, {
|
|
135
160
|
keyName: keyName,
|
|
136
|
-
value: value
|
|
161
|
+
value: value,
|
|
162
|
+
keys: keys,
|
|
163
|
+
parentValue: parentValue
|
|
137
164
|
}), /*#__PURE__*/_jsx(Value, {
|
|
165
|
+
keyName: keyName,
|
|
166
|
+
value: value
|
|
167
|
+
}), /*#__PURE__*/_jsx(Copied, {
|
|
138
168
|
keyName: keyName,
|
|
139
169
|
value: value,
|
|
170
|
+
keys: keys,
|
|
171
|
+
parentValue: parentValue,
|
|
140
172
|
expandKey: subkeyid
|
|
141
173
|
})]
|
|
142
174
|
}));
|
package/esm/comps/NestedClose.js
CHANGED
|
@@ -7,16 +7,26 @@ export var NestedClose = props => {
|
|
|
7
7
|
var {
|
|
8
8
|
value,
|
|
9
9
|
expandKey,
|
|
10
|
-
level
|
|
10
|
+
level,
|
|
11
|
+
keys = []
|
|
11
12
|
} = props;
|
|
12
13
|
var expands = useExpandsStore();
|
|
13
14
|
var isArray = Array.isArray(value);
|
|
14
15
|
var {
|
|
15
|
-
collapsed
|
|
16
|
+
collapsed,
|
|
17
|
+
shouldExpandNodeInitially
|
|
16
18
|
} = useStore();
|
|
17
19
|
var isMySet = value instanceof Set;
|
|
18
|
-
var
|
|
20
|
+
var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
|
|
21
|
+
var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
|
|
19
22
|
var len = Object.keys(value).length;
|
|
23
|
+
if (expands[expandKey] === undefined && shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
|
|
24
|
+
value,
|
|
25
|
+
keys,
|
|
26
|
+
level
|
|
27
|
+
})) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
20
30
|
if (isExpanded || len === 0) {
|
|
21
31
|
return null;
|
|
22
32
|
}
|
|
@@ -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
|
@@ -8,27 +8,38 @@ import { CountInfoComp } from '../section/CountInfo';
|
|
|
8
8
|
import { Arrow, BracketsOpen, BracketsClose } from '../symbol';
|
|
9
9
|
import { EllipsisComp } from '../section/Ellipsis';
|
|
10
10
|
import { SetComp, MapComp } from '../types';
|
|
11
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
12
|
export var NestedOpen = props => {
|
|
14
13
|
var _expands$expandKey;
|
|
15
14
|
var {
|
|
16
15
|
keyName,
|
|
17
16
|
expandKey,
|
|
17
|
+
keys = [],
|
|
18
18
|
initialValue,
|
|
19
19
|
value,
|
|
20
|
+
parentValue,
|
|
20
21
|
level
|
|
21
22
|
} = props;
|
|
22
23
|
var expands = useExpandsStore();
|
|
23
24
|
var dispatchExpands = useExpandsDispatch();
|
|
24
25
|
var {
|
|
25
26
|
onExpand,
|
|
26
|
-
collapsed
|
|
27
|
+
collapsed,
|
|
28
|
+
shouldExpandNodeInitially
|
|
27
29
|
} = useStore();
|
|
28
30
|
var isArray = Array.isArray(value);
|
|
29
31
|
var isMySet = value instanceof Set;
|
|
30
|
-
var
|
|
32
|
+
var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
|
|
31
33
|
var isObject = typeof value === 'object';
|
|
34
|
+
var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : defaultExpanded;
|
|
35
|
+
var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, {
|
|
36
|
+
value,
|
|
37
|
+
keys,
|
|
38
|
+
level
|
|
39
|
+
});
|
|
40
|
+
if (expands[expandKey] === undefined && shouldExpand !== undefined) {
|
|
41
|
+
isExpanded = shouldExpand;
|
|
42
|
+
}
|
|
32
43
|
var click = () => {
|
|
33
44
|
var opt = {
|
|
34
45
|
expand: !isExpanded,
|
|
@@ -57,26 +68,32 @@ export var NestedOpen = props => {
|
|
|
57
68
|
if (showArrow) {
|
|
58
69
|
reset.onClick = click;
|
|
59
70
|
}
|
|
71
|
+
var compProps = {
|
|
72
|
+
keyName,
|
|
73
|
+
value,
|
|
74
|
+
keys,
|
|
75
|
+
parentValue
|
|
76
|
+
};
|
|
60
77
|
return /*#__PURE__*/_jsxs("span", _extends({}, reset, {
|
|
61
|
-
children: [showArrow && /*#__PURE__*/_jsx(Arrow, {
|
|
78
|
+
children: [showArrow && /*#__PURE__*/_jsx(Arrow, _extends({
|
|
62
79
|
style: arrowStyle,
|
|
63
80
|
expandKey: expandKey
|
|
64
|
-
}), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, {
|
|
81
|
+
}, compProps)), (keyName || typeof keyName === 'number') && /*#__PURE__*/_jsx(KayName, _extends({}, compProps)), /*#__PURE__*/_jsx(SetComp, {
|
|
82
|
+
value: initialValue,
|
|
65
83
|
keyName: keyName
|
|
66
|
-
}), /*#__PURE__*/_jsx(SetComp, {
|
|
67
|
-
value: initialValue
|
|
68
84
|
}), /*#__PURE__*/_jsx(MapComp, {
|
|
69
|
-
value: initialValue
|
|
70
|
-
|
|
85
|
+
value: initialValue,
|
|
86
|
+
keyName: keyName
|
|
87
|
+
}), /*#__PURE__*/_jsx(BracketsOpen, _extends({
|
|
71
88
|
isBrackets: isArray || isMySet
|
|
72
|
-
}), /*#__PURE__*/_jsx(EllipsisComp, {
|
|
89
|
+
}, compProps)), /*#__PURE__*/_jsx(EllipsisComp, {
|
|
73
90
|
keyName: keyName,
|
|
74
91
|
value: value,
|
|
75
92
|
isExpanded: isExpanded
|
|
76
|
-
}), /*#__PURE__*/_jsx(BracketsClose, {
|
|
93
|
+
}), /*#__PURE__*/_jsx(BracketsClose, _extends({
|
|
77
94
|
isVisiable: isExpanded || !showArrow,
|
|
78
95
|
isBrackets: isArray || isMySet
|
|
79
|
-
}), /*#__PURE__*/_jsx(CountInfoComp, {
|
|
96
|
+
}, compProps)), /*#__PURE__*/_jsx(CountInfoComp, {
|
|
80
97
|
value: value,
|
|
81
98
|
keyName: keyName
|
|
82
99
|
}), /*#__PURE__*/_jsx(CountInfoExtraComps, {
|
|
@@ -85,7 +102,9 @@ export var NestedOpen = props => {
|
|
|
85
102
|
}), /*#__PURE__*/_jsx(Copied, {
|
|
86
103
|
keyName: keyName,
|
|
87
104
|
value: value,
|
|
88
|
-
expandKey: expandKey
|
|
105
|
+
expandKey: expandKey,
|
|
106
|
+
parentValue: parentValue,
|
|
107
|
+
keys: keys
|
|
89
108
|
})]
|
|
90
109
|
}));
|
|
91
110
|
};
|
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
|
@@ -5,12 +5,10 @@ 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 @@
|
|
|
1
|
+
export declare function useIdCompat(): string;
|
|
@@ -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,18 @@
|
|
|
1
|
+
import { type JsonViewProps } from '../';
|
|
2
|
+
export interface JsonViewEditorProps<T extends object> extends Omit<JsonViewProps<T>, 'shortenTextAfterLength'> {
|
|
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
|
+
/** Whether enable edit feature. @default true */
|
|
15
|
+
editable?: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
18
|
+
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,27 @@
|
|
|
1
|
+
type InitialState = {
|
|
2
|
+
/**
|
|
3
|
+
* When a callback function is passed in, edit functionality is enabled. The callback is invoked before edits are completed.
|
|
4
|
+
* @returns {boolean} Returning false from onEdit will prevent the change from being made.
|
|
5
|
+
*/
|
|
6
|
+
onEdit?: (option: {
|
|
7
|
+
value: unknown;
|
|
8
|
+
oldValue: unknown;
|
|
9
|
+
keyName?: string | number;
|
|
10
|
+
parentName?: string | number;
|
|
11
|
+
type?: 'value' | 'key';
|
|
12
|
+
}) => boolean;
|
|
13
|
+
};
|
|
14
|
+
type Dispatch = React.Dispatch<InitialState>;
|
|
15
|
+
export declare const Context: import("react").Context<InitialState>;
|
|
16
|
+
export declare const Dispatch: import("react").Context<Dispatch>;
|
|
17
|
+
export declare const useStore: () => InitialState;
|
|
18
|
+
export declare function useStoreReducer(initialState: InitialState): [{
|
|
19
|
+
onEdit?: (option: {
|
|
20
|
+
value: unknown;
|
|
21
|
+
oldValue: unknown;
|
|
22
|
+
keyName?: string | number;
|
|
23
|
+
parentName?: string | number;
|
|
24
|
+
type?: "value" | "key";
|
|
25
|
+
}) => boolean;
|
|
26
|
+
}, import("react").Dispatch<InitialState>];
|
|
27
|
+
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
|
+
}
|