@logicflow/core 2.0.6 → 2.0.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 (58) hide show
  1. package/.turbo/turbo-build$colon$dev.log +10 -10
  2. package/.turbo/turbo-build.log +33 -33
  3. package/CHANGELOG.md +21 -0
  4. package/__tests__/algorithm/egde.test.ts +36 -23
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/es/event/eventArgs.d.ts +23 -29
  8. package/es/model/GraphModel.d.ts +10 -0
  9. package/es/model/GraphModel.js +26 -1
  10. package/es/model/edge/BaseEdgeModel.d.ts +1 -0
  11. package/es/model/node/BaseNodeModel.js +1 -1
  12. package/es/util/drag.d.ts +1 -0
  13. package/es/util/drag.js +11 -0
  14. package/es/view/Anchor.js +6 -8
  15. package/es/view/Control.js +1 -1
  16. package/es/view/Graph.js +3 -15
  17. package/es/view/behavior/dnd.js +1 -0
  18. package/es/view/edge/BaseEdge.d.ts +3 -1
  19. package/es/view/edge/BaseEdge.js +8 -5
  20. package/es/view/overlay/BackgroundOverlay.d.ts +4 -14
  21. package/es/view/overlay/BackgroundOverlay.js +11 -1
  22. package/es/view/overlay/Grid.d.ts +4 -3
  23. package/es/view/overlay/Grid.js +8 -31
  24. package/es/view/text/BaseText.js +1 -1
  25. package/lib/event/eventArgs.d.ts +23 -29
  26. package/lib/model/GraphModel.d.ts +10 -0
  27. package/lib/model/GraphModel.js +25 -0
  28. package/lib/model/edge/BaseEdgeModel.d.ts +1 -0
  29. package/lib/model/node/BaseNodeModel.js +1 -1
  30. package/lib/util/drag.d.ts +1 -0
  31. package/lib/util/drag.js +11 -0
  32. package/lib/view/Anchor.js +6 -8
  33. package/lib/view/Control.js +1 -1
  34. package/lib/view/Graph.js +3 -15
  35. package/lib/view/behavior/dnd.js +1 -0
  36. package/lib/view/edge/BaseEdge.d.ts +3 -1
  37. package/lib/view/edge/BaseEdge.js +8 -5
  38. package/lib/view/overlay/BackgroundOverlay.d.ts +4 -14
  39. package/lib/view/overlay/BackgroundOverlay.js +11 -1
  40. package/lib/view/overlay/Grid.d.ts +4 -3
  41. package/lib/view/overlay/Grid.js +8 -31
  42. package/lib/view/text/BaseText.js +1 -1
  43. package/package.json +1 -1
  44. package/src/algorithm/edge.ts +2 -4
  45. package/src/event/eventArgs.ts +23 -29
  46. package/src/model/GraphModel.ts +12 -1
  47. package/src/model/edge/BaseEdgeModel.ts +1 -0
  48. package/src/model/node/BaseNodeModel.ts +1 -1
  49. package/src/model/node/HtmlNodeModel.ts +1 -1
  50. package/src/util/drag.ts +12 -0
  51. package/src/view/Anchor.tsx +7 -8
  52. package/src/view/Control.tsx +1 -1
  53. package/src/view/Graph.tsx +2 -3
  54. package/src/view/behavior/dnd.ts +1 -0
  55. package/src/view/edge/BaseEdge.tsx +8 -3
  56. package/src/view/overlay/Grid.tsx +13 -9
  57. package/src/view/text/BaseText.tsx +1 -1
  58. package/stats.html +1 -1
@@ -52,6 +52,7 @@ var _1 = require(".");
52
52
  var constant_1 = require("../constant");
53
53
  var util_1 = require("../util");
54
54
  var eventEmitter_1 = __importDefault(require("../event/eventEmitter"));
