aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/PDFBox.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-09-02 09:26:37 -0400
committerbobzel <zzzman@gmail.com>2024-09-02 09:26:37 -0400
commitcda69e48361fce8d71a4dc66edd9dd976a27f52d (patch)
tree82b9a1a5967ae88a9534f89f7eaed3aeb289652f /src/client/views/nodes/PDFBox.tsx
parentc01828308714874589d1f60c33ca59df4c656c0c (diff)
parenta958577d4c27b276aa37484e3f895e196138b17c (diff)
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/client/views/nodes/PDFBox.tsx')
-rw-r--r--src/client/views/nodes/PDFBox.tsx28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx
index 8db68ddfe..cb0b0d71f 100644
--- a/src/client/views/nodes/PDFBox.tsx
+++ b/src/client/views/nodes/PDFBox.tsx
@@ -1,5 +1,3 @@
-/* eslint-disable jsx-a11y/no-static-element-interactions */
-/* eslint-disable jsx-a11y/control-has-associated-label */
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { action, computed, IReactionDisposer, makeObservable, observable, reaction, runInAction } from 'mobx';
import { observer } from 'mobx-react';
@@ -24,7 +22,6 @@ import { undoBatch, UndoManager } from '../../util/UndoManager';
import { CollectionFreeFormView } from '../collections/collectionFreeForm';
import { CollectionStackingView } from '../collections/CollectionStackingView';
import { ContextMenu } from '../ContextMenu';
-import { ContextMenuProps } from '../ContextMenuItem';
import { ViewBoxAnnotatableComponent } from '../DocComponent';
import { Colors } from '../global/globalEnums';
import { PDFViewer } from '../pdf/PDFViewer';
@@ -59,10 +56,6 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
@computed get pdfUrl() {
return Cast(this.dataDoc[this._props.fieldKey], PdfField);
}
- @computed get pdfThumb() {
- return ImageCast(this.layoutDoc['thumb-frozen'], ImageCast(this.layoutDoc.thumb))?.url;
- }
-
constructor(props: FieldViewProps) {
super(props);
makeObservable(this);
@@ -76,7 +69,7 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
});
else if (PDFBox.pdfpromise.get(this.pdfUrl.url.href))
PDFBox.pdfpromise.get(this.pdfUrl.url.href)?.then(
- action((pdf: any) => {
+ action(pdf => {
this._pdf = pdf;
})
);
@@ -108,7 +101,8 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
};
crop = (region: Doc | undefined, addCrop?: boolean) => {
- if (!region) return undefined;
+ const docViewContent = this.DocumentView?.().ContentDiv;
+ if (!region || !docViewContent) return undefined;
const cropping = Doc.MakeCopy(region, true);
cropping.layout_unrendered = false; // text selection have this
cropping.text_inlineAnnotations = undefined; // text selections have this -- it causes them not to be rendered.
@@ -120,7 +114,6 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
regionData.followLinkToggle = true;
this.addDocument(region);
- const docViewContent = this.DocumentView?.().ContentDiv!;
const newDiv = docViewContent.cloneNode(true) as HTMLDivElement;
newDiv.style.width = NumCast(this.layoutDoc._width).toString();
newDiv.style.height = NumCast(this.layoutDoc._height).toString();
@@ -162,7 +155,7 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
(NumCast(region.x) * this._props.PanelWidth()) / NumCast(this.dataDoc[this.fieldKey + '_nativeWidth']),
4
)
- .then((dataUrl: any) => {
+ .then(dataUrl => {
ClientUtils.convertDataUri(dataUrl, region[Id]).then(returnedfilename =>
setTimeout(
action(() => {
@@ -172,7 +165,7 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
)
);
})
- .catch((error: any) => {
+ .catch(error => {
console.error('oops, something went wrong!', error);
});
@@ -181,9 +174,10 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
updateIcon = () => {
// currently we render pdf icons as text labels
- const docViewContent = this.DocumentView?.().ContentDiv!;
+ const docViewContent = this.DocumentView?.().ContentDiv;
const filename = this.layoutDoc[Id] + '-icon' + new Date().getTime();
this._pdfViewer?._mainCont.current &&
+ docViewContent &&
UpdateIcon(
filename,
docViewContent,
@@ -399,6 +393,7 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
</button>
</>
);
+
const searchTitle = `${!this._searching ? 'Open' : 'Close'} Search Bar`;
const curPage = NumCast(this.Document._layout_curPage) || 1;
return !this._props.isContentActive() || this._pdfViewer?.isAnnotating ? null : (
@@ -474,13 +469,14 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
specificContextMenu = (): void => {
const cm = ContextMenu.Instance;
const options = cm.findByDescription('Options...');
- const optionItems: ContextMenuProps[] = options && 'subitems' in options ? options.subitems : [];
+ const optionItems = options?.subitems ?? [];
+
!Doc.noviceMode && optionItems.push({ description: 'Toggle Sidebar Type', event: this.toggleSidebarType, icon: 'expand-arrows-alt' });
!Doc.noviceMode && optionItems.push({ description: 'update icon', event: () => this.pdfUrl && this.updateIcon(), icon: 'expand-arrows-alt' });
// optionItems.push({ description: "Toggle Sidebar ", event: () => this.toggleSidebar(), icon: "expand-arrows-alt" });
!options && ContextMenu.Instance.addItem({ description: 'Options...', subitems: optionItems, icon: 'asterisk' });
const help = cm.findByDescription('Help...');
- const helpItems: ContextMenuProps[] = help && 'subitems' in help ? help.subitems : [];
+ const helpItems = help?.subitems ?? [];
helpItems.push({ description: 'Copy path', event: () => this.pdfUrl && ClientUtils.CopyText(ClientUtils.prepend('') + this.pdfUrl.url.pathname), icon: 'expand-arrows-alt' });
!help && ContextMenu.Instance.addItem({ description: 'Help...', noexpand: true, subitems: helpItems, icon: 'asterisk' });
};
@@ -656,7 +652,7 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
else {
if (!PDFBox.pdfpromise.get(href)) PDFBox.pdfpromise.set(href, Pdfjs.getDocument(href).promise);
PDFBox.pdfpromise.get(href)?.then(
- action((pdf: any) => {
+ action(pdf => {
PDFBox.pdfcache.set(href, (this._pdf = pdf));
})
);