showConnectionMenu with searchbox options (#111)

* showConnectionMenu with searchbox options

* nit
This commit is contained in:
Chenlei Hu
2024-09-03 13:07:38 -04:00
committed by GitHub
parent bcd3c6b30f
commit 85076881c8
2 changed files with 25 additions and 16 deletions

11
public/litegraph.d.ts vendored
View File

@@ -1537,7 +1537,16 @@ export declare class LGraphCanvas {
callback: Function, callback: Function,
event: any event: any
): HTMLDivElement; ): HTMLDivElement;
showSearchBox(event?: MouseEvent): void; showSearchBox(event?: MouseEvent, options?: LinkReleaseContext): void;
showConnectionMenu(optPass?: {
nodeFrom?: LGraphNode;
slotFrom?: INodeSlot | string | number;
nodeTo?: LGraphNode;
slotTo?: INodeSlot | string | number;
e?: MouseEvent;
allow_searchbox?: boolean;
showSearchBox?: (event?: MouseEvent, options?: LinkReleaseContext) => void;
}): void;
showEditPropertyValue(node: LGraphNode, property: any, options: any): void; showEditPropertyValue(node: LGraphNode, property: any, options: any): void;
createDialog( createDialog(
html: string, html: string,

View File

@@ -7651,13 +7651,13 @@ const globalExport = {};
}; };
this.canvas.dispatchEvent(new CustomEvent( this.canvas.dispatchEvent(new CustomEvent(
"litegraph:canvas", { "litegraph:canvas", {
bubbles: true, bubbles: true,
detail: { detail: {
subType: "empty-release", subType: "empty-release",
originalEvent: e, originalEvent: e,
linkReleaseContext: linkReleaseContextExtended, linkReleaseContext: linkReleaseContextExtended,
}, },
} }
)); ));
// add menu when releasing link in empty space // add menu when releasing link in empty space
if (LiteGraph.release_link_on_empty_shows_menu) { if (LiteGraph.release_link_on_empty_shows_menu) {
@@ -11319,7 +11319,9 @@ const globalExport = {};
, ,
slotTo: null // output slotTo: null // output
, ,
e: null e: null,
allow_searchbox: this.allow_searchbox,
showSearchBox: this.showSearchBox,
}, },
optPass optPass
); );
@@ -11330,7 +11332,7 @@ const globalExport = {};
if (!isFrom && !isTo) { if (!isFrom && !isTo) {
console.warn("No data passed to showConnectionMenu"); console.warn("No data passed to showConnectionMenu");
return false; return;
} }
var nodeX = isFrom ? opts.nodeFrom : opts.nodeTo; var nodeX = isFrom ? opts.nodeFrom : opts.nodeTo;
@@ -11354,12 +11356,12 @@ const globalExport = {};
// bad ? // bad ?
//iSlotConn = 0; //iSlotConn = 0;
console.warn("Cant get slot information " + slotX); console.warn("Cant get slot information " + slotX);
return false; return;
} }
var options = ["Add Node", null]; var options = ["Add Node", null];
if (that.allow_searchbox) { if (opts.allow_searchbox) {
options.push("Search"); options.push("Search");
options.push(null); options.push(null);
} }
@@ -11399,9 +11401,9 @@ const globalExport = {};
break; break;
case "Search": case "Search":
if (isFrom) { if (isFrom) {
that.showSearchBox(e, { node_from: opts.nodeFrom, slot_from: slotX, type_filter_in: fromSlotType }); opts.showSearchBox(e, { node_from: opts.nodeFrom, slot_from: slotX, type_filter_in: fromSlotType });
} else { } else {
that.showSearchBox(e, { node_to: opts.nodeTo, slot_from: slotX, type_filter_out: fromSlotType }); opts.showSearchBox(e, { node_to: opts.nodeTo, slot_from: slotX, type_filter_out: fromSlotType });
} }
break; break;
default: default:
@@ -11419,8 +11421,6 @@ const globalExport = {};
break; break;
} }
} }
return false;
} }
// refactor: there are different dialogs, some uses createDialog some dont // refactor: there are different dialogs, some uses createDialog some dont
prompt(title, value, callback, event, multiline) { prompt(title, value, callback, event, multiline) {