@logicflow/core 1.2.0-alpha.13 → 1.2.0-alpha.16

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.12\"}");
11340
+ module.exports = JSON.parse("{\"a\":\"1.2.0-alpha.16\"}");
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',
@@ -24031,7 +24031,7 @@ var PolylineEdgeModel_PolylineEdgeModel = /*#__PURE__*/function (_BaseEdgeModel)
24031
24031
  var _inNode2 = isInNode(_startPosition, this.sourceNode);
24032
24032
 
24033
24033
  if (!_inNode2) {
24034
- // FIXME: 如果某一条边上没有任何锚点,会有问题
24034
+ // FIXME: 如果某一节点上没有任何锚点,会有问题
24035
24035
  var _anchorList3 = this.sourceNode.anchors;
24036
24036
  _draggingPointList = this.getDraggingPoints(direction, 'start', _startPosition, _anchorList3, _draggingPointList);
24037
24037
  }
@@ -24196,6 +24196,27 @@ var getVerticalPointOfLine = function getVerticalPointOfLine(config) {
24196
24196
 
24197
24197
  return pointPosition;
24198
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
+ };
24199
24220
  // CONCATENATED MODULE: ./src/util/edge.ts
24200
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; }
24201
24222
 
@@ -24253,6 +24274,7 @@ function edge_arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
24253
24274
 
24254
24275
 
24255
24276
 
24277
+
24256
24278
 
24257
24279
 
24258
24280
  /* 手动创建边时edge->edgeModel */
