@logicflow/core 2.0.5 → 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.
- package/.turbo/turbo-build$colon$dev.log +10 -10
- package/.turbo/turbo-build.log +33 -33
- package/CHANGELOG.md +29 -0
- package/__tests__/algorithm/egde.test.ts +36 -23
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/algorithm/rotate.d.ts +31 -0
- package/es/algorithm/rotate.js +43 -0
- package/es/event/eventArgs.d.ts +23 -29
- package/es/model/BaseModel.d.ts +9 -0
- package/es/model/GraphModel.d.ts +17 -1
- package/es/model/GraphModel.js +37 -2
- package/es/model/edge/BaseEdgeModel.d.ts +1 -0
- package/es/model/node/BaseNodeModel.d.ts +7 -0
- package/es/model/node/BaseNodeModel.js +55 -2
- package/es/util/drag.d.ts +1 -0
- package/es/util/drag.js +11 -0
- package/es/util/graph.d.ts +1 -1
- package/es/util/resize.d.ts +23 -9
- package/es/util/resize.js +139 -16
- package/es/view/Anchor.js +6 -8
- package/es/view/Control.d.ts +1 -0
- package/es/view/Control.js +6 -1
- package/es/view/Graph.js +3 -15
- package/es/view/behavior/dnd.js +1 -0
- package/es/view/edge/BaseEdge.d.ts +3 -1
- package/es/view/edge/BaseEdge.js +8 -5
- package/es/view/overlay/BackgroundOverlay.d.ts +4 -14
- package/es/view/overlay/BackgroundOverlay.js +11 -1
- package/es/view/overlay/Grid.d.ts +4 -3
- package/es/view/overlay/Grid.js +8 -31
- package/es/view/text/BaseText.js +1 -1
- package/lib/algorithm/rotate.d.ts +31 -0
- package/lib/algorithm/rotate.js +50 -0
- package/lib/event/eventArgs.d.ts +23 -29
- package/lib/model/BaseModel.d.ts +9 -0
- package/lib/model/GraphModel.d.ts +17 -1
- package/lib/model/GraphModel.js +36 -1
- package/lib/model/edge/BaseEdgeModel.d.ts +1 -0
- package/lib/model/node/BaseNodeModel.d.ts +7 -0
- package/lib/model/node/BaseNodeModel.js +55 -2
- package/lib/util/drag.d.ts +1 -0
- package/lib/util/drag.js +11 -0
- package/lib/util/graph.d.ts +1 -1
- package/lib/util/resize.d.ts +23 -9
- package/lib/util/resize.js +141 -17
- package/lib/view/Anchor.js +6 -8
- package/lib/view/Control.d.ts +1 -0
- package/lib/view/Control.js +6 -1
- package/lib/view/Graph.js +3 -15
- package/lib/view/behavior/dnd.js +1 -0
- package/lib/view/edge/BaseEdge.d.ts +3 -1
- package/lib/view/edge/BaseEdge.js +8 -5
- package/lib/view/overlay/BackgroundOverlay.d.ts +4 -14
- package/lib/view/overlay/BackgroundOverlay.js +11 -1
- package/lib/view/overlay/Grid.d.ts +4 -3
- package/lib/view/overlay/Grid.js +8 -31
- package/lib/view/text/BaseText.js +1 -1
- package/package.json +1 -1
- package/src/algorithm/edge.ts +2 -4
- package/src/event/eventArgs.ts +23 -29
- package/src/model/BaseModel.ts +16 -0
- package/src/model/GraphModel.ts +25 -3
- package/src/model/edge/BaseEdgeModel.ts +1 -0
- package/src/model/node/BaseNodeModel.ts +33 -1
- package/src/model/node/HtmlNodeModel.ts +1 -1
- package/src/util/drag.ts +12 -0
- package/src/util/resize.ts +7 -1
- package/src/view/Anchor.tsx +7 -8
- package/src/view/Control.tsx +1 -1
- package/src/view/Graph.tsx +2 -3
- package/src/view/behavior/dnd.ts +1 -0
- package/src/view/edge/BaseEdge.tsx +8 -3
- package/src/view/overlay/Grid.tsx +13 -9
- package/src/view/text/BaseText.tsx +1 -1
- package/stats.html +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface SimplePoint {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 根据两个点获取中心点坐标
|
|
7
|
+
*/
|
|
8
|
+
export declare function getNewCenter(startPoint: SimplePoint, endPoint: SimplePoint): {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 旋转矩阵公式,可以获取某一个坐标旋转angle后的坐标
|
|
14
|
+
* @param p 当前坐标
|
|
15
|
+
* @param center 旋转中心
|
|
16
|
+
* @param angle 旋转角度(不是弧度)
|
|
17
|
+
*/
|
|
18
|
+
export declare function calculatePointAfterRotateAngle(p: SimplePoint, center: SimplePoint, angle: number): {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 角度转弧度
|
|
24
|
+
* @param angle 角度
|
|
25
|
+
*/
|
|
26
|
+
export declare function angleToRadian(angle: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* 弧度转角度
|
|
29
|
+
* @param radian 弧度
|
|
30
|
+
*/
|
|
31
|
+
export declare function radianToAngle(radian: number): number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据两个点获取中心点坐标
|
|
3
|
+
*/
|
|
4
|
+
export function getNewCenter(startPoint, endPoint) {
|
|
5
|
+
var x1 = startPoint.x, y1 = startPoint.y;
|
|
6
|
+
var x2 = endPoint.x, y2 = endPoint.y;
|
|
7
|
+
var newCenter = {
|
|
8
|
+
x: x1 + (x2 - x1) / 2,
|
|
9
|
+
y: y1 + (y2 - y1) / 2,
|
|
10
|
+
};
|
|
11
|
+
return newCenter;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 旋转矩阵公式,可以获取某一个坐标旋转angle后的坐标
|
|
15
|
+
* @param p 当前坐标
|
|
16
|
+
* @param center 旋转中心
|
|
17
|
+
* @param angle 旋转角度(不是弧度)
|
|
18
|
+
*/
|
|
19
|
+
export function calculatePointAfterRotateAngle(p, center, angle) {
|
|
20
|
+
var radian = angleToRadian(angle);
|
|
21
|
+
var dx = p.x - center.x;
|
|
22
|
+
var dy = p.y - center.y;
|
|
23
|
+
var x = dx * Math.cos(radian) - dy * Math.sin(radian) + center.x;
|
|
24
|
+
var y = dx * Math.sin(radian) + dy * Math.cos(radian) + center.y;
|
|
25
|
+
return {
|
|
26
|
+
x: x,
|
|
27
|
+
y: y,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 角度转弧度
|
|
32
|
+
* @param angle 角度
|
|
33
|
+
*/
|
|
34
|
+
export function angleToRadian(angle) {
|
|
35
|
+
return (angle * Math.PI) / 180;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 弧度转角度
|
|
39
|
+
* @param radian 弧度
|
|
40
|
+
*/
|
|
41
|
+
export function radianToAngle(radian) {
|
|
42
|
+
return (radian / Math.PI) * 180;
|
|
43
|
+
}
|
package/es/event/eventArgs.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ interface NodeEventArgs {
|
|
|
105
105
|
/**
|
|
106
106
|
* 拖拽外部拖入节点
|
|
107
107
|
*/
|
|
108
|
-
'node:dnd-drag': NodeEventArgsPick<'data'>;
|
|
108
|
+
'node:dnd-drag': NodeEventArgsPick<'data' | 'e'>;
|
|
109
109
|
/**
|
|
110
110
|
* 开始拖拽节点
|
|
111
111
|
*/
|
|
@@ -130,6 +130,27 @@ interface NodeEventArgs {
|
|
|
130
130
|
* 节点缩放
|
|
131
131
|
*/
|
|
132
132
|
'node:resize': NodeEventArgsPick<'preData' | 'data' | 'model' | 'deltaX' | 'deltaY' | 'index'>;
|
|
133
|
+
/**
|
|
134
|
+
* 元素的 properties 发生改变
|
|
135
|
+
*/
|
|
136
|
+
'node:properties-change': {
|
|
137
|
+
/**
|
|
138
|
+
* 元素的 id
|
|
139
|
+
*/
|
|
140
|
+
id: string;
|
|
141
|
+
/**
|
|
142
|
+
* 改变的 properties 的 key
|
|
143
|
+
*/
|
|
144
|
+
keys: string[];
|
|
145
|
+
/**
|
|
146
|
+
* 改变前的 properties
|
|
147
|
+
*/
|
|
148
|
+
preProperties: Record<string, any>;
|
|
149
|
+
/**
|
|
150
|
+
* 改变后的 properties
|
|
151
|
+
*/
|
|
152
|
+
properties: Record<string, any>;
|
|
153
|
+
};
|
|
133
154
|
}
|
|
134
155
|
type EdgeEventArgsPick<T extends 'data' | 'e' | 'position'> = Pick<{
|
|
135
156
|
/**
|
|
@@ -275,33 +296,6 @@ interface CommonEventArgs {
|
|
|
275
296
|
*/
|
|
276
297
|
position: ClientPosition;
|
|
277
298
|
};
|
|
278
|
-
/**
|
|
279
|
-
* 元素的 properties 发生改变
|
|
280
|
-
*/
|
|
281
|
-
'properties:change': {
|
|
282
|
-
data: {
|
|
283
|
-
/**
|
|
284
|
-
* 元素的 id
|
|
285
|
-
*/
|
|
286
|
-
id: string;
|
|
287
|
-
/**
|
|
288
|
-
* 元素的类型
|
|
289
|
-
*/
|
|
290
|
-
type: string;
|
|
291
|
-
/**
|
|
292
|
-
* 改变的 properties 的 key
|
|
293
|
-
*/
|
|
294
|
-
keys: string[];
|
|
295
|
-
/**
|
|
296
|
-
* 改变前的 properties
|
|
297
|
-
*/
|
|
298
|
-
preProperties: Record<string, any>;
|
|
299
|
-
/**
|
|
300
|
-
* 改变后的 properties
|
|
301
|
-
*/
|
|
302
|
-
properties: Record<string, any>;
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
299
|
/**
|
|
306
300
|
* 进行画布平移或缩放等变化操作时触发
|
|
307
301
|
*/
|
|
@@ -356,7 +350,7 @@ type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> = P
|
|
|
356
350
|
/**
|
|
357
351
|
* 通过拖动锚点连线添加的边的数据
|
|
358
352
|
*/
|
|
359
|
-
edgeModel
|
|
353
|
+
edgeModel?: BaseEdgeModel;
|
|
360
354
|
}, T>;
|
|
361
355
|
/**
|
|
362
356
|
* 锚点事件
|
package/es/model/BaseModel.d.ts
CHANGED
|
@@ -42,6 +42,15 @@ export declare namespace Model {
|
|
|
42
42
|
* deltaY: 移动的 Y 轴距离
|
|
43
43
|
*/
|
|
44
44
|
type NodeMoveRule = (model: BaseNodeModel, deltaX: number, deltaY: number) => boolean | IsAllowMove;
|
|
45
|
+
/**
|
|
46
|
+
* 限制节点resize规则
|
|
47
|
+
* model: 移动节点的 model
|
|
48
|
+
* deltaX: 中心点移动的 X 轴距离
|
|
49
|
+
* deltaY: 中心点移动的 Y 轴距离
|
|
50
|
+
* width: 中心点新的width
|
|
51
|
+
* height: 中心点新的height
|
|
52
|
+
*/
|
|
53
|
+
type NodeResizeRule = (model: BaseNodeModel, deltaX: number, deltaY: number, width: number, height: number) => boolean;
|
|
45
54
|
type AdjustEdgeStartAndEndParams = {
|
|
46
55
|
startPoint: LogicFlow.Point;
|
|
47
56
|
endPoint: LogicFlow.Point;
|
package/es/model/GraphModel.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ElementState, EventType, OverlapMode, TextMode } from '../constant';
|
|
|
3
3
|
import LogicFlow from '../LogicFlow';
|
|
4
4
|
import { Options as LFOptions } from '../options';
|
|
5
5
|
import EventEmitter from '../event/eventEmitter';
|
|
6
|
+
import { Grid } from '../view/overlay';
|
|
6
7
|
import PointTuple = LogicFlow.PointTuple;
|
|
7
8
|
import GraphData = LogicFlow.GraphData;
|
|
8
9
|
import NodeConfig = LogicFlow.NodeConfig;
|
|
@@ -16,6 +17,7 @@ export declare class GraphModel {
|
|
|
16
17
|
width: number;
|
|
17
18
|
height: number;
|
|
18
19
|
theme: LogicFlow.Theme;
|
|
20
|
+
grid: Grid.GridOptions;
|
|
19
21
|
readonly eventCenter: EventEmitter;
|
|
20
22
|
readonly modelMap: Map<string, LogicFlow.GraphElementCtor>;
|
|
21
23
|
/**
|
|
@@ -32,9 +34,14 @@ export declare class GraphModel {
|
|
|
32
34
|
elementsModelMap: Map<string, BaseNodeModel | BaseEdgeModel>;
|
|
33
35
|
/**
|
|
34
36
|
* 节点移动规则判断
|
|
35
|
-
*
|
|
37
|
+
* 在节点移动的时候,会触发此数组中的所有规则判断
|
|
36
38
|
*/
|
|
37
39
|
nodeMoveRules: Model.NodeMoveRule[];
|
|
40
|
+
/**
|
|
41
|
+
* 节点resize规则判断
|
|
42
|
+
* 在节点resize的时候,会触发此数组中的所有规则判断
|
|
43
|
+
*/
|
|
44
|
+
nodeResizeRules: Model.NodeResizeRule[];
|
|
38
45
|
/**
|
|
39
46
|
* 获取自定义连线轨迹
|
|
40
47
|
*/
|
|
@@ -330,6 +337,7 @@ export declare class GraphModel {
|
|
|
330
337
|
*
|
|
331
338
|
*/
|
|
332
339
|
addNodeMoveRules(fn: Model.NodeMoveRule): void;
|
|
340
|
+
addNodeResizeRules(fn: Model.NodeResizeRule): void;
|
|
333
341
|
/**
|
|
334
342
|
* 设置默认的边类型
|
|
335
343
|
* 也就是设置在节点直接有用户手动绘制的连线类型。
|
|
@@ -377,6 +385,14 @@ export declare class GraphModel {
|
|
|
377
385
|
* todo docs link
|
|
378
386
|
*/
|
|
379
387
|
setTheme(style: Partial<LogicFlow.Theme>): void;
|
|
388
|
+
/**
|
|
389
|
+
* 更新网格配置
|
|
390
|
+
*/
|
|
391
|
+
updateGridOptions(options: Partial<Grid.GridOptions>): void;
|
|
392
|
+
/**
|
|
393
|
+
* 更新网格配置
|
|
394
|
+
*/
|
|
395
|
+
updateBackgroundOptions(options: boolean | Partial<LFOptions.BackgroundConfig>): void;
|
|
380
396
|
/**
|
|
381
397
|
* 重新设置画布的宽高
|
|
382
398
|
*/
|
package/es/model/GraphModel.js
CHANGED
|
@@ -40,12 +40,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
40
40
|
}
|
|
41
41
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
42
42
|
};
|
|
43
|
-
import { find, forEach, map } from 'lodash-es';
|
|
43
|
+
import { find, forEach, map, merge } from 'lodash-es';
|
|
44
44
|
import { action, computed, observable } from 'mobx';
|
|
45
45
|
import { EditConfigModel, TransformModel, } from '.';
|
|
46
46
|
import { DEFAULT_VISIBLE_SPACE, ELEMENT_MAX_Z_INDEX, ElementState, ElementType, EventType, ModelType, OverlapMode, TextMode, } from '../constant';
|
|
47
47
|
import { createEdgeGenerator, createUuid, formatData, getClosestPointOfPolyline, getMinIndex, getNodeAnchorPosition, getNodeBBox, getZIndex, isPointInArea, setupAnimation, setupTheme, snapToGrid, updateTheme, } from '../util';
|
|
48
48
|
import EventEmitter from '../event/eventEmitter';
|
|
49
|
+
import { Grid } from '../view/overlay';
|
|
49
50
|
var GraphModel = /** @class */ (function () {
|
|
50
51
|
function GraphModel(options) {
|
|
51
52
|
// 维护所有节点和边类型对应的 model
|
|
@@ -58,9 +59,14 @@ var GraphModel = /** @class */ (function () {
|
|
|
58
59
|
this.elementsModelMap = new Map();
|
|
59
60
|
/**
|
|
60
61
|
* 节点移动规则判断
|
|
61
|
-
*
|
|
62
|
+
* 在节点移动的时候,会触发此数组中的所有规则判断
|
|
62
63
|
*/
|
|
63
64
|
this.nodeMoveRules = [];
|
|
65
|
+
/**
|
|
66
|
+
* 节点resize规则判断
|
|
67
|
+
* 在节点resize的时候,会触发此数组中的所有规则判断
|
|
68
|
+
*/
|
|
69
|
+
this.nodeResizeRules = [];
|
|
64
70
|
// 当前图上所有节点的model
|
|
65
71
|
this.nodes = [];
|
|
66
72
|
// 当前图上所有边的model
|
|
@@ -83,6 +89,7 @@ var GraphModel = /** @class */ (function () {
|
|
|
83
89
|
this.gridSize = grid.size || 1; // 默认 gridSize 设置为 1
|
|
84
90
|
}
|
|
85
91
|
this.theme = setupTheme(options.style);
|
|
92
|
+
this.grid = Grid.getGridOptions(grid !== null && grid !== void 0 ? grid : false);
|
|
86
93
|
this.edgeType = options.edgeType || 'polyline';
|
|
87
94
|
this.animation = setupAnimation(animation);
|
|
88
95
|
this.overlapMode = options.overlapMode || OverlapMode.DEFAULT;
|
|
@@ -1081,6 +1088,11 @@ var GraphModel = /** @class */ (function () {
|
|
|
1081
1088
|
this.nodeMoveRules.push(fn);
|
|
1082
1089
|
}
|
|
1083
1090
|
};
|
|
1091
|
+
GraphModel.prototype.addNodeResizeRules = function (fn) {
|
|
1092
|
+
if (!this.nodeResizeRules.includes(fn)) {
|
|
1093
|
+
this.nodeResizeRules.push(fn);
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1084
1096
|
/**
|
|
1085
1097
|
* 设置默认的边类型
|
|
1086
1098
|
* 也就是设置在节点直接有用户手动绘制的连线类型。
|
|
@@ -1228,6 +1240,26 @@ var GraphModel = /** @class */ (function () {
|
|
|
1228
1240
|
GraphModel.prototype.setTheme = function (style) {
|
|
1229
1241
|
this.theme = updateTheme(__assign(__assign({}, this.theme), style));
|
|
1230
1242
|
};
|
|
1243
|
+
/**
|
|
1244
|
+
* 更新网格配置
|
|
1245
|
+
*/
|
|
1246
|
+
GraphModel.prototype.updateGridOptions = function (options) {
|
|
1247
|
+
merge(this.grid, options);
|
|
1248
|
+
};
|
|
1249
|
+
/**
|
|
1250
|
+
* 更新网格配置
|
|
1251
|
+
*/
|
|
1252
|
+
GraphModel.prototype.updateBackgroundOptions = function (options) {
|
|
1253
|
+
if (typeof options === 'boolean') {
|
|
1254
|
+
this.background = options;
|
|
1255
|
+
}
|
|
1256
|
+
else if (typeof this.background === 'boolean') {
|
|
1257
|
+
this.background = options;
|
|
1258
|
+
}
|
|
1259
|
+
else {
|
|
1260
|
+
this.background = __assign(__assign({}, this.background), options);
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1231
1263
|
/**
|
|
1232
1264
|
* 重新设置画布的宽高
|
|
1233
1265
|
*/
|
|
@@ -1355,6 +1387,9 @@ var GraphModel = /** @class */ (function () {
|
|
|
1355
1387
|
__decorate([
|
|
1356
1388
|
observable
|
|
1357
1389
|
], GraphModel.prototype, "height", void 0);
|
|
1390
|
+
__decorate([
|
|
1391
|
+
observable
|
|
1392
|
+
], GraphModel.prototype, "grid", void 0);
|
|
1358
1393
|
__decorate([
|
|
1359
1394
|
observable
|
|
1360
1395
|
], GraphModel.prototype, "edgeType", void 0);
|
|
@@ -72,6 +72,7 @@ export declare class BaseNodeModel<P extends PropertiesType = PropertiesType> im
|
|
|
72
72
|
targetRules: Model.ConnectRule[];
|
|
73
73
|
sourceRules: Model.ConnectRule[];
|
|
74
74
|
moveRules: Model.NodeMoveRule[];
|
|
75
|
+
resizeRules: Model.NodeResizeRule[];
|
|
75
76
|
hasSetTargetRules: boolean;
|
|
76
77
|
hasSetSourceRules: boolean;
|
|
77
78
|
[propName: string]: any;
|
|
@@ -264,6 +265,12 @@ export declare class BaseNodeModel<P extends PropertiesType = PropertiesType> im
|
|
|
264
265
|
moveTo(x: number, y: number, isIgnoreRule?: boolean): boolean;
|
|
265
266
|
moveText(deltaX: number, deltaY: number): void;
|
|
266
267
|
updateText(value: string): void;
|
|
268
|
+
addNodeResizeRules(fn: Model.NodeResizeRule): void;
|
|
269
|
+
/**
|
|
270
|
+
* 内部方法
|
|
271
|
+
* 是否允许resize节点到新的位置
|
|
272
|
+
*/
|
|
273
|
+
isAllowResizeNode(deltaX: number, deltaY: number, width: number, height: number): boolean;
|
|
267
274
|
setSelected(flag?: boolean): void;
|
|
268
275
|
setHovered(flag?: boolean): void;
|
|
269
276
|
setIsShowAnchor(flag?: boolean): void;
|
|
@@ -95,6 +95,7 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
95
95
|
this.targetRules = [];
|
|
96
96
|
this.sourceRules = [];
|
|
97
97
|
this.moveRules = []; // 节点移动之前的hook
|
|
98
|
+
this.resizeRules = []; // 节点resize之前的hook
|
|
98
99
|
this.hasSetTargetRules = false; // 用来限制rules的重复值
|
|
99
100
|
this.hasSetSourceRules = false; // 用来限制rules的重复值
|
|
100
101
|
this.graphModel = graphModel;
|
|
@@ -240,7 +241,7 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
240
241
|
textConfig.draggable = text.draggable;
|
|
241
242
|
}
|
|
242
243
|
if (!isUndefined(text.editable)) {
|
|
243
|
-
textConfig.
|
|
244
|
+
textConfig.editable = text.editable;
|
|
244
245
|
}
|
|
245
246
|
}
|
|
246
247
|
}
|
|
@@ -252,6 +253,10 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
252
253
|
*/
|
|
253
254
|
BaseNodeModel.prototype.resize = function (resizeInfo) {
|
|
254
255
|
var width = resizeInfo.width, height = resizeInfo.height, deltaX = resizeInfo.deltaX, deltaY = resizeInfo.deltaY;
|
|
256
|
+
var isAllowResize = this.isAllowResizeNode(deltaX, deltaY, width, height);
|
|
257
|
+
if (!isAllowResize) {
|
|
258
|
+
return this.getData();
|
|
259
|
+
}
|
|
255
260
|
// 移动节点以及文本内容
|
|
256
261
|
this.move(deltaX / 2, deltaY / 2);
|
|
257
262
|
this.width = width;
|
|
@@ -274,6 +279,18 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
274
279
|
if (isObservable(properties)) {
|
|
275
280
|
properties = toJS(properties);
|
|
276
281
|
}
|
|
282
|
+
if (isNil(properties.width)) {
|
|
283
|
+
// resize()的时候会触发this.setProperties({width,height})
|
|
284
|
+
// 然后返回getData(),可以从properties拿到width
|
|
285
|
+
// 但是初始化如果没有在properties传入width,那么getData()就一直无法从properties拿到width
|
|
286
|
+
properties.width = this.width;
|
|
287
|
+
}
|
|
288
|
+
if (isNil(properties.height)) {
|
|
289
|
+
// resize()的时候会触发this.setProperties({width,height})
|
|
290
|
+
// 然后返回getData(),可以从properties拿到height
|
|
291
|
+
// 但是初始化如果没有在properties传入height,那么getData()就一直无法从properties拿到width
|
|
292
|
+
properties.height = this.height;
|
|
293
|
+
}
|
|
277
294
|
var data = {
|
|
278
295
|
id: this.id,
|
|
279
296
|
type: this.type,
|
|
@@ -606,6 +623,10 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
606
623
|
this.y = this.y + deltaY;
|
|
607
624
|
this.text && this.moveText(0, deltaY);
|
|
608
625
|
}
|
|
626
|
+
if (isAllowMoveX || isAllowMoveY) {
|
|
627
|
+
// 更新x和y的同时也要更新对应的transform旋转矩阵(依赖x、y)
|
|
628
|
+
this.rotate = this._rotate;
|
|
629
|
+
}
|
|
609
630
|
return isAllowMoveX || isAllowMoveY;
|
|
610
631
|
};
|
|
611
632
|
BaseNodeModel.prototype.getMoveDistance = function (deltaX, deltaY, isIgnoreRule) {
|
|
@@ -649,6 +670,35 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
649
670
|
BaseNodeModel.prototype.updateText = function (value) {
|
|
650
671
|
this.text = __assign(__assign({}, toJS(this.text)), { value: value });
|
|
651
672
|
};
|
|
673
|
+
BaseNodeModel.prototype.addNodeResizeRules = function (fn) {
|
|
674
|
+
if (!this.resizeRules.includes(fn)) {
|
|
675
|
+
this.resizeRules.push(fn);
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* 内部方法
|
|
680
|
+
* 是否允许resize节点到新的位置
|
|
681
|
+
*/
|
|
682
|
+
BaseNodeModel.prototype.isAllowResizeNode = function (deltaX, deltaY, width, height) {
|
|
683
|
+
var e_2, _a;
|
|
684
|
+
var rules = this.resizeRules.concat(this.graphModel.nodeResizeRules);
|
|
685
|
+
try {
|
|
686
|
+
for (var rules_2 = __values(rules), rules_2_1 = rules_2.next(); !rules_2_1.done; rules_2_1 = rules_2.next()) {
|
|
687
|
+
var rule = rules_2_1.value;
|
|
688
|
+
var r = rule(this, deltaX, deltaY, width, height);
|
|
689
|
+
if (!r)
|
|
690
|
+
return false;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
694
|
+
finally {
|
|
695
|
+
try {
|
|
696
|
+
if (rules_2_1 && !rules_2_1.done && (_a = rules_2.return)) _a.call(rules_2);
|
|
697
|
+
}
|
|
698
|
+
finally { if (e_2) throw e_2.error; }
|
|
699
|
+
}
|
|
700
|
+
return true;
|
|
701
|
+
};
|
|
652
702
|
BaseNodeModel.prototype.setSelected = function (flag) {
|
|
653
703
|
if (flag === void 0) { flag = true; }
|
|
654
704
|
this.isSelected = flag;
|
|
@@ -686,7 +736,7 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
686
736
|
var preProperties = toJS(this.properties);
|
|
687
737
|
this.properties = nextProperties;
|
|
688
738
|
this.setAttributes();
|
|
689
|
-
// 触发更新节点 properties
|
|
739
|
+
// 触发更新节点 node:properties-change 的事件
|
|
690
740
|
this.graphModel.eventCenter.emit(EventType.NODE_PROPERTIES_CHANGE, {
|
|
691
741
|
id: this.id,
|
|
692
742
|
keys: updateKeys,
|
|
@@ -839,6 +889,9 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
839
889
|
__decorate([
|
|
840
890
|
action
|
|
841
891
|
], BaseNodeModel.prototype, "updateText", null);
|
|
892
|
+
__decorate([
|
|
893
|
+
action
|
|
894
|
+
], BaseNodeModel.prototype, "addNodeResizeRules", null);
|
|
842
895
|
__decorate([
|
|
843
896
|
action
|
|
844
897
|
], BaseNodeModel.prototype, "setSelected", null);
|
package/es/util/drag.d.ts
CHANGED
package/es/util/drag.js
CHANGED
|
@@ -121,6 +121,17 @@ var StepDrag = /** @class */ (function () {
|
|
|
121
121
|
_this.onDragEnd({ event: undefined });
|
|
122
122
|
_this.isDragging = false;
|
|
123
123
|
};
|
|
124
|
+
this.destroy = function () {
|
|
125
|
+
if (_this.isStartDragging) {
|
|
126
|
+
// https://github.com/didi/LogicFlow/issues/1934
|
|
127
|
+
// https://github.com/didi/LogicFlow/issues/1926
|
|
128
|
+
// cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算
|
|
129
|
+
// 我们的本意是为了防止mousemove和mouseup没有及时被移除
|
|
130
|
+
// 因此这里增加if(this.isStartDragging)的判断,isStartDragging=true代表没有触发handleMouseUp(),此时监听还没被移除
|
|
131
|
+
// 在拖拽情况下(isStartDragging=true),此时注册了监听,在组件突然销毁时,强制触发cancelDrag进行监听事件的移除
|
|
132
|
+
_this.cancelDrag();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
124
135
|
this.onDragStart = onDragStart;
|
|
125
136
|
this.onDragging = onDragging;
|
|
126
137
|
this.onDragEnd = onDragEnd;
|
package/es/util/graph.d.ts
CHANGED
package/es/util/resize.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ResizeControl, ResizeControlIndex } from '../view/Control';
|
|
|
2
2
|
import { BaseNodeModel, GraphModel } from '../model';
|
|
3
3
|
import ResizeInfo = ResizeControl.ResizeInfo;
|
|
4
4
|
import ResizeNodeData = ResizeControl.ResizeNodeData;
|
|
5
|
+
import type { SimplePoint } from '../algorithm/rotate';
|
|
5
6
|
/**
|
|
6
7
|
* 计算 Control 拖动后,节点的高度信息
|
|
7
8
|
* @param index
|
|
@@ -10,11 +11,23 @@ import ResizeNodeData = ResizeControl.ResizeNodeData;
|
|
|
10
11
|
* @param freezeWidth
|
|
11
12
|
* @param freezeHeight
|
|
12
13
|
*/
|
|
13
|
-
export declare const recalcResizeInfo: (index: ResizeControlIndex, resizeInfo: ResizeInfo, pct
|
|
14
|
+
export declare const recalcResizeInfo: (index: ResizeControlIndex, resizeInfo: ResizeInfo, pct: number | undefined, freezeWidth: boolean | undefined, freezeHeight: boolean | undefined, rotate: number | undefined, controlX: number | undefined, controlY: number | undefined, oldCenterX: number, oldCenterY: number) => ResizeInfo;
|
|
14
15
|
export declare const updateEdgePointByAnchors: (nodeModel: BaseNodeModel, graphModel: GraphModel) => void;
|
|
15
16
|
export declare const triggerResizeEvent: (preNodeData: ResizeNodeData, curNodeData: ResizeNodeData, deltaX: number, deltaY: number, index: number, nodeModel: BaseNodeModel, graphModel: GraphModel) => void;
|
|
17
|
+
export type IHandleResizeParams = {
|
|
18
|
+
x?: number;
|
|
19
|
+
y?: number;
|
|
20
|
+
deltaX: number;
|
|
21
|
+
deltaY: number;
|
|
22
|
+
index: ResizeControlIndex;
|
|
23
|
+
nodeModel: BaseNodeModel;
|
|
24
|
+
graphModel: GraphModel;
|
|
25
|
+
cancelCallback?: () => void;
|
|
26
|
+
};
|
|
16
27
|
/**
|
|
17
28
|
* 处理节点的 resize 事件,提出来放到 utils 中,方便在外面(extension)中使用
|
|
29
|
+
* @param x
|
|
30
|
+
* @param y
|
|
18
31
|
* @param deltaX
|
|
19
32
|
* @param deltaY
|
|
20
33
|
* @param index
|
|
@@ -22,11 +35,12 @@ export declare const triggerResizeEvent: (preNodeData: ResizeNodeData, curNodeDa
|
|
|
22
35
|
* @param graphModel
|
|
23
36
|
* @param cancelCallback
|
|
24
37
|
*/
|
|
25
|
-
export declare const handleResize: ({ deltaX, deltaY, index, nodeModel, graphModel, cancelCallback, }:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
38
|
+
export declare const handleResize: ({ x, y, deltaX, deltaY, index, nodeModel, graphModel, cancelCallback, }: IHandleResizeParams) => void;
|
|
39
|
+
export declare function calculateWidthAndHeight(startRotatedTouchControlPoint: SimplePoint, endRotatedTouchControlPoint: SimplePoint, oldCenter: SimplePoint, angle: number, freezeWidth: boolean | undefined, freezeHeight: boolean | undefined, oldWidth: number, oldHeight: number): {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
center: {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
};
|
|
46
|
+
};
|