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.js CHANGED
@@ -1600,7 +1600,7 @@ function Report(props) {
1600
1600
 
1601
1601
  // src/components/doc/MermaidView.tsx
1602
1602
  import { useEffect, useRef, useState as useState2 } from "react";
1603
- import { jsx as jsx36, jsxs as jsxs23 } from "react/jsx-runtime";
1603
+ import { Fragment as Fragment11, jsx as jsx36, jsxs as jsxs23 } from "react/jsx-runtime";
1604
1604
  function prefersDark(el) {
1605
1605
  const themed = el?.closest("[data-theme]");
1606
1606
  if (themed?.dataset.theme === "dark") return true;
@@ -1610,21 +1610,38 @@ function prefersDark(el) {
1610
1610
  function MermaidView({ entry, load }) {
1611
1611
  const ref = useRef(null);
1612
1612
  const [svg, setSvg] = useState2(null);
1613
+ const [error, setError] = useState2(null);
1613
1614
  useEffect(() => {
1614
1615
  let cancelled = false;
1615
1616
  const draw = async () => {
1617
+ let mermaid;
1618
+ try {
1619
+ mermaid = await load();
1620
+ } catch {
1621
+ if (!cancelled) {
1622
+ setSvg(null);
1623
+ setError(null);
1624
+ }
1625
+ return;
1626
+ }
1616
1627
  try {
1617
- const mermaid = await load();
1618
1628
  mermaid.initialize({
1619
1629
  startOnLoad: false,
1620
1630
  securityLevel: "strict",
1621
1631
  theme: prefersDark(ref.current) ? "dark" : "default"
1622
1632
  });
1633
+ await mermaid.parse(entry.code);
1623
1634
  const id = `es-mermaid-${Math.random().toString(36).slice(2)}`;
1624
1635
  const { svg: rendered } = await mermaid.render(id, entry.code);
1625
- if (!cancelled) setSvg(rendered);
1626
- } catch {
1627
- if (!cancelled) setSvg(null);
1636
+ if (!cancelled) {
1637
+ setSvg(rendered);
1638
+ setError(null);
1639
+ }
1640
+ } catch (err2) {
1641
+ if (!cancelled) {
1642
+ setSvg(null);
1643
+ setError(err2 instanceof Error ? err2.message : String(err2));
1644
+ }
1628
1645
  }
1629
1646
  };
1630
1647
  void draw();
@@ -1650,7 +1667,21 @@ function MermaidView({ entry, load }) {
1650
1667
  )
1651
1668
  ] });
1652
1669
  }
1653
- return /* @__PURE__ */ jsx36(MermaidSource, { entry, ref });
1670
+ return /* @__PURE__ */ jsxs23(Fragment11, { children: [
1671
+ error ? /* @__PURE__ */ jsxs23(
1672
+ "p",
1673
+ {
1674
+ role: "alert",
1675
+ "data-es-mermaid-error": true,
1676
+ className: "mt-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",
1677
+ children: [
1678
+ "Diagram failed to render: ",
1679
+ error
1680
+ ]
1681
+ }
1682
+ ) : null,
1683
+ /* @__PURE__ */ jsx36(MermaidSource, { entry, ref })
1684
+ ] });
1654
1685
  }
1655
1686
 
1656
1687
  // src/components/doc/MermaidDiagram.tsx