web: shared modal focus controller (M1/M2) — work in progress
This commit is contained in:
+27
-54
@@ -42,6 +42,7 @@ import {
|
||||
} from "./search.js";
|
||||
import { DecisionDraft, pendingDecision } from "./actions.js";
|
||||
import { h } from "./dom.js";
|
||||
import { createModalController } from "./modal.js";
|
||||
import { describeError, isExecuting } from "./format.js";
|
||||
import {
|
||||
createAttentionView,
|
||||
@@ -510,9 +511,24 @@ const dock = h(
|
||||
// The attention sheet lives in its own layer so it can overlay any view without
|
||||
// being torn down by a content re-render; renderAttentionSheet rebuilds it.
|
||||
const attentionLayer = h("div", { id: "attentionLayer" });
|
||||
// Dialogs are re-parented here, outside the inert app root. `inert` inherits and
|
||||
// cannot be overridden by a descendant, so a panel left inside .app-root could
|
||||
// never be interactive while the background is inert.
|
||||
const modalLayer = h("div", { id: "modalLayer" });
|
||||
const skipLink = h("a", { class: "skip-link", href: "#pane-main", text: "Skip to detail" });
|
||||
document.body.append(skipLink);
|
||||
document.body.append(h("div", { class: "app-root" }, appRail, workspace, dock, attentionLayer));
|
||||
document.body.append(h("div", { class: "app-root" }, appRail, workspace, dock));
|
||||
document.body.append(attentionLayer);
|
||||
document.body.append(modalLayer);
|
||||
|
||||
// One controller owns Escape, the Tab trap, the background's inert state and
|
||||
// focus return for every role="dialog" surface.
|
||||
const modal = createModalController({
|
||||
document,
|
||||
layer: () => modalLayer,
|
||||
background: () => document.querySelector(".app-root"),
|
||||
skipLinks: () => [...document.querySelectorAll(".skip-link")],
|
||||
});
|
||||
|
||||
/** Whether the URL field currently holds a usable endpoint for Reconnect. */
|
||||
function endpointConfigured() {
|
||||
@@ -931,6 +947,7 @@ function renderContent() {
|
||||
nodes.push(h("div", { class: "settings-pane", id: "detail-panel" }, renderSettingsView()));
|
||||
captureChatPosition();
|
||||
content.replaceChildren(...nodes);
|
||||
modal.reconcile();
|
||||
stopChatClock();
|
||||
stopListClock();
|
||||
stopDetailClock();
|
||||
@@ -1021,11 +1038,13 @@ function renderContent() {
|
||||
content.replaceChildren(...nodes);
|
||||
if (state.view === "chat") {
|
||||
afterChatRender();
|
||||
modal.reconcile();
|
||||
stopListClock();
|
||||
stopDetailClock();
|
||||
refreshChatClock();
|
||||
return;
|
||||
}
|
||||
modal.reconcile();
|
||||
stopChatClock();
|
||||
if (state.view === "runs") {
|
||||
refreshListClock();
|
||||
@@ -2035,6 +2054,7 @@ const runtime = {
|
||||
repo,
|
||||
runAlerts,
|
||||
attentionLayer,
|
||||
modal,
|
||||
searchHost,
|
||||
render,
|
||||
renderContent,
|
||||
@@ -2070,12 +2090,11 @@ const {
|
||||
renderAttentionBell,
|
||||
refreshAttentionBell,
|
||||
renderAttentionSheet,
|
||||
closeAttentionSheet,
|
||||
onRunAlertFrame,
|
||||
} = views.attention;
|
||||
const { renderSettingsView, refreshServerUrlError } = views.settings;
|
||||
const { renderPipelineList, renderPipelineDetail } = views.pipelines;
|
||||
const { renderTemplateGallery, renderTemplateDetail, loadTemplates, selectTemplate, resetTemplateCreateState, resetTemplateSelection, closeTemplateCreateDialog } =
|
||||
const { renderTemplateGallery, renderTemplateDetail, loadTemplates, selectTemplate, resetTemplateCreateState, resetTemplateSelection } =
|
||||
views.templates;
|
||||
const renderRunList = () => views.runs.renderRunList(listNow);
|
||||
const renderRunDetail = () => views.runDetail.renderRunDetail(detailNow);
|
||||
@@ -2098,8 +2117,6 @@ const {
|
||||
onChatEvent,
|
||||
onChatPermission,
|
||||
onChatFrame,
|
||||
dismissChatClose,
|
||||
dismissChatRename,
|
||||
} = views.chat;
|
||||
const {
|
||||
openSearch,
|
||||
@@ -2108,8 +2125,7 @@ const {
|
||||
onSearchInput,
|
||||
sendSearchNow,
|
||||
} = views.search;
|
||||
const { openDecisionSheet, closeDecisionSheet, dismissConfirm, dismissActionError } = views.dialogs;
|
||||
const { closeStagePane } = views.runDetail;
|
||||
const { openDecisionSheet } = views.dialogs;
|
||||
|
||||
// Kept as named exports for the UI smoke's page-rendered markdown/tool samples.
|
||||
export const renderToolCallRow = views.chat.renderToolCallRow;
|
||||
@@ -2200,55 +2216,12 @@ client.addEventListener("frame", (event) => {
|
||||
onChatFrame(message);
|
||||
});
|
||||
|
||||
// The stage pane, the decision sheet, the confirm/Action-failed dialogs, the
|
||||
// omni-search field and the attention sheet are modal: Escape closes the topmost
|
||||
// one (the artifact viewer or the diff viewer, when either is above, owns Escape
|
||||
// first via its own listener). The attention sheet, when open, is the topmost
|
||||
// overlay and owns Escape first. Registered once; every branch is a no-op when
|
||||
// nothing is open.
|
||||
// The shared modal controller owns Escape for every role="dialog" (attention
|
||||
// sheet, stage pane, viewers, decision/confirm/Action-failed, chat Rename/Close,
|
||||
// template create). Only the non-modal surfaces below are handled here: the Chat
|
||||
// actions menu and the Search disclosure, which are not dialogs.
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key !== "Escape") return;
|
||||
if (state.attentionSheetOpen) {
|
||||
event.preventDefault();
|
||||
closeAttentionSheet();
|
||||
return;
|
||||
}
|
||||
if (document.querySelector(".artifact-viewer") || document.querySelector(".change-viewer")) return;
|
||||
if (state.templateCreateOpen) {
|
||||
event.preventDefault();
|
||||
closeTemplateCreateDialog();
|
||||
return;
|
||||
}
|
||||
if (state.actionError) {
|
||||
event.preventDefault();
|
||||
dismissActionError();
|
||||
return;
|
||||
}
|
||||
if (state.chatRename) {
|
||||
event.preventDefault();
|
||||
dismissChatRename();
|
||||
return;
|
||||
}
|
||||
if (state.chatClose) {
|
||||
event.preventDefault();
|
||||
dismissChatClose();
|
||||
return;
|
||||
}
|
||||
if (state.confirmKind) {
|
||||
event.preventDefault();
|
||||
dismissConfirm();
|
||||
return;
|
||||
}
|
||||
if (state.decisionOpen) {
|
||||
event.preventDefault();
|
||||
closeDecisionSheet();
|
||||
return;
|
||||
}
|
||||
if (state.runStagePane) {
|
||||
event.preventDefault();
|
||||
closeStagePane();
|
||||
return;
|
||||
}
|
||||
if (state.chatMenu) {
|
||||
event.preventDefault();
|
||||
state.chatMenu = null;
|
||||
|
||||
Reference in New Issue
Block a user