LCOV - code coverage report
Current view: top level - src/components/common - FormItem.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 83.9 % 31 26
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1           16 : <template>
       2         4791 :   <div class="flex min-h-8 items-center gap-2">
       3              :     <div class="flex grow items-center">
       4              :       <span
       5              :         :id="`${props.id}-label`"
       6              :         class="text-sm text-muted-foreground"
       7              :         :class="props.labelClass"
       8              :       >
       9              :         <slot name="name-prefix" />
      10              :         {{ props.item.name }}
      11              :         <Tooltip v-if="props.item.tooltip">
      12              :           <TooltipTrigger as-child>
      13              :             <i class="icon-[lucide--info]" />
      14              :           </TooltipTrigger>
      15              :           <TooltipContent>{{ props.item.tooltip }}</TooltipContent>
      16              :         </Tooltip>
      17              :         <slot name="name-suffix" />
      18              :       </span>
      19              :     </div>
      20              :     <div class="flex justify-end">
      21              :       <component
      22              :         :is="markRaw(getFormComponent(props.item))"
      23              :         :id="props.id"
      24              :         v-model:model-value="formValue"
      25              :         :aria-labelledby="`${props.id}-label`"
      26              :         v-bind="getFormAttrs(props.item)"
      27              :       />
      28              :     </div>
      29              :   </div>
      30              : </template>
      31              : 
      32              : <script setup lang="ts">
      33              : import { markRaw } from 'vue'
      34              : import type { Component } from 'vue'
      35              : 
      36              : import BackgroundImageUpload from '@/components/common/BackgroundImageUpload.vue'
      37              : import CustomFormValue from '@comfyorg/design-system/common/CustomFormValue'
      38              : import FormColorPicker from '@/components/common/FormColorPicker.vue'
      39              : import FormImageUpload from '@/components/common/FormImageUpload.vue'
      40              : import FormNumberField from '@/components/common/FormNumberField.vue'
      41              : import FormRadioGroup from '@/components/common/FormRadioGroup.vue'
      42              : import InputKnob from '@/components/common/InputKnob.vue'
      43              : import InputSlider from '@/components/common/InputSlider.vue'
      44              : import UrlInput from '@/components/common/UrlInput.vue'
      45              : import Input from '@comfyorg/design-system/input/Input'
      46              : import AppSingleSelect from '@/components/common/AppSingleSelect.vue'
      47              : import Switch from '@comfyorg/design-system/switch/Switch'
      48              : import Tooltip from '@comfyorg/design-system/tooltip/Tooltip'
      49              : import TooltipContent from '@comfyorg/design-system/tooltip/TooltipContent'
      50              : import TooltipTrigger from '@comfyorg/design-system/tooltip/TooltipTrigger'
      51              : import type { FormItem } from '@comfyorg/settings-core/types'
      52              : 
      53         4724 : const formValue = defineModel<unknown>('formValue')
      54         4724 : const props = defineProps<{
      55              :   item: FormItem
      56              :   id?: string
      57              :   labelClass?: string | Record<string, boolean>
      58              : }>()
      59              : 
      60         4791 : function getFormAttrs(item: FormItem) {
      61         4791 :   const attrs = { ...item.attrs }
      62         4791 :   const inputType = item.type
      63         4791 :   if (typeof inputType === 'function') {
      64            0 :     attrs['renderFunction'] = () =>
      65              :       inputType(
      66              :         props.item.name,
      67              :         (v: unknown) => (formValue.value = v),
      68              :         formValue.value,
      69              :         item.attrs
      70              :       )
      71              :   }
      72         4791 :   switch (item.type) {
      73              :     case 'combo':
      74              :     case 'radio': {
      75          908 :       const options =
      76              :         typeof item.options === 'function'
      77              :           ? item.options(formValue.value)
      78              :           : item.options
      79          908 :       attrs['options'] =
      80              :         item.type === 'combo'
      81              :           ? options?.map((option) =>
      82              :               typeof option === 'string'
      83              :                 ? { name: option, value: option }
      84              :                 : { name: option.text, value: option.value ?? option.text }
      85              :             )
      86              :           : options
      87          908 :       attrs['class'] = 'w-44'
      88          908 :       break
      89              :     }
      90              :     case 'text':
      91            9 :       attrs['class'] = 'w-44'
      92              :       break
      93              :   }
      94         4791 :   return attrs
      95              : }
      96              : 
      97         4791 : function getFormComponent(item: FormItem): Component {
      98         4791 :   if (typeof item.type === 'function') {
      99            0 :     return CustomFormValue
     100              :   }
     101         4791 :   switch (item.type) {
     102              :     case 'boolean':
     103         3279 :       return Switch
     104              :     case 'number':
     105          217 :       return FormNumberField
     106              :     case 'slider':
     107          362 :       return InputSlider
     108              :     case 'knob':
     109            0 :       return InputKnob
     110              :     case 'combo':
     111          904 :       return AppSingleSelect
     112              :     case 'radio':
     113            4 :       return FormRadioGroup
     114              :     case 'image':
     115            0 :       return FormImageUpload
     116              :     case 'color':
     117            1 :       return FormColorPicker
     118              :     case 'url':
     119            0 :       return UrlInput
     120              :     case 'backgroundImage':
     121           15 :       return BackgroundImageUpload
     122              :     default:
     123            9 :       return Input
     124              :   }
     125              : }
     126              : </script>
        

Generated by: LCOV version 2.0-1