@logicflow/extension 2.3.0-alpha.1 → 2.3.1-alpha.0

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.
@@ -44,6 +44,13 @@ var __read = (this && this.__read) || function (o, n) {
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.getCurvedEdgePath = exports.CurvedEdgeModel = exports.CurvedEdge = void 0;
46
46
  var core_1 = require("@logicflow/core");
47
+ // SVG 路径点只能是严格的 [x, y];多余坐标也视为格式错误,不能静默忽略。
48
+ var isFinitePointTuple = function (point) {
49
+ return Array.isArray(point) &&
50
+ point.length === 2 &&
51
+ Number.isFinite(point[0]) &&
52
+ Number.isFinite(point[1]);
53
+ };
47
54
  // 方向组合到圆弧象限的映射。
48
55
  // key 由进入方向(dir1)和离开方向(dir2)拼接,例如 'tr' 表示从上(t)到右(r)的拐角。
49
56
  // 通过该映射确定在拐点处应该绘制的圆弧象限,用于计算中间控制点。
@@ -183,13 +190,21 @@ function getPartialPath(prevPoint, cornerPoint, nextPoint, cornerRadius) {
183
190
  return path;
184
191
  }
185
192
  function getCurvedEdgePath(points, radius) {
193
+ // 这是可独立调用的导出函数,不能依赖 View 一定提前完成校验。
194
+ if (points.length === 0 || !points.every(isFinitePointTuple)) {
195
+ return '';
196
+ }
197
+ // i 始终指向下一个尚未写入路径的点:首点只生成 M,单点路径到此结束;
198
+ // 两点生成直线,三个及以上的点才为中间拐点计算圆角。
186
199
  var i = 0;
187
- var d = '';
200
+ var d = "M".concat(points[i][0], " ").concat(points[i++][1]);
201
+ if (points.length === 1) {
202
+ return d;
203
+ }
188
204
  if (points.length === 2) {
189
- d += "M".concat(points[i][0], " ").concat(points[i++][1], " L ").concat(points[i][0], " ").concat(points[i][1]);
205
+ d += " L ".concat(points[i][0], " ").concat(points[i][1]);
190
206
  }
191
207
  else {
192
- d += "M".concat(points[i][0], " ").concat(points[i++][1]);
193
208
  for (; i + 1 < points.length;) {
194
209
  var prev = points[i - 1];
195
210
  var cur = points[i];
@@ -25,7 +25,7 @@ export declare const LaneNode: {
25
25
  export declare class PoolElements {
26
26
  static pluginName: string;
27
27
  private lf;
28
- activeGroup?: LaneModel;
28
+ private activeGroups;
29
29
  nodeLaneMap: Map<string, string>;
30
30
  constructor({ lf, options }: LogicFlow.IExtensionProps);
31
31
  /**
@@ -51,7 +51,11 @@ export declare class PoolElements {
51
51
  removeNodeFromGroup: ({ data: node, model, }: CallbackArgs<'node:delete'>) => void;
52
52
  onSelectionDrag: () => void;
53
53
  onNodeDrag: ({ data: node }: CallbackArgs<'node:drag'>) => void;
54
+ private getTargetLaneForNode;
54
55
  setActiveGroup: (node: LogicFlow.NodeData) => void;
56
+ clearDragTargetHighlight(): void;
57
+ onNodeDrop: () => void;
58
+ onNodeMouseUp: () => void;
55
59
  /**
56
60
  * @param node
57
61
  * @param isMultiple
package/lib/pool/index.js CHANGED
@@ -60,6 +60,8 @@ var PoolElements = /** @class */ (function () {
60
60
  function PoolElements(_a) {
61
61
  var lf = _a.lf, options = _a.options;
62
62
  var _this = this;
63
+ // 激活态的泳道节点(支持多泳道同时高亮)
64
+ this.activeGroups = new Set();
63
65
  // 存储节点与 group 的映射关系
64
66
  this.nodeLaneMap = new Map();
65
67
  /**
@@ -150,32 +152,46 @@ var PoolElements = /** @class */ (function () {
150
152
  };
151
153
  this.onSelectionDrag = function () {
152
154
  var selectedNodes = _this.lf.graphModel.getSelectElements().nodes;
155
+ var next = new Set();
153
156
  selectedNodes.forEach(function (node) {
154
- _this.setActiveGroup(node);
157
+ var targetLane = _this.getTargetLaneForNode(node);
158
+ if (targetLane)
159
+ next.add(targetLane);
155
160
  });
161
+ _this.activeGroups.forEach(function (lane) {
162
+ if (!next.has(lane))
163
+ lane.setAllowAppendChild(false);
164
+ });
165
+ next.forEach(function (lane) {
166
+ if (!_this.activeGroups.has(lane))
167
+ lane.setAllowAppendChild(true);
168
+ });
169
+ _this.activeGroups = next;
156
170
  };
157
171
  this.onNodeDrag = function (_a) {
158
172
  var node = _a.data;
159
173
  _this.setActiveGroup(node);
160
174
  };
161
175
  this.setActiveGroup = function (node) {
162
- var _a;
163
- var nodeModel = _this.lf.getNodeModelById(node.id);
164
- var bounds = nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.getBounds();
165
- if (nodeModel && bounds) {
166
- var targetGroup = _this.getLaneByBounds(bounds, node);
167
- if (_this.activeGroup) {
168
- _this.activeGroup.setAllowAppendChild(false);
169
- }
170
- if (!targetGroup || (nodeModel.isGroup && targetGroup.id === node.id)) {
171
- return;
172
- }
173
- var isAllowAppendIn = targetGroup.isAllowAppendIn(node);
174
- if (!isAllowAppendIn)
175
- return;
176
- _this.activeGroup = targetGroup;
177
- (_a = _this.activeGroup) === null || _a === void 0 ? void 0 : _a.setAllowAppendChild(true);
178
- }
176
+ var targetLane = _this.getTargetLaneForNode(node);
177
+ var next = new Set();
178
+ if (targetLane)
179
+ next.add(targetLane);
180
+ _this.activeGroups.forEach(function (lane) {
181
+ if (!next.has(lane))
182
+ lane.setAllowAppendChild(false);
183
+ });
184
+ next.forEach(function (lane) {
185
+ if (!_this.activeGroups.has(lane))
186
+ lane.setAllowAppendChild(true);
187
+ });
188
+ _this.activeGroups = next;
189
+ };
190
+ this.onNodeDrop = function () {
191
+ _this.clearDragTargetHighlight();
192
+ };
193
+ this.onNodeMouseUp = function () {
194
+ _this.clearDragTargetHighlight();
179
195
  };
180
196
  /**
181
197
  * @param node
@@ -256,6 +272,7 @@ var PoolElements = /** @class */ (function () {
256
272
  groupModel.width = newGroupWidth;
257
273
  groupModel.height = newGroupHeight;
258
274
  groupModel.updateExpandedSize(newGroupWidth, newGroupHeight);
275
+ groupModel.setTextPosition();
259
276
  };
260
277
  this.onGraphRendered = function (_a) {
261
278
  var data = _a.data;
@@ -311,6 +328,26 @@ var PoolElements = /** @class */ (function () {
311
328
  return topZIndexLane;
312
329
  }
313
330
  };
331
+ PoolElements.prototype.getTargetLaneForNode = function (node) {
332
+ var nodeModel = this.lf.getNodeModelById(node.id);
333
+ var bounds = nodeModel === null || nodeModel === void 0 ? void 0 : nodeModel.getBounds();
334
+ if (!nodeModel || !bounds)
335
+ return undefined;
336
+ var targetLane = this.getLaneByBounds(bounds, node);
337
+ if (!targetLane)
338
+ return undefined;
339
+ if (nodeModel.isGroup && targetLane.id === node.id)
340
+ return undefined;
341
+ if (!targetLane.isAllowAppendIn(node))
342
+ return undefined;
343
+ return targetLane;
344
+ };
345
+ PoolElements.prototype.clearDragTargetHighlight = function () {
346
+ this.activeGroups.forEach(function (lane) {
347
+ lane.setAllowAppendChild(false);
348
+ });
349
+ this.activeGroups.clear();
350
+ };
314
351
  PoolElements.prototype.removeChildrenInGroupNodeData = function (nodeData) {
315
352
  var _a;
316
353
  var newNodeData = (0, lodash_es_1.cloneDeep)(nodeData);
@@ -450,6 +487,8 @@ var PoolElements = /** @class */ (function () {
450
487
  lf.on(core_1.EventType.NODE_DELETE, this.removeNodeFromGroup);
451
488
  lf.on(events_1.NODE_DRAG_EVENTS, this.onNodeDrag);
452
489
  lf.on(core_1.EventType.SELECTION_DRAG, this.onSelectionDrag);
490
+ lf.on(core_1.EventType.NODE_DROP, this.onNodeDrop);
491
+ lf.on(core_1.EventType.NODE_MOUSEUP, this.onNodeMouseUp);
453
492
  lf.on(core_1.EventType.NODE_CLICK, this.onNodeSelect);
454
493
  lf.on(core_1.EventType.NODE_MOUSEMOVE, this.onNodeMove);
455
494
  lf.on(core_1.EventType.GRAPH_RENDERED, this.onGraphRendered);
@@ -499,6 +538,8 @@ var PoolElements = /** @class */ (function () {
499
538
  this.lf.off(core_1.EventType.NODE_DELETE, this.removeNodeFromGroup);
500
539
  this.lf.off(events_1.NODE_DRAG_EVENTS, this.onNodeDrag);
501
540
  this.lf.off(core_1.EventType.SELECTION_DRAG, this.onSelectionDrag);
541
+ this.lf.off(core_1.EventType.NODE_DROP, this.onNodeDrop);
542
+ this.lf.off(core_1.EventType.NODE_MOUSEUP, this.onNodeMouseUp);
502
543
  this.lf.off(core_1.EventType.NODE_CLICK, this.onNodeSelect);
503
544
  this.lf.off(core_1.EventType.NODE_MOUSEMOVE, this.onNodeMove);
504
545
  this.lf.off(core_1.EventType.GRAPH_RENDERED, this.onGraphRendered);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/extension",
3
- "version": "2.3.0-alpha.1",
3
+ "version": "2.3.1-alpha.0",
4
4
  "description": "LogicFlow Extensions",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -20,7 +20,7 @@
20
20
  "author": "Logicflow-Team",
21
21
  "license": "Apache-2.0",
22
22
  "peerDependencies": {
23
- "@logicflow/core": "2.2.3-alpha.0"
23
+ "@logicflow/core": "^2.2.5-alpha.0"
24
24
  },
25
25
  "dependencies": {
26
26
  "@antv/hierarchy": "^0.6.11",
@@ -37,7 +37,7 @@
37
37
  "postcss-url": "^10.1.3",
38
38
  "postcss-import": "^16.1.0",
39
39
  "rollup-plugin-postcss": "^4.0.2",
40
- "@logicflow/core": "2.2.3-alpha.0"
40
+ "@logicflow/core": "2.2.5-alpha.0"
41
41
  },
42
42
  "files": [
43
43
  "dist",