diff --git a/src/lib/components/ComfyApp.ts b/src/lib/components/ComfyApp.ts index ce7a9bc..44b4df6 100644 --- a/src/lib/components/ComfyApp.ts +++ b/src/lib/components/ComfyApp.ts @@ -23,7 +23,7 @@ import { ComfyComboNode } from "$lib/nodes/widgets"; import notify from "$lib/notify"; import parseA1111, { type A1111ParsedInfotext } from "$lib/parseA1111"; 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 queueState from "$lib/stores/queueState"; import selectionState from "$lib/stores/selectionState"; @@ -272,6 +272,9 @@ export default class ComfyApp { } resizeCanvas() { + if (!this.canvasEl) + return; + this.canvasEl.width = this.canvasEl.parentElement.offsetWidth; this.canvasEl.height = this.canvasEl.parentElement.offsetHeight; this.canvasEl.style.width = "" @@ -482,12 +485,16 @@ export default class ComfyApp { } catch (error) { } } - if (workflow && typeof workflow.createdBy === "string") { - this.openWorkflow(workflow); - } - else { - // TODO handle vanilla workflows - throw new Error("Workflow was not in ComfyBox format!") + if (workflow == null) + return; + + if (typeof workflow === "object") { + if (typeof workflow.createdBy === "string") + this.openWorkflow(workflow); + else { + // TODO handle vanilla workflows + throw new Error("Workflow was not in ComfyBox format!") + } } }); } @@ -784,6 +791,30 @@ export default class ComfyApp { 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() { this.clean(); @@ -821,6 +852,8 @@ export default class ComfyApp { return; } + this.saveWorkflowStateAsDefault(workflow); + const promptFilename = get(configState).promptForWorkflowName; const title = workflow.attrs.title.trim() || "workflow" diff --git a/src/lib/components/ComfyBoxWorkflowsView.svelte b/src/lib/components/ComfyBoxWorkflowsView.svelte index 374b396..8cc5aa1 100644 --- a/src/lib/components/ComfyBoxWorkflowsView.svelte +++ b/src/lib/components/ComfyBoxWorkflowsView.svelte @@ -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() { app.createNewWorkflow(); } @@ -273,28 +280,31 @@ + - + - - UI Edit mode - - - - Theme - - + +
diff --git a/src/lib/nodes/widgets/ComfyComboNode.ts b/src/lib/nodes/widgets/ComfyComboNode.ts index de6fedd..5373298 100644 --- a/src/lib/nodes/widgets/ComfyComboNode.ts +++ b/src/lib/nodes/widgets/ComfyComboNode.ts @@ -162,6 +162,8 @@ export default class ComfyComboNode extends ComfyWidgetNode { override stripUserState(o: SerializedLGraphNode) { super.stripUserState(o); o.properties.values = [] + o.properties.defaultValue = null; + (o as any).comfyValue = null } } diff --git a/src/lib/nodes/widgets/ComfyWidgetNode.ts b/src/lib/nodes/widgets/ComfyWidgetNode.ts index 6be6872..9c8ca01 100644 --- a/src/lib/nodes/widgets/ComfyWidgetNode.ts +++ b/src/lib/nodes/widgets/ComfyWidgetNode.ts @@ -355,7 +355,6 @@ export default abstract class ComfyWidgetNode extends ComfyGraphNode { override stripUserState(o: SerializedLGraphNode) { super.stripUserState(o); - (o as any).comfyValue = this.defaultValue; - o.properties.defaultValue = null; + (o as any).comfyValue = this.properties.defaultValue; } } diff --git a/src/lib/stores/layoutStates.ts b/src/lib/stores/layoutStates.ts index a460bae..3f9fd54 100644 --- a/src/lib/stores/layoutStates.ts +++ b/src/lib/stores/layoutStates.ts @@ -525,7 +525,37 @@ const ALL_ATTRIBUTES: AttributesSpecList = [ 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 + { + name: "defaultValue", + type: "number", + location: "nodeProps", + editable: true, + defaultValue: 0, + min: -2 ^ 16, + max: 2 ^ 16, + validNodeTypes: ["ui/number"], + }, { name: "min", type: "number", @@ -587,6 +617,14 @@ const ALL_ATTRIBUTES: AttributesSpecList = [ }, // Radio + { + name: "defaultValue", + type: "string", + location: "nodeProps", + editable: true, + defaultValue: "Choice A", + validNodeTypes: ["ui/radio"], + }, { name: "choices", type: "string", @@ -598,6 +636,16 @@ const ALL_ATTRIBUTES: AttributesSpecList = [ deserialize: deserializeStringArray, }, + // Text + { + name: "defaultValue", + type: "string", + location: "nodeProps", + editable: true, + defaultValue: "", + validNodeTypes: ["ui/text"], + }, + // Workflow { name: "title",