@@ -24992,14 +25014,58 @@ var edge_getBezierControlPoints = function getBezierControlPoints(_ref) {
24992
25014
  sourceNode = _ref.sourceNode,
24993
25015
  targetNode = _ref.targetNode,
24994
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;
24995
25019
  var sBBox = getNodeBBox(sourceNode);
24996
25020
  var tBBox = getNodeBBox(targetNode);
24997
25021
  var sExpendBBox = getExpandedBBox(sBBox, offset);
24998
25022
  var tExpendBBox = getExpandedBBox(tBBox, offset);
24999
25023
  var sDirection = edge_pointDirection(start, sourceNode);
25024
+ var tDirection = edge_pointDirection(end, targetNode); // 1. 避免两个节点连出的多个连线重合。
25025
+ // 2. 避免开始节点和结束节点方向相同时成为一个穿过节点的直线。
25026
+
25000
25027
  var sNext = edge_getExpandedBBoxPoint(sExpendBBox, start, sDirection);
25001
- var tDirection = edge_pointDirection(end, targetNode);
25002
- 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
+
25003
25069
  return {
25004
25070
  sNext: sNext,
25005
25071
  ePre: ePre
@@ -25649,6 +25715,8 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
25649
25715
  this.partial = options.partial;
25650
25716
  this.overlapMode = options.overlapMode || 0;
25651
25717
  this.idGenerator = idGenerator;
25718
+ this.width = options.width || this.rootEl.getBoundingClientRect().width;
25719
+ this.height = options.height || this.rootEl.getBoundingClientRect().height;
25652
25720
  }
25653
25721
 
25654
25722
  GraphModel_createClass(GraphModel, [{
@@ -25932,6 +26000,10 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
25932
26000
  value: function graphDataToModel(graphData) {
25933
26001
  var _this = this;
25934
26002
 
26003
+ if (!this.width || !this.height) {
26004
+ this.resize();
26005
+ }
26006
+
25935
26007
  this.nodes = lodash_es_map(graphData.nodes, function (node) {
25936
26008
  var Model = _this.getModel(node.type);
25937
26009
 
@@ -26906,8 +26978,12 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
26906
26978
  }, {
26907
26979
  key: "resize",
26908
26980
  value: function resize(width, height) {
26909
- this.width = width !== null && width !== void 0 ? width : this.width;
26910
- 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
+ }
26911
26987
  }
26912
26988
  /**
26913
26989
  * 清空画布
@@ -28968,7 +29044,7 @@ var BezierEdgeModel_BezierEdgeModel = /*#__PURE__*/function (_BaseEdgeModel) {
28968
29044
  BezierEdgeModel_createClass(BezierEdgeModel, [{
28969
29045
  key: "initEdgeData",
28970
29046
  value: function initEdgeData(data) {
28971
- this.offset = 100;
29047
+ this.offset = 0;
28972
29048
 
28973
29049
  BezierEdgeModel_get(BezierEdgeModel_getPrototypeOf(BezierEdgeModel.prototype), "initEdgeData", this).call(this, data);
28974
29050
  }
@@ -31270,6 +31346,39 @@ var SnaplineModel_SnaplineModel = /*#__PURE__*/function () {
31270
31346
 
31271
31347
 
31272
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
+ };
31273
31382
  // CONCATENATED MODULE: ./src/view/Anchor.tsx
31274
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); }
31275
31384
 
@@ -31344,6 +31453,7 @@ function Anchor_defineProperty(obj, key, value) { if (key in obj) { Object.defin
31344
31453
 
31345
31454
 
31346
31455
 
31456
+
31347
31457
  var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31348
31458
  Anchor_inherits(Anchor, _Component);
31349
31459
 
@@ -31424,7 +31534,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31424
31534
  y1 = _graphModel$getPointB3.y;
31425
31535
 
31426
31536
  if (_this.t) {
31427
- clearInterval(_this.t);
31537
+ cancelRaf(_this.t);
31428
31538
  }
31429
31539
 
31430
31540
  var nearBoundary = [];
@@ -31449,7 +31559,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31449
31559
  _this.moveAnchorEnd(x1, y1);
31450
31560
 
31451
31561
  if (nearBoundary.length > 0 && !stopMoveGraph && autoExpand) {
31452
- _this.t = setInterval(function () {
31562
+ _this.t = raf_createRaf(function () {
31453
31563
  var _nearBoundary = nearBoundary,
31454
31564
  _nearBoundary2 = Anchor_slicedToArray(_nearBoundary, 2),
31455
31565
  translateX = _nearBoundary2[0],
@@ -31466,7 +31576,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31466
31576
  });
31467
31577
 
31468
31578
  _this.moveAnchorEnd(endX - translateX, endY - translateY);
31469
- }, 50);
31579
+ });
31470
31580
  }
31471
31581
 
31472
31582
  eventCenter.emit(EventType.ANCHOR_DRAG, {
@@ -32084,39 +32194,6 @@ var BaseText_BaseText = /*#__PURE__*/function (_Component) {
32084
32194
 
32085
32195
 
32086
32196
  var isIe = window.navigator.userAgent.match(/MSIE|Trident/) !== null;
32087
- // CONCATENATED MODULE: ./src/util/raf.ts
32088
-
32089
-
32090
-
32091
-
32092
-
32093
-
32094
- var rafIdMap = new Map();
32095
- var raf_createRaf = function createRaf(callback) {
32096
- var rafId = uuid_createUuid();
32097
-
32098
- function run() {
32099
- callback();
32100
- var eId = rafIdMap.get(rafId);
32101
-
32102
- if (eId) {
32103
- var nId = window.requestAnimationFrame(run);
32104
- rafIdMap.set(rafId, nId);
32105
- }
32106
- }
32107
-
32108
- var id = window.requestAnimationFrame(run);
32109
- rafIdMap.set(rafId, id);
32110
- return rafId;
32111
- };
32112
- var cancelRaf = function cancelRaf(rafId) {
32113
- var eId = rafIdMap.get(rafId);
32114
-
32115
- if (eId) {
32116
- window.cancelAnimationFrame(eId);
32117
- rafIdMap.delete(rafId);
32118
- }
32119
- };
32120
32197
  // CONCATENATED MODULE: ./src/view/node/BaseNode.tsx
32121
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); }
32122
32199
 
@@ -32267,7 +32344,20 @@ var BaseNode_BaseNode = /*#__PURE__*/function (_Component) {
32267
32344
  y = y + _this.moveOffset.y; // 将x, y移动到grid上
32268
32345
 
32269
32346
  x = snapToGrid(x, gridSize);
32270
- 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
+
32271
32361
 
32272
32362
  var _transformModel$Canva3 = transformModel.CanvasPointToHtmlPoint([x - model.width / 2, y - model.height / 2]),
32273
32363
  _transformModel$Canva4 = BaseNode_slicedToArray(_transformModel$Canva3, 2),
@@ -36867,14 +36957,15 @@ var LogicFlow_LogicFlow = /*#__PURE__*/function () {
36867
36957
  }
36868
36958
  /**
36869
36959
  * 重新设置画布的宽高
36960
+ * 不传会自动计算画布宽高
36870
36961
  */
36871
36962
 
36872
36963
  }, {
36873
36964
  key: "resize",
36874
36965
  value: function resize(width, height) {
36875
- this.options.width = width !== null && width !== void 0 ? width : this.options.width;
36876
- this.options.height = height !== null && height !== void 0 ? height : this.options.height;
36877
36966
  this.graphModel.resize(width, height);
36967
+ this.options.width = this.graphModel.width;
36968
+ this.options.height = this.graphModel.height;
36878
36969
  }
36879
36970
  /**
36880
36971
  * 设置默认的边类型。