/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; type TerminalLayerViewContext = Record; export function TerminalLayerView({ ctx }: { ctx: TerminalLayerViewContext }) { const { accentMode, activeResizers, activeSidePanelTab, activeTabId, activeTerminalCwd, activeWorkspace, AIChatPanelsHost, aiContextsByTabId, AIStateMaintenanceHost, AIStateProvider, Array, Button, cn, composeBarThemeColors, computeSplitHint, customAccent, draggingSessionId, dropHint, editorWordWrap, effectiveHosts, findSplitNode, focusedFontFamilyId, focusedFontFamilyOverridden, focusedFontSize, focusedFontSizeOverridden, focusedFontWeight, focusedFontWeightOverridden, focusedSessionId, focusedThemeOverridden, FolderTree, followAppTerminalTheme, fontSize, getTerminalCwd, handleAddKnownHost, handleAddSelectionToAI, handleBroadcastInput, handleCloseSession, handleCloseSidePanel, handleCommandExecuted, handleComposeSend, handleFontFamilyChangeForFocusedSession, handleFontFamilyResetForFocusedSession, handleFontSizeChangeForFocusedSession, handleFontSizeResetForFocusedSession, handleFontWeightChangeForFocusedSession, handleFontWeightResetForFocusedSession, handleOpenAI, handleOpenScripts, handleOpenSftp, handleOpenTheme, handleOsDetected, handlePendingTerminalSelectionConsumed, handlePendingUploadHandled, handleSessionExit, handleSftpInitialLocationApplied, handleSidePanelResizeStart, handleSnippetFromPanel, handleSnippetExecutorChange, handleStatusChange, handleTerminalCwdChange, handleTerminalDataCapture, handleTerminalFontSizeChange, handleThemeChangeForFocusedSession, handleThemeResetForFocusedSession, handleToggleSftpFromBar, handleToggleWorkspaceComposeBar, handleUpdateHost, handleWorkspaceDrop, hosts, hotkeyScheme, identities, isBroadcastEnabled, isComposeBarOpen, isFocusMode, isSidePanelOpenForCurrentTab, isTerminalLayerVisible, keyBindings, keys, knownHosts, MessageSquare, mountedAiTabIds, mountedSftpTabIds, onHotkeyAction, onSetWorkspaceFocusedSession, onSplitSession, Palette, PanelLeft, PanelRight, pendingTerminalSelectionForAI, previewedOrVisibleThemeId, refocusActiveTerminalSession, refocusTerminalSession, renderFocusModeSidebar, resizing, resolveAIExecutorContext, resolvedPreviewTheme, ScriptsSidePanel, sessionChainHostsMap, sessionHostsMap, sessionLogConfig, sessionSudoAutofillPasswordsMap, sessions, setDropHint, setEditorWordWrap, setIsComposeBarOpen, setResizing, setSidePanelPosition, setSftpFollowTerminalCwd, sftpActiveHost, sftpAutoSync, sftpDefaultViewMode, sftpDoubleClickBehavior, sftpFollowTerminalCwd, sftpInitialLocationForTab, sftpPendingUploadsForTab, sftpShowHiddenFiles, SftpSidePanel, sftpUseCompressedUpload, sidePanelPosition, sidePanelWidth, snippetPackages, snippets, splitHorizontalHandlersRef, splitVerticalHandlersRef, sshDebugLogsEnabled, t, TerminalComposeBar, terminalFontFamilyId, TerminalPanesHost, terminalSettings, terminalTheme, themePreview, ThemeSidePanel, Tooltip, TooltipContent, TooltipTrigger, updateHosts, validAIScopeTargetIds, workspaceBroadcastHandlersRef, workspaceById, workspaceFocusHandlersRef, workspaceInnerRef, workspaceOuterRef, workspaceOverlayRef, workspaceRectsById, X, Zap } = ctx; return (
{/* Side panel with tab header + content (SFTP / Scripts / Theme). Uses `order-last` instead of flex-row-reverse on the parent so the workspace focus-mode sidebar and terminal area below stay in source order (sidebar on the left) regardless of the side panel's side. */} {(isSidePanelOpenForCurrentTab || mountedSftpTabIds.length > 0 || mountedAiTabIds.length > 0) && ( <>
{isSidePanelOpenForCurrentTab && (
)}
{isSidePanelOpenForCurrentTab && (
{t('terminal.layer.sftp')} {t('terminal.layer.scripts')} {t('terminal.layer.theme')} {t('terminal.layer.aiChat')}
{sidePanelPosition === 'left' ? t('terminal.layer.movePanelRight') : t('terminal.layer.movePanelLeft')} {t('terminal.layer.closePanel')}
)}
{/* SFTP sub-panel */} {mountedSftpTabIds.map((tabId) => { const isVisibleSftpPanel = activeTabId === tabId && activeSidePanelTab === 'sftp'; return ( handleSftpInitialLocationApplied(tabId, location)} showWorkspaceHostHeader={isVisibleSftpPanel && !!activeWorkspace} isVisible={isVisibleSftpPanel} renderOverlays={isVisibleSftpPanel} pendingUpload={sftpPendingUploadsForTab.get(tabId) ?? null} onPendingUploadHandled={(requestId) => handlePendingUploadHandled(tabId, requestId)} sftpDoubleClickBehavior={sftpDoubleClickBehavior} sftpAutoSync={isVisibleSftpPanel ? sftpAutoSync : false} sftpShowHiddenFiles={sftpShowHiddenFiles} sftpUseCompressedUpload={sftpUseCompressedUpload} hotkeyScheme={hotkeyScheme} keyBindings={keyBindings} editorWordWrap={editorWordWrap} setEditorWordWrap={setEditorWordWrap} onGetTerminalCwd={getTerminalCwd} activeTerminalCwd={activeTerminalCwd} sftpFollowTerminalCwd={sftpFollowTerminalCwd} onSftpFollowTerminalCwdChange={setSftpFollowTerminalCwd} onRequestTerminalFocus={refocusActiveTerminalSession} terminalSettings={terminalSettings} /> ); })} {/* Scripts sub-panel */} {activeSidePanelTab === 'scripts' && (
)} {/* Theme sub-panel */} {activeSidePanelTab === 'theme' && (
)}
)} {/* Focus mode sidebar */} {isFocusMode && renderFocusModeSidebar()}
{draggingSessionId && !isFocusMode && (
{ if (isFocusMode) return; 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 && (
)}
)} {/* Only show resizers in split view mode, not in focus mode */} {!isFocusMode && activeResizers.map(handle => { const isVertical = handle.direction === 'vertical'; // Expand hit area perpendicular to the split line, but stay within bounds // Vertical split (left-right): expand horizontally, keep vertical bounds // Horizontal split (top-bottom): expand vertically, keep horizontal bounds const left = isVertical ? handle.rect.x - 3 : handle.rect.x; const top = isVertical ? handle.rect.y : handle.rect.y - 3; const width = isVertical ? handle.rect.w + 6 : handle.rect.w; const height = isVertical ? handle.rect.h : handle.rect.h + 6; return (
{ 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 }, }); }} >
); })}
{/* Global compose bar for workspace mode */} {activeWorkspace && isComposeBarOpen && ( { setIsComposeBarOpen(false); refocusTerminalSession(focusedSessionId); }} isBroadcastEnabled={isBroadcastEnabled?.(activeWorkspace.id)} themeColors={composeBarThemeColors} /> )}
); }