aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/TabDocView.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/collections/TabDocView.tsx
parentc01828308714874589d1f60c33ca59df4c656c0c (diff)
parenta958577d4c27b276aa37484e3f895e196138b17c (diff)
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/client/views/collections/TabDocView.tsx')
-rw-r--r--src/client/views/collections/TabDocView.tsx55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx
index 46f61290e..31b6be927 100644
--- a/src/client/views/collections/TabDocView.tsx
+++ b/src/client/views/collections/TabDocView.tsx
@@ -6,15 +6,16 @@ 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 { ClientUtils, DashColor, lightOrDark, returnEmptyDoclist, returnFalse, returnTrue, setupMoveUpEvents, simulateMouseClick } from '../../../ClientUtils';
+import ResizeObserver from 'resize-observer-polyfill';
+import { ClientUtils, DashColor, lightOrDark, returnEmptyFilter, returnFalse, returnTrue, setupMoveUpEvents, simulateMouseClick } from '../../../ClientUtils';
import { emptyFunction } from '../../../Utils';
-import { Doc, Opt } from '../../../fields/Doc';
+import { Doc, Opt, returnEmptyDoclist } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
import { Id } from '../../../fields/FieldSymbols';
import { List } from '../../../fields/List';
import { FieldId } from '../../../fields/RefField';
import { ComputedField } from '../../../fields/ScriptField';
-import { Cast, DocCast, NumCast, StrCast, toList } from '../../../fields/Types';
+import { Cast, NumCast, StrCast, toList } from '../../../fields/Types';
import { DocServer } from '../../DocServer';
import { CollectionViewType, DocumentType } from '../../documents/DocumentTypes';
import { Docs } from '../../documents/Documents';
@@ -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;
@@ -67,7 +66,7 @@ class TabMiniThumb extends React.Component<TabMiniThumbProps> {
}
@observer
export class TabMinimapView extends ObservableReactComponent<TabMinimapViewProps> {
- static miniStyleProvider = (doc: Opt<Doc>, props: Opt<FieldViewProps>, property: string): any => {
+ static miniStyleProvider = (doc: Opt<Doc>, props: Opt<FieldViewProps>, property: string) => {
if (doc) {
switch (property.split(':')[0]) {
case StyleProp.PointerEvents: return 'none';
@@ -158,8 +157,8 @@ export class TabMinimapView extends ObservableReactComponent<TabMinimapViewProps
addDocTab={this._props.addDocTab}
// eslint-disable-next-line no-use-before-define
pinToPres={TabDocView.PinDoc}
- childFilters={CollectionDockingView.Instance?.childDocFilters ?? returnEmptyDoclist}
- childFiltersByRanges={CollectionDockingView.Instance?.childDocRangeFilters ?? returnEmptyDoclist}
+ childFilters={CollectionDockingView.Instance?.childDocFilters ?? returnEmptyFilter}
+ childFiltersByRanges={CollectionDockingView.Instance?.childDocRangeFilters ?? returnEmptyFilter}
searchFilterDocs={CollectionDockingView.Instance?.searchFilterDocs ?? returnEmptyDoclist}
fitContentsToBox={returnTrue}
xPadding={this.xPadding}
@@ -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
@@ -274,7 +274,7 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
}
static Activate = (tabDoc: Doc) => {
- const tab = Array.from(CollectionDockingView.Instance?.tabMap!).find(findTab => findTab.DashDoc === tabDoc && !findTab.contentItem.config.props.keyValue);
+ const tab = Array.from(CollectionDockingView.Instance?.tabMap ?? []).find(findTab => findTab.DashDoc === tabDoc && !findTab.contentItem.config.props.keyValue);
tab?.header.parent.setActiveContentItem(tab.contentItem); // glr: Panning does not work when this is set - (this line is for trying to make a tab that is not topmost become topmost)
return tab !== undefined;
};
@@ -286,7 +286,7 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
// }
// return undefined;
// }
- constructor(props: any) {
+ constructor(props: TabDocViewProps) {
super(props);
makeObservable(this);
DocumentView.activateTabView = TabDocView.Activate;
@@ -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')();
};
@@ -399,9 +402,10 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
tab._disposers.color = reaction(
() => ({ variant: SnappingManager.userVariantColor, degree: Doc.GetBrushStatus(doc), highlight: DefaultStyleProvider(this._document, undefined, StyleProp.Highlighting) }),
({ variant, degree, highlight }) => {
- const color = highlight?.highlightIndex === Doc.DocBrushStatus.highlighted ? highlight.highlightColor : degree ? ['transparent', variant, variant, 'orange'][degree] : variant;
+ const { highlightIndex, highlightColor } = (highlight as { highlightIndex: number; highlightColor: string }) ?? { highlightIndex: undefined, highlightColor: undefined };
+ const color = highlightIndex === Doc.DocBrushStatus.highlighted ? highlightColor : degree ? ['transparent', variant, variant, 'orange'][degree] : variant;
- const textColor = color === variant ? SnappingManager.userColor ?? '' : lightOrDark(color);
+ const textColor = color === variant ? (SnappingManager.userColor ?? '') : lightOrDark(color);
titleEle.style.color = textColor;
iconWrap.style.color = textColor;
closeWrap.style.color = textColor;
@@ -448,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();
@@ -481,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');
});
@@ -489,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;
@@ -523,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;
@@ -612,8 +617,8 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
PanelWidth={this.PanelWidth}
PanelHeight={this.PanelHeight}
styleProvider={DefaultStyleProvider}
- childFilters={CollectionDockingView.Instance?.childDocFilters ?? returnEmptyDoclist}
- childFiltersByRanges={CollectionDockingView.Instance?.childDocRangeFilters ?? returnEmptyDoclist}
+ childFilters={CollectionDockingView.Instance?.childDocFilters ?? returnEmptyFilter}
+ childFiltersByRanges={CollectionDockingView.Instance?.childDocRangeFilters ?? returnEmptyFilter}
searchFilterDocs={CollectionDockingView.Instance?.searchFilterDocs ?? returnEmptyDoclist}
addDocument={undefined}
removeDocument={this.remDocTab}
@@ -623,7 +628,7 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> {
dontCenter="y"
whenChildContentsActiveChanged={this.whenChildContentActiveChanges}
focus={this.focusFunc}
- containerViewPath={returnEmptyDoclist}
+ containerViewPath={returnEmptyDocViewList}
pinToPres={TabDocView.PinDoc}
/>
{this.disableMinimap() ? null : <TabMinimapView key="minimap" addDocTab={this.addDocTab} PanelHeight={this.PanelHeight} PanelWidth={this.PanelWidth} background={this.miniMapColor} document={this._document} tabView={this.tabView} />}
@@ -649,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}