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

Method showConnectionMenu

src/LGraphCanvas.ts:6022–6188  ·  view source on GitHub ↗
(optPass: Partial<ICreateNodeOptions & { e: MouseEvent }>)

Source from the content-addressed store, hash-verified

6020 }
6021
6022 showConnectionMenu(optPass: Partial<ICreateNodeOptions & { e: MouseEvent }>): ContextMenu<string> | undefined {
6023 const opts = Object.assign<ICreateNodeOptions & HasShowSearchCallback, ICreateNodeOptions>({
6024 nodeFrom: null,
6025 slotFrom: null,
6026 nodeTo: null,
6027 slotTo: null,
6028 e: undefined,
6029 allow_searchbox: this.allow_searchbox,
6030 showSearchBox: this.showSearchBox,
6031 }, optPass || {})
6032 const dirty = () => this.#dirty()
6033 const that = this
6034 const { graph } = this
6035 const { afterRerouteId } = opts
6036
6037 const isFrom = opts.nodeFrom && opts.slotFrom
6038 const isTo = !isFrom && opts.nodeTo && opts.slotTo
6039
6040 if (!isFrom && !isTo) {
6041 console.warn("No data passed to showConnectionMenu")
6042 return
6043 }
6044
6045 const nodeX = isFrom ? opts.nodeFrom : opts.nodeTo
6046 if (!nodeX) throw new TypeError("nodeX was null when creating default node for slot.")
6047 let slotX = isFrom ? opts.slotFrom : opts.slotTo
6048
6049 let iSlotConn: number
6050 if (nodeX instanceof SubgraphIONodeBase) {
6051 if (typeof slotX !== "object" || !slotX) {
6052 console.warn("Cant get slot information", slotX)
6053 return
6054 }
6055 const { name } = slotX
6056 iSlotConn = nodeX.slots.findIndex(s => s.name === name)
6057 // If it's not found in the main slots, it might be the empty slot from a Subgraph node.
6058 // In that case, the original `slotX` object is the correct one, so don't overwrite it.
6059 if (iSlotConn !== -1) {
6060 slotX = nodeX.slots[iSlotConn]
6061 }
6062 if (!slotX) {
6063 console.warn("Cant get slot information", slotX)
6064 return
6065 }
6066 } else {
6067 switch (typeof slotX) {
6068 case "string":
6069 iSlotConn = isFrom
6070 ? nodeX.findOutputSlot(slotX, false)
6071 : nodeX.findInputSlot(slotX, false)
6072 slotX = isFrom ? nodeX.outputs[slotX] : nodeX.inputs[slotX]
6073 break
6074 case "object":
6075 if (slotX === null) {
6076 console.warn("Cant get slot information", slotX)
6077 return
6078 }
6079

Callers 1

constructorMethod · 0.95

Calls 2

findInputSlotMethod · 0.80
findOutputSlotMethod · 0.45

Tested by

no test coverage detected