@logicflow/core 2.1.0 → 2.1.2
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 +7 -7
- package/CHANGELOG.md +12 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.js +3 -0
- package/es/constant/index.d.ts +3 -1
- package/es/constant/index.js +2 -0
- package/es/model/EditConfigModel.d.ts +1 -1
- package/es/model/GraphModel.js +3 -2
- package/es/model/NestedTransformModel.d.ts +52 -0
- package/es/model/NestedTransformModel.js +129 -0
- package/es/model/index.d.ts +1 -0
- package/es/model/index.js +1 -0
- package/es/options.d.ts +2 -0
- package/es/view/behavior/dnd.js +3 -0
- package/es/view/node/BaseNode.js +0 -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 +1 -1
- package/lib/model/GraphModel.js +2 -1
- package/lib/model/NestedTransformModel.d.ts +52 -0
- package/lib/model/NestedTransformModel.js +132 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +1 -0
- package/lib/options.d.ts +2 -0
- package/lib/view/behavior/dnd.js +3 -0
- package/lib/view/node/BaseNode.js +0 -1
- package/package.json +1 -1
- package/src/model/GraphModel.ts +3 -1
- package/src/model/NestedTransformModel.ts +121 -0
- package/src/model/index.ts +1 -0
- package/src/options.ts +5 -0
- package/src/view/node/BaseNode.tsx +0 -1
- package/stats.html +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import LogicFlow from '../LogicFlow'
|
|
2
|
+
import { TransformModel } from './TransformModel'
|
|
3
|
+
import { Options as LFOptions } from '../options'
|
|
4
|
+
import EventEmitter from '../event/eventEmitter'
|
|
5
|
+
type PointTuple = LogicFlow.PointTuple
|
|
6
|
+
|
|
7
|
+
export class NestedTransformModel extends TransformModel {
|
|
8
|
+
parentTransform?: TransformModel
|
|
9
|
+
|
|
10
|
+
constructor(eventCenter: EventEmitter, options: LFOptions.Common) {
|
|
11
|
+
super(eventCenter, options)
|
|
12
|
+
this.parentTransform = options.parentTransform
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 设置父级变换
|
|
17
|
+
* @param parentTransform 父级变换模型
|
|
18
|
+
*/
|
|
19
|
+
setParentTransform(parentTransform: TransformModel) {
|
|
20
|
+
this.parentTransform = parentTransform
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 获取累积的缩放值
|
|
25
|
+
* 计算包括所有父级的累积缩放
|
|
26
|
+
*/
|
|
27
|
+
private getCumulativeScale(): { scaleX: number; scaleY: number } {
|
|
28
|
+
let scaleX = this.SCALE_X
|
|
29
|
+
let scaleY = this.SCALE_Y
|
|
30
|
+
|
|
31
|
+
if (this.parentTransform) {
|
|
32
|
+
if (this.parentTransform instanceof NestedTransformModel) {
|
|
33
|
+
const parentScale = this.parentTransform.getCumulativeScale()
|
|
34
|
+
scaleX *= parentScale.scaleX
|
|
35
|
+
scaleY *= parentScale.scaleY
|
|
36
|
+
} else {
|
|
37
|
+
scaleX *= this.parentTransform.SCALE_X
|
|
38
|
+
scaleY *= this.parentTransform.SCALE_Y
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { scaleX, scaleY }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 获取累积的平移值
|
|
47
|
+
* 计算包括所有父级的累积平移
|
|
48
|
+
*/
|
|
49
|
+
private getCumulativeTranslate(): { translateX: number; translateY: number } {
|
|
50
|
+
let translateX = this.TRANSLATE_X
|
|
51
|
+
let translateY = this.TRANSLATE_Y
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
this.parentTransform &&
|
|
55
|
+
this.parentTransform instanceof NestedTransformModel
|
|
56
|
+
) {
|
|
57
|
+
const { scaleX, scaleY } = this.parentTransform.getCumulativeScale()
|
|
58
|
+
translateX = scaleX * translateX
|
|
59
|
+
translateY = scaleY * translateY
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { translateX, translateY }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 将最外层graph上的点基于缩放转换为canvasOverlay层上的点。
|
|
67
|
+
* 重写以支持嵌套变换
|
|
68
|
+
* @param point HTML点
|
|
69
|
+
*/
|
|
70
|
+
HtmlPointToCanvasPoint(point: PointTuple): PointTuple {
|
|
71
|
+
const [x, y] = point
|
|
72
|
+
const { scaleX, scaleY } = this.getCumulativeScale()
|
|
73
|
+
const { translateX, translateY } = this.getCumulativeTranslate()
|
|
74
|
+
|
|
75
|
+
return [(x - translateX) / scaleX, (y - translateY) / scaleY]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 将最外层canvasOverlay层上的点基于缩放转换为graph上的点。
|
|
80
|
+
* 重写以支持嵌套变换
|
|
81
|
+
* @param point Canvas点
|
|
82
|
+
*/
|
|
83
|
+
CanvasPointToHtmlPoint(point: PointTuple): PointTuple {
|
|
84
|
+
const [x, y] = point
|
|
85
|
+
const { scaleX, scaleY } = this.getCumulativeScale()
|
|
86
|
+
const { translateX, translateY } = this.getCumulativeTranslate()
|
|
87
|
+
|
|
88
|
+
return [x * scaleX + translateX, y * scaleY + translateY]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 将一个在canvas上的点,向x轴方向移动directionX距离,向y轴方向移动directionY距离。
|
|
93
|
+
* 重写以支持嵌套变换
|
|
94
|
+
* @param point 点
|
|
95
|
+
* @param directionX x轴距离
|
|
96
|
+
* @param directionY y轴距离
|
|
97
|
+
*/
|
|
98
|
+
moveCanvasPointByHtml(
|
|
99
|
+
point: PointTuple,
|
|
100
|
+
directionX: number,
|
|
101
|
+
directionY: number,
|
|
102
|
+
): PointTuple {
|
|
103
|
+
const [x, y] = point
|
|
104
|
+
const { scaleX, scaleY } = this.getCumulativeScale()
|
|
105
|
+
|
|
106
|
+
return [x + directionX / scaleX, y + directionY / scaleY]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 根据缩放情况,获取缩放后的delta距离
|
|
111
|
+
* 重写以支持嵌套变换
|
|
112
|
+
* @param deltaX x轴距离变化
|
|
113
|
+
* @param deltaY y轴距离变化
|
|
114
|
+
*/
|
|
115
|
+
fixDeltaXY(deltaX: number, deltaY: number): PointTuple {
|
|
116
|
+
const { scaleX, scaleY } = this.getCumulativeScale()
|
|
117
|
+
return [deltaX / scaleX, deltaY / scaleY]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default NestedTransformModel
|
package/src/model/index.ts
CHANGED
package/src/options.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TransformModel } from './model'
|
|
2
|
+
|
|
1
3
|
import { assign } from 'lodash-es'
|
|
2
4
|
import { createElement as h } from 'preact/compat'
|
|
3
5
|
import LogicFlow from './LogicFlow'
|
|
@@ -104,6 +106,9 @@ export namespace Options {
|
|
|
104
106
|
|
|
105
107
|
customTrajectory?: (props: CustomAnchorLineProps) => h.JSX.Element
|
|
106
108
|
themeMode?: 'radius' | 'dark' | 'colorful' // 主题模式
|
|
109
|
+
|
|
110
|
+
parentTransform?: TransformModel // 父级变换模型,用于嵌套变换
|
|
111
|
+
|
|
107
112
|
[key: string]: unknown
|
|
108
113
|
}
|
|
109
114
|
|
|
@@ -427,7 +427,6 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
427
427
|
const { model, graphModel } = this.props
|
|
428
428
|
this.startTime = new Date().getTime()
|
|
429
429
|
const { editConfigModel } = graphModel
|
|
430
|
-
model.setSelected(true)
|
|
431
430
|
if (editConfigModel.adjustNodePosition && model.draggable) {
|
|
432
431
|
this.stepDrag && this.stepDrag.handleMouseDown(ev)
|
|
433
432
|
}
|