feat: add getTitleValue api #536

pr675
Hufe921 2 years ago
parent 0ae67ec602
commit 15f52c5e43

@ -231,3 +231,17 @@ Usage:
```javascript
const container = await instance.command.getContainer()
```
## getTitleValue
Feature: Get title value
Usage:
```javascript
const {
value: string | null
elementList: IElement[]
zone: EditorZone
}[] = await instance.command.getTitleValue(payload: IGetTitleValueOption)
```

@ -164,6 +164,7 @@ interface IElement {
};
// title
level?: TitleLevel;
title?: ITitle;
// list
listType?: ListType;
listStyle?: ListStyle;

@ -209,7 +209,8 @@ const groupIds = await instance.command.getGroupIds()
const {
value: string | null
innerText: string | null
} = await instance.command.getControlValue(payload: IGetControlValueOption)
zone: EditorZone
}[] = await instance.command.getControlValue(payload: IGetControlValueOption)
```
## getControlList
@ -231,3 +232,17 @@ const controlList = await instance.command.getControlList()
```javascript
const container = await instance.command.getContainer()
```
## getTitleValue
功能:获取标题值
用法:
```javascript
const {
value: string | null
elementList: IElement[]
zone: EditorZone
}[] = await instance.command.getTitleValue(payload: IGetTitleValueOption)
```

@ -164,6 +164,7 @@ interface IElement {
};
// 标题
level?: TitleLevel;
title?: ITitle;
// 列表
listType?: ListType;
listStyle?: ListStyle;

@ -110,6 +110,7 @@ export class Command {
public getControlValue: CommandAdapt['getControlValue']
public getControlList: CommandAdapt['getControlList']
public getContainer: CommandAdapt['getContainer']
public getTitleValue: CommandAdapt['getTitleValue']
constructor(adapt: CommandAdapt) {
// 全局命令
@ -223,6 +224,7 @@ export class Command {
this.getLocale = adapt.getLocale.bind(adapt)
this.getGroupIds = adapt.getGroupIds.bind(adapt)
this.getContainer = adapt.getContainer.bind(adapt)
this.getTitleValue = adapt.getTitleValue.bind(adapt)
// 控件
this.executeSetControlValue = adapt.setControlValue.bind(adapt)
this.executeSetControlExtension = adapt.setControlExtension.bind(adapt)

@ -1,6 +1,9 @@
import { NBSP, WRAP, ZERO } from '../../dataset/constant/Common'
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
import { titleSizeMapping } from '../../dataset/constant/Title'
import {
titleOrderNumberMapping,
titleSizeMapping
} from '../../dataset/constant/Title'
import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
import { ImageDisplay } from '../../dataset/enum/Common'
import { ControlComponent } from '../../dataset/enum/Control'
@ -52,6 +55,10 @@ import { IColgroup } from '../../interface/table/Colgroup'
import { ITd } from '../../interface/table/Td'
import { ITr } from '../../interface/table/Tr'
import { ITextDecoration } from '../../interface/Text'
import {
IGetTitleValueOption,
IGetTitleValueResult
} from '../../interface/Title'
import { IWatermark } from '../../interface/Watermark'
import { deepClone, downloadFile, getUUID, isObjectEqual } from '../../utils'
import {
@ -2398,4 +2405,70 @@ export class CommandAdapt {
public getContainer(): HTMLDivElement {
return this.draw.getContainer()
}
public getTitleValue(
payload: IGetTitleValueOption
): IGetTitleValueResult | null {
const { conceptId } = payload
const result: IGetTitleValueResult = []
const getValue = (elementList: IElement[], zone: EditorZone) => {
let i = 0
while (i < elementList.length) {
const element = elementList[i]
i++
if (element.type === ElementType.TABLE) {
const trList = element.trList!
for (let r = 0; r < trList.length; r++) {
const tr = trList[r]
for (let d = 0; d < tr.tdList.length; d++) {
const td = tr.tdList[d]
getValue(td.value, zone)
}
}
}
if (element?.title?.conceptId !== conceptId) continue
// 先查找到标题,后循环至同级或上级标题处停止
const valueList: IElement[] = []
let j = i
while (j < elementList.length) {
const nextElement = elementList[j]
j++
if (element.titleId === nextElement.titleId) continue
if (
nextElement.level &&
titleOrderNumberMapping[nextElement.level] <=
titleOrderNumberMapping[element.level!]
) {
break
}
valueList.push(nextElement)
}
result.push({
...element.title!,
value: getTextFromElementList(valueList),
elementList: zipElementList(valueList),
zone
})
i = j
}
}
const data = [
{
zone: EditorZone.HEADER,
elementList: this.draw.getHeaderElementList()
},
{
zone: EditorZone.MAIN,
elementList: this.draw.getOriginalMainElementList()
},
{
zone: EditorZone.FOOTER,
elementList: this.draw.getFooterElementList()
}
]
for (const { zone, elementList } of data) {
getValue(elementList, zone)
}
return result
}
}

@ -64,6 +64,7 @@ export const EDITOR_ELEMENT_ZIP_ATTR: Array<keyof IElement> = [
'dateFormat',
'block',
'level',
'title',
'listType',
'listStyle',
'listWrap',
@ -88,7 +89,11 @@ export const TABLE_CONTEXT_ATTR: Array<keyof IElement> = [
'tableId'
]
export const TITLE_CONTEXT_ATTR: Array<keyof IElement> = ['level', 'titleId']
export const TITLE_CONTEXT_ATTR: Array<keyof IElement> = [
'level',
'titleId',
'title'
]
export const LIST_CONTEXT_ATTR: Array<keyof IElement> = [
'listId',

@ -10,6 +10,7 @@ import { ICheckbox } from './Checkbox'
import { IControl } from './Control'
import { IRadio } from './Radio'
import { ITextDecoration } from './Text'
import { ITitle } from './Title'
import { IColgroup } from './table/Colgroup'
import { ITr } from './table/Tr'
@ -45,6 +46,7 @@ export interface ITitleElement {
valueList?: IElement[]
level?: TitleLevel
titleId?: string
title?: ITitle
}
export interface IListElement {

@ -1,3 +1,6 @@
import { EditorZone } from '../dataset/enum/Editor'
import { IElement } from './Element'
export interface ITitleSizeOption {
defaultFirstSize?: number
defaultSecondSize?: number
@ -8,3 +11,17 @@ export interface ITitleSizeOption {
}
export type ITitleOption = ITitleSizeOption & {}
export interface ITitle {
conceptId?: string
}
export interface IGetTitleValueOption {
conceptId: string
}
export type IGetTitleValueResult = (ITitle & {
value: string | null
elementList: IElement[]
zone: EditorZone
})[]

@ -103,6 +103,7 @@ export function formatElementList(
const titleOptions = editorOptions.title
for (let v = 0; v < valueList.length; v++) {
const value = valueList[v]
value.title = el.title
if (el.level) {
value.titleId = titleId
value.level = el.level
@ -523,6 +524,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
const level = element.level
const titleElement: IElement = {
type: ElementType.TITLE,
title: element.title,
value: '',
level
}
@ -534,6 +536,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
break
}
delete titleE.level
delete titleE.title
valueList.push(titleE)
e++
}

Loading…
Cancel
Save