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.
package/dist/index.cjs CHANGED
@@ -948,42 +948,76 @@ function StateCardView({ card }) {
948
948
 
949
949
  // src/components/ReportAttachments.tsx
950
950
  var import_jsx_runtime21 = require("react/jsx-runtime");
951
+ function attachmentText(att) {
952
+ if (att.contentEncoding !== "BASE64") return att.body;
953
+ try {
954
+ return new TextDecoder().decode(Uint8Array.from(atob(att.body), (c) => c.charCodeAt(0)));
955
+ } catch {
956
+ return void 0;
957
+ }
958
+ }
959
+ function preview(att) {
960
+ const type = att.mediaType.split(";")[0].trim().toLowerCase();
961
+ const text = attachmentText(att);
962
+ if (text === void 0) return null;
963
+ if (type === "text/plain") {
964
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("pre", { className: "max-h-96 overflow-auto rounded-md border border-border bg-muted/40 p-3 text-xs whitespace-pre-wrap", children: text });
965
+ }
966
+ if (type === "text/markdown") {
967
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
968
+ "div",
969
+ {
970
+ className: "es-doc-prose prose prose-sm max-w-none rounded-md border border-border p-3",
971
+ dangerouslySetInnerHTML: { __html: safeMarkdownHtml(text) }
972
+ }
973
+ );
974
+ }
975
+ if (type === "text/html") {
976
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(DocHtml, { entry: { kind: "html", content: text, title: att.name, phase: "runtime" } });
977
+ }
978
+ return null;
979
+ }
951
980
  function ReportAttachments({ attachments }) {
952
981
  if (attachments.length === 0) return null;
953
982
  return (
954
983
  // role="group" (not a labelled <section>) so multiple scenarios' attachment
955
984
  // blocks don't create duplicate "Attachments" region landmarks.
956
985
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { role: "group", "aria-label": "Attachments", className: "mt-3 flex flex-col gap-2", children: attachments.map((att, i) => {
957
- const dataUri = att.contentEncoding === "BASE64" ? `data:${att.mediaType};base64,${att.body}` : `data:${att.mediaType},${encodeURIComponent(att.body)}`;
958
- const isImage = att.mediaType.startsWith("image/");
986
+ const dataUri = att.external ? void 0 : att.contentEncoding === "BASE64" ? `data:${att.mediaType};base64,${att.body}` : `data:${att.mediaType},${encodeURIComponent(att.body)}`;
987
+ const href = dataUri ?? (0, import_url.safeUrl)(att.body);
988
+ const imageSrc = dataUri ?? (0, import_url.safeImageUrl)(att.body);
989
+ const isImage = att.mediaType.startsWith("image/") && imageSrc !== void 0;
959
990
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("figure", { className: "m-0", children: isImage ? /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
960
991
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
961
992
  "img",
962
993
  {
963
- src: dataUri,
994
+ src: imageSrc,
964
995
  alt: att.name,
965
996
  loading: "lazy",
966
997
  className: "max-w-full rounded-md border border-border"
967
998
  }
968
999
  ),
969
1000
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("figcaption", { className: "mt-1 text-xs text-muted-foreground", children: att.name })
970
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
971
- "a",
972
- {
973
- href: dataUri,
974
- download: att.name,
975
- className: "text-xs text-link underline underline-offset-2",
976
- children: [
977
- att.name,
978
- " ",
979
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "text-muted-foreground", children: [
980
- "(",
981
- att.mediaType,
982
- ")"
983
- ] })
984
- ]
985
- }
986
- ) }, `${att.name}-${i}`);
1001
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1002
+ att.external ? null : preview(att),
1003
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
1004
+ "a",
1005
+ {
1006
+ href,
1007
+ download: att.name,
1008
+ className: "text-xs text-link underline underline-offset-2",
1009
+ children: [
1010
+ att.name,
1011
+ " ",
1012
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("span", { className: "text-muted-foreground", children: [
1013
+ "(",
1014
+ att.mediaType,
1015
+ ")"
1016
+ ] })
1017
+ ]
1018
+ }
1019
+ )
1020
+ ] }) }, `${att.name}-${i}`);
987
1021
  }) })
988
1022
  );
989
1023
  }
@@ -2617,6 +2651,10 @@ var story_report_v1_default = {
2617
2651
  contentEncoding: {
2618
2652
  type: "string",
2619
2653
  enum: ["BASE64", "IDENTITY"]
2654
+ },
2655
+ external: {
2656
+ const: true,
2657
+ description: "body holds the file's path or URL (file missing or too large to embed)."
2620
2658
  }
2621
2659
  },
2622
2660
  required: ["name", "mediaType", "body", "contentEncoding"],