@logicflow/core 1.2.0-alpha.12 → 1.2.0-alpha.15

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.
@@ -11337,7 +11337,7 @@ module.exports.f = function (C) {
11337
11337
  /* 161 */
11338
11338
  /***/ (function(module) {
11339
11339
 
11340
- module.exports = JSON.parse("{\"a\":\"1.2.0-alpha.11\"}");
11340
+ module.exports = JSON.parse("{\"a\":\"1.2.0-alpha.14\"}");
11341
11341
 
11342
11342
  /***/ }),
11343
11343
  /* 162 */
@@ -21633,7 +21633,7 @@ var defaultTheme = {
21633
21633
  stroke: 'red',
21634
21634
  strokeDasharray: '10 10',
21635
21635
  strokeDashoffset: '100%',
21636
- animationName: 'dash',
21636
+ animationName: 'lf-dash',
21637
21637
  animationDuration: '20s',
21638
21638
  animationIterationCount: 'infinite',
21639
21639
  animationTimingFunction: 'linear',
@@ -22727,7 +22727,7 @@ var BaseEdgeModel_BaseEdgeModel = /*#__PURE__*/function () {
22727
22727
  BaseEdgeModel_defineProperty(this, "style", {});
22728
22728
 
22729
22729
  BaseEdgeModel_defineProperty(this, "arrowConfig", {
22730
- markerEnd: "url(#marker-end-".concat(this.id, ")"),
22730
+ markerEnd: '',
22731
22731
  markerStart: ''
22732
22732
  });
22733
22733
 
@@ -22824,6 +22824,8 @@ var BaseEdgeModel_BaseEdgeModel = /*#__PURE__*/function () {
22824
22824
  if (overlapMode === OverlapMode.INCREASE) {
22825
22825
  this.zIndex = data.zIndex || getZIndex();
22826
22826
  }
22827
+
22828
+ this.arrowConfig.markerEnd = "url(#marker-end-".concat(this.id, ")");
22827
22829
  }
22828
22830
  /**
22829
22831
  * 设置model属性,每次properties发生变化会触发
@@ -24194,6 +24196,27 @@ var getVerticalPointOfLine = function getVerticalPointOfLine(config) {
24194
24196
 
24195
24197
  return pointPosition;
24196
24198
  };
24199
+ // CONCATENATED MODULE: ./src/util/vector.ts
24200
+ var getDirectionVector = function getDirectionVector(point1, point2) {
24201
+ var a = point2.x - point1.x;
24202
+ var b = point2.y - point1.y;
24203
+
24204
+ if (a !== 0) {
24205
+ a = a / Math.abs(a);
24206
+ }
24207
+
24208
+ if (b !== 0) {
24209
+ b = b / Math.abs(b);
24210
+ }
24211
+
24212
+ return [a, b];
24213
+ };
24214
+ var isSameDirection = function isSameDirection(v1, v2) {
24215
+ return v1[0] === v2[0] && v1[1] === v2[1];
24216
+ };
24217
+ var isContraryDirection = function isContraryDirection(v1, v2) {
24218
+ return !(v1[0] + v2[0] || v1[1] + v2[1]);
24219
+ };
24197
24220
  // CONCATENATED MODULE: ./src/util/edge.ts
24198
24221
  function edge_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
24199
24222
 
@@ -24251,6 +24274,7 @@ function edge_arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
24251
24274
 
24252
24275
 
24253
24276
 
24277
+
24254
24278
 
24255
24279
 
24256
24280
  /* 手动创建边时edge->edgeModel */
@@ -24990,14 +25014,58 @@ var edge_getBezierControlPoints = function getBezierControlPoints(_ref) {
24990
25014
  sourceNode = _ref.sourceNode,
24991
25015
  targetNode = _ref.targetNode,
24992
25016
  offset = _ref.offset;
25017
+ var nodeDistance = Math.max(Math.abs(sourceNode.x - targetNode.x), Math.abs(sourceNode.y - targetNode.y));
25018
+ offset = offset || nodeDistance / 4;
24993
25019
  var sBBox = getNodeBBox(sourceNode);
24994
25020
  var tBBox = getNodeBBox(targetNode);
24995
25021
  var sExpendBBox = getExpandedBBox(sBBox, offset);
24996
25022
  var tExpendBBox = getExpandedBBox(tBBox, offset);
24997
25023
  var sDirection = edge_pointDirection(start, sourceNode);
25024
+ var tDirection = edge_pointDirection(end, targetNode); // 1. 避免两个节点连出的多个连线重合。
25025
+ // 2. 避免开始节点和结束节点方向相同时成为一个穿过节点的直线。
25026
+
24998
25027
  var sNext = edge_getExpandedBBoxPoint(sExpendBBox, start, sDirection);
24999
- var tDirection = edge_pointDirection(end, targetNode);
25000
- var ePre = edge_getExpandedBBoxPoint(tExpendBBox, end, tDirection);
25028
+ var ePre = edge_getExpandedBBoxPoint(tExpendBBox, end, tDirection); // 如果两个节点水平或垂直并且连线在两个节点最近的锚点之间,则不产生偏移,保证连线看起来像是直线
25029
+
25030
+ var vector1 = getDirectionVector(sourceNode, start);
25031
+ var vector2 = getDirectionVector(targetNode, end);
25032
+ var vector3 = getDirectionVector(sourceNode, targetNode); // 当开始节点控制连线的方向和连线方向相同,并且结束节点控制连线相反的时候,则意味这两个节点直接相连。此时不需要对控制点进行偏移调整
25033
+
25034
+ if (isSameDirection(vector1, vector3) && isContraryDirection(vector2, vector3)) {
25035
+ return {
25036
+ sNext: sNext,
25037
+ ePre: ePre
25038
+ };
25039
+ } // 当开始节点控制连线方向和连线方向相反的时候或者结束节点控制连线形同的时候,增大偏移量,实现更美观的效果。
25040
+
25041
+
25042
+ if (isSameDirection(vector2, vector3) || isContraryDirection(vector1, vector3)) {
25043
+ offset = offset * 2;
25044
+ } // 计算起点的调整点是否需要偏移
25045
+ // 如果起点的调整点方向和连线方向相反,则添加偏移量
25046
+ // 如果终点的调整点方向与连线方向
25047
+
25048
+
25049
+ var randomNumberX = Math.ceil((Math.random() + 0.5) * offset);
25050
+ var randomNumberY = Math.ceil((Math.random() + 0.5) * offset); // 如果是调整点在节点水平方向,那么调整的点Y需要向着另一个节点的方向进行一定随机量的偏移。
25051
+ // 如果是调整点在节点垂直方向,那么调整的点X需要向着另一个节点的方向进行一定随机量的偏移。
25052
+
25053
+ if (sDirection === SegmentDirection.HORIZONTAL) {
25054
+ sNext.y += sourceNode.y >= targetNode.y ? randomNumberY : -randomNumberY;
25055
+ }
25056
+
25057
+ if (sDirection === SegmentDirection.VERTICAL) {
25058
+ sNext.x += sourceNode.x >= targetNode.x ? randomNumberX : -randomNumberX;
25059
+ }
25060
+
25061
+ if (tDirection === SegmentDirection.HORIZONTAL) {
25062
+ ePre.y += sourceNode.y > targetNode.y ? randomNumberY : -randomNumberY;
25063
+ }
25064
+
25065
+ if (tDirection === SegmentDirection.VERTICAL) {
25066
+ ePre.x += sourceNode.x > targetNode.x ? randomNumberX : -randomNumberX;
25067
+ }
25068
+
25001
25069
  return {
25002
25070
  sNext: sNext,
25003
25071
  ePre: ePre
@@ -25647,6 +25715,8 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
25647
25715
  this.partial = options.partial;
25648
25716
  this.overlapMode = options.overlapMode || 0;
25649
25717
  this.idGenerator = idGenerator;
25718
+ this.width = options.width || this.rootEl.getBoundingClientRect().width;
25719
+ this.height = options.height || this.rootEl.getBoundingClientRect().height;
25650
25720
  }
25651
25721
 
25652
25722
  GraphModel_createClass(GraphModel, [{
@@ -25930,6 +26000,10 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
25930
26000
  value: function graphDataToModel(graphData) {
25931
26001
  var _this = this;
25932
26002
 
26003
+ if (!this.width || !this.height) {
26004
+ this.resize();
26005
+ }
26006
+
25933
26007
  this.nodes = lodash_es_map(graphData.nodes, function (node) {
25934
26008
  var Model = _this.getModel(node.type);
25935
26009
 
@@ -26904,8 +26978,12 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
26904
26978
  }, {
26905
26979
  key: "resize",
26906
26980
  value: function resize(width, height) {
26907
- this.width = width !== null && width !== void 0 ? width : this.width;
26908
- this.height = height !== null && height !== void 0 ? height : this.height;
26981
+ this.width = width || this.rootEl.getBoundingClientRect().width;
26982
+ this.height = height || this.rootEl.getBoundingClientRect().height;
26983
+
26984
+ if (!this.width || !this.height) {
26985
+ console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
26986
+ }
26909
26987
  }
26910
26988
  /**
26911
26989
  * 清空画布
@@ -28966,7 +29044,7 @@ var BezierEdgeModel_BezierEdgeModel = /*#__PURE__*/function (_BaseEdgeModel) {
28966
29044
  BezierEdgeModel_createClass(BezierEdgeModel, [{
28967
29045
  key: "initEdgeData",
28968
29046
  value: function initEdgeData(data) {
28969
- this.offset = 100;
29047
+ this.offset = 0;
28970
29048
 
28971
29049
  BezierEdgeModel_get(BezierEdgeModel_getPrototypeOf(BezierEdgeModel.prototype), "initEdgeData", this).call(this, data);
28972
29050
  }
@@ -31268,6 +31346,39 @@ var SnaplineModel_SnaplineModel = /*#__PURE__*/function () {
31268
31346
 
31269
31347
 
31270
31348
 
31349
+ // CONCATENATED MODULE: ./src/util/raf.ts
31350
+
31351
+
31352
+
31353
+
31354
+
31355
+
31356
+ var rafIdMap = new Map();
31357
+ var raf_createRaf = function createRaf(callback) {
31358
+ var rafId = uuid_createUuid();
31359
+
31360
+ function run() {
31361
+ callback();
31362
+ var eId = rafIdMap.get(rafId);
31363
+
31364
+ if (eId) {
31365
+ var nId = window.requestAnimationFrame(run);
31366
+ rafIdMap.set(rafId, nId);
31367
+ }
31368
+ }
31369
+
31370
+ var id = window.requestAnimationFrame(run);
31371
+ rafIdMap.set(rafId, id);
31372
+ return rafId;
31373
+ };
31374
+ var cancelRaf = function cancelRaf(rafId) {
31375
+ var eId = rafIdMap.get(rafId);
31376
+
31377
+ if (eId) {
31378
+ window.cancelAnimationFrame(eId);
31379
+ rafIdMap.delete(rafId);
31380
+ }
31381
+ };
31271
31382
  // CONCATENATED MODULE: ./src/view/Anchor.tsx
31272
31383
  function Anchor_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { Anchor_typeof = function _typeof(obj) { return typeof obj; }; } else { Anchor_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return Anchor_typeof(obj); }
31273
31384
 
@@ -31342,6 +31453,7 @@ function Anchor_defineProperty(obj, key, value) { if (key in obj) { Object.defin
31342
31453
 
31343
31454
 
31344
31455
 
31456
+
31345
31457
  var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31346
31458
  Anchor_inherits(Anchor, _Component);
31347
31459
 
@@ -31422,7 +31534,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31422
31534
  y1 = _graphModel$getPointB3.y;
31423
31535
 
31424
31536
  if (_this.t) {
31425
- clearInterval(_this.t);
31537
+ cancelRaf(_this.t);
31426
31538
  }
31427
31539
 
31428
31540
  var nearBoundary = [];
@@ -31447,7 +31559,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31447
31559
  _this.moveAnchorEnd(x1, y1);
31448
31560
 
31449
31561
  if (nearBoundary.length > 0 && !stopMoveGraph && autoExpand) {
31450
- _this.t = setInterval(function () {
31562
+ _this.t = raf_createRaf(function () {
31451
31563
  var _nearBoundary = nearBoundary,
31452
31564
  _nearBoundary2 = Anchor_slicedToArray(_nearBoundary, 2),
31453
31565
  translateX = _nearBoundary2[0],
@@ -31464,7 +31576,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31464
31576
  });
31465
31577
 
31466
31578
  _this.moveAnchorEnd(endX - translateX, endY - translateY);
31467
- }, 50);
31579
+ });
31468
31580
  }
31469
31581
 
31470
31582
  eventCenter.emit(EventType.ANCHOR_DRAG, {
@@ -32082,39 +32194,6 @@ var BaseText_BaseText = /*#__PURE__*/function (_Component) {
32082
32194
 
32083
32195
 
32084
32196
  var isIe = window.navigator.userAgent.match(/MSIE|Trident/) !== null;
32085
- // CONCATENATED MODULE: ./src/util/raf.ts
32086
-
32087
-
32088
-
32089
-
32090
-
32091
-
32092
- var rafIdMap = new Map();
32093
- var raf_createRaf = function createRaf(callback) {
32094
- var rafId = uuid_createUuid();
32095
-
32096
- function run() {
32097
- callback();
32098
- var eId = rafIdMap.get(rafId);
32099
-
32100
- if (eId) {
32101
- var nId = window.requestAnimationFrame(run);
32102
- rafIdMap.set(rafId, nId);
32103
- }
32104
- }
32105
-
32106
- var id = window.requestAnimationFrame(run);
32107
- rafIdMap.set(rafId, id);
32108
- return rafId;
32109
- };
32110
- var cancelRaf = function cancelRaf(rafId) {
32111
- var eId = rafIdMap.get(rafId);
32112
-
32113
- if (eId) {
32114
- window.cancelAnimationFrame(eId);
32115
- rafIdMap.delete(rafId);
32116
- }
32117
- };
32118
32197
  // CONCATENATED MODULE: ./src/view/node/BaseNode.tsx
32119
32198
  function BaseNode_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { BaseNode_typeof = function _typeof(obj) { return typeof obj; }; } else { BaseNode_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return BaseNode_typeof(obj); }
32120
32199
 
@@ -32265,7 +32344,20 @@ var BaseNode_BaseNode = /*#__PURE__*/function (_Component) {
32265
32344
  y = y + _this.moveOffset.y; // 将x, y移动到grid上
32266
32345
 
32267
32346
  x = snapToGrid(x, gridSize);
32268
- y = snapToGrid(y, gridSize); // 取节点左上角和右下角,计算节点移动是否超出范围
32347
+ y = snapToGrid(y, gridSize);
32348
+
32349
+ if (!width || !height) {
32350
+ graphModel.moveNode2Coordinate(model.id, x, y);
32351
+ return;
32352
+ }
32353
+
32354
+ var isOutCanvas = x1 < 0 || y1 < 0 || x1 > width || y1 > height;
32355
+
32356
+ if (autoExpand && !stopMoveGraph && isOutCanvas) {
32357
+ // 鼠标超出画布后的拖动,不处理,而是让上一次setInterval持续滚动画布
32358
+ return;
32359
+ } // 取节点左上角和右下角,计算节点移动是否超出范围
32360
+
32269
32361
 
32270
32362
  var _transformModel$Canva3 = transformModel.CanvasPointToHtmlPoint([x - model.width / 2, y - model.height / 2]),
32271
32363
  _transformModel$Canva4 = BaseNode_slicedToArray(_transformModel$Canva3, 2),
@@ -35481,7 +35573,11 @@ var History_History = /*#__PURE__*/function () {
35481
35573
 
35482
35574
  this.eventCenter = graphModel.eventCenter;
35483
35575
  var NODE_ADD = EventType.NODE_ADD,
35576
+ NODE_DELETE = EventType.NODE_DELETE,
35577
+ NODE_DND_ADD = EventType.NODE_DND_ADD,
35484
35578
  EDGE_ADD = EventType.EDGE_ADD,
35579
+ EDGE_DELETE = EventType.EDGE_DELETE,
35580
+ TEXT_UPDATE = EventType.TEXT_UPDATE,
35485
35581
  NODE_DROP = EventType.NODE_DROP,
35486
35582
  EDGE_ADJUST = EventType.EDGE_ADJUST,
35487
35583
  SELECTION_DROP = EventType.SELECTION_DROP,
@@ -35492,7 +35588,7 @@ var History_History = /*#__PURE__*/function () {
35492
35588
  NODE_PROPERTY_UPDATE = EventType.NODE_PROPERTY_UPDATE,
35493
35589
  EDGE_PROPERTY_UPDATE = EventType.EDGE_PROPERTY_UPDATE,
35494
35590
  HISTORY_INSERT = EventType.HISTORY_INSERT;
35495
- var historyChangeKeys = "\n ".concat(NODE_ADD, ",\n ").concat(EDGE_ADD, ",\n ").concat(NODE_DROP, ",\n ").concat(EDGE_ADJUST, ",\n ").concat(SELECTION_DROP, ",\n ").concat(TEXT_DROP, ",\n ").concat(NODE_TEXT_UPDATE, ",\n ").concat(EDGE_TEXT_UPDATE, ",\n ").concat(GRAPH_RENDERED, "\n ");
35591
+ var historyChangeKeys = "\n ".concat(NODE_ADD, ",\n ").concat(EDGE_ADD, ",\n ").concat(NODE_DELETE, ",\n ").concat(NODE_DND_ADD, ",\n ").concat(EDGE_DELETE, ",\n ").concat(TEXT_UPDATE, ",\n ").concat(NODE_DROP, ",\n ").concat(EDGE_ADJUST, ",\n ").concat(SELECTION_DROP, ",\n ").concat(TEXT_DROP, ",\n ").concat(NODE_TEXT_UPDATE, ",\n ").concat(EDGE_TEXT_UPDATE, ",\n ").concat(GRAPH_RENDERED, "\n ");
35496
35592
 
35497
35593
  if (isPropertiesChangeHistory) {
35498
35594
  historyChangeKeys += ",".concat(NODE_PROPERTY_UPDATE, ",").concat(EDGE_PROPERTY_UPDATE);
@@ -36861,14 +36957,15 @@ var LogicFlow_LogicFlow = /*#__PURE__*/function () {
36861
36957
  }
36862
36958
  /**
36863
36959
  * 重新设置画布的宽高
36960
+ * 不传会自动计算画布宽高
36864
36961
  */
36865
36962
 
36866
36963
  }, {
36867
36964
  key: "resize",
36868
36965
  value: function resize(width, height) {
36869
- this.options.width = width !== null && width !== void 0 ? width : this.options.width;
36870
- this.options.height = height !== null && height !== void 0 ? height : this.options.height;
36871
36966
  this.graphModel.resize(width, height);
36967
+ this.options.width = this.graphModel.width;
36968
+ this.options.height = this.graphModel.height;
36872
36969
  }
36873
36970
  /**
36874
36971
  * 设置默认的边类型。