🤯 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(resource): preview files and pages in an inline right detail panel (#19599)
Arvin Xu7bca055b6a9c
diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/FilePreview.tsx b/src/features/ResourceManager/components/Explorer/FileDetailPanel/FilePreview.tsxnew file mode 100644index 00000000000..42b9af6cc9b--- /dev/null+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/FilePreview.tsx@@ -0,0 +1,31 @@+'use client';++import { Center, Empty } from '@lobehub/ui';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++import FileViewer from '@/features/FileViewer';+import { type FileListItem } from '@/types/files';++interface FilePreviewProps {+ file: FileListItem;+}++/**+ * Live preview of the selected resource inside the detail panel. Falls back+ * to a neutral hint for types the FileViewer cannot render.+ */+const FilePreview = memo<FilePreviewProps>(({ file }) => {+ const { t } = useTranslation('file');++ if (!file?.url)+ return (+ <Center height={'100%'} width={'100%'}>+ <Empty description={t('preview.unsupportedFileAndContact')} />+ </Center>+ );++ return <FileViewer {...file} id={file.fileId ?? file.id} />;+});++export default FilePreview;diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/PagePreview.tsx b/src/features/ResourceManager/components/Explorer/FileDetailPanel/PagePreview.tsxnew file mode 100644index 00000000000..315363e00be--- /dev/null+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/PagePreview.tsx@@ -0,0 +1,47 @@+'use client';++import { Center, Empty, Flexbox, Markdown } from '@lobehub/ui';+import { Skeleton } from '@lobehub/ui/base-ui';+import { memo } from 'react';++import { useClientDataSWR } from '@/libs/swr';+import { portalKeys } from '@/libs/swr/keys';+import { documentService } from '@/services/document';++interface PagePreviewProps {+ id: string;+}++/**+ * Read-only preview of a page (文稿) inside the detail panel. Pages carry no+ * file URL, so render the document's Markdown content instead of FileViewer.+ */+const PagePreview = memo<PagePreviewProps>(({ id }) => {+ const { data: document, isLoading } = useClientDataSWR(portalKeys.documentHeader(id), () =>+ documentService.getDocumentById(id),+ );++ if (isLoading)+ return (+ <Flexbox padding={24}>+ <Skeleton.Text rows={6} width={['60%', '90%', '80%', '85%', '70%', '40%']} />+ </Flexbox>+ );++ if (!document?.content)+ return (+ <Center height={'100%'} width={'100%'}>+ <Empty />+ </Center>+ );++ return (+ <Flexbox paddingBlock={16} paddingInline={24}>+ <Markdown variant={'chat'}>{document.content}</Markdown>+ </Flexbox>+ );+});++PagePreview.displayName = 'PagePreview';++export default PagePreview;diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/index.tsx b/src/features/ResourceManager/components/Explorer/FileDetailPanel/index.tsxnew file mode 100644index 00000000000..789e963d9fa--- /dev/null+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/index.tsx@@ -0,0 +1,129 @@+'use client';++import { Flexbox } from '@lobehub/ui';+import { ActionIcon, DraggablePanel } from '@lobehub/ui/base-ui';+import { cssVar, useTheme } from 'antd-style';+import { t as i18nT } from 'i18next';+import { DownloadIcon, InfoIcon, PanelRightCloseIcon } from 'lucide-react';+import { memo, useState } from 'react';++import FileDetail from '@/features/ResourceManager/FileDetail';+import { useResourceManagerStore } from '@/features/ResourceManager/store';+import { downloadFile } from '@/utils/client/downloadFile';++import FilePreview from './FilePreview';+import PagePreview from './PagePreview';+import { useDetailPanelFile } from './useDetailPanelFile';++/**+ * In-context right dock for the explorer list: single click on a file row+ * below shows a live preview here, split-screen style — the list stays+ * visible (no mask, no modal). The properties column is opt-in from the+ * header so the preview gets the whole dock by default. Double click still+ * commits to the fullscreen editor.+ */+const FileDetailPanel = memo(() => {+ const theme = useTheme();+ const detailPanelId = useResourceManagerStore((s) => s.detailPanelId);+ const detailPanelIsPage = useResourceManagerStore((s) => s.detailPanelIsPage);+ const closeDetailPanel = useResourceManagerStore((s) => s.closeDetailPanel);+ const [showProperties, setShowProperties] = useState(false);++ const fileDetail = useDetailPanelFile(detailPanelId);++ return (+ <DraggablePanel+ backgroundColor={cssVar.colorBgContainer}+ expand={!!detailPanelId}+ expandable={false}+ minWidth={320}+ placement={'right'}+ size={{ height: '100%', width: 480 }}+ style={{+ borderInlineStart: `1px solid ${cssVar.colorBorderSecondary}`,+ boxShadow: theme.boxShadowTertiary,+ }}+ >+ {fileDetail && (+ <Flexbox height={'100%'} style={{ minHeight: 0, overflow: 'hidden' }}>+ <Flexbox+ horizontal+ align={'center'}+ gap={8}+ justify={'space-between'}+ paddingInline={16}+ style={{+ flexShrink: 0,+ borderBottom: `1px solid ${cssVar.colorBorderSecondary}`,+ minHeight: 48,+ }}+ >+ <span+ title={fileDetail.name}+ style={{+ color: theme.colorText,+ fontSize: 14,+ fontWeight: 500,+ minWidth: 0,+ overflow: 'hidden',+ textOverflow: 'ellipsis',+ whiteSpace: 'nowrap',+ }}+ >+ {fileDetail.name}+ </span>+ <Flexbox horizontal align={'center'} gap={4} style={{ flexShrink: 0 }}>+ {fileDetail.url && (+ <ActionIcon+ icon={DownloadIcon}+ title={i18nT('download', { ns: 'common' })}+ onClick={() => {+ if (fileDetail.url) downloadFile(fileDetail.url, fileDetail.name);+ }}+ />+ )}+ <ActionIcon+ active={showProperties}+ icon={InfoIcon}+ title={i18nT('detail.basic.title', { ns: 'file' })}+ onClick={() => setShowProperties((value) => !value)}+ />+ <ActionIcon+ icon={PanelRightCloseIcon}+ title={i18nT('close', { ns: 'common' })}+ onClick={closeDetailPanel}+ />+ </Flexbox>+ </Flexbox>+ <Flexbox horizontal flex={1} style={{ minHeight: 0, overflow: 'hidden' }}>+ <Flexbox flex={1} style={{ minHeight: 0, minWidth: 0, overflow: 'auto' }}>+ {detailPanelIsPage && detailPanelId ? (+ <PagePreview id={detailPanelId} />+ ) : (+ <FilePreview file={fileDetail} />+ )}+ </Flexbox>+ {showProperties && (+ <Flexbox+ style={{+ borderInlineStart: `1px solid ${cssVar.colorSplit}`,+ flexShrink: 0,+ overflow: 'auto',+ paddingBlock: 12,+ paddingInline: 16,+ width: 220,+ }}+ >+ <FileDetail {...fileDetail} showDownloadButton={false} showTitle={false} />+ </Flexbox>+ )}+ </Flexbox>+ </Flexbox>+ )}+ </DraggablePanel>+ );+});++FileDetailPanel.displayName = 'FileDetailPanel';++export default FileDetailPanel;diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelFile.test.ts b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelFile.test.tsnew file mode 100644index 00000000000..de607bfab33--- /dev/null+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelFile.test.ts@@ -0,0 +1,67 @@+import { renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useDetailPanelFile } from './useDetailPanelFile';++const mocks = vi.hoisted(() => ({+ fetchKnowledgeItem: vi.fn(),+ fileInList: undefined as { id: string; name: string } | undefined,+ resourceMap: new Map<string, { id: string; name: string }>(),+}));++vi.mock('@/store/file', () => ({+ fileManagerSelectors: {+ getFileById: () => () => mocks.fileInList,+ },+ useFileStore: (selector: (state: any) => unknown) =>+ selector({ resourceMap: mocks.resourceMap, useFetchKnowledgeItem: mocks.fetchKnowledgeItem }),+}));++describe('useDetailPanelFile', () => {+ beforeEach(() => {+ mocks.fileInList = undefined;+ mocks.resourceMap = new Map();+ mocks.fetchKnowledgeItem.mockReset();+ });++ it('returns the fetched item when the file is not loaded anywhere', () => {+ mocks.fetchKnowledgeItem.mockReturnValue({+ data: { id: 'resource-1', name: 'analysis-report.md' },+ });++ const { result } = renderHook(() => useDetailPanelFile('resource-1'));++ expect(mocks.fetchKnowledgeItem).toHaveBeenCalledWith('resource-1');+ expect(result.current).toEqual({ id: 'resource-1', name: 'analysis-report.md' });+ });++ it('uses the loaded list entry and skips the request', () => {+ mocks.fileInList = { id: 'resource-1', name: 'final.pdf' };+ mocks.fetchKnowledgeItem.mockReturnValue({ data: undefined });++ const { result } = renderHook(() => useDetailPanelFile('resource-1'));++ expect(mocks.fetchKnowledgeItem).toHaveBeenCalledWith(undefined);+ expect(result.current).toEqual({ id: 'resource-1', name: 'final.pdf' });+ });++ it('uses the explorer resource row and skips the request', () => {+ mocks.resourceMap.set('docs_1', { id: 'docs_1', name: 'detail-panel-notes.md' });+ mocks.fetchKnowledgeItem.mockReturnValue({ data: undefined });++ const { result } = renderHook(() => useDetailPanelFile('docs_1'));++ // Explorer rows are only in `resourceMap`; missing it rendered a blank panel+ // until a duplicate request for an already visible row came back.+ expect(mocks.fetchKnowledgeItem).toHaveBeenCalledWith(undefined);+ expect(result.current).toEqual({ id: 'docs_1', name: 'detail-panel-notes.md' });+ });++ it('returns nothing when no file is selected', () => {+ mocks.fetchKnowledgeItem.mockReturnValue({ data: undefined });++ const { result } = renderHook(() => useDetailPanelFile(undefined));++ expect(result.current).toBeUndefined();+ });+});diff --git a/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelFile.ts b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelFile.tsnew file mode 100644index 00000000000..604d187bce0--- /dev/null+++ b/src/features/ResourceManager/components/Explorer/FileDetailPanel/useDetailPanelFile.ts@@ -0,0 +1,21 @@+import { fileManagerSelectors, useFileStore } from '@/store/file';+import { type FileListItem } from '@/types/files';++/**+ * Resolve the resource shown in the detail panel: the already-loaded row when+ * there is one, otherwise a single-item fetch (e.g. the list page has not+ * reached it yet, or it belongs to another view). Explorer rows live in the+ * resource store (`resourceMap`), not the legacy `fileList`, so both are checked+ * before falling back to the request.+ */+export const useDetailPanelFile = (id?: string): FileListItem | undefined => {+ const fromStore = useFileStore(+ (s) =>+ fileManagerSelectors.getFileById(id)(s) ??+ (id ? (s.resourceMap.get(id) as FileListItem | undefined) : undefined),+ );+ const useFetchKnowledgeItem = useFileStore((s) => s.useFetchKnowledgeItem);+ const { data: fromQuery } = useFetchKnowledgeItem(!fromStore ? id : undefined);++ return fromStore ?? fromQuery;+};diff --git a/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.test.tsx b/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.test.tsxindex 4688a18e81a..ba0fa511678 100644--- a/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.test.tsx+++ b/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.test.tsx@@ -45,6 +45,7 @@ vi.mock('@/store/file', () => ({vi.mock('../../hooks/useFileItemClick', () => ({useFileItemClick: () => vi.fn(),+ useFileItemDoubleClick: () => vi.fn(),}));vi.mock('../../ItemDropdown/useFileItemDropdown', () => ({diff --git a/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx b/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsxindex bc1e8588d95..990391098f7 100644--- a/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx+++ b/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx@@ -13,7 +13,7 @@ import { fileManagerSelectors, getChunkTargetId, useFileStore } from '@/store/fiimport type { FileListItem as FileListItemType } from '@/types/files';import { formatSize } from '@/utils/format';-import { useFileItemClick } from '../../hooks/useFileItemClick';+import { useFileItemClick, useFileItemDoubleClick } from '../../hooks/useFileItemClick';import { useFileItemDropdown } from '../../ItemDropdown/useFileItemDropdown';import { getListViewMinWidth } from './constants';import FileListItemActions from './FileListItemActions';@@ -240,8 +240,10 @@ const FileListItem = ({isFolder,isPage,libraryId: resourceManagerState.libraryId,+ openInPanel: true,slug,});+ const handleItemDoubleClick = useFileItemDoubleClick({ id, isPage });const { menuItems } = useFileItemDropdown({fileId,fileType,@@ -297,6 +299,7 @@ const FileListItem = ({userSelect: 'none',}}onClick={handleItemClick}+ onDoubleClick={handleItemDoubleClick}onDragEnd={handleDragEnd}onDragLeave={handleDragLeave}onDragOver={handleDragOver}diff --git a/src/features/ResourceManager/components/Explorer/MasonryView/MasonryItem/index.tsx b/src/features/ResourceManager/components/Explorer/MasonryView/MasonryItem/index.tsxindex 11f000de818..d277df96dfe 100644--- a/src/features/ResourceManager/components/Explorer/MasonryView/MasonryItem/index.tsx+++ b/src/features/ResourceManager/components/Explorer/MasonryView/MasonryItem/index.tsx@@ -20,7 +20,7 @@ import { showContextMenu } from '@/libs/contextMenu';import { getChunkTargetId, useFileStore } from '@/store/file';import { type FileListItem } from '@/types/files';-import { useFileItemClick } from '../../hooks/useFileItemClick';+import { useFileItemClick, useFileItemDoubleClick } from '../../hooks/useFileItemClick';import DropdownMenu from '../../ItemDropdown/DropdownMenu';import { useFileItemDropdown } from '../../ItemDropdown/useFileItemDropdown';import AudioFileItem from './AudioFileItem';@@ -249,8 +249,10 @@ const MasonryFileItem = memo<MasonryFileItemProps>(isPage,libraryId: knowledgeBaseId,onOpen,+ openInPanel: true,slug,});+ const handleItemDoubleClick = useFileItemDoubleClick({ id, isPage });// Memoize drag data to prevent recreationconst dragData = useMemo(@@ -418,6 +420,7 @@ const MasonryFileItem = memo<MasonryFileItemProps>(styles.contentWithPadding,)}onClick={handleItemClick}+ onDoubleClick={handleItemDoubleClick}>{(() => {switch (true) {diff --git a/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx b/src/features/ResourceManager/components/Explorer/MasonryView/index.tsxindex 2a519d8be95..0a22e13ad7f 100644--- a/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx+++ b/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx@@ -20,7 +20,7 @@ import {} from '../hooks/useExplorerSelection';import { isQueryNavigation } from '../isQueryNavigation';import SourceFilter from '../ToolBar/SourceFilter';-import { useMasonryColumnCount } from '../useMasonryColumnCount';+import { useContainerMasonryColumnCount } from '../useMasonryColumnCount';import MasonryItemWrapper from './MasonryItem/MasonryItemWrapper';import MasonryViewSkeleton from './Skeleton';import { useMasonryViewState } from './useMasonryViewState';@@ -73,7 +73,8 @@ const MasonryView = memo(function MasonryView({]);const { t } = useTranslation(['components', 'file']);- const columnCount = useMasonryColumnCount();+ const [container, setContainer] = useState<HTMLDivElement | null>(null);+ const columnCount = useContainerMasonryColumnCount(container);const [isLoadingMore, setIsLoadingMore] = useState(false);// NEW: Read from resource store instead of fetching independently@@ -214,7 +215,10 @@ const MasonryView = memo(function MasonryView({}}onScroll={handleScroll}>- <div style={{ paddingBlockEnd: 24, paddingBlockStart: 12, paddingInline: 24 }}>+ <div+ ref={setContainer}+ style={{ paddingBlockEnd: 24, paddingBlockStart: 12, paddingInline: 24 }}+ ><Flexbox horizontal align={'center'} className={styles.toolbar} gap={8}><Checkboxchecked={allSelected}diff --git a/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.desktop.test.ts b/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.desktop.test.tsindex 13235dd8d97..a8ad4933d33 100644--- a/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.desktop.test.ts+++ b/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.desktop.test.ts@@ -23,7 +23,9 @@ vi.mock(const { getOrCreateTabRouter, getTabRouter, resetTabRouterManager } =await import('@/features/Electron/TabHost/tabRouterManager');const { useElectronStore } = await import('@/store/electron');-const { useFileItemClick } = await import('./useFileItemClick');+const { useResourceManagerStore } = await import('@/features/ResourceManager/store');+const { DETAIL_PANEL_OPEN_DELAY_MS, useFileItemClick, useFileItemDoubleClick } =+ await import('./useFileItemClick');const TAB_ID = 'tab-1';const TAB_URL = '/resource/library/kb_1?view=grid';@@ -57,31 +59,178 @@ const setupActiveTab = (url: string) => {getOrCreateTabRouter(TAB_ID, url, createRouter);};+const flushPanelOpenDelay = () =>+ act(async () => {+ vi.advanceTimersByTime(DETAIL_PANEL_OPEN_DELAY_MS);+ });+beforeEach(() => {+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });setupActiveTab(TAB_URL);+ useResourceManagerStore.setState({+ currentViewItemId: undefined,+ detailPanelId: undefined,+ detailPanelIsPage: false,+ mode: 'explorer',+ });});afterEach(() => {cleanup();+ vi.useRealTimers();resetTabRouterManager();useElectronStore.setState({ activeTabId: null, tabs: [] });});describe('useFileItemClick (desktop shell)', () => {- it('writes ?file= to the active tab router, not the shell router', async () => {+ it('opens the inline detail panel without touching the tab URL', async () => {const { result } = renderFileClick({id: 'file_1',isFolder: false,isPage: false,libraryId: 'kb_1',+ openInPanel: true,});await act(async () => {result.current();});+ await flushPanelOpenDelay();- expect(getTabRouter(TAB_ID)!.state.location.search).toBe('?view=grid&file=file_1');+ // A plain click is an in-context preview: it must not write `?file=`,+ // which doubles as the fullscreen deep-link on restore.+ expect(getTabRouter(TAB_ID)!.state.location.search).toBe('?view=grid');expect(screen.getByTestId('shell-search').textContent).toBe('');+ expect(useResourceManagerStore.getState().detailPanelId).toBe('file_1');+ expect(useResourceManagerStore.getState().detailPanelIsPage).toBe(false);+ });++ it('waits out the double-click window before expanding a closed panel', async () => {+ const { result } = renderFileClick({+ id: 'file_1',+ isFolder: false,+ isPage: false,+ libraryId: 'kb_1',+ openInPanel: true,+ });++ await act(async () => {+ result.current();+ });++ // Expanding the panel reflows the explorer, so it must not happen between+ // the two clicks of a double click.+ expect(useResourceManagerStore.getState().detailPanelId).toBeUndefined();++ await flushPanelOpenDelay();++ expect(useResourceManagerStore.getState().detailPanelId).toBe('file_1');+ });++ it('switches an already open panel immediately', async () => {+ useResourceManagerStore.setState({ detailPanelId: 'file_1' });+ const { result } = renderFileClick({+ id: 'file_2',+ isFolder: false,+ isPage: false,+ libraryId: 'kb_1',+ openInPanel: true,+ });++ await act(async () => {+ result.current();+ });++ expect(useResourceManagerStore.getState().detailPanelId).toBe('file_2');+ });++ it('never opens the panel when the click turns into a double click', async () => {+ const { result: clickResult } = renderFileClick({+ id: 'file_1',+ isFolder: false,+ isPage: false,+ libraryId: 'kb_1',+ openInPanel: true,+ });+ const { result: doubleClickResult } = renderHook(+ () => useFileItemDoubleClick({ id: 'file_1', isPage: false }),+ { wrapper: shellWrapper },+ );++ await act(async () => {+ clickResult.current();+ clickResult.current();+ doubleClickResult.current();+ });+ await flushPanelOpenDelay();++ expect(useResourceManagerStore.getState().mode).toBe('editor');+ expect(useResourceManagerStore.getState().detailPanelId).toBeUndefined();+ });++ it('opens a page in the inline detail panel instead of the page editor', async () => {+ const { result } = renderFileClick({+ id: 'page_1',+ isFolder: false,+ isPage: true,+ libraryId: 'kb_1',+ openInPanel: true,+ });++ await act(async () => {+ result.current();+ });+ await flushPanelOpenDelay();++ expect(getTabRouter(TAB_ID)!.state.location.search).toBe('?view=grid');+ expect(useResourceManagerStore.getState().mode).toBe('explorer');+ expect(useResourceManagerStore.getState().detailPanelId).toBe('page_1');+ expect(useResourceManagerStore.getState().detailPanelIsPage).toBe(true);+ });++ it('opens the page editor on double click of a page', async () => {+ const { result } = renderHook(() => useFileItemDoubleClick({ id: 'page_1', isPage: true }), {+ wrapper: shellWrapper,+ });++ await act(async () => {+ result.current();+ });++ expect(getTabRouter(TAB_ID)!.state.location.search).toBe('?view=grid&file=page_1');+ expect(useResourceManagerStore.getState().mode).toBe('page');+ expect(useResourceManagerStore.getState().detailPanelId).toBeUndefined();+ });++ it('keeps the sidebar tree click opening the fullscreen file editor', async () => {+ const { result } = renderFileClick({+ id: 'file_2',+ isFolder: false,+ isPage: false,+ libraryId: 'kb_1',+ });++ await act(async () => {+ result.current();+ });++ expect(getTabRouter(TAB_ID)!.state.location.search).toBe('?view=grid&file=file_2');+ expect(useResourceManagerStore.getState().mode).toBe('editor');+ expect(useResourceManagerStore.getState().detailPanelId).toBeUndefined();+ });++ it('fullscreen editor on double click writes ?file= to the tab router', async () => {+ const { result } = renderHook(() => useFileItemDoubleClick({ id: 'file_1', isPage: false }), {+ wrapper: shellWrapper,+ });++ await act(async () => {+ result.current();+ });++ expect(getTabRouter(TAB_ID)!.state.location.search).toBe('?view=grid&file=file_1');+ expect(useResourceManagerStore.getState().mode).toBe('editor');+ expect(useResourceManagerStore.getState().detailPanelId).toBeUndefined();});it('preserves the tab url view preferences when selecting a page', async () => {diff --git a/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.ts b/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.tsindex ecfbaa02082..24eb5396c37 100644--- a/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.ts+++ b/src/features/ResourceManager/components/Explorer/hooks/useFileItemClick.ts@@ -10,9 +10,32 @@ export interface UseFileItemClickOptions {isPage: boolean;libraryId?: string | null;onOpen?: (id: string) => void;+ /**+ * Explorer rows (list / masonry) preview files and pages in the inline right+ * detail panel. The library sidebar tree is navigation and also stays mounted+ * where no explorer (and so no panel) exists, e.g. the Permissions page, so it+ * keeps opening the fullscreen editor.+ */+ openInPanel?: boolean;slug?: string | null;}+/**+ * How long a first click waits before expanding a closed detail panel. Expanding+ * the panel narrows the explorer (the masonry drops columns), which can move the+ * clicked card before a second click lands and swallow the double click.+ */+export const DETAIL_PANEL_OPEN_DELAY_MS = 250;++let pendingPanelOpen: ReturnType<typeof setTimeout> | undefined;++const cancelPendingPanelOpen = () => {+ if (pendingPanelOpen === undefined) return;++ clearTimeout(pendingPanelOpen);+ pendingPanelOpen = undefined;+};+/*** Shared hook for handling file item click across different view modes (list/masonry)*/@@ -23,6 +46,7 @@ export const useFileItemClick = ({isFolder,isPage,onOpen,+ openInPanel = false,}: UseFileItemClickOptions) => {const navigate = useWorkspaceAwareNavigate();// Read/write the URL through the active-tab facade rather than@@ -31,6 +55,7 @@ export const useFileItemClick = ({const { pathname, search } = useActiveLocation();const setMode = useResourceManagerStore((s) => s.setMode);const setCurrentViewItemId = useResourceManagerStore((s) => s.setCurrentViewItemId);+ const openDetailPanel = useResourceManagerStore((s) => s.openDetailPanel);const handleClick = useCallback(() => {const selectFile = () => {@@ -63,21 +88,37 @@ export const useFileItemClick = ({const basePath = `/resource/library/${libraryId}/${folderSlug}`;navigate(queryString ? `${basePath}?${queryString}` : basePath);}- } else if (isPage) {- // Switch to page view mode- setCurrentViewItemId(id);- setMode('page');- // Update URL query parameter for shareable links- selectFile();- } else {- // Set mode to editor for regular files- setCurrentViewItemId(id);- setMode('editor');- // Update URL query parameter for shareable links- selectFile();- // Call onOpen if provided for backwards compatibility- onOpen?.(id);+ return;}++ if (openInPanel) {+ // A plain click is a "look at this" gesture — the promise of the explorer+ // is to keep the working list visible. Fullscreen focus stays available as+ // the explicit double click (see `useFileItemDoubleClick`).+ const open = () => {+ openDetailPanel(id, isPage);+ onOpen?.(id);+ };++ cancelPendingPanelOpen();+ // Switching an already open panel keeps the layout, so it can be instant.+ if (useResourceManagerStore.getState().detailPanelId) {+ open();+ return;+ }++ pendingPanelOpen = setTimeout(() => {+ pendingPanelOpen = undefined;+ open();+ }, DETAIL_PANEL_OPEN_DELAY_MS);+ return;+ }++ setCurrentViewItemId(id);+ setMode(isPage ? 'page' : 'editor');+ // Update URL query parameter for shareable links+ selectFile();+ onOpen?.(id);}, [isFolder,slug,@@ -85,12 +126,39 @@ export const useFileItemClick = ({libraryId,isPage,navigate,+ openInPanel,pathname,search,setMode,setCurrentViewItemId,+ openDetailPanel,onOpen,]);return handleClick;};++/**+ * Double click = the committed "open this item" gesture: leave the list into+ * the fullscreen page editor or file editor. Keeps the `?file=` deep-link write+ * so a restored tab still lands on this item.+ */+export const useFileItemDoubleClick = ({ id, isPage }: { id: string; isPage: boolean }) => {+ const setMode = useResourceManagerStore((s) => s.setMode);+ const setCurrentViewItemId = useResourceManagerStore((s) => s.setCurrentViewItemId);+ const closeDetailPanel = useResourceManagerStore((s) => s.closeDetailPanel);+ const { search } = useActiveLocation();+ const navigate = useWorkspaceAwareNavigate();++ return useCallback(() => {+ // Both clicks of the double click scheduled a panel open; drop it.+ cancelPendingPanelOpen();+ closeDetailPanel();+ setCurrentViewItemId(id);+ setMode(isPage ? 'page' : 'editor');++ const newParams = new URLSearchParams(search);+ newParams.set('file', id);+ navigate({ search: `?${newParams.toString()}` }, { replace: true });+ }, [closeDetailPanel, id, isPage, setCurrentViewItemId, setMode, navigate, search]);+};diff --git a/src/features/ResourceManager/components/Explorer/index.tsx b/src/features/ResourceManager/components/Explorer/index.tsxindex c87c75ec809..5790f7d9410 100644--- a/src/features/ResourceManager/components/Explorer/index.tsx+++ b/src/features/ResourceManager/components/Explorer/index.tsx@@ -16,6 +16,7 @@ import { useFetchResources, useResourceStore } from '@/store/file/slices/resourcimport { KnowledgeBaseListProvider } from '../KnowledgeBaseListProvider';import EmptyPlaceholder from './EmptyPlaceholder';+import FileDetailPanel from './FileDetailPanel';import Header from './Header';import { useResetSelectionOnQueryChange } from './hooks/useResetSelectionOnQueryChange';import ListView from './ListView';@@ -125,43 +126,50 @@ const ResourceExplorer = memo(() => {searchQuery,});+ // Inline split-screen dock: rendered next to the list so a file click can+ // show its detail without leaving the surface.+ const detailPanelMount = useMemo(() => <FileDetailPanel />, []);+const showEmptyStatus = !isLoading && !isValidating && data?.length === 0;return (<KnowledgeBaseListProvider><Flexbox height={'100%'}><Header />- <div style={{ flex: 1, overflow: 'hidden', position: 'relative' }}>- {/*- AsyncBoundary gates error → empty → data. `isLoading` stays false here- because the list/masonry views own their own skeletons (loading is a- content swap inside them, not a full relayout), so the boundary only- arbitrates the failed-vs-empty-vs-data precedence the call site got wrong.- */}- <AsyncBoundary- data={data}- empty={<EmptyPlaceholder />}- error={error}- errorVariant={'block'}- isEmpty={showEmptyStatus}- onRetry={() => mutate()}- >- {viewMode === 'list' ? (- <ListView- isLoading={isLoading}- isValidating={isValidating}- queryParams={queryParams}- />- ) : (- <MasonryView- isLoading={isLoading}- isValidating={isValidating}- queryParams={queryParams}- />- )}- </AsyncBoundary>- <SearchResultsOverlay />- </div>+ <Flexbox horizontal flex={1} style={{ minHeight: 0, overflow: 'hidden' }}>+ <div style={{ flex: 1, overflow: 'hidden', position: 'relative', minWidth: 0 }}>+ {/*+ AsyncBoundary gates error → empty → data. `isLoading` stays false here+ because the list/masonry views own their own skeletons (loading is a+ content swap inside them, not a full relayout), so the boundary only+ arbitrates the failed-vs-empty-vs-data precedence the call site got wrong.+ */}+ <AsyncBoundary+ data={data}+ empty={<EmptyPlaceholder />}+ error={error}+ errorVariant={'block'}+ isEmpty={showEmptyStatus}+ onRetry={() => mutate()}+ >+ {viewMode === 'list' ? (+ <ListView+ isLoading={isLoading}+ isValidating={isValidating}+ queryParams={queryParams}+ />+ ) : (+ <MasonryView+ isLoading={isLoading}+ isValidating={isValidating}+ queryParams={queryParams}+ />+ )}+ </AsyncBoundary>+ <SearchResultsOverlay />+ </div>+ {detailPanelMount}+ </Flexbox></Flexbox></KnowledgeBaseListProvider>);diff --git a/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.test.ts b/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.test.tsindex 72f828a833c..083f4a6ee26 100644--- a/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.test.ts+++ b/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.test.ts@@ -1,6 +1,9 @@import { describe, expect, it } from 'vitest';-import { resolveMasonryColumnCount } from './useMasonryColumnCount';+import {+ resolveMasonryColumnCount,+ resolveMasonryColumnCountByWidth,+} from './useMasonryColumnCount';describe('resolveMasonryColumnCount', () => {it('maps viewport width to the masonry column count without a default guess', () => {@@ -11,3 +14,21 @@ describe('resolveMasonryColumnCount', () => {expect(resolveMasonryColumnCount(1920)).toBe(5);});});++describe('resolveMasonryColumnCountByWidth', () => {+ it('drops to two columns when the detail panel squeezes the grid', () => {+ // 1280px window with the 480px panel open leaves ~462px of card area.+ expect(resolveMasonryColumnCountByWidth(462)).toBe(2);+ });++ it('never goes below two columns or above five', () => {+ expect(resolveMasonryColumnCountByWidth(120)).toBe(2);+ expect(resolveMasonryColumnCountByWidth(2400)).toBe(5);+ });++ it('keeps cards at least 200px wide as the container grows', () => {+ expect(resolveMasonryColumnCountByWidth(696)).toBe(3);+ expect(resolveMasonryColumnCountByWidth(942)).toBe(4);+ expect(resolveMasonryColumnCountByWidth(1100)).toBe(5);+ });+});diff --git a/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.ts b/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.tsindex dbd0b7f2638..2ad782ffceb 100644--- a/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.ts+++ b/src/features/ResourceManager/components/Explorer/useMasonryColumnCount.ts@@ -7,6 +7,26 @@ export const resolveMasonryColumnCount = (width: number) => {return 5;};+const MASONRY_GAP = 16;+const MASONRY_MIN_CARD_WIDTH = 200;+const MASONRY_MIN_COLUMNS = 2;+const MASONRY_MAX_COLUMNS = 5;++/**+ * Column count for the masonry's own content width. The grid shares its row+ * with the detail panel, so the viewport says nothing about how much room the+ * cards really have: fit as many columns as keep each card at least+ * `MASONRY_MIN_CARD_WIDTH` wide, never fewer than two.+ */+export const resolveMasonryColumnCountByWidth = (contentWidth: number) =>+ Math.min(+ MASONRY_MAX_COLUMNS,+ Math.max(+ MASONRY_MIN_COLUMNS,+ Math.floor((contentWidth + MASONRY_GAP) / (MASONRY_MIN_CARD_WIDTH + MASONRY_GAP)),+ ),+ );+// Resolved synchronously on the first render: a default column count that is// corrected in an effect re-lays out every masonry card one frame later.export const useMasonryColumnCount = () => {@@ -24,3 +44,36 @@ export const useMasonryColumnCount = () => {return columnCount;};++const getContentWidth = (element: HTMLElement) => {+ const style = window.getComputedStyle(element);+ return (+ element.clientWidth -+ Number.parseFloat(style.paddingInlineStart || '0') -+ Number.parseFloat(style.paddingInlineEnd || '0')+ );+};++/**+ * Masonry column count that follows the container (e.g. when the detail panel+ * opens beside the grid). Falls back to the viewport rule until the container+ * is mounted.+ */+export const useContainerMasonryColumnCount = (container: HTMLElement | null) => {+ const viewportColumnCount = useMasonryColumnCount();+ const [containerColumnCount, setContainerColumnCount] = useState<number>();++ useLayoutEffect(() => {+ if (!container) return;++ const update = () =>+ setContainerColumnCount(resolveMasonryColumnCountByWidth(getContentWidth(container)));++ update();+ const observer = new ResizeObserver(update);+ observer.observe(container);+ return () => observer.disconnect();+ }, [container]);++ return containerColumnCount ?? viewportColumnCount;+};diff --git a/src/features/ResourceManager/store/action.ts b/src/features/ResourceManager/store/action.tsindex 4ff3ab0f9df..7aa84e44c15 100644--- a/src/features/ResourceManager/store/action.ts+++ b/src/features/ResourceManager/store/action.ts@@ -195,6 +195,14 @@ export class ResourceManagerStoreActionImpl {this.#set({ currentViewItemId });};+ closeDetailPanel = (): void => {+ this.#set({ detailPanelId: undefined, detailPanelIsPage: false });+ };++ openDetailPanel = (detailPanelId: string, isPage = false): void => {+ this.#set({ detailPanelId, detailPanelIsPage: isPage });+ };+setLibraryId = (libraryId?: string): void => {if (this.#get().libraryId === libraryId) return;// A sidebar search is scoped to one library; carrying it over to the nextdiff --git a/src/features/ResourceManager/store/initialState.ts b/src/features/ResourceManager/store/initialState.tsindex 9c72cdd320c..712a8f3deb0 100644--- a/src/features/ResourceManager/store/initialState.ts+++ b/src/features/ResourceManager/store/initialState.ts@@ -35,6 +35,18 @@ export interface State {* Current view item ID (document ID or file ID)*/currentViewItemId?: string;+ /**+ * Resource shown in the explorer's inline right detail panel (list click).+ * Kept apart from `currentViewItemId`/`mode`: the panel is an in-context+ * preview dock, not a view mode, so opening it must not kick the user out+ * of the list or fight the `?file=` deep-link restoration.+ */+ detailPanelId?: string;+ /**+ * Whether the detail panel item is a page (文稿). Pages have no file URL, so+ * the panel previews their document content instead of the file viewer.+ */+ detailPanelIsPage: boolean;/*** Current library ID*/@@ -110,6 +122,8 @@ export interface State {export const initialState: State = {category: FilesTabs.All,currentViewItemId: undefined,+ detailPanelId: undefined,+ detailPanelIsPage: false,libraryId: undefined,librarySearchQuery: '',// Personal mode keeps the historical neutral value; workspace mode hydrates