feat: add setValue command api #210
Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
This commit is contained in:
@@ -551,6 +551,14 @@ instance.command.executeSetPaperMargin([top: number, right: number, bottom: numb
|
||||
instance.command.executeInsertElementList(elementList: IElement[])
|
||||
```
|
||||
|
||||
## executeSetValue
|
||||
功能:设置编辑器数据
|
||||
|
||||
用法:
|
||||
```javascript
|
||||
instance.command.executeSetValue(payload: Partial<IEditorData>)
|
||||
```
|
||||
|
||||
## executeRemoveControl
|
||||
功能:删除控件
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ export class Command {
|
||||
public executePaperDirection: CommandAdapt['paperDirection']
|
||||
public executeSetPaperMargin: CommandAdapt['setPaperMargin']
|
||||
public executeInsertElementList: CommandAdapt['insertElementList']
|
||||
public executeSetValue: CommandAdapt['setValue']
|
||||
public executeRemoveControl: CommandAdapt['removeControl']
|
||||
public executeSetLocale: CommandAdapt['setLocale']
|
||||
public executeLocationCatalog: CommandAdapt['locationCatalog']
|
||||
@@ -155,6 +156,7 @@ export class Command {
|
||||
this.executeSetPaperMargin = adapt.setPaperMargin.bind(adapt)
|
||||
// 通用
|
||||
this.executeInsertElementList = adapt.insertElementList.bind(adapt)
|
||||
this.executeSetValue = adapt.setValue.bind(adapt)
|
||||
this.executeRemoveControl = adapt.removeControl.bind(adapt)
|
||||
this.executeSetLocale = adapt.setLocale.bind(adapt)
|
||||
this.executeLocationCatalog = adapt.locationCatalog.bind(adapt)
|
||||
|
||||
@@ -13,7 +13,7 @@ import { TitleLevel } from '../../dataset/enum/Title'
|
||||
import { VerticalAlign } from '../../dataset/enum/VerticalAlign'
|
||||
import { ICatalog } from '../../interface/Catalog'
|
||||
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
|
||||
import { IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||
import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||
import { IElement, IElementStyle } from '../../interface/Element'
|
||||
import { IMargin } from '../../interface/Margin'
|
||||
import { IColgroup } from '../../interface/table/Colgroup'
|
||||
@@ -1655,6 +1655,10 @@ export class CommandAdapt {
|
||||
this.draw.insertElementList(payload)
|
||||
}
|
||||
|
||||
public setValue(payload: Partial<IEditorData>) {
|
||||
this.draw.setValue(payload)
|
||||
}
|
||||
|
||||
public removeControl() {
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
if (startIndex !== endIndex) return
|
||||
|
||||
@@ -738,6 +738,34 @@ export class Draw {
|
||||
}
|
||||
}
|
||||
|
||||
public setValue(payload: Partial<IEditorData>) {
|
||||
const { header, main, footer } = payload
|
||||
if (!header && !main && !footer) return
|
||||
if (header) {
|
||||
formatElementList(header, {
|
||||
editorOptions: this.options
|
||||
})
|
||||
this.header.setElementList(header)
|
||||
}
|
||||
if (main) {
|
||||
formatElementList(main, {
|
||||
editorOptions: this.options
|
||||
})
|
||||
this.elementList = main
|
||||
}
|
||||
if (footer) {
|
||||
formatElementList(footer, {
|
||||
editorOptions: this.options
|
||||
})
|
||||
this.footer.setElementList(footer)
|
||||
}
|
||||
// 渲染&计算&清空历史记录
|
||||
this.historyManager.recovery()
|
||||
this.render({
|
||||
isSetCursor: false
|
||||
})
|
||||
}
|
||||
|
||||
private _wrapContainer(rootContainer: HTMLElement): HTMLDivElement {
|
||||
const container = document.createElement('div')
|
||||
rootContainer.append(container)
|
||||
|
||||
@@ -47,4 +47,9 @@ export class HistoryManager {
|
||||
return !!this.redoStack.length
|
||||
}
|
||||
|
||||
public recovery() {
|
||||
this.undoStack = []
|
||||
this.redoStack = []
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user