mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 19:49:58 +00:00
[fix] Preserve subgraph structure when clearing workflow (#4567)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -3,6 +3,8 @@ import type { LGraph, LGraphNode, Subgraph } from '@comfyorg/litegraph'
|
||||
import type { NodeLocatorId } from '@/types/nodeIdentification'
|
||||
import { parseNodeLocatorId } from '@/types/nodeIdentification'
|
||||
|
||||
import { isSubgraphIoNode } from './typeGuardUtil'
|
||||
|
||||
/**
|
||||
* Parses an execution ID into its component parts.
|
||||
*
|
||||
@@ -338,3 +340,14 @@ export function mapSubgraphNodes<T>(
|
||||
return undefined
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all non-IO nodes from a subgraph (excludes SubgraphInputNode and SubgraphOutputNode).
|
||||
* These are the user-created nodes that can be safely removed when clearing a subgraph.
|
||||
*
|
||||
* @param subgraph - The subgraph to get non-IO nodes from
|
||||
* @returns Array of non-IO nodes (user-created nodes)
|
||||
*/
|
||||
export function getAllNonIoNodesInSubgraph(subgraph: Subgraph): LGraphNode[] {
|
||||
return subgraph.nodes.filter((node) => !isSubgraphIoNode(node))
|
||||
}
|
||||
|
||||
@@ -27,3 +27,16 @@ export const isSubgraph = (
|
||||
*/
|
||||
export const isNonNullish = <T>(item: T | undefined | null): item is T =>
|
||||
item != null
|
||||
|
||||
/**
|
||||
* Type guard to check if a node is a subgraph input/output node.
|
||||
* These nodes are essential to subgraph structure and should not be removed.
|
||||
*/
|
||||
export const isSubgraphIoNode = (
|
||||
node: LGraphNode
|
||||
): node is LGraphNode & {
|
||||
constructor: { comfyClass: 'SubgraphInputNode' | 'SubgraphOutputNode' }
|
||||
} => {
|
||||
const nodeClass = node.constructor?.comfyClass
|
||||
return nodeClass === 'SubgraphInputNode' || nodeClass === 'SubgraphOutputNode'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user