diff --git a/src/client/SideCardSection.tsx b/src/client/SideCardSection.tsx index c9503acc..844159d6 100644 --- a/src/client/SideCardSection.tsx +++ b/src/client/SideCardSection.tsx @@ -65,6 +65,7 @@ import { CLUE_PREFS_ID, CLUE_WINDOW_SURFACE_SETTING, type SidebarPrefs } from '. import { api } from './api.ts' import { parsePrefs, syncClueWindowSurface } from './prefs.ts' import { AddPluginModal, type PluginKind } from './add-plugin-modal.tsx' +import { CollapsedPanelsSetting } from './collapsed-panels-setting.tsx' import { t } from './locales.ts' import type { SidebarStore } from './state.ts' import { mergeGuideEntries, type NativeGuideCatalog, type NativeGuideEntry } from './native/guide-catalog.ts' @@ -1890,6 +1891,12 @@ export function SideCardSection(props: SideCardSectionInjected & Partial

{t('settingsGeneralTitle')}

+ {/* 侧栏入口折叠: which left-sidebar entries stay out of the way. + The host folds an entry into its More menu when the entry's + panel id is in the host's pin storage; this block is where the + user picks that set. */} + + typeof id === 'string') : [] + } catch { + return [] + } +} + +/** + * Write the folded set and reload, so the host's pin store picks it up. + * + * @param ids - the panel ids to fold away. + */ +function writeUnpinned(ids: string[]): void { + if (typeof localStorage === 'undefined') return + try { + localStorage.setItem(PIN_KEY, JSON.stringify({ unpinned: ids })) + localStorage.setItem(MARK_KEY, CUSTOM_MARK) + location.reload() + } catch { + // A storage that refuses the write keeps the current layout. + } +} + +/** + * The setting block: one checkbox per known entry plus an apply button. + * + * @returns the setting rows. + */ +export function CollapsedPanelsSetting(): React.ReactNode { + const [selected, setSelected] = useState([]) + + useEffect(() => { + setSelected(readUnpinned()) + }, []) + + function toggle(id: string, next: boolean): void { + setSelected(current => (next ? [...current.filter(entry => entry !== id), id] : current.filter(entry => entry !== id))) + } + + return ( +
+
{t('settingsCollapsedPanelsTitle')}
+ {CANDIDATE_PANELS.map(panel => ( + + toggle(panel.id, event.currentTarget.checked)} + /> + + ))} + +
+ ) +} diff --git a/src/client/index.tsx b/src/client/index.tsx index 808b5c0e..963b7ac1 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -107,6 +107,9 @@ function ensureDefaultCollapsedPanels(): void { if (typeof localStorage === 'undefined') return try { const mark = localStorage.getItem(PANEL_PIN_MARK_KEY) + // `custom` = the user manages the folded set in the settings block; the + // default set must not creep back in. + if (mark === 'custom') return if (mark === DEFAULT_COLLAPSED_PANELS.join(',')) return const raw = localStorage.getItem(PANEL_PIN_KEY) const current = raw === null ? [] : (JSON.parse(raw)?.unpinned ?? []) diff --git a/src/client/locales.ts b/src/client/locales.ts index 735764a1..3eb5d6fc 100644 --- a/src/client/locales.ts +++ b/src/client/locales.ts @@ -506,6 +506,9 @@ export const zh = { settingsMobileTreeTitle: '窄屏时任务页默认树状图', settingsMobileTreeDesc: '手机 / 窄屏下任务页默认用经典树,而不是工作流图;页内切换仍可临时改成图', settingsGeneralTitle: '常规', + settingsCollapsedPanelsTitle: '折叠的侧栏入口', + settingsCollapsedPanelsDesc: '勾选后该入口从左侧栏收进「更多」菜单,随时可在那里钉回。', + settingsCollapsedPanelsApply: '应用并刷新', settingsPopup: '功能设置', settingsViewerCatchAll: '兜底:任意文件', viewerMarkdown: 'Markdown', @@ -1779,6 +1782,9 @@ export const en: Record = { settingsMobileTreeTitle: 'Default the Tasks page to the tree', settingsMobileTreeDesc: "On a phone / narrow viewport the Tasks page opens as the classic tree instead of the workflow graph; the in-page toggle still switches it ad hoc", settingsGeneralTitle: 'General', + settingsCollapsedPanelsTitle: 'Folded sidebar entries', + settingsCollapsedPanelsDesc: 'Checked entries move out of the left sidebar into the More menu; pin them back from there.', + settingsCollapsedPanelsApply: 'Apply and refresh', settingsPopup: 'Feature settings', settingsViewerCatchAll: 'Catch-all: any file', viewerMarkdown: 'Markdown',