@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,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 网格高级 majorBold 配置。
|
|
3
|
-
*
|
|
4
|
-
* 示例(布尔值):
|
|
5
|
-
* - false:禁用特殊样式,opacity=1,无加粗,无虚线
|
|
6
|
-
* - true:启用默认值,opacity=0.75,每第 5 条线/点加粗/实线,
|
|
7
|
-
* 虚线图案通过 getDashArrayForSize(size) 计算
|
|
8
|
-
*
|
|
9
|
-
* 示例(对象):
|
|
10
|
-
* {
|
|
11
|
-
* opacity: 0.6,
|
|
12
|
-
* boldIndices: [4, 8],
|
|
13
|
-
* dashArrayConfig: { pattern: [4,2,4] },
|
|
14
|
-
* customBoldWidth: 2,
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
export type MajorBoldConfig = {
|
|
18
|
-
/** 默认网格透明度 (0-1) */
|
|
19
|
-
opacity: number
|
|
20
|
-
/** 一个周期内需要加粗/实线的索引列表 */
|
|
21
|
-
boldIndices: number[]
|
|
22
|
-
/** 虚线样式的计算配置 */
|
|
23
|
-
dashArrayConfig: {
|
|
24
|
-
/** 固定的虚线模式(可选) */
|
|
25
|
-
pattern: number[]
|
|
26
|
-
}
|
|
27
|
-
/** mesh 网格的自定义加粗线宽(可选) */
|
|
28
|
-
customBoldWidth?: number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const defaultGridConfig: MajorBoldConfig = {
|
|
32
|
-
opacity: 1,
|
|
33
|
-
boldIndices: [5],
|
|
34
|
-
dashArrayConfig: {
|
|
35
|
-
pattern: [2, 1],
|
|
36
|
-
},
|
|
37
|
-
customBoldWidth: 2,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 校验并规范化 GridConfig。
|
|
42
|
-
* - 将 opacity 限制在 [0,1] 范围
|
|
43
|
-
* - boldIndices 过滤为正整数并去重
|
|
44
|
-
*/
|
|
45
|
-
export function validateGridConfig(cfg: MajorBoldConfig): MajorBoldConfig {
|
|
46
|
-
const opacity = Math.max(
|
|
47
|
-
0,
|
|
48
|
-
Math.min(1, cfg.opacity ?? defaultGridConfig.opacity),
|
|
49
|
-
)
|
|
50
|
-
const boldIndicesSet = new Set<number>()
|
|
51
|
-
const boldRaw = Array.isArray(cfg.boldIndices)
|
|
52
|
-
? cfg.boldIndices
|
|
53
|
-
: defaultGridConfig.boldIndices
|
|
54
|
-
for (const n of boldRaw) {
|
|
55
|
-
if (typeof n === 'number' && Number.isFinite(n) && n > 0) {
|
|
56
|
-
boldIndicesSet.add(Math.floor(n))
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const boldIndices = Array.from(boldIndicesSet)
|
|
60
|
-
const pattern = Array.isArray(cfg.dashArrayConfig?.pattern)
|
|
61
|
-
? cfg.dashArrayConfig.pattern
|
|
62
|
-
: defaultGridConfig.dashArrayConfig.pattern
|
|
63
|
-
const dashArrayConfig = {
|
|
64
|
-
pattern,
|
|
65
|
-
}
|
|
66
|
-
const customBoldWidth = cfg.customBoldWidth
|
|
67
|
-
return {
|
|
68
|
-
opacity,
|
|
69
|
-
boldIndices: boldIndices.length
|
|
70
|
-
? boldIndices
|
|
71
|
-
: defaultGridConfig.boldIndices,
|
|
72
|
-
dashArrayConfig,
|
|
73
|
-
customBoldWidth,
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 合并用户行为配置与默认值。
|
|
79
|
-
* - false → 关闭模式:opacity=1,bold=[],关闭虚线
|
|
80
|
-
* - true → 默认模式:采用 defaultGridConfig
|
|
81
|
-
* - object → 自定义模式:校验后使用用户配置
|
|
82
|
-
*/
|
|
83
|
-
export function mergeMajorBoldConfig(input?: boolean | MajorBoldConfig): {
|
|
84
|
-
mode: 'disabled' | 'default' | 'custom'
|
|
85
|
-
config: MajorBoldConfig
|
|
86
|
-
} {
|
|
87
|
-
if (input === false) {
|
|
88
|
-
return {
|
|
89
|
-
mode: 'disabled',
|
|
90
|
-
config: {
|
|
91
|
-
opacity: 1,
|
|
92
|
-
boldIndices: [],
|
|
93
|
-
dashArrayConfig: {
|
|
94
|
-
pattern: [],
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (input === true || input == null) {
|
|
100
|
-
return { mode: 'default', config: { ...defaultGridConfig } }
|
|
101
|
-
}
|
|
102
|
-
return { mode: 'custom', config: validateGridConfig(input) }
|
|
103
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './CanvasOverlay'
|
|
2
|
-
export * from './BezierAdjustOverlay'
|
|
3
|
-
export * from './BackgroundOverlay'
|
|
4
|
-
export * from './Grid'
|
|
5
|
-
export * from './ModificationOverlay'
|
|
6
|
-
export * from './OutlineOverlay'
|
|
7
|
-
export * from './SnaplineOverlay'
|
|
8
|
-
export * from './ToolOverlay'
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
import { LogicFlow } from '../..'
|
|
4
|
-
|
|
5
|
-
export type ICircleProps = {
|
|
6
|
-
x?: number
|
|
7
|
-
y?: number
|
|
8
|
-
r?: number
|
|
9
|
-
className?: string
|
|
10
|
-
} & LogicFlow.CommonTheme
|
|
11
|
-
|
|
12
|
-
export function Circle(props: ICircleProps): h.JSX.Element {
|
|
13
|
-
const { x = 0, y = 0, r = 4, className } = props
|
|
14
|
-
|
|
15
|
-
const attrs: ICircleProps = {
|
|
16
|
-
cx: x,
|
|
17
|
-
cy: y,
|
|
18
|
-
r,
|
|
19
|
-
fill: 'transparent',
|
|
20
|
-
fillOpacity: 1,
|
|
21
|
-
strokeWidth: 1,
|
|
22
|
-
stroke: '#000',
|
|
23
|
-
strokeOpacity: 1,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
27
|
-
if (typeof v !== 'object') {
|
|
28
|
-
attrs[k] = v
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
if (className) {
|
|
33
|
-
attrs.className = `lf-basic-shape ${className}`
|
|
34
|
-
} else {
|
|
35
|
-
attrs.className = `lf-basic-shape`
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return <circle {...attrs} />
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default Circle
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
import { LogicFlow } from '../..'
|
|
4
|
-
|
|
5
|
-
export type IEllipseProps = {
|
|
6
|
-
x?: number
|
|
7
|
-
y?: number
|
|
8
|
-
rx?: number
|
|
9
|
-
ry?: number
|
|
10
|
-
className?: string
|
|
11
|
-
} & LogicFlow.CommonTheme
|
|
12
|
-
|
|
13
|
-
export function Ellipse(props: IEllipseProps): h.JSX.Element {
|
|
14
|
-
const { x = 0, y = 0, rx = 4, ry = 4, className } = props
|
|
15
|
-
|
|
16
|
-
const attrs: Record<string, any> = {
|
|
17
|
-
cx: x,
|
|
18
|
-
cy: y,
|
|
19
|
-
rx,
|
|
20
|
-
ry,
|
|
21
|
-
fill: 'transparent',
|
|
22
|
-
fillOpacity: 1,
|
|
23
|
-
strokeWidth: 1,
|
|
24
|
-
stroke: '#000',
|
|
25
|
-
strokeOpacity: 1,
|
|
26
|
-
}
|
|
27
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
28
|
-
if (typeof v !== 'object') {
|
|
29
|
-
attrs[k] = v
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
if (className) {
|
|
34
|
-
attrs.className = `lf-basic-shape ${className}`
|
|
35
|
-
} else {
|
|
36
|
-
attrs.className = `lf-basic-shape`
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return <ellipse {...attrs} />
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default Ellipse
|
package/src/view/shape/Line.tsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
export type ILineProps = {
|
|
5
|
-
id?: string
|
|
6
|
-
tabindex?: number
|
|
7
|
-
x1?: number
|
|
8
|
-
y1?: number
|
|
9
|
-
x2?: number
|
|
10
|
-
y2?: number
|
|
11
|
-
stroke?: string // Color
|
|
12
|
-
className?: string
|
|
13
|
-
style?: h.JSX.CSSProperties
|
|
14
|
-
[key: string]: any
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function Line(props: ILineProps): h.JSX.Element {
|
|
18
|
-
const attrs: ILineProps = {
|
|
19
|
-
// default
|
|
20
|
-
x1: 10,
|
|
21
|
-
y1: 10,
|
|
22
|
-
x2: 20,
|
|
23
|
-
y2: 20,
|
|
24
|
-
stroke: 'black',
|
|
25
|
-
// ...props
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
29
|
-
if (k === 'style') {
|
|
30
|
-
attrs[k] = v
|
|
31
|
-
} else if (typeof v !== 'object') {
|
|
32
|
-
attrs[k] = v
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
return <line {...attrs} />
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default Line
|
package/src/view/shape/Path.tsx
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
export type IPathProps = {
|
|
5
|
-
d: string
|
|
6
|
-
[key: string]: any
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function Path(props: IPathProps): h.JSX.Element {
|
|
10
|
-
const attrs: Record<string, any> = {
|
|
11
|
-
d: '',
|
|
12
|
-
}
|
|
13
|
-
forEach(toPairs(props), ([k, v]: [key: string, v: any]) => {
|
|
14
|
-
if (k === 'style' || typeof v !== 'object') {
|
|
15
|
-
attrs[k] = v
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
return <path {...attrs} />
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default Path
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
import { LogicFlow } from '../..'
|
|
4
|
-
import { generateRoundedCorners } from '../../util/geometry'
|
|
5
|
-
|
|
6
|
-
export type IPolygonProps = {
|
|
7
|
-
points: LogicFlow.PointTuple[]
|
|
8
|
-
x?: number
|
|
9
|
-
y?: number
|
|
10
|
-
className?: string
|
|
11
|
-
radius?: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function Polygon(props: IPolygonProps): h.JSX.Element {
|
|
15
|
-
const { points = [], className, radius } = props
|
|
16
|
-
const attrs: Record<string, any> = {
|
|
17
|
-
fill: 'transparent',
|
|
18
|
-
fillOpacity: 1,
|
|
19
|
-
strokeWidth: 1,
|
|
20
|
-
stroke: '#000',
|
|
21
|
-
strokeOpacity: 1,
|
|
22
|
-
points: '',
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
26
|
-
if (typeof v !== 'object') {
|
|
27
|
-
attrs[k] = v
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
if (className) {
|
|
32
|
-
attrs.className = `lf-basic-shape ${className}`
|
|
33
|
-
} else {
|
|
34
|
-
attrs.className = 'lf-basic-shape'
|
|
35
|
-
}
|
|
36
|
-
if (radius) {
|
|
37
|
-
const pointList = points.map((point) => ({ x: point[0], y: point[1] }))
|
|
38
|
-
const rounded = generateRoundedCorners(pointList, radius, true)
|
|
39
|
-
const d = rounded.length
|
|
40
|
-
? `M ${rounded[0].x} ${rounded[0].y} ${rounded
|
|
41
|
-
.slice(1)
|
|
42
|
-
.map((p) => `L ${p.x} ${p.y}`)
|
|
43
|
-
.join(' ')} Z`
|
|
44
|
-
: ''
|
|
45
|
-
attrs.d = d
|
|
46
|
-
delete attrs.points
|
|
47
|
-
return <path {...attrs} />
|
|
48
|
-
} else {
|
|
49
|
-
attrs.points = points.map((point) => point.join(',')).join(' ')
|
|
50
|
-
return <polygon {...attrs} />
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default Polygon
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
export type IPolylineProps = {
|
|
5
|
-
points: string
|
|
6
|
-
pathLength?: number | 'none'
|
|
7
|
-
className?: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function Polyline(props: IPolylineProps): h.JSX.Element {
|
|
11
|
-
const { className } = props
|
|
12
|
-
const attrs: Record<string, unknown> = {
|
|
13
|
-
points: '',
|
|
14
|
-
fill: 'none',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: unknown]) => {
|
|
18
|
-
if (k === 'style') {
|
|
19
|
-
attrs[k] = v
|
|
20
|
-
} else if (typeof v !== 'object') {
|
|
21
|
-
attrs[k] = v
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
if (className) {
|
|
25
|
-
attrs.className = `${className}`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return <polyline {...attrs} />
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default Polyline
|
package/src/view/shape/Rect.tsx
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
import LogicFlow from '../..'
|
|
4
|
-
|
|
5
|
-
export type IRectProps = {
|
|
6
|
-
x: number
|
|
7
|
-
y: number
|
|
8
|
-
width: number
|
|
9
|
-
height: number
|
|
10
|
-
className?: string
|
|
11
|
-
radius?: LogicFlow.NumberOrPercent
|
|
12
|
-
[key: string]: any
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function Rect(props: IRectProps): h.JSX.Element {
|
|
16
|
-
const { x, y, width, height, className, strokeWidth, radius = 0 } = props
|
|
17
|
-
|
|
18
|
-
const leftTopX = x - width / 2
|
|
19
|
-
const leftTopY = y - height / 2
|
|
20
|
-
const attrs: Record<string, any> = {}
|
|
21
|
-
attrs['stroke-width'] = strokeWidth
|
|
22
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
23
|
-
if (typeof v !== 'object') {
|
|
24
|
-
attrs[k] = v
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
if (className) {
|
|
29
|
-
attrs.className = `lf-basic-shape ${className}`
|
|
30
|
-
} else {
|
|
31
|
-
attrs.className = 'lf-basic-shape'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (radius) {
|
|
35
|
-
attrs.rx = radius
|
|
36
|
-
attrs.ry = radius
|
|
37
|
-
}
|
|
38
|
-
attrs.x = leftTopX
|
|
39
|
-
attrs.y = leftTopY
|
|
40
|
-
|
|
41
|
-
return <rect {...attrs} />
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default Rect
|
package/src/view/shape/Text.tsx
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { BaseNodeModel, BaseEdgeModel } from '../../model'
|
|
3
|
-
import { ElementType, ModelType } from '../../constant'
|
|
4
|
-
import { getHtmlTextHeight } from '../../util'
|
|
5
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
6
|
-
|
|
7
|
-
export type ITextProps = {
|
|
8
|
-
x: number
|
|
9
|
-
y: number
|
|
10
|
-
value: string
|
|
11
|
-
fontSize?: number
|
|
12
|
-
fill?: string
|
|
13
|
-
overflowMode?: 'default' | 'autoWrap' | 'ellipsis'
|
|
14
|
-
textWidth?: number
|
|
15
|
-
lineHeight?: number
|
|
16
|
-
fontFamily?: string | null
|
|
17
|
-
wrapPadding?: string | number | null
|
|
18
|
-
model: BaseNodeModel | BaseEdgeModel
|
|
19
|
-
[key: string]: any
|
|
20
|
-
}
|
|
21
|
-
export type ForeignObjectPropsType =
|
|
22
|
-
'string | number | SignalLike<string | number | undefined> | undefined'
|
|
23
|
-
|
|
24
|
-
export function Text(props: ITextProps): h.JSX.Element | null {
|
|
25
|
-
const {
|
|
26
|
-
x = 0,
|
|
27
|
-
y = 0,
|
|
28
|
-
value,
|
|
29
|
-
fontSize = 12,
|
|
30
|
-
fill = 'currentColor',
|
|
31
|
-
overflowMode = 'default',
|
|
32
|
-
// TODO: 确认该 textWidth 为 '' 时跟设置什么值一致
|
|
33
|
-
textWidth = undefined,
|
|
34
|
-
model,
|
|
35
|
-
} = props
|
|
36
|
-
|
|
37
|
-
const attrs: Record<string, any> = {
|
|
38
|
-
x,
|
|
39
|
-
y,
|
|
40
|
-
fill,
|
|
41
|
-
fontSize,
|
|
42
|
-
textAnchor: 'middle',
|
|
43
|
-
dominantBaseline: 'central',
|
|
44
|
-
// ...props,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
48
|
-
if (typeof v !== 'object') {
|
|
49
|
-
attrs[k] = v
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
if (value) {
|
|
54
|
-
// String(value),兼容纯数字的文案
|
|
55
|
-
// TODO: 将 value 转为纯文本,移除其中 \n \r 等特殊字符,看是否应该丰富该功能
|
|
56
|
-
const rows = String(value).split(/[\r\n]/g)
|
|
57
|
-
const rowsLength = rows.length
|
|
58
|
-
|
|
59
|
-
if (overflowMode !== 'default') {
|
|
60
|
-
// 非文本节点设置了自动换行,或者边设置了自动换行并且设置了 textWidth
|
|
61
|
-
const { BaseType, modelType } = model
|
|
62
|
-
if (
|
|
63
|
-
(BaseType === ElementType.NODE && modelType !== ModelType.TEXT_NODE) ||
|
|
64
|
-
(BaseType === ElementType.EDGE && textWidth)
|
|
65
|
-
) {
|
|
66
|
-
return renderHtmlText(props)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (rowsLength > 1) {
|
|
71
|
-
const tSpans = rows.map((row, idx) => {
|
|
72
|
-
// 保证文字居中,文字 Y 轴偏移为当前行数对应中心行数的偏移行 * 行高
|
|
73
|
-
const tSpanLineHeight = fontSize + 2
|
|
74
|
-
const offsetY = (idx - (rowsLength - 1) / 2) * tSpanLineHeight
|
|
75
|
-
return (
|
|
76
|
-
<tspan className="lf-text-tspan" x={x} y={y + offsetY}>
|
|
77
|
-
{row}
|
|
78
|
-
</tspan>
|
|
79
|
-
)
|
|
80
|
-
})
|
|
81
|
-
return <text {...attrs}>{tSpans}</text>
|
|
82
|
-
}
|
|
83
|
-
return <text {...attrs}>{value}</text>
|
|
84
|
-
}
|
|
85
|
-
return null
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function renderHtmlText(props: ITextProps): h.JSX.Element {
|
|
89
|
-
const {
|
|
90
|
-
x,
|
|
91
|
-
y,
|
|
92
|
-
value,
|
|
93
|
-
model,
|
|
94
|
-
textWidth,
|
|
95
|
-
fontSize = 12,
|
|
96
|
-
lineHeight,
|
|
97
|
-
fontFamily = '',
|
|
98
|
-
wrapPadding = '0, 0',
|
|
99
|
-
overflowMode,
|
|
100
|
-
} = props
|
|
101
|
-
|
|
102
|
-
const { width, height, textHeight } = model
|
|
103
|
-
// TODO: 设置文本宽度为 textWidth 或 节点的宽度
|
|
104
|
-
const textRealWidth: number = textWidth || (width as number)
|
|
105
|
-
const rows = String(value).split(/[\r\n]/g)
|
|
106
|
-
const rowsLength = rows.length
|
|
107
|
-
const textRealHeight = getHtmlTextHeight({
|
|
108
|
-
rows,
|
|
109
|
-
style: {
|
|
110
|
-
fontSize: `${fontSize}px`,
|
|
111
|
-
width: `${textRealWidth}px`,
|
|
112
|
-
fontFamily,
|
|
113
|
-
lineHeight,
|
|
114
|
-
padding: wrapPadding,
|
|
115
|
-
},
|
|
116
|
-
rowsLength,
|
|
117
|
-
className: 'lf-get-text-height',
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
// 当文字超过边框时,取文字高度的实际值,也就是文字可以超过边框
|
|
121
|
-
let foreignObjectHeight: number =
|
|
122
|
-
(height as number) > textRealHeight ? (height as number) : textRealHeight
|
|
123
|
-
// 如果设置了文本高度,取设置的高度
|
|
124
|
-
if (textHeight) {
|
|
125
|
-
foreignObjectHeight = textHeight as number
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const isEllipsis = overflowMode === 'ellipsis'
|
|
129
|
-
if (isEllipsis) {
|
|
130
|
-
foreignObjectHeight = fontSize + 2
|
|
131
|
-
}
|
|
132
|
-
return (
|
|
133
|
-
<g>
|
|
134
|
-
<foreignObject
|
|
135
|
-
width={textRealWidth}
|
|
136
|
-
height={foreignObjectHeight}
|
|
137
|
-
x={x - textRealWidth / 2}
|
|
138
|
-
y={y - foreignObjectHeight / 2}
|
|
139
|
-
style={{ overflow: 'visible', textAlign: 'left' }}
|
|
140
|
-
>
|
|
141
|
-
<div
|
|
142
|
-
className="lf-node-text-auto-wrap"
|
|
143
|
-
style={{
|
|
144
|
-
minHeight: foreignObjectHeight,
|
|
145
|
-
width: textRealWidth,
|
|
146
|
-
padding: wrapPadding,
|
|
147
|
-
}}
|
|
148
|
-
>
|
|
149
|
-
<div
|
|
150
|
-
className={
|
|
151
|
-
isEllipsis
|
|
152
|
-
? 'lf-node-text-ellipsis-content'
|
|
153
|
-
: 'lf-node-text-auto-wrap-content'
|
|
154
|
-
}
|
|
155
|
-
title={isEllipsis ? rows.join('') : ''}
|
|
156
|
-
style={{ ...(props as h.JSX.CSSProperties) }}
|
|
157
|
-
>
|
|
158
|
-
{rows.map((row) => (
|
|
159
|
-
<div className="lf-node-text--auto-wrap-inner">{row}</div>
|
|
160
|
-
))}
|
|
161
|
-
</div>
|
|
162
|
-
</div>
|
|
163
|
-
</foreignObject>
|
|
164
|
-
</g>
|
|
165
|
-
)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export default Text
|
package/src/view/shape/index.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames'
|
|
2
|
-
import { createElement as h, Component } from 'preact/compat'
|
|
3
|
-
import { ElementState, EventType } from '../../constant'
|
|
4
|
-
import { GraphModel, BaseNodeModel, BaseEdgeModel } from '../../model'
|
|
5
|
-
import { Text } from '../shape'
|
|
6
|
-
import { IDragParams, StepDrag } from '../../util'
|
|
7
|
-
|
|
8
|
-
export type IBaseTextProps = {
|
|
9
|
-
model: BaseNodeModel | BaseEdgeModel
|
|
10
|
-
graphModel: GraphModel
|
|
11
|
-
draggable: boolean
|
|
12
|
-
editable: boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type IBaseTextState = {
|
|
16
|
-
isHovered: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class BaseText<
|
|
20
|
-
P extends IBaseTextProps,
|
|
21
|
-
S extends IBaseTextState,
|
|
22
|
-
> extends Component<P, S> {
|
|
23
|
-
stepperDrag: StepDrag
|
|
24
|
-
|
|
25
|
-
constructor(props: P) {
|
|
26
|
-
super()
|
|
27
|
-
const { draggable } = props
|
|
28
|
-
// TODO: 确认为什么不在 new 的时候传入 model,而在下面使用的时候赋值
|
|
29
|
-
this.stepperDrag = new StepDrag({
|
|
30
|
-
onDragging: this.onDragging,
|
|
31
|
-
step: 1,
|
|
32
|
-
// model,
|
|
33
|
-
eventType: 'TEXT',
|
|
34
|
-
isStopPropagation: draggable,
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getShape(): h.JSX.Element | null {
|
|
39
|
-
const { model, graphModel } = this.props
|
|
40
|
-
const { editConfigModel } = graphModel
|
|
41
|
-
const {
|
|
42
|
-
text: { value, x, y, editable, draggable },
|
|
43
|
-
} = model
|
|
44
|
-
const attr = {
|
|
45
|
-
x,
|
|
46
|
-
y,
|
|
47
|
-
className: '',
|
|
48
|
-
value,
|
|
49
|
-
}
|
|
50
|
-
// DONE: 代码优化,看是否可以引入 classnames
|
|
51
|
-
// TODO: 确认下面逻辑是否正确,确认正确后删除下面注释
|
|
52
|
-
// if (editable) {
|
|
53
|
-
// attr.className = 'lf-element-text';
|
|
54
|
-
// } else if (draggable || editConfigModel.nodeTextDraggable) {
|
|
55
|
-
// attr.className = 'lf-text-draggable';
|
|
56
|
-
// } else {
|
|
57
|
-
// attr.className = 'lf-text-disabled';
|
|
58
|
-
// }
|
|
59
|
-
const style = model.getTextStyle()
|
|
60
|
-
const isDraggable = editConfigModel.nodeTextDraggable || draggable
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<Text
|
|
64
|
-
{...attr}
|
|
65
|
-
{...style}
|
|
66
|
-
className={classNames({
|
|
67
|
-
'lf-element-text': editable,
|
|
68
|
-
'lf-text-draggable': !editable && isDraggable,
|
|
69
|
-
'lf-text-disabled': !editable && !isDraggable,
|
|
70
|
-
})}
|
|
71
|
-
model={model}
|
|
72
|
-
/>
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
mouseDownHandler = (e: PointerEvent) => {
|
|
77
|
-
const { draggable, model, graphModel } = this.props
|
|
78
|
-
const {
|
|
79
|
-
editConfigModel: { nodeTextDraggable },
|
|
80
|
-
} = graphModel
|
|
81
|
-
|
|
82
|
-
if (draggable ?? nodeTextDraggable) {
|
|
83
|
-
e.stopPropagation()
|
|
84
|
-
this.stepperDrag.model = model
|
|
85
|
-
this.stepperDrag.handleMouseDown(e)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
onDragging = ({ deltaX, deltaY }: IDragParams) => {
|
|
90
|
-
const {
|
|
91
|
-
model,
|
|
92
|
-
graphModel: { transformModel },
|
|
93
|
-
} = this.props
|
|
94
|
-
|
|
95
|
-
if (deltaX || deltaY) {
|
|
96
|
-
const [curDeltaX, curDeltaY] = transformModel.fixDeltaXY(deltaX, deltaY)
|
|
97
|
-
model.moveText(curDeltaX, curDeltaY)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
dbClickHandler = () => {
|
|
102
|
-
// 静默模式下,双击不更改状态,不可编辑
|
|
103
|
-
const {
|
|
104
|
-
editable,
|
|
105
|
-
graphModel: { eventCenter },
|
|
106
|
-
model,
|
|
107
|
-
} = this.props
|
|
108
|
-
if (editable) {
|
|
109
|
-
model.setElementState(ElementState.TEXT_EDIT)
|
|
110
|
-
}
|
|
111
|
-
eventCenter.emit(EventType.TEXT_DBCLICK, {
|
|
112
|
-
data: model.text,
|
|
113
|
-
model,
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
render(): h.JSX.Element | undefined {
|
|
118
|
-
const {
|
|
119
|
-
model: { text },
|
|
120
|
-
} = this.props
|
|
121
|
-
if (text) {
|
|
122
|
-
return (
|
|
123
|
-
<g
|
|
124
|
-
onPointerDown={this.mouseDownHandler}
|
|
125
|
-
onDblClick={this.dbClickHandler}
|
|
126
|
-
>
|
|
127
|
-
{this.getShape()}
|
|
128
|
-
</g>
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export default BaseText
|