2024-08-27 17:03:16 -04:00
|
|
|
import dedent from 'dedent';
|
2025-07-04 13:23:37 -04:00
|
|
|
import { shadcnComponents } from 'librechat-data-provider';
|
2024-08-27 17:03:16 -04:00
|
|
|
import type {
|
|
|
|
|
SandpackProviderProps,
|
|
|
|
|
SandpackPredefinedTemplate,
|
|
|
|
|
} from '@codesandbox/sandpack-react';
|
|
|
|
|
|
|
|
|
|
const artifactFilename = {
|
|
|
|
|
'application/vnd.react': 'App.tsx',
|
🏎️ refactor: Replace Sandpack Code Editor with Monaco for Artifact Editing (#12109)
* refactor: Code Editor and Auto Scroll Functionality
- Added a useEffect hook in CodeEditor to sync streaming content with Sandpack without remounting the provider, improving performance and user experience.
- Updated useAutoScroll to accept an optional editorRef, allowing for dynamic scroll container selection based on the editor's state.
- Refactored ArtifactTabs to utilize the new editorRef in the useAutoScroll hook, ensuring consistent scrolling behavior during content updates.
- Introduced stableFiles and mergedFiles logic in CodeEditor to optimize file handling and prevent unnecessary updates during streaming content changes.
* refactor: Update CodeEditor to Sync Streaming Content Based on Read-Only State
- Modified the useEffect hook in CodeEditor to conditionally sync streaming content with Sandpack only when in read-only mode, preventing unnecessary updates during user edits.
- Enhanced the dependency array of the useEffect hook to include the readOnly state, ensuring accurate synchronization behavior.
* refactor: Monaco Editor for Artifact Code Editing
* refactor: Clean up ArtifactCodeEditor and ArtifactTabs components
- Removed unused scrollbar styles from mobile.css to streamline the code.
- Refactored ArtifactCodeEditor to improve content synchronization and read-only state handling.
- Enhanced ArtifactTabs by removing unnecessary context usage and optimizing component structure for better readability.
* feat: Add support for new artifact type 'application/vnd.ant.react'
- Introduced handling for 'application/vnd.ant.react' in artifactFilename, artifactTemplate, and dependenciesMap.
- Updated relevant mappings to ensure proper integration of the new artifact type within the application.
* refactor:ArtifactCodeEditor with Monaco Editor Configuration
- Added support for disabling validation in the Monaco Editor to improve the artifact viewer/editor experience.
- Introduced a new type definition for Monaco to enhance type safety.
- Updated the handling of the 'application/vnd.ant.react' artifact type to ensure proper integration with the editor.
* refactor: Clean up ArtifactCodeEditor and mobile.css
- Removed unnecessary whitespace in mobile.css for cleaner code.
- Refactored ArtifactCodeEditor to streamline language mapping and type handling, enhancing readability and maintainability.
- Consolidated language and type mappings into dedicated constants for improved clarity and efficiency.
* feat: Integrate Monaco Editor for Enhanced Code Editing Experience
- Added the Monaco Editor as a dependency to improve the code editing capabilities within the ArtifactCodeEditor component.
- Refactored the handling of TypeScript and JavaScript defaults in the Monaco Editor configuration for better type safety and clarity.
- Streamlined the setup for disabling validation, enhancing the artifact viewer/editor experience.
* fix: Update ArtifactCodeEditor to handle null content checks
- Modified conditional checks in ArtifactCodeEditor to use `art.content != null` instead of `art.content` for improved null safety.
- Ensured consistent handling of artifact content across various useEffect hooks to prevent potential errors when content is null.
* fix: Refine content comparison logic in ArtifactCodeEditor
- Updated the condition for checking if the code is not original by removing the redundant null check for `art.content`, ensuring more concise and clear logic.
- This change enhances the readability of the code and maintains the integrity of content comparison within the editor.
* fix: Simplify code comparison logic in ArtifactCodeEditor
- Removed redundant null check for the `code` variable, ensuring a more straightforward comparison with the current update reference.
- This change improves code clarity and maintains the integrity of the content comparison logic within the editor.
2026-03-06 15:02:04 -05:00
|
|
|
'application/vnd.ant.react': 'App.tsx',
|
2024-08-27 17:03:16 -04:00
|
|
|
'text/html': 'index.html',
|
|
|
|
|
'application/vnd.code-html': 'index.html',
|
2025-10-11 23:37:35 +09:00
|
|
|
// mermaid and markdown types are handled separately in useArtifactProps.ts
|
2024-08-27 17:03:16 -04:00
|
|
|
default: 'index.html',
|
|
|
|
|
// 'css': 'css',
|
|
|
|
|
// 'javascript': 'js',
|
|
|
|
|
// 'typescript': 'ts',
|
|
|
|
|
// 'jsx': 'jsx',
|
|
|
|
|
// 'tsx': 'tsx',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const artifactTemplate: Record<
|
2025-10-11 23:37:35 +09:00
|
|
|
| keyof typeof artifactFilename
|
|
|
|
|
| 'application/vnd.mermaid'
|
|
|
|
|
| 'text/markdown'
|
|
|
|
|
| 'text/md'
|
|
|
|
|
| 'text/plain',
|
2024-08-27 17:03:16 -04:00
|
|
|
SandpackPredefinedTemplate | undefined
|
|
|
|
|
> = {
|
|
|
|
|
'text/html': 'static',
|
|
|
|
|
'application/vnd.react': 'react-ts',
|
🏎️ refactor: Replace Sandpack Code Editor with Monaco for Artifact Editing (#12109)
* refactor: Code Editor and Auto Scroll Functionality
- Added a useEffect hook in CodeEditor to sync streaming content with Sandpack without remounting the provider, improving performance and user experience.
- Updated useAutoScroll to accept an optional editorRef, allowing for dynamic scroll container selection based on the editor's state.
- Refactored ArtifactTabs to utilize the new editorRef in the useAutoScroll hook, ensuring consistent scrolling behavior during content updates.
- Introduced stableFiles and mergedFiles logic in CodeEditor to optimize file handling and prevent unnecessary updates during streaming content changes.
* refactor: Update CodeEditor to Sync Streaming Content Based on Read-Only State
- Modified the useEffect hook in CodeEditor to conditionally sync streaming content with Sandpack only when in read-only mode, preventing unnecessary updates during user edits.
- Enhanced the dependency array of the useEffect hook to include the readOnly state, ensuring accurate synchronization behavior.
* refactor: Monaco Editor for Artifact Code Editing
* refactor: Clean up ArtifactCodeEditor and ArtifactTabs components
- Removed unused scrollbar styles from mobile.css to streamline the code.
- Refactored ArtifactCodeEditor to improve content synchronization and read-only state handling.
- Enhanced ArtifactTabs by removing unnecessary context usage and optimizing component structure for better readability.
* feat: Add support for new artifact type 'application/vnd.ant.react'
- Introduced handling for 'application/vnd.ant.react' in artifactFilename, artifactTemplate, and dependenciesMap.
- Updated relevant mappings to ensure proper integration of the new artifact type within the application.
* refactor:ArtifactCodeEditor with Monaco Editor Configuration
- Added support for disabling validation in the Monaco Editor to improve the artifact viewer/editor experience.
- Introduced a new type definition for Monaco to enhance type safety.
- Updated the handling of the 'application/vnd.ant.react' artifact type to ensure proper integration with the editor.
* refactor: Clean up ArtifactCodeEditor and mobile.css
- Removed unnecessary whitespace in mobile.css for cleaner code.
- Refactored ArtifactCodeEditor to streamline language mapping and type handling, enhancing readability and maintainability.
- Consolidated language and type mappings into dedicated constants for improved clarity and efficiency.
* feat: Integrate Monaco Editor for Enhanced Code Editing Experience
- Added the Monaco Editor as a dependency to improve the code editing capabilities within the ArtifactCodeEditor component.
- Refactored the handling of TypeScript and JavaScript defaults in the Monaco Editor configuration for better type safety and clarity.
- Streamlined the setup for disabling validation, enhancing the artifact viewer/editor experience.
* fix: Update ArtifactCodeEditor to handle null content checks
- Modified conditional checks in ArtifactCodeEditor to use `art.content != null` instead of `art.content` for improved null safety.
- Ensured consistent handling of artifact content across various useEffect hooks to prevent potential errors when content is null.
* fix: Refine content comparison logic in ArtifactCodeEditor
- Updated the condition for checking if the code is not original by removing the redundant null check for `art.content`, ensuring more concise and clear logic.
- This change enhances the readability of the code and maintains the integrity of content comparison within the editor.
* fix: Simplify code comparison logic in ArtifactCodeEditor
- Removed redundant null check for the `code` variable, ensuring a more straightforward comparison with the current update reference.
- This change improves code clarity and maintains the integrity of the content comparison logic within the editor.
2026-03-06 15:02:04 -05:00
|
|
|
'application/vnd.ant.react': 'react-ts',
|
2024-08-27 17:03:16 -04:00
|
|
|
'application/vnd.mermaid': 'react-ts',
|
|
|
|
|
'application/vnd.code-html': 'static',
|
2026-03-20 13:31:08 -04:00
|
|
|
'text/markdown': 'static',
|
|
|
|
|
'text/md': 'static',
|
|
|
|
|
'text/plain': 'static',
|
2024-08-27 17:03:16 -04:00
|
|
|
default: 'static',
|
|
|
|
|
// 'css': 'css',
|
|
|
|
|
// 'javascript': 'js',
|
|
|
|
|
// 'typescript': 'ts',
|
|
|
|
|
// 'jsx': 'jsx',
|
|
|
|
|
// 'tsx': 'tsx',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function getKey(type: string, language?: string): string {
|
|
|
|
|
return `${type}${(language?.length ?? 0) > 0 ? `-${language}` : ''}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getArtifactFilename(type: string, language?: string): string {
|
|
|
|
|
const key = getKey(type, language);
|
|
|
|
|
return artifactFilename[key] ?? artifactFilename.default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getTemplate(type: string, language?: string): SandpackPredefinedTemplate {
|
|
|
|
|
const key = getKey(type, language);
|
|
|
|
|
return artifactTemplate[key] ?? (artifactTemplate.default as SandpackPredefinedTemplate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const standardDependencies = {
|
|
|
|
|
three: '^0.167.1',
|
|
|
|
|
'lucide-react': '^0.394.0',
|
|
|
|
|
'react-router-dom': '^6.11.2',
|
|
|
|
|
'class-variance-authority': '^0.6.0',
|
|
|
|
|
clsx: '^1.2.1',
|
|
|
|
|
'date-fns': '^3.3.1',
|
|
|
|
|
'tailwind-merge': '^1.9.1',
|
|
|
|
|
'tailwindcss-animate': '^1.0.5',
|
|
|
|
|
recharts: '2.12.7',
|
|
|
|
|
'@radix-ui/react-accordion': '^1.1.2',
|
|
|
|
|
'@radix-ui/react-alert-dialog': '^1.0.2',
|
|
|
|
|
'@radix-ui/react-aspect-ratio': '^1.1.0',
|
|
|
|
|
'@radix-ui/react-avatar': '^1.1.0',
|
|
|
|
|
'@radix-ui/react-checkbox': '^1.0.3',
|
|
|
|
|
'@radix-ui/react-collapsible': '^1.0.3',
|
|
|
|
|
'@radix-ui/react-dialog': '^1.0.2',
|
|
|
|
|
'@radix-ui/react-dropdown-menu': '^2.1.1',
|
|
|
|
|
'@radix-ui/react-hover-card': '^1.0.5',
|
|
|
|
|
'@radix-ui/react-label': '^2.0.0',
|
|
|
|
|
'@radix-ui/react-menubar': '^1.1.1',
|
|
|
|
|
'@radix-ui/react-navigation-menu': '^1.2.0',
|
|
|
|
|
'@radix-ui/react-popover': '^1.0.7',
|
|
|
|
|
'@radix-ui/react-progress': '^1.1.0',
|
|
|
|
|
'@radix-ui/react-radio-group': '^1.1.3',
|
|
|
|
|
'@radix-ui/react-select': '^2.0.0',
|
|
|
|
|
'@radix-ui/react-separator': '^1.0.3',
|
|
|
|
|
'@radix-ui/react-slider': '^1.1.1',
|
|
|
|
|
'@radix-ui/react-switch': '^1.0.3',
|
|
|
|
|
'@radix-ui/react-tabs': '^1.0.3',
|
|
|
|
|
'@radix-ui/react-toast': '^1.1.5',
|
|
|
|
|
'@radix-ui/react-slot': '^1.1.0',
|
|
|
|
|
'@radix-ui/react-toggle': '^1.1.0',
|
|
|
|
|
'@radix-ui/react-toggle-group': '^1.1.0',
|
2025-10-17 09:26:14 +13:00
|
|
|
'@radix-ui/react-tooltip': '^1.2.8',
|
2024-08-27 17:03:16 -04:00
|
|
|
'embla-carousel-react': '^8.2.0',
|
|
|
|
|
'react-day-picker': '^9.0.8',
|
2024-10-19 14:34:57 +02:00
|
|
|
'dat.gui': '^0.7.9',
|
2024-08-27 17:03:16 -04:00
|
|
|
vaul: '^0.9.1',
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-11 23:37:35 +09:00
|
|
|
const mermaidDependencies = {
|
|
|
|
|
mermaid: '^11.4.1',
|
|
|
|
|
'react-zoom-pan-pinch': '^3.6.1',
|
|
|
|
|
'class-variance-authority': '^0.6.0',
|
|
|
|
|
clsx: '^1.2.1',
|
|
|
|
|
'tailwind-merge': '^1.9.1',
|
|
|
|
|
'@radix-ui/react-slot': '^1.1.0',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const dependenciesMap: Record<
|
|
|
|
|
| keyof typeof artifactFilename
|
|
|
|
|
| 'application/vnd.mermaid'
|
|
|
|
|
| 'text/markdown'
|
|
|
|
|
| 'text/md'
|
|
|
|
|
| 'text/plain',
|
|
|
|
|
Record<string, string>
|
|
|
|
|
> = {
|
2024-08-27 17:03:16 -04:00
|
|
|
'application/vnd.mermaid': mermaidDependencies,
|
|
|
|
|
'application/vnd.react': standardDependencies,
|
🏎️ refactor: Replace Sandpack Code Editor with Monaco for Artifact Editing (#12109)
* refactor: Code Editor and Auto Scroll Functionality
- Added a useEffect hook in CodeEditor to sync streaming content with Sandpack without remounting the provider, improving performance and user experience.
- Updated useAutoScroll to accept an optional editorRef, allowing for dynamic scroll container selection based on the editor's state.
- Refactored ArtifactTabs to utilize the new editorRef in the useAutoScroll hook, ensuring consistent scrolling behavior during content updates.
- Introduced stableFiles and mergedFiles logic in CodeEditor to optimize file handling and prevent unnecessary updates during streaming content changes.
* refactor: Update CodeEditor to Sync Streaming Content Based on Read-Only State
- Modified the useEffect hook in CodeEditor to conditionally sync streaming content with Sandpack only when in read-only mode, preventing unnecessary updates during user edits.
- Enhanced the dependency array of the useEffect hook to include the readOnly state, ensuring accurate synchronization behavior.
* refactor: Monaco Editor for Artifact Code Editing
* refactor: Clean up ArtifactCodeEditor and ArtifactTabs components
- Removed unused scrollbar styles from mobile.css to streamline the code.
- Refactored ArtifactCodeEditor to improve content synchronization and read-only state handling.
- Enhanced ArtifactTabs by removing unnecessary context usage and optimizing component structure for better readability.
* feat: Add support for new artifact type 'application/vnd.ant.react'
- Introduced handling for 'application/vnd.ant.react' in artifactFilename, artifactTemplate, and dependenciesMap.
- Updated relevant mappings to ensure proper integration of the new artifact type within the application.
* refactor:ArtifactCodeEditor with Monaco Editor Configuration
- Added support for disabling validation in the Monaco Editor to improve the artifact viewer/editor experience.
- Introduced a new type definition for Monaco to enhance type safety.
- Updated the handling of the 'application/vnd.ant.react' artifact type to ensure proper integration with the editor.
* refactor: Clean up ArtifactCodeEditor and mobile.css
- Removed unnecessary whitespace in mobile.css for cleaner code.
- Refactored ArtifactCodeEditor to streamline language mapping and type handling, enhancing readability and maintainability.
- Consolidated language and type mappings into dedicated constants for improved clarity and efficiency.
* feat: Integrate Monaco Editor for Enhanced Code Editing Experience
- Added the Monaco Editor as a dependency to improve the code editing capabilities within the ArtifactCodeEditor component.
- Refactored the handling of TypeScript and JavaScript defaults in the Monaco Editor configuration for better type safety and clarity.
- Streamlined the setup for disabling validation, enhancing the artifact viewer/editor experience.
* fix: Update ArtifactCodeEditor to handle null content checks
- Modified conditional checks in ArtifactCodeEditor to use `art.content != null` instead of `art.content` for improved null safety.
- Ensured consistent handling of artifact content across various useEffect hooks to prevent potential errors when content is null.
* fix: Refine content comparison logic in ArtifactCodeEditor
- Updated the condition for checking if the code is not original by removing the redundant null check for `art.content`, ensuring more concise and clear logic.
- This change enhances the readability of the code and maintains the integrity of content comparison within the editor.
* fix: Simplify code comparison logic in ArtifactCodeEditor
- Removed redundant null check for the `code` variable, ensuring a more straightforward comparison with the current update reference.
- This change improves code clarity and maintains the integrity of the content comparison logic within the editor.
2026-03-06 15:02:04 -05:00
|
|
|
'application/vnd.ant.react': standardDependencies,
|
2024-08-27 17:03:16 -04:00
|
|
|
'text/html': standardDependencies,
|
|
|
|
|
'application/vnd.code-html': standardDependencies,
|
2026-03-20 13:31:08 -04:00
|
|
|
'text/markdown': {},
|
|
|
|
|
'text/md': {},
|
|
|
|
|
'text/plain': {},
|
2024-08-27 17:03:16 -04:00
|
|
|
default: standardDependencies,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function getDependencies(type: string): Record<string, string> {
|
|
|
|
|
return dependenciesMap[type] ?? standardDependencies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getProps(type: string): Partial<SandpackProviderProps> {
|
|
|
|
|
return {
|
|
|
|
|
customSetup: {
|
|
|
|
|
dependencies: getDependencies(type),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const sharedOptions: SandpackProviderProps['options'] = {
|
2025-10-31 07:49:00 +13:00
|
|
|
externalResources: ['https://cdn.tailwindcss.com/3.4.17'],
|
2024-08-27 17:03:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const sharedFiles = {
|
|
|
|
|
'/lib/utils.ts': shadcnComponents.utils,
|
|
|
|
|
'/components/ui/accordion.tsx': shadcnComponents.accordian,
|
|
|
|
|
'/components/ui/alert-dialog.tsx': shadcnComponents.alertDialog,
|
|
|
|
|
'/components/ui/alert.tsx': shadcnComponents.alert,
|
|
|
|
|
'/components/ui/avatar.tsx': shadcnComponents.avatar,
|
|
|
|
|
'/components/ui/badge.tsx': shadcnComponents.badge,
|
|
|
|
|
'/components/ui/breadcrumb.tsx': shadcnComponents.breadcrumb,
|
|
|
|
|
'/components/ui/button.tsx': shadcnComponents.button,
|
|
|
|
|
'/components/ui/calendar.tsx': shadcnComponents.calendar,
|
|
|
|
|
'/components/ui/card.tsx': shadcnComponents.card,
|
|
|
|
|
'/components/ui/carousel.tsx': shadcnComponents.carousel,
|
|
|
|
|
'/components/ui/checkbox.tsx': shadcnComponents.checkbox,
|
|
|
|
|
'/components/ui/collapsible.tsx': shadcnComponents.collapsible,
|
|
|
|
|
'/components/ui/dialog.tsx': shadcnComponents.dialog,
|
|
|
|
|
'/components/ui/drawer.tsx': shadcnComponents.drawer,
|
|
|
|
|
'/components/ui/dropdown-menu.tsx': shadcnComponents.dropdownMenu,
|
|
|
|
|
'/components/ui/input.tsx': shadcnComponents.input,
|
|
|
|
|
'/components/ui/label.tsx': shadcnComponents.label,
|
|
|
|
|
'/components/ui/menubar.tsx': shadcnComponents.menuBar,
|
|
|
|
|
'/components/ui/navigation-menu.tsx': shadcnComponents.navigationMenu,
|
|
|
|
|
'/components/ui/pagination.tsx': shadcnComponents.pagination,
|
|
|
|
|
'/components/ui/popover.tsx': shadcnComponents.popover,
|
|
|
|
|
'/components/ui/progress.tsx': shadcnComponents.progress,
|
|
|
|
|
'/components/ui/radio-group.tsx': shadcnComponents.radioGroup,
|
|
|
|
|
'/components/ui/select.tsx': shadcnComponents.select,
|
|
|
|
|
'/components/ui/separator.tsx': shadcnComponents.separator,
|
|
|
|
|
'/components/ui/skeleton.tsx': shadcnComponents.skeleton,
|
|
|
|
|
'/components/ui/slider.tsx': shadcnComponents.slider,
|
|
|
|
|
'/components/ui/switch.tsx': shadcnComponents.switchComponent,
|
|
|
|
|
'/components/ui/table.tsx': shadcnComponents.table,
|
|
|
|
|
'/components/ui/tabs.tsx': shadcnComponents.tabs,
|
|
|
|
|
'/components/ui/textarea.tsx': shadcnComponents.textarea,
|
|
|
|
|
'/components/ui/toast.tsx': shadcnComponents.toast,
|
|
|
|
|
'/components/ui/toaster.tsx': shadcnComponents.toaster,
|
|
|
|
|
'/components/ui/toggle-group.tsx': shadcnComponents.toggleGroup,
|
|
|
|
|
'/components/ui/toggle.tsx': shadcnComponents.toggle,
|
|
|
|
|
'/components/ui/tooltip.tsx': shadcnComponents.tooltip,
|
|
|
|
|
'/components/ui/use-toast.tsx': shadcnComponents.useToast,
|
|
|
|
|
'/public/index.html': dedent`
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
<title>Document</title>
|
2025-10-31 07:49:00 +13:00
|
|
|
<script src="https://cdn.tailwindcss.com/3.4.17"></script>
|
2024-08-27 17:03:16 -04:00
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div id="root"></div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
`,
|
|
|
|
|
};
|