diff options
author | Sophie Zhang <sophie_zhang@brown.edu> | 2023-08-18 17:41:51 -0400 |
---|---|---|
committer | Sophie Zhang <sophie_zhang@brown.edu> | 2023-08-18 17:41:51 -0400 |
commit | ad2f3695ddfb4a7bec17ddbdf6e7011862936bc4 (patch) | |
tree | 05333c5bfaa7342829ff550388778db9e363d5b1 /src | |
parent | bce4589c0bd871437c83bf44a6a818d01b9bf0f2 (diff) |
added gen_fill_children field
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 37 | ||||
-rw-r--r-- | src/client/views/nodes/generativeFill/GenerativeFill.tsx | 24 | ||||
-rw-r--r-- | src/client/views/pdf/GPTPopup/GPTPopup.tsx | 5 |
3 files changed, 16 insertions, 50 deletions
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index fd30c43d7..daf8719eb 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -946,46 +946,9 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FieldViewProps console.log('Generate image from text: ', (this.dataDoc.text as RichTextField)?.Text); GPTPopup.Instance?.setTextAnchor(this.getAnchor(false)); GPTPopup.Instance?.setImgTargetDoc(this.rootDoc); - // GPTPopup.Instance.setImgUrls([]); - // GPTPopup.Instance.setMode(GPTPopupMode.IMAGE); - // GPTPopup.Instance.setVisible(true); GPTPopup.Instance.addToCollection = this.props.addDocument; - // GPTPopup.Instance.setLoading(true); GPTPopup.Instance.setImgDesc((this.dataDoc.text as RichTextField)?.Text); GPTPopup.Instance.generateImage(); - - // try { - // // make this support multiple images - // let image_urls = await gptImageCall((this.dataDoc.text as RichTextField)?.Text); - // console.log(image_urls); - // if (image_urls) { - // const [result] = await Networking.PostToServer('/uploadRemoteImage', { sources: [image_urls[0]] }); - // const source = Utils.prepend(result.accessPaths.agnostic.client); - // GPTPopup.Instance.setImgUrls([source]); - - // // const newDoc = Docs.Create.ImageDocument(source, { - // // x: NumCast(this.rootDoc.x) + NumCast(this.layoutDoc._width) + 10, - // // y: NumCast(this.rootDoc.y), - // // _height: 200, - // // _width: 200, - // // data_nativeWidth: result.nativeWidth, - // // data_nativeHeight: result.nativeHeight, - // // }); - // // if (Doc.IsInMyOverlay(this.rootDoc)) { - // // newDoc.overlayX = this.rootDoc.x; - // // newDoc.overlayY = NumCast(this.rootDoc.y) + NumCast(this.rootDoc._height); - // // Doc.AddToMyOverlay(newDoc); - // // } else { - // // this.props.addDocument?.(newDoc); - // // } - // // // Create link between prompt and image - // // DocUtils.MakeLink(this.rootDoc, newDoc, { link_relationship: 'Image Prompt' }); - // } - // } catch (err) { - // console.log(err); - // return ''; - // } - // GPTPopup.Instance.setLoading(false); }; breakupDictation = () => { diff --git a/src/client/views/nodes/generativeFill/GenerativeFill.tsx b/src/client/views/nodes/generativeFill/GenerativeFill.tsx index 92ce3a8a8..06819d08c 100644 --- a/src/client/views/nodes/generativeFill/GenerativeFill.tsx +++ b/src/client/views/nodes/generativeFill/GenerativeFill.tsx @@ -12,12 +12,11 @@ import { CiUndo, CiRedo } from 'react-icons/ci'; import { MainView } from '../../MainView'; import { Doc, DocListCast } from '../../../../fields/Doc'; import { Networking } from '../../../Network'; -import { Utils, returnEmptyDoclist } from '../../../../Utils'; +import { Utils } from '../../../../Utils'; import { DocUtils, Docs } from '../../../documents/Documents'; -import { DocCast, NumCast } from '../../../../fields/Types'; +import { NumCast } from '../../../../fields/Types'; import { CollectionDockingView } from '../../collections/CollectionDockingView'; import { OpenWhereMod } from '../DocumentView'; -import { Oval } from 'react-loader-spinner'; import Buttons from './GenerativeFillButtons'; import { List } from '../../../../fields/List'; @@ -314,12 +313,13 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD const adjustImgPositions = () => { if (!parentDoc.current) return; const startY = NumCast(parentDoc.current.y); - const len = childrenDocs.current.length; + const children = DocListCast(parentDoc.current.gen_fill_children); + const len = children.length; let initialYPositions: number[] = []; for (let i = 0; i < len; i++) { initialYPositions.push(startY + i * offsetDistanceY); } - childrenDocs.current.forEach((doc, i) => { + children.forEach((doc, i) => { if (len % 2 === 1) { doc.y = initialYPositions[i] - Math.floor(len / 2) * offsetDistanceY; } else { @@ -368,9 +368,15 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD data_nativeWidth: result.nativeWidth, data_nativeHeight: result.nativeHeight, }); - newImg.gen_fill_children = new List<Doc>([]); - childrenDocs.current.push(newImg); - // DocListCast(parentDoc.current.gen_fill_children).push(newImg); + + const parentList = DocListCast(parentDoc.current.gen_fill_children); + if (parentList.length > 0) { + parentList.push(newImg); + parentDoc.current.gen_fill_children = new List<Doc>(parentList); + } else { + parentDoc.current.gen_fill_children = new List<Doc>([newImg]); + } + DocUtils.MakeLink(parentDoc.current, newImg, { link_relationship: `Image edit; Prompt: ${input}`, link_displayLine: true }); adjustImgPositions(); @@ -408,7 +414,7 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD return ( <div className="generativeFillContainer" style={{ display: imageEditorOpen ? 'flex' : 'none' }}> <div className="generativeFillControls"> - <h1>AI Image Editor</h1> + <h1>Image Editor</h1> <div style={{ display: 'flex', alignItems: 'center', gap: '1.5rem' }}> <FormControlLabel control={ diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index 943c38d42..43fd8df16 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -11,8 +11,7 @@ import { Button, IconButton, Type } from 'browndash-components'; import { NumCast, StrCast } from '../../../../fields/Types'; import { CgClose } from 'react-icons/cg'; import { AnchorMenu } from '../AnchorMenu'; -import { gptAPICall, gptImageCall } from '../../../apis/gpt/GPT'; -import { RichTextField } from '../../../../fields/RichTextField'; +import { gptImageCall } from '../../../apis/gpt/GPT'; import { Networking } from '../../../Network'; import { Utils } from '../../../../Utils'; @@ -122,9 +121,7 @@ export class GPTPopup extends React.Component<GPTPopupProps> { this.setLoading(true); try { - // make this support multiple images let image_urls = await gptImageCall(this.imgDesc); - console.log(image_urls); if (image_urls && image_urls[0]) { const [result] = await Networking.PostToServer('/uploadRemoteImage', { sources: [image_urls[0]] }); const source = Utils.prepend(result.accessPaths.agnostic.client); |