@logicflow/core 2.0.9 → 2.0.11

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 (85) hide show
  1. package/.turbo/turbo-build$colon$dev.log +2 -2
  2. package/.turbo/turbo-build.log +7 -7
  3. package/CHANGELOG.md +26 -0
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/es/LogicFlow.js +21 -1
  7. package/es/event/eventEmitter.d.ts +1 -0
  8. package/es/event/eventEmitter.js +3 -0
  9. package/es/history/index.d.ts +1 -0
  10. package/es/history/index.js +6 -0
  11. package/es/keyboard/index.d.ts +1 -0
  12. package/es/keyboard/index.js +3 -0
  13. package/es/model/EditConfigModel.d.ts +3 -1
  14. package/es/model/EditConfigModel.js +5 -0
  15. package/es/model/GraphModel.d.ts +13 -1
  16. package/es/model/GraphModel.js +41 -41
  17. package/es/model/edge/BaseEdgeModel.js +6 -3
  18. package/es/model/edge/BezierEdgeModel.js +2 -2
  19. package/es/model/edge/PolylineEdgeModel.d.ts +1 -0
  20. package/es/model/edge/PolylineEdgeModel.js +9 -2
  21. package/es/model/node/BaseNodeModel.js +7 -2
  22. package/es/tool/index.d.ts +1 -0
  23. package/es/tool/index.js +6 -2
  24. package/es/util/geometry.d.ts +1 -1
  25. package/es/util/geometry.js +4 -1
  26. package/es/util/node.d.ts +1 -1
  27. package/es/util/node.js +32 -16
  28. package/es/view/Graph.js +19 -2
  29. package/es/view/behavior/dnd.js +3 -2
  30. package/es/view/edge/BaseEdge.js +9 -2
  31. package/es/view/node/BaseNode.js +20 -11
  32. package/es/view/node/HtmlNode.js +1 -0
  33. package/es/view/overlay/CanvasOverlay.js +6 -4
  34. package/es/view/text/BaseText.js +1 -0
  35. package/lib/LogicFlow.js +20 -0
  36. package/lib/event/eventEmitter.d.ts +1 -0
  37. package/lib/event/eventEmitter.js +3 -0
  38. package/lib/history/index.d.ts +1 -0
  39. package/lib/history/index.js +6 -0
  40. package/lib/keyboard/index.d.ts +1 -0
  41. package/lib/keyboard/index.js +3 -0
  42. package/lib/model/EditConfigModel.d.ts +3 -1
  43. package/lib/model/EditConfigModel.js +5 -0
  44. package/lib/model/GraphModel.d.ts +13 -1
  45. package/lib/model/GraphModel.js +40 -40
  46. package/lib/model/edge/BaseEdgeModel.js +6 -3
  47. package/lib/model/edge/BezierEdgeModel.js +1 -1
  48. package/lib/model/edge/PolylineEdgeModel.d.ts +1 -0
  49. package/lib/model/edge/PolylineEdgeModel.js +8 -1
  50. package/lib/model/node/BaseNodeModel.js +7 -2
  51. package/lib/tool/index.d.ts +1 -0
  52. package/lib/tool/index.js +6 -2
  53. package/lib/util/geometry.d.ts +1 -1
  54. package/lib/util/geometry.js +4 -1
  55. package/lib/util/node.d.ts +1 -1
  56. package/lib/util/node.js +32 -16
  57. package/lib/view/Graph.js +19 -2
  58. package/lib/view/behavior/dnd.js +3 -2
  59. package/lib/view/edge/BaseEdge.js +9 -2
  60. package/lib/view/node/BaseNode.js +19 -10
  61. package/lib/view/node/HtmlNode.js +1 -0
  62. package/lib/view/overlay/CanvasOverlay.js +6 -4
  63. package/lib/view/text/BaseText.js +1 -0
  64. package/package.json +1 -1
  65. package/src/LogicFlow.tsx +25 -1
  66. package/src/event/eventEmitter.ts +4 -0
  67. package/src/history/index.ts +7 -0
  68. package/src/keyboard/index.ts +4 -0
  69. package/src/model/EditConfigModel.ts +4 -0
  70. package/src/model/GraphModel.ts +62 -70
  71. package/src/model/edge/BaseEdgeModel.ts +7 -2
  72. package/src/model/edge/BezierEdgeModel.ts +2 -2
  73. package/src/model/edge/PolylineEdgeModel.ts +10 -2
  74. package/src/model/node/BaseNodeModel.ts +9 -2
  75. package/src/tool/index.ts +7 -2
  76. package/src/util/geometry.ts +3 -1
  77. package/src/util/node.ts +19 -18
  78. package/src/view/Graph.tsx +19 -2
  79. package/src/view/behavior/dnd.ts +5 -2
  80. package/src/view/edge/BaseEdge.tsx +9 -2
  81. package/src/view/node/BaseNode.tsx +20 -12
  82. package/src/view/node/HtmlNode.tsx +1 -0
  83. package/src/view/overlay/CanvasOverlay.tsx +6 -5
  84. package/src/view/text/BaseText.tsx +1 -0
  85. package/stats.html +1 -1
