Files
orca/src/shared/markdown-toc-panel-width.ts
T
Jinjing 996284241d Implement resizable Markdown table of contents panel (#5444)
* Implement resizable Markdown table of contents panel

Introduce resizable behavior to the Markdown table of contents panel,
allowing users to adjust its width via a draggable handle.

- Persist the custom panel width in the UI state and main process store.
- Clamp the width to a safe range (200px to 600px) based on layout space.
- Ensure the remaining editor workspace does not shrink below 320px
  by computing constraints dynamically against the parent container width.

* Clone process env without undefined values for Windows preflight

- Filter out undefined values when cloning process.env to prevent
  potential serialization or typing issues.
- Update buildLocalPreflightEnv return type to Record<string, string>.
2026-06-15 19:59:44 -07:00

33 lines
1010 B
TypeScript

export const MARKDOWN_TOC_PANEL_MIN_WIDTH = 200
export const MARKDOWN_TOC_PANEL_DEFAULT_WIDTH = 240
export const MARKDOWN_TOC_PANEL_MIN_EDITOR_WIDTH = 320
export const MARKDOWN_TOC_PANEL_MAX_WIDTH = 600
export function computeMaxMarkdownTocPanelWidth(containerWidth: number): number {
if (!Number.isFinite(containerWidth) || containerWidth <= 0) {
return MARKDOWN_TOC_PANEL_MAX_WIDTH
}
return Math.min(
MARKDOWN_TOC_PANEL_MAX_WIDTH,
Math.max(MARKDOWN_TOC_PANEL_MIN_WIDTH, containerWidth - MARKDOWN_TOC_PANEL_MIN_EDITOR_WIDTH)
)
}
export function clampMarkdownTocPanelWidth(
width: unknown,
containerWidth?: number,
fallback = MARKDOWN_TOC_PANEL_DEFAULT_WIDTH
): number {
if (typeof width !== 'number' || !Number.isFinite(width)) {
return fallback
}
const maxWidth =
containerWidth !== undefined
? computeMaxMarkdownTocPanelWidth(containerWidth)
: MARKDOWN_TOC_PANEL_MAX_WIDTH
return Math.min(maxWidth, Math.max(MARKDOWN_TOC_PANEL_MIN_WIDTH, width))
}