feat:add control context menu
This commit is contained in:
@@ -65,6 +65,7 @@ export class Command {
|
|||||||
private static pageScaleMinus: Function
|
private static pageScaleMinus: Function
|
||||||
private static pageScaleAdd: Function
|
private static pageScaleAdd: Function
|
||||||
private static insertElementList: Function
|
private static insertElementList: Function
|
||||||
|
private static removeControl: Function
|
||||||
|
|
||||||
constructor(adapt: CommandAdapt) {
|
constructor(adapt: CommandAdapt) {
|
||||||
Command.mode = adapt.mode.bind(adapt)
|
Command.mode = adapt.mode.bind(adapt)
|
||||||
@@ -123,6 +124,7 @@ export class Command {
|
|||||||
Command.pageScaleMinus = adapt.pageScaleMinus.bind(adapt)
|
Command.pageScaleMinus = adapt.pageScaleMinus.bind(adapt)
|
||||||
Command.pageScaleAdd = adapt.pageScaleAdd.bind(adapt)
|
Command.pageScaleAdd = adapt.pageScaleAdd.bind(adapt)
|
||||||
Command.insertElementList = adapt.insertElementList.bind(adapt)
|
Command.insertElementList = adapt.insertElementList.bind(adapt)
|
||||||
|
Command.removeControl = adapt.removeControl.bind(adapt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局命令
|
// 全局命令
|
||||||
@@ -355,4 +357,8 @@ export class Command {
|
|||||||
return Command.insertElementList(payload)
|
return Command.insertElementList(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public executeRemoveControl() {
|
||||||
|
return Command.removeControl()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1305,4 +1305,20 @@ export class CommandAdapt {
|
|||||||
this.draw.insertElementList(payload)
|
this.draw.insertElementList(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public removeControl() {
|
||||||
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
|
if (startIndex !== endIndex) return
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
const element = elementList[startIndex]
|
||||||
|
if (element.type !== ElementType.CONTROL) return
|
||||||
|
// 删除控件
|
||||||
|
const control = this.draw.getControl()
|
||||||
|
const newIndex = control.removeControl(startIndex)
|
||||||
|
// 重新渲染
|
||||||
|
this.range.setRange(newIndex, newIndex)
|
||||||
|
this.draw.render({
|
||||||
|
curIndex: newIndex
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import { Command } from '../command/Command'
|
|||||||
import { Draw } from '../draw/Draw'
|
import { Draw } from '../draw/Draw'
|
||||||
import { Position } from '../position/Position'
|
import { Position } from '../position/Position'
|
||||||
import { RangeManager } from '../range/RangeManager'
|
import { RangeManager } from '../range/RangeManager'
|
||||||
|
import { controlMenus } from './menus/controlMenus'
|
||||||
import { globalMenus } from './menus/globalMenus'
|
import { globalMenus } from './menus/globalMenus'
|
||||||
import { imageMenus } from './menus/imageMenus'
|
import { imageMenus } from './menus/imageMenus'
|
||||||
import { tableMenus } from './menus/tableMenus'
|
import { tableMenus } from './menus/tableMenus'
|
||||||
@@ -38,7 +39,8 @@ export class ContextMenu {
|
|||||||
this.contextMenuList = [
|
this.contextMenuList = [
|
||||||
...globalMenus,
|
...globalMenus,
|
||||||
...tableMenus,
|
...tableMenus,
|
||||||
...imageMenus
|
...imageMenus,
|
||||||
|
...controlMenus
|
||||||
]
|
]
|
||||||
this.contextMenuContainerList = []
|
this.contextMenuContainerList = []
|
||||||
this.contextMenuRelationShip = new Map()
|
this.contextMenuRelationShip = new Map()
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { ElementType } from '../../../dataset/enum/Element'
|
||||||
|
import { IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu'
|
||||||
|
import { Command } from '../../command/Command'
|
||||||
|
|
||||||
|
export const controlMenus: IRegisterContextMenu[] = [
|
||||||
|
{
|
||||||
|
name: '删除控件',
|
||||||
|
when: (payload) => {
|
||||||
|
return !payload.editorHasSelection && payload.startElement?.type === ElementType.CONTROL
|
||||||
|
},
|
||||||
|
callback: (command: Command) => {
|
||||||
|
command.executeRemoveControl()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user