mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* fix: Reset artifacts on unmount and remove useIdChangeEffect hook * feat: Replace SVG icons with Lucide icons for improved consistency * fix: Refactor artifact reset logic on unmount and conversation change * refactor: Rename artifactsVisible to artifactsVisibility for consistency * feat: Replace custom SVG icons with Lucide icons for improved consistency * feat: Add visibleArtifacts atom for managing visibility state * feat: Implement debounced visibility state management for artifacts * refactor: Add useIdChangeEffect hook to reset visible artifacts on conversation ID change * refactor: Remove unnecessary dependency from useMemo in TextPart component * refactor: Enhance artifact visibility management by incorporating location checks for search path * refactor: Improve transition effects for artifact visibility in Artifacts component * chore: Remove preprocessCodeArtifacts function and related tests * fix: Update regex for detecting enclosed artifacts in latest message * refactor: Update artifact visibility checks to be more generic (not just search) * chore: Enhance artifact visibility logging * refactor: Extract closeArtifacts function to improve button click handling * refactor: remove nested logic from use artifacts effect * refactor: Update regex for detecting enclosed artifacts to handle new line variations
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { memo, useMemo, ReactElement } from 'react';
|
|
import { useRecoilValue } from 'recoil';
|
|
import MarkdownLite from '~/components/Chat/Messages/Content/MarkdownLite';
|
|
import Markdown from '~/components/Chat/Messages/Content/Markdown';
|
|
import { useChatContext, useMessageContext } from '~/Providers';
|
|
import { cn } from '~/utils';
|
|
import store from '~/store';
|
|
|
|
type TextPartProps = {
|
|
text: string;
|
|
showCursor: boolean;
|
|
isCreatedByUser: boolean;
|
|
};
|
|
|
|
type ContentType =
|
|
| ReactElement<React.ComponentProps<typeof Markdown>>
|
|
| ReactElement<React.ComponentProps<typeof MarkdownLite>>
|
|
| ReactElement;
|
|
|
|
const TextPart = memo(({ text, isCreatedByUser, showCursor }: TextPartProps) => {
|
|
const { messageId } = useMessageContext();
|
|
const { isSubmitting, latestMessage } = useChatContext();
|
|
const enableUserMsgMarkdown = useRecoilValue(store.enableUserMsgMarkdown);
|
|
const showCursorState = useMemo(() => showCursor && isSubmitting, [showCursor, isSubmitting]);
|
|
const isLatestMessage = useMemo(
|
|
() => messageId === latestMessage?.messageId,
|
|
[messageId, latestMessage?.messageId],
|
|
);
|
|
|
|
const content: ContentType = useMemo(() => {
|
|
if (!isCreatedByUser) {
|
|
return <Markdown content={text} isLatestMessage={isLatestMessage} />;
|
|
} else if (enableUserMsgMarkdown) {
|
|
return <MarkdownLite content={text} />;
|
|
} else {
|
|
return <>{text}</>;
|
|
}
|
|
}, [isCreatedByUser, enableUserMsgMarkdown, text, isLatestMessage]);
|
|
|
|
return (
|
|
<div
|
|
className={cn(
|
|
isSubmitting ? 'submitting' : '',
|
|
showCursorState && !!text.length ? 'result-streaming' : '',
|
|
'markdown prose message-content dark:prose-invert light w-full break-words',
|
|
isCreatedByUser && !enableUserMsgMarkdown && 'whitespace-pre-wrap',
|
|
isCreatedByUser ? 'dark:text-gray-20' : 'dark:text-gray-100',
|
|
)}
|
|
>
|
|
{content}
|
|
</div>
|
|
);
|
|
});
|
|
|
|
export default TextPart;
|