Skip to main content

jellyflow_core/ops/fragment/collect/
mod.rs

1mod collector;
2
3use crate::core::{Graph, GroupId, NodeId};
4
5use super::model::GraphFragment;
6use collector::FragmentCollector;
7
8impl GraphFragment {
9    /// Builds a fragment from a set of nodes, capturing:
10    /// - the selected nodes,
11    /// - their ports,
12    /// - edges that connect between selected nodes.
13    ///
14    /// Groups/notes are not inferred; callers may add them explicitly.
15    ///
16    /// Symbols are inferred for built-in symbol-ref nodes (`core::SYMBOL_REF_NODE_KIND`) so
17    /// copy/paste can remain self-contained for the "blackboard variables" contract.
18    pub fn from_nodes(graph: &Graph, nodes: impl IntoIterator<Item = NodeId>) -> Self {
19        Self::from_selection(graph, nodes, std::iter::empty())
20    }
21
22    /// Builds a fragment from a selection of nodes and groups.
23    ///
24    /// Captures:
25    /// - selected groups,
26    /// - selected nodes,
27    /// - nodes inside selected groups,
28    /// - ports for all captured nodes,
29    /// - edges that connect between captured nodes.
30    ///
31    /// Nodes are detached from their parent group unless that group is included in the fragment.
32    pub fn from_selection(
33        graph: &Graph,
34        selected_nodes: impl IntoIterator<Item = NodeId>,
35        selected_groups: impl IntoIterator<Item = GroupId>,
36    ) -> Self {
37        FragmentCollector::new(graph, selected_nodes, selected_groups).finish()
38    }
39}
40
41#[cfg(test)]
42mod tests;