Line data Source code
1 : import type { LGraphCanvas } from '@/lib/litegraph/src/litegraph'
2 : import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
3 : import { LayoutSource } from '@/renderer/core/layout/types'
4 :
5 2355 : export function notifyLayoutChanges(canvas: LGraphCanvas): () => void {
6 2355 : const stopOperations = layoutStore.onChange((change) => {
7 110694 : const graph = canvas.graph
8 110694 : if (
9 : !graph ||
10 : change.operation.graphId !== graph.rootGraph.id ||
11 : change.source === LayoutSource.Canvas
12 : ) {
13 109277 : return
14 : }
15 :
16 25361 : for (const nodeId of change.sizeChangedNodeIds) {
17 135 : const node = graph.getNodeById(nodeId)
18 135 : node?.onResize?.(node.size)
19 : }
20 : })
21 2355 : const stopGeometry = layoutStore.onGeometryChange((graphIds) => {
22 120638 : const graph = canvas.graph
23 120638 : if (!graph || !graphIds.has(graph.rootGraph.id)) return
24 :
25 118970 : canvas.setDirty(true, true)
26 : })
27 :
28 2355 : return () => {
29 0 : stopOperations()
30 0 : stopGeometry()
31 : }
32 : }
|