From 8b7e18e62795248f11c2b3cb469f92ca4795a055 Mon Sep 17 00:00:00 2001 From: Ed McConnell Date: Thu, 5 Dec 2024 17:30:45 -0500 Subject: [PATCH 1/7] Initial commit for screen cap feature --- app/components/chat/BaseChat.tsx | 11 + .../chat/ScreenshotStateManager.tsx | 33 +++ app/components/workbench/Preview.tsx | 14 +- .../workbench/ScreenshotSelector.tsx | 203 ++++++++++++++++++ 4 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 app/components/chat/ScreenshotStateManager.tsx create mode 100644 app/components/workbench/ScreenshotSelector.tsx diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 8c7589a68..ed317e464 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -25,6 +25,7 @@ import { ExamplePrompts } from '~/components/chat/ExamplePrompts'; import FilePreview from './FilePreview'; import { ModelSelector } from '~/components/chat/ModelSelector'; import { SpeechRecognitionButton } from '~/components/chat/SpeechRecognition'; +import { ScreenshotStateManager } from './ScreenshotStateManager'; const TEXTAREA_MIN_HEIGHT = 76; @@ -376,6 +377,16 @@ export const BaseChat = React.forwardRef( setImageDataList?.(imageDataList.filter((_, i) => i !== index)); }} /> + + {() => ( + + )} +
void; + setImageDataList?: (dataList: string[]) => void; + uploadedFiles: File[]; + imageDataList: string[]; +} + +export const ScreenshotStateManager = ({ + setUploadedFiles, + setImageDataList, + uploadedFiles, + imageDataList, +}: ScreenshotStateManagerProps) => { + useEffect(() => { + if (setUploadedFiles && setImageDataList) { + (window as any).__BOLT_SET_UPLOADED_FILES__ = setUploadedFiles; + (window as any).__BOLT_SET_IMAGE_DATA_LIST__ = setImageDataList; + (window as any).__BOLT_UPLOADED_FILES__ = uploadedFiles; + (window as any).__BOLT_IMAGE_DATA_LIST__ = imageDataList; + } + + return () => { + delete (window as any).__BOLT_SET_UPLOADED_FILES__; + delete (window as any).__BOLT_SET_IMAGE_DATA_LIST__; + delete (window as any).__BOLT_UPLOADED_FILES__; + delete (window as any).__BOLT_IMAGE_DATA_LIST__; + }; + }, [setUploadedFiles, setImageDataList, uploadedFiles, imageDataList]); + + return null; +}; diff --git a/app/components/workbench/Preview.tsx b/app/components/workbench/Preview.tsx index 4c1877c5d..a86667643 100644 --- a/app/components/workbench/Preview.tsx +++ b/app/components/workbench/Preview.tsx @@ -3,6 +3,7 @@ import { memo, useCallback, useEffect, useRef, useState } from 'react'; import { IconButton } from '~/components/ui/IconButton'; import { workbenchStore } from '~/lib/stores/workbench'; import { PortDropdown } from './PortDropdown'; +import { ScreenshotSelector } from './ScreenshotSelector'; export const Preview = memo(() => { const iframeRef = useRef(null); @@ -15,6 +16,7 @@ export const Preview = memo(() => { const [url, setUrl] = useState(''); const [iframeUrl, setIframeUrl] = useState(); + const [isSelectionMode, setIsSelectionMode] = useState(false); useEffect(() => { if (!activePreview) { @@ -25,7 +27,7 @@ export const Preview = memo(() => { } const { baseUrl } = activePreview; - + setUrl(baseUrl); setIframeUrl(baseUrl); }, [activePreview, iframeUrl]); @@ -78,18 +80,19 @@ export const Preview = memo(() => { )}
+ setIsSelectionMode(!isSelectionMode)} className={isSelectionMode ? 'bg-bolt-elements-background-depth-3' : ''} />
- { setUrl(event.target.value); - }} + }} onKeyDown={(event) => { if (event.key === 'Enter' && validateUrl(url)) { setIframeUrl(url); @@ -114,7 +117,10 @@ export const Preview = memo(() => {
{activePreview ? ( -