Extract flashButton in utils

This commit is contained in:
relhamdi
2026-06-04 00:19:08 +02:00
parent 60634daa6f
commit a66491b03c
3 changed files with 28 additions and 48 deletions
+1 -24
View File
@@ -1,6 +1,7 @@
import { API_ROOT, COLORS, EMPTY_VALUE } from "./constants.js";
import {
findWidget,
flashButton,
registerNode,
setWidgetValue,
waitForWidgets,
@@ -66,30 +67,6 @@ const loadFileIntoWidgets = async (file, node) => {
// --- Buttons ---
const flashButton = (node, index, flashLabel) => {
const buttonRowWidget = node.widgets?.find(
(w) => w.name === "action_buttons",
);
if (!buttonRowWidget) return;
const btn = buttonRowWidget.buttons[index];
// Cancel previous timer if existing
if (btn._flashTimer) clearTimeout(btn._flashTimer);
// Save original if not flashing
if (!btn._originalLabel) btn._originalLabel = btn.label;
btn.label = flashLabel;
if (node.graph) node.graph.setDirtyCanvas(true, true);
btn._flashTimer = setTimeout(() => {
btn.label = btn._originalLabel;
btn._originalLabel = null;
btn._flashTimer = null;
if (node.graph) node.graph.setDirtyCanvas(true, true);
}, 1500);
};
const handleNew = async (node, characterFileWidget) => {
const name = prompt("New character file name (e.g. characters/Alice):");
if (!name?.trim()) return;
+1 -24
View File
@@ -1,6 +1,7 @@
import { API_ROOT, COLORS, EMPTY_VALUE } from "./constants.js";
import {
findWidget,
flashButton,
registerNode,
setWidgetValue,
waitForWidgets,
@@ -265,30 +266,6 @@ const loadFileIntoWidgets = async (
// --- Buttons ---
const flashButton = (node, index, flashLabel) => {
const buttonRowWidget = node.widgets.find(
(w) => w.name === "action_buttons",
);
if (!buttonRowWidget) return;
const btn = buttonRowWidget.buttons[index];
// Cancel previous timer if existing
if (btn._flashTimer) clearTimeout(btn._flashTimer);
// Save original if not flashing
if (!btn._originalLabel) btn._originalLabel = btn.label;
btn.label = flashLabel;
if (node.graph) node.graph.setDirtyCanvas(true, true);
btn._flashTimer = setTimeout(() => {
btn.label = btn._originalLabel;
btn._originalLabel = null;
btn._flashTimer = null;
if (node.graph) node.graph.setDirtyCanvas(true, true);
}, 1500);
};
const handleNew = async (node, styleFileWidget, addButtonWidget) => {
const name = prompt("New style file name (e.g. anime/illustrious):");
if (!name?.trim()) return;
+26
View File
@@ -380,3 +380,29 @@ export const waitForWidgets = (node, callback) => {
};
requestAnimationFrame(tryAttach);
};
// --- Buttons ---
export const flashButton = (node, index, flashLabel) => {
const buttonRowWidget = node.widgets.find(
(w) => w.name === "action_buttons",
);
if (!buttonRowWidget) return;
const btn = buttonRowWidget.buttons[index];
// Cancel previous timer if existing
if (btn._flashTimer) clearTimeout(btn._flashTimer);
// Save original if not flashing
if (!btn._originalLabel) btn._originalLabel = btn.label;
btn.label = flashLabel;
if (node.graph) node.graph.setDirtyCanvas(true, true);
btn._flashTimer = setTimeout(() => {
btn.label = btn._originalLabel;
btn._originalLabel = null;
btn._flashTimer = null;
if (node.graph) node.graph.setDirtyCanvas(true, true);
}, 1500);
};