Fixed tooltip on custom lora settings

This commit is contained in:
Lucas Sköld
2024-04-23 17:12:47 +02:00
parent 3b945f44da
commit 4112fe96b0
+29 -13
View File
@@ -1,6 +1,8 @@
import { app } from "../../../scripts/app.js";
function createMultilineTextSetting(name, setter, value, attrs, tooltip = "") {
console.log("Tooltip received:", tooltip); // Debug to check tooltip value
// Create elements
const tr = document.createElement("tr");
const tdLabel = document.createElement("td");
@@ -12,12 +14,19 @@ function createMultilineTextSetting(name, setter, value, attrs, tooltip = "") {
const uniqueId = `custom-setting-${Date.now()}`; // Unique ID for associating label with textarea
label.setAttribute("for", uniqueId);
label.textContent = name;
label.className = tooltip ? "comfy-tooltip-indicator" : ""; // Apply class if tooltip is present
// Check for tooltip and apply the class and title
if (tooltip) {
label.className = "comfy-tooltip-indicator"; // Apply tooltip indicator class
console.log("Class set:", label.className); // Debug to verify class set
}
// Configure textarea
textarea.id = uniqueId;
textarea.value = value;
textarea.setAttribute("style", "width: 100%; height: 100px; resize: none;"); // Fixed size and non-resizable
textarea.style.width = "100%";
textarea.style.height = "100px";
textarea.style.resize = "none";
// Set event handlers
textarea.onchange = () => {
@@ -35,34 +44,41 @@ function createMultilineTextSetting(name, setter, value, attrs, tooltip = "") {
tr.appendChild(tdLabel);
tr.appendChild(tdInput);
// Set tooltip if available
if (tooltip) {
label.title = tooltip; // Set the tooltip text
}
return tr;
}
// Define a wrapper function for creating the multiline text setting that includes the tooltip
const createMultilineTextSettingWithTooltip = (name, defaultValue, tooltip) => {
return () => createMultilineTextSetting(name, value => console.log(`Setting ${name} updated to: ${value}`), defaultValue, {}, tooltip);
};
// Define settings for "Custom Lora Loaders XL"
const xlId = "sn0w.CustomLoraLoadersXL";
const xlSettingDefinition = {
id: xlId,
id: "sn0w.CustomLoraLoadersXL",
name: "[Sn0w] Custom Lora Loaders XL",
type: createMultilineTextSetting,
type: createMultilineTextSettingWithTooltip(
"[Sn0w] Custom Lora Loaders XL",
"ExampleName1:Value1\nExampleName2:Value2",
"Enter each name-value pair on a new line, separated by a colon (:)."
),
defaultValue: "ExampleName1:Value1\nExampleName2:Value2",
tooltip: "Enter each name-value pair on a new line, separated by a colon (:)."
};
// Define settings for "Custom Lora Loaders" (without XL)
const nonXlId = "sn0w.CustomLoraLoaders1.5";
const nonXlSettingDefinition = {
id: nonXlId,
id: "sn0w.CustomLoraLoaders1.5",
name: "[Sn0w] Custom Lora Loaders 1.5",
type: createMultilineTextSetting,
type: createMultilineTextSettingWithTooltip(
"[Sn0w] Custom Lora Loaders 1.5",
"ExampleName1:Value1\nExampleName2:Value2",
"Enter each name-value pair on a new line, separated by a colon (:)."
),
defaultValue: "ExampleName1:Value1\nExampleName2:Value2",
tooltip: "Enter each name-value pair on a new line, separated by a colon (:)."
};
// Register extensions for both settings
const registerSetting = (settingDefinition) => {
const extension = {