Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show null and explicit undefined values #207

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion example/Basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ import VueJsonPretty from 'src';

const defaultData = {
status: 200,
error: '',
text: '',
error: null,
config: undefined,
data: [
{
news_id: 51184,
Expand Down
4 changes: 3 additions & 1 deletion example/Editable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ import VueJsonPretty from 'src';

const defaultData = {
status: 200,
error: '',
text: '',
error: null,
config: undefined,
data: [
{
news_id: 51184,
Expand Down
4 changes: 3 additions & 1 deletion example/SelectControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ import VueJsonPretty from 'src';

const defaultData = {
status: 200,
error: '',
text: '',
error: null,
config: undefined,
data: [
{
news_id: 51184,
Expand Down
4 changes: 3 additions & 1 deletion example/VirtualList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import VueJsonPretty from 'src';

const defaultData = {
status: 200,
error: '',
text: '',
error: null,
config: undefined,
data: Array.from(Array(1000)).map((item, index) => ({
news_id: index,
title: 'iPhone X Review: Innovative future with real black technology',
Expand Down
8 changes: 5 additions & 3 deletions src/components/TreeNode/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ export default {
},

defaultValue() {
const str = (this.node?.content ?? '') + '';
const text = this.dataType === 'string' ? `"${str}"` : str;
return text;
let value = this.node?.content;
if(value === null || value === undefined) {
value += '';
}
return this.dataType === 'string' ? `"${value}"` : value
},
},
methods: {
Expand Down
4 changes: 4 additions & 0 deletions src/components/TreeNode/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
.gen-value-style(@color-null);
}

.@{css-prefix}-value-undefined {
.gen-value-style(@color-undefined);
}

.@{css-prefix}-value-number {
.gen-value-style(@color-number);
}
Expand Down
4 changes: 3 additions & 1 deletion src/themes.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
@color-info: #1d8ce0;
@color-error: #ff4949;
@color-success: #13ce66;
@color-nil: #D55FDE;

/* field values color */
@color-string: @color-success;
@color-number: @color-info;
@color-boolean: @color-info;
@color-null: @color-error;
@color-null: @color-nil;
@color-undefined: @color-nil;

/* highlight */
@highlight-bg-color: #e6f7ff;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function arrFlat(arr) {
}

export function cloneDeep(source, hash = new WeakMap()) {
if (source === null) return source;
if (source === null || source === undefined) return source;
if (source instanceof Date) return new Date(source);
if (source instanceof RegExp) return new RegExp(source);
if (typeof source !== 'object') return source;
Expand Down