Compare commits

...

9 Commits

Author SHA1 Message Date
bymyself
e488b2abce standardize size and color 2025-06-09 04:58:17 -07:00
Christian Byrne
20e4427602 Add Vue Image Preview widget (#4116) 2025-06-09 03:52:17 -07:00
Christian Byrne
33e99da325 Add Vue File/Media Upload Widget (#4115) 2025-06-09 01:48:03 -07:00
github-actions
a7461c49c7 Update locales [skip ci] 2025-06-09 08:39:01 +00:00
Christian Byrne
102590c2c2 Add Vue Color Picker widget (#4114) 2025-06-09 01:35:06 -07:00
Christian Byrne
928dfc6b8e Add Vue Combo (dropdown) widget (#4113) 2025-06-09 00:51:08 -07:00
Christian Byrne
593ac576da Add Vue String widget and multiline textarea widgets (#4112) 2025-06-09 00:44:48 -07:00
bymyself
0858356dcf alias old float/int widgets 2025-06-09 00:24:23 -07:00
bymyself
471018a962 [feat] Add BadgedNumberInput Vue widget with state indicators
- Create BadgedNumberInput.vue component using PrimeVue InputNumber
- Add badges for random, lock, increment, decrement states
- Implement useBadgedNumberInput composable with proper DOM widget integration
- Register BADGED_NUMBER widget type in widgets registry
- Include comprehensive unit tests for widget functionality
- Widget spans node width with padding and rounded corners as specified
2025-06-08 23:21:44 -07:00
49 changed files with 7154 additions and 417 deletions

View File

@@ -0,0 +1,53 @@
# Create a Vue Widget for ComfyUI
Your task is to create a new Vue widget for ComfyUI based on the widget specification: $ARGUMENTS
## Instructions
Follow the comprehensive guide in `vue-widget-conversion/vue-widget-guide.md` to create the widget. This guide contains step-by-step instructions, examples from actual PRs, and best practices.
### Key Steps to Follow:
1. **Understand the Widget Type**
- Analyze what type of widget is needed: $ARGUMENTS
- Identify the data type (string, number, array, object, etc.)
- Determine if it needs special behaviors (execution state awareness, dynamic management, etc.)
2. **Component Creation**
- Create Vue component in `src/components/graph/widgets/`
- REQUIRED: Use PrimeVue components (reference `vue-widget-conversion/primevue-components.md`)
- Use Composition API with `<script setup>`
- Implement proper v-model binding with `defineModel`
3. **Composable Pattern**
- Always create widget constructor composable in `src/composables/widgets/`
- Only create node-level composable in `src/composables/node/` if the widget needs dynamic management
- Follow the dual composable pattern explained in the guide
4. **Registration**
- Register in `src/scripts/widgets.ts`
- Use appropriate widget type name
5. **Testing**
- Create unit tests for composables
- Test with actual nodes that use the widget
### Important Requirements:
- **Always use PrimeVue components** - Check `vue-widget-conversion/primevue-components.md` for available components
- Use TypeScript with proper types
- Follow Vue 3 Composition API patterns
- Use Tailwind CSS for styling (no custom CSS unless absolutely necessary)
- Implement proper error handling and validation
- Consider performance (use v-show vs v-if appropriately)
### Before Starting:
1. First read through the entire guide at `vue-widget-conversion/vue-widget-guide.md`
2. Check existing widget implementations for similar patterns
3. Identify which PrimeVue component(s) best fit the widget requirements
### Widget Specification to Implement:
$ARGUMENTS
Begin by analyzing the widget requirements and proposing an implementation plan based on the guide.

89
copy-widget-resources.sh Executable file
View File

@@ -0,0 +1,89 @@
#!/bin/bash
# Script to copy vue-widget-conversion folder and .claude/commands/create-widget.md
# to another local copy of the same repository
# Check if destination directory was provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <destination-repo-path>"
echo "Example: $0 /home/c_byrne/projects/comfyui-frontend-testing/ComfyUI_frontend-clone-8"
exit 1
fi
# Get the destination directory from first argument
DEST_DIR="$1"
# Source files/directories (relative to script location)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_WIDGET_DIR="$SCRIPT_DIR/vue-widget-conversion"
SOURCE_COMMAND_FILE="$SCRIPT_DIR/.claude/commands/create-widget.md"
# Destination paths
DEST_WIDGET_DIR="$DEST_DIR/vue-widget-conversion"
DEST_COMMAND_DIR="$DEST_DIR/.claude/commands"
DEST_COMMAND_FILE="$DEST_COMMAND_DIR/create-widget.md"
# Check if destination directory exists
if [ ! -d "$DEST_DIR" ]; then
echo "Error: Destination directory does not exist: $DEST_DIR"
exit 1
fi
# Check if source vue-widget-conversion directory exists
if [ ! -d "$SOURCE_WIDGET_DIR" ]; then
echo "Error: Source vue-widget-conversion directory not found: $SOURCE_WIDGET_DIR"
exit 1
fi
# Check if source command file exists
if [ ! -f "$SOURCE_COMMAND_FILE" ]; then
echo "Error: Source command file not found: $SOURCE_COMMAND_FILE"
exit 1
fi
echo "Copying widget resources to: $DEST_DIR"
# Copy vue-widget-conversion directory
echo "Copying vue-widget-conversion directory..."
if [ -d "$DEST_WIDGET_DIR" ]; then
echo " Warning: Destination vue-widget-conversion already exists. Overwriting..."
rm -rf "$DEST_WIDGET_DIR"
fi
cp -r "$SOURCE_WIDGET_DIR" "$DEST_WIDGET_DIR"
echo " ✓ Copied vue-widget-conversion directory"
# Create .claude/commands directory if it doesn't exist
echo "Creating .claude/commands directory structure..."
mkdir -p "$DEST_COMMAND_DIR"
echo " ✓ Created .claude/commands directory"
# Copy create-widget.md command
echo "Copying create-widget.md command..."
cp "$SOURCE_COMMAND_FILE" "$DEST_COMMAND_FILE"
echo " ✓ Copied create-widget.md command"
# Verify the copy was successful
echo ""
echo "Verification:"
if [ -d "$DEST_WIDGET_DIR" ] && [ -f "$DEST_WIDGET_DIR/vue-widget-guide.md" ] && [ -f "$DEST_WIDGET_DIR/primevue-components.md" ]; then
echo " ✓ vue-widget-conversion directory copied successfully"
echo " - vue-widget-guide.md exists"
echo " - primevue-components.md exists"
if [ -f "$DEST_WIDGET_DIR/primevue-components.json" ]; then
echo " - primevue-components.json exists"
fi
else
echo " ✗ Error: vue-widget-conversion directory copy may have failed"
fi
if [ -f "$DEST_COMMAND_FILE" ]; then
echo " ✓ create-widget.md command copied successfully"
else
echo " ✗ Error: create-widget.md command copy may have failed"
fi
echo ""
echo "Copy complete! Widget resources are now available in: $DEST_DIR"
echo ""
echo "You can now use the widget creation command in the destination repo:"
echo " /project:create-widget <widget specification>"

View File

@@ -0,0 +1,204 @@
<template>
<div class="badged-number-input relative w-full">
<InputGroup class="w-full rounded-lg border-none px-0.5">
<!-- State badge prefix -->
<InputGroupAddon
v-if="badgeState !== 'normal'"
class="rounded-l-lg bg-[#222222] border-[#222222] shadow-none border-r-[#A0A1A2] rounded-r-none"
>
<i
:class="badgeIcon + ' text-xs'"
:title="badgeTooltip"
:style="{ color: badgeColor }"
></i>
</InputGroupAddon>
<!-- Number input for non-slider mode -->
<InputNumber
v-if="!isSliderMode"
v-model="numericValue"
:min="min"
:max="max"
:step="step"
:placeholder="placeholder"
:disabled="disabled"
size="small"
:pt="{
pcInputText: {
root: {
class: 'bg-[#222222] text-xs shadow-none rounded-none !border-0'
}
},
incrementButton: {
class: 'text-xs shadow-none bg-[#222222] rounded-l-none !border-0'
},
decrementButton: {
class: {
'text-xs shadow-none bg-[#222222] rounded-r-none !border-0':
badgeState === 'normal',
'text-xs shadow-none bg-[#222222] rounded-none !border-0':
badgeState !== 'normal'
}
}
}"
class="flex-1 rounded-none"
show-buttons
button-layout="horizontal"
:increment-button-icon="'pi pi-plus'"
:decrement-button-icon="'pi pi-minus'"
/>
<!-- Slider mode -->
<div
v-else
:class="{
'rounded-r-lg': badgeState !== 'normal',
'rounded-lg': badgeState === 'normal'
}"
class="flex-1 flex items-center gap-2 px-1 bg-surface-0 border border-surface-300"
>
<Slider
v-model="numericValue"
:min="min"
:max="max"
:step="step"
:disabled="disabled"
class="flex-1"
/>
<InputNumber
v-model="numericValue"
:min="min"
:max="max"
:step="step"
:disabled="disabled"
class="w-16 rounded-md"
:pt="{
pcInputText: {
root: {
class: 'bg-[#222222] text-xs shadow-none border-[#222222]'
}
}
}"
:show-buttons="false"
size="small"
/>
</div>
</InputGroup>
</div>
</template>
<script setup lang="ts">
import InputGroup from 'primevue/inputgroup'
import InputGroupAddon from 'primevue/inputgroupaddon'
import InputNumber from 'primevue/inputnumber'
import Slider from 'primevue/slider'
import { computed } from 'vue'
import type { ComponentWidget } from '@/scripts/domWidget'
type BadgeState = 'normal' | 'random' | 'lock' | 'increment' | 'decrement'
const modelValue = defineModel<string>({ required: true })
const {
widget,
badgeState = 'normal',
disabled = false
} = defineProps<{
widget: ComponentWidget<string>
badgeState?: BadgeState
disabled?: boolean
}>()
// Convert string model value to/from number for the InputNumber component
const numericValue = computed({
get: () => parseFloat(modelValue.value) || 0,
set: (value: number) => {
modelValue.value = value.toString()
}
})
// Extract options from input spec
const inputSpec = widget.inputSpec
const min = (inputSpec as any).min ?? 0
const max = (inputSpec as any).max ?? 100
const step = (inputSpec as any).step ?? 1
const placeholder = (inputSpec as any).placeholder ?? 'Enter number'
// Check if slider mode should be enabled
const isSliderMode = computed(() => {
console.log('inputSpec', inputSpec)
return (inputSpec as any).slider === true
})
// Badge configuration
const badgeIcon = computed(() => {
switch (badgeState) {
case 'random':
return 'pi pi-refresh'
case 'lock':
return 'pi pi-lock'
case 'increment':
return 'pi pi-arrow-up'
case 'decrement':
return 'pi pi-arrow-down'
default:
return ''
}
})
const badgeColor = computed(() => {
switch (badgeState) {
case 'random':
return 'var(--p-primary-color)'
case 'lock':
return 'var(--p-orange-500)'
case 'increment':
return 'var(--p-green-500)'
case 'decrement':
return 'var(--p-red-500)'
default:
return 'var(--p-text-color)'
}
})
const badgeTooltip = computed(() => {
switch (badgeState) {
case 'random':
return 'Random mode: Value randomizes after each run'
case 'lock':
return 'Locked: Value never changes'
case 'increment':
return 'Auto-increment: Value increases after each run'
case 'decrement':
return 'Auto-decrement: Value decreases after each run'
default:
return ''
}
})
</script>
<style scoped>
.badged-number-input {
padding: 4px;
}
/* Ensure proper styling for the input group */
:deep(.p-inputgroup) {
border-radius: 0.5rem;
}
:deep(.p-inputnumber) {
flex: 1;
}
:deep(.p-inputnumber-input) {
border-radius: inherit;
}
/* Badge styling */
:deep(.p-badge) {
font-size: 0.75rem;
padding: 0.25rem 0.5rem;
}
</style>

View File

@@ -0,0 +1,545 @@
<template>
<div class="color-picker-widget">
<div
:style="{ width: widgetWidth }"
class="flex items-center gap-2 p-2 rounded-lg border border-surface-300 bg-surface-0 w-full"
>
<!-- Color picker preview and popup trigger -->
<div class="relative">
<div
:style="{ backgroundColor: parsedColor.hex }"
class="w-4 h-4 rounded border-2 border-surface-400 cursor-pointer hover:border-surface-500 transition-colors"
title="Click to edit color"
@click="toggleColorPicker"
/>
<!-- Color picker popover -->
<Popover ref="colorPickerPopover" class="!p-0">
<ColorPicker
v-model="colorValue"
format="hex"
class="border-none"
@update:model-value="updateColorFromPicker"
/>
</Popover>
</div>
<!-- Color component inputs -->
<div class="flex gap-5">
<InputNumber
v-for="component in colorComponents"
:key="component.name"
v-model="component.value"
:min="component.min"
:max="component.max"
:step="component.step"
:placeholder="component.name"
class="flex-1 text-xs max-w-8"
:pt="{
pcInputText: {
root: {
class:
'max-w-12 bg-[#222222] text-xs shadow-none border-[#222222]'
}
}
}"
:show-buttons="false"
size="small"
@update:model-value="updateColorFromComponents"
/>
</div>
<!-- Format dropdown -->
<Select
v-model="currentFormat"
:options="colorFormats"
option-label="label"
option-value="value"
class="w-24 ml-3 bg-[#222222] text-xs shadow-none border-none p-0"
size="small"
@update:model-value="handleFormatChange"
/>
</div>
</div>
</template>
<script setup lang="ts">
import ColorPicker from 'primevue/colorpicker'
import InputNumber from 'primevue/inputnumber'
import Popover from 'primevue/popover'
import Select from 'primevue/select'
import { computed, ref, watch } from 'vue'
import type { ComponentWidget } from '@/scripts/domWidget'
interface ColorComponent {
name: string
value: number
min: number
max: number
step: number
}
interface ParsedColor {
hex: string
rgb: { r: number; g: number; b: number; a: number }
hsl: { h: number; s: number; l: number; a: number }
hsv: { h: number; s: number; v: number; a: number }
}
type ColorFormat = 'rgba' | 'hsla' | 'hsva' | 'hex'
const modelValue = defineModel<string>({ required: true })
const { widget } = defineProps<{
widget: ComponentWidget<string>
}>()
// Color format options
const colorFormats = [
{ label: 'RGBA', value: 'rgba' },
{ label: 'HSLA', value: 'hsla' },
{ label: 'HSVA', value: 'hsva' },
{ label: 'HEX', value: 'hex' }
]
// Current format state
const currentFormat = ref<ColorFormat>('rgba')
// Color picker popover reference
const colorPickerPopover = ref()
// Internal color value for the PrimeVue ColorPicker
const colorValue = ref<string>('#ff0000')
// Calculate widget width based on node size with padding
const widgetWidth = computed(() => {
if (!widget?.node?.size) return 'auto'
const nodeWidth = widget.node.size[0]
const WIDGET_PADDING = 16 // Account for padding around the widget
const maxWidth = Math.max(200, nodeWidth - WIDGET_PADDING) // Minimum 200px, but scale with node
return `${maxWidth}px`
})
// Parse color string to various formats
const parsedColor = computed<ParsedColor>(() => {
const value = modelValue.value || '#ff0000'
// Handle different input formats
if (value.startsWith('#')) {
return parseHexColor(value)
} else if (value.startsWith('rgb')) {
return parseRgbaColor(value)
} else if (value.startsWith('hsl')) {
return parseHslaColor(value)
} else if (value.startsWith('hsv')) {
return parseHsvaColor(value)
}
return parseHexColor('#ff0000') // Default fallback
})
// Get color components based on current format
const colorComponents = computed<ColorComponent[]>(() => {
const { rgb, hsl, hsv } = parsedColor.value
switch (currentFormat.value) {
case 'rgba':
return [
{ name: 'R', value: rgb.r, min: 0, max: 255, step: 1 },
{ name: 'G', value: rgb.g, min: 0, max: 255, step: 1 },
{ name: 'B', value: rgb.b, min: 0, max: 255, step: 1 },
{ name: 'A', value: rgb.a, min: 0, max: 1, step: 0.01 }
]
case 'hsla':
return [
{ name: 'H', value: hsl.h, min: 0, max: 360, step: 1 },
{ name: 'S', value: hsl.s, min: 0, max: 100, step: 1 },
{ name: 'L', value: hsl.l, min: 0, max: 100, step: 1 },
{ name: 'A', value: hsl.a, min: 0, max: 1, step: 0.01 }
]
case 'hsva':
return [
{ name: 'H', value: hsv.h, min: 0, max: 360, step: 1 },
{ name: 'S', value: hsv.s, min: 0, max: 100, step: 1 },
{ name: 'V', value: hsv.v, min: 0, max: 100, step: 1 },
{ name: 'A', value: hsv.a, min: 0, max: 1, step: 0.01 }
]
case 'hex':
return [] // No components for hex format
default:
return []
}
})
// Watch for changes in modelValue to update colorValue
watch(
() => modelValue.value,
(newValue) => {
if (newValue && newValue !== colorValue.value) {
colorValue.value = parsedColor.value.hex
}
},
{ immediate: true }
)
// Toggle color picker popover
function toggleColorPicker(event: Event) {
colorPickerPopover.value.toggle(event)
}
// Update color from picker
function updateColorFromPicker(value: string) {
colorValue.value = value
updateModelValue(parseHexColor(value))
}
// Update color from component inputs
function updateColorFromComponents() {
const components = colorComponents.value
if (components.length === 0) return
let newColor: ParsedColor
const rgbFromHsl = hslToRgb(
components[0].value,
components[1].value,
components[2].value,
components[3].value
)
const rgbFromHsv = hsvToRgb(
components[0].value,
components[1].value,
components[2].value,
components[3].value
)
switch (currentFormat.value) {
case 'rgba':
newColor = {
hex: rgbToHex(
components[0].value,
components[1].value,
components[2].value
),
rgb: {
r: components[0].value,
g: components[1].value,
b: components[2].value,
a: components[3].value
},
hsl: rgbToHsl(
components[0].value,
components[1].value,
components[2].value,
components[3].value
),
hsv: rgbToHsv(
components[0].value,
components[1].value,
components[2].value,
components[3].value
)
}
break
case 'hsla':
newColor = {
hex: rgbToHex(rgbFromHsl.r, rgbFromHsl.g, rgbFromHsl.b),
rgb: rgbFromHsl,
hsl: {
h: components[0].value,
s: components[1].value,
l: components[2].value,
a: components[3].value
},
hsv: rgbToHsv(rgbFromHsl.r, rgbFromHsl.g, rgbFromHsl.b, rgbFromHsl.a)
}
break
case 'hsva':
newColor = {
hex: rgbToHex(rgbFromHsv.r, rgbFromHsv.g, rgbFromHsv.b),
rgb: rgbFromHsv,
hsl: rgbToHsl(rgbFromHsv.r, rgbFromHsv.g, rgbFromHsv.b, rgbFromHsv.a),
hsv: {
h: components[0].value,
s: components[1].value,
v: components[2].value,
a: components[3].value
}
}
break
default:
return
}
updateModelValue(newColor)
}
// Handle format change
function handleFormatChange() {
updateModelValue(parsedColor.value)
}
// Update the model value based on current format
function updateModelValue(color: ParsedColor) {
switch (currentFormat.value) {
case 'rgba':
modelValue.value = `rgba(${color.rgb.r}, ${color.rgb.g}, ${color.rgb.b}, ${color.rgb.a})`
break
case 'hsla':
modelValue.value = `hsla(${color.hsl.h}, ${color.hsl.s}%, ${color.hsl.l}%, ${color.hsl.a})`
break
case 'hsva':
modelValue.value = `hsva(${color.hsv.h}, ${color.hsv.s}%, ${color.hsv.v}%, ${color.hsv.a})`
break
case 'hex':
modelValue.value = color.hex
break
}
colorValue.value = color.hex
}
// Color parsing functions
function parseHexColor(hex: string): ParsedColor {
const r = parseInt(hex.slice(1, 3), 16)
const g = parseInt(hex.slice(3, 5), 16)
const b = parseInt(hex.slice(5, 7), 16)
const a = hex.length === 9 ? parseInt(hex.slice(7, 9), 16) / 255 : 1
return {
hex,
rgb: { r, g, b, a },
hsl: rgbToHsl(r, g, b, a),
hsv: rgbToHsv(r, g, b, a)
}
}
function parseRgbaColor(rgba: string): ParsedColor {
const match = rgba.match(/rgba?\(([^)]+)\)/)
if (!match) return parseHexColor('#ff0000')
const [r, g, b, a = 1] = match[1].split(',').map((v) => parseFloat(v.trim()))
return {
hex: rgbToHex(r, g, b),
rgb: { r, g, b, a },
hsl: rgbToHsl(r, g, b, a),
hsv: rgbToHsv(r, g, b, a)
}
}
function parseHslaColor(hsla: string): ParsedColor {
const match = hsla.match(/hsla?\(([^)]+)\)/)
if (!match) return parseHexColor('#ff0000')
const [h, s, l, a = 1] = match[1]
.split(',')
.map((v) => parseFloat(v.trim().replace('%', '')))
const rgb = hslToRgb(h, s, l, a)
return {
hex: rgbToHex(rgb.r, rgb.g, rgb.b),
rgb,
hsl: { h, s, l, a },
hsv: rgbToHsv(rgb.r, rgb.g, rgb.b, rgb.a)
}
}
function parseHsvaColor(hsva: string): ParsedColor {
const match = hsva.match(/hsva?\(([^)]+)\)/)
if (!match) return parseHexColor('#ff0000')
const [h, s, v, a = 1] = match[1]
.split(',')
.map((val) => parseFloat(val.trim().replace('%', '')))
const rgb = hsvToRgb(h, s, v, a)
return {
hex: rgbToHex(rgb.r, rgb.g, rgb.b),
rgb,
hsl: rgbToHsl(rgb.r, rgb.g, rgb.b, rgb.a),
hsv: { h, s, v, a }
}
}
// Color conversion utility functions
function rgbToHex(r: number, g: number, b: number): string {
return (
'#' +
[r, g, b].map((x) => Math.round(x).toString(16).padStart(2, '0')).join('')
)
}
function rgbToHsl(r: number, g: number, b: number, a: number) {
r /= 255
g /= 255
b /= 255
const max = Math.max(r, g, b)
const min = Math.min(r, g, b)
let h: number, s: number
const l = (max + min) / 2
if (max === min) {
h = s = 0
} else {
const d = max - min
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0)
break
case g:
h = (b - r) / d + 2
break
case b:
h = (r - g) / d + 4
break
default:
h = 0
}
h /= 6
}
return {
h: Math.round(h * 360),
s: Math.round(s * 100),
l: Math.round(l * 100),
a
}
}
function rgbToHsv(r: number, g: number, b: number, a: number) {
r /= 255
g /= 255
b /= 255
const max = Math.max(r, g, b)
const min = Math.min(r, g, b)
let h: number
const v = max
const s = max === 0 ? 0 : (max - min) / max
if (max === min) {
h = 0
} else {
const d = max - min
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0)
break
case g:
h = (b - r) / d + 2
break
case b:
h = (r - g) / d + 4
break
default:
h = 0
}
h /= 6
}
return {
h: Math.round(h * 360),
s: Math.round(s * 100),
v: Math.round(v * 100),
a
}
}
function hslToRgb(h: number, s: number, l: number, a: number) {
h /= 360
s /= 100
l /= 100
const hue2rgb = (p: number, q: number, t: number) => {
if (t < 0) t += 1
if (t > 1) t -= 1
if (t < 1 / 6) return p + (q - p) * 6 * t
if (t < 1 / 2) return q
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
return p
}
let r: number, g: number, b: number
if (s === 0) {
r = g = b = l
} else {
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
const p = 2 * l - q
r = hue2rgb(p, q, h + 1 / 3)
g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h - 1 / 3)
}
return {
r: Math.round(r * 255),
g: Math.round(g * 255),
b: Math.round(b * 255),
a
}
}
function hsvToRgb(h: number, s: number, v: number, a: number) {
h /= 360
s /= 100
v /= 100
const c = v * s
const x = c * (1 - Math.abs(((h * 6) % 2) - 1))
const m = v - c
let r: number, g: number, b: number
if (h < 1 / 6) {
;[r, g, b] = [c, x, 0]
} else if (h < 2 / 6) {
;[r, g, b] = [x, c, 0]
} else if (h < 3 / 6) {
;[r, g, b] = [0, c, x]
} else if (h < 4 / 6) {
;[r, g, b] = [0, x, c]
} else if (h < 5 / 6) {
;[r, g, b] = [x, 0, c]
} else {
;[r, g, b] = [c, 0, x]
}
return {
r: Math.round((r + m) * 255),
g: Math.round((g + m) * 255),
b: Math.round((b + m) * 255),
a
}
}
</script>
<style scoped>
.color-picker-widget {
min-height: 40px;
overflow: hidden; /* Prevent overflow outside node bounds */
}
/* Ensure proper styling for small inputs */
:deep(.p-inputnumber-input) {
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
}
:deep(.p-select) {
font-size: 0.75rem;
}
:deep(.p-select .p-select-label) {
padding: 0.25rem 0.5rem;
}
:deep(.p-colorpicker) {
border: none;
}
</style>

