aboutsummaryrefslogtreecommitdiff
path: root/src/fields/RichTextField.ts
diff options
context:
space:
mode:
authoraaravkumar <aarav.kumar1510@gmail.com>2025-03-07 12:55:31 -0500
committeraaravkumar <aarav.kumar1510@gmail.com>2025-03-07 12:55:31 -0500
commit9d4bfd04760753b6fdd7ed81372ab8d85b615bc3 (patch)
tree965a33751512c49497e4d647fdfa731f96029ad9 /src/fields/RichTextField.ts
parent1b1dd47cd640eced707840f306ab71861a53fb8b (diff)
added more individual text formatting features + journal like background
Diffstat (limited to 'src/fields/RichTextField.ts')
-rw-r--r--src/fields/RichTextField.ts57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index 63ae61c2f..8f4d782b4 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -42,7 +42,8 @@ export class RichTextField extends ObjectField {
return this.Text;
}
- // AARAV ADD=
+ // AARAV ADD
+
static ToProsemirrorDoc = (content: Record<string, unknown>[], selection: Record<string, unknown>) => ({
doc: {
type: 'doc',
@@ -86,7 +87,57 @@ export class RichTextField extends ObjectField {
{ type: 'text', anchor: 2 + plaintext.length - (selectBack ?? 0), head: 2 + plaintext.length }
);
- public static textToRtf(text: string, imgDocId?: string, styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string }, selectBack?: number) {
- return new RichTextField(JSON.stringify(RichTextField.ToProsemirror(text, imgDocId, styles, selectBack)), text);
+
+ // AARAV ADD
+
+ // takes in text segments instead of single text field
+ private static ToProsemirrorSegmented = (
+ textSegments: { text: string; styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string } }[],
+ imgDocId?: string,
+ selectBack?: number
+ ) =>
+ RichTextField.ToProsemirrorDoc(
+ textSegments.map(seg => ({
+ type: 'paragraph', // Each segment becomes its own paragraph
+ content: [
+ ...RichTextField.ToProsemirrorTextContent(seg.text, seg.styles),
+ ...(imgDocId ? RichTextField.ToProsemirrorDashDocContent(imgDocId) : []),
+ ],
+ })),
+ {
+ type: 'text',
+ anchor: 2 + textSegments.map(seg => seg.text).join('').length - (selectBack ?? 0),
+ head: 2 + textSegments.map(seg => seg.text).join('').length,
+ }
+ );
+
+ // AARAV ADD ||
+
+
+
+ public static textToRtf(
+ text: string,
+ imgDocId?: string,
+ styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string },
+ selectBack?: number
+ ) {
+ return new RichTextField(
+ JSON.stringify(RichTextField.ToProsemirror(text, imgDocId, styles, selectBack)), text);
+ }
+
+ // AARAV ADD
+ public static textToRtfFormat(
+ textSegments: { text: string; styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string } }[],
+ imgDocId?: string,
+ selectBack?: number
+ ) {
+ return new RichTextField(
+ JSON.stringify(RichTextField.ToProsemirrorSegmented(textSegments, imgDocId, selectBack)),
+ textSegments.map(seg => seg.text).join(''));
}
+
+ // AARAV ADD
+
+
+
}