Enhance notification system and auto-correct node_id

Adds a modern, type-based notification UI with support for success, error, info, warning, and alert styles, including a new showAlertNotification function. CanvasState now auto-corrects the node_id widget before saving state and notifies the user if a correction occurs. CanvasView centering logic now uses the actual canvas container for more accurate viewport adjustments.
This commit is contained in:
Dariusz L
2025-07-28 00:28:15 +02:00
parent 7701ceda56
commit bfea0cdbab
5 changed files with 515 additions and 40 deletions

View File

@@ -1,5 +1,6 @@
import {getCanvasState, setCanvasState, saveImage, getImage} from "./db.js";
import {createModuleLogger} from "./utils/LoggerUtils.js";
import {showAlertNotification} from "./utils/NotificationUtils.js";
import {generateUUID, cloneLayers, getStateSignature, debounce, createCanvas} from "./utils/CommonUtils.js";
import {withErrorHandling} from "./ErrorHandler.js";
import type { Canvas } from './Canvas';
@@ -272,6 +273,23 @@ export class CanvasState {
return;
}
// Auto-correct node_id widget if needed before saving state
if (this.canvas.node && this.canvas.node.widgets) {
const nodeIdWidget = this.canvas.node.widgets.find((w: any) => w.name === "node_id");
if (nodeIdWidget) {
const correctId = String(this.canvas.node.id);
if (nodeIdWidget.value !== correctId) {
const prevValue = nodeIdWidget.value;
nodeIdWidget.value = correctId;
log.warn(`[CanvasState] node_id widget value (${prevValue}) did not match node.id (${correctId}) - auto-corrected (saveStateToDB).`);
showAlertNotification(
`The value of node_id (${prevValue}) did not match the node number (${correctId}) and was automatically corrected.
If you see dark images or masks in the output, make sure node_id is set to ${correctId}.`
);
}
}
}
log.info("Preparing state to be sent to worker...");
const layers = await this._prepareLayers();
const state = {