diff --git a/docs/guide/command-execute.md b/docs/guide/command-execute.md index da756ee..63a33d3 100644 --- a/docs/guide/command-execute.md +++ b/docs/guide/command-execute.md @@ -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) +``` + ## executeRemoveControl 功能:删除控件 diff --git a/src/editor/core/command/Command.ts b/src/editor/core/command/Command.ts index e9d3d72..a2c9aba 100644 --- a/src/editor/core/command/Command.ts +++ b/src/editor/core/command/Command.ts @@ -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) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index ebfc4f2..1c5a3ab 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -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) { + this.draw.setValue(payload) + } + public removeControl() { const { startIndex, endIndex } = this.range.getRange() if (startIndex !== endIndex) return diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index ce0d78d..c52c134 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -738,6 +738,34 @@ export class Draw { } } + public setValue(payload: Partial) { + 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) diff --git a/src/editor/core/history/HistoryManager.ts b/src/editor/core/history/HistoryManager.ts index e8ef8f3..371b843 100644 --- a/src/editor/core/history/HistoryManager.ts +++ b/src/editor/core/history/HistoryManager.ts @@ -47,4 +47,9 @@ export class HistoryManager { return !!this.redoStack.length } + public recovery() { + this.undoStack = [] + this.redoStack = [] + } + } \ No newline at end of file