1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
import React = require("react");
import { Doc, DocListCast, WidthSym, HeightSym } from "../../../new_fields/Doc";
import { AnnotationTypes, Viewer, scale } from "./PDFViewer";
import { observer } from "mobx-react";
import { observable, IReactionDisposer, reaction, action } from "mobx";
import { BoolCast, NumCast, FieldValue, Cast, StrCast } from "../../../new_fields/Types";
import { Id } from "../../../new_fields/FieldSymbols";
import { List } from "../../../new_fields/List";
import PDFMenu from "./PDFMenu";
import { DocumentManager } from "../../util/DocumentManager";
import { PresentationView } from "../presentationview/PresentationView";
interface IAnnotationProps {
anno: Doc;
index: number;
parent: Viewer;
}
export default class Annotation extends React.Component<IAnnotationProps> {
render() {
let annotationDocs = DocListCast(this.props.anno.annotations);
let res = annotationDocs.map(a => {
let type = NumCast(a.type);
switch (type) {
// case AnnotationTypes.Pin:
// return <PinAnnotation parent={this} document={a} x={NumCast(a.x)} y={NumCast(a.y)} width={a[WidthSym]()} height={a[HeightSym]()} key={a[Id]} />;
case AnnotationTypes.Region:
return <RegionAnnotation parent={this.props.parent} document={a} index={this.props.index} x={NumCast(a.x)} y={NumCast(a.y)} width={a[WidthSym]()} height={a[HeightSym]()} key={a[Id]} />;
default:
return <div></div>;
}
});
return res;
}
}
interface IRegionAnnotationProps {
x: number;
y: number;
width: number;
height: number;
index: number;
parent: Viewer;
document: Doc;
}
@observer
class RegionAnnotation extends React.Component<IRegionAnnotationProps> {
@observable private _backgroundColor: string = "red";
private _reactionDisposer?: IReactionDisposer;
private _scrollDisposer?: IReactionDisposer;
private _mainCont: React.RefObject<HTMLDivElement>;
constructor(props: IRegionAnnotationProps) {
super(props);
this._mainCont = React.createRef();
}
componentDidMount() {
this._reactionDisposer = reaction(
() => BoolCast(this.props.document.delete),
() => {
if (BoolCast(this.props.document.delete)) {
if (this._mainCont.current) {
this._mainCont.current.style.display = "none";
}
}
},
{ fireImmediately: true }
);
this._scrollDisposer = reaction(
() => this.props.parent.Index,
() => {
if (this.props.parent.Index === this.props.index) {
this.props.parent.scrollTo(this.props.y * scale - (NumCast(this.props.parent.props.parent.Document.pdfHeight) / 2));
}
}
);
}
componentWillUnmount() {
this._reactionDisposer && this._reactionDisposer();
this._scrollDisposer && this._scrollDisposer();
}
deleteAnnotation = () => {
let annotation = DocListCast(this.props.parent.props.parent.fieldExtensionDoc.annotations);
let group = FieldValue(Cast(this.props.document.group, Doc));
if (group && annotation.indexOf(group) !== -1) {
let newAnnotations = annotation.filter(a => a !== FieldValue(Cast(this.props.document.group, Doc)));
this.props.parent.props.parent.fieldExtensionDoc.annotations = new List<Doc>(newAnnotations);
}
if (group) {
let groupAnnotations = DocListCast(group.annotations);
groupAnnotations.forEach(anno => anno.delete = true);
}
PDFMenu.Instance.fadeOut(true);
}
pinToPres = () => {
let group = FieldValue(Cast(this.props.document.group, Doc));
if (group) {
PresentationView.Instance.PinDoc(group);
}
}
@action
onPointerDown = (e: React.PointerEvent) => {
if (e.button === 0) {
let targetDoc = Cast(this.props.document.target, Doc, null);
if (targetDoc) {
DocumentManager.Instance.jumpToDocument(targetDoc, false);
}
}
if (e.button === 2) {
PDFMenu.Instance.Status = "annotation";
PDFMenu.Instance.Delete = this.deleteAnnotation.bind(this);
PDFMenu.Instance.Pinned = false;
PDFMenu.Instance.AddTag = this.addTag.bind(this);
PDFMenu.Instance.PinToPres = this.pinToPres;
PDFMenu.Instance.jumpTo(e.clientX, e.clientY, true);
}
}
addTag = (key: string, value: string): boolean => {
let group = FieldValue(Cast(this.props.document.group, Doc));
if (group) {
let valNum = parseInt(value);
group[key] = isNaN(valNum) ? value : valNum;
return true;
}
return false;
}
render() {
return (
<div className="pdfViewer-annotationBox" onPointerDown={this.onPointerDown} ref={this._mainCont}
style={{
top: this.props.y * scale,
left: this.props.x * scale,
width: this.props.width * scale,
height: this.props.height * scale,
pointerEvents: "all",
backgroundColor: this.props.parent.Index === this.props.index ? "green" : StrCast(this.props.document.color)
}}></div>
);
}
}
|