mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-20 04:21:27 -03:00
refactor(nodes): declare loras widget as LORAS input type on lora nodes
This commit is contained in:
@@ -39,6 +39,7 @@ class CreateHookLoraLM:
|
||||
),
|
||||
},
|
||||
),
|
||||
"loras": ("LORAS", {}),
|
||||
},
|
||||
"optional": FlexibleOptionalInputType(any_type),
|
||||
}
|
||||
@@ -52,7 +53,7 @@ class CreateHookLoraLM:
|
||||
RETURN_NAMES = ("HOOKS", "trigger_words", "active_loras")
|
||||
FUNCTION = "create_hook"
|
||||
|
||||
def create_hook(self, text: str, **kwargs):
|
||||
def create_hook(self, text: str, loras, **kwargs):
|
||||
"""Create a HookGroup from the selected LoRAs, chained with prev_hooks.
|
||||
|
||||
Each active LoRA from the widget is loaded and wrapped in a WeightHook
|
||||
@@ -73,7 +74,7 @@ class CreateHookLoraLM:
|
||||
all_trigger_words: list[str] = []
|
||||
active_loras: list[tuple[str, float, float]] = []
|
||||
|
||||
for lora in get_loras_list(kwargs):
|
||||
for lora in get_loras_list({"loras": loras}):
|
||||
if not lora.get("active", False):
|
||||
continue
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@ def _collect_stack_entries(lora_stack):
|
||||
return entries
|
||||
|
||||
|
||||
def _collect_widget_entries(kwargs):
|
||||
def _collect_widget_entries(loras):
|
||||
entries = []
|
||||
for lora in get_loras_list(kwargs):
|
||||
for lora in get_loras_list({"loras": loras}):
|
||||
if not lora.get("active", False):
|
||||
continue
|
||||
lora_name = apply_lora_syntax_format(lora["name"])
|
||||
@@ -139,6 +139,7 @@ class LoraLoaderLM:
|
||||
"placeholder": "Search LoRAs to add...",
|
||||
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
||||
}),
|
||||
"loras": ("LORAS", {}),
|
||||
},
|
||||
"optional": FlexibleOptionalInputType(any_type),
|
||||
}
|
||||
@@ -152,12 +153,12 @@ class LoraLoaderLM:
|
||||
RETURN_NAMES = ("MODEL", "CLIP", "trigger_words", "loaded_loras")
|
||||
FUNCTION = "load_loras"
|
||||
|
||||
def load_loras(self, model, text, **kwargs):
|
||||
"""Loads multiple LoRAs based on the kwargs input and lora_stack."""
|
||||
def load_loras(self, model, text, loras, **kwargs):
|
||||
"""Loads multiple LoRAs based on the widget input and lora_stack."""
|
||||
del text
|
||||
clip = kwargs.get("clip", None)
|
||||
lora_entries = _collect_stack_entries(kwargs.get("lora_stack", None))
|
||||
lora_entries.extend(_collect_widget_entries(kwargs))
|
||||
lora_entries.extend(_collect_widget_entries(loras))
|
||||
|
||||
nunchaku_model_kind = detect_nunchaku_model_kind(model)
|
||||
if nunchaku_model_kind == "flux":
|
||||
|
||||
@@ -18,6 +18,7 @@ class LoraStackerLM:
|
||||
"placeholder": "Search LoRAs to add...",
|
||||
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
||||
}),
|
||||
"loras": ("LORAS", {}),
|
||||
},
|
||||
"optional": FlexibleOptionalInputType(any_type),
|
||||
}
|
||||
@@ -31,8 +32,8 @@ class LoraStackerLM:
|
||||
RETURN_NAMES = ("LORA_STACK", "trigger_words", "active_loras")
|
||||
FUNCTION = "stack_loras"
|
||||
|
||||
def stack_loras(self, text, **kwargs):
|
||||
"""Stacks multiple LoRAs based on the kwargs input without loading them."""
|
||||
def stack_loras(self, text, loras, **kwargs):
|
||||
"""Stacks multiple LoRAs based on the widget input without loading them."""
|
||||
stack = []
|
||||
active_loras = []
|
||||
all_trigger_words = []
|
||||
@@ -47,8 +48,8 @@ class LoraStackerLM:
|
||||
_, trigger_words = get_lora_info(lora_name)
|
||||
all_trigger_words.extend(trigger_words)
|
||||
|
||||
# Process loras from kwargs with support for both old and new formats
|
||||
loras_list = get_loras_list(kwargs)
|
||||
# Process loras from the widget with support for both old and new formats
|
||||
loras_list = get_loras_list({"loras": loras})
|
||||
for lora in loras_list:
|
||||
if not lora.get('active', False):
|
||||
continue
|
||||
|
||||
@@ -31,6 +31,7 @@ class WanVideoLoraSelectLM:
|
||||
"placeholder": "Search LoRAs to add...",
|
||||
"tooltip": "Format: <lora:lora_name:strength> separated by spaces or punctuation",
|
||||
}),
|
||||
"loras": ("LORAS", {}),
|
||||
},
|
||||
"optional": FlexibleOptionalInputType(any_type),
|
||||
}
|
||||
@@ -44,7 +45,7 @@ class WanVideoLoraSelectLM:
|
||||
RETURN_NAMES = ("lora", "trigger_words", "active_loras")
|
||||
FUNCTION = "process_loras"
|
||||
|
||||
def process_loras(self, text, low_mem_load=False, merge_loras=True, **kwargs):
|
||||
def process_loras(self, text, loras, low_mem_load=False, merge_loras=True, **kwargs):
|
||||
loras_list = []
|
||||
all_trigger_words = []
|
||||
active_loras = []
|
||||
@@ -62,8 +63,8 @@ class WanVideoLoraSelectLM:
|
||||
selected_blocks = blocks.get("selected_blocks", {})
|
||||
layer_filter = blocks.get("layer_filter", "")
|
||||
|
||||
# Process loras from kwargs with support for both old and new formats
|
||||
loras_from_widget = get_loras_list(kwargs)
|
||||
# Process loras from the widget with support for both old and new formats
|
||||
loras_from_widget = get_loras_list({"loras": loras})
|
||||
for lora in loras_from_widget:
|
||||
if not lora.get('active', False):
|
||||
continue
|
||||
|
||||
@@ -4,13 +4,11 @@ const {
|
||||
APP_MODULE,
|
||||
API_MODULE,
|
||||
UTILS_MODULE,
|
||||
LORAS_WIDGET_MODULE,
|
||||
LORA_LOADER_MODULE,
|
||||
} = vi.hoisted(() => ({
|
||||
APP_MODULE: new URL("../../../scripts/app.js", import.meta.url).pathname,
|
||||
API_MODULE: new URL("../../../scripts/api.js", import.meta.url).pathname,
|
||||
UTILS_MODULE: new URL("../../../web/comfyui/utils.js", import.meta.url).pathname,
|
||||
LORAS_WIDGET_MODULE: new URL("../../../web/comfyui/loras_widget.js", import.meta.url).pathname,
|
||||
LORA_LOADER_MODULE: new URL("../../../web/comfyui/lora_loader.js", import.meta.url).pathname,
|
||||
}));
|
||||
|
||||
@@ -59,12 +57,6 @@ vi.mock(UTILS_MODULE, () => ({
|
||||
LORA_PATTERN: /<lora:([^:]+):([-\d.]+)(?::([-\d.]+))?>/g,
|
||||
}));
|
||||
|
||||
const addLorasWidget = vi.fn();
|
||||
|
||||
vi.mock(LORAS_WIDGET_MODULE, () => ({
|
||||
addLorasWidget,
|
||||
}));
|
||||
|
||||
describe("Lora Loader trigger word updates", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
@@ -82,11 +74,6 @@ describe("Lora Loader trigger word updates", () => {
|
||||
|
||||
getWidgetByName.mockClear();
|
||||
getWidgetSerializedValue.mockClear();
|
||||
|
||||
addLorasWidget.mockClear();
|
||||
addLorasWidget.mockImplementation((_node, _name, _opts, callback) => ({
|
||||
widget: { value: [], callback },
|
||||
}));
|
||||
});
|
||||
|
||||
it("refreshes trigger word toggles after LoRA syntax edits in the input widget", async () => {
|
||||
@@ -113,9 +100,18 @@ describe("Lora Loader trigger word updates", () => {
|
||||
options: {},
|
||||
};
|
||||
|
||||
// Declared LORAS input widget, created by the LoraManager.LorasWidget
|
||||
// extension and taken over by the loader's onNodeCreated.
|
||||
const lorasWidget = {
|
||||
name: "loras",
|
||||
value: [],
|
||||
options: {},
|
||||
callback: null, // Will be set by onNodeCreated
|
||||
};
|
||||
|
||||
const node = {
|
||||
comfyClass: "Lora Loader (LoraManager)",
|
||||
widgets: [metadataWidget, inputWidget],
|
||||
widgets: [metadataWidget, inputWidget, lorasWidget],
|
||||
addInput: vi.fn(),
|
||||
graph: {},
|
||||
};
|
||||
@@ -124,8 +120,9 @@ describe("Lora Loader trigger word updates", () => {
|
||||
|
||||
// The widget is now the AUTOCOMPLETE_TEXT_LORAS type, created automatically by Vue widgets
|
||||
expect(node.inputWidget).toBe(inputWidget);
|
||||
expect(node.lorasWidget).toBeDefined();
|
||||
expect(node.lorasWidget).toBe(lorasWidget);
|
||||
expect(getWidgetByName).toHaveBeenCalledWith(node, "text");
|
||||
expect(typeof lorasWidget.callback).toBe("function");
|
||||
|
||||
// The callback should have been set up by onNodeCreated
|
||||
const inputCallback = inputWidget.callback;
|
||||
|
||||
@@ -4,14 +4,12 @@ const {
|
||||
APP_MODULE,
|
||||
API_MODULE,
|
||||
UTILS_MODULE,
|
||||
LORAS_WIDGET_MODULE,
|
||||
LORA_LOADER_MODULE,
|
||||
LORA_STACKER_MODULE,
|
||||
} = vi.hoisted(() => ({
|
||||
APP_MODULE: new URL("../../../scripts/app.js", import.meta.url).pathname,
|
||||
API_MODULE: new URL("../../../scripts/api.js", import.meta.url).pathname,
|
||||
UTILS_MODULE: new URL("../../../web/comfyui/utils.js", import.meta.url).pathname,
|
||||
LORAS_WIDGET_MODULE: new URL("../../../web/comfyui/loras_widget.js", import.meta.url).pathname,
|
||||
LORA_LOADER_MODULE: new URL("../../../web/comfyui/lora_loader.js", import.meta.url).pathname,
|
||||
LORA_STACKER_MODULE: new URL("../../../web/comfyui/lora_stacker.js", import.meta.url).pathname,
|
||||
}));
|
||||
@@ -80,12 +78,6 @@ vi.mock(UTILS_MODULE, async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
const addLorasWidget = vi.fn();
|
||||
|
||||
vi.mock(LORAS_WIDGET_MODULE, () => ({
|
||||
addLorasWidget,
|
||||
}));
|
||||
|
||||
describe("Node mode change handling", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
@@ -109,11 +101,6 @@ describe("Node mode change handling", () => {
|
||||
|
||||
getWidgetByName.mockClear();
|
||||
getWidgetSerializedValue.mockClear();
|
||||
|
||||
addLorasWidget.mockClear();
|
||||
addLorasWidget.mockImplementation((_node, _name, _opts, callback) => ({
|
||||
widget: { value: [], callback },
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Lora Stacker mode change handling", () => {
|
||||
@@ -222,6 +209,13 @@ describe("Node mode change handling", () => {
|
||||
options: {},
|
||||
callback: null, // Will be set by onNodeCreated
|
||||
},
|
||||
{
|
||||
// Declared LORAS input widget, taken over by onNodeCreated
|
||||
name: "loras",
|
||||
value: [],
|
||||
options: {},
|
||||
callback: null,
|
||||
},
|
||||
],
|
||||
addInput: vi.fn(),
|
||||
mode: 0, // Initial mode
|
||||
|
||||
@@ -197,5 +197,6 @@ def test_lora_loader_qwen_model_raises_clear_error_when_helper_import_fails(monk
|
||||
loader.load_loras(
|
||||
qwen_model,
|
||||
"",
|
||||
[],
|
||||
lora_stack=[("stack_qwen.safetensors", 0.6, 0.1)],
|
||||
)
|
||||
|
||||
@@ -85,9 +85,6 @@ export function createAutocompleteTextWidgetInstanceId() {
|
||||
return autocompleteTextWidgetInstanceId
|
||||
}
|
||||
|
||||
// Cache for dynamically loaded addLorasWidget module
|
||||
let addLorasWidgetCache: any = null
|
||||
|
||||
// @ts-ignore
|
||||
function createLoraPoolWidget(node) {
|
||||
const container = document.createElement('div')
|
||||
@@ -876,91 +873,6 @@ app.registerExtension({
|
||||
CYCLER_CONFIG(node) {
|
||||
return createLoraCyclerWidget(node)
|
||||
},
|
||||
// @ts-ignore
|
||||
async LORAS(node: any) {
|
||||
if (!addLorasWidgetCache) {
|
||||
// @ts-ignore
|
||||
const module = await import(/* @vite-ignore */ '../loras_widget.js')
|
||||
addLorasWidgetCache = module.addLorasWidget
|
||||
}
|
||||
// Check if this is a randomizer node to enable lock buttons
|
||||
const isRandomizerNode = node.comfyClass === 'Lora Randomizer (LoraManager)'
|
||||
|
||||
// For randomizer nodes, add a callback to update connected trigger words
|
||||
const callback = isRandomizerNode ? () => {
|
||||
updateDownstreamLoaders(node)
|
||||
} : null
|
||||
|
||||
const opts: { isRandomizerNode?: boolean; onSelectionChange?: (selection: any) => void } = {
|
||||
isRandomizerNode,
|
||||
}
|
||||
if (isRandomizerNode) {
|
||||
opts.onSelectionChange = async (selection: any) => {
|
||||
if (!selection?.name || !selection?.active) return
|
||||
|
||||
// Walk outputs to find directly connected Lora Info nodes
|
||||
const infoNodes: any[] = []
|
||||
if (node.outputs) {
|
||||
for (const output of node.outputs) {
|
||||
if (!output?.links?.length) continue
|
||||
for (const linkId of output.links) {
|
||||
const links = node.graph?.links
|
||||
if (!links) continue
|
||||
const link = Array.isArray(links) ? links[linkId] : links.get?.(linkId)
|
||||
if (!link) continue
|
||||
const targetNode = node.graph?.getNodeById?.(link.target_id)
|
||||
if (targetNode?.comfyClass === 'Lora Info (LoraManager)') {
|
||||
infoNodes.push(targetNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (infoNodes.length === 0) return
|
||||
|
||||
// Bump request token to guard against stale async responses
|
||||
for (const infoNode of infoNodes) {
|
||||
infoNode.__loraInfoReqId = (infoNode.__loraInfoReqId || 0) + 1
|
||||
}
|
||||
const reqIdSnapshot = new Map<any, number>()
|
||||
for (const infoNode of infoNodes) {
|
||||
reqIdSnapshot.set(infoNode, infoNode.__loraInfoReqId)
|
||||
}
|
||||
|
||||
// Fetch notes via the real ComfyUI api
|
||||
let infoData: any
|
||||
try {
|
||||
const response = await api.fetchApi(
|
||||
`/lm/loras/get-notes?name=${encodeURIComponent(selection.name)}`,
|
||||
{ method: 'GET' }
|
||||
)
|
||||
if (response?.ok) {
|
||||
const data = await response.json()
|
||||
infoData = {
|
||||
name: selection.name,
|
||||
notes: data?.notes || '',
|
||||
filePath: data?.file_path || '',
|
||||
}
|
||||
} else {
|
||||
infoData = { name: selection.name, notes: '[Error loading notes]', filePath: '' }
|
||||
}
|
||||
} catch {
|
||||
infoData = { name: selection.name, notes: '[Error loading notes]', filePath: '' }
|
||||
}
|
||||
|
||||
for (const infoNode of infoNodes) {
|
||||
if (infoNode.__loraInfoReqId !== reqIdSnapshot.get(infoNode)) {
|
||||
continue
|
||||
}
|
||||
if (typeof infoNode._setLoraInfo === 'function') {
|
||||
infoNode._setLoraInfo(infoData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addLorasWidgetCache(node, 'loras', opts, callback)
|
||||
},
|
||||
// Autocomplete text widget for LoRAs (used by Lora Loader, Lora Stacker, WanVideo Lora Select)
|
||||
// @ts-ignore
|
||||
AUTOCOMPLETE_TEXT_LORAS(node) {
|
||||
|
||||
@@ -7,10 +7,7 @@ import {
|
||||
getWidgetByName,
|
||||
getWidgetSerializedValue,
|
||||
} from "./utils.js";
|
||||
import { addLorasWidget } from "./loras_widget.js";
|
||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "LoraManager.CreateHookLora",
|
||||
@@ -62,39 +59,37 @@ app.registerExtension({
|
||||
}
|
||||
});
|
||||
|
||||
// Create the LoRA list widget
|
||||
const result = addLorasWidget(
|
||||
this,
|
||||
"loras",
|
||||
{
|
||||
onSelectionChange: (selection) => {
|
||||
applySelectionHighlight(this, selection);
|
||||
updateConnectedLoraInfoNodes(this, selection);
|
||||
},
|
||||
},
|
||||
(value) => {
|
||||
// Prevent recursive calls
|
||||
if (isUpdating) return;
|
||||
isUpdating = true;
|
||||
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||
const lorasWidget = getWidgetByName(this, "loras");
|
||||
if (!lorasWidget) {
|
||||
console.warn(
|
||||
"LoRA Manager: loras widget not found for Create Hook LoRA"
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.lorasWidget = lorasWidget;
|
||||
|
||||
try {
|
||||
// Update connected trigger word toggles with active LoRA names
|
||||
const activeLoraNames = new Set();
|
||||
value.forEach((lora) => {
|
||||
if (lora.active) {
|
||||
activeLoraNames.add(lora.name);
|
||||
}
|
||||
});
|
||||
updateConnectedTriggerWords(this, activeLoraNames);
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
lorasWidget.callback = (value) => {
|
||||
// Prevent recursive calls
|
||||
if (isUpdating) return;
|
||||
isUpdating = true;
|
||||
|
||||
scheduleInputSync(value);
|
||||
try {
|
||||
// Update connected trigger word toggles with active LoRA names
|
||||
const activeLoraNames = new Set();
|
||||
value.forEach((lora) => {
|
||||
if (lora.active) {
|
||||
activeLoraNames.add(lora.name);
|
||||
}
|
||||
});
|
||||
updateConnectedTriggerWords(this, activeLoraNames);
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
);
|
||||
|
||||
this.lorasWidget = result.widget;
|
||||
scheduleInputSync(value);
|
||||
};
|
||||
|
||||
// Set up callback for the text input widget to trigger merge logic
|
||||
inputWidget.callback = (value) => {
|
||||
|
||||
+22
-27
@@ -10,10 +10,7 @@ import {
|
||||
getWidgetByName,
|
||||
getWidgetSerializedValue,
|
||||
} from "./utils.js";
|
||||
import { addLorasWidget } from "./loras_widget.js";
|
||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "LoraManager.LoraLoader",
|
||||
@@ -188,34 +185,32 @@ app.registerExtension({
|
||||
}
|
||||
});
|
||||
|
||||
// Get the widget object directly from the returned object
|
||||
this.lorasWidget = addLorasWidget(
|
||||
this,
|
||||
"loras",
|
||||
{
|
||||
onSelectionChange: (selection) => {
|
||||
applySelectionHighlight(this, selection);
|
||||
updateConnectedLoraInfoNodes(this, selection);
|
||||
},
|
||||
},
|
||||
(value) => {
|
||||
// Prevent recursive calls
|
||||
if (isUpdating) return;
|
||||
isUpdating = true;
|
||||
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||
const lorasWidget = getWidgetByName(this, "loras");
|
||||
if (!lorasWidget) {
|
||||
console.warn("LoRA Manager: loras widget not found for Lora Loader");
|
||||
return;
|
||||
}
|
||||
this.lorasWidget = lorasWidget;
|
||||
|
||||
try {
|
||||
// Collect all active loras from this node and its input chain
|
||||
const allActiveLoraNames = collectActiveLorasFromChain(this);
|
||||
lorasWidget.callback = (value) => {
|
||||
// Prevent recursive calls
|
||||
if (isUpdating) return;
|
||||
isUpdating = true;
|
||||
|
||||
// Update trigger words for connected toggle nodes with the aggregated lora names
|
||||
updateConnectedTriggerWords(this, allActiveLoraNames);
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
try {
|
||||
// Collect all active loras from this node and its input chain
|
||||
const allActiveLoraNames = collectActiveLorasFromChain(this);
|
||||
|
||||
scheduleInputSync(value);
|
||||
// Update trigger words for connected toggle nodes with the aggregated lora names
|
||||
updateConnectedTriggerWords(this, allActiveLoraNames);
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
).widget;
|
||||
|
||||
scheduleInputSync(value);
|
||||
};
|
||||
|
||||
// Set up callback for the text input widget to trigger merge logic
|
||||
inputWidget.callback = (value) => {
|
||||
|
||||
+31
-36
@@ -8,10 +8,7 @@ import {
|
||||
getWidgetByName,
|
||||
getWidgetSerializedValue,
|
||||
} from "./utils.js";
|
||||
import { addLorasWidget } from "./loras_widget.js";
|
||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "LoraManager.LoraStacker",
|
||||
@@ -61,44 +58,42 @@ app.registerExtension({
|
||||
}
|
||||
});
|
||||
|
||||
const result = addLorasWidget(
|
||||
this,
|
||||
"loras",
|
||||
{
|
||||
onSelectionChange: (selection) => {
|
||||
applySelectionHighlight(this, selection);
|
||||
updateConnectedLoraInfoNodes(this, selection);
|
||||
},
|
||||
},
|
||||
(value) => {
|
||||
// Prevent recursive calls
|
||||
if (isUpdating) return;
|
||||
isUpdating = true;
|
||||
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||
const lorasWidget = getWidgetByName(this, "loras");
|
||||
if (!lorasWidget) {
|
||||
console.warn("LoRA Manager: loras widget not found for Lora Stacker");
|
||||
return;
|
||||
}
|
||||
this.lorasWidget = lorasWidget;
|
||||
|
||||
try {
|
||||
// Update this stacker's direct trigger toggles with its own active loras
|
||||
// Only if the stacker node itself is active (mode 0 for Always, mode 3 for On Trigger)
|
||||
const isNodeActive = this.mode === undefined || this.mode === 0 || this.mode === 3;
|
||||
const activeLoraNames = new Set();
|
||||
if (isNodeActive) {
|
||||
value.forEach((lora) => {
|
||||
if (lora.active) {
|
||||
activeLoraNames.add(lora.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
updateConnectedTriggerWords(this, activeLoraNames);
|
||||
lorasWidget.callback = (value) => {
|
||||
// Prevent recursive calls
|
||||
if (isUpdating) return;
|
||||
isUpdating = true;
|
||||
|
||||
// Find all Lora Loader nodes in the chain that might need updates
|
||||
updateDownstreamLoaders(this);
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
try {
|
||||
// Update this stacker's direct trigger toggles with its own active loras
|
||||
// Only if the stacker node itself is active (mode 0 for Always, mode 3 for On Trigger)
|
||||
const isNodeActive = this.mode === undefined || this.mode === 0 || this.mode === 3;
|
||||
const activeLoraNames = new Set();
|
||||
if (isNodeActive) {
|
||||
value.forEach((lora) => {
|
||||
if (lora.active) {
|
||||
activeLoraNames.add(lora.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
updateConnectedTriggerWords(this, activeLoraNames);
|
||||
|
||||
scheduleInputSync(value);
|
||||
});
|
||||
// Find all Lora Loader nodes in the chain that might need updates
|
||||
updateDownstreamLoaders(this);
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
|
||||
this.lorasWidget = result.widget;
|
||||
scheduleInputSync(value);
|
||||
};
|
||||
|
||||
// Set up callback for the text input widget to trigger merge logic
|
||||
inputWidget.callback = (value) => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { createToggle, createArrowButton, createDragHandle, updateEntrySelection, createExpandButton, updateExpandButtonState, createLockButton, updateLockButtonState } from "./loras_widget_components.js";
|
||||
import {
|
||||
parseLoraValue,
|
||||
@@ -10,7 +11,9 @@ import {
|
||||
onLibraryChanged
|
||||
} from "./loras_widget_utils.js";
|
||||
import { initDrag, createContextMenu, initHeaderDrag, initReorderDrag, handleKeyboardNavigation } from "./loras_widget_events.js";
|
||||
import { forwardMiddleMouseToCanvas, forwardWheelToCanvas, enableListWheelScroll } from "./utils.js";
|
||||
import { forwardMiddleMouseToCanvas, forwardWheelToCanvas, enableListWheelScroll, updateDownstreamLoaders } from "./utils.js";
|
||||
import { applySelectionHighlight } from "./trigger_word_highlight.js";
|
||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
||||
import { PreviewTooltip } from "./preview_tooltip.js";
|
||||
import { ensureLmStyles } from "./lm_styles_loader.js";
|
||||
import { getStrengthStepPreference } from "./settings.js";
|
||||
@@ -885,3 +888,50 @@ export function addLorasWidget(node, name, opts, callback) {
|
||||
|
||||
return { minWidth: 400, minHeight: defaultHeight, widget };
|
||||
}
|
||||
|
||||
// Node classes whose declared "loras" input (LORAS widget type) also applies
|
||||
// trigger-word selection highlighting on lora selection.
|
||||
const LORAS_WIDGET_HIGHLIGHT_NODE_CLASSES = new Set([
|
||||
"Lora Loader (LoraManager)",
|
||||
"Lora Stacker (LoraManager)",
|
||||
"Create Hook LoRA (LoraManager)",
|
||||
]);
|
||||
|
||||
app.registerExtension({
|
||||
name: "LoraManager.LorasWidget",
|
||||
|
||||
getCustomWidgets() {
|
||||
return {
|
||||
// Synchronous factory for the declared "loras" input (LORAS type) used by
|
||||
// Lora Loader / Lora Stacker / Create Hook LoRA / WanVideo Lora Select /
|
||||
// Lora Randomizer nodes. ComfyUI calls widget constructors synchronously,
|
||||
// so this must NOT be async.
|
||||
LORAS(node) {
|
||||
const comfyClass = node?.comfyClass;
|
||||
const isRandomizerNode = comfyClass === "Lora Randomizer (LoraManager)";
|
||||
|
||||
const opts = { isRandomizerNode };
|
||||
|
||||
if (isRandomizerNode || comfyClass === "WanVideo Lora Select (LoraManager)") {
|
||||
opts.onSelectionChange = (selection) => {
|
||||
updateConnectedLoraInfoNodes(node, selection);
|
||||
};
|
||||
} else if (LORAS_WIDGET_HIGHLIGHT_NODE_CLASSES.has(comfyClass)) {
|
||||
opts.onSelectionChange = (selection) => {
|
||||
applySelectionHighlight(node, selection);
|
||||
updateConnectedLoraInfoNodes(node, selection);
|
||||
};
|
||||
}
|
||||
|
||||
// The randomizer has no per-node JS extension; update downstream
|
||||
// loaders directly from the widget callback. The other nodes assign
|
||||
// their own widget.callback in their onNodeCreated handlers.
|
||||
const callback = isRandomizerNode
|
||||
? () => updateDownstreamLoaders(node)
|
||||
: null;
|
||||
|
||||
return addLorasWidget(node, "loras", opts, callback);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -16070,7 +16070,6 @@ function createAutocompleteTextWidgetInstanceId() {
|
||||
autocompleteTextWidgetInstanceId += 1;
|
||||
return autocompleteTextWidgetInstanceId;
|
||||
}
|
||||
let addLorasWidgetCache = null;
|
||||
function createLoraPoolWidget(node) {
|
||||
const container = document.createElement("div");
|
||||
container.id = `lora-pool-widget-${node.id}`;
|
||||
@@ -16683,81 +16682,6 @@ app$1.registerExtension({
|
||||
CYCLER_CONFIG(node) {
|
||||
return createLoraCyclerWidget(node);
|
||||
},
|
||||
// @ts-ignore
|
||||
async LORAS(node) {
|
||||
if (!addLorasWidgetCache) {
|
||||
const module = await import(
|
||||
/* @vite-ignore */
|
||||
"../loras_widget.js"
|
||||
);
|
||||
addLorasWidgetCache = module.addLorasWidget;
|
||||
}
|
||||
const isRandomizerNode = node.comfyClass === "Lora Randomizer (LoraManager)";
|
||||
const callback = isRandomizerNode ? () => {
|
||||
updateDownstreamLoaders(node);
|
||||
} : null;
|
||||
const opts = {
|
||||
isRandomizerNode
|
||||
};
|
||||
if (isRandomizerNode) {
|
||||
opts.onSelectionChange = async (selection) => {
|
||||
var _a2, _b, _c, _d, _e2;
|
||||
if (!(selection == null ? void 0 : selection.name) || !(selection == null ? void 0 : selection.active)) return;
|
||||
const infoNodes = [];
|
||||
if (node.outputs) {
|
||||
for (const output of node.outputs) {
|
||||
if (!((_a2 = output == null ? void 0 : output.links) == null ? void 0 : _a2.length)) continue;
|
||||
for (const linkId of output.links) {
|
||||
const links = (_b = node.graph) == null ? void 0 : _b.links;
|
||||
if (!links) continue;
|
||||
const link = Array.isArray(links) ? links[linkId] : (_c = links.get) == null ? void 0 : _c.call(links, linkId);
|
||||
if (!link) continue;
|
||||
const targetNode = (_e2 = (_d = node.graph) == null ? void 0 : _d.getNodeById) == null ? void 0 : _e2.call(_d, link.target_id);
|
||||
if ((targetNode == null ? void 0 : targetNode.comfyClass) === "Lora Info (LoraManager)") {
|
||||
infoNodes.push(targetNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (infoNodes.length === 0) return;
|
||||
for (const infoNode of infoNodes) {
|
||||
infoNode.__loraInfoReqId = (infoNode.__loraInfoReqId || 0) + 1;
|
||||
}
|
||||
const reqIdSnapshot = /* @__PURE__ */ new Map();
|
||||
for (const infoNode of infoNodes) {
|
||||
reqIdSnapshot.set(infoNode, infoNode.__loraInfoReqId);
|
||||
}
|
||||
let infoData;
|
||||
try {
|
||||
const response = await api$1.fetchApi(
|
||||
`/lm/loras/get-notes?name=${encodeURIComponent(selection.name)}`,
|
||||
{ method: "GET" }
|
||||
);
|
||||
if (response == null ? void 0 : response.ok) {
|
||||
const data = await response.json();
|
||||
infoData = {
|
||||
name: selection.name,
|
||||
notes: (data == null ? void 0 : data.notes) || "",
|
||||
filePath: (data == null ? void 0 : data.file_path) || ""
|
||||
};
|
||||
} else {
|
||||
infoData = { name: selection.name, notes: "[Error loading notes]", filePath: "" };
|
||||
}
|
||||
} catch {
|
||||
infoData = { name: selection.name, notes: "[Error loading notes]", filePath: "" };
|
||||
}
|
||||
for (const infoNode of infoNodes) {
|
||||
if (infoNode.__loraInfoReqId !== reqIdSnapshot.get(infoNode)) {
|
||||
continue;
|
||||
}
|
||||
if (typeof infoNode._setLoraInfo === "function") {
|
||||
infoNode._setLoraInfo(infoData);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
return addLorasWidgetCache(node, "loras", opts, callback);
|
||||
},
|
||||
// Autocomplete text widget for LoRAs (used by Lora Loader, Lora Stacker, WanVideo Lora Select)
|
||||
// @ts-ignore
|
||||
AUTOCOMPLETE_TEXT_LORAS(node) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,9 +7,7 @@ import {
|
||||
getWidgetByName,
|
||||
getWidgetSerializedValue,
|
||||
} from "./utils.js";
|
||||
import { addLorasWidget } from "./loras_widget.js";
|
||||
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
|
||||
import { updateConnectedLoraInfoNodes } from "./lora_info.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "LoraManager.WanVideoLoraSelect",
|
||||
@@ -64,11 +62,16 @@ app.registerExtension({
|
||||
}
|
||||
});
|
||||
|
||||
const result = addLorasWidget(this, "loras", {
|
||||
onSelectionChange: (selection) => {
|
||||
updateConnectedLoraInfoNodes(this, selection);
|
||||
},
|
||||
}, (value) => {
|
||||
// The "loras" widget is declared in INPUT_TYPES (LORAS type) and
|
||||
// created by the LoraManager.LorasWidget extension; take it over here.
|
||||
const lorasWidget = getWidgetByName(this, "loras");
|
||||
if (!lorasWidget) {
|
||||
console.warn("LoRA Manager: loras widget not found for WanVideo Lora Select");
|
||||
return;
|
||||
}
|
||||
this.lorasWidget = lorasWidget;
|
||||
|
||||
lorasWidget.callback = (value) => {
|
||||
// Prevent recursive calls
|
||||
if (isUpdating) return;
|
||||
isUpdating = true;
|
||||
@@ -87,9 +90,7 @@ app.registerExtension({
|
||||
}
|
||||
|
||||
scheduleInputSync(value);
|
||||
});
|
||||
|
||||
this.lorasWidget = result.widget;
|
||||
};
|
||||
|
||||
// Set up callback for the text input widget to trigger merge logic
|
||||
inputWidget.callback = (value) => {
|
||||
|
||||
Reference in New Issue
Block a user