diff options
Diffstat (limited to 'src')
5 files changed, 9 insertions, 64 deletions
diff --git a/src/client/views/nodes/generativeFill/GenerativeFill.tsx b/src/client/views/nodes/generativeFill/GenerativeFill.tsx index 06819d08c..547a76348 100644 --- a/src/client/views/nodes/generativeFill/GenerativeFill.tsx +++ b/src/client/views/nodes/generativeFill/GenerativeFill.tsx @@ -33,7 +33,7 @@ interface GenerativeFillProps { addDoc: ((doc: Doc | Doc[], annotationKey?: string) => boolean) | undefined; } -// New field on image doc: gen_fill_children => list of children Docs +// Added field on image doc: gen_fill_children: List of children Docs const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addDoc }: GenerativeFillProps) => { const canvasRef = useRef<HTMLCanvasElement>(null); @@ -191,6 +191,7 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD }; }, [canvasRef, imageEditorSource]); + // once the appropriate dimensions are set, draw the image to the canvas useEffect(() => { if (!currImg.current) return; ImageUtility.drawImgToCanvas(currImg.current, canvasRef, canvasDims.width, canvasDims.height); @@ -338,7 +339,6 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD if (firstDoc) { const x = 0; const initialY = 0; - const newImg = Docs.Create.ImageDocument(source, { x: x, y: initialY, @@ -347,7 +347,6 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD data_nativeWidth: result.nativeWidth, data_nativeHeight: result.nativeHeight, }); - // add a new doc list field to newimg if (isNewCollection && newCollectionRef.current) { Doc.AddDocToList(newCollectionRef.current, undefined, newImg); } else { @@ -389,6 +388,7 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD } }; + // Saves an image to the collection const onSave = async (src: string) => { const img = new Image(); img.src = src; @@ -401,13 +401,13 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD } }; + // Closes the editor view const handleViewClose = () => { MainView.Instance.setImageEditorOpen(false); MainView.Instance.setImageEditorSource(''); if (newCollectionRef.current) { newCollectionRef.current.fitContentOnce = true; } - setEdits([]); }; @@ -419,7 +419,7 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD <FormControlLabel control={ <Checkbox - // disable once edited has been clicked + // disable once edited has been clicked (doesn't make sense to change after first edit) disabled={edited} checked={isNewCollection} onChange={e => { @@ -431,7 +431,7 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD labelPlacement="end" sx={{ whiteSpace: 'nowrap' }} /> - <Buttons canvasRef={canvasRef} currImg={currImg} getEdit={getEdit} loading={loading} onReset={handleReset} /> + <Buttons getEdit={getEdit} loading={loading} onReset={handleReset} /> <IconButton onClick={handleViewClose}> <BsX color={activeColor} /> </IconButton> diff --git a/src/client/views/nodes/generativeFill/GenerativeFillButtons.tsx b/src/client/views/nodes/generativeFill/GenerativeFillButtons.tsx index e15af0a56..398ba5333 100644 --- a/src/client/views/nodes/generativeFill/GenerativeFillButtons.tsx +++ b/src/client/views/nodes/generativeFill/GenerativeFillButtons.tsx @@ -1,14 +1,9 @@ import { Button } from '@mui/material'; -import { ImageUtility } from './generativeFillUtils/ImageHandler'; -import { canvasSize } from './generativeFillUtils/generativeFillConstants'; import { Oval } from 'react-loader-spinner'; import './GenerativeFillButtons.scss'; import React = require('react'); -import { Doc } from '../../../../fields/Doc'; interface ButtonContainerProps { - canvasRef: React.RefObject<HTMLCanvasElement>; - currImg: React.MutableRefObject<HTMLImageElement | null>; getEdit: () => Promise<void>; loading: boolean; onReset: () => void; diff --git a/src/client/views/nodes/generativeFill/generativeFillUtils/BrushHandler.ts b/src/client/views/nodes/generativeFill/generativeFillUtils/BrushHandler.ts index f84f04190..ace7ebcae 100644 --- a/src/client/views/nodes/generativeFill/generativeFillUtils/BrushHandler.ts +++ b/src/client/views/nodes/generativeFill/generativeFillUtils/BrushHandler.ts @@ -15,7 +15,6 @@ export class BrushHandler { static brushCircleOverlay = (x: number, y: number, brushRadius: number, ctx: CanvasRenderingContext2D, fillColor: string, erase: boolean) => { ctx.globalCompositeOperation = 'destination-out'; - // ctx.globalCompositeOperation = erase ? "destination-out" : "source-over"; ctx.fillStyle = fillColor; ctx.shadowColor = eraserColor; ctx.shadowBlur = 5; diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index 10cf50dff..b0924888a 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -149,54 +149,6 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { GPTPopup.Instance.setLoading(false); }; - /** - * Makes a GPT call to edit selected text. - * @returns nothing - */ - gptEdit = async () => { - if (!this.editorView) return; - this.setHighlightRange(undefined); - const state = this.editorView.state; - const sel = state.selection; - const fullText = state.doc.textBetween(0, this.editorView.state.doc.content.size, ' \n'); - const selectedText = state.doc.textBetween(sel.from, sel.to); - - GPTPopup.Instance.setVisible(true); - this.setGPTMode(GPTPopupMode.EDIT); - GPTPopup.Instance.setLoading(true); - - try { - let res = await gptAPICall(selectedText, GPTCallType.EDIT); - // let res = await this.mockGPTCall(); - if (!res) return; - res = res.trim(); - const resultText = fullText.slice(0, sel.from - 1) + res + fullText.slice(sel.to - 1); - - if (res) { - GPTPopup.Instance.setText(resultText); - this.setHighlightRange([sel.from - 1, sel.from - 1 + res.length]); - } else { - GPTPopup.Instance.setText('Something went wrong.'); - } - } catch (err) { - console.error(err); - } - - GPTPopup.Instance.setLoading(false); - }; - - gptImage = async () => { - console.log(this.GetAnchor(undefined, false)); - }; - - /** - * Replaces text suggestions from GPT. - */ - replaceText = (replacement: string) => { - if (!this.editorView || !this.textDoc) return; - this.textDoc.text = replacement; - }; - pointerDown = (e: React.PointerEvent) => { setupMoveUpEvents( this, @@ -313,9 +265,6 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { color={StrCast(Doc.UserDoc().userColor)} /> )} - {/* Removed text editing for now, not quite ready */} - {/* {this.canEdit() && <IconButton tooltip={'AI edit suggestions'} onPointerDown={this.gptEdit} icon={<FontAwesomeIcon icon="pencil-alt" />} color={StrCast(Doc.UserDoc().userColor)} />} */} - {<IconButton tooltip={'Generate DALL-E Image'} onPointerDown={this.gptImage} icon={<FontAwesomeIcon icon="image" />} color={StrCast(Doc.UserDoc().userColor)} />} <Popup tooltip="Find document to link to selected text" // type={Type.PRIM} diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index 43fd8df16..034470c6e 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -113,6 +113,9 @@ export class GPTPopup extends React.Component<GPTPopupProps> { public addDoc: (doc: Doc | Doc[], sidebarKey?: string | undefined) => boolean = () => false; public addToCollection: ((doc: Doc | Doc[], annotationKey?: string | undefined) => boolean) | undefined; + /** + * Generates a Dalle image and uploads it to the server. + */ generateImage = async () => { if (this.imgDesc === '') return; this.setImgUrls([]); @@ -125,7 +128,6 @@ export class GPTPopup extends React.Component<GPTPopupProps> { if (image_urls && image_urls[0]) { const [result] = await Networking.PostToServer('/uploadRemoteImage', { sources: [image_urls[0]] }); const source = Utils.prepend(result.accessPaths.agnostic.client); - console.log('Source', source); this.setImgUrls([[image_urls[0], source]]); } } catch (err) { |