Configurable defaults per workflow and reset
This commit is contained in:
@@ -23,7 +23,7 @@ import { ComfyComboNode } from "$lib/nodes/widgets";
|
|||||||
import notify from "$lib/notify";
|
import notify from "$lib/notify";
|
||||||
import parseA1111, { type A1111ParsedInfotext } from "$lib/parseA1111";
|
import parseA1111, { type A1111ParsedInfotext } from "$lib/parseA1111";
|
||||||
import configState, { type ConfigState } from "$lib/stores/configState";
|
import configState, { type ConfigState } from "$lib/stores/configState";
|
||||||
import layoutStates, { defaultWorkflowAttributes, type SerializedLayoutState } from "$lib/stores/layoutStates";
|
import layoutStates, { defaultWorkflowAttributes, isComfyWidgetNode, type SerializedLayoutState } from "$lib/stores/layoutStates";
|
||||||
import modalState from "$lib/stores/modalState";
|
import modalState from "$lib/stores/modalState";
|
||||||
import queueState from "$lib/stores/queueState";
|
import queueState from "$lib/stores/queueState";
|
||||||
import selectionState from "$lib/stores/selectionState";
|
import selectionState from "$lib/stores/selectionState";
|
||||||
@@ -272,6 +272,9 @@ export default class ComfyApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resizeCanvas() {
|
resizeCanvas() {
|
||||||
|
if (!this.canvasEl)
|
||||||
|
return;
|
||||||
|
|
||||||
this.canvasEl.width = this.canvasEl.parentElement.offsetWidth;
|
this.canvasEl.width = this.canvasEl.parentElement.offsetWidth;
|
||||||
this.canvasEl.height = this.canvasEl.parentElement.offsetHeight;
|
this.canvasEl.height = this.canvasEl.parentElement.offsetHeight;
|
||||||
this.canvasEl.style.width = ""
|
this.canvasEl.style.width = ""
|
||||||
@@ -482,13 +485,17 @@ export default class ComfyApp {
|
|||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (workflow && typeof workflow.createdBy === "string") {
|
if (workflow == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (typeof workflow === "object") {
|
||||||
|
if (typeof workflow.createdBy === "string")
|
||||||
this.openWorkflow(workflow);
|
this.openWorkflow(workflow);
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
// TODO handle vanilla workflows
|
// TODO handle vanilla workflows
|
||||||
throw new Error("Workflow was not in ComfyBox format!")
|
throw new Error("Workflow was not in ComfyBox format!")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -784,6 +791,30 @@ export default class ComfyApp {
|
|||||||
await this.openWorkflow(state, options)
|
await this.openWorkflow(state, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveWorkflowStateAsDefault(workflow: ComfyBoxWorkflow | null) {
|
||||||
|
workflow ||= workflowState.getActiveWorkflow();
|
||||||
|
if (workflow == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (const node of workflow.graph.iterateNodesInOrderRecursive()) {
|
||||||
|
if (isComfyWidgetNode(node)) {
|
||||||
|
node.properties.defaultValue = node.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resetCurrentWorkflow() {
|
||||||
|
const workflow = workflowState.getActiveWorkflow();
|
||||||
|
if (workflow == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (const node of workflow.graph.iterateNodesInOrderRecursive()) {
|
||||||
|
if (isComfyWidgetNode(node)) {
|
||||||
|
node.setValue(node.properties.defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this.clean();
|
this.clean();
|
||||||
|
|
||||||
@@ -821,6 +852,8 @@ export default class ComfyApp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.saveWorkflowStateAsDefault(workflow);
|
||||||
|
|
||||||
const promptFilename = get(configState).promptForWorkflowName;
|
const promptFilename = get(configState).promptForWorkflowName;
|
||||||
|
|
||||||
const title = workflow.attrs.title.trim() || "workflow"
|
const title = workflow.attrs.title.trim() || "workflow"
|
||||||
|
|||||||
@@ -151,6 +151,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function doReset() {
|
||||||
|
var confirmed = confirm("Are you sure you want to reset this workflow to its default state?");
|
||||||
|
if (confirmed) {
|
||||||
|
app.resetCurrentWorkflow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createNewWorkflow() {
|
function createNewWorkflow() {
|
||||||
app.createNewWorkflow();
|
app.createNewWorkflow();
|
||||||
}
|
}
|
||||||
@@ -273,28 +280,31 @@
|
|||||||
<Button variant="secondary" disabled={loading} on:click={doLoadDefault}>
|
<Button variant="secondary" disabled={loading} on:click={doLoadDefault}>
|
||||||
Load Default
|
Load Default
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button variant="secondary" disabled={loading} on:click={doReset}>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
<Button variant="secondary" disabled={loading} on:click={doRefreshCombos}>
|
<Button variant="secondary" disabled={loading} on:click={doRefreshCombos}>
|
||||||
🔄
|
🔄
|
||||||
</Button>
|
</Button>
|
||||||
<!-- <Checkbox label="Lock Nodes" bind:value={$uiState.nodesLocked}/>
|
<!-- <Checkbox label="Lock Nodes" bind:value={$uiState.nodesLocked}/>
|
||||||
<Checkbox label="Disable Interaction" bind:value={$uiState.graphLocked}/> -->
|
<Checkbox label="Disable Interaction" bind:value={$uiState.graphLocked}/> -->
|
||||||
<span style="display: inline-flex !important">
|
<span style="display: inline-flex !important; padding: 0 0.75rem;">
|
||||||
<Checkbox label="Auto-Add UI" bind:value={$uiState.autoAddUI}/>
|
<Checkbox label="Auto-Add UI" bind:value={$uiState.autoAddUI}/>
|
||||||
</span>
|
</span>
|
||||||
<span class="label" for="ui-edit-mode">
|
<!-- <span class="label" for="ui-edit-mode">
|
||||||
<BlockTitle>UI Edit mode</BlockTitle>
|
<BlockTitle>UI Edit mode</BlockTitle>
|
||||||
<select id="ui-edit-mode" name="ui-edit-mode" bind:value={$uiState.uiEditMode}>
|
<select id="ui-edit-mode" name="ui-edit-mode" bind:value={$uiState.uiEditMode}>
|
||||||
<option value="widgets">Widgets</option>
|
<option value="widgets">Widgets</option>
|
||||||
</select>
|
</select>
|
||||||
</span>
|
</span> -->
|
||||||
<span class="label" for="ui-theme">
|
<!-- <span class="label" for="ui-theme">
|
||||||
<BlockTitle>Theme</BlockTitle>
|
<BlockTitle>Theme</BlockTitle>
|
||||||
<select id="ui-theme" name="ui-theme" bind:value={uiTheme}>
|
<select id="ui-theme" name="ui-theme" bind:value={uiTheme}>
|
||||||
<option value="gradio-dark">Gradio Dark</option>
|
<option value="gradio-dark">Gradio Dark</option>
|
||||||
<option value="gradio-light">Gradio Light</option>
|
<option value="gradio-light">Gradio Light</option>
|
||||||
<option value="anapnoe">Anapnoe</option>
|
<option value="anapnoe">Anapnoe</option>
|
||||||
</select>
|
</select>
|
||||||
</span>
|
</span> -->
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<ComfyUnlockUIButton bind:toggled={$uiState.uiUnlocked} />
|
<ComfyUnlockUIButton bind:toggled={$uiState.uiUnlocked} />
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ export default class ComfyComboNode extends ComfyWidgetNode<string> {
|
|||||||
override stripUserState(o: SerializedLGraphNode) {
|
override stripUserState(o: SerializedLGraphNode) {
|
||||||
super.stripUserState(o);
|
super.stripUserState(o);
|
||||||
o.properties.values = []
|
o.properties.values = []
|
||||||
|
o.properties.defaultValue = null;
|
||||||
|
(o as any).comfyValue = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -355,7 +355,6 @@ export default abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
|
|||||||
|
|
||||||
override stripUserState(o: SerializedLGraphNode) {
|
override stripUserState(o: SerializedLGraphNode) {
|
||||||
super.stripUserState(o);
|
super.stripUserState(o);
|
||||||
(o as any).comfyValue = this.defaultValue;
|
(o as any).comfyValue = this.properties.defaultValue;
|
||||||
o.properties.defaultValue = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -525,7 +525,37 @@ const ALL_ATTRIBUTES: AttributesSpecList = [
|
|||||||
canShow: (di: IDragItem) => di.type === "container"
|
canShow: (di: IDragItem) => di.type === "container"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Combo
|
||||||
|
{
|
||||||
|
name: "defaultValue",
|
||||||
|
type: "string",
|
||||||
|
location: "nodeProps",
|
||||||
|
editable: true,
|
||||||
|
defaultValue: "A",
|
||||||
|
validNodeTypes: ["ui/combo"],
|
||||||
|
},
|
||||||
|
|
||||||
|
// Checkbox
|
||||||
|
{
|
||||||
|
name: "defaultValue",
|
||||||
|
type: "boolean",
|
||||||
|
location: "nodeProps",
|
||||||
|
editable: true,
|
||||||
|
defaultValue: true,
|
||||||
|
validNodeTypes: ["ui/checkbox"],
|
||||||
|
},
|
||||||
|
|
||||||
// Range
|
// Range
|
||||||
|
{
|
||||||
|
name: "defaultValue",
|
||||||
|
type: "number",
|
||||||
|
location: "nodeProps",
|
||||||
|
editable: true,
|
||||||
|
defaultValue: 0,
|
||||||
|
min: -2 ^ 16,
|
||||||
|
max: 2 ^ 16,
|
||||||
|
validNodeTypes: ["ui/number"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "min",
|
name: "min",
|
||||||
type: "number",
|
type: "number",
|
||||||
@@ -587,6 +617,14 @@ const ALL_ATTRIBUTES: AttributesSpecList = [
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Radio
|
// Radio
|
||||||
|
{
|
||||||
|
name: "defaultValue",
|
||||||
|
type: "string",
|
||||||
|
location: "nodeProps",
|
||||||
|
editable: true,
|
||||||
|
defaultValue: "Choice A",
|
||||||
|
validNodeTypes: ["ui/radio"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "choices",
|
name: "choices",
|
||||||
type: "string",
|
type: "string",
|
||||||
@@ -598,6 +636,16 @@ const ALL_ATTRIBUTES: AttributesSpecList = [
|
|||||||
deserialize: deserializeStringArray,
|
deserialize: deserializeStringArray,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Text
|
||||||
|
{
|
||||||
|
name: "defaultValue",
|
||||||
|
type: "string",
|
||||||
|
location: "nodeProps",
|
||||||
|
editable: true,
|
||||||
|
defaultValue: "",
|
||||||
|
validNodeTypes: ["ui/text"],
|
||||||
|
},
|
||||||
|
|
||||||
// Workflow
|
// Workflow
|
||||||
{
|
{
|
||||||
name: "title",
|
name: "title",
|
||||||
|
|||||||
Reference in New Issue
Block a user