Add tool edit page

This commit is contained in:
2024-01-31 18:07:16 +08:00
parent d6ff952596
commit 28140543c4
11 changed files with 254 additions and 22 deletions

View File

@@ -8,9 +8,18 @@ interface PreviewProps {
files: IFiles
importMap: IImportMap
entryPoint: string
preExpansionCode?: string
postExpansionCode?: string
}
const Preview = ({ iframeKey, files, importMap, entryPoint }: PreviewProps) => {
const Preview = ({
iframeKey,
files,
importMap,
entryPoint,
preExpansionCode = '',
postExpansionCode = ''
}: PreviewProps) => {
const [errorMsg, setErrorMsg] = useState('')
const [compiledCode, setCompiledCode] = useState('')
@@ -19,14 +28,19 @@ const Preview = ({ iframeKey, files, importMap, entryPoint }: PreviewProps) => {
}
useEffect(() => {
if (!Object.keys(files).length || !importMap || !entryPoint.length) {
return
}
Compiler.compile(files, importMap, entryPoint)
.then((result) => {
setCompiledCode(result.outputFiles[0].text)
setCompiledCode(
`${preExpansionCode}\n${result.outputFiles[0].text}\n${postExpansionCode}`
)
})
.catch((e: Error) => {
setErrorMsg(`编译失败:${e.message}`)
})
}, [files, Compiler])
}, [files, Compiler, importMap, entryPoint])
return (
<div data-component={'playground-preview'}>

View File

@@ -3,4 +3,14 @@
position: relative;
width: 100%;
height: 100%;
.playground-error-message {
position: absolute;
bottom: 0;
width: 100%;
color: white;
background-color: #FF4D4FAA;
padding: 5px 10px;
font-size: 1.2em;
}
}

View File

@@ -9,9 +9,18 @@ interface OutputProps {
selectedFileName: string
importMap: IImportMap
entryPoint: string
preExpansionCode?: string
postExpansionCode?: string
}
const Output = ({ files, selectedFileName, importMap, entryPoint }: OutputProps) => {
const Output = ({
files,
selectedFileName,
importMap,
entryPoint,
preExpansionCode,
postExpansionCode
}: OutputProps) => {
const [selectedTab, setSelectedTab] = useState('Preview')
return (
@@ -31,6 +40,8 @@ const Output = ({ files, selectedFileName, importMap, entryPoint }: OutputProps)
files={files}
importMap={importMap}
entryPoint={entryPoint}
preExpansionCode={preExpansionCode}
postExpansionCode={postExpansionCode}
/>
)}
{selectedTab === 'Transform' && <Transform file={files[selectedFileName]} />}

View File

@@ -5,14 +5,4 @@
> * {
width: 0 !important;
}
.playground-error-message {
position: absolute;
bottom: 0;
width: 100%;
color: white;
background-color: #FF4D4FAA;
padding: 5px 10px;
font-size: 1.2em;
}
}