aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.DS_Storebin0 -> 6148 bytes
-rw-r--r--src/client/documents/Documents.ts17
-rw-r--r--src/client/util/DragManager.ts26
-rw-r--r--src/client/util/Scripting.ts4
-rw-r--r--src/client/views/Main.tsx5
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx2
-rw-r--r--src/client/views/collections/CollectionFreeFormView.scss29
-rw-r--r--src/client/views/collections/CollectionFreeFormView.tsx11
-rw-r--r--src/client/views/collections/CollectionView.tsx2
-rw-r--r--src/client/views/nodes/Annotation.tsx117
-rw-r--r--src/client/views/nodes/DocumentView.tsx3
-rw-r--r--src/client/views/nodes/FormattedTextBox.scss8
-rw-r--r--src/client/views/nodes/ImageBox.tsx14
-rw-r--r--src/client/views/nodes/KeyValueBox.tsx23
-rw-r--r--src/client/views/nodes/PDFNode.scss15
-rw-r--r--src/client/views/nodes/PDFNode.tsx515
-rw-r--r--src/client/views/nodes/Sticky.tsx83
-rw-r--r--src/fields/ImageField.ts1
-rw-r--r--src/fields/KeyStore.ts1
-rw-r--r--src/fields/ListField.ts1
-rw-r--r--src/fields/PDFField.ts36
-rw-r--r--src/server/Message.ts2
-rw-r--r--src/server/ServerUtil.ts30
-rw-r--r--src/typings/index.d.ts322
24 files changed, 1202 insertions, 65 deletions
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 000000000..620e4ebce
--- /dev/null
+++ b/src/.DS_Store
Binary files differ
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 1d24ff7d2..47b8ea844 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -15,6 +15,8 @@ import { Key } from "../../fields/Key"
import { Field } from "../../fields/Field";
import { KeyValueBox } from "../views/nodes/KeyValueBox"
import { KVPField } from "../../fields/KVPField";
+import { PDFField } from "../../fields/PDFField";
+import { PDFNode } from "../views/nodes/PDFNode";
export interface DocumentOptions {
x?: number;
@@ -38,7 +40,9 @@ export namespace Documents {
let webProto: Document;
let collProto: Document;
let kvpProto: Document;
+ let pdfProto: Document;
const textProtoId = "textProto";
+ const pdfProtoId = "pdfProto";
const imageProtoId = "imageProto";
const webProtoId = "webProto";
const collProtoId = "collectionProto";
@@ -92,6 +96,14 @@ export namespace Documents {
textProto = setupPrototypeOptions(textProtoId, "TEXT_PROTO", FormattedTextBox.LayoutString(),
{ x: 0, y: 0, width: 300, height: 150, layoutKeys: [KeyStore.Data] });
}
+ function GetPdfPrototype(): Document {
+ if (!pdfProto) {
+ pdfProto = setupPrototypeOptions(pdfProtoId, "PDF_PROTO", CollectionView.LayoutString("AnnotationsKey"),
+ { x: 0, y: 0, nativeWidth: 600, width: 300, layoutKeys: [KeyStore.Data, KeyStore.Annotations] });
+ pdfProto.SetText(KeyStore.BackgroundLayout, PDFNode.LayoutString());
+ }
+ return pdfProto;
+ }
function GetWebPrototype(): Document {
return webProto ? webProto :
webProto = setupPrototypeOptions(webProtoId, "WEB_PROTO", WebBox.LayoutString(),
@@ -120,6 +132,9 @@ export namespace Documents {
export function TextDocument(options: DocumentOptions = {}) {
return SetInstanceOptions(GetTextPrototype(), options, "", TextField);
}
+ export function PdfDocument(url: string, options: DocumentOptions = {}) {
+ return SetInstanceOptions(GetPdfPrototype(), options, new URL(url), PDFField);
+ }
export function WebDocument(url: string, options: DocumentOptions = {}) {
return SetInstanceOptions(GetWebPrototype(), options, new URL(url), WebField);
}
@@ -141,8 +156,6 @@ export namespace Documents {
return assignOptions(deleg, options);
}
-
-
// example of custom display string for an image that shows a caption.
function EmbeddedCaption() {
return `<div style="height:100%">
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 60910a40b..a7af399e2 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -3,6 +3,8 @@ import { CollectionDockingView } from "../views/collections/CollectionDockingVie
import { Document } from "../../fields/Document"
import { action } from "mobx";
import { DocumentView } from "../views/nodes/DocumentView";
+import { ImageField } from "../../fields/ImageField";
+import { KeyStore } from "../../fields/KeyStore";
export function setupDrag(_reference: React.RefObject<HTMLDivElement>, docFunc: () => Document) {
let onRowMove = action((e: PointerEvent): void => {
@@ -105,6 +107,7 @@ export namespace DragManager {
const scaleX = rect.width / w, scaleY = rect.height / h;
let x = rect.left, y = rect.top;
// const offsetX = e.x - rect.left, offsetY = e.y - rect.top;
+
let dragElement = ele.cloneNode(true) as HTMLElement;
dragElement.style.opacity = "0.7";
dragElement.style.position = "absolute";
@@ -115,10 +118,23 @@ export namespace DragManager {
dragElement.style.transform = `translate(${x}px, ${y}px) scale(${scaleX}, ${scaleY})`;
dragElement.style.width = `${rect.width / scaleX}px`;
dragElement.style.height = `${rect.height / scaleY}px`;
- // It seems like the above code should be able to just be this:
- // dragElement.style.transform = `translate(${x}px, ${y}px)`;
- // dragElement.style.width = `${rect.width}px`;
- // dragElement.style.height = `${rect.height}px`;
+
+ // bcz: PDFs don't show up if you clone them because they contain a canvas.
+ // however, PDF's have a thumbnail field that contains an image of their canvas.
+ // So we replace the pdf's canvas with the image thumbnail
+ const docView: DocumentView = dragData["documentView"];
+ const doc: Document = docView ? docView.props.Document : dragData["document"];
+ var pdfNode = dragElement.getElementsByClassName("pdfNode-cont")[0] as HTMLElement;
+ let thumbnail = doc.GetT(KeyStore.Thumbnail, ImageField);
+ if (pdfNode && pdfNode.childElementCount && thumbnail) {
+ let img = new Image();
+ img!.src = thumbnail.toString();
+ img!.style.position = "absolute";
+ img!.style.width = `${rect.width / scaleX}px`;
+ img!.style.height = `${rect.height / scaleY}px`;
+ pdfNode.replaceChild(img!, pdfNode.children[0])
+ }
+
dragDiv.appendChild(dragElement);
let hideSource = false;
@@ -140,8 +156,6 @@ export namespace DragManager {
y += e.movementY;
if (e.shiftKey) {
abortDrag();
- const docView: DocumentView = dragData["documentView"];
- const doc: Document = docView ? docView.props.Document : dragData["document"];
CollectionDockingView.Instance.StartOtherDrag(doc, { pageX: e.pageX, pageY: e.pageY, preventDefault: () => { }, button: 0 });
}
dragElement.style.transform = `translate(${x}px, ${y}px) scale(${scaleX}, ${scaleY})`;
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index 44f36fe19..46bd1a206 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -1,5 +1,5 @@
-import * as ts from "typescript"
-// let ts = (window as any).ts;
+// import * as ts from "typescript"
+let ts = (window as any).ts;
import { Opt, Field } from "../../fields/Field";
import { Document } from "../../fields/Document";
import { NumberField } from "../../fields/NumberField";
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 7aca6d88f..c9bdc24c2 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -52,11 +52,13 @@ Documents.initProtos(mainDocId, (res?: Document) => {
}
let imgurl = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg";
+ let pdfurl = "http://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf"
let weburl = "https://cs.brown.edu/courses/cs166/";
let clearDatabase = action(() => Utils.Emit(Server.Socket, MessageStore.DeleteAll, {}))
let addTextNode = action(() => Documents.TextDocument({ width: 200, height: 200, title: "a text note" }))
let addColNode = action(() => Documents.FreeformDocument([], { width: 200, height: 200, title: "a freeform collection" }));
let addSchemaNode = action(() => Documents.SchemaDocument([Documents.TextDocument()], { width: 200, height: 200, title: "a schema collection" }));
+ let addPDFNode = action(() => Documents.PdfDocument(pdfurl, { width: 200, height: 200, title: "a schema collection" }));
let addImageNode = action(() => Documents.ImageDocument(imgurl, { width: 200, height: 200, title: "an image of a cat" }));
let addWebNode = action(() => Documents.WebDocument(weburl, { width: 200, height: 200, title: "a sample web page" }));
@@ -65,6 +67,7 @@ Documents.initProtos(mainDocId, (res?: Document) => {
);
let imgRef = React.createRef<HTMLDivElement>();
+ let pdfRef = React.createRef<HTMLDivElement>();
let webRef = React.createRef<HTMLDivElement>();
let textRef = React.createRef<HTMLDivElement>();
let schemaRef = React.createRef<HTMLDivElement>();
@@ -95,6 +98,8 @@ Documents.initProtos(mainDocId, (res?: Document) => {
<button onPointerDown={setupDrag(schemaRef, addSchemaNode)} onClick={addClick(addSchemaNode)}>Add Schema</button></div>
<div className="main-buttonDiv" style={{ bottom: '125px' }} >
<button onClick={clearDatabase}>Clear Database</button></div>
+ <div className="main-buttonDiv" style={{ bottom: '150px' }} ref={pdfRef}>
+ <button onPointerDown={setupDrag(pdfRef, addPDFNode)} onClick={addClick(addPDFNode)}>Add PDF</button></div>
<button className="main-undoButtons" style={{ bottom: '25px' }} onClick={() => UndoManager.Undo()}>Undo</button>
<button className="main-undoButtons" style={{ bottom: '0px' }} onClick={() => UndoManager.Redo()}>Redo</button>
<InkingControl />
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index c51fba908..f01c538e6 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -35,6 +35,7 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp
private _goldenLayout: any = null;
private _containerRef = React.createRef<HTMLDivElement>();
private _fullScreen: any = null;
+ private _flush: boolean = false;
constructor(props: SubCollectionViewProps) {
super(props);
@@ -164,7 +165,6 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp
this._goldenLayout.updateSize(cur!.getBoundingClientRect().width, cur!.getBoundingClientRect().height);
}
- _flush: boolean = false;
@action
onPointerUp = (e: React.PointerEvent): void => {
if (this._flush) {
diff --git a/src/client/views/collections/CollectionFreeFormView.scss b/src/client/views/collections/CollectionFreeFormView.scss
index f432e8cc3..f496517f5 100644
--- a/src/client/views/collections/CollectionFreeFormView.scss
+++ b/src/client/views/collections/CollectionFreeFormView.scss
@@ -1,9 +1,36 @@
.collectionfreeformview-container {
+ .collectionfreeformview > .jsx-parser{
+ position:absolute;
+ height: 100%;
+ width: 100%;
+ }
+
+ border-style: solid;
+ box-sizing: border-box;
+ position: relative;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ overflow: hidden;
+ .collectionfreeformview {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width:100%;
+ height: 100%;
+ }
+}
+.collectionfreeformview-overlay {
+
.collectionfreeformview > .jsx-parser{
position:absolute;
height: 100%;
}
+ .formattedTextBox-cont {
+ background:yellow;
+ }
border-style: solid;
box-sizing: border-box;
@@ -18,7 +45,7 @@
top: 0;
left: 0;
width:100%;
- height: 100%
+ height: 100%;
}
}
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index aac0153dd..86d9a10e3 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -15,6 +15,7 @@ import { CollectionFreeFormDocumentView } from "../nodes/CollectionFreeFormDocum
import { DocumentView } from "../nodes/DocumentView";
import { FormattedTextBox } from "../nodes/FormattedTextBox";
import { ImageBox } from "../nodes/ImageBox";
+import { PDFNode } from "../nodes/PDFNode";
import { WebBox } from "../nodes/WebBox";
import { KeyValueBox } from "../nodes/KeyValueBox"
import "./CollectionFreeFormView.scss";
@@ -69,8 +70,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
@action
onPointerDown = (e: React.PointerEvent): void => {
- if ((e.button === 2 && this.props.active()) ||
- !e.defaultPrevented) {
+ if (((e.button === 2 && this.props.active()) ||
+ !e.defaultPrevented) && (!this.isAnnotationOverlay || this.zoomScaling != 1 || e.button == 0)) {
document.removeEventListener("pointermove", this.onPointerMove);
document.addEventListener("pointermove", this.onPointerMove);
document.removeEventListener("pointerup", this.onPointerUp);
@@ -249,7 +250,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
get backgroundView() {
return !this.backgroundLayout ? (null) :
(<JsxParser
- components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebBox, KeyValueBox }}
+ components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebBox, KeyValueBox, PDFNode }}
bindings={this.props.bindings}
jsx={this.backgroundLayout}
showWarnings={true}
@@ -260,7 +261,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
get overlayView() {
return !this.overlayLayout ? (null) :
(<JsxParser
- components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebBox, KeyValueBox }}
+ components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebBox, KeyValueBox, PDFNode }}
bindings={this.props.bindings}
jsx={this.overlayLayout}
showWarnings={true}
@@ -294,7 +295,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
const pany: number = -this.props.Document.GetNumber(KeyStore.PanY, 0);
return (
- <div className="collectionfreeformview-container"
+ <div className={`collectionfreeformview${this.isAnnotationOverlay ? "-overlay" : "-container"}`}
onPointerDown={this.onPointerDown}
onKeyPress={this.onKeyDown}
onWheel={this.onPointerWheel}
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 31824763d..8d175ee35 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -126,7 +126,7 @@ export class CollectionView extends React.Component<CollectionViewProps> {
subView = <div></div>
break;
}
- return (<div onContextMenu={this.specificContextMenu}>
+ return (<div className="collectionView-cont" onContextMenu={this.specificContextMenu}>
{subView}
</div>)
}
diff --git a/src/client/views/nodes/Annotation.tsx b/src/client/views/nodes/Annotation.tsx
new file mode 100644
index 000000000..a2c7be1a8
--- /dev/null
+++ b/src/client/views/nodes/Annotation.tsx
@@ -0,0 +1,117 @@
+import "./ImageBox.scss";
+import React = require("react")
+import { observer } from "mobx-react"
+import { observable, action } from 'mobx';
+import 'react-pdf/dist/Page/AnnotationLayer.css'
+
+interface IProps{
+ Span: HTMLSpanElement;
+ X: number;
+ Y: number;
+ Highlights: any[];
+ Annotations: any[];
+ CurrAnno: any[];
+
+}
+
+/**
+ * Annotation class is used to take notes on a particular highlight. You can also change highlighted span's color
+ * Improvements to be made: Removing the annotation when onRemove is called. (Removing this, not just the highlighted span).
+ * Also need to support multiline highlighting
+ *
+ * Written by: Andrew Kim
+ */
+@observer
+export class Annotation extends React.Component<IProps> {
+
+ /**
+ * changes color of the span (highlighted section)
+ */
+ onColorChange = (e:React.PointerEvent) => {
+ if (e.currentTarget.innerHTML == "r"){
+ this.props.Span.style.backgroundColor = "rgba(255,0,0, 0.3)"
+ } else if (e.currentTarget.innerHTML == "b"){
+ this.props.Span.style.backgroundColor = "rgba(0,255, 255, 0.3)"
+ } else if (e.currentTarget.innerHTML == "y"){
+ this.props.Span.style.backgroundColor = "rgba(255,255,0, 0.3)"
+ } else if (e.currentTarget.innerHTML == "g"){
+ this.props.Span.style.backgroundColor = "rgba(76, 175, 80, 0.3)"
+ }
+
+ }
+
+ /**
+ * removes the highlighted span. Supposed to remove Annotation too, but I don't know how to unmount this
+ */
+ @action
+ onRemove = (e:any) => {
+ let index:number = -1;
+ //finding the highlight in the highlight array
+ this.props.Highlights.forEach((e) => {
+ for (let i = 0; i < e.spans.length; i++){
+ if (e.spans[i] == this.props.Span){
+ index = this.props.Highlights.indexOf(e);
+ this.props.Highlights.splice(index, 1);
+ }
+ }
+ })
+
+ //removing from CurrAnno and Annotation array
+ this.props.Annotations.splice(index, 1);
+ this.props.CurrAnno.pop()
+
+ //removing span from div
+ if(this.props.Span.parentElement){
+ let nodesArray = this.props.Span.parentElement.childNodes;
+ nodesArray.forEach((e) => {
+ if (e == this.props.Span){
+ if (this.props.Span.parentElement){
+ this.props.Highlights.forEach((item) => {
+ if (item == e){
+ item.remove();
+ }
+ })
+ e.remove();
+ }
+ }
+ })
+ }
+
+
+ }
+
+ render() {
+ return (
+ <div
+ style = {{
+ position: "absolute",
+ top: "20px",
+ left: "0px",
+ zIndex: 1,
+ transform: `translate(${this.props.X}px, ${this.props.Y}px)`,
+
+ }}>
+ <div style = {{width:"200px", height:"50px", backgroundColor: "orange"}}>
+ <button
+ style = {{borderRadius: "25px", width:"25%", height:"100%"}}
+ onClick = {this.onRemove}
+ >x</button>
+ <div style = {{width:"75%", height: "100%" , display:"inline-block"}}>
+ <button onPointerDown = {this.onColorChange} style = {{backgroundColor:"red", borderRadius:"50%", color: "transparent"}}>r</button>
+ <button onPointerDown = {this.onColorChange} style = {{backgroundColor:"blue", borderRadius:"50%", color: "transparent"}}>b</button>
+ <button onPointerDown = {this.onColorChange} style = {{backgroundColor:"yellow", borderRadius:"50%", color:"transparent"}}>y</button>
+ <button onPointerDown = {this.onColorChange} style = {{backgroundColor:"green", borderRadius:"50%", color:"transparent"}}>g</button>
+ </div>
+
+ </div>
+ <div style = {{width:"200px", height:"200"}}>
+ <textarea style = {{width: "100%", height: "100%"}}
+ defaultValue = "Enter Text Here..."
+
+ ></textarea>
+ </div>
+ </div>
+
+ );
+ }
+} \ No newline at end of file
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index e01e1d4cd..1f928a3d6 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -18,6 +18,7 @@ import { ImageBox } from "../nodes/ImageBox";
import { Documents } from "../../documents/Documents"
import { KeyValueBox } from "./KeyValueBox"
import { WebBox } from "../nodes/WebBox";
+import { PDFNode } from "../nodes/PDFNode";
import "./DocumentView.scss";
import React = require("react");
const JsxParser = require('react-jsx-parser').default; //TODO Why does this need to be imported like this?
@@ -194,7 +195,7 @@ export class DocumentView extends React.Component<DocumentViewProps> {
}
@computed get mainContent() {
return <JsxParser
- components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebBox, KeyValueBox }}
+ components={{ FormattedTextBox, ImageBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, WebBox, KeyValueBox, PDFNode }}
bindings={this._documentBindings}
jsx={this.layout}
showWarnings={true}
diff --git a/src/client/views/nodes/FormattedTextBox.scss b/src/client/views/nodes/FormattedTextBox.scss
index cddbef6be..ab5849f09 100644
--- a/src/client/views/nodes/FormattedTextBox.scss
+++ b/src/client/views/nodes/FormattedTextBox.scss
@@ -11,8 +11,12 @@
.formattedTextBox-cont {
background: white;
padding: 1;
- border: black;
- border-width: 10;
+ border-width: 1px;
+ border-radius: 2px;
+ border-color:black;
+ box-sizing: border-box;
+ background: white;
+ border-style:solid;
overflow-y: scroll;
overflow-x: hidden;
color: initial;
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 8c44395f4..30910fb1f 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -1,15 +1,15 @@
+import { action, observable } from 'mobx';
+import { observer } from "mobx-react";
import Lightbox from 'react-image-lightbox';
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
-import "./ImageBox.scss";
-import React = require("react")
-import { ImageField } from '../../../fields/ImageField';
-import { FieldViewProps, FieldView } from './FieldView';
import { FieldWaiting } from '../../../fields/Field';
-import { observer } from "mobx-react"
-import { ContextMenu } from "../../views/ContextMenu";
-import { observable, action } from 'mobx';
+import { ImageField } from '../../../fields/ImageField';
import { KeyStore } from '../../../fields/KeyStore';
+import { ContextMenu } from "../../views/ContextMenu";
+import { FieldView, FieldViewProps } from './FieldView';
+import "./ImageBox.scss";
+import React = require("react")
@observer
export class ImageBox extends React.Component<FieldViewProps> {
diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx
index e8ebd50be..ac8c949a9 100644
--- a/src/client/views/nodes/KeyValueBox.tsx
+++ b/src/client/views/nodes/KeyValueBox.tsx
@@ -1,37 +1,18 @@
-import { IReactionDisposer } from 'mobx';
import { observer } from "mobx-react";
-import { EditorView } from 'prosemirror-view';
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
import { Document } from '../../../fields/Document';
-import { Opt, FieldWaiting } from '../../../fields/Field';
+import { FieldWaiting } from '../../../fields/Field';
import { KeyStore } from '../../../fields/KeyStore';
import { FieldView, FieldViewProps } from './FieldView';
-import { KeyValuePair } from "./KeyValuePair";
import "./KeyValueBox.scss";
+import { KeyValuePair } from "./KeyValuePair";
import React = require("react")
@observer
export class KeyValueBox extends React.Component<FieldViewProps> {
public static LayoutString(fieldStr: string = "DataKey") { return FieldView.LayoutString(KeyValueBox, fieldStr) }
- private _ref: React.RefObject<HTMLDivElement>;
- private _editorView: Opt<EditorView>;
- private _reactionDisposer: Opt<IReactionDisposer>;
-
-
- constructor(props: FieldViewProps) {
- super(props);
-
- this._ref = React.createRef();
- }
-
-
-
- shouldComponentUpdate() {
- return false;
- }
-
onPointerDown = (e: React.PointerEvent): void => {
if (e.buttons === 1 && this.props.isSelected()) {
diff --git a/src/client/views/nodes/PDFNode.scss b/src/client/views/nodes/PDFNode.scss
new file mode 100644
index 000000000..18ebca952
--- /dev/null
+++ b/src/client/views/nodes/PDFNode.scss
@@ -0,0 +1,15 @@
+.react-pdf__Page {
+ transform-origin: left top;
+ position: absolute;
+}
+.react-pdf__Document {
+ position: absolute;
+}
+.pdfNode-buttonTray {
+ position:absolute;
+ z-index: 25;
+}
+.pdfNode-contentContainer {
+ position: absolute;
+ transform-origin: "left top";
+} \ No newline at end of file
diff --git a/src/client/views/nodes/PDFNode.tsx b/src/client/views/nodes/PDFNode.tsx
new file mode 100644
index 000000000..648bd3e62
--- /dev/null
+++ b/src/client/views/nodes/PDFNode.tsx
@@ -0,0 +1,515 @@
+import { action, observable, _interceptReads, computed } from 'mobx';
+import { observer } from "mobx-react";
+import Measure from "react-measure";
+import 'react-image-lightbox/style.css';
+//@ts-ignore
+import { Document, Page } from "react-pdf";
+import 'react-pdf/dist/Page/AnnotationLayer.css';
+import { Utils } from '../../../Utils';
+import { Annotation } from './Annotation';
+import { FieldView, FieldViewProps } from './FieldView';
+import "./ImageBox.scss";
+import { Sticky } from './Sticky'; //you should look at sticky and annotation, because they are used here
+import React = require("react")
+import { KeyStore } from '../../../fields/KeyStore';
+import "./PDFNode.scss";
+import { PDFField } from '../../../fields/PDFField';
+import { FieldWaiting } from '../../../fields/Field';
+import { ImageField } from '../../../fields/ImageField';
+import * as htmlToImage from "html-to-image";
+import { url } from 'inspector';
+
+/** ALSO LOOK AT: Annotation.tsx, Sticky.tsx
+ * This method renders PDF and puts all kinds of functionalities such as annotation, highlighting,
+ * area selection (I call it stickies), embedded ink node for directly annotating using a pen or
+ * mouse, and pagination.
+ *
+ *
+ * HOW TO USE:
+ * AREA selection:
+ * 1) Click on Area button.
+ * 2) click on any part of the PDF, and drag to get desired sized area shape
+ * 3) You can write on the area (hence the reason why it's called sticky)
+ * 4) to make another area, you need to click on area button AGAIN.
+ *
+ * HIGHLIGHT: (Buggy. No multiline/multidiv text highlighting for now...)
+ * 1) just click and drag on a text
+ * 2) click highlight
+ * 3) for annotation, just pull your cursor over to that text
+ * 4) another method: click on highlight first and then drag on your desired text
+ * 5) To make another highlight, you need to reclick on the button
+ *
+ * Draw:
+ * 1) click draw and select color. then just draw like there's no tomorrow.
+ * 2) once you finish drawing your masterpiece, just reclick on the draw button to end your drawing session.
+ *
+ * Pagination:
+ * 1) click on arrows. You'll notice that stickies will stay in those page. But... highlights won't.
+ * 2) to test this out, make few area/stickies and then click on next page then come back. You'll see that they are all saved.
+ *
+ *
+ * written by: Andrew Kim
+ */
+@observer
+export class PDFNode extends React.Component<FieldViewProps> {
+ public static LayoutString() { return FieldView.LayoutString(PDFNode); }
+
+ private _mainDiv = React.createRef<HTMLDivElement>()
+ private _pdf = React.createRef<HTMLCanvasElement>();
+
+ //very useful for keeping track of X and y position throughout the PDF Canvas
+ private initX: number = 0;
+ private initY: number = 0;
+
+ //checks if tool is on
+ private _toolOn: boolean = false; //checks if tool is on
+ private _pdfContext: any = null; //gets pdf context
+ private bool: Boolean = false; //general boolean debounce
+ private currSpan: any;//keeps track of current span (for highlighting)
+
+ private _currTool: any; //keeps track of current tool button reference
+ private _drawToolOn: boolean = false; //boolean that keeps track of the drawing tool
+ private _drawTool = React.createRef<HTMLButtonElement>()//drawing tool button reference
+
+ private _colorTool = React.createRef<HTMLButtonElement>(); //color button reference
+ private _currColor: string = "black"; //current color that user selected (for ink/pen)
+
+ private _highlightTool = React.createRef<HTMLButtonElement>(); //highlighter button reference
+ private _highlightToolOn: boolean = false;
+ private _pdfCanvas: any;
+
+ @observable private _perPageInfo: Object[] = []; //stores pageInfo
+ @observable private _pageInfo: any = { area: [], divs: [], anno: [] }; //divs is array of objects linked to anno
+
+ @observable private _currAnno: any = []
+ @observable private _page: number = 1; //default is the first page.
+ @observable private _numPages: number = 1; //default number of pages
+ @observable private _interactive: boolean = false;
+ @observable private _loaded: boolean = false;
+
+ /**
+ * for pagination backwards
+ */
+ @action
+ onPageBack = () => {
+ if (this._page > 1) {
+ this._page -= 1;
+ this._currAnno = [];
+ this._perPageInfo[this._page] = this._pageInfo
+ this._pageInfo = { area: [], divs: [], anno: [] }; //resets the object to default
+ if (this._perPageInfo[this._page - 1]) {
+ this._pageInfo = this._perPageInfo[this._page - 1];
+ }
+ this.saveThumbnail();
+ }
+ }
+
+ /**
+ * for pagination forwards
+ */
+ @action
+ onPageForward = () => {
+ if (this._page < this._numPages) {
+ this._page += 1;
+ this._currAnno = [];
+ this._perPageInfo[this._page - 2] = this._pageInfo;
+ this._pageInfo = { area: [], divs: [], anno: [] }; //resets the object to default
+ if (this._perPageInfo[this._page - 1]) {
+ this._pageInfo = this._perPageInfo[this._page - 1];
+ }
+ this.saveThumbnail();
+ }
+ }
+
+ /**
+ * selection tool used for area highlighting (stickies). Kinda temporary
+ */
+ selectionTool = () => {
+ this._toolOn = true;
+ }
+ /**
+ * when user draws on the canvas. When mouse pointer is down
+ */
+ drawDown = (e: PointerEvent) => {
+ this.initX = e.offsetX;
+ this.initY = e.offsetY;
+ this._pdfContext.beginPath();
+ this._pdfContext.lineTo(this.initX, this.initY);
+ this._pdfContext.strokeStyle = this._currColor;
+ this._pdfCanvas.addEventListener("pointermove", this.drawMove);
+ this._pdfCanvas.addEventListener("pointerup", this.drawUp);
+
+ }
+ //when user drags
+ drawMove = (e: PointerEvent): void => {
+ //x and y mouse movement
+ let x = this.initX += e.movementX,
+ y = this.initY += e.movementY;
+ //connects the point
+ this._pdfContext.lineTo(x, y);
+ this._pdfContext.stroke();
+ }
+
+ drawUp = (e: PointerEvent) => {
+ this._pdfContext.closePath();
+ this._pdfCanvas.removeEventListener("pointermove", this.drawMove);
+ this._pdfCanvas.removeEventListener("pointerdown", this.drawDown);
+ this._pdfCanvas.addEventListener("pointerdown", this.drawDown);
+ }
+
+
+ /**
+ * highlighting helper function
+ */
+ makeEditableAndHighlight = (colour: string) => {
+ var range, sel = window.getSelection();
+ if (sel.rangeCount && sel.getRangeAt) {
+ range = sel.getRangeAt(0);
+ }
+ document.designMode = "on";
+ if (!document.execCommand("HiliteColor", false, colour)) {
+ document.execCommand("HiliteColor", false, colour);
+ }
+
+ if (range) {
+ sel.removeAllRanges();
+ sel.addRange(range);
+
+ let obj: Object = { parentDivs: [], spans: [] };
+ //@ts-ignore
+ if (range.commonAncestorContainer.className == 'react-pdf__Page__textContent') { //multiline highlighting case
+ obj = this.highlightNodes(range.commonAncestorContainer.childNodes)
+ } else { //single line highlighting case
+ let parentDiv = range.commonAncestorContainer.parentElement
+ if (parentDiv) {
+ if (parentDiv.className == 'react-pdf__Page__textContent') { //when highlight is overwritten
+ obj = this.highlightNodes(parentDiv.childNodes)
+ } else {
+ parentDiv.childNodes.forEach((child) => {
+ if (child.nodeName == 'SPAN') {
+ //@ts-ignore
+ obj.parentDivs.push(parentDiv)
+ //@ts-ignore
+ child.id = "highlighted"
+ //@ts-ignore
+ obj.spans.push(child)
+ child.addEventListener("mouseover", this.onEnter); //adds mouseover annotation handler
+ }
+ })
+ }
+ }
+ }
+ this._pageInfo.divs.push(obj);
+
+ }
+ document.designMode = "off";
+ }
+
+ highlightNodes = (nodes: NodeListOf<ChildNode>) => {
+ let temp = { parentDivs: [], spans: [] }
+ nodes.forEach((div) => {
+ div.childNodes.forEach((child) => {
+ if (child.nodeName == 'SPAN') {
+ //@ts-ignore
+ temp.parentDivs.push(div)
+ //@ts-ignore
+ child.id = "highlighted"
+ //@ts-ignore
+ temp.spans.push(child)
+ child.addEventListener("mouseover", this.onEnter); //adds mouseover annotation handler
+ }
+ })
+
+ })
+ return temp;
+ }
+
+ /**
+ * when the cursor enters the highlight, it pops out annotation. ONLY WORKS FOR SINGLE DIV LINES
+ */
+ @action
+ onEnter = (e: any) => {
+ let span: HTMLSpanElement = e.toElement;
+ let index: any;
+ this._pageInfo.divs.forEach((obj: any) => {
+ obj.spans.forEach((element: any) => {
+ if (element == span) {
+ if (!index) {
+ index = this._pageInfo.divs.indexOf(obj);
+ }
+ }
+ })
+ })
+
+ if (this._pageInfo.anno.length >= index + 1) {
+ if (this._currAnno.length == 0) {
+ this._currAnno.push(this._pageInfo.anno[index]);
+ }
+ } else {
+ if (this._currAnno.length == 0) { //if there are no current annotation
+ let div = span.offsetParent;
+ //@ts-ignore
+ let divX = div.style.left
+ //@ts-ignore
+ let divY = div.style.top
+ //slicing "px" from the end
+ divX = divX.slice(0, divX.length - 2); //gets X of the DIV element (parent of Span)
+ divY = divY.slice(0, divY.length - 2); //gets Y of the DIV element (parent of Span)
+ let annotation = <Annotation key={Utils.GenerateGuid()} Span={span} X={divX} Y={divY - 300} Highlights={this._pageInfo.divs} Annotations={this._pageInfo.anno} CurrAnno={this._currAnno} />
+ this._pageInfo.anno.push(annotation);
+ this._currAnno.push(annotation);
+ }
+ }
+
+ }
+
+ /**
+ * highlight function for highlighting actual text. This works fine.
+ */
+ highlight = (color: string) => {
+ if (window.getSelection()) {
+ try {
+ if (!document.execCommand("hiliteColor", false, color)) {
+ this.makeEditableAndHighlight(color);
+ }
+ } catch (ex) {
+ this.makeEditableAndHighlight(color)
+ }
+ }
+ }
+
+ /**
+ * controls the area highlighting (stickies) Kinda temporary
+ */
+ onPointerDown = (e: React.PointerEvent) => {
+ if (this._toolOn) {
+ let mouse = e.nativeEvent;
+ this.initX = mouse.offsetX;
+ this.initY = mouse.offsetY;
+
+ }
+ }
+
+ /**
+ * controls area highlighting and partially highlighting. Kinda temporary
+ */
+ @action
+ onPointerUp = (e: React.PointerEvent) => {
+ if (this._highlightToolOn) {
+ this.highlight("rgba(76, 175, 80, 0.3)"); //highlights to this default color.
+ this._highlightToolOn = false;
+ }
+ if (this._toolOn) {
+ let mouse = e.nativeEvent;
+ let finalX = mouse.offsetX;
+ let finalY = mouse.offsetY;
+ let width = Math.abs(finalX - this.initX); //width
+ let height = Math.abs(finalY - this.initY); //height
+
+ //these two if statements are bidirectional dragging. You can drag from any point to another point and generate sticky
+ if (finalX < this.initX) {
+ this.initX = finalX;
+ }
+ if (finalY < this.initY) {
+ this.initY = finalY;
+ }
+
+ if (this._mainDiv.current) {
+ let sticky = <Sticky key={Utils.GenerateGuid()} Height={height} Width={width} X={this.initX} Y={this.initY} />
+ this._pageInfo.area.push(sticky);
+ }
+ this._toolOn = false;
+ }
+ this._interactive = true;
+ }
+
+ /**
+ * starts drawing the line when user presses down.
+ */
+ onDraw = () => {
+ if (this._currTool != null) {
+ this._currTool.style.backgroundColor = "grey";
+ }
+
+ if (this._drawTool.current) {
+ this._currTool = this._drawTool.current;
+ if (this._drawToolOn) {
+ this._drawToolOn = false;
+ this._pdfCanvas.removeEventListener("pointerdown", this.drawDown);
+ this._pdfCanvas.removeEventListener("pointerup", this.drawUp);
+ this._pdfCanvas.removeEventListener("pointermove", this.drawMove);
+ this._drawTool.current.style.backgroundColor = "grey";
+ } else {
+ this._drawToolOn = true;
+ this._pdfCanvas.addEventListener("pointerdown", this.drawDown);
+ this._drawTool.current.style.backgroundColor = "cyan";
+ }
+ }
+ }
+
+
+ /**
+ * for changing color (for ink/pen)
+ */
+ onColorChange = (e: React.PointerEvent) => {
+ if (e.currentTarget.innerHTML == "Red") {
+ this._currColor = "red";
+ } else if (e.currentTarget.innerHTML == "Blue") {
+ this._currColor = "blue";
+ } else if (e.currentTarget.innerHTML == "Green") {
+ this._currColor = "green";
+ } else if (e.currentTarget.innerHTML == "Black") {
+ this._currColor = "black";
+ }
+
+ }
+
+
+ /**
+ * For highlighting (text drag highlighting)
+ */
+ onHighlight = () => {
+ this._drawToolOn = false;
+ if (this._currTool != null) {
+ this._currTool.style.backgroundColor = "grey";
+ }
+ if (this._highlightTool.current) {
+ this._currTool = this._drawTool.current;
+ if (this._highlightToolOn) {
+ this._highlightToolOn = false;
+ this._highlightTool.current.style.backgroundColor = "grey";
+ } else {
+ this._highlightToolOn = true;
+ this._highlightTool.current.style.backgroundColor = "orange";
+ }
+ }
+ }
+
+
+
+
+ @action
+ saveThumbnail = () => {
+ setTimeout(() => {
+ var me = this;
+ htmlToImage.toPng(this._mainDiv.current!,
+ { width: me.props.doc.GetNumber(KeyStore.NativeWidth, 0), height: me.props.doc.GetNumber(KeyStore.NativeHeight, 0), quality: 0.5 })
+ .then(function (dataUrl: string) {
+ me.props.doc.SetData(KeyStore.Thumbnail, new URL(dataUrl), ImageField);
+ })
+ .catch(function (error: any) {
+ console.error('oops, something went wrong!', error);
+ });
+ }, 1000);
+ }
+
+ @action
+ onLoaded = (page: any) => {
+ if (this._mainDiv.current) {
+ this._mainDiv.current.childNodes.forEach((element) => {
+ if (element.nodeName == "DIV") {
+ element.childNodes[0].childNodes.forEach((e) => {
+
+ if (e instanceof HTMLCanvasElement) {
+ this._pdfCanvas = e;
+ this._pdfContext = e.getContext("2d")
+
+ }
+
+ })
+ }
+ })
+ }
+ this._numPages = page.transport.numPages
+ if (this._perPageInfo.length == 0) { //Makes sure it only runs once
+ this._perPageInfo = [...Array(this._numPages)]
+ }
+ this._loaded = true;
+ }
+
+ @action
+ setScaling = (r: any) => {
+ // bcz: the nativeHeight should really be set when the document is imported.
+ // also, the native dimensions could be different for different pages of the PDF
+ // so this design is flawed.
+ var nativeWidth = this.props.doc.GetNumber(KeyStore.NativeWidth, 0);
+ if (!this.props.doc.GetNumber(KeyStore.NativeHeight, 0)) {
+ this.props.doc.SetNumber(KeyStore.NativeHeight, nativeWidth * r.entry.height / r.entry.width);
+ }
+ if (!this.props.doc.GetT(KeyStore.Thumbnail, ImageField)) {
+ this.saveThumbnail();
+ }
+ }
+
+ @computed
+ get uIButtons() {
+ return (
+ <div className="pdfNode-buttonTray" key="tray">
+ <button className="pdfButton" onClick={this.onPageBack}>{"<"}</button>
+ <button className="pdfButton" onClick={this.onPageForward}>{">"}</button>
+ <button className="pdfButton" onClick={this.selectionTool}>{"Area"}</button>
+ <button className="pdfButton" style={{ color: "white", backgroundColor: "grey" }} onClick={this.onHighlight} ref={this._highlightTool}>Highlight</button>
+ <button className="pdfButton" style={{ color: "white", backgroundColor: "grey" }} ref={this._drawTool} onClick={this.onDraw}>{"Draw"}</button>
+ <button className="pdfButton" ref={this._colorTool} onPointerDown={this.onColorChange}>{"Red"}</button>
+ <button className="pdfButton" ref={this._colorTool} onPointerDown={this.onColorChange}>{"Blue"}</button>
+ <button className="pdfButton" ref={this._colorTool} onPointerDown={this.onColorChange}>{"Green"}</button>
+ <button className="pdfButton" ref={this._colorTool} onPointerDown={this.onColorChange}>{"Black"}</button>
+ </div>);
+ }
+
+ @computed
+ get pdfContent() {
+ const renderHeight = 2400;
+ let pdfUrl = this.props.doc.GetT(this.props.fieldKey, PDFField);
+ let xf = this.props.doc.GetNumber(KeyStore.NativeHeight, 0) / renderHeight;
+ return <div className="pdfNode-contentContainer" key="container" style={{ transform: `scale(${xf}, ${xf})` }}>
+ <Document file={window.origin + "/corsProxy/" + `${pdfUrl}`}>
+ <Measure onResize={this.setScaling}>
+ {({ measureRef }) =>
+ <div className="pdfNode-page" ref={measureRef}>
+ <Page height={renderHeight} pageNumber={this._page} onLoadSuccess={this.onLoaded} />
+ </div>
+ }
+ </Measure>
+ </Document>
+ </div >;
+ }
+
+ @computed
+ get pdfRenderer() {
+ let proxy = this._loaded ? (null) : this.imageProxyRenderer;
+ let pdfUrl = this.props.doc.GetT(this.props.fieldKey, PDFField);
+ if ((!this._interactive && proxy) || !pdfUrl || pdfUrl == FieldWaiting) {
+ return proxy;
+ }
+ return [
+ this._pageInfo.area.filter(() => this._pageInfo.area).map((element: any) => element),
+ this._currAnno.map((element: any) => element),
+ this.uIButtons,
+ <div key="pdfNode-contentShell">
+ {this.pdfContent}
+ {proxy}
+ </div>
+ ];
+ }
+
+ @computed
+ get imageProxyRenderer() {
+ let field = this.props.doc.Get(KeyStore.Thumbnail);
+ if (field) {
+ let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
+ field instanceof ImageField ? field.Data.href : "http://cs.brown.edu/people/bcz/prairie.jpg";
+ return <img src={path} width="100%" />;
+ }
+ return (null);
+ }
+
+ render() {
+ return (
+ <div className="pdfNode-cont" ref={this._mainDiv} onPointerDown={this.onPointerDown} onPointerUp={this.onPointerUp} >
+ {this.pdfRenderer}
+ </div >
+ );
+ }
+
+} \ No newline at end of file
diff --git a/src/client/views/nodes/Sticky.tsx b/src/client/views/nodes/Sticky.tsx
new file mode 100644
index 000000000..d57dd5c0b
--- /dev/null
+++ b/src/client/views/nodes/Sticky.tsx
@@ -0,0 +1,83 @@
+import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
+import React = require("react")
+import { observer } from "mobx-react"
+import 'react-pdf/dist/Page/AnnotationLayer.css'
+
+interface IProps {
+ Height: number;
+ Width: number;
+ X: number;
+ Y: number;
+}
+
+/**
+ * Sticky, also known as area highlighting, is used to highlight large selection of the PDF file.
+ * Improvements that could be made: maybe store line array and store that somewhere for future rerendering.
+ *
+ * Written By: Andrew Kim
+ */
+@observer
+export class Sticky extends React.Component<IProps> {
+
+ private initX: number = 0;
+ private initY: number = 0;
+
+ private _ref = React.createRef<HTMLCanvasElement>();
+ private ctx: any; //context that keeps track of sticky canvas
+
+ /**
+ * drawing. Registers the first point that user clicks when mouse button is pressed down on canvas
+ */
+ drawDown = (e: React.PointerEvent) => {
+ if (this._ref.current) {
+ this.ctx = this._ref.current.getContext("2d");
+ let mouse = e.nativeEvent;
+ this.initX = mouse.offsetX;
+ this.initY = mouse.offsetY;
+ this.ctx.beginPath();
+ this.ctx.lineTo(this.initX, this.initY);
+ this.ctx.strokeStyle = "black";
+ document.addEventListener("pointermove", this.drawMove);
+ document.addEventListener("pointerup", this.drawUp);
+ }
+ }
+
+ //when user drags
+ drawMove = (e: PointerEvent): void => {
+ //x and y mouse movement
+ let x = this.initX += e.movementX,
+ y = this.initY += e.movementY;
+ //connects the point
+ this.ctx.lineTo(x, y);
+ this.ctx.stroke();
+
+ }
+
+ /**
+ * when user lifts the mouse, the drawing ends
+ */
+ drawUp = (e: PointerEvent) => {
+ this.ctx.closePath();
+ console.log(this.ctx);
+ document.removeEventListener("pointermove", this.drawMove);
+ }
+
+ render() {
+ return (
+ <div onPointerDown={this.drawDown}>
+ <canvas ref={this._ref} height={this.props.Height} width={this.props.Width}
+ style={{
+ position: "absolute",
+ top: "20px",
+ left: "0px",
+ zIndex: 1,
+ background: "yellow",
+ transform: `translate(${this.props.X}px, ${this.props.Y}px)`,
+ opacity: 0.4
+ }}
+ />
+
+ </div>
+ );
+ }
+} \ No newline at end of file
diff --git a/src/fields/ImageField.ts b/src/fields/ImageField.ts
index b2226d55a..be8d73e68 100644
--- a/src/fields/ImageField.ts
+++ b/src/fields/ImageField.ts
@@ -1,7 +1,6 @@
import { BasicField } from "./BasicField";
import { Field, FieldId } from "./Field";
import { Types } from "../server/Message";
-import { ObjectID } from "bson";
export class ImageField extends BasicField<URL> {
constructor(data: URL | undefined = undefined, id?: FieldId, save: boolean = true) {
diff --git a/src/fields/KeyStore.ts b/src/fields/KeyStore.ts
index 9cdd18f4e..259d1acaf 100644
--- a/src/fields/KeyStore.ts
+++ b/src/fields/KeyStore.ts
@@ -26,5 +26,6 @@ export namespace KeyStore {
export const Caption = new Key("Caption");
export const ActiveFrame = new Key("ActiveFrame");
export const DocumentText = new Key("DocumentText");
+ export const Thumbnail = new Key("Thumbnail");
export const Ink = new Key("Ink");
}
diff --git a/src/fields/ListField.ts b/src/fields/ListField.ts
index 700600804..a71325a65 100644
--- a/src/fields/ListField.ts
+++ b/src/fields/ListField.ts
@@ -40,6 +40,7 @@ export class ListField<T extends Field> extends BasicField<T[]> {
this.observeDisposer()
}
this.data = observable(value);
+ this.updateProxies();
this.observeList();
}
diff --git a/src/fields/PDFField.ts b/src/fields/PDFField.ts
new file mode 100644
index 000000000..f3a009001
--- /dev/null
+++ b/src/fields/PDFField.ts
@@ -0,0 +1,36 @@
+import { BasicField } from "./BasicField";
+import { Field, FieldId } from "./Field";
+import { observable } from "mobx"
+import { Types } from "../server/Message";
+
+
+
+export class PDFField extends BasicField<URL> {
+ constructor(data: URL | undefined = undefined, id?: FieldId, save: boolean = true) {
+ super(data == undefined ? new URL("http://cs.brown.edu/~bcz/bob_fettucine.jpg") : data, save, id);
+ }
+
+ toString(): string {
+ return this.Data.href;
+ }
+
+ Copy(): Field {
+ return new PDFField(this.Data);
+ }
+
+ ToScriptString(): string {
+ return `new PDFField("${this.Data}")`;
+ }
+
+ ToJson(): { type: Types, data: URL, _id: string } {
+ return {
+ type: Types.PDF,
+ data: this.Data,
+ _id: this.Id
+ }
+ }
+
+ @observable
+ Page: Number = 1;
+
+} \ No newline at end of file
diff --git a/src/server/Message.ts b/src/server/Message.ts
index fc07ef89b..5e97a5edf 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -45,7 +45,7 @@ export class GetFieldArgs {
}
export enum Types {
- Number, List, Key, Image, Web, Document, Text, RichText, DocumentReference, Html, Ink
+ Number, List, Key, Image, Web, Document, Text, RichText, DocumentReference, Html, Ink, PDF
}
export class DocumentTransfer implements Transferable {
diff --git a/src/server/ServerUtil.ts b/src/server/ServerUtil.ts
index f5734a86c..3b9d14891 100644
--- a/src/server/ServerUtil.ts
+++ b/src/server/ServerUtil.ts
@@ -1,17 +1,17 @@
-import { Field } from './../fields/Field';
-import { TextField } from './../fields/TextField';
-import { NumberField } from './../fields/NumberField';
-import { RichTextField } from './../fields/RichTextField';
-import { Key } from './../fields/Key';
-import { ImageField } from './../fields/ImageField';
-import { ListField } from './../fields/ListField';
-import { Document } from './../fields/Document';
-import { Server } from './../client/Server';
-import { Types } from './Message';
-import { Utils } from '../Utils';
-import { HtmlField } from '../fields/HtmlField';
-import { WebField } from '../fields/WebField';
-import { InkField } from '../fields/InkField';
+import {HtmlField} from '../fields/HtmlField';
+import {InkField} from '../fields/InkField';
+import {PDFField} from '../fields/PDFField';
+import {WebField} from '../fields/WebField';
+import {Utils} from '../Utils';
+import {Document} from './../fields/Document';
+import {Field} from './../fields/Field';
+import {ImageField} from './../fields/ImageField';
+import {Key} from './../fields/Key';
+import {ListField} from './../fields/ListField';
+import {NumberField} from './../fields/NumberField';
+import {RichTextField} from './../fields/RichTextField';
+import {TextField} from './../fields/TextField';
+import {Types} from './Message';
export class ServerUtils {
public static FromJson(json: any): Field {
@@ -40,6 +40,8 @@ export class ServerUtils {
return new Key(data, id, false)
case Types.Image:
return new ImageField(new URL(data), id, false)
+ case Types.PDF:
+ return new PDFField(new URL(data), id, false)
case Types.List:
return ListField.FromJson(id, data)
case Types.Ink:
diff --git a/src/typings/index.d.ts b/src/typings/index.d.ts
new file mode 100644
index 000000000..e4a66f7f2
--- /dev/null
+++ b/src/typings/index.d.ts
@@ -0,0 +1,322 @@
+/// <reference types="node" />
+
+declare module '@react-pdf/renderer' {
+ import * as React from 'react';
+
+ namespace ReactPDF {
+ interface Style {
+ [property: string]: any;
+ }
+ interface Styles {
+ [key: string]: Style;
+ }
+ type Orientation = 'portrait' | 'landscape';
+
+ interface DocumentProps {
+ title?: string;
+ author?: string;
+ subject?: string;
+ keywords?: string;
+ creator?: string;
+ producer?: string;
+ onRender?: () => any;
+ }
+
+ /**
+ * This component represent the PDF document itself. It must be the root
+ * of your tree element structure, and under no circumstances should it be
+ * used as children of another react-pdf component. In addition, it should
+ * only have childs of type <Page />.
+ */
+ class Document extends React.Component<DocumentProps> {}
+
+ interface NodeProps {
+ style?: Style | Style[];
+ /**
+ * Render component in all wrapped pages.
+ * @see https://react-pdf.org/advanced#fixed-components
+ */
+ fixed?: boolean;
+ /**
+ * Force the wrapping algorithm to start a new page when rendering the
+ * element.
+ * @see https://react-pdf.org/advanced#page-breaks
+ */
+ break?: boolean;
+ }
+
+ interface PageProps extends NodeProps {
+ /**
+ * Enable page wrapping for this page.
+ * @see https://react-pdf.org/components#page-wrapping
+ */
+ wrap?: boolean;
+ debug?: boolean;
+ size?: string | [number, number] | {width: number; height: number};
+ orientation?: Orientation;
+ ruler?: boolean;
+ rulerSteps?: number;
+ verticalRuler?: boolean;
+ verticalRulerSteps?: number;
+ horizontalRuler?: boolean;
+ horizontalRulerSteps?: number;
+ ref?: Page;
+ }
+
+ /**
+ * Represents single page inside the PDF document, or a subset of them if
+ * using the wrapping feature. A <Document /> can contain as many pages as
+ * you want, but ensure not rendering a page inside any component besides
+ * Document.
+ */
+ class Page extends React.Component<PageProps> {}
+
+ interface ViewProps extends NodeProps {
+ /**
+ * Enable/disable page wrapping for element.
+ * @see https://react-pdf.org/components#page-wrapping
+ */
+ wrap?: boolean;
+ debug?: boolean;
+ render?: (props: {pageNumber: number}) => React.ReactNode;
+ children?: React.ReactNode;
+ }
+
+ /**
+ * The most fundamental component for building a UI and is designed to be
+ * nested inside other views and can have 0 to many children.
+ */
+ class View extends React.Component<ViewProps> {}
+
+ interface ImageProps extends NodeProps {
+ debug?: boolean;
+ src: string | {data: Buffer; format: 'png' | 'jpg'};
+ cache?: boolean;
+ }
+
+ /**
+ * A React component for displaying network or local (Node only) JPG or
+ * PNG images, as well as base64 encoded image strings.
+ */
+ class Image extends React.Component<ImageProps> {}
+
+ interface TextProps extends NodeProps {
+ /**
+ * Enable/disable page wrapping for element.
+ * @see https://react-pdf.org/components#page-wrapping
+ */
+ wrap?: boolean;
+ debug?: boolean;
+ render?: (
+ props: {pageNumber: number; totalPages: number},
+ ) => React.ReactNode;
+ children?: React.ReactNode;
+ /**
+ * How much hyphenated breaks should be avoided.
+ */
+ hyphenationCallback?: number;
+ }
+
+ /**
+ * A React component for displaying text. Text supports nesting of other
+ * Text or Link components to create inline styling.
+ */
+ class Text extends React.Component<TextProps> {}
+
+ interface LinkProps extends NodeProps {
+ /**
+ * Enable/disable page wrapping for element.
+ * @see https://react-pdf.org/components#page-wrapping
+ */
+ wrap?: boolean;
+ debug?: boolean;
+ src: string;
+ children?: React.ReactNode;
+ }
+
+ /**
+ * A React component for displaying an hyperlink. Link’s can be nested
+ * inside a Text component, or being inside any other valid primitive.
+ */
+ class Link extends React.Component<LinkProps> {}
+
+ interface NoteProps extends NodeProps {
+ children: string;
+ }
+
+ class Note extends React.Component<NoteProps> {}
+
+ interface BlobProviderParams {
+ blob: Blob | null;
+ url: string | null;
+ loading: boolean;
+ error: Error | null;
+ }
+ interface BlobProviderProps {
+ document: React.ReactElement<DocumentProps>;
+ children: (params: BlobProviderParams) => React.ReactNode;
+ }
+
+ /**
+ * Easy and declarative way of getting document's blob data without
+ * showing it on screen.
+ * @see https://react-pdf.org/advanced#on-the-fly-rendering
+ * @platform web
+ */
+ class BlobProvider extends React.Component<BlobProviderProps> {}
+
+ interface PDFViewerProps {
+ width?: number;
+ height?: number;
+ style?: Style | Style[];
+ className?: string;
+ children?: React.ReactElement<DocumentProps>;
+ }
+
+ /**
+ * Iframe PDF viewer for client-side generated documents.
+ * @platform web
+ */
+ class PDFViewer extends React.Component<PDFViewerProps> {}
+
+ interface PDFDownloadLinkProps {
+ document: React.ReactElement<DocumentProps>;
+ fileName?: string;
+ style?: Style | Style[];
+ className?: string;
+ children?:
+ | React.ReactNode
+ | ((params: BlobProviderParams) => React.ReactNode);
+ }
+
+ /**
+ * Anchor tag to enable generate and download PDF documents on the fly.
+ * @see https://react-pdf.org/advanced#on-the-fly-rendering
+ * @platform web
+ */
+ class PDFDownloadLink extends React.Component<PDFDownloadLinkProps> {}
+
+ interface EmojiSource {
+ url: string;
+ format: string;
+ }
+ interface RegisteredFont {
+ src: string;
+ loaded: boolean;
+ loading: boolean;
+ data: any;
+ [key: string]: any;
+ }
+ type HyphenationCallback = (
+ words: string[],
+ glyphString: {[key: string]: any},
+ ) => string[];
+
+ const Font: {
+ register: (
+ src: string,
+ options: {family: string; [key: string]: any},
+ ) => void;
+ getEmojiSource: () => EmojiSource;
+ getRegisteredFonts: () => string[];
+ registerEmojiSource: (emojiSource: EmojiSource) => void;
+ registerHyphenationCallback: (
+ hyphenationCallback: HyphenationCallback,
+ ) => void;
+ getHyphenationCallback: () => HyphenationCallback;
+ getFont: (fontFamily: string) => RegisteredFont | undefined;
+ load: (
+ fontFamily: string,
+ document: React.ReactElement<DocumentProps>,
+ ) => Promise<void>;
+ clear: () => void;
+ reset: () => void;
+ };
+
+ const StyleSheet: {
+ hairlineWidth: number;
+ create: <TStyles>(styles: TStyles) => TStyles;
+ resolve: (
+ style: Style,
+ container: {
+ width: number;
+ height: number;
+ orientation: Orientation;
+ },
+ ) => Style;
+ flatten: (...styles: Style[]) => Style;
+ absoluteFillObject: {
+ position: 'absolute';
+ left: 0;
+ right: 0;
+ top: 0;
+ bottom: 0;
+ };
+ };
+
+ const version: any;
+
+ const PDFRenderer: any;
+
+ const createInstance: (
+ element: {
+ type: string;
+ props: {[key: string]: any};
+ },
+ root?: any,
+ ) => any;
+
+ const pdf: (
+ document: React.ReactElement<DocumentProps>,
+ ) => {
+ isDirty: () => boolean;
+ updateContainer: (document: React.ReactElement<any>) => void;
+ toBuffer: () => NodeJS.ReadableStream;
+ toBlob: () => Blob;
+ toString: () => string;
+ };
+
+ const renderToStream: (
+ document: React.ReactElement<DocumentProps>,
+ ) => NodeJS.ReadableStream;
+
+ const renderToFile: (
+ document: React.ReactElement<DocumentProps>,
+ filePath: string,
+ callback?: (output: NodeJS.ReadableStream, filePath: string) => any,
+ ) => Promise<NodeJS.ReadableStream>;
+
+ const render: typeof renderToFile;
+ }
+
+ const Document: typeof ReactPDF.Document;
+ const Page: typeof ReactPDF.Page;
+ const View: typeof ReactPDF.View;
+ const Image: typeof ReactPDF.Image;
+ const Text: typeof ReactPDF.Text;
+ const Link: typeof ReactPDF.Link;
+ const Note: typeof ReactPDF.Note;
+ const Font: typeof ReactPDF.Font;
+ const StyleSheet: typeof ReactPDF.StyleSheet;
+ const createInstance: typeof ReactPDF.createInstance;
+ const PDFRenderer: typeof ReactPDF.PDFRenderer;
+ const version: typeof ReactPDF.version;
+ const pdf: typeof ReactPDF.pdf;
+
+ export default ReactPDF;
+ export {
+ Document,
+ Page,
+ View,
+ Image,
+ Text,
+ Link,
+ Note,
+ Font,
+ StyleSheet,
+ createInstance,
+ PDFRenderer,
+ version,
+ pdf,
+ };
+ } \ No newline at end of file