@logicflow/extension 2.2.0-alpha.5 → 2.2.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +15 -0
  3. package/dist/index.min.js +1 -1
  4. package/dist/index.min.js.map +1 -1
  5. package/es/bpmn-elements-adapter/json2xml.d.ts +2 -1
  6. package/es/bpmn-elements-adapter/json2xml.js +18 -4
  7. package/es/bpmn-elements-adapter/xml2json.js +2 -7
  8. package/es/components/control/index.js +3 -3
  9. package/es/index.d.ts +1 -0
  10. package/es/index.js +2 -0
  11. package/es/materials/curved-edge/index.js +41 -25
  12. package/es/pool/LaneModel.d.ts +90 -0
  13. package/es/pool/LaneModel.js +252 -0
  14. package/es/pool/LaneView.d.ts +40 -0
  15. package/es/pool/LaneView.js +202 -0
  16. package/es/pool/PoolModel.d.ts +120 -0
  17. package/es/pool/PoolModel.js +586 -0
  18. package/es/pool/PoolView.d.ts +17 -0
  19. package/es/pool/PoolView.js +76 -0
  20. package/es/pool/constant.d.ts +15 -0
  21. package/es/pool/constant.js +17 -0
  22. package/es/pool/index.d.ts +89 -0
  23. package/es/pool/index.js +524 -0
  24. package/es/pool/utils.d.ts +19 -0
  25. package/es/pool/utils.js +33 -0
  26. package/lib/bpmn-elements-adapter/json2xml.d.ts +2 -1
  27. package/lib/bpmn-elements-adapter/json2xml.js +19 -4
  28. package/lib/bpmn-elements-adapter/xml2json.js +2 -7
  29. package/lib/components/control/index.js +3 -3
  30. package/lib/index.d.ts +1 -0
  31. package/lib/index.js +2 -0
  32. package/lib/materials/curved-edge/index.js +41 -25
  33. package/lib/pool/LaneModel.d.ts +90 -0
  34. package/lib/pool/LaneModel.js +255 -0
  35. package/lib/pool/LaneView.d.ts +40 -0
  36. package/lib/pool/LaneView.js +205 -0
  37. package/lib/pool/PoolModel.d.ts +120 -0
  38. package/lib/pool/PoolModel.js +589 -0
  39. package/lib/pool/PoolView.d.ts +17 -0
  40. package/lib/pool/PoolView.js +79 -0
  41. package/lib/pool/constant.d.ts +15 -0
  42. package/lib/pool/constant.js +20 -0
  43. package/lib/pool/index.d.ts +89 -0
  44. package/lib/pool/index.js +527 -0
  45. package/lib/pool/utils.d.ts +19 -0
  46. package/lib/pool/utils.js +38 -0
  47. package/package.json +5 -5
  48. package/src/bpmn-elements-adapter/json2xml.ts +18 -4
  49. package/src/bpmn-elements-adapter/xml2json.ts +2 -8
  50. package/src/components/control/index.ts +3 -3
  51. package/src/dynamic-group/index.ts +0 -1
  52. package/src/index.ts +2 -0
  53. package/src/materials/curved-edge/index.ts +47 -30
  54. package/src/pool/LaneModel.ts +226 -0
  55. package/src/pool/LaneView.ts +220 -0
  56. package/src/pool/PoolModel.ts +631 -0
  57. package/src/pool/PoolView.ts +75 -0
  58. package/src/pool/constant.ts +19 -0
  59. package/src/pool/index.ts +621 -0
  60. package/src/pool/utils.ts +46 -0
  61. package/stats.html +1 -1
