executable-stories-react 0.8.0 → 0.9.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/dist/index.cjs CHANGED
@@ -1694,21 +1694,38 @@ function prefersDark(el) {
1694
1694
  function MermaidView({ entry, load }) {
1695
1695
  const ref = (0, import_react8.useRef)(null);
1696
1696
  const [svg, setSvg] = (0, import_react8.useState)(null);
1697
+ const [error, setError] = (0, import_react8.useState)(null);
1697
1698
  (0, import_react8.useEffect)(() => {
1698
1699
  let cancelled = false;
1699
1700
  const draw = async () => {
1701
+ let mermaid;
1702
+ try {
1703
+ mermaid = await load();
1704
+ } catch {
1705
+ if (!cancelled) {
1706
+ setSvg(null);
1707
+ setError(null);
1708
+ }
1709
+ return;
1710
+ }
1700
1711
  try {
1701
- const mermaid = await load();
1702
1712
  mermaid.initialize({
1703
1713
  startOnLoad: false,
1704
1714
  securityLevel: "strict",
1705
1715
  theme: prefersDark(ref.current) ? "dark" : "default"
1706
1716
  });
1717
+ await mermaid.parse(entry.code);
1707
1718
  const id = `es-mermaid-${Math.random().toString(36).slice(2)}`;
1708
1719
  const { svg: rendered } = await mermaid.render(id, entry.code);
1709
- if (!cancelled) setSvg(rendered);
1710
- } catch {
1711
- if (!cancelled) setSvg(null);
1720
+ if (!cancelled) {
1721
+ setSvg(rendered);
1722
+ setError(null);
1723
+ }
1724
+ } catch (err2) {
1725
+ if (!cancelled) {
1726
+ setSvg(null);
1727
+ setError(err2 instanceof Error ? err2.message : String(err2));
1728
+ }
1712
1729
  }
1713
1730
  };
1714
1731
  void draw();
@@ -1734,7 +1751,21 @@ function MermaidView({ entry, load }) {
1734
1751
  )
1735
1752
  ] });
1736
1753
  }
1737
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(MermaidSource, { entry, ref });
1754
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(import_jsx_runtime36.Fragment, { children: [
1755
+ error ? /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
1756
+ "p",
1757
+ {
1758
+ role: "alert",
1759
+ "data-es-mermaid-error": true,
1760
+ className: "mt-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",
1761
+ children: [
1762
+ "Diagram failed to render: ",
1763
+ error
1764
+ ]
1765
+ }
1766
+ ) : null,
1767
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(MermaidSource, { entry, ref })
1768
+ ] });
1738
1769
  }
1739
1770
 
1740
1771
  // src/components/doc/MermaidDiagram.tsx