Fix node size

This commit is contained in:
Will Miao
2025-03-03 05:32:54 +08:00
parent 6db4ff3bd6
commit 1281ae29cb
4 changed files with 28 additions and 15 deletions

View File

@@ -89,15 +89,13 @@ app.registerExtension({
node.lorasWidget = result.widget;
// get the input widget and set a callback
// Update input widget callback
const inputWidget = node.widgets[0];
inputWidget.callback = (value) => {
// Prevent recursive calls
if (isUpdating) return;
isUpdating = true;
try {
// Merge the loras data with widget value
const currentLoras = node.lorasWidget.value || [];
const mergedLoras = mergeLoras(value, currentLoras);

View File

@@ -666,13 +666,23 @@ export function addLorasWidget(node, name, opts, callback) {
setValue: function(v) {
widgetValue = v || "";
renderLoras(widgetValue, widget);
// Update container height after rendering
requestAnimationFrame(() => {
const minHeight = this.getMinHeight();
container.style.height = `${minHeight}px`;
// Force node to update size
node.setSize([node.size[0], node.computeSize()[1]]);
node.setDirtyCanvas(true, true);
});
},
getHeight: function() {
getMinHeight: function() {
// Calculate height based on content
const lorasCount = parseLoraValue(widgetValue).length;
return Math.max(
100,
lorasCount > 0 ? 60 + lorasCount * 44 : 60 // Header + entries or minimum height
lorasCount > 0 ? 60 + lorasCount * 44 : 60
);
},
});

View File

@@ -5,7 +5,7 @@ export function addTagsWidget(node, name, opts, callback) {
Object.assign(container.style, {
display: "flex",
flexWrap: "wrap",
gap: "8px",
gap: "4px", // 从8px减小到4px
padding: "6px",
minHeight: "30px",
backgroundColor: "rgba(40, 44, 52, 0.6)", // Darker, more modern background
@@ -54,7 +54,7 @@ export function addTagsWidget(node, name, opts, callback) {
// Helper function to update tag style based on active state
function updateTagStyle(tagEl, active) {
const baseStyles = {
padding: "6px 12px", // 水平内边距从16px减小到12px
padding: "4px 12px", // 垂直内边距从6px减小到4px
borderRadius: "6px", // Matching container radius
maxWidth: "200px", // Increased max width
overflow: "hidden",
@@ -66,7 +66,7 @@ export function addTagsWidget(node, name, opts, callback) {
border: "1px solid transparent",
display: "inline-block",
boxShadow: "0 1px 2px rgba(0,0,0,0.1)",
margin: "4px", // 从6px减小到4px
margin: "2px", // 从4px减小到2px
userSelect: "none", // Add this line to prevent text selection
WebkitUserSelect: "none", // For Safari support
MozUserSelect: "none", // For Firefox support
@@ -112,12 +112,22 @@ export function addTagsWidget(node, name, opts, callback) {
setValue: function(v) {
widgetValue = v;
renderTags(widgetValue, widget);
// Update container height after rendering
requestAnimationFrame(() => {
const minHeight = this.getMinHeight();
container.style.height = `${minHeight}px`;
// Force node to update size
node.setSize([node.size[0], node.computeSize()[1]]);
node.setDirtyCanvas(true, true);
});
},
getHeight: function() {
getMinHeight: function() {
// Calculate height based on content
return Math.max(
150,
Math.ceil(container.scrollHeight / 5) * 5 // Round up to nearest 5px
Math.ceil(container.scrollHeight / 5) * 5 + 15// Round up to nearest 5px
);
},
});

View File

@@ -53,9 +53,6 @@ app.registerExtension({
if (typeof message === 'string') {
// Get existing tags to preserve active states
const existingTags = node.tagWidget.value || [];
const tempWidget = node.tagWidget;
const originalHeight = tempWidget.options.getHeight();
// Create a map of existing tags and their active states
const existingTagMap = {};
@@ -75,8 +72,6 @@ app.registerExtension({
}));
node.tagWidget.value = tagArray;
node.size[1] = node.size[1] + (tempWidget.options.getHeight() - originalHeight);
node.setDirtyCanvas(true, true);
}
}
},