web: render stage-turn markdown in the artifact viewer
The full-screen viewer now opens markdown/text artifacts (text/markdown, text/plain, .md/.markdown/.txt) through the resolved artifact URL and renders them with the page's own DOM markdown renderer, with an honest failure message and an external fallback. ArrowLeft/ArrowRight page the shared media+document list, and a backdrop click closes the viewer while panel clicks do not. The run gallery and per-visit artifacts present input.md, memory.md and output.md as ordinary Document tiles with a drawn glyph and open the viewer. Adds isMarkdownArtifact/isViewerArtifact with unit coverage, deterministic viewer fixtures, and ui-smoke assertions/captures for rendered markdown, keyboard paging, the honest 404 and backdrop dismissal.
This commit is contained in:
+22
-10
@@ -43,6 +43,7 @@ import {
|
||||
artifactViewerPositionLabel,
|
||||
displayVisit,
|
||||
humanBytes,
|
||||
isViewerArtifact,
|
||||
pagedArtifacts,
|
||||
presentedArtifacts,
|
||||
resolvedArtifactUrl,
|
||||
@@ -580,7 +581,7 @@ function renderVerdictBlock(step) {
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** One inline artifact reference in a verdict reason (media opens the viewer). */
|
||||
/** One inline artifact reference in a verdict reason (viewer files open the viewer). */
|
||||
function renderVerdictLink(text, artifact, step) {
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
if (!resolved) return h("span", { class: "verdict-link disabled", text });
|
||||
@@ -604,17 +605,18 @@ function renderVerdictRef(artifact, step) {
|
||||
return chip;
|
||||
}
|
||||
|
||||
/** Open a referenced artifact: media in the viewer, everything else externally. */
|
||||
/** Open a referenced artifact: viewer-selectable files in the viewer, others externally. */
|
||||
function openArtifactFromVerdict(artifact, step, resolved, trigger = null) {
|
||||
if (!resolved) return;
|
||||
const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts: presentedArtifacts(step) };
|
||||
const viewable = pagedArtifacts([group]);
|
||||
const viewerIndexOf = viewerIndexByUrl([group]);
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
const kind = artifactKind(artifact.content_type, artifact.name);
|
||||
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
|
||||
if (media && at != null) openArtifactViewer(viewable, at, trigger);
|
||||
else window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
if (isViewerArtifact(artifact.content_type, artifact.name) && at != null) {
|
||||
openArtifactViewer(viewable, at, trigger);
|
||||
} else {
|
||||
window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
}
|
||||
|
||||
/** Open the stage pane for one visit of a stage; the controller moves focus in. */
|
||||
@@ -808,7 +810,8 @@ function renderArtifactGallery(steps) {
|
||||
* The per-visit artifacts section shown inside one step: the summary line, the
|
||||
* capture notes, the no-server-URL hint and a headerless grid of that visit's
|
||||
* tiles (matching the Android ArtifactsSection). Its viewer pages only through
|
||||
* that visit's media, exactly as the Android section does.
|
||||
* that visit's viewable artifacts (media and markdown), exactly as the Android
|
||||
* section does.
|
||||
*/
|
||||
function renderVisitArtifacts(step) {
|
||||
const wrap = h("div", { class: "artifacts" });
|
||||
@@ -842,13 +845,15 @@ function renderArtifactGrid(artifacts, viewable, viewerIndexOf) {
|
||||
|
||||
/**
|
||||
* One gallery tile: an image thumbnail, a video poster with a play marker (never
|
||||
* a <video> element or autoplay), or a kind/name/size label. Every server string
|
||||
* is set as text, never as markup.
|
||||
* a <video> element or autoplay), or a kind/name/size label. Markdown and text
|
||||
* documents get a paper glyph and open in the viewer like media. Every server
|
||||
* string is set as text, never as markup.
|
||||
*/
|
||||
function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
const kind = artifactKind(artifact.content_type, artifact.name);
|
||||
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
|
||||
const opensViewer = isViewerArtifact(artifact.content_type, artifact.name);
|
||||
const name = artifact.name || "(unnamed artifact)";
|
||||
// The tile is the native control (M5): Enter/Space activate it for free, and
|
||||
// the Copy link / Share buttons are siblings in the wrapper, never children.
|
||||
@@ -857,6 +862,9 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
class: "artifact-tile clickable",
|
||||
type: "button",
|
||||
"aria-label": `Open ${name}`,
|
||||
"data-artifact-name": artifact.name ?? "",
|
||||
"data-artifact-kind": kind,
|
||||
"data-artifact-url": artifact.url ?? "",
|
||||
});
|
||||
const openViewer = () => {
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
@@ -881,12 +889,16 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
tile.append(h("div", { class: "artifact-name", text: name }));
|
||||
tile.addEventListener("click", openViewer);
|
||||
} else {
|
||||
if (opensViewer) {
|
||||
tile.classList.add("artifact-document-tile");
|
||||
tile.append(h("span", { class: "artifact-doc-glyph", "aria-hidden": "true" }));
|
||||
}
|
||||
tile.append(
|
||||
h("div", { class: "artifact-kind", text: artifactKindLabel(kind) }),
|
||||
h("div", { class: "artifact-name", text: name }),
|
||||
h("div", { class: "artifact-size", text: humanBytes(artifact.size_bytes) }),
|
||||
);
|
||||
tile.addEventListener("click", openTab);
|
||||
tile.addEventListener("click", opensViewer ? openViewer : openTab);
|
||||
}
|
||||
wrap.append(tile, renderTileActions(resolved, media));
|
||||
return wrap;
|
||||
|
||||
Reference in New Issue
Block a user