@uiw/react-json-view 2.0.0-alpha.36 → 2.0.0-alpha.37
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/cjs/comps/Copied.d.ts +1 -0
- package/cjs/comps/Copied.js +12 -2
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +4 -2
- package/cjs/section/Copied.d.ts +4 -1
- package/cjs/store.d.ts +1 -0
- package/esm/comps/Copied.d.ts +1 -0
- package/esm/comps/Copied.js +13 -3
- package/esm/index.d.ts +2 -0
- package/esm/index.js +5 -3
- package/esm/section/Copied.d.ts +4 -1
- package/esm/store.d.ts +1 -0
- package/package.json +1 -1
- package/triangle-arrow.d.ts +2 -2
- package/triangle-solid-arrow.d.ts +2 -2
package/cjs/comps/Copied.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type CopiedOption<T extends object> = {
|
|
|
7
7
|
};
|
|
8
8
|
export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement>, SectionElementResult<T> {
|
|
9
9
|
expandKey: string;
|
|
10
|
+
beforeCopy?: (copyText: string, keyName?: string | number, value?: T, parentValue?: T, expandKey?: string, keys?: (number | string)[]) => string;
|
|
10
11
|
}
|
|
11
12
|
export declare const Copied: {
|
|
12
13
|
<T extends object, K extends TagType>(props: CopiedProps<T>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
|
package/cjs/comps/Copied.js
CHANGED
|
@@ -14,7 +14,7 @@ var _Section = require("../store/Section");
|
|
|
14
14
|
var _ShowTools = require("../store/ShowTools");
|
|
15
15
|
var _types = require("../types/");
|
|
16
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
-
var _excluded = ["keyName", "value", "parentValue", "expandKey", "keys"],
|
|
17
|
+
var _excluded = ["keyName", "value", "parentValue", "expandKey", "keys", "beforeCopy"],
|
|
18
18
|
_excluded2 = ["as", "render"];
|
|
19
19
|
var Copied = exports.Copied = function Copied(props) {
|
|
20
20
|
var keyName = props.keyName,
|
|
@@ -22,10 +22,12 @@ var Copied = exports.Copied = function Copied(props) {
|
|
|
22
22
|
parentValue = props.parentValue,
|
|
23
23
|
expandKey = props.expandKey,
|
|
24
24
|
keys = props.keys,
|
|
25
|
+
beforeCopy = props.beforeCopy,
|
|
25
26
|
other = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
26
27
|
var _useStore = (0, _store.useStore)(),
|
|
27
28
|
onCopied = _useStore.onCopied,
|
|
28
|
-
enableClipboard = _useStore.enableClipboard
|
|
29
|
+
enableClipboard = _useStore.enableClipboard,
|
|
30
|
+
globalBeforeCopy = _useStore.beforeCopy;
|
|
29
31
|
var showTools = (0, _ShowTools.useShowToolsStore)();
|
|
30
32
|
var isShowTools = showTools[expandKey];
|
|
31
33
|
var _useState = (0, _react.useState)(false),
|
|
@@ -35,6 +37,7 @@ var Copied = exports.Copied = function Copied(props) {
|
|
|
35
37
|
var _useSectionStore = (0, _Section.useSectionStore)(),
|
|
36
38
|
_useSectionStore$Copi = _useSectionStore.Copied,
|
|
37
39
|
Comp = _useSectionStore$Copi === void 0 ? {} : _useSectionStore$Copi;
|
|
40
|
+
var sectionBeforeCopy = Comp === null || Comp === void 0 ? void 0 : Comp.beforeCopy;
|
|
38
41
|
if (enableClipboard === false || !isShowTools) return null;
|
|
39
42
|
var click = function click(event) {
|
|
40
43
|
event.stopPropagation();
|
|
@@ -52,6 +55,13 @@ var Copied = exports.Copied = function Copied(props) {
|
|
|
52
55
|
return typeof v === 'bigint' ? (0, _types.bigIntToString)(v) : v;
|
|
53
56
|
}, 2);
|
|
54
57
|
}
|
|
58
|
+
|
|
59
|
+
// Apply beforeCopy transformation if provided
|
|
60
|
+
// Priority: component prop > section prop > global prop
|
|
61
|
+
var finalBeforeCopy = beforeCopy || sectionBeforeCopy || globalBeforeCopy;
|
|
62
|
+
if (finalBeforeCopy && typeof finalBeforeCopy === 'function') {
|
|
63
|
+
copyText = finalBeforeCopy(copyText, keyName, value, parentValue, expandKey, keys);
|
|
64
|
+
}
|
|
55
65
|
onCopied && onCopied(copyText, value);
|
|
56
66
|
setCopied(true);
|
|
57
67
|
var _clipboard = navigator.clipboard || {
|
package/cjs/index.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
72
72
|
}) => void;
|
|
73
73
|
/** Fires event when you copy */
|
|
74
74
|
onCopied?: (text: string, value?: T) => void;
|
|
75
|
+
/** Transform the text before copying to clipboard */
|
|
76
|
+
beforeCopy?: (copyText: string, keyName?: string | number, value?: T, parentValue?: T, expandKey?: string, keys?: (number | string)[]) => string;
|
|
75
77
|
}
|
|
76
78
|
type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
|
|
77
79
|
Bigint: typeof Bigint;
|
package/cjs/index.js
CHANGED
|
@@ -110,7 +110,7 @@ Object.keys(_symbol).forEach(function (key) {
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
|
-
var _excluded = ["className", "style", "value", "children", "collapsed", "shouldExpandNodeInitially", "indentWidth", "displayObjectSize", "shortenTextAfterLength", "stringEllipsis", "highlightUpdates", "enableClipboard", "displayDataTypes", "objectSortKeys", "onExpand", "onCopied"];
|
|
113
|
+
var _excluded = ["className", "style", "value", "children", "collapsed", "shouldExpandNodeInitially", "indentWidth", "displayObjectSize", "shortenTextAfterLength", "stringEllipsis", "highlightUpdates", "enableClipboard", "displayDataTypes", "objectSortKeys", "onExpand", "onCopied", "beforeCopy"];
|
|
114
114
|
var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
115
115
|
var _props$className = props.className,
|
|
116
116
|
className = _props$className === void 0 ? '' : _props$className,
|
|
@@ -136,6 +136,7 @@ var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
136
136
|
objectSortKeys = _props$objectSortKeys === void 0 ? false : _props$objectSortKeys,
|
|
137
137
|
onExpand = props.onExpand,
|
|
138
138
|
onCopied = props.onCopied,
|
|
139
|
+
beforeCopy = props.beforeCopy,
|
|
139
140
|
elmProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
140
141
|
var defaultStyle = (0, _objectSpread2["default"])({
|
|
141
142
|
lineHeight: 1.4,
|
|
@@ -158,7 +159,8 @@ var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
158
159
|
stringEllipsis: stringEllipsis,
|
|
159
160
|
highlightUpdates: highlightUpdates,
|
|
160
161
|
onCopied: onCopied,
|
|
161
|
-
onExpand: onExpand
|
|
162
|
+
onExpand: onExpand,
|
|
163
|
+
beforeCopy: beforeCopy
|
|
162
164
|
},
|
|
163
165
|
initialTypes: {
|
|
164
166
|
displayDataTypes: displayDataTypes
|
package/cjs/section/Copied.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type TagType } from '../store/Types';
|
|
2
2
|
import { type SectionElement } from '../store/Section';
|
|
3
|
+
export type CopiedSectionElement<T extends TagType = 'svg'> = SectionElement<T> & {
|
|
4
|
+
beforeCopy?: (copyText: string, keyName?: string | number, value?: object, parentValue?: object, expandKey?: string, keys?: (number | string)[]) => string;
|
|
5
|
+
};
|
|
3
6
|
export declare const Copied: {
|
|
4
|
-
<K extends TagType = "svg">(props:
|
|
7
|
+
<K extends TagType = "svg">(props: CopiedSectionElement<K>): null;
|
|
5
8
|
displayName: string;
|
|
6
9
|
};
|
package/cjs/store.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface InitialState<T extends object> {
|
|
|
6
6
|
value?: object;
|
|
7
7
|
onExpand?: JsonViewProps<object>['onExpand'];
|
|
8
8
|
onCopied?: JsonViewProps<object>['onCopied'];
|
|
9
|
+
beforeCopy?: JsonViewProps<T>['beforeCopy'];
|
|
9
10
|
objectSortKeys?: JsonViewProps<T>['objectSortKeys'];
|
|
10
11
|
displayObjectSize?: JsonViewProps<T>['displayObjectSize'];
|
|
11
12
|
shortenTextAfterLength?: JsonViewProps<T>['shortenTextAfterLength'];
|
package/esm/comps/Copied.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type CopiedOption<T extends object> = {
|
|
|
7
7
|
};
|
|
8
8
|
export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement>, SectionElementResult<T> {
|
|
9
9
|
expandKey: string;
|
|
10
|
+
beforeCopy?: (copyText: string, keyName?: string | number, value?: T, parentValue?: T, expandKey?: string, keys?: (number | string)[]) => string;
|
|
10
11
|
}
|
|
11
12
|
export declare const Copied: {
|
|
12
13
|
<T extends object, K extends TagType>(props: CopiedProps<T>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
|
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", "parentValue", "expandKey", "keys"],
|
|
3
|
+
var _excluded = ["keyName", "value", "parentValue", "expandKey", "keys", "beforeCopy"],
|
|
4
4
|
_excluded2 = ["as", "render"];
|
|
5
5
|
import { useState } from 'react';
|
|
6
6
|
import { useStore } from "../store.js";
|
|
@@ -14,12 +14,14 @@ export var Copied = props => {
|
|
|
14
14
|
value,
|
|
15
15
|
parentValue,
|
|
16
16
|
expandKey,
|
|
17
|
-
keys
|
|
17
|
+
keys,
|
|
18
|
+
beforeCopy
|
|
18
19
|
} = props,
|
|
19
20
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
20
21
|
var {
|
|
21
22
|
onCopied,
|
|
22
|
-
enableClipboard
|
|
23
|
+
enableClipboard,
|
|
24
|
+
beforeCopy: globalBeforeCopy
|
|
23
25
|
} = useStore();
|
|
24
26
|
var showTools = useShowToolsStore();
|
|
25
27
|
var isShowTools = showTools[expandKey];
|
|
@@ -27,6 +29,7 @@ export var Copied = props => {
|
|
|
27
29
|
var {
|
|
28
30
|
Copied: Comp = {}
|
|
29
31
|
} = useSectionStore();
|
|
32
|
+
var sectionBeforeCopy = Comp == null ? void 0 : Comp.beforeCopy;
|
|
30
33
|
if (enableClipboard === false || !isShowTools) return null;
|
|
31
34
|
var click = event => {
|
|
32
35
|
event.stopPropagation();
|
|
@@ -42,6 +45,13 @@ export var Copied = props => {
|
|
|
42
45
|
} else {
|
|
43
46
|
copyText = JSON.stringify(value, (_, v) => typeof v === 'bigint' ? bigIntToString(v) : v, 2);
|
|
44
47
|
}
|
|
48
|
+
|
|
49
|
+
// Apply beforeCopy transformation if provided
|
|
50
|
+
// Priority: component prop > section prop > global prop
|
|
51
|
+
var finalBeforeCopy = beforeCopy || sectionBeforeCopy || globalBeforeCopy;
|
|
52
|
+
if (finalBeforeCopy && typeof finalBeforeCopy === 'function') {
|
|
53
|
+
copyText = finalBeforeCopy(copyText, keyName, value, parentValue, expandKey, keys);
|
|
54
|
+
}
|
|
45
55
|
onCopied && onCopied(copyText, value);
|
|
46
56
|
setCopied(true);
|
|
47
57
|
var _clipboard = navigator.clipboard || {
|
package/esm/index.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
72
72
|
}) => void;
|
|
73
73
|
/** Fires event when you copy */
|
|
74
74
|
onCopied?: (text: string, value?: T) => void;
|
|
75
|
+
/** Transform the text before copying to clipboard */
|
|
76
|
+
beforeCopy?: (copyText: string, keyName?: string | number, value?: T, parentValue?: T, expandKey?: string, keys?: (number | string)[]) => string;
|
|
75
77
|
}
|
|
76
78
|
type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
|
|
77
79
|
Bigint: typeof Bigint;
|
package/esm/index.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", "style", "value", "children", "collapsed", "shouldExpandNodeInitially", "indentWidth", "displayObjectSize", "shortenTextAfterLength", "stringEllipsis", "highlightUpdates", "enableClipboard", "displayDataTypes", "objectSortKeys", "onExpand", "onCopied"];
|
|
3
|
+
var _excluded = ["className", "style", "value", "children", "collapsed", "shouldExpandNodeInitially", "indentWidth", "displayObjectSize", "shortenTextAfterLength", "stringEllipsis", "highlightUpdates", "enableClipboard", "displayDataTypes", "objectSortKeys", "onExpand", "onCopied", "beforeCopy"];
|
|
4
4
|
import { forwardRef } from 'react';
|
|
5
5
|
import { Provider } from "./store.js";
|
|
6
6
|
import { Container } from "./Container.js";
|
|
@@ -55,7 +55,8 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
55
55
|
displayDataTypes = true,
|
|
56
56
|
objectSortKeys = false,
|
|
57
57
|
onExpand,
|
|
58
|
-
onCopied
|
|
58
|
+
onCopied,
|
|
59
|
+
beforeCopy
|
|
59
60
|
} = props,
|
|
60
61
|
elmProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
61
62
|
var defaultStyle = _extends({
|
|
@@ -79,7 +80,8 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
79
80
|
stringEllipsis,
|
|
80
81
|
highlightUpdates,
|
|
81
82
|
onCopied,
|
|
82
|
-
onExpand
|
|
83
|
+
onExpand,
|
|
84
|
+
beforeCopy
|
|
83
85
|
},
|
|
84
86
|
initialTypes: {
|
|
85
87
|
displayDataTypes
|
package/esm/section/Copied.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type TagType } from '../store/Types';
|
|
2
2
|
import { type SectionElement } from '../store/Section';
|
|
3
|
+
export type CopiedSectionElement<T extends TagType = 'svg'> = SectionElement<T> & {
|
|
4
|
+
beforeCopy?: (copyText: string, keyName?: string | number, value?: object, parentValue?: object, expandKey?: string, keys?: (number | string)[]) => string;
|
|
5
|
+
};
|
|
3
6
|
export declare const Copied: {
|
|
4
|
-
<K extends TagType = "svg">(props:
|
|
7
|
+
<K extends TagType = "svg">(props: CopiedSectionElement<K>): null;
|
|
5
8
|
displayName: string;
|
|
6
9
|
};
|
package/esm/store.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface InitialState<T extends object> {
|
|
|
6
6
|
value?: object;
|
|
7
7
|
onExpand?: JsonViewProps<object>['onExpand'];
|
|
8
8
|
onCopied?: JsonViewProps<object>['onCopied'];
|
|
9
|
+
beforeCopy?: JsonViewProps<T>['beforeCopy'];
|
|
9
10
|
objectSortKeys?: JsonViewProps<T>['objectSortKeys'];
|
|
10
11
|
displayObjectSize?: JsonViewProps<T>['displayObjectSize'];
|
|
11
12
|
shortenTextAfterLength?: JsonViewProps<T>['shortenTextAfterLength'];
|
package/package.json
CHANGED
package/triangle-arrow.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module '@uiw/react-json-view/triangle-arrow' {
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export interface TriangleArrowProps extends React.SVGProps<SVGSVGElement> {
|
|
4
|
-
export function TriangleArrow(props: TriangleArrowProps): import(
|
|
3
|
+
export interface TriangleArrowProps extends React.SVGProps<SVGSVGElement> {}
|
|
4
|
+
export function TriangleArrow(props: TriangleArrowProps): import('react/jsx-runtime').JSX.Element;
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module '@uiw/react-json-view/triangle-solid-arrow' {
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export interface TriangleSolidArrowProps extends React.SVGProps<SVGSVGElement> {
|
|
4
|
-
export function TriangleSolidArrow(props: TriangleSolidArrowProps): import(
|
|
3
|
+
export interface TriangleSolidArrowProps extends React.SVGProps<SVGSVGElement> {}
|
|
4
|
+
export function TriangleSolidArrow(props: TriangleSolidArrowProps): import('react/jsx-runtime').JSX.Element;
|
|
5
5
|
}
|