|
@ -2,14 +2,12 @@ |
|
|
* Copyright (c) Facebook, Inc. and its affiliates. |
|
|
* Copyright (c) Facebook, Inc. and its affiliates. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import React from 'react'; |
|
|
import * as React from 'react'; |
|
|
import { |
|
|
import {SandpackProvider} from '@codesandbox/sandpack-react'; |
|
|
SandpackProvider, |
|
|
|
|
|
SandpackSetup, |
|
|
|
|
|
SandpackFile, |
|
|
|
|
|
} from '@codesandbox/sandpack-react'; |
|
|
|
|
|
|
|
|
|
|
|
import {CustomPreset} from './CustomPreset'; |
|
|
import {CustomPreset} from './CustomPreset'; |
|
|
|
|
|
import {createFileMap} from './utils'; |
|
|
|
|
|
|
|
|
|
|
|
import type {SandpackSetup} from '@codesandbox/sandpack-react'; |
|
|
|
|
|
|
|
|
type SandpackProps = { |
|
|
type SandpackProps = { |
|
|
children: React.ReactChildren; |
|
|
children: React.ReactChildren; |
|
@ -17,7 +15,6 @@ type SandpackProps = { |
|
|
setup?: SandpackSetup; |
|
|
setup?: SandpackSetup; |
|
|
showDevTools?: boolean; |
|
|
showDevTools?: boolean; |
|
|
}; |
|
|
}; |
|
|
import {reducedCodeSnippet} from './utils'; |
|
|
|
|
|
|
|
|
|
|
|
const sandboxStyle = ` |
|
|
const sandboxStyle = ` |
|
|
* { |
|
|
* { |
|
@ -65,13 +62,13 @@ ul { |
|
|
} |
|
|
} |
|
|
`.trim();
|
|
|
`.trim();
|
|
|
|
|
|
|
|
|
function SandpackWrapper(props: SandpackProps) { |
|
|
function SandpackRoot(props: SandpackProps) { |
|
|
let {children, setup, autorun = true, showDevTools = false} = props; |
|
|
let {children, setup, autorun = true, showDevTools = false} = props; |
|
|
const [devToolsLoaded, setDevToolsLoaded] = React.useState(false); |
|
|
const [devToolsLoaded, setDevToolsLoaded] = React.useState(false); |
|
|
let codeSnippets = React.Children.toArray(children) as React.ReactElement[]; |
|
|
let codeSnippets = React.Children.toArray(children) as React.ReactElement[]; |
|
|
let isSingleFile = true; |
|
|
let isSingleFile = true; |
|
|
|
|
|
|
|
|
const files = reducedCodeSnippet(codeSnippets); |
|
|
const files = createFileMap(codeSnippets); |
|
|
|
|
|
|
|
|
files['/styles.css'] = { |
|
|
files['/styles.css'] = { |
|
|
code: [sandboxStyle, files['/styles.css']?.code ?? ''].join('\n\n'), |
|
|
code: [sandboxStyle, files['/styles.css']?.code ?? ''].join('\n\n'), |
|
@ -97,6 +94,6 @@ function SandpackWrapper(props: SandpackProps) { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
SandpackWrapper.displayName = 'Sandpack'; |
|
|
SandpackRoot.displayName = 'Sandpack'; |
|
|
|
|
|
|
|
|
export default SandpackWrapper; |
|
|
export default SandpackRoot; |