web: shared modal focus controller (M1/M2) — work in progress
This commit is contained in:
@@ -37,7 +37,7 @@ export function loadNotifyAsked() {
|
||||
}
|
||||
|
||||
export function createAttentionView(rt) {
|
||||
const { state, attentionLayer, runAlerts } = rt;
|
||||
const { state, attentionLayer, runAlerts, modal } = rt;
|
||||
const render = (...args) => rt.render(...args);
|
||||
const selectRun = (...args) => rt.selectRun(...args);
|
||||
|
||||
@@ -126,6 +126,7 @@ function refreshAttentionBell() {
|
||||
function renderAttentionSheet() {
|
||||
if (!state.attentionSheetOpen) {
|
||||
attentionLayer.replaceChildren();
|
||||
modal.close("attention-sheet");
|
||||
return;
|
||||
}
|
||||
const entries = attentionEntries(state.runs, state.attentionDismissed);
|
||||
@@ -175,6 +176,14 @@ function renderAttentionSheet() {
|
||||
const sheet = h("div", { class: "attention-sheet-panel", tabindex: "-1" }, head, body);
|
||||
overlay.append(sheet);
|
||||
attentionLayer.replaceChildren(overlay);
|
||||
modal.open("attention-sheet", overlay, {
|
||||
// The sheet is rebuilt by renderAttentionSheet, not by renderContent's
|
||||
// staged set, so it is managed imperatively rather than reconciled away.
|
||||
renderManaged: false,
|
||||
onClose: () => closeAttentionSheet(),
|
||||
triggerSelector: "#attentionBell",
|
||||
fallbackSelectors: ["#listTitle", "#pane-main"],
|
||||
});
|
||||
}
|
||||
|
||||
/** One attention row: status icon, the two text lines, and a trailing Dismiss. */
|
||||
@@ -227,16 +236,15 @@ function openAttentionSheet() {
|
||||
attentionEntries(state.runs, state.attentionDismissed),
|
||||
);
|
||||
render();
|
||||
document.querySelector(".attention-sheet-close")?.focus();
|
||||
}
|
||||
|
||||
/** Close the sheet, dropping the snapshot; focus returns to the bell. */
|
||||
/** Close the sheet, dropping the snapshot; the controller returns focus to the bell. */
|
||||
function closeAttentionSheet({ restoreFocus = true } = {}) {
|
||||
if (!state.attentionSheetOpen) return;
|
||||
state.attentionSheetOpen = false;
|
||||
state.attentionSnapshot = null;
|
||||
if (!restoreFocus) modal.close("attention-sheet", { restoreFocus: false });
|
||||
render();
|
||||
if (restoreFocus) document.querySelector("#attentionBell")?.focus();
|
||||
}
|
||||
|
||||
/** Dismiss one or more entries for good, persisting the identity set. */
|
||||
|
||||
+11
-3
@@ -254,7 +254,7 @@ export function readChatSeenStore() {
|
||||
}
|
||||
|
||||
export function createChatView(rt) {
|
||||
const { state, repo } = rt;
|
||||
const { state, repo, modal } = rt;
|
||||
let chatClock = null;
|
||||
let chatNow = Date.now();
|
||||
const renderContent = (...args) => rt.renderContent(...args);
|
||||
@@ -915,8 +915,6 @@ function openChatRename(session) {
|
||||
state.chatMenu = null;
|
||||
state.chatRename = session;
|
||||
renderContent();
|
||||
// Same re-render note as the menu: put the cursor in the Name field.
|
||||
document.getElementById("chatRenameInput")?.focus();
|
||||
}
|
||||
|
||||
function dismissChatRename() {
|
||||
@@ -2003,6 +2001,11 @@ function renderChatRenameDialog(session) {
|
||||
actions.append(save);
|
||||
panel.append(actions);
|
||||
overlay.append(panel);
|
||||
modal.stage("chat-rename", overlay, {
|
||||
onClose: () => dismissChatRename(),
|
||||
triggerSelector: `#chatRows .chat-row[data-session="${CSS.escape(String(session.id))}"] .chat-menu-button`,
|
||||
fallbackSelectors: ["#detailTitle", "#listTitle", "#pane-main"],
|
||||
});
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@@ -3041,6 +3044,11 @@ function renderChatCloseDialog(session) {
|
||||
);
|
||||
panel.append(actions);
|
||||
overlay.append(panel);
|
||||
modal.stage("chat-close", overlay, {
|
||||
onClose: () => dismissChatClose(),
|
||||
triggerSelector: `#chatRows .chat-row[data-session="${CSS.escape(String(session.id))}"] .chat-menu-button`,
|
||||
fallbackSelectors: ["#detailTitle", "#listTitle", "#pane-main"],
|
||||
});
|
||||
return overlay;
|
||||
}
|
||||
|
||||
|
||||
+37
-34
@@ -51,27 +51,18 @@ import {
|
||||
} from "../actions.js";
|
||||
|
||||
export function createDialogsView(rt) {
|
||||
const { state, repo } = rt;
|
||||
const { state, repo, modal } = rt;
|
||||
const renderContent = (...args) => rt.renderContent(...args);
|
||||
const selectRun = (...args) => rt.selectRun(...args);
|
||||
|
||||
let changeViewerOverlay = null;
|
||||
let changeViewerKeydown = null;
|
||||
let changeViewerIndex = null;
|
||||
|
||||
/** Close the diff viewer, returning focus to the row that opened it. */
|
||||
/** Close the diff viewer; the controller returns focus to the viewed row. */
|
||||
function closeChangeViewer() {
|
||||
if (changeViewerKeydown) {
|
||||
document.removeEventListener("keydown", changeViewerKeydown);
|
||||
changeViewerKeydown = null;
|
||||
}
|
||||
const index = changeViewerIndex;
|
||||
changeViewerOverlay?.remove();
|
||||
changeViewerOverlay = null;
|
||||
modal.close("change-viewer");
|
||||
changeViewerIndex = null;
|
||||
if (index != null) {
|
||||
document.querySelector(`.change-row[data-change-index="${index}"]`)?.focus();
|
||||
}
|
||||
changeViewerOverlay = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +76,7 @@ function closeChangeViewer() {
|
||||
* give a patch for (binary, truncated, or a capture that recorded none) shows the
|
||||
* honest reason in place of a diff rather than a fabricated one.
|
||||
*/
|
||||
function openChangeViewer(files, startIndex) {
|
||||
function openChangeViewer(files, startIndex, trigger = null) {
|
||||
closeChangeViewer();
|
||||
if (!files?.length) return;
|
||||
let index = Math.min(Math.max(Number(startIndex) || 0, 0), files.length - 1);
|
||||
@@ -209,12 +200,16 @@ function openChangeViewer(files, startIndex) {
|
||||
};
|
||||
|
||||
renderViewer();
|
||||
document.body.append(overlay);
|
||||
changeViewerOverlay = overlay;
|
||||
changeViewerKeydown = (event) => {
|
||||
if (event.key === "Escape") closeChangeViewer();
|
||||
};
|
||||
document.addEventListener("keydown", changeViewerKeydown);
|
||||
modal.open("change-viewer", overlay, {
|
||||
onClose: () => closeChangeViewer(),
|
||||
trigger,
|
||||
restore: () =>
|
||||
changeViewerIndex == null
|
||||
? null
|
||||
: document.querySelector(`.change-row[data-change-index="${changeViewerIndex}"]`),
|
||||
fallbackSelectors: ["#detailTitle", "#pane-main"],
|
||||
});
|
||||
}
|
||||
|
||||
/** The rendered reading: the stat line, an optional truncation note, each hunk. */
|
||||
@@ -267,7 +262,6 @@ function openDecisionSheet(decision) {
|
||||
state.decisionDraft = new DecisionDraft();
|
||||
state.decisionError = "";
|
||||
renderContent();
|
||||
document.querySelector(".decision-sheet .decision-option")?.focus();
|
||||
}
|
||||
|
||||
/** Dismiss the decision sheet (never while a decision is in flight). */
|
||||
@@ -280,7 +274,6 @@ function closeDecisionSheet() {
|
||||
state.decisionDraft = new DecisionDraft();
|
||||
if (!wasOpen) return;
|
||||
renderContent();
|
||||
document.querySelector(".decision-card .decision-open")?.focus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,6 +360,11 @@ function renderDecisionSheet(decision) {
|
||||
);
|
||||
sheet.append(actions);
|
||||
overlay.append(sheet);
|
||||
modal.stage("decision-sheet", overlay, {
|
||||
onClose: () => closeDecisionSheet(),
|
||||
triggerSelector: ".decision-card .decision-open",
|
||||
fallbackSelectors: ["#detailTitle", "#pane-main"],
|
||||
});
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@@ -477,6 +475,12 @@ function renderConfirmDialog(d) {
|
||||
);
|
||||
panel.append(actions);
|
||||
overlay.append(panel);
|
||||
modal.stage("confirm", overlay, {
|
||||
onClose: () => dismissConfirm(),
|
||||
triggerSelector:
|
||||
kind.kind === "cancel" ? ".run-actions .cancel-run" : ".run-actions .retry-run",
|
||||
fallbackSelectors: ["#detailTitle", "#pane-main"],
|
||||
});
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@@ -521,6 +525,10 @@ function renderActionFailedDialog() {
|
||||
h("button", { class: "action-failed-ok", type: "button", text: ACTION_FAILED_OK, onclick: dismissActionError }),
|
||||
);
|
||||
overlay.append(panel);
|
||||
modal.stage("action-error", overlay, {
|
||||
onClose: () => dismissActionError(),
|
||||
fallbackSelectors: ["#detailTitle", "#listTitle", "#pane-main"],
|
||||
});
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@@ -530,15 +538,10 @@ function dismissActionError() {
|
||||
}
|
||||
|
||||
let viewerOverlay = null;
|
||||
let viewerKeydown = null;
|
||||
|
||||
/** Close the full-screen viewer and remove its Escape listener. */
|
||||
/** Close the full-screen viewer; the controller returns focus to its trigger. */
|
||||
function closeArtifactViewer() {
|
||||
if (viewerKeydown) {
|
||||
document.removeEventListener("keydown", viewerKeydown);
|
||||
viewerKeydown = null;
|
||||
}
|
||||
viewerOverlay?.remove();
|
||||
modal.close("artifact-viewer");
|
||||
viewerOverlay = null;
|
||||
}
|
||||
|
||||
@@ -548,7 +551,7 @@ function closeArtifactViewer() {
|
||||
* a single artifact; Escape and a backdrop click close it. Nothing autoplays: a
|
||||
* non-image artifact shows a still poster placeholder instead.
|
||||
*/
|
||||
function openArtifactViewer(viewable, startIndex) {
|
||||
function openArtifactViewer(viewable, startIndex, trigger = null) {
|
||||
closeArtifactViewer();
|
||||
if (!viewable?.length) return;
|
||||
let index = pagedIndex(startIndex, 0, viewable.length);
|
||||
@@ -660,12 +663,12 @@ function openArtifactViewer(viewable, startIndex) {
|
||||
};
|
||||
|
||||
renderViewer();
|
||||
document.body.append(overlay);
|
||||
viewerOverlay = overlay;
|
||||
viewerKeydown = (event) => {
|
||||
if (event.key === "Escape") closeArtifactViewer();
|
||||
};
|
||||
document.addEventListener("keydown", viewerKeydown);
|
||||
modal.open("artifact-viewer", overlay, {
|
||||
onClose: () => closeArtifactViewer(),
|
||||
trigger,
|
||||
fallbackSelectors: ["#detailTitle", "#pane-main"],
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
+27
-23
@@ -91,7 +91,7 @@ const ARTIFACT_SERVER_HINT =
|
||||
"Set the server URL in Settings to open or copy artifact links.";
|
||||
|
||||
export function createRunDetailView(rt) {
|
||||
const { state, repo } = rt;
|
||||
const { state, repo, modal } = rt;
|
||||
const renderContent = (...args) => rt.renderContent(...args);
|
||||
const selectRun = (...args) => rt.selectRun(...args);
|
||||
const pushRoute = (...args) => rt.pushRoute(...args);
|
||||
@@ -347,7 +347,6 @@ function renderChangesBody(changes) {
|
||||
* the diff viewer on this file, whose position there confirms which row it is.
|
||||
*/
|
||||
function renderChangeRow(entry, index, files) {
|
||||
const open = () => openChangeViewer(files, index);
|
||||
const row = h("div", {
|
||||
class: "change-row",
|
||||
role: "button",
|
||||
@@ -355,6 +354,7 @@ function renderChangeRow(entry, index, files) {
|
||||
"data-change-index": String(index),
|
||||
"aria-label": `Open ${entry.path}`,
|
||||
});
|
||||
const open = () => openChangeViewer(files, index, row);
|
||||
row.addEventListener("click", open);
|
||||
row.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
@@ -492,6 +492,23 @@ function renderStagePane(d) {
|
||||
}
|
||||
for (const spec of specs) body.append(renderStageSection(spec, step));
|
||||
overlay.append(h("div", { class: "stage-pane-sheet" }, bar, body));
|
||||
modal.stage("stage-pane", overlay, {
|
||||
onClose: () => closeStagePane(),
|
||||
fallbackSelectors: ["#detailTitle", "#pane-main"],
|
||||
// A pane opened from the Timeline returns to its row; one opened from the
|
||||
// Graph returns to the stage node (there is no timeline row then).
|
||||
restore: () => {
|
||||
const row = [...document.querySelectorAll(".timeline-row")].find(
|
||||
(node) =>
|
||||
node.dataset.stageKey === stageKey && node.dataset.visitIndex === String(visitIndex),
|
||||
);
|
||||
return (
|
||||
row ??
|
||||
[...document.querySelectorAll(".graph-node")].find((node) => node.dataset.key === stageKey) ??
|
||||
null
|
||||
);
|
||||
},
|
||||
});
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@@ -570,7 +587,7 @@ function renderVerdictLink(text, artifact, step) {
|
||||
const link = h("a", { class: "verdict-link", href: resolved, target: "_blank", rel: "noreferrer", text });
|
||||
link.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
openArtifactFromVerdict(artifact, step, resolved);
|
||||
openArtifactFromVerdict(artifact, step, resolved, link);
|
||||
});
|
||||
return link;
|
||||
}
|
||||
@@ -583,12 +600,12 @@ function renderVerdictRef(artifact, step) {
|
||||
type: "button",
|
||||
text: artifact.name || "(unnamed artifact)",
|
||||
});
|
||||
chip.addEventListener("click", () => openArtifactFromVerdict(artifact, step, resolved));
|
||||
chip.addEventListener("click", () => openArtifactFromVerdict(artifact, step, resolved, chip));
|
||||
return chip;
|
||||
}
|
||||
|
||||
/** Open a referenced artifact: media in the viewer, everything else externally. */
|
||||
function openArtifactFromVerdict(artifact, step, resolved) {
|
||||
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]);
|
||||
@@ -596,11 +613,11 @@ function openArtifactFromVerdict(artifact, step, resolved) {
|
||||
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);
|
||||
if (media && at != null) openArtifactViewer(viewable, at, trigger);
|
||||
else window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
|
||||
/** Open the stage pane for one visit of a stage and move focus into it. */
|
||||
/** Open the stage pane for one visit of a stage; the controller moves focus in. */
|
||||
function openStagePane(stageKey, visitIndex, { updateRoute = true } = {}) {
|
||||
state.runStagePane = { stageKey, visitIndex };
|
||||
state.runStageSections = new Set();
|
||||
@@ -613,30 +630,17 @@ function openStagePane(stageKey, visitIndex, { updateRoute = true } = {}) {
|
||||
});
|
||||
}
|
||||
renderContent();
|
||||
document.querySelector(".stage-pane-back")?.focus();
|
||||
}
|
||||
|
||||
/** Close the stage pane, returning focus to the timeline row that opened it. */
|
||||
/** Close the stage pane; the controller returns focus to the row or graph node. */
|
||||
function closeStagePane({ updateRoute = true } = {}) {
|
||||
const closing = state.runStagePane;
|
||||
if (!closing) return;
|
||||
if (!state.runStagePane) return;
|
||||
state.runStagePane = null;
|
||||
state.runStageSections = new Set();
|
||||
if (updateRoute && state.selectedRunId) {
|
||||
pushRoute({ kind: "run", id: state.selectedRunId });
|
||||
}
|
||||
renderContent();
|
||||
const row = [...document.querySelectorAll(".timeline-row")].find(
|
||||
(node) => node.dataset.stageKey === closing.stageKey && node.dataset.visitIndex === String(closing.visitIndex),
|
||||
);
|
||||
// A pane opened from the Timeline returns to its row; one opened from the Graph
|
||||
// returns to the stage node that opened it (there is no timeline row then).
|
||||
const focusTarget =
|
||||
row ??
|
||||
[...document.querySelectorAll(".graph-node")].find(
|
||||
(candidate) => candidate.dataset.key === closing.stageKey,
|
||||
);
|
||||
focusTarget?.focus();
|
||||
}
|
||||
|
||||
// --- Run-level operator actions (R11–R14) ----------------------------------
|
||||
@@ -856,7 +860,7 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
});
|
||||
const openViewer = () => {
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
if (at != null) openArtifactViewer(viewable, at);
|
||||
if (at != null) openArtifactViewer(viewable, at, tile);
|
||||
};
|
||||
const openTab = () => {
|
||||
if (resolved) window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
} from "../templates.js";
|
||||
|
||||
export function createTemplatesView(rt) {
|
||||
const { state, repo } = rt;
|
||||
const { state, repo, modal } = rt;
|
||||
const renderContent = (...args) => rt.renderContent(...args);
|
||||
const focusDetailHeading = (...args) => rt.focusDetailHeading(...args);
|
||||
const pushRoute = (...args) => rt.pushRoute(...args);
|
||||
@@ -133,7 +133,6 @@ function openTemplateCreateDialog() {
|
||||
state.templateCreateError = "";
|
||||
state.templateCreateCreated = null;
|
||||
renderContent();
|
||||
document.querySelector(".template-create-name")?.focus();
|
||||
}
|
||||
|
||||
/** Dismiss the create dialog (never while a validate+submit is in flight). */
|
||||
@@ -229,6 +228,11 @@ function renderTemplateCreateDialog(entry) {
|
||||
);
|
||||
panel.append(actions);
|
||||
overlay.append(panel);
|
||||
modal.stage("template-create", overlay, {
|
||||
onClose: () => closeTemplateCreateDialog(),
|
||||
triggerSelector: ".template-create-open",
|
||||
fallbackSelectors: ["#detailTitle", "#pane-main"],
|
||||
});
|
||||
return overlay;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user