Added missing alerts on add buttons.
This commit is contained in:
@@ -123,12 +123,12 @@
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfy-grid .model-button.copy-alert-success {
|
.comfy-grid .model-button.model-button-success {
|
||||||
color: green;
|
color: green;
|
||||||
border-color: green;
|
border-color: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfy-grid .model-button.copy-alert-fail {
|
.comfy-grid .model-button.model-button-failure {
|
||||||
color: darkred;
|
color: darkred;
|
||||||
border-color: darkred;
|
border-color: darkred;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,12 +43,18 @@ function modelWidgetIndex(nodeType) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pathToEmbeddingString(path, removeExtension = false) {
|
function pathToFileString(path) {
|
||||||
const i = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")) + 1;
|
const i = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")) + 1;
|
||||||
|
return path.slice(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertEmbeddingIntoText(currentText, embeddingFile, removeExtension = false) {
|
||||||
if (removeExtension) {
|
if (removeExtension) {
|
||||||
// TODO: setting.remove_extension_embedding
|
// TODO: setting.remove_extension_embedding
|
||||||
}
|
}
|
||||||
return "(embedding:" + path.slice(i) + ":1.0)";
|
// TODO: don't add if it is already in the text?
|
||||||
|
const sep = currentText.length === 0 || currentText.slice(-1).match(/\s/) ? "" : " ";
|
||||||
|
return currentText + sep + "(embedding:" + embeddingFile + ":1.0)";
|
||||||
}
|
}
|
||||||
|
|
||||||
class Tabs {
|
class Tabs {
|
||||||
@@ -275,8 +281,21 @@ class ModelGrid {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static #buttonAlert(event, successful, innerHTML) {
|
||||||
|
const element = event.target;
|
||||||
|
const name = successful ? "model-button-success" : "model-button-failure";
|
||||||
|
element.classList.add(name);
|
||||||
|
element.innerHTML = successful ? "✔" : "✖";
|
||||||
|
// TODO: debounce would be nice to get working...
|
||||||
|
window.setTimeout((element, name) => {
|
||||||
|
element.classList.remove(name);
|
||||||
|
element.innerHTML = innerHTML;
|
||||||
|
}, 500, element, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static #addModel(event, modelType, path) {
|
static #addModel(event, modelType, path) {
|
||||||
|
let successful = false;
|
||||||
if (modelType !== "embeddings") {
|
if (modelType !== "embeddings") {
|
||||||
const nodeType = modelNodeType(modelType);
|
const nodeType = modelNodeType(modelType);
|
||||||
const widgetIndex = modelWidgetIndex(nodeType);
|
const widgetIndex = modelWidgetIndex(nodeType);
|
||||||
@@ -300,25 +319,29 @@ class ModelGrid {
|
|||||||
}
|
}
|
||||||
app.graph.add(node, {doProcessChange: true});
|
app.graph.add(node, {doProcessChange: true});
|
||||||
app.canvas.selectNode(node);
|
app.canvas.selectNode(node);
|
||||||
|
successful = true;
|
||||||
}
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
else if (modelType === "embeddings") {
|
else if (modelType === "embeddings") {
|
||||||
const text = pathToEmbeddingString(path);
|
const embeddingFile = pathToFileString(path);
|
||||||
const selectedNodes = app.canvas.selected_nodes;
|
const selectedNodes = app.canvas.selected_nodes;
|
||||||
for (var i in selectedNodes) {
|
for (var i in selectedNodes) {
|
||||||
const selectedNode = selectedNodes[i];
|
const selectedNode = selectedNodes[i];
|
||||||
const nodeType = modelNodeType(modelType);
|
const nodeType = modelNodeType(modelType);
|
||||||
const widgetIndex = modelWidgetIndex(nodeType);
|
const widgetIndex = modelWidgetIndex(nodeType);
|
||||||
const target = selectedNode.widgets[widgetIndex].element;
|
const target = selectedNode.widgets[widgetIndex].element;
|
||||||
if (target.type === "textarea") {
|
if (target && target.type === "textarea") {
|
||||||
const currentText = target.value;
|
target.value = insertEmbeddingIntoText(target.value, embeddingFile);
|
||||||
const sep = currentText.length === 0 || currentText.slice(-1).match(/\s/) ? "" : " ";
|
successful = true;
|
||||||
target.value = currentText + sep + text;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!successful) {
|
||||||
|
console.warn("Try selecting a node before adding the embedding.");
|
||||||
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
this.#buttonAlert(event, successful, "✚");
|
||||||
}
|
}
|
||||||
|
|
||||||
static #dragAddModel(event, modelType, path) {
|
static #dragAddModel(event, modelType, path) {
|
||||||
@@ -347,11 +370,14 @@ class ModelGrid {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
else if (modelType === "embeddings" && target.type === "textarea") {
|
else if (modelType === "embeddings" && target.type === "textarea") {
|
||||||
const text = pathToEmbeddingString(path);
|
const pos = app.canvas.convertEventToCanvasOffset(event);
|
||||||
const currentText = target.value;
|
const nodeAtPos = app.graph.getNodeOnPos(pos[0], pos[1], app.canvas.visible_nodes);
|
||||||
const sep = currentText.length === 0 || currentText.slice(-1).match(/\s/) ? "" : " ";
|
if (nodeAtPos) {
|
||||||
target.value = currentText + sep + text;
|
app.canvas.selectNode(nodeAtPos);
|
||||||
event.stopPropagation();
|
const embeddingFile = pathToFileString(path);
|
||||||
|
target.value = insertEmbeddingIntoText(target.value, embeddingFile);
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,8 +386,8 @@ class ModelGrid {
|
|||||||
let successful = false;
|
let successful = false;
|
||||||
if (nodeType === "Embedding") {
|
if (nodeType === "Embedding") {
|
||||||
if (navigator.clipboard){
|
if (navigator.clipboard){
|
||||||
const text = pathToEmbeddingString(path);
|
const embeddingText = pathToFileString(path);
|
||||||
navigator.clipboard.writeText(text);
|
navigator.clipboard.writeText(embeddingText);
|
||||||
successful = true;
|
successful = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -378,15 +404,7 @@ class ModelGrid {
|
|||||||
else {
|
else {
|
||||||
console.warn(`Unable to copy unknown model type '${modelType}.`);
|
console.warn(`Unable to copy unknown model type '${modelType}.`);
|
||||||
}
|
}
|
||||||
|
this.#buttonAlert(event, successful, "⧉︎");
|
||||||
const element = event.target;
|
|
||||||
const name = successful ? "copy-alert-success" : "copy-alert-fail";
|
|
||||||
element.classList.add(name);
|
|
||||||
element.innerHTML = successful ? "✔" : "✖";
|
|
||||||
window.setTimeout((element, name) => {
|
|
||||||
element.classList.remove(name);
|
|
||||||
element.innerHTML = "⧉︎";
|
|
||||||
}, 500, element, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static generateInnerHtml(models, modelType) {
|
static generateInnerHtml(models, modelType) {
|
||||||
@@ -744,6 +762,7 @@ class ModelManager extends ComfyDialog {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#setSidebar(event) {
|
#setSidebar(event) {
|
||||||
|
// TODO: use checkboxes with 0 or 1 values set at once?
|
||||||
// TODO: settings.sidebar_side_width
|
// TODO: settings.sidebar_side_width
|
||||||
// TODO: settings.sidebar_bottom_height
|
// TODO: settings.sidebar_bottom_height
|
||||||
// TODO: draggable resize?
|
// TODO: draggable resize?
|
||||||
|
|||||||
Reference in New Issue
Block a user