@uiw/react-json-view 2.0.0-alpha.5 → 2.0.0-alpha.7
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 +4 -0
- package/cjs/comps/Copied.js +14 -11
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/store/Types.d.ts +27 -24
- package/cjs/store/Types.js +7 -6
- package/cjs/store.d.ts +7 -4
- package/cjs/types/index.js +5 -2
- package/esm/comps/Copied.js +14 -11
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/store/Types.d.ts +27 -24
- package/esm/store/Types.js +6 -4
- package/esm/store.d.ts +7 -4
- package/esm/types/index.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -696,8 +696,12 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
696
696
|
displayDataTypes?: boolean;
|
|
697
697
|
/** The user can copy objects and arrays to clipboard by clicking on the clipboard icon. @default true */
|
|
698
698
|
enableClipboard?: boolean;
|
|
699
|
+
/** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
|
|
700
|
+
collapsed?: boolean | number;
|
|
699
701
|
/** Whether to highlight updates. @default true */
|
|
700
702
|
highlightUpdates?: boolean;
|
|
703
|
+
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
|
|
704
|
+
shortenTextAfterLength?: number;
|
|
701
705
|
/** Callback function for when a treeNode is expanded or collapsed */
|
|
702
706
|
onExpand?: (props: {
|
|
703
707
|
expand: boolean;
|
package/cjs/comps/Copied.js
CHANGED
|
@@ -35,18 +35,21 @@ var Copied = function Copied(props) {
|
|
|
35
35
|
if (enableClipboard === false || !isShowTools) return null;
|
|
36
36
|
var click = function click(event) {
|
|
37
37
|
event.stopPropagation();
|
|
38
|
-
var copyText =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
38
|
+
var copyText = '';
|
|
39
|
+
if (typeof value === 'number' && value === Infinity) {
|
|
40
|
+
copyText = 'Infinity';
|
|
41
|
+
} else if (typeof value === 'number' && isNaN(value)) {
|
|
42
|
+
copyText = 'NaN';
|
|
43
|
+
} else if (typeof value === 'bigint') {
|
|
44
|
+
copyText = value + 'n';
|
|
45
|
+
} else if (value instanceof Date) {
|
|
46
|
+
copyText = value.toLocaleString();
|
|
47
|
+
} else {
|
|
48
|
+
copyText = JSON.stringify(value, null, 2);
|
|
49
|
+
}
|
|
50
|
+
onCopied && onCopied(copyText, value);
|
|
51
|
+
setCopied(true);
|
|
47
52
|
navigator.clipboard.writeText(copyText).then(function () {
|
|
48
|
-
onCopied && onCopied(copyText, value);
|
|
49
|
-
setCopied(true);
|
|
50
53
|
var timer = setTimeout(function () {
|
|
51
54
|
setCopied(false);
|
|
52
55
|
clearTimeout(timer);
|
package/cjs/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
50
50
|
collapsed?: boolean | number;
|
|
51
51
|
/** Whether to highlight updates. @default true */
|
|
52
52
|
highlightUpdates?: boolean;
|
|
53
|
-
/** Shorten long JSON strings, Set to `0` to disable this feature @default
|
|
53
|
+
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
|
|
54
54
|
shortenTextAfterLength?: number;
|
|
55
55
|
/** Callback function for when a treeNode is expanded or collapsed */
|
|
56
56
|
onExpand?: (props: {
|
package/cjs/index.js
CHANGED
|
@@ -122,7 +122,7 @@ var JsonView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
122
122
|
_props$displayObjectS = props.displayObjectSize,
|
|
123
123
|
displayObjectSize = _props$displayObjectS === void 0 ? true : _props$displayObjectS,
|
|
124
124
|
_props$shortenTextAft = props.shortenTextAfterLength,
|
|
125
|
-
shortenTextAfterLength = _props$shortenTextAft === void 0 ?
|
|
125
|
+
shortenTextAfterLength = _props$shortenTextAft === void 0 ? 30 : _props$shortenTextAft,
|
|
126
126
|
_props$highlightUpdat = props.highlightUpdates,
|
|
127
127
|
highlightUpdates = _props$highlightUpdat === void 0 ? true : _props$highlightUpdat,
|
|
128
128
|
_props$enableClipboar = props.enableClipboard,
|
package/cjs/store/Types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren, ComponentPropsWithoutRef } from 'react';
|
|
2
2
|
export type TagType = React.ElementType | keyof JSX.IntrinsicElements;
|
|
3
|
-
type TypesElementProps<T extends TagType> = {
|
|
3
|
+
type TypesElementProps<T extends TagType = 'span'> = {
|
|
4
4
|
as?: T;
|
|
5
5
|
render?: (props: TypesElement<T>, result: {
|
|
6
6
|
type: 'type' | 'value';
|
|
@@ -9,24 +9,24 @@ type TypesElementProps<T extends TagType> = {
|
|
|
9
9
|
'data-type'?: string;
|
|
10
10
|
};
|
|
11
11
|
export type TypesElement<T extends TagType> = TypesElementProps<T> & ComponentPropsWithoutRef<T>;
|
|
12
|
-
export type InitialTypesState = {
|
|
12
|
+
export type InitialTypesState<T extends TagType = 'span'> = {
|
|
13
13
|
displayDataTypes?: boolean;
|
|
14
|
-
Url?: TypesElement<
|
|
15
|
-
Str?: TypesElement<
|
|
16
|
-
Undefined?: TypesElement<
|
|
17
|
-
Null?: TypesElement<
|
|
18
|
-
True?: TypesElement<
|
|
19
|
-
False?: TypesElement<
|
|
20
|
-
Date?: TypesElement<
|
|
21
|
-
Float?: TypesElement<
|
|
22
|
-
Set?: TypesElement<
|
|
23
|
-
Int?: TypesElement<
|
|
24
|
-
Map?: TypesElement<
|
|
25
|
-
Nan?: TypesElement<
|
|
26
|
-
Bigint?: TypesElement<
|
|
14
|
+
Url?: TypesElement<T>;
|
|
15
|
+
Str?: TypesElement<T>;
|
|
16
|
+
Undefined?: TypesElement<T>;
|
|
17
|
+
Null?: TypesElement<T>;
|
|
18
|
+
True?: TypesElement<T>;
|
|
19
|
+
False?: TypesElement<T>;
|
|
20
|
+
Date?: TypesElement<T>;
|
|
21
|
+
Float?: TypesElement<T>;
|
|
22
|
+
Set?: TypesElement<T>;
|
|
23
|
+
Int?: TypesElement<T>;
|
|
24
|
+
Map?: TypesElement<T>;
|
|
25
|
+
Nan?: TypesElement<T>;
|
|
26
|
+
Bigint?: TypesElement<T>;
|
|
27
27
|
};
|
|
28
|
-
type Dispatch = React.Dispatch<InitialTypesState
|
|
29
|
-
export declare const useTypesStore: () => InitialTypesState
|
|
28
|
+
type Dispatch<T extends TagType> = React.Dispatch<InitialTypesState<T>>;
|
|
29
|
+
export declare const useTypesStore: () => InitialTypesState<TagType>;
|
|
30
30
|
export declare function useTypes(): [{
|
|
31
31
|
displayDataTypes?: boolean | undefined;
|
|
32
32
|
Url?: TypesElement<TagType> | undefined;
|
|
@@ -42,11 +42,14 @@ export declare function useTypes(): [{
|
|
|
42
42
|
Map?: TypesElement<TagType> | undefined;
|
|
43
43
|
Nan?: TypesElement<TagType> | undefined;
|
|
44
44
|
Bigint?: TypesElement<TagType> | undefined;
|
|
45
|
-
}, import("react").Dispatch<InitialTypesState
|
|
46
|
-
export declare function useTypesDispatch(): Dispatch
|
|
47
|
-
interface TypesProps {
|
|
48
|
-
initial: InitialTypesState
|
|
49
|
-
dispatch: Dispatch
|
|
45
|
+
}, import("react").Dispatch<InitialTypesState<TagType>>];
|
|
46
|
+
export declare function useTypesDispatch(): Dispatch<TagType>;
|
|
47
|
+
interface TypesProps<T extends TagType> {
|
|
48
|
+
initial: InitialTypesState<T>;
|
|
49
|
+
dispatch: Dispatch<TagType>;
|
|
50
|
+
}
|
|
51
|
+
export declare function Types<T extends TagType>({ initial, dispatch, children }: PropsWithChildren<TypesProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
export declare namespace Types {
|
|
53
|
+
var displayName: string;
|
|
50
54
|
}
|
|
51
|
-
export declare const Types: FC<PropsWithChildren<TypesProps>>;
|
|
52
55
|
export {};
|
package/cjs/store/Types.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.Types =
|
|
7
|
+
exports.Types = Types;
|
|
8
8
|
exports.useTypes = useTypes;
|
|
9
9
|
exports.useTypesDispatch = useTypesDispatch;
|
|
10
10
|
exports.useTypesStore = void 0;
|
|
@@ -50,7 +50,8 @@ var initialState = {
|
|
|
50
50
|
},
|
|
51
51
|
Map: {
|
|
52
52
|
style: {
|
|
53
|
-
color: 'var(--w-rjv-type-map-color, #268bd2)'
|
|
53
|
+
color: 'var(--w-rjv-type-map-color, #268bd2)',
|
|
54
|
+
marginRight: 3
|
|
54
55
|
},
|
|
55
56
|
as: 'span',
|
|
56
57
|
'data-type': 'map',
|
|
@@ -86,7 +87,8 @@ var initialState = {
|
|
|
86
87
|
},
|
|
87
88
|
Set: {
|
|
88
89
|
style: {
|
|
89
|
-
color: 'var(--w-rjv-type-set-color, #268bd2)'
|
|
90
|
+
color: 'var(--w-rjv-type-set-color, #268bd2)',
|
|
91
|
+
marginRight: 3
|
|
90
92
|
},
|
|
91
93
|
as: 'span',
|
|
92
94
|
'data-type': 'set',
|
|
@@ -146,7 +148,7 @@ function useTypes() {
|
|
|
146
148
|
function useTypesDispatch() {
|
|
147
149
|
return (0, _react.useContext)(DispatchTypes);
|
|
148
150
|
}
|
|
149
|
-
|
|
151
|
+
function Types(_ref) {
|
|
150
152
|
var initial = _ref.initial,
|
|
151
153
|
dispatch = _ref.dispatch,
|
|
152
154
|
children = _ref.children;
|
|
@@ -157,6 +159,5 @@ var Types = function Types(_ref) {
|
|
|
157
159
|
children: children
|
|
158
160
|
})
|
|
159
161
|
});
|
|
160
|
-
}
|
|
161
|
-
exports.Types = Types;
|
|
162
|
+
}
|
|
162
163
|
Types.displayName = 'JVR.Types';
|
package/cjs/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
import { JsonViewProps } from './';
|
|
3
|
-
import { type InitialTypesState } from './store/Types';
|
|
3
|
+
import { type InitialTypesState, type TagType } from './store/Types';
|
|
4
4
|
export type BlockTagType = keyof JSX.IntrinsicElements;
|
|
5
5
|
export interface InitialState<T extends object> {
|
|
6
6
|
value?: object;
|
|
@@ -20,10 +20,13 @@ export declare const Context: React.Context<InitialState<object>>;
|
|
|
20
20
|
export declare function reducer(state: InitialState<object>, action: InitialState<object>): InitialState<object>;
|
|
21
21
|
export declare const useStore: () => InitialState<object>;
|
|
22
22
|
export declare const useDispatchStore: () => Dispatch;
|
|
23
|
-
export interface ProviderProps {
|
|
23
|
+
export interface ProviderProps<T extends TagType> {
|
|
24
24
|
initialState?: InitialState<object>;
|
|
25
|
-
initialTypes?: InitialTypesState
|
|
25
|
+
initialTypes?: InitialTypesState<T>;
|
|
26
26
|
}
|
|
27
|
-
export declare const Provider:
|
|
27
|
+
export declare const Provider: {
|
|
28
|
+
<T extends TagType>({ children, initialState: init, initialTypes, }: React.PropsWithChildren<ProviderProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
displayName: string;
|
|
30
|
+
};
|
|
28
31
|
export declare function useDispatch(): Dispatch;
|
|
29
32
|
export {};
|
package/cjs/types/index.js
CHANGED
|
@@ -86,7 +86,7 @@ var TypeString = function TypeString(_ref3) {
|
|
|
86
86
|
displayDataTypes = _useTypesStore3.displayDataTypes;
|
|
87
87
|
var _useStore = (0, _store.useStore)(),
|
|
88
88
|
_useStore$shortenText = _useStore.shortenTextAfterLength,
|
|
89
|
-
length = _useStore$shortenText === void 0 ?
|
|
89
|
+
length = _useStore$shortenText === void 0 ? 30 : _useStore$shortenText;
|
|
90
90
|
var as = Str.as,
|
|
91
91
|
render = Str.render,
|
|
92
92
|
reset = (0, _objectWithoutProperties2["default"])(Str, _excluded3);
|
|
@@ -95,6 +95,9 @@ var TypeString = function TypeString(_ref3) {
|
|
|
95
95
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
96
96
|
shorten = _useState2[0],
|
|
97
97
|
setShorten = _useState2[1];
|
|
98
|
+
(0, _react.useEffect)(function () {
|
|
99
|
+
return setShorten(length && childrenStr.length >= length);
|
|
100
|
+
}, [length]);
|
|
98
101
|
var Comp = as || 'span';
|
|
99
102
|
var style = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, defalutStyle), Str.style || {});
|
|
100
103
|
if (length > 0) {
|
|
@@ -414,7 +417,7 @@ var TypeDate = function TypeDate(_ref10) {
|
|
|
414
417
|
type: 'type',
|
|
415
418
|
value: children
|
|
416
419
|
});
|
|
417
|
-
var childStr = children
|
|
420
|
+
var childStr = children instanceof Date ? children.toLocaleString() : children;
|
|
418
421
|
var child = isRender && render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
|
|
419
422
|
children: childStr,
|
|
420
423
|
className: 'w-rjv-value'
|
package/esm/comps/Copied.js
CHANGED
|
@@ -27,18 +27,21 @@ export var Copied = props => {
|
|
|
27
27
|
if (enableClipboard === false || !isShowTools) return null;
|
|
28
28
|
var click = event => {
|
|
29
29
|
event.stopPropagation();
|
|
30
|
-
var copyText =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
30
|
+
var copyText = '';
|
|
31
|
+
if (typeof value === 'number' && value === Infinity) {
|
|
32
|
+
copyText = 'Infinity';
|
|
33
|
+
} else if (typeof value === 'number' && isNaN(value)) {
|
|
34
|
+
copyText = 'NaN';
|
|
35
|
+
} else if (typeof value === 'bigint') {
|
|
36
|
+
copyText = value + 'n';
|
|
37
|
+
} else if (value instanceof Date) {
|
|
38
|
+
copyText = value.toLocaleString();
|
|
39
|
+
} else {
|
|
40
|
+
copyText = JSON.stringify(value, null, 2);
|
|
41
|
+
}
|
|
42
|
+
onCopied && onCopied(copyText, value);
|
|
43
|
+
setCopied(true);
|
|
39
44
|
navigator.clipboard.writeText(copyText).then(() => {
|
|
40
|
-
onCopied && onCopied(copyText, value);
|
|
41
|
-
setCopied(true);
|
|
42
45
|
var timer = setTimeout(() => {
|
|
43
46
|
setCopied(false);
|
|
44
47
|
clearTimeout(timer);
|
package/esm/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
|
|
|
50
50
|
collapsed?: boolean | number;
|
|
51
51
|
/** Whether to highlight updates. @default true */
|
|
52
52
|
highlightUpdates?: boolean;
|
|
53
|
-
/** Shorten long JSON strings, Set to `0` to disable this feature @default
|
|
53
|
+
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
|
|
54
54
|
shortenTextAfterLength?: number;
|
|
55
55
|
/** Callback function for when a treeNode is expanded or collapsed */
|
|
56
56
|
onExpand?: (props: {
|
package/esm/index.js
CHANGED
|
@@ -47,7 +47,7 @@ var JsonView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
47
47
|
collapsed,
|
|
48
48
|
indentWidth = 15,
|
|
49
49
|
displayObjectSize = true,
|
|
50
|
-
shortenTextAfterLength =
|
|
50
|
+
shortenTextAfterLength = 30,
|
|
51
51
|
highlightUpdates = true,
|
|
52
52
|
enableClipboard = true,
|
|
53
53
|
displayDataTypes = true,
|
package/esm/store/Types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren, ComponentPropsWithoutRef } from 'react';
|
|
2
2
|
export type TagType = React.ElementType | keyof JSX.IntrinsicElements;
|
|
3
|
-
type TypesElementProps<T extends TagType> = {
|
|
3
|
+
type TypesElementProps<T extends TagType = 'span'> = {
|
|
4
4
|
as?: T;
|
|
5
5
|
render?: (props: TypesElement<T>, result: {
|
|
6
6
|
type: 'type' | 'value';
|
|
@@ -9,24 +9,24 @@ type TypesElementProps<T extends TagType> = {
|
|
|
9
9
|
'data-type'?: string;
|
|
10
10
|
};
|
|
11
11
|
export type TypesElement<T extends TagType> = TypesElementProps<T> & ComponentPropsWithoutRef<T>;
|
|
12
|
-
export type InitialTypesState = {
|
|
12
|
+
export type InitialTypesState<T extends TagType = 'span'> = {
|
|
13
13
|
displayDataTypes?: boolean;
|
|
14
|
-
Url?: TypesElement<
|
|
15
|
-
Str?: TypesElement<
|
|
16
|
-
Undefined?: TypesElement<
|
|
17
|
-
Null?: TypesElement<
|
|
18
|
-
True?: TypesElement<
|
|
19
|
-
False?: TypesElement<
|
|
20
|
-
Date?: TypesElement<
|
|
21
|
-
Float?: TypesElement<
|
|
22
|
-
Set?: TypesElement<
|
|
23
|
-
Int?: TypesElement<
|
|
24
|
-
Map?: TypesElement<
|
|
25
|
-
Nan?: TypesElement<
|
|
26
|
-
Bigint?: TypesElement<
|
|
14
|
+
Url?: TypesElement<T>;
|
|
15
|
+
Str?: TypesElement<T>;
|
|
16
|
+
Undefined?: TypesElement<T>;
|
|
17
|
+
Null?: TypesElement<T>;
|
|
18
|
+
True?: TypesElement<T>;
|
|
19
|
+
False?: TypesElement<T>;
|
|
20
|
+
Date?: TypesElement<T>;
|
|
21
|
+
Float?: TypesElement<T>;
|
|
22
|
+
Set?: TypesElement<T>;
|
|
23
|
+
Int?: TypesElement<T>;
|
|
24
|
+
Map?: TypesElement<T>;
|
|
25
|
+
Nan?: TypesElement<T>;
|
|
26
|
+
Bigint?: TypesElement<T>;
|
|
27
27
|
};
|
|
28
|
-
type Dispatch = React.Dispatch<InitialTypesState
|
|
29
|
-
export declare const useTypesStore: () => InitialTypesState
|
|
28
|
+
type Dispatch<T extends TagType> = React.Dispatch<InitialTypesState<T>>;
|
|
29
|
+
export declare const useTypesStore: () => InitialTypesState<TagType>;
|
|
30
30
|
export declare function useTypes(): [{
|
|
31
31
|
displayDataTypes?: boolean | undefined;
|
|
32
32
|
Url?: TypesElement<TagType> | undefined;
|
|
@@ -42,11 +42,14 @@ export declare function useTypes(): [{
|
|
|
42
42
|
Map?: TypesElement<TagType> | undefined;
|
|
43
43
|
Nan?: TypesElement<TagType> | undefined;
|
|
44
44
|
Bigint?: TypesElement<TagType> | undefined;
|
|
45
|
-
}, import("react").Dispatch<InitialTypesState
|
|
46
|
-
export declare function useTypesDispatch(): Dispatch
|
|
47
|
-
interface TypesProps {
|
|
48
|
-
initial: InitialTypesState
|
|
49
|
-
dispatch: Dispatch
|
|
45
|
+
}, import("react").Dispatch<InitialTypesState<TagType>>];
|
|
46
|
+
export declare function useTypesDispatch(): Dispatch<TagType>;
|
|
47
|
+
interface TypesProps<T extends TagType> {
|
|
48
|
+
initial: InitialTypesState<T>;
|
|
49
|
+
dispatch: Dispatch<TagType>;
|
|
50
|
+
}
|
|
51
|
+
export declare function Types<T extends TagType>({ initial, dispatch, children }: PropsWithChildren<TypesProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
export declare namespace Types {
|
|
53
|
+
var displayName: string;
|
|
50
54
|
}
|
|
51
|
-
export declare const Types: FC<PropsWithChildren<TypesProps>>;
|
|
52
55
|
export {};
|
package/esm/store/Types.js
CHANGED
|
@@ -40,7 +40,8 @@ var initialState = {
|
|
|
40
40
|
},
|
|
41
41
|
Map: {
|
|
42
42
|
style: {
|
|
43
|
-
color: 'var(--w-rjv-type-map-color, #268bd2)'
|
|
43
|
+
color: 'var(--w-rjv-type-map-color, #268bd2)',
|
|
44
|
+
marginRight: 3
|
|
44
45
|
},
|
|
45
46
|
as: 'span',
|
|
46
47
|
'data-type': 'map',
|
|
@@ -76,7 +77,8 @@ var initialState = {
|
|
|
76
77
|
},
|
|
77
78
|
Set: {
|
|
78
79
|
style: {
|
|
79
|
-
color: 'var(--w-rjv-type-set-color, #268bd2)'
|
|
80
|
+
color: 'var(--w-rjv-type-set-color, #268bd2)',
|
|
81
|
+
marginRight: 3
|
|
80
82
|
},
|
|
81
83
|
as: 'span',
|
|
82
84
|
'data-type': 'set',
|
|
@@ -133,7 +135,7 @@ export function useTypes() {
|
|
|
133
135
|
export function useTypesDispatch() {
|
|
134
136
|
return useContext(DispatchTypes);
|
|
135
137
|
}
|
|
136
|
-
export
|
|
138
|
+
export function Types(_ref) {
|
|
137
139
|
var {
|
|
138
140
|
initial,
|
|
139
141
|
dispatch,
|
|
@@ -146,5 +148,5 @@ export var Types = _ref => {
|
|
|
146
148
|
children: children
|
|
147
149
|
})
|
|
148
150
|
});
|
|
149
|
-
}
|
|
151
|
+
}
|
|
150
152
|
Types.displayName = 'JVR.Types';
|
package/esm/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
import { JsonViewProps } from './';
|
|
3
|
-
import { type InitialTypesState } from './store/Types';
|
|
3
|
+
import { type InitialTypesState, type TagType } from './store/Types';
|
|
4
4
|
export type BlockTagType = keyof JSX.IntrinsicElements;
|
|
5
5
|
export interface InitialState<T extends object> {
|
|
6
6
|
value?: object;
|
|
@@ -20,10 +20,13 @@ export declare const Context: React.Context<InitialState<object>>;
|
|
|
20
20
|
export declare function reducer(state: InitialState<object>, action: InitialState<object>): InitialState<object>;
|
|
21
21
|
export declare const useStore: () => InitialState<object>;
|
|
22
22
|
export declare const useDispatchStore: () => Dispatch;
|
|
23
|
-
export interface ProviderProps {
|
|
23
|
+
export interface ProviderProps<T extends TagType> {
|
|
24
24
|
initialState?: InitialState<object>;
|
|
25
|
-
initialTypes?: InitialTypesState
|
|
25
|
+
initialTypes?: InitialTypesState<T>;
|
|
26
26
|
}
|
|
27
|
-
export declare const Provider:
|
|
27
|
+
export declare const Provider: {
|
|
28
|
+
<T extends TagType>({ children, initialState: init, initialTypes, }: React.PropsWithChildren<ProviderProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
displayName: string;
|
|
30
|
+
};
|
|
28
31
|
export declare function useDispatch(): Dispatch;
|
|
29
32
|
export {};
|
package/esm/types/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var _excluded = ["as", "render"],
|
|
|
13
13
|
_excluded11 = ["as", "render"],
|
|
14
14
|
_excluded12 = ["as", "render"],
|
|
15
15
|
_excluded13 = ["as", "render"];
|
|
16
|
-
import { Fragment, useState } from 'react';
|
|
16
|
+
import { Fragment, useEffect, useState } from 'react';
|
|
17
17
|
import { useTypesStore } from '../store/Types';
|
|
18
18
|
import { useStore } from '../store';
|
|
19
19
|
import { ValueQuote } from '../symbol';
|
|
@@ -85,7 +85,7 @@ export var TypeString = _ref3 => {
|
|
|
85
85
|
displayDataTypes
|
|
86
86
|
} = useTypesStore();
|
|
87
87
|
var {
|
|
88
|
-
shortenTextAfterLength: length =
|
|
88
|
+
shortenTextAfterLength: length = 30
|
|
89
89
|
} = useStore();
|
|
90
90
|
var {
|
|
91
91
|
as,
|
|
@@ -94,6 +94,7 @@ export var TypeString = _ref3 => {
|
|
|
94
94
|
reset = _objectWithoutPropertiesLoose(Str, _excluded3);
|
|
95
95
|
var childrenStr = children;
|
|
96
96
|
var [shorten, setShorten] = useState(length && childrenStr.length >= length);
|
|
97
|
+
useEffect(() => setShorten(length && childrenStr.length >= length), [length]);
|
|
97
98
|
var Comp = as || 'span';
|
|
98
99
|
var style = _extends({}, defalutStyle, Str.style || {});
|
|
99
100
|
if (length > 0) {
|
|
@@ -434,7 +435,7 @@ export var TypeDate = _ref10 => {
|
|
|
434
435
|
type: 'type',
|
|
435
436
|
value: children
|
|
436
437
|
});
|
|
437
|
-
var childStr = children
|
|
438
|
+
var childStr = children instanceof Date ? children.toLocaleString() : children;
|
|
438
439
|
var child = isRender && render(_extends({}, reset, {
|
|
439
440
|
children: childStr,
|
|
440
441
|
className: 'w-rjv-value'
|