Rename RenderImageURL

This commit is contained in:
Enrico Ros
2024-06-10 21:45:40 -07:00
parent e77e2045e3
commit bc0a7b6ac3
3 changed files with 21 additions and 32 deletions
+19 -30
View File
@@ -13,7 +13,7 @@ import { InlineError } from '~/common/components/InlineError';
import { RenderCode, RenderCodeMemo } from './code/RenderCode';
import { RenderHtml } from './RenderHtml';
import { RenderImage } from './RenderImage';
import { RenderImageURL } from './RenderImageURL';
import { RenderMarkdown, RenderMarkdownMemo } from './markdown/RenderMarkdown';
import { RenderChatText } from './RenderChatText';
import { RenderTextDiff } from './RenderTextDiff';
@@ -193,35 +193,24 @@ export const BlocksRenderer = React.forwardRef<HTMLDivElement, BlocksRendererPro
<Typography level='body-sm' color='warning' sx={{ mt: 1, mx: 1.5 }}>modified by user - auto-update disabled</Typography>
)}
{errorMessage ? (
<Tooltip title={<Typography sx={{ maxWidth: 800 }}>{text}</Typography>} variant='soft'>
<InlineError error={errorMessage} />
</Tooltip>
) : (
// sequence of render components, for each Block
blocks.map(
(block, index) => {
// Optimization: only memo the non-currently-rendered components, if the message is still in flux
const optimizeSubBlockWithMemo = props.optiAllowSubBlocksMemo && index !== blocks.length - 1;
const RenderCodeMemoOrNot = optimizeSubBlockWithMemo ? RenderCodeMemo : RenderCode;
const RenderMarkdownMemoOrNot = optimizeSubBlockWithMemo ? RenderMarkdownMemo : RenderMarkdown;
return block.type === 'htmlb'
? <RenderHtml key={'html-' + index} htmlBlock={block} sx={scaledCodeSx} />
: block.type === 'codeb'
? <RenderCodeMemoOrNot key={'code-' + index} codeBlock={block} fitScreen={props.fitScreen} initialShowHTML={props.showUnsafeHtml} noCopyButton={props.specialDiagramMode} optimizeLightweight={!optimizeSubBlockWithMemo} sx={scaledCodeSx} />
: block.type === 'imageb'
? <RenderImage key={'image-' + index} imageBlock={block} onRunAgain={props.isBottom ? props.onImageRegenerate : undefined} sx={scaledImageSx} />
: block.type === 'diffb'
? <RenderTextDiff key={'text-diff-' + index} diffBlock={block} sx={scaledTypographySx} />
: (props.renderTextAsMarkdown && !fromSystem && !isUserCommand)
? <RenderMarkdownMemoOrNot key={'text-md-' + index} textBlock={block} sx={scaledTypographySx} />
: <RenderChatText key={'text-' + index} textBlock={block} sx={scaledTypographySx} />;
})
)}
{/* sequence of render components, for each Block */}
{blocks.map((block, index) => {
// Optimization: only memo the non-currently-rendered components, if the message is still in flux
const optimizeSubBlockWithMemo = props.optiAllowSubBlocksMemo && index !== blocks.length - 1;
const RenderCodeMemoOrNot = optimizeSubBlockWithMemo ? RenderCodeMemo : RenderCode;
const RenderMarkdownMemoOrNot = optimizeSubBlockWithMemo ? RenderMarkdownMemo : RenderMarkdown;
return block.type === 'htmlb'
? <RenderHtml key={'html-' + index} htmlBlock={block} sx={scaledCodeSx} />
: block.type === 'codeb'
? <RenderCodeMemoOrNot key={'code-' + index} codeBlock={block} fitScreen={props.fitScreen} initialShowHTML={props.showUnsafeHtml} noCopyButton={props.specialDiagramMode} optimizeLightweight={!optimizeSubBlockWithMemo} sx={scaledCodeSx} />
: block.type === 'imageb'
? <RenderImageURL key={'image-' + index} imageBlock={block} onRunAgain={/*props.isBottom ? props.onImageRegenerate :*/ undefined} sx={scaledImageSx} />
: block.type === 'diffb'
? <RenderTextDiff key={'text-diff-' + index} diffBlock={block} sx={scaledTypographySx} />
: (props.renderTextAsMarkdown && !fromSystem && !isUserCommand)
? <RenderMarkdownMemoOrNot key={'text-md-' + index} textBlock={block} sx={scaledTypographySx} />
: <RenderChatText key={'text-' + index} textBlock={block} sx={scaledTypographySx} />;
})}
{isTextCollapsed ? (
<Box sx={{ textAlign: 'right' }}><Button variant='soft' size='sm' onClick={handleTextUncollapse} startDecorator={<ExpandMoreIcon />} sx={{ minWidth: 120 }}>Expand</Button></Box>
@@ -70,7 +70,7 @@ export function heuristicLegacyImageBlocks(fullText: string): ImageBlock[] | nul
}
export const RenderImage = (props: {
export const RenderImageURL = (props: {
imageBlock: ImageBlock,
noTooltip?: boolean,
onRunAgain?: (e: React.MouseEvent) => void, sx?: SxProps,
+1 -1
View File
@@ -1,7 +1,7 @@
import type { Diff as TextDiff } from '@sanity/diff-match-patch';
import { heuristicIsHtml } from './RenderHtml';
import { heuristicLegacyImageBlocks, heuristicMarkdownImageReferenceBlocks } from './RenderImage';
import { heuristicLegacyImageBlocks, heuristicMarkdownImageReferenceBlocks } from './RenderImageURL';
// Block types
export type Block = CodeBlock | DiffBlock | HtmlBlock | ImageBlock | TextBlock;