From 762ac2bf354e4cc2c4b15f42502da939f5061646 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 9 Aug 2024 16:48:18 -0400
Subject: a bunch more typing fixes.

---
 src/client/views/PreviewCursor.tsx | 51 ++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 22 deletions(-)

(limited to 'src/client/views/PreviewCursor.tsx')

diff --git a/src/client/views/PreviewCursor.tsx b/src/client/views/PreviewCursor.tsx
index 034ade50b..7e597879d 100644
--- a/src/client/views/PreviewCursor.tsx
+++ b/src/client/views/PreviewCursor.tsx
@@ -7,13 +7,14 @@ import { Docs, DocumentOptions } from '../documents/Documents';
 import { DocUtils } from '../documents/DocUtils';
 import { ImageUtils } from '../util/Import & Export/ImageUtils';
 import { Transform } from '../util/Transform';
-import { UndoManager, undoBatch } from '../util/UndoManager';
+import { UndoManager, undoable } from '../util/UndoManager';
 import { ObservableReactComponent } from './ObservableReactComponent';
 import './PreviewCursor.scss';
 import { FormattedTextBox } from './nodes/formattedText/FormattedTextBox';
+import { StrCast } from '../../fields/Types';
 
 @observer
-export class PreviewCursor extends ObservableReactComponent<{}> {
+export class PreviewCursor extends ObservableReactComponent<object> {
     // eslint-disable-next-line no-use-before-define
     static _instance: PreviewCursor;
     public static get Instance() {
@@ -29,7 +30,7 @@ export class PreviewCursor extends ObservableReactComponent<{}> {
     @observable _clickPoint: number[] = [];
     @observable public Visible = false;
     public Doc: Opt<Doc>;
-    constructor(props: any) {
+    constructor(props: object) {
         super(props);
         makeObservable(this);
         PreviewCursor._instance = this;
@@ -46,7 +47,7 @@ export class PreviewCursor extends ObservableReactComponent<{}> {
             });
 
             // tests for URL and makes web document
-            const re: any = /^https?:\/\//g;
+            const re = /^https?:\/\//g;
             const plain = e.clipboardData.getData('text/plain');
             if (plain && newPoint) {
                 // tests for youtube and makes video document
@@ -64,17 +65,19 @@ export class PreviewCursor extends ObservableReactComponent<{}> {
                 } else if (re.test(plain)) {
                     const url = plain;
                     if (!url.startsWith(window.location.href)) {
-                        undoBatch(() =>
-                            this._addDocument?.(
-                                Docs.Create.WebDocument(url, {
-                                    title: url,
-                                    _width: 500,
-                                    _height: 300,
-                                    data_useCors: true,
-                                    x: newPoint[0],
-                                    y: newPoint[1],
-                                })
-                            )
+                        undoable(
+                            () =>
+                                this._addDocument?.(
+                                    Docs.Create.WebDocument(url, {
+                                        title: url,
+                                        _width: 500,
+                                        _height: 300,
+                                        data_useCors: true,
+                                        x: newPoint[0],
+                                        y: newPoint[1],
+                                    })
+                                ),
+                            'paste web doc'
                         )();
                     } else alert('cannot paste dash into itself');
                 } else if (plain.startsWith('__DashDocId(') || plain.startsWith('__DashCloneId(')) {
@@ -94,11 +97,11 @@ export class PreviewCursor extends ObservableReactComponent<{}> {
             }
             // pasting in images
             else if (e.clipboardData.getData('text/html') !== '' && e.clipboardData.getData('text/html').includes('<img src=')) {
-                const regEx: any = /<img src="(.*?)"/g;
-                const arr: any[] = regEx.exec(e.clipboardData.getData('text/html'));
+                const regEx = /<img src="(.*?)"/g;
+                const arr = regEx.exec(e.clipboardData.getData('text/html'));
 
-                if (newPoint) {
-                    undoBatch(() => {
+                if (newPoint && arr) {
+                    undoable(() => {
                         const doc = Docs.Create.ImageDocument(arr[1], {
                             _width: 300,
                             title: arr[1],
@@ -107,7 +110,7 @@ export class PreviewCursor extends ObservableReactComponent<{}> {
                         });
                         ImageUtils.ExtractImgInfo(doc);
                         this._addDocument?.(doc);
-                    })();
+                    }, 'paste image doc')();
                 }
             } else if (e.clipboardData.items.length && newPoint) {
                 const batch = UndoManager.StartBatch('collection view drop');
@@ -196,8 +199,12 @@ export class PreviewCursor extends ObservableReactComponent<{}> {
     }
     render() {
         return !this._clickPoint || !this.Visible ? null : (
-            // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
-            <div className="previewCursor" onBlur={this.onBlur} tabIndex={0} ref={e => e?.focus()} style={{ color: lightOrDark(this.Doc?.backgroundColor ?? 'white'), transform: `translate(${this._clickPoint[0]}px, ${this._clickPoint[1]}px)` }}>
+            <div
+                className="previewCursor"
+                onBlur={this.onBlur}
+                tabIndex={0}
+                ref={e => e?.focus()}
+                style={{ color: lightOrDark(StrCast(this.Doc?.backgroundColor, 'white')), transform: `translate(${this._clickPoint[0]}px, ${this._clickPoint[1]}px)` }}>
                 I
             </div>
         );
-- 
cgit v1.2.3-70-g09d2

