feat: add executeInsertControl api

pr675
Hufe921 2 years ago
parent b024050b3e
commit e5b3d05991

@ -932,6 +932,16 @@ Usage:
instance.command.executeLocationControl(controlId: string) instance.command.executeLocationControl(controlId: string)
``` ```
## executeInsertControl
Feature: Insert control
Usage:
```javascript
instance.command.executeInsertControl(payload: IElement)
```
## executeUpdateOptions ## executeUpdateOptions
Feature: Update options Feature: Update options

@ -932,6 +932,16 @@ instance.command.executeSetControlHighlight(payload: ISetControlHighlightOption)
instance.command.executeLocationControl(controlId: string) instance.command.executeLocationControl(controlId: string)
``` ```
## executeInsertControl
功能:插入控件
用法:
```javascript
instance.command.executeInsertControl(payload: IElement)
```
## executeUpdateOptions ## executeUpdateOptions
功能:修改配置 功能:修改配置

@ -92,6 +92,7 @@ export class Command {
public executeSetControlProperties: CommandAdapt['setControlProperties'] public executeSetControlProperties: CommandAdapt['setControlProperties']
public executeSetControlHighlight: CommandAdapt['setControlHighlight'] public executeSetControlHighlight: CommandAdapt['setControlHighlight']
public executeLocationControl: CommandAdapt['locationControl'] public executeLocationControl: CommandAdapt['locationControl']
public executeInsertControl: CommandAdapt['insertControl']
public executeUpdateOptions: CommandAdapt['updateOptions'] public executeUpdateOptions: CommandAdapt['updateOptions']
public executeInsertTitle: CommandAdapt['insertTitle'] public executeInsertTitle: CommandAdapt['insertTitle']
public getCatalog: CommandAdapt['getCatalog'] public getCatalog: CommandAdapt['getCatalog']
@ -242,5 +243,6 @@ export class Command {
this.getControlValue = adapt.getControlValue.bind(adapt) this.getControlValue = adapt.getControlValue.bind(adapt)
this.getControlList = adapt.getControlList.bind(adapt) this.getControlList = adapt.getControlList.bind(adapt)
this.executeLocationControl = adapt.locationControl.bind(adapt) this.executeLocationControl = adapt.locationControl.bind(adapt)
this.executeInsertControl = adapt.insertControl.bind(adapt)
} }
} }

@ -2582,6 +2582,25 @@ export class CommandAdapt {
} }
} }
public insertControl(payload: IElement) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
const cloneElement = deepClone(payload)
// 格式化上下文信息
const { startIndex } = this.range.getRange()
const elementList = this.draw.getElementList()
const copyElement = getAnchorElement(elementList, startIndex)
if (!copyElement) return
const cloneAttr = [
...TABLE_CONTEXT_ATTR,
...EDITOR_ROW_ATTR,
...LIST_CONTEXT_ATTR
]
cloneProperty<IElement>(cloneAttr, copyElement, cloneElement)
// 插入控件
this.draw.insertElementList([cloneElement])
}
public getContainer(): HTMLDivElement { public getContainer(): HTMLDivElement {
return this.draw.getContainer() return this.draw.getContainer()
} }

Loading…
Cancel
Save