2
0
mirror of https://github.com/tenrok/vue-json-viewer.git synced 2026-06-20 20:00:37 +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
+26 -4
View File
@@ -26,19 +26,30 @@ export default {
default: 0
},
previewMode: Boolean,
forceExpand: Boolean,
},
data() {
return {
expand: true
expand: true,
forceExpandMe: this.forceExpand,
}
},
mounted() {
this.expand = this.previewMode || (this.depth >= this.expandDepth ? false : true)
this.expand = this.previewMode || (this.depth >= this.expandDepth ? false : true) || this.forceExpandMe
},
methods: {
toggle() {
this.expand = !this.expand
this.dispatchEvent()
},
toggleAll() {
this.expand = !this.expand
this.forceExpandMe = this.expand
this.dispatchEvent()
},
dispatchEvent() {
try {
this.$el.dispatchEvent(new Event('resized'))
} catch (e) {
@@ -64,7 +75,7 @@ export default {
let elements = []
let dataType
if (this.value === null || this.value === undefined) {
if (this.value === null || this.value === undefined) {
dataType = JsonUndefined
} else if (Array.isArray(this.value)) {
dataType = JsonArray
@@ -90,7 +101,13 @@ export default {
open: !!this.expand
},
on: {
click: this.toggle
click: (event) => {
if (event.altKey) {
this.toggleAll()
} else {
this.toggle()
}
}
}
}))
}
@@ -117,10 +134,15 @@ export default {
depth: this.depth,
expand: this.expand,
previewMode: this.previewMode,
forceExpand: this.forceExpandMe
},
on: {
'update:expand': value => {
this.expand = value
},
'update:expandAll': value => {
this.expand = value
this.forceExpandMe = this.expand
}
}
}))