@logicflow/core 2.0.10 → 2.0.12
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 +2 -2
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +24 -5
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.js +7 -0
- package/es/constant/index.d.ts +2 -0
- package/es/constant/index.js +2 -0
- package/es/event/eventArgs.d.ts +8 -0
- package/es/model/GraphModel.js +3 -0
- package/es/model/edge/BezierEdgeModel.js +5 -2
- package/es/model/edge/PolylineEdgeModel.js +5 -2
- package/es/model/node/BaseNodeModel.js +4 -0
- package/es/tool/index.js +2 -2
- package/es/util/node.d.ts +1 -1
- package/es/util/node.js +32 -16
- package/es/view/Anchor.js +15 -2
- package/es/view/Control.d.ts +1 -0
- package/es/view/Control.js +4 -0
- package/es/view/Graph.d.ts +3 -0
- package/es/view/Graph.js +7 -3
- package/es/view/node/BaseNode.js +1 -5
- package/es/view/overlay/ToolOverlay.d.ts +3 -1
- package/es/view/overlay/ToolOverlay.js +39 -2
- package/lib/LogicFlow.js +7 -0
- package/lib/constant/index.d.ts +2 -0
- package/lib/constant/index.js +2 -0
- package/lib/event/eventArgs.d.ts +8 -0
- package/lib/model/GraphModel.js +3 -0
- package/lib/model/edge/BezierEdgeModel.js +4 -1
- package/lib/model/edge/PolylineEdgeModel.js +4 -1
- package/lib/model/node/BaseNodeModel.js +4 -0
- package/lib/tool/index.js +2 -2
- package/lib/util/node.d.ts +1 -1
- package/lib/util/node.js +32 -16
- package/lib/view/Anchor.js +15 -2
- package/lib/view/Control.d.ts +1 -0
- package/lib/view/Control.js +4 -0
- package/lib/view/Graph.d.ts +3 -0
- package/lib/view/Graph.js +6 -2
- package/lib/view/node/BaseNode.js +0 -4
- package/lib/view/overlay/ToolOverlay.d.ts +3 -1
- package/lib/view/overlay/ToolOverlay.js +39 -2
- package/package.json +1 -1
- package/src/LogicFlow.tsx +6 -0
- package/src/constant/index.ts +2 -0
- package/src/event/eventArgs.ts +8 -0
- package/src/model/GraphModel.ts +1 -1
- package/src/model/edge/BezierEdgeModel.ts +3 -3
- package/src/model/edge/PolylineEdgeModel.ts +3 -3
- package/src/model/node/BaseNodeModel.ts +4 -0
- package/src/tool/index.ts +2 -2
- package/src/util/node.ts +19 -18
- package/src/view/Anchor.tsx +15 -4
- package/src/view/Control.tsx +5 -0
- package/src/view/Graph.tsx +15 -3
- package/src/view/node/BaseNode.tsx +0 -6
- package/src/view/overlay/ToolOverlay.tsx +17 -2
- package/stats.html +1 -1
package/es/LogicFlow.js
CHANGED
|
@@ -1176,12 +1176,19 @@ var LogicFlow = /** @class */ (function () {
|
|
|
1176
1176
|
};
|
|
1177
1177
|
/** 销毁当前实例 */
|
|
1178
1178
|
LogicFlow.prototype.destroy = function () {
|
|
1179
|
+
var _a;
|
|
1179
1180
|
this.clearData();
|
|
1180
1181
|
render(null, this.container);
|
|
1181
1182
|
this.keyboard.destroy();
|
|
1182
1183
|
this.graphModel.destroy();
|
|
1183
1184
|
this.tool.destroy();
|
|
1184
1185
|
this.history.destroy();
|
|
1186
|
+
for (var extensionName in this.extension) {
|
|
1187
|
+
var extensionInstance = this.extension[extensionName];
|
|
1188
|
+
if ('destroy' in extensionInstance) {
|
|
1189
|
+
(_a = extensionInstance.destroy) === null || _a === void 0 ? void 0 : _a.call(extensionInstance);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1185
1192
|
};
|
|
1186
1193
|
// 全局配置的插件,所有的LogicFlow示例都会使用
|
|
1187
1194
|
LogicFlow.extensions = new Map();
|
package/es/constant/index.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export declare enum EventType {
|
|
|
64
64
|
EDGE_CONTEXTMENU = "edge:contextmenu",
|
|
65
65
|
EDGE_ADJUST = "edge:adjust",
|
|
66
66
|
EDGE_EXCHANGE_NODE = "edge:exchange-node",
|
|
67
|
+
ANCHOR_CLICK = "anchor:click",
|
|
68
|
+
ANCHOR_MOUSEDOWN = "anchor:mousedown",
|
|
67
69
|
ANCHOR_DRAGSTART = "anchor:dragstart",
|
|
68
70
|
ANCHOR_DRAG = "anchor:drag",
|
|
69
71
|
ANCHOR_DROP = "anchor:drop",
|
package/es/constant/index.js
CHANGED
|
@@ -72,6 +72,8 @@ export var EventType;
|
|
|
72
72
|
EventType["EDGE_ADJUST"] = "edge:adjust";
|
|
73
73
|
EventType["EDGE_EXCHANGE_NODE"] = "edge:exchange-node";
|
|
74
74
|
// Anchor events
|
|
75
|
+
EventType["ANCHOR_CLICK"] = "anchor:click";
|
|
76
|
+
EventType["ANCHOR_MOUSEDOWN"] = "anchor:mousedown";
|
|
75
77
|
EventType["ANCHOR_DRAGSTART"] = "anchor:dragstart";
|
|
76
78
|
EventType["ANCHOR_DRAG"] = "anchor:drag";
|
|
77
79
|
EventType["ANCHOR_DROP"] = "anchor:drop";
|
package/es/event/eventArgs.d.ts
CHANGED
|
@@ -382,6 +382,14 @@ type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> = P
|
|
|
382
382
|
* 锚点事件
|
|
383
383
|
*/
|
|
384
384
|
interface AnchorEventArgs {
|
|
385
|
+
/**
|
|
386
|
+
* anchor 锚点 click
|
|
387
|
+
*/
|
|
388
|
+
'anchor:click': AnchorEventArgsPick<'data' | 'e' | 'nodeModel'>;
|
|
389
|
+
/**
|
|
390
|
+
* anchor 锚点 mousedown
|
|
391
|
+
*/
|
|
392
|
+
'anchor:mousedown': AnchorEventArgsPick<'data' | 'e' | 'nodeModel'>;
|
|
385
393
|
/**
|
|
386
394
|
* 开始拖拽锚点
|
|
387
395
|
*/
|
package/es/model/GraphModel.js
CHANGED
|
@@ -1464,6 +1464,9 @@ var GraphModel = /** @class */ (function () {
|
|
|
1464
1464
|
__decorate([
|
|
1465
1465
|
observable
|
|
1466
1466
|
], GraphModel.prototype, "height", void 0);
|
|
1467
|
+
__decorate([
|
|
1468
|
+
observable
|
|
1469
|
+
], GraphModel.prototype, "theme", void 0);
|
|
1467
1470
|
__decorate([
|
|
1468
1471
|
observable
|
|
1469
1472
|
], GraphModel.prototype, "grid", void 0);
|
|
@@ -46,7 +46,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
46
46
|
}
|
|
47
47
|
return ar;
|
|
48
48
|
};
|
|
49
|
-
import { assign, cloneDeep } from 'lodash-es';
|
|
49
|
+
import { get, assign, cloneDeep } from 'lodash-es';
|
|
50
50
|
import { action, observable } from 'mobx';
|
|
51
51
|
import BaseEdgeModel from './BaseEdgeModel';
|
|
52
52
|
import { ModelType } from '../../constant';
|
|
@@ -62,7 +62,7 @@ var BezierEdgeModel = /** @class */ (function (_super) {
|
|
|
62
62
|
return _this;
|
|
63
63
|
}
|
|
64
64
|
BezierEdgeModel.prototype.initEdgeData = function (data) {
|
|
65
|
-
this.offset = 100;
|
|
65
|
+
this.offset = get(data, 'properties.offset', 100);
|
|
66
66
|
_super.prototype.initEdgeData.call(this, data);
|
|
67
67
|
};
|
|
68
68
|
BezierEdgeModel.prototype.getEdgeStyle = function () {
|
|
@@ -208,6 +208,9 @@ var BezierEdgeModel = /** @class */ (function (_super) {
|
|
|
208
208
|
this.pointsList = [startPoint, sNext, ePre, endPoint];
|
|
209
209
|
this.initPoints();
|
|
210
210
|
};
|
|
211
|
+
__decorate([
|
|
212
|
+
observable
|
|
213
|
+
], BezierEdgeModel.prototype, "offset", void 0);
|
|
211
214
|
__decorate([
|
|
212
215
|
observable
|
|
213
216
|
], BezierEdgeModel.prototype, "path", void 0);
|
|
@@ -55,7 +55,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
55
55
|
}
|
|
56
56
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
57
|
};
|
|
58
|
-
import { assign, cloneDeep } from 'lodash-es';
|
|
58
|
+
import { get, assign, cloneDeep } from 'lodash-es';
|
|
59
59
|
import { observable, action } from 'mobx';
|
|
60
60
|
import { BaseEdgeModel } from '.';
|
|
61
61
|
import { ModelType, SegmentDirection } from '../../constant';
|
|
@@ -69,7 +69,7 @@ var PolylineEdgeModel = /** @class */ (function (_super) {
|
|
|
69
69
|
return _this;
|
|
70
70
|
}
|
|
71
71
|
PolylineEdgeModel.prototype.initEdgeData = function (data) {
|
|
72
|
-
this.offset = 30;
|
|
72
|
+
this.offset = get(data, 'properties.offset', 30);
|
|
73
73
|
if (data.pointsList) {
|
|
74
74
|
this.pointsList = data.pointsList;
|
|
75
75
|
}
|
|
@@ -553,6 +553,9 @@ var PolylineEdgeModel = /** @class */ (function (_super) {
|
|
|
553
553
|
}, sourceNode, targetNode, this.offset || 0);
|
|
554
554
|
this.initPoints();
|
|
555
555
|
};
|
|
556
|
+
__decorate([
|
|
557
|
+
observable
|
|
558
|
+
], PolylineEdgeModel.prototype, "offset", void 0);
|
|
556
559
|
__decorate([
|
|
557
560
|
observable
|
|
558
561
|
], PolylineEdgeModel.prototype, "dbClickPosition", void 0);
|
|
@@ -645,6 +645,10 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
645
645
|
this.text && this.moveText(0, deltaY);
|
|
646
646
|
moveY = deltaY;
|
|
647
647
|
}
|
|
648
|
+
this.transform = new TranslateMatrix(-this.x, -this.y)
|
|
649
|
+
.rotate(this.rotate)
|
|
650
|
+
.translate(this.x, this.y)
|
|
651
|
+
.toString();
|
|
648
652
|
return [moveX, moveY];
|
|
649
653
|
};
|
|
650
654
|
BaseNodeModel.prototype.moveTo = function (x, y, isIgnoreRule) {
|
package/es/tool/index.js
CHANGED
|
@@ -50,7 +50,7 @@ var Tool = /** @class */ (function () {
|
|
|
50
50
|
this.toolMap.delete(name);
|
|
51
51
|
return true;
|
|
52
52
|
}
|
|
53
|
-
throw new Error(
|
|
53
|
+
throw new Error("\u7981\u7528\u5931\u8D25\uFF0C\u4E0D\u5B58\u5728\u540D\u4E3A ".concat(tool, " \u7684\u5DE5\u5177"));
|
|
54
54
|
};
|
|
55
55
|
Tool.prototype.enableTool = function (name) {
|
|
56
56
|
var tool = this.disabledToolMap.get(name);
|
|
@@ -59,7 +59,7 @@ var Tool = /** @class */ (function () {
|
|
|
59
59
|
this.disabledToolMap.delete(name);
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
62
|
-
throw new Error(
|
|
62
|
+
throw new Error("\u4E0D\u5B58\u5728\u540D\u4E3A ".concat(tool, " \u7684\u5DE5\u5177"));
|
|
63
63
|
};
|
|
64
64
|
Tool.prototype.getTools = function () {
|
|
65
65
|
return Array.from(this.toolMap.values());
|
package/es/util/node.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type NodeContaint = {
|
|
|
15
15
|
export declare const targetNodeInfo: (position: Point, graphModel: GraphModel) => NodeContaint;
|
|
16
16
|
export declare const getClosestAnchor: (position: Point, node: BaseNodeModel) => AnchorInfo;
|
|
17
17
|
export declare const distance: (x1: number, y1: number, x2: number, y2: number) => number;
|
|
18
|
-
export declare const isInNode: (position: Point, node: BaseNodeModel) => boolean;
|
|
18
|
+
export declare const isInNode: (position: Point, node: BaseNodeModel, offset?: number) => boolean;
|
|
19
19
|
export declare const isInNodeBbox: (position: Point, node: BaseNodeModel) => boolean;
|
|
20
20
|
export type NodeBBox = {
|
|
21
21
|
x: number;
|
package/es/util/node.js
CHANGED
|
@@ -9,10 +9,27 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
12
28
|
import { pick } from 'lodash-es';
|
|
13
29
|
import { getBytesLength } from './edge';
|
|
14
30
|
import { SegmentDirection } from '../constant';
|
|
15
31
|
import { isInSegment } from '../algorithm/edge';
|
|
32
|
+
import { Matrix } from './matrix';
|
|
16
33
|
/* 获取所有锚点 */
|
|
17
34
|
export var getAnchors = function (data) {
|
|
18
35
|
var anchors = data.anchors;
|
|
@@ -72,29 +89,28 @@ export var getClosestAnchor = function (position, node) {
|
|
|
72
89
|
/* 两点之间距离 */
|
|
73
90
|
export var distance = function (x1, y1, x2, y2) { return Math.hypot(x1 - x2, y1 - y2); };
|
|
74
91
|
/* 是否在某个节点内,手否进行连接,有offset控制粒度,与outline有关,可以优化 */
|
|
75
|
-
export var isInNode = function (position, node) {
|
|
92
|
+
export var isInNode = function (position, node, offset) {
|
|
93
|
+
if (offset === void 0) { offset = 0; }
|
|
76
94
|
var inNode = false;
|
|
77
|
-
var offset = 0;
|
|
78
95
|
var bBox = getNodeBBox(node);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
var _a = __read(new Matrix([position.x, position.y, 1])
|
|
97
|
+
.translate(-node.x, -node.y)
|
|
98
|
+
.rotate(-node.rotate)
|
|
99
|
+
.translate(node.x, node.y)[0], 2), x = _a[0], y = _a[1];
|
|
100
|
+
var reverseRotatedPosition = {
|
|
101
|
+
x: x,
|
|
102
|
+
y: y,
|
|
103
|
+
};
|
|
104
|
+
if (reverseRotatedPosition.x >= bBox.minX - offset &&
|
|
105
|
+
reverseRotatedPosition.x <= bBox.maxX + offset &&
|
|
106
|
+
reverseRotatedPosition.y >= bBox.minY - offset &&
|
|
107
|
+
reverseRotatedPosition.y <= bBox.maxY + offset) {
|
|
83
108
|
inNode = true;
|
|
84
109
|
}
|
|
85
110
|
return inNode;
|
|
86
111
|
};
|
|
87
112
|
export var isInNodeBbox = function (position, node) {
|
|
88
|
-
|
|
89
|
-
var offset = 5;
|
|
90
|
-
var bBox = getNodeBBox(node);
|
|
91
|
-
if (position.x >= bBox.minX - offset &&
|
|
92
|
-
position.x <= bBox.maxX + offset &&
|
|
93
|
-
position.y >= bBox.minY - offset &&
|
|
94
|
-
position.y <= bBox.maxY + offset) {
|
|
95
|
-
inNode = true;
|
|
96
|
-
}
|
|
97
|
-
return inNode;
|
|
113
|
+
return isInNode(position, node, 5);
|
|
98
114
|
};
|
|
99
115
|
/* 获取节点bbox */
|
|
100
116
|
export var getNodeBBox = function (node) {
|
package/es/view/Anchor.js
CHANGED
|
@@ -294,10 +294,23 @@ var Anchor = /** @class */ (function (_super) {
|
|
|
294
294
|
Anchor.prototype.render = function () {
|
|
295
295
|
var _this = this;
|
|
296
296
|
var _a = this.state, startX = _a.startX, startY = _a.startY, endX = _a.endX, endY = _a.endY;
|
|
297
|
-
var _b = this.props,
|
|
297
|
+
var _b = this.props, anchorData = _b.anchorData, edgeStyle = _b.edgeStyle, nodeModel = _b.nodeModel, graphModel = _b.graphModel;
|
|
298
|
+
var edgeAddable = anchorData.edgeAddable;
|
|
298
299
|
return (
|
|
299
300
|
// className="lf-anchor" 作为下载时,需要将锚点删除的依据,不要修改类名
|
|
300
|
-
_jsxs("g", { className: "lf-anchor", children: [_jsx("g", {
|
|
301
|
+
_jsxs("g", { className: "lf-anchor", children: [_jsx("g", { onClick: function (ev) {
|
|
302
|
+
ev.stopPropagation();
|
|
303
|
+
graphModel.eventCenter.emit(EventType.ANCHOR_CLICK, {
|
|
304
|
+
data: anchorData,
|
|
305
|
+
e: ev,
|
|
306
|
+
nodeModel: nodeModel,
|
|
307
|
+
});
|
|
308
|
+
}, onMouseDown: function (ev) {
|
|
309
|
+
graphModel.eventCenter.emit(EventType.ANCHOR_MOUSEDOWN, {
|
|
310
|
+
data: anchorData,
|
|
311
|
+
e: ev,
|
|
312
|
+
nodeModel: nodeModel,
|
|
313
|
+
});
|
|
301
314
|
if (edgeAddable !== false) {
|
|
302
315
|
_this.dragHandler.handleMouseDown(ev);
|
|
303
316
|
}
|
package/es/view/Control.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare class ResizeControl extends Component<IResizeControlProps, IResiz
|
|
|
43
43
|
*/
|
|
44
44
|
recalcResizeInfo: (index: ResizeControlIndex, resizeInfo: ResizeInfo, pct?: number, freezeWidth?: boolean, freezeHeight?: boolean) => ResizeInfo;
|
|
45
45
|
resizeNode: ({ deltaX, deltaY }: VectorData) => void;
|
|
46
|
+
onDragStart: () => void;
|
|
46
47
|
onDragging: ({ deltaX, deltaY }: IDragParams) => void;
|
|
47
48
|
onDragEnd: () => void;
|
|
48
49
|
render(): h.JSX.Element;
|
package/es/view/Control.js
CHANGED
|
@@ -280,6 +280,9 @@ var ResizeControl = /** @class */ (function (_super) {
|
|
|
280
280
|
// // 触发 resize 事件
|
|
281
281
|
// this.triggerResizeEvent(preNodeData, curNodeData, deltaX, deltaY, this.index, this.nodeModel)
|
|
282
282
|
};
|
|
283
|
+
_this.onDragStart = function () {
|
|
284
|
+
_this.graphModel.selectNodeById(_this.nodeModel.id);
|
|
285
|
+
};
|
|
283
286
|
_this.onDragging = function (_a) {
|
|
284
287
|
var deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
285
288
|
var transformModel = _this.graphModel.transformModel;
|
|
@@ -309,6 +312,7 @@ var ResizeControl = /** @class */ (function (_super) {
|
|
|
309
312
|
_this.graphModel = graphModel;
|
|
310
313
|
// 初始化拖拽工具
|
|
311
314
|
_this.dragHandler = new StepDrag({
|
|
315
|
+
onDragStart: _this.onDragStart,
|
|
312
316
|
onDragging: _this.onDragging,
|
|
313
317
|
onDragEnd: _this.onDragEnd,
|
|
314
318
|
step: graphModel.gridSize,
|
package/es/view/Graph.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Component, ComponentType } from 'preact/compat';
|
|
2
|
+
import { CanvasOverlay } from './overlay';
|
|
2
3
|
import DnD from './behavior/dnd';
|
|
3
4
|
import Tool from '../tool';
|
|
4
5
|
import { Options as LFOptions } from '../options';
|
|
@@ -12,6 +13,8 @@ type IGraphProps = {
|
|
|
12
13
|
graphModel: GraphModel;
|
|
13
14
|
};
|
|
14
15
|
declare class Graph extends Component<IGraphProps> {
|
|
16
|
+
canvasOverlayRef: import("preact").RefObject<CanvasOverlay>;
|
|
17
|
+
getCanvasOverlay: () => CanvasOverlay | null;
|
|
15
18
|
private handleResize;
|
|
16
19
|
private throttleResize;
|
|
17
20
|
componentDidMount(): void;
|
package/es/view/Graph.js
CHANGED
|
@@ -45,7 +45,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
47
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
48
|
-
import { Component } from 'preact/compat';
|
|
48
|
+
import { Component, createRef } from 'preact/compat';
|
|
49
49
|
import { map, throttle } from 'lodash-es';
|
|
50
50
|
import { CanvasOverlay, ToolOverlay, BackgroundOverlay, Grid, SnaplineOverlay, OutlineOverlay, BezierAdjustOverlay, ModificationOverlay, } from './overlay';
|
|
51
51
|
import { observer } from '..';
|
|
@@ -54,6 +54,10 @@ var Graph = /** @class */ (function (_super) {
|
|
|
54
54
|
__extends(Graph, _super);
|
|
55
55
|
function Graph() {
|
|
56
56
|
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
|
|
57
|
+
_this.canvasOverlayRef = createRef();
|
|
58
|
+
_this.getCanvasOverlay = function () {
|
|
59
|
+
return _this.canvasOverlayRef.current;
|
|
60
|
+
};
|
|
57
61
|
_this.handleResize = function () {
|
|
58
62
|
var _a = _this.props, graphModel = _a.graphModel, options = _a.options;
|
|
59
63
|
var width = graphModel.width, height = graphModel.height, isContainerWidth = graphModel.isContainerWidth, isContainerHeight = graphModel.isContainerHeight;
|
|
@@ -110,9 +114,9 @@ var Graph = /** @class */ (function (_super) {
|
|
|
110
114
|
}
|
|
111
115
|
var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel, background = graphModel.background;
|
|
112
116
|
var adjustEdge = editConfigModel.adjustEdge;
|
|
113
|
-
return (_jsxs("div", { className: "lf-graph", "flow-id": graphModel.flowId, style: style, children: [_jsxs(CanvasOverlay, { graphModel: graphModel, dnd: dnd, children: [_jsx("g", { className: "lf-base", children: map(graphModel.sortElements, function (nodeModel) {
|
|
117
|
+
return (_jsxs("div", { className: "lf-graph", "flow-id": graphModel.flowId, style: style, children: [_jsxs(CanvasOverlay, { ref: this.canvasOverlayRef, graphModel: graphModel, dnd: dnd, children: [_jsx("g", { className: "lf-base", children: map(graphModel.sortElements, function (nodeModel) {
|
|
114
118
|
return _this.getComponent(nodeModel, graphModel);
|
|
115
|
-
}) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), _jsxs(ModificationOverlay, { graphModel: graphModel, children: [_jsx(OutlineOverlay, { graphModel: graphModel }), adjustEdge ? _jsx(BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? (_jsx(SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), _jsx(ToolOverlay, { graphModel: graphModel, tool: tool }), background && _jsx(BackgroundOverlay, { background: background }), _jsx(Grid, { graphModel: graphModel })] }));
|
|
119
|
+
}) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), _jsxs(ModificationOverlay, { graphModel: graphModel, children: [_jsx(OutlineOverlay, { graphModel: graphModel }), adjustEdge ? _jsx(BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? (_jsx(SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), _jsx(ToolOverlay, { graphModel: graphModel, tool: tool, getCanvasOverlay: this.getCanvasOverlay }), background && _jsx(BackgroundOverlay, { background: background }), _jsx(Grid, { graphModel: graphModel })] }));
|
|
116
120
|
};
|
|
117
121
|
Graph = __decorate([
|
|
118
122
|
observer
|
package/es/view/node/BaseNode.js
CHANGED
|
@@ -58,7 +58,7 @@ import { map } from 'lodash-es';
|
|
|
58
58
|
import Anchor from '../Anchor';
|
|
59
59
|
import { BaseText } from '../text';
|
|
60
60
|
import { ElementState, EventType, TextMode } from '../../constant';
|
|
61
|
-
import { StepDrag, snapToGrid, isIe, isMultipleSelect, cancelRaf, createRaf,
|
|
61
|
+
import { StepDrag, snapToGrid, isIe, isMultipleSelect, cancelRaf, createRaf,
|
|
62
62
|
// RotateMatrix,
|
|
63
63
|
} from '../../util';
|
|
64
64
|
import RotateControlPoint from '../Rotate';
|
|
@@ -135,10 +135,6 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
135
135
|
if (_this.t) {
|
|
136
136
|
cancelRaf(_this.t);
|
|
137
137
|
}
|
|
138
|
-
model.transform = new TranslateMatrix(-x, -y)
|
|
139
|
-
.rotate(model.rotate)
|
|
140
|
-
.translate(x, y)
|
|
141
|
-
.toString();
|
|
142
138
|
var moveNodes = selectNodes.map(function (node) { return node.id; });
|
|
143
139
|
// 未被选中的节点也可以拖动
|
|
144
140
|
if (moveNodes.indexOf(model.id) === -1) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createElement as h, Component } from 'preact/compat';
|
|
2
|
-
import { OutlineOverlay } from '.';
|
|
2
|
+
import { CanvasOverlay, OutlineOverlay } from '.';
|
|
3
3
|
import { GraphModel } from '../../model';
|
|
4
4
|
import { Tool } from '../../tool';
|
|
5
5
|
type IProps = {
|
|
6
6
|
graphModel: GraphModel;
|
|
7
7
|
tool: Tool;
|
|
8
|
+
getCanvasOverlay: () => CanvasOverlay | null;
|
|
8
9
|
};
|
|
9
10
|
export declare class ToolOverlay extends Component<IProps> {
|
|
10
11
|
componentDidMount(): void;
|
|
@@ -14,6 +15,7 @@ export declare class ToolOverlay extends Component<IProps> {
|
|
|
14
15
|
*/
|
|
15
16
|
getTools(): import("preact").VNode<import("../..").IToolProps>[];
|
|
16
17
|
triggerToolRender(): void;
|
|
18
|
+
zoomHandler: (e: WheelEvent) => void;
|
|
17
19
|
render(): h.JSX.Element;
|
|
18
20
|
}
|
|
19
21
|
export default OutlineOverlay;
|
|
@@ -19,6 +19,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
19
19
|
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;
|
|
20
20
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
21
|
};
|
|
22
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
23
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
24
|
+
if (!m) return o;
|
|
25
|
+
var i = m.call(o), r, ar = [], e;
|
|
26
|
+
try {
|
|
27
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
28
|
+
}
|
|
29
|
+
catch (error) { e = { error: error }; }
|
|
30
|
+
finally {
|
|
31
|
+
try {
|
|
32
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
33
|
+
}
|
|
34
|
+
finally { if (e) throw e.error; }
|
|
35
|
+
}
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
22
47
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
23
48
|
import { createElement as h, Component } from 'preact/compat';
|
|
24
49
|
import { OutlineOverlay } from '.';
|
|
@@ -26,7 +51,13 @@ import { observer } from '../..';
|
|
|
26
51
|
var ToolOverlay = /** @class */ (function (_super) {
|
|
27
52
|
__extends(ToolOverlay, _super);
|
|
28
53
|
function ToolOverlay() {
|
|
29
|
-
|
|
54
|
+
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
|
|
55
|
+
_this.zoomHandler = function (e) {
|
|
56
|
+
var _a;
|
|
57
|
+
// TODO 是否应该使用 dispatchEvent 来触发事件
|
|
58
|
+
(_a = _this.props.getCanvasOverlay()) === null || _a === void 0 ? void 0 : _a.zoomHandler(e);
|
|
59
|
+
};
|
|
60
|
+
return _this;
|
|
30
61
|
}
|
|
31
62
|
// 在react严格模式下,useEffect会执行两次,但是在LogicFlow内部,则只会触发一次componentDidMount和componentDidUpdate。
|
|
32
63
|
// 其中第一次componentDidMount对应的graphModel为被丢弃的graphModel, 所以不应该生效。
|
|
@@ -64,7 +95,13 @@ var ToolOverlay = /** @class */ (function (_super) {
|
|
|
64
95
|
};
|
|
65
96
|
ToolOverlay.prototype.render = function () {
|
|
66
97
|
var graphModel = this.props.graphModel;
|
|
67
|
-
return (_jsx("div", { className: "lf-tool-overlay", id: "ToolOverlay_".concat(graphModel.flowId),
|
|
98
|
+
return (_jsx("div", { className: "lf-tool-overlay", id: "ToolOverlay_".concat(graphModel.flowId),
|
|
99
|
+
/*
|
|
100
|
+
* 默认情况下该容器设置了 pointer-events: none,不会触发这些事件
|
|
101
|
+
* 只会在容器取消 pointer-events: none 后触发,用于缩放、滚动画布等操作
|
|
102
|
+
* 目前只在 selection-select 插件中使用。为了能在元素内部进行框选,在开启选区后会关闭事件透传。需要手动触发事件
|
|
103
|
+
*/
|
|
104
|
+
onWheel: this.zoomHandler, children: this.getTools() }));
|
|
68
105
|
};
|
|
69
106
|
ToolOverlay = __decorate([
|
|
70
107
|
observer
|
package/lib/LogicFlow.js
CHANGED
|
@@ -1205,12 +1205,19 @@ var LogicFlow = /** @class */ (function () {
|
|
|
1205
1205
|
};
|
|
1206
1206
|
/** 销毁当前实例 */
|
|
1207
1207
|
LogicFlow.prototype.destroy = function () {
|
|
1208
|
+
var _a;
|
|
1208
1209
|
this.clearData();
|
|
1209
1210
|
(0, compat_1.render)(null, this.container);
|
|
1210
1211
|
this.keyboard.destroy();
|
|
1211
1212
|
this.graphModel.destroy();
|
|
1212
1213
|
this.tool.destroy();
|
|
1213
1214
|
this.history.destroy();
|
|
1215
|
+
for (var extensionName in this.extension) {
|
|
1216
|
+
var extensionInstance = this.extension[extensionName];
|
|
1217
|
+
if ('destroy' in extensionInstance) {
|
|
1218
|
+
(_a = extensionInstance.destroy) === null || _a === void 0 ? void 0 : _a.call(extensionInstance);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1214
1221
|
};
|
|
1215
1222
|
// 全局配置的插件,所有的LogicFlow示例都会使用
|
|
1216
1223
|
LogicFlow.extensions = new Map();
|
package/lib/constant/index.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export declare enum EventType {
|
|
|
64
64
|
EDGE_CONTEXTMENU = "edge:contextmenu",
|
|
65
65
|
EDGE_ADJUST = "edge:adjust",
|
|
66
66
|
EDGE_EXCHANGE_NODE = "edge:exchange-node",
|
|
67
|
+
ANCHOR_CLICK = "anchor:click",
|
|
68
|
+
ANCHOR_MOUSEDOWN = "anchor:mousedown",
|
|
67
69
|
ANCHOR_DRAGSTART = "anchor:dragstart",
|
|
68
70
|
ANCHOR_DRAG = "anchor:drag",
|
|
69
71
|
ANCHOR_DROP = "anchor:drop",
|
package/lib/constant/index.js
CHANGED
|
@@ -75,6 +75,8 @@ var EventType;
|
|
|
75
75
|
EventType["EDGE_ADJUST"] = "edge:adjust";
|
|
76
76
|
EventType["EDGE_EXCHANGE_NODE"] = "edge:exchange-node";
|
|
77
77
|
// Anchor events
|
|
78
|
+
EventType["ANCHOR_CLICK"] = "anchor:click";
|
|
79
|
+
EventType["ANCHOR_MOUSEDOWN"] = "anchor:mousedown";
|
|
78
80
|
EventType["ANCHOR_DRAGSTART"] = "anchor:dragstart";
|
|
79
81
|
EventType["ANCHOR_DRAG"] = "anchor:drag";
|
|
80
82
|
EventType["ANCHOR_DROP"] = "anchor:drop";
|
package/lib/event/eventArgs.d.ts
CHANGED
|
@@ -382,6 +382,14 @@ type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> = P
|
|
|
382
382
|
* 锚点事件
|
|
383
383
|
*/
|
|
384
384
|
interface AnchorEventArgs {
|
|
385
|
+
/**
|
|
386
|
+
* anchor 锚点 click
|
|
387
|
+
*/
|
|
388
|
+
'anchor:click': AnchorEventArgsPick<'data' | 'e' | 'nodeModel'>;
|
|
389
|
+
/**
|
|
390
|
+
* anchor 锚点 mousedown
|
|
391
|
+
*/
|
|
392
|
+
'anchor:mousedown': AnchorEventArgsPick<'data' | 'e' | 'nodeModel'>;
|
|
385
393
|
/**
|
|
386
394
|
* 开始拖拽锚点
|
|
387
395
|
*/
|
package/lib/model/GraphModel.js
CHANGED
|
@@ -1470,6 +1470,9 @@ var GraphModel = /** @class */ (function () {
|
|
|
1470
1470
|
__decorate([
|
|
1471
1471
|
mobx_1.observable
|
|
1472
1472
|
], GraphModel.prototype, "height", void 0);
|
|
1473
|
+
__decorate([
|
|
1474
|
+
mobx_1.observable
|
|
1475
|
+
], GraphModel.prototype, "theme", void 0);
|
|
1473
1476
|
__decorate([
|
|
1474
1477
|
mobx_1.observable
|
|
1475
1478
|
], GraphModel.prototype, "grid", void 0);
|
|
@@ -68,7 +68,7 @@ var BezierEdgeModel = /** @class */ (function (_super) {
|
|
|
68
68
|
return _this;
|
|
69
69
|
}
|
|
70
70
|
BezierEdgeModel.prototype.initEdgeData = function (data) {
|
|
71
|
-
this.offset = 100;
|
|
71
|
+
this.offset = (0, lodash_es_1.get)(data, 'properties.offset', 100);
|
|
72
72
|
_super.prototype.initEdgeData.call(this, data);
|
|
73
73
|
};
|
|
74
74
|
BezierEdgeModel.prototype.getEdgeStyle = function () {
|
|
@@ -214,6 +214,9 @@ var BezierEdgeModel = /** @class */ (function (_super) {
|
|
|
214
214
|
this.pointsList = [startPoint, sNext, ePre, endPoint];
|
|
215
215
|
this.initPoints();
|
|
216
216
|
};
|
|
217
|
+
__decorate([
|
|
218
|
+
mobx_1.observable
|
|
219
|
+
], BezierEdgeModel.prototype, "offset", void 0);
|
|
217
220
|
__decorate([
|
|
218
221
|
mobx_1.observable
|
|
219
222
|
], BezierEdgeModel.prototype, "path", void 0);
|
|
@@ -72,7 +72,7 @@ var PolylineEdgeModel = /** @class */ (function (_super) {
|
|
|
72
72
|
return _this;
|
|
73
73
|
}
|
|
74
74
|
PolylineEdgeModel.prototype.initEdgeData = function (data) {
|
|
75
|
-
this.offset = 30;
|
|
75
|
+
this.offset = (0, lodash_es_1.get)(data, 'properties.offset', 30);
|
|
76
76
|
if (data.pointsList) {
|
|
77
77
|
this.pointsList = data.pointsList;
|
|
78
78
|
}
|
|
@@ -556,6 +556,9 @@ var PolylineEdgeModel = /** @class */ (function (_super) {
|
|
|
556
556
|
}, sourceNode, targetNode, this.offset || 0);
|
|
557
557
|
this.initPoints();
|
|
558
558
|
};
|
|
559
|
+
__decorate([
|
|
560
|
+
mobx_1.observable
|
|
561
|
+
], PolylineEdgeModel.prototype, "offset", void 0);
|
|
559
562
|
__decorate([
|
|
560
563
|
mobx_1.observable
|
|
561
564
|
], PolylineEdgeModel.prototype, "dbClickPosition", void 0);
|
|
@@ -648,6 +648,10 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
648
648
|
this.text && this.moveText(0, deltaY);
|
|
649
649
|
moveY = deltaY;
|
|
650
650
|
}
|
|
651
|
+
this.transform = new util_1.TranslateMatrix(-this.x, -this.y)
|
|
652
|
+
.rotate(this.rotate)
|
|
653
|
+
.translate(this.x, this.y)
|
|
654
|
+
.toString();
|
|
651
655
|
return [moveX, moveY];
|
|
652
656
|
};
|
|
653
657
|
BaseNodeModel.prototype.moveTo = function (x, y, isIgnoreRule) {
|
package/lib/tool/index.js
CHANGED
|
@@ -56,7 +56,7 @@ var Tool = /** @class */ (function () {
|
|
|
56
56
|
this.toolMap.delete(name);
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
|
-
throw new Error(
|
|
59
|
+
throw new Error("\u7981\u7528\u5931\u8D25\uFF0C\u4E0D\u5B58\u5728\u540D\u4E3A ".concat(tool, " \u7684\u5DE5\u5177"));
|
|
60
60
|
};
|
|
61
61
|
Tool.prototype.enableTool = function (name) {
|
|
62
62
|
var tool = this.disabledToolMap.get(name);
|
|
@@ -65,7 +65,7 @@ var Tool = /** @class */ (function () {
|
|
|
65
65
|
this.disabledToolMap.delete(name);
|
|
66
66
|
return true;
|
|
67
67
|
}
|
|
68
|
-
throw new Error(
|
|
68
|
+
throw new Error("\u4E0D\u5B58\u5728\u540D\u4E3A ".concat(tool, " \u7684\u5DE5\u5177"));
|
|
69
69
|
};
|
|
70
70
|
Tool.prototype.getTools = function () {
|
|
71
71
|
return Array.from(this.toolMap.values());
|
package/lib/util/node.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type NodeContaint = {
|
|
|
15
15
|
export declare const targetNodeInfo: (position: Point, graphModel: GraphModel) => NodeContaint;
|
|
16
16
|
export declare const getClosestAnchor: (position: Point, node: BaseNodeModel) => AnchorInfo;
|
|
17
17
|
export declare const distance: (x1: number, y1: number, x2: number, y2: number) => number;
|
|
18
|
-
export declare const isInNode: (position: Point, node: BaseNodeModel) => boolean;
|
|
18
|
+
export declare const isInNode: (position: Point, node: BaseNodeModel, offset?: number) => boolean;
|
|
19
19
|
export declare const isInNodeBbox: (position: Point, node: BaseNodeModel) => boolean;
|
|
20
20
|
export type NodeBBox = {
|
|
21
21
|
x: number;
|