LCOV - code coverage report
Current view: top level - src/components/sidebar/tabs - NodeLibrarySidebarTab.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 77.0 % 74 57
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2           58 :   <div class="h-full">
       3              :     <SidebarTabTemplate
       4              :       v-if="!isHelpOpen"
       5              :       :title="$t('sideToolbar.nodeLibrary')"
       6              :     >
       7              :       <template #tool-buttons>
       8              :         <Button
       9              :           :tooltip="$t('g.newFolder')"
      10              :           tooltip-side="bottom"
      11              :           class="new-folder-button"
      12              :           variant="muted-textonly"
      13              :           size="icon"
      14              :           :aria-label="$t('g.newFolder')"
      15              :           @click="nodeBookmarkTreeExplorerRef?.addNewBookmarkFolder()"
      16              :         >
      17              :           <i class="icon-[lucide--folder-plus]" />
      18              :         </Button>
      19              :         <PopoverRoot v-slot="{ close }">
      20              :           <PopoverTrigger as-child>
      21              :             <Button
      22              :               :tooltip="$t('sideToolbar.nodeLibraryTab.groupBy')"
      23              :               tooltip-side="bottom"
      24              :               variant="muted-textonly"
      25              :               size="icon"
      26              :               :aria-label="$t('sideToolbar.nodeLibraryTab.groupBy')"
      27              :             >
      28              :               <i :class="selectedGroupingIcon" />
      29              :             </Button>
      30              :           </PopoverTrigger>
      31              :           <PopoverContent
      32              :             class="w-auto rounded-lg border-border/50 p-0 shadow-lg data-[state=open]:animate-none"
      33              :             dismiss-on-viewport-change
      34              :           >
      35              :             <div class="flex flex-col gap-1 p-2">
      36            0 :               <Button
      37              :                 v-for="option in groupingOptions"
      38              :                 :key="option.id"
      39              :                 :variant="
      40              :                   selectedGroupingId === option.id ? 'primary' : 'textonly'
      41              :                 "
      42              :                 class="justify-start"
      43              :                 @click="
      44              :                   () => {
      45              :                     selectGrouping(option.id)
      46              :                     close()
      47              :                   }
      48              :                 "
      49              :               >
      50              :                 <i :class="option.icon" />
      51              :                 {{ $t(option.label) }}
      52              :               </Button>
      53              :             </div>
      54              :           </PopoverContent>
      55              :         </PopoverRoot>
      56              :         <PopoverRoot v-slot="{ close }">
      57              :           <PopoverTrigger as-child>
      58              :             <Button
      59              :               :tooltip="$t('sideToolbar.nodeLibraryTab.sortMode')"
      60              :               tooltip-side="bottom"
      61              :               variant="muted-textonly"
      62              :               size="icon"
      63              :               :aria-label="$t('sideToolbar.nodeLibraryTab.sortMode')"
      64              :             >
      65              :               <i :class="selectedSortingIcon" />
      66              :             </Button>
      67              :           </PopoverTrigger>
      68              :           <PopoverContent
      69              :             class="w-auto rounded-lg border-border/50 p-0 shadow-lg data-[state=open]:animate-none"
      70              :             dismiss-on-viewport-change
      71              :           >
      72              :             <div class="flex flex-col gap-1 p-2">
      73            0 :               <Button
      74              :                 v-for="option in sortingOptions"
      75              :                 :key="option.id"
      76              :                 :variant="
      77              :                   selectedSortingId === option.id ? 'primary' : 'textonly'
      78              :                 "
      79              :                 class="justify-start"
      80              :                 @click="
      81              :                   () => {
      82              :                     selectSorting(option.id)
      83              :                     close()
      84              :                   }
      85              :                 "
      86              :               >
      87              :                 <i :class="option.icon" />
      88              :                 {{ $t(option.label) }}
      89              :               </Button>
      90              :             </div>
      91              :           </PopoverContent>
      92              :         </PopoverRoot>
      93              :         <Button
      94              :           :tooltip="$t('sideToolbar.nodeLibraryTab.resetView')"
      95              :           tooltip-side="bottom"
      96              :           variant="muted-textonly"
      97              :           size="icon"
      98              :           :aria-label="$t('sideToolbar.nodeLibraryTab.resetView')"
      99              :           @click="resetOrganization"
     100              :         >
     101              :           <i class="icon-[lucide--filter-x]" />
     102              :         </Button>
     103              :         <Button
     104              :           :tooltip="$t('menu.refresh')"
     105              :           tooltip-side="bottom"
     106              :           variant="muted-textonly"
     107              :           size="icon"
     108              :           :aria-label="$t('menu.refresh')"
     109              :           @click="() => commandStore.execute('Comfy.RefreshNodeDefinitions')"
     110              :         >
     111              :           <i class="icon-[lucide--refresh-cw]" />
     112              :         </Button>
     113              :       </template>
     114              :       <template #header>
     115              :         <SidebarTopArea>
     116              :           <SearchInput
     117              :             ref="searchBoxRef"
     118              :             v-model="searchQuery"
     119              :             :clear-label="$t('g.clear')"
     120              :             :accessible-label="
     121              :               $t('g.searchPlaceholder', { subject: $t('g.nodes') })
     122              :             "
     123              :             data-testid="node-library-search"
     124              :             class="node-lib-search-box"
     125              :             :placeholder="$t('g.searchPlaceholder', { subject: $t('g.nodes') })"
     126              :             @search="handleSearch"
     127              :           />
     128              :           <template #actions>
     129              :             <PopoverRoot>
     130              :               <PopoverTrigger as-child>
     131              :                 <Button
     132              :                   variant="secondary"
     133              :                   size="icon"
     134              :                   class="filter-button"
     135              :                   :aria-label="$t('g.filter')"
     136              :                 >
     137              :                   <i class="icon-[lucide--list-filter]" />
     138              :                 </Button>
     139              :               </PopoverTrigger>
     140              :               <PopoverContent
     141              :                 class="ml-[-13px] w-auto rounded-lg border-border/50 p-0 shadow-lg data-[state=open]:animate-none"
     142              :                 dismiss-on-viewport-change
     143              :               >
     144              :                 <NodeSearchFilter @add-filter="onAddFilter" />
     145              :               </PopoverContent>
     146              :             </PopoverRoot>
     147              :           </template>
     148              :         </SidebarTopArea>
     149              :         <div class="px-4">
     150              :           <div
     151              :             v-if="filters?.length"
     152              :             class="search-filters flex flex-wrap gap-2 pb-2"
     153              :           >
     154            0 :             <SearchFilterChip
     155              :               v-for="filter in filters"
     156              :               :key="filter.id"
     157              :               :text="filter.text"
     158              :               :badge="filter.badge"
     159              :               :badge-class="filter.badgeClass"
     160              :               @remove="onRemoveFilter(filter)"
     161              :             />
     162              :           </div>
     163              :         </div>
     164              :       </template>
     165              :       <template #body>
     166              :         <div>
     167              :           <NodeBookmarkTreeExplorer
     168              :             ref="nodeBookmarkTreeExplorerRef"
     169              :             :filtered-node-defs
     170              :             :open-node-help="openNodeHelp"
     171              :           />
     172              :           <div
     173              :             v-show="nodeBookmarkStore.bookmarks.length > 0"
     174              :             role="separator"
     175              :             class="m-2 border-0 border-t border-dashed"
     176              :           />
     177              :           <TreeExplorer
     178              :             v-model:expanded-keys="expandedKeys"
     179              :             data-testid="node-library-tree"
     180              :             class="node-lib-tree-explorer"
     181              :             :root="renderedRoot"
     182              :           >
     183              :             <template #node="{ node }">
     184              :               <TreeExplorerTreeNode :node>
     185              :                 <template #before-label>
     186              :                   <Badge v-if="node.data?.experimental" severity="primary">
     187              :                     {{ $t('g.experimental') }}
     188              :                   </Badge>
     189              :                   <Badge v-if="node.data?.deprecated" severity="danger">
     190              :                     {{ $t('g.deprecated') }}
     191              :                   </Badge>
     192              :                 </template>
     193              :                 <template v-if="node.data" #actions>
     194              :                   <template
     195              :                     v-if="subgraphStore.isUserBlueprint(node.data.name)"
     196              :                   >
     197              :                     <Button
     198              :                       variant="destructive"
     199              :                       size="icon-sm"
     200              :                       :aria-label="$t('g.delete')"
     201              :                       @click.stop="
     202              :                         void subgraphStore.deleteBlueprint(node.data.name)
     203              :                       "
     204              :                     >
     205              :                       <i class="icon-[lucide--trash-2]" />
     206              :                     </Button>
     207              :                     <Button
     208              :                       variant="muted-textonly"
     209              :                       size="icon-sm"
     210              :                       :aria-label="$t('g.edit')"
     211              :                       @click.stop="
     212              :                         void subgraphStore.editBlueprint(node.data.name)
     213              :                       "
     214              :                     >
     215              :                       <i class="icon-[lucide--square-pen]" />
     216              :                     </Button>
     217              :                   </template>
     218              :                   <template v-else>
     219              :                     <Button
     220              :                       variant="muted-textonly"
     221              :                       size="icon-sm"
     222              :                       :aria-label="$t('icon.bookmark')"
     223              :                       @click.stop="
     224              :                         void nodeBookmarkStore.toggleBookmark(node.data)
     225              :                       "
     226              :                     >
     227              :                       <i
     228              :                         :class="
     229              :                           cn(
     230              :                             nodeBookmarkStore.isBookmarked(node.data)
     231              :                               ? 'pi pi-bookmark-fill'
     232              :                               : 'pi pi-bookmark',
     233              :                             'size-3.5'
     234              :                           )
     235              :                         "
     236              :                       />
     237              :                     </Button>
     238              :                     <Button
     239              :                       :tooltip="$t('g.learnMore')"
     240              :                       tooltip-side="bottom"
     241              :                       variant="muted-textonly"
     242              :                       size="icon-sm"
     243              :                       :aria-label="$t('g.learnMore')"
     244              :                       @click.stop="openNodeHelp(node.data)"
     245              :                     >
     246              :                       <i class="pi pi-question size-3.5" />
     247              :                     </Button>
     248              :                   </template>
     249              :                 </template>
     250              :               </TreeExplorerTreeNode>
     251              :             </template>
     252              :             <template #preview="{ node }">
     253              :               <NodePreview v-if="node.data" :node-def="node.data" />
     254              :             </template>
     255              :           </TreeExplorer>
     256              :         </div>
     257              :       </template>
     258              :     </SidebarTabTemplate>
     259              : 
     260              :     <NodeHelpPage v-else :node="currentHelpNode!" @close="closeHelp" />
     261              :   </div>
     262              : </template>
     263              : 
     264              : <script setup lang="ts">
     265              : import { useLocalStorage } from '@vueuse/core'
     266              : import { storeToRefs } from 'pinia'
     267              : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
     268              : import { PopoverRoot, PopoverTrigger } from 'reka-ui'
     269              : import type { Ref } from 'vue'
     270              : import {
     271              :   computed,
     272              :   getCurrentInstance,
     273              :   nextTick,
     274              :   onMounted,
     275              :   onUnmounted,
     276              :   ref
     277              : } from 'vue'
     278              : 
     279              : import SearchFilterChip from '@/components/common/SearchFilterChip.vue'
     280              : import type { SearchFilter } from '@/components/common/SearchFilterChip.vue'
     281              : import SearchInput from '@comfyorg/design-system/search-input/SearchInput'
     282              : import TreeExplorer from '@/components/common/TreeExplorer.vue'
     283              : import TreeExplorerTreeNode from '@/components/common/TreeExplorerTreeNode.vue'
     284              : import NodePreview from '@/components/node/NodePreview.vue'
     285              : import { renderNodePreview } from '@/components/node/renderNodePreview'
     286              : import NodeSearchFilter from '@/components/searchbox/NodeSearchFilter.vue'
     287              : import SidebarTabTemplate from '@/components/sidebar/tabs/SidebarTabTemplate.vue'
     288              : import SidebarTopArea from '@comfyorg/design-system/navigation/SidebarTopArea'
     289              : import NodeHelpPage from '@/components/sidebar/tabs/nodeLibrary/NodeHelpPage.vue'
     290              : import Badge from '@comfyorg/design-system/badge/Badge'
     291              : import Button from '@comfyorg/design-system/button/Button'
     292              : import { useTreeExpansion } from '@/composables/useTreeExpansion'
     293              : import { useTelemetry } from '@comfyorg/telemetry'
     294              : import { withNodeAddSource } from '@/platform/telemetry/nodeAdded/nodeAddSource'
     295              : import { useSearchQueryTracking } from '@/platform/telemetry/searchQuery/useSearchQueryTracking'
     296              : import { useLitegraphService } from '@/services/litegraphService'
     297              : import {
     298              :   DEFAULT_GROUPING_ID,
     299              :   DEFAULT_SORTING_ID,
     300              :   nodeOrganizationService
     301              : } from '@/services/nodeOrganizationService'
     302              : import { useCommandStore } from '@/platform/keybindings/commandStore'
     303              : import { useNodeBookmarkStore } from '@/stores/nodeBookmarkStore'
     304              : import type { ComfyNodeDefImpl } from '@/core/graph/nodeDef/ComfyNodeDefImpl'
     305              : import { useNodeDefStore } from '@/stores/nodeDefStore'
     306              : import { useSubgraphStore } from '@/stores/subgraphStore'
     307              : import { useNodeHelpStore } from '@/stores/workspace/nodeHelpStore'
     308              : import type {
     309              :   GroupingStrategyId,
     310              :   SortingStrategyId
     311              : } from '@/types/nodeOrganizationTypes'
     312              : import type { TreeExplorerNode, TreeNode } from '@/types/treeExplorerTypes'
     313              : import type { FuseFilterWithValue } from '@/utils/fuseUtil'
     314              : import { cn } from '@comfyorg/tailwind-utils'
     315              : 
     316              : import NodeBookmarkTreeExplorer from './nodeLibrary/NodeBookmarkTreeExplorer.vue'
     317              : 
     318              : const instance = getCurrentInstance()!
     319           55 : const appContext = instance.appContext
     320           55 : const nodeDefStore = useNodeDefStore()
     321           55 : const nodeBookmarkStore = useNodeBookmarkStore()
     322           55 : const nodeHelpStore = useNodeHelpStore()
     323           55 : const subgraphStore = useSubgraphStore()
     324           55 : const commandStore = useCommandStore()
     325           55 : const expandedKeys = ref<Record<string, boolean>>({})
     326           55 : const { expandNode, toggleNodeOnEvent } = useTreeExpansion(expandedKeys)
     327              : 
     328           55 : const nodeBookmarkTreeExplorerRef = ref<InstanceType<
     329              :   typeof NodeBookmarkTreeExplorer
     330              : > | null>(null)
     331           55 : const searchBoxRef = ref()
     332              : 
     333           55 : onMounted(() => {
     334           55 :   searchBoxRef.value?.focus()
     335              : })
     336              : 
     337           55 : const selectedGroupingId = useLocalStorage<GroupingStrategyId>(
     338              :   'Comfy.NodeLibrary.GroupBy',
     339              :   DEFAULT_GROUPING_ID
     340              : )
     341           55 : const selectedSortingId = useLocalStorage<SortingStrategyId>(
     342              :   'Comfy.NodeLibrary.SortBy',
     343              :   DEFAULT_SORTING_ID
     344              : )
     345              : 
     346           55 : const searchQuery = ref<string>('')
     347              : 
     348           55 : const { currentHelpNode, isHelpOpen } = storeToRefs(nodeHelpStore)
     349           55 : const { openHelp, closeHelp } = nodeHelpStore
     350              : 
     351           55 : onUnmounted(closeHelp)
     352              : 
     353            2 : function openNodeHelp(nodeDef: ComfyNodeDefImpl) {
     354            2 :   useTelemetry()?.trackUiButtonClicked({
     355              :     button_id: 'node_library_help_button',
     356              :     element_group: 'node_library'
     357              :   })
     358            2 :   openHelp(nodeDef)
     359              : }
     360              : 
     361           55 : const groupingOptions = computed(() =>
     362              :   nodeOrganizationService.getGroupingStrategies().map((strategy) => ({
     363              :     id: strategy.id,
     364              :     label: strategy.label,
     365              :     icon: strategy.icon
     366              :   }))
     367              : )
     368           55 : const sortingOptions = computed(() =>
     369              :   nodeOrganizationService.getSortingStrategies().map((strategy) => ({
     370              :     id: strategy.id,
     371              :     label: strategy.label,
     372              :     icon: strategy.icon
     373              :   }))
     374              : )
     375              : 
     376           55 : const selectedGroupingIcon = computed(() =>
     377              :   nodeOrganizationService.getGroupingIcon(selectedGroupingId.value)
     378              : )
     379           55 : const selectedSortingIcon = computed(() =>
     380              :   nodeOrganizationService.getSortingIcon(selectedSortingId.value)
     381              : )
     382              : 
     383           55 : const selectGrouping = (groupingId: string) => {
     384            0 :   selectedGroupingId.value = groupingId as GroupingStrategyId
     385              : }
     386           55 : const selectSorting = (sortingId: string) => {
     387            0 :   selectedSortingId.value = sortingId as SortingStrategyId
     388              : }
     389              : 
     390           55 : const resetOrganization = () => {
     391            0 :   selectedGroupingId.value = DEFAULT_GROUPING_ID
     392            0 :   selectedSortingId.value = DEFAULT_SORTING_ID
     393              : }
     394              : 
     395           55 : const root = computed(() => {
     396              :   // Determine which nodes to use
     397          837 :   const nodes =
     398              :     filteredNodeDefs.value.length > 0
     399              :       ? filteredNodeDefs.value
     400              :       : nodeDefStore.visibleNodeDefs
     401              : 
     402              :   // Use the service to organize nodes
     403          837 :   return nodeOrganizationService.organizeNodes(nodes, {
     404              :     groupBy: selectedGroupingId.value,
     405              :     sortBy: selectedSortingId.value
     406              :   })
     407              : })
     408              : 
     409           55 : const renderedRoot = computed<TreeExplorerNode<ComfyNodeDefImpl>>(() => {
     410          837 :   const fillNodeInfo = (
     411              :     node: TreeNode<ComfyNodeDefImpl>
     412              :   ): TreeExplorerNode<ComfyNodeDefImpl> => {
     413      1105794 :     const children = node.children?.map(fillNodeInfo)
     414              : 
     415      1105794 :     return {
     416              :       key: node.key,
     417              :       label: node.leaf ? (node.data?.display_name ?? node.label) : node.label,
     418              :       leaf: node.leaf,
     419              :       data: node.data,
     420              :       getIcon() {
     421      1135872 :         if (this.leaf) {
     422       913488 :           return 'pi pi-circle-fill'
     423              :         }
     424              :       },
     425              :       children,
     426              :       draggable: node.leaf,
     427              :       renderDragPreview(container) {
     428            2 :         if (!node.data) return
     429            2 :         return renderNodePreview(container, node.data, appContext)
     430              :       },
     431              :       handleClick(e: MouseEvent) {
     432           35 :         const nodeDef = this.data
     433           35 :         if (this.leaf && nodeDef) {
     434           13 :           withNodeAddSource('sidebar_drag', () =>
     435              :             useLitegraphService().addNodeOnGraph(nodeDef)
     436              :           )
     437              :         } else {
     438           22 :           toggleNodeOnEvent(e, this)
     439              :         }
     440              :       },
     441              :       ...(node.leaf &&
     442              :       node.data &&
     443              :       subgraphStore.isUserBlueprint(node.data.name)
     444              :         ? {
     445              :             async handleDelete() {
     446            0 :               if (this.data) await subgraphStore.deleteBlueprint(this.data.name)
     447              :             }
     448              :           }
     449              :         : {})
     450              :     }
     451              :   }
     452          837 :   return fillNodeInfo(root.value)
     453              : })
     454              : 
     455           55 : const filteredNodeDefs = ref<ComfyNodeDefImpl[]>([])
     456           55 : useSearchQueryTracking('node_sidebar', searchQuery, filteredNodeDefs)
     457           55 : const filters: Ref<
     458              :   (SearchFilter & { filter: FuseFilterWithValue<ComfyNodeDefImpl, string> })[]
     459              : > = ref([])
     460           55 : const handleSearch = async (query: string) => {
     461              :   // Don't apply a min length filter because it does not make sense in
     462              :   // multi-byte languages like Chinese, Japanese, Korean, etc.
     463            3 :   if (query.length === 0 && !filters.value.length) {
     464            0 :     filteredNodeDefs.value = []
     465            0 :     expandedKeys.value = {}
     466            0 :     return
     467              :   }
     468              : 
     469            3 :   const f = filters.value.map((f) => f.filter)
     470            3 :   filteredNodeDefs.value = nodeDefStore.nodeSearchService.searchNode(
     471              :     query,
     472              :     f,
     473              :     {
     474              :       limit: 64
     475              :     },
     476              :     {
     477              :       matchWildcards: false
     478              :     }
     479              :   )
     480              : 
     481            3 :   await nextTick()
     482              :   // Expand the search results tree
     483            3 :   if (filteredNodeDefs.value.length > 0) {
     484            3 :     expandNode(root.value)
     485              :   }
     486              : }
     487              : 
     488           55 : const onAddFilter = async (
     489              :   filterAndValue: FuseFilterWithValue<ComfyNodeDefImpl, string>
     490              : ) => {
     491            0 :   filters.value.push({
     492              :     filter: filterAndValue,
     493              :     badge: filterAndValue.filterDef.invokeSequence.toUpperCase(),
     494              :     badgeClass: filterAndValue.filterDef.invokeSequence + '-badge',
     495              :     text: filterAndValue.value,
     496              :     id: +new Date()
     497              :   })
     498              : 
     499            0 :   await handleSearch(searchQuery.value)
     500              : }
     501              : 
     502           55 : const onRemoveFilter = async (
     503              :   filterAndValue: SearchFilter & {
     504              :     filter: FuseFilterWithValue<ComfyNodeDefImpl, string>
     505              :   }
     506              : ) => {
     507            0 :   const index = filters.value.findIndex((f) => f === filterAndValue)
     508            0 :   if (index !== -1) {
     509            0 :     filters.value.splice(index, 1)
     510              :   }
     511            0 :   await handleSearch(searchQuery.value)
     512              : }
     513              : </script>
        

Generated by: LCOV version 2.0-1