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

            Line data    Source code
       1              : <script setup lang="ts">
       2              : import { isEqual } from 'es-toolkit'
       3              : import { computed } from 'vue'
       4              : import { useI18n } from 'vue-i18n'
       5              : 
       6              : import Button from '@comfyorg/design-system/button/Button'
       7              : import Menu from '@comfyorg/design-system/menu/Menu'
       8              : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
       9              : import { inputForWidget } from '@/core/graph/subgraph/promotedInputWidget'
      10              : import { promoteWidget } from '@/core/graph/subgraph/promotionUtils'
      11              : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
      12              : import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode'
      13              : import type { IBaseWidget } from '@comfyorg/graph-model/widgets'
      14              : import { useTelemetry } from '@comfyorg/telemetry'
      15              : import { useNodeDefStore } from '@/stores/nodeDefStore'
      16              : import { useWidgetValueStore } from '@/stores/widgetValueStore'
      17              : import { useFavoritedWidgetsStore } from '@/renderer/extensions/propertiesPanel/favoritedWidgetsStore'
      18              : import { getWidgetDefaultValue, promptWidgetLabel } from '@/utils/widgetUtil'
      19              : import type { WidgetValue } from '@/utils/widgetUtil'
      20              : 
      21              : const { widget, node, host } = defineProps<{
      22              :   widget: IBaseWidget
      23              :   node: LGraphNode
      24              :   host?: SubgraphNode
      25              : }>()
      26              : 
      27         2355 : const emit = defineEmits<{
      28              :   resetToDefault: [value: WidgetValue]
      29              : }>()
      30              : 
      31          387 : const label = defineModel<string>('label', { required: true })
      32              : 
      33          387 : const favoritedWidgetsStore = useFavoritedWidgetsStore()
      34          387 : const nodeDefStore = useNodeDefStore()
      35          387 : const { t } = useI18n()
      36              : 
      37          387 : const isLinked = computed(() => {
      38            0 :   if (!node.isSubgraphNode()) return false
      39            0 :   return inputForWidget(node, widget)?.widgetId != null
      40              : })
      41          387 : const canShowInput = computed(() => host != null && !isLinked.value)
      42          387 : const isFavorited = computed(() =>
      43              :   favoritedWidgetsStore.isFavorited(node, widget.name)
      44              : )
      45              : 
      46          387 : const inputSpec = computed(() =>
      47              :   nodeDefStore.getInputSpecForWidget(node, widget.name)
      48              : )
      49              : 
      50          387 : const defaultValue = computed(() => getWidgetDefaultValue(inputSpec.value))
      51              : 
      52          387 : const hasDefault = computed(() => defaultValue.value !== undefined)
      53              : 
      54          387 : const currentValue = computed(() => {
      55            5 :   if (!widget.widgetId) return widget.value
      56            5 :   const state = useWidgetValueStore().getWidget(widget.widgetId)
      57            5 :   return state ? state.value : widget.value
      58              : })
      59              : 
      60          387 : const isCurrentValueDefault = computed(() => {
      61            5 :   if (!hasDefault.value) return true
      62            5 :   return isEqual(currentValue.value, defaultValue.value)
      63              : })
      64              : 
      65            0 : async function handleRename() {
      66            0 :   const newLabel = await promptWidgetLabel(widget, t)
      67            0 :   if (newLabel !== null) label.value = newLabel
      68              : }
      69              : 
      70            0 : function handleShowInput() {
      71            0 :   if (!host) return
      72            0 :   promoteWidget(node, widget, [host])
      73              : }
      74              : 
      75            2 : function handleToggleFavorite() {
      76            2 :   useTelemetry()?.trackWidgetFavoriteToggled({
      77              :     node_type: node.type,
      78              :     widget_name: widget.name,
      79              :     widget_type: widget.type,
      80              :     is_favorited: !isFavorited.value,
      81              :     source: 'right_side_panel'
      82              :   })
      83            2 :   favoritedWidgetsStore.toggleFavorite(node, widget.name)
      84              : }
      85              : 
      86            0 : function handleResetToDefault() {
      87            0 :   if (!hasDefault.value) return
      88            0 :   emit('resetToDefault', defaultValue.value)
      89              : }
      90              : 
      91          387 : const menuItems = computed<MenuItem[]>(() => [
      92              :   {
      93              :     label: () => t('g.rename'),
      94              :     icon: 'icon-[lucide--edit]',
      95              :     command: handleRename
      96              :   },
      97              :   {
      98              :     label: () => t('rightSidePanel.showInput'),
      99              :     icon: 'icon-[lucide--eye]',
     100              :     visible: () => canShowInput.value,
     101              :     command: handleShowInput
     102              :   },
     103              :   {
     104              :     label: () =>
     105              :       t(
     106              :         isFavorited.value
     107              :           ? 'rightSidePanel.removeFavorite'
     108              :           : 'rightSidePanel.addFavorite'
     109              :       ),
     110              :     icon: 'icon-[lucide--star]',
     111              :     command: handleToggleFavorite
     112              :   },
     113              :   {
     114              :     label: () => t('rightSidePanel.resetToDefault'),
     115              :     icon: 'icon-[lucide--rotate-ccw]',
     116              :     visible: () => hasDefault.value,
     117              :     disabled: () => isCurrentValueDefault.value,
     118              :     command: handleResetToDefault
     119              :   }
     120              : ])
     121          387 : </script>
     122              : 
     123              : <template>
     124          387 :   <Menu :items="menuItems" align="end">
     125              :     <template #trigger>
     126              :       <Button
     127              :         size="icon"
     128              :         variant="muted-textonly"
     129              :         data-testid="widget-actions-menu-button"
     130              :         icon="icon-[lucide--more-vertical]"
     131              :         :aria-label="t('g.more')"
     132              :       />
     133              :     </template>
     134              :   </Menu>
     135              : </template>
        

Generated by: LCOV version 2.0-1