Skip to content

Commit

Permalink
feat(docusaurus-plugin): add simple mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chongqiangchen committed Apr 20, 2023
1 parent 0ea4cde commit 63efd9e
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions packages/docusaurus-plugin/src/theme/SoliveCodeBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import resolveMeta from '../utils/resolve-meta';
import transformModel from '../utils/transform-model';

const PropsInfo = {
simple: {
type: 'boolean',
default: false,
},
width: {
type: 'string',
default: '90%',
Expand Down Expand Up @@ -47,30 +51,50 @@ const PropsInfo = {

function SoliveCodeBlock(props: SoliveCodeBlockProps) {
const { metastring, children } = props;
const allProps = matchProps(metastring?.split('solive')[1] || '', PropsInfo);
const allProps = useMemo(() => matchProps(metastring?.split('solive')[1] || '', PropsInfo), [metastring]);

const id = useMemo(() => uuidv4(), []);
const modelInfos = useMemo(() => transformModel(resolveMeta(children)), [children]);

const state = useMemo(() => {
if (allProps.simple) {
return {
height: allProps.height,
id,
modelInfos,
fileNav: { open: false },
console: { open: false },
deploy: { open: false },
disableValidation: true,
};
}

return {
fileNav: {
open: allProps.fileNavOpen,
},
console: {
defaultVisible: allProps.consoleDefaultVisible,
open: allProps.consoleOpen,
triggerControl: allProps.consoleTriggerControl,
},
deploy: {
defaultVisible: allProps.deployDefaultVisible,
open: allProps.deployOpen,
},
height: allProps.height,
id,
modelInfos,
};
}, [
allProps,
id,
modelInfos,
]);

return (
<div style={{ width: allProps.width, maxWidth: '800px', margin: 'auto' }}>
<Editor
fileNav={{
open: allProps.fileNavOpen,
}}
console={{
defaultVisible: allProps.consoleDefaultVisible,
open: allProps.consoleOpen,
triggerControl: allProps.consoleTriggerControl,
}}
deploy={{
defaultVisible: allProps.deployDefaultVisible,
open: allProps.deployOpen,
}}
height={allProps.height}
id={id}
modelInfos={modelInfos}
/>
<Editor {...state} />
</div>
);
}
Expand Down

0 comments on commit 63efd9e

Please sign in to comment.