feat: add title element
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IElement, ImageDisplay, INavigateInfo, TableBorder, VerticalAlign } from '../..'
|
||||
import { IElement, ImageDisplay, INavigateInfo, TableBorder, TitleLevel, VerticalAlign } from '../..'
|
||||
import { EditorMode, PageMode, PaperDirection } from '../../dataset/enum/Editor'
|
||||
import { RowFlex } from '../../dataset/enum/Row'
|
||||
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
|
||||
@@ -33,6 +33,7 @@ export class Command {
|
||||
private static subscript: CommandAdapt['subscript']
|
||||
private static color: CommandAdapt['color']
|
||||
private static highlight: CommandAdapt['highlight']
|
||||
private static title: CommandAdapt['title']
|
||||
private static left: CommandAdapt['rowFlex']
|
||||
private static center: CommandAdapt['rowFlex']
|
||||
private static right: CommandAdapt['rowFlex']
|
||||
@@ -109,6 +110,7 @@ export class Command {
|
||||
Command.subscript = adapt.subscript.bind(adapt)
|
||||
Command.color = adapt.color.bind(adapt)
|
||||
Command.highlight = adapt.highlight.bind(adapt)
|
||||
Command.title = adapt.title.bind(adapt)
|
||||
Command.left = adapt.rowFlex.bind(adapt)
|
||||
Command.center = adapt.rowFlex.bind(adapt)
|
||||
Command.right = adapt.rowFlex.bind(adapt)
|
||||
@@ -260,6 +262,11 @@ export class Command {
|
||||
return Command.highlight(payload)
|
||||
}
|
||||
|
||||
// 标题、对齐方式
|
||||
public executeTitle(payload: TitleLevel | null) {
|
||||
return Command.title(payload)
|
||||
}
|
||||
|
||||
public executeLeft() {
|
||||
return Command.left(RowFlex.LEFT)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { WRAP, ZERO } from '../../dataset/constant/Common'
|
||||
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
|
||||
import { titleSizeMapping } from '../../dataset/constant/Title'
|
||||
import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
|
||||
import { ControlComponent, ImageDisplay } from '../../dataset/enum/Control'
|
||||
import { EditorContext, EditorMode, PageMode, PaperDirection } from '../../dataset/enum/Editor'
|
||||
@@ -7,6 +8,7 @@ import { ElementType } from '../../dataset/enum/Element'
|
||||
import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
|
||||
import { RowFlex } from '../../dataset/enum/Row'
|
||||
import { TableBorder } from '../../dataset/enum/table/Table'
|
||||
import { TitleLevel } from '../../dataset/enum/Title'
|
||||
import { VerticalAlign } from '../../dataset/enum/VerticalAlign'
|
||||
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
|
||||
import { IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||
@@ -379,6 +381,63 @@ export class CommandAdapt {
|
||||
})
|
||||
}
|
||||
|
||||
public title(payload: TitleLevel | null) {
|
||||
const isReadonly = this.draw.isReadonly()
|
||||
if (isReadonly) return
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
if (!~startIndex && !~endIndex) return
|
||||
// 需要改变的元素列表
|
||||
let changeElementList: IElement[] = []
|
||||
const elementList = this.draw.getElementList()
|
||||
if (startIndex === endIndex) {
|
||||
// 选区行信息
|
||||
const rangeRow = this.range.getRangeRow()
|
||||
if (!rangeRow) return
|
||||
const positionList = this.position.getPositionList()
|
||||
for (let p = 0; p < positionList.length; p++) {
|
||||
const position = positionList[p]
|
||||
const rowSet = rangeRow.get(position.pageNo)
|
||||
if (!rowSet) continue
|
||||
if (rowSet.has(position.rowNo)) {
|
||||
changeElementList.push(elementList[p])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
changeElementList = elementList.slice(startIndex + 1, endIndex + 1)
|
||||
}
|
||||
// 检验数据合法性
|
||||
const isExistNotTextElement = !!changeElementList.find(el =>
|
||||
el.type &&
|
||||
el.type !== ElementType.TEXT &&
|
||||
el.type !== ElementType.TITLE
|
||||
)
|
||||
if (isExistNotTextElement) return
|
||||
// 设置值
|
||||
const titleId = getUUID()
|
||||
const titleOptions = this.draw.getOptions().title
|
||||
changeElementList.forEach(el => {
|
||||
if (payload) {
|
||||
el.type = ElementType.TITLE
|
||||
el.level = payload
|
||||
el.titleId = titleId
|
||||
el.size = titleOptions[titleSizeMapping[payload]]
|
||||
el.bold = true
|
||||
} else {
|
||||
if (el.type === ElementType.TITLE) {
|
||||
delete el.type
|
||||
delete el.titleId
|
||||
delete el.level
|
||||
delete el.size
|
||||
delete el.bold
|
||||
}
|
||||
}
|
||||
})
|
||||
// 光标定位
|
||||
const isSetCursor = startIndex === endIndex
|
||||
const curIndex = isSetCursor ? endIndex : startIndex
|
||||
this.draw.render({ curIndex, isSetCursor })
|
||||
}
|
||||
|
||||
public rowFlex(payload: RowFlex) {
|
||||
const isReadonly = this.draw.isReadonly()
|
||||
if (isReadonly) return
|
||||
|
||||
@@ -27,7 +27,7 @@ export function input(data: string, host: CanvasEvent) {
|
||||
cursor.clearAgentDomValue()
|
||||
}
|
||||
const activeControl = control.getActiveControl()
|
||||
const { TEXT, HYPERLINK, SUBSCRIPT, SUPERSCRIPT, DATE } = ElementType
|
||||
const { TEXT, HYPERLINK, SUBSCRIPT, SUPERSCRIPT, DATE, TITLE } = ElementType
|
||||
const text = data.replaceAll(`\n`, ZERO)
|
||||
const rangeManager = draw.getRange()
|
||||
const { startIndex, endIndex } = rangeManager.getRange()
|
||||
@@ -55,6 +55,7 @@ export function input(data: string, host: CanvasEvent) {
|
||||
|| (!copyElement.type && copyElement.value !== ZERO)
|
||||
|| (copyElement.type === HYPERLINK && nextElement?.type === HYPERLINK)
|
||||
|| (copyElement.type === DATE && nextElement?.type === DATE)
|
||||
|| copyElement.type === TITLE
|
||||
|| (copyElement.type === SUBSCRIPT && nextElement?.type === SUBSCRIPT)
|
||||
|| (copyElement.type === SUPERSCRIPT && nextElement?.type === SUPERSCRIPT)
|
||||
) {
|
||||
|
||||
@@ -152,6 +152,7 @@ export class RangeManager {
|
||||
const rowFlex = curElement.rowFlex || null
|
||||
const rowMargin = curElement.rowMargin || this.options.defaultRowMargin
|
||||
const dashArray = curElement.dashArray || []
|
||||
const level = curElement.level || null
|
||||
// 菜单
|
||||
const painter = !!this.draw.getPainterStyle()
|
||||
const undo = this.historyManager.isCanUndo()
|
||||
@@ -171,7 +172,8 @@ export class RangeManager {
|
||||
highlight,
|
||||
rowFlex,
|
||||
rowMargin,
|
||||
dashArray
|
||||
dashArray,
|
||||
level
|
||||
})
|
||||
}
|
||||
|
||||
@@ -198,7 +200,8 @@ export class RangeManager {
|
||||
highlight: null,
|
||||
rowFlex: null,
|
||||
rowMargin,
|
||||
dashArray: []
|
||||
dashArray: [],
|
||||
level: null
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user