@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
package/es/util/resize.js
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { ResizeControlIndex } from '../view/Control';
|
|
2
2
|
import { cloneDeep, find, forEach } from 'lodash-es';
|
|
3
3
|
import { EventType } from '../constant';
|
|
4
|
+
import { calculatePointAfterRotateAngle, getNewCenter, radianToAngle, } from '../algorithm/rotate';
|
|
5
|
+
function recalcRotatedResizeInfo(pct, resizeInfo, rotate, controlX, controlY, oldCenterX, oldCenterY, freezeWidth, freezeHeight) {
|
|
6
|
+
if (freezeWidth === void 0) { freezeWidth = false; }
|
|
7
|
+
if (freezeHeight === void 0) { freezeHeight = false; }
|
|
8
|
+
// 假设我们触摸的点是右下角的control
|
|
9
|
+
var deltaX = resizeInfo.deltaX, deltaY = resizeInfo.deltaY, oldWidth = resizeInfo.width, oldHeight = resizeInfo.height;
|
|
10
|
+
var angle = radianToAngle(rotate);
|
|
11
|
+
// 右下角的control
|
|
12
|
+
var startZeroTouchControlPoint = {
|
|
13
|
+
x: controlX, // control锚点的坐标x
|
|
14
|
+
y: controlY, // control锚点的坐标y
|
|
15
|
+
};
|
|
16
|
+
var oldCenter = { x: oldCenterX, y: oldCenterY };
|
|
17
|
+
// 右下角的control坐标(transform后的-touchStartPoint)
|
|
18
|
+
var startRotatedTouchControlPoint = calculatePointAfterRotateAngle(startZeroTouchControlPoint, oldCenter, angle);
|
|
19
|
+
// 右下角的control坐标(transform后的-touchEndPoint)
|
|
20
|
+
var endRotatedTouchControlPoint = {
|
|
21
|
+
x: startRotatedTouchControlPoint.x + deltaX,
|
|
22
|
+
y: startRotatedTouchControlPoint.y + deltaY,
|
|
23
|
+
};
|
|
24
|
+
// 计算出新的宽度和高度以及新的中心点
|
|
25
|
+
var _a = calculateWidthAndHeight(startRotatedTouchControlPoint, endRotatedTouchControlPoint, oldCenter, angle, freezeWidth, freezeHeight, oldWidth, oldHeight), newWidth = _a.width, newHeight = _a.height, newCenter = _a.center;
|
|
26
|
+
// calculateWidthAndHeight()得到的是整个宽度,比如圆pct=0.5,此时newWidth等于整个圆直径
|
|
27
|
+
resizeInfo.width = newWidth * pct;
|
|
28
|
+
resizeInfo.height = newHeight * pct;
|
|
29
|
+
// BaseNodeModel.resize(deltaX/2, deltaY/2),因此这里要*2
|
|
30
|
+
resizeInfo.deltaX = (newCenter.x - oldCenter.x) * 2;
|
|
31
|
+
resizeInfo.deltaY = (newCenter.y - oldCenter.y) * 2;
|
|
32
|
+
return resizeInfo;
|
|
33
|
+
}
|
|
4
34
|
/**
|
|
5
35
|
* 计算 Control 拖动后,节点的高度信息
|
|
6
36
|
* @param index
|
|
@@ -9,10 +39,11 @@ import { EventType } from '../constant';
|
|
|
9
39
|
* @param freezeWidth
|
|
10
40
|
* @param freezeHeight
|
|
11
41
|
*/
|
|
12
|
-
export var recalcResizeInfo = function (index, resizeInfo, pct, freezeWidth, freezeHeight) {
|
|
42
|
+
export var recalcResizeInfo = function (index, resizeInfo, pct, freezeWidth, freezeHeight, rotate, controlX, controlY, oldCenterX, oldCenterY) {
|
|
13
43
|
if (pct === void 0) { pct = 1; }
|
|
14
44
|
if (freezeWidth === void 0) { freezeWidth = false; }
|
|
15
45
|
if (freezeHeight === void 0) { freezeHeight = false; }
|
|
46
|
+
if (rotate === void 0) { rotate = 0; }
|
|
16
47
|
var nextResizeInfo = cloneDeep(resizeInfo);
|
|
17
48
|
var deltaX = nextResizeInfo.deltaX, deltaY = nextResizeInfo.deltaY;
|
|
18
49
|
var width = nextResizeInfo.width, height = nextResizeInfo.height, PCTResizeInfo = nextResizeInfo.PCTResizeInfo;
|
|
@@ -70,6 +101,14 @@ export var recalcResizeInfo = function (index, resizeInfo, pct, freezeWidth, fre
|
|
|
70
101
|
}
|
|
71
102
|
return nextResizeInfo;
|
|
72
103
|
}
|
|
104
|
+
if (rotate % (2 * Math.PI) !== 0 &&
|
|
105
|
+
controlX !== undefined &&
|
|
106
|
+
controlY !== undefined) {
|
|
107
|
+
// 角度rotate不为0,则触发另外的计算修正resize的deltaX和deltaY
|
|
108
|
+
// 因为rotate不为0的时候,左上角的坐标一直在变化
|
|
109
|
+
// 角度rotate不为0得到的resizeInfo.deltaX仅仅代表中心点的变化,而不是宽度的变化
|
|
110
|
+
return recalcRotatedResizeInfo(pct, nextResizeInfo, rotate, controlX, controlY, oldCenterX, oldCenterY, freezeWidth, freezeHeight);
|
|
111
|
+
}
|
|
73
112
|
// 如果限制了宽/高不变,对应的 width/height 保持一致
|
|
74
113
|
switch (index) {
|
|
75
114
|
case ResizeControlIndex.LEFT_TOP:
|
|
@@ -140,17 +179,10 @@ export var triggerResizeEvent = function (preNodeData, curNodeData, deltaX, delt
|
|
|
140
179
|
model: nodeModel,
|
|
141
180
|
});
|
|
142
181
|
};
|
|
143
|
-
// TODO:确认 handleResize 函数的类型定义
|
|
144
|
-
// export type IHandleResizeParams = {
|
|
145
|
-
// deltaX: number
|
|
146
|
-
// deltaY: number
|
|
147
|
-
// index: ResizeControlIndex
|
|
148
|
-
// nodeModel: BaseNodeModel
|
|
149
|
-
// graphModel: GraphModel
|
|
150
|
-
// cancelCallback?: () => void
|
|
151
|
-
// }
|
|
152
182
|
/**
|
|
153
183
|
* 处理节点的 resize 事件,提出来放到 utils 中,方便在外面(extension)中使用
|
|
184
|
+
* @param x
|
|
185
|
+
* @param y
|
|
154
186
|
* @param deltaX
|
|
155
187
|
* @param deltaY
|
|
156
188
|
* @param index
|
|
@@ -159,11 +191,11 @@ export var triggerResizeEvent = function (preNodeData, curNodeData, deltaX, delt
|
|
|
159
191
|
* @param cancelCallback
|
|
160
192
|
*/
|
|
161
193
|
export var handleResize = function (_a) {
|
|
162
|
-
var deltaX = _a.deltaX, deltaY = _a.deltaY, index = _a.index, nodeModel = _a.nodeModel, graphModel = _a.graphModel, cancelCallback = _a.cancelCallback;
|
|
194
|
+
var x = _a.x, y = _a.y, deltaX = _a.deltaX, deltaY = _a.deltaY, index = _a.index, nodeModel = _a.nodeModel, graphModel = _a.graphModel, cancelCallback = _a.cancelCallback;
|
|
163
195
|
var r = nodeModel.r, // circle
|
|
164
196
|
rx = nodeModel.rx, // ellipse/diamond
|
|
165
197
|
ry = nodeModel.ry, width = nodeModel.width, // rect/html
|
|
166
|
-
height = nodeModel.height, PCTResizeInfo = nodeModel.PCTResizeInfo, minWidth = nodeModel.minWidth, minHeight = nodeModel.minHeight, maxWidth = nodeModel.maxWidth, maxHeight = nodeModel.maxHeight;
|
|
198
|
+
height = nodeModel.height, PCTResizeInfo = nodeModel.PCTResizeInfo, minWidth = nodeModel.minWidth, minHeight = nodeModel.minHeight, maxWidth = nodeModel.maxWidth, maxHeight = nodeModel.maxHeight, rotate = nodeModel.rotate, oldCenterX = nodeModel.x, oldCenterY = nodeModel.y;
|
|
167
199
|
var isFreezeWidth = minWidth === maxWidth;
|
|
168
200
|
var isFreezeHeight = minHeight === maxHeight;
|
|
169
201
|
var resizeInfo = {
|
|
@@ -174,7 +206,9 @@ export var handleResize = function (_a) {
|
|
|
174
206
|
PCTResizeInfo: PCTResizeInfo,
|
|
175
207
|
};
|
|
176
208
|
var pct = r || (rx && ry) ? 1 / 2 : 1;
|
|
177
|
-
var
|
|
209
|
+
var controlX = x;
|
|
210
|
+
var controlY = y;
|
|
211
|
+
var nextSize = recalcResizeInfo(index, resizeInfo, pct, isFreezeWidth, isFreezeHeight, rotate, controlX, controlY, oldCenterX, oldCenterY);
|
|
178
212
|
// 限制放大缩小的最大最小范围
|
|
179
213
|
if (nextSize.width < minWidth ||
|
|
180
214
|
nextSize.width > maxWidth ||
|
|
@@ -184,13 +218,102 @@ export var handleResize = function (_a) {
|
|
|
184
218
|
cancelCallback === null || cancelCallback === void 0 ? void 0 : cancelCallback();
|
|
185
219
|
return;
|
|
186
220
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
221
|
+
if (rotate % (2 * Math.PI) == 0 ||
|
|
222
|
+
PCTResizeInfo ||
|
|
223
|
+
controlX === undefined ||
|
|
224
|
+
controlY === undefined) {
|
|
225
|
+
// rotate!==0并且不是PCTResizeInfo时,即使是isFreezeWidth||isFreezeHeight
|
|
226
|
+
// recalcRotatedResizeInfo()计算出来的中心点会发生变化
|
|
227
|
+
// 如果限制了宽高不变,对应的 x/y 不产生位移
|
|
228
|
+
nextSize.deltaX = isFreezeWidth ? 0 : nextSize.deltaX;
|
|
229
|
+
nextSize.deltaY = isFreezeHeight ? 0 : nextSize.deltaY;
|
|
230
|
+
}
|
|
190
231
|
var preNodeData = nodeModel.getData();
|
|
191
232
|
var curNodeData = nodeModel.resize(nextSize);
|
|
233
|
+
// 检测preNodeData和curNodeData是否没变化
|
|
234
|
+
if (preNodeData.x === curNodeData.x && preNodeData.y === curNodeData.y) {
|
|
235
|
+
// 中心点x和y都没有变化,说明无法resize,阻止下面边的更新以及resize事件的emit
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
192
238
|
// 更新边
|
|
193
239
|
updateEdgePointByAnchors(nodeModel, graphModel);
|
|
194
240
|
// 触发 resize 事件
|
|
195
241
|
triggerResizeEvent(preNodeData, curNodeData, deltaX, deltaY, index, nodeModel, graphModel);
|
|
196
242
|
};
|
|
243
|
+
export function calculateWidthAndHeight(startRotatedTouchControlPoint, endRotatedTouchControlPoint, oldCenter, angle, freezeWidth, freezeHeight, oldWidth, oldHeight) {
|
|
244
|
+
if (freezeWidth === void 0) { freezeWidth = false; }
|
|
245
|
+
if (freezeHeight === void 0) { freezeHeight = false; }
|
|
246
|
+
// 假设目前触摸的是右下角的control点
|
|
247
|
+
// 计算出来左上角的control坐标,resize过程左上角的control坐标保持不变
|
|
248
|
+
var freezePoint = {
|
|
249
|
+
x: oldCenter.x - (startRotatedTouchControlPoint.x - oldCenter.x),
|
|
250
|
+
y: oldCenter.y - (startRotatedTouchControlPoint.y - oldCenter.y),
|
|
251
|
+
};
|
|
252
|
+
// 【touchEndPoint】右下角 + freezePoint左上角 计算出新的中心点
|
|
253
|
+
var newCenter = getNewCenter(freezePoint, endRotatedTouchControlPoint);
|
|
254
|
+
// 得到【touchEndPoint】右下角-没有transform的坐标
|
|
255
|
+
var endZeroTouchControlPoint = calculatePointAfterRotateAngle(endRotatedTouchControlPoint, newCenter, -angle);
|
|
256
|
+
// ---------- 使用transform之前的坐标计算出新的width和height ----------
|
|
257
|
+
// 得到左上角---没有transform的坐标
|
|
258
|
+
var zeroFreezePoint = calculatePointAfterRotateAngle(freezePoint, newCenter, -angle);
|
|
259
|
+
if (freezeWidth) {
|
|
260
|
+
// 如果固定width,那么不能单纯使用endZeroTouchControlPoint.x=startZeroTouchControlPoint.x
|
|
261
|
+
// 因为去掉transform的左上角不一定是重合的,我们要保证的是transform后的左上角重合
|
|
262
|
+
var newWidth = Math.abs(endZeroTouchControlPoint.x - zeroFreezePoint.x);
|
|
263
|
+
var widthDx = newWidth - oldWidth;
|
|
264
|
+
// 点击的是左边锚点,是+widthDx/2,点击是右边锚点,是-widthDx/2
|
|
265
|
+
if (newCenter.x > endZeroTouchControlPoint.x) {
|
|
266
|
+
// 当前触摸的是左边锚点
|
|
267
|
+
newCenter.x = newCenter.x + widthDx / 2;
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
// 当前触摸的是右边锚点
|
|
271
|
+
newCenter.x = newCenter.x - widthDx / 2;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (freezeHeight) {
|
|
275
|
+
var newHeight = Math.abs(endZeroTouchControlPoint.y - zeroFreezePoint.y);
|
|
276
|
+
var heightDy = newHeight - oldHeight;
|
|
277
|
+
if (newCenter.y > endZeroTouchControlPoint.y) {
|
|
278
|
+
// 当前触摸的是上边锚点
|
|
279
|
+
newCenter.y = newCenter.y + heightDy / 2;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
newCenter.y = newCenter.y - heightDy / 2;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (freezeWidth || freezeHeight) {
|
|
286
|
+
// 如果调整过transform之前的坐标,那么transform后的坐标也会改变,那么算出来的newCenter也得调整
|
|
287
|
+
// 由于无论如何rotate,中心点都是不变的,因此我们可以使用transform之前的坐标算出新的中心点
|
|
288
|
+
var nowFreezePoint = calculatePointAfterRotateAngle(zeroFreezePoint, newCenter, angle);
|
|
289
|
+
// 得到当前新rect的左上角与实际上transform后的左上角的偏移量
|
|
290
|
+
var dx = nowFreezePoint.x - freezePoint.x;
|
|
291
|
+
var dy = nowFreezePoint.y - freezePoint.y;
|
|
292
|
+
// 修正不使用transform的坐标: 左上角、右下角、center
|
|
293
|
+
newCenter.x = newCenter.x - dx;
|
|
294
|
+
newCenter.y = newCenter.y - dy;
|
|
295
|
+
zeroFreezePoint = calculatePointAfterRotateAngle(freezePoint, newCenter, -angle);
|
|
296
|
+
endZeroTouchControlPoint = {
|
|
297
|
+
x: newCenter.x - (zeroFreezePoint.x - newCenter.x),
|
|
298
|
+
y: newCenter.y - (zeroFreezePoint.y - newCenter.y),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
// transform之前的坐标的左上角+右下角计算出宽度和高度
|
|
302
|
+
var width = Math.abs(endZeroTouchControlPoint.x - zeroFreezePoint.x);
|
|
303
|
+
var height = Math.abs(endZeroTouchControlPoint.y - zeroFreezePoint.y);
|
|
304
|
+
// ---------- 使用transform之前的坐标计算出新的width和height ----------
|
|
305
|
+
if (freezeWidth) {
|
|
306
|
+
// 理论计算出来的width应该等于oldWidth
|
|
307
|
+
// 但是有误差,比如oldWidth = 100; newWidth=100.000000000001
|
|
308
|
+
// 会在handleResize()限制放大缩小的最大最小范围中被阻止滑动
|
|
309
|
+
width = oldWidth;
|
|
310
|
+
}
|
|
311
|
+
if (freezeHeight) {
|
|
312
|
+
height = oldHeight;
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
width: width,
|
|
316
|
+
height: height,
|
|
317
|
+
center: newCenter,
|
|
318
|
+
};
|
|
319
|
+
}
|
package/es/view/Anchor.js
CHANGED
|
@@ -139,14 +139,12 @@ var Anchor = /** @class */ (function (_super) {
|
|
|
139
139
|
_this.sourceRuleResults.clear();
|
|
140
140
|
_this.targetRuleResults.clear();
|
|
141
141
|
var _b = _this.props, graphModel = _b.graphModel, nodeModel = _b.nodeModel, anchorData = _b.anchorData;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
}
|
|
142
|
+
graphModel.eventCenter.emit(EventType.ANCHOR_DRAGEND, {
|
|
143
|
+
data: anchorData,
|
|
144
|
+
e: event,
|
|
145
|
+
nodeModel: nodeModel,
|
|
146
|
+
edgeModel: edgeModel !== null && edgeModel !== void 0 ? edgeModel : undefined,
|
|
147
|
+
});
|
|
150
148
|
};
|
|
151
149
|
_this.checkEnd = function (event) {
|
|
152
150
|
var _a;
|
package/es/view/Control.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare class ResizeControl extends Component<IResizeControlProps, IResiz
|
|
|
30
30
|
readonly graphModel: GraphModel;
|
|
31
31
|
readonly dragHandler: StepDrag;
|
|
32
32
|
constructor(props: IResizeControlProps);
|
|
33
|
+
componentWillUnmount(): void;
|
|
33
34
|
updateEdgePointByAnchors: () => void;
|
|
34
35
|
triggerResizeEvent: (preNodeData: ResizeNodeData, curNodeData: ResizeNodeData, deltaX: any, deltaY: any, index: any, nodeModel: BaseNodeModel) => void;
|
|
35
36
|
/**
|
package/es/view/Control.js
CHANGED
|
@@ -210,9 +210,11 @@ var ResizeControl = /** @class */ (function (_super) {
|
|
|
210
210
|
_this.resizeNode = function (_a) {
|
|
211
211
|
var deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
212
212
|
var index = _this.index;
|
|
213
|
-
var _b = _this.props, model = _b.model, graphModel = _b.graphModel;
|
|
213
|
+
var _b = _this.props, model = _b.model, graphModel = _b.graphModel, x = _b.x, y = _b.y;
|
|
214
214
|
// DONE: 调用每个节点中更新缩放时的方法 updateNode 函数,用来各节点缩放的方法
|
|
215
215
|
handleResize({
|
|
216
|
+
x: x,
|
|
217
|
+
y: y,
|
|
216
218
|
deltaX: deltaX,
|
|
217
219
|
deltaY: deltaY,
|
|
218
220
|
index: index,
|
|
@@ -313,6 +315,9 @@ var ResizeControl = /** @class */ (function (_super) {
|
|
|
313
315
|
});
|
|
314
316
|
return _this;
|
|
315
317
|
}
|
|
318
|
+
ResizeControl.prototype.componentWillUnmount = function () {
|
|
319
|
+
this.dragHandler.destroy();
|
|
320
|
+
};
|
|
316
321
|
ResizeControl.prototype.render = function () {
|
|
317
322
|
var _a = this.props, x = _a.x, y = _a.y, direction = _a.direction, model = _a.model;
|
|
318
323
|
var _b = model.getResizeControlStyle(), width = _b.width, height = _b.height, restStyle = __rest(_b, ["width", "height"]);
|
package/es/view/Graph.js
CHANGED
|
@@ -13,17 +13,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
13
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
14
|
};
|
|
15
15
|
})();
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
16
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
28
17
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
18
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -102,12 +91,11 @@ var Graph = /** @class */ (function (_super) {
|
|
|
102
91
|
if (options.height) {
|
|
103
92
|
style.height = "".concat(graphModel.height, "px");
|
|
104
93
|
}
|
|
105
|
-
var
|
|
106
|
-
var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel;
|
|
94
|
+
var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel, background = graphModel.background;
|
|
107
95
|
var adjustEdge = editConfigModel.adjustEdge;
|
|
108
|
-
return (_jsxs("div", { className: "lf-graph", "flow-id": graphModel.flowId, children: [_jsxs(CanvasOverlay, { graphModel: graphModel, dnd: dnd, children: [_jsx("g", { className: "lf-base", children: map(graphModel.sortElements, function (nodeModel) {
|
|
96
|
+
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) {
|
|
109
97
|
return _this.getComponent(nodeModel, graphModel);
|
|
110
|
-
}) }), 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 }),
|
|
98
|
+
}) }), 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 })] }));
|
|
111
99
|
};
|
|
112
100
|
Graph = __decorate([
|
|
113
101
|
observer
|
package/es/view/behavior/dnd.js
CHANGED
|
@@ -13,6 +13,7 @@ export type IEdgeState = {
|
|
|
13
13
|
export declare abstract class BaseEdge<P extends IProps> extends Component<P, IEdgeState> {
|
|
14
14
|
static isObserved: boolean;
|
|
15
15
|
static extendsKey?: string;
|
|
16
|
+
mouseUpDrag?: boolean;
|
|
16
17
|
startTime?: number;
|
|
17
18
|
contextMenuTime?: number;
|
|
18
19
|
clickTimer?: number;
|
|
@@ -127,10 +128,11 @@ export declare abstract class BaseEdge<P extends IProps> extends Component<P, IE
|
|
|
127
128
|
* 不支持重写
|
|
128
129
|
*/
|
|
129
130
|
handleMouseDown: (e: MouseEvent) => void;
|
|
131
|
+
handleMouseUp: () => void;
|
|
130
132
|
/**
|
|
131
133
|
* 不支持重写
|
|
132
134
|
*/
|
|
133
|
-
|
|
135
|
+
handleClick: (e: MouseEvent) => void;
|
|
134
136
|
/**
|
|
135
137
|
* @overridable 支持重写, 此方法为获取边的形状,如果需要自定义边的形状,请重写此方法。
|
|
136
138
|
* @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
|
package/es/view/edge/BaseEdge.js
CHANGED
|
@@ -123,15 +123,18 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
123
123
|
e.stopPropagation();
|
|
124
124
|
_this.startTime = new Date().getTime();
|
|
125
125
|
};
|
|
126
|
+
_this.handleMouseUp = function () {
|
|
127
|
+
var model = _this.props.model;
|
|
128
|
+
_this.mouseUpDrag = model.isDragging;
|
|
129
|
+
};
|
|
126
130
|
/**
|
|
127
131
|
* 不支持重写
|
|
128
132
|
*/
|
|
129
|
-
_this.
|
|
133
|
+
_this.handleClick = function (e) {
|
|
130
134
|
if (!_this.startTime)
|
|
131
135
|
return;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return; // 事件大于200ms,认为是拖拽。
|
|
136
|
+
if (_this.mouseUpDrag)
|
|
137
|
+
return; // 如果是拖拽,不触发click事件。
|
|
135
138
|
var isRightClick = e.button === 2;
|
|
136
139
|
if (isRightClick)
|
|
137
140
|
return;
|
|
@@ -379,7 +382,7 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
379
382
|
isSelected && 'lf-edge-selected',
|
|
380
383
|
]
|
|
381
384
|
.filter(Boolean)
|
|
382
|
-
.join(' '), onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onContextMenu: this.handleContextMenu, onMouseOver: this.setHoverOn, onMouseEnter: this.setHoverOn, onMouseLeave: this.setHoverOff, children: [this.getShape(), this.getAppend(), this.getText(), this.getArrow()] }), isShowAdjustPoint && isSelected ? this.getAdjustPoints() : ''] }));
|
|
385
|
+
.join(' '), onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onClick: this.handleClick, onContextMenu: this.handleContextMenu, onMouseOver: this.setHoverOn, onMouseEnter: this.setHoverOn, onMouseLeave: this.setHoverOff, children: [this.getShape(), this.getAppend(), this.getText(), this.getArrow()] }), isShowAdjustPoint && isSelected ? this.getAdjustPoints() : ''] }));
|
|
383
386
|
};
|
|
384
387
|
BaseEdge.isObserved = false;
|
|
385
388
|
return BaseEdge;
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import { Component } from 'preact/compat';
|
|
2
|
+
import { Options as LFOptions } from '../../options';
|
|
2
3
|
/**
|
|
3
4
|
* 背景配置, 支持css属性配置
|
|
4
5
|
* https://developer.mozilla.org/zh-CN/docs/Web/CSS/background
|
|
5
6
|
* @example
|
|
6
7
|
* {
|
|
7
|
-
*
|
|
8
|
-
|
|
8
|
+
* backgroundImage: "url('./img/grid.svg')",
|
|
9
|
+
backgroundRepeat: 'repeat',
|
|
9
10
|
* }
|
|
10
11
|
*/
|
|
11
|
-
export type BackgroundConfig = {
|
|
12
|
-
/**
|
|
13
|
-
* 背景图片地址
|
|
14
|
-
*/
|
|
15
|
-
backgroundImage?: string;
|
|
16
|
-
/**
|
|
17
|
-
* 是否重复
|
|
18
|
-
*/
|
|
19
|
-
backgroundRepeat?: string;
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
};
|
|
22
12
|
type IProps = {
|
|
23
|
-
background: BackgroundConfig;
|
|
13
|
+
background: boolean | LFOptions.BackgroundConfig;
|
|
24
14
|
};
|
|
25
15
|
export declare class BackgroundOverlay extends Component<IProps> {
|
|
26
16
|
render(): import("preact/compat").JSX.Element;
|
|
@@ -13,8 +13,15 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
13
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
14
|
};
|
|
15
15
|
})();
|
|
16
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
17
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
+
};
|
|
16
22
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
17
23
|
import { Component } from 'preact/compat';
|
|
24
|
+
import { observer } from '../..';
|
|
18
25
|
var BackgroundOverlay = /** @class */ (function (_super) {
|
|
19
26
|
__extends(BackgroundOverlay, _super);
|
|
20
27
|
function BackgroundOverlay() {
|
|
@@ -22,8 +29,11 @@ var BackgroundOverlay = /** @class */ (function (_super) {
|
|
|
22
29
|
}
|
|
23
30
|
BackgroundOverlay.prototype.render = function () {
|
|
24
31
|
var background = this.props.background;
|
|
25
|
-
return (_jsx("div", { className: "lf-background", children: _jsx("div", { style: background, className: "lf-background-area" }) }));
|
|
32
|
+
return (_jsx("div", { className: "lf-background", children: _jsx("div", { style: typeof background === 'object' ? background : {}, className: "lf-background-area" }) }));
|
|
26
33
|
};
|
|
34
|
+
BackgroundOverlay = __decorate([
|
|
35
|
+
observer
|
|
36
|
+
], BackgroundOverlay);
|
|
27
37
|
return BackgroundOverlay;
|
|
28
38
|
}(Component));
|
|
29
39
|
export { BackgroundOverlay };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Component } from 'preact/compat';
|
|
2
2
|
import { GraphModel } from '../../model';
|
|
3
|
-
|
|
4
|
-
type IProps = GridOptions & {
|
|
3
|
+
type IProps = {
|
|
5
4
|
graphModel: GraphModel;
|
|
6
5
|
};
|
|
7
6
|
export declare class Grid extends Component<IProps> {
|
|
7
|
+
gridOptions: Grid.GridOptions;
|
|
8
8
|
readonly id: string;
|
|
9
|
+
constructor(props: IProps);
|
|
9
10
|
renderDot(): import("preact/compat").JSX.Element;
|
|
10
11
|
renderMesh(): import("preact/compat").JSX.Element;
|
|
11
12
|
render(): import("preact/compat").JSX.Element;
|
|
@@ -30,7 +31,7 @@ export declare namespace Grid {
|
|
|
30
31
|
/**
|
|
31
32
|
* 网格的颜色
|
|
32
33
|
*/
|
|
33
|
-
color
|
|
34
|
+
color?: string;
|
|
34
35
|
/**
|
|
35
36
|
* 网格的宽度
|
|
36
37
|
* - 对于 `dot` 点状网格,表示点的大小
|
package/es/view/overlay/Grid.js
CHANGED
|
@@ -19,31 +19,6 @@ 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
|
-
};
|
|
47
22
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
48
23
|
import { Component } from 'preact/compat';
|
|
49
24
|
import { cloneDeep, assign } from 'lodash-es';
|
|
@@ -52,14 +27,15 @@ import { createUuid } from '../../util';
|
|
|
52
27
|
import { DEFAULT_GRID_SIZE } from '../../constant';
|
|
53
28
|
var Grid = /** @class */ (function (_super) {
|
|
54
29
|
__extends(Grid, _super);
|
|
55
|
-
function Grid() {
|
|
56
|
-
var _this = _super.
|
|
30
|
+
function Grid(props) {
|
|
31
|
+
var _this = _super.call(this, props) || this;
|
|
57
32
|
_this.id = createUuid();
|
|
33
|
+
_this.gridOptions = _this.props.graphModel.grid;
|
|
58
34
|
return _this;
|
|
59
35
|
}
|
|
60
36
|
// 网格类型为点状
|
|
61
37
|
Grid.prototype.renderDot = function () {
|
|
62
|
-
var _a = this.
|
|
38
|
+
var _a = this.gridOptions, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
|
|
63
39
|
var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 2 : _d;
|
|
64
40
|
// 对于点状网格,点的半径不能大于网格大小的四分之一
|
|
65
41
|
var radius = Math.min(Math.max(2, thickness), size / 4);
|
|
@@ -69,16 +45,17 @@ var Grid = /** @class */ (function (_super) {
|
|
|
69
45
|
// 网格类型为交叉线
|
|
70
46
|
// todo: 采用背景缩放的方式,实现更好的体验
|
|
71
47
|
Grid.prototype.renderMesh = function () {
|
|
72
|
-
var _a = this.
|
|
48
|
+
var _a = this.gridOptions, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
|
|
73
49
|
var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 1 : _d;
|
|
74
50
|
// 对于交叉线网格,线的宽度不能大于网格大小的一半
|
|
75
51
|
var strokeWidth = Math.min(Math.max(1, thickness), size / 2);
|
|
76
52
|
var d = "M 0 0 H ".concat(size, " V ").concat(size, " H 0 Z");
|
|
77
53
|
var opacity = visible ? 1 : 0;
|
|
78
|
-
return (_jsx("path", { d: d, stroke: color, strokeWidth: strokeWidth, opacity: opacity, fill: "transparent" }));
|
|
54
|
+
return (_jsx("path", { d: d, stroke: color, strokeWidth: strokeWidth / 2, opacity: opacity, fill: "transparent" }));
|
|
79
55
|
};
|
|
80
56
|
Grid.prototype.render = function () {
|
|
81
|
-
var
|
|
57
|
+
var transformModel = this.props.graphModel.transformModel;
|
|
58
|
+
var _a = this.gridOptions, type = _a.type, _b = _a.size, size = _b === void 0 ? 1 : _b;
|
|
82
59
|
var SCALE_X = transformModel.SCALE_X, SKEW_Y = transformModel.SKEW_Y, SKEW_X = transformModel.SKEW_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
|
|
83
60
|
var matrixString = [
|
|
84
61
|
SCALE_X,
|
package/es/view/text/BaseText.js
CHANGED
|
@@ -61,7 +61,7 @@ var BaseText = /** @class */ (function (_super) {
|
|
|
61
61
|
_this.onDragging = function (_a) {
|
|
62
62
|
var deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
63
63
|
var _b = _this.props, model = _b.model, transformModel = _b.graphModel.transformModel;
|
|
64
|
-
if (deltaX
|
|
64
|
+
if (deltaX || deltaY) {
|
|
65
65
|
var _c = __read(transformModel.fixDeltaXY(deltaX, deltaY), 2), curDeltaX = _c[0], curDeltaY = _c[1];
|
|
66
66
|
model.moveText(curDeltaX, curDeltaY);
|
|
67
67
|
}
|
|
@@ -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,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.radianToAngle = exports.angleToRadian = exports.calculatePointAfterRotateAngle = exports.getNewCenter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 根据两个点获取中心点坐标
|
|
6
|
+
*/
|
|
7
|
+
function getNewCenter(startPoint, endPoint) {
|
|
8
|
+
var x1 = startPoint.x, y1 = startPoint.y;
|
|
9
|
+
var x2 = endPoint.x, y2 = endPoint.y;
|
|
10
|
+
var newCenter = {
|
|
11
|
+
x: x1 + (x2 - x1) / 2,
|
|
12
|
+
y: y1 + (y2 - y1) / 2,
|
|
13
|
+
};
|
|
14
|
+
return newCenter;
|
|
15
|
+
}
|
|
16
|
+
exports.getNewCenter = getNewCenter;
|
|
17
|
+
/**
|
|
18
|
+
* 旋转矩阵公式,可以获取某一个坐标旋转angle后的坐标
|
|
19
|
+
* @param p 当前坐标
|
|
20
|
+
* @param center 旋转中心
|
|
21
|
+
* @param angle 旋转角度(不是弧度)
|
|
22
|
+
*/
|
|
23
|
+
function calculatePointAfterRotateAngle(p, center, angle) {
|
|
24
|
+
var radian = angleToRadian(angle);
|
|
25
|
+
var dx = p.x - center.x;
|
|
26
|
+
var dy = p.y - center.y;
|
|
27
|
+
var x = dx * Math.cos(radian) - dy * Math.sin(radian) + center.x;
|
|
28
|
+
var y = dx * Math.sin(radian) + dy * Math.cos(radian) + center.y;
|
|
29
|
+
return {
|
|
30
|
+
x: x,
|
|
31
|
+
y: y,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.calculatePointAfterRotateAngle = calculatePointAfterRotateAngle;
|
|
35
|
+
/**
|
|
36
|
+
* 角度转弧度
|
|
37
|
+
* @param angle 角度
|
|
38
|
+
*/
|
|
39
|
+
function angleToRadian(angle) {
|
|
40
|
+
return (angle * Math.PI) / 180;
|
|
41
|
+
}
|
|
42
|
+
exports.angleToRadian = angleToRadian;
|
|
43
|
+
/**
|
|
44
|
+
* 弧度转角度
|
|
45
|
+
* @param radian 弧度
|
|
46
|
+
*/
|
|
47
|
+
function radianToAngle(radian) {
|
|
48
|
+
return (radian / Math.PI) * 180;
|
|
49
|
+
}
|
|
50
|
+
exports.radianToAngle = radianToAngle;
|