aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionDockingView.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/CollectionDockingView.tsx
parentc01828308714874589d1f60c33ca59df4c656c0c (diff)
parenta958577d4c27b276aa37484e3f895e196138b17c (diff)
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/client/views/collections/CollectionDockingView.tsx')
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx71
1 files changed, 35 insertions, 36 deletions
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index 2a36e96bf..e0aa79c7b 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -2,12 +2,14 @@ import { action, IReactionDisposer, makeObservable, observable, reaction } from
import { observer } from 'mobx-react';
import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
+import ResizeObserver from 'resize-observer-polyfill';
import { addStyleSheet, addStyleSheetRule, clearStyleSheetRules, DivHeight, DivWidth, incrementTitleCopy, returnTrue, UpdateIcon } from '../../../ClientUtils';
import { Doc, DocListCast, Field, Opt } from '../../../fields/Doc';
import { AclAdmin, AclEdit, DocData } from '../../../fields/DocSymbols';
import { Id } from '../../../fields/FieldSymbols';
import { InkTool } from '../../../fields/InkField';
import { List } from '../../../fields/List';
+import { FieldType } from '../../../fields/ObjectField';
import { ImageCast, NumCast, StrCast } from '../../../fields/Types';
import { ImageField } from '../../../fields/URLField';
import { GetEffectiveAcl, inheritParentAcls, SetPropSetterCb } from '../../../fields/util';
@@ -28,19 +30,17 @@ import { OverlayView } from '../OverlayView';
import { ScriptingRepl } from '../ScriptingRepl';
import { UndoStack } from '../UndoStack';
import './CollectionDockingView.scss';
-import { CollectionSubView } from './CollectionSubView';
-
-const _global = (window /* browser */ || global) /* node */ as any;
+import { CollectionSubView, SubCollectionViewProps } from './CollectionSubView';
@observer
export class CollectionDockingView extends CollectionSubView() {
- static tabClass: JSX.Element | null = null;
+ static tabClass: unknown = null;
/**
* Initialize by assigning the add split method to DocumentView and by
* configuring golden layout to render its documents using the specified React component
* @param ele - typically would be set to TabDocView
*/
- public static Init(ele: any) {
+ public static Init(ele: unknown) {
this.tabClass = ele;
DocumentView.addSplit = CollectionDockingView.AddSplit;
}
@@ -53,20 +53,22 @@ export class CollectionDockingView extends CollectionSubView() {
private _flush: UndoManager.Batch | undefined;
private _unmounting = false;
private _ignoreStateChange = '';
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ private _goldenLayout: any = null;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
public tabMap: Set<any> = new Set();
public get HasFullScreen() {
return this._goldenLayout._maximisedItem !== null;
}
- private _goldenLayout: any = null;
static _highlightStyleSheet = addStyleSheet();
- constructor(props: any) {
+ constructor(props: SubCollectionViewProps) {
super(props);
makeObservable(this);
if (this._props.renderDepth < 0) CollectionDockingView.Instance = this;
// Why is this here?
- (window as any).React = React;
- (window as any).ReactDOM = ReactDOM;
+ (window as unknown as { React: unknown }).React = React;
+ (window as unknown as { ReactDOM: unknown }).ReactDOM = ReactDOM;
DragManager.StartWindowDrag = this.StartOtherDrag;
this.Document.myTrails; // this is equivalent to having a prefetchProxy for myTrails which is needed for the My Trails button in the UI which assumes that Doc.ActiveDashboard.myTrails is legit...
}
@@ -88,10 +90,11 @@ export class CollectionDockingView extends CollectionSubView() {
};
tabItemDropped = () => DragManager.CompleteWindowDrag?.(false);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
tabDragStart = (proxy: any, finishDrag?: (aborted: boolean) => void) => {
this._flush = this._flush ?? UndoManager.StartBatch('tab move');
- const dashDoc = proxy?._contentItem?.tab?.DashDoc as Doc;
- dashDoc && (DragManager.DocDragData = new DragManager.DocumentDragData([proxy._contentItem.tab.DashDoc]));
+ //const dashDoc = proxy?._contentItem?.tab?.DashDoc as Doc;
+ //dashDoc && (DragManager.DocDragData = new DragManager.DocumentDragData([proxy._contentItem.tab.DashDoc]));
DragManager.CompleteWindowDrag = (aborted: boolean) => {
if (aborted) {
proxy._dragListener.AbortDrag();
@@ -129,12 +132,13 @@ export class CollectionDockingView extends CollectionSubView() {
}
@undoBatch
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
public static ReplaceTab(document: Doc, mods: OpenWhereMod, stack: any, panelName: string, addToSplit?: boolean, keyValue?: boolean): boolean {
const instance = CollectionDockingView.Instance;
if (!instance) return false;
const newConfig = DashboardView.makeDocumentConfig(document, panelName, undefined, keyValue);
if (!panelName && stack) {
- const activeContentItemIndex = stack.contentItems.findIndex((item: any) => item.config === stack._activeContentItem.config);
+ const activeContentItemIndex = stack.contentItems.findIndex((item: { config: unknown }) => item.config === stack._activeContentItem.config);
const newContentItem = stack.layoutManager.createContentItem(newConfig, instance._goldenLayout);
stack.addChild(newContentItem.contentItems[0], undefined);
stack.contentItems[activeContentItemIndex].remove();
@@ -154,6 +158,7 @@ export class CollectionDockingView extends CollectionSubView() {
}
@undoBatch
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
public static ToggleSplit(doc: Doc, location: OpenWhereMod, stack?: any, panelName?: string, keyValue?: boolean) {
return Array.from(CollectionDockingView.Instance?.tabMap.keys() ?? []).findIndex(tab => tab.DashDoc === doc) !== -1 ? CollectionDockingView.CloseSplit(doc) : CollectionDockingView.AddSplit(doc, location, stack, panelName, keyValue);
}
@@ -162,6 +167,7 @@ export class CollectionDockingView extends CollectionSubView() {
// Creates a split on any side of the docking view based on the passed input pullSide and then adds the Document to the requested side
//
@action
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
public static AddSplit(document: Doc, pullSide: OpenWhereMod, stack?: any, panelName?: string, keyValue?: boolean) {
if (document?._type_collection === CollectionViewType.Docking && !keyValue) return DashboardView.openDashboard(document);
if (!CollectionDockingView.Instance) return false;
@@ -320,7 +326,7 @@ export class CollectionDockingView extends CollectionSubView() {
* @param target
* @param title
*/
- titleChanged = (target: any, value: any) => {
+ titleChanged = (target: Doc, value: FieldType) => {
const title = Field.toString(value);
if (title.startsWith('@') && !title.substring(1).match(/[()[\]@]/) && title.length > 1) {
const embedding = DocListCast(target.proto_embeddings).lastElement();
@@ -339,7 +345,7 @@ export class CollectionDockingView extends CollectionSubView() {
() => DocumentView.LightboxDoc(),
doc => setTimeout(() => !doc && this.onResize())
);
- new _global.ResizeObserver(this.onResize).observe(this._containerRef.current);
+ new ResizeObserver(this.onResize).observe(this._containerRef.current);
this._reactionDisposer = reaction(
() => StrCast(this.Document.dockingConfig),
config => {
@@ -428,7 +434,7 @@ export class CollectionDockingView extends CollectionSubView() {
@action
onPointerDown = (e: React.PointerEvent): void => {
let hitFlyout = false;
- for (let par = e.target as any; !hitFlyout && par; par = par.parentElement) {
+ for (let par = e.target as HTMLElement | null; !hitFlyout && par; par = par.parentElement) {
hitFlyout = par.className === 'dockingViewButtonSelector';
}
if (!hitFlyout) {
@@ -513,6 +519,7 @@ export class CollectionDockingView extends CollectionSubView() {
return changesMade;
};
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
tabDestroyed = (tab: any) => {
this._flush = this._flush ?? UndoManager.StartBatch('tab movement');
const dashDoc = tab.DashDoc;
@@ -530,18 +537,21 @@ export class CollectionDockingView extends CollectionSubView() {
const { fieldKey } = CollectionDockingView.Instance.props;
Doc.RemoveDocFromList(dview, fieldKey, dashDoc);
this.tabMap.delete(tab);
- tab._disposers && Object.values(tab._disposers).forEach((disposer: any) => disposer?.());
+ tab._disposers && Object.values(tab._disposers).forEach(disposer => (disposer as () => void)());
this.stateChanged();
}
};
- tabCreated = (tab: any) => {
+ tabCreated = (tab: { contentItem: { element: HTMLElement[] } }) => {
this.tabMap.add(tab);
- tab.contentItem.element[0]?.firstChild?.firstChild?.InitTab?.(tab); // have to explicitly initialize tabs that reuse contents from previous tabs (ie, when dragging a tab around a new tab is created for the old content)
+ // InitTab is added to the tab's HTMLElement in TabDocView
+ const tabdocviewContent = tab.contentItem.element[0]?.firstChild?.firstChild as unknown as { InitTab?: (tab: object) => void };
+ tabdocviewContent?.InitTab?.(tab); // have to explicitly initialize tabs that reuse contents from previous tabs (ie, when dragging a tab around a new tab is created for the old content)
};
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
stackCreated = (stackIn: any) => {
const stack = stackIn.header ? stackIn : stackIn.origin;
- stack.header?.element.on('mousedown', (e: any) => {
+ stack.header?.element.on('mousedown', (e: MouseEvent) => {
const dashboard = Doc.ActiveDashboard;
if (dashboard && e.target === stack.header?.element[0] && e.button === 2) {
dashboard.pane_count = NumCast(dashboard.pane_count) + 1;
@@ -594,7 +604,7 @@ export class CollectionDockingView extends CollectionSubView() {
})
);
- stack.element.click((e: any) => {
+ stack.element.click((e: { originalEvent: MouseEvent }) => {
if (stack.contentItems.length === 0 && Array.from(document.elementsFromPoint(e.originalEvent.x, e.originalEvent.y)).some(ele => ele?.className === 'empty-tabs-message')) {
addNewDoc();
}
@@ -632,7 +642,7 @@ export class CollectionDockingView extends CollectionSubView() {
ScriptingGlobals.add(
// eslint-disable-next-line prefer-arrow-callback
- function openInLightbox(doc: any) {
+ function openInLightbox(doc: Doc) {
CollectionDockingView.Instance?._props.addDocTab(doc, OpenWhere.lightboxAlways);
},
'opens up document in a lightbox',
@@ -640,33 +650,22 @@ ScriptingGlobals.add(
);
ScriptingGlobals.add(
// eslint-disable-next-line prefer-arrow-callback
- function openDoc(doc: any, where: OpenWhere) {
+ function openDoc(doc: Doc | string, where: OpenWhere) {
switch (where) {
case OpenWhere.addRight:
- return CollectionDockingView.AddSplit(doc, OpenWhereMod.right);
+ return doc instanceof Doc && CollectionDockingView.AddSplit(doc, OpenWhereMod.right);
case OpenWhere.overlay:
default:
- // prettier-ignore
switch (doc) {
case '<ScriptingRepl />': return OverlayView.Instance.addWindow(<ScriptingRepl />, { x: 300, y: 100, width: 200, height: 200, title: 'Scripting REPL' });
case "<UndoStack />": return OverlayView.Instance.addWindow(<UndoStack />, { x: 300, y: 100, width: 200, height: 200, title: 'Undo stack' });
- default:
- }
- Doc.AddToMyOverlay(doc);
- return true;
+ default: return doc instanceof Doc && Doc.AddToMyOverlay(doc);
+ } // prettier-ignore
}
},
'opens up document in location specified',
'(doc: any)'
);
-ScriptingGlobals.add(
- // eslint-disable-next-line prefer-arrow-callback
- function openRepl() {
- return 'openRepl';
- },
- 'opens up document in screen overlay layer',
- '(doc: any)'
-);
// eslint-disable-next-line prefer-arrow-callback
ScriptingGlobals.add(async function snapshotDashboard() {
const batch = UndoManager.StartBatch('snapshot');