@uiw/react-md-editor 3.25.6 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -718,16 +718,26 @@ const randomid = () => parseInt(String(Math.random() * 1e15), 10).toString(36);
718
718
  const Code = ({ inline, children = [], className, ...props }) => {
719
719
  const demoid = useRef(`dome${randomid()}`);
720
720
  const [container, setContainer] = useState(null);
721
- const isMermaid = className && /^language-mermaid/.test(className.toLocaleLowerCase());
722
- const code = props.node && props.node.children ? getCodeString(props.node.children) : children[0] || '';
721
+ const isMermaid =
722
+ className && /^language-mermaid/.test(className.toLocaleLowerCase());
723
+ const code = children
724
+ ? getCodeString(props.node.children)
725
+ : children[0] || "";
726
+
723
727
  useEffect(() => {
724
- if (container && isMermaid) {
725
- try {
726
- const str = mermaid.render(demoid.current, code);
727
- container.innerHTML = str;
728
- } catch (error) {
729
- container.innerHTML = error;
730
- }
728
+ if (container && isMermaid && demoid.current && code) {
729
+ mermaid
730
+ .render(demoid.current, code)
731
+ .then(({ svg, bindFunctions }) => {
732
+ console.log("svg:", svg);
733
+ container.innerHTML = svg;
734
+ if (bindFunctions) {
735
+ bindFunctions(container);
736
+ }
737
+ })
738
+ .catch((error) => {
739
+ console.log("error:", error);
740
+ });
731
741
  }
732
742
  }, [container, isMermaid, code, demoid]);
733
743
 
@@ -741,11 +751,11 @@ const Code = ({ inline, children = [], className, ...props }) => {
741
751
  return (
742
752
  <Fragment>
743
753
  <code id={demoid.current} style={{ display: "none" }} />
744
- <code ref={refElement} data-name="mermaid" />
754
+ <code className={className} ref={refElement} data-name="mermaid" />
745
755
  </Fragment>
746
756
  );
747
757
  }
748
- return <code>{children}</code>;
758
+ return <code className={className}>{children}</code>;
749
759
  };
750
760
 
751
761
  export default function App() {
package/dist/mdeditor.css CHANGED
@@ -1183,7 +1183,7 @@ body[data-color-mode*='light'] {
1183
1183
  .w-md-editor-toolbar {
1184
1184
  border-bottom: 1px solid var(--md-editor-box-shadow-color);
1185
1185
  background-color: var(--md-editor-background-color);
1186
- padding: 5px 5px;
1186
+ padding: 3px;
1187
1187
  display: flex;
1188
1188
  justify-content: space-between;
1189
1189
  align-items: center;