mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 18:22:40 +00:00
Migrate forceInput widgets_values (#3337)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import type { ColorOption } from '@comfyorg/litegraph'
|
||||
import { LGraphGroup, LGraphNode, isColorable } from '@comfyorg/litegraph'
|
||||
import type { IComboWidget } from '@comfyorg/litegraph/dist/types/widgets'
|
||||
import type {
|
||||
IComboWidget,
|
||||
IWidget
|
||||
} from '@comfyorg/litegraph/dist/types/widgets'
|
||||
import _ from 'lodash'
|
||||
|
||||
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
|
||||
type ImageNode = LGraphNode & { imgs: HTMLImageElement[] | undefined }
|
||||
type VideoNode = LGraphNode & {
|
||||
videoContainer: HTMLElement | undefined
|
||||
@@ -70,3 +75,32 @@ export function executeWidgetsCallback(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Since frontend version 1.16, forceInput input is no longer treated
|
||||
* as widget. So we need to remove the dummy widget value serialized
|
||||
* from workflows prior to v1.16.
|
||||
* Ref: https://github.com/Comfy-Org/ComfyUI_frontend/pull/3326
|
||||
*
|
||||
* @param nodeDef the node definition
|
||||
* @param widgets the widgets on the node instance (from node definition)
|
||||
* @param widgetsValues the widgets values to populate the node during configuration
|
||||
* @returns the widgets values without the dummy widget values
|
||||
*/
|
||||
export function migrateWidgetsValues<TWidgetValue>(
|
||||
inputDefs: Record<string, InputSpec>,
|
||||
widgets: IWidget[],
|
||||
widgetsValues: TWidgetValue[]
|
||||
): TWidgetValue[] {
|
||||
const widgetNames = new Set(widgets.map((w) => w.name))
|
||||
const originalWidgetsInputs = Object.values(inputDefs).filter(
|
||||
(input) => widgetNames.has(input.name) || input.forceInput
|
||||
)
|
||||
|
||||
if (originalWidgetsInputs.length === widgetsValues?.length) {
|
||||
return _.zip(originalWidgetsInputs, widgetsValues)
|
||||
.filter(([input]) => !input?.forceInput)
|
||||
.map(([_, value]) => value as TWidgetValue)
|
||||
}
|
||||
return widgetsValues
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user