2023-08-22 13:11:18 +08:00
|
|
|
import React from 'react';
|
2023-08-21 14:38:22 +08:00
|
|
|
import type { IPreviewerProps } from 'dumi';
|
2023-10-23 22:49:49 +08:00
|
|
|
import { LiveProvider, useTabMeta } from 'dumi';
|
2023-08-22 13:11:18 +08:00
|
|
|
|
2023-08-21 14:38:22 +08:00
|
|
|
import CodePreviewer from './CodePreviewer';
|
|
|
|
import DesignPreviewer from './DesignPreviewer';
|
|
|
|
|
|
|
|
export interface AntdPreviewerProps extends IPreviewerProps {
|
|
|
|
originDebug?: IPreviewerProps['debug'];
|
|
|
|
}
|
|
|
|
|
|
|
|
const Previewer: React.FC<AntdPreviewerProps> = (props) => {
|
|
|
|
const tab = useTabMeta();
|
|
|
|
|
|
|
|
if (tab?.frontmatter.title === 'Design') {
|
|
|
|
return <DesignPreviewer {...props} />;
|
|
|
|
}
|
|
|
|
|
2023-10-23 22:49:49 +08:00
|
|
|
const codePreviewer = <CodePreviewer {...props} />;
|
|
|
|
|
|
|
|
if (props.live === false || props.iframe) {
|
|
|
|
return codePreviewer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<LiveProvider
|
|
|
|
initialCode={
|
|
|
|
Object.entries(props.asset.dependencies).filter(([, { type }]) => type === 'FILE')[0][1]
|
|
|
|
.value
|
|
|
|
}
|
|
|
|
demoId={props.asset.id}
|
|
|
|
>
|
|
|
|
{codePreviewer}
|
|
|
|
</LiveProvider>
|
|
|
|
);
|
2023-08-21 14:38:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Previewer;
|