From 45c2bf0a22ae83a65d91f11934e1c21770b897c7 Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 15 Sep 2020 12:06:15 -0400 Subject: simplifying menus for annotations. added target toggle option to PDFmenu --- src/client/views/pdf/Annotation.tsx | 11 +++++ src/client/views/pdf/PDFMenu.tsx | 89 +++++++++++++++---------------------- src/client/views/pdf/PDFViewer.tsx | 2 +- 3 files changed, 48 insertions(+), 54 deletions(-) (limited to 'src/client/views/pdf') diff --git a/src/client/views/pdf/Annotation.tsx b/src/client/views/pdf/Annotation.tsx index 5ec564e7b..78438e7e3 100644 --- a/src/client/views/pdf/Annotation.tsx +++ b/src/client/views/pdf/Annotation.tsx @@ -8,6 +8,7 @@ import { Cast, FieldValue, NumCast, StrCast, PromiseValue } from "../../../field import { DocumentManager } from "../../util/DocumentManager"; import { PDFMenu } from "./PDFMenu"; import "./Annotation.scss"; +import { undoBatch } from "../../util/UndoManager"; interface IAnnotationProps { anno: Doc; @@ -86,6 +87,14 @@ class RegionAnnotation extends React.Component { group && this.props.pinToPres(group, isPinned); } + @undoBatch + makePushpin = action(() => { + const group = Cast(this.props.document.group, Doc, null); + group.isPushpin = !group.isPushpin; + }) + + isPushpin = () => Cast(this.props.document.group, Doc, null).isPushpin; + @action onPointerDown = (e: React.PointerEvent) => { if (e.button === 2 || e.ctrlKey) { @@ -94,6 +103,8 @@ class RegionAnnotation extends React.Component { PDFMenu.Instance.Pinned = false; PDFMenu.Instance.AddTag = this.addTag.bind(this); PDFMenu.Instance.PinToPres = this.pinToPres; + PDFMenu.Instance.MakePushpin = this.makePushpin; + PDFMenu.Instance.IsPushpin = this.isPushpin; PDFMenu.Instance.jumpTo(e.clientX, e.clientY, true); e.stopPropagation(); } diff --git a/src/client/views/pdf/PDFMenu.tsx b/src/client/views/pdf/PDFMenu.tsx index c5ed75980..1a5b14e07 100644 --- a/src/client/views/pdf/PDFMenu.tsx +++ b/src/client/views/pdf/PDFMenu.tsx @@ -1,15 +1,15 @@ import React = require("react"); import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { Tooltip } from "@material-ui/core"; import { action, computed, observable } from "mobx"; import { observer } from "mobx-react"; import { ColorState } from "react-color"; import { Doc, Opt } from "../../../fields/Doc"; -import { returnFalse, unimplementedFunction, Utils } from "../../../Utils"; +import { returnFalse, setupMoveUpEvents, unimplementedFunction, Utils } from "../../../Utils"; import { AntimodeMenu, AntimodeMenuProps } from "../AntimodeMenu"; import { ButtonDropdown } from "../nodes/formattedText/RichTextMenu"; import "./PDFMenu.scss"; - @observer export class PDFMenu extends AntimodeMenu { static Instance: PDFMenu; @@ -46,6 +46,8 @@ export class PDFMenu extends AntimodeMenu { public Delete: () => void = unimplementedFunction; public AddTag: (key: string, value: string) => boolean = returnFalse; public PinToPres: () => void = unimplementedFunction; + public MakePushpin: () => void = unimplementedFunction; + public IsPushpin: () => boolean = returnFalse; public Marquee: { left: number; top: number; width: number; height: number; } | undefined; public get Active() { return this._left > 0; } @@ -57,31 +59,10 @@ export class PDFMenu extends AntimodeMenu { } pointerDown = (e: React.PointerEvent) => { - document.removeEventListener("pointermove", this.pointerMove); - document.addEventListener("pointermove", this.pointerMove); - document.removeEventListener("pointerup", this.pointerUp); - document.addEventListener("pointerup", this.pointerUp); - - e.stopPropagation(); - e.preventDefault(); - } - - pointerMove = (e: PointerEvent) => { - e.stopPropagation(); - e.preventDefault(); - - if (!this._dragging) { + setupMoveUpEvents(this, e, (e: PointerEvent) => { this.StartDrag(e, this._commentCont.current!); - this._dragging = true; - } - } - - pointerUp = (e: PointerEvent) => { - this._dragging = false; - document.removeEventListener("pointermove", this.pointerMove); - document.removeEventListener("pointerup", this.pointerUp); - e.stopPropagation(); - e.preventDefault(); + return true; + }, returnFalse, returnFalse); } @action @@ -93,7 +74,7 @@ export class PDFMenu extends AntimodeMenu { @computed get highlighter() { const button = - ; @@ -112,12 +93,13 @@ export class PDFMenu extends AntimodeMenu { ; return ( - + {"Click to Highlight"}}> + + ); } - @action - changeHighlightColor = (color: string, e: React.PointerEvent) => { + @action changeHighlightColor = (color: string, e: React.PointerEvent) => { const col: ColorState = { hex: color, hsl: { a: 0, h: 0, s: 0, l: 0, source: "" }, hsv: { a: 0, h: 0, s: 0, v: 0, source: "" }, rgb: { a: 0, r: 0, b: 0, g: 0, source: "" }, oldHue: 0, source: "", @@ -127,25 +109,11 @@ export class PDFMenu extends AntimodeMenu { this.highlightColor = Utils.colorString(col); } - deleteClicked = (e: React.PointerEvent) => { - this.Delete(); - } - - @action - keyChanged = (e: React.ChangeEvent) => { - this._keyValue = e.currentTarget.value; - } - - @action - valueChanged = (e: React.ChangeEvent) => { - this._valueValue = e.currentTarget.value; - } - - @action - addTag = (e: React.PointerEvent) => { + @action keyChanged = (e: React.ChangeEvent) => { this._keyValue = e.currentTarget.value; } + @action valueChanged = (e: React.ChangeEvent) => { this._valueValue = e.currentTarget.value; } + @action addTag = (e: React.PointerEvent) => { if (this._keyValue.length > 0 && this._valueValue.length > 0) { this._added = this.AddTag(this._keyValue, this._valueValue); - setTimeout(action(() => this._added = false), 1000); } } @@ -154,13 +122,28 @@ export class PDFMenu extends AntimodeMenu { const buttons = this.Status === "pdf" ? [ this.highlighter, - , + + {"Drag to Place Annotation"}}> + + , ] : [ - , - , + {"Remove Link Anchor"}}> + + , + {"Pin to Presentation"}}> + + , + {"toggle pushpin behavior"}}> + + , //
// // diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 79bd190c5..45a862954 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -697,7 +697,7 @@ export class PDFViewer extends ViewBoxAnnotatableComponent this._pageSizes.length && this._pageSizes[0] ? this._pageSizes[0].width : (this.Document._nativeWidth || 0); @computed get overlayLayer() { return
+ style={{ pointerEvents: SnappingManager.GetIsDragging() ? "all" : undefined, transform: `scale(${this._zoomed})` }}>