mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-09 21:04:41 +08:00
Initial simple context menu for adding set/get
wip
This commit is contained in:
parent
26cdd07f52
commit
8202643f82
51
web/js/contextmenu.js
Normal file
51
web/js/contextmenu.js
Normal file
@ -0,0 +1,51 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
// Adds context menu entries, code from pyssssscustom-scripts
|
||||
|
||||
function addMenuHandler(nodeType, cb) {
|
||||
const getOpts = nodeType.prototype.getExtraMenuOptions;
|
||||
nodeType.prototype.getExtraMenuOptions = function () {
|
||||
const r = getOpts.apply(this, arguments);
|
||||
cb.apply(this, arguments);
|
||||
return r;
|
||||
};
|
||||
}
|
||||
|
||||
function addNode(name, nextTo, options) {
|
||||
options = { select: true, shiftY: 0, shiftX: 0, before: false, ...(options || {}) };
|
||||
const node = LiteGraph.createNode(name);
|
||||
app.graph.add(node);
|
||||
node.pos = [
|
||||
options.before ? nextTo.pos[0] - node.size[0] - 30 : nextTo.pos[0] + nextTo.size[0] + 30,
|
||||
nextTo.pos[0] + options.shiftX,
|
||||
nextTo.pos[1] + options.shiftY,
|
||||
|
||||
];
|
||||
if (options.select) {
|
||||
app.canvas.selectNode(node, false);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
app.registerExtension({
|
||||
name: "KJNodesContextmenu",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.input && nodeData.input.required) {
|
||||
addMenuHandler(nodeType, function (_, options) {
|
||||
options.unshift(
|
||||
{
|
||||
content: "Add GetNode",
|
||||
callback: () => {addNode("GetNode", this, { shiftY: 0,shiftX: this.size[0] + 30 });}
|
||||
},
|
||||
{
|
||||
content: "Add SetNode",
|
||||
callback: () => {
|
||||
addNode("SetNode", this);
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user