Skip to content

Commit 66a298b

Browse files
authored
fix(client): expand all parent nodes on inspecting component tree (#151)
1 parent 4b857d4 commit 66a298b

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

packages/client/src/pages/components.vue

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ const selectedComponentTreeNode = computed<ComponentTreeNode>(() => {
3737
find(treeNode.value)
3838
return res[0]
3939
})
40+
41+
const treeNodeIdLinkedList = computed<string[][]>(() => {
42+
const res: string[][] = []
43+
const find = (treeNode: ComponentTreeNode[], linkedList: string[] = []) => {
44+
treeNode.forEach((item) => {
45+
res.push([...linkedList, item.id])
46+
if (item.children?.length)
47+
find(item.children, [...linkedList, item.id])
48+
})
49+
}
50+
find(treeNode.value)
51+
return res
52+
})
53+
4054
// selected component file path
4155
const selectedComponentFilePath = computed(() => selectedComponentTreeNode.value?.file ?? '')
4256
@@ -127,9 +141,22 @@ function inspectComponentInspector() {
127141
selectedComponentTree.value = data.id
128142
selectComponentTree(data.id)
129143
const linkedList = componentTreeLinkedList.value[data.id]
130-
linkedList.forEach((id) => {
131-
componentTreeCollapseMap.value[id] = true
132-
})
144+
if (linkedList) {
145+
linkedList.forEach((id) => {
146+
componentTreeCollapseMap.value[id] = true
147+
})
148+
}
149+
else {
150+
treeNodeIdLinkedList.value.forEach((item) => {
151+
let index = item.indexOf(data.id)
152+
if (index > -1) {
153+
while (index >= 0) {
154+
componentTreeCollapseMap.value[item[index]] = true
155+
index--
156+
}
157+
}
158+
})
159+
}
133160
}).finally(() => {
134161
bridge.value.emit('toggle-panel', true)
135162
})

0 commit comments

Comments
 (0)