22import type { CustomInspectorNode , CustomInspectorOptions , CustomInspectorState } from ' @vue/devtools-kit'
33import { DevToolsMessagingEvents , rpc } from ' @vue/devtools-core'
44import { parse } from ' @vue/devtools-kit'
5- import { vTooltip } from ' @vue/devtools-ui'
5+ import { vTooltip , VueInput } from ' @vue/devtools-ui'
66import { Pane , Splitpanes } from ' splitpanes'
77import { computed , onUnmounted , ref , watch } from ' vue'
88import DevToolsHeader from ' ~/components/basic/DevToolsHeader.vue'
@@ -11,21 +11,40 @@ import Navbar from '~/components/basic/Navbar.vue'
1111import RootStateViewer from ' ~/components/state/RootStateViewer.vue'
1212import ComponentTree from ' ~/components/tree/TreeViewer.vue'
1313
14+ import { useCustomInspectorState } from ' ~/composables/custom-inspector-state'
1415import { createExpandedContext } from ' ~/composables/toggle-expanded'
16+ import { filterInspectorState } from ' ~/utils'
17+ import { PiniaPluginInspectorId } from ' ../../constants'
1518
1619const { expanded : expandedTreeNodes } = createExpandedContext ()
1720const { expanded : expandedStateNodes } = createExpandedContext (' pinia-store-state' )
1821
19- const inspectorId = ' pinia '
22+ const inspectorId = PiniaPluginInspectorId
2023const nodeActions = ref <CustomInspectorOptions [' nodeActions' ]>([])
2124const actions = ref <CustomInspectorOptions [' nodeActions' ]>([])
25+ const inspectorState = useCustomInspectorState ()
2226
2327const selected = ref (' ' )
2428const tree = ref <CustomInspectorNode []>([])
2529const treeNodeLinkedList = computed (() => tree .value ?.length ? dfs (tree .value ?.[0 ]) : [])
2630const flattenedTreeNodes = computed (() => flattenTreeNodes (tree .value ))
2731const flattenedTreeNodesIds = computed (() => flattenedTreeNodes .value .map (node => node .id ))
2832const state = ref <Record <string , CustomInspectorState []>>({})
33+ const filterStoreKey = ref (' ' )
34+ const filterStateKey = ref (' ' )
35+
36+ watch (filterStoreKey , (value , oldValue ) => {
37+ if (! value .trim ().length && ! oldValue .trim ().length )
38+ return
39+ getPiniaInspectorTree (value )
40+ })
41+
42+ const displayState = computed (() => {
43+ return filterInspectorState ({
44+ state: state .value ,
45+ filterKey: filterStateKey .value ,
46+ })
47+ })
2948
3049const emptyState = computed (() => ! state .value .state ?.length && ! state .value .getters ?.length )
3150
@@ -118,8 +137,8 @@ watch(selected, () => {
118137 getPiniaState (selected .value )
119138})
120139
121- const getPiniaInspectorTree = () => {
122- rpc .value .getInspectorTree ({ inspectorId , filter: ' ' }).then ((_data ) => {
140+ function getPiniaInspectorTree( filter : string = ' ' ) {
141+ rpc .value .getInspectorTree ({ inspectorId , filter }).then ((_data ) => {
123142 const data = parse (_data ! )
124143 tree .value = data
125144 if (! selected .value && data .length ) {
@@ -184,8 +203,9 @@ onUnmounted(() => {
184203 <Splitpanes class =" flex-1 overflow-auto" >
185204 <Pane border =" r base" size =" 40" h-full >
186205 <div class =" h-full flex flex-col p2" >
187- <div v-if =" actions?.length" class =" mb-1 flex justify-end pb-1" border =" b dashed base" >
188- <div class =" flex items-center gap-2 px-1" >
206+ <div class =" grid grid-cols-[1fr_auto] mb1 items-center gap2 pb1" border =" b dashed base" >
207+ <VueInput v-model =" filterStoreKey" :placeholder =" inspectorState.treeFilterPlaceholder" />
208+ <div v-if =" actions?.length" class =" flex items-center gap-2 px-1" >
189209 <div v-for =" (action, index) in actions" :key =" index" v-tooltip.bottom-end =" { content: action.tooltip }" class =" flex items-center gap1" @click =" callAction(index)" >
190210 <i :class =" `i-ic-baseline-${action.icon.replace(/\_/g, '-')}`" cursor-pointer op70 text-base hover:op100 />
191211 </div >
@@ -198,14 +218,15 @@ onUnmounted(() => {
198218 </Pane >
199219 <Pane size =" 60" >
200220 <div class =" h-full flex flex-col p2" >
201- <div v-if =" nodeActions?.length" class =" mb-1 flex justify-end pb-1" border =" b dashed base" >
202- <div class =" flex items-center gap-2 px-1" >
221+ <div class =" grid grid-cols-[1fr_auto] mb1 items-center gap2 pb1" border =" b dashed base" >
222+ <VueInput v-model =" filterStateKey" :placeholder =" inspectorState.stateFilterPlaceholder" />
223+ <div v-if =" nodeActions?.length" class =" flex items-center gap-2 px-1" >
203224 <div v-for =" (action, index) in nodeActions" :key =" index" v-tooltip.bottom-end =" { content: action.tooltip }" class =" flex items-center gap1" @click =" callNodeAction(index)" >
204225 <i :class =" `i-ic-baseline-${action.icon.replace(/\_/g, '-')}`" cursor-pointer op70 text-base hover:op100 />
205226 </div >
206227 </div >
207228 </div >
208- <RootStateViewer v-if =" selected && !emptyState" class =" no-scrollbar flex-1 select-none overflow-scroll" :data =" state " :node-id =" selected" :inspector-id =" inspectorId" expanded-state-id =" pinia-store-state" />
229+ <RootStateViewer v-if =" selected && !emptyState" class =" no-scrollbar flex-1 select-none overflow-scroll" :data =" displayState " :node-id =" selected" :inspector-id =" inspectorId" expanded-state-id =" pinia-store-state" />
209230 <Empty v-else >
210231 No Data
211232 </Empty >
0 commit comments