View File

@@ -0,0 +1,40 @@
<template>
<div class="px-2">
<Select
v-model="selectedValue"
:options="computedOptions"
:placeholder="placeholder"
class="w-full rounded-lg bg-[#222222] text-xs border-[#222222] shadow-none"
:disabled="isLoading"
/>
</div>
</template>
<script setup lang="ts">
import Select from 'primevue/select'
import { computed } from 'vue'
import type { ComboInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComponentWidget } from '@/scripts/domWidget'
const selectedValue = defineModel<string>()
const { widget } = defineProps<{
widget?: ComponentWidget<string>
}>()
const inputSpec = (widget?.inputSpec ?? {}) as ComboInputSpec
const placeholder = 'Select option'
const isLoading = computed(() => selectedValue.value === 'Loading...')
// For remote widgets, we need to dynamically get options
const computedOptions = computed(() => {
if (inputSpec.remote) {
// For remote widgets, the options may be dynamically updated
// The useRemoteWidget will update the inputSpec.options
return inputSpec.options ?? []
}
return inputSpec.options ?? []
})
// Tooltip support is available via inputSpec.tooltip if needed in the future
</script>

View File

@@ -0,0 +1,210 @@
<template>
<div class="image-preview-widget relative w-full">
<!-- Single image or grid view -->
<div
v-if="images.length > 0"
class="relative rounded-lg overflow-hidden bg-gray-100 dark-theme:bg-gray-800"
:style="{ minHeight: `${minHeight}px` }"
>
<!-- Single image view -->
<div
v-if="selectedImageIndex !== null && images[selectedImageIndex]"
class="relative flex items-center justify-center w-full h-full"
>
<img
:src="images[selectedImageIndex].src"
:alt="`Preview ${selectedImageIndex + 1}`"
class="max-w-full max-h-full object-contain"
@error="handleImageError"
/>
<!-- Action buttons overlay -->
<div class="absolute top-2 right-2 flex gap-1">
<Button
v-if="images.length > 1"
icon="pi pi-times"
size="small"
severity="secondary"
class="w-8 h-8 rounded-lg bg-black/60 text-white border-none hover:bg-black/80"
@click="showGrid"
/>
<Button
icon="pi pi-pencil"
size="small"
severity="secondary"
class="w-8 h-8 rounded-lg bg-black/60 text-white border-none hover:bg-black/80"
@click="handleEdit"
/>
<Button
icon="pi pi-sun"
size="small"
severity="secondary"
class="w-8 h-8 rounded-lg bg-black/60 text-white border-none hover:bg-black/80"
@click="handleBrightness"
/>
<Button
icon="pi pi-download"
size="small"
severity="secondary"
class="w-8 h-8 rounded-lg bg-black/60 text-white border-none hover:bg-black/80"
@click="handleSave"
/>
</div>
<!-- Navigation for multiple images -->
<div
v-if="images.length > 1"
class="absolute bottom-2 right-2 bg-black/60 text-white px-2 py-1 rounded text-sm cursor-pointer hover:bg-black/80"
@click="nextImage"
>
{{ selectedImageIndex + 1 }}/{{ images.length }}
</div>
</div>
<!-- Grid view for multiple images -->
<div
v-else-if="allowBatch && images.length > 1"
class="grid gap-1 p-2"
:style="gridStyle"
>
<div
v-for="(image, index) in images"
:key="index"
class="relative aspect-square bg-gray-200 dark-theme:bg-gray-700 rounded cursor-pointer overflow-hidden hover:ring-2 hover:ring-blue-500"
@click="selectImage(index)"
>
<img
:src="image.src"
:alt="`Thumbnail ${index + 1}`"
class="w-full h-full object-cover"
@error="handleImageError"
/>
</div>
</div>
<!-- Single image in grid mode -->
<div v-else-if="images.length === 1" class="p-2">
<div
class="relative bg-gray-200 dark-theme:bg-gray-700 rounded cursor-pointer overflow-hidden"
@click="selectImage(0)"
>
<img
:src="images[0].src"
:alt="'Preview'"
class="w-full h-auto object-contain"
@error="handleImageError"
/>
</div>
</div>
</div>
<!-- Empty state -->
<div
v-else
class="flex items-center justify-center w-full bg-gray-100 dark-theme:bg-gray-800 rounded-lg"
:style="{ minHeight: `${minHeight}px` }"
>
<div class="text-gray-500 text-sm">No images to preview</div>
</div>
</div>
</template>
<script setup lang="ts">
import Button from 'primevue/button'
import { computed, ref } from 'vue'
import type { ComponentWidget } from '@/scripts/domWidget'
interface ImageData {
src: string
width?: number
height?: number
}
const modelValue = defineModel<string | string[]>({ required: true })
const { widget } = defineProps<{
widget: ComponentWidget<string | string[]>
}>()
// Widget configuration
const inputSpec = widget.inputSpec
const allowBatch = computed(() => Boolean(inputSpec.allow_batch))
const imageFolder = computed(() => inputSpec.image_folder || 'input')
// State
const selectedImageIndex = ref<number | null>(null)
const minHeight = 320
// Convert model value to image data
const images = computed<ImageData[]>(() => {
const value = modelValue.value
if (!value) return []
const paths = Array.isArray(value) ? value : [value]
return paths.map((path) => ({
src: path.startsWith('http')
? path
: `api/view?filename=${encodeURIComponent(path)}&type=${imageFolder.value}`, // TODO: add subfolder
width: undefined,
height: undefined
}))
})
// Grid layout for batch images
const gridStyle = computed(() => {
const count = images.value.length
if (count <= 1) return {}
const cols = Math.ceil(Math.sqrt(count))
return {
gridTemplateColumns: `repeat(${cols}, 1fr)`
}
})
// Methods
const selectImage = (index: number) => {
selectedImageIndex.value = index
}
const showGrid = () => {
selectedImageIndex.value = null
}
const nextImage = () => {
if (images.value.length === 0) return
const current = selectedImageIndex.value ?? -1
const next = (current + 1) % images.value.length
selectedImageIndex.value = next
}
const handleImageError = (event: Event) => {
const img = event.target as HTMLImageElement
img.style.display = 'none'
console.warn('Failed to load image:', img.src)
}
// Stub button handlers for now
const handleEdit = () => {
console.log('Edit button clicked - functionality to be implemented')
}
const handleBrightness = () => {
console.log('Brightness button clicked - functionality to be implemented')
}
const handleSave = () => {
console.log('Save button clicked - functionality to be implemented')
}
// Initialize to show first image if available
if (images.value.length === 1) {
selectedImageIndex.value = 0
}
</script>
<style scoped>
.image-preview-widget {
/* Ensure proper dark theme styling */
}
</style>

View File

@@ -0,0 +1,150 @@
<template>
<div class="media-loader-widget w-full px-2 max-h-44">
<div
class="upload-area border-2 border-dashed border-surface-300 dark-theme:border-surface-600 rounded-lg p-6 text-center bg-surface-50 dark-theme:bg-surface-800 hover:bg-surface-100 dark-theme:hover:bg-surface-700 transition-colors cursor-pointer"
:class="{
'border-primary-500 bg-primary-50 dark-theme:bg-primary-950': isDragOver
}"
@click="triggerFileUpload"
@dragover.prevent="onDragOver"
@dragleave.prevent="onDragLeave"
@drop.prevent="onDrop"
>
<div class="flex flex-col items-center gap-2">
<i
class="pi pi-cloud-upload text-2xl text-surface-500 dark-theme:text-surface-400"
></i>
<div class="text-sm text-surface-600 dark-theme:text-surface-300">
<span>Drop your file here or </span>
<span
class="text-primary-600 dark-theme:text-primary-400 hover:text-primary-700 dark-theme:hover:text-primary-300 underline cursor-pointer"
@click.stop="triggerFileUpload"
>
browse files
</span>
</div>
<div
v-if="accept"
class="text-xs text-surface-500 dark-theme:text-surface-400"
>
Accepted formats: {{ formatAcceptTypes }}
</div>
</div>
</div>
<!-- Hidden file input -->
<input
ref="fileInput"
type="file"
:accept="accept"
multiple
class="hidden"
@change="onFileSelect"
/>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import type { ComponentWidget } from '@/scripts/domWidget'
// Props and model
const modelValue = defineModel<string[]>({ required: true, default: () => [] })
const { widget, accept } = defineProps<{
widget: ComponentWidget<string[]>
accept?: string
}>()
// Reactive state
const fileInput = ref<HTMLInputElement>()
const isDragOver = ref(false)
// Computed properties
const formatAcceptTypes = computed(() => {
if (!accept) return ''
return accept
.split(',')
.map((type) =>
type
.trim()
.replace('image/', '')
.replace('video/', '')
.replace('audio/', '')
)
.join(', ')
})
// Methods
const triggerFileUpload = () => {
fileInput.value?.click()
}
const onFileSelect = (event: Event) => {
const target = event.target as HTMLInputElement
if (target.files) {
handleFiles(Array.from(target.files))
}
}
const onDragOver = (event: DragEvent) => {
event.preventDefault()
isDragOver.value = true
}
const onDragLeave = (event: DragEvent) => {
event.preventDefault()
isDragOver.value = false
}
const onDrop = (event: DragEvent) => {
event.preventDefault()
isDragOver.value = false
if (event.dataTransfer?.files) {
handleFiles(Array.from(event.dataTransfer.files))
}
}
const handleFiles = (files: File[]) => {
// Filter files based on accept prop if provided
let validFiles = files
if (accept) {
const acceptTypes = accept
.split(',')
.map((type) => type.trim().toLowerCase())
validFiles = files.filter((file) => {
return acceptTypes.some((acceptType) => {
if (acceptType.includes('*')) {
// Handle wildcard types like "image/*"
const baseType = acceptType.split('/')[0]
return file.type.startsWith(baseType + '/')
}
return file.type.toLowerCase() === acceptType
})
})
}
if (validFiles.length > 0) {
// Emit files to parent component for handling upload
const fileNames = validFiles.map((file) => file.name)
modelValue.value = fileNames
// Trigger the widget's upload handler if available
if ((widget.options as any)?.onFilesSelected) {
;(widget.options as any).onFilesSelected(validFiles)
}
}
}
</script>
<style scoped>
.upload-area {
min-height: 80px;
transition: all 0.2s ease;
}
.upload-area:hover {
border-color: var(--p-primary-500);
}
</style>

View File

@@ -0,0 +1,45 @@
<template>
<div class="w-full px-2">
<!-- Single line text input -->
<InputText
v-if="!isMultiline"
v-model="modelValue"
:placeholder="placeholder"
class="w-full rounded-lg px-3 py-2 text-sm bg-[#222222] text-xs mt-0.5 border-[#222222] shadow-none"
/>
<!-- Multi-line textarea -->
<Textarea
v-else
v-model="modelValue"
:placeholder="placeholder"
:auto-resize="true"
:rows="3"
class="w-full rounded-lg px-3 py-2 text-sm resize-none bg-[#222222] text-xs mt-0.5 border-[#222222] shadow-none"
/>
</div>
</template>
<script setup lang="ts">
import InputText from 'primevue/inputtext'
import Textarea from 'primevue/textarea'
import { computed } from 'vue'
import type { StringInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComponentWidget } from '@/scripts/domWidget'
const modelValue = defineModel<string>({ required: true })
const { widget } = defineProps<{
widget: ComponentWidget<string>
}>()
const inputSpec = widget.inputSpec as StringInputSpec
const isMultiline = computed(() => inputSpec.multiline === true)
const placeholder = computed(
() =>
inputSpec.placeholder ??
inputSpec.default ??
inputSpec.defaultVal ??
inputSpec.name
)
</script>

View File

