mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 23:25:43 -03:00
Refactor Lora handling to improve data consistency and remove duplicates in widget value
This commit is contained in:
@@ -4,7 +4,7 @@ import { addLorasWidget } from "./loras_widget.js";
|
|||||||
// Extract pattern into a constant for consistent use
|
// Extract pattern into a constant for consistent use
|
||||||
const LORA_PATTERN = /<lora:([^:]+):([-\d\.]+)>/g;
|
const LORA_PATTERN = /<lora:([^:]+):([-\d\.]+)>/g;
|
||||||
|
|
||||||
function mergeLoras(lorasText, lorasJson) {
|
function mergeLoras(lorasText, lorasArr) {
|
||||||
const result = [];
|
const result = [];
|
||||||
let match;
|
let match;
|
||||||
|
|
||||||
@@ -13,8 +13,8 @@ function mergeLoras(lorasText, lorasJson) {
|
|||||||
const name = match[1];
|
const name = match[1];
|
||||||
const inputStrength = Number(match[2]);
|
const inputStrength = Number(match[2]);
|
||||||
|
|
||||||
// Find if this lora exists in the JSON data
|
// Find if this lora exists in the array data
|
||||||
const existingLora = lorasJson.find(l => l.name === name);
|
const existingLora = lorasArr.find(l => l.name === name);
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
name: name,
|
name: name,
|
||||||
|
|||||||
@@ -664,7 +664,15 @@ export function addLorasWidget(node, name, opts, callback) {
|
|||||||
return widgetValue;
|
return widgetValue;
|
||||||
},
|
},
|
||||||
setValue: function(v) {
|
setValue: function(v) {
|
||||||
widgetValue = v || "";
|
// Remove duplicates by keeping the last occurrence of each lora name
|
||||||
|
const uniqueValue = (v || []).reduce((acc, lora) => {
|
||||||
|
// Remove any existing lora with the same name
|
||||||
|
const filtered = acc.filter(l => l.name !== lora.name);
|
||||||
|
// Add the current lora
|
||||||
|
return [...filtered, lora];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
widgetValue = uniqueValue;
|
||||||
renderLoras(widgetValue, widget);
|
renderLoras(widgetValue, widget);
|
||||||
|
|
||||||
// Update container height after rendering
|
// Update container height after rendering
|
||||||
|
|||||||
Reference in New Issue
Block a user