feat: add SetHTML api

Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
This commit is contained in:
汥坳赵
2023-07-31 21:05:43 +08:00
committed by GitHub
co-authored by Hufe921
parent cf5dd35686
commit 52f7500ae3
4 changed files with 38 additions and 1 deletions
+8
View File
@@ -743,3 +743,11 @@ Usage:
```javascript ```javascript
instance.command.executeWordTool() instance.command.executeWordTool()
``` ```
## executeSetHTML
Feature: Set the editor HTML data
Usage:
```javascript
instance.command.executeSetHTML(payload: Partial<IEditorHTML)
```
+8
View File
@@ -743,3 +743,11 @@ instance.command.executeLocationCatalog(titleId: string)
```javascript ```javascript
instance.command.executeWordTool() instance.command.executeWordTool()
``` ```
## executeSetHTML
功能:设置编辑器HTML数据
用法:
```javascript
instance.command.executeSetHTML(payload: Partial<IEditorHTML)
```
+3
View File
@@ -74,6 +74,7 @@ export class Command {
public executeSetLocale: CommandAdapt['setLocale'] public executeSetLocale: CommandAdapt['setLocale']
public executeLocationCatalog: CommandAdapt['locationCatalog'] public executeLocationCatalog: CommandAdapt['locationCatalog']
public executeWordTool: CommandAdapt['wordTool'] public executeWordTool: CommandAdapt['wordTool']
public executeSetHTML: CommandAdapt['setHTML']
public getCatalog: CommandAdapt['getCatalog'] public getCatalog: CommandAdapt['getCatalog']
public getImage: CommandAdapt['getImage'] public getImage: CommandAdapt['getImage']
public getValue: CommandAdapt['getValue'] public getValue: CommandAdapt['getValue']
@@ -165,6 +166,8 @@ export class Command {
this.executeSetLocale = adapt.setLocale.bind(adapt) this.executeSetLocale = adapt.setLocale.bind(adapt)
this.executeLocationCatalog = adapt.locationCatalog.bind(adapt) this.executeLocationCatalog = adapt.locationCatalog.bind(adapt)
this.executeWordTool = adapt.wordTool.bind(adapt) this.executeWordTool = adapt.wordTool.bind(adapt)
this.executeSetHTML = adapt.setHTML.bind(adapt)
// 获取 // 获取
this.getImage = adapt.getImage.bind(adapt) this.getImage = adapt.getImage.bind(adapt)
this.getValue = adapt.getValue.bind(adapt) this.getValue = adapt.getValue.bind(adapt)
+19 -1
View File
@@ -43,7 +43,8 @@ import {
formatElementContext, formatElementContext,
formatElementList, formatElementList,
isTextLikeElement, isTextLikeElement,
pickElementAttr pickElementAttr,
getElementListByHTML
} from '../../utils/element' } from '../../utils/element'
import { printImageBase64 } from '../../utils/print' import { printImageBase64 } from '../../utils/print'
import { Control } from '../draw/control/Control' 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)
})
}
} }