Skip to main content

jellyflow_runtime/runtime/drag/
store.rs

1use crate::runtime::store::{DispatchError, DispatchOutcome, NodeGraphStore};
2
3use super::planner::{plan_node_drag, plan_node_nudge};
4use super::types::{NodeDragPlan, NodeDragRequest, NodeNudgePlan, NodeNudgeRequest};
5
6impl NodeGraphStore {
7    /// Plans a node drag update against the store's current selection and interaction state.
8    pub fn plan_node_drag(&self, request: NodeDragRequest) -> Option<NodeDragPlan> {
9        let interaction = self.resolved_interaction_state();
10        plan_node_drag(self.graph(), self.view_state(), &interaction, request)
11    }
12
13    /// Plans a keyboard nudge update against the store's current selection and interaction state.
14    pub fn plan_node_nudge(&self, request: NodeNudgeRequest) -> Option<NodeNudgePlan> {
15        let interaction = self.resolved_interaction_state();
16        plan_node_nudge(self.graph(), self.view_state(), &interaction, request)
17    }
18
19    /// Commits a node drag update through the normal store dispatch path.
20    ///
21    /// This records normal graph history for the committed update. Higher-level drag sessions that
22    /// need preview/final-commit semantics should build on top of the planning API.
23    pub fn apply_node_drag(
24        &mut self,
25        request: NodeDragRequest,
26    ) -> Result<Option<DispatchOutcome>, DispatchError> {
27        let Some(plan) = self.plan_node_drag(request) else {
28            return Ok(None);
29        };
30        self.dispatch_transaction(plan.transaction()).map(Some)
31    }
32
33    /// Commits a keyboard nudge update through the normal store dispatch path.
34    pub fn apply_node_nudge(
35        &mut self,
36        request: NodeNudgeRequest,
37    ) -> Result<Option<DispatchOutcome>, DispatchError> {
38        let Some(plan) = self.plan_node_nudge(request) else {
39            return Ok(None);
40        };
41        self.dispatch_transaction(plan.transaction()).map(Some)
42    }
43}