@@ -0,0 +1,589 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
29
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
32
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.PoolModel = void 0;
36
+ var mobx_1 = require("mobx");
37
+ var lodash_es_1 = require("lodash-es");
38
+ var model_1 = require("../dynamic-group/model");
39
+ var constant_1 = require("./constant");
40
+ var PoolModel = /** @class */ (function (_super) {
41
+ __extends(PoolModel, _super);
42
+ function PoolModel(data, graphModel) {
43
+ var _this = _super.call(this, data, graphModel) || this;
44
+ // 泳池特定属性
45
+ // 标题区域大小:如果是垂直方向,指代的就是标题区的宽度,如果是水平方向,指代的就是标题区的高度
46
+ _this.titleSize = constant_1.poolConfig.titleSize;
47
+ _this.poolConfig = constant_1.poolConfig;
48
+ _this.isPool = true;
49
+ // 标记是否已创建默认泳道
50
+ _this._defaultLaneCreated = false;
51
+ return _this;
52
+ }
53
+ Object.defineProperty(PoolModel.prototype, "isHorizontal", {
54
+ get: function () {
55
+ var _a;
56
+ return ((_a = this.properties) === null || _a === void 0 ? void 0 : _a.direction) === 'horizontal';
57
+ },
58
+ enumerable: false,
59
+ configurable: true
60
+ });
61
+ PoolModel.prototype.initNodeData = function (data) {
62
+ var _a, _b;
63
+ _super.prototype.initNodeData.call(this, data);
64
+ if (data.properties) {
65
+ // 泳池基础配置
66
+ this.width = ((_a = data.properties) === null || _a === void 0 ? void 0 : _a.width) || constant_1.poolConfig.defaultWidth;
67
+ this.height = ((_b = data.properties) === null || _b === void 0 ? void 0 : _b.height) || constant_1.poolConfig.defaultHeight;
68
+ }
69
+ // 动态分组配置
70
+ this.autoResize = false;
71
+ this.isRestrict = true;
72
+ this.transformWithContainer = true;
73
+ this.resizable = false;
74
+ this.rotatable = false;
75
+ this.autoToFront = false;
76
+ // 允许文本编辑
77
+ this.text.editable = true;
78
+ // 初始化文本位置
79
+ this.updateTextPosition();
80
+ this.addEventListeners();
81
+ this.resizePool();
82
+ };
83
+ // 增加监听事件
84
+ PoolModel.prototype.addEventListeners = function () {
85
+ var _this = this;
86
+ this.graphModel.eventCenter.on('node:resize', function (_a) {
87
+ var data = _a.data, index = _a.index;
88
+ // 如果resize的是子泳道
89
+ if (_this.children.has(data.id)) {
90
+ // 检查是否为泳道节点的尺寸变化
91
+ var resizedNode = _this.graphModel.getNodeModelById(data.id);
92
+ if (!resizedNode || !resizedNode.type || resizedNode.type !== 'lane') {
93
+ return;
94
+ }
95
+ // 获取所有子泳道
96
+ var lanes = _this.getLanes();
97
+ // 更新泳池宽高
98
+ var newWidth = void 0;
99
+ var newHeight = void 0;
100
+ var deltaX = 0;
101
+ var deltaY = 0;
102
+ if (_this.isHorizontal) {
103
+ // 横向布局:
104
+ // 泳池宽度 = 最大泳道宽度 + 标题区域
105
+ var totalLaneHeight = lanes.reduce(function (sum, lane) { return sum + lane.height; }, 0);
106
+ newWidth = resizedNode.width + constant_1.poolConfig.titleSize;
107
+ // 泳池高度 = 所有泳道高度之和
108
+ newHeight = totalLaneHeight;
109
+ }
110
+ else {
111
+ // 竖向布局:
112
+ // 泳池高度 = 最大泳道高度 + 标题区域
113
+ var totalLaneWidth = lanes.reduce(function (sum, lane) { return sum + lane.width; }, 0);
114
+ newHeight = resizedNode.height + constant_1.poolConfig.titleSize;
115
+ // 泳池宽度 = 所有泳道宽度之和
116
+ newWidth = totalLaneWidth;
117
+ }
118
+ // 根据拖拽控制点方向计算位移方向
119
+ // ResizeControlIndex: 0-左上, 1-右上, 2-右下, 3-左下
120
+ var resizeIndex = typeof index === 'number' ? index : 2;
121
+ var isLeft = resizeIndex === 0 || resizeIndex === 3;
122
+ var isTop = resizeIndex === 0 || resizeIndex === 1;
123
+ var signX = isLeft ? -1 : 1;
124
+ var signY = isTop ? -1 : 1;
125
+ deltaX = signX * (newWidth - _this.width);
126
+ deltaY = signY * (newHeight - _this.height);
127
+ _this.width = newWidth;
128
+ _this.height = newHeight;
129
+ _this.move(deltaX / 2, deltaY / 2);
130
+ }
131
+ // 重新布局泳道以适应新的泳池尺寸
132
+ _this.resizeChildren();
133
+ // 更新泳池文本位置
134
+ _this.updateTextPosition();
135
+ });
136
+ };
137
+ /**
138
+ * 获取需要移动的节点
139
+ * @param groupModel
140
+ */
141
+ PoolModel.prototype.getNodesInGroup = function (groupModel) {
142
+ var _this = this;
143
+ var nodeIds = [];
144
+ if (groupModel.isGroup) {
145
+ (0, lodash_es_1.forEach)(Array.from(groupModel.children), function (nodeId) {
146
+ var nodeModel = _this.graphModel.getNodeModelById(nodeId);
147
+ // 拖拽泳道时会触发泳池的getNodesInGroup,这时泳池再触发移动的子泳道里就需要剔除当前正在拖拽的泳道
148
+ if (nodeModel && !nodeModel.isDragging) {
149
+ nodeIds.push(nodeId);
150
+ }
151
+ });
152
+ }
153
+ return nodeIds;
154
+ };
155
+ /**
156
+ * 初始化文本位置 - 根据布局方向设置文本位置
157
+ */
158
+ PoolModel.prototype.updateTextPosition = function () {
159
+ if (this.isHorizontal) {
160
+ // 横向泳池:文本显示在左侧标题区域
161
+ this.text.x = this.x - this.width / 2 + constant_1.poolConfig.titleSize / 2;
162
+ this.text.y = this.y;
163
+ }
164
+ else {
165
+ // 纵向泳池:文本显示在顶部标题区域
166
+ this.text.x = this.x;
167
+ this.text.y = this.y - this.height / 2 + constant_1.poolConfig.titleSize / 2;
168
+ }
169
+ };
170
+ /**
171
+ * 根据子泳道自动调整泳池尺寸
172
+ */
173
+ PoolModel.prototype.resizePool = function () {
174
+ var lanes = this.getLanes();
175
+ if (lanes.length === 0)
176
+ return;
177
+ var contentWidth = 0;
178
+ var contentHeight = 0;
179
+ if (this.isHorizontal) {
180
+ // 横向布局:计算所有泳道的边界
181
+ (0, lodash_es_1.forEach)(lanes, function (lane) {
182
+ var laneWidth = lane.width;
183
+ var laneHeight = lane.height;
184
+ contentWidth = Math.max(contentWidth, laneWidth);
185
+ contentHeight += laneHeight;
186
+ });
187
+ // 计算新尺寸(横向布局:宽度包含标题区域)
188
+ this.width = contentWidth + constant_1.poolConfig.titleSize;
189
+ this.height = contentHeight;
190
+ }
191
+ else {
192
+ // 竖向布局:计算所有泳道的边界
193
+ (0, lodash_es_1.forEach)(lanes, function (lane) {
194
+ var laneWidth = lane.width;
195
+ var laneHeight = lane.height;
196
+ contentWidth += laneWidth;
197
+ contentHeight = Math.max(contentHeight, laneHeight);
198
+ });
199
+ // 计算新尺寸(竖向布局:高度包含标题区域)
200
+ this.width = contentWidth;
201
+ this.height = contentHeight + constant_1.poolConfig.titleSize;
202
+ }
203
+ // 更新文本位置
204
+ this.updateTextPosition();
205
+ };
206
+ /**
207
+ * 重新调整所有泳道布局
208
+ * @param newLanePosition 添加位置(可选):'above'|'below'|'left'|'right'
209
+ * @param newLaneId 新添加的泳道ID(可选)
210
+ */
211
+ PoolModel.prototype.resizeChildrenWithNewLane = function (newLanePosition, newLaneId) {
212
+ var _this = this;
213
+ var _a;
214
+ var lanes = this.getLanes();
215
+ var isAddingNewLane = newLanePosition && newLaneId;
216
+ if (!isAddingNewLane || (0, lodash_es_1.isEmpty)(lanes))
217
+ return;
218
+ var orderedLanes = [];
219
+ // 找到新创建的泳道
220
+ var newLane = lanes.find(function (lane) { return lane.id === newLaneId; });
221
+ // 先找到触发新增泳道的泳道的index
222
+ orderedLanes = lanes
223
+ .filter(function (lane) { return lane.id !== newLaneId; })
224
+ .slice()
225
+ .sort(function (a, b) { return (_this.isHorizontal ? a.y - b.y : a.x - b.x); });
226
+ if (newLane) {
227
+ var refId_1 = (_a = newLane.properties) === null || _a === void 0 ? void 0 : _a.referenceLaneId;
228
+ var refIndex = refId_1
229
+ ? orderedLanes.findIndex(function (l) { return l.id === refId_1; })
230
+ : 0;
231
+ var insertIndex = ['above', 'left'].includes(newLanePosition)
232
+ ? Math.max(refIndex, 0)
233
+ : Math.min(refIndex + 1, orderedLanes.length);
234
+ // 按顺序插入新泳道
235
+ orderedLanes.splice(insertIndex, 0, newLane);
236
+ }
237
+ if (this.isHorizontal) {
238
+ // 统一泳道宽度
239
+ var laneWidth_1 = this.width - constant_1.poolConfig.titleSize;
240
+ // 计算泳道在内容区域内的分布
241
+ var newHeight = orderedLanes.reduce(function (sum, lane) {
242
+ return sum + lane.height;
243
+ }, 0);
244
+ var laneTopDistance_1 = this.y - newHeight / 2;
245
+ orderedLanes.forEach(function (lane, index) {
246
+ var newLaneY = laneTopDistance_1 + lane.height / 2;
247
+ // 统一泳道文本位置
248
+ lane.text = __assign(__assign({}, lane.text), { x: lane.x - laneWidth_1 / 2 + constant_1.laneConfig.titleSize / 2, y: lane.y });
249
+ _this.moveLane(lane, lane.x, newLaneY);
250
+ // 为下一个泳道计算Y坐标
251
+ if (index < orderedLanes.length - 1) {
252
+ laneTopDistance_1 += lane.height;
253
+ }
254
+ });
255
+ this.height = newHeight;
256
+ }
257
+ else {
258
+ // 统一泳道高度
259
+ var laneHeight_1 = this.height - constant_1.poolConfig.titleSize;
260
+ var newWidth = orderedLanes.reduce(function (sum, lane) {
261
+ return sum + lane.width;
262
+ }, 0);
263
+ var laneLeftDistance_1 = this.x - newWidth / 2;
264
+ // 遍历所有泳道,设置它们的位置
265
+ orderedLanes.forEach(function (lane, index) {
266
+ var newLaneX = laneLeftDistance_1 + lane.width / 2;
267
+ // 统一泳道文本位置
268
+ lane.text = __assign(__assign({}, lane.text), { x: lane.x, y: lane.y - laneHeight_1 / 2 + constant_1.laneConfig.titleSize / 2 });
269
+ _this.moveLane(lane, newLaneX, lane.y);
270
+ // 为下一个泳道计算X坐标
271
+ if (index < orderedLanes.length - 1) {
272
+ laneLeftDistance_1 += lane.width;
273
+ }
274
+ });
275
+ this.width = newWidth;
276
+ }
277
+ // 更新文本位置
278
+ this.updateTextPosition();
279
+ };
280
+ PoolModel.prototype.moveLane = function (lane, newX, newY) {
281
+ var _this = this;
282
+ // 更新泳子节点位置
283
+ var childrenRelPos = [];
284
+ if (lane.children && lane.children.size > 0) {
285
+ lane.children.forEach(function (childId) {
286
+ var childNode = _this.graphModel.getNodeModelById(childId);
287
+ // 过滤掉拖拽中的节点和 Lane 类型(避免递归)
288
+ if (childNode &&
289
+ !childNode.isDragging &&
290
+ String(childNode.type) !== 'lane') {
291
+ childrenRelPos.push({
292
+ id: childId,
293
+ dx: childNode.x - lane.x,
294
+ dy: childNode.y - lane.y,
295
+ });
296
+ }
297
+ });
298
+ }
299
+ // 设置泳道位置和尺寸
300
+ lane.moveTo(newX, newY, true);
301
+ childrenRelPos.forEach(function (_a) {
302
+ var id = _a.id, dx = _a.dx, dy = _a.dy;
303
+ var childNode = _this.graphModel.getNodeModelById(id);
304
+ if (childNode) {
305
+ var x_1 = childNode.x, y_1 = childNode.y;
306
+ var newChildX_1 = lane.x + dx;
307
+ var newChildY_1 = lane.y + dy;
308
+ childNode.moveTo(newChildX_1, newChildY_1);
309
+ var incomingEdges = childNode.incoming.edges;
310
+ var outgoingEdges = childNode.outgoing.edges;
311
+ incomingEdges.forEach(function (edge) {
312
+ edge.moveEndPoint(newChildX_1 - x_1, newChildY_1 - y_1);
313
+ });
314
+ outgoingEdges.forEach(function (edge) {
315
+ edge.moveStartPoint(newChildX_1 - x_1, newChildY_1 - y_1);
316
+ });
317
+ }
318
+ });
319
+ };
320
+ /**
321
+ * 重新调整所有泳道布局
322
+ * @param newLanePosition 添加位置(可选):'above'|'below'|'left'|'right'
323
+ * @param newLaneId 新添加的泳道ID(可选)
324
+ */
325
+ PoolModel.prototype.resizeChildren = function () {
326
+ var _this = this;
327
+ // 遍历所有泳道,horizontal泳道按Y轴排序,vertical泳道按X轴排序并调整位置
328
+ var lanes = this.getLanes();
329
+ if (lanes.length === 0)
330
+ return;
331
+ if (this.isHorizontal) {
332
+ this.height = lanes.reduce(function (sum, lane) {
333
+ return sum + lane.height;
334
+ }, 0);
335
+ // 遍历所有泳道,产出它们在y轴从上到下的顺序
336
+ var orderedLanes_1 = lanes.slice().sort(function (a, b) { return a.y - b.y; });
337
+ lanes.forEach(function (lane) {
338
+ lane.width = _this.width - constant_1.poolConfig.titleSize;
339
+ var laneIndex = orderedLanes_1.findIndex(function (orderedLane) { return orderedLane.id === lane.id; });
340
+ // 遍历orderedLanes,计算出lane相比泳池顶部的距离
341
+ var laneTopDistance = orderedLanes_1.reduce(function (sum, orderedLane, index) {
342
+ if (index < laneIndex && orderedLane.id !== lane.id) {
343
+ return sum + orderedLane.height;
344
+ }
345
+ return sum;
346
+ }, _this.y - _this.height / 2);
347
+ lane.moveTo(_this.x - _this.width / 2 + constant_1.poolConfig.titleSize + lane.width / 2, laneTopDistance + lane.height / 2, true);
348
+ });
349
+ }
350
+ else {
351
+ this.width = lanes.reduce(function (sum, lane) {
352
+ return sum + lane.width;
353
+ }, 0);
354
+ // 垂直泳道按X轴排序
355
+ var orderedLanes_2 = (0, lodash_es_1.cloneDeep)(lanes).sort(function (a, b) { return a.x - b.x; });
356
+ lanes.forEach(function (lane) {
357
+ lane.height = _this.height - constant_1.poolConfig.titleSize;
358
+ var laneIndex = orderedLanes_2.findIndex(function (orderedLane) { return orderedLane.id === lane.id; });
359
+ // 遍历orderedLanes,计算出lane相比泳池顶部的距离
360
+ var laneLeftDistance = orderedLanes_2.reduce(function (sum, orderedLane, index) {
361
+ if (index < laneIndex && orderedLane.id !== lane.id) {
362
+ return sum + orderedLane.width;
363
+ }
364
+ return sum;
365
+ }, _this.x - _this.width / 2);
366
+ lane.moveTo(laneLeftDistance + lane.width / 2, _this.y - _this.height / 2 + constant_1.poolConfig.titleSize + lane.height / 2, true);
367
+ });
368
+ }
369
+ };
370
+ /**
371
+ * 获取子泳道
372
+ */
373
+ PoolModel.prototype.getLanes = function () {
374
+ var _this = this;
375
+ var children = [];
376
+ Array.from(this.children).forEach(function (childId) {
377
+ var childModel = _this.graphModel.getNodeModelById(childId);
378
+ if (childModel && String(childModel.type) === 'lane') {
379
+ children.push(childModel);
380
+ }
381
+ });
382
+ return children;
383
+ };
384
+ /**
385
+ * 添加泳道的公共方法
386
+ * @param position 添加位置:'above'|'below'|'left'|'right'
387
+ * @param laneData 泳道数据
388
+ */
389
+ PoolModel.prototype.addLane = function (position, laneData) {
390
+ var _a, _b, _c, _d;
391
+ var lanes = this.getLanes();
392
+ if (lanes.length === 0) {
393
+ return this.createDefaultLane(laneData);
394
+ }
395
+ // 计算初始位置
396
+ var initialX = this.x;
397
+ var initialY = this.y;
398
+ // 参考泳道(用于定位)
399
+ var referenceLane = lanes.find(function (lane) { return lane.id === (laneData === null || laneData === void 0 ? void 0 : laneData.id); });
400
+ // 用于确定新泳道尺寸的参考泳道,优先使用referenceLane,其次使用现有第一个泳道,最后回退到泳池尺寸
401
+ var sizeLane = referenceLane || lanes[0];
402
+ var laneWidth = (_a = sizeLane === null || sizeLane === void 0 ? void 0 : sizeLane.width) !== null && _a !== void 0 ? _a : this.width;
403
+ var laneHeight = (_b = sizeLane === null || sizeLane === void 0 ? void 0 : sizeLane.height) !== null && _b !== void 0 ? _b : this.height;
404
+ if (this.isHorizontal && ['above', 'below'].includes(position)) {
405
+ if (referenceLane) {
406
+ initialY =
407
+ position === 'above'
408
+ ? referenceLane.y - referenceLane.height / 2 - laneHeight / 2
409
+ : referenceLane.y + referenceLane.height / 2 + laneHeight / 2;
410
+ initialX = referenceLane.x;
411
+ }
412
+ }
413
+ if (!this.isHorizontal && ['left', 'right'].includes(position)) {
414
+ if (referenceLane) {
415
+ initialX =
416
+ position === 'left'
417
+ ? referenceLane.x - referenceLane.width / 2 - laneWidth / 2
418
+ : referenceLane.x + referenceLane.width / 2 + laneWidth / 2;
419
+ initialY = referenceLane.y;
420
+ }
421
+ }
422
+ // 确保不将referenceLaneId作为parent或者其他可能引起递归引用的属性传入
423
+ // laneData可能包含一些运行时属性,需要清理
424
+ var cleanLaneData = (0, lodash_es_1.cloneDeep)(laneData);
425
+ if (cleanLaneData) {
426
+ delete cleanLaneData.id;
427
+ delete cleanLaneData.children;
428
+ (_c = cleanLaneData.properties) === null || _c === void 0 ? true : delete _c.parent;
429
+ (_d = cleanLaneData.properties) === null || _d === void 0 ? true : delete _d.children;
430
+ }
431
+ var nodeConfig = (0, lodash_es_1.merge)(cleanLaneData, {
432
+ type: 'lane',
433
+ x: initialX,
434
+ y: initialY,
435
+ width: laneWidth,
436
+ height: laneHeight,
437
+ text: '新泳道',
438
+ properties: {
439
+ parent: this.id, // 确保父节点始终指向泳池
440
+ position: position, // 记录添加位置,供resizeChildren使用
441
+ referenceLaneId: referenceLane === null || referenceLane === void 0 ? void 0 : referenceLane.id, // 记录参考泳道ID
442
+ },
443
+ zIndex: this.zIndex,
444
+ }, this.properties.laneConfig);
445
+ var newLane = this.graphModel.addNode(nodeConfig);
446
+ this.setZIndex(this.zIndex - 1);
447
+ this.addChild(newLane.id);
448
+ // 调用优化后的resizeChildren,它会处理所有位置计算和泳池尺寸调整
449
+ this.resizeChildrenWithNewLane(position, newLane.id);
450
+ return newLane;
451
+ };
452
+ PoolModel.prototype.setZIndex = function (zIndex) {
453
+ // this.zIndex = zIndex
454
+ this.zIndex = Math.min(zIndex, -100);
455
+ };
456
+ /**
457
+ * 在上方添加泳道
458
+ */
459
+ PoolModel.prototype.addChildAbove = function (laneData) {
460
+ return this.addLane('above', laneData);
461
+ };
462
+ /**
463
+ * 在下方添加泳道
464
+ */
465
+ PoolModel.prototype.addChildBelow = function (laneData) {
466
+ return this.addLane('below', laneData);
467
+ };
468
+ /**
469
+ * 在左侧添加泳道
470
+ */
471
+ PoolModel.prototype.addChildLeft = function (laneData) {
472
+ return this.addLane('left', laneData);
473
+ };
474
+ /**
475
+ * 在右侧添加泳道(纵向布局专用)
476
+ */
477
+ PoolModel.prototype.addChildRight = function (laneData) {
478
+ return this.addLane('right', laneData);
479
+ };
480
+ /**
481
+ * 创建默认泳道
482
+ */
483
+ PoolModel.prototype.createDefaultLane = function (laneConfig) {
484
+ var newLane = null;
485
+ // 只在没有子节点时创建默认泳道
486
+ if (this.isHorizontal) {
487
+ // 横向泳池:泳道垂直排列
488
+ var laneWidth = this.width - constant_1.poolConfig.titleSize;
489
+ var laneHeight = this.height;
490
+ newLane = this.graphModel.addNode((0, lodash_es_1.merge)({
491
+ type: 'lane',
492
+ x: this.x - this.width / 2 + constant_1.poolConfig.titleSize + laneWidth / 2,
493
+ y: this.y,
494
+ width: laneWidth,
495
+ height: laneHeight,
496
+ text: {
497
+ x: this.x - this.width / 2 + constant_1.poolConfig.titleSize / 2,
498
+ y: this.y,
499
+ value: '泳道1',
500
+ },
501
+ properties: {
502
+ parent: this.id,
503
+ isHorizontal: this.isHorizontal,
504
+ },
505
+ zIndex: this.zIndex,
506
+ }, laneConfig));
507
+ }
508
+ else {
509
+ // 纵向泳池:泳道水平排列
510
+ // 修复:初始泳道在泳池中心位置,与resizeChildren逻辑保持一致
511
+ var laneWidth = this.width;
512
+ var laneHeight = this.height - constant_1.poolConfig.titleSize;
513
+ newLane = this.graphModel.addNode((0, lodash_es_1.merge)({
514
+ type: 'lane',
515
+ x: this.x,
516
+ y: this.y -
517
+ this.height / 2 +
518
+ constant_1.poolConfig.titleSize +
519
+ (this.height - constant_1.poolConfig.titleSize) / 2,
520
+ width: laneWidth,
521
+ height: laneHeight,
522
+ text: {
523
+ x: this.x,
524
+ y: this.y - this.height / 2 + constant_1.poolConfig.titleSize / 2,
525
+ value: '泳道1',
526
+ },
527
+ properties: {
528
+ parent: this.id,
529
+ },
530
+ zIndex: this.zIndex,
531
+ }, laneConfig));
532
+ }
533
+ this.setZIndex(this.zIndex - 1);
534
+ this.addChild(newLane.id);
535
+ this.resizeChildren();
536
+ this.updateTextPosition();
537
+ return newLane;
538
+ };
539
+ /**
540
+ * 删除泳道
541
+ */
542
+ PoolModel.prototype.deleteChild = function (childId) {
543
+ var lanes = this.getLanes();
544
+ if (lanes.length <= 1)
545
+ return;
546
+ var laneToDelete = lanes.find(function (lane) { return lane.id === childId; });
547
+ if (!laneToDelete)
548
+ return;
549
+ // 移除子节点
550
+ this.removeChild(childId);
551
+ this.graphModel.deleteNode(childId);
552
+ // 重新调整泳池
553
+ this.resizePool();
554
+ this.resizeChildren();
555
+ };
556
+ PoolModel.prototype.getNodeStyle = function () {
557
+ var style = _super.prototype.getNodeStyle.call(this);
558
+ style.strokeWidth = 2;
559
+ return style;
560
+ };
561
+ /**
562
+ * 获取文本样式
563
+ */
564
+ PoolModel.prototype.getTextStyle = function () {
565
+ var style = _super.prototype.getTextStyle.call(this);
566
+ style.overflowMode = 'ellipsis';
567
+ style.strokeWidth = 2;
568
+ style.textWidth = this.isHorizontal ? this.height : this.width;
569
+ style.textHeight = this.isHorizontal ? this.width : this.height;
570
+ if (this.isHorizontal) {
571
+ style.transform = 'rotate(-90deg)';
572
+ style.textAlign = 'center';
573
+ }
574
+ return style;
575
+ };
576
+ PoolModel.prototype.getData = function () {
577
+ var data = _super.prototype.getData.call(this);
578
+ // const poolModel = this.getPoolModel()
579
+ return __assign(__assign({}, data), { properties: __assign(__assign({}, data.properties), { width: this.width, height: this.height }) });
580
+ };
581
+ __decorate([
582
+ mobx_1.computed
583
+ ], PoolModel.prototype, "isHorizontal", null);
584
+ return PoolModel;
585
+ }(model_1.DynamicGroupNodeModel));
586
+ exports.PoolModel = PoolModel;
587
+ exports.default = {
588
+ PoolModel: PoolModel,
589
+ };
@@ -0,0 +1,17 @@
1
+ import { h } from '@logicflow/core';
2
+ import { DynamicGroupNode } from '../dynamic-group/node';
3
+ export declare class PoolView extends DynamicGroupNode {
4
+ componentDidMount(): void;
5
+ /**
6
+ * 渲染泳池形状 - 根据布局方向分为标题区域和内容区域
7
+ */
8
+ getShape(): import("preact").VNode<import("preact").ClassAttributes<HTMLElement>>;
9
+ /**
10
+ * 获取调整控制点 - 只在展开状态下显示
11
+ */
12
+ getResizeControl(): h.JSX.Element | null;
13
+ }
14
+ declare const _default: {
15
+ PoolView: typeof PoolView;
16
+ };
17
+ export default _default;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.PoolView = void 0;
30
+ var core_1 = require("@logicflow/core");
31
+ var node_1 = require("../dynamic-group/node");
32
+ var constant_1 = require("./constant");
33
+ var PoolView = /** @class */ (function (_super) {
34
+ __extends(PoolView, _super);
35
+ function PoolView() {
36
+ return _super !== null && _super.apply(this, arguments) || this;
37
+ }
38
+ PoolView.prototype.componentDidMount = function () {
39
+ var _a, _b, _c;
40
+ var _d = this.props, graphModel = _d.graphModel, model = _d.model;
41
+ var index = graphModel.nodes.findIndex(function (node) { return node.id === model.id; });
42
+ var poolCount = graphModel.nodes.filter(function (node) { return String(node.type) === 'pool'; }).length;
43
+ // 设置一个足够低的z-index,确保泳池在所有节点的最底层
44
+ model.setZIndex(-((poolCount - index) * 100));
45
+ if (!((_b = (_a = model.properties) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.length) &&
46
+ !model._defaultLaneCreated &&
47
+ !model.virtual) {
48
+ model.createDefaultLane((_c = model.properties) === null || _c === void 0 ? void 0 : _c.laneConfig);
49
+ model._defaultLaneCreated = true;
50
+ }
51
+ };
52
+ /**
53
+ * 渲染泳池形状 - 根据布局方向分为标题区域和内容区域
54
+ */
55
+ PoolView.prototype.getShape = function () {
56
+ var model = this.props.model;
57
+ var x = model.x, y = model.y, width = model.width, height = model.height, _a = model.properties, _b = _a.textStyle, customTextStyle = _b === void 0 ? {} : _b, _c = _a.style, customStyle = _c === void 0 ? {} : _c, isHorizontal = model.isHorizontal;
58
+ var style = model.getNodeStyle();
59
+ var base = { fill: '#ffffff', stroke: '#000000', strokeWidth: 1 };
60
+ var left = x - width / 2;
61
+ var top = y - height / 2;
62
+ var titleRect = __assign(__assign(__assign(__assign({}, base), style), { x: left, y: top, width: isHorizontal ? constant_1.poolConfig.titleSize : width, height: isHorizontal ? height : constant_1.poolConfig.titleSize }), (isHorizontal && customTextStyle));
63
+ var contentRect = __assign(__assign(__assign(__assign({}, base), style), { x: isHorizontal ? left + constant_1.poolConfig.titleSize : left, y: isHorizontal ? top : top + constant_1.poolConfig.titleSize, width: isHorizontal ? width - constant_1.poolConfig.titleSize : width, height: isHorizontal ? height : height - constant_1.poolConfig.titleSize }), (isHorizontal && customStyle));
64
+ return (0, core_1.h)('g', {}, [(0, core_1.h)('rect', titleRect), (0, core_1.h)('rect', contentRect)]);
65
+ };
66
+ /**
67
+ * 获取调整控制点 - 只在展开状态下显示
68
+ */
69
+ PoolView.prototype.getResizeControl = function () {
70
+ var _a = this.props.model, resizable = _a.resizable, isCollapsed = _a.isCollapsed;
71
+ var showResizeControl = resizable && !isCollapsed;
72
+ return showResizeControl ? _super.prototype.getResizeControl.call(this) : null;
73
+ };
74
+ return PoolView;
75
+ }(node_1.DynamicGroupNode));
76
+ exports.PoolView = PoolView;
77
+ exports.default = {
78
+ PoolView: PoolView,
79
+ };