@@ -0,0 +1,77 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { useImagePreviewWidget } from '@/composables/widgets/useImagePreviewWidget'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
const IMAGE_PREVIEW_WIDGET_NAME = '$$node-image-preview'
/**
* Composable for handling node-level operations for ImagePreview widget
*/
export function useNodeImagePreview() {
const imagePreviewWidget = useImagePreviewWidget()
const findImagePreviewWidget = (node: LGraphNode) =>
node.widgets?.find((w) => w.name === IMAGE_PREVIEW_WIDGET_NAME)
const addImagePreviewWidget = (
node: LGraphNode,
inputSpec?: Partial<InputSpec>
) =>
imagePreviewWidget(node, {
name: IMAGE_PREVIEW_WIDGET_NAME,
type: 'IMAGEPREVIEW',
allow_batch: true,
image_folder: 'input',
...inputSpec
} as InputSpec)
/**
* Shows image preview widget for a node
* @param node The graph node to show the widget for
* @param images The images to display (can be single image or array)
* @param options Configuration options
*/
function showImagePreview(
node: LGraphNode,
images: string | string[],
options: {
allow_batch?: boolean
image_folder?: string
imageInputName?: string
} = {}
) {
const widget =
findImagePreviewWidget(node) ??
addImagePreviewWidget(node, {
allow_batch: options.allow_batch,
image_folder: options.image_folder || 'input'
})
// Set the widget value
widget.value = images
node.setDirtyCanvas?.(true)
}
/**
* Removes image preview widget from a node
* @param node The graph node to remove the widget from
*/
function removeImagePreview(node: LGraphNode) {
if (!node.widgets) return
const widgetIdx = node.widgets.findIndex(
(w) => w.name === IMAGE_PREVIEW_WIDGET_NAME
)
if (widgetIdx > -1) {
node.widgets[widgetIdx].onRemove?.()
node.widgets.splice(widgetIdx, 1)
}
}
return {
showImagePreview,
removeImagePreview
}
}

View File

