aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts6
-rw-r--r--src/client/util/TooltipTextMenu.tsx6
-rw-r--r--src/client/views/GlobalKeyHandler.ts2
-rw-r--r--src/client/views/nodes/FormattedTextBox.tsx84
-rw-r--r--src/client/views/nodes/PDFBox.tsx16
-rw-r--r--src/client/views/pdf/PDFViewer.tsx53
-rw-r--r--src/client/views/pdf/Page.tsx12
7 files changed, 157 insertions, 22 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index e6fe1b8b3..ee1b9fd0d 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -582,12 +582,12 @@ export namespace Docs {
export namespace DocUtils {
export function MakeLink(source: Doc, target: Doc, targetContext?: Doc, title: string = "", description: string = "", tags: string = "Default", sourceContext?: Doc) {
- if (LinkManager.Instance.doesLinkExist(source, target)) return;
+ if (LinkManager.Instance.doesLinkExist(source, target)) return undefined;
let sv = DocumentManager.Instance.getDocumentView(source);
if (sv && sv.props.ContainingCollectionView && sv.props.ContainingCollectionView.props.Document === target) return;
- if (target === CurrentUserUtils.UserDocument) return;
+ if (target === CurrentUserUtils.UserDocument) return undefined;
- let linkDoc;
+ let linkDoc: Doc | undefined;
UndoManager.RunInBatch(() => {
linkDoc = Docs.Create.TextDocument({ width: 100, height: 30, borderRounding: "100%" });
linkDoc.type = DocumentType.LINK;
diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx
index a4c053de2..6214b568c 100644
--- a/src/client/util/TooltipTextMenu.tsx
+++ b/src/client/util/TooltipTextMenu.tsx
@@ -1,6 +1,6 @@
import { action } from "mobx";
import { Dropdown, MenuItem, icons, } from "prosemirror-menu"; //no import css
-import { EditorState, NodeSelection, TextSelection } from "prosemirror-state";
+import { EditorState, NodeSelection, TextSelection, Transaction } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
import { schema } from "./RichTextSchema";
import { Schema, NodeType, MarkType, Mark, ResolvedPos } from "prosemirror-model";
@@ -321,6 +321,10 @@ export class TooltipTextMenu {
}
}
+ makeLinkWithState = (state: EditorState, target: string, location: string) => {
+ let link = state.schema.mark(state.schema.marks.link, { href: target, location: location });
+ }
+
makeLink = (target: string, location: string) => {
let node = this.view.state.selection.$from.nodeAfter;
let link = this.view.state.schema.mark(this.view.state.schema.marks.link, { href: target, location: location });
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index 5050f34ab..d52c05b2f 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -152,9 +152,9 @@ export default class KeyManager {
stopPropagation = false;
break;
case "a":
- case "c":
case "v":
case "x":
+ case "c":
stopPropagation = false;
preventDefault = false;
break;
diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index d5f539194..f019868aa 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -5,17 +5,17 @@ import { observer } from "mobx-react";
import { baseKeymap } from "prosemirror-commands";
import { history } from "prosemirror-history";
import { keymap } from "prosemirror-keymap";
+import { EditorState, Plugin, Transaction, Selection } from "prosemirror-state";
import { NodeType, Slice, Node, Fragment } from 'prosemirror-model';
-import { EditorState, Plugin, Transaction } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
-import { Doc, Opt } from "../../../new_fields/Doc";
+import { Doc, Opt, DocListCast } from "../../../new_fields/Doc";
import { Id, Copy } from '../../../new_fields/FieldSymbols';
import { List } from '../../../new_fields/List';
import { RichTextField } from "../../../new_fields/RichTextField";
import { createSchema, listSpec, makeInterface } from "../../../new_fields/Schema";
import { BoolCast, Cast, NumCast, StrCast, DateCast } from "../../../new_fields/Types";
import { DocServer } from "../../DocServer";
-import { Docs } from '../../documents/Documents';
+import { Docs, DocUtils } from '../../documents/Documents';
import { DocumentManager } from '../../util/DocumentManager';
import { DragManager } from "../../util/DragManager";
import buildKeymap from "../../util/ProsemirrorExampleTransfer";
@@ -122,12 +122,40 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
if (this.props.isOverlay) {
DragManager.StartDragFunctions.push(() => FormattedTextBox.InputBoxOverlay = undefined);
}
+
+ document.addEventListener("paste", this.paste);
}
@computed get extensionDoc() { return Doc.resolvedFieldDataDoc(this.dataDoc, this.props.fieldKey, "dummy"); }
@computed get dataDoc() { return BoolCast(this.props.Document.isTemplate) && this.props.DataDoc ? this.props.DataDoc : Doc.GetProto(this.props.Document); }
+ paste = (e: ClipboardEvent) => {
+ if (e.clipboardData && this._editorView) {
+ let pdfPasteText = `${Utils.GenerateDeterministicGuid("pdf paste")}`;
+ for (let i = 0; i < e.clipboardData.items.length; i++) {
+ let item = e.clipboardData.items.item(i);
+ if (item.type === "text/plain") {
+ item.getAsString((text) => {
+ let pdfPasteIndex = text.indexOf(pdfPasteText);
+ if (pdfPasteIndex > -1) {
+ let insertText = text.substr(0, pdfPasteIndex);
+ const tx = this._editorView!.state.tr.insertText(insertText);
+ // tx.setSelection(new Selection(tx.))
+ const state = this._editorView!.state;
+ this._editorView!.dispatch(tx);
+ if (this._toolTipTextMenu) {
+ // this._toolTipTextMenu.makeLinkWithState(state)
+ }
+ e.stopPropagation();
+ e.preventDefault();
+ }
+ });
+ }
+ }
+ }
+ }
+
dispatchTransaction = (tx: Transaction) => {
if (this._editorView) {
const state = this._editorView.state.apply(tx);
@@ -272,7 +300,48 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
}
handlePaste = (view: EditorView, event: Event, slice: Slice): boolean => {
- return false;
+ let cbe = event as ClipboardEvent;
+ let docId: string;
+ let regionId: string;
+ if (!cbe.clipboardData) {
+ return false;
+ }
+ let linkId: string;
+ docId = cbe.clipboardData.getData("dash/pdfOrigin");
+ regionId = cbe.clipboardData.getData("dash/pdfRegion");
+ if (!docId || !regionId) {
+ return false;
+ }
+
+ DocServer.GetRefField(docId).then(doc => {
+ DocServer.GetRefField(regionId).then(region => {
+ if (!(doc instanceof Doc) || !(region instanceof Doc)) {
+ return;
+ }
+
+ let annotations = DocListCast(region.annotations);
+ annotations.forEach(anno => anno.target = this.props.Document);
+ let fieldExtDoc = Doc.resolvedFieldDataDoc(doc, "data", "true");
+ let targetAnnotations = DocListCast(fieldExtDoc.annotations);
+ if (targetAnnotations) {
+ targetAnnotations.push(region);
+ fieldExtDoc.annotations = new List<Doc>(targetAnnotations);
+ }
+
+ let link = DocUtils.MakeLink(this.props.Document, region);
+ if (link) {
+ cbe.clipboardData!.setData("dash/linkDoc", link[Id]);
+ linkId = link[Id];
+ let frag = addMarkToFrag(slice.content);
+ slice = new Slice(frag, slice.openStart, slice.openEnd);
+ var tr = view.state.tr.replaceSelection(slice);
+ view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste"));
+ }
+ });
+ });
+
+ return true;
+
function addMarkToFrag(frag: Fragment) {
const nodes: Node[] = [];
frag.forEach(node => nodes.push(addLinkMark(node)));
@@ -285,7 +354,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
}
const marks = [...node.marks];
const linkIndex = marks.findIndex(mark => mark.type.name === "link");
- const link = view.state.schema.mark(view.state.schema.marks.link, { href: "http://localhost:1050/doc/[link document id]", location: "onRight" });
+ const link = view.state.schema.mark(view.state.schema.marks.link, { href: `http://localhost:1050/doc/${linkId}`, location: "onRight" });
if (linkIndex !== -1) {
marks.splice(linkIndex, 1, link);
} else {
@@ -293,11 +362,6 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
}
return node.mark(marks);
}
- let frag = addMarkToFrag(slice.content);
- slice = new Slice(frag, slice.openStart, slice.openEnd);
- var tr = view.state.tr.replaceSelection(slice);
- view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste"));
- return true;
}
private setupEditor(config: any, doc: Doc, fieldKey: string) {
diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx
index 5a5e6e6dd..f527c0595 100644
--- a/src/client/views/nodes/PDFBox.tsx
+++ b/src/client/views/nodes/PDFBox.tsx
@@ -24,6 +24,8 @@ import { Flyout, anchorPoints } from '../DocumentDecorations';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { ScriptField } from '../../../new_fields/ScriptField';
import { KeyCodes } from '../../northstar/utils/KeyCodes';
+import { Utils } from '../../../Utils';
+import { Id } from '../../../new_fields/FieldSymbols';
type PdfDocument = makeInterface<[typeof positionSchema, typeof pageSchema]>;
const PdfDocument = makeInterface(positionSchema, pageSchema);
@@ -67,10 +69,24 @@ export class PDFBox extends DocComponent<FieldViewProps, PdfDocument>(PdfDocumen
componentDidMount() {
if (this.props.setPdfBox) this.props.setPdfBox(this);
+
+ document.removeEventListener("copy", this.copy);
+ document.addEventListener("copy", this.copy);
}
componentWillUnmount() {
this._reactionDisposer && this._reactionDisposer();
+ document.removeEventListener("copy", this.copy);
+ }
+
+ private copy = (e: ClipboardEvent) => {
+ if (this.props.active()) {
+ if (e.clipboardData) {
+ e.clipboardData.setData("text/plain", text);
+ e.clipboardData.setData("dash/pdfOrigin", this.props.Document[Id]);
+ e.preventDefault();
+ }
+ }
}
public GetPage() {
diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index b7ded7e06..6fef8a4de 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -20,6 +20,7 @@ import { ScriptField } from "../../../new_fields/ScriptField";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import Annotation from "./Annotation";
import { KeyCodes } from "../../northstar/utils/KeyCodes";
+import { DocServer } from "../../DocServer";
const PDFJSViewer = require("pdfjs-dist/web/pdf_viewer");
export const scale = 2;
@@ -91,6 +92,7 @@ export class Viewer extends React.Component<IViewerProps> {
// private _textContent: Pdfjs.TextContent[] = [];
private _pdfFindController: any;
private _searchString: string = "";
+ private _selectionText: string = "";
constructor(props: IViewerProps) {
super(props);
@@ -101,6 +103,10 @@ export class Viewer extends React.Component<IViewerProps> {
this._mainCont = React.createRef();
}
+ setSelectionText = (text: string) => {
+ this._selectionText = text;
+ }
+
componentDidUpdate = (prevProps: IViewerProps) => {
if (this.scrollY !== prevProps.scrollY) {
this.renderPages();
@@ -156,6 +162,9 @@ export class Viewer extends React.Component<IViewerProps> {
if (this._mainCont.current) {
this._dropDisposer = this._mainCont.current && DragManager.MakeDropTarget(this._mainCont.current, { handlers: { drop: this.drop.bind(this) } });
}
+
+ document.removeEventListener("copy", this.copy);
+ document.addEventListener("copy", this.copy);
}
componentWillUnmount = () => {
@@ -163,6 +172,42 @@ export class Viewer extends React.Component<IViewerProps> {
this._annotationReactionDisposer && this._annotationReactionDisposer();
this._filterReactionDisposer && this._filterReactionDisposer();
this._dropDisposer && this._dropDisposer();
+ document.removeEventListener("copy", this.copy);
+ }
+
+ private copy = (e: ClipboardEvent) => {
+ if (this.props.parent.props.active()) {
+ let text = this._selectionText;
+ if (e.clipboardData) {
+ e.clipboardData.setData("text/plain", text);
+ e.clipboardData.setData("dash/pdfOrigin", this.props.parent.props.Document[Id]);
+ let annoDoc = this.makeAnnotationDocument(undefined, 0, "#0390fc");
+ e.clipboardData.setData("dash/pdfRegion", annoDoc[Id]);
+ e.preventDefault();
+ }
+ }
+ // let targetAnnotations = DocListCast(this.props.parent.fieldExtensionDoc.annotations);
+ // if (targetAnnotations) {
+ // targetAnnotations.push(destDoc);
+ // }
+ }
+
+ paste = (e: ClipboardEvent) => {
+ if (e.clipboardData) {
+ if (e.clipboardData.getData("dash/pdfOrigin") === this.props.parent.props.Document[Id]) {
+ let linkDocId = e.clipboardData.getData("dash/linkDoc");
+ if (linkDocId) {
+ DocServer.GetRefField(linkDocId).then(async (link) => {
+ if (!(link instanceof Doc)) {
+ return;
+ }
+ let proto = Doc.GetProto(link);
+ let source = await Cast(proto.anchor1, Doc);
+ proto.anchor2 = this.makeAnnotationDocument(source, 0, "#0390fc", false);
+ });
+ }
+ }
+ }
}
scrollTo(y: number) {
@@ -213,7 +258,7 @@ export class Viewer extends React.Component<IViewerProps> {
}
@action
- makeAnnotationDocument = (sourceDoc: Doc | undefined, s: number, color: string): Doc => {
+ makeAnnotationDocument = (sourceDoc: Doc | undefined, s: number, color: string, createLink: boolean = true): Doc => {
let annoDocs: Doc[] = [];
let mainAnnoDoc = Docs.Create.InstanceFromProto(new Doc(), "", {});
@@ -242,7 +287,7 @@ export class Viewer extends React.Component<IViewerProps> {
mainAnnoDoc.y = Math.max(minY, 0);
mainAnnoDoc.annotations = new List<Doc>(annoDocs);
- if (sourceDoc) {
+ if (sourceDoc && createLink) {
DocUtils.MakeLink(sourceDoc, mainAnnoDoc, undefined, `Annotation from ${StrCast(this.props.parent.Document.title)}`, "", StrCast(this.props.parent.Document.title));
}
this._savedAnnotations.clear();
@@ -258,7 +303,6 @@ export class Viewer extends React.Component<IViewerProps> {
let targetAnnotations = DocListCast(this.props.parent.fieldExtensionDoc.annotations);
if (targetAnnotations) {
targetAnnotations.push(destDoc);
- this.props.parent.fieldExtensionDoc.annotations = new List<Doc>(targetAnnotations);
}
else {
this.props.parent.fieldExtensionDoc.annotations = new List<Doc>([destDoc]);
@@ -292,6 +336,7 @@ export class Viewer extends React.Component<IViewerProps> {
this._isPage[page] = "page";
this._visibleElements[page] = (
<Page
+ setSelectionText={this.setSelectionText}
size={this._pageSizes[page]}
pdf={this.props.pdf}
page={page}
@@ -611,7 +656,7 @@ export class Viewer extends React.Component<IViewerProps> {
<div className="viewer" style={this._searching ? { position: "absolute", top: 0 } : {}}>
{this._visibleElements}
</div>
- <div className="pdfViewer-text" ref={this._viewer} style={{ transform: "scale(1.5)", transformOrigin: "top left" }} />
+ <div className="pdfViewer-text" ref={this._viewer} onCopy={() => console.log("gello world")} style={{ transform: "scale(1.5)", transformOrigin: "top left" }} />
<div className="pdfViewer-annotationLayer"
style={{
height: this.props.parent.Document.nativeHeight, width: `100%`,
diff --git a/src/client/views/pdf/Page.tsx b/src/client/views/pdf/Page.tsx
index a6864e0f3..c205617b4 100644
--- a/src/client/views/pdf/Page.tsx
+++ b/src/client/views/pdf/Page.tsx
@@ -29,6 +29,7 @@ interface IPageProps {
createAnnotation: (div: HTMLDivElement, page: number) => void;
makeAnnotationDocuments: (doc: Doc | undefined, scale: number, color: string, linkTo: boolean) => Doc;
getScrollFromPage: (page: number) => number;
+ setSelectionText: (text: string) => void;
}
@observer
@@ -353,7 +354,8 @@ export default class Page extends React.Component<IPageProps> {
else {
let sel = window.getSelection();
if (sel && sel.type === "Range") {
- this.createTextAnnotation(sel);
+ let selRange = sel.getRangeAt(0);
+ this.createTextAnnotation(sel, selRange);
PDFMenu.Instance.jumpTo(e.clientX, e.clientY);
}
}
@@ -371,8 +373,8 @@ export default class Page extends React.Component<IPageProps> {
}
@action
- createTextAnnotation = (sel: Selection) => {
- let clientRects = sel.getRangeAt(0).getClientRects();
+ createTextAnnotation = (sel: Selection, selRange: Range) => {
+ let clientRects = selRange.getClientRects();
if (this._textLayer.current) {
let boundingRect = this._textLayer.current.getBoundingClientRect();
for (let i = 0; i < clientRects.length; i++) {
@@ -389,6 +391,10 @@ export default class Page extends React.Component<IPageProps> {
}
}
}
+ let text = selRange.extractContents().textContent;
+ if (text) {
+ this.props.setSelectionText(text);
+ }
// clear selection
if (sel.empty) { // Chrome
sel.empty();