diff --git a/App.tsx b/App.tsx index 0b5664d04..adf05ae24 100755 --- a/App.tsx +++ b/App.tsx @@ -1,296 +1,31 @@ -import React, { useState, useEffect, useMemo, useRef } from 'react'; -import Terminal from './components/Terminal'; -import AssistantPanel from './components/AssistantPanel'; -import KeyManager from './components/KeyManager'; -import SnippetsManager from './components/SnippetsManager'; +import React, { useState, useEffect, useMemo } from 'react'; import SettingsDialog from './components/SettingsDialog'; -import PortForwarding from './components/PortForwarding'; import HostDetailsPanel from './components/HostDetailsPanel'; -import { Host, SSHKey, GroupNode, Snippet, SyncConfig, TerminalSession, Workspace, WorkspaceNode, RemoteFile } from './types'; +import { SftpView } from './components/SftpView'; +import { TopTabs } from './components/TopTabs'; +import { QuickSwitcher } from './components/QuickSwitcher'; +import { VaultView } from './components/VaultView'; +import { TerminalLayer } from './components/TerminalLayer'; +import { normalizeDistroId } from './components/DistroAvatar'; +import { INITIAL_HOSTS, INITIAL_SNIPPETS } from './lib/defaultData'; +import { + STORAGE_KEY_COLOR, + STORAGE_KEY_GROUPS, + STORAGE_KEY_HOSTS, + STORAGE_KEY_KEYS, + STORAGE_KEY_SNIPPET_PACKAGES, + STORAGE_KEY_SNIPPETS, + STORAGE_KEY_SYNC, + STORAGE_KEY_TERM_THEME, + STORAGE_KEY_THEME, +} from './lib/storageKeys'; +import { Host, SSHKey, Snippet, SyncConfig, TerminalSession, Workspace, WorkspaceNode } from './types'; import { TERMINAL_THEMES } from './lib/terminalThemes'; -import { - Plus, Search, Settings, LayoutGrid, List as ListIcon, Monitor, Command, - Trash2, Edit2, Key, Folder, FolderOpen, ChevronRight, FolderPlus, FileCode, - X, TerminalSquare, Shield, Grid, Heart, Star, Bell, User, Plug, BookMarked, Activity, Sun, Moon, - HardDrive, RefreshCw -} from 'lucide-react'; +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from './components/ui/dialog'; import { Button } from './components/ui/button'; import { Input } from './components/ui/input'; -import { Card, CardContent } from './components/ui/card'; -import { Badge } from './components/ui/badge'; -import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from './components/ui/dialog'; -import { Popover, PopoverContent, PopoverTrigger } from './components/ui/popover'; import { Label } from './components/ui/label'; -import { cn } from './lib/utils'; -import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from './components/ui/context-menu'; -import { Collapsible, CollapsibleContent, CollapsibleTrigger } from './components/ui/collapsible'; -import { ScrollArea } from './components/ui/scroll-area'; -const STORAGE_KEY_HOSTS = 'nebula_hosts_v1'; -const STORAGE_KEY_KEYS = 'nebula_keys_v1'; -const STORAGE_KEY_GROUPS = 'nebula_groups_v1'; -const STORAGE_KEY_SNIPPETS = 'nebula_snippets_v1'; -const STORAGE_KEY_SNIPPET_PACKAGES = 'nebula_snippet_packages_v1'; -const STORAGE_KEY_THEME = 'nebula_theme_v1'; -const STORAGE_KEY_COLOR = 'nebula_color_v1'; -const STORAGE_KEY_SYNC = 'nebula_sync_v1'; -const STORAGE_KEY_TERM_THEME = 'nebula_term_theme_v1'; - -const normalizeDistroId = (value?: string) => { - const v = (value || '').toLowerCase().trim(); - if (!v) return ''; - if (v.includes('ubuntu')) return 'ubuntu'; - if (v.includes('debian')) return 'debian'; - if (v.includes('centos')) return 'centos'; - if (v.includes('rocky')) return 'rocky'; - if (v.includes('fedora')) return 'fedora'; - if (v.includes('arch') || v.includes('manjaro')) return 'arch'; - if (v.includes('alpine')) return 'alpine'; - if (v.includes('amzn') || v.includes('amazon') || v.includes('aws')) return 'amazon'; - if (v.includes('opensuse') || v.includes('suse') || v.includes('sles')) return 'opensuse'; - if (v.includes('red hat') || v.includes('rhel')) return 'redhat'; - if (v.includes('oracle')) return 'oracle'; - if (v.includes('kali')) return 'kali'; - return ''; -}; - -const INITIAL_HOSTS: Host[] = [ - { id: '1', label: 'Production Web', hostname: '10.0.0.12', port: 22, username: 'ubuntu', group: 'AWS/Production', tags: ['prod', 'web'], os: 'linux' }, - { id: '2', label: 'DB Master', hostname: 'db-01.internal', port: 22, username: 'admin', group: 'AWS/Production', tags: ['prod', 'db'], os: 'linux' }, -]; - -const INITIAL_SNIPPETS: Snippet[] = [ - { id: '1', label: 'Check Disk Space', command: 'df -h', tags: [] }, - { id: '2', label: 'Tail System Log', command: 'tail -f /var/log/syslog', tags: [] }, - { id: '3', label: 'Update Ubuntu', command: 'sudo apt update && sudo apt upgrade -y', tags: [] }, -]; - -const DISTRO_LOGOS: Record = { - ubuntu: "/distro/ubuntu.svg", - debian: "/distro/debian.svg", - centos: "/distro/centos.svg", - rocky: "/distro/rocky.svg", - fedora: "/distro/fedora.svg", - arch: "/distro/arch.svg", - alpine: "/distro/alpine.svg", - amazon: "/distro/amazon.svg", - opensuse: "/distro/opensuse.svg", - redhat: "/distro/redhat.svg", - oracle: "/distro/oracle.svg", - kali: "/distro/kali.svg", -}; - -const DISTRO_COLORS: Record = { - ubuntu: "bg-[#E95420]", - debian: "bg-[#A81D33]", - centos: "bg-[#9C27B0]", - rocky: "bg-[#0B9B69]", - fedora: "bg-[#3C6EB4]", - arch: "bg-[#1793D1]", - alpine: "bg-[#0D597F]", - amazon: "bg-[#FF9900]", - opensuse: "bg-[#73BA25]", - redhat: "bg-[#EE0000]", - oracle: "bg-[#C74634]", - kali: "bg-[#0F6DB3]", - default: "bg-slate-600", -}; - -type FileItem = RemoteFile & { kind?: string }; - -const LOCAL_FILE_MAP: Record = { - "/": [ - { name: "Applications", type: "directory", size: "--", lastModified: "--", kind: "folder" }, - { name: "Users", type: "directory", size: "--", lastModified: "--", kind: "folder" }, - ], - "/Users": [ - { name: "chenqi", type: "directory", size: "--", lastModified: "Dec 27, 2025 9:10 AM", kind: "folder" }, - ], - "/Users/chenqi": [ - { name: "Documents", type: "directory", size: "--", lastModified: "Dec 12, 2025 10:18 AM", kind: "folder" }, - { name: "Downloads", type: "directory", size: "--", lastModified: "Dec 17, 2025 3:40 AM", kind: "folder" }, - { name: "Pictures", type: "directory", size: "--", lastModified: "Jul 19, 2025 10:52 PM", kind: "folder" }, - { name: "Projects", type: "directory", size: "--", lastModified: "Dec 3, 2025 2:22 PM", kind: "folder" }, - { name: "notes.txt", type: "file", size: "3.2 KB", lastModified: "Nov 2, 2025 9:12 PM", kind: "txt" }, - ], - "/Users/chenqi/Downloads": [ - { name: "archive.zip", type: "file", size: "128 MB", lastModified: "Dec 2, 2025 11:12 PM", kind: "zip" }, - { name: "release", type: "directory", size: "--", lastModified: "Dec 1, 2025 5:00 PM", kind: "folder" }, - ], - "/Users/chenqi/Projects": [ - { name: "nebula-ssh", type: "directory", size: "--", lastModified: "Dec 27, 2025 9:10 AM", kind: "folder" }, - { name: "readme.md", type: "file", size: "7.2 KB", lastModified: "Nov 4, 2025 8:12 AM", kind: "md" }, - ], - "/Users/chenqi/Projects/nebula-ssh": [ - { name: "src", type: "directory", size: "--", lastModified: "Dec 18, 2025 12:12 PM", kind: "folder" }, - { name: "package.json", type: "file", size: "2.4 KB", lastModified: "Dec 18, 2025 12:12 PM", kind: "json" }, - { name: "README.md", type: "file", size: "4.1 KB", lastModified: "Nov 30, 2025 9:40 AM", kind: "md" }, - ], -}; - -const REMOTE_FILE_MAP: Record = { - "/": [ - { name: "root", type: "directory", size: "--", lastModified: "--", kind: "folder" }, - { name: "var", type: "directory", size: "--", lastModified: "--", kind: "folder" }, - { name: "etc", type: "directory", size: "--", lastModified: "--", kind: "folder" }, - { name: "opt", type: "directory", size: "--", lastModified: "--", kind: "folder" }, - ], - "/root": [ - { name: "deploy.sh", type: "file", size: "21.3 KB", lastModified: "Sep 28, 2025 3:42 PM", kind: "sh" }, - { name: "clean.sh", type: "file", size: "1.6 KB", lastModified: "Sep 28, 2025 3:46 PM", kind: "sh" }, - { name: "update.sh", type: "file", size: "498 Bytes", lastModified: "Nov 17, 2025 10:20 PM", kind: "sh" }, - { name: "notes", type: "directory", size: "--", lastModified: "Sep 15, 2025 10:20 PM", kind: "folder" }, - ], - "/root/notes": [ - { name: "todo.md", type: "file", size: "1.2 KB", lastModified: "Sep 10, 2025 8:11 PM", kind: "md" }, - { name: "deploy-checklist.md", type: "file", size: "2.4 KB", lastModified: "Sep 9, 2025 6:05 PM", kind: "md" }, - ], - "/var": [ - { name: "log", type: "directory", size: "--", lastModified: "Aug 1, 2025 12:00 PM", kind: "folder" }, - { name: "www", type: "directory", size: "--", lastModified: "Jul 1, 2025 7:32 PM", kind: "folder" }, - ], - "/var/log": [ - { name: "syslog", type: "file", size: "14.2 MB", lastModified: "Dec 17, 2025 7:11 PM", kind: "log" }, - { name: "kern.log", type: "file", size: "2.9 MB", lastModified: "Dec 17, 2025 7:07 PM", kind: "log" }, - ], - "/etc": [ - { name: "nginx", type: "directory", size: "--", lastModified: "Nov 1, 2025 4:20 PM", kind: "folder" }, - { name: "ssh", type: "directory", size: "--", lastModified: "Oct 12, 2025 11:20 AM", kind: "folder" }, - { name: "timezone", type: "file", size: "122 Bytes", lastModified: "Oct 2, 2025 9:02 AM", kind: "conf" }, - ], - "/etc/nginx": [ - { name: "nginx.conf", type: "file", size: "3.4 KB", lastModified: "Nov 1, 2025 4:20 PM", kind: "conf" }, - { name: "sites-enabled", type: "directory", size: "--", lastModified: "Nov 1, 2025 4:20 PM", kind: "folder" }, - ], - "/etc/ssh": [ - { name: "sshd_config", type: "file", size: "2.1 KB", lastModified: "Oct 12, 2025 11:21 AM", kind: "conf" }, - { name: "ssh_config", type: "file", size: "1.1 KB", lastModified: "Oct 12, 2025 11:19 AM", kind: "conf" }, - ], -}; - -const DistroAvatar: React.FC<{ host: Host; fallback: string; className?: string }> = ({ host, fallback, className }) => { - const distro = (host.distro || '').toLowerCase(); - const logo = DISTRO_LOGOS[distro]; - const [errored, setErrored] = React.useState(false); - const bg = DISTRO_COLORS[distro] || DISTRO_COLORS.default; - - if (logo && !errored) { - return ( -
- {host.distro setErrored(true)} - /> -
- ); - } - - return ( -
- {fallback} -
- ); -}; - -// --- Group Tree Item --- -interface GroupTreeItemProps { - node: GroupNode; - depth: number; - expandedPaths: Set; - onToggle: (path: string) => void; - onSelectGroup: (path: string) => void; - selectedGroup: string | null; - onEditGroup: (path: string) => void; - onNewHost: (path: string) => void; - onNewSubfolder: (path: string) => void; -} - -const GroupTreeItem: React.FC = ({ - node, depth, expandedPaths, onToggle, onSelectGroup, selectedGroup, - onEditGroup, onNewHost, onNewSubfolder -}) => { - const isExpanded = expandedPaths.has(node.path); - const hasChildren = node.children && Object.keys(node.children).length > 0; - const paddingLeft = `${depth * 12 + 12}px`; - const isSelected = selectedGroup === node.path; - - // Convert children map to sorted array - const childNodes = useMemo(() => { - return node.children - ? (Object.values(node.children) as unknown as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)) - : []; - }, [node.children]); - - return ( - onToggle(node.path)}> - - - -
{ - onSelectGroup(node.path); - }} - > -
- {hasChildren && ( -
- -
- )} -
- -
- {isExpanded ? : } -
- - {node.name} - - {node.hosts.length > 0 && ( - - {node.hosts.length} - - )} -
-
-
- - onNewHost(node.path)}> - New Host - - onNewSubfolder(node.path)}> - New Subfolder - - -
- - {hasChildren && ( - - {childNodes.map(child => ( - - ))} - - )} -
- ); -}; function App() { const sanitizeHost = (host: Host): Host => { @@ -320,25 +55,6 @@ function App() { const [activeTabId, setActiveTabId] = useState('vault'); // 'vault', session.id, or workspace.id const [workspaces, setWorkspaces] = useState([]); const [draggingSessionId, setDraggingSessionId] = useState(null); - const [dropHint, setDropHint] = useState<{ - direction: 'horizontal' | 'vertical'; - position: 'left' | 'right' | 'top' | 'bottom'; - targetSessionId?: string; - rect?: { x: number; y: number; w: number; h: number }; - } | null>(null); - const [workspaceArea, setWorkspaceArea] = useState<{ width: number; height: number }>({ width: 0, height: 0 }); - const workspaceOuterRef = useRef(null); - const workspaceInnerRef = useRef(null); - const workspaceOverlayRef = useRef(null); - const [resizing, setResizing] = useState<{ - workspaceId: string; - splitId: string; - index: number; - direction: 'vertical' | 'horizontal'; - startSizes: number[]; - startArea: { w: number; h: number }; - startClient: { x: number; y: number }; - } | null>(null); // Modals const [editingHost, setEditingHost] = useState(null); @@ -346,26 +62,10 @@ function App() { const [isSettingsOpen, setIsSettingsOpen] = useState(false); const [isQuickSwitcherOpen, setIsQuickSwitcherOpen] = useState(false); const [quickSearch, setQuickSearch] = useState(''); - - // Vault View State - const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid'); - const [currentSection, setCurrentSection] = useState<'hosts' | 'keys' | 'snippets' | 'port'>('hosts'); - const [showAssistant, setShowAssistant] = useState(false); - const [search, setSearch] = useState(''); - const [expandedPaths, setExpandedPaths] = useState>(new Set()); - const [selectedGroupPath, setSelectedGroupPath] = useState(null); - const [isNewFolderOpen, setIsNewFolderOpen] = useState(false); - const [newFolderName, setNewFolderName] = useState(''); - const [targetParentPath, setTargetParentPath] = useState(null); - const [snippetPackages, setSnippetPackages] = useState([]); - const [focusedSessionId, setFocusedSessionId] = useState(null); - // SFTP View State - type SftpPaneTab = { id: string; label: string; isLocal: boolean; hostId?: string; path: string; filter: string; status?: 'idle' | 'connecting' | 'connected' }; - const [sftpLeftTab, setSftpLeftTab] = useState({ id: 'local-default', label: 'Local', isLocal: true, hostId: 'local', path: '/Users/chenqi', filter: '' }); - const [sftpRightTab, setSftpRightTab] = useState(null); - const [sftpHostModalSide, setSftpHostModalSide] = useState<'left' | 'right' | null>(null); - const [sftpHostPickerSearch, setSftpHostPickerSearch] = useState(''); + // Vault View State + const [showAssistant, setShowAssistant] = useState(false); + const [snippetPackages, setSnippetPackages] = useState([]); // --- Effects --- useEffect(() => { @@ -459,102 +159,6 @@ function App() { }); }; - const sftpGroups = useMemo(() => { - const bucket: Record = {}; - hosts.forEach(h => { - const key = (h.group || 'Ungrouped').split('/')[0] || 'Ungrouped'; - bucket[key] = (bucket[key] || 0) + 1; - }); - return Object.entries(bucket) - .map(([name, count]) => ({ name, count })) - .sort((a, b) => a.name.localeCompare(b.name)); - }, [hosts]); - - const filteredSftpHosts = useMemo(() => { - const term = sftpHostPickerSearch.trim().toLowerCase(); - return hosts - .filter(h => { - if (!term) return true; - return ( - h.label.toLowerCase().includes(term) || - h.hostname.toLowerCase().includes(term) || - (h.group || '').toLowerCase().includes(term) - ); - }) - .sort((a, b) => a.label.localeCompare(b.label)); - }, [hosts, sftpHostPickerSearch]); - - const breadcrumbForPath = (path: string) => { - if (path === '/') return []; - const parts = path.split('/').filter(Boolean); - return parts.map((part, idx) => ({ - label: part, - path: '/' + parts.slice(0, idx + 1).join('/'), - })); - }; - - const parentForPath = (path: string) => { - if (path === '/') return '/'; - const parts = path.split('/').filter(Boolean); - parts.pop(); - return parts.length ? `/${parts.join('/')}` : '/'; - }; - - const applyFileFilter = (items: FileItem[], filter: string) => { - const term = filter.trim().toLowerCase(); - if (!term) return items; - return items.filter(item => item.name === '..' || item.name.toLowerCase().includes(term)); - }; - - const getEntriesForTab = (tab: SftpPaneTab | null) => { - if (!tab) return []; - const map: Record = tab.isLocal ? LOCAL_FILE_MAP : REMOTE_FILE_MAP; - const files: FileItem[] = map[tab.path] || []; - const parentEntry: FileItem = { name: '..', type: 'directory', size: '--', lastModified: '--', kind: 'folder' }; - const withParent = tab.path === '/' ? files : [parentEntry, ...files]; - return applyFileFilter(withParent, tab.filter); - }; - - const formatKind = (item: FileItem) => { - if (item.type === 'directory') return 'folder'; - if (item.kind) return item.kind; - const ext = item.name.split('.').pop(); - return ext ? ext.toLowerCase() : 'file'; - }; - - const updateTabField = (side: 'left' | 'right', updater: (tab: SftpPaneTab) => Partial) => { - if (side === 'left') setSftpLeftTab(prev => ({ ...prev, ...updater(prev) })); - else setSftpRightTab(prev => prev ? ({ ...prev, ...updater(prev) }) : prev); - }; - - const openEntry = (side: 'left' | 'right', tab: SftpPaneTab | null, item: FileItem) => { - if (!tab || item.type !== 'directory') return; - if (item.name === '..') { - const parent = parentForPath(tab.path); - updateTabField(side, () => ({ path: parent })); - return; - } - const next = tab.path === '/' ? `/${item.name}` : `${tab.path}/${item.name}`; - updateTabField(side, () => ({ path: next })); - }; - - const leftEntries = useMemo(() => getEntriesForTab(sftpLeftTab), [sftpLeftTab]); - const rightEntries = useMemo(() => getEntriesForTab(sftpRightTab), [sftpRightTab]); - const leftBreadcrumbs = useMemo(() => breadcrumbForPath(sftpLeftTab?.path || '/'), [sftpLeftTab]); - const rightBreadcrumbs = useMemo(() => breadcrumbForPath(sftpRightTab?.path || '/'), [sftpRightTab]); - - const selectHostForSide = (side: 'left' | 'right', host: Host | 'local') => { - if (host === 'local') { - const tab = { id: `tab-${side}-${crypto.randomUUID()}`, label: 'Local', isLocal: true, hostId: 'local', path: '/Users/chenqi', filter: '', status: 'connected' } as SftpPaneTab; - side === 'left' ? setSftpLeftTab(tab) : setSftpRightTab(tab); - } else { - const tab = { id: `tab-${side}-${crypto.randomUUID()}`, label: host.label, isLocal: false, hostId: host.id, path: '/root', filter: '', status: 'connected' } as SftpPaneTab; - side === 'left' ? setSftpLeftTab(tab) : setSftpRightTab(tab); - } - setSftpHostModalSide(null); - setSftpHostPickerSearch(''); - }; - const pruneWorkspaceNode = (node: WorkspaceNode, targetSessionId: string): WorkspaceNode | null => { if (node.type === 'pane') { return node.sessionId === targetSessionId ? null : node; @@ -656,68 +260,10 @@ function App() { setWorkspaceRenameValue(''); }; - type WorkspaceRect = { x: number; y: number; w: number; h: number }; - - const computeSplitHint = (e: React.DragEvent): { - direction: 'horizontal' | 'vertical'; - position: 'left' | 'right' | 'top' | 'bottom'; - targetSessionId?: string; - rect?: { x: number; y: number; w: number; h: number }; - } | null => { - const surface = workspaceOverlayRef.current || workspaceInnerRef.current || workspaceOuterRef.current; - if (!surface || !workspaceArea.width || !workspaceArea.height) return null; - const rect = surface.getBoundingClientRect(); - const localX = e.clientX - rect.left; - const localY = e.clientY - rect.top; - if (localX < 0 || localX > rect.width || localY < 0 || localY > rect.height) return null; - - let targetSessionId: string | undefined; - let targetRect: WorkspaceRect | undefined; - const workspaceEntries = Object.entries(activeWorkspaceRects) as Array<[string, WorkspaceRect]>; - workspaceEntries.forEach(([sessionId, area]) => { - if (targetSessionId) return; - if ( - localX >= area.x && - localX <= area.x + area.w && - localY >= area.y && - localY <= area.y + area.h - ) { - targetSessionId = sessionId; - targetRect = area; - } - }); - - const baseRect: WorkspaceRect = targetRect || { x: 0, y: 0, w: rect.width, h: rect.height }; - const relX = (localX - baseRect.x) / baseRect.w; - const relY = (localY - baseRect.y) / baseRect.h; - - const prefersVertical = Math.abs(relX - 0.5) > Math.abs(relY - 0.5); - const direction = prefersVertical ? 'vertical' : 'horizontal'; - const position = prefersVertical - ? (relX < 0.5 ? 'left' : 'right') - : (relY < 0.5 ? 'top' : 'bottom'); - - const previewRect: WorkspaceRect = { ...baseRect }; - if (direction === 'vertical') { - previewRect.w = baseRect.w / 2; - previewRect.x = position === 'left' ? baseRect.x : baseRect.x + baseRect.w / 2; - } else { - previewRect.h = baseRect.h / 2; - previewRect.y = position === 'top' ? baseRect.y : baseRect.y + baseRect.h / 2; - } - - return { - direction, - position, - targetSessionId, - rect: previewRect, - }; - }; - const createWorkspaceFromSessions = ( baseSessionId: string, joiningSessionId: string, - hint: { direction: 'horizontal' | 'vertical'; position: 'left' | 'right' | 'top' | 'bottom'; targetSessionId?: string } | null + hint: { direction: 'horizontal' | 'vertical'; position: 'left' | 'right' | 'top' | 'bottom'; targetSessionId?: string } ) => { if (!hint || baseSessionId === joiningSessionId) return; const base = sessions.find(s => s.id === baseSessionId); @@ -804,52 +350,6 @@ function App() { setActiveTabId(workspaceId); }; - const handleWorkspaceDrop = (e: React.DragEvent) => { - const draggedSessionId = e.dataTransfer.getData('session-id'); - if (!draggedSessionId) return; - e.preventDefault(); - const hint = computeSplitHint(e); - setDropHint(null); - - if (activeWorkspace) { - const draggedSession = sessions.find(s => s.id === draggedSessionId); - if (!draggedSession || draggedSession.workspaceId) return; - addSessionToWorkspace(activeWorkspace.id, draggedSessionId, hint); - return; - } - - if (activeSession) { - createWorkspaceFromSessions(activeSession.id, draggedSessionId, hint); - } - }; - - const computeWorkspaceRects = (workspace?: Workspace, size?: { width: number; height: number }): Record => { - if (!workspace) return {} as Record; - const wTotal = size?.width || 1; - const hTotal = size?.height || 1; - const rects: Record = {}; - const walk = (node: WorkspaceNode, area: WorkspaceRect) => { - if (node.type === 'pane') { - rects[node.sessionId] = area; - return; - } - const isVertical = node.direction === 'vertical'; - const sizes = (node.sizes && node.sizes.length === node.children.length ? node.sizes : Array(node.children.length).fill(1)); - const total = sizes.reduce((acc, n) => acc + n, 0) || 1; - let offset = 0; - node.children.forEach((child, idx) => { - const share = sizes[idx] / total; - const childArea = isVertical - ? { x: area.x + area.w * offset, y: area.y, w: area.w * share, h: area.h } - : { x: area.x, y: area.y + area.h * offset, w: area.w, h: area.h * share }; - walk(child, childArea); - offset += share; - }); - }; - walk(workspace.root, { x: 0, y: 0, w: wTotal, h: hTotal }); - return rects; - }; - // --- Data Logic --- const getExportData = () => ({ hosts, keys, snippets, customGroups }); const handleImportData = (jsonString: string) => { @@ -860,37 +360,6 @@ function App() { if(data.customGroups) updateCustomGroups(data.customGroups); }; - const buildGroupTree = useMemo>(() => { - const root: Record = {}; - const insertPath = (path: string, host?: Host) => { - const parts = path.split('/').filter(Boolean); - let currentLevel = root; - let currentPath = ''; - parts.forEach((part, index) => { - currentPath = currentPath ? `${currentPath}/${part}` : part; - if (!currentLevel[part]) { - currentLevel[part] = { name: part, path: currentPath, children: {}, hosts: [] }; - } - if (host && index === parts.length - 1) currentLevel[part].hosts.push(host); - currentLevel = currentLevel[part].children; - }); - }; - customGroups.forEach(path => insertPath(path)); - hosts.forEach(host => insertPath(host.group || 'General', host)); - return root; - }, [hosts, customGroups]); - - const findGroupNode = (path: string | null): GroupNode | null => { - if (!path) return { name: 'root', path: '', children: buildGroupTree, hosts: [] } as any; - const parts = path.split('/').filter(Boolean); - let current: any = { children: buildGroupTree }; - for (const p of parts) { - current = current.children?.[p]; - if (!current) return null; - } - return current; - }; - const quickResults = useMemo(() => { const term = quickSearch.trim().toLowerCase(); const filtered = term @@ -902,85 +371,6 @@ function App() { : hosts; return filtered.slice(0, 8); }, [hosts, quickSearch]); - - const toggleExpand = (path: string) => { - const newSet = new Set(expandedPaths); - newSet.has(path) ? newSet.delete(path) : newSet.add(path); - setExpandedPaths(newSet); - }; - - const displayedHosts = useMemo(() => { - let filtered = hosts; - if (selectedGroupPath) { - filtered = filtered.filter(h => (h.group || '') === selectedGroupPath); - } - if (search.trim()) { - const s = search.toLowerCase(); - filtered = filtered.filter(h => - h.label.toLowerCase().includes(s) || - h.hostname.toLowerCase().includes(s) || - h.tags.some(t => t.toLowerCase().includes(s)) - ); - } - return filtered; - }, [hosts, selectedGroupPath, search]); - - const displayedGroups = useMemo(() => { - if (!selectedGroupPath) { - return (Object.values(buildGroupTree) as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)); - } - const node = findGroupNode(selectedGroupPath); - if (!node || !node.children) return []; - return (Object.values(node.children) as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)); - }, [buildGroupTree, selectedGroupPath]); - - const submitNewFolder = () => { - if(!newFolderName.trim()) return; - const fullPath = targetParentPath ? `${targetParentPath}/${newFolderName.trim()}` : newFolderName.trim(); - updateCustomGroups(Array.from(new Set([...customGroups, fullPath]))); - if (targetParentPath) setExpandedPaths(prev => new Set(prev).add(targetParentPath)); - setIsNewFolderOpen(false); - }; - - const deleteGroupPath = (path: string) => { - const keepGroups = customGroups.filter(g => !(g === path || g.startsWith(path + '/'))); - const keepHosts = hosts.map(h => { - const g = h.group || ''; - if (g === path || g.startsWith(path + '/')) return { ...h, group: '' }; - return h; - }); - updateCustomGroups(keepGroups); - updateHosts(keepHosts); - if (selectedGroupPath && (selectedGroupPath === path || selectedGroupPath.startsWith(path + '/'))) { - setSelectedGroupPath(null); - } - }; - - const moveGroup = (sourcePath: string, targetParent: string | null) => { - const name = sourcePath.split('/').filter(Boolean).pop() || ''; - const newPath = targetParent ? `${targetParent}/${name}` : name; - if (newPath === sourcePath || newPath.startsWith(sourcePath + '/')) return; - const updatedGroups = customGroups.map(g => { - if (g === sourcePath) return newPath; - if (g.startsWith(sourcePath + '/')) return g.replace(sourcePath, newPath); - return g; - }); - const updatedHosts = hosts.map(h => { - const g = h.group || ''; - if (g === sourcePath) return { ...h, group: newPath }; - if (g.startsWith(sourcePath + '/')) return { ...h, group: g.replace(sourcePath, newPath) }; - return h; - }); - updateCustomGroups(Array.from(new Set(updatedGroups))); - updateHosts(updatedHosts); - if (selectedGroupPath && (selectedGroupPath === sourcePath || selectedGroupPath.startsWith(sourcePath + '/'))) { - setSelectedGroupPath(newPath); - } - }; - - const moveHostToGroup = (hostId: string, groupPath: string | null) => { - updateHosts(hosts.map(h => h.id === hostId ? { ...h, group: groupPath || '' } : h)); - }; const currentTerminalTheme = TERMINAL_THEMES.find(t => t.id === terminalThemeId) || TERMINAL_THEMES[0]; const isVaultActive = activeTabId === 'vault'; @@ -999,87 +389,7 @@ function App() { return () => window.removeEventListener('keydown', onKeyDown); }, [isQuickSwitcherOpen]); - // Sort root nodes for display - const rootNodes = useMemo( - () => (Object.values(buildGroupTree) as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)), - [buildGroupTree] - ); - const activeWorkspace = useMemo(() => workspaces.find(w => w.id === activeTabId), [workspaces, activeTabId]); - const activeSession = useMemo(() => sessions.find(s => s.id === activeTabId), [sessions, activeTabId]); const orphanSessions = useMemo(() => sessions.filter(s => !s.workspaceId), [sessions]); - const activeWorkspaceRects = useMemo>( - () => computeWorkspaceRects(activeWorkspace, workspaceArea), - [activeWorkspace, workspaceArea] - ); - - useEffect(() => { - if (!workspaceInnerRef.current) return; - const el = workspaceInnerRef.current; - const updateSize = () => setWorkspaceArea({ width: el.clientWidth, height: el.clientHeight }); - updateSize(); - const observer = new ResizeObserver(() => updateSize()); - observer.observe(el); - return () => observer.disconnect(); - }, [activeWorkspace]); - - type ResizerHandle = { - id: string; - splitId: string; - index: number; - direction: 'vertical' | 'horizontal'; - rect: { x: number; y: number; w: number; h: number }; - splitArea: { w: number; h: number }; - }; - - const collectResizers = (workspace?: Workspace, size?: { width: number; height: number }): ResizerHandle[] => { - if (!workspace || !size?.width || !size?.height) return []; - const resizers: ResizerHandle[] = []; - const walk = (node: WorkspaceNode, area: { x: number; y: number; w: number; h: number }) => { - if (node.type === 'pane') return; - const isVertical = node.direction === 'vertical'; - const sizes = (node.sizes && node.sizes.length === node.children.length ? node.sizes : Array(node.children.length).fill(1)); - const total = sizes.reduce((acc, n) => acc + n, 0) || 1; - let offset = 0; - node.children.forEach((child, idx) => { - const share = sizes[idx] / total; - const childArea = isVertical - ? { x: area.x + area.w * offset, y: area.y, w: area.w * share, h: area.h } - : { x: area.x, y: area.y + area.h * offset, w: area.w, h: area.h * share }; - if (idx < node.children.length - 1) { - const boundary = isVertical ? childArea.x + childArea.w : childArea.y + childArea.h; - const rect = isVertical - ? { x: boundary - 2, y: area.y, w: 4, h: area.h } - : { x: area.x, y: boundary - 2, w: area.w, h: 4 }; - resizers.push({ - id: `${node.id}-${idx}`, - splitId: node.id, - index: idx, - direction: node.direction, - rect, - splitArea: { w: area.w, h: area.h }, - }); - } - walk(child, childArea); - offset += share; - }); - }; - walk(workspace.root, { x: 0, y: 0, w: size.width, h: size.height }); - return resizers; - }; - - const activeResizers = useMemo(() => collectResizers(activeWorkspace, workspaceArea), [activeWorkspace, workspaceArea]); - - const findSplitNode = (node: WorkspaceNode, splitId: string): WorkspaceNode | null => { - if (node.type === 'split') { - if (node.id === splitId) return node; - for (const child of node.children) { - const found = findSplitNode(child, splitId); - if (found) return found; - } - } - return null; - }; - const updateSplitSizes = (workspaceId: string, splitId: string, sizes: number[]) => { setWorkspaces(prev => prev.map(ws => { if (ws.id !== workspaceId) return ws; @@ -1096,861 +406,90 @@ function App() { })); }; - useEffect(() => { - if (!resizing) return; - const onMove = (e: MouseEvent) => { - const dimension = resizing.direction === 'vertical' ? resizing.startArea.w : resizing.startArea.h; - if (dimension <= 0) return; - const total = resizing.startSizes.reduce((acc, n) => acc + n, 0) || 1; - const pxSizes = resizing.startSizes.map(s => (s / total) * dimension); - const i = resizing.index; - const delta = (resizing.direction === 'vertical' ? e.clientX - resizing.startClient.x : e.clientY - resizing.startClient.y); - let a = pxSizes[i] + delta; - let b = pxSizes[i + 1] - delta; - const minPx = Math.min(120, dimension / 2); - if (a < minPx) { - const diff = minPx - a; - a = minPx; - b -= diff; - } - if (b < minPx) { - const diff = minPx - b; - b = minPx; - a -= diff; - } - const newPxSizes = [...pxSizes]; - newPxSizes[i] = Math.max(minPx, a); - newPxSizes[i + 1] = Math.max(minPx, b); - const totalPx = newPxSizes.reduce((acc, n) => acc + n, 0) || 1; - const newSizes = newPxSizes.map(n => n / totalPx); - updateSplitSizes(resizing.workspaceId, resizing.splitId, newSizes); - }; - const onUp = () => setResizing(null); - window.addEventListener('mousemove', onMove); - window.addEventListener('mouseup', onUp); - return () => { - window.removeEventListener('mousemove', onMove); - window.removeEventListener('mouseup', onUp); - }; - }, [resizing]); + const handleSessionDragStart = (sessionId: string) => setDraggingSessionId(sessionId); + const handleSessionDragEnd = () => setDraggingSessionId(null); - const sessionStatusDot = (status: TerminalSession['status']) => { - const tone = status === 'connected' - ? "bg-emerald-400" - : status === 'connecting' - ? "bg-amber-400" - : "bg-rose-500"; - return ; - }; - - const topTabs = ( -
-
-
setActiveTabId('vault')} - className={cn( - "h-8 px-3 rounded-md border text-xs font-semibold cursor-pointer flex items-center gap-2 app-no-drag", - isVaultActive ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground" - )} - > - Vaults -
-
setActiveTabId('sftp')} - className={cn( - "h-8 px-3 rounded-md border text-xs font-semibold cursor-pointer flex items-center gap-2 app-no-drag", - isSftpActive ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground" - )} - > - SFTP -
- {orphanSessions.map(session => ( -
setActiveTabId(session.id)} - draggable - onDragStart={(e) => { - e.dataTransfer.effectAllowed = 'move'; - e.dataTransfer.setData('session-id', session.id); - setDraggingSessionId(session.id); - }} - onDragEnd={() => { - setDraggingSessionId(null); - setDropHint(null); - }} - className={cn( - "h-8 pl-3 pr-2 min-w-[140px] max-w-[240px] rounded-md border text-xs font-semibold cursor-pointer flex items-center justify-between gap-2 app-no-drag", - activeTabId === session.id ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground", - draggingSessionId === session.id ? "opacity-70" : "" - )} - > -
- - {session.hostLabel} -
{sessionStatusDot(session.status)}
-
- -
- ))} - {workspaces.map(workspace => { - const paneCount = sessions.filter(s => s.workspaceId === workspace.id).length; - const isActive = activeTabId === workspace.id; - return ( - - -
setActiveTabId(workspace.id)} - className={cn( - "h-8 pl-3 pr-2 min-w-[150px] max-w-[260px] rounded-md border text-xs font-semibold cursor-pointer flex items-center justify-between gap-2 app-no-drag", - isActive ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground" - )} - > -
- - {workspace.title} -
-
- {paneCount} -
-
-
- - renameWorkspace(workspace.id)}> - Rename - - closeWorkspace(workspace.id)}> - Close - - -
- ); - })} - -
- - - -
-
-
- ); return (
e.preventDefault()}> - {topTabs} + setIsQuickSwitcherOpen(true)} + onToggleTheme={() => setTheme(prev => prev === 'dark' ? 'light' : 'dark')} + onStartSessionDrag={handleSessionDragStart} + onEndSessionDrag={handleSessionDragEnd} + />
- {/* Vault layer */} -
- {/* Sidebar */} -
-
- netcatty logo -
-

Netcatty

-
-
+ setShowAssistant(prev => !prev)} + onOpenSettings={() => setIsSettingsOpen(true)} + onOpenQuickSwitcher={() => setIsQuickSwitcherOpen(true)} + onNewHost={() => { setEditingHost(null); setIsFormOpen(true); }} + onEditHost={handleEditHost} + onDeleteHost={handleDeleteHost} + onConnect={handleConnect} + onUpdateHosts={updateHosts} + onUpdateKeys={updateKeys} + onUpdateSnippets={updateSnippets} + onUpdateSnippetPackages={updateSnippetPackages} + onUpdateCustomGroups={updateCustomGroups} + /> -
- - - - - - -
+ -
- - -
-
- - {/* Main Area */} -
- {currentSection === 'hosts' && ( -
-
-
- - setSearch(e.target.value)} /> -
- -
- - - - -
-
- - - - - - - - - -
-
-
- )} - -
- {currentSection === 'hosts' && ( - <> -
-
- - {selectedGroupPath && selectedGroupPath.split('/').filter(Boolean).map((part, idx, arr) => { - const crumbPath = arr.slice(0, idx + 1).join('/'); - const isLast = idx === arr.length - 1; - return ( - - › - - - ); - })} -
- {displayedGroups.length > 0 && ( - <> -
-

Groups

-
{displayedGroups.length} total
-
- - )} -
{ e.preventDefault(); }} - onDrop={(e) => { - e.preventDefault(); - e.stopPropagation(); - const hostId = e.dataTransfer.getData('host-id'); - const groupPath = e.dataTransfer.getData('group-path'); - if (hostId) moveHostToGroup(hostId, selectedGroupPath); - if (groupPath && selectedGroupPath !== null) moveGroup(groupPath, selectedGroupPath); - }}> - {displayedGroups.map(node => ( - - -
e.dataTransfer.setData('group-path', node.path)} - onDoubleClick={() => setSelectedGroupPath(node.path)} - onClick={() => setSelectedGroupPath(node.path)} - onDragOver={(e) => { e.preventDefault(); e.stopPropagation(); }} - onDrop={(e) => { - e.preventDefault(); - e.stopPropagation(); - const hostId = e.dataTransfer.getData('host-id'); - const groupPath = e.dataTransfer.getData('group-path'); - if (hostId) moveHostToGroup(hostId, node.path); - if (groupPath) moveGroup(groupPath, node.path); - }} - > -
-
- -
-
-
{node.name}
-
{node.hosts.length} Hosts
-
-
-
-
- - { setTargetParentPath(node.path); setIsNewFolderOpen(true); }}> - New Subgroup - - deleteGroupPath(node.path)}> - Delete Group - - -
- ))} -
-
- -
-
-

