Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/lib/litegraph/src/LGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,22 @@ export class LGraph
} {
if (items.size === 0)
throw new Error('Cannot convert to subgraph: nothing to convert')

// Record state before conversion for proper undo support
this.beforeChange()

try {
return this._convertToSubgraphImpl(items)
} finally {
// Mark state change complete for proper undo support
this.afterChange()
}
}

private _convertToSubgraphImpl(items: Set<Positionable>): {
subgraph: Subgraph
node: SubgraphNode
} {
const { state, revision, config } = this
const firstChild = [...items][0]
if (items.size === 1 && firstChild instanceof LGraphGroup) {
Expand Down Expand Up @@ -1715,6 +1731,7 @@ export class LGraph

subgraphNode._setConcreteSlots()
subgraphNode.arrange()

this.canvasAction((c) =>
c.canvas.dispatchEvent(
new CustomEvent('subgraph-converted', {
Expand All @@ -1733,9 +1750,23 @@ export class LGraph
if (!(subgraphNode instanceof SubgraphNode))
throw new Error('Can only unpack Subgraph Nodes')

// Record state before unpacking for proper undo support
this.beforeChange()

try {
this._unpackSubgraphImpl(subgraphNode, options)
} finally {
// Mark state change complete for proper undo support
this.afterChange()
}
}

private _unpackSubgraphImpl(
subgraphNode: SubgraphNode,
options?: { skipMissingNodes?: boolean }
) {
const skipMissingNodes = options?.skipMissingNodes ?? false

this.beforeChange()
//NOTE: Create bounds can not be called on positionables directly as the subgraph is not being displayed and boundingRect is not initialized.
//NOTE: NODE_TITLE_HEIGHT is explicitly excluded here
const positionables = [
Expand Down Expand Up @@ -2006,7 +2037,6 @@ export class LGraph
}

this.canvasAction((c) => c.selectItems(toSelect))
this.afterChange()
}

/**
Expand Down