@@ -68,7 +68,10 @@ export const useNodeImageUpload = (
return validPaths
}
// Handle drag & drop
// Note: MediaLoader widget functionality is handled directly by
// useImageUploadMediaWidget.ts to avoid circular dependencies
// Traditional approach: Handle drag & drop
useNodeDragAndDrop(node, {
fileFilter,
onDrop: handleUploadBatch

View File

@@ -0,0 +1,122 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { useMediaLoaderWidget } from '@/composables/widgets/useMediaLoaderWidget'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { api } from '@/scripts/api'
import { useToastStore } from '@/stores/toastStore'
const MEDIA_LOADER_WIDGET_NAME = '$$node-media-loader'
const PASTED_IMAGE_EXPIRY_MS = 2000
const uploadFile = async (file: File, isPasted: boolean) => {
const body = new FormData()
body.append('image', file)
if (isPasted) body.append('subfolder', 'pasted')
const resp = await api.fetchApi('/upload/image', {
method: 'POST',
body
})
if (resp.status !== 200) {
useToastStore().addAlert(resp.status + ' - ' + resp.statusText)
return
}
const data = await resp.json()
return data.subfolder ? `${data.subfolder}/${data.name}` : data.name
}
interface MediaUploadOptions {
fileFilter?: (file: File) => boolean
onUploadComplete: (paths: string[]) => void
allow_batch?: boolean
accept?: string
}
/**
* Composable for handling media upload with Vue MediaLoader widget
*/
export function useNodeMediaUpload() {
const mediaLoaderWidget = useMediaLoaderWidget()
const findMediaLoaderWidget = (node: LGraphNode) =>
node.widgets?.find((w) => w.name === MEDIA_LOADER_WIDGET_NAME)
const addMediaLoaderWidget = (
node: LGraphNode,
options: MediaUploadOptions
) => {
const isPastedFile = (file: File): boolean =>
file.name === 'image.png' &&
file.lastModified - Date.now() < PASTED_IMAGE_EXPIRY_MS
const handleUpload = async (file: File) => {
try {
const path = await uploadFile(file, isPastedFile(file))
if (!path) return
return path
} catch (error) {
useToastStore().addAlert(String(error))
}
}
// Create the MediaLoader widget
const widget = mediaLoaderWidget(node, {
name: MEDIA_LOADER_WIDGET_NAME,
type: 'MEDIA_LOADER'
} as InputSpec)
// Connect the widget to the upload handler
if (widget.options) {
;(widget.options as any).onFilesSelected = async (files: File[]) => {
const filteredFiles = options.fileFilter
? files.filter(options.fileFilter)
: files
const paths = await Promise.all(filteredFiles.map(handleUpload))
const validPaths = paths.filter((p): p is string => !!p)
if (validPaths.length) {
options.onUploadComplete(validPaths)
}
}
}
return widget
}
/**
* Shows media loader widget for a node
* @param node The graph node to show the widget for
* @param options Upload configuration options
*/
function showMediaLoader(node: LGraphNode, options: MediaUploadOptions) {
const widget =
findMediaLoaderWidget(node) ?? addMediaLoaderWidget(node, options)
node.setDirtyCanvas?.(true)
return widget
}
/**
* Removes media loader widget from a node
* @param node The graph node to remove the widget from
*/
function removeMediaLoader(node: LGraphNode) {
if (!node.widgets) return
const widgetIdx = node.widgets.findIndex(
(w) => w.name === MEDIA_LOADER_WIDGET_NAME
)
if (widgetIdx > -1) {
node.widgets[widgetIdx].onRemove?.()
node.widgets.splice(widgetIdx, 1)
}
}
return {
showMediaLoader,
removeMediaLoader,
addMediaLoaderWidget
}
}

View File

@@ -0,0 +1,173 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { reactive, ref } from 'vue'
import BadgedNumberInput from '@/components/graph/widgets/BadgedNumberInput.vue'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
const PADDING = 8
type BadgeState = 'normal' | 'random' | 'lock' | 'increment' | 'decrement'
type NumberWidgetMode = 'int' | 'float'
interface BadgedNumberInputOptions {
defaultValue?: number
badgeState?: BadgeState
disabled?: boolean
minHeight?: number
serialize?: boolean
mode?: NumberWidgetMode
}
// Helper function to map control widget values to badge states
const mapControlValueToBadgeState = (controlValue: string): BadgeState => {
switch (controlValue) {
case 'fixed':
return 'lock'
case 'increment':
return 'increment'
case 'decrement':
return 'decrement'
case 'randomize':
return 'random'
default:
return 'normal'
}
}
export const useBadgedNumberInput = (
options: BadgedNumberInputOptions = {}
) => {
const {
defaultValue = 0,
disabled = false,
minHeight = 32,
serialize = true,
mode = 'int'
} = options
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
// Initialize widget value as string to conform to ComponentWidgetImpl requirements
const widgetValue = ref<string>(defaultValue.toString())
// Determine if we should show control widget and badge
const shouldShowControlWidget =
inputSpec.control_after_generate ??
// Legacy compatibility: seed inputs get control widgets
['seed', 'noise_seed'].includes(inputSpec.name)
// Create reactive props object for the component
const componentProps = reactive({
badgeState:
options.badgeState ??
(shouldShowControlWidget ? 'random' : ('normal' as BadgeState)),
disabled
})
const controlWidget: any = null
// Create the main widget instance
const widget = new ComponentWidgetImpl<
string | object,
Omit<
InstanceType<typeof BadgedNumberInput>['$props'],
'widget' | 'modelValue'
>
>({
node,
name: inputSpec.name,
component: BadgedNumberInput,
inputSpec,
props: componentProps,
options: {
// Required: getter for widget value - return as string
getValue: () => widgetValue.value as string | object,
// Required: setter for widget value - accept number, string or object
setValue: (value: string | object | number) => {
let numValue: number
if (typeof value === 'object') {
numValue = parseFloat(JSON.stringify(value))
} else {
numValue =
typeof value === 'number' ? value : parseFloat(String(value))
}
if (!isNaN(numValue)) {
// Apply int/float specific value processing
if (mode === 'int') {
const step = (inputSpec as any).step ?? 1
if (step === 1) {
numValue = Math.round(numValue)
} else {
const min = (inputSpec as any).min ?? 0
const offset = min % step
numValue =
Math.round((numValue - offset) / step) * step + offset
}
}
widgetValue.value = numValue.toString()
}
},
// Optional: minimum height for the widget
getMinHeight: () => minHeight + PADDING,
// Lock maximum height to prevent oversizing
getMaxHeight: () => 48,
// Optional: whether to serialize this widget's value
serialize
}
})
// Add control widget if needed - temporarily disabled to fix circular dependency
if (shouldShowControlWidget) {
// TODO: Re-implement control widget functionality without circular dependency
console.warn(
'Control widget functionality temporarily disabled due to circular dependency'
)
// controlWidget = addValueControlWidget(
// node,
// widget as any, // Cast to satisfy the interface
// 'randomize',
// undefined,
// undefined,
// transformInputSpecV2ToV1(inputSpec)
// )
// Set up reactivity to update badge state when control widget changes
if (controlWidget) {
const originalCallback = controlWidget.callback
controlWidget.callback = function (value: string) {
componentProps.badgeState = mapControlValueToBadgeState(value)
if (originalCallback) {
originalCallback.call(this, value)
}
}
// Initialize badge state
componentProps.badgeState = mapControlValueToBadgeState(
controlWidget.value || 'randomize'
)
// Link the widgets
;(widget as any).linkedWidgets = [controlWidget]
}
}
// Register the widget with the node
addWidget(node, widget)
return widget
}
return widgetConstructor
}
// Export types for use in other modules
export type { BadgeState, BadgedNumberInputOptions, NumberWidgetMode }

View File

@@ -4,7 +4,7 @@ import {
type InputSpec,
isBooleanInputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
export const useBooleanWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (

View File

@@ -4,7 +4,7 @@ import { ref } from 'vue'
import ChatHistoryWidget from '@/components/graph/widgets/ChatHistoryWidget.vue'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
const PADDING = 16

View File

@@ -0,0 +1,207 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { ref } from 'vue'
import ColorPickerWidget from '@/components/graph/widgets/ColorPickerWidget.vue'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
const PADDING = 8
interface ColorPickerWidgetOptions {
defaultValue?: string
defaultFormat?: 'rgba' | 'hsla' | 'hsva' | 'hex'
minHeight?: number
serialize?: boolean
}
export const useColorPickerWidget = (
options: ColorPickerWidgetOptions = {}
) => {
const {
defaultValue = 'rgba(255, 0, 0, 1)',
minHeight = 48,
serialize = true
} = options
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
// Initialize widget value as string
const widgetValue = ref<string>(defaultValue)
// Create the main widget instance
const widget = new ComponentWidgetImpl<string>({
node,
name: inputSpec.name,
component: ColorPickerWidget,
inputSpec,
options: {
// Required: getter for widget value
getValue: () => widgetValue.value,
// Required: setter for widget value
setValue: (value: string | any) => {
// Handle different input types
if (typeof value === 'string') {
// Validate and normalize color string
const normalizedValue = normalizeColorString(value)
if (normalizedValue) {
widgetValue.value = normalizedValue
}
} else if (typeof value === 'object' && value !== null) {
// Handle object input (e.g., from PrimeVue ColorPicker)
if (value.hex) {
widgetValue.value = value.hex
} else {
// Try to convert object to string
widgetValue.value = String(value)
}
} else {
// Fallback to string conversion
widgetValue.value = String(value)
}
},
// Optional: minimum height for the widget
getMinHeight: () => minHeight + PADDING,
// Optional: whether to serialize this widget's value
serialize
}
})
// Register the widget with the node
addWidget(node, widget as any)
return widget
}
return widgetConstructor
}
/**
* Normalizes color string inputs to ensure consistent format
* @param colorString - The input color string
* @returns Normalized color string or null if invalid
*/
function normalizeColorString(colorString: string): string | null {
if (!colorString || typeof colorString !== 'string') {
return null
}
const trimmed = colorString.trim()
// Handle hex colors
if (trimmed.startsWith('#')) {
if (/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(trimmed)) {
// Convert 3-digit hex to 6-digit
if (trimmed.length === 4) {
return (
'#' +
trimmed[1] +
trimmed[1] +
trimmed[2] +
trimmed[2] +
trimmed[3] +
trimmed[3]
)
}
return trimmed.toLowerCase()
}
return null
}
// Handle rgb/rgba colors
if (trimmed.startsWith('rgb')) {
const rgbaMatch = trimmed.match(
/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/
)
if (rgbaMatch) {
const [, r, g, b, a] = rgbaMatch
const red = Math.max(0, Math.min(255, parseInt(r)))
const green = Math.max(0, Math.min(255, parseInt(g)))
const blue = Math.max(0, Math.min(255, parseInt(b)))
const alpha = a ? Math.max(0, Math.min(1, parseFloat(a))) : 1
if (alpha === 1) {
return `rgb(${red}, ${green}, ${blue})`
} else {
return `rgba(${red}, ${green}, ${blue}, ${alpha})`
}
}
return null
}
// Handle hsl/hsla colors
if (trimmed.startsWith('hsl')) {
const hslaMatch = trimmed.match(
/hsla?\(\s*(\d+)\s*,\s*(\d+)%?\s*,\s*(\d+)%?\s*(?:,\s*([\d.]+))?\s*\)/
)
if (hslaMatch) {
const [, h, s, l, a] = hslaMatch
const hue = Math.max(0, Math.min(360, parseInt(h)))
const saturation = Math.max(0, Math.min(100, parseInt(s)))
const lightness = Math.max(0, Math.min(100, parseInt(l)))
const alpha = a ? Math.max(0, Math.min(1, parseFloat(a))) : 1
if (alpha === 1) {
return `hsl(${hue}, ${saturation}%, ${lightness}%)`
} else {
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`
}
}
return null
}
// Handle hsv/hsva colors (custom format)
if (trimmed.startsWith('hsv')) {
const hsvaMatch = trimmed.match(
/hsva?\(\s*(\d+)\s*,\s*(\d+)%?\s*,\s*(\d+)%?\s*(?:,\s*([\d.]+))?\s*\)/
)
if (hsvaMatch) {
const [, h, s, v, a] = hsvaMatch
const hue = Math.max(0, Math.min(360, parseInt(h)))
const saturation = Math.max(0, Math.min(100, parseInt(s)))
const value = Math.max(0, Math.min(100, parseInt(v)))
const alpha = a ? Math.max(0, Math.min(1, parseFloat(a))) : 1
if (alpha === 1) {
return `hsv(${hue}, ${saturation}%, ${value}%)`
} else {
return `hsva(${hue}, ${saturation}%, ${value}%, ${alpha})`
}
}
return null
}
// Handle named colors by converting to hex (basic set)
const namedColors: Record<string, string> = {
red: '#ff0000',
green: '#008000',
blue: '#0000ff',
white: '#ffffff',
black: '#000000',
yellow: '#ffff00',
cyan: '#00ffff',
magenta: '#ff00ff',
orange: '#ffa500',
purple: '#800080',
pink: '#ffc0cb',
brown: '#a52a2a',
gray: '#808080',
grey: '#808080'
}
const lowerTrimmed = trimmed.toLowerCase()
if (namedColors[lowerTrimmed]) {
return namedColors[lowerTrimmed]
}
// If we can't parse it, return null
return null
}
// Export types for use in other modules
export type { ColorPickerWidgetOptions }

View File

@@ -1,9 +1,7 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import type { IComboWidget } from '@comfyorg/litegraph/dist/types/widgets'
import { ref } from 'vue'
import MultiSelectWidget from '@/components/graph/widgets/MultiSelectWidget.vue'
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
import {
ComboInputSpec,
type InputSpec,
@@ -14,19 +12,11 @@ import {
ComponentWidgetImpl,
addWidget
} from '@/scripts/domWidget'
import {
type ComfyWidgetConstructorV2,
addValueControlWidgets
} from '@/scripts/widgets'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
import { useRemoteWidget } from './useRemoteWidget'
import { useDropdownComboWidget } from './useDropdownComboWidget'
const getDefaultValue = (inputSpec: ComboInputSpec) => {
if (inputSpec.default) return inputSpec.default
if (inputSpec.options?.length) return inputSpec.options[0]
if (inputSpec.remote) return 'Loading...'
return undefined
}
// Default value logic is now handled in useDropdownComboWidget
const addMultiSelectWidget = (node: LGraphNode, inputSpec: ComboInputSpec) => {
const widgetValue = ref<string[]>([])
@@ -39,7 +29,13 @@ const addMultiSelectWidget = (node: LGraphNode, inputSpec: ComboInputSpec) => {
getValue: () => widgetValue.value,
setValue: (value: string[]) => {
widgetValue.value = value
}
},
// Optional: minimum height for the widget (multiselect needs minimal height)
getMinHeight: () => 24,
// Lock maximum height to prevent oversizing
getMaxHeight: () => 32,
// Optional: whether to serialize this widget's value
serialize: true
}
})
addWidget(node, widget as BaseDOMWidget<object | string>)
@@ -49,49 +45,9 @@ const addMultiSelectWidget = (node: LGraphNode, inputSpec: ComboInputSpec) => {
}
const addComboWidget = (node: LGraphNode, inputSpec: ComboInputSpec) => {
const defaultValue = getDefaultValue(inputSpec)
const comboOptions = inputSpec.options ?? []
const widget = node.addWidget(
'combo',
inputSpec.name,
defaultValue,
() => {},
{
values: comboOptions
}
) as IComboWidget
if (inputSpec.remote) {
const remoteWidget = useRemoteWidget({
remoteConfig: inputSpec.remote,
defaultValue,
node,
widget
})
if (inputSpec.remote.refresh_button) remoteWidget.addRefreshButton()
const origOptions = widget.options
widget.options = new Proxy(origOptions, {
get(target, prop) {
// Assertion: Proxy handler passthrough
return prop !== 'values'
? target[prop as keyof typeof target]
: remoteWidget.getValue()
}
})
}
if (inputSpec.control_after_generate) {
widget.linkedWidgets = addValueControlWidgets(
node,
widget,
undefined,
undefined,
transformInputSpecV2ToV1(inputSpec)
)
}
return widget
// Use the new dropdown combo widget for single-selection combo widgets
const dropdownWidget = useDropdownComboWidget()
return dropdownWidget(node, inputSpec)
}
export const useComboWidget = () => {

View File

@@ -0,0 +1,98 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { ref } from 'vue'
import DropdownComboWidget from '@/components/graph/widgets/DropdownComboWidget.vue'
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
import type {
ComboInputSpec,
InputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
import { addValueControlWidgets } from '@/scripts/widgets'
import { useRemoteWidget } from './useRemoteWidget'
const getDefaultValue = (inputSpec: ComboInputSpec) => {
if (inputSpec.default) return inputSpec.default
if (inputSpec.options?.length) return inputSpec.options[0]
if (inputSpec.remote) return 'Loading...'
return ''
}
export const useDropdownComboWidget = (
options: { defaultValue?: string } = {}
) => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
// Type assertion to ComboInputSpec since this is specifically for combo widgets
const comboInputSpec = inputSpec as ComboInputSpec
// Initialize widget value
const defaultValue = options.defaultValue ?? getDefaultValue(comboInputSpec)
const widgetValue = ref<string>(defaultValue)
// Create the widget instance
const widget = new ComponentWidgetImpl<string>({
node,
name: inputSpec.name,
component: DropdownComboWidget,
inputSpec,
options: {
// Required: getter for widget value
getValue: () => widgetValue.value,
// Required: setter for widget value
setValue: (value: string) => {
widgetValue.value = value
},
// Optional: minimum height for the widget (dropdown needs minimal height)
getMinHeight: () => 32,
// Lock maximum height to prevent oversizing
getMaxHeight: () => 48,
// Optional: whether to serialize this widget's value
serialize: true
}
})
// Handle remote widget functionality
if (comboInputSpec.remote) {
const remoteWidget = useRemoteWidget({
remoteConfig: comboInputSpec.remote,
defaultValue,
node,
widget: widget as any // Cast to be compatible with the remote widget interface
})
if (comboInputSpec.remote.refresh_button) {
remoteWidget.addRefreshButton()
}
// Update the widget to use remote data
// Note: The remote widget will handle updating the options through the inputSpec
}
// Handle control_after_generate widgets
if (comboInputSpec.control_after_generate) {
const linkedWidgets = addValueControlWidgets(
node,
widget as any, // Cast to be compatible with legacy widget interface
undefined,
undefined,
transformInputSpecV2ToV1(comboInputSpec)
)
// Store reference to linked widgets (mimicking original behavior)
;(widget as any).linkedWidgets = linkedWidgets
}
// Register the widget with the node
addWidget(node, widget as any)
return widget
}
return widgetConstructor
}

View File

@@ -6,7 +6,7 @@ import {
type InputSpec,
isFloatInputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
import { useSettingStore } from '@/stores/settingStore'
function onFloatValueChange(this: INumericWidget, v: number) {

View File

@@ -1,317 +1,53 @@
import {
BaseWidget,
type CanvasPointer,
type LGraphNode,
LiteGraph
} from '@comfyorg/litegraph'
import type {
IBaseWidget,
IWidgetOptions
} from '@comfyorg/litegraph/dist/types/widgets'
import type { LGraphNode } from '@comfyorg/litegraph'
import { ref } from 'vue'
import ImagePreviewWidget from '@/components/graph/widgets/ImagePreviewWidget.vue'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { app } from '@/scripts/app'
import { calculateImageGrid } from '@/scripts/ui/imagePreview'
import { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { useCanvasStore } from '@/stores/graphStore'
import { useSettingStore } from '@/stores/settingStore'
import { is_all_same_aspect_ratio } from '@/utils/imageUtil'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
const renderPreview = (
ctx: CanvasRenderingContext2D,
node: LGraphNode,
shiftY: number
const PADDING = 8
export const useImagePreviewWidget = (
options: { defaultValue?: string | string[] } = {}
) => {
const canvas = useCanvasStore().getCanvas()
const mouse = canvas.graph_mouse
if (!canvas.pointer_is_down && node.pointerDown) {
if (
mouse[0] === node.pointerDown.pos[0] &&
mouse[1] === node.pointerDown.pos[1]
) {
node.imageIndex = node.pointerDown.index
}
node.pointerDown = null
}
const imgs = node.imgs ?? []
let { imageIndex } = node
const numImages = imgs.length
if (numImages === 1 && !imageIndex) {
// This skips the thumbnail render section below
node.imageIndex = imageIndex = 0
}
const settingStore = useSettingStore()
const allowImageSizeDraw = settingStore.get('Comfy.Node.AllowImageSizeDraw')
const IMAGE_TEXT_SIZE_TEXT_HEIGHT = allowImageSizeDraw ? 15 : 0
const dw = node.size[0]
const dh = node.size[1] - shiftY - IMAGE_TEXT_SIZE_TEXT_HEIGHT
if (imageIndex == null) {
// No image selected; draw thumbnails of all
let cellWidth: number
let cellHeight: number
let shiftX: number
let cell_padding: number
let cols: number
const compact_mode = is_all_same_aspect_ratio(imgs)
if (!compact_mode) {
// use rectangle cell style and border line
cell_padding = 2
// Prevent infinite canvas2d scale-up
const largestDimension = imgs.reduce(
(acc, current) =>
Math.max(acc, current.naturalWidth, current.naturalHeight),
0
)
const fakeImgs = []
fakeImgs.length = imgs.length
fakeImgs[0] = {
naturalWidth: largestDimension,
naturalHeight: largestDimension
}
;({ cellWidth, cellHeight, cols, shiftX } = calculateImageGrid(
fakeImgs,
dw,
dh
))
} else {
cell_padding = 0
;({ cellWidth, cellHeight, cols, shiftX } = calculateImageGrid(
imgs,
dw,
dh
))
}
let anyHovered = false
node.imageRects = []
for (let i = 0; i < numImages; i++) {
const img = imgs[i]
const row = Math.floor(i / cols)
const col = i % cols
const x = col * cellWidth + shiftX
const y = row * cellHeight + shiftY
if (!anyHovered) {
anyHovered = LiteGraph.isInsideRectangle(
mouse[0],
mouse[1],
x + node.pos[0],
y + node.pos[1],
cellWidth,
cellHeight
)
if (anyHovered) {
node.overIndex = i
let value = 110
if (canvas.pointer_is_down) {
if (!node.pointerDown || node.pointerDown.index !== i) {
node.pointerDown = { index: i, pos: [...mouse] }
}
value = 125
}
ctx.filter = `contrast(${value}%) brightness(${value}%)`
canvas.canvas.style.cursor = 'pointer'
}
}
node.imageRects.push([x, y, cellWidth, cellHeight])
const wratio = cellWidth / img.width
const hratio = cellHeight / img.height
const ratio = Math.min(wratio, hratio)
const imgHeight = ratio * img.height
const imgY = row * cellHeight + shiftY + (cellHeight - imgHeight) / 2
const imgWidth = ratio * img.width
const imgX = col * cellWidth + shiftX + (cellWidth - imgWidth) / 2
ctx.drawImage(
img,
imgX + cell_padding,
imgY + cell_padding,
imgWidth - cell_padding * 2,
imgHeight - cell_padding * 2
)
if (!compact_mode) {
// rectangle cell and border line style
ctx.strokeStyle = '#8F8F8F'
ctx.lineWidth = 1
ctx.strokeRect(
x + cell_padding,
y + cell_padding,
cellWidth - cell_padding * 2,
cellHeight - cell_padding * 2
)
}
ctx.filter = 'none'
}
if (!anyHovered) {
node.pointerDown = null
node.overIndex = null
}
return
}
// Draw individual
const img = imgs[imageIndex]
let w = img.naturalWidth
let h = img.naturalHeight
const scaleX = dw / w
const scaleY = dh / h
const scale = Math.min(scaleX, scaleY, 1)
w *= scale
h *= scale
const x = (dw - w) / 2
const y = (dh - h) / 2 + shiftY
ctx.drawImage(img, x, y, w, h)
// Draw image size text below the image
if (allowImageSizeDraw) {
ctx.fillStyle = LiteGraph.NODE_TEXT_COLOR
ctx.textAlign = 'center'
ctx.font = '10px sans-serif'
const sizeText = `${Math.round(img.naturalWidth)} × ${Math.round(img.naturalHeight)}`
const textY = y + h + 10
ctx.fillText(sizeText, x + w / 2, textY)
}
const drawButton = (
x: number,
y: number,
sz: number,
text: string
): boolean => {
const hovered = LiteGraph.isInsideRectangle(
mouse[0],
mouse[1],
x + node.pos[0],
y + node.pos[1],
sz,
sz
)
let fill = '#333'
let textFill = '#fff'
let isClicking = false
if (hovered) {
canvas.canvas.style.cursor = 'pointer'
if (canvas.pointer_is_down) {
fill = '#1e90ff'
isClicking = true
} else {
fill = '#eee'
textFill = '#000'
}
}
ctx.fillStyle = fill
ctx.beginPath()
ctx.roundRect(x, y, sz, sz, [4])
ctx.fill()
ctx.fillStyle = textFill
ctx.font = '12px Arial'
ctx.textAlign = 'center'
ctx.fillText(text, x + 15, y + 20)
return isClicking
}
if (!(numImages > 1)) return
const imageNum = (node.imageIndex ?? 0) + 1
if (drawButton(dw - 40, dh + shiftY - 40, 30, `${imageNum}/${numImages}`)) {
const i = imageNum >= numImages ? 0 : imageNum
if (!node.pointerDown || node.pointerDown.index !== i) {
node.pointerDown = { index: i, pos: [...mouse] }
}
}
if (drawButton(dw - 40, shiftY + 10, 30, `x`)) {
if (!node.pointerDown || node.pointerDown.index !== null) {
node.pointerDown = { index: null, pos: [...mouse] }
}
}
}
class ImagePreviewWidget extends BaseWidget {
constructor(
node: LGraphNode,
name: string,
options: IWidgetOptions<string | object>
) {
const widget: IBaseWidget = {
name,
options,
type: 'custom',
/** Dummy value to satisfy type requirements. */
value: '',
y: 0
}
super(widget, node)
// Don't serialize the widget value
this.serialize = false
}
override drawWidget(ctx: CanvasRenderingContext2D): void {
renderPreview(ctx, this.node, this.y)
}
override onPointerDown(pointer: CanvasPointer, node: LGraphNode): boolean {
pointer.onDragStart = () => {
const { canvas } = app
const { graph } = canvas
canvas.emitBeforeChange()
graph?.beforeChange()
// Ensure that dragging is properly cleaned up, on success or failure.
pointer.finally = () => {
canvas.isDragging = false
graph?.afterChange()
canvas.emitAfterChange()
}
canvas.processSelect(node, pointer.eDown)
canvas.isDragging = true
}
pointer.onDragEnd = (e) => {
const { canvas } = app
if (e.shiftKey || LiteGraph.alwaysSnapToGrid)
canvas.graph?.snapToGrid(canvas.selectedItems)
canvas.setDirty(true, true)
}
return true
}
override onClick(): void {}
override computeLayoutSize() {
return {
minHeight: 220,
minWidth: 1
}
}
}
export const useImagePreviewWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
return node.addCustomWidget(
new ImagePreviewWidget(node, inputSpec.name, {
serialize: false
})
// Initialize widget value
const widgetValue = ref<string | string[]>(
options.defaultValue ?? (inputSpec.allow_batch ? [] : '')
)
// Create the Vue-based widget instance
const widget = new ComponentWidgetImpl<string | string[]>({
node,
name: inputSpec.name,
component: ImagePreviewWidget,
inputSpec,
options: {
// Required: getter for widget value
getValue: () => widgetValue.value,
// Required: setter for widget value
setValue: (value: string | string[]) => {
widgetValue.value = value
},
// Optional: minimum height for the widget
getMinHeight: () => 320 + PADDING,
getMaxHeight: () => 512 + PADDING,
// Optional: whether to serialize this widget's value
serialize: false
}
})
// Register the widget with the node
addWidget(node, widget as any)
return widget
}
return widgetConstructor

View File

@@ -0,0 +1,242 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { IComboWidget } from '@comfyorg/litegraph/dist/types/widgets'
import { ref } from 'vue'
import MediaLoaderWidget from '@/components/graph/widgets/MediaLoaderWidget.vue'
import { useNodeImage, useNodeVideo } from '@/composables/node/useNodeImage'
import { useNodeImagePreview } from '@/composables/node/useNodeImagePreview'
import { useValueTransform } from '@/composables/useValueTransform'
import type { ResultItem } from '@/schemas/apiSchema'
import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import { api } from '@/scripts/api'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
import { useToastStore } from '@/stores/toastStore'
import { createAnnotatedPath } from '@/utils/formatUtil'
import { addToComboValues } from '@/utils/litegraphUtil'
const ACCEPTED_IMAGE_TYPES = 'image/png,image/jpeg,image/webp'
const ACCEPTED_VIDEO_TYPES = 'video/webm,video/mp4'
const PASTED_IMAGE_EXPIRY_MS = 2000
const uploadFile = async (file: File, isPasted: boolean) => {
const body = new FormData()
body.append('image', file)
if (isPasted) body.append('subfolder', 'pasted')
const resp = await api.fetchApi('/upload/image', {
method: 'POST',
body
})
if (resp.status !== 200) {
useToastStore().addAlert(resp.status + ' - ' + resp.statusText)
return
}
const data = await resp.json()
return data.subfolder ? `${data.subfolder}/${data.name}` : data.name
}
type InternalFile = string | ResultItem
type InternalValue = InternalFile | InternalFile[]
type ExposedValue = string | string[]
const isImageFile = (file: File) => file.type.startsWith('image/')
const isVideoFile = (file: File) => file.type.startsWith('video/')
const findFileComboWidget = (node: LGraphNode, inputName: string) =>
node.widgets!.find((w) => w.name === inputName) as IComboWidget & {
value: ExposedValue
}
export const useImageUploadMediaWidget = () => {
const widgetConstructor: ComfyWidgetConstructor = (
node: LGraphNode,
inputName: string,
inputData: InputSpec
) => {
const inputOptions = inputData[1] ?? {}
const { imageInputName, allow_batch, image_folder = 'input' } = inputOptions
const nodeOutputStore = useNodeOutputStore()
const isAnimated = !!inputOptions.animated_image_upload
const isVideo = !!inputOptions.video_upload
const accept = isVideo ? ACCEPTED_VIDEO_TYPES : ACCEPTED_IMAGE_TYPES
const { showPreview } = isVideo ? useNodeVideo(node) : useNodeImage(node)
const { showImagePreview } = useNodeImagePreview()
const fileFilter = isVideo ? isVideoFile : isImageFile
// @ts-expect-error InputSpec is not typed correctly
const fileComboWidget = findFileComboWidget(node, imageInputName)
const initialFile = `${fileComboWidget.value}`
const formatPath = (value: InternalFile) =>
// @ts-expect-error InputSpec is not typed correctly
createAnnotatedPath(value, { rootFolder: image_folder })
const transform = (internalValue: InternalValue): ExposedValue => {
if (!internalValue) return initialFile
if (Array.isArray(internalValue))
return allow_batch
? internalValue.map(formatPath)
: formatPath(internalValue[0])
return formatPath(internalValue)
}
Object.defineProperty(
fileComboWidget,
'value',
useValueTransform(transform, initialFile)
)
// Convert the V1 input spec to V2 format for the MediaLoader widget
const inputSpecV2 = transformInputSpecV1ToV2(inputData, { name: inputName })
// Handle widget dimensions based on input options
const getMinHeight = () => {
// Use smaller height for MediaLoader upload widget
let baseHeight = 176
// Handle multiline attribute for expanded height
if (inputOptions.multiline) {
baseHeight = Math.max(
baseHeight,
inputOptions.multiline === true
? 120
: Number(inputOptions.multiline) || 120
)
}
// Handle other height-related attributes
if (inputOptions.min_height) {
baseHeight = Math.max(baseHeight, Number(inputOptions.min_height))
}
return baseHeight + 8 // Add padding
}
const getMaxHeight = () => {
// Lock maximum height to prevent oversizing of upload widget
if (inputOptions.multiline || inputOptions.min_height) {
// Allow more height for special cases
return Math.max(200, getMinHeight())
}
// Lock standard upload widget to ~80px max
return 80
}
// State for MediaLoader widget
const uploadedFiles = ref<string[]>([])
// Create the MediaLoader widget directly
const uploadWidget = new ComponentWidgetImpl<string[], { accept?: string }>(
{
node,
name: inputName,
component: MediaLoaderWidget,
inputSpec: inputSpecV2,
props: {
accept
},
options: {
getValue: () => uploadedFiles.value,
setValue: (value: string[]) => {
uploadedFiles.value = value
},
getMinHeight,
getMaxHeight, // Lock maximum height to prevent oversizing
serialize: false,
onFilesSelected: async (files: File[]) => {
const isPastedFile = (file: File): boolean =>
file.name === 'image.png' &&
file.lastModified - Date.now() < PASTED_IMAGE_EXPIRY_MS
const handleUpload = async (file: File) => {
try {
const path = await uploadFile(file, isPastedFile(file))
if (!path) return
return path
} catch (error) {
useToastStore().addAlert(String(error))
}
}
// Filter and upload files
const filteredFiles = files.filter(fileFilter)
const paths = await Promise.all(filteredFiles.map(handleUpload))
const validPaths = paths.filter((p): p is string => !!p)
if (validPaths.length) {
validPaths.forEach((path) =>
addToComboValues(fileComboWidget, path)
)
const output = allow_batch ? validPaths : validPaths[0]
// @ts-expect-error litegraph combo value type does not support arrays yet
fileComboWidget.value = output
// Update widget value to show file names
uploadedFiles.value = Array.isArray(output) ? output : [output]
// Trigger the combo widget callback to update all dependent widgets
fileComboWidget.callback?.(output)
}
}
} as any
}
)
// Register the widget with the node
addWidget(node, uploadWidget as any)
// Store the original callback if it exists
const originalCallback = fileComboWidget.callback
// Add our own callback to the combo widget to render an image when it changes
fileComboWidget.callback = function (value?: any) {
// Call original callback first if it exists
originalCallback?.call(this, value)
nodeOutputStore.setNodeOutputs(node, fileComboWidget.value, {
isAnimated
})
// Use Vue widget for image preview, fallback to DOM widget for video
if (!isVideo) {
showImagePreview(node, fileComboWidget.value, {
allow_batch: allow_batch as boolean,
image_folder: image_folder as string,
imageInputName: imageInputName as string
})
}
node.graph?.setDirtyCanvas(true)
}
// On load if we have a value then render the image
// The value isnt set immediately so we need to wait a moment
// No change callbacks seem to be fired on initial setting of the value
requestAnimationFrame(() => {
nodeOutputStore.setNodeOutputs(node, fileComboWidget.value, {
isAnimated
})
// Use appropriate preview method
if (isVideo) {
showPreview({ block: false })
} else {
showImagePreview(node, fileComboWidget.value, {
allow_batch: allow_batch as boolean,
image_folder: image_folder as string,
imageInputName: imageInputName as string
})
}
})
return { widget: uploadWidget }
}
return widgetConstructor
}

View File

@@ -2,6 +2,7 @@ import type { LGraphNode } from '@comfyorg/litegraph'
import { IComboWidget } from '@comfyorg/litegraph/dist/types/widgets'
import { useNodeImage, useNodeVideo } from '@/composables/node/useNodeImage'
import { useNodeImagePreview } from '@/composables/node/useNodeImagePreview'
import { useNodeImageUpload } from '@/composables/node/useNodeImageUpload'
import { useValueTransform } from '@/composables/useValueTransform'
import { t } from '@/i18n'
@@ -41,6 +42,7 @@ export const useImageUploadWidget = () => {
const isVideo = !!inputOptions.video_upload
const accept = isVideo ? ACCEPTED_VIDEO_TYPES : ACCEPTED_IMAGE_TYPES
const { showPreview } = isVideo ? useNodeVideo(node) : useNodeImage(node)
const { showImagePreview } = useNodeImagePreview()
const fileFilter = isVideo ? isVideoFile : isImageFile
// @ts-expect-error InputSpec is not typed correctly
@@ -96,6 +98,16 @@ export const useImageUploadWidget = () => {
nodeOutputStore.setNodeOutputs(node, fileComboWidget.value, {
isAnimated
})
// Use Vue widget for image preview, fallback to DOM widget for video
if (!isVideo) {
showImagePreview(node, fileComboWidget.value, {
allow_batch: allow_batch as boolean,
image_folder: image_folder as string,
imageInputName: imageInputName as string
})
}
node.graph?.setDirtyCanvas(true)
}
@@ -106,7 +118,17 @@ export const useImageUploadWidget = () => {
nodeOutputStore.setNodeOutputs(node, fileComboWidget.value, {
isAnimated
})
showPreview({ block: false })
// Use appropriate preview method
if (isVideo) {
showPreview({ block: false })
} else {
showImagePreview(node, fileComboWidget.value, {
allow_batch: allow_batch as boolean,
image_folder: image_folder as string,
imageInputName: imageInputName as string
})
}
})
return { widget: uploadWidget }

View File

@@ -1,15 +1,11 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import type { INumericWidget } from '@comfyorg/litegraph/dist/types/widgets'
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
import {
type InputSpec,
isIntInputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import {
type ComfyWidgetConstructorV2,
addValueControlWidget
} from '@/scripts/widgets'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
import { useSettingStore } from '@/stores/settingStore'
function onValueChange(this: INumericWidget, v: number) {
@@ -81,15 +77,19 @@ export const useIntWidget = () => {
['seed', 'noise_seed'].includes(inputSpec.name)
if (controlAfterGenerate) {
const seedControl = addValueControlWidget(
node,
widget,
'randomize',
undefined,
undefined,
transformInputSpecV2ToV1(inputSpec)
// TODO: Re-implement control widget functionality without circular dependency
console.warn(
'Control widget functionality temporarily disabled for int widgets due to circular dependency'
)
widget.linkedWidgets = [seedControl]
// const seedControl = addValueControlWidget(
// node,
// widget,
// 'randomize',
// undefined,
// undefined,
// transformInputSpecV2ToV1(inputSpec)
// )
// widget.linkedWidgets = [seedControl]
}
return widget

View File

@@ -10,7 +10,7 @@ import { Markdown as TiptapMarkdown } from 'tiptap-markdown'
import { type InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { app } from '@/scripts/app'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
function addMarkdownWidget(
node: LGraphNode,

View File

@@ -0,0 +1,72 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { ref } from 'vue'
import MediaLoaderWidget from '@/components/graph/widgets/MediaLoaderWidget.vue'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import {
ComponentWidgetImpl,
type DOMWidgetOptions,
addWidget
} from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
const PADDING = 8
interface MediaLoaderOptions {
defaultValue?: string[]
minHeight?: number
accept?: string
onFilesSelected?: (files: File[]) => void
}
interface MediaLoaderWidgetOptions extends DOMWidgetOptions<string[]> {
onFilesSelected?: (files: File[]) => void
}
export const useMediaLoaderWidget = (options: MediaLoaderOptions = {}) => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
// Initialize widget value
const widgetValue = ref<string[]>(options.defaultValue ?? [])
// Create the widget instance
const widget = new ComponentWidgetImpl<string[], { accept?: string }>({
node,
name: inputSpec.name,
component: MediaLoaderWidget,
inputSpec,
props: {
accept: options.accept
},
options: {
// Required: getter for widget value
getValue: () => widgetValue.value,
// Required: setter for widget value
setValue: (value: string[]) => {
widgetValue.value = Array.isArray(value) ? value : []
},
// Optional: minimum height for the widget
// getMinHeight: () => (options.minHeight ?? 64) + PADDING,
getMaxHeight: () => 225 + PADDING,
getMinHeight: () => 176 + PADDING,
// Optional: whether to serialize this widget's value
serialize: true,
// Custom option for file selection callback
onFilesSelected: options.onFilesSelected
} as MediaLoaderWidgetOptions
})
// Register the widget with the node
addWidget(node, widget as any)
return widget
}
return widgetConstructor
}

View File

@@ -4,7 +4,7 @@ import { ref } from 'vue'
import TextPreviewWidget from '@/components/graph/widgets/TextPreviewWidget.vue'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
const PADDING = 16

View File

@@ -5,7 +5,7 @@ import {
isStringInputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import { app } from '@/scripts/app'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
import { useSettingStore } from '@/stores/settingStore'
function addMultilineWidget(
@@ -91,6 +91,55 @@ function addMultilineWidget(
return widget
}
function addSingleLineWidget(
node: LGraphNode,
name: string,
opts: { defaultVal: string; placeholder?: string }
) {
const inputEl = document.createElement('input')
inputEl.className = 'comfy-text-input'
inputEl.type = 'text'
inputEl.value = opts.defaultVal
inputEl.placeholder = opts.placeholder || name
const widget = node.addDOMWidget(name, 'text', inputEl, {
getValue(): string {
return inputEl.value
},
setValue(v: string) {
inputEl.value = v
}
})
widget.inputEl = inputEl
widget.options.minNodeSize = [200, 40]
inputEl.addEventListener('input', () => {
widget.callback?.(widget.value)
})
// Allow middle mouse button panning
inputEl.addEventListener('pointerdown', (event: PointerEvent) => {
if (event.button === 1) {
app.canvas.processMouseDown(event)
}
})
inputEl.addEventListener('pointermove', (event: PointerEvent) => {
if ((event.buttons & 4) === 4) {
app.canvas.processMouseMove(event)
}
})
inputEl.addEventListener('pointerup', (event: PointerEvent) => {
if (event.button === 1) {
app.canvas.processMouseUp(event)
}
})
return widget
}
export const useStringWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
@@ -108,7 +157,10 @@ export const useStringWidget = () => {
defaultVal,
placeholder: inputSpec.placeholder
})
: node.addWidget('text', inputSpec.name, defaultVal, () => {}, {})
: addSingleLineWidget(node, inputSpec.name, {
defaultVal,
placeholder: inputSpec.placeholder
})
if (typeof inputSpec.dynamicPrompts === 'boolean') {
widget.dynamicPrompts = inputSpec.dynamicPrompts

View File

@@ -0,0 +1,65 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { ref } from 'vue'
import StringWidget from '@/components/graph/widgets/StringWidget.vue'
import {
type InputSpec,
isStringInputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgetTypes'
const PADDING = 8
export const useStringWidgetVue = (options: { defaultValue?: string } = {}) => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
if (!isStringInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
// Initialize widget value
const widgetValue = ref<string>(
inputSpec.default ?? options.defaultValue ?? ''
)
// Create the Vue-based widget instance
const widget = new ComponentWidgetImpl<string>({
node,
name: inputSpec.name,
component: StringWidget,
inputSpec,
options: {
// Required: getter for widget value
getValue: () => widgetValue.value,
// Required: setter for widget value
setValue: (value: string) => {
widgetValue.value = value
},
// Optional: minimum height for the widget
getMinHeight: () => {
return inputSpec.multiline ? 80 + PADDING : 40 + PADDING
},
// Optional: whether to serialize this widget's value
serialize: true
}
})
// Add dynamic prompts support if specified
if (typeof inputSpec.dynamicPrompts === 'boolean') {
widget.dynamicPrompts = inputSpec.dynamicPrompts
}
// Register the widget with the node
addWidget(node, widget as any)
return widget
}
return widgetConstructor
}

View File

@@ -230,6 +230,16 @@
"black": "Black",
"custom": "Custom"
},
"widgets": {
"colorPicker": {
"clickToEdit": "Click to edit color",
"selectColor": "Select a color",
"formatRGBA": "RGBA",
"formatHSLA": "HSLA",
"formatHSVA": "HSVA",
"formatHEX": "HEX"
}
},
"contextMenu": {
"Inputs": "Inputs",
"Outputs": "Outputs",

View File

@@ -1429,6 +1429,16 @@
"getStarted": "Empezar",
"title": "Bienvenido a ComfyUI"
},
"widgets": {
"colorPicker": {
"clickToEdit": "Haz clic para editar el color",
"formatHEX": "HEX",
"formatHSLA": "HSLA",
"formatHSVA": "HSVA",
"formatRGBA": "RGBA",
"selectColor": "Selecciona un color"
}
},
"workflowService": {
"enterFilename": "Introduzca el nombre del archivo",
"exportWorkflow": "Exportar flujo de trabajo",

View File

@@ -1429,6 +1429,16 @@
"getStarted": "Commencer",
"title": "Bienvenue sur ComfyUI"
},
"widgets": {
"colorPicker": {
"clickToEdit": "Cliquez pour modifier la couleur",
"formatHEX": "HEX",
"formatHSLA": "HSLA",
"formatHSVA": "HSVA",
"formatRGBA": "RGBA",
"selectColor": "Sélectionnez une couleur"
}
},
"workflowService": {
"enterFilename": "Entrez le nom du fichier",
"exportWorkflow": "Exporter le flux de travail",

View File

@@ -1429,6 +1429,16 @@
"getStarted": "はじめる",
"title": "ComfyUIへようこそ"
},
"widgets": {
"colorPicker": {
"clickToEdit": "色を編集するにはクリックしてください",
"formatHEX": "HEX",
"formatHSLA": "HSLA",
"formatHSVA": "HSVA",
"formatRGBA": "RGBA",
"selectColor": "色を選択"
}
},
"workflowService": {
"enterFilename": "ファイル名を入力",
"exportWorkflow": "ワークフローをエクスポート",

View File

@@ -1429,6 +1429,16 @@
"getStarted": "시작하기",
"title": "ComfyUI에 오신 것을 환영합니다"
},
"widgets": {
"colorPicker": {
"clickToEdit": "색상 편집하려면 클릭하세요",
"formatHEX": "HEX",
"formatHSLA": "HSLA",
"formatHSVA": "HSVA",
"formatRGBA": "RGBA",
"selectColor": "색상 선택"
}
},
"workflowService": {
"enterFilename": "파일 이름 입력",
"exportWorkflow": "워크플로 내보내기",

View File

@@ -1429,6 +1429,16 @@
"getStarted": "Начать",
"title": "Добро пожаловать в ComfyUI"
},
"widgets": {
"colorPicker": {
"clickToEdit": "Нажмите, чтобы изменить цвет",
"formatHEX": "HEX",
"formatHSLA": "HSLA",
"formatHSVA": "HSVA",
"formatRGBA": "RGBA",
"selectColor": "Выберите цвет"
}
},
"workflowService": {
"enterFilename": "Введите название файла",
"exportWorkflow": "Экспорт рабочего процесса",

View File

@@ -1429,6 +1429,16 @@
"getStarted": "开始使用",
"title": "欢迎使用 ComfyUI"
},
"widgets": {
"colorPicker": {
"clickToEdit": "点击编辑颜色",
"formatHEX": "HEX",
"formatHSLA": "HSLA",
"formatHSVA": "HSVA",
"formatRGBA": "RGBA",
"selectColor": "选择颜色"
}
},
"workflowService": {
"enterFilename": "输入文件名",
"exportWorkflow": "导出工作流",

View File

@@ -0,0 +1,12 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import type { IBaseWidget } from '@comfyorg/litegraph/dist/types/widgets'
import type { InputSpec as InputSpecV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
/**
* Constructor function type for ComfyUI widgets using V2 input specification
*/
export type ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpecV2
) => IBaseWidget

View File

@@ -5,27 +5,25 @@ import type {
IStringWidget
} from '@comfyorg/litegraph/dist/types/widgets'
import { useBadgedNumberInput } from '@/composables/widgets/useBadgedNumberInput'
import { useBooleanWidget } from '@/composables/widgets/useBooleanWidget'
import { useColorPickerWidget } from '@/composables/widgets/useColorPickerWidget'
import { useComboWidget } from '@/composables/widgets/useComboWidget'
import { useFloatWidget } from '@/composables/widgets/useFloatWidget'
import { useImageUploadWidget } from '@/composables/widgets/useImageUploadWidget'
import { useIntWidget } from '@/composables/widgets/useIntWidget'
import { useImagePreviewWidget } from '@/composables/widgets/useImagePreviewWidget'
import { useImageUploadMediaWidget } from '@/composables/widgets/useImageUploadMediaWidget'
import { useMarkdownWidget } from '@/composables/widgets/useMarkdownWidget'
import { useMediaLoaderWidget } from '@/composables/widgets/useMediaLoaderWidget'
import { useStringWidget } from '@/composables/widgets/useStringWidget'
import { useStringWidgetVue } from '@/composables/widgets/useStringWidgetVue'
import { t } from '@/i18n'
import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration'
import type { InputSpec as InputSpecV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import { useSettingStore } from '@/stores/settingStore'
import type { ComfyApp } from './app'
import './domWidget'
import './errorNodeWidgets'
export type ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpecV2
) => IBaseWidget
import type { ComfyWidgetConstructorV2 } from './widgetTypes'
export type ComfyWidgetConstructor = (
node: LGraphNode,
@@ -283,11 +281,18 @@ export function addValueControlWidgets(
}
export const ComfyWidgets: Record<string, ComfyWidgetConstructor> = {
INT: transformWidgetConstructorV2ToV1(useIntWidget()),
FLOAT: transformWidgetConstructorV2ToV1(useFloatWidget()),
INT: transformWidgetConstructorV2ToV1(useBadgedNumberInput({ mode: 'int' })),
FLOAT: transformWidgetConstructorV2ToV1(
useBadgedNumberInput({ mode: 'float' })
),
BOOLEAN: transformWidgetConstructorV2ToV1(useBooleanWidget()),
STRING: transformWidgetConstructorV2ToV1(useStringWidget()),
STRING: transformWidgetConstructorV2ToV1(useStringWidgetVue()),
STRING_DOM: transformWidgetConstructorV2ToV1(useStringWidget()), // Fallback to DOM-based implementation
MARKDOWN: transformWidgetConstructorV2ToV1(useMarkdownWidget()),
COMBO: transformWidgetConstructorV2ToV1(useComboWidget()),
IMAGEUPLOAD: useImageUploadWidget()
COLOR: transformWidgetConstructorV2ToV1(useColorPickerWidget()),
IMAGEUPLOAD: useImageUploadMediaWidget(),
MEDIA_LOADER: transformWidgetConstructorV2ToV1(useMediaLoaderWidget()),
IMAGEPREVIEW: transformWidgetConstructorV2ToV1(useImagePreviewWidget()),
BADGED_NUMBER: transformWidgetConstructorV2ToV1(useBadgedNumberInput())
}

View File

@@ -552,7 +552,13 @@ export const useLitegraphService = () => {
showAnimatedPreview(this)
} else {
removeAnimatedPreview(this)
showCanvasImagePreview(this)
// Only show canvas image preview if we don't already have a Vue image preview widget
const hasVueImagePreview = this.widgets?.some(
(w) => w.name === '$$node-image-preview' || w.type === 'IMAGEPREVIEW'
)
if (!hasVueImagePreview) {
showCanvasImagePreview(this)
}
}
}

View File

@@ -0,0 +1,55 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { describe, expect, it, vi } from 'vitest'
import { useImagePreviewWidget } from '@/composables/widgets/useImagePreviewWidget'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
// Mock dependencies
vi.mock('@/scripts/domWidget', () => ({
ComponentWidgetImpl: vi.fn().mockImplementation(() => ({
name: 'test-widget',
value: ''
})),
addWidget: vi.fn()
}))
describe('useImagePreviewWidget', () => {
const mockNode = {
id: 'test-node',
widgets: []
} as unknown as LGraphNode
const mockInputSpec: InputSpec = {
name: 'image_preview',
type: 'IMAGEPREVIEW',
allow_batch: true,
image_folder: 'input'
}
it('creates widget constructor with default options', () => {
const constructor = useImagePreviewWidget()
expect(constructor).toBeDefined()
expect(typeof constructor).toBe('function')
})
it('creates widget with custom default value', () => {
const constructor = useImagePreviewWidget({
defaultValue: 'test-image.png'
})
expect(constructor).toBeDefined()
})
it('creates widget with array default value for batch mode', () => {
const constructor = useImagePreviewWidget({
defaultValue: ['image1.png', 'image2.png']
})
expect(constructor).toBeDefined()
})
it('calls constructor with node and inputSpec', () => {
const constructor = useImagePreviewWidget()
const widget = constructor(mockNode, mockInputSpec)
expect(widget).toBeDefined()
})
})

View File

@@ -0,0 +1,108 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useMediaLoaderWidget } from '@/composables/widgets/useMediaLoaderWidget'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
// Mock dependencies
vi.mock('@/scripts/domWidget', () => ({
ComponentWidgetImpl: class MockComponentWidgetImpl {
node: any
name: string
component: any
inputSpec: any
props: any
options: any
constructor(config: any) {
this.node = config.node
this.name = config.name
this.component = config.component
this.inputSpec = config.inputSpec
this.props = config.props
this.options = config.options
}
},
addWidget: vi.fn()
}))
vi.mock('@/components/graph/widgets/MediaLoaderWidget.vue', () => ({
default: {}
}))
describe('useMediaLoaderWidget', () => {
let mockNode: LGraphNode
let mockInputSpec: InputSpec
beforeEach(() => {
mockNode = {
id: 1,
widgets: []
} as unknown as LGraphNode
mockInputSpec = {
name: 'test_media_loader',
type: 'MEDIA_LOADER'
}
})
it('creates widget constructor with default options', () => {
const constructor = useMediaLoaderWidget()
expect(constructor).toBeInstanceOf(Function)
})
it('creates widget with custom options', () => {
const onFilesSelected = vi.fn()
const constructor = useMediaLoaderWidget({
defaultValue: ['test.jpg'],
minHeight: 120,
accept: 'image/*',
onFilesSelected
})
const widget = constructor(mockNode, mockInputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe('test_media_loader')
expect((widget.options as any)?.getValue()).toEqual(['test.jpg'])
expect((widget.options as any)?.getMinHeight()).toBe(128) // 120 + 8 padding
expect((widget.options as any)?.onFilesSelected).toBe(onFilesSelected)
})
it('handles value setting with validation', () => {
const constructor = useMediaLoaderWidget()
const widget = constructor(mockNode, mockInputSpec)
// Test valid array
;(widget.options as any)?.setValue(['file1.jpg', 'file2.png'])
expect((widget.options as any)?.getValue()).toEqual([
'file1.jpg',
'file2.png'
])
// Test invalid value conversion
;(widget.options as any)?.setValue('invalid' as any)
expect((widget.options as any)?.getValue()).toEqual([])
})
it('sets correct minimum height with padding', () => {
const constructor = useMediaLoaderWidget({ minHeight: 150 })
const widget = constructor(mockNode, mockInputSpec)
expect((widget.options as any)?.getMinHeight()).toBe(158) // 150 + 8 padding
})
it('uses default minimum height when not specified', () => {
const constructor = useMediaLoaderWidget()
const widget = constructor(mockNode, mockInputSpec)
expect((widget.options as any)?.getMinHeight()).toBe(108) // 100 + 8 padding
})
it('passes accept prop to widget', () => {
const constructor = useMediaLoaderWidget({ accept: 'video/*' })
const widget = constructor(mockNode, mockInputSpec)
expect((widget as any).props?.accept).toBe('video/*')
})
})

View File

@@ -0,0 +1,69 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { describe, expect, it, vi } from 'vitest'
import { useNodeImagePreview } from '@/composables/node/useNodeImagePreview'
// Mock dependencies
vi.mock('@/composables/widgets/useImagePreviewWidget', () => ({
useImagePreviewWidget: vi.fn(() =>
vi.fn(() => ({
name: '$$node-image-preview',
value: '',
onRemove: vi.fn()
}))
)
}))
describe('useNodeImagePreview', () => {
const mockNode = {
id: 'test-node',
widgets: [],
setDirtyCanvas: vi.fn()
} as unknown as LGraphNode
it('provides showImagePreview and removeImagePreview functions', () => {
const { showImagePreview, removeImagePreview } = useNodeImagePreview()
expect(showImagePreview).toBeDefined()
expect(removeImagePreview).toBeDefined()
expect(typeof showImagePreview).toBe('function')
expect(typeof removeImagePreview).toBe('function')
})
it('shows image preview for single image', () => {
const { showImagePreview } = useNodeImagePreview()
showImagePreview(mockNode, 'test-image.png')
expect(mockNode.setDirtyCanvas).toHaveBeenCalledWith(true)
})
it('shows image preview for multiple images', () => {
const { showImagePreview } = useNodeImagePreview()
showImagePreview(mockNode, ['image1.png', 'image2.png'], {
allow_batch: true
})
expect(mockNode.setDirtyCanvas).toHaveBeenCalledWith(true)
})
it('removes image preview widget', () => {
const mockWidget = {
name: '$$node-image-preview',
onRemove: vi.fn()
}
const nodeWithWidget = {
...mockNode,
widgets: [mockWidget]
} as unknown as LGraphNode
const { removeImagePreview } = useNodeImagePreview()
removeImagePreview(nodeWithWidget)
expect(mockWidget.onRemove).toHaveBeenCalled()
expect(nodeWithWidget.widgets).toHaveLength(0)
})
})

View File

@@ -0,0 +1,114 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useNodeMediaUpload } from '@/composables/node/useNodeMediaUpload'
// Mock dependencies
vi.mock('@/composables/widgets/useMediaLoaderWidget', () => ({
useMediaLoaderWidget: vi.fn(() =>
vi.fn(() => ({
name: '$$node-media-loader',
options: {
onFilesSelected: null
}
}))
)
}))
vi.mock('@/composables/node/useNodeImageUpload', () => ({
useNodeImageUpload: vi.fn(() => ({
handleUpload: vi.fn()
}))
}))
describe('useNodeMediaUpload', () => {
let mockNode: LGraphNode
beforeEach(() => {
mockNode = {
id: 1,
widgets: [],
setDirtyCanvas: vi.fn()
} as unknown as LGraphNode
})
it('creates composable with required methods', () => {
const { showMediaLoader, removeMediaLoader, addMediaLoaderWidget } =
useNodeMediaUpload()
expect(showMediaLoader).toBeInstanceOf(Function)
expect(removeMediaLoader).toBeInstanceOf(Function)
expect(addMediaLoaderWidget).toBeInstanceOf(Function)
})
it('shows media loader widget with options', () => {
const { showMediaLoader } = useNodeMediaUpload()
const options = {
fileFilter: (file: File) => file.type.startsWith('image/'),
onUploadComplete: vi.fn(),
allow_batch: true,
accept: 'image/*'
}
const widget = showMediaLoader(mockNode, options)
expect(widget).toBeDefined()
expect(widget.name).toBe('$$node-media-loader')
expect(mockNode.setDirtyCanvas).toHaveBeenCalledWith(true)
})
it('removes media loader widget from node', () => {
const { showMediaLoader, removeMediaLoader } = useNodeMediaUpload()
const options = {
fileFilter: () => true,
onUploadComplete: vi.fn()
}
// Add widget
showMediaLoader(mockNode, options)
mockNode.widgets = [
{
name: '$$node-media-loader',
onRemove: vi.fn()
}
] as any
// Remove widget
removeMediaLoader(mockNode)
expect(mockNode.widgets).toHaveLength(0)
})
it('handles node without widgets gracefully', () => {
const { removeMediaLoader } = useNodeMediaUpload()
const nodeWithoutWidgets = { id: 1 } as LGraphNode
expect(() => removeMediaLoader(nodeWithoutWidgets)).not.toThrow()
})
it('does not remove non-matching widgets', () => {
const { removeMediaLoader } = useNodeMediaUpload()
const otherWidget = { name: 'other-widget' }
mockNode.widgets! = [otherWidget] as any
removeMediaLoader(mockNode)
expect(mockNode.widgets).toHaveLength(1)
expect(mockNode.widgets![0]).toBe(otherWidget)
})
it('calls widget onRemove when removing', () => {
const { removeMediaLoader } = useNodeMediaUpload()
const onRemove = vi.fn()
mockNode.widgets! = [
{
name: '$$node-media-loader',
onRemove
}
] as any
removeMediaLoader(mockNode)
expect(onRemove).toHaveBeenCalled()
})
})

View File

@@ -0,0 +1,93 @@
import { LGraphNode } from '@comfyorg/litegraph'
import { describe, expect, it } from 'vitest'
import { useStringWidgetVue } from '@/composables/widgets/useStringWidgetVue'
import type { StringInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
describe('useStringWidgetVue', () => {
it('creates widget constructor with correct default value', () => {
const constructor = useStringWidgetVue({ defaultValue: 'test' })
expect(constructor).toBeDefined()
expect(typeof constructor).toBe('function')
})
it('creates widget for single-line string input', () => {
const constructor = useStringWidgetVue()
const node = new LGraphNode('test')
const inputSpec: StringInputSpec = {
type: 'STRING',
name: 'test_input',
default: 'default_value',
placeholder: 'Enter text...'
}
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe('test_input')
expect(widget.value).toBe('default_value')
})
it('creates widget for multiline string input', () => {
const constructor = useStringWidgetVue()
const node = new LGraphNode('test')
const inputSpec: StringInputSpec = {
type: 'STRING',
name: 'multiline_input',
default: 'default\nvalue',
placeholder: 'Enter multiline text...',
multiline: true
}
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe('multiline_input')
expect(widget.value).toBe('default\nvalue')
})
it('handles placeholder fallback correctly', () => {
const constructor = useStringWidgetVue()
const node = new LGraphNode('test')
const inputSpec: StringInputSpec = {
type: 'STRING',
name: 'no_placeholder_input',
default: 'default_value'
}
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe('no_placeholder_input')
expect(widget.value).toBe('default_value')
})
it('supports dynamic prompts configuration', () => {
const constructor = useStringWidgetVue()
const node = new LGraphNode('test')
const inputSpec: StringInputSpec = {
type: 'STRING',
name: 'dynamic_input',
default: 'value',
dynamicPrompts: true
}
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.dynamicPrompts).toBe(true)
})
it('throws error for invalid input spec', () => {
const constructor = useStringWidgetVue()
const node = new LGraphNode('test')
const invalidInputSpec = {
type: 'INT',
name: 'invalid_input'
} as any
expect(() => constructor(node, invalidInputSpec)).toThrow(
'Invalid input data'
)
})
})

View File

@@ -0,0 +1,73 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { describe, expect, it, vi } from 'vitest'
import { useBadgedNumberInput } from '@/composables/widgets/useBadgedNumberInput'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
// Mock dependencies
vi.mock('@/scripts/domWidget', () => ({
ComponentWidgetImpl: vi.fn().mockImplementation((config) => ({
...config,
value: config.options.getValue(),
setValue: config.options.setValue,
options: config.options,
props: config.props
})),
addWidget: vi.fn()
}))
describe('useBadgedNumberInput', () => {
const createMockNode = (): LGraphNode =>
({
id: 1,
title: 'Test Node',
widgets: [],
addWidget: vi.fn()
}) as any
const createInputSpec = (overrides: Partial<InputSpec> = {}): InputSpec => ({
name: 'test_input',
type: 'number',
...overrides
})
it('creates widget constructor with default options', () => {
const constructor = useBadgedNumberInput()
expect(constructor).toBeDefined()
expect(typeof constructor).toBe('function')
})
it('creates widget with default options', () => {
const constructor = useBadgedNumberInput()
const node = createMockNode()
const inputSpec = createInputSpec()
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe(inputSpec.name)
})
it('creates widget with custom badge state', () => {
const constructor = useBadgedNumberInput({ badgeState: 'random' })
const node = createMockNode()
const inputSpec = createInputSpec()
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
// Widget is created with the props, but accessing them requires the mock structure
expect((widget as any).props.badgeState).toBe('random')
})
it('creates widget with disabled state', () => {
const constructor = useBadgedNumberInput({ disabled: true })
const node = createMockNode()
const inputSpec = createInputSpec()
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect((widget as any).props.disabled).toBe(true)
})
})

View File

@@ -0,0 +1,80 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { describe, expect, it, vi } from 'vitest'
import { useColorPickerWidget } from '@/composables/widgets/useColorPickerWidget'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
// Mock dependencies
vi.mock('@/scripts/domWidget', () => ({
ComponentWidgetImpl: vi.fn().mockImplementation((config) => ({
...config,
name: config.name,
options: {
...config.options,
getValue: config.options.getValue,
setValue: config.options.setValue,
getMinHeight: config.options.getMinHeight
}
})),
addWidget: vi.fn()
}))
describe('useColorPickerWidget', () => {
const createMockNode = (): LGraphNode =>
({
id: 1,
title: 'Test Node',
widgets: [],
addWidget: vi.fn()
}) as any
const createInputSpec = (overrides: Partial<InputSpec> = {}): InputSpec => ({
name: 'color',
type: 'COLOR',
...overrides
})
it('creates widget constructor with default options', () => {
const constructor = useColorPickerWidget()
expect(constructor).toBeDefined()
expect(typeof constructor).toBe('function')
})
it('creates widget with default options', () => {
const constructor = useColorPickerWidget()
const node = createMockNode()
const inputSpec = createInputSpec()
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe(inputSpec.name)
})
it('creates widget with custom default value', () => {
const constructor = useColorPickerWidget({
defaultValue: '#00ff00'
})
const node = createMockNode()
const inputSpec = createInputSpec()
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe(inputSpec.name)
})
it('creates widget with custom options', () => {
const constructor = useColorPickerWidget({
minHeight: 60,
serialize: false
})
const node = createMockNode()
const inputSpec = createInputSpec()
const widget = constructor(node, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe(inputSpec.name)
})
})

View File

@@ -0,0 +1,109 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useDropdownComboWidget } from '@/composables/widgets/useDropdownComboWidget'
import type { ComboInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
// Mock the domWidget store and related dependencies
vi.mock('@/scripts/domWidget', () => ({
ComponentWidgetImpl: vi.fn().mockImplementation((config) => ({
name: config.name,
value: '',
options: config.options
})),
addWidget: vi.fn()
}))
// Mock the scripts/widgets for control widgets
vi.mock('@/scripts/widgets', () => ({
addValueControlWidgets: vi.fn().mockReturnValue([])
}))
// Mock the remote widget functionality
vi.mock('@/composables/widgets/useRemoteWidget', () => ({
useRemoteWidget: vi.fn(() => ({
addRefreshButton: vi.fn()
}))
}))
const createMockNode = () => {
return {
widgets: [],
graph: {
setDirtyCanvas: vi.fn()
},
addWidget: vi.fn(),
addCustomWidget: vi.fn(),
setDirtyCanvas: vi.fn()
} as unknown as LGraphNode
}
describe('useDropdownComboWidget', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('creates widget constructor successfully', () => {
const constructor = useDropdownComboWidget()
expect(constructor).toBeDefined()
expect(typeof constructor).toBe('function')
})
it('widget constructor handles input spec correctly', () => {
const constructor = useDropdownComboWidget()
const mockNode = createMockNode()
const inputSpec: ComboInputSpec = {
name: 'test_dropdown',
type: 'COMBO',
options: ['option1', 'option2', 'option3']
}
const widget = constructor(mockNode, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe('test_dropdown')
})
it('widget constructor accepts default value option', () => {
const constructor = useDropdownComboWidget({ defaultValue: 'custom' })
expect(constructor).toBeDefined()
expect(typeof constructor).toBe('function')
})
it('handles remote widgets correctly', () => {
const constructor = useDropdownComboWidget()
const mockNode = createMockNode()
const inputSpec: ComboInputSpec = {
name: 'remote_dropdown',
type: 'COMBO',
options: [],
remote: {
route: '/api/options',
refresh_button: true
}
}
const widget = constructor(mockNode, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe('remote_dropdown')
})
it('handles control_after_generate widgets correctly', () => {
const constructor = useDropdownComboWidget()
const mockNode = createMockNode()
const inputSpec: ComboInputSpec = {
name: 'control_dropdown',
type: 'COMBO',
options: ['option1', 'option2'],
control_after_generate: true
}
const widget = constructor(mockNode, inputSpec)
expect(widget).toBeDefined()
expect(widget.name).toBe('control_dropdown')
})
})

View File

@@ -1,39 +1,89 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useComboWidget } from '@/composables/widgets/useComboWidget'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComboInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
vi.mock('@/scripts/widgets', () => ({
addValueControlWidgets: vi.fn()
// Mock the dropdown combo widget since COMBO now uses it
vi.mock('@/composables/widgets/useDropdownComboWidget', () => ({
useDropdownComboWidget: vi.fn(() =>
vi.fn().mockReturnValue({ name: 'mockWidget' })
)
}))
// Mock the domWidget store and related dependencies
vi.mock('@/scripts/domWidget', () => ({
ComponentWidgetImpl: vi.fn().mockImplementation((config) => ({
name: config.name,
value: [],
options: config.options
})),
addWidget: vi.fn()
}))
const createMockNode = () => {
return {
widgets: [],
graph: {
setDirtyCanvas: vi.fn()
},
addWidget: vi.fn(),
addCustomWidget: vi.fn(),
setDirtyCanvas: vi.fn()
} as unknown as LGraphNode
}
describe('useComboWidget', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('should handle undefined spec', () => {
it('should delegate single-selection combo to dropdown widget', () => {
const constructor = useComboWidget()
const mockNode = {
addWidget: vi.fn().mockReturnValue({ options: {} } as any)
}
const mockNode = createMockNode()
const inputSpec: InputSpec = {
const inputSpec: ComboInputSpec = {
type: 'COMBO',
name: 'inputName'
name: 'inputName',
options: ['option1', 'option2']
}
const widget = constructor(mockNode as any, inputSpec)
const widget = constructor(mockNode, inputSpec)
expect(mockNode.addWidget).toHaveBeenCalledWith(
'combo',
'inputName',
undefined, // default value
expect.any(Function), // callback
expect.objectContaining({
values: []
})
// Should create a widget (delegated to dropdown widget)
expect(widget).toBeDefined()
expect(widget.name).toBe('mockWidget')
})
it('should use multi-select widget for multi_select combo', () => {
const constructor = useComboWidget()
const mockNode = createMockNode()
const inputSpec: ComboInputSpec = {
type: 'COMBO',
name: 'multiSelectInput',
options: ['option1', 'option2'],
multi_select: { placeholder: 'Select multiple' }
}
const widget = constructor(mockNode, inputSpec)
// Should create a multi-select widget
expect(widget).toBeDefined()
expect(widget.name).toBe('multiSelectInput')
})
it('should handle invalid input spec', () => {
const constructor = useComboWidget()
const mockNode = createMockNode()
const invalidSpec = {
type: 'NOT_COMBO',
name: 'invalidInput'
} as any
expect(() => constructor(mockNode, invalidSpec)).toThrow(
'Invalid input data'
)
expect(widget).toEqual({ options: {} })
})
})

View File

@@ -0,0 +1,919 @@
{
"version": "4.2.5",
"generatedAt": "2025-06-09T04:50:20.566Z",
"totalComponents": 147,
"categories": {
"Panel": [
{
"name": "accordion",
"description": "Groups a collection of contents in tabs",
"documentationUrl": "https://primevue.org/accordion/",
"pascalCase": "Accordion"
},
{
"name": "accordioncontent",
"description": "Content container for accordion panels",
"documentationUrl": "https://primevue.org/accordion/",
"pascalCase": "Accordioncontent"
},
{
"name": "accordionheader",
"description": "Header section for accordion panels",
"documentationUrl": "https://primevue.org/accordion/",
"pascalCase": "Accordionheader"
},
{
"name": "accordionpanel",
"description": "Individual panel in an accordion",
"documentationUrl": "https://primevue.org/accordion/",
"pascalCase": "Accordionpanel"
},
{
"name": "accordiontab",
"description": "Legacy accordion tab component",
"documentationUrl": "https://primevue.org/accordion/",
"pascalCase": "Accordiontab"
},
{
"name": "card",
"description": "Flexible content container",
"documentationUrl": "https://primevue.org/card/",
"pascalCase": "Card"
},
{
"name": "deferredcontent",
"description": "Loads content on demand",
"documentationUrl": "https://primevue.org/deferredcontent/",
"pascalCase": "Deferredcontent"
},
{
"name": "divider",
"description": "Separator component",
"documentationUrl": "https://primevue.org/divider/",
"pascalCase": "Divider"
},
{
"name": "fieldset",
"description": "Groups related form elements",
"documentationUrl": "https://primevue.org/fieldset/",
"pascalCase": "Fieldset"
},
{
"name": "panel",
"description": "Collapsible content container",
"documentationUrl": "https://primevue.org/panel/",
"pascalCase": "Panel"
},
{
"name": "scrollpanel",
"description": "Scrollable content container",
"documentationUrl": "https://primevue.org/scrollpanel/",
"pascalCase": "Scrollpanel"
},
{
"name": "splitter",
"description": "Resizable split panels",
"documentationUrl": "https://primevue.org/splitter/",
"pascalCase": "Splitter"
},
{
"name": "splitterpanel",
"description": "Panel within splitter",
"documentationUrl": "https://primevue.org/splitter/",
"pascalCase": "Splitterpanel"
},
{
"name": "tab",
"description": "Individual tab component",
"documentationUrl": "https://primevue.org/tabs/",
"pascalCase": "Tab"
},
{
"name": "tablist",
"description": "Container for tabs",
"documentationUrl": "https://primevue.org/tabs/",
"pascalCase": "Tablist"
},
{
"name": "tabpanel",
"description": "Content panel for tabs",
"documentationUrl": "https://primevue.org/tabs/",
"pascalCase": "Tabpanel"
},
{
"name": "tabpanels",
"description": "Container for tab panels",
"documentationUrl": "https://primevue.org/tabs/",
"pascalCase": "Tabpanels"
},
{
"name": "tabs",
"description": "Modern tab container",
"documentationUrl": "https://primevue.org/tabs/",
"pascalCase": "Tabs"
},
{
"name": "tabview",
"description": "Legacy tabbed interface",
"documentationUrl": "https://primevue.org/tabview/",
"pascalCase": "Tabview"
}
],
"Directives": [
{
"name": "animateonscroll",
"description": "Directive to apply animations when element becomes visible",
"documentationUrl": "https://primevue.org/animateonscroll/",
"pascalCase": "Animateonscroll"
},
{
"name": "badgedirective",
"description": "Directive to add badges to any element",
"documentationUrl": "https://primevue.org/badge/",
"pascalCase": "Badgedirective"
},
{
"name": "focustrap",
"description": "Directive to trap focus within element",
"documentationUrl": "https://primevue.org/focustrap/",
"pascalCase": "Focustrap"
},
{
"name": "keyfilter",
"description": "Directive to filter keyboard input",
"documentationUrl": "https://primevue.org/keyfilter/",
"pascalCase": "Keyfilter"
},
{
"name": "ripple",
"description": "Directive for material design ripple effect",
"documentationUrl": "https://primevue.org/ripple/",
"pascalCase": "Ripple"
},
{
"name": "styleclass",
"description": "Directive for dynamic styling",
"documentationUrl": "https://primevue.org/styleclass/",
"pascalCase": "Styleclass"
}
],
"Form": [
{
"name": "autocomplete",
"description": "Provides filtered suggestions while typing input, supports multiple selection and custom item templates",
"documentationUrl": "https://primevue.org/autocomplete/",
"pascalCase": "Autocomplete"
},
{
"name": "calendar",
"description": "Input component for date selection (legacy)",
"documentationUrl": "https://primevue.org/calendar/",
"pascalCase": "Calendar"
},
{
"name": "cascadeselect",
"description": "Nested dropdown selection component",
"documentationUrl": "https://primevue.org/cascadeselect/",
"pascalCase": "Cascadeselect"
},
{
"name": "checkbox",
"description": "Binary selection component",
"documentationUrl": "https://primevue.org/checkbox/",
"pascalCase": "Checkbox"
},
{
"name": "checkboxgroup",
"description": "Groups multiple checkboxes",
"documentationUrl": "https://primevue.org/checkbox/",
"pascalCase": "Checkboxgroup"
},
{
"name": "chips",
"description": "Input component for entering multiple values",
"documentationUrl": "https://primevue.org/chips/",
"pascalCase": "Chips"
},
{
"name": "colorpicker",
"description": "Input component for color selection",
"documentationUrl": "https://primevue.org/colorpicker/",
"pascalCase": "Colorpicker"
},
{
"name": "datepicker",
"description": "Input component for date and time selection with calendar popup, supports date ranges and custom formatting",
"documentationUrl": "https://primevue.org/datepicker/",
"pascalCase": "Datepicker"
},
{
"name": "dropdown",
"description": "Single selection dropdown",
"documentationUrl": "https://primevue.org/dropdown/",
"pascalCase": "Dropdown"
},
{
"name": "editor",
"description": "Rich text editor component",
"documentationUrl": "https://primevue.org/editor/",
"pascalCase": "Editor"
},
{
"name": "floatlabel",
"description": "Floating label for input components",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Floatlabel"
},
{
"name": "iconfield",
"description": "Input field with icon",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Iconfield"
},
{
"name": "iftalabel",
"description": "Input field with top-aligned label",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Iftalabel"
},
{
"name": "inputchips",
"description": "Multiple input values as chips",
"documentationUrl": "https://primevue.org/chips/",
"pascalCase": "Inputchips"
},
{
"name": "inputgroup",
"description": "Groups input elements",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Inputgroup"
},
{
"name": "inputgroupaddon",
"description": "Addon for input groups",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Inputgroupaddon"
},
{
"name": "inputicon",
"description": "Icon for input components",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Inputicon"
},
{
"name": "inputmask",
"description": "Input with format masking",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Inputmask"
},
{
"name": "inputnumber",
"description": "Numeric input with spinner",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Inputnumber"
},
{
"name": "inputotp",
"description": "One-time password input",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Inputotp"
},
{
"name": "inputswitch",
"description": "Binary switch component",
"documentationUrl": "https://primevue.org/toggleswitch/",
"pascalCase": "Inputswitch"
},
{
"name": "inputtext",
"description": "Text input component",
"documentationUrl": "https://primevue.org/inputtext/",
"pascalCase": "Inputtext"
},
{
"name": "knob",
"description": "Circular input component",
"documentationUrl": "https://primevue.org/knob/",
"pascalCase": "Knob"
},
{
"name": "listbox",
"description": "Selection component with list interface",
"documentationUrl": "https://primevue.org/listbox/",
"pascalCase": "Listbox"
},
{
"name": "multiselect",
"description": "Multiple selection dropdown",
"documentationUrl": "https://primevue.org/multiselect/",
"pascalCase": "Multiselect"
},
{
"name": "password",
"description": "Password input with strength meter",
"documentationUrl": "https://primevue.org/password/",
"pascalCase": "Password"
},
{
"name": "radiobutton",
"description": "Single selection from group",
"documentationUrl": "https://primevue.org/radiobutton/",
"pascalCase": "Radiobutton"
},
{
"name": "radiobuttongroup",
"description": "Groups radio buttons",
"documentationUrl": "https://primevue.org/radiobutton/",
"pascalCase": "Radiobuttongroup"
},
{
"name": "rating",
"description": "Star rating input component",
"documentationUrl": "https://primevue.org/rating/",
"pascalCase": "Rating"
},
{
"name": "select",
"description": "Modern dropdown selection",
"documentationUrl": "https://primevue.org/select/",
"pascalCase": "Select"
},
{
"name": "selectbutton",
"description": "Button-style selection component",
"documentationUrl": "https://primevue.org/selectbutton/",
"pascalCase": "Selectbutton"
},
{
"name": "slider",
"description": "Range selection component",
"documentationUrl": "https://primevue.org/slider/",
"pascalCase": "Slider"
},
{
"name": "textarea",
"description": "Multi-line text input",
"documentationUrl": "https://primevue.org/textarea/",
"pascalCase": "Textarea"
},
{
"name": "togglebutton",
"description": "Two-state button component",
"documentationUrl": "https://primevue.org/togglebutton/",
"pascalCase": "Togglebutton"
},
{
"name": "toggleswitch",
"description": "Switch component for binary state",
"documentationUrl": "https://primevue.org/toggleswitch/",
"pascalCase": "Toggleswitch"
},
{
"name": "treeselect",
"description": "Tree-structured selection",
"documentationUrl": "https://primevue.org/treeselect/",
"pascalCase": "Treeselect"
}
],
"Misc": [
{
"name": "avatar",
"description": "Represents people using icons, labels and images",
"documentationUrl": "https://primevue.org/avatar/",
"pascalCase": "Avatar"
},
{
"name": "avatargroup",
"description": "Groups multiple avatars together",
"documentationUrl": "https://primevue.org/avatar/",
"pascalCase": "Avatargroup"
},
{
"name": "badge",
"description": "Small numeric indicator for other components",
"documentationUrl": "https://primevue.org/badge/",
"pascalCase": "Badge"
},
{
"name": "blockui",
"description": "Blocks user interaction with page elements",
"documentationUrl": "https://primevue.org/blockui/",
"pascalCase": "Blockui"
},
{
"name": "chip",
"description": "Compact element representing input, attribute or action",
"documentationUrl": "https://primevue.org/chip/",
"pascalCase": "Chip"
},
{
"name": "inplace",
"description": "Editable content in place",
"documentationUrl": "https://primevue.org/inplace/",
"pascalCase": "Inplace"
},
{
"name": "metergroup",
"description": "Displays multiple meter values",
"documentationUrl": "https://primevue.org/metergroup/",
"pascalCase": "Metergroup"
},
{
"name": "overlaybadge",
"description": "Badge overlay for components",
"documentationUrl": "https://primevue.org/badge/",
"pascalCase": "Overlaybadge"
},
{
"name": "progressbar",
"description": "Progress indication component",
"documentationUrl": "https://primevue.org/progressbar/",
"pascalCase": "Progressbar"
},
{
"name": "progressspinner",
"description": "Loading spinner component",
"documentationUrl": "https://primevue.org/progressspinner/",
"pascalCase": "Progressspinner"
},
{
"name": "skeleton",
"description": "Placeholder for loading content",
"documentationUrl": "https://primevue.org/skeleton/",
"pascalCase": "Skeleton"
},
{
"name": "tag",
"description": "Label component for categorization",
"documentationUrl": "https://primevue.org/tag/",
"pascalCase": "Tag"
},
{
"name": "terminal",
"description": "Command line interface",
"documentationUrl": "https://primevue.org/terminal/",
"pascalCase": "Terminal"
}
],
"Menu": [
{
"name": "breadcrumb",
"description": "Navigation component showing current page location",
"documentationUrl": "https://primevue.org/breadcrumb/",
"pascalCase": "Breadcrumb"
},
{
"name": "contextmenu",
"description": "Right-click context menu",
"documentationUrl": "https://primevue.org/contextmenu/",
"pascalCase": "Contextmenu"
},
{
"name": "dock",
"description": "Dock layout with expandable items",
"documentationUrl": "https://primevue.org/dock/",
"pascalCase": "Dock"
},
{
"name": "megamenu",
"description": "Navigation with grouped menu items",
"documentationUrl": "https://primevue.org/megamenu/",
"pascalCase": "Megamenu"
},
{
"name": "menu",
"description": "Navigation menu component",
"documentationUrl": "https://primevue.org/menu/",
"pascalCase": "Menu"
},
{
"name": "menubar",
"description": "Horizontal navigation menu",
"documentationUrl": "https://primevue.org/menubar/",
"pascalCase": "Menubar"
},
{
"name": "panelmenu",
"description": "Vertical navigation menu",
"documentationUrl": "https://primevue.org/panelmenu/",
"pascalCase": "Panelmenu"
},
{
"name": "steps",
"description": "Step-by-step navigation",
"documentationUrl": "https://primevue.org/steps/",
"pascalCase": "Steps"
},
{
"name": "tabmenu",
"description": "Menu styled as tabs",
"documentationUrl": "https://primevue.org/tabmenu/",
"pascalCase": "Tabmenu"
},
{
"name": "tieredmenu",
"description": "Hierarchical menu component",
"documentationUrl": "https://primevue.org/tieredmenu/",
"pascalCase": "Tieredmenu"
}
],
"Button": [
{
"name": "button",
"description": "Standard button component with various styles and severity levels, supports icons and loading states",
"documentationUrl": "https://primevue.org/button/",
"pascalCase": "Button"
},
{
"name": "buttongroup",
"description": "Groups multiple buttons together as a cohesive unit with shared styling",
"documentationUrl": "https://primevue.org/button/",
"pascalCase": "Buttongroup"
},
{
"name": "speeddial",
"description": "Floating action button with expandable menu items, supports radial and linear layouts",
"documentationUrl": "https://primevue.org/speeddial/",
"pascalCase": "Speeddial"
},
{
"name": "splitbutton",
"description": "Button with attached dropdown menu for additional actions",
"documentationUrl": "https://primevue.org/splitbutton/",
"pascalCase": "Splitbutton"
}
],
"Data": [
{
"name": "carousel",
"description": "Displays content in a rotating slideshow",
"documentationUrl": "https://primevue.org/carousel/",
"pascalCase": "Carousel"
},
{
"name": "datatable",
"description": "Advanced data table with sorting, filtering, pagination, row selection, and column resizing",
"documentationUrl": "https://primevue.org/datatable/",
"pascalCase": "Datatable"
},
{
"name": "dataview",
"description": "Displays data in list layout",
"documentationUrl": "https://primevue.org/dataview/",
"pascalCase": "Dataview"
},
{
"name": "orderlist",
"description": "Reorderable list component",
"documentationUrl": "https://primevue.org/orderlist/",
"pascalCase": "Orderlist"
},
{
"name": "organizationchart",
"description": "Hierarchical organization display",
"documentationUrl": "https://primevue.org/organizationchart/",
"pascalCase": "Organizationchart"
},
{
"name": "paginator",
"description": "Navigation for paged data",
"documentationUrl": "https://primevue.org/paginator/",
"pascalCase": "Paginator"
},
{
"name": "picklist",
"description": "Dual list for item transfer",
"documentationUrl": "https://primevue.org/picklist/",
"pascalCase": "Picklist"
},
{
"name": "timeline",
"description": "Chronological event display",
"documentationUrl": "https://primevue.org/timeline/",
"pascalCase": "Timeline"
},
{
"name": "tree",
"description": "Hierarchical tree structure",
"documentationUrl": "https://primevue.org/tree/",
"pascalCase": "Tree"
},
{
"name": "treetable",
"description": "Table with tree structure",
"documentationUrl": "https://primevue.org/treetable/",
"pascalCase": "Treetable"
},
{
"name": "virtualscroller",
"description": "Virtual scrolling for large datasets",
"documentationUrl": "https://primevue.org/virtualscroller/",
"pascalCase": "Virtualscroller"
}
],
"Chart": [
{
"name": "chart",
"description": "Charts and graphs using Chart.js",
"documentationUrl": "https://primevue.org/chart/",
"pascalCase": "Chart"
}
],
"Utilities": [
{
"name": "column",
"description": "Table column component for DataTable",
"documentationUrl": "https://primevue.org/datatable/",
"pascalCase": "Column"
},
{
"name": "columngroup",
"description": "Groups table columns",
"documentationUrl": "https://primevue.org/datatable/",
"pascalCase": "Columngroup"
},
{
"name": "confirmationservice",
"description": "Service for programmatically displaying and managing confirmation dialogs",
"documentationUrl": "https://primevue.org/confirmdialog/",
"pascalCase": "Confirmationservice"
},
{
"name": "dialogservice",
"description": "Service for dynamic dialog creation",
"documentationUrl": "https://primevue.org/dialogservice/",
"pascalCase": "Dialogservice"
},
{
"name": "fluid",
"description": "Container with fluid width",
"documentationUrl": "https://primevue.org/fluid/",
"pascalCase": "Fluid"
},
{
"name": "portal",
"description": "Renders content in different DOM location",
"documentationUrl": "https://primevue.org/portal/",
"pascalCase": "Portal"
},
{
"name": "row",
"description": "Table row component",
"documentationUrl": "https://primevue.org/datatable/",
"pascalCase": "Row"
},
{
"name": "scrolltop",
"description": "Button to scroll to top",
"documentationUrl": "https://primevue.org/scrolltop/",
"pascalCase": "Scrolltop"
},
{
"name": "terminalservice",
"description": "Service for terminal component",
"documentationUrl": "https://primevue.org/terminal/",
"pascalCase": "Terminalservice"
},
{
"name": "useconfirm",
"description": "Composable for confirmation dialogs",
"documentationUrl": "https://primevue.org/confirmdialog/",
"pascalCase": "Useconfirm"
},
{
"name": "usedialog",
"description": "Composable for dynamic dialogs",
"documentationUrl": "https://primevue.org/dynamicdialog/",
"pascalCase": "Usedialog"
},
{
"name": "usestyle",
"description": "Composable for dynamic styling",
"documentationUrl": "https://primevue.org/usestyle/",
"pascalCase": "Usestyle"
},
{
"name": "usetoast",
"description": "Composable for toast notifications",
"documentationUrl": "https://primevue.org/toast/",
"pascalCase": "Usetoast"
}
],
"Uncategorized": [
{
"name": "config",
"description": "Configuration utility for global PrimeVue settings including theming, locale, and component options",
"documentationUrl": "https://primevue.org/config/",
"pascalCase": "Config"
},
{
"name": "confirmationeventbus",
"description": "Internal event bus system for managing confirmation dialog events and communication",
"documentationUrl": "https://primevue.org/confirmdialog/",
"pascalCase": "Confirmationeventbus"
},
{
"name": "confirmationoptions",
"description": "TypeScript interface definitions for confirmation dialog configuration options",
"documentationUrl": "https://primevue.org/confirmdialog/",
"pascalCase": "Confirmationoptions"
},
{
"name": "dynamicdialogeventbus",
"description": "Internal event bus system for managing dynamic dialog creation and communication",
"documentationUrl": "https://primevue.org/dynamicdialog/",
"pascalCase": "Dynamicdialogeventbus"
},
{
"name": "dynamicdialogoptions",
"description": "TypeScript interface definitions for dynamic dialog configuration options",
"documentationUrl": "https://primevue.org/dynamicdialog/",
"pascalCase": "Dynamicdialogoptions"
},
{
"name": "menuitem",
"description": "TypeScript interface definitions for menu item configuration shared across menu components",
"documentationUrl": "https://primevue.org/menuitem/",
"pascalCase": "Menuitem"
},
{
"name": "overlayeventbus",
"description": "Internal event bus system for managing overlay component events and communication",
"documentationUrl": "https://primevue.org/overlaypanel/",
"pascalCase": "Overlayeventbus"
},
{
"name": "passthrough",
"description": "Utility for customizing component styling and attributes through pass-through properties",
"documentationUrl": "https://primevue.org/passthrough/",
"pascalCase": "Passthrough"
},
{
"name": "toasteventbus",
"description": "Internal event bus system for managing toast notification events and communication",
"documentationUrl": "https://primevue.org/toast/",
"pascalCase": "Toasteventbus"
},
{
"name": "toastservice",
"description": "Service for programmatically displaying and managing toast notifications",
"documentationUrl": "https://primevue.org/toast/",
"pascalCase": "Toastservice"
},
{
"name": "toolbar",
"description": "Container for action buttons",
"documentationUrl": "https://primevue.org/toolbar/",
"pascalCase": "Toolbar"
},
{
"name": "treenode",
"description": "Individual node in tree",
"documentationUrl": "https://primevue.org/tree/",
"pascalCase": "Treenode"
}
],
"Overlay": [
{
"name": "confirmdialog",
"description": "Modal dialog for user confirmation",
"documentationUrl": "https://primevue.org/confirmdialog/",
"pascalCase": "Confirmdialog"
},
{
"name": "confirmpopup",
"description": "Popup for user confirmation",
"documentationUrl": "https://primevue.org/confirmdialog/",
"pascalCase": "Confirmpopup"
},
{
"name": "dialog",
"description": "Modal dialog component",
"documentationUrl": "https://primevue.org/dialog/",
"pascalCase": "Dialog"
},
{
"name": "drawer",
"description": "Sliding panel overlay",
"documentationUrl": "https://primevue.org/drawer/",
"pascalCase": "Drawer"
},
{
"name": "dynamicdialog",
"description": "Programmatically created dialogs",
"documentationUrl": "https://primevue.org/dynamicdialog/",
"pascalCase": "Dynamicdialog"
},
{
"name": "overlaypanel",
"description": "Overlay panel component",
"documentationUrl": "https://primevue.org/overlaypanel/",
"pascalCase": "Overlaypanel"
},
{
"name": "popover",
"description": "Overlay component triggered by user interaction",
"documentationUrl": "https://primevue.org/popover/",
"pascalCase": "Popover"
},
{
"name": "sidebar",
"description": "Side panel overlay",
"documentationUrl": "https://primevue.org/sidebar/",
"pascalCase": "Sidebar"
},
{
"name": "tooltip",
"description": "Informational popup on hover",
"documentationUrl": "https://primevue.org/tooltip/",
"pascalCase": "Tooltip"
}
],
"File": [
{
"name": "fileupload",
"description": "File upload component with drag-drop",
"documentationUrl": "https://primevue.org/fileupload/",
"pascalCase": "Fileupload"
}
],
"Media": [
{
"name": "galleria",
"description": "Image gallery with thumbnails",
"documentationUrl": "https://primevue.org/galleria/",
"pascalCase": "Galleria"
},
{
"name": "image",
"description": "Enhanced image component with preview",
"documentationUrl": "https://primevue.org/image/",
"pascalCase": "Image"
},
{
"name": "imagecompare",
"description": "Before/after image comparison slider",
"documentationUrl": "https://primevue.org/imagecompare/",
"pascalCase": "Imagecompare"
}
],
"Messages": [
{
"name": "inlinemessage",
"description": "Inline message display",
"documentationUrl": "https://primevue.org/inlinemessage/",
"pascalCase": "Inlinemessage"
},
{
"name": "message",
"description": "Message component for notifications",
"documentationUrl": "https://primevue.org/message/",
"pascalCase": "Message"
},
{
"name": "toast",
"description": "Temporary message notifications",
"documentationUrl": "https://primevue.org/toast/",
"pascalCase": "Toast"
}
],
"Stepper": [
{
"name": "step",
"description": "Individual step in stepper",
"documentationUrl": "https://primevue.org/stepper/",
"pascalCase": "Step"
},
{
"name": "stepitem",
"description": "Item within step",
"documentationUrl": "https://primevue.org/stepper/",
"pascalCase": "Stepitem"
},
{
"name": "steplist",
"description": "List of steps",
"documentationUrl": "https://primevue.org/stepper/",
"pascalCase": "Steplist"
},
{
"name": "steppanel",
"description": "Content panel for stepper",
"documentationUrl": "https://primevue.org/stepper/",
"pascalCase": "Steppanel"
},
{
"name": "steppanels",
"description": "Container for step panels",
"documentationUrl": "https://primevue.org/stepper/",
"pascalCase": "Steppanels"
},
{
"name": "stepper",
"description": "Multi-step process navigation",
"documentationUrl": "https://primevue.org/stepper/",
"pascalCase": "Stepper"
}
]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,552 @@
# Step-by-Step Guide: Converting Widgets to Vue Components in ComfyUI
## Overview
This guide explains how to convert existing DOM widgets or create new widgets using Vue components in ComfyUI. The Vue widget system provides better reactivity, type safety, and maintainability compared to traditional DOM manipulation.
## Prerequisites
- Understanding of Vue 3 Composition API
- Basic knowledge of TypeScript
- Familiarity with ComfyUI widget system
## Step 1: Create the Vue Component
Create a new Vue component in `src/components/graph/widgets/`:
```vue
<!-- src/components/graph/widgets/YourWidget.vue -->
<template>
<div class="your-widget-container">
<!-- Your widget UI here -->
<input
v-model="modelValue"
type="text"
class="w-full px-2 py-1 rounded"
/>
</div>
</template>
<script setup lang="ts">
import { defineModel, defineProps } from 'vue'
import type { ComponentWidget } from '@/types'
// Define two-way binding for the widget value
const modelValue = defineModel<string>({ required: true })
// Receive widget configuration
const { widget } = defineProps<{
widget: ComponentWidget<string>
}>()
// Access widget properties
const inputSpec = widget.inputSpec
const options = inputSpec.options || {}
// Add any logic necessary here to make a functional, feature-rich widget.
// You can use the vueuse library for helper functions.
// You can take liberty in things to add, as this is just a prototype.
</script>
<style scoped>
/* Use Tailwind classes in template, custom CSS here if needed */
</style>
```
## Step 2: Create the Widget Composables (Dual Pattern)
The Vue widget system uses a **dual composable pattern** for separation of concerns:
### 2a. Create the Widget Constructor Composable
Create the core widget constructor in `src/composables/widgets/`:
```typescript
// src/composables/widgets/useYourWidget.ts
import { ref } from 'vue'
import type { LGraphNode } from '@comfyorg/litegraph'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import YourWidget from '@/components/graph/widgets/YourWidget.vue'
const PADDING = 8
export const useYourWidget = (options: { defaultValue?: string } = {}) => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
// Initialize widget value
const widgetValue = ref<string>(options.defaultValue ?? '')
// Create the widget instance
const widget = new ComponentWidgetImpl<string>({
node,
name: inputSpec.name,
component: YourWidget,
inputSpec,
options: {
// Required: getter for widget value
getValue: () => widgetValue.value,
// Required: setter for widget value
setValue: (value: string) => {
widgetValue.value = value
},
// Optional: minimum height for the widget
getMinHeight: () => options.minHeight ?? 40 + PADDING,
// Optional: whether to serialize this widget's value
serialize: true,
// Optional: custom serialization
serializeValue: (value: string) => {
return { yourWidget: value }
}
}
})
// Register the widget with the node
addWidget(node, widget)
return widget
}
return widgetConstructor
}
```
### 2b. Create the Node-Level Logic Composable (When Needed)
**Only create this if your widget needs dynamic management** (showing/hiding widgets based on events, execution state, etc.). Most standard widgets only need the widget constructor composable.
For widgets that need node-level operations (like showing/hiding widgets dynamically), create a separate composable in `src/composables/node/`:
```typescript
// src/composables/node/useNodeYourWidget.ts
import type { LGraphNode } from '@comfyorg/litegraph'
import { useYourWidget } from '@/composables/widgets/useYourWidget'
const YOUR_WIDGET_NAME = '$$node-your-widget'
/**
* Composable for handling node-level operations for YourWidget
*/
export function useNodeYourWidget() {
const yourWidget = useYourWidget()
const findYourWidget = (node: LGraphNode) =>
node.widgets?.find((w) => w.name === YOUR_WIDGET_NAME)
const addYourWidget = (node: LGraphNode) =>
yourWidget(node, {
name: YOUR_WIDGET_NAME,
type: 'yourWidgetType'
})
/**
* Shows your widget for a node
* @param node The graph node to show the widget for
* @param value The value to set
*/
function showYourWidget(node: LGraphNode, value: string) {
const widget = findYourWidget(node) ?? addYourWidget(node)
widget.value = value
node.setDirtyCanvas?.(true)
}
/**
* Removes your widget from a node
* @param node The graph node to remove the widget from
*/
function removeYourWidget(node: LGraphNode) {
if (!node.widgets) return
const widgetIdx = node.widgets.findIndex(
(w) => w.name === YOUR_WIDGET_NAME
)
if (widgetIdx > -1) {
node.widgets[widgetIdx].onRemove?.()
node.widgets.splice(widgetIdx, 1)
}
}
return {
showYourWidget,
removeYourWidget
}
}
```
## Step 3: Register the Widget
Add your widget to the global widget registry in `src/scripts/widgets.ts`:
```typescript
// src/scripts/widgets.ts
import { useYourWidget } from '@/composables/widgets/useYourWidget'
import { transformWidgetConstructorV2ToV1 } from '@/scripts/utils'
export const ComfyWidgets: Record<string, ComfyWidgetConstructor> = {
// ... existing widgets ...
YOUR_WIDGET: transformWidgetConstructorV2ToV1(useYourWidget()),
}
```
## Step 4: Handle Widget-Specific Logic
For widgets that need special handling (e.g., listening to execution events):
```typescript
// In your composable or a separate composable
import { useExecutionStore } from '@/stores/executionStore'
import { watchEffect, onUnmounted } from 'vue'
export const useYourWidgetLogic = (nodeId: string) => {
const executionStore = useExecutionStore()
// Watch for execution state changes
const stopWatcher = watchEffect(() => {
if (executionStore.isNodeExecuting(nodeId)) {
// Handle execution start
}
})
// Cleanup
onUnmounted(() => {
stopWatcher()
})
}
```
## Step 5: Handle Complex Widget Types
For widgets with complex data types or special requirements:
```typescript
// Multi-value widget example
const widget = new ComponentWidgetImpl<string[]>({
node,
name: inputSpec.name,
component: MultiSelectWidget,
inputSpec,
options: {
getValue: () => widgetValue.value,
setValue: (value: string[]) => {
widgetValue.value = Array.isArray(value) ? value : []
},
getMinHeight: () => 40 + PADDING,
// Custom validation
isValid: (value: string[]) => {
return Array.isArray(value) && value.length > 0
}
}
})
```
## Step 6: Add Widget Props (Optional)
Pass additional props to your Vue component:
```typescript
const widget = new ComponentWidgetImpl<string, { placeholder: string }>({
node,
name: inputSpec.name,
component: YourWidget,
inputSpec,
props: {
placeholder: 'Enter value...'
},
options: {
// ... options
}
})
```
## Step 7: Handle Widget Lifecycle
For widgets that need cleanup or special lifecycle handling:
```typescript
// In your widget component
<script setup lang="ts">
import { onMounted, onUnmounted } from 'vue'
onMounted(() => {
// Initialize resources
})
onUnmounted(() => {
// Cleanup resources
})
</script>
```
## Step 8: Test Your Widget
1. Create a test node that uses your widget:
```python
class TestYourWidget:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"value": ("YOUR_WIDGET", {"default": "test"})
}
}
```
2. Write unit tests for your composable:
```typescript
// tests-ui/composables/useYourWidget.test.ts
import { describe, it, expect } from 'vitest'
import { useYourWidget } from '@/composables/widgets/useYourWidget'
describe('useYourWidget', () => {
it('creates widget with correct default value', () => {
const constructor = useYourWidget({ defaultValue: 'test' })
// ... test implementation
})
})
```
## Common Patterns and Best Practices
### 1. Use PrimeVue Components (REQUIRED)
**Always use PrimeVue components** for UI elements to maintain consistency across the application. ComfyUI includes PrimeVue 4.2.5 with 147 available components.
**Reference Documentation**:
- See `primevue-components.md` in the project root directory for a complete list of all available PrimeVue components with descriptions and documentation links
- Alternative location: `vue-widget-conversion/primevue-components.md` (if working in a conversion branch)
- This reference includes all 147 components organized by category (Form, Button, Data, Panel, etc.) with enhanced descriptions
**Important**: When deciding how to create a widget, always consult the PrimeVue components reference first to find the most appropriate component for your use case.
Common widget components include:
```vue
<template>
<!-- Text input -->
<InputText v-model="modelValue" class="w-full" />
<!-- Number input -->
<InputNumber v-model="modelValue" class="w-full" />
<!-- Dropdown selection -->
<Dropdown v-model="modelValue" :options="options" class="w-full" />
<!-- Multi-selection -->
<MultiSelect v-model="modelValue" :options="options" class="w-full" />
<!-- Toggle switch -->
<ToggleSwitch v-model="modelValue" />
<!-- Slider -->
<Slider v-model="modelValue" class="w-full" />
<!-- Text area -->
<Textarea v-model="modelValue" class="w-full" />
<!-- File upload -->
<FileUpload mode="basic" />
<!-- Color picker -->
<ColorPicker v-model="modelValue" />
<!-- Rating -->
<Rating v-model="modelValue" />
</template>
<script setup lang="ts">
import InputText from 'primevue/inputtext'
import InputNumber from 'primevue/inputnumber'
import Dropdown from 'primevue/dropdown'
import MultiSelect from 'primevue/multiselect'
import ToggleSwitch from 'primevue/toggleswitch'
import Slider from 'primevue/slider'
import Textarea from 'primevue/textarea'
import FileUpload from 'primevue/fileupload'
import ColorPicker from 'primevue/colorpicker'
import Rating from 'primevue/rating'
</script>
```
**Important**: Always import PrimeVue components individually as shown above, not from the main primevue package.
### 2. Handle Type Conversions
Ensure proper type handling:
```typescript
setValue: (value: string | number) => {
widgetValue.value = String(value)
}
```
### 3. Responsive Design
Use Tailwind classes for responsive widgets:
```vue
<div class="w-full min-h-[40px] max-h-[200px] overflow-y-auto">
```
### 4. Error Handling
Add validation and error states:
```vue
<template>
<div :class="{ 'border-red-500': hasError }">
<!-- widget content -->
</div>
</template>
```
### 5. Performance
Use `v-show` instead of `v-if` for frequently toggled content:
```vue
<div v-show="isExpanded">...</div>
```
## File References
- **Widget components**: `src/components/graph/widgets/`
- **Widget composables**: `src/composables/widgets/`
- **Widget registration**: `src/scripts/widgets.ts`
- **DOM widget implementation**: `src/scripts/domWidget.ts`
- **Widget store**: `src/stores/domWidgetStore.ts`
- **Widget container**: `src/components/graph/DomWidgets.vue`
- **Widget wrapper**: `src/components/graph/widgets/DomWidget.vue`
## Real Examples from PRs
### Example 1: Text Progress Widget (PR #3824)
**Component** (`src/components/graph/widgets/TextPreviewWidget.vue`):
```vue
<template>
<div class="relative w-full text-xs min-h-[28px] max-h-[200px] rounded-lg px-4 py-2 overflow-y-auto">
<div class="flex items-center gap-2">
<div class="flex-1 break-all flex items-center gap-2">
<span v-html="formattedText"></span>
<Skeleton v-if="isParentNodeExecuting" class="!flex-1 !h-4" />
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { useNodeProgressText } from '@/composables/node/useNodeProgressText'
import { formatMarkdownValue } from '@/utils/formatUtil'
import Skeleton from 'primevue/skeleton'
const modelValue = defineModel<string>({ required: true })
const { widget } = defineProps<{ widget?: object }>()
const { isParentNodeExecuting } = useNodeProgressText(widget?.node)
const formattedText = computed(() => formatMarkdownValue(modelValue.value || ''))
</script>
```
### Example 2: Multi-Select Widget (PR #2987)
**Component** (`src/components/graph/widgets/MultiSelectWidget.vue`):
```vue
<template>
<div>
<MultiSelect
v-model="selectedItems"
:options="options"
filter
:placeholder="placeholder"
:max-selected-labels="3"
:display="display"
class="w-full"
/>
</div>
</template>
<script setup lang="ts">
import MultiSelect from 'primevue/multiselect'
import type { ComponentWidget } from '@/types'
import type { ComboInputSpec } from '@/types/apiTypes'
const selectedItems = defineModel<string[]>({ required: true })
const { widget } = defineProps<{ widget: ComponentWidget<string[]> }>()
const inputSpec = widget.inputSpec as ComboInputSpec
const options = inputSpec.options ?? []
const placeholder = inputSpec.multi_select?.placeholder ?? 'Select items'
const display = inputSpec.multi_select?.chip ? 'chip' : 'comma'
</script>
```
## Migration Checklist
When converting an existing widget:
- [ ] Identify the widget type and its current implementation
- [ ] Create Vue component with proper v-model binding using PrimeVue components
- [ ] Create widget constructor composable in `src/composables/widgets/`
- [ ] Create node-level composable in `src/composables/node/` (only if widget needs dynamic management)
- [ ] Implement getValue/setValue logic with Vue reactivity
- [ ] Handle any special widget behavior (events, validation, execution state)
- [ ] Register widget in ComfyWidgets registry
- [ ] Test with actual nodes that use the widget type
- [ ] Add unit tests for both composables
- [ ] Update documentation if needed
## Key Implementation Patterns
### 1. Vue Component Definition
- Use Composition API with `<script setup>`
- Use `defineModel` for two-way binding
- Accept `widget` prop to access configuration
- Use Tailwind CSS for styling
### 2. Dual Composable Pattern
- **Widget Composable** (`src/composables/widgets/`): Always required - creates widget constructor, handles component instantiation and value management
- **Node Composable** (`src/composables/node/`): Only needed for dynamic widget management (showing/hiding based on events/state)
- Return `ComfyWidgetConstructorV2` from widget composable
- Use `ComponentWidgetImpl` class as bridge between Vue and LiteGraph
- Handle value initialization and updates with Vue reactivity
### 3. Widget Registration
- Use `ComponentWidgetImpl` as bridge between Vue and LiteGraph
- Register in `domWidgetStore` for state management
- Add to `ComfyWidgets` registry
### 4. Integration Points
- **DomWidgets.vue**: Main container for all widgets
- **DomWidget.vue**: Wrapper handling positioning and rendering
- **domWidgetStore**: Centralized widget state management
- **executionStore**: For widgets reacting to execution state
This guide provides a complete pathway for creating Vue-based widgets in ComfyUI, following the patterns established in PRs #3824 and #2987.
The system uses:
- Cloud Scheduler → HTTP POST → Cloud Run API endpoints
- Pub/Sub is only for event-driven tasks (file uploads, deletions)
- Direct HTTP approach for scheduled tasks with OIDC authentication
Existing Scheduled Tasks
1. Node Reindexing - Daily at midnight
2. Security Scanning - Hourly
3. Comfy Node Pack Backfill - Every 6 hours
Standard Approach for GitHub Stars Update
Following the established pattern, you would:
1. Add API endpoint to openapi.yml
2. Implement handler in server/implementation/registry.go
3. Add Cloud Scheduler job in infrastructure/modules/compute/cloud_scheduler.tf
4. Update authentication rules
The scheduler would be configured like:
schedule = "0 2 */2 * *" # Every 2 days at 2 AM PST
uri = "${var.registry_backend_url}/packs/update-github-stars?max_packs=100"
This follows the exact same HTTP-based pattern as the existing reindex-nodes, security-scan, and
comfy-node-pack-backfill jobs. The infrastructure is designed around direct HTTP calls rather than
pub/sub orchestration for scheduled tasks.