35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
export const WORKSPACE_PANEL_WIDTH_STORAGE_KEY =
|
|
"libtv:workspacePanelDrawer:width";
|
|
|
|
export const WORKSPACE_PANEL_MIN_WIDTH = 240;
|
|
export const WORKSPACE_PANEL_MAX_WIDTH = 380;
|
|
export const WORKSPACE_PANEL_VIEWPORT_GUTTER = 48;
|
|
|
|
export function clampWorkspacePanelWidth(
|
|
requestedWidth: number,
|
|
viewportWidth: number,
|
|
) {
|
|
const availableWidth = Math.min(
|
|
WORKSPACE_PANEL_MAX_WIDTH,
|
|
Math.max(0, viewportWidth - WORKSPACE_PANEL_VIEWPORT_GUTTER),
|
|
);
|
|
const minimumWidth = Math.min(WORKSPACE_PANEL_MIN_WIDTH, availableWidth);
|
|
const roundedWidth = Number.isFinite(requestedWidth)
|
|
? Math.round(requestedWidth)
|
|
: minimumWidth;
|
|
|
|
return Math.max(minimumWidth, Math.min(availableWidth, roundedWidth));
|
|
}
|
|
|
|
export function getInitialWorkspacePanelWidth(
|
|
viewportWidth: number,
|
|
persistedWidth?: string | number | null,
|
|
) {
|
|
const parsedWidth = Number(persistedWidth ?? "");
|
|
if (Number.isFinite(parsedWidth) && parsedWidth > 0) {
|
|
return clampWorkspacePanelWidth(parsedWidth, viewportWidth);
|
|
}
|
|
|
|
return clampWorkspacePanelWidth(viewportWidth > 1520 ? 280 : 240, viewportWidth);
|
|
}
|