aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/smartdraw/SmartDrawHandler.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/smartdraw/SmartDrawHandler.tsx')
-rw-r--r--src/client/views/smartdraw/SmartDrawHandler.tsx15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/client/views/smartdraw/SmartDrawHandler.tsx b/src/client/views/smartdraw/SmartDrawHandler.tsx
index 4ec787e07..368970f75 100644
--- a/src/client/views/smartdraw/SmartDrawHandler.tsx
+++ b/src/client/views/smartdraw/SmartDrawHandler.tsx
@@ -10,7 +10,7 @@ import { AiOutlineSend } from 'react-icons/ai';
import { gptAPICall, GPTCallType, gptDrawingColor } from '../../apis/gpt/GPT';
import { InkData, InkField, InkTool } from '../../../fields/InkField';
import { SVGToBezier } from '../../util/bezierFit';
-const { parse } = require('svgson');
+import { INode, parse } from 'svgson';
import { Slider, Switch } from '@mui/material';
import { Doc, DocListCast } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
@@ -35,6 +35,7 @@ export interface DrawingOptions {
}
@observer
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export class SmartDrawHandler extends ObservableReactComponent<{}> {
static Instance: SmartDrawHandler;
@@ -59,7 +60,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
private _errorOccurredOnce = false;
public RemoveDrawing: (doc?: Doc) => void = unimplementedFunction;
- public CreateDrawingDoc: (strokeList: [InkData, string, string][], opts: DrawingOptions, gptRes: string, containerDoc?: Doc) => Doc | undefined = (strokeList: [InkData, string, string][], opts: DrawingOptions, gptRes: string) => {
+ public CreateDrawingDoc: (strokeList: [InkData, string, string][], opts: DrawingOptions, gptRes: string, containerDoc?: Doc) => Doc | undefined = (strokeList: [InkData, string, string][], opts: DrawingOptions) => {
const drawing: Doc[] = [];
strokeList.forEach((stroke: [InkData, string, string]) => {
const bounds = InkField.getBounds(stroke[0]);
@@ -89,6 +90,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
};
public AddDrawing: (doc: Doc, opts: DrawingOptions, gptRes: string) => void = unimplementedFunction;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(props: any) {
super(props);
makeObservable(this);
@@ -223,6 +225,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
console.log(res);
const strokeData = await this.parseSvg(res, startPt, false, autoColor);
const drawingDoc = strokeData && this.CreateDrawingDoc(strokeData?.data, strokeData?.lastInput, strokeData?.lastRes);
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
drawingDoc && this.AddDrawing(drawingDoc, this._lastInput, res);
this._errorOccurredOnce = false;
@@ -253,8 +256,10 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
}
console.log(res);
const strokeData = await this.parseSvg(res, { X: this._lastInput.x, Y: this._lastInput.y }, true, lastInput?.autoColor || this._autoColor);
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.RemoveDrawing !== unimplementedFunction && this.RemoveDrawing(this._selectedDoc);
const drawingDoc = strokeData && this.CreateDrawingDoc(strokeData?.data, strokeData?.lastInput, strokeData?.lastRes);
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
drawingDoc && this.AddDrawing(drawingDoc, this._lastInput, res);
return strokeData;
} catch (err) {
@@ -271,8 +276,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
if (svg) {
this._lastResponse = svg[0];
const svgObject = await parse(svg[0]);
- const svgStrokes: any = svgObject.children;
+ const svgStrokes: INode[] = svgObject.children;
const strokeData: [InkData, string, string][] = [];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
svgStrokes.forEach((child: any) => {
const convertedBezier: InkData = SVGToBezier(child.name, child.attributes);
strokeData.push([
@@ -318,7 +324,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
console.log(colorResponse);
this.colorStrokes(colorResponse, drawing);
} catch (error) {
- console.log('GPT call failed');
+ console.log('GPT call failed', error);
}
};
@@ -335,6 +341,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
strokes[index][DocData].color = strokeAndFill[0];
const inkStroke = DocumentView.getDocumentView(strokes[index])?.ComponentView as InkingStroke;
const { inkData } = inkStroke.inkScaledData();
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
InkingStroke.IsClosed(inkData) ? (strokes[index][DocData].fillColor = strokeAndFill[1]) : (strokes[index][DocData].fillColor = undefined);
}
});