Extract flashButton in utils
This commit is contained in:
+1
-24
@@ -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
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user