diff options
-rw-r--r-- | src/client/documents/Documents.ts | 8 | ||||
-rw-r--r-- | src/client/views/nodes/formattedText/DailyJournal.tsx | 15 | ||||
-rw-r--r-- | src/fields/RichTextField.ts | 46 |
3 files changed, 65 insertions, 4 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index fe6e6b22d..d21fa04d4 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -919,9 +919,15 @@ export namespace Docs { // AARAV ADD // export function DailyJournalDocument(text: string | RichTextField, options: DocumentOptions = {}, fieldKey: string = 'text') { + const styles = { + bold: true, // Make the journal date bold + color: 'blue', // Set the journal date color to blue + fontSize: 18, // Set the font size to 18px for the whole text + }; + return InstanceFromProto( Prototypes.get(DocumentType.JOURNAL), - typeof text === 'string' ? RichTextField.textToRtf(text) : text, + typeof text === 'string' ? RichTextField.textToRtfFormatting(text, undefined, undefined, styles) : text, { title: new Date().toLocaleDateString(undefined, { weekday: 'long', diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx index 7999357b0..42c559da4 100644 --- a/src/client/views/nodes/formattedText/DailyJournal.tsx +++ b/src/client/views/nodes/formattedText/DailyJournal.tsx @@ -31,7 +31,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() month: 'long', day: 'numeric', }); - console.log('📆 getFormattedDate():', date); + console.log('getFormattedDate():', date); return date; } @@ -56,8 +56,19 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() console.log('Checking if dataDoc has text field...'); + const styles = { + bold: true, // Make the journal date bold + color: 'blue', // Set the journal date color to blue + fontSize: 18 // Set the font size to 18px for the whole text + }; + console.log('Setting new text field with:', initialText); - this.dataDoc[this.fieldKey] = RichTextField.textToRtf(initialText, undefined, placeholderText.length); + this.dataDoc[this.fieldKey] = RichTextField.textToRtfFormatting( + initialText, + undefined, // No image DocId + placeholderText.length, // The position for text selection + styles // Pass the styles object here + ); console.log('Current text field:', this.dataDoc[this.fieldKey]); } diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts index 4b1403b88..79ba34ada 100644 --- a/src/fields/RichTextField.ts +++ b/src/fields/RichTextField.ts @@ -111,7 +111,7 @@ export class RichTextField extends ObjectField { type: 'paragraph', attrs: { align: 'center', color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, content: [ - ...(text ? [{ type: 'text', text }] : []), // + ...(text ? [{ type: 'text', text }] : []), ...(imgDocId ? [{ type: 'dashDoc', attrs: { width: '200px', height: '200px', title: 'dashDoc', float: 'unset', hidden: false, docId: imgDocId } }] : []), ], }, @@ -122,4 +122,48 @@ export class RichTextField extends ObjectField { text ); } + + // AARAV ADD + + public static textToRtfFormatting( + text: string, + imgDocId?: string, + selectBack?: number, + styles?: { bold?: boolean, italic?: boolean, fontSize?: number, color?: string } + ) { + return new RichTextField( + !imgDocId + ? this.ToProsemirrorState(text, selectBack) + : JSON.stringify({ + // This is the RichText JSON with the text and optional image + doc: { + type: 'doc', + content: [ + { + type: 'paragraph', + attrs: { align: 'center', color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, + content: [ + { + type: 'text', + text: text, + marks: [ + ...(styles?.bold ? [{ type: 'bold' }] : []), + ...(styles?.italic ? [{ type: 'italic' }] : []), + ...(styles?.fontSize ? [{ type: 'textStyle', style: `font-size:${styles.fontSize}px` }] : []), + ...(styles?.color ? [{ type: 'textStyle', style: `color:${styles.color}` }] : []), + ] + } + ] + } + ] + }, + selection: { type: 'text', anchor: 2 + text.length, head: 2 + text.length }, + }), + text + ); + } + + + + } |