executable-stories-react 0.18.0 → 0.19.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.
@@ -721,42 +721,76 @@ function StateCardView({ card }) {
721
721
 
722
722
  // src/components/ReportAttachments.tsx
723
723
  import { Fragment as Fragment6, jsx as jsx21, jsxs as jsxs12 } from "react/jsx-runtime";
724
+ function attachmentText(att) {
725
+ if (att.contentEncoding !== "BASE64") return att.body;
726
+ try {
727
+ return new TextDecoder().decode(Uint8Array.from(atob(att.body), (c) => c.charCodeAt(0)));
728
+ } catch {
729
+ return void 0;
730
+ }
731
+ }
732
+ function preview(att) {
733
+ const type = att.mediaType.split(";")[0].trim().toLowerCase();
734
+ const text = attachmentText(att);
735
+ if (text === void 0) return null;
736
+ if (type === "text/plain") {
737
+ return /* @__PURE__ */ jsx21("pre", { className: "max-h-96 overflow-auto rounded-md border border-border bg-muted/40 p-3 text-xs whitespace-pre-wrap", children: text });
738
+ }
739
+ if (type === "text/markdown") {
740
+ return /* @__PURE__ */ jsx21(
741
+ "div",
742
+ {
743
+ className: "es-doc-prose prose prose-sm max-w-none rounded-md border border-border p-3",
744
+ dangerouslySetInnerHTML: { __html: safeMarkdownHtml(text) }
745
+ }
746
+ );
747
+ }
748
+ if (type === "text/html") {
749
+ return /* @__PURE__ */ jsx21(DocHtml, { entry: { kind: "html", content: text, title: att.name, phase: "runtime" } });
750
+ }
751
+ return null;
752
+ }
724
753
  function ReportAttachments({ attachments }) {
725
754
  if (attachments.length === 0) return null;
726
755
  return (
727
756
  // role="group" (not a labelled <section>) so multiple scenarios' attachment
728
757
  // blocks don't create duplicate "Attachments" region landmarks.
729
758
  /* @__PURE__ */ jsx21("div", { role: "group", "aria-label": "Attachments", className: "mt-3 flex flex-col gap-2", children: attachments.map((att, i) => {
730
- const dataUri = att.contentEncoding === "BASE64" ? `data:${att.mediaType};base64,${att.body}` : `data:${att.mediaType},${encodeURIComponent(att.body)}`;
731
- const isImage = att.mediaType.startsWith("image/");
759
+ const dataUri = att.external ? void 0 : att.contentEncoding === "BASE64" ? `data:${att.mediaType};base64,${att.body}` : `data:${att.mediaType},${encodeURIComponent(att.body)}`;
760
+ const href = dataUri ?? safeUrl(att.body);
761
+ const imageSrc = dataUri ?? safeImageUrl(att.body);
762
+ const isImage = att.mediaType.startsWith("image/") && imageSrc !== void 0;
732
763
  return /* @__PURE__ */ jsx21("figure", { className: "m-0", children: isImage ? /* @__PURE__ */ jsxs12(Fragment6, { children: [
733
764
  /* @__PURE__ */ jsx21(
734
765
  "img",
735
766
  {
736
- src: dataUri,
767
+ src: imageSrc,
737
768
  alt: att.name,
738
769
  loading: "lazy",
739
770
  className: "max-w-full rounded-md border border-border"
740
771
  }
741
772
  ),
742
773
  /* @__PURE__ */ jsx21("figcaption", { className: "mt-1 text-xs text-muted-foreground", children: att.name })
743
- ] }) : /* @__PURE__ */ jsxs12(
744
- "a",
745
- {
746
- href: dataUri,
747
- download: att.name,
748
- className: "text-xs text-link underline underline-offset-2",
749
- children: [
750
- att.name,
751
- " ",
752
- /* @__PURE__ */ jsxs12("span", { className: "text-muted-foreground", children: [
753
- "(",
754
- att.mediaType,
755
- ")"
756
- ] })
757
- ]
758
- }
759
- ) }, `${att.name}-${i}`);
774
+ ] }) : /* @__PURE__ */ jsxs12(Fragment6, { children: [
775
+ att.external ? null : preview(att),
776
+ /* @__PURE__ */ jsxs12(
777
+ "a",
778
+ {
779
+ href,
780
+ download: att.name,
781
+ className: "text-xs text-link underline underline-offset-2",
782
+ children: [
783
+ att.name,
784
+ " ",
785
+ /* @__PURE__ */ jsxs12("span", { className: "text-muted-foreground", children: [
786
+ "(",
787
+ att.mediaType,
788
+ ")"
789
+ ] })
790
+ ]
791
+ }
792
+ )
793
+ ] }) }, `${att.name}-${i}`);
760
794
  }) })
761
795
  );
762
796
  }