Skip to content

Commit 6a3c075

Browse files
Removes node's dependency on LGraph for access to layout mutations composable (#5356)
* remove DI * remove layoutMutations property on LGraph * remove layout mutations property from LGraph snapshot
1 parent c30f5a4 commit 6a3c075

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

src/lib/litegraph/src/LGraph.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
import type { UUID } from '@/lib/litegraph/src/utils/uuid'
88
import { createUuidv4, zeroUuid } from '@/lib/litegraph/src/utils/uuid'
99
import { useLayoutMutations } from '@/renderer/core/layout/operations/LayoutMutations'
10-
import type { LayoutMutations } from '@/renderer/core/layout/operations/LayoutMutations'
1110
import { LayoutSource } from '@/renderer/core/layout/types'
1211

1312
import type { DragAndScaleState } from './DragAndScale'
@@ -191,9 +190,6 @@ export class LGraph
191190
nodes_executedAction: string[] = []
192191
extra: LGraphExtra = {}
193192

194-
/** Layout mutations instance for this graph */
195-
layoutMutations!: LayoutMutations
196-
197193
/** @deprecated Deserialising a workflow sets this unused property. */
198194
version?: number
199195

@@ -280,9 +276,6 @@ export class LGraph
280276
constructor(o?: ISerialisedGraph | SerialisableGraph) {
281277
if (LiteGraph.debug) console.log('Graph created')
282278

283-
// Get layout mutations composable
284-
this.layoutMutations = useLayoutMutations()
285-
286279
/** @see MapProxyHandler */
287280
const links = this._links
288281
MapProxyHandler.bindAllMethods(links)
@@ -1345,6 +1338,7 @@ export class LGraph
13451338
* @returns The newly created reroute - typically ignored.
13461339
*/
13471340
createReroute(pos: Point, before: LinkSegment): Reroute {
1341+
const layoutMutations = useLayoutMutations()
13481342
const rerouteId = ++this.state.lastRerouteId
13491343
const linkIds = before instanceof Reroute ? before.linkIds : [before.id]
13501344
const floatingLinkIds =
@@ -1360,8 +1354,8 @@ export class LGraph
13601354
this.reroutes.set(rerouteId, reroute)
13611355

13621356
// Register reroute in Layout Store for spatial tracking
1363-
this.layoutMutations.setSource(LayoutSource.Canvas)
1364-
this.layoutMutations.createReroute(
1357+
layoutMutations.setSource(LayoutSource.Canvas)
1358+
layoutMutations.createReroute(
13651359
rerouteId,
13661360
{ x: pos[0], y: pos[1] },
13671361
before.parentId,
@@ -1398,6 +1392,7 @@ export class LGraph
13981392
* @param id ID of reroute to remove
13991393
*/
14001394
removeReroute(id: RerouteId): void {
1395+
const layoutMutations = useLayoutMutations()
14011396
const { reroutes } = this
14021397
const reroute = reroutes.get(id)
14031398
if (!reroute) return
@@ -1443,8 +1438,8 @@ export class LGraph
14431438
reroutes.delete(id)
14441439

14451440
// Delete reroute from Layout Store
1446-
this.layoutMutations.setSource(LayoutSource.Canvas)
1447-
this.layoutMutations.deleteReroute(id)
1441+
layoutMutations.setSource(LayoutSource.Canvas)
1442+
layoutMutations.deleteReroute(id)
14481443

14491444
// This does not belong here; it should be handled by the caller, or run by a remove-many API.
14501445
// https://github.com/Comfy-Org/litegraph.js/issues/898
@@ -2129,6 +2124,7 @@ export class LGraph
21292124
data: ISerialisedGraph | SerialisableGraph,
21302125
keep_old?: boolean
21312126
): boolean | undefined {
2127+
const layoutMutations = useLayoutMutations()
21322128
const options: LGraphEventMap['configuring'] = {
21332129
data,
21342130
clearGraph: !keep_old
@@ -2270,8 +2266,8 @@ export class LGraph
22702266
if (!reroute.validateLinks(this._links, this.floatingLinks)) {
22712267
this.reroutes.delete(reroute.id)
22722268
// Clean up layout store
2273-
this.layoutMutations.setSource(LayoutSource.Canvas)
2274-
this.layoutMutations.deleteReroute(reroute.id)
2269+
layoutMutations.setSource(LayoutSource.Canvas)
2270+
layoutMutations.deleteReroute(reroute.id)
22752271
}
22762272
}
22772273

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
calculateInputSlotPosFromSlot,
66
calculateOutputSlotPos
77
} from '@/renderer/core/canvas/litegraph/SlotCalculations'
8+
import { useLayoutMutations } from '@/renderer/core/layout/operations/LayoutMutations'
89
import { LayoutSource } from '@/renderer/core/layout/types'
910

1011
import type { DragAndScale } from './DragAndScale'
@@ -2785,6 +2786,8 @@ export class LGraphNode
27852786
const { graph } = this
27862787
if (!graph) throw new NullGraphError()
27872788

2789+
const layoutMutations = useLayoutMutations()
2790+
27882791
const outputIndex = this.outputs.indexOf(output)
27892792
if (outputIndex === -1) {
27902793
console.warn('connectSlots: output not found')
@@ -2844,8 +2847,8 @@ export class LGraphNode
28442847
graph._links.set(link.id, link)
28452848

28462849
// Register link in Layout Store for spatial tracking
2847-
graph.layoutMutations.setSource(LayoutSource.Canvas)
2848-
graph.layoutMutations.createLink(
2850+
layoutMutations.setSource(LayoutSource.Canvas)
2851+
layoutMutations.createLink(
28492852
link.id,
28502853
this.id,
28512854
outputIndex,

tests-ui/tests/litegraph/core/__snapshots__/LGraph.test.ts.snap

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,6 @@ LGraph {
281281
"id": "b4e984f1-b421-4d24-b8b4-ff895793af13",
282282
"iteration": 0,
283283
"last_update_time": 0,
284-
"layoutMutations": {
285-
"bringNodeToFront": [Function],
286-
"createLink": [Function],
287-
"createNode": [Function],
288-
"createReroute": [Function],
289-
"deleteLink": [Function],
290-
"deleteNode": [Function],
291-
"deleteReroute": [Function],
292-
"moveNode": [Function],
293-
"moveReroute": [Function],
294-
"resizeNode": [Function],
295-
"setActor": [Function],
296-
"setNodeZIndex": [Function],
297-
"setSource": [Function],
298-
},
299284
"links": Map {},
300285
"list_of_graphcanvas": null,
301286
"nodes_actioning": [],

0 commit comments

Comments
 (0)