From 29dff3b54e8c722e342ae57f9cd3bf7b193c8ec5 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 22 Jul 2025 16:55:22 -0600 Subject: [PATCH] more props for container --- .../StreamingMessageCode.tsx | 37 +++--- .../SyntaxHighlighter.module.css | 7 +- .../SyntaxHighlight/SyntaxHighlighter.tsx | 116 +++++++++--------- 3 files changed, 80 insertions(+), 80 deletions(-) diff --git a/apps/web/src/components/ui/streaming/StreamingMessageCode/StreamingMessageCode.tsx b/apps/web/src/components/ui/streaming/StreamingMessageCode/StreamingMessageCode.tsx index a4e907701..ef3dc87e6 100644 --- a/apps/web/src/components/ui/streaming/StreamingMessageCode/StreamingMessageCode.tsx +++ b/apps/web/src/components/ui/streaming/StreamingMessageCode/StreamingMessageCode.tsx @@ -121,18 +121,31 @@ export const StreamingMessageCode: React.FC<{ return ( -
- {lineSegments.map((segment, index) => ( +
+ {/* {lineSegments.map((segment, index) => (
{segment.type === 'text' ? ( - + + {segment.content} + ) : ( )}
- ))} + ))} */} + + {text} +
); @@ -152,19 +165,3 @@ const HiddenSection: React.FC<{
); - -const MemoizedSyntaxHighlighter = React.memo( - ({ lineNumber, text }: { lineNumber: number; text: string }) => { - return ( - - {text} - - ); - } -); - -MemoizedSyntaxHighlighter.displayName = 'MemoizedSyntaxHighlighter'; diff --git a/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.module.css b/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.module.css index 1928ac5b9..154e5560f 100644 --- a/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.module.css +++ b/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.module.css @@ -2,7 +2,8 @@ .shikiWrapper :global(pre) { margin: 0; padding: 0em; - overflow-x: auto; + width: fit-content; + margin-right: 0.75rem; } .shikiWrapper :global(code) { @@ -23,8 +24,8 @@ .shikiWrapper.withLineNumbers .line::before { content: counter(step); counter-increment: step; - width: 2rem; - margin-right: 1.35rem; + width: 1.5rem; + margin-right: 1rem; display: inline-block; text-align: right; color: var(--color-text-tertiary); diff --git a/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.tsx b/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.tsx index 719a444f6..0a35a6328 100644 --- a/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.tsx +++ b/apps/web/src/components/ui/typography/SyntaxHighlight/SyntaxHighlighter.tsx @@ -7,65 +7,65 @@ import styles from './SyntaxHighlighter.module.css'; import { animations, type MarkdownAnimation } from '../animation-common'; import type { ThemedToken } from 'shiki'; -export const SyntaxHighlighter = (props: { - children: string; - language?: 'sql' | 'yaml'; - showLineNumbers?: boolean; - startingLineNumber?: number; - className?: string; - containerClassName?: string; - customStyle?: React.CSSProperties; - isDarkMode?: boolean; - animation?: MarkdownAnimation; - animationDuration?: number; -}) => { - const { - children, - language = 'sql', - showLineNumbers = false, - startingLineNumber = 1, - className = '', - containerClassName = '', - customStyle = {}, - isDarkMode = false, - animation = 'none', - animationDuration = 700 - } = props; +export const SyntaxHighlighter = React.memo( + (props: { + children: string; + language?: 'sql' | 'yaml'; + showLineNumbers?: boolean; + startingLineNumber?: number; + className?: string; + containerClassName?: string; + isDarkMode?: boolean; + animation?: MarkdownAnimation; + animationDuration?: number; + }) => { + const { + children, + language = 'sql', + showLineNumbers = false, + startingLineNumber = 1, + className = '', + containerClassName = '', + isDarkMode = false, + animation = 'none', + animationDuration = 700 + } = props; - const [tokens, setTokens] = useState(null); - const [isLoading, setIsLoading] = useState(true); + const [tokens, setTokens] = useState<{ + tokens: ThemedToken[][]; + bg: string; + fg: string; + } | null>(null); + const [isLoading, setIsLoading] = useState(true); - useEffect(() => { - const loadTokens = async () => { - try { - const theme = isDarkMode ? 'github-dark' : 'github-light'; - const tokenData = await getCodeTokens(children, language, theme); + useEffect(() => { + const loadTokens = async () => { + try { + const theme = isDarkMode ? 'github-dark' : 'github-light'; + const tokenData = await getCodeTokens(children, language, theme); - setTokens(tokenData); - setIsLoading(false); - } catch (error) { - console.error('Error tokenizing code:', error); - setIsLoading(false); - } - }; + setTokens(tokenData); + setIsLoading(false); + } catch (error) { + console.error('Error tokenizing code:', error); + setIsLoading(false); + } + }; - loadTokens(); - }, [children, language, isDarkMode]); + loadTokens(); + }, [children, language, isDarkMode]); + + if (isLoading || !tokens) { + return ( +
+
+            {children}
+          
+
+ ); + } - if (isLoading || !tokens) { return ( -
-
-          {children}
-        
-
- ); - } - - return ( -
           
-            {tokens.tokens.map((line: any[], index: number) => {
+            {tokens.tokens.map((line: ThemedToken[], index: number) => {
               return (
                 
         
-
- ); -}; + ); + } +); + +SyntaxHighlighter.displayName = 'SyntaxHighlighter'; // Line component for rendering individual lines with animation support interface LineProps {