feat: get page value and append element api #211
This commit is contained in:
@@ -551,6 +551,14 @@ instance.command.executeSetPaperMargin([top: number, right: number, bottom: numb
|
|||||||
instance.command.executeInsertElementList(elementList: IElement[])
|
instance.command.executeInsertElementList(elementList: IElement[])
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## executeAppendElementList
|
||||||
|
功能:追加元素
|
||||||
|
|
||||||
|
用法:
|
||||||
|
```javascript
|
||||||
|
instance.command.executeAppendElementList(elementList: IElement[], options?: IAppendElementListOption)
|
||||||
|
```
|
||||||
|
|
||||||
## executeSetValue
|
## executeSetValue
|
||||||
功能:设置编辑器数据
|
功能:设置编辑器数据
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const {
|
|||||||
header?: IHeader;
|
header?: IHeader;
|
||||||
watermark?: IWatermark;
|
watermark?: IWatermark;
|
||||||
data: IEditorData;
|
data: IEditorData;
|
||||||
} = instance.command.getValue()
|
} = instance.command.getValue(options?: IGetValueOption)
|
||||||
```
|
```
|
||||||
|
|
||||||
## getImage
|
## getImage
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ export class Command {
|
|||||||
public executePaperDirection: CommandAdapt['paperDirection']
|
public executePaperDirection: CommandAdapt['paperDirection']
|
||||||
public executeSetPaperMargin: CommandAdapt['setPaperMargin']
|
public executeSetPaperMargin: CommandAdapt['setPaperMargin']
|
||||||
public executeInsertElementList: CommandAdapt['insertElementList']
|
public executeInsertElementList: CommandAdapt['insertElementList']
|
||||||
|
public executeAppendElementList: CommandAdapt['appendElementList']
|
||||||
public executeSetValue: CommandAdapt['setValue']
|
public executeSetValue: CommandAdapt['setValue']
|
||||||
public executeRemoveControl: CommandAdapt['removeControl']
|
public executeRemoveControl: CommandAdapt['removeControl']
|
||||||
public executeSetLocale: CommandAdapt['setLocale']
|
public executeSetLocale: CommandAdapt['setLocale']
|
||||||
@@ -156,6 +157,7 @@ export class Command {
|
|||||||
this.executeSetPaperMargin = adapt.setPaperMargin.bind(adapt)
|
this.executeSetPaperMargin = adapt.setPaperMargin.bind(adapt)
|
||||||
// 通用
|
// 通用
|
||||||
this.executeInsertElementList = adapt.insertElementList.bind(adapt)
|
this.executeInsertElementList = adapt.insertElementList.bind(adapt)
|
||||||
|
this.executeAppendElementList = adapt.appendElementList.bind(adapt)
|
||||||
this.executeSetValue = adapt.setValue.bind(adapt)
|
this.executeSetValue = adapt.setValue.bind(adapt)
|
||||||
this.executeRemoveControl = adapt.removeControl.bind(adapt)
|
this.executeRemoveControl = adapt.removeControl.bind(adapt)
|
||||||
this.executeSetLocale = adapt.setLocale.bind(adapt)
|
this.executeSetLocale = adapt.setLocale.bind(adapt)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { TableBorder } from '../../dataset/enum/table/Table'
|
|||||||
import { TitleLevel } from '../../dataset/enum/Title'
|
import { TitleLevel } from '../../dataset/enum/Title'
|
||||||
import { VerticalAlign } from '../../dataset/enum/VerticalAlign'
|
import { VerticalAlign } from '../../dataset/enum/VerticalAlign'
|
||||||
import { ICatalog } from '../../interface/Catalog'
|
import { ICatalog } from '../../interface/Catalog'
|
||||||
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
|
import { IAppendElementListOption, IDrawImagePayload, IGetValueOption, IPainterOptions } from '../../interface/Draw'
|
||||||
import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor'
|
import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||||
import { IElement, IElementStyle } from '../../interface/Element'
|
import { IElement, IElementStyle } from '../../interface/Element'
|
||||||
import { IMargin } from '../../interface/Margin'
|
import { IMargin } from '../../interface/Margin'
|
||||||
@@ -1589,8 +1589,8 @@ export class CommandAdapt {
|
|||||||
return this.draw.getDataURL()
|
return this.draw.getDataURL()
|
||||||
}
|
}
|
||||||
|
|
||||||
public getValue(): IEditorResult {
|
public getValue(options?: IGetValueOption): IEditorResult {
|
||||||
return this.draw.getValue()
|
return this.draw.getValue(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getWordCount(): Promise<number> {
|
public getWordCount(): Promise<number> {
|
||||||
@@ -1655,6 +1655,13 @@ export class CommandAdapt {
|
|||||||
this.draw.insertElementList(payload)
|
this.draw.insertElementList(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public appendElementList(elementList: IElement[], options?: IAppendElementListOption) {
|
||||||
|
if (!elementList.length) return
|
||||||
|
const isReadonly = this.draw.isReadonly()
|
||||||
|
if (isReadonly) return
|
||||||
|
this.draw.appendElementList(elementList, options)
|
||||||
|
}
|
||||||
|
|
||||||
public setValue(payload: Partial<IEditorData>) {
|
public setValue(payload: Partial<IEditorData>) {
|
||||||
this.draw.setValue(payload)
|
this.draw.setValue(payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { version } from '../../../../package.json'
|
import { version } from '../../../../package.json'
|
||||||
import { ZERO } from '../../dataset/constant/Common'
|
import { ZERO } from '../../dataset/constant/Common'
|
||||||
import { RowFlex } from '../../dataset/enum/Row'
|
import { RowFlex } from '../../dataset/enum/Row'
|
||||||
import { IDrawOption, IDrawPagePayload, IDrawRowPayload, IPainterOptions } from '../../interface/Draw'
|
import { IAppendElementListOption, IDrawOption, IDrawPagePayload, IDrawRowPayload, IGetValueOption, IPainterOptions } from '../../interface/Draw'
|
||||||
import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor'
|
import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||||
import { IElement, IElementMetrics, IElementFillRect, IElementStyle } from '../../interface/Element'
|
import { IElement, IElementMetrics, IElementFillRect, IElementStyle } from '../../interface/Element'
|
||||||
import { IRow, IRowElement } from '../../interface/Row'
|
import { IRow, IRowElement } from '../../interface/Row'
|
||||||
@@ -474,6 +474,27 @@ export class Draw {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public appendElementList(elementList: IElement[], options: IAppendElementListOption = {}) {
|
||||||
|
if (!elementList.length) return
|
||||||
|
formatElementList(elementList, {
|
||||||
|
isHandleFirstElement: false,
|
||||||
|
editorOptions: this.options
|
||||||
|
})
|
||||||
|
let curIndex: number
|
||||||
|
const { isPrepend } = options
|
||||||
|
if (isPrepend) {
|
||||||
|
this.elementList.splice(1, 0, ...elementList)
|
||||||
|
curIndex = elementList.length
|
||||||
|
} else {
|
||||||
|
this.elementList.push(...elementList)
|
||||||
|
curIndex = this.elementList.length - 1
|
||||||
|
}
|
||||||
|
this.range.setRange(curIndex, curIndex)
|
||||||
|
this.render({
|
||||||
|
curIndex
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public spliceElementList(elementList: IElement[], start: number, deleteCount: number, ...items: IElement[]) {
|
public spliceElementList(elementList: IElement[], start: number, deleteCount: number, ...items: IElement[]) {
|
||||||
if (deleteCount > 0) {
|
if (deleteCount > 0) {
|
||||||
// 当最后元素与开始元素列表信息不一致时:清除当前列表信息
|
// 当最后元素与开始元素列表信息不一致时:清除当前列表信息
|
||||||
@@ -719,13 +740,18 @@ export class Draw {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public getValue(): IEditorResult {
|
public getValue(options: IGetValueOption = {}): IEditorResult {
|
||||||
// 配置
|
// 配置
|
||||||
const { width, height, margins, watermark } = this.options
|
const { width, height, margins, watermark } = this.options
|
||||||
// 数据
|
// 数据
|
||||||
|
const { pageNo } = options
|
||||||
|
let mainElementList = this.elementList
|
||||||
|
if (Number.isInteger(pageNo) && pageNo! >= 0 && pageNo! < this.pageRowList.length) {
|
||||||
|
mainElementList = this.pageRowList[pageNo!].flatMap(row => row.elementList)
|
||||||
|
}
|
||||||
const data: IEditorData = {
|
const data: IEditorData = {
|
||||||
header: zipElementList(this.headerElementList),
|
header: zipElementList(this.headerElementList),
|
||||||
main: zipElementList(this.elementList),
|
main: zipElementList(mainElementList),
|
||||||
footer: zipElementList(this.footerElementList)
|
footer: zipElementList(this.footerElementList)
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -36,3 +36,11 @@ export interface IDrawPagePayload {
|
|||||||
export interface IPainterOptions {
|
export interface IPainterOptions {
|
||||||
isDblclick: boolean;
|
isDblclick: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IGetValueOption {
|
||||||
|
pageNo?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IAppendElementListOption {
|
||||||
|
isPrepend?: boolean;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user