File size: 1,630 Bytes
681fa96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { app } from "../../scripts/app.js";

function autoCreateMenu(opts) {
    //opts.e.stopPropagation();
    var options = ["Search",];
    var search_opts;
    if (opts.nodeFrom && opts.slotFrom) {
        options.push(null);
        options.push("Anything Everywhere");
        options.push("Anything Everywhere?");
        if (opts.nodeFrom?.outputs?.length==3 && 
            opts.nodeFrom.outputs[0].name=='MODEL' && 
            opts.nodeFrom.outputs[1].name=='CLIP' && 
            opts.nodeFrom.outputs[2].name=='VAE') options.push("Anything Everywhere3");
        search_opts = {node_from: opts.nodeFrom, slot_from: opts.slotFrom, type_filter_in: opts.slotFrom.type};
    } else {
        search_opts = {node_to: opts.nodeTo, slot_from: opts.slotTo, type_filter_out: slotTo.type};
    }

    var menu = new LiteGraph.ContextMenu(options, {
        event: opts.e,
        title: "UE Node",
        callback: inner_clicked
    });

    const p = [	opts.e.canvasX, opts.e.canvasY ];

    function inner_clicked(v,options,e) {
        if (!v) return;
        if (v=="Search") {
            app.canvas.showSearchBox(opts.e,search_opts);
            return;
        }
        var newNode = LiteGraph.createNode(v);
        app.graph.add(newNode);
        newNode.pos = p; 
        if (v=="Anything Everywhere3") {
            for (var i=0; i<3; i++) {opts.nodeFrom.connect( i, newNode, i );}
        } else {
            opts.nodeFrom.connect( opts.nodeFrom.findOutputSlot(opts.slotFrom.name), newNode, 0 );
        }
        app.graph.change();
    }
}

export {autoCreateMenu}