mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
checkpoint
This commit is contained in:
@@ -14,23 +14,7 @@ export function addTagsWidget(node, name, opts, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Initialize default value as array
|
// Initialize default value as array
|
||||||
const defaultValue = opts?.defaultVal || [];
|
const initialTagsData = opts?.defaultVal || [];
|
||||||
let initialTagsData = Array.isArray(defaultValue) ? defaultValue : [];
|
|
||||||
|
|
||||||
// Normalize tag data to ensure consistent format
|
|
||||||
const normalizeTagData = (data) => {
|
|
||||||
if (!Array.isArray(data)) return [];
|
|
||||||
|
|
||||||
return data.map(item => {
|
|
||||||
if (item && typeof item === 'object' && 'text' in item) {
|
|
||||||
return {
|
|
||||||
text: item.text,
|
|
||||||
active: item.active !== undefined ? item.active : true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { text: String(item), active: true };
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Function to render tags from array data
|
// Function to render tags from array data
|
||||||
const renderTags = (tagsData, widget) => {
|
const renderTags = (tagsData, widget) => {
|
||||||
@@ -39,8 +23,7 @@ export function addTagsWidget(node, name, opts, callback) {
|
|||||||
container.removeChild(container.firstChild);
|
container.removeChild(container.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we're working with normalized data
|
const normalizedTags = tagsData;
|
||||||
const normalizedTags = normalizeTagData(tagsData);
|
|
||||||
|
|
||||||
normalizedTags.forEach((tagData, index) => {
|
normalizedTags.forEach((tagData, index) => {
|
||||||
const { text, active } = tagData;
|
const { text, active } = tagData;
|
||||||
@@ -119,16 +102,15 @@ export function addTagsWidget(node, name, opts, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store the value as array
|
// Store the value as array
|
||||||
let widgetValue = normalizeTagData(initialTagsData);
|
let widgetValue = initialTagsData;
|
||||||
|
|
||||||
// Create widget with initial properties
|
// Create widget with initial properties
|
||||||
const widget = node.addDOMWidget(name, "tags", container, {
|
const widget = node.addDOMWidget(name, "tags", container, {
|
||||||
getValue: function() {
|
getValue: function() {
|
||||||
console.log("Tags widget value:", widgetValue);
|
|
||||||
return widgetValue;
|
return widgetValue;
|
||||||
},
|
},
|
||||||
setValue: function(v) {
|
setValue: function(v) {
|
||||||
widgetValue = normalizeTagData(Array.isArray(v) ? v : []);
|
widgetValue = v;
|
||||||
renderTags(widgetValue, widget);
|
renderTags(widgetValue, widget);
|
||||||
},
|
},
|
||||||
getHeight: function() {
|
getHeight: function() {
|
||||||
@@ -138,21 +120,11 @@ export function addTagsWidget(node, name, opts, callback) {
|
|||||||
Math.ceil(container.scrollHeight / 5) * 5 // Round up to nearest 5px
|
Math.ceil(container.scrollHeight / 5) * 5 // Round up to nearest 5px
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onDraw: function() {
|
|
||||||
// Empty function
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
widget.value = defaultValue;
|
widget.value = initialTagsData;
|
||||||
|
|
||||||
widget.callback = callback;
|
widget.callback = callback;
|
||||||
|
|
||||||
// Render initial state
|
|
||||||
renderTags(widgetValue, widget);
|
|
||||||
|
|
||||||
widget.onRemove = () => {
|
|
||||||
container.remove();
|
|
||||||
};
|
|
||||||
|
|
||||||
return { minWidth: 300, minHeight: 150, widget };
|
return { minWidth: 300, minHeight: 150, widget };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user