Thanks to visit codestin.com
Credit goes to github.com

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

Commit 52f3069

Browse files
feat: support filter components in component tree (#173)
* feat: support filter components in component tree * fix: to lowercase * chore: hide if not init
1 parent f1dc3ea commit 52f3069

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

‎packages/client/logic/components/filter.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ComponentInternalInstance } from 'vue'
22
import { classify, getInstanceName, kebabize } from './util'
33

44
export class ComponentFilter {
5-
filter: string
5+
private filter: string
66

77
constructor(filter: string | null) {
88
this.filter = filter || ''
@@ -19,4 +19,8 @@ export class ComponentFilter {
1919
return classify(name).toLowerCase().includes(this.filter)
2020
|| kebabize(name).toLowerCase().includes(this.filter)
2121
}
22+
23+
setFilter(filter: string) {
24+
this.filter = filter
25+
}
2226
}

‎packages/client/pages/components.vue

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import { instance, onVueInstanceUpdate } from '~/logic/app'
1010
import { rootPath } from '~/logic/global'
1111
1212
const componentTree = ref<ComponentTreeNode[]>([])
13+
const filterName = ref('')
14+
15+
const componentWalker = shallowRef<ComponentWalker | null>(null)
16+
17+
watchDebounced(filterName, (value) => {
18+
value = value.trim().toLowerCase()
19+
componentWalker.value!.componentFilter.setFilter(value)
20+
componentWalker.value!.getComponentTree(instance.value!).then((res) => {
21+
componentTree.value = res
22+
})
23+
}, { debounce: 200 })
1324
1425
function normalizeComponentState(value: unknown, type: string) {
1526
if (type === 'Reactive')
@@ -48,10 +59,10 @@ const normalizedComponentState = computed(() => {
4859
})
4960
5061
function init() {
51-
const walker = new ComponentWalker(500, null, true)
62+
componentWalker.value = new ComponentWalker(500, null, true)
5263
selectedComponent.value = instance.value
5364
selectedComponentState.value = getInstanceState(instance.value!)
54-
walker.getComponentTree(instance.value!).then((res) => {
65+
componentWalker.value.getComponentTree(instance.value!).then((res) => {
5566
componentTree.value = res
5667
selectedComponentName.value = res?.[0]?.name ?? ''
5768
selectedComponentNode.value = res?.[0]
@@ -77,6 +88,9 @@ function openInEditor() {
7788
<div h-screen n-panel-grids>
7889
<Splitpanes>
7990
<Pane border="r base">
91+
<div v-if="componentWalker" w-full px10px py12px>
92+
<VDTextInput v-model="filterName" placeholder="Find components..." />
93+
</div>
8094
<div h-screen select-none overflow-scroll p-2 class="no-scrollbar">
8195
<ComponentTreeNode v-for="(item) in componentTree" :key="item.id" :data="item" />
8296
</div>

0 commit comments

Comments
 (0)