From f8da2a897de4d737ac3ea697b58d06bba5ce9f66 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Sun, 20 Oct 2019 15:15:15 -0400 Subject: working version of updated template refactoring --- src/client/views/nodes/DocumentContentsView.tsx | 7 ++- src/client/views/nodes/DocumentView.tsx | 2 +- src/client/views/nodes/ImageBox.tsx | 83 ++++++++++--------------- src/client/views/nodes/PDFBox.tsx | 8 +-- src/client/views/nodes/VideoBox.tsx | 37 ++++++----- src/client/views/pdf/PDFViewer.tsx | 63 ++++++++++--------- src/new_fields/Doc.ts | 2 +- 7 files changed, 96 insertions(+), 106 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx index 7aed416f4..779d25cdd 100644 --- a/src/client/views/nodes/DocumentContentsView.tsx +++ b/src/client/views/nodes/DocumentContentsView.tsx @@ -56,6 +56,7 @@ export class DocumentContentsView extends React.Component { @computed get layout(): string { + if (!this.layoutDoc) return "

awaiting layout

"; const layout = Cast(this.layoutDoc[this.props.layoutKey], "string"); if (layout === undefined) { return this.props.Document.data ? @@ -69,14 +70,16 @@ export class DocumentContentsView extends React.Component(Docu let preventDefault = true; if (this._doubleTap && this.props.renderDepth && (!this.onClickHandler || !this.onClickHandler.script)) { // disable double-click to show full screen for things that have an on click behavior since clicking them twice can be misinterpreted as a double click let fullScreenAlias = Doc.MakeAlias(this.props.Document); - if (StrCast(fullScreenAlias.layoutKey) !== "layoutCustom" && fullScreenAlias["layoutCustom"] !== undefined) { + if (StrCast(fullScreenAlias.layoutKey) !== "layoutCustom" && fullScreenAlias.layoutCustom !== undefined) { fullScreenAlias.layoutKey = "layoutCustom"; } this.props.addDocTab(fullScreenAlias, undefined, "inTab"); diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index dc80af268..f3ba968f5 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -39,7 +39,8 @@ library.add(faFileAudio, faAsterisk); export const pageSchema = createSchema({ curPage: "number", - fitWidth: "boolean" + fitWidth: "boolean", + rotation: "number" }); interface Window { @@ -178,18 +179,17 @@ export class ImageBox extends DocAnnotatableComponent { - let nw = this.layoutDoc.nativeWidth; - let nh = this.layoutDoc.nativeHeight; - let w = this.layoutDoc.width; - let h = this.layoutDoc.height; - this.layoutDoc.rotation = (NumCast(this.layoutDoc.rotation) + 90) % 360; - this.layoutDoc.nativeWidth = nh; - this.layoutDoc.nativeHeight = nw; - this.layoutDoc.width = h; - this.layoutDoc.height = w; + let nw = this.Document.nativeWidth; + let nh = this.Document.nativeHeight; + let w = this.Document.width; + let h = this.Document.height; + this.Document.rotation = ((this.Document.rotation || 0) + 90) % 360; + this.Document.nativeWidth = nh; + this.Document.nativeHeight = nw; + this.Document.width = h; + this.Document.height = w; }); specificContextMenu = (e: React.MouseEvent): void => { @@ -251,7 +251,7 @@ export class ImageBox extends DocAnnotatableComponent @@ -291,17 +291,17 @@ export class ImageBox extends DocAnnotatableComponent { requestImageSize(srcpath) .then((size: any) => { let rotation = NumCast(this.dataDoc.rotation) % 180; let realsize = rotation === 90 || rotation === 270 ? { height: size.width, width: size.height } : size; let aspect = realsize.height / realsize.width; - if (layoutdoc.width && (Math.abs(1 - NumCast(layoutdoc.height) / NumCast(layoutdoc.width) / (realsize.height / realsize.width)) > 0.1)) { + if (this.Document.width && (Math.abs(1 - NumCast(this.Document.height) / NumCast(this.Document.width) / (realsize.height / realsize.width)) > 0.1)) { setTimeout(action(() => { - layoutdoc.height = layoutdoc[WidthSym]() * aspect; - layoutdoc.nativeHeight = realsize.height; - layoutdoc.nativeWidth = realsize.width; + this.Document.height = this.Document[WidthSym]() * aspect; + this.Document.nativeHeight = realsize.height; + this.Document.nativeWidth = realsize.width; }), 0); } }) @@ -346,41 +346,24 @@ export class ImageBox extends DocAnnotatableComponent { - this.recordAudioAnnotation(); - } + audioDown = () => this.recordAudioAnnotation(); considerGooglePhotosLink = () => { const remoteUrl = StrCast(this.props.Document.googlePhotosUrl); - if (remoteUrl) { - return ( - window.open(remoteUrl)} - /> - ); - } - return (null); + return !remoteUrl ? (null) : ( window.open(remoteUrl)} + />); } considerGooglePhotosTags = () => { const tags = StrCast(this.props.Document.googlePhotosTags); - if (tags) { - return ( - - ); - } - return (null); + return !tags ? (null) : (); } - content(layoutDoc: Doc) { - if (!layoutDoc) return (null); + @computed get content() { console.log("REDOING IMAGE CONTENT"); // let transform = this.props.ScreenToLocalTransform().inverse(); let pw = typeof this.props.PanelWidth === "function" ? this.props.PanelWidth() : typeof this.props.PanelWidth === "number" ? (this.props.PanelWidth as any) as number : 50; @@ -388,8 +371,8 @@ export class ImageBox extends DocAnnotatableComponent 20) { @@ -403,13 +386,13 @@ export class ImageBox extends DocAnnotatableComponent - {() => [this.content(this.layoutDoc)]} + {() => [this.content]} ); } diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx index f3ea8328b..4513117b2 100644 --- a/src/client/views/nodes/PDFBox.tsx +++ b/src/client/views/nodes/PDFBox.tsx @@ -65,13 +65,11 @@ export class PDFBox extends DocAnnotatableComponent }, { fireImmediately: true }); } - get layoutDoc() { return Doc.Layout(this.props.Document); } - loaded = (nw: number, nh: number, np: number) => { this.dataDoc.numPages = np; - this.layoutDoc.nativeWidth = nw * 96 / 72; - this.layoutDoc.nativeHeight = nh * 96 / 72; - !this.layoutDoc.fitWidth && !this.layoutDoc.ignoreAspect && (this.layoutDoc.height = this.layoutDoc[WidthSym]() * (nh / nw)); + this.Document.nativeWidth = nw * 96 / 72; + this.Document.nativeHeight = nh * 96 / 72; + !this.Document.fitWidth && !this.Document.ignoreAspect && (this.Document.height = this.Document[WidthSym]() * (nh / nw)); } public search(string: string, fwd: boolean) { this._pdfViewer && this._pdfViewer.search(string, fwd); } diff --git a/src/client/views/nodes/VideoBox.tsx b/src/client/views/nodes/VideoBox.tsx index 4c01279ae..24f6cca9d 100644 --- a/src/client/views/nodes/VideoBox.tsx +++ b/src/client/views/nodes/VideoBox.tsx @@ -55,15 +55,14 @@ export class VideoBox extends DocAnnotatableComponent { let aspect = this.player!.videoWidth / this.player!.videoHeight; - var nativeWidth = NumCast(this.layoutDoc.nativeWidth, 0); - var nativeHeight = NumCast(this.layoutDoc.nativeHeight, 0); + var nativeWidth = (this.Document.nativeWidth || 0); + var nativeHeight = (this.Document.nativeHeight || 0); if (!nativeWidth || !nativeHeight) { - if (!this.layoutDoc.nativeWidth) this.layoutDoc.nativeWidth = this.player!.videoWidth; - this.layoutDoc.nativeHeight = NumCast(this.layoutDoc.nativeWidth) / aspect; - this.layoutDoc.height = NumCast(this.layoutDoc.width, 0) / aspect; + if (!this.Document.nativeWidth) this.Document.nativeWidth = this.player!.videoWidth; + this.Document.nativeHeight = (this.Document.nativeWidth || 0) / aspect; + this.Document.height = (this.Document.width || 0) / aspect; } if (!this.Document.duration) this.Document.duration = this.player!.duration; } @@ -108,7 +107,7 @@ export class VideoBox extends DocAnnotatableComponent {"" + Math.round(curTime)} {" " + Math.round((curTime - Math.trunc(curTime)) * 100)} @@ -313,7 +312,7 @@ export class VideoBox extends DocAnnotatableComponent { this._isResetClick += Math.abs(e.movementX) + Math.abs(e.movementY); - this.Seek(Math.max(0, NumCast(this.layoutDoc.currentTimecode, 0) + Math.sign(e.movementX) * 0.0333)); + this.Seek(Math.max(0, (this.Document.currentTimecode || 0) + Math.sign(e.movementX) * 0.0333)); e.stopImmediatePropagation(); } @action @@ -321,10 +320,10 @@ export class VideoBox extends DocAnnotatableComponent Math.round(this.Document.currentTimecode || 0)); return