Add context menu for Lora items and improve Lora cleanup logic

This commit is contained in:
Will Miao
2025-03-02 17:47:28 +08:00
parent 988d298008
commit 3e68a7f772
2 changed files with 144 additions and 1 deletions

View File

@@ -58,7 +58,19 @@ app.registerExtension({
const result = addLorasWidget(node, "loras", {
defaultVal: mergedLoras // Pass object directly
}, (value) => {
console.log("Loras data updated:", value);
// Remove loras that are not in the value array
const inputWidget = node.widgets[0];
const pattern = /<lora:([^:]+):([\d\.]+)>/g;
const currentLoras = value.map(l => l.name);
let newText = inputWidget.value.replace(pattern, (match, name, strength) => {
return currentLoras.includes(name) ? match : '';
});
// Clean up multiple spaces and trim
newText = newText.replace(/\s+/g, ' ').trim();
inputWidget.value = newText;
});
node.lorasWidget = result.widget;