Account for upstream links when refreshing combo widgets

This commit is contained in:
space-nuko
2023-05-16 20:55:20 -05:00
parent 0d6395c072
commit 9f1da40385
14 changed files with 1436 additions and 129 deletions

View File

@@ -0,0 +1,69 @@
import type IComfyInputSlot from "$lib/IComfyInputSlot";
import { clamp } from "$lib/utils";
import { BuiltInSlotType, LiteGraph, type SlotLayout } from "@litegraph-ts/core";
import RangeWidget from "$lib/widgets/RangeWidget.svelte";
import type { ComfyWidgetProperties } from "./ComfyWidgetNode";
import ComfyWidgetNode from "./ComfyWidgetNode";
export interface ComfyNumberProperties extends ComfyWidgetProperties {
min: number,
max: number,
step: number,
precision: number
}
export default class ComfyNumberNode extends ComfyWidgetNode<number> {
override properties: ComfyNumberProperties = {
tags: [],
defaultValue: 0,
min: 0,
max: 10,
step: 1,
precision: 1
}
override svelteComponentType = RangeWidget
override defaultValue = 0;
static slotLayout: SlotLayout = {
inputs: [
{ name: "store", type: BuiltInSlotType.ACTION }
],
outputs: [
{ name: "value", type: "number" },
{ name: "changed", type: BuiltInSlotType.EVENT },
]
}
override outputProperties = [
{ name: "min", type: "number" },
{ name: "max", type: "number" },
{ name: "step", type: "number" },
{ name: "precision", type: "number" },
]
constructor(name?: string) {
super(name, 0)
}
override parseValue(value: any): number {
if (typeof value !== "number")
return this.properties.min;
return clamp(value, this.properties.min, this.properties.max)
}
override clampOneConfig(input: IComfyInputSlot) {
// this.setProperty("min", clamp(this.properties.min, input.config.min, input.config.max))
// this.setProperty("max", clamp(this.properties.max, input.config.max, input.config.min))
// this.setProperty("step", Math.min(this.properties.step, input.config.step))
this.setValue(this.properties.defaultValue)
}
}
LiteGraph.registerNodeType({
class: ComfyNumberNode,
title: "UI.Number",
desc: "Displays a number, by default in a slider format.",
type: "ui/number"
})