Trying to fix prop updates reflected in widgets

This commit is contained in:
space-nuko
2023-05-03 20:16:45 -07:00
parent 573970eac6
commit 3d55badda8
7 changed files with 106 additions and 32 deletions

View File

@@ -7,14 +7,22 @@
export let widget: WidgetLayout | null = null;
let node: ComfyComboNode | null = null;
let nodeValue: Writable<string> | null = null;
let propsChanged: Writable<boolean> | null = null;
let option: any
$: widget && setNodeValue(widget);
$: if ($propsChanged && nodeValue !== null) {
setOption($nodeValue)
setNodeValue(widget)
node.properties = node.properties
}
function setNodeValue(widget: WidgetLayout) {
if(widget && !node) {
if(widget) {
node = widget.node as ComfyComboNode
nodeValue = node.value;
propsChanged = node.propsChanged;
setOption($nodeValue) // don't react on option
}
}
@@ -23,7 +31,7 @@
option = value;
}
$: if (nodeValue && option) {
$: if (nodeValue && option && option.value) {
$nodeValue = option.value;
}
</script>
@@ -34,8 +42,8 @@
<BlockTitle show_label={true}>{widget.attrs.title}</BlockTitle>
<Select
bind:value={option}
bind:items={node.properties.options}
disabled={node.properties.options.length === 0}
bind:items={node.properties.values}
disabled={node.properties.values.length === 0}
clearable={false}
on:change
on:select

View File

@@ -6,16 +6,28 @@
export let widget: WidgetLayout | null = null;
let node: ComfySliderNode | null = null;
let nodeValue: Writable<number> | null = null;
let propsChanged: Writable<boolean> | null = null;
let option: number | null = null;
$: if(widget) {
node = widget.node
nodeValue = node.value;
updateOption(); // don't react on option
$: widget && setNodeValue(widget);
function setNodeValue(widget: WidgetLayout) {
if (widget) {
node = widget.node as ComfySliderNode
nodeValue = node.value;
propsChanged = node.propsChanged;
setOption($nodeValue); // don't react on option
}
};
function updateOption() {
option = get(nodeValue);
$: if ($propsChanged && nodeValue !== null) {
setOption($nodeValue)
setNodeValue(widget)
node.properties = node.properties
}
function setOption(value: any) {
option = value;
}
function onRelease(e: Event) {