Skip to content

Commit

Permalink
fix: show null and explicit undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
cstuncsik committed Oct 13, 2022
1 parent 1d09bfa commit 800c416
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
4 changes: 3 additions & 1 deletion example/Basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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 @@ -56,7 +56,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 @@ -97,7 +97,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 @@ -48,7 +48,9 @@ import VueJsonPretty from 'src';
const defaultData = {
status: 200,
error: '',
text: '',
error: null,
config: undefined,
data: [],
};
Expand Down
11 changes: 8 additions & 3 deletions src/components/TreeNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,14 @@ export default defineComponent({
};

const defaultValue = computed(() => {
const str = (props.node?.content ?? '') + '';
const text = dataType.value === 'string' ? `"${str}"` : str;
return text;
let value = props.node?.content;
if(value === null) {
value = 'null'
}
if(value === undefined) {
value = 'undefined'
}
return dataType.value === 'string' ? `"${value}"` : value + ''
});

const renderValue = () => {
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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function arrFlat<T extends unknown[]>(arr: T): unknown[] {
}

export function cloneDeep<T extends unknown>(source: T, hash = new WeakMap()): T {
if (source === null) return source;
if (source === null || source === undefined) return source;
if (source instanceof Date) return new Date(source) as T;
if (source instanceof RegExp) return new RegExp(source) as T;
if (typeof source !== 'object') return source;
Expand Down

0 comments on commit 800c416

Please sign in to comment.