LCOV - code coverage report
Current view: top level - src/components/searchbox - NodeSearchBox.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 52 52
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2          520 :   <div
       3              :     class="comfy-vue-node-search-container flex w-full min-w-96 items-center justify-center"
       4              :   >
       5              :     <div
       6              :       v-if="enableNodePreview && hoveredSuggestion"
       7              :       class="comfy-vue-node-preview-container absolute top-1/2 left-[-375px] z-50 hidden max-h-[85vh] -translate-y-1/2 cursor-pointer overflow-y-auto 2xl:block"
       8              :       @mousedown.stop="onAddNode(hoveredSuggestion!, $event)"
       9              :     >
      10              :       <NodePreview
      11              :         :key="hoveredSuggestion?.name || ''"
      12              :         :node-def="hoveredSuggestion"
      13              :         position="relative"
      14              :       />
      15              :     </div>
      16              : 
      17              :     <Button
      18              :       variant="secondary"
      19              :       :aria-label="$t('g.addNodeFilterCondition')"
      20              :       class="filter-button z-10"
      21              :       @click="filterVisible = true"
      22              :     >
      23              :       <i class="icon-[lucide--funnel]" />
      24              :     </Button>
      25              :     <Dialog :open="filterVisible" @update:open="onFilterDialogOpenChange">
      26              :       <DialogPortal>
      27              :         <DialogOverlay
      28              :           data-testid="node-search-filter-overlay"
      29              :           @pointerdown.self.stop="filterVisible = false"
      30              :         />
      31              :         <DialogContent
      32              :           class="min-w-96"
      33              :           @escape-key-down="$event.isComposing && $event.preventDefault()"
      34              :           @pointer-down-outside="(e) => onRekaPointerDownOutside({}, e)"
      35              :           @close-auto-focus="onFilterDialogCloseAutoFocus"
      36              :         >
      37              :           <DialogHeader>
      38              :             <DialogTitle>{{ $t('g.addNodeFilterCondition') }}</DialogTitle>
      39              :             <DialogClose :aria-label="$t('g.close')" />
      40              :           </DialogHeader>
      41              :           <div class="px-4 py-2">
      42              :             <NodeSearchFilter @add-filter="onAddFilter" />
      43              :           </div>
      44              :         </DialogContent>
      45              :       </DialogPortal>
      46              :     </Dialog>
      47              : 
      48              :     <SearchAutocomplete
      49              :       ref="searchAutocomplete"
      50              :       v-model="currentQuery"
      51              :       :clear-label="$t('g.clear')"
      52              :       :accessible-label="searchLabel"
      53              :       class="comfy-vue-node-search-box z-10 grow"
      54              :       anchor-class="h-auto min-h-8 flex-wrap"
      55              :       :content-style="{ maxHeight: '40vh' }"
      56              :       :placeholder="placeholder"
      57              :       :input-id="inputId"
      58              :       :suggestions="suggestions"
      59              :       :loading="!nodeFrequencyStore.isLoaded"
      60              :       open-on-focus
      61              :       :update-model-on-select="false"
      62              :       option-label="display_name"
      63              :       option-key="name"
      64              :       @select="onAddNode"
      65              :       @highlight="setHoverSuggestion"
      66              :     >
      67              :       <template #suggestion="{ suggestion }">
      68              :         <NodeSearchItem :node-def="suggestion" :current-query="currentQuery" />
      69              :       </template>
      70              :       <template #leading>
      71              :         <div v-if="filters.length" class="ml-8 flex flex-wrap gap-1 py-1">
      72              :           <template
      73              :             v-for="filter in filters"
      74          117 :             :key="`${filter.filterDef?.id}-${filter.value}`"
      75              :           >
      76              :             <SearchFilterChip
      77              :               v-if="filter.filterDef && filter.value"
      78              :               data-testid="node-search-filter-chip"
      79              :               :text="filter.value"
      80              :               :badge="filter.filterDef.invokeSequence.toUpperCase()"
      81              :               :badge-class="filter.filterDef.invokeSequence + '-badge'"
      82              :               @remove="onRemoveFilter($event, filter)"
      83              :             />
      84              :           </template>
      85              :         </div>
      86              :       </template>
      87              :     </SearchAutocomplete>
      88              :   </div>
      89              : </template>
      90              : 
      91              : <script setup lang="ts">
      92              : import { refDebounced } from '@vueuse/core'
      93              : import { debounce } from 'es-toolkit/compat'
      94              : import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
      95              : import { useI18n } from 'vue-i18n'
      96              : 
      97              : import { onRekaPointerDownOutside } from '@/components/dialog/dialogDismissGuards'
      98              : import NodePreview from '@/components/node/NodePreview.vue'
      99              : import NodeSearchFilter from '@/components/searchbox/NodeSearchFilter.vue'
     100              : import NodeSearchItem from '@/components/searchbox/NodeSearchItem.vue'
     101              : import Button from '@comfyorg/design-system/button/Button'
     102              : import Dialog from '@comfyorg/design-system/dialog/Dialog'
     103              : import DialogClose from '@comfyorg/design-system/dialog/DialogClose'
     104              : import DialogContent from '@comfyorg/design-system/dialog/DialogContent'
     105              : import DialogHeader from '@comfyorg/design-system/dialog/DialogHeader'
     106              : import DialogOverlay from '@comfyorg/design-system/dialog/DialogOverlay'
     107              : import DialogPortal from '@comfyorg/design-system/dialog/DialogPortal'
     108              : import DialogTitle from '@comfyorg/design-system/dialog/DialogTitle'
     109              : import SearchAutocomplete from '@comfyorg/design-system/search-input/SearchAutocomplete'
     110              : import { useSettingStore } from '@/platform/settings/settingStore'
     111              : import { useTelemetry } from '@comfyorg/telemetry'
     112              : import { useSearchQueryTracking } from '@/platform/telemetry/searchQuery/useSearchQueryTracking'
     113              : import type { ComfyNodeDefImpl } from '@/core/graph/nodeDef/ComfyNodeDefImpl'
     114              : import { useNodeDefStore } from '@/stores/nodeDefStore'
     115              : import { useNodeFrequencyStore } from '@/stores/nodeFrequencyStore'
     116              : import type { FuseFilterWithValue } from '@/utils/fuseUtil'
     117              : 
     118              : import SearchFilterChip from '@/components/common/SearchFilterChip.vue'
     119              : 
     120           34 : const settingStore = useSettingStore()
     121           34 : const { t } = useI18n()
     122           34 : const telemetry = useTelemetry()
     123              : 
     124           34 : const enableNodePreview = computed(() =>
     125              :   settingStore.get('Comfy.NodeSearchBoxImpl.NodePreview')
     126              : )
     127              : 
     128              : const { filters, searchLimit = 64 } = defineProps<{
     129              :   filters: FuseFilterWithValue<ComfyNodeDefImpl, string>[]
     130              :   searchLimit?: number
     131              : }>()
     132              : 
     133           34 : const searchAutocomplete = ref<{
     134              :   focus: () => void
     135              :   open: () => void
     136              : } | null>(null)
     137           34 : const filterVisible = defineModel<boolean>('filterVisible', { required: true })
     138           34 : const inputId = `comfy-vue-node-search-box-input-${Math.random()}`
     139           34 : const hoveredSuggestion = ref<ComfyNodeDefImpl | null>(null)
     140           34 : const currentQuery = ref('')
     141           34 : const searchLabel = computed(() =>
     142              :   t('g.searchPlaceholder', { subject: t('g.nodes') })
     143              : )
     144           34 : const placeholder = computed(() =>
     145              :   filters.length === 0 ? searchLabel.value : ''
     146              : )
     147              : 
     148           34 : const nodeDefStore = useNodeDefStore()
     149           34 : const nodeFrequencyStore = useNodeFrequencyStore()
     150              : 
     151           34 : const searchedQuery = refDebounced(currentQuery, 100)
     152           34 : const suggestions = computed(() =>
     153              :   searchedQuery.value === '' && filters.length === 0
     154              :     ? nodeDefStore.topNodeDefs
     155              :     : [
     156              :         ...nodeDefStore.nodeSearchService.searchNode(
     157              :           searchedQuery.value,
     158              :           filters,
     159              :           { limit: searchLimit }
     160              :         )
     161              :       ]
     162              : )
     163              : 
     164           34 : useSearchQueryTracking('node_modal', currentQuery, suggestions)
     165              : 
     166           34 : const debouncedTrackSearch = debounce((query: string) => {
     167            2 :   if (query.trim()) {
     168            2 :     telemetry?.trackNodeSearch({ query })
     169              :   }
     170              : }, 500)
     171           34 : watch(searchedQuery, debouncedTrackSearch)
     172           34 : onUnmounted(() => {
     173           10 :   debouncedTrackSearch.cancel()
     174              : })
     175              : 
     176           34 : const emit = defineEmits<{
     177              :   addFilter: [filter: FuseFilterWithValue<ComfyNodeDefImpl, string>]
     178              :   removeFilter: [filter: FuseFilterWithValue<ComfyNodeDefImpl, string>]
     179              :   addNode: [nodeDef: ComfyNodeDefImpl, dragEvent?: MouseEvent]
     180              : }>()
     181              : 
     182              : // Track node selection and emit addNode event
     183            9 : function onAddNode(nodeDef: ComfyNodeDefImpl, event?: MouseEvent) {
     184            9 :   telemetry?.trackNodeSearchResultSelected({
     185              :     node_type: nodeDef.name,
     186              :     last_query: currentQuery.value
     187              :   })
     188            9 :   emit('addNode', nodeDef, event)
     189              : }
     190              : 
     191           34 : const reFocusInput = async () => {
     192           28 :   await nextTick()
     193           28 :   searchAutocomplete.value?.focus()
     194           28 :   searchAutocomplete.value?.open()
     195              : }
     196              : 
     197            3 : function onFilterDialogOpenChange(open: boolean) {
     198            3 :   filterVisible.value = open
     199              : }
     200              : 
     201           20 : function onFilterDialogCloseAutoFocus(event: Event) {
     202           20 :   event.preventDefault()
     203           20 :   void reFocusInput()
     204              : }
     205              : 
     206           34 : onMounted(() => {
     207           34 :   void nextTick(() => {
     208           34 :     searchAutocomplete.value?.focus()
     209           34 :     searchAutocomplete.value?.open()
     210              :   })
     211              : })
     212           34 : const onAddFilter = (
     213              :   filterAndValue: FuseFilterWithValue<ComfyNodeDefImpl, string>
     214              : ) => {
     215           17 :   filterVisible.value = false
     216           17 :   emit('addFilter', filterAndValue)
     217              : }
     218           34 : const onRemoveFilter = async (
     219              :   event: Event,
     220              :   filterAndValue: FuseFilterWithValue<ComfyNodeDefImpl, string>
     221              : ) => {
     222            8 :   event.stopPropagation()
     223            8 :   event.preventDefault()
     224            8 :   emit('removeFilter', filterAndValue)
     225            8 :   await nextTick()
     226            8 :   await reFocusInput()
     227              : }
     228           34 : const setHoverSuggestion = (suggestion: ComfyNodeDefImpl | undefined) => {
     229          481 :   hoveredSuggestion.value = suggestion ?? null
     230              : }
     231              : </script>
        

Generated by: LCOV version 2.0-1