aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-06-10 14:07:36 -0400
committeryipstanley <stanley_yip@brown.edu>2019-06-10 14:07:36 -0400
commit2ecd0c3486ec37d1061468cda12aa64e38d0d3d5 (patch)
tree0d54e533df467a163ef74d388b59e0f86abe0401
parentbcd6960fe91008bf31d364c48b5c8765eec28701 (diff)
annotation improvements
-rw-r--r--src/client/documents/Documents.ts8
-rw-r--r--src/client/views/collections/CollectionSubView.tsx2
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx64
-rw-r--r--src/client/views/pdf/Page.tsx17
4 files changed, 57 insertions, 34 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 973c90ff4..fa6d19a5e 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -69,15 +69,15 @@ export interface DocumentOptions {
const delegateKeys = ["x", "y", "width", "height", "panX", "panY"];
export namespace DocUtils {
- export function MakeLink(source: Doc, target: Doc) {
+ export function MakeLink(source: Doc, target: Doc, title: string = "-link name-", description: string = "", tags: string = "Default") {
let protoSrc = source.proto ? source.proto : source;
let protoTarg = target.proto ? target.proto : target;
UndoManager.RunInBatch(() => {
let linkDoc = Docs.TextDocument({ width: 100, height: 30, borderRounding: -1 });
//let linkDoc = new Doc;
- linkDoc.proto!.title = "-link name-";
- linkDoc.proto!.linkDescription = "";
- linkDoc.proto!.linkTags = "Default";
+ linkDoc.proto!.title = title;
+ linkDoc.proto!.linkDescription = description;
+ linkDoc.proto!.linkTags = tags;
linkDoc.proto!.linkedTo = target;
linkDoc.proto!.linkedToPage = target.curPage;
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 1ced6a426..d25d07c3d 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -110,6 +110,8 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) {
else if (de.data instanceof DragManager.AnnotationDragData) {
console.log("dropped!");
console.log(de.data);
+ // de.data.dropDocument.x = de.x;
+ // de.data.dropDocument.y = de.y;
return this.props.addDocument(de.data.dropDocument);
}
return false;
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 9d19df540..d8e197cbe 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -81,31 +81,47 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
@undoBatch
@action
drop = (e: Event, de: DragManager.DropEvent) => {
- if (super.drop(e, de) && de.data instanceof DragManager.DocumentDragData) {
- if (de.data.droppedDocuments.length) {
- let dragDoc = de.data.droppedDocuments[0];
- let zoom = NumCast(dragDoc.zoomBasis, 1);
- let [xp, yp] = this.getTransform().transformPoint(de.x, de.y);
- let x = xp - de.data.xOffset / zoom;
- let y = yp - de.data.yOffset / zoom;
- let dropX = NumCast(de.data.droppedDocuments[0].x);
- let dropY = NumCast(de.data.droppedDocuments[0].y);
- de.data.droppedDocuments.forEach(d => {
- d.x = x + NumCast(d.x) - dropX;
- d.y = y + NumCast(d.y) - dropY;
- if (!NumCast(d.width)) {
- d.width = 300;
- }
- if (!NumCast(d.height)) {
- let nw = NumCast(d.nativeWidth);
- let nh = NumCast(d.nativeHeight);
- d.height = nw && nh ? nh / nw * NumCast(d.width) : 300;
- }
- this.bringToFront(d);
- });
- SelectionManager.ReselectAll();
+ if (super.drop(e, de)) {
+ if (de.data instanceof DragManager.DocumentDragData) {
+ if (de.data.droppedDocuments.length) {
+ let dragDoc = de.data.droppedDocuments[0];
+ let zoom = NumCast(dragDoc.zoomBasis, 1);
+ let [xp, yp] = this.getTransform().transformPoint(de.x, de.y);
+ let x = xp - de.data.xOffset / zoom;
+ let y = yp - de.data.yOffset / zoom;
+ let dropX = NumCast(de.data.droppedDocuments[0].x);
+ let dropY = NumCast(de.data.droppedDocuments[0].y);
+ de.data.droppedDocuments.forEach(d => {
+ d.x = x + NumCast(d.x) - dropX;
+ d.y = y + NumCast(d.y) - dropY;
+ if (!NumCast(d.width)) {
+ d.width = 300;
+ }
+ if (!NumCast(d.height)) {
+ let nw = NumCast(d.nativeWidth);
+ let nh = NumCast(d.nativeHeight);
+ d.height = nw && nh ? nh / nw * NumCast(d.width) : 300;
+ }
+ this.bringToFront(d);
+ });
+ SelectionManager.ReselectAll();
+ }
+ return true;
+ }
+ else if (de.data instanceof DragManager.AnnotationDragData) {
+ if (de.data.dropDocument) {
+ let dragDoc = de.data.dropDocument;
+ let zoom = NumCast(dragDoc.zoomBasis, 1);
+ let [xp, yp] = this.getTransform().transformPoint(de.x, de.y);
+ let x = xp - de.data.xOffset / zoom;
+ let y = yp - de.data.yOffset / zoom;
+ let dropX = NumCast(de.data.dropDocument.x);
+ let dropY = NumCast(de.data.dropDocument.y);
+ dragDoc.x = x + NumCast(dragDoc.x) - dropX;
+ dragDoc.y = y + NumCast(dragDoc.y) - dropY;
+ this.bringToFront(dragDoc);
+ }
}
- return true;
}
return false;
}
diff --git a/src/client/views/pdf/Page.tsx b/src/client/views/pdf/Page.tsx
index 7125c820c..5269f448b 100644
--- a/src/client/views/pdf/Page.tsx
+++ b/src/client/views/pdf/Page.tsx
@@ -7,10 +7,10 @@ import "./PDFViewer.scss";
import "pdfjs-dist/web/pdf_viewer.css";
import { PDFBox } from "../nodes/PDFBox";
import { DragManager } from "../../util/DragManager";
-import { Docs } from "../../documents/Documents";
+import { Docs, DocUtils } from "../../documents/Documents";
import { List } from "../../../new_fields/List";
import { emptyFunction } from "../../../Utils";
-import { Cast, NumCast } from "../../../new_fields/Types";
+import { Cast, NumCast, StrCast } from "../../../new_fields/Types";
import { listSpec } from "../../../new_fields/Schema";
import { menuBar } from "prosemirror-menu";
@@ -66,6 +66,7 @@ export default class Page extends React.Component<IPageProps> {
() => {
let annotations = DocListCast(this.props.parent.Document.annotations);
if (annotations && annotations.length) {
+ annotations = annotations.filter(anno => NumCast(anno.page) === this.props.page);
this.renderAnnotations(annotations, true);
}
},
@@ -163,8 +164,10 @@ export default class Page extends React.Component<IPageProps> {
annoDoc.y = anno.offsetTop;
annoDoc.height = anno.offsetHeight;
annoDoc.width = anno.offsetWidth;
+ annoDoc.page = this.props.page;
annoDoc.target = targetDoc;
annoDocs.push(annoDoc);
+ DocUtils.MakeLink(annoDoc, targetDoc, `Annotation from ${StrCast(this.props.parent.Document.title)}`, "", StrCast(this.props.parent.Document.title));
anno.remove();
}
this._currentAnnotations = [];
@@ -190,13 +193,14 @@ export default class Page extends React.Component<IPageProps> {
targetDoc.targetPage = this.props.page;
// creates annotation documents for current highlights
let annotationDocs = this.makeAnnotationDocuments(targetDoc);
- let targetAnnotations = Cast(targetDoc.annotations, listSpec(Doc));
+ console.log(annotationDocs);
+ let targetAnnotations = DocListCast(this.props.parent.Document.annotations);
if (targetAnnotations) {
targetAnnotations.push(...annotationDocs);
- targetDoc.annotations = targetAnnotations;
+ this.props.parent.Document.annotations = new List<Doc>(targetAnnotations);
}
else {
- targetDoc.annotations = new List<Doc>(annotationDocs);
+ this.props.parent.Document.annotations = new List<Doc>(annotationDocs);
}
// create dragData and star tdrag
let dragData = new DragManager.AnnotationDragData(thisDoc, annotationDocs, targetDoc);
@@ -422,10 +426,11 @@ interface IAnnotation {
width: number;
height: number;
}
+
class RegionAnnotation extends React.Component<IAnnotation> {
render() {
return (
- <div className="pdfViewer-annotationBox" style={{ top: this.props.x, left: this.props.y, width: this.props.width, height: this.props.height }}></div>
+ <div className="pdfViewer-annotationBox" style={{ top: this.props.y, left: this.props.x, width: this.props.width, height: this.props.height }}></div>
);
}
} \ No newline at end of file