index.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { FC } from 'react';
  6. import { Sandpack } from '@codesandbox/sandpack-react';
  7. interface CodePreviewProps {
  8. files: Record<string, string>;
  9. activeFile?: string;
  10. }
  11. export const CodePreview: FC<CodePreviewProps> = ({ files, activeFile }) => (
  12. <Sandpack
  13. files={files}
  14. theme="light"
  15. template="react-ts"
  16. customSetup={{
  17. dependencies: {
  18. '@flowgram.ai/free-layout-editor': '0.5.5',
  19. '@flowgram.ai/free-snap-plugin': '0.5.5',
  20. '@flowgram.ai/minimap-plugin': '0.5.5',
  21. 'styled-components': '5.3.11',
  22. },
  23. }}
  24. options={{
  25. editorHeight: 350,
  26. activeFile,
  27. }}
  28. />
  29. );
  30. export const FixedLayoutCodePreview: FC<CodePreviewProps> = ({ files, activeFile }) => (
  31. <Sandpack
  32. files={files}
  33. theme="light"
  34. template="react-ts"
  35. customSetup={{
  36. dependencies: {
  37. '@flowgram.ai/fixed-layout-editor': '0.1.0-alpha.19',
  38. // 为了解决semi无法在sandpack使用的问题,单独发了包,将semi打包进@flowgram.ai/fixed-semi-materials中
  39. '@flowgram.ai/fixed-semi-materials': '0.1.0-alpha.19',
  40. '@flowgram.ai/minimap-plugin': '0.1.0-alpha.19',
  41. 'styled-components': '5.3.11',
  42. },
  43. }}
  44. options={{
  45. editorHeight: 350,
  46. activeFile,
  47. }}
  48. />
  49. );