From 146f8622d5bac2edc6b09f57c173bd057dfbcfad Mon Sep 17 00:00:00 2001 From: bobzel Date: Fri, 8 Jul 2022 00:17:26 -0400 Subject: restructured currentUserUtils to avoid having import cycles. --- src/client/views/pdf/Annotation.tsx | 108 +++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 52 deletions(-) (limited to 'src/client/views/pdf/Annotation.tsx') diff --git a/src/client/views/pdf/Annotation.tsx b/src/client/views/pdf/Annotation.tsx index 5bdce273d..44f815336 100644 --- a/src/client/views/pdf/Annotation.tsx +++ b/src/client/views/pdf/Annotation.tsx @@ -1,15 +1,15 @@ -import React = require("react"); -import { action, computed, IReactionDisposer, observable, reaction, runInAction } from "mobx"; -import { observer } from "mobx-react"; -import { Doc, DocListCast, Opt } from "../../../fields/Doc"; -import { Id } from "../../../fields/FieldSymbols"; -import { List } from "../../../fields/List"; -import { BoolCast, Cast, NumCast, StrCast } from "../../../fields/Types"; -import { LinkManager } from "../../util/LinkManager"; -import { undoBatch } from "../../util/UndoManager"; -import { FieldViewProps } from "../nodes/FieldView"; -import { AnchorMenu } from "./AnchorMenu"; -import "./Annotation.scss"; +import React = require('react'); +import { action, computed, IReactionDisposer, observable, reaction, runInAction } from 'mobx'; +import { observer } from 'mobx-react'; +import { Doc, DocListCast, Opt } from '../../../fields/Doc'; +import { Id } from '../../../fields/FieldSymbols'; +import { List } from '../../../fields/List'; +import { BoolCast, Cast, NumCast, StrCast } from '../../../fields/Types'; +import { LinkFollower } from '../../util/LinkFollower'; +import { undoBatch } from '../../util/UndoManager'; +import { FieldViewProps } from '../nodes/FieldView'; +import { AnchorMenu } from './AnchorMenu'; +import './Annotation.scss'; interface IAnnotationProps extends FieldViewProps { anno: Doc; @@ -19,14 +19,15 @@ interface IAnnotationProps extends FieldViewProps { pointerEvents?: () => Opt; } @observer -export - class Annotation extends React.Component { +export class Annotation extends React.Component { render() { - return
- {DocListCast(this.props.anno.textInlineAnnotations).map(a => - - )} -
; + return ( +
+ {DocListCast(this.props.anno.textInlineAnnotations).map(a => ( + + ))} +
+ ); } } @@ -38,7 +39,9 @@ interface IRegionAnnotationProps extends IAnnotationProps { class RegionAnnotation extends React.Component { private _mainCont: React.RefObject = React.createRef(); - @computed get annoTextRegion() { return Cast(this.props.document.annoTextRegion, Doc, null) || this.props.document; } + @computed get annoTextRegion() { + return Cast(this.props.document.annoTextRegion, Doc, null) || this.props.document; + } @undoBatch deleteAnnotation = () => { @@ -46,20 +49,20 @@ class RegionAnnotation extends React.Component { this.props.dataDoc[this.props.fieldKey] = new List(docAnnotations.filter(a => a !== this.annoTextRegion)); AnchorMenu.Instance.fadeOut(true); this.props.select(false); - } + }; @undoBatch - pinToPres = () => this.props.pinToPres(this.annoTextRegion) + pinToPres = () => this.props.pinToPres(this.annoTextRegion); @undoBatch - makePushpin = () => this.annoTextRegion.isPushpin = !this.annoTextRegion.isPushpin + makePushpin = () => (this.annoTextRegion.isPushpin = !this.annoTextRegion.isPushpin); isPushpin = () => BoolCast(this.annoTextRegion.isPushpin); @action onPointerDown = (e: React.PointerEvent) => { if (e.button === 2 || e.ctrlKey) { - AnchorMenu.Instance.Status = "annotation"; + AnchorMenu.Instance.Status = 'annotation'; AnchorMenu.Instance.Delete = this.deleteAnnotation.bind(this); AnchorMenu.Instance.Pinned = false; AnchorMenu.Instance.AddTag = this.addTag.bind(this); @@ -68,42 +71,43 @@ class RegionAnnotation extends React.Component { AnchorMenu.Instance.IsPushpin = this.isPushpin; AnchorMenu.Instance.jumpTo(e.clientX, e.clientY, true); e.stopPropagation(); - } - else if (e.button === 0) { + } else if (e.button === 0) { e.stopPropagation(); - LinkManager.FollowLink(undefined, this.annoTextRegion, this.props, false); + LinkFollower.FollowLink(undefined, this.annoTextRegion, this.props, false); } - } + }; addTag = (key: string, value: string): boolean => { const valNum = parseInt(value); this.annoTextRegion[key] = isNaN(valNum) ? value : valNum; return true; - } + }; render() { const brushed = this.annoTextRegion && Doc.isBrushedHighlightedDegree(this.annoTextRegion); - return (
{ - Doc.BrushDoc(this.props.anno); - this.props.showInfo(this.props.anno); - })} - onPointerLeave={action(() => { - Doc.UnBrushDoc(this.props.anno); - this.props.showInfo(undefined); - })} - onPointerDown={this.onPointerDown} - style={{ - left: NumCast(this.props.document.x), - top: NumCast(this.props.document.y), - width: NumCast(this.props.document._width), - height: NumCast(this.props.document._height), - opacity: brushed === Doc.DocBrushStatus.highlighted ? 0.5 : undefined, - pointerEvents: this.props.pointerEvents?.() as any, - outline: brushed === Doc.DocBrushStatus.linkHighlighted ? "solid 1px lightBlue" : undefined, - backgroundColor: brushed === Doc.DocBrushStatus.highlighted ? "orange" : - StrCast(this.props.document.backgroundColor), - }} > -
); + return ( +
{ + Doc.BrushDoc(this.props.anno); + this.props.showInfo(this.props.anno); + })} + onPointerLeave={action(() => { + Doc.UnBrushDoc(this.props.anno); + this.props.showInfo(undefined); + })} + onPointerDown={this.onPointerDown} + style={{ + left: NumCast(this.props.document.x), + top: NumCast(this.props.document.y), + width: NumCast(this.props.document._width), + height: NumCast(this.props.document._height), + opacity: brushed === Doc.DocBrushStatus.highlighted ? 0.5 : undefined, + pointerEvents: this.props.pointerEvents?.() as any, + outline: brushed === Doc.DocBrushStatus.linkHighlighted ? 'solid 1px lightBlue' : undefined, + backgroundColor: brushed === Doc.DocBrushStatus.highlighted ? 'orange' : StrCast(this.props.document.backgroundColor), + }}>
+ ); } -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2