From e9bc998554515ecbe86f7d00b01d3cf5d2048b6e Mon Sep 17 00:00:00 2001 From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> Date: Thu, 3 Apr 2025 03:36:07 -0400 Subject: Firefly integration and some UI changes --- .../DataVizBox/DocCreatorMenu/DocCreatorMenu.scss | 65 ++++--- .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx | 213 ++++++++++++++------- .../DataVizBox/DocCreatorMenu/TemplateBackend.ts | 2 +- .../TemplateFieldTypes/StaticContentField.ts | 2 +- src/client/views/smartdraw/DrawingFillHandler.tsx | 59 +++--- src/server/ApiManagers/FireflyManager.ts | 3 +- 6 files changed, 229 insertions(+), 115 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.scss b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.scss index 57f4a1e94..48e09d12f 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.scss +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.scss @@ -277,18 +277,6 @@ scrollbar-width: none; } -.docCreatorMenu-preview-container { - display: grid; - grid-template-columns: repeat(2, 140px); - grid-template-rows: 140px; - grid-auto-rows: 141px; - overflow-y: scroll; - margin: 0px; - margin-top: 0px; - width: 100%; - height: 100%; -} - .docCreatorMenu-expanded-template-preview { display: flex; flex-direction: column; @@ -297,6 +285,7 @@ position: relative; width: 100%; height: 100%; + flex-grow: 1; .top-panel{ width: 100%; @@ -322,15 +311,12 @@ display: flex; justify-content: center; align-items: center; - width: 113px; - height: 113px; - margin-top: 10px; - margin-left: 10px; + height: 100%; + aspect-ratio: 1; color: none; border: 1px solid rgb(163, 163, 163); border-radius: 5px; box-shadow: 5px 5px rgb(29, 29, 31); - flex: 0 0 auto; &:hover{ background-color: rgb(72, 72, 73); @@ -394,17 +380,42 @@ } } +.docCreatorMenu-variation-prompt-input { + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: center; + margin: 5px; + gap: 15px; + height: 30px; + width: 100%; +} + +.docCreatorMenu-variation-prompt-input-textbox { + height: 100%; + width: 80%; + color: white; + margin-top: 1%; + margin-bottom: 1%; + margin-left: 5%; + background-color: rgb(50, 50, 50); + border-radius: 5px; +} + +.docCreatorMenu-variations-tab { + flex-grow: .5; +} + .docCreatorMenu-section { display: flex; flex-direction: column; align-items: center; position: relative; + flex-grow: 1; + height: 100%; margin: 0px; margin-top: 0px; margin-bottom: 0px; - width: 100%; - height: 200; - flex: 0 0 auto; } .docCreatorMenu-GPT-options-container { @@ -422,12 +433,14 @@ .docCreatorMenu-templates-preview-window { display: flex; flex-direction: row; - //justify-content: center; + justify-content: flex-start; align-items: center; overflow-y: scroll; + gap: 10px; + margin: 5px; position: relative; color: black; - height: 125px; + height: 100%; width: calc(100% - 10px); -ms-overflow-style: none; scrollbar-width: none; @@ -463,6 +476,12 @@ } } +.docCreatorMenu-templates-displays { + display: flex; + flex-direction: column; + height: 100%; +} + .docCreatorMenu-section-title { border: 1px solid rgb(163, 163, 163); border-top: 0px; @@ -1057,4 +1076,4 @@ } -} +} \ No newline at end of file diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx index 6d37f8f0f..0c5ae58a3 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx @@ -31,6 +31,8 @@ import { TemplateField, ViewType } from './TemplateFieldTypes/TemplateField'; import { Template } from './Template'; import { TemplateFieldSize, TemplateFieldType, TemplateLayouts } from './TemplateBackend'; import { TemplateManager } from './TemplateManager'; +import { DrawingFillHandler } from '../../../smartdraw/DrawingFillHandler'; +import { CgPathIntersect } from 'react-icons/cg'; export enum LayoutType { FREEFORM = 'Freeform', @@ -72,7 +74,7 @@ export class DocCreatorMenu extends ObservableReactComponent // eslint-disable-next-line no-use-before-define static Instance: DocCreatorMenu; - private DEBUG_MODE: boolean = false; + private DEBUG_MODE: boolean = true; private _disposers: { [name: string]: IDisposer } = {}; private _ref: HTMLDivElement | null = null; private templateManager: TemplateManager; @@ -91,6 +93,12 @@ export class DocCreatorMenu extends ObservableReactComponent @observable _layout: { type: LayoutType; yMargin: number; xMargin: number; columns?: number; repeat: number } = { type: LayoutType.FREEFORM, yMargin: 10, xMargin: 10, columns: 3, repeat: 0 }; @observable _savedLayouts: DataVizTemplateLayout[] = []; @observable _expandedPreview: Doc | undefined = undefined; + @observable _variationsTab: boolean = false; + @observable _numVarsToGenerate: number = 3; + @observable _loadingVariants: boolean = false; + @observable _currentVariations: Doc[] = []; + @observable _variationPrompt: string = 'Use this template to generate an empty baseball card template.'; + _previewWindow: HTMLDivElement | null = null; @observable _suggestedTemplates: Template[] = []; @observable _suggestedTemplatePreviews: { doc: Doc; template: Template }[] = []; @@ -129,6 +137,10 @@ export class DocCreatorMenu extends ObservableReactComponent this.templateManager = new TemplateManager(TemplateLayouts.allTemplates); } + setContainerRef: React.LegacyRef = (node) => { + this._previewWindow = node; + }; + @action setDataViz = (dataViz: DataVizBox) => { this._dataViz = dataViz; this._selectedTemplate = undefined; @@ -493,6 +505,42 @@ export class DocCreatorMenu extends ObservableReactComponent this.forceUpdate(); }; + @action setVariationTab = (open: boolean) => { + this._variationsTab = open; + if (this._previewWindow && open) { + this._previewWindow.style.height = String(Number(this._previewWindow.clientHeight) * .6); + } else if (this._previewWindow && !open) { + this._previewWindow.style.height = String(Number(this._previewWindow.clientHeight) * 5/3); + } + } + + generateVariations = async (onDoc: Doc): Promise => { + this._loadingVariants = true; + this.variationDocss = []; + const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView; + + const clone: Doc = (await Doc.MakeClone(onDoc)).clone; + mainCollection.addDocument(clone); + clone.x = 10000; + clone.y = 10000; + + await DrawingFillHandler.drawingToImage(clone, 100, this._variationPrompt, undefined, this) + + this._loadingVariants = false; + + return this.variationDocss; + } + + @observable variationDocss: Doc[] = [] + + @action addVariationDoc = (doc: Doc) => { + this.variationDocss.push(doc); + const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView; + mainCollection.addDocument(doc); + doc.x = 10000; + doc.y = 10000; + } + generateGPTImage = async (prompt: string): Promise => { try { const res = await gptImageCall(prompt); @@ -768,31 +816,71 @@ export class DocCreatorMenu extends ObservableReactComponent this._expandedPreview = template?.doc; //Docs.Create.FreeformDocument([doc], { _height: NumListCast(doc._height)[0], _width: NumListCast(doc._width)[0], title: ''}); }; + @action setVariationPrompt = (prompt: string) => { + this._variationPrompt = prompt; + } + get editingWindow() { const rendered = !this._expandedPreview ? null : ( -
- this._menuDimensions.width - 10} - PanelHeight={() => this._menuDimensions.height - 60} - ScreenToLocalTransform={() => new Transform(-this._pageX - 5, -this._pageY - 35, 1)} - renderDepth={5} - whenChildContentsActiveChanged={emptyFunction} - focus={emptyFunction} - styleProvider={DefaultStyleProvider} - addDocTab={DocumentViewInternal.addDocTabFunc} - pinToPres={() => undefined} - childFilters={returnEmptyFilter} - childFiltersByRanges={returnEmptyFilter} - searchFilterDocs={returnEmptyDoclist} - fitContentsToBox={returnFalse} - fitWidth={returnFalse} - /> -
+ <> +
+ { this._previewWindow ? this._previewWindow?.clientWidth ?? 1000 - 10} + PanelHeight={() => this._previewWindow?.clientHeight ?? 1000 - 60} + ScreenToLocalTransform={() => new Transform(-this._pageX - 5, -this._pageY - 35, 1)} + renderDepth={5} + whenChildContentsActiveChanged={emptyFunction} + focus={emptyFunction} + styleProvider={DefaultStyleProvider} + addDocTab={DocumentViewInternal.addDocTabFunc} + pinToPres={() => undefined} + childFilters={returnEmptyFilter} + childFiltersByRanges={returnEmptyFilter} + searchFilterDocs={returnEmptyDoclist} + fitContentsToBox={returnFalse} + fitWidth={returnFalse} + /> : null + } +
+ { this._variationsTab ? +
+
+
Variations
+ +
+
+ {this._currentVariations.map(variant => +
+ {this.docPreview(variant)} +
+ )} +
+
+