This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
/
nodeActions.ts
127 lines (113 loc) · 3.77 KB
/
nodeActions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { Action } from 'redux';
import { Position, Rectangle, Size } from 'diagramMaker/state/types';
export enum NodeActionsType {
NODE_CREATE = 'NODE_CREATE',
NODE_DELETE = 'NODE_DELETE',
NODE_SELECT = 'NODE_SELECT',
NODE_DRAG_START = 'NODE_DRAG_START',
NODE_DRAG_END = 'NODE_DRAG_END',
NODE_DRAG = 'NODE_DRAG',
NODE_LAYOUT = 'NODE_LAYOUT',
POTENTIAL_NODE_DRAG_START = 'POTENTIAL_NODE_DRAG_START',
POTENTIAL_NODE_DRAG = 'POTENTIAL_NODE_DRAG',
POTENTIAL_NODE_DRAG_END = 'POTENTIAL_NODE_DRAG_END',
}
export const NodeActions = {
...NodeActionsType,
};
/** Action fired to create a new node */
export interface CreateNodeAction<NodeType> extends Action {
type: NodeActionsType.NODE_CREATE;
payload: {
/** ID for the new node that needs to be created. Needs to be unique. */
id: string,
/** type ID of the new node. Picked up from the potential node that was used to create this node. */
typeId: string,
/** Position where the new node will be created. */
position: Position,
/** Size of the new node */
size: Size,
/** Consumer data that needs to be added for the newly created node. */
consumerData?: NodeType
};
}
/** Action fired when a new potential node starts being dragged */
export interface DragStartPotentialNodeAction extends Action {
type: NodeActionsType.POTENTIAL_NODE_DRAG_START;
payload: {
/**
* type ID of the new node that will be created if this is dropped on the workspace.
* Picked up from the potential node that was used to create this potential node.
*/
typeId: string,
/** Current position of the potential node */
position: Position,
/** Size for the node that will be created if this is dropped on the workspace. */
size: Size
};
}
/** Action fired to update the position for a potential node */
export interface DragPotentialNodeAction extends Action {
type: NodeActionsType.POTENTIAL_NODE_DRAG;
payload: {
/** Updated position for the potential node */
position: Position,
/** A Rectangle representing the workspace */
workspaceRectangle: Rectangle
};
}
/** Action fired to end dragging the potential node */
export interface DragEndPotentialNodeAction extends Action {
type: NodeActionsType.POTENTIAL_NODE_DRAG_END;
}
/** Action fired to select a node */
export interface SelectNodeAction extends Action {
type: NodeActionsType.NODE_SELECT;
payload: {
/** ID of the node to select */
id: string;
};
}
/**
* Action fired to delete a node.
* Please note that this doesn't delete the connected edges
* and may lead to edges that remain in state but are not rendered.
*/
export interface DeleteNodeAction extends Action {
type: NodeActionsType.NODE_DELETE;
payload: {
/** ID of the node to delete */
id: string;
};
}
/** Action fired to start dragging a node */
export interface DragStartNodeAction extends Action {
type: NodeActionsType.NODE_DRAG_START;
payload: {
/** ID of the node to start dragging for */
id: string;
};
}
/** Action fired to end dragging a node */
export interface DragEndNodeAction extends Action {
type: NodeActionsType.NODE_DRAG_END;
payload: {
/** ID of the node to end dragging for */
id: string;
};
}
/** Action fired to update the position for the node */
export interface DragNodeAction extends Action {
type: NodeActionsType.NODE_DRAG;
payload: {
/** ID of the node to update position for */
id: string;
/** Updated position for the node */
position: Position;
workspaceRectangle: Rectangle;
size: Size;
};
}
export type NodeAction<NodeType> =
SelectNodeAction | DeleteNodeAction | DragStartNodeAction | DragEndNodeAction | DragNodeAction |
DragPotentialNodeAction | DragStartPotentialNodeAction | DragEndPotentialNodeAction | CreateNodeAction<NodeType>;