web: shared modal focus controller (M1/M2) — work in progress
This commit is contained in:
+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 {
|
||||
|
||||
Reference in New Issue
Block a user