2
0
mirror of https://github.com/tenrok/vue-json-viewer.git synced 2026-06-17 19:21:24 +03:00

Add ability to expand full branch

This commit is contained in:
Maksim Lanin
2021-12-17 16:43:16 +03:00
parent 683909e61e
commit 6c1da0769a
4 changed files with 74 additions and 24 deletions
+24 -11
View File
@@ -18,6 +18,7 @@ export default {
},
sort: Boolean,
expand: Boolean,
forceExpand: Boolean,
previewMode: Boolean,
},
data() {
@@ -47,7 +48,13 @@ export default {
},
toggle() {
this.$emit('update:expand', !this.expand)
this.dispatchEvent();
},
toggleAll() {
this.$emit('update:expandAll', !this.expand)
this.dispatchEvent();
},
dispatchEvent() {
try {
this.$el.dispatchEvent(new Event('resized'))
} catch (e) {
@@ -56,8 +63,7 @@ export default {
evt.initEvent('resized', true, false)
this.$el.dispatchEvent(evt)
}
},
}
},
render (h) {
let elements = []
@@ -69,7 +75,13 @@ export default {
'open': !!this.expand,
},
on: {
click: this.toggle
click: (event) => {
if (event.altKey) {
this.toggleAll()
} else {
this.toggle()
}
}
}
}))
}
@@ -87,15 +99,13 @@ export default {
this.value.forEach((value, key) => {
elements.push(h(JsonBox, {
key,
style: {
display: this.expand ? undefined : 'none'
},
props: {
sort: this.sort,
keyName: `${key}`,
depth: this.depth + 1,
value,
previewMode: this.previewMode,
forceExpand: this.forceExpand,
}
}))
})
@@ -103,14 +113,17 @@ export default {
if (!this.expand && this.value.length) {
elements.push(h('span', {
style: {
display: undefined
},
class: {
'jv-ellipsis': true,
},
on: {
click: this.toggle
click: (event) => {
if (event.altKey) {
this.toggleAll()
} else {
this.toggle()
}
}
},
attrs: {
title: `click to reveal ${this.value.length} hidden items`
+20 -8
View File
@@ -17,6 +17,7 @@ export default {
default: 0
},
expand: Boolean,
forceExpand: Boolean,
sort: Boolean,
previewMode: Boolean,
},
@@ -56,6 +57,10 @@ export default {
this.$emit('update:expand', !this.expand)
this.dispatchEvent();
},
toggleAll() {
this.$emit('update:expandAll', !this.expand)
this.dispatchEvent();
},
dispatchEvent() {
try {
this.$el.dispatchEvent(new Event('resized'))
@@ -77,7 +82,13 @@ export default {
'open': !!this.expand,
},
on: {
click: this.toggle
click: (event) => {
if (event.altKey) {
this.toggleAll()
} else {
this.toggle()
}
}
}
}))
}
@@ -99,15 +110,13 @@ export default {
elements.push(h(JsonBox, {
key,
style: {
display: !this.expand ? 'none' : undefined
},
props: {
sort: this.sort,
keyName: key,
depth: this.depth + 1,
value,
previewMode: this.previewMode,
forceExpand: this.forceExpand,
}
}))
}
@@ -116,14 +125,17 @@ export default {
if (!this.expand && Object.keys(this.value).length) {
elements.push(h('span', {
style: {
display: this.expand ? 'none' : undefined
},
class: {
'jv-ellipsis': true,
},
on: {
click: this.toggle
click: (event) => {
if (event.altKey) {
this.toggleAll()
} else {
this.toggle()
}
}
},
attrs: {
title: `click to reveal object content (keys: ${Object.keys(this.ordered).join(', ')})`