aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/smartdraw
diff options
context:
space:
mode:
authoreleanor-park <eleanor_park@brown.edu>2024-08-27 16:22:33 -0400
committereleanor-park <eleanor_park@brown.edu>2024-08-27 16:22:33 -0400
commit6f73686ec4dc3e01ae3eacc0150aa59eafea0325 (patch)
tree392d6ebcb6122326441afbb7dfe69ff4cb583c1d /src/client/views/smartdraw
parentfd5278045e8c2e280d81cb965c0b2cc5afb59be8 (diff)
pulling from master
Diffstat (limited to 'src/client/views/smartdraw')
-rw-r--r--src/client/views/smartdraw/AnnotationPalette.tsx13
-rw-r--r--src/client/views/smartdraw/SmartDrawHandler.tsx22
2 files changed, 32 insertions, 3 deletions
diff --git a/src/client/views/smartdraw/AnnotationPalette.tsx b/src/client/views/smartdraw/AnnotationPalette.tsx
index 7e4d46204..7f00fa2f2 100644
--- a/src/client/views/smartdraw/AnnotationPalette.tsx
+++ b/src/client/views/smartdraw/AnnotationPalette.tsx
@@ -107,6 +107,10 @@ export class AnnotationPalette extends ObservableReactComponent<AnnotationPalett
this._props.Document[DocData].data = undefined;
};
+ /**
+ * Adds a doc to the annotation palette. Gets a snapshot of the document to use as a preview in the palette. When this
+ * preview is dragged onto a parent document, a copy of that document is added as an annotation.
+ */
public static addToPalette = async (doc: Doc) => {
if (!doc.savedAsAnno) {
const clone = await Doc.MakeClone(doc);
@@ -129,6 +133,10 @@ export class AnnotationPalette extends ObservableReactComponent<AnnotationPalett
return undefined;
}
+ /**
+ * Calls the draw with GPT functions in SmartDrawHandler to allow users to generate drawings straight from
+ * the annotation palette.
+ */
@undoBatch
generateDrawings = action(async () => {
this._isLoading = true;
@@ -159,6 +167,11 @@ export class AnnotationPalette extends ObservableReactComponent<AnnotationPalett
Doc.AddDocToList(this._props.Document, 'data', drawing);
};
+ /**
+ * Saves the currently showing, newly generated drawing to the annotation palette and sets the metadata.
+ * AddToPalette() is generically used to add any document to the palette, while this defines the behavior for when a user
+ * presses the "save drawing" button.
+ */
saveDrawing = async () => {
const cIndex: number = this._props.Document.carousel_index as number;
const focusedDrawing = DocListCast(this._props.Document.data)[cIndex];
diff --git a/src/client/views/smartdraw/SmartDrawHandler.tsx b/src/client/views/smartdraw/SmartDrawHandler.tsx
index 52df598ee..4ec787e07 100644
--- a/src/client/views/smartdraw/SmartDrawHandler.tsx
+++ b/src/client/views/smartdraw/SmartDrawHandler.tsx
@@ -208,6 +208,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
this._canInteract = true;
};
+ /**
+ * Calls GPT API to create a drawing based on user input
+ */
@action
drawWithGPT = async (startPt: { X: number; Y: number }, input: string, complexity: number, size: number, autoColor: boolean) => {
if (input === '') return;
@@ -226,6 +229,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
return strokeData;
};
+ /**
+ * Regenerates drawings with the option to add a specific regenerate prompt/request.
+ */
@action
regenerate = async (lastInput?: DrawingOptions, lastResponse?: string, regenInput?: string) => {
if (lastInput) this._lastInput = lastInput;
@@ -256,6 +262,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
}
};
+ /**
+ * Parses the svg code that GPT returns into Bezier curves.
+ */
@action
parseSvg = async (res: string, startPoint: { X: number; Y: number }, regenerate: boolean, autoColor: boolean) => {
const svg = res.match(/<svg[^>]*>([\s\S]*?)<\/svg>/g);
@@ -278,6 +287,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
}
};
+ /**
+ * Sends request to GPT API to recolor a selected ink document or group of ink documents.
+ */
colorWithGPT = async (drawing: Doc) => {
const img = await this.getIcon(drawing);
const { href } = (img as URLField).url;
@@ -310,6 +322,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
}
};
+ /**
+ * Function that parses the GPT color response and sets the selected stroke(s) to the new color.
+ */
@undoBatch
colorStrokes = (res: string, drawing: Doc) => {
const colorList = res.match(/\{.*?\}/g);
@@ -320,13 +335,14 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
strokes[index][DocData].color = strokeAndFill[0];
const inkStroke = DocumentView.getDocumentView(strokes[index])?.ComponentView as InkingStroke;
const { inkData } = inkStroke.inkScaledData();
- if (InkingStroke.IsClosed(inkData)) {
- strokes[index][DocData].fillColor = strokeAndFill[1];
- }
+ InkingStroke.IsClosed(inkData) ? (strokes[index][DocData].fillColor = strokeAndFill[1]) : (strokes[index][DocData].fillColor = undefined);
}
});
};
+ /**
+ * Gets an image snapshot of a doc. In this class, it's used to snapshot a selected ink stroke/group to use for GPT color.
+ */
async getIcon(doc: Doc) {
const docView = DocumentView.getDocumentView(doc);
console.log(doc);