@uiw/react-json-view 2.0.0-alpha.6 → 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.
@@ -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 = JSON.stringify(value, function (key, value) {
39
- if (typeof value === 'bigint') {
40
- return value.toString();
41
- }
42
- return value;
43
- }, 2);
44
- if (typeof value === 'number' && value === Infinity) copyText = 'Infinity';
45
- if (typeof value === 'number' && isNaN(value)) copyText = 'NaN';
46
- if (typeof value === 'bigint') copyText = value + 'n';
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);
@@ -1,6 +1,6 @@
1
- import { FC, PropsWithChildren, ComponentPropsWithoutRef } from 'react';
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<TagType>;
15
- Str?: TypesElement<TagType>;
16
- Undefined?: TypesElement<TagType>;
17
- Null?: TypesElement<TagType>;
18
- True?: TypesElement<TagType>;
19
- False?: TypesElement<TagType>;
20
- Date?: TypesElement<TagType>;
21
- Float?: TypesElement<TagType>;
22
- Set?: TypesElement<TagType>;
23
- Int?: TypesElement<TagType>;
24
- Map?: TypesElement<TagType>;
25
- Nan?: TypesElement<TagType>;
26
- Bigint?: TypesElement<TagType>;
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 {};
@@ -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 = void 0;
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
- var Types = function Types(_ref) {
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: React.FC<PropsWithChildren<ProviderProps>>;
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 {};
@@ -417,7 +417,7 @@ var TypeDate = function TypeDate(_ref10) {
417
417
  type: 'type',
418
418
  value: children
419
419
  });
420
- var childStr = children === null || children === void 0 ? void 0 : children.toString();
420
+ var childStr = children instanceof Date ? children.toLocaleString() : children;
421
421
  var child = isRender && render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
422
422
  children: childStr,
423
423
  className: 'w-rjv-value'
@@ -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 = JSON.stringify(value, (key, value) => {
31
- if (typeof value === 'bigint') {
32
- return value.toString();
33
- }
34
- return value;
35
- }, 2);
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';
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);
@@ -1,6 +1,6 @@
1
- import { FC, PropsWithChildren, ComponentPropsWithoutRef } from 'react';
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<TagType>;
15
- Str?: TypesElement<TagType>;
16
- Undefined?: TypesElement<TagType>;
17
- Null?: TypesElement<TagType>;
18
- True?: TypesElement<TagType>;
19
- False?: TypesElement<TagType>;
20
- Date?: TypesElement<TagType>;
21
- Float?: TypesElement<TagType>;
22
- Set?: TypesElement<TagType>;
23
- Int?: TypesElement<TagType>;
24
- Map?: TypesElement<TagType>;
25
- Nan?: TypesElement<TagType>;
26
- Bigint?: TypesElement<TagType>;
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 {};
@@ -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 var Types = _ref => {
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: React.FC<PropsWithChildren<ProviderProps>>;
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 {};
@@ -435,7 +435,7 @@ export var TypeDate = _ref10 => {
435
435
  type: 'type',
436
436
  value: children
437
437
  });
438
- var childStr = children == null ? void 0 : children.toString();
438
+ var childStr = children instanceof Date ? children.toLocaleString() : children;
439
439
  var child = isRender && render(_extends({}, reset, {
440
440
  children: childStr,
441
441
  className: 'w-rjv-value'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-json-view",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.7",
4
4
  "description": "JSON viewer for react.",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",