refactor: header indicator #159
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
background: rgb(218 231 252);
|
background: rgb(218 231 252);
|
||||||
position: absolute;
|
position: absolute;
|
||||||
transform: translate(10px, 10px);
|
transform-origin: 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ce-header-indicator-border__top,
|
.ce-header-indicator-border__top,
|
||||||
|
|||||||
@@ -264,10 +264,6 @@ export class Draw {
|
|||||||
return bottom * scale
|
return bottom * scale
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHeaderTop(): number {
|
|
||||||
return this.options.headerTop * this.options.scale
|
|
||||||
}
|
|
||||||
|
|
||||||
public getMarginIndicatorSize(): number {
|
public getMarginIndicatorSize(): number {
|
||||||
return this.options.marginIndicatorSize * this.options.scale
|
return this.options.marginIndicatorSize * this.options.scale
|
||||||
}
|
}
|
||||||
@@ -1363,7 +1359,7 @@ export class Draw {
|
|||||||
this.tableTool.render()
|
this.tableTool.render()
|
||||||
}
|
}
|
||||||
// 页眉指示器重新渲染
|
// 页眉指示器重新渲染
|
||||||
if (isCompute && !this.isReadonly() && this.zone.isHeaderActive()) {
|
if (isCompute && this.zone.isHeaderActive()) {
|
||||||
this.zone.drawHeaderZoneIndicator()
|
this.zone.drawHeaderZoneIndicator()
|
||||||
}
|
}
|
||||||
// 页面尺寸改变
|
// 页面尺寸改变
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ function dblclick(host: CanvasEvent, evt: MouseEvent) {
|
|||||||
y: evt.offsetY
|
y: evt.offsetY
|
||||||
})
|
})
|
||||||
if (!~positionContext.index && positionContext.zone) {
|
if (!~positionContext.index && positionContext.zone) {
|
||||||
const isReadonly = draw.isReadonly()
|
|
||||||
if (isReadonly) return
|
|
||||||
draw.getZone().setZone(positionContext.zone)
|
draw.getZone().setZone(positionContext.zone)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,9 +260,12 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
|||||||
}
|
}
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
} else if (evt.key === KeyMap.ESC) {
|
} else if (evt.key === KeyMap.ESC) {
|
||||||
|
// 退出格式刷
|
||||||
host.clearPainterStyle()
|
host.clearPainterStyle()
|
||||||
if (draw.getZone().isHeaderActive()) {
|
// 退出页眉编辑
|
||||||
draw.getZone().setZone(EditorZone.MAIN)
|
const zoneManager = draw.getZone()
|
||||||
|
if (zoneManager.isHeaderActive()) {
|
||||||
|
zoneManager.setZone(EditorZone.MAIN)
|
||||||
}
|
}
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
} else if (evt.key === KeyMap.TAB) {
|
} else if (evt.key === KeyMap.TAB) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
"minute": "Minute",
|
"minute": "Minute",
|
||||||
"second": "Second"
|
"second": "Second"
|
||||||
},
|
},
|
||||||
"global": {
|
"frame": {
|
||||||
"header": "Header",
|
"header": "Header",
|
||||||
"footer": "Footer"
|
"footer": "Footer"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
"minute": "分",
|
"minute": "分",
|
||||||
"second": "秒"
|
"second": "秒"
|
||||||
},
|
},
|
||||||
"global": {
|
"frame": {
|
||||||
"header": "页眉",
|
"header": "页眉",
|
||||||
"footer": "页脚"
|
"footer": "页脚"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import { Draw } from '../draw/Draw'
|
|||||||
import { I18n } from '../i18n/I18n'
|
import { I18n } from '../i18n/I18n'
|
||||||
|
|
||||||
export class Zone {
|
export class Zone {
|
||||||
|
|
||||||
|
private readonly INDICATOR_TITLE_TRANSLATE = [20, 5]
|
||||||
|
|
||||||
private draw: Draw
|
private draw: Draw
|
||||||
private options: Required<IEditorOption>
|
private options: Required<IEditorOption>
|
||||||
private i18n: I18n
|
private i18n: I18n
|
||||||
@@ -54,54 +57,56 @@ export class Zone {
|
|||||||
public drawHeaderZoneIndicator() {
|
public drawHeaderZoneIndicator() {
|
||||||
this._clearHeaderZoneIndicator()
|
this._clearHeaderZoneIndicator()
|
||||||
const { scale } = this.options
|
const { scale } = this.options
|
||||||
|
const [offsetX, offsetY] = this.INDICATOR_TITLE_TRANSLATE
|
||||||
this.headerIndicatorContainer = document.createElement('div')
|
this.headerIndicatorContainer = document.createElement('div')
|
||||||
this.headerIndicatorContainer.classList.add(`${EDITOR_PREFIX}-header-indicator`)
|
this.headerIndicatorContainer.classList.add(`${EDITOR_PREFIX}-header-indicator`)
|
||||||
const pageList = this.draw.getPageList()
|
const pageList = this.draw.getPageList()
|
||||||
|
const margins = this.draw.getMargins()
|
||||||
|
const innerWidth = this.draw.getInnerWidth()
|
||||||
const pageHeight = this.draw.getHeight()
|
const pageHeight = this.draw.getHeight()
|
||||||
const pageGap = this.draw.getPageGap()
|
const pageGap = this.draw.getPageGap()
|
||||||
const preY = pageHeight + pageGap
|
const preY = pageHeight + pageGap
|
||||||
const headerHeight = this.draw.getHeader().getHeight()
|
const header = this.draw.getHeader()
|
||||||
const headerTop = (this.options.header?.top ?? 0) * scale
|
const headerHeight = header.getHeight()
|
||||||
const margins = this.draw.getMargins()
|
const headerTop = header.getHeaderTop()
|
||||||
|
|
||||||
for (let p = 0; p < pageList.length; p++) {
|
for (let p = 0; p < pageList.length; p++) {
|
||||||
const indicator = document.createElement('div')
|
const startY = preY * p + headerTop
|
||||||
indicator.innerText = this.i18n.t('global.header')
|
const indicatorTitle = document.createElement('div')
|
||||||
document.body.appendChild(indicator)
|
// 标题
|
||||||
const indicatorStyle = getComputedStyle(indicator)
|
indicatorTitle.innerText = this.i18n.t('frame.header')
|
||||||
indicator.style.top = `${preY * p + headerHeight + parseFloat(indicatorStyle.height) * scale}px`
|
indicatorTitle.style.top = `${startY + headerHeight}px`
|
||||||
this.headerIndicatorContainer.append(indicator)
|
indicatorTitle.style.transform = `translate(${offsetX * scale}px, ${offsetY * scale}px) scale(${scale})`
|
||||||
|
this.headerIndicatorContainer.append(indicatorTitle)
|
||||||
// 绘制上,左,下,右边线
|
|
||||||
|
|
||||||
// 上边线
|
// 上边线
|
||||||
const lineTop = document.createElement('span')
|
const lineTop = document.createElement('span')
|
||||||
lineTop.classList.add(`${EDITOR_PREFIX}-header-indicator-border__top`)
|
lineTop.classList.add(`${EDITOR_PREFIX}-header-indicator-border__top`)
|
||||||
lineTop.style.top = `${(preY * p + headerTop)}px`
|
lineTop.style.top = `${startY}px`
|
||||||
lineTop.style.width = this.draw.getInnerWidth() + 'px'
|
lineTop.style.width = `${innerWidth}px`
|
||||||
lineTop.style.marginLeft = margins[3] + 'px'
|
lineTop.style.marginLeft = `${margins[3]}px`
|
||||||
this.headerIndicatorContainer.append(lineTop)
|
this.headerIndicatorContainer.append(lineTop)
|
||||||
|
|
||||||
// 左边线
|
// 左边线
|
||||||
const lineLeft = document.createElement('span')
|
const lineLeft = document.createElement('span')
|
||||||
lineLeft.classList.add(`${EDITOR_PREFIX}-header-indicator-border__left`)
|
lineLeft.classList.add(`${EDITOR_PREFIX}-header-indicator-border__left`)
|
||||||
lineLeft.style.top = `${(preY * p + headerTop)}px`
|
lineLeft.style.top = `${startY}px`
|
||||||
lineLeft.style.height = `${headerHeight}px`
|
lineLeft.style.height = `${headerHeight}px`
|
||||||
lineLeft.style.left = margins[3] + 'px'
|
lineLeft.style.left = `${margins[3]}px`
|
||||||
this.headerIndicatorContainer.append(lineLeft)
|
this.headerIndicatorContainer.append(lineLeft)
|
||||||
|
|
||||||
// 下边线
|
// 下边线
|
||||||
const lineBottom = document.createElement('span')
|
const lineBottom = document.createElement('span')
|
||||||
lineBottom.classList.add(`${EDITOR_PREFIX}-header-indicator-border__bottom`)
|
lineBottom.classList.add(`${EDITOR_PREFIX}-header-indicator-border__bottom`)
|
||||||
lineBottom.style.top = `${(preY * p + headerHeight + headerTop)}px`
|
lineBottom.style.top = `${startY + headerHeight}px`
|
||||||
this.headerIndicatorContainer.append(lineBottom)
|
this.headerIndicatorContainer.append(lineBottom)
|
||||||
|
|
||||||
// 右边线
|
// 右边线
|
||||||
const lineRight = document.createElement('span')
|
const lineRight = document.createElement('span')
|
||||||
lineRight.classList.add(`${EDITOR_PREFIX}-header-indicator-border__right`)
|
lineRight.classList.add(`${EDITOR_PREFIX}-header-indicator-border__right`)
|
||||||
lineRight.style.top = `${(preY * p + headerTop)}px`
|
lineRight.style.top = `${startY}px`
|
||||||
lineRight.style.height = `${headerHeight}px`
|
lineRight.style.height = `${headerHeight}px`
|
||||||
lineRight.style.left = `${(margins[3] + this.draw.getInnerWidth())}px`
|
lineRight.style.left = `${margins[3] + innerWidth}px`
|
||||||
this.headerIndicatorContainer.append(lineRight)
|
this.headerIndicatorContainer.append(lineRight)
|
||||||
}
|
}
|
||||||
this.container.append(this.headerIndicatorContainer)
|
this.container.append(this.headerIndicatorContainer)
|
||||||
@@ -109,5 +114,6 @@ export class Zone {
|
|||||||
|
|
||||||
private _clearHeaderZoneIndicator() {
|
private _clearHeaderZoneIndicator() {
|
||||||
this.headerIndicatorContainer?.remove()
|
this.headerIndicatorContainer?.remove()
|
||||||
|
this.headerIndicatorContainer = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,6 @@ export default class Editor {
|
|||||||
tdPadding: 5,
|
tdPadding: 5,
|
||||||
defaultTdHeight: 40,
|
defaultTdHeight: 40,
|
||||||
defaultHyperlinkColor: '#0000FF',
|
defaultHyperlinkColor: '#0000FF',
|
||||||
headerTop: 50,
|
|
||||||
paperDirection: PaperDirection.VERTICAL,
|
paperDirection: PaperDirection.VERTICAL,
|
||||||
inactiveAlpha: 0.6,
|
inactiveAlpha: 0.6,
|
||||||
...options,
|
...options,
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export interface IEditorOption {
|
|||||||
tdPadding?: number;
|
tdPadding?: number;
|
||||||
defaultTdHeight?: number;
|
defaultTdHeight?: number;
|
||||||
defaultHyperlinkColor?: string;
|
defaultHyperlinkColor?: string;
|
||||||
headerTop?: number;
|
|
||||||
paperDirection?: PaperDirection;
|
paperDirection?: PaperDirection;
|
||||||
inactiveAlpha?: number;
|
inactiveAlpha?: number;
|
||||||
header?: IHeader;
|
header?: IHeader;
|
||||||
|
|||||||
Reference in New Issue
Block a user