Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/composables/graph/useGraphNodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import type {
INodeInputSlot,
INodeOutputSlot
} from '@/lib/litegraph/src/interfaces'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
import type {
IBaseWidget,
IWidgetOptions
} from '@/lib/litegraph/src/types/widgets'
import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations'
import { LayoutSource } from '@/renderer/core/layout/types'
import type { NodeId } from '@/renderer/core/layout/types'
Expand Down Expand Up @@ -39,7 +42,7 @@ export interface SafeWidgetData {
type: string
value: WidgetValue
label?: string
options?: Record<string, unknown>
options?: IWidgetOptions<unknown>
callback?: ((value: unknown) => void) | undefined
spec?: InputSpec
slotMetadata?: WidgetSlotMetadata
Expand Down Expand Up @@ -107,7 +110,7 @@ export function safeWidgetMapper(
type: widget.type,
value: value,
label: widget.label,
options: widget.options ? { ...widget.options } : undefined,
options: widget.options,
callback: widget.callback,
spec,
slotMetadata: slotInfo,
Expand Down
42 changes: 38 additions & 4 deletions src/extensions/core/previewAny.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,43 @@ useExtensionService().registerExtension({
app
).widget as DOMWidget<HTMLTextAreaElement, string>

showValueWidget.options.read_only = true
const showValueWidgetPlain = ComfyWidgets['STRING'](
this,
'preview',
['STRING', { multiline: true }],
app
).widget as DOMWidget<HTMLTextAreaElement, string>

const showAsPlaintextWidget = ComfyWidgets['BOOLEAN'](
this,
'previewMode',
[
'BOOLEAN',
{ label_on: 'Markdown', label_off: 'Plaintext', default: false }
],
app
)

showAsPlaintextWidget.widget.callback = (value) => {
showValueWidget.hidden = !value
showValueWidget.options.hidden = !value
showValueWidgetPlain.hidden = value
showValueWidgetPlain.options.hidden = value
}

showValueWidget.hidden = true
showValueWidget.options.hidden = true
showValueWidget.options.read_only = true
showValueWidget.element.readOnly = true
showValueWidget.element.disabled = true

showValueWidget.serialize = false

showValueWidgetPlain.hidden = false
showValueWidgetPlain.options.hidden = false
showValueWidgetPlain.options.read_only = true
showValueWidgetPlain.element.readOnly = true
showValueWidgetPlain.element.disabled = true
showValueWidgetPlain.serialize = false
}

const onExecuted = nodeType.prototype.onExecuted
Expand All @@ -39,9 +70,12 @@ useExtensionService().registerExtension({
? void 0
: onExecuted.apply(this, [message])

const previewWidget = this.widgets?.find((w) => w.name === 'preview')
const previewWidgets =
this.widgets?.filter((w) => w.name === 'preview') ?? []

if (!previewWidgets) return
Comment thread
DrJKL marked this conversation as resolved.
Outdated

if (previewWidget) {
for (const previewWidget of previewWidgets) {
previewWidget.value = message.text[0]
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/extensions/core/widgetInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import { app } from '@/scripts/app'
import { ComfyWidgets, addValueControlWidgets } from '@/scripts/widgets'
import {
ComfyWidgets,
addValueControlWidgets,
isValidWidgetType
} from '@/scripts/widgets'
import { CONFIG, GET_CONFIG } from '@/services/litegraphService'
import { mergeInputSpec } from '@/utils/nodeDefUtil'
import { applyTextReplacements } from '@/utils/searchAndReplace'
Expand Down Expand Up @@ -223,8 +227,8 @@ export class PrimitiveNode extends LGraphNode {

// Store current size as addWidget resizes the node
const [oldWidth, oldHeight] = this.size
let widget: IBaseWidget | undefined
if (type in ComfyWidgets) {
let widget: IBaseWidget
if (isValidWidgetType(type)) {
widget = (ComfyWidgets[type](this, 'value', inputData, app) || {}).widget
} else {
// @ts-expect-error InputSpec is not typed correctly
Expand Down
6 changes: 4 additions & 2 deletions src/lib/litegraph/src/LGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4027,7 +4027,9 @@ export class LGraphNode
w: IBaseWidget
}[] = []

for (const w of this.widgets) {
const visibleWidgets = this.widgets.filter((w) => !w.hidden)

for (const w of visibleWidgets) {
if (w.computeSize) {
const height = w.computeSize()[1] + 4
w.computedHeight = height
Expand Down Expand Up @@ -4066,7 +4068,7 @@ export class LGraphNode

// Position widgets
let y = startY
for (const w of this.widgets) {
for (const w of visibleWidgets) {
w.y = y
y += w.computedHeight ?? 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const nodeData = computed<VueNodeData>(() => {
? input.options[0]
: '',
options: {
...input,
hidden: input.hidden,
advanced: input.advanced,
values: input.type === 'COMBO' ? input.options : undefined // For combo widgets
Expand Down
90 changes: 45 additions & 45 deletions src/renderer/extensions/vueNodes/components/NodeWidgets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,57 @@
@pointermove="handleWidgetPointerEvent"
@pointerup="handleWidgetPointerEvent"
>
<div
<template
v-for="(widget, index) in processedWidgets"
:key="`widget-${index}-${widget.name}`"
class="lg-node-widget group col-span-full grid grid-cols-subgrid items-stretch has-[.widget-expands]:flex-1"
>
<!-- Widget Input Slot Dot -->

<div
:class="
cn(
'z-10 w-3 opacity-0 transition-opacity duration-150 group-hover:opacity-100 flex items-center',
widget.slotMetadata?.linked && 'opacity-100'
)
"
v-if="!widget.simplified.options?.hidden"
:data-is-hidden="`hidden: ${widget.simplified.options?.hidden}`"
class="lg-node-widget group col-span-full grid grid-cols-subgrid items-stretch has-[.widget-expands]:flex-1"
>
<InputSlot
v-if="widget.slotMetadata"
:slot-data="{
name: widget.name,
type: widget.type,
boundingRect: [0, 0, 0, 0]
}"
<!-- Widget Input Slot Dot -->

<div
:class="
cn(
'z-10 w-3 opacity-0 transition-opacity duration-150 group-hover:opacity-100 flex items-center',
widget.slotMetadata?.linked && 'opacity-100'
)
"
>
<InputSlot
v-if="widget.slotMetadata"
: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"
:socketless="widget.simplified.spec?.socketless"
dot-only
/>
</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) : ''"
:index="widget.slotMetadata.index"
:socketless="widget.simplified.spec?.socketless"
dot-only
:node-type="nodeType"
class="flex-1 col-span-2"
@update:model-value="widget.updateHandler"
/>
</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) : ''"
:node-type="nodeType"
class="flex-1 col-span-2"
@update:model-value="widget.updateHandler"
/>
</div>
</template>
</div>
</template>

<script setup lang="ts">
import type { TooltipOptions } from 'primevue'
import { computed, onErrorCaptured, ref } from 'vue'
import { computed, onErrorCaptured, reactive, ref } from 'vue'
import type { Component } from 'vue'

import type {
Expand Down Expand Up @@ -132,37 +137,32 @@ const processedWidgets = computed((): ProcessedWidget[] => {
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 : WidgetLegacy)

const slotMetadata = widget.slotMetadata
const { slotMetadata, options } = widget

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, disabled: true }
}
const widgetOptions = slotMetadata?.linked
? { ...options, disabled: true }
: options

const simplified: SimplifiedWidget = {
const simplified: SimplifiedWidget = reactive({
name: widget.name,
type: widget.type,
value: widget.value,
label: widget.label,
options: widgetOptions,
callback: widget.callback,
spec: widget.spec
}
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const updateHandler = (value: WidgetValue) => {
function updateHandler(value: WidgetValue) {
// Update the widget value directly
widget.value = value

Expand Down
8 changes: 7 additions & 1 deletion src/scripts/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export function addValueControlWidgets(
return widgets
}

export const ComfyWidgets: Record<string, ComfyWidgetConstructor> = {
export const ComfyWidgets = {
INT: transformWidgetConstructorV2ToV1(useIntWidget()),
FLOAT: transformWidgetConstructorV2ToV1(useFloatWidget()),
BOOLEAN: transformWidgetConstructorV2ToV1(useBooleanWidget()),
Expand All @@ -299,4 +299,10 @@ export const ComfyWidgets: Record<string, ComfyWidgetConstructor> = {
GALLERIA: transformWidgetConstructorV2ToV1(useGalleriaWidget()),
TEXTAREA: transformWidgetConstructorV2ToV1(useTextareaWidget()),
...dynamicWidgets
} as const

export function isValidWidgetType(
key: unknown
): key is keyof typeof ComfyWidgets {
return ComfyWidgets[key as keyof typeof ComfyWidgets] !== undefined
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
shouldRenderAsVue,
FOR_TESTING
} from '@/renderer/extensions/vueNodes/widgets/registry/widgetRegistry'
import type { SafeWidgetData } from '@/composables/graph/useGraphNodeManager'

const {
WidgetAudioUI,
Expand Down Expand Up @@ -121,7 +122,10 @@ describe('widgetRegistry', () => {
})

it('should respect options while checking type', () => {
const widget = { type: 'text', options: { someOption: 'value' } }
const widget: Partial<SafeWidgetData> = {
type: 'text',
options: { precision: 5 }
}
expect(shouldRenderAsVue(widget)).toBe(true)
})
})
Expand Down