From 4574b7f03ccc85c4bebdbfd9475788456086704f Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 8 Aug 2024 12:27:40 -0400
Subject: many changes to add typing in place of 'any's etc

---
 src/client/views/collections/TabDocView.tsx | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

(limited to 'src/client/views/collections/TabDocView.tsx')

diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx
index f50f7394b..ee5c4afc0 100644
--- a/src/client/views/collections/TabDocView.tsx
+++ b/src/client/views/collections/TabDocView.tsx
@@ -6,6 +6,7 @@ import { IReactionDisposer, ObservableSet, action, computed, makeObservable, obs
 import { observer } from 'mobx-react';
 import * as React from 'react';
 import * as ReactDOM from 'react-dom/client';
+import ResizeObserver from 'resize-observer-polyfill';
 import { ClientUtils, DashColor, lightOrDark, returnEmptyDoclist, returnFalse, returnTrue, setupMoveUpEvents, simulateMouseClick } from '../../../ClientUtils';
 import { emptyFunction } from '../../../Utils';
 import { Doc, Opt } from '../../../fields/Doc';
@@ -41,8 +42,6 @@ import { CollectionView } from './CollectionView';
 import './TabDocView.scss';
 import { CollectionFreeFormView } from './collectionFreeForm/CollectionFreeFormView';
 
-const _global = (window /* browser */ || global) /* node */ as any;
-
 interface TabMinimapViewProps {
     document: Doc;
     tabView: () => DocumentView | undefined;
@@ -183,6 +182,7 @@ export class TabMinimapView extends ObservableReactComponent<TabMinimapViewProps
 interface TabDocViewProps {
     documentId: FieldId;
     keyValue?: boolean;
+    // eslint-disable-next-line @typescript-eslint/no-explicit-any
     glContainer: any;
 }
 @observer
@@ -327,10 +327,12 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
     get view() {
         return this._view;
     }
+    // eslint-disable-next-line @typescript-eslint/no-explicit-any
     _lastTab: any;
     _lastView: DocumentView | undefined;
 
     @action
+    // eslint-disable-next-line @typescript-eslint/no-explicit-any
     init = (tab: any, doc: Opt<Doc>) => {
         if (tab.contentItem === tab.header.parent.getActiveContentItem()) this._activated = true;
         if (tab.DashDoc !== doc && doc && tab.contentItem?.config.type !== 'stack') {
@@ -357,10 +359,11 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
             titleEle.size = StrCast(doc.title).length + 3;
             titleEle.value = doc.title;
             titleEle.onkeydown = (e: KeyboardEvent) => e.stopPropagation();
-            titleEle.onchange = (e: any) => {
+            titleEle.onchange = (e: InputEvent) => {
                 undoable(() => {
-                    titleEle.size = e.currentTarget.value.length + 3;
-                    doc[DocData].title = e.currentTarget.value;
+                    const target = e.currentTarget as unknown as { value: string };
+                    titleEle.size = target?.value.length + 3;
+                    doc[DocData].title = target?.value ?? '';
                 }, 'edit tab title')();
             };
 
@@ -449,8 +452,8 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
             };
 
             // select the tab document when the tab is directly clicked and activate the tab whenver the tab document is selected
-            titleEle.onpointerdown = action((e: any) => {
-                if (e.target.className !== 'lm_iconWrap') {
+            titleEle.onpointerdown = action((e: PointerEvent) => {
+                if ((e.target as HTMLElement)?.className !== 'lm_iconWrap') {
                     if (this.view) DocumentView.SelectView(this.view, false);
                     else this._activated = true;
                     if (Date.now() - titleEle.lastClick < 1000) titleEle.select();
@@ -482,7 +485,7 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
             tab.closeElement
                 .off('click') // unbind the current click handler
                 .click(() => {
-                    Object.values(tab._disposers).forEach((disposer: any) => disposer?.());
+                    Object.values(tab._disposers).forEach(disposer => (disposer as () => void)());
                     DocumentView.DeselectAll();
                     UndoManager.RunInBatch(() => tab.contentItem.remove(), 'delete tab');
                 });
@@ -490,8 +493,8 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
     };
 
     componentDidMount() {
-        new _global.ResizeObserver(
-            action((entries: any) => {
+        new ResizeObserver(
+            action(entries => {
                 // eslint-disable-next-line no-restricted-syntax
                 for (const entry of entries) {
                     this._panelWidth = entry.contentRect.width;
@@ -524,6 +527,7 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
     public static DontSelectOnActivate = 'dontSelectOnActivate';
 
     @action.bound
+    // eslint-disable-next-line @typescript-eslint/no-explicit-any
     private onActiveContentItemChanged(contentItem: any) {
         if (!contentItem || (this.stack === contentItem.parent && ((contentItem?.tab === this.tab && !this._isActive) || (contentItem?.tab !== this.tab && this._isActive)))) {
             this._activated = this._isActive = !contentItem || contentItem?.tab === this.tab;
@@ -650,13 +654,13 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
                             this._view && DocumentView.removeView(this._view);
                         }
                         this._lastTab = this.tab;
-                        (this._mainCont as any).InitTab = (tab: any) => this.init(tab, this._document);
+                        (this._mainCont as { InitTab?: (tab: object) => void }).InitTab = (tab: object) => this.init(tab, this._document);
                         DocServer.GetRefField(this._props.documentId).then(
                             action(doc => {
                                 doc instanceof Doc && (this._document = doc) && this.tab && this.init(this.tab, this._document);
                             })
                         );
-                        new _global.ResizeObserver(action(() => this._forceInvalidateScreenToLocal++)).observe(ref);
+                        ref && new ResizeObserver(action(() => this._forceInvalidateScreenToLocal++)).observe(ref);
                     }
                 }}>
                 {this.docView}
-- 
cgit v1.2.3-70-g09d2

