aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/PreviewCursor.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/PreviewCursor.tsx
parentc01828308714874589d1f60c33ca59df4c656c0c (diff)
parenta958577d4c27b276aa37484e3f895e196138b17c (diff)
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/client/views/PreviewCursor.tsx')
-rw-r--r--src/client/views/PreviewCursor.tsx51
1 files changed, 29 insertions, 22 deletions
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>
);