Hosts

-
- {displayedHosts.length} entries -
{sessions.length} live
-
-
-
- {displayedHosts.map((host, idx) => { - const safeHost = sanitizeHost(host); - const distro = (safeHost.distro || '').toLowerCase(); - const accentBg = 'bg-primary/15 text-primary'; - const distroBadge = { bg: accentBg, text: (safeHost.os || 'L')[0].toUpperCase(), label: safeHost.distro || safeHost.os || 'Linux' }; - return ( - - -
{ - e.dataTransfer.effectAllowed = 'move'; - e.dataTransfer.setData('host-id', host.id); - }} - onClick={() => handleConnect(safeHost)} - > -
- -
-
{safeHost.label}
-
{safeHost.username}@{safeHost.hostname}
- {safeHost.distro &&
{distroBadge.label}
} -
-
-
-
- - handleConnect(host)}> - Connect - - handleEditHost(host)}> - Edit - - handleDeleteHost(host.id)}> - Delete - - -
- ); - })} - {displayedHosts.length === 0 && ( -
-
-
- -
-
No results found
-
Adjust your search or create a new host.
-
- - -
-
-
- )} -
-
- - )} - - {currentSection === 'keys' && ( - updateKeys([...keys, k])} onDelete={id => updateKeys(keys.filter(k => k.id !== id))} /> - )} - {currentSection === 'snippets' && ( - updateSnippets(snippets.find(ex => ex.id === s.id) ? snippets.map(ex => ex.id === s.id ? s : ex) : [...snippets, s])} - onDelete={id => updateSnippets(snippets.filter(s => s.id !== id))} - /> - )} - {currentSection === 'port' && } -
-
-
- - {/* SFTP layer */} -
-
-
- {/* Left pane */} -
-
-
- - {sftpLeftTab?.label || 'Local / Hosts'} -
- - {sftpLeftTab && ( -
- updateTabField('left', () => ({ filter: e.target.value }))} - placeholder="Filter" - className="h-9 w-44 bg-background/60" - /> - -
- )} -
- -
- / - {leftBreadcrumbs.map((crumb, idx) => ( - - - {idx < leftBreadcrumbs.length - 1 && /} - - ))} -
- -
-
- Name - Date Modified - Size - Kind -
-
- {leftEntries.map((file, idx) => ( -
openEntry('left', sftpLeftTab, file)} - > -
-
- {file.type === 'directory' ? : } -
- {file.name} -
- {file.lastModified} - {file.size} - {formatKind(file)} -
- ))} -
-
- {leftEntries.length} items - {sftpLeftTab?.path} -
-
-
- - {/* Right pane */} -
-
-
- - {sftpRightTab?.label || 'Remote'} -
- - {sftpRightTab && ( -
- updateTabField('right', () => ({ filter: e.target.value }))} - placeholder="Filter remote" - className="h-9 w-44 bg-background/60" - /> - -
- )} -
- - {sftpRightTab ? ( - <> -
- / - {rightBreadcrumbs.map((crumb, idx) => ( - - - {idx < rightBreadcrumbs.length - 1 && /} - - ))} -
-
-
- Name - Date Modified - Size - Kind -
-
- {rightEntries.map((file, idx) => ( -
openEntry('right', sftpRightTab, file)} - > -
-
- {file.type === 'directory' ? : } -
- {file.name} -
- {file.lastModified} - {file.size} - {formatKind(file)} -
- ))} -
-
- {rightEntries.length} items - {sftpRightTab?.hostId || 'No host'} -
-
- - ) : ( -
-
- -
-
Select a host to start
-
Use “Add host” to open a remote in this pane.
- -
- )} -
-
-
-
- - setSftpHostModalSide(open ? (sftpHostModalSide || 'left') : null)}> - - - Select Host - Pick a host for the {sftpHostModalSide === 'left' ? 'left' : 'right'} pane. - -
- setSftpHostPickerSearch(e.target.value)} - placeholder="Search hosts" - className="h-10" - /> -
selectHostForSide(sftpHostModalSide || 'left', 'local')} - > -
-
L
-
-
Local filesystem
-
/Users/chenqi
-
-
- Local -
-
- {filteredSftpHosts.map(host => ( -
selectHostForSide(sftpHostModalSide || 'left', host)} - > -
- -
-
{host.label}
-
{host.username}@{host.hostname}
-
{host.group || 'Personal'}
-
-
- Host -
- ))} - {filteredSftpHosts.length === 0 && ( -
- No matching hosts -
- )} -
-
-
-
- - {/* Terminal layer (kept mounted) */} -
- {draggingSessionId && ( -
{ - if (!e.dataTransfer.types.includes('session-id')) return; - e.preventDefault(); - e.stopPropagation(); - const hint = computeSplitHint(e); - setDropHint(hint); - }} - onDragLeave={(e) => { - if (!e.dataTransfer.types.includes('session-id')) return; - setDropHint(null); - }} - onDrop={(e) => { - e.preventDefault(); - e.stopPropagation(); - setDraggingSessionId(null); - handleWorkspaceDrop(e); - }} - > - {dropHint && ( -
-
-
- )} -
- )} -
- {sessions.map(session => { - const host = hosts.find(h => h.id === session.hostId); - if (!host) return null; - const inActiveWorkspace = !!activeWorkspace && session.workspaceId === activeWorkspace.id; - const isActiveSolo = activeTabId === session.id && !activeWorkspace && isTerminalLayerVisible; - const isVisible = (inActiveWorkspace || isActiveSolo) && isTerminalLayerVisible; - const rect = inActiveWorkspace ? activeWorkspaceRects[session.id] : null; - const isFocused = focusedSessionId === session.id && isVisible; - - const layoutStyle = rect - ? { - left: `${rect.x}px`, - top: `${rect.y}px`, - width: `${rect.w}px`, - height: `${rect.h}px`, - } - : { left: 0, top: 0, width: '100%', height: '100%' }; - - const style: React.CSSProperties = isFocused - ? { - ...layoutStyle, - outline: '2px solid hsl(var(--primary))', - outlineOffset: -4, - boxShadow: 'inset 0 0 0 1px rgba(255,255,255,0.12)', - } - : { ...layoutStyle }; - - if (!isVisible) { - style.display = 'none'; - } - - return ( -
setFocusedSessionId(session.id)} - > - closeSession(session.id)} - onStatusChange={(next) => updateSessionStatus(session.id, next)} - onSessionExit={() => updateSessionStatus(session.id, 'disconnected')} - onOsDetected={(hid, distro) => updateHostDistro(hid, distro)} - /> -
- ); - })} - {activeResizers.map(handle => ( -
{ - e.preventDefault(); - e.stopPropagation(); - const ws = activeWorkspace; - if (!ws) return; - const split = findSplitNode(ws.root, handle.splitId); - const childCount = split && split.type === 'split' ? split.children.length : 0; - const sizes = split && split.type === 'split' && split.sizes && split.sizes.length === childCount - ? split.sizes - : Array(childCount).fill(1); - setResizing({ - workspaceId: ws.id, - splitId: handle.splitId, - index: handle.index, - direction: handle.direction, - startSizes: sizes.length ? sizes : [1, 1], - startArea: handle.splitArea, - startClient: { x: e.clientX, y: e.clientY }, - }); - }} - > -
-
- ))} -
- {showAssistant && ( -
- -
- )} -
+
- {isQuickSwitcherOpen && ( -
{ if (e.target === e.currentTarget) setIsQuickSwitcherOpen(false); }} - > -
-
- setQuickSearch(e.target.value)} - placeholder="Search hosts or tabs..." - className="h-12 text-sm bg-secondary border-primary/50 focus-visible:ring-primary" - /> -
⌘K
-
-
-
- Recent connections -
- - -
-
-
- {quickResults.length > 0 ? quickResults.map(host => ( -
{ e.stopPropagation(); handleConnect(host); setIsQuickSwitcherOpen(false); setQuickSearch(''); }} - > -
-
- -
-
-
{host.label}
-
{host.username}@{host.hostname}
-
-
-
{host.group || 'Personal'}
-
- )) : ( -
No matches. Start typing to search.
- )} -
-
-
-
- )} + { + handleConnect(host); + setIsQuickSwitcherOpen(false); + setQuickSearch(''); + }} + onClose={() => setIsQuickSwitcherOpen(false)} + /> { if (!open) { @@ -2009,21 +548,6 @@ function App() { terminalThemeId={terminalThemeId} onTerminalThemeChange={setTerminalThemeId} /> - - - - - {targetParentPath ? `Create Subfolder` : 'Create Root Group'} - Create a new group for organizing hosts. - -
- - setNewFolderName(e.target.value)} placeholder="e.g. Production" autoFocus onKeyDown={e => e.key === 'Enter' && submitNewFolder()} /> - {targetParentPath &&

Parent: {targetParentPath}

} -
- -
-
); } diff --git a/components/DistroAvatar.tsx b/components/DistroAvatar.tsx new file mode 100644 index 000000000..59335974d --- /dev/null +++ b/components/DistroAvatar.tsx @@ -0,0 +1,80 @@ +import React from 'react'; +import { Host } from '../types'; +import { cn } from '../lib/utils'; + +export const DISTRO_LOGOS: Record = { + ubuntu: "/distro/ubuntu.svg", + debian: "/distro/debian.svg", + centos: "/distro/centos.svg", + rocky: "/distro/rocky.svg", + fedora: "/distro/fedora.svg", + arch: "/distro/arch.svg", + alpine: "/distro/alpine.svg", + amazon: "/distro/amazon.svg", + opensuse: "/distro/opensuse.svg", + redhat: "/distro/redhat.svg", + oracle: "/distro/oracle.svg", + kali: "/distro/kali.svg", +}; + +export const DISTRO_COLORS: Record = { + ubuntu: "bg-[#E95420]", + debian: "bg-[#A81D33]", + centos: "bg-[#9C27B0]", + rocky: "bg-[#0B9B69]", + fedora: "bg-[#3C6EB4]", + arch: "bg-[#1793D1]", + alpine: "bg-[#0D597F]", + amazon: "bg-[#FF9900]", + opensuse: "bg-[#73BA25]", + redhat: "bg-[#EE0000]", + oracle: "bg-[#C74634]", + kali: "bg-[#0F6DB3]", + default: "bg-slate-600", +}; + +export const normalizeDistroId = (value?: string) => { + const v = (value || '').toLowerCase().trim(); + if (!v) return ''; + if (v.includes('ubuntu')) return 'ubuntu'; + if (v.includes('debian')) return 'debian'; + if (v.includes('centos')) return 'centos'; + if (v.includes('rocky')) return 'rocky'; + if (v.includes('fedora')) return 'fedora'; + if (v.includes('arch') || v.includes('manjaro')) return 'arch'; + if (v.includes('alpine')) return 'alpine'; + if (v.includes('amzn') || v.includes('amazon') || v.includes('aws')) return 'amazon'; + if (v.includes('opensuse') || v.includes('suse') || v.includes('sles')) return 'opensuse'; + if (v.includes('red hat') || v.includes('rhel')) return 'redhat'; + if (v.includes('oracle')) return 'oracle'; + if (v.includes('kali')) return 'kali'; + return ''; +}; + +type DistroAvatarProps = { host: Host; fallback: string; className?: string }; + +export const DistroAvatar: React.FC = ({ host, fallback, className }) => { + const distro = (host.distro || '').toLowerCase(); + const logo = DISTRO_LOGOS[distro]; + const [errored, setErrored] = React.useState(false); + const bg = DISTRO_COLORS[distro] || DISTRO_COLORS.default; + + if (logo && !errored) { + return ( +
+ {host.distro setErrored(true)} + /> +
+ ); + } + + return ( +
+ {fallback} +
+ ); +}; diff --git a/components/GroupTreeItem.tsx b/components/GroupTreeItem.tsx new file mode 100644 index 000000000..91466e7a6 --- /dev/null +++ b/components/GroupTreeItem.tsx @@ -0,0 +1,104 @@ +import React, { useMemo } from 'react'; +import { ChevronRight, Folder, FolderOpen, FolderPlus, Plus } from 'lucide-react'; +import { GroupNode } from '../types'; +import { cn } from '../lib/utils'; +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from './ui/collapsible'; +import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from './ui/context-menu'; + +interface GroupTreeItemProps { + node: GroupNode; + depth: number; + expandedPaths: Set; + onToggle: (path: string) => void; + onSelectGroup: (path: string) => void; + selectedGroup: string | null; + onEditGroup: (path: string) => void; + onNewHost: (path: string) => void; + onNewSubfolder: (path: string) => void; +} + +export const GroupTreeItem: React.FC = ({ + node, + depth, + expandedPaths, + onToggle, + onSelectGroup, + selectedGroup, + onEditGroup, + onNewHost, + onNewSubfolder, +}) => { + const isExpanded = expandedPaths.has(node.path); + const hasChildren = node.children && Object.keys(node.children).length > 0; + const paddingLeft = `${depth * 12 + 12}px`; + const isSelected = selectedGroup === node.path; + + const childNodes = useMemo(() => { + return node.children + ? (Object.values(node.children) as unknown as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)) + : []; + }, [node.children]); + + return ( + onToggle(node.path)}> + + + +
onSelectGroup(node.path)} + > +
+ {hasChildren && ( +
+ +
+ )} +
+
+ {isExpanded ? : } +
+ {node.name} + {node.hosts.length > 0 && ( + + {node.hosts.length} + + )} +
+
+
+ + onNewHost(node.path)}> + New Host + + onNewSubfolder(node.path)}> + New Subfolder + + +
+ + {hasChildren && ( + + {childNodes.map((child) => ( + + ))} + + )} +
+ ); +}; diff --git a/components/QuickSwitcher.tsx b/components/QuickSwitcher.tsx new file mode 100644 index 000000000..9a0cf084f --- /dev/null +++ b/components/QuickSwitcher.tsx @@ -0,0 +1,76 @@ +import React from 'react'; +import { Monitor } from 'lucide-react'; +import { Host } from '../types'; +import { Button } from './ui/button'; +import { Input } from './ui/input'; + +interface QuickSwitcherProps { + isOpen: boolean; + query: string; + results: Host[]; + onQueryChange: (value: string) => void; + onSelect: (host: Host) => void; + onClose: () => void; +} + +export const QuickSwitcher: React.FC = ({ + isOpen, + query, + results, + onQueryChange, + onSelect, + onClose, +}) => { + if (!isOpen) return null; + + return ( +
{ if (e.target === e.currentTarget) onClose(); }} + > +
+
+ onQueryChange(e.target.value)} + placeholder="Search hosts or tabs..." + className="h-12 text-sm bg-secondary border-primary/50 focus-visible:ring-primary" + /> +
⌘K
+
+
+
+ Recent connections +
+ + +
+
+
+ {results.length > 0 ? results.map(host => ( +
{ e.stopPropagation(); onSelect(host); }} + > +
+
+ +
+
+
{host.label}
+
{host.username}@{host.hostname}
+
+
+
{host.group || 'Personal'}
+
+ )) : ( +
No matches. Start typing to search.
+ )} +
+
+
+
+ ); +}; diff --git a/components/SftpView.tsx b/components/SftpView.tsx new file mode 100644 index 000000000..9cc97a179 --- /dev/null +++ b/components/SftpView.tsx @@ -0,0 +1,403 @@ +import React, { useMemo, useState } from 'react'; +import { Badge } from './ui/badge'; +import { Button } from './ui/button'; +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from './ui/dialog'; +import { Input } from './ui/input'; +import { cn } from '../lib/utils'; +import { Host, RemoteFile } from '../types'; +import { DistroAvatar } from './DistroAvatar'; +import { FileCode, Folder, HardDrive, Monitor, Plus, X } from 'lucide-react'; + +type FileItem = RemoteFile & { kind?: string }; +type SftpPaneTab = { id: string; label: string; isLocal: boolean; hostId?: string; path: string; filter: string; status?: 'idle' | 'connecting' | 'connected' }; +type Breadcrumb = { label: string; path: string }; + +const LOCAL_FILE_MAP: Record = { + "/": [ + { name: "Applications", type: "directory", size: "--", lastModified: "--", kind: "folder" }, + { name: "Users", type: "directory", size: "--", lastModified: "--", kind: "folder" }, + ], + "/Users": [ + { name: "chenqi", type: "directory", size: "--", lastModified: "Dec 27, 2025 9:10 AM", kind: "folder" }, + ], + "/Users/chenqi": [ + { name: "Documents", type: "directory", size: "--", lastModified: "Dec 12, 2025 10:18 AM", kind: "folder" }, + { name: "Downloads", type: "directory", size: "--", lastModified: "Dec 17, 2025 3:40 AM", kind: "folder" }, + { name: "Pictures", type: "directory", size: "--", lastModified: "Jul 19, 2025 10:52 PM", kind: "folder" }, + { name: "Projects", type: "directory", size: "--", lastModified: "Dec 3, 2025 2:22 PM", kind: "folder" }, + { name: "notes.txt", type: "file", size: "3.2 KB", lastModified: "Nov 2, 2025 9:12 PM", kind: "txt" }, + ], + "/Users/chenqi/Downloads": [ + { name: "archive.zip", type: "file", size: "128 MB", lastModified: "Dec 2, 2025 11:12 PM", kind: "zip" }, + { name: "release", type: "directory", size: "--", lastModified: "Dec 1, 2025 5:00 PM", kind: "folder" }, + ], + "/Users/chenqi/Projects": [ + { name: "nebula-ssh", type: "directory", size: "--", lastModified: "Dec 27, 2025 9:10 AM", kind: "folder" }, + { name: "readme.md", type: "file", size: "7.2 KB", lastModified: "Nov 4, 2025 8:12 AM", kind: "md" }, + ], + "/Users/chenqi/Projects/nebula-ssh": [ + { name: "src", type: "directory", size: "--", lastModified: "Dec 18, 2025 12:12 PM", kind: "folder" }, + { name: "package.json", type: "file", size: "2.4 KB", lastModified: "Dec 18, 2025 12:12 PM", kind: "json" }, + { name: "README.md", type: "file", size: "4.1 KB", lastModified: "Nov 30, 2025 9:40 AM", kind: "md" }, + ], +}; + +const REMOTE_FILE_MAP: Record = { + "/": [ + { name: "root", type: "directory", size: "--", lastModified: "--", kind: "folder" }, + { name: "var", type: "directory", size: "--", lastModified: "--", kind: "folder" }, + { name: "etc", type: "directory", size: "--", lastModified: "--", kind: "folder" }, + { name: "opt", type: "directory", size: "--", lastModified: "--", kind: "folder" }, + ], + "/root": [ + { name: "deploy.sh", type: "file", size: "21.3 KB", lastModified: "Sep 28, 2025 3:42 PM", kind: "sh" }, + { name: "clean.sh", type: "file", size: "1.6 KB", lastModified: "Sep 28, 2025 3:46 PM", kind: "sh" }, + { name: "update.sh", type: "file", size: "498 Bytes", lastModified: "Nov 17, 2025 10:20 PM", kind: "sh" }, + { name: "notes", type: "directory", size: "--", lastModified: "Sep 15, 2025 10:20 PM", kind: "folder" }, + ], + "/root/notes": [ + { name: "todo.md", type: "file", size: "1.2 KB", lastModified: "Sep 10, 2025 8:11 PM", kind: "md" }, + { name: "deploy-checklist.md", type: "file", size: "2.4 KB", lastModified: "Sep 9, 2025 6:05 PM", kind: "md" }, + ], + "/var": [ + { name: "log", type: "directory", size: "--", lastModified: "Aug 1, 2025 12:00 PM", kind: "folder" }, + { name: "www", type: "directory", size: "--", lastModified: "Jul 1, 2025 7:32 PM", kind: "folder" }, + ], + "/var/log": [ + { name: "syslog", type: "file", size: "14.2 MB", lastModified: "Dec 17, 2025 7:11 PM", kind: "log" }, + { name: "kern.log", type: "file", size: "2.9 MB", lastModified: "Dec 17, 2025 7:07 PM", kind: "log" }, + ], + "/etc": [ + { name: "nginx", type: "directory", size: "--", lastModified: "Nov 1, 2025 4:20 PM", kind: "folder" }, + { name: "ssh", type: "directory", size: "--", lastModified: "Oct 12, 2025 11:20 AM", kind: "folder" }, + { name: "timezone", type: "file", size: "122 Bytes", lastModified: "Oct 2, 2025 9:02 AM", kind: "conf" }, + ], + "/etc/nginx": [ + { name: "nginx.conf", type: "file", size: "3.4 KB", lastModified: "Nov 1, 2025 4:20 PM", kind: "conf" }, + { name: "sites-enabled", type: "directory", size: "--", lastModified: "Nov 1, 2025 4:20 PM", kind: "folder" }, + ], + "/etc/ssh": [ + { name: "sshd_config", type: "file", size: "2.1 KB", lastModified: "Oct 12, 2025 11:21 AM", kind: "conf" }, + { name: "ssh_config", type: "file", size: "1.1 KB", lastModified: "Oct 12, 2025 11:19 AM", kind: "conf" }, + ], +}; + +const breadcrumbForPath = (path: string): Breadcrumb[] => { + if (path === '/') return []; + const parts = path.split('/').filter(Boolean); + return parts.map((part, idx) => ({ + label: part, + path: '/' + parts.slice(0, idx + 1).join('/'), + })); +}; + +const parentForPath = (path: string) => { + if (path === '/') return '/'; + const parts = path.split('/').filter(Boolean); + parts.pop(); + return parts.length ? `/${parts.join('/')}` : '/'; +}; + +const applyFileFilter = (items: FileItem[], filter: string) => { + const term = filter.trim().toLowerCase(); + if (!term) return items; + return items.filter(item => item.name === '..' || item.name.toLowerCase().includes(term)); +}; + +const getEntriesForTab = (tab: SftpPaneTab | null) => { + if (!tab) return []; + const map: Record = tab.isLocal ? LOCAL_FILE_MAP : REMOTE_FILE_MAP; + const files: FileItem[] = map[tab.path] || []; + const parentEntry: FileItem = { name: '..', type: 'directory', size: '--', lastModified: '--', kind: 'folder' }; + const withParent = tab.path === '/' ? files : [parentEntry, ...files]; + return applyFileFilter(withParent, tab.filter); +}; + +const formatKind = (item: FileItem) => { + if (item.type === 'directory') return 'folder'; + if (item.kind) return item.kind; + const ext = item.name.split('.').pop(); + return ext ? ext.toLowerCase() : 'file'; +}; + +interface SftpViewProps { + hosts: Host[]; + isActive: boolean; +} + +export const SftpView: React.FC = ({ hosts, isActive }) => { + const [sftpLeftTab, setSftpLeftTab] = useState({ id: 'local-default', label: 'Local', isLocal: true, hostId: 'local', path: '/Users/chenqi', filter: '' }); + const [sftpRightTab, setSftpRightTab] = useState(null); + const [sftpHostModalSide, setSftpHostModalSide] = useState<'left' | 'right' | null>(null); + const [sftpHostPickerSearch, setSftpHostPickerSearch] = useState(''); + + const filteredSftpHosts = useMemo(() => { + const term = sftpHostPickerSearch.trim().toLowerCase(); + return hosts + .filter(h => { + if (!term) return true; + return ( + h.label.toLowerCase().includes(term) || + h.hostname.toLowerCase().includes(term) || + (h.group || '').toLowerCase().includes(term) + ); + }) + .sort((a, b) => a.label.localeCompare(b.label)); + }, [hosts, sftpHostPickerSearch]); + + const leftEntries = useMemo(() => getEntriesForTab(sftpLeftTab), [sftpLeftTab]); + const rightEntries = useMemo(() => getEntriesForTab(sftpRightTab), [sftpRightTab]); + const leftBreadcrumbs = useMemo(() => breadcrumbForPath(sftpLeftTab?.path || '/'), [sftpLeftTab]); + const rightBreadcrumbs = useMemo(() => breadcrumbForPath(sftpRightTab?.path || '/'), [sftpRightTab]); + + const updateTabField = (side: 'left' | 'right', updater: (tab: SftpPaneTab) => Partial) => { + if (side === 'left') setSftpLeftTab(prev => ({ ...prev, ...updater(prev) })); + else setSftpRightTab(prev => prev ? ({ ...prev, ...updater(prev) }) : prev); + }; + + const openEntry = (side: 'left' | 'right', tab: SftpPaneTab | null, item: FileItem) => { + if (!tab || item.type !== 'directory') return; + if (item.name === '..') { + const parent = parentForPath(tab.path); + updateTabField(side, () => ({ path: parent })); + return; + } + const next = tab.path === '/' ? `/${item.name}` : `${tab.path}/${item.name}`; + updateTabField(side, () => ({ path: next })); + }; + + const selectHostForSide = (side: 'left' | 'right', host: Host | 'local') => { + if (host === 'local') { + const tab = { id: `tab-${side}-${crypto.randomUUID()}`, label: 'Local', isLocal: true, hostId: 'local', path: '/Users/chenqi', filter: '', status: 'connected' } as SftpPaneTab; + side === 'left' ? setSftpLeftTab(tab) : setSftpRightTab(tab); + } else { + const tab = { id: `tab-${side}-${crypto.randomUUID()}`, label: host.label, isLocal: false, hostId: host.id, path: '/root', filter: '', status: 'connected' } as SftpPaneTab; + side === 'left' ? setSftpLeftTab(tab) : setSftpRightTab(tab); + } + setSftpHostModalSide(null); + setSftpHostPickerSearch(''); + }; + + return ( +
+
+
+ {/* Left pane */} +
+
+
+ + {sftpLeftTab?.label || 'Local / Hosts'} +
+ + {sftpLeftTab && ( +
+ updateTabField('left', () => ({ filter: e.target.value }))} + placeholder="Filter" + className="h-9 w-44 bg-background/60" + /> + +
+ )} +
+ +
+ / + {leftBreadcrumbs.map((crumb, idx) => ( + + + {idx < leftBreadcrumbs.length - 1 && /} + + ))} +
+ +
+
+ Name + Date Modified + Size + Kind +
+
+ {leftEntries.map((file, idx) => ( +
openEntry('left', sftpLeftTab, file)} + > +
+
+ {file.type === 'directory' ? : } +
+ {file.name} +
+ {file.lastModified} + {file.size} + {formatKind(file)} +
+ ))} +
+
+ {leftEntries.length} items + {sftpLeftTab?.path} +
+
+
+ + {/* Right pane */} +
+
+
+ + {sftpRightTab?.label || 'Remote'} +
+ + {sftpRightTab && ( +
+ updateTabField('right', () => ({ filter: e.target.value }))} + placeholder="Filter remote" + className="h-9 w-44 bg-background/60" + /> + +
+ )} +
+ + {sftpRightTab ? ( + <> +
+ / + {rightBreadcrumbs.map((crumb, idx) => ( + + + {idx < rightBreadcrumbs.length - 1 && /} + + ))} +
+
+
+ Name + Date Modified + Size + Kind +
+
+ {rightEntries.map((file, idx) => ( +
openEntry('right', sftpRightTab, file)} + > +
+
+ {file.type === 'directory' ? : } +
+ {file.name} +
+ {file.lastModified} + {file.size} + {formatKind(file)} +
+ ))} +
+
+ {rightEntries.length} items + {sftpRightTab?.hostId || 'No host'} +
+
+ + ) : ( +
+
+ +
+
Select a host to start
+
Use “Add host” to open a remote in this pane.
+ +
+ )} +
+
+
+ + setSftpHostModalSide(open ? (sftpHostModalSide || 'left') : null)}> + + + Select Host + Pick a host for the {sftpHostModalSide === 'left' ? 'left' : 'right'} pane. + +
+ setSftpHostPickerSearch(e.target.value)} + placeholder="Search hosts" + className="h-10" + /> +
selectHostForSide(sftpHostModalSide || 'left', 'local')} + > +
+
L
+
+
Local filesystem
+
/Users/chenqi
+
+
+ Local +
+
+ {filteredSftpHosts.map(host => ( +
selectHostForSide(sftpHostModalSide || 'left', host)} + > +
+ +
+
{host.label}
+
{host.username}@{host.hostname}
+
{host.group || 'Personal'}
+
+
+ Host +
+ ))} + {filteredSftpHosts.length === 0 && ( +
+ No matching hosts +
+ )} +
+
+
+
+
+ ); +}; diff --git a/components/TerminalLayer.tsx b/components/TerminalLayer.tsx new file mode 100644 index 000000000..495435190 --- /dev/null +++ b/components/TerminalLayer.tsx @@ -0,0 +1,439 @@ +import React, { useEffect, useMemo, useRef, useState } from 'react'; +import { cn } from '../lib/utils'; +import Terminal from './Terminal'; +import AssistantPanel from './AssistantPanel'; +import { Host, SSHKey, Snippet, TerminalSession, TerminalTheme, Workspace, WorkspaceNode } from '../types'; + +type WorkspaceRect = { x: number; y: number; w: number; h: number }; + +type SplitHint = { + direction: 'horizontal' | 'vertical'; + position: 'left' | 'right' | 'top' | 'bottom'; + targetSessionId?: string; + rect?: { x: number; y: number; w: number; h: number }; +} | null; + +type ResizerHandle = { + id: string; + splitId: string; + index: number; + direction: 'vertical' | 'horizontal'; + rect: { x: number; y: number; w: number; h: number }; + splitArea: { w: number; h: number }; +}; + +interface TerminalLayerProps { + hosts: Host[]; + keys: SSHKey[]; + snippets: Snippet[]; + sessions: TerminalSession[]; + workspaces: Workspace[]; + activeTabId: string; + draggingSessionId: string | null; + isVisible: boolean; + terminalTheme: TerminalTheme; + showAssistant: boolean; + onCloseSession: (sessionId: string, e?: React.MouseEvent) => void; + onUpdateSessionStatus: (sessionId: string, status: TerminalSession['status']) => void; + onUpdateHostDistro: (hostId: string, distro: string) => void; + onCreateWorkspaceFromSessions: (baseSessionId: string, joiningSessionId: string, hint: Exclude) => void; + onAddSessionToWorkspace: (workspaceId: string, sessionId: string, hint: Exclude) => void; + onUpdateSplitSizes: (workspaceId: string, splitId: string, sizes: number[]) => void; + onSetDraggingSessionId: (id: string | null) => void; +} + +export const TerminalLayer: React.FC = ({ + hosts, + keys, + snippets, + sessions, + workspaces, + activeTabId, + draggingSessionId, + isVisible, + terminalTheme, + showAssistant, + onCloseSession, + onUpdateSessionStatus, + onUpdateHostDistro, + onCreateWorkspaceFromSessions, + onAddSessionToWorkspace, + onUpdateSplitSizes, + onSetDraggingSessionId, +}) => { + const [workspaceArea, setWorkspaceArea] = useState<{ width: number; height: number }>({ width: 0, height: 0 }); + const workspaceOuterRef = useRef(null); + const workspaceInnerRef = useRef(null); + const workspaceOverlayRef = useRef(null); + const [dropHint, setDropHint] = useState(null); + const [focusedSessionId, setFocusedSessionId] = useState(null); + const [resizing, setResizing] = useState<{ + workspaceId: string; + splitId: string; + index: number; + direction: 'vertical' | 'horizontal'; + startSizes: number[]; + startArea: { w: number; h: number }; + startClient: { x: number; y: number }; + } | null>(null); + + const activeWorkspace = useMemo(() => workspaces.find(w => w.id === activeTabId), [workspaces, activeTabId]); + const activeSession = useMemo(() => sessions.find(s => s.id === activeTabId), [sessions, activeTabId]); + + const computeWorkspaceRects = (workspace?: Workspace, size?: { width: number; height: number }): Record => { + if (!workspace) return {} as Record; + const wTotal = size?.width || 1; + const hTotal = size?.height || 1; + const rects: Record = {}; + const walk = (node: WorkspaceNode, area: WorkspaceRect) => { + if (node.type === 'pane') { + rects[node.sessionId] = area; + return; + } + const isVertical = node.direction === 'vertical'; + const sizes = (node.sizes && node.sizes.length === node.children.length ? node.sizes : Array(node.children.length).fill(1)); + const total = sizes.reduce((acc, n) => acc + n, 0) || 1; + let offset = 0; + node.children.forEach((child, idx) => { + const share = sizes[idx] / total; + const childArea = isVertical + ? { x: area.x + area.w * offset, y: area.y, w: area.w * share, h: area.h } + : { x: area.x, y: area.y + area.h * offset, w: area.w, h: area.h * share }; + walk(child, childArea); + offset += share; + }); + }; + walk(workspace.root, { x: 0, y: 0, w: wTotal, h: hTotal }); + return rects; + }; + + const activeWorkspaceRects = useMemo>( + () => computeWorkspaceRects(activeWorkspace, workspaceArea), + [activeWorkspace, workspaceArea] + ); + + useEffect(() => { + if (!workspaceInnerRef.current) return; + const el = workspaceInnerRef.current; + const updateSize = () => setWorkspaceArea({ width: el.clientWidth, height: el.clientHeight }); + updateSize(); + const observer = new ResizeObserver(() => updateSize()); + observer.observe(el); + return () => observer.disconnect(); + }, [activeWorkspace]); + + const collectResizers = (workspace?: Workspace, size?: { width: number; height: number }): ResizerHandle[] => { + if (!workspace || !size?.width || !size?.height) return []; + const resizers: ResizerHandle[] = []; + const walk = (node: WorkspaceNode, area: { x: number; y: number; w: number; h: number }) => { + if (node.type === 'pane') return; + const isVertical = node.direction === 'vertical'; + const sizes = (node.sizes && node.sizes.length === node.children.length ? node.sizes : Array(node.children.length).fill(1)); + const total = sizes.reduce((acc, n) => acc + n, 0) || 1; + let offset = 0; + node.children.forEach((child, idx) => { + const share = sizes[idx] / total; + const childArea = isVertical + ? { x: area.x + area.w * offset, y: area.y, w: area.w * share, h: area.h } + : { x: area.x, y: area.y + area.h * offset, w: area.w, h: area.h * share }; + if (idx < node.children.length - 1) { + const boundary = isVertical ? childArea.x + childArea.w : childArea.y + childArea.h; + const rect = isVertical + ? { x: boundary - 2, y: area.y, w: 4, h: area.h } + : { x: area.x, y: boundary - 2, w: area.w, h: 4 }; + resizers.push({ + id: `${node.id}-${idx}`, + splitId: node.id, + index: idx, + direction: node.direction, + rect, + splitArea: { w: area.w, h: area.h }, + }); + } + walk(child, childArea); + offset += share; + }); + }; + walk(workspace.root, { x: 0, y: 0, w: size.width, h: size.height }); + return resizers; + }; + + const activeResizers = useMemo(() => collectResizers(activeWorkspace, workspaceArea), [activeWorkspace, workspaceArea]); + + const computeSplitHint = (e: React.DragEvent): SplitHint => { + const surface = workspaceOverlayRef.current || workspaceInnerRef.current || workspaceOuterRef.current; + if (!surface || !workspaceArea.width || !workspaceArea.height) return null; + const rect = surface.getBoundingClientRect(); + const localX = e.clientX - rect.left; + const localY = e.clientY - rect.top; + if (localX < 0 || localX > rect.width || localY < 0 || localY > rect.height) return null; + + let targetSessionId: string | undefined; + let targetRect: WorkspaceRect | undefined; + const workspaceEntries = Object.entries(activeWorkspaceRects) as Array<[string, WorkspaceRect]>; + workspaceEntries.forEach(([sessionId, area]) => { + if (targetSessionId) return; + if ( + localX >= area.x && + localX <= area.x + area.w && + localY >= area.y && + localY <= area.y + area.h + ) { + targetSessionId = sessionId; + targetRect = area; + } + }); + + const baseRect: WorkspaceRect = targetRect || { x: 0, y: 0, w: rect.width, h: rect.height }; + const relX = (localX - baseRect.x) / baseRect.w; + const relY = (localY - baseRect.y) / baseRect.h; + + const prefersVertical = Math.abs(relX - 0.5) > Math.abs(relY - 0.5); + const direction = prefersVertical ? 'vertical' : 'horizontal'; + const position = prefersVertical + ? (relX < 0.5 ? 'left' : 'right') + : (relY < 0.5 ? 'top' : 'bottom'); + + const previewRect: WorkspaceRect = { ...baseRect }; + if (direction === 'vertical') { + previewRect.w = baseRect.w / 2; + previewRect.x = position === 'left' ? baseRect.x : baseRect.x + baseRect.w / 2; + } else { + previewRect.h = baseRect.h / 2; + previewRect.y = position === 'top' ? baseRect.y : baseRect.y + baseRect.h / 2; + } + + return { + direction, + position, + targetSessionId, + rect: previewRect, + }; + }; + + useEffect(() => { + if (!resizing) return; + const onMove = (e: MouseEvent) => { + const dimension = resizing.direction === 'vertical' ? resizing.startArea.w : resizing.startArea.h; + if (dimension <= 0) return; + const total = resizing.startSizes.reduce((acc, n) => acc + n, 0) || 1; + const pxSizes = resizing.startSizes.map(s => (s / total) * dimension); + const i = resizing.index; + const delta = (resizing.direction === 'vertical' ? e.clientX - resizing.startClient.x : e.clientY - resizing.startClient.y); + let a = pxSizes[i] + delta; + let b = pxSizes[i + 1] - delta; + const minPx = Math.min(120, dimension / 2); + if (a < minPx) { + const diff = minPx - a; + a = minPx; + b -= diff; + } + if (b < minPx) { + const diff = minPx - b; + b = minPx; + a -= diff; + } + const newPxSizes = [...pxSizes]; + newPxSizes[i] = Math.max(minPx, a); + newPxSizes[i + 1] = Math.max(minPx, b); + const totalPx = newPxSizes.reduce((acc, n) => acc + n, 0) || 1; + const newSizes = newPxSizes.map(n => n / totalPx); + onUpdateSplitSizes(resizing.workspaceId, resizing.splitId, newSizes); + }; + const onUp = () => setResizing(null); + window.addEventListener('mousemove', onMove); + window.addEventListener('mouseup', onUp); + return () => { + window.removeEventListener('mousemove', onMove); + window.removeEventListener('mouseup', onUp); + }; + }, [resizing, onUpdateSplitSizes]); + + const handleWorkspaceDrop = (e: React.DragEvent) => { + const draggedSessionId = e.dataTransfer.getData('session-id'); + if (!draggedSessionId) return; + e.preventDefault(); + const hint = computeSplitHint(e); + setDropHint(null); + onSetDraggingSessionId(null); + if (!hint) return; + + if (activeWorkspace) { + const draggedSession = sessions.find(s => s.id === draggedSessionId); + if (!draggedSession || draggedSession.workspaceId) return; + onAddSessionToWorkspace(activeWorkspace.id, draggedSessionId, hint); + return; + } + + if (activeSession) { + onCreateWorkspaceFromSessions(activeSession.id, draggedSessionId, hint); + } + }; + + const findSplitNode = (node: WorkspaceNode, splitId: string): WorkspaceNode | null => { + if (node.type === 'split') { + if (node.id === splitId) return node; + for (const child of node.children) { + const found = findSplitNode(child, splitId); + if (found) return found; + } + } + return null; + }; + + const isTerminalLayerVisible = isVisible || !!draggingSessionId; + + return ( +
+ {draggingSessionId && ( +
{ + if (!e.dataTransfer.types.includes('session-id')) return; + e.preventDefault(); + e.stopPropagation(); + const hint = computeSplitHint(e); + setDropHint(hint); + }} + onDragLeave={(e) => { + if (!e.dataTransfer.types.includes('session-id')) return; + setDropHint(null); + }} + onDrop={(e) => { + e.preventDefault(); + e.stopPropagation(); + handleWorkspaceDrop(e); + }} + > + {dropHint && ( +
+
+
+ )} +
+ )} +
+ {sessions.map(session => { + const host = hosts.find(h => h.id === session.hostId); + if (!host) return null; + const inActiveWorkspace = !!activeWorkspace && session.workspaceId === activeWorkspace.id; + const isActiveSolo = activeTabId === session.id && !activeWorkspace && isTerminalLayerVisible; + const isVisible = (inActiveWorkspace || isActiveSolo) && isTerminalLayerVisible; + const rect = inActiveWorkspace ? activeWorkspaceRects[session.id] : null; + const isFocused = focusedSessionId === session.id && isVisible; + + const layoutStyle = rect + ? { + left: `${rect.x}px`, + top: `${rect.y}px`, + width: `${rect.w}px`, + height: `${rect.h}px`, + } + : { left: 0, top: 0, width: '100%', height: '100%' }; + + const style: React.CSSProperties = isFocused + ? { + ...layoutStyle, + outline: '2px solid hsl(var(--primary))', + outlineOffset: -4, + boxShadow: 'inset 0 0 0 1px rgba(255,255,255,0.12)', + } + : { ...layoutStyle }; + + if (!isVisible) { + style.display = 'none'; + } + + return ( +
setFocusedSessionId(session.id)} + > + onCloseSession(session.id)} + onStatusChange={(next) => onUpdateSessionStatus(session.id, next)} + onSessionExit={() => onUpdateSessionStatus(session.id, 'disconnected')} + onOsDetected={(hid, distro) => onUpdateHostDistro(hid, distro)} + /> +
+ ); + })} + {activeResizers.map(handle => ( +
{ + e.preventDefault(); + e.stopPropagation(); + const ws = activeWorkspace; + if (!ws) return; + const split = findSplitNode(ws.root, handle.splitId); + const childCount = split && split.type === 'split' ? split.children.length : 0; + const sizes = split && split.type === 'split' && split.sizes && split.sizes.length === childCount + ? split.sizes + : Array(childCount).fill(1); + setResizing({ + workspaceId: ws.id, + splitId: handle.splitId, + index: handle.index, + direction: handle.direction, + startSizes: sizes.length ? sizes : [1, 1], + startArea: handle.splitArea, + startClient: { x: e.clientX, y: e.clientY }, + }); + }} + > +
+
+ ))} +
+ {showAssistant && ( +
+ +
+ )} +
+ ); +}; diff --git a/components/TopTabs.tsx b/components/TopTabs.tsx new file mode 100644 index 000000000..0abb0c0f5 --- /dev/null +++ b/components/TopTabs.tsx @@ -0,0 +1,173 @@ +import React from 'react'; +import { TerminalSquare, Shield, Folder, LayoutGrid, Plus, Bell, User, Sun, Moon, X } from 'lucide-react'; +import { TerminalSession, Workspace } from '../types'; +import { Button } from './ui/button'; +import { cn } from '../lib/utils'; +import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from './ui/context-menu'; + +interface TopTabsProps { + theme: 'dark' | 'light'; + isVaultActive: boolean; + isSftpActive: boolean; + activeTabId: string; + sessions: TerminalSession[]; + orphanSessions: TerminalSession[]; + workspaces: Workspace[]; + draggingSessionId: string | null; + isMacClient: boolean; + onSelectTab: (id: string) => void; + onCloseSession: (sessionId: string, e?: React.MouseEvent) => void; + onRenameWorkspace: (workspaceId: string) => void; + onCloseWorkspace: (workspaceId: string) => void; + onOpenQuickSwitcher: () => void; + onToggleTheme: () => void; + onStartSessionDrag: (sessionId: string) => void; + onEndSessionDrag: () => void; +} + +const sessionStatusDot = (status: TerminalSession['status']) => { + const tone = status === 'connected' + ? "bg-emerald-400" + : status === 'connecting' + ? "bg-amber-400" + : "bg-rose-500"; + return ; +}; + +export const TopTabs: React.FC = ({ + theme, + isVaultActive, + isSftpActive, + activeTabId, + sessions, + orphanSessions, + workspaces, + draggingSessionId, + isMacClient, + onSelectTab, + onCloseSession, + onRenameWorkspace, + onCloseWorkspace, + onOpenQuickSwitcher, + onToggleTheme, + onStartSessionDrag, + onEndSessionDrag, +}) => { + return ( +
+
+
onSelectTab('vault')} + className={cn( + "h-8 px-3 rounded-md border text-xs font-semibold cursor-pointer flex items-center gap-2 app-no-drag", + isVaultActive ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground" + )} + > + Vaults +
+
onSelectTab('sftp')} + className={cn( + "h-8 px-3 rounded-md border text-xs font-semibold cursor-pointer flex items-center gap-2 app-no-drag", + isSftpActive ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground" + )} + > + SFTP +
+ {orphanSessions.map(session => ( +
onSelectTab(session.id)} + draggable + onDragStart={(e) => { + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('session-id', session.id); + onStartSessionDrag(session.id); + }} + onDragEnd={() => onEndSessionDrag()} + className={cn( + "h-8 pl-3 pr-2 min-w-[140px] max-w-[240px] rounded-md border text-xs font-semibold cursor-pointer flex items-center justify-between gap-2 app-no-drag", + activeTabId === session.id ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground", + draggingSessionId === session.id ? "opacity-70" : "" + )} + > +
+ + {session.hostLabel} +
{sessionStatusDot(session.status)}
+
+ +
+ ))} + {workspaces.map(workspace => { + const paneCount = sessions.filter(s => s.workspaceId === workspace.id).length; + const isActive = activeTabId === workspace.id; + return ( + + +
onSelectTab(workspace.id)} + className={cn( + "h-8 pl-3 pr-2 min-w-[150px] max-w-[260px] rounded-md border text-xs font-semibold cursor-pointer flex items-center justify-between gap-2 app-no-drag", + isActive ? "bg-primary/20 border-primary/60 text-foreground" : "border-border/60 text-muted-foreground hover:border-primary/40 hover:text-foreground" + )} + > +
+ + {workspace.title} +
+
+ {paneCount} +
+
+
+ + onRenameWorkspace(workspace.id)}> + Rename + + onCloseWorkspace(workspace.id)}> + Close + + +
+ ); + })} + +
+ + + +
+
+
+ ); +}; diff --git a/components/VaultView.tsx b/components/VaultView.tsx new file mode 100644 index 000000000..476954c90 --- /dev/null +++ b/components/VaultView.tsx @@ -0,0 +1,466 @@ +import React, { useMemo, useState } from 'react'; +import { + Activity, + BookMarked, + ChevronRight, + Command, + FolderPlus, + Edit2, + FileCode, + Grid, + Heart, + Key, + LayoutGrid, + Plug, + Plus, + Search, + Settings, + Star, + Trash2, +} from 'lucide-react'; +import { Host, SSHKey, Snippet, GroupNode, TerminalSession } from '../types'; +import { normalizeDistroId, DistroAvatar } from './DistroAvatar'; +import SnippetsManager from './SnippetsManager'; +import KeyManager from './KeyManager'; +import PortForwarding from './PortForwarding'; +import { Button } from './ui/button'; +import { Input } from './ui/input'; +import { Popover, PopoverContent, PopoverTrigger } from './ui/popover'; +import { cn } from '../lib/utils'; +import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from './ui/context-menu'; +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from './ui/dialog'; +import { Label } from './ui/label'; + +type VaultSection = 'hosts' | 'keys' | 'snippets' | 'port'; + +interface VaultViewProps { + isActive: boolean; + hosts: Host[]; + keys: SSHKey[]; + snippets: Snippet[]; + snippetPackages: string[]; + customGroups: string[]; + sessions: TerminalSession[]; + showAssistant: boolean; + onToggleAssistant: () => void; + onOpenSettings: () => void; + onOpenQuickSwitcher: () => void; + onNewHost: () => void; + onEditHost: (host: Host) => void; + onDeleteHost: (id: string) => void; + onConnect: (host: Host) => void; + onUpdateHosts: (hosts: Host[]) => void; + onUpdateKeys: (keys: SSHKey[]) => void; + onUpdateSnippets: (snippets: Snippet[]) => void; + onUpdateSnippetPackages: (pkgs: string[]) => void; + onUpdateCustomGroups: (groups: string[]) => void; +} + +const sanitizeHost = (host: Host): Host => { + const cleanHostname = (host.hostname || '').split(/\s+/)[0]; + const cleanDistro = normalizeDistroId(host.distro); + return { ...host, hostname: cleanHostname, distro: cleanDistro }; +}; + +export const VaultView: React.FC = ({ + isActive, + hosts, + keys, + snippets, + snippetPackages, + customGroups, + sessions, + showAssistant, + onToggleAssistant, + onOpenSettings, + onOpenQuickSwitcher, + onNewHost, + onEditHost, + onDeleteHost, + onConnect, + onUpdateHosts, + onUpdateKeys, + onUpdateSnippets, + onUpdateSnippetPackages, + onUpdateCustomGroups, +}) => { + const [currentSection, setCurrentSection] = useState('hosts'); + const [search, setSearch] = useState(''); + const [selectedGroupPath, setSelectedGroupPath] = useState(null); + const [isNewFolderOpen, setIsNewFolderOpen] = useState(false); + const [newFolderName, setNewFolderName] = useState(''); + const [targetParentPath, setTargetParentPath] = useState(null); + + const buildGroupTree = useMemo>(() => { + const root: Record = {}; + const insertPath = (path: string, host?: Host) => { + const parts = path.split('/').filter(Boolean); + let currentLevel = root; + let currentPath = ''; + parts.forEach((part, index) => { + currentPath = currentPath ? `${currentPath}/${part}` : part; + if (!currentLevel[part]) { + currentLevel[part] = { name: part, path: currentPath, children: {}, hosts: [] }; + } + if (host && index === parts.length - 1) currentLevel[part].hosts.push(host); + currentLevel = currentLevel[part].children; + }); + }; + customGroups.forEach(path => insertPath(path)); + hosts.forEach(host => insertPath(host.group || 'General', host)); + return root; + }, [hosts, customGroups]); + + const findGroupNode = (path: string | null): GroupNode | null => { + if (!path) return { name: 'root', path: '', children: buildGroupTree, hosts: [] } as any; + const parts = path.split('/').filter(Boolean); + let current: any = { children: buildGroupTree }; + for (const p of parts) { + current = current.children?.[p]; + if (!current) return null; + } + return current; + }; + + const displayedHosts = useMemo(() => { + let filtered = hosts; + if (selectedGroupPath) { + filtered = filtered.filter(h => (h.group || '') === selectedGroupPath); + } + if (search.trim()) { + const s = search.toLowerCase(); + filtered = filtered.filter(h => + h.label.toLowerCase().includes(s) || + h.hostname.toLowerCase().includes(s) || + h.tags.some(t => t.toLowerCase().includes(s)) + ); + } + return filtered; + }, [hosts, selectedGroupPath, search]); + + const displayedGroups = useMemo(() => { + if (!selectedGroupPath) { + return (Object.values(buildGroupTree) as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)); + } + const node = findGroupNode(selectedGroupPath); + if (!node || !node.children) return []; + return (Object.values(node.children) as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)); + }, [buildGroupTree, selectedGroupPath]); + + const submitNewFolder = () => { + if (!newFolderName.trim()) return; + const fullPath = targetParentPath ? `${targetParentPath}/${newFolderName.trim()}` : newFolderName.trim(); + onUpdateCustomGroups(Array.from(new Set([...customGroups, fullPath]))); + setIsNewFolderOpen(false); + }; + + const deleteGroupPath = (path: string) => { + const keepGroups = customGroups.filter(g => !(g === path || g.startsWith(path + '/'))); + const keepHosts = hosts.map(h => { + const g = h.group || ''; + if (g === path || g.startsWith(path + '/')) return { ...h, group: '' }; + return h; + }); + onUpdateCustomGroups(keepGroups); + onUpdateHosts(keepHosts); + if (selectedGroupPath && (selectedGroupPath === path || selectedGroupPath.startsWith(path + '/'))) { + setSelectedGroupPath(null); + } + }; + + const moveGroup = (sourcePath: string, targetParent: string | null) => { + const name = sourcePath.split('/').filter(Boolean).pop() || ''; + const newPath = targetParent ? `${targetParent}/${name}` : name; + if (newPath === sourcePath || newPath.startsWith(sourcePath + '/')) return; + const updatedGroups = customGroups.map(g => { + if (g === sourcePath) return newPath; + if (g.startsWith(sourcePath + '/')) return g.replace(sourcePath, newPath); + return g; + }); + const updatedHosts = hosts.map(h => { + const g = h.group || ''; + if (g === sourcePath) return { ...h, group: newPath }; + if (g.startsWith(sourcePath + '/')) return { ...h, group: g.replace(sourcePath, newPath) }; + return h; + }); + onUpdateCustomGroups(Array.from(new Set(updatedGroups))); + onUpdateHosts(updatedHosts); + if (selectedGroupPath && (selectedGroupPath === sourcePath || selectedGroupPath.startsWith(sourcePath + '/'))) { + setSelectedGroupPath(newPath); + } + }; + + const moveHostToGroup = (hostId: string, groupPath: string | null) => { + onUpdateHosts(hosts.map(h => h.id === hostId ? { ...h, group: groupPath || '' } : h)); + }; + + return ( +
+ {/* Sidebar */} +
+
+ netcatty logo +
+

Netcatty

+
+
+ +
+ + + + + + +
+ +
+ + +
+
+ + {/* Main Area */} +
+ {currentSection === 'hosts' && ( +
+
+
+ + setSearch(e.target.value)} /> +
+ +
+ + + + +
+
+ + + + + + + + + +
+
+
+ )} + +
+ {currentSection === 'hosts' && ( + <> +
+
+ + {selectedGroupPath && selectedGroupPath.split('/').filter(Boolean).map((part, idx, arr) => { + const crumbPath = arr.slice(0, idx + 1).join('/'); + const isLast = idx === arr.length - 1; + return ( + + › + + + ); + })} +
+ {displayedGroups.length > 0 && ( + <> +
+

Groups

+
{displayedGroups.length} total
+
+ + )} +
{ e.preventDefault(); }} + onDrop={(e) => { + e.preventDefault(); + e.stopPropagation(); + const hostId = e.dataTransfer.getData('host-id'); + const groupPath = e.dataTransfer.getData('group-path'); + if (hostId) moveHostToGroup(hostId, selectedGroupPath); + if (groupPath && selectedGroupPath !== null) moveGroup(groupPath, selectedGroupPath); + }}> + {displayedGroups.map(node => ( + + +
e.dataTransfer.setData('group-path', node.path)} + onDoubleClick={() => setSelectedGroupPath(node.path)} + onClick={() => setSelectedGroupPath(node.path)} + onDragOver={(e) => { e.preventDefault(); e.stopPropagation(); }} + onDrop={(e) => { + e.preventDefault(); + e.stopPropagation(); + const hostId = e.dataTransfer.getData('host-id'); + const groupPath = e.dataTransfer.getData('group-path'); + if (hostId) moveHostToGroup(hostId, node.path); + if (groupPath) moveGroup(groupPath, node.path); + }} + > +
+
+ +
+
+
{node.name}
+
{node.hosts.length} Hosts
+
+
+
+
+ + { setTargetParentPath(node.path); setIsNewFolderOpen(true); }}> + New Subgroup + + deleteGroupPath(node.path)}> + Delete Group + + +
+ ))} +
+
+ +
+
+

