File size: 2,792 Bytes
4d70170 |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
<script>
import { useDefer } from '@front/util/defer'
import { getStorage, setStorage } from '@vue-devtools/shared-utils'
import StateType from './StateType.vue'
const keyOrder = {
'props': 1,
'register module': 1,
'unregister module': 1,
'mutation': 1,
'setup': 2,
'data': 2,
'state': 2,
'undefined': 3,
'getters': 3,
'computed': 4,
'injected': 5,
'provided': 5,
'vuex bindings': 5,
'$refs': 6,
'refs': 6,
'$attrs': 7,
'attrs': 7,
'event listeners': 7,
'setup (other)': 8,
}
const STORAGE_COLLAPSE_ALL = 'state-inspector.collapse-all'
export default {
components: {
StateType,
},
props: {
state: {
type: Object,
required: true,
},
dimAfter: {
type: Number,
default: -1,
},
},
emits: ['editState'],
setup() {
const { defer } = useDefer()
return {
defer,
}
},
data() {
return {
expandedState: {},
forceCollapse: null,
}
},
computed: {
dataTypes() {
return Object.keys(this.state).sort((a, b) => {
return (
(keyOrder[a] || (a.toLowerCase().charCodeAt(0) + 999))
- (keyOrder[b] || (b.toLowerCase().charCodeAt(0) + 999))
)
})
},
totalCount() {
return Object.keys(this.state).reduce((total, state) => total + state.length, 0)
},
highDensity() {
const pref = this.$shared.displayDensity
return (pref === 'auto' && this.totalCount > 12) || pref === 'high'
},
},
watch: {
state: {
handler() {
this.forceCollapse = null
if (getStorage(STORAGE_COLLAPSE_ALL)) {
this.setExpandToAll(false)
}
},
immediate: true,
},
},
methods: {
toggle(dataType, currentExpanded, event = null) {
if (event?.shiftKey) {
this.setExpandToAll(!currentExpanded)
return
}
this.expandedState[dataType] = !currentExpanded
},
setExpandToAll(value) {
this.dataTypes.forEach((key) => {
this.forceCollapse = value ? 'expand' : 'collapse'
this.expandedState[key] = value
})
this.$emit(value ? 'expand-all' : 'collapse-all')
setStorage(STORAGE_COLLAPSE_ALL, !value)
},
},
}
</script>
<template>
<div class="data-wrapper">
<template v-for="(dataType, index) in dataTypes">
<StateType
v-if="defer(index + 1)"
:key="dataType"
:data-type="dataType"
:index="index"
:state="state"
:expanded-state="expandedState"
:force-collapse="forceCollapse"
:high-density="highDensity"
:dim-after="dimAfter"
@toggle="toggle"
@edit-state="(path, payload) => $emit('editState', path, payload, dataType)"
/>
</template>
</div>
</template>
|