-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Add tsx to editorconfig * feat: Add Mermaid Diagram block
- Loading branch information
Showing
15 changed files
with
126 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.storybook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,6 @@ services: | |
ports: | ||
- 3000:3000 | ||
- 3001:3001 | ||
depends_on: | ||
- backend | ||
tty: true | ||
profiles: | ||
- dev | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/components/Block/DefaultView.jsx → src/components/Blocks/Code/DefaultView.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/components/Block/schema.js → src/components/Blocks/Code/schema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
const MermaidView = (props) => { | ||
const { code } = props; | ||
const [loaded, setLoaded] = useState(false); | ||
useEffect(() => { | ||
if (window.mermaid) { | ||
setLoaded(true); | ||
} | ||
}, [loaded]); | ||
useEffect(() => { | ||
if (loaded && window.mermaid) { | ||
window.mermaid.contentLoaded(); | ||
} | ||
}, [loaded, code]); | ||
return <>{code && <pre className="mermaid">{code}</pre>}</>; | ||
}; | ||
|
||
export default MermaidView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { withBlockExtensions } from '@plone/volto/helpers'; | ||
import config from '@plone/volto/registry'; | ||
import Editor from '../../Editor/Editor.tsx'; | ||
import { highlight } from 'prismjs/components/prism-core'; | ||
|
||
const MermaidBlockEdit = (props) => { | ||
const { data, block, onChangeBlock } = props; | ||
const [code, setCode] = React.useState(data.code || ''); | ||
const className = `code-block-wrapper edit light`; | ||
const allLanguages = config.settings.codeBlock.languages; | ||
const language = allLanguages['mermaid'].language; | ||
|
||
const handleChange = (code) => { | ||
setCode(code); | ||
onChangeBlock(block, { ...data, code: code }); | ||
}; | ||
|
||
return ( | ||
<div className="block code"> | ||
<div className={className}> | ||
<Editor | ||
value={code} | ||
onValueChange={(code) => handleChange(code)} | ||
highlight={(code) => highlight(code, language)} | ||
padding={10} | ||
preClassName={`code-block-wrapper ${data.style} language-mermaid`} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default withBlockExtensions(MermaidBlockEdit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import MermaidView from './DefaultView'; | ||
import { withBlockExtensions } from '@plone/volto/helpers'; | ||
|
||
const MermaidBlockView = (props) => { | ||
const { data } = props; | ||
const code = data.code || ''; | ||
return <>{code && <MermaidView code={code} />}</>; | ||
}; | ||
|
||
export default withBlockExtensions(MermaidBlockView); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const MermaidConfig = () => { | ||
const script = ` | ||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs'; | ||
window.mermaid = mermaid; | ||
mermaid.initialize( | ||
{ startOnLoad: true } | ||
); | ||
`; | ||
return ( | ||
<script | ||
type="module" | ||
dangerouslySetInnerHTML={{ | ||
__html: script, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default MermaidConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters