From 05845fa3e5a6d71a58845d058a15233ccf6d72c0 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 11 Jun 2025 13:01:44 -0400 Subject: refactor unwrapPlaceholder duplicated code to DocUtils. --- src/client/views/nodes/scrapbook/ScrapbookBox.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/client/views/nodes') 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(); @@ -206,13 +207,6 @@ export class ScrapbookBox extends ViewBoxAnnotatableComponent() // eslint-disable-next-line @typescript-eslint/no-unused-vars 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. @@ -220,12 +214,12 @@ export class ScrapbookBox extends ViewBoxAnnotatableComponent() * @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(allDocs.flatMap(doc => StrListCast(doc.$tags_chat).filter(tag => !tag.startsWith?.('ASPECT_')))); const internalTags = Array.from(internalTagsSet).join(', '); -- cgit v1.2.3-70-g09d2