From a9a1a6a507616a77f70d6525dab5027f5b7a60e6 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Wed, 26 Feb 2025 20:48:51 -0500
Subject: added typing to PostToServer calls.  made smartDraw popup create
 images locally.

---
 src/client/views/nodes/ImageBox.tsx | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

(limited to 'src/client/views/nodes/ImageBox.tsx')

diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index b6b0e4a8a..9395863d8 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -36,7 +36,7 @@ import { OverlayView } from '../OverlayView';
 import { AnchorMenu } from '../pdf/AnchorMenu';
 import { PinDocView, PinProps } from '../PinFuncs';
 import { DrawingFillHandler } from '../smartdraw/DrawingFillHandler';
-import { FireflyImageData } from '../smartdraw/FireflyConstants';
+import { FireflyImageData, isFireflyImageData } from '../smartdraw/FireflyConstants';
 import { SmartDrawHandler } from '../smartdraw/SmartDrawHandler';
 import { StickerPalette } from '../smartdraw/StickerPalette';
 import { StyleProp } from '../StyleProp';
@@ -354,7 +354,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                             const ext = extname(file);
                             return file.replace(ext, (this._error ? '_o' : this._curSuffix) + ext);
                         })(ImageCast(this.Document[Doc.LayoutFieldKey(this.Document)])?.url.href),
-                    }).then((info: Upload.ImageInformation) => {
+                    }).then(res => {
+                        const info = res as Upload.ImageInformation;
                         const img = Docs.Create.ImageDocument(info.accessPaths.agnostic.client, { title: 'expand:' + this.Document.title });
                         DocUtils.assignImageInfo(info, img);
                         this._props.addDocTab(img, OpenWhere.addRight);
@@ -627,14 +628,15 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                                 } else
                                     SmartDrawHandler.Instance.regenerate([this.Document], undefined, undefined, this._regenInput || StrCast(this.Document.title), true).then(
                                         action(newImgs => {
-                                            if (newImgs[0] && !(newImgs[0] instanceof Doc)) {
-                                                const url = newImgs[0].pathname;
+                                            const firstImg = newImgs[0];
+                                            if (isFireflyImageData(firstImg)) {
+                                                const url = firstImg.pathname;
                                                 const imgField = new ImageField(url);
                                                 this._prevImgs.length === 0 &&
                                                     this._prevImgs.push({ prompt: StrCast(this.dataDoc.ai_firefly_prompt), seed: this.dataDoc.ai_firefly_seed as number, href: this.paths.lastElement(), pathname: field.url.pathname });
-                                                this._prevImgs.unshift({ prompt: newImgs[0].prompt, seed: newImgs[0].seed, pathname: url });
+                                                this._prevImgs.unshift({ prompt: firstImg.prompt, seed: firstImg.seed, pathname: url });
                                                 this.dataDoc.ai_firefly_history = JSON.stringify(this._prevImgs);
-                                                this.dataDoc.ai_firefly_prompt = newImgs[0].prompt;
+                                                this.dataDoc.ai_firefly_prompt = firstImg.prompt;
                                                 this.dataDoc[this.fieldKey] = imgField;
                                                 this._regenerateLoading = false;
                                                 this._regenInput = '';
@@ -688,7 +690,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                                     const ext = extname(file);
                                     return file.replace(ext, (this._error ? '_o' : this._curSuffix) + ext);
                                 })(ImageCast(this.Document[Doc.LayoutFieldKey(this.Document)])?.url.href),
-                            }).then((info: Upload.ImageInformation) => {
+                            }).then(res => {
+                                const info = res as Upload.ImageInformation;
                                 const img = Docs.Create.ImageDocument(info.accessPaths.agnostic.client, { title: 'expand:' + this.Document.title });
                                 DocUtils.assignImageInfo(info, img);
                                 const genratedDocs = this.Document.generatedDocs
@@ -741,7 +744,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
     focus = (anchor: Doc, options: FocusViewOptions) => (anchor.type === DocumentType.CONFIG ? undefined : this._ffref.current?.focus(anchor, options));
 
     renderedPixelDimensions = async () => {
-        const { nativeWidth: width, nativeHeight: height } = await Networking.PostToServer('/inspectImage', { source: this.paths[0] });
+        const res = await Networking.PostToServer('/inspectImage', { source: this.paths[0] });
+        const { nativeWidth: width, nativeHeight: height } = res as { nativeWidth: number; nativeHeight: number };
         return { width, height };
     };
     savedAnnotations = () => this._savedAnnotations;
-- 
cgit v1.2.3-70-g09d2

