feat(maestro): mobile multi-view — tabs-only projection + sidebar drawer
ci / rust (push) Successful in 4m48s
ci / rust (push) Successful in 4m48s
Below 860px the split tree projects to a one-pane-at-a-time pill strip (no splits/drag/resize — desktop only); the tree is untouched so widening restores the splits. Only the visible pane's session stays live; the rest park. The sidebar becomes an off-canvas drawer toggled by a ☰ in the tab bar, with a backdrop; tapping a session opens it and closes the drawer. Re-renders on the breakpoint crossing without losing sessions. Closes #35. Part of epic #37. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+75
-6
@@ -36,6 +36,8 @@ export interface MultiViewOptions {
|
||||
/** Called after any layout change (structure, focus, or divider resize) so the
|
||||
* shell can persist it (issue #34). */
|
||||
onLayoutChange?: () => void;
|
||||
/** Toggle the mobile sidebar drawer (the ☰ button in the tab bar, issue #35). */
|
||||
onToggleSidebar?: () => void;
|
||||
}
|
||||
|
||||
export interface MultiView {
|
||||
@@ -66,6 +68,16 @@ export function createMultiView(opts: MultiViewOptions): MultiView {
|
||||
canvas.className = "mv-canvas";
|
||||
el.append(tabBar, canvas);
|
||||
|
||||
// Mobile (issue #35): below 860px the tree projects to a one-pane-at-a-time
|
||||
// strip of pills — splits/drag/resize are desktop-only. The tree is untouched,
|
||||
// so widening restores the splits.
|
||||
const mq = window.matchMedia("(max-width: 859px)");
|
||||
let isMobile = mq.matches;
|
||||
mq.addEventListener("change", (e) => {
|
||||
isMobile = e.matches;
|
||||
render();
|
||||
});
|
||||
|
||||
// ---- highlight helpers ----
|
||||
|
||||
function colorMap(): Map<string, string> {
|
||||
@@ -140,23 +152,27 @@ export function createMultiView(opts: MultiViewOptions): MultiView {
|
||||
return b;
|
||||
};
|
||||
// Order: disconnect (⏻) leftmost, then split-right / split-down / close.
|
||||
// Splits are desktop-only; mobile keeps just disconnect + close.
|
||||
if (leaf.sessionId) {
|
||||
const off = mkBtn("⏻", "Disconnect", () => onDisconnect(leaf.sessionId!));
|
||||
off.classList.add("mv-tool-off");
|
||||
tools.appendChild(off);
|
||||
}
|
||||
tools.append(
|
||||
mkBtn("▥", "Split right", () => splitFocused(leaf.id, "row")),
|
||||
mkBtn("▤", "Split down", () => splitFocused(leaf.id, "col")),
|
||||
mkBtn("✕", "Close pane", () => closePane(leaf.id)),
|
||||
);
|
||||
if (!isMobile) {
|
||||
tools.append(
|
||||
mkBtn("▥", "Split right", () => splitFocused(leaf.id, "row")),
|
||||
mkBtn("▤", "Split down", () => splitFocused(leaf.id, "col")),
|
||||
);
|
||||
}
|
||||
tools.appendChild(mkBtn("✕", "Close pane", () => closePane(leaf.id)));
|
||||
|
||||
pane.append(host, tools);
|
||||
pane.addEventListener(
|
||||
"pointerdown",
|
||||
(e) => {
|
||||
focusLeaf(leaf.id);
|
||||
// Drag a pane by its title bar (not its buttons or the terminal body).
|
||||
// Drag a pane by its title bar (desktop only — no docking on mobile).
|
||||
if (isMobile) return;
|
||||
const t = e.target as HTMLElement;
|
||||
if (t.closest(".attach-header") && !t.closest("button, a, .mv-tool")) {
|
||||
runDrag({ kind: "pane", leafId: leaf.id }, e, { deferred: true });
|
||||
@@ -235,6 +251,14 @@ export function createMultiView(opts: MultiViewOptions): MultiView {
|
||||
|
||||
function renderTabs(): void {
|
||||
tabBar.replaceChildren();
|
||||
// Mobile-only ☰ to open the sidebar drawer (CSS hides it on desktop).
|
||||
const menu = document.createElement("button");
|
||||
menu.type = "button";
|
||||
menu.className = "mv-mobile-menu";
|
||||
menu.title = "Sessions";
|
||||
menu.textContent = "☰";
|
||||
menu.addEventListener("click", () => opts.onToggleSidebar?.());
|
||||
tabBar.appendChild(menu);
|
||||
for (const t of layout.tabs) {
|
||||
const tab = document.createElement("button");
|
||||
tab.type = "button";
|
||||
@@ -335,6 +359,12 @@ export function createMultiView(opts: MultiViewOptions): MultiView {
|
||||
tab.focusedLeafId = leaves(tab.root)[0]?.id ?? null;
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
renderMobile(tab);
|
||||
persist();
|
||||
return;
|
||||
}
|
||||
|
||||
const hosts: { id: string; host: HTMLElement; info?: AttachInfo }[] = [];
|
||||
canvas.appendChild(buildTree(tab.root, hosts));
|
||||
pool.setVisible(hosts.map((h) => ({ id: h.id, pane: h.host, info: h.info })));
|
||||
@@ -342,6 +372,45 @@ export function createMultiView(opts: MultiViewOptions): MultiView {
|
||||
persist();
|
||||
}
|
||||
|
||||
// Mobile: a pill strip of the active tab's leaves + one full-screen pane.
|
||||
function renderMobile(tab: { root: Node | null; focusedLeafId: string | null }): void {
|
||||
const ls = leaves(tab.root);
|
||||
const focused = (tab.focusedLeafId && findLeaf(tab.root, tab.focusedLeafId)) || ls[0];
|
||||
|
||||
const wrap = document.createElement("div");
|
||||
wrap.className = "mv-mobile";
|
||||
|
||||
if (ls.length > 1) {
|
||||
const bar = document.createElement("div");
|
||||
bar.className = "mv-panebar";
|
||||
for (const l of ls) {
|
||||
const pill = document.createElement("button");
|
||||
pill.type = "button";
|
||||
pill.className = "mv-pill" + (l.id === focused.id ? " is-active" : "");
|
||||
pill.textContent = l.sessionId ? (infoFor(l.sessionId)?.name ?? l.sessionId.slice(0, 8)) : "empty";
|
||||
if (l.sessionId) pill.style.setProperty("--mv-color", sessionColor(l.sessionId));
|
||||
pill.addEventListener("click", () => {
|
||||
tab.focusedLeafId = l.id;
|
||||
render();
|
||||
});
|
||||
bar.appendChild(pill);
|
||||
}
|
||||
wrap.appendChild(bar);
|
||||
}
|
||||
|
||||
const pane = buildPane(focused);
|
||||
pane.el.classList.add("is-focused"); // the only pane — never dimmed
|
||||
wrap.appendChild(pane.el);
|
||||
canvas.appendChild(wrap);
|
||||
|
||||
// Only the focused leaf's session is live on mobile; the rest park.
|
||||
pool.setVisible(
|
||||
focused.sessionId ? [{ id: focused.sessionId, pane: pane.host, info: infoFor(focused.sessionId) }] : [],
|
||||
);
|
||||
pool.setFocus(focused.sessionId ?? null);
|
||||
sidebar.setHighlights({ open: openSessions(layout), focused: focused.sessionId ?? null, colors: colorMap() });
|
||||
}
|
||||
|
||||
function closeSession(sessionId: string): void {
|
||||
const loc = locateSession(layout, sessionId);
|
||||
if (!loc) return;
|
||||
|
||||
Reference in New Issue
Block a user