LibreChat/client/src/components/Artifacts/ArtifactPreview.tsx
Marco Beretta 7e1d02bcc3
feat: Enhance artifact panel animations and improve UI responsiveness
- Updated Thinking component button styles for smoother transitions.
- Implemented dynamic rendering for artifacts panel with animation effects.
- Refactored localization keys for consistency across multiple languages.
- Added new CSS animations for iOS-inspired smooth transitions.
- Improved Tailwind CSS configuration to support enhanced animation effects.
2025-10-24 11:08:57 +02:00

72 lines
1.8 KiB
TypeScript

import React, { memo, useMemo, type MutableRefObject } from 'react';
import { SandpackPreview, SandpackProvider } from '@codesandbox/sandpack-react/unstyled';
import type {
SandpackProviderProps,
SandpackPreviewRef,
PreviewProps,
} from '@codesandbox/sandpack-react/unstyled';
import type { TStartupConfig } from 'librechat-data-provider';
import type { ArtifactFiles } from '~/common';
import { sharedFiles, sharedOptions } from '~/utils/artifacts';
export const ArtifactPreview = memo(function ({
files,
fileKey,
template,
sharedProps,
previewRef,
currentCode,
startupConfig,
}: {
files: ArtifactFiles;
fileKey: string;
template: SandpackProviderProps['template'];
sharedProps: Partial<SandpackProviderProps>;
previewRef: MutableRefObject<SandpackPreviewRef>;
currentCode?: string;
startupConfig?: TStartupConfig;
}) {
const artifactFiles = useMemo(() => {
if (Object.keys(files).length === 0) {
return files;
}
const code = currentCode ?? '';
if (!code) {
return files;
}
return {
...files,
[fileKey]: { code },
};
}, [currentCode, files, fileKey]);
const options: typeof sharedOptions = useMemo(() => {
if (!startupConfig) {
return sharedOptions;
}
return {
...sharedOptions,
bundlerURL: template === 'static' ? startupConfig.staticBundlerURL : startupConfig.bundlerURL,
};
}, [startupConfig, template]);
if (Object.keys(artifactFiles).length === 0) {
return null;
}
return (
<SandpackProvider
files={{ ...artifactFiles, ...sharedFiles }}
options={options}
{...sharedProps}
template={template}
>
<SandpackPreview
showOpenInCodeSandbox={false}
showRefreshButton={false}
tabIndex={0}
ref={previewRef}
/>
</SandpackProvider>
);
});