@logicflow/core 1.2.0-alpha.14 → 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.13\"}");
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',
@@ -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 */
@@ -25003,10 +25025,27 @@ var edge_getBezierControlPoints = function getBezierControlPoints(_ref) {
25003
25025
  // 2. 避免开始节点和结束节点方向相同时成为一个穿过节点的直线。
25004
25026
 
25005
25027
  var sNext = edge_getExpandedBBoxPoint(sExpendBBox, start, sDirection);
25006
- 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
+ } // 计算起点的调整点是否需要偏移
25007
25045
  // 如果起点的调整点方向和连线方向相反,则添加偏移量
25008
25046
  // 如果终点的调整点方向与连线方向
25009
25047
 
25048
+
25010
25049
  var randomNumberX = Math.ceil((Math.random() + 0.5) * offset);
25011
25050
  var randomNumberY = Math.ceil((Math.random() + 0.5) * offset); // 如果是调整点在节点水平方向,那么调整的点Y需要向着另一个节点的方向进行一定随机量的偏移。
25012
25051
  // 如果是调整点在节点垂直方向,那么调整的点X需要向着另一个节点的方向进行一定随机量的偏移。
@@ -25676,6 +25715,8 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
25676
25715
  this.partial = options.partial;
25677
25716
  this.overlapMode = options.overlapMode || 0;
25678
25717
  this.idGenerator = idGenerator;
25718
+ this.width = options.width || this.rootEl.getBoundingClientRect().width;
25719
+ this.height = options.height || this.rootEl.getBoundingClientRect().height;
25679
25720
  }
25680
25721
 
25681
25722
  GraphModel_createClass(GraphModel, [{
@@ -25959,6 +26000,10 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
25959
26000
  value: function graphDataToModel(graphData) {
25960
26001
  var _this = this;
25961
26002
 
26003
+ if (!this.width || !this.height) {
26004
+ this.resize();
26005
+ }
26006
+
25962
26007
  this.nodes = lodash_es_map(graphData.nodes, function (node) {
25963
26008
  var Model = _this.getModel(node.type);
25964
26009
 
@@ -26933,8 +26978,12 @@ var GraphModel_GraphModel = /*#__PURE__*/function () {
26933
26978
  }, {
26934
26979
  key: "resize",
26935
26980
  value: function resize(width, height) {
26936
- this.width = width !== null && width !== void 0 ? width : this.width;
26937
- 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
+ }
26938
26987
  }
26939
26988
  /**
26940
26989
  * 清空画布
@@ -31297,6 +31346,39 @@ var SnaplineModel_SnaplineModel = /*#__PURE__*/function () {
31297
31346
 
31298
31347
 
31299
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
+ };
31300
31382
  // CONCATENATED MODULE: ./src/view/Anchor.tsx
31301
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); }
31302
31384
 
@@ -31371,6 +31453,7 @@ function Anchor_defineProperty(obj, key, value) { if (key in obj) { Object.defin
31371
31453
 
31372
31454
 
31373
31455
 
31456
+
31374
31457
  var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31375
31458
  Anchor_inherits(Anchor, _Component);
31376
31459
 
@@ -31451,7 +31534,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31451
31534
  y1 = _graphModel$getPointB3.y;
31452
31535
 
31453
31536
  if (_this.t) {
31454
- clearInterval(_this.t);
31537
+ cancelRaf(_this.t);
31455
31538
  }
31456
31539
 
31457
31540
  var nearBoundary = [];
@@ -31476,7 +31559,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31476
31559
  _this.moveAnchorEnd(x1, y1);
31477
31560
 
31478
31561
  if (nearBoundary.length > 0 && !stopMoveGraph && autoExpand) {
31479
- _this.t = setInterval(function () {
31562
+ _this.t = raf_createRaf(function () {
31480
31563
  var _nearBoundary = nearBoundary,
31481
31564
  _nearBoundary2 = Anchor_slicedToArray(_nearBoundary, 2),
31482
31565
  translateX = _nearBoundary2[0],
@@ -31493,7 +31576,7 @@ var Anchor_Anchor = /*#__PURE__*/function (_Component) {
31493
31576
  });
31494
31577
 
31495
31578
  _this.moveAnchorEnd(endX - translateX, endY - translateY);
31496
- }, 50);
31579
+ });
31497
31580
  }
31498
31581
 
31499
31582
  eventCenter.emit(EventType.ANCHOR_DRAG, {
@@ -32111,39 +32194,6 @@ var BaseText_BaseText = /*#__PURE__*/function (_Component) {
32111
32194
 
32112
32195
 
32113
32196
  var isIe = window.navigator.userAgent.match(/MSIE|Trident/) !== null;
32114
- // CONCATENATED MODULE: ./src/util/raf.ts
32115
-
32116
-
32117
-
32118
-
32119
-
32120
-
32121
- var rafIdMap = new Map();
32122
- var raf_createRaf = function createRaf(callback) {
32123
- var rafId = uuid_createUuid();
32124
-
32125
- function run() {
32126
- callback();
32127
- var eId = rafIdMap.get(rafId);
32128
-
32129
- if (eId) {
32130
- var nId = window.requestAnimationFrame(run);
32131
- rafIdMap.set(rafId, nId);
32132
- }
32133
- }
32134
-
32135
- var id = window.requestAnimationFrame(run);
32136
- rafIdMap.set(rafId, id);
32137
- return rafId;
32138
- };
32139
- var cancelRaf = function cancelRaf(rafId) {
32140
- var eId = rafIdMap.get(rafId);
32141
-
32142
- if (eId) {
32143
- window.cancelAnimationFrame(eId);
32144
- rafIdMap.delete(rafId);
32145
- }
32146
- };
32147
32197
  // CONCATENATED MODULE: ./src/view/node/BaseNode.tsx
32148
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); }
32149
32199
 
@@ -32294,7 +32344,20 @@ var BaseNode_BaseNode = /*#__PURE__*/function (_Component) {
32294
32344
  y = y + _this.moveOffset.y; // 将x, y移动到grid上
32295
32345
 
32296
32346
  x = snapToGrid(x, gridSize);
32297
- 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
+
32298
32361
 
32299
32362
  var _transformModel$Canva3 = transformModel.CanvasPointToHtmlPoint([x - model.width / 2, y - model.height / 2]),
32300
32363
  _transformModel$Canva4 = BaseNode_slicedToArray(_transformModel$Canva3, 2),
@@ -36894,14 +36957,15 @@ var LogicFlow_LogicFlow = /*#__PURE__*/function () {
36894
36957
  }
36895
36958
  /**
36896
36959
  * 重新设置画布的宽高
36960
+ * 不传会自动计算画布宽高
36897
36961
  */
36898
36962
 
36899
36963
  }, {
36900
36964
  key: "resize",
36901
36965
  value: function resize(width, height) {
36902
- this.options.width = width !== null && width !== void 0 ? width : this.options.width;
36903
- this.options.height = height !== null && height !== void 0 ? height : this.options.height;
36904
36966
  this.graphModel.resize(width, height);
36967
+ this.options.width = this.graphModel.width;
36968
+ this.options.height = this.graphModel.height;
36905
36969
  }
36906
36970
  /**
36907
36971
  * 设置默认的边类型。