LCOV - code coverage report
Current view: top level - src/renderer/extensions/propertiesPanel/parameters - TabNormalInputs.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 97.4 % 39 38
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <script setup lang="ts">
       2              : import { computed, reactive, ref, shallowRef } from 'vue'
       3              : import { useI18n } from 'vue-i18n'
       4              : 
       5              : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
       6              : import CollapseToggleButton from '@comfyorg/design-system/accordion/CollapseToggleButton'
       7              : import type { NodeId } from '@comfyorg/graph-model/nodeId'
       8              : import { deriveWidgetVisibility } from '@/types/widgetVisibility'
       9              : 
      10              : import { computedSectionDataList } from './widgetSections'
      11              : import type { NodeWidgetsListList } from './widgetSections'
      12              : import { searchWidgetsAndNodes } from './widgetSearch'
      13              : import PanelSearchHeader from './PanelSearchHeader.vue'
      14              : import SectionWidgets from './SectionWidgets.vue'
      15              : 
      16              : const { nodes, mustShowNodeTitle } = defineProps<{
      17              :   mustShowNodeTitle?: boolean
      18              :   nodes: LGraphNode[]
      19              : }>()
      20              : 
      21         2355 : const { t } = useI18n()
      22           96 : const searchQuery = ref('')
      23              : 
      24           96 : const { widgetsSectionDataList, includesAdvanced } = computedSectionDataList(
      25              :   () => nodes
      26              : )
      27              : 
      28           96 : const advancedWidgetsSectionDataList = computed((): NodeWidgetsListList => {
      29          106 :   if (includesAdvanced.value) {
      30            0 :     return []
      31              :   }
      32          106 :   return nodes
      33              :     .map((node) => {
      34          142 :       const { widgets = [] } = node
      35              :       const advancedWidgets = widgets
      36              :         .filter((w) => {
      37          672 :           const visibility = w.visibility ?? deriveWidgetVisibility(w)
      38          672 :           return (
      39              :             !visibility.suppression.byExtension &&
      40              :             !visibility.suppression.byConnection &&
      41              :             visibility.surfaces.panel === 'advanced'
      42              :           )
      43              :         })
      44              :         .map((widget) => ({ node, widget }))
      45          142 :       return { widgets: advancedWidgets, node }
      46              :     })
      47              :     .filter(({ widgets }) => widgets.length > 0)
      48              : })
      49              : 
      50           96 : const isMultipleNodesSelected = computed(
      51              :   () => widgetsSectionDataList.value.length > 1
      52              : )
      53              : 
      54           96 : const searchedWidgetsSectionDataList = shallowRef<NodeWidgetsListList>(
      55              :   widgetsSectionDataList.value
      56              : )
      57           96 : const isSearching = ref(false)
      58              : 
      59           96 : const collapseMap = reactive<Record<string, boolean>>({})
      60           96 : const advancedCollapsed = ref(true)
      61              : 
      62          308 : function isSectionCollapsed(nodeId: NodeId): boolean {
      63              :   // When not explicitly set, sections are collapsed if multiple nodes are selected
      64          308 :   return collapseMap[nodeId] ?? isMultipleNodesSelected.value
      65              : }
      66              : 
      67            6 : function setSectionCollapsed(nodeId: NodeId, collapsed: boolean) {
      68            6 :   collapseMap[nodeId] = collapsed
      69              : }
      70              : 
      71           96 : const isAllCollapsed = computed({
      72              :   get() {
      73          120 :     const normalAllCollapsed = searchedWidgetsSectionDataList.value.every(
      74              :       ({ node }) => isSectionCollapsed(node.id)
      75              :     )
      76              :     const hasAdvanced = advancedWidgetsSectionDataList.value.length > 0
      77          120 :     return hasAdvanced
      78              :       ? normalAllCollapsed && advancedCollapsed.value
      79              :       : normalAllCollapsed
      80              :   },
      81              :   set(collapse: boolean) {
      82            2 :     for (const { node } of widgetsSectionDataList.value) {
      83            6 :       setSectionCollapsed(node.id, collapse)
      84              :     }
      85            2 :     advancedCollapsed.value = collapse
      86              :   }
      87              : })
      88              : 
      89          108 : async function searcher(query: string) {
      90          108 :   const list = widgetsSectionDataList.value
      91          108 :   const target = searchedWidgetsSectionDataList
      92          108 :   isSearching.value = query.trim() !== ''
      93          108 :   target.value = searchWidgetsAndNodes(list, query)
      94              : }
      95              : 
      96           96 : const label = computed(() => {
      97          106 :   const sections = widgetsSectionDataList.value
      98          106 :   return !mustShowNodeTitle && sections.length === 1
      99              :     ? sections[0].widgets.length !== 0
     100              :       ? t('rightSidePanel.inputs')
     101              :       : t('rightSidePanel.inputsNone')
     102              :     : undefined // SectionWidgets display node titles by default
     103              : })
     104              : 
     105           96 : const advancedLabel = computed(() => {
     106            1 :   return !mustShowNodeTitle && !isMultipleNodesSelected.value
     107              :     ? t('rightSidePanel.advancedInputs')
     108              :     : undefined // SectionWidgets display node titles by default
     109              : })
     110           96 : </script>
     111              : 
     112              : <template>
     113              :   <PanelSearchHeader
     114              :     v-model="searchQuery"
     115              :     :searcher
     116              :     :update-key="widgetsSectionDataList"
     117              :   >
     118              :     <CollapseToggleButton
     119              :       v-model="isAllCollapsed"
     120              :       :expand-label="$t('g.expandAll')"
     121              :       :collapse-label="$t('g.collapseAll')"
     122              :       :show="
     123              :         !isSearching &&
     124              :         widgetsSectionDataList.length + advancedWidgetsSectionDataList.length >
     125              :           1
     126              :       "
     127              :     />
     128              :   </PanelSearchHeader>
     129              :   <TransitionGroup tag="div" name="list-scale" class="relative">
     130              :     <div
     131              :       v-if="searchedWidgetsSectionDataList.length === 0"
     132              :       class="px-4 py-10 text-center text-sm text-muted-foreground"
     133              :     >
     134              :       {{
     135              :         isSearching
     136              :           ? t('rightSidePanel.noneSearchDesc')
     137              :           : t('rightSidePanel.nodesNoneDesc')
     138              :       }}
     139              :     </div>
     140          149 :     <SectionWidgets
     141              :       v-for="{ widgets, node } in searchedWidgetsSectionDataList"
     142              :       :key="node.id"
     143              :       :node
     144              :       :label
     145              :       :widgets
     146              :       :collapse="isSectionCollapsed(node.id) && !isSearching"
     147              :       :show-locate-button="isMultipleNodesSelected"
     148              :       :tooltip="
     149              :         isSearching || widgets.length
     150              :           ? ''
     151              :           : t('rightSidePanel.inputsNoneTooltip')
     152              :       "
     153              :       class="border-b"
     154              :       @update:collapse="setSectionCollapsed(node.id, $event)"
     155              :     />
     156              :   </TransitionGroup>
     157              :   <template v-if="advancedWidgetsSectionDataList.length > 0 && !isSearching">
     158            1 :     <SectionWidgets
     159              :       v-for="{ widgets, node } in advancedWidgetsSectionDataList"
     160              :       :key="`advanced-${node.id}`"
     161              :       v-model:collapse="advancedCollapsed"
     162              :       :node
     163              :       :label="advancedLabel"
     164              :       :widgets
     165              :       :show-locate-button="isMultipleNodesSelected"
     166              :       class="border-b"
     167              :     />
     168              :   </template>
     169              : </template>
        

Generated by: LCOV version 2.0-1