🤯 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
✨ feat(portal): show the document outline rail in the portal document view (#22589)
Arvin Xua1e0574c939f
diff --git a/src/features/Portal/Document/Body.test.tsx b/src/features/Portal/Document/Body.test.tsxindex 83405756425..0b44540ed62 100644--- a/src/features/Portal/Document/Body.test.tsx+++ b/src/features/Portal/Document/Body.test.tsx@@ -88,6 +88,23 @@ vi.mock('./TodoList', () => ({default: () => <div data-testid="todo-list" />,}));+const mockTocProps = vi.hoisted(() => ({+ current: undefined as+ | {+ contentRef: { current: HTMLElement | null };+ scrollRef: { current: HTMLElement | null };+ }+ | undefined,+}));++vi.mock('@/features/PageEditor/TableOfContents', () => ({+ TOC_RAIL_GUTTER: 32,+ default: (props: NonNullable<typeof mockTocProps.current>) => {+ mockTocProps.current = props;+ return <div data-testid="table-of-contents" />;+ },+}));+vi.mock('@/features/FloatingChatPanel', () => ({default: () => <div data-testid="floating-chat-panel" />,}));@@ -216,6 +233,29 @@ describe('DocumentBody', () => {expect(screen.getByTestId('char-limit-banner').dataset.documentId).toBe('document-1');});+ it('offers the outline rail for rich-text documents, wired to the portal scroll host', () => {+ mockDocumentMeta.current = { content: '# hi', filename: 'note.md' };++ render(<DocumentBody />);++ expect(screen.getByTestId('table-of-contents')).toBeDefined();+ const canvas = screen.getByTestId('editor-canvas');+ expect(mockTocProps.current?.contentRef.current).toContainElement(canvas);+ expect(mockTocProps.current?.scrollRef.current).toContainElement(canvas);+ });++ it.each([+ ['highlight', { content: 'raw', filename: 'topic_call.txt' }],+ ['html', { content: '<h1>a</h1><h2>b</h2>', fileType: 'custom/html', filename: 'report' }],+ ['file', { content: '', fileId: 'file-original', filename: 'source.unknown' }],+ ])('does not offer the outline rail in %s mode', (_mode, meta) => {+ mockDocumentMeta.current = meta;++ render(<DocumentBody />);++ expect(screen.queryByTestId('table-of-contents')).toBeNull();+ });+it('renders an HTML page in a sandboxed frame without mounting either editor', () => {mockDocumentMeta.current = {content: '<!doctype html><html><body><h1>Goal report</h1></body></html>',diff --git a/src/features/Portal/Document/Body.tsx b/src/features/Portal/Document/Body.tsxindex e9ca337eeb0..ad621206447 100644--- a/src/features/Portal/Document/Body.tsx+++ b/src/features/Portal/Document/Body.tsx@@ -5,13 +5,14 @@ import {Button,createStaticStyles,cssVar,+ cx,Flexbox,Text,TextArea,} from '@lobehub/ui';import { CheckIcon, PencilIcon, XIcon } from 'lucide-react';import type { ChangeEvent } from 'react';-import { memo, useCallback, useEffect, useMemo, useState } from 'react';+import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import AsyncError from '@/components/AsyncError';@@ -21,6 +22,7 @@ import Loading from '@/components/Loading/CircleLoading';import CharLimitBanner from '@/features/EditorCanvas/CharLimitBanner';import FileNotFound from '@/features/FileNotFound';import { FileDocumentPreview } from '@/features/FileViewer/FileDocumentPreview';+import TableOfContents, { TOC_RAIL_GUTTER } from '@/features/PageEditor/TableOfContents';import WideScreenContainer from '@/features/WideScreenContainer';import { useDocumentStore } from '@/store/document';import { getDocumentRenderMode } from '@/utils/documentRenderMode';@@ -46,6 +48,15 @@ const styles = createStaticStyles(({ css }) => ({overflow: auto;flex: 1;`,+ contentWithToc: css`+ /* The TOC rail is hidden at this width (see TableOfContents). */+ @media (width > 1024px) {+ /* The editor bleeds tables past the column, which would run under the rail. */+ --lobe-table-bleed: 0px;++ padding-inline-end: ${TOC_RAIL_GUTTER}px;+ }+ `,textArea: css`font-family: ${cssVar.fontFamilyCode};`,@@ -233,6 +244,8 @@ const DocumentBody = memo(() => {: ['', undefined],);const isSkillMarkdown = contentFormat === 'skillMarkdown';+ const scrollRef = useRef<HTMLDivElement>(null);+ const [tocVisible, setTocVisible] = useState(false);const useFetchDocumentDetail = useDocumentStore((s) => s.useFetchDocumentDetail);const beginDocumentDetailPatch = useDocumentStore((s) => s.beginDocumentDetailPatch);@@ -300,20 +313,32 @@ const DocumentBody = memo(() => {if (!documentMeta) return <FileNotFound />;return (- <Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden' }}>+ <Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden', position: 'relative' }}>{/* Above the scroll host, so the plan page-size notice stays in view. */}{(renderMode.mode === 'editor' || renderMode.mode === 'highlight') && (<Flexbox paddingInline={16}><CharLimitBanner documentId={documentId} /></Flexbox>)}- <div className={fullPage ? styles.contentFull : styles.content}>+ <div+ ref={scrollRef}+ className={+ fullPage ? styles.contentFull : cx(styles.content, tocVisible && styles.contentWithToc)+ }+ >{fullPage && renderMode.mode !== 'file' ? (<WideScreenContainer>{editorContent}</WideScreenContainer>) : (editorContent)}</div>+ {renderMode.mode === 'editor' && (+ <TableOfContents+ contentRef={scrollRef}+ scrollRef={scrollRef}+ onVisibleChange={setTocVisible}+ />+ )}{renderMode.mode !== 'file' && <TodoList />}</Flexbox>);