LCOV - code coverage report
Current view: top level - src/composables/graph - useNodeMenuOptions.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 21 21
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { computed } from 'vue'
       2              : import { useI18n } from 'vue-i18n'
       3              : 
       4              : import { useSelectedLiteGraphItems } from '@/composables/canvas/useSelectedLiteGraphItems'
       5              : import { LGraphEventMode } from '@/lib/litegraph/src/litegraph'
       6              : 
       7              : import type { MenuOption } from './menuOption'
       8              : import { useNodeCustomization } from './useNodeCustomization'
       9              : import { useSelectedNodeActions } from './useSelectedNodeActions'
      10              : import type { NodeSelectionState } from './useSelectionState'
      11              : 
      12              : /**
      13              :  * Composable for node-related menu operations
      14              :  */
      15         2355 : export function useNodeMenuOptions() {
      16         2355 :   const { t } = useI18n()
      17         2355 :   const { shapeOptions, applyShape, applyColor, colorOptions, isLightTheme } =
      18              :     useNodeCustomization()
      19         2355 :   const {
      20              :     adjustNodeSize,
      21              :     toggleNodeCollapse,
      22              :     toggleNodePin,
      23              :     toggleNodeBypass,
      24              :     runBranch
      25              :   } = useSelectedNodeActions()
      26         2355 :   const { areAllSelectedNodesInMode } = useSelectedLiteGraphItems()
      27              : 
      28         2355 :   const shapeSubmenu = computed(() =>
      29              :     shapeOptions.map((shape) => ({
      30              :       label: shape.localizedName,
      31              :       action: () => applyShape(shape)
      32              :     }))
      33              :   )
      34              : 
      35         2355 :   const colorSubmenu = computed(() => {
      36         2366 :     return colorOptions.map((colorOption) => ({
      37              :       label: colorOption.localizedName,
      38              :       color: isLightTheme.value
      39              :         ? colorOption.value.light
      40              :         : colorOption.value.dark,
      41              :       action: () =>
      42              :         applyColor(colorOption.name === 'noColor' ? null : colorOption)
      43              :     }))
      44              :   })
      45              : 
      46         2355 :   const getAdjustSizeOption = (): MenuOption => ({
      47              :     label: t('contextMenu.Adjust Size'),
      48              :     icon: 'icon-[lucide--move-diagonal-2]',
      49              :     action: adjustNodeSize
      50              :   })
      51              : 
      52         2355 :   const getNodeVisualOptions = (
      53              :     states: NodeSelectionState,
      54              :     bump: () => void
      55              :   ): MenuOption[] => [
      56              :     {
      57              :       label: states.collapsed
      58              :         ? t('contextMenu.Expand Node')
      59              :         : t('contextMenu.Minimize Node'),
      60              :       icon: states.collapsed
      61              :         ? 'icon-[lucide--maximize-2]'
      62              :         : 'icon-[lucide--minimize-2]',
      63              :       action: () => {
      64            7 :         toggleNodeCollapse()
      65            7 :         bump()
      66              :       }
      67              :     },
      68              :     {
      69              :       label: t('contextMenu.Shape'),
      70              :       icon: 'icon-[lucide--box]',
      71              :       hasSubmenu: true,
      72              :       submenu: shapeSubmenu.value,
      73              :       isShapePicker: true,
      74              :       action: () => {}
      75              :     },
      76              :     {
      77              :       label: t('contextMenu.Color'),
      78              :       icon: 'icon-[lucide--palette]',
      79              :       hasSubmenu: true,
      80              :       submenu: colorSubmenu.value,
      81              :       isColorPicker: true,
      82              :       action: () => {}
      83              :     }
      84              :   ]
      85              : 
      86         2355 :   const getPinOption = (
      87              :     states: NodeSelectionState,
      88              :     bump: () => void
      89              :   ): MenuOption => ({
      90              :     label: states.pinned ? t('contextMenu.Unpin') : t('contextMenu.Pin'),
      91              :     icon: states.pinned ? 'icon-[lucide--pin-off]' : 'icon-[lucide--pin]',
      92              :     action: () => {
      93            6 :       toggleNodePin()
      94            6 :       bump()
      95              :     }
      96              :   })
      97              : 
      98         2355 :   const getBypassOption = (bump: () => void): MenuOption => ({
      99              :     label: areAllSelectedNodesInMode(LGraphEventMode.BYPASS)
     100              :       ? t('contextMenu.Remove Bypass')
     101              :       : t('contextMenu.Bypass'),
     102              :     icon: 'icon-[lucide--redo-dot]',
     103              :     shortcut: 'Ctrl+B',
     104              :     action: () => {
     105            6 :       toggleNodeBypass()
     106            6 :       bump()
     107              :     }
     108              :   })
     109              : 
     110         2355 :   const getRunBranchOption = (): MenuOption => ({
     111              :     label: t('contextMenu.Run Branch'),
     112              :     icon: 'icon-[lucide--play]',
     113              :     action: runBranch
     114              :   })
     115              : 
     116         2355 :   const getNodeInfoOption = (openNodeInfo: () => boolean): MenuOption => ({
     117              :     label: t('contextMenu.Node Info'),
     118              :     icon: 'icon-[lucide--info]',
     119              :     action: openNodeInfo
     120              :   })
     121              : 
     122         2355 :   return {
     123              :     getNodeInfoOption,
     124              :     getAdjustSizeOption,
     125              :     getNodeVisualOptions,
     126              :     getPinOption,
     127              :     getBypassOption,
     128              :     getRunBranchOption,
     129              :     colorSubmenu
     130              :   }
     131              : }
        

Generated by: LCOV version 2.0-1