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

Commit

Permalink
feat: support filter components in component tree (#173)
Browse files Browse the repository at this point in the history
* feat: support filter components in component tree

* fix: to lowercase

* chore: hide if not init
  • Loading branch information
alexzhang1030 authored Jul 27, 2023
1 parent f1dc3ea commit 52f3069
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/client/logic/components/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ComponentInternalInstance } from 'vue'
import { classify, getInstanceName, kebabize } from './util'

export class ComponentFilter {
filter: string
private filter: string

constructor(filter: string | null) {
this.filter = filter || ''
Expand All @@ -19,4 +19,8 @@ export class ComponentFilter {
return classify(name).toLowerCase().includes(this.filter)
|| kebabize(name).toLowerCase().includes(this.filter)
}

setFilter(filter: string) {
this.filter = filter
}
}
18 changes: 16 additions & 2 deletions packages/client/pages/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import { instance, onVueInstanceUpdate } from '~/logic/app'
import { rootPath } from '~/logic/global'
const componentTree = ref<ComponentTreeNode[]>([])
const filterName = ref('')
const componentWalker = shallowRef<ComponentWalker | null>(null)
watchDebounced(filterName, (value) => {
value = value.trim().toLowerCase()
componentWalker.value!.componentFilter.setFilter(value)
componentWalker.value!.getComponentTree(instance.value!).then((res) => {
componentTree.value = res
})
}, { debounce: 200 })
function normalizeComponentState(value: unknown, type: string) {
if (type === 'Reactive')
Expand Down Expand Up @@ -48,10 +59,10 @@ const normalizedComponentState = computed(() => {
})
function init() {
const walker = new ComponentWalker(500, null, true)
componentWalker.value = new ComponentWalker(500, null, true)
selectedComponent.value = instance.value
selectedComponentState.value = getInstanceState(instance.value!)
walker.getComponentTree(instance.value!).then((res) => {
componentWalker.value.getComponentTree(instance.value!).then((res) => {
componentTree.value = res
selectedComponentName.value = res?.[0]?.name ?? ''
selectedComponentNode.value = res?.[0]
Expand All @@ -77,6 +88,9 @@ function openInEditor() {
<div h-screen n-panel-grids>
<Splitpanes>
<Pane border="r base">
<div v-if="componentWalker" w-full px10px py12px>
<VDTextInput v-model="filterName" placeholder="Find components..." />
</div>
<div h-screen select-none overflow-scroll p-2 class="no-scrollbar">
<ComponentTreeNode v-for="(item) in componentTree" :key="item.id" :data="item" />
</div>
Expand Down

0 comments on commit 52f3069

Please sign in to comment.