55
+ var overlay_1 = require("../view/overlay");
55
56
  var GraphModel = /** @class */ (function () {
56
57
  function GraphModel(options) {
57
58
  // 维护所有节点和边类型对应的 model
@@ -94,6 +95,7 @@ var GraphModel = /** @class */ (function () {
94
95
  this.gridSize = grid.size || 1; // 默认 gridSize 设置为 1
95
96
  }
96
97
  this.theme = (0, util_1.setupTheme)(options.style);
98
+ this.grid = overlay_1.Grid.getGridOptions(grid !== null && grid !== void 0 ? grid : false);
97
99
  this.edgeType = options.edgeType || 'polyline';
98
100
  this.animation = (0, util_1.setupAnimation)(animation);
99
101
  this.overlapMode = options.overlapMode || constant_1.OverlapMode.DEFAULT;
@@ -1244,6 +1246,26 @@ var GraphModel = /** @class */ (function () {
1244
1246
  GraphModel.prototype.setTheme = function (style) {
1245
1247
  this.theme = (0, util_1.updateTheme)(__assign(__assign({}, this.theme), style));
1246
1248
  };
1249
+ /**
1250
+ * 更新网格配置
1251
+ */
1252
+ GraphModel.prototype.updateGridOptions = function (options) {
1253
+ (0, lodash_es_1.merge)(this.grid, options);
1254
+ };
1255
+ /**
1256
+ * 更新网格配置
1257
+ */
1258
+ GraphModel.prototype.updateBackgroundOptions = function (options) {
1259
+ if (typeof options === 'boolean') {
1260
+ this.background = options;
1261
+ }
1262
+ else if (typeof this.background === 'boolean') {
1263
+ this.background = options;
1264
+ }
1265
+ else {
1266
+ this.background = __assign(__assign({}, this.background), options);
1267
+ }
1268
+ };
1247
1269
  /**
1248
1270
  * 重新设置画布的宽高
1249
1271
  */
@@ -1371,6 +1393,9 @@ var GraphModel = /** @class */ (function () {
1371
1393
  __decorate([
1372
1394
  mobx_1.observable
1373
1395
  ], GraphModel.prototype, "height", void 0);
1396
+ __decorate([
1397
+ mobx_1.observable
1398
+ ], GraphModel.prototype, "grid", void 0);
1374
1399
  __decorate([
1375
1400
  mobx_1.observable
1376
1401
  ], GraphModel.prototype, "edgeType", void 0);
@@ -48,6 +48,7 @@ export declare class BaseEdgeModel<P extends PropertiesType = PropertiesType> im
48
48
  visible: boolean;
49
49
  isAnimation: boolean;
50
50
  isShowAdjustPoint: boolean;
51
+ isDragging?: boolean;
51
52
  graphModel: GraphModel;
52
53
  zIndex: number;
53
54
  state: ElementState;
@@ -739,7 +739,7 @@ var BaseNodeModel = /** @class */ (function () {
739
739
  var preProperties = (0, mobx_1.toJS)(this.properties);
740
740
  this.properties = nextProperties;
741
741
  this.setAttributes();
742
- // 触发更新节点 properties:change 的事件
742
+ // 触发更新节点 node:properties-change 的事件
743
743
  this.graphModel.eventCenter.emit(constant_1.EventType.NODE_PROPERTIES_CHANGE, {
744
744
  id: this.id,
745
745
  keys: updateKeys,
@@ -44,4 +44,5 @@ export declare class StepDrag {
44
44
  handleMouseMove: (e: MouseEvent) => void;
45
45
  handleMouseUp: (e: MouseEvent) => void;
46
46
  cancelDrag: () => void;
47
+ destroy: () => void;
47
48
  }
package/lib/util/drag.js CHANGED
@@ -124,6 +124,17 @@ var StepDrag = /** @class */ (function () {
124
124
  _this.onDragEnd({ event: undefined });
125
125
  _this.isDragging = false;
126
126
  };
127
+ this.destroy = function () {
128
+ if (_this.isStartDragging) {
129
+ // https://github.com/didi/LogicFlow/issues/1934
130
+ // https://github.com/didi/LogicFlow/issues/1926
131
+ // cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算
132
+ // 我们的本意是为了防止mousemove和mouseup没有及时被移除
133
+ // 因此这里增加if(this.isStartDragging)的判断,isStartDragging=true代表没有触发handleMouseUp(),此时监听还没被移除
134
+ // 在拖拽情况下(isStartDragging=true),此时注册了监听,在组件突然销毁时,强制触发cancelDrag进行监听事件的移除
135
+ _this.cancelDrag();
136
+ }
137
+ };
127
138
  this.onDragStart = onDragStart;
128
139
  this.onDragging = onDragging;
129
140
  this.onDragEnd = onDragEnd;
@@ -141,14 +141,12 @@ var Anchor = /** @class */ (function (_super) {
141
141
  _this.sourceRuleResults.clear();
142
142
  _this.targetRuleResults.clear();
143
143
  var _b = _this.props, graphModel = _b.graphModel, nodeModel = _b.nodeModel, anchorData = _b.anchorData;
144
- if (edgeModel) {
145
- graphModel.eventCenter.emit(constant_1.EventType.ANCHOR_DRAGEND, {
146
- data: anchorData,
147
- e: event,
148
- nodeModel: nodeModel,
149
- edgeModel: edgeModel,
150
- });
151
- }
144
+ graphModel.eventCenter.emit(constant_1.EventType.ANCHOR_DRAGEND, {
145
+ data: anchorData,
146
+ e: event,
147
+ nodeModel: nodeModel,
148
+ edgeModel: edgeModel !== null && edgeModel !== void 0 ? edgeModel : undefined,
149
+ });
152
150
  };
153
151
  _this.checkEnd = function (event) {
154
152
  var _a;
@@ -319,7 +319,7 @@ var ResizeControl = /** @class */ (function (_super) {
319
319
  return _this;
320
320
  }
321
321
  ResizeControl.prototype.componentWillUnmount = function () {
322
- this.dragHandler.cancelDrag();
322
+ this.dragHandler.destroy();
323
323
  };
324
324
  ResizeControl.prototype.render = function () {
325
325
  var _a = this.props, x = _a.x, y = _a.y, direction = _a.direction, model = _a.model;
package/lib/view/Graph.js CHANGED
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
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
17
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
29
18
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
19
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -104,12 +93,11 @@ var Graph = /** @class */ (function (_super) {
104
93
  if (options.height) {
105
94
  style.height = "".concat(graphModel.height, "px");
106
95
  }
107
- var grid = options.grid && overlay_1.Grid.getGridOptions(options.grid);
108
- var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel;
96
+ var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel, background = graphModel.background;
109
97
  var adjustEdge = editConfigModel.adjustEdge;
110
- return ((0, jsx_runtime_1.jsxs)("div", { className: "lf-graph", "flow-id": graphModel.flowId, children: [(0, jsx_runtime_1.jsxs)(overlay_1.CanvasOverlay, { graphModel: graphModel, dnd: dnd, children: [(0, jsx_runtime_1.jsx)("g", { className: "lf-base", children: (0, lodash_es_1.map)(graphModel.sortElements, function (nodeModel) {
98
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "lf-graph", "flow-id": graphModel.flowId, style: style, children: [(0, jsx_runtime_1.jsxs)(overlay_1.CanvasOverlay, { graphModel: graphModel, dnd: dnd, children: [(0, jsx_runtime_1.jsx)("g", { className: "lf-base", children: (0, lodash_es_1.map)(graphModel.sortElements, function (nodeModel) {
111
99
  return _this.getComponent(nodeModel, graphModel);
112
- }) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), (0, jsx_runtime_1.jsxs)(overlay_1.ModificationOverlay, { graphModel: graphModel, children: [(0, jsx_runtime_1.jsx)(overlay_1.OutlineOverlay, { graphModel: graphModel }), adjustEdge ? (0, jsx_runtime_1.jsx)(overlay_1.BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? ((0, jsx_runtime_1.jsx)(overlay_1.SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), (0, jsx_runtime_1.jsx)(overlay_1.ToolOverlay, { graphModel: graphModel, tool: tool }), options.background && ((0, jsx_runtime_1.jsx)(overlay_1.BackgroundOverlay, { background: options.background })), grid && (0, jsx_runtime_1.jsx)(overlay_1.Grid, __assign({}, grid, { graphModel: graphModel }))] }));
100
+ }) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), (0, jsx_runtime_1.jsxs)(overlay_1.ModificationOverlay, { graphModel: graphModel, children: [(0, jsx_runtime_1.jsx)(overlay_1.OutlineOverlay, { graphModel: graphModel }), adjustEdge ? (0, jsx_runtime_1.jsx)(overlay_1.BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? ((0, jsx_runtime_1.jsx)(overlay_1.SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), (0, jsx_runtime_1.jsx)(overlay_1.ToolOverlay, { graphModel: graphModel, tool: tool }), background && (0, jsx_runtime_1.jsx)(overlay_1.BackgroundOverlay, { background: background }), (0, jsx_runtime_1.jsx)(overlay_1.Grid, { graphModel: graphModel })] }));
113
101
  };
114
102
  Graph = __decorate([
115
103
  __1.observer
@@ -44,6 +44,7 @@ var Dnd = /** @class */ (function () {
44
44
  _this.lf.setNodeSnapLine(nodeData);
45
45
  _this.lf.graphModel.eventCenter.emit(constant_1.EventType.NODE_DND_DRAG, {
46
46
  data: nodeData,
47
+ e: e,
47
48
  });
48
49
  }
49
50
  return false;
@@ -13,6 +13,7 @@ export type IEdgeState = {
13
13
  export declare abstract class BaseEdge<P extends IProps> extends Component<P, IEdgeState> {
14
14
  static isObserved: boolean;
15
15
  static extendsKey?: string;
16
+ mouseUpDrag?: boolean;
16
17
  startTime?: number;
17
18
  contextMenuTime?: number;
18
19
  clickTimer?: number;
@@ -127,10 +128,11 @@ export declare abstract class BaseEdge<P extends IProps> extends Component<P, IE
127
128
  * 不支持重写
128
129
  */
129
130
  handleMouseDown: (e: MouseEvent) => void;
131
+ handleMouseUp: () => void;
130
132
  /**
131
133
  * 不支持重写
132
134
  */
133
- handleMouseUp: (e: MouseEvent) => void;
135
+ handleClick: (e: MouseEvent) => void;
134
136
  /**
135
137
  * @overridable 支持重写, 此方法为获取边的形状,如果需要自定义边的形状,请重写此方法。
136
138
  * @example https://docs.logic-flow.cn/docs/#/zh/guide/basic/edge?id=%e5%9f%ba%e4%ba%8e-react-%e7%bb%84%e4%bb%b6%e8%87%aa%e5%ae%9a%e4%b9%89%e8%be%b9
@@ -149,15 +149,18 @@ var BaseEdge = /** @class */ (function (_super) {
149
149
  e.stopPropagation();
150
150
  _this.startTime = new Date().getTime();
151
151
  };
152
+ _this.handleMouseUp = function () {
153
+ var model = _this.props.model;
154
+ _this.mouseUpDrag = model.isDragging;
155
+ };
152
156
  /**
153
157
  * 不支持重写
154
158
  */
155
- _this.handleMouseUp = function (e) {
159
+ _this.handleClick = function (e) {
156
160
  if (!_this.startTime)
157
161
  return;
158
- var time = new Date().getTime() - _this.startTime;
159
- if (time > 200)
160
- return; // 事件大于200ms,认为是拖拽。
162
+ if (_this.mouseUpDrag)
163
+ return; // 如果是拖拽,不触发click事件。
161
164
  var isRightClick = e.button === 2;
162
165
  if (isRightClick)
163
166
  return;
@@ -405,7 +408,7 @@ var BaseEdge = /** @class */ (function (_super) {
405
408
  isSelected && 'lf-edge-selected',
406
409
  ]
407
410
  .filter(Boolean)
408
- .join(' '), onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onContextMenu: this.handleContextMenu, onMouseOver: this.setHoverOn, onMouseEnter: this.setHoverOn, onMouseLeave: this.setHoverOff, children: [this.getShape(), this.getAppend(), this.getText(), this.getArrow()] }), isShowAdjustPoint && isSelected ? this.getAdjustPoints() : ''] }));
411
+ .join(' '), onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onClick: this.handleClick, onContextMenu: this.handleContextMenu, onMouseOver: this.setHoverOn, onMouseEnter: this.setHoverOn, onMouseLeave: this.setHoverOff, children: [this.getShape(), this.getAppend(), this.getText(), this.getArrow()] }), isShowAdjustPoint && isSelected ? this.getAdjustPoints() : ''] }));
409
412
  };
410
413
  BaseEdge.isObserved = false;
411
414
  return BaseEdge;
@@ -1,26 +1,16 @@
1
1
  import { Component } from 'preact/compat';
2
+ import { Options as LFOptions } from '../../options';
2
3
  /**
3
4
  * 背景配置, 支持css属性配置
4
5
  * https://developer.mozilla.org/zh-CN/docs/Web/CSS/background
5
6
  * @example
6
7
  * {
7
- * backgroundImage: "url('./img/grid.svg')",
8
- backgroundRepeat: 'repeat',
8
+ * backgroundImage: "url('./img/grid.svg')",
9
+ backgroundRepeat: 'repeat',
9
10
  * }
10
11
  */
11
- export type BackgroundConfig = {
12
- /**
13
- * 背景图片地址
14
- */
15
- backgroundImage?: string;
16
- /**
17
- * 是否重复
18
- */
19
- backgroundRepeat?: string;
20
- [key: string]: any;
21
- };
22
12
  type IProps = {
23
- background: BackgroundConfig;
13
+ background: boolean | LFOptions.BackgroundConfig;
24
14
  };
25
15
  export declare class BackgroundOverlay extends Component<IProps> {
26
16
  render(): import("preact/compat").JSX.Element;
@@ -14,10 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ 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;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
17
23
  Object.defineProperty(exports, "__esModule", { value: true });
18
24
  exports.BackgroundOverlay = void 0;
19
25
  var jsx_runtime_1 = require("preact/jsx-runtime");
20
26
  var compat_1 = require("preact/compat");
27
+ var __1 = require("../..");
21
28
  var BackgroundOverlay = /** @class */ (function (_super) {
22
29
  __extends(BackgroundOverlay, _super);
23
30
  function BackgroundOverlay() {
@@ -25,8 +32,11 @@ var BackgroundOverlay = /** @class */ (function (_super) {
25
32
  }
26
33
  BackgroundOverlay.prototype.render = function () {
27
34
  var background = this.props.background;
28
- return ((0, jsx_runtime_1.jsx)("div", { className: "lf-background", children: (0, jsx_runtime_1.jsx)("div", { style: background, className: "lf-background-area" }) }));
35
+ return ((0, jsx_runtime_1.jsx)("div", { className: "lf-background", children: (0, jsx_runtime_1.jsx)("div", { style: typeof background === 'object' ? background : {}, className: "lf-background-area" }) }));
29
36
  };
37
+ BackgroundOverlay = __decorate([
38
+ __1.observer
39
+ ], BackgroundOverlay);
30
40
  return BackgroundOverlay;
31
41
  }(compat_1.Component));
32
42
  exports.BackgroundOverlay = BackgroundOverlay;
@@ -1,11 +1,12 @@
1
1
  import { Component } from 'preact/compat';
2
2
  import { GraphModel } from '../../model';
3
- import GridOptions = Grid.GridOptions;
4
- type IProps = GridOptions & {
3
+ type IProps = {
5
4
  graphModel: GraphModel;
6
5
  };
7
6
  export declare class Grid extends Component<IProps> {
7
+ gridOptions: Grid.GridOptions;
8
8
  readonly id: string;
9
+ constructor(props: IProps);
9
10
  renderDot(): import("preact/compat").JSX.Element;
10
11
  renderMesh(): import("preact/compat").JSX.Element;
11
12
  render(): import("preact/compat").JSX.Element;
@@ -30,7 +31,7 @@ export declare namespace Grid {
30
31
  /**
31
32
  * 网格的颜色
32
33
  */
33
- color: string;
34
+ color?: string;
34
35
  /**
35
36
  * 网格的宽度
36
37
  * - 对于 `dot` 点状网格,表示点的大小
@@ -20,31 +20,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
20
20
  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;
21
21
  return c > 3 && r && Object.defineProperty(target, key, r), r;
22
22
  };
23
- var __read = (this && this.__read) || function (o, n) {
24
- var m = typeof Symbol === "function" && o[Symbol.iterator];
25
- if (!m) return o;
26
- var i = m.call(o), r, ar = [], e;
27
- try {
28
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
- }
30
- catch (error) { e = { error: error }; }
31
- finally {
32
- try {
33
- if (r && !r.done && (m = i["return"])) m.call(i);
34
- }
35
- finally { if (e) throw e.error; }
36
- }
37
- return ar;
38
- };
39
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
40
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
41
- if (ar || !(i in from)) {
42
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
43
- ar[i] = from[i];
44
- }
45
- }
46
- return to.concat(ar || Array.prototype.slice.call(from));
47
- };
48
23
  Object.defineProperty(exports, "__esModule", { value: true });
49
24
  exports.Grid = void 0;
50
25
  var jsx_runtime_1 = require("preact/jsx-runtime");
@@ -55,14 +30,15 @@ var util_1 = require("../../util");
55
30
  var constant_1 = require("../../constant");
56
31
  var Grid = /** @class */ (function (_super) {
57
32
  __extends(Grid, _super);
58
- function Grid() {
59
- var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
33
+ function Grid(props) {
34
+ var _this = _super.call(this, props) || this;
60
35
  _this.id = (0, util_1.createUuid)();
36
+ _this.gridOptions = _this.props.graphModel.grid;
61
37
  return _this;
62
38
  }
63
39
  // 网格类型为点状
64
40
  Grid.prototype.renderDot = function () {
65
- var _a = this.props, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
41
+ var _a = this.gridOptions, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
66
42
  var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 2 : _d;
67
43
  // 对于点状网格,点的半径不能大于网格大小的四分之一
68
44
  var radius = Math.min(Math.max(2, thickness), size / 4);
@@ -72,16 +48,17 @@ var Grid = /** @class */ (function (_super) {
72
48
  // 网格类型为交叉线
73
49
  // todo: 采用背景缩放的方式,实现更好的体验
74
50
  Grid.prototype.renderMesh = function () {
75
- var _a = this.props, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
51
+ var _a = this.gridOptions, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
76
52
  var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 1 : _d;
77
53
  // 对于交叉线网格,线的宽度不能大于网格大小的一半
78
54
  var strokeWidth = Math.min(Math.max(1, thickness), size / 2);
79
55
  var d = "M 0 0 H ".concat(size, " V ").concat(size, " H 0 Z");
80
56
  var opacity = visible ? 1 : 0;
81
- return ((0, jsx_runtime_1.jsx)("path", { d: d, stroke: color, strokeWidth: strokeWidth, opacity: opacity, fill: "transparent" }));
57
+ return ((0, jsx_runtime_1.jsx)("path", { d: d, stroke: color, strokeWidth: strokeWidth / 2, opacity: opacity, fill: "transparent" }));
82
58
  };
83
59
  Grid.prototype.render = function () {
84
- var _a = this.props, type = _a.type, _b = _a.size, size = _b === void 0 ? 1 : _b, transformModel = _a.graphModel.transformModel;
60
+ var transformModel = this.props.graphModel.transformModel;
61
+ var _a = this.gridOptions, type = _a.type, _b = _a.size, size = _b === void 0 ? 1 : _b;
85
62
  var SCALE_X = transformModel.SCALE_X, SKEW_Y = transformModel.SKEW_Y, SKEW_X = transformModel.SKEW_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
86
63
  var matrixString = [
87
64
  SCALE_X,
@@ -67,7 +67,7 @@ var BaseText = /** @class */ (function (_super) {
67
67
  _this.onDragging = function (_a) {
68
68
  var deltaX = _a.deltaX, deltaY = _a.deltaY;
69
69
  var _b = _this.props, model = _b.model, transformModel = _b.graphModel.transformModel;
70
- if (deltaX && deltaY) {
70
+ if (deltaX || deltaY) {
71
71
  var _c = __read(transformModel.fixDeltaXY(deltaX, deltaY), 2), curDeltaX = _c[0], curDeltaY = _c[1];
72
72
  model.moveText(curDeltaX, curDeltaY);
73
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "LogicFlow, help you quickly create flowcharts",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -60,10 +60,8 @@ export const isInSegment = (point: Point, start: Point, end: Point) => {
60
60
  const k = (endY - startY) / (endX - startX)
61
61
  const b = startY - k * startX
62
62
  return (
63
- x >= startX &&
64
- x <= endX &&
65
- y >= startY &&
66
- y <= endY &&
63
+ ((x >= startX && x <= endX) || (x <= startX && x >= endX)) &&
64
+ ((y >= startY && y <= endY) || (y <= startY && y >= endY)) &&
67
65
  Math.abs(y - k * x + b) < Number.EPSILON
68
66
  )
69
67
  }
@@ -140,7 +140,7 @@ interface NodeEventArgs {
140
140
  /**
141
141
  * 拖拽外部拖入节点
142
142
  */
143
- 'node:dnd-drag': NodeEventArgsPick<'data'>
143
+ 'node:dnd-drag': NodeEventArgsPick<'data' | 'e'>
144
144
  /**
145
145
  * 开始拖拽节点
146
146
  */
@@ -167,6 +167,27 @@ interface NodeEventArgs {
167
167
  'node:resize': NodeEventArgsPick<
168
168
  'preData' | 'data' | 'model' | 'deltaX' | 'deltaY' | 'index'
169
169
  >
170
+ /**
171
+ * 元素的 properties 发生改变
172
+ */
173
+ 'node:properties-change': {
174
+ /**
175
+ * 元素的 id
176
+ */
177
+ id: string
178
+ /**
179
+ * 改变的 properties 的 key
180
+ */
181
+ keys: string[]
182
+ /**
183
+ * 改变前的 properties
184
+ */
185
+ preProperties: Record<string, any>
186
+ /**
187
+ * 改变后的 properties
188
+ */
189
+ properties: Record<string, any>
190
+ }
170
191
  }
171
192
 
172
193
  type EdgeEventArgsPick<T extends 'data' | 'e' | 'position'> = Pick<
@@ -356,33 +377,6 @@ interface CommonEventArgs {
356
377
  */
357
378
  position: ClientPosition
358
379
  }
359
- /**
360
- * 元素的 properties 发生改变
361
- */
362
- 'properties:change': {
363
- data: {
364
- /**
365
- * 元素的 id
366
- */
367
- id: string
368
- /**
369
- * 元素的类型
370
- */
371
- type: string
372
- /**
373
- * 改变的 properties 的 key
374
- */
375
- keys: string[]
376
- /**
377
- * 改变前的 properties
378
- */
379
- preProperties: Record<string, any>
380
- /**
381
- * 改变后的 properties
382
- */
383
- properties: Record<string, any>
384
- }
385
- }
386
380
  /**
387
381
  * 进行画布平移或缩放等变化操作时触发
388
382
  */
@@ -440,7 +434,7 @@ type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> =
440
434
  /**
441
435
  * 通过拖动锚点连线添加的边的数据
442
436
  */
443
- edgeModel: BaseEdgeModel
437
+ edgeModel?: BaseEdgeModel
444
438
  },
445
439
  T
446
440
  >
@@ -1,4 +1,4 @@
1
- import { find, forEach, map } from 'lodash-es'
1
+ import { find, forEach, map, merge } from 'lodash-es'
2
2
  import { action, computed, observable } from 'mobx'
3
3
  import {
4
4
  BaseEdgeModel,
@@ -36,6 +36,7 @@ import {
36
36
  updateTheme,
37
37
  } from '../util'
38
38
  import EventEmitter from '../event/eventEmitter'
39
+ import { Grid } from '../view/overlay'
39
40
  import Position = LogicFlow.Position
40
41
  import PointTuple = LogicFlow.PointTuple
41
42
  import GraphData = LogicFlow.GraphData
@@ -55,6 +56,8 @@ export class GraphModel {
55
56
 
56
57
  // 流程图主题配置
57
58
  theme: LogicFlow.Theme
59
+ // 网格配置
60
+ @observable grid: Grid.GridOptions
58
61
  // 事件中心
59
62
  readonly eventCenter: EventEmitter
60
63
  // 维护所有节点和边类型对应的 model
@@ -142,6 +145,7 @@ export class GraphModel {
142
145
  this.gridSize = grid.size || 1 // 默认 gridSize 设置为 1
143
146
  }
144
147
  this.theme = setupTheme(options.style)
148
+ this.grid = Grid.getGridOptions(grid ?? false)
145
149
  this.edgeType = options.edgeType || 'polyline'
146
150
  this.animation = setupAnimation(animation)
147
151
  this.overlapMode = options.overlapMode || OverlapMode.DEFAULT
@@ -1407,6 +1411,13 @@ export class GraphModel {
1407
1411
  this.theme = updateTheme({ ...this.theme, ...style })
1408
1412
  }
1409
1413
 
1414
+ /**
1415
+ * 更新网格配置
1416
+ */
1417
+ updateGridOptions(options: Partial<Grid.GridOptions>) {
1418
+ merge(this.grid, options)
1419
+ }
1420
+
1410
1421
  /**
1411
1422
  * 重新设置画布的宽高
1412
1423
  */
@@ -87,6 +87,7 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
87
87
  // 边特有属性,动画及调整点
88
88
  @observable isAnimation = false
89
89
  @observable isShowAdjustPoint = false // 是否显示边两端的调整点
90
+ isDragging?: boolean
90
91
  // 引用属性
91
92
  graphModel: GraphModel
92
93
  @observable zIndex: number = 0
@@ -835,7 +835,7 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
835
835
  this.properties = nextProperties
836
836
  this.setAttributes()
837
837
 
838
- // 触发更新节点 properties:change 的事件
838
+ // 触发更新节点 node:properties-change 的事件
839
839
  this.graphModel.eventCenter.emit(EventType.NODE_PROPERTIES_CHANGE, {
840
840
  id: this.id,
841
841
  keys: updateKeys,
@@ -6,7 +6,7 @@ import AnchorConfig = Model.AnchorConfig
6
6
  import LogicFlow from '../../LogicFlow'
7
7
  import GraphModel from '../GraphModel'
8
8
 
9
- export type IHtmlNodeProperties = {
9
+ export interface IHtmlNodeProperties {
10
10
  width?: number
11
11
  height?: number
12
12
  style?: LogicFlow.CommonTheme
package/src/util/drag.ts CHANGED
@@ -201,4 +201,16 @@ export class StepDrag {
201
201
  this.onDragEnd({ event: undefined })
202
202
  this.isDragging = false
203
203
  }
204
+
205
+ destroy = () => {
206
+ if (this.isStartDragging) {
207
+ // https://github.com/didi/LogicFlow/issues/1934
208
+ // https://github.com/didi/LogicFlow/issues/1926
209
+ // cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算
210
+ // 我们的本意是为了防止mousemove和mouseup没有及时被移除
211
+ // 因此这里增加if(this.isStartDragging)的判断,isStartDragging=true代表没有触发handleMouseUp(),此时监听还没被移除
212
+ // 在拖拽情况下(isStartDragging=true),此时注册了监听,在组件突然销毁时,强制触发cancelDrag进行监听事件的移除
213
+ this.cancelDrag()
214
+ }
215
+ }
204
216
  }
@@ -189,14 +189,13 @@ class Anchor extends Component<IProps, IState> {
189
189
  this.sourceRuleResults.clear()
190
190
  this.targetRuleResults.clear()
191
191
  const { graphModel, nodeModel, anchorData } = this.props
192
- if (edgeModel) {
193
- graphModel.eventCenter.emit(EventType.ANCHOR_DRAGEND, {
194
- data: anchorData,
195
- e: event!,
196
- nodeModel,
197
- edgeModel,
198
- })
199
- }
192
+
193
+ graphModel.eventCenter.emit(EventType.ANCHOR_DRAGEND, {
194
+ data: anchorData,
195
+ e: event!,
196
+ nodeModel,
197
+ edgeModel: edgeModel ?? undefined,
198
+ })
200
199
  }
201
200
 
202
201
  get customTrajectory() {
@@ -57,7 +57,7 @@ export class ResizeControl extends Component<
57
57
  }
58
58
 
59
59
  componentWillUnmount() {
60
- this.dragHandler.cancelDrag()
60
+ this.dragHandler.destroy()
61
61
  }
62
62
 
63
63
  updateEdgePointByAnchors = () => {
@@ -87,11 +87,10 @@ class Graph extends Component<IGraphProps> {
87
87
  if (options.height) {
88
88
  style.height = `${graphModel.height}px`
89
89
  }
90
- const grid = options.grid && Grid.getGridOptions(options.grid)
91
90
  const { fakeNode, editConfigModel } = graphModel
92
91
  const { adjustEdge } = editConfigModel
93
92
  return (
94
- <div className="lf-graph" flow-id={graphModel.flowId}>
93
+ <div className="lf-graph" flow-id={graphModel.flowId} style={style}>
95
94
  {/* 元素层 */}
96
95
  <CanvasOverlay graphModel={graphModel} dnd={dnd}>
97
96
  <g className="lf-base">
@@ -117,7 +116,7 @@ class Graph extends Component<IGraphProps> {
117
116
  <BackgroundOverlay background={options.background} />
118
117
  )}
119
118
  {/* 画布网格 */}
120
- {grid && <Grid {...grid} graphModel={graphModel} />}
119
+ <Grid graphModel={graphModel} />
121
120
  </div>
122
121
  )
123
122
  }