From 6c1da0769a17745fa7b002af4628915d5f8a8e2a Mon Sep 17 00:00:00 2001 From: Maksim Lanin Date: Fri, 17 Dec 2021 16:43:16 +0300 Subject: [PATCH 1/4] Add ability to expand full branch --- lib/json-box.vue | 30 ++++++++++++++++++++++++++---- lib/json-viewer.vue | 5 ++++- lib/types/json-array.vue | 35 ++++++++++++++++++++++++----------- lib/types/json-object.vue | 28 ++++++++++++++++++++-------- 4 files changed, 74 insertions(+), 24 deletions(-) diff --git a/lib/json-box.vue b/lib/json-box.vue index fb622e2..1c4b23c 100644 --- a/lib/json-box.vue +++ b/lib/json-box.vue @@ -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 } } })) diff --git a/lib/json-viewer.vue b/lib/json-viewer.vue index 1519c78..3f31385 100644 --- a/lib/json-viewer.vue +++ b/lib/json-viewer.vue @@ -1,5 +1,8 @@