diff options
-rw-r--r-- | src/client/views/nodes/ImageBox.tsx | 24 | ||||
-rw-r--r-- | src/client/views/smartdraw/FireflyConstants.ts | 7 | ||||
-rw-r--r-- | src/client/views/smartdraw/SmartDrawHandler.tsx | 9 |
3 files changed, 27 insertions, 13 deletions
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index 09daea6bb..a1fa9a283 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -45,6 +45,7 @@ import { Button } from 'browndash-components'; import { SettingsManager } from '../../util/SettingsManager'; import { AiOutlineSend } from 'react-icons/ai'; import { returnEmptyDocViewList } from '../StyleProvider'; +import { FireflyImageData } from '../smartdraw/FireflyConstants'; export class ImageEditorData { // eslint-disable-next-line no-use-before-define @@ -533,7 +534,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { @observable private _regenInput = ''; @observable private _canInteract = true; @observable private _regenerateLoading = false; - @observable private _prevImgs: { href: string; pathname: string }[] = []; + @observable private _prevImgs: FireflyImageData[] = []; componentAIViewHistory = () => { return ( @@ -544,6 +545,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { src={img.href} onClick={() => { this.dataDoc[this.fieldKey] = new ImageField(img.pathname); + this.dataDoc.ai_firefly_prompt = img.prompt; + this.dataDoc.ai_firefly_seed = img.seed; }} /> ))} @@ -580,14 +583,17 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { onClick={undoable( action(async () => { this._regenerateLoading = true; - SmartDrawHandler.Instance.regenerate([this.Document], undefined, undefined, this._regenInput, true).then(newDocs => { - const url = newDocs[0]; - const imgField = new ImageField(url); - this._prevImgs.length === 0 && this._prevImgs.push({ href: this.paths.lastElement(), pathname: field.url.pathname }); - this.dataDoc[this.fieldKey] = imgField; - this._prevImgs.unshift({ href: this.paths.lastElement(), pathname: url }); - this._regenerateLoading = false; - this._regenInput = ''; + SmartDrawHandler.Instance.regenerate([this.Document], undefined, undefined, this._regenInput, true).then(newImgs => { + if (newImgs[0]) { + const url = newImgs[0].pathname; + const imgField = new ImageField(url); + this._prevImgs.length === 0 && + this._prevImgs.push({ prompt: StrCast(this.dataDoc.ai_firefly_prompt), seed: NumCast(this.dataDoc.ai_firefly_seed), href: this.paths.lastElement(), pathname: field.url.pathname }); + this.dataDoc[this.fieldKey] = imgField; + this._prevImgs.unshift({ prompt: newImgs[0].prompt, seed: newImgs[0].seed, href: this.paths.lastElement(), pathname: url }); + this._regenerateLoading = false; + this._regenInput = ''; + } }); }), 'regenerate image' diff --git a/src/client/views/smartdraw/FireflyConstants.ts b/src/client/views/smartdraw/FireflyConstants.ts index 3574039e4..1f1781617 100644 --- a/src/client/views/smartdraw/FireflyConstants.ts +++ b/src/client/views/smartdraw/FireflyConstants.ts @@ -1,3 +1,10 @@ +export interface FireflyImageData { + prompt: string; + seed: number | undefined; + pathname: string; + href?: string; +} + export enum FireflyImageDimensions { Square = 'square', Landscape = 'landscape', diff --git a/src/client/views/smartdraw/SmartDrawHandler.tsx b/src/client/views/smartdraw/SmartDrawHandler.tsx index 13a93367c..5ebe2e358 100644 --- a/src/client/views/smartdraw/SmartDrawHandler.tsx +++ b/src/client/views/smartdraw/SmartDrawHandler.tsx @@ -25,7 +25,7 @@ import { ActiveInkArrowEnd, ActiveInkArrowStart, ActiveInkDash, ActiveInkFillCol import './SmartDrawHandler.scss'; import { Networking } from '../../Network'; import { OpenWhere } from '../nodes/OpenWhere'; -import { FireflyDimensionsMap, FireflyImageDimensions } from './FireflyConstants'; +import { FireflyDimensionsMap, FireflyImageDimensions, FireflyImageData } from './FireflyConstants'; export interface DrawingOptions { text: string; @@ -267,23 +267,24 @@ export class SmartDrawHandler extends ObservableReactComponent<object> { /** * Calls Firefly API to create an image based on user input */ - createImageWithFirefly = (input: string, seed?: number, changeInPlace?: boolean) => { + createImageWithFirefly = (input: string, seed?: number, changeInPlace?: boolean): Promise<FireflyImageData> => { this._lastInput.text = input; const dims = FireflyDimensionsMap[this._imgDims]; return Networking.PostToServer('/queryFireflyImage', { prompt: input, width: dims.width, height: dims.height, seed: seed }).then(img => { if (!changeInPlace) { + const seed = img.accessPaths.agnostic.client.match(/\/(\d+)upload/)[1]; const imgDoc: Doc = Docs.Create.ImageDocument(img.accessPaths.agnostic.client, { title: input.match(/^(.*?)~~~.*$/)?.[1] || input, nativeWidth: dims.width, nativeHeight: dims.height, ai: 'firefly', - ai_firefly_seed: img.accessPaths.agnostic.client.match(/\/(\d+)upload/)[1], + ai_firefly_seed: seed, ai_firefly_prompt: input, }); DocumentViewInternal.addDocTabFunc(imgDoc, OpenWhere.addRight); this._selectedDocs.push(imgDoc); } - return img.accessPaths.agnostic.client; + return { prompt: input, seed: seed, pathname: img.accessPaths.agnostic.client }; }); }; |