@logicflow/core 2.2.0-alpha.7 → 2.2.1
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/package.json +6 -1
- package/.turbo/turbo-build$colon$dev.log +0 -10
- package/.turbo/turbo-build.log +0 -33
- package/CHANGELOG.md +0 -1901
- package/__tests__/algorithm/egde.test.ts +0 -131
- package/__tests__/algorithm/index.test.ts +0 -74
- package/__tests__/algorithm/outline.test.ts +0 -43
- package/__tests__/bugs/1545-spec.test.ts +0 -42
- package/__tests__/event/event.test.ts +0 -22
- package/__tests__/history/history.test.ts +0 -28
- package/__tests__/logicflow.test.ts +0 -575
- package/__tests__/model/graphmodel.test.ts +0 -87
- package/__tests__/util/compatible.test.ts +0 -48
- package/__tests__/util/edge.test.ts +0 -224
- package/__tests__/util/geometry.test.ts +0 -14
- package/__tests__/util/graph.test.ts +0 -16
- package/__tests__/util/matrix.test.ts +0 -41
- package/__tests__/util/node.test.ts +0 -68
- package/__tests__/util/sampling.test.ts +0 -12
- package/__tests__/util/vector.test.ts +0 -50
- package/__tests__/util/zIndex.test.ts +0 -10
- package/src/LogicFlow.tsx +0 -2017
- package/src/algorithm/edge.ts +0 -67
- package/src/algorithm/index.ts +0 -70
- package/src/algorithm/outline.ts +0 -77
- package/src/algorithm/rotate.ts +0 -55
- package/src/common/drag.ts +0 -219
- package/src/common/history.ts +0 -108
- package/src/common/index.ts +0 -6
- package/src/common/keyboard.ts +0 -108
- package/src/common/matrix.ts +0 -122
- package/src/common/vector.ts +0 -93
- package/src/constant/index.ts +0 -179
- package/src/constant/theme.ts +0 -708
- package/src/event/event.md +0 -66
- package/src/event/eventArgs.ts +0 -643
- package/src/event/eventEmitter.ts +0 -156
- package/src/history/index.ts +0 -119
- package/src/index.less +0 -1
- package/src/index.ts +0 -26
- package/src/keyboard/index.ts +0 -112
- package/src/keyboard/shortcut.ts +0 -200
- package/src/model/BaseModel.ts +0 -250
- package/src/model/EditConfigModel.ts +0 -334
- package/src/model/GraphModel.ts +0 -1824
- package/src/model/NestedTransformModel.ts +0 -121
- package/src/model/SnaplineModel.ts +0 -256
- package/src/model/TransformModel.ts +0 -258
- package/src/model/edge/BaseEdgeModel.ts +0 -785
- package/src/model/edge/BezierEdgeModel.ts +0 -197
- package/src/model/edge/LineEdgeModel.ts +0 -36
- package/src/model/edge/PolylineEdgeModel.ts +0 -817
- package/src/model/edge/index.ts +0 -4
- package/src/model/index.ts +0 -9
- package/src/model/node/BaseNodeModel.ts +0 -959
- package/src/model/node/CircleNodeModel.ts +0 -91
- package/src/model/node/DiamondNodeModel.ts +0 -132
- package/src/model/node/EllipseNodeModel.ts +0 -98
- package/src/model/node/HtmlNodeModel.ts +0 -64
- package/src/model/node/PolygonNodeModel.ts +0 -152
- package/src/model/node/RectNodeModel.ts +0 -69
- package/src/model/node/TextNodeModel.ts +0 -54
- package/src/model/node/index.ts +0 -8
- package/src/options.ts +0 -150
- package/src/style/index.less +0 -262
- package/src/style/raw.ts +0 -221
- package/src/tool/MultipleSelectTool.tsx +0 -140
- package/src/tool/TextEditTool.tsx +0 -193
- package/src/tool/index.ts +0 -101
- package/src/typings.d.ts +0 -5
- package/src/util/animation.ts +0 -29
- package/src/util/browser.ts +0 -4
- package/src/util/compatible.ts +0 -15
- package/src/util/drag.ts +0 -219
- package/src/util/edge.ts +0 -1094
- package/src/util/geometry.ts +0 -154
- package/src/util/graph.ts +0 -46
- package/src/util/index.ts +0 -17
- package/src/util/matrix.ts +0 -129
- package/src/util/mobx.ts +0 -23
- package/src/util/node.ts +0 -543
- package/src/util/raf.ts +0 -28
- package/src/util/resize.ts +0 -606
- package/src/util/sampling.ts +0 -85
- package/src/util/theme.ts +0 -84
- package/src/util/uuid.ts +0 -26
- package/src/util/vector.ts +0 -93
- package/src/util/zIndex.ts +0 -6
- package/src/view/Anchor.tsx +0 -462
- package/src/view/Control.tsx +0 -510
- package/src/view/Graph.tsx +0 -141
- package/src/view/Rotate.tsx +0 -113
- package/src/view/behavior/dnd.ts +0 -162
- package/src/view/behavior/index.ts +0 -2
- package/src/view/behavior/snapline.ts +0 -16
- package/src/view/edge/AdjustPoint.tsx +0 -425
- package/src/view/edge/Arrow.tsx +0 -54
- package/src/view/edge/BaseEdge.tsx +0 -660
- package/src/view/edge/BezierEdge.tsx +0 -101
- package/src/view/edge/LineEdge.tsx +0 -81
- package/src/view/edge/PolylineEdge.tsx +0 -311
- package/src/view/edge/index.ts +0 -6
- package/src/view/index.ts +0 -8
- package/src/view/node/BaseNode.tsx +0 -585
- package/src/view/node/CircleNode.tsx +0 -21
- package/src/view/node/DiamondNode.tsx +0 -24
- package/src/view/node/EllipseNode.tsx +0 -22
- package/src/view/node/HtmlNode.tsx +0 -112
- package/src/view/node/PolygonNode.tsx +0 -28
- package/src/view/node/RectNode.tsx +0 -30
- package/src/view/node/TextNode.tsx +0 -39
- package/src/view/node/index.ts +0 -8
- package/src/view/overlay/BackgroundOverlay.tsx +0 -34
- package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
- package/src/view/overlay/CanvasOverlay.tsx +0 -290
- package/src/view/overlay/Grid.tsx +0 -319
- package/src/view/overlay/ModificationOverlay.tsx +0 -31
- package/src/view/overlay/OutlineOverlay.tsx +0 -158
- package/src/view/overlay/SnaplineOverlay.tsx +0 -44
- package/src/view/overlay/ToolOverlay.tsx +0 -65
- package/src/view/overlay/getTransformHoc.tsx +0 -50
- package/src/view/overlay/gridConfig.ts +0 -103
- package/src/view/overlay/index.ts +0 -8
- package/src/view/shape/Circle.tsx +0 -41
- package/src/view/shape/Ellipse.tsx +0 -42
- package/src/view/shape/Line.tsx +0 -39
- package/src/view/shape/Path.tsx +0 -22
- package/src/view/shape/Polygon.tsx +0 -54
- package/src/view/shape/Polyline.tsx +0 -31
- package/src/view/shape/Rect.tsx +0 -44
- package/src/view/shape/Text.tsx +0 -168
- package/src/view/shape/index.ts +0 -8
- package/src/view/text/BaseText.tsx +0 -134
- package/src/view/text/LineText.tsx +0 -168
- package/src/view/text/index.ts +0 -2
- package/stats.html +0 -4842
- package/tsconfig.json +0 -18
package/src/algorithm/edge.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import LogicFlow from '../LogicFlow'
|
|
2
|
-
|
|
3
|
-
import Point = LogicFlow.Point
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 求两个线段交点入参:线段1端点: ab, 线段2端点: cd,
|
|
7
|
-
* @param a
|
|
8
|
-
* @param b
|
|
9
|
-
* @param c
|
|
10
|
-
* @param d
|
|
11
|
-
* @return:有交点返回交点 Point,无交点返回false
|
|
12
|
-
*/
|
|
13
|
-
export const getCrossPointOfLine = (a: Point, b: Point, c: Point, d: Point) => {
|
|
14
|
-
/** 1 解线性方程组, 求线段交点. * */
|
|
15
|
-
// 如果分母为0 则平行或共线, 不相交
|
|
16
|
-
const denominator = (b.y - a.y) * (d.x - c.x) - (a.x - b.x) * (c.y - d.y)
|
|
17
|
-
if (denominator === 0) {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
// 线段所在直线的交点坐标 (x , y)
|
|
21
|
-
const x =
|
|
22
|
-
((b.x - a.x) * (d.x - c.x) * (c.y - a.y) +
|
|
23
|
-
(b.y - a.y) * (d.x - c.x) * a.x -
|
|
24
|
-
(d.y - c.y) * (b.x - a.x) * c.x) /
|
|
25
|
-
denominator
|
|
26
|
-
const y =
|
|
27
|
-
-(
|
|
28
|
-
(b.y - a.y) * (d.y - c.y) * (c.x - a.x) +
|
|
29
|
-
(b.x - a.x) * (d.y - c.y) * a.y -
|
|
30
|
-
(d.x - c.x) * (b.y - a.y) * c.y
|
|
31
|
-
) / denominator
|
|
32
|
-
|
|
33
|
-
/** 2 判断交点是否在两条线段上 * */
|
|
34
|
-
if (
|
|
35
|
-
// 交点在线段1上
|
|
36
|
-
(x - a.x) * (x - b.x) <= 0 &&
|
|
37
|
-
(y - a.y) * (y - b.y) <= 0 &&
|
|
38
|
-
// 且交点也在线段2上
|
|
39
|
-
(x - c.x) * (x - d.x) <= 0 &&
|
|
40
|
-
(y - c.y) * (y - d.y) <= 0
|
|
41
|
-
) {
|
|
42
|
-
// 返回交点p
|
|
43
|
-
return {
|
|
44
|
-
x,
|
|
45
|
-
y,
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// 否则不相交
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/* 判断一个点是否在线段中
|
|
53
|
-
入参点:point, 线段起终点,start,end,
|
|
54
|
-
返回值: 在线段中true,否则false
|
|
55
|
-
*/
|
|
56
|
-
export const isInSegment = (point: Point, start: Point, end: Point) => {
|
|
57
|
-
const { x, y } = point
|
|
58
|
-
const { x: startX, y: startY } = start
|
|
59
|
-
const { x: endX, y: endY } = end
|
|
60
|
-
const k = (endY - startY) / (endX - startX)
|
|
61
|
-
const b = startY - k * startX
|
|
62
|
-
return (
|
|
63
|
-
((x >= startX && x <= endX) || (x <= startX && x >= endX)) &&
|
|
64
|
-
((y >= startY && y <= endY) || (y <= startY && y >= endY)) &&
|
|
65
|
-
Math.abs(y - k * x - b) < Number.EPSILON
|
|
66
|
-
)
|
|
67
|
-
}
|
package/src/algorithm/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// 各类算法的实现
|
|
2
|
-
export * from './outline'
|
|
3
|
-
export * from './edge'
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* 计算垂直边的与起始点有一定距离对称,边垂直于边的点
|
|
7
|
-
* 调用方:计算箭头位置,计算扩大变得点击区域
|
|
8
|
-
*/
|
|
9
|
-
export const getVerticalPointOfLine = (config) => {
|
|
10
|
-
/*
|
|
11
|
-
** offset: 端点到垂直点的距离
|
|
12
|
-
** verticalLength: 两边点到垂直点的距离
|
|
13
|
-
** type: 标识求的是线段的开始端点/结束端点
|
|
14
|
-
*/
|
|
15
|
-
const { start, end, offset, verticalLength, type } = config
|
|
16
|
-
const pointPosition = {
|
|
17
|
-
leftX: 0,
|
|
18
|
-
leftY: 0,
|
|
19
|
-
rightX: 0,
|
|
20
|
-
rightY: 0,
|
|
21
|
-
}
|
|
22
|
-
// // 边与水平线的夹角
|
|
23
|
-
const angleOfHorizontal = Math.atan((end.y - start.y) / (end.x - start.x))
|
|
24
|
-
// 边和两边点的夹角
|
|
25
|
-
const angleOfPoints = Math.atan(offset / verticalLength)
|
|
26
|
-
// 点到起点的距离
|
|
27
|
-
const len = Math.sqrt(verticalLength * verticalLength + offset * offset)
|
|
28
|
-
if (type === 'start') {
|
|
29
|
-
if (end.x >= start.x) {
|
|
30
|
-
pointPosition.leftX =
|
|
31
|
-
start.x + len * Math.sin(angleOfHorizontal + angleOfPoints)
|
|
32
|
-
pointPosition.leftY =
|
|
33
|
-
start.y - len * Math.cos(angleOfHorizontal + angleOfPoints)
|
|
34
|
-
pointPosition.rightX =
|
|
35
|
-
start.x - len * Math.sin(angleOfHorizontal - angleOfPoints)
|
|
36
|
-
pointPosition.rightY =
|
|
37
|
-
start.y + len * Math.cos(angleOfHorizontal - angleOfPoints)
|
|
38
|
-
} else {
|
|
39
|
-
pointPosition.leftX =
|
|
40
|
-
start.x - len * Math.sin(angleOfHorizontal + angleOfPoints)
|
|
41
|
-
pointPosition.leftY =
|
|
42
|
-
start.y + len * Math.cos(angleOfHorizontal + angleOfPoints)
|
|
43
|
-
pointPosition.rightX =
|
|
44
|
-
start.x + len * Math.sin(angleOfHorizontal - angleOfPoints)
|
|
45
|
-
pointPosition.rightY =
|
|
46
|
-
start.y - len * Math.cos(angleOfHorizontal - angleOfPoints)
|
|
47
|
-
}
|
|
48
|
-
} else if (type === 'end') {
|
|
49
|
-
if (end.x >= start.x) {
|
|
50
|
-
pointPosition.leftX =
|
|
51
|
-
end.x + len * Math.sin(angleOfHorizontal - angleOfPoints)
|
|
52
|
-
pointPosition.leftY =
|
|
53
|
-
end.y - len * Math.cos(angleOfHorizontal - angleOfPoints)
|
|
54
|
-
pointPosition.rightX =
|
|
55
|
-
end.x - len * Math.sin(angleOfHorizontal + angleOfPoints)
|
|
56
|
-
pointPosition.rightY =
|
|
57
|
-
end.y + len * Math.cos(angleOfHorizontal + angleOfPoints)
|
|
58
|
-
} else {
|
|
59
|
-
pointPosition.leftX =
|
|
60
|
-
end.x - len * Math.sin(angleOfHorizontal - angleOfPoints)
|
|
61
|
-
pointPosition.leftY =
|
|
62
|
-
end.y + len * Math.cos(angleOfHorizontal - angleOfPoints)
|
|
63
|
-
pointPosition.rightX =
|
|
64
|
-
end.x + len * Math.sin(angleOfHorizontal + angleOfPoints)
|
|
65
|
-
pointPosition.rightY =
|
|
66
|
-
end.y - len * Math.cos(angleOfHorizontal + angleOfPoints)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return pointPosition
|
|
70
|
-
}
|
package/src/algorithm/outline.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { ModelType } from '../constant'
|
|
2
|
-
import {
|
|
3
|
-
Model,
|
|
4
|
-
BaseNodeModel,
|
|
5
|
-
BaseEdgeModel,
|
|
6
|
-
LineEdgeModel,
|
|
7
|
-
BezierEdgeModel,
|
|
8
|
-
PolylineEdgeModel,
|
|
9
|
-
} from '../model'
|
|
10
|
-
import { points2PointsList, getBBoxOfPoints, getBezierPoints } from '../util'
|
|
11
|
-
|
|
12
|
-
import OutlineInfo = Model.OutlineInfo
|
|
13
|
-
|
|
14
|
-
// 获取节点的out
|
|
15
|
-
export const getNodeOutline = (node: BaseNodeModel): OutlineInfo => {
|
|
16
|
-
const { x, y, width, height } = node
|
|
17
|
-
return {
|
|
18
|
-
x: x - width / 2,
|
|
19
|
-
y: y - height / 2,
|
|
20
|
-
x1: x + width / 2,
|
|
21
|
-
y1: y + height / 2,
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const getLineOutline = (edge: LineEdgeModel): OutlineInfo => {
|
|
26
|
-
const { startPoint, endPoint } = edge
|
|
27
|
-
const x = (startPoint.x + endPoint.x) / 2
|
|
28
|
-
const y = (startPoint.y + endPoint.y) / 2
|
|
29
|
-
const width = Math.abs(startPoint.x - endPoint.x) + 10
|
|
30
|
-
const height = Math.abs(startPoint.y - endPoint.y) + 10
|
|
31
|
-
return {
|
|
32
|
-
x: x - width / 2,
|
|
33
|
-
y: y - height / 2,
|
|
34
|
-
x1: x + width / 2,
|
|
35
|
-
y1: y + height / 2,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const getPolylineOutline = (edge: PolylineEdgeModel): OutlineInfo => {
|
|
40
|
-
const { points } = edge
|
|
41
|
-
const pointsList = points2PointsList(points)
|
|
42
|
-
const bbox = getBBoxOfPoints(pointsList, 8)
|
|
43
|
-
const { x, y, width, height } = bbox
|
|
44
|
-
return {
|
|
45
|
-
x: x - width / 2,
|
|
46
|
-
y: y - height / 2,
|
|
47
|
-
x1: x + width / 2,
|
|
48
|
-
y1: y + height / 2,
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const getBezierOutline = (edge: BezierEdgeModel): OutlineInfo => {
|
|
53
|
-
const { path } = edge
|
|
54
|
-
const pointsList = getBezierPoints(path)
|
|
55
|
-
const bbox = getBBoxOfPoints(pointsList, 8)
|
|
56
|
-
const { x, y, width, height } = bbox
|
|
57
|
-
return {
|
|
58
|
-
x: x - width / 2,
|
|
59
|
-
y: y - height / 2,
|
|
60
|
-
x1: x + width / 2,
|
|
61
|
-
y1: y + height / 2,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const getEdgeOutline = (
|
|
66
|
-
edge: BaseEdgeModel,
|
|
67
|
-
): OutlineInfo | undefined => {
|
|
68
|
-
if (edge.modelType === ModelType.LINE_EDGE) {
|
|
69
|
-
return getLineOutline(edge as LineEdgeModel)
|
|
70
|
-
}
|
|
71
|
-
if (edge.modelType === ModelType.POLYLINE_EDGE) {
|
|
72
|
-
return getPolylineOutline(edge as PolylineEdgeModel)
|
|
73
|
-
}
|
|
74
|
-
if (edge.modelType === ModelType.BEZIER_EDGE) {
|
|
75
|
-
return getBezierOutline(edge as BezierEdgeModel)
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/algorithm/rotate.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export interface SimplePoint {
|
|
2
|
-
x: number
|
|
3
|
-
y: number
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 根据两个点获取中心点坐标
|
|
8
|
-
*/
|
|
9
|
-
export function getNewCenter(startPoint: SimplePoint, endPoint: SimplePoint) {
|
|
10
|
-
const { x: x1, y: y1 } = startPoint
|
|
11
|
-
const { x: x2, y: y2 } = endPoint
|
|
12
|
-
const newCenter = {
|
|
13
|
-
x: x1 + (x2 - x1) / 2,
|
|
14
|
-
y: y1 + (y2 - y1) / 2,
|
|
15
|
-
}
|
|
16
|
-
return newCenter
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 旋转矩阵公式,可以获取某一个坐标旋转angle后的坐标
|
|
21
|
-
* @param p 当前坐标
|
|
22
|
-
* @param center 旋转中心
|
|
23
|
-
* @param angle 旋转角度(不是弧度)
|
|
24
|
-
*/
|
|
25
|
-
export function calculatePointAfterRotateAngle(
|
|
26
|
-
p: SimplePoint,
|
|
27
|
-
center: SimplePoint,
|
|
28
|
-
angle: number,
|
|
29
|
-
) {
|
|
30
|
-
const radian = angleToRadian(angle)
|
|
31
|
-
const dx = p.x - center.x
|
|
32
|
-
const dy = p.y - center.y
|
|
33
|
-
const x = dx * Math.cos(radian) - dy * Math.sin(radian) + center.x
|
|
34
|
-
const y = dx * Math.sin(radian) + dy * Math.cos(radian) + center.y
|
|
35
|
-
return {
|
|
36
|
-
x,
|
|
37
|
-
y,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 角度转弧度
|
|
43
|
-
* @param angle 角度
|
|
44
|
-
*/
|
|
45
|
-
export function angleToRadian(angle: number) {
|
|
46
|
-
return (angle * Math.PI) / 180
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 弧度转角度
|
|
51
|
-
* @param radian 弧度
|
|
52
|
-
*/
|
|
53
|
-
export function radianToAngle(radian: number) {
|
|
54
|
-
return (radian / Math.PI) * 180
|
|
55
|
-
}
|
package/src/common/drag.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { noop } from 'lodash-es'
|
|
2
|
-
import { Model } from '../model'
|
|
3
|
-
import { EventType } from '../constant'
|
|
4
|
-
import EventEmitter from '../event/eventEmitter'
|
|
5
|
-
|
|
6
|
-
// TODO:这种方式在同构项目中,会报错,该如何解决(是否要求用户控制在浏览器环境时才初始化)
|
|
7
|
-
// const DOC: any = window?.document
|
|
8
|
-
const LEFT_MOUSE_BUTTON_CODE = 0
|
|
9
|
-
|
|
10
|
-
export type IDragParams = {
|
|
11
|
-
deltaX: number
|
|
12
|
-
deltaY: number
|
|
13
|
-
event: MouseEvent | null
|
|
14
|
-
[key: string]: unknown
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type ICreateDragParams = {
|
|
18
|
-
onDragStart?: (params: Partial<IDragParams>) => void
|
|
19
|
-
onDragging?: (param: IDragParams) => void
|
|
20
|
-
onDragEnd?: (param: Partial<IDragParams>) => void
|
|
21
|
-
step?: number
|
|
22
|
-
isStopPropagation?: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type IStepperDragProps = {
|
|
26
|
-
eventType?:
|
|
27
|
-
| 'NODE'
|
|
28
|
-
| 'BLANK'
|
|
29
|
-
| 'SELECTION'
|
|
30
|
-
| 'ADJUST_POINT'
|
|
31
|
-
| 'TEXT'
|
|
32
|
-
| 'LABEL'
|
|
33
|
-
| ''
|
|
34
|
-
eventCenter?: EventEmitter
|
|
35
|
-
model?: Model.BaseModel
|
|
36
|
-
data?: Record<string, unknown>
|
|
37
|
-
[key: string]: unknown
|
|
38
|
-
} & Partial<ICreateDragParams>
|
|
39
|
-
/**
|
|
40
|
-
* 支持拖拽时按步长进行移动
|
|
41
|
-
* REMIND:在绘制的过程中因为放大缩小,移动的真实 step 是变化的
|
|
42
|
-
*/
|
|
43
|
-
export class StepperDrag {
|
|
44
|
-
// 初始化
|
|
45
|
-
onDragStart: (params: Partial<IDragParams>) => void
|
|
46
|
-
onDragging: (params: IDragParams) => void
|
|
47
|
-
onDragEnd: (params: Partial<IDragParams>) => void
|
|
48
|
-
|
|
49
|
-
step: number
|
|
50
|
-
isStopPropagation: boolean
|
|
51
|
-
eventType:
|
|
52
|
-
| 'NODE'
|
|
53
|
-
| 'BLANK'
|
|
54
|
-
| 'SELECTION'
|
|
55
|
-
| 'ADJUST_POINT'
|
|
56
|
-
| 'TEXT'
|
|
57
|
-
| 'LABEL'
|
|
58
|
-
| ''
|
|
59
|
-
eventCenter?: EventEmitter
|
|
60
|
-
model?: Model.BaseModel
|
|
61
|
-
data?: Record<string, unknown>
|
|
62
|
-
|
|
63
|
-
// 运行时
|
|
64
|
-
isDragging: boolean = false
|
|
65
|
-
isStartDrag: boolean = false
|
|
66
|
-
|
|
67
|
-
startX: number = 0
|
|
68
|
-
startY: number = 0
|
|
69
|
-
totalDeltaX: number = 0
|
|
70
|
-
totalDeltaY: number = 0
|
|
71
|
-
|
|
72
|
-
startTime?: number
|
|
73
|
-
constructor({
|
|
74
|
-
onDragStart = noop,
|
|
75
|
-
onDragging = noop,
|
|
76
|
-
onDragEnd = noop,
|
|
77
|
-
step = 1,
|
|
78
|
-
eventType = '',
|
|
79
|
-
isStopPropagation = true,
|
|
80
|
-
eventCenter,
|
|
81
|
-
model,
|
|
82
|
-
data,
|
|
83
|
-
}: IStepperDragProps) {
|
|
84
|
-
this.onDragStart = onDragStart
|
|
85
|
-
this.onDragging = onDragging
|
|
86
|
-
this.onDragEnd = onDragEnd
|
|
87
|
-
this.step = step
|
|
88
|
-
this.eventType = eventType
|
|
89
|
-
this.isStopPropagation = isStopPropagation
|
|
90
|
-
this.eventCenter = eventCenter
|
|
91
|
-
this.model = model
|
|
92
|
-
this.data = data
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
setStep(step: number) {
|
|
96
|
-
this.step = step
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
handleMouseMove = (e: MouseEvent) => {
|
|
100
|
-
if (this.isStopPropagation) e.stopPropagation()
|
|
101
|
-
if (!this.isStartDrag) return
|
|
102
|
-
|
|
103
|
-
this.totalDeltaX += e.clientX - this.startX
|
|
104
|
-
this.totalDeltaY += e.clientY - this.startY
|
|
105
|
-
this.startX = e.clientX
|
|
106
|
-
this.startY = e.clientY
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
this.step <= 1 ||
|
|
110
|
-
Math.abs(this.totalDeltaX) > this.step ||
|
|
111
|
-
Math.abs(this.totalDeltaY) > this.step
|
|
112
|
-
) {
|
|
113
|
-
const remainderX = this.totalDeltaX % this.step
|
|
114
|
-
const remainderY = this.totalDeltaY % this.step
|
|
115
|
-
|
|
116
|
-
const deltaX = this.totalDeltaX - remainderX
|
|
117
|
-
const deltaY = this.totalDeltaY - remainderY
|
|
118
|
-
|
|
119
|
-
this.totalDeltaX = remainderX
|
|
120
|
-
this.totalDeltaY = remainderY
|
|
121
|
-
|
|
122
|
-
const elementData = this.model?.getData()
|
|
123
|
-
// REMIND: 为了区分点击和拖动,在鼠标没有拖动时,不触发 dragstart。
|
|
124
|
-
if (!this.isDragging) {
|
|
125
|
-
if (this.eventType) {
|
|
126
|
-
this.eventCenter?.emit(EventType[`${this.eventType}_DRAGSTART`], {
|
|
127
|
-
e,
|
|
128
|
-
data: this.data || elementData,
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
this.onDragStart({ event: e })
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
this.isDragging = true
|
|
135
|
-
// REMIND: 为了让 dragstart 和 drag 不在同一个事件循环中,将 drag 事件放在下一个任务队列中。
|
|
136
|
-
// TODO: 测试用例是否可覆盖???
|
|
137
|
-
Promise.resolve().then(() => {
|
|
138
|
-
this.onDragging({ deltaX, deltaY, event: e })
|
|
139
|
-
if (this.eventType) {
|
|
140
|
-
this.eventCenter?.emit(EventType[`${this.eventType}_MOUSEMOVE`], {
|
|
141
|
-
e,
|
|
142
|
-
data: this.data || elementData,
|
|
143
|
-
})
|
|
144
|
-
this.eventCenter?.emit(EventType[`${this.eventType}_DRAG`], {
|
|
145
|
-
e,
|
|
146
|
-
data: this.data || elementData,
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
handleMouseUp = (e: MouseEvent) => {
|
|
154
|
-
const DOC: any = window?.document
|
|
155
|
-
|
|
156
|
-
this.isStartDrag = false
|
|
157
|
-
if (this.isStopPropagation) e.stopPropagation()
|
|
158
|
-
|
|
159
|
-
// fix: issue#568, 如果 onDragging 在下一个时间循环中触发,而 drop 在当前事件循环,会出现问题
|
|
160
|
-
Promise.resolve().then(() => {
|
|
161
|
-
DOC?.removeEventListener('mousemove', this.handleMouseMove, true)
|
|
162
|
-
DOC?.removeEventListener('mouseup', this.handleMouseUp, true)
|
|
163
|
-
|
|
164
|
-
const elementData = this.model?.getData()
|
|
165
|
-
if (this.eventType) {
|
|
166
|
-
this.eventCenter?.emit(EventType[`${this.eventType}_MOUSEUP`], {
|
|
167
|
-
e,
|
|
168
|
-
data: this.data || elementData,
|
|
169
|
-
})
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (!this.isDragging) return
|
|
173
|
-
this.isDragging = false
|
|
174
|
-
this.onDragEnd({ event: e })
|
|
175
|
-
if (this.eventType) {
|
|
176
|
-
this.eventCenter?.emit(EventType[`${this.eventType}_DROP`], {
|
|
177
|
-
e,
|
|
178
|
-
data: this.data || elementData,
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
handleMouseDown = (e: MouseEvent) => {
|
|
185
|
-
const DOC: any = window?.document
|
|
186
|
-
|
|
187
|
-
// issue: LogicFlow交流群-3群 8.10 号抛出的事件相关的问题,是否是这引起的???
|
|
188
|
-
if (e.button !== LEFT_MOUSE_BUTTON_CODE) return
|
|
189
|
-
if (this.isStopPropagation) e.stopPropagation()
|
|
190
|
-
|
|
191
|
-
this.isStartDrag = true
|
|
192
|
-
this.startX = e.clientX
|
|
193
|
-
this.startY = e.clientY
|
|
194
|
-
|
|
195
|
-
DOC?.addEventListener('mousemove', this.handleMouseMove, true)
|
|
196
|
-
DOC?.addEventListener('mouseup', this.handleMouseUp, true)
|
|
197
|
-
|
|
198
|
-
const elementData = this.model?.getData()
|
|
199
|
-
if (this.eventType) {
|
|
200
|
-
this.eventCenter?.emit(EventType[`${this.eventType}_MOUSEDOWN`], {
|
|
201
|
-
e,
|
|
202
|
-
data: this.data || elementData,
|
|
203
|
-
})
|
|
204
|
-
}
|
|
205
|
-
this.startTime = new Date().getTime()
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
cancelDrag = () => {
|
|
209
|
-
const DOC: any = window?.document
|
|
210
|
-
|
|
211
|
-
DOC?.removeEventListener('mousemove', this.handleMouseMove, true)
|
|
212
|
-
DOC?.removeEventListener('mouseup', this.handleMouseUp, true)
|
|
213
|
-
|
|
214
|
-
this.onDragEnd({ event: null })
|
|
215
|
-
this.isDragging = false
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export default StepperDrag
|
package/src/common/history.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, debounce, isEqual, last } from 'lodash-es'
|
|
2
|
-
import { deepObserve, IDisposer } from 'mobx-utils'
|
|
3
|
-
import { LogicFlow } from '../LogicFlow'
|
|
4
|
-
// import { EventType } from '../constant'
|
|
5
|
-
import { GraphModel } from '../model'
|
|
6
|
-
import EventEmitter from '../event/eventEmitter'
|
|
7
|
-
|
|
8
|
-
export type HistoryData = LogicFlow.GraphConfigData
|
|
9
|
-
|
|
10
|
-
export class History {
|
|
11
|
-
undos: HistoryData[] = []
|
|
12
|
-
redos: HistoryData[] = []
|
|
13
|
-
stopWatch: IDisposer | null = null
|
|
14
|
-
curData: HistoryData | null = null
|
|
15
|
-
maxSize: number = 50
|
|
16
|
-
// 发生数据变化后,最多再等 500ms,把距离上次的数据变更存储起来。
|
|
17
|
-
// 所以 waitTime 值越小,History 对数据变化越敏感,存的 undos 数据就越细
|
|
18
|
-
waitTime: number = 100
|
|
19
|
-
eventCenter: EventEmitter
|
|
20
|
-
|
|
21
|
-
constructor(eventCenter: EventEmitter) {
|
|
22
|
-
this.eventCenter = eventCenter
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
add(data: HistoryData) {
|
|
26
|
-
if (isEqual(last(this.undos), data)) return
|
|
27
|
-
this.undos.push(data)
|
|
28
|
-
|
|
29
|
-
// 因为 undo 的时候会触发 add.
|
|
30
|
-
// 所以需要区分这个 add 是 undo 触发的还是用户正常操作触发的
|
|
31
|
-
// 如果是用户正常操作触发的,需要清空 redos
|
|
32
|
-
if (!isEqual(this.curData, data)) {
|
|
33
|
-
this.redos = []
|
|
34
|
-
}
|
|
35
|
-
// this.eventCenter.emit(EventType.HISTORY_CHANGE, {
|
|
36
|
-
// data: {
|
|
37
|
-
// undos: this.undos,
|
|
38
|
-
// redos: this.redos,
|
|
39
|
-
// undoAble: this.undos.length > 1,
|
|
40
|
-
// redoAble: this.redos.length > 0,
|
|
41
|
-
// },
|
|
42
|
-
// })
|
|
43
|
-
|
|
44
|
-
if (this.undos.length > this.maxSize) {
|
|
45
|
-
this.undos.shift()
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
undoAble() {
|
|
50
|
-
return this.undos.length > 1
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* undo 方法触发:
|
|
55
|
-
* graphModel 重新渲染 nodes 和 edges
|
|
56
|
-
* graphModel 发生变化,触发 watch
|
|
57
|
-
* watch 触发 add
|
|
58
|
-
*/
|
|
59
|
-
undo() {
|
|
60
|
-
if (!this.undoAble()) return
|
|
61
|
-
const preData = this.undos.pop()
|
|
62
|
-
if (preData) {
|
|
63
|
-
this.redos.push(preData)
|
|
64
|
-
}
|
|
65
|
-
const curData = this.undos.pop()
|
|
66
|
-
if (curData) {
|
|
67
|
-
this.curData = cloneDeep(curData)
|
|
68
|
-
}
|
|
69
|
-
return curData
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
redoAble() {
|
|
73
|
-
return this.redos.length > 0
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
redo() {
|
|
77
|
-
if (!this.redoAble()) return
|
|
78
|
-
const curData = this.redos.pop()
|
|
79
|
-
if (curData) {
|
|
80
|
-
this.curData = cloneDeep(curData)
|
|
81
|
-
}
|
|
82
|
-
return curData
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
watch(model: GraphModel) {
|
|
86
|
-
this.stopWatch && this.stopWatch()
|
|
87
|
-
|
|
88
|
-
// 把当前 watch 的 model 转换一下数据存起来,无需清空 redos
|
|
89
|
-
const historyData = model.modelToHistoryData()
|
|
90
|
-
if (historyData) {
|
|
91
|
-
this.undos.push(historyData)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.stopWatch = deepObserve(
|
|
95
|
-
model,
|
|
96
|
-
debounce(() => {
|
|
97
|
-
// 数据变更后,把最新的当前 model 数据存起来,并清空 redos
|
|
98
|
-
// 因为这个回调函数的触发,一般是用户交互而引起的,所以按照正常逻辑需要清空 redos
|
|
99
|
-
const data = model.modelToHistoryData()
|
|
100
|
-
if (data) {
|
|
101
|
-
this.add(data)
|
|
102
|
-
}
|
|
103
|
-
}, this.waitTime),
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default History
|