mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-05 13:10:24 +00:00
 Did testing on about a dozen custom nodes. Most just work. - Some custom nodes have copy/pasted the `addDOMWidget` call with types like `customtext` and get converted to textareas -> Not feasible to fix here. Can open PRs into custom nodes if complaints arise. - Only the KJNodes spline editor had mouse issues -> Can investigate/open PR into KJNodes later. - Many nodes don't resize gracefully. Probably best handled in a future PR. - Some expect to be handled like textareas. These currently have minsize and don't scale. - Others, like VHS previews, scale self properly, but don't update height inside a drag operation -> node height can be set to less than fit. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6006-Implement-DOMWidget-for-vue-2886d73d3650817ca497c15d87d70f4f) by [Unito](https://www.unito.io)
183 lines
5.1 KiB
Vue
183 lines
5.1 KiB
Vue
<template>
|
|
<div v-if="renderError" class="node-error p-2 text-sm text-red-500">
|
|
{{ $t('Node Widgets Error') }}
|
|
</div>
|
|
<div
|
|
v-else
|
|
:class="
|
|
cn(
|
|
'lg-node-widgets flex flex-col gap-2 pr-4',
|
|
shouldHandleNodePointerEvents
|
|
? 'pointer-events-auto'
|
|
: 'pointer-events-none'
|
|
)
|
|
"
|
|
@pointerdown.stop="handleWidgetPointerEvent"
|
|
@pointermove.stop="handleWidgetPointerEvent"
|
|
@pointerup.stop="handleWidgetPointerEvent"
|
|
>
|
|
<div
|
|
v-for="(widget, index) in processedWidgets"
|
|
:key="`widget-${index}-${widget.name}`"
|
|
class="lg-widget-container group flex items-center"
|
|
>
|
|
<!-- Widget Input Slot Dot -->
|
|
|
|
<div
|
|
class="opacity-0 transition-opacity duration-150 group-hover:opacity-100"
|
|
>
|
|
<InputSlot
|
|
:slot-data="{
|
|
name: widget.name,
|
|
type: widget.type,
|
|
boundingRect: [0, 0, 0, 0]
|
|
}"
|
|
:node-id="nodeData?.id != null ? String(nodeData.id) : ''"
|
|
:index="widget.slotMetadata?.index ?? 0"
|
|
:dot-only="true"
|
|
/>
|
|
</div>
|
|
<!-- Widget Component -->
|
|
<component
|
|
:is="widget.vueComponent"
|
|
v-tooltip.left="widget.tooltipConfig"
|
|
:widget="widget.simplified"
|
|
:model-value="widget.value"
|
|
:node-id="nodeData?.id != null ? String(nodeData.id) : ''"
|
|
class="flex-1"
|
|
@update:model-value="widget.updateHandler"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onErrorCaptured, ref } from 'vue'
|
|
|
|
import type {
|
|
SafeWidgetData,
|
|
VueNodeData,
|
|
WidgetSlotMetadata
|
|
} from '@/composables/graph/useGraphNodeManager'
|
|
import { useErrorHandling } from '@/composables/useErrorHandling'
|
|
import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteractions'
|
|
import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips'
|
|
import WidgetDOM from '@/renderer/extensions/vueNodes/widgets/components/WidgetDOM.vue'
|
|
import WidgetInputText from '@/renderer/extensions/vueNodes/widgets/components/WidgetInputText.vue'
|
|
import {
|
|
getComponent,
|
|
shouldRenderAsVue
|
|
} from '@/renderer/extensions/vueNodes/widgets/registry/widgetRegistry'
|
|
import type { SimplifiedWidget, WidgetValue } from '@/types/simplifiedWidget'
|
|
import { cn } from '@/utils/tailwindUtil'
|
|
|
|
import InputSlot from './InputSlot.vue'
|
|
|
|
interface NodeWidgetsProps {
|
|
nodeData?: VueNodeData
|
|
}
|
|
|
|
const { nodeData } = defineProps<NodeWidgetsProps>()
|
|
|
|
const { shouldHandleNodePointerEvents, forwardEventToCanvas } =
|
|
useCanvasInteractions()
|
|
const handleWidgetPointerEvent = (event: PointerEvent) => {
|
|
if (!shouldHandleNodePointerEvents.value) {
|
|
forwardEventToCanvas(event)
|
|
}
|
|
}
|
|
|
|
// Error boundary implementation
|
|
const renderError = ref<string | null>(null)
|
|
|
|
const { toastErrorHandler } = useErrorHandling()
|
|
|
|
onErrorCaptured((error) => {
|
|
renderError.value = error.message
|
|
toastErrorHandler(error)
|
|
return false
|
|
})
|
|
|
|
const nodeType = computed(() => nodeData?.type || '')
|
|
const { getWidgetTooltip, createTooltipConfig } = useNodeTooltips(
|
|
nodeType.value
|
|
)
|
|
|
|
interface ProcessedWidget {
|
|
name: string
|
|
type: string
|
|
vueComponent: any
|
|
simplified: SimplifiedWidget
|
|
value: WidgetValue
|
|
updateHandler: (value: unknown) => void
|
|
tooltipConfig: any
|
|
slotMetadata?: WidgetSlotMetadata
|
|
}
|
|
|
|
const processedWidgets = computed((): ProcessedWidget[] => {
|
|
if (!nodeData?.widgets) return []
|
|
|
|
const widgets = nodeData.widgets as SafeWidgetData[]
|
|
const result: ProcessedWidget[] = []
|
|
|
|
for (const widget of widgets) {
|
|
// Skip if widget is in the hidden list for this node type
|
|
if (widget.options?.hidden) continue
|
|
if (widget.options?.canvasOnly) continue
|
|
if (!widget.type) continue
|
|
if (!shouldRenderAsVue(widget)) continue
|
|
|
|
const vueComponent =
|
|
getComponent(widget.type, widget.name) ||
|
|
(widget.isDOMWidget ? WidgetDOM : WidgetInputText)
|
|
|
|
const slotMetadata = widget.slotMetadata
|
|
|
|
let widgetOptions = widget.options
|
|
// Core feature: Disable Vue widgets when their input slots are connected
|
|
// This prevents conflicting input sources - when a slot is linked to another
|
|
// node's output, the widget should be read-only to avoid data conflicts
|
|
if (slotMetadata?.linked) {
|
|
widgetOptions = widget.options
|
|
? { ...widget.options, disabled: true }
|
|
: { disabled: true }
|
|
}
|
|
|
|
const simplified: SimplifiedWidget = {
|
|
name: widget.name,
|
|
type: widget.type,
|
|
value: widget.value,
|
|
label: widget.label,
|
|
options: widgetOptions,
|
|
callback: widget.callback,
|
|
spec: widget.spec
|
|
}
|
|
|
|
const updateHandler = (value: unknown) => {
|
|
// Update the widget value directly
|
|
widget.value = value as WidgetValue
|
|
|
|
if (widget.callback) {
|
|
widget.callback(value)
|
|
}
|
|
}
|
|
|
|
const tooltipText = getWidgetTooltip(widget)
|
|
const tooltipConfig = createTooltipConfig(tooltipText)
|
|
|
|
result.push({
|
|
name: widget.name,
|
|
type: widget.type,
|
|
vueComponent,
|
|
simplified,
|
|
value: widget.value,
|
|
updateHandler,
|
|
tooltipConfig,
|
|
slotMetadata
|
|
})
|
|
}
|
|
|
|
return result
|
|
})
|
|
</script>
|