Error handling modals

This commit is contained in:
space-nuko
2023-05-21 16:55:18 -05:00
parent 02afbae406
commit a3c10d5be9
12 changed files with 241 additions and 61 deletions

View File

@@ -5,16 +5,18 @@ import { v4 as uuidv4 } from "uuid";
export type ModalButton = {
name: string,
variant: "primary" | "secondary",
onClick: () => void
onClick: () => void,
closeOnClick?: boolean
}
export interface ModalData {
id: string,
title: string,
title?: string,
onClose?: () => void,
svelteComponent?: typeof SvelteComponentDev,
svelteProps?: Record<string, any>,
buttons?: ModalButton[],
showCloseButton?: boolean
svelteProps: Record<string, any>,
buttons: ModalButton[],
showCloseButton: boolean,
closeOnClick: boolean
}
export interface ModalState {
activeModals: ModalData[]
@@ -34,7 +36,10 @@ const store: Writable<ModalState> = writable(
function pushModal(data: Partial<ModalData>) {
const modal: ModalData = {
title: "Modal",
showCloseButton: true,
closeOnClick: true,
buttons: [],
svelteProps: {},
...data,
id: uuidv4(),
}

View File

@@ -79,7 +79,7 @@ export class ComfyWorkflow {
/*
* Missing node types encountered when deserializing the graph
*/
missingNodeTypes: string[];
missingNodeTypes: Set<string> = new Set();
get layout(): WritableLayoutStateStore | null {
return layoutStates.getLayout(this.id)
@@ -168,6 +168,13 @@ export class ComfyWorkflow {
}
}
/*
* Creates a workflow and layout.
*
* NOTE: The layout will be attached to the global store, but the workflow
* will not. If you change your mind later be sure to call
* layoutStates.remove(workflow.id)!
*/
static create(title: string = "New Workflow"): [ComfyWorkflow, WritableLayoutStateStore] {
const workflow = new ComfyWorkflow(title);
const layoutState = layoutStates.create(workflow);
@@ -175,7 +182,7 @@ export class ComfyWorkflow {
}
deserialize(layoutState: WritableLayoutStateStore, data: SerializedWorkflowState) {
this.missingNodeTypes = []
this.missingNodeTypes.clear();
for (let n of data.graph.nodes) {
// Patch T2IAdapterLoader to ControlNetLoader since they are the same node now
@@ -183,7 +190,7 @@ export class ComfyWorkflow {
// Find missing node types
if (!(n.type in LiteGraph.registered_node_types)) {
this.missingNodeTypes.push(n.type);
this.missingNodeTypes.add(n.type);
}
}
@@ -233,6 +240,7 @@ type WorkflowStateOps = {
getActiveWorkflow: () => ComfyWorkflow | null
createNewWorkflow: (canvas: ComfyGraphCanvas, title?: string, setActive?: boolean) => ComfyWorkflow,
openWorkflow: (canvas: ComfyGraphCanvas, data: SerializedAppState) => ComfyWorkflow,
addWorkflow: (canvas: ComfyGraphCanvas, data: ComfyWorkflow) => void,
closeWorkflow: (canvas: ComfyGraphCanvas, index: number) => void,
closeAllWorkflows: (canvas: ComfyGraphCanvas) => void,
setActiveWorkflow: (canvas: ComfyGraphCanvas, index: number) => ComfyWorkflow | null
@@ -296,6 +304,12 @@ function openWorkflow(canvas: ComfyGraphCanvas, data: SerializedAppState): Comfy
const [workflow, layoutState] = ComfyWorkflow.create("Workflow")
workflow.deserialize(layoutState, { graph: data.workflow, layout: data.layout, attrs: data.attrs })
addWorkflow(canvas, workflow);
return workflow;
}
function addWorkflow(canvas: ComfyGraphCanvas, workflow: ComfyWorkflow) {
const state = get(store);
state.openedWorkflows.push(workflow);
state.openedWorkflowsByID[workflow.id] = workflow;
@@ -317,7 +331,6 @@ function closeWorkflow(canvas: ComfyGraphCanvas, index: number) {
layoutStates.remove(workflow.id)
state.openedWorkflows.splice(index, 1)
delete state.openedWorkflowsByID[workflow.id]
let newIndex = clamp(index, 0, state.openedWorkflows.length - 1)
@@ -372,6 +385,7 @@ const workflowStateStore: WritableWorkflowStateStore =
getActiveWorkflow,
createNewWorkflow,
openWorkflow,
addWorkflow,
closeWorkflow,
closeAllWorkflows,
setActiveWorkflow,