Skip to content

Commit

Permalink
feat: Apply default select to components
Browse files Browse the repository at this point in the history
  • Loading branch information
Azurewarth0920 committed Apr 1, 2024
1 parent 6f01317 commit 7f08c16
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
7 changes: 5 additions & 2 deletions packages/client/src/pages/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ function checkComponentInTree(treeNode: ComponentTreeNode[], id: string) {
return treeNode.some(item => checkComponentInTree(item.children || [], id))
}
const { saveParamId, getValidNestedNodeId } = useDefaultSelect()
function initSelectedComponent(treeNode: ComponentTreeNode[]) {
if (!treeNode.length)
return
if (!selectedComponentTree.value) {
selectedComponentTree.value = treeNode?.[0].id
getComponentState(treeNode?.[0].id)
selectedComponentTree.value = getValidNestedNodeId(treeNode) || treeNode?.[0].id
getComponentState(selectedComponentTree.value)
}
else {
// fallback to root if selected component is not in the tree
Expand Down Expand Up @@ -185,6 +187,7 @@ function selectComponentTree(id: string) {
clearComponentState()
getComponentState(id)
activeComponentId.value = id
saveParamId(id)
}
watch(selectedComponentTree, (id) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/client/src/pages/pinia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ function clearPiniaState() {
state.value = {}
}
const { saveParamId, getValidNodeId } = useDefaultSelect()
watch(selected, () => {
clearPiniaState()
getPiniaState(selected.value)
saveParamId(selected.value)
})
createCollapseContext('inspector-state')
Expand All @@ -37,8 +40,8 @@ onDevToolsClientConnected(() => {
const data = parse(_data!)
tree.value = data
if (!selected.value && data.length) {
selected.value = data[0].id
getPiniaState(data[0].id)
selected.value = getValidNodeId(data) || data[0].id
getPiniaState(selected.value)
}
})
Expand Down
7 changes: 5 additions & 2 deletions packages/client/src/pages/router.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ function clearRouterState() {
state.value = {}
}
const { saveParamId, getValidNodeId } = useDefaultSelect()
watch(selected, () => {
clearRouterState()
getRouterState(selected.value)
saveParamId(selected.value)
})
onDevToolsClientConnected(() => {
getInspectorTree({ inspectorId: inspectorId.value, filter: '' }).then((_data) => {
const data = parse(_data!)
tree.value = data
if (!selected.value && data.length) {
selected.value = data[0].id
getRouterState(data[0].id)
selected.value = getValidNodeId(data) || data[0].id
getRouterState(selected.value)
}
})
Expand Down
9 changes: 7 additions & 2 deletions packages/client/src/pages/timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function normalizeGroupInfo(layerId: string, event: TimelineEvent['event']) {
}
}
const { saveParamId, getValidNodeId } = useDefaultSelect()
onDevToolsClientConnected(() => {
getTimelineLayer().then((data) => {
layers.value = data!
Expand All @@ -74,7 +76,7 @@ onDevToolsClientConnected(() => {
layer.groups = {}
})
if (!selectedLayer.value)
selectedLayer.value = data?.length ? data[0].id : ''
selectedLayer.value = data?.length ? (getValidNodeId(layers.value) || data[0].id) : ''
})
onAddTimelineEvent((payload) => {
if (!payload)
Expand All @@ -99,7 +101,10 @@ watch(() => activeTimelineEvent.value.length, (l) => {
<!-- layer -->
<Pane border="r base" size="20">
<div h-screen select-none overflow-scroll p-2 class="no-scrollbar">
<TimelineLayer v-for="(item) in layers" :key="item.id" v-model="selectedLayer" :data="item" />
<TimelineLayer
v-for="(item) in layers" :key="item.id" v-model="selectedLayer" :data="item"
@update:model-value="saveParamId"
/>
</div>
</Pane>
<!-- event -->
Expand Down

0 comments on commit 7f08c16

Please sign in to comment.