MCPcopy Index your code
hub / github.com/rgthree/rgthree-comfy / addMenuSubMenu

Function addMenuSubMenu

js/utils.js:43–66  ·  view source on GitHub ↗
(node, _app, config)

Source from the content-addressed store, hash-verified

41 };
42}
43export function addMenuSubMenu(node, _app, config) {
44 const oldGetExtraMenuOptions = node.prototype.getExtraMenuOptions;
45 node.prototype.getExtraMenuOptions = function (canvas, menuOptions) {
46 oldGetExtraMenuOptions && oldGetExtraMenuOptions.apply(this, [canvas, menuOptions]);
47 const idx = menuOptions.findIndex(option => option === null || option === void 0 ? void 0 : option.content.includes('Shape')) + 1;
48 menuOptions.splice((idx > 0 ? idx : menuOptions.length - 1), 0, {
49 content: typeof config.name == 'function' ? config.name(this) : config.name,
50 has_submenu: true,
51 callback: (_value, _options, event, parentMenu, _node) => {
52 new LiteGraph.ContextMenu(config.options.map(option => ({ content: option })), {
53 event,
54 parentMenu,
55 callback: (value, _options, _event, _parentMenu, _node) => {
56 if (config.property) {
57 this.properties = this.properties || {};
58 this.properties[config.property] = config.prepareValue ? config.prepareValue(value.content, this) : value.content;
59 }
60 config.callback && config.callback(this);
61 },
62 });
63 }
64 });
65 };
66}
67export function addConnectionLayoutSupport(node, app, options = [['Left', 'Right'], ['Right', 'Left']], callback) {
68 addMenuSubMenu(node, app, {
69 name: 'Connections Layout',

Callers 3

registerCustomNodesFunction · 0.90
registerCustomNodesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected