@logicflow/core 2.1.4 → 2.1.5
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 +8 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/model/GraphModel.js +28 -6
- package/es/view/node/BaseNode.d.ts +1 -0
- package/es/view/node/BaseNode.js +13 -8
- package/lib/model/GraphModel.js +28 -6
- package/lib/view/node/BaseNode.d.ts +1 -0
- package/lib/view/node/BaseNode.js +13 -8
- package/package.json +1 -1
- package/src/model/GraphModel.ts +29 -9
- package/src/view/node/BaseNode.tsx +9 -3
- package/stats.html +1 -1
package/es/model/GraphModel.js
CHANGED
|
@@ -124,6 +124,10 @@ var GraphModel = /** @class */ (function () {
|
|
|
124
124
|
for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
|
|
125
125
|
var entry = entries_1_1.value;
|
|
126
126
|
if (entry.target === _this.rootEl) {
|
|
127
|
+
// 检查元素是否仍在DOM中
|
|
128
|
+
var isElementInDOM = document.body.contains(_this.rootEl);
|
|
129
|
+
if (!isElementInDOM)
|
|
130
|
+
return;
|
|
127
131
|
_this.resize();
|
|
128
132
|
_this.eventCenter.emit('graph:resize', {
|
|
129
133
|
target: _this.rootEl,
|
|
@@ -1382,12 +1386,30 @@ var GraphModel = /** @class */ (function () {
|
|
|
1382
1386
|
* 重新设置画布的宽高
|
|
1383
1387
|
*/
|
|
1384
1388
|
GraphModel.prototype.resize = function (width, height) {
|
|
1385
|
-
|
|
1386
|
-
this.
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1389
|
+
// 检查当前实例是否已被销毁或rootEl不存在
|
|
1390
|
+
if (!this.rootEl)
|
|
1391
|
+
return;
|
|
1392
|
+
// 检查元素是否仍在DOM中
|
|
1393
|
+
var isElementInDOM = document.body.contains(this.rootEl);
|
|
1394
|
+
if (!isElementInDOM)
|
|
1395
|
+
return;
|
|
1396
|
+
// 检查元素是否可见
|
|
1397
|
+
var isVisible = this.rootEl.offsetParent !== null;
|
|
1398
|
+
if (!isVisible)
|
|
1399
|
+
return;
|
|
1400
|
+
try {
|
|
1401
|
+
this.width = width !== null && width !== void 0 ? width : this.rootEl.getBoundingClientRect().width;
|
|
1402
|
+
this.isContainerWidth = isNil(width);
|
|
1403
|
+
this.height = height !== null && height !== void 0 ? height : this.rootEl.getBoundingClientRect().height;
|
|
1404
|
+
this.isContainerHeight = isNil(height);
|
|
1405
|
+
// 只有在元素可见且应该有宽高的情况下才显示警告
|
|
1406
|
+
if (isVisible && (!this.width || !this.height)) {
|
|
1407
|
+
console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
catch (error) {
|
|
1411
|
+
// 捕获可能的DOM操作错误
|
|
1412
|
+
console.warn('获取画布宽高时发生错误:', error);
|
|
1391
1413
|
}
|
|
1392
1414
|
};
|
|
1393
1415
|
/**
|
|
@@ -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
|
+
mouseDownPosition?: LogicFlow.Position;
|
|
22
23
|
constructor(props: IProps);
|
|
23
24
|
componentWillUnmount(): void;
|
|
24
25
|
componentDidMount(): void;
|
package/es/view/node/BaseNode.js
CHANGED
|
@@ -88,11 +88,15 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
88
88
|
var _g = graphModel.editConfigModel, stopMoveGraph = _g.stopMoveGraph, autoExpand = _g.autoExpand, snapGrid = _g.snapGrid, transformModel = graphModel.transformModel, selectNodes = graphModel.selectNodes, width = graphModel.width, height = graphModel.height, gridSize = graphModel.gridSize;
|
|
89
89
|
model.isDragging = true;
|
|
90
90
|
var _h = event, clientX = _h.clientX, clientY = _h.clientY;
|
|
91
|
-
var _j =
|
|
91
|
+
var _j = _this.mouseDownPosition, mouseDownX = _j.x, mouseDownY = _j.y;
|
|
92
|
+
if (clientX - mouseDownX > gridSize || clientY - mouseDownY > gridSize) {
|
|
93
|
+
model.isDragging = true;
|
|
94
|
+
}
|
|
95
|
+
var _k = graphModel.getPointByClient({
|
|
92
96
|
x: clientX,
|
|
93
97
|
y: clientY,
|
|
94
|
-
}).canvasOverlayPosition, x =
|
|
95
|
-
var
|
|
98
|
+
}).canvasOverlayPosition, x = _k.x, y = _k.y;
|
|
99
|
+
var _l = __read(transformModel.CanvasPointToHtmlPoint([x, y]), 2), x1 = _l[0], y1 = _l[1];
|
|
96
100
|
// 1. 考虑画布被缩放
|
|
97
101
|
// 2. 考虑鼠标位置不再节点中心
|
|
98
102
|
x = x + ((_c = (_b = _this.moveOffset) === null || _b === void 0 ? void 0 : _b.dx) !== null && _c !== void 0 ? _c : 0);
|
|
@@ -110,14 +114,14 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
112
116
|
// 取节点左上角和右下角,计算节点移动是否超出范围
|
|
113
|
-
var
|
|
117
|
+
var _m = __read(transformModel.CanvasPointToHtmlPoint([
|
|
114
118
|
x - model.width / 2,
|
|
115
119
|
y - model.height / 2,
|
|
116
|
-
]), 2), leftTopX =
|
|
117
|
-
var
|
|
120
|
+
]), 2), leftTopX = _m[0], leftTopY = _m[1];
|
|
121
|
+
var _o = __read(transformModel.CanvasPointToHtmlPoint([
|
|
118
122
|
x + model.width / 2,
|
|
119
123
|
y + model.height / 2,
|
|
120
|
-
]), 2), rightBottomX =
|
|
124
|
+
]), 2), rightBottomX = _o[0], rightBottomY = _o[1];
|
|
121
125
|
var size = Math.max(gridSize, 20);
|
|
122
126
|
var nearBoundary = [];
|
|
123
127
|
if (leftTopX < 0) {
|
|
@@ -180,7 +184,7 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
180
184
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
181
185
|
// 这里会有一种极端情况:当网格大小是1或者关闭网格吸附时,用触摸板点击节点会触发拖拽事件导致节点无法选中
|
|
182
186
|
// 当触摸板点击节点时,为了防止误触发拖拽导致节点无法选中,允许在非拖拽状态且时间间隔小于100ms时触发点击事件
|
|
183
|
-
if (!isDragging && timeInterval >
|
|
187
|
+
if (!isDragging && timeInterval > 300)
|
|
184
188
|
return;
|
|
185
189
|
if (!isDragging) {
|
|
186
190
|
_this.onDragEnd();
|
|
@@ -263,6 +267,7 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
263
267
|
};
|
|
264
268
|
_this.handleMouseDown = function (ev) {
|
|
265
269
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
270
|
+
_this.mouseDownPosition = { x: ev.clientX, y: ev.clientY };
|
|
266
271
|
_this.startTime = new Date().getTime();
|
|
267
272
|
var editConfigModel = graphModel.editConfigModel;
|
|
268
273
|
if (editConfigModel.adjustNodePosition && model.draggable) {
|
package/lib/model/GraphModel.js
CHANGED
|
@@ -130,6 +130,10 @@ var GraphModel = /** @class */ (function () {
|
|
|
130
130
|
for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
|
|
131
131
|
var entry = entries_1_1.value;
|
|
132
132
|
if (entry.target === _this.rootEl) {
|
|
133
|
+
// 检查元素是否仍在DOM中
|
|
134
|
+
var isElementInDOM = document.body.contains(_this.rootEl);
|
|
135
|
+
if (!isElementInDOM)
|
|
136
|
+
return;
|
|
133
137
|
_this.resize();
|
|
134
138
|
_this.eventCenter.emit('graph:resize', {
|
|
135
139
|
target: _this.rootEl,
|
|
@@ -1388,12 +1392,30 @@ var GraphModel = /** @class */ (function () {
|
|
|
1388
1392
|
* 重新设置画布的宽高
|
|
1389
1393
|
*/
|
|
1390
1394
|
GraphModel.prototype.resize = function (width, height) {
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1395
|
+
// 检查当前实例是否已被销毁或rootEl不存在
|
|
1396
|
+
if (!this.rootEl)
|
|
1397
|
+
return;
|
|
1398
|
+
// 检查元素是否仍在DOM中
|
|
1399
|
+
var isElementInDOM = document.body.contains(this.rootEl);
|
|
1400
|
+
if (!isElementInDOM)
|
|
1401
|
+
return;
|
|
1402
|
+
// 检查元素是否可见
|
|
1403
|
+
var isVisible = this.rootEl.offsetParent !== null;
|
|
1404
|
+
if (!isVisible)
|
|
1405
|
+
return;
|
|
1406
|
+
try {
|
|
1407
|
+
this.width = width !== null && width !== void 0 ? width : this.rootEl.getBoundingClientRect().width;
|
|
1408
|
+
this.isContainerWidth = (0, lodash_es_1.isNil)(width);
|
|
1409
|
+
this.height = height !== null && height !== void 0 ? height : this.rootEl.getBoundingClientRect().height;
|
|
1410
|
+
this.isContainerHeight = (0, lodash_es_1.isNil)(height);
|
|
1411
|
+
// 只有在元素可见且应该有宽高的情况下才显示警告
|
|
1412
|
+
if (isVisible && (!this.width || !this.height)) {
|
|
1413
|
+
console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
catch (error) {
|
|
1417
|
+
// 捕获可能的DOM操作错误
|
|
1418
|
+
console.warn('获取画布宽高时发生错误:', error);
|
|
1397
1419
|
}
|
|
1398
1420
|
};
|
|
1399
1421
|
/**
|
|
@@ -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
|
+
mouseDownPosition?: LogicFlow.Position;
|
|
22
23
|
constructor(props: IProps);
|
|
23
24
|
componentWillUnmount(): void;
|
|
24
25
|
componentDidMount(): void;
|
|
@@ -92,11 +92,15 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
92
92
|
var _g = graphModel.editConfigModel, stopMoveGraph = _g.stopMoveGraph, autoExpand = _g.autoExpand, snapGrid = _g.snapGrid, transformModel = graphModel.transformModel, selectNodes = graphModel.selectNodes, width = graphModel.width, height = graphModel.height, gridSize = graphModel.gridSize;
|
|
93
93
|
model.isDragging = true;
|
|
94
94
|
var _h = event, clientX = _h.clientX, clientY = _h.clientY;
|
|
95
|
-
var _j =
|
|
95
|
+
var _j = _this.mouseDownPosition, mouseDownX = _j.x, mouseDownY = _j.y;
|
|
96
|
+
if (clientX - mouseDownX > gridSize || clientY - mouseDownY > gridSize) {
|
|
97
|
+
model.isDragging = true;
|
|
98
|
+
}
|
|
99
|
+
var _k = graphModel.getPointByClient({
|
|
96
100
|
x: clientX,
|
|
97
101
|
y: clientY,
|
|
98
|
-
}).canvasOverlayPosition, x =
|
|
99
|
-
var
|
|
102
|
+
}).canvasOverlayPosition, x = _k.x, y = _k.y;
|
|
103
|
+
var _l = __read(transformModel.CanvasPointToHtmlPoint([x, y]), 2), x1 = _l[0], y1 = _l[1];
|
|
100
104
|
// 1. 考虑画布被缩放
|
|
101
105
|
// 2. 考虑鼠标位置不再节点中心
|
|
102
106
|
x = x + ((_c = (_b = _this.moveOffset) === null || _b === void 0 ? void 0 : _b.dx) !== null && _c !== void 0 ? _c : 0);
|
|
@@ -114,14 +118,14 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
114
118
|
return;
|
|
115
119
|
}
|
|
116
120
|
// 取节点左上角和右下角,计算节点移动是否超出范围
|
|
117
|
-
var
|
|
121
|
+
var _m = __read(transformModel.CanvasPointToHtmlPoint([
|
|
118
122
|
x - model.width / 2,
|
|
119
123
|
y - model.height / 2,
|
|
120
|
-
]), 2), leftTopX =
|
|
121
|
-
var
|
|
124
|
+
]), 2), leftTopX = _m[0], leftTopY = _m[1];
|
|
125
|
+
var _o = __read(transformModel.CanvasPointToHtmlPoint([
|
|
122
126
|
x + model.width / 2,
|
|
123
127
|
y + model.height / 2,
|
|
124
|
-
]), 2), rightBottomX =
|
|
128
|
+
]), 2), rightBottomX = _o[0], rightBottomY = _o[1];
|
|
125
129
|
var size = Math.max(gridSize, 20);
|
|
126
130
|
var nearBoundary = [];
|
|
127
131
|
if (leftTopX < 0) {
|
|
@@ -184,7 +188,7 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
184
188
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
185
189
|
// 这里会有一种极端情况:当网格大小是1或者关闭网格吸附时,用触摸板点击节点会触发拖拽事件导致节点无法选中
|
|
186
190
|
// 当触摸板点击节点时,为了防止误触发拖拽导致节点无法选中,允许在非拖拽状态且时间间隔小于100ms时触发点击事件
|
|
187
|
-
if (!isDragging && timeInterval >
|
|
191
|
+
if (!isDragging && timeInterval > 300)
|
|
188
192
|
return;
|
|
189
193
|
if (!isDragging) {
|
|
190
194
|
_this.onDragEnd();
|
|
@@ -267,6 +271,7 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
267
271
|
};
|
|
268
272
|
_this.handleMouseDown = function (ev) {
|
|
269
273
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
274
|
+
_this.mouseDownPosition = { x: ev.clientX, y: ev.clientY };
|
|
270
275
|
_this.startTime = new Date().getTime();
|
|
271
276
|
var editConfigModel = graphModel.editConfigModel;
|
|
272
277
|
if (editConfigModel.adjustNodePosition && model.draggable) {
|
package/package.json
CHANGED
package/src/model/GraphModel.ts
CHANGED
|
@@ -192,6 +192,9 @@ export class GraphModel {
|
|
|
192
192
|
((entries) => {
|
|
193
193
|
for (const entry of entries) {
|
|
194
194
|
if (entry.target === this.rootEl) {
|
|
195
|
+
// 检查元素是否仍在DOM中
|
|
196
|
+
const isElementInDOM = document.body.contains(this.rootEl)
|
|
197
|
+
if (!isElementInDOM) return
|
|
195
198
|
this.resize()
|
|
196
199
|
this.eventCenter.emit('graph:resize', {
|
|
197
200
|
target: this.rootEl,
|
|
@@ -1584,15 +1587,32 @@ export class GraphModel {
|
|
|
1584
1587
|
* 重新设置画布的宽高
|
|
1585
1588
|
*/
|
|
1586
1589
|
@action resize(width?: number, height?: number): void {
|
|
1587
|
-
|
|
1588
|
-
this.
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
if (!
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1590
|
+
// 检查当前实例是否已被销毁或rootEl不存在
|
|
1591
|
+
if (!this.rootEl) return
|
|
1592
|
+
|
|
1593
|
+
// 检查元素是否仍在DOM中
|
|
1594
|
+
const isElementInDOM = document.body.contains(this.rootEl)
|
|
1595
|
+
if (!isElementInDOM) return
|
|
1596
|
+
|
|
1597
|
+
// 检查元素是否可见
|
|
1598
|
+
const isVisible = this.rootEl.offsetParent !== null
|
|
1599
|
+
if (!isVisible) return
|
|
1600
|
+
|
|
1601
|
+
try {
|
|
1602
|
+
this.width = width ?? this.rootEl.getBoundingClientRect().width
|
|
1603
|
+
this.isContainerWidth = isNil(width)
|
|
1604
|
+
this.height = height ?? this.rootEl.getBoundingClientRect().height
|
|
1605
|
+
this.isContainerHeight = isNil(height)
|
|
1606
|
+
|
|
1607
|
+
// 只有在元素可见且应该有宽高的情况下才显示警告
|
|
1608
|
+
if (isVisible && (!this.width || !this.height)) {
|
|
1609
|
+
console.warn(
|
|
1610
|
+
'渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675',
|
|
1611
|
+
)
|
|
1612
|
+
}
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
// 捕获可能的DOM操作错误
|
|
1615
|
+
console.warn('获取画布宽高时发生错误:', error)
|
|
1596
1616
|
}
|
|
1597
1617
|
}
|
|
1598
1618
|
|
|
@@ -42,6 +42,7 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
42
42
|
mouseUpDrag?: boolean
|
|
43
43
|
startTime?: number
|
|
44
44
|
modelDisposer: IReactionDisposer
|
|
45
|
+
mouseDownPosition?: LogicFlow.Position
|
|
45
46
|
|
|
46
47
|
constructor(props: IProps) {
|
|
47
48
|
super()
|
|
@@ -88,9 +89,9 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
componentDidMount() {
|
|
92
|
+
componentDidMount() {}
|
|
92
93
|
|
|
93
|
-
componentDidUpdate() {
|
|
94
|
+
componentDidUpdate() {}
|
|
94
95
|
|
|
95
96
|
abstract getShape(): h.JSX.Element | null
|
|
96
97
|
|
|
@@ -249,6 +250,10 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
249
250
|
} = graphModel
|
|
250
251
|
model.isDragging = true
|
|
251
252
|
const { clientX, clientY } = event!
|
|
253
|
+
const { x: mouseDownX, y: mouseDownY } = this.mouseDownPosition!
|
|
254
|
+
if (clientX - mouseDownX > gridSize || clientY - mouseDownY > gridSize) {
|
|
255
|
+
model.isDragging = true
|
|
256
|
+
}
|
|
252
257
|
let {
|
|
253
258
|
canvasOverlayPosition: { x, y },
|
|
254
259
|
} = graphModel.getPointByClient({
|
|
@@ -342,7 +347,7 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
342
347
|
const { model, graphModel } = this.props
|
|
343
348
|
// 这里会有一种极端情况:当网格大小是1或者关闭网格吸附时,用触摸板点击节点会触发拖拽事件导致节点无法选中
|
|
344
349
|
// 当触摸板点击节点时,为了防止误触发拖拽导致节点无法选中,允许在非拖拽状态且时间间隔小于100ms时触发点击事件
|
|
345
|
-
if (!isDragging && timeInterval >
|
|
350
|
+
if (!isDragging && timeInterval > 300) return
|
|
346
351
|
if (!isDragging) {
|
|
347
352
|
this.onDragEnd()
|
|
348
353
|
this.handleMouseUp()
|
|
@@ -433,6 +438,7 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
433
438
|
|
|
434
439
|
handleMouseDown = (ev: MouseEvent) => {
|
|
435
440
|
const { model, graphModel } = this.props
|
|
441
|
+
this.mouseDownPosition = { x: ev.clientX, y: ev.clientY }
|
|
436
442
|
this.startTime = new Date().getTime()
|
|
437
443
|
const { editConfigModel } = graphModel
|
|
438
444
|
if (editConfigModel.adjustNodePosition && model.draggable) {
|