aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ImageBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/ImageBox.tsx')
-rw-r--r--src/client/views/nodes/ImageBox.tsx26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 32d1e471e..31f6df2ea 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -25,7 +25,7 @@ import { Networking } from '../../Network';
import { DragManager } from '../../util/DragManager';
import { dropActionType } from '../../util/DropActionTypes';
import { SnappingManager } from '../../util/SnappingManager';
-import { undoBatch } from '../../util/UndoManager';
+import { undoable, undoBatch } from '../../util/UndoManager';
import { CollectionFreeFormView } from '../collections/collectionFreeForm/CollectionFreeFormView';
import { ContextMenu } from '../ContextMenu';
import { ContextMenuProps } from '../ContextMenuItem';
@@ -195,8 +195,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
const images = await this.fetchImages();
};
- @undoBatch
- drop = (e: Event, de: DragManager.DropEvent) => {
+ drop = undoable((e: Event, de: DragManager.DropEvent) => {
if (de.complete.docDragData) {
let added: boolean | undefined;
const targetIsBullseye = (ele: HTMLElement): boolean => {
@@ -225,7 +224,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
return added;
}
return false;
- };
+ }, 'image drop');
@undoBatch
resolution = () => {
@@ -316,15 +315,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
return cropping;
};
- /**
- * Draw image to a canvas so it can be converted to base64 and be passed into
- * GPT to be analyzed.
- * @param downX
- * @param downY
- * @param cb
- * @returns
- */
- createCanvas = async (downX?: number, downY?: number, cb?: (filename: string, x: number | undefined, y: number | undefined) => void) => {
+ createCanvas = async () => {
const canvas = document.createElement('canvas');
const scaling = 1 / (this._props.NativeDimScaling?.() || 1);
const w = AnchorMenu.Instance.marqueeWidth * scaling;
@@ -407,9 +398,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
* @param texts
*/
createBoxes = (boxes: [[[number, number]]], texts: [string]) => {
- const nscale = NumCast(this._props.PanelWidth()) * NumCast(this.layoutDoc._freeform_scale, 1);
- const nw = nscale / NumCast(this.dataDoc[this.fieldKey + '_nativeWidth']);
- for (var i = 0; i < boxes.length; i++) {
+ for (let i = 0; i < boxes.length; i++) {
const coords = boxes[i] ? boxes[i] : [];
const width = coords[1][0] - coords[0][0];
const height = coords[2][1] - coords[0][1];
@@ -446,7 +435,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
const response = await gptImageLabel(hrefBase64, 'Make flashcards out of this image with each question and answer labeled as "question" and "answer". Do not label each flashcard and do not include asterisks: ');
AnchorMenu.Instance.transferToFlashcard(response, NumCast(this.layoutDoc['x']), NumCast(this.layoutDoc['y']));
} catch (error) {
- console.log('Error');
+ console.log('Error', error);
}
this._loading = false;
};
@@ -461,7 +450,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
const hrefBase64 = await this.createCanvas();
this.pushInfo(quizMode.NORMAL, hrefBase64);
} catch (error) {
- console.log('Error');
+ console.log('Error', error);
}
};
@@ -877,7 +866,6 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
}}>
<CollectionFreeFormView
ref={this._ffref}
- // eslint-disable-next-line react/jsx-props-no-spreading
{...this._props}
setContentViewBox={emptyFunction}
NativeWidth={returnZero}