@atercates/claude-deck 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/app/api/claude/hidden/route.ts +66 -0
- package/app/api/claude/projects/[name]/sessions/route.ts +71 -0
- package/app/api/claude/projects/route.ts +44 -0
- package/app/api/code-search/available/route.ts +12 -0
- package/app/api/code-search/route.ts +47 -0
- package/app/api/dev-servers/[id]/logs/route.ts +23 -0
- package/app/api/dev-servers/[id]/restart/route.ts +20 -0
- package/app/api/dev-servers/[id]/route.ts +51 -0
- package/app/api/dev-servers/[id]/stop/route.ts +20 -0
- package/app/api/dev-servers/detect/route.ts +39 -0
- package/app/api/dev-servers/route.ts +48 -0
- package/app/api/exec/route.ts +60 -0
- package/app/api/files/content/route.ts +76 -0
- package/app/api/files/route.ts +37 -0
- package/app/api/files/upload-temp/route.ts +41 -0
- package/app/api/git/check/route.ts +54 -0
- package/app/api/git/clone/route.ts +99 -0
- package/app/api/git/commit/route.ts +75 -0
- package/app/api/git/discard/route.ts +38 -0
- package/app/api/git/file-content/route.ts +64 -0
- package/app/api/git/history/[hash]/diff/route.ts +38 -0
- package/app/api/git/history/[hash]/route.ts +34 -0
- package/app/api/git/history/route.ts +27 -0
- package/app/api/git/multi-status/route.ts +46 -0
- package/app/api/git/pr/route.ts +164 -0
- package/app/api/git/push/route.ts +64 -0
- package/app/api/git/stage/route.ts +40 -0
- package/app/api/git/status/route.ts +51 -0
- package/app/api/git/unstage/route.ts +46 -0
- package/app/api/groups/[...path]/route.ts +136 -0
- package/app/api/groups/route.ts +93 -0
- package/app/api/orchestrate/spawn/route.ts +45 -0
- package/app/api/orchestrate/workers/[id]/route.ts +89 -0
- package/app/api/orchestrate/workers/route.ts +31 -0
- package/app/api/projects/[id]/detect/route.ts +27 -0
- package/app/api/projects/[id]/dev-servers/[dsId]/route.ts +66 -0
- package/app/api/projects/[id]/dev-servers/route.ts +51 -0
- package/app/api/projects/[id]/repositories/[repoId]/route.ts +67 -0
- package/app/api/projects/[id]/repositories/route.ts +74 -0
- package/app/api/projects/[id]/route.ts +108 -0
- package/app/api/projects/detect/route.ts +33 -0
- package/app/api/projects/route.ts +59 -0
- package/app/api/sessions/[id]/claude-session/route.ts +42 -0
- package/app/api/sessions/[id]/fork/route.ts +74 -0
- package/app/api/sessions/[id]/mcp-config/route.ts +34 -0
- package/app/api/sessions/[id]/messages/route.ts +60 -0
- package/app/api/sessions/[id]/pr/route.ts +188 -0
- package/app/api/sessions/[id]/preview/route.ts +42 -0
- package/app/api/sessions/[id]/route.ts +229 -0
- package/app/api/sessions/[id]/send-keys/route.ts +119 -0
- package/app/api/sessions/[id]/summarize/route.ts +331 -0
- package/app/api/sessions/init-script/route.ts +84 -0
- package/app/api/sessions/route.ts +209 -0
- package/app/api/sessions/status/route.ts +237 -0
- package/app/api/system/route.ts +9 -0
- package/app/api/tmux/kill-all/route.ts +57 -0
- package/app/api/tmux/rename/route.ts +30 -0
- package/app/globals.css +174 -0
- package/app/icon.svg +11 -0
- package/app/layout.tsx +122 -0
- package/app/page.tsx +629 -0
- package/components/ChatMessage.tsx +65 -0
- package/components/ChatView.tsx +276 -0
- package/components/ClaudeProjects/ClaudeProjectCard.tsx +195 -0
- package/components/ClaudeProjects/ClaudeProjectsSection.tsx +89 -0
- package/components/ClaudeProjects/ClaudeSessionCard.tsx +100 -0
- package/components/ClaudeProjects/index.ts +1 -0
- package/components/CodeSearch/CodeSearchResults.tsx +177 -0
- package/components/ConductorPanel.tsx +256 -0
- package/components/DevServers/DevServerCard.tsx +311 -0
- package/components/DevServers/DevServersSection.tsx +91 -0
- package/components/DevServers/ServerLogsModal.tsx +151 -0
- package/components/DevServers/StartServerDialog.tsx +359 -0
- package/components/DevServers/index.ts +4 -0
- package/components/DiffViewer/DiffModal.tsx +151 -0
- package/components/DiffViewer/UnifiedDiff.tsx +185 -0
- package/components/DiffViewer/index.tsx +2 -0
- package/components/DirectoryPicker.tsx +355 -0
- package/components/FileExplorer/FileEditor.tsx +276 -0
- package/components/FileExplorer/FileTabs.tsx +118 -0
- package/components/FileExplorer/FileTree.tsx +214 -0
- package/components/FileExplorer/HtmlRenderer.tsx +16 -0
- package/components/FileExplorer/MarkdownRenderer.tsx +18 -0
- package/components/FileExplorer/index.tsx +520 -0
- package/components/FilePicker.tsx +339 -0
- package/components/FolderPicker.tsx +201 -0
- package/components/GitDrawer/FileEditDialog.tsx +400 -0
- package/components/GitDrawer/index.tsx +464 -0
- package/components/GitPanel/CommitForm.tsx +205 -0
- package/components/GitPanel/CommitHistory.tsx +174 -0
- package/components/GitPanel/CommitItem.tsx +196 -0
- package/components/GitPanel/FileChanges.tsx +414 -0
- package/components/GitPanel/GitPanelTabs.tsx +39 -0
- package/components/GitPanel/index.tsx +817 -0
- package/components/MessageInput.tsx +82 -0
- package/components/NewClaudeSessionDialog.tsx +166 -0
- package/components/NewSessionDialog/AdvancedSettings.tsx +78 -0
- package/components/NewSessionDialog/AgentSelector.tsx +37 -0
- package/components/NewSessionDialog/CreatingOverlay.tsx +94 -0
- package/components/NewSessionDialog/NewSessionDialog.types.ts +136 -0
- package/components/NewSessionDialog/ProjectSelector.tsx +146 -0
- package/components/NewSessionDialog/WorkingDirectoryInput.tsx +55 -0
- package/components/NewSessionDialog/WorktreeSection.tsx +92 -0
- package/components/NewSessionDialog/hooks/useNewSessionForm.ts +370 -0
- package/components/NewSessionDialog/index.tsx +106 -0
- package/components/NotificationSettings.tsx +127 -0
- package/components/PRCreationModal.tsx +272 -0
- package/components/Pane/DesktopTabBar.tsx +353 -0
- package/components/Pane/MobileTabBar.tsx +210 -0
- package/components/Pane/OpenInVSCode.tsx +69 -0
- package/components/Pane/PaneSkeletons.tsx +57 -0
- package/components/Pane/index.tsx +558 -0
- package/components/PaneLayout.tsx +60 -0
- package/components/Projects/DevServersSection.tsx +140 -0
- package/components/Projects/DirectoryField.tsx +92 -0
- package/components/Projects/NewProjectDialog.tsx +188 -0
- package/components/Projects/NewProjectDialog.types.ts +46 -0
- package/components/Projects/ProjectCard.tsx +276 -0
- package/components/Projects/ProjectSettingsDialog.tsx +811 -0
- package/components/Projects/hooks/useNewProjectForm.ts +249 -0
- package/components/Projects/index.ts +3 -0
- package/components/Providers.tsx +49 -0
- package/components/QuickSwitcher.tsx +306 -0
- package/components/SessionList/KillAllConfirm.tsx +46 -0
- package/components/SessionList/SelectionToolbar.tsx +164 -0
- package/components/SessionList/SessionList.types.ts +37 -0
- package/components/SessionList/SessionListHeader.tsx +71 -0
- package/components/SessionList/hooks/useSessionListMutations.ts +269 -0
- package/components/SessionList/index.tsx +189 -0
- package/components/ShellDrawer/index.tsx +106 -0
- package/components/SidebarFooter.tsx +55 -0
- package/components/Terminal/KeybarToggleButton.tsx +45 -0
- package/components/Terminal/ScrollToBottomButton.tsx +32 -0
- package/components/Terminal/SearchBar.tsx +71 -0
- package/components/Terminal/TerminalToolbar.tsx +551 -0
- package/components/Terminal/VirtualKeyboard.tsx +711 -0
- package/components/Terminal/constants.ts +20 -0
- package/components/Terminal/hooks/index.ts +5 -0
- package/components/Terminal/hooks/resize-handlers.ts +140 -0
- package/components/Terminal/hooks/terminal-init.ts +151 -0
- package/components/Terminal/hooks/touch-scroll.ts +155 -0
- package/components/Terminal/hooks/useTerminalConnection.ts +282 -0
- package/components/Terminal/hooks/useTerminalConnection.types.ts +39 -0
- package/components/Terminal/hooks/useTerminalSearch.ts +103 -0
- package/components/Terminal/hooks/websocket-connection.ts +274 -0
- package/components/Terminal/index.tsx +320 -0
- package/components/ThemeToggle.tsx +168 -0
- package/components/TmuxSessions.tsx +132 -0
- package/components/ToolCallDisplay.tsx +71 -0
- package/components/WorkerCard.tsx +245 -0
- package/components/a/ABadge.tsx +115 -0
- package/components/a/AButton.tsx +163 -0
- package/components/a/ADialog.tsx +93 -0
- package/components/a/ADropdownMenu.tsx +279 -0
- package/components/a/AIconButton.tsx +190 -0
- package/components/a/ASheet.tsx +150 -0
- package/components/a/ATooltip.tsx +77 -0
- package/components/a/index.ts +64 -0
- package/components/mobile/SwipeSidebar.tsx +122 -0
- package/components/ui/badge.tsx +41 -0
- package/components/ui/button.tsx +60 -0
- package/components/ui/context-menu.tsx +197 -0
- package/components/ui/dialog.tsx +143 -0
- package/components/ui/dropdown-menu.tsx +257 -0
- package/components/ui/input.tsx +21 -0
- package/components/ui/scroll-area.tsx +52 -0
- package/components/ui/select.tsx +159 -0
- package/components/ui/skeleton.tsx +111 -0
- package/components/ui/switch.tsx +31 -0
- package/components/ui/textarea.tsx +21 -0
- package/components/ui/tooltip.tsx +32 -0
- package/components/views/DesktopView.tsx +244 -0
- package/components/views/MobileView.tsx +110 -0
- package/components/views/types.ts +75 -0
- package/contexts/PaneContext.tsx +336 -0
- package/data/claude/index.ts +9 -0
- package/data/claude/keys.ts +6 -0
- package/data/claude/queries.ts +120 -0
- package/data/claude/useClaudeUpdates.ts +37 -0
- package/data/code-search/index.ts +2 -0
- package/data/code-search/keys.ts +7 -0
- package/data/code-search/queries.ts +61 -0
- package/data/dev-servers/index.ts +8 -0
- package/data/dev-servers/keys.ts +4 -0
- package/data/dev-servers/queries.ts +104 -0
- package/data/files/index.ts +3 -0
- package/data/files/keys.ts +4 -0
- package/data/files/queries.ts +25 -0
- package/data/git/keys.ts +15 -0
- package/data/git/queries.ts +395 -0
- package/data/groups/index.ts +1 -0
- package/data/groups/mutations.ts +95 -0
- package/data/projects/index.ts +10 -0
- package/data/projects/keys.ts +4 -0
- package/data/projects/queries.ts +193 -0
- package/data/repositories/index.ts +7 -0
- package/data/repositories/keys.ts +5 -0
- package/data/repositories/queries.ts +122 -0
- package/data/sessions/index.ts +12 -0
- package/data/sessions/keys.ts +8 -0
- package/data/sessions/queries.ts +218 -0
- package/data/statuses/index.ts +1 -0
- package/data/statuses/queries.ts +69 -0
- package/hooks/useCopyToClipboard.ts +48 -0
- package/hooks/useDevServersManager.ts +73 -0
- package/hooks/useDirectoryBrowser.ts +90 -0
- package/hooks/useDrawerAnimation.ts +27 -0
- package/hooks/useFileDrop.ts +87 -0
- package/hooks/useFileEditor.ts +184 -0
- package/hooks/useGroups.ts +37 -0
- package/hooks/useHomePath.ts +34 -0
- package/hooks/useKeyRepeat.ts +55 -0
- package/hooks/useKeybarVisibility.ts +42 -0
- package/hooks/useNotifications.ts +257 -0
- package/hooks/useProjects.ts +53 -0
- package/hooks/useSessionStatuses.ts +30 -0
- package/hooks/useSessions.ts +86 -0
- package/hooks/useSpeechRecognition.ts +124 -0
- package/hooks/useViewport.ts +32 -0
- package/hooks/useViewportHeight.ts +50 -0
- package/lib/async-operations.ts +35 -0
- package/lib/banner.ts +81 -0
- package/lib/claude/jsonl-cache.ts +86 -0
- package/lib/claude/jsonl-reader.ts +271 -0
- package/lib/claude/process-manager.ts +278 -0
- package/lib/claude/stream-parser.ts +173 -0
- package/lib/claude/types.ts +154 -0
- package/lib/claude/watcher.ts +71 -0
- package/lib/client/session-registry.ts +111 -0
- package/lib/code-search.ts +121 -0
- package/lib/db/index.ts +48 -0
- package/lib/db/migrations.ts +45 -0
- package/lib/db/queries.ts +460 -0
- package/lib/db/schema.ts +114 -0
- package/lib/db/types.ts +92 -0
- package/lib/db.ts +2 -0
- package/lib/dev-servers.ts +509 -0
- package/lib/diff-parser.ts +221 -0
- package/lib/env-setup.ts +285 -0
- package/lib/file-upload.ts +34 -0
- package/lib/file-utils.ts +50 -0
- package/lib/files.ts +207 -0
- package/lib/git-history.ts +294 -0
- package/lib/git-status.ts +391 -0
- package/lib/git.ts +257 -0
- package/lib/mcp-config.ts +81 -0
- package/lib/multi-repo-git.ts +179 -0
- package/lib/notifications.ts +219 -0
- package/lib/orchestration.ts +448 -0
- package/lib/panes.ts +232 -0
- package/lib/ports.ts +97 -0
- package/lib/pr-generation.ts +307 -0
- package/lib/pr.ts +234 -0
- package/lib/projects.ts +578 -0
- package/lib/providers/registry.ts +70 -0
- package/lib/providers.ts +121 -0
- package/lib/query-client.ts +14 -0
- package/lib/rangeSelectionUtils.ts +65 -0
- package/lib/status-detector.ts +375 -0
- package/lib/terminal-themes.ts +265 -0
- package/lib/theme-config.ts +327 -0
- package/lib/utils.ts +6 -0
- package/lib/worktrees.ts +262 -0
- package/mcp/orchestration-server.ts +438 -0
- package/package.json +139 -0
- package/postcss.config.mjs +7 -0
- package/public/icon.svg +10 -0
- package/public/icons/icon-128x128.png +0 -0
- package/public/icons/icon-144x144.png +0 -0
- package/public/icons/icon-152x152.png +0 -0
- package/public/icons/icon-192x192.png +0 -0
- package/public/icons/icon-384x384.png +0 -0
- package/public/icons/icon-512x512.png +0 -0
- package/public/icons/icon-72x72.png +0 -0
- package/public/icons/icon-96x96.png +0 -0
- package/public/manifest.json +61 -0
- package/public/sw.js +64 -0
- package/scripts/agent-os +91 -0
- package/scripts/install.sh +48 -0
- package/scripts/lib/ai-clis.sh +132 -0
- package/scripts/lib/commands.sh +487 -0
- package/scripts/lib/common.sh +89 -0
- package/scripts/lib/prerequisites.sh +462 -0
- package/scripts/setup.sh +134 -0
- package/server.ts +155 -0
- package/stores/fileOpen.ts +26 -0
- package/stores/index.ts +1 -0
- package/stores/initialPrompt.ts +24 -0
- package/stores/sessionSelection.ts +48 -0
- package/styles/themes.css +603 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useCallback } from "react";
|
|
4
|
+
import {
|
|
5
|
+
Dialog,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogHeader,
|
|
8
|
+
DialogTitle,
|
|
9
|
+
DialogFooter,
|
|
10
|
+
} from "./ui/dialog";
|
|
11
|
+
import { Button } from "./ui/button";
|
|
12
|
+
import {
|
|
13
|
+
ChevronRight,
|
|
14
|
+
ChevronDown,
|
|
15
|
+
Folder,
|
|
16
|
+
FolderOpen,
|
|
17
|
+
Home,
|
|
18
|
+
ChevronUp,
|
|
19
|
+
Loader2,
|
|
20
|
+
FolderInput,
|
|
21
|
+
HardDrive,
|
|
22
|
+
} from "lucide-react";
|
|
23
|
+
import { cn } from "@/lib/utils";
|
|
24
|
+
import type { FileNode } from "@/lib/file-utils";
|
|
25
|
+
|
|
26
|
+
interface DirectoryPickerProps {
|
|
27
|
+
open: boolean;
|
|
28
|
+
onClose: () => void;
|
|
29
|
+
onSelect: (path: string) => void;
|
|
30
|
+
initialPath?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function DirectoryPicker({
|
|
34
|
+
open,
|
|
35
|
+
onClose,
|
|
36
|
+
onSelect,
|
|
37
|
+
initialPath = "~",
|
|
38
|
+
}: DirectoryPickerProps) {
|
|
39
|
+
const [currentPath, setCurrentPath] = useState(initialPath);
|
|
40
|
+
const [selectedPath, setSelectedPath] = useState<string | null>(null);
|
|
41
|
+
const [directories, setDirectories] = useState<FileNode[]>([]);
|
|
42
|
+
const [expanded, setExpanded] = useState<Set<string>>(new Set());
|
|
43
|
+
const [loading, setLoading] = useState(false);
|
|
44
|
+
const [error, setError] = useState<string | null>(null);
|
|
45
|
+
|
|
46
|
+
// Track home directory path from API
|
|
47
|
+
const [homePath, setHomePath] = useState<string | null>(null);
|
|
48
|
+
|
|
49
|
+
// Fetch directory contents
|
|
50
|
+
const fetchDirectory = useCallback(async (path: string) => {
|
|
51
|
+
setLoading(true);
|
|
52
|
+
setError(null);
|
|
53
|
+
try {
|
|
54
|
+
const res = await fetch(`/api/files?path=${encodeURIComponent(path)}`);
|
|
55
|
+
const data = await res.json();
|
|
56
|
+
if (data.error) {
|
|
57
|
+
setError(data.error);
|
|
58
|
+
return { dirs: [], expandedPath: path };
|
|
59
|
+
}
|
|
60
|
+
// Store the home path if we're at ~
|
|
61
|
+
if (path === "~" && data.path) {
|
|
62
|
+
setHomePath(data.path);
|
|
63
|
+
}
|
|
64
|
+
// Filter to only directories
|
|
65
|
+
const dirs = (data.files || []).filter(
|
|
66
|
+
(f: FileNode) => f.type === "directory"
|
|
67
|
+
);
|
|
68
|
+
return { dirs, expandedPath: data.path };
|
|
69
|
+
} catch {
|
|
70
|
+
setError("Failed to load directory");
|
|
71
|
+
return { dirs: [], expandedPath: path };
|
|
72
|
+
} finally {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
}
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
// Load initial directory
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (open) {
|
|
80
|
+
fetchDirectory(currentPath).then(({ dirs }) => setDirectories(dirs));
|
|
81
|
+
setSelectedPath(null);
|
|
82
|
+
}
|
|
83
|
+
}, [open, currentPath, fetchDirectory]);
|
|
84
|
+
|
|
85
|
+
// Navigate up to parent
|
|
86
|
+
const goUp = () => {
|
|
87
|
+
// Can't go above root
|
|
88
|
+
if (currentPath === "/") {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// From ~ or homePath, go to parent of home directory
|
|
93
|
+
if (currentPath === "~" || (homePath && currentPath === homePath)) {
|
|
94
|
+
if (homePath) {
|
|
95
|
+
const homeParent = homePath.split("/").slice(0, -1).join("/") || "/";
|
|
96
|
+
setCurrentPath(homeParent);
|
|
97
|
+
setExpanded(new Set());
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const parts = currentPath.split("/").filter(Boolean);
|
|
103
|
+
parts.pop();
|
|
104
|
+
const newPath = currentPath.startsWith("~")
|
|
105
|
+
? "~/" + parts.slice(1).join("/") || "~"
|
|
106
|
+
: "/" + parts.join("/") || "/";
|
|
107
|
+
setCurrentPath(newPath);
|
|
108
|
+
setExpanded(new Set());
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Go to root
|
|
112
|
+
const goRoot = () => {
|
|
113
|
+
setCurrentPath("/");
|
|
114
|
+
setExpanded(new Set());
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Go to home
|
|
118
|
+
const goHome = () => {
|
|
119
|
+
setCurrentPath("~");
|
|
120
|
+
setExpanded(new Set());
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Toggle directory expansion and fetch children
|
|
124
|
+
const toggleExpand = async (node: FileNode) => {
|
|
125
|
+
const newExpanded = new Set(expanded);
|
|
126
|
+
if (newExpanded.has(node.path)) {
|
|
127
|
+
newExpanded.delete(node.path);
|
|
128
|
+
} else {
|
|
129
|
+
newExpanded.add(node.path);
|
|
130
|
+
// Fetch children if not already loaded
|
|
131
|
+
if (!node.children || node.children.length === 0) {
|
|
132
|
+
const { dirs } = await fetchDirectory(node.path);
|
|
133
|
+
// Update the node with children
|
|
134
|
+
setDirectories((prev) => updateNodeChildren(prev, node.path, dirs));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
setExpanded(newExpanded);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// Select a directory
|
|
141
|
+
const handleSelect = (path: string) => {
|
|
142
|
+
setSelectedPath(path);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Confirm selection
|
|
146
|
+
const handleConfirm = () => {
|
|
147
|
+
if (selectedPath) {
|
|
148
|
+
// Convert absolute path back to ~ format if it's in home directory
|
|
149
|
+
let finalPath = selectedPath;
|
|
150
|
+
if (homePath && selectedPath.startsWith(homePath)) {
|
|
151
|
+
finalPath = "~" + selectedPath.slice(homePath.length);
|
|
152
|
+
}
|
|
153
|
+
onSelect(finalPath);
|
|
154
|
+
onClose();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Select current directory
|
|
159
|
+
const selectCurrentDirectory = () => {
|
|
160
|
+
// Convert to ~ format if in home directory
|
|
161
|
+
let finalPath = currentPath;
|
|
162
|
+
if (homePath && currentPath.startsWith(homePath)) {
|
|
163
|
+
finalPath = "~" + currentPath.slice(homePath.length);
|
|
164
|
+
}
|
|
165
|
+
onSelect(finalPath);
|
|
166
|
+
onClose();
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<Dialog open={open} onOpenChange={(o) => !o && onClose()}>
|
|
171
|
+
<DialogContent className="flex max-h-[80vh] max-w-md flex-col">
|
|
172
|
+
<DialogHeader>
|
|
173
|
+
<DialogTitle>Select Directory</DialogTitle>
|
|
174
|
+
</DialogHeader>
|
|
175
|
+
|
|
176
|
+
{/* Navigation bar */}
|
|
177
|
+
<div className="flex items-center gap-2 border-b pb-2">
|
|
178
|
+
<Button variant="ghost" size="icon-sm" onClick={goRoot} title="Root">
|
|
179
|
+
<HardDrive className="h-4 w-4" />
|
|
180
|
+
</Button>
|
|
181
|
+
<Button variant="ghost" size="icon-sm" onClick={goHome} title="Home">
|
|
182
|
+
<Home className="h-4 w-4" />
|
|
183
|
+
</Button>
|
|
184
|
+
<Button
|
|
185
|
+
variant="ghost"
|
|
186
|
+
size="icon-sm"
|
|
187
|
+
onClick={goUp}
|
|
188
|
+
disabled={currentPath === "/"}
|
|
189
|
+
title="Go up"
|
|
190
|
+
>
|
|
191
|
+
<ChevronUp className="h-4 w-4" />
|
|
192
|
+
</Button>
|
|
193
|
+
<span className="text-muted-foreground flex-1 truncate font-mono text-sm">
|
|
194
|
+
{currentPath}
|
|
195
|
+
</span>
|
|
196
|
+
<Button
|
|
197
|
+
variant="outline"
|
|
198
|
+
size="sm"
|
|
199
|
+
onClick={selectCurrentDirectory}
|
|
200
|
+
title="Select this directory"
|
|
201
|
+
>
|
|
202
|
+
<FolderInput className="mr-1 h-4 w-4" />
|
|
203
|
+
Use This
|
|
204
|
+
</Button>
|
|
205
|
+
</div>
|
|
206
|
+
|
|
207
|
+
{/* Directory listing */}
|
|
208
|
+
<div className="max-h-[400px] min-h-[200px] flex-1 overflow-y-auto">
|
|
209
|
+
{loading && directories.length === 0 ? (
|
|
210
|
+
<div className="flex items-center justify-center py-8">
|
|
211
|
+
<Loader2 className="text-muted-foreground h-6 w-6 animate-spin" />
|
|
212
|
+
</div>
|
|
213
|
+
) : error ? (
|
|
214
|
+
<div className="py-8 text-center text-sm text-red-500">{error}</div>
|
|
215
|
+
) : directories.length === 0 ? (
|
|
216
|
+
<div className="text-muted-foreground py-8 text-center text-sm">
|
|
217
|
+
No subdirectories
|
|
218
|
+
</div>
|
|
219
|
+
) : (
|
|
220
|
+
<DirectoryTree
|
|
221
|
+
nodes={directories}
|
|
222
|
+
expanded={expanded}
|
|
223
|
+
selectedPath={selectedPath}
|
|
224
|
+
onToggle={toggleExpand}
|
|
225
|
+
onSelect={handleSelect}
|
|
226
|
+
onDoubleClick={(path) => {
|
|
227
|
+
setCurrentPath(path);
|
|
228
|
+
setExpanded(new Set());
|
|
229
|
+
}}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
<DialogFooter>
|
|
235
|
+
<Button variant="outline" onClick={onClose}>
|
|
236
|
+
Cancel
|
|
237
|
+
</Button>
|
|
238
|
+
<Button onClick={handleConfirm} disabled={!selectedPath}>
|
|
239
|
+
Select
|
|
240
|
+
</Button>
|
|
241
|
+
</DialogFooter>
|
|
242
|
+
</DialogContent>
|
|
243
|
+
</Dialog>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface DirectoryTreeProps {
|
|
248
|
+
nodes: FileNode[];
|
|
249
|
+
expanded: Set<string>;
|
|
250
|
+
selectedPath: string | null;
|
|
251
|
+
onToggle: (node: FileNode) => void;
|
|
252
|
+
onSelect: (path: string) => void;
|
|
253
|
+
onDoubleClick: (path: string) => void;
|
|
254
|
+
depth?: number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function DirectoryTree({
|
|
258
|
+
nodes,
|
|
259
|
+
expanded,
|
|
260
|
+
selectedPath,
|
|
261
|
+
onToggle,
|
|
262
|
+
onSelect,
|
|
263
|
+
onDoubleClick,
|
|
264
|
+
depth = 0,
|
|
265
|
+
}: DirectoryTreeProps) {
|
|
266
|
+
return (
|
|
267
|
+
<div>
|
|
268
|
+
{nodes.map((node) => {
|
|
269
|
+
const isExpanded = expanded.has(node.path);
|
|
270
|
+
const isSelected = selectedPath === node.path;
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<div key={node.path}>
|
|
274
|
+
<div
|
|
275
|
+
role="button"
|
|
276
|
+
tabIndex={0}
|
|
277
|
+
onClick={() => onSelect(node.path)}
|
|
278
|
+
onDoubleClick={() => onDoubleClick(node.path)}
|
|
279
|
+
onKeyDown={(e) => {
|
|
280
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
281
|
+
e.preventDefault();
|
|
282
|
+
onSelect(node.path);
|
|
283
|
+
}
|
|
284
|
+
}}
|
|
285
|
+
className={cn(
|
|
286
|
+
"flex w-full cursor-pointer items-center gap-2 px-2 py-2 text-left transition-colors",
|
|
287
|
+
"min-h-[40px] text-sm md:min-h-[32px]",
|
|
288
|
+
isSelected ? "bg-primary/20 text-primary" : "hover:bg-accent"
|
|
289
|
+
)}
|
|
290
|
+
style={{ paddingLeft: `${depth * 16 + 8}px` }}
|
|
291
|
+
>
|
|
292
|
+
{/* Expand/collapse */}
|
|
293
|
+
<button
|
|
294
|
+
onClick={(e) => {
|
|
295
|
+
e.stopPropagation();
|
|
296
|
+
onToggle(node);
|
|
297
|
+
}}
|
|
298
|
+
className="hover:bg-muted flex h-5 w-5 flex-shrink-0 items-center justify-center rounded"
|
|
299
|
+
>
|
|
300
|
+
{isExpanded ? (
|
|
301
|
+
<ChevronDown className="text-muted-foreground h-4 w-4" />
|
|
302
|
+
) : (
|
|
303
|
+
<ChevronRight className="text-muted-foreground h-4 w-4" />
|
|
304
|
+
)}
|
|
305
|
+
</button>
|
|
306
|
+
|
|
307
|
+
{/* Icon */}
|
|
308
|
+
{isExpanded ? (
|
|
309
|
+
<FolderOpen className="h-4 w-4 flex-shrink-0 text-blue-400" />
|
|
310
|
+
) : (
|
|
311
|
+
<Folder className="h-4 w-4 flex-shrink-0 text-blue-400" />
|
|
312
|
+
)}
|
|
313
|
+
|
|
314
|
+
{/* Name */}
|
|
315
|
+
<span className="flex-1 truncate font-medium">{node.name}</span>
|
|
316
|
+
</div>
|
|
317
|
+
|
|
318
|
+
{/* Children */}
|
|
319
|
+
{isExpanded && node.children && node.children.length > 0 && (
|
|
320
|
+
<DirectoryTree
|
|
321
|
+
nodes={node.children}
|
|
322
|
+
expanded={expanded}
|
|
323
|
+
selectedPath={selectedPath}
|
|
324
|
+
onToggle={onToggle}
|
|
325
|
+
onSelect={onSelect}
|
|
326
|
+
onDoubleClick={onDoubleClick}
|
|
327
|
+
depth={depth + 1}
|
|
328
|
+
/>
|
|
329
|
+
)}
|
|
330
|
+
</div>
|
|
331
|
+
);
|
|
332
|
+
})}
|
|
333
|
+
</div>
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Helper to update node children in tree
|
|
338
|
+
function updateNodeChildren(
|
|
339
|
+
nodes: FileNode[],
|
|
340
|
+
targetPath: string,
|
|
341
|
+
children: FileNode[]
|
|
342
|
+
): FileNode[] {
|
|
343
|
+
return nodes.map((node) => {
|
|
344
|
+
if (node.path === targetPath) {
|
|
345
|
+
return { ...node, children };
|
|
346
|
+
}
|
|
347
|
+
if (node.children) {
|
|
348
|
+
return {
|
|
349
|
+
...node,
|
|
350
|
+
children: updateNodeChildren(node.children, targetPath, children),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
return node;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import CodeMirror from "@uiw/react-codemirror";
|
|
5
|
+
import { EditorView, keymap } from "@codemirror/view";
|
|
6
|
+
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
7
|
+
import { tags as t } from "@lezer/highlight";
|
|
8
|
+
import { javascript } from "@codemirror/lang-javascript";
|
|
9
|
+
import { python } from "@codemirror/lang-python";
|
|
10
|
+
import { json } from "@codemirror/lang-json";
|
|
11
|
+
import { css } from "@codemirror/lang-css";
|
|
12
|
+
import { html } from "@codemirror/lang-html";
|
|
13
|
+
import { markdown } from "@codemirror/lang-markdown";
|
|
14
|
+
import type { Extension } from "@codemirror/state";
|
|
15
|
+
import { FileCode, Eye, Code2 } from "lucide-react";
|
|
16
|
+
import { Button } from "@/components/ui/button";
|
|
17
|
+
import { MarkdownRenderer } from "./MarkdownRenderer";
|
|
18
|
+
import { HtmlRenderer } from "./HtmlRenderer";
|
|
19
|
+
|
|
20
|
+
interface FileEditorProps {
|
|
21
|
+
content: string;
|
|
22
|
+
language: string;
|
|
23
|
+
isBinary: boolean;
|
|
24
|
+
readOnly?: boolean;
|
|
25
|
+
onChange: (content: string) => void;
|
|
26
|
+
onSave?: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Theme that uses CSS variables from the app
|
|
30
|
+
const editorTheme = EditorView.theme({
|
|
31
|
+
"&": {
|
|
32
|
+
fontSize: "13px",
|
|
33
|
+
height: "100%",
|
|
34
|
+
backgroundColor: "hsl(var(--background))",
|
|
35
|
+
color: "hsl(var(--foreground))",
|
|
36
|
+
},
|
|
37
|
+
".cm-content": {
|
|
38
|
+
fontFamily: "var(--font-geist-mono), ui-monospace, monospace",
|
|
39
|
+
padding: "8px 0",
|
|
40
|
+
caretColor: "hsl(var(--primary))",
|
|
41
|
+
},
|
|
42
|
+
".cm-gutters": {
|
|
43
|
+
backgroundColor: "hsl(var(--background))",
|
|
44
|
+
borderRight: "none",
|
|
45
|
+
color: "hsl(var(--muted-foreground))",
|
|
46
|
+
},
|
|
47
|
+
".cm-lineNumbers .cm-gutterElement": {
|
|
48
|
+
padding: "0 8px 0 16px",
|
|
49
|
+
},
|
|
50
|
+
".cm-activeLineGutter": {
|
|
51
|
+
backgroundColor: "hsl(var(--accent))",
|
|
52
|
+
},
|
|
53
|
+
".cm-activeLine": {
|
|
54
|
+
backgroundColor: "hsl(var(--accent) / 0.5)",
|
|
55
|
+
},
|
|
56
|
+
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":
|
|
57
|
+
{
|
|
58
|
+
backgroundColor: "hsl(var(--primary) / 0.3) !important",
|
|
59
|
+
},
|
|
60
|
+
"&.cm-focused .cm-cursor": {
|
|
61
|
+
borderLeftColor: "hsl(var(--primary))",
|
|
62
|
+
borderLeftWidth: "2px",
|
|
63
|
+
},
|
|
64
|
+
".cm-scroller": {
|
|
65
|
+
overflow: "auto",
|
|
66
|
+
},
|
|
67
|
+
".cm-foldGutter": {
|
|
68
|
+
color: "hsl(var(--muted-foreground))",
|
|
69
|
+
},
|
|
70
|
+
".cm-tooltip": {
|
|
71
|
+
backgroundColor: "hsl(var(--popover))",
|
|
72
|
+
boxShadow: "0 4px 12px hsl(var(--foreground) / 0.15)",
|
|
73
|
+
color: "hsl(var(--popover-foreground))",
|
|
74
|
+
},
|
|
75
|
+
".cm-tooltip-autocomplete": {
|
|
76
|
+
"& > ul > li[aria-selected]": {
|
|
77
|
+
backgroundColor: "hsl(var(--accent))",
|
|
78
|
+
color: "hsl(var(--accent-foreground))",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
".cm-panels": {
|
|
82
|
+
backgroundColor: "hsl(var(--muted))",
|
|
83
|
+
},
|
|
84
|
+
".cm-searchMatch": {
|
|
85
|
+
backgroundColor: "hsl(var(--primary) / 0.2)",
|
|
86
|
+
outline: "1px solid hsl(var(--primary) / 0.4)",
|
|
87
|
+
},
|
|
88
|
+
".cm-searchMatch.cm-searchMatch-selected": {
|
|
89
|
+
backgroundColor: "hsl(var(--primary) / 0.4)",
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Syntax highlighting that adapts to both light and dark themes
|
|
94
|
+
const highlightStyle = HighlightStyle.define([
|
|
95
|
+
{ tag: t.keyword, color: "hsl(var(--primary))" },
|
|
96
|
+
{
|
|
97
|
+
tag: [t.name, t.deleted, t.character, t.macroName],
|
|
98
|
+
color: "hsl(var(--foreground))",
|
|
99
|
+
},
|
|
100
|
+
{ tag: [t.propertyName], color: "#7dd3fc" }, // sky-300
|
|
101
|
+
{ tag: [t.function(t.variableName), t.labelName], color: "#c4b5fd" }, // violet-300
|
|
102
|
+
{ tag: [t.color, t.constant(t.name), t.standard(t.name)], color: "#fcd34d" }, // amber-300
|
|
103
|
+
{ tag: [t.definition(t.name), t.separator], color: "hsl(var(--foreground))" },
|
|
104
|
+
{
|
|
105
|
+
tag: [
|
|
106
|
+
t.typeName,
|
|
107
|
+
t.className,
|
|
108
|
+
t.number,
|
|
109
|
+
t.changed,
|
|
110
|
+
t.annotation,
|
|
111
|
+
t.modifier,
|
|
112
|
+
t.self,
|
|
113
|
+
t.namespace,
|
|
114
|
+
],
|
|
115
|
+
color: "#f9a8d4", // pink-300
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
tag: [
|
|
119
|
+
t.operator,
|
|
120
|
+
t.operatorKeyword,
|
|
121
|
+
t.url,
|
|
122
|
+
t.escape,
|
|
123
|
+
t.regexp,
|
|
124
|
+
t.special(t.string),
|
|
125
|
+
],
|
|
126
|
+
color: "#67e8f9", // cyan-300
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
tag: [t.meta, t.comment],
|
|
130
|
+
color: "hsl(var(--muted-foreground))",
|
|
131
|
+
fontStyle: "italic",
|
|
132
|
+
},
|
|
133
|
+
{ tag: t.strong, fontWeight: "bold" },
|
|
134
|
+
{ tag: t.emphasis, fontStyle: "italic" },
|
|
135
|
+
{ tag: t.strikethrough, textDecoration: "line-through" },
|
|
136
|
+
{ tag: t.link, color: "#67e8f9", textDecoration: "underline" },
|
|
137
|
+
{ tag: t.heading, fontWeight: "bold", color: "hsl(var(--primary))" },
|
|
138
|
+
{ tag: [t.atom, t.bool], color: "#f9a8d4" }, // pink-300
|
|
139
|
+
{ tag: [t.processingInstruction, t.string, t.inserted], color: "#86efac" }, // green-300
|
|
140
|
+
{ tag: t.invalid, color: "#fca5a5" }, // red-300
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
function getLanguageExtension(language: string): Extension | null {
|
|
144
|
+
switch (language) {
|
|
145
|
+
case "javascript":
|
|
146
|
+
return javascript({ jsx: true });
|
|
147
|
+
case "typescript":
|
|
148
|
+
return javascript({ jsx: true, typescript: true });
|
|
149
|
+
case "python":
|
|
150
|
+
return python();
|
|
151
|
+
case "json":
|
|
152
|
+
return json();
|
|
153
|
+
case "css":
|
|
154
|
+
case "scss":
|
|
155
|
+
return css();
|
|
156
|
+
case "html":
|
|
157
|
+
case "xml":
|
|
158
|
+
return html();
|
|
159
|
+
case "markdown":
|
|
160
|
+
return markdown();
|
|
161
|
+
default:
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function FileEditor({
|
|
167
|
+
content,
|
|
168
|
+
language,
|
|
169
|
+
isBinary,
|
|
170
|
+
readOnly = false,
|
|
171
|
+
onChange,
|
|
172
|
+
onSave,
|
|
173
|
+
}: FileEditorProps) {
|
|
174
|
+
const [extensions, setExtensions] = useState<Extension[]>([]);
|
|
175
|
+
const [previewMode, setPreviewMode] = useState(false);
|
|
176
|
+
const isMarkdown = language === "markdown";
|
|
177
|
+
const isHtml = language === "html";
|
|
178
|
+
const hasPreview = isMarkdown || isHtml;
|
|
179
|
+
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
const langExt = getLanguageExtension(language);
|
|
182
|
+
const baseExtensions: Extension[] = [
|
|
183
|
+
editorTheme,
|
|
184
|
+
syntaxHighlighting(highlightStyle),
|
|
185
|
+
EditorView.lineWrapping,
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
if (onSave) {
|
|
189
|
+
baseExtensions.push(
|
|
190
|
+
keymap.of([
|
|
191
|
+
{
|
|
192
|
+
key: "Mod-s",
|
|
193
|
+
run: () => {
|
|
194
|
+
onSave();
|
|
195
|
+
return true;
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
])
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (langExt) {
|
|
203
|
+
baseExtensions.push(langExt);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setExtensions(baseExtensions);
|
|
207
|
+
}, [language, onSave]);
|
|
208
|
+
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
if (!hasPreview) setPreviewMode(false);
|
|
211
|
+
}, [hasPreview]);
|
|
212
|
+
|
|
213
|
+
if (isBinary) {
|
|
214
|
+
return (
|
|
215
|
+
<div className="text-muted-foreground flex h-full flex-col items-center justify-center p-8">
|
|
216
|
+
<FileCode className="mb-4 h-12 w-12 opacity-50" />
|
|
217
|
+
<p className="text-center text-sm">Binary file cannot be displayed</p>
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<div className="bg-background flex h-full w-full flex-col overflow-hidden">
|
|
224
|
+
{hasPreview && (
|
|
225
|
+
<div className="bg-muted/30 flex items-center justify-end px-2 py-1 shadow-sm">
|
|
226
|
+
<Button
|
|
227
|
+
variant="ghost"
|
|
228
|
+
size="icon-sm"
|
|
229
|
+
onClick={() => setPreviewMode(!previewMode)}
|
|
230
|
+
title={previewMode ? "Show source" : "Preview"}
|
|
231
|
+
>
|
|
232
|
+
{previewMode ? (
|
|
233
|
+
<Code2 className="h-4 w-4" />
|
|
234
|
+
) : (
|
|
235
|
+
<Eye className="h-4 w-4" />
|
|
236
|
+
)}
|
|
237
|
+
</Button>
|
|
238
|
+
</div>
|
|
239
|
+
)}
|
|
240
|
+
|
|
241
|
+
<div className="min-h-0 flex-1 overflow-hidden">
|
|
242
|
+
{previewMode && isMarkdown ? (
|
|
243
|
+
<MarkdownRenderer content={content} />
|
|
244
|
+
) : previewMode && isHtml ? (
|
|
245
|
+
<HtmlRenderer content={content} />
|
|
246
|
+
) : (
|
|
247
|
+
<CodeMirror
|
|
248
|
+
value={content}
|
|
249
|
+
height="100%"
|
|
250
|
+
theme="none"
|
|
251
|
+
extensions={extensions}
|
|
252
|
+
onChange={onChange}
|
|
253
|
+
readOnly={readOnly}
|
|
254
|
+
basicSetup={{
|
|
255
|
+
lineNumbers: true,
|
|
256
|
+
highlightActiveLineGutter: true,
|
|
257
|
+
highlightActiveLine: true,
|
|
258
|
+
foldGutter: true,
|
|
259
|
+
dropCursor: true,
|
|
260
|
+
allowMultipleSelections: true,
|
|
261
|
+
indentOnInput: true,
|
|
262
|
+
bracketMatching: true,
|
|
263
|
+
closeBrackets: true,
|
|
264
|
+
autocompletion: true,
|
|
265
|
+
rectangularSelection: true,
|
|
266
|
+
crosshairCursor: false,
|
|
267
|
+
highlightSelectionMatches: true,
|
|
268
|
+
searchKeymap: true,
|
|
269
|
+
}}
|
|
270
|
+
className="h-full [&_.cm-editor]:h-full [&_.cm-scroller]:!overflow-auto"
|
|
271
|
+
/>
|
|
272
|
+
)}
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}
|