🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style: use @lobehub/ui built-in HtmlPreview instead of custom component (#14703)
Arvin Xu266d10206b1a
diff --git a/src/components/HtmlPreview/HtmlPreviewAction.tsx b/src/components/HtmlPreview/HtmlPreviewAction.tsxdeleted file mode 100644index 05bc95fca38..00000000000--- a/src/components/HtmlPreview/HtmlPreviewAction.tsx+++ /dev/null@@ -1,32 +0,0 @@-import { ActionIcon } from '@lobehub/ui';-import { Eye } from 'lucide-react';-import { memo, useState } from 'react';-import { useTranslation } from 'react-i18next';--import HtmlPreviewDrawer from './PreviewDrawer';--interface HtmlPreviewActionProps {- content: string;- size?: number;-}--const HtmlPreviewAction = memo<HtmlPreviewActionProps>(({ content, size }) => {- const { t } = useTranslation('components');- const [open, setOpen] = useState(false);-- return (- <>- <ActionIcon- icon={Eye}- size={size}- title={t('HtmlPreview.actions.preview')}- onClick={() => setOpen(true)}- />- <HtmlPreviewDrawer content={content} open={open} onClose={() => setOpen(false)} />- </>- );-});--HtmlPreviewAction.displayName = 'HtmlPreviewAction';--export default HtmlPreviewAction;diff --git a/src/components/HtmlPreview/index.ts b/src/components/HtmlPreview/index.tsindex 12af3b27807..2cd4a72f38b 100644--- a/src/components/HtmlPreview/index.ts+++ b/src/components/HtmlPreview/index.ts@@ -1,2 +1 @@-export { default as HtmlPreviewAction } from './HtmlPreviewAction';export { default as HtmlPreviewDrawer } from './PreviewDrawer';diff --git a/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx b/src/features/Conversation/Messages/Assistant/components/MessageContent.tsxindex 1a6d43d917e..18a1a372639 100644--- a/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx+++ b/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx@@ -18,7 +18,7 @@ import { useMarkdown } from '../useMarkdown';const MessageContent = memo<UIChatMessage>(({ id, tools, content, chunksList, search, imageList, metadata, ...props }) => {- const markdownProps = useMarkdown(id);+ const { drawer, markdownProps } = useMarkdown(id);// Use ConversationStore instead of ChatStoreconst generating = useConversationStore(messageStateSelectors.isMessageGenerating(id));const isCreating = useConversationStore(messageStateSelectors.isMessageCreating(id));@@ -68,6 +68,7 @@ const MessageContent = memo<UIChatMessage>(return (<Flexbox gap={8} id={id}>+ {drawer}{showSearch && (<SearchGroundingcitations={search?.citations}diff --git a/src/features/Conversation/Messages/Assistant/useMarkdown.tsx b/src/features/Conversation/Messages/Assistant/useMarkdown.tsxindex b80c7d307fe..aae4818594c 100644--- a/src/features/Conversation/Messages/Assistant/useMarkdown.tsx+++ b/src/features/Conversation/Messages/Assistant/useMarkdown.tsx@@ -2,9 +2,9 @@import { type MarkdownProps } from '@lobehub/ui';import isEqual from 'fast-deep-equal';-import { useMemo } from 'react';+import { type ReactNode, useMemo, useState } from 'react';-import { HtmlPreviewAction } from '@/components/HtmlPreview';+import { HtmlPreviewDrawer } from '@/components/HtmlPreview';import { useUserStore } from '@/store/user';import { userGeneralSettingsSelectors } from '@/store/user/selectors';@@ -14,21 +14,17 @@ import { dataSelectors, messageStateSelectors, useConversationStore } from '../.const rehypePlugins = markdownElements.map((element) => element.rehypePlugin).filter(Boolean);const remarkPlugins = markdownElements.map((element) => element.remarkPlugin).filter(Boolean);-const isHtmlCode = (content: string, language: string) => {- return (- language === 'html' ||- (language === '' && content.includes('<html>')) ||- (language === '' && content.includes('<!DOCTYPE html>'))- );-};--export const useMarkdown = (id: string): Partial<MarkdownProps> => {+export const useMarkdown = (+ id: string,+): { drawer: ReactNode; markdownProps: Partial<MarkdownProps> } => {const item = useConversationStore(dataSelectors.getDbMessageById(id), isEqual)!;const { role, search } = item || {};const { transitionMode } = useUserStore(userGeneralSettingsSelectors.config);const generating = useConversationStore(messageStateSelectors.isMessageGenerating(id));const animated = transitionMode === 'fadeIn' && generating;+ const [drawerContent, setDrawerContent] = useState<string | null>(null);+const components = useMemo(() =>Object.fromEntries(@@ -40,36 +36,37 @@ export const useMarkdown = (id: string): Partial<MarkdownProps> => {[id],);- return useMemo(+ const markdownProps = useMemo(() =>({animated,citations: search?.citations,componentProps: {- highlight: {- actionsRender: ({ content, actionIconSize, language, originalNode }: any) => {- const showHtmlPreview = isHtmlCode(content, language);- return (- <>- {showHtmlPreview && <HtmlPreviewAction content={content} size={actionIconSize} />}- {originalNode}- </>- );- },+ html: {+ onExpand: (content: string) => setDrawerContent(content),},},components,enableCustomFootnotes: true,+ enableHtmlPreview: true,enableStream: true,rehypePlugins,remarkPlugins,showFootnotes:search?.citations &&- // if the citations are all empty, we should not show the citationssearch?.citations.length > 0 &&- // if the citations's url and title are all the same, we should not show the citationssearch?.citations.every((item) => item.title !== item.url),}) satisfies Partial<MarkdownProps>,[animated, components, role, search],);++ const drawer = drawerContent ? (+ <HtmlPreviewDrawer+ content={drawerContent}+ open={!!drawerContent}+ onClose={() => setDrawerContent(null)}+ />+ ) : null;++ return useMemo(() => ({ drawer, markdownProps }), [drawer, markdownProps]);};diff --git a/src/features/Conversation/Messages/Task/components/MessageContent.tsx b/src/features/Conversation/Messages/Task/components/MessageContent.tsxindex 6a40dfea80d..de25f0c9fd9 100644--- a/src/features/Conversation/Messages/Task/components/MessageContent.tsx+++ b/src/features/Conversation/Messages/Task/components/MessageContent.tsx@@ -15,7 +15,7 @@ import SearchGrounding from '../../components/SearchGrounding';const MessageContent = memo<UIChatMessage>(({ id, tools, content, chunksList, search, imageList, metadata, ...props }) => {- const markdownProps = useMarkdown(id);+ const { drawer, markdownProps } = useMarkdown(id);// Use ConversationStore instead of ChatStoreconst generating = useConversationStore(messageStateSelectors.isMessageGenerating(id));const isCollapsed = useConversationStore(messageStateSelectors.isMessageCollapsed(id));@@ -41,12 +41,13 @@ const MessageContent = memo<UIChatMessage>(return (<Flexbox gap={8} id={id}>+ {drawer}{showSearch && (<SearchGrounding- citations={search?.citations}- imageResults={search?.imageResults}- imageSearchQueries={search?.imageSearchQueries}- searchQueries={search?.searchQueries}+ citations={search.citations}+ imageResults={search.imageResults}+ imageSearchQueries={search.imageSearchQueries}+ searchQueries={search.searchQueries}/>)}{showFileChunks && <FileChunks data={chunksList} />}diff --git a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/FileItem.tsx b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/FileItem.tsxindex 685054b8a54..5217b723bc7 100644--- a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/FileItem.tsx+++ b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/FileItem.tsx@@ -40,6 +40,12 @@ const styles = createStaticStyles(({ css, cssVar }) => ({color: ${cssVar.colorError};}`,+ // Pushes the revert trigger to the right edge of the header so it sits+ // next to the Collapse chevron, visually separating the destructive action+ // from the path-related copy icon.+ revertWrapper: css`+ margin-inline-start: auto;+ `,deletions: css`color: ${cssVar.colorError};`,@@ -178,6 +184,13 @@ export const FileItemHeader = memo<FileItemHeaderProps>({additions > 0 && deletions > 0 && ' '}{deletions > 0 && <span className={styles.deletions}>-{deletions}</span>}</span>+ <ActionIcon+ className={styles.rowAction}+ icon={CopyIcon}+ size={'small'}+ title={t('workingPanel.review.copyPath')}+ onClick={handleCopy}+ />{revertContext && (<Popconfirmarrow={false}@@ -195,7 +208,7 @@ export const FileItemHeader = memo<FileItemHeaderProps>(onConfirm={handleConfirmRevert}onOpenChange={setConfirmOpen}>- <span onClick={(event) => event.stopPropagation()}>+ <span className={styles.revertWrapper} onClick={(event) => event.stopPropagation()}><ActionIconclassName={`${styles.rowAction} ${styles.revertDanger}`}data-force-visible={confirmOpen}@@ -206,13 +219,6 @@ export const FileItemHeader = memo<FileItemHeaderProps>(</span></Popconfirm>)}- <ActionIcon- className={styles.rowAction}- icon={CopyIcon}- size={'small'}- title={t('workingPanel.review.copyPath')}- onClick={handleCopy}- /></span>);},