Skip to content

Commit cdf9e8d

Browse files
ChangeSugerDymoneLewis
authored andcommitted
feat: menu插件功能完善
- 为menu插件中画布菜单选项的回调增加触发画布菜单时鼠标的坐标 - 增加对应的示例
1 parent 9eaae66 commit cdf9e8d

File tree

2 files changed

+14
-1
lines changed
  • examples/feature-examples/src/pages/extensions/menu
  • packages/extension/src/components/menu

2 files changed

+14
-1
lines changed

examples/feature-examples/src/pages/extensions/menu/index.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ export default function MenuExtension() {
171171
alert('分享成功!')
172172
},
173173
},
174+
{
175+
text: '添加节点',
176+
callback(data: LogicFlow.Position) {
177+
lf.addNode({
178+
type: 'rect',
179+
x: data.x,
180+
y: data.y,
181+
})
182+
},
183+
},
174184
],
175185
})
176186

packages/extension/src/components/menu/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import LogicFlow from '@logicflow/core'
33
import GraphData = LogicFlow.GraphData
44
import NodeData = LogicFlow.NodeData
55
import EdgeData = LogicFlow.EdgeData
6+
import Position = LogicFlow.Position
67

78
type SetType = 'add' | 'reset'
89

@@ -29,7 +30,8 @@ class Menu {
2930
private __container?: HTMLElement
3031
private __menuDOM?: HTMLElement
3132
private menuTypeMap?: Map<string, MenuItem[]>
32-
private __currentData: EdgeData | NodeData | GraphData | null = null
33+
private __currentData: EdgeData | NodeData | GraphData | Position | null =
34+
null
3335
static pluginName = 'menu'
3436

3537
constructor({ lf }) {
@@ -209,6 +211,7 @@ class Menu {
209211
const {
210212
domOverlayPosition: { x, y },
211213
} = position
214+
this.__currentData = { ...position.canvasOverlayPosition }
212215
this.showMenu(x, y, menuList)
213216
})
214217
this.lf.on('selection:contextmenu', ({ data, position }) => {

0 commit comments

Comments
 (0)