Hosts

+
+ {displayedHosts.length} entries +
{sessions.length} live
+
+
+
+ {displayedHosts.map((host) => { + const safeHost = sanitizeHost(host); + const distroBadge = { text: (safeHost.os || 'L')[0].toUpperCase(), label: safeHost.distro || safeHost.os || 'Linux' }; + return ( + + +
{ + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('host-id', host.id); + }} + onClick={() => onConnect(safeHost)} + > +
+ +
+
{safeHost.label}
+
{safeHost.username}@{safeHost.hostname}
+ {safeHost.distro &&
{distroBadge.label}
} +
+
+
+
+ + onConnect(host)}> + Connect + + onEditHost(host)}> + Edit + + onDeleteHost(host.id)}> + Delete + + +
+ ); + })} + {displayedHosts.length === 0 && ( +
+
+
+ +
+
No results found
+
Adjust your search or create a new host.
+
+ + +
+
+
+ )} +
+
+ + )} + + {currentSection === 'keys' && ( + onUpdateKeys([...keys, k])} onDelete={id => onUpdateKeys(keys.filter(k => k.id !== id))} /> + )} + {currentSection === 'snippets' && ( + onUpdateSnippets(snippets.find(ex => ex.id === s.id) ? snippets.map(ex => ex.id === s.id ? s : ex) : [...snippets, s])} + onDelete={id => onUpdateSnippets(snippets.filter(s => s.id !== id))} + /> + )} + {currentSection === 'port' && } +
+
+ + + + + {targetParentPath ? `Create Subfolder` : 'Create Root Group'} + Create a new group for organizing hosts. + +
+ + setNewFolderName(e.target.value)} placeholder="e.g. Production" autoFocus onKeyDown={e => e.key === 'Enter' && submitNewFolder()} /> + {targetParentPath &&

Parent: {targetParentPath}

} +
+ +
+
+
+ ); +}; diff --git a/lib/defaultData.ts b/lib/defaultData.ts new file mode 100644 index 000000000..6a425c434 --- /dev/null +++ b/lib/defaultData.ts @@ -0,0 +1,12 @@ +import { Host, Snippet } from '../types'; + +export const INITIAL_HOSTS: Host[] = [ + { id: '1', label: 'Production Web', hostname: '10.0.0.12', port: 22, username: 'ubuntu', group: 'AWS/Production', tags: ['prod', 'web'], os: 'linux' }, + { id: '2', label: 'DB Master', hostname: 'db-01.internal', port: 22, username: 'admin', group: 'AWS/Production', tags: ['prod', 'db'], os: 'linux' }, +]; + +export const INITIAL_SNIPPETS: Snippet[] = [ + { id: '1', label: 'Check Disk Space', command: 'df -h', tags: [] }, + { id: '2', label: 'Tail System Log', command: 'tail -f /var/log/syslog', tags: [] }, + { id: '3', label: 'Update Ubuntu', command: 'sudo apt update && sudo apt upgrade -y', tags: [] }, +]; diff --git a/lib/storageKeys.ts b/lib/storageKeys.ts new file mode 100644 index 000000000..8c4828a12 --- /dev/null +++ b/lib/storageKeys.ts @@ -0,0 +1,9 @@ +export const STORAGE_KEY_HOSTS = 'nebula_hosts_v1'; +export const STORAGE_KEY_KEYS = 'nebula_keys_v1'; +export const STORAGE_KEY_GROUPS = 'nebula_groups_v1'; +export const STORAGE_KEY_SNIPPETS = 'nebula_snippets_v1'; +export const STORAGE_KEY_SNIPPET_PACKAGES = 'nebula_snippet_packages_v1'; +export const STORAGE_KEY_THEME = 'nebula_theme_v1'; +export const STORAGE_KEY_COLOR = 'nebula_color_v1'; +export const STORAGE_KEY_SYNC = 'nebula_sync_v1'; +export const STORAGE_KEY_TERM_THEME = 'nebula_term_theme_v1';