-
Notifications
You must be signed in to change notification settings - Fork 6
/
ObjectTreeNodeComplex.vue
89 lines (86 loc) · 2.49 KB
/
ObjectTreeNodeComplex.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
<div :class="{ open: open, inline: !open, 'inline-nowrap': !open && nowrap, 'vue-object-view-complex': true }">
<openButton v-if="primary && !open" @click="open = true" :html="'▶'" style="float:left" />
<openButton v-if="primary && open" @click="open = false" :html="'▼'" style="float:left" />
<div>
<span v-html="charOpen" />
<button v-if="!open && !expanded" @click="expanded = true" v-html="expandButtonText" class="vue-object-view-expand"></button>
<div v-if="open || expanded" v-for="(key, index) in items"><span v-if="open || type=='object'" class="key">{{ key }}: </span><objectTreeNode v-model="value[key]" :primary="open" :nowrap="nowrap" :expandButtonText="expandButtonText" /><span v-if="!open && index < items.length - 1">, </span></div>
<span v-html="charClose" /></div>
</div>
</template>
<script>
import openButton from './OpenButton.vue';
import objectTreeNode from './ObjectTreeNode.vue';
export default {
name: 'objectTreeNodeComplex',
props: [ 'type', 'value', 'primary', 'nowrap', 'expandButtonText' ],
data () {
return {
open: false,
expanded: this.primary,
items: this.makeItems()
}
},
beforeCreate: function () {
this.$options.components.objectTreeNode = require('./ObjectTreeNode.vue').default
},
methods: {
makeItems() {
if (this.type == 'object') {
return Object.keys(this.value);
} else if (this.type == 'array') {
return [...Array(this.value.length).keys()]
}
}
},
computed: {
charOpen() {
if (this.type == 'object')
return "{"
else
return "["
},
charClose() {
if (this.type == 'object')
return "}"
else
return "]"
}
},
watch: {
primary(value) {
this.expanded = value;
this.open = this.open && value;
}
},
components: {
openButton
}
}
</script>
<style scoped>
div.open {
display: block;
overflow: hidden;
}
div.open > div {
float: left;
display: block;
overflow: hidden;
}
div.open > div > div {
display: block;
padding-left: 16px;
}
div.inline, div.inline div, div.inline div div {
display: inline-block;
}
div.inline-nowrap, div.inline-nowrap div, div.inline-nowrap div div {
display: inline-block;
white-space: nowrap;
}
span.key {
font-style: italic;
}
</style>