0.3.4 小图标功能增加

This commit is contained in:
liaibo
2026-01-22 18:53:20 +08:00
parent 71de56850b
commit 25923f308c
25 changed files with 2781 additions and 141 deletions
+7 -21
View File
@@ -5,14 +5,11 @@ import type { SidebarSectionId } from "@/components/sidebar/types";
interface SidebarState {
open: boolean;
width: number;
sectionsTrayOpen: boolean;
collapsedSections: Record<SidebarSectionId, boolean>;
trashConfirm: boolean;
viewMode: "section" | "filesystem";
setOpen: (open: boolean) => void;
setWidth: (width: number) => void;
setSectionsTrayOpen: (open: boolean) => void;
toggleSectionsTray: () => void;
toggleSection: (section: SidebarSectionId) => void;
setSectionCollapsed: (section: SidebarSectionId, collapsed: boolean) => void;
setTrashConfirm: (value: boolean) => void;
@@ -21,11 +18,11 @@ interface SidebarState {
}
const sectionDefaults: Record<SidebarSectionId, boolean> = {
starred: false,
public: false,
shared: false,
starred: true,
public: true,
shared: true,
private: false,
templates: false,
templates: true,
};
export const useSidebarStore = create<SidebarState>()(
@@ -33,14 +30,11 @@ export const useSidebarStore = create<SidebarState>()(
(set) => ({
open: false,
width: 280,
sectionsTrayOpen: false,
collapsedSections: { ...sectionDefaults },
trashConfirm: true,
viewMode: "section",
setOpen: (open) => set({ open }),
setWidth: (width) => set({ width }),
setSectionsTrayOpen: (open) => set({ sectionsTrayOpen: open }),
toggleSectionsTray: () => set((state) => ({ sectionsTrayOpen: !state.sectionsTrayOpen })),
toggleSection: (section) =>
set((state) => ({
collapsedSections: {
@@ -61,39 +55,31 @@ export const useSidebarStore = create<SidebarState>()(
}),
{
name: "sidebar-ui",
version: 2,
version: 4,
migrate: (persistedState, version) => {
const state = persistedState as
| Partial<
Pick<
SidebarState,
"width" | "collapsedSections" | "trashConfirm" | "viewMode" | "sectionsTrayOpen"
"width" | "collapsedSections" | "trashConfirm" | "viewMode"
>
>
| undefined;
if (!state) return state;
if (version >= 2) return state;
if (version >= 4) return state;
const nextCollapsedSections = {
...sectionDefaults,
...(state.collapsedSections ?? {}),
};
// 迁移到「分区入口可折叠」后,让分区默认展开,折叠由入口开关控制。
nextCollapsedSections.starred = false;
nextCollapsedSections.public = false;
nextCollapsedSections.shared = false;
nextCollapsedSections.templates = false;
return {
...state,
sectionsTrayOpen: false,
collapsedSections: nextCollapsedSections,
};
},
partialize: (state) => ({
width: state.width,
sectionsTrayOpen: state.sectionsTrayOpen,
collapsedSections: state.collapsedSections,
trashConfirm: state.trashConfirm,
viewMode: state.viewMode,