-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 修复 GroupNode 中 getNodeStyle 解构后调用,BaseNodeModel 中 getNodeStyle 方…
…法 this 为空的问题 - 确认解构后赋值和直接 this.props.model.getNodeStyle() 方法调用的区别 -> this 指向的问题 - LogicFlow Examples 中新增 Group 插件
- Loading branch information
1 parent
2fd2e0d
commit 4802f1e
Showing
17 changed files
with
342 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+696 Bytes
examples/feature-examples/src/assets/group/subprocess-collapsed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions
11
examples/feature-examples/src/pages/extensions/group/index.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.viewport { | ||
position: relative; | ||
height: 70vh; | ||
overflow: hidden; | ||
} | ||
|
||
:global { | ||
.lf-dnd-shape { | ||
background-size: contain; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import LogicFlow from '@logicflow/core' | ||
import { | ||
Control, | ||
DndPanel, | ||
ShapeItem, | ||
Group, | ||
SelectionSelect, | ||
} from '@logicflow/extension' | ||
|
||
import { Button, Card, Divider, Flex } from 'antd' | ||
import { useEffect, useRef } from 'react' | ||
import { customGroup, subProcess } from './nodes' | ||
import GraphConfigData = LogicFlow.GraphConfigData | ||
|
||
import '@logicflow/core/es/index.css' | ||
import '@logicflow/extension/es/index.css' | ||
import styles from './index.less' | ||
|
||
const config: Partial<LogicFlow.Options> = { | ||
grid: true, | ||
multipleSelectKey: 'alt', | ||
autoExpand: false, | ||
keyboard: { | ||
enabled: true, | ||
}, | ||
plugins: [Group, Control, DndPanel, SelectionSelect], | ||
} | ||
|
||
const customDndConfig: ShapeItem[] = [ | ||
{ | ||
type: 'custom-group', | ||
label: '自定义分组', | ||
text: 'CustomGroup', | ||
icon: require('@/assets/group/group.png'), | ||
}, | ||
{ | ||
type: 'circle', | ||
label: '圆形', | ||
text: 'Circle', | ||
icon: require('@/assets/group/circle.png'), | ||
}, | ||
{ | ||
type: 'rect', | ||
label: '矩形', | ||
text: 'Rect', | ||
icon: require('@/assets/group/rect.png'), | ||
}, | ||
{ | ||
type: 'sub-process', | ||
label: '子流程-展开', | ||
text: 'SubProcess', | ||
icon: require('@/assets/group/subprocess-expanded.png'), | ||
}, | ||
{ | ||
type: 'sub-process', | ||
label: '子流程-收起', | ||
text: 'SubProcess', | ||
icon: require('@/assets/group/subprocess-collapsed.png'), | ||
}, | ||
] | ||
|
||
const getDndPanelConfig = (lf: LogicFlow): ShapeItem[] => [ | ||
{ | ||
label: '选区', | ||
icon: require('@/assets/bpmn/select.png'), | ||
callback: () => { | ||
lf.openSelectionSelect() | ||
lf.once('selection:selected', () => { | ||
lf.closeSelectionSelect() | ||
}) | ||
}, | ||
}, | ||
...customDndConfig, | ||
] | ||
|
||
export default function BPMNExtension() { | ||
const lfRef = useRef<LogicFlow>() | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
if (!lfRef.current) { | ||
const lf = new LogicFlow({ | ||
...config, | ||
container: containerRef.current as HTMLElement, | ||
}) | ||
|
||
const dndPanelConfig = getDndPanelConfig(lf) | ||
lf.setPatternItems(dndPanelConfig) | ||
|
||
lf.register(customGroup) | ||
lf.register(subProcess) | ||
|
||
// 获取渲染数据 | ||
const graphData: GraphConfigData = { | ||
nodes: [ | ||
// { | ||
// type: "custom-group", | ||
// x: 400, | ||
// y: 400, | ||
// text: 'custom-group1', | ||
// children: ["circle_1"] | ||
// }, | ||
// { | ||
// id: "circle_1", | ||
// type: "circle", | ||
// x: 400, | ||
// y: 400 | ||
// }, | ||
// { | ||
// id: "rect_1", | ||
// type: "rect", | ||
// x: 200, | ||
// y: 100 | ||
// }, | ||
// { | ||
// id: "circle_2", | ||
// type: "circle", | ||
// x: 800, | ||
// y: 140 | ||
// }, | ||
{ | ||
id: 'group_1', | ||
type: 'sub-process', | ||
x: 300, | ||
y: 120, | ||
// children: ["rect_3"], | ||
text: 'sub-process-1', | ||
properties: { | ||
isFolded: true, | ||
}, | ||
}, | ||
// { | ||
// id: "group_2", | ||
// type: "sub-process", | ||
// x: 800, | ||
// y: 120, | ||
// children: ["circle_4"], | ||
// text: 'sub-process-2', | ||
// properties: { | ||
// isFolded: true | ||
// } | ||
// } | ||
], | ||
edges: [], | ||
} | ||
lf.render(graphData) | ||
|
||
lfRef.current = lf | ||
} | ||
}, []) | ||
|
||
const getGraphData = () => {} | ||
|
||
const rerender = () => {} | ||
|
||
return ( | ||
<Card title="LogicFlow Extension - DndPanel" className="control-container"> | ||
<Flex wrap="wrap" gap="small"> | ||
<Button type="primary" key="getData" onClick={getGraphData}> | ||
获取数据 | ||
</Button> | ||
<Button type="primary" key="rerender" onClick={rerender}> | ||
重新渲染 | ||
</Button> | ||
</Flex> | ||
<Divider /> | ||
<div ref={containerRef} id="graph" className={styles.viewport}></div> | ||
</Card> | ||
) | ||
} |
60 changes: 60 additions & 0 deletions
60
examples/feature-examples/src/pages/extensions/group/nodes/custom-group/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import LogicFlow from '@logicflow/core' | ||
import { GroupNode, GroupNodeModel } from '@logicflow/extension' | ||
|
||
import NodeConfig = LogicFlow.NodeConfig | ||
import TextConfig = LogicFlow.TextConfig | ||
|
||
export class CustomGroup extends GroupNode {} | ||
|
||
export class CustomGroupModel extends GroupNodeModel { | ||
foldedText?: TextConfig | ||
|
||
initNodeData(data: NodeConfig) { | ||
super.initNodeData(data) | ||
this.isRestrict = true | ||
this.resizable = true | ||
this.width = 480 | ||
this.height = 280 | ||
} | ||
|
||
getNodeStyle() { | ||
const style = super.getNodeStyle() | ||
style.stroke = '#AEAFAE' | ||
style.strokeWidth = 1 | ||
return style | ||
} | ||
|
||
foldGroup(folded: boolean) { | ||
super.foldGroup(folded) | ||
// this.isFolded = folded | ||
|
||
if (folded) { | ||
if (this.foldedText) { | ||
this.text = { ...this.foldedText } | ||
} | ||
if (!this.text.value) { | ||
this.text.value = '已折叠分组' | ||
} | ||
this.text.x = this.x + 10 | ||
this.text.y = this.y | ||
} else { | ||
this.foldedText = { ...this.text } | ||
this.text.value = '' | ||
} | ||
} | ||
|
||
// isAllowAppendIn(nodeData) { | ||
// if (nodeData.type === 'rect') { | ||
// return false | ||
// } | ||
// return true | ||
// } | ||
} | ||
|
||
export const customGroup = { | ||
type: 'custom-group', | ||
view: CustomGroup, | ||
model: CustomGroupModel, | ||
} | ||
|
||
export default customGroup |
2 changes: 2 additions & 0 deletions
2
examples/feature-examples/src/pages/extensions/group/nodes/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './custom-group' | ||
export * from './sub-process' |
72 changes: 72 additions & 0 deletions
72
examples/feature-examples/src/pages/extensions/group/nodes/sub-process/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import LogicFlow from '@logicflow/core' | ||
import { GroupNode, GroupNodeModel } from '@logicflow/extension' | ||
|
||
import TextConfig = LogicFlow.TextConfig | ||
import NodeData = LogicFlow.NodeData | ||
|
||
export class SubProcess extends GroupNode {} | ||
|
||
export class SubProcessModel extends GroupNodeModel { | ||
foldedText?: TextConfig | ||
setAttributes() { | ||
// const size = 80 | ||
const circleOnlyAsTarget = { | ||
message: '正方形节点下一个节点只能是圆形节点', | ||
validate: () => { | ||
return false | ||
}, | ||
} | ||
this.targetRules.push(circleOnlyAsTarget) | ||
} | ||
|
||
initNodeData(data: NodeData) { | ||
super.initNodeData(data) | ||
this.foldable = true | ||
this.resizable = true | ||
this.width = 400 | ||
this.height = 200 | ||
} | ||
|
||
getNodeStyle() { | ||
const style = super.getNodeStyle() | ||
style.stroke = '#989891' | ||
style.strokeWidth = 1 | ||
style.strokeDasharray = '3 3' | ||
if (this.isSelected) { | ||
style.stroke = 'rgb(124, 15, 255)' | ||
} | ||
if (this.isFolded) { | ||
style.fill = '#47C769' | ||
} | ||
return style | ||
} | ||
|
||
foldGroup(folded: boolean) { | ||
super.foldGroup(folded) | ||
if (folded) { | ||
if (this.foldedText) { | ||
this.text = { ...this.foldedText } | ||
} | ||
if (!this.text.value) { | ||
this.text.value = '已折叠分组已折叠分组已折叠分组' | ||
} | ||
this.text.x = this.x + 10 | ||
this.text.y = this.y | ||
} else { | ||
this.foldedText = { ...this.text } | ||
this.text.value = '' | ||
} | ||
} | ||
|
||
// isAllowAppendIn(nodeData) { | ||
// return false | ||
// } | ||
} | ||
|
||
export const subProcess = { | ||
type: 'sub-process', | ||
view: SubProcess, | ||
model: SubProcessModel, | ||
} | ||
|
||
export default subProcess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.