mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2026-07-27 02:27:30 +08:00
Merge branch 'main' into feat/component-manager
This commit is contained in:
+42
-7
@@ -18,12 +18,13 @@ import { ModelInstaller } from "./model-downloader.js";
|
||||
import { manager_instance, setManagerInstance, install_via_git_url, install_pip, rebootAPI, free_models } from "./common.js";
|
||||
import { ComponentBuilderDialog, load_components, set_component_policy, getPureName } from "./component-builder.js";
|
||||
import { ComponentsManager } from "./components-manager.js";
|
||||
import { set_double_click_policy } from "./node_fixer.js";
|
||||
|
||||
var docStyle = document.createElement('style');
|
||||
docStyle.innerHTML = `
|
||||
#cm-manager-dialog {
|
||||
width: 1000px;
|
||||
height: 495px;
|
||||
height: 520px;
|
||||
box-sizing: content-box;
|
||||
z-index: 10000;
|
||||
}
|
||||
@@ -137,7 +138,7 @@ docStyle.innerHTML = `
|
||||
|
||||
.cm-notice-board {
|
||||
width: 290px;
|
||||
height: 230px;
|
||||
height: 270px;
|
||||
overflow: auto;
|
||||
color: var(--input-text);
|
||||
border: 1px solid var(--descrip-text);
|
||||
@@ -911,6 +912,27 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
set_component_policy(event.target.value);
|
||||
});
|
||||
|
||||
let dbl_click_policy_combo = document.createElement("select");
|
||||
dbl_click_policy_combo.setAttribute("title", "When loading the workflow, configure which version of the component to use.");
|
||||
dbl_click_policy_combo.className = "cm-menu-combo";
|
||||
dbl_click_policy_combo.appendChild($el('option', { value: 'none', text: 'Double-Click: None' }, []));
|
||||
dbl_click_policy_combo.appendChild($el('option', { value: 'copy-all', text: 'Double-Click: Copy All Connections' }, []));
|
||||
dbl_click_policy_combo.appendChild($el('option', { value: 'copy-input', text: 'Double-Click: Copy Input Connections' }, []));
|
||||
dbl_click_policy_combo.appendChild($el('option', { value: 'possible-input', text: 'Double-Click: Possible Input Connections' }, []));
|
||||
dbl_click_policy_combo.appendChild($el('option', { value: 'dual', text: 'Double-Click: Possible(left) + Copy(right)' }, []));
|
||||
|
||||
api.fetchApi('/manager/dbl_click/policy')
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
dbl_click_policy_combo.value = data;
|
||||
set_double_click_policy(data);
|
||||
});
|
||||
|
||||
dbl_click_policy_combo.addEventListener('change', function (event) {
|
||||
api.fetchApi(`/manager/dbl_click/policy?value=${event.target.value}`);
|
||||
set_double_click_policy(event.target.value);
|
||||
});
|
||||
|
||||
api.fetchApi('/manager/share_option')
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
@@ -940,6 +962,7 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
default_ui_combo,
|
||||
share_combo,
|
||||
component_policy_combo,
|
||||
dbl_click_policy_combo,
|
||||
$el("br", {}, []),
|
||||
|
||||
$el("br", {}, []),
|
||||
@@ -1044,7 +1067,7 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
onclick: (e) => {
|
||||
const last_visited_site = localStorage.getItem("wg_last_visited")
|
||||
if (!!last_visited_site) {
|
||||
window.open(last_visited_site, "comfyui-workflow-gallery");
|
||||
window.open(last_visited_site, last_visited_site);
|
||||
} else {
|
||||
this.handleWorkflowGalleryButtonClick(e)
|
||||
}
|
||||
@@ -1171,7 +1194,7 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
callback: () => {
|
||||
const url = "https://openart.ai/workflows/dev";
|
||||
localStorage.setItem("wg_last_visited", url);
|
||||
window.open(url, "comfyui-workflow-gallery");
|
||||
window.open(url, url);
|
||||
modifyButtonStyle(url);
|
||||
},
|
||||
},
|
||||
@@ -1180,7 +1203,7 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
callback: () => {
|
||||
const url = "https://youml.com/?from=comfyui-share";
|
||||
localStorage.setItem("wg_last_visited", url);
|
||||
window.open(url, "comfyui-workflow-gallery");
|
||||
window.open(url, url);
|
||||
modifyButtonStyle(url);
|
||||
},
|
||||
},
|
||||
@@ -1189,7 +1212,16 @@ class ManagerMenuDialog extends ComfyDialog {
|
||||
callback: () => {
|
||||
const url = "https://comfyworkflows.com/";
|
||||
localStorage.setItem("wg_last_visited", url);
|
||||
window.open(url, "comfyui-workflow-gallery");
|
||||
window.open(url, url);
|
||||
modifyButtonStyle(url);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Open 'flowt.ai'",
|
||||
callback: () => {
|
||||
const url = "https://flowt.ai/";
|
||||
localStorage.setItem("wg_last_visited", url);
|
||||
window.open(url, url);
|
||||
modifyButtonStyle(url);
|
||||
},
|
||||
},
|
||||
@@ -1286,7 +1318,10 @@ app.registerExtension({
|
||||
async nodeCreated(node, app) {
|
||||
if(!node.badge_enabled) {
|
||||
node.getNickname = function () { return getNickname(node, node.comfyClass.trim()) };
|
||||
const orig = node.__proto__.onDrawForeground;
|
||||
let orig = node.onDrawForeground;
|
||||
if(!orig)
|
||||
orig = node.__proto__.onDrawForeground;
|
||||
|
||||
node.onDrawForeground = function (ctx) {
|
||||
drawBadge(node, orig, arguments)
|
||||
};
|
||||
|
||||
+159
-17
@@ -1,6 +1,16 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { api } from "../../scripts/api.js";
|
||||
|
||||
let double_click_policy = "copy-all";
|
||||
|
||||
api.fetchApi('/manager/dbl_click/policy')
|
||||
.then(response => response.text())
|
||||
.then(data => set_double_click_policy(data));
|
||||
|
||||
export function set_double_click_policy(mode) {
|
||||
double_click_policy = mode;
|
||||
}
|
||||
|
||||
function addMenuHandler(nodeType, cb) {
|
||||
const getOpts = nodeType.prototype.getExtraMenuOptions;
|
||||
nodeType.prototype.getExtraMenuOptions = function () {
|
||||
@@ -10,8 +20,88 @@ function addMenuHandler(nodeType, cb) {
|
||||
};
|
||||
}
|
||||
|
||||
function distance(node1, node2) {
|
||||
let dx = (node1.pos[0] + node1.size[0]/2) - (node2.pos[0] + node2.size[0]/2);
|
||||
let dy = (node1.pos[1] + node1.size[1]/2) - (node2.pos[1] + node2.size[1]/2);
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
function node_info_copy(src, dest) {
|
||||
function lookup_nearest_nodes(node) {
|
||||
let nearest_distance = Infinity;
|
||||
let nearest_node = null;
|
||||
for(let other of app.graph._nodes) {
|
||||
if(other === node)
|
||||
continue;
|
||||
|
||||
let dist = distance(node, other);
|
||||
if (dist < nearest_distance && dist < 1000) {
|
||||
nearest_distance = dist;
|
||||
nearest_node = other;
|
||||
}
|
||||
}
|
||||
|
||||
return nearest_node;
|
||||
}
|
||||
|
||||
function lookup_nearest_inputs(node) {
|
||||
let input_map = {};
|
||||
|
||||
for(let i in node.inputs) {
|
||||
let input = node.inputs[i];
|
||||
|
||||
if(input.link || input_map[input.type])
|
||||
continue;
|
||||
|
||||
input_map[input.type] = {distance: Infinity, input_name: input.name, node: null, slot: null};
|
||||
}
|
||||
|
||||
let x = node.pos[0];
|
||||
let y = node.pos[1] + node.size[1]/2;
|
||||
|
||||
for(let other of app.graph._nodes) {
|
||||
if(other === node || !other.outputs)
|
||||
continue;
|
||||
|
||||
let dx = x - (other.pos[0] + other.size[0]);
|
||||
let dy = y - (other.pos[1] + other.size[1]/2);
|
||||
|
||||
if(dx < 0)
|
||||
continue;
|
||||
|
||||
let dist = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
for(let input_type in input_map) {
|
||||
for(let j in other.outputs) {
|
||||
let output = other.outputs[j];
|
||||
if(output.type == input_type) {
|
||||
if(input_map[input_type].distance > dist) {
|
||||
input_map[input_type].distance = dist;
|
||||
input_map[input_type].node = other;
|
||||
input_map[input_type].slot = parseInt(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let res = {};
|
||||
for (let i in input_map) {
|
||||
if (input_map[i].node) {
|
||||
res[i] = input_map[i];
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
function connect_inputs(nearest_inputs, node) {
|
||||
for(let i in nearest_inputs) {
|
||||
let info = nearest_inputs[i];
|
||||
info.node.connect(info.slot, node.id, info.input_name);
|
||||
}
|
||||
}
|
||||
|
||||
function node_info_copy(src, dest, connect_both) {
|
||||
// copy input connections
|
||||
for(let i in src.inputs) {
|
||||
let input = src.inputs[i];
|
||||
@@ -23,25 +113,27 @@ function node_info_copy(src, dest) {
|
||||
}
|
||||
|
||||
// copy output connections
|
||||
let output_links = {};
|
||||
for(let i in src.outputs) {
|
||||
let output = src.outputs[i];
|
||||
if(output.links) {
|
||||
let links = [];
|
||||
for(let j in output.links) {
|
||||
links.push(app.graph.links[output.links[j]]);
|
||||
if(connect_both) {
|
||||
let output_links = {};
|
||||
for(let i in src.outputs) {
|
||||
let output = src.outputs[i];
|
||||
if(output.links) {
|
||||
let links = [];
|
||||
for(let j in output.links) {
|
||||
links.push(app.graph.links[output.links[j]]);
|
||||
}
|
||||
output_links[output.name] = links;
|
||||
}
|
||||
output_links[output.name] = links;
|
||||
}
|
||||
}
|
||||
|
||||
for(let i in dest.outputs) {
|
||||
let links = output_links[dest.outputs[i].name];
|
||||
if(links) {
|
||||
for(let j in links) {
|
||||
let link = links[j];
|
||||
let target_node = app.graph.getNodeById(link.target_id);
|
||||
dest.connect(parseInt(i), target_node, link.target_slot);
|
||||
for(let i in dest.outputs) {
|
||||
let links = output_links[dest.outputs[i].name];
|
||||
if(links) {
|
||||
for(let j in links) {
|
||||
let link = links[j];
|
||||
let target_node = app.graph.getNodeById(link.target_id);
|
||||
dest.connect(parseInt(i), target_node, link.target_slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +144,56 @@ function node_info_copy(src, dest) {
|
||||
app.registerExtension({
|
||||
name: "Comfy.Manager.NodeFixer",
|
||||
|
||||
async nodeCreated(node, app) {
|
||||
let orig_dblClick = node.onDblClick;
|
||||
node.onDblClick = function (e, pos, self) {
|
||||
orig_dblClick?.apply?.(this, arguments);
|
||||
|
||||
if((!node.inputs && !node.outputs) || pos[1] > 0)
|
||||
return;
|
||||
|
||||
switch(double_click_policy) {
|
||||
case "copy-all":
|
||||
case "copy-input":
|
||||
{
|
||||
if(node.inputs?.some(x => x.link != null) || node.outputs?.some(x => x.links != null && x.links.length > 0) )
|
||||
return;
|
||||
|
||||
let src_node = lookup_nearest_nodes(node);
|
||||
if(src_node)
|
||||
node_info_copy(src_node, node, double_click_policy == "copy-all");
|
||||
}
|
||||
break;
|
||||
case "possible-input":
|
||||
{
|
||||
let nearest_inputs = lookup_nearest_inputs(node);
|
||||
if(nearest_inputs)
|
||||
connect_inputs(nearest_inputs, node);
|
||||
}
|
||||
break;
|
||||
case "dual":
|
||||
{
|
||||
if(pos[0] < node.size[0]/2) {
|
||||
// left: possible-input
|
||||
let nearest_inputs = lookup_nearest_inputs(node);
|
||||
if(nearest_inputs)
|
||||
connect_inputs(nearest_inputs, node);
|
||||
}
|
||||
else {
|
||||
// right: copy-all
|
||||
if(node.inputs?.some(x => x.link != null) || node.outputs?.some(x => x.links != null && x.links.length > 0) )
|
||||
return;
|
||||
|
||||
let src_node = lookup_nearest_nodes(node);
|
||||
if(src_node)
|
||||
node_info_copy(src_node, node, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
addMenuHandler(nodeType, function (_, options) {
|
||||
options.push({
|
||||
|
||||
Reference in New Issue
Block a user