|
@@ -15,7 +15,8 @@ export class TextEditor {
|
|
|
scale,
|
|
|
messageHandler,
|
|
|
newAdd,
|
|
|
- pageViewer
|
|
|
+ pageViewer,
|
|
|
+ hidden
|
|
|
}) {
|
|
|
this.eventBus = eventBus
|
|
|
this.contentContainer = contentContainer
|
|
@@ -29,6 +30,9 @@ export class TextEditor {
|
|
|
this.messageHandler = messageHandler
|
|
|
this.newAdd = newAdd
|
|
|
this.pageViewer = pageViewer
|
|
|
+ this.hidden = hidden
|
|
|
+
|
|
|
+ this.type = 'text'
|
|
|
|
|
|
this.frame = null
|
|
|
this.canvas = null
|
|
@@ -47,6 +51,7 @@ export class TextEditor {
|
|
|
this.mouseDown = false
|
|
|
this.moving = false
|
|
|
this.ratio = window.devicePixelRatio || 1
|
|
|
+ this.removed = false
|
|
|
|
|
|
this.start = null
|
|
|
this.end = null
|
|
@@ -74,12 +79,14 @@ export class TextEditor {
|
|
|
this.onHandlePropertyPanelChanged = this.handlePropertyPanelChanged.bind(this)
|
|
|
this.onCompositionstart = this.handleCompositionstart.bind(this)
|
|
|
this.onCompositionend = this.handleCompositionend.bind(this)
|
|
|
+ this.onShowContentEditorType = this.handleShow.bind(this)
|
|
|
|
|
|
this.render()
|
|
|
}
|
|
|
|
|
|
async render () {
|
|
|
this.eventBus._on('textPropertyChanged', this.onHandlePropertyPanelChanged)
|
|
|
+ this.eventBus._on('showContentEditorType', this.onShowContentEditorType)
|
|
|
|
|
|
await this.getRect()
|
|
|
this.canvas = document.createElement('canvas')
|
|
@@ -91,7 +98,8 @@ export class TextEditor {
|
|
|
left: this.rect.left + 'px',
|
|
|
top: this.rect.top + 'px',
|
|
|
width: this.rect.width + 'px',
|
|
|
- height: this.rect.height + 'px'
|
|
|
+ height: this.rect.height + 'px',
|
|
|
+ display: this.hidden ? 'none' : 'block'
|
|
|
},
|
|
|
{
|
|
|
class: 'frame-container',
|
|
@@ -379,7 +387,7 @@ export class TextEditor {
|
|
|
}
|
|
|
|
|
|
handleMouseDown (e) {
|
|
|
- if (e.button === 2) return // 右键点击不执行
|
|
|
+ if (e.button === 2 || this.hidden) return // 右键点击不执行
|
|
|
|
|
|
if (this.state === 1) {
|
|
|
const operatorId = e.target.getAttribute('data-id')
|
|
@@ -426,6 +434,11 @@ export class TextEditor {
|
|
|
if (e && !this.textContainer.contains(e.target) && this.state === 0) return
|
|
|
if (this.contentContainer.selectedFrameIndex !== -1 && this.contentContainer.selectedFrameIndex !== this.editAreaIndex && this.state === 0) return
|
|
|
|
|
|
+ document.removeEventListener(this.mousemove, this.onMousemove)
|
|
|
+ document.removeEventListener(this.mouseup, this.onMouseup)
|
|
|
+
|
|
|
+ this.textContainer.removeEventListener(this.mousemove, this.onMousemove)
|
|
|
+
|
|
|
if (e && e.target !== this.textarea && e.target !== this.textContainer) {
|
|
|
let offsetX, offsetY
|
|
|
if (isMobileDevice) {
|
|
@@ -584,14 +597,9 @@ export class TextEditor {
|
|
|
|
|
|
this.frameContainer.classList.add('selected')
|
|
|
|
|
|
- if (this.state === 1) {
|
|
|
+ if (this.state === 1 && !this.mouseMoved) {
|
|
|
onClickOutsideUp([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
|
}
|
|
|
-
|
|
|
- document.removeEventListener(this.mousemove, this.onMousemove)
|
|
|
- document.removeEventListener(this.mouseup, this.onMouseup)
|
|
|
-
|
|
|
- this.textContainer.removeEventListener(this.mousemove, this.onMousemove)
|
|
|
}
|
|
|
|
|
|
async handleMouseMove (e) {
|
|
@@ -772,7 +780,10 @@ export class TextEditor {
|
|
|
}
|
|
|
|
|
|
async handleOutside () {
|
|
|
- if (this.moving) return
|
|
|
+ if (this.moving) {
|
|
|
+ onClickOutsideUp([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
this.state = this.state === 2 ? 1 : this.state === 1 ? 0 : this.state
|
|
|
|
|
@@ -786,7 +797,7 @@ export class TextEditor {
|
|
|
this.frameContainer.classList.remove('selected')
|
|
|
this.outerLine.remove()
|
|
|
|
|
|
- this.contentContainer.selectedFrameIndex = -1
|
|
|
+ if (!this.removed) this.contentContainer.selectedFrameIndex = -1
|
|
|
|
|
|
setTimeout(() => {
|
|
|
const hasItem = document.querySelector('.frame-container.selected')
|
|
@@ -800,8 +811,6 @@ export class TextEditor {
|
|
|
if (this.state === 1) {
|
|
|
const text = await this.getText()
|
|
|
if (text.length === 0) {
|
|
|
- await this.outerLine.remove()
|
|
|
- this.contentContainer.selectedFrameIndex = -1
|
|
|
this.remove()
|
|
|
return
|
|
|
}
|
|
@@ -960,7 +969,7 @@ export class TextEditor {
|
|
|
|
|
|
// 更新canvas图
|
|
|
async updateCanvas(whole, oldRect) {
|
|
|
- await this.getRect()
|
|
|
+ if (!this.removed) await this.getRect()
|
|
|
|
|
|
if (this.frameContainer && this.outerLine) {
|
|
|
this.updateOutline({
|
|
@@ -1638,7 +1647,10 @@ export class TextEditor {
|
|
|
|
|
|
// 删除区域
|
|
|
async remove () {
|
|
|
+ await this.outerLine.remove()
|
|
|
this.frameContainer.remove()
|
|
|
+ this.contentContainer.selectedFrameIndex = -1
|
|
|
+ this.removed = true
|
|
|
|
|
|
await this.messageHandler.send('RemoveEditAreaByIndex', {
|
|
|
editPagePtr: this.editPagePtr,
|
|
@@ -1648,8 +1660,10 @@ export class TextEditor {
|
|
|
// editPagePtr: this.editPagePtr,
|
|
|
// editAreaPtr: this.editAreaPtr
|
|
|
// })
|
|
|
-
|
|
|
+
|
|
|
+ this.updateCanvas()
|
|
|
this.contentContainer.removeEditor(this.editAreaIndex)
|
|
|
+ this.eventBus.dispatch('contentPropertyChange', { type: 'text', isOpen: false })
|
|
|
}
|
|
|
|
|
|
// 复制区域对象
|
|
@@ -1670,4 +1684,15 @@ export class TextEditor {
|
|
|
this.selectedCharRange = { start, end }
|
|
|
if (this.state === 2) this.selectedRectList = await this.getCharsRect(start, end)
|
|
|
}
|
|
|
+
|
|
|
+ // 图片模式下隐藏
|
|
|
+ handleShow (type) {
|
|
|
+ if (type === 'image') {
|
|
|
+ this.hidden = true
|
|
|
+ this.frameContainer && (this.frameContainer.style.display = 'none')
|
|
|
+ } else {
|
|
|
+ this.hidden = false
|
|
|
+ this.frameContainer && (this.frameContainer.style.display = 'block')
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|