feat: add getTitleValue api #536
This commit is contained in:
@@ -231,3 +231,17 @@ Usage:
|
|||||||
```javascript
|
```javascript
|
||||||
const container = await instance.command.getContainer()
|
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
|
// title
|
||||||
level?: TitleLevel;
|
level?: TitleLevel;
|
||||||
|
title?: ITitle;
|
||||||
// list
|
// list
|
||||||
listType?: ListType;
|
listType?: ListType;
|
||||||
listStyle?: ListStyle;
|
listStyle?: ListStyle;
|
||||||
|
|||||||
@@ -209,7 +209,8 @@ const groupIds = await instance.command.getGroupIds()
|
|||||||
const {
|
const {
|
||||||
value: string | null
|
value: string | null
|
||||||
innerText: string | null
|
innerText: string | null
|
||||||
} = await instance.command.getControlValue(payload: IGetControlValueOption)
|
zone: EditorZone
|
||||||
|
}[] = await instance.command.getControlValue(payload: IGetControlValueOption)
|
||||||
```
|
```
|
||||||
|
|
||||||
## getControlList
|
## getControlList
|
||||||
@@ -231,3 +232,17 @@ const controlList = await instance.command.getControlList()
|
|||||||
```javascript
|
```javascript
|
||||||
const container = await instance.command.getContainer()
|
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;
|
level?: TitleLevel;
|
||||||
|
title?: ITitle;
|
||||||
// 列表
|
// 列表
|
||||||
listType?: ListType;
|
listType?: ListType;
|
||||||
listStyle?: ListStyle;
|
listStyle?: ListStyle;
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ export class Command {
|
|||||||
public getControlValue: CommandAdapt['getControlValue']
|
public getControlValue: CommandAdapt['getControlValue']
|
||||||
public getControlList: CommandAdapt['getControlList']
|
public getControlList: CommandAdapt['getControlList']
|
||||||
public getContainer: CommandAdapt['getContainer']
|
public getContainer: CommandAdapt['getContainer']
|
||||||
|
public getTitleValue: CommandAdapt['getTitleValue']
|
||||||
|
|
||||||
constructor(adapt: CommandAdapt) {
|
constructor(adapt: CommandAdapt) {
|
||||||
// 全局命令
|
// 全局命令
|
||||||
@@ -223,6 +224,7 @@ export class Command {
|
|||||||
this.getLocale = adapt.getLocale.bind(adapt)
|
this.getLocale = adapt.getLocale.bind(adapt)
|
||||||
this.getGroupIds = adapt.getGroupIds.bind(adapt)
|
this.getGroupIds = adapt.getGroupIds.bind(adapt)
|
||||||
this.getContainer = adapt.getContainer.bind(adapt)
|
this.getContainer = adapt.getContainer.bind(adapt)
|
||||||
|
this.getTitleValue = adapt.getTitleValue.bind(adapt)
|
||||||
// 控件
|
// 控件
|
||||||
this.executeSetControlValue = adapt.setControlValue.bind(adapt)
|
this.executeSetControlValue = adapt.setControlValue.bind(adapt)
|
||||||
this.executeSetControlExtension = adapt.setControlExtension.bind(adapt)
|
this.executeSetControlExtension = adapt.setControlExtension.bind(adapt)
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { NBSP, WRAP, ZERO } from '../../dataset/constant/Common'
|
import { NBSP, WRAP, ZERO } from '../../dataset/constant/Common'
|
||||||
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
|
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 { defaultWatermarkOption } from '../../dataset/constant/Watermark'
|
||||||
import { ImageDisplay } from '../../dataset/enum/Common'
|
import { ImageDisplay } from '../../dataset/enum/Common'
|
||||||
import { ControlComponent } from '../../dataset/enum/Control'
|
import { ControlComponent } from '../../dataset/enum/Control'
|
||||||
@@ -52,6 +55,10 @@ import { IColgroup } from '../../interface/table/Colgroup'
|
|||||||
import { ITd } from '../../interface/table/Td'
|
import { ITd } from '../../interface/table/Td'
|
||||||
import { ITr } from '../../interface/table/Tr'
|
import { ITr } from '../../interface/table/Tr'
|
||||||
import { ITextDecoration } from '../../interface/Text'
|
import { ITextDecoration } from '../../interface/Text'
|
||||||
|
import {
|
||||||
|
IGetTitleValueOption,
|
||||||
|
IGetTitleValueResult
|
||||||
|
} from '../../interface/Title'
|
||||||
import { IWatermark } from '../../interface/Watermark'
|
import { IWatermark } from '../../interface/Watermark'
|
||||||
import { deepClone, downloadFile, getUUID, isObjectEqual } from '../../utils'
|
import { deepClone, downloadFile, getUUID, isObjectEqual } from '../../utils'
|
||||||
import {
|
import {
|
||||||
@@ -2398,4 +2405,70 @@ export class CommandAdapt {
|
|||||||
public getContainer(): HTMLDivElement {
|
public getContainer(): HTMLDivElement {
|
||||||
return this.draw.getContainer()
|
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',
|
'dateFormat',
|
||||||
'block',
|
'block',
|
||||||
'level',
|
'level',
|
||||||
|
'title',
|
||||||
'listType',
|
'listType',
|
||||||
'listStyle',
|
'listStyle',
|
||||||
'listWrap',
|
'listWrap',
|
||||||
@@ -88,7 +89,11 @@ export const TABLE_CONTEXT_ATTR: Array<keyof IElement> = [
|
|||||||
'tableId'
|
'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> = [
|
export const LIST_CONTEXT_ATTR: Array<keyof IElement> = [
|
||||||
'listId',
|
'listId',
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { ICheckbox } from './Checkbox'
|
|||||||
import { IControl } from './Control'
|
import { IControl } from './Control'
|
||||||
import { IRadio } from './Radio'
|
import { IRadio } from './Radio'
|
||||||
import { ITextDecoration } from './Text'
|
import { ITextDecoration } from './Text'
|
||||||
|
import { ITitle } from './Title'
|
||||||
import { IColgroup } from './table/Colgroup'
|
import { IColgroup } from './table/Colgroup'
|
||||||
import { ITr } from './table/Tr'
|
import { ITr } from './table/Tr'
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ export interface ITitleElement {
|
|||||||
valueList?: IElement[]
|
valueList?: IElement[]
|
||||||
level?: TitleLevel
|
level?: TitleLevel
|
||||||
titleId?: string
|
titleId?: string
|
||||||
|
title?: ITitle
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IListElement {
|
export interface IListElement {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { EditorZone } from '../dataset/enum/Editor'
|
||||||
|
import { IElement } from './Element'
|
||||||
|
|
||||||
export interface ITitleSizeOption {
|
export interface ITitleSizeOption {
|
||||||
defaultFirstSize?: number
|
defaultFirstSize?: number
|
||||||
defaultSecondSize?: number
|
defaultSecondSize?: number
|
||||||
@@ -8,3 +11,17 @@ export interface ITitleSizeOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ITitleOption = 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
|
const titleOptions = editorOptions.title
|
||||||
for (let v = 0; v < valueList.length; v++) {
|
for (let v = 0; v < valueList.length; v++) {
|
||||||
const value = valueList[v]
|
const value = valueList[v]
|
||||||
|
value.title = el.title
|
||||||
if (el.level) {
|
if (el.level) {
|
||||||
value.titleId = titleId
|
value.titleId = titleId
|
||||||
value.level = el.level
|
value.level = el.level
|
||||||
@@ -523,6 +524,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
|
|||||||
const level = element.level
|
const level = element.level
|
||||||
const titleElement: IElement = {
|
const titleElement: IElement = {
|
||||||
type: ElementType.TITLE,
|
type: ElementType.TITLE,
|
||||||
|
title: element.title,
|
||||||
value: '',
|
value: '',
|
||||||
level
|
level
|
||||||
}
|
}
|
||||||
@@ -534,6 +536,7 @@ export function zipElementList(payload: IElement[]): IElement[] {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
delete titleE.level
|
delete titleE.level
|
||||||
|
delete titleE.title
|
||||||
valueList.push(titleE)
|
valueList.push(titleE)
|
||||||
e++
|
e++
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user