1
- import LogicFlow , { h , RectNode , RectNodeModel } from '@logicflow/core'
2
- import RectSize = LogicFlow . RectSize
1
+ import LogicFlow , {
2
+ h ,
3
+ GraphModel ,
4
+ RectNode ,
5
+ RectNodeModel ,
6
+ IRectNodeProperties ,
7
+ } from '@logicflow/core'
8
+ import NodeConfig = LogicFlow . NodeConfig
3
9
4
- export class GroupNode extends RectNode {
10
+ export type IGroupNodeProps = {
11
+ model : GroupNodeModel
12
+ graphModel : GraphModel
13
+ }
14
+
15
+ // 分组节点默认展开时的大小
16
+ const DEFAULT_GROUP_EXPAND_WIDTH = 500
17
+ const DEFAULT_GROUP_EXPAND_HEIGHT = 300
18
+ // 分组节点默认收起时的大小
19
+ const DEFAULT_GROUP_COLLAPSE_WIDTH = 80
20
+ const DEFAULT_GROUP_COLLAPSE_HEIGHT = 60
21
+
22
+ const DEFAULT_BOTTOM_Z_INDEX = - 10000
23
+
24
+ export class GroupNode <
25
+ P extends IGroupNodeProps = IGroupNodeProps ,
26
+ > extends RectNode < P > {
5
27
getResizeControl ( ) : h . JSX . Element | null {
6
28
const { resizable, properties } = this . props . model
7
29
const showResizeControl = resizable && properties . _isCollapsed
8
30
return showResizeControl ? super . getResizeControl ( ) : null
9
31
}
10
32
11
33
getGroupShape ( ) : h . JSX . Element | null {
34
+ // TODO: 此区域用于初始化 group container, 即元素拖拽进入感应区域
12
35
return null
13
36
}
14
37
@@ -55,7 +78,7 @@ export class GroupNode extends RectNode {
55
78
x : sx ,
56
79
y : sy ,
57
80
onClick : ( ) => {
58
- model . foldGroup ( ! model . properties . isFolded )
81
+ model . toggleCollapse ( ! model . properties . isCollapsed )
59
82
} ,
60
83
} ) ,
61
84
operateIcon ,
@@ -71,19 +94,116 @@ export class GroupNode extends RectNode {
71
94
}
72
95
}
73
96
74
- export class GroupNodeModel extends RectNodeModel {
97
+ export type IGroupNodeProperties = {
98
+ children ?: string [ ]
99
+ isCollapsed ?: boolean
100
+ isRestrict ?: boolean
101
+ collapsible ?: boolean
102
+ collapsedWidth ?: number
103
+ collapsedHeight ?: number
104
+
105
+ expandWidth ?: number
106
+ expandHeight ?: number
107
+ zIndex ?: number
108
+ autoToFront ?: boolean
109
+ } & IRectNodeProperties
110
+
111
+ export class GroupNodeModel extends RectNodeModel < IGroupNodeProperties > {
75
112
readonly isGroup = true
76
113
77
114
// 保存组内的节点
78
115
children : Set < string > = new Set ( )
79
116
// 是否限制组内节点的移动范围。默认不限制
80
117
isRestrict : boolean = false
81
118
// 分组节点是否可以折叠
82
- foldable : boolean = true
83
- isFolded : boolean = false
119
+ collapsible : boolean = true
120
+ // 当前组是否收起状态
121
+ isCollapsed : boolean = false
122
+
123
+ // 分组节点 初始化尺寸(默认展开),后续支持从 properties 中传入 width 和 height 设置
124
+ expandWidth : number = DEFAULT_GROUP_EXPAND_WIDTH
125
+ expandHeight : number = DEFAULT_GROUP_EXPAND_HEIGHT
126
+ // 折叠后
127
+ collapsedWidth : number = DEFAULT_GROUP_COLLAPSE_WIDTH
128
+ collapsedHeight : number = DEFAULT_GROUP_COLLAPSE_HEIGHT
129
+
130
+ childrenLastFoldState : Record < string , boolean > = { }
131
+
132
+ constructor ( data : NodeConfig < IGroupNodeProperties > , graphModel : GraphModel ) {
133
+ super ( data , graphModel )
134
+
135
+ this . setAttributes ( )
136
+ }
137
+
138
+ setAttributes ( ) {
139
+ super . setAttributes ( )
140
+
141
+ const {
142
+ children,
143
+ width,
144
+ height,
145
+ collapsible,
146
+ isCollapsed,
147
+ zIndex,
148
+ isRestrict,
149
+ autoToFront,
150
+ } = this . properties
84
151
85
- defaultSize : RectSize = { width : 400 , height : 200 }
86
- expandSize : RectSize = { width : 80 , height : 40 }
152
+ if ( children ) this . children = new Set ( children )
153
+
154
+ if ( width ) {
155
+ this . width = width
156
+ this . expandWidth = width
157
+ }
158
+ if ( height ) {
159
+ this . height = height
160
+ this . expandHeight = height
161
+ }
162
+ this . zIndex = zIndex ?? DEFAULT_BOTTOM_Z_INDEX
163
+
164
+ this . isRestrict = isRestrict ?? false
165
+ this . collapsible = collapsible ?? true
166
+ this . autoToFront = autoToFront ?? false
167
+
168
+ // 禁用掉 Group 节点的文本编辑能力
169
+ this . text . editable = false
170
+ this . text . draggable = false
171
+
172
+ // 当前状态为折叠时,调用一下折叠的方法
173
+ // 确认是否
174
+ isCollapsed && this . collapseGroup ( )
175
+ }
176
+
177
+ /**
178
+ * 折叠 or 展开分组
179
+ * 1. 折叠分组的宽高
180
+ * 2. 处理分组子节点
181
+ * 3. 处理连线
182
+ * @param collapsed
183
+ */
184
+ toggleCollapse ( collapsed ?: boolean ) {
185
+ console . log ( 'collapsed' , collapsed )
186
+ }
187
+
188
+ collapse ( ) { }
189
+
190
+ expand ( ) { }
191
+
192
+ /**
193
+ * 重写 Group 节点的 Resize Outline
194
+ */
195
+ getResizeOutlineStyle ( ) : LogicFlow . CommonTheme {
196
+ const style = super . getResizeOutlineStyle ( )
197
+ style . stroke = 'none'
198
+ return style
199
+ }
200
+
201
+ // TODO: 是否是设置 group 节点没有锚点,而不是设置成透明???
202
+ getAnchorStyle ( ) {
203
+ const style = super . getAnchorStyle ( )
204
+ style . stroke = 'transparent'
205
+ return style
206
+ }
87
207
}
88
208
89
209
export const groupNode = {
0 commit comments