Compare commits

...
8 changed files with 314 additions and 96 deletions

No files matched your search

+31 -11
View File
@@ -195,6 +195,7 @@
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/code-frame": "^7.27.1",
"@babel/generator": "^7.28.5",
@@ -1830,6 +1831,7 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
},
@@ -1853,6 +1855,7 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
}
@@ -1874,6 +1877,7 @@
"resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",
"integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@dnd-kit/accessibility": "^3.1.1",
"@dnd-kit/utilities": "^3.2.2",
@@ -5404,8 +5408,7 @@
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
"integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/@types/cacheable-request": {
"version": "6.0.3",
@@ -5647,6 +5650,7 @@
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.20.tgz",
"integrity": "sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==",
"license": "MIT",
"peer": true,
"dependencies": {
"@types/prop-types": "*",
"csstype": "^3.0.2"
@@ -5658,6 +5662,7 @@
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
"devOptional": true,
"license": "MIT",
"peer": true,
"peerDependencies": {
"@types/react": "^18.0.0"
}
@@ -5762,6 +5767,7 @@
"integrity": "sha512-oU/OtYVydhXnumd0BobL9rkJg7wFJ9bFFPmSmB/bf/XWN85hlViji59ko6bSKBXyseT9V8l+CN1nwmlbiN0G7Q==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "8.31.1",
"@typescript-eslint/types": "8.31.1",
@@ -6108,6 +6114,7 @@
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"license": "MIT",
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -6552,6 +6559,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"baseline-browser-mapping": "^2.8.19",
"caniuse-lite": "^1.0.30001751",
@@ -6811,6 +6819,7 @@
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
"license": "MIT",
"peer": true,
"dependencies": {
"anymatch": "~3.1.2",
"braces": "~3.0.2",
@@ -7549,8 +7558,7 @@
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz",
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/dom-helpers": {
"version": "5.2.1",
@@ -7628,7 +7636,8 @@
"version": "8.6.0",
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz",
"integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==",
"license": "MIT"
"license": "MIT",
"peer": true
},
"node_modules/embla-carousel-react": {
"version": "8.6.0",
@@ -7927,6 +7936,7 @@
"integrity": "sha512-QldCVh/ztyKJJZLr4jXNUByx3gR+TDYZCRXEktiZoUR3PGy4qCmSbkxcIle8GEwGpb5JBZazlaJ/CxLidXdEbQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.12.1",
@@ -9274,6 +9284,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/runtime": "^7.27.6"
},
@@ -10043,6 +10054,7 @@
"integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"cssstyle": "^4.2.1",
"data-urls": "^5.0.0",
@@ -10439,7 +10451,6 @@
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"lz-string": "bin/bin.js"
}
@@ -12143,6 +12154,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"nanoid": "^3.3.8",
"picocolors": "^1.1.1",
@@ -12310,7 +12322,6 @@
"integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"ansi-regex": "^5.0.1",
"ansi-styles": "^5.0.0",
@@ -12326,7 +12337,6 @@
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=8"
}
@@ -12337,7 +12347,6 @@
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=10"
},
@@ -12350,8 +12359,7 @@
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/prismjs": {
"version": "1.30.0",
@@ -12491,6 +12499,7 @@
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0"
},
@@ -12517,6 +12526,7 @@
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0",
"scheduler": "^0.23.2"
@@ -12542,6 +12552,7 @@
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.56.1.tgz",
"integrity": "sha512-qWAVokhSpshhcEuQDSANHx3jiAEFzu2HAaaQIzi/r9FNPm1ioAvuJSD4EuZzWd7Al7nTRKcKPnBKO7sRn+zavQ==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18.0.0"
},
@@ -12590,6 +12601,7 @@
"resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-10.1.0.tgz",
"integrity": "sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@types/hast": "^3.0.0",
"@types/mdast": "^4.0.0",
@@ -13172,6 +13184,7 @@
"integrity": "sha512-C5VvvgCCyfyotVITIAv+4efVytl5F7wt+/I2i9q9GZcEXW9BP52YYOXC58igUi+LFZVHukErIIqQSWwv/M3WRw==",
"devOptional": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@types/estree": "1.0.7"
},
@@ -14223,6 +14236,7 @@
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
"license": "MIT",
"peer": true,
"dependencies": {
"@alloc/quick-lru": "^5.2.0",
"arg": "^5.0.2",
@@ -14426,6 +14440,7 @@
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@@ -14698,6 +14713,7 @@
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
"devOptional": true,
"license": "Apache-2.0",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -15207,6 +15223,7 @@
"integrity": "sha512-cZn6NDFE7wdTpINgs++ZJ4N49W2vRp8LCKrn3Ob1kYNtOo21vfDoaV5GzBfLU4MovSAB8uNRm4jgzVQZ+mBzPQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"esbuild": "^0.25.0",
"fdir": "^6.4.4",
@@ -15351,6 +15368,7 @@
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@@ -15821,6 +15839,7 @@
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"fast-deep-equal": "^3.1.3",
"fast-uri": "^3.0.1",
@@ -15897,6 +15916,7 @@
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"rollup": "dist/bin/rollup"
},
+271 -85
View File
@@ -1,16 +1,16 @@
import { encodeBase64 } from '@std/encoding/base64';
import { useState, useEffect, useCallback, useRef } from 'react';
import { useState, useEffect, useCallback, useRef, useMemo, memo } from 'react';
import { useTranslation } from 'react-i18next';
import { useProjectsManager } from '@/hooks/useProjectsManager';
import { useFS } from '@/hooks/useFS';
import { useFSPaths } from '@/hooks/useFSPaths';
import { addConsoleMessage, getConsoleMessages, type ConsoleMessage } from '@/lib/consoleMessages';
import { addConsoleMessage, getConsoleMessages, addConsoleMessageListener, removeConsoleMessageListener, type ConsoleMessage } from '@/lib/consoleMessages';
import { useConsoleError } from '@/hooks/useConsoleError';
import { useBuildProject } from '@/hooks/useBuildProject';
import { Tabs, TabsContent } from '@/components/ui/tabs';
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
import { Button } from '@/components/ui/button';
import { FolderOpen, ArrowLeft, Bug, Copy, Check, Play, Loader2, MenuIcon, Code, Rocket, X, Terminal } from 'lucide-react';
import { FolderOpen, ArrowLeft, Bug, Copy, Check, Play, Loader2, MenuIcon, Code, Rocket, Terminal, Trash2, ChevronRight } from 'lucide-react';
import { useIsMobile } from '@/hooks/useIsMobile';
import { GitStatusIndicator } from '@/components/GitStatusIndicator';
import { BrowserAddressBar } from '@/components/ui/browser-address-bar';
@@ -20,11 +20,6 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
import { cn } from '@/lib/utils';
import { FileTree } from './FileTree';
import { FileEditor } from './FileEditor';
@@ -88,6 +83,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
const [historyIndex, setHistoryIndex] = useState(0);
const [deployDialogOpen, setDeployDialogOpen] = useState(false);
const [showConsoleView, setShowConsoleView] = useState(false);
const iframeRef = useRef<HTMLIFrameElement>(null);
const { fs } = useFS();
const { projectsPath } = useFSPaths();
@@ -465,6 +461,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
setFileContent('');
setMobileCodeView('explorer');
setDesktopCodeView('files');
setShowConsoleView(false);
// Reset navigation history and state
setCurrentPath('/');
@@ -521,102 +518,282 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
}
};
const ConsoleDropdown = () => {
const [isOpen, setIsOpen] = useState(false);
const [copiedMessageIndex, setCopiedMessageIndex] = useState<number | null>(null);
// Constants
const CONSOLE_SORT_ORDER_KEY = 'consoleSortOrder';
const COPY_FEEDBACK_DURATION = 2000;
const MAX_CONSOLE_MESSAGES = 500; // Limit displayed messages for performance
const messages = isOpen ? getConsoleMessages() : [];
// Helper function to get message level color
const getMessageLevelColor = (level: ConsoleMessage['level']): string => {
switch (level) {
case 'error': return 'text-destructive';
case 'warn': return 'text-warning';
case 'info': return 'text-primary';
default: return 'text-muted-foreground';
}
};
const ConsoleToggleButton = () => {
return (
<Button
variant={showConsoleView ? "secondary" : "ghost"}
size="sm"
className="h-8 w-8 p-0 relative"
onClick={() => setShowConsoleView(!showConsoleView)}
title={showConsoleView ? "Show preview" : "Show console"}
>
<Bug className="h-4 w-4" />
{hasConsoleErrors && (
<span className="absolute -top-1 -right-1 h-3 w-3 rounded-full border-2 border-background bg-red-500" />
)}
</Button>
);
};
// Individual console message component - memoized for performance
const ConsoleMessage = memo(({ msg, index, copiedMessageIndex, onCopy }: {
msg: ConsoleMessage;
index: number;
copiedMessageIndex: number | null;
onCopy: (msg: ConsoleMessage, index: number) => void;
}) => {
return (
<div
className="group relative py-0.5 px-1 hover:bg-muted/50 transition-colors duration-150 rounded cursor-pointer"
onClick={(e) => {
e.stopPropagation();
onCopy(msg, index);
}}
>
<div className={cn(
"text-xs font-mono leading-tight whitespace-pre-wrap break-words",
getMessageLevelColor(msg.level)
)}>
{msg.message}
</div>
<Button
variant="ghost"
size="sm"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onCopy(msg, index);
}}
className="h-3 w-3 p-0 opacity-0 group-hover:opacity-100 transition-all duration-200 absolute right-1 top-1 hover:bg-muted/70 text-muted-foreground hover:text-foreground bg-background/80 rounded border"
>
{copiedMessageIndex === index ? (
<Check className="h-2 w-2 text-success" />
) : (
<Copy className="h-2 w-2" />
)}
</Button>
</div>
);
});
ConsoleMessage.displayName = 'ConsoleMessage';
const ConsoleView = () => {
const [copiedMessageIndex, setCopiedMessageIndex] = useState<number | null>(null);
const [isInitialLoad, setIsInitialLoad] = useState(true);
const [rawMessages, setRawMessages] = useState<ConsoleMessage[]>([]);
const [totalMessageCount, setTotalMessageCount] = useState(0);
// Load sort order from localStorage, default to 'newest-first'
const [sortOrder, setSortOrder] = useState<'newest-first' | 'oldest-first'>(() => {
const saved = localStorage.getItem(CONSOLE_SORT_ORDER_KEY);
return (saved === 'oldest-first' || saved === 'newest-first') ? saved : 'newest-first';
});
// Save sort order to localStorage whenever it changes
useEffect(() => {
localStorage.setItem(CONSOLE_SORT_ORDER_KEY, sortOrder);
}, [sortOrder]);
// Track rapid message bursts for intelligent batching
const lastMessageTimeRef = useRef<number>(0);
const pendingUpdateRef = useRef<number>();
const messageCountSinceUpdateRef = useRef<number>(0);
// Update messages from the global store - optimized for immediate updates
const updateMessages = useCallback(() => {
const allMessages = getConsoleMessages();
setTotalMessageCount(allMessages.length);
// Limit messages for performance (keep most recent)
const limitedMessages = allMessages.length > MAX_CONSOLE_MESSAGES
? allMessages.slice(-MAX_CONSOLE_MESSAGES)
: allMessages;
setRawMessages(limitedMessages);
setIsInitialLoad(false);
messageCountSinceUpdateRef.current = 0;
}, []);
// Smart update handler: immediate for single messages, batched for rapid bursts
const handleMessageUpdate = useCallback(() => {
const now = Date.now();
const timeSinceLastMessage = now - lastMessageTimeRef.current;
lastMessageTimeRef.current = now;
messageCountSinceUpdateRef.current += 1;
// Detect rapid bursts: if we get more than 3 messages within 50ms, batch them
const isRapidBurst = messageCountSinceUpdateRef.current > 3 && timeSinceLastMessage < 50;
// Clear any pending update
if (pendingUpdateRef.current) {
cancelAnimationFrame(pendingUpdateRef.current);
pendingUpdateRef.current = undefined;
}
if (isRapidBurst) {
// Batch rapid updates using requestAnimationFrame for smooth rendering
// This prevents UI blocking during loops that log many messages
pendingUpdateRef.current = requestAnimationFrame(() => {
updateMessages();
});
} else {
// Immediate update for normal console.log calls (like browser console)
// Single messages appear instantly, just like native browser console
updateMessages();
}
}, [updateMessages]);
// Initial load and listener setup
useEffect(() => {
// Initial load - check if we have many messages
const allMessages = getConsoleMessages();
if (allMessages.length > 500) {
setIsInitialLoad(true);
// Use requestIdleCallback for non-blocking initial render, fallback to setTimeout
const scheduleUpdate = () => {
if ('requestIdleCallback' in window) {
requestIdleCallback(() => {
updateMessages();
}, { timeout: 100 });
} else {
setTimeout(() => {
updateMessages();
}, 0);
}
};
scheduleUpdate();
} else {
updateMessages();
}
addConsoleMessageListener(handleMessageUpdate);
return () => {
removeConsoleMessageListener(handleMessageUpdate);
if (pendingUpdateRef.current) {
cancelAnimationFrame(pendingUpdateRef.current);
}
};
}, [handleMessageUpdate, updateMessages]);
// Memoize sorted messages to avoid recalculation on every render
const messages = useMemo(() => {
if (sortOrder === 'newest-first') {
// For newest-first, reverse the array (messages are stored oldest-first)
return [...rawMessages].reverse();
}
return rawMessages;
}, [rawMessages, sortOrder]);
const copyMessageToClipboard = async (msg: ConsoleMessage, index: number) => {
try {
await navigator.clipboard.writeText(msg.message);
setCopiedMessageIndex(index);
setTimeout(() => setCopiedMessageIndex(null), 2000);
setTimeout(() => setCopiedMessageIndex(null), COPY_FEEDBACK_DURATION);
} catch (error) {
console.error('Failed to copy message to clipboard:', error);
}
};
const handleClearMessages = () => {
clearErrors();
setCopiedMessageIndex(null);
};
const messageCount = messages.length;
const hasMoreMessages = rawMessages.length >= MAX_CONSOLE_MESSAGES;
return (
<Popover open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger asChild>
<div className="h-full w-full flex flex-col bg-background">
{/* Header */}
<div className="h-12 flex-shrink-0 flex items-center justify-between px-4 border-b">
<Button
variant="ghost"
size="sm"
className="h-8 w-8 p-0 relative"
onClick={() => setShowConsoleView(false)}
className="h-8 gap-2 text-muted-foreground hover:text-foreground"
>
<Bug className="h-4 w-4" />
{hasConsoleErrors && (
<span className="absolute -top-1 -right-1 h-3 w-3 rounded-full border-2 border-background bg-red-500" />
)}
<ArrowLeft className="h-4 w-4" />
Back
</Button>
</PopoverTrigger>
<PopoverContent
align="end"
className="w-[calc(100vw-1rem)] max-w-[480px] max-h-[512px] overflow-hidden shadow-lg border rounded-lg bg-background p-0"
sideOffset={4}
>
<div className="flex items-center gap-2">
{messageCount > 0 && (
<>
{hasMoreMessages && (
<span className="text-xs text-muted-foreground">
Showing last {MAX_CONSOLE_MESSAGES.toLocaleString()} of {totalMessageCount.toLocaleString()}
</span>
)}
<Button
variant="ghost"
size="sm"
onClick={() => setSortOrder(sortOrder === 'newest-first' ? 'oldest-first' : 'newest-first')}
className="h-8 text-muted-foreground hover:text-foreground"
>
{sortOrder === 'newest-first' ? t('latestFirst') : t('oldestFirst')}
</Button>
<Button
variant="ghost"
size="sm"
onClick={handleClearMessages}
className="h-8 w-8 p-0 text-destructive/80 hover:text-destructive"
>
<Trash2 className="h-4 w-4" />
</Button>
</>
)}
</div>
</div>
{/* Messages */}
<div className="h-[60vh] max-h-[512px] w-full bg-background text-foreground font-mono text-xs relative overflow-y-auto overflow-x-hidden [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]">
{/* Messages */}
<div className="flex-1 min-h-0 overflow-y-auto overflow-x-hidden [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none] bg-background text-foreground font-mono text-xs relative">
{isInitialLoad ? (
<div className="absolute inset-0 flex items-center justify-center z-10 bg-background">
<div className="flex flex-col items-center gap-2">
<Loader2 className="h-5 w-5 animate-spin text-primary" />
<span className="text-sm text-muted-foreground">Loading console messages...</span>
</div>
</div>
) : (
<div className="py-2 px-1 space-y-0">
{messageCount === 0 ? (
<div className="flex flex-col items-center justify-center py-12 text-center">
<p className="text-sm text-muted-foreground font-medium">No console messages</p>
<p className="text-xs text-muted-foreground mt-1">Messages from your project will appear here</p>
{/* Console prompt indicator - at top for newest-first, bottom for oldest-first */}
{sortOrder === 'newest-first' && (
<div className="py-0.5 px-1 flex items-center">
<ChevronRight className="h-3 w-3 text-muted-foreground" />
</div>
)}
{messages.map((msg, index) => (
<ConsoleMessage
key={`${index}-${msg.message.slice(0, 20)}`}
msg={msg}
index={index}
copiedMessageIndex={copiedMessageIndex}
onCopy={copyMessageToClipboard}
/>
))}
{sortOrder === 'oldest-first' && (
<div className="py-0.5 px-1 flex items-center">
<ChevronRight className="h-3 w-3 text-muted-foreground" />
</div>
) : (
messages.map((msg, index) => (
<div
key={index}
className="group relative py-0.5 px-1 hover:bg-muted/50 transition-colors duration-150 rounded cursor-pointer"
onClick={(e) => {
e.stopPropagation();
copyMessageToClipboard(msg, index);
}}
>
<div className={cn(
"text-xs font-mono leading-tight whitespace-pre-wrap break-words",
msg.level === 'error' ? "text-destructive" :
msg.level === 'warn' ? "text-warning" :
msg.level === 'info' ? "text-primary" :
"text-muted-foreground"
)}>
{msg.message}
</div>
<Button
variant="ghost"
size="sm"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
copyMessageToClipboard(msg, index);
}}
className="h-3 w-3 p-0 opacity-0 group-hover:opacity-100 transition-all duration-200 absolute right-1 top-1 hover:bg-muted/70 text-muted-foreground hover:text-foreground bg-background/80 rounded border"
>
{copiedMessageIndex === index ? (
<Check className="h-2 w-2 text-success" />
) : (
<Copy className="h-2 w-2" />
)}
</Button>
</div>
))
)}
</div>
</div>
{/* Close button */}
<button
onClick={() => setIsOpen(false)}
className="absolute top-2 right-2 h-8 w-8 p-0 bg-muted/50 hover:bg-muted/70 rounded-md z-10 flex items-center justify-center border"
>
<X className="h-5 w-5 text-muted-foreground" />
</button>
</PopoverContent>
</Popover>
)}
</div>
</div>
);
};
@@ -689,7 +866,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
<Code className="h-4 w-4" />
</Button>
)}
<ConsoleDropdown />
<ConsoleToggleButton />
<Menu />
</div>
)}
@@ -697,16 +874,25 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
</div>
{/* Content area */}
<div className="flex-1">
{hasBuiltProject ? (
<div className="flex-1 min-h-0 relative">
{/* Console View */}
<div className={cn("absolute inset-0", showConsoleView ? "block" : "hidden")}>
<ConsoleView />
</div>
{/* Preview iframe */}
{hasBuiltProject && (
<iframe
ref={iframeRef}
src={`https://${projectId}.${previewDomain}/`}
className="w-full h-full border-0"
className={cn("w-full h-full border-0", showConsoleView ? "hidden" : "block")}
title="Project Preview"
sandbox="allow-scripts allow-same-origin"
/>
) : (
)}
{/* Build prompt */}
{!hasBuiltProject && !showConsoleView && (
<div className="h-full flex items-center justify-center bg-muted">
<div className="text-center">
<h3 className="text-lg font-semibold mb-2">{t('projectPreview')}</h3>
+2
View File
@@ -87,6 +87,8 @@
"add": "Add",
"remove": "Remove",
"retry": "Retry",
"latestFirst": "Latest First",
"oldestFirst": "Oldest First",
"name": "Name",
"email": "Email",
"buildNostrApps": "Build apps with AI",
+2
View File
@@ -83,6 +83,8 @@
"add": "Ƙara",
"remove": "Cire",
"retry": "Sake gwadawa",
"latestFirst": "Na Baya-bayan nan Da farko",
"oldestFirst": "Na Dā Da farko",
"name": "Suna",
"email": "Imel",
"buildNostrApps": "Gina aikace-aikace da AI",
+2
View File
@@ -83,6 +83,8 @@
"add": "Tinye",
"remove": "Wepụ",
"retry": "Nwaa ọzọ",
"latestFirst": "Nke Ọhụrụ Mbụ",
"oldestFirst": "Nke Ochie Mbụ",
"name": "Aha",
"email": "Ozi-eletrọniki",
"buildNostrApps": "Wuo ngwa na AI",
+2
View File
@@ -83,6 +83,8 @@
"add": "Adicionar",
"remove": "Remover",
"retry": "Tentar novamente",
"latestFirst": "Mais Recentes Primeiro",
"oldestFirst": "Mais Antigos Primeiro",
"name": "Nome",
"email": "Email",
"buildNostrApps": "Construa aplicativos com IA",
+2
View File
@@ -83,6 +83,8 @@
"add": "Fi kun",
"remove": "Yọ kuro",
"retry": "Tun gbiyanju",
"latestFirst": "Tuntun Akọkọ",
"oldestFirst": "Atijọ Akọkọ",
"name": "Orukọ",
"email": "Imeeli",
"buildNostrApps": "Kọ awọn ohun elo pẹlu AI",
+2
View File
@@ -83,6 +83,8 @@
"add": "添加",
"remove": "移除",
"retry": "重试",
"latestFirst": "最新优先",
"oldestFirst": "最旧优先",
"name": "名称",
"email": "邮箱",
"buildNostrApps": "使用AI构建应用",