@readme/markdown 7.7.0 → 7.7.2

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.
@@ -1,16 +1,25 @@
1
+ import type { Mermaid } from 'mermaid';
2
+
1
3
  import { uppercase } from '@readme/syntax-highlighter';
2
4
  import React, { useEffect } from 'react';
3
- import mermaid from 'mermaid';
5
+
6
+ let mermaid: Mermaid;
7
+
8
+ if (typeof window !== 'undefined') {
9
+ import('mermaid').then(module => {
10
+ mermaid = module.default;
11
+ });
12
+ }
4
13
 
5
14
  const CodeTabs = props => {
6
15
  const { children, theme } = props;
7
16
 
8
17
  // set Mermaid theme
9
18
  useEffect(() => {
10
- mermaid.initialize({
19
+ mermaid?.initialize({
11
20
  theme: theme === 'dark' ? 'dark' : 'default',
12
21
  });
13
- }, [theme])
22
+ }, [theme]);
14
23
 
15
24
  function handleClick({ target }, index: number) {
16
25
  const $wrap = target.parentElement.parentElement;
@@ -22,21 +31,12 @@ const CodeTabs = props => {
22
31
  codeblocks[index].classList.add('CodeTabs_active');
23
32
 
24
33
  target.classList.add('CodeTabs_active');
25
-
26
- if (target.value === 'mermaid') {
27
- const $openMermaid = [].slice.call($wrap.querySelectorAll('.mermaid'));
28
- $openMermaid.forEach((el: Element) => el.classList.remove('mermaid'));
29
- codeblocks[index].classList.add('mermaid');
30
- mermaid.contentLoaded();
31
- }
32
34
  }
33
35
 
34
36
  // render single Mermaid diagram
35
37
  if (!Array.isArray(children) && children.props?.children.props.lang === 'mermaid') {
36
38
  const value = children.props.children.props.value;
37
- return (
38
- <pre className="mermaid mermaid_single">{value}</pre>
39
- )
39
+ return <pre className="mermaid mermaid_single">{value}</pre>;
40
40
  }
41
41
 
42
42
  return (