aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/util/bezierFit.ts3
-rw-r--r--src/client/views/MainView.tsx32
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx3
-rw-r--r--src/client/views/pdf/AnchorMenu.tsx9
-rw-r--r--src/client/views/smartdraw/SmartDrawHandler.tsx29
5 files changed, 54 insertions, 22 deletions
diff --git a/src/client/util/bezierFit.ts b/src/client/util/bezierFit.ts
index d52460023..84b27e84c 100644
--- a/src/client/util/bezierFit.ts
+++ b/src/client/util/bezierFit.ts
@@ -703,7 +703,6 @@ export function SVGToBezier(name: SVGType, attributes: any): Point[] {
coordList.push({ X: parseInt(match[1]), Y: parseInt(match[2]) });
coordList.push({ X: parseInt(match[1]), Y: parseInt(match[2]) });
coordList.push({ X: parseInt(match[3]), Y: parseInt(match[4]) });
- coordList.push({ X: parseInt(match[3]), Y: parseInt(match[4]) });
lastPt = { X: parseInt(match[3]), Y: parseInt(match[4]) };
} else if (match[0].startsWith('C')) {
coordList.push({ X: parseInt(match[5]), Y: parseInt(match[6]) });
@@ -720,7 +719,7 @@ export function SVGToBezier(name: SVGType, attributes: any): Point[] {
}
});
const hasZ = attributes.d.match(/Z/);
- if (hasZ) {
+ if (hasZ || attributes.fill) {
coordList.push(lastPt);
coordList.push(startPt);
coordList.push(startPt);
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 7779d339f..0d071fe4f 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -8,7 +8,7 @@ import { observer } from 'mobx-react';
import * as React from 'react';
import ResizeObserver from 'resize-observer-polyfill';
import '../../../node_modules/browndash-components/dist/styles/global.min.css';
-import { ClientUtils, lightOrDark, returnEmptyFilter, returnFalse, returnTrue, returnZero, setupMoveUpEvents } from '../../ClientUtils';
+import { ClientUtils, returnEmptyFilter, returnFalse, returnTrue, returnZero, setupMoveUpEvents } from '../../ClientUtils';
import { emptyFunction } from '../../Utils';
import { Doc, DocListCast, GetDocFromUrl, Opt, returnEmptyDoclist } from '../../fields/Doc';
import { DocData } from '../../fields/DocSymbols';
@@ -1023,10 +1023,36 @@ export class MainView extends ObservableReactComponent<object> {
<svg style={{ width: '100%', height: '100%' }}>
{[
...SnappingManager.HorizSnapLines.map(l => (
- <line key={'horiz' + l} x1="0" y1={l} x2="2000" y2={l} stroke={lightOrDark(StrCast(dragPar.layoutDoc.backgroundColor, 'gray'))} opacity={0.3} strokeWidth={1} strokeDasharray="2 2" />
+ <line
+ key={'horiz' + l}
+ x1="0"
+ y1={l}
+ x2="2000"
+ y2={l}
+ stroke={
+ SnappingManager.userVariantColor
+ /* lightOrDark(StrCast(dragPar.layoutDoc.backgroundColor, 'gray'))*/
+ }
+ opacity={0.3}
+ strokeWidth={3}
+ strokeDasharray="2 2"
+ />
)),
...SnappingManager.VertSnapLines.map(l => (
- <line key={'vert' + l} y1={this.topOfMainDocContent.toString()} x1={l} y2="2000" x2={l} stroke={lightOrDark(StrCast(dragPar.layoutDoc.backgroundColor, 'gray'))} opacity={0.3} strokeWidth={1} strokeDasharray="2 2" />
+ <line
+ key={'vert' + l}
+ y1={this.topOfMainDocContent.toString()}
+ x1={l}
+ y2="2000"
+ x2={l}
+ stroke={
+ SnappingManager.userVariantColor
+ /* lightOrDark(StrCast(dragPar.layoutDoc.backgroundColor, 'gray'))*/
+ }
+ opacity={0.3}
+ strokeWidth={3}
+ strokeDasharray="2 2"
+ />
)),
]}
</svg>
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index a61705250..3ef6bdd8b 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -431,7 +431,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
doc = Docs.Create.FunctionPlotDocument([], options);
break;
case 'dataviz':
- case 'data_viz':
+ case 'data_viz': {
const { fileUrl, id } = await Networking.PostToServer('/createCSV', {
filename: (options.title as string).replace(/\s+/g, '') + '.csv',
data: data,
@@ -439,6 +439,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
doc = Docs.Create.DataVizDocument(fileUrl, { ...options, text: RTFCast(data) });
this.addCSVForAnalysis(doc, id);
break;
+ }
case 'chat':
doc = Docs.Create.ChatDocument(options);
break;
diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx
index 5ab9b556c..fe03f32a5 100644
--- a/src/client/views/pdf/AnchorMenu.tsx
+++ b/src/client/views/pdf/AnchorMenu.tsx
@@ -131,12 +131,15 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
/**
* Creates a GPT drawing based on selected text.
*/
- gptDraw = async (e: React.PointerEvent) => {
+ gptDraw = (e: React.PointerEvent) => {
try {
SmartDrawHandler.Instance.AddDrawing = this.createDrawingAnnotation;
runInAction(() => (this._isLoading = true));
- await SmartDrawHandler.Instance.drawWithGPT({ X: e.clientX, Y: e.clientY }, this._selectedText, 5, 100, true);
- runInAction(() => (this._isLoading = false));
+ SmartDrawHandler.Instance.drawWithGPT({ X: e.clientX, Y: e.clientY }, this._selectedText, 5, 100, true)?.then(
+ action(() => {
+ this._isLoading = false;
+ })
+ );
} catch (err) {
console.error(err);
}
diff --git a/src/client/views/smartdraw/SmartDrawHandler.tsx b/src/client/views/smartdraw/SmartDrawHandler.tsx
index d0f6566a5..342b91bd9 100644
--- a/src/client/views/smartdraw/SmartDrawHandler.tsx
+++ b/src/client/views/smartdraw/SmartDrawHandler.tsx
@@ -13,6 +13,7 @@ import { Doc, DocListCast } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
import { InkData, InkField, InkTool } from '../../../fields/InkField';
import { BoolCast, ImageCast, NumCast, StrCast } from '../../../fields/Types';
+import { Networking } from '../../Network';
import { GPTCallType, gptAPICall, gptDrawingColor } from '../../apis/gpt/GPT';
import { Docs } from '../../documents/Documents';
import { SettingsManager } from '../../util/SettingsManager';
@@ -21,7 +22,8 @@ import { SVGToBezier, SVGType } from '../../util/bezierFit';
import { InkingStroke } from '../InkingStroke';
import { ObservableReactComponent } from '../ObservableReactComponent';
import { MarqueeView } from '../collections/collectionFreeForm';
-import { ActiveInkArrowEnd, ActiveInkArrowStart, ActiveInkDash, ActiveInkFillColor, ActiveInkBezierApprox, ActiveInkColor, ActiveInkWidth, ActiveIsInkMask, DocumentView } from '../nodes/DocumentView';
+import { ActiveInkArrowEnd, ActiveInkArrowStart, ActiveInkBezierApprox, ActiveInkColor, ActiveInkDash, ActiveInkFillColor, ActiveInkWidth, ActiveIsInkMask, DocumentView, DocumentViewInternal } from '../nodes/DocumentView';
+import { OpenWhere } from '../nodes/OpenWhere';
import './SmartDrawHandler.scss';
export interface DrawingOptions {
@@ -230,20 +232,21 @@ export class SmartDrawHandler extends ObservableReactComponent<object> {
* 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;
- this._lastInput = { text: input, complexity: complexity, size: size, autoColor: autoColor, x: startPt.X, y: startPt.Y };
- const res = await gptAPICall(`"${input}", "${complexity}", "${size}"`, GPTCallType.DRAW, undefined, true);
- if (!res) {
- console.error('GPT call failed');
- return;
- }
- const strokeData = await this.parseSvg(res, startPt, false, autoColor);
- const drawingDoc = strokeData && this.CreateDrawingDoc(strokeData.data, strokeData.lastInput, strokeData.lastRes);
- drawingDoc && this.AddDrawing(drawingDoc, this._lastInput, res);
+ drawWithGPT = (startPt: { X: number; Y: number }, prompt: string, complexity: number, size: number, autoColor: boolean) => {
+ if (prompt === '') return;
+ this._lastInput = { text: prompt, complexity: complexity, size: size, autoColor: autoColor, x: startPt.X, y: startPt.Y };
+
+ Networking.PostToServer('/queryFireflyImage', { prompt }).then(img => DocumentViewInternal.addDocTabFunc(Docs.Create.ImageDocument(img, { title: prompt }), OpenWhere.addRight));
+
+ const result = gptAPICall(`"${prompt}", "${complexity}", "${size}"`, GPTCallType.DRAW, undefined, true).then(res =>
+ this.parseSvg(res, startPt, false, autoColor).then(strokeData => {
+ const drawingDoc = strokeData && this.CreateDrawingDoc(strokeData.data, strokeData.lastInput, strokeData.lastRes);
+ drawingDoc && this.AddDrawing(drawingDoc, this._lastInput, res);
+ })
+ );
this._errorOccurredOnce = false;
- return strokeData;
+ return result;
};
/**