1- <script setup lang="ts">
2- import type { ModuleListItem , SessionContext } from ' ~~/shared/types'
1+ <script setup lang="ts" generic =" T extends { id: string , imports: Record <string , unknown >[] }" >
2+ import type { SessionContext } from ' ~~/shared/types'
3+ import type { GraphPathSelector } from ' ~/composables/graph-path-selector'
34import { computed , watch } from ' vue'
4- import { useModulePathSelector } from ' ~/composables/moduleGraph '
5+ import { useGraphPathSelector } from ' ~/composables/graph-path-selector '
56
67const props = defineProps <{
78 session: SessionContext
8- modules: ModuleListItem []
9+ data: T []
10+ importIdKey: string
11+ searchKeys? : string []
912}>()
1013
1114const emit = defineEmits <{
1215 (e : ' close' ): void
1316 (e : ' select' , nodes : { start: string , end: string }): void
1417}>()
1518
16- const modulesMap = computed (() => {
17- const map = new Map <string , ModuleListItem >()
18- props .modules .forEach ((m ) => {
19+ defineSlots <{
20+ list: (props : {
21+ select: (module : T ) => void
22+ data: T []
23+ }) => void
24+ item: (props : {
25+ id: string
26+ }) => void
27+ }>()
28+
29+ const dataMap = computed (() => {
30+ const map = new Map <string , T >()
31+ props .data .forEach ((m ) => {
1932 map .set (m .id , m )
2033 })
2134 return map
2235})
2336
24- const startSelector = useModulePathSelector ({
37+ const startSelector: GraphPathSelector <T > = useGraphPathSelector <T >({
38+ searchKeys: props .searchKeys ,
2539 getModules : () => {
2640 if (! startSelector .state .value .search ) {
27- return props .modules
41+ return props .data
2842 }
2943 else {
3044 return startSelector .fuse .value ! .value ?.search (startSelector .state .value .search ).map (r => r .item ) ?? []
3145 }
3246 },
3347})
3448
35- startSelector .initSelector (computed (() => props .modules ))
49+ startSelector .initSelector (computed (() => props .data ))
3650
37- function getAllImports(moduleId : string , visited = new Set <string >()): ModuleListItem [] {
51+ function getAllImports(moduleId : string , visited = new Set <string >()): T [] {
3852 if (visited .has (moduleId ))
3953 return []
4054 visited .add (moduleId )
4155
42- const module = modulesMap .value .get (moduleId )
56+ const module = dataMap .value .get (moduleId )
4357 if (! module ?.imports ?.length )
4458 return []
4559
46- const res: ModuleListItem [] = []
60+ const res: T [] = []
4761
4862 for (const importItem of module .imports ) {
49- const importedModule = modulesMap .value .get (importItem . module_id )
63+ const importedModule = dataMap .value .get (` ${ importItem [ props . importIdKey ]} ` )
5064 if (! importedModule )
5165 continue
5266
@@ -59,7 +73,8 @@ function getAllImports(moduleId: string, visited = new Set<string>()): ModuleLis
5973 return res
6074}
6175
62- const endSelector = useModulePathSelector ({
76+ const endSelector = useGraphPathSelector <T >({
77+ searchKeys: props .searchKeys ,
6378 getModules : () => {
6479 return startSelector .state .value .selected ? getAllImports (startSelector .state .value .selected ) : []
6580 },
@@ -82,39 +97,60 @@ watch([() => startSelector.state.value.selected, () => endSelector.state.value.s
8297 end: endSelector .state .value .selected ?? ' ' ,
8398 })
8499})
100+
101+ function close() {
102+ emit (' select' , {
103+ start: ' ' ,
104+ end: ' ' ,
105+ })
106+ emit (' close' )
107+ }
85108 </script >
86109
87110<template >
88- <div h12 px4 p2 relative flex =" ~ gap2 items-center" >
89- <div flex =" ~ items-center gap2" class =" flex-1" min-w-0 >
90- <ModulesPathSelectorItem
111+ <div h10 px4 p1 relative flex =" ~ gap2 items-center" >
112+ <div flex =" ~ items-center gap2" class =" flex-1 h-full " min-w-0 >
113+ <DataPathSelectorItem
91114 v-model:search =" startSelector.state.value.search"
92115 placeholder =" Start"
93116 :selector =" startSelector"
94117 :session =" session"
95- :modules =" startSelector.modules.value"
118+ :data =" startSelector.modules.value"
96119 @clear =" () => { startSelector.clear(); endSelector.clear() }"
97- />
120+ >
121+ <template #list >
122+ <slot name =" list" :select =" startSelector.select" :data =" startSelector.modules.value" />
123+ </template >
124+ <template #item >
125+ <slot :id =" startSelector.state.value.selected!" name =" item" />
126+ </template >
127+ </DataPathSelectorItem >
98128 <div class =" i-carbon-arrow-right op50" flex-shrink-0 />
99129
100- <ModulesPathSelectorItem
130+ <DataPathSelectorItem
101131 v-model:search =" endSelector.state.value.search"
102132 placeholder =" End"
103133 :selector =" endSelector"
104134 :session =" session"
105- :modules =" filteredEndModules"
135+ :data =" filteredEndModules"
106136 @clear =" endSelector.clear"
107137 >
138+ <template #list >
139+ <slot name =" list" :select =" endSelector.select" :data =" filteredEndModules" />
140+ </template >
141+ <template #item >
142+ <slot :id =" endSelector.state.value.selected!" name =" item" />
143+ </template >
108144 <template #empty >
109145 <div flex =" ~ items-center justify-center" w-full h-20 >
110146 <span italic op50 >
111147 {{ startSelector.state.value.selected ? 'No modules' : 'Select a start module to get end modules' }}
112148 </span >
113149 </div >
114150 </template >
115- </ModulesPathSelectorItem >
151+ </DataPathSelectorItem >
116152 </div >
117153
118- <DisplayCloseButton class =" mr--2" @click =" emit(' close') " />
154+ <DisplayCloseButton class =" mr--2" @click =" close" />
119155 </div >
120156</template >
0 commit comments