aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/DocUtils.ts9
-rw-r--r--src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx7
-rw-r--r--src/client/views/collections/collectionFreeForm/MarqueeView.tsx19
-rw-r--r--src/client/views/nodes/scrapbook/ScrapbookBox.tsx12
4 files changed, 20 insertions, 27 deletions
diff --git a/src/client/documents/DocUtils.ts b/src/client/documents/DocUtils.ts
index dee929c89..9704867d5 100644
--- a/src/client/documents/DocUtils.ts
+++ b/src/client/documents/DocUtils.ts
@@ -587,6 +587,15 @@ export namespace DocUtils {
doc.onClick = FollowLinkScript();
}
+ /**
+ * iterate through all items and their children and return a flat list of leaf placeholder content Docs
+ * @param items
+ * @returns list of placeholder content Docs
+ */
+ export function unwrapPlaceholders(items: Doc[]): Doc[] {
+ return items.flatMap(d => (d.$type === DocumentType.COL ? unwrapPlaceholders(DocListCast(d[Doc.LayoutDataKey(d)])) : [d]));
+ }
+
export function LeavePushpin(doc: Doc, annotationField: string) {
if (doc.followLinkToggle) return undefined;
const context = Cast(doc.embedContainer, Doc, null) ?? Cast(doc.annotationOn, Doc, null);
diff --git a/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx b/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx
index 038b1c6f9..e3a3f9b05 100644
--- a/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx
+++ b/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx
@@ -158,10 +158,9 @@ export class ImageLabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
this._currentLabel = e.target.value;
});
- classifyImagesInBox = async (selectedImages? : Doc[], prompt? : string) => {
+ classifyImagesInBox = async () => {
this.startLoading();
- alert('Classifying images...');
- selectedImages ??= this._selectedImages;
+ const selectedImages = this._selectedImages;
// Converts the images into a Base64 format, afterwhich the information is sent to GPT to label them.
@@ -170,7 +169,7 @@ export class ImageLabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
const url = ImageCastWithSuffix(doc[Doc.LayoutDataKey(doc)], '_o') ?? '';
return imageUrlToBase64(url).then(hrefBase64 =>
!hrefBase64 ? undefined :
- gptImageLabel(hrefBase64, prompt ?? 'Give three labels to describe this image.').then(labels =>
+ gptImageLabel(hrefBase64, 'Give three labels to describe this image.').then(labels =>
({ doc, labels }))) ; // prettier-ignore
}
});
diff --git a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
index 7a456c46f..128606675 100644
--- a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
+++ b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
@@ -527,17 +527,11 @@ export class MarqueeView extends ObservableReactComponent<SubCollectionViewProps
MarqueeOptionsMenu.Instance.fadeOut(true);
});
- getAiPresetsDescriptors(): DocumentDescriptor[] {
- const selected = this.marqueeSelect(false);
- return selected.map(doc => ({
+ getAiPresetsDescriptors = (): DocumentDescriptor[] =>
+ this.marqueeSelect(false).map(doc => ({
type: typeof doc.$type === 'string' ? doc.$type : 'UNKNOWN',
- tags: (() => {
- const s = new Set<string>();
- StrListCast(doc.$tags_chat ?? new List<string>()).forEach(t => s.add(t));
- return Array.from(s);
- })(),
+ tags: Array.from(new Set(StrListCast(doc.$tags_chat))),
}));
- }
generateScrapbook = action(async () => {
const selectedDocs = this.marqueeSelect(false);
@@ -582,14 +576,12 @@ export class MarqueeView extends ObservableReactComponent<SubCollectionViewProps
});
// 3) Now grab that new scrapbook’s flat placeholders
- const flatPl = DocListCast(scrapbook[Doc.LayoutDataKey(scrapbook)]) as Doc[];
- const unwrap = (items: Doc[]): Doc[] => items.flatMap(d => (d.$type === DocumentType.COL ? unwrap(DocListCast(d[Doc.LayoutDataKey(d)])) : [d]));
- const allPlaceholders = unwrap(flatPl);
+ const allPlaceholders = DocUtils.unwrapPlaceholders(scrapbookPlaceholders);
// 4) Slot each selectedDocs[i] into the first matching placeholder
selectedDocs.forEach(realDoc => slotRealDocIntoPlaceholders(realDoc, allPlaceholders));
- const selected = this.marqueeSelect(false).map(d => {
+ const selected = selectedDocs.map(d => {
this._props.removeDocument?.(d);
d.x = NumCast(d.x) - this.Bounds.left;
d.y = NumCast(d.y) - this.Bounds.top;
@@ -597,7 +589,6 @@ export class MarqueeView extends ObservableReactComponent<SubCollectionViewProps
});
this._props.addDocument?.(scrapbook);
- selectedDocs.forEach(doc => this._props.removeDocument?.(doc));
const portal = Docs.Create.FreeformDocument(selected, { title: 'summarized documents', x: this.Bounds.left + 200, y: this.Bounds.top, isGroup: true, backgroundColor: 'transparent' });
DocUtils.MakeLink(scrapbook, portal, { link_relationship: 'summary of:summarized by' });
diff --git a/src/client/views/nodes/scrapbook/ScrapbookBox.tsx b/src/client/views/nodes/scrapbook/ScrapbookBox.tsx
index 2db76c76f..ff757af88 100644
--- a/src/client/views/nodes/scrapbook/ScrapbookBox.tsx
+++ b/src/client/views/nodes/scrapbook/ScrapbookBox.tsx
@@ -23,6 +23,7 @@ import './ScrapbookBox.scss';
import { ScrapbookItemConfig } from './ScrapbookPreset';
import { createPreset, getPresetNames } from './ScrapbookPresetRegistry';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { DocUtils } from '../../../documents/DocUtils';
function createPlaceholder(cfg: ScrapbookItemConfig, doc: Doc) {
const placeholder = new Doc();
@@ -207,25 +208,18 @@ export class ScrapbookBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
rejectDrop = (de: DragManager.DropEvent, subView?: DocumentView) => false; // allow all Docs to be dropped onto scrapbook -- let filterAddDocument make the final decision.
/**
- * iterate through all items and their children and return a flat list of leaf placeholder content Docs
- * @param items
- * @returns list of placeholder content Docs
- */
- unwrapPlaceholders = (items: Doc[]): Doc[] => items.flatMap(d => (d.$type === DocumentType.COL ? this.unwrapPlaceholders(DocListCast(d[Doc.LayoutDataKey(d)])) : [d]));
-
- /**
* Filter function to determine if a document can be added to the scrapbook.
* This checks if the document matches any of the placeholder slots in the scrapbook.
* @param docs - The document(s) being added to the scrapbook.
* @returns true if the document can be added, false otherwise.
*/
filterAddDocument = (docs: Doc | Doc[]) => {
- toList(docs).forEach(doc => slotRealDocIntoPlaceholders(doc, this.unwrapPlaceholders(this.ScrapbookLayoutDocs)));
+ toList(docs).forEach(doc => slotRealDocIntoPlaceholders(doc, DocUtils.unwrapPlaceholders(this.ScrapbookLayoutDocs)));
return false;
};
@computed get regenPrompt() {
- const allDocs = this.unwrapPlaceholders(this.ScrapbookLayoutDocs); // find all non-collections in scrapbook (e.g., placeholder content docs)
+ const allDocs = DocUtils.unwrapPlaceholders(this.ScrapbookLayoutDocs); // find all non-collections in scrapbook (e.g., placeholder content docs)
const internalTagsSet = new Set<string>(allDocs.flatMap(doc => StrListCast(doc.$tags_chat).filter(tag => !tag.startsWith?.('ASPECT_'))));
const internalTags = Array.from(internalTagsSet).join(', ');