Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 97541c0

Browse files
authored
fix(components): keep components tree selected state (#221)
1 parent 94db2bc commit 97541c0

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

packages/client/pages/components.vue

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,36 @@ const normalizedComponentState = computed(() => {
6161
return list
6262
})
6363
64+
function findComponentNode(treeNode: any[], uid: number) {
65+
for (const node of treeNode) {
66+
if (node.uid === uid) {
67+
return node
68+
}
69+
else if (node.children) {
70+
const findNode = findComponentNode(node.children, uid)
71+
if (findNode)
72+
return findNode
73+
}
74+
}
75+
return undefined
76+
}
77+
6478
function init() {
6579
componentWalker.value = new ComponentWalker(500, null, true)
66-
selectedComponent.value = instance.value
67-
selectedComponentState.value = getInstanceState(instance.value!)
6880
componentWalker.value.getComponentTree(instance.value!).then((res) => {
81+
const currentNode = findComponentNode(res, selectedComponentNode.value?.uid || 0) || res[0]
6982
componentTree.value = res
70-
selectedComponentName.value = res?.[0]?.name ?? ''
71-
selectedComponentNode.value = res?.[0]
83+
selected.value = currentNode.id
84+
selectedComponentName.value = currentNode.name
85+
selectedComponentNode.value = currentNode
86+
selectedComponentState.value = getInstanceState(currentNode.instance)
7287
})
7388
}
7489
7590
onMounted(() => {
7691
onVueInstanceUpdate((v) => {
77-
if (v) {
92+
if (v)
7893
init()
79-
selected.value = 'vue-devtools:root'
80-
}
8194
})
8295
})
8396

0 commit comments

Comments
 (0)