|
@@ -1,10 +1,8 @@
|
|
import Base from './base';
|
|
import Base from './base';
|
|
-import { ALIGN } from '../../constants'
|
|
|
|
import { getActualPoint, getClickPoint, createSvg, keepLastIndex, getInitialPoint, getHtmlToText, createElement, pastePlainText } from './utils';
|
|
import { getActualPoint, getClickPoint, createSvg, keepLastIndex, getInitialPoint, getHtmlToText, createElement, pastePlainText } from './utils';
|
|
-import { hexToRgb, onClickOutside } from '../ui_utils'
|
|
|
|
|
|
+import { onClickOutside } from '../ui_utils'
|
|
|
|
|
|
export default class Shape extends Base {
|
|
export default class Shape extends Base {
|
|
-
|
|
|
|
constructor ({
|
|
constructor ({
|
|
container,
|
|
container,
|
|
annotation = null,
|
|
annotation = null,
|
|
@@ -20,14 +18,13 @@ export default class Shape extends Base {
|
|
container,
|
|
container,
|
|
annotation,
|
|
annotation,
|
|
page,
|
|
page,
|
|
|
|
+ layer,
|
|
viewport,
|
|
viewport,
|
|
scale,
|
|
scale,
|
|
eventBus,
|
|
eventBus,
|
|
- show
|
|
|
|
})
|
|
})
|
|
this.enableReply = enableReply
|
|
this.enableReply = enableReply
|
|
|
|
|
|
- this.layer = layer
|
|
|
|
this.hidden = true
|
|
this.hidden = true
|
|
this.initial = false
|
|
this.initial = false
|
|
this.outline = null
|
|
this.outline = null
|
|
@@ -42,7 +39,6 @@ export default class Shape extends Base {
|
|
this.endCircle = null
|
|
this.endCircle = null
|
|
|
|
|
|
this.show = show
|
|
this.show = show
|
|
- this.firstSelect = false
|
|
|
|
|
|
|
|
this.onContainerClick = this.handleContainerClick.bind(this)
|
|
this.onContainerClick = this.handleContainerClick.bind(this)
|
|
this.onMousedown = this.handleMouseDown.bind(this)
|
|
this.onMousedown = this.handleMouseDown.bind(this)
|
|
@@ -359,9 +355,7 @@ export default class Shape extends Base {
|
|
this.outerLineContainer.append(this.deletetButton)
|
|
this.outerLineContainer.append(this.deletetButton)
|
|
this.enableReply && this.outerLineContainer.append(this.replyButton)
|
|
this.enableReply && this.outerLineContainer.append(this.replyButton)
|
|
this.initial = true
|
|
this.initial = true
|
|
- this.firstSelect = true
|
|
|
|
if (this.show) {
|
|
if (this.show) {
|
|
- this.firstSelect = false
|
|
|
|
!this.layer.addMode && this.handleElementSelect()
|
|
!this.layer.addMode && this.handleElementSelect()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -471,13 +465,12 @@ export default class Shape extends Base {
|
|
|
|
|
|
// 处理选中
|
|
// 处理选中
|
|
handleElementSelect () {
|
|
handleElementSelect () {
|
|
- this.show = false
|
|
|
|
this.hidden = false
|
|
this.hidden = false
|
|
- if (!this.firstSelect) {
|
|
|
|
|
|
+ if (this.show) {
|
|
this.updateTool()
|
|
this.updateTool()
|
|
|
|
+ this.show = false
|
|
}
|
|
}
|
|
onClickOutside([this.freetextElement, this.outerLine, this.deletetButton, this.replyButton, document.querySelector('.toggle-button')], this.handleOutside.bind(this))
|
|
onClickOutside([this.freetextElement, this.outerLine, this.deletetButton, this.replyButton, document.querySelector('.toggle-button')], this.handleOutside.bind(this))
|
|
- this.firstSelect = false
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// 获取实际坐标
|
|
// 获取实际坐标
|
|
@@ -736,44 +729,67 @@ export default class Shape extends Base {
|
|
rightBottom,
|
|
rightBottom,
|
|
});
|
|
});
|
|
} else if (startState.operator === 'move') {
|
|
} else if (startState.operator === 'move') {
|
|
- let left = pageX - (startState.clickX - leftTop.x);
|
|
|
|
- let top = pageY - (startState.clickY - leftTop.y);
|
|
|
|
- let right = pageX - (startState.clickX - rightBottom.x);
|
|
|
|
- let bottom = pageY - (startState.clickY - rightBottom.y);
|
|
|
|
-
|
|
|
|
- const rect = {
|
|
|
|
- width: Math.abs(left - right),
|
|
|
|
- height: Math.abs(bottom - top)
|
|
|
|
- }
|
|
|
|
- if (left < right) {
|
|
|
|
- left = Math.max(12, left)
|
|
|
|
- left = Math.min(width - rect.width - 4, left)
|
|
|
|
- right = Math.max(rect.width + 12, right)
|
|
|
|
- right = Math.min(width - 4, right)
|
|
|
|
- } else {
|
|
|
|
- right = Math.max(4, right)
|
|
|
|
- right = Math.min(width - rect.width - 12, right)
|
|
|
|
- left = Math.max(rect.width + 4, left)
|
|
|
|
- left = Math.min(width - 12, left)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (bottom < top) {
|
|
|
|
- bottom = Math.max(6, bottom)
|
|
|
|
- bottom = Math.min(height - rect.height - 9, bottom)
|
|
|
|
- top = Math.max(rect.height + 6, top)
|
|
|
|
- top = Math.min(height - 9, top)
|
|
|
|
|
|
+ let left, top, right, bottom
|
|
|
|
+ const documentViewer = this.layer.documentViewer
|
|
|
|
+ let windowCoordinates = this.getMouseLocation(event);
|
|
|
|
+ const page = documentViewer.getSelectedPage(windowCoordinates, windowCoordinates)
|
|
|
|
+ if (page.first && page.first !== (this.page + 1)) {
|
|
|
|
+ const annotationHeight = Math.abs(leftTop.y - rightBottom.y)
|
|
|
|
+ left = pageX - (startState.clickX - leftTop.x)
|
|
|
|
+ top = page.first > (this.page + 1) ? 0 : height - annotationHeight
|
|
|
|
+ right = pageX - (startState.clickX - rightBottom.x)
|
|
|
|
+ bottom = page.first > (this.page + 1) ? annotationHeight : height
|
|
|
|
+ this.page = page.first - 1
|
|
|
|
+
|
|
|
|
+ this.annotationContainer.remove()
|
|
|
|
+ this.outerLineContainer.remove()
|
|
|
|
+ const container = documentViewer.pdfViewer._pages[this.page].compdfAnnotationLayer.div
|
|
|
|
+ container.append(this.annotationContainer)
|
|
|
|
+ container.append(this.outerLineContainer)
|
|
|
|
+
|
|
|
|
+ this.container = container
|
|
} else {
|
|
} else {
|
|
- top = Math.max(9, top)
|
|
|
|
- top = Math.min(height - rect.height - 6, top)
|
|
|
|
- bottom = Math.max(rect.height + 9, bottom)
|
|
|
|
- bottom = Math.min(height - 6, bottom)
|
|
|
|
|
|
+ left = pageX - (startState.clickX - leftTop.x);
|
|
|
|
+ top = pageY - (startState.clickY - leftTop.y);
|
|
|
|
+ right = pageX - (startState.clickX - rightBottom.x);
|
|
|
|
+ bottom = pageY - (startState.clickY - rightBottom.y);
|
|
|
|
+
|
|
|
|
+ const rect = {
|
|
|
|
+ width: Math.abs(left - right),
|
|
|
|
+ height: Math.abs(bottom - top)
|
|
|
|
+ }
|
|
|
|
+ if (left < right) {
|
|
|
|
+ left = Math.max(12, left)
|
|
|
|
+ left = Math.min(width - rect.width - 4, left)
|
|
|
|
+ right = Math.max(rect.width + 12, right)
|
|
|
|
+ right = Math.min(width - 4, right)
|
|
|
|
+ } else {
|
|
|
|
+ right = Math.max(4, right)
|
|
|
|
+ right = Math.min(width - rect.width - 12, right)
|
|
|
|
+ left = Math.max(rect.width + 4, left)
|
|
|
|
+ left = Math.min(width - 12, left)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (bottom < top) {
|
|
|
|
+ bottom = Math.max(6, bottom)
|
|
|
|
+ bottom = Math.min(height - rect.height - 9, bottom)
|
|
|
|
+ top = Math.max(rect.height + 6, top)
|
|
|
|
+ top = Math.min(height - 9, top)
|
|
|
|
+ } else {
|
|
|
|
+ top = Math.max(9, top)
|
|
|
|
+ top = Math.min(height - rect.height - 6, top)
|
|
|
|
+ bottom = Math.max(rect.height + 9, bottom)
|
|
|
|
+ bottom = Math.min(height - 6, bottom)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
this.update({
|
|
this.update({
|
|
leftTop: { x: left, y: top },
|
|
leftTop: { x: left, y: top },
|
|
rightBottom: { x: right, y: bottom },
|
|
rightBottom: { x: right, y: bottom },
|
|
- });
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
+ startState.clickX = pageX
|
|
|
|
+ startState.clickY = pageY
|
|
}
|
|
}
|
|
|
|
|
|
handleMouseUp (event) {
|
|
handleMouseUp (event) {
|
|
@@ -790,12 +806,6 @@ export default class Shape extends Base {
|
|
document.removeEventListener('touchmove', this.onMousemove)
|
|
document.removeEventListener('touchmove', this.onMousemove)
|
|
document.removeEventListener('touchend', this.onMouseup)
|
|
document.removeEventListener('touchend', this.onMouseup)
|
|
|
|
|
|
- const { pageX, pageY } = getClickPoint(event)
|
|
|
|
- if (pageX === this.startState.clickX && pageY === this.startState.clickY) return
|
|
|
|
-
|
|
|
|
- this.leftTop = this.newStart
|
|
|
|
- this.rightBottom = this.newEnd
|
|
|
|
-
|
|
|
|
const annotation = this.annotation
|
|
const annotation = this.annotation
|
|
const { leftTop, rightBottom } = this.getInitialPoint()
|
|
const { leftTop, rightBottom } = this.getInitialPoint()
|
|
|
|
|
|
@@ -805,27 +815,56 @@ export default class Shape extends Base {
|
|
right: rightBottom.x,
|
|
right: rightBottom.x,
|
|
bottom: rightBottom.y
|
|
bottom: rightBottom.y
|
|
}
|
|
}
|
|
|
|
+ if (rect === annotation.rect && annotation.pageIndex === this.page) return
|
|
annotation.rect = rect
|
|
annotation.rect = rect
|
|
|
|
|
|
- this.eventBus.dispatch('annotationChange', {
|
|
|
|
- type: 'modify',
|
|
|
|
- annotation: {
|
|
|
|
- operate: "mod-annot",
|
|
|
|
- name: annotation.name,
|
|
|
|
- pageIndex: this.page,
|
|
|
|
- pagePtr: annotation.pagePtr,
|
|
|
|
- annotPtr: annotation.annotPtr,
|
|
|
|
- rect
|
|
|
|
|
|
+ if (annotation.pageIndex !== this.page) {
|
|
|
|
+ const annotationData = {
|
|
|
|
+ type: 'delete',
|
|
|
|
+ annotation: {
|
|
|
|
+ operate: "del-annot",
|
|
|
|
+ name: annotation.name,
|
|
|
|
+ pageIndex: annotation.pageIndex,
|
|
|
|
+ annotPtr: annotation.annotPtr
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ this.eventBus.dispatch('annotationChange', annotationData)
|
|
|
|
+
|
|
|
|
+ const newAnnotationData = Object.assign({}, annotation)
|
|
|
|
+ delete newAnnotationData.annotPtr
|
|
|
|
+ delete newAnnotationData.pagePtr
|
|
|
|
+ delete newAnnotationData.name
|
|
|
|
+ newAnnotationData.operate = 'add-annot'
|
|
|
|
+ newAnnotationData.pageIndex = this.page
|
|
|
|
+ this.eventBus.dispatch('annotationChange', {
|
|
|
|
+ type: 'add',
|
|
|
|
+ show: true,
|
|
|
|
+ annotation: newAnnotationData
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ this.annotationContainer.remove()
|
|
|
|
+ this.outerLineContainer.remove()
|
|
|
|
+ } else {
|
|
|
|
+ this.eventBus.dispatch('annotationChange', {
|
|
|
|
+ type: 'modify',
|
|
|
|
+ annotation: {
|
|
|
|
+ operate: "mod-annot",
|
|
|
|
+ name: annotation.name,
|
|
|
|
+ pageIndex: this.page,
|
|
|
|
+ pagePtr: annotation.pagePtr,
|
|
|
|
+ annotPtr: annotation.annotPtr,
|
|
|
|
+ rect
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
update ({ leftTop, rightBottom }) {
|
|
update ({ leftTop, rightBottom }) {
|
|
const { width, height } = this.viewport
|
|
const { width, height } = this.viewport
|
|
const rect = this.calculate(leftTop, rightBottom)
|
|
const rect = this.calculate(leftTop, rightBottom)
|
|
|
|
|
|
- this.newStart = leftTop
|
|
|
|
- this.newEnd = rightBottom
|
|
|
|
|
|
+ this.leftTop = leftTop
|
|
|
|
+ this.rightBottom = rightBottom
|
|
|
|
|
|
this.setCss(this.annotationContainer, {
|
|
this.setCss(this.annotationContainer, {
|
|
top: rect.top - 2 + 'px',
|
|
top: rect.top - 2 + 'px',
|