@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
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Component } from 'preact/compat'
|
|
2
|
-
import { IToolProps } from '.'
|
|
3
|
-
import { Model, observer } from '..'
|
|
4
|
-
import LogicFlow from '../LogicFlow'
|
|
5
|
-
import { StepDrag, IDragParams } from '../util'
|
|
6
|
-
import { ElementType, EventType } from '../constant'
|
|
7
|
-
import { getNodeOutline, getEdgeOutline } from '../algorithm/outline'
|
|
8
|
-
|
|
9
|
-
import GraphData = LogicFlow.GraphData
|
|
10
|
-
|
|
11
|
-
@observer
|
|
12
|
-
export default class MultipleSelect extends Component<IToolProps> {
|
|
13
|
-
static toolName = 'multiple-select-tool'
|
|
14
|
-
stepDrag: StepDrag
|
|
15
|
-
|
|
16
|
-
constructor(props: IToolProps) {
|
|
17
|
-
super(props)
|
|
18
|
-
const {
|
|
19
|
-
graphModel: { gridSize, eventCenter },
|
|
20
|
-
} = props
|
|
21
|
-
this.stepDrag = new StepDrag({
|
|
22
|
-
onDragging: this.onDragging,
|
|
23
|
-
step: gridSize,
|
|
24
|
-
eventType: 'SELECTION',
|
|
25
|
-
eventCenter,
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
handleMouseDown = (ev: PointerEvent) => {
|
|
30
|
-
// 多选区域的拖拽步长随缩放变化
|
|
31
|
-
const {
|
|
32
|
-
graphModel: { gridSize },
|
|
33
|
-
lf,
|
|
34
|
-
} = this.props
|
|
35
|
-
const { SCALE_X } = lf.getTransform()
|
|
36
|
-
this.stepDrag.setStep(gridSize * SCALE_X)
|
|
37
|
-
this.stepDrag.handleMouseDown(ev)
|
|
38
|
-
}
|
|
39
|
-
// 使多选区域的滚轮事件可以触发画布的滚轮事件
|
|
40
|
-
handleWheelEvent = (ev: WheelEvent) => {
|
|
41
|
-
ev.preventDefault()
|
|
42
|
-
const { deltaX, deltaY, clientX, clientY, ctrlKey } = ev
|
|
43
|
-
const newEvent = new WheelEvent('wheel', {
|
|
44
|
-
deltaX,
|
|
45
|
-
deltaY,
|
|
46
|
-
clientX,
|
|
47
|
-
clientY,
|
|
48
|
-
ctrlKey,
|
|
49
|
-
})
|
|
50
|
-
this.props.lf.container
|
|
51
|
-
?.querySelector('.lf-canvas-overlay[name="canvas-overlay"]')
|
|
52
|
-
?.dispatchEvent(newEvent)
|
|
53
|
-
}
|
|
54
|
-
onDragging = ({ deltaX, deltaY }: IDragParams) => {
|
|
55
|
-
const { graphModel, lf } = this.props
|
|
56
|
-
const { SCALE_X, SCALE_Y } = lf.getTransform()
|
|
57
|
-
const selectElements = graphModel.getSelectElements(true)
|
|
58
|
-
graphModel.moveNodes(
|
|
59
|
-
selectElements.nodes.map((node) => node.id),
|
|
60
|
-
deltaX / SCALE_X,
|
|
61
|
-
deltaY / SCALE_Y,
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
handleContextMenu = (ev: MouseEvent) => {
|
|
65
|
-
ev.preventDefault()
|
|
66
|
-
const {
|
|
67
|
-
graphModel,
|
|
68
|
-
graphModel: { eventCenter, selectElements },
|
|
69
|
-
} = this.props
|
|
70
|
-
const position = graphModel.getPointByClient({
|
|
71
|
-
x: ev.clientX,
|
|
72
|
-
y: ev.clientY,
|
|
73
|
-
})
|
|
74
|
-
const selectGraphData: GraphData = {
|
|
75
|
-
nodes: [],
|
|
76
|
-
edges: [],
|
|
77
|
-
}
|
|
78
|
-
const models = [...selectElements.values()]
|
|
79
|
-
models.forEach((model) => {
|
|
80
|
-
if (model.BaseType === ElementType.NODE) {
|
|
81
|
-
selectGraphData.nodes.push(model.getData())
|
|
82
|
-
}
|
|
83
|
-
if (model.BaseType === ElementType.EDGE) {
|
|
84
|
-
selectGraphData.edges.push(model.getData())
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
eventCenter.emit(EventType.SELECTION_CONTEXTMENU, {
|
|
88
|
-
data: selectGraphData,
|
|
89
|
-
e: ev,
|
|
90
|
-
position,
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
render() {
|
|
95
|
-
const {
|
|
96
|
-
graphModel: { selectElements, transformModel, theme },
|
|
97
|
-
} = this.props
|
|
98
|
-
const { SCALE_X, SCALE_Y } = this.props.lf.getTransform()
|
|
99
|
-
const { xPadding = 8, yPadding = 8 } = theme.multiSelect || {}
|
|
100
|
-
if (selectElements.size <= 1) return
|
|
101
|
-
let x = Number.MAX_SAFE_INTEGER
|
|
102
|
-
let y = Number.MAX_SAFE_INTEGER
|
|
103
|
-
let x1 = Number.MIN_SAFE_INTEGER
|
|
104
|
-
let y1 = Number.MIN_SAFE_INTEGER
|
|
105
|
-
selectElements.forEach((element) => {
|
|
106
|
-
let outline: Model.OutlineInfo | undefined
|
|
107
|
-
if (element.BaseType === ElementType.NODE) {
|
|
108
|
-
outline = getNodeOutline(element)
|
|
109
|
-
}
|
|
110
|
-
if (element.BaseType === ElementType.EDGE) {
|
|
111
|
-
outline = getEdgeOutline(element)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (outline !== undefined) {
|
|
115
|
-
x = Math.min(x, outline.x)
|
|
116
|
-
y = Math.min(y, outline.y)
|
|
117
|
-
x1 = Math.max(x1, outline.x1)
|
|
118
|
-
y1 = Math.max(y1, outline.y1)
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
;[x, y] = transformModel.CanvasPointToHtmlPoint([x, y])
|
|
122
|
-
;[x1, y1] = transformModel.CanvasPointToHtmlPoint([x1, y1])
|
|
123
|
-
const style = {
|
|
124
|
-
left: `${x - (20 * SCALE_X) / 2 - xPadding / 2}px`,
|
|
125
|
-
top: `${y - (20 * SCALE_Y) / 2 - yPadding / 2}px`,
|
|
126
|
-
width: `${x1 - x + 20 * SCALE_X + xPadding}px`,
|
|
127
|
-
height: `${y1 - y + 20 * SCALE_Y + yPadding}px`,
|
|
128
|
-
'border-width': `${2 * SCALE_X}px`,
|
|
129
|
-
}
|
|
130
|
-
return (
|
|
131
|
-
<div
|
|
132
|
-
className="lf-multiple-select"
|
|
133
|
-
style={style}
|
|
134
|
-
onPointerDown={this.handleMouseDown}
|
|
135
|
-
onContextMenu={this.handleContextMenu}
|
|
136
|
-
onWheel={this.handleWheelEvent}
|
|
137
|
-
/>
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { createRef, Component } from 'preact/compat'
|
|
2
|
-
import { IToolProps } from '.'
|
|
3
|
-
import { ElementState, observer } from '..'
|
|
4
|
-
import { ElementType, EventType, ModelType } from '../constant'
|
|
5
|
-
|
|
6
|
-
type IState = {
|
|
7
|
-
style: {
|
|
8
|
-
left: number
|
|
9
|
-
top: number
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@observer
|
|
14
|
-
export class TextEditTool extends Component<IToolProps, IState> {
|
|
15
|
-
static toolName = 'text-edit-tool'
|
|
16
|
-
ref = createRef()
|
|
17
|
-
__prevText = {
|
|
18
|
-
type: '',
|
|
19
|
-
text: '',
|
|
20
|
-
id: '',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
constructor(props: IToolProps) {
|
|
24
|
-
super(props)
|
|
25
|
-
this.state = {
|
|
26
|
-
style: {
|
|
27
|
-
left: 0,
|
|
28
|
-
top: 0,
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static getDerivedStateFromProps(props: IToolProps): IState | null {
|
|
34
|
-
const { textEditElement, graphModel } = props
|
|
35
|
-
const { transformModel, theme } = graphModel
|
|
36
|
-
const { inputText } = theme
|
|
37
|
-
|
|
38
|
-
let autoStyle
|
|
39
|
-
if (textEditElement) {
|
|
40
|
-
// 由于边上的文本是依据显示的时候动态计算出来的
|
|
41
|
-
// 所以不能在边创建的时候就初始化文本位置。
|
|
42
|
-
// 而是在边上新建文本的时候创建。
|
|
43
|
-
if (!textEditElement.text?.value) {
|
|
44
|
-
if (textEditElement.BaseType === ElementType.EDGE) {
|
|
45
|
-
// textEditElement = textEditElement as BaseEdgeModel
|
|
46
|
-
const textConfig = textEditElement.text
|
|
47
|
-
const { x, y } = textEditElement.textPosition
|
|
48
|
-
textConfig.x = x
|
|
49
|
-
textConfig.y = y
|
|
50
|
-
textEditElement.setText(textConfig)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// 自动换行节点边通用样式
|
|
54
|
-
const commonAutoStyle = {
|
|
55
|
-
resize: 'auto',
|
|
56
|
-
whiteSpace: 'normal',
|
|
57
|
-
wordBreak: 'break-all',
|
|
58
|
-
}
|
|
59
|
-
if (textEditElement.BaseType === ElementType.EDGE) {
|
|
60
|
-
// 如果边文案自动换行, 设置编辑框宽度
|
|
61
|
-
const {
|
|
62
|
-
edgeText: { overflowMode, lineHeight, wrapPadding, textWidth },
|
|
63
|
-
} = theme
|
|
64
|
-
if (textWidth && overflowMode === 'autoWrap') {
|
|
65
|
-
autoStyle = {
|
|
66
|
-
...commonAutoStyle,
|
|
67
|
-
width: textWidth,
|
|
68
|
-
minWidth: textWidth,
|
|
69
|
-
lineHeight,
|
|
70
|
-
padding: wrapPadding,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} else if (textEditElement.BaseType === ElementType.NODE) {
|
|
74
|
-
// 如果节点文案自动换行, 设置编辑框宽度
|
|
75
|
-
const {
|
|
76
|
-
nodeText: { overflowMode, lineHeight, wrapPadding, textWidth },
|
|
77
|
-
} = theme
|
|
78
|
-
const { width, modelType, textWidth: nodeTextWidth } = textEditElement
|
|
79
|
-
|
|
80
|
-
const finalTextWidth = nodeTextWidth || textWidth || width
|
|
81
|
-
// 文本节点没有默认宽高,只有在设置了textWidth之后才能进行自动换行
|
|
82
|
-
if (
|
|
83
|
-
(modelType !== ModelType.TEXT_NODE && overflowMode === 'autoWrap') ||
|
|
84
|
-
(modelType === ModelType.TEXT_NODE && textWidth)
|
|
85
|
-
) {
|
|
86
|
-
autoStyle = {
|
|
87
|
-
...commonAutoStyle,
|
|
88
|
-
width: finalTextWidth,
|
|
89
|
-
minWidth: finalTextWidth,
|
|
90
|
-
lineHeight,
|
|
91
|
-
padding: wrapPadding,
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const { x, y } = textEditElement.text
|
|
97
|
-
const [left, top] = transformModel.CanvasPointToHtmlPoint([x, y])
|
|
98
|
-
return {
|
|
99
|
-
style: {
|
|
100
|
-
left,
|
|
101
|
-
top,
|
|
102
|
-
...autoStyle,
|
|
103
|
-
...inputText,
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return null
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
componentDidUpdate() {
|
|
112
|
-
const { graphModel } = this.props
|
|
113
|
-
if (this.ref.current) {
|
|
114
|
-
this.ref.current.focus()
|
|
115
|
-
this.placeCaretAtEnd(this.ref.current)
|
|
116
|
-
}
|
|
117
|
-
if (this.__prevText.id !== '') {
|
|
118
|
-
const { text, id } = this.__prevText
|
|
119
|
-
graphModel.updateText(id, text)
|
|
120
|
-
graphModel.eventCenter.emit(EventType.TEXT_UPDATE, {
|
|
121
|
-
data: { ...this.__prevText },
|
|
122
|
-
})
|
|
123
|
-
this.__prevText.id = ''
|
|
124
|
-
this.__prevText.text = ''
|
|
125
|
-
this.__prevText.type = ''
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
keyupHandler = (ev: KeyboardEvent) => {
|
|
130
|
-
const {
|
|
131
|
-
graphModel: { textEditElement },
|
|
132
|
-
} = this.props
|
|
133
|
-
// 按下alt+enter表示输入完成
|
|
134
|
-
if (ev.key === 'Enter' && ev.altKey) {
|
|
135
|
-
textEditElement?.setElementState(ElementState.DEFAULT)
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
inputHandler = (ev: any) => {
|
|
139
|
-
const { innerText: value } = ev.target as HTMLElement
|
|
140
|
-
const {
|
|
141
|
-
graphModel: { textEditElement },
|
|
142
|
-
} = this.props
|
|
143
|
-
if (textEditElement) {
|
|
144
|
-
this.__prevText = {
|
|
145
|
-
type: textEditElement.type,
|
|
146
|
-
text: value.replace(/(\r\n)+$|(\n)+$/, ''), // fix #488: 文本后面的换行符不保留
|
|
147
|
-
id: textEditElement.id,
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// fix: #587 #760
|
|
152
|
-
keydownHandler = (ev: any) => {
|
|
153
|
-
ev.stopPropagation()
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
placeCaretAtEnd(el: any) {
|
|
157
|
-
if (
|
|
158
|
-
window.getSelection !== undefined &&
|
|
159
|
-
document.createRange !== undefined
|
|
160
|
-
) {
|
|
161
|
-
const range = document.createRange()
|
|
162
|
-
range.selectNodeContents(el)
|
|
163
|
-
range.collapse(false)
|
|
164
|
-
const sel = window.getSelection()
|
|
165
|
-
sel?.removeAllRanges()
|
|
166
|
-
sel?.addRange(range)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
render() {
|
|
171
|
-
const {
|
|
172
|
-
graphModel: { textEditElement },
|
|
173
|
-
} = this.props
|
|
174
|
-
const { style } = this.state
|
|
175
|
-
return textEditElement ? (
|
|
176
|
-
<div
|
|
177
|
-
contentEditable
|
|
178
|
-
className="lf-text-input"
|
|
179
|
-
style={style}
|
|
180
|
-
ref={this.ref}
|
|
181
|
-
key={textEditElement.id}
|
|
182
|
-
onKeyUp={this.keyupHandler}
|
|
183
|
-
onKeyDown={this.keydownHandler}
|
|
184
|
-
onKeyPress={this.keydownHandler}
|
|
185
|
-
onInput={this.inputHandler}
|
|
186
|
-
>
|
|
187
|
-
{textEditElement.text?.value}
|
|
188
|
-
</div>
|
|
189
|
-
) : null
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export default TextEditTool
|
package/src/tool/index.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Component, ReactElement } from 'preact/compat'
|
|
2
|
-
import { action, observable } from 'mobx'
|
|
3
|
-
import { forEach } from 'lodash-es'
|
|
4
|
-
import TextEdit from './TextEditTool'
|
|
5
|
-
import MultipleSelect from './MultipleSelectTool'
|
|
6
|
-
import LogicFlow from '../LogicFlow'
|
|
7
|
-
import { ElementState, EventType } from '../constant'
|
|
8
|
-
import { GraphModel, BaseEdgeModel, BaseNodeModel } from '../model'
|
|
9
|
-
|
|
10
|
-
export type IToolProps = {
|
|
11
|
-
lf: LogicFlow
|
|
12
|
-
graphModel: GraphModel
|
|
13
|
-
textEditElement?: BaseNodeModel | BaseEdgeModel
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type ToolConstructor = new (props: IToolProps) => Component<IToolProps>
|
|
17
|
-
|
|
18
|
-
// 默认内置的工具
|
|
19
|
-
const defaultTools = [TextEdit, MultipleSelect]
|
|
20
|
-
|
|
21
|
-
export class Tool {
|
|
22
|
-
tools?: Component[]
|
|
23
|
-
components?: ReactElement<IToolProps>[]
|
|
24
|
-
@observable toolMap = new Map<string, ToolConstructor>()
|
|
25
|
-
|
|
26
|
-
disabledToolMap = new Map<string, ToolConstructor>()
|
|
27
|
-
instance: LogicFlow
|
|
28
|
-
|
|
29
|
-
constructor(instance: LogicFlow) {
|
|
30
|
-
this.instance = instance
|
|
31
|
-
forEach(defaultTools, (tool) => {
|
|
32
|
-
if (!this.isDisabled(tool.toolName)) {
|
|
33
|
-
this.registerTool(tool.toolName, tool)
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
// @see https://github.com/didi/LogicFlow/issues/152
|
|
38
|
-
const { graphModel } = instance
|
|
39
|
-
const { eventCenter } = graphModel
|
|
40
|
-
eventCenter.on(
|
|
41
|
-
`${EventType.GRAPH_TRANSFORM},${EventType.NODE_CLICK},${EventType.BLANK_CLICK} `,
|
|
42
|
-
() => {
|
|
43
|
-
const {
|
|
44
|
-
textEditElement,
|
|
45
|
-
editConfigModel: { edgeTextEdit, nodeTextEdit },
|
|
46
|
-
} = graphModel
|
|
47
|
-
// fix #826, 保留之前的文本可以编辑点击空白才设置为不可编辑。如果以后有其他需求再改。
|
|
48
|
-
if ((edgeTextEdit || nodeTextEdit) && textEditElement) {
|
|
49
|
-
graphModel.textEditElement?.setElementState(ElementState.DEFAULT)
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private isDisabled(toolName) {
|
|
56
|
-
return this.instance.options.disabledTools?.indexOf(toolName) !== -1
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 注册工具
|
|
60
|
-
registerTool(name: string, component: ToolConstructor) {
|
|
61
|
-
this.toolMap.set(name, component)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 禁用工具
|
|
65
|
-
@action
|
|
66
|
-
disableTool(name: string): boolean | Error {
|
|
67
|
-
const tool = this.toolMap.get(name)
|
|
68
|
-
if (tool) {
|
|
69
|
-
this.disabledToolMap.set(name, tool)
|
|
70
|
-
this.toolMap.delete(name)
|
|
71
|
-
return true
|
|
72
|
-
}
|
|
73
|
-
throw new Error(`禁用失败,不存在名为 ${tool} 的工具`)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@action
|
|
77
|
-
enableTool(name: string): boolean | Error {
|
|
78
|
-
const tool = this.disabledToolMap.get(name)
|
|
79
|
-
if (tool) {
|
|
80
|
-
this.toolMap.set(name, tool)
|
|
81
|
-
this.disabledToolMap.delete(name)
|
|
82
|
-
return true
|
|
83
|
-
}
|
|
84
|
-
throw new Error(`不存在名为 ${tool} 的工具`)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getTools() {
|
|
88
|
-
return Array.from(this.toolMap.values())
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
getInstance() {
|
|
92
|
-
return this.instance
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
destroy() {
|
|
96
|
-
this.toolMap.clear()
|
|
97
|
-
this.disabledToolMap.clear()
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export default Tool
|
package/src/typings.d.ts
DELETED
package/src/util/animation.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, merge } from 'lodash-es'
|
|
2
|
-
import { Options } from '../options'
|
|
3
|
-
|
|
4
|
-
import AnimationConfig = Options.AnimationConfig
|
|
5
|
-
|
|
6
|
-
export const defaultAnimationOffConfig = {
|
|
7
|
-
node: false,
|
|
8
|
-
edge: false,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const defaultAnimationOnConfig = {
|
|
12
|
-
node: true,
|
|
13
|
-
edge: true,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const setupAnimation = (
|
|
17
|
-
config?: boolean | Partial<AnimationConfig>,
|
|
18
|
-
): AnimationConfig => {
|
|
19
|
-
if (!config || typeof config === 'boolean') {
|
|
20
|
-
return config === true
|
|
21
|
-
? cloneDeep(defaultAnimationOnConfig)
|
|
22
|
-
: cloneDeep(defaultAnimationOffConfig)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 当传入的是对象时,将其与默认关合并
|
|
26
|
-
return merge(cloneDeep(defaultAnimationOffConfig), config)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const updateAnimation = setupAnimation
|
package/src/util/browser.ts
DELETED
package/src/util/compatible.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// import { cloneDeep } from 'lodash-es'
|
|
2
|
-
/**
|
|
3
|
-
* 对数据实现兼容处理。
|
|
4
|
-
*
|
|
5
|
-
* Vue 中的 data 会进行 Observe,深拷贝的原始数据对象
|
|
6
|
-
*/
|
|
7
|
-
export function formatData<T>(data: T): T {
|
|
8
|
-
try {
|
|
9
|
-
// WARNING: cloneDeep虽然也会将Observe对象转换为plain对象,但是不会像JSON.parse那样,会将undefined去掉。
|
|
10
|
-
// 会导致后面的pick因为存在pick覆盖默认值的情况。
|
|
11
|
-
return JSON.parse(JSON.stringify(data))
|
|
12
|
-
} catch {
|
|
13
|
-
return data
|
|
14
|
-
}
|
|
15
|
-
}
|