@@ -26,10 +26,11 @@ import './Mermaid.scss';
2626
2727const b = cnMermaid ;
2828
29- const MermaidPreview : React . FC < { mermaidInstance : Mermaid | null ; text : string } > = ( {
30- mermaidInstance,
31- text = '' ,
32- } ) => {
29+ const MermaidPreview : React . FC < {
30+ mermaidInstance : Mermaid | null ;
31+ text : string ;
32+ options : MermaidOptions ;
33+ } > = ( { mermaidInstance, text = '' , options} ) => {
3334 const [ svg , setSvg ] = useState < string > ( ) ;
3435 const [ error , setError ] = useState < string | null > ( null ) ;
3536
@@ -42,7 +43,11 @@ const MermaidPreview: React.FC<{mermaidInstance: Mermaid | null; text: string}>
4243 // Validates syntax and throws error if text is invalid
4344 await mermaidInstance . parse ( text ) ;
4445
45- mermaidInstance . initialize ( { theme : theme === 'dark' ? 'dark' : 'forest' } ) ;
46+ if ( options . theme ) {
47+ mermaidInstance . initialize ( {
48+ theme : theme === 'dark' ? options . theme . dark : options . theme . light ,
49+ } ) ;
50+ }
4651
4752 const { svg : S } = await mermaidInstance . render ( `mermaid-${ Date . now ( ) } ` , text ) ;
4853
@@ -55,7 +60,7 @@ const MermaidPreview: React.FC<{mermaidInstance: Mermaid | null; text: string}>
5560 } ;
5661
5762 p ( ) ;
58- } , [ mermaidInstance , text , theme ] ) ;
63+ } , [ mermaidInstance , text , theme , options . theme ] ) ;
5964
6065 if ( error ) {
6166 return < div className = { b ( 'Error' ) } > { error && < div > { error } </ div > } </ div > ;
@@ -74,17 +79,17 @@ const DiagramEditMode: React.FC<{
7479 onSave : ( v : string ) => void ;
7580 onCancel : ( ) => void ;
7681 options : MermaidOptions ;
77- } > = ( { initialText, onSave, onCancel, mermaidInstance, options : { autoSave } } ) => {
82+ } > = ( { initialText, onSave, onCancel, mermaidInstance, options} ) => {
7883 const { value, handleChange, handleManualSave, isSaveDisabled, isAutoSaveEnabled} = useAutoSave ( {
7984 initialValue : initialText || '' ,
8085 onSave,
8186 onClose : onCancel ,
82- autoSave,
87+ autoSave : options . autoSave ,
8388 } ) ;
8489
8590 return (
8691 < div className = { b ( ) } >
87- < MermaidPreview mermaidInstance = { mermaidInstance } text = { value } />
92+ < MermaidPreview mermaidInstance = { mermaidInstance } text = { value } options = { options } />
8893 < div className = { b ( 'Editor' ) } >
8994 < div >
9095 < TextArea
@@ -173,6 +178,7 @@ export const MermaidView: React.FC<{
173178 < MermaidPreview
174179 mermaidInstance = { mermaidInstance }
175180 text = { node . attrs [ MermaidConsts . NodeAttrs . content ] }
181+ options = { options }
176182 />
177183 < div >
178184 < Button
0 commit comments