mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-09 18:32:52 +00:00
7637091e84
* feat(ui): add glassmorphism design tokens and utility classes Introduce glass design system foundation: translucent oklch color variables for both light and dark themes, glass/glass-border/glass-highlight tokens, semantic status colors (success/warning/info), .glass and .glass-strong utility classes with backdrop-filter, reduced shadow values, and standardized spring animation presets in lib/motion.ts. * feat(ui): apply glass treatment to core components Update card, dialog, input, button, popover, sheet, tooltip, dropdown-menu, context-menu, select, alert-dialog, and tabs components with glassmorphism styling: translucent backgrounds via new CSS variables, backdrop-blur layers, glass-border luminous edges, and glass-highlight hover states. * refactor(settings): decompose Settings Modal into section components Extract 10 inline sections from the 1,987-line SettingsModal into dedicated files under components/settings/. Introduce section registry pattern replacing 14 conditional blocks. Add shared types, sidebar navigation grouping with separators, glass treatment on sidebar and nav buttons, and responsive modal height. SettingsModal shell shrinks to ~380 lines. * refactor(ui): unify all tabs to animate-ui TabsHighlight with glass styling Migrate 4 tab instances (EditorLayout, FleetView, ResourcesView, NotificationsSection) from inconsistent patterns (manual layoutId, underline border-b-2, default fade) to the shared TabsHighlight primitive with glass-highlight indicator and springs.snappy transition. Standardize EditorLayout nav highlight spring config, apply glass-highlight to sidebar stack list hover/active states, and update mobile nav styling. * refactor(ui): migrate hardcoded colors to semantic CSS variables Replace hardcoded Tailwind color classes across ~19 component files with semantic CSS variable classes: emerald/green to success, orange/amber to warning, blue to info. Preserves brand/decorative colors (Crown amber, Admiral blue). Enables consistent theming of status indicators across the entire application. * refactor(ui): Linear dark precision aesthetic — solid surfaces, depth cues, text hierarchy Replace glassmorphism with Linear.app-inspired design: solid surface tokens (card #111111, sidebar #0d0d0d, root #0a0a0a), backdrop-blur restricted to floating overlays only (blur(10px) saturate(1.15)), desaturated teal accent, font-weight 500 everywhere, monochrome chart palette, and three depth cues: root ambient glow, luminous card top-edge, steep text brightness ramp. * refactor(ui): precision polish — fix muddy dark, snowblind light, add design anchors - Replace 34 hardcoded rgba values with theme-aware stat-* CSS tokens - Fix light theme: solid white cards, off-white background, readable text - Add card-border tokens with sharper directional lighting (top edge 2x) - Add chart-grid/chart-tick tokens for theme-aware axis rendering - Upgrade body glow: teal-tinted (dark), warm amber (light) - Terminal-inspired sidebar: monospaced UP/DN status codes, Geist Mono - Add tabular-nums to stat values to prevent layout jitter - Light mode cards get shadow-sm for depth against off-white background * refactor(ui): Linear materiality pass — ghosted nav, translucent sidebar, font unity - De-escalate Delete button from solid destructive to ghost with hover fill - Make sidebar translucent (80% opacity + backdrop-blur) so body glow bleeds through - Bump dark nav accent to 0.07 for ghosted backlit selection - Unify all terminal/editor fonts to Geist Mono (was JetBrains/Consolas mix) - Add Monaco editor fontFamily for YAML/env editing consistency - Add threshold-based color to Host RAM and Host Disk stat values (warn/crit) * refactor(ui): material simulation — inherent depth, layer separation, recessed terminal - Bump dark background 0.065→0.08, card surfaces 0.10→0.12 for 4% layer separation - Add card-bevel token (inset top shimmer) for permanent structural depth - Add button-inner-glow token for physical key feel on outline buttons - Recess terminal with inset shadow and dimmed label - Reduce action icon strokeWidth to 1.5 for refined industrial feel - Add teal LED backlight bar on active nav item via blur pseudo-element * fix(ui): parse usagePercent string to number for getValueColor usagePercent is typed as string in SystemStats but getValueColor expects number, causing TS2345 in CI builds.
243 lines
7.4 KiB
TypeScript
243 lines
7.4 KiB
TypeScript
import { useEffect, useRef, useState, useCallback } from 'react';
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from './ui/dialog';
|
|
import { Terminal as TerminalIcon } from 'lucide-react';
|
|
import { Terminal } from '@xterm/xterm';
|
|
import { FitAddon } from '@xterm/addon-fit';
|
|
import '@xterm/xterm/css/xterm.css';
|
|
|
|
type TerminalContainer = HTMLDivElement & { __resizeObserver?: ResizeObserver };
|
|
|
|
interface BashExecModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
containerId: string;
|
|
containerName: string;
|
|
}
|
|
|
|
export default function BashExecModal({ isOpen, onClose, containerId, containerName }: BashExecModalProps) {
|
|
const terminalRef = useRef<HTMLDivElement>(null);
|
|
const xtermRef = useRef<Terminal | null>(null);
|
|
const fitAddonRef = useRef<FitAddon | null>(null);
|
|
const wsRef = useRef<WebSocket | null>(null);
|
|
const initTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
const [isConnected, setIsConnected] = useState(false);
|
|
|
|
const cleanup = useCallback(() => {
|
|
if (initTimeoutRef.current) {
|
|
clearTimeout(initTimeoutRef.current);
|
|
initTimeoutRef.current = null;
|
|
}
|
|
if (wsRef.current) {
|
|
wsRef.current.close();
|
|
wsRef.current = null;
|
|
}
|
|
if (xtermRef.current) {
|
|
xtermRef.current.dispose();
|
|
xtermRef.current = null;
|
|
}
|
|
fitAddonRef.current = null;
|
|
setIsConnected(false);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!isOpen) {
|
|
cleanup();
|
|
return;
|
|
}
|
|
|
|
let attempts = 0;
|
|
const maxAttempts = 15; // up to 1.5 seconds
|
|
|
|
const checkAndInit = () => {
|
|
// If already initialized, stop.
|
|
if (xtermRef.current) return;
|
|
|
|
const container = terminalRef.current;
|
|
|
|
// If Radix Dialog Portal hasn't rendered the DOM node yet, poll.
|
|
if (!container) {
|
|
if (attempts++ < maxAttempts) {
|
|
initTimeoutRef.current = setTimeout(checkAndInit, 100);
|
|
} else {
|
|
console.error('BashExecModal: terminalRef never populated.');
|
|
}
|
|
return;
|
|
}
|
|
|
|
// DOM exists. Now verify it has actual layout size from CSS.
|
|
// During initial Radix zoom-in animation, it might be 0x0.
|
|
const rect = container.getBoundingClientRect();
|
|
if (rect.width === 0 || rect.height === 0) {
|
|
if (attempts++ < maxAttempts) {
|
|
initTimeoutRef.current = setTimeout(checkAndInit, 100);
|
|
} else {
|
|
console.warn('BashExecModal: terminal container has zero dimensions after 1.5s, forcing init anyway.');
|
|
initTerminal(container);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Node exists and has layout - safe to initialize xterm!
|
|
initTerminal(container);
|
|
};
|
|
|
|
// Start polling
|
|
initTimeoutRef.current = setTimeout(checkAndInit, 50);
|
|
|
|
function initTerminal(containerEl: HTMLDivElement) {
|
|
const term = new Terminal({
|
|
theme: {
|
|
background: '#1e1e1e',
|
|
foreground: '#d4d4d4',
|
|
cursor: '#ffffff',
|
|
cursorAccent: '#000000',
|
|
selectionBackground: 'rgba(255, 255, 255, 0.3)',
|
|
},
|
|
fontFamily: "'Geist Mono', monospace",
|
|
fontSize: 14,
|
|
cursorBlink: true,
|
|
});
|
|
|
|
const fitAddon = new FitAddon();
|
|
term.loadAddon(fitAddon);
|
|
term.open(containerEl);
|
|
|
|
xtermRef.current = term;
|
|
fitAddonRef.current = fitAddon;
|
|
|
|
// Fit after xterm has rendered its canvas
|
|
requestAnimationFrame(() => {
|
|
try {
|
|
fitAddon.fit();
|
|
} catch {
|
|
// Ignore fit errors during initial render
|
|
}
|
|
});
|
|
|
|
// Connect to WebSocket for bash exec
|
|
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const activeNodeId = localStorage.getItem('sencho-active-node') || '';
|
|
const ws = new WebSocket(`${wsProtocol}//${window.location.host}/ws${activeNodeId ? `?nodeId=${activeNodeId}` : ''}`);
|
|
wsRef.current = ws;
|
|
|
|
ws.onopen = () => {
|
|
ws.send(JSON.stringify({
|
|
action: 'execContainer',
|
|
containerId: containerId,
|
|
nodeId: localStorage.getItem('sencho-active-node') || undefined
|
|
}));
|
|
setIsConnected(true);
|
|
|
|
// Focus so user can type immediately
|
|
term.focus();
|
|
|
|
// Fit again now that everything is settled, then send dimensions
|
|
setTimeout(() => {
|
|
try {
|
|
fitAddon.fit();
|
|
} catch {
|
|
// Ignore
|
|
}
|
|
if (ws.readyState === WebSocket.OPEN && term.rows > 0 && term.cols > 0) {
|
|
ws.send(JSON.stringify({
|
|
type: 'resize',
|
|
rows: term.rows,
|
|
cols: term.cols,
|
|
}));
|
|
}
|
|
}, 100);
|
|
};
|
|
|
|
ws.onmessage = (event) => {
|
|
// Raw text from container → write directly to xterm
|
|
term.write(event.data);
|
|
};
|
|
|
|
ws.onerror = () => {
|
|
term.write('\r\n\x1b[31mConnection error\x1b[0m\r\n');
|
|
setIsConnected(false);
|
|
};
|
|
|
|
ws.onclose = () => {
|
|
term.write('\r\n\x1b[33mSession ended\x1b[0m\r\n');
|
|
setIsConnected(false);
|
|
};
|
|
|
|
// Handle user input - JSON up
|
|
term.onData((data) => {
|
|
if (ws.readyState === WebSocket.OPEN) {
|
|
ws.send(JSON.stringify({
|
|
type: 'input',
|
|
data: data,
|
|
}));
|
|
}
|
|
});
|
|
|
|
// ResizeObserver for modal/window resize events
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
if (!fitAddonRef.current || !wsRef.current) return;
|
|
try {
|
|
fitAddonRef.current.fit();
|
|
} catch {
|
|
return;
|
|
}
|
|
if (wsRef.current.readyState === WebSocket.OPEN && term.rows > 0 && term.cols > 0) {
|
|
wsRef.current.send(JSON.stringify({
|
|
type: 'resize',
|
|
rows: term.rows,
|
|
cols: term.cols,
|
|
}));
|
|
}
|
|
});
|
|
|
|
resizeObserver.observe(containerEl);
|
|
|
|
// Store observer cleanup on the container element for later
|
|
(containerEl as TerminalContainer).__resizeObserver = resizeObserver;
|
|
}
|
|
|
|
return () => {
|
|
// Clean up ResizeObserver
|
|
const el = terminalRef.current as TerminalContainer | null;
|
|
if (el?.__resizeObserver) {
|
|
el.__resizeObserver.disconnect();
|
|
delete el.__resizeObserver;
|
|
}
|
|
};
|
|
}, [isOpen, containerId, cleanup]);
|
|
|
|
const handleClose = () => {
|
|
cleanup();
|
|
onClose();
|
|
};
|
|
|
|
return (
|
|
<Dialog open={isOpen} onOpenChange={handleClose}>
|
|
<DialogContent className="max-w-4xl h-[600px] flex flex-col">
|
|
<DialogHeader>
|
|
<DialogTitle className="flex items-center gap-2">
|
|
<TerminalIcon className="w-5 h-5" />
|
|
Bash: {containerName}
|
|
{isConnected && (
|
|
<span className="ml-2 text-xs bg-success/20 text-success px-2 py-0.5 rounded-full">
|
|
Connected
|
|
</span>
|
|
)}
|
|
</DialogTitle>
|
|
<DialogDescription className="hidden">
|
|
Interactive bash terminal session for {containerName}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
{/* Styling wrapper - padding and rounded corners go here */}
|
|
<div className="flex-1 rounded-lg bg-[#1e1e1e] p-1 min-h-0" style={{ overflow: 'hidden' }}>
|
|
{/* Clean xterm container - NO padding, NO overflow-hidden, explicit dimensions */}
|
|
<div
|
|
ref={terminalRef}
|
|
style={{ width: '100%', height: '100%' }}
|
|
/>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|