LCOV - code coverage report
Current view: top level - src/composables/graph - useSelectionMenuOptions.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 { useI18n } from 'vue-i18n'
       2              : 
       3              : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
       4              : 
       5              : import { useFrameNodes } from './useFrameNodes'
       6              : import { BadgeVariant } from './menuOption'
       7              : import type { MenuOption } from './menuOption'
       8              : import { useNodeArrangement } from './useNodeArrangement'
       9              : import { useSelectionOperations } from './useSelectionOperations'
      10              : import { useSubgraphOperations } from './useSubgraphOperations'
      11              : 
      12              : /**
      13              :  * Composable for selection-related menu operations
      14              :  */
      15         2355 : export function useSelectionMenuOptions() {
      16         2355 :   const { t } = useI18n()
      17         2355 :   const {
      18              :     copySelection,
      19              :     duplicateSelection,
      20              :     deleteSelection,
      21              :     renameSelection
      22              :   } = useSelectionOperations()
      23              : 
      24         2355 :   const { alignOptions, distributeOptions, applyAlign, applyDistribute } =
      25              :     useNodeArrangement()
      26              : 
      27         2355 :   const { convertToSubgraph, unpackSubgraph, addSubgraphToLibrary } =
      28              :     useSubgraphOperations()
      29              : 
      30         2355 :   const { frameNodes } = useFrameNodes()
      31              : 
      32         2355 :   const getBasicSelectionOptions = (): MenuOption[] => [
      33              :     {
      34              :       label: t('contextMenu.Rename'),
      35              :       action: renameSelection
      36              :     },
      37              :     {
      38              :       label: t('contextMenu.Copy'),
      39              :       shortcut: 'Ctrl+C',
      40              :       action: copySelection
      41              :     },
      42              :     {
      43              :       label: t('contextMenu.Duplicate'),
      44              :       shortcut: 'Ctrl+D',
      45              :       action: duplicateSelection
      46              :     }
      47              :   ]
      48              : 
      49         2355 :   const getSubgraphOptions = ({
      50              :     hasSubgraphs,
      51              :     hasMultipleSelection
      52              :   }: {
      53              :     hasSubgraphs: boolean
      54              :     hasMultipleSelection: boolean
      55              :   }): MenuOption[] => {
      56        13397 :     const convertOption: MenuOption = {
      57              :       label: t('contextMenu.Convert to Subgraph'),
      58              :       icon: 'icon-[lucide--shrink]',
      59              :       action: convertToSubgraph,
      60              :       badge: BadgeVariant.NEW
      61              :     }
      62              : 
      63        13397 :     const options: MenuOption[] = []
      64              :     const showConvertOption = !hasSubgraphs || hasMultipleSelection
      65              : 
      66        13397 :     if (showConvertOption) {
      67        12973 :       options.push(convertOption)
      68              :     }
      69              : 
      70        13397 :     if (hasSubgraphs) {
      71          449 :       if (!hasMultipleSelection) {
      72          424 :         options.push({
      73              :           label: t('contextMenu.Add Subgraph to Library'),
      74              :           icon: 'icon-[lucide--folder-plus]',
      75              :           action: addSubgraphToLibrary
      76              :         })
      77              :       }
      78          449 :       options.push({
      79              :         label: t('contextMenu.Unpack Subgraph'),
      80              :         icon: 'icon-[lucide--expand]',
      81              :         action: unpackSubgraph
      82              :       })
      83              :     }
      84              : 
      85        13397 :     return options
      86              :   }
      87              : 
      88         2355 :   const getMultipleNodesOptions = (): MenuOption[] => [
      89              :     {
      90              :       label: t('g.frameNodes'),
      91              :       icon: 'icon-[lucide--frame]',
      92              :       action: frameNodes
      93              :     }
      94              :   ]
      95              : 
      96         2355 :   const getAlignmentOptions = (alignTo?: LGraphNode): MenuOption[] => [
      97              :     {
      98              :       label: t('contextMenu.Align Selected To'),
      99              :       icon: 'icon-[lucide--align-start-horizontal]',
     100              :       hasSubmenu: true,
     101              :       submenu: alignOptions.map((align) => ({
     102              :         label: align.localizedName,
     103              :         icon: align.icon,
     104              :         action: () => applyAlign(align, alignTo)
     105              :       })),
     106              :       action: () => {}
     107              :     },
     108              :     {
     109              :       label: t('contextMenu.Distribute Nodes'),
     110              :       icon: 'icon-[lucide--align-center-horizontal]',
     111              :       hasSubmenu: true,
     112              :       submenu: distributeOptions.map((distribute) => ({
     113              :         label: distribute.localizedName,
     114              :         icon: distribute.icon,
     115              :         action: () => applyDistribute(distribute)
     116              :       })),
     117              :       action: () => {}
     118              :     }
     119              :   ]
     120              : 
     121         2355 :   const getDeleteOption = (disabled: boolean): MenuOption => ({
     122              :     label: t('contextMenu.Delete'),
     123              :     icon: 'icon-[lucide--trash-2]',
     124              :     shortcut: 'Delete',
     125              :     disabled,
     126              :     action: deleteSelection
     127              :   })
     128              : 
     129         2355 :   return {
     130              :     getBasicSelectionOptions,
     131              :     getSubgraphOptions,
     132              :     getMultipleNodesOptions,
     133              :     getDeleteOption,
     134              :     getAlignmentOptions
     135              :   }
     136              : }
        

Generated by: LCOV version 2.0-1