mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-27 23:00:20 +08:00
Expose convert widget functions
This commit is contained in:
parent
f7edcfd927
commit
21251135a0
@ -4,7 +4,7 @@ import { app } from "/scripts/app.js";
|
|||||||
const CONVERTED_TYPE = "converted-widget";
|
const CONVERTED_TYPE = "converted-widget";
|
||||||
const VALID_TYPES = ["STRING", "combo", "number"];
|
const VALID_TYPES = ["STRING", "combo", "number"];
|
||||||
|
|
||||||
function isConvertableWidget(widget, config) {
|
export function isConvertableWidget(widget, config) {
|
||||||
return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]);
|
return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ function showWidget(widget) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToInput(node, widget, config) {
|
export function convertToInput(node, widget, config) {
|
||||||
hideWidget(node, widget);
|
hideWidget(node, widget);
|
||||||
|
|
||||||
const { linkType } = getWidgetType(config);
|
const { linkType } = getWidgetType(config);
|
||||||
@ -63,7 +63,7 @@ function convertToInput(node, widget, config) {
|
|||||||
node.setSize([Math.max(sz[0], node.size[0]), Math.max(sz[1], node.size[1])]);
|
node.setSize([Math.max(sz[0], node.size[0]), Math.max(sz[1], node.size[1])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToWidget(node, widget) {
|
export function convertToWidget(node, widget) {
|
||||||
showWidget(widget);
|
showWidget(widget);
|
||||||
const sz = node.size;
|
const sz = node.size;
|
||||||
node.removeInput(node.inputs.findIndex((i) => i.widget?.name === widget.name));
|
node.removeInput(node.inputs.findIndex((i) => i.widget?.name === widget.name));
|
||||||
@ -83,6 +83,10 @@ function getWidgetType(config) {
|
|||||||
return { type, linkType };
|
return { type, linkType };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getConfig(nodeData, widget) {
|
||||||
|
return nodeData?.input?.required[widget.name] || nodeData?.input?.optional?.[widget.name] || [widget.type, widget.options || {}];
|
||||||
|
}
|
||||||
|
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "Comfy.WidgetInputs",
|
name: "Comfy.WidgetInputs",
|
||||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||||
@ -101,7 +105,7 @@ app.registerExtension({
|
|||||||
callback: () => convertToWidget(this, w),
|
callback: () => convertToWidget(this, w),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const config = nodeData?.input?.required[w.name] || nodeData?.input?.optional?.[w.name] || [w.type, w.options || {}];
|
const config = getConfig(nodeData, w);
|
||||||
if (isConvertableWidget(w, config)) {
|
if (isConvertableWidget(w, config)) {
|
||||||
toInput.push({
|
toInput.push({
|
||||||
content: `Convert ${w.name} to input`,
|
content: `Convert ${w.name} to input`,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user