0.1.08 文件树视图修复

This commit is contained in:
liaibo
2026-01-08 18:17:07 +08:00
parent 9af8b9e489
commit e7350c87c6
2 changed files with 21 additions and 11 deletions
@@ -42,6 +42,7 @@ import { PrivateTree } from "@/components/sidebar/private-tree";
import { buildSidebarSectionsFromTree, flattenDocumentTree } from "@/lib/sidebar-tree";
import { supabaseBrowser } from "@/lib/supabase/client";
import { useSearchPaletteStore } from "@/store/search-palette";
import { useEditorBridgeStore } from "@/store/editor-bridge";
import { FileTree } from "@/components/sidebar/file-tree";
import { buildVisibleRows } from "@/lib/file-tree/rows";
import type { FileTreeSelectionState } from "@/lib/file-tree/selection";
@@ -100,6 +101,7 @@ export function Sidebar({ initialData }: SidebarProps) {
const segments = useSelectedLayoutSegments();
const router = useRouter();
const activeId = segments?.[1] ?? "";
const editorBridge = useEditorBridgeStore((state) => state.bridge);
const [tree, setTree] = useState<DocumentNode[]>(() => buildDocumentTree(sidebarData.documents));
const [filter, setFilter] = useState("");
@@ -979,6 +981,10 @@ export function Sidebar({ initialData }: SidebarProps) {
const payload = (await resp.json()) as { asset?: MediaAsset };
if (payload.asset?.id) {
emitAssetsChanged(inferredTargetDocId, payload.asset);
// 拖拽文件进文件树:如果落点就是当前打开的页面,则把文件也插入到主编辑区
if (inferredTargetDocId === activeId) {
editorBridge?.insertMediaAsset?.(payload.asset);
}
} else {
errors.push(`${file.name}: 返回数据缺少 asset`);
}
@@ -1003,6 +1009,7 @@ export function Sidebar({ initialData }: SidebarProps) {
},
[
activeId,
editorBridge,
fileTreeRowById,
fileTreeSelection.focusedRowId,
sidebarData.activeWorkspaceId,
@@ -1326,7 +1333,7 @@ export function Sidebar({ initialData }: SidebarProps) {
}, [workspaceMenuOpen]);
const sidebarBody = (
<div className="flex h-full flex-col">
<div className="flex h-full min-w-0 flex-col">
<div className="border-b border-[#f1f1f1] p-3">
<div className="text-xs text-gray-400"></div>
<div className="mt-1 flex items-center justify-between">
@@ -1387,8 +1394,8 @@ export function Sidebar({ initialData }: SidebarProps) {
))}
</div>
<div className="flex-1 overflow-hidden">
<div className="flex h-full flex-col overflow-y-auto">
<div className="flex-1 min-w-0 overflow-hidden">
<div className="flex h-full min-w-0 flex-col overflow-y-auto overflow-x-hidden">
<div className="border-b border-[#f1f1f1] p-3">
<div className="flex items-center gap-2 text-sm text-gray-500">
<Library className="h-4 w-4" />
@@ -1491,7 +1498,7 @@ export function Sidebar({ initialData }: SidebarProps) {
<div
ref={fileTreeContainerRef}
data-testid="file-tree-container"
className="h-full rounded-md border border-[#eff2f6] bg-white"
className="h-full w-full min-w-0 overflow-x-hidden rounded-md border border-[#eff2f6] bg-white"
>
<FileTree
rows={fileTreeRows}
@@ -1536,8 +1543,10 @@ export function Sidebar({ initialData }: SidebarProps) {
return (
<>
<aside className="hidden h-full md:flex" style={{ width }}>
<div className="flex h-full flex-1 flex-col border-r border-[#e9edf5] bg-white">{sidebarBody}</div>
<aside className="hidden h-full min-w-0 overflow-hidden md:flex" style={{ width }}>
<div className="flex h-full min-w-0 flex-1 flex-col overflow-hidden border-r border-[#e9edf5] bg-white">
{sidebarBody}
</div>
<div className="w-1 cursor-col-resize bg-transparent" onMouseDown={handleResizeStart} />
</aside>
<Drawer open={open} onOpenChange={setOpen}>