@@ -226,13 +226,14 @@ var BaseNodeModel = /** @class */ (function () {
226
226
  */
227
227
  BaseNodeModel.prototype.formatText = function (data) {
228
228
  var _a, _b, _c;
229
+ var _d = this.graphModel.editConfigModel, nodeTextDraggable = _d.nodeTextDraggable, nodeTextEdit = _d.nodeTextEdit;
229
230
  var x = data.x, y = data.y, text = data.text;
230
231
  var textConfig = {
231
232
  value: '',
232
233
  x: x,
233
234
  y: y,
234
- draggable: false,
235
- editable: true,
235
+ draggable: nodeTextDraggable,
236
+ editable: nodeTextEdit,
236
237
  };
237
238
  if (text) {
238
239
  if (typeof text === 'string') {
@@ -647,6 +648,10 @@ var BaseNodeModel = /** @class */ (function () {
647
648
  this.text && this.moveText(0, deltaY);
648
649
  moveY = deltaY;
649
650
  }
651
+ this.transform = new util_1.TranslateMatrix(-this.x, -this.y)
652
+ .rotate(this.rotate)
653
+ .translate(this.x, this.y)
654
+ .toString();
650
655
  return [moveX, moveY];
651
656
  };
652
657
  BaseNodeModel.prototype.moveTo = function (x, y, isIgnoreRule) {
@@ -20,5 +20,6 @@ export declare class Tool {
20
20
  enableTool(name: string): boolean | Error;
21
21
  getTools(): ToolConstructor[];
22
22
  getInstance(): LogicFlow;
23
+ destroy(): void;
23
24
  }
24
25
  export default Tool;
package/lib/tool/index.js CHANGED
@@ -56,7 +56,7 @@ var Tool = /** @class */ (function () {
56
56
  this.toolMap.delete(name);
57
57
  return true;
58
58
  }
59
- throw new Error('禁用失败,不存在名为 ${tool} 的工具');
59
+ throw new Error("\u7981\u7528\u5931\u8D25\uFF0C\u4E0D\u5B58\u5728\u540D\u4E3A ".concat(tool, " \u7684\u5DE5\u5177"));
60
60
  };
61
61
  Tool.prototype.enableTool = function (name) {
62
62
  var tool = this.disabledToolMap.get(name);
@@ -65,7 +65,7 @@ var Tool = /** @class */ (function () {
65
65
  this.disabledToolMap.delete(name);
66
66
  return true;
67
67
  }
68
- throw new Error('不存在名为 ${tool} 的工具');
68
+ throw new Error("\u4E0D\u5B58\u5728\u540D\u4E3A ".concat(tool, " \u7684\u5DE5\u5177"));
69
69
  };
70
70
  Tool.prototype.getTools = function () {
71
71
  return Array.from(this.toolMap.values());
@@ -73,6 +73,10 @@ var Tool = /** @class */ (function () {
73
73
  Tool.prototype.getInstance = function () {
74
74
  return this.instance;
75
75
  };
76
+ Tool.prototype.destroy = function () {
77
+ this.toolMap.clear();
78
+ this.disabledToolMap.clear();
79
+ };
76
80
  __decorate([
77
81
  mobx_1.observable
78
82
  ], Tool.prototype, "toolMap", void 0);
@@ -1,6 +1,6 @@
1
1
  import LogicFlow from '../LogicFlow';
2
2
  import PointTuple = LogicFlow.PointTuple;
3
- export declare function snapToGrid(point: number, gridSize: number): number;
3
+ export declare function snapToGrid(point: number, gridSize: number, snapGrid: boolean): number;
4
4
  export declare function getGridOffset(distance: number, gridSize: number): number;
5
5
  /**
6
6
  * 多边形设置 points 后,坐标平移至原点 并 根据 width、height 缩放
@@ -26,7 +26,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
28
  exports.normalizePolygon = exports.getGridOffset = exports.snapToGrid = void 0;
29
- function snapToGrid(point, gridSize) {
29
+ function snapToGrid(point, gridSize, snapGrid) {
30
+ // 开启节网格对齐时才根据网格尺寸校准坐标
31
+ if (!snapGrid)
32
+ return point;
30
33
  // 保证 x, y 的值为 gridSize 的整数倍
31
34
  return gridSize * Math.round(point / gridSize) || point;
32
35
  }
@@ -15,7 +15,7 @@ export type NodeContaint = {
15
15
  export declare const targetNodeInfo: (position: Point, graphModel: GraphModel) => NodeContaint;
16
16
  export declare const getClosestAnchor: (position: Point, node: BaseNodeModel) => AnchorInfo;
17
17
  export declare const distance: (x1: number, y1: number, x2: number, y2: number) => number;
18
- export declare const isInNode: (position: Point, node: BaseNodeModel) => boolean;
18
+ export declare const isInNode: (position: Point, node: BaseNodeModel, offset?: number) => boolean;
19
19
  export declare const isInNodeBbox: (position: Point, node: BaseNodeModel) => boolean;
20
20
  export type NodeBBox = {
21
21
  x: number;
package/lib/util/node.js CHANGED
@@ -10,12 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
13
29
  Object.defineProperty(exports, "__esModule", { value: true });
14
30
  exports.formatAnchorConnectValidateData = exports.getSvgTextWidthHeight = exports.getHtmlTextHeight = exports.getNodeAnchorPosition = exports.pickNodeConfig = exports.getCrossPointWithPolygon = exports.getCrossPointWithEllipse = exports.inStraightLineOfRect = exports.pointEdgeDirection = exports.getCrossPointWithCircle = exports.getClosestRadiusCenter = exports.getRectRadiusCircle = exports.getNodeBBox = exports.isInNodeBbox = exports.isInNode = exports.distance = exports.getClosestAnchor = exports.targetNodeInfo = exports.getAnchors = void 0;
15
31
  var lodash_es_1 = require("lodash-es");
16
32
  var edge_1 = require("./edge");
17
33
  var constant_1 = require("../constant");
18
34
  var edge_2 = require("../algorithm/edge");
35
+ var matrix_1 = require("./matrix");
19
36
  /* 获取所有锚点 */
20
37
  var getAnchors = function (data) {
21
38
  var anchors = data.anchors;
@@ -79,30 +96,29 @@ exports.getClosestAnchor = getClosestAnchor;
79
96
  var distance = function (x1, y1, x2, y2) { return Math.hypot(x1 - x2, y1 - y2); };
80
97
  exports.distance = distance;
81
98
  /* 是否在某个节点内,手否进行连接,有offset控制粒度,与outline有关,可以优化 */
82
- var isInNode = function (position, node) {
99
+ var isInNode = function (position, node, offset) {
100
+ if (offset === void 0) { offset = 0; }
83
101
  var inNode = false;
84
- var offset = 0;
85
102
  var bBox = (0, exports.getNodeBBox)(node);
86
- if (position.x >= bBox.minX - offset &&
87
- position.x <= bBox.maxX + offset &&
88
- position.y >= bBox.minY - offset &&
89
- position.y <= bBox.maxY + offset) {
103
+ var _a = __read(new matrix_1.Matrix([position.x, position.y, 1])
104
+ .translate(-node.x, -node.y)
105
+ .rotate(-node.rotate)
106
+ .translate(node.x, node.y)[0], 2), x = _a[0], y = _a[1];
107
+ var reverseRotatedPosition = {
108
+ x: x,
109
+ y: y,
110
+ };
111
+ if (reverseRotatedPosition.x >= bBox.minX - offset &&
112
+ reverseRotatedPosition.x <= bBox.maxX + offset &&
113
+ reverseRotatedPosition.y >= bBox.minY - offset &&
114
+ reverseRotatedPosition.y <= bBox.maxY + offset) {
90
115
  inNode = true;
91
116
  }
92
117
  return inNode;
93
118
  };
94
119
  exports.isInNode = isInNode;
95
120
  var isInNodeBbox = function (position, node) {
96
- var inNode = false;
97
- var offset = 5;
98
- var bBox = (0, exports.getNodeBBox)(node);
99
- if (position.x >= bBox.minX - offset &&
100
- position.x <= bBox.maxX + offset &&
101
- position.y >= bBox.minY - offset &&
102
- position.y <= bBox.maxY + offset) {
103
- inNode = true;
104
- }
105
- return inNode;
121
+ return (0, exports.isInNode)(position, node, 5);
106
122
  };
107
123
  exports.isInNodeBbox = isInNodeBbox;
108
124
  /* 获取节点bbox */
package/lib/view/Graph.js CHANGED
@@ -57,9 +57,26 @@ var Graph = /** @class */ (function (_super) {
57
57
  function Graph() {
58
58
  var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
59
59
  _this.handleResize = function () {
60
- _this.props.graphModel.resize();
60
+ var _a = _this.props, graphModel = _a.graphModel, options = _a.options;
61
+ var width = graphModel.width, height = graphModel.height, isContainerWidth = graphModel.isContainerWidth, isContainerHeight = graphModel.isContainerHeight;
62
+ var resizeWidth = width;
63
+ var resizeHeight = height;
64
+ var needUpdate = false;
65
+ if (isContainerWidth) {
66
+ resizeWidth = undefined;
67
+ needUpdate = true;
68
+ }
69
+ if (isContainerHeight) {
70
+ resizeHeight = undefined;
71
+ needUpdate = true;
72
+ }
73
+ if (needUpdate) {
74
+ graphModel.resize(resizeWidth, resizeHeight);
75
+ }
76
+ options.width = width;
77
+ options.height = height;
61
78
  };
62
- _this.throttleResize = function () { return (0, lodash_es_1.throttle)(_this.handleResize, 200); };
79
+ _this.throttleResize = (0, lodash_es_1.throttle)(_this.handleResize, 200);
63
80
  return _this;
64
81
  }
65
82
  Graph.prototype.componentDidMount = function () {
@@ -84,10 +84,11 @@ var Dnd = /** @class */ (function () {
84
84
  });
85
85
  // 处理缩放和偏移
86
86
  var _b = position.canvasOverlayPosition, x1 = _b.x, y1 = _b.y;
87
+ var snapGrid = this.lf.graphModel.editConfigModel.snapGrid;
87
88
  // x, y 对齐到网格的 size
88
89
  return {
89
- x: (0, util_1.snapToGrid)(x1, gridSize),
90
- y: (0, util_1.snapToGrid)(y1, gridSize),
90
+ x: (0, util_1.snapToGrid)(x1, gridSize, snapGrid),
91
+ y: (0, util_1.snapToGrid)(y1, gridSize, snapGrid),
91
92
  };
92
93
  };
93
94
  Dnd.prototype.startDrag = function (nodeConfig) {
@@ -125,12 +125,16 @@ var BaseEdge = /** @class */ (function (_super) {
125
125
  clearTimeout(_this.clickTimer);
126
126
  }
127
127
  var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
128
+ var editConfigModel = graphModel.editConfigModel;
128
129
  var position = graphModel.getPointByClient({
129
130
  x: ev.clientX,
130
131
  y: ev.clientY,
131
132
  });
132
133
  graphModel.setElementStateById(model.id, constant_1.ElementState.SHOW_MENU, position.domOverlayPosition);
133
- _this.toFront();
134
+ // 静默模式下点击节点不变更节点层级
135
+ if (!editConfigModel.isSilentMode) {
136
+ _this.toFront();
137
+ }
134
138
  if (!model.isSelected) {
135
139
  graphModel.selectEdgeById(model.id);
136
140
  }
@@ -218,7 +222,10 @@ var BaseEdge = /** @class */ (function (_super) {
218
222
  }
219
223
  var editConfigModel = graphModel.editConfigModel;
220
224
  graphModel.selectEdgeById(model.id, (0, util_1.isMultipleSelect)(e, editConfigModel));
221
- _this.toFront();
225
+ // 静默模式下点击节点不变更节点层级
226
+ if (!editConfigModel.isSilentMode) {
227
+ _this.toFront();
228
+ }
222
229
  };
223
230
  _this.handleFocus = function () {
224
231
  var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
@@ -89,7 +89,7 @@ var BaseNode = /** @class */ (function (_super) {
89
89
  var _b, _c, _d, _e;
90
90
  var event = _a.event;
91
91
  var _f = _this.props, model = _f.model, graphModel = _f.graphModel;
92
- var _g = graphModel.editConfigModel, stopMoveGraph = _g.stopMoveGraph, autoExpand = _g.autoExpand, transformModel = graphModel.transformModel, selectNodes = graphModel.selectNodes, width = graphModel.width, height = graphModel.height, gridSize = graphModel.gridSize;
92
+ var _g = graphModel.editConfigModel, stopMoveGraph = _g.stopMoveGraph, autoExpand = _g.autoExpand, snapGrid = _g.snapGrid, transformModel = graphModel.transformModel, selectNodes = graphModel.selectNodes, width = graphModel.width, height = graphModel.height, gridSize = graphModel.gridSize;
93
93
  model.isDragging = true;
94
94
  var _h = event, clientX = _h.clientX, clientY = _h.clientY;
95
95
  var _j = graphModel.getPointByClient({
@@ -101,9 +101,9 @@ var BaseNode = /** @class */ (function (_super) {
101
101
  // 2. 考虑鼠标位置不再节点中心
102
102
  x = x + ((_c = (_b = _this.moveOffset) === null || _b === void 0 ? void 0 : _b.dx) !== null && _c !== void 0 ? _c : 0);
103
103
  y = y + ((_e = (_d = _this.moveOffset) === null || _d === void 0 ? void 0 : _d.dy) !== null && _e !== void 0 ? _e : 0);
104
- // 将x, y移动到grid上
105
- x = (0, util_1.snapToGrid)(x, gridSize);
106
- y = (0, util_1.snapToGrid)(y, gridSize);
104
+ // 校准坐标
105
+ x = (0, util_1.snapToGrid)(x, gridSize, snapGrid);
106
+ y = (0, util_1.snapToGrid)(y, gridSize, snapGrid);
107
107
  if (!width || !height) {
108
108
  graphModel.moveNode2Coordinate(model.id, x, y);
109
109
  return;
@@ -139,10 +139,6 @@ var BaseNode = /** @class */ (function (_super) {
139
139
  if (_this.t) {
140
140
  (0, util_1.cancelRaf)(_this.t);
141
141
  }
142
- model.transform = new util_1.TranslateMatrix(-x, -y)
143
- .rotate(model.rotate)
144
- .translate(x, y)
145
- .toString();
146
142
  var moveNodes = selectNodes.map(function (node) { return node.id; });
147
143
  // 未被选中的节点也可以拖动
148
144
  if (moveNodes.indexOf(model.id) === -1) {
@@ -217,7 +213,10 @@ var BaseNode = /** @class */ (function (_super) {
217
213
  else {
218
214
  graphModel.selectNodeById(model.id, isMultiple);
219
215
  eventOptions.isSelected = true;
220
- _this.toFront();
216
+ // 静默模式下点击节点不变更节点层级
217
+ if (!editConfigModel.isSilentMode) {
218
+ _this.toFront();
219
+ }
221
220
  }
222
221
  // 不是双击的,默认都是单击
223
222
  if (isDoubleClick) {
@@ -237,6 +236,7 @@ var BaseNode = /** @class */ (function (_super) {
237
236
  _this.handleContextMenu = function (ev) {
238
237
  ev.preventDefault();
239
238
  var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
239
+ var editConfigModel = graphModel.editConfigModel;
240
240
  // 节点数据,多为事件对象数据抛出
241
241
  var nodeData = model.getData();
242
242
  var position = graphModel.getPointByClient({
@@ -252,7 +252,10 @@ var BaseNode = /** @class */ (function (_super) {
252
252
  e: ev,
253
253
  position: position,
254
254
  });
255
- _this.toFront();
255
+ // 静默模式下点击节点不变更节点层级
256
+ if (!editConfigModel.isSilentMode) {
257
+ _this.toFront();
258
+ }
256
259
  };
257
260
  _this.handleMouseDown = function (ev) {
258
261
  var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
@@ -326,6 +329,12 @@ var BaseNode = /** @class */ (function (_super) {
326
329
  if (this.modelDisposer) {
327
330
  this.modelDisposer();
328
331
  }
332
+ // 以下是 mobx-preact 中 componentWillUnmount 的回调逻辑,但是不知道出于什么考虑,mobx-preact 没有混入这一段逻辑
333
+ // @ts-ignore
334
+ if (this.render.$mobx) {
335
+ // @ts-ignore
336
+ this.render.$mobx.dispose();
337
+ }
329
338
  };
330
339
  BaseNode.prototype.componentDidMount = function () { };
331
340
  BaseNode.prototype.componentDidUpdate = function () { };
@@ -119,6 +119,7 @@ var HtmlNode = /** @class */ (function (_super) {
119
119
  }
120
120
  };
121
121
  HtmlNode.prototype.componentWillUnmount = function () {
122
+ _super.prototype.componentWillUnmount.call(this);
122
123
  this.rootEl.innerHTML = '';
123
124
  };
124
125
  HtmlNode.prototype.getShape = function () {
@@ -66,8 +66,9 @@ var CanvasOverlay = /** @class */ (function (_super) {
66
66
  _this.zoomHandler = function (ev) {
67
67
  var _a = _this.props, _b = _a.graphModel, editConfigModel = _b.editConfigModel, transformModel = _b.transformModel, gridSize = _b.gridSize, graphModel = _a.graphModel;
68
68
  var eX = ev.deltaX, eY = ev.deltaY;
69
+ var stopScrollGraph = editConfigModel.stopScrollGraph, stopZoomGraph = editConfigModel.stopZoomGraph;
69
70
  // 如果没有禁止滚动移动画布, 并且当前触发的时候ctrl键、cmd键没有按住, 那么移动画布
70
- if (!editConfigModel.stopScrollGraph && !ev.ctrlKey && !ev.metaKey) {
71
+ if (!stopScrollGraph && !ev.ctrlKey && !ev.metaKey) {
71
72
  ev.preventDefault();
72
73
  _this.stepScrollX += eX;
73
74
  _this.stepScrollY += eY;
@@ -86,7 +87,7 @@ var CanvasOverlay = /** @class */ (function (_super) {
86
87
  return;
87
88
  }
88
89
  // 如果没有禁止缩放画布,那么进行缩放. 在禁止缩放画布后,按住 ctrl、cmd 键也不能缩放了。
89
- if (!editConfigModel.stopZoomGraph) {
90
+ if (!stopZoomGraph) {
90
91
  ev.preventDefault();
91
92
  var position = graphModel.getPointByClient({
92
93
  x: ev.clientX,
@@ -127,10 +128,11 @@ var CanvasOverlay = /** @class */ (function (_super) {
127
128
  // 鼠标、触摸板 按下
128
129
  _this.mouseDownHandler = function (ev) {
129
130
  var _a = _this.props.graphModel, eventCenter = _a.eventCenter, editConfigModel = _a.editConfigModel, SCALE_X = _a.transformModel.SCALE_X, gridSize = _a.gridSize;
131
+ var adjustEdge = editConfigModel.adjustEdge, adjustNodePosition = editConfigModel.adjustNodePosition, stopMoveGraph = editConfigModel.stopMoveGraph;
130
132
  var target = ev.target;
131
- var isFrozenElement = !editConfigModel.adjustEdge && !editConfigModel.adjustNodePosition;
133
+ var isFrozenElement = !adjustEdge && !adjustNodePosition;
132
134
  if (target.getAttribute('name') === 'canvas-overlay' || isFrozenElement) {
133
- if (editConfigModel.stopMoveGraph !== true) {
135
+ if (stopMoveGraph !== true) {
134
136
  _this.stepDrag.setStep(gridSize * SCALE_X);
135
137
  _this.stepDrag.handleMouseDown(ev);
136
138
  }
@@ -60,6 +60,7 @@ var BaseText = /** @class */ (function (_super) {
60
60
  var _a = _this.props, draggable = _a.draggable, model = _a.model, graphModel = _a.graphModel;
61
61
  var nodeTextDraggable = graphModel.editConfigModel.nodeTextDraggable;
62
62
  if (draggable !== null && draggable !== void 0 ? draggable : nodeTextDraggable) {
63
+ e.stopPropagation();
63
64
  _this.stepperDrag.model = model;
64
65
  _this.stepperDrag.handleMouseDown(e);
65
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "description": "LogicFlow, help you quickly create flowcharts",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
package/src/LogicFlow.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, createElement as h, render } from 'preact/compat'
2
- import { cloneDeep, forEach, indexOf } from 'lodash-es'
2
+ import { cloneDeep, forEach, indexOf, isNil } from 'lodash-es'
3
3
  import { observer } from '.'
4
4
  import { Options as LFOptions } from './options'
5
5
  import * as _Model from './model'
@@ -885,12 +885,23 @@ export class LogicFlow {
885
885
  */
886
886
  updateEditConfig(config: Partial<IEditConfigType>) {
887
887
  const { editConfigModel, transformModel } = this.graphModel
888
+ const currentSnapGrid = editConfigModel.snapGrid
889
+
888
890
  editConfigModel.updateEditConfig(config)
889
891
  if (config?.stopMoveGraph !== undefined) {
890
892
  transformModel.updateTranslateLimits(config.stopMoveGraph)
891
893
  }
894
+
892
895
  // 静默模式切换时,修改快捷键的启用状态
893
896
  config?.isSilentMode ? this.keyboard.disable() : this.keyboard.enable(true)
897
+
898
+ // 切换网格对齐状态时,修改网格尺寸
899
+ if (!isNil(config?.snapGrid) && config.snapGrid !== currentSnapGrid) {
900
+ const {
901
+ grid: { size = 1 },
902
+ } = this.graphModel
903
+ this.graphModel.updateGridSize(config.snapGrid ? size : 1)
904
+ }
894
905
  }
895
906
 
896
907
  /**
@@ -1044,6 +1055,8 @@ export class LogicFlow {
1044
1055
  */
1045
1056
  clearData() {
1046
1057
  this.graphModel.clearData()
1058
+ // 强制刷新数据, 让 preact 清除对已删除节点的引用
1059
+ this.render({})
1047
1060
  }
1048
1061
 
1049
1062
  /*********************************************************
@@ -1372,7 +1385,18 @@ export class LogicFlow {
1372
1385
 
1373
1386
  /** 销毁当前实例 */
1374
1387
  destroy() {
1388
+ this.clearData()
1389
+ render(null, this.container)
1390
+ this.keyboard.destroy()
1375
1391
  this.graphModel.destroy()
1392
+ this.tool.destroy()
1393
+ this.history.destroy()
1394
+ for (const extensionName in this.extension) {
1395
+ const extensionInstance = this.extension[extensionName]
1396
+ if ('destroy' in extensionInstance) {
1397
+ extensionInstance.destroy?.()
1398
+ }
1399
+ }
1376
1400
  }
1377
1401
  }
1378
1402
 
@@ -147,6 +147,10 @@ export default class EventEmitter {
147
147
  getEvents() {
148
148
  return this._events
149
149
  }
150
+
151
+ destroy() {
152
+ this._events = {}
153
+ }
150
154
  }
151
155
 
152
156
  export { EventEmitter, EventArgs }
@@ -107,6 +107,13 @@ export class History {
107
107
  }, this.waitTime),
108
108
  )
109
109
  }
110
+
111
+ destroy() {
112
+ this.undos = []
113
+ this.redos = []
114
+ this.curData = null
115
+ this.stopWatch && this.stopWatch()
116
+ }
110
117
  }
111
118
 
112
119
  export default History
@@ -90,6 +90,10 @@ export class Keyboard {
90
90
  }
91
91
  }
92
92
 
93
+ destroy() {
94
+ this.mousetrap.reset()
95
+ }
96
+
93
97
  private getKeys(keys: string | string[]) {
94
98
  return (Array.isArray(keys) ? keys : [keys]).map((key) =>
95
99
  this.formatKey(key),
@@ -123,6 +123,8 @@ export interface IEditConfigType {
123
123
  nodeTextMode: TextMode
124
124
  // 边文本类型
125
125
  edgeTextMode: TextMode
126
+ // 开启网格对齐
127
+ snapGrid: boolean
126
128
  }
127
129
 
128
130
  export type IConfigKeys = keyof IEditConfigType
@@ -154,6 +156,7 @@ const allKeys = [
154
156
  'stopZoomGraph', // 禁止缩放画布
155
157
  'stopScrollGraph', // 禁止鼠标滚动移动画布
156
158
  'stopMoveGraph', // 禁止拖动画布
159
+ 'snapGrid', // 是否开启网格对齐
157
160
  'adjustEdge', // 允许调整边
158
161
  'adjustEdgeMiddle', // 允许调整边中点
159
162
  'adjustEdgeStartAndEnd', // 允许调整边起点和终点
@@ -198,6 +201,7 @@ export class EditConfigModel {
198
201
  @observable stopZoomGraph = false
199
202
  @observable stopMoveGraph = false
200
203
  @observable stopScrollGraph = false
204
+ @observable snapGrid = false
201
205
  /*********************************************************
202
206
  * 文本相关配置(全局)
203
207
  ********************************************************/