mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 15:10:06 +00:00
Bad circular dep fix: Lazily import and lose some types (needs long term solution)
This commit is contained in:
@@ -33,7 +33,7 @@ import { MapProxyHandler } from "./MapProxyHandler"
|
||||
import { alignOutsideContainer, alignToContainer, createBounds } from "./measure"
|
||||
import { Reroute, type RerouteId } from "./Reroute"
|
||||
import { stringOrEmpty } from "./strings"
|
||||
import { type GraphOrSubgraph, Subgraph } from "./subgraph/Subgraph"
|
||||
import type { GraphOrSubgraph } from "./subgraph/Subgraph"
|
||||
import { SubgraphInput } from "./subgraph/SubgraphInput"
|
||||
import { SubgraphOutput } from "./subgraph/SubgraphOutput"
|
||||
import { findUsedSubgraphIds, getBoundaryLinks, groupResolvedByOutput, mapSubgraphInputsAndLinks, mapSubgraphOutputsAndLinks, multiClone, splitPositionables } from "./subgraph/subgraphUtils"
|
||||
@@ -130,7 +130,7 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
|
||||
}
|
||||
|
||||
readonly events = new CustomEventTarget<LGraphEventMap>()
|
||||
readonly _subgraphs: Map<UUID, Subgraph> = new Map()
|
||||
readonly _subgraphs: Map<UUID, any> = new Map()
|
||||
|
||||
_nodes: (LGraphNode | SubgraphNode)[] = []
|
||||
_nodes_by_id: Record<NodeId, LGraphNode> = {}
|
||||
@@ -331,7 +331,7 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
|
||||
this.canvasAction(c => c.clear())
|
||||
}
|
||||
|
||||
get subgraphs(): Map<UUID, Subgraph> {
|
||||
get subgraphs(): Map<UUID, any> {
|
||||
return this.rootGraph._subgraphs
|
||||
}
|
||||
|
||||
@@ -1402,9 +1402,11 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
|
||||
* @param data Exported data (typically serialised) to configure the new subgraph with
|
||||
* @returns The newly created subgraph definition.
|
||||
*/
|
||||
createSubgraph(data: ExportedSubgraph): Subgraph {
|
||||
createSubgraph(data: ExportedSubgraph): any {
|
||||
const { id } = data
|
||||
|
||||
// Lazy load Subgraph to avoid circular dependency
|
||||
const { Subgraph } = require("./subgraph/Subgraph")
|
||||
const subgraph = new Subgraph(this.rootGraph, data)
|
||||
this.subgraphs.set(id, subgraph)
|
||||
|
||||
@@ -1413,7 +1415,7 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable<Serialisabl
|
||||
return subgraph
|
||||
}
|
||||
|
||||
convertToSubgraph(items: Set<Positionable>): { subgraph: Subgraph, node: SubgraphNode } {
|
||||
convertToSubgraph(items: Set<Positionable>): { subgraph: any, node: SubgraphNode } {
|
||||
if (items.size === 0) throw new Error("Cannot convert to subgraph: nothing to convert")
|
||||
const { state, revision, config } = this
|
||||
|
||||
|
||||
@@ -12,9 +12,7 @@ import type { IBaseWidget } from "@/lib/litegraph/src/types/widgets"
|
||||
import { SUBGRAPH_INPUT_ID, SUBGRAPH_OUTPUT_ID } from "@/lib/litegraph/src/constants"
|
||||
import { CustomEventTarget } from "@/lib/litegraph/src/infrastructure/CustomEventTarget"
|
||||
import { LLink } from "@/lib/litegraph/src/LLink"
|
||||
import { Subgraph } from "@/lib/litegraph/src/subgraph/Subgraph"
|
||||
import { SubgraphInputNode } from "@/lib/litegraph/src/subgraph/SubgraphInputNode"
|
||||
import { SubgraphOutputNode } from "@/lib/litegraph/src/subgraph/SubgraphOutputNode"
|
||||
import { Subgraph } from "@/lib/litegraph/src/litegraph"
|
||||
import { LinkDirection } from "@/lib/litegraph/src/types/globalEnums"
|
||||
|
||||
import { FloatingRenderLink } from "./FloatingRenderLink"
|
||||
@@ -310,7 +308,7 @@ export class LinkConnector {
|
||||
this.#setLegacyLinks(true)
|
||||
}
|
||||
|
||||
dragNewFromSubgraphInput(network: LinkNetwork, inputNode: SubgraphInputNode, input: SubgraphInput, fromReroute?: Reroute): void {
|
||||
dragNewFromSubgraphInput(network: LinkNetwork, inputNode: any, input: SubgraphInput, fromReroute?: Reroute): void {
|
||||
if (this.isConnecting) throw new Error("Already dragging links.")
|
||||
|
||||
const renderLink = new ToInputFromIoNodeLink(network, inputNode, input, fromReroute)
|
||||
@@ -321,7 +319,7 @@ export class LinkConnector {
|
||||
this.#setLegacyLinks(false)
|
||||
}
|
||||
|
||||
dragNewFromSubgraphOutput(network: LinkNetwork, outputNode: SubgraphOutputNode, output: SubgraphOutput, fromReroute?: Reroute): void {
|
||||
dragNewFromSubgraphOutput(network: LinkNetwork, outputNode: any, output: SubgraphOutput, fromReroute?: Reroute): void {
|
||||
if (this.isConnecting) throw new Error("Already dragging links.")
|
||||
|
||||
const renderLink = new ToOutputFromIoNodeLink(network, outputNode, output, fromReroute)
|
||||
@@ -499,19 +497,19 @@ export class LinkConnector {
|
||||
}
|
||||
}
|
||||
|
||||
dropOnIoNode(ioNode: SubgraphInputNode | SubgraphOutputNode, event: CanvasPointerEvent): void {
|
||||
dropOnIoNode(ioNode: any, event: CanvasPointerEvent): void {
|
||||
const { renderLinks, state } = this
|
||||
const { connectingTo } = state
|
||||
const { canvasX, canvasY } = event
|
||||
|
||||
if (connectingTo === "input" && ioNode instanceof SubgraphOutputNode) {
|
||||
if (connectingTo === "input" && ioNode.id === SUBGRAPH_OUTPUT_ID) {
|
||||
const output = ioNode.getSlotInPosition(canvasX, canvasY)
|
||||
if (!output) throw new Error("No output slot found for link.")
|
||||
|
||||
for (const link of renderLinks) {
|
||||
link.connectToSubgraphOutput(output, this.events)
|
||||
}
|
||||
} else if (connectingTo === "output" && ioNode instanceof SubgraphInputNode) {
|
||||
} else if (connectingTo === "output" && ioNode.id === SUBGRAPH_INPUT_ID) {
|
||||
const input = ioNode.getSlotInPosition(canvasX, canvasY)
|
||||
if (!input) throw new Error("No input slot found for link.")
|
||||
|
||||
|
||||
@@ -14,13 +14,20 @@ import { LLink } from "@/lib/litegraph/src/LLink"
|
||||
import { NodeSlotType } from "@/lib/litegraph/src/types/globalEnums"
|
||||
import { findFreeSlotOfType } from "@/lib/litegraph/src/utils/collections"
|
||||
|
||||
import { EmptySubgraphInput } from "./EmptySubgraphInput"
|
||||
import { SubgraphIONodeBase } from "./SubgraphIONodeBase"
|
||||
|
||||
export class SubgraphInputNode extends SubgraphIONodeBase<SubgraphInput> implements Positionable {
|
||||
readonly id: NodeId = SUBGRAPH_INPUT_ID
|
||||
|
||||
readonly emptySlot: EmptySubgraphInput = new EmptySubgraphInput(this)
|
||||
private _emptySlot?: any // EmptySubgraphInput type
|
||||
get emptySlot(): any {
|
||||
if (!this._emptySlot) {
|
||||
// Lazy load to avoid circular dependency
|
||||
const { EmptySubgraphInput } = require("./EmptySubgraphInput")
|
||||
this._emptySlot = new EmptySubgraphInput(this)
|
||||
}
|
||||
return this._emptySlot
|
||||
}
|
||||
|
||||
get slots() {
|
||||
return this.subgraph.inputs
|
||||
|
||||
@@ -14,13 +14,20 @@ import { SUBGRAPH_OUTPUT_ID } from "@/lib/litegraph/src/constants"
|
||||
import { Rectangle } from "@/lib/litegraph/src/infrastructure/Rectangle"
|
||||
import { findFreeSlotOfType } from "@/lib/litegraph/src/utils/collections"
|
||||
|
||||
import { EmptySubgraphOutput } from "./EmptySubgraphOutput"
|
||||
import { SubgraphIONodeBase } from "./SubgraphIONodeBase"
|
||||
|
||||
export class SubgraphOutputNode extends SubgraphIONodeBase<SubgraphOutput> implements Positionable {
|
||||
readonly id: NodeId = SUBGRAPH_OUTPUT_ID
|
||||
|
||||
readonly emptySlot: EmptySubgraphOutput = new EmptySubgraphOutput(this)
|
||||
private _emptySlot?: any // EmptySubgraphOutput type
|
||||
get emptySlot(): any {
|
||||
if (!this._emptySlot) {
|
||||
// Lazy load to avoid circular dependency
|
||||
const { EmptySubgraphOutput } = require("./EmptySubgraphOutput")
|
||||
this._emptySlot = new EmptySubgraphOutput(this)
|
||||
}
|
||||
return this._emptySlot
|
||||
}
|
||||
|
||||
get slots() {
|
||||
return this.subgraph.outputs
|
||||
|
||||
Reference in New Issue
Block a user