MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / processContextMenu

Method processContextMenu

src/LGraphCanvas.ts:7608–7793  ·  view source on GitHub ↗
(node: LGraphNode | undefined, event: CanvasPointerEvent)

Source from the content-addressed store, hash-verified

7606 }
7607
7608 processContextMenu(node: LGraphNode | undefined, event: CanvasPointerEvent): void {
7609 const canvas = LGraphCanvas.active_canvas
7610 const ref_window = canvas.getCanvasWindow()
7611
7612 // TODO: Remove type kludge
7613 let menu_info: (IContextMenuValue | string | null)[]
7614 const options: IContextMenuOptions = {
7615 event,
7616 callback: inner_option_clicked,
7617 extra: node,
7618 }
7619
7620 if (node) {
7621 options.title = node.displayType ?? node.type ?? undefined
7622 LGraphCanvas.active_node = node
7623
7624 // check if mouse is in input
7625 const slot = node.getSlotInPosition(event.canvasX, event.canvasY)
7626 if (slot) {
7627 // on slot
7628 menu_info = []
7629 if (node.getSlotMenuOptions) {
7630 menu_info = node.getSlotMenuOptions(slot)
7631 } else {
7632 if (slot.output?.links?.length || slot.input?.link != null) {
7633 menu_info.push({ content: "Disconnect Links", slot })
7634 }
7635
7636 const _slot = slot.input || slot.output
7637 if (!_slot) throw new TypeError("Both in put and output slots were null when processing context menu.")
7638
7639 if (_slot.removable) {
7640 menu_info.push(
7641 _slot.locked
7642 ? "Cannot remove"
7643 : { content: "Remove Slot", slot },
7644 )
7645 }
7646 if (!_slot.nameLocked && !(("link" in _slot) && _slot.widget)) {
7647 menu_info.push({ content: "Rename Slot", slot })
7648 }
7649
7650 if (node.getExtraSlotMenuOptions) {
7651 menu_info.push(...node.getExtraSlotMenuOptions(slot))
7652 }
7653 }
7654 // @ts-expect-error Slot type can be number and has number checks
7655 options.title = (slot.input ? slot.input.type : slot.output.type) || "*"
7656 if (slot.input && slot.input.type == LiteGraph.ACTION)
7657 options.title = "Action"
7658
7659 if (slot.output && slot.output.type == LiteGraph.EVENT)
7660 options.title = "Event"
7661 } else {
7662 // on node
7663 menu_info = this.getNodeMenuOptions(node)
7664 }
7665 } else {

Callers 1

processMouseDownMethod · 0.95

Calls 8

getNodeMenuOptionsMethod · 0.95
getCanvasMenuOptionsMethod · 0.95
getCanvasWindowMethod · 0.80
getSlotInPositionMethod · 0.80
getGroupOnPosMethod · 0.80
getMenuOptionsMethod · 0.80
getRerouteOnPosMethod · 0.65
removeRerouteMethod · 0.65

Tested by

no test coverage detected