@logicflow/core 2.1.3 → 2.2.0
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 +15 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.d.ts +2 -1
- package/es/LogicFlow.js +4 -1
- package/es/constant/index.d.ts +3 -1
- package/es/constant/index.js +2 -0
- package/es/model/EditConfigModel.d.ts +3 -1
- package/es/model/EditConfigModel.js +5 -0
- package/es/model/GraphModel.d.ts +9 -1
- package/es/model/GraphModel.js +35 -8
- package/es/model/edge/BaseEdgeModel.d.ts +2 -1
- package/es/model/edge/BaseEdgeModel.js +29 -5
- package/es/model/node/BaseNodeModel.d.ts +2 -1
- package/es/model/node/BaseNodeModel.js +29 -5
- package/es/tool/MultipleSelectTool.d.ts +1 -1
- package/es/tool/MultipleSelectTool.js +1 -1
- package/es/util/drag.d.ts +4 -4
- package/es/util/drag.js +12 -6
- package/es/view/Anchor.d.ts +3 -3
- package/es/view/Anchor.js +30 -4
- package/es/view/Control.js +1 -1
- package/es/view/Rotate.js +1 -1
- package/es/view/behavior/dnd.d.ts +4 -8
- package/es/view/behavior/dnd.js +50 -14
- package/es/view/edge/AdjustPoint.d.ts +1 -1
- package/es/view/edge/AdjustPoint.js +1 -1
- package/es/view/edge/BaseEdge.d.ts +2 -1
- package/es/view/edge/BaseEdge.js +18 -1
- package/es/view/edge/PolylineEdge.d.ts +1 -1
- package/es/view/edge/PolylineEdge.js +1 -1
- package/es/view/node/BaseNode.d.ts +2 -1
- package/es/view/node/BaseNode.js +30 -3
- package/es/view/overlay/BezierAdjustOverlay.js +1 -1
- package/es/view/overlay/CanvasOverlay.d.ts +12 -1
- package/es/view/overlay/CanvasOverlay.js +94 -15
- package/es/view/text/BaseText.d.ts +1 -1
- package/es/view/text/BaseText.js +1 -1
- package/lib/LogicFlow.d.ts +2 -1
- package/lib/LogicFlow.js +3 -0
- package/lib/constant/index.d.ts +3 -1
- package/lib/constant/index.js +2 -0
- package/lib/model/EditConfigModel.d.ts +3 -1
- package/lib/model/EditConfigModel.js +5 -0
- package/lib/model/GraphModel.d.ts +9 -1
- package/lib/model/GraphModel.js +35 -8
- package/lib/model/edge/BaseEdgeModel.d.ts +2 -1
- package/lib/model/edge/BaseEdgeModel.js +29 -5
- package/lib/model/node/BaseNodeModel.d.ts +2 -1
- package/lib/model/node/BaseNodeModel.js +29 -5
- package/lib/tool/MultipleSelectTool.d.ts +1 -1
- package/lib/tool/MultipleSelectTool.js +1 -1
- package/lib/util/drag.d.ts +4 -4
- package/lib/util/drag.js +12 -6
- package/lib/view/Anchor.d.ts +3 -3
- package/lib/view/Anchor.js +30 -4
- package/lib/view/Control.js +1 -1
- package/lib/view/Rotate.js +1 -1
- package/lib/view/behavior/dnd.d.ts +4 -8
- package/lib/view/behavior/dnd.js +50 -14
- package/lib/view/edge/AdjustPoint.d.ts +1 -1
- package/lib/view/edge/AdjustPoint.js +1 -1
- package/lib/view/edge/BaseEdge.d.ts +2 -1
- package/lib/view/edge/BaseEdge.js +18 -1
- package/lib/view/edge/PolylineEdge.d.ts +1 -1
- package/lib/view/edge/PolylineEdge.js +1 -1
- package/lib/view/node/BaseNode.d.ts +2 -1
- package/lib/view/node/BaseNode.js +30 -3
- package/lib/view/overlay/BezierAdjustOverlay.js +1 -1
- package/lib/view/overlay/CanvasOverlay.d.ts +12 -1
- package/lib/view/overlay/CanvasOverlay.js +94 -15
- package/lib/view/text/BaseText.d.ts +1 -1
- package/lib/view/text/BaseText.js +1 -1
- package/package.json +1 -1
- package/src/LogicFlow.tsx +9 -1
- package/src/constant/index.ts +2 -0
- package/src/model/EditConfigModel.ts +3 -0
- package/src/model/GraphModel.ts +37 -11
- package/src/model/edge/BaseEdgeModel.ts +32 -5
- package/src/model/node/BaseNodeModel.ts +30 -5
- package/src/tool/MultipleSelectTool.tsx +2 -2
- package/src/util/drag.ts +16 -12
- package/src/view/Anchor.tsx +32 -6
- package/src/view/Control.tsx +1 -1
- package/src/view/Rotate.tsx +1 -1
- package/src/view/behavior/dnd.ts +55 -16
- package/src/view/edge/AdjustPoint.tsx +2 -2
- package/src/view/edge/BaseEdge.tsx +23 -3
- package/src/view/edge/PolylineEdge.tsx +2 -2
- package/src/view/node/BaseNode.tsx +30 -4
- package/src/view/overlay/BezierAdjustOverlay.tsx +1 -1
- package/src/view/overlay/CanvasOverlay.tsx +110 -4
- package/src/view/text/BaseText.tsx +5 -2
- package/stats.html +1 -1
|
@@ -152,10 +152,24 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
152
152
|
_this.handleMouseDown = function (e) {
|
|
153
153
|
e.stopPropagation();
|
|
154
154
|
_this.startTime = new Date().getTime();
|
|
155
|
+
if (_this.longPressTimer) {
|
|
156
|
+
clearTimeout(_this.longPressTimer);
|
|
157
|
+
}
|
|
158
|
+
if (e.pointerType === 'touch') {
|
|
159
|
+
_this.longPressTimer = window.setTimeout(function () {
|
|
160
|
+
if (!_this.props.model.isDragging) {
|
|
161
|
+
_this.handleContextMenu(e);
|
|
162
|
+
}
|
|
163
|
+
}, 500);
|
|
164
|
+
}
|
|
155
165
|
};
|
|
156
166
|
_this.handleMouseUp = function () {
|
|
157
167
|
var model = _this.props.model;
|
|
158
168
|
_this.mouseUpDrag = model.isDragging;
|
|
169
|
+
if (_this.longPressTimer) {
|
|
170
|
+
clearTimeout(_this.longPressTimer);
|
|
171
|
+
_this.longPressTimer = undefined;
|
|
172
|
+
}
|
|
159
173
|
};
|
|
160
174
|
/**
|
|
161
175
|
* 不支持重写
|
|
@@ -478,7 +492,10 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
478
492
|
isSelected && 'lf-edge-selected',
|
|
479
493
|
]
|
|
480
494
|
.filter(Boolean)
|
|
481
|
-
.join(' '),
|
|
495
|
+
.join(' '), style: {
|
|
496
|
+
touchAction: 'none',
|
|
497
|
+
WebkitTouchCallout: 'none',
|
|
498
|
+
}, onClick: this.handleClick, onContextMenu: this.handleContextMenu, onPointerDown: this.handleMouseDown, onPointerUp: this.handleMouseUp, onPointerCancel: this.handleMouseUp, onMouseOver: this.setHoverOn, onMouseEnter: this.setHoverOn, onMouseLeave: this.setHoverOff, onFocus: this.handleFocus, onBlur: this.handleBlur, children: [this.getShape(), this.getAppend(), this.getText(), this.getArrow()] }), isShowAdjustPoint && isSelected ? this.getAdjustPoints() : ''] }));
|
|
482
499
|
};
|
|
483
500
|
BaseEdge.isObserved = false;
|
|
484
501
|
return BaseEdge;
|
|
@@ -34,7 +34,7 @@ export declare class PolylineEdge extends BaseEdge<IPolylineEdgeProps> {
|
|
|
34
34
|
/**
|
|
35
35
|
* 不支持重写
|
|
36
36
|
*/
|
|
37
|
-
beforeDragStart: (e:
|
|
37
|
+
beforeDragStart: (e: PointerEvent, appendInfo: any) => void;
|
|
38
38
|
/**
|
|
39
39
|
* @overridable 支持重写, 此方法为获取边的形状,如果需要自定义边的形状,请重写此方法。
|
|
40
40
|
* @example https://docs.logic-flow.cn/docs/#/zh/guide/basic/edge?id=%e5%9f%ba%e4%ba%8e-react-%e7%bb%84%e4%bb%b6%e8%87%aa%e5%ae%9a%e4%b9%89%e8%be%b9
|
|
@@ -263,7 +263,7 @@ var PolylineEdge = /** @class */ (function (_super) {
|
|
|
263
263
|
}
|
|
264
264
|
appendInfo.direction = constant_1.SegmentDirection.HORIZONTAL;
|
|
265
265
|
}
|
|
266
|
-
append = ((0, jsx_runtime_1.jsx)("g", { className: this_1.isDragging ? 'lf-dragging' : 'lf-drag-able',
|
|
266
|
+
append = ((0, jsx_runtime_1.jsx)("g", { className: this_1.isDragging ? 'lf-dragging' : 'lf-drag-able', onPointerDown: function (e) { return _this.beforeDragStart(e, appendInfo); }, children: (0, jsx_runtime_1.jsx)("g", { className: className, children: this_1.getAppendShape(appendInfo) }) }));
|
|
267
267
|
}
|
|
268
268
|
LineAppendList.push(append);
|
|
269
269
|
};
|
|
@@ -19,6 +19,7 @@ export declare abstract class BaseNode<P extends IProps = IProps> extends Compon
|
|
|
19
19
|
mouseUpDrag?: boolean;
|
|
20
20
|
startTime?: number;
|
|
21
21
|
modelDisposer: IReactionDisposer;
|
|
22
|
+
longPressTimer?: number;
|
|
22
23
|
constructor(props: IProps);
|
|
23
24
|
componentWillUnmount(): void;
|
|
24
25
|
componentDidMount(): void;
|
|
@@ -37,7 +38,7 @@ export declare abstract class BaseNode<P extends IProps = IProps> extends Compon
|
|
|
37
38
|
handleMouseUp: () => void;
|
|
38
39
|
handleClick: (e: MouseEvent) => void;
|
|
39
40
|
handleContextMenu: (ev: MouseEvent) => void;
|
|
40
|
-
handleMouseDown: (ev:
|
|
41
|
+
handleMouseDown: (ev: PointerEvent) => void;
|
|
41
42
|
handleFocus: () => void;
|
|
42
43
|
handleBlur: () => void;
|
|
43
44
|
setHoverOn: (ev: MouseEvent) => void;
|
|
@@ -172,16 +172,28 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
172
172
|
_this.handleMouseUp = function () {
|
|
173
173
|
var model = _this.props.model;
|
|
174
174
|
_this.mouseUpDrag = model.isDragging;
|
|
175
|
+
if (_this.longPressTimer) {
|
|
176
|
+
clearTimeout(_this.longPressTimer);
|
|
177
|
+
_this.longPressTimer = undefined;
|
|
178
|
+
}
|
|
175
179
|
};
|
|
176
180
|
_this.handleClick = function (e) {
|
|
177
181
|
// 节点拖拽进画布之后,不触发click事件相关emit
|
|
178
182
|
// 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分
|
|
179
183
|
var isDragging = _this.mouseUpDrag === false;
|
|
184
|
+
var curTime = new Date().getTime();
|
|
180
185
|
if (!_this.startTime)
|
|
181
186
|
return;
|
|
187
|
+
var timeInterval = curTime - _this.startTime;
|
|
182
188
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
// 这里会有一种极端情况:当网格大小是1或者关闭网格吸附时,用触摸板点击节点会触发拖拽事件导致节点无法选中
|
|
190
|
+
// 当触摸板点击节点时,为了防止误触发拖拽导致节点无法选中,允许在非拖拽状态且时间间隔小于100ms时触发点击事件
|
|
191
|
+
if (!isDragging && timeInterval > 100)
|
|
192
|
+
return;
|
|
193
|
+
if (!isDragging) {
|
|
194
|
+
_this.onDragEnd();
|
|
195
|
+
_this.handleMouseUp();
|
|
196
|
+
}
|
|
185
197
|
// 节点数据,多为事件对象数据抛出
|
|
186
198
|
var nodeData = model.getData();
|
|
187
199
|
var position = graphModel.getPointByClient({
|
|
@@ -264,6 +276,16 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
264
276
|
if (editConfigModel.adjustNodePosition && model.draggable) {
|
|
265
277
|
_this.stepDrag && _this.stepDrag.handleMouseDown(ev);
|
|
266
278
|
}
|
|
279
|
+
if (_this.longPressTimer) {
|
|
280
|
+
clearTimeout(_this.longPressTimer);
|
|
281
|
+
}
|
|
282
|
+
if (ev.pointerType === 'touch') {
|
|
283
|
+
_this.longPressTimer = window.setTimeout(function () {
|
|
284
|
+
if (!_this.props.model.isDragging) {
|
|
285
|
+
_this.handleContextMenu(ev);
|
|
286
|
+
}
|
|
287
|
+
}, 500);
|
|
288
|
+
}
|
|
267
289
|
};
|
|
268
290
|
_this.handleFocus = function () {
|
|
269
291
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
@@ -272,6 +294,9 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
272
294
|
});
|
|
273
295
|
};
|
|
274
296
|
_this.handleBlur = function () {
|
|
297
|
+
// 当节点通过自定义锚点实现节点删除时,这里props会变成undefined,需兼容一下
|
|
298
|
+
if (!_this.props)
|
|
299
|
+
return;
|
|
275
300
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
276
301
|
graphModel.eventCenter.emit(constant_1.EventType.NODE_BLUR, {
|
|
277
302
|
data: model.getData(),
|
|
@@ -442,7 +467,9 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
442
467
|
if (adjustNodePosition && draggable) {
|
|
443
468
|
this.stepDrag.setStep(gridSize * SCALE_X);
|
|
444
469
|
}
|
|
445
|
-
nodeShape = ((0, jsx_runtime_1.jsx)("g", __assign({ className: "".concat(this.getStateClassName(), " ").concat(className),
|
|
470
|
+
nodeShape = ((0, jsx_runtime_1.jsx)("g", __assign({ className: "".concat(this.getStateClassName(), " ").concat(className), onPointerDown: this.handleMouseDown, onPointerUp: this.handleMouseUp, onClick: this.handleClick,
|
|
471
|
+
//因为移动端点击操作完成会按顺序触发enter、leave、click事件,所以会造成节点的闪烁,所以在这里没有统一状态为Pointer
|
|
472
|
+
onMouseEnter: this.setHoverOn, onMouseOver: this.setHoverOn, onMouseLeave: this.setHoverOff, onMouseOut: this.onMouseOut, onContextMenu: this.handleContextMenu, onFocus: this.handleFocus, onBlur: this.handleBlur }, restAttributes, { children: nodeShapeInner })));
|
|
446
473
|
}
|
|
447
474
|
return nodeShape;
|
|
448
475
|
};
|
|
@@ -91,7 +91,7 @@ var BezierAdjustAnchor = /** @class */ (function (_super) {
|
|
|
91
91
|
var x = position.x, y = position.y;
|
|
92
92
|
var bezierModel = this.props.bezierModel;
|
|
93
93
|
var adjustAnchor = bezierModel.getEdgeStyle().adjustAnchor;
|
|
94
|
-
return ((0, jsx_runtime_1.jsx)(shape_1.Circle, __assign({ className: "lf-bezier-adjust-anchor", x: x, y: y }, adjustAnchor, {
|
|
94
|
+
return ((0, jsx_runtime_1.jsx)(shape_1.Circle, __assign({ className: "lf-bezier-adjust-anchor", x: x, y: y }, adjustAnchor, { onPointerDown: function (ev) {
|
|
95
95
|
// if (edgeAddable !== false) {
|
|
96
96
|
_this.dragHandler.handleMouseDown(ev);
|
|
97
97
|
// }
|
|
@@ -13,13 +13,24 @@ export declare class CanvasOverlay extends Component<IProps, IState> {
|
|
|
13
13
|
stepDrag: StepDrag;
|
|
14
14
|
stepScrollX: number;
|
|
15
15
|
stepScrollY: number;
|
|
16
|
+
pointers: Map<number, {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
}>;
|
|
20
|
+
pinchStartDistance?: number;
|
|
21
|
+
pinchStartScale?: number;
|
|
22
|
+
pinchLastCenterX?: number;
|
|
23
|
+
pinchLastCenterY?: number;
|
|
24
|
+
longPressTimer?: number;
|
|
16
25
|
constructor(props: IProps);
|
|
17
26
|
onDragging: ({ deltaX, deltaY }: IDragParams) => void;
|
|
18
27
|
onDragEnd: () => void;
|
|
19
28
|
zoomHandler: (ev: WheelEvent) => void;
|
|
20
29
|
clickHandler: (ev: MouseEvent) => void;
|
|
21
30
|
handleContextMenu: (ev: MouseEvent) => void;
|
|
22
|
-
|
|
31
|
+
pointerDownHandler: (ev: PointerEvent) => void;
|
|
32
|
+
pointerMoveHandler: (ev: PointerEvent) => void;
|
|
33
|
+
pointerUpHandler: (ev: PointerEvent) => void;
|
|
23
34
|
render(): import("preact/compat").JSX.Element;
|
|
24
35
|
}
|
|
25
36
|
export default CanvasOverlay;
|
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
17
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
29
18
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
30
19
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -44,11 +33,16 @@ var CanvasOverlay = /** @class */ (function (_super) {
|
|
|
44
33
|
var _this = _super.call(this) || this;
|
|
45
34
|
_this.stepScrollX = 0;
|
|
46
35
|
_this.stepScrollY = 0;
|
|
36
|
+
_this.pointers = new Map();
|
|
47
37
|
// get InjectedProps() {
|
|
48
38
|
// return this.props as InjectedProps;
|
|
49
39
|
// }
|
|
50
40
|
_this.onDragging = function (_a) {
|
|
51
41
|
var deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
42
|
+
if (_this.longPressTimer) {
|
|
43
|
+
clearTimeout(_this.longPressTimer);
|
|
44
|
+
_this.longPressTimer = undefined;
|
|
45
|
+
}
|
|
52
46
|
_this.setState({
|
|
53
47
|
isDragging: true,
|
|
54
48
|
});
|
|
@@ -126,8 +120,36 @@ var CanvasOverlay = /** @class */ (function (_super) {
|
|
|
126
120
|
}
|
|
127
121
|
};
|
|
128
122
|
// 鼠标、触摸板 按下
|
|
129
|
-
_this.
|
|
123
|
+
_this.pointerDownHandler = function (ev) {
|
|
130
124
|
var _a = _this.props.graphModel, eventCenter = _a.eventCenter, editConfigModel = _a.editConfigModel, SCALE_X = _a.transformModel.SCALE_X, gridSize = _a.gridSize;
|
|
125
|
+
_this.pointers.set(ev.pointerId, { x: ev.clientX, y: ev.clientY });
|
|
126
|
+
if (_this.longPressTimer) {
|
|
127
|
+
clearTimeout(_this.longPressTimer);
|
|
128
|
+
}
|
|
129
|
+
if (ev.pointerType === 'touch') {
|
|
130
|
+
_this.longPressTimer = window.setTimeout(function () {
|
|
131
|
+
_this.handleContextMenu(ev);
|
|
132
|
+
}, 500);
|
|
133
|
+
}
|
|
134
|
+
// 检测双指触摸,初始化捏合缩放
|
|
135
|
+
if (_this.pointers.size === 2) {
|
|
136
|
+
var _b = _this.props.graphModel, transformModel = _b.transformModel, editConfigModel_1 = _b.editConfigModel;
|
|
137
|
+
// 记录两指当前位置用于计算初始距离
|
|
138
|
+
var pts = Array.from(_this.pointers.values());
|
|
139
|
+
var dx = pts[0].x - pts[1].x;
|
|
140
|
+
var dy = pts[0].y - pts[1].y;
|
|
141
|
+
var cx = (pts[0].x + pts[1].x) / 2;
|
|
142
|
+
var cy = (pts[0].y + pts[1].y) / 2;
|
|
143
|
+
// 记录捏合起始距离与当前缩放,后续按比例计算缩放
|
|
144
|
+
_this.pinchStartDistance = Math.hypot(dx, dy);
|
|
145
|
+
_this.pinchStartScale = transformModel.SCALE_X;
|
|
146
|
+
// 双指操作下取消画布拖拽,避免与捏合缩放冲突
|
|
147
|
+
_this.stepDrag.cancelDrag();
|
|
148
|
+
_this.pinchLastCenterX = cx;
|
|
149
|
+
_this.pinchLastCenterY = cy;
|
|
150
|
+
editConfigModel_1.updateEditConfig({ isPinching: true });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
131
153
|
var adjustEdge = editConfigModel.adjustEdge, adjustNodePosition = editConfigModel.adjustNodePosition, stopMoveGraph = editConfigModel.stopMoveGraph;
|
|
132
154
|
var target = ev.target;
|
|
133
155
|
var isFrozenElement = !adjustEdge && !adjustNodePosition;
|
|
@@ -143,6 +165,63 @@ var CanvasOverlay = /** @class */ (function (_super) {
|
|
|
143
165
|
_this.clickHandler(ev);
|
|
144
166
|
}
|
|
145
167
|
};
|
|
168
|
+
_this.pointerMoveHandler = function (ev) {
|
|
169
|
+
var _a;
|
|
170
|
+
// 记录当前指针位置(按 pointerId)
|
|
171
|
+
_this.pointers.set(ev.pointerId, { x: ev.clientX, y: ev.clientY });
|
|
172
|
+
// 当已记录初始捏合距离且存在两指时,执行捏合缩放
|
|
173
|
+
if (_this.pinchStartDistance && _this.pointers.size >= 2) {
|
|
174
|
+
var _b = _this.props, graphModel = _b.graphModel, _c = _b.graphModel, editConfigModel = _c.editConfigModel, transformModel = _c.transformModel;
|
|
175
|
+
if (editConfigModel.stopZoomGraph)
|
|
176
|
+
return;
|
|
177
|
+
// 取消触摸长按计时,避免捏合过程中误触发上下文菜单
|
|
178
|
+
if (_this.longPressTimer) {
|
|
179
|
+
clearTimeout(_this.longPressTimer);
|
|
180
|
+
}
|
|
181
|
+
// 计算两指间当前距离
|
|
182
|
+
var pts = Array.from(_this.pointers.values());
|
|
183
|
+
var dx = pts[0].x - pts[1].x;
|
|
184
|
+
var dy = pts[0].y - pts[1].y;
|
|
185
|
+
var dist = Math.hypot(dx, dy);
|
|
186
|
+
// 以初始缩放为基准,根据距离比例得到新的缩放比例
|
|
187
|
+
var scale = ((_a = _this.pinchStartScale) !== null && _a !== void 0 ? _a : transformModel.SCALE_X) *
|
|
188
|
+
(dist / _this.pinchStartDistance);
|
|
189
|
+
// 取两指中心作为缩放原点,并转换为画布坐标系
|
|
190
|
+
var cx = (pts[0].x + pts[1].x) / 2;
|
|
191
|
+
var cy = (pts[0].y + pts[1].y) / 2;
|
|
192
|
+
var pos = graphModel.getPointByClient({ x: cx, y: cy });
|
|
193
|
+
var _d = pos.canvasOverlayPosition, x = _d.x, y = _d.y;
|
|
194
|
+
transformModel.zoom(scale, [x, y]);
|
|
195
|
+
// 双指中心位移驱动画布平移,配合缩放实现捏合移动;
|
|
196
|
+
if (!editConfigModel.stopMoveGraph || editConfigModel.isPinching) {
|
|
197
|
+
var deltaX = _this.pinchLastCenterX === undefined ? 0 : cx - _this.pinchLastCenterX;
|
|
198
|
+
var deltaY = _this.pinchLastCenterY === undefined ? 0 : cy - _this.pinchLastCenterY;
|
|
199
|
+
transformModel.translate(deltaX, deltaY);
|
|
200
|
+
_this.pinchLastCenterX = cx;
|
|
201
|
+
_this.pinchLastCenterY = cy;
|
|
202
|
+
}
|
|
203
|
+
ev.preventDefault();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
_this.pointerUpHandler = function (ev) {
|
|
207
|
+
_this.pointers.delete(ev.pointerId);
|
|
208
|
+
if (_this.longPressTimer) {
|
|
209
|
+
clearTimeout(_this.longPressTimer);
|
|
210
|
+
_this.longPressTimer = undefined;
|
|
211
|
+
}
|
|
212
|
+
// 双指松开或仅剩一指:结束捏合手势并清理临时状态
|
|
213
|
+
if (_this.pointers.size < 2) {
|
|
214
|
+
// 清空捏合距离与缩放起始值
|
|
215
|
+
_this.pinchStartDistance = undefined;
|
|
216
|
+
_this.pinchStartScale = undefined;
|
|
217
|
+
// 清空上一帧的双指中心
|
|
218
|
+
_this.pinchLastCenterX = undefined;
|
|
219
|
+
_this.pinchLastCenterY = undefined;
|
|
220
|
+
var editConfigModel = _this.props.graphModel.editConfigModel;
|
|
221
|
+
// 标记退出捏合,框选等交互可恢复
|
|
222
|
+
editConfigModel.updateEditConfig({ isPinching: false });
|
|
223
|
+
}
|
|
224
|
+
};
|
|
146
225
|
var _a = props.graphModel, gridSize = _a.gridSize, eventCenter = _a.eventCenter;
|
|
147
226
|
_this.stepDrag = new util_1.StepDrag({
|
|
148
227
|
onDragging: _this.onDragging,
|
|
@@ -162,11 +241,11 @@ var CanvasOverlay = /** @class */ (function (_super) {
|
|
|
162
241
|
CanvasOverlay.prototype.render = function () {
|
|
163
242
|
var transformModel = this.props.graphModel.transformModel;
|
|
164
243
|
var transform = transformModel.getTransformStyle().transform;
|
|
165
|
-
var
|
|
244
|
+
var children = this.props.children;
|
|
166
245
|
var isDragging = this.state.isDragging;
|
|
167
|
-
return ((0, jsx_runtime_1.jsx)("svg",
|
|
246
|
+
return ((0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "100%", height: "100%", name: "canvas-overlay", onWheel: this.zoomHandler, onPointerDown: this.pointerDownHandler, onPointerMove: this.pointerMoveHandler, onPointerUp: this.pointerUpHandler, onPointerCancel: this.pointerUpHandler, onContextMenu: this.handleContextMenu, style: { touchAction: 'none', WebkitUserSelect: 'none' }, className: isDragging
|
|
168
247
|
? 'lf-canvas-overlay lf-dragging'
|
|
169
|
-
: 'lf-canvas-overlay lf-drag-able'
|
|
248
|
+
: 'lf-canvas-overlay lf-drag-able', children: (0, jsx_runtime_1.jsx)("g", { transform: transform, children: children }) }));
|
|
170
249
|
};
|
|
171
250
|
CanvasOverlay = __decorate([
|
|
172
251
|
__1.observer
|
|
@@ -14,7 +14,7 @@ export declare class BaseText<P extends IBaseTextProps, S extends IBaseTextState
|
|
|
14
14
|
stepperDrag: StepDrag;
|
|
15
15
|
constructor(props: P);
|
|
16
16
|
getShape(): h.JSX.Element | null;
|
|
17
|
-
mouseDownHandler: (e:
|
|
17
|
+
mouseDownHandler: (e: PointerEvent) => void;
|
|
18
18
|
onDragging: ({ deltaX, deltaY }: IDragParams) => void;
|
|
19
19
|
dbClickHandler: () => void;
|
|
20
20
|
render(): h.JSX.Element | undefined;
|
|
@@ -125,7 +125,7 @@ var BaseText = /** @class */ (function (_super) {
|
|
|
125
125
|
BaseText.prototype.render = function () {
|
|
126
126
|
var text = this.props.model.text;
|
|
127
127
|
if (text) {
|
|
128
|
-
return ((0, jsx_runtime_1.jsx)("g", {
|
|
128
|
+
return ((0, jsx_runtime_1.jsx)("g", { onPointerDown: this.mouseDownHandler, onDblClick: this.dbClickHandler, children: this.getShape() }));
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
return BaseText;
|
package/package.json
CHANGED
package/src/LogicFlow.tsx
CHANGED
|
@@ -26,7 +26,12 @@ import Tool from './tool'
|
|
|
26
26
|
import History from './history'
|
|
27
27
|
import Keyboard, { initDefaultShortcut } from './keyboard'
|
|
28
28
|
import { EventCallback, CallbackArgs, EventArgs } from './event/eventEmitter'
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
ElementType,
|
|
31
|
+
EventType,
|
|
32
|
+
OverlapMode,
|
|
33
|
+
SegmentDirection,
|
|
34
|
+
} from './constant'
|
|
30
35
|
import { Grid } from './view/overlay'
|
|
31
36
|
|
|
32
37
|
import Extension = LogicFlow.Extension
|
|
@@ -1088,6 +1093,9 @@ export class LogicFlow {
|
|
|
1088
1093
|
this.render({})
|
|
1089
1094
|
}
|
|
1090
1095
|
|
|
1096
|
+
setOverlapMode(mode: OverlapMode) {
|
|
1097
|
+
this.graphModel.setOverlapMode(mode)
|
|
1098
|
+
}
|
|
1091
1099
|
/*********************************************************
|
|
1092
1100
|
* LogicFlow Render方法
|
|
1093
1101
|
********************************************************/
|
package/src/constant/index.ts
CHANGED
|
@@ -125,6 +125,7 @@ export interface IEditConfigType {
|
|
|
125
125
|
edgeTextMode: TextMode
|
|
126
126
|
// 开启网格对齐
|
|
127
127
|
snapGrid: boolean
|
|
128
|
+
isPinching: boolean
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export type IConfigKeys = keyof IEditConfigType
|
|
@@ -186,6 +187,7 @@ const allKeys = [
|
|
|
186
187
|
'edgeTextMultiple', // 是否支持多个边文本
|
|
187
188
|
'nodeTextVertical', // 节点文本是否纵向显示
|
|
188
189
|
'edgeTextVertical', // 边文本是否纵向显示
|
|
190
|
+
'isPinching', //是否是双指捏合态
|
|
189
191
|
] as const
|
|
190
192
|
|
|
191
193
|
/**
|
|
@@ -202,6 +204,7 @@ export class EditConfigModel {
|
|
|
202
204
|
@observable stopMoveGraph = false
|
|
203
205
|
@observable stopScrollGraph = false
|
|
204
206
|
@observable snapGrid = false
|
|
207
|
+
@observable isPinching = false
|
|
205
208
|
/*********************************************************
|
|
206
209
|
* 文本相关配置(全局)
|
|
207
210
|
********************************************************/
|
package/src/model/GraphModel.ts
CHANGED
|
@@ -181,6 +181,7 @@ export class GraphModel {
|
|
|
181
181
|
this.animation = setupAnimation(animation)
|
|
182
182
|
this.overlapMode = options.overlapMode || OverlapMode.DEFAULT
|
|
183
183
|
|
|
184
|
+
this.isMiniMap = options.isMiniMap || false
|
|
184
185
|
this.width = options.width ?? this.rootEl.getBoundingClientRect().width
|
|
185
186
|
this.isContainerWidth = isNil(options.width)
|
|
186
187
|
this.height = options.height ?? this.rootEl.getBoundingClientRect().height
|
|
@@ -249,9 +250,11 @@ export class GraphModel {
|
|
|
249
250
|
* todo: 性能优化
|
|
250
251
|
*/
|
|
251
252
|
@computed get sortElements() {
|
|
252
|
-
const
|
|
253
|
-
(a, b) => a.zIndex - b.zIndex
|
|
254
|
-
|
|
253
|
+
const sortElement = (list) => {
|
|
254
|
+
return [...list].sort((a, b) => a.zIndex - b.zIndex)
|
|
255
|
+
}
|
|
256
|
+
// 默认情况下节点与边按照 zIndex 排序
|
|
257
|
+
const elements = sortElement([...this.nodes, ...this.edges])
|
|
255
258
|
|
|
256
259
|
// 只显示可见区域的节点和边
|
|
257
260
|
const visibleElements: (BaseNodeModel | BaseEdgeModel)[] = []
|
|
@@ -717,6 +720,22 @@ export class GraphModel {
|
|
|
717
720
|
}
|
|
718
721
|
}
|
|
719
722
|
|
|
723
|
+
/**
|
|
724
|
+
* 内部保留方法,请勿直接使用
|
|
725
|
+
*/
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* 设置重叠模式
|
|
729
|
+
* @param mode 重叠模式
|
|
730
|
+
*/
|
|
731
|
+
@action
|
|
732
|
+
setOverlapMode(mode: OverlapMode) {
|
|
733
|
+
this.overlapMode = mode
|
|
734
|
+
this.eventCenter.emit('overlap:change', {
|
|
735
|
+
overlapMode: mode,
|
|
736
|
+
})
|
|
737
|
+
}
|
|
738
|
+
|
|
720
739
|
/**
|
|
721
740
|
* 更新元素的文本模式
|
|
722
741
|
* @param mode
|
|
@@ -767,14 +786,19 @@ export class GraphModel {
|
|
|
767
786
|
toFront(id: string) {
|
|
768
787
|
const element = this.nodesMap[id]?.model || this.edgesMap[id]?.model
|
|
769
788
|
if (element) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
this.topElement = element
|
|
789
|
+
// 静态模式toFront不做处理
|
|
790
|
+
if (this.overlapMode === OverlapMode.STATIC) {
|
|
791
|
+
return
|
|
774
792
|
}
|
|
793
|
+
// 递增模式下,将需指定元素zIndex设置为当前最大zIndex + 1
|
|
775
794
|
if (this.overlapMode === OverlapMode.INCREASE) {
|
|
776
795
|
this.setElementZIndex(id, 'top')
|
|
796
|
+
return
|
|
777
797
|
}
|
|
798
|
+
// 默认模式(节点在上)和边在上模式下,将原置顶元素重新恢复原有层级,将需指定元素zIndex设置为最大zIndex
|
|
799
|
+
this.topElement?.setZIndex()
|
|
800
|
+
element.setZIndex(ELEMENT_MAX_Z_INDEX)
|
|
801
|
+
this.topElement = element
|
|
778
802
|
}
|
|
779
803
|
}
|
|
780
804
|
|
|
@@ -1224,12 +1248,15 @@ export class GraphModel {
|
|
|
1224
1248
|
clearSelectElements() {
|
|
1225
1249
|
this.selectElements.forEach((element) => {
|
|
1226
1250
|
element?.setSelected(false)
|
|
1251
|
+
element?.setHovered(false)
|
|
1227
1252
|
})
|
|
1228
1253
|
this.selectElements.clear()
|
|
1229
1254
|
/**
|
|
1230
1255
|
* 如果堆叠模式为默认模式,则将置顶元素重新恢复原有层级
|
|
1231
1256
|
*/
|
|
1232
|
-
if (
|
|
1257
|
+
if (
|
|
1258
|
+
[OverlapMode.DEFAULT, OverlapMode.EDGE_TOP].includes(this.overlapMode)
|
|
1259
|
+
) {
|
|
1233
1260
|
this.topElement?.setZIndex()
|
|
1234
1261
|
}
|
|
1235
1262
|
}
|
|
@@ -1584,7 +1611,7 @@ export class GraphModel {
|
|
|
1584
1611
|
}
|
|
1585
1612
|
|
|
1586
1613
|
/**
|
|
1587
|
-
*
|
|
1614
|
+
* 获取图形区域虚拟矩形的尺寸和中心坐标
|
|
1588
1615
|
* @returns
|
|
1589
1616
|
*/
|
|
1590
1617
|
getVirtualRectSize(): GraphModel.VirtualRectProps {
|
|
@@ -1611,7 +1638,7 @@ export class GraphModel {
|
|
|
1611
1638
|
const virtualRectWidth = maxX - minX || 0
|
|
1612
1639
|
const virtualRectHeight = maxY - minY || 0
|
|
1613
1640
|
|
|
1614
|
-
//
|
|
1641
|
+
// 获取虚拟矩形的中心坐标
|
|
1615
1642
|
const virtualRectCenterPositionX = minX + virtualRectWidth / 2
|
|
1616
1643
|
const virtualRectCenterPositionY = minY + virtualRectHeight / 2
|
|
1617
1644
|
|
|
@@ -1717,7 +1744,6 @@ export class GraphModel {
|
|
|
1717
1744
|
@action setPartial(partial: boolean): void {
|
|
1718
1745
|
this.partial = partial
|
|
1719
1746
|
}
|
|
1720
|
-
|
|
1721
1747
|
/** 销毁当前实例 */
|
|
1722
1748
|
destroy() {
|
|
1723
1749
|
try {
|
|
@@ -144,10 +144,8 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
144
144
|
} = this.graphModel
|
|
145
145
|
this.isShowAdjustPoint = adjustEdgeStartAndEnd
|
|
146
146
|
assign(this, pickEdgeConfig(data))
|
|
147
|
-
const { overlapMode } = this.graphModel
|
|
148
|
-
|
|
149
|
-
this.zIndex = data.zIndex || getZIndex()
|
|
150
|
-
}
|
|
147
|
+
const { overlapMode, eventCenter } = this.graphModel
|
|
148
|
+
this.updateZIndexByOverlap(overlapMode, data.zIndex || getZIndex())
|
|
151
149
|
// 设置边的 anchors,也就是边的两个端点
|
|
152
150
|
// 端点依赖于 edgeData 的 sourceNode 和 targetNode
|
|
153
151
|
this.setAnchors()
|
|
@@ -155,6 +153,11 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
155
153
|
this.initPoints()
|
|
156
154
|
// 文本位置依赖于边上的所有拐点
|
|
157
155
|
this.formatText(data)
|
|
156
|
+
|
|
157
|
+
eventCenter.on('overlap:change', (data) => {
|
|
158
|
+
const { overlapMode: newMode } = data
|
|
159
|
+
this.updateZIndexByOverlap(newMode, this.zIndex || getZIndex())
|
|
160
|
+
})
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
/**
|
|
@@ -397,7 +400,13 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
397
400
|
startPoint: assign({}, this.startPoint),
|
|
398
401
|
endPoint: assign({}, this.endPoint),
|
|
399
402
|
}
|
|
400
|
-
|
|
403
|
+
// 因为默认模式和边在上模式下,对节点的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
|
|
404
|
+
// 所以只在递增模式和静态模式下设置zIndex
|
|
405
|
+
if (
|
|
406
|
+
[OverlapMode.INCREASE, OverlapMode.STATIC].includes(
|
|
407
|
+
this.graphModel.overlapMode,
|
|
408
|
+
)
|
|
409
|
+
) {
|
|
401
410
|
data.zIndex = this.zIndex
|
|
402
411
|
}
|
|
403
412
|
const { x, y, value } = this.text
|
|
@@ -745,6 +754,24 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
745
754
|
this.updateStartPoint({ x: startPoint.x, y: startPoint.y })
|
|
746
755
|
this.updateEndPoint({ x: endPoint.x, y: endPoint.y })
|
|
747
756
|
}
|
|
757
|
+
|
|
758
|
+
// 堆叠模式变化时,更新zIndex
|
|
759
|
+
@action
|
|
760
|
+
updateZIndexByOverlap(overlapMode: OverlapMode, defaultZIndex) {
|
|
761
|
+
switch (overlapMode) {
|
|
762
|
+
case OverlapMode.DEFAULT:
|
|
763
|
+
this.zIndex = 0
|
|
764
|
+
break
|
|
765
|
+
case OverlapMode.EDGE_TOP:
|
|
766
|
+
this.zIndex = 1
|
|
767
|
+
break
|
|
768
|
+
case OverlapMode.INCREASE:
|
|
769
|
+
this.zIndex = defaultZIndex
|
|
770
|
+
break
|
|
771
|
+
default:
|
|
772
|
+
break
|
|
773
|
+
}
|
|
774
|
+
}
|
|
748
775
|
}
|
|
749
776
|
|
|
750
777
|
export default BaseEdgeModel
|
|
@@ -206,10 +206,12 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
206
206
|
// TODO: 确认 constructor 中赋值 properties 是否必要,此处将 NodeConfig 中所有属性赋值给 this,包括 rotate、rotatable,resizable 等
|
|
207
207
|
assign(this, pickNodeConfig(data))
|
|
208
208
|
|
|
209
|
-
const { overlapMode } = this.graphModel
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
const { overlapMode, eventCenter } = this.graphModel
|
|
210
|
+
this.updateZIndexByOverlap(overlapMode, data.zIndex || getZIndex())
|
|
211
|
+
eventCenter.on('overlap:change', (data) => {
|
|
212
|
+
const { overlapMode: newMode } = data
|
|
213
|
+
this.updateZIndexByOverlap(newMode, this.zIndex || getZIndex())
|
|
214
|
+
})
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
/**
|
|
@@ -339,7 +341,13 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
339
341
|
if (this.rotate) {
|
|
340
342
|
data.rotate = this.rotate
|
|
341
343
|
}
|
|
342
|
-
|
|
344
|
+
// 因为默认模式和节点在上模式下,对边的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
|
|
345
|
+
// 所以只在递增模式和静态模式下设置zIndex
|
|
346
|
+
if (
|
|
347
|
+
[OverlapMode.INCREASE, OverlapMode.STATIC].includes(
|
|
348
|
+
this.graphModel.overlapMode,
|
|
349
|
+
)
|
|
350
|
+
) {
|
|
343
351
|
data.zIndex = this.zIndex
|
|
344
352
|
}
|
|
345
353
|
if (value) {
|
|
@@ -914,6 +922,23 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
914
922
|
@action updateAttributes(attributes: any) {
|
|
915
923
|
assign(this, attributes)
|
|
916
924
|
}
|
|
925
|
+
// 堆叠模式变化时,更新zIndex
|
|
926
|
+
@action
|
|
927
|
+
updateZIndexByOverlap(overlapMode: OverlapMode, defaultZIndex) {
|
|
928
|
+
switch (overlapMode) {
|
|
929
|
+
case OverlapMode.DEFAULT:
|
|
930
|
+
this.zIndex = 1
|
|
931
|
+
break
|
|
932
|
+
case OverlapMode.EDGE_TOP:
|
|
933
|
+
this.zIndex = 0
|
|
934
|
+
break
|
|
935
|
+
case OverlapMode.INCREASE:
|
|
936
|
+
this.zIndex = defaultZIndex
|
|
937
|
+
break
|
|
938
|
+
default:
|
|
939
|
+
break
|
|
940
|
+
}
|
|
941
|
+
}
|
|
917
942
|
}
|
|
918
943
|
|
|
919
944
|
export namespace BaseNodeModel {
|