LCOV - code coverage report
Current view: top level - src/types - simplifiedWidget.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 90.0 % 10 9
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : /**
       2              :  * Simplified widget interface for Vue-based node rendering
       3              :  * Removes all DOM manipulation and positioning concerns
       4              :  */
       5              : import type { InputSpec as InputSpecV2 } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
       6              : import type { IBaseWidget, IWidgetOptions } from '@comfyorg/graph-model/widgets'
       7              : import { IS_CONTROL_WIDGET } from '@/core/graph/widgets/controlWidgetMarker'
       8              : import type { NodeId } from '@comfyorg/graph-model/nodeId'
       9              : import type { NodeLocatorId } from '@comfyorg/graph-model/nodeIdentification'
      10              : import type { WidgetValue } from '@comfyorg/graph-model/widgetValue'
      11              : 
      12              : export type { WidgetValue } from '@comfyorg/graph-model/widgetValue'
      13              : 
      14         2356 : export const CONTROL_OPTIONS = [
      15              :   'fixed',
      16              :   'increment',
      17              :   'decrement',
      18              :   'randomize'
      19              : ] as const
      20              : export type ControlOptions = (typeof CONTROL_OPTIONS)[number]
      21              : 
      22         3570 : export function isControlOption(value: unknown): value is ControlOptions {
      23         3570 :   return CONTROL_OPTIONS.some((option) => option === value)
      24              : }
      25              : 
      26         3370 : function normalizeControlOption(val: WidgetValue): ControlOptions {
      27         3370 :   if (isControlOption(val)) return val
      28            0 :   return 'randomize'
      29              : }
      30              : 
      31              : export type SafeControlWidget = {
      32              :   value: ControlOptions
      33              :   update: (value: WidgetValue) => void
      34              : }
      35              : 
      36        47508 : export function getControlWidget(
      37              :   widget: IBaseWidget
      38              : ): SafeControlWidget | undefined {
      39        47508 :   const controlWidget = widget.linkedWidgets?.find((w) => w[IS_CONTROL_WIDGET])
      40        47508 :   if (!controlWidget) return
      41         3368 :   return {
      42              :     value: normalizeControlOption(controlWidget.value),
      43              :     update: (value) => (controlWidget.value = normalizeControlOption(value))
      44              :   }
      45              : }
      46              : 
      47              : export interface LinkedUpstreamInfo {
      48              :   nodeId: NodeId
      49              :   outputName?: string
      50              : }
      51              : 
      52              : export interface SimplifiedWidget<
      53              :   T extends WidgetValue = WidgetValue,
      54              :   O extends IWidgetOptions = IWidgetOptions
      55              : > {
      56              :   /** Display name of the widget */
      57              :   name: string
      58              : 
      59              :   /** Widget type identifier (e.g., 'STRING', 'INT', 'COMBO') */
      60              :   type: string
      61              : 
      62              :   /** Current value of the widget */
      63              :   value: T
      64              : 
      65              :   borderStyle?: string
      66              : 
      67              :   /** Callback fired when value changes */
      68              :   callback?: (value: T) => void
      69              : 
      70              :   /** Optional method to compute widget size requirements */
      71              :   computeSize?: () => { minHeight: number; maxHeight?: number }
      72              : 
      73              :   controlWidget?: SafeControlWidget
      74              : 
      75              :   displayLabel?: string
      76              : 
      77              :   /** Localized display label (falls back to name if not provided) */
      78              :   label?: string
      79              : 
      80              :   linkedUpstream?: LinkedUpstreamInfo
      81              : 
      82              :   /** NodeLocatorId for the node that owns this widget's execution outputs */
      83              :   nodeLocatorId?: NodeLocatorId
      84              : 
      85              :   /** Override for use with subgraph promoted asset widgets*/
      86              :   nodeType?: string
      87              : 
      88              :   options?: O
      89              : 
      90              :   /** Optional serialization method for custom value handling */
      91              :   serializeValue?: () => unknown
      92              : 
      93              :   /** Optional input specification backing this widget */
      94              :   spec?: InputSpecV2
      95              : 
      96              :   tooltip?: string
      97              : }
      98              : 
      99              : export interface SimplifiedControlWidget<
     100              :   T extends WidgetValue = WidgetValue,
     101              :   O extends IWidgetOptions = IWidgetOptions
     102              : > extends SimplifiedWidget<T, O> {
     103              :   controlWidget: SafeControlWidget
     104              : }
        

Generated by: LCOV version 2.0-1