UNPKG

@gordon1210/depup

Version:

a dependency upgrade tool for node projects

49 lines (48 loc) 3.16 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Text } from "ink"; import Spinner from "ink-spinner"; import path from "path"; import { Fragment, useEffect, useState } from "react"; import { truncateText } from "../utils.js"; import { ScrollingText } from "./ScrollingText.js"; const TARGET_HEIGHT = 26; export function SideNav({ groups, activeTab, visibleCount, loading, }) { const [visible, setVisible] = useState(true); useEffect(() => { if (!loading) { return; } const timer = setInterval(() => { setVisible((v) => !v); }, 1250); return () => clearInterval(timer); }, [loading]); const start = visibleCount ? Math.min(Math.max(0, activeTab - Math.floor(visibleCount / 2)), Math.max(0, groups.length - visibleCount)) : 0; const visibleGroups = visibleCount ? groups.slice(start, start + visibleCount) : groups; return (_jsxs(Box, { flexDirection: "column", marginRight: 3, children: [loading ? (_jsxs(Text, { children: [_jsx(Text, { color: "green", children: _jsx(Spinner, { type: "dots" }) }), " ", visible && "Scanning"] })) : (_jsx(Text, { children: "Package" })), visibleGroups.map((group, i) => { const actualIndex = start + i; if (group.path === "__SHARED__") { return (_jsxs(Fragment, { children: [_jsx(Text, { children: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" }), _jsx(Text, { color: actualIndex === activeTab ? "green" : undefined, bold: actualIndex === activeTab, children: "shared-packages" })] }, "__shared__")); } const selected = group.packages.filter((p) => p.selected).length; return (_jsxs(Text, { color: actualIndex === activeTab ? "green" : undefined, bold: actualIndex === activeTab, children: [actualIndex === activeTab ? (_jsx(ScrollingText, { text: path.basename(group.path), maxLength: 13, isActive: actualIndex === activeTab, color: actualIndex === activeTab ? "green" : undefined, bold: actualIndex === activeTab })) : (truncateText(path.basename(group.path), 13)), selected > 0 ? ` (${selected})` : " "] }, group.path)); }), (() => { // Calculate current content height // Count loading indicator if present const loadingLines = loading ? 1 : 0; // Count shared package divider as an extra line const sharedDividerLines = visibleGroups.some((g) => g.path === "__SHARED__") ? 1 : 0; // Total content lines including groups and special elements const contentLines = visibleGroups.length + loadingLines + sharedDividerLines; // Calculate how many placeholder lines we need const placeholderCount = Math.max(0, TARGET_HEIGHT - contentLines); // Return array of placeholder lines return Array.from({ length: placeholderCount }).map((_, i) => (_jsx(Text, { children: " " }, `placeholder-${i}`))); })()] })); }