-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,5 +96,9 @@ interface ILang { | |
pageBreak: { | ||
displayName: string | ||
} | ||
zone: { | ||
headerTip: string | ||
footerTip: string | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,5 +96,9 @@ interface ILang { | |
pageBreak: { | ||
displayName: string | ||
} | ||
zone: { | ||
headerTip: string | ||
footerTip: string | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,5 +76,9 @@ | |
}, | ||
"pageBreak": { | ||
"displayName": "分页符" | ||
}, | ||
"zone": { | ||
"headerTip": "双击编辑页眉", | ||
"footerTip": "双击编辑页脚" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { EDITOR_PREFIX } from '../../dataset/constant/Editor' | ||
import { EditorZone } from '../../dataset/enum/Editor' | ||
import { throttle } from '../../utils' | ||
import { Draw } from '../draw/Draw' | ||
import { I18n } from '../i18n/I18n' | ||
import { Position } from '../position/Position' | ||
|
||
export class ZoneTip { | ||
private position: Position | ||
private i18n: I18n | ||
private container: HTMLDivElement | ||
private pageContainer: HTMLDivElement | ||
|
||
private isDisableMouseMove: boolean | ||
private tipContainer: HTMLDivElement | ||
private tipContent: HTMLSpanElement | ||
private currentMoveZone: EditorZone | undefined | ||
|
||
constructor(draw: Draw) { | ||
this.position = draw.getPosition() | ||
this.i18n = draw.getI18n() | ||
this.container = draw.getContainer() | ||
this.pageContainer = draw.getPageContainer() | ||
|
||
const { tipContainer, tipContent } = this._drawZoneTip() | ||
this.tipContainer = tipContainer | ||
this.tipContent = tipContent | ||
this.isDisableMouseMove = true | ||
this.currentMoveZone = EditorZone.MAIN | ||
|
||
this._watchMouseMoveZoneChange() | ||
} | ||
|
||
private _watchMouseMoveZoneChange() { | ||
this.pageContainer.addEventListener( | ||
'mousemove', | ||
throttle((evt: MouseEvent) => { | ||
if (this.isDisableMouseMove) return | ||
const pageNo = Number((<HTMLCanvasElement>evt.target).dataset.index) | ||
if (Number.isNaN(pageNo)) { | ||
this._updateZoneTip(false) | ||
} else { | ||
const positionInfo = this.position.getPositionByXY({ | ||
x: evt.offsetX, | ||
y: evt.offsetY, | ||
pageNo | ||
}) | ||
this.currentMoveZone = positionInfo.zone | ||
this._updateZoneTip( | ||
positionInfo.zone === EditorZone.HEADER || | ||
positionInfo.zone === EditorZone.FOOTER, | ||
evt.x, | ||
evt.y | ||
) | ||
} | ||
}, 250) | ||
) | ||
// mouseenter后mousemove有效,避免因节流导致的mouseleave后继续执行逻辑 | ||
this.pageContainer.addEventListener('mouseenter', () => { | ||
this.isDisableMouseMove = false | ||
}) | ||
this.pageContainer.addEventListener('mouseleave', () => { | ||
this.isDisableMouseMove = true | ||
this._updateZoneTip(false) | ||
}) | ||
} | ||
|
||
private _drawZoneTip() { | ||
const tipContainer = document.createElement('div') | ||
tipContainer.classList.add(`${EDITOR_PREFIX}-zone-tip`) | ||
const tipContent = document.createElement('span') | ||
tipContainer.append(tipContent) | ||
this.container.append(tipContainer) | ||
return { | ||
tipContainer, | ||
tipContent | ||
} | ||
} | ||
|
||
private _updateZoneTip(visible: boolean, left?: number, top?: number) { | ||
if (visible) { | ||
this.tipContainer.classList.add('show') | ||
this.tipContainer.style.left = `${left}px` | ||
this.tipContainer.style.top = `${top}px` | ||
this.tipContent.innerText = this.i18n.t( | ||
`zone.${ | ||
this.currentMoveZone === EditorZone.HEADER ? 'headerTip' : 'footerTip' | ||
}` | ||
) | ||
} else { | ||
this.tipContainer.classList.remove('show') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IZoneOption } from '../../interface/Zone' | ||
|
||
export const defaultZoneOption: Readonly<Required<IZoneOption>> = { | ||
tipDisabled: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IZoneOption { | ||
tipDisabled?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters