1use serde::{Deserialize, Serialize};
2
3use crate::core::{
4 Binding, BindingEndpoint, BindingId, CanvasPoint, CanvasRect, CanvasSize, Edge, EdgeId,
5 EdgeKind, EdgeReconnectable, GraphId, GraphImport, Group, GroupId, Node, NodeExtent, NodeId,
6 NodeKindKey, NodeOrigin, Port, PortId, StickyNote, StickyNoteId, Symbol, SymbolId,
7};
8use crate::types::TypeDesc;
9
10use super::endpoints::EdgeEndpoints;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(tag = "op", rename_all = "snake_case")]
18pub enum GraphOp {
19 AddNode { id: NodeId, node: Node },
21 RemoveNode {
25 id: NodeId,
26 node: Node,
27 #[serde(default, skip_serializing_if = "Vec::is_empty")]
28 ports: Vec<(PortId, Port)>,
29 #[serde(default, skip_serializing_if = "Vec::is_empty")]
30 edges: Vec<(EdgeId, Edge)>,
31 #[serde(default, skip_serializing_if = "Vec::is_empty")]
32 bindings: Vec<(BindingId, Binding)>,
33 },
34 SetNodePos {
36 id: NodeId,
37 from: CanvasPoint,
38 to: CanvasPoint,
39 },
40 SetNodeOrigin {
42 id: NodeId,
43 from: Option<NodeOrigin>,
44 to: Option<NodeOrigin>,
45 },
46 SetNodeKind {
48 id: NodeId,
49 from: NodeKindKey,
50 to: NodeKindKey,
51 },
52 SetNodeKindVersion { id: NodeId, from: u32, to: u32 },
54 SetNodeSelectable {
56 id: NodeId,
57 from: Option<bool>,
58 to: Option<bool>,
59 },
60 SetNodeFocusable {
62 id: NodeId,
63 from: Option<bool>,
64 to: Option<bool>,
65 },
66 SetNodeDraggable {
68 id: NodeId,
69 from: Option<bool>,
70 to: Option<bool>,
71 },
72 SetNodeConnectable {
74 id: NodeId,
75 from: Option<bool>,
76 to: Option<bool>,
77 },
78 SetNodeDeletable {
80 id: NodeId,
81 from: Option<bool>,
82 to: Option<bool>,
83 },
84 SetNodeParent {
86 id: NodeId,
87 from: Option<GroupId>,
88 to: Option<GroupId>,
89 },
90 SetNodeExtent {
92 id: NodeId,
93 from: Option<NodeExtent>,
94 to: Option<NodeExtent>,
95 },
96 SetNodeExpandParent {
98 id: NodeId,
99 from: Option<bool>,
100 to: Option<bool>,
101 },
102 SetNodeSize {
104 id: NodeId,
105 from: Option<CanvasSize>,
106 to: Option<CanvasSize>,
107 },
108 SetNodeHidden { id: NodeId, from: bool, to: bool },
110 SetNodeCollapsed { id: NodeId, from: bool, to: bool },
112 SetNodePorts {
114 id: NodeId,
115 from: Vec<PortId>,
116 to: Vec<PortId>,
117 },
118 SetNodeData {
123 id: NodeId,
124 from: serde_json::Value,
125 to: serde_json::Value,
126 },
127
128 AddPort { id: PortId, port: Port },
130 RemovePort {
134 id: PortId,
135 port: Port,
136 #[serde(default, skip_serializing_if = "Vec::is_empty")]
137 edges: Vec<(EdgeId, Edge)>,
138 #[serde(default, skip_serializing_if = "Vec::is_empty")]
139 bindings: Vec<(BindingId, Binding)>,
140 },
141 SetPortConnectable {
143 id: PortId,
144 from: Option<bool>,
145 to: Option<bool>,
146 },
147 SetPortConnectableStart {
149 id: PortId,
150 from: Option<bool>,
151 to: Option<bool>,
152 },
153 SetPortConnectableEnd {
155 id: PortId,
156 from: Option<bool>,
157 to: Option<bool>,
158 },
159 SetPortType {
161 id: PortId,
162 from: Option<TypeDesc>,
163 to: Option<TypeDesc>,
164 },
165 SetPortData {
167 id: PortId,
168 from: serde_json::Value,
169 to: serde_json::Value,
170 },
171
172 AddEdge { id: EdgeId, edge: Edge },
174 RemoveEdge {
176 id: EdgeId,
177 edge: Edge,
178 #[serde(default, skip_serializing_if = "Vec::is_empty")]
179 bindings: Vec<(BindingId, Binding)>,
180 },
181 SetEdgeKind {
183 id: EdgeId,
184 from: EdgeKind,
185 to: EdgeKind,
186 },
187 SetEdgeSelectable {
189 id: EdgeId,
190 from: Option<bool>,
191 to: Option<bool>,
192 },
193 SetEdgeFocusable {
195 id: EdgeId,
196 from: Option<bool>,
197 to: Option<bool>,
198 },
199 SetEdgeHidden { id: EdgeId, from: bool, to: bool },
201 SetEdgeInteractionWidth {
203 id: EdgeId,
204 from: Option<f32>,
205 to: Option<f32>,
206 },
207 SetEdgeDeletable {
209 id: EdgeId,
210 from: Option<bool>,
211 to: Option<bool>,
212 },
213 SetEdgeReconnectable {
215 id: EdgeId,
216 from: Option<EdgeReconnectable>,
217 to: Option<EdgeReconnectable>,
218 },
219 SetEdgeEndpoints {
221 id: EdgeId,
222 from: EdgeEndpoints,
223 to: EdgeEndpoints,
224 },
225
226 AddImport { id: GraphId, import: GraphImport },
228 RemoveImport { id: GraphId, import: GraphImport },
230 SetImportAlias {
232 id: GraphId,
233 from: Option<String>,
234 to: Option<String>,
235 },
236
237 AddSymbol { id: SymbolId, symbol: Symbol },
239 RemoveSymbol { id: SymbolId, symbol: Symbol },
241 SetSymbolName {
243 id: SymbolId,
244 from: String,
245 to: String,
246 },
247 SetSymbolType {
249 id: SymbolId,
250 from: Option<TypeDesc>,
251 to: Option<TypeDesc>,
252 },
253 SetSymbolDefaultValue {
255 id: SymbolId,
256 from: Option<serde_json::Value>,
257 to: Option<serde_json::Value>,
258 },
259 SetSymbolMeta {
261 id: SymbolId,
262 from: serde_json::Value,
263 to: serde_json::Value,
264 },
265
266 AddGroup { id: GroupId, group: Group },
268 RemoveGroup {
272 id: GroupId,
273 group: Group,
274 #[serde(default, skip_serializing_if = "Vec::is_empty")]
275 detached: Vec<(NodeId, Option<GroupId>)>,
276 #[serde(default, skip_serializing_if = "Vec::is_empty")]
277 bindings: Vec<(BindingId, Binding)>,
278 },
279 SetGroupRect {
281 id: GroupId,
282 from: CanvasRect,
283 to: CanvasRect,
284 },
285 SetGroupTitle {
287 id: GroupId,
288 from: String,
289 to: String,
290 },
291 SetGroupColor {
293 id: GroupId,
294 from: Option<String>,
295 to: Option<String>,
296 },
297
298 AddStickyNote { id: StickyNoteId, note: StickyNote },
300 RemoveStickyNote {
302 id: StickyNoteId,
303 note: StickyNote,
304 #[serde(default, skip_serializing_if = "Vec::is_empty")]
305 bindings: Vec<(BindingId, Binding)>,
306 },
307 SetStickyNoteText {
309 id: StickyNoteId,
310 from: String,
311 to: String,
312 },
313 SetStickyNoteRect {
315 id: StickyNoteId,
316 from: CanvasRect,
317 to: CanvasRect,
318 },
319 SetStickyNoteColor {
321 id: StickyNoteId,
322 from: Option<String>,
323 to: Option<String>,
324 },
325
326 AddBinding { id: BindingId, binding: Binding },
328 RemoveBinding { id: BindingId, binding: Binding },
330 SetBindingSubject {
332 id: BindingId,
333 from: BindingEndpoint,
334 to: BindingEndpoint,
335 },
336 SetBindingTarget {
338 id: BindingId,
339 from: BindingEndpoint,
340 to: BindingEndpoint,
341 },
342 SetBindingKind {
344 id: BindingId,
345 from: Option<String>,
346 to: Option<String>,
347 },
348 SetBindingMeta {
350 id: BindingId,
351 from: serde_json::Value,
352 to: serde_json::Value,
353 },
354}