Skip to content

Commit 88d0c5d

Browse files
authored
feat: add input filter property (#4)
1 parent 6fa041b commit 88d0c5d

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

entrypoints/devtools-panel/devtools-panel.vue

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<script setup lang="ts">
2-
import { ElBacktop, ElButton, ElCheckbox, ElIcon, ElOption, ElSelect, ElTable, ElTableColumn, ElText, ElTooltip } from 'element-plus'
2+
import { ElBacktop, ElButton, ElCheckbox, ElIcon, ElInput, ElOption, ElSelect, ElTable, ElTableColumn, ElText, ElTooltip } from 'element-plus'
3+
import { defineComponent, h } from 'vue'
34
import { useDevToolsPanel } from './hooks/useDevToolsPanel'
45
import { filterJoin } from './utils'
56
67
const {
8+
inputValue,
9+
710
selectedEl,
811
renderCssDiffs,
912
isAllProperty,
@@ -12,6 +15,28 @@ const {
1215
onTableRowClassName,
1316
handleCopyStyle,
1417
} = useDevToolsPanel()
18+
19+
const PropertyNode = defineComponent({
20+
props: {
21+
text: {
22+
type: String,
23+
},
24+
},
25+
setup(props) {
26+
return () => {
27+
if (!inputValue.value) {
28+
return h('div', props.text)
29+
}
30+
else {
31+
const result = inputValue.value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
32+
const reg = new RegExp(`(${result})`, 'gi')
33+
34+
const text = props.text!.replace(reg, '<span class=\'text-[#409eff]\'>$1</span>')
35+
return h('div', { innerHTML: text })
36+
}
37+
}
38+
},
39+
})
1540
</script>
1641

1742
<template>
@@ -38,7 +63,9 @@ const {
3863
{{ $t('selectedInfo') }}
3964
</ElText>
4065

41-
<div class="flex justify-end">
66+
<div class="flex justify-between my-3">
67+
<ElInput v-model="inputValue" :placeholder="$t('inputPlaceholder')" clearable class="!w-[50%]" />
68+
4269
<ElCheckbox v-model="isAllProperty" :label="$t('isAllProperty')" />
4370
</div>
4471
<ElTable
@@ -49,7 +76,11 @@ const {
4976
:row-class-name="onTableRowClassName"
5077
@cell-click="handleCopyStyle"
5178
>
52-
<ElTableColumn prop="property" :label="$t('property')" />
79+
<ElTableColumn prop="property" :label="$t('property')">
80+
<template #default="scope">
81+
<PropertyNode :text="scope.row.property" />
82+
</template>
83+
</ElTableColumn>
5384
<template v-for="(el) in selectedEl" :key="el.valueType">
5485
<ElTableColumn :prop="el.valueType">
5586
<template #header>

entrypoints/devtools-panel/hooks/useDevToolsPanel.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { formatStyle, type FormatStyleValue } from '../utils'
77

88
export function useDevToolsPanel() {
99
const { t } = useI18n()
10+
const inputValue = ref('')
1011

1112
const selectedEl: Array<SelectedElType> = reactive([])
1213
const cssDiffs: Array<CssDiffsType> = reactive([])
@@ -106,15 +107,19 @@ export function useDevToolsPanel() {
106107
}
107108

108109
const renderCssDiffs = computed(() => {
109-
return isAllProperty.value
110+
return inputValueFilter(isAllProperty.value
110111
? cssDiffs
111-
: cssDiffs.filter(css => css.isDiff)
112+
: cssDiffs.filter(css => css.isDiff), inputValue.value)
112113
})
113114

115+
function inputValueFilter(cssDiffs: Array<CssDiffsType>, inputValue: string) {
116+
return !inputValue
117+
? cssDiffs
118+
: cssDiffs.filter(c => c.property.includes(inputValue))
119+
}
120+
114121
function onTableCellClassName({ columnIndex }: { columnIndex: number }) {
115-
if (!columnIndex) {
116-
return 'text-[var(--el-table-text-color)] cursor-auto'
117-
}
122+
return !columnIndex ? 'text-[var(--el-table-text-color)] cursor-auto' : ''
118123
}
119124

120125
function onTableRowClassName({ row }: { row: CssDiffsType }) {
@@ -156,6 +161,8 @@ export function useDevToolsPanel() {
156161
}
157162

158163
return {
164+
inputValue,
165+
159166
selectedEl,
160167
renderCssDiffs,
161168
isAllProperty,

entrypoints/devtools-panel/lang.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
isAllProperty: 'Show all',
88
tableColumnInfo: 'The header name is concatenated from the DOM\'s `TagName`, `Id`, and `Class` attributes using `$$`.',
99
copyInfo: 'Copy Success',
10+
inputPlaceholder: 'Please enter the css property you want to view',
1011
},
1112

1213
'zh-CN': {
@@ -17,5 +18,6 @@ export default {
1718
isAllProperty: '显示全部',
1819
tableColumnInfo: '表头名称由DOM的 `TagName`、`Id`、`Class` 属性使用 `$$` 拼接而成。',
1920
copyInfo: '复制成功',
21+
inputPlaceholder: '请输入需要查看的css属性',
2022
},
2123
}

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "./.wxt/tsconfig.json"
2+
"extends": "./.wxt/tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["element-plus/global"]
5+
}
36
}

0 commit comments

Comments
 (0)