forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lobehub:main' into database
- Loading branch information
Showing
5 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
src/app/(main)/chat/(workspace)/@portal/Artifacts/Body/Renderer/React.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/app/(main)/chat/(workspace)/@portal/Artifacts/Body/Renderer/React/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { SandpackLayout, SandpackPreview, SandpackProvider } from '@codesandbox/sandpack-react'; | ||
import { memo } from 'react'; | ||
|
||
import { useChatStore } from '@/store/chat'; | ||
import { chatPortalSelectors } from '@/store/chat/selectors'; | ||
|
||
import { createTemplateFiles } from './template'; | ||
|
||
interface ReactRendererProps { | ||
code: string; | ||
} | ||
|
||
const ReactRenderer = memo<ReactRendererProps>(({ code }) => { | ||
const title = useChatStore(chatPortalSelectors.artifactTitle); | ||
|
||
return ( | ||
<SandpackProvider | ||
customSetup={{ | ||
dependencies: { | ||
'@lshay/ui': 'latest', | ||
'@radix-ui/react-alert-dialog': 'latest', | ||
'@radix-ui/react-dialog': 'latest', | ||
'@radix-ui/react-icons': 'latest', | ||
'antd': 'latest', | ||
'class-variance-authority': 'latest', | ||
'clsx': 'latest', | ||
'lucide-react': 'latest', | ||
'recharts': 'latest', | ||
'tailwind-merge': 'latest', | ||
}, | ||
}} | ||
files={{ | ||
'App.tsx': code, | ||
...createTemplateFiles({ title }), | ||
}} | ||
options={{ | ||
externalResources: ['https://cdn.tailwindcss.com'], | ||
visibleFiles: ['App.tsx'], | ||
}} | ||
style={{ height: '100%' }} | ||
template="vite-react-ts" | ||
theme="auto" | ||
> | ||
<SandpackLayout style={{ height: '100%' }}> | ||
<SandpackPreview style={{ height: '100%' }} /> | ||
</SandpackLayout> | ||
</SandpackProvider> | ||
); | ||
}); | ||
|
||
export default ReactRenderer; |
32 changes: 32 additions & 0 deletions
32
src/app/(main)/chat/(workspace)/@portal/Artifacts/Body/Renderer/React/template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
interface TemplateFilesParams { | ||
title?: string; | ||
} | ||
export const createTemplateFiles = ({ title }: TemplateFilesParams = {}) => ({ | ||
'index.html': `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>${title || 'Artifacts App'}</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/index.tsx"></script> | ||
</body> | ||
</html> | ||
`, | ||
'vite.config.ts': { | ||
code: `import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
export default defineConfig({ | ||
plugins: [react()], | ||
resolve: { | ||
alias: { | ||
'@/components/ui': '@lshay/ui/components/default', | ||
}, | ||
}, | ||
});`, | ||
}, | ||
}); |