From 94d96375cb00108d40cf84cf9b3cbce0f8426524 Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sat, 3 Jun 2023 20:11:24 -0500 Subject: [PATCH] History fixes --- src/lib/components/ComfyApp.ts | 2 +- src/lib/components/ComfyJourneyView.svelte | 38 +++++++------ src/lib/components/JourneyRenderer.svelte | 20 ++++--- src/lib/components/PromptDisplay.svelte | 7 +-- src/lib/components/graph/GraphStyles.ts | 5 +- .../modal/RestoreParamsTable.svelte | 56 ++++++++++++++----- src/lib/restoreParameters.ts | 22 ++++++-- src/lib/stores/journeyStates.ts | 21 ++++++- src/lib/stores/queueState.ts | 2 +- src/lib/stores/uiQueueState.ts | 4 ++ src/lib/utils.ts | 4 ++ 11 files changed, 125 insertions(+), 56 deletions(-) diff --git a/src/lib/components/ComfyApp.ts b/src/lib/components/ComfyApp.ts index 008966d..323660f 100644 --- a/src/lib/components/ComfyApp.ts +++ b/src/lib/components/ComfyApp.ts @@ -1113,7 +1113,7 @@ export default class ComfyApp { queueState.afterQueued(workflow.id, response.promptID, response.number, p.output, extraData) workflowState.afterQueued(workflow.id, response.promptID) if (journeyNode != null) { - journeyNode.promptID = response.promptID; + targetWorkflow.journey.afterQueued(journeyNode, response.promptID); } } } catch (err) { diff --git a/src/lib/components/ComfyJourneyView.svelte b/src/lib/components/ComfyJourneyView.svelte index e4492eb..8004451 100644 --- a/src/lib/components/ComfyJourneyView.svelte +++ b/src/lib/components/ComfyJourneyView.svelte @@ -20,7 +20,7 @@ import selectionState from '$lib/stores/selectionState'; import { Checkbox } from '@gradio/form'; import modalState from '$lib/stores/modalState'; - import queueState from '$lib/stores/queueState'; + import queueState, { type QueueEntry } from '$lib/stores/queueState'; import PromptDisplay from "$lib/components/PromptDisplay.svelte" import { getQueueEntryImages } from '$lib/stores/uiQueueState'; import { SvelteComponent } from 'svelte'; @@ -91,23 +91,25 @@ return; } - const promptID = journeyNode.promptID; - if (promptID != null) { - const queueEntry = queueState.getQueueEntry(journeyNode.promptID) - if (queueEntry?.prompt != null) { - modalState.pushModal({ - title: "Prompt Details", - svelteComponent: PromptDisplay, - svelteProps: { - prompt: queueEntry.prompt, - workflow: queueEntry.extraData?.extra_pnginfo?.comfyBoxWorkflow, - images: getQueueEntryImages(queueEntry), - closeModal: () => modalState.closeAllModals(), - expandAll: false, - app - }, - }) - } + // pick first resolved prompt + const queueEntry: QueueEntry | null = + Array.from(journeyNode.promptIDs) + .map(id => queueState.getQueueEntry(id)) + .find(qe => qe?.prompt != null); + + if (queueEntry) { + modalState.pushModal({ + title: "Prompt Details", + svelteComponent: PromptDisplay, + svelteProps: { + prompt: queueEntry.prompt, + workflow: queueEntry.extraData?.extra_pnginfo?.comfyBoxWorkflow, + images: getQueueEntryImages(queueEntry), + closeModal: () => modalState.closeAllModals(), + expandAll: false, + app + }, + }) } else { notify("This journey entry has no prompts yet.", { type: "warning" }) diff --git a/src/lib/components/JourneyRenderer.svelte b/src/lib/components/JourneyRenderer.svelte index a6f440d..a8c7fa9 100644 --- a/src/lib/components/JourneyRenderer.svelte +++ b/src/lib/components/JourneyRenderer.svelte @@ -50,23 +50,31 @@ return a[1].name > b[1].name ? 1 : -1 }) - for (const [nodeID, source] of sorted) { + const MAX_ENTRIES = 5 + const entries = sorted.slice(0, MAX_ENTRIES) + const leftover = sorted.length - MAX_ENTRIES + + for (const [nodeID, source] of entries) { let line = "" switch (source.nodeType) { case "ui/text": - line = `${source.name} (changed)` + line = `${source.name}: (changed)` break; default: const prevValue = prev[nodeID]; let prevValueStr = "???" if (prevValue) prevValueStr = prevValue.finalValue - line = `${source.name}: ${prevValueStr} -> ${source.finalValue}` + line = `${source.name}: ${prevValueStr} → ${source.finalValue}` break; } lines.push(line) } + if (leftover > 0) { + lines.push(`(+ ${leftover} more)`) + } + return lines.join("\n") } @@ -128,8 +136,6 @@ const patchText = makePatchText(patchNode.patch, prev); const patchNodeHeight = countNewLines(patchText) * 11 + 22; - console.debug("[JourneyRenderer] Patch text", prev, patchText); - nodes.push({ data: { id: midNodeID, @@ -224,8 +230,8 @@ const journeyNode = $journey.nodesByID[nodeID] if (journeyNode) { - if (journeyNode.promptID != null) { - const queueEntry = queueState.getQueueEntry(journeyNode.promptID) + if (journeyNode.promptIDs) { + const queueEntry = Array.from(journeyNode.promptIDs).map(id => queueState.getQueueEntry(id)).find(Boolean); if (queueEntry) { const outputs = getQueueEntryImages(queueEntry); diff --git a/src/lib/components/PromptDisplay.svelte b/src/lib/components/PromptDisplay.svelte index d435fbb..8d9ef13 100644 --- a/src/lib/components/PromptDisplay.svelte +++ b/src/lib/components/PromptDisplay.svelte @@ -8,7 +8,7 @@ import Gallery from "$lib/components/gradio/gallery/Gallery.svelte"; import { ImageViewer } from "$lib/ImageViewer"; import type { Styles } from "@gradio/utils"; - import { comfyFileToComfyBoxMetadata, comfyURLToComfyFile, countNewLines } from "$lib/utils"; + import { comfyFileToComfyBoxMetadata, comfyURLToComfyFile, countNewLines, isMultiline } from "$lib/utils"; import ReceiveOutputTargets from "./modal/ReceiveOutputTargets.svelte"; import RestoreParamsTable from "./modal/RestoreParamsTable.svelte"; import workflowState, { type ComfyBoxWorkflow, type WorkflowReceiveOutputTargets } from "$lib/stores/workflowState"; @@ -41,6 +41,7 @@ // TODO other sources than serialized workflow if (workflow != null) { const workflowParams = getWorkflowRestoreParamsUsingLayout(workflow.workflow, workflow.layout) + console.error("GETPARMS", workflowParams) restoreParams = concatRestoreParams(restoreParams, workflowParams); } @@ -100,10 +101,6 @@ && typeof input[1] === "number" } - function isMultiline(input: any): boolean { - return typeof input === "string" && (input.length > splitLength || countNewLines(input) > 1); - } - function formatInput(input: any): string { if (typeof input === "string") return input diff --git a/src/lib/components/graph/GraphStyles.ts b/src/lib/components/graph/GraphStyles.ts index 325ca4b..d724c1d 100644 --- a/src/lib/components/graph/GraphStyles.ts +++ b/src/lib/components/graph/GraphStyles.ts @@ -68,8 +68,9 @@ const styles: Stylesheet[] = [ "text-valign": "center", "text-wrap": "wrap", "text-max-width": "140", - "background-color": "#333", - "border-color": "#black", + "line-height": "1.5", + "background-color": "#374151", + "border-color": "#1f2937", "border-width": "1", "color": "white", } diff --git a/src/lib/components/modal/RestoreParamsTable.svelte b/src/lib/components/modal/RestoreParamsTable.svelte index fc0f0b8..6b4bb55 100644 --- a/src/lib/components/modal/RestoreParamsTable.svelte +++ b/src/lib/components/modal/RestoreParamsTable.svelte @@ -1,13 +1,16 @@
No parameters to restore found in this workflow.
-(TODO: Only parameters compatible with the currently active workflow can be restored right now)
+(Either prompt is unchanged from active workflow, or the workflow the parameters were saved from was different)