feat: add SetHTML api

Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
pr675
汥坳赵 3 years ago committed by GitHub
parent cf5dd35686
commit 52f7500ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -743,3 +743,11 @@ Usage:
```javascript
instance.command.executeWordTool()
```
## executeSetHTML
Feature: Set the editor HTML data
Usage:
```javascript
instance.command.executeSetHTML(payload: Partial<IEditorHTML)
```

@ -743,3 +743,11 @@ instance.command.executeLocationCatalog(titleId: string)
```javascript
instance.command.executeWordTool()
```
## executeSetHTML
功能设置编辑器HTML数据
用法:
```javascript
instance.command.executeSetHTML(payload: Partial<IEditorHTML)
```

@ -74,6 +74,7 @@ export class Command {
public executeSetLocale: CommandAdapt['setLocale']
public executeLocationCatalog: CommandAdapt['locationCatalog']
public executeWordTool: CommandAdapt['wordTool']
public executeSetHTML: CommandAdapt['setHTML']
public getCatalog: CommandAdapt['getCatalog']
public getImage: CommandAdapt['getImage']
public getValue: CommandAdapt['getValue']
@ -165,6 +166,8 @@ export class Command {
this.executeSetLocale = adapt.setLocale.bind(adapt)
this.executeLocationCatalog = adapt.locationCatalog.bind(adapt)
this.executeWordTool = adapt.wordTool.bind(adapt)
this.executeSetHTML = adapt.setHTML.bind(adapt)
// 获取
this.getImage = adapt.getImage.bind(adapt)
this.getValue = adapt.getValue.bind(adapt)

@ -43,7 +43,8 @@ import {
formatElementContext,
formatElementList,
isTextLikeElement,
pickElementAttr
pickElementAttr,
getElementListByHTML
} from '../../utils/element'
import { printImageBase64 } from '../../utils/print'
import { Control } from '../draw/control/Control'
@ -1869,4 +1870,21 @@ export class CommandAdapt {
})
}
}
public setHTML(payload: Partial<IEditorHTML>) {
const { header, main, footer } = payload
const innerWidth = this.draw.getOriginalInnerWidth()
// 不设置值时数据为undefined避免覆盖当前数据
const getElementList = (htmlText?: string) =>
htmlText !== undefined
? getElementListByHTML(htmlText, {
innerWidth
})
: undefined
this.setValue({
header: getElementList(header),
main: getElementList(main),
footer: getElementList(footer)
})
}
}

Loading…
Cancel
Save