Skip to content

Commit f15b993

Browse files
committed
fix: fix NaN display & font size style.
1 parent 1be3b2d commit f15b993

File tree

6 files changed

+12
-43
lines changed

6 files changed

+12
-43
lines changed

core/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ const object = {
190190
null: null,
191191
undefined,
192192
timer: 0,
193+
nan: NaN,
193194
url: new URL('https://example.com'),
194195
date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'),
195196
array: [19, 100.86, 'test', NaN, Infinity],

core/src/editor/value.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ export function ReValue<T extends object>(props: ReValueProps<T>) {
102102
} else if (typeof text === 'string' && /^(null)$/gi.test(text)) {
103103
text = null;
104104
typeStr = 'null';
105+
} else if (typeof text === 'string' && /^(NaN)$/gi.test(text)) {
106+
text = NaN;
107+
typeStr = 'NaN';
105108
} else if (typeof text === 'string' && /^(undefined)$/gi.test(text)) {
106109
text = undefined;
107110
typeStr = 'undefined';
@@ -142,7 +145,7 @@ export function ReValue<T extends object>(props: ReValueProps<T>) {
142145
style: editable ? { ...style, ...defaultStyle, color } : { ...style, color },
143146
};
144147
let typeView = <Type type={typeStr} />;
145-
if (typeStr === 'null' || typeStr === 'undefined') {
148+
if (typeStr === 'null' || typeStr === 'undefined' || type.toLocaleLowerCase() === 'nan') {
146149
typeView = <Fragment />;
147150
}
148151
const deleteHandle = async (evn: React.MouseEvent<SVGSVGElement, MouseEvent>) => {

core/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const JsonView = forwardRef<HTMLDivElement, JsonViewProps<object>>((props, ref)
7878
fontFamily: 'var(--w-rjv-font-family, Menlo, monospace)',
7979
color: 'var(--w-rjv-color, #002b36)',
8080
backgroundColor: 'var(--w-rjv-background-color, #00000000)',
81+
fontSize: 13,
8182
...style,
8283
} as React.CSSProperties;
8384
const cls = `w-json-view-container w-rjv ${className || ''}`;

core/src/value.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,10 @@ export function ValueView<T extends object>(props: ValueViewProps<T>) {
211211
typeView = <Fragment />;
212212
style = { fontWeight: 'bold' };
213213
}
214-
if (value === undefined || type === 'NaN') {
214+
if (value === undefined || type.toLocaleLowerCase() === 'nan' || !displayDataTypes) {
215215
typeView = <Fragment />;
216216
}
217217
const isURL = value instanceof URL;
218-
219-
if (!displayDataTypes) {
220-
typeView = <Fragment />;
221-
}
222218
color = typeMap[type]?.color || '';
223219

224220
const [showTools, setShowTools] = useState(false);

www/src/example/default.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { monokaiTheme } from '@uiw/react-json-view/monokai';
1212
import { basicTheme } from '@uiw/react-json-view/basic';
1313

1414
export const themesData = {
15-
basic: basicTheme,
15+
nord: nordTheme,
1616
light: lightTheme,
1717
dark: darkTheme,
18-
nord: nordTheme,
18+
basic: basicTheme,
1919
vscode: vscodeTheme,
2020
githubLight: githubLightTheme,
2121
githubDark: githubDarkTheme,
@@ -28,13 +28,14 @@ const avatar = 'https://i.imgur.com/1bX5QH6.jpg';
2828
function aPlusB(a: number, b: number) {
2929
return a + b;
3030
}
31-
const example = {
31+
export const example = {
3232
avatar,
3333
string: 'Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet',
3434
integer: 42,
3535
float: 114.514,
3636
// @ts-ignore
3737
bigint: 10086n,
38+
nan: NaN,
3839
null: null,
3940
undefined,
4041
boolean: true,

www/src/example/editor.tsx

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,7 @@
11
import { Fragment, useState, useEffect } from 'react';
22
import { styled } from 'styled-components';
33
import JsonViewEditor from '@uiw/react-json-view/editor';
4-
import { themesData } from './default';
5-
6-
const avatar = 'https://i.imgur.com/1bX5QH6.jpg';
7-
// const longArray = new Array(1000).fill(1);
8-
function aPlusB(a: number, b: number) {
9-
return a + b;
10-
}
11-
const example = {
12-
avatar,
13-
string: 'Lorem ipsum dolor sit amet',
14-
integer: 42,
15-
float: 114.514,
16-
// @ts-ignore
17-
bigint: 10086n,
18-
null: null,
19-
undefined,
20-
boolean: true,
21-
timer: 0,
22-
date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'),
23-
array: [19, 100.86, 'test', NaN, Infinity],
24-
emptyArray: [],
25-
nestedArray: [[1, 2], [3, 4], { a: 1 }],
26-
object3: {},
27-
object2: {
28-
'first-child': true,
29-
'second-child': false,
30-
'last-child': null,
31-
a: { b: 1 },
32-
},
33-
fn: aPlusB,
34-
// longArray,
35-
string_number: '1234',
36-
string_empty: '',
37-
};
4+
import { themesData, example } from './default';
385

396
const Label = styled.label`
407
margin-top: 0.83rem;

0 commit comments

Comments
 (0)