|
@@ -1,10 +1,8 @@
|
|
|
import Base from './base';
|
|
|
-import { ALIGN } from '../../constants'
|
|
|
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 {
|
|
|
-
|
|
|
constructor ({
|
|
|
container,
|
|
|
annotation = null,
|
|
@@ -20,14 +18,13 @@ export default class Shape extends Base {
|
|
|
container,
|
|
|
annotation,
|
|
|
page,
|
|
|
+ layer,
|
|
|
viewport,
|
|
|
scale,
|
|
|
eventBus,
|
|
|
- show
|
|
|
})
|
|
|
this.enableReply = enableReply
|
|
|
|
|
|
- this.layer = layer
|
|
|
this.hidden = true
|
|
|
this.initial = false
|
|
|
this.outline = null
|
|
@@ -42,7 +39,6 @@ export default class Shape extends Base {
|
|
|
this.endCircle = null
|
|
|
|
|
|
this.show = show
|
|
|
- this.firstSelect = false
|
|
|
|
|
|
this.onContainerClick = this.handleContainerClick.bind(this)
|
|
|
this.onMousedown = this.handleMouseDown.bind(this)
|
|
@@ -359,9 +355,7 @@ export default class Shape extends Base {
|
|
|
this.outerLineContainer.append(this.deletetButton)
|
|
|
this.enableReply && this.outerLineContainer.append(this.replyButton)
|
|
|
this.initial = true
|
|
|
- this.firstSelect = true
|
|
|
if (this.show) {
|
|
|
- this.firstSelect = false
|
|
|
!this.layer.addMode && this.handleElementSelect()
|
|
|
}
|
|
|
}
|
|
@@ -471,13 +465,12 @@ export default class Shape extends Base {
|
|
|
|
|
|
// 处理选中
|
|
|
handleElementSelect () {
|
|
|
- this.show = false
|
|
|
this.hidden = false
|
|
|
- if (!this.firstSelect) {
|
|
|
+ if (this.show) {
|
|
|
this.updateTool()
|
|
|
+ this.show = false
|
|
|
}
|
|
|
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,
|
|
|
});
|
|
|
} 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 {
|
|
|
- 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({
|
|
|
leftTop: { x: left, y: top },
|
|
|
rightBottom: { x: right, y: bottom },
|
|
|
- });
|
|
|
+ })
|
|
|
}
|
|
|
+ startState.clickX = pageX
|
|
|
+ startState.clickY = pageY
|
|
|
}
|
|
|
|
|
|
handleMouseUp (event) {
|
|
@@ -790,12 +806,6 @@ export default class Shape extends Base {
|
|
|
document.removeEventListener('touchmove', this.onMousemove)
|
|
|
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 { leftTop, rightBottom } = this.getInitialPoint()
|
|
|
|
|
@@ -805,27 +815,56 @@ export default class Shape extends Base {
|
|
|
right: rightBottom.x,
|
|
|
bottom: rightBottom.y
|
|
|
}
|
|
|
+ if (rect === annotation.rect && annotation.pageIndex === this.page) return
|
|
|
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 }) {
|
|
|
const { width, height } = this.viewport
|
|
|
const rect = this.calculate(leftTop, rightBottom)
|
|
|
|
|
|
- this.newStart = leftTop
|
|
|
- this.newEnd = rightBottom
|
|
|
+ this.leftTop = leftTop
|
|
|
+ this.rightBottom = rightBottom
|
|
|
|
|
|
this.setCss(this.annotationContainer, {
|
|
|
top: rect.top - 2 + 'px',
|