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

Commit

Permalink
fix(components): keep components tree selected state (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
OneGIl authored Aug 30, 2023
1 parent 94db2bc commit 97541c0
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/client/pages/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,36 @@ const normalizedComponentState = computed(() => {
return list
})
function findComponentNode(treeNode: any[], uid: number) {
for (const node of treeNode) {
if (node.uid === uid) {
return node
}
else if (node.children) {
const findNode = findComponentNode(node.children, uid)
if (findNode)
return findNode
}
}
return undefined
}
function init() {
componentWalker.value = new ComponentWalker(500, null, true)
selectedComponent.value = instance.value
selectedComponentState.value = getInstanceState(instance.value!)
componentWalker.value.getComponentTree(instance.value!).then((res) => {
const currentNode = findComponentNode(res, selectedComponentNode.value?.uid || 0) || res[0]
componentTree.value = res
selectedComponentName.value = res?.[0]?.name ?? ''
selectedComponentNode.value = res?.[0]
selected.value = currentNode.id
selectedComponentName.value = currentNode.name
selectedComponentNode.value = currentNode
selectedComponentState.value = getInstanceState(currentNode.instance)
})
}
onMounted(() => {
onVueInstanceUpdate((v) => {
if (v) {
if (v)
init()
selected.value = 'vue-devtools:root'
}
})
})
Expand Down

0 comments on commit 97541c0

Please sign in to comment.