@logicflow/core 2.0.6 → 2.0.8
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 +3 -19
- package/CHANGELOG.md +31 -0
- package/__tests__/algorithm/egde.test.ts +36 -23
- package/dist/index.css +3 -0
- package/es/algorithm/edge.js +3 -5
- package/es/constant/index.d.ts +4 -0
- package/es/constant/index.js +4 -0
- package/es/event/eventArgs.d.ts +40 -30
- package/es/index.css +3 -0
- package/es/model/GraphModel.d.ts +13 -3
- package/es/model/GraphModel.js +54 -3
- package/es/model/edge/BaseEdgeModel.d.ts +1 -0
- package/es/model/edge/LineEdgeModel.d.ts +2 -0
- package/es/model/edge/LineEdgeModel.js +8 -0
- package/es/model/edge/PolylineEdgeModel.d.ts +1 -0
- package/es/model/edge/PolylineEdgeModel.js +4 -3
- package/es/model/node/BaseNodeModel.d.ts +2 -2
- package/es/model/node/BaseNodeModel.js +1 -1
- package/es/model/node/HtmlNodeModel.d.ts +2 -2
- package/es/model/node/TextNodeModel.d.ts +2 -2
- package/es/style/index.css +3 -0
- package/es/style/index.less +5 -0
- package/es/style/raw.d.ts +1 -1
- package/es/style/raw.js +1 -1
- package/es/util/drag.d.ts +1 -0
- package/es/util/drag.js +11 -0
- package/es/view/Anchor.js +6 -8
- package/es/view/Control.js +1 -1
- package/es/view/Graph.js +3 -15
- package/es/view/behavior/dnd.js +1 -0
- package/es/view/edge/BaseEdge.d.ts +5 -1
- package/es/view/edge/BaseEdge.js +20 -5
- package/es/view/node/BaseNode.d.ts +2 -0
- package/es/view/node/BaseNode.js +13 -1
- package/es/view/overlay/BackgroundOverlay.d.ts +4 -14
- package/es/view/overlay/BackgroundOverlay.js +12 -1
- package/es/view/overlay/Grid.d.ts +4 -3
- package/es/view/overlay/Grid.js +8 -31
- package/es/view/overlay/getTransformHoc.d.ts +1 -1
- package/es/view/text/BaseText.js +1 -1
- package/lib/algorithm/edge.js +3 -5
- package/lib/constant/index.d.ts +4 -0
- package/lib/constant/index.js +4 -0
- package/lib/event/eventArgs.d.ts +40 -30
- package/lib/index.css +3 -0
- package/lib/model/GraphModel.d.ts +13 -3
- package/lib/model/GraphModel.js +53 -2
- package/lib/model/edge/BaseEdgeModel.d.ts +1 -0
- package/lib/model/edge/LineEdgeModel.d.ts +2 -0
- package/lib/model/edge/LineEdgeModel.js +8 -0
- package/lib/model/edge/PolylineEdgeModel.d.ts +1 -0
- package/lib/model/edge/PolylineEdgeModel.js +4 -3
- package/lib/model/node/BaseNodeModel.d.ts +2 -2
- package/lib/model/node/BaseNodeModel.js +1 -1
- package/lib/model/node/HtmlNodeModel.d.ts +2 -2
- package/lib/model/node/TextNodeModel.d.ts +2 -2
- package/lib/style/index.css +3 -0
- package/lib/style/index.less +5 -0
- package/lib/style/raw.d.ts +1 -1
- package/lib/style/raw.js +1 -1
- package/lib/util/drag.d.ts +1 -0
- package/lib/util/drag.js +11 -0
- package/lib/view/Anchor.js +6 -8
- package/lib/view/Control.js +1 -1
- package/lib/view/Graph.js +3 -15
- package/lib/view/behavior/dnd.js +1 -0
- package/lib/view/edge/BaseEdge.d.ts +5 -1
- package/lib/view/edge/BaseEdge.js +20 -5
- package/lib/view/node/BaseNode.d.ts +2 -0
- package/lib/view/node/BaseNode.js +13 -1
- package/lib/view/overlay/BackgroundOverlay.d.ts +4 -14
- package/lib/view/overlay/BackgroundOverlay.js +12 -1
- package/lib/view/overlay/Grid.d.ts +4 -3
- package/lib/view/overlay/Grid.js +8 -31
- package/lib/view/overlay/getTransformHoc.d.ts +1 -1
- package/lib/view/text/BaseText.js +1 -1
- package/package.json +1 -1
- package/src/LogicFlow.tsx +6 -0
- package/src/algorithm/edge.ts +3 -5
- package/src/algorithm/outline.ts +1 -1
- package/src/constant/index.ts +4 -0
- package/src/event/eventArgs.ts +50 -30
- package/src/model/GraphModel.ts +122 -3
- package/src/model/edge/BaseEdgeModel.ts +1 -0
- package/src/model/edge/LineEdgeModel.ts +8 -0
- package/src/model/edge/PolylineEdgeModel.ts +5 -3
- package/src/model/node/BaseNodeModel.ts +1 -1
- package/src/model/node/HtmlNodeModel.ts +1 -1
- package/src/style/index.less +5 -0
- package/src/style/raw.ts +3 -0
- package/src/util/drag.ts +12 -0
- package/src/view/Anchor.tsx +7 -8
- package/src/view/Control.tsx +1 -1
- package/src/view/Graph.tsx +5 -7
- package/src/view/behavior/dnd.ts +1 -0
- package/src/view/edge/BaseEdge.tsx +24 -3
- package/src/view/node/BaseNode.tsx +17 -1
- package/src/view/overlay/BackgroundOverlay.tsx +11 -16
- package/src/view/overlay/Grid.tsx +13 -9
- package/src/view/overlay/OutlineOverlay.tsx +1 -1
- package/src/view/text/BaseText.tsx +1 -1
- package/stats.html +1 -1
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -1
package/src/style/index.less
CHANGED
package/src/style/raw.ts
CHANGED
package/src/util/drag.ts
CHANGED
|
@@ -201,4 +201,16 @@ export class StepDrag {
|
|
|
201
201
|
this.onDragEnd({ event: undefined })
|
|
202
202
|
this.isDragging = false
|
|
203
203
|
}
|
|
204
|
+
|
|
205
|
+
destroy = () => {
|
|
206
|
+
if (this.isStartDragging) {
|
|
207
|
+
// https://github.com/didi/LogicFlow/issues/1934
|
|
208
|
+
// https://github.com/didi/LogicFlow/issues/1926
|
|
209
|
+
// cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算
|
|
210
|
+
// 我们的本意是为了防止mousemove和mouseup没有及时被移除
|
|
211
|
+
// 因此这里增加if(this.isStartDragging)的判断,isStartDragging=true代表没有触发handleMouseUp(),此时监听还没被移除
|
|
212
|
+
// 在拖拽情况下(isStartDragging=true),此时注册了监听,在组件突然销毁时,强制触发cancelDrag进行监听事件的移除
|
|
213
|
+
this.cancelDrag()
|
|
214
|
+
}
|
|
215
|
+
}
|
|
204
216
|
}
|
package/src/view/Anchor.tsx
CHANGED
|
@@ -189,14 +189,13 @@ class Anchor extends Component<IProps, IState> {
|
|
|
189
189
|
this.sourceRuleResults.clear()
|
|
190
190
|
this.targetRuleResults.clear()
|
|
191
191
|
const { graphModel, nodeModel, anchorData } = this.props
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
192
|
+
|
|
193
|
+
graphModel.eventCenter.emit(EventType.ANCHOR_DRAGEND, {
|
|
194
|
+
data: anchorData,
|
|
195
|
+
e: event!,
|
|
196
|
+
nodeModel,
|
|
197
|
+
edgeModel: edgeModel ?? undefined,
|
|
198
|
+
})
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
get customTrajectory() {
|
package/src/view/Control.tsx
CHANGED
package/src/view/Graph.tsx
CHANGED
|
@@ -87,11 +87,10 @@ class Graph extends Component<IGraphProps> {
|
|
|
87
87
|
if (options.height) {
|
|
88
88
|
style.height = `${graphModel.height}px`
|
|
89
89
|
}
|
|
90
|
-
const
|
|
91
|
-
const { fakeNode, editConfigModel } = graphModel
|
|
90
|
+
const { fakeNode, editConfigModel, background } = graphModel
|
|
92
91
|
const { adjustEdge } = editConfigModel
|
|
93
92
|
return (
|
|
94
|
-
<div className="lf-graph" flow-id={graphModel.flowId}>
|
|
93
|
+
<div className="lf-graph" flow-id={graphModel.flowId} style={style}>
|
|
95
94
|
{/* 元素层 */}
|
|
96
95
|
<CanvasOverlay graphModel={graphModel} dnd={dnd}>
|
|
97
96
|
<g className="lf-base">
|
|
@@ -113,11 +112,10 @@ class Graph extends Component<IGraphProps> {
|
|
|
113
112
|
</ModificationOverlay>
|
|
114
113
|
{/* 工具层:插件 */}
|
|
115
114
|
<ToolOverlay graphModel={graphModel} tool={tool} />
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
)}
|
|
115
|
+
{/* 画布背景 */}
|
|
116
|
+
{background && <BackgroundOverlay background={background} />}
|
|
119
117
|
{/* 画布网格 */}
|
|
120
|
-
|
|
118
|
+
<Grid graphModel={graphModel} />
|
|
121
119
|
</div>
|
|
122
120
|
)
|
|
123
121
|
}
|
package/src/view/behavior/dnd.ts
CHANGED
|
@@ -29,6 +29,7 @@ export abstract class BaseEdge<P extends IProps> extends Component<
|
|
|
29
29
|
> {
|
|
30
30
|
static isObserved: boolean = false
|
|
31
31
|
static extendsKey?: string
|
|
32
|
+
mouseUpDrag?: boolean
|
|
32
33
|
|
|
33
34
|
startTime?: number
|
|
34
35
|
contextMenuTime?: number
|
|
@@ -385,13 +386,16 @@ export abstract class BaseEdge<P extends IProps> extends Component<
|
|
|
385
386
|
e.stopPropagation()
|
|
386
387
|
this.startTime = new Date().getTime()
|
|
387
388
|
}
|
|
389
|
+
handleMouseUp = () => {
|
|
390
|
+
const { model } = this.props
|
|
391
|
+
this.mouseUpDrag = model.isDragging
|
|
392
|
+
}
|
|
388
393
|
/**
|
|
389
394
|
* 不支持重写
|
|
390
395
|
*/
|
|
391
|
-
|
|
396
|
+
handleClick = (e: MouseEvent) => {
|
|
392
397
|
if (!this.startTime) return
|
|
393
|
-
|
|
394
|
-
if (time > 200) return // 事件大于200ms,认为是拖拽。
|
|
398
|
+
if (this.mouseUpDrag) return // 如果是拖拽,不触发click事件。
|
|
395
399
|
const isRightClick = e.button === 2
|
|
396
400
|
if (isRightClick) return
|
|
397
401
|
// 这里 IE 11不能正确显示
|
|
@@ -455,6 +459,20 @@ export abstract class BaseEdge<P extends IProps> extends Component<
|
|
|
455
459
|
this.toFront()
|
|
456
460
|
}
|
|
457
461
|
|
|
462
|
+
handleFocus = () => {
|
|
463
|
+
const { model, graphModel } = this.props
|
|
464
|
+
graphModel.eventCenter.emit(EventType.EDGE_FOCUS, {
|
|
465
|
+
data: model.getData(),
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
handleBlur = () => {
|
|
470
|
+
const { model, graphModel } = this.props
|
|
471
|
+
graphModel.eventCenter.emit(EventType.EDGE_BLUR, {
|
|
472
|
+
data: model.getData(),
|
|
473
|
+
})
|
|
474
|
+
}
|
|
475
|
+
|
|
458
476
|
/**
|
|
459
477
|
* @overridable 支持重写, 此方法为获取边的形状,如果需要自定义边的形状,请重写此方法。
|
|
460
478
|
* @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
|
|
@@ -490,10 +508,13 @@ export abstract class BaseEdge<P extends IProps> extends Component<
|
|
|
490
508
|
.join(' ')}
|
|
491
509
|
onMouseDown={this.handleMouseDown}
|
|
492
510
|
onMouseUp={this.handleMouseUp}
|
|
511
|
+
onClick={this.handleClick}
|
|
493
512
|
onContextMenu={this.handleContextMenu}
|
|
494
513
|
onMouseOver={this.setHoverOn}
|
|
495
514
|
onMouseEnter={this.setHoverOn}
|
|
496
515
|
onMouseLeave={this.setHoverOff}
|
|
516
|
+
onFocus={this.handleFocus}
|
|
517
|
+
onBlur={this.handleBlur}
|
|
497
518
|
>
|
|
498
519
|
{this.getShape()}
|
|
499
520
|
{this.getAppend()}
|
|
@@ -377,7 +377,7 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
377
377
|
// 不是双击的,默认都是单击
|
|
378
378
|
if (isDoubleClick) {
|
|
379
379
|
if (editConfigModel.nodeTextEdit) {
|
|
380
|
-
if (model.text.editable) {
|
|
380
|
+
if (model.text.editable && editConfigModel.textMode === TextMode.TEXT) {
|
|
381
381
|
model.setSelected(false)
|
|
382
382
|
graphModel.setElementStateById(model.id, ElementState.TEXT_EDIT)
|
|
383
383
|
}
|
|
@@ -424,6 +424,20 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
handleFocus = () => {
|
|
428
|
+
const { model, graphModel } = this.props
|
|
429
|
+
graphModel.eventCenter.emit(EventType.NODE_FOCUS, {
|
|
430
|
+
data: model.getData(),
|
|
431
|
+
})
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
handleBlur = () => {
|
|
435
|
+
const { model, graphModel } = this.props
|
|
436
|
+
graphModel.eventCenter.emit(EventType.NODE_BLUR, {
|
|
437
|
+
data: model.getData(),
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
|
|
427
441
|
// 因为自定义节点的时候,可能会基于hover状态自定义不同的样式。
|
|
428
442
|
setHoverOn = (ev: MouseEvent) => {
|
|
429
443
|
const { model, graphModel } = this.props
|
|
@@ -508,6 +522,8 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
508
522
|
onMouseLeave={this.setHoverOff}
|
|
509
523
|
onMouseOut={this.onMouseOut}
|
|
510
524
|
onContextMenu={this.handleContextMenu}
|
|
525
|
+
onFocus={this.handleFocus}
|
|
526
|
+
onBlur={this.handleBlur}
|
|
511
527
|
{...restAttributes}
|
|
512
528
|
>
|
|
513
529
|
{nodeShapeInner}
|
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
import { Component } from 'preact/compat'
|
|
2
|
+
import { isObject } from 'lodash-es'
|
|
3
|
+
import { Options as LFOptions } from '../../options'
|
|
4
|
+
import { observer } from '../..'
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* 背景配置, 支持css属性配置
|
|
5
8
|
* https://developer.mozilla.org/zh-CN/docs/Web/CSS/background
|
|
6
9
|
* @example
|
|
7
10
|
* {
|
|
8
|
-
*
|
|
9
|
-
|
|
11
|
+
* backgroundImage: "url('./img/grid.svg')",
|
|
12
|
+
backgroundRepeat: 'repeat',
|
|
10
13
|
* }
|
|
11
14
|
*/
|
|
12
|
-
export type BackgroundConfig = {
|
|
13
|
-
/**
|
|
14
|
-
* 背景图片地址
|
|
15
|
-
*/
|
|
16
|
-
backgroundImage?: string
|
|
17
|
-
/**
|
|
18
|
-
* 是否重复
|
|
19
|
-
*/
|
|
20
|
-
backgroundRepeat?: string
|
|
21
|
-
[key: string]: any
|
|
22
|
-
}
|
|
23
|
-
|
|
24
15
|
type IProps = {
|
|
25
|
-
background: BackgroundConfig
|
|
16
|
+
background: boolean | LFOptions.BackgroundConfig
|
|
26
17
|
}
|
|
27
18
|
|
|
19
|
+
@observer
|
|
28
20
|
export class BackgroundOverlay extends Component<IProps> {
|
|
29
21
|
render() {
|
|
30
22
|
const { background } = this.props
|
|
31
23
|
return (
|
|
32
24
|
<div className="lf-background">
|
|
33
|
-
<div
|
|
25
|
+
<div
|
|
26
|
+
style={isObject(background) ? background : {}}
|
|
27
|
+
className="lf-background-area"
|
|
28
|
+
/>
|
|
34
29
|
</div>
|
|
35
30
|
)
|
|
36
31
|
}
|
|
@@ -5,19 +5,24 @@ import { createUuid } from '../../util'
|
|
|
5
5
|
import { GraphModel } from '../../model'
|
|
6
6
|
import { DEFAULT_GRID_SIZE } from '../../constant'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type IProps = GridOptions & {
|
|
8
|
+
type IProps = {
|
|
11
9
|
graphModel: GraphModel
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
@observer
|
|
15
13
|
export class Grid extends Component<IProps> {
|
|
14
|
+
gridOptions: Grid.GridOptions
|
|
15
|
+
|
|
16
16
|
readonly id = createUuid()
|
|
17
17
|
|
|
18
|
+
constructor(props: IProps) {
|
|
19
|
+
super(props)
|
|
20
|
+
this.gridOptions = this.props.graphModel.grid
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
// 网格类型为点状
|
|
19
24
|
renderDot() {
|
|
20
|
-
const { config, size = 1, visible } = this.
|
|
25
|
+
const { config, size = 1, visible } = this.gridOptions
|
|
21
26
|
|
|
22
27
|
const { color, thickness = 2 } = config ?? {}
|
|
23
28
|
|
|
@@ -37,7 +42,7 @@ export class Grid extends Component<IProps> {
|
|
|
37
42
|
// 网格类型为交叉线
|
|
38
43
|
// todo: 采用背景缩放的方式,实现更好的体验
|
|
39
44
|
renderMesh() {
|
|
40
|
-
const { config, size = 1, visible } = this.
|
|
45
|
+
const { config, size = 1, visible } = this.gridOptions
|
|
41
46
|
const { color, thickness = 1 } = config ?? {}
|
|
42
47
|
|
|
43
48
|
// 对于交叉线网格,线的宽度不能大于网格大小的一半
|
|
@@ -48,7 +53,7 @@ export class Grid extends Component<IProps> {
|
|
|
48
53
|
<path
|
|
49
54
|
d={d}
|
|
50
55
|
stroke={color}
|
|
51
|
-
strokeWidth={strokeWidth}
|
|
56
|
+
strokeWidth={strokeWidth / 2}
|
|
52
57
|
opacity={opacity}
|
|
53
58
|
fill="transparent"
|
|
54
59
|
/>
|
|
@@ -57,10 +62,9 @@ export class Grid extends Component<IProps> {
|
|
|
57
62
|
|
|
58
63
|
render() {
|
|
59
64
|
const {
|
|
60
|
-
type,
|
|
61
|
-
size = 1,
|
|
62
65
|
graphModel: { transformModel },
|
|
63
66
|
} = this.props
|
|
67
|
+
const { type, size = 1 } = this.gridOptions
|
|
64
68
|
const { SCALE_X, SKEW_Y, SKEW_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y } =
|
|
65
69
|
transformModel
|
|
66
70
|
const matrixString = [
|
|
@@ -124,7 +128,7 @@ export namespace Grid {
|
|
|
124
128
|
/**
|
|
125
129
|
* 网格的颜色
|
|
126
130
|
*/
|
|
127
|
-
color
|
|
131
|
+
color?: string
|
|
128
132
|
/**
|
|
129
133
|
* 网格的宽度
|
|
130
134
|
* - 对于 `dot` 点状网格,表示点的大小
|
|
@@ -82,7 +82,7 @@ export class OutlineOverlay extends Component<IProps> {
|
|
|
82
82
|
(hoverOutline && edge.isHovered)
|
|
83
83
|
) {
|
|
84
84
|
if (edge.modelType === ModelType.LINE_EDGE) {
|
|
85
|
-
edgeOutline.push(this.getLineOutline(edge))
|
|
85
|
+
edgeOutline.push(this.getLineOutline(edge as LineEdgeModel))
|
|
86
86
|
} else if (edge.modelType === ModelType.POLYLINE_EDGE) {
|
|
87
87
|
edgeOutline.push(this.getPolylineOutline(edge as PolylineEdgeModel))
|
|
88
88
|
} else if (edge.modelType === ModelType.BEZIER_EDGE) {
|