feat: add editor placeholder
This commit is contained in:
@@ -54,6 +54,7 @@ import { Zone } from '../zone/Zone'
|
|||||||
import { Footer } from './frame/Footer'
|
import { Footer } from './frame/Footer'
|
||||||
import { INLINE_ELEMENT_TYPE } from '../../dataset/constant/Element'
|
import { INLINE_ELEMENT_TYPE } from '../../dataset/constant/Element'
|
||||||
import { ListParticle } from './particle/ListParticle'
|
import { ListParticle } from './particle/ListParticle'
|
||||||
|
import { Placeholder } from './frame/Placeholder'
|
||||||
|
|
||||||
export class Draw {
|
export class Draw {
|
||||||
|
|
||||||
@@ -91,6 +92,7 @@ export class Draw {
|
|||||||
private tableTool: TableTool
|
private tableTool: TableTool
|
||||||
private pageNumber: PageNumber
|
private pageNumber: PageNumber
|
||||||
private waterMark: Watermark
|
private waterMark: Watermark
|
||||||
|
private placeholder: Placeholder
|
||||||
private header: Header
|
private header: Header
|
||||||
private footer: Footer
|
private footer: Footer
|
||||||
private hyperlinkParticle: HyperlinkParticle
|
private hyperlinkParticle: HyperlinkParticle
|
||||||
@@ -156,6 +158,7 @@ export class Draw {
|
|||||||
this.tableTool = new TableTool(this)
|
this.tableTool = new TableTool(this)
|
||||||
this.pageNumber = new PageNumber(this)
|
this.pageNumber = new PageNumber(this)
|
||||||
this.waterMark = new Watermark(this)
|
this.waterMark = new Watermark(this)
|
||||||
|
this.placeholder = new Placeholder(this)
|
||||||
this.header = new Header(this)
|
this.header = new Header(this)
|
||||||
this.footer = new Footer(this)
|
this.footer = new Footer(this)
|
||||||
this.hyperlinkParticle = new HyperlinkParticle(this)
|
this.hyperlinkParticle = new HyperlinkParticle(this)
|
||||||
@@ -1374,6 +1377,10 @@ export class Draw {
|
|||||||
if (pageMode !== PageMode.CONTINUITY && this.options.watermark.data) {
|
if (pageMode !== PageMode.CONTINUITY && this.options.watermark.data) {
|
||||||
this.waterMark.render(ctx)
|
this.waterMark.render(ctx)
|
||||||
}
|
}
|
||||||
|
// 绘制空白占位符
|
||||||
|
if (this.elementList.length <= 1) {
|
||||||
|
this.placeholder.render(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _lazyRender() {
|
private _lazyRender() {
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import { IEditorOption, IElement } from '../../..'
|
||||||
|
import { DeepRequired } from '../../../interface/Common'
|
||||||
|
import { IElementPosition } from '../../../interface/Element'
|
||||||
|
import { IRow } from '../../../interface/Row'
|
||||||
|
import { formatElementList } from '../../../utils/element'
|
||||||
|
import { Position } from '../../position/Position'
|
||||||
|
import { Draw } from '../Draw'
|
||||||
|
|
||||||
|
export class Placeholder {
|
||||||
|
|
||||||
|
private draw: Draw
|
||||||
|
private position: Position
|
||||||
|
private options: DeepRequired<IEditorOption>
|
||||||
|
|
||||||
|
private elementList: IElement[]
|
||||||
|
private rowList: IRow[]
|
||||||
|
private positionList: IElementPosition[]
|
||||||
|
|
||||||
|
constructor(draw: Draw) {
|
||||||
|
this.draw = draw
|
||||||
|
this.position = draw.getPosition()
|
||||||
|
this.options = <DeepRequired<IEditorOption>>draw.getOptions()
|
||||||
|
|
||||||
|
this.elementList = []
|
||||||
|
this.rowList = []
|
||||||
|
this.positionList = []
|
||||||
|
}
|
||||||
|
|
||||||
|
private _recovery() {
|
||||||
|
this.elementList = []
|
||||||
|
this.rowList = []
|
||||||
|
this.positionList = []
|
||||||
|
}
|
||||||
|
|
||||||
|
public _compute() {
|
||||||
|
this._computeRowList()
|
||||||
|
this._computePositionList()
|
||||||
|
}
|
||||||
|
|
||||||
|
private _computeRowList() {
|
||||||
|
const innerWidth = this.draw.getInnerWidth()
|
||||||
|
this.rowList = this.draw.computeRowList(innerWidth, this.elementList)
|
||||||
|
}
|
||||||
|
|
||||||
|
private _computePositionList() {
|
||||||
|
const headerExtraHeight = this.draw.getHeader().getExtraHeight()
|
||||||
|
const innerWidth = this.draw.getInnerWidth()
|
||||||
|
const margins = this.draw.getMargins()
|
||||||
|
const startX = margins[3]
|
||||||
|
const startY = margins[0] + headerExtraHeight
|
||||||
|
this.position.computePageRowPosition({
|
||||||
|
positionList: this.positionList,
|
||||||
|
rowList: this.rowList,
|
||||||
|
pageNo: 0,
|
||||||
|
startRowIndex: 0,
|
||||||
|
startIndex: 0,
|
||||||
|
startX,
|
||||||
|
startY,
|
||||||
|
innerWidth
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(ctx: CanvasRenderingContext2D) {
|
||||||
|
const { placeholder: { data, font, size, color, opacity } } = this.options
|
||||||
|
if (!data) return
|
||||||
|
this._recovery()
|
||||||
|
// 构建元素列表并格式化
|
||||||
|
this.elementList = [{
|
||||||
|
value: data,
|
||||||
|
font,
|
||||||
|
size,
|
||||||
|
color
|
||||||
|
}]
|
||||||
|
formatElementList(this.elementList, {
|
||||||
|
editorOptions: this.options
|
||||||
|
})
|
||||||
|
// 计算
|
||||||
|
this._compute()
|
||||||
|
const innerWidth = this.draw.getInnerWidth()
|
||||||
|
// 绘制
|
||||||
|
ctx.save()
|
||||||
|
ctx.globalAlpha = opacity
|
||||||
|
this.draw.drawRow(ctx, {
|
||||||
|
elementList: this.elementList,
|
||||||
|
positionList: this.positionList,
|
||||||
|
rowList: this.rowList,
|
||||||
|
pageNo: 0,
|
||||||
|
startIndex: 0,
|
||||||
|
innerWidth
|
||||||
|
})
|
||||||
|
ctx.restore()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { IPlaceholder } from '../../interface/Placeholder'
|
||||||
|
|
||||||
|
export const defaultPlaceholderOption: Readonly<Required<IPlaceholder>> = {
|
||||||
|
data: '',
|
||||||
|
color: '#DCDFE6',
|
||||||
|
opacity: 1,
|
||||||
|
size: 16,
|
||||||
|
font: 'Yahei'
|
||||||
|
}
|
||||||
+8
-1
@@ -43,6 +43,8 @@ import { defaultTitleOption } from './dataset/constant/Title'
|
|||||||
import { TitleLevel } from './dataset/enum/Title'
|
import { TitleLevel } from './dataset/enum/Title'
|
||||||
import { ListStyle, ListType } from './dataset/enum/List'
|
import { ListStyle, ListType } from './dataset/enum/List'
|
||||||
import { ICatalog, ICatalogItem } from './interface/Catalog'
|
import { ICatalog, ICatalogItem } from './interface/Catalog'
|
||||||
|
import { IPlaceholder } from './interface/Placeholder'
|
||||||
|
import { defaultPlaceholderOption } from './dataset/constant/Placeholder'
|
||||||
|
|
||||||
export default class Editor {
|
export default class Editor {
|
||||||
|
|
||||||
@@ -84,6 +86,10 @@ export default class Editor {
|
|||||||
...defaultTitleOption,
|
...defaultTitleOption,
|
||||||
...options.title
|
...options.title
|
||||||
}
|
}
|
||||||
|
const placeholderOptions: Required<IPlaceholder> = {
|
||||||
|
...defaultPlaceholderOption,
|
||||||
|
...options.placeholder
|
||||||
|
}
|
||||||
|
|
||||||
const editorOptions: DeepRequired<IEditorOption> = {
|
const editorOptions: DeepRequired<IEditorOption> = {
|
||||||
mode: EditorMode.EDIT,
|
mode: EditorMode.EDIT,
|
||||||
@@ -127,7 +133,8 @@ export default class Editor {
|
|||||||
control: controlOptions,
|
control: controlOptions,
|
||||||
checkbox: checkboxOptions,
|
checkbox: checkboxOptions,
|
||||||
cursor: cursorOptions,
|
cursor: cursorOptions,
|
||||||
title: titleOptions
|
title: titleOptions,
|
||||||
|
placeholder: placeholderOptions
|
||||||
}
|
}
|
||||||
// 数据处理
|
// 数据处理
|
||||||
let headerElementList: IElement[] = []
|
let headerElementList: IElement[] = []
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export interface IDrawRowPayload {
|
|||||||
pageNo: number;
|
pageNo: number;
|
||||||
startIndex: number;
|
startIndex: number;
|
||||||
innerWidth: number;
|
innerWidth: number;
|
||||||
zone: EditorZone;
|
zone?: EditorZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDrawPagePayload {
|
export interface IDrawPagePayload {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { IFooter } from './Footer'
|
|||||||
import { IHeader } from './Header'
|
import { IHeader } from './Header'
|
||||||
import { IMargin } from './Margin'
|
import { IMargin } from './Margin'
|
||||||
import { IPageNumber } from './PageNumber'
|
import { IPageNumber } from './PageNumber'
|
||||||
|
import { IPlaceholder } from './Placeholder'
|
||||||
import { ITitleOption } from './Title'
|
import { ITitleOption } from './Title'
|
||||||
import { IWatermark } from './Watermark'
|
import { IWatermark } from './Watermark'
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ export interface IEditorOption {
|
|||||||
checkbox?: ICheckboxOption;
|
checkbox?: ICheckboxOption;
|
||||||
cursor?: ICursorOption;
|
cursor?: ICursorOption;
|
||||||
title?: ITitleOption;
|
title?: ITitleOption;
|
||||||
|
placeholder?: IPlaceholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEditorResult {
|
export interface IEditorResult {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export interface IPlaceholder {
|
||||||
|
data: string;
|
||||||
|
color?: string;
|
||||||
|
opacity?: number;
|
||||||
|
size?: number;
|
||||||
|
font?: string;
|
||||||
|
}
|
||||||
@@ -331,5 +331,8 @@ export const options: IEditorOption = {
|
|||||||
},
|
},
|
||||||
pageNumber: {
|
pageNumber: {
|
||||||
format: '第{pageNo}页/共{pageCount}页'
|
format: '第{pageNo}页/共{pageCount}页'
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
data: '请输入正文'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user