aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/MainView.tsx
diff options
context:
space:
mode:
authorZachary Zhang <zacharyzhang7@gmail.com>2024-08-31 00:46:29 -0400
committerZachary Zhang <zacharyzhang7@gmail.com>2024-08-31 00:46:29 -0400
commit196294f331496262bef256da8b8e9dbc80288bea (patch)
tree85ff27b7a8070585f9a5ef71dff63566e03232ba /src/client/views/MainView.tsx
parent0cf61501ec9be34294935f01973c1bd9cad6d267 (diff)
parentc36607691e0b7f5c04f3209a64958f5e51ddd785 (diff)
Merge branch 'master' into zach-starter
Diffstat (limited to 'src/client/views/MainView.tsx')
-rw-r--r--src/client/views/MainView.tsx65
1 files changed, 25 insertions, 40 deletions
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index f8c7fd7b1..7deca234e 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable node/no-unpublished-import */
import { library } from '@fortawesome/fontawesome-svg-core';
import { faBuffer, faHireAHelper } from '@fortawesome/free-brands-svg-icons';
import * as far from '@fortawesome/free-regular-svg-icons';
@@ -7,11 +6,11 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { action, computed, configure, makeObservable, observable, reaction, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-// eslint-disable-next-line import/no-relative-packages
+import ResizeObserver from 'resize-observer-polyfill';
import '../../../node_modules/browndash-components/dist/styles/global.min.css';
-import { ClientUtils, lightOrDark, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnTrue, returnZero, setupMoveUpEvents } from '../../ClientUtils';
+import { ClientUtils, lightOrDark, returnEmptyFilter, returnFalse, returnTrue, returnZero, setupMoveUpEvents } from '../../ClientUtils';
import { emptyFunction } from '../../Utils';
-import { Doc, DocListCast, GetDocFromUrl, Opt } from '../../fields/Doc';
+import { Doc, DocListCast, GetDocFromUrl, Opt, returnEmptyDoclist } from '../../fields/Doc';
import { DocData } from '../../fields/DocSymbols';
import { Id } from '../../fields/FieldSymbols';
import { DocCast, StrCast, toList } from '../../fields/Types';
@@ -58,7 +57,6 @@ import { ImageLabelHandler } from './collections/collectionFreeForm/ImageLabelHa
import { MarqueeOptionsMenu } from './collections/collectionFreeForm/MarqueeOptionsMenu';
import { CollectionLinearView } from './collections/collectionLinear';
import { LinkMenu } from './linking/LinkMenu';
-import { AudioBox } from './nodes/AudioBox';
import { SchemaCSVPopUp } from './nodes/DataVizBox/SchemaCSVPopUp';
import { DocButtonState } from './nodes/DocumentLinksButton';
import { DocumentView, DocumentViewInternal } from './nodes/DocumentView';
@@ -78,11 +76,11 @@ import { GPTPopup } from './pdf/GPTPopup/GPTPopup';
import { TopBar } from './topbar/TopBar';
import { InkTranscription } from './InkTranscription';
+// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const { LEFT_MENU_WIDTH, TOPBAR_HEIGHT } = require('./global/globalCssVariables.module.scss'); // prettier-ignore
-const _global = (window /* browser */ || global) /* node */ as any;
@observer
-export class MainView extends ObservableReactComponent<{}> {
+export class MainView extends ObservableReactComponent<object> {
// eslint-disable-next-line no-use-before-define
public static Instance: MainView;
public static Live: boolean = false;
@@ -93,7 +91,7 @@ export class MainView extends ObservableReactComponent<{}> {
@observable private _dashUIWidth: number = 0; // width of entire main dashboard region including left menu buttons and properties panel (but not including the dashboard selector button row)
@observable private _dashUIHeight: number = 0; // height of entire main dashboard region including top menu buttons
@observable private _panelContent: string = 'none';
- @observable private _sidebarContent: any = Doc.MyLeftSidebarPanel;
+ @observable private _sidebarContent: Doc = Doc.MyLeftSidebarPanel;
@observable private _leftMenuFlyoutWidth: number = 0;
@computed get _hideUI() {
return this.mainDoc && this.mainDoc._type_collection !== CollectionViewType.Docking;
@@ -153,7 +151,7 @@ export class MainView extends ObservableReactComponent<{}> {
}
};
headerBarDocWidth = () => this.mainDocViewWidth();
- headerBarDocHeight = () => (this._hideUI ? 0 : this.headerBarHeight ?? 0);
+ headerBarDocHeight = () => (this._hideUI ? 0 : (this.headerBarHeight ?? 0));
topMenuHeight = () => (this._hideUI ? 0 : 35);
topMenuWidth = returnZero; // value is ignored ...
leftMenuWidth = () => (this._hideUI ? 0 : Number(LEFT_MENU_WIDTH.replace('px', '')));
@@ -170,7 +168,7 @@ export class MainView extends ObservableReactComponent<{}> {
reaction(
// when a multi-selection occurs, remove focus from all active elements to allow keyboad input to go only to global key manager to act upon selection
() => DocumentView.Selected().slice(),
- views => views.length > 1 && (document.activeElement as any)?.blur !== undefined && (document.activeElement as any)!.blur()
+ views => views.length > 1 && document.activeElement instanceof HTMLElement && document.activeElement?.blur()
);
reaction(
() => Doc.MyDockedBtns.linearView_IsOpen,
@@ -235,9 +233,9 @@ export class MainView extends ObservableReactComponent<{}> {
tag.src = 'https://www.youtube.com/iframe_api';
const firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode!.insertBefore(tag, firstScriptTag);
- document.addEventListener('dash', (e: any) => {
+ document.addEventListener('dash', (e: Event) => {
// event used by chrome plugin to tell Dash which document to focus on
- const id = GetDocFromUrl(e.detail);
+ const id = GetDocFromUrl((e as Event & { detail: string }).detail);
DocServer.GetRefField(id).then(doc => (doc instanceof Doc ? DocumentView.showDocument(doc, { willPan: false }) : null));
});
document.addEventListener('linkAnnotationToDash', Hypothesis.linkListener);
@@ -254,12 +252,12 @@ export class MainView extends ObservableReactComponent<{}> {
// document.removeEventListener('linkAnnotationToDash', Hypothesis.linkListener);
}
- constructor(props: any) {
+ constructor(props: object) {
super(props);
makeObservable(this);
DocumentViewInternal.addDocTabFunc = MainView.addDocTabFunc_impl;
MainView.Instance = this;
- DashboardView._urlState = HistoryUtil.parseUrl(window.location) || ({} as any);
+ DashboardView._urlState = HistoryUtil.parseUrl(window.location) ?? { type: 'doc', docId: '' };
// causes errors to be generated when modifying an observable outside of an action
configure({ enforceActions: 'observed' });
@@ -294,7 +292,7 @@ export class MainView extends ObservableReactComponent<{}> {
fa.faExternalLinkAlt,
fa.faCalendar,
fa.faSquare,
- far.faSquare as any,
+ far.faSquare,
fa.faConciergeBell,
fa.faWindowRestore,
fa.faFolder,
@@ -446,7 +444,7 @@ export class MainView extends ObservableReactComponent<{}> {
fa.faHandPaper,
fa.faMap,
fa.faUser,
- faHireAHelper as any,
+ faHireAHelper,
fa.faTrashRestore,
fa.faUsers,
fa.faWrench,
@@ -457,14 +455,14 @@ export class MainView extends ObservableReactComponent<{}> {
fa.faArchive,
fa.faBezierCurve,
fa.faCircle,
- far.faCircle as any,
+ far.faCircle,
fa.faLongArrowAltRight,
fa.faPenFancy,
fa.faAngleDoubleRight,
fa.faAngleDoubleDown,
fa.faAngleDoubleLeft,
fa.faAngleDoubleUp,
- faBuffer as any,
+ faBuffer,
fa.faExpand,
fa.faUndo,
fa.faSlidersH,
@@ -571,7 +569,6 @@ export class MainView extends ObservableReactComponent<{}> {
);
DocumentManager.removeOverlayViews();
Doc.linkFollowUnhighlight();
- AudioBox.Enabled = true;
const targets = document.elementsFromPoint(e.x, e.y);
if (targets.length) {
let targClass = targets[0].className.toString();
@@ -591,18 +588,6 @@ export class MainView extends ObservableReactComponent<{}> {
document.addEventListener('pointerdown', this.globalPointerDown, true);
document.addEventListener('pointermove', this.globalPointerMove, true);
document.addEventListener('pointerup', this.globalPointerClick, true);
- document.addEventListener(
- 'click',
- (e: MouseEvent) => {
- if (!e.cancelBubble) {
- const pathstr = (e as any)?.path?.map((p: any) => p.classList?.toString()).join();
- if (pathstr?.includes('libraryFlyout')) {
- DocumentView.DeselectAll();
- }
- }
- },
- false
- );
document.oncontextmenu = () => false;
};
@@ -643,7 +628,7 @@ export class MainView extends ObservableReactComponent<{}> {
Document={this.headerBarDoc}
addDocTab={DocumentViewInternal.addDocTabFunc}
pinToPres={emptyFunction}
- containerViewPath={returnEmptyDoclist}
+ containerViewPath={returnEmptyDocViewList}
styleProvider={DefaultStyleProvider}
addDocument={this.addHeaderDoc}
removeDocument={this.removeHeaderDoc}
@@ -678,7 +663,7 @@ export class MainView extends ObservableReactComponent<{}> {
addDocument={undefined}
addDocTab={DocumentViewInternal.addDocTabFunc}
pinToPres={emptyFunction}
- containerViewPath={returnEmptyDoclist}
+ containerViewPath={returnEmptyDocViewList}
styleProvider={this._hideUI ? DefaultStyleProvider : undefined}
isContentActive={returnTrue}
removeDocument={undefined}
@@ -778,11 +763,11 @@ export class MainView extends ObservableReactComponent<{}> {
<div key="libFlyout" className="mainView-libraryFlyout" style={{ minWidth: this._leftMenuFlyoutWidth, width: this._leftMenuFlyoutWidth }}>
<div className="mainView-contentArea">
<DocumentView
- Document={this._sidebarContent.proto || this._sidebarContent}
+ Document={DocCast(this._sidebarContent.proto, this._sidebarContent)}
addDocument={undefined}
addDocTab={DocumentViewInternal.addDocTabFunc}
pinToPres={DocumentView.PinDoc}
- containerViewPath={returnEmptyDoclist}
+ containerViewPath={returnEmptyDocViewList}
styleProvider={this._sidebarContent.proto === Doc.MyDashboards || this._sidebarContent.proto === Doc.MyFilesystem || this._sidebarContent.proto === Doc.MyTrails ? DashboardStyleProvider : DefaultStyleProvider}
removeDocument={returnFalse}
ScreenToLocalTransform={this.mainContainerXf}
@@ -815,7 +800,7 @@ export class MainView extends ObservableReactComponent<{}> {
PanelWidth={this.leftMenuWidth}
PanelHeight={this.leftMenuHeight}
renderDepth={0}
- containerViewPath={returnEmptyDoclist}
+ containerViewPath={returnEmptyDocViewList}
focus={emptyFunction}
styleProvider={DefaultStyleProvider}
isContentActive={returnTrue}
@@ -890,7 +875,7 @@ export class MainView extends ObservableReactComponent<{}> {
className="mainView-dashboardArea"
ref={r => {
r &&
- new _global.ResizeObserver(
+ new ResizeObserver(
action(() => {
this._dashUIWidth = r.getBoundingClientRect().width;
this._dashUIHeight = r.getBoundingClientRect().height;
@@ -977,11 +962,11 @@ export class MainView extends ObservableReactComponent<{}> {
{[
...SnappingManager.HorizSnapLines.map((l, i) => (
// eslint-disable-next-line react/no-array-index-key
- <line key={'horiz' + i} x1="0" y1={l} x2="2000" y2={l} stroke={lightOrDark(dragPar.layoutDoc.backgroundColor ?? 'gray')} opacity={0.3} strokeWidth={1} strokeDasharray="2 2" />
+ <line key={'horiz' + i} x1="0" y1={l} x2="2000" y2={l} stroke={lightOrDark(StrCast(dragPar.layoutDoc.backgroundColor, 'gray'))} opacity={0.3} strokeWidth={1} strokeDasharray="2 2" />
)),
...SnappingManager.VertSnapLines.map((l, i) => (
// eslint-disable-next-line react/no-array-index-key
- <line key={'vert' + i} y1={this.topOfMainDocContent.toString()} x1={l} y2="2000" x2={l} stroke={lightOrDark(dragPar.layoutDoc.backgroundColor ?? 'gray')} opacity={0.3} strokeWidth={1} strokeDasharray="2 2" />
+ <line key={'vert' + i} y1={this.topOfMainDocContent.toString()} x1={l} y2="2000" x2={l} stroke={lightOrDark(StrCast(dragPar.layoutDoc.backgroundColor, 'gray'))} opacity={0.3} strokeWidth={1} strokeDasharray="2 2" />
)),
]}
</svg>
@@ -1039,7 +1024,7 @@ export class MainView extends ObservableReactComponent<{}> {
}
ref={r => {
r &&
- new _global.ResizeObserver(
+ new ResizeObserver(
action(() => {
this._windowWidth = r.getBoundingClientRect().width;
this._windowHeight = r.getBoundingClientRect().height;