1use serde::{Deserialize, Serialize};
2
3use crate::core::{
4 Binding, BindingEndpoint, BindingId, CanvasPoint, CanvasRect, CanvasSize, Edge, EdgeId,
5 EdgeKind, EdgeReconnectable, EdgeViewDescriptor, GraphId, GraphImport, Group, GroupId, Node,
6 NodeExtent, NodeId, NodeKindKey, NodeOrigin, Port, PortId, StickyNote, StickyNoteId, Symbol,
7 SymbolId,
8};
9use crate::types::TypeDesc;
10
11use super::endpoints::EdgeEndpoints;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(tag = "op", rename_all = "snake_case")]
19pub enum GraphOp {
20 AddNode { id: NodeId, node: Node },
22 RemoveNode {
26 id: NodeId,
27 node: Node,
28 #[serde(default, skip_serializing_if = "Vec::is_empty")]
29 ports: Vec<(PortId, Port)>,
30 #[serde(default, skip_serializing_if = "Vec::is_empty")]
31 edges: Vec<(EdgeId, Edge)>,
32 #[serde(default, skip_serializing_if = "Vec::is_empty")]
33 bindings: Vec<(BindingId, Binding)>,
34 },
35 SetNodePos {
37 id: NodeId,
38 from: CanvasPoint,
39 to: CanvasPoint,
40 },
41 SetNodeOrigin {
43 id: NodeId,
44 from: Option<NodeOrigin>,
45 to: Option<NodeOrigin>,
46 },
47 SetNodeKind {
49 id: NodeId,
50 from: NodeKindKey,
51 to: NodeKindKey,
52 },
53 SetNodeKindVersion { id: NodeId, from: u32, to: u32 },
55 SetNodeSelectable {
57 id: NodeId,
58 from: Option<bool>,
59 to: Option<bool>,
60 },
61 SetNodeFocusable {
63 id: NodeId,
64 from: Option<bool>,
65 to: Option<bool>,
66 },
67 SetNodeDraggable {
69 id: NodeId,
70 from: Option<bool>,
71 to: Option<bool>,
72 },
73 SetNodeConnectable {
75 id: NodeId,
76 from: Option<bool>,
77 to: Option<bool>,
78 },
79 SetNodeDeletable {
81 id: NodeId,
82 from: Option<bool>,
83 to: Option<bool>,
84 },
85 SetNodeParent {
87 id: NodeId,
88 from: Option<GroupId>,
89 to: Option<GroupId>,
90 },
91 SetNodeExtent {
93 id: NodeId,
94 from: Option<NodeExtent>,
95 to: Option<NodeExtent>,
96 },
97 SetNodeExpandParent {
99 id: NodeId,
100 from: Option<bool>,
101 to: Option<bool>,
102 },
103 SetNodeSize {
105 id: NodeId,
106 from: Option<CanvasSize>,
107 to: Option<CanvasSize>,
108 },
109 SetNodeHidden { id: NodeId, from: bool, to: bool },
111 SetNodeCollapsed { id: NodeId, from: bool, to: bool },
113 SetNodePorts {
115 id: NodeId,
116 from: Vec<PortId>,
117 to: Vec<PortId>,
118 },
119 SetNodeData {
124 id: NodeId,
125 from: serde_json::Value,
126 to: serde_json::Value,
127 },
128
129 AddPort { id: PortId, port: Port },
131 RemovePort {
135 id: PortId,
136 port: Port,
137 #[serde(default, skip_serializing_if = "Vec::is_empty")]
138 edges: Vec<(EdgeId, Edge)>,
139 #[serde(default, skip_serializing_if = "Vec::is_empty")]
140 bindings: Vec<(BindingId, Binding)>,
141 },
142 SetPortConnectable {
144 id: PortId,
145 from: Option<bool>,
146 to: Option<bool>,
147 },
148 SetPortConnectableStart {
150 id: PortId,
151 from: Option<bool>,
152 to: Option<bool>,
153 },
154 SetPortConnectableEnd {
156 id: PortId,
157 from: Option<bool>,
158 to: Option<bool>,
159 },
160 SetPortType {
162 id: PortId,
163 from: Option<TypeDesc>,
164 to: Option<TypeDesc>,
165 },
166 SetPortData {
168 id: PortId,
169 from: serde_json::Value,
170 to: serde_json::Value,
171 },
172
173 AddEdge { id: EdgeId, edge: Edge },
175 RemoveEdge {
177 id: EdgeId,
178 edge: Edge,
179 #[serde(default, skip_serializing_if = "Vec::is_empty")]
180 bindings: Vec<(BindingId, Binding)>,
181 },
182 SetEdgeKind {
184 id: EdgeId,
185 from: EdgeKind,
186 to: EdgeKind,
187 },
188 SetEdgeSelectable {
190 id: EdgeId,
191 from: Option<bool>,
192 to: Option<bool>,
193 },
194 SetEdgeFocusable {
196 id: EdgeId,
197 from: Option<bool>,
198 to: Option<bool>,
199 },
200 SetEdgeHidden { id: EdgeId, from: bool, to: bool },
202 SetEdgeInteractionWidth {
204 id: EdgeId,
205 from: Option<f32>,
206 to: Option<f32>,
207 },
208 SetEdgeDeletable {
210 id: EdgeId,
211 from: Option<bool>,
212 to: Option<bool>,
213 },
214 SetEdgeReconnectable {
216 id: EdgeId,
217 from: Option<EdgeReconnectable>,
218 to: Option<EdgeReconnectable>,
219 },
220 SetEdgeData {
222 id: EdgeId,
223 from: serde_json::Value,
224 to: serde_json::Value,
225 },
226 SetEdgeView {
228 id: EdgeId,
229 from: EdgeViewDescriptor,
230 to: EdgeViewDescriptor,
231 },
232 SetEdgeEndpoints {
234 id: EdgeId,
235 from: EdgeEndpoints,
236 to: EdgeEndpoints,
237 },
238
239 AddImport { id: GraphId, import: GraphImport },
241 RemoveImport { id: GraphId, import: GraphImport },
243 SetImportAlias {
245 id: GraphId,
246 from: Option<String>,
247 to: Option<String>,
248 },
249
250 AddSymbol { id: SymbolId, symbol: Symbol },
252 RemoveSymbol { id: SymbolId, symbol: Symbol },
254 SetSymbolName {
256 id: SymbolId,
257 from: String,
258 to: String,
259 },
260 SetSymbolType {
262 id: SymbolId,
263 from: Option<TypeDesc>,
264 to: Option<TypeDesc>,
265 },
266 SetSymbolDefaultValue {
268 id: SymbolId,
269 from: Option<serde_json::Value>,
270 to: Option<serde_json::Value>,
271 },
272 SetSymbolMeta {
274 id: SymbolId,
275 from: serde_json::Value,
276 to: serde_json::Value,
277 },
278
279 AddGroup { id: GroupId, group: Group },
281 RemoveGroup {
285 id: GroupId,
286 group: Group,
287 #[serde(default, skip_serializing_if = "Vec::is_empty")]
288 detached: Vec<(NodeId, Option<GroupId>)>,
289 #[serde(default, skip_serializing_if = "Vec::is_empty")]
290 bindings: Vec<(BindingId, Binding)>,
291 },
292 SetGroupRect {
294 id: GroupId,
295 from: CanvasRect,
296 to: CanvasRect,
297 },
298 SetGroupTitle {
300 id: GroupId,
301 from: String,
302 to: String,
303 },
304 SetGroupColor {
306 id: GroupId,
307 from: Option<String>,
308 to: Option<String>,
309 },
310
311 AddStickyNote { id: StickyNoteId, note: StickyNote },
313 RemoveStickyNote {
315 id: StickyNoteId,
316 note: StickyNote,
317 #[serde(default, skip_serializing_if = "Vec::is_empty")]
318 bindings: Vec<(BindingId, Binding)>,
319 },
320 SetStickyNoteText {
322 id: StickyNoteId,
323 from: String,
324 to: String,
325 },
326 SetStickyNoteRect {
328 id: StickyNoteId,
329 from: CanvasRect,
330 to: CanvasRect,
331 },
332 SetStickyNoteColor {
334 id: StickyNoteId,
335 from: Option<String>,
336 to: Option<String>,
337 },
338
339 AddBinding { id: BindingId, binding: Binding },
341 RemoveBinding { id: BindingId, binding: Binding },
343 SetBindingSubject {
345 id: BindingId,
346 from: BindingEndpoint,
347 to: BindingEndpoint,
348 },
349 SetBindingTarget {
351 id: BindingId,
352 from: BindingEndpoint,
353 to: BindingEndpoint,
354 },
355 SetBindingKind {
357 id: BindingId,
358 from: Option<String>,
359 to: Option<String>,
360 },
361 SetBindingMeta {
363 id: BindingId,
364 from: serde_json::Value,
365 to: serde_json::Value,
366 },
367}