diff --git a/packages/app/src/components/plan-card.tsx b/packages/app/src/components/plan-card.tsx index 11741bb22..05da8b59f 100644 --- a/packages/app/src/components/plan-card.tsx +++ b/packages/app/src/components/plan-card.tsx @@ -1,10 +1,62 @@ -import type { ReactNode } from "react"; +import { useMemo, type ReactNode } from "react"; import { Text, View } from "react-native"; import Markdown from "react-native-markdown-display"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { createMarkdownStyles } from "@/styles/markdown-styles"; import { getMarkdownListMarker } from "@/utils/markdown-list"; +function MarkdownInlineText({ + textKey, + inheritedStyle, + ruleStyle, + children, +}: { + textKey: string; + inheritedStyle: any; + ruleStyle: any; + children: ReactNode; +}) { + const style = useMemo(() => [inheritedStyle, ruleStyle], [inheritedStyle, ruleStyle]); + return ( + + {children} + + ); +} + +function MarkdownListItemContent({ + contentStyle, + children, +}: { + contentStyle: any; + children: ReactNode; +}) { + const style = useMemo(() => [contentStyle, LIST_ITEM_CONTENT_INNER], [contentStyle]); + return {children}; +} + +function MarkdownParagraph({ + textKey, + paragraphStyle, + isLastChild, + children, +}: { + textKey: string; + paragraphStyle: any; + isLastChild: boolean; + children: ReactNode; +}) { + const style = useMemo( + () => [paragraphStyle, isLastChild ? PARAGRAPH_LAST_CHILD : false], + [paragraphStyle, isLastChild], + ); + return ( + + {children} + + ); +} + function createPlanMarkdownRules() { return { text: ( @@ -14,9 +66,13 @@ function createPlanMarkdownRules() { styles: any, inheritedStyles: any = {}, ) => ( - + {node.content} - + ), textgroup: ( node: any, @@ -25,9 +81,13 @@ function createPlanMarkdownRules() { styles: any, inheritedStyles: any = {}, ) => ( - + {children} - + ), code_block: ( node: any, @@ -36,9 +96,13 @@ function createPlanMarkdownRules() { styles: any, inheritedStyles: any = {}, ) => ( - + {node.content} - + ), fence: ( node: any, @@ -47,9 +111,13 @@ function createPlanMarkdownRules() { styles: any, inheritedStyles: any = {}, ) => ( - + {node.content} - + ), code_inline: ( node: any, @@ -58,9 +126,13 @@ function createPlanMarkdownRules() { styles: any, inheritedStyles: any = {}, ) => ( - + {node.content} - + ), bullet_list: (node: any, children: ReactNode[], _parent: any, styles: any) => ( @@ -80,16 +152,20 @@ function createPlanMarkdownRules() { return ( {marker} - {children} + {children} ); }, paragraph: (node: any, children: ReactNode[], parent: any, styles: any) => { const isLastChild = parent[0]?.children?.at(-1)?.key === node.key; return ( - + {children} - + ); }, }; @@ -112,23 +188,30 @@ export function PlanCard({ const markdownStyles = createMarkdownStyles(theme); const markdownRules = createPlanMarkdownRules(); + const containerStyle = useMemo( + () => [ + styles.container, + disableOuterSpacing && styles.containerCompact, + { + backgroundColor: theme.colors.surface1, + borderColor: theme.colors.border, + }, + ], + [disableOuterSpacing, theme.colors.surface1, theme.colors.border], + ); + const titleStyle = useMemo( + () => [styles.title, { color: theme.colors.foreground }], + [theme.colors.foreground], + ); + const descriptionStyle = useMemo( + () => [styles.description, { color: theme.colors.foregroundMuted }], + [theme.colors.foregroundMuted], + ); + return ( - - {title} - {description ? ( - - {description} - - ) : null} + + {title} + {description ? {description} : null} {text} @@ -160,3 +243,6 @@ const styles = StyleSheet.create((theme) => ({ gap: theme.spacing[2], }, })); + +const LIST_ITEM_CONTENT_INNER = { flex: 1, flexShrink: 1, minWidth: 0 }; +const PARAGRAPH_LAST_CHILD = { marginBottom: 0 };