Skip to content

Commit 66a9745

Browse files
committed
fix: show null and explicit undefined values
(cherry picked from commit 800c416)
1 parent 31c20f9 commit 66a9745

File tree

8 files changed

+28
-9
lines changed

8 files changed

+28
-9
lines changed

example/Basic.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ import VueJsonPretty from 'src';
9494
9595
const defaultData = {
9696
status: 200,
97-
error: '',
97+
text: '',
98+
error: null,
99+
config: undefined,
98100
data: [
99101
{
100102
news_id: 51184,

example/Editable.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ import VueJsonPretty from 'src';
5656
5757
const defaultData = {
5858
status: 200,
59-
error: '',
59+
text: '',
60+
error: null,
61+
config: undefined,
6062
data: [
6163
{
6264
news_id: 51184,

example/SelectControl.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ import VueJsonPretty from 'src';
9797
9898
const defaultData = {
9999
status: 200,
100-
error: '',
100+
text: '',
101+
error: null,
102+
config: undefined,
101103
data: [
102104
{
103105
news_id: 51184,

example/VirtualList.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ import VueJsonPretty from 'src';
4848
4949
const defaultData = {
5050
status: 200,
51-
error: '',
51+
text: '',
52+
error: null,
53+
config: undefined,
5254
data: [],
5355
};
5456

src/components/TreeNode/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ export default defineComponent({
145145
};
146146

147147
const defaultValue = computed(() => {
148-
const str = (props.node?.content ?? '') + '';
149-
const text = dataType.value === 'string' ? `"${str}"` : str;
150-
return text;
148+
let value = props.node?.content;
149+
if(value === null) {
150+
value = 'null'
151+
}
152+
if(value === undefined) {
153+
value = 'undefined'
154+
}
155+
return dataType.value === 'string' ? `"${value}"` : value + ''
151156
});
152157

153158
const renderValue = () => {

src/components/TreeNode/styles.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
.gen-value-style(@color-null);
5656
}
5757

58+
.@{css-prefix}-value-undefined {
59+
.gen-value-style(@color-undefined);
60+
}
61+
5862
.@{css-prefix}-value-number {
5963
.gen-value-style(@color-number);
6064
}

src/themes.less

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
@color-info: #1d8ce0;
77
@color-error: #ff4949;
88
@color-success: #13ce66;
9+
@color-nil: #D55FDE;
910

1011
/* field values color */
1112
@color-string: @color-success;
1213
@color-number: @color-info;
1314
@color-boolean: @color-info;
14-
@color-null: @color-error;
15+
@color-null: @color-nil;
16+
@color-undefined: @color-nil;
1517

1618
/* highlight */
1719
@highlight-bg-color: #e6f7ff;

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function arrFlat<T extends unknown[]>(arr: T): unknown[] {
133133
}
134134

135135
export function cloneDeep<T extends unknown>(source: T, hash = new WeakMap()): T {
136-
if (source === null) return source;
136+
if (source === null || source === undefined) return source;
137137
if (source instanceof Date) return new Date(source) as T;
138138
if (source instanceof RegExp) return new RegExp(source) as T;
139139
if (typeof source !== 'object') return source;

0 commit comments

Comments
 (0)