From 70cf5ad795055c1f628c918b08a13a96e4ab89a6 Mon Sep 17 00:00:00 2001 From: Sophie Zhang Date: Wed, 7 Feb 2024 19:08:38 -0500 Subject: saving prog --- .../collectionFreeForm/CollectionFreeFormView.tsx | 29 +++++++++++++++++++++- .../views/nodes/formattedText/FormattedTextBox.tsx | 5 ++-- 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src/client/views') diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 8e415a407..fb9d42bc7 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -55,7 +55,7 @@ import './CollectionFreeFormView.scss'; import { MarqueeView } from './MarqueeView'; import { PropertiesView } from '../../PropertiesView'; import { ExtractColors } from '../../ExtractColors'; -import { StyleInputDocument } from '../../../apis/gpt/customization'; +import { smartLayout, smartLayout2, StyleInputDocument } from '../../../apis/gpt/customization'; import { RichTextField } from '../../../../fields/RichTextField'; import { extname } from 'path'; @@ -1659,6 +1659,31 @@ export class CollectionFreeFormView extends CollectionSubView { + const docLayouts = this.childDocs.map(doc => ({ + width: NumCast(doc.width), + height: NumCast(doc.height), + content: StrCast(doc.title), + })); + console.log(docLayouts); + + const res = await smartLayout2(docLayouts); + console.log('Smart layout result', res); + // make type-safe + const resObj = JSON.parse(res) as any[]; + resObj.forEach((elem, i) => { + this.childDocs[i].x = elem.x; + this.childDocs[i].y = elem.y; + }); + + // refit collection + setTimeout(() => { + this.fitContentOnce(); + }, 500); + }; + // gpt styling @action gptStyling = async () => { @@ -1740,7 +1765,9 @@ export class CollectionFreeFormView extends CollectionSubView (this._showAnimTimeline = !this._showAnimTimeline)), icon: 'eye' }); this._props.renderDepth && optionItems.push({ description: 'Use Background Color as Default', event: () => (Cast(Doc.UserDoc().emptyCollection, Doc, null)._backgroundColor = StrCast(this.layoutDoc._backgroundColor)), icon: 'palette' }); this._props.renderDepth && optionItems.push({ description: 'Fit Content Once', event: this.fitContentOnce, icon: 'object-group' }); + // Want to condense into a Smart Organize button this._props.renderDepth && optionItems.push({ description: 'Style with AI', event: this.gptStyling, icon: 'paint-brush' }); + this._props.renderDepth && optionItems.push({ description: 'Smart Layout', event: this.gptLayout, icon: 'object-group' }); if (!Doc.noviceMode) { optionItems.push({ description: (!Doc.NativeWidth(this.layoutDoc) || !Doc.NativeHeight(this.layoutDoc) ? 'Freeze' : 'Unfreeze') + ' Aspect', event: this.toggleNativeDimensions, icon: 'snowflake' }); } diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index f9cef1a60..460f2a1c6 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -67,6 +67,7 @@ import { RichTextMenu, RichTextMenuPlugin } from './RichTextMenu'; import { RichTextRules } from './RichTextRules'; import { schema } from './schema_rts'; import { SummaryView } from './SummaryView'; +import { isDarkMode } from '../../../util/reportManager/reportManagerUtils'; // import * as applyDevTools from 'prosemirror-dev-tools'; @observer export class FormattedTextBox extends ViewBoxAnnotatableComponent() implements ViewBoxInterface { @@ -1153,7 +1154,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent this.rootDoc._backgroundColor, + () => this.Document._backgroundColor, color => this.checkBackgroundColor() ); this._disposers.componentHeights = reaction( -- cgit v1.2.3-70-g09d2