mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-22 00:17:05 +08:00
various fixes
add close unsaved warning
This commit is contained in:
parent
c6e8c3be6f
commit
35d3ecbdff
@ -44,6 +44,8 @@ export class ChangeTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkState() {
|
checkState() {
|
||||||
|
if(!this.app.graph) return;
|
||||||
|
|
||||||
const currentState = this.app.graph.serialize();
|
const currentState = this.app.graph.serialize();
|
||||||
if (!this.activeState) {
|
if (!this.activeState) {
|
||||||
this.activeState = clone(currentState);
|
this.activeState = clone(currentState);
|
||||||
|
|||||||
64
web/scripts/ui/components/asyncDialog.js
Normal file
64
web/scripts/ui/components/asyncDialog.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import { ComfyDialog } from "../dialog.js";
|
||||||
|
import { $el } from "../../ui.js";
|
||||||
|
|
||||||
|
export class ComfyAsyncDialog extends ComfyDialog {
|
||||||
|
#resolve;
|
||||||
|
|
||||||
|
constructor(actions) {
|
||||||
|
super(
|
||||||
|
"dialog.comfy-dialog",
|
||||||
|
actions.map((opt) => {
|
||||||
|
if (typeof opt === "string") {
|
||||||
|
opt = { text: opt };
|
||||||
|
}
|
||||||
|
return $el("button.comfyui-button", {
|
||||||
|
type: "button",
|
||||||
|
textContent: opt.text,
|
||||||
|
onclick: () => this.close(opt.value ?? opt.text),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
show(html) {
|
||||||
|
this.element.addEventListener("close", () => {
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
super.show(html);
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.#resolve = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
showModal(html) {
|
||||||
|
this.element.addEventListener("close", () => {
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
super.show(html);
|
||||||
|
this.element.showModal();
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.#resolve = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
close(result = null) {
|
||||||
|
this.#resolve(result);
|
||||||
|
this.element.close();
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
static async prompt({ title = null, message, actions }) {
|
||||||
|
const dialog = new ComfyAsyncDialog(actions);
|
||||||
|
const content = [$el("span", message)];
|
||||||
|
if (title) {
|
||||||
|
content.unshift($el("h3", title));
|
||||||
|
}
|
||||||
|
const res = await dialog.showModal(content);
|
||||||
|
dialog.element.remove();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,21 +1,26 @@
|
|||||||
import { $el } from "../ui.js";
|
import { $el } from "../ui.js";
|
||||||
|
|
||||||
export class ComfyDialog extends EventTarget {
|
export class ComfyDialog extends EventTarget {
|
||||||
constructor(type = "div") {
|
#buttons;
|
||||||
|
|
||||||
|
constructor(type = "div", buttons = null) {
|
||||||
super();
|
super();
|
||||||
|
this.#buttons = buttons;
|
||||||
this.element = $el(type + ".comfy-modal", { parent: document.body }, [
|
this.element = $el(type + ".comfy-modal", { parent: document.body }, [
|
||||||
$el("div.comfy-modal-content", [$el("p", { $: (p) => (this.textElement = p) }), ...this.createButtons()]),
|
$el("div.comfy-modal-content", [$el("p", { $: (p) => (this.textElement = p) }), ...this.createButtons()]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
createButtons() {
|
createButtons() {
|
||||||
return [
|
return (
|
||||||
|
this.#buttons ?? [
|
||||||
$el("button", {
|
$el("button", {
|
||||||
type: "button",
|
type: "button",
|
||||||
textContent: "Close",
|
textContent: "Close",
|
||||||
onclick: () => this.close(),
|
onclick: () => this.close(),
|
||||||
}),
|
}),
|
||||||
];
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { api } from "../../api.js";
|
|||||||
import { ComfyPopup } from "../components/popup.js";
|
import { ComfyPopup } from "../components/popup.js";
|
||||||
import { createSpinner } from "../spinner.js";
|
import { createSpinner } from "../spinner.js";
|
||||||
import { ComfyWorkflow, trimJsonExt } from "../../workflows.js";
|
import { ComfyWorkflow, trimJsonExt } from "../../workflows.js";
|
||||||
import { ComfyDialog } from "../dialog.js";
|
import { ComfyAsyncDialog } from "../components/asyncDialog.js";
|
||||||
|
|
||||||
export class ComfyWorkflowsMenu {
|
export class ComfyWorkflowsMenu {
|
||||||
#first = true;
|
#first = true;
|
||||||
@ -213,6 +213,8 @@ export class ComfyWorkflowsMenu {
|
|||||||
const getExtraMenuOptions = nodeType.prototype["getExtraMenuOptions"];
|
const getExtraMenuOptions = nodeType.prototype["getExtraMenuOptions"];
|
||||||
nodeType.prototype["getExtraMenuOptions"] = function (_, options) {
|
nodeType.prototype["getExtraMenuOptions"] = function (_, options) {
|
||||||
const r = getExtraMenuOptions?.apply?.(this, arguments);
|
const r = getExtraMenuOptions?.apply?.(this, arguments);
|
||||||
|
|
||||||
|
if (app.ui.settings.getSettingValue("Comfy.UseNewMenu", false) === true) {
|
||||||
const t = /** @type { {imageIndex?: number, overIndex?: number, imgs: string[]} } */ /** @type {any} */ (this);
|
const t = /** @type { {imageIndex?: number, overIndex?: number, imgs: string[]} } */ /** @type {any} */ (this);
|
||||||
let img;
|
let img;
|
||||||
if (t.imageIndex != null) {
|
if (t.imageIndex != null) {
|
||||||
@ -247,6 +249,7 @@ export class ComfyWorkflowsMenu {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
};
|
};
|
||||||
@ -277,6 +280,7 @@ export class ComfyWorkflowsContent {
|
|||||||
icon: "file-code",
|
icon: "file-code",
|
||||||
iconSize: 18,
|
iconSize: 18,
|
||||||
classList: "comfyui-button primary",
|
classList: "comfyui-button primary",
|
||||||
|
tooltip: "Load default workflow",
|
||||||
action: () => {
|
action: () => {
|
||||||
popup.open = false;
|
popup.open = false;
|
||||||
app.loadGraphData();
|
app.loadGraphData();
|
||||||
@ -286,6 +290,7 @@ export class ComfyWorkflowsContent {
|
|||||||
content: "Browse",
|
content: "Browse",
|
||||||
icon: "folder",
|
icon: "folder",
|
||||||
iconSize: 18,
|
iconSize: 18,
|
||||||
|
tooltip: "Browse for an image or exported workflow",
|
||||||
action: () => {
|
action: () => {
|
||||||
popup.open = false;
|
popup.open = false;
|
||||||
app.ui.loadFile();
|
app.ui.loadFile();
|
||||||
@ -295,6 +300,7 @@ export class ComfyWorkflowsContent {
|
|||||||
content: "Blank",
|
content: "Blank",
|
||||||
icon: "plus-thick",
|
icon: "plus-thick",
|
||||||
iconSize: 18,
|
iconSize: 18,
|
||||||
|
tooltip: "Create a new blank workflow",
|
||||||
action: () => {
|
action: () => {
|
||||||
app.workflowManager.setWorkflow(null);
|
app.workflowManager.setWorkflow(null);
|
||||||
app.clean();
|
app.clean();
|
||||||
@ -351,6 +357,7 @@ export class ComfyWorkflowsContent {
|
|||||||
icon: "close",
|
icon: "close",
|
||||||
iconSize: 18,
|
iconSize: 18,
|
||||||
classList: "comfyui-button comfyui-workflows-file-action",
|
classList: "comfyui-button comfyui-workflows-file-action",
|
||||||
|
tooltip: "Close workflow",
|
||||||
action: (e) => {
|
action: (e) => {
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
this.app.workflowManager.closeWorkflow(w);
|
this.app.workflowManager.closeWorkflow(w);
|
||||||
@ -469,6 +476,11 @@ export class ComfyWorkflowsContent {
|
|||||||
return workflow.isFavorite ? "star-off" : "star-outline";
|
return workflow.isFavorite ? "star-off" : "star-outline";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param {ComfyWorkflow} workflow */
|
||||||
|
#getFavoriteTooltip(workflow) {
|
||||||
|
return workflow.isFavorite ? "Remove this workflow from your favorites" : "Add this workflow to your favorites";
|
||||||
|
}
|
||||||
|
|
||||||
/** @param {ComfyWorkflow} workflow */
|
/** @param {ComfyWorkflow} workflow */
|
||||||
#getFavoriteButton(workflow, primary) {
|
#getFavoriteButton(workflow, primary) {
|
||||||
return new ComfyButton({
|
return new ComfyButton({
|
||||||
@ -476,6 +488,7 @@ export class ComfyWorkflowsContent {
|
|||||||
overIcon: this.#getFavoriteOverIcon(workflow),
|
overIcon: this.#getFavoriteOverIcon(workflow),
|
||||||
iconSize: 18,
|
iconSize: 18,
|
||||||
classList: "comfyui-button comfyui-workflows-file-action-favorite" + (primary ? " comfyui-workflows-file-action-primary" : ""),
|
classList: "comfyui-button comfyui-workflows-file-action-favorite" + (primary ? " comfyui-workflows-file-action-primary" : ""),
|
||||||
|
tooltip: this.#getFavoriteTooltip(workflow),
|
||||||
action: (e) => {
|
action: (e) => {
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
workflow.favorite(!workflow.isFavorite);
|
workflow.favorite(!workflow.isFavorite);
|
||||||
@ -613,24 +626,20 @@ class WorkflowElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WidgetSelectionDialog extends ComfyDialog {
|
class WidgetSelectionDialog extends ComfyAsyncDialog {
|
||||||
#options;
|
#options;
|
||||||
#resolve;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array<{widget: {name: string}, node: {pos: [number, number], title: string, id: string, type: string}}>} options
|
* @param {Array<{widget: {name: string}, node: {pos: [number, number], title: string, id: string, type: string}}>} options
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super("dialog");
|
super();
|
||||||
this.#options = options;
|
this.#options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
show(app) {
|
show(app) {
|
||||||
this.element.addEventListener("close", () => {
|
|
||||||
this.close();
|
|
||||||
});
|
|
||||||
this.element.classList.add("comfy-widget-selection-dialog");
|
this.element.classList.add("comfy-widget-selection-dialog");
|
||||||
super.show(
|
return super.show(
|
||||||
$el("div", [
|
$el("div", [
|
||||||
$el("h2", "Select image target"),
|
$el("h2", "Select image target"),
|
||||||
$el(
|
$el(
|
||||||
@ -649,6 +658,7 @@ class WidgetSelectionDialog extends ComfyDialog {
|
|||||||
app.canvas.ds.offset[0] = -opt.node.pos[0] + 50;
|
app.canvas.ds.offset[0] = -opt.node.pos[0] + 50;
|
||||||
app.canvas.ds.offset[1] = -opt.node.pos[1] + 50;
|
app.canvas.ds.offset[1] = -opt.node.pos[1] + 50;
|
||||||
app.canvas.selectNode(opt.node);
|
app.canvas.selectNode(opt.node);
|
||||||
|
app.graph.setDirtyCanvas(true, true);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Show"
|
"Show"
|
||||||
@ -657,8 +667,7 @@ class WidgetSelectionDialog extends ComfyDialog {
|
|||||||
"button.comfyui-button.primary",
|
"button.comfyui-button.primary",
|
||||||
{
|
{
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
this.#resolve(opt);
|
this.close(opt);
|
||||||
this.close();
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Select"
|
"Select"
|
||||||
@ -668,13 +677,5 @@ class WidgetSelectionDialog extends ComfyDialog {
|
|||||||
),
|
),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
return new Promise((resolve) => {
|
|
||||||
this.#resolve = resolve;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
|
||||||
this.#resolve();
|
|
||||||
super.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { api } from "./api.js";
|
import { api } from "./api.js";
|
||||||
import { ChangeTracker } from "./changeTracker.js";
|
import { ChangeTracker } from "./changeTracker.js";
|
||||||
|
import { ComfyAsyncDialog } from "./ui/components/asyncDialog.js";
|
||||||
import { getStorageValue, setStorageValue } from "./utils.js";
|
import { getStorageValue, setStorageValue } from "./utils.js";
|
||||||
|
|
||||||
function appendJsonExt(path) {
|
function appendJsonExt(path) {
|
||||||
@ -171,10 +172,34 @@ export class ComfyWorkflowManager extends EventTarget {
|
|||||||
/**
|
/**
|
||||||
* @param {ComfyWorkflow} workflow
|
* @param {ComfyWorkflow} workflow
|
||||||
*/
|
*/
|
||||||
async closeWorkflow(workflow) {
|
async closeWorkflow(workflow, warnIfUnsaved = true) {
|
||||||
if (!workflow.isOpen) {
|
if (!workflow.isOpen) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (workflow.unsaved && warnIfUnsaved) {
|
||||||
|
const res = await ComfyAsyncDialog.prompt({
|
||||||
|
title: "Save Changes?",
|
||||||
|
message: `Do you want to save changes to "${workflow.path ?? workflow.name}" before closing?`,
|
||||||
|
actions: ["Yes", "No", "Cancel"],
|
||||||
|
});
|
||||||
|
if (res === "Yes") {
|
||||||
|
const active = this.activeWorkflow;
|
||||||
|
if (active !== workflow) {
|
||||||
|
// We need to switch to the workflow to save it
|
||||||
|
await workflow.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await workflow.save())) {
|
||||||
|
// Save was canceled, restore the previous workflow
|
||||||
|
if (active !== workflow) {
|
||||||
|
await active.load();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (res === "Cancel") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
workflow.changeTracker = null;
|
workflow.changeTracker = null;
|
||||||
this.openWorkflows.splice(this.openWorkflows.indexOf(workflow), 1);
|
this.openWorkflows.splice(this.openWorkflows.indexOf(workflow), 1);
|
||||||
if (this.openWorkflows.length) {
|
if (this.openWorkflows.length) {
|
||||||
@ -284,9 +309,9 @@ export class ComfyWorkflow {
|
|||||||
|
|
||||||
async save(saveAs = false) {
|
async save(saveAs = false) {
|
||||||
if (!this.path || saveAs) {
|
if (!this.path || saveAs) {
|
||||||
await this.#save(null, false);
|
return !!(await this.#save(null, false));
|
||||||
} else {
|
} else {
|
||||||
await this.#save(this.path, true);
|
return !!(await this.#save(this.path, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,6 +356,7 @@ export class ComfyWorkflow {
|
|||||||
await this.favorite(true);
|
await this.favorite(true);
|
||||||
}
|
}
|
||||||
this.manager.dispatchEvent(new CustomEvent("rename", { detail: this }));
|
this.manager.dispatchEvent(new CustomEvent("rename", { detail: this }));
|
||||||
|
setStorageValue("Comfy.PreviousWorkflow", this.path ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
async insert() {
|
async insert() {
|
||||||
@ -405,6 +431,7 @@ export class ComfyWorkflow {
|
|||||||
await this.manager.loadWorkflows();
|
await this.manager.loadWorkflows();
|
||||||
this.unsaved = false;
|
this.unsaved = false;
|
||||||
this.manager.dispatchEvent(new CustomEvent("rename", { detail: this }));
|
this.manager.dispatchEvent(new CustomEvent("rename", { detail: this }));
|
||||||
|
setStorageValue("Comfy.PreviousWorkflow", this.path ?? "");
|
||||||
} else if (path !== this.path) {
|
} else if (path !== this.path) {
|
||||||
// Saved as, open the new copy
|
// Saved as, open the new copy
|
||||||
await this.manager.loadWorkflows();
|
await this.manager.loadWorkflows();
|
||||||
@ -415,5 +442,7 @@ export class ComfyWorkflow {
|
|||||||
this.unsaved = false;
|
this.unsaved = false;
|
||||||
this.manager.dispatchEvent(new CustomEvent("save", { detail: this }));
|
this.manager.dispatchEvent(new CustomEvent("save", { detail: this }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -372,6 +372,32 @@ dialog::backdrop {
|
|||||||
background: rgba(0, 0, 0, 0.5);
|
background: rgba(0, 0, 0, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comfy-dialog.comfy-modal {
|
||||||
|
top: 0;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
border-color: var(--bg-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-dialog .comfy-modal-content {
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
color: var(--fg-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-dialog .comfy-modal-content h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-dialog .comfy-modal-content > p {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfy-dialog .comfy-modal-content > .comfyui-button {
|
||||||
|
flex: 1;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
#comfy-settings-dialog {
|
#comfy-settings-dialog {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
width: 41rem;
|
width: 41rem;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user