aboutsummaryrefslogtreecommitdiff
path: root/src/client/views
diff options
context:
space:
mode:
authorSophie Zhang <sophie_zhang@brown.edu>2024-02-07 19:08:38 -0500
committerSophie Zhang <sophie_zhang@brown.edu>2024-02-07 19:08:38 -0500
commit70cf5ad795055c1f628c918b08a13a96e4ab89a6 (patch)
tree60d799c32e36549f8ffa1f67de1ba232030e8294 /src/client/views
parent7082d37c07575afe29818c3a286e9b981e8bc307 (diff)
saving prog
Diffstat (limited to 'src/client/views')
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx29
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBox.tsx5
2 files changed, 31 insertions, 3 deletions
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<Partial<collection
return url.href.replace(ext, '_m' + ext);
}
+ // gpt layout
+ @action
+ gptLayout = async () => {
+ 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<Partial<collection
optionItems.push({ description: (this._showAnimTimeline ? 'Close' : 'Open') + ' Animation Timeline', event: action(() => (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<FieldViewProps>() implements ViewBoxInterface {
@@ -1153,7 +1154,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FieldViewProps
if (BoolCast(Doc.UserDoc().settingBgColor)) return;
console.log('checking bg color 2');
let fontColor = '#000000';
- if (isDarkMode(StrCast(this.rootDoc._backgroundColor))) {
+ if (isDarkMode(StrCast(this.Document._backgroundColor))) {
fontColor = '#ffffff';
}
// set text to white
@@ -1188,7 +1189,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FieldViewProps
{ fireImmediately: true }
);
this._disposers.bgColor = reaction(
- () => this.rootDoc._backgroundColor,
+ () => this.Document._backgroundColor,
color => this.checkBackgroundColor()
);
this._disposers.componentHeights = reaction(