@logicflow/core 2.0.12 → 2.0.14
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/__tests__/algorithm/index.test.ts +22 -17
- package/__tests__/algorithm/outline.test.ts +9 -9
- package/__tests__/event/event.test.ts +18 -18
- package/__tests__/history/history.test.ts +23 -23
- package/__tests__/logicflow.test.ts +236 -228
- package/__tests__/model/graphmodel.test.ts +51 -31
- package/__tests__/util/compatible.test.ts +5 -5
- package/__tests__/util/geometry.test.ts +10 -10
- package/__tests__/util/graph.test.ts +12 -12
- package/__tests__/util/matrix.test.ts +26 -26
- package/__tests__/util/node.test.ts +22 -22
- package/__tests__/util/sampling.test.ts +6 -10
- package/__tests__/util/vector.test.ts +36 -36
- package/__tests__/util/zIndex.test.ts +6 -6
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.d.ts +29 -4
- package/es/LogicFlow.js +35 -6
- package/es/model/GraphModel.d.ts +35 -1
- package/es/model/GraphModel.js +45 -5
- package/es/model/node/RectNodeModel.js +3 -0
- package/es/options.d.ts +1 -0
- package/es/util/theme.d.ts +67 -2
- package/es/util/theme.js +189 -2
- package/es/view/Graph.d.ts +0 -3
- package/es/view/Graph.js +3 -7
- package/es/view/edge/BaseEdge.d.ts +4 -0
- package/es/view/edge/BaseEdge.js +45 -3
- package/es/view/overlay/Grid.js +3 -2
- package/es/view/overlay/ToolOverlay.d.ts +1 -3
- package/es/view/overlay/ToolOverlay.js +2 -39
- package/es/view/shape/Polygon.d.ts +8 -0
- package/es/view/shape/Polygon.js +50 -3
- package/lib/LogicFlow.d.ts +29 -4
- package/lib/LogicFlow.js +34 -5
- package/lib/model/GraphModel.d.ts +35 -1
- package/lib/model/GraphModel.js +43 -3
- package/lib/model/node/RectNodeModel.js +3 -0
- package/lib/options.d.ts +1 -0
- package/lib/util/theme.d.ts +67 -2
- package/lib/util/theme.js +192 -2
- package/lib/view/Graph.d.ts +0 -3
- package/lib/view/Graph.js +2 -6
- package/lib/view/edge/BaseEdge.d.ts +4 -0
- package/lib/view/edge/BaseEdge.js +45 -3
- package/lib/view/overlay/Grid.js +3 -2
- package/lib/view/overlay/ToolOverlay.d.ts +1 -3
- package/lib/view/overlay/ToolOverlay.js +2 -39
- package/lib/view/shape/Polygon.d.ts +8 -0
- package/lib/view/shape/Polygon.js +52 -4
- package/package.json +1 -1
- package/src/LogicFlow.tsx +57 -7
- package/src/model/GraphModel.ts +56 -3
- package/src/model/edge/index.ts +4 -4
- package/src/model/index.ts +7 -7
- package/src/model/node/RectNodeModel.ts +2 -1
- package/src/model/node/index.ts +8 -8
- package/src/options.ts +1 -0
- package/src/util/theme.ts +198 -3
- package/src/view/Graph.tsx +3 -15
- package/src/view/edge/BaseEdge.tsx +96 -12
- package/src/view/overlay/Grid.tsx +2 -1
- package/src/view/overlay/ToolOverlay.tsx +2 -17
- package/src/view/shape/Polygon.tsx +56 -4
- package/stats.html +1 -1
package/src/LogicFlow.tsx
CHANGED
|
@@ -14,7 +14,12 @@ import {
|
|
|
14
14
|
|
|
15
15
|
import Graph from './view/Graph'
|
|
16
16
|
import * as _View from './view'
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
formatData,
|
|
19
|
+
addThemeMode,
|
|
20
|
+
removeThemeMode,
|
|
21
|
+
clearThemeMode,
|
|
22
|
+
} from './util'
|
|
18
23
|
|
|
19
24
|
import { Dnd, snapline } from './view/behavior'
|
|
20
25
|
import Tool from './tool'
|
|
@@ -22,6 +27,7 @@ import History from './history'
|
|
|
22
27
|
import Keyboard, { initDefaultShortcut } from './keyboard'
|
|
23
28
|
import { EventCallback, CallbackArgs, EventArgs } from './event/eventEmitter'
|
|
24
29
|
import { ElementType, EventType, SegmentDirection } from './constant'
|
|
30
|
+
import { Grid } from './view/overlay'
|
|
25
31
|
|
|
26
32
|
import Extension = LogicFlow.Extension
|
|
27
33
|
import ExtensionConfig = LogicFlow.ExtensionConfig
|
|
@@ -733,6 +739,14 @@ export class LogicFlow {
|
|
|
733
739
|
}
|
|
734
740
|
}
|
|
735
741
|
|
|
742
|
+
/**
|
|
743
|
+
* 移除选中的元素
|
|
744
|
+
* @param id 元素ID
|
|
745
|
+
*/
|
|
746
|
+
deselectElementById(id: string) {
|
|
747
|
+
this.graphModel.deselectElementById(id)
|
|
748
|
+
}
|
|
749
|
+
|
|
736
750
|
/**
|
|
737
751
|
* 获取选中的元素数据
|
|
738
752
|
* @param isIgnoreCheck 是否包括sourceNode和targetNode没有被选中的边,默认包括。
|
|
@@ -821,7 +835,7 @@ export class LogicFlow {
|
|
|
821
835
|
|
|
822
836
|
/**
|
|
823
837
|
* 设置元素的自定义属性
|
|
824
|
-
* @see
|
|
838
|
+
* @see http://logicflow.cn/api/detail#setproperties
|
|
825
839
|
* @param id 元素的id
|
|
826
840
|
* @param properties 自定义属性
|
|
827
841
|
*/
|
|
@@ -881,7 +895,7 @@ export class LogicFlow {
|
|
|
881
895
|
/**
|
|
882
896
|
* 更新流程图编辑相关设置
|
|
883
897
|
* @param {object} config 编辑配置
|
|
884
|
-
* @see
|
|
898
|
+
* @see http://logicflow.cn/api/detail#updateeditconfig
|
|
885
899
|
*/
|
|
886
900
|
updateEditConfig(config: Partial<IEditConfigType>) {
|
|
887
901
|
const { editConfigModel, transformModel } = this.graphModel
|
|
@@ -906,7 +920,7 @@ export class LogicFlow {
|
|
|
906
920
|
|
|
907
921
|
/**
|
|
908
922
|
* 获取流程图当前编辑相关设置
|
|
909
|
-
* @see
|
|
923
|
+
* @see http://logicflow.cn/api/detail#geteditconfig
|
|
910
924
|
*/
|
|
911
925
|
getEditConfig() {
|
|
912
926
|
return this.graphModel.editConfigModel.getConfig()
|
|
@@ -920,8 +934,18 @@ export class LogicFlow {
|
|
|
920
934
|
* @param { object } style 自定义主题样式
|
|
921
935
|
* todo docs link
|
|
922
936
|
*/
|
|
923
|
-
setTheme(
|
|
924
|
-
|
|
937
|
+
setTheme(
|
|
938
|
+
style: Partial<LogicFlow.Theme>,
|
|
939
|
+
themeMode?: 'radius' | 'dark' | 'colorful' | 'default' | string,
|
|
940
|
+
): void {
|
|
941
|
+
this.graphModel.setTheme(style, themeMode)
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* 获取当前主题样式
|
|
945
|
+
* @see todo docs link
|
|
946
|
+
*/
|
|
947
|
+
getTheme(): LogicFlow.Theme {
|
|
948
|
+
return this.graphModel.getTheme()
|
|
925
949
|
}
|
|
926
950
|
|
|
927
951
|
private focusByElement(id: string) {
|
|
@@ -1325,6 +1349,23 @@ export class LogicFlow {
|
|
|
1325
1349
|
})
|
|
1326
1350
|
}
|
|
1327
1351
|
|
|
1352
|
+
/**
|
|
1353
|
+
* 添加主题模式
|
|
1354
|
+
* @param themeMode 主题模式
|
|
1355
|
+
* @param style 主题样式
|
|
1356
|
+
*/
|
|
1357
|
+
static addThemeMode(themeMode: string, style: Partial<LogicFlow.Theme>) {
|
|
1358
|
+
addThemeMode(themeMode, style)
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
static removeThemeMode(themeMode: string) {
|
|
1362
|
+
removeThemeMode(themeMode)
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
static clearThemeMode() {
|
|
1366
|
+
clearThemeMode()
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1328
1369
|
private installPlugins(disabledPlugins: string[] = []) {
|
|
1329
1370
|
const extensionsAddByUse = Array.from(
|
|
1330
1371
|
LogicFlow.extensions,
|
|
@@ -1391,6 +1432,7 @@ export class LogicFlow {
|
|
|
1391
1432
|
this.graphModel.destroy()
|
|
1392
1433
|
this.tool.destroy()
|
|
1393
1434
|
this.history.destroy()
|
|
1435
|
+
this.clearThemeMode()
|
|
1394
1436
|
for (const extensionName in this.extension) {
|
|
1395
1437
|
const extensionInstance = this.extension[extensionName]
|
|
1396
1438
|
if ('destroy' in extensionInstance) {
|
|
@@ -1793,6 +1835,10 @@ export namespace LogicFlow {
|
|
|
1793
1835
|
refX?: number
|
|
1794
1836
|
refY?: number
|
|
1795
1837
|
verticalLength: number
|
|
1838
|
+
endArrowType?: 'solid' | 'hollow' | 'diamond' | 'circle' | 'none' // 结束箭头类型
|
|
1839
|
+
startArrowType?: 'solid' | 'hollow' | 'diamond' | 'circle' | 'none' // 开始箭头类型
|
|
1840
|
+
strokeLinecap?: 'butt' | 'round' | 'square' // 线条的端点样式
|
|
1841
|
+
strokeLinejoin?: 'miter' | 'round' | 'bevel' // 线条的连接样式
|
|
1796
1842
|
} & CommonTheme
|
|
1797
1843
|
export type ArrowAttributesType = {
|
|
1798
1844
|
d: string
|
|
@@ -1817,7 +1863,7 @@ export namespace LogicFlow {
|
|
|
1817
1863
|
* 基础图形线相关主题
|
|
1818
1864
|
*/
|
|
1819
1865
|
line: EdgeTheme // 直线样式
|
|
1820
|
-
polyline: EdgePolylineTheme //
|
|
1866
|
+
polyline: EdgePolylineTheme // 折线样式
|
|
1821
1867
|
bezier: EdgeBezierTheme // 贝塞尔曲线样式
|
|
1822
1868
|
anchorLine: AnchorLineTheme // 从锚点拉出的边的样式
|
|
1823
1869
|
|
|
@@ -1847,6 +1893,10 @@ export namespace LogicFlow {
|
|
|
1847
1893
|
edgeAdjust: CircleTheme
|
|
1848
1894
|
outline: OutlineTheme // 节点选择状态下外侧的选框样式
|
|
1849
1895
|
edgeAnimation: EdgeAnimation // 边动画样式
|
|
1896
|
+
|
|
1897
|
+
// 画布背景
|
|
1898
|
+
background?: boolean | Partial<LFOptions.BackgroundConfig>
|
|
1899
|
+
grid?: boolean | Partial<Grid.GridOptions>
|
|
1850
1900
|
}
|
|
1851
1901
|
}
|
|
1852
1902
|
|
package/src/model/GraphModel.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
merge,
|
|
6
6
|
isBoolean,
|
|
7
7
|
debounce,
|
|
8
|
+
cloneDeep,
|
|
8
9
|
isNil,
|
|
9
10
|
} from 'lodash-es'
|
|
10
11
|
import { action, computed, observable } from 'mobx'
|
|
@@ -42,6 +43,8 @@ import {
|
|
|
42
43
|
setupTheme,
|
|
43
44
|
snapToGrid,
|
|
44
45
|
updateTheme,
|
|
46
|
+
backgroundModeMap,
|
|
47
|
+
gridModeMap,
|
|
45
48
|
} from '../util'
|
|
46
49
|
import EventEmitter from '../event/eventEmitter'
|
|
47
50
|
import { Grid } from '../view/overlay'
|
|
@@ -64,6 +67,8 @@ export class GraphModel {
|
|
|
64
67
|
|
|
65
68
|
// 流程图主题配置
|
|
66
69
|
@observable theme: LogicFlow.Theme
|
|
70
|
+
// 初始化样式
|
|
71
|
+
customStyles: object
|
|
67
72
|
// 网格配置
|
|
68
73
|
@observable grid: Grid.GridOptions
|
|
69
74
|
// 事件中心
|
|
@@ -165,8 +170,11 @@ export class GraphModel {
|
|
|
165
170
|
// TODO:需要让用户设置成 0 吗?后面可以讨论一下
|
|
166
171
|
this.gridSize = grid.size || 1 // 默认 gridSize 设置为 1
|
|
167
172
|
}
|
|
168
|
-
this.
|
|
173
|
+
this.customStyles = options.style || {}
|
|
169
174
|
this.grid = Grid.getGridOptions(grid ?? false)
|
|
175
|
+
this.theme = setupTheme(options.style, options.themeMode)
|
|
176
|
+
this.theme.grid = cloneDeep(this.grid)
|
|
177
|
+
this.theme.background = cloneDeep(this.background)
|
|
170
178
|
this.edgeType = options.edgeType || 'polyline'
|
|
171
179
|
this.animation = setupAnimation(animation)
|
|
172
180
|
this.overlapMode = options.overlapMode || OverlapMode.DEFAULT
|
|
@@ -1197,6 +1205,14 @@ export class GraphModel {
|
|
|
1197
1205
|
selectElement?.setSelected(true)
|
|
1198
1206
|
}
|
|
1199
1207
|
|
|
1208
|
+
@action
|
|
1209
|
+
deselectElementById(id: string) {
|
|
1210
|
+
const element = this.getElement(id)
|
|
1211
|
+
if (element) {
|
|
1212
|
+
element.setSelected(false)
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1200
1216
|
/**
|
|
1201
1217
|
* 将所有选中的元素设置为非选中
|
|
1202
1218
|
*/
|
|
@@ -1463,8 +1479,45 @@ export class GraphModel {
|
|
|
1463
1479
|
* 设置主题
|
|
1464
1480
|
* todo docs link
|
|
1465
1481
|
*/
|
|
1466
|
-
@action setTheme(
|
|
1467
|
-
|
|
1482
|
+
@action setTheme(
|
|
1483
|
+
style: Partial<LogicFlow.Theme>,
|
|
1484
|
+
themeMode?: 'radius' | 'dark' | 'colorful' | 'default' | string,
|
|
1485
|
+
) {
|
|
1486
|
+
if (themeMode) {
|
|
1487
|
+
// 修改背景颜色
|
|
1488
|
+
backgroundModeMap[themeMode] &&
|
|
1489
|
+
this.updateBackgroundOptions({
|
|
1490
|
+
...(typeof this.background === 'object' ? this.background : {}),
|
|
1491
|
+
...backgroundModeMap[themeMode],
|
|
1492
|
+
})
|
|
1493
|
+
gridModeMap[themeMode] &&
|
|
1494
|
+
this.updateGridOptions(
|
|
1495
|
+
Grid.getGridOptions({ ...this.grid, ...gridModeMap[themeMode] }),
|
|
1496
|
+
)
|
|
1497
|
+
}
|
|
1498
|
+
if (style.background) {
|
|
1499
|
+
this.updateBackgroundOptions(style.background)
|
|
1500
|
+
}
|
|
1501
|
+
if (style.grid) {
|
|
1502
|
+
const formattedGrid = Grid.getGridOptions(style.grid ?? false)
|
|
1503
|
+
this.updateGridOptions(formattedGrid)
|
|
1504
|
+
}
|
|
1505
|
+
this.theme = updateTheme({ ...this.customStyles, ...style }, themeMode)
|
|
1506
|
+
this.customStyles = { ...this.customStyles, ...style }
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* 设置主题
|
|
1511
|
+
* todo docs link
|
|
1512
|
+
*/
|
|
1513
|
+
@action getTheme() {
|
|
1514
|
+
const { background, grid } = this
|
|
1515
|
+
const theme = {
|
|
1516
|
+
...cloneDeep(this.theme),
|
|
1517
|
+
background,
|
|
1518
|
+
grid,
|
|
1519
|
+
}
|
|
1520
|
+
return theme
|
|
1468
1521
|
}
|
|
1469
1522
|
|
|
1470
1523
|
/**
|
package/src/model/edge/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './BaseEdgeModel'
|
|
2
|
-
export * from './BezierEdgeModel'
|
|
3
|
-
export * from './LineEdgeModel'
|
|
4
|
-
export * from './PolylineEdgeModel'
|
|
1
|
+
export * from './BaseEdgeModel'
|
|
2
|
+
export * from './BezierEdgeModel'
|
|
3
|
+
export * from './LineEdgeModel'
|
|
4
|
+
export * from './PolylineEdgeModel'
|
package/src/model/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './edge'
|
|
2
|
-
export * from './node'
|
|
1
|
+
export * from './edge'
|
|
2
|
+
export * from './node'
|
|
3
3
|
|
|
4
|
-
export * from './BaseModel'
|
|
5
|
-
export * from './EditConfigModel'
|
|
6
|
-
export * from './GraphModel'
|
|
7
|
-
export * from './SnaplineModel'
|
|
8
|
-
export * from './TransformModel'
|
|
4
|
+
export * from './BaseModel'
|
|
5
|
+
export * from './EditConfigModel'
|
|
6
|
+
export * from './GraphModel'
|
|
7
|
+
export * from './SnaplineModel'
|
|
8
|
+
export * from './TransformModel'
|
|
@@ -36,11 +36,12 @@ export class RectNodeModel<
|
|
|
36
36
|
super.setAttributes()
|
|
37
37
|
|
|
38
38
|
const { width, height, radius } = this.properties
|
|
39
|
+
const { radius: styleRadius } = this.getNodeStyle()
|
|
39
40
|
if (!isNil(width)) this.width = width
|
|
40
41
|
if (!isNil(height)) this.height = height
|
|
41
|
-
|
|
42
42
|
// 矩形特有
|
|
43
43
|
if (!isNil(radius)) this.radius = radius
|
|
44
|
+
if (!isNil(styleRadius)) this.radius = styleRadius
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
getDefaultAnchor() {
|
package/src/model/node/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './BaseNodeModel'
|
|
2
|
-
export * from './CircleNodeModel'
|
|
3
|
-
export * from './DiamondNodeModel'
|
|
4
|
-
export * from './EllipseNodeModel'
|
|
5
|
-
export * from './PolygonNodeModel'
|
|
6
|
-
export * from './RectNodeModel'
|
|
7
|
-
export * from './TextNodeModel'
|
|
8
|
-
export * from './HtmlNodeModel'
|
|
1
|
+
export * from './BaseNodeModel'
|
|
2
|
+
export * from './CircleNodeModel'
|
|
3
|
+
export * from './DiamondNodeModel'
|
|
4
|
+
export * from './EllipseNodeModel'
|
|
5
|
+
export * from './PolygonNodeModel'
|
|
6
|
+
export * from './RectNodeModel'
|
|
7
|
+
export * from './TextNodeModel'
|
|
8
|
+
export * from './HtmlNodeModel'
|
package/src/options.ts
CHANGED
package/src/util/theme.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneDeep, merge } from 'lodash-es'
|
|
1
|
+
import { cloneDeep, merge, assign } from 'lodash-es'
|
|
2
2
|
import LogicFlow from '../LogicFlow'
|
|
3
3
|
|
|
4
4
|
export const defaultTheme: LogicFlow.Theme = {
|
|
@@ -135,13 +135,178 @@ export const defaultTheme: LogicFlow.Theme = {
|
|
|
135
135
|
strokeDasharray: '3,3',
|
|
136
136
|
},
|
|
137
137
|
}
|
|
138
|
+
export const radiusMode: any = {
|
|
139
|
+
rect: { radius: 8 },
|
|
140
|
+
diamond: { radius: 8 },
|
|
141
|
+
polygon: { radius: 8 },
|
|
142
|
+
polyline: { radius: 8 },
|
|
143
|
+
arrow: {
|
|
144
|
+
strokeLinecap: 'round',
|
|
145
|
+
strokeLinejoin: 'round',
|
|
146
|
+
offset: 10,
|
|
147
|
+
verticalLength: 5, // 箭头垂直于边的距离
|
|
148
|
+
},
|
|
149
|
+
snapline: {
|
|
150
|
+
strokeLinecap: 'round',
|
|
151
|
+
strokeLinejoin: 'round',
|
|
152
|
+
stroke: '#949494',
|
|
153
|
+
strokeWidth: 1,
|
|
154
|
+
},
|
|
155
|
+
outline: {
|
|
156
|
+
radius: 8,
|
|
157
|
+
fill: 'transparent',
|
|
158
|
+
stroke: '#949494',
|
|
159
|
+
strokeDasharray: '3,3',
|
|
160
|
+
hover: {
|
|
161
|
+
stroke: '#949494',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
resizeOutline: {
|
|
165
|
+
radius: 8,
|
|
166
|
+
fill: 'none',
|
|
167
|
+
stroke: 'transparent', // 矩形默认不显示调整边框
|
|
168
|
+
strokeWidth: 1,
|
|
169
|
+
strokeDasharray: '3,3',
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
export const darkMode: any = {
|
|
173
|
+
baseNode: {
|
|
174
|
+
fill: '#23272e',
|
|
175
|
+
stroke: '#fefeff',
|
|
176
|
+
},
|
|
177
|
+
baseEdge: {
|
|
178
|
+
stroke: '#fefeff',
|
|
179
|
+
},
|
|
180
|
+
rect: { radius: 8 },
|
|
181
|
+
diamond: { radius: 8 },
|
|
182
|
+
polygon: { radius: 8 },
|
|
183
|
+
polyline: { radius: 8 },
|
|
184
|
+
nodeText: {
|
|
185
|
+
color: '#fefeff',
|
|
186
|
+
overflowMode: 'default',
|
|
187
|
+
fontSize: 12,
|
|
188
|
+
lineHeight: 1.2,
|
|
189
|
+
},
|
|
190
|
+
arrow: {
|
|
191
|
+
strokeLinecap: 'round',
|
|
192
|
+
strokeLinejoin: 'round',
|
|
193
|
+
offset: 10,
|
|
194
|
+
verticalLength: 5, // 箭头垂直于边的距离
|
|
195
|
+
},
|
|
196
|
+
snapline: {
|
|
197
|
+
strokeLinecap: 'round',
|
|
198
|
+
strokeLinejoin: 'round',
|
|
199
|
+
stroke: '#949494',
|
|
200
|
+
strokeWidth: 1,
|
|
201
|
+
},
|
|
202
|
+
outline: {
|
|
203
|
+
radius: 8,
|
|
204
|
+
fill: 'transparent',
|
|
205
|
+
stroke: '#949494',
|
|
206
|
+
strokeDasharray: '3,3',
|
|
207
|
+
hover: {
|
|
208
|
+
stroke: '#949494',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
resizeOutline: {
|
|
212
|
+
radius: 8,
|
|
213
|
+
fill: 'none',
|
|
214
|
+
stroke: 'transparent', // 矩形默认不显示调整边框
|
|
215
|
+
strokeWidth: 1,
|
|
216
|
+
strokeDasharray: '3,3',
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
export const colorfulMode: any = {
|
|
220
|
+
rect: { fill: '#72CBFF', stroke: '#3ABDF9', radius: 8 },
|
|
221
|
+
circle: { fill: '#FFE075', stroke: '#F9CE3A', radius: 8 },
|
|
222
|
+
ellipse: { fill: '#FFA8A8', stroke: '#FF6B66', radius: 8 },
|
|
223
|
+
text: { fill: '#72CBFF', radius: 8 },
|
|
224
|
+
diamond: { fill: '#96F7AF', stroke: '#40EF7E', radius: 8 },
|
|
225
|
+
polygon: { fill: '#E0A8FF', stroke: '#C271FF', radius: 8 },
|
|
226
|
+
polyline: { radius: 8 },
|
|
227
|
+
arrow: {
|
|
228
|
+
strokeLinecap: 'round',
|
|
229
|
+
strokeLinejoin: 'round',
|
|
230
|
+
offset: 10,
|
|
231
|
+
verticalLength: 5, // 箭头垂直于边的距离
|
|
232
|
+
},
|
|
233
|
+
snapline: {
|
|
234
|
+
strokeLinecap: 'round',
|
|
235
|
+
strokeLinejoin: 'round',
|
|
236
|
+
stroke: '#949494',
|
|
237
|
+
strokeWidth: 1,
|
|
238
|
+
},
|
|
239
|
+
outline: {
|
|
240
|
+
radius: 8,
|
|
241
|
+
fill: 'transparent',
|
|
242
|
+
stroke: '#949494',
|
|
243
|
+
strokeDasharray: '3,3',
|
|
244
|
+
hover: {
|
|
245
|
+
stroke: '#949494',
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
resizeOutline: {
|
|
249
|
+
radius: 8,
|
|
250
|
+
fill: 'none',
|
|
251
|
+
stroke: 'transparent', // 矩形默认不显示调整边框
|
|
252
|
+
strokeWidth: 1,
|
|
253
|
+
strokeDasharray: '3,3',
|
|
254
|
+
},
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const themeModeMap = {
|
|
258
|
+
colorful: colorfulMode,
|
|
259
|
+
dark: darkMode,
|
|
260
|
+
radius: radiusMode,
|
|
261
|
+
default: defaultTheme,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 不同主题的背景色
|
|
265
|
+
export const darkBackground = {
|
|
266
|
+
background: '#23272e',
|
|
267
|
+
}
|
|
268
|
+
export const colorfulBackground = {
|
|
269
|
+
background: '#fefeff',
|
|
270
|
+
}
|
|
271
|
+
export const defaultBackground = {
|
|
272
|
+
background: '#ffffff',
|
|
273
|
+
}
|
|
274
|
+
export const backgroundModeMap = {
|
|
275
|
+
colorful: colorfulBackground,
|
|
276
|
+
dark: darkBackground,
|
|
277
|
+
radius: defaultBackground,
|
|
278
|
+
default: defaultBackground,
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 不同主题的网格样式
|
|
282
|
+
export const darkGrid = {
|
|
283
|
+
color: '#66676a',
|
|
284
|
+
thickness: 1,
|
|
285
|
+
}
|
|
286
|
+
export const colorfulGrid = {
|
|
287
|
+
color: '#dadada',
|
|
288
|
+
thickness: 1,
|
|
289
|
+
}
|
|
290
|
+
export const defaultGrid = {
|
|
291
|
+
color: '#acacac',
|
|
292
|
+
thickness: 1,
|
|
293
|
+
}
|
|
294
|
+
export const gridModeMap = {
|
|
295
|
+
colorful: colorfulGrid,
|
|
296
|
+
dark: darkGrid,
|
|
297
|
+
radius: defaultGrid,
|
|
298
|
+
default: defaultGrid,
|
|
299
|
+
}
|
|
138
300
|
|
|
139
301
|
/* 主题(全局样式)相关工具方法 */
|
|
140
302
|
export const setupTheme = (
|
|
141
303
|
customTheme?: Partial<LogicFlow.Theme>,
|
|
304
|
+
themeMode?: 'radius' | 'dark' | 'colorful' | 'default' | string,
|
|
142
305
|
): LogicFlow.Theme => {
|
|
143
306
|
let theme = cloneDeep(defaultTheme)
|
|
144
|
-
|
|
307
|
+
if (themeMode) {
|
|
308
|
+
theme = merge(theme, themeModeMap[themeMode])
|
|
309
|
+
}
|
|
145
310
|
if (customTheme) {
|
|
146
311
|
/**
|
|
147
312
|
* 为了不让默认样式被覆盖,使用 merge 方法
|
|
@@ -172,9 +337,39 @@ export const setupTheme = (
|
|
|
172
337
|
*/
|
|
173
338
|
theme = merge(theme, customTheme)
|
|
174
339
|
}
|
|
175
|
-
|
|
176
340
|
return theme
|
|
177
341
|
}
|
|
178
342
|
|
|
343
|
+
export const addThemeMode = (
|
|
344
|
+
themeMode: string,
|
|
345
|
+
style: Partial<LogicFlow.Theme>,
|
|
346
|
+
): void => {
|
|
347
|
+
if (themeModeMap[themeMode]) {
|
|
348
|
+
console.warn(`theme mode ${themeMode} already exists`)
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
themeModeMap[themeMode] = style
|
|
352
|
+
backgroundModeMap[themeMode] = style.background || defaultBackground
|
|
353
|
+
gridModeMap[themeMode] = style.grid || defaultGrid
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export const removeThemeMode = (themeMode: string): void => {
|
|
357
|
+
delete themeModeMap[themeMode]
|
|
358
|
+
delete backgroundModeMap[themeMode]
|
|
359
|
+
delete gridModeMap[themeMode]
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export const clearThemeMode = (): void => {
|
|
363
|
+
const resetTheme = {
|
|
364
|
+
colorful: {},
|
|
365
|
+
dark: {},
|
|
366
|
+
radius: {},
|
|
367
|
+
default: {},
|
|
368
|
+
}
|
|
369
|
+
assign(themeModeMap, resetTheme)
|
|
370
|
+
assign(backgroundModeMap, resetTheme)
|
|
371
|
+
assign(gridModeMap, resetTheme)
|
|
372
|
+
}
|
|
373
|
+
|
|
179
374
|
/* 更新 theme 方法 */
|
|
180
375
|
export const updateTheme = setupTheme
|
package/src/view/Graph.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, ComponentType
|
|
1
|
+
import { Component, ComponentType } from 'preact/compat'
|
|
2
2
|
import { map, throttle } from 'lodash-es'
|
|
3
3
|
import {
|
|
4
4
|
CanvasOverlay,
|
|
@@ -38,10 +38,6 @@ type ContainerStyle = {
|
|
|
38
38
|
|
|
39
39
|
@observer
|
|
40
40
|
class Graph extends Component<IGraphProps> {
|
|
41
|
-
canvasOverlayRef = createRef<CanvasOverlay>()
|
|
42
|
-
getCanvasOverlay = () => {
|
|
43
|
-
return this.canvasOverlayRef.current
|
|
44
|
-
}
|
|
45
41
|
private handleResize = () => {
|
|
46
42
|
const { graphModel, options } = this.props
|
|
47
43
|
const { width, height, isContainerWidth, isContainerHeight } = graphModel
|
|
@@ -113,11 +109,7 @@ class Graph extends Component<IGraphProps> {
|
|
|
113
109
|
return (
|
|
114
110
|
<div className="lf-graph" flow-id={graphModel.flowId} style={style}>
|
|
115
111
|
{/* 元素层 */}
|
|
116
|
-
<CanvasOverlay
|
|
117
|
-
ref={this.canvasOverlayRef}
|
|
118
|
-
graphModel={graphModel}
|
|
119
|
-
dnd={dnd}
|
|
120
|
-
>
|
|
112
|
+
<CanvasOverlay graphModel={graphModel} dnd={dnd}>
|
|
121
113
|
<g className="lf-base">
|
|
122
114
|
{map(graphModel.sortElements, (nodeModel) =>
|
|
123
115
|
this.getComponent(nodeModel, graphModel),
|
|
@@ -136,11 +128,7 @@ class Graph extends Component<IGraphProps> {
|
|
|
136
128
|
)}
|
|
137
129
|
</ModificationOverlay>
|
|
138
130
|
{/* 工具层:插件 */}
|
|
139
|
-
<ToolOverlay
|
|
140
|
-
graphModel={graphModel}
|
|
141
|
-
tool={tool}
|
|
142
|
-
getCanvasOverlay={this.getCanvasOverlay}
|
|
143
|
-
/>
|
|
131
|
+
<ToolOverlay graphModel={graphModel} tool={tool} />
|
|
144
132
|
{/* 画布背景 */}
|
|
145
133
|
{background && <BackgroundOverlay background={background} />}
|
|
146
134
|
{/* 画布网格 */}
|