diff options
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r-- | src/client/documents/Documents.ts | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 5f2a592ae..e539e3c65 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -18,6 +18,7 @@ import { PointData } from '../../pen-gestures/GestureTypes'; import { DocServer } from '../DocServer'; import { dropActionType } from '../util/DropActionTypes'; import { CollectionViewType, DocumentType } from './DocumentTypes'; +import { Id } from '../../fields/FieldSymbols'; class EmptyBox { public static LayoutString() { @@ -240,7 +241,6 @@ export class DocumentOptions { borderWidth?: STRt = new StrInfo('Width of user-added border', false); borderColor?: STRt = new StrInfo('Color of user-added border', false); text_fontColor?: STRt = new StrInfo('Color of text', false); - text_align?: STRt = new StrInfo('alignment'); hCentering?: 'h-left' | 'h-center' | 'h-right'; isDefaultTemplateDoc?: BOOLt = new BoolInfo(''); contentBold?: BOOLt = new BoolInfo(''); @@ -306,6 +306,7 @@ export class DocumentOptions { _text_fontFamily?: string; _text_fontWeight?: string; text_align?: STRt = new StrInfo('horizontal text alignment default'); + text_placeholder?: BOOLt = new BoolInfo('makes the text act like a placeholder and automatically select when the text box is selected'); fontSize?: string; _pivotField?: string; // field key used to determine headings for sections in stacking, masonry, pivot views @@ -360,6 +361,7 @@ export class DocumentOptions { isFolder?: BOOLt = new BoolInfo('is document a tree view folder'); _isTimelineLabel?: BOOLt = new BoolInfo('is document a timeline label'); _isLightbox?: BOOLt = new BoolInfo('whether a collection acts as a lightbox by opening lightbox links by hiding all other documents in collection besides link target'); + cloneOnCopy?: BOOLt = new BoolInfo('if this Doc is a field of another Doc, then it should be copied when the other Doc is copied'); mapPin?: DOCt = new DocInfo('pin associated with a config anchor', false); config_latitude?: NUMt = new NumInfo('latitude of a map', false); @@ -420,6 +422,12 @@ export class DocumentOptions { flexGap?: NUMt = new NumInfo('Linear view flex gap'); flexDirection?: 'unset' | 'row' | 'column' | 'row-reverse' | 'column-reverse'; + // Comparison + data_revealOp?: STRt = new StrInfo("visual reveal type for front and back of comparison - 'slide' or 'flip' "); + data_revealOp_hover?: BOOLt = new BoolInfo('reveal back of comparison manually or by hovering'); + data_front?: DOCt = new DocInfo('contents of front of flashcard/comparison'); + data_back?: DOCt = new DocInfo('contents of back of flashcard/comparison'); + link?: string; link_description?: string; // added for links link_relationship?: string; // type of relatinoship a link represents @@ -500,8 +508,8 @@ export class DocumentOptions { userBackgroundColor?: STRt = new StrInfo('background color associated with a Dash user (seen in header fields of shared documents)'); userColor?: STRt = new StrInfo('color associated with a Dash user (seen in header fields of shared documents)'); - cardSort?: STRt = new StrInfo('way cards are sorted in deck view'); - cardSort_isDesc?: BOOLt = new BoolInfo('whether the cards are sorted ascending or descending'); + card_sort?: STRt = new StrInfo('way cards are sorted in deck view'); + card_sort_isDesc?: BOOLt = new BoolInfo('whether the cards are sorted ascending or descending'); } export const DocOptions = new DocumentOptions(); @@ -697,7 +705,7 @@ export namespace Docs { dataProps.author_date = new DateField(); if (fieldKey) { dataProps[`${fieldKey}_modificationDate`] = new DateField(); - dataProps[fieldKey] = options.data ?? data; + dataProps[fieldKey] = (options as unknown as { [key: string]: FieldType | undefined })[fieldKey] ?? data; // so that the list of annotations is already initialised, prevents issues in addonly. // without this, if a doc has no annotations but the user has AddOnly privileges, they won't be able to add an annotation because they would have needed to create the field's list which they don't have permissions to do. @@ -784,8 +792,39 @@ export namespace Docs { return InstanceFromProto(Prototypes.get(DocumentType.SCREENSHOT), '', options); } - export function ComparisonDocument(text: string, options: DocumentOptions = { title: 'Comparison Box' }) { - return InstanceFromProto(Prototypes.get(DocumentType.COMPARISON), text, options); + export function ComparisonDocument(title: string, options: DocumentOptions) { + return InstanceFromProto(Prototypes.get(DocumentType.COMPARISON), '', options); + } + /** + * Creates a text box where the supplied text (and optional iimage) will be vertically + * and horizontally centered. If text_placeholder is set to true, then the text will be + * treated as placeholder text and automatically selected when the text box is selected. + * @param title name of text box + * @param text text to display in text box + * @param opts metadata fields to set on text box + * @param img optional image to add to text box + * @returns + */ + export function CenteredTextCreator(title: string, text: string, opts: DocumentOptions, img?: Doc) { + return TextDocument(RichTextField.textToRtf(text, img?.[Id]), { + title, // + _layout_autoHeight: true, + _layout_centered: true, + text_align: 'center', + _layout_fitWidth: true, + ...opts, + }); + } + + export function FlashcardDocument(title: string, front?: Doc, back?: Doc, options: DocumentOptions = { title: 'Flashcard' }) { + return InstanceFromProto(Prototypes.get(DocumentType.COMPARISON), '', { + data_front: front ?? CenteredTextCreator('question', 'hint: Enter a topic, select this document and click the stack button to have GPT create a deck of cards', { text_placeholder: true, cloneOnCopy: true }, undefined), + data_back: back ?? CenteredTextCreator('answer', 'answer here', { text_placeholder: true, cloneOnCopy: true }, undefined), + _layout_fitWidth: true, + _layout_isFlashcard: true, + title, + ...options, + }); } export function DiagramDocument(options: DocumentOptions = { title: '' }) { return InstanceFromProto(Prototypes.get(DocumentType.DIAGRAM), undefined, options); @@ -827,7 +866,7 @@ export namespace Docs { return InstanceFromProto(Prototypes.get(DocumentType.MESSAGE), field, options, undefined, fieldKey); } - export function TextDocument(text: string, options: DocumentOptions = {}, fieldKey: string = 'text') { + export function TextDocument(text: string | RichTextField, options: DocumentOptions = {}, fieldKey: string = 'text') { const rtf = { doc: { type: 'doc', @@ -846,7 +885,7 @@ export namespace Docs { selection: { type: 'text', anchor: 1, head: 1 }, storedMarks: [], }; - const field = text ? new RichTextField(JSON.stringify(rtf), text) : undefined; + const field = text instanceof RichTextField ? text : text ? new RichTextField(JSON.stringify(rtf), text) : options.text instanceof RichTextField ? options.text : undefined; return InstanceFromProto(Prototypes.get(DocumentType.RTF), field, options, undefined, fieldKey); } |