index.tsx